This is an automated email from the git hooks/post-receive script.

Git pushed a commit to branch master
in repository ffmpeg.

commit fe38a1e257f85ad2e16e4b3bd0bde9f6873592e7
Author:     Jun Zhao <[email protected]>
AuthorDate: Sun Jun 28 07:08:12 2026 +0800
Commit:     Jun Zhao <[email protected]>
CommitDate: Sun Jul 12 00:02:40 2026 +0000

    avformat/network: make ff_network_init() follow standard AVERROR convention
    
    ff_network_init() used to return 0 on failure and 1 on success,
    requiring callers to check !ff_network_init(). Change it to return
    a negative AVERROR(EIO) on failure and 0 on success, matching the
    standard FFmpeg convention where negative values indicate errors.
    
    Update all callers (avio.c, rtsp.c, rtspdec.c, sapdec.c, sapenc.c,
    utils.c) to use the standard (ret = ff_network_init()) < 0 pattern.
    
    Signed-off-by: Jun Zhao <[email protected]>
---
 libavformat/avio.c    |  4 ++--
 libavformat/network.c |  9 +++++++--
 libavformat/rtsp.c    | 12 ++++++------
 libavformat/rtspdec.c |  4 ++--
 libavformat/sapdec.c  |  4 ++--
 libavformat/sapenc.c  |  4 ++--
 6 files changed, 21 insertions(+), 16 deletions(-)

diff --git a/libavformat/avio.c b/libavformat/avio.c
index 1e26092f79..34aad24683 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 2b7e665bc4..2b4c78cfb1 100644
--- a/libavformat/network.c
+++ b/libavformat/network.c
@@ -55,15 +55,20 @@ void ff_tls_deinit(void)
 #endif
 }
 
+/**
+ * Initialize the network subsystem. On Windows, this calls WSAStartup().
+ *
+ * @return 0 on success, a negative AVERROR code on failure.
+ */
 int ff_network_init(void)
 {
 #if HAVE_WINSOCK2_H
     WSADATA wsaData;
 
     if (WSAStartup(MAKEWORD(1,1), &wsaData))
-        return 0;
+        return AVERROR(EIO);
 #endif
-    return 1;
+    return 0;
 }
 
 int ff_network_wait_fd(int fd, int write)
diff --git a/libavformat/rtsp.c b/libavformat/rtsp.c
index 45b62c4188..20baacf0c6 100644
--- a/libavformat/rtsp.c
+++ b/libavformat/rtsp.c
@@ -1891,8 +1891,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;
 
     if (s->max_delay < 0) /* Not set by the caller */
         s->max_delay = s->iformat ? DEFAULT_REORDERING_DELAY : 0;
@@ -2579,8 +2579,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;
@@ -2706,8 +2706,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 4f970d4c89..fada311367 100644
--- a/libavformat/rtspdec.c
+++ b/libavformat/rtspdec.c
@@ -770,8 +770,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 22db3803c9..715cd0656a 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..e264a588d8 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,

_______________________________________________
ffmpeg-cvslog mailing list -- [email protected]
To unsubscribe send an email to [email protected]

Reply via email to