[MPlayer-cvslog] r18775 - in trunk/libmpdemux/realrtsp: real.c rtsp.c rtsp.h

ben subversion at mplayerhq.hu
Wed Jun 21 19:39:27 CEST 2006


Author: ben
Date: Wed Jun 21 19:39:27 2006
New Revision: 18775

Modified:
   trunk/libmpdemux/realrtsp/real.c
   trunk/libmpdemux/realrtsp/rtsp.c
   trunk/libmpdemux/realrtsp/rtsp.h

Log:
better RTSP RFC compliance (fixes in CSeq and TEARDOWN handling)

Modified: trunk/libmpdemux/realrtsp/real.c
==============================================================================
--- trunk/libmpdemux/realrtsp/real.c	(original)
+++ trunk/libmpdemux/realrtsp/real.c	Wed Jun 21 19:39:27 2006
@@ -800,7 +800,7 @@
   rtsp_schedule_field(rtsp_session, "Transport: x-pn-tng/tcp;mode=play,rtp/avp/tcp;unicast;mode=play");
   buf = xbuffer_ensure_size(buf, strlen(mrl) + 32);
   sprintf(buf, "%s/streamid=0", mrl);
-  rtsp_request_setup(rtsp_session,buf);
+  rtsp_request_setup(rtsp_session,buf,NULL);
 
   if (h->prop->num_streams > 1) {
     rtsp_schedule_field(rtsp_session, "Transport: x-pn-tng/tcp;mode=play,rtp/avp/tcp;unicast;mode=play");
@@ -810,7 +810,7 @@
 
     buf = xbuffer_ensure_size(buf, strlen(mrl) + 32);
     sprintf(buf, "%s/streamid=1", mrl);
-    rtsp_request_setup(rtsp_session,buf);
+    rtsp_request_setup(rtsp_session,buf,NULL);
   }
   /* set stream parameter (bandwidth) with our subscribe string */
   rtsp_schedule_field(rtsp_session, subscribe);

Modified: trunk/libmpdemux/realrtsp/rtsp.c
==============================================================================
--- trunk/libmpdemux/realrtsp/rtsp.c	(original)
+++ trunk/libmpdemux/realrtsp/rtsp.c	Wed Jun 21 19:39:27 2006
@@ -24,6 +24,9 @@
  *
  * a minimalistic implementation of rtsp protocol,
  * *not* RFC 2326 compilant yet.
+ *
+ *    2006, Benjamin Zores and Vincent Mussard
+ *      fixed a lot of RFC compliance issues.
  */
 
 #include <unistd.h>
@@ -382,7 +385,7 @@
 
   char tmp[16];
   
-  snprintf(tmp, 16, "Cseq: %u", s->cseq);
+  snprintf(tmp, 16, "CSeq: %u", s->cseq);
   rtsp_schedule_field(s, tmp);
   
   if (s->session) {
@@ -419,11 +422,11 @@
     if (!answer)
       return 0;
     
-    if (!strncmp(answer,"Cseq:",5)) {
-      sscanf(answer,"Cseq: %u",&answer_seq);
+    if (!strncmp(answer,"CSeq:",5)) {
+      sscanf(answer,"CSeq: %u",&answer_seq);
       if (s->cseq != answer_seq) {
 #ifdef LOG
-        mp_msg(MSGT_OPEN, MSGL_WARN, "librtsp: warning: Cseq mismatch. got %u, assumed %u", answer_seq, s->cseq);
+        mp_msg(MSGT_OPEN, MSGL_WARN, "librtsp: warning: CSeq mismatch. got %u, assumed %u", answer_seq, s->cseq);
 #endif
         s->cseq=answer_seq;
       }
@@ -518,11 +521,26 @@
   return rtsp_get_answers(s);
 }
 
-int rtsp_request_setup(rtsp_t *s, const char *what) {
+int rtsp_request_setup(rtsp_t *s, const char *what, char *control) {
+
+  char *buf = NULL;
 
-  rtsp_send_request(s,"SETUP",what);
+  if (what)
+    buf = strdup (what);
+  else
+  {
+    int len = strlen (s->host) + strlen (s->path) + 16;
+    if (control)
+      len += strlen (control) + 1;
+    
+    buf = malloc (len);
+    sprintf (buf, "rtsp://%s:%i/%s%s%s", s->host, s->port, s->path,
+             control ? "/" : "", control ? control : "");
+  }
   
-  return rtsp_get_answers(s);
+  rtsp_send_request (s, "SETUP", buf);
+  free (buf);
+  return rtsp_get_answers (s);
 }
 
 int rtsp_request_setparameter(rtsp_t *s, const char *what) {
@@ -545,7 +563,8 @@
 int rtsp_request_play(rtsp_t *s, const char *what) {
 
   char *buf;
-
+  int ret;
+  
   if (what) {
     buf=strdup(what);
   } else
@@ -556,13 +575,28 @@
   rtsp_send_request(s,"PLAY",buf);
   free(buf);
   
-  return rtsp_get_answers(s);
+  ret = rtsp_get_answers (s);
+  if (ret == 200)
+    s->server_state = RTSP_PLAYING;
+
+  return ret;
 }
 
-int rtsp_request_tearoff(rtsp_t *s, const char *what) {
+int rtsp_request_teardown(rtsp_t *s, const char *what) {
 
-  rtsp_send_request(s,"TEAROFF",what);
+  char *buf;
   
+  if (what)
+    buf = strdup (what);
+  else
+  {
+    buf =
+      malloc (strlen (s->host) + strlen (s->path) + 16);
+    sprintf (buf, "rtsp://%s:%i/%s", s->host, s->port, s->path);
+  }
+  rtsp_send_request (s, "TEARDOWN", buf);
+  free (buf);
+ 
   return rtsp_get_answers(s);
 }
 
@@ -596,7 +630,7 @@
       free(rest);
       if (seq<0) {
 #ifdef LOG
-        mp_msg(MSGT_OPEN, MSGL_WARN, "rtsp: warning: cseq not recognized!\n");
+        mp_msg(MSGT_OPEN, MSGL_WARN, "rtsp: warning: CSeq not recognized!\n");
 #endif
         seq=1;
       }
@@ -640,7 +674,7 @@
   s->server_state=0;
   s->server_caps=0;
   
-  s->cseq=1;
+  s->cseq=0;
   s->session=NULL;
   
   if (user_agent)
@@ -690,7 +724,13 @@
 
 void rtsp_close(rtsp_t *s) {
 
-  if (s->server_state) closesocket(s->s); /* TODO: send a TEAROFF */
+  if (s->server_state)
+  {
+    if (s->server_state == RTSP_PLAYING)
+      rtsp_request_teardown (s, NULL);
+    closesocket (s->s);
+  }
+
   if (s->path) free(s->path);
   if (s->host) free(s->host);
   if (s->mrl) free(s->mrl);
@@ -805,6 +845,8 @@
   while(*ptr) {
     if (!strncmp(*ptr, string, strlen(string)))
       break;
+    else
+      ptr++;
   }
   if (*ptr) free(*ptr);
   ptr++;

Modified: trunk/libmpdemux/realrtsp/rtsp.h
==============================================================================
--- trunk/libmpdemux/realrtsp/rtsp.h	(original)
+++ trunk/libmpdemux/realrtsp/rtsp.h	Wed Jun 21 19:39:27 2006
@@ -24,6 +24,9 @@
  *
  * a minimalistic implementation of rtsp protocol,
  * *not* RFC 2326 compilant yet.
+ *
+ *    2006, Benjamin Zores and Vincent Mussard
+ *      fixed a lot of RFC compliance issues.
  */
  
 #ifndef HAVE_RTSP_H
@@ -41,10 +44,10 @@
 
 int rtsp_request_options(rtsp_t *s, const char *what);
 int rtsp_request_describe(rtsp_t *s, const char *what);
-int rtsp_request_setup(rtsp_t *s, const char *what);
+int rtsp_request_setup(rtsp_t *s, const char *what, char *control);
 int rtsp_request_setparameter(rtsp_t *s, const char *what);
 int rtsp_request_play(rtsp_t *s, const char *what);
-int rtsp_request_tearoff(rtsp_t *s, const char *what);
+int rtsp_request_teardown(rtsp_t *s, const char *what);
 
 int rtsp_send_ok(rtsp_t *s);
 



More information about the MPlayer-cvslog mailing list