]> git.sesse.net Git - vlc/blob - include/vlc_aout.h
QT4 wineventfilter for Win32, allows WM_APPCOMMAND stuff
[vlc] / include / vlc_aout.h
1 /*****************************************************************************
2  * audio_output.h : audio output interface
3  *****************************************************************************
4  * Copyright (C) 2002-2005 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 #ifndef VLC_AOUT_H
25 #define VLC_AOUT_H 1
26
27 /**
28  * \file
29  * This file defines functions, structures and macros for audio output object
30  */
31
32 # ifdef __cplusplus
33 extern "C" {
34 # endif
35
36 #include "vlc_es.h"
37
38 #define AOUT_FMTS_IDENTICAL( p_first, p_second ) (                          \
39     ((p_first)->i_format == (p_second)->i_format)                           \
40       && ((p_first)->i_rate == (p_second)->i_rate)                          \
41       && ((p_first)->i_physical_channels == (p_second)->i_physical_channels)\
42       && ((p_first)->i_original_channels == (p_second)->i_original_channels) )
43
44 /* Check if i_rate == i_rate and i_channels == i_channels */
45 #define AOUT_FMTS_SIMILAR( p_first, p_second ) (                            \
46     ((p_first)->i_rate == (p_second)->i_rate)                               \
47       && ((p_first)->i_physical_channels == (p_second)->i_physical_channels)\
48       && ((p_first)->i_original_channels == (p_second)->i_original_channels) )
49
50 #ifdef WORDS_BIGENDIAN
51 #   define AOUT_FMT_S16_NE VLC_FOURCC('s','1','6','b')
52 #   define AOUT_FMT_U16_NE VLC_FOURCC('u','1','6','b')
53 #   define AOUT_FMT_S24_NE VLC_FOURCC('s','2','4','b')
54 #   define AOUT_FMT_S32_NE VLC_FOURCC('s','3','2','b')
55 #   define AOUT_FMT_SPDIF_NE VLC_FOURCC('s','p','d','b')
56 #else
57 #   define AOUT_FMT_S16_NE VLC_FOURCC('s','1','6','l')
58 #   define AOUT_FMT_U16_NE VLC_FOURCC('u','1','6','l')
59 #   define AOUT_FMT_S24_NE VLC_FOURCC('s','2','4','l')
60 #   define AOUT_FMT_S32_NE VLC_FOURCC('s','3','2','l')
61 #   define AOUT_FMT_SPDIF_NE VLC_FOURCC('s','p','d','i')
62 #endif
63
64 #define AOUT_FMT_NON_LINEAR( p_format )                                    \
65     ( ((p_format)->i_format == VLC_FOURCC('s','p','d','i'))                \
66        || ((p_format)->i_format == VLC_FOURCC('s','p','d','b'))            \
67        || ((p_format)->i_format == VLC_FOURCC('a','5','2',' '))            \
68        || ((p_format)->i_format == VLC_FOURCC('d','t','s',' ')) )
69
70 /* This is heavily borrowed from libmad, by Robert Leslie <rob@mars.org> */
71 /*
72  * Fixed-point format: 0xABBBBBBB
73  * A == whole part      (sign + 3 bits)
74  * B == fractional part (28 bits)
75  *
76  * Values are signed two's complement, so the effective range is:
77  * 0x80000000 to 0x7fffffff
78  *       -8.0 to +7.9999999962747097015380859375
79  *
80  * The smallest representable value is:
81  * 0x00000001 == 0.0000000037252902984619140625 (i.e. about 3.725e-9)
82  *
83  * 28 bits of fractional accuracy represent about
84  * 8.6 digits of decimal accuracy.
85  *
86  * Fixed-point numbers can be added or subtracted as normal
87  * integers, but multiplication requires shifting the 64-bit result
88  * from 56 fractional bits back to 28 (and rounding.)
89  */
90 typedef int32_t vlc_fixed_t;
91 #define FIXED32_FRACBITS 28
92 #define FIXED32_MIN ((vlc_fixed_t) -0x80000000L)
93 #define FIXED32_MAX ((vlc_fixed_t) +0x7fffffffL)
94 #define FIXED32_ONE ((vlc_fixed_t) 0x10000000)
95
96 /*
97  * Channels descriptions
98  */
99
100 /* Values available for physical and original channels */
101 #define AOUT_CHAN_CENTER            0x1
102 #define AOUT_CHAN_LEFT              0x2
103 #define AOUT_CHAN_RIGHT             0x4
104 #define AOUT_CHAN_REARCENTER        0x10
105 #define AOUT_CHAN_REARLEFT          0x20
106 #define AOUT_CHAN_REARRIGHT         0x40
107 #define AOUT_CHAN_MIDDLELEFT        0x100
108 #define AOUT_CHAN_MIDDLERIGHT       0x200
109 #define AOUT_CHAN_LFE               0x1000
110
111 /* Values available for original channels only */
112 #define AOUT_CHAN_DOLBYSTEREO       0x10000
113 #define AOUT_CHAN_DUALMONO          0x20000
114 #define AOUT_CHAN_REVERSESTEREO     0x40000
115
116 #define AOUT_CHAN_PHYSMASK          0xFFFF
117 #define AOUT_CHAN_MAX               9
118
119 /* Values used for the audio-device and audio-channels object variables */
120 #define AOUT_VAR_MONO               1
121 #define AOUT_VAR_STEREO             2
122 #define AOUT_VAR_2F2R               4
123 #define AOUT_VAR_3F2R               5
124 #define AOUT_VAR_5_1                6
125 #define AOUT_VAR_6_1                7
126 #define AOUT_VAR_7_1                8
127 #define AOUT_VAR_SPDIF              10
128
129 #define AOUT_VAR_CHAN_STEREO        1
130 #define AOUT_VAR_CHAN_RSTEREO       2
131 #define AOUT_VAR_CHAN_LEFT          3
132 #define AOUT_VAR_CHAN_RIGHT         4
133 #define AOUT_VAR_CHAN_DOLBYS        5
134
135 /*****************************************************************************
136  * Main audio output structures
137  *****************************************************************************/
138
139 /** audio output buffer */
140 struct aout_buffer_t
141 {
142     uint8_t *               p_buffer;
143     int                     i_alloc_type;
144     /* i_size is the real size of the buffer (used for debug ONLY), i_nb_bytes
145      * is the number of significative bytes in it. */
146     size_t                  i_size, i_nb_bytes;
147     unsigned int            i_nb_samples;
148     mtime_t                 start_date, end_date;
149     bool                    b_discontinuity; /* Set on discontinuity (for non pcm stream) */
150
151     struct aout_buffer_t *  p_next;
152
153     /** Private data (aout_buffer_t will disappear soon so no need for an
154      * aout_buffer_sys_t type) */
155     void * p_sys;
156
157     /** This way the release can be overloaded */
158     void (*pf_release)( aout_buffer_t * );
159 };
160
161 #define aout_BufferFree( p_buffer ) do {                                    \
162     if( p_buffer != NULL && (p_buffer)->i_alloc_type == AOUT_ALLOC_HEAP )   \
163     {                                                                       \
164         free( p_buffer );                                                   \
165     }                                                                       \
166     p_buffer = NULL; } while(0)
167
168 /* Size of a frame for S/PDIF output. */
169 #define AOUT_SPDIF_SIZE 6144
170
171 /* Number of samples in an A/52 frame. */
172 #define A52_FRAME_NB 1536
173
174 /* Max input rate factor (1/4 -> 4) */
175 #define AOUT_MAX_INPUT_RATE (4)
176
177 /** date incrementation helper structure without long-term
178  * rounding errors
179  */
180 struct audio_date_t
181 {
182     mtime_t  date;
183     uint32_t i_divider;
184     uint32_t i_remainder;
185 };
186
187 /** allocation of memory in the audio output */
188 typedef struct aout_alloc_t
189 {
190     int                     i_alloc_type;
191     int                     i_bytes_per_sec;
192 } aout_alloc_t;
193
194 #define AOUT_ALLOC_NONE     0
195 #define AOUT_ALLOC_STACK    1
196 #define AOUT_ALLOC_HEAP     2
197
198 /** audio output mixer */
199 typedef struct aout_mixer_t
200 {
201     audio_sample_format_t   mixer;
202     aout_alloc_t            output_alloc;
203
204     module_t *              p_module;
205     struct aout_mixer_sys_t * p_sys;
206     void                 (* pf_do_work)( struct aout_instance_t *,
207                                          struct aout_buffer_t * );
208
209     /** If b_error == 1, there is no mixer. */
210     bool              b_error;
211     /** Multiplier used to raise or lower the volume of the sound in
212      * software. Beware, this creates sound distortion and should be avoided
213      * as much as possible. This isn't available for non-float32 mixer. */
214     float                   f_multiplier;
215 } aout_mixer_t;
216
217 /** audio output buffer FIFO */
218 struct aout_fifo_t
219 {
220     aout_buffer_t *         p_first;
221     aout_buffer_t **        pp_last;
222     audio_date_t            end_date;
223 };
224
225 /** audio output filter */
226 struct aout_filter_t
227 {
228     VLC_COMMON_MEMBERS
229
230     audio_sample_format_t   input;
231     audio_sample_format_t   output;
232     aout_alloc_t            output_alloc;
233
234     module_t *              p_module;
235     struct aout_filter_sys_t * p_sys;
236     void                 (* pf_do_work)( struct aout_instance_t *,
237                                          struct aout_filter_t *,
238                                          struct aout_buffer_t *,
239                                          struct aout_buffer_t * );
240     bool              b_in_place;
241     bool              b_continuity;
242 };
243
244 #define AOUT_RESAMPLING_NONE     0
245 #define AOUT_RESAMPLING_UP       1
246 #define AOUT_RESAMPLING_DOWN     2
247 /** an input stream for the audio output */
248 struct aout_input_t
249 {
250     /* When this lock is taken, the pipeline cannot be changed by a
251      * third-party. */
252     vlc_mutex_t             lock;
253
254     audio_sample_format_t   input;
255     aout_alloc_t            input_alloc;
256
257     /* pre-filters */
258     aout_filter_t *         pp_filters[AOUT_MAX_FILTERS];
259     int                     i_nb_filters;
260
261     aout_filter_t *         p_playback_rate_filter;
262
263     /* resamplers */
264     aout_filter_t *         pp_resamplers[AOUT_MAX_FILTERS];
265     int                     i_nb_resamplers;
266     int                     i_resampling_type;
267     mtime_t                 i_resamp_start_date;
268     int                     i_resamp_start_drift;
269
270     aout_fifo_t             fifo;
271
272     /* Mixer information */
273     uint8_t *               p_first_byte_to_mix;
274     audio_replay_gain_t     replay_gain;
275     float                   f_multiplier;
276
277     /* If b_restart == 1, the input pipeline will be re-created. */
278     bool              b_restart;
279
280     /* If b_error == 1, there is no input pipeline. */
281     bool              b_error;
282
283     /* Did we just change the output format? (expect buffer inconsistencies) */
284     bool              b_changed;
285
286     /* last rate from input */
287     int               i_last_input_rate;
288
289     /* */
290     int               i_buffer_lost;
291
292     /* */
293     bool              b_paused;
294     mtime_t           i_pause_date;
295  };
296
297 /** an output stream for the audio output */
298 typedef struct aout_output_t
299 {
300     audio_sample_format_t   output;
301     /* Indicates whether the audio output is currently starving, to avoid
302      * printing a 1,000 "output is starving" messages. */
303     bool              b_starving;
304
305     /* post-filters */
306     aout_filter_t *         pp_filters[AOUT_MAX_FILTERS];
307     int                     i_nb_filters;
308
309     aout_fifo_t             fifo;
310
311     struct module_t *       p_module;
312     struct aout_sys_t *     p_sys;
313     void                 (* pf_play)( aout_instance_t * );
314     int                  (* pf_volume_get )( aout_instance_t *, audio_volume_t * );
315     int                  (* pf_volume_set )( aout_instance_t *, audio_volume_t );
316     int                  (* pf_volume_infos )( aout_instance_t *, audio_volume_t * );
317     int                     i_nb_samples;
318
319     /* Current volume for the output - it's just a placeholder, the plug-in
320      * may or may not use it. */
321     audio_volume_t          i_volume;
322
323     /* If b_error == 1, there is no audio output pipeline. */
324     bool              b_error;
325 } aout_output_t;
326
327 /** audio output thread descriptor */
328 struct aout_instance_t
329 {
330     VLC_COMMON_MEMBERS
331
332     /* Locks : please note that if you need several of these locks, it is
333      * mandatory (to avoid deadlocks) to take them in the following order :
334      * mixer_lock, p_input->lock, output_fifo_lock, input_fifos_lock.
335      * --Meuuh */
336     /* When input_fifos_lock is taken, none of the p_input->fifo structures
337      * can be read or modified by a third-party thread. */
338     vlc_mutex_t             input_fifos_lock;
339     /* When mixer_lock is taken, all decoder threads willing to mix a
340      * buffer must wait until it is released. The output pipeline cannot
341      * be modified. No input stream can be added or removed. */
342     vlc_mutex_t             mixer_lock;
343     /* When output_fifo_lock is taken, the p_aout->output.fifo structure
344      * cannot be read or written  by a third-party thread. */
345     vlc_mutex_t             output_fifo_lock;
346
347     /* Input streams & pre-filters */
348     aout_input_t *          pp_inputs[AOUT_MAX_INPUTS];
349     int                     i_nb_inputs;
350
351     /* Mixer */
352     aout_mixer_t            mixer;
353
354     /* Output plug-in */
355     aout_output_t           output;
356 };
357
358 /**
359  * It describes the audio channel order VLC except.
360  */
361 static const uint32_t pi_vlc_chan_order_wg4[] =
362 {
363     AOUT_CHAN_LEFT, AOUT_CHAN_RIGHT,
364     AOUT_CHAN_MIDDLELEFT, AOUT_CHAN_MIDDLERIGHT,
365     AOUT_CHAN_REARLEFT, AOUT_CHAN_REARRIGHT, AOUT_CHAN_REARCENTER,
366     AOUT_CHAN_CENTER, AOUT_CHAN_LFE, 0
367 };
368
369 /*****************************************************************************
370  * Prototypes
371  *****************************************************************************/
372
373 /* From common.c : */
374 VLC_EXPORT( void, aout_DateInit, ( audio_date_t *, uint32_t ) );
375 VLC_EXPORT( void, aout_DateSet, ( audio_date_t *, mtime_t ) );
376 VLC_EXPORT( void, aout_DateMove, ( audio_date_t *, mtime_t ) );
377 VLC_EXPORT( mtime_t, aout_DateGet, ( const audio_date_t * ) LIBVLC_USED);
378 VLC_EXPORT( mtime_t, aout_DateIncrement, ( audio_date_t *, uint32_t ) );
379
380 VLC_EXPORT( aout_buffer_t *, aout_OutputNextBuffer, ( aout_instance_t *, mtime_t, bool ) LIBVLC_USED );
381
382 /**
383  * This function computes the reordering needed to go from pi_chan_order_in to
384  * pi_chan_order_out.
385  * If pi_chan_order_in or pi_chan_order_out is NULL, it will assume that vlc
386  * internal (WG4) order is requested.
387  */
388 VLC_EXPORT( int, aout_CheckChannelReorder, ( const uint32_t *pi_chan_order_in, const uint32_t *pi_chan_order_out, uint32_t i_channel_mask, int i_channels, int *pi_chan_table ) );
389 VLC_EXPORT( void, aout_ChannelReorder, ( uint8_t *, int, int, const int *, int ) );
390
391 VLC_EXPORT( unsigned int, aout_FormatNbChannels, ( const audio_sample_format_t * p_format ) LIBVLC_USED );
392 VLC_EXPORT( unsigned int, aout_BitsPerSample, ( vlc_fourcc_t i_format ) LIBVLC_USED );
393 VLC_EXPORT( void, aout_FormatPrepare, ( audio_sample_format_t * p_format ) );
394 VLC_EXPORT( void, aout_FormatPrint, ( aout_instance_t * p_aout, const char * psz_text, const audio_sample_format_t * p_format ) );
395 VLC_EXPORT( const char *, aout_FormatPrintChannels, ( const audio_sample_format_t * ) LIBVLC_USED );
396
397 VLC_EXPORT( mtime_t, aout_FifoFirstDate, ( aout_instance_t *, aout_fifo_t * ) LIBVLC_USED );
398 VLC_EXPORT( aout_buffer_t *, aout_FifoPop, ( aout_instance_t * p_aout, aout_fifo_t * p_fifo ) LIBVLC_USED );
399
400 /* From intf.c : */
401 VLC_EXPORT( void, aout_VolumeSoftInit, ( aout_instance_t * ) );
402 VLC_EXPORT( void, aout_VolumeNoneInit, ( aout_instance_t * ) );
403 #define aout_VolumeGet(a, b) __aout_VolumeGet(VLC_OBJECT(a), b)
404 VLC_EXPORT( int, __aout_VolumeGet, ( vlc_object_t *, audio_volume_t * ) );
405 #define aout_VolumeSet(a, b) __aout_VolumeSet(VLC_OBJECT(a), b)
406 VLC_EXPORT( int, __aout_VolumeSet, ( vlc_object_t *, audio_volume_t ) );
407 #define aout_VolumeInfos(a, b) __aout_VolumeInfos(VLC_OBJECT(a), b)
408 VLC_EXPORT( int, __aout_VolumeInfos, ( vlc_object_t *, audio_volume_t * ) );
409 #define aout_VolumeUp(a, b, c) __aout_VolumeUp(VLC_OBJECT(a), b, c)
410 VLC_EXPORT( int, __aout_VolumeUp, ( vlc_object_t *, int, audio_volume_t * ) );
411 #define aout_VolumeDown(a, b, c) __aout_VolumeDown(VLC_OBJECT(a), b, c)
412 VLC_EXPORT( int, __aout_VolumeDown, ( vlc_object_t *, int, audio_volume_t * ) );
413 #define aout_VolumeMute(a, b) __aout_VolumeMute(VLC_OBJECT(a), b)
414 VLC_EXPORT( int, __aout_VolumeMute, ( vlc_object_t *, audio_volume_t * ) );
415 VLC_EXPORT( int, aout_FindAndRestart, ( vlc_object_t *, const char *, vlc_value_t, vlc_value_t, void * ) );
416 VLC_EXPORT( int, aout_ChannelsRestart, ( vlc_object_t *, const char *, vlc_value_t, vlc_value_t, void * ) );
417
418 VLC_EXPORT( void, aout_EnableFilter, (vlc_object_t *, const char *, bool ));
419
420 #define aout_VisualNext(a) aout_VisualChange( VLC_OBJECT(a),1 )
421 #define aout_VisualPrev(a) aout_VisualChange( VLC_OBJECT(a),-1 )
422
423 VLC_EXPORT( char *, aout_VisualChange, (vlc_object_t *, int ) );
424
425 # ifdef __cplusplus
426 }
427 # endif
428
429 #endif /* _VLC_AOUT_H */