Commit 7c7ad3b0 authored by Laurent Aimar's avatar Laurent Aimar

Simplified and fixed mmst/u pausing (close #2673).

parent cdc9281c
...@@ -82,7 +82,8 @@ static int mms_HeaderMediaRead( access_t *, int ); ...@@ -82,7 +82,8 @@ static int mms_HeaderMediaRead( access_t *, int );
static int mms_ReceivePacket( access_t * ); static int mms_ReceivePacket( access_t * );
static void* KeepAliveThread( void * ); static void KeepAliveStart( access_t * );
static void KeepAliveStop( access_t * );
int MMSTUOpen( access_t *p_access ) int MMSTUOpen( access_t *p_access )
{ {
...@@ -179,6 +180,7 @@ int MMSTUOpen( access_t *p_access ) ...@@ -179,6 +180,7 @@ int MMSTUOpen( access_t *p_access )
(uint64_t)p_sys->i_header + (uint64_t)p_sys->i_header +
(uint64_t)p_sys->i_packet_count * (uint64_t)p_sys->i_packet_length; (uint64_t)p_sys->i_packet_count * (uint64_t)p_sys->i_packet_length;
} }
p_sys->b_keep_alive = false;
/* *** Start stream *** */ /* *** Start stream *** */
if( MMSStart( p_access, 0xffffffff ) < 0 ) if( MMSStart( p_access, 0xffffffff ) < 0 )
...@@ -188,26 +190,6 @@ int MMSTUOpen( access_t *p_access ) ...@@ -188,26 +190,6 @@ int MMSTUOpen( access_t *p_access )
return VLC_EGENERIC; return VLC_EGENERIC;
} }
/* Keep the connection alive when paused */
p_sys->p_keepalive = malloc( sizeof( mmstu_keepalive_t ) );
if( !p_sys->p_keepalive )
{
MMSTUClose ( p_access );
return VLC_ENOMEM;
}
p_sys->p_keepalive->p_access = p_access;
vlc_mutex_init( &p_sys->p_keepalive->lock );
vlc_cond_init( &p_sys->p_keepalive->wait );
p_sys->p_keepalive->b_paused = false;
if( vlc_clone( &p_sys->p_keepalive->handle, KeepAliveThread,
p_sys->p_keepalive, VLC_THREAD_PRIORITY_LOW ) )
{
vlc_cond_destroy( &p_sys->p_keepalive->wait );
vlc_mutex_destroy( &p_sys->p_keepalive->lock );
free( p_sys->p_keepalive );
p_sys->p_keepalive = NULL;
}
return VLC_SUCCESS; return VLC_SUCCESS;
} }
...@@ -218,21 +200,13 @@ void MMSTUClose( access_t *p_access ) ...@@ -218,21 +200,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;
if( p_sys->p_keepalive ) KeepAliveStop( p_access );
{
vlc_cancel( p_sys->p_keepalive->handle );
vlc_join( p_sys->p_keepalive->handle, NULL );
vlc_cond_destroy( &p_sys->p_keepalive->wait );
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 );
/* free memory */ /* free memory */
vlc_UrlClean( &p_sys->url ); vlc_UrlClean( &p_sys->url );
vlc_mutex_destroy( &p_sys->lock_netwrite );
free( p_sys ); free( p_sys );
} }
...@@ -295,17 +269,14 @@ static int Control( access_t *p_access, int i_query, va_list args ) ...@@ -295,17 +269,14 @@ 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 );
KeepAliveStart( p_access );
}
else else
Seek( p_access, p_access->info.i_pos );
if( p_sys->p_keepalive )
{ {
vlc_mutex_lock( &p_sys->p_keepalive->lock ); KeepAliveStop( p_access );
p_sys->p_keepalive->b_paused = b_bool; Seek( p_access, p_access->info.i_pos );
if( b_bool )
vlc_cond_signal( &p_sys->p_keepalive->wait );
vlc_mutex_unlock( &p_sys->p_keepalive->lock );
} }
break; break;
...@@ -1018,6 +989,7 @@ static int mms_CommandSend( access_t *p_access, int i_command, ...@@ -1018,6 +989,7 @@ static int mms_CommandSend( access_t *p_access, int i_command,
i_ret = net_Write( p_access, p_sys->i_handle_tcp, NULL, buffer.p_data, i_ret = net_Write( p_access, p_sys->i_handle_tcp, NULL, buffer.p_data,
buffer.i_data - ( 8 - ( i_data - i_data_old ) ) ); buffer.i_data - ( 8 - ( i_data - i_data_old ) ) );
vlc_mutex_unlock( &p_sys->lock_netwrite ); vlc_mutex_unlock( &p_sys->lock_netwrite );
if( i_ret != buffer.i_data - ( 8 - ( i_data - i_data_old ) ) ) if( i_ret != buffer.i_data - ( 8 - ( i_data - i_data_old ) ) )
{ {
var_buffer_free( &buffer ); var_buffer_free( &buffer );
...@@ -1582,38 +1554,42 @@ static int mms_HeaderMediaRead( access_t *p_access, int i_type ) ...@@ -1582,38 +1554,42 @@ static int mms_HeaderMediaRead( access_t *p_access, int i_type )
return -1; return -1;
} }
static void* KeepAliveThread( void *p_data ) static void *KeepAliveThread( void *p_data )
{ {
mmstu_keepalive_t *p_thread = (mmstu_keepalive_t *) p_data; access_t *p_access = p_data;
access_t *p_access = p_thread->p_access;
vlc_mutex_lock( &p_thread->lock );
mutex_cleanup_push( &p_thread->lock );
for( ;; ) for( ;; )
{ {
/* Do nothing until paused (if ever) */ /* Send keep-alive every ten seconds */
while( !p_thread->b_paused ) int canc = vlc_savecancel();
vlc_cond_wait( &p_thread->wait, &p_thread->lock );
do mms_CommandSend( p_access, 0x1b, 0, 0, NULL, 0 );
{
int canc;
/* Send keep-alive every ten seconds */ vlc_restorecancel( canc );
vlc_mutex_unlock( &p_thread->lock );
canc = vlc_savecancel();
mms_CommandSend( p_access, 0x1b, 0, 0, NULL, 0 ); msleep( 10 * CLOCK_FREQ );
}
assert(0);
}
static void KeepAliveStart( access_t *p_access )
{
access_sys_t *p_sys = p_access->p_sys;
if( p_sys->b_keep_alive )
return;
vlc_restorecancel( canc ); p_sys->b_keep_alive = !vlc_clone( &p_sys->keep_alive,
vlc_mutex_lock( &p_thread->lock ); KeepAliveThread, p_access,
VLC_THREAD_PRIORITY_LOW );
}
msleep( 10 * CLOCK_FREQ ); static void KeepAliveStop( access_t *p_access )
} {
while( p_thread->b_paused ); access_sys_t *p_sys = p_access->p_sys;
} if( !p_sys->b_keep_alive )
return;
vlc_cleanup_pop(); vlc_cancel( p_sys->keep_alive );
assert(0); vlc_join( p_sys->keep_alive, NULL );
p_sys->b_keep_alive = false;
} }
...@@ -94,17 +94,9 @@ struct access_sys_t ...@@ -94,17 +94,9 @@ struct access_sys_t
/* misc */ /* misc */
bool b_seekable; bool b_seekable;
vlc_mutex_t lock_netwrite; vlc_mutex_t lock_netwrite;
struct mmstu_keepalive_t *p_keepalive; bool b_keep_alive;
vlc_thread_t keep_alive;
}; };
typedef struct mmstu_keepalive_t
{
access_t *p_access;
vlc_mutex_t lock;
vlc_cond_t wait;
vlc_thread_t handle;
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