Git Inbox Mirror of the ffmpeg-devel mailing list - see https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
 help / color / mirror / Atom feed
* [FFmpeg-devel] [PATCH 1/2] avcodec/error_resilience: Make applying decode_error_flags optional
@ 2023-09-12 19:30 Andreas Rheinhardt
  2023-09-12 19:33 ` [FFmpeg-devel] [PATCH 2/2] avcodec/h264dec: Fix data race when updating decode_error_flags Andreas Rheinhardt
  2023-09-14 10:35 ` [FFmpeg-devel] [PATCH 1/2] avcodec/error_resilience: Make applying decode_error_flags optional Andreas Rheinhardt
  0 siblings, 2 replies; 3+ messages in thread
From: Andreas Rheinhardt @ 2023-09-12 19:30 UTC (permalink / raw)
  To: ffmpeg-devel; +Cc: Andreas Rheinhardt

Add a pointer parameter that if supplied will be used to return
the updated decode_error_flags. This will allow to fix several
races when using frame-threading; these resulted from AVFrame
that the earlier code updated concurrently being used as source
in an av_frame_ref() call in the decoder's update_thread_context.

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
---
 libavcodec/error_resilience.c |  7 +++++--
 libavcodec/error_resilience.h | 12 +++++++++++-
 libavcodec/h263dec.c          |  2 +-
 libavcodec/h264dec.c          |  2 +-
 libavcodec/mpeg12dec.c        |  2 +-
 libavcodec/mss2.c             |  2 +-
 libavcodec/rv10.c             |  4 ++--
 libavcodec/rv34.c             |  6 +++---
 libavcodec/vc1dec.c           |  2 +-
 9 files changed, 26 insertions(+), 13 deletions(-)

diff --git a/libavcodec/error_resilience.c b/libavcodec/error_resilience.c
index 68e20925e0..880aea6f30 100644
--- a/libavcodec/error_resilience.c
+++ b/libavcodec/error_resilience.c
@@ -889,7 +889,7 @@ void ff_er_add_slice(ERContext *s, int startx, int starty,
     }
 }
 
