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

MMSTU: suspend the keep-alive thread while not paused

parent 93f09fb2
...@@ -74,7 +74,7 @@ VLC_EXPORT( char *, secstotimestr, ( char *psz_buffer, int secs ) ); ...@@ -74,7 +74,7 @@ VLC_EXPORT( char *, secstotimestr, ( char *psz_buffer, int secs ) );
# else # else
# define VLC_HARD_MIN_SLEEP 0 # define VLC_HARD_MIN_SLEEP 0
# endif # endif
#define VLC_SOFT_MIN_SLEEP 29000000 #define VLC_SOFT_MIN_SLEEP 9000000
static static
__attribute__((unused)) __attribute__((unused))
......
...@@ -33,6 +33,7 @@ ...@@ -33,6 +33,7 @@
#include <vlc_access.h> #include <vlc_access.h>
#include <errno.h> #include <errno.h>
#include <assert.h>
#ifdef HAVE_UNISTD_H #ifdef HAVE_UNISTD_H
# include <unistd.h> # include <unistd.h>
...@@ -92,7 +93,7 @@ static int mms_HeaderMediaRead( access_t *, int ); ...@@ -92,7 +93,7 @@ static int mms_HeaderMediaRead( access_t *, int );
static int mms_ReceivePacket( access_t * ); static int mms_ReceivePacket( access_t * );
static void* KeepAliveThread( vlc_object_t *p_this ); static void* KeepAliveThread( void * );
int MMSTUOpen( access_t *p_access ) int MMSTUOpen( access_t *p_access )
{ {
...@@ -203,13 +204,17 @@ int MMSTUOpen( access_t *p_access ) ...@@ -203,13 +204,17 @@ int MMSTUOpen( access_t *p_access )
} }
/* Keep the connection alive when paused */ /* Keep the connection alive when paused */
p_sys->p_keepalive_thread = vlc_object_create( p_access, sizeof( mmstu_keepalive_thread_t ) ); p_sys->p_keepalive = malloc( sizeof( mmstu_keepalive_t ) );
p_sys->p_keepalive_thread->p_access = p_access; p_sys->p_keepalive->p_access = p_access;
p_sys->p_keepalive_thread->b_paused = false; vlc_mutex_init( &p_sys->p_keepalive->lock );
p_sys->p_keepalive_thread->b_thread_error = false; p_sys->p_keepalive->b_paused = false;
if( vlc_thread_create( p_sys->p_keepalive_thread, "mmstu keepalive thread", KeepAliveThread, if( vlc_clone( &p_sys->p_keepalive->handle, KeepAliveThread,
VLC_THREAD_PRIORITY_LOW, false) ) p_sys->p_keepalive, VLC_THREAD_PRIORITY_LOW ) )
p_sys->p_keepalive_thread->b_thread_error = true; {
vlc_mutex_destroy( &p_sys->p_keepalive->lock );
free( p_sys->p_keepalive );
p_sys->p_keepalive = NULL;
}
return VLC_SUCCESS; return VLC_SUCCESS;
} }
...@@ -221,10 +226,13 @@ void MMSTUClose( access_t *p_access ) ...@@ -221,10 +226,13 @@ void MMSTUClose( access_t *p_access )
{ {
access_sys_t *p_sys = p_access->p_sys; access_sys_t *p_sys = p_access->p_sys;
vlc_object_kill( p_sys->p_keepalive_thread ); if( p_sys->p_keepalive )
if( !p_sys->p_keepalive_thread->b_thread_error ) {
vlc_thread_join( p_sys->p_keepalive_thread ); vlc_cancel( p_sys->p_keepalive->handle );
vlc_object_release( p_sys->p_keepalive_thread ); vlc_join( p_sys->p_keepalive->handle, NULL );
vlc_mutex_destroy( &p_sys->p_keepalive->lock );
free( p_sys->p_keepalive );
}
/* close connection with server */ /* close connection with server */
MMSClose( p_access ); MMSClose( p_access );
...@@ -302,19 +310,15 @@ static int Control( access_t *p_access, int i_query, va_list args ) ...@@ -302,19 +310,15 @@ static int Control( access_t *p_access, int i_query, va_list args )
case ACCESS_SET_PAUSE_STATE: case ACCESS_SET_PAUSE_STATE:
b_bool = (bool)va_arg( args, int ); b_bool = (bool)va_arg( args, int );
if( b_bool ) if( b_bool )
{
MMSStop( p_access ); MMSStop( p_access );
vlc_object_lock( p_sys->p_keepalive_thread );
p_sys->p_keepalive_thread->b_paused = true;
vlc_object_unlock( p_sys->p_keepalive_thread );
}
else else
{
Seek( p_access, p_access->info.i_pos ); Seek( p_access, p_access->info.i_pos );
vlc_object_lock( p_sys->p_keepalive_thread );
p_sys->p_keepalive_thread->b_paused = false; vlc_mutex_lock( &p_sys->p_keepalive->lock );
vlc_object_unlock( p_sys->p_keepalive_thread ); p_sys->p_keepalive->b_paused = b_bool;
} if( b_bool )
vlc_cond_signal( &p_sys->p_keepalive->wait );
vlc_mutex_unlock( &p_sys->p_keepalive->lock );
break; break;
case ACCESS_GET_TITLE_INFO: case ACCESS_GET_TITLE_INFO:
...@@ -1599,26 +1603,38 @@ static int mms_HeaderMediaRead( access_t *p_access, int i_type ) ...@@ -1599,26 +1603,38 @@ static int mms_HeaderMediaRead( access_t *p_access, int i_type )
return -1; return -1;
} }
static void* KeepAliveThread( vlc_object_t *p_this ) static void* KeepAliveThread( void *p_data )
{ {
mmstu_keepalive_thread_t *p_thread = (mmstu_keepalive_thread_t *) p_this; mmstu_keepalive_t *p_thread = (mmstu_keepalive_t *) p_data;
access_t *p_access = p_thread->p_access; access_t *p_access = p_thread->p_access;
bool b_paused;
bool b_was_paused = false;
vlc_object_lock( p_thread ); vlc_mutex_lock( &p_thread->lock );
while( vlc_object_alive( p_thread) ) mutex_cleanup_push( &p_thread->lock );
for( ;; )
{ {
int canc = vlc_savecancel (); /* Do nothing until paused (if ever) */
b_paused = p_thread->b_paused; while( !p_thread->b_paused )
vlc_cond_wait( &p_thread->wait, &p_thread->lock );
if( b_paused && b_was_paused ) do
mms_CommandSend( p_access, 0x1b, 0, 0, NULL, 0 ); {
int canc;
/* Send keep-alive every ten seconds */
vlc_mutex_unlock( &p_thread->lock );
canc = vlc_savecancel();
b_was_paused = b_paused; mms_CommandSend( p_access, 0x1b, 0, 0, NULL, 0 );
vlc_object_timedwait( p_thread, mdate() + 10000000 );
vlc_restorecancel (canc); vlc_restorecancel( canc );
vlc_mutex_lock( &p_thread->lock );
msleep( 10 * CLOCK_FREQ );
}
while( p_thread->b_paused );
} }
vlc_object_unlock( p_thread );
return NULL; vlc_cleanup_pop();
assert(0);
} }
...@@ -34,8 +34,6 @@ ...@@ -34,8 +34,6 @@
#define MMS_BUFFER_SIZE 100000 #define MMS_BUFFER_SIZE 100000
typedef struct mmstu_keepalive_thread_t mmstu_keepalive_thread_t;
struct access_sys_t struct access_sys_t
{ {
int i_proto; /* MMS_PROTO_TCP, MMS_PROTO_UDP */ int i_proto; /* MMS_PROTO_TCP, MMS_PROTO_UDP */
...@@ -96,17 +94,17 @@ struct access_sys_t ...@@ -96,17 +94,17 @@ struct access_sys_t
/* misc */ /* misc */
bool b_seekable; bool b_seekable;
mmstu_keepalive_thread_t *p_keepalive_thread;
vlc_mutex_t lock_netwrite; vlc_mutex_t lock_netwrite;
struct mmstu_keepalive_t *p_keepalive;
}; };
struct mmstu_keepalive_thread_t typedef struct mmstu_keepalive_t
{ {
VLC_COMMON_MEMBERS access_t *p_access;
vlc_mutex_t lock;
access_t *p_access; vlc_cond_t wait;
bool b_paused; vlc_thread_t handle;
bool b_thread_error; bool b_paused;
}; } mmstu_keepalive_t;
#endif #endif
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