[vlc-devel] commit: Added basic VLM events. (Laurent Aimar )

git version control git at videolan.org
Sun Mar 8 20:29:16 CET 2009


vlc | branch: master | Laurent Aimar <fenrir at videolan.org> | Sun Mar  8 20:25:52 2009 +0100| [3d82199341fe58cf2a451a1f700d0404e31da557] | committer: Laurent Aimar 

Added basic VLM events.

 You need to attach a callback on the variable 'intf-event' of the vlm
object.
 Becarefull, as (always) inside an event callback you cannot call back
the object (here vlm).

> http://git.videolan.org/gitweb.cgi/vlc.git/?a=commit;h=3d82199341fe58cf2a451a1f700d0404e31da557
---

 include/vlc_vlm.h        |   23 +++++++++++++++++++++++
 src/Makefile.am          |    2 ++
 src/input/vlm.c          |   23 +++++++++++++++++++----
 src/input/vlm_internal.h |    1 +
 4 files changed, 45 insertions(+), 4 deletions(-)

diff --git a/include/vlc_vlm.h b/include/vlc_vlm.h
index 4abe29a..4be26ed 100644
--- a/include/vlc_vlm.h
+++ b/include/vlc_vlm.h
@@ -87,6 +87,29 @@ typedef struct
 } vlm_schedule_t
 #endif
 
+/** VLM events
+ * You can catch vlm event by adding a callback on the variable "intf-event"
+ * of the VLM object.
+ * This variable is an address that will hold a vlm_event_t* value.
+ */
+enum vlm_event_type_e
+{
+    /* */
+    VLM_EVENT_MEDIA_ADDED   = 0x100,
+    VLM_EVENT_MEDIA_REMOVED,
+    VLM_EVENT_MEDIA_CHANGED,
+
+    /* */
+    VLM_EVENT_MEDIA_INSTANCE_STARTED    = 0x200,
+    VLM_EVENT_MEDIA_INSTANCE_STOPPED,
+};
+
+typedef struct
+{
+    int     i_type;     /* a vlm_event_type_e value */
+    int64_t id;         /* Media ID */
+} vlm_event_t;
+
 /** VLM control query */
 enum vlm_query_e
 {
diff --git a/src/Makefile.am b/src/Makefile.am
index fbbe92c..32206ec 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -310,6 +310,7 @@ SOURCES_libvlc_common = \
 	input/input_internal.h \
 	input/input_interface.h \
 	input/vlm_internal.h \
+	input/vlm_event.h \
 	input/resource.h \
 	input/resource.c \
 	input/stream.c \
@@ -403,6 +404,7 @@ SOURCES_libvlc_sout = \
 
 SOURCES_libvlc_vlm = \
 	input/vlm.c \
+	input/vlm_event.c \
 	input/vlmshell.c \
 	$(NULL)
 
diff --git a/src/input/vlm.c b/src/input/vlm.c
index 03cad44..d611eb8 100644
--- a/src/input/vlm.c
+++ b/src/input/vlm.c
@@ -52,9 +52,9 @@
 #endif
 
 #include <vlc_input.h>
-#include "input_internal.h"
 #include <vlc_stream.h>
 #include "vlm_internal.h"
+#include "vlm_event.h"
 #include <vlc_vod.h>
 #include <vlc_charset.h>
 #include <vlc_sout.h>
@@ -110,6 +110,7 @@ vlm_t *__vlm_New ( vlc_object_t *p_this )
     TAB_INIT( p_vlm->i_schedule, p_vlm->schedule );
     p_vlm->i_vod = 0;
     p_vlm->p_vod = NULL;
+    var_Create( p_vlm, "intf-event", VLC_VAR_ADDRESS );
     vlc_object_attach( p_vlm, p_this->p_libvlc );
 
     if( vlc_clone( &p_vlm->thread, Manage, p_vlm, VLC_THREAD_PRIORITY_LOW ) )
@@ -574,6 +575,7 @@ static int vlm_OnMediaUpdate( vlm_t *p_vlm, vlm_media_sys_t *p_media )
 
     /* TODO add support of var vlm_media_broadcast/vlm_media_vod */
 
+    vlm_SendEventMediaChanged( p_vlm, p_cfg->id );
     return VLC_SUCCESS;
 }
 static int vlm_ControlMediaChange( vlm_t *p_vlm, vlm_media_t *p_cfg )
