1 /*****************************************************************************
2 * aout_internal.h : internal defines for audio output
3 *****************************************************************************
4 * Copyright (C) 2002 the VideoLAN team
7 * Authors: Christophe Massiot <massiot@via.ecp.fr>
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.
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.
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 *****************************************************************************/
24 /*****************************************************************************
25 * aout_alloc_t : allocation of memory in the audio output
26 *****************************************************************************/
27 typedef struct aout_alloc_t
33 #define AOUT_ALLOC_NONE 0
34 #define AOUT_ALLOC_STACK 1
35 #define AOUT_ALLOC_HEAP 2
37 #if defined( __APPLE__ ) || defined( SYS_BSD )
42 # define ALLOCA_TEST( p_alloc, p_new_buffer ) \
43 if ( (p_alloc)->i_alloc_type == AOUT_ALLOC_STACK ) \
45 (p_new_buffer) = alloca( i_alloc_size + sizeof(aout_buffer_t) );\
46 i_alloc_type = AOUT_ALLOC_STACK; \
50 # define ALLOCA_TEST( p_alloc, p_new_buffer )
53 #define aout_BufferAlloc( p_alloc, i_nb_usec, p_previous_buffer, \
55 if ( (p_alloc)->i_alloc_type == AOUT_ALLOC_NONE ) \
57 (p_new_buffer) = p_previous_buffer; \
61 int i_alloc_size, i_alloc_type; \
62 i_alloc_size = (int)( (uint64_t)(p_alloc)->i_bytes_per_sec \
63 * (i_nb_usec) / 1000000 + 1 ); \
64 ALLOCA_TEST( p_alloc, p_new_buffer ) \
66 (p_new_buffer) = malloc( i_alloc_size + sizeof(aout_buffer_t) );\
67 i_alloc_type = AOUT_ALLOC_HEAP; \
69 if ( p_new_buffer != NULL ) \
71 (p_new_buffer)->i_alloc_type = i_alloc_type; \
72 (p_new_buffer)->i_size = i_alloc_size; \
73 (p_new_buffer)->p_buffer = (byte_t *)(p_new_buffer) \
74 + sizeof(aout_buffer_t); \
75 if ( (p_previous_buffer) != NULL ) \
77 (p_new_buffer)->start_date = \
78 ((aout_buffer_t *)p_previous_buffer)->start_date;\
79 (p_new_buffer)->end_date = \
80 ((aout_buffer_t *)p_previous_buffer)->end_date; \
83 /* we'll keep that for a while --Meuuh */ \
84 /* else printf("%s:%d\n", __FILE__, __LINE__); */ \
87 #define aout_BufferFree( p_buffer ) \
88 if( p_buffer != NULL && (p_buffer)->i_alloc_type == AOUT_ALLOC_HEAP ) \
94 /*****************************************************************************
95 * aout_fifo_t : audio output buffer FIFO
96 *****************************************************************************/
99 aout_buffer_t * p_first;
100 aout_buffer_t ** pp_last;
101 audio_date_t end_date;
104 /*****************************************************************************
105 * aout_filter_t : audio output filter
106 *****************************************************************************/
111 audio_sample_format_t input;
112 audio_sample_format_t output;
113 aout_alloc_t output_alloc;
116 struct aout_filter_sys_t * p_sys;
117 void (* pf_do_work)( struct aout_instance_t *,
118 struct aout_filter_t *,
119 struct aout_buffer_t *,
120 struct aout_buffer_t * );
121 vlc_bool_t b_in_place;
122 vlc_bool_t b_continuity;
125 /*****************************************************************************
126 * aout_mixer_t : audio output mixer
127 *****************************************************************************/
128 typedef struct aout_mixer_t
130 audio_sample_format_t mixer;
131 aout_alloc_t output_alloc;
134 struct aout_mixer_sys_t * p_sys;
135 void (* pf_do_work)( struct aout_instance_t *,
136 struct aout_buffer_t * );
138 /* If b_error == 1, there is no mixer. */
140 /* Multiplier used to raise or lower the volume of the sound in
141 * software. Beware, this creates sound distortion and should be avoided
142 * as much as possible. This isn't available for non-float32 mixer. */
146 /*****************************************************************************
147 * aout_input_t : input stream for the audio output
148 *****************************************************************************/
149 #define AOUT_RESAMPLING_NONE 0
150 #define AOUT_RESAMPLING_UP 1
151 #define AOUT_RESAMPLING_DOWN 2
154 /* When this lock is taken, the pipeline cannot be changed by a
158 /* The input thread that spawned this input */
159 input_thread_t *p_input_thread;
161 audio_sample_format_t input;
162 aout_alloc_t input_alloc;
165 aout_filter_t * pp_filters[AOUT_MAX_FILTERS];
169 aout_filter_t * pp_resamplers[AOUT_MAX_FILTERS];
171 int i_resampling_type;
172 mtime_t i_resamp_start_date;
173 int i_resamp_start_drift;
177 /* Mixer information */
178 byte_t * p_first_byte_to_mix;
180 /* If b_restart == 1, the input pipeline will be re-created. */
181 vlc_bool_t b_restart;
183 /* If b_error == 1, there is no input pipeline. */
186 /* Did we just change the output format? (expect buffer inconsistencies) */
187 vlc_bool_t b_changed;
189 /* internal caching delay from input */
191 /* desynchronisation delay request by the user */
196 /*****************************************************************************
197 * aout_output_t : output stream for the audio output
198 *****************************************************************************/
199 typedef struct aout_output_t
201 audio_sample_format_t output;
202 /* Indicates whether the audio output is currently starving, to avoid
203 * printing a 1,000 "output is starving" messages. */
204 vlc_bool_t b_starving;
207 aout_filter_t * pp_filters[AOUT_MAX_FILTERS];
212 struct module_t * p_module;
213 struct aout_sys_t * p_sys;
214 void (* pf_play)( aout_instance_t * );
215 int (* pf_volume_get )( aout_instance_t *, audio_volume_t * );
216 int (* pf_volume_set )( aout_instance_t *, audio_volume_t );
217 int (* pf_volume_infos )( aout_instance_t *, audio_volume_t * );
220 /* Current volume for the output - it's just a placeholder, the plug-in
221 * may or may not use it. */
222 audio_volume_t i_volume;
224 /* If b_error == 1, there is no audio output pipeline. */
228 /*****************************************************************************
229 * aout_instance_t : audio output thread descriptor
230 *****************************************************************************/
231 struct aout_instance_t
235 /* Locks : please note that if you need several of these locks, it is
236 * mandatory (to avoid deadlocks) to take them in the following order :
237 * mixer_lock, p_input->lock, output_fifo_lock, input_fifos_lock.
239 /* When input_fifos_lock is taken, none of the p_input->fifo structures
240 * can be read or modified by a third-party thread. */
241 vlc_mutex_t input_fifos_lock;
242 /* When mixer_lock is taken, all decoder threads willing to mix a
243 * buffer must wait until it is released. The output pipeline cannot
244 * be modified. No input stream can be added or removed. */
245 vlc_mutex_t mixer_lock;
246 /* When output_fifo_lock is taken, the p_aout->output.fifo structure
247 * cannot be read or written by a third-party thread. */
248 vlc_mutex_t output_fifo_lock;
250 /* Input streams & pre-filters */
251 aout_input_t * pp_inputs[AOUT_MAX_INPUTS];
258 aout_output_t output;
261 /*****************************************************************************
263 *****************************************************************************/
265 int aout_InputNew( aout_instance_t * p_aout, aout_input_t * p_input );
266 int aout_InputDelete( aout_instance_t * p_aout, aout_input_t * p_input );
267 int aout_InputPlay( aout_instance_t * p_aout, aout_input_t * p_input,
268 aout_buffer_t * p_buffer );
270 /* From filters.c : */
271 VLC_EXPORT( int, aout_FiltersCreatePipeline, ( aout_instance_t * p_aout, aout_filter_t ** pp_filters, int * pi_nb_filters, const audio_sample_format_t * p_input_format, const audio_sample_format_t * p_output_format ) );
272 VLC_EXPORT( void, aout_FiltersDestroyPipeline, ( aout_instance_t * p_aout, aout_filter_t ** pp_filters, int i_nb_filters ) );
273 VLC_EXPORT( void, aout_FiltersPlay, ( aout_instance_t * p_aout, aout_filter_t ** pp_filters, int i_nb_filters, aout_buffer_t ** pp_input_buffer ) );
274 void aout_FiltersHintBuffers( aout_instance_t * p_aout, aout_filter_t ** pp_filters, int i_nb_filters, aout_alloc_t * p_first_alloc );
277 int aout_MixerNew( aout_instance_t * p_aout );
278 void aout_MixerDelete( aout_instance_t * p_aout );
279 void aout_MixerRun( aout_instance_t * p_aout );
280 int aout_MixerMultiplierSet( aout_instance_t * p_aout, float f_multiplier );
281 int aout_MixerMultiplierGet( aout_instance_t * p_aout, float * pf_multiplier );
283 /* From output.c : */
284 int aout_OutputNew( aout_instance_t * p_aout,
285 audio_sample_format_t * p_format );
286 void aout_OutputPlay( aout_instance_t * p_aout, aout_buffer_t * p_buffer );
287 void aout_OutputDelete( aout_instance_t * p_aout );
288 VLC_EXPORT( aout_buffer_t *, aout_OutputNextBuffer, ( aout_instance_t *, mtime_t, vlc_bool_t ) );
290 /* From common.c : */
291 VLC_EXPORT( unsigned int, aout_FormatNbChannels, ( const audio_sample_format_t * p_format ) );
292 VLC_EXPORT( void, aout_FormatPrepare, ( audio_sample_format_t * p_format ) );
293 VLC_EXPORT( void, aout_FormatPrint, ( aout_instance_t * p_aout, const char * psz_text, const audio_sample_format_t * p_format ) );
294 VLC_EXPORT( 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 ) );
295 VLC_EXPORT( const char *, aout_FormatPrintChannels, ( const audio_sample_format_t * ) );
296 void aout_FifoInit( aout_instance_t *, aout_fifo_t *, uint32_t );
297 mtime_t aout_FifoNextStart( aout_instance_t *, aout_fifo_t * );
298 void aout_FifoPush( aout_instance_t *, aout_fifo_t *, aout_buffer_t * );
299 void aout_FifoSet( aout_instance_t *, aout_fifo_t *, mtime_t );
300 void aout_FifoMoveDates( aout_instance_t *, aout_fifo_t *, mtime_t );
301 VLC_EXPORT( aout_buffer_t *, aout_FifoPop, ( aout_instance_t * p_aout, aout_fifo_t * p_fifo ) );
302 void aout_FifoDestroy( aout_instance_t * p_aout, aout_fifo_t * p_fifo );
303 VLC_EXPORT( mtime_t, aout_FifoFirstDate, ( aout_instance_t *, aout_fifo_t * ) );
306 VLC_EXPORT( void, aout_VolumeSoftInit, ( aout_instance_t * ) );
307 int aout_VolumeSoftGet( aout_instance_t *, audio_volume_t * );
308 int aout_VolumeSoftSet( aout_instance_t *, audio_volume_t );
309 int aout_VolumeSoftInfos( aout_instance_t *, audio_volume_t * );
310 VLC_EXPORT( void, aout_VolumeNoneInit, ( aout_instance_t * ) );
311 int aout_VolumeNoneGet( aout_instance_t *, audio_volume_t * );
312 int aout_VolumeNoneSet( aout_instance_t *, audio_volume_t );
313 int aout_VolumeNoneInfos( aout_instance_t *, audio_volume_t * );