[FFmpeg-devel] [PATCH v5 5/6] avformat/network: Return 0/AVERROR from ff_network_init()

Andrew Sayers ffmpeg-devel at pileofstuff.org
Thu May 16 14:59:10 EEST 2024


---
 libavformat/avio.c    |  7 +++++--
 libavformat/network.c |  7 +++----
 libavformat/rtsp.c    | 14 ++++++++------
 libavformat/rtspdec.c |  5 +++--
 libavformat/sapdec.c  |  5 +++--
 libavformat/sapenc.c  |  5 +++--
 6 files changed, 25 insertions(+), 18 deletions(-)

diff --git a/libavformat/avio.c b/libavformat/avio.c
index d109f3adff..8c94bfeb14 100644
--- a/libavformat/avio.c
+++ b/libavformat/avio.c
@@ -123,8 +123,11 @@ 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();
+        if (err<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 351dc34bb6..643294efe4 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_neterror2(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..d50d0b7fc0 100644
--- a/libavformat/rtsp.c
+++ b/libavformat/rtsp.c
@@ -1740,8 +1740,9 @@ int ff_rtsp_connect(AVFormatContext *s)
         return AVERROR(EINVAL);
     }
 
-    if (!ff_network_init())
-        return AVERROR(EIO);
+    err = ff_network_init();
+    if (err<0)
+        return err;
 
     if (s->max_delay < 0) /* Not set by the caller */
         s->max_delay = s->iformat ? DEFAULT_REORDERING_DELAY : 0;
@@ -2395,8 +2396,9 @@ static int sdp_read_header(AVFormatContext *s)
     char url[MAX_URL_SIZE];
     AVBPrint bp;
 
-    if (!ff_network_init())
-        return AVERROR(EIO);
+    err = ff_network_init();
+    if (err<0)
+        return err;
 
     if (s->max_delay < 0) /* Not set by the caller */
         s->max_delay = DEFAULT_REORDERING_DELAY;
@@ -2522,8 +2524,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..1b4b478170 100644
--- a/libavformat/rtspdec.c
+++ b/libavformat/rtspdec.c
@@ -663,8 +663,9 @@ static int rtsp_listen(AVFormatContext *s)
     int ret;
     enum RTSPMethod methodcode;
 
-    if (!ff_network_init())
-        return AVERROR(EIO);
+    ret = ff_network_init();
+    if (ret<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..393e544556 100644
--- a/libavformat/sapdec.c
+++ b/libavformat/sapdec.c
@@ -70,8 +70,9 @@ static int sap_read_header(AVFormatContext *s)
     int port;
     int ret, i;
 
-    if (!ff_network_init())
-        return AVERROR(EIO);
+    ret = ff_network_init();
+    if (ret<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..5760e3a0c2 100644
--- a/libavformat/sapenc.c
+++ b/libavformat/sapenc.c
@@ -80,8 +80,9 @@ 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);
+    ret = ff_network_init();
+    if (ret<0)
+        return ret;
 
     /* extract hostname and port */
     av_url_split(NULL, 0, NULL, 0, host, sizeof(host), &base_port,
-- 
2.43.0



More information about the ffmpeg-devel mailing list