# DtsUtil

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

*** ** * ** ***


```
@UnstableApi
public final class DtsUtil
```

<br />

*** ** * ** ***

Utility methods for parsing DTS frames.

## Summary

| ### Nested types |
|---|
| `@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/androidx/annotation/StringDef(value = [https://developer.android.com/reference/androidx/media3/common/MimeTypes.AUDIO_DTS, https://developer.android.com/reference/androidx/media3/common/MimeTypes.AUDIO_DTS_EXPRESS, https://developer.android.com/reference/androidx/media3/common/MimeTypes.AUDIO_DTS_HD, https://developer.android.com/reference/androidx/media3/common/MimeTypes.AUDIO_DTS_UHD_P2]) public annotation https://developer.android.com/reference/androidx/media3/extractor/DtsUtil.DtsAudioMimeType` The possible MIME types for DTS that can be used. |
| `public final class https://developer.android.com/reference/androidx/media3/extractor/DtsUtil.DtsHeader` Information parsed from a DTS frame 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/androidx/annotation/IntDef(value = ) public annotation https://developer.android.com/reference/androidx/media3/extractor/DtsUtil.FrameType` Frame types for a DTS stream. |

| ### Constants |
|---|---|
| `static final int` | `https://developer.android.com/reference/androidx/media3/extractor/DtsUtil#DTS_EXPRESS_MAX_RATE_BITS_PER_SECOND() = 768000` Maximum bit-rate for a DTS Express audio stream, in bits per second. |
| `static final int` | `https://developer.android.com/reference/androidx/media3/extractor/DtsUtil#DTS_HD_MAX_RATE_BYTES_PER_SECOND() = 2250000` Maximum rate for a DTS-HD audio stream, in bytes per second. |
| `static final int` | `https://developer.android.com/reference/androidx/media3/extractor/DtsUtil#DTS_MAX_RATE_BYTES_PER_SECOND() = 192000` Maximum rate for a DTS audio stream, in bytes per second. |
| `static final int` | `https://developer.android.com/reference/androidx/media3/extractor/DtsUtil#FRAME_TYPE_CORE() = 1` Represents a DTS core frame. |
| `static final int` | `https://developer.android.com/reference/androidx/media3/extractor/DtsUtil#FRAME_TYPE_EXTENSION_SUBSTREAM() = 2` Represents a DTS extension substream frame. |
| `static final int` | `https://developer.android.com/reference/androidx/media3/extractor/DtsUtil#FRAME_TYPE_UHD_NON_SYNC() = 4` Represents a DTS UHD non-sync frame. |
| `static final int` | `https://developer.android.com/reference/androidx/media3/extractor/DtsUtil#FRAME_TYPE_UHD_SYNC() = 3` Represents a DTS UHD sync frame. |
| `static final int` | `https://developer.android.com/reference/androidx/media3/extractor/DtsUtil#FRAME_TYPE_UNKNOWN() = 0` Represents a DTS frame for which type is unknown. |

