]> git.sesse.net Git - vlc/blobdiff - modules/stream_out/rtsp.c
DASH: fix URL parsing
[vlc] / modules / stream_out / rtsp.c
index c9ab534e943a724bf1f3b818a71760688434cde5..2f9569ae5c65a047b862e44bde525685862fe03e 100644 (file)
@@ -43,6 +43,7 @@
 #include <assert.h>
 #include <errno.h>
 #include <stdlib.h>
+#include <time.h>
 
 #ifndef WIN32
 # include <locale.h>
@@ -84,11 +85,11 @@ static void RtspClientDel( rtsp_stream_t *rtsp, rtsp_session_t *session );
 static void RtspTimeOut( void *data );
 
 rtsp_stream_t *RtspSetup( vlc_object_t *owner, vod_media_t *media,
-                          const vlc_url_t *url )
+                          const char *path )
 {
     rtsp_stream_t *rtsp = malloc( sizeof( *rtsp ) );
 
-    if( rtsp == NULL || ( url->i_port > 99999 ) )
+    if( rtsp == NULL )
     {
         free( rtsp );
         return NULL;
@@ -111,19 +112,23 @@ rtsp_stream_t *RtspSetup( vlc_object_t *owner, vod_media_t *media,
             goto error;
     }
 
-    int port = (url->i_port > 0) ? url->i_port : 554;
-    rtsp->psz_path = strdup( ( url->psz_path != NULL ) ? url->psz_path : "/" );
+    rtsp->psz_path = strdup( (path != NULL) ? path : "/" );
     if( rtsp->psz_path == NULL )
         goto error;
 
-    msg_Dbg( owner, "RTSP stream: port %d at %s", port, rtsp->psz_path );
+    msg_Dbg( owner, "RTSP stream at %s", rtsp->psz_path );
 
-    rtsp->host = vlc_rtsp_HostNew( VLC_OBJECT(owner), port );
+    rtsp->host = vlc_rtsp_HostNew( VLC_OBJECT(owner) );
     if( rtsp->host == NULL )
         goto error;
 
+    char *user = var_InheritString(owner, "sout-rtsp-user");
+    char *pwd = var_InheritString(owner, "sout-rtsp-pwd");
+
     rtsp->url = httpd_UrlNewUnique( rtsp->host, rtsp->psz_path,
-                                    NULL, NULL, NULL );
+                                    user, pwd, NULL );
+    free(user);
+    free(pwd);
     if( rtsp->url == NULL )
         goto error;
 
@@ -249,7 +254,13 @@ rtsp_stream_id_t *RtspAddId( rtsp_stream_t *rtsp, sout_stream_id_t *sid,
     }
 
     msg_Dbg( rtsp->owner, "RTSP: adding %s", urlbuf );
-    url = id->url = httpd_UrlNewUnique( rtsp->host, urlbuf, NULL, NULL, NULL );
+
+    char *user = var_InheritString(rtsp->owner, "sout-rtsp-user");
+    char *pwd = var_InheritString(rtsp->owner, "sout-rtsp-pwd");
+
+    url = id->url = httpd_UrlNewUnique( rtsp->host, urlbuf, user, pwd, NULL );
+    free( user );
+    free( pwd );
     free( urlbuf );
 
     if( url == NULL )
@@ -1041,16 +1052,17 @@ static int RtspHandler( rtsp_stream_t *rtsp, rtsp_stream_id_t *id,
                     info[infolen - 2] = '\0'; /* remove trailing ", " */
                     httpd_MsgAdd( answer, "RTP-Info", "%s", info );
                 }
+            }
+            vlc_mutex_unlock( &rtsp->lock );
+
+            if (ses != NULL)
+            {
                 if (vod)
                 {
                     vod_play(rtsp->vod_media, psz_session, &start, end);
                     npt = start;
                 }
-            }
-            vlc_mutex_unlock( &rtsp->lock );
 
-            if (ses != NULL)
-            {
                 double f_npt = (double) npt / CLOCK_FREQ;
                 httpd_MsgAdd( answer, "Range", "npt=%f-", f_npt );
             }
@@ -1078,15 +1090,7 @@ static int RtspHandler( rtsp_stream_t *rtsp, rtsp_stream_id_t *id,
             ses = RtspClientGet( rtsp, psz_session );
             if (ses != NULL)
             {
-                if (id == NULL)
-                {
-                    assert(vod);
-                    int64_t npt;
-                    vod_pause(rtsp->vod_media, psz_session, &npt);
-                    double f_npt = (double) npt / CLOCK_FREQ;
-                    httpd_MsgAdd( answer, "Range", "npt=%f-", f_npt );
-                }
-                else /* "Mute" the selected track */
+                if (id != NULL) /* "Mute" the selected track */
                 {
                     bool found = false;
                     for (int i = 0; i < ses->trackc; i++)
@@ -1112,6 +1116,15 @@ static int RtspHandler( rtsp_stream_t *rtsp, rtsp_stream_id_t *id,
                 RtspClientAlive(ses);
             }
             vlc_mutex_unlock( &rtsp->lock );
+
+            if (ses != NULL && id == NULL)
+            {
+                assert(vod);
+                int64_t npt = 0;
+                vod_pause(rtsp->vod_media, psz_session, &npt);
+                double f_npt = (double) npt / CLOCK_FREQ;
+                httpd_MsgAdd( answer, "Range", "npt=%f-", f_npt );
+            }
             break;
         }