[vlc-devel] commit: Handle VLM events in libvlc ( Sébastien Escudier )
git version control
git at videolan.org
Tue May 26 17:16:56 CEST 2009
vlc | branch: master | Sébastien Escudier <sebastien-devel at celeos.eu> | Mon May 18 14:17:53 2009 +0200| [bda1fc3c38d7ba0834a671f436aa69e68368da5e] | committer: Rémi Denis-Courmont
Handle VLM events in libvlc
Signed-off-by: Rémi Denis-Courmont <remi at remlab.net>
> http://git.videolan.org/gitweb.cgi/vlc.git/?a=commit;h=bda1fc3c38d7ba0834a671f436aa69e68368da5e
---
include/vlc/libvlc_events.h | 13 +++++++++
include/vlc/libvlc_vlm.h | 13 +++++++++
src/control/core.c | 3 ++
src/control/libvlc_internal.h | 1 +
src/control/vlm.c | 60 ++++++++++++++++++++++++++++++++++++++++-
src/libvlc.sym | 1 +
6 files changed, 90 insertions(+), 1 deletions(-)
diff --git a/include/vlc/libvlc_events.h b/include/vlc/libvlc_events.h
index bf0e3a2..9373896 100644
--- a/include/vlc/libvlc_events.h
+++ b/include/vlc/libvlc_events.h
@@ -93,6 +93,12 @@ enum libvlc_event_type_t {
libvlc_MediaPlayerTitleChanged,
libvlc_MediaPlayerSnapshotTaken,
libvlc_MediaPlayerLengthChanged,
+
+ libvlc_VlmMediaAdded,
+ libvlc_VlmMediaRemoved,
+ libvlc_VlmMediaChanged,
+ libvlc_VlmMediaInstanceStarted,
+ libvlc_VlmMediaInstanceStopped,
/* New event types HERE */
};
@@ -212,6 +218,13 @@ struct libvlc_event_t
{
libvlc_time_t new_length;
} media_player_length_changed;
+
+ /* VLM media */
+ struct
+ {
+ const char * psz_media_name;
+ } vlm_media_event;
+
} u;
};
diff --git a/include/vlc/libvlc_vlm.h b/include/vlc/libvlc_vlm.h
index c3305ba..56a0a46 100644
--- a/include/vlc/libvlc_vlm.h
+++ b/include/vlc/libvlc_vlm.h
@@ -333,6 +333,19 @@ VLC_PUBLIC_API int libvlc_vlm_get_media_instance_seekable( libvlc_instance_t *,
const char *, int,
libvlc_exception_t * );
+/**
+ * Get libvlc_event_manager from a vlm media.
+ * The p_event_manager is immutable, so you don't have to hold the lock
+ *
+ * \param p_instance a libvlc instance
+ * \param psz_name name of vlm media instance
+ * \param p_exception an initialized exception pointer
+ * \return libvlc_event_manager
+ */
+VLC_PUBLIC_API libvlc_event_manager_t *
+ libvlc_vlm_get_event_manager( libvlc_instance_t *,
+ libvlc_exception_t * );
+
/** @} */
# ifdef __cplusplus
diff --git a/src/control/core.c b/src/control/core.c
index 0ac8a3c..eaf2b1b 100644
--- a/src/control/core.c
+++ b/src/control/core.c
@@ -138,6 +138,7 @@ libvlc_instance_t * libvlc_new( int argc, const char *const *argv,
p_new->p_libvlc_int = p_libvlc_int;
p_new->p_vlm = NULL;
+ p_new->p_event_manager = NULL;
p_new->b_playlist_locked = 0;
p_new->ref_count = 1;
p_new->verbosity = 1;
@@ -173,6 +174,8 @@ void libvlc_release( libvlc_instance_t *p_instance )
{
vlc_mutex_destroy( lock );
vlc_mutex_destroy( &p_instance->event_callback_lock );
+ if( p_instance->p_event_manager )
+ libvlc_event_manager_release( p_instance->p_event_manager );
libvlc_InternalCleanup( p_instance->p_libvlc_int );
libvlc_InternalDestroy( p_instance->p_libvlc_int );
free( p_instance );
diff --git a/src/control/libvlc_internal.h b/src/control/libvlc_internal.h
index 392bcce..e37e3db 100644
--- a/src/control/libvlc_internal.h
+++ b/src/control/libvlc_internal.h
@@ -61,6 +61,7 @@ struct libvlc_instance_t
{
libvlc_int_t *p_libvlc_int;
vlm_t *p_vlm;
+ libvlc_event_manager_t *p_event_manager;
int b_playlist_locked;
unsigned ref_count;
int verbosity;
diff --git a/src/control/vlm.c b/src/control/vlm.c
index 30c598c..2942d80 100644
--- a/src/control/vlm.c
+++ b/src/control/vlm.c
@@ -105,13 +105,63 @@ char* libvlc_vlm_show_media( libvlc_instance_t *p_instance,
}
#endif /* 0 */
+/* VLM events callback. Transmit to libvlc */
+static int VlmEvent( vlc_object_t *p_this, const char * name,
+ vlc_value_t old_val, vlc_value_t newval, void *param )
+{
+ vlm_event_t *event = (vlm_event_t*)newval.p_address;
+ libvlc_event_manager_t *p_event_manager = (libvlc_event_manager_t *) param;
+ libvlc_event_t libvlc_event;
+
+ libvlc_event.u.vlm_media_event.psz_media_name = event->psz_name;
+
+ switch( event->i_type )
+ {
+ case VLM_EVENT_MEDIA_ADDED:
+ libvlc_event.type = libvlc_VlmMediaAdded;
+ break;
+ case VLM_EVENT_MEDIA_REMOVED:
+ libvlc_event.type = libvlc_VlmMediaRemoved;
+ break;
+ case VLM_EVENT_MEDIA_CHANGED:
+ libvlc_event.type = libvlc_VlmMediaChanged;
+ break;
+ case VLM_EVENT_MEDIA_INSTANCE_STARTED:
+ libvlc_event.type = libvlc_VlmMediaInstanceStarted;
+ break;
+ case VLM_EVENT_MEDIA_INSTANCE_STOPPED:
+ libvlc_event.type = libvlc_VlmMediaInstanceStopped;
+ break;
+ }
+ libvlc_event_send( p_event_manager, &libvlc_event );
+ return 0;
+}
static int libvlc_vlm_init( libvlc_instance_t *p_instance,
libvlc_exception_t *p_exception )
{
+ if( !p_instance->p_event_manager )
+ {
+ p_instance->p_event_manager = libvlc_event_manager_new( p_instance->p_vlm,
+ p_instance, p_exception );
+ libvlc_event_manager_register_event_type( p_instance->p_event_manager,
+ libvlc_VlmMediaAdded, NULL );
+ libvlc_event_manager_register_event_type( p_instance->p_event_manager,
+ libvlc_VlmMediaRemoved, NULL );
+ libvlc_event_manager_register_event_type( p_instance->p_event_manager,
+ libvlc_VlmMediaChanged, NULL );
+ libvlc_event_manager_register_event_type( p_instance->p_event_manager,
+ libvlc_VlmMediaInstanceStarted, NULL );
+ libvlc_event_manager_register_event_type( p_instance->p_event_manager,
+ libvlc_VlmMediaInstanceStopped, NULL );
+ }
+
if( !p_instance->p_vlm )
+ {
p_instance->p_vlm = vlm_New( p_instance->p_libvlc_int );
-
+ var_AddCallback( (vlc_object_t *)p_instance->p_vlm, "intf-event", VlmEvent,
+ p_instance->p_event_manager );
+ }
if( !p_instance->p_vlm )
{
libvlc_exception_raise( p_exception,
@@ -530,3 +580,11 @@ int libvlc_vlm_get_media_instance_seekable( libvlc_instance_t *p_instance,
vlm_media_instance_Delete( p_mi );
return p_mi ? 0 : -1;
}
+
+libvlc_event_manager_t * libvlc_vlm_get_event_manager( libvlc_instance_t *p_instance,
+ libvlc_exception_t *p_exception )
+{
+ vlm_t *p_vlm;
+ VLM_RET( p_vlm, NULL);
+ return p_instance->p_event_manager;
+}
diff --git a/src/libvlc.sym b/src/libvlc.sym
index c8c489b..e652116 100644
--- a/src/libvlc.sym
+++ b/src/libvlc.sym
@@ -202,6 +202,7 @@ libvlc_vlm_add_vod
libvlc_vlm_add_input
libvlc_vlm_change_media
libvlc_vlm_del_media
+libvlc_vlm_get_event_manager
libvlc_vlm_get_media_instance_chapter
libvlc_vlm_get_media_instance_length
libvlc_vlm_get_media_instance_position
More information about the vlc-devel
mailing list