[FFmpeg-cvslog] avcodec/decode: split ProgressFrame allocator into two functions

James Almer git at videolan.org
Mon Sep 23 16:21:12 EEST 2024


ffmpeg | branch: master | James Almer <jamrial at gmail.com> | Wed Aug 28 10:46:12 2024 -0300| [dbbf9a5ff771e0b77705ad0f75de353a5e593f9b] | committer: James Almer

avcodec/decode: split ProgressFrame allocator into two functions

Signed-off-by: James Almer <jamrial at gmail.com>

> http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=dbbf9a5ff771e0b77705ad0f75de353a5e593f9b
---

 libavcodec/decode.c        | 11 +++++++----
 libavcodec/progressframe.h | 16 ++++++++++++++--
 2 files changed, 21 insertions(+), 6 deletions(-)

diff --git a/libavcodec/decode.c b/libavcodec/decode.c
index 18ddd28690..e4e92e34e4 100644
--- a/libavcodec/decode.c
+++ b/libavcodec/decode.c
@@ -1725,7 +1725,7 @@ static void check_progress_consistency(const ProgressFrame *f)
     av_assert1(!f->progress || f->progress->f == f->f);
 }
 
-static int progress_frame_get(AVCodecContext *avctx, ProgressFrame *f)
+int ff_progress_frame_alloc(AVCodecContext *avctx, ProgressFrame *f)
 {
     FFRefStructPool *pool = avctx->internal->progress_frame_pool;
 
@@ -1743,9 +1743,12 @@ int ff_progress_frame_get_buffer(AVCodecContext *avctx, ProgressFrame *f, int fl
 {
     int ret;
 
-    ret = progress_frame_get(avctx, f);
-    if (ret < 0)
-        return ret;
+    check_progress_consistency(f);
+    if (!f->f) {
+        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/progressframe.h b/libavcodec/progressframe.h
index 428a461659..32a345beec 100644
--- a/libavcodec/progressframe.h
+++ b/libavcodec/progressframe.h
@@ -102,12 +102,24 @@ void ff_progress_frame_report(ProgressFrame *f, int progress);
 void ff_progress_frame_await(const ProgressFrame *f, int progress);
 
 /**
- * This function sets up the ProgressFrame, i.e. gets ProgressFrame.f
- * and also calls ff_thread_get_buffer() on the frame.
+ * 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().
  *
  * @note: This must only be called by codecs with the
  *        FF_CODEC_CAP_USES_PROGRESSFRAMES internal cap.
  */
+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.
+ *
+ * @note: This must only be called by codecs with the
+ *        FF_CODEC_CAP_USES_PROGRESSFRAMES internal cap.
+ * @see ff_progress_frame_alloc
+ */
 int ff_progress_frame_get_buffer(struct AVCodecContext *avctx,
                                  ProgressFrame *f, int flags);
 



More information about the ffmpeg-cvslog mailing list