@UnstableApi
public final class Ac3Util


Utility methods for parsing Dolby TrueHD and (E-)AC-3 syncframes. (E-)AC-3 parsing follows the definition in ETSI TS 102 366 V1.4.1.

Summary

Nested types

public final class Ac3Util.SyncFrameInfo

Holds sample format information as presented by a syncframe header.

@Documented
@Retention(value = RetentionPolicy.SOURCE)
@Target(value = TYPE_USE)
@IntDef(value = )
public annotation Ac3Util.SyncFrameInfo.StreamType

AC3 stream types.

Constants

static final int

Maximum rate for an AC-3 audio stream, in bytes per second.

static final int

Maximum rate for an E-AC-3 audio stream, in bytes per second.

static final int

Maximum rate for a TrueHD audio stream, in bytes per second.

static final int

The number of samples to store in each output chunk when rechunking TrueHD streams.

static final int

The number of bytes that must be parsed from a TrueHD syncframe to calculate the sample count.

Public methods

static int

Returns the offset relative to the buffer's position of the start of a TrueHD syncframe, or INDEX_UNSET if no syncframe was found.

static Format
parseAc3AnnexFFormat(
    ParsableByteArray data,
    String trackId,
    String language,
    @Nullable DrmInitData drmInitData
)

Returns the AC-3 format given data containing the AC3SpecificBox according to Annex F.

static int

Reads the number of audio samples represented by the given (E-)AC-3 syncframe.

static Ac3Util.SyncFrameInfo

Returns (E-)AC-3 format information given data containing a syncframe.

static int
parseAc3SyncframeSize(byte[] data)

Returns the size in bytes of the given (E-)AC-3 syncframe.

static Format
parseEAc3AnnexFFormat(
    ParsableByteArray data,
    String trackId,
    String language,
    @Nullable DrmInitData drmInitData
)

Returns the E-AC-3 format given data containing the EC3SpecificBox according to Annex F.

static int

Returns the number of audio samples represented by the given TrueHD syncframe, or 0 if the buffer is not the start of a syncframe.

static int

Reads the number of audio samples represented by a TrueHD syncframe.

Constants

AC3_MAX_RATE_BYTES_PER_SECOND

public static final int AC3_MAX_RATE_BYTES_PER_SECOND = 80000

Maximum rate for an AC-3 audio stream, in bytes per second.

E_AC3_MAX_RATE_BYTES_PER_SECOND

public static final int E_AC3_MAX_RATE_BYTES_PER_SECOND = 768000

Maximum rate for an E-AC-3 audio stream, in bytes per second.

TRUEHD_MAX_RATE_BYTES_PER_SECOND

public static final int TRUEHD_MAX_RATE_BYTES_PER_SECOND = 3062500

Maximum rate for a TrueHD audio stream, in bytes per second.

TRUEHD_RECHUNK_SAMPLE_COUNT

public static final int TRUEHD_RECHUNK_SAMPLE_COUNT = 16

The number of samples to store in each output chunk when rechunking TrueHD streams. The number of samples extracted from the container corresponding to one syncframe must be an integer multiple of this value.

TRUEHD_SYNCFRAME_PREFIX_LENGTH

public static final int TRUEHD_SYNCFRAME_PREFIX_LENGTH = 10

The number of bytes that must be parsed from a TrueHD syncframe to calculate the sample count.

Public methods

findTrueHdSyncframeOffset

public static int findTrueHdSyncframeOffset(ByteBuffer buffer)

Returns the offset relative to the buffer's position of the start of a TrueHD syncframe, or INDEX_UNSET if no syncframe was found. The buffer's position is not modified.

Parameters
ByteBuffer buffer

The ByteBuffer within which to find a syncframe.

Returns
int

The offset relative to the buffer's position of the start of a TrueHD syncframe, or INDEX_UNSET if no syncframe was found.

parseAc3AnnexFFormat

public static Format parseAc3AnnexFFormat(
    ParsableByteArray data,
    String trackId,
    String language,
    @Nullable DrmInitData drmInitData
)

Returns the AC-3 format given data containing the AC3SpecificBox according to Annex F. The reading position of data will be modified.

Parameters
ParsableByteArray data

The AC3SpecificBox to parse.

String trackId

The track identifier to set on the format.

String language

The language to set on the format.

@Nullable DrmInitData drmInitData

DrmInitData to be included in the format.

Returns
Format

The AC-3 format parsed from data in the header.

parseAc3SyncframeAudioSampleCount

public static int parseAc3SyncframeAudioSampleCount(ByteBuffer buffer)

Reads the number of audio samples represented by the given (E-)AC-3 syncframe. The buffer's position is not modified.

Parameters
ByteBuffer buffer

The ByteBuffer from which to read the syncframe.

Returns
int

The number of audio samples represented by the syncframe.

parseAc3SyncframeInfo

public static Ac3Util.SyncFrameInfo parseAc3SyncframeInfo(ParsableBitArray data)

Returns (E-)AC-3 format information given data containing a syncframe. The reading position of data will be modified.

Parameters
ParsableBitArray data

The data to parse, positioned at the start of the syncframe.

Returns
Ac3Util.SyncFrameInfo

The (E-)AC-3 format data parsed from the header.

parseAc3SyncframeSize

public static int parseAc3SyncframeSize(byte[] data)

Returns the size in bytes of the given (E-)AC-3 syncframe.

Parameters
byte[] data

The syncframe to parse.

Returns
int

The syncframe size in bytes. LENGTH_UNSET if the input is invalid.

parseEAc3AnnexFFormat

public static Format parseEAc3AnnexFFormat(
    ParsableByteArray data,
    String trackId,
    String language,
    @Nullable DrmInitData drmInitData
)

Returns the E-AC-3 format given data containing the EC3SpecificBox according to Annex F. The reading position of data will be modified.

Parameters
ParsableByteArray data

The EC3SpecificBox to parse.

String trackId

The track identifier to set on the format.

String language

The language to set on the format.

@Nullable DrmInitData drmInitData

DrmInitData to be included in the format.

Returns
Format

The E-AC-3 format parsed from data in the header.

parseTrueHdSyncframeAudioSampleCount

public static int parseTrueHdSyncframeAudioSampleCount(byte[] syncframe)

Returns the number of audio samples represented by the given TrueHD syncframe, or 0 if the buffer is not the start of a syncframe.

Parameters
byte[] syncframe

The bytes from which to read the syncframe. Must be at least TRUEHD_SYNCFRAME_PREFIX_LENGTH bytes long.

Returns
int

The number of audio samples represented by the syncframe, or 0 if the buffer doesn't contain the start of a syncframe.

parseTrueHdSyncframeAudioSampleCount

public static int parseTrueHdSyncframeAudioSampleCount(ByteBuffer buffer, int offset)

Reads the number of audio samples represented by a TrueHD syncframe. The buffer's position is not modified.

Parameters
ByteBuffer buffer

The ByteBuffer from which to read the syncframe.

int offset

The offset of the start of the syncframe relative to the buffer's position.

Returns
int

The number of audio samples represented by the syncframe.