Bug 1306483 - Part 1: use concurrent queue to fix race condition.
MozReview-Commit-ID: HRus9Sn7k6q
--- a/mobile/android/base/java/org/mozilla/gecko/media/Codec.java
+++ b/mobile/android/base/java/org/mozilla/gecko/media/Codec.java
@@ -14,16 +14,17 @@ import android.os.TransactionTooLargeExc
import android.util.Log;
import android.view.Surface;
import java.io.IOException;
import java.nio.ByteBuffer;
import java.util.LinkedList;
import java.util.NoSuchElementException;
import java.util.Queue;
+import java.util.concurrent.ConcurrentLinkedQueue;
/* package */ final class Codec extends ICodec.Stub implements IBinder.DeathRecipient {
private static final String LOGTAG = "GeckoRemoteCodec";
private static final boolean DEBUG = false;
public enum Error {
DECODE, FATAL
};
@@ -183,22 +184,23 @@ import java.util.Queue;
}
}
private synchronized void reset() {
mInputSamples.clear();
mAvailableInputBuffers.clear();
}
}
+
private volatile ICodecCallbacks mCallbacks;
private AsyncCodec mCodec;
private InputProcessor mInputProcessor;
private volatile boolean mFlushing = false;
private SamplePool mSamplePool;
- private Queue<Sample> mSentOutputs = new LinkedList<>();
+ private Queue<Sample> mSentOutputs = new ConcurrentLinkedQueue<>();
public synchronized void setCallbacks(ICodecCallbacks callbacks) throws RemoteException {
mCallbacks = callbacks;
callbacks.asBinder().linkToDeath(this, 0);
}
// IBinder.DeathRecipient
@Override
@@ -340,18 +342,19 @@ import java.util.Queue;
reportError(Error.FATAL, new Exception("FAIL: input sample queue is full"));
}
}
@Override
public synchronized void releaseOutput(Sample sample) {
try {
mSamplePool.recycleOutput(mSentOutputs.remove());
- } catch (NoSuchElementException e) {
- Log.e(LOGTAG, "releaseOutput not found: " + sample + "sent: " + mSentOutputs);
+ } catch (Exception e) {
+ Log.e(LOGTAG, "failed to release output:" + sample);
+ e.printStackTrace();
}
sample.dispose();
}
@Override
public synchronized void release() throws RemoteException {
if (DEBUG) Log.d(LOGTAG, "release " + this);
releaseCodec();