]> git.sesse.net Git - vlc/blobdiff - modules/stream_out/rtsp.c
Qt: Simple Preferences: conditionally hide the whole groupbox, not
[vlc] / modules / stream_out / rtsp.c
index c216539a357756c3928f9f35af3aadbb24c9d285..da781594c532401379fcae1398d97d8cce8715ff 100644 (file)
@@ -43,8 +43,9 @@
 #include <assert.h>
 #include <errno.h>
 #include <stdlib.h>
+#include <time.h>
 
-#ifndef WIN32
+#ifndef _WIN32
 # include <locale.h>
 #endif
 #ifdef HAVE_XLOCALE_H
@@ -64,7 +65,6 @@ struct rtsp_stream_t
     httpd_url_t    *url;
     char           *psz_path;
     unsigned        track_id;
-    unsigned        port;
 
     int             sessionc;
     rtsp_session_t **sessionv;
@@ -85,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;
@@ -112,21 +112,22 @@ rtsp_stream_t *RtspSetup( vlc_object_t *owner, vod_media_t *media,
             goto error;
     }
 
-    rtsp->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: host %s port %d at %s",
-             url->psz_host, rtsp->port, rtsp->psz_path );
+    msg_Dbg( owner, "RTSP stream at %s", rtsp->psz_path );
 
-    rtsp->host = httpd_HostNew( VLC_OBJECT(owner), url->psz_host,
-                                rtsp->port );
+    rtsp->host = vlc_rtsp_HostNew( VLC_OBJECT(owner) );
     if( rtsp->host == NULL )
         goto error;
 
-    rtsp->url = httpd_UrlNewUnique( rtsp->host, rtsp->psz_path,
-                                    NULL, NULL, NULL );
+    char *user = var_InheritString(owner, "sout-rtsp-user");
+    char *pwd = var_InheritString(owner, "sout-rtsp-pwd");
+
+    rtsp->url = httpd_UrlNew( rtsp->host, rtsp->psz_path, user, pwd );
+    free(user);
+    free(pwd);
     if( rtsp->url == NULL )
         goto error;
 
@@ -252,7 +253,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_UrlNew( rtsp->host, urlbuf, user, pwd );
+    free( user );
+    free( pwd );
     free( urlbuf );
 
     if( url == NULL )
