Bug 1306483 - Part 2: send notification immediately when caller sender shares looper with buffer poller. draft
authorJohn Lin <jolin@mozilla.com>
Thu, 20 Oct 2016 15:43:25 +0800
changeset 427988 1f814a24990db17627c69a11075c1478ee2b47ad
parent 427987 ced1bf9bac2dacff2b0f59198e8c1b25d2ceb53e
child 427993 b56e9bf9d0e544402900e1f9b7a069ff3cfcd467
push id33192
push userbmo:jolin@mozilla.com
push dateFri, 21 Oct 2016 09:35:57 +0000
bugs1306483
milestone52.0a1
Bug 1306483 - Part 2: send notification immediately when caller sender shares looper with buffer poller. MozReview-Commit-ID: 9hZB6TI4A6X
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
@@ -82,40 +82,47 @@ final class JellyBeanAsyncCodec implemen
 
         public void notifyInputBuffer(int index) {
             if (isCanceled()) {
                 return;
             }
 
             Message msg = obtainMessage(MSG_INPUT_BUFFER_AVAILABLE);
             msg.arg1 = index;
-            sendMessage(msg);
+            processMessage(msg);
+        }
+
+        private void processMessage(Message msg) {
+            if (Looper.myLooper() == getLooper()) {
+                handleMessage(msg);
+            } else {
+                sendMessage(msg);
+            }
         }
 
         public void notifyOutputBuffer(int index, MediaCodec.BufferInfo info) {
             if (isCanceled()) {
                 return;
             }
 
             Message msg = obtainMessage(MSG_OUTPUT_BUFFER_AVAILABLE, info);
             msg.arg1 = index;
-            sendMessage(msg);
+            processMessage(msg);
         }
 
         public void notifyOutputFormat(MediaFormat format) {
             if (isCanceled()) {
                 return;
             }
-
-            sendMessage(obtainMessage(MSG_OUTPUT_FORMAT_CHANGE, format));
+            processMessage(obtainMessage(MSG_OUTPUT_FORMAT_CHANGE, format));
         }
 
         public void notifyError(int result) {
             Log.e(LOGTAG, "codec error:" + result);
-            sendMessage(obtainMessage(MSG_ERROR, result, 0));
+            processMessage(obtainMessage(MSG_ERROR, result, 0));
         }
 
         protected boolean handleMessageLocked(Message msg) {
             switch (msg.what) {
                 case MSG_INPUT_BUFFER_AVAILABLE: // arg1: buffer index.
                     mCallbacks.onInputBufferAvailable(JellyBeanAsyncCodec.this,
                                                       msg.arg1);
                     break;