Patch attached.

- Andreas
From 90d34e5d87a390b6e0058426a1f0b1168eb5ebeb Mon Sep 17 00:00:00 2001
From: Andreas Rheinhardt <andreas.rheinha...@outlook.com>
Date: Fri, 11 Apr 2025 11:01:01 +0200
Subject: [PATCH] avcodec/decode: Only use ff_progress_frame_get_buffer() with
 blank input

All users (namely HEVC) that use ff_progress_frame_alloc()
should just use ff_thread_get_buffer(). Using
ff_progress_frame_get_buffer() is not a must; it is merely
a convenience wrapper.

Signed-off-by: Andreas Rheinhardt <andreas.rheinha...@outlook.com>
---
 libavcodec/decode.c        | 11 +++--------
 libavcodec/hevc/refs.c     |  6 +++---
 libavcodec/progressframe.h | 10 ++++------
 3 files changed, 10 insertions(+), 17 deletions(-)

diff --git a/libavcodec/decode.c b/libavcodec/decode.c
index 14702fb041..c2b2dd6e3b 100644
--- a/libavcodec/decode.c
+++ b/libavcodec/decode.c
@@ -1761,14 +1761,9 @@ int ff_progress_frame_alloc(AVCodecContext *avctx, ProgressFrame *f)
 
 int ff_progress_frame_get_buffer(AVCodecContext *avctx, ProgressFrame *f, int flags)
 {
-    int ret;
-
-    check_progress_consistency(f);
-    if (!f->f) {
-        ret = ff_progress_frame_alloc(avctx, f);
-        if (ret < 0)
-            return ret;
-    }
+    int ret = ff_progress_frame_alloc(avctx, f);
+    if (ret < 0)
+        return ret;
 
     ret = ff_thread_get_buffer(avctx, f->progress->f, flags);
     if (ret < 0) {
diff --git a/libavcodec/hevc/refs.c b/libavcodec/hevc/refs.c
index 6f291bbf79..ab2e075af0 100644
--- a/libavcodec/hevc/refs.c
+++ b/libavcodec/hevc/refs.c
@@ -29,6 +29,7 @@
 #include "hevc.h"
 #include "hevcdec.h"
 #include "progressframe.h"
+#include "thread.h"
 #include "libavutil/refstruct.h"
 
 void ff_hevc_unref_frame(HEVCFrame *frame, int flags)
@@ -157,10 +158,9 @@ static HEVCFrame *alloc_frame(HEVCContext *s, HEVCLayerContext *l)
             }
         }
 
-        ret = ff_progress_frame_get_buffer(s->avctx, &frame->tf,
-                                           AV_GET_BUFFER_FLAG_REF);
+        ret = ff_thread_get_buffer(s->avctx, frame->f, AV_GET_BUFFER_FLAG_REF);
         if (ret < 0)
-            return NULL;
+            goto fail;
 
         frame->rpl = av_refstruct_allocz(s->pkt.nb_nals * sizeof(*frame->rpl));
         if (!frame->rpl)
diff --git a/libavcodec/progressframe.h b/libavcodec/progressframe.h
index 32a345beec..e3cb83c5b4 100644
--- a/libavcodec/progressframe.h
+++ b/libavcodec/progressframe.h
@@ -102,10 +102,9 @@ void ff_progress_frame_report(ProgressFrame *f, int progress);
 void ff_progress_frame_await(const ProgressFrame *f, int progress);
 
 /**
- * This function allocates ProgressFrame.f
- * May be called before ff_progress_frame_get_buffer() in the cases where the
- * AVFrame needs to be accessed before the ff_thread_get_buffer() call in
- * ff_progress_frame_alloc().
+ * This function sets up the ProgressFrame, i.e. ProgressFrame.f
+ * and ProgressFrame.progress. ProgressFrame.f will be blank
+ * (as if from av_frame_alloc() or av_frame_unref()) on success.
  *
  * @note: This must only be called by codecs with the
  *        FF_CODEC_CAP_USES_PROGRESSFRAMES internal cap.
@@ -113,8 +112,7 @@ void ff_progress_frame_await(const ProgressFrame *f, int progress);
 int ff_progress_frame_alloc(struct AVCodecContext *avctx, ProgressFrame *f);
 
 /**
- * This function sets up the ProgressFrame, i.e. allocates ProgressFrame.f
- * if needed, and also calls ff_thread_get_buffer() on the frame.
+ * Wrapper around ff_progress_frame_alloc() and ff_thread_get_buffer().
  *
  * @note: This must only be called by codecs with the
  *        FF_CODEC_CAP_USES_PROGRESSFRAMES internal cap.
-- 
2.45.2

_______________________________________________
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