[FFmpeg-devel] [PATCH 10/10] lavc/hevc_ps: compactify ShortTermRPS

Anton Khirnov anton at khirnov.net
Wed Apr 10 16:31:18 EEST 2024


Do not use larger fields than needed, use size-1 bitfields for flags.

Reduces sizeof(HEVCSPS) by 1280 bytes.
---
 libavcodec/hevc_ps.c     |  6 +++---
 libavcodec/hevc_ps.h     | 19 +++++++++++--------
 libavcodec/vulkan_hevc.c |  2 +-
 3 files changed, 15 insertions(+), 12 deletions(-)

diff --git a/libavcodec/hevc_ps.c b/libavcodec/hevc_ps.c
index 76fe507e7b..7b486ce0af 100644
--- a/libavcodec/hevc_ps.c
+++ b/libavcodec/hevc_ps.c
@@ -143,11 +143,11 @@ int ff_hevc_decode_short_term_rps(GetBitContext *gb, AVCodecContext *avctx,
         for (i = 0; i <= rps_ridx->num_delta_pocs; i++) {
             used[k] = get_bits1(gb);
 
-            rps->use_delta_flag = 0;
+            rps->use_delta = 0;
             if (!used[k])
-                rps->use_delta_flag = get_bits1(gb);
+                rps->use_delta = get_bits1(gb);
 
-            if (used[k] || rps->use_delta_flag) {
+            if (used[k] || rps->use_delta) {
                 if (i < rps_ridx->num_delta_pocs)
                     delta_poc = delta_rps + rps_ridx->delta_poc[i];
                 else
diff --git a/libavcodec/hevc_ps.h b/libavcodec/hevc_ps.h
index 92b85115f7..a8d07aa1b2 100644
--- a/libavcodec/hevc_ps.h
+++ b/libavcodec/hevc_ps.h
@@ -70,16 +70,19 @@ typedef struct HEVCHdrParams {
 } HEVCHdrParams;
 
 typedef struct ShortTermRPS {
-    uint8_t rps_predict;
-    unsigned int delta_idx;
-    uint8_t use_delta_flag;
-    uint8_t delta_rps_sign;
-    unsigned int abs_delta_rps;
-    unsigned int num_negative_pics;
-    int num_delta_pocs;
-    int rps_idx_num_delta_pocs;
     int32_t delta_poc[32];
     uint32_t used;
+
+    uint8_t delta_idx;
+    uint8_t num_negative_pics;
+    uint8_t num_delta_pocs;
+    uint8_t rps_idx_num_delta_pocs;
+
+    uint16_t abs_delta_rps;
+    unsigned delta_rps_sign:1;
+
+    unsigned rps_predict:1;
+    unsigned use_delta:1;
 } ShortTermRPS;
 
 typedef struct HEVCWindow {
diff --git a/libavcodec/vulkan_hevc.c b/libavcodec/vulkan_hevc.c
index c2b65fc201..b109475194 100644
--- a/libavcodec/vulkan_hevc.c
+++ b/libavcodec/vulkan_hevc.c
@@ -359,7 +359,7 @@ static void set_sps(const HEVCSPS *sps, int sps_idx,
                 .delta_rps_sign = sps->st_rps[i].delta_rps_sign,
             },
             .delta_idx_minus1 = sps->st_rps[i].delta_idx - 1,
-            .use_delta_flag = sps->st_rps[i].use_delta_flag,
+            .use_delta_flag = sps->st_rps[i].use_delta,
             .abs_delta_rps_minus1 = sps->st_rps[i].abs_delta_rps - 1,
             .used_by_curr_pic_flag    = 0x0,
             .used_by_curr_pic_s0_flag = 0x0,
-- 
2.43.0



More information about the ffmpeg-devel mailing list