Bug 1365205 - part 2: execute callback directly when already on the right looper/thread. r?esawin draft
authorJohn Lin <jolin@mozilla.com>
Mon, 17 Jul 2017 11:40:17 +0800
changeset 610338 7d0c9129dadba27f9991886fa9347e8ed74214ed
parent 610337 fb495e8cce83c30add745da8b160c4f13a5946b3
child 637839 b1f7c55e4d46d0c220c21e3ef697e6961703ad04
push id68868
push userbmo:jolin@mozilla.com
push dateTue, 18 Jul 2017 07:47:09 +0000
reviewersesawin
bugs1365205
milestone56.0a1
Bug 1365205 - part 2: execute callback directly when already on the right looper/thread. r?esawin 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();