[FFmpeg-devel] [PATCH] avformat/rtsp: fix infinite loop with udp transport

quinkblack at foxmail.com quinkblack at foxmail.com
Thu Aug 6 11:50:05 EEST 2020


From: Zhao Zhili <quinkblack at foxmail.com>

User report: http://ffmpeg.org/pipermail/ffmpeg-user/2020-August/049494.html

server:
./ffmpeg -i test.mp4 -c copy -f rtsp -rtsp_transport udp  rtsp://localhost:12345/live.sdp

client:
./ffmpeg_g -y -rtsp_flags listen -timeout 100 -i rtsp://localhost:12345/live.sdp -c copy test.mp4
---
 libavformat/rtsp.c | 5 +++++
 1 file changed, 5 insertions(+)

diff --git a/libavformat/rtsp.c b/libavformat/rtsp.c
index 5d8491b74b..0fb9fde6b4 100644
--- a/libavformat/rtsp.c
+++ b/libavformat/rtsp.c
@@ -2051,6 +2051,11 @@ static int udp_read_packet(AVFormatContext *s, RTSPStream **prtsp_st,
                 if ((ret = parse_rtsp_message(s)) < 0) {
                     return ret;
                 }
+                /* Since there is no way to detect eof of udp streams, break
+                 * the loop in teardown state to prevent run into infinite.
+                 */
+                if (rt->state == RTSP_STATE_IDLE)
+                    return AVERROR_EOF;
             }
 #endif
         } else if (n == 0 && ++timeout_cnt >= MAX_TIMEOUTS) {
-- 
2.17.1



More information about the ffmpeg-devel mailing list