Bug 1306483 - Part 1: use concurrent queue to fix race condition. draft
authorJohn Lin <jolin@mozilla.com>
Thu, 20 Oct 2016 15:25:44 +0800
changeset 427987 ced1bf9bac2dacff2b0f59198e8c1b25d2ceb53e
parent 427779 f0f1aaf051d6798e1e73d1feee07ca847333167a
child 427988 1f814a24990db17627c69a11075c1478ee2b47ad
push id33192
push userbmo:jolin@mozilla.com
push dateFri, 21 Oct 2016 09:35:57 +0000
bugs1306483
milestone52.0a1
Bug 1306483 - Part 1: use concurrent queue to fix race condition. MozReview-Commit-ID: HRus9Sn7k6q
mobile/android/base/java/org/mozilla/gecko/media/Codec.java
--- 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();