diff mbox series

[FFmpeg-devel,24/39] lavc/ffv1dec: move slice_damaged to per-slice context

Message ID 20240716171155.31838-24-anton@khirnov.net
State New
Headers show
Series [FFmpeg-devel,01/39] tests/fate/vcodec: add vsynth tests for FFV1 version 2 | expand

Checks

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

Commit Message

Anton Khirnov July 16, 2024, 5:11 p.m. UTC
---
 libavcodec/ffv1.h    |  2 +-
 libavcodec/ffv1dec.c | 18 ++++++++----------
 2 files changed, 9 insertions(+), 11 deletions(-)

Comments

Michael Niedermayer July 24, 2024, 7:45 p.m. UTC | #1
On Tue, Jul 16, 2024 at 07:11:39PM +0200, Anton Khirnov wrote:
> ---
>  libavcodec/ffv1.h    |  2 +-
>  libavcodec/ffv1dec.c | 18 ++++++++----------
>  2 files changed, 9 insertions(+), 11 deletions(-)

LGTM

thx

[...]
diff mbox series

Patch

diff --git a/libavcodec/ffv1.h b/libavcodec/ffv1.h
index cef61f38ec..c4803654f2 100644
--- a/libavcodec/ffv1.h
+++ b/libavcodec/ffv1.h
@@ -91,6 +91,7 @@  typedef struct FFV1SliceContext {
         // decoder-only
         struct {
             int slice_reset_contexts;
+            int slice_damaged;
         };
 
         // encoder-only
@@ -131,7 +132,6 @@  typedef struct FFV1Context {
 
     int ec;
     int intra;
-    int slice_damaged;
     int key_frame_ok;
     int context_model;
 
diff --git a/libavcodec/ffv1dec.c b/libavcodec/ffv1dec.c
index 92e5b2a80b..bd46930ec7 100644
--- a/libavcodec/ffv1dec.c
+++ b/libavcodec/ffv1dec.c
@@ -268,11 +268,10 @@  static int decode_slice(AVCodecContext *c, void *arg)
         ff_progress_frame_await(&f->last_picture, si);
 
     if(f->fsrc && !(p->flags & AV_FRAME_FLAG_KEY)) {
-        FFV1Context *fssrc = f->fsrc->slice_context[si];
         const FFV1SliceContext *scsrc = &f->fsrc->slices[si];
 
         if (!(p->flags & AV_FRAME_FLAG_KEY))
-            fs->slice_damaged |= fssrc->slice_damaged;
+            sc->slice_damaged |= scsrc->slice_damaged;
 
         for (int i = 0; i < f->plane_count; i++) {
             const PlaneContext *psrc = &scsrc->plane[i];
@@ -302,7 +301,7 @@  static int decode_slice(AVCodecContext *c, void *arg)
             return AVERROR(ENOMEM);
         if (decode_slice_header(f, fs, sc, p) < 0) {
             sc->slice_x = sc->slice_y = sc->slice_height = sc->slice_width = 0;
-            fs->slice_damaged = 1;
+            sc->slice_damaged = 1;
             return AVERROR_INVALIDDATA;
         }
     }
@@ -310,7 +309,7 @@  static int decode_slice(AVCodecContext *c, void *arg)
         return ret;
     if ((p->flags & AV_FRAME_FLAG_KEY) || sc->slice_reset_contexts) {
         ff_ffv1_clear_slice_state(f, sc);
-    } else if (fs->slice_damaged) {
+    } else if (sc->slice_damaged) {
         return AVERROR_INVALIDDATA;
     }
 
@@ -364,7 +363,7 @@  static int decode_slice(AVCodecContext *c, void *arg)
         v = sc->c.bytestream_end - sc->c.bytestream - 2 - 5*f->ec;
         if (v) {
             av_log(f->avctx, AV_LOG_ERROR, "bytestream end mismatching by %d\n", v);
-            fs->slice_damaged = 1;
+            sc->slice_damaged = 1;
         }
     }
 
@@ -793,7 +792,7 @@  static int read_header(FFV1Context *f)
         FFV1SliceContext *sc = &f->slices[j];
         fs->packed_at_lsb = f->packed_at_lsb;
 
-        fs->slice_damaged = 0;
+        sc->slice_damaged = 0;
 
         if (f->version == 2) {
             int sx = get_symbol(c, state, 0);
@@ -965,7 +964,7 @@  static int decode_frame(AVCodecContext *avctx, AVFrame *rframe,
                 } else {
                     av_log(f->avctx, AV_LOG_ERROR, "\n");
                 }
-                fs->slice_damaged = 1;
+                sc->slice_damaged = 1;
             }
             if (avctx->debug & FF_DEBUG_PICT_INFO) {
                 av_log(avctx, AV_LOG_DEBUG, "slice %d, CRC: 0x%08"PRIX32"\n", i, AV_RB32(buf_p + v - 4));
@@ -989,9 +988,8 @@  static int decode_frame(AVCodecContext *avctx, AVFrame *rframe,
                    sizeof(void*));
 
     for (int i = f->slice_count - 1; i >= 0; i--) {
-        FFV1Context *fs = f->slice_context[i];
         FFV1SliceContext *sc = &f->slices[i];
-        if (fs->slice_damaged && f->last_picture.f) {
+        if (sc->slice_damaged && f->last_picture.f) {
             const AVPixFmtDescriptor *desc = av_pix_fmt_desc_get(avctx->pix_fmt);
             const uint8_t *src[4];
             uint8_t *dst[4];
@@ -1044,7 +1042,6 @@  static void copy_fields(FFV1Context *fsdst, const FFV1Context *fssrc,
 
     fsdst->ec                  = fsrc->ec;
     fsdst->intra               = fsrc->intra;
-    fsdst->slice_damaged       = fssrc->slice_damaged;
     fsdst->key_frame_ok        = fsrc->key_frame_ok;
 
     fsdst->packed_at_lsb       = fsrc->packed_at_lsb;
@@ -1077,6 +1074,7 @@  static int update_thread_context(AVCodecContext *dst, const AVCodecContext *src)
         const FFV1SliceContext *sc0 = &fsrc->slices[i];
 
         copy_fields(fsdst, fssrc, fsrc);
+        sc->slice_damaged = sc0->slice_damaged;
 
         if (fsrc->version < 3) {
             sc->slice_x             = sc0->slice_x;