]> git.sesse.net Git - vlc/blob - src/audio_output/aout_internal.h
Pass mixer multiplier as argument
[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 # include <vlc_aout_mixer.h>
28
29 typedef struct
30 {
31     struct vout_thread_t  *(*pf_request_vout)( void *, struct vout_thread_t *,
32                                                video_format_t *, bool );
33     void *p_private;
34 } aout_request_vout_t;
35
36 struct filter_owner_sys_t
37 {
38     aout_instance_t *p_aout;
39     aout_input_t    *p_input;
40 };
41
42 block_t *aout_FilterBufferNew( filter_t *, int );
43
44 /** an input stream for the audio output */
45 struct aout_input_t
46 {
47     /* When this lock is taken, the pipeline cannot be changed by a
48      * third-party. */
49     vlc_mutex_t             lock;
50
51     audio_sample_format_t   input;
52
53     /* pre-filters */
54     filter_t *              pp_filters[AOUT_MAX_FILTERS];
55     int                     i_nb_filters;
56
57     filter_t *              p_playback_rate_filter;
58
59     /* resamplers */
60     filter_t *              pp_resamplers[AOUT_MAX_FILTERS];
61     int                     i_nb_resamplers;
62     int                     i_resampling_type;
63     mtime_t                 i_resamp_start_date;
64     int                     i_resamp_start_drift;
65
66     /* Mixer information */
67     audio_replay_gain_t     replay_gain;
68
69     /* If b_restart == 1, the input pipeline will be re-created. */
70     bool              b_restart;
71
72     /* If b_error == 1, there is no input pipeline. */
73     bool              b_error;
74
75     /* last rate from input */
76     int               i_last_input_rate;
77
78     /* */
79     int               i_buffer_lost;
80
81     /* */
82     bool              b_paused;
83     mtime_t           i_pause_date;
84
85     /* */
86     bool                b_recycle_vout;
87     aout_request_vout_t request_vout;
88
89     /* */
90     aout_mixer_input_t mixer;
91  };
92
93 /****************************************************************************
94  * Prototypes
95  *****************************************************************************/
96
97 /* From input.c : */
98 int aout_InputNew( aout_instance_t * p_aout, aout_input_t * p_input, const aout_request_vout_t * );
99 int aout_InputDelete( aout_instance_t * p_aout, aout_input_t * p_input );
100 int aout_InputPlay( aout_instance_t * p_aout, aout_input_t * p_input,
101                     aout_buffer_t * p_buffer, int i_input_rate );
102 void aout_InputCheckAndRestart( aout_instance_t * p_aout, aout_input_t * p_input );
103 bool aout_InputIsEmpty( aout_instance_t * p_aout, aout_input_t * p_input );
104
105 /* From filters.c : */
106 int aout_FiltersCreatePipeline( aout_instance_t *, filter_t **, int *,
107     const audio_sample_format_t *, const audio_sample_format_t * );
108 void aout_FiltersDestroyPipeline( filter_t *const *, unsigned );
109 void aout_FiltersPlay( filter_t *const *, unsigned, aout_buffer_t ** );
110
111 /* From mixer.c : */
112 int aout_MixerNew( aout_instance_t * p_aout );
113 void aout_MixerDelete( aout_instance_t * p_aout );
114 void aout_MixerRun( aout_instance_t * p_aout, float );
115
116 /* From output.c : */
117 int aout_OutputNew( aout_instance_t * p_aout,
118                     audio_sample_format_t * p_format );
119 void aout_OutputPlay( aout_instance_t * p_aout, aout_buffer_t * p_buffer );
120 void aout_OutputDelete( aout_instance_t * p_aout );
121
122
123 /* From common.c : */
124 #define aout_New(a) __aout_New(VLC_OBJECT(a))
125 /* Release with vlc_object_release() */
126 aout_instance_t * __aout_New ( vlc_object_t * );
127
128 void aout_FifoInit( aout_instance_t *, aout_fifo_t *, uint32_t );
129 mtime_t aout_FifoNextStart( aout_instance_t *, aout_fifo_t * );
130 void aout_FifoPush( aout_instance_t *, aout_fifo_t *, aout_buffer_t * );
131 void aout_FifoSet( aout_instance_t *, aout_fifo_t *, mtime_t );
132 void aout_FifoMoveDates( aout_instance_t *, aout_fifo_t *, mtime_t );
133 void aout_FifoDestroy( aout_instance_t * p_aout, aout_fifo_t * p_fifo );
134 void aout_FormatsPrint( aout_instance_t * p_aout, const char * psz_text, const audio_sample_format_t * p_format1, const audio_sample_format_t * p_format2 );
135 bool aout_ChangeFilterString( vlc_object_t *, aout_instance_t *, const char *psz_variable, const char *psz_name, bool b_add );
136
137 /* From dec.c */
138 aout_input_t *aout_DecNew( aout_instance_t *, audio_sample_format_t *,
139                    const audio_replay_gain_t *, const aout_request_vout_t * );
140 int aout_DecDelete ( aout_instance_t *, aout_input_t * );
141 aout_buffer_t * aout_DecNewBuffer( aout_input_t *, size_t );
142 void aout_DecDeleteBuffer( aout_instance_t *, aout_input_t *, aout_buffer_t * );
143 int aout_DecPlay( aout_instance_t *, aout_input_t *, aout_buffer_t *, int i_input_rate );
144 int aout_DecGetResetLost( aout_instance_t *, aout_input_t * );
145 void aout_DecChangePause( aout_instance_t *, aout_input_t *, bool b_paused, mtime_t i_date );
146 void aout_DecFlush( aout_instance_t *, aout_input_t * );
147
148 /* Audio output locking */
149
150 #if !defined (NDEBUG) \
151  && defined __linux__ && (defined (__i386__) || defined (__x86_64__))
152 # define AOUT_DEBUG 1
153 #endif
154
155 #ifdef AOUT_DEBUG
156 enum
157 {
158     MIXER_LOCK=1,
159     INPUT_LOCK=2,
160     INPUT_FIFO_LOCK=4,
161     OUTPUT_FIFO_LOCK=8,
162     VOLUME_VARS_LOCK=16
163 };
164
165 void aout_lock (unsigned);
166 void aout_unlock (unsigned);
167
168 #else
169 # define aout_lock( i )   (void)0
170 # define aout_unlock( i ) (void)0
171 #endif
172
173 static inline void aout_lock_mixer( aout_instance_t *p_aout )
174 {
175     aout_lock( MIXER_LOCK );
176     vlc_mutex_lock( &p_aout->mixer_lock );
177 }
178
179 static inline void aout_unlock_mixer( aout_instance_t *p_aout )
180 {
181     aout_unlock( MIXER_LOCK );
182     vlc_mutex_unlock( &p_aout->mixer_lock );
183 }
184
185 static inline void aout_lock_input_fifos( aout_instance_t *p_aout )
186 {
187     aout_lock( INPUT_FIFO_LOCK );
188     vlc_mutex_lock( &p_aout->input_fifos_lock );
189 }
190
191 static inline void aout_unlock_input_fifos( aout_instance_t *p_aout )
192 {
193     aout_unlock( INPUT_FIFO_LOCK );
194     vlc_mutex_unlock( &p_aout->input_fifos_lock );
195 }
196
197 static inline void aout_lock_output_fifo( aout_instance_t *p_aout )
198 {
199     aout_lock( OUTPUT_FIFO_LOCK );
200     vlc_mutex_lock( &p_aout->output_fifo_lock );
201 }
202
203 static inline void aout_unlock_output_fifo( aout_instance_t *p_aout )
204 {
205     aout_unlock( OUTPUT_FIFO_LOCK );
206     vlc_mutex_unlock( &p_aout->output_fifo_lock );
207 }
208
209 static inline void aout_lock_input( aout_instance_t *p_aout, aout_input_t * p_input )
210 {
211     (void)p_aout;
212     aout_lock( INPUT_LOCK );
213     vlc_mutex_lock( &p_input->lock );
214 }
215
216 static inline void aout_unlock_input( aout_instance_t *p_aout, aout_input_t * p_input )
217 {
218     (void)p_aout;
219     aout_unlock( INPUT_LOCK );
220     vlc_mutex_unlock( &p_input->lock );
221 }
222
223 static inline void aout_lock_volume( aout_instance_t *p_aout )
224 {
225     aout_lock( VOLUME_VARS_LOCK );
226     vlc_mutex_lock( &p_aout->volume_vars_lock );
227 }
228
229 static inline void aout_unlock_volume( aout_instance_t *p_aout )
230 {
231     aout_unlock( VOLUME_VARS_LOCK );
232     vlc_mutex_unlock( &p_aout->volume_vars_lock );
233 }
234
235 /* Helpers */
236
237 /**
238  * This function will safely mark aout input to be restarted as soon as
239  * possible to take configuration changes into account */
240 static inline void AoutInputsMarkToRestart( aout_instance_t *p_aout )
241 {
242     int i;
243     aout_lock_mixer( p_aout );
244     for( i = 0; i < p_aout->i_nb_inputs; i++ )
245         p_aout->pp_inputs[i]->b_restart = true;
246     aout_unlock_mixer( p_aout );
247 }
248
249 #endif /* !LIBVLC_AOUT_INTERNAL_H */