]> git.sesse.net Git - vlc/blob - src/audio_output/aout_internal.h
Replace remaining instances of aout_buffer_t with block_t
[vlc] / src / audio_output / aout_internal.h
1 /*****************************************************************************
2  * aout_internal.h : internal defines for audio output
3  *****************************************************************************
4  * Copyright (C) 2002 VLC authors and VideoLAN
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 it
10  * under the terms of the GNU Lesser General Public License as published by
11  * the Free Software Foundation; either version 2.1 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 Lesser General Public License for more details.
18  *
19  * You should have received a copy of the GNU Lesser General Public License
20  * along with this program; if not, write to the Free Software Foundation,
21  * 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 # include <vlc_atomic.h>
28
29 /* Max input rate factor (1/4 -> 4) */
30 # define AOUT_MAX_INPUT_RATE (4)
31
32 enum {
33     AOUT_RESAMPLING_NONE=0,
34     AOUT_RESAMPLING_UP,
35     AOUT_RESAMPLING_DOWN
36 };
37
38 typedef struct
39 {
40     struct vout_thread_t  *(*pf_request_vout)( void *, struct vout_thread_t *,
41                                                video_format_t *, bool );
42     void *p_private;
43 } aout_request_vout_t;
44
45 struct filter_owner_sys_t
46 {
47     audio_output_t *p_aout;
48     aout_input_t    *p_input;
49 };
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     /* last rate from input */
70     int               i_last_input_rate;
71
72     /* */
73     int               i_buffer_lost;
74
75     /* */
76     bool                b_recycle_vout;
77     aout_request_vout_t request_vout;
78 };
79
80 typedef struct
81 {
82     vlc_mutex_t lock;
83     module_t *module; /**< Output plugin (or NULL if inactive) */
84     aout_input_t *input;
85
86     struct
87     {
88         date_t date;
89     } sync;
90
91     struct
92     {
93         vlc_mutex_t lock;
94         float multiplier; /**< Software volume amplification multiplier */
95         struct audio_mixer *mixer; /**< Software volume plugin */
96     } volume;
97
98     struct
99     {
100         vlc_atomic_t multiplier;
101         audio_replay_gain_t data;
102     } gain;
103
104     audio_sample_format_t mixer_format;
105     audio_sample_format_t input_format;
106
107     /* Filters between mixer and output */
108     filter_t *filters[AOUT_MAX_FILTERS];
109     int       nb_filters;
110
111     vlc_atomic_t restart;
112 } aout_owner_t;
113
114 typedef struct
115 {
116     audio_output_t output;
117     aout_owner_t   owner;
118 } aout_instance_t;
119
120 static inline aout_owner_t *aout_owner (audio_output_t *aout)
121 {
122     return &((aout_instance_t *)aout)->owner;
123 }
124
125 /****************************************************************************
126  * Prototypes
127  *****************************************************************************/
128
129 /* From input.c : */
130 aout_input_t *aout_InputNew(audio_output_t *, const audio_sample_format_t *,
131                             const audio_sample_format_t *,
132                             const aout_request_vout_t *);
133 int aout_InputDelete( audio_output_t * p_aout, aout_input_t * p_input );
134 block_t *aout_InputPlay( audio_output_t *p_aout, aout_input_t *p_input,
135                          block_t *p_buffer, int i_input_rate, date_t * );
136
137 /* From filters.c : */
138 int aout_FiltersCreatePipeline( vlc_object_t *, filter_t **, int *,
139     const audio_sample_format_t *, const audio_sample_format_t * );
140 #define aout_FiltersCreatePipeline(o, pv, pc, inf, outf) \
141         aout_FiltersCreatePipeline(VLC_OBJECT(o), pv, pc, inf, outf)
142 void aout_FiltersDestroyPipeline( filter_t *const *, unsigned );
143 void aout_FiltersPlay( filter_t *const *, unsigned, block_t ** );
144
145 /* From mixer.c : */
146 #define aout_MixerNew(o, f) aout_MixerNew(VLC_OBJECT(o), f)
147
148 float aout_ReplayGainSelect(vlc_object_t *, const char *,
149                             const audio_replay_gain_t *);
150 #define aout_ReplayGainSelect(o, s, g) \
151         aout_ReplayGainSelect(VLC_OBJECT(o), s, g)
152
153 static inline void aout_ReplayGainInit(audio_replay_gain_t *restrict d,
154                                        const audio_replay_gain_t *restrict s)
155 {
156     if (s != NULL)
157         *d = *s;
158     else
159         memset (d, 0, sizeof (*d));
160 }
161
162
163 /* From output.c : */
164 int aout_OutputNew( audio_output_t * p_aout,
165                     const audio_sample_format_t * p_format );
166 void aout_OutputPlay( audio_output_t * p_aout, block_t * p_buffer );
167 void aout_OutputPause( audio_output_t * p_aout, bool, mtime_t );
168 void aout_OutputFlush( audio_output_t * p_aout, bool );
169 void aout_OutputDelete( audio_output_t * p_aout );
170
171
172 /* From common.c : */
173 audio_output_t *aout_New (vlc_object_t *);
174 #define aout_New(a) aout_New(VLC_OBJECT(a))
175 void aout_Destroy (audio_output_t *);
176
177 void aout_FormatsPrint(vlc_object_t *, const char *,
178                        const audio_sample_format_t *,
179                        const audio_sample_format_t *);
180 #define aout_FormatsPrint(o, t, a, b) \
181         aout_FormatsPrint(VLC_OBJECT(o), t, a, b)
182 bool aout_ChangeFilterString( vlc_object_t *manager, vlc_object_t *aout,
183                               const char *var, const char *name, bool b_add );
184
185 /* From dec.c */
186 int aout_DecNew(audio_output_t *, const audio_sample_format_t *,
187                 const audio_replay_gain_t *, const aout_request_vout_t *);
188 void aout_DecDelete(audio_output_t *);
189 block_t *aout_DecNewBuffer(audio_output_t *, size_t);
190 void aout_DecDeleteBuffer(audio_output_t *, block_t *);
191 int aout_DecPlay(audio_output_t *, block_t *, int i_input_rate);
192 int aout_DecGetResetLost(audio_output_t *);
193 void aout_DecChangePause(audio_output_t *, bool b_paused, mtime_t i_date);
194 void aout_DecFlush(audio_output_t *);
195 bool aout_DecIsEmpty(audio_output_t *);
196
197 void aout_InputRequestRestart(audio_output_t *);
198 void aout_RequestRestart(audio_output_t *);
199 void aout_Shutdown (audio_output_t *);
200
201 /* Audio output locking */
202
203 #if !defined (NDEBUG) \
204  && defined __linux__ && (defined (__i386__) || defined (__x86_64__))
205 # define AOUT_DEBUG 1
206 #endif
207
208 #ifdef AOUT_DEBUG
209 enum
210 {
211     OUTPUT_LOCK=1,
212     VOLUME_LOCK=2,
213 };
214
215 void aout_lock_check (unsigned);
216 void aout_unlock_check (unsigned);
217
218 #else
219 # define aout_lock_check( i )   (void)0
220 # define aout_unlock_check( i ) (void)0
221 #endif
222
223 static inline void aout_lock( audio_output_t *p_aout )
224 {
225     aout_lock_check( OUTPUT_LOCK );
226     vlc_mutex_lock( &aout_owner(p_aout)->lock );
227 }
228
229 static inline void aout_unlock( audio_output_t *p_aout )
230 {
231     aout_unlock_check( OUTPUT_LOCK );
232     vlc_mutex_unlock( &aout_owner(p_aout)->lock );
233 }
234
235 static inline void aout_lock_volume( audio_output_t *p_aout )
236 {
237     aout_lock_check( VOLUME_LOCK );
238     vlc_mutex_lock( &aout_owner(p_aout)->volume.lock );
239 }
240
241 static inline void aout_unlock_volume( audio_output_t *p_aout )
242 {
243     aout_unlock_check( VOLUME_LOCK );
244     vlc_mutex_unlock( &aout_owner(p_aout)->volume.lock );
245 }
246
247 #define aout_assert_locked( aout ) \
248         vlc_assert_locked( &aout_owner(aout)->lock )
249
250 #endif /* !LIBVLC_AOUT_INTERNAL_H */