]> git.sesse.net Git - vlc/blobdiff - modules/demux/livedotcom.cpp
Copyright fixes
[vlc] / modules / demux / livedotcom.cpp
index 127eb4ddd7adc59cf39a10026b65a0a85d0099d3..d4afa5002d7e32d038c429217182a0e485e7d6ea 100644 (file)
@@ -1,7 +1,7 @@
 /*****************************************************************************
  * live.cpp : live.com support.
  *****************************************************************************
- * Copyright (C) 2003-2004 VideoLAN
+ * Copyright (C) 2003-2004 VideoLAN (Centrale Réseaux) and its contributors
  * $Id$
  *
  * Authors: Laurent Aimar <fenrir@via.ecp.fr>
@@ -28,6 +28,7 @@
 
 #include <vlc/vlc.h>
 #include <vlc/input.h>
+#include "network.h"
 
 #include <iostream>
 
@@ -132,6 +133,7 @@ typedef struct
 struct demux_sys_t
 {
     char         *p_sdp;    /* XXX mallocated */
+    char         *psz_path; /* URL-encoded path */
 
     MediaSession     *ms;
     TaskScheduler    *scheduler;
@@ -153,6 +155,7 @@ struct demux_sys_t
     mtime_t          i_start;
 
     /* */
+    vlc_bool_t       b_multicast;   /* true if one of the tracks is multicasted */
     vlc_bool_t       b_no_data;     /* true if we never receive any data */
     int              i_no_data_ti;  /* consecutive number of TaskInterrupt */
 
@@ -193,16 +196,12 @@ static int  Open ( vlc_object_t *p_this )
     {
         /* See if it looks like a SDP
            v, o, s fields are mandatory and in this order */
-        if( stream_Peek( p_demux->s, &p_peek, 7 ) < 7 )
-        {
-            msg_Err( p_demux, "cannot peek" );
-            return VLC_EGENERIC;
-        }
+        if( stream_Peek( p_demux->s, &p_peek, 7 ) < 7 ) return VLC_EGENERIC;
+
         if( strncmp( (char*)p_peek, "v=0\r\n", 5 ) &&
             strncmp( (char*)p_peek, "v=0\n", 4 ) &&
             ( p_peek[0] < 'a' || p_peek[0] > 'z' || p_peek[1] != '=' ) )
         {
-            msg_Warn( p_demux, "SDP module discarded" );
             return VLC_EGENERIC;
         }
     }
@@ -228,6 +227,8 @@ static int  Open ( vlc_object_t *p_this )
     p_sys->p_out_asf = NULL;
     p_sys->b_no_data = VLC_TRUE;
     p_sys->i_no_data_ti = 0;
+    p_sys->b_multicast = VLC_FALSE;
+    p_sys->psz_path = p_demux->psz_path;
 
 
     if( ( p_sys->scheduler = BasicTaskScheduler::createNew() ) == NULL )
@@ -241,6 +242,14 @@ static int  Open ( vlc_object_t *p_this )
         goto error;
     }
 
+    if( strcasecmp( p_demux->psz_access, "sdp" ) && 
+       vlc_UrlIsNotEncoded( p_sys->psz_path ) )
+    {
+        p_sys->psz_path = vlc_UrlEncode( p_sys->psz_path );
+        if( p_sys->psz_path == NULL )
+            goto error;
+    }
+
     if( p_demux->s == NULL && !strcasecmp( p_demux->psz_access, "rtsp" ) )
     {
         char *psz_url;
@@ -253,8 +262,8 @@ static int  Open ( vlc_object_t *p_this )
                      p_sys->env->getResultMsg() );
             goto error;
         }
-        psz_url = (char*)malloc( strlen( p_demux->psz_path ) + 8 );
-        sprintf( psz_url, "rtsp://%s", p_demux->psz_path );
+        psz_url = (char*)malloc( strlen( p_sys->psz_path ) + 8 );
+        sprintf( psz_url, "rtsp://%s", p_sys->psz_path );
 
         psz_options = p_sys->rtsp->sendOptionsCmd( psz_url );
         if( psz_options )
