Bug 1340582 - handle shared memory allocation failure. r?jchen draft
authorJohn Lin <jolin@mozilla.com>
Mon, 20 Feb 2017 15:17:10 +0800
changeset 487162 901b298ca1664e73907cf3e7a73e83d176c6e538
parent 487087 d0462b0948e0b1147dcce615bddcc46379bdadb2
child 546404 a4992272bbb46dd7326471b355c439a7a6a53b60
push id46160
push userbmo:jolin@mozilla.com
push dateTue, 21 Feb 2017 03:01:29 +0000
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;