@UnstableApi
public final class Cea608Decoder implements SubtitleDecoder


A SubtitleDecoder for CEA-608 (also known as "line 21 captions" and "EIA-608").

Summary

Constants

static final long

The minimum value for the validDataChannelTimeoutMs constructor parameter permitted by ANSI/CTA-608-E R-2014 Annex C.9.

Public constructors

Cea608Decoder(
    String mimeType,
    int accessibilityChannel,
    long validDataChannelTimeoutMs
)

Constructs an instance.

Public methods

@Nullable SubtitleInputBuffer

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

@Nullable SubtitleOutputBuffer

Dequeues the next output buffer from the decoder.

void

Flushes the decoder.

String

Returns the name of the decoder.

void

Queues an input buffer to the decoder.

void

Releases the decoder.

final void
setOutputStartTimeUs(long outputStartTimeUs)

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

void
setPositionUs(long positionUs)

Informs the decoder of the current playback position.

Protected methods

Subtitle

Creates a Subtitle from the available data.

void

Filters and processes the raw data, providing Subtitles via createSubtitle when sufficient data has been processed.

final @Nullable SubtitleOutputBuffer
final long
boolean

Returns whether there is data available to create a new Subtitle.

void

Inherited methods

From androidx.media3.decoder.Decoder
abstract @Nullable I

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

abstract @Nullable O

Dequeues the next output buffer from the decoder.

abstract void
queueInputBuffer(I inputBuffer)

Queues an input buffer to the decoder.

Constants

MIN_DATA_CHANNEL_TIMEOUT_MS

public static final long MIN_DATA_CHANNEL_TIMEOUT_MS = 16000

The minimum value for the validDataChannelTimeoutMs constructor parameter permitted by ANSI/CTA-608-E R-2014 Annex C.9.

Public constructors

Cea608Decoder

public Cea608Decoder(
    String mimeType,
    int accessibilityChannel,
    long validDataChannelTimeoutMs
)

Constructs an instance.

Parameters
String mimeType

The MIME type of the CEA-608 data.

int accessibilityChannel

The Accessibility channel, or NO_VALUE if unknown.

long validDataChannelTimeoutMs

The timeout (in milliseconds) permitted by ANSI/CTA-608-E R-2014 Annex C.9 to clear "stuck" captions where no removal control code is received. The timeout should be at least MIN_DATA_CHANNEL_TIMEOUT_MS or TIME_UNSET for no timeout.

Public methods

dequeueInputBuffer

public @Nullable SubtitleInputBuffer dequeueInputBuffer()

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

Returns
@Nullable SubtitleInputBuffer

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

Throws
E

If a decoder error has occurred.

androidx.media3.extractor.text.SubtitleDecoderException

dequeueOutputBuffer

public @Nullable SubtitleOutputBuffer dequeueOutputBuffer()

Dequeues the next output buffer from the decoder.

Returns
@Nullable SubtitleOutputBuffer

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

Throws
E

If a decoder error has occurred.

androidx.media3.extractor.text.SubtitleDecoderException

flush

public 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.

getName

public String getName()

Returns the name of the decoder.

Returns
String

The name of the decoder.

queueInputBuffer

public void queueInputBuffer(SubtitleInputBuffer inputBuffer)

Queues an input buffer to the decoder.

Parameters
SubtitleInputBuffer inputBuffer

The input buffer.

Throws
E

If a decoder error has occurred.

androidx.media3.extractor.text.SubtitleDecoderException

release

public void release()

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

setOutputStartTimeUs

public final void setOutputStartTimeUs(long outputStartTimeUs)

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

Any decoded buffer with a timestamp less than outputStartTimeUs should be skipped by the implementation and not made available via dequeueOutputBuffer.

This method must only be called before queuing the first input buffer initially or after flush.

Parameters
long outputStartTimeUs

The time from which output buffer should be produced, in microseconds.

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

createSubtitle

protected Subtitle createSubtitle()

Creates a Subtitle from the available data.

decode

protected void decode(SubtitleInputBuffer inputBuffer)

Filters and processes the raw data, providing Subtitles via createSubtitle when sufficient data has been processed.

getAvailableOutputBuffer

protected final @Nullable SubtitleOutputBuffer getAvailableOutputBuffer()

getPositionUs

protected final long getPositionUs()

isNewSubtitleDataAvailable

protected boolean isNewSubtitleDataAvailable()

Returns whether there is data available to create a new Subtitle.

releaseOutputBuffer

protected void releaseOutputBuffer(SubtitleOutputBuffer outputBuffer)