Commit 445d63e0 authored by Olivier Aubert's avatar Olivier Aubert
Browse files

mediacontrol API: update to use the new libvlc_media_player/libvlc_media API.

This implies the removal of playlist support (single-file playing only, through set_mrl/get_mrl methods). Position parameters for _pause, _resume and _stop method have also been removed.
parent 0b96b7ca
......@@ -130,6 +130,14 @@ mediacontrol_new_from_instance( libvlc_instance_t* p_instance,
VLC_PUBLIC_API libvlc_instance_t*
mediacontrol_get_libvlc_instance( mediacontrol_Instance* self );
/**
* Get the associated libvlc_media_player
* \param self: the mediacontrol instance
* \return a libvlc_media_player_t instance
*/
VLC_PUBLIC_API libvlc_media_player_t*
mediacontrol_get_media_player( mediacontrol_Instance* self );
/**
* Get the current position
* \param self the mediacontrol instance
......@@ -167,31 +175,25 @@ VLC_PUBLIC_API void mediacontrol_start( mediacontrol_Instance *self,
/**
* Pause the movie at a given position
* \param self the mediacontrol instance
* \param a_position a mediacontrol_Position (ignored for now)
* \param exception an initialized exception pointer
*/
VLC_PUBLIC_API void mediacontrol_pause( mediacontrol_Instance *self,
const mediacontrol_Position *a_position,
mediacontrol_Exception *exception );
/**
* Resume the movie at a given position
* \param self the mediacontrol instance
* \param a_position a mediacontrol_Position (ignored for now)
* \param exception an initialized exception pointer
*/
VLC_PUBLIC_API void mediacontrol_resume( mediacontrol_Instance *self,
const mediacontrol_Position *a_position,
mediacontrol_Exception *exception );
/**
* Stop the movie at a given position
* \param self the mediacontrol instance
* \param a_position a mediacontrol_Position (ignored for now)
* \param exception an initialized exception pointer
*/
VLC_PUBLIC_API void mediacontrol_stop( mediacontrol_Instance *self,
const mediacontrol_Position *a_position,
mediacontrol_Exception *exception );
/**
......@@ -201,39 +203,22 @@ VLC_PUBLIC_API void mediacontrol_stop( mediacontrol_Instance *self,
VLC_PUBLIC_API void mediacontrol_exit( mediacontrol_Instance *self );
/**
* Add a new MRL to the playlist
* Set the MRL to be played.
* \param self the mediacontrol instance
* \param psz_file the MRL
* \param exception an initialized exception pointer
*/
VLC_PUBLIC_API void mediacontrol_playlist_add_item( mediacontrol_Instance *self,
VLC_PUBLIC_API void mediacontrol_set_mrl( mediacontrol_Instance *self,
const char* psz_file,
mediacontrol_Exception *exception );
/**
* Clear the playlist
* \param self the mediacontrol instance
* \param exception an initialized exception pointer
*/
VLC_PUBLIC_API void mediacontrol_playlist_clear( mediacontrol_Instance *self,
mediacontrol_Exception *exception );
/**
* Get a flattened view of the playlist
* \param self the mediacontrol instance
* \param exception an initialized exception pointer
* \return a list of strings
*/
VLC_PUBLIC_API mediacontrol_PlaylistSeq *
mediacontrol_playlist_get_list( mediacontrol_Instance *self,
mediacontrol_Exception *exception );
/**
* Play the next item
* Get the MRL to be played.
* \param self the mediacontrol instance
* \param exception an initialized exception pointer
*/
VLC_PUBLIC_API void
mediacontrol_playlist_next_item( mediacontrol_Instance *self,
mediacontrol_Exception *exception );
VLC_PUBLIC_API char * mediacontrol_get_mrl( mediacontrol_Instance *self,
mediacontrol_Exception *exception );
/*****************************************************************************
* A/V functions
......@@ -250,17 +235,6 @@ VLC_PUBLIC_API mediacontrol_RGBPicture *
const mediacontrol_Position *a_position,
mediacontrol_Exception *exception );
/* Return a NULL terminated list */
/**
* Get a list of all cached snapshots (unimplemented)
* \param self the mediacontrol instance
* \param exception an initialized exception pointer
* \return a NULL-terminated list of RGBpicture
*/
VLC_PUBLIC_API mediacontrol_RGBPicture **
mediacontrol_all_snapshots( mediacontrol_Instance *self,
mediacontrol_Exception *exception );
/**
* Displays the message string, between "begin" and "end" positions.
* \param self the mediacontrol instance
......
......@@ -25,14 +25,11 @@
# include "config.h"
#endif
#include "mediacontrol_internal.h"
#include "libvlc_internal.h"
#include <vlc/mediacontrol.h>
#include <vlc/libvlc.h>
#include <vlc_playlist.h>
#include <vlc_aout.h>
#include <vlc_vout.h>
#include <vlc_osd.h>
......@@ -60,21 +57,30 @@ mediacontrol_snapshot( mediacontrol_Instance *self,
{
vlc_object_t* p_cache;
vout_thread_t* p_vout;
input_thread_t *p_input;
mediacontrol_RGBPicture *p_pic = NULL;
char path[256];
snapshot_t *p_snapshot;
libvlc_exception_t ex;
libvlc_exception_init( &ex );
mediacontrol_exception_init( exception );
p_vout = vlc_object_find( self->p_playlist, VLC_OBJECT_VOUT, FIND_CHILD );
p_input = libvlc_get_input_thread( self->p_media_player, &ex );
if( ! p_input )
{
RAISE_NULL( mediacontrol_InternalException, "No input" );
}
p_vout = vlc_object_find( p_input, VLC_OBJECT_VOUT, FIND_CHILD );
if( ! p_vout )
{
RAISE_NULL( mediacontrol_InternalException, "No video output" );
}
p_cache = vlc_object_create( self->p_playlist, VLC_OBJECT_GENERIC );
p_cache = vlc_object_create( p_input, VLC_OBJECT_GENERIC );
if( p_cache == NULL )
{
vlc_object_release( p_vout );
vlc_object_release( p_input );
RAISE_NULL( mediacontrol_InternalException, "Out of memory" );
}
snprintf( path, 255, "object:%d", p_cache->i_object_id );
......@@ -89,6 +95,7 @@ mediacontrol_snapshot( mediacontrol_Instance *self,
p_snapshot = ( snapshot_t* ) p_cache->p_private;
vlc_object_unlock( p_cache );
vlc_object_release( p_cache );
vlc_object_release( p_input );
if( p_snapshot )
{
......@@ -112,15 +119,6 @@ mediacontrol_snapshot( mediacontrol_Instance *self,
return p_pic;
}
mediacontrol_RGBPicture **
mediacontrol_all_snapshots( mediacontrol_Instance *self,
mediacontrol_Exception *exception )
{
mediacontrol_exception_init( exception );
RAISE_NULL( mediacontrol_InternalException, "unsupported method" );
}
static
int mediacontrol_showtext( vout_thread_t *p_vout, int i_channel,
char *psz_string, text_style_t *p_style,
......@@ -174,20 +172,29 @@ mediacontrol_display_text( mediacontrol_Instance *self,
const mediacontrol_Position * end,
mediacontrol_Exception *exception )
{
input_thread_t *p_input = NULL;
vout_thread_t *p_vout = NULL;
char* psz_message;
input_thread_t *p_input;
libvlc_exception_t ex;
psz_message = strdup( message );
if( !psz_message )
libvlc_exception_init( &ex );
mediacontrol_exception_init( exception );
p_input = libvlc_get_input_thread( self->p_media_player, &ex );
if( ! p_input )
{
RAISE_VOID( mediacontrol_InternalException, "no more memory" );
RAISE_VOID( mediacontrol_InternalException, "No input" );
}
p_vout = vlc_object_find( self->p_playlist, VLC_OBJECT_VOUT, FIND_CHILD );
p_vout = vlc_object_find( p_input, VLC_OBJECT_VOUT, FIND_CHILD );
if( ! p_vout )
{
RAISE_VOID( mediacontrol_InternalException, "no video output" );
RAISE_VOID( mediacontrol_InternalException, "No video output" );
}
psz_message = strdup( message );
if( !psz_message )
{
RAISE_VOID( mediacontrol_InternalException, "no more memory" );
}
if( begin->origin == mediacontrol_RelativePosition &&
......@@ -198,10 +205,10 @@ mediacontrol_display_text( mediacontrol_Instance *self,
mtime_t i_now = mdate();
i_duration = 1000 * private_mediacontrol_unit_convert(
self->p_playlist->p_input,
end->key,
mediacontrol_MediaTime,
end->value );
self->p_media_player,
end->key,
mediacontrol_MediaTime,
end->value );
mediacontrol_showtext( p_vout, DEFAULT_CHAN, psz_message, NULL,
OSD_ALIGN_BOTTOM | OSD_ALIGN_LEFT, 0, 0,
......@@ -211,22 +218,15 @@ mediacontrol_display_text( mediacontrol_Instance *self,
{
mtime_t i_debut, i_fin, i_now;
p_input = self->p_playlist->p_input;
if( ! p_input )
{
vlc_object_release( p_vout );
RAISE_VOID( mediacontrol_InternalException, "No input" );
}
/* FIXME */
/* i_now = input_ClockGetTS( p_input, NULL, 0 ); */
i_now = mdate();
i_debut = private_mediacontrol_position2microsecond( p_input,
i_debut = private_mediacontrol_position2microsecond( self->p_media_player,
( mediacontrol_Position* ) begin );
i_debut += i_now;
i_fin = private_mediacontrol_position2microsecond( p_input,
i_fin = private_mediacontrol_position2microsecond( self->p_media_player,
( mediacontrol_Position * ) end );
i_fin += i_now;
......@@ -278,7 +278,7 @@ bool mediacontrol_set_visual( mediacontrol_Instance *self,
mediacontrol_exception_init( exception );
libvlc_exception_init( &ex );
libvlc_video_set_parent( self->p_instance, visual_id, &ex );
libvlc_media_player_set_drawable( self->p_media_player, visual_id, &ex );
HANDLE_LIBVLC_EXCEPTION_ZERO( &ex );
return true;
}
......@@ -288,17 +288,12 @@ mediacontrol_get_rate( mediacontrol_Instance *self,
mediacontrol_Exception *exception )
{
libvlc_exception_t ex;
libvlc_media_player_t* p_mi;
int i_ret;
mediacontrol_exception_init( exception );
libvlc_exception_init( &ex );
p_mi = libvlc_playlist_get_media_player( self->p_instance, &ex );
HANDLE_LIBVLC_EXCEPTION_ZERO( &ex );
i_ret = libvlc_media_player_get_rate( p_mi, &ex );
libvlc_media_player_release( p_mi );
i_ret = libvlc_media_player_get_rate( self->p_media_player, &ex );
HANDLE_LIBVLC_EXCEPTION_ZERO( &ex );
return i_ret / 10;
......@@ -310,16 +305,11 @@ mediacontrol_set_rate( mediacontrol_Instance *self,
mediacontrol_Exception *exception )
{
libvlc_exception_t ex;
libvlc_media_player_t* p_mi;
mediacontrol_exception_init( exception );
libvlc_exception_init( &ex );
p_mi = libvlc_playlist_get_media_player( self->p_instance, &ex );
HANDLE_LIBVLC_EXCEPTION_VOID( &ex );
libvlc_media_player_set_rate( p_mi, rate * 10, &ex );
libvlc_media_player_release( p_mi );
libvlc_media_player_set_rate( self->p_media_player, rate * 10, &ex );
HANDLE_LIBVLC_EXCEPTION_VOID( &ex );
}
......@@ -328,17 +318,12 @@ mediacontrol_get_fullscreen( mediacontrol_Instance *self,
mediacontrol_Exception *exception )
{
libvlc_exception_t ex;
libvlc_media_player_t* p_mi;
int i_ret;
mediacontrol_exception_init( exception );
libvlc_exception_init( &ex );
p_mi = libvlc_playlist_get_media_player( self->p_instance, &ex );
HANDLE_LIBVLC_EXCEPTION_ZERO( &ex );
i_ret = libvlc_get_fullscreen( p_mi, &ex );
libvlc_media_player_release( p_mi );
i_ret = libvlc_get_fullscreen( self->p_media_player, &ex );
HANDLE_LIBVLC_EXCEPTION_ZERO( &ex );
return i_ret;
......@@ -350,15 +335,10 @@ mediacontrol_set_fullscreen( mediacontrol_Instance *self,
mediacontrol_Exception *exception )
{
libvlc_exception_t ex;
libvlc_media_player_t* p_mi;
mediacontrol_exception_init( exception );
libvlc_exception_init( &ex );
p_mi = libvlc_playlist_get_media_player( self->p_instance, &ex );
HANDLE_LIBVLC_EXCEPTION_VOID( &ex );
libvlc_set_fullscreen( p_mi, b_fullscreen, &ex );
libvlc_media_player_release( p_mi );
libvlc_set_fullscreen( self->p_media_player, b_fullscreen, &ex );
HANDLE_LIBVLC_EXCEPTION_VOID( &ex );
}
......@@ -69,7 +69,8 @@ mediacontrol_Instance* mediacontrol_new( int argc, char** argv, mediacontrol_Exc
retval->p_instance = libvlc_new( argc, (const char**)argv, &ex );
HANDLE_LIBVLC_EXCEPTION_NULL( &ex );
retval->p_playlist = retval->p_instance->p_libvlc_int->p_playlist;
retval->p_media_player = libvlc_media_player_new( retval->p_instance, &ex );
HANDLE_LIBVLC_EXCEPTION_NULL( &ex );
return retval;
}
......@@ -82,23 +83,33 @@ mediacontrol_exit( mediacontrol_Instance *self )
libvlc_instance_t*
mediacontrol_get_libvlc_instance( mediacontrol_Instance *self )
{
return self->p_instance;
return self->p_instance;
}
libvlc_media_player_t*
mediacontrol_get_media_player( mediacontrol_Instance *self )
{
return self->p_media_player;
}
mediacontrol_Instance *
mediacontrol_new_from_instance( libvlc_instance_t* p_instance,
mediacontrol_Exception *exception )
{
mediacontrol_Instance* retval;
retval = ( mediacontrol_Instance* )malloc( sizeof( mediacontrol_Instance ) );
if( ! retval )
{
RAISE_NULL( mediacontrol_InternalException, "Out of memory" );
}
retval->p_instance = p_instance;
retval->p_playlist = retval->p_instance->p_libvlc_int->p_playlist;
return retval;
mediacontrol_Instance* retval;
libvlc_exception_t ex;
libvlc_exception_init( &ex );
retval = ( mediacontrol_Instance* )malloc( sizeof( mediacontrol_Instance ) );
if( ! retval )
{
RAISE_NULL( mediacontrol_InternalException, "Out of memory" );
}
retval->p_instance = p_instance;
retval->p_media_player = libvlc_media_player_new( retval->p_instance, &ex );
HANDLE_LIBVLC_EXCEPTION_NULL( &ex );
return retval;
}
/**************************************************************************
......@@ -113,7 +124,6 @@ mediacontrol_get_media_position( mediacontrol_Instance *self,
mediacontrol_Position* retval = NULL;
libvlc_exception_t ex;
vlc_int64_t pos;
libvlc_media_player_t * p_mi;
mediacontrol_exception_init( exception );
libvlc_exception_init( &ex );
......@@ -122,19 +132,15 @@ mediacontrol_get_media_position( mediacontrol_Instance *self,
retval->origin = an_origin;
retval->key = a_key;
p_mi = libvlc_playlist_get_media_player( self->p_instance, &ex);
HANDLE_LIBVLC_EXCEPTION_NULL( &ex );
if( an_origin != mediacontrol_AbsolutePosition )
{
libvlc_media_player_release( p_mi );
/* Relative or ModuloPosition make no sense */
RAISE_NULL( mediacontrol_PositionOriginNotSupported,
"Only absolute position is valid." );
}
/* We are asked for an AbsolutePosition. */
pos = libvlc_media_player_get_time( p_mi, &ex );
pos = libvlc_media_player_get_time( self->p_media_player, &ex );
if( a_key == mediacontrol_MediaTime )
{
......@@ -142,18 +148,11 @@ mediacontrol_get_media_position( mediacontrol_Instance *self,
}
else
{
if( ! self->p_playlist->p_input )
{
libvlc_media_player_release( p_mi );
RAISE_NULL( mediacontrol_InternalException,
"No input" );
}
retval->value = private_mediacontrol_unit_convert( self->p_playlist->p_input,
mediacontrol_MediaTime,
a_key,
pos );
retval->value = private_mediacontrol_unit_convert( self->p_media_player,
mediacontrol_MediaTime,
a_key,
pos );
}
libvlc_media_player_release( p_mi );
return retval;
}
......@@ -163,19 +162,14 @@ mediacontrol_set_media_position( mediacontrol_Instance *self,
const mediacontrol_Position * a_position,
mediacontrol_Exception *exception )
{
libvlc_media_player_t * p_mi;
libvlc_exception_t ex;
vlc_int64_t i_pos;
libvlc_exception_init( &ex );
mediacontrol_exception_init( exception );
p_mi = libvlc_playlist_get_media_player( self->p_instance, &ex);
HANDLE_LIBVLC_EXCEPTION_VOID( &ex );
i_pos = private_mediacontrol_position2microsecond( self->p_playlist->p_input, a_position );
libvlc_media_player_set_time( p_mi, i_pos / 1000, &ex );
libvlc_media_player_release( p_mi );
i_pos = private_mediacontrol_position2microsecond( self->p_media_player, a_position );
libvlc_media_player_set_time( self->p_media_player, i_pos / 1000, &ex );
HANDLE_LIBVLC_EXCEPTION_VOID( &ex );
}
......@@ -194,169 +188,136 @@ mediacontrol_start( mediacontrol_Instance *self,
const mediacontrol_Position * a_position,
mediacontrol_Exception *exception )
{
playlist_t * p_playlist = self->p_playlist;
libvlc_media_t * p_media;
char * psz_name;
libvlc_exception_t ex;
mediacontrol_exception_init( exception );
if( ! p_playlist )
libvlc_exception_init( &ex );
p_media = libvlc_media_player_get_media( self->p_media_player, &ex );
HANDLE_LIBVLC_EXCEPTION_VOID( &ex );
if ( ! p_media )
{
RAISE( mediacontrol_PlaylistException, "No available playlist" );
return;
/* No media was defined. */
RAISE( mediacontrol_PlaylistException, "No defined media." );
}
vlc_mutex_lock( &p_playlist->object_lock );
if( p_playlist->items.i_size )
else
{
int i_from;
char *psz_from = NULL;
psz_from = ( char * )malloc( 20 * sizeof( char ) );
if( psz_from && p_playlist->status.p_item )
/* A media was defined. Get its mrl to reuse it, but reset the options
(because start-time may have been set on the previous invocation */
psz_name = libvlc_media_get_mrl( p_media, &ex );
HANDLE_LIBVLC_EXCEPTION_VOID( &ex );
/* Create a new media */
p_media = libvlc_media_new( self->p_instance, psz_name, &ex );
HANDLE_LIBVLC_EXCEPTION_VOID( &ex );
if( a_position->value )
{
i_from = private_mediacontrol_position2microsecond( p_playlist->p_input, a_position ) / 1000000;
/* Set start time */
snprintf( psz_from, 20, "start-time=%i", i_from );
input_ItemAddOption( p_playlist->status.p_item->p_input, psz_from );
free( psz_from );
char * psz_from;
libvlc_time_t i_from;
/* A start position was specified. Add it to media options */
psz_from = ( char * )malloc( 20 * sizeof( char ) );
i_from = private_mediacontrol_position2microsecond( self->p_media_player, a_position ) / 1000000;
snprintf( psz_from, 20, "start-time=%ld", i_from );
libvlc_media_add_option( p_media, psz_from, &ex );
HANDLE_LIBVLC_EXCEPTION_VOID( &ex );
}
libvlc_media_player_set_media( self->p_media_player, p_media, &ex );
HANDLE_LIBVLC_EXCEPTION_VOID( &ex );
vlc_mutex_unlock( &p_playlist->object_lock );
playlist_Play( p_playlist );
}
else
{
RAISE( mediacontrol_PlaylistException, "Empty playlist." );
vlc_mutex_unlock( &p_playlist->object_lock );
libvlc_media_player_play( self->p_media_player, &ex );
HANDLE_LIBVLC_EXCEPTION_VOID( &ex );
}
}
void
mediacontrol_pause( mediacontrol_Instance *self,
const mediacontrol_Position * a_position,
mediacontrol_Exception *exception )
{
input_thread_t *p_input = self->p_playlist->p_input;
libvlc_exception_t ex;
/* FIXME: use the a_position parameter */
mediacontrol_exception_init( exception );
if( p_input != NULL )
{
var_SetInteger( p_input, "state", PAUSE_S );
}
else
{
RAISE( mediacontrol_InternalException, "No input" );
}
libvlc_exception_init( &ex );
libvlc_media_player_pause( self->p_media_player, &ex );
HANDLE_LIBVLC_EXCEPTION_VOID( &ex );
}
void
mediacontrol_resume( mediacontrol_Instance *self,
const mediacontrol_Position * a_position,
mediacontrol_Exception *exception )
{
input_thread_t *p_input = self->p_playlist->p_input;
libvlc_exception_t ex;
/* FIXME: use the a_position parameter */
mediacontrol_exception_init( exception );
if( p_input != NULL )
{
var_SetInteger( p_input, "state", PAUSE_S );
}
else
{
RAISE( mediacontrol_InternalException, "No input" );
}
libvlc_exception_init( &ex );
libvlc_media_player_pause( self->p_media_player, &ex );
HANDLE_LIBVLC_EXCEPTION_VOID( &ex );
}
void
mediacontrol_stop( mediacontrol_Instance *self,
const mediacontrol_Position * a_position,
mediacontrol_Exception *exception )
{
/* FIXME: use the a_position parameter */
mediacontrol_exception_init( exception );
if( !self->p_playlist )
{
RAISE( mediacontrol_PlaylistException, "No playlist" );
}
else
playlist_Stop( self->p_playlist );
}
/**************************************************************************
* Playlist management
**************************************************************************/
void
mediacontrol_playlist_add_item( mediacontrol_Instance *self,
const char * psz_file,
mediacontrol_Exception *exception )
{
libvlc_exception_t ex;
mediacontrol_exception_init( exception );
libvlc_exception_init( &ex );
libvlc_playlist_add( self->p_instance, psz_file, psz_file, &ex );
libvlc_media_player_stop( self->p_media_player, &ex );
HANDLE_LIBVLC_EXCEPTION_VOID( &ex );
}
/**************************************************************************
* File management
**************************************************************************/
void