[vlc-commits] playlist: type-safe functions for audio output management

Rémi Denis-Courmont git at videolan.org
Thu Nov 1 18:26:11 CET 2012


vlc | branch: master | Rémi Denis-Courmont <remi at remlab.net> | Thu Nov  1 18:57:34 2012 +0200| [617abeecabf91f0fef29fa551a58b72c9ef4c4cd] | committer: Rémi Denis-Courmont

playlist: type-safe functions for audio output management

> http://git.videolan.org/gitweb.cgi/vlc.git/?a=commit;h=617abeecabf91f0fef29fa551a58b72c9ef4c4cd
---

 include/vlc_playlist.h |   24 +++++++++
 src/Makefile.am        |    1 +
 src/libvlccore.sym     |    6 +++
 src/playlist/aout.c    |  140 ++++++++++++++++++++++++++++++++++++++++++++++++
 4 files changed, 171 insertions(+)

diff --git a/include/vlc_playlist.h b/include/vlc_playlist.h
index ca42260..09f4162 100644
--- a/include/vlc_playlist.h
+++ b/include/vlc_playlist.h
@@ -364,6 +364,30 @@ VLC_API int playlist_NodeDelete( playlist_t *, playlist_item_t *, bool , bool );
 VLC_API playlist_item_t * playlist_GetNextLeaf( playlist_t *p_playlist, playlist_item_t *p_root, playlist_item_t *p_item, bool b_ena, bool b_unplayed ) VLC_USED;
 VLC_API playlist_item_t * playlist_GetPrevLeaf( playlist_t *p_playlist, playlist_item_t *p_root, playlist_item_t *p_item, bool b_ena, bool b_unplayed ) VLC_USED;
 
+/**************************
+ * Audio output management
+ **************************/
+
+#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 * );
+#define playlist_VolumeDown(a, b, c) playlist_VolumeUp(a, -(b), c)
+VLC_API int playlist_MuteSet( playlist_t *, bool );
+VLC_API int playlist_MuteGet( playlist_t * );
+
+static inline int playlist_MuteToggle( playlist_t *pl )
+{
+    int val = playlist_MuteGet( pl );
+    if (val >= 0)
+        val = playlist_MuteSet( pl, !val );
+    return val;
+}
+
+VLC_API void playlist_EnableAudioFilter( playlist_t *, const char *, bool );
+
 /***********************************************************************
  * Inline functions
  ***********************************************************************/
diff --git a/src/Makefile.am b/src/Makefile.am
index ab8c46c..6d5915f 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -330,6 +330,7 @@ SOURCES_libvlc_common = \
 	playlist/playlist_internal.h \
 	playlist/art.c \
 	playlist/art.h \
+	playlist/aout.c \
 	playlist/thread.c \
 	playlist/control.c \
 	playlist/engine.c \
diff --git a/src/libvlccore.sym b/src/libvlccore.sym
index f54fc3c..93cda49 100644
--- a/src/libvlccore.sym
+++ b/src/libvlccore.sym
@@ -352,6 +352,12 @@ playlist_Status
 playlist_TreeMove
 playlist_TreeMoveMany
 playlist_Unlock
+playlist_EnableAudioFilter
+playlist_VolumeGet
+playlist_VolumeSet
+playlist_VolumeUp
+playlist_MuteSet
+playlist_MuteGet
 pl_Get
 resolve_xml_special_chars
 sdp_AddAttribute
diff --git a/src/playlist/aout.c b/src/playlist/aout.c
new file mode 100644
index 0000000..74a0cbb
--- /dev/null
+++ b/src/playlist/aout.c
@@ -0,0 +1,140 @@
+/*****************************************************************************
+ * aout.c: audio output controls for the VLC playlist
+ *****************************************************************************
+ * Copyright (C) 2002-2012 VLC authors and VideoLAN
+ *
+ * Authors: Christophe Massiot <massiot at via.ecp.fr>
+ *
+ * This program is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as published by
+ * the Free Software Foundation; either version 2.1 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
+ *****************************************************************************/
+
+#ifdef HAVE_CONFIG_H
+# include "config.h"
+#endif
+
+#include <vlc_common.h>
+#include <vlc_aout.h>
+#include <vlc_playlist.h>
+
+#include "../audio_output/aout_internal.h"
+#include "playlist_internal.h"
+
+static inline audio_output_t *findAout(playlist_t *pl)
+{
+    /* NOTE: it is assumed that the input resource exists. In practice,
+     * the playlist must have been activated. This is automatic when calling         * pl_Get(). FIXME: input resources are deleted at deactivation, this can
+     * be too early. */
+    playlist_private_t *sys = pl_priv(pl);
+    return input_resource_HoldAout(sys->p_input_resource);
+}
+
+float playlist_VolumeGet (playlist_t *pl)
+{
+    float volume = -1.f;
+
+    audio_output_t *aout = findAout (pl);
+    if (aout != NULL)
+    {
+        volume = aout_OutputVolumeGet (aout);
+        vlc_object_release (aout);
+    }
+    return volume;
+}
+
+int playlist_VolumeSet (playlist_t *pl, float vol)
+{
+    int ret = -1;
+
+    audio_output_t *aout = findAout (pl);
+    if (aout != NULL)
+    {
+        ret = aout_OutputVolumeSet (aout, vol);
+        vlc_object_release (aout);
+    }
+    return ret;
+}
+
+/**
+ * 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 playlist_VolumeUp (playlist_t *pl, int value, float *volp)
+{
+    int ret = -1;
+
+    value *= var_InheritInteger (pl, "volume-step");
+
+    audio_output_t *aout = findAout (pl);
+    if (aout != NULL)
+    {
+        float vol = aout_OutputVolumeGet (aout);
+        if (vol >= 0.)
+        {
+            vol += value / (float)AOUT_VOLUME_DEFAULT;
+            if (vol < 0.)
+                vol = 0.;
+            if (vol > 2.)
+                vol = 2.;
+            if (volp != NULL)
+                *volp = vol;
+            ret = aout_OutputVolumeSet (aout, vol);
+        }
+        vlc_object_release (aout);
+    }
+    return ret;
+}
+
+int playlist_MuteGet (playlist_t *pl)
+{
+    int mute = -1;
+
+    audio_output_t *aout = findAout (pl);
+    if (aout != NULL)
+    {
+        mute = aout_OutputMuteGet (aout);
+        vlc_object_release (aout);
+    }
+    return mute;
+}
+
+int playlist_MuteSet (playlist_t *pl, bool mute)
+{
+    int ret = -1;
+
+    audio_output_t *aout = findAout (pl);
+    if (aout != NULL)
+    {
+        ret = aout_OutputMuteSet (aout, mute);
+        vlc_object_release (aout);
+        if (ret == 0)
+            var_SetBool (pl, "mute", mute);
+    }
+    return ret;
+}
+
+void playlist_EnableAudioFilter (playlist_t *pl, const char *name, bool add)
+{
+    audio_output_t *aout = findAout (pl);
+
+    if (aout_ChangeFilterString (VLC_OBJECT(pl), VLC_OBJECT(aout),
+                                 "audio-filter", name, add))
+    {
+        if (aout != NULL)
+            aout_InputRequestRestart (aout);
+    }
+    if (aout != NULL)
+        vlc_object_release (aout);
+}



More information about the vlc-commits mailing list