diff mbox series

[FFmpeg-devel,12/14] avcodec/ffv1, ffv1dec: Store index of slice context

Message ID HE1PR0301MB21548AF921C2674D24E9EF6B8F449@HE1PR0301MB2154.eurprd03.prod.outlook.com
State New
Headers show
Series [FFmpeg-devel,01/14] avcodec/ffv1dec: Remove redundant writes, fix races | expand

Checks

Context Check Description
andriy/x86_make success Make finished
andriy/x86_make_fate success Make fate finished
andriy/PPC64_make success Make finished
andriy/PPC64_make_fate success Make fate finished

Commit Message

Andreas Rheinhardt April 24, 2021, 11:14 a.m. UTC
instead of searching the index again and again each time a slice is
decoded.

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
---
 libavcodec/ffv1.c    | 3 ++-
 libavcodec/ffv1.h    | 1 +
 libavcodec/ffv1dec.c | 8 +++-----
 3 files changed, 6 insertions(+), 6 deletions(-)
diff mbox series

Patch

diff --git a/libavcodec/ffv1.c b/libavcodec/ffv1.c
index 47bb032876..8e7542f918 100644
--- a/libavcodec/ffv1.c
+++ b/libavcodec/ffv1.c
@@ -131,10 +131,11 @@  av_cold int ff_ffv1_init_slice_contexts(FFV1Context *f)
         if (!fs)
             goto memfail;
 
-        f->slice_context[i++] = fs;
+        f->slice_context[i] = fs;
         memcpy(fs, f, sizeof(*fs));
         memset(fs->rc_stat2, 0, sizeof(fs->rc_stat2));
 
+        fs->slice_index  = i++;
         fs->slice_width  = sxe - sxs;
         fs->slice_height = sye - sys;
         fs->slice_x      = sxs;
diff --git a/libavcodec/ffv1.h b/libavcodec/ffv1.h
index f5ac8090bd..7f97b2c6f7 100644
--- a/libavcodec/ffv1.h
+++ b/libavcodec/ffv1.h
@@ -127,6 +127,7 @@  typedef struct FFV1Context {
     int quant_table_count;
 
     struct FFV1Context *slice_context[MAX_SLICES];
+    int slice_index;
     int slice_count;
     int max_slice_count;
     int num_v_slices;
diff --git a/libavcodec/ffv1dec.c b/libavcodec/ffv1dec.c
index c16fc81927..060efc25ab 100644
--- a/libavcodec/ffv1dec.c
+++ b/libavcodec/ffv1dec.c
@@ -230,19 +230,17 @@  static int decode_slice(AVCodecContext *c, void *arg)
     int width, height, x, y, ret;
     const int ps      = av_pix_fmt_desc_get(c->pix_fmt)->comp[0].step;
     AVFrame * const p = f->cur;
-    int i, si;
+    int i, si = fs->slice_index;
 
-    for( si=0; fs != f->slice_context[si]; si ++)
-        ;
+    av_assert1(si >= 0 && si < MAX_SLICES && f->slice_context[si] == fs);
 
     if(f->fsrc && !p->key_frame)
         ff_thread_await_progress(&f->last_picture, si, 0);
 
     if(f->fsrc && !p->key_frame) {
         FFV1Context *fssrc = f->fsrc->slice_context[si];
-        FFV1Context *fsdst = f->slice_context[si];
+        FFV1Context *fsdst = fs;
         av_assert1(fsdst->plane_count == fssrc->plane_count);
-        av_assert1(fsdst == fs);
 
         if (!p->key_frame)
             fsdst->slice_damaged |= fssrc->slice_damaged;