diff mbox series

[FFmpeg-devel,1/3] avformat/mux: Store pointer to interleavement func in FFFormatContext

Message ID AM7PR03MB666084D25AF922511B6613BF8FB39@AM7PR03MB6660.eurprd03.prod.outlook.com
State New
Headers show
Series [FFmpeg-devel,1/3] avformat/mux: Store pointer to interleavement func in FFFormatContext
Related show

Checks

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

Commit Message

Andreas Rheinhardt Oct. 9, 2021, 3:13 p.m. UTC
It avoids branches lateron and will allow to easily avoid the overhead
of the linked list currently in use in case there is only one stream.

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
---
 libavformat/internal.h |  6 ++++++
 libavformat/mux.c      | 17 +++--------------
 2 files changed, 9 insertions(+), 14 deletions(-)
diff mbox series

Patch

diff --git a/libavformat/internal.h b/libavformat/internal.h
index f1ae7db365..223befdbc0 100644
--- a/libavformat/internal.h
+++ b/libavformat/internal.h
@@ -81,6 +81,12 @@  typedef struct FFFormatContext {
      */
     int nb_interleaved_streams;
 
+    /**
+     * The interleavement function in use. Always set for muxers.
+     */
+    int (*interleave_packet)(struct AVFormatContext *s, AVPacket *pkt,
+                             int flush, int has_packet);
+
     /**
      * This buffer is only needed when packets were already buffered but
      * not decoded, for example to get the codec parameters in MPEG
diff --git a/libavformat/mux.c b/libavformat/mux.c
index a6e1a08be0..f4f1bc289e 100644
--- a/libavformat/mux.c
+++ b/libavformat/mux.c
@@ -334,6 +334,7 @@  static int init_muxer(AVFormatContext *s, AVDictionary **options)
         if (par->codec_type != AVMEDIA_TYPE_ATTACHMENT)
             si->nb_interleaved_streams++;
     }
+    si->interleave_packet = of->interleave_packet ? of->interleave_packet : ff_interleave_packet_per_dts;
 
     if (!s->priv_data && of->priv_data_size > 0) {
         s->priv_data = av_mallocz(of->priv_data_size);
@@ -1054,19 +1055,6 @@  const AVPacket *ff_interleaved_peek(AVFormatContext *s, int stream)
     return NULL;
 }
 
-/**
- * A wrapper around AVOutputFormat.interleave_packet.
- * See its documentation for details.
- */
-static int interleave_packet(AVFormatContext *s, AVPacket *pkt,
-                             int flush, int has_packet)
-{
-    if (s->oformat->interleave_packet) {
-        return s->oformat->interleave_packet(s, pkt, flush, has_packet);
-    } else
-        return ff_interleave_packet_per_dts(s, pkt, flush, has_packet);
-}
-
 static int check_bitstream(AVFormatContext *s, FFStream *sti, AVPacket *pkt)
 {
     int ret;
@@ -1089,8 +1077,9 @@  static int check_bitstream(AVFormatContext *s, FFStream *sti, AVPacket *pkt)
 static int interleaved_write_packet(AVFormatContext *s, AVPacket *pkt,
                                     int flush, int has_packet)
 {
+    FFFormatContext *const si = ffformatcontext(s);
     for (;; ) {
-        int ret = interleave_packet(s, pkt, flush, has_packet);
+        int ret = si->interleave_packet(s, pkt, flush, has_packet);
         if (ret <= 0)
             return ret;