[FFmpeg-cvslog] avcodec/hevc_ps: use get_ue_golomb() for some SPS Screen Content Coding extension fields

James Almer git at videolan.org
Mon May 1 00:32:23 EEST 2023


ffmpeg | branch: master | James Almer <jamrial at gmail.com> | Sun Apr 30 18:24:23 2023 -0300| [45fc89bb14989a585be024faf1349806a1acbb9a] | committer: James Almer

avcodec/hevc_ps: use get_ue_golomb() for some SPS Screen Content Coding extension fields

Also remove the _minus1 part of the name to be in line with the rest of the
decoder.

Signed-off-by: James Almer <jamrial at gmail.com>

> http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=45fc89bb14989a585be024faf1349806a1acbb9a
---

 libavcodec/hevc_ps.c    | 21 ++++++++++++++-------
 libavcodec/hevc_ps.h    |  2 +-
 libavcodec/vaapi_hevc.c |  2 +-
 3 files changed, 16 insertions(+), 9 deletions(-)

diff --git a/libavcodec/hevc_ps.c b/libavcodec/hevc_ps.c
index 585b095073..bba0ebd1dd 100644
--- a/libavcodec/hevc_ps.c
+++ b/libavcodec/hevc_ps.c
@@ -1140,17 +1140,24 @@ int ff_hevc_parse_sps(HEVCSPS *sps, GetBitContext *gb, unsigned int *sps_id,
             sps->sps_curr_pic_ref_enabled_flag = get_bits1(gb);
             sps->palette_mode_enabled_flag     = get_bits1(gb);
             if (sps->palette_mode_enabled_flag) {
-                sps->palette_max_size = get_ue_golomb_long(gb);
-                sps->delta_palette_max_predictor_size = get_ue_golomb_long(gb);
+                sps->palette_max_size = get_ue_golomb(gb);
+                sps->delta_palette_max_predictor_size = get_ue_golomb(gb);
                 sps->sps_palette_predictor_initializers_present_flag = get_bits1(gb);
 
                 if (sps->sps_palette_predictor_initializers_present_flag) {
-                    sps->sps_num_palette_predictor_initializers_minus1 = get_ue_golomb_long(gb);
+                    sps->sps_num_palette_predictor_initializers = get_ue_golomb(gb) + 1;
+                    if (sps->sps_num_palette_predictor_initializers > HEVC_MAX_PALETTE_PREDICTOR_SIZE) {
+                        av_log(avctx, AV_LOG_ERROR,
+                               "sps_num_palette_predictor_initializers out of range: %u\n",
+                               sps->sps_num_palette_predictor_initializers);
+                        return AVERROR_INVALIDDATA;
+                    }
                     num_comps = !sps->chroma_format_idc ? 1 : 3;
-                    for (int comp = 0; comp < num_comps; comp++)
-                        for (i = 0; i <= sps->sps_num_palette_predictor_initializers_minus1; i++)
-                            sps->sps_palette_predictor_initializer[comp][i] =
-                                    get_bits(gb, !comp ? sps->bit_depth : sps->bit_depth_chroma);
+                    for (int comp = 0; comp < num_comps; comp++) {
+                        int bit_depth = !comp ? sps->bit_depth : sps->bit_depth_chroma;
+                        for (i = 0; i < sps->sps_num_palette_predictor_initializers; i++)
+                            sps->sps_palette_predictor_initializer[comp][i] = get_bits(gb, bit_depth);
+                    }
                 }
             }
             sps->motion_vector_resolution_control_idc   = get_bits(gb, 2);
diff --git a/libavcodec/hevc_ps.h b/libavcodec/hevc_ps.h
index 8cd99bb161..a0437815d6 100644
--- a/libavcodec/hevc_ps.h
+++ b/libavcodec/hevc_ps.h
@@ -219,7 +219,7 @@ typedef struct HEVCSPS {
     int palette_max_size;
     int delta_palette_max_predictor_size;
     int sps_palette_predictor_initializers_present_flag;
-    int sps_num_palette_predictor_initializers_minus1;
+    int sps_num_palette_predictor_initializers;
     int sps_palette_predictor_initializer[3][HEVC_MAX_PALETTE_PREDICTOR_SIZE];
     int motion_vector_resolution_control_idc;
     int intra_boundary_filtering_disabled_flag;
diff --git a/libavcodec/vaapi_hevc.c b/libavcodec/vaapi_hevc.c
index 984af75c84..17c38963f8 100644
--- a/libavcodec/vaapi_hevc.c
+++ b/libavcodec/vaapi_hevc.c
@@ -259,7 +259,7 @@ static int vaapi_hevc_start_frame(AVCodecContext          *avctx,
     pre_palette_size = pps->pps_palette_predictor_initializers_present_flag ?
                        pps->pps_num_palette_predictor_initializers :
                        (sps->sps_palette_predictor_initializers_present_flag ?
-                       sps->sps_num_palette_predictor_initializers_minus1 + 1 :
+                       sps->sps_num_palette_predictor_initializers :
                        0);
 
     if (avctx->profile == FF_PROFILE_HEVC_SCC) {



More information about the ffmpeg-cvslog mailing list