PR #23013 opened by gnattu
URL: https://code.ffmpeg.org/FFmpeg/FFmpeg/pulls/23013
Patch URL: https://code.ffmpeg.org/FFmpeg/FFmpeg/pulls/23013.patch

This detects DTS:X for DTS-HD HRA, in addition to already present DTS-HD MA 
detection.
The magic sync word is taken from MediaInfoLib: 
https://github.com/MediaArea/MediaInfoLib/commit/a58e2a2000d0236652dde9e6e0462cb0408aad28

Signed-off-by: gnattu <[email protected]>


>From f5d34b777bbb3ce63675023283bb2a226bfb8f69 Mon Sep 17 00:00:00 2001
From: gnattu <[email protected]>
Date: Tue, 5 May 2026 00:30:57 +0800
Subject: [PATCH] avcodec: add dtsx detection for dts hra

The magic sync word is taken from 
https://github.com/MediaArea/MediaInfoLib/commit/a58e2a2000d0236652dde9e6e0462cb0408aad28

Signed-off-by: gnattu <[email protected]>
---
 libavcodec/dca_core.c      | 11 ++++++++---
 libavcodec/dca_exss.c      | 16 ++++++++++++++++
 libavcodec/dca_exss.h      |  3 +++
 libavcodec/dca_syncwords.h |  2 ++
 libavcodec/defs.h          |  2 ++
 libavcodec/profiles.c      |  2 ++
 6 files changed, 33 insertions(+), 3 deletions(-)

diff --git a/libavcodec/dca_core.c b/libavcodec/dca_core.c
index cb1f7b7bbf..cd8849ae40 100644
--- a/libavcodec/dca_core.c
+++ b/libavcodec/dca_core.c
@@ -2370,9 +2370,14 @@ int ff_dca_core_filter_frame(DCACoreDecoder *s, AVFrame 
*frame)
         return ret;
 
     // Set profile, bit rate, etc
-    if (s->ext_audio_mask & DCA_EXSS_MASK)
-        avctx->profile = AV_PROFILE_DTS_HD_HRA;
-    else if (s->ext_audio_mask & (DCA_CSS_XXCH | DCA_CSS_XCH))
+    if (s->ext_audio_mask & DCA_EXSS_MASK) {
+        if (dca->exss.x_imax_syncword_present)
+            avctx->profile = AV_PROFILE_DTS_HD_HRA_X_IMAX;
+        else if (dca->exss.x_syncword_present)
+            avctx->profile = AV_PROFILE_DTS_HD_HRA_X;
+        else
+            avctx->profile = AV_PROFILE_DTS_HD_HRA;
+    } else if (s->ext_audio_mask & (DCA_CSS_XXCH | DCA_CSS_XCH))
         avctx->profile = AV_PROFILE_DTS_ES;
     else if (s->ext_audio_mask & DCA_CSS_X96)
         avctx->profile = AV_PROFILE_DTS_96_24;
diff --git a/libavcodec/dca_exss.c b/libavcodec/dca_exss.c
index e873088f82..79cc3a0434 100644
--- a/libavcodec/dca_exss.c
+++ b/libavcodec/dca_exss.c
@@ -19,6 +19,9 @@
  */
 
 #include "dcadec.h"
+#include "libavutil/intreadwrite.h"
+
+#include "dca_syncwords.h"
 
 static void parse_xll_parameters(DCAExssParser *s, DCAExssAsset *asset)
 {
@@ -379,6 +382,9 @@ int ff_dca_exss_parse(DCAExssParser *s, const uint8_t 
*data, int size)
 {
     int i, ret, offset, wide_hdr, header_size;
 
+    s->x_syncword_present = 0;
+    s->x_imax_syncword_present = 0;
+
     if ((ret = init_get_bits8(&s->gb, data, size)) < 0)
         return ret;
 
@@ -510,5 +516,15 @@ int ff_dca_exss_parse(DCAExssParser *s, const uint8_t 
*data, int size)
         return AVERROR_INVALIDDATA;
     }
 
+    if (s->exss_size - offset >= 10 && AV_RB48(data + offset) == 
DCA_SYNCWORD_X_AFTER_ASSETS) {
+        unsigned int extradata_syncword = AV_RB32(data + offset + 6);
+
+        if (extradata_syncword == DCA_SYNCWORD_XLL_X) {
+            s->x_syncword_present = 1;
+        } else if ((extradata_syncword >> 1) == (DCA_SYNCWORD_XLL_X_IMAX >> 
1)) {
+            s->x_imax_syncword_present = 1;
+        }
+    }
+
     return 0;
 }
diff --git a/libavcodec/dca_exss.h b/libavcodec/dca_exss.h
index 9e91b00bfd..29def10a37 100644
--- a/libavcodec/dca_exss.h
+++ b/libavcodec/dca_exss.h
@@ -84,6 +84,9 @@ typedef struct DCAExssParser {
     int     nmixoutconfigs;         ///< Number of mixing configurations
     int     nmixoutchs[4];          ///< Speaker layout mask for mixer output 
channels
 
+    int     x_syncword_present;     ///< DTS:X extension syncword detected
+    int     x_imax_syncword_present;///< DTS:X IMAX extension syncword detected
+
     DCAExssAsset   assets[1];    ///< Audio asset descriptors
 } DCAExssParser;
 
diff --git a/libavcodec/dca_syncwords.h b/libavcodec/dca_syncwords.h
index 649bbd90dc..640cf4ca38 100644
--- a/libavcodec/dca_syncwords.h
+++ b/libavcodec/dca_syncwords.h
@@ -36,4 +36,6 @@
 #define    DCA_SYNCWORD_XLL_X                0x02000850U
 #define    DCA_SYNCWORD_XLL_X_IMAX           0xF14000D0U
 
+#define    DCA_SYNCWORD_X_AFTER_ASSETS       0x3A429B0A0011ULL
+
 #endif /* AVCODEC_DCA_SYNCWORDS_H */
diff --git a/libavcodec/defs.h b/libavcodec/defs.h
index b13e983b13..01342f7cce 100644
--- a/libavcodec/defs.h
+++ b/libavcodec/defs.h
@@ -88,6 +88,8 @@
 #define AV_PROFILE_DTS_ES             30
 #define AV_PROFILE_DTS_96_24          40
 #define AV_PROFILE_DTS_HD_HRA         50
+#define AV_PROFILE_DTS_HD_HRA_X       51
+#define AV_PROFILE_DTS_HD_HRA_X_IMAX  52
 #define AV_PROFILE_DTS_HD_MA          60
 #define AV_PROFILE_DTS_EXPRESS        70
 #define AV_PROFILE_DTS_HD_MA_X        61
diff --git a/libavcodec/profiles.c b/libavcodec/profiles.c
index 1b67870c43..91d37cee07 100644
--- a/libavcodec/profiles.c
+++ b/libavcodec/profiles.c
@@ -42,6 +42,8 @@ const AVProfile ff_dca_profiles[] = {
     { AV_PROFILE_DTS_ES,             "DTS-ES"                 },
     { AV_PROFILE_DTS_96_24,          "DTS 96/24"              },
     { AV_PROFILE_DTS_HD_HRA,         "DTS-HD HRA"             },
+    { AV_PROFILE_DTS_HD_HRA_X,       "DTS-HD HRA + DTS:X"      },
+    { AV_PROFILE_DTS_HD_HRA_X_IMAX,  "DTS-HD HRA + DTS:X IMAX" },
     { AV_PROFILE_DTS_HD_MA,          "DTS-HD MA"              },
     { AV_PROFILE_DTS_HD_MA_X,        "DTS-HD MA + DTS:X"      },
     { AV_PROFILE_DTS_HD_MA_X_IMAX,   "DTS-HD MA + DTS:X IMAX" },
-- 
2.52.0

_______________________________________________
ffmpeg-devel mailing list -- [email protected]
To unsubscribe send an email to [email protected]

Reply via email to