[vlc-devel] [PATCH 7/9] dbus: Move the input "intf-event" handling code to a separate function

Mirsal Ennaime mirsal at mirsal.fr
Tue Feb 8 22:36:02 CET 2011


From: Mirsal Ennaime <mirsal.ennaime at gmail.com>

---
 modules/control/dbus/dbus.c |   62 ++++++++++++++++++++++++++++++++++--------
 1 files changed, 50 insertions(+), 12 deletions(-)

diff --git a/modules/control/dbus/dbus.c b/modules/control/dbus/dbus.c
index 9cda60a..0d5e7e7 100644
--- a/modules/control/dbus/dbus.c
+++ b/modules/control/dbus/dbus.c
@@ -875,6 +875,52 @@ int UpdateCaps( intf_thread_t* p_intf )
     }
 
     return VLC_SUCCESS;
+
+/* InputIntfEventCallback() fills a callback_info_t data structure in response
+ * to an "intf-event" input event.
+ *
+ * Caution: 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
+ */
+static int InputIntfEventCallback( intf_thread_t   *p_intf,
+                                   input_thread_t  *p_input,
+                                   const int        i_event,
+                                   callback_info_t *p_info )
+{
+    dbus_int32_t i_state = PLAYBACK_STATE_INVALID;
+    assert(!p_info->signal);
+
+    switch( i_event )
+    {
+        case INPUT_EVENT_DEAD:
+        case INPUT_EVENT_ABORT:
+            i_state = PLAYBACK_STATE_STOPPED;
+            break;
+        case INPUT_EVENT_STATE:
+            i_state = ( var_GetInteger( p_input, "state" ) == PAUSE_S ) ?
+                PLAYBACK_STATE_PAUSED : PLAYBACK_STATE_PLAYING;
+            break;
+        case INPUT_EVENT_ITEM_META:
+            p_info->signal = SIGNAL_INPUT_METADATA;
+            return VLC_SUCCESS;
+        default:
+            return VLC_EGENERIC;
+    }
+
+    if( i_state != p_intf->p_sys->i_playing_state )
+    {
+        p_intf->p_sys->i_playing_state = i_state;
+        p_info->signal = SIGNAL_STATE;
+    }
+
+    return p_info->signal ? VLC_SUCCESS : VLC_EGENERIC;
 }
 
 // Get all the callbacks
@@ -912,21 +958,13 @@ static int AllCallback( vlc_object_t *p_this, const char *psz_var,
         info->signal = SIGNAL_LOOP;
     else if( !strcmp( "intf-event", psz_var ) )
     {
-        dbus_int32_t state;
-        if( INPUT_EVENT_DEAD == newval.i_int )
-            state = PLAYBACK_STATE_STOPPED;
-        else
-            state = (var_GetInteger(p_this, "state") == PAUSE_S) ?
-                    PLAYBACK_STATE_PAUSED : PLAYBACK_STATE_PLAYING;
-
-        if( state == p_intf->p_sys->i_playing_state )
+        int i_res;
+        i_res = InputIntfEventCallback( p_intf, p_this, newval.i_int, info );
+        if( VLC_SUCCESS != i_res )
         {
             vlc_mutex_unlock( &p_intf->p_sys->lock );
-            return VLC_SUCCESS;
+            return i_res;
         }
-
-        p_intf->p_sys->i_playing_state = state;
-        info->signal = SIGNAL_STATE;
     }
     else
         assert(0);
-- 
1.7.1




More information about the vlc-devel mailing list