Bug 1346235 - part 3: forward shared memory allocation error to peer process. r=jchen
authorJohn Lin <jolin@mozilla.com>
Fri, 17 Mar 2017 15:17:16 +0800
changeset 348403 0dad897e64bd4ba08d167e4f9d09faea1340de0e
parent 348402 639a9dcab2bbef7d2ffe8b888a595145242ec1b4
child 348404 c4f7d0039351ec60456a1613ed34b0645bdc292e
push id39149
push userjolin@mozilla.com
push dateMon, 20 Mar 2017 11:18:00 +0000
treeherderautoland@c4f7d0039351 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersjchen
bugs1346235
milestone55.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1346235 - part 3: forward shared memory allocation error to peer process. r=jchen MozReview-Commit-ID: KDIMylv9tVt
mobile/android/base/java/org/mozilla/gecko/media/Codec.java
mobile/android/base/java/org/mozilla/gecko/media/SamplePool.java
--- a/mobile/android/base/java/org/mozilla/gecko/media/Codec.java
+++ b/mobile/android/base/java/org/mozilla/gecko/media/Codec.java
@@ -191,18 +191,18 @@ import java.util.concurrent.ConcurrentLi
             mRenderToSurface = renderToSurface;
         }
 
         private synchronized void onBuffer(int index, MediaCodec.BufferInfo info) {
             if (mStopped) {
                 return;
             }
 
-            Sample output = obtainOutputSample(index, info);
             try {
+                Sample output = obtainOutputSample(index, info);
                 mSentIndices.add(index);
                 mSentOutputs.add(output);
                 mCallbacks.onOutput(output);
             } catch (Exception e) {
                 e.printStackTrace();
                 mCodec.releaseOutputBuffer(index, false);
             }
 
@@ -466,18 +466,23 @@ import java.util.concurrent.ConcurrentLi
             mOutputProcessor.start();
             mCodec.resumeReceivingInputs();
         } catch (Exception e) {
             reportError(Error.FATAL, e);
         }
     }
 
     @Override
-    public synchronized Sample dequeueInput(int size) {
-        return mInputProcessor.onAllocate(size);
+    public synchronized Sample dequeueInput(int size) throws RemoteException {
+        try {
+            return mInputProcessor.onAllocate(size);
+        } catch (Exception e) {
+            // Translate allocation error to remote exception.
+            throw new RemoteException(e.getMessage());
+        }
     }
 
     @Override
     public synchronized void queueInput(Sample sample) throws RemoteException {
         mInputProcessor.onSample(sample);
     }
 
     @Override
--- a/mobile/android/base/java/org/mozilla/gecko/media/SamplePool.java
+++ b/mobile/android/base/java/org/mozilla/gecko/media/SamplePool.java
@@ -27,39 +27,37 @@ final class SamplePool {
 
         private void setDefaultBufferSize(int size) {
             if (mBufferless) {
                 throw new IllegalStateException("Setting buffer size of a bufferless pool is not allowed");
             }
             mDefaultBufferSize = size;
         }
 
-        private synchronized Sample obtain(int size)  {
+        private synchronized Sample obtain(int size) {
             if (!mRecycledSamples.isEmpty()) {
                 return mRecycledSamples.remove(0);
             }
 
             if (mBufferless) {
                 return Sample.create();
             } else {
                 return allocateSharedMemorySample(size);
             }
         }
 
         private Sample allocateSharedMemorySample(int size) {
             SharedMemory shm = null;
             try {
                 shm = new SharedMemory(mNextId++, Math.max(size, mDefaultBufferSize));
-            } catch (NoSuchMethodException e) {
-                e.printStackTrace();
-            } catch (IOException e) {
-                e.printStackTrace();
+            } catch (NoSuchMethodException | IOException e) {
+                throw new UnsupportedOperationException(e);
             }
 
-            return shm != null ? Sample.create(shm) : Sample.create();
+            return Sample.create(shm);
         }
 
         private synchronized void recycle(Sample recycled) {
             if (mBufferless || recycled.buffer.capacity() >= mDefaultBufferSize) {
                 mRecycledSamples.add(recycled);
             } else {
                 recycled.dispose();
             }