Class SynchronousMediaCodecAdapter
- java.lang.Object
-
- com.google.android.exoplayer2.mediacodec.SynchronousMediaCodecAdapter
-
- All Implemented Interfaces:
MediaCodecAdapter
public class SynchronousMediaCodecAdapter extends Object implements MediaCodecAdapter
AMediaCodecAdapterthat operates the underlyingMediaCodecin synchronous mode.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static classSynchronousMediaCodecAdapter.FactoryA factory forSynchronousMediaCodecAdapterinstances.-
Nested classes/interfaces inherited from interface com.google.android.exoplayer2.mediacodec.MediaCodecAdapter
MediaCodecAdapter.Configuration, MediaCodecAdapter.OnFrameRenderedListener
-
-
Method Summary
All Methods Instance Methods Concrete 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
-
needsReconfiguration
public boolean needsReconfiguration()
Description copied from interface:MediaCodecAdapterWhether the adapter needs to be reconfigured before it is used.- Specified by:
needsReconfigurationin interfaceMediaCodecAdapter
-
dequeueInputBufferIndex
public int dequeueInputBufferIndex()
Description copied from interface:MediaCodecAdapterReturns the next available input buffer index from the underlyingMediaCodecorMediaCodec.INFO_TRY_AGAIN_LATERif no such buffer exists.- Specified by:
dequeueInputBufferIndexin interfaceMediaCodecAdapter
-
dequeueOutputBufferIndex
public int dequeueOutputBufferIndex(MediaCodec.BufferInfo bufferInfo)
Description copied from interface:MediaCodecAdapterReturns 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 callMediaCodecAdapter.getOutputFormat()to get the format. If there is no available output, this method will returnMediaCodec.INFO_TRY_AGAIN_LATER.- Specified by:
dequeueOutputBufferIndexin interfaceMediaCodecAdapter
-
getOutputFormat
public MediaFormat getOutputFormat()
Description copied from interface:MediaCodecAdapterGets theMediaFormatthat was output from theMediaCodec.Call this method if a previous call to
MediaCodecAdapter.dequeueOutputBufferIndex(android.media.MediaCodec.BufferInfo)returnedMediaCodec.INFO_OUTPUT_FORMAT_CHANGED.- Specified by:
getOutputFormatin interfaceMediaCodecAdapter
-
getInputBuffer
@Nullable public ByteBuffer getInputBuffer(int index)
Description copied from interface:MediaCodecAdapterReturns a writable ByteBuffer object for a dequeued input buffer index.- Specified by:
getInputBufferin interfaceMediaCodecAdapter- See Also:
MediaCodec.getInputBuffer(int)
-
getInputSurface
@Nullable public Surface getInputSurface()
Description copied from interface:MediaCodecAdapterReturns the inputSurface, or null if the input is not a surface.- Specified by:
getInputSurfacein interfaceMediaCodecAdapter- See Also:
MediaCodec.createInputSurface()
-
getOutputBuffer
@Nullable public ByteBuffer getOutputBuffer(int index)
Description copied from interface:MediaCodecAdapterReturns a read-only ByteBuffer for a dequeued output buffer index.- Specified by:
getOutputBufferin interfaceMediaCodecAdapter- See Also:
MediaCodec.getOutputBuffer(int)
-
queueInputBuffer
public void queueInputBuffer(int index, int offset, int size, long presentationTimeUs, int flags)Description copied from interface:MediaCodecAdapterSubmit an input buffer for decoding.The
indexmust be an input buffer index that has been obtained from a previous call toMediaCodecAdapter.dequeueInputBufferIndex().- Specified by:
queueInputBufferin interfaceMediaCodecAdapter- See Also:
MediaCodec.queueInputBuffer(int, int, int, long, int)
-
queueSecureInputBuffer
public void queueSecureInputBuffer(int index, int offset, CryptoInfo info, long presentationTimeUs, int flags)Description copied from interface:MediaCodecAdapterSubmit an input buffer that is potentially encrypted for decoding.The
indexmust be an input buffer index that has been obtained from a previous call toMediaCodecAdapter.dequeueInputBufferIndex().This method behaves like
MediaCodec.queueSecureInputBuffer(int, int, android.media.MediaCodec.CryptoInfo, long, int), with the difference thatinfois of typeCryptoInfoand notMediaCodec.CryptoInfo.- Specified by:
queueSecureInputBufferin interfaceMediaCodecAdapter- See Also:
MediaCodec.queueSecureInputBuffer(int, int, android.media.MediaCodec.CryptoInfo, long, int)
-
releaseOutputBuffer
public void releaseOutputBuffer(int index, boolean render)Description copied from interface:MediaCodecAdapterReturns 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.- Specified by:
releaseOutputBufferin interfaceMediaCodecAdapter- See Also:
MediaCodec.releaseOutputBuffer(int, boolean)
-
releaseOutputBuffer
@RequiresApi(21) public void releaseOutputBuffer(int index, long renderTimeStampNs)Description copied from interface:MediaCodecAdapterUpdates 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.- Specified by:
releaseOutputBufferin interfaceMediaCodecAdapter- See Also:
MediaCodec.releaseOutputBuffer(int, long)
-
flush
public void flush()
Description copied from interface:MediaCodecAdapterFlushes the adapter and the underlyingMediaCodec.- Specified by:
flushin interfaceMediaCodecAdapter
-
release
public void release()
Description copied from interface:MediaCodecAdapterReleases the adapter and the underlyingMediaCodec.- Specified by:
releasein interfaceMediaCodecAdapter
-
signalEndOfInputStream
@RequiresApi(18) public void signalEndOfInputStream()
Description copied from interface:MediaCodecAdapterSignals the encoder of end-of-stream on input. The call can only be used when the encoder receives its input from asurface.- Specified by:
signalEndOfInputStreamin interfaceMediaCodecAdapter- See Also:
MediaCodec.signalEndOfInputStream()
-
setOnFrameRenderedListener
@RequiresApi(23) public void setOnFrameRenderedListener(MediaCodecAdapter.OnFrameRenderedListener listener, Handler handler)
Description copied from interface:MediaCodecAdapterRegisters a callback to be invoked when an output frame is rendered on the output surface.- Specified by:
setOnFrameRenderedListenerin interfaceMediaCodecAdapter- See Also:
MediaCodec.setOnFrameRenderedListener(android.media.MediaCodec.OnFrameRenderedListener, android.os.Handler)
-
setOutputSurface
@RequiresApi(23) public void setOutputSurface(Surface surface)
Description copied from interface:MediaCodecAdapterDynamically sets the output surface of aMediaCodec.- Specified by:
setOutputSurfacein interfaceMediaCodecAdapter- See Also:
MediaCodec.setOutputSurface(Surface)
-
setParameters
@RequiresApi(19) public void setParameters(Bundle params)
Description copied from interface:MediaCodecAdapterCommunicate additional parameter changes to theMediaCodecinstance.- Specified by:
setParametersin interfaceMediaCodecAdapter- See Also:
MediaCodec.setParameters(Bundle)
-
setVideoScalingMode
public void setVideoScalingMode(@VideoScalingMode int scalingMode)
Description copied from interface:MediaCodecAdapterSpecifies the scaling mode to use, if a surface was specified when the codec was created.- Specified by:
setVideoScalingModein interfaceMediaCodecAdapter- See Also:
MediaCodec.setVideoScalingMode(int)
-
-