[vlc-devel] [PATCH 1/2] player: pass old_caps to on_capabilities_changed
Thomas Guillem
thomas at gllm.fr
Thu May 2 12:08:56 CEST 2019
LGTM for the set
On Thu, May 2, 2019, at 11:17, Romain Vimont wrote:
> The capabilities are stored in a bitset. When it changes, it may be
> useful to know its old value, to know which capability changed.
> ---
> include/vlc_player.h | 5 +++--
> modules/control/dbus/dbus.c | 7 ++++---
> .../gui/qt/components/player_controller.cpp | 3 ++-
> src/input/player.c | 5 ++++-
> test/src/input/player.c | 21 ++++++++++++++-----
> 5 files changed, 29 insertions(+), 12 deletions(-)
>
> diff --git a/include/vlc_player.h b/include/vlc_player.h
> index a055c842cc..17e927c948 100644
> --- a/include/vlc_player.h
> +++ b/include/vlc_player.h
> @@ -473,11 +473,12 @@ struct vlc_player_cbs
> * Always called when the media is opening. Can be called during playback.
> *
> * @param player locked player instance
> - * @param new_caps player capabilities
> + * @param old_caps old player capabilities
> + * @param new_caps new player capabilities
> * @param data opaque pointer set by vlc_player_AddListener()
> */
> void (*on_capabilities_changed)(vlc_player_t *player,
> - int new_caps, void *data);
> + int old_caps, int new_caps, void *data);
>
> /**
> * Called when the player position has changed
> diff --git a/modules/control/dbus/dbus.c b/modules/control/dbus/dbus.c
> index d117d5332b..af6e4dc58f 100644
> --- a/modules/control/dbus/dbus.c
> +++ b/modules/control/dbus/dbus.c
> @@ -145,7 +145,7 @@ static void player_on_state_changed(vlc_player_t *,
> static void player_on_error_changed(vlc_player_t *,
> enum vlc_player_error, void *);
> static void player_on_rate_changed(vlc_player_t *, float, void *);
> -static void player_on_capabilities_changed(vlc_player_t *, int, void
> *);
> +static void player_on_capabilities_changed(vlc_player_t *, int, int,
> void *);
> static void player_on_position_changed(vlc_player_t *,
> vlc_tick_t, float, void *);
> static void player_on_media_meta_changed(vlc_player_t *,
> @@ -1080,7 +1080,8 @@ player_on_rate_changed(vlc_player_t *player,
> float new_rate, void *data)
> }
>
> static void
> -player_on_capabilities_changed(vlc_player_t *player, int new_caps,
> void *data)
> +player_on_capabilities_changed(vlc_player_t *player, int old_caps, int
> new_caps,
> + void *data)
> {
> intf_thread_t *intf = data;
> intf_sys_t *sys = intf->p_sys;
> @@ -1093,7 +1094,7 @@ player_on_capabilities_changed(vlc_player_t
> *player, int new_caps, void *data)
> vlc_mutex_unlock(&sys->lock);
> if (ok1 || ok2)
> wakeup_main_loop(intf);
> - (void) player; (void) new_caps;
> + (void) player; (void) old_caps; (void) new_caps;
> }
>
> static void
> diff --git a/modules/gui/qt/components/player_controller.cpp
> b/modules/gui/qt/components/player_controller.cpp
> index cd8fc33b45..c79f376576 100644
> --- a/modules/gui/qt/components/player_controller.cpp
> +++ b/modules/gui/qt/components/player_controller.cpp
> @@ -323,8 +323,9 @@ static void on_player_rate_changed(vlc_player_t *,
> float new_rate, void *data)
> });
> }
>
> -static void on_player_capabilities_changed(vlc_player_t *, int
> new_caps, void *data)
> +static void on_player_capabilities_changed(vlc_player_t *, int
> old_caps, int new_caps, void *data)
> {
> + Q_UNUSED(old_caps);
> PlayerControllerPrivate* that =
> static_cast<PlayerControllerPrivate*>(data);
> msg_Dbg( that->p_intf, "on_player_capabilities_changed");
> that->callAsync([that,new_caps](){
> diff --git a/src/input/player.c b/src/input/player.c
> index 1cd06ca42b..da74eb4ee4 100644
> --- a/src/input/player.c
> +++ b/src/input/player.c
> @@ -1904,10 +1904,13 @@ input_thread_Events(input_thread_t
> *input_thread,
> vlc_player_SendEvent(player, on_rate_changed, input->rate);
> break;
> case INPUT_EVENT_CAPABILITIES:
> + {
> + int old_caps = input->capabilities;
> input->capabilities = event->capabilities;
> vlc_player_SendEvent(player, on_capabilities_changed,
> - input->capabilities);
> + old_caps, input->capabilities);
> break;
> + }
> case INPUT_EVENT_POSITION:
> if (input->time != event->position.ms ||
> input->position != event->position.percentage)
> diff --git a/test/src/input/player.c b/test/src/input/player.c
> index 669a6c5013..c30f6128dd 100644
> --- a/test/src/input/player.c
> +++ b/test/src/input/player.c
> @@ -27,6 +27,12 @@
> #include <vlc_player.h>
> #include <vlc_vector.h>
>
> +struct report_capabilities
> +{
> + int old_caps;
> + int new_caps;
> +};
> +
> struct report_position
> {
> vlc_tick_t time;
> @@ -87,7 +93,7 @@ struct report_media_subitems
> X(enum vlc_player_error, on_error_changed) \
> X(float, on_buffering_changed) \
> X(float, on_rate_changed) \
> - X(int, on_capabilities_changed) \
> + X(struct report_capabilities, on_capabilities_changed) \
> X(struct report_position, on_position_changed) \
> X(vlc_tick_t, on_length_changed) \
> X(struct report_track_list, on_track_list_changed) \
> @@ -261,11 +267,15 @@ player_on_rate_changed(vlc_player_t *player,
> float new_rate, void *data)
> }
>
> static void
> -player_on_capabilities_changed(vlc_player_t *player, int new_caps,
> +player_on_capabilities_changed(vlc_player_t *player, int old_caps, int
> new_caps,
> void *data)
> {
> struct ctx *ctx = get_ctx(player, data);
> - VEC_PUSH(on_capabilities_changed, new_caps);
> + struct report_capabilities report = {
> + .old_caps = old_caps,
> + .new_caps = new_caps,
> + };
> + VEC_PUSH(on_capabilities_changed, report);
> }
>
> static void
> @@ -731,10 +741,11 @@ test_end_prestop_capabilities(struct ctx *ctx)
> vec_on_capabilities_changed *vec = &ctx->report.on_capabilities_changed;
> while (vec->size == 0)
> vlc_player_CondWait(ctx->player, &ctx->wait);
> + int new_caps = VEC_LAST(vec).new_caps;
> assert(vlc_player_CanSeek(player) == ctx->params.can_seek
> - && !!(VEC_LAST(vec) & VLC_PLAYER_CAP_SEEK) == ctx->params.can_seek);
> + && !!(new_caps & VLC_PLAYER_CAP_SEEK) == ctx->params.can_seek);
> assert(vlc_player_CanPause(player) == ctx->params.can_pause
> - && !!(VEC_LAST(vec) & VLC_PLAYER_CAP_PAUSE) == ctx->params.can_pause);
> + && !!(new_caps & VLC_PLAYER_CAP_PAUSE) == ctx->params.can_pause);
> }
>
> static void
> --
> 2.20.1
>
> _______________________________________________
> 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