[Mplayer-cvslog] CVS: main/libmpdemux/realrtsp real.c,1.2,1.3 rtsp.c,1.5,1.6 rtsp.h,1.2,1.3

Roberto Togni CVS rtognimp at mplayerhq.hu
Sun Nov 23 14:36:19 CET 2003


Update of /cvsroot/mplayer/main/libmpdemux/realrtsp
In directory mail:/var/tmp.root/cvs-serv19807

Modified Files:
	real.c rtsp.c rtsp.h 
Log Message:
Real rtsp Range parameter (Start and End) support.
Patch by rgselk <rgselknospam(at)yahoo(dot)com>


Index: real.c
===================================================================
RCS file: /cvsroot/mplayer/main/libmpdemux/realrtsp/real.c,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- real.c	17 May 2003 00:58:13 -0000	1.2
+++ real.c	23 Nov 2003 13:35:55 -0000	1.3
@@ -649,6 +649,25 @@
   return n+12;
 }
 
+int convert_timestamp(char *str, int *sec, int *msec) {
+  int hh, mm, ss, ms = 0;
+  if (sscanf(str, "%d:%d:%d.%d", &hh, &mm, &ss, &ms) < 3) {
+    hh = 0;
+    if (sscanf(str, "%d:%d.%d", &mm, &ss, &ms) < 2) {
+      mm = 0;
+      if (sscanf(str, "%d.%d", &ss, &ms) < 1) {
+	ss = 0;
+	ms = 0;
+      }
+    }
+  }
+  if (sec)
+    *sec = hh * 3600 + mm * 60 + ss;
+  if (msec)
+    *msec = ms;
+  return 1;
+}
+
 rmff_header_t  *real_setup_and_get_header(rtsp_t *rtsp_session, uint32_t bandwidth) {
 
   char *description=NULL;
@@ -745,10 +764,24 @@
   rtsp_schedule_field(rtsp_session, subscribe);
   rtsp_request_setparameter(rtsp_session,NULL);
 
+  {
+    int s_ss = 0, s_ms = 0, e_ss = 0, e_ms = 0;
+    char *str;
+    if ((str = rtsp_get_param(rtsp_session, "start"))) {
+      convert_timestamp(str, &s_ss, &s_ms);
+      free(str);
+    }
+    if ((str = rtsp_get_param(rtsp_session, "end"))) {
+      convert_timestamp(str, &e_ss, &e_ms);
+      free(str);
+    }
+    str = buf + sprintf(buf, s_ms ? "%s%d.%d-" : "%s%d-", "Range: npt=", s_ss, s_ms);
+    if (e_ss || e_ms)
+      sprintf(str, e_ms ? "%d.%d" : "%d", e_ss, e_ms);
+  }
+  rtsp_schedule_field(rtsp_session, buf);
   /* and finally send a play request */
-  rtsp_schedule_field(rtsp_session, "Range: npt=0-");
   rtsp_request_play(rtsp_session,NULL);
 
   return h;
 }
-

Index: rtsp.c
===================================================================
RCS file: /cvsroot/mplayer/main/libmpdemux/realrtsp/rtsp.c,v
retrieving revision 1.5
retrieving revision 1.6
diff -u -r1.5 -r1.6
--- rtsp.c	4 Oct 2003 17:29:03 -0000	1.5
+++ rtsp.c	23 Nov 2003 13:35:55 -0000	1.6
@@ -65,6 +65,7 @@
   char         *host;
   int           port;
   char         *path;
+  char         *param;
   char         *mrl;
   char         *user_agent;
 
@@ -622,7 +623,13 @@
   s->mrl = strdup(mrl);
   s->host = strdup(host);
   s->port = port;
+  while (*path == '/')
+    path++;
   s->path = strdup(path);
+  if ((s->param = strchr(s->path, '?')) != NULL)
+    s->param++;
+  //printf("path=%s\n", s->path);
+  //printf("param=%s\n", s->param ? s->param : "NULL");
   s->s = fd;
 
   if (s->s < 0) {
@@ -716,6 +723,30 @@
 
 }
 
+char *rtsp_get_param(rtsp_t *s, char *p) {
+  int len;
+  char *param;
+  if (!s->param)
+    return NULL;
+  if (!p)
+    return strdup(s->param);
+  len = strlen(p);
+  param = s->param;
+  while (param && *param) {
+    char *nparam = strchr(param, '&');
+    if (strncmp(param, p, len) == 0 && param[len] == '=') {
+      param += len + 1;
+      len = nparam ? nparam - param : strlen(param);
+      nparam = malloc(len + 1);
+      memcpy(nparam, param, len);
+      nparam[len] = 0;
+      return nparam;
+    }
+    param = nparam ? nparam + 1 : NULL;
+  }
+  return NULL;
+}
+  
 /*
  * schedules a field for transmission
  */

Index: rtsp.h
===================================================================
RCS file: /cvsroot/mplayer/main/libmpdemux/realrtsp/rtsp.h,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- rtsp.h	20 Apr 2003 14:40:38 -0000	1.2
+++ rtsp.h	23 Nov 2003 13:35:55 -0000	1.3
@@ -62,6 +62,7 @@
 char *rtsp_get_session(rtsp_t *s);
 
 char *rtsp_get_mrl(rtsp_t *s);
+char *rtsp_get_param(rtsp_t *s, char *param);
 
 /*int      rtsp_peek_header (rtsp_t *this, char *data); */
 



More information about the MPlayer-cvslog mailing list