Bug 1340582 - handle shared memory allocation failure. r=jchen
authorJohn Lin <jolin@mozilla.com>
Mon, 20 Feb 2017 15:17:10 +0800
changeset 373225 bf67ad546e37a4dd2c1e0317b290d46f95d02688
parent 373224 afe3edac6acd6ee4c3832226c839ae9f4b3bcce7
child 373226 7561692c1bc7ae4e4f7d968412e65015c611050f
push id10863
push userjlorenzo@mozilla.com
push dateMon, 06 Mar 2017 23:02:23 +0000
treeherdermozilla-aurora@0931190cd725 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersjchen
bugs1340582
milestone54.0a1
Bug 1340582 - handle shared memory allocation failure. r=jchen MozReview-Commit-ID: ETk9nHHkyYA
dom/media/platforms/android/RemoteDataDecoder.cpp
mobile/android/base/java/org/mozilla/gecko/media/CodecProxy.java
--- a/dom/media/platforms/android/RemoteDataDecoder.cpp
+++ b/dom/media/platforms/android/RemoteDataDecoder.cpp
@@ -579,19 +579,21 @@ RemoteDataDecoder::Decode(MediaRawData* 
     nsresult rv = BufferInfo::New(&bufferInfo);
     if (NS_FAILED(rv)) {
       return DecodePromise::CreateAndReject(
         MediaResult(NS_ERROR_OUT_OF_MEMORY, __func__), __func__);
     }
     bufferInfo->Set(0, sample->Size(), sample->mTime, 0);
 
     mDrainStatus = DrainStatus::DRAINABLE;
-    RefPtr<DecodePromise> p = mDecodePromise.Ensure(__func__);
-    mJavaDecoder->Input(bytes, bufferInfo, GetCryptoInfoFromSample(sample));
-    return p;
+    return mJavaDecoder->Input(bytes, bufferInfo, GetCryptoInfoFromSample(sample))
+           ? mDecodePromise.Ensure(__func__)
+           : DecodePromise::CreateAndReject(
+               MediaResult(NS_ERROR_OUT_OF_MEMORY, __func__), __func__);
+
   });
 }
 
 void
 RemoteDataDecoder::Output(MediaData* aSample)
 {
   if (!mTaskQueue->IsCurrentThreadIn()) {
     mTaskQueue->Dispatch(
--- a/mobile/android/base/java/org/mozilla/gecko/media/CodecProxy.java
+++ b/mobile/android/base/java/org/mozilla/gecko/media/CodecProxy.java
@@ -172,39 +172,35 @@ public final class CodecProxy {
         }
         try {
             Sample sample = processInput(bytes, info, cryptoInfo);
             if (sample == null) {
                 return false;
             }
             mRemote.queueInput(sample);
             sample.dispose();
-        } catch (RemoteException e) {
-            e.printStackTrace();
+        } catch (RemoteException | IOException e) {
             Log.e(LOGTAG, "fail to input sample: size=" + info.size +
                     ", pts=" + info.presentationTimeUs +
-                    ", flags=" + Integer.toHexString(info.flags));
+                    ", flags=" + Integer.toHexString(info.flags) +
+                    ", e=" + e);
             return false;
         }
 
         return true;
     }
 
-    private Sample processInput(ByteBuffer bytes, BufferInfo info, CryptoInfo cryptoInfo) throws RemoteException {
+    private Sample processInput(ByteBuffer bytes, BufferInfo info, CryptoInfo cryptoInfo)
+            throws RemoteException, IOException {
         if (info.flags == MediaCodec.BUFFER_FLAG_END_OF_STREAM) {
             mCallbacks.setEndOfInput(true);
             return Sample.EOS;
         } else {
             mCallbacks.setEndOfInput(false);
-            try {
-                return mRemote.dequeueInput(info.size).set(bytes, info, cryptoInfo);
-            } catch (IOException e) {
-                e.printStackTrace();
-                return null;
-            }
+            return mRemote.dequeueInput(info.size).set(bytes, info, cryptoInfo);
         }
     }
 
     @WrapForJNI
     public synchronized boolean flush() {
         if (mRemote == null) {
             Log.e(LOGTAG, "cannot flush an ended codec");
             return false;