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 #if defined(__PLUGIN__) || defined(__BUILTIN__) || !defined(__LIBVLC__)
25 # error This header file can only be included from LibVLC.
28 #ifndef __LIBVLC_AOUT_INTERNAL_H
29 # define __LIBVLC_AOUT_INTERNAL_H 1
33 #if defined( __APPLE__ ) || defined( SYS_BSD )
38 # define ALLOCA_TEST( p_alloc, p_new_buffer ) \
39 if ( (p_alloc)->i_alloc_type == AOUT_ALLOC_STACK ) \
41 (p_new_buffer) = alloca( i_alloc_size + sizeof(aout_buffer_t) );\
42 i_alloc_type = AOUT_ALLOC_STACK; \
46 # define ALLOCA_TEST( p_alloc, p_new_buffer )
49 #define aout_BufferAlloc( p_alloc, i_nb_usec, p_previous_buffer, \
51 if ( (p_alloc)->i_alloc_type == AOUT_ALLOC_NONE ) \
53 (p_new_buffer) = p_previous_buffer; \
57 int i_alloc_size, i_alloc_type; \
58 i_alloc_size = (int)( (uint64_t)(p_alloc)->i_bytes_per_sec \
59 * (i_nb_usec) / 1000000 + 1 ); \
60 ALLOCA_TEST( p_alloc, p_new_buffer ) \
62 (p_new_buffer) = malloc( i_alloc_size + sizeof(aout_buffer_t) );\
63 i_alloc_type = AOUT_ALLOC_HEAP; \
65 if ( p_new_buffer != NULL ) \
67 (p_new_buffer)->i_alloc_type = i_alloc_type; \
68 (p_new_buffer)->i_size = i_alloc_size; \
69 (p_new_buffer)->p_buffer = (uint8_t *)(p_new_buffer) \
70 + sizeof(aout_buffer_t); \
71 (p_new_buffer)->b_discontinuity = false; \
72 if ( (p_previous_buffer) != NULL ) \
74 (p_new_buffer)->start_date = \
75 ((aout_buffer_t *)p_previous_buffer)->start_date;\
76 (p_new_buffer)->end_date = \
77 ((aout_buffer_t *)p_previous_buffer)->end_date; \
80 /* we'll keep that for a while --Meuuh */ \
81 /* else printf("%s:%d\n", __FILE__, __LINE__); */ \
84 struct aout_filter_owner_sys_t
86 aout_instance_t *p_aout;
87 aout_input_t *p_input;
90 /** an input stream for the audio output */
93 /* When this lock is taken, the pipeline cannot be changed by a
97 audio_sample_format_t input;
98 aout_alloc_t input_alloc;
101 aout_filter_t * pp_filters[AOUT_MAX_FILTERS];
104 aout_filter_t * p_playback_rate_filter;
107 aout_filter_t * pp_resamplers[AOUT_MAX_FILTERS];
109 int i_resampling_type;
110 mtime_t i_resamp_start_date;
111 int i_resamp_start_drift;
113 /* Mixer information */
114 audio_replay_gain_t replay_gain;
116 /* If b_restart == 1, the input pipeline will be re-created. */
119 /* If b_error == 1, there is no input pipeline. */
122 /* Did we just change the output format? (expect buffer inconsistencies) */
125 /* last rate from input */
126 int i_last_input_rate;
133 mtime_t i_pause_date;
137 aout_request_vout_t request_vout;
140 aout_mixer_input_t mixer;
143 /****************************************************************************
145 *****************************************************************************/
148 int aout_InputNew( aout_instance_t * p_aout, aout_input_t * p_input, const aout_request_vout_t * );
149 int aout_InputDelete( aout_instance_t * p_aout, aout_input_t * p_input );
150 int aout_InputPlay( aout_instance_t * p_aout, aout_input_t * p_input,
151 aout_buffer_t * p_buffer, int i_input_rate );
153 /* From filters.c : */
154 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 );
155 void aout_FiltersDestroyPipeline ( aout_instance_t * p_aout, aout_filter_t ** pp_filters, int i_nb_filters );
156 void aout_FiltersPlay ( aout_instance_t * p_aout, aout_filter_t ** pp_filters, int i_nb_filters, aout_buffer_t ** pp_input_buffer );
157 void aout_FiltersHintBuffers( aout_instance_t * p_aout, aout_filter_t ** pp_filters, int i_nb_filters, aout_alloc_t * p_first_alloc );
160 int aout_MixerNew( aout_instance_t * p_aout );
161 void aout_MixerDelete( aout_instance_t * p_aout );
162 void aout_MixerRun( aout_instance_t * p_aout );
163 int aout_MixerMultiplierSet( aout_instance_t * p_aout, float f_multiplier );
164 int aout_MixerMultiplierGet( aout_instance_t * p_aout, float * pf_multiplier );
166 /* From output.c : */
167 int aout_OutputNew( aout_instance_t * p_aout,
168 audio_sample_format_t * p_format );
169 void aout_OutputPlay( aout_instance_t * p_aout, aout_buffer_t * p_buffer );
170 void aout_OutputDelete( aout_instance_t * p_aout );
173 /* From common.c : */
174 #define aout_New(a) __aout_New(VLC_OBJECT(a))
175 /* Release with vlc_object_release() */
176 aout_instance_t * __aout_New ( vlc_object_t * );
178 void aout_FifoInit( aout_instance_t *, aout_fifo_t *, uint32_t );
179 mtime_t aout_FifoNextStart( aout_instance_t *, aout_fifo_t * );
180 void aout_FifoPush( aout_instance_t *, aout_fifo_t *, aout_buffer_t * );
181 void aout_FifoSet( aout_instance_t *, aout_fifo_t *, mtime_t );
182 void aout_FifoMoveDates( aout_instance_t *, aout_fifo_t *, mtime_t );
183 void aout_FifoDestroy( aout_instance_t * p_aout, aout_fifo_t * p_fifo );
184 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 );
188 int aout_VolumeSoftGet( aout_instance_t *, audio_volume_t * );
189 int aout_VolumeSoftSet( aout_instance_t *, audio_volume_t );
190 int aout_VolumeSoftInfos( aout_instance_t *, audio_volume_t * );
191 int aout_VolumeNoneGet( aout_instance_t *, audio_volume_t * );
192 int aout_VolumeNoneSet( aout_instance_t *, audio_volume_t );
193 int aout_VolumeNoneInfos( aout_instance_t *, audio_volume_t * );
196 #define aout_DecNew(a, b, c, d, e) __aout_DecNew(VLC_OBJECT(a), b, c, d, e)
197 aout_input_t * __aout_DecNew( vlc_object_t *, aout_instance_t **,
198 audio_sample_format_t *, const audio_replay_gain_t *,
199 const aout_request_vout_t * );
200 int aout_DecDelete ( aout_instance_t *, aout_input_t * );
201 aout_buffer_t * aout_DecNewBuffer( aout_input_t *, size_t );
202 void aout_DecDeleteBuffer( aout_instance_t *, aout_input_t *, aout_buffer_t * );
203 int aout_DecPlay( aout_instance_t *, aout_input_t *, aout_buffer_t *, int i_input_rate );
204 int aout_DecGetResetLost( aout_instance_t *, aout_input_t * );
205 void aout_DecChangePause( aout_instance_t *, aout_input_t *, bool b_paused, mtime_t i_date );
206 void aout_DecFlush( aout_instance_t *, aout_input_t * );
210 static inline void aout_lock_mixer( aout_instance_t *p_aout )
212 vlc_mutex_lock( &p_aout->mixer_lock );
215 static inline void aout_unlock_mixer( aout_instance_t *p_aout )
217 vlc_mutex_unlock( &p_aout->mixer_lock );
220 static inline void aout_lock_input_fifos( aout_instance_t *p_aout )
222 vlc_mutex_lock( &p_aout->input_fifos_lock );
225 static inline void aout_unlock_input_fifos( aout_instance_t *p_aout )
227 vlc_mutex_unlock( &p_aout->input_fifos_lock );
230 static inline void aout_lock_output_fifo( aout_instance_t *p_aout )
232 vlc_mutex_lock( &p_aout->output_fifo_lock );
235 static inline void aout_unlock_output_fifo( aout_instance_t *p_aout )
237 vlc_mutex_unlock( &p_aout->output_fifo_lock );
240 static inline void aout_lock_input( aout_instance_t *p_aout, aout_input_t * p_input )
243 vlc_mutex_lock( &p_input->lock );
246 static inline void aout_unlock_input( aout_instance_t *p_aout, aout_input_t * p_input )
249 vlc_mutex_unlock( &p_input->lock );
254 * This function will safely mark aout input to be restarted as soon as
255 * possible to take configuration changes into account */
256 static inline void AoutInputsMarkToRestart( aout_instance_t *p_aout )
259 aout_lock_mixer( p_aout );
260 for( i = 0; i < p_aout->i_nb_inputs; i++ )
261 p_aout->pp_inputs[i]->b_restart = true;
262 aout_unlock_mixer( p_aout );
265 /* This function will add or remove a a module from a string list (comma
266 * separated). It will return true if there is a modification
267 * In case p_aout is NULL, we will use configuration instead of variable */
268 static inline bool AoutChangeFilterString( vlc_object_t *p_obj, aout_instance_t * p_aout,
269 const char* psz_variable,
270 const char *psz_name, bool b_add )
275 if( *psz_name == '\0' )
279 var_Get( p_aout, psz_variable, &val );
281 val.psz_string = config_GetPsz( p_obj, "audio-filter" );
283 if( !val.psz_string )
284 val.psz_string = strdup("");
286 psz_parser = strstr( val.psz_string, psz_name );
288 if( ( b_add && psz_parser ) || ( !b_add && !psz_parser ) )
291 free( val.psz_string );
297 char *psz_old = val.psz_string;
300 if( asprintf( &val.psz_string, "%s:%s", psz_old, psz_name ) == -1 )
301 val.psz_string = NULL;
304 val.psz_string = strdup( psz_name );
309 const int i_name = strlen( psz_name );
310 const char *psz_next;
312 psz_next = &psz_parser[i_name];
313 if( *psz_next == ':' )
316 memmove( psz_parser, psz_next, strlen(psz_next)+1 );
320 var_Set( p_aout, psz_variable, val );
322 config_PutPsz( p_obj, psz_variable, val.psz_string );
323 free( val.psz_string );
327 #endif /* !__LIBVLC_AOUT_INTERNAL_H */