X-Git-Url: https://git.sesse.net/?a=blobdiff_plain;ds=sidebyside;f=modules%2Fmisc%2Fdummy%2Finput.c;h=cb7b39129fb0ae2f7cc6687941e9b026676ccd12;hb=a68a5ff4f7161e5681f0426868d477ae2acf78c6;hp=af93d5320e65dc92244adc136bd3978f6549ee7f;hpb=434bd50cda912314c62b33e5e6c5fcd4aa3d886a;p=vlc diff --git a/modules/misc/dummy/input.c b/modules/misc/dummy/input.c index af93d5320e..cb7b39129f 100644 --- a/modules/misc/dummy/input.c +++ b/modules/misc/dummy/input.c @@ -31,103 +31,93 @@ #include #include -#include #include +#include #include "dummy.h" -/***************************************************************************** - * Access functions. - *****************************************************************************/ -static ssize_t AccessRead( access_t *p_access, uint8_t *p, size_t i_size ) +static int DemuxControl( demux_t *, int, va_list ); + +static int DemuxNoOp( demux_t *demux ) { - VLC_UNUSED(p_access); - memset( p, 0, i_size ); - return i_size; + (void) demux; + return 0; } -static int AccessControl( access_t *p_access, int i_query, va_list args ) -{ - bool *pb_bool; - int64_t *pi_64; - switch( i_query ) - { - /* */ - case ACCESS_CAN_SEEK: - case ACCESS_CAN_FASTSEEK: - case ACCESS_CAN_PAUSE: - case ACCESS_CAN_CONTROL_PACE: - pb_bool = (bool*)va_arg( args, bool* ); - *pb_bool = false; - break; +struct demux_sys_t +{ + mtime_t end; + mtime_t length; +}; - /* */ - case ACCESS_GET_PTS_DELAY: - pi_64 = (int64_t*)va_arg( args, int64_t * ); - *pi_64 = DEFAULT_PTS_DELAY * 1000; - break; +static int DemuxPause( demux_t *demux ) +{ + demux_sys_t *p_sys = demux->p_sys; + mtime_t now = mdate(); - /* */ - case ACCESS_SET_PAUSE_STATE: - case ACCESS_GET_TITLE_INFO: - case ACCESS_GET_META: - case ACCESS_SET_TITLE: - case ACCESS_SET_SEEKPOINT: - return VLC_EGENERIC; + if( now >= p_sys->end ) + return 0; - default: - msg_Err( p_access, "unimplemented query in control" ); - return VLC_EGENERIC; - } - return VLC_SUCCESS; + msleep( 10000 ); /* FIXME!!! */ + return 1; } -int OpenAccess( vlc_object_t *p_this ) +static int ControlPause( demux_t *demux, int query, va_list args ) { - access_t *p_access = (access_t*)p_this; - - /* Init p_access */ - p_access->pf_read = AccessRead; - p_access->pf_block = NULL; - p_access->pf_seek = NULL; - p_access->pf_control = AccessControl; - p_access->info.i_update = 0; - p_access->info.i_size = 0; - p_access->info.i_pos = 0; - p_access->info.b_eof = false; - p_access->info.i_title = 0; - p_access->info.i_seekpoint = 0; - p_access->p_sys = NULL; - - /* Force dummy demux plug-in */ - free( p_access->psz_demux ); - p_access->psz_demux = strdup( "vlc" ); + demux_sys_t *p_sys = demux->p_sys; - return VLC_SUCCESS; -} + switch( query ) + { + case DEMUX_GET_POSITION: + { + double *ppos = va_arg( args, double * ); + double pos; + mtime_t now = mdate(); + + pos = 1. + ((double)(now - p_sys->end) / (double)p_sys->length); + *ppos = (pos <= 1.) ? pos : 1.; + break; + } + case DEMUX_SET_POSITION: + { + double pos = va_arg( args, double ); + mtime_t now = mdate(); -/***************************************************************************** - * Demux - *****************************************************************************/ -struct demux_sys_t -{ - /* The real command */ - int i_command; + p_sys->end = now + (p_sys->length * (1. - pos)); + break; + } - /* Used for the pause command */ - mtime_t expiration; -}; -enum -{ - COMMAND_NOP = 0, - COMMAND_QUIT = 1, - COMMAND_PAUSE= 3, -}; + case DEMUX_GET_LENGTH: + { + mtime_t *plen = va_arg( args, mtime_t * ); + *plen = p_sys->length; + break; + } -static int Demux( demux_t * ); -static int DemuxControl( demux_t *, int, va_list ); + case DEMUX_GET_TIME: + { + mtime_t *ppos = va_arg( args, mtime_t * ); + *ppos = mdate() + p_sys->length - p_sys->end; + break; + } + + case DEMUX_SET_TIME: + { + mtime_t pos = va_arg( args, mtime_t ); + p_sys->end = mdate() + p_sys->length - pos; + break; + } + + case DEMUX_CAN_SEEK: + *va_arg( args, bool * ) = true; + break; + default: + return DemuxControl( demux, query, args ); + } + return VLC_SUCCESS; +} /***************************************************************************** * OpenDemux: initialize the target, ie. parse the command @@ -137,43 +127,52 @@ int OpenDemux ( vlc_object_t *p_this ) demux_t *p_demux = (demux_t*)p_this; char * psz_name = p_demux->psz_path; - int i_len = strlen( psz_name ); - demux_sys_t *p_sys; - int i_arg; - - p_demux->pf_demux = Demux; - p_demux->pf_control = DemuxControl; - p_demux->p_sys = p_sys = malloc( sizeof( demux_sys_t ) ); + p_demux->p_sys = NULL; /* Check for a "vlc://nop" command */ - if( i_len == 3 && !strncasecmp( psz_name, "nop", 3 ) ) + if( !strcasecmp( psz_name, "nop" ) ) { +nop: msg_Info( p_demux, "command `nop'" ); - p_sys->i_command = COMMAND_NOP; + p_demux->pf_demux = DemuxNoOp; + p_demux->pf_control = DemuxControl; return VLC_SUCCESS; } /* Check for a "vlc://quit" command */ - if( i_len == 4 && !strncasecmp( psz_name, "quit", 4 ) ) + if( !strcasecmp( psz_name, "quit" ) ) { msg_Info( p_demux, "command `quit'" ); - p_sys->i_command = COMMAND_QUIT; + p_demux->pf_demux = DemuxNoOp; + p_demux->pf_control = DemuxControl; + libvlc_Quit( p_demux->p_libvlc ); return VLC_SUCCESS; } /* Check for a "vlc://pause:***" command */ - if( i_len > 6 && !strncasecmp( psz_name, "pause:", 6 ) ) + if( !strncasecmp( psz_name, "pause:", 6 ) ) { - i_arg = atoi( psz_name + 6 ); - msg_Info( p_demux, "command `pause %i'", i_arg ); - p_sys->i_command = COMMAND_PAUSE; - p_sys->expiration = mdate() + (mtime_t)i_arg * (mtime_t)1000000; + double f = us_atof( psz_name + 6 ); + mtime_t length = f * CLOCK_FREQ; + + msg_Info( p_demux, "command `pause %f'", f ); + if( length == 0 ) + goto nop; /* avoid division by zero */ + + demux_sys_t *p_sys = malloc( sizeof( *p_sys ) ); + if( p_sys == NULL ) + return VLC_ENOMEM; + + p_sys->end = mdate() + length; + p_sys->length = length; + + p_demux->p_sys = p_sys; + p_demux->pf_demux = DemuxPause; + p_demux->pf_control = ControlPause; return VLC_SUCCESS; } msg_Err( p_demux, "unknown command `%s'", psz_name ); - - free( p_sys ); return VLC_EGENERIC; } @@ -187,40 +186,18 @@ void CloseDemux ( vlc_object_t *p_this ) free( p_demux->p_sys ); } -/***************************************************************************** - * Demux: do what the command says - *****************************************************************************/ -static int Demux( demux_t *p_demux ) +static int DemuxControl( demux_t *p_demux, int i_query, va_list args ) { - demux_sys_t *p_sys = p_demux->p_sys; - bool b_eof = false; - - switch( p_sys->i_command ) + (void)p_demux; (void)i_query; (void)args; + switch( i_query ) { - case COMMAND_QUIT: - b_eof = true; - libvlc_Quit( p_demux->p_libvlc ); - break; - - case COMMAND_PAUSE: - if( mdate() >= p_sys->expiration ) - b_eof = true; - else - msleep( 10000 ); - break; - - case COMMAND_NOP: - default: - b_eof = true; - break; + case DEMUX_GET_PTS_DELAY: + { + int64_t *pi_pts_delay = va_arg( args, int64_t * ); + *pi_pts_delay = DEFAULT_PTS_DELAY; + return VLC_SUCCESS; + } + default: + return VLC_EGENERIC; } - - return b_eof ? 0 : 1; -} - -static int DemuxControl( demux_t *p_demux, int i_query, va_list args ) -{ - return demux_vaControlHelper( p_demux->s, - 0, 0, 0, 1, - i_query, args ); }