| ### Public methods |
|---|---|
| `static int` | `https://developer.android.com/reference/androidx/media3/extractor/DtsUtil#getDtsFrameSize(byte[])(byte[] data)` Returns the size in bytes of the given DTS Core frame. |
| `static int` | `@https://developer.android.com/reference/androidx/media3/extractor/DtsUtil.FrameType https://developer.android.com/reference/androidx/media3/extractor/DtsUtil#getFrameType(int)(int word)` Returns the `https://developer.android.com/reference/androidx/media3/extractor/DtsUtil.FrameType` if `word` is a DTS sync word, otherwise `https://developer.android.com/reference/androidx/media3/extractor/DtsUtil#FRAME_TYPE_UNKNOWN()`. |
| `static boolean` | `https://developer.android.com/reference/androidx/media3/extractor/DtsUtil#isDtsBaseAudioMimeType(java.lang.String)(@https://developer.android.com/reference/androidx/annotation/Nullable https://developer.android.com/reference/java/lang/String.html mimeType)` Returns whether `mimeType` is `https://developer.android.com/reference/androidx/media3/common/MimeTypes#AUDIO_DTS()` or `https://developer.android.com/reference/androidx/media3/common/MimeTypes#AUDIO_DTS_HD()`. |
| `static int` | `https://developer.android.com/reference/androidx/media3/extractor/DtsUtil#parseDtsAudioSampleCount(java.nio.ByteBuffer)(https://developer.android.com/reference/java/nio/ByteBuffer.html buffer)` Like `https://developer.android.com/reference/androidx/media3/extractor/DtsUtil#parseDtsAudioSampleCount(byte[])` but reads from a `https://developer.android.com/reference/java/nio/ByteBuffer.html`. |
| `static int` | `https://developer.android.com/reference/androidx/media3/extractor/DtsUtil#parseDtsAudioSampleCount(byte[])(byte[] data)` Returns the number of audio samples represented by the given DTS Core frame. |
| `static https://developer.android.com/reference/androidx/media3/common/Format` | `https://developer.android.com/reference/androidx/media3/extractor/DtsUtil#parseDtsFormat(byte[],java.lang.String,java.lang.String,int,java.lang.String,androidx.media3.common.DrmInitData)( byte[] frame, @https://developer.android.com/reference/androidx/annotation/Nullable 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/media3/common/C.RoleFlags int roleFlags, https://developer.android.com/reference/java/lang/String.html containerMimeType, @https://developer.android.com/reference/androidx/annotation/Nullable https://developer.android.com/reference/androidx/media3/common/DrmInitData drmInitData )` Returns the DTS format given `data` containing the DTS Core frame according to ETSI TS 102 114 V1.6.1 (2019-08) subsections 5.3/5.4. |
| `static https://developer.android.com/reference/androidx/media3/extractor/DtsUtil.DtsHeader` | `https://developer.android.com/reference/androidx/media3/extractor/DtsUtil#parseDtsHdHeader(byte[])(byte[] header)` Parses the `https://developer.android.com/reference/androidx/media3/extractor/DtsUtil.DtsHeader` data from the extension substream header of a DTS-HD frame according to ETSI TS 102 114 V1.6.1 (2019-08), Section 7.5.2. |
| `static int` | `https://developer.android.com/reference/androidx/media3/extractor/DtsUtil#parseDtsHdHeaderSize(byte[])(byte[] headerPrefix)` Returns the size of the extension substream header in a DTS-HD frame according to ETSI TS 102 114 V1.6.1 (2019-08), Section 7.5.2. |
| `static https://developer.android.com/reference/androidx/media3/extractor/DtsUtil.DtsHeader` | `https://developer.android.com/reference/androidx/media3/extractor/DtsUtil#parseDtsUhdHeader(byte[],java.util.concurrent.atomic.AtomicInteger)(byte[] header, https://developer.android.com/reference/java/util/concurrent/atomic/AtomicInteger.html uhdAudioChunkId)` Parses the `https://developer.android.com/reference/androidx/media3/extractor/DtsUtil.DtsHeader` data from the headers of a DTS-UHD(Profile 2) frame according to ETSI TS 103 491 V1.2.1 (2019-05), Section 6.4.3. |
| `static int` | `https://developer.android.com/reference/androidx/media3/extractor/DtsUtil#parseDtsUhdHeaderSize(byte[])(byte[] headerPrefix)` Returns the size of frame header in a DTS-UHD(Profile 2) frame according to ETSI TS 103 491 V1.2.1 (2019-05), Section 6.4.3. |
| `static https://developer.android.com/reference/androidx/media3/common/Format` | `https://developer.android.com/reference/androidx/media3/extractor/DtsUtil#updateFormatWithDtsHdInfo(androidx.media3.extractor.ExtractorInput,int,androidx.media3.common.Format)( https://developer.android.com/reference/androidx/media3/extractor/ExtractorInput input, int sampleSize, https://developer.android.com/reference/androidx/media3/common/Format format )` Returns a `https://developer.android.com/reference/androidx/media3/common/Format` with an adjusted MIME type if the sample data at the current `https://developer.android.com/reference/androidx/media3/extractor/ExtractorInput` is a DTS-HD sample with static fields, or the unmodified `format` if it is not. |

## Constants

### DTS_EXPRESS_MAX_RATE_BITS_PER_SECOND

```
public static final int DTS_EXPRESS_MAX_RATE_BITS_PER_SECOND = 768000
```

Maximum bit-rate for a DTS Express audio stream, in bits per second.

