Patches attached. - Andreas
From d45f52c848de42ef40b0593330724de13324d921 Mon Sep 17 00:00:00 2001 From: Andreas Rheinhardt <andreas.rheinha...@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.rheinha...@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
From 2d673fe1701e5b703d8a6622ab0b7639a09693de Mon Sep 17 00:00:00 2001 From: Andreas Rheinhardt <andreas.rheinha...@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.rheinha...@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
_______________________________________________ ffmpeg-devel mailing list ffmpeg-devel@ffmpeg.org https://ffmpeg.org/mailman/listinfo/ffmpeg-devel To unsubscribe, visit link above, or email ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".