Commit bda1fc3c authored by Sébastien Escudier's avatar Sébastien Escudier Committed by Rémi Denis-Courmont

Handle VLM events in libvlc

Signed-off-by: default avatarRémi Denis-Courmont <remi@remlab.net>
parent 0537633a
......@@ -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;
};
......
......@@ -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
......
......@@ -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 );
......
......@@ -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;
......
......@@ -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;
}
......@@ -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
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment