Bug 1345599 - part 1: reduce InputExhausted() calls to avoid input queue flood. r?snorp
MozReview-Commit-ID: Kgl77k9Cx7w
--- a/mobile/android/base/java/org/mozilla/gecko/media/Codec.java
+++ b/mobile/android/base/java/org/mozilla/gecko/media/Codec.java
@@ -46,16 +46,17 @@ import java.util.concurrent.ConcurrentLi
@Override
public void onOutputFormatChanged(AsyncCodec codec, MediaFormat format) {
mOutputProcessor.onFormatChanged(format);
}
}
private final class InputProcessor {
+ private static final int FEW_PENDING_INPUTS = 2;
private boolean mHasInputCapacitySet;
private Queue<Integer> mAvailableInputBuffers = new LinkedList<>();
private Queue<Sample> mDequeuedSamples = new LinkedList<>();
private Queue<Sample> mInputSamples = new LinkedList<>();
private boolean mStopped;
private synchronized Sample onAllocate(int size) {
Sample sample = mSamplePool.obtainInput(size);
@@ -118,31 +119,37 @@ import java.util.concurrent.ConcurrentLi
long pts = sample.info.presentationTimeUs;
int flags = sample.info.flags;
MediaCodec.CryptoInfo cryptoInfo = sample.cryptoInfo;
if (!sample.isEOS() && sample.buffer != null) {
len = sample.info.size;
ByteBuffer buf = mCodec.getInputBuffer(index);
try {
sample.writeToByteBuffer(buf);
- mCallbacks.onInputExhausted();
} catch (IOException e) {
e.printStackTrace();
- } catch (RemoteException e) {
- e.printStackTrace();
}
mSamplePool.recycleInput(sample);
}
if (cryptoInfo != null) {
mCodec.queueSecureInputBuffer(index, 0, cryptoInfo, pts, flags);
} else {
mCodec.queueInputBuffer(index, 0, len, pts, flags);
}
}
+ // To avoid input queue flood, request more input samples only when
+ // there are just a few waiting to be processed.
+ if (mDequeuedSamples.size() + mInputSamples.size() <= FEW_PENDING_INPUTS) {
+ try {
+ mCallbacks.onInputExhausted();
+ } catch (RemoteException e) {
+ e.printStackTrace();
+ }
+ }
}
private synchronized void reset() {
for (Sample s : mInputSamples) {
if (!s.isEOS()) {
mSamplePool.recycleInput(s);
}
}