Bug 1365205 - Part 2: Execute callback directly when already on the right looper/thread. r=esawin, a=jcristau
authorJohn Lin <jolin@mozilla.com>
Mon, 17 Jul 2017 11:40:17 +0800
changeset 414386 823d66f7bf9879302b69bd71682b773752151c5b
parent 414385 3b374998e442cd3ff4d0120273b6f65be367abf4
child 414387 447c20e16b4d96dfb0fbfbc7dbf5b878a293a0c4
push id1490
push usermtabara@mozilla.com
push dateMon, 31 Jul 2017 14:08:16 +0000
treeherdermozilla-release@70e32e6bf15e [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersesawin, jcristau
bugs1365205
milestone55.0
Bug 1365205 - Part 2: Execute callback directly when already on the right looper/thread. r=esawin, a=jcristau MozReview-Commit-ID: 4rceodXTV3a
mobile/android/geckoview/src/main/java/org/mozilla/gecko/media/LollipopAsyncCodec.java
--- a/mobile/android/geckoview/src/main/java/org/mozilla/gecko/media/LollipopAsyncCodec.java
+++ b/mobile/android/geckoview/src/main/java/org/mozilla/gecko/media/LollipopAsyncCodec.java
@@ -60,31 +60,39 @@ import java.nio.ByteBuffer;
                                 msg.arg1); // error code
                         break;
                     default:
                         super.handleMessage(msg);
                 }
             }
 
             private void onInput(final int index) {
-                sendMessage(obtainMessage(MSG_INPUT_BUFFER_AVAILABLE, index, 0));
+                notify(obtainMessage(MSG_INPUT_BUFFER_AVAILABLE, index, 0));
+            }
+
+            private void notify(final Message msg) {
+                if (Looper.myLooper() == getLooper()) {
+                    handleMessage(msg);
+                } else {
+                    sendMessage(msg);
+                }
             }
 
             private void onOutput(final int index, final MediaCodec.BufferInfo info) {
                 final Message msg = obtainMessage(MSG_OUTPUT_BUFFER_AVAILABLE, index, 0, info);
-                sendMessage(msg);
+                notify(msg);
             }
 
             private void onOutputFormatChanged(final MediaFormat format) {
-                sendMessage(obtainMessage(MSG_OUTPUT_FORMAT_CHANGE, format));
+                notify(obtainMessage(MSG_OUTPUT_FORMAT_CHANGE, format));
             }
 
             private void onError(final MediaCodec.CodecException e) {
                 e.printStackTrace();
-                sendMessage(obtainMessage(MSG_ERROR, e.getErrorCode()));
+                notify(obtainMessage(MSG_ERROR, e.getErrorCode()));
             }
         }
 
         private CodecCallback(final Callbacks callbacks, final Handler handler) {
             Looper looper = (handler == null) ? null : handler.getLooper();
             if (looper == null) {
                 // Use this thread if no handler supplied.
                 looper = Looper.myLooper();