[FFmpeg-devel] [PATCH 04/11] avformat/muxers: Add non-blocking mode support for av_write_trailer

Michael Niedermayer michael at niedermayer.cc
Wed Aug 10 20:04:30 EEST 2016


On Tue, Aug 02, 2016 at 03:24:15PM +0200, sebechlebskyjan at gmail.com wrote:
> From: Jan Sebechlebsky <sebechlebskyjan at gmail.com>
> 
> This makes av_write_trailer not to free the resources if write_trailer
> call returns AVERROR(EAGAIN) allowing repeated calls of write_trailer of
> non-blocking muxer.
> 
> Signed-off-by: Jan Sebechlebsky <sebechlebskyjan at gmail.com>
> ---
>  libavformat/avformat.h | 6 +++++-
>  libavformat/mux.c      | 3 +++
>  2 files changed, 8 insertions(+), 1 deletion(-)
> 
> diff --git a/libavformat/avformat.h b/libavformat/avformat.h
> index 818184e..9191c69 100644
> --- a/libavformat/avformat.h
> +++ b/libavformat/avformat.h
> @@ -2508,8 +2508,12 @@ int av_write_uncoded_frame_query(AVFormatContext *s, int stream_index);
>   *
>   * May only be called after a successful call to avformat_write_header.
>   *
> + * If AVFMT_FLAG_NONBLOCK is set, this call may return AVERROR(EAGAIN)
> + * meaning the operation is pending and the call should be repeated.
> + *
>   * @param s media file handle
> - * @return 0 if OK, AVERROR_xxx on error
> + * @return 0 if OK, AVERROR(EAGAIN) in case call should be repeated,
> + *         other AVERROR on error
>   */
>  int av_write_trailer(AVFormatContext *s);
>  
> diff --git a/libavformat/mux.c b/libavformat/mux.c
> index e9973ed..b58e4c1 100644
> --- a/libavformat/mux.c
> +++ b/libavformat/mux.c
> @@ -1238,6 +1238,9 @@ fail:
>          }
>      }
>  
> +    if (ret == AVERROR(EAGAIN))
> +        return ret;

IIUC the non blocking code works only if packet interleaving is not
used (which is implied by AVFMT_FLAG_NONBLOCK being set)

is there an assert ensuring that EAGAIN only occurs in such case
somewhere ?

if it would occur with the interleave code then
ret could be set before or maybe even set to EAGAIN and then

    if (s->internal->header_written && s->oformat->write_trailer) {
        if (!(s->oformat->flags & AVFMT_NOFILE) && s->pb)
            avio_write_marker(s->pb, AV_NOPTS_VALUE, AVIO_DATA_MARKER_TRAILER);
        if (ret >= 0) {
        ret = s->oformat->write_trailer(s);
        } else {
            s->oformat->write_trailer(s);
        }
    }

would do all kinds of unexpected things like ignoring the write_trailer
return  or returning to the user EAGAIN even when trailer didnt return
that, ...

[...]
-- 
Michael     GnuPG fingerprint: 9FF2128B147EF6730BADF133611EC787040B0FAB

I know you won't believe me, but the highest form of Human Excellence is
to question oneself and others. -- Socrates
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 181 bytes
Desc: Digital signature
URL: <http://ffmpeg.org/pipermail/ffmpeg-devel/attachments/20160810/668f9b8d/attachment.sig>


More information about the ffmpeg-devel mailing list