Commit e87dd9f0 authored by Rémi Denis-Courmont's avatar Rémi Denis-Courmont

Convert "rate" variable to float everywhere

This follows the historical LibVLC semantic (and new --rate one), so
bigger is faster. In the process, simplify a few code paths, especially
those in LibVLC, but make many other code paths more complicated due to
integer<->float conversion. Most of those paths could probably be
simplified.

 * Fix RC "fastforward" command behaviour (it was slowing down instead)
 * Fix str_format_mera 'R' format string with negative rates and
   rates such that (rate % 1000 < 100).
parent d2a714c1
......@@ -344,12 +344,14 @@ typedef enum input_state_e
/**
* Input rate.
*
* It is an integer used by the variable "rate" in the
* range [INPUT_RATE_MIN, INPUT_RATE_MAX] the default value
* being INPUT_RATE_DEFAULT.
* It is an float used by the variable "rate" in the
* range [INPUT_RATE_DEFAULT/INPUT_RATE_MAX, INPUT_RATE_DEFAULT/INPUT_RATE_MAX]
* the default value being 1. It represents the ratio of playback speed to
* nominal speed (bigger is faster).
*
* A value lower than INPUT_RATE_DEFAULT plays faster.
* A value higher than INPUT_RATE_DEFAULT plays slower.
* Internally, the rate is stored as a value in the range
* [INPUT_RATE_MIN, INPUT_RATE_MAX].
* internal rate = INPUT_RATE_DEFAULT / rate variable
*/
/**
......@@ -452,7 +454,7 @@ enum input_query_e
INPUT_GET_TIME, /* arg1= int64_t * res= */
INPUT_SET_TIME, /* arg1= int64_t res=can fail */
/* input variable "rate" (1 is DEFAULT_RATE) */
/* input variable "rate" (nominal is INPUT_RATE_DEFAULT) */
INPUT_GET_RATE, /* arg1= int * res= */
INPUT_SET_RATE, /* arg1= int res=can fail */
......
......@@ -710,7 +710,7 @@ static int PutAction( intf_thread_t *p_intf, int i_action )
}
else if( i_action == ACTIONID_RATE_NORMAL )
{
var_SetInteger( p_input, "rate", INPUT_RATE_DEFAULT );
var_SetFloat( p_input, "rate", 1. );
vout_OSDMessage( VLC_OBJECT(p_input), DEFAULT_CHAN,
"%s", _("1.00x") );
}
......@@ -721,9 +721,12 @@ static int PutAction( intf_thread_t *p_intf, int i_action )
* and we want to increase/decrease it by 0.1 while making sure
* that the resulting playback rate is a multiple of 0.1
*/
int i_rate = var_GetInteger( p_input, "rate" );
if( i_rate == 0 )
int i_rate = 1. * INPUT_RATE_DEFAULT
/ var_GetFloat( p_input, "rate" );
if( i_rate < INPUT_RATE_MIN )
i_rate = INPUT_RATE_MIN;
else if( i_rate > INPUT_RATE_MAX )
i_rate = INPUT_RATE_MAX;
int i_sign = i_rate < 0 ? -1 : 1;
const int i_dir = i_action == ACTIONID_RATE_FASTER_FINE ? 1 : -1;
......@@ -735,7 +738,7 @@ static int PutAction( intf_thread_t *p_intf, int i_action )
i_rate = i_sign * __MIN( __MAX( i_rate, INPUT_RATE_MIN ), INPUT_RATE_MAX );
var_SetInteger( p_input, "rate", i_rate );
var_SetFloat( p_input, "rate", i_rate );
char psz_msg[7+1];
snprintf( psz_msg, sizeof(psz_msg), _("%.2fx"), (double)INPUT_RATE_DEFAULT / i_rate );
......@@ -809,9 +812,9 @@ static int PutAction( intf_thread_t *p_intf, int i_action )
}
else if( i_action == ACTIONID_PLAY )
{
if( var_GetInteger( p_input, "rate" ) != INPUT_RATE_DEFAULT )
if( var_GetFloat( p_input, "rate" ) != 1. )
/* Return to normal speed */
var_SetInteger( p_input, "rate", INPUT_RATE_DEFAULT );
var_SetFloat( p_input, "rate", 1. );
else
{
ClearChannels( p_intf, p_vout );
......
......@@ -962,8 +962,8 @@ static void RateChanged( intf_thread_t *p_intf,
input_thread_t *p_input )
{
vlc_mutex_lock( &p_intf->p_sys->status_lock );
msg_rc( STATUS_CHANGE "( new rate: %d )",
var_GetInteger( p_input, "rate" ) );
msg_rc( STATUS_CHANGE "( new rate: %.3f )",
var_GetFloat( p_input, "rate" ) );
vlc_mutex_unlock( &p_intf->p_sys->status_lock );
}
static void PositionChanged( intf_thread_t *p_intf,
......@@ -1059,9 +1059,9 @@ static int Input( vlc_object_t *p_this, char const *psz_cmd,
{
if( var_GetBool( p_input, "can-rate" ) )
{
int i_rate = var_GetInteger( p_input, "rate" );
i_rate = (i_rate < 0) ? -i_rate : i_rate * 2;
var_SetInteger( p_input, "rate", i_rate );
float f_rate = var_GetFloat( p_input, "rate" );
f_rate = (f_rate < 0) ? -f_rate : f_rate * 2;
var_SetFloat( p_input, "rate", f_rate );
}
else
{
......@@ -1073,9 +1073,9 @@ static int Input( vlc_object_t *p_this, char const *psz_cmd,
{
if( var_GetBool( p_input, "can-rewind" ) )
{
int i_rate = var_GetInteger( p_input, "rate" );
i_rate = (i_rate > 0) ? -i_rate : i_rate / 2;
var_SetInteger( p_input, "rate", i_rate );
float f_rate = var_GetFloat( p_input, "rate" );
f_rate = (f_rate > 0) ? -f_rate : f_rate * 2;
var_SetFloat( p_input, "rate", f_rate );
}
else
{
......
......@@ -487,49 +487,49 @@ void InterfaceWindow::MessageReceived( BMessage * p_message )
case HEIGHTH_PLAY:
if( p_input )
{
var_SetInteger( p_input, "rate", INPUT_RATE_DEFAULT * 8 );
var_SetFloat( p_input, "rate", .125 );
}
break;
case QUARTER_PLAY:
if( p_input )
{
var_SetInteger( p_input, "rate", INPUT_RATE_DEFAULT * 4 );
var_SetFloat( p_input, "rate", .25 );
}
break;
case HALF_PLAY:
if( p_input )
{
var_SetInteger( p_input, "rate", INPUT_RATE_DEFAULT * 2 );
var_SetFloat( p_input, "rate", .5 );
}
break;
case NORMAL_PLAY:
if( p_input )
{
var_SetInteger( p_input, "rate", INPUT_RATE_DEFAULT );
var_SetFloat( p_input, "rate", 1. );
}
break;
case TWICE_PLAY:
if( p_input )
{
var_SetInteger( p_input, "rate", INPUT_RATE_DEFAULT / 2 );
var_SetFloat( p_input, "rate", 2. );
}
break;
case FOUR_PLAY:
if( p_input )
{
var_SetInteger( p_input, "rate", INPUT_RATE_DEFAULT / 4 );
var_SetFloat( p_input, "rate", 4. );
}
break;
case HEIGHT_PLAY:
if( p_input )
{
var_SetInteger( p_input, "rate", INPUT_RATE_DEFAULT / 8 );
var_SetFloat( p_input, "rate", 8. );
}
break;
......@@ -840,12 +840,12 @@ void InterfaceWindow::UpdateInterface()
p_mediaControl->SetEnabled( true );
bool hasTitles = !var_Get( p_input, "title", &val );
bool hasChapters = !var_Get( p_input, "chapter", &val );
p_mediaControl->SetStatus( var_GetInteger( p_input, "state" ),
var_GetInteger( p_input, "rate" ) );
p_mediaControl->SetStatus( INPUT_RATE_DEFAULT / var_GetFloat( p_input, "state" ),
INPUT_RATE_DEFAULT / var_GetFloat( p_input, "rate" ) );
var_Get( p_input, "position", &val );
p_mediaControl->SetProgress( val.f_float );
_SetMenusEnabled( true, hasChapters, hasTitles );
_UpdateSpeedMenu( var_GetInteger( p_input, "rate" ) );
_UpdateSpeedMenu( INPUT_RATE_DEFAULT / var_GetFloat( p_input, "rate" ) );
// enable/disable skip buttons
#if 0
......
......@@ -407,7 +407,7 @@ void InputManager::UpdateStatus()
void InputManager::UpdateRate()
{
/* Update Rate */
int i_new_rate = var_GetInteger( p_input, "rate");
int i_new_rate = INPUT_RATE_DEFAULT / var_GetFloat( p_input, "rate" );
if( i_new_rate != i_rate )
{
i_rate = i_new_rate;
......@@ -776,8 +776,8 @@ void InputManager::reverse()
{
if( hasInput() )
{
int i_rate = var_GetInteger( p_input, "rate" );
var_SetInteger( p_input, "rate", -i_rate );
float f_rate = var_GetFloat( p_input, "rate" );
var_SetFloat( p_input, "rate", -f_rate );
}
}
......@@ -806,13 +806,14 @@ void InputManager::littleslower()
void InputManager::normalRate()
{
if( hasInput() )
var_SetInteger( p_input, "rate", INPUT_RATE_DEFAULT );
var_SetFloat( p_input, "rate", 1. );
}
void InputManager::setRate( int new_rate )
{
if( hasInput() )
var_SetInteger( p_input, "rate", new_rate );
var_SetFloat( p_input, "rate",
(float)INPUT_RATE_DEFAULT / (float)new_rate );
}
void InputManager::jumpFwd()
......
......@@ -195,7 +195,7 @@ void Timer::Notify( void )
/* Manage Speed status */
var_Get( p_input, "rate", &val );
if( i_old_rate != val.i_int )
if( i_old_rate != (int)((float)INPUT_RATE_DEFAULT / val.f_float) )
{
TCHAR psz_text[15];
_stprintf( psz_text + 2, _T("x%.2f"), 1000.0 / val.i_int );
......
......@@ -407,7 +407,7 @@ end
function rate(name,client)
local input = vlc.object.input()
if name == "normal" then
vlc.var.set(input,"rate",1000) -- FIXME: INPUT_RATE_DEFAULT
vlc.var.set(input,"rate",1)
else
vlc.var.set(input,"rate-"..name,nil)
end
......
......@@ -1052,7 +1052,7 @@ void libvlc_media_player_set_rate(
return;
}
var_SetInteger( p_input_thread, "rate", 1000.0f/rate );
var_SetFloat( p_input_thread, "rate", rate );
vlc_object_release( p_input_thread );
}
......@@ -1061,23 +1061,24 @@ float libvlc_media_player_get_rate(
libvlc_exception_t *p_e )
{
input_thread_t *p_input_thread;
int i_rate;
float f_rate;
bool b_can_rewind;
p_input_thread = libvlc_get_input_thread ( p_mi, p_e );
if( !p_input_thread )
return 0.0; /* rate < 0 indicates rewind */
i_rate = var_GetInteger( p_input_thread, "rate" );
f_rate = var_GetFloat( p_input_thread, "rate" );
b_can_rewind = var_GetBool( p_input_thread, "can-rewind" );
if( i_rate < 0 && !b_can_rewind )
/* FIXME: why are negative values forbidden ?? (rewinding) */
if( f_rate < 0 && !b_can_rewind )
{
vlc_object_release( p_input_thread );
return 0.0;
}
vlc_object_release( p_input_thread );
return (float)1000.0f/i_rate;
return f_rate;
}
libvlc_state_t libvlc_media_player_get_state(
......
......@@ -99,12 +99,13 @@ int input_vaControl( input_thread_t *p_input, int i_query, va_list args )
case INPUT_GET_RATE:
pi_int = (int*)va_arg( args, int * );
*pi_int = var_GetInteger( p_input, "rate" );
*pi_int = INPUT_RATE_DEFAULT / var_GetFloat( p_input, "rate" );
return VLC_SUCCESS;
case INPUT_SET_RATE:
i_int = (int)va_arg( args, int );
return var_SetInteger( p_input, "rate", i_int );
return var_SetFloat( p_input, "rate",
(float)INPUT_RATE_DEFAULT / (float)i_int );
case INPUT_GET_STATE:
pi_int = (int*)va_arg( args, int * );
......
......@@ -95,10 +95,10 @@ void input_SendEventStatistics( input_thread_t *p_input )
}
void input_SendEventRate( input_thread_t *p_input, int i_rate )
{
vlc_value_t val;
vlc_value_t val;
val.i_int = i_rate;
var_Change( p_input, "rate", VLC_VAR_SETVALUE, &val, NULL );
val.f_float = (float)INPUT_RATE_DEFAULT / (float)i_rate;
var_Change( p_input, "rate", VLC_VAR_SETVALUE, &val, NULL );
Trigger( p_input, INPUT_EVENT_RATE );
}
......
......@@ -136,8 +136,8 @@ void input_ControlVarInit ( input_thread_t *p_input )
var_Change( p_input, "state", VLC_VAR_SETVALUE, &val, NULL );
/* Rate */
var_Create( p_input, "rate", VLC_VAR_INTEGER );
val.i_int = p_input->p->i_rate;
var_Create( p_input, "rate", VLC_VAR_FLOAT );
val.f_float = (float)INPUT_RATE_DEFAULT / (float)p_input->p->i_rate;
var_Change( p_input, "rate", VLC_VAR_SETVALUE, &val, NULL );
var_Create( p_input, "rate-slower", VLC_VAR_VOID );
......@@ -574,6 +574,7 @@ static int RateCallback( vlc_object_t *p_this, char const *psz_cmd,
}
else
{
int i_rate = INPUT_RATE_DEFAULT / newval.f_float;
input_ControlPush( p_input, INPUT_CONTROL_SET_RATE, &newval );
}
return VLC_SUCCESS;
......
......@@ -1064,7 +1064,8 @@ static int vlm_ControlMediaInstanceGets( vlm_t *p_vlm, int64_t id, vlm_media_ins
p_idsc->d_position = var_GetFloat( p_instance->p_input, "position" );
if( var_GetInteger( p_instance->p_input, "state" ) == PAUSE_S )
p_idsc->b_paused = true;
p_idsc->i_rate = var_GetInteger( p_instance->p_input, "rate" );
p_idsc->i_rate = INPUT_RATE_DEFAULT
/ var_GetFloat( p_instance->p_input, "rate" );
}
TAB_APPEND( i_idsc, pp_idsc, p_idsc );
......
......@@ -1365,7 +1365,7 @@ static vlm_message_t *vlm_ShowMedia( vlm_media_sys_t *p_media )
APPEND_INPUT_INFO( "position", "%f", Float );
APPEND_INPUT_INFO( "time", "%"PRIi64, Time );
APPEND_INPUT_INFO( "length", "%"PRIi64, Time );
APPEND_INPUT_INFO( "rate", "%d", Integer );
APPEND_INPUT_INFO( "rate", "%f", Float );
APPEND_INPUT_INFO( "title", "%d", Integer );
APPEND_INPUT_INFO( "chapter", "%d", Integer );
APPEND_INPUT_INFO( "can-seek", "%d", Bool );
......
......@@ -858,8 +858,8 @@ char *__str_format_meta( vlc_object_t *p_object, const char *string )
case 'R':
if( p_input )
{
int r = var_GetInteger( p_input, "rate" );
snprintf( buf, 10, "%d.%d", r/1000, r%1000 );
float f = var_GetFloat( p_input, "rate" );
snprintf( buf, 10, "%.3f", f );
}
else
{
......
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