Commit 141e740f authored by Pierre d'Herbemont's avatar Pierre d'Herbemont

control/media_descriptor.c: Publish an Event plus a method to get the...

control/media_descriptor.c: Publish an Event plus a method to get the media_descriptor state, which is buffering, playing, error, nothing special. This is a bit controversial as we need a media_instance to set that state, and this is media_instance dependant. However, this is a nice shortcut.
parent f2c77da9
...@@ -196,6 +196,10 @@ VLC_PUBLIC_API char * libvlc_media_descriptor_get_meta( ...@@ -196,6 +196,10 @@ VLC_PUBLIC_API char * libvlc_media_descriptor_get_meta(
libvlc_meta_t e_meta, libvlc_meta_t e_meta,
libvlc_exception_t *p_e ); libvlc_exception_t *p_e );
VLC_PUBLIC_API libvlc_state_t libvlc_media_descriptor_get_state(
libvlc_media_descriptor_t *p_meta_desc,
libvlc_exception_t *p_e );
/* Tags */ /* Tags */
VLC_PUBLIC_API void libvlc_media_descriptor_add_tag( libvlc_media_descriptor_t *p_md, VLC_PUBLIC_API void libvlc_media_descriptor_add_tag( libvlc_media_descriptor_t *p_md,
const char * key, const char * key,
......
...@@ -122,6 +122,7 @@ typedef struct libvlc_media_instance_t libvlc_media_instance_t; ...@@ -122,6 +122,7 @@ typedef struct libvlc_media_instance_t libvlc_media_instance_t;
typedef enum libvlc_state_t typedef enum libvlc_state_t
{ {
libvlc_NothingSpecial,
libvlc_Stopped, libvlc_Stopped,
libvlc_Opening, libvlc_Opening,
libvlc_Buffering, libvlc_Buffering,
...@@ -299,6 +300,7 @@ typedef enum libvlc_event_type_t { ...@@ -299,6 +300,7 @@ typedef enum libvlc_event_type_t {
libvlc_MediaDescriptorDurationChanged, libvlc_MediaDescriptorDurationChanged,
libvlc_MediaDescriptorPreparsedChanged, libvlc_MediaDescriptorPreparsedChanged,
libvlc_MediaDescriptorFreed, libvlc_MediaDescriptorFreed,
libvlc_MediaDescriptorStateChanged,
libvlc_MediaInstancePlayed, libvlc_MediaInstancePlayed,
libvlc_MediaInstancePaused, libvlc_MediaInstancePaused,
...@@ -355,6 +357,10 @@ typedef struct libvlc_event_t ...@@ -355,6 +357,10 @@ typedef struct libvlc_event_t
{ {
libvlc_media_descriptor_t * md; libvlc_media_descriptor_t * md;
} media_descriptor_freed; } media_descriptor_freed;
struct
{
libvlc_state_t new_state;
} media_descriptor_state_changed;
/* media instance */ /* media instance */
struct struct
......
...@@ -87,6 +87,7 @@ struct libvlc_media_descriptor_t ...@@ -87,6 +87,7 @@ struct libvlc_media_descriptor_t
int i_refcount; int i_refcount;
libvlc_instance_t *p_libvlc_instance; libvlc_instance_t *p_libvlc_instance;
vlc_dictionary_t tags; /* To be merged with core's meta soon */ vlc_dictionary_t tags; /* To be merged with core's meta soon */
libvlc_state_t state;
struct libvlc_media_list_t *p_subitems; /* A media descriptor can have struct libvlc_media_list_t *p_subitems; /* A media descriptor can have
* Sub item */ * Sub item */
void *p_user_data; /* Allows for VLC.framework to hook into media descriptor without creating a new VLCMedia object. */ void *p_user_data; /* Allows for VLC.framework to hook into media descriptor without creating a new VLCMedia object. */
...@@ -292,6 +293,9 @@ VLC_EXPORT (libvlc_media_descriptor_t *, libvlc_media_descriptor_new_from_input_ ...@@ -292,6 +293,9 @@ VLC_EXPORT (libvlc_media_descriptor_t *, libvlc_media_descriptor_new_from_input_
VLC_EXPORT (libvlc_media_descriptor_t *, libvlc_media_descriptor_duplicate, VLC_EXPORT (libvlc_media_descriptor_t *, libvlc_media_descriptor_duplicate,
( libvlc_media_descriptor_t * ) ); ( libvlc_media_descriptor_t * ) );
VLC_EXPORT (void, libvlc_media_descriptor_set_state,
( libvlc_media_descriptor_t *, libvlc_state_t, libvlc_exception_t * ) );
/* Media List View */ /* Media List View */
VLC_EXPORT ( libvlc_media_list_view_t *, libvlc_media_list_view_new, VLC_EXPORT ( libvlc_media_list_view_t *, libvlc_media_list_view_new,
( libvlc_media_list_t * p_mlist, ( libvlc_media_list_t * p_mlist,
......
...@@ -248,7 +248,9 @@ libvlc_media_descriptor_t * libvlc_media_descriptor_new_from_input_item( ...@@ -248,7 +248,9 @@ libvlc_media_descriptor_t * libvlc_media_descriptor_new_from_input_item(
p_md->p_input_item = p_input_item; p_md->p_input_item = p_input_item;
p_md->b_preparsed = VLC_FALSE; p_md->b_preparsed = VLC_FALSE;
p_md->i_refcount = 1; p_md->i_refcount = 1;
p_md->p_user_data = NULL; // VLC.framework hook p_md->p_user_data = NULL;
p_md->state = libvlc_NothingSpecial;
/* A media descriptor can be a playlist. When you open a playlist /* A media descriptor can be a playlist. When you open a playlist
* It can give a bunch of item to read. */ * It can give a bunch of item to read. */
...@@ -265,6 +267,8 @@ libvlc_media_descriptor_t * libvlc_media_descriptor_new_from_input_item( ...@@ -265,6 +267,8 @@ libvlc_media_descriptor_t * libvlc_media_descriptor_new_from_input_item(
libvlc_MediaDescriptorFreed, p_e ); libvlc_MediaDescriptorFreed, p_e );
libvlc_event_manager_register_event_type( p_md->p_event_manager, libvlc_event_manager_register_event_type( p_md->p_event_manager,
libvlc_MediaDescriptorDurationChanged, p_e ); libvlc_MediaDescriptorDurationChanged, p_e );
libvlc_event_manager_register_event_type( p_md->p_event_manager,
libvlc_MediaDescriptorStateChanged, p_e );
vlc_gc_incref( p_md->p_input_item ); vlc_gc_incref( p_md->p_input_item );
...@@ -450,6 +454,41 @@ char * libvlc_media_descriptor_get_meta( libvlc_media_descriptor_t *p_md, ...@@ -450,6 +454,41 @@ char * libvlc_media_descriptor_get_meta( libvlc_media_descriptor_t *p_md,
return psz_meta; return psz_meta;
} }
/**************************************************************************
* Getter for state information
* Can be error, playing, buffering, NothingSpecial.
**************************************************************************/
libvlc_state_t
libvlc_media_descriptor_get_state( libvlc_media_descriptor_t *p_md,
libvlc_exception_t *p_e )
{
(void)p_e;
return p_md->state;
}
/**************************************************************************
* Setter for state information (LibVLC Internal)
**************************************************************************/
void
libvlc_media_descriptor_set_state( libvlc_media_descriptor_t *p_md,
libvlc_state_t state,
libvlc_exception_t *p_e )
{
(void)p_e;
libvlc_event_t event;
p_md->state = state;
/* Construct the event */
event.type = libvlc_MediaDescriptorStateChanged;
event.u.media_descriptor_state_changed.new_state = state;
/* Send the event */
libvlc_event_send( p_md->p_event_manager, &event );
}
/************************************************************************** /**************************************************************************
* Add a tag * Add a tag
**************************************************************************/ **************************************************************************/
......
...@@ -27,6 +27,24 @@ ...@@ -27,6 +27,24 @@
#include "libvlc_internal.h" #include "libvlc_internal.h"
#include "libvlc.h" #include "libvlc.h"
static const libvlc_state_t vlc_to_libvlc_state_array[] =
{
[INIT_S] = libvlc_Opening,
[OPENING_S] = libvlc_Opening,
[BUFFERING_S] = libvlc_Buffering,
[PLAYING_S] = libvlc_Playing,
[PAUSE_S] = libvlc_Paused,
[END_S] = libvlc_Ended,
[ERROR_S] = libvlc_Error,
};
static inline libvlc_state_t vlc_to_libvlc_state( int vlc_state )
{
if( vlc_state < 0 || vlc_state > 6 )
return libvlc_Stopped;
return vlc_to_libvlc_state_array[vlc_state];
}
/* /*
* Release the associated input thread * Release the associated input thread
* *
...@@ -114,18 +132,27 @@ input_state_changed( vlc_object_t * p_this, char const * psz_cmd, ...@@ -114,18 +132,27 @@ 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 */
switch ( newval.i_int ) switch ( newval.i_int )
{ {
case END_S: case END_S:
libvlc_media_descriptor_set_state( p_mi->p_md, libvlc_NothingSpecial, NULL);
event.type = libvlc_MediaInstanceReachedEnd; event.type = libvlc_MediaInstanceReachedEnd;
break; break;
case PAUSE_S: case PAUSE_S:
libvlc_media_descriptor_set_state( p_mi->p_md, libvlc_Playing, NULL);
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);
event.type = libvlc_MediaInstancePlayed;
break;
case ERROR_S:
libvlc_media_descriptor_set_state( p_mi->p_md, libvlc_Error, NULL);
event.type = libvlc_MediaInstancePlayed; event.type = libvlc_MediaInstancePlayed;
break; break;
default: default:
...@@ -729,17 +756,6 @@ float libvlc_media_instance_get_rate( ...@@ -729,17 +756,6 @@ float libvlc_media_instance_get_rate(
return (float)1000.0f/val.i_int; return (float)1000.0f/val.i_int;
} }
static const libvlc_state_t vlc_to_libvlc_state[] =
{
[INIT_S] = libvlc_Opening,
[OPENING_S] = libvlc_Opening,
[BUFFERING_S] = libvlc_Buffering,
[PLAYING_S] = libvlc_Playing,
[PAUSE_S] = libvlc_Paused,
[END_S] = libvlc_Ended,
[ERROR_S] = libvlc_Error,
};
libvlc_state_t libvlc_media_instance_get_state( libvlc_state_t libvlc_media_instance_get_state(
libvlc_media_instance_t *p_mi, libvlc_media_instance_t *p_mi,
libvlc_exception_t *p_e ) libvlc_exception_t *p_e )
...@@ -754,8 +770,5 @@ libvlc_state_t libvlc_media_instance_get_state( ...@@ -754,8 +770,5 @@ libvlc_state_t libvlc_media_instance_get_state(
var_Get( p_input_thread, "state", &val ); var_Get( p_input_thread, "state", &val );
vlc_object_release( p_input_thread ); vlc_object_release( p_input_thread );
if( val.i_int < 0 || val.i_int > 6 ) return vlc_to_libvlc_state(val.i_int);
return libvlc_Stopped;
return vlc_to_libvlc_state[val.i_int];
} }
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