diff options
author | Jean-Michel Trivi <jmtrivi@google.com> | 2020-03-24 15:22:01 -0700 |
---|---|---|
committer | Jean-Michel Trivi <jmtrivi@google.com> | 2020-03-24 15:22:01 -0700 |
commit | 6abd17edc8028feb51fe6a3b68cfb0986be2a483 (patch) | |
tree | 543226076af9ccb0bd7678988f23209e96208d76 /media/java/android/media/MediaCodec.java | |
parent | 294823f0cb489e6cd560c7d22083102edbc44d7e (diff) |
MediaCodec: LinearBlock API for optional crypto
Split setter for LinearBlock in QueueRequest between:
- setLinearBlock for unencrypted streams
- setEncryptedLinearBlock with non-null crypto info
Bug: 149487982
Test: atest CtsMediaTestCases -- --module-arg CtsMediaTestCases:size:small
Change-Id: I7d147b3963febeb431b268262343c782f2c1e3e9
Diffstat (limited to 'media/java/android/media/MediaCodec.java')
-rw-r--r-- | media/java/android/media/MediaCodec.java | 38 |
1 files changed, 35 insertions, 3 deletions
diff --git a/media/java/android/media/MediaCodec.java b/media/java/android/media/MediaCodec.java index c0461bc598ed..1d70a0dbc57c 100644 --- a/media/java/android/media/MediaCodec.java +++ b/media/java/android/media/MediaCodec.java @@ -46,6 +46,7 @@ import java.util.Collections; import java.util.HashMap; import java.util.HashSet; import java.util.Map; +import java.util.Objects; import java.util.Set; import java.util.concurrent.BlockingQueue; import java.util.concurrent.LinkedBlockingQueue; @@ -3048,16 +3049,47 @@ final public class MediaCodec { * @param block The linear block object * @param offset The byte offset into the input buffer at which the data starts. * @param size The number of bytes of valid input data. - * @param cryptoInfo Metadata describing the structure of the encrypted input sample. - * may be null for non-encrypted content. * @return this object * @throws IllegalStateException if a buffer is already set */ public @NonNull QueueRequest setLinearBlock( @NonNull LinearBlock block, int offset, + int size) { + if (!isAccessible()) { + throw new IllegalStateException("The request is stale"); + } + if (mLinearBlock != null || mHardwareBuffer != null) { + throw new IllegalStateException("Cannot set block twice"); + } + mLinearBlock = block; + mOffset = offset; + mSize = size; + mCryptoInfo = null; + return this; + } + + /** + * Set an encrypted linear block to this queue request. Exactly one buffer must be + * set for a queue request before calling {@link #queue}. It is possible + * to use the same {@link LinearBlock} object for multiple queue + * requests. The behavior is undefined if the range of the buffer + * overlaps for multiple requests, or the application writes into the + * region being processed by the codec. + * + * @param block The linear block object + * @param offset The byte offset into the input buffer at which the data starts. + * @param size The number of bytes of valid input data. + * @param cryptoInfo Metadata describing the structure of the encrypted input sample. + * @return this object + * @throws IllegalStateException if a buffer is already set + */ + public @NonNull QueueRequest setEncryptedLinearBlock( + @NonNull LinearBlock block, + int offset, int size, - @Nullable MediaCodec.CryptoInfo cryptoInfo) { + @NonNull MediaCodec.CryptoInfo cryptoInfo) { + Objects.requireNonNull(cryptoInfo); if (!isAccessible()) { throw new IllegalStateException("The request is stale"); } |