Bug 1326238 - stop calling InputExhausted() once RemoteDataDecoder sends EOS input. r?snorp
MozReview-Commit-ID: L5KPHUi8uLx
--- a/mobile/android/base/java/org/mozilla/gecko/media/CodecProxy.java
+++ b/mobile/android/base/java/org/mozilla/gecko/media/CodecProxy.java
@@ -48,24 +48,27 @@ public final class CodecProxy {
public native void onError(boolean fatal);
@Override // JNIObject
protected native void disposeNative();
}
private class CallbacksForwarder extends ICodecCallbacks.Stub {
private final Callbacks mCallbacks;
+ private boolean mEndOfInput;
CallbacksForwarder(Callbacks callbacks) {
mCallbacks = callbacks;
}
@Override
public void onInputExhausted() throws RemoteException {
- mCallbacks.onInputExhausted();
+ if (!mEndOfInput) {
+ mCallbacks.onInputExhausted();
+ }
}
@Override
public void onOutputFormatChanged(FormatParam format) throws RemoteException {
mCallbacks.onOutputFormatChanged(format.asFormat());
}
@Override
@@ -85,16 +88,20 @@ public final class CodecProxy {
@Override
public void onError(boolean fatal) throws RemoteException {
reportError(fatal);
}
private void reportError(boolean fatal) {
mCallbacks.onError(fatal);
}
+
+ private void setEndOfInput(boolean end) {
+ mEndOfInput = end;
+ }
}
@WrapForJNI
public static CodecProxy create(MediaFormat format,
Surface surface,
Callbacks callbacks,
String drmStubId) {
return RemoteManager.getInstance().createCodec(format, surface, callbacks, drmStubId);
@@ -157,35 +164,48 @@ public final class CodecProxy {
@WrapForJNI
public synchronized boolean input(ByteBuffer bytes, BufferInfo info, CryptoInfo cryptoInfo) {
if (mRemote == null) {
Log.e(LOGTAG, "cannot send input to an ended codec");
return false;
}
try {
- Sample sample = (info.flags == MediaCodec.BUFFER_FLAG_END_OF_STREAM) ?
- Sample.EOS : mRemote.dequeueInput(info.size).set(bytes, info, cryptoInfo);
+ Sample sample = processInput(bytes, info, cryptoInfo);
+ if (sample == null) {
+ return false;
+ }
mRemote.queueInput(sample);
sample.dispose();
- } catch (IOException e) {
- e.printStackTrace();
- return false;
- } catch (DeadObjectException e) {
- return false;
} catch (RemoteException e) {
e.printStackTrace();
Log.e(LOGTAG, "fail to input sample: size=" + info.size +
", pts=" + info.presentationTimeUs +
", flags=" + Integer.toHexString(info.flags));
return false;
}
+
return true;
}
+ private Sample processInput(ByteBuffer bytes, BufferInfo info, CryptoInfo cryptoInfo) throws RemoteException {
+ if (info.flags == MediaCodec.BUFFER_FLAG_END_OF_STREAM) {
+ mCallbacks.setEndOfInput(true);
+ return Sample.EOS;
+ } else {
+ mCallbacks.setEndOfInput(false);
+ try {
+ return mRemote.dequeueInput(info.size).set(bytes, info, cryptoInfo);
+ } catch (IOException e) {
+ e.printStackTrace();
+ return null;
+ }
+ }
+ }
+
@WrapForJNI
public synchronized boolean flush() {
if (mRemote == null) {
Log.e(LOGTAG, "cannot flush an ended codec");
return false;
}
try {
if (DEBUG) { Log.d(LOGTAG, "flush " + this); }