Bug 1326238 - stop calling InputExhausted() once RemoteDataDecoder sends EOS input. r=snorp
authorJohn Lin <jolin@mozilla.com>
Fri, 30 Dec 2016 13:52:49 +0800
changeset 374483 4ed09f5f11991b28f838d657e999992d9ad22d46
parent 374482 a6b1db06ced9a83d00630a1e10b7d782639ca8b1
child 374484 8c24e94982ff872a2397ea572c1451a6d4f5ed30
push id6996
push userjlorenzo@mozilla.com
push dateMon, 06 Mar 2017 20:48:21 +0000
treeherdermozilla-beta@d89512dab048 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerssnorp
bugs1326238
milestone53.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1326238 - stop calling InputExhausted() once RemoteDataDecoder sends EOS input. r=snorp MozReview-Commit-ID: L5KPHUi8uLx
mobile/android/base/java/org/mozilla/gecko/media/CodecProxy.java
--- a/mobile/android/base/java/org/mozilla/gecko/media/CodecProxy.java
+++ b/mobile/android/base/java/org/mozilla/gecko/media/CodecProxy.java
@@ -48,24 +48,27 @@ public final class CodecProxy {
         public native void onError(boolean fatal);
 
         @Override // JNIObject
         protected native void disposeNative();
     }
 
     private class CallbacksForwarder extends ICodecCallbacks.Stub {
         private final Callbacks mCallbacks;
+        private boolean mEndOfInput;
 
         CallbacksForwarder(Callbacks callbacks) {
             mCallbacks = callbacks;
         }
 
         @Override
         public void onInputExhausted() throws RemoteException {
-            mCallbacks.onInputExhausted();
+            if (!mEndOfInput) {
+                mCallbacks.onInputExhausted();
+            }
         }
 
         @Override
         public void onOutputFormatChanged(FormatParam format) throws RemoteException {
             mCallbacks.onOutputFormatChanged(format.asFormat());
         }
 
         @Override
@@ -85,16 +88,20 @@ public final class CodecProxy {
         @Override
         public void onError(boolean fatal) throws RemoteException {
             reportError(fatal);
         }
 
         private void reportError(boolean fatal) {
             mCallbacks.onError(fatal);
         }
+
+        private void setEndOfInput(boolean end) {
+            mEndOfInput = end;
+        }
     }
 
     @WrapForJNI
     public static CodecProxy create(MediaFormat format,
                                     Surface surface,
                                     Callbacks callbacks,
                                     String drmStubId) {
         return RemoteManager.getInstance().createCodec(format, surface, callbacks, drmStubId);
@@ -157,35 +164,48 @@ public final class CodecProxy {
 
     @WrapForJNI
     public synchronized boolean input(ByteBuffer bytes, BufferInfo info, CryptoInfo cryptoInfo) {
         if (mRemote == null) {
             Log.e(LOGTAG, "cannot send input to an ended codec");
             return false;
         }
         try {
-            Sample sample = (info.flags == MediaCodec.BUFFER_FLAG_END_OF_STREAM) ?
-                    Sample.EOS : mRemote.dequeueInput(info.size).set(bytes, info, cryptoInfo);
+            Sample sample = processInput(bytes, info, cryptoInfo);
+            if (sample == null) {
+                return false;
+            }
             mRemote.queueInput(sample);
             sample.dispose();
-        } catch (IOException e) {
-            e.printStackTrace();
-            return false;
-        } catch (DeadObjectException e) {
-            return false;
         } catch (RemoteException e) {
             e.printStackTrace();
             Log.e(LOGTAG, "fail to input sample: size=" + info.size +
                     ", pts=" + info.presentationTimeUs +
                     ", flags=" + Integer.toHexString(info.flags));
             return false;
         }
+
         return true;
     }
 
+    private Sample processInput(ByteBuffer bytes, BufferInfo info, CryptoInfo cryptoInfo) throws RemoteException {
+        if (info.flags == MediaCodec.BUFFER_FLAG_END_OF_STREAM) {
+            mCallbacks.setEndOfInput(true);
+            return Sample.EOS;
+        } else {
+            mCallbacks.setEndOfInput(false);
+            try {
+                return mRemote.dequeueInput(info.size).set(bytes, info, cryptoInfo);
+            } catch (IOException e) {
+                e.printStackTrace();
+                return null;
+            }
+        }
+    }
+
     @WrapForJNI
     public synchronized boolean flush() {
         if (mRemote == null) {
             Log.e(LOGTAG, "cannot flush an ended codec");
             return false;
         }
         try {
             if (DEBUG) { Log.d(LOGTAG, "flush " + this); }