[FFmpeg-cvslog] all: Use av_frame_replace() where appropriate

Andreas Rheinhardt git at videolan.org
Sun Sep 10 22:35:25 EEST 2023


ffmpeg | branch: master | Andreas Rheinhardt <andreas.rheinhardt at outlook.com> | Thu Sep  7 12:02:26 2023 +0200| [cfa47fd3310aa64d5c48e855bfcaf26d170bcbc1] | committer: Andreas Rheinhardt

all: Use av_frame_replace() where appropriate

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt at outlook.com>

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

 libavcodec/agm.c             | 3 +--
 libavcodec/arbc.c            | 3 +--
 libavcodec/audiotoolboxenc.c | 3 +--
 libavcodec/bink.c            | 3 +--
 libavcodec/cdgraphics.c      | 3 +--
 libavcodec/dxa.c             | 3 +--
 libavcodec/eacmv.c           | 5 ++---
 libavcodec/eamad.c           | 3 +--
 libavcodec/eatgv.c           | 3 +--
 libavcodec/escape124.c       | 3 +--
 libavcodec/gif.c             | 3 +--
 libavcodec/imm4.c            | 3 +--
 libavcodec/interplayvideo.c  | 3 +--
 libavcodec/mss2.c            | 3 +--
 libavcodec/mv30.c            | 3 +--
 libavcodec/mwsc.c            | 3 +--
 libavcodec/pdvdec.c          | 3 +--
 libavcodec/pngenc.c          | 3 +--
 libavcodec/qpeg.c            | 3 +--
 libavcodec/qsvenc.c          | 3 +--
 libavcodec/qtrleenc.c        | 3 +--
 libavcodec/smcenc.c          | 3 +--
 libavcodec/snowenc.c         | 3 +--
 libavcodec/svq1dec.c         | 3 +--
 libavcodec/vmdvideo.c        | 3 +--
 libavcodec/vp56.c            | 6 ++----
 libavcodec/xan.c             | 3 +--
 libavcodec/zerocodec.c       | 3 +--
 libavfilter/vf_paletteuse.c  | 3 +--
 libavfilter/vsrc_ddagrab.c   | 3 +--
 libavutil/hwcontext.c        | 6 ++----
 31 files changed, 34 insertions(+), 67 deletions(-)

