Stay organized with collections Save and categorize content based on your preferences.

SimpleDecoder

@UnstableApi
public abstract class SimpleDecoder<I extends DecoderInputBuffer, O extends DecoderOutputBuffer, E extends DecoderException> implements Decoder

Known direct subclasses
SimpleSubtitleDecoder

Base class for subtitle parsers that use their own decode thread.

Known indirect subclasses
DvbDecoder

A SimpleSubtitleDecoder for DVB subtitles.

Mp4WebvttDecoder

A SimpleSubtitleDecoder for Webvtt embedded in a Mp4 container file.

PgsDecoder

A SimpleSubtitleDecoder for PGS subtitles.

SsaDecoder

A SimpleSubtitleDecoder for SSA/ASS.

SubripDecoder

A SimpleSubtitleDecoder for SubRip.

TtmlDecoder

A SimpleSubtitleDecoder for TTML supporting the DFXP presentation profile.

Tx3gDecoder

A SimpleSubtitleDecoder for tx3g.

WebvttDecoder

A SimpleSubtitleDecoder for WebVTT.


Base class for Decoders that use their own decode thread and decode each input buffer immediately into a corresponding output buffer.

Summary

Protected constructors

SimpleDecoder(I[] inputBuffers, O[] outputBuffers)

Public methods

final @Nullable I

Dequeues the next input buffer to be filled and queued to the decoder.

final @Nullable O

Dequeues the next output buffer from the decoder.

final void

Flushes the decoder.

final void
queueInputBuffer(I inputBuffer)

Queues an input buffer to the decoder.

void

Releases the decoder.

Protected methods

abstract I

Creates a new input buffer.

abstract O

Creates a new output buffer.

abstract E

Creates an exception to propagate for an unexpected decode error.

abstract @Nullable E
decode(I inputBuffer, O outputBuffer, boolean reset)

Decodes the inputBuffer and stores any decoded output in outputBuffer.

void

Releases an output buffer back to the decoder.

final void

Sets the initial size of each input buffer.

Inherited methods

From androidx.media3.decoder.Decoder
abstract String

Returns the name of the decoder.

Protected constructors

SimpleDecoder

protected SimpleDecoder(I[] inputBuffers, O[] outputBuffers)
Parameters
I[] inputBuffers

An array of nulls that will be used to store references to input buffers.

O[] outputBuffers

An array of nulls that will be used to store references to output buffers.

Public methods

dequeueInputBuffer

public final @NullabledequeueInputBuffer()

Dequeues the next input buffer to be filled and queued to the decoder.

Returns
@Nullable I

The input buffer, which will have been cleared, or null if a buffer isn't available.

Throws
E E

If a decoder error has occurred.

androidx.media3.decoder.SimpleDecoder androidx.media3.decoder.SimpleDecoder

dequeueOutputBuffer

public final @NullabledequeueOutputBuffer()

Dequeues the next output buffer from the decoder.

Returns
@Nullable O

The output buffer, or null if an output buffer isn't available.

Throws
E E

If a decoder error has occurred.

androidx.media3.decoder.SimpleDecoder androidx.media3.decoder.SimpleDecoder

flush

public final void flush()

Flushes the decoder. Ownership of dequeued input buffers is returned to the decoder. The caller is still responsible for releasing any dequeued output buffers.

queueInputBuffer

public final void queueInputBuffer(I inputBuffer)

Queues an input buffer to the decoder.

Parameters
I inputBuffer

The input buffer.

Throws
E E

If a decoder error has occurred.

androidx.media3.decoder.SimpleDecoder androidx.media3.decoder.SimpleDecoder

release

@CallSuper
public void release()

Releases the decoder. Must be called when the decoder is no longer needed.

Protected methods

createInputBuffer

protected abstract I createInputBuffer()

Creates a new input buffer.

createOutputBuffer

protected abstract O createOutputBuffer()

Creates a new output buffer.

createUnexpectedDecodeException

protected abstract E createUnexpectedDecodeException(Throwable error)

Creates an exception to propagate for an unexpected decode error.

Parameters
Throwable error

The unexpected decode error.

Returns
E

The exception to propagate.

decode

protected abstract @Nullabledecode(I inputBuffer, O outputBuffer, boolean reset)

Decodes the inputBuffer and stores any decoded output in outputBuffer.

Parameters
I inputBuffer

The buffer to decode.

O outputBuffer

The output buffer to store decoded data. The flag BUFFER_FLAG_DECODE_ONLY will be set if the same flag is set on inputBuffer, but may be set/unset as required. If the flag is set when the call returns then the output buffer will not be made available to dequeue. The output buffer may not have been populated in this case.

boolean reset

Whether the decoder must be reset before decoding.

Returns
@Nullable E

A decoder exception if an error occurred, or null if decoding was successful.

releaseOutputBuffer

@CallSuper
protected void releaseOutputBuffer(O outputBuffer)

Releases an output buffer back to the decoder.

Parameters
O outputBuffer

The output buffer being released.

setInitialInputBufferSize

protected final void setInitialInputBufferSize(int size)

Sets the initial size of each input buffer.

This method should only be called before the decoder is used (i.e. before the first call to dequeueInputBuffer.

Parameters
int size

The required input buffer size.