]> git.sesse.net Git - vlc/blobdiff - modules/stream_out/rtsp.c
Qt4 - Remove a funny debug message.
[vlc] / modules / stream_out / rtsp.c
index 7ee996f2b6f1f9aa40d0146cf9cd5bfbfe83a383..17d6844457ade45e31b718aec252b8c3d232af9f 100644 (file)
@@ -48,6 +48,7 @@ struct rtsp_stream_t
     httpd_host_t   *host;
     httpd_url_t    *url;
     char           *psz_path;
+    const char     *track_fmt;
     unsigned        port;
 
     int             sessionc;
@@ -68,40 +69,40 @@ rtsp_stream_t *RtspSetup( sout_stream_t *p_stream, const vlc_url_t *url )
     rtsp_stream_t *rtsp = malloc( sizeof( *rtsp ) );
 
     if( rtsp == NULL || ( url->i_port > 99999 ) )
+    {
+        free( rtsp );
         return NULL;
+    }
 
     rtsp->owner = p_stream;
     rtsp->sessionc = 0;
     rtsp->sessionv = NULL;
+    rtsp->host = NULL;
+    rtsp->url = NULL;
+    rtsp->psz_path = NULL;
     vlc_mutex_init( p_stream, &rtsp->lock );
 
-    msg_Dbg( p_stream, "rtsp setup: %s : %d / %s\n",
-             url->psz_host, url->i_port, url->psz_path );
-
     rtsp->port = (url->i_port > 0) ? url->i_port : 554;
-    if( url->psz_path != NULL )
-        rtsp->psz_path = strdup( url->psz_path + 1 );
+    rtsp->psz_path = strdup( ( url->psz_path != NULL ) ? url->psz_path : "/" );
+    if( rtsp->psz_path == NULL )
+        goto error;
+
+    assert( strlen( rtsp->psz_path ) > 0 );
+    if( rtsp->psz_path[strlen( rtsp->psz_path ) - 1] == '/' )
+        rtsp->track_fmt = "%strackID=%u";
     else
-        rtsp->psz_path = NULL;
+        rtsp->track_fmt = "%s/trackID=%u";
 
-#if 0
-    if( asprintf( &rtsp->psz_control, "rtsp://%s:%d%s",
-                  url->psz_host,  url->i_port > 0 ? url->i_port : 554,
-                  rtsp->psz_path ) == -1 )
-    {
-        rtsp->psz_control = NULL;
-        goto error;
-    }
-#endif
+    msg_Dbg( p_stream, "RTSP stream: host %s port %d at %s",
+             url->psz_host, rtsp->port, rtsp->psz_path );
 
     rtsp->host = httpd_HostNew( VLC_OBJECT(p_stream), url->psz_host,
                                 rtsp->port );
     if( rtsp->host == NULL )
         goto error;
 
-    rtsp->url = httpd_UrlNewUnique( rtsp->host,
-                                    url->psz_path ? url->psz_path : "/", NULL,
-                                    NULL, NULL );
+    rtsp->url = httpd_UrlNewUnique( rtsp->host, rtsp->psz_path,
+                                    NULL, NULL, NULL );
     if( rtsp->url == NULL )
         goto error;
 
@@ -131,6 +132,7 @@ void RtspUnsetup( rtsp_stream_t *rtsp )
     if( rtsp->host )
         httpd_HostDelete( rtsp->host );
 
+    free( rtsp->psz_path );
     vlc_mutex_destroy( &rtsp->lock );
 }
 
@@ -164,7 +166,7 @@ struct rtsp_session_t
 struct rtsp_strack_t
 {
     sout_stream_id_t  *id;
-    sout_access_out_t *access;
+    int                fd;
     vlc_bool_t         playing;
 };
 