diff --git a/libavcodec/agm.c b/libavcodec/agm.c
index 55cf0b47c8..84c96d22b5 100644
--- a/libavcodec/agm.c
+++ b/libavcodec/agm.c
@@ -1203,8 +1203,7 @@ static int decode_frame(AVCodecContext *avctx, AVFrame *frame,
     if (ret < 0)
         return ret;
 
-    av_frame_unref(s->prev_frame);
-    if ((ret = av_frame_ref(s->prev_frame, frame)) < 0)
+    if ((ret = av_frame_replace(s->prev_frame, frame)) < 0)
         return ret;
 
     frame->crop_top  = avctx->coded_height - avctx->height;
diff --git a/libavcodec/arbc.c b/libavcodec/arbc.c
index 1b349f4dd6..46b0275e9a 100644
--- a/libavcodec/arbc.c
+++ b/libavcodec/arbc.c
@@ -166,8 +166,7 @@ static int decode_frame(AVCodecContext *avctx, AVFrame *frame,
             prev_pixels -= fill_tile4(avctx, fill, frame);
     }
 
-    av_frame_unref(s->prev_frame);
-    if ((ret = av_frame_ref(s->prev_frame, frame)) < 0)
+    if ((ret = av_frame_replace(s->prev_frame, frame)) < 0)
         return ret;
 
     frame->pict_type = prev_pixels <= 0 ? AV_PICTURE_TYPE_I : AV_PICTURE_TYPE_P;
diff --git a/libavcodec/audiotoolboxenc.c b/libavcodec/audiotoolboxenc.c
index 1b4e2a6c43..42ab7ae6e4 100644
--- a/libavcodec/audiotoolboxenc.c
+++ b/libavcodec/audiotoolboxenc.c
@@ -483,8 +483,7 @@ static OSStatus ffat_encode_callback(AudioConverterRef converter, UInt32 *nb_pac
     if (*nb_packets > frame->nb_samples)
         *nb_packets = frame->nb_samples;
 
-    av_frame_unref(at->encoding_frame);
-    ret = av_frame_ref(at->encoding_frame, frame);
+    ret = av_frame_replace(at->encoding_frame, frame);
     if (ret < 0) {
         *nb_packets = 0;
         return ret;
diff --git a/libavcodec/bink.c b/libavcodec/bink.c
index 8d96dee705..9024c388f3 100644
--- a/libavcodec/bink.c
+++ b/libavcodec/bink.c
@@ -1300,8 +1300,7 @@ static int decode_frame(AVCodecContext *avctx, AVFrame *frame,
     emms_c();
 
     if (c->version > 'b') {
-        av_frame_unref(c->last);
-        if ((ret = av_frame_ref(c->last, frame)) < 0)
+        if ((ret = av_frame_replace(c->last, frame)) < 0)
             return ret;
     }
 
diff --git a/libavcodec/cdgraphics.c b/libavcodec/cdgraphics.c
index 0c5022a5d6..7b0666a3e2 100644
--- a/libavcodec/cdgraphics.c
+++ b/libavcodec/cdgraphics.c
@@ -344,8 +344,7 @@ static int cdg_decode_frame(AVCodecContext *avctx, AVFrame *frame,
                 return ret;
 
             cdg_scroll(cc, cdg_data, frame, inst == CDG_INST_SCROLL_COPY);
-            av_frame_unref(cc->frame);
-            ret = av_frame_ref(cc->frame, frame);
+            ret = av_frame_replace(cc->frame, frame);
             if (ret < 0)
                 return ret;
             break;
diff --git a/libavcodec/dxa.c b/libavcodec/dxa.c
index d903b7ecd4..650502ad23 100644
--- a/libavcodec/dxa.c
+++ b/libavcodec/dxa.c
@@ -317,8 +317,7 @@ FF_ENABLE_DEPRECATION_WARNINGS
         return AVERROR_INVALIDDATA;
     }
 
-    av_frame_unref(c->prev);
-    if ((ret = av_frame_ref(c->prev, frame)) < 0)
+    if ((ret = av_frame_replace(c->prev, frame)) < 0)
         return ret;
 
     *got_frame = 1;
diff --git a/libavcodec/eacmv.c b/libavcodec/eacmv.c
index e73e310c4a..43dba20fae 100644
--- a/libavcodec/eacmv.c
+++ b/libavcodec/eacmv.c
@@ -210,9 +210,8 @@ static int cmv_decode_frame(AVCodecContext *avctx, AVFrame *frame,
         cmv_decode_intra(s, frame, buf+2, buf_end);
     }
 
-    av_frame_unref(s->last2_frame);
-    av_frame_move_ref(s->last2_frame, s->last_frame);
-    if ((ret = av_frame_ref(s->last_frame, frame)) < 0)
+    FFSWAP(AVFrame*, s->last2_frame, s->last_frame);
+    if ((ret = av_frame_replace(s->last_frame, frame)) < 0)
         return ret;
 
     *got_frame = 1;
diff --git a/libavcodec/eamad.c b/libavcodec/eamad.c
index 45012c62b8..287575e073 100644
--- a/libavcodec/eamad.c
+++ b/libavcodec/eamad.c
@@ -317,8 +317,7 @@ static int decode_frame(AVCodecContext *avctx, AVFrame *frame,
     *got_frame = 1;
 
     if (chunk_type != MADe_TAG) {
-        av_frame_unref(s->last_frame);
-        if ((ret = av_frame_ref(s->last_frame, frame)) < 0)
+        if ((ret = av_frame_replace(s->last_frame, frame)) < 0)
             return ret;
     }
 
diff --git a/libavcodec/eatgv.c b/libavcodec/eatgv.c
index a2aead46eb..35bd88b740 100644
--- a/libavcodec/eatgv.c
+++ b/libavcodec/eatgv.c
@@ -338,8 +338,7 @@ static int tgv_decode_frame(AVCodecContext *avctx, AVFrame *frame,
         }
     }
 
-    av_frame_unref(s->last_frame);
-    if ((ret = av_frame_ref(s->last_frame, frame)) < 0)
+    if ((ret = av_frame_replace(s->last_frame, frame)) < 0)
         return ret;
 
     *got_frame = 1;
diff --git a/libavcodec/escape124.c b/libavcodec/escape124.c
index 592de09a9f..cd62f8d1f0 100644
--- a/libavcodec/escape124.c
+++ b/libavcodec/escape124.c
@@ -362,8 +362,7 @@ static int escape124_decode_frame(AVCodecContext *avctx, AVFrame *frame,
            "Escape sizes: %i, %i, %i\n",
            frame_size, buf_size, get_bits_count(&gb) / 8);
 
-    av_frame_unref(s->frame);
-    if ((ret = av_frame_ref(s->frame, frame)) < 0)
+    if ((ret = av_frame_replace(s->frame, frame)) < 0)
         return ret;
 
     *got_frame = 1;
diff --git a/libavcodec/gif.c b/libavcodec/gif.c
index 131af6198a..11add64468 100644
--- a/libavcodec/gif.c
+++ b/libavcodec/gif.c
@@ -503,8 +503,7 @@ static int gif_encode_frame(AVCodecContext *avctx, AVPacket *pkt,
     }
 
     if (!s->image) {
-        av_frame_unref(s->last_frame);
-        ret = av_frame_ref(s->last_frame, pict);
+        ret = av_frame_replace(s->last_frame, pict);
         if (ret < 0)
             return ret;
     }
diff --git a/libavcodec/imm4.c b/libavcodec/imm4.c
index b95ad86921..25e7570a2c 100644
--- a/libavcodec/imm4.c
+++ b/libavcodec/imm4.c
@@ -453,8 +453,7 @@ static int decode_frame(AVCodecContext *avctx, AVFrame *frame,
         if (ret < 0)
             return ret;
 
-        av_frame_unref(s->prev_frame);
-        if ((ret = av_frame_ref(s->prev_frame, frame)) < 0)
+        if ((ret = av_frame_replace(s->prev_frame, frame)) < 0)
             return ret;
     } else {
         if (!s->prev_frame->data[0]) {
diff --git a/libavcodec/interplayvideo.c b/libavcodec/interplayvideo.c
index 1f0414bbaf..9c13707f87 100644
--- a/libavcodec/interplayvideo.c
+++ b/libavcodec/interplayvideo.c
@@ -1340,9 +1340,8 @@ FF_ENABLE_DEPRECATION_WARNINGS
     *got_frame = send_buffer;
 
     /* shuffle frames */
-    av_frame_unref(s->second_last_frame);
     FFSWAP(AVFrame*, s->second_last_frame, s->last_frame);
-    if ((ret = av_frame_ref(s->last_frame, frame)) < 0)
+    if ((ret = av_frame_replace(s->last_frame, frame)) < 0)
         return ret;
 
     /* report that the buffer was completely consumed */
diff --git a/libavcodec/mss2.c b/libavcodec/mss2.c
index 98103f7fed..94211ffc5e 100644
--- a/libavcodec/mss2.c
+++ b/libavcodec/mss2.c
@@ -797,8 +797,7 @@ static int mss2_decode_frame(AVCodecContext *avctx, AVFrame *frame,
         av_log(avctx, AV_LOG_WARNING, "buffer not fully consumed\n");
 
     if (c->mvX < 0 || c->mvY < 0) {
-        av_frame_unref(ctx->last_pic);
-        ret = av_frame_ref(ctx->last_pic, frame);
+        ret = av_frame_replace(ctx->last_pic, frame);
         if (ret < 0)
             return ret;
     }
diff --git a/libavcodec/mv30.c b/libavcodec/mv30.c
index c2d0547053..92c567c620 100644
--- a/libavcodec/mv30.c
+++ b/libavcodec/mv30.c
@@ -643,8 +643,7 @@ static int decode_frame(AVCodecContext *avctx, AVFrame *frame,
             return ret;
     }
 
-    av_frame_unref(s->prev_frame);
-    if ((ret = av_frame_ref(s->prev_frame, frame)) < 0)
+    if ((ret = av_frame_replace(s->prev_frame, frame)) < 0)
         return ret;
 
     *got_frame = 1;
diff --git a/libavcodec/mwsc.c b/libavcodec/mwsc.c
index c7045ac793..f8c53c33ff 100644
--- a/libavcodec/mwsc.c
+++ b/libavcodec/mwsc.c
@@ -127,8 +127,7 @@ static int decode_frame(AVCodecContext *avctx, AVFrame *frame,
 
     frame->pict_type = (frame->flags & AV_FRAME_FLAG_KEY) ? AV_PICTURE_TYPE_I : AV_PICTURE_TYPE_P;
 
-    av_frame_unref(s->prev_frame);
-    if ((ret = av_frame_ref(s->prev_frame, frame)) < 0)
+    if ((ret = av_frame_replace(s->prev_frame, frame)) < 0)
         return ret;
 
     *got_frame = 1;
diff --git a/libavcodec/pdvdec.c b/libavcodec/pdvdec.c
index d50c4e729c..e2c03e7e0d 100644
--- a/libavcodec/pdvdec.c
+++ b/libavcodec/pdvdec.c
@@ -102,8 +102,7 @@ static int decode_frame(AVCodecContext *avctx, AVFrame *frame,
         dst += frame->linesize[0];
     }
 
-    av_frame_unref(s->previous_frame);
-    if ((ret = av_frame_ref(s->previous_frame, frame)) < 0)
+    if ((ret = av_frame_replace(s->previous_frame, frame)) < 0)
         return ret;
 
     if (avpkt->flags & AV_PKT_FLAG_KEY) {
diff --git a/libavcodec/pngenc.c b/libavcodec/pngenc.c
index 21b033ea16..f0650962d2 100644
--- a/libavcodec/pngenc.c
+++ b/libavcodec/pngenc.c
@@ -1059,8 +1059,7 @@ static int encode_apng(AVCodecContext *avctx, AVPacket *pkt,
             }
         }
 
-        av_frame_unref(s->last_frame);
-        ret = av_frame_ref(s->last_frame, pict);
+        ret = av_frame_replace(s->last_frame, pict);
         if (ret < 0)
             return ret;
 
diff --git a/libavcodec/qpeg.c b/libavcodec/qpeg.c
index 1f76ebc5a1..9b4ad8e25d 100644
--- a/libavcodec/qpeg.c
+++ b/libavcodec/qpeg.c
@@ -307,8 +307,7 @@ FF_ENABLE_DEPRECATION_WARNINGS
 #endif
     memcpy(p->data[1], a->pal, AVPALETTE_SIZE);
 
-    av_frame_unref(ref);
-    if ((ret = av_frame_ref(ref, p)) < 0)
+    if ((ret = av_frame_replace(ref, p)) < 0)
         return ret;
 
     if (intra)
diff --git a/libavcodec/qsvenc.c b/libavcodec/qsvenc.c
index 4efc8d551e..a0144b0760 100644
--- a/libavcodec/qsvenc.c
+++ b/libavcodec/qsvenc.c
@@ -1996,8 +1996,7 @@ static int submit_frame(QSVEncContext *q, const AVFrame *frame,
                 return ret;
             }
         } else {
-            av_frame_unref(qf->frame);
-            ret = av_frame_ref(qf->frame, frame);
+            ret = av_frame_replace(qf->frame, frame);
             if (ret < 0)
                 return ret;
         }
diff --git a/libavcodec/qtrleenc.c b/libavcodec/qtrleenc.c
index 3846762745..92e6e84380 100644
--- a/libavcodec/qtrleenc.c
+++ b/libavcodec/qtrleenc.c
@@ -385,8 +385,7 @@ static int qtrle_encode_frame(AVCodecContext *avctx, AVPacket *pkt,
     pkt->size = encode_frame(s, pict, pkt->data);
 
     /* save the current frame */
-    av_frame_unref(s->previous_frame);
-    ret = av_frame_ref(s->previous_frame, pict);
+    ret = av_frame_replace(s->previous_frame, pict);
     if (ret < 0) {
         av_log(avctx, AV_LOG_ERROR, "cannot add reference\n");
         return ret;
diff --git a/libavcodec/smcenc.c b/libavcodec/smcenc.c
index fb15489ad2..789aef4f77 100644
--- a/libavcodec/smcenc.c
+++ b/libavcodec/smcenc.c
@@ -566,8 +566,7 @@ static int smc_encode_frame(AVCodecContext *avctx, AVPacket *pkt,
     // write chunk length
     AV_WB24(pkt->data + 1, pkt->size);
 
-    av_frame_unref(s->prev_frame);
-    ret = av_frame_ref(s->prev_frame, frame);
+    ret = av_frame_replace(s->prev_frame, frame);
     if (ret < 0) {
         av_log(avctx, AV_LOG_ERROR, "cannot add reference\n");
         return ret;
diff --git a/libavcodec/snowenc.c b/libavcodec/snowenc.c
index c330303317..14a59ca67b 100644
--- a/libavcodec/snowenc.c
+++ b/libavcodec/snowenc.c
@@ -1887,8 +1887,7 @@ redo_frame:
                                    (s->avctx->flags&AV_CODEC_FLAG_PSNR) ? SNOW_MAX_PLANES : 0,
                                    s->current_picture->pict_type);
     if (s->avctx->flags & AV_CODEC_FLAG_RECON_FRAME) {
-        av_frame_unref(avci->recon_frame);
-        av_frame_ref(avci->recon_frame, s->current_picture);
+        av_frame_replace(avci->recon_frame, s->current_picture);
     }
 
     pkt->size = ff_rac_terminate(c, 0);
diff --git a/libavcodec/svq1dec.c b/libavcodec/svq1dec.c
index c7269456e2..e3f22f108c 100644
--- a/libavcodec/svq1dec.c
+++ b/libavcodec/svq1dec.c
@@ -764,8 +764,7 @@ static int svq1_decode_frame(AVCodecContext *avctx, AVFrame *cur,
     }
 
     if (!s->nonref) {
-        av_frame_unref(s->prev);
-        result = av_frame_ref(s->prev, cur);
+        result = av_frame_replace(s->prev, cur);
         if (result < 0)
             return result;
     }
diff --git a/libavcodec/vmdvideo.c b/libavcodec/vmdvideo.c
index 226ae0d316..2da8af31f5 100644
--- a/libavcodec/vmdvideo.c
+++ b/libavcodec/vmdvideo.c
@@ -454,8 +454,7 @@ static int vmdvideo_decode_frame(AVCodecContext *avctx, AVFrame *frame,
     memcpy(frame->data[1], s->palette, PALETTE_COUNT * 4);
 
     /* shuffle frames */
-    av_frame_unref(s->prev_frame);
-    if ((ret = av_frame_ref(s->prev_frame, frame)) < 0)
+    if ((ret = av_frame_replace(s->prev_frame, frame)) < 0)
         return ret;
 
     *got_frame      = 1;
diff --git a/libavcodec/vp56.c b/libavcodec/vp56.c
index a5c5b23622..f2ee3fafd4 100644
--- a/libavcodec/vp56.c
+++ b/libavcodec/vp56.c
@@ -607,8 +607,7 @@ int ff_vp56_decode_frame(AVCodecContext *avctx, AVFrame *rframe,
     }
 
     if (avctx->pix_fmt == AV_PIX_FMT_YUVA420P) {
-        av_frame_unref(s->alpha_context->frames[VP56_FRAME_CURRENT]);
-        if ((ret = av_frame_ref(s->alpha_context->frames[VP56_FRAME_CURRENT], p)) < 0) {
+        if ((ret = av_frame_replace(s->alpha_context->frames[VP56_FRAME_CURRENT], p)) < 0) {
             av_frame_unref(p);
             if (res == VP56_SIZE_CHANGE)
                 ff_set_dimensions(avctx, 0, 0);
@@ -764,8 +763,7 @@ static int ff_vp56_decode_mbs(AVCodecContext *avctx, void *data,
 
 next:
     if ((p->flags & AV_FRAME_FLAG_KEY) || s->golden_frame) {
-        av_frame_unref(s->frames[VP56_FRAME_GOLDEN]);
-        if ((res = av_frame_ref(s->frames[VP56_FRAME_GOLDEN], p)) < 0)
+        if ((res = av_frame_replace(s->frames[VP56_FRAME_GOLDEN], p)) < 0)
             return res;
     }
 
diff --git a/libavcodec/xan.c b/libavcodec/xan.c
index 14fc2443c5..cc0ecea5eb 100644
--- a/libavcodec/xan.c
+++ b/libavcodec/xan.c
@@ -622,8 +622,7 @@ static int xan_decode_frame(AVCodecContext *avctx, AVFrame *frame,
     if (xan_wc3_decode_frame(s, frame) < 0)
         return AVERROR_INVALIDDATA;
 
-    av_frame_unref(s->last_frame);
-    if ((ret = av_frame_ref(s->last_frame, frame)) < 0)
+    if ((ret = av_frame_replace(s->last_frame, frame)) < 0)
         return ret;
 
     *got_frame = 1;
diff --git a/libavcodec/zerocodec.c b/libavcodec/zerocodec.c
index 6c3bcebce0..48f78d1d86 100644
--- a/libavcodec/zerocodec.c
+++ b/libavcodec/zerocodec.c
@@ -93,8 +93,7 @@ static int zerocodec_decode_frame(AVCodecContext *avctx, AVFrame *pic,
         dst  -= pic->linesize[0];
     }
 
-    av_frame_unref(zc->previous_frame);
-    if ((ret = av_frame_ref(zc->previous_frame, pic)) < 0)
+    if ((ret = av_frame_replace(zc->previous_frame, pic)) < 0)
         return ret;
 
     *got_frame = 1;
diff --git a/libavfilter/vf_paletteuse.c b/libavfilter/vf_paletteuse.c
index 79d8fb2e51..bc767c508c 100644
--- a/libavfilter/vf_paletteuse.c
+++ b/libavfilter/vf_paletteuse.c
@@ -781,9 +781,8 @@ static int apply_palette(AVFilterLink *inlink, AVFrame *in, AVFrame **outf)
 
     set_processing_window(s->diff_mode, s->last_in, in,
                           s->last_out, out, &x, &y, &w, &h);
-    av_frame_unref(s->last_in);
     av_frame_unref(s->last_out);
-    if ((ret = av_frame_ref(s->last_in, in))       < 0 ||
+    if ((ret = av_frame_replace(s->last_in, in))   < 0 ||
         (ret = av_frame_ref(s->last_out, out))     < 0 ||
         (ret = ff_inlink_make_frame_writable(inlink, &s->last_in)) < 0) {
         av_frame_free(&out);
diff --git a/libavfilter/vsrc_ddagrab.c b/libavfilter/vsrc_ddagrab.c
index c3107e11b4..2d9d71a7ba 100644
--- a/libavfilter/vsrc_ddagrab.c
+++ b/libavfilter/vsrc_ddagrab.c
@@ -1076,8 +1076,7 @@ static int ddagrab_request_frame(AVFilterLink *outlink)
         goto fail;
     }
 
-    av_frame_unref(dda->last_frame);
-    ret = av_frame_ref(dda->last_frame, frame);
+    ret = av_frame_replace(dda->last_frame, frame);
     if (ret < 0)
         return ret;
 
diff --git a/libavutil/hwcontext.c b/libavutil/hwcontext.c
index 3396598269..3650d4653a 100644
--- a/libavutil/hwcontext.c
+++ b/libavutil/hwcontext.c
@@ -819,8 +819,7 @@ int av_hwframe_map(AVFrame *dst, const AVFrame *src, int flags)
                 return AVERROR(EINVAL);
             }
             hwmap = (HWMapDescriptor*)src->buf[0]->data;
-            av_frame_unref(dst);
-            return av_frame_ref(dst, hwmap->source);
+            return av_frame_replace(dst, hwmap->source);
         }
     }
 
@@ -950,6 +949,5 @@ fail:
 int ff_hwframe_map_replace(AVFrame *dst, const AVFrame *src)
 {
     HWMapDescriptor *hwmap = (HWMapDescriptor*)dst->buf[0]->data;
-    av_frame_unref(hwmap->source);
-    return av_frame_ref(hwmap->source, src);
+    return av_frame_replace(hwmap->source, src);
 }



More information about the ffmpeg-cvslog mailing list