libvlc: Rename input to media_instance. And add the possibility to create a medi_inst...
[vlc.git] / src / control / event.c
index 170bc01..d67c148 100644 (file)
  * Private functions
  */
 
+/**************************************************************************
+ *       handle_event (private)
+ *
+ * Callback from the vlc variables
+ **************************************************************************/
 static int handle_event( vlc_object_t *p_this, char const *psz_cmd,
                          vlc_value_t oldval, vlc_value_t newval,
                          void *p_data )
@@ -40,21 +45,34 @@ static int handle_event( vlc_object_t *p_this, char const *psz_cmd,
     struct libvlc_callback_entry_t *entry = p_data;
     libvlc_event_t event;
 
-    event.type = entry->i_event_type;
+    event.type = entry->i_event_type;    
 
-    if (event.type == INPUT_POSITION_CHANGED && !strcmp(psz_cmd, "intf-change"))
+    if (event.type == libvlc_VolumeChanged)
     {
-        input_thread_t * p_input = (input_thread_t *)p_this;
-        vlc_value_t val;
-        var_Get( p_input, "position", &val );
-
-        /* Only send event at a reasonable time precision (500ms) */
-        /* (FIXME: this should be configurable) */
-        if ((val.i_time % I64C(500000)) != 0)
+        if(!strcmp(psz_cmd, "intf-change"))
         {
-            /* Don't send this event */
-            return VLC_SUCCESS;
+            input_thread_t * p_input = (input_thread_t *)p_this;
+            vlc_value_t val;
+            var_Get( p_input, "time", &val );
+
+            /* Only send event at a reasonable time precision (500ms) */
+            /* (FIXME: this should be configurable) */
+            if ((val.i_time % I64C(500000)) != 0)
+            {
+                /* Don't send this event */
+                return VLC_SUCCESS;
+            }
+
+            event.u.input_position_changed.new_position = val.i_time;
         }
+        else
+            event.u.input_position_changed.new_position = newval.i_time;
+
+        event.u.input_position_changed.new_position *= 1000LL;
+    }
+    else if (event.type == libvlc_InputPositionChanged)
+    {
+        event.u.volume_changed.new_volume = newval.i_int;
     }
 
     /* Call the client entry */
@@ -63,23 +81,36 @@ static int handle_event( vlc_object_t *p_this, char const *psz_cmd,
     return VLC_SUCCESS;
 }
 
-/* Utility function: Object should be released by vlc_object_release afterwards */
+/**************************************************************************
+ *       get_input (private) :
+ *
+ * Utility function, Object should be released by vlc_object_release
+ * afterwards
+ **************************************************************************/
 static input_thread_t * get_input(libvlc_instance_t * p_instance)
 {
     libvlc_exception_t p_e_unused; /* FIXME: error checking here */
-    libvlc_input_t * p_libvlc_input = libvlc_playlist_get_input( p_instance, &p_e_unused );
+    libvlc_media_instance_t * p_mi;
     input_thread_t * p_input;
 
-    if( !p_libvlc_input )
+    p_mi = libvlc_playlist_get_media_instance( p_instance, &p_e_unused );
+
+    if( !p_mi )
         return NULL;
-    
-    p_input = libvlc_get_input_thread( p_libvlc_input, &p_e_unused );
 
-    libvlc_input_free(p_libvlc_input);
+    p_input = libvlc_get_input_thread( p_mi, &p_e_unused );
+
+    libvlc_media_instance_destroy( p_mi );
 
     return p_input;
 }
 
+/**************************************************************************
+ *       install_input_event (private) :
+ *
+ * vlc variables callback, used to install input event.
+ * Can be called manually though.
+ **************************************************************************/
 static int install_input_event( vlc_object_t *p_this, char const *psz_cmd,
                                 vlc_value_t oldval, vlc_value_t newval,
                                 void *p_data )
@@ -94,12 +125,12 @@ static int install_input_event( vlc_object_t *p_this, char const *psz_cmd,
 
     for( ; p_listitem ; p_listitem = p_listitem->next )
     {
-        if (p_listitem->elmt->i_event_type == INPUT_POSITION_CHANGED)
+        if (p_listitem->elmt->i_event_type == libvlc_InputPositionChanged)
         {
             /* FIXME: here we shouldn't listen on intf-change, we have to provide
              * in vlc core a more accurate callback */
             var_AddCallback( p_input, "intf-change", handle_event, p_listitem->elmt );
-            var_AddCallback( p_input, "position", handle_event, p_listitem->elmt );
+            var_AddCallback( p_input, "time", handle_event, p_listitem->elmt );
         }
     }
 
@@ -108,6 +139,11 @@ static int install_input_event( vlc_object_t *p_this, char const *psz_cmd,
     return VLC_SUCCESS;
 }
 
+/**************************************************************************
+ *       add_callback_to_list (private) :
+ *
+ * callback list utility function.
+ **************************************************************************/
 static inline void add_callback_to_list( struct libvlc_callback_entry_t *entry,
                                          struct libvlc_callback_entry_list_t **list )
 {
@@ -130,6 +166,11 @@ static inline void add_callback_to_list( struct libvlc_callback_entry_t *entry,
     *list = new_listitem;
 }
 
+/**************************************************************************
+ *       remove_variable_callback (private) :
+ *
+ * Delete the appropriate vlc variables callback for an event.
+ **************************************************************************/
 static int remove_variable_callback( libvlc_instance_t *p_instance, 
                                      struct libvlc_callback_entry_t * p_entry )
 {
@@ -140,17 +181,15 @@ static int remove_variable_callback( libvlc_instance_t *p_instance,
 
     switch ( p_entry->i_event_type )
     {
-        case VOLUME_CHANGED:
+        case libvlc_VolumeChanged:
             res = var_DelCallback( p_instance->p_libvlc_int, "volume-change",
                              handle_event, p_entry );
             break;
-        case INPUT_POSITION_CHANGED:
+        case libvlc_InputPositionChanged:
             /* We may not be deleting the right p_input callback, in this case this
              * will be a no-op */
-            var_DelCallback( p_input, "intf-change",
-                             handle_event, p_entry );
-            var_DelCallback( p_input, "position",
-                             handle_event, p_entry );
+            var_DelCallback( p_input, "intf-change", handle_event, p_entry );
+            var_DelCallback( p_input, "position", handle_event, p_entry );
             break;
     }
     
@@ -163,6 +202,12 @@ static int remove_variable_callback( libvlc_instance_t *p_instance,
 /*
  * Internal libvlc functions
  */
+
+/**************************************************************************
+ *       libvlc_event_init (internal) :
+ *
+ * initialization function.
+ **************************************************************************/
 void libvlc_event_init( libvlc_instance_t *p_instance, libvlc_exception_t *p_e )
 {
     playlist_t *p_playlist = p_instance->p_libvlc_int->p_playlist;
@@ -176,6 +221,11 @@ void libvlc_event_init( libvlc_instance_t *p_instance, libvlc_exception_t *p_e )
                       install_input_event, p_instance );
 }
 
+/**************************************************************************
+ *       libvlc_event_fini (internal) :
+ *
+ * finalization function.
+ **************************************************************************/
 void libvlc_event_fini( libvlc_instance_t *p_instance, libvlc_exception_t *p_e )
 {
     playlist_t *p_playlist = p_instance->p_libvlc_int->p_playlist;
@@ -194,6 +244,11 @@ void libvlc_event_fini( libvlc_instance_t *p_instance, libvlc_exception_t *p_e )
  * Public libvlc functions
  */
 
+/**************************************************************************
+ *       libvlc_event_add_callback (public) :
+ *
+ * Add a callback for an event.
+ **************************************************************************/
 void libvlc_event_add_callback( libvlc_instance_t *p_instance,
                                 libvlc_event_type_t i_event_type,
                                 libvlc_callback_t f_callback,
@@ -221,11 +276,11 @@ void libvlc_event_add_callback( libvlc_instance_t *p_instance,
     
     switch ( i_event_type )
     {
-        case VOLUME_CHANGED:
+        case libvlc_VolumeChanged:
             res = var_AddCallback( p_instance->p_libvlc_int, "volume-change",
                            handle_event, entry );
             break;
-        case INPUT_POSITION_CHANGED:
+        case libvlc_InputPositionChanged:
             install_input_event( NULL, NULL, unused1, unused2, p_instance);
             break;
         default:
@@ -246,26 +301,11 @@ void libvlc_event_add_callback( libvlc_instance_t *p_instance,
     return;
 }
 
-void libvlc_event_remove_all_callbacks( libvlc_instance_t *p_instance,
-                                       libvlc_exception_t *p_e )
-{
-    struct libvlc_callback_entry_list_t *p_listitem;
-
-    vlc_mutex_lock( &p_instance->instance_lock );
-
-    p_listitem = p_instance->p_callback_list;
-
-    while( p_listitem )
-    {
-        remove_variable_callback( p_instance, p_listitem->elmt ); /* FIXME: We could warn on error */
-        p_listitem = p_listitem->next;
-
-    }
-    p_instance->p_callback_list = NULL;
-
-    vlc_mutex_unlock( &p_instance->instance_lock );
-}
-
+/**************************************************************************
+ *       libvlc_event_remove_callback (public) :
+ *
+ * Remove a callback for an event.
+ **************************************************************************/
 void libvlc_event_remove_callback( libvlc_instance_t *p_instance,
                                    libvlc_event_type_t i_event_type,
                                    libvlc_callback_t f_callback,
@@ -306,3 +346,28 @@ void libvlc_event_remove_callback( libvlc_instance_t *p_instance,
     }
     vlc_mutex_unlock( &p_instance->instance_lock );
 }
+
+/**************************************************************************
+ *       libvlc_event_remove_all_callbacks (public) :
+ *
+ * Remove all callbacks for all events.
+ **************************************************************************/
+void libvlc_event_remove_all_callbacks( libvlc_instance_t *p_instance,
+                                       libvlc_exception_t *p_e )
+{
+    struct libvlc_callback_entry_list_t *p_listitem;
+
+    vlc_mutex_lock( &p_instance->instance_lock );
+
+    p_listitem = p_instance->p_callback_list;
+
+    while( p_listitem )
+    {
+        remove_variable_callback( p_instance, p_listitem->elmt ); /* FIXME: We could warn on error */
+        p_listitem = p_listitem->next;
+
+    }
+    p_instance->p_callback_list = NULL;
+
+    vlc_mutex_unlock( &p_instance->instance_lock );
+}