[FFmpeg-cvslog] avformat/network: use av_err2str to simplify code

Marvin Scholz git at videolan.org
Fri Sep 13 01:36:31 EEST 2024


ffmpeg | branch: master | Marvin Scholz <epirat07 at gmail.com> | Sun Sep  8 21:16:45 2024 +0200| [24711b00c687d6df175d4fd5bea0b66d6450c7e3] | committer: Marvin Scholz

avformat/network: use av_err2str to simplify code

No need to explicitly specify the buffer here as it is only
ever passed to av_log, so av_err2str can be used.

> http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=24711b00c687d6df175d4fd5bea0b66d6450c7e3
---

 libavformat/network.c | 21 +++++++--------------
 1 file changed, 7 insertions(+), 14 deletions(-)

diff --git a/libavformat/network.c b/libavformat/network.c
index 6db82b6d26..2eabd0c167 100644
--- a/libavformat/network.c
+++ b/libavformat/network.c
@@ -287,16 +287,14 @@ int ff_listen_connect(int fd, const struct sockaddr *addr,
             if (getsockopt (fd, SOL_SOCKET, SO_ERROR, &ret, &optlen))
                 ret = AVUNERROR(ff_neterrno());
             if (ret != 0) {
-                char errbuf[100];
                 ret = AVERROR(ret);
-                av_strerror(ret, errbuf, sizeof(errbuf));
                 if (will_try_next)
                     av_log(h, AV_LOG_WARNING,
                            "Connection to %s failed (%s), trying next address\n",
-                           h->filename, errbuf);
+                           h->filename, av_err2str(ret));
                 else
                     av_log(h, AV_LOG_ERROR, "Connection to %s failed: %s\n",
-                           h->filename, errbuf);
+                           h->filename, av_err2str(ret));
             }
         default:
             return ret;
@@ -421,7 +419,7 @@ int ff_connect_parallel(struct addrinfo *addrs, int timeout_ms_per_address,
     int64_t next_attempt_us = av_gettime_relative(), next_deadline_us;
     int last_err = AVERROR(EIO);
     socklen_t optlen;
-    char errbuf[100], hostbuf[100], portbuf[20];
+    char hostbuf[100], portbuf[20];
 
     if (parallel > FF_ARRAY_ELEMS(attempts))
         parallel = FF_ARRAY_ELEMS(attempts);
@@ -445,9 +443,8 @@ int ff_connect_parallel(struct addrinfo *addrs, int timeout_ms_per_address,
                                              timeout_ms_per_address, h,
                                              customize_fd, customize_ctx);
             if (last_err < 0) {
-                av_strerror(last_err, errbuf, sizeof(errbuf));
                 av_log(h, AV_LOG_VERBOSE, "Connected attempt failed: %s\n",
-                                          errbuf);
+                                          av_err2str(last_err));
                 continue;
             }
             if (last_err > 0) {
@@ -511,9 +508,8 @@ int ff_connect_parallel(struct addrinfo *addrs, int timeout_ms_per_address,
             getnameinfo(attempts[i].addr->ai_addr, attempts[i].addr->ai_addrlen,
                         hostbuf, sizeof(hostbuf), portbuf, sizeof(portbuf),
                         NI_NUMERICHOST | NI_NUMERICSERV);
-            av_strerror(last_err, errbuf, sizeof(errbuf));
             av_log(h, AV_LOG_VERBOSE, "Connection attempt to %s port %s "
-                                      "failed: %s\n", hostbuf, portbuf, errbuf);
+                                      "failed: %s\n", hostbuf, portbuf, av_err2str(last_err));
             closesocket(attempts[i].fd);
             memmove(&attempts[i], &attempts[i + 1],
                     (nb_attempts - i - 1) * sizeof(*attempts));
@@ -528,9 +524,8 @@ int ff_connect_parallel(struct addrinfo *addrs, int timeout_ms_per_address,
     if (last_err >= 0)
         last_err = AVERROR(ECONNREFUSED);
     if (last_err != AVERROR_EXIT) {
-        av_strerror(last_err, errbuf, sizeof(errbuf));
         av_log(h, AV_LOG_ERROR, "Connection to %s failed: %s\n",
-               h->filename, errbuf);
+               h->filename, av_err2str(last_err));
     }
     return last_err;
 }
@@ -591,7 +586,5 @@ int ff_http_match_no_proxy(const char *no_proxy, const char *hostname)
 
 void ff_log_net_error(void *ctx, int level, const char* prefix)
 {
-    char errbuf[100];
-    av_strerror(ff_neterrno(), errbuf, sizeof(errbuf));
-    av_log(ctx, level, "%s: %s\n", prefix, errbuf);
+    av_log(ctx, level, "%s: %s\n", prefix, av_err2str(ff_neterrno()));
 }



More information about the ffmpeg-cvslog mailing list