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

Git pushed a commit to branch master
in repository ffmpeg.

commit 823c6fc0b8f16d4583a394e3327afca445b2e4b1
Author:     James Almer <[email protected]>
AuthorDate: Fri Mar 27 14:30:53 2026 -0300
Commit:     James Almer <[email protected]>
CommitDate: Sat Mar 28 22:07:54 2026 -0300

    avcodec/decode: make LCEVC injection available to decoders that don't call 
ff_get_buffer()
    
    Signed-off-by: James Almer <[email protected]>
---
 libavcodec/amfdec.c       |  2 +-
 libavcodec/decode.c       | 82 ++++++++++++++++++++++++-----------------------
 libavcodec/decode.h       |  2 +-
 libavcodec/qsvdec.c       |  2 +-
 libavcodec/videotoolbox.c |  2 +-
 5 files changed, 46 insertions(+), 44 deletions(-)

diff --git a/libavcodec/amfdec.c b/libavcodec/amfdec.c
index 7c58a96bb0..76b22ad750 100644
--- a/libavcodec/amfdec.c
+++ b/libavcodec/amfdec.c
@@ -349,7 +349,7 @@ static int amf_amfsurface_to_avframe(AVCodecContext *avctx, 
AMFSurface* surface,
 
         avctx->sw_pix_fmt = avctx->pix_fmt;
 
-        ret = ff_attach_decode_data(frame);
+        ret = ff_attach_decode_data(avctx, frame);
         if (ret < 0)
             return ret;
         frame->width  = avctx->width;
diff --git a/libavcodec/decode.c b/libavcodec/decode.c
index c1db89d450..6ddf469663 100644
--- a/libavcodec/decode.c
+++ b/libavcodec/decode.c
@@ -1620,6 +1620,33 @@ int ff_decode_frame_props(AVCodecContext *avctx, AVFrame 
*frame)
         }
         break;
     }
+
+#if CONFIG_LIBLCEVC_DEC
+    AVCodecInternal    *avci = avctx->internal;
+    DecodeContext        *dc = decode_ctx(avci);
+
+    dc->lcevc.frame = dc->lcevc.ctx && avctx->codec_type == AVMEDIA_TYPE_VIDEO 
&&
+                      av_frame_get_side_data(frame, AV_FRAME_DATA_LCEVC);
+
+    if (dc->lcevc.frame) {
+        int ret = ff_lcevc_parse_frame(dc->lcevc.ctx, frame,
+                                       &dc->lcevc.width, &dc->lcevc.height, 
avctx);
+        if (ret < 0 && (avctx->err_recognition & AV_EF_EXPLODE))
+            return ret;
+
+        // force get_buffer2() to allocate the base frame using the same 
dimensions
+        // as the final enhanced frame, in order to prevent reinitializing the 
buffer
+        // pools unnecessarely
+        if (!ret && dc->lcevc.width && dc->lcevc.height) {
+            dc->lcevc.base_width  = frame->width;
+            dc->lcevc.base_height = frame->height;
+            frame->width  = dc->lcevc.width;
+            frame->height = dc->lcevc.height;
+        } else
+            dc->lcevc.frame = 0;
+    }
+#endif
+
     return 0;
 }
 
@@ -1655,7 +1682,7 @@ static void decode_data_free(AVRefStructOpaque unused, 
void *obj)
         fdd->hwaccel_priv_free(fdd->hwaccel_priv);
 }
 
-int ff_attach_decode_data(AVFrame *frame)
+int ff_attach_decode_data(AVCodecContext *avctx, AVFrame *frame)
 {
     FrameDecodeData *fdd;
 
@@ -1668,46 +1695,28 @@ int ff_attach_decode_data(AVFrame *frame)
 
     frame->private_ref = fdd;
 
-    return 0;
-}
-
-static int update_frame_props(AVCodecContext *avctx, AVFrame *frame)
-{
 #if CONFIG_LIBLCEVC_DEC
     AVCodecInternal    *avci = avctx->internal;
     DecodeContext        *dc = decode_ctx(avci);
 
-    dc->lcevc.frame = dc->lcevc.ctx && avctx->codec_type == AVMEDIA_TYPE_VIDEO 
&&
-                      av_frame_get_side_data(frame, AV_FRAME_DATA_LCEVC);
+    if (!dc->lcevc.frame) {
+        dc->lcevc.frame = dc->lcevc.ctx && avctx->codec_type == 
AVMEDIA_TYPE_VIDEO &&
+                          av_frame_get_side_data(frame, AV_FRAME_DATA_LCEVC);
 
-    if (dc->lcevc.frame) {
-        int ret = ff_lcevc_parse_frame(dc->lcevc.ctx, frame,
-                                       &dc->lcevc.width, &dc->lcevc.height, 
avctx);
-        if (ret < 0)
-            return ret;
+        if (dc->lcevc.frame) {
+            int ret = ff_lcevc_parse_frame(dc->lcevc.ctx, frame,
+                                           &dc->lcevc.width, 
&dc->lcevc.height, avctx);
+            if (ret < 0 && (avctx->err_recognition & AV_EF_EXPLODE))
+                return ret;
 
-        // force get_buffer2() to allocate the base frame using the same 
dimensions
-        // as the final enhanced frame, in order to prevent reinitializing the 
buffer
-        // pools unnecessarely
-        if (dc->lcevc.width && dc->lcevc.height) {
-            dc->lcevc.base_width  = frame->width;
-            dc->lcevc.base_height = frame->height;
-            frame->width  = dc->lcevc.width;
-            frame->height = dc->lcevc.height;
+            if (!ret && dc->lcevc.width && dc->lcevc.height) {
+                dc->lcevc.base_width  = frame->width;
+                dc->lcevc.base_height = frame->height;
+            } else
+                dc->lcevc.frame = 0;
         }
     }
-#endif
-    return 0;
-}
-
-static int attach_post_process_data(AVCodecContext *avctx, AVFrame *frame)
-{
-#if CONFIG_LIBLCEVC_DEC
-    AVCodecInternal    *avci = avctx->internal;
-    DecodeContext        *dc = decode_ctx(avci);
-
     if (dc->lcevc.frame) {
-        FrameDecodeData *fdd = frame->private_ref;
         FFLCEVCFrame *frame_ctx;
         int ret;
 
@@ -1797,9 +1806,6 @@ int ff_get_buffer(AVCodecContext *avctx, AVFrame *frame, 
int flags)
         }
     } else {
         avctx->sw_pix_fmt = avctx->pix_fmt;
-        ret = update_frame_props(avctx, frame);
-        if (ret < 0)
-            goto fail;
     }
 
     ret = avctx->get_buffer2(avctx, frame, flags);
@@ -1808,11 +1814,7 @@ int ff_get_buffer(AVCodecContext *avctx, AVFrame *frame, 
int flags)
 
     validate_avframe_allocation(avctx, frame);
 
-    ret = ff_attach_decode_data(frame);
-    if (ret < 0)
-        goto fail;
-
-    ret = attach_post_process_data(avctx, frame);
+    ret = ff_attach_decode_data(avctx, frame);
     if (ret < 0)
         goto fail;
 
diff --git a/libavcodec/decode.h b/libavcodec/decode.h
index c74ed5e62c..5a7ab64c29 100644
--- a/libavcodec/decode.h
+++ b/libavcodec/decode.h
@@ -86,7 +86,7 @@ int ff_decode_frame_props(AVCodecContext *avctx, AVFrame 
*frame);
 int ff_decode_get_hw_frames_ctx(AVCodecContext *avctx,
                                 enum AVHWDeviceType dev_type);
 
-int ff_attach_decode_data(AVFrame *frame);
+int ff_attach_decode_data(AVCodecContext *avctx, AVFrame *frame);
 
 /**
  * Check whether the side-data of src contains a palette of
diff --git a/libavcodec/qsvdec.c b/libavcodec/qsvdec.c
index a85c1785cf..5aacde9785 100644
--- a/libavcodec/qsvdec.c
+++ b/libavcodec/qsvdec.c
@@ -176,7 +176,7 @@ static int qsv_get_continuous_buffer(AVCodecContext *avctx, 
AVFrame *frame,
             frame->linesize[0] * FFALIGN(avctx->coded_height, 64);
     }
 
-    ret = ff_attach_decode_data(frame);
+    ret = ff_attach_decode_data(avctx, frame);
     if (ret < 0)
         return ret;
 
diff --git a/libavcodec/videotoolbox.c b/libavcodec/videotoolbox.c
index 7d68a3cd4f..7e05ce999c 100644
--- a/libavcodec/videotoolbox.c
+++ b/libavcodec/videotoolbox.c
@@ -152,7 +152,7 @@ int ff_videotoolbox_alloc_frame(AVCodecContext *avctx, 
AVFrame *frame)
     size_t      size = sizeof(VTHWFrame);
     uint8_t    *data = NULL;
     AVBufferRef *buf = NULL;
-    int ret = ff_attach_decode_data(frame);
+    int ret = ff_attach_decode_data(avctx, frame);
     FrameDecodeData *fdd;
     if (ret < 0)
         return ret;

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

Reply via email to