Bug 1340041 - make callbacks no-op for dying CodecProxy. r=jchen

MozReview-Commit-ID: CJPwRNp78HP

--HG--
extra : rebase_source : 33fbd5f8f50ac19827a5adbf22fcdc5129f123d7
This commit is contained in:
John Lin 2017-02-21 17:17:34 +08:00
parent cd607fcae6
commit c6d5934ada

View File

@ -40,6 +40,13 @@ public final class CodecProxy {
void onError(boolean fatal);
}
private static Callbacks sNoOpCallbacks = new Callbacks() {
public void onInputExhausted() { }
public void onOutputFormatChanged(MediaFormat format) { }
public void onOutput(Sample output) { output.dispose(); }
public void onError(boolean fatal) { }
};
@WrapForJNI
public static class NativeCallbacks extends JNIObject implements Callbacks {
public native void onInputExhausted();
@ -52,7 +59,7 @@ public final class CodecProxy {
}
private class CallbacksForwarder extends ICodecCallbacks.Stub {
private final Callbacks mCallbacks;
private Callbacks mCallbacks;
private boolean mEndOfInput;
CallbacksForwarder(Callbacks callbacks) {
@ -60,19 +67,19 @@ public final class CodecProxy {
}
@Override
public void onInputExhausted() throws RemoteException {
public synchronized void onInputExhausted() throws RemoteException {
if (!mEndOfInput) {
mCallbacks.onInputExhausted();
}
}
@Override
public void onOutputFormatChanged(FormatParam format) throws RemoteException {
public synchronized void onOutputFormatChanged(FormatParam format) throws RemoteException {
mCallbacks.onOutputFormatChanged(format.asFormat());
}
@Override
public void onOutput(Sample sample) throws RemoteException {
public synchronized void onOutput(Sample sample) throws RemoteException {
if (mOutputSurface != null) {
// Don't render to surface just yet. Callback will make that happen when it's time.
mSurfaceOutputs.offer(sample);
@ -90,13 +97,17 @@ public final class CodecProxy {
reportError(fatal);
}
private void reportError(boolean fatal) {
private synchronized void reportError(boolean fatal) {
mCallbacks.onError(fatal);
}
private void setEndOfInput(boolean end) {
mEndOfInput = end;
}
private synchronized void cancel() {
mCallbacks = sNoOpCallbacks;
}
}
@WrapForJNI
@ -219,6 +230,8 @@ public final class CodecProxy {
@WrapForJNI
public synchronized boolean release() {
mCallbacks.cancel();
if (mRemote == null) {
Log.w(LOGTAG, "codec already ended");
return true;