diff mbox series

[FFmpeg-devel] lavfi/src_movie: stop using AV_CODEC_FLAG_COPY_OPAQUE

Message ID 20230709093430.31673-1-anton@khirnov.net
State Accepted
Commit bbff143b07613c3055eaa606b011168e94a3a024
Headers show
Series [FFmpeg-devel] lavfi/src_movie: stop using AV_CODEC_FLAG_COPY_OPAQUE | expand

Checks

Context Check Description
yinshiyou/make_loongarch64 success Make finished
yinshiyou/make_fate_loongarch64 success Make fate finished
andriy/make_x86 success Make finished
andriy/make_fate_x86 success Make fate finished

Commit Message

Anton Khirnov July 9, 2023, 9:34 a.m. UTC
That feature is overkill for a constant pointer to AVFilterLink which
can be stored in AVCodecContext.opaque (indirectly, because the link is
not allocated yet at the time the codec is opened).

This also avoid leaking non-NULL AVFrame.opaque to callers.
---
 libavfilter/src_movie.c | 10 ++++++----
 1 file changed, 6 insertions(+), 4 deletions(-)
diff mbox series

Patch

diff --git a/libavfilter/src_movie.c b/libavfilter/src_movie.c
index f0d295d4bb..e50ebc99dc 100644
--- a/libavfilter/src_movie.c
+++ b/libavfilter/src_movie.c
@@ -51,6 +51,7 @@ 
 #include "video.h"
 
 typedef struct MovieStream {
+    AVFilterLink *link;
     AVStream *st;
     AVCodecContext *codec_ctx;
     int64_t discontinuity_threshold;
@@ -162,7 +163,8 @@  static AVStream *find_stream(void *log, AVFormatContext *avf, const char *spec)
 static int get_buffer(AVCodecContext *avctx, AVFrame *frame, int flags)
 {
     int linesize_align[AV_NUM_DATA_POINTERS];
-    AVFilterLink *outlink = frame->opaque;
+    MovieStream *st = avctx->opaque;
+    AVFilterLink *outlink = st->link;
     int w, h, ow, oh, copy = 0;
     AVFrame *new;
 
@@ -202,7 +204,6 @@  static int get_buffer(AVCodecContext *avctx, AVFrame *frame, int flags)
     av_frame_move_ref(frame, new);
     av_frame_free(&new);
 
-    frame->opaque = outlink;
     frame->width  = ow;
     frame->height = oh;
 
@@ -224,7 +225,7 @@  static int open_stream(AVFilterContext *ctx, MovieStream *st, int dec_threads)
     if (!st->codec_ctx)
         return AVERROR(ENOMEM);
 
-    st->codec_ctx->flags |= AV_CODEC_FLAG_COPY_OPAQUE;
+    st->codec_ctx->opaque = st;
     st->codec_ctx->get_buffer2 = get_buffer;
     ret = avcodec_parameters_to_context(st->codec_ctx, st->st->codecpar);
     if (ret < 0)
@@ -469,6 +470,8 @@  static int movie_config_output_props(AVFilterLink *outlink)
         break;
     }
 
+    st->link = outlink;
+
     return 0;
 }
 
@@ -581,7 +584,6 @@  static int activate(AVFilterContext *ctx)
                              movie->out_index[movie->pkt->stream_index];
 
             if (pkt_out_id >= 0) {
-                movie->pkt->opaque = ctx->outputs[pkt_out_id];
                 ret = decode_packet(ctx, pkt_out_id);
             }
             av_packet_unref(movie->pkt);