[FFmpeg-devel] [PATCH 09/13] fftools/ffmpeg_mux: allocate sq_pkt in setup_sync_queues()

Anton Khirnov anton at khirnov.net
Thu Oct 13 16:49:00 EEST 2022


This is now possible since setup_sync_queues() can interact with Muxer.
---
 fftools/ffmpeg_mux.c      |  8 --------
 fftools/ffmpeg_mux_init.c | 13 ++++++++++---
 2 files changed, 10 insertions(+), 11 deletions(-)

diff --git a/fftools/ffmpeg_mux.c b/fftools/ffmpeg_mux.c
index 4cb5a71659..4c56f4ba96 100644
--- a/fftools/ffmpeg_mux.c
+++ b/fftools/ffmpeg_mux.c
@@ -671,14 +671,6 @@ int of_muxer_init(OutputFile *of, AVFormatContext *fc,
     if (strcmp(of->format->name, "rtp"))
         want_sdp = 0;
 
-    if (of->sq_mux) {
-        mux->sq_pkt = av_packet_alloc();
-        if (!mux->sq_pkt) {
-            ret = AVERROR(ENOMEM);
-            goto fail;
-        }
-    }
-
     /* write the header for files with no streams */
     if (of->format->flags & AVFMT_NOSTREAMS && fc->nb_streams == 0) {
         ret = mux_check_init(of);
diff --git a/fftools/ffmpeg_mux_init.c b/fftools/ffmpeg_mux_init.c
index 5b515ed034..6c4d9bad1e 100644
--- a/fftools/ffmpeg_mux_init.c
+++ b/fftools/ffmpeg_mux_init.c
@@ -1040,8 +1040,9 @@ loop_end:
     }
 }
 
-static int setup_sync_queues(OutputFile *of, AVFormatContext *oc, int64_t buf_size_us)
+static int setup_sync_queues(Muxer *mux, AVFormatContext *oc, int64_t buf_size_us)
 {
+    OutputFile *of = &mux->of;
     int nb_av_enc = 0, nb_interleaved = 0;
     int limit_frames = 0, limit_frames_av_enc = 0;
 
@@ -1103,6 +1104,10 @@ static int setup_sync_queues(OutputFile *of, AVFormatContext *oc, int64_t buf_si
         if (!of->sq_mux)
             return AVERROR(ENOMEM);
 
+        mux->sq_pkt = av_packet_alloc();
+        if (!mux->sq_pkt)
+            return AVERROR(ENOMEM);
+
         for (int i = 0; i < oc->nb_streams; i++) {
             OutputStream *ost = output_streams[of->ost_index + i];
             enum AVMediaType type = ost->st->codecpar->codec_type;
@@ -1573,6 +1578,7 @@ static int set_dispositions(OutputFile *of, AVFormatContext *ctx)
 
 int of_open(OptionsContext *o, const char *filename)
 {
+    Muxer *mux;
     AVFormatContext *oc;
     int i, j, err;
     OutputFile *of;
@@ -1594,7 +1600,8 @@ int of_open(OptionsContext *o, const char *filename)
         }
     }
 
-    of = allocate_array_elem(&output_files, sizeof(Muxer), &nb_output_files);
+    mux = allocate_array_elem(&output_files, sizeof(Muxer), &nb_output_files);
+    of  = &mux->of;
 
     of->index          = nb_output_files - 1;
     of->ost_index      = nb_output_streams;
@@ -1869,7 +1876,7 @@ int of_open(OptionsContext *o, const char *filename)
         exit_program(1);
     }
 
-    err = setup_sync_queues(of, oc, o->shortest_buf_duration * AV_TIME_BASE);
+    err = setup_sync_queues(mux, oc, o->shortest_buf_duration * AV_TIME_BASE);
     if (err < 0) {
         av_log(NULL, AV_LOG_FATAL, "Error setting up output sync queues\n");
         exit_program(1);
-- 
2.35.1



More information about the ffmpeg-devel mailing list