diff mbox series

[FFmpeg-devel,20/23] fftools/ffmpeg_mux: use a dedicated packet for BSF output

Message ID 20230531145453.20994-20-anton@khirnov.net
State Accepted
Commit 96e1325d9152323cb6418df017da7aca99d59f78
Headers show
Series [FFmpeg-devel,01/23] fftools/ffmpeg_enc: move nb_frames{dup, drop} globals into OutputStream | expand

Checks

Context Check Description
andriy/make_x86 success Make finished
andriy/make_fate_x86 success Make fate finished

Commit Message

Anton Khirnov May 31, 2023, 2:54 p.m. UTC
Currently of_output_packet() reuses the input packet, which requires its
callers to submit blank packets even on EOF, which makes the code more
complex.
---
 fftools/ffmpeg_mux.c | 9 +++++++--
 fftools/ffmpeg_mux.h | 1 +
 2 files changed, 8 insertions(+), 2 deletions(-)
diff mbox series

Patch

diff --git a/fftools/ffmpeg_mux.c b/fftools/ffmpeg_mux.c
index dc2d189ff0..485f499971 100644
--- a/fftools/ffmpeg_mux.c
+++ b/fftools/ffmpeg_mux.c
@@ -351,7 +351,7 @@  void of_output_packet(OutputFile *of, AVPacket *pkt, OutputStream *ost, int eof)
         }
 
         while (!bsf_eof) {
-            ret = av_bsf_receive_packet(ms->bsf_ctx, pkt);
+            ret = av_bsf_receive_packet(ms->bsf_ctx, ms->bsf_pkt);
             if (ret == AVERROR(EAGAIN))
                 return;
             else if (ret == AVERROR_EOF)
@@ -361,7 +361,7 @@  void of_output_packet(OutputFile *of, AVPacket *pkt, OutputStream *ost, int eof)
                 goto fail;
             }
 
-            ret = submit_packet(mux, bsf_eof ? NULL : pkt, ost);
+            ret = submit_packet(mux, bsf_eof ? NULL : ms->bsf_pkt, ost);
             if (ret < 0)
                 goto mux_fail;
         }
@@ -656,6 +656,10 @@  static int bsf_init(MuxStream *ms)
         return ret;
     ost->st->time_base = ctx->time_base_out;
 
+    ms->bsf_pkt = av_packet_alloc();
+    if (!ms->bsf_pkt)
+        return AVERROR(ENOMEM);
+
     return 0;
 }
 
@@ -856,6 +860,7 @@  static void ost_free(OutputStream **post)
     avcodec_parameters_free(&ost->par_in);
 
     av_bsf_free(&ms->bsf_ctx);
+    av_packet_free(&ms->bsf_pkt);
 
     av_packet_free(&ost->pkt);
     av_dict_free(&ost->encoder_opts);
diff --git a/fftools/ffmpeg_mux.h b/fftools/ffmpeg_mux.h
index bee7addd6a..ad7b1df8a7 100644
--- a/fftools/ffmpeg_mux.h
+++ b/fftools/ffmpeg_mux.h
@@ -44,6 +44,7 @@  typedef struct MuxStream {
     AVFifo *muxing_queue;
 
     AVBSFContext *bsf_ctx;
+    AVPacket     *bsf_pkt;
 
     EncStats stats;