]> git.sesse.net Git - vlc/blob - include/aout_internal.h
* aout_Volume* functions now do their own vlc_object_find() on the
[vlc] / include / aout_internal.h
1 /*****************************************************************************
2  * aout_internal.h : internal defines for audio output
3  *****************************************************************************
4  * Copyright (C) 2002 VideoLAN
5  * $Id: aout_internal.h,v 1.38 2003/02/09 01:13:43 massiot Exp $
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., 59 Temple Place - Suite 330, Boston, MA  02111, USA.
22  *****************************************************************************/
23
24 /*****************************************************************************
25  * aout_alloc_t : allocation of memory in the audio output
26  *****************************************************************************/
27 typedef struct aout_alloc_t
28 {
29     int                     i_alloc_type;
30     int                     i_bytes_per_sec;
31 } aout_alloc_t;
32
33 #define AOUT_ALLOC_NONE     0
34 #define AOUT_ALLOC_STACK    1
35 #define AOUT_ALLOC_HEAP     2
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         }                                                                   \
43         else
44 #else
45 #   define ALLOCA_TEST( p_alloc, p_new_buffer )
46 #endif
47
48 #define aout_BufferAlloc( p_alloc, i_nb_usec, p_previous_buffer,            \
49                           p_new_buffer )                                    \
50     if ( (p_alloc)->i_alloc_type == AOUT_ALLOC_NONE )                       \
51     {                                                                       \
52         (p_new_buffer) = p_previous_buffer;                                 \
53     }                                                                       \
54     else                                                                    \
55     {                                                                       \
56         int i_alloc_size;                                                   \
57         i_alloc_size = (int)( (uint64_t)(p_alloc)->i_bytes_per_sec          \
58                                             * (i_nb_usec) / 1000000 + 1 );  \
59         ALLOCA_TEST( p_alloc, p_new_buffer )                                \
60         {                                                                   \
61             (p_new_buffer) = malloc( i_alloc_size + sizeof(aout_buffer_t) );\
62         }                                                                   \
63         if ( p_new_buffer != NULL )                                         \
64         {                                                                   \
65             (p_new_buffer)->i_alloc_type = (p_alloc)->i_alloc_type;         \
66             (p_new_buffer)->i_size = i_alloc_size;                          \
67             (p_new_buffer)->p_buffer = (byte_t *)(p_new_buffer)             \
68                                          + sizeof(aout_buffer_t);           \
69             if ( (p_previous_buffer) != NULL )                              \
70             {                                                               \
71                 (p_new_buffer)->start_date =                                \
72                            ((aout_buffer_t *)p_previous_buffer)->start_date;\
73                 (p_new_buffer)->end_date =                                  \
74                            ((aout_buffer_t *)p_previous_buffer)->end_date;  \
75             }                                                               \
76         }                                                                   \
77         /* we'll keep that for a while --Meuuh */                           \
78         /* else printf("%s:%d\n", __FILE__, __LINE__); */                   \
79     }
80
81 #define aout_BufferFree( p_buffer )                                         \
82     if ( (p_buffer)->i_alloc_type == AOUT_ALLOC_HEAP )                      \
83     {                                                                       \
84         free( p_buffer );                                                   \
85     }
86
87 /*****************************************************************************
88  * aout_fifo_t : audio output buffer FIFO
89  *****************************************************************************/
90 struct aout_fifo_t
91 {
92     aout_buffer_t *         p_first;
93     aout_buffer_t **        pp_last;
94     audio_date_t            end_date;
95 };
96
97 /*****************************************************************************
98  * aout_filter_t : audio output filter
99  *****************************************************************************/
100 typedef struct aout_filter_t
101 {
102     VLC_COMMON_MEMBERS
103
104     audio_sample_format_t   input;
105     audio_sample_format_t   output;
106     aout_alloc_t            output_alloc;
107
108     module_t *              p_module;
109     struct aout_filter_sys_t * p_sys;
110     void                 (* pf_do_work)( struct aout_instance_t *,
111                                          struct aout_filter_t *,
112                                          struct aout_buffer_t *,
113                                          struct aout_buffer_t * );
114     vlc_bool_t              b_in_place;
115     vlc_bool_t              b_reinit;
116 } aout_filter_t;
117
118 /*****************************************************************************
119  * aout_mixer_t : audio output mixer
120  *****************************************************************************/
121 typedef struct aout_mixer_t
122 {
123     audio_sample_format_t   mixer;
124     aout_alloc_t            output_alloc;
125
126     module_t *              p_module;
127     struct aout_mixer_sys_t * p_sys;
128     void                 (* pf_do_work)( struct aout_instance_t *,
129                                          struct aout_buffer_t * );
130
131     /* If b_error == 1, there is no mixer. */
132     vlc_bool_t              b_error;
133     /* Multiplier used to raise or lower the volume of the sound in
134      * software. Beware, this creates sound distortion and should be avoided
135      * as much as possible. This isn't available for non-float32 mixer. */
136     float                   f_multiplier;
137 } aout_mixer_t;
138
139 /*****************************************************************************
140  * aout_input_t : input stream for the audio output
141  *****************************************************************************/
142 #define AOUT_RESAMPLING_NONE     0
143 #define AOUT_RESAMPLING_UP       1
144 #define AOUT_RESAMPLING_DOWN     2
145 struct aout_input_t
146 {
147     /* When this lock is taken, the pipeline cannot be changed by a
148      * third-party. */
149     vlc_mutex_t             lock;
150
151     audio_sample_format_t   input;
152     aout_alloc_t            input_alloc;
153
154     /* pre-filters */
155     aout_filter_t *         pp_filters[AOUT_MAX_FILTERS];
156     int                     i_nb_filters;
157
158     /* resamplers */
159     aout_filter_t *         pp_resamplers[AOUT_MAX_FILTERS];
160     int                     i_nb_resamplers;
161     int                     i_resampling_type;
162     mtime_t                 i_resamp_start_date;
163     int                     i_resamp_start_drift;
164
165     aout_fifo_t             fifo;
166
167     /* Mixer information */
168     byte_t *                p_first_byte_to_mix;
169
170     /* If b_error == 1, there is no input pipeline. */
171     vlc_bool_t              b_error;
172     /* Did we just change the output format ? (expect buffer inconsistencies) */
173     vlc_bool_t              b_changed;
174 };
175
176 /*****************************************************************************
177  * aout_output_t : output stream for the audio output
178  *****************************************************************************/
179 typedef struct aout_output_t
180 {
181     audio_sample_format_t   output;
182     /* Indicates whether the audio output is currently starving, to avoid
183      * printing a 1,000 "output is starving" messages. */
184     vlc_bool_t              b_starving;
185
186     /* post-filters */
187     aout_filter_t *         pp_filters[AOUT_MAX_FILTERS];
188     int                     i_nb_filters;
189
190     aout_fifo_t             fifo;
191
192     struct module_t *       p_module;
193     struct aout_sys_t *     p_sys;
194     void                 (* pf_play)( aout_instance_t * );
195     int                  (* pf_volume_get )( aout_instance_t *, audio_volume_t * );
196     int                  (* pf_volume_set )( aout_instance_t *, audio_volume_t );
197     int                  (* pf_volume_infos )( aout_instance_t *, audio_volume_t * );
198     int                     i_nb_samples;
199
200     /* Current volume for the output - it's just a placeholder, the plug-in
201      * may or may not use it. */
202     audio_volume_t          i_volume;
203
204     /* If b_error == 1, there is no audio output pipeline. */
205     vlc_bool_t              b_error;
206 } aout_output_t;
207
208 /*****************************************************************************
209  * aout_instance_t : audio output thread descriptor
210  *****************************************************************************/
211 struct aout_instance_t
212 {
213     VLC_COMMON_MEMBERS
214
215     /* Locks : please note that if you need several of these locks, it is
216      * mandatory (to avoid deadlocks) to take them in the following order :
217      * mixer_lock, p_input->lock, output_fifo_lock, input_fifos_lock.
218      * --Meuuh */
219     /* When input_fifos_lock is taken, none of the p_input->fifo structures
220      * can be read or modified by a third-party thread. */
221     vlc_mutex_t             input_fifos_lock;
222     /* When mixer_lock is taken, all decoder threads willing to mix a
223      * buffer must wait until it is released. The output pipeline cannot
224      * be modified. No input stream can be added or removed. */
225     vlc_mutex_t             mixer_lock;
226     /* When output_fifo_lock is taken, the p_aout->output.fifo structure
227      * cannot be read or written  by a third-party thread. */
228     vlc_mutex_t             output_fifo_lock;
229
230     /* Input streams & pre-filters */
231     aout_input_t *          pp_inputs[AOUT_MAX_INPUTS];
232     int                     i_nb_inputs;
233
234     /* Mixer */
235     aout_mixer_t            mixer;
236
237     /* Output plug-in */
238     aout_output_t           output;
239 };
240
241 /*****************************************************************************
242  * Prototypes
243  *****************************************************************************/
244 /* From input.c : */
245 int aout_InputNew( aout_instance_t * p_aout, aout_input_t * p_input );
246 int aout_InputDelete( aout_instance_t * p_aout, aout_input_t * p_input );
247 int aout_InputPlay( aout_instance_t * p_aout, aout_input_t * p_input,
248                     aout_buffer_t * p_buffer );
249
250 /* From filters.c : */
251 int aout_FiltersCreatePipeline( aout_instance_t * p_aout,
252                                 aout_filter_t ** pp_filters,
253                                 int * pi_nb_filters,
254                                 const audio_sample_format_t * p_input_format,
255                                 const audio_sample_format_t * p_output_format );
256 void aout_FiltersDestroyPipeline( aout_instance_t * p_aout,
257                                   aout_filter_t ** pp_filters,
258                                   int i_nb_filters );
259 void aout_FiltersHintBuffers( aout_instance_t * p_aout,
260                               aout_filter_t ** pp_filters,
261                               int i_nb_filters, aout_alloc_t * p_first_alloc );
262 void aout_FiltersPlay( aout_instance_t * p_aout,
263                        aout_filter_t ** pp_filters,
264                        int i_nb_filters, aout_buffer_t ** pp_input_buffer );
265
266 /* From mixer.c : */
267 int aout_MixerNew( aout_instance_t * p_aout );
268 void aout_MixerDelete( aout_instance_t * p_aout );
269 void aout_MixerRun( aout_instance_t * p_aout );
270 int aout_MixerMultiplierSet( aout_instance_t * p_aout, float f_multiplier );
271 int aout_MixerMultiplierGet( aout_instance_t * p_aout, float * pf_multiplier );
272
273 /* From output.c : */
274 int aout_OutputNew( aout_instance_t * p_aout,
275                     audio_sample_format_t * p_format );
276 void aout_OutputPlay( aout_instance_t * p_aout, aout_buffer_t * p_buffer );
277 void aout_OutputDelete( aout_instance_t * p_aout );
278 VLC_EXPORT( aout_buffer_t *, aout_OutputNextBuffer, ( aout_instance_t *, mtime_t, vlc_bool_t ) );
279
280 /* From common.c : */
281 VLC_EXPORT( unsigned int, aout_FormatNbChannels, ( const audio_sample_format_t * p_format ) );
282 VLC_EXPORT( void, aout_FormatPrepare, ( audio_sample_format_t * p_format ) );
283 VLC_EXPORT( void, aout_FormatPrint, ( aout_instance_t * p_aout, const char * psz_text, const audio_sample_format_t * p_format ) );
284 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 ) );
285 VLC_EXPORT( const char *, aout_FormatPrintChannels, ( const audio_sample_format_t * ) );
286 void aout_FifoInit( aout_instance_t *, aout_fifo_t *, uint32_t );
287 mtime_t aout_FifoNextStart( aout_instance_t *, aout_fifo_t * );
288 void aout_FifoPush( aout_instance_t *, aout_fifo_t *, aout_buffer_t * );
289 void aout_FifoSet( aout_instance_t *, aout_fifo_t *, mtime_t );
290 void aout_FifoMoveDates( aout_instance_t *, aout_fifo_t *, mtime_t );
291 VLC_EXPORT( aout_buffer_t *, aout_FifoPop, ( aout_instance_t * p_aout, aout_fifo_t * p_fifo ) );
292 void aout_FifoDestroy( aout_instance_t * p_aout, aout_fifo_t * p_fifo );
293 VLC_EXPORT( mtime_t, aout_FifoFirstDate, ( aout_instance_t *, aout_fifo_t * ) );
294
295 /* From intf.c :*/
296 VLC_EXPORT( void, aout_VolumeSoftInit, ( aout_instance_t * ) );
297 int aout_VolumeSoftGet( aout_instance_t *, audio_volume_t * );
298 int aout_VolumeSoftSet( aout_instance_t *, audio_volume_t );
299 int aout_VolumeSoftInfos( aout_instance_t *, audio_volume_t * );
300 VLC_EXPORT( void, aout_VolumeNoneInit, ( aout_instance_t * ) );
301 int aout_VolumeNoneGet( aout_instance_t *, audio_volume_t * );
302 int aout_VolumeNoneSet( aout_instance_t *, audio_volume_t );
303 int aout_VolumeNoneInfos( aout_instance_t *, audio_volume_t * );
304