SimpleSubtitleDecoder


@UnstableApi
abstract class SimpleSubtitleDecoder : SimpleDecoder, SubtitleDecoder


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

Summary

Protected constructors

Public functions

Unit
setPositionUs(positionUs: Long)

Informs the decoder of the current playback position.

Protected functions

SubtitleInputBuffer!

Creates a new input buffer.

SubtitleOutputBuffer!

Creates a new output buffer.

SubtitleDecoderException!

Creates an exception to propagate for an unexpected decode error.

abstract Subtitle!
decode(data: ByteArray!, length: Int, reset: Boolean)

Decodes data into a Subtitle.

SubtitleDecoderException?
decode(
    inputBuffer: SubtitleInputBuffer!,
    outputBuffer: SubtitleOutputBuffer!,
    reset: Boolean
)

Decodes the inputBuffer and stores any decoded output in outputBuffer.

Public properties

String!

Inherited functions

From androidx.media3.decoder.SimpleDecoder
I?

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

O?

Dequeues the next output buffer from the decoder.

Unit

Flushes the decoder.

Boolean

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

Unit
queueInputBuffer(inputBuffer: I!)

Queues an input buffer to the decoder.

Unit

Releases the decoder.

Unit
@CallSuper
releaseOutputBuffer(outputBuffer: O!)

Releases an output buffer back to the decoder.

Unit

Sets the initial size of each input buffer.

Unit
setOutputStartTimeUs(outputStartTimeUs: Long)

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

Protected constructors

SimpleSubtitleDecoder

protected SimpleSubtitleDecoder(name: String!)
Parameters
name: String!

The name of the decoder.

Public functions

setPositionUs

fun setPositionUs(positionUs: Long): Unit

Informs the decoder of the current playback position.

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

Parameters
positionUs: Long

The current playback position in microseconds.

Protected functions

createInputBuffer

protected fun createInputBuffer(): SubtitleInputBuffer!

Creates a new input buffer.

createOutputBuffer

protected fun createOutputBuffer(): SubtitleOutputBuffer!

Creates a new output buffer.

createUnexpectedDecodeException

protected fun createUnexpectedDecodeException(error: Throwable!): SubtitleDecoderException!

Creates an exception to propagate for an unexpected decode error.

Parameters
error: Throwable!

The unexpected decode error.

Returns
SubtitleDecoderException!

The exception to propagate.

decode

protected abstract fun decode(data: ByteArray!, length: Int, reset: Boolean): Subtitle!

Decodes data into a Subtitle.

Parameters
data: ByteArray!

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

length: Int

The number of bytes from data to be decoded.

reset: Boolean

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 fun decode(
    inputBuffer: SubtitleInputBuffer!,
    outputBuffer: SubtitleOutputBuffer!,
    reset: Boolean
): SubtitleDecoderException?

Decodes the inputBuffer and stores any decoded output in outputBuffer.

Parameters
inputBuffer: SubtitleInputBuffer!

The buffer to decode.

outputBuffer: SubtitleOutputBuffer!

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.

reset: Boolean

Whether the decoder must be reset before decoding.

Returns
SubtitleDecoderException?

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

Public properties

name

val nameString!