Skip to content

Enable accurate mime type assignment for DTS-HD in TS#3184

Merged
copybara-service[bot] merged 3 commits into
androidx:mainfrom
nift4:dtshdintsmime
May 14, 2026
Merged

Enable accurate mime type assignment for DTS-HD in TS#3184
copybara-service[bot] merged 3 commits into
androidx:mainfrom
nift4:dtshdintsmime

Conversation

@nift4
Copy link
Copy Markdown
Contributor

@nift4 nift4 commented Apr 20, 2026

Read more of the DTS-HD header in order to find out extension substream type, to get correct mime type which is relevant for buffer size decision logic (as DTS Express has way lower maximum bit rate than DTS-HD).

Issue: #2487
Issue: #3147

Read more of the DTS-HD header in order to find out extension
substream type, to get correct mime type which is relevant for
buffer size decision logic (as DTS Express has way lower maximum
bit rate than DTS-HD).

Issue: androidx#2487
Issue: androidx#3147
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi @rohitjoins,

I don't understand why this is needed: according to my reading of Table 7-5/7-6/7-7 you don't need to check this and can just assume embedded stereo/6ch flags as false if static fields aren't present.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for looking into these commits and providing feedback.

I took a closer look at the ETSI TS 102 114 V1.6.1 specification to verify this, and unfortunately, assuming those flags are false when bStaticFieldsPresent == 0 violates the spec and will cause a parser desync.

According to Section 7.5.2 (Page 98), the definition of bStaticFieldsPresent states: If the bStaticFieldsPresent is false, the metadata fields that are static over the duration of an encoded stream are omitted from the extension substream header.

Because they are static over the duration of an encoded stream, they are simply omitted to save bandwidth, they do not become false? They retain whatever value was established in the initial keyframe.

Since DtsUtil.parseDtsHdHeader is a stateless utility, it has no memory of the stream's true bEmbeddedStereoFlag. If we blindly assume the flag is false on an intermediate frame, but the stream actually has embedded stereo, our parser will fail to skip those 8 bits and instantly desync. By the time it tries to read the coding mode for the MIME type, it will be reading misaligned garbage data.

Therefore, because we cannot reliably parse the Dynamic Metadata statelessly, safely confining the parsing to if (staticFieldsPresent) and using the sampleMimeType fallback in DtsReader is required to prevent crashes on intermediate frames?

Please let me know if my interpretation of the spec is correct, and if I should send this PR at its current state for internal review. Thanks!

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for explaining, you're right :)

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@nift4 Is your next PR going to modify the DTS format detection of MKV files?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes

Moves the parsing of the Asset Descriptor's Dynamic Metadata and
Decoder Navigation Data inside the `staticFieldsPresent` block.
Because `DtsUtil.parseDtsHdHeader` is a stateless utility, it
cannot safely skip dynamic metadata on intermediate frames where
static fields are absent, as the bit layout relies on flags
(like `embeddedStereo` and `enableMixMetadata`) established in
the static block.

To handle intermediate frames safely:
- Extracts the complex ETSI Table 7-6 and 7-7 parsing into
  dedicated helper methods for readability.
- Makes `DtsHeader.mimeType` `@Nullable` so it can be safely
  omitted when static fields are skipped.
- Updates `DtsReader` to gracefully fall back to the existing
  format's `sampleMimeType` when the parsed header yields a null
  MIME type, preventing unnecessary format recreations.
@copybara-service copybara-service Bot merged commit 22b7cfe into androidx:main May 14, 2026
1 check passed
@nift4 nift4 deleted the dtshdintsmime branch May 14, 2026 15:52
@nift4
Copy link
Copy Markdown
Contributor Author

nift4 commented May 14, 2026

Thanks @rohitjoins, I've uploaded #3226 as next step

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants