[FFmpeg-devel] [PATCH v2 11/12] ffv1dec: reference the current packet into the main context

Lynne dev at lynne.ee
Mon Feb 24 10:05:08 EET 2025


---
 libavcodec/ffv1.h    |  3 +++
 libavcodec/ffv1dec.c | 19 +++++++++++++++++--
 2 files changed, 20 insertions(+), 2 deletions(-)

diff --git a/libavcodec/ffv1.h b/libavcodec/ffv1.h
index 22acac35e4..9af17326b3 100644
--- a/libavcodec/ffv1.h
+++ b/libavcodec/ffv1.h
@@ -169,6 +169,9 @@ typedef struct FFV1Context {
      * NOT shared between frame threads.
      */
     uint8_t           frame_damaged;
+
+    /* Reference to the current packet */
+    AVPacket *pkt_ref;
 } FFV1Context;
 
 int ff_ffv1_common_init(AVCodecContext *avctx, FFV1Context *s);
diff --git a/libavcodec/ffv1dec.c b/libavcodec/ffv1dec.c
index 990fdc3711..5ab41da1b7 100644
--- a/libavcodec/ffv1dec.c
+++ b/libavcodec/ffv1dec.c
@@ -455,6 +455,10 @@ static av_cold int decode_init(AVCodecContext *avctx)
     FFV1Context *f = avctx->priv_data;
     int ret;
 
+    f->pkt_ref = av_packet_alloc();
+    if (!f->pkt_ref)
+        return AVERROR(ENOMEM);
+
     if ((ret = ff_ffv1_common_init(avctx, f)) < 0)
         return ret;
 
@@ -686,6 +690,10 @@ static int decode_frame(AVCodecContext *avctx, AVFrame *rframe,
 
     /* Start */
     if (hwaccel) {
+        ret = av_packet_ref(f->pkt_ref, avpkt);
+        if (ret < 0)
+            return ret;
+
         ret = hwaccel->start_frame(avctx, avpkt->data, avpkt->size);
         if (ret < 0)
             return ret;
@@ -705,15 +713,21 @@ static int decode_frame(AVCodecContext *avctx, AVFrame *rframe,
             uint32_t len;
             ret = find_next_slice(avctx, avpkt->data, buf_end, i,
                                   &pos, &len);
-            if (ret < 0)
+            if (ret < 0) {
+                av_packet_unref(f->pkt_ref);
                 return ret;
+            }
 
             buf_end -= len;
 
             ret = hwaccel->decode_slice(avctx, pos, len);
-            if (ret < 0)
+            if (ret < 0) {
+                av_packet_unref(f->pkt_ref);
                 return ret;
+            }
         }
+
+        av_packet_unref(f->pkt_ref);
     } else {
         ret = decode_slices(avctx, c, avpkt);
         if (ret < 0)
@@ -809,6 +823,7 @@ static av_cold int ffv1_decode_close(AVCodecContext *avctx)
     ff_progress_frame_unref(&s->last_picture);
     av_refstruct_unref(&s->hwaccel_last_picture_private);
 
+    av_packet_free(&s->pkt_ref);
     ff_ffv1_close(s);
 
     return 0;
-- 
2.47.2


More information about the ffmpeg-devel mailing list