Commit 145a649d authored by Pierre d'Herbemont's avatar Pierre d'Herbemont

libvlc: Implement the _get_state function. Fix a leak. Fix a warning.

parent 723934d9
......@@ -388,7 +388,7 @@ VLC_PUBLIC_API void libvlc_media_instance_set_position ( libvlc_media_i
VLC_PUBLIC_API vlc_bool_t libvlc_media_instance_will_play ( libvlc_media_instance_t *, libvlc_exception_t *);
VLC_PUBLIC_API float libvlc_media_instance_get_rate ( libvlc_media_instance_t *, libvlc_exception_t *);
VLC_PUBLIC_API void libvlc_media_instance_set_rate ( libvlc_media_instance_t *, float, libvlc_exception_t *);
VLC_PUBLIC_API int libvlc_media_instance_get_state ( libvlc_media_instance_t *, libvlc_exception_t *);
VLC_PUBLIC_API libvlc_state_t libvlc_media_instance_get_state ( libvlc_media_instance_t *, libvlc_exception_t *);
/**
* Does this input have a video output ?
......@@ -529,6 +529,11 @@ VLC_PUBLIC_API void
int index,
libvlc_exception_t * p_e );
VLC_PUBLIC_API void
libvlc_media_list_view_remove_at_index( libvlc_media_list_view_t * p_mlv,
int index,
libvlc_exception_t * p_e );
VLC_PUBLIC_API void
libvlc_media_list_view_add_item( libvlc_media_list_view_t * p_mlv,
libvlc_media_descriptor_t * p_md,
......@@ -623,6 +628,18 @@ VLC_PUBLIC_API void
libvlc_media_list_player_play( libvlc_media_list_player_t * p_mlp,
libvlc_exception_t * p_e );
VLC_PUBLIC_API void
libvlc_media_list_player_pause( libvlc_media_list_player_t * p_mlp,
libvlc_exception_t * p_e );
VLC_PUBLIC_API int
libvlc_media_list_player_is_playing( libvlc_media_list_player_t * p_mlp,
libvlc_exception_t * p_e );
VLC_PUBLIC_API libvlc_state_t
libvlc_media_list_player_get_state( libvlc_media_list_player_t * p_mlp,
libvlc_exception_t * p_e );
VLC_PUBLIC_API void
libvlc_media_list_player_play_item_at_index(
libvlc_media_list_player_t * p_mlp,
......
......@@ -120,6 +120,17 @@ typedef struct libvlc_media_descriptor_t libvlc_media_descriptor_t;
typedef struct libvlc_media_instance_t libvlc_media_instance_t;
typedef enum libvlc_state_t
{
libvlc_Stopped,
libvlc_Opening,
libvlc_Buffering,
libvlc_Ended,
libvlc_Error,
libvlc_Playing,
libvlc_Paused
} libvlc_state_t;
/**@} */
/*****************************************************************************
......
......@@ -676,7 +676,18 @@ float libvlc_media_instance_get_rate(
return (float)1000.0f/val.i_int;
}
int libvlc_media_instance_get_state(
static 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_media_instance_t *p_mi,
libvlc_exception_t *p_e )
{
......@@ -685,10 +696,13 @@ int libvlc_media_instance_get_state(
p_input_thread = libvlc_get_input_thread ( p_mi, p_e );
if ( !p_input_thread )
return 0;
return libvlc_Stopped;
var_Get( p_input_thread, "state", &val );
vlc_object_release( p_input_thread );
return val.i_int;
if( val.i_int < 0 || val.i_int > 6 )
return libvlc_Stopped;
return vlc_to_libvlc_state[val.i_int];
}
......@@ -175,17 +175,6 @@ uninstall_media_instance_observer( libvlc_media_list_player_t * p_mlp )
media_instance_reached_end, p_mlp, NULL );
}
/**************************************************************************
* Stop (Public)
**************************************************************************/
static vlc_bool_t
libvlc_media_list_player_is_playing( libvlc_media_list_player_t * p_mlp,
libvlc_exception_t * p_e )
{
//libvlc_exception_raise( p_e, "Unimplemented" );
return 1;
}
/**************************************************************************
* set_current_playing_item (private)
*
......@@ -199,18 +188,17 @@ set_current_playing_item( libvlc_media_list_player_t * p_mlp,
libvlc_media_descriptor_t * p_md;
p_md = libvlc_media_list_item_at_path( p_mlp->p_mlist, path );
if( !p_md )
{
if( !libvlc_exception_raised( p_e ) )
libvlc_exception_raise( p_e, "Can't obtain a media" );
return;
}
vlc_mutex_lock( &p_mlp->object_lock );
free( p_mlp->current_playing_item_path );
p_mlp->current_playing_item_path = path;
if( !p_md )
{
vlc_mutex_unlock( &p_mlp->object_lock );
return;
}
/* We are not interested in getting media_descriptor stop event now */
uninstall_media_instance_observer( p_mlp );
if( p_md->p_subitems && libvlc_media_list_count( p_md->p_subitems, NULL ) > 0 )
......@@ -337,6 +325,41 @@ void libvlc_media_list_player_play( libvlc_media_list_player_t * p_mlp,
libvlc_media_instance_play( p_mlp->p_mi, p_e );
}
/**************************************************************************
* Pause (Public)
**************************************************************************/
void libvlc_media_list_player_pause( libvlc_media_list_player_t * p_mlp,
libvlc_exception_t * p_e )
{
if( !p_mlp->p_mi )
return;
libvlc_media_instance_pause( p_mlp->p_mi, p_e );
}
/**************************************************************************
* is_playing (Public)
**************************************************************************/
int libvlc_media_list_player_is_playing( libvlc_media_list_player_t * p_mlp,
libvlc_exception_t * p_e )
{
libvlc_state_t state = libvlc_media_instance_get_state( p_mlp->p_mi, p_e );
return (state == libvlc_Opening) || (state == libvlc_Buffering) ||
(state == libvlc_Playing);
}
/**************************************************************************
* State (Public)
**************************************************************************/
libvlc_state_t
libvlc_media_list_player_get_state( libvlc_media_list_player_t * p_mlp,
libvlc_exception_t * p_e )
{
if( !p_mlp->p_mi )
return libvlc_Stopped;
return libvlc_media_instance_get_state( p_mlp->p_mi, p_e );
}
/**************************************************************************
* Play item at index (Public)
**************************************************************************/
......@@ -389,6 +412,7 @@ void libvlc_media_list_player_stop( libvlc_media_list_player_t * p_mlp,
libvlc_media_instance_stop( p_mlp->p_mi, p_e );
vlc_mutex_lock( &p_mlp->object_lock );
free( p_mlp->current_playing_item_path );
p_mlp->current_playing_item_path = NULL;
vlc_mutex_unlock( &p_mlp->object_lock );
}
......
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