[FFmpeg-devel] [PATCH] avfilter/src_movie: stop using AVPacket on stack

James Almer jamrial at gmail.com
Sat May 20 05:40:05 EEST 2023


Signed-off-by: James Almer <jamrial at gmail.com>
---
 libavfilter/src_movie.c | 18 ++++++++++++------
 1 file changed, 12 insertions(+), 6 deletions(-)

diff --git a/libavfilter/src_movie.c b/libavfilter/src_movie.c
index 5937613d13..b55c2bcb6e 100644
--- a/libavfilter/src_movie.c
+++ b/libavfilter/src_movie.c
@@ -72,6 +72,7 @@ typedef struct MovieContext {
     int dec_threads;
 
     AVFormatContext *format_ctx;
+    AVPacket *pkt;
 
     int max_stream_index; /**< max stream # actually used for output */
     MovieStream *st; /**< array of all streams, one per output */
@@ -279,6 +280,10 @@ static av_cold int movie_common_init(AVFilterContext *ctx)
     for (i = 0; i < movie->format_ctx->nb_streams; i++)
         movie->format_ctx->streams[i]->discard = AVDISCARD_ALL;
 
+    movie->pkt = av_packet_alloc();
+    if (!movie->pkt)
+        return AVERROR(ENOMEM);
+
     movie->st = av_calloc(nb_streams, sizeof(*movie->st));
     if (!movie->st)
         return AVERROR(ENOMEM);
@@ -348,6 +353,7 @@ static av_cold void movie_uninit(AVFilterContext *ctx)
     av_freep(&movie->out_index);
     if (movie->format_ctx)
         avformat_close_input(&movie->format_ctx);
+    av_packet_free(&movie->pkt);
 }
 
 static int movie_query_formats(AVFilterContext *ctx)
@@ -459,11 +465,11 @@ static int rewind_file(AVFilterContext *ctx)
 static int movie_decode_packet(AVFilterContext *ctx)
 {
     MovieContext *movie = ctx->priv;
-    AVPacket pkt = { 0 };
+    AVPacket *pkt = movie->pkt;
     int pkt_out_id, ret;
 
     /* read a new packet from input stream */
-    ret = av_read_frame(movie->format_ctx, &pkt);
+    ret = av_read_frame(movie->format_ctx, pkt);
     if (ret == AVERROR_EOF) {
         /* EOF -> set all decoders for flushing */
         for (int i = 0; i < ctx->nb_outputs; i++) {
@@ -477,11 +483,11 @@ static int movie_decode_packet(AVFilterContext *ctx)
         return ret;
 
     /* send the packet to its decoder, if any */
-    pkt_out_id = pkt.stream_index > movie->max_stream_index ? -1 :
-                 movie->out_index[pkt.stream_index];
+    pkt_out_id = pkt->stream_index > movie->max_stream_index ? -1 :
+                 movie->out_index[pkt->stream_index];
     if (pkt_out_id >= 0)
-        ret = avcodec_send_packet(movie->st[pkt_out_id].codec_ctx, &pkt);
-    av_packet_unref(&pkt);
+        ret = avcodec_send_packet(movie->st[pkt_out_id].codec_ctx, pkt);
+    av_packet_unref(pkt);
 
     return ret;
 }
-- 
2.40.1



More information about the ffmpeg-devel mailing list