[vlc-devel] [PATCH 3/3] libvlc: expose event for audio volume change

Harald Sitter sitter at kde.org
Mon Jul 27 13:13:35 CEST 2015


LGTM

also, more hearts
<3 <3 <3 Rémi <3 <3 <3

On Mon, Jul 27, 2015 at 1:07 PM, Rémi Denis-Courmont <remi at remlab.net> wrote:
> Cc: Harald Sitter <sitter at kde.org>
> ---
>  include/vlc/libvlc_events.h |  6 ++++++
>  lib/event.c                 |  1 +
>  lib/media_player.c          | 19 +++++++++++++++++++
>  3 files changed, 26 insertions(+)
>
> diff --git a/include/vlc/libvlc_events.h b/include/vlc/libvlc_events.h
> index a997d22..0c0019e 100644
> --- a/include/vlc/libvlc_events.h
> +++ b/include/vlc/libvlc_events.h
> @@ -81,6 +81,7 @@ enum libvlc_event_e {
>      libvlc_MediaPlayerUncorked,
>      libvlc_MediaPlayerMuted,
>      libvlc_MediaPlayerUnmuted,
> +    libvlc_MediaPlayerAudioVolume,
>
>      libvlc_MediaListItemAdded=0x200,
>      libvlc_MediaListWillAddItem,
> @@ -244,6 +245,11 @@ typedef struct libvlc_event_t
>              libvlc_track_type_t i_type;
>              int                 i_id;
>          } media_player_es_changed;
> +
> +        struct
> +        {
> +           float volume;
> +        } media_player_audio_volume;
>      } u; /**< Type-dependent event description */
>  } libvlc_event_t;
>
> diff --git a/lib/event.c b/lib/event.c
> index f26af5c..b13fc92 100644
> --- a/lib/event.c
> +++ b/lib/event.c
> @@ -287,6 +287,7 @@ static const event_name_t event_list[] = {
>      DEF(MediaPlayerUncorked)
>      DEF(MediaPlayerMuted)
>      DEF(MediaPlayerUnmuted)
> +    DEF(MediaPlayerAudioVolume)
>
>      DEF(MediaListItemAdded)
>      DEF(MediaListWillAddItem)
> diff --git a/lib/media_player.c b/lib/media_player.c
> index 5cf5bf1..1ddd4bf 100644
> --- a/lib/media_player.c
> +++ b/lib/media_player.c
> @@ -75,6 +75,10 @@ static int
>  mute_changed(vlc_object_t *obj, const char *name, vlc_value_t old,
>               vlc_value_t cur, void *opaque);
>
> +static int
> +volume_changed(vlc_object_t *obj, const char *name, vlc_value_t old,
> +               vlc_value_t cur, void *opaque);
> +
>  static void
>  add_es_callbacks( input_thread_t *p_input_thread, libvlc_media_player_t *p_mi );
>
> @@ -504,6 +508,19 @@ static int mute_changed(vlc_object_t *obj, const char *name, vlc_value_t old,
>      return VLC_SUCCESS;
>  }
>
> +static int volume_changed(vlc_object_t *obj, const char *name, vlc_value_t old,
> +                          vlc_value_t cur, void *opaque)
> +{
> +    libvlc_media_player_t *mp = (libvlc_media_player_t *)obj;
> +    libvlc_event_t event;
> +
> +    event.type = libvlc_MediaPlayerAudioVolume;
> +    event.u.media_player_audio_volume.volume = cur.f_float;
> +    libvlc_event_send(mp->p_event_manager, &event);
> +    VLC_UNUSED(name); VLC_UNUSED(old); VLC_UNUSED(opaque);
> +    return VLC_SUCCESS;
> +}
> +
>  /**************************************************************************
>   * Create a Media Instance object.
>   *
> @@ -684,6 +701,7 @@ libvlc_media_player_new( libvlc_instance_t *instance )
>
>      var_AddCallback(mp, "corks", corks_changed, NULL);
>      var_AddCallback(mp, "mute", mute_changed, NULL);
> +    var_AddCallback(mp, "volume", volume_changed, NULL);
>
>      /* Snapshot initialization */
>      register_event(mp, SnapshotTaken);
> @@ -735,6 +753,7 @@ static void libvlc_media_player_destroy( libvlc_media_player_t *p_mi )
>                       "snapshot-file", snapshot_was_taken, p_mi );
>
>      /* Detach callback from the media player / input manager object */
> +    var_DelCallback( p_mi, "volume", volume_changed, NULL );
>      var_DelCallback( p_mi, "mute", mute_changed, NULL );
>      var_DelCallback( p_mi, "corks", corks_changed, NULL );
>
> --
> 1.9.1
>



More information about the vlc-devel mailing list