[vlc-devel] [RFC PATCH 2/2] player: signal position discontinuities

Thomas Guillem thomas at gllm.fr
Thu Sep 6 13:40:14 CEST 2018



On Thu, Sep 6, 2018, at 13:11, Thomas Guillem wrote:
> ---
>  include/vlc_player.h | 20 ++++++++++++++++++++
>  src/input/player.c   | 40 +++++++++++++++++++++++++++++++++++++++-
>  2 files changed, 59 insertions(+), 1 deletion(-)
> 
> diff --git a/include/vlc_player.h b/include/vlc_player.h
> index 06476cfc65..833b57959a 100644
> --- a/include/vlc_player.h
> +++ b/include/vlc_player.h
> @@ -168,6 +168,26 @@ struct vlc_player_cbs
>      void (*on_capabilities_changed)(vlc_player_t *player, int new_caps,
>                                      void *data);
>  
> +    /**
> +     * Signal a discontinuity
> +     *
> +     * This callback signals a discontinuity in the player position (because of
> +     * a rate change, a pause, a seek, or a buffering).
> +     *
> +     * Example: When a discontinuity starts, the UI can show an indefinite
> +     * progress. When it stops, the UI can set the progress bar to the time/pos
> +     * value, and continue updating it according to the rate.
> +     *
> +     * @param player locked player instance
> +     * @param started true to start a discontinuity, false to end it
> +     * @param time the current time or VLC_TICK_INVALID if started is false
> +     * @param pos the current pos or VLC_TICK_INVALID if started if false
> +     * @param rate the current rate of VLC_TICK_INVALID if started if false
> +     */
> +    void (*on_discontinuity_changed)(vlc_player_t *player, bool started,
> +                                     vlc_tick_t time, float pos, float rate,
> +                                     void *data);
> +
>      void (*on_length_changed)(vlc_player_t *player, vlc_tick_t new_length,
>                                void *data);
>  
> diff --git a/src/input/player.c b/src/input/player.c
> index 7fe80a08e7..68394573f3 100644
> --- a/src/input/player.c
> +++ b/src/input/player.c
> @@ -76,6 +76,8 @@ struct vlc_player_input
>  
>      struct input_stats_t stats;
>  
> +    bool discontinuity;
> +
>      vlc_player_program_vector program_vector;
>      vlc_player_track_vector video_track_vector;
>      vlc_player_track_vector audio_track_vector;
> @@ -168,6 +170,8 @@ vlc_player_input_New(vlc_player_t *player, 
> input_item_t *item)
>  
>      memset(&input->stats, 0, sizeof(input->stats));
>  
> +    input->discontinuity = false;
> +
>      vlc_vector_init(&input->program_vector);
>      vlc_vector_init(&input->video_track_vector);
>      vlc_vector_init(&input->audio_track_vector);
> @@ -614,6 +618,34 @@ vlc_player_track_Update(struct vlc_player_track *track,
>      return VLC_SUCCESS;
>  }
>  
> +static void
> +vlc_player_StartDiscontinuity(vlc_player_t *player)
> +{
> +    struct vlc_player_input *input = player->input;
> +    if (input->discontinuity)
> +        return;
> +
> +    input->discontinuity = true;
> +    vlc_player_SendEvent(player, on_discontinuity_changed,
> +                         input->discontinuity, VLC_TICK_INVALID, 0.0f, 0.0f);
> +}
> +
> +static void
> +vlc_player_StopDiscontinuity(vlc_player_t *player, vlc_tick_t time, float pos,
> +                             float rate)
> +{
> +    struct vlc_player_input *input = player->input;
> +    if (!input->discontinuity)
> +        return;
> +
> +    if (input->cache == 1.f && input->state == PLAYING_S)
> +    {
> +        input->discontinuity = false;
> +        vlc_player_SendEvent(player, on_discontinuity_changed,
> +                             input->discontinuity, time, pos, rate);
> +    }
> +}
> +
>  static void
>  vlc_player_input_HandleEsEvent(struct vlc_player_input *input,
>                                 const struct vlc_input_event_es *ev)
> @@ -729,6 +761,7 @@ input_thread_events(input_thread_t *input_thread,
>                      break;
>                  case PAUSE_S:
>                      player_state = VLC_PLAYER_STATE_PAUSED;
> +                    vlc_player_StartDiscontinuity(player);
>                      break;
>                  case END_S:
>                      player_state = VLC_PLAYER_STATE_STOPPED;
> @@ -747,7 +780,7 @@ input_thread_events(input_thread_t *input_thread,
>          case INPUT_EVENT_RATE:
>              input->rate = event->rate;
>              vlc_player_SendEvent(player, on_rate_changed, input->rate);
> -            vlc_player_SendEvent(player, on_discontinuity, false);
> +            vlc_player_StartDiscontinuity(player);
>              break;
>          case INPUT_EVENT_CAPABILITIES:
>              input->capabilities = event->capabilities;
> @@ -768,6 +801,9 @@ input_thread_events(input_thread_t *input_thread,
>              input->position_ms = event->position.ms;
>              input->position_percent = event->position.percentage;
>              input->position_date = vlc_tick_now();
> +            /* INPUT_EVENT_POSITION */
> +            vlc_player_StopDiscontinuity(player,input->position_ms,
> +                                         input->position_percent, input->rate);

This position should come the future clock, and maybe the discontinuity should come from it too.

>              break;
>          case INPUT_EVENT_LENGTH:
>              input->length = event->length;
> @@ -807,6 +843,8 @@ input_thread_events(input_thread_t *input_thread,
>              break;
>          case INPUT_EVENT_CACHE:
>              input->cache = event->cache;
> +            if (input->cache == 0.0f)
> +                vlc_player_StartDiscontinuity(player);
>              vlc_player_SendEvent(player, on_buffering, event->cache);
>              break;
>          case INPUT_EVENT_AOUT:
> -- 
> 2.18.0
> 
> _______________________________________________
> 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