diff rtsp.c @ 5112:85e0a9761818 libavformat

Implement support for EOS as used by WMS and other RTSP servers that do not implement RTCP/bye. See "[PATCH] rtsp.c: EOS support" thread from a few months back.
author rbultje
date Mon, 27 Jul 2009 14:03:53 +0000
parents 43d99d0e12e0
children cad276e8f96e
line wrap: on
line diff
--- a/rtsp.c	Mon Jul 27 14:00:10 2009 +0000
+++ b/rtsp.c	Mon Jul 27 14:03:53 2009 +0000
@@ -700,6 +700,9 @@
     } else if (av_stristart(p, "Server:", &p)) {
         skip_spaces(&p);
         av_strlcpy(reply->server, p, sizeof(reply->server));
+    } else if (av_stristart(p, "Notice:", &p) ||
+               av_stristart(p, "X-Notice:", &p)) {
+        reply->notice = strtol(p, NULL, 10);
     }
 }
 
@@ -823,6 +826,17 @@
     else
         av_free(content);
 
+    /* EOS */
+    if (reply->notice == 2101 /* End-of-Stream Reached */      ||
+        reply->notice == 2104 /* Start-of-Stream Reached */    ||
+        reply->notice == 2306 /* Continuous Feed Terminated */)
+        rt->state = RTSP_STATE_IDLE;
+    else if (reply->notice >= 4400 && reply->notice < 5500)
+        return AVERROR(EIO); /* data or server error */
+    else if (reply->notice == 2401 /* Ticket Expired */ ||
+             (reply->notice >= 5500 && reply->notice < 5600) /* end of term */ )
+        return AVERROR(EPERM);
+
     return 0;
 }
 
@@ -1314,6 +1328,8 @@
         if (ret == 1) /* received '$' */
             break;
         /* XXX: parse message */
+        if (rt->state != RTSP_STATE_PLAYING)
+            return 0;
     }
     ret = url_read_complete(rt->rtsp_hd, buf, 3);
     if (ret != 3)
@@ -1399,6 +1415,8 @@
 
                 rtsp_read_reply(s, &reply, NULL, 0);
                 /* XXX: parse message */
+                if (rt->state != RTSP_STATE_PLAYING)
+                    return 0;
             }
         }
     }
@@ -1506,6 +1524,8 @@
     }
     if (len < 0)
         return len;
+    if (len == 0)
+        return AVERROR_EOF;
     if (rt->transport == RTSP_TRANSPORT_RDT)
         ret = ff_rdt_parse_packet(rtsp_st->transport_priv, pkt, buf, len);
     else