[MPlayer-dev-eng] [PATCH] for starting .rm streaming over rtsp:// at specifiedstarting point(.ram syntax)

Bernhard Kaindl bernhard.kaindl at gmx.de
Sun Aug 3 06:46:27 CEST 2003


Hi,
   I needed to start rtsp://-streamed realvideo&audio with some start
offset in the video clip like it's often used in .ram files like this

rtsp://helixserver.example.com/video1.rm?start="0:51:02"

to start realplay playback at offset 51 min 02 sec into the stream(e.g.)

The exact format including all parameters is described at:
http://service.real.com/help/library/guides/realone/IntroGuide/HTML/htmfiles/ramsum.htm

So I implemented the start="time offset" parameter in the simplest way
possible. The attached patch is doing any syntax checking, it only passes
the parsed data to the server, which has to do the real parsing.

I think this is good enough for an initial implementation it enable this
often needed feature, improvements/pointers to a HTTP URL parser would
be welcome of course.

The patch should fairly trivial to understand with the comments I added
and I cannot see anything it could break, the only possibility would be
MRL paths which contain '?', to be passed as such, but the RFC would be
really broken if it would support MRL paths which contain '?', at least
the URL syntax in the .ram files would violate it, which I don't assume.

So I think the patch should not have a problem to be included.

I also did a small change to *rtsp_get() which was aborting mplayer with
the message "librtsp: buffer overflow in rtsp_get\n" when playing an
rtsp:// stream over UDP in combination with a server which does not
get even a single answer to mplayer for a few seconds. The cause was
that the for loop loops pretty quick and ran quickly over it's treshold.

It would likely be best to run the recv() using an timeout, with this
change it loops untis a newline is received from the server.

Bernhard
-------------- next part --------------
--- mplayer-0.99-cvs/libmpdemux/realrtsp/rtsp.c	2003-06-11 18:48:08.000000000 +0200
+++ mplayer-0.99-cvs/libmpdemux/realrtsp/rtsp.c	2003-08-03 05:58:57.000000000 +0200
@@ -66,6 +66,13 @@
   int           port;
   char         *path;
   char         *mrl;
+/*
+ * startpoint always holds a char[] containting the start point
+ * in the stream where we should start playback,
+ * can be set using the URL syntax for rtsp:// as used in .ram files:
+ * http://service.real.com/help/library/guides/realone/IntroGuide/HTML/htmfiles/ramsum.htms
+ */
+  char         *startpoint;
   char         *user_agent;
 
   char         *server;
@@ -269,13 +276,14 @@
  
 static char *rtsp_get(rtsp_t *s) {
 
-  int n=0;
+  int r, n=0;
   char *string;
 
   while (n<BUF_SIZE) {
-    read_stream(s->s, &s->buffer[n], 1);
+    r=read_stream(s->s, &s->buffer[n], 1);
     if ((s->buffer[n-1]==0x0d)&&(s->buffer[n]==0x0a)) break;
-    n++;
+    if (r>0)
+      n++; /* move buffer index only if we got input for the buffer */
   }
 
   if (n>=BUF_SIZE) {
@@ -599,6 +606,7 @@
 //rtsp_t *rtsp_connect(const char *mrl, const char *user_agent) {
 rtsp_t *rtsp_connect(int fd, char* mrl, char *path, char *host, int port, char *user_agent) {
 
+  char *cpnt;
   rtsp_t *s=malloc(sizeof(rtsp_t));
   int i;
   
@@ -619,10 +627,29 @@
   else
     s->user_agent=strdup("User-Agent: RealMedia Player Version 6.0.9.1235 (linux-2.0-libc6-i386-gcc2.95)");
 
-  s->mrl = strdup(mrl);
+  s->mrl = cpnt = strdup(mrl);
+  /* some servers get confused by the URL syntax used in .ram files, cut if needed: */
+  for (; *cpnt; cpnt++)
+    if (*cpnt == '?')
+      *cpnt = '\0';
   s->host = strdup(host);
   s->port = port;
-  s->path = strdup(path);
+
+  /* default session start is the beginning of the stream(second 0) */
+  s->startpoint="0";
+  s->path = cpnt = strdup(path);
+  for (; *cpnt; cpnt++) {
+    if (*cpnt == '?') {
+      /* URL parameters used in .ram files are not part of the path, cut it: */
+      *cpnt++ = '\0';
+      if (!strncmp(cpnt, "start=", 6))
+	// Found a possible start= parameter, mark and terminate it: */
+	for (s->startpoint = cpnt; *cpnt; cpnt++)
+	  if (*cpnt == '&')
+	    *cpnt = '\0';
+    }
+  }
+
   s->s = fd;
 
   if (s->s < 0) {
@@ -716,6 +743,12 @@
 
 }
 
+char *rtsp_get_startpoint(rtsp_t *s) {
+
+  return s->startpoint;
+
+}
+
 /*
  * schedules a field for transmission
  */
--- mplayer-0.99-cvs/libmpdemux/realrtsp/real.c	2003-05-17 02:58:13.000000000 +0200
+++ mplayer-0.99-cvs/libmpdemux/realrtsp/real.c	2003-08-03 06:00:11.000000000 +0200
@@ -746,7 +746,8 @@
   rtsp_request_setparameter(rtsp_session,NULL);
 
   /* and finally send a play request */
-  rtsp_schedule_field(rtsp_session, "Range: npt=0-");
+  sprintf(buf, "Range: npt=%s-", rtsp_get_startpoint(rtsp_session));
+  rtsp_schedule_field(rtsp_session, buf);
   rtsp_request_play(rtsp_session,NULL);
 
   return h;


More information about the MPlayer-dev-eng mailing list