Commit f7f791b9 authored by Pierre d'Herbemont's avatar Pierre d'Herbemont

Libvlc event: Support for event extra information passing. And register to...

Libvlc event: Support for event extra information passing. And register to "time" event rather than "position".
parent c9e0e4e1
...@@ -141,34 +141,29 @@ typedef struct libvlc_log_message_t ...@@ -141,34 +141,29 @@ typedef struct libvlc_log_message_t
/** /**
* Available events: * Available events:
* - VOLUME_CHANGED * - libvlc_VolumeChanged
* - INPUT_POSITION_CHANGED * - libvlc_InputPositionChanged
*/ */
typedef enum { typedef enum {
VOLUME_CHANGED, libvlc_VolumeChanged,
INPUT_POSITION_CHANGED, libvlc_InputPositionChanged,
} libvlc_event_type_t; } libvlc_event_type_t;
typedef enum {
INT_EVENT,
BOOLEAN_EVENT,
FLOAT_EVENT,
STRING_EVENT,
ADDRESS_EVENT,
OBJECT_EVENT,
LIST_EVENT,
TIME_EVENT,
VAR_EVENT,
} libvlc_event_value_type_t;
typedef struct typedef struct
{ {
libvlc_event_type_t type; libvlc_event_type_t type;
libvlc_event_value_type_t value_type; union
vlc_value_t old_value; {
vlc_value_t new_value; struct
char reserved[8]; /* For future use */ {
int new_volume;
} volume_changed;
struct
{
uint64_t new_position;
} input_position_changed;
} u;
} libvlc_event_t; } libvlc_event_t;
/** /**
......
...@@ -42,11 +42,13 @@ static int handle_event( vlc_object_t *p_this, char const *psz_cmd, ...@@ -42,11 +42,13 @@ static int handle_event( vlc_object_t *p_this, char const *psz_cmd,
event.type = entry->i_event_type; event.type = entry->i_event_type;
if (event.type == INPUT_POSITION_CHANGED && !strcmp(psz_cmd, "intf-change")) if (event.type == libvlc_VolumeChanged)
{
if(!strcmp(psz_cmd, "intf-change"))
{ {
input_thread_t * p_input = (input_thread_t *)p_this; input_thread_t * p_input = (input_thread_t *)p_this;
vlc_value_t val; vlc_value_t val;
var_Get( p_input, "position", &val ); var_Get( p_input, "time", &val );
/* Only send event at a reasonable time precision (500ms) */ /* Only send event at a reasonable time precision (500ms) */
/* (FIXME: this should be configurable) */ /* (FIXME: this should be configurable) */
...@@ -55,6 +57,17 @@ static int handle_event( vlc_object_t *p_this, char const *psz_cmd, ...@@ -55,6 +57,17 @@ static int handle_event( vlc_object_t *p_this, char const *psz_cmd,
/* Don't send this event */ /* Don't send this event */
return VLC_SUCCESS; return VLC_SUCCESS;
} }
event.u.input_position_changed.new_position = val.i_time;
}
else
event.u.input_position_changed.new_position = newval.i_time;
event.u.input_position_changed.new_position *= 1000LL;
}
else if (event.type == libvlc_InputPositionChanged)
{
event.u.volume_changed.new_volume = newval.i_int;
} }
/* Call the client entry */ /* Call the client entry */
...@@ -94,12 +107,12 @@ static int install_input_event( vlc_object_t *p_this, char const *psz_cmd, ...@@ -94,12 +107,12 @@ static int install_input_event( vlc_object_t *p_this, char const *psz_cmd,
for( ; p_listitem ; p_listitem = p_listitem->next ) for( ; p_listitem ; p_listitem = p_listitem->next )
{ {
if (p_listitem->elmt->i_event_type == INPUT_POSITION_CHANGED) if (p_listitem->elmt->i_event_type == libvlc_InputPositionChanged)
{ {
/* FIXME: here we shouldn't listen on intf-change, we have to provide /* FIXME: here we shouldn't listen on intf-change, we have to provide
* in vlc core a more accurate callback */ * in vlc core a more accurate callback */
var_AddCallback( p_input, "intf-change", handle_event, p_listitem->elmt ); var_AddCallback( p_input, "intf-change", handle_event, p_listitem->elmt );
var_AddCallback( p_input, "position", handle_event, p_listitem->elmt ); var_AddCallback( p_input, "time", handle_event, p_listitem->elmt );
} }
} }
...@@ -140,17 +153,15 @@ static int remove_variable_callback( libvlc_instance_t *p_instance, ...@@ -140,17 +153,15 @@ static int remove_variable_callback( libvlc_instance_t *p_instance,
switch ( p_entry->i_event_type ) switch ( p_entry->i_event_type )
{ {
case VOLUME_CHANGED: case libvlc_VolumeChanged:
res = var_DelCallback( p_instance->p_libvlc_int, "volume-change", res = var_DelCallback( p_instance->p_libvlc_int, "volume-change",
handle_event, p_entry ); handle_event, p_entry );
break; break;
case INPUT_POSITION_CHANGED: case libvlc_InputPositionChanged:
/* We may not be deleting the right p_input callback, in this case this /* We may not be deleting the right p_input callback, in this case this
* will be a no-op */ * will be a no-op */
var_DelCallback( p_input, "intf-change", var_DelCallback( p_input, "intf-change", handle_event, p_entry );
handle_event, p_entry ); var_DelCallback( p_input, "position", handle_event, p_entry );
var_DelCallback( p_input, "position",
handle_event, p_entry );
break; break;
} }
...@@ -221,11 +232,11 @@ void libvlc_event_add_callback( libvlc_instance_t *p_instance, ...@@ -221,11 +232,11 @@ void libvlc_event_add_callback( libvlc_instance_t *p_instance,
switch ( i_event_type ) switch ( i_event_type )
{ {
case VOLUME_CHANGED: case libvlc_VolumeChanged:
res = var_AddCallback( p_instance->p_libvlc_int, "volume-change", res = var_AddCallback( p_instance->p_libvlc_int, "volume-change",
handle_event, entry ); handle_event, entry );
break; break;
case INPUT_POSITION_CHANGED: case libvlc_InputPositionChanged:
install_input_event( NULL, NULL, unused1, unused2, p_instance); install_input_event( NULL, NULL, unused1, unused2, p_instance);
break; break;
default: default:
......
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