[FFmpeg-devel] [PATCH 15/39] lavc/hevcdec: pass SliceHeader explicitly to pred_weight_table()

Anton Khirnov anton at khirnov.net
Fri Jun 7 16:01:11 EEST 2024


And replace the HEVCContext* parameter by void *logctx.

Makes it clear that only SliceHeader is modified by this function.
---
 libavcodec/hevc/hevcdec.c | 75 ++++++++++++++++++++-------------------
 1 file changed, 38 insertions(+), 37 deletions(-)

diff --git a/libavcodec/hevc/hevcdec.c b/libavcodec/hevc/hevcdec.c
index 2c26d397df..6a9de79dcd 100644
--- a/libavcodec/hevc/hevcdec.c
+++ b/libavcodec/hevc/hevcdec.c
@@ -143,7 +143,8 @@ fail:
     return AVERROR(ENOMEM);
 }
 
-static int pred_weight_table(HEVCContext *s, const HEVCSPS *sps, GetBitContext *gb)
+static int pred_weight_table(SliceHeader *sh, void *logctx,
+                             const HEVCSPS *sps, GetBitContext *gb)
 {
     int i = 0;
     int j = 0;
@@ -155,40 +156,40 @@ static int pred_weight_table(HEVCContext *s, const HEVCSPS *sps, GetBitContext *
 
     luma_log2_weight_denom = get_ue_golomb_long(gb);
     if (luma_log2_weight_denom < 0 || luma_log2_weight_denom > 7) {
-        av_log(s->avctx, AV_LOG_ERROR, "luma_log2_weight_denom %d is invalid\n", luma_log2_weight_denom);
+        av_log(logctx, AV_LOG_ERROR, "luma_log2_weight_denom %d is invalid\n", luma_log2_weight_denom);
         return AVERROR_INVALIDDATA;
     }
-    s->sh.luma_log2_weight_denom = av_clip_uintp2(luma_log2_weight_denom, 3);
+    sh->luma_log2_weight_denom = av_clip_uintp2(luma_log2_weight_denom, 3);
     if (sps->chroma_format_idc != 0) {
         int64_t chroma_log2_weight_denom = luma_log2_weight_denom + (int64_t)get_se_golomb(gb);
         if (chroma_log2_weight_denom < 0 || chroma_log2_weight_denom > 7) {
-            av_log(s->avctx, AV_LOG_ERROR, "chroma_log2_weight_denom %"PRId64" is invalid\n", chroma_log2_weight_denom);
+            av_log(logctx, AV_LOG_ERROR, "chroma_log2_weight_denom %"PRId64" is invalid\n", chroma_log2_weight_denom);
             return AVERROR_INVALIDDATA;
         }
-        s->sh.chroma_log2_weight_denom = chroma_log2_weight_denom;
+        sh->chroma_log2_weight_denom = chroma_log2_weight_denom;
     }
 
-    for (i = 0; i < s->sh.nb_refs[L0]; i++) {
+    for (i = 0; i < sh->nb_refs[L0]; i++) {
         luma_weight_l0_flag[i] = get_bits1(gb);
         if (!luma_weight_l0_flag[i]) {
-            s->sh.luma_weight_l0[i] = 1 << s->sh.luma_log2_weight_denom;
-            s->sh.luma_offset_l0[i] = 0;
+            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 < s->sh.nb_refs[L0]; i++)
+        for (i = 0; i < sh->nb_refs[L0]; i++)
             chroma_weight_l0_flag[i] = get_bits1(gb);
     } else {
-        for (i = 0; i < s->sh.nb_refs[L0]; i++)
+        for (i = 0; i < sh->nb_refs[L0]; i++)
             chroma_weight_l0_flag[i] = 0;
     }
-    for (i = 0; i < s->sh.nb_refs[L0]; i++) {
+    for (i = 0; i < sh->nb_refs[L0]; i++) {
         if (luma_weight_l0_flag[i]) {
             int delta_luma_weight_l0 = get_se_golomb(gb);
             if ((int8_t)delta_luma_weight_l0 != delta_luma_weight_l0)
                 return AVERROR_INVALIDDATA;
-            s->sh.luma_weight_l0[i] = (1 << s->sh.luma_log2_weight_denom) + delta_luma_weight_l0;
-            s->sh.luma_offset_l0[i] = get_se_golomb(gb);
+            sh->luma_weight_l0[i] = (1 << sh->luma_log2_weight_denom) + delta_luma_weight_l0;
+            sh->luma_offset_l0[i] = get_se_golomb(gb);
         }
         if (chroma_weight_l0_flag[i]) {
             for (j = 0; j < 2; j++) {
@@ -200,39 +201,39 @@ static int pred_weight_table(HEVCContext *s, const HEVCSPS *sps, GetBitContext *
                     return AVERROR_INVALIDDATA;
                 }
 
-                s->sh.chroma_weight_l0[i][j] = (1 << s->sh.chroma_log2_weight_denom) + delta_chroma_weight_l0;
-                s->sh.chroma_offset_l0[i][j] = av_clip((delta_chroma_offset_l0 - ((128 * s->sh.chroma_weight_l0[i][j])
-                                                                                    >> s->sh.chroma_log2_weight_denom) + 128), -128, 127);
+                sh->chroma_weight_l0[i][j] = (1 << sh->chroma_log2_weight_denom) + delta_chroma_weight_l0;
+                sh->chroma_offset_l0[i][j] = av_clip((delta_chroma_offset_l0 - ((128 * sh->chroma_weight_l0[i][j])
+                                                                                    >> sh->chroma_log2_weight_denom) + 128), -128, 127);
             }
         } else {
-            s->sh.chroma_weight_l0[i][0] = 1 << s->sh.chroma_log2_weight_denom;
-            s->sh.chroma_offset_l0[i][0] = 0;
-            s->sh.chroma_weight_l0[i][1] = 1 << s->sh.chroma_log2_weight_denom;
-            s->sh.chroma_offset_l0[i][1] = 0;
+            sh->chroma_weight_l0[i][0] = 1 << sh->chroma_log2_weight_denom;
+            sh->chroma_offset_l0[i][0] = 0;
+            sh->chroma_weight_l0[i][1] = 1 << sh->chroma_log2_weight_denom;
+            sh->chroma_offset_l0[i][1] = 0;
         }
     }
-    if (s->sh.slice_type == HEVC_SLICE_B) {
-        for (i = 0; i < s->sh.nb_refs[L1]; i++) {
+    if (sh->slice_type == HEVC_SLICE_B) {
+        for (i = 0; i < sh->nb_refs[L1]; i++) {
             luma_weight_l1_flag[i] = get_bits1(gb);
             if (!luma_weight_l1_flag[i]) {
-                s->sh.luma_weight_l1[i] = 1 << s->sh.luma_log2_weight_denom;
-                s->sh.luma_offset_l1[i] = 0;
+                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 < s->sh.nb_refs[L1]; i++)
+            for (i = 0; i < sh->nb_refs[L1]; i++)
                 chroma_weight_l1_flag[i] = get_bits1(gb);
         } else {
-            for (i = 0; i < s->sh.nb_refs[L1]; i++)
+            for (i = 0; i < sh->nb_refs[L1]; i++)
                 chroma_weight_l1_flag[i] = 0;
         }
-        for (i = 0; i < s->sh.nb_refs[L1]; i++) {
+        for (i = 0; i < sh->nb_refs[L1]; i++) {
             if (luma_weight_l1_flag[i]) {
                 int delta_luma_weight_l1 = get_se_golomb(gb);
                 if ((int8_t)delta_luma_weight_l1 != delta_luma_weight_l1)
                     return AVERROR_INVALIDDATA;
-                s->sh.luma_weight_l1[i] = (1 << s->sh.luma_log2_weight_denom) + delta_luma_weight_l1;
-                s->sh.luma_offset_l1[i] = get_se_golomb(gb);
+                sh->luma_weight_l1[i] = (1 << sh->luma_log2_weight_denom) + delta_luma_weight_l1;
+                sh->luma_offset_l1[i] = get_se_golomb(gb);
             }
             if (chroma_weight_l1_flag[i]) {
                 for (j = 0; j < 2; j++) {
@@ -244,15 +245,15 @@ static int pred_weight_table(HEVCContext *s, const HEVCSPS *sps, GetBitContext *
                         return AVERROR_INVALIDDATA;
                     }
 
-                    s->sh.chroma_weight_l1[i][j] = (1 << s->sh.chroma_log2_weight_denom) + delta_chroma_weight_l1;
-                    s->sh.chroma_offset_l1[i][j] = av_clip((delta_chroma_offset_l1 - ((128 * s->sh.chroma_weight_l1[i][j])
-                                                                                        >> s->sh.chroma_log2_weight_denom) + 128), -128, 127);
+                    sh->chroma_weight_l1[i][j] = (1 << sh->chroma_log2_weight_denom) + delta_chroma_weight_l1;
+                    sh->chroma_offset_l1[i][j] = av_clip((delta_chroma_offset_l1 - ((128 * sh->chroma_weight_l1[i][j])
+                                                                                        >> sh->chroma_log2_weight_denom) + 128), -128, 127);
                 }
             } else {
-                s->sh.chroma_weight_l1[i][0] = 1 << s->sh.chroma_log2_weight_denom;
-                s->sh.chroma_offset_l1[i][0] = 0;
-                s->sh.chroma_weight_l1[i][1] = 1 << s->sh.chroma_log2_weight_denom;
-                s->sh.chroma_offset_l1[i][1] = 0;
+                sh->chroma_weight_l1[i][0] = 1 << sh->chroma_log2_weight_denom;
+                sh->chroma_offset_l1[i][0] = 0;
+                sh->chroma_weight_l1[i][1] = 1 << sh->chroma_log2_weight_denom;
+                sh->chroma_offset_l1[i][1] = 0;
             }
         }
     }
@@ -857,7 +858,7 @@ static int hls_slice_header(HEVCContext *s, GetBitContext *gb)
 
             if ((pps->weighted_pred_flag   && sh->slice_type == HEVC_SLICE_P) ||
                 (pps->weighted_bipred_flag && sh->slice_type == HEVC_SLICE_B)) {
-                int ret = pred_weight_table(s, sps, gb);
+                int ret = pred_weight_table(sh, s->avctx, sps, gb);
                 if (ret < 0)
                     return ret;
             }
-- 
2.43.0



More information about the ffmpeg-devel mailing list