[FFmpeg-cvslog] Merge commit '79331df362fb05a0d04ca9489c87e5b80077a3f4'

James Almer git at videolan.org
Wed Oct 4 05:20:07 EEST 2017


ffmpeg | branch: master | James Almer <jamrial at gmail.com> | Tue Oct  3 23:08:06 2017 -0300| [1e7b6e47d2752a91bcd6d0c91ed2aaf118eaeee9] | committer: James Almer

Merge commit '79331df362fb05a0d04ca9489c87e5b80077a3f4'

* commit '79331df362fb05a0d04ca9489c87e5b80077a3f4':
  rtsp: Lazily set up the pollfd array once

Merged-by: James Almer <jamrial at gmail.com>

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

 libavformat/rtsp.c | 53 ++++++++++++++++++++++++++---------------------------
 libavformat/rtsp.h |  1 +
 2 files changed, 27 insertions(+), 27 deletions(-)

diff --git a/libavformat/rtsp.c b/libavformat/rtsp.c
index 2d1df80ed0..375d0d9e14 100644
--- a/libavformat/rtsp.c
+++ b/libavformat/rtsp.c
@@ -1924,7 +1924,6 @@ static int udp_read_packet(AVFormatContext *s, RTSPStream **prtsp_st,
     RTSPState *rt = s->priv_data;
     RTSPStream *rtsp_st;
     int n, i, ret, tcp_fd, timeout_cnt = 0;
-    int max_p = 0;
     struct pollfd *p = rt->p;
     int *fds = NULL, fdsnum, fdsidx;
 
@@ -1932,33 +1931,33 @@ static int udp_read_packet(AVFormatContext *s, RTSPStream **prtsp_st,
         p = rt->p = av_malloc_array(2 * (rt->nb_rtsp_streams + 1), sizeof(struct pollfd));
         if (!p)
             return AVERROR(ENOMEM);
-    }
 
-    if (rt->rtsp_hd) {
-        tcp_fd = ffurl_get_file_handle(rt->rtsp_hd);
-        p[max_p].fd = tcp_fd;
-        p[max_p++].events = POLLIN;
-    } else {
-        tcp_fd = -1;
-    }
-    for (i = 0; i < rt->nb_rtsp_streams; i++) {
-        rtsp_st = rt->rtsp_streams[i];
-        if (rtsp_st->rtp_handle) {
-            if (ret = ffurl_get_multi_file_handle(rtsp_st->rtp_handle,
-                                                  &fds, &fdsnum)) {
-                av_log(s, AV_LOG_ERROR, "Unable to recover rtp ports\n");
-                return ret;
-            }
-            if (fdsnum != 2) {
-                av_log(s, AV_LOG_ERROR,
-                       "Number of fds %d not supported\n", fdsnum);
-                return AVERROR_INVALIDDATA;
-            }
-            for (fdsidx = 0; fdsidx < fdsnum; fdsidx++) {
-                p[max_p].fd       = fds[fdsidx];
-                p[max_p++].events = POLLIN;
+        if (rt->rtsp_hd) {
+            tcp_fd = ffurl_get_file_handle(rt->rtsp_hd);
+            p[rt->max_p].fd = tcp_fd;
+            p[rt->max_p++].events = POLLIN;
+        } else {
+            tcp_fd = -1;
+        }
+        for (i = 0; i < rt->nb_rtsp_streams; i++) {
+            rtsp_st = rt->rtsp_streams[i];
+            if (rtsp_st->rtp_handle) {
+                if (ret = ffurl_get_multi_file_handle(rtsp_st->rtp_handle,
+                                                      &fds, &fdsnum)) {
+                    av_log(s, AV_LOG_ERROR, "Unable to recover rtp ports\n");
+                    return ret;
+                }
+                if (fdsnum != 2) {
+                    av_log(s, AV_LOG_ERROR,
+                           "Number of fds %d not supported\n", fdsnum);
+                    return AVERROR_INVALIDDATA;
+                }
+                for (fdsidx = 0; fdsidx < fdsnum; fdsidx++) {
+                    p[rt->max_p].fd       = fds[fdsidx];
+                    p[rt->max_p++].events = POLLIN;
+                }
+                av_freep(&fds);
             }
-            av_freep(&fds);
         }
     }
 
@@ -1967,7 +1966,7 @@ static int udp_read_packet(AVFormatContext *s, RTSPStream **prtsp_st,
             return AVERROR_EXIT;
         if (wait_end && wait_end - av_gettime_relative() < 0)
             return AVERROR(EAGAIN);
-        n = poll(p, max_p, POLL_TIMEOUT_MS);
+        n = poll(p, rt->max_p, POLL_TIMEOUT_MS);
         if (n > 0) {
             int j = 1 - (tcp_fd == -1);
             timeout_cnt = 0;
diff --git a/libavformat/rtsp.h b/libavformat/rtsp.h
index 852fd6704e..36fdae492b 100644
--- a/libavformat/rtsp.h
+++ b/libavformat/rtsp.h
@@ -352,6 +352,7 @@ typedef struct RTSPState {
      * Polling array for udp
      */
     struct pollfd *p;
+    int max_p;
 
     /**
      * Whether the server supports the GET_PARAMETER method.


======================================================================

diff --cc libavformat/rtsp.c
index 2d1df80ed0,141477bbbf..375d0d9e14
--- a/libavformat/rtsp.c
+++ b/libavformat/rtsp.c
@@@ -1932,33 -1920,33 +1931,33 @@@ static int udp_read_packet(AVFormatCont
          p = rt->p = av_malloc_array(2 * (rt->nb_rtsp_streams + 1), sizeof(struct pollfd));
          if (!p)
              return AVERROR(ENOMEM);
-     }
  
-     if (rt->rtsp_hd) {
-         tcp_fd = ffurl_get_file_handle(rt->rtsp_hd);
-         p[max_p].fd = tcp_fd;
-         p[max_p++].events = POLLIN;
-     } else {
-         tcp_fd = -1;
-     }
-     for (i = 0; i < rt->nb_rtsp_streams; i++) {
-         rtsp_st = rt->rtsp_streams[i];
-         if (rtsp_st->rtp_handle) {
-             if (ret = ffurl_get_multi_file_handle(rtsp_st->rtp_handle,
-                                                   &fds, &fdsnum)) {
-                 av_log(s, AV_LOG_ERROR, "Unable to recover rtp ports\n");
-                 return ret;
-             }
-             if (fdsnum != 2) {
-                 av_log(s, AV_LOG_ERROR,
-                        "Number of fds %d not supported\n", fdsnum);
-                 return AVERROR_INVALIDDATA;
-             }
-             for (fdsidx = 0; fdsidx < fdsnum; fdsidx++) {
-                 p[max_p].fd       = fds[fdsidx];
-                 p[max_p++].events = POLLIN;
+         if (rt->rtsp_hd) {
+             tcp_fd = ffurl_get_file_handle(rt->rtsp_hd);
+             p[rt->max_p].fd = tcp_fd;
+             p[rt->max_p++].events = POLLIN;
+         } else {
+             tcp_fd = -1;
+         }
+         for (i = 0; i < rt->nb_rtsp_streams; i++) {
+             rtsp_st = rt->rtsp_streams[i];
+             if (rtsp_st->rtp_handle) {
+                 if (ret = ffurl_get_multi_file_handle(rtsp_st->rtp_handle,
+                                                       &fds, &fdsnum)) {
+                     av_log(s, AV_LOG_ERROR, "Unable to recover rtp ports\n");
+                     return ret;
+                 }
+                 if (fdsnum != 2) {
+                     av_log(s, AV_LOG_ERROR,
+                            "Number of fds %d not supported\n", fdsnum);
+                     return AVERROR_INVALIDDATA;
+                 }
+                 for (fdsidx = 0; fdsidx < fdsnum; fdsidx++) {
+                     p[rt->max_p].fd       = fds[fdsidx];
+                     p[rt->max_p++].events = POLLIN;
+                 }
 -                av_free(fds);
++                av_freep(&fds);
              }
-             av_freep(&fds);
          }
      }
  



More information about the ffmpeg-cvslog mailing list