### DTS_HD_MAX_RATE_BYTES_PER_SECOND

```
public static final int DTS_HD_MAX_RATE_BYTES_PER_SECOND = 2250000
```

Maximum rate for a DTS-HD audio stream, in bytes per second.

### DTS_MAX_RATE_BYTES_PER_SECOND

```
public static final int DTS_MAX_RATE_BYTES_PER_SECOND = 192000
```

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

DTS allows an 'open' bitrate, but we assume the maximum listed value: 1536 kbit/s.

### FRAME_TYPE_CORE

```
public static final int FRAME_TYPE_CORE = 1
```

Represents a DTS core frame.

### FRAME_TYPE_EXTENSION_SUBSTREAM

```
public static final int FRAME_TYPE_EXTENSION_SUBSTREAM = 2
```

Represents a DTS extension substream frame.

### FRAME_TYPE_UHD_NON_SYNC

```
public static final int FRAME_TYPE_UHD_NON_SYNC = 4
```

Represents a DTS UHD non-sync frame.

### FRAME_TYPE_UHD_SYNC

```
public static final int FRAME_TYPE_UHD_SYNC = 3
```

Represents a DTS UHD sync frame.

### FRAME_TYPE_UNKNOWN

```
public static final int FRAME_TYPE_UNKNOWN = 0
```

Represents a DTS frame for which type is unknown.

## Public methods

### getDtsFrameSize

```
public static int getDtsFrameSize(byte[] data)
```

Returns the size in bytes of the given DTS Core frame.

| Parameters |
|---|---|
| `byte[] data` | The frame to parse. |

| Returns |
|---|---|
| `int` | The frame's size in bytes. |

### getFrameType

```
@DtsUtil.FrameType
public static int getFrameType(int word)
```

Returns the `https://developer.android.com/reference/androidx/media3/extractor/DtsUtil.FrameType` if `word` is a DTS sync word, otherwise `https://developer.android.com/reference/androidx/media3/extractor/DtsUtil#FRAME_TYPE_UNKNOWN()`.

### isDtsBaseAudioMimeType

```
public static boolean isDtsBaseAudioMimeType(@Nullable String mimeType)
```

Returns whether `mimeType` is `https://developer.android.com/reference/androidx/media3/common/MimeTypes#AUDIO_DTS()` or `https://developer.android.com/reference/androidx/media3/common/MimeTypes#AUDIO_DTS_HD()`.

### parseDtsAudioSampleCount

```
public static int parseDtsAudioSampleCount(ByteBuffer buffer)
```

Like `https://developer.android.com/reference/androidx/media3/extractor/DtsUtil#parseDtsAudioSampleCount(byte[])` but reads from a `https://developer.android.com/reference/java/nio/ByteBuffer.html`. 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. |

| Returns |
|---|---|
| `int` | The number of audio samples represented by the syncframe. |

### parseDtsAudioSampleCount

```
public static int parseDtsAudioSampleCount(byte[] data)
```

Returns the number of audio samples represented by the given DTS Core frame.

| Parameters |
|---|---|
| `byte[] data` | The frame to parse. |

| Returns |
|---|---|
| `int` | The number of audio samples represented by the frame. |

### parseDtsFormat

```
public static Format parseDtsFormat(
    byte[] frame,
    @Nullable String trackId,
    @Nullable String language,
    @C.RoleFlags int roleFlags,
    String containerMimeType,
    @Nullable DrmInitData drmInitData
)
```

Returns the DTS format given `data` containing the DTS Core frame according to ETSI TS 102 114 V1.6.1 (2019-08) subsections 5.3/5.4.

| Parameters |
|---|---|
| `byte[] frame` | The DTS Core frame to parse. |
| `@https://developer.android.com/reference/androidx/annotation/Nullable 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. |
| `@https://developer.android.com/reference/androidx/media3/common/C.RoleFlags int roleFlags` | The role flags to set on the format. |
| `https://developer.android.com/reference/java/lang/String.html containerMimeType` | The MIME type of the container to set on the format. |
| `@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 DTS format parsed from data in the header. |

### parseDtsHdHeader

```
public static DtsUtil.DtsHeader parseDtsHdHeader(byte[] header)
```

Parses the `https://developer.android.com/reference/androidx/media3/extractor/DtsUtil.DtsHeader` data from the extension substream header of a DTS-HD frame according to ETSI TS 102 114 V1.6.1 (2019-08), Section 7.5.2.

