SimpleSubtitleDecoder


@UnstableApi
public abstract class SimpleSubtitleDecoder extends SimpleDecoder implements SubtitleDecoder


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

Summary

Public fields

final String

Protected constructors

Public methods

final String

Returns the name of the decoder.

void
setPositionUs(long positionUs)

Informs the decoder of the current playback position.

Protected methods

final SubtitleInputBuffer

Creates a new input buffer.

final SubtitleOutputBuffer

Creates a new output buffer.

final SubtitleDecoderException

Creates an exception to propagate for an unexpected decode error.

abstract Subtitle
decode(byte[] data, int length, boolean reset)

Decodes data into a Subtitle.

final @Nullable SubtitleDecoderException
decode(
    SubtitleInputBuffer inputBuffer,
    SubtitleOutputBuffer outputBuffer,
    boolean reset
)

Decodes the inputBuffer and stores any decoded output in outputBuffer.

Inherited methods

From androidx.media3.decoder.SimpleDecoder
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 boolean

Returns whether a sample time is greater or equal to the output start time, if set.

final void
queueInputBuffer(I inputBuffer)

Queues an input buffer to the decoder.

void

Releases the decoder.

void

Releases an output buffer back to the decoder.

final void

Sets the initial size of each input buffer.

final void
setOutputStartTimeUs(long outputStartTimeUs)

Sets the timestamp from which output buffers should be produced, in microseconds.

Public fields

name

public final String name

Protected constructors

SimpleSubtitleDecoder

protected SimpleSubtitleDecoder(String name)
Parameters
String name

The name of the decoder.

Public methods

getName

public final String getName()

Returns the name of the decoder.

Returns
String

The name of the decoder.

setPositionUs

public void setPositionUs(long positionUs)

Informs the decoder of the current playback position.

Must be called prior to each attempt to dequeue output buffers from the decoder.

Parameters
long positionUs

The current playback position in microseconds.

Protected methods

createInputBuffer

protected final SubtitleInputBuffer createInputBuffer()

Creates a new input buffer.

createOutputBuffer

protected final SubtitleOutputBuffer createOutputBuffer()

Creates a new output buffer.

createUnexpectedDecodeException

protected final SubtitleDecoderException createUnexpectedDecodeException(Throwable error)

Creates an exception to propagate for an unexpected decode error.

Parameters
Throwable error

The unexpected decode error.

Returns
SubtitleDecoderException

The exception to propagate.

decode

protected abstract Subtitle decode(byte[] data, int length, boolean reset)

Decodes data into a Subtitle.

Parameters
byte[] data

An array holding the data to be decoded, starting at position 0.

int length

The number of bytes from data to be decoded.

boolean reset

Whether the decoder must be reset before decoding.

Returns
Subtitle

The decoded Subtitle.

Throws
androidx.media3.extractor.text.SubtitleDecoderException

If a decoding error occurs.

decode

protected final @Nullable SubtitleDecoderException decode(
    SubtitleInputBuffer inputBuffer,
    SubtitleOutputBuffer outputBuffer,
    boolean reset
)

Decodes the inputBuffer and stores any decoded output in outputBuffer.

Parameters
SubtitleInputBuffer inputBuffer

The buffer to decode.

SubtitleOutputBuffer outputBuffer

The output buffer to store decoded data. The output buffer will not be made available to dequeue if its timeUs is not at least the output start time or when it's marked with shouldBeSkipped. The output buffer may not have been populated in these cases.

boolean reset

Whether the decoder must be reset before decoding.

Returns
@Nullable SubtitleDecoderException

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