diff mbox series

[FFmpeg-devel,4/4] avcodec/hevcdec: Avoid redundant entry_point_offsets array

Message ID AM7PR03MB66601467F893BCB1EF3B92258F4B9@AM7PR03MB6660.eurprd03.prod.outlook.com
State New
Headers show
Series [FFmpeg-devel,1/4] avcodec/hevcdec: Combine multiple allocations | expand

Checks

Context Check Description
andriy/make_x86 success Make finished
andriy/make_fate_x86 success Make fate finished
andriy/make_ppc success Make finished
andriy/make_fate_ppc success Make fate finished

Commit Message

Andreas Rheinhardt Jan. 5, 2022, 9:19 p.m. UTC
Instead modify the offsets in place.

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
---
 libavcodec/hevcdec.c | 19 +++++++++----------
 libavcodec/hevcdec.h |  1 -
 2 files changed, 9 insertions(+), 11 deletions(-)

Comments

Michael Niedermayer Jan. 6, 2022, 9:47 a.m. UTC | #1
On Wed, Jan 05, 2022 at 10:19:08PM +0100, Andreas Rheinhardt wrote:
> Instead modify the offsets in place.
> 
> Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
> ---
>  libavcodec/hevcdec.c | 19 +++++++++----------
>  libavcodec/hevcdec.h |  1 -
>  2 files changed, 9 insertions(+), 11 deletions(-)

This seems to break -threads 4 -thread_type slice
ill send you the sample file privatly

[...]
diff mbox series

Patch

diff --git a/libavcodec/hevcdec.c b/libavcodec/hevcdec.c
index fc0dc7a584..6aa14455d0 100644
--- a/libavcodec/hevcdec.c
+++ b/libavcodec/hevcdec.c
@@ -77,7 +77,6 @@  static void pic_arrays_free(HEVCContext *s)
     av_freep(&s->horizontal_bs);
     av_freep(&s->vertical_bs);
 
-    av_freep(&s->sh.entry_point_offset);
     av_freep(&s->sh.entry_points);
 
     av_buffer_pool_uninit(&s->tab_mvf_pool);
@@ -913,18 +912,16 @@  static int hls_slice_header(HEVCContext *s)
                 return AVERROR_INVALIDDATA;
             }
 
-            av_freep(&sh->entry_point_offset);
             av_freep(&sh->entry_points);
-            sh->entry_point_offset = av_malloc_array(sh->num_entry_point_offsets, sizeof(unsigned));
             FF_ALLOC_TYPED_ARRAY(sh->entry_points, sh->num_entry_point_offsets);
-            if (!sh->entry_point_offset || !sh->entry_points) {
+            if (!sh->entry_points) {
                 sh->num_entry_point_offsets = 0;
                 av_log(s->avctx, AV_LOG_ERROR, "Failed to allocate memory\n");
                 return AVERROR(ENOMEM);
             }
             for (i = 0; i < sh->num_entry_point_offsets; i++) {
                 unsigned val = get_bits_long(gb, offset_len);
-                sh->entry_point_offset[i] = val + 1; // +1; // +1 to get the size
+                sh->entry_points[i].offset = val + 1; // +1; // +1 to get the size
             }
             if (s->threads_number > 1 && (s->ps.pps->num_tile_rows > 1 || s->ps.pps->num_tile_columns > 1)) {
                 s->enable_parallel_tiles = 0; // TODO: you can enable tiles in parallel here
@@ -2657,29 +2654,31 @@  static int hls_slice_data_wpp(HEVCContext *s, const H2645NAL *nal)
 
     offset = (lc->gb.index >> 3);
 
-    for (j = 0, cmpt = 0, startheader = offset + s->sh.entry_point_offset[0]; j < nal->skipped_bytes; j++) {
+    for (j = 0, cmpt = 0, startheader = offset + s->sh.entry_points[0].offset; j < nal->skipped_bytes; j++) {
         if (nal->skipped_bytes_pos[j] >= offset && nal->skipped_bytes_pos[j] < startheader) {
             startheader--;
             cmpt++;
         }
     }
 
+    /* Convert the entry_points offsets from being pre-0x03-escaping
+     * to post-0x03-escaping and set sizes. */
     for (i = 1; i < s->sh.num_entry_point_offsets; i++) {
-        offset += (s->sh.entry_point_offset[i - 1] - cmpt);
+        offset += (s->sh.entry_points[i - 1].offset - cmpt);
         for (j = 0, cmpt = 0, startheader = offset
-             + s->sh.entry_point_offset[i]; j < nal->skipped_bytes; j++) {
+             + s->sh.entry_points[i].offset; j < nal->skipped_bytes; j++) {
             if (nal->skipped_bytes_pos[j] >= offset && nal->skipped_bytes_pos[j] < startheader) {
                 startheader--;
                 cmpt++;
             }
         }
         s->sh.entry_points[i - 1] = (EntryPoint){
-            .size   = s->sh.entry_point_offset[i] - cmpt,
+            .size   = s->sh.entry_points[i].offset - cmpt,
             .offset = offset
         };
     }
     if (s->sh.num_entry_point_offsets != 0) {
-        offset += s->sh.entry_point_offset[s->sh.num_entry_point_offsets - 1] - cmpt;
+        offset += s->sh.entry_points[s->sh.num_entry_point_offsets - 1].offset - cmpt;
         if (length < offset) {
             av_log(s->avctx, AV_LOG_ERROR, "entry_point_offset table is corrupted\n");
             res = AVERROR_INVALIDDATA;
diff --git a/libavcodec/hevcdec.h b/libavcodec/hevcdec.h
index 76ad262558..9ac04555f4 100644
--- a/libavcodec/hevcdec.h
+++ b/libavcodec/hevcdec.h
@@ -304,7 +304,6 @@  typedef struct SliceHeader {
 
     unsigned int max_num_merge_cand; ///< 5 - 5_minus_max_num_merge_cand
 
-    unsigned *entry_point_offset;
     EntryPoint *entry_points;
     int num_entry_point_offsets;