Bug 1313991 - Rewrite input buffer polling logic. r=esawin
authorJohn Lin <jolin@mozilla.com>
Mon, 21 Nov 2016 15:36:06 +0800
changeset 324238 82701190b854a4a4adc9805a123421aa02c25ea9
parent 324237 fcdea0f0691b930b8d7ef78d6d17a1ee92ae8bce
child 324239 9e8fa067c09c9227ff5239799d6172de700bc22e
push id24
push usermaklebus@msu.edu
push dateTue, 20 Dec 2016 03:11:33 +0000
reviewersesawin
bugs1313991
milestone53.0a1
Bug 1313991 - Rewrite input buffer polling logic. r=esawin - poll all buffers when started or flushed. - retry only for timed out. - remove unnecessary polling MozReview-Commit-ID: DU9vvjJkwDH
mobile/android/base/java/org/mozilla/gecko/media/JellyBeanAsyncCodec.java
--- a/mobile/android/base/java/org/mozilla/gecko/media/JellyBeanAsyncCodec.java
+++ b/mobile/android/base/java/org/mozilla/gecko/media/JellyBeanAsyncCodec.java
@@ -209,34 +209,32 @@ final class JellyBeanAsyncCodec implemen
 
             return true;
         }
 
         private void pollInputBuffer() {
             int result = mCodec.dequeueInputBuffer(DEQUEUE_TIMEOUT_US);
             if (result >= 0) {
                 mCallbackSender.notifyInputBuffer(result);
-                schedulePollingIfNotCanceled(BufferPoller.MSG_POLL_INPUT_BUFFERS);
-            } else if (result != MediaCodec.INFO_TRY_AGAIN_LATER) {
+            } else if (result == MediaCodec.INFO_TRY_AGAIN_LATER) {
+                mBufferPoller.schedulePollingIfNotCanceled(BufferPoller.MSG_POLL_INPUT_BUFFERS);
+            } else {
                 mCallbackSender.notifyError(result);
             }
         }
 
         private void pollOutputBuffer() {
             boolean dequeueMoreBuffer = true;
             MediaCodec.BufferInfo info = new MediaCodec.BufferInfo();
             int result = mCodec.dequeueOutputBuffer(info, DEQUEUE_TIMEOUT_US);
             if (result >= 0) {
                 if ((info.flags & MediaCodec.BUFFER_FLAG_END_OF_STREAM) != 0) {
                     mOutputEnded = true;
                 }
                 mCallbackSender.notifyOutputBuffer(result, info);
-                if (!hasMessages(MSG_POLL_INPUT_BUFFERS)) {
-                    schedulePollingIfNotCanceled(MSG_POLL_INPUT_BUFFERS);
-                }
             } else if (result == MediaCodec.INFO_OUTPUT_BUFFERS_CHANGED) {
                 mOutputBuffers = mCodec.getOutputBuffers();
             } else if (result == MediaCodec.INFO_OUTPUT_FORMAT_CHANGED) {
                 mCallbackSender.notifyOutputFormat(mCodec.getOutputFormat());
             } else if (result == MediaCodec.INFO_TRY_AGAIN_LATER) {
                 // When input ended, keep polling remaining output buffer until EOS.
                 dequeueMoreBuffer = mInputEnded;
             } else {
@@ -321,36 +319,38 @@ final class JellyBeanAsyncCodec implemen
     @Override
     public void start() {
         assertCallbacks();
 
         mCodec.start();
         mInputEnded = false;
         mOutputEnded = false;
         mInputBuffers = mCodec.getInputBuffers();
+        for (int i = 0; i < mInputBuffers.length; i++) {
+            mBufferPoller.schedulePolling(BufferPoller.MSG_POLL_INPUT_BUFFERS);
+        }
         mOutputBuffers = mCodec.getOutputBuffers();
-        mBufferPoller.schedulePolling(BufferPoller.MSG_POLL_INPUT_BUFFERS);
     }
 
     @Override
     public final void queueInputBuffer(int index, int offset, int size, long presentationTimeUs, int flags) {
         assertCallbacks();
 
         mInputEnded = (flags & MediaCodec.BUFFER_FLAG_END_OF_STREAM) != 0;
 
         try {
             mCodec.queueInputBuffer(index, offset, size, presentationTimeUs, flags);
         } catch (IllegalStateException e) {
             e.printStackTrace();
             mCallbackSender.notifyError(ERROR_CODEC);
             return;
         }
 
+        mBufferPoller.schedulePolling(BufferPoller.MSG_POLL_OUTPUT_BUFFERS);
         mBufferPoller.schedulePolling(BufferPoller.MSG_POLL_INPUT_BUFFERS);
-        mBufferPoller.schedulePolling(BufferPoller.MSG_POLL_OUTPUT_BUFFERS);
     }
 
     @Override
     public final void queueSecureInputBuffer(int index,
                                              int offset,
                                              MediaCodec.CryptoInfo cryptoInfo,
                                              long presentationTimeUs,
                                              int flags) {
@@ -394,17 +394,19 @@ final class JellyBeanAsyncCodec implemen
     @Override
     public void flush() {
         assertCallbacks();
 
         mInputEnded = false;
         mOutputEnded = false;
         cancelPendingTasks();
         mCodec.flush();
-        mBufferPoller.schedulePolling(BufferPoller.MSG_POLL_INPUT_BUFFERS);
+        for (int i = 0; i < mInputBuffers.length; i++) {
+            mBufferPoller.schedulePolling(BufferPoller.MSG_POLL_INPUT_BUFFERS);
+        }
     }
 
     private void cancelPendingTasks() {
         mBufferPoller.cancel();
         mCallbackSender.cancel();
     }
 
     @Override