diff mbox series

[FFmpeg-devel,26/39] lavc/hevcdec: move slice decoding dispatch to its own function

Message ID 20240607130135.9088-26-anton@khirnov.net
State New
Headers show
Series [FFmpeg-devel,01/39] lavc/hevcdec: do not free SliceHeader arrays in pic_arrays_free() | expand

Commit Message

Anton Khirnov June 7, 2024, 1:01 p.m. UTC
Also move there a sanity check from hls_decode_entry() that should also
be performed when WPP is active (note that the check is not moved to
hls_slice_header() because it requires the HEVCContext.tab_slice_address
to be set up).
---
 libavcodec/hevc/hevcdec.c | 36 ++++++++++++++++++++++--------------
 1 file changed, 22 insertions(+), 14 deletions(-)
diff mbox series

Patch

diff --git a/libavcodec/hevc/hevcdec.c b/libavcodec/hevc/hevcdec.c
index 9c1d879953..bbcaa350c7 100644
--- a/libavcodec/hevc/hevcdec.c
+++ b/libavcodec/hevc/hevcdec.c
@@ -2578,14 +2578,6 @@  static int hls_decode_entry(HEVCContext *s, GetBitContext *gb)
     int ctb_addr_ts = pps->ctb_addr_rs_to_ts[s->sh.slice_ctb_addr_rs];
     int ret;
 
-    if (s->sh.dependent_slice_segment_flag) {
-        int prev_rs = pps->ctb_addr_ts_to_rs[ctb_addr_ts - 1];
-        if (s->tab_slice_address[prev_rs] != s->sh.slice_addr) {
-            av_log(s->avctx, AV_LOG_ERROR, "Previous slice segment missing\n");
-            return AVERROR_INVALIDDATA;
-        }
-    }
-
     while (more_data && ctb_addr_ts < sps->ctb_size) {
         int ctb_addr_rs = pps->ctb_addr_ts_to_rs[ctb_addr_ts];
 
@@ -2813,6 +2805,27 @@  static int hls_slice_data_wpp(HEVCContext *s, const H2645NAL *nal)
     return res;
 }
 
+static int decode_slice_data(HEVCContext *s, const H2645NAL *nal, GetBitContext *gb)
+{
+    const HEVCPPS *pps = s->pps;
+
+    if (s->sh.dependent_slice_segment_flag) {
+        int ctb_addr_ts = pps->ctb_addr_rs_to_ts[s->sh.slice_ctb_addr_rs];
+        int prev_rs = pps->ctb_addr_ts_to_rs[ctb_addr_ts - 1];
+        if (s->tab_slice_address[prev_rs] != s->sh.slice_addr) {
+            av_log(s->avctx, AV_LOG_ERROR, "Previous slice segment missing\n");
+            return AVERROR_INVALIDDATA;
+        }
+    }
+
+    if (s->avctx->active_thread_type == FF_THREAD_SLICE  &&
+        s->sh.num_entry_point_offsets > 0                &&
+        pps->num_tile_rows == 1 && pps->num_tile_columns == 1)
+        return hls_slice_data_wpp(s, nal);
+
+    return hls_decode_entry(s, gb);
+}
+
 static int set_side_data(HEVCContext *s)
 {
     AVFrame *out = s->cur_frame->f;
@@ -3152,12 +3165,7 @@  static int decode_nal_unit(HEVCContext *s, const H2645NAL *nal)
                 goto fail;
             }
 
-            if (s->avctx->active_thread_type == FF_THREAD_SLICE  &&
-                s->sh.num_entry_point_offsets > 0                &&
-                s->pps->num_tile_rows == 1 && s->pps->num_tile_columns == 1)
-                ctb_addr_ts = hls_slice_data_wpp(s, nal);
-            else
-                ctb_addr_ts = hls_decode_entry(s, &gb);
+            ctb_addr_ts = decode_slice_data(s, nal, &gb);
             if (ctb_addr_ts >= s->cur_frame->ctb_count) {
                 ret = hevc_frame_end(s);
                 if (ret < 0)