@UnstableApi
class TsUtil


Utilities method for extracting MPEG-TS streams.

Summary

Public functions

java-static Int
findSyncBytePosition(
    data: ByteArray!,
    startPosition: Int,
    limitPosition: Int
)

Returns the position of the first TS_SYNC_BYTE within the range [startPosition, limitPosition) from the provided data array, or returns limitPosition if sync byte could not be found.

java-static Boolean
isStartOfTsPacket(
    data: ByteArray!,
    start: Int,
    limit: Int,
    searchPosition: Int
)

Returns whether a TS packet starts at searchPosition according to the MPEG-TS synchronization recommendations.

java-static Long
readPcrFromPacket(
    packetBuffer: ParsableByteArray!,
    startOfPacket: Int,
    pcrPid: Int
)

Returns the PCR value read from a given TS packet.

Public functions

findSyncBytePosition

java-static fun findSyncBytePosition(
    data: ByteArray!,
    startPosition: Int,
    limitPosition: Int
): Int

Returns the position of the first TS_SYNC_BYTE within the range [startPosition, limitPosition) from the provided data array, or returns limitPosition if sync byte could not be found.

isStartOfTsPacket

java-static fun isStartOfTsPacket(
    data: ByteArray!,
    start: Int,
    limit: Int,
    searchPosition: Int
): Boolean

Returns whether a TS packet starts at searchPosition according to the MPEG-TS synchronization recommendations.

ISO/IEC 13818-1:2015 Annex G recommends that 5 sync bytes emulating the start of 5 consecutive TS packets should never occur as part of the TS packets' contents. So, this method returns true when data contains a sync byte at searchPosition, and said sync byte is also one of five consecutive sync bytes separated from each other by the size of a TS packet.

Parameters
data: ByteArray!

The array holding the data to search in.

start: Int

The first valid position in data from which a sync byte can be read.

limit: Int

The first invalid position in data, after which no data should be read.

searchPosition: Int

The position to check for a TS packet start.

Returns
Boolean

Whether a TS packet starts at searchPosition.

readPcrFromPacket

java-static fun readPcrFromPacket(
    packetBuffer: ParsableByteArray!,
    startOfPacket: Int,
    pcrPid: Int
): Long

Returns the PCR value read from a given TS packet.

Parameters
packetBuffer: ParsableByteArray!

The buffer that holds the packet.

startOfPacket: Int

The starting position of the packet in the buffer.

pcrPid: Int

The PID for valid packets that contain PCR values.

Returns
Long

The PCR value read from the packet, if its PID is equal to pcrPid and it contains a valid PCR value. Returns TIME_UNSET otherwise.