@Implements(value=android.media.MediaCodec.class, minSdk=16) public class ShadowMediaCodec extends Object
Implementation of MediaCodec
which only supports a passthrough asynchronous encoding pipeline.
Once the pipeline 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 directly copied to an output buffer once queued, which will be subsequently presented to the callback handler.
Modifier and Type | Class and Description |
---|---|
protected static class |
ShadowMediaCodec.ShadowCodecBuffer
Shadows CodecBuffer to prevent attempting to free non-direct ByteBuffer objects.
|
Constructor and Description |
---|
ShadowMediaCodec() |
Modifier and Type | Method and Description |
---|---|
protected void |
freeByteBuffer(ByteBuffer buffer)
Prevents attempting to free non-direct ByteBuffer objects.
|
protected ByteBuffer |
getBuffer(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 void |
invalidateByteBuffer(ByteBuffer[] buffers,
int index)
Prevents calling Android-only methods on basic ByteBuffer objects.
|
protected void |
invalidateByteBuffers(ByteBuffer[] buffers)
Prevents calling Android-only methods on basic ByteBuffer objects.
|
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.
|
protected void |
native_setCallback(MediaCodec.Callback callback)
Saves the callback to allow use inside the shadow.
|
protected void |
native_start()
Starts the async encoding process, by first reporting a format change event, and then presenting an input buffer to the callback.
|
protected void |
releaseOutputBuffer(int index,
boolean render,
boolean updatePTS,
long timeNs)
Triggers presentation of the corresponding input buffer for the given output buffer, if end of stream has not yet been signaled.
|
protected void |
revalidateByteBuffer(ByteBuffer[] buffers,
int index)
Prevents calling Android-only methods on basic ByteBuffer objects.
|
protected void |
validateInputByteBuffer(ByteBuffer[] buffers,
int index)
Prevents calling Android-only methods on basic ByteBuffer objects.
|
protected void |
validateOutputByteBuffer(ByteBuffer[] buffers,
int index,
MediaCodec.BufferInfo info)
Prevents calling Android-only methods on basic ByteBuffer objects.
|
@Implementation(minSdk=21) protected void native_setCallback(MediaCodec.Callback callback)
Saves the callback to allow use inside the shadow.
@Implementation(minSdk=21) protected void native_start()
Starts the async encoding process, by first reporting a format change event, and then presenting an input buffer to the callback.
@Implementation protected ByteBuffer[] getBuffers(boolean input)
Returns the shadow buffers used for input or output.
@Implementation(minSdk=21) protected ByteBuffer getBuffer(boolean input, int index)
Returns the input or output buffer corresponding to the given index, or null if invalid.
@Implementation(minSdk=21) 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.
@Implementation(minSdk=21) protected void releaseOutputBuffer(int index, boolean render, boolean updatePTS, long timeNs)
Triggers presentation of the corresponding input buffer for the given output buffer, if end of stream has not yet been signaled.
@Implementation(minSdk=21) protected void invalidateByteBuffer(ByteBuffer[] buffers, int index)
Prevents calling Android-only methods on basic ByteBuffer objects.
@Implementation(minSdk=21) protected void validateInputByteBuffer(ByteBuffer[] buffers, int index)
Prevents calling Android-only methods on basic ByteBuffer objects.
@Implementation(minSdk=21) protected void revalidateByteBuffer(ByteBuffer[] buffers, int index)
Prevents calling Android-only methods on basic ByteBuffer objects.
@Implementation(minSdk=21) protected void validateOutputByteBuffer(ByteBuffer[] buffers, int index, MediaCodec.BufferInfo info)
Prevents calling Android-only methods on basic ByteBuffer objects. Replicates existing behavior adjusting buffer positions and limits.
@Implementation(minSdk=21) protected void invalidateByteBuffers(ByteBuffer[] buffers)
Prevents calling Android-only methods on basic ByteBuffer objects.
@Implementation(minSdk=21) protected void freeByteBuffer(ByteBuffer buffer)
Prevents attempting to free non-direct ByteBuffer objects.