[vlc-devel] [PATCH] libvlc: don't check current state in libvlc_media_player_set_pause

Hugo Beauzée-Luyssen hugo at beauzee.fr
Thu Sep 28 10:17:58 CEST 2017


On Thu, Sep 28, 2017, at 04:34 AM, Zhao Zhili wrote:
> Since input_Control is executed asynchronously, current state may be
> different to the state when INPUT_SET_STATE executing. Here is a use
> case which is broken by check current state in
> libvlc_media_player_set_pause():
> 
> 1. current state is paused
> 2. call libvlc_media_player_play()
> 3. call libvlc_media_player_set_pause() immediately before
> INPUT_SET_STATE PLAYING_S is executed, libvlc_media_player_set_pause()
> will do nothing, so it looks like the pause request is been dropped
> silently
> ---
>   lib/media_player.c | 17 ++++++-----------
>   1 file changed, 6 insertions(+), 11 deletions(-)
> 
> diff --git a/lib/media_player.c b/lib/media_player.c
> index a462f46..8ccf317 100644
> --- a/lib/media_player.c
> +++ b/lib/media_player.c
> @@ -1007,21 +1007,16 @@ void libvlc_media_player_set_pause( 
> libvlc_media_player_t *p_mi, int paused )
>       if( !p_input_thread )
>           return;
> 
> -    libvlc_state_t state = libvlc_media_player_get_state( p_mi );
> -    if( state == libvlc_Playing )
> +    if( paused )
>       {
> -        if( paused )
> -        {
> -            if( libvlc_media_player_can_pause( p_mi ) )
> -                input_Control( p_input_thread, INPUT_SET_STATE, PAUSE_S
> );
> -            else
> -                input_Stop( p_input_thread );
> -        }
> +        if( libvlc_media_player_can_pause( p_mi ) )
> +            input_Control( p_input_thread, INPUT_SET_STATE, PAUSE_S );
> +        else
> +            input_Stop( p_input_thread );
>       }
>       else
>       {
> -        if( !paused )
> -            input_Control( p_input_thread, INPUT_SET_STATE, PLAYING_S );
> +        input_Control( p_input_thread, INPUT_SET_STATE, PLAYING_S );
>       }
> 
>       vlc_object_release( p_input_thread );
> -- 
> 2.7.4
> 

That looks sensible to me.

Regards,

-- 
  Hugo Beauzée-Luyssen
  hugo at beauzee.fr


More information about the vlc-devel mailing list