changeset 5846:6821f3887d0e libavformat

Don't let ff_rtsp_read_reply skip interleaved RTP/TCP packets in rtsp_write_packet. Skip interleaved packets manually and recheck if there's more to be read.
author mstorsjo
date Mon, 15 Mar 2010 16:36:20 +0000
parents 7512694b0515
children d04ce2be0081
files rtspenc.c
diffstat 1 files changed, 14 insertions(+), 4 deletions(-) [+]
line wrap: on
line diff
--- a/rtspenc.c	Mon Mar 15 16:31:15 2010 +0000
+++ b/rtspenc.c	Mon Mar 15 16:36:20 2010 +0000
@@ -72,20 +72,30 @@
     struct timeval tv;
     AVFormatContext *rtpctx;
     AVPacket local_pkt;
+    int ret;
 
-    FD_ZERO(&rfds);
     tcp_fd = url_get_file_handle(rt->rtsp_hd);
-    FD_SET(tcp_fd, &rfds);
 
+    while (1) {
+        FD_ZERO(&rfds);
+        FD_SET(tcp_fd, &rfds);
     tv.tv_sec = 0;
     tv.tv_usec = 0;
     n = select(tcp_fd + 1, &rfds, NULL, NULL, &tv);
-    if (n > 0) {
+        if (n <= 0)
+            break;
         if (FD_ISSET(tcp_fd, &rfds)) {
             RTSPMessageHeader reply;
 
-            if (ff_rtsp_read_reply(s, &reply, NULL, 0) < 0)
+            /* Don't let ff_rtsp_read_reply handle interleaved packets,
+             * since it would block and wait for an RTSP reply on the socket
+             * (which may not be coming any time soon) if it handles
+             * interleaved packets internally. */
+            ret = ff_rtsp_read_reply(s, &reply, NULL, 1);
+            if (ret < 0)
                 return AVERROR(EPIPE);
+            if (ret == 1)
+                ff_rtsp_skip_packet(s);
             /* XXX: parse message */
             if (rt->state != RTSP_STATE_STREAMING)
                 return AVERROR(EPIPE);