[FFmpeg-devel] [PATCH] rtsp.c: EOS support

Ronald S. Bultje rsbultje
Sat Mar 21 22:17:23 CET 2009


Hi,

attached is something that adds sort-of functional EOS support to the
RTSP demuxer. It works, but I don't think it's entirely ready, so see
it partially as a RFC. For example, I'm wondering if people agree
setting RTSPState::state is a good way to maintain EOS state on
subsequent read_packet() calls, and I'm interested in other approaches
that do the same thing.

Ronald
-------------- next part --------------
Index: ffmpeg-svn/libavformat/rtsp.c
===================================================================
--- ffmpeg-svn.orig/libavformat/rtsp.c	2009-03-05 22:23:11.000000000 -0500
+++ ffmpeg-svn/libavformat/rtsp.c	2009-03-05 22:23:36.000000000 -0500
@@ -701,6 +701,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);
     }
 }
 
@@ -838,6 +841,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;
 }
 
@@ -1310,7 +1324,8 @@
             return -1;
         if (ret == 1) /* received '$' */
             break;
-        /* XXX: parse message */
+        if (rt->state != RTSP_STATE_PLAYING)
+            return 0;
     }
     ret = url_readbuf(rt->rtsp_hd, buf, 3);
     if (ret != 3)
@@ -1390,7 +1405,8 @@
                 RTSPMessageHeader reply;
 
                 rtsp_read_reply(s, &reply, NULL, 0);
-                /* XXX: parse message */
+                if (rt->state != RTSP_STATE_PLAYING)
+                    return 0;
             }
         }
     }
@@ -1498,6 +1514,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
Index: ffmpeg-svn/libavformat/rtsp.h
===================================================================
--- ffmpeg-svn.orig/libavformat/rtsp.h	2009-03-05 22:23:11.000000000 -0500
+++ ffmpeg-svn/libavformat/rtsp.h	2009-03-05 22:23:14.000000000 -0500
@@ -132,6 +132,11 @@
      * (RealServer compatible)" or "RealServer Version v.e.r.sion (platform)",
      * where platform is the output of $uname -msr | sed 's/ /-/g'. */
     char server[64];
+
+    /** The "Notice" or "X-Notice" field value. See
+     * http://tools.ietf.org/html/draft-stiemerling-rtsp-announce-00
+     * for a complete list of supported values. */
+    int notice;
 } RTSPMessageHeader;
 
 /**



More information about the ffmpeg-devel mailing list