This is an automated email from the git hooks/post-receive script.

Git pushed a commit to branch master
in repository ffmpeg.

commit 0ee1947d9b141480cfdd15a2714f3fd16f675bcc
Author:     Andreas Rheinhardt <[email protected]>
AuthorDate: Wed Apr 15 14:49:56 2026 +0200
Commit:     James Almer <[email protected]>
CommitDate: Thu Apr 16 19:27:03 2026 +0000

    avcodec/lcevcdec: Use pool to avoid allocations of FFLCEVCFrame
    
    Signed-off-by: Andreas Rheinhardt <[email protected]>
---
 libavcodec/decode.c   | 10 ++--------
 libavcodec/lcevcdec.c | 39 ++++++++++++++++++++++++++++++++++++---
 libavcodec/lcevcdec.h |  1 +
 3 files changed, 39 insertions(+), 11 deletions(-)

diff --git a/libavcodec/decode.c b/libavcodec/decode.c
index 206b711390..892f6fce1d 100644
--- a/libavcodec/decode.c
+++ b/libavcodec/decode.c
@@ -1726,16 +1726,10 @@ int ff_attach_decode_data(AVCodecContext *avctx, 
AVFrame *frame)
             return 0;
         }
 
-        frame_ctx = av_mallocz(sizeof(*frame_ctx));
+        frame_ctx = av_refstruct_pool_get(dc->lcevc.ctx->frame_pool);
         if (!frame_ctx)
             return AVERROR(ENOMEM);
 
-        frame_ctx->frame = av_frame_alloc();
-        if (!frame_ctx->frame) {
-            av_free(frame_ctx);
-            return AVERROR(ENOMEM);
-        }
-
         frame_ctx->lcevc = av_refstruct_ref(dc->lcevc.ctx);
         frame_ctx->frame->width  = dc->lcevc.width;
         frame_ctx->frame->height = dc->lcevc.height;
@@ -1747,7 +1741,7 @@ int ff_attach_decode_data(AVCodecContext *avctx, AVFrame 
*frame)
 
         ret = avctx->get_buffer2(avctx, frame_ctx->frame, 0);
         if (ret < 0) {
-            ff_lcevc_unref(frame_ctx);
+            av_refstruct_unref(&frame_ctx);
             return ret;
         }
 
diff --git a/libavcodec/lcevcdec.c b/libavcodec/lcevcdec.c
index d1f1584816..270a7be81b 100644
--- a/libavcodec/lcevcdec.c
+++ b/libavcodec/lcevcdec.c
@@ -300,9 +300,35 @@ static void lcevc_free(AVRefStructOpaque unused, void *obj)
         ff_cbs_fragment_free(lcevc->frag);
     av_freep(&lcevc->frag);
     ff_cbs_close(&lcevc->cbc);
+    av_refstruct_pool_uninit(&lcevc->frame_pool);
     memset(lcevc, 0, sizeof(*lcevc));
 }
 
+static av_cold int lcevc_frame_init_cb(AVRefStructOpaque unused, void *obj)
+{
+    FFLCEVCFrame *frame = obj;
+
+    frame->frame = av_frame_alloc();
+    if (!frame->frame)
+        return AVERROR(ENOMEM);
+    return 0;
+}
+
+static void lcevc_frame_reset_cb(AVRefStructOpaque unused, void *obj)
+{
+    FFLCEVCFrame *frame = obj;
+
+    av_frame_unref(frame->frame);
+    av_refstruct_unref(&frame->lcevc);
+}
+
+static av_cold void lcevc_frame_free_entry_cb(AVRefStructOpaque unused, void 
*obj)
+{
+    FFLCEVCFrame *frame = obj;
+
+    av_frame_free(&frame->frame);
+}
+
 static int lcevc_init(FFLCEVCContext *lcevc, void *logctx)
 {
     LCEVC_AccelContextHandle dummy = { 0 };
@@ -423,6 +449,15 @@ int ff_lcevc_alloc(FFLCEVCContext **plcevc, void *logctx)
     lcevc->cbc->decompose_unit_types    = decompose_unit_types;
     lcevc->cbc->nb_decompose_unit_types = FF_ARRAY_ELEMS(decompose_unit_types);
 
+    lcevc->frame_pool = av_refstruct_pool_alloc_ext(sizeof(FFLCEVCFrame), 0, 
NULL,
+                                                    lcevc_frame_init_cb,
+                                                    lcevc_frame_reset_cb,
+                                                    lcevc_frame_free_entry_cb, 
NULL);
+    if (!lcevc->frame_pool) {
+        ret = AVERROR(ENOMEM);
+        goto fail;
+    }
+
     *plcevc = lcevc;
     return 0;
 fail:
@@ -433,7 +468,5 @@ fail:
 void ff_lcevc_unref(void *opaque)
 {
     FFLCEVCFrame *lcevc = opaque;
-    av_refstruct_unref(&lcevc->lcevc);
-    av_frame_free(&lcevc->frame);
-    av_free(opaque);
+    av_refstruct_unref(&lcevc);
 }
diff --git a/libavcodec/lcevcdec.h b/libavcodec/lcevcdec.h
index 0a255d2951..5aed07f999 100644
--- a/libavcodec/lcevcdec.h
+++ b/libavcodec/lcevcdec.h
@@ -35,6 +35,7 @@ typedef struct FFLCEVCContext {
     LCEVC_DecoderHandle decoder;
     struct CodedBitstreamContext *cbc;
     struct CodedBitstreamFragment *frag;
+    struct AVRefStructPool *frame_pool; ///< pool of FFLCEVCFrame
     int initialized;
 } FFLCEVCContext;
 

_______________________________________________
ffmpeg-cvslog mailing list -- [email protected]
To unsubscribe send an email to [email protected]

Reply via email to