[vlc-commits] dbus: simplify input event handling and reduce lock scope
Rémi Denis-Courmont
git at videolan.org
Mon Mar 11 19:00:18 CET 2013
vlc/vlc-2.0 | branch: master | Rémi Denis-Courmont <remi at remlab.net> | Sat Oct 13 20:25:16 2012 +0300| [9b0414dc7f5c18ff2951175cf076779c444efd70] | committer: Jean-Baptiste Kempf
dbus: simplify input event handling and reduce lock scope
(cherry picked from commit a508c29e2dbb82d88013dd99cdd5539d5a3f1ff7)
Signed-off-by: Jean-Baptiste Kempf <jb at videolan.org>
> http://git.videolan.org/gitweb.cgi/vlc/vlc-2.0.git/?a=commit;h=9b0414dc7f5c18ff2951175cf076779c444efd70
---
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 4958f98..0ed15c2 100644
--- a/modules/control/dbus/dbus.c
+++ b/modules/control/dbus/dbus.c
@@ -97,6 +97,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 void dispatch_status_cb( DBusConnection *p_conn,
DBusDispatchStatus i_status,
@@ -288,7 +289,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 );
@@ -859,30 +860,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:
@@ -909,6 +907,10 @@ static int InputIntfEventCallback( intf_thread_t *p_intf,
p_info->signal = SIGNAL_RATE;
break;
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" );
@@ -936,19 +938,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
@@ -964,8 +977,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;
@@ -997,20 +1008,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;
@@ -1021,6 +1018,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 );
@@ -1044,7 +1042,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 );
@@ -1070,7 +1068,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 dd1f011..c494af0 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
More information about the vlc-commits
mailing list