Commit 30501731 authored by Filip Roséen's avatar Filip Roséen Committed by Rémi Denis-Courmont
Browse files

playlist/engine: RateOffsetCallback: refactor



Besides the shortening of the implementation, the refactor also make
sure that we return an error-code if var_SetFloat fails - instead of
silently pretending everything was ok.
Signed-off-by: Rémi Denis-Courmont's avatarRémi Denis-Courmont <remi@remlab.net>
parent defff36a
......@@ -124,46 +124,33 @@ static int RateOffsetCallback( vlc_object_t *obj, char const *psz_cmd,
playlist_t *p_playlist = (playlist_t *)obj;
VLC_UNUSED(oldval); VLC_UNUSED(p_data); VLC_UNUSED(newval);
static const float pf_rate[] = {
static const float rates[] = {
1.0/64, 1.0/32, 1.0/16, 1.0/8, 1.0/4, 1.0/3, 1.0/2, 2.0/3,
1.0/1,
3.0/2, 2.0/1, 3.0/1, 4.0/1, 8.0/1, 16.0/1, 32.0/1, 64.0/1,
};
const size_t i_rate_count = sizeof(pf_rate)/sizeof(*pf_rate);
float f_rate;
struct input_thread_t *input;
PL_LOCK;
input = pl_priv( p_playlist )->p_input;
f_rate = var_GetFloat( input ? (vlc_object_t *)input : obj, "rate" );
input_thread_t *input = pl_priv( p_playlist )->p_input;
float current_rate = var_GetFloat( input ? VLC_OBJECT( input ) : obj, "rate" );
PL_UNLOCK;
if( !strcmp( psz_cmd, "rate-faster" ) )
{
/* compensate for input rounding errors */
float r = f_rate * 1.1f;
for( size_t i = 0; i < i_rate_count; i++ )
if( r < pf_rate[i] )
{
f_rate = pf_rate[i];
break;
}
}
else
const bool faster = !strcmp( psz_cmd, "rate-faster" );
float rate = current_rate * ( faster ? 1.1f : 0.9f );
/* find closest rate (if any) in the desired direction */
for( size_t i = 0; i < ARRAY_SIZE( rates ); ++i )
{
/* compensate for input rounding errors */
float r = f_rate * .9f;
for( size_t i = 1; i < i_rate_count; i++ )
if( r <= pf_rate[i] )
{
f_rate = pf_rate[i - 1];
break;
}
if( ( faster && rates[i] > rate ) ||
(!faster && rates[i] >= rate && i ) )
{
rate = faster ? rates[i] : rates[i-1];
break;
}
}
var_SetFloat( p_playlist, "rate", f_rate );
return VLC_SUCCESS;
return var_SetFloat( p_playlist, "rate", rate );
}
static int VideoSplitterCallback( vlc_object_t *p_this, char const *psz_cmd,
......
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