@@ -415,7 +422,7 @@ static void RtspClientAlive( rtsp_session_t *session )
 static int dup_socket(int oldfd)
 {
     int newfd;
-#if !defined(WIN32) || defined(UNDER_CE)
+#ifndef _WIN32
     newfd = vlc_dup(oldfd);
 #else
     WSAPROTOCOL_INFO info;
@@ -442,7 +449,7 @@ int RtspTrackAttach( rtsp_stream_t *rtsp, const char *name,
         goto out;
 
     rtsp_strack_t *tr = NULL;
-    for (int i = 0; session->trackc; i++)
+    for (int i = 0; i < session->trackc; i++)
     {
         if (session->trackv[i].id == id)
         {
@@ -466,6 +473,7 @@ int RtspTrackAttach( rtsp_stream_t *rtsp, const char *name,
         vlc_rand_bytes (&track.ssrc, sizeof (track.ssrc));
 
         INSERT_ELEM(session->trackv, session->trackc, session->trackc, track);
+        tr = session->trackv + session->trackc - 1;
     }
 
     *ssrc = ntohl(tr->ssrc);
@@ -500,7 +508,7 @@ void RtspTrackDetach( rtsp_stream_t *rtsp, const char *name,
     if (session == NULL)
         goto out;
 
-    for (int i = 0; session->trackc; i++)
+    for (int i = 0; i < session->trackc; i++)
     {
         rtsp_strack_t *tr = session->trackv + i;
         if (tr->sout_id == sout_id)
@@ -618,18 +626,17 @@ static int RtspHandler( rtsp_stream_t *rtsp, rtsp_stream_id_t *id,
     {
         /* Build self-referential control URL */
         char ip[NI_MAXNUMERICHOST], *ptr;
+        int port;
 
-        httpd_ServerIP( cl, ip );
+        httpd_ServerIP( cl, ip, &port );
         ptr = strchr( ip, '%' );
         if( ptr != NULL )
             *ptr = '\0';
 
         if( strchr( ip, ':' ) != NULL )
-            sprintf( control, "rtsp://[%s]:%u%s", ip, rtsp->port,
-                     rtsp->psz_path );
+            sprintf( control, "rtsp://[%s]:%d%s", ip, port, rtsp->psz_path );
         else
-            sprintf( control, "rtsp://%s:%u%s", ip, rtsp->port,
-                     rtsp->psz_path );
+            sprintf( control, "rtsp://%s:%d%s", ip, port, rtsp->psz_path );
     }
 
     /* */
@@ -810,7 +817,7 @@ static int RtspHandler( rtsp_stream_t *rtsp, rtsp_stream_id_t *id,
                     int fd, sport;
                     uint32_t ssrc;
 
-                    if( httpd_ClientIP( cl, ip ) == NULL )
+                    if( httpd_ClientIP( cl, ip, NULL ) == NULL )
                     {
                         answer->i_status = 500;
                         continue;
@@ -903,7 +910,7 @@ static int RtspHandler( rtsp_stream_t *rtsp, rtsp_stream_id_t *id,
                     }
                     vlc_mutex_unlock( &rtsp->lock );
 
-                    httpd_ServerIP( cl, ip );
+                    httpd_ServerIP( cl, ip, NULL );
 
                     /* Specify source IP only if it is different from the
                      * RTSP control connection server address */
@@ -934,7 +941,7 @@ static int RtspHandler( rtsp_stream_t *rtsp, rtsp_stream_id_t *id,
             answer->i_status = 200;
 
             psz_session = httpd_MsgGet( query, "Session" );
-            int64_t start = -1, end = -1;
+            int64_t start = -1, end = -1, npt;
             const char *range = httpd_MsgGet (query, "Range");
             if (range != NULL)
             {
@@ -995,7 +1002,8 @@ static int RtspHandler( rtsp_stream_t *rtsp, rtsp_stream_id_t *id,
                     }
                 }
                 int64_t ts = rtp_get_ts(vod ? NULL : (sout_stream_t *)owner,
-                                        sout_id, rtsp->vod_media, psz_session);
+                                        sout_id, rtsp->vod_media, psz_session,
+                                        vod ? NULL : &npt);
 
                 for( int i = 0; i < ses->trackc; i++ )
                 {
@@ -1043,13 +1051,20 @@ 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)
                 {
-                    bool running = (sout_id != NULL);
-                    vod_play(rtsp->vod_media, psz_session, start, end, running);
+                    vod_play(rtsp->vod_media, psz_session, &start, end);
+                    npt = start;
                 }
+
+                double f_npt = (double) npt / CLOCK_FREQ;
+                httpd_MsgAdd( answer, "Range", "npt=%f-", f_npt );
             }
-            vlc_mutex_unlock( &rtsp->lock );
 
             if( httpd_MsgGet( query, "Scale" ) != NULL )
                 httpd_MsgAdd( answer, "Scale", "1." );
@@ -1074,12 +1089,7 @@ static int RtspHandler( rtsp_stream_t *rtsp, rtsp_stream_id_t *id,
             ses = RtspClientGet( rtsp, psz_session );
             if (ses != NULL)
             {
-                if (id == NULL)
-                {
-                    if (vod)
-                        vod_pause(rtsp->vod_media, psz_session);
-                }
-                else /* "Mute" the selected track */
+                if (id != NULL) /* "Mute" the selected track */
                 {
                     bool found = false;
                     for (int i = 0; i < ses->trackc; i++)
@@ -1105,6 +1115,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;
         }