Browse Source

input: change rate argument

Use a float and inverse it.

Before, the int rate value for a 4x speed was 250 (INPUT_RATE_DEFAULT / 250 =
4.f).  Now, for a 4x speed, the float value will be 4.f.
pull/85/head
Thomas Guillem 7 years ago
parent
commit
6df5d5db51
  1. 4
      include/vlc_demux.h
  2. 12
      modules/access/live555.cpp
  3. 2
      modules/demux/subtitle.c
  4. 2
      src/input/es_out_timeshift.c
  5. 4
      src/input/event.h
  6. 69
      src/input/input.c
  7. 6
      src/input/input_internal.h
  8. 2
      src/input/player.c
  9. 1
      src/input/var.c

4
include/vlc_demux.h

@ -236,8 +236,8 @@ enum demux_query_e
* (using DEMUX_SET_RATE). */
DEMUX_CAN_CONTROL_RATE, /* arg1= bool*pb_rate */
/* DEMUX_SET_RATE is called only if DEMUX_CAN_CONTROL_RATE has returned true.
* It should return the value really used in *pi_rate */
DEMUX_SET_RATE, /* arg1= int*pi_rate can fail */
* It should return the value really used in *p_rate */
DEMUX_SET_RATE, /* arg1= float*p_rate res=can fail */
/** Checks whether the stream is actually a playlist, rather than a real
* stream.

12
modules/access/live555.cpp

@ -1647,8 +1647,8 @@ static int Control( demux_t *p_demux, int i_query, va_list args )
case DEMUX_SET_RATE:
{
int *pi_int;
double f_scale, f_old_scale;
float *pf_scale, f_scale;
double f_old_scale;
if( !p_sys->rtsp || (p_sys->f_npt_length <= 0) ||
!(p_sys->capabilities & CAP_RATE_CONTROL) )
@ -1668,8 +1668,8 @@ static int Control( demux_t *p_demux, int i_query, va_list args )
* Scale < 0 value indicates rewind
*/
pi_int = va_arg( args, int * );
f_scale = (double)INPUT_RATE_DEFAULT / (*pi_int);
pf_scale = va_arg( args, float * );
f_scale = *pf_scale;
f_old_scale = p_sys->ms->scale();
/* Passing -1 for the start and end time will mean liveMedia won't
@ -1696,8 +1696,8 @@ static int Control( demux_t *p_demux, int i_query, va_list args )
p_sys->i_pcr = VLC_TICK_INVALID;
p_sys->f_npt = 0.0;
*pi_int = (int)( INPUT_RATE_DEFAULT / p_sys->ms->scale() );
msg_Dbg( p_demux, "PLAY with new Scale %0.2f (%d)", p_sys->ms->scale(), (*pi_int) );
*pf_scale = p_sys->ms->scale() ;
msg_Dbg( p_demux, "PLAY with new Scale %0.2f", p_sys->ms->scale() );
return VLC_SUCCESS;
}

2
modules/demux/subtitle.c

@ -808,7 +808,7 @@ static int Control( demux_t *p_demux, int i_query, va_list args )
*va_arg( args, bool * ) = true;
return VLC_SUCCESS;
case DEMUX_SET_RATE:
p_sys->f_rate = (double)INPUT_RATE_DEFAULT / *va_arg( args, int * );
p_sys->f_rate = *va_arg( args, float * );
ResetCurrentIndex( p_demux );
return VLC_SUCCESS;
case DEMUX_SET_NEXT_DEMUX_TIME:

2
src/input/es_out_timeshift.c

@ -1057,7 +1057,7 @@ static void *TsRun( void *p_data )
if( !es_out_SetRate( p_ts->p_out, p_ts->rate_source, p_ts->rate ) )
{
vlc_value_t val = { .i_int = INPUT_RATE_DEFAULT / p_ts->rate };
vlc_value_t val = { .f_float = p_ts->rate };
/* Warn back input
* FIXME it is perfectly safe BUT it is ugly as it may hide a
* rate change requested by user */

4
src/input/event.h

@ -83,11 +83,11 @@ static inline void input_SendEventStatistics(input_thread_t *p_input,
});
}
static inline void input_SendEventRate(input_thread_t *p_input, int i_rate)
static inline void input_SendEventRate(input_thread_t *p_input, float rate)
{
input_SendEvent(p_input, &(struct vlc_input_event) {
.type = INPUT_EVENT_RATE,
.rate = (float)INPUT_RATE_DEFAULT / (float)i_rate,
.rate = rate,
});
}

