diff mbox series

[FFmpeg-devel,2/3] avformat/mux: Avoid overhead of packet list in case of single streams

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

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:14 p.m. UTC
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
---
 libavformat/internal.h |  7 +++++++
 libavformat/mux.c      | 11 ++++++++++-
 2 files changed, 17 insertions(+), 1 deletion(-)

Comments

Paul B Mahol Oct. 9, 2021, 3:22 p.m. UTC | #1
lgtm, nice
James Almer Oct. 9, 2021, 3:24 p.m. UTC | #2
On 10/9/2021 12:14 PM, Andreas Rheinhardt wrote:
> Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
> ---
>   libavformat/internal.h |  7 +++++++
>   libavformat/mux.c      | 11 ++++++++++-
>   2 files changed, 17 insertions(+), 1 deletion(-)
> 
> diff --git a/libavformat/internal.h b/libavformat/internal.h
> index 223befdbc0..867b5de514 100644
> --- a/libavformat/internal.h
> +++ b/libavformat/internal.h
> @@ -760,6 +760,13 @@ int ff_add_attached_pic(AVFormatContext *s, AVStream *st, AVIOContext *pb,
>   int ff_interleave_packet_per_dts(AVFormatContext *s, AVPacket *pkt,
>                                    int flush, int has_packet);
>   
> +/**
> + * Interleave packets directly in the order in which they arrive
> + * without any sort of buffering.
> + */
> +int ff_interleave_packet_passthrough(AVFormatContext *s, AVPacket *pkt,
> +                                     int flush, int has_packet);
> +
>   void ff_free_stream(AVFormatContext *s, AVStream *st);
>   
>   unsigned int ff_codec_get_tag(const AVCodecTag *tags, enum AVCodecID id);
> diff --git a/libavformat/mux.c b/libavformat/mux.c
> index f4f1bc289e..a6129720dd 100644
> --- a/libavformat/mux.c
> +++ b/libavformat/mux.c
> @@ -334,7 +334,10 @@ 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;
> +    si->interleave_packet = of->interleave_packet ? of->interleave_packet :
> +                                si->nb_interleaved_streams > 1 ?
> +                                    ff_interleave_packet_per_dts :
> +                                    ff_interleave_packet_passthrough;

This is hard to read. Make it something like

si->interleave_packet = of->interleave_packet;
if (!si->interleave_packet)
     si->interleave_packet = si->nb_interleaved_streams > 1 ?
                                 ff_interleave_packet_per_dts :
                                 ff_interleave_packet_passthrough;

Instead, or at the very least add some brackets.

>   
>       if (!s->priv_data && of->priv_data_size > 0) {
>           s->priv_data = av_mallocz(of->priv_data_size);
> @@ -1026,6 +1029,12 @@ int ff_interleave_packet_per_dts(AVFormatContext *s, AVPacket *pkt,
>       }
>   }
>   
> +int ff_interleave_packet_passthrough(AVFormatContext *s, AVPacket *pkt,
> +                                     int flush, int has_packet)
> +{
> +    return has_packet;
> +}
> +
>   int ff_get_muxer_ts_offset(AVFormatContext *s, int stream_index, int64_t *offset)
>   {
>       AVStream *st;
>
Hendrik Leppkes Oct. 9, 2021, 3:47 p.m. UTC | #3
On Sat, Oct 9, 2021 at 5:14 PM Andreas Rheinhardt
<andreas.rheinhardt@outlook.com> wrote:
>
> Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
> ---
>  libavformat/internal.h |  7 +++++++
>  libavformat/mux.c      | 11 ++++++++++-
>  2 files changed, 17 insertions(+), 1 deletion(-)
>
> diff --git a/libavformat/internal.h b/libavformat/internal.h
> index 223befdbc0..867b5de514 100644
> --- a/libavformat/internal.h
> +++ b/libavformat/internal.h
> @@ -760,6 +760,13 @@ int ff_add_attached_pic(AVFormatContext *s, AVStream *st, AVIOContext *pb,
>  int ff_interleave_packet_per_dts(AVFormatContext *s, AVPacket *pkt,
>                                   int flush, int has_packet);
>
> +/**
> + * Interleave packets directly in the order in which they arrive
> + * without any sort of buffering.
> + */
> +int ff_interleave_packet_passthrough(AVFormatContext *s, AVPacket *pkt,
> +                                     int flush, int has_packet);
> +

The name seems inaccurate if its designed for a single stream and does
not in fact do any actual interleaving.

- Hendrik
Andreas Rheinhardt Oct. 9, 2021, 3:50 p.m. UTC | #4
Hendrik Leppkes:
> On Sat, Oct 9, 2021 at 5:14 PM Andreas Rheinhardt
> <andreas.rheinhardt@outlook.com> wrote:
>>
>> Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
>> ---
>>  libavformat/internal.h |  7 +++++++
>>  libavformat/mux.c      | 11 ++++++++++-
>>  2 files changed, 17 insertions(+), 1 deletion(-)
>>
>> diff --git a/libavformat/internal.h b/libavformat/internal.h
>> index 223befdbc0..867b5de514 100644
>> --- a/libavformat/internal.h
>> +++ b/libavformat/internal.h
>> @@ -760,6 +760,13 @@ int ff_add_attached_pic(AVFormatContext *s, AVStream *st, AVIOContext *pb,
>>  int ff_interleave_packet_per_dts(AVFormatContext *s, AVPacket *pkt,
>>                                   int flush, int has_packet);
>>
>> +/**
>> + * Interleave packets directly in the order in which they arrive
>> + * without any sort of buffering.
>> + */
>> +int ff_interleave_packet_passthrough(AVFormatContext *s, AVPacket *pkt,
>> +                                     int flush, int has_packet);
>> +
> 
> The name seems inaccurate if its designed for a single stream and does
> not in fact do any actual interleaving.
> 

The name stems from the fact that it is used as an interleavement
function. And in 3/3 it is used in a scenario where there might be more
than one stream.

- Andreas
diff mbox series

Patch

diff --git a/libavformat/internal.h b/libavformat/internal.h
index 223befdbc0..867b5de514 100644
--- a/libavformat/internal.h
+++ b/libavformat/internal.h
@@ -760,6 +760,13 @@  int ff_add_attached_pic(AVFormatContext *s, AVStream *st, AVIOContext *pb,
 int ff_interleave_packet_per_dts(AVFormatContext *s, AVPacket *pkt,
                                  int flush, int has_packet);
 
+/**
+ * Interleave packets directly in the order in which they arrive
+ * without any sort of buffering.
+ */
+int ff_interleave_packet_passthrough(AVFormatContext *s, AVPacket *pkt,
+                                     int flush, int has_packet);
+
 void ff_free_stream(AVFormatContext *s, AVStream *st);
 
 unsigned int ff_codec_get_tag(const AVCodecTag *tags, enum AVCodecID id);
diff --git a/libavformat/mux.c b/libavformat/mux.c
index f4f1bc289e..a6129720dd 100644
--- a/libavformat/mux.c
+++ b/libavformat/mux.c
@@ -334,7 +334,10 @@  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;
+    si->interleave_packet = of->interleave_packet ? of->interleave_packet :
+                                si->nb_interleaved_streams > 1 ?
+                                    ff_interleave_packet_per_dts :
+                                    ff_interleave_packet_passthrough;
 
     if (!s->priv_data && of->priv_data_size > 0) {
         s->priv_data = av_mallocz(of->priv_data_size);
@@ -1026,6 +1029,12 @@  int ff_interleave_packet_per_dts(AVFormatContext *s, AVPacket *pkt,
     }
 }
 
+int ff_interleave_packet_passthrough(AVFormatContext *s, AVPacket *pkt,
+                                     int flush, int has_packet)
+{
+    return has_packet;
+}
+
 int ff_get_muxer_ts_offset(AVFormatContext *s, int stream_index, int64_t *offset)
 {
     AVStream *st;