]> git.sesse.net Git - vlc/commitdiff
control/media_instance.c: Support libvlc_MediaInstanceReachedEnd event for upcoming...
authorPierre d'Herbemont <pdherbemont@videolan.org>
Tue, 7 Aug 2007 23:51:17 +0000 (23:51 +0000)
committerPierre d'Herbemont <pdherbemont@videolan.org>
Tue, 7 Aug 2007 23:51:17 +0000 (23:51 +0000)
include/vlc/libvlc.h
include/vlc/libvlc_structures.h
src/control/media_instance.c

index 628633bb6fe31d7d5595c9820b0f13679f683eab..fcc5df7e1009116dfd1a08a15fc290586133db8d 100644 (file)
@@ -333,11 +333,13 @@ VLC_PUBLIC_API void libvlc_media_instance_set_media_descriptor( libvlc_media_ins
 /** Get the media descriptor used by the media_instance (if any). A copy of
  * the md is returned. NULL is returned if no media instance is associated.
  * \param p_mi the Media Instance 
- * \param p_md the Media Descriptor. Afterwards the p_md can safely be
- * destroyed.
  */
 VLC_PUBLIC_API libvlc_media_descriptor_t * libvlc_media_instance_get_media_descriptor( libvlc_media_instance_t *, libvlc_exception_t * );
 
+/** Get the Event Manager from which the media instance send event.
+ * \param p_mi the Media Instance 
+ */
+VLC_PUBLIC_API libvlc_event_manager_t * libvlc_media_instance_event_manager ( libvlc_media_instance_t *, libvlc_exception_t * );
 
 VLC_PUBLIC_API void libvlc_media_instance_play ( libvlc_media_instance_t *, libvlc_exception_t * );
 VLC_PUBLIC_API void libvlc_media_instance_pause ( libvlc_media_instance_t *, libvlc_exception_t * );
index ce63b143c44337f02c61c1e91998c5a795258676..a31e2cadf13323efa1127676a61a0b6841966180 100644 (file)
@@ -183,13 +183,11 @@ typedef struct libvlc_log_message_t
     
 /**
  * Available events: (XXX: being reworked)
- * - libvlc_VolumeChanged
- * - libvlc_InputPositionChanged
+ * - libvlc_MediaInstanceReachedEnd
  */
 
 typedef enum libvlc_event_type_t {
-    libvlc_VolumeChanged,
-    libvlc_InputPositionChanged,
+    libvlc_MediaInstanceReachedEnd,
 } libvlc_event_type_t;
 
 /**
@@ -208,11 +206,7 @@ typedef struct libvlc_event_t
         struct
         {
             int new_volume;
-        } volume_changed;
-        struct
-        {
-            vlc_int64_t new_position;
-        } input_position_changed;
+        } volume_changed; /* Scheduled for deletion */
     } u;
 } libvlc_event_t;
 
index 9364811b778fcf5283df66866ea482cddd03c679..9e664616b4d5ec0d9e3e069d23fc5189851cfbfa 100644 (file)
@@ -101,6 +101,33 @@ input_thread_t *libvlc_get_input_thread( libvlc_media_instance_t *p_mi,
     return p_input_thread;
 }
 
+/*
+ * input_state_changed (Private) (input var "state" Callback)
+ */
+static int
+input_state_changed( vlc_object_t * p_this, char const * psz_cmd,
+                     vlc_value_t oldval, vlc_value_t newval,
+                     void * p_userdata )
+{
+    libvlc_media_instance_t * p_mi = p_userdata;
+    libvlc_event_t event;
+
+    if( newval.i_int == oldval.i_int )
+        return VLC_SUCCESS; /* No change since last time, don't propagate */
+
+    switch ( newval.i_int )
+    {
+        case END_S:
+            event.type = libvlc_MediaInstanceReachedEnd;
+            break;
+        default:
+            return VLC_SUCCESS;
+    }
+
+    libvlc_event_send( p_mi->p_event_manager, &event );
+    return VLC_SUCCESS;
+}
+
 /**************************************************************************
  * Create a Media Instance object
  **************************************************************************/
@@ -132,6 +159,16 @@ libvlc_media_instance_new( libvlc_instance_t * p_libvlc_instance,
      * - Lock when attempting to destroy the object the lock is also held */
     vlc_mutex_init( p_mi->p_libvlc_instance->p_libvlc_int,
                     &p_mi->object_lock );
+    p_mi->p_event_manager = libvlc_event_manager_new( p_mi,
+            p_libvlc_instance, p_e );
+    if( libvlc_exception_raised( p_e ) )
+    {
+        free( p_mi );
+        return NULL;
+    }
+    
+    libvlc_event_manager_register_event_type( p_mi->p_event_manager,
+            libvlc_MediaInstanceReachedEnd, p_e );
 
     return p_mi;
 }
@@ -217,6 +254,7 @@ void libvlc_media_instance_destroy( libvlc_media_instance_t *p_mi )
 
     if( libvlc_exception_raised( &p_e ) )
     {
+        libvlc_event_manager_release( p_mi->p_event_manager );
         free( p_mi );
         return; /* no need to worry about no input thread */
     }
@@ -249,6 +287,8 @@ void libvlc_media_instance_release( libvlc_media_instance_t *p_mi )
     if( p_mi->i_refcount > 0 )
         return;
 
+    libvlc_event_manager_release( p_mi->p_event_manager );
+    
     release_input_thread( p_mi );
 
     libvlc_media_descriptor_destroy( p_mi->p_md );
@@ -292,7 +332,7 @@ void libvlc_media_instance_set_media_descriptor(
 }
 
 /**************************************************************************
- * Set the Media descriptor associated with the instance
+ * Get the Media descriptor associated with the instance
  **************************************************************************/
 libvlc_media_descriptor_t *
 libvlc_media_instance_get_media_descriptor(
@@ -307,6 +347,22 @@ libvlc_media_instance_get_media_descriptor(
     return libvlc_media_descriptor_duplicate( p_mi->p_md );
 }
 
+/**************************************************************************
+ * Get the event Manager
+ **************************************************************************/
+libvlc_event_manager_t *
+libvlc_media_instance_event_manager(
+                            libvlc_media_instance_t *p_mi,
+                            libvlc_exception_t *p_e )
+{
+    (void)p_e;
+
+    if( !p_mi->p_md )
+        return NULL;
+
+    return p_mi->p_event_manager;
+}
+
 /**************************************************************************
  * Play
  **************************************************************************/