[vlc-devel] [PATCH] libvlc: return int for libvlc_MediaPlayerAudioVolume

Daniel Amm da2424 at t-online.de
Mon Oct 3 15:41:45 CEST 2016


Since libvlc_audio_get_volume() returns an integer (0=mute, 100=nominal), the associated event should also do that.
So the API would be more consistent.
---
 include/vlc/libvlc_events.h | 2 +-
 lib/media_player.c          | 3 ++-
 2 files changed, 3 insertions(+), 2 deletions(-)

diff --git a/include/vlc/libvlc_events.h b/include/vlc/libvlc_events.h
index b69c5ce..d5fa80b 100644
--- a/include/vlc/libvlc_events.h
+++ b/include/vlc/libvlc_events.h
@@ -267,7 +267,7 @@ typedef struct libvlc_event_t
 
         struct
         {
-            float volume;
+            int volume;
         } media_player_audio_volume;
 
         struct
diff --git a/lib/media_player.c b/lib/media_player.c
index 9a8f73a..2df3c48 100644
--- a/lib/media_player.c
+++ b/lib/media_player.c
@@ -41,6 +41,7 @@
 #include "media_internal.h" // libvlc_media_set_state()
 #include "media_player_internal.h"
 #include "renderer_discoverer_internal.h"
+#include <math.h> //lroundf()
 
 static int
 input_seekable_changed( vlc_object_t * p_this, char const * psz_cmd,
@@ -567,7 +568,7 @@ static int volume_changed(vlc_object_t *obj, const char *name, vlc_value_t old,
     libvlc_event_t event;
 
     event.type = libvlc_MediaPlayerAudioVolume;
-    event.u.media_player_audio_volume.volume = cur.f_float;
+    event.u.media_player_audio_volume.volume = lroundf( cur.f_float * 100.f );
     libvlc_event_send(mp->p_event_manager, &event);
     VLC_UNUSED(name); VLC_UNUSED(old); VLC_UNUSED(opaque);
     return VLC_SUCCESS;
-- 
2.9.0.windows.1



More information about the vlc-devel mailing list