]> git.sesse.net Git - vlc/blob - src/playlist/aout.c
2203d2de3f17c5d69cf28b47b7b34d33c8dc1770
[vlc] / src / playlist / aout.c
1 /*****************************************************************************
2  * aout.c: audio output controls for the VLC playlist
3  *****************************************************************************
4  * Copyright (C) 2002-2012 VLC authors and VideoLAN
5  *
6  * Authors: Christophe Massiot <massiot@via.ecp.fr>
7  *
8  * This program is free software; you can redistribute it and/or modify it
9  * under the terms of the GNU Lesser General Public License as published by
10  * the Free Software Foundation; either version 2.1 of the License, or
11  * (at your option) any later version.
12  *
13  * This program is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16  * GNU Lesser General Public License for more details.
17  *
18  * You should have received a copy of the GNU Lesser General Public License
19  * along with this program; if not, write to the Free Software Foundation,
20  * Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
21  *****************************************************************************/
22
23 #ifdef HAVE_CONFIG_H
24 # include "config.h"
25 #endif
26
27 #include <vlc_common.h>
28 #include <vlc_aout.h>
29 #include <vlc_playlist.h>
30
31 #include "../audio_output/aout_internal.h"
32 #include "playlist_internal.h"
33
34 static inline audio_output_t *findAout(playlist_t *pl)
35 {
36     /* NOTE: it is assumed that the input resource exists. In practice,
37      * the playlist must have been activated. This is automatic when calling         * pl_Get(). FIXME: input resources are deleted at deactivation, this can
38      * be too early. */
39     playlist_private_t *sys = pl_priv(pl);
40     return input_resource_HoldAout(sys->p_input_resource);
41 }
42
43 float playlist_VolumeGet (playlist_t *pl)
44 {
45     float volume = -1.f;
46
47     audio_output_t *aout = findAout (pl);
48     if (aout != NULL)
49     {
50         volume = aout_VolumeGet (aout);
51         vlc_object_release (aout);
52     }
53     return volume;
54 }
55
56 int playlist_VolumeSet (playlist_t *pl, float vol)
57 {
58     int ret = -1;
59
60     audio_output_t *aout = findAout (pl);
61     if (aout != NULL)
62     {
63         ret = aout_VolumeSet (aout, vol);
64         vlc_object_release (aout);
65     }
66     return ret;
67 }
68
69 /**
70  * Raises the volume.
71  * \param value how much to increase (> 0) or decrease (< 0) the volume
72  * \param volp if non-NULL, will contain contain the resulting volume
73  */
74 int playlist_VolumeUp (playlist_t *pl, int value, float *volp)
75 {
76     int ret = -1;
77
78     value *= var_InheritInteger (pl, "volume-step");
79
80     audio_output_t *aout = findAout (pl);
81     if (aout != NULL)
82     {
83         float vol = aout_VolumeGet (aout);
84         if (vol >= 0.)
85         {
86             vol += value / (float)AOUT_VOLUME_DEFAULT;
87             if (vol < 0.)
88                 vol = 0.;
89             if (vol > 2.)
90                 vol = 2.;
91             if (volp != NULL)
92                 *volp = vol;
93             ret = aout_VolumeSet (aout, vol);
94         }
95         vlc_object_release (aout);
96     }
97     return ret;
98 }
99
100 int playlist_MuteGet (playlist_t *pl)
101 {
102     int mute = -1;
103
104     audio_output_t *aout = findAout (pl);
105     if (aout != NULL)
106     {
107         mute = aout_MuteGet (aout);
108         vlc_object_release (aout);
109     }
110     return mute;
111 }
112
113 int playlist_MuteSet (playlist_t *pl, bool mute)
114 {
115     int ret = -1;
116
117     audio_output_t *aout = findAout (pl);
118     if (aout != NULL)
119     {
120         ret = aout_MuteSet (aout, mute);
121         vlc_object_release (aout);
122         if (ret == 0)
123             var_SetBool (pl, "mute", mute);
124     }
125     return ret;
126 }
127
128 void playlist_EnableAudioFilter (playlist_t *pl, const char *name, bool add)
129 {
130     audio_output_t *aout = findAout (pl);
131
132     if (aout_ChangeFilterString (VLC_OBJECT(pl), VLC_OBJECT(aout),
133                                  "audio-filter", name, add))
134     {
135         if (aout != NULL)
136             aout_InputRequestRestart (aout);
137     }
138     if (aout != NULL)
139         vlc_object_release (aout);
140 }