ElementaryStreamReader


@UnstableApi
public interface ElementaryStreamReader
Known direct subclasses

Extracts individual samples from an elementary media stream, preserving original order.

The expected sequence of method calls is as follows:

  1. createTracks (once at initialization)
  2. seek (optional, to reset the state)
  3. packetStarted (to signal the start of a new packet)
  4. consume (zero or more times, to provide packet data)
  5. packetFinished (to signal the end of the current PES packet)
  6. Repeat steps 3-5 for subsequent packets
  7. endOfInputReached (called when there are no more packets)

Summary

Public methods

abstract void

Consumes (possibly partial) data from the current packet.

abstract void
createTracks(
 ExtractorOutput extractorOutput,
 TsPayloadReader.TrackIdGenerator idGenerator
)

Initializes the reader by providing outputs and ids for the tracks.

default void

Called when there will be no further packets (unless a seek occurs) because the stream ended.

default void

Called when a PES packet ends.

abstract void
packetStarted(long pesTimeUs, @TsPayloadReader.Flags int flags)

Called when a packet starts.

abstract void

Notifies the reader that a seek has occurred.

Public methods

consume

abstract void consume(ParsableByteArray data)

Consumes (possibly partial) data from the current packet.

Parameters
ParsableByteArray data

The data to consume.

Throws
androidx.media3.common.ParserException

If the data could not be parsed.

createTracks

abstract void createTracks(
 ExtractorOutput extractorOutput,
 TsPayloadReader.TrackIdGenerator idGenerator
)

Initializes the reader by providing outputs and ids for the tracks.

Parameters
ExtractorOutput extractorOutput

The ExtractorOutput that receives the extracted data.

TsPayloadReader.TrackIdGenerator idGenerator

A PesReader.TrackIdGenerator that generates unique track ids for the TrackOutputs.

endOfInputReached

default void endOfInputReached()

Called when there will be no further packets (unless a seek occurs) because the stream ended.

packetFinished

default void packetFinished()

Called when a PES packet ends. For PES packets with an unset length, this is called when the next packet starts or the stream ends.

packetStarted

abstract void packetStarted(long pesTimeUs, @TsPayloadReader.Flags int flags)

Called when a packet starts.

seek

abstract void seek()

Notifies the reader that a seek has occurred.