@@ -278,7 +287,7 @@ static int  Open ( vlc_object_t *p_this )
     }
     else if( p_demux->s == NULL && !strcasecmp( p_demux->psz_access, "sdp" ) )
     {
-        p_sys->p_sdp = strdup( p_demux->psz_path );
+        p_sys->p_sdp = strdup( p_sys->psz_path );
     }
     else
     {
@@ -365,6 +374,11 @@ static int  Open ( vlc_object_t *p_this )
                 p_sys->rtsp->setupMediaSubsession( *sub, False,
                                                    b_rtsp_tcp ? True : False );
             }
+            if( !p_sys->b_multicast )
+            {
+                /* Check, because we need diff. rollover behaviour for multicast */
+                p_sys->b_multicast = IsMulticastAddress( sub->connectionEndpointAddress() );
+            }
         }
     }
 
@@ -623,6 +637,10 @@ error:
     {
         free( p_sys->p_sdp );
     }
+    if( ( p_sys->psz_path != NULL )
+     && ( p_sys->psz_path != p_demux->psz_path ) )
+        free( p_sys->psz_path );
+
     free( p_sys );
     return VLC_EGENERIC;
 }
@@ -660,6 +678,8 @@ static void Close( vlc_object_t *p_this )
     if( p_sys->env ) RECLAIM_ENV(p_sys->env);
     if( p_sys->scheduler ) delete p_sys->scheduler;
     if( p_sys->p_sdp ) free( p_sys->p_sdp );
+    if( p_sys->psz_path != p_demux->psz_path )
+        free( p_sys->psz_path );
     free( p_sys );
 }
 
@@ -747,13 +767,20 @@ static int Demux( demux_t *p_demux )
         }
     }
 
-    if( p_sys->b_no_data && p_sys->i_no_data_ti > 3 )
+    if( p_sys->b_multicast && p_sys->b_no_data && p_sys->i_no_data_ti > 120 )
+    {
+        /* FIXME Make this configurable
+        msg_Err( p_demux, "no multicast data received in 36s, aborting" );
+        return 0;
+        */
+    }
+    else if( !p_sys->b_multicast && p_sys->b_no_data && p_sys->i_no_data_ti > 34 )
     {
         vlc_bool_t b_rtsp_tcp = var_GetBool( p_demux, "rtsp-tcp" );
 
         if( !b_rtsp_tcp && p_sys->rtsp && p_sys->ms )
         {
-            msg_Warn( p_demux, "no data received in 900ms. Switching to TCP" );
+            msg_Warn( p_demux, "no data received in 10s. Switching to TCP" );
             if( RollOverTcp( p_demux ) )
             {
                 msg_Err( p_demux, "TCP rollover failed, aborting" );
@@ -761,16 +788,16 @@ static int Demux( demux_t *p_demux )
             }
             var_SetBool( p_demux, "rtsp-tcp", VLC_TRUE );
         }
-        else if( p_sys->i_no_data_ti > 10 )
+        else if( p_sys->i_no_data_ti > 34 )
         {
-            msg_Err( p_demux, "no data received in 3s, aborting" );
+            msg_Err( p_demux, "no data received in 10s, aborting" );
             return 0;
         }
     }
-    else if( p_sys->i_no_data_ti > 10 )
+    else if( !p_sys->b_multicast && p_sys->b_no_data&& p_sys->i_no_data_ti > 34 )
     {
         /* EOF ? */
-        msg_Warn( p_demux, "no data received in 3s, eof ?" );
+        msg_Warn( p_demux, "no data received in 10s, eof ?" );
        return 0;
     }
 
@@ -947,7 +974,7 @@ static int RollOverTcp( demux_t *p_demux )
         return VLC_EGENERIC;
     }
 
-    asprintf( &psz_url, "rtsp://%s", p_demux->psz_path );
+    asprintf( &psz_url, "rtsp://%s", p_sys->psz_path );
 
     if( ( psz_options = p_sys->rtsp->sendOptionsCmd( psz_url ) ) )
         delete [] psz_options;