# 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)

*** ** * ** ***


```
@UnstableApi
public final class Ac4Util
```

<br />

*** ** * ** ***

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

## Summary

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

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

| ### Public methods |
|---|---|
| `static void` | `https://developer.android.com/reference/androidx/media3/extractor/Ac4Util#getAc4SampleHeader(int,androidx.media3.common.util.ParsableByteArray)(int size, https://developer.android.com/reference/androidx/media3/common/util/ParsableByteArray buffer)` Populates `buffer` with an AC-4 sample header for a sample of the specified size. |
| `static https://developer.android.com/reference/androidx/media3/common/Format` | `https://developer.android.com/reference/androidx/media3/extractor/Ac4Util#parseAc4AnnexEFormat(androidx.media3.common.util.ParsableByteArray,java.lang.String,java.lang.String,androidx.media3.common.DrmInitData)( https://developer.android.com/reference/androidx/media3/common/util/ParsableByteArray data, https://developer.android.com/reference/java/lang/String.html trackId, @https://developer.android.com/reference/androidx/annotation/Nullable https://developer.android.com/reference/java/lang/String.html language, @https://developer.android.com/reference/androidx/annotation/Nullable https://developer.android.com/reference/androidx/media3/common/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` | `https://developer.android.com/reference/androidx/media3/extractor/Ac4Util#parseAc4SyncframeAudioSampleCount(java.nio.ByteBuffer)(https://developer.android.com/reference/java/nio/ByteBuffer.html buffer)` Reads the number of audio samples represented by the given AC-4 syncframe. |
| `static https://developer.android.com/reference/androidx/media3/extractor/Ac4Util.SyncFrameInfo` | `https://developer.android.com/reference/androidx/media3/extractor/Ac4Util#parseAc4SyncframeInfo(androidx.media3.common.util.ParsableBitArray)(https://developer.android.com/reference/androidx/media3/common/util/ParsableBitArray data)` Returns AC-4 format information given `data` containing a syncframe. |
| `static int` | `https://developer.android.com/reference/androidx/media3/extractor/Ac4Util#parseAc4SyncframeSize(byte[],int)(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,
    @Nullable 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 |
|---|---|
| `https://developer.android.com/reference/androidx/media3/common/util/ParsableByteArray data` | The AC4SpecificBox to parse. |
| `https://developer.android.com/reference/java/lang/String.html trackId` | The track identifier to set on the format. |
| `@https://developer.android.com/reference/androidx/annotation/Nullable https://developer.android.com/reference/java/lang/String.html language` | The language to set on the format, or `null` if unset. |
| `@https://developer.android.com/reference/androidx/annotation/Nullable https://developer.android.com/reference/androidx/media3/common/DrmInitData drmInitData` | `https://developer.android.com/reference/androidx/media3/common/DrmInitData` to be included in the format. |

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

| Throws |
|---|---|
| `https://developer.android.com/reference/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 |
|---|---|
| `https://developer.android.com/reference/java/nio/ByteBuffer.html buffer` | The `https://developer.android.com/reference/java/nio/ByteBuffer.html` 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 |
|---|---|
| `https://developer.android.com/reference/androidx/media3/common/util/ParsableBitArray data` | The data to parse, positioned at the start of the syncframe. |

| Returns |
|---|---|
| `https://developer.android.com/reference/androidx/media3/extractor/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 `https://developer.android.com/reference/androidx/media3/common/C#LENGTH_UNSET()` if the input is invalid. |