]> git.sesse.net Git - vlc/blob - src/audio_output/aout_internal.h
aout: move replay gain handling to dec and mixer
[vlc] / src / audio_output / aout_internal.h
1 /*****************************************************************************
2  * aout_internal.h : internal defines for audio output
3  *****************************************************************************
4  * Copyright (C) 2002 the VideoLAN team
5  * $Id$
6  *
7  * Authors: Christophe Massiot <massiot@via.ecp.fr>
8  *
9  * This program is free software; you can redistribute it and/or modify
10  * it under the terms of the GNU General Public License as published by
11  * the Free Software Foundation; either version 2 of the License, or
12  * (at your option) any later version.
13  *
14  * This program is distributed in the hope that it will be useful,
15  * but WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17  * GNU General Public License for more details.
18  *
19  * You should have received a copy of the GNU General Public License
20  * along with this program; if not, write to the Free Software
21  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
22  *****************************************************************************/
23
24 #ifndef LIBVLC_AOUT_INTERNAL_H
25 # define LIBVLC_AOUT_INTERNAL_H 1
26
27 /* Max input rate factor (1/4 -> 4) */
28 # define AOUT_MAX_INPUT_RATE (4)
29
30 enum {
31     AOUT_RESAMPLING_NONE=0,
32     AOUT_RESAMPLING_UP,
33     AOUT_RESAMPLING_DOWN
34 };
35
36 typedef struct
37 {
38     struct vout_thread_t  *(*pf_request_vout)( void *, struct vout_thread_t *,
39                                                video_format_t *, bool );
40     void *p_private;
41 } aout_request_vout_t;
42
43 struct filter_owner_sys_t
44 {
45     audio_output_t *p_aout;
46     aout_input_t    *p_input;
47 };
48
49 block_t *aout_FilterBufferNew( filter_t *, int );
50
51 /** an input stream for the audio output */
52 struct aout_input_t
53 {
54     unsigned            samplerate; /**< Input sample rate */
55
56     /* pre-filters */
57     filter_t *              pp_filters[AOUT_MAX_FILTERS];
58     int                     i_nb_filters;
59
60     filter_t *              p_playback_rate_filter;
61
62     /* resamplers */
63     filter_t *              pp_resamplers[AOUT_MAX_FILTERS];
64     int                     i_nb_resamplers;
65     int                     i_resampling_type;
66     mtime_t                 i_resamp_start_date;
67     int                     i_resamp_start_drift;
68
69     /* If b_error == 1, there is no input pipeline. */
70     bool              b_error;
71
72     /* last rate from input */
73     int               i_last_input_rate;
74
75     /* */
76     int               i_buffer_lost;
77
78     /* */
79     bool                b_recycle_vout;
80     aout_request_vout_t request_vout;
81 };
82
83 typedef struct
84 {
85     vlc_mutex_t lock;
86     module_t *module; /**< Output plugin (or NULL if inactive) */
87     aout_input_t *input;
88
89     struct
90     {
91         date_t date;
92     } sync;
93
94     struct
95     {
96         vlc_mutex_t lock;
97         float multiplier; /**< Software volume amplification multiplier */
98         struct audio_mixer *mixer; /**< Software volume plugin */
99     } volume;
100
101     struct
102     {
103         vlc_atomic_t multiplier;
104         audio_replay_gain_t data;
105     } gain;
106
107     audio_sample_format_t mixer_format;
108     audio_sample_format_t input_format;
109
110     /* Filters between mixer and output */
111     filter_t *filters[AOUT_MAX_FILTERS];
112     int       nb_filters;
113
114     vlc_atomic_t restart;
115 } aout_owner_t;
116
117 typedef struct
118 {
119     audio_output_t output;
120     aout_owner_t   owner;
121 } aout_instance_t;
122
123 static inline aout_owner_t *aout_owner (audio_output_t *aout)
124 {
125     return &((aout_instance_t *)aout)->owner;
126 }
127
128 /****************************************************************************
129  * Prototypes
130  *****************************************************************************/
131
132 /* From input.c : */
133 int aout_InputNew(audio_output_t *, const audio_sample_format_t *,
134                   const audio_sample_format_t *,
135                   aout_input_t *, const aout_request_vout_t *);
136 int aout_InputDelete( audio_output_t * p_aout, aout_input_t * p_input );
137 block_t *aout_InputPlay( audio_output_t *p_aout, aout_input_t *p_input,
138                          block_t *p_buffer, int i_input_rate, date_t * );
139
140 /* From filters.c : */
141 int aout_FiltersCreatePipeline( vlc_object_t *, filter_t **, int *,
142     const audio_sample_format_t *, const audio_sample_format_t * );
143 #define aout_FiltersCreatePipeline(o, pv, pc, inf, outf) \
144         aout_FiltersCreatePipeline(VLC_OBJECT(o), pv, pc, inf, outf)
145 void aout_FiltersDestroyPipeline( filter_t *const *, unsigned );
146 void aout_FiltersPlay( filter_t *const *, unsigned, aout_buffer_t ** );
147
148 /* From mixer.c : */
149 struct audio_mixer *aout_MixerNew(vlc_object_t *, vlc_fourcc_t);
150 #define aout_MixerNew(o, f) aout_MixerNew(VLC_OBJECT(o), f)
151 void aout_MixerDelete(struct audio_mixer *);
152 void aout_MixerRun(struct audio_mixer *, block_t *, float);
153 float aout_ReplayGainSelect(vlc_object_t *, const char *,
154                             const audio_replay_gain_t *);
155 #define aout_ReplayGainSelect(o, s, g) \
156         aout_ReplayGainSelect(VLC_OBJECT(o), s, g)
157
158 static inline void aout_ReplayGainInit(audio_replay_gain_t *restrict d,
159                                        const audio_replay_gain_t *restrict s)
160 {
161     if (s != NULL)
162         *d = *s;
163     else
164         memset (d, 0, sizeof (*d));
165 }
166
167
168 /* From output.c : */
169 int aout_OutputNew( audio_output_t * p_aout,
170                     const audio_sample_format_t * p_format );
171 void aout_OutputPlay( audio_output_t * p_aout, aout_buffer_t * p_buffer );
172 void aout_OutputPause( audio_output_t * p_aout, bool, mtime_t );
173 void aout_OutputFlush( audio_output_t * p_aout, bool );
174 void aout_OutputDelete( audio_output_t * p_aout );
175
176
177 /* From common.c : */
178 /* Release with vlc_object_release() */
179 audio_output_t *aout_New ( vlc_object_t * );
180 #define aout_New(a) aout_New(VLC_OBJECT(a))
181
182 void aout_FifoInit( vlc_object_t *, aout_fifo_t *, uint32_t );
183 mtime_t aout_FifoFirstDate( const aout_fifo_t * ) VLC_USED;
184 #define aout_FifoInit(o, f, r) aout_FifoInit(VLC_OBJECT(o), f, r)
185 void aout_FifoPush( aout_fifo_t *, aout_buffer_t * );
186 aout_buffer_t *aout_FifoPop( aout_fifo_t * p_fifo ) VLC_USED;
187 void aout_FifoReset( aout_fifo_t * );
188 void aout_FifoMoveDates( aout_fifo_t *, mtime_t );
189 void aout_FifoDestroy( aout_fifo_t * p_fifo );
190 void aout_FormatsPrint(vlc_object_t *, const char *,
191                        const audio_sample_format_t *,
192                        const audio_sample_format_t *);
193 #define aout_FormatsPrint(o, t, a, b) \
194         aout_FormatsPrint(VLC_OBJECT(o), t, a, b)
195 bool aout_ChangeFilterString( vlc_object_t *manager, vlc_object_t *aout,
196                               const char *var, const char *name, bool b_add );
197
198 /* From dec.c */
199 int aout_DecNew(audio_output_t *, const audio_sample_format_t *,
200                 const audio_replay_gain_t *, const aout_request_vout_t *);
201 void aout_DecDelete(audio_output_t *);
202 block_t *aout_DecNewBuffer(audio_output_t *, size_t);
203 void aout_DecDeleteBuffer(audio_output_t *, block_t *);
204 int aout_DecPlay(audio_output_t *, block_t *, int i_input_rate);
205 int aout_DecGetResetLost(audio_output_t *);
206 void aout_DecChangePause(audio_output_t *, bool b_paused, mtime_t i_date);
207 void aout_DecFlush(audio_output_t *);
208 bool aout_DecIsEmpty(audio_output_t *);
209
210 void aout_InputRequestRestart(audio_output_t *);
211 void aout_RequestRestart(audio_output_t *);
212
213 /* Audio output locking */
214
215 #if !defined (NDEBUG) \
216  && defined __linux__ && (defined (__i386__) || defined (__x86_64__))
217 # define AOUT_DEBUG 1
218 #endif
219
220 #ifdef AOUT_DEBUG
221 enum
222 {
223     OUTPUT_LOCK=1,
224     VOLUME_LOCK=2,
225 };
226
227 void aout_lock_check (unsigned);
228 void aout_unlock_check (unsigned);
229
230 #else
231 # define aout_lock_check( i )   (void)0
232 # define aout_unlock_check( i ) (void)0
233 #endif
234
235 static inline void aout_lock( audio_output_t *p_aout )
236 {
237     aout_lock_check( OUTPUT_LOCK );
238     vlc_mutex_lock( &aout_owner(p_aout)->lock );
239 }
240
241 static inline void aout_unlock( audio_output_t *p_aout )
242 {
243     aout_unlock_check( OUTPUT_LOCK );
244     vlc_mutex_unlock( &aout_owner(p_aout)->lock );
245 }
246
247 static inline void aout_lock_volume( audio_output_t *p_aout )
248 {
249     aout_lock_check( VOLUME_LOCK );
250     vlc_mutex_lock( &aout_owner(p_aout)->volume.lock );
251 }
252
253 static inline void aout_unlock_volume( audio_output_t *p_aout )
254 {
255     aout_unlock_check( VOLUME_LOCK );
256     vlc_mutex_unlock( &aout_owner(p_aout)->volume.lock );
257 }
258
259 #define aout_assert_locked( aout ) \
260         vlc_assert_locked( &aout_owner(aout)->lock )
261
262 #endif /* !LIBVLC_AOUT_INTERNAL_H */