69
src/input/input.c

@ -352,7 +352,7 @@ static input_thread_t *Create( vlc_object_t *p_parent,
priv->is_stopped = false;
priv->b_recording = false;
priv->b_thumbnailing = b_thumbnailing;
priv->i_rate = INPUT_RATE_DEFAULT;
priv->rate = 1.f;
memset( &priv->bookmark, 0, sizeof(priv->bookmark) );
TAB_INIT( priv->i_bookmark, priv->pp_bookmark );
TAB_INIT( priv->i_attachment, priv->attachment );
@ -508,7 +508,7 @@ static input_thread_t *Create( vlc_object_t *p_parent,
else
priv->stats = NULL;
priv->p_es_out_display = input_EsOutNew( p_input, INPUT_RATE_DEFAULT / (float) priv->i_rate );
priv->p_es_out_display = input_EsOutNew( p_input, priv->rate );
priv->p_es_out = NULL;
/* Set the destructor when we are sure we are initialized */
@ -1008,9 +1008,9 @@ static void RequestSubRate( input_thread_t *p_input, float f_slave_fps )
input_thread_private_t *priv = input_priv(p_input);
const float f_fps = input_priv(p_input)->master->f_fps;
if( f_fps > 1.f && f_slave_fps > 1.f )
priv->i_slave_subs_rate = INPUT_RATE_DEFAULT / ( f_fps / f_slave_fps );
else if ( priv->i_slave_subs_rate != 0 )
priv->i_slave_subs_rate = INPUT_RATE_DEFAULT;
priv->slave_subs_rate = f_fps / f_slave_fps;
else if ( priv->slave_subs_rate != 0 )
priv->slave_subs_rate = 1.f;
}
static void SetSubtitlesOptions( input_thread_t *p_input )
@ -1354,8 +1354,7 @@ static int Init( input_thread_t * p_input )
#endif
/* Create es out */
priv->p_es_out = input_EsOutTimeshiftNew( p_input, priv->p_es_out_display,
INPUT_RATE_DEFAULT / (float) priv->i_rate );
priv->p_es_out = input_EsOutTimeshiftNew( p_input, priv->p_es_out_display, priv->rate );
if( priv->p_es_out == NULL )
goto error;
@ -1388,7 +1387,7 @@ static int Init( input_thread_t * p_input )
double f_rate = var_GetFloat( p_input, "rate" );
if( f_rate != 0.0 && f_rate != 1.0 )
{
vlc_value_t val = { .i_int = INPUT_RATE_DEFAULT / f_rate };
vlc_value_t val = { .f_float = f_rate };
input_ControlPushHelper( p_input, INPUT_CONTROL_SET_RATE, &val );
}
}
@ -1998,19 +1997,19 @@ static bool Control( input_thread_t *p_input,
case INPUT_CONTROL_SET_RATE:
{
/* Get rate and direction */
long long i_rate = llabs( param.val.i_int );
int i_rate_sign = param.val.i_int < 0 ? -1 : 1;
float rate = fabsf( param.val.f_float );
int i_rate_sign = rate < 0 ? -1 : 1;
/* Check rate bound */
if( i_rate < INPUT_RATE_MIN )
if( rate > INPUT_RATE_DEFAULT / INPUT_RATE_MIN )
{
msg_Dbg( p_input, "cannot set rate faster" );
i_rate = INPUT_RATE_MIN;
msg_Info( p_input, "cannot set rate faster" );
rate = INPUT_RATE_DEFAULT / INPUT_RATE_MIN;
}
else if( i_rate > INPUT_RATE_MAX )
else if( rate < INPUT_RATE_DEFAULT / INPUT_RATE_MAX )
{
msg_Dbg( p_input, "cannot set rate slower" );
i_rate = INPUT_RATE_MAX;
msg_Info( p_input, "cannot set rate slower" );
rate = INPUT_RATE_DEFAULT / INPUT_RATE_MAX;
}
/* Apply direction */
@ -2019,48 +2018,46 @@ static bool Control( input_thread_t *p_input,
if( priv->master->b_rescale_ts )
{
msg_Dbg( p_input, "cannot set negative rate" );
i_rate = priv->i_rate;
assert( i_rate > 0 );
rate = priv->rate;
assert( rate > 0 );
}
else
{
i_rate *= i_rate_sign;
rate *= i_rate_sign;
}
}
if( i_rate != INPUT_RATE_DEFAULT &&
if( rate != 1.f &&
( ( !priv->b_can_rate_control && !priv->master->b_rescale_ts ) ||
( priv->p_sout && !priv->b_out_pace_control ) ) )
{
msg_Dbg( p_input, "cannot change rate" );
i_rate = INPUT_RATE_DEFAULT;
rate = 1.f;
}
if( i_rate != priv->i_rate &&
if( rate != priv->rate &&
!priv->b_can_pace_control && priv->b_can_rate_control )
{
if( !priv->master->b_rescale_ts )
es_out_Control( priv->p_es_out, ES_OUT_RESET_PCR );
if( demux_Control( priv->master->p_demux, DEMUX_SET_RATE,
&i_rate ) )
&rate ) )
{
msg_Warn( p_input, "ACCESS/DEMUX_SET_RATE failed" );
i_rate = priv->i_rate;
rate = priv->rate;
}
}
/* */
if( i_rate != priv->i_rate )
if( rate != priv->rate )
{
priv->i_rate = i_rate;
input_SendEventRate( p_input, i_rate );
priv->rate = rate;
input_SendEventRate( p_input, rate );
if( priv->master->b_rescale_ts )
{
const int i_rate_source = (priv->b_can_pace_control || priv->b_can_rate_control ) ? i_rate : INPUT_RATE_DEFAULT;
es_out_SetRate( priv->p_es_out,
INPUT_RATE_DEFAULT / (float) i_rate_source,
INPUT_RATE_DEFAULT / (float) i_rate );
const float rate_source = (priv->b_can_pace_control || priv->b_can_rate_control ) ? rate : 1.f;
es_out_SetRate( priv->p_es_out, rate_source, rate );
}
b_force_update = true;
@ -2891,16 +2888,16 @@ static void SlaveDemux( input_thread_t *p_input )
if( in->b_eof )
continue;
if( priv->i_slave_subs_rate != in->i_sub_rate )
if( priv->slave_subs_rate != in->sub_rate )
{
if( in->b_slave_sub && in->b_can_rate_control )
{
if( in->i_sub_rate != 0 ) /* Don't reset when it's the first time */
if( in->sub_rate != 0 ) /* Don't reset when it's the first time */
es_out_Control( priv->p_es_out, ES_OUT_RESET_PCR );
int i_new_rate = priv->i_slave_subs_rate;
demux_Control( in->p_demux, DEMUX_SET_RATE, &i_new_rate );
float new_rate = priv->slave_subs_rate;
demux_Control( in->p_demux, DEMUX_SET_RATE, &new_rate );
}
in->i_sub_rate = priv->i_slave_subs_rate;
in->sub_rate = priv->slave_subs_rate;
}

6
src/input/input_internal.h

@ -70,7 +70,7 @@ typedef struct
/* sub-fps handling */
bool b_slave_sub;
unsigned i_sub_rate;
float sub_rate;
/* */
vlc_tick_t i_pts_delay;
@ -132,7 +132,7 @@ typedef struct input_thread_private_t
bool is_stopped;
bool b_recording;
bool b_thumbnailing;
int i_rate;
float rate;
/* Playtime configuration and state */
vlc_tick_t i_start; /* :start-time,0 by default */
@ -179,7 +179,7 @@ typedef struct input_thread_private_t
/* Slave sources (subs, and others) */
int i_slave;
input_source_t **slave;
unsigned i_slave_subs_rate;
float slave_subs_rate;
/* Last ES added */
enum es_format_category_e i_last_es_cat;

2
src/input/player.c

@ -2357,7 +2357,7 @@ vlc_player_ChangeRate(vlc_player_t *player, float rate)
if (input)
{
input_ControlPushHelper(input->thread, INPUT_CONTROL_SET_RATE,
&(vlc_value_t) { .i_int = INPUT_RATE_DEFAULT / rate });
&(vlc_value_t) { .f_float = rate });
}
else
vlc_player_SendEvent(player, on_rate_changed, rate);

1
src/input/var.c

@ -844,7 +844,6 @@ static int RateCallback( vlc_object_t *p_this, char const *psz_cmd,
input_thread_t *p_input = (input_thread_t*)p_this;
VLC_UNUSED(oldval); VLC_UNUSED(p_data); VLC_UNUSED(psz_cmd);
newval.i_int = INPUT_RATE_DEFAULT / newval.f_float;
input_ControlPushHelper( p_input, INPUT_CONTROL_SET_RATE, &newval );
return VLC_SUCCESS;

Loading…
Cancel
Save