OSDN Git Service

MediaCodec: revalidate cached queued input buffers if queue fails
authorLajos Molnar <lajos@google.com>
Wed, 24 Sep 2014 21:07:35 +0000 (14:07 -0700)
committerLajos Molnar <lajos@google.com>
Wed, 24 Sep 2014 21:12:08 +0000 (14:12 -0700)
For legacy behavior (using getInputBuffers) input buffer needs to
be made valid if queue fails.  Otherwise, it becomes unusable,
and the buffer still belongs to the user.

In the new model, buffers obtained by getIn/OutputBuffer will
become invalid even if queue/release fails.

We do not do the same logic for output buffers, as these should
not be accessed even if releaseBuffer fails (which really should not
happen anyway unless codec is in bad state).

Bug: 17630446
Change-Id: Ica72a168d8aea97a0ee3f3ef49c60d0ca5a9fa06

media/java/android/media/MediaCodec.java

index 5fb4f12..bf68921 100644 (file)
@@ -827,8 +827,13 @@ final public class MediaCodec {
             invalidateByteBuffer(mCachedInputBuffers, index);
             mDequeuedInputBuffers.remove(index);
         }
-        native_queueInputBuffer(
-                index, offset, size, presentationTimeUs, flags);
+        try {
+            native_queueInputBuffer(
+                    index, offset, size, presentationTimeUs, flags);
+        } catch (CryptoException e) {
+            validateInputByteBuffer(mCachedInputBuffers, index);
+            throw e;
+        }
     }
 
     private native final void native_queueInputBuffer(
@@ -947,8 +952,13 @@ final public class MediaCodec {
             invalidateByteBuffer(mCachedInputBuffers, index);
             mDequeuedInputBuffers.remove(index);
         }
-        native_queueSecureInputBuffer(
-                index, offset, info, presentationTimeUs, flags);
+        try {
+            native_queueSecureInputBuffer(
+                    index, offset, info, presentationTimeUs, flags);
+        } catch (CryptoException e) {
+            validateInputByteBuffer(mCachedInputBuffers, index);
+            throw e;
+        }
     }
 
     private native final void native_queueSecureInputBuffer(