Package org.robolectric.shadows
Class ShadowMediaCodec
java.lang.Object
org.robolectric.shadows.ShadowMediaCodec
Implementation of
MediaCodec which supports both asynchronous and
synchronous modes.
By default for any encoded required, a 1 to 1 mapping will be used between the input and
output buffers. Data from a queued input buffer will be copied to the output buffer. In the case
that is it necessary so simulate some form of data compression, a custom encoder or decoder can
be added via addEncoder(String, CodecConfig) and addDecoder(String, CodecConfig) respectively.
Asynchronous mode: Once the codec is started, a format change will be reported, switching to
an empty MediaFormat with fake codec-specific info. Following this, the
implementation will present an input buffer, which will be copied to an output buffer once
queued, which will be subsequently presented to the callback handler.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic final classConfiguration that can be supplied toShadowMediaCodecto simulate actual encoding/decoding.protected static classShadows CodecBuffer to prevent attempting to free non-direct ByteBuffer objects. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprotected void__constructor__(String name, boolean nameIsType, boolean encoder) static voidaddDecoder(String type, ShadowMediaCodec.CodecConfig config) Add a fake decoding codec to the Shadow.static voidaddEncoder(String type, ShadowMediaCodec.CodecConfig config) Add a fake encoding codec to the Shadow.static voidClears any previously added encoders and decoders.protected voidfreeByteBuffer(ByteBuffer buffer) Prevents attempting to free non-direct ByteBuffer objects.protected voidfreeByteBufferLocked(ByteBuffer buffer) protected ByteBuffergetBuffer(boolean input, int index) Returns the input or output buffer corresponding to the given index, or null if invalid.protected ByteBuffer[]getBuffers(boolean input) Returns the shadow buffers used for input or output.protected MediaFormatReturnsMediaFormatset as input format viaMediaCodec.configure(android.media.MediaFormat, android.view.Surface, android.media.MediaCrypto, int).protected MediaFormatReturnsMediaFormatset as output format viaMediaCodec.configure(android.media.MediaFormat, android.view.Surface, android.media.MediaCrypto, int).protected voidinvalidateByteBuffer(ByteBuffer[] buffers, int index) Prevents calling Android-only methods on basic ByteBuffer objects.protected voidinvalidateByteBufferLocked(ByteBuffer[] buffers, int index, boolean input) protected voidinvalidateByteBuffers(ByteBuffer[] buffers) Prevents calling Android-only methods on basic ByteBuffer objects.protected voidinvalidateByteBuffersLocked(ByteBuffer[] buffers) protected voidnative_configure(String[] keys, Object[] values, Surface surface, MediaCrypto crypto, int flags) protected voidnative_configure(String[] keys, Object[] values, Surface surface, MediaCrypto crypto, IBinder descramblerBinder, int flags) protected voidnative_configure(String[] keys, Object[] values, Surface surface, MediaCrypto crypto, Object descramblerBinder, int flags) protected intnative_dequeueInputBuffer(long timeoutUs) protected intnative_dequeueOutputBuffer(MediaCodec.BufferInfo info, long timeoutUs) protected voidFlushes the available output buffers.protected voidnative_queueInputBuffer(int index, int offset, int size, long presentationTimeUs, int flags) Triggers presentation of the corresponding output buffer for the given input buffer, and passes the given metadata as buffer info.protected voidnative_setCallback(MediaCodec.Callback callback) Saves the callback to allow use inside the shadow.protected voidStarts the async encoding process, by first reporting a format change event, and then presenting an input buffer to the callback.protected voidreleaseOutputBuffer(int index, boolean renderer) protected voidreleaseOutputBuffer(int index, long renderTimestampNs) protected voidrevalidateByteBuffer(ByteBuffer[] buffers, int index) Prevents calling Android-only methods on basic ByteBuffer objects.protected voidrevalidateByteBuffer(ByteBuffer[] buffers, int index, boolean input) protected voidvalidateInputByteBuffer(ByteBuffer[] buffers, int index) Prevents calling Android-only methods on basic ByteBuffer objects.protected voidvalidateInputByteBufferLocked(ByteBuffer[] buffers, int index) protected voidvalidateOutputByteBuffer(ByteBuffer[] buffers, int index, MediaCodec.BufferInfo info) Prevents calling Android-only methods on basic ByteBuffer objects.protected voidvalidateOutputByteBufferLocked(ByteBuffer[] buffers, int index, MediaCodec.BufferInfo info)
-
Constructor Details
-
ShadowMediaCodec
public ShadowMediaCodec()
-
-
Method Details
-
addEncoder
Add a fake encoding codec to the Shadow. -
addDecoder
Add a fake decoding codec to the Shadow. -
clearCodecs
Clears any previously added encoders and decoders. -
__constructor__
-
native_setCallback
Saves the callback to allow use inside the shadow. -
native_configure
@Implementation(maxSdk=25) protected void native_configure(String[] keys, Object[] values, Surface surface, MediaCrypto crypto, int flags) -
native_configure
@Implementation(minSdk=26, maxSdk=26) protected void native_configure(String[] keys, Object[] values, Surface surface, MediaCrypto crypto, IBinder descramblerBinder, int flags) -
native_configure
@Implementation(minSdk=27) protected void native_configure(String[] keys, Object[] values, Surface surface, MediaCrypto crypto, Object descramblerBinder, int flags) -
native_start
Starts the async encoding process, by first reporting a format change event, and then presenting an input buffer to the callback. -
native_flush
Flushes the available output buffers. -
getBuffers
Returns the shadow buffers used for input or output. -
getBuffer
Returns the input or output buffer corresponding to the given index, or null if invalid. -
native_dequeueInputBuffer
-
native_queueInputBuffer
@Implementation protected void native_queueInputBuffer(int index, int offset, int size, long presentationTimeUs, int flags) Triggers presentation of the corresponding output buffer for the given input buffer, and passes the given metadata as buffer info. -
native_dequeueOutputBuffer
@Implementation protected int native_dequeueOutputBuffer(MediaCodec.BufferInfo info, long timeoutUs) -
releaseOutputBuffer
-
releaseOutputBuffer
-
invalidateByteBuffer
@Implementation(maxSdk=33) protected void invalidateByteBuffer(@Nullable ByteBuffer[] buffers, int index) Prevents calling Android-only methods on basic ByteBuffer objects. -
invalidateByteBufferLocked
@Implementation(minSdk=34) protected void invalidateByteBufferLocked(@Nullable ByteBuffer[] buffers, int index, boolean input) -
validateInputByteBuffer
@Implementation(maxSdk=33) protected void validateInputByteBuffer(@Nullable ByteBuffer[] buffers, int index) Prevents calling Android-only methods on basic ByteBuffer objects. -
validateInputByteBufferLocked
@Implementation(minSdk=34) protected void validateInputByteBufferLocked(@Nullable ByteBuffer[] buffers, int index) -
revalidateByteBuffer
@Implementation(maxSdk=33) protected void revalidateByteBuffer(@Nullable ByteBuffer[] buffers, int index) Prevents calling Android-only methods on basic ByteBuffer objects. -
revalidateByteBuffer
@Implementation(minSdk=34) protected void revalidateByteBuffer(@Nullable ByteBuffer[] buffers, int index, boolean input) -
validateOutputByteBuffer
@Implementation(maxSdk=33) protected void validateOutputByteBuffer(@Nullable ByteBuffer[] buffers, int index, @Nonnull MediaCodec.BufferInfo info) Prevents calling Android-only methods on basic ByteBuffer objects. Replicates existing behavior adjusting buffer positions and limits. -
validateOutputByteBufferLocked
@Implementation(minSdk=34) protected void validateOutputByteBufferLocked(@Nullable ByteBuffer[] buffers, int index, @Nonnull MediaCodec.BufferInfo info) -
invalidateByteBuffers
Prevents calling Android-only methods on basic ByteBuffer objects. -
invalidateByteBuffersLocked
@Implementation(minSdk=34) protected void invalidateByteBuffersLocked(@Nullable ByteBuffer[] buffers) -
freeByteBuffer
Prevents attempting to free non-direct ByteBuffer objects. -
freeByteBufferLocked
-
getOutputFormat
ReturnsMediaFormatset as output format viaMediaCodec.configure(android.media.MediaFormat, android.view.Surface, android.media.MediaCrypto, int).- Throws:
IllegalStateException- if not in configured state.
-
getInputFormat
ReturnsMediaFormatset as input format viaMediaCodec.configure(android.media.MediaFormat, android.view.Surface, android.media.MediaCrypto, int).- Throws:
IllegalStateException- if not in configured state.
-