X-Git-Url: https://git.sesse.net/?a=blobdiff_plain;f=src%2Fcontrol%2Fmediacontrol_util.c;h=b34dfa38feb41df6fa3dfabf4fda37a9712b4929;hb=c691aa044dbe28929104a7d31eda24e2f254f450;hp=c7133d4b807663d871a1f80d65de23d7834760ed;hpb=470b47fe952dbba82beca44cafefd4b6ec711384;p=vlc diff --git a/src/control/mediacontrol_util.c b/src/control/mediacontrol_util.c index c7133d4b80..b34dfa38fe 100644 --- a/src/control/mediacontrol_util.c +++ b/src/control/mediacontrol_util.c @@ -21,52 +21,36 @@ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA. *****************************************************************************/ -#include -#include +#ifdef HAVE_CONFIG_H +# include "config.h" +#endif -#include -#include -#include -#include +#include "mediacontrol_internal.h" +#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 - -#define RAISE( c, m ) exception->code = c; \ - exception->message = strdup(m); +#include -vlc_int64_t mediacontrol_unit_convert( input_thread_t *p_input, - mediacontrol_PositionKey from, - mediacontrol_PositionKey to, - vlc_int64_t value ) +libvlc_time_t private_mediacontrol_unit_convert( libvlc_media_player_t *p_media_player, + mediacontrol_PositionKey from, + mediacontrol_PositionKey to, + int64_t value ) { 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 ) @@ -74,7 +58,7 @@ vlc_int64_t 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; @@ -82,34 +66,39 @@ vlc_int64_t mediacontrol_unit_convert( input_thread_t *p_input, if( to == mediacontrol_SampleCount ) { double f_fps; + libvlc_exception_t ex; + libvlc_exception_init( &ex ); - if( demux2_Control( p_input->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 ); } /* Cannot happen */ - /* See http://catb.org/~esr/jargon/html/entry/can't-happen.html */ + /* See http://catb.org/~esr/jargon/html/entry/can-t-happen.html */ break; case mediacontrol_SampleCount: { double f_fps; + libvlc_exception_t ex; + libvlc_exception_init( &ex ); - if( demux2_Control( p_input->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 ) { /* FIXME */ /* vlc < 0.8 API */ -/* return ( vlc_int64_t )( value * 50 * p_input->stream.i_mux_rate / f_fps ); */ +/* return ( int64_t )( value * 50 * p_input->stream.i_mux_rate / f_fps ); */ return 0; } if( to == mediacontrol_MediaTime ) - return( vlc_int64_t )( value * 1000.0 / ( double )f_fps ); + return( int64_t )( value * 1000.0 / ( double )f_fps ); /* Cannot happen */ break; @@ -117,28 +106,6 @@ vlc_int64_t 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( demux2_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; @@ -146,142 +113,136 @@ vlc_int64_t mediacontrol_unit_convert( input_thread_t *p_input, /* Converts a mediacontrol_Position into a time in microseconds in movie clock time */ -vlc_int64_t -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 * 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; - - val.i_time = 0; - if( p_input ) - { - var_Get( p_input, "time", &val ); - } - - l_pos = 1000 * mediacontrol_unit_convert( p_input, - pos->key, - mediacontrol_MediaTime, - pos->value ); - return val.i_time + l_pos; + libvlc_time_t l_time = 0; + libvlc_time_t l_pos = 0; + libvlc_exception_t ex; + libvlc_exception_init( &ex ); + + l_time = libvlc_media_player_get_time( p_media_player, &ex ); + /* Ignore exception, we will assume a 0 time value */ + + l_pos = private_mediacontrol_unit_convert( p_media_player, + pos->key, + mediacontrol_MediaTime, + pos->value ); + return 1000 * ( 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 * mediacontrol_unit_convert( p_input, - pos->key, - mediacontrol_MediaTime, - pos->value ) ); - } - else - l_pos = 0; + l_pos = private_mediacontrol_unit_convert( p_media_player, + pos->key, + mediacontrol_MediaTime, + pos->value ); - return l_pos % val.i_time; + return 1000 * ( ( l_time + l_pos ) % l_length ); break; } } return 0; } -mediacontrol_RGBPicture* -mediacontrol_RGBPicture__alloc( int datasize ) -{ - mediacontrol_RGBPicture* pic; - - pic = ( mediacontrol_RGBPicture * )malloc( sizeof( mediacontrol_RGBPicture ) ); - if( ! pic ) - return NULL; - - pic->size = datasize; - pic->data = ( char* )malloc( datasize * sizeof( char ) ); - return pic; -} - void mediacontrol_RGBPicture__free( mediacontrol_RGBPicture* pic ) { if( pic ) + { free( pic->data ); - free( pic ); + free( pic ); + } } -mediacontrol_PlaylistSeq* -mediacontrol_PlaylistSeq__alloc( int size ) +void +mediacontrol_StreamInformation__free( mediacontrol_StreamInformation* p_si ) { - mediacontrol_PlaylistSeq* ps; + if( p_si ) + { + free( p_si->url ); + free( p_si ); + } +} + - ps =( mediacontrol_PlaylistSeq* )malloc( sizeof( mediacontrol_PlaylistSeq ) ); - if( ! ps ) - return NULL; +mediacontrol_Exception* +mediacontrol_exception_create( void ) +{ + mediacontrol_Exception* exception; - ps->size = size; - ps->data = ( char** )malloc( size * sizeof( char* ) ); - return ps; + exception = ( mediacontrol_Exception* )malloc( sizeof( mediacontrol_Exception ) ); + mediacontrol_exception_init( exception ); + return exception; } void -mediacontrol_PlaylistSeq__free( mediacontrol_PlaylistSeq* ps ) +mediacontrol_exception_init( mediacontrol_Exception *exception ) { - if( ps ) + if( exception ) { - int i; - for( i = 0 ; i < ps->size ; i++ ) - free( ps->data[i] ); + exception->code = 0; + exception->message = NULL; } - free( ps->data ); - free( ps ); } -mediacontrol_Exception* -mediacontrol_exception_init( mediacontrol_Exception *exception ) +void +mediacontrol_exception_cleanup( mediacontrol_Exception *exception ) { - if( exception == NULL ) - { - exception = ( mediacontrol_Exception* )malloc( sizeof( mediacontrol_Exception ) ); - } - - exception->code = 0; - exception->message = NULL; - return exception; + if( exception ) + free( exception->message ); } void mediacontrol_exception_free( mediacontrol_Exception *exception ) { - if( ! exception ) - return; - - free( exception->message ); + mediacontrol_exception_cleanup( exception ); free( exception ); } +/** + * Allocates and initializes a mediacontrol_RGBPicture object. + * + * @param i_width: picture width + * @param i_height: picture width + * @param i_chroma: picture chroma + * @param l_date: picture timestamp + * @param p_data: pointer to the data. The data will be directly used, not copied. + * @param i_datasize: data size in bytes + * + * @return the new object, or NULL on error. + */ mediacontrol_RGBPicture* -_mediacontrol_createRGBPicture( int i_width, int i_height, long i_chroma, vlc_int64_t l_date, - char* p_data, int i_datasize ) +private_mediacontrol_createRGBPicture( int i_width, int i_height, long i_chroma, int64_t l_date, + char* p_data, int i_datasize ) { mediacontrol_RGBPicture *retval; - retval = mediacontrol_RGBPicture__alloc( i_datasize ); + retval = ( mediacontrol_RGBPicture * )malloc( sizeof( mediacontrol_RGBPicture ) ); if( retval ) { retval->width = i_width; @@ -289,7 +250,7 @@ _mediacontrol_createRGBPicture( int i_width, int i_height, long i_chroma, vlc_in retval->type = i_chroma; retval->date = l_date; retval->size = i_datasize; - memcpy( retval->data, p_data, i_datasize ); + retval->data = p_data; } return retval; }