Commit 48f7ca7f authored by Pierre d'Herbemont's avatar Pierre d'Herbemont

control/media_instance.c:

* Implement MediaInstancePositionChanged and MediaInstanceTimeChanged accurately.
control/event.c:
* Register the all event types.
* Don't strdup() in libvlc_event_type_name().
parent 8a7b94a1
...@@ -305,6 +305,7 @@ typedef enum libvlc_event_type_t { ...@@ -305,6 +305,7 @@ typedef enum libvlc_event_type_t {
libvlc_MediaInstancePlayed, libvlc_MediaInstancePlayed,
libvlc_MediaInstancePaused, libvlc_MediaInstancePaused,
libvlc_MediaInstanceReachedEnd, libvlc_MediaInstanceReachedEnd,
libvlc_MediaInstanceTimeChanged,
libvlc_MediaInstancePositionChanged, libvlc_MediaInstancePositionChanged,
libvlc_MediaListItemAdded, libvlc_MediaListItemAdded,
...@@ -368,8 +369,12 @@ typedef struct libvlc_event_t ...@@ -368,8 +369,12 @@ typedef struct libvlc_event_t
/* media instance */ /* media instance */
struct struct
{ {
long int new_position; float new_position;
} media_instance_position_changed; } media_instance_position_changed;
struct
{
long int new_time;
} media_instance_time_changed;
/* media list */ /* media list */
struct struct
...@@ -414,7 +419,8 @@ typedef struct libvlc_event_t ...@@ -414,7 +419,8 @@ typedef struct libvlc_event_t
libvlc_media_descriptor_t * item; libvlc_media_descriptor_t * item;
int index; int index;
} media_list_view_will_delete_item; } media_list_view_will_delete_item;
/* media list view */
/* media discoverer */
struct struct
{ {
void * unused; void * unused;
......
...@@ -213,10 +213,12 @@ static const char * event_type_to_name[] = ...@@ -213,10 +213,12 @@ static const char * event_type_to_name[] =
EVENT(libvlc_MediaDescriptorDurationChanged), EVENT(libvlc_MediaDescriptorDurationChanged),
EVENT(libvlc_MediaDescriptorPreparsedChanged), EVENT(libvlc_MediaDescriptorPreparsedChanged),
EVENT(libvlc_MediaDescriptorFreed), EVENT(libvlc_MediaDescriptorFreed),
EVENT(libvlc_MediaDescriptorStateChanged),
EVENT(libvlc_MediaInstancePlayed), EVENT(libvlc_MediaInstancePlayed),
EVENT(libvlc_MediaInstancePaused), EVENT(libvlc_MediaInstancePaused),
EVENT(libvlc_MediaInstanceReachedEnd), EVENT(libvlc_MediaInstanceReachedEnd),
EVENT(libvlc_MediaInstanceTimeChanged),
EVENT(libvlc_MediaInstancePositionChanged), EVENT(libvlc_MediaInstancePositionChanged),
EVENT(libvlc_MediaListItemAdded), EVENT(libvlc_MediaListItemAdded),
...@@ -231,7 +233,10 @@ static const char * event_type_to_name[] = ...@@ -231,7 +233,10 @@ static const char * event_type_to_name[] =
EVENT(libvlc_MediaListPlayerPlayed), EVENT(libvlc_MediaListPlayerPlayed),
EVENT(libvlc_MediaListPlayerNextItemSet), EVENT(libvlc_MediaListPlayerNextItemSet),
EVENT(libvlc_MediaListPlayerStopped) EVENT(libvlc_MediaListPlayerStopped),
EVENT(libvlc_MediaDiscovererStarted),
EVENT(libvlc_MediaDiscovererEnded)
#undef EVENT #undef EVENT
}; };
static const char * unkwown_event_name = "Unknown Event"; static const char * unkwown_event_name = "Unknown Event";
...@@ -240,7 +245,7 @@ const char * libvlc_event_type_name( libvlc_event_type_t event_type ) ...@@ -240,7 +245,7 @@ const char * libvlc_event_type_name( libvlc_event_type_t event_type )
{ {
if( event_type >= sizeof(event_type_to_name)/sizeof(event_type_to_name[0])) if( event_type >= sizeof(event_type_to_name)/sizeof(event_type_to_name[0]))
return unkwown_event_name; return unkwown_event_name;
return strdup(event_type_to_name[event_type]); return event_type_to_name[event_type];
} }
/************************************************************************** /**************************************************************************
......
...@@ -132,7 +132,6 @@ input_state_changed( vlc_object_t * p_this, char const * psz_cmd, ...@@ -132,7 +132,6 @@ input_state_changed( vlc_object_t * p_this, char const * psz_cmd,
libvlc_media_instance_t * p_mi = p_userdata; libvlc_media_instance_t * p_mi = p_userdata;
libvlc_event_t event; libvlc_event_t event;
printf("input_state_changed!!!!!!!!\n");
if( newval.i_int == oldval.i_int ) if( newval.i_int == oldval.i_int )
return VLC_SUCCESS; /* No change since last time, don't propagate */ return VLC_SUCCESS; /* No change since last time, don't propagate */
...@@ -147,7 +146,6 @@ input_state_changed( vlc_object_t * p_this, char const * psz_cmd, ...@@ -147,7 +146,6 @@ input_state_changed( vlc_object_t * p_this, char const * psz_cmd,
event.type = libvlc_MediaInstancePaused; event.type = libvlc_MediaInstancePaused;
break; break;
case PLAYING_S: case PLAYING_S:
printf("PLAYING_S!!!!!!!!\n");
libvlc_media_descriptor_set_state( p_mi->p_md, libvlc_Playing, NULL); libvlc_media_descriptor_set_state( p_mi->p_md, libvlc_Playing, NULL);
event.type = libvlc_MediaInstancePlayed; event.type = libvlc_MediaInstancePlayed;
break; break;
...@@ -173,7 +171,39 @@ input_position_changed( vlc_object_t * p_this, char const * psz_cmd, ...@@ -173,7 +171,39 @@ input_position_changed( vlc_object_t * p_this, char const * psz_cmd,
{ {
libvlc_media_instance_t * p_mi = p_userdata; libvlc_media_instance_t * p_mi = p_userdata;
vlc_value_t val; vlc_value_t val;
if (!strncmp(psz_cmd, "intf", 4 /* "-change" no need to go further */))
{
input_thread_t * p_input = (input_thread_t *)p_this;
var_Get( p_input, "state", &val );
if( val.i_int != PLAYING_S )
return VLC_SUCCESS; /* Don't send the position while stopped */
var_Get( p_input, "position", &val );
}
else
val.i_time = newval.i_time;
libvlc_event_t event;
event.type = libvlc_MediaInstancePositionChanged;
event.u.media_instance_position_changed.new_position = val.f_float;
libvlc_event_send( p_mi->p_event_manager, &event );
return VLC_SUCCESS;
}
/*
* input_time_changed (Private) (input var "intf-change" Callback)
*/
static int
input_time_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;
vlc_value_t val;
if (!strncmp(psz_cmd, "intf", 4 /* "-change" no need to go further */)) if (!strncmp(psz_cmd, "intf", 4 /* "-change" no need to go further */))
{ {
vlc_value_t val2; vlc_value_t val2;
...@@ -191,8 +221,8 @@ input_position_changed( vlc_object_t * p_this, char const * psz_cmd, ...@@ -191,8 +221,8 @@ input_position_changed( vlc_object_t * p_this, char const * psz_cmd,
val.i_time = newval.i_time; val.i_time = newval.i_time;
libvlc_event_t event; libvlc_event_t event;
event.type = libvlc_MediaInstancePositionChanged; event.type = libvlc_MediaInstanceTimeChanged;
event.u.media_instance_position_changed.new_position = val.i_time; event.u.media_instance_time_changed.new_time = val.i_time;
libvlc_event_send( p_mi->p_event_manager, &event ); libvlc_event_send( p_mi->p_event_manager, &event );
return VLC_SUCCESS; return VLC_SUCCESS;
...@@ -247,6 +277,8 @@ libvlc_media_instance_new( libvlc_instance_t * p_libvlc_instance, ...@@ -247,6 +277,8 @@ libvlc_media_instance_new( libvlc_instance_t * p_libvlc_instance,
libvlc_MediaInstancePlayed, p_e ); libvlc_MediaInstancePlayed, p_e );
libvlc_event_manager_register_event_type( p_mi->p_event_manager, libvlc_event_manager_register_event_type( p_mi->p_event_manager,
libvlc_MediaInstancePositionChanged, p_e ); libvlc_MediaInstancePositionChanged, p_e );
libvlc_event_manager_register_event_type( p_mi->p_event_manager,
libvlc_MediaInstanceTimeChanged, p_e );
return p_mi; return p_mi;
} }
...@@ -495,6 +527,7 @@ void libvlc_media_instance_play( libvlc_media_instance_t *p_mi, ...@@ -495,6 +527,7 @@ void libvlc_media_instance_play( libvlc_media_instance_t *p_mi,
} }
var_AddCallback( p_input_thread, "state", input_state_changed, p_mi ); var_AddCallback( p_input_thread, "state", input_state_changed, p_mi );
var_AddCallback( p_input_thread, "intf-change", input_position_changed, p_mi ); var_AddCallback( p_input_thread, "intf-change", input_position_changed, p_mi );
var_AddCallback( p_input_thread, "intf-change", input_time_changed, p_mi );
/* will be released in media_instance_release() */ /* will be released in media_instance_release() */
vlc_object_yield( p_input_thread ); vlc_object_yield( p_input_thread );
......
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