Commit 75412805 authored by Rémi Denis-Courmont's avatar Rémi Denis-Courmont

Fix crash when thread creation fails, fix msleep usage.

parent c3ae935f
...@@ -48,6 +48,7 @@ ...@@ -48,6 +48,7 @@
#include <iostream> #include <iostream>
#include <limits.h> #include <limits.h>
#include <assert.h>
#if defined( WIN32 ) #if defined( WIN32 )
...@@ -160,10 +161,9 @@ typedef struct ...@@ -160,10 +161,9 @@ typedef struct
struct timeout_thread_t struct timeout_thread_t
{ {
VLC_COMMON_MEMBERS
bool b_handle_keep_alive;
demux_sys_t *p_sys; demux_sys_t *p_sys;
vlc_thread_t handle;
bool b_handle_keep_alive;
}; };
struct demux_sys_t struct demux_sys_t
...@@ -222,7 +222,7 @@ static void StreamRead ( void *, unsigned int, unsigned int, ...@@ -222,7 +222,7 @@ static void StreamRead ( void *, unsigned int, unsigned int,
static void StreamClose ( void * ); static void StreamClose ( void * );
static void TaskInterrupt( void * ); static void TaskInterrupt( void * );
static void* TimeoutPrevention( vlc_object_t * ); static void* TimeoutPrevention( void * );
static unsigned char* parseH264ConfigStr( char const* configStr, static unsigned char* parseH264ConfigStr( char const* configStr,
unsigned int& configSize ); unsigned int& configSize );
...@@ -412,10 +412,9 @@ error: ...@@ -412,10 +412,9 @@ error:
if( p_sys->env ) p_sys->env->reclaim(); if( p_sys->env ) p_sys->env->reclaim();
if( p_sys->p_timeout ) if( p_sys->p_timeout )
{ {
vlc_object_kill( p_sys->p_timeout ); vlc_cancel( p_sys->p_timeout->handle );
vlc_thread_join( p_sys->p_timeout ); vlc_join( p_sys->p_timeout->handle, NULL );
vlc_object_detach( p_sys->p_timeout ); free( p_sys->p_timeout );
vlc_object_release( p_sys->p_timeout );
} }
delete p_sys->scheduler; delete p_sys->scheduler;
free( p_sys->p_sdp ); free( p_sys->p_sdp );
...@@ -454,10 +453,9 @@ static void Close( vlc_object_t *p_this ) ...@@ -454,10 +453,9 @@ static void Close( vlc_object_t *p_this )
if( p_sys->env ) p_sys->env->reclaim(); if( p_sys->env ) p_sys->env->reclaim();
if( p_sys->p_timeout ) if( p_sys->p_timeout )
{ {
vlc_object_kill( p_sys->p_timeout ); vlc_cancel( p_sys->p_timeout->handle );
vlc_thread_join( p_sys->p_timeout ); vlc_join( p_sys->p_timeout->handle, NULL );
vlc_object_detach( p_sys->p_timeout ); free( p_sys->p_timeout );
vlc_object_release( p_sys->p_timeout );
} }
delete p_sys->scheduler; delete p_sys->scheduler;
free( p_sys->p_sdp ); free( p_sys->p_sdp );
...@@ -1042,17 +1040,16 @@ static int Play( demux_t *p_demux ) ...@@ -1042,17 +1040,16 @@ static int Play( demux_t *p_demux )
if( !p_sys->p_timeout && p_sys->b_get_param ) if( !p_sys->p_timeout && p_sys->b_get_param )
{ {
msg_Dbg( p_demux, "We have a timeout of %d seconds", p_sys->i_timeout ); msg_Dbg( p_demux, "We have a timeout of %d seconds", p_sys->i_timeout );
p_sys->p_timeout = (timeout_thread_t *)vlc_object_create( p_demux, sizeof(timeout_thread_t) ); p_sys->p_timeout = (timeout_thread_t *)malloc( sizeof(timeout_thread_t) );
p_sys->p_timeout->p_sys = p_demux->p_sys; /* lol, object recursion :D */ p_sys->p_timeout->p_sys = p_demux->p_sys; /* lol, object recursion :D */
if( vlc_thread_create( p_sys->p_timeout, "liveMedia-timeout", if( vlc_clone( &p_sys->p_timeout->handle, TimeoutPrevention,
TimeoutPrevention, p_sys->p_timeout, VLC_THREAD_PRIORITY_LOW ) )
VLC_THREAD_PRIORITY_LOW, false ) )
{ {
msg_Err( p_demux, "cannot spawn liveMedia timeout thread" ); msg_Err( p_demux, "cannot spawn liveMedia timeout thread" );
vlc_object_release( p_sys->p_timeout ); free( p_sys->p_timeout );
p_sys->p_timeout = NULL;
} }
msg_Dbg( p_demux, "spawned timeout thread" ); msg_Dbg( p_demux, "spawned timeout thread" );
vlc_object_attach( p_sys->p_timeout, p_demux );
} }
} }
p_sys->i_pcr = 0; p_sys->i_pcr = 0;
...@@ -1711,37 +1708,26 @@ static void TaskInterrupt( void *p_private ) ...@@ -1711,37 +1708,26 @@ static void TaskInterrupt( void *p_private )
/***************************************************************************** /*****************************************************************************
* *
*****************************************************************************/ *****************************************************************************/
static void* TimeoutPrevention( vlc_object_t * p_this ) static void* TimeoutPrevention( void *p_data )
{ {
timeout_thread_t *p_timeout = (timeout_thread_t *)p_this; timeout_thread_t *p_timeout = (timeout_thread_t *)p_data;
int64_t i_remain = (int64_t)p_timeout->p_sys->i_timeout - 2;
i_remain *= 1000000; for( ;; )
int canc = vlc_savecancel ();
/* Avoid lock */
while( vlc_object_alive (p_timeout) )
{ {
if( i_remain <= 0 ) /* Voodoo (= no) thread safety here! *Ahem* */
if( p_timeout->b_handle_keep_alive )
{ {
char *psz_bye = NULL; char *psz_bye = NULL;
i_remain = (int64_t)p_timeout->p_sys->i_timeout -2; int canc = vlc_savecancel ();
i_remain *= 1000000;
msg_Dbg( p_timeout, "reset the timeout timer" ); p_timeout->p_sys->rtsp->getMediaSessionParameter( *p_timeout->p_sys->ms, NULL, psz_bye );
if( p_timeout->b_handle_keep_alive == true ) vlc_restorecancel (canc);
{
p_timeout->p_sys->rtsp->getMediaSessionParameter( *p_timeout->p_sys->ms, NULL, psz_bye );
p_timeout->p_sys->b_timeout_call = false;
}
else
{
p_timeout->p_sys->b_timeout_call = true;
}
} }
i_remain -= 200000; p_timeout->p_sys->b_timeout_call = !p_timeout->b_handle_keep_alive;
msleep( 200000 ); /* 200 ms */
msleep (((int64_t)p_timeout->p_sys->i_timeout - 2) * CLOCK_FREQ);
} }
vlc_restorecancel (canc); assert(0); /* dead code */
} }
/***************************************************************************** /*****************************************************************************
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment