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 /****************************************************************************
92 *****************************************************************************/
95 int aout_InputNew( aout_instance_t * p_aout, aout_input_t * p_input, const aout_request_vout_t * );
96 int aout_InputDelete( aout_instance_t * p_aout, aout_input_t * p_input );
97 int aout_InputPlay( aout_instance_t * p_aout, aout_input_t * p_input,
98 aout_buffer_t * p_buffer, int i_input_rate );
100 /* From filters.c : */
101 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 );
102 void aout_FiltersDestroyPipeline ( aout_instance_t * p_aout, aout_filter_t ** pp_filters, int i_nb_filters );
103 void aout_FiltersPlay ( aout_instance_t * p_aout, aout_filter_t ** pp_filters, int i_nb_filters, aout_buffer_t ** pp_input_buffer );
104 void aout_FiltersHintBuffers( aout_instance_t * p_aout, aout_filter_t ** pp_filters, int i_nb_filters, aout_alloc_t * p_first_alloc );
107 int aout_MixerNew( aout_instance_t * p_aout );
108 void aout_MixerDelete( aout_instance_t * p_aout );
109 void aout_MixerRun( aout_instance_t * p_aout );
110 int aout_MixerMultiplierSet( aout_instance_t * p_aout, float f_multiplier );
111 int aout_MixerMultiplierGet( aout_instance_t * p_aout, float * pf_multiplier );
113 /* From output.c : */
114 int aout_OutputNew( aout_instance_t * p_aout,
115 audio_sample_format_t * p_format );
116 void aout_OutputPlay( aout_instance_t * p_aout, aout_buffer_t * p_buffer );
117 void aout_OutputDelete( aout_instance_t * p_aout );
120 /* From common.c : */
121 #define aout_New(a) __aout_New(VLC_OBJECT(a))
122 /* Release with vlc_object_release() */
123 aout_instance_t * __aout_New ( vlc_object_t * );
125 void aout_FifoInit( aout_instance_t *, aout_fifo_t *, uint32_t );
126 mtime_t aout_FifoNextStart( aout_instance_t *, aout_fifo_t * );
127 void aout_FifoPush( aout_instance_t *, aout_fifo_t *, aout_buffer_t * );
128 void aout_FifoSet( aout_instance_t *, aout_fifo_t *, mtime_t );
129 void aout_FifoMoveDates( aout_instance_t *, aout_fifo_t *, mtime_t );
130 void aout_FifoDestroy( aout_instance_t * p_aout, aout_fifo_t * p_fifo );
131 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 int aout_VolumeSoftGet( aout_instance_t *, audio_volume_t * );
136 int aout_VolumeSoftSet( aout_instance_t *, audio_volume_t );
137 int aout_VolumeSoftInfos( aout_instance_t *, audio_volume_t * );
138 int aout_VolumeNoneGet( aout_instance_t *, audio_volume_t * );
139 int aout_VolumeNoneSet( aout_instance_t *, audio_volume_t );
140 int aout_VolumeNoneInfos( aout_instance_t *, audio_volume_t * );
143 #define aout_DecNew(a, b, c, d, e) __aout_DecNew(VLC_OBJECT(a), b, c, d, e)
144 aout_input_t * __aout_DecNew( vlc_object_t *, aout_instance_t **,
145 audio_sample_format_t *, const audio_replay_gain_t *,
146 const aout_request_vout_t * );
147 int aout_DecDelete ( aout_instance_t *, aout_input_t * );
148 aout_buffer_t * aout_DecNewBuffer( aout_input_t *, size_t );
149 void aout_DecDeleteBuffer( aout_instance_t *, aout_input_t *, aout_buffer_t * );
150 int aout_DecPlay( aout_instance_t *, aout_input_t *, aout_buffer_t *, int i_input_rate );
151 int aout_DecGetResetLost( aout_instance_t *, aout_input_t * );
152 void aout_DecChangePause( aout_instance_t *, aout_input_t *, bool b_paused, mtime_t i_date );
153 void aout_DecFlush( aout_instance_t *, aout_input_t * );
157 static inline void aout_lock_mixer( aout_instance_t *p_aout )
159 vlc_mutex_lock( &p_aout->mixer_lock );
162 static inline void aout_unlock_mixer( aout_instance_t *p_aout )
164 vlc_mutex_unlock( &p_aout->mixer_lock );
167 static inline void aout_lock_input_fifos( aout_instance_t *p_aout )
169 vlc_mutex_lock( &p_aout->input_fifos_lock );
172 static inline void aout_unlock_input_fifos( aout_instance_t *p_aout )
174 vlc_mutex_unlock( &p_aout->input_fifos_lock );
177 static inline void aout_lock_output_fifo( aout_instance_t *p_aout )
179 vlc_mutex_lock( &p_aout->output_fifo_lock );
182 static inline void aout_unlock_output_fifo( aout_instance_t *p_aout )
184 vlc_mutex_unlock( &p_aout->output_fifo_lock );
187 static inline void aout_lock_input( aout_instance_t *p_aout, aout_input_t * p_input )
190 vlc_mutex_lock( &p_input->lock );
193 static inline void aout_unlock_input( aout_instance_t *p_aout, aout_input_t * p_input )
196 vlc_mutex_unlock( &p_input->lock );
201 * This function will safely mark aout input to be restarted as soon as
202 * possible to take configuration changes into account */
203 static inline void AoutInputsMarkToRestart( aout_instance_t *p_aout )
206 aout_lock_mixer( p_aout );
207 for( i = 0; i < p_aout->i_nb_inputs; i++ )
208 p_aout->pp_inputs[i]->b_restart = true;
209 aout_unlock_mixer( p_aout );
212 /* This function will add or remove a a module from a string list (comma
213 * separated). It will return true if there is a modification
214 * In case p_aout is NULL, we will use configuration instead of variable */
215 static inline bool AoutChangeFilterString( vlc_object_t *p_obj, aout_instance_t * p_aout,
216 const char* psz_variable,
217 const char *psz_name, bool b_add )
222 if( *psz_name == '\0' )
226 var_Get( p_aout, psz_variable, &val );
228 val.psz_string = config_GetPsz( p_obj, "audio-filter" );
230 if( !val.psz_string )
231 val.psz_string = strdup("");
233 psz_parser = strstr( val.psz_string, psz_name );
235 if( ( b_add && psz_parser ) || ( !b_add && !psz_parser ) )
238 free( val.psz_string );
244 char *psz_old = val.psz_string;
247 if( asprintf( &val.psz_string, "%s:%s", psz_old, psz_name ) == -1 )
248 val.psz_string = NULL;
251 val.psz_string = strdup( psz_name );
256 const int i_name = strlen( psz_name );
257 const char *psz_next;
259 psz_next = &psz_parser[i_name];
260 if( *psz_next == ':' )
263 memmove( psz_parser, psz_next, strlen(psz_next)+1 );
267 var_Set( p_aout, psz_variable, val );
269 config_PutPsz( p_obj, psz_variable, val.psz_string );
270 free( val.psz_string );
274 #endif /* !__LIBVLC_AOUT_INTERNAL_H */