Commit 710ad7ed authored by Felix Abecassis's avatar Felix Abecassis

libvlc: add 3 libvlc events: MediaPlayerESAdded, MediaPlayerESDeleted, MediaPlayerESSelected

parent ad24c4fb
...@@ -74,6 +74,9 @@ enum libvlc_event_e { ...@@ -74,6 +74,9 @@ enum libvlc_event_e {
libvlc_MediaPlayerLengthChanged, libvlc_MediaPlayerLengthChanged,
libvlc_MediaPlayerVout, libvlc_MediaPlayerVout,
libvlc_MediaPlayerScrambledChanged, libvlc_MediaPlayerScrambledChanged,
libvlc_MediaPlayerESAdded,
libvlc_MediaPlayerESDeleted,
libvlc_MediaPlayerESSelected,
libvlc_MediaListItemAdded=0x200, libvlc_MediaListItemAdded=0x200,
libvlc_MediaListWillAddItem, libvlc_MediaListWillAddItem,
...@@ -230,6 +233,12 @@ typedef struct libvlc_event_t ...@@ -230,6 +233,12 @@ typedef struct libvlc_event_t
{ {
libvlc_media_t * new_media; libvlc_media_t * new_media;
} media_player_media_changed; } media_player_media_changed;
struct
{
libvlc_track_type_t i_type;
int i_id;
} media_player_es_changed;
} u; /**< Type-dependent event description */ } u; /**< Type-dependent event description */
} libvlc_event_t; } libvlc_event_t;
......
...@@ -281,6 +281,9 @@ static const event_name_t event_list[] = { ...@@ -281,6 +281,9 @@ static const event_name_t event_list[] = {
DEF(MediaPlayerLengthChanged) DEF(MediaPlayerLengthChanged)
DEF(MediaPlayerVout) DEF(MediaPlayerVout)
DEF(MediaPlayerScrambledChanged) DEF(MediaPlayerScrambledChanged)
DEF(MediaPlayerESAdded)
DEF(MediaPlayerESDeleted)
DEF(MediaPlayerESSelected)
DEF(MediaListItemAdded) DEF(MediaListItemAdded)
DEF(MediaListWillAddItem) DEF(MediaListWillAddItem)
......
...@@ -57,6 +57,22 @@ input_event_changed( vlc_object_t * p_this, char const * psz_cmd, ...@@ -57,6 +57,22 @@ input_event_changed( vlc_object_t * p_this, char const * psz_cmd,
vlc_value_t oldval, vlc_value_t newval, vlc_value_t oldval, vlc_value_t newval,
void * p_userdata ); void * p_userdata );
static int
input_es_changed( vlc_object_t * p_this, char const * psz_cmd,
int action, vlc_value_t *p_val,
void *p_userdata);
static int
input_es_selected( vlc_object_t * p_this, char const * psz_cmd,
vlc_value_t oldval, vlc_value_t newval,
void * p_userdata );
static void
add_es_callbacks( input_thread_t *p_input_thread, libvlc_media_player_t *p_mi );
static void
del_es_callbacks( input_thread_t *p_input_thread, libvlc_media_player_t *p_mi );
static int static int
snapshot_was_taken( vlc_object_t *p_this, char const *psz_cmd, snapshot_was_taken( vlc_object_t *p_this, char const *psz_cmd,
vlc_value_t oldval, vlc_value_t newval, void *p_data ); vlc_value_t oldval, vlc_value_t newval, void *p_data );
...@@ -125,6 +141,7 @@ static void release_input_thread( libvlc_media_player_t *p_mi, bool b_input_abor ...@@ -125,6 +141,7 @@ static void release_input_thread( libvlc_media_player_t *p_mi, bool b_input_abor
input_scrambled_changed, p_mi ); input_scrambled_changed, p_mi );
var_DelCallback( p_input_thread, "intf-event", var_DelCallback( p_input_thread, "intf-event",
input_event_changed, p_mi ); input_event_changed, p_mi );
del_es_callbacks( p_input_thread, p_mi );
/* We owned this one */ /* We owned this one */
input_Stop( p_input_thread, b_input_abort ); input_Stop( p_input_thread, b_input_abort );
...@@ -347,6 +364,85 @@ input_event_changed( vlc_object_t * p_this, char const * psz_cmd, ...@@ -347,6 +364,85 @@ input_event_changed( vlc_object_t * p_this, char const * psz_cmd,
return VLC_SUCCESS; return VLC_SUCCESS;
} }
static int track_type_from_name(const char *psz_name)
{
if( !strcmp( psz_name, "video-es" ) )
return libvlc_track_video;
else if( !strcmp( psz_name, "audio-es" ) )
return libvlc_track_audio;
else if( !strcmp( psz_name, "spu-es" ) )
return libvlc_track_text;
else
return libvlc_track_unknown;
}
static int input_es_changed( vlc_object_t *p_this,
char const *psz_cmd,
int action,
vlc_value_t *p_val,
void *p_userdata )
{
VLC_UNUSED(p_this);
libvlc_media_player_t *mp = p_userdata;
libvlc_event_t event;
/* Ignore the "Disable" element */
if (p_val && p_val->i_int < 0)
return VLC_EGENERIC;
switch (action)
{
case VLC_VAR_ADDCHOICE:
event.type = libvlc_MediaPlayerESAdded;
break;
case VLC_VAR_DELCHOICE:
case VLC_VAR_CLEARCHOICES:
event.type = libvlc_MediaPlayerESDeleted;
break;
default:
return VLC_EGENERIC;
}
event.u.media_player_es_changed.i_type = track_type_from_name(psz_cmd);
int i_id;
if (action != VLC_VAR_CLEARCHOICES)
{
if (!p_val)
return VLC_EGENERIC;
i_id = p_val->i_int;
}
else
{
/* -1 means all ES tracks of this type were deleted. */
i_id = -1;
}
event.u.media_player_es_changed.i_id = i_id;
libvlc_event_send(mp->p_event_manager, &event);
return VLC_SUCCESS;
}
static int
input_es_selected( vlc_object_t * p_this, char const * psz_cmd,
vlc_value_t oldval, vlc_value_t newval,
void * p_userdata )
{
VLC_UNUSED(p_this);
VLC_UNUSED(oldval);
libvlc_media_player_t *mp = p_userdata;
libvlc_event_t event;
event.type = libvlc_MediaPlayerESSelected;
event.u.media_player_es_changed.i_type = track_type_from_name(psz_cmd);
event.u.media_player_es_changed.i_id = newval.i_int;
libvlc_event_send(mp->p_event_manager, &event);
return VLC_SUCCESS;
}
/************************************************************************** /**************************************************************************
* Snapshot Taken Event. * Snapshot Taken Event.
* *
...@@ -538,6 +634,9 @@ libvlc_media_player_new( libvlc_instance_t *instance ) ...@@ -538,6 +634,9 @@ libvlc_media_player_new( libvlc_instance_t *instance )
register_event(mp, Vout); register_event(mp, Vout);
register_event(mp, ScrambledChanged); register_event(mp, ScrambledChanged);
register_event(mp, ESAdded);
register_event(mp, ESDeleted);
register_event(mp, ESSelected);
/* Snapshot initialization */ /* Snapshot initialization */
register_event(mp, SnapshotTaken); register_event(mp, SnapshotTaken);
...@@ -710,6 +809,26 @@ libvlc_media_player_event_manager( libvlc_media_player_t *p_mi ) ...@@ -710,6 +809,26 @@ libvlc_media_player_event_manager( libvlc_media_player_t *p_mi )
return p_mi->p_event_manager; return p_mi->p_event_manager;
} }
static void add_es_callbacks( input_thread_t *p_input_thread, libvlc_media_player_t *p_mi )
{
var_AddListCallback( p_input_thread, "video-es", input_es_changed, p_mi );
var_AddListCallback( p_input_thread, "audio-es", input_es_changed, p_mi );
var_AddListCallback( p_input_thread, "spu-es", input_es_changed, p_mi );
var_AddCallback( p_input_thread, "video-es", input_es_selected, p_mi );
var_AddCallback( p_input_thread, "audio-es", input_es_selected, p_mi );
var_AddCallback( p_input_thread, "spu-es", input_es_selected, p_mi );
}
static void del_es_callbacks( input_thread_t *p_input_thread, libvlc_media_player_t *p_mi )
{
var_DelListCallback( p_input_thread, "video-es", input_es_changed, p_mi );
var_DelListCallback( p_input_thread, "audio-es", input_es_changed, p_mi );
var_DelListCallback( p_input_thread, "spu-es", input_es_changed, p_mi );
var_DelCallback( p_input_thread, "video-es", input_es_selected, p_mi );
var_DelCallback( p_input_thread, "audio-es", input_es_selected, p_mi );
var_DelCallback( p_input_thread, "spu-es", input_es_selected, p_mi );
}
/************************************************************************** /**************************************************************************
* Tell media player to start playing. * Tell media player to start playing.
**************************************************************************/ **************************************************************************/
...@@ -751,10 +870,12 @@ int libvlc_media_player_play( libvlc_media_player_t *p_mi ) ...@@ -751,10 +870,12 @@ int libvlc_media_player_play( libvlc_media_player_t *p_mi )
var_AddCallback( p_input_thread, "can-pause", input_pausable_changed, p_mi ); var_AddCallback( p_input_thread, "can-pause", input_pausable_changed, p_mi );
var_AddCallback( p_input_thread, "program-scrambled", input_scrambled_changed, p_mi ); var_AddCallback( p_input_thread, "program-scrambled", input_scrambled_changed, p_mi );
var_AddCallback( p_input_thread, "intf-event", input_event_changed, p_mi ); var_AddCallback( p_input_thread, "intf-event", input_event_changed, p_mi );
add_es_callbacks( p_input_thread, p_mi );
if( input_Start( p_input_thread ) ) if( input_Start( p_input_thread ) )
{ {
unlock_input(p_mi); unlock_input(p_mi);
del_es_callbacks( p_input_thread, p_mi );
var_DelCallback( p_input_thread, "intf-event", input_event_changed, p_mi ); var_DelCallback( p_input_thread, "intf-event", input_event_changed, p_mi );
var_DelCallback( p_input_thread, "can-pause", input_pausable_changed, p_mi ); var_DelCallback( p_input_thread, "can-pause", input_pausable_changed, p_mi );
var_DelCallback( p_input_thread, "program-scrambled", input_scrambled_changed, p_mi ); var_DelCallback( p_input_thread, "program-scrambled", input_scrambled_changed, p_mi );
......
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