[PR] avcodec/ac3dec: fix dual-mono program metadata order (PR #24251)

AYOUB NABIL BOUBAGRAT via ffmpeg-devel <[email protected]>
Newsgroups gmane.comp.video.ffmpeg.devel
Message-ID <[email protected]>
PR #24251 opened by AYOUB NABIL BOUBAGRAT (ayoubnabil)
URL: https://code.ffmpeg.org/FFmpeg/FFmpeg/pulls/24251
Patch URL: https://code.ffmpeg.org/FFmpeg/FFmpeg/pulls/24251.patch

dual-mono dynamic range values were stored in reverse order to match a
reversed output lookup. that lookup also selects dialnorm and compression
data, which are already stored in program order.

store and apply all per-program metadata in bitstream order.



>From ed7f19d1a5b147ecf42e3b5b307ccfa42070872e Mon Sep 17 00:00:00 2001
From: Ayoub Nabil Boubagrat <[email protected]>
Date: Sun, 23 Aug 2026 21:50:47 +0200
Subject: [PATCH] avcodec/ac3dec: fix dual-mono program metadata order

dual-mono dynamic range values were stored in reverse order to match a
reversed output lookup. that lookup also selects dialnorm and compression
data, which are already stored in program order.

store and apply all per-program metadata in bitstream order.

Signed-off-by: Ayoub Nabil Boubagrat <[email protected]>
---
 libavcodec/ac3dec.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/libavcodec/ac3dec.c b/libavcodec/ac3dec.c
index 79a8751154..1091759991 100644
--- a/libavcodec/ac3dec.c
+++ b/libavcodec/ac3dec.c
@@ -1035,7 +1035,7 @@ static int decode_audio_block(AC3DecodeContext *s, int blk, int offset)
     }
 
     /* dynamic range */
-    i = !s->channel_mode;
+    i = 0;
     do {
         if (get_bits1(gbc)) {
             /* Allow asymmetric application of DRC when drc_scale > 1.
@@ -1049,7 +1049,7 @@ static int decode_audio_block(AC3DecodeContext *s, int blk, int offset)
         } else if (blk == 0) {
             s->dynamic_range[i] = AC3_DYNAMIC_RANGE1;
         }
-    } while (i--);
+    } while (++i < (s->channel_mode ? 1 : 2));
 
     /* spectral extension strategy */
     if (s->eac3 && (!blk || get_bits1(gbc))) {
@@ -1333,7 +1333,7 @@ static int decode_audio_block(AC3DecodeContext *s, int blk, int offset)
         int audio_channel = 0;
         INTFLOAT gain;
         if (s->channel_mode == AC3_CHMODE_DUALMONO && ch <= 2)
-            audio_channel = 2-ch;
+            audio_channel = ch-1;
         if (s->heavy_compression && s->compression_exists[audio_channel])
             gain = s->heavy_dynamic_range[audio_channel];
         else
-- 
2.52.0

_______________________________________________
ffmpeg-devel mailing list -- [email protected]
To unsubscribe send an email to [email protected]
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.