There is no reason to delay it and this is a more natural place for
this code.
---
 libavcodec/ffv1dec.c | 53 ++++++++++++++++++++++----------------------
 1 file changed, 27 insertions(+), 26 deletions(-)

diff --git a/libavcodec/ffv1dec.c b/libavcodec/ffv1dec.c
index aa2c35880e..5821a4156a 100644
--- a/libavcodec/ffv1dec.c
+++ b/libavcodec/ffv1dec.c
@@ -290,7 +290,7 @@ static int decode_slice(AVCodecContext *c, void *arg)
     if ((p->flags & AV_FRAME_FLAG_KEY) || sc->slice_reset_contexts) {
         ff_ffv1_clear_slice_state(f, sc);
     } else if (sc->slice_damaged) {
-        return AVERROR_INVALIDDATA;
+        goto handle_damage;
     }
 
     width  = sc->slice_width;
@@ -347,6 +347,32 @@ static int decode_slice(AVCodecContext *c, void *arg)
         }
     }
 
+handle_damage:
+    if (sc->slice_damaged && f->last_picture.f) {
+        const AVPixFmtDescriptor *desc = av_pix_fmt_desc_get(c->pix_fmt);
+        const uint8_t *src[4];
+        uint8_t *dst[4];
+
+        ff_progress_frame_await(&f->last_picture, si);
+
+        for (int j = 0; j < desc->nb_components; j++) {
+            int pixshift = desc->comp[j].depth > 8;
+            int sh = (j == 1 || j == 2) ? f->chroma_h_shift : 0;
+            int sv = (j == 1 || j == 2) ? f->chroma_v_shift : 0;
+            dst[j] = p->data[j] + p->linesize[j] *
+                     (sc->slice_y >> sv) + ((sc->slice_x >> sh) << pixshift);
+            src[j] = f->last_picture.f->data[j] + 
f->last_picture.f->linesize[j] *
+                     (sc->slice_y >> sv) + ((sc->slice_x >> sh) << pixshift);
+
+        }
+
+        av_image_copy(dst, p->linesize, src,
+                      f->last_picture.f->linesize,
+                      c->pix_fmt,
+                      sc->slice_width,
+                      sc->slice_height);
+    }
+
     ff_progress_frame_report(&f->picture, si);
 
     return 0;
@@ -964,31 +990,6 @@ static int decode_frame(AVCodecContext *avctx, AVFrame 
*rframe,
                    f->slice_count,
                    sizeof(*f->slices));
 
-    for (int i = f->slice_count - 1; i >= 0; i--) {
-        FFV1SliceContext *sc = &f->slices[i];
-        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];
-            ff_progress_frame_await(&f->last_picture, INT_MAX);
-            for (int j = 0; j < desc->nb_components; j++) {
-                int pixshift = desc->comp[j].depth > 8;
-                int sh = (j == 1 || j == 2) ? f->chroma_h_shift : 0;
-                int sv = (j == 1 || j == 2) ? f->chroma_v_shift : 0;
-                dst[j] = p->data[j] + p->linesize[j] *
-                         (sc->slice_y >> sv) + ((sc->slice_x >> sh) << 
pixshift);
-                src[j] = f->last_picture.f->data[j] + 
f->last_picture.f->linesize[j] *
-                         (sc->slice_y >> sv) + ((sc->slice_x >> sh) << 
pixshift);
-
-            }
-
-            av_image_copy(dst, p->linesize, src,
-                          f->last_picture.f->linesize,
-                          avctx->pix_fmt,
-                          sc->slice_width,
-                          sc->slice_height);
-        }
-    }
     ff_progress_frame_report(&f->picture, INT_MAX);
 
     ff_progress_frame_unref(&f->last_picture);
-- 
2.43.0

_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".

Reply via email to