X-Git-Url: https://git.sesse.net/?a=blobdiff_plain;f=src%2Fcontrol%2Fmediacontrol_core.c;h=7ab5e8f557439f08fa137c64272d45a35b81ec82;hb=148630710d221cd81ac64e34c3c67735db3c0f0d;hp=a265d3a2fa9aba13af581a2f76f2d72e1d014bc4;hpb=857b51f9c9ace345a6b6a9a45a20829101830abb;p=vlc diff --git a/src/control/mediacontrol_core.c b/src/control/mediacontrol_core.c index a265d3a2fa..7ab5e8f557 100644 --- a/src/control/mediacontrol_core.c +++ b/src/control/mediacontrol_core.c @@ -21,117 +21,87 @@ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA. *****************************************************************************/ -#include +#ifdef HAVE_CONFIG_H +# include "config.h" +#endif + +#include "mediacontrol_internal.h" #include #include -#include -#include -#include -#include +#include +#include +#include +#include +#include +#include #include -#define HAS_SNAPSHOT 1 - -#ifdef HAS_SNAPSHOT -#include -#endif - #include /* malloc(), free() */ #include -#include /* ENOMEM */ #include -#include #ifdef HAVE_UNISTD_H # include #endif -#ifdef HAVE_SYS_TIME_H -# include -#endif -#ifdef HAVE_SYS_TYPES_H -# include -#endif +#include -mediacontrol_Instance* mediacontrol_new( char** args, mediacontrol_Exception *exception ) +mediacontrol_Instance* mediacontrol_new( int argc, char** argv, mediacontrol_Exception *exception ) { mediacontrol_Instance* retval; libvlc_exception_t ex; - char **ppsz_argv; - int i_count = 0; - int i_index; - char **p_tmp; libvlc_exception_init( &ex ); - exception=mediacontrol_exception_init( exception ); - - /* Copy args array */ - if( args ) - { - for ( p_tmp = args ; *p_tmp != NULL ; p_tmp++ ) - i_count++; - } - - ppsz_argv = malloc( ( i_count + 2 ) * sizeof( char * ) ) ; - if( ! ppsz_argv ) - { - RAISE_NULL( mediacontrol_InternalException, "out of memory" ); - } - ppsz_argv[0] = "vlc"; - for ( i_index = 0; i_index < i_count; i_index++ ) - { - ppsz_argv[i_index + 1] = strdup( args[i_index] ); - if( ! ppsz_argv[i_index + 1] ) - { - RAISE_NULL( mediacontrol_InternalException, "out of memory" ); - } - } - - ppsz_argv[i_count + 2] = NULL; + mediacontrol_exception_init( exception ); retval = ( mediacontrol_Instance* )malloc( sizeof( mediacontrol_Instance ) ); - if( ! retval ) - { - RAISE_NULL( mediacontrol_InternalException, "out of memory" ); - } + if( !retval ) + RAISE_NULL( mediacontrol_InternalException, "Out of memory" ); - retval->p_instance = libvlc_new( i_count + 1, ppsz_argv, &ex ); - retval->p_playlist = retval->p_instance->p_libvlc_int->p_playlist; + retval->p_instance = libvlc_new( argc, (const char**)argv, &ex ); HANDLE_LIBVLC_EXCEPTION_NULL( &ex ); - return retval; -}; + retval->p_media_player = libvlc_media_player_new( retval->p_instance ); + if( !retval->p_media_player ) + RAISE_NULL( mediacontrol_InternalException, "Out of memory" ); + return retval; +} void mediacontrol_exit( mediacontrol_Instance *self ) { - libvlc_exception_t ex; - libvlc_exception_init( &ex ); - - libvlc_destroy( self->p_instance, &ex ); + libvlc_release( self->p_instance ); } 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_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; + + 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 ); + if( ! retval->p_media_player ) + RAISE_NULL( mediacontrol_InternalException, "Out of memory" ); + return retval; } /************************************************************************** @@ -144,49 +114,36 @@ mediacontrol_get_media_position( mediacontrol_Instance *self, mediacontrol_Exception *exception ) { mediacontrol_Position* retval = NULL; - libvlc_exception_t ex; - vlc_int64_t pos; - libvlc_input_t * p_input; + int64_t pos; - exception = mediacontrol_exception_init( exception ); - libvlc_exception_init( &ex ); + mediacontrol_exception_init( exception ); retval = ( mediacontrol_Position* )malloc( sizeof( mediacontrol_Position ) ); retval->origin = an_origin; retval->key = a_key; - p_input = libvlc_playlist_get_input( self->p_instance, &ex); - HANDLE_LIBVLC_EXCEPTION_NULL( &ex ); - if( an_origin != mediacontrol_AbsolutePosition ) { - libvlc_input_free( p_input ); + free( retval ); /* Relative or ModuloPosition make no sense */ RAISE_NULL( mediacontrol_PositionOriginNotSupported, "Only absolute position is valid." ); } /* We are asked for an AbsolutePosition. */ - pos = libvlc_input_get_time( p_input, &ex ); + pos = libvlc_media_player_get_time( self->p_media_player ); if( a_key == mediacontrol_MediaTime ) { - retval->value = pos / 1000; + retval->value = pos; } else { - if( ! self->p_playlist->p_input ) - { - libvlc_input_free( p_input ); - RAISE_NULL( mediacontrol_InternalException, - "No input" ); - } - retval->value = mediacontrol_unit_convert( self->p_playlist->p_input, - mediacontrol_MediaTime, - a_key, - pos / 1000 ); + retval->value = private_mediacontrol_unit_convert( self->p_media_player, + mediacontrol_MediaTime, + a_key, + pos ); } - libvlc_input_free( p_input ); return retval; } @@ -196,20 +153,12 @@ mediacontrol_set_media_position( mediacontrol_Instance *self, const mediacontrol_Position * a_position, mediacontrol_Exception *exception ) { - libvlc_input_t * p_input; - libvlc_exception_t ex; - vlc_int64_t i_pos; + int64_t i_pos; - libvlc_exception_init( &ex ); mediacontrol_exception_init( exception ); - p_input = libvlc_playlist_get_input( self->p_instance, &ex); - HANDLE_LIBVLC_EXCEPTION_VOID( &ex ); - - i_pos = mediacontrol_position2microsecond( self->p_playlist->p_input, a_position ); - libvlc_input_set_time( p_input, i_pos, &ex ); - libvlc_input_free( p_input ); - HANDLE_LIBVLC_EXCEPTION_VOID( &ex ); + i_pos = private_mediacontrol_position2microsecond( self->p_media_player, a_position ); + libvlc_media_player_set_time( self->p_media_player, i_pos / 1000 ); } /* Starts playing a stream */ @@ -217,7 +166,7 @@ mediacontrol_set_media_position( mediacontrol_Instance *self, * Known issues: since moving in the playlist using playlist_Next * or playlist_Prev implies starting to play items, the a_position * argument will be only honored for the 1st item in the list. - * + * * XXX:FIXME split moving in the playlist and playing items two * different actions or make playlist_ accept a time * value to start to play from. @@ -227,167 +176,119 @@ 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 ); + libvlc_exception_init( &ex ); + + p_media = libvlc_media_player_get_media( self->p_media_player ); - exception = mediacontrol_exception_init( exception ); - if( ! p_playlist ) + 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->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 ); + HANDLE_LIBVLC_EXCEPTION_VOID( &ex ); - psz_from = ( char * )malloc( 20 * sizeof( char ) ); - if( psz_from && p_playlist->status.p_item ) - { - i_from = mediacontrol_position2microsecond( p_playlist->p_input, a_position ) / 1000000; + /* Create a new media */ + p_media = libvlc_media_new( self->p_instance, psz_name, &ex ); + HANDLE_LIBVLC_EXCEPTION_VOID( &ex ); - /* 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 ); + if( a_position->value ) + { + 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=%"PRId64, i_from ); + libvlc_media_add_option( p_media, psz_from ); + 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 ); + + libvlc_media_player_play( self->p_media_player ); } } void mediacontrol_pause( mediacontrol_Instance *self, - const mediacontrol_Position * a_position, mediacontrol_Exception *exception ) { - input_thread_t *p_input = self->p_playlist->p_input; - - /* FIXME: use the a_position parameter */ - exception=mediacontrol_exception_init( exception ); - if( p_input != NULL ) - { - var_SetInteger( p_input, "state", PAUSE_S ); - } - else - { - RAISE( mediacontrol_InternalException, "No input" ); - } + mediacontrol_exception_init( exception ); + libvlc_media_player_pause( self->p_media_player ); } void mediacontrol_resume( mediacontrol_Instance *self, - const mediacontrol_Position * a_position, mediacontrol_Exception *exception ) { - input_thread_t *p_input = self->p_playlist->p_input; - - /* FIXME: use the a_position parameter */ - exception=mediacontrol_exception_init( exception ); - if( p_input != NULL ) - { - var_SetInteger( p_input, "state", PAUSE_S ); - } - else - { - RAISE( mediacontrol_InternalException, "No input" ); - } + mediacontrol_exception_init( exception ); + libvlc_media_player_pause( self->p_media_player ); } void mediacontrol_stop( mediacontrol_Instance *self, - const mediacontrol_Position * a_position, mediacontrol_Exception *exception ) { - /* FIXME: use the a_position parameter */ - exception=mediacontrol_exception_init( exception ); - if( !self->p_playlist ) - { - RAISE( mediacontrol_PlaylistException, "No playlist" ); - } - else - playlist_Stop( self->p_playlist ); + mediacontrol_exception_init( exception ); + libvlc_media_player_stop( self->p_media_player ); } /************************************************************************** - * Playlist management + * File management **************************************************************************/ void -mediacontrol_playlist_add_item( mediacontrol_Instance *self, - const char * psz_file, - mediacontrol_Exception *exception ) +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 ); - HANDLE_LIBVLC_EXCEPTION_VOID( &ex ); + libvlc_media_player_set_media( self->p_media_player, p_media ); } -void -mediacontrol_playlist_clear( mediacontrol_Instance *self, - mediacontrol_Exception *exception ) +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; - int i_playlist_size; + p_media = libvlc_media_player_get_media( self->p_media_player ); - exception=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 ); - i_playlist_size = p_playlist->i_size; - - retval = mediacontrol_PlaylistSeq__alloc( i_playlist_size ); - - for( i_index = 0 ; i_index < i_playlist_size ; i_index++ ) + else { - retval->data[i_index] = strdup( p_playlist->pp_items[i_index]->p_input->psz_uri ); - } - vlc_mutex_unlock( &p_playlist->object_lock ); + char * psz_mrl; - return retval; + psz_mrl = libvlc_media_get_mrl( p_media ); + HANDLE_LIBVLC_EXCEPTION_NULL( &ex ); + return psz_mrl; + } } /*************************************************************************** @@ -399,9 +300,12 @@ mediacontrol_get_stream_information( mediacontrol_Instance *self, mediacontrol_PositionKey a_key, mediacontrol_Exception *exception ) { + (void)a_key; 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 ) ); @@ -411,50 +315,55 @@ mediacontrol_get_stream_information( mediacontrol_Instance *self, return NULL; } - if( ! p_input ) + p_media = libvlc_media_player_get_media( self->p_media_player ); + if( ! p_media ) { - /* No p_input defined */ + /* No p_media defined */ retval->streamstatus = mediacontrol_UndefinedStatus; - retval->url = strdup( "None" ); + retval->url = strdup( "" ); retval->position = 0; retval->length = 0; } else { - switch( var_GetInteger( p_input, "state" ) ) + libvlc_state_t state; + + state = libvlc_media_player_get_state( self->p_media_player ); + switch( state ) { - case PLAYING_S : + case libvlc_NothingSpecial: + retval->streamstatus = mediacontrol_UndefinedStatus; + break; + case libvlc_Opening : + retval->streamstatus = mediacontrol_InitStatus; + break; + case libvlc_Buffering: + retval->streamstatus = mediacontrol_BufferingStatus; + break; + case libvlc_Playing: retval->streamstatus = mediacontrol_PlayingStatus; break; - case PAUSE_S : + case libvlc_Paused: retval->streamstatus = mediacontrol_PauseStatus; break; - case INIT_S : - retval->streamstatus = mediacontrol_InitStatus; + case libvlc_Stopped: + retval->streamstatus = mediacontrol_StopStatus; break; - case END_S : + case libvlc_Ended: retval->streamstatus = mediacontrol_EndStatus; break; + case libvlc_Error: + retval->streamstatus = mediacontrol_ErrorStatus; + break; default : retval->streamstatus = mediacontrol_UndefinedStatus; break; } - retval->url = strdup( p_input->input.p_item->psz_uri ); - - /* TIME and LENGTH are in microseconds. We want them in ms */ - var_Get( p_input, "time", &val); - retval->position = val.i_time / 1000; - - var_Get( p_input, "length", &val); - retval->length = val.i_time / 1000; + retval->url = libvlc_media_get_mrl( p_media ); - retval->position = mediacontrol_unit_convert( p_input, - mediacontrol_MediaTime, a_key, - retval->position ); - retval->length = mediacontrol_unit_convert( p_input, - mediacontrol_MediaTime, a_key, - retval->length ); + retval->position = libvlc_media_player_get_time( self->p_media_player ); + retval->length = libvlc_media_player_get_length( self->p_media_player ); } return retval; }