MediaCodecAdapterpublic final class SynchronousMediaCodecAdapter extends Object implements MediaCodecAdapter
MediaCodecAdapter that operates the underlying MediaCodec in synchronous mode.| Modifier and Type | Class | Description |
|---|---|---|
static class |
SynchronousMediaCodecAdapter.Factory |
A factory for
SynchronousMediaCodecAdapter instances. |
MediaCodecAdapter.OnFrameRenderedListener| Modifier and Type | Method | Description |
|---|---|---|
void |
configure(MediaFormat mediaFormat,
Surface surface,
MediaCrypto crypto,
int flags) |
Configures this adapter and the underlying
MediaCodec. |
int |
dequeueInputBufferIndex() |
Returns the next available input buffer index from the underlying
MediaCodec or MediaCodec.INFO_TRY_AGAIN_LATER if no such buffer exists. |
int |
dequeueOutputBufferIndex(MediaCodec.BufferInfo bufferInfo) |
Returns the next available output buffer index from the underlying
MediaCodec. |
void |
flush() |
Flushes the adapter and the underlying
MediaCodec. |
ByteBuffer |
getInputBuffer(int index) |
Returns a writable ByteBuffer object for a dequeued input buffer index.
|
ByteBuffer |
getOutputBuffer(int index) |
Returns a read-only ByteBuffer for a dequeued output buffer index.
|
MediaFormat |
getOutputFormat() |
Gets the
MediaFormat that was output from the MediaCodec. |
void |
queueInputBuffer(int index,
int offset,
int size,
long presentationTimeUs,
int flags) |
Submit an input buffer for decoding.
|
void |
queueSecureInputBuffer(int index,
int offset,
CryptoInfo info,
long presentationTimeUs,
int flags) |
Submit an input buffer that is potentially encrypted for decoding.
|
void |
release() |
Releases the adapter and the underlying
MediaCodec. |
void |
releaseOutputBuffer(int index,
boolean render) |
Returns the buffer to the
MediaCodec. |
void |
releaseOutputBuffer(int index,
long renderTimeStampNs) |
Updates the output buffer's surface timestamp and sends it to the
MediaCodec to render
it on the output surface. |
void |
setOnFrameRenderedListener(MediaCodecAdapter.OnFrameRenderedListener listener,
Handler handler) |
Registers a callback to be invoked when an output frame is rendered on the output surface.
|
void |
setOutputSurface(Surface surface) |
Dynamically sets the output surface of a
MediaCodec. |
void |
setParameters(Bundle params) |
Communicate additional parameter changes to the
MediaCodec instance. |
void |
setVideoScalingMode(int scalingMode) |
Specifies the scaling mode to use, if a surface has been specified in a previous call to
MediaCodecAdapter.configure(android.media.MediaFormat, android.view.Surface, android.media.MediaCrypto, int). |
void |
start() |
Starts this instance.
|
public void configure(@Nullable
MediaFormat mediaFormat,
@Nullable
Surface surface,
@Nullable
MediaCrypto crypto,
int flags)
MediaCodecAdapterMediaCodec. Needs to be called before MediaCodecAdapter.start().configure in interface MediaCodecAdapterMediaCodec.configure(MediaFormat, Surface, MediaCrypto, int)public void start()
MediaCodecAdapterMediaCodecAdapter.configure(android.media.MediaFormat, android.view.Surface, android.media.MediaCrypto, int).start in interface MediaCodecAdapterMediaCodec.start()public int dequeueInputBufferIndex()
MediaCodecAdapterMediaCodec or MediaCodec.INFO_TRY_AGAIN_LATER if no such buffer exists.dequeueInputBufferIndex in interface MediaCodecAdapterpublic int dequeueOutputBufferIndex(MediaCodec.BufferInfo bufferInfo)
MediaCodecAdapterMediaCodec. If the
next available output is a MediaFormat change, it will return MediaCodec.INFO_OUTPUT_FORMAT_CHANGED and you should call MediaCodecAdapter.getOutputFormat() to get
the format. If there is no available output, this method will return MediaCodec.INFO_TRY_AGAIN_LATER.dequeueOutputBufferIndex in interface MediaCodecAdapterpublic MediaFormat getOutputFormat()
MediaCodecAdapterMediaFormat that was output from the MediaCodec.
Call this method if a previous call to MediaCodecAdapter.dequeueOutputBufferIndex(android.media.MediaCodec.BufferInfo) returned MediaCodec.INFO_OUTPUT_FORMAT_CHANGED.
getOutputFormat in interface MediaCodecAdapter@Nullable public ByteBuffer getInputBuffer(int index)
MediaCodecAdaptergetInputBuffer in interface MediaCodecAdapterMediaCodec.getInputBuffer(int)@Nullable public ByteBuffer getOutputBuffer(int index)
MediaCodecAdaptergetOutputBuffer in interface MediaCodecAdapterMediaCodec.getOutputBuffer(int)public void queueInputBuffer(int index,
int offset,
int size,
long presentationTimeUs,
int flags)
MediaCodecAdapterThe index must be an input buffer index that has been obtained from a previous call
to MediaCodecAdapter.dequeueInputBufferIndex().
queueInputBuffer in interface MediaCodecAdapterMediaCodec.queueInputBuffer(int, int, int, long, int)public void queueSecureInputBuffer(int index,
int offset,
CryptoInfo info,
long presentationTimeUs,
int flags)
MediaCodecAdapterThe index must be an input buffer index that has been obtained from a previous call
to MediaCodecAdapter.dequeueInputBufferIndex().
This method behaves like MediaCodec.queueSecureInputBuffer(int, int, android.media.MediaCodec.CryptoInfo, long, int), with the difference that
info is of type CryptoInfo and not MediaCodec.CryptoInfo.
queueSecureInputBuffer in interface MediaCodecAdapterMediaCodec.queueSecureInputBuffer(int, int, android.media.MediaCodec.CryptoInfo, long, int)public void releaseOutputBuffer(int index,
boolean render)
MediaCodecAdapterMediaCodec. If the MediaCodec was configured with an
output surface, setting render to true will first send the buffer to the output
surface. The surface will release the buffer back to the codec once it is no longer
used/displayed.releaseOutputBuffer in interface MediaCodecAdapterMediaCodec.releaseOutputBuffer(int, boolean)public void releaseOutputBuffer(int index,
long renderTimeStampNs)
MediaCodecAdapterMediaCodec to render
it on the output surface. If the MediaCodec is not configured with an output surface,
this call will simply return the buffer to the MediaCodec.releaseOutputBuffer in interface MediaCodecAdapterMediaCodec.releaseOutputBuffer(int, long)public void flush()
MediaCodecAdapterMediaCodec.flush in interface MediaCodecAdapterpublic void release()
MediaCodecAdapterMediaCodec.release in interface MediaCodecAdapterpublic void setOnFrameRenderedListener(MediaCodecAdapter.OnFrameRenderedListener listener, Handler handler)
MediaCodecAdaptersetOnFrameRenderedListener in interface MediaCodecAdapterMediaCodec.setOnFrameRenderedListener(android.media.MediaCodec.OnFrameRenderedListener, android.os.Handler)public void setOutputSurface(Surface surface)
MediaCodecAdapterMediaCodec.setOutputSurface in interface MediaCodecAdapterMediaCodec.setOutputSurface(Surface)public void setParameters(Bundle params)
MediaCodecAdapterMediaCodec instance.setParameters in interface MediaCodecAdapterMediaCodec.setParameters(Bundle)public void setVideoScalingMode(@VideoScalingMode int scalingMode)
MediaCodecAdapterMediaCodecAdapter.configure(android.media.MediaFormat, android.view.Surface, android.media.MediaCrypto, int).setVideoScalingMode in interface MediaCodecAdapterMediaCodec.setVideoScalingMode(int)