[vlc-devel] [PATCH 2/8] playlist/engine: RateOffsetCallback: refactor
Rémi Denis-Courmont
remi at remlab.net
Sun May 21 21:13:03 CEST 2017
Le sunnuntaina 21. toukokuuta 2017, 20.48.12 EEST Filip Roséen a écrit :
> 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.
var_Set() can only fail if the variable does not exist, which should be
impossible (I think). So I am not quite sure what you are trying to achieve
here.
> ---
> src/playlist/engine.c | 45 ++++++++++++++++-----------------------------
> 1 file changed, 16 insertions(+), 29 deletions(-)
>
> diff --git a/src/playlist/engine.c b/src/playlist/engine.c
> index eeacbc59e7..848a86ad45 100644
> --- a/src/playlist/engine.c
> +++ b/src/playlist/engine.c
> @@ -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,
--
雷米‧德尼-库尔蒙
https://www.remlab.net/
More information about the vlc-devel
mailing list