Bug 1338975 - Don't leak MediaCodec exceptions to CodecProxy. r=jchen a=gchang
authorJohn Lin <jolin@mozilla.com>
Tue, 14 Feb 2017 13:43:35 +0800
changeset 378538 c4dda37794c12e666b66fc72b570585657a1b1c7
parent 378537 9599f3612a604852c5daac4ba4bca8887c73cccc
child 378539 03268e651db85ff3e6f00ce2e222a8b388a79243
push id1419
push userjlund@mozilla.com
push dateMon, 10 Apr 2017 20:44:07 +0000
treeherdermozilla-release@5e6801b73ef6 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersjchen, gchang
bugs1338975
milestone53.0a2
Bug 1338975 - Don't leak MediaCodec exceptions to CodecProxy. r=jchen a=gchang MozReview-Commit-ID: AaouG5McGNb
mobile/android/base/java/org/mozilla/gecko/media/Codec.java
--- a/mobile/android/base/java/org/mozilla/gecko/media/Codec.java
+++ b/mobile/android/base/java/org/mozilla/gecko/media/Codec.java
@@ -72,20 +72,25 @@ import java.util.concurrent.ConcurrentLi
             if (!sample.isEOS()) {
                 Sample temp = sample;
                 sample = mDequeuedSamples.remove();
                 sample.info = temp.info;
                 sample.cryptoInfo = temp.cryptoInfo;
                 temp.dispose();
             }
 
-            if (mInputSamples.offer(sample)) {
+            if (!mInputSamples.offer(sample)) {
+                reportError(Error.FATAL, new Exception("FAIL: input sample queue is full"));
+                return;
+            }
+
+            try {
                 feedSampleToBuffer();
-            } else {
-                reportError(Error.FATAL, new Exception("FAIL: input sample queue is full"));
+            } catch (Exception e) {
+                reportError(Error.FATAL, e);
             }
         }
 
         private synchronized void onBuffer(int index) {
             if (mStopped) {
                 return;
             }
 
@@ -364,20 +369,21 @@ import java.util.concurrent.ConcurrentLi
     }
 
     @Override
     public synchronized boolean isAdaptivePlaybackSupported() {
         return mIsAdaptivePlaybackSupported;
     }
 
     private void releaseCodec() {
-        // In case Codec.stop() is not called yet.
-        mInputProcessor.stop();
-        mOutputProcessor.stop();
         try {
+            // In case Codec.stop() is not called yet.
+            mInputProcessor.stop();
+            mOutputProcessor.stop();
+
             mCodec.release();
         } catch (Exception e) {
             reportError(Error.FATAL, e);
         }
         mCodec = null;
     }
 
     private String getDecoderForFormat(MediaFormat format) {
@@ -425,31 +431,33 @@ import java.util.concurrent.ConcurrentLi
         } catch (RemoteException re) {
             re.printStackTrace();
         }
     }
 
     @Override
     public synchronized void stop() throws RemoteException {
         if (DEBUG) { Log.d(LOGTAG, "stop " + this); }
-        mInputProcessor.stop();
-        mOutputProcessor.stop();
         try {
+            mInputProcessor.stop();
+            mOutputProcessor.stop();
+
             mCodec.stop();
         } catch (Exception e) {
             reportError(Error.FATAL, e);
         }
     }
 
     @Override
     public synchronized void flush() throws RemoteException {
         if (DEBUG) { Log.d(LOGTAG, "flush " + this); }
-        mInputProcessor.stop();
-        mOutputProcessor.stop();
         try {
+            mInputProcessor.stop();
+            mOutputProcessor.stop();
+
             mCodec.flush();
             if (DEBUG) { Log.d(LOGTAG, "flushed " + this); }
             mInputProcessor.start();
             mOutputProcessor.start();
             mCodec.resumeReceivingInputs();
         } catch (Exception e) {
             reportError(Error.FATAL, e);
         }
@@ -462,17 +470,21 @@ import java.util.concurrent.ConcurrentLi
 
     @Override
     public synchronized void queueInput(Sample sample) throws RemoteException {
         mInputProcessor.onSample(sample);
     }
 
     @Override
     public synchronized void releaseOutput(Sample sample, boolean render) {
-        mOutputProcessor.onRelease(sample, render);
+        try {
+            mOutputProcessor.onRelease(sample, render);
+        } catch (Exception e) {
+            reportError(Error.FATAL, e);
+        }
     }
 
     @Override
     public synchronized void release() throws RemoteException {
         if (DEBUG) { Log.d(LOGTAG, "release " + this); }
         releaseCodec();
         mSamplePool.reset();
         mSamplePool = null;