[FFmpeg-cvslog] lavc/hevc_ps: reduce the size of used_by_curr_pic_lt_sps_flag

Anton Khirnov git at videolan.org
Fri May 31 20:32:35 EEST 2024


ffmpeg | branch: master | Anton Khirnov <anton at khirnov.net> | Wed Apr 10 11:27:51 2024 +0200| [bd1a06dc439403d7e16a220629165e34791016d7] | committer: Anton Khirnov

lavc/hevc_ps: reduce the size of used_by_curr_pic_lt_sps_flag

It is currently an array of 32 uint8_t, each storing a single flag. A
single uint32_t is sufficient.

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

 libavcodec/hevc_ps.c     | 4 +++-
 libavcodec/hevc_ps.h     | 2 +-
 libavcodec/hevcdec.c     | 2 +-
 libavcodec/vulkan_hevc.c | 3 +--
 4 files changed, 6 insertions(+), 5 deletions(-)

diff --git a/libavcodec/hevc_ps.c b/libavcodec/hevc_ps.c
index 25f087ed75..8d5fc0d0ca 100644
--- a/libavcodec/hevc_ps.c
+++ b/libavcodec/hevc_ps.c
@@ -1094,9 +1094,11 @@ int ff_hevc_parse_sps(HEVCSPS *sps, GetBitContext *gb, unsigned int *sps_id,
                    sps->num_long_term_ref_pics_sps);
             return AVERROR_INVALIDDATA;
         }
+
+        sps->used_by_curr_pic_lt = 0;
         for (i = 0; i < sps->num_long_term_ref_pics_sps; i++) {
             sps->lt_ref_pic_poc_lsb_sps[i]       = get_bits(gb, sps->log2_max_poc_lsb);
-            sps->used_by_curr_pic_lt_sps_flag[i] = get_bits1(gb);
+            sps->used_by_curr_pic_lt            |= get_bits1(gb) * (1 << i);
         }
     }
 
diff --git a/libavcodec/hevc_ps.h b/libavcodec/hevc_ps.h
index 61a0fe2219..b2f3a8dbd1 100644
--- a/libavcodec/hevc_ps.h
+++ b/libavcodec/hevc_ps.h
@@ -230,7 +230,7 @@ typedef struct HEVCSPS {
 
     uint8_t long_term_ref_pics_present_flag;
     uint16_t lt_ref_pic_poc_lsb_sps[HEVC_MAX_LONG_TERM_REF_PICS];
-    uint8_t used_by_curr_pic_lt_sps_flag[HEVC_MAX_LONG_TERM_REF_PICS];
+    uint32_t used_by_curr_pic_lt;
     uint8_t num_long_term_ref_pics_sps;
 
     struct {
diff --git a/libavcodec/hevcdec.c b/libavcodec/hevcdec.c
index b8ab34d710..ef3ed75c8a 100644
--- a/libavcodec/hevcdec.c
+++ b/libavcodec/hevcdec.c
@@ -295,7 +295,7 @@ static int decode_lt_rps(HEVCContext *s, LongTermRPS *rps, GetBitContext *gb)
                 lt_idx_sps = get_bits(gb, av_ceil_log2(sps->num_long_term_ref_pics_sps));
 
             rps->poc[i]  = sps->lt_ref_pic_poc_lsb_sps[lt_idx_sps];
-            rps->used[i] = sps->used_by_curr_pic_lt_sps_flag[lt_idx_sps];
+            rps->used[i] = !!(sps->used_by_curr_pic_lt & (1 << lt_idx_sps));
         } else {
             rps->poc[i]  = get_bits(gb, sps->log2_max_poc_lsb);
             rps->used[i] = get_bits1(gb);
diff --git a/libavcodec/vulkan_hevc.c b/libavcodec/vulkan_hevc.c
index 2705a965b9..9b40f5ad58 100644
--- a/libavcodec/vulkan_hevc.c
+++ b/libavcodec/vulkan_hevc.c
@@ -386,11 +386,10 @@ static void set_sps(const HEVCSPS *sps, int sps_idx,
     }
 
     *ltr = (StdVideoH265LongTermRefPicsSps) {
-        .used_by_curr_pic_lt_sps_flag = 0x0,
+        .used_by_curr_pic_lt_sps_flag = sps->used_by_curr_pic_lt,
     };
 
     for (int i = 0; i < sps->num_long_term_ref_pics_sps; i++) {
-        ltr->used_by_curr_pic_lt_sps_flag |= sps->used_by_curr_pic_lt_sps_flag[i] << i;
         ltr->lt_ref_pic_poc_lsb_sps[i]     = sps->lt_ref_pic_poc_lsb_sps[i];
     }
 



More information about the ffmpeg-cvslog mailing list