Git Inbox Mirror of the ffmpeg-devel mailing list - see https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
 help / color / mirror / Atom feed
* [FFmpeg-devel] [PATCH 1/2] avcodec/ac3dec: Read spx flags at once, not one bit at a, time
@ 2025-03-30 12:38 Andreas Rheinhardt
  2025-04-01 12:27 ` Andreas Rheinhardt
  0 siblings, 1 reply; 2+ messages in thread
From: Andreas Rheinhardt @ 2025-03-30 12:38 UTC (permalink / raw)
  To: FFmpeg development discussions and patches

[-- Attachment #1: Type: text/plain, Size: 29 bytes --]

Patches attached.

- Andreas

[-- Attachment #2: 0001-avcodec-ac3dec-Read-spx-flags-at-once-not-one-bit-at.patch --]
[-- Type: text/x-patch, Size: 1727 bytes --]

From d45f52c848de42ef40b0593330724de13324d921 Mon Sep 17 00:00:00 2001
From: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
Date: Sun, 30 Mar 2025 13:40:58 +0200
Subject: [PATCH 1/2] avcodec/ac3dec: Read spx flags at once, not one bit at a
 time

Doing so gets rid of a stupid GCC -Wstringop-overflow= warning
(GCC somehow believes that fbw_channels can be 7 with the old
form of the code, so that channel_uses_spx[7] would be written
to, but now it no longer believes so).

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
---
 libavcodec/ac3dec.c | 10 ++++++----
 1 file changed, 6 insertions(+), 4 deletions(-)

diff --git a/libavcodec/ac3dec.c b/libavcodec/ac3dec.c
index 2cf82abc19..49b170c235 100644
--- a/libavcodec/ac3dec.c
+++ b/libavcodec/ac3dec.c
@@ -854,16 +854,18 @@ static void decode_band_structure(GetBitContext *gbc, int blk, int eac3,
 static inline int spx_strategy(AC3DecodeContext *s, int blk)
 {
     GetBitContext *bc = &s->gbc;
-    int fbw_channels = s->fbw_channels;
     int dst_start_freq, dst_end_freq, src_start_freq,
-        start_subband, end_subband, ch;
+        start_subband, end_subband;
 
     /* determine which channels use spx */
     if (s->channel_mode == AC3_CHMODE_MONO) {
         s->channel_uses_spx[1] = 1;
     } else {
-        for (ch = 1; ch <= fbw_channels; ch++)
-            s->channel_uses_spx[ch] = get_bits1(bc);
+        unsigned channel_uses_spx = get_bits(bc, s->fbw_channels);
+        for (int ch = s->fbw_channels; ch >= 1; --ch) {
+            s->channel_uses_spx[ch] = channel_uses_spx & 1;
+            channel_uses_spx      >>= 1;
+        }
     }
 
     /* get the frequency bins of the spx copy region and the spx start
-- 
2.45.2


[-- Attachment #3: 0002-avcodec-hevc-hevcdec-Use-bitfield-instead-of-array-o.patch --]
[-- Type: text/x-patch, Size: 4811 bytes --]

From 2d673fe1701e5b703d8a6622ab0b7639a09693de Mon Sep 17 00:00:00 2001
From: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
Date: Sun, 30 Mar 2025 14:35:04 +0200
Subject: [PATCH 2/2] avcodec/hevc/hevcdec: Use bitfield instead of array of
 flags

It is simpler, avoids several loops and also makes GCC no longer
emit bogus -Wstringop-overflow= warnings.

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
---
 libavcodec/hevc/hevcdec.c | 55 ++++++++++++++-------------------------
 1 file changed, 19 insertions(+), 36 deletions(-)

diff --git a/libavcodec/hevc/hevcdec.c b/libavcodec/hevc/hevcdec.c
index e0ca1b9690..83acf3511f 100644
--- a/libavcodec/hevc/hevcdec.c
+++ b/libavcodec/hevc/hevcdec.c
@@ -174,11 +174,8 @@ static int pred_weight_table(SliceHeader *sh, void *logctx,
 {
     int i = 0;
     int j = 0;
-    uint8_t luma_weight_l0_flag[16];
-    uint8_t chroma_weight_l0_flag[16];
-    uint8_t luma_weight_l1_flag[16];
-    uint8_t chroma_weight_l1_flag[16];
     int luma_log2_weight_denom;
+    unsigned luma_weight_flags, chroma_weight_flags;
 
     luma_log2_weight_denom = get_ue_golomb_long(gb);
     if (luma_log2_weight_denom < 0 || luma_log2_weight_denom > 7) {
@@ -195,29 +192,22 @@ static int pred_weight_table(SliceHeader *sh, void *logctx,
         sh->chroma_log2_weight_denom = chroma_log2_weight_denom;
     }
 
+    luma_weight_flags   = get_bits(gb, sh->nb_refs[L0]);
+    chroma_weight_flags = sps->chroma_format_idc != 0 ? get_bits(gb, sh->nb_refs[L0]) : 0;
     for (i = 0; i < sh->nb_refs[L0]; i++) {
-        luma_weight_l0_flag[i] = get_bits1(gb);
-        if (!luma_weight_l0_flag[i]) {
-            sh->luma_weight_l0[i] = 1 << sh->luma_log2_weight_denom;
-            sh->luma_offset_l0[i] = 0;
-        }
-    }
-    if (sps->chroma_format_idc != 0) {
-        for (i = 0; i < sh->nb_refs[L0]; i++)
-            chroma_weight_l0_flag[i] = get_bits1(gb);
-    } else {
-        for (i = 0; i < sh->nb_refs[L0]; i++)
-            chroma_weight_l0_flag[i] = 0;
-    }
-    for (i = 0; i < sh->nb_refs[L0]; i++) {
-        if (luma_weight_l0_flag[i]) {
+        unsigned flag_bit = 1 << (sh->nb_refs[L0] - 1 - i);
+
+        if (luma_weight_flags & flag_bit) {
             int delta_luma_weight_l0 = get_se_golomb(gb);
             if ((int8_t)delta_luma_weight_l0 != delta_luma_weight_l0)
                 return AVERROR_INVALIDDATA;
             sh->luma_weight_l0[i] = (1 << sh->luma_log2_weight_denom) + delta_luma_weight_l0;
             sh->luma_offset_l0[i] = get_se_golomb(gb);
+        } else {
+            sh->luma_weight_l0[i] = 1 << sh->luma_log2_weight_denom;
+            sh->luma_offset_l0[i] = 0;
         }
-        if (chroma_weight_l0_flag[i]) {
+        if (chroma_weight_flags & flag_bit) {
             for (j = 0; j < 2; j++) {
                 int delta_chroma_weight_l0 = get_se_golomb(gb);
                 int delta_chroma_offset_l0 = get_se_golomb(gb);
@@ -239,29 +229,22 @@ static int pred_weight_table(SliceHeader *sh, void *logctx,
         }
     }
     if (sh->slice_type == HEVC_SLICE_B) {
+        luma_weight_flags   = get_bits(gb, sh->nb_refs[L1]);
+        chroma_weight_flags = sps->chroma_format_idc != 0 ? get_bits(gb, sh->nb_refs[L1]) : 0;
         for (i = 0; i < sh->nb_refs[L1]; i++) {
-            luma_weight_l1_flag[i] = get_bits1(gb);
-            if (!luma_weight_l1_flag[i]) {
-                sh->luma_weight_l1[i] = 1 << sh->luma_log2_weight_denom;
-                sh->luma_offset_l1[i] = 0;
-            }
-        }
-        if (sps->chroma_format_idc != 0) {
-            for (i = 0; i < sh->nb_refs[L1]; i++)
-                chroma_weight_l1_flag[i] = get_bits1(gb);
-        } else {
-            for (i = 0; i < sh->nb_refs[L1]; i++)
-                chroma_weight_l1_flag[i] = 0;
-        }
-        for (i = 0; i < sh->nb_refs[L1]; i++) {
-            if (luma_weight_l1_flag[i]) {
+            unsigned flag_bit = 1 << (sh->nb_refs[L1] - 1 - i);
+
+            if (luma_weight_flags & flag_bit) {
                 int delta_luma_weight_l1 = get_se_golomb(gb);
                 if ((int8_t)delta_luma_weight_l1 != delta_luma_weight_l1)
                     return AVERROR_INVALIDDATA;
                 sh->luma_weight_l1[i] = (1 << sh->luma_log2_weight_denom) + delta_luma_weight_l1;
                 sh->luma_offset_l1[i] = get_se_golomb(gb);
+            } else {
+                sh->luma_weight_l1[i] = 1 << sh->luma_log2_weight_denom;
+                sh->luma_offset_l1[i] = 0;
             }
-            if (chroma_weight_l1_flag[i]) {
+            if (chroma_weight_flags & flag_bit) {
                 for (j = 0; j < 2; j++) {
                     int delta_chroma_weight_l1 = get_se_golomb(gb);
                     int delta_chroma_offset_l1 = get_se_golomb(gb);
-- 
2.45.2


[-- Attachment #4: Type: text/plain, Size: 251 bytes --]

_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".

^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: [FFmpeg-devel] [PATCH 1/2] avcodec/ac3dec: Read spx flags at once, not one bit at a, time
  2025-03-30 12:38 [FFmpeg-devel] [PATCH 1/2] avcodec/ac3dec: Read spx flags at once, not one bit at a, time Andreas Rheinhardt
@ 2025-04-01 12:27 ` Andreas Rheinhardt
  0 siblings, 0 replies; 2+ messages in thread
From: Andreas Rheinhardt @ 2025-04-01 12:27 UTC (permalink / raw)
  To: ffmpeg-devel

Andreas Rheinhardt:
> Patches attached.
> 
> - Andreas
> 
Will apply tomorrow unless there are objections.

- Andreas

_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2025-04-01 12:27 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2025-03-30 12:38 [FFmpeg-devel] [PATCH 1/2] avcodec/ac3dec: Read spx flags at once, not one bit at a, time Andreas Rheinhardt
2025-04-01 12:27 ` Andreas Rheinhardt

Git Inbox Mirror of the ffmpeg-devel mailing list - see https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

This inbox may be cloned and mirrored by anyone:

	git clone --mirror https://master.gitmailbox.com/ffmpegdev/0 ffmpegdev/git/0.git

	# If you have public-inbox 1.1+ installed, you may
	# initialize and index your mirror using the following commands:
	public-inbox-init -V2 ffmpegdev ffmpegdev/ https://master.gitmailbox.com/ffmpegdev \
		ffmpegdev@gitmailbox.com
	public-inbox-index ffmpegdev

Example config snippet for mirrors.


AGPL code for this site: git clone https://public-inbox.org/public-inbox.git