# Ac3Util

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/Ac3Util.java+class:androidx.media3.extractor.Ac3Util)

*** ** * ** ***

<br />

```
@UnstableApi
class Ac3Util
```

<br />

*** ** * ** ***

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 |
|---|
| `class https://developer.android.com/reference/kotlin/androidx/media3/extractor/Ac3Util.SyncFrameInfo` Holds sample format information as presented by a syncframe header. |
| `@https://developer.android.com/reference/java/lang/annotation/Documented.html @https://developer.android.com/reference/java/lang/annotation/Retention.html(value = https://developer.android.com/reference/java/lang/annotation/RetentionPolicy.html#SOURCE) @https://developer.android.com/reference/java/lang/annotation/Target.html(value = https://developer.android.com/reference/java/lang/annotation/ElementType.html#TYPE_USE) @https://developer.android.com/reference/kotlin/androidx/annotation/IntDef(value = ) annotation https://developer.android.com/reference/kotlin/androidx/media3/extractor/Ac3Util.SyncFrameInfo.StreamType` AC3 stream types. |

| ### Constants |
|---|---|
| `const https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html` | `https://developer.android.com/reference/kotlin/androidx/media3/extractor/Ac3Util#AC3_MAX_RATE_BYTES_PER_SECOND() = 80000` Maximum rate for an AC-3 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/Ac3Util#E_AC3_MAX_RATE_BYTES_PER_SECOND() = 768000` Maximum rate for an E-AC-3 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/Ac3Util#TRUEHD_MAX_RATE_BYTES_PER_SECOND() = 3062500` Maximum rate for a TrueHD 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/Ac3Util#TRUEHD_RECHUNK_SAMPLE_COUNT() = 16` The number of samples to store in each output chunk when rechunking TrueHD streams. |
| `const https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html` | `https://developer.android.com/reference/kotlin/androidx/media3/extractor/Ac3Util#TRUEHD_SYNCFRAME_PREFIX_LENGTH() = 10` The number of bytes that must be parsed from a TrueHD syncframe to calculate the sample count. |

| ### Public functions |
|---|---|
| `java-static https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html` | `https://developer.android.com/reference/kotlin/androidx/media3/extractor/Ac3Util#findTrueHdSyncframeOffset(java.nio.ByteBuffer)(buffer: https://developer.android.com/reference/java/nio/ByteBuffer.html!)` Returns the offset relative to the buffer's position of the start of a TrueHD syncframe, or `https://developer.android.com/reference/kotlin/androidx/media3/common/C#INDEX_UNSET()` if no syncframe was found. |
| `java-static https://developer.android.com/reference/kotlin/androidx/media3/common/Format!` | `https://developer.android.com/reference/kotlin/androidx/media3/extractor/Ac3Util#parseAc3AnnexFFormat(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-3 format given `data` containing the AC3SpecificBox according to Annex F. |
| `java-static https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html` | `https://developer.android.com/reference/kotlin/androidx/media3/extractor/Ac3Util#parseAc3SyncframeAudioSampleCount(java.nio.ByteBuffer)(buffer: https://developer.android.com/reference/java/nio/ByteBuffer.html!)` Reads the number of audio samples represented by the given (E-)AC-3 syncframe. |
| `java-static https://developer.android.com/reference/kotlin/androidx/media3/extractor/Ac3Util.SyncFrameInfo!` | `https://developer.android.com/reference/kotlin/androidx/media3/extractor/Ac3Util#parseAc3SyncframeInfo(androidx.media3.common.util.ParsableBitArray)(data: https://developer.android.com/reference/kotlin/androidx/media3/common/util/ParsableBitArray!)` Returns (E-)AC-3 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/Ac3Util#parseAc3SyncframeSize(byte[])(data: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-byte-array/index.html<https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-byte/index.html>!)` Returns the size in bytes of the given (E-)AC-3 syncframe. |
| `java-static https://developer.android.com/reference/kotlin/androidx/media3/common/Format!` | `https://developer.android.com/reference/kotlin/androidx/media3/extractor/Ac3Util#parseEAc3AnnexFFormat(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 E-AC-3 format given `data` containing the EC3SpecificBox according to Annex F. |
| `java-static https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html` | `https://developer.android.com/reference/kotlin/androidx/media3/extractor/Ac3Util#parseTrueHdSyncframeAudioSampleCount(byte[])(syncframe: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-byte-array/index.html<https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-byte/index.html>!)` Returns the number of audio samples represented by the given TrueHD syncframe, or 0 if the buffer is not the start of a syncframe. |
| `java-static https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html` | `https://developer.android.com/reference/kotlin/androidx/media3/extractor/Ac3Util#parseTrueHdSyncframeAudioSampleCount(java.nio.ByteBuffer,int)(buffer: https://developer.android.com/reference/java/nio/ByteBuffer.html!, offset: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html)` Reads the number of audio samples represented by a TrueHD syncframe. |

