PR #24340 opened by mkver URL: https://code.ffmpeg.org/FFmpeg/FFmpeg/pulls/24340 Patch URL: https://code.ffmpeg.org/FFmpeg/FFmpeg/pulls/24340.patch
>From 85b9bc8110e73c5e701a68b02aaedfcfe84dd344 Mon Sep 17 00:00:00 2001 From: Andreas Rheinhardt <[email protected]> Date: Mon, 31 Aug 2026 22:36:03 +0200 Subject: [PATCH 1/2] avcodec/h264_mvpred: Optimize always-false checks away data_partitioning is only used with CAVLC, not CABAC. Signed-off-by: Andreas Rheinhardt <[email protected]> --- libavcodec/h264_mvpred.h | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/libavcodec/h264_mvpred.h b/libavcodec/h264_mvpred.h index 1d5f22417e..bcc058b1e4 100644 --- a/libavcodec/h264_mvpred.h +++ b/libavcodec/h264_mvpred.h @@ -676,8 +676,8 @@ static void fill_decode_caches(const H264Context *h, H264SliceContext *sl, int m int nnz_mask = -1; int nnz_excluded = 64; // 64: unavailable, 0: present but empty - if (sl->data_partitioning && h->ps.pps->constrained_intra_pred && - IS_INTRA(mb_type)) { + if (!CABAC(h) && sl->data_partitioning && + h->ps.pps->constrained_intra_pred && IS_INTRA(mb_type)) { nnz_mask = IS_INTRA(-1); if (h->workaround_bugs & FF_BUG_H264_DP_NNZ) nnz_excluded = 0; @@ -696,7 +696,7 @@ static void fill_decode_caches(const H264Context *h, H264SliceContext *sl, int m } } else { uint32_t top_empty = CABAC(h) && !IS_INTRA(mb_type) ? 0 : - top_type ? nnz_excluded * 0x01010101u : 0x40404040; + !CABAC(h) && top_type ? nnz_excluded * 0x01010101u : 0x40404040; AV_WN32A(&nnz_cache[4 + 8 * 0], top_empty); AV_WN32A(&nnz_cache[4 + 8 * 5], top_empty); AV_WN32A(&nnz_cache[4 + 8 * 10], top_empty); @@ -723,7 +723,7 @@ static void fill_decode_caches(const H264Context *h, H264SliceContext *sl, int m } } else { int empty = CABAC(h) && !IS_INTRA(mb_type) ? 0 : - left_type[LEFT(i)] ? nnz_excluded : 64; + !CABAC(h) && left_type[LEFT(i)] ? nnz_excluded : 64; nnz_cache[3 + 8 * 1 + 2 * 8 * i] = nnz_cache[3 + 8 * 2 + 2 * 8 * i] = nnz_cache[3 + 8 * 6 + 2 * 8 * i] = -- 2.52.0 >From 1fb3d21cf94a303f6d7b36ddd2abd18fe74a3329 Mon Sep 17 00:00:00 2001 From: Andreas Rheinhardt <[email protected]> Date: Mon, 31 Aug 2026 23:41:34 +0200 Subject: [PATCH 2/2] avcodec/h264dec: Put CABAC and data_partitioing stuff into union data_partitioning and CABAC are incompatible, so one can put data_partitioning stuff into a union with the CABAC context/state. Signed-off-by: Andreas Rheinhardt <[email protected]> --- libavcodec/h264dec.h | 32 +++++++++++++++++++------------- 1 file changed, 19 insertions(+), 13 deletions(-) diff --git a/libavcodec/h264dec.h b/libavcodec/h264dec.h index 7bce897021..3b05605423 100644 --- a/libavcodec/h264dec.h +++ b/libavcodec/h264dec.h @@ -180,14 +180,7 @@ typedef struct H264SliceContext { GetBitContext gb; ERContext *er; - /* Data partitioning: residual comes from gb_dpb (intra) or gb_dpc (inter), - * chosen per macroblock. Values not pointers: this struct is memcpy'd. */ - GetBitContext gb_dpb; - GetBitContext gb_dpc; int data_partitioning; - int dpb_available; - int dpc_available; - unsigned slice_id; int slice_num; int slice_type; @@ -321,12 +314,25 @@ typedef struct H264SliceContext { uint8_t (*mvd_table[2])[2]; - /** - * Cabac - */ - CABACContext cabac; - uint8_t cabac_state[1024]; - int cabac_init_idc; + union { + struct { + /** + * Cabac + */ + CABACContext cabac; + uint8_t cabac_state[1024]; + int cabac_init_idc; + }; + struct { + /* Data partitioning: residual comes from gb_dpb (intra) or gb_dpc (inter), + * chosen per macroblock. Values not pointers: this struct is memcpy'd. */ + GetBitContext gb_dpb; + GetBitContext gb_dpc; + int dpb_available; + int dpc_available; + unsigned slice_id; + }; + }; MMCO mmco[H264_MAX_MMCO_COUNT]; int nb_mmco; -- 2.52.0 _______________________________________________ ffmpeg-devel mailing list -- [email protected] To unsubscribe send an email to [email protected]
