Bug 1365205 - part 2: execute callback directly when already on the right looper/thread. r?esawin
MozReview-Commit-ID: 4rceodXTV3a
--- 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();