]> git.sesse.net Git - vlc/blob - src/playlist/aout.c
demux: avi: improve broken index offset heuristic (fix #14120)
[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 <math.h>
28
29 #include <vlc_common.h>
30 #include <vlc_aout.h>
31 #include <vlc_playlist.h>
32
33 #include "../audio_output/aout_internal.h"
34 #include "playlist_internal.h"
35
36 audio_output_t *playlist_GetAout(playlist_t *pl)
37 {
38     /* NOTE: it is assumed that the input resource exists. In practice,
39      * the playlist must have been activated. This is automatic when calling
40      * pl_Get(). FIXME: input resources are deleted at deactivation, this can
41      * be too early. */
42     playlist_private_t *sys = pl_priv(pl);
43     return input_resource_HoldAout(sys->p_input_resource);
44 }
45
46 float playlist_VolumeGet (playlist_t *pl)
47 {
48     float volume = -1.f;
49
50     audio_output_t *aout = playlist_GetAout (pl);
51     if (aout != NULL)
52     {
53         volume = aout_VolumeGet (aout);
54         vlc_object_release (aout);
55     }
56     return volume;
57 }
58
59 int playlist_VolumeSet (playlist_t *pl, float vol)
60 {
61     int ret = -1;
62
63     audio_output_t *aout = playlist_GetAout (pl);
64     if (aout != NULL)
65     {
66         ret = aout_VolumeSet (aout, vol);
67         vlc_object_release (aout);
68     }
69     return ret;
70 }
71
72 /**
73  * Raises the volume.
74  * \param value how much to increase (> 0) or decrease (< 0) the volume
75  * \param volp if non-NULL, will contain contain the resulting volume
76  */
77 int playlist_VolumeUp (playlist_t *pl, int value, float *volp)
78 {
79     int ret = -1;
80
81     float stepSize = var_InheritFloat (pl, "volume-step") / (float)AOUT_VOLUME_DEFAULT;
82
83     float delta = value * stepSize;
84
85     audio_output_t *aout = playlist_GetAout (pl);
86     if (aout != NULL)
87     {
88         float vol = aout_VolumeGet (aout);
89         if (vol >= 0.f)
90         {
91             vol += delta;
92             if (vol < 0.f)
93                 vol = 0.f;
94             if (vol > 2.f)
95                 vol = 2.f;
96             vol = (roundf (vol / stepSize)) * stepSize;
97             if (volp != NULL)
98                 *volp = vol;
99             ret = aout_VolumeSet (aout, vol);
100         }
101         vlc_object_release (aout);
102     }
103     return ret;
104 }
105
106 int playlist_MuteGet (playlist_t *pl)
107 {
108     int mute = -1;
109
110     audio_output_t *aout = playlist_GetAout (pl);
111     if (aout != NULL)
112     {
113         mute = aout_MuteGet (aout);
114         vlc_object_release (aout);
115     }
116     return mute;
117 }
118
119 int playlist_MuteSet (playlist_t *pl, bool mute)
120 {
121     int ret = -1;
122
123     audio_output_t *aout = playlist_GetAout (pl);
124     if (aout != NULL)
125     {
126         ret = aout_MuteSet (aout, mute);
127         vlc_object_release (aout);
128     }
129     return ret;
130 }
131
132 void playlist_EnableAudioFilter (playlist_t *pl, const char *name, bool add)
133 {
134     audio_output_t *aout = playlist_GetAout (pl);
135
136     aout_ChangeFilterString (VLC_OBJECT(pl), VLC_OBJECT(aout),
137                              "audio-filter", name, add);
138     if (aout != NULL)
139         vlc_object_release (aout);
140 }