Bug 1349883 - part 1: combine output buffer index and sample records. r=esawin,jya
MozReview-Commit-ID: 7yWMkgjOtQB
--- a/mobile/android/geckoview/src/main/java/org/mozilla/gecko/media/Codec.java
+++ b/mobile/android/geckoview/src/main/java/org/mozilla/gecko/media/Codec.java
@@ -183,36 +183,44 @@ import java.util.concurrent.ConcurrentLi
if (mStopped) {
return;
}
mStopped = true;
reset();
}
}
+ private static final class Output {
+ public final Sample sample;
+ public final int index;
+
+ public Output(final Sample sample, int index) {
+ this.sample = sample;
+ this.index = index;
+ }
+ }
+
private class OutputProcessor {
private final boolean mRenderToSurface;
private boolean mHasOutputCapacitySet;
- private Queue<Integer> mSentIndices = new LinkedList<>();
- private Queue<Sample> mSentOutputs = new LinkedList<>();
+ private Queue<Output> mSentOutputs = new LinkedList<>();
private boolean mStopped;
private OutputProcessor(boolean renderToSurface) {
mRenderToSurface = renderToSurface;
}
private synchronized void onBuffer(int index, MediaCodec.BufferInfo info) {
if (mStopped) {
return;
}
try {
Sample output = obtainOutputSample(index, info);
- mSentIndices.add(index);
- mSentOutputs.add(output);
+ mSentOutputs.add(new Output(output, index));
mCallbacks.onOutput(output);
} catch (Exception e) {
e.printStackTrace();
mCodec.releaseOutputBuffer(index, false);
}
boolean eos = (info.flags & MediaCodec.BUFFER_FLAG_END_OF_STREAM) != 0;
if (DEBUG && eos) {
@@ -243,44 +251,40 @@ import java.util.concurrent.ConcurrentLi
Log.e(LOGTAG, "Fail to read output buffer:" + e.getMessage());
}
}
return sample;
}
private synchronized void onRelease(Sample sample, boolean render) {
- Integer i = mSentIndices.poll();
- Sample output = mSentOutputs.poll();
- if (i == null || output == null) {
- Log.d(LOGTAG, "output buffer#" + i + "(" + output + ")" + ": " + sample + " already released");
+ final Output output = mSentOutputs.poll();
+ if (output == null) {
+ if (DEBUG) { Log.d(LOGTAG, sample + " already released"); }
return;
}
- mCodec.releaseOutputBuffer(i, render);
- mSamplePool.recycleOutput(output);
+ mCodec.releaseOutputBuffer(output.index, render);
+ mSamplePool.recycleOutput(output.sample);
sample.dispose();
}
private void onFormatChanged(MediaFormat format) {
try {
mCallbacks.onOutputFormatChanged(new FormatParam(format));
} catch (RemoteException re) {
// Dead recipient.
re.printStackTrace();
}
}
private synchronized void reset() {
- for (int i : mSentIndices) {
- mCodec.releaseOutputBuffer(i, false);
- }
- mSentIndices.clear();
- for (Sample s : mSentOutputs) {
- mSamplePool.recycleOutput(s);
+ for (final Output o : mSentOutputs) {
+ mCodec.releaseOutputBuffer(o.index, false);
+ mSamplePool.recycleOutput(o.sample);
}
mSentOutputs.clear();
}
private synchronized void start() {
if (!mStopped) {
return;
}
@@ -296,17 +300,16 @@ import java.util.concurrent.ConcurrentLi
}
}
private volatile ICodecCallbacks mCallbacks;
private AsyncCodec mCodec;
private InputProcessor mInputProcessor;
private OutputProcessor mOutputProcessor;
private SamplePool mSamplePool;
- private Queue<Sample> mSentOutputs = new ConcurrentLinkedQueue<>();
// Value will be updated after configure called.
private volatile boolean mIsAdaptivePlaybackSupported = false;
public synchronized void setCallbacks(ICodecCallbacks callbacks) throws RemoteException {
mCallbacks = callbacks;
callbacks.asBinder().linkToDeath(this, 0);
}