]> git.sesse.net Git - vlc/blobdiff - modules/demux/live555.cpp
Compile fix for packaged ffmpeg on debian etch.
[vlc] / modules / demux / live555.cpp
index dc1bc0ab6d8078cf6143906a5a3c44c8e9f00705..710aa6a04b2af7299fe2ab5a52d69fc860744e09 100644 (file)
  * Preamble
  *****************************************************************************/
 
+#ifdef HAVE_CONFIG_H
+# include "config.h"
+#endif
+
 #include <vlc/vlc.h>
 
 #include <vlc_demux.h>
@@ -35,6 +39,7 @@
 #include <vlc_url.h>
 
 #include <iostream>
+#include <limits.h>
 
 #if defined( WIN32 )
 #   include <winsock2.h>
@@ -304,11 +309,17 @@ static int  Open ( vlc_object_t *p_this )
             int i_read = stream_Read( p_demux->s, &p_sdp[i_sdp],
                                       i_sdp_max - i_sdp - 1 );
 
+            if( p_demux->b_die || p_demux->b_error )
+            {
+                free( p_sdp );
+                goto error;
+            }
+
             if( i_read < 0 )
             {
                 msg_Err( p_demux, "failed to read SDP" );
-                free( p_sys );
-                return VLC_EGENERIC;
+                free( p_sdp );
+                goto error;
             }
 
             i_sdp += i_read;
@@ -387,7 +398,7 @@ error:
         vlc_object_kill( p_sys->p_timeout );
         vlc_thread_join( p_sys->p_timeout );
         vlc_object_detach( p_sys->p_timeout );
-        vlc_object_destroy( p_sys->p_timeout );
+        vlc_object_release( p_sys->p_timeout );
     }
     if( p_sys->scheduler ) delete p_sys->scheduler;
     if( p_sys->p_sdp ) free( p_sys->p_sdp );
@@ -428,7 +439,7 @@ static void Close( vlc_object_t *p_this )
         vlc_object_kill( p_sys->p_timeout );
         vlc_thread_join( p_sys->p_timeout );
         vlc_object_detach( p_sys->p_timeout );
-        vlc_object_destroy( p_sys->p_timeout );
+        vlc_object_release( p_sys->p_timeout );
     }
     if( p_sys->scheduler ) delete p_sys->scheduler;
     if( p_sys->p_sdp ) free( p_sys->p_sdp );
@@ -446,6 +457,7 @@ static int Connect( demux_t *p_demux )
 {
     demux_sys_t *p_sys = p_demux->p_sys;
     Authenticator authenticator;
+    vlc_bool_t b_firstpass = VLC_TRUE;
 
     char *psz_user    = NULL;
     char *psz_pwd     = NULL;
@@ -531,9 +543,21 @@ describe:
         if( var_GetBool( p_demux, "rtsp-http" ) )
             sscanf( psz_error, "%*s %*s HTTP GET %*s HTTP/%*u.%*u %3u %*s",
                     &i_code );
-        else sscanf( psz_error, "%*sRTSP/%*s%3u", &i_code );
+        else
+        {
+            const char *psz_tmp = strstr( psz_error, "RTSP" );
+            sscanf( psz_tmp, "RTSP/%*s%3u", &i_code );
+        }
         msg_Dbg( p_demux, "DESCRIBE failed with %d: %s", i_code, psz_error );
 
+        if( b_firstpass )
+        {   /* describeURL always returns an "RTSP/1.0 401 Unauthorized" the
+             * first time. This is a workaround to avoid asking for a
+             * user/passwd the first time the code passess here. */
+            i_code = 0;
+            b_firstpass = VLC_FALSE;
+        }
+
         if( i_code == 401 )
         {
             int i_result;
@@ -621,6 +645,12 @@ static int SessionsSetup( demux_t *p_demux )
         Boolean bInit;
         live_track_t *tk;
 
+        if( p_demux->b_die || p_demux->b_error )
+        {
+            delete iter;
+            return VLC_EGENERIC;
+        }
+
         /* Value taken from mplayer */
         if( !strcmp( sub->mediumName(), "audio" ) )
             i_buffer = 100000;
@@ -695,6 +725,11 @@ static int SessionsSetup( demux_t *p_demux )
             }
 
             tk = (live_track_t*)malloc( sizeof( live_track_t ) );
+            if( !tk )
+            {
+                delete iter;
+                return VLC_ENOMEM;
+            }
             tk->p_demux     = p_demux;
             tk->sub         = sub;
             tk->p_es        = NULL;
@@ -707,6 +742,11 @@ static int SessionsSetup( demux_t *p_demux )
             tk->i_pts       = 0;
             tk->i_buffer    = 65536;
             tk->p_buffer    = (uint8_t *)malloc( 65536 );
+            if( !tk->p_buffer )
+            {
+                delete iter;
+                return VLC_ENOMEM;
+            }
 
             /* Value taken from mplayer */
             if( !strcmp( sub->mediumName(), "audio" ) )
@@ -993,7 +1033,7 @@ static int Play( demux_t *p_demux )
                                    VLC_THREAD_PRIORITY_LOW, VLC_TRUE ) )
             {
                 msg_Err( p_demux, "cannot spawn liveMedia timeout thread" );
-                vlc_object_destroy( p_sys->p_timeout );
+                vlc_object_release( p_sys->p_timeout );
             }
             msg_Dbg( p_demux, "spawned timeout thread" );
             vlc_object_attach( p_sys->p_timeout, p_demux );