## Constants

### AC3_MAX_RATE_BYTES_PER_SECOND

```
const val AC3_MAX_RATE_BYTES_PER_SECOND = 80000: Int
```

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

### E_AC3_MAX_RATE_BYTES_PER_SECOND

```
const val E_AC3_MAX_RATE_BYTES_PER_SECOND = 768000: Int
```

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

### TRUEHD_MAX_RATE_BYTES_PER_SECOND

```
const val TRUEHD_MAX_RATE_BYTES_PER_SECOND = 3062500: Int
```

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

### TRUEHD_RECHUNK_SAMPLE_COUNT

```
const val TRUEHD_RECHUNK_SAMPLE_COUNT = 16: Int
```

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

```
const val TRUEHD_SYNCFRAME_PREFIX_LENGTH = 10: Int
```

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

## Public functions

### findTrueHdSyncframeOffset

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

Returns the offset relative to the buffer's position of the start of a TrueHD syncframe, or `https://developer.android.com/reference/kotlin/androidx/media3/common/C#INDEX_UNSET()` if no syncframe was found. 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` within which to find a syncframe. |

| Returns |
|---|---|
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html` | The offset relative to the buffer's position of the start of a TrueHD syncframe, or `https://developer.android.com/reference/kotlin/androidx/media3/common/C#INDEX_UNSET()` if no syncframe was found. |

### parseAc3AnnexFFormat

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

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

| Parameters |
|---|---|
| `data: https://developer.android.com/reference/kotlin/androidx/media3/common/util/ParsableByteArray!` | The AC3SpecificBox 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-3 format parsed from data in the header. |

### parseAc3SyncframeAudioSampleCount

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

Reads the number of audio samples represented by the given (E-)AC-3 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. |

### parseAc3SyncframeInfo

```
java-static fun parseAc3SyncframeInfo(data: ParsableBitArray!): Ac3Util.SyncFrameInfo!
```

Returns (E-)AC-3 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/Ac3Util.SyncFrameInfo!` | The (E-)AC-3 format data parsed from the header. |

### parseAc3SyncframeSize

```
java-static fun parseAc3SyncframeSize(data: ByteArray<Byte>!): Int
```

Returns the size in bytes of the given (E-)AC-3 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. |

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

### parseEAc3AnnexFFormat

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

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

| Parameters |
|---|---|
| `data: https://developer.android.com/reference/kotlin/androidx/media3/common/util/ParsableByteArray!` | The EC3SpecificBox 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 E-AC-3 format parsed from data in the header. |

### parseTrueHdSyncframeAudioSampleCount

```
java-static fun parseTrueHdSyncframeAudioSampleCount(syncframe: ByteArray<Byte>!): 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.

| Parameters |
|---|---|
| `syncframe: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-byte-array/index.html<https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-byte/index.html>!` | The bytes from which to read the syncframe. Must be at least `https://developer.android.com/reference/kotlin/androidx/media3/extractor/Ac3Util#TRUEHD_SYNCFRAME_PREFIX_LENGTH()` bytes long. |

| Returns |
|---|---|
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html` | The number of audio samples represented by the syncframe, or 0 if the buffer doesn't contain the start of a syncframe. |

### parseTrueHdSyncframeAudioSampleCount

```
java-static fun parseTrueHdSyncframeAudioSampleCount(buffer: ByteBuffer!, offset: Int): Int
```

Reads the number of audio samples represented by a TrueHD 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. |
| `offset: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html` | The offset of the start of the syncframe relative to the buffer's position. |

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