]> git.sesse.net Git - vlc/blobdiff - modules/access/rtsp/rtsp.c
Simplify the CDDA module. Split more between parse and play
[vlc] / modules / access / rtsp / rtsp.c
index d6f38561f1961d211a87eaad89492c5585c614d8..02b80e907d30c14d0a9a0b3524aae2063595ec03 100644 (file)
@@ -4,7 +4,7 @@
  *****************************************************************************
  * Copyright (C) 2002-2004 the xine project
  * Copyright (C) 2005 VideoLAN
- * $Id: file.c 10310 2005-03-11 22:36:40Z anil $
+ * $Id$
  *
  * Authors: Gildas Bazin <gbazin@videolan.org>
  *          Adapted from xine which itself adapted it from joschkas real tools.
  *
  * You should have received a copy of the GNU General Public License
  * along with this program; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111, USA.
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
  *****************************************************************************/
-
-#include <unistd.h>
 #include <stdio.h>
 #include <stdlib.h>
 
@@ -91,7 +89,7 @@ static char *rtsp_get( rtsp_client_t *rtsp )
   char *psz_buffer = malloc( BUF_SIZE );
   char *psz_string = NULL;
 
-  if( rtsp->pf_read_line( rtsp->p_userdata, psz_buffer, BUF_SIZE ) >= 0 )
+  if( rtsp->pf_read_line( rtsp->p_userdata, psz_buffer, (unsigned int)BUF_SIZE ) >= 0 )
   {
     //printf( "<< '%s'\n", psz_buffer );
       psz_string = strdup( psz_buffer );
@@ -105,10 +103,10 @@ static char *rtsp_get( rtsp_client_t *rtsp )
 /*
  * rtsp_put puts a line on stream
  */
+
 static int rtsp_put( rtsp_client_t *rtsp, const char *psz_string )
 {
-    int i_buffer = strlen( psz_string );
+    unsigned int i_buffer = strlen( psz_string );
     char *psz_buffer = malloc( i_buffer + 3 );
     int i_ret;
 
@@ -130,7 +128,7 @@ static int rtsp_get_status_code( rtsp_client_t *rtsp, const char *psz_string )
 {
     char psz_buffer[4];
     int i_code = 0;
+
     if( !strncmp( psz_string, "RTSP/1.0", sizeof("RTSP/1.0") - 1 ) )
     {
         memcpy( psz_buffer, psz_string + sizeof("RTSP/1.0"), 3 );
@@ -204,7 +202,7 @@ static void rtsp_schedule_standard( rtsp_client_t *rtsp )
 /*
  * get the answers, if server responses with something != 200, return NULL
  */
+
 static int rtsp_get_answers( rtsp_client_t *rtsp )
 {
     char *answer = NULL;
@@ -212,7 +210,7 @@ static int rtsp_get_answers( rtsp_client_t *rtsp )
     char **answer_ptr = rtsp->p_private->answers;
     int code;
     int ans_count = 0;
-  
+
     answer = rtsp_get( rtsp );
     if( !answer ) return 0;
     code = rtsp_get_status_code( rtsp, answer );
@@ -224,7 +222,7 @@ static int rtsp_get_answers( rtsp_client_t *rtsp )
 
       answer = rtsp_get( rtsp );
       if( !answer ) return 0;
-    
+
       if( !strncasecmp( answer, "Cseq:", 5 ) )
       {
           sscanf( answer, "%*s %u", &answer_seq );
@@ -241,8 +239,7 @@ static int rtsp_get_answers( rtsp_client_t *rtsp )
           char *buf = malloc( strlen(answer) );
           sscanf( answer, "%*s %s", buf );
           if( rtsp->p_private->server ) free( rtsp->p_private->server );
-          rtsp->p_private->server = strdup( buf );
-          free( buf );
+          rtsp->p_private->server = buf;
       }
       if( !strncasecmp( answer, "Session:", 8 ) )
       {
@@ -285,7 +282,7 @@ static int rtsp_get_answers( rtsp_client_t *rtsp )
 int rtsp_send_ok( rtsp_client_t *rtsp )
 {
     char cseq[16];
-  
+
     rtsp_put( rtsp, "RTSP/1.0 200 OK" );
     sprintf( cseq, "CSeq: %u", rtsp->p_private->cseq );
     rtsp_put( rtsp, cseq );
@@ -402,7 +399,7 @@ int rtsp_read_data( rtsp_client_t *rtsp, char *buffer, unsigned int size )
 
     if( size >= 4 )
     {
-        i= rtsp->pf_read( rtsp->p_userdata, buffer, 4 );
+        i = rtsp->pf_read( rtsp->p_userdata, buffer, (unsigned int) 4 );
         if( i < 4 ) return i;
 
         if( buffer[0]=='S' && buffer[1]=='E' && buffer[2]=='T' &&
@@ -420,13 +417,13 @@ int rtsp_read_data( rtsp_client_t *rtsp, char *buffer, unsigned int size )
 
                 if( !strncasecmp( rest, "Cseq:", 5 ) )
                     sscanf( rest, "%*s %u", &seq );
-            } while( strlen(rest) != 0 );
-
+            } while( *rest );
             free( rest );
+
             if( seq < 0 )
             {
                 fprintf(stderr, "warning: cseq not recognized!\n");
-                seq=1;
+                seq = 1;
             }
 
             /* lets make the server happy */
@@ -435,15 +432,16 @@ int rtsp_read_data( rtsp_client_t *rtsp, char *buffer, unsigned int size )
             sprintf( rest,"CSeq: %u", seq );
             rtsp_put( rtsp, rest );
             rtsp_put( rtsp, "" );
-            rtsp->pf_read( rtsp->p_userdata, buffer, size );
+            free( rest );
+            i = rtsp->pf_read( rtsp->p_userdata, (unsigned char*)buffer, size );
         }
         else
         {
-            i = rtsp->pf_read( rtsp->p_userdata, buffer + 4, size - 4 );
+            i = rtsp->pf_read( rtsp->p_userdata, (unsigned char*)buffer + 4, size - 4 );
             i += 4;
         }
     }
-    else i= rtsp->pf_read( rtsp->p_userdata, buffer, size );
+    else i = rtsp->pf_read( rtsp->p_userdata, (unsigned char*)buffer, size );
 
     //fprintf( stderr, "<< %d of %d bytes\n", i, size );
 
@@ -460,7 +458,7 @@ int rtsp_connect( rtsp_client_t *rtsp, const char *psz_mrl,
     rtsp_t *s;
     char *mrl_ptr;
     char *slash, *colon;
-    int hostend, pathbegin, i;
+    unsigned int hostend, pathbegin, i;
 
     if( !psz_mrl ) return -1;
     s = malloc( sizeof(rtsp_t) );
@@ -516,6 +514,7 @@ int rtsp_connect( rtsp_client_t *rtsp, const char *psz_mrl,
         if( s->port < 0 || s->port > 65535 ) s->port = 554;
     }
 
+    free( mrl_ptr );
     fprintf( stderr, "got mrl: %s %i %s\n", s->host, s->port, s->path );
 
     s->s = rtsp->pf_connect( rtsp->p_userdata, s->host, s->port );
@@ -563,6 +562,7 @@ void rtsp_close( rtsp_client_t *rtsp )
     if( rtsp->p_private->mrl ) free( rtsp->p_private->mrl );
     if( rtsp->p_private->session ) free( rtsp->p_private->session );
     if( rtsp->p_private->user_agent ) free( rtsp->p_private->user_agent );
+    if( rtsp->p_private->server ) free( rtsp->p_private->server );
     rtsp_free_answers( rtsp );
     rtsp_unschedule_all( rtsp );
     free( rtsp->p_private );