[FFmpeg-devel] [PATCH 4/8] avformat/utils: function to check and ignore non fatal network errors

wm4 nfxjfg at googlemail.com
Fri Mar 30 16:21:15 EEST 2018


On Fri, 30 Mar 2018 10:38:34 +0530
vdixit at akamai.com wrote:

> From: Vishwanath Dixit <vdixit at akamai.com>
> 
> For live HLS/DASH output usecases, currently ffmpeg application exits
> for any network error during muxing. However, some of the errors like
> EPIPE, ECONNREFUSED and ECONNRESET are non-fatal. They might cause
> temporary disruption. However, muxer can recover and continue further
> processing.
> ---
>  libavformat/internal.h | 11 +++++++++++
>  libavformat/utils.c    | 10 ++++++++++
>  2 files changed, 21 insertions(+)
> 
> diff --git a/libavformat/internal.h b/libavformat/internal.h
> index a020b1b..e56f867 100644
> --- a/libavformat/internal.h
> +++ b/libavformat/internal.h
> @@ -731,6 +731,17 @@ int ff_unlock_avformat(void);
>   */
>  void ff_format_set_url(AVFormatContext *s, char *url);
>  
> +/**
> + * Handle error.
> + * Ignores network errors EPIPE, ECONNREFUSED and ECONNRESET
> + *
> + * @param s AVFormatContext
> + * @param err error code
> + * @param ignore_nw_err flag to ignore network errors
> + * @return 0 if error is ignored, else err
> + */
> +int av_handle_error(AVFormatContext *s, int err, int ignore_nw_err);

av_ is for public API only.

> +
>  #if FF_API_NEXT
>  /**
>    * Register devices in deprecated format linked list.
> diff --git a/libavformat/utils.c b/libavformat/utils.c
> index f13c820..a942ad0 100644
> --- a/libavformat/utils.c
> +++ b/libavformat/utils.c
> @@ -5658,3 +5658,13 @@ FF_DISABLE_DEPRECATION_WARNINGS
>  FF_ENABLE_DEPRECATION_WARNINGS
>  #endif
>  }
> +
> +int av_handle_error(AVFormatContext *s, int err, int ignore_nw_err) {
> +    if (err && ff_is_http_proto(s->url) && ignore_nw_err &&

It's absurd and not really acceptable to check for the HTTP protocol in
such a function. Instead, and if it really makes sense, these kind of
error checks should be done in the HTTP implementation.

> +        (err == AVERROR(EPIPE) || err == AVERROR(ECONNREFUSED) ||
> +         err == AVERROR(ECONNRESET))) {
> +        av_log(s, AV_LOG_WARNING, "Ignored network error %d\n", err);
> +        return 0;
> +    }
> +    return err;
> +}

(Not sure if I'm sending this mail twice. My shitty mail client froze
over yet again.)


More information about the ffmpeg-devel mailing list