[vlc-commits] libvlc: expose event for audio volume change (fixes #14568)

Rémi Denis-Courmont git at videolan.org
Mon Jul 27 15:45:08 CEST 2015


vlc/vlc-2.2 | branch: master | Rémi Denis-Courmont <remi at remlab.net> | Mon Jul 27 14:05:37 2015 +0300| [8c86b9073b697ec9e403143366416d59884c8073] | committer: Jean-Baptiste Kempf

libvlc: expose event for audio volume change (fixes #14568)

Cc: Harald Sitter <sitter at kde.org>
(cherry picked from commit 33638b85834a52e59f8cd25e51f0fa22d03d475e)
Signed-off-by: Jean-Baptiste Kempf <jb at videolan.org>

> http://git.videolan.org/gitweb.cgi/vlc/vlc-2.2.git/?a=commit;h=8c86b9073b697ec9e403143366416d59884c8073
---

 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 1102209..7b29cd3 100644
--- a/include/vlc/libvlc_events.h
+++ b/include/vlc/libvlc_events.h
@@ -78,6 +78,7 @@ enum libvlc_event_e {
     libvlc_MediaPlayerUncorked,
     libvlc_MediaPlayerMuted,
     libvlc_MediaPlayerUnmuted,
+    libvlc_MediaPlayerAudioVolume,
 
     libvlc_MediaListItemAdded=0x200,
     libvlc_MediaListWillAddItem,
@@ -234,6 +235,11 @@ typedef struct libvlc_event_t
         {
             libvlc_media_t * new_media;
         } media_player_media_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 a17eade..ad3a3b8 100644
--- a/lib/event.c
+++ b/lib/event.c
@@ -285,6 +285,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 b23ac3a..b09152e 100644
--- a/lib/media_player.c
+++ b/lib/media_player.c
@@ -66,6 +66,10 @@ 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 int
 snapshot_was_taken( vlc_object_t *p_this, char const *psz_cmd,
                     vlc_value_t oldval, vlc_value_t newval, void *p_data );
 
@@ -410,6 +414,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.
  *
@@ -585,6 +602,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);
@@ -636,6 +654,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 );
 



More information about the vlc-commits mailing list