| Parameters |
|---|---|
| `byte[] header` | The DTS-HD extension substream header to parse. |

| Returns |
|---|---|
| `https://developer.android.com/reference/androidx/media3/extractor/DtsUtil.DtsHeader` | The `https://developer.android.com/reference/androidx/media3/extractor/DtsUtil.DtsHeader` data extracted from the header. |

| Throws |
|---|---|
| `https://developer.android.com/reference/androidx/media3/common/ParserException` |   |

### parseDtsHdHeaderSize

```
public static int parseDtsHdHeaderSize(byte[] headerPrefix)
```

Returns the size of the extension substream header in a DTS-HD frame according to ETSI TS 102 114 V1.6.1 (2019-08), Section 7.5.2.

| Parameters |
|---|---|
| `byte[] headerPrefix` | A byte array containing at least the first 55 bits of a DTS-HD frame. |

| Returns |
|---|---|
| `int` | Size of the DTS-HD frame header in bytes. |

### parseDtsUhdHeader

```
public static DtsUtil.DtsHeader parseDtsUhdHeader(byte[] header, AtomicInteger uhdAudioChunkId)
```

Parses the `https://developer.android.com/reference/androidx/media3/extractor/DtsUtil.DtsHeader` data from the headers of a DTS-UHD(Profile 2) frame according to ETSI TS 103 491 V1.2.1 (2019-05), Section 6.4.3.

| Parameters |
|---|---|
| `byte[] header` | The DTS-UHD header to parse. |
| `https://developer.android.com/reference/java/util/concurrent/atomic/AtomicInteger.html uhdAudioChunkId` | An `https://developer.android.com/reference/java/util/concurrent/atomic/AtomicInteger.html` containing the last read UHD audio chunk ID from a synchronized frame, or zero if unset. This parameter is both an input and output parameter. In synchronized frames, the input value is not used; instead, the parameter is set to the current UHD audio chunk ID, which becomes the output value. For non-synchronized frames, it is used without any modification. |

| Returns |
|---|---|
| `https://developer.android.com/reference/androidx/media3/extractor/DtsUtil.DtsHeader` | The `https://developer.android.com/reference/androidx/media3/extractor/DtsUtil.DtsHeader` data extracted from the header. |

| Throws |
|---|---|
| `https://developer.android.com/reference/androidx/media3/common/ParserException` |   |

### parseDtsUhdHeaderSize

```
public static int parseDtsUhdHeaderSize(byte[] headerPrefix)
```

Returns the size of frame header in a DTS-UHD(Profile 2) frame according to ETSI TS 103 491 V1.2.1 (2019-05), Section 6.4.3.

| Parameters |
|---|---|
| `byte[] headerPrefix` | A byte array containing at least the first 47 bits of a DTS-UHD frame. |

| Returns |
|---|---|
| `int` | Size of the DTS-UHD frame header in bytes. |

### updateFormatWithDtsHdInfo

```
public static Format updateFormatWithDtsHdInfo(
    ExtractorInput input,
    int sampleSize,
    Format format
)
```

Returns a `https://developer.android.com/reference/androidx/media3/common/Format` with an adjusted MIME type if the sample data at the current `https://developer.android.com/reference/androidx/media3/extractor/ExtractorInput` is a DTS-HD sample with static fields, or the unmodified `format` if it is not.

| Parameters |
|---|---|
| `https://developer.android.com/reference/androidx/media3/extractor/ExtractorInput input` | The `https://developer.android.com/reference/androidx/media3/extractor/ExtractorInput` to read from. |
| `int sampleSize` | The size of the sample data. |
| `https://developer.android.com/reference/androidx/media3/common/Format format` | The `https://developer.android.com/reference/androidx/media3/common/Format` to build upon. |

| Returns |
|---|---|
| `https://developer.android.com/reference/androidx/media3/common/Format` | The updated `https://developer.android.com/reference/androidx/media3/common/Format`. |

| Throws |
|---|---|
| `https://developer.android.com/reference/java/io/IOException.html` | If an error occurs reading from the input. |