[FFmpeg-devel] [PATCH v4 2/3] avformat/network: Return 0/AVERROR from ff_network_init()
Marton Balint
cus at passwd.hu
Sun May 5 23:05:36 EEST 2024
On Sat, 20 Apr 2024, Andrew Sayers wrote:
> ---
> libavformat/avio.c | 4 ++--
> libavformat/network.c | 7 +++----
> libavformat/rtsp.c | 12 ++++++------
> libavformat/rtspdec.c | 4 ++--
> libavformat/sapdec.c | 4 ++--
> libavformat/sapenc.c | 4 ++--
> 6 files changed, 17 insertions(+), 18 deletions(-)
>
> diff --git a/libavformat/avio.c b/libavformat/avio.c
> index d109f3adff..f82edec779 100644
> --- a/libavformat/avio.c
> +++ b/libavformat/avio.c
> @@ -123,8 +123,8 @@ static int url_alloc_for_protocol(URLContext **puc, const URLProtocol *up,
> int err;
>
> #if CONFIG_NETWORK
> - if (up->flags & URL_PROTOCOL_FLAG_NETWORK && !ff_network_init())
> - return AVERROR(EIO);
> + if (up->flags & URL_PROTOCOL_FLAG_NETWORK && (err=ff_network_init())<0)
> + return err;
> #endif
> if ((flags & AVIO_FLAG_READ) && !up->url_read) {
> av_log(NULL, AV_LOG_ERROR,
> diff --git a/libavformat/network.c b/libavformat/network.c
> index f295957aa5..c1b0e69362 100644
> --- a/libavformat/network.c
> +++ b/libavformat/network.c
> @@ -59,11 +59,10 @@ int ff_network_init(void)
> {
> #if HAVE_WINSOCK2_H
> WSADATA wsaData;
> -
> - if (WSAStartup(MAKEWORD(1,1), &wsaData))
> - return 0;
> + return ff_neterrno2(WSAStartup(MAKEWORD(1,1), &wsaData));
> +#else
> + return 0;
> #endif
> - return 1;
> }
>
> int ff_network_wait_fd(int fd, int write)
> diff --git a/libavformat/rtsp.c b/libavformat/rtsp.c
> index b0c61ee00a..3db4ed11c2 100644
> --- a/libavformat/rtsp.c
> +++ b/libavformat/rtsp.c
> @@ -1740,8 +1740,8 @@ int ff_rtsp_connect(AVFormatContext *s)
> return AVERROR(EINVAL);
> }
>
> - if (!ff_network_init())
> - return AVERROR(EIO);
> + if ((err = ff_network_init())<0)
> + return err;
Assignments in if conditions should be avoided. So this should be expanded
to:
err = ff_network_init();
if (err < 0)
return err;
Same for the rest of the checks later.
Thanks,
Marton
>
> if (s->max_delay < 0) /* Not set by the caller */
> s->max_delay = s->iformat ? DEFAULT_REORDERING_DELAY : 0;
> @@ -2395,8 +2395,8 @@ static int sdp_read_header(AVFormatContext *s)
> char url[MAX_URL_SIZE];
> AVBPrint bp;
>
> - if (!ff_network_init())
> - return AVERROR(EIO);
> + if ((err = ff_network_init())<0)
> + return err;
>
> if (s->max_delay < 0) /* Not set by the caller */
> s->max_delay = DEFAULT_REORDERING_DELAY;
> @@ -2522,8 +2522,8 @@ static int rtp_read_header(AVFormatContext *s)
> AVBPrint sdp;
> AVDictionary *opts = NULL;
>
> - if (!ff_network_init())
> - return AVERROR(EIO);
> + if ((ret = ff_network_init())<0)
> + return ret;
>
> opts = map_to_opts(rt);
> ret = ffurl_open_whitelist(&in, s->url, AVIO_FLAG_READ,
> diff --git a/libavformat/rtspdec.c b/libavformat/rtspdec.c
> index 10078ce2fa..3b0829694e 100644
> --- a/libavformat/rtspdec.c
> +++ b/libavformat/rtspdec.c
> @@ -663,8 +663,8 @@ static int rtsp_listen(AVFormatContext *s)
> int ret;
> enum RTSPMethod methodcode;
>
> - if (!ff_network_init())
> - return AVERROR(EIO);
> + if ((ret = ff_network_init())<0)
> + return ret;
>
> /* extract hostname and port */
> av_url_split(proto, sizeof(proto), auth, sizeof(auth), host, sizeof(host),
> diff --git a/libavformat/sapdec.c b/libavformat/sapdec.c
> index 357c0dd514..719c26c6b8 100644
> --- a/libavformat/sapdec.c
> +++ b/libavformat/sapdec.c
> @@ -70,8 +70,8 @@ static int sap_read_header(AVFormatContext *s)
> int port;
> int ret, i;
>
> - if (!ff_network_init())
> - return AVERROR(EIO);
> + if ((ret = ff_network_init())<0)
> + return ret;
>
> av_url_split(NULL, 0, NULL, 0, host, sizeof(host), &port,
> path, sizeof(path), s->url);
> diff --git a/libavformat/sapenc.c b/libavformat/sapenc.c
> index 87a834a8d8..3305122524 100644
> --- a/libavformat/sapenc.c
> +++ b/libavformat/sapenc.c
> @@ -80,8 +80,8 @@ static int sap_write_header(AVFormatContext *s)
> int udp_fd;
> AVDictionaryEntry* title = av_dict_get(s->metadata, "title", NULL, 0);
>
> - if (!ff_network_init())
> - return AVERROR(EIO);
> + if ((ret = ff_network_init())<0)
> + return ret;
>
> /* extract hostname and port */
> av_url_split(NULL, 0, NULL, 0, host, sizeof(host), &base_port,
> --
> 2.43.0
>
> _______________________________________________
> ffmpeg-devel mailing list
> ffmpeg-devel at ffmpeg.org
> https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
>
> To unsubscribe, visit link above, or email
> ffmpeg-devel-request at ffmpeg.org with subject "unsubscribe".
>
More information about the ffmpeg-devel
mailing list