On Sat, 29 Sep 2012 23:07:44 +0200, Luca Barbato <[email protected]> wrote:
> Quite low latency streaming would enjoy sparing the muxer setup time
> when possible.
> The segment muxer would be simplified a lot and the mpegts corner case
> would be solved clearly.
> Any application using more than once a muxer could spare a deinit/init
> cycle.
> ---
>  libavformat/avformat.h | 25 +++++++++++++++++++++++++
>  libavformat/mux.c      | 43 +++++++++++++++++++++++++++++++++++++++++++
>  2 files changed, 68 insertions(+)
> 
> diff --git a/libavformat/avformat.h b/libavformat/avformat.h
> index 134a38b..ad383b3 100644
> --- a/libavformat/avformat.h
> +++ b/libavformat/avformat.h
> @@ -407,7 +407,22 @@ typedef struct AVOutputFormat {
>       */
>      int priv_data_size;
>  
> +    /**
> +     * Initialize the muxer context and write the header.
> +     * @deprecated implement the split functions below.
> +     */
>      int (*write_header)(struct AVFormatContext *);
> +
> +    /**
> +     * Initialize the muxer context.
> +     */
> +    int (*init)(struct AVFormatContext *);
> +
> +    /**
> +     * Write the header, requires an initialized context.
> +     */
> +    int (*write_header2)(struct AVFormatContext *);
> +
>      /**
>       * Write a packet. If AVFMT_ALLOW_FLUSH is set in flags,
>       * pkt can be NULL in order to flush data buffered in the muxer.
> @@ -416,7 +431,13 @@ typedef struct AVOutputFormat {
>       * data.
>       */
>      int (*write_packet)(struct AVFormatContext *, AVPacket *pkt);
> +
>      int (*write_trailer)(struct AVFormatContext *);
> +
> +    int (*write_trailer2)(struct AVFormatContext *);
> +
> +    int (*deinit)(struct AVFormatContext *);
> +
>      /**
>       * Currently only used to set pixel format if not YUV420P.
>       */
> @@ -1426,6 +1447,10 @@ void avformat_close_input(AVFormatContext **s);
>   */
>  int avformat_write_header(AVFormatContext *s, AVDictionary **options);
>  
> +int avformat_mux_init(AVFormatContext *s, AVDictionary **options);
> +
> +int avformat_mux_header(AVFormatContext *s);
> +
>  /**
>   * Write a packet to an output media file.
>   *
> diff --git a/libavformat/mux.c b/libavformat/mux.c
> index aa8d228..5f42321 100644
> --- a/libavformat/mux.c
> +++ b/libavformat/mux.c
> @@ -303,6 +303,17 @@ int avformat_write_header(AVFormatContext *s, 
> AVDictionary **options)
>          ret = s->oformat->write_header(s);
>          if (ret < 0)
>              return ret;
> +    } else {
> +        if (s->oformat->init) {
> +            ret = s->oformat->init(s);
> +            if (ret < 0)
> +                return ret;
> +        }
> +        if (s->oformat->write_header2) {
> +            ret = s->oformat->write_header2(s);
> +            if (ret < 0)
> +                return ret;
> +        }
>      }
>  
>      if ((ret = init_pts(s) < 0))
> @@ -311,6 +322,38 @@ int avformat_write_header(AVFormatContext *s, 
> AVDictionary **options)
>      return 0;
>  }
>  
> +int avformat_mux_init(AVFormatContext *s, AVDictionary **options)
> +{
> +    int ret = 0;
> +
> +    if (ret = write_setup(s, options))
> +        return ret;
> +
> +    if (s->oformat->init) {
> +        ret = s->oformat->init(s);
> +        if (ret < 0)
> +            return ret;
> +    }
> +
> +    if ((ret = init_pts(s) < 0))
> +        return ret;
> +
> +    return 0;
> +}
> +
> +int avformat_mux_header(AVFormatContext *s)
> +{
> +    int ret = 0;
> +
> +    if (s->oformat->write_header2) {
> +        ret = s->oformat->write_header2(s);
> +        if (ret < 0)
> +            return ret;
> +    }
> +
> +    return 0;
> +}
> +
>  //FIXME merge with compute_pkt_fields
>  static int compute_pkt_fields2(AVFormatContext *s, AVStream *st, AVPacket 
> *pkt)
>  {
> -- 
> 1.7.12
> 

There is no documentation.

write_trailer2() is unused

Why the write_header/write_header2() split? Shouldn't just adding init
be enough?

-- 
Anton Khirnov
_______________________________________________
libav-devel mailing list
[email protected]
https://lists.libav.org/mailman/listinfo/libav-devel

Reply via email to