Interface Codec
-
- All Known Implementing Classes:
DefaultCodec
public interface Codec
Provides a layer of abstraction for interacting with decoders and encoders.DecoderInputBuffers
are used as both decoders' and encoders' input buffers.
-
-
Nested Class Summary
Nested Classes Modifier and Type Interface Description static interface
Codec.DecoderFactory
A factory for decoder instances.static interface
Codec.EncoderFactory
A factory for encoder instances.
-
Field Summary
Fields Modifier and Type Field Description static int
UNLIMITED_PENDING_FRAME_COUNT
Default value for the pending frame count, which represents applying no limit.
-
Method Summary
All Methods Instance Methods Abstract Methods Default Methods Modifier and Type Method Description Format
getConfigurationFormat()
Returns theFormat
used for configuring theCodec
.Surface
getInputSurface()
Returns the inputSurface
of an underlying video encoder.default int
getMaxPendingFrameCount()
Returns the maximum number of frames that may be pending in the outputCodec
at a time, orUNLIMITED_PENDING_FRAME_COUNT
if it's not necessary to enforce a limit.String
getName()
Returns the name of the underlying codec.ByteBuffer
getOutputBuffer()
Returns the current outputByteBuffer
, ornull
if unavailable.MediaCodec.BufferInfo
getOutputBufferInfo()
Returns theMediaCodec.BufferInfo
associated with the current output buffer, ornull
if there is no output buffer available.Format
getOutputFormat()
Returns the current output format, ornull
if unavailable.boolean
isEnded()
Returns whether theCodec
's output stream has ended, and no more data can be dequeued.boolean
maybeDequeueInputBuffer(DecoderInputBuffer inputBuffer)
Dequeues a writable input buffer, if available.void
queueInputBuffer(DecoderInputBuffer inputBuffer)
Queues an input buffer to theCodec
.void
release()
Releases theCodec
.void
releaseOutputBuffer(boolean render)
Releases the current output buffer.void
signalEndOfInputStream()
Signals end-of-stream on input to a video encoder.
-
-
-
Field Detail
-
UNLIMITED_PENDING_FRAME_COUNT
static final int UNLIMITED_PENDING_FRAME_COUNT
Default value for the pending frame count, which represents applying no limit.- See Also:
- Constant Field Values
-
-
Method Detail
-
getConfigurationFormat
Format getConfigurationFormat()
Returns theFormat
used for configuring theCodec
.The configuration
Format
is the inputFormat
used by theCodec.DecoderFactory
or outputFormat
used by theCodec.EncoderFactory
for selecting and configuring the underlying decoder or encoder.
-
getName
String getName()
Returns the name of the underlying codec.
-
getInputSurface
Surface getInputSurface()
-
getMaxPendingFrameCount
default int getMaxPendingFrameCount()
Returns the maximum number of frames that may be pending in the outputCodec
at a time, orUNLIMITED_PENDING_FRAME_COUNT
if it's not necessary to enforce a limit.
-
maybeDequeueInputBuffer
boolean maybeDequeueInputBuffer(DecoderInputBuffer inputBuffer) throws TransformationException
Dequeues a writable input buffer, if available.This method must not be called from video encoders because they must use a
Surface
to receive input.- Parameters:
inputBuffer
- The buffer where the dequeued buffer data is stored, atinputBuffer.data
.- Returns:
- Whether an input buffer is ready to be used.
- Throws:
TransformationException
- If the underlying decoder or encoder encounters a problem.
-
queueInputBuffer
void queueInputBuffer(DecoderInputBuffer inputBuffer) throws TransformationException
Queues an input buffer to theCodec
. No buffers may be queued after end of stream buffer has been queued.This method must not be called from video encoders because they must use a
Surface
to receive input.- Parameters:
inputBuffer
- The input buffer.- Throws:
TransformationException
- If the underlying decoder or encoder encounters a problem.
-
signalEndOfInputStream
void signalEndOfInputStream() throws TransformationException
Signals end-of-stream on input to a video encoder.This method must only be called on video encoders because they must use a
Surface
as input. For audio/video decoders or audio encoders, theC.BUFFER_FLAG_END_OF_STREAM
flag should be set on the last input buffer queued.- Throws:
TransformationException
- If the underlying video encoder encounters a problem.
-
getOutputFormat
@Nullable Format getOutputFormat() throws TransformationException
Returns the current output format, ornull
if unavailable.- Throws:
TransformationException
- If the underlying decoder or encoder encounters a problem.
-
getOutputBuffer
@Nullable ByteBuffer getOutputBuffer() throws TransformationException
Returns the current outputByteBuffer
, ornull
if unavailable.This method must not be called on video decoders because they must output to a
Surface
.- Throws:
TransformationException
- If the underlying decoder or encoder encounters a problem.
-
getOutputBufferInfo
@Nullable MediaCodec.BufferInfo getOutputBufferInfo() throws TransformationException
Returns theMediaCodec.BufferInfo
associated with the current output buffer, ornull
if there is no output buffer available.This method returns
null
if and only ifgetOutputBuffer()
returns null.- Throws:
TransformationException
- If the underlying decoder or encoder encounters a problem.
-
releaseOutputBuffer
void releaseOutputBuffer(boolean render) throws TransformationException
Releases the current output buffer.Only set
render
totrue
when theCodec
is a video decoder. Settingrender
totrue
will first render the buffer to the output surface. In this case, the surface will release the buffer back to theCodec
once it is no longer used/displayed.This should be called after the buffer has been processed. The next output buffer will not be available until the current output buffer has been released.
- Parameters:
render
- Whether the buffer needs to be rendered to the outputSurface
.- Throws:
TransformationException
- If the underlying decoder or encoder encounters a problem.
-
isEnded
boolean isEnded()
Returns whether theCodec
's output stream has ended, and no more data can be dequeued.
-
release
void release()
Releases theCodec
.
-
-