-void ff_er_frame_end(ERContext *s)
+void ff_er_frame_end(ERContext *s, int *decode_error_flags)
 {
     int *linesize = NULL;
     int i, mb_x, mb_y, error, error_type, dc_error, mv_error, ac_error;
@@ -1114,7 +1114,10 @@ void ff_er_frame_end(ERContext *s)
     av_log(s->avctx, AV_LOG_INFO, "concealing %d DC, %d AC, %d MV errors in %c frame\n",
            dc_error, ac_error, mv_error, av_get_picture_type_char(s->cur_pic.f->pict_type));
 
-    s->cur_pic.f->decode_error_flags |= FF_DECODE_ERROR_CONCEALMENT_ACTIVE;
+    if (decode_error_flags)
+        *decode_error_flags |= FF_DECODE_ERROR_CONCEALMENT_ACTIVE;
+    else
+        s->cur_pic.f->decode_error_flags |= FF_DECODE_ERROR_CONCEALMENT_ACTIVE;
 
     is_intra_likely = is_intra_more_likely(s);
 
diff --git a/libavcodec/error_resilience.h b/libavcodec/error_resilience.h
index 47cc8a4fc6..b03f8ec896 100644
--- a/libavcodec/error_resilience.h
+++ b/libavcodec/error_resilience.h
@@ -90,7 +90,17 @@ typedef struct ERContext {
 } ERContext;
 
 void ff_er_frame_start(ERContext *s);
-void ff_er_frame_end(ERContext *s);
+
+/**
+ * Indicate that a frame has finished decoding and perform error concealment
+ * in case it has been enabled and is necessary and supported.
+ *
+ * @param s                  ERContext in use
+ * @param decode_error_flags pointer where updated decode_error_flags are written
+ *                           if supplied; if not, the new flags are directly
+ *                           applied to the AVFrame whose errors are concealed
+ */
+void ff_er_frame_end(ERContext *s, int *decode_error_flags);
 void ff_er_add_slice(ERContext *s, int startx, int starty, int endx, int endy,
                      int status);
 
diff --git a/libavcodec/h263dec.c b/libavcodec/h263dec.c
index 52e51dd489..9f63f1a7cb 100644
--- a/libavcodec/h263dec.c
+++ b/libavcodec/h263dec.c
@@ -622,7 +622,7 @@ retry:
     av_assert1(s->bitstream_buffer_size == 0);
 frame_end:
     if (!s->studio_profile)
-        ff_er_frame_end(&s->er);
+        ff_er_frame_end(&s->er, NULL);
 
     if (avctx->hwaccel) {
         ret = FF_HW_SIMPLE_CALL(avctx, end_frame);
diff --git a/libavcodec/h264dec.c b/libavcodec/h264dec.c
index f13b1081fc..8e90678125 100644
--- a/libavcodec/h264dec.c
+++ b/libavcodec/h264dec.c
@@ -779,7 +779,7 @@ end:
         if (sl->ref_count[1])
             ff_h264_set_erpic(&h->er.next_pic, sl->ref_list[1][0].parent);
 
-        ff_er_frame_end(&h->er);
+        ff_er_frame_end(&h->er, NULL);
         if (use_last_pic)
             memset(&sl->ref_list[0][0], 0, sizeof(sl->ref_list[0][0]));
     }
diff --git a/libavcodec/mpeg12dec.c b/libavcodec/mpeg12dec.c
index 1accd07e9e..4b5341b914 100644
--- a/libavcodec/mpeg12dec.c
+++ b/libavcodec/mpeg12dec.c
@@ -2033,7 +2033,7 @@ static int slice_end(AVCodecContext *avctx, AVFrame *pict)
     if (/* s->mb_y << field_pic == s->mb_height && */ !s->first_field && !s1->first_slice) {
         /* end of image */
 
-        ff_er_frame_end(&s->er);
+        ff_er_frame_end(&s->er, NULL);
 
         ff_mpv_frame_end(s);
 
diff --git a/libavcodec/mss2.c b/libavcodec/mss2.c
index 70aa56cb84..2237cc8bb1 100644
--- a/libavcodec/mss2.c
+++ b/libavcodec/mss2.c
@@ -422,7 +422,7 @@ static int decode_wmv9(AVCodecContext *avctx, const uint8_t *buf, int buf_size,
     ff_vc1_decode_blocks(v);
 
     if (v->end_mb_x == s->mb_width && s->end_mb_y == s->mb_height) {
-        ff_er_frame_end(&s->er);
+        ff_er_frame_end(&s->er, NULL);
     } else {
         av_log(v->s.avctx, AV_LOG_WARNING,
                "disabling error correction due to block count mismatch %dx%d != %dx%d\n",
diff --git a/libavcodec/rv10.c b/libavcodec/rv10.c
index 5edd934f82..6abceade4e 100644
--- a/libavcodec/rv10.c
+++ b/libavcodec/rv10.c
@@ -477,7 +477,7 @@ static int rv10_decode_packet(AVCodecContext *avctx, const uint8_t *buf,
     if ((s->mb_x == 0 && s->mb_y == 0) || !s->current_picture_ptr) {
         // FIXME write parser so we always have complete frames?
         if (s->current_picture_ptr) {
-            ff_er_frame_end(&s->er);
+            ff_er_frame_end(&s->er, NULL);
             ff_mpv_frame_end(s);
             s->mb_x = s->mb_y = s->resync_mb_x = s->resync_mb_y = 0;
         }
@@ -649,7 +649,7 @@ static int rv10_decode_frame(AVCodecContext *avctx, AVFrame *pict,
     }
 
     if (s->current_picture_ptr && s->mb_y >= s->mb_height) {
-        ff_er_frame_end(&s->er);
+        ff_er_frame_end(&s->er, NULL);
         ff_mpv_frame_end(s);
 
         if (s->pict_type == AV_PICTURE_TYPE_B || s->low_delay) {
diff --git a/libavcodec/rv34.c b/libavcodec/rv34.c
index af4d6a3400..e9660bb457 100644
--- a/libavcodec/rv34.c
+++ b/libavcodec/rv34.c
@@ -1560,7 +1560,7 @@ static int finish_frame(AVCodecContext *avctx, AVFrame *pict)
     MpegEncContext *s = &r->s;
     int got_picture = 0, ret;
 
-    ff_er_frame_end(&s->er);
+    ff_er_frame_end(&s->er, NULL);
     ff_mpv_frame_end(s);
     s->mb_num_left = 0;
 
@@ -1655,7 +1655,7 @@ int ff_rv34_decode_frame(AVCodecContext *avctx, AVFrame *pict,
             av_log(avctx, AV_LOG_ERROR, "New frame but still %d MB left.\n",
                    s->mb_num_left);
             if (!s->context_reinit)
-                ff_er_frame_end(&s->er);
+                ff_er_frame_end(&s->er, NULL);
             ff_mpv_frame_end(s);
         }
 
@@ -1790,7 +1790,7 @@ int ff_rv34_decode_frame(AVCodecContext *avctx, AVFrame *pict,
             av_log(avctx, AV_LOG_INFO, "marking unfished frame as finished\n");
             /* always mark the current frame as finished, frame-mt supports
              * only complete frames */
-            ff_er_frame_end(&s->er);
+            ff_er_frame_end(&s->er, NULL);
             ff_mpv_frame_end(s);
             s->mb_num_left = 0;
             ff_thread_report_progress(&s->current_picture_ptr->tf, INT_MAX, 0);
diff --git a/libavcodec/vc1dec.c b/libavcodec/vc1dec.c
index b8663aaf98..449d2fea5e 100644
--- a/libavcodec/vc1dec.c
+++ b/libavcodec/vc1dec.c
@@ -1348,7 +1348,7 @@ static int vc1_decode_frame(AVCodecContext *avctx, AVFrame *pict,
         if (   !v->field_mode
             && avctx->codec_id != AV_CODEC_ID_WMV3IMAGE
             && avctx->codec_id != AV_CODEC_ID_VC1IMAGE)
-            ff_er_frame_end(&s->er);
+            ff_er_frame_end(&s->er, NULL);
     }
 
     ff_mpv_frame_end(s);
-- 
2.34.1

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

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

^ permalink raw reply	[flat|nested] 3+ messages in thread

* [FFmpeg-devel] [PATCH 2/2] avcodec/h264dec: Fix data race when updating decode_error_flags
  2023-09-12 19:30 [FFmpeg-devel] [PATCH 1/2] avcodec/error_resilience: Make applying decode_error_flags optional Andreas Rheinhardt
@ 2023-09-12 19:33 ` Andreas Rheinhardt
  2023-09-14 10:35 ` [FFmpeg-devel] [PATCH 1/2] avcodec/error_resilience: Make applying decode_error_flags optional Andreas Rheinhardt
  1 sibling, 0 replies; 3+ messages in thread
From: Andreas Rheinhardt @ 2023-09-12 19:33 UTC (permalink / raw)
  To: ffmpeg-devel; +Cc: Andreas Rheinhardt

When using multi-threaded decoding, every decoding thread
has its own DBP consisting of H264Pictures and each of these
points to its own AVFrames. They are synced during
update_thread_context via av_frame_ref() and therefore
the threads actually decoding (as well as all the others)
must not modify any field that is copied by av_frame_ref()
after ff_thread_finish_setup().

Yet this is exactly what happens when an error occurs
during decoding and the AVFrame's decode_error_flags are updated.
Given that these errors only become apparent during decoding,
this can't be set before ff_thread_finish_setup() without
defeating the point of frame-threading; in practice,
this meant that the decoder did not set these flags correctly
in case frame-threading was in use. (This means that e.g.
the ffmpeg cli tool fails to output its "corrupt decoded frame"
message in a nondeterministic fashion.)

This commit fixes this by adding a new H264Picture field
that is actually propagated across threads; the field
is an AVBufferRef* whose data is an atomic_int; it is
atomic in order to allow multiple threads to update it
concurrently and not to provide synchronization
between the threads setting the field and the thread
ultimately returning the AVFrame.

This unfortunately has the overhead of one allocation
per H264Picture (both the original one as well as
creating a reference to an existing one), even in case
of no errors. In order to mitigate this, an AVBufferPool
has been used and only if frame-threading is actually
in use. This expense will be removed as soon as
a proper API for refcounted objects (not based upon
AVBuffer) is in place.

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
---
 libavcodec/h264_picture.c |  9 +++++++++
 libavcodec/h264_slice.c   |  7 +++++++
 libavcodec/h264dec.c      | 38 ++++++++++++++++++++++++++++++++++++--
 libavcodec/h264dec.h      |  4 ++++
 4 files changed, 56 insertions(+), 2 deletions(-)

diff --git a/libavcodec/h264_picture.c b/libavcodec/h264_picture.c
index bd31f700cb..31b5e231c2 100644
--- a/libavcodec/h264_picture.c
+++ b/libavcodec/h264_picture.c
@@ -54,6 +54,7 @@ void ff_h264_unref_picture(H264Context *h, H264Picture *pic)
         av_buffer_unref(&pic->motion_val_buf[i]);
         av_buffer_unref(&pic->ref_index_buf[i]);
     }
+    av_buffer_unref(&pic->decode_error_flags);
 
     memset((uint8_t*)pic + off, 0, sizeof(*pic) - off);
 }
@@ -136,6 +137,10 @@ int ff_h264_ref_picture(H264Context *h, H264Picture *dst, H264Picture *src)
         dst->hwaccel_picture_private = dst->hwaccel_priv_buf->data;
     }
 
+    ret = av_buffer_replace(&dst->decode_error_flags, src->decode_error_flags);
+    if (ret < 0)
+        goto fail;
+
     h264_copy_picture_params(dst, src);
 
     return 0;
@@ -186,6 +191,10 @@ int ff_h264_replace_picture(H264Context *h, H264Picture *dst, const H264Picture
 
     dst->hwaccel_picture_private = src->hwaccel_picture_private;
 
+    ret = av_buffer_replace(&dst->decode_error_flags, src->decode_error_flags);
+    if (ret < 0)
+        goto fail;
+
     h264_copy_picture_params(dst, src);
 
     return 0;
diff --git a/libavcodec/h264_slice.c b/libavcodec/h264_slice.c
index 6cd7bb8fe7..71a878b80b 100644
--- a/libavcodec/h264_slice.c
+++ b/libavcodec/h264_slice.c
@@ -210,6 +210,13 @@ static int alloc_picture(H264Context *h, H264Picture *pic)
     if (ret < 0)
         goto fail;
 
+    if (h->decode_error_flags_pool) {
+        pic->decode_error_flags = av_buffer_pool_get(h->decode_error_flags_pool);
+        if (!pic->decode_error_flags)
+            goto fail;
+        atomic_init((atomic_int*)pic->decode_error_flags->data, 0);
+    }
+
     if (CONFIG_GRAY && !h->avctx->hwaccel && h->flags & AV_CODEC_FLAG_GRAY && pic->f->data[2]) {
         int h_chroma_shift, v_chroma_shift;
         av_pix_fmt_get_chroma_sub_sample(pic->f->format,
diff --git a/libavcodec/h264dec.c b/libavcodec/h264dec.c
index 8e90678125..796f80be8d 100644
--- a/libavcodec/h264dec.c
+++ b/libavcodec/h264dec.c
@@ -307,6 +307,12 @@ static int h264_init_context(AVCodecContext *avctx, H264Context *h)
 
     ff_h264_sei_uninit(&h->sei);
 
+    if (avctx->active_thread_type & FF_THREAD_FRAME) {
+        h->decode_error_flags_pool = av_buffer_pool_init(sizeof(atomic_int), NULL);
+        if (!h->decode_error_flags_pool)
+            return AVERROR(ENOMEM);
+    }
+
     h->nb_slice_ctx = (avctx->active_thread_type & FF_THREAD_SLICE) ? avctx->thread_count : 1;
     h->slice_ctx = av_calloc(h->nb_slice_ctx, sizeof(*h->slice_ctx));
     if (!h->slice_ctx) {
@@ -353,6 +359,8 @@ static av_cold int h264_decode_end(AVCodecContext *avctx)
 
     h->cur_pic_ptr = NULL;
 
+    av_buffer_pool_uninit(&h->decode_error_flags_pool);
+
     av_freep(&h->slice_ctx);
     h->nb_slice_ctx = 0;
 
@@ -739,7 +747,16 @@ static int decode_nal_units(H264Context *h, const uint8_t *buf, int buf_size)
 
     // set decode_error_flags to allow users to detect concealed decoding errors
     if ((ret < 0 || h->er.error_occurred) && h->cur_pic_ptr) {
-        h->cur_pic_ptr->f->decode_error_flags |= FF_DECODE_ERROR_DECODE_SLICES;
+        if (h->cur_pic_ptr->decode_error_flags) {
+            /* Frame-threading in use */
+            atomic_int *decode_error = (atomic_int*)h->cur_pic_ptr->decode_error_flags->data;
+            /* Using atomics here is not supposed to provide syncronisation;
+             * they are merely used to allow to set decode_error from both
+             * decoding threads in case of coded slices. */
+            atomic_fetch_or_explicit(decode_error, FF_DECODE_ERROR_DECODE_SLICES,
+                                     memory_order_relaxed);
+        } else
+            h->cur_pic_ptr->f->decode_error_flags |= FF_DECODE_ERROR_DECODE_SLICES;
     }
 
     ret = 0;
@@ -762,6 +779,7 @@ end:
 
         H264SliceContext *sl = h->slice_ctx;
         int use_last_pic = h->last_pic_for_ec.f->buf[0] && !sl->ref_count[0];
+        int decode_error_flags = 0;
 
         ff_h264_set_erpic(&h->er.cur_pic, h->cur_pic_ptr);
 
@@ -779,7 +797,15 @@ end:
         if (sl->ref_count[1])
             ff_h264_set_erpic(&h->er.next_pic, sl->ref_list[1][0].parent);
 
-        ff_er_frame_end(&h->er, NULL);
+        ff_er_frame_end(&h->er, &decode_error_flags);
+        if (decode_error_flags) {
+            if (h->cur_pic_ptr->decode_error_flags) {
+                atomic_int *decode_error = (atomic_int*)h->cur_pic_ptr->decode_error_flags->data;
+                atomic_fetch_or_explicit(decode_error, decode_error_flags,
+                                         memory_order_relaxed);
+            } else
+                h->cur_pic_ptr->f->decode_error_flags |= decode_error_flags;
+        }
         if (use_last_pic)
             memset(&sl->ref_list[0][0], 0, sizeof(sl->ref_list[0][0]));
     }
@@ -851,6 +877,14 @@ static int output_frame(H264Context *h, AVFrame *dst, H264Picture *srcp)
     if (srcp->needs_fg && (ret = av_frame_copy_props(dst, srcp->f)) < 0)
         return ret;
 
+    if (srcp->decode_error_flags) {
+        atomic_int *decode_error = (atomic_int*)srcp->decode_error_flags->data;
+        /* The following is not supposed to provide synchronisation at all:
+         * given that srcp has already finished decoding, decode_error
+         * has already been set to its final value. */
+        dst->decode_error_flags |= atomic_load_explicit(decode_error, memory_order_relaxed);
+    }
+
     av_dict_set(&dst->metadata, "stereo_mode", ff_h264_sei_stereo_mode(&h->sei.common.frame_packing), 0);
 
     if (srcp->sei_recovery_frame_cnt == 0)
diff --git a/libavcodec/h264dec.h b/libavcodec/h264dec.h
index beaab3902c..322c06a19c 100644
--- a/libavcodec/h264dec.h
+++ b/libavcodec/h264dec.h
@@ -152,6 +152,9 @@ typedef struct H264Picture {
 
     int mb_width, mb_height;
     int mb_stride;
+
+    /* data points to an atomic_int */
+    AVBufferRef *decode_error_flags;
 } H264Picture;
 
 typedef struct H264Ref {
@@ -549,6 +552,7 @@ typedef struct H264Context {
     AVBufferPool *mb_type_pool;
     AVBufferPool *motion_val_pool;
     AVBufferPool *ref_index_pool;
+    AVBufferPool *decode_error_flags_pool;
     int ref2frm[MAX_SLICES][2][64];     ///< reference to frame number lists, used in the loop filter, the first 2 are for -2,-1
 } H264Context;
 
-- 
2.34.1

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

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

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [FFmpeg-devel] [PATCH 1/2] avcodec/error_resilience: Make applying decode_error_flags optional
  2023-09-12 19:30 [FFmpeg-devel] [PATCH 1/2] avcodec/error_resilience: Make applying decode_error_flags optional Andreas Rheinhardt
  2023-09-12 19:33 ` [FFmpeg-devel] [PATCH 2/2] avcodec/h264dec: Fix data race when updating decode_error_flags Andreas Rheinhardt
@ 2023-09-14 10:35 ` Andreas Rheinhardt
  1 sibling, 0 replies; 3+ messages in thread
From: Andreas Rheinhardt @ 2023-09-14 10:35 UTC (permalink / raw)
  To: ffmpeg-devel

Andreas Rheinhardt:
> Add a pointer parameter that if supplied will be used to return
> the updated decode_error_flags. This will allow to fix several
> races when using frame-threading; these resulted from AVFrame
> that the earlier code updated concurrently being used as source
> in an av_frame_ref() call in the decoder's update_thread_context.
> 
> Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
> ---
>  libavcodec/error_resilience.c |  7 +++++--
>  libavcodec/error_resilience.h | 12 +++++++++++-
>  libavcodec/h263dec.c          |  2 +-
>  libavcodec/h264dec.c          |  2 +-
>  libavcodec/mpeg12dec.c        |  2 +-
>  libavcodec/mss2.c             |  2 +-
>  libavcodec/rv10.c             |  4 ++--
>  libavcodec/rv34.c             |  6 +++---
>  libavcodec/vc1dec.c           |  2 +-
>  9 files changed, 26 insertions(+), 13 deletions(-)
> 
> diff --git a/libavcodec/error_resilience.c b/libavcodec/error_resilience.c
> index 68e20925e0..880aea6f30 100644
> --- a/libavcodec/error_resilience.c
> +++ b/libavcodec/error_resilience.c
> @@ -889,7 +889,7 @@ void ff_er_add_slice(ERContext *s, int startx, int starty,
>      }
>  }
>  
> -void ff_er_frame_end(ERContext *s)
> +void ff_er_frame_end(ERContext *s, int *decode_error_flags)
>  {
>      int *linesize = NULL;
>      int i, mb_x, mb_y, error, error_type, dc_error, mv_error, ac_error;
> @@ -1114,7 +1114,10 @@ void ff_er_frame_end(ERContext *s)
>      av_log(s->avctx, AV_LOG_INFO, "concealing %d DC, %d AC, %d MV errors in %c frame\n",
>             dc_error, ac_error, mv_error, av_get_picture_type_char(s->cur_pic.f->pict_type));
>  
> -    s->cur_pic.f->decode_error_flags |= FF_DECODE_ERROR_CONCEALMENT_ACTIVE;
> +    if (decode_error_flags)
> +        *decode_error_flags |= FF_DECODE_ERROR_CONCEALMENT_ACTIVE;
> +    else
> +        s->cur_pic.f->decode_error_flags |= FF_DECODE_ERROR_CONCEALMENT_ACTIVE;
>  
>      is_intra_likely = is_intra_more_likely(s);
>  
> diff --git a/libavcodec/error_resilience.h b/libavcodec/error_resilience.h
> index 47cc8a4fc6..b03f8ec896 100644
> --- a/libavcodec/error_resilience.h
> +++ b/libavcodec/error_resilience.h
> @@ -90,7 +90,17 @@ typedef struct ERContext {
>  } ERContext;
>  
>  void ff_er_frame_start(ERContext *s);
> -void ff_er_frame_end(ERContext *s);
> +
> +/**
> + * Indicate that a frame has finished decoding and perform error concealment
> + * in case it has been enabled and is necessary and supported.
> + *
> + * @param s                  ERContext in use
> + * @param decode_error_flags pointer where updated decode_error_flags are written
> + *                           if supplied; if not, the new flags are directly
> + *                           applied to the AVFrame whose errors are concealed
> + */
> +void ff_er_frame_end(ERContext *s, int *decode_error_flags);
>  void ff_er_add_slice(ERContext *s, int startx, int starty, int endx, int endy,
>                       int status);
>  
> diff --git a/libavcodec/h263dec.c b/libavcodec/h263dec.c
> index 52e51dd489..9f63f1a7cb 100644
> --- a/libavcodec/h263dec.c
> +++ b/libavcodec/h263dec.c
> @@ -622,7 +622,7 @@ retry:
>      av_assert1(s->bitstream_buffer_size == 0);
>  frame_end:
>      if (!s->studio_profile)
> -        ff_er_frame_end(&s->er);
> +        ff_er_frame_end(&s->er, NULL);
>  
>      if (avctx->hwaccel) {
>          ret = FF_HW_SIMPLE_CALL(avctx, end_frame);
> diff --git a/libavcodec/h264dec.c b/libavcodec/h264dec.c
> index f13b1081fc..8e90678125 100644
> --- a/libavcodec/h264dec.c
> +++ b/libavcodec/h264dec.c
> @@ -779,7 +779,7 @@ end:
>          if (sl->ref_count[1])
>              ff_h264_set_erpic(&h->er.next_pic, sl->ref_list[1][0].parent);
>  
> -        ff_er_frame_end(&h->er);
> +        ff_er_frame_end(&h->er, NULL);
>          if (use_last_pic)
>              memset(&sl->ref_list[0][0], 0, sizeof(sl->ref_list[0][0]));
>      }
> diff --git a/libavcodec/mpeg12dec.c b/libavcodec/mpeg12dec.c
> index 1accd07e9e..4b5341b914 100644
> --- a/libavcodec/mpeg12dec.c
> +++ b/libavcodec/mpeg12dec.c
> @@ -2033,7 +2033,7 @@ static int slice_end(AVCodecContext *avctx, AVFrame *pict)
>      if (/* s->mb_y << field_pic == s->mb_height && */ !s->first_field && !s1->first_slice) {
>          /* end of image */
>  
> -        ff_er_frame_end(&s->er);
> +        ff_er_frame_end(&s->er, NULL);
>  
>          ff_mpv_frame_end(s);
>  
> diff --git a/libavcodec/mss2.c b/libavcodec/mss2.c
> index 70aa56cb84..2237cc8bb1 100644
> --- a/libavcodec/mss2.c
> +++ b/libavcodec/mss2.c
> @@ -422,7 +422,7 @@ static int decode_wmv9(AVCodecContext *avctx, const uint8_t *buf, int buf_size,
>      ff_vc1_decode_blocks(v);
>  
>      if (v->end_mb_x == s->mb_width && s->end_mb_y == s->mb_height) {
> -        ff_er_frame_end(&s->er);
> +        ff_er_frame_end(&s->er, NULL);
>      } else {
>          av_log(v->s.avctx, AV_LOG_WARNING,
>                 "disabling error correction due to block count mismatch %dx%d != %dx%d\n",
> diff --git a/libavcodec/rv10.c b/libavcodec/rv10.c
> index 5edd934f82..6abceade4e 100644
> --- a/libavcodec/rv10.c
> +++ b/libavcodec/rv10.c
> @@ -477,7 +477,7 @@ static int rv10_decode_packet(AVCodecContext *avctx, const uint8_t *buf,
>      if ((s->mb_x == 0 && s->mb_y == 0) || !s->current_picture_ptr) {
>          // FIXME write parser so we always have complete frames?
>          if (s->current_picture_ptr) {
> -            ff_er_frame_end(&s->er);
> +            ff_er_frame_end(&s->er, NULL);
>              ff_mpv_frame_end(s);
>              s->mb_x = s->mb_y = s->resync_mb_x = s->resync_mb_y = 0;
>          }
> @@ -649,7 +649,7 @@ static int rv10_decode_frame(AVCodecContext *avctx, AVFrame *pict,
>      }
>  
>      if (s->current_picture_ptr && s->mb_y >= s->mb_height) {
> -        ff_er_frame_end(&s->er);
> +        ff_er_frame_end(&s->er, NULL);
>          ff_mpv_frame_end(s);
>  
>          if (s->pict_type == AV_PICTURE_TYPE_B || s->low_delay) {
> diff --git a/libavcodec/rv34.c b/libavcodec/rv34.c
> index af4d6a3400..e9660bb457 100644
> --- a/libavcodec/rv34.c
> +++ b/libavcodec/rv34.c
> @@ -1560,7 +1560,7 @@ static int finish_frame(AVCodecContext *avctx, AVFrame *pict)
>      MpegEncContext *s = &r->s;
>      int got_picture = 0, ret;
>  
> -    ff_er_frame_end(&s->er);
> +    ff_er_frame_end(&s->er, NULL);
>      ff_mpv_frame_end(s);
>      s->mb_num_left = 0;
>  
> @@ -1655,7 +1655,7 @@ int ff_rv34_decode_frame(AVCodecContext *avctx, AVFrame *pict,
>              av_log(avctx, AV_LOG_ERROR, "New frame but still %d MB left.\n",
>                     s->mb_num_left);
>              if (!s->context_reinit)
> -                ff_er_frame_end(&s->er);
> +                ff_er_frame_end(&s->er, NULL);
>              ff_mpv_frame_end(s);
>          }
>  
> @@ -1790,7 +1790,7 @@ int ff_rv34_decode_frame(AVCodecContext *avctx, AVFrame *pict,
>              av_log(avctx, AV_LOG_INFO, "marking unfished frame as finished\n");
>              /* always mark the current frame as finished, frame-mt supports
>               * only complete frames */
> -            ff_er_frame_end(&s->er);
> +            ff_er_frame_end(&s->er, NULL);
>              ff_mpv_frame_end(s);
>              s->mb_num_left = 0;
>              ff_thread_report_progress(&s->current_picture_ptr->tf, INT_MAX, 0);
> diff --git a/libavcodec/vc1dec.c b/libavcodec/vc1dec.c
> index b8663aaf98..449d2fea5e 100644
> --- a/libavcodec/vc1dec.c
> +++ b/libavcodec/vc1dec.c
> @@ -1348,7 +1348,7 @@ static int vc1_decode_frame(AVCodecContext *avctx, AVFrame *pict,
>          if (   !v->field_mode
>              && avctx->codec_id != AV_CODEC_ID_WMV3IMAGE
>              && avctx->codec_id != AV_CODEC_ID_VC1IMAGE)
> -            ff_er_frame_end(&s->er);
> +            ff_er_frame_end(&s->er, NULL);
>      }
>  
>      ff_mpv_frame_end(s);

Will apply this patchset tomorrow unless there are objections.

- Andreas

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

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

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2023-09-14 10:34 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-09-12 19:30 [FFmpeg-devel] [PATCH 1/2] avcodec/error_resilience: Make applying decode_error_flags optional Andreas Rheinhardt
2023-09-12 19:33 ` [FFmpeg-devel] [PATCH 2/2] avcodec/h264dec: Fix data race when updating decode_error_flags Andreas Rheinhardt
2023-09-14 10:35 ` [FFmpeg-devel] [PATCH 1/2] avcodec/error_resilience: Make applying decode_error_flags optional Andreas Rheinhardt

Git Inbox Mirror of the ffmpeg-devel mailing list - see https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

This inbox may be cloned and mirrored by anyone:

	git clone --mirror https://master.gitmailbox.com/ffmpegdev/0 ffmpegdev/git/0.git

	# If you have public-inbox 1.1+ installed, you may
	# initialize and index your mirror using the following commands:
	public-inbox-init -V2 ffmpegdev ffmpegdev/ https://master.gitmailbox.com/ffmpegdev \
		ffmpegdev@gitmailbox.com
	public-inbox-index ffmpegdev

Example config snippet for mirrors.


AGPL code for this site: git clone https://public-inbox.org/public-inbox.git