Interface MediaCodecAdapter
-
- All Known Implementing Classes:
SynchronousMediaCodecAdapter
public interface MediaCodecAdapterAbstractsMediaCodecoperations.MediaCodecAdapteroffers a common interface to interact with aMediaCodecregardless of the mode theMediaCodecis operating in.
-
-
Nested Class Summary
Nested Classes Modifier and Type Interface Description static classMediaCodecAdapter.ConfigurationConfiguration parameters for aMediaCodecAdapter.static interfaceMediaCodecAdapter.FactoryA factory forMediaCodecAdapterinstances.static interfaceMediaCodecAdapter.OnFrameRenderedListenerListener to be called when an output frame has rendered on the output surface.
-
Method Summary
All Methods Instance Methods Abstract Methods Modifier and Type Method Description intdequeueInputBufferIndex()Returns the next available input buffer index from the underlyingMediaCodecorMediaCodec.INFO_TRY_AGAIN_LATERif no such buffer exists.intdequeueOutputBufferIndex(MediaCodec.BufferInfo bufferInfo)Returns the next available output buffer index from the underlyingMediaCodec.voidflush()Flushes the adapter and the underlyingMediaCodec.ByteBuffergetInputBuffer(int index)Returns a writable ByteBuffer object for a dequeued input buffer index.SurfacegetInputSurface()Returns the inputSurface, or null if the input is not a surface.ByteBuffergetOutputBuffer(int index)Returns a read-only ByteBuffer for a dequeued output buffer index.MediaFormatgetOutputFormat()Gets theMediaFormatthat was output from theMediaCodec.booleanneedsReconfiguration()Whether the adapter needs to be reconfigured before it is used.voidqueueInputBuffer(int index, int offset, int size, long presentationTimeUs, int flags)Submit an input buffer for decoding.voidqueueSecureInputBuffer(int index, int offset, CryptoInfo info, long presentationTimeUs, int flags)Submit an input buffer that is potentially encrypted for decoding.voidrelease()Releases the adapter and the underlyingMediaCodec.voidreleaseOutputBuffer(int index, boolean render)Returns the buffer to theMediaCodec.voidreleaseOutputBuffer(int index, long renderTimeStampNs)Updates the output buffer's surface timestamp and sends it to theMediaCodecto render it on the output surface.voidsetOnFrameRenderedListener(MediaCodecAdapter.OnFrameRenderedListener listener, Handler handler)Registers a callback to be invoked when an output frame is rendered on the output surface.voidsetOutputSurface(Surface surface)Dynamically sets the output surface of aMediaCodec.voidsetParameters(Bundle params)Communicate additional parameter changes to theMediaCodecinstance.voidsetVideoScalingMode(int scalingMode)Specifies the scaling mode to use, if a surface was specified when the codec was created.voidsignalEndOfInputStream()Signals the encoder of end-of-stream on input.
-
-
-
Method Detail
-
dequeueInputBufferIndex
int dequeueInputBufferIndex()
Returns the next available input buffer index from the underlyingMediaCodecorMediaCodec.INFO_TRY_AGAIN_LATERif no such buffer exists.- Throws:
IllegalStateException- If the underlyingMediaCodecraised an error.
-
dequeueOutputBufferIndex
int dequeueOutputBufferIndex(MediaCodec.BufferInfo bufferInfo)
Returns the next available output buffer index from the underlyingMediaCodec. If the next available output is a MediaFormat change, it will returnMediaCodec.INFO_OUTPUT_FORMAT_CHANGEDand you should callgetOutputFormat()to get the format. If there is no available output, this method will returnMediaCodec.INFO_TRY_AGAIN_LATER.- Throws:
IllegalStateException- If the underlyingMediaCodecraised an error.
-
getOutputFormat
MediaFormat getOutputFormat()
Gets theMediaFormatthat was output from theMediaCodec.Call this method if a previous call to
dequeueOutputBufferIndex(android.media.MediaCodec.BufferInfo)returnedMediaCodec.INFO_OUTPUT_FORMAT_CHANGED.
-
getInputBuffer
@Nullable ByteBuffer getInputBuffer(int index)
Returns a writable ByteBuffer object for a dequeued input buffer index.- See Also:
MediaCodec.getInputBuffer(int)
-
getInputSurface
@Nullable Surface getInputSurface()
Returns the inputSurface, or null if the input is not a surface.- See Also:
MediaCodec.createInputSurface()
-
getOutputBuffer
@Nullable ByteBuffer getOutputBuffer(int index)
Returns a read-only ByteBuffer for a dequeued output buffer index.- See Also:
MediaCodec.getOutputBuffer(int)
-
queueInputBuffer
void queueInputBuffer(int index, int offset, int size, long presentationTimeUs, int flags)Submit an input buffer for decoding.The
indexmust be an input buffer index that has been obtained from a previous call todequeueInputBufferIndex().
-
queueSecureInputBuffer
void queueSecureInputBuffer(int index, int offset, CryptoInfo info, long presentationTimeUs, int flags)Submit an input buffer that is potentially encrypted for decoding.The
indexmust be an input buffer index that has been obtained from a previous call todequeueInputBufferIndex().This method behaves like
MediaCodec.queueSecureInputBuffer(int, int, android.media.MediaCodec.CryptoInfo, long, int), with the difference thatinfois of typeCryptoInfoand notMediaCodec.CryptoInfo.
-
releaseOutputBuffer
void releaseOutputBuffer(int index, boolean render)Returns the buffer to theMediaCodec. If theMediaCodecwas configured with an output surface, settingrendertotruewill 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
@RequiresApi(21) void releaseOutputBuffer(int index, long renderTimeStampNs)Updates the output buffer's surface timestamp and sends it to theMediaCodecto render it on the output surface. If theMediaCodecis not configured with an output surface, this call will simply return the buffer to theMediaCodec.
-
flush
void flush()
Flushes the adapter and the underlyingMediaCodec.
-
release
void release()
Releases the adapter and the underlyingMediaCodec.
-
setOnFrameRenderedListener
@RequiresApi(23) void setOnFrameRenderedListener(MediaCodecAdapter.OnFrameRenderedListener listener, Handler handler)
Registers a callback to be invoked when an output frame is rendered on the output surface.
-
setOutputSurface
@RequiresApi(23) void setOutputSurface(Surface surface)
Dynamically sets the output surface of aMediaCodec.- See Also:
MediaCodec.setOutputSurface(Surface)
-
setParameters
@RequiresApi(19) void setParameters(Bundle params)
Communicate additional parameter changes to theMediaCodecinstance.- See Also:
MediaCodec.setParameters(Bundle)
-
setVideoScalingMode
void setVideoScalingMode(@VideoScalingMode int scalingMode)
Specifies the scaling mode to use, if a surface was specified when the codec was created.- See Also:
MediaCodec.setVideoScalingMode(int)
-
needsReconfiguration
boolean needsReconfiguration()
Whether the adapter needs to be reconfigured before it is used.
-
signalEndOfInputStream
@RequiresApi(18) void signalEndOfInputStream()
Signals the encoder of end-of-stream on input. The call can only be used when the encoder receives its input from asurface.- See Also:
MediaCodec.signalEndOfInputStream()
-
-