vlc | branch: master | Rémi Denis-Courmont <r...@remlab.net> | Sat Oct 13 20:25:16 2012 +0300| [a508c29e2dbb82d88013dd99cdd5539d5a3f1ff7] | committer: Rémi Denis-Courmont
dbus: simplify input event handling and reduce lock scope > http://git.videolan.org/gitweb.cgi/vlc.git/?a=commit;h=a508c29e2dbb82d88013dd99cdd5539d5a3f1ff7 --- modules/control/dbus/dbus.c | 80 ++++++++++++++++++------------------ modules/control/dbus/dbus_common.h | 5 ++- 2 files changed, 42 insertions(+), 43 deletions(-) diff --git a/modules/control/dbus/dbus.c b/modules/control/dbus/dbus.c index 71cf7d0..b5fd547 100644 --- a/modules/control/dbus/dbus.c +++ b/modules/control/dbus/dbus.c @@ -108,6 +108,7 @@ static void Run ( 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 InputCallback( vlc_object_t*, const char*, vlc_value_t, vlc_value_t, void* ); static dbus_bool_t add_timeout ( DBusTimeout *p_timeout, void *p_data ); static dbus_bool_t add_watch ( DBusWatch *p_watch, void *p_data ); @@ -304,7 +305,7 @@ static void Close ( vlc_object_t *p_this ) 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-seek", AllCallback, p_intf ); vlc_object_release( p_sys->p_input ); @@ -872,30 +873,27 @@ static void wakeup_main_loop( void *p_data ) 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. * - * 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 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 + * @return VLC_SUCCESS on success, VLC_E* on error. */ -static int InputIntfEventCallback( intf_thread_t *p_intf, - input_thread_t *p_input, - const int i_event, - callback_info_t *p_info ) +static int InputCallback( vlc_object_t *p_this, const char *psz_var, + vlc_value_t oldval, vlc_value_t newval, void *data ) { + 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; - 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_ABORT: @@ -922,6 +920,10 @@ static int InputIntfEventCallback( intf_thread_t *p_intf, p_info->signal = SIGNAL_RATE; return VLC_SUCCESS; case INPUT_EVENT_POSITION: + { + mtime_t i_now = mdate(), i_pos, i_projected_pos, i_interval; + float f_current_rate; + /* Detect seeks * XXX: This is way more convoluted than it should be... */ i_pos = var_GetTime( p_input, "time" ); @@ -949,19 +951,30 @@ static int InputIntfEventCallback( intf_thread_t *p_intf, p_info->signal = SIGNAL_SEEK; p_info->i_item = input_GetItem( p_input )->i_id; break; - + } 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 && - 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; } + 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 ); - return p_info->signal ? VLC_SUCCESS : VLC_EGENERIC; + wakeup_main_loop( p_intf ); + + (void)psz_var; + (void)oldval; + return VLC_SUCCESS; } // Get all the callbacks @@ -977,8 +990,6 @@ static int AllCallback( vlc_object_t *p_this, const char *psz_var, if( !info ) return VLC_ENOMEM; - vlc_mutex_lock( &p_intf->p_sys->lock ); - // Wich event is it ? if( !strcmp( "item-current", psz_var ) ) info->signal = SIGNAL_ITEM_CURRENT; @@ -1013,20 +1024,6 @@ static int AllCallback( vlc_object_t *p_this, const char *psz_var, else if( !strcmp( "loop", psz_var ) ) 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 ) ) info->signal = SIGNAL_CAN_SEEK; @@ -1037,6 +1034,7 @@ static int AllCallback( vlc_object_t *p_this, const char *psz_var, assert(0); // Append the event + vlc_mutex_lock( &p_intf->p_sys->lock ); vlc_array_append( p_intf->p_sys->p_events, info ); vlc_mutex_unlock( &p_intf->p_sys->lock ); @@ -1060,7 +1058,7 @@ static int TrackChange( intf_thread_t *p_intf ) 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-seek", AllCallback, p_intf ); vlc_object_release( p_sys->p_input ); @@ -1086,7 +1084,7 @@ static int TrackChange( intf_thread_t *p_intf ) p_sys->b_meta_read = true; 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-seek", AllCallback, p_intf ); diff --git a/modules/control/dbus/dbus_common.h b/modules/control/dbus/dbus_common.h index 30d6e2c..d5d5bb8 100644 --- a/modules/control/dbus/dbus_common.h +++ b/modules/control/dbus/dbus_common.h @@ -101,8 +101,9 @@ struct intf_sys_t int p_pipe_fds[2]; vlc_mutex_t lock; 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 _______________________________________________ vlc-commits mailing list vlc-commits@videolan.org http://mailman.videolan.org/listinfo/vlc-commits