[vlc-devel] [PATCH 4/5] aout: move playlist_VolumeUp implementation to aout_VolumeUpdate

Thomas Guillem thomas at gllm.fr
Mon Sep 4 12:33:04 CEST 2017


---
 include/vlc_aout.h        |  4 ++++
 include/vlc_playlist.h    |  4 +---
 src/audio_output/output.c | 27 +++++++++++++++++++++++++++
 src/libvlccore.sym        |  1 +
 src/playlist/aout.c       | 18 +-----------------
 5 files changed, 34 insertions(+), 20 deletions(-)

diff --git a/include/vlc_aout.h b/include/vlc_aout.h
index 8e2fd19903..db9ec90bfc 100644
--- a/include/vlc_aout.h
+++ b/include/vlc_aout.h
@@ -290,8 +290,12 @@ VLC_API void aout_FormatPrint(vlc_object_t *, const char *,
 #define aout_FormatPrint(o, t, f) aout_FormatPrint(VLC_OBJECT(o), t, f)
 VLC_API const char * aout_FormatPrintChannels( const audio_sample_format_t * ) VLC_USED;
 
+#define AOUT_VOLUME_DEFAULT             256
+#define AOUT_VOLUME_MAX                 512
+
 VLC_API float aout_VolumeGet (audio_output_t *);
 VLC_API int aout_VolumeSet (audio_output_t *, float);
+VLC_API int aout_VolumeUpdate (audio_output_t *, int, float *);
 VLC_API int aout_MuteGet (audio_output_t *);
 VLC_API int aout_MuteSet (audio_output_t *, bool);
 VLC_API char *aout_DeviceGet (audio_output_t *);
diff --git a/include/vlc_playlist.h b/include/vlc_playlist.h
index 6774410433..b320e98b50 100644
--- a/include/vlc_playlist.h
+++ b/include/vlc_playlist.h
@@ -29,6 +29,7 @@ extern "C" {
 # endif
 
 #include <vlc_events.h>
+#include <vlc_aout.h>
 
 TYPEDEF_ARRAY(playlist_item_t*, playlist_item_array_t)
 
@@ -392,9 +393,6 @@ VLC_API void playlist_NodeDelete( playlist_t *, playlist_item_t * );
 
 VLC_API audio_output_t *playlist_GetAout( playlist_t * );
 
-#define AOUT_VOLUME_DEFAULT             256
-#define AOUT_VOLUME_MAX                 512
-
 VLC_API float playlist_VolumeGet( playlist_t * );
 VLC_API int playlist_VolumeSet( playlist_t *, float );
 VLC_API int playlist_VolumeUp( playlist_t *, int, float * );
diff --git a/src/audio_output/output.c b/src/audio_output/output.c
index 2fa2b976ae..3c72a50184 100644
--- a/src/audio_output/output.c
+++ b/src/audio_output/output.c
@@ -739,6 +739,33 @@ int aout_VolumeSet (audio_output_t *aout, float vol)
 }
 
 /**
+ * Raises the volume.
+ * \param value how much to increase (> 0) or decrease (< 0) the volume
+ * \param volp if non-NULL, will contain contain the resulting volume
+ */
+int aout_VolumeUpdate (audio_output_t *aout, int value, float *volp)
+{
+    int ret = -1;
+    float stepSize = var_InheritFloat (aout, "volume-step") / (float)AOUT_VOLUME_DEFAULT;
+    float delta = value * stepSize;
+    float vol = aout_VolumeGet (aout);
+
+    if (vol >= 0.f)
+    {
+        vol += delta;
+        if (vol < 0.f)
+            vol = 0.f;
+        if (vol > 2.f)
+            vol = 2.f;
+        vol = (roundf (vol / stepSize)) * stepSize;
+        if (volp != NULL)
+            *volp = vol;
+        ret = aout_VolumeSet (aout, vol);
+    }
+    return ret;
+}
+
+/**
  * Gets the audio output stream mute flag.
  * \return 0 if not muted, 1 if muted, -1 if undefined.
  */
diff --git a/src/libvlccore.sym b/src/libvlccore.sym
index f9a82d7a51..2d5d4feb55 100644
--- a/src/libvlccore.sym
+++ b/src/libvlccore.sym
@@ -17,6 +17,7 @@ aout_FormatPrint
 aout_FormatPrintChannels
 aout_VolumeGet
 aout_VolumeSet
+aout_VolumeUpdate
 aout_MuteSet
 aout_MuteGet
 aout_DeviceGet
diff --git a/src/playlist/aout.c b/src/playlist/aout.c
index b9eb157a2e..3ceb66d891 100644
--- a/src/playlist/aout.c
+++ b/src/playlist/aout.c
@@ -78,26 +78,10 @@ int playlist_VolumeUp (playlist_t *pl, int value, float *volp)
 {
     int ret = -1;
 
-    float stepSize = var_InheritFloat (pl, "volume-step") / (float)AOUT_VOLUME_DEFAULT;
-
-    float delta = value * stepSize;
-
     audio_output_t *aout = playlist_GetAout (pl);
     if (aout != NULL)
     {
-        float vol = aout_VolumeGet (aout);
-        if (vol >= 0.f)
-        {
-            vol += delta;
-            if (vol < 0.f)
-                vol = 0.f;
-            if (vol > 2.f)
-                vol = 2.f;
-            vol = (roundf (vol / stepSize)) * stepSize;
-            if (volp != NULL)
-                *volp = vol;
-            ret = aout_VolumeSet (aout, vol);
-        }
+        ret = aout_VolumeUpdate (aout, value, volp);
         vlc_object_release (aout);
     }
     return ret;
-- 
2.11.0



More information about the vlc-devel mailing list