[vlc-devel] [PATCH 1/3] player: refactor UpdateTimerState

Thomas Guillem thomas at gllm.fr
Tue Dec 15 09:23:24 CET 2020



On Mon, Dec 14, 2020, at 18:51, Francois Cartegnie wrote:
> ---
>  src/player/timer.c | 55 ++++++++++++++++++++++++----------------------
>  1 file changed, 29 insertions(+), 26 deletions(-)
> 
> diff --git a/src/player/timer.c b/src/player/timer.c
> index 1be28b22f0..f6db96a0ed 100644
> --- a/src/player/timer.c
> +++ b/src/player/timer.c
> @@ -178,43 +178,46 @@ vlc_player_UpdateTimerState(vlc_player_t *player, 
> vlc_es_id_t *es_source,
>  {
>      vlc_mutex_lock(&player->timer.lock);
>  
> -    if (state == VLC_PLAYER_TIMER_STATE_DISCONTINUITY)
> -    {
> -        assert(system_date == VLC_TICK_INVALID);
> +    /* Discontinuity is signalled by all output clocks and the input.
> +     * discard the event if it was already signalled or not on the good
> +     * es_source. */
> +    bool notify = false;
> +    struct vlc_player_timer_source *bestsource = &player->timer.best_source;
>  
> -        /* Discontinuity is signalled by all output clocks and the 
> input.
> -         * discard the event if it was already signalled or not on the 
> good
> -         * es_source. */
> -        bool signal_discontinuity = false;
> -        for (size_t i = 0; i < VLC_PLAYER_TIMER_TYPE_COUNT; ++i)
> -        {
> -            struct vlc_player_timer_source *source = 
> &player->timer.sources[i];
> -            if (source->es == es_source
> -             && source->point.system_date != VLC_TICK_INVALID)
> +    switch(state)
> +    {
> +        case VLC_PLAYER_TIMER_STATE_DISCONTINUITY:
> +            assert(system_date == VLC_TICK_INVALID);
> +            for (size_t i = 0; i < VLC_PLAYER_TIMER_TYPE_COUNT; ++i)
>              {
> -                source->point.system_date = VLC_TICK_INVALID;
> +                struct vlc_player_timer_source *source = 
> &player->timer.sources[i];
> +                if(source->es != es_source)
> +                    continue;
>                  /* signal discontinuity only on best source */
> -                if (i == VLC_PLAYER_TIMER_TYPE_BEST)
> -                    signal_discontinuity = true;
> +                if(source->point.system_date != VLC_TICK_INVALID)

Nit: respect the codestyle of the file: s/if(/if ( 

> +                    notify = (bestsource->es == es_source);

Nit: useless parentheses.

> +                source->point.system_date = VLC_TICK_INVALID;
>              }
> -        }
> -        if (!signal_discontinuity)
> -        {
> -            vlc_mutex_unlock(&player->timer.lock);
> -            return;
> -        }
> +            break;
> +
> +        case VLC_PLAYER_TIMER_STATE_PAUSED:
> +        default:
> +            assert(state == VLC_PLAYER_TIMER_STATE_PAUSED);
> +            notify = true;
> +            assert(system_date != VLC_TICK_INVALID);
> +            break;
>      }
> -    else
> +
> +    if( !notify )
>      {
> -        assert(state == VLC_PLAYER_TIMER_STATE_PAUSED);
> -        assert(system_date != VLC_TICK_INVALID);
> +        vlc_mutex_unlock(&player->timer.lock);
> +        return;
>      }
>  
>      player->timer.state = state;
>  
> -    struct vlc_player_timer_source *source = &player->timer.best_source;
>      vlc_player_timer_id *timer;
> -    vlc_list_foreach(timer, &source->listeners, node)
> +    vlc_list_foreach(timer, &bestsource->listeners, node)
>      {
>          timer->last_update_date = VLC_TICK_INVALID;
>          timer->cbs->on_discontinuity(system_date, timer->data);
> -- 
> 2.26.2
> 
> _______________________________________________
> vlc-devel mailing list
> To unsubscribe or modify your subscription options:
> https://mailman.videolan.org/listinfo/vlc-devel


More information about the vlc-devel mailing list