@@ -175,7 +177,7 @@ rtsp_stream_id_t *RtspAddId( rtsp_stream_t *rtsp, sout_stream_id_t *sid,
                              const char *dst, int ttl,
                              unsigned loport, unsigned hiport )
 {
-    char urlbuf[sizeof( "//trackID=123" ) + strlen( rtsp->psz_path )];
+    char urlbuf[sizeof( "/trackID=123" ) + strlen( rtsp->psz_path )];
     rtsp_stream_id_t *id = malloc( sizeof( *id ) );
     httpd_url_t *url;
 
@@ -193,9 +195,9 @@ rtsp_stream_id_t *RtspAddId( rtsp_stream_t *rtsp, sout_stream_id_t *sid,
         id->hiport = hiport;
     }
 
-    snprintf( urlbuf, sizeof( urlbuf ), "/%s/trackID=%u", rtsp->psz_path,
+    snprintf( urlbuf, sizeof( urlbuf ), rtsp->track_fmt, rtsp->psz_path,
               num );
-    msg_Dbg( rtsp->owner, "RTSP: adding %s\n", urlbuf );
+    msg_Dbg( rtsp->owner, "RTSP: adding %s", urlbuf );
     url = id->url = httpd_UrlNewUnique( rtsp->host, urlbuf, NULL, NULL, NULL );
 
     if( url == NULL )
@@ -227,9 +229,8 @@ void RtspDelId( rtsp_stream_t *rtsp, rtsp_stream_id_t *id )
             if( ses->trackv[j].id == id->sout_id )
             {
                 rtsp_strack_t *tr = ses->trackv + j;
-                sout_AccessOutDelete( tr->access );
+                net_Close( tr->fd );
                 REMOVE_ELEM( ses->trackv, ses->trackc, j );
-                /* FIXME: are we supposed to notify the client? */
             }
         }
     }
@@ -293,10 +294,7 @@ void RtspClientDel( rtsp_stream_t *rtsp, rtsp_session_t *session )
     TAB_REMOVE( rtsp->sessionc, rtsp->sessionv, session );
 
     for( i = 0; i < session->trackc; i++ )
-    {
-        rtp_del_sink( session->trackv[i].id, session->trackv[i].access );
-        sout_AccessOutDelete( session->trackv[i].access );
-    }
+        rtp_del_sink( session->trackv[i].id, session->trackv[i].fd );
 
     free( session->trackv );
     free( session );
@@ -338,11 +336,11 @@ static int RtspHandler( rtsp_stream_t *rtsp, rtsp_stream_id_t *id,
                         httpd_message_t *answer,
                         const httpd_message_t *query )
 {
-    sout_stream_t *p_stream = id->stream->owner;
+    sout_stream_t *p_stream = rtsp->owner;
     char psz_sesbuf[17];
     const char *psz_session = NULL, *psz;
 
-    if( answer == NULL || query == NULL )
+    if( answer == NULL || query == NULL || cl == NULL )
         return VLC_SUCCESS;
 
     /* */
@@ -370,7 +368,7 @@ static int RtspHandler( rtsp_stream_t *rtsp, rtsp_stream_id_t *id,
             }
 
             char ip[NI_MAXNUMERICHOST], *ptr;
-            char control[sizeof("rtsp://[]:12345/") + sizeof( ip )
+            char control[sizeof("rtsp://[]:12345") + sizeof( ip )
                             + strlen( rtsp->psz_path )];
 
             /* Build self-referential URL */
@@ -380,11 +378,11 @@ static int RtspHandler( rtsp_stream_t *rtsp, rtsp_stream_id_t *id,
                 *ptr = '\0';
 
             if( strchr( ip, ':' ) != NULL )
-                sprintf( control, "rtsp://[%s]:%u/%s", ip, rtsp->port,
-                         ( rtsp->psz_path != NULL ) ? rtsp->psz_path : "" );
+                sprintf( control, "rtsp://[%s]:%u%s", ip, rtsp->port,
+                         rtsp->psz_path );
             else
-                sprintf( control, "rtsp://%s:%u/%s", ip, rtsp->port,
-                         ( rtsp->psz_path != NULL ) ? rtsp->psz_path : "" );
+                sprintf( control, "rtsp://%s:%u%s", ip, rtsp->port,
+                         rtsp->psz_path );
 
             ptr = SDPGenerate( rtsp->owner, control );
 
@@ -501,10 +499,10 @@ static int RtspHandler( rtsp_stream_t *rtsp, rtsp_stream_id_t *id,
                 }
                 else
                 {
-                    char ip[NI_MAXNUMERICHOST], url[NI_MAXNUMERICHOST + 8];
-                    static const char access[] = "udp{raw,rtcp}";
+                    char ip[NI_MAXNUMERICHOST], src[NI_MAXNUMERICHOST];
                     rtsp_session_t *ses = NULL;
-                    rtsp_strack_t track = { id->sout_id, NULL, VLC_FALSE };
+                    rtsp_strack_t track = { id->sout_id, -1, VLC_FALSE };
+                    int sport;
 
                     if( httpd_ClientIP( cl, ip ) == NULL )
                     {
@@ -512,25 +510,18 @@ static int RtspHandler( rtsp_stream_t *rtsp, rtsp_stream_id_t *id,
                         continue;
                     }
 
-                    snprintf( url, sizeof( url ),
-                              ( strchr( ip, ':' ) != NULL )
-                                  ? "[%s]:%d" : "%s:%d",
-                              ip, loport );
-
-                    track.access = sout_AccessOutNew( p_stream->p_sout,
-                                                      access, url );
-                    if( track.access == NULL )
+                    track.fd = net_ConnectDgram( p_stream, ip, loport, -1,
+                                                 IPPROTO_UDP );
+                    if( track.fd == -1 )
                     {
                         msg_Err( p_stream,
-                                 "cannot create access output for %s://%s",
-                                 access, url );
+                                 "cannot create RTP socket for %s port %u",
+                                 ip, loport );
                         answer->i_status = 500;
                         continue;
                     }
 
-                    char *src = var_GetNonEmptyString( track.access,
-                                                       "src-addr" );
-                    int sport = var_GetInteger( track.access, "src-port" );
+                    net_GetSockAddress( track.fd, src, &sport );
 
                     vlc_mutex_lock( &rtsp->lock );
                     if( psz_session == NULL )
@@ -559,7 +550,7 @@ static int RtspHandler( rtsp_stream_t *rtsp, rtsp_stream_id_t *id,
 
                     httpd_ServerIP( cl, ip );
 
-                    if( ( src != NULL ) && strcmp( src, ip ) )
+                    if( strcmp( src, ip ) )
                     {
                         /* Specify source IP if it is different from the RTSP
                          * control connection server address */
@@ -583,7 +574,6 @@ static int RtspHandler( rtsp_stream_t *rtsp, rtsp_stream_id_t *id,
                     }
 
                     answer->i_status = 200;
-                    free( src );
                 }
                 break;
             }
@@ -612,7 +602,7 @@ static int RtspHandler( rtsp_stream_t *rtsp, rtsp_stream_id_t *id,
                      && ( ( id == NULL ) || ( tr->id == id->sout_id ) ) )
                     {
                         tr->playing = VLC_TRUE;
-                        rtp_add_sink( tr->id, tr->access );
+                        rtp_add_sink( tr->id, tr->fd, VLC_FALSE );
                     }
                 }
             }
@@ -660,8 +650,7 @@ static int RtspHandler( rtsp_stream_t *rtsp, rtsp_stream_id_t *id,
                 {
                     if( ses->trackv[i].id == id->sout_id )
                     {
-                        rtp_del_sink( id->sout_id, ses->trackv[i].access );
-                        sout_AccessOutDelete( ses->trackv[i].access );
+                        rtp_del_sink( id->sout_id, ses->trackv[i].fd );
                         REMOVE_ELEM( ses->trackv, ses->trackc, i );
                     }
                 }