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

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,38 +203,21 @@ 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,
VLC_PUBLIC_API char * mediacontrol_get_mrl( mediacontrol_Instance *self,
mediacontrol_Exception *exception );
/*****************************************************************************
......@@ -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,7 +205,7 @@ mediacontrol_display_text( mediacontrol_Instance *self,
mtime_t i_now = mdate();
i_duration = 1000 * private_mediacontrol_unit_convert(
self->p_playlist->p_input,
self->p_media_player,
end->key,
mediacontrol_MediaTime,
end->value );
......@@ -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;
}
......@@ -85,11 +86,20 @@ mediacontrol_get_libvlc_instance( mediacontrol_Instance *self )
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;
libvlc_exception_t ex;
libvlc_exception_init( &ex );
retval = ( mediacontrol_Instance* )malloc( sizeof( mediacontrol_Instance ) );
if( ! retval )
......@@ -97,7 +107,8 @@ mediacontrol_new_from_instance( libvlc_instance_t* p_instance,
RAISE_NULL( mediacontrol_InternalException, "Out of memory" );
}
retval->p_instance = p_instance;
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;
}
......@@ -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,
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;
/* 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 );
psz_from = ( char * )malloc( 20 * sizeof( char ) );
if( psz_from && p_playlist->status.p_item )
/* 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;
char * psz_from;
libvlc_time_t i_from;
/* 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 );
/* 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 );
}
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_set_media( self->p_media_player, p_media, &ex );
HANDLE_LIBVLC_EXCEPTION_VOID( &ex );
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 */
libvlc_exception_t ex;
mediacontrol_exception_init( exception );
if( !self->p_playlist )
{
RAISE( mediacontrol_PlaylistException, "No playlist" );
}
else
playlist_Stop( self->p_playlist );
libvlc_exception_init( &ex );
libvlc_media_player_stop( self->p_media_player, &ex );
HANDLE_LIBVLC_EXCEPTION_VOID( &ex );
}
/**************************************************************************
* Playlist management
* File management
**************************************************************************/
void
mediacontrol_playlist_add_item( mediacontrol_Instance *self,
mediacontrol_set_mrl( mediacontrol_Instance *self,
const char * psz_file,
mediacontrol_Exception *exception )
{
libvlc_media_t * p_media;
libvlc_exception_t ex;
mediacontrol_exception_init( exception );
libvlc_exception_init( &ex );
libvlc_playlist_add( self->p_instance, psz_file, psz_file, &ex );
p_media = libvlc_media_new( self->p_instance, psz_file, &ex );
HANDLE_LIBVLC_EXCEPTION_VOID( &ex );
}
void
mediacontrol_playlist_next_item( mediacontrol_Instance *self,
mediacontrol_Exception *exception )
{
libvlc_exception_t ex;
mediacontrol_exception_init( exception );
libvlc_exception_init( &ex );
libvlc_playlist_next( self->p_instance, &ex );
libvlc_media_player_set_media( self->p_media_player, p_media, &ex );
HANDLE_LIBVLC_EXCEPTION_VOID( &ex );
}
void
mediacontrol_playlist_clear( mediacontrol_Instance *self,
char *
mediacontrol_get_mrl( mediacontrol_Instance *self,
mediacontrol_Exception *exception )
{
libvlc_media_t * p_media;
libvlc_exception_t ex;
mediacontrol_exception_init( exception );
libvlc_exception_init( &ex );
libvlc_playlist_clear( self->p_instance, &ex );
HANDLE_LIBVLC_EXCEPTION_VOID( &ex );
}
mediacontrol_PlaylistSeq *
mediacontrol_playlist_get_list( mediacontrol_Instance *self,
mediacontrol_Exception *exception )
{
mediacontrol_PlaylistSeq *retval = NULL;
int i_index;
playlist_t * p_playlist = self->p_playlist;
playlist_item_t *p_root;
int i_playlist_size;
p_media = libvlc_media_player_get_media( self->p_media_player, &ex );
HANDLE_LIBVLC_EXCEPTION_NULL( &ex );
mediacontrol_exception_init( exception );
if( !p_playlist )
if ( ! p_media )
{
RAISE( mediacontrol_PlaylistException, "No playlist" );
return NULL;
return strdup( "" );
}
vlc_mutex_lock( &p_playlist->object_lock );
p_root = p_playlist->p_root_onelevel->pp_children[0];
i_playlist_size = p_root->i_children;
retval = private_mediacontrol_PlaylistSeq__alloc( i_playlist_size );
for( i_index = 0 ; i_index < i_playlist_size ; i_index++ )
else
{
retval->data[i_index] = strdup( p_root->pp_children[i_index]->p_input->psz_name );
}
vlc_mutex_unlock( &p_playlist->object_lock );
char * psz_mrl;
return retval;
psz_mrl = libvlc_media_get_mrl( p_media, &ex );
HANDLE_LIBVLC_EXCEPTION_NULL( &ex );
return psz_mrl;
}
}
/***************************************************************************
......@@ -369,8 +330,10 @@ mediacontrol_get_stream_information( mediacontrol_Instance *self,
mediacontrol_Exception *exception )
{
mediacontrol_StreamInformation *retval = NULL;
input_thread_t *p_input = self->p_playlist->p_input;
vlc_value_t val;
libvlc_media_t * p_media;
libvlc_exception_t ex;
libvlc_exception_init( &ex );
retval = ( mediacontrol_StreamInformation* )
malloc( sizeof( mediacontrol_StreamInformation ) );
......@@ -380,9 +343,11 @@ mediacontrol_get_stream_information( mediacontrol_Instance *self,
return NULL;
}
if( ! p_input )
p_media = libvlc_media_player_get_media( self->p_media_player, &ex );
HANDLE_LIBVLC_EXCEPTION_NULL( &ex );
if( ! p_media )
{
/* No p_input defined */
/* No p_media defined */
retval->streamstatus = mediacontrol_UndefinedStatus;
retval->url = strdup( "None" );
retval->position = 0;
......@@ -390,18 +355,24 @@ mediacontrol_get_stream_information( mediacontrol_Instance *self,
}
else
{
switch( var_GetInteger( p_input, "state" ) )
libvlc_state_t state;
state = libvlc_media_player_get_state( self->p_media_player, &ex );
HANDLE_LIBVLC_EXCEPTION_NULL( &ex );
switch( state )
{
case PLAYING_S :
case libvlc_Playing :
retval->streamstatus = mediacontrol_PlayingStatus;
break;
case PAUSE_S :
case libvlc_Paused :
retval->streamstatus = mediacontrol_PauseStatus;
break;
case INIT_S :
case libvlc_Opening :
case libvlc_Buffering:
retval->streamstatus = mediacontrol_InitStatus;
break;
case END_S :
case libvlc_Stopped:
case libvlc_Ended:
retval->streamstatus = mediacontrol_EndStatus;
break;
default :
......@@ -409,19 +380,17 @@ mediacontrol_get_stream_information( mediacontrol_Instance *self,
break;
}
retval->url = input_item_GetURI( input_GetItem( p_input ) );
retval->url = libvlc_media_get_mrl( p_media, &ex );
/* TIME and LENGTH are in microseconds. We want them in ms */
var_Get( p_input, "time", &val);
retval->position = val.i_time / 1000;
retval->position = libvlc_media_player_get_time( self->p_media_player, &ex );
var_Get( p_input, "length", &val);
retval->length = val.i_time / 1000;
retval->length = libvlc_media_player_get_length( self->p_media_player, &ex );
retval->position = private_mediacontrol_unit_convert( p_input,
retval->position = private_mediacontrol_unit_convert( self->p_media_player,
mediacontrol_MediaTime, a_key,
retval->position );
retval->length = private_mediacontrol_unit_convert( p_input,
retval->length = private_mediacontrol_unit_convert( self->p_media_player,
mediacontrol_MediaTime, a_key,
retval->length );
}
......
......@@ -30,19 +30,19 @@ extern "C" {
#include <vlc/vlc.h>
#include <vlc/mediacontrol_structures.h>
#include "libvlc_internal.h"
#include <vlc/libvlc_structures.h>
#include <vlc/libvlc.h>
struct mediacontrol_Instance {
struct libvlc_instance_t * p_instance;
playlist_t *p_playlist;
libvlc_instance_t * p_instance;
libvlc_media_player_t * p_media_player;
};
vlc_int64_t private_mediacontrol_unit_convert( input_thread_t *p_input,
libvlc_time_t private_mediacontrol_unit_convert( libvlc_media_player_t *p_media_player,
mediacontrol_PositionKey from,
mediacontrol_PositionKey to,
vlc_int64_t value );
vlc_int64_t private_mediacontrol_position2microsecond( input_thread_t *p_input,
libvlc_time_t private_mediacontrol_position2microsecond( libvlc_media_player_t *p_media_player,
const mediacontrol_Position *pos );
/**
......@@ -53,8 +53,6 @@ mediacontrol_RGBPicture *private_mediacontrol_RGBPicture__alloc( int datasize );
mediacontrol_RGBPicture *private_mediacontrol_createRGBPicture( int, int, long, vlc_int64_t l_date, char *, int);
mediacontrol_PlaylistSeq *private_mediacontrol_PlaylistSeq__alloc( int size );
#define RAISE( c, m ) if( exception ) { exception->code = c; \
exception->message = strdup(m); }
......
......@@ -26,11 +26,7 @@
#endif
#include <vlc/mediacontrol.h>
#include <vlc_interface.h>
#include <vlc_aout.h>
#include <vlc_input.h>
#include <vlc_demux.h>
#include <vlc/libvlc.h>
#include <vlc_vout.h>
#include <vlc_osd.h>
......@@ -53,10 +49,7 @@
# include <sys/types.h>
#endif
/* FIXME: Need to stop accessing private input structures !! */
#include "input/input_internal.h"
vlc_int64_t private_mediacontrol_unit_convert( input_thread_t *p_input,
libvlc_time_t private_mediacontrol_unit_convert( libvlc_media_player_t *p_media_player,
mediacontrol_PositionKey from,
mediacontrol_PositionKey to,
vlc_int64_t value )
......@@ -64,8 +57,7 @@ vlc_int64_t private_mediacontrol_unit_convert( input_thread_t *p_input,
if( to == from )
return value;
/* For all conversions, we need data from p_input */
if( !p_input )
if( !p_media_player )
return 0;
switch( from )
......@@ -73,7 +65,7 @@ vlc_int64_t private_mediacontrol_unit_convert( input_thread_t *p_input,
case mediacontrol_MediaTime:
if( to == mediacontrol_ByteCount )
{
/* FIXME */
/* FIXME Unsupported */
/* vlc < 0.8 API */
/* return value * 50 * p_input->stream.i_mux_rate / 1000; */
return 0;
......@@ -81,8 +73,11 @@ vlc_int64_t private_mediacontrol_unit_convert( input_thread_t *p_input,
if( to == mediacontrol_SampleCount )
{
double f_fps;
libvlc_exception_t ex;
libvlc_exception_init( &ex );
if( demux_Control( p_input->p->input.p_demux, DEMUX_GET_FPS, &f_fps ) || f_fps < 0.1 )
f_fps = libvlc_media_player_get_rate( p_media_player, &ex );
if( f_fps < 0 )
return 0;
else
return( value * f_fps / 1000.0 );
......@@ -94,9 +89,11 @@ vlc_int64_t private_mediacontrol_unit_convert( input_thread_t *p_input,
case mediacontrol_SampleCount:
{
double f_fps;
libvlc_exception_t ex;
libvlc_exception_init( &ex );
if( demux_Control( p_input->p->input.p_demux, DEMUX_GET_FPS, &f_fps ) ||
f_fps < 0.1 )
f_fps = libvlc_media_player_get_rate( p_media_player, &ex );
if( f_fps < 0 )
return 0;
if( to == mediacontrol_ByteCount )
......@@ -116,28 +113,6 @@ vlc_int64_t private_mediacontrol_unit_convert( input_thread_t *p_input,
case mediacontrol_ByteCount:
/* FIXME */
return 0;
/* vlc < 0.8 API: */
// if( p_input->stream.i_mux_rate == 0 )
// return 0;
//
// /* Convert an offset into milliseconds. Taken from input_ext-intf.c.
// The 50 hardcoded constant comes from the definition of i_mux_rate :
// i_mux_rate : the rate we read the stream (in units of 50 bytes/s) ;
// 0 if undef */
// if( to == mediacontrol_MediaTime )
// return ( vlc_int64_t )( 1000 * value / 50 / p_input->stream.i_mux_rate );
//
// if( to == mediacontrol_SampleCount )
// {
// double f_fps;
// if( demux_Control( p_input->input.p_demux, DEMUX_GET_FPS, &f_fps ) || f_fps < 0.1 )
// return 0;
// else
// return ( vlc_int64_t )( value * f_fps / 50 / p_input->stream.i_mux_rate );
// }
/* Cannot happen */
break;
}
/* Cannot happen */
return 0;
......@@ -145,57 +120,56 @@ vlc_int64_t private_mediacontrol_unit_convert( input_thread_t *p_input,
/* Converts a mediacontrol_Position into a time in microseconds in
movie clock time */
vlc_int64_t
private_mediacontrol_position2microsecond( input_thread_t* p_input, const mediacontrol_Position * pos )
libvlc_time_t
private_mediacontrol_position2microsecond( libvlc_media_player_t * p_media_player,
const mediacontrol_Position * pos )
{
switch( pos->origin )
{
case mediacontrol_AbsolutePosition:
return ( 1000 * private_mediacontrol_unit_convert( p_input,
return ( 1000 * private_mediacontrol_unit_convert( p_media_player,
pos->key, /* from */
mediacontrol_MediaTime, /* to */
pos->value ) );
break;
case mediacontrol_RelativePosition:
{
vlc_int64_t l_pos;
vlc_value_t val;
libvlc_time_t l_time = 0;
libvlc_time_t l_pos = 0;
libvlc_exception_t ex;
libvlc_exception_init( &ex );
val.i_time = 0;
if( p_input )
{
var_Get( p_input, "time", &val );
}
l_time = libvlc_media_player_get_time( p_media_player, &ex );
/* Ignore exception, we will assume a 0 time value */
l_pos = 1000 * private_mediacontrol_unit_convert( p_input,
l_pos = 1000 * private_mediacontrol_unit_convert( p_media_player,
pos->key,
mediacontrol_MediaTime,
pos->value );
return val.i_time + l_pos;
return l_time + l_pos;
break;
}
case mediacontrol_ModuloPosition:
{
vlc_int64_t l_pos;
vlc_value_t val;
libvlc_time_t l_time = 0;
libvlc_time_t l_length = 0;
libvlc_time_t l_pos = 0;
libvlc_exception_t ex;
libvlc_exception_init( &ex );
l_length = libvlc_media_player_get_length( p_media_player, &ex );
if( l_length <= 0 )
return 0;
val.i_time = 0;
if( p_input )
{
var_Get( p_input, "length", &val );
}
l_time = libvlc_media_player_get_time( p_media_player, &ex );
/* Ignore exception, we will assume a 0 time value */
if( val.i_time > 0)
{
l_pos = ( 1000 * private_mediacontrol_unit_convert( p_input,
l_pos = ( 1000 * private_mediacontrol_unit_convert( p_media_player,
pos->key,
mediacontrol_MediaTime,
pos->value ) );
}
else
l_pos = 0;
return l_pos % val.i_time;
return ( l_time + l_pos ) % l_length;
break;
}
}
......@@ -226,33 +200,6 @@ mediacontrol_RGBPicture__free( mediacontrol_RGBPicture* pic )
}
}
mediacontrol_PlaylistSeq*
private_mediacontrol_PlaylistSeq__alloc( int size )
{
mediacontrol_PlaylistSeq* ps;
ps =( mediacontrol_PlaylistSeq* )malloc( sizeof( mediacontrol_PlaylistSeq ) );
if( ! ps )
return NULL;
ps->size = size;
ps->data = ( char** )malloc( size * sizeof( char* ) );
return ps;
}
void
mediacontrol_PlaylistSeq__free( mediacontrol_PlaylistSeq* ps )
{
if( ps )
{
int i;
for( i = 0 ; i < ps->size ; i++ )
free( ps->data[i] );
free( ps->data );
free( ps );
}
}
void
mediacontrol_StreamInformation__free( mediacontrol_StreamInformation* p_si )
{
......
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