@@ -648,6 +650,8 @@ static int vlm_ControlMediaAdd( vlm_t *p_vlm, vlm_media_t *p_cfg, int64_t *p_id
     if( p_id )
         *p_id = p_media->cfg.id;
 
+    /* */
+    vlm_SendEventMediaAdded( p_vlm, p_media->cfg.id );
     return vlm_OnMediaUpdate( p_vlm, p_media );
 }
 
@@ -684,6 +688,9 @@ static int vlm_ControlMediaDel( vlm_t *p_vlm, int64_t id )
         vlc_object_release( p_vlm->p_vod );
         p_vlm->p_vod = NULL;
     }
+
+    /* */
+    vlm_SendEventMediaRemoved( p_vlm, id );
     return VLC_SUCCESS;
 }
 
@@ -763,7 +770,7 @@ static vlm_media_instance_sys_t *vlm_MediaInstanceNew( vlm_t *p_vlm, const char
 
     return p_instance;
 }
-static void vlm_MediaInstanceDelete( vlm_media_instance_sys_t *p_instance )
+static void vlm_MediaInstanceDelete( vlm_t *p_vlm, int64_t id, vlm_media_instance_sys_t *p_instance )
 {
     input_thread_t *p_input = p_instance->p_input;
     if( p_input )
@@ -777,6 +784,8 @@ static void vlm_MediaInstanceDelete( vlm_media_instance_sys_t *p_instance )
         input_resource_Delete( p_resource );
 
         vlc_object_release( p_input );
+
+        vlm_SendEventMediaInstanceStopped( p_vlm, id );
     }
     if( p_instance->p_input_resource )
         input_resource_Delete( p_instance->p_input_resource );
@@ -861,6 +870,8 @@ static int vlm_ControlMediaInstanceStart( vlm_t *p_vlm, int64_t id, const char *
         if( !p_instance->b_sout_keep )
             input_resource_TerminateSout( p_instance->p_input_resource );
         input_resource_TerminateVout( p_instance->p_input_resource );
+
+        vlm_SendEventMediaInstanceStopped( p_vlm, id );
     }
 
     /* Start new one */
@@ -876,7 +887,11 @@ static int vlm_ControlMediaInstanceStart( vlm_t *p_vlm, int64_t id, const char *
         if( !p_instance->p_input )
         {
             TAB_REMOVE( p_media->i_instance, p_media->instance, p_instance );
-            vlm_MediaInstanceDelete( p_instance );
+            vlm_MediaInstanceDelete( p_vlm, id, p_instance );
+        }
+        else
+        {
+            vlm_SendEventMediaInstanceStarted( p_vlm, id );
         }
         free( psz_log );
     }
@@ -898,7 +913,7 @@ static int vlm_ControlMediaInstanceStop( vlm_t *p_vlm, int64_t id, const char *p
 
     TAB_REMOVE( p_media->i_instance, p_media->instance, p_instance );
 
-    vlm_MediaInstanceDelete( p_instance );
+    vlm_MediaInstanceDelete( p_vlm, id, p_instance );
 
     return VLC_SUCCESS;
 }
diff --git a/src/input/vlm_internal.h b/src/input/vlm_internal.h
index 67462f5..a8c72fc 100644
--- a/src/input/vlm_internal.h
+++ b/src/input/vlm_internal.h
@@ -29,6 +29,7 @@
 #define _VLM_INTERNAL_H 1
 
 #include <vlc_vlm.h>
+#include "input_internal.h"
 
 /* Private */
 typedef struct




More information about the vlc-devel mailing list