Commit 9b0414dc authored by Rémi Denis-Courmont's avatar Rémi Denis-Courmont Committed by Jean-Baptiste Kempf

dbus: simplify input event handling and reduce lock scope

(cherry picked from commit a508c29e2dbb82d88013dd99cdd5539d5a3f1ff7)
Signed-off-by: default avatarJean-Baptiste Kempf <jb@videolan.org>
parent 36108d26
...@@ -97,6 +97,7 @@ static void Run ( intf_thread_t * ); ...@@ -97,6 +97,7 @@ static void Run ( intf_thread_t * );
static int TrackChange( intf_thread_t * ); static int TrackChange( intf_thread_t * );
static int AllCallback( vlc_object_t*, const char*, vlc_value_t, vlc_value_t, void* ); static int AllCallback( vlc_object_t*, const char*, vlc_value_t, vlc_value_t, void* );
static int InputCallback( vlc_object_t*, const char*, vlc_value_t, vlc_value_t, void* );
static void dispatch_status_cb( DBusConnection *p_conn, static void dispatch_status_cb( DBusConnection *p_conn,
DBusDispatchStatus i_status, DBusDispatchStatus i_status,
...@@ -288,7 +289,7 @@ static void Close ( vlc_object_t *p_this ) ...@@ -288,7 +289,7 @@ static void Close ( vlc_object_t *p_this )
if( p_sys->p_input ) if( p_sys->p_input )
{ {
var_DelCallback( p_sys->p_input, "intf-event", AllCallback, p_intf ); var_DelCallback( p_sys->p_input, "intf-event", InputCallback, p_intf );
var_DelCallback( p_sys->p_input, "can-pause", AllCallback, p_intf ); var_DelCallback( p_sys->p_input, "can-pause", AllCallback, p_intf );
var_DelCallback( p_sys->p_input, "can-seek", AllCallback, p_intf ); var_DelCallback( p_sys->p_input, "can-seek", AllCallback, p_intf );
vlc_object_release( p_sys->p_input ); vlc_object_release( p_sys->p_input );
...@@ -859,30 +860,27 @@ static void wakeup_main_loop( void *p_data ) ...@@ -859,30 +860,27 @@ static void wakeup_main_loop( void *p_data )
msg_Err( p_intf, "Could not wake up the main loop: %m" ); msg_Err( p_intf, "Could not wake up the main loop: %m" );
} }
/* InputIntfEventCallback() fills a callback_info_t data structure in response /* Flls a callback_info_t data structure in response
* to an "intf-event" input event. * to an "intf-event" input event.
* *
* Caution: This function executes in the input thread * @warning This function executes in the input thread.
* *
* This function must be called with p_sys->lock locked * @return VLC_SUCCESS on success, VLC_E* on error.
*
* @return int VLC_SUCCESS on success, VLC_E* on error
* @param intf_thread_t *p_intf the interface thread
* @param input_thread_t *p_input This input thread
* @param const int i_event input event type
* @param callback_info_t *p_info Location of the callback info to fill
*/ */
static int InputIntfEventCallback( intf_thread_t *p_intf, static int InputCallback( vlc_object_t *p_this, const char *psz_var,
input_thread_t *p_input, vlc_value_t oldval, vlc_value_t newval, void *data )
const int i_event,
callback_info_t *p_info )
{ {
input_thread_t *p_input = (input_thread_t *)p_this;
intf_thread_t *p_intf = data;
intf_sys_t *p_sys = p_intf->p_sys;
dbus_int32_t i_state = PLAYBACK_STATE_INVALID; dbus_int32_t i_state = PLAYBACK_STATE_INVALID;
assert(!p_info->signal);
mtime_t i_now = mdate(), i_pos, i_projected_pos, i_interval;
float f_current_rate;
switch( i_event ) callback_info_t *p_info = calloc( 1, sizeof( callback_info_t ) );
if( unlikely(p_info == NULL) )
return VLC_ENOMEM;
switch( newval.i_int )
{ {
case INPUT_EVENT_DEAD: case INPUT_EVENT_DEAD:
case INPUT_EVENT_ABORT: case INPUT_EVENT_ABORT:
...@@ -909,6 +907,10 @@ static int InputIntfEventCallback( intf_thread_t *p_intf, ...@@ -909,6 +907,10 @@ static int InputIntfEventCallback( intf_thread_t *p_intf,
p_info->signal = SIGNAL_RATE; p_info->signal = SIGNAL_RATE;
break; break;
case INPUT_EVENT_POSITION: case INPUT_EVENT_POSITION:
{
mtime_t i_now = mdate(), i_pos, i_projected_pos, i_interval;
float f_current_rate;
/* Detect seeks /* Detect seeks
* XXX: This is way more convoluted than it should be... */ * XXX: This is way more convoluted than it should be... */
i_pos = var_GetTime( p_input, "time" ); i_pos = var_GetTime( p_input, "time" );
...@@ -936,19 +938,30 @@ static int InputIntfEventCallback( intf_thread_t *p_intf, ...@@ -936,19 +938,30 @@ static int InputIntfEventCallback( intf_thread_t *p_intf,
p_info->signal = SIGNAL_SEEK; p_info->signal = SIGNAL_SEEK;
p_info->i_item = input_GetItem( p_input )->i_id; p_info->i_item = input_GetItem( p_input )->i_id;
break; break;
}
default: default:
return VLC_EGENERIC; free( p_info );
return VLC_SUCCESS; /* don't care */
} }
vlc_mutex_lock( &p_sys->lock );
if( i_state != PLAYBACK_STATE_INVALID && if( i_state != PLAYBACK_STATE_INVALID &&
i_state != p_intf->p_sys->i_playing_state ) i_state != p_sys->i_playing_state )
{ {
p_intf->p_sys->i_playing_state = i_state; p_sys->i_playing_state = i_state;
p_info->signal = SIGNAL_STATE; p_info->signal = SIGNAL_STATE;
} }
if( p_info->signal )
vlc_array_append( p_intf->p_sys->p_events, p_info );
else
free( p_info );
vlc_mutex_unlock( &p_intf->p_sys->lock );
wakeup_main_loop( p_intf );
return p_info->signal ? VLC_SUCCESS : VLC_EGENERIC; (void)psz_var;
(void)oldval;
return VLC_SUCCESS;
} }
// Get all the callbacks // Get all the callbacks
...@@ -964,8 +977,6 @@ static int AllCallback( vlc_object_t *p_this, const char *psz_var, ...@@ -964,8 +977,6 @@ static int AllCallback( vlc_object_t *p_this, const char *psz_var,
if( !info ) if( !info )
return VLC_ENOMEM; return VLC_ENOMEM;
vlc_mutex_lock( &p_intf->p_sys->lock );
// Wich event is it ? // Wich event is it ?
if( !strcmp( "item-current", psz_var ) ) if( !strcmp( "item-current", psz_var ) )
info->signal = SIGNAL_ITEM_CURRENT; info->signal = SIGNAL_ITEM_CURRENT;
...@@ -997,20 +1008,6 @@ static int AllCallback( vlc_object_t *p_this, const char *psz_var, ...@@ -997,20 +1008,6 @@ static int AllCallback( vlc_object_t *p_this, const char *psz_var,
else if( !strcmp( "loop", psz_var ) ) else if( !strcmp( "loop", psz_var ) )
info->signal = SIGNAL_LOOP; info->signal = SIGNAL_LOOP;
else if( !strcmp( "intf-event", psz_var ) )
{
int i_res = InputIntfEventCallback( p_intf,
(input_thread_t*) p_this,
newval.i_int, info );
if( VLC_SUCCESS != i_res )
{
vlc_mutex_unlock( &p_intf->p_sys->lock );
free( info );
return i_res;
}
}
else if( !strcmp( "can-seek", psz_var ) ) else if( !strcmp( "can-seek", psz_var ) )
info->signal = SIGNAL_CAN_SEEK; info->signal = SIGNAL_CAN_SEEK;
...@@ -1021,6 +1018,7 @@ static int AllCallback( vlc_object_t *p_this, const char *psz_var, ...@@ -1021,6 +1018,7 @@ static int AllCallback( vlc_object_t *p_this, const char *psz_var,
assert(0); assert(0);
// Append the event // Append the event
vlc_mutex_lock( &p_intf->p_sys->lock );
vlc_array_append( p_intf->p_sys->p_events, info ); vlc_array_append( p_intf->p_sys->p_events, info );
vlc_mutex_unlock( &p_intf->p_sys->lock ); vlc_mutex_unlock( &p_intf->p_sys->lock );
...@@ -1044,7 +1042,7 @@ static int TrackChange( intf_thread_t *p_intf ) ...@@ -1044,7 +1042,7 @@ static int TrackChange( intf_thread_t *p_intf )
if( p_sys->p_input ) if( p_sys->p_input )
{ {
var_DelCallback( p_sys->p_input, "intf-event", AllCallback, p_intf ); var_DelCallback( p_sys->p_input, "intf-event", InputCallback, p_intf );
var_DelCallback( p_sys->p_input, "can-pause", AllCallback, p_intf ); var_DelCallback( p_sys->p_input, "can-pause", AllCallback, p_intf );
var_DelCallback( p_sys->p_input, "can-seek", AllCallback, p_intf ); var_DelCallback( p_sys->p_input, "can-seek", AllCallback, p_intf );
vlc_object_release( p_sys->p_input ); vlc_object_release( p_sys->p_input );
...@@ -1070,7 +1068,7 @@ static int TrackChange( intf_thread_t *p_intf ) ...@@ -1070,7 +1068,7 @@ static int TrackChange( intf_thread_t *p_intf )
p_sys->b_meta_read = true; p_sys->b_meta_read = true;
p_sys->p_input = p_input; p_sys->p_input = p_input;
var_AddCallback( p_input, "intf-event", AllCallback, p_intf ); var_AddCallback( p_input, "intf-event", InputCallback, p_intf );
var_AddCallback( p_input, "can-pause", AllCallback, p_intf ); var_AddCallback( p_input, "can-pause", AllCallback, p_intf );
var_AddCallback( p_input, "can-seek", AllCallback, p_intf ); var_AddCallback( p_input, "can-seek", AllCallback, p_intf );
......
...@@ -101,8 +101,9 @@ struct intf_sys_t ...@@ -101,8 +101,9 @@ struct intf_sys_t
int p_pipe_fds[2]; int p_pipe_fds[2];
vlc_mutex_t lock; vlc_mutex_t lock;
input_thread_t *p_input; input_thread_t *p_input;
mtime_t i_last_input_pos; /* Only access it from the input thread */
mtime_t i_last_input_pos_event; /* idem */ mtime_t i_last_input_pos; /* Only access from input thread */
mtime_t i_last_input_pos_event; /* Same as above */
}; };
enum enum
......
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