Commit 8d6c4b8e by andrewlewis Committed by Oliver Woodman

Only allow one input buffer to be dequeued at a time.

-------------
Created by MOE: https://github.com/google/moe
MOE_MIGRATED_REVID=110238340
parent 3a958ed5
...@@ -16,6 +16,7 @@ ...@@ -16,6 +16,7 @@
package com.google.android.exoplayer.ext.vp9; package com.google.android.exoplayer.ext.vp9;
import com.google.android.exoplayer.SampleHolder; import com.google.android.exoplayer.SampleHolder;
import com.google.android.exoplayer.util.Assertions;
import java.nio.ByteBuffer; import java.nio.ByteBuffer;
import java.util.LinkedList; import java.util.LinkedList;
...@@ -36,13 +37,13 @@ import java.util.LinkedList; ...@@ -36,13 +37,13 @@ import java.util.LinkedList;
private final Object lock; private final Object lock;
private final LinkedList<VpxInputBuffer> dequeuedInputBuffers;
private final LinkedList<VpxInputBuffer> queuedInputBuffers; private final LinkedList<VpxInputBuffer> queuedInputBuffers;
private final LinkedList<VpxOutputBuffer> queuedOutputBuffers; private final LinkedList<VpxOutputBuffer> queuedOutputBuffers;
private final VpxInputBuffer[] availableInputBuffers; private final VpxInputBuffer[] availableInputBuffers;
private final VpxOutputBuffer[] availableOutputBuffers; private final VpxOutputBuffer[] availableOutputBuffers;
private int availableInputBufferCount; private int availableInputBufferCount;
private int availableOutputBufferCount; private int availableOutputBufferCount;
private VpxInputBuffer dequeuedInputBuffer;
private boolean flushDecodedOutputBuffer; private boolean flushDecodedOutputBuffer;
private boolean released; private boolean released;
...@@ -57,7 +58,6 @@ import java.util.LinkedList; ...@@ -57,7 +58,6 @@ import java.util.LinkedList;
public VpxDecoderWrapper(int outputMode) { public VpxDecoderWrapper(int outputMode) {
lock = new Object(); lock = new Object();
this.outputMode = outputMode; this.outputMode = outputMode;
dequeuedInputBuffers = new LinkedList<>();
queuedInputBuffers = new LinkedList<>(); queuedInputBuffers = new LinkedList<>();
queuedOutputBuffers = new LinkedList<>(); queuedOutputBuffers = new LinkedList<>();
availableInputBuffers = new VpxInputBuffer[NUM_BUFFERS]; availableInputBuffers = new VpxInputBuffer[NUM_BUFFERS];
...@@ -77,13 +77,14 @@ import java.util.LinkedList; ...@@ -77,13 +77,14 @@ import java.util.LinkedList;
public VpxInputBuffer dequeueInputBuffer() throws VpxDecoderException { public VpxInputBuffer dequeueInputBuffer() throws VpxDecoderException {
synchronized (lock) { synchronized (lock) {
maybeThrowDecoderError(); maybeThrowDecoderError();
Assertions.checkState(dequeuedInputBuffer == null);
if (availableInputBufferCount == 0) { if (availableInputBufferCount == 0) {
return null; return null;
} }
VpxInputBuffer inputBuffer = availableInputBuffers[--availableInputBufferCount]; VpxInputBuffer inputBuffer = availableInputBuffers[--availableInputBufferCount];
inputBuffer.flags = 0; inputBuffer.flags = 0;
inputBuffer.sampleHolder.clearData(); inputBuffer.sampleHolder.clearData();
dequeuedInputBuffers.addLast(inputBuffer); dequeuedInputBuffer = inputBuffer;
return inputBuffer; return inputBuffer;
} }
} }
...@@ -91,9 +92,10 @@ import java.util.LinkedList; ...@@ -91,9 +92,10 @@ import java.util.LinkedList;
public void queueInputBuffer(VpxInputBuffer inputBuffer) throws VpxDecoderException { public void queueInputBuffer(VpxInputBuffer inputBuffer) throws VpxDecoderException {
synchronized (lock) { synchronized (lock) {
maybeThrowDecoderError(); maybeThrowDecoderError();
dequeuedInputBuffers.remove(inputBuffer); Assertions.checkArgument(inputBuffer == dequeuedInputBuffer);
queuedInputBuffers.addLast(inputBuffer); queuedInputBuffers.addLast(inputBuffer);
maybeNotifyDecodeLoop(); maybeNotifyDecodeLoop();
dequeuedInputBuffer = null;
} }
} }
...@@ -119,8 +121,9 @@ import java.util.LinkedList; ...@@ -119,8 +121,9 @@ import java.util.LinkedList;
public void flush() { public void flush() {
synchronized (lock) { synchronized (lock) {
flushDecodedOutputBuffer = true; flushDecodedOutputBuffer = true;
while (!dequeuedInputBuffers.isEmpty()) { if (dequeuedInputBuffer != null) {
availableInputBuffers[availableInputBufferCount++] = dequeuedInputBuffers.removeFirst(); availableInputBuffers[availableInputBufferCount++] = dequeuedInputBuffer;
dequeuedInputBuffer = null;
} }
while (!queuedInputBuffers.isEmpty()) { while (!queuedInputBuffers.isEmpty()) {
availableInputBuffers[availableInputBufferCount++] = queuedInputBuffers.removeFirst(); availableInputBuffers[availableInputBufferCount++] = queuedInputBuffers.removeFirst();
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment