# Ac4Util

Artifact: [androidx.media3:media3-extractor](https://developer.android.com/jetpack/androidx/releases/media3) [View Source](https://cs.android.com/search?q=file:androidx/media3/extractor/Ac4Util.java+class:androidx.media3.extractor.Ac4Util)

*** ** * ** ***

<br />

```
@UnstableApi
class Ac4Util
```

<br />

*** ** * ** ***

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

## Summary

| ### Nested types |
|---|
| `class https://developer.android.com/reference/kotlin/androidx/media3/extractor/Ac4Util.SyncFrameInfo` Holds sample format information as presented by a syncframe header. |

| ### Constants |
|---|---|
| `const https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html` | `https://developer.android.com/reference/kotlin/androidx/media3/extractor/Ac4Util#AC40_SYNCWORD() = 44096` |
| `const https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html` | `https://developer.android.com/reference/kotlin/androidx/media3/extractor/Ac4Util#AC41_SYNCWORD() = 44097` |
| `const https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html` | `https://developer.android.com/reference/kotlin/androidx/media3/extractor/Ac4Util#HEADER_SIZE_FOR_PARSER() = 16` The header size for AC-4 parser. |
| `const https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html` | `https://developer.android.com/reference/kotlin/androidx/media3/extractor/Ac4Util#MAX_RATE_BYTES_PER_SECOND() = 336000` Maximum rate for an AC-4 audio stream, in bytes per second. |
| `const https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html` | `https://developer.android.com/reference/kotlin/androidx/media3/extractor/Ac4Util#SAMPLE_HEADER_SIZE() = 7` The AC-4 sync frame header size for extractor. |

| ### Public functions |
|---|---|
| `java-static https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html` | `https://developer.android.com/reference/kotlin/androidx/media3/extractor/Ac4Util#getAc4SampleHeader(int,androidx.media3.common.util.ParsableByteArray)(size: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html, buffer: https://developer.android.com/reference/kotlin/androidx/media3/common/util/ParsableByteArray!)` Populates `buffer` with an AC-4 sample header for a sample of the specified size. |
| `java-static https://developer.android.com/reference/kotlin/androidx/media3/common/Format!` | `https://developer.android.com/reference/kotlin/androidx/media3/extractor/Ac4Util#parseAc4AnnexEFormat(androidx.media3.common.util.ParsableByteArray,java.lang.String,java.lang.String,androidx.media3.common.DrmInitData)( data: https://developer.android.com/reference/kotlin/androidx/media3/common/util/ParsableByteArray!, trackId: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-string/index.html!, language: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-string/index.html?, drmInitData: https://developer.android.com/reference/kotlin/androidx/media3/common/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). |
| `java-static https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html` | `https://developer.android.com/reference/kotlin/androidx/media3/extractor/Ac4Util#parseAc4SyncframeAudioSampleCount(java.nio.ByteBuffer)(buffer: https://developer.android.com/reference/java/nio/ByteBuffer.html!)` Reads the number of audio samples represented by the given AC-4 syncframe. |
| `java-static https://developer.android.com/reference/kotlin/androidx/media3/extractor/Ac4Util.SyncFrameInfo!` | `https://developer.android.com/reference/kotlin/androidx/media3/extractor/Ac4Util#parseAc4SyncframeInfo(androidx.media3.common.util.ParsableBitArray)(data: https://developer.android.com/reference/kotlin/androidx/media3/common/util/ParsableBitArray!)` Returns AC-4 format information given `data` containing a syncframe. |
| `java-static https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html` | `https://developer.android.com/reference/kotlin/androidx/media3/extractor/Ac4Util#parseAc4SyncframeSize(byte[],int)(data: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-byte-array/index.html<https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-byte/index.html>!, syncword: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html)` Returns the size in bytes of the given AC-4 syncframe. |

## Constants

### AC40_SYNCWORD

```
const val AC40_SYNCWORD = 44096: Int
```

### AC41_SYNCWORD

```
const val AC41_SYNCWORD = 44097: Int
```

### HEADER_SIZE_FOR_PARSER

```
const val HEADER_SIZE_FOR_PARSER = 16: Int
```

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

```
const val MAX_RATE_BYTES_PER_SECOND = 336000: Int
```

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

### SAMPLE_HEADER_SIZE

```
const val SAMPLE_HEADER_SIZE = 7: Int
```

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 functions

### getAc4SampleHeader

```
java-static fun getAc4SampleHeader(size: Int, buffer: ParsableByteArray!): Unit
```

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

### parseAc4AnnexEFormat

```
java-static fun parseAc4AnnexEFormat(
    data: ParsableByteArray!,
    trackId: String!,
    language: String?,
    drmInitData: DrmInitData?
): Format!
```

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 |
|---|---|
| `data: https://developer.android.com/reference/kotlin/androidx/media3/common/util/ParsableByteArray!` | The AC4SpecificBox to parse. |
| `trackId: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-string/index.html!` | The track identifier to set on the format. |
| `language: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-string/index.html?` | The language to set on the format, or `null` if unset. |
| `drmInitData: https://developer.android.com/reference/kotlin/androidx/media3/common/DrmInitData?` | `https://developer.android.com/reference/kotlin/androidx/media3/common/DrmInitData` to be included in the format. |

| Returns |
|---|---|
| `https://developer.android.com/reference/kotlin/androidx/media3/common/Format!` | The AC-4 format parsed from data in the header. |

| Throws |
|---|---|
| `https://developer.android.com/reference/kotlin/androidx/media3/common/ParserException` | If an unsupported container feature is encountered while parsing AC-4 Annex E. |

### parseAc4SyncframeAudioSampleCount

```
java-static fun parseAc4SyncframeAudioSampleCount(buffer: ByteBuffer!): Int
```

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

| Parameters |
|---|---|
| `buffer: https://developer.android.com/reference/java/nio/ByteBuffer.html!` | The `https://developer.android.com/reference/java/nio/ByteBuffer.html` from which to read the syncframe. |

| Returns |
|---|---|
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html` | The number of audio samples represented by the syncframe. |

### parseAc4SyncframeInfo

```
java-static fun parseAc4SyncframeInfo(data: ParsableBitArray!): Ac4Util.SyncFrameInfo!
```

Returns AC-4 format information given `data` containing a syncframe. The reading position of `data` will be modified.

| Parameters |
|---|---|
| `data: https://developer.android.com/reference/kotlin/androidx/media3/common/util/ParsableBitArray!` | The data to parse, positioned at the start of the syncframe. |

| Returns |
|---|---|
| `https://developer.android.com/reference/kotlin/androidx/media3/extractor/Ac4Util.SyncFrameInfo!` | The AC-4 format data parsed from the header. |

### parseAc4SyncframeSize

```
java-static fun parseAc4SyncframeSize(data: ByteArray<Byte>!, syncword: Int): Int
```

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

| Parameters |
|---|---|
| `data: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-byte-array/index.html<https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-byte/index.html>!` | The syncframe to parse. |
| `syncword: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html` | The syncword value for the syncframe. |

| Returns |
|---|---|
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html` | The syncframe size in bytes, or `https://developer.android.com/reference/kotlin/androidx/media3/common/C#LENGTH_UNSET()` if the input is invalid. |