]> git.sesse.net Git - vlc/blob - src/audio_output/aout_internal.h
Merge commit 'origin/1.0-bugfix'
[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 #if defined(__PLUGIN__) || defined(__BUILTIN__) || !defined(__LIBVLC__)
25 # error This header file can only be included from LibVLC.
26 #endif
27
28 #ifndef __LIBVLC_AOUT_INTERNAL_H
29 # define __LIBVLC_AOUT_INTERNAL_H 1
30
31 #include <assert.h>
32
33 #if defined( __APPLE__ ) || defined( SYS_BSD )
34 #undef HAVE_ALLOCA
35 #endif
36
37 #ifdef HAVE_ALLOCA
38 #   define ALLOCA_TEST( p_alloc, p_new_buffer )                             \
39         if ( (p_alloc)->i_alloc_type == AOUT_ALLOC_STACK )                  \
40         {                                                                   \
41             (p_new_buffer) = alloca( i_alloc_size + sizeof(aout_buffer_t) );\
42             i_alloc_type = AOUT_ALLOC_STACK;                                \
43         }                                                                   \
44         else
45 #else
46 #   define ALLOCA_TEST( p_alloc, p_new_buffer )
47 #endif
48
49 #define aout_BufferAlloc( p_alloc, i_nb_usec, p_previous_buffer,            \
50                           p_new_buffer )                                    \
51     if ( (p_alloc)->i_alloc_type == AOUT_ALLOC_NONE )                       \
52     {                                                                       \
53         (p_new_buffer) = p_previous_buffer;                                 \
54     }                                                                       \
55     else                                                                    \
56     {                                                                       \
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 )                                \
61         {                                                                   \
62             (p_new_buffer) = malloc( i_alloc_size + sizeof(aout_buffer_t) );\
63             i_alloc_type = AOUT_ALLOC_HEAP;                                 \
64         }                                                                   \
65         if ( p_new_buffer != NULL )                                         \
66         {                                                                   \
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 )                              \
73             {                                                               \
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;  \
78             }                                                               \
79         }                                                                   \
80         /* we'll keep that for a while --Meuuh */                           \
81         /* else printf("%s:%d\n", __FILE__, __LINE__); */                   \
82     }
83
84 struct aout_filter_owner_sys_t
85 {
86     aout_instance_t *p_aout;
87     aout_input_t    *p_input;
88 };
89
90 /****************************************************************************
91  * Prototypes
92  *****************************************************************************/
93
94 /* From input.c : */
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 );
99
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 );
105
106 /* From mixer.c : */
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 );
112
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 );
118
119
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 * );
124
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 );
132
133
134 /* From intf.c :*/
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 * );
141
142 /* From dec.c */
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 * );
154
155 /* Helpers */
156
157 static inline void aout_lock_mixer( aout_instance_t *p_aout )
158 {
159     vlc_mutex_lock( &p_aout->mixer_lock );
160 }
161
162 static inline void aout_unlock_mixer( aout_instance_t *p_aout )
163 {
164     vlc_mutex_unlock( &p_aout->mixer_lock );
165 }
166
167 static inline void aout_lock_input_fifos( aout_instance_t *p_aout )
168 {
169     vlc_mutex_lock( &p_aout->input_fifos_lock );
170 }
171
172 static inline void aout_unlock_input_fifos( aout_instance_t *p_aout )
173 {
174     vlc_mutex_unlock( &p_aout->input_fifos_lock );
175 }
176
177 static inline void aout_lock_output_fifo( aout_instance_t *p_aout )
178 {
179     vlc_mutex_lock( &p_aout->output_fifo_lock );
180 }
181
182 static inline void aout_unlock_output_fifo( aout_instance_t *p_aout )
183 {
184     vlc_mutex_unlock( &p_aout->output_fifo_lock );
185 }
186
187 static inline void aout_lock_input( aout_instance_t *p_aout, aout_input_t * p_input )
188 {
189     (void)p_aout;
190     vlc_mutex_lock( &p_input->lock );
191 }
192
193 static inline void aout_unlock_input( aout_instance_t *p_aout, aout_input_t * p_input )
194 {
195     (void)p_aout;
196     vlc_mutex_unlock( &p_input->lock );
197 }
198
199
200 /**
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 )
204 {
205     int i;
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 );
210 }
211
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 )
218 {
219     vlc_value_t val;
220     char *psz_parser;
221
222     if( *psz_name == '\0' )
223         return false;
224
225     if( p_aout )
226         var_Get( p_aout, psz_variable, &val );
227     else
228         val.psz_string = config_GetPsz( p_obj, "audio-filter" );
229
230     if( !val.psz_string )
231         val.psz_string = strdup("");
232
233     psz_parser = strstr( val.psz_string, psz_name );
234
235     if( ( b_add && psz_parser ) || ( !b_add && !psz_parser ) )
236     {
237         /* Nothing to do */
238         free( val.psz_string );
239         return false;
240     }
241
242     if( b_add )
243     {
244         char *psz_old = val.psz_string;
245         if( *psz_old )
246         {
247             if( asprintf( &val.psz_string, "%s:%s", psz_old, psz_name ) == -1 )
248                 val.psz_string = NULL;
249         }
250         else
251             val.psz_string = strdup( psz_name );
252         free( psz_old );
253     }
254     else
255     {
256         const int i_name = strlen( psz_name );
257         const char *psz_next;
258
259         psz_next = &psz_parser[i_name];
260         if( *psz_next == ':' )
261             psz_next++;
262
263         memmove( psz_parser, psz_next, strlen(psz_next)+1 );
264     }
265
266     if( p_aout )
267         var_Set( p_aout, psz_variable, val );
268     else
269         config_PutPsz( p_obj, psz_variable, val.psz_string );
270     free( val.psz_string );
271     return true;
272 }
273
274 #endif /* !__LIBVLC_AOUT_INTERNAL_H */