@UnstableApi
public final class Ac4Util


Utility methods for parsing AC-4 frames, which are access units in AC-4 bitstreams.

Summary

Nested types

public final class Ac4Util.SyncFrameInfo

Holds sample format information as presented by a syncframe header.

Constants

static final int
static final int
static final int

The header size for AC-4 parser.

static final int

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

static final int

The AC-4 sync frame header size for extractor.

Public methods

static void

Populates buffer with an AC-4 sample header for a sample of the specified size.

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

Returns the AC-4 format given data containing the AC4SpecificBox according to ETSI TS 103 190-1 Annex E.4 (ac4_dsi) and TS 103 190-2 section E.6 (ac4_dsi_v1).

static int

Reads the number of audio samples represented by the given AC-4 syncframe.

static Ac4Util.SyncFrameInfo

Returns AC-4 format information given data containing a syncframe.

static int
parseAc4SyncframeSize(byte[] data, int syncword)

Returns the size in bytes of the given AC-4 syncframe.

Constants

AC40_SYNCWORD

public static final int AC40_SYNCWORD = 44096

AC41_SYNCWORD

public static final int AC41_SYNCWORD = 44097

HEADER_SIZE_FOR_PARSER

public static final int HEADER_SIZE_FOR_PARSER = 16

The header size for AC-4 parser. Only needs to be as big as we need to read, not the full header size.

MAX_RATE_BYTES_PER_SECOND

public static final int MAX_RATE_BYTES_PER_SECOND = 336000

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

SAMPLE_HEADER_SIZE

public static final int SAMPLE_HEADER_SIZE = 7

The AC-4 sync frame header size for extractor. The seven bytes are 0xAC, 0x40, 0xFF, 0xFF, sizeByte1, sizeByte2, sizeByte3. See ETSI TS 103 190-1 V1.3.1, Annex G

Public methods

getAc4SampleHeader

public static void getAc4SampleHeader(int size, ParsableByteArray buffer)

Populates buffer with an AC-4 sample header for a sample of the specified size.

parseAc4AnnexEFormat

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

Returns the AC-4 format given data containing the AC4SpecificBox according to ETSI TS 103 190-1 Annex E.4 (ac4_dsi) and TS 103 190-2 section E.6 (ac4_dsi_v1). The reading position of data will be modified.

Parameters
ParsableByteArray data

The AC4SpecificBox 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-4 format parsed from data in the header.

Throws
androidx.media3.common.ParserException

If an unsupported container feature is encountered while parsing AC-4 Annex E.

parseAc4SyncframeAudioSampleCount

public static int parseAc4SyncframeAudioSampleCount(ByteBuffer buffer)

Reads the number of audio samples represented by the given AC-4 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.

parseAc4SyncframeInfo

public static Ac4Util.SyncFrameInfo parseAc4SyncframeInfo(ParsableBitArray data)

Returns AC-4 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
Ac4Util.SyncFrameInfo

The AC-4 format data parsed from the header.

parseAc4SyncframeSize

public static int parseAc4SyncframeSize(byte[] data, int syncword)

Returns the size in bytes of the given AC-4 syncframe.

Parameters
byte[] data

The syncframe to parse.

int syncword

The syncword value for the syncframe.

Returns
int

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