]> git.sesse.net Git - vlc/blob - include/vlc_aout.h
Remove object type field
[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       && AOUT_FMTS_SIMILAR(p_first, p_second) )
41
42 /* Check if i_rate == i_rate and i_channels == i_channels */
43 #define AOUT_FMTS_SIMILAR( p_first, p_second ) (                            \
44     ((p_first)->i_rate == (p_second)->i_rate)                               \
45       && ((p_first)->i_physical_channels == (p_second)->i_physical_channels)\
46       && ((p_first)->i_original_channels == (p_second)->i_original_channels) )
47
48 #define VLC_CODEC_SPDIFL VLC_FOURCC('s','p','d','i')
49 #define VLC_CODEC_SPDIFB VLC_FOURCC('s','p','d','b')
50
51 #define AOUT_FMT_NON_LINEAR( p_format )                 \
52     ( ((p_format)->i_format == VLC_CODEC_SPDIFL)       \
53        || ((p_format)->i_format == VLC_CODEC_SPDIFB)   \
54        || ((p_format)->i_format == VLC_CODEC_A52)       \
55        || ((p_format)->i_format == VLC_CODEC_DTS) )
56
57 /* This is heavily borrowed from libmad, by Robert Leslie <rob@mars.org> */
58 /*
59  * Fixed-point format: 0xABBBBBBB
60  * A == whole part      (sign + 3 bits)
61  * B == fractional part (28 bits)
62  *
63  * Values are signed two's complement, so the effective range is:
64  * 0x80000000 to 0x7fffffff
65  *       -8.0 to +7.9999999962747097015380859375
66  *
67  * The smallest representable value is:
68  * 0x00000001 == 0.0000000037252902984619140625 (i.e. about 3.725e-9)
69  *
70  * 28 bits of fractional accuracy represent about
71  * 8.6 digits of decimal accuracy.
72  *
73  * Fixed-point numbers can be added or subtracted as normal
74  * integers, but multiplication requires shifting the 64-bit result
75  * from 56 fractional bits back to 28 (and rounding.)
76  */
77 typedef int32_t vlc_fixed_t;
78 #define FIXED32_FRACBITS 28
79 #define FIXED32_MIN ((vlc_fixed_t) -0x80000000L)
80 #define FIXED32_MAX ((vlc_fixed_t) +0x7fffffffL)
81 #define FIXED32_ONE ((vlc_fixed_t) 0x10000000)
82
83 /*
84  * Channels descriptions
85  */
86
87 /* Values available for physical and original channels */
88 #define AOUT_CHAN_CENTER            0x1
89 #define AOUT_CHAN_LEFT              0x2
90 #define AOUT_CHAN_RIGHT             0x4
91 #define AOUT_CHAN_REARCENTER        0x10
92 #define AOUT_CHAN_REARLEFT          0x20
93 #define AOUT_CHAN_REARRIGHT         0x40
94 #define AOUT_CHAN_MIDDLELEFT        0x100
95 #define AOUT_CHAN_MIDDLERIGHT       0x200
96 #define AOUT_CHAN_LFE               0x1000
97
98 /* Values available for original channels only */
99 #define AOUT_CHAN_DOLBYSTEREO       0x10000
100 #define AOUT_CHAN_DUALMONO          0x20000
101 #define AOUT_CHAN_REVERSESTEREO     0x40000
102
103 #define AOUT_CHAN_PHYSMASK          0xFFFF
104 #define AOUT_CHAN_MAX               9
105
106 /* Values used for the audio-device and audio-channels object variables */
107 #define AOUT_VAR_MONO               1
108 #define AOUT_VAR_STEREO             2
109 #define AOUT_VAR_2F2R               4
110 #define AOUT_VAR_3F2R               5
111 #define AOUT_VAR_5_1                6
112 #define AOUT_VAR_6_1                7
113 #define AOUT_VAR_7_1                8
114 #define AOUT_VAR_SPDIF              10
115
116 #define AOUT_VAR_CHAN_STEREO        1
117 #define AOUT_VAR_CHAN_RSTEREO       2
118 #define AOUT_VAR_CHAN_LEFT          3
119 #define AOUT_VAR_CHAN_RIGHT         4
120 #define AOUT_VAR_CHAN_DOLBYS        5
121
122 /*****************************************************************************
123  * Main audio output structures
124  *****************************************************************************/
125
126 #define aout_BufferFree( buffer ) block_Release( buffer )
127
128 /* Size of a frame for S/PDIF output. */
129 #define AOUT_SPDIF_SIZE 6144
130
131 /* Number of samples in an A/52 frame. */
132 #define A52_FRAME_NB 1536
133
134 /* Max input rate factor (1/4 -> 4) */
135 #define AOUT_MAX_INPUT_RATE (4)
136
137 /** audio output buffer FIFO */
138 struct aout_fifo_t
139 {
140     aout_buffer_t *         p_first;
141     aout_buffer_t **        pp_last;
142     date_t                  end_date;
143 };
144
145 /* FIXME to remove once aout.h is cleaned a bit more */
146 #include <vlc_block.h>
147
148 #define AOUT_RESAMPLING_NONE     0
149 #define AOUT_RESAMPLING_UP       1
150 #define AOUT_RESAMPLING_DOWN     2
151
152 /** an output stream for the audio output */
153 typedef struct aout_output_t
154 {
155     audio_sample_format_t   output;
156     /* Indicates whether the audio output is currently starving, to avoid
157      * printing a 1,000 "output is starving" messages. */
158     bool              b_starving;
159
160     /* post-filters */
161     filter_t *              pp_filters[AOUT_MAX_FILTERS];
162     int                     i_nb_filters;
163
164     aout_fifo_t             fifo;
165
166     struct module_t *       p_module;
167     struct aout_sys_t *     p_sys;
168     void (*pf_play)( aout_instance_t * );
169     void (* pf_pause)( aout_instance_t *, bool, mtime_t );
170     int (* pf_volume_set )( aout_instance_t *, audio_volume_t, bool );
171     int                     i_nb_samples;
172 } aout_output_t;
173
174 struct aout_mixer_t;
175
176 /** audio output thread descriptor */
177 struct aout_instance_t
178 {
179     VLC_COMMON_MEMBERS
180
181     /* Lock for volume variables (FIXME: should be in input manager) */
182     vlc_mutex_t             volume_lock;
183     vlc_mutex_t             lock;
184
185     /* Input streams & pre-filters */
186     aout_input_t *          p_input;
187
188     /* Mixer */
189     audio_sample_format_t   mixer_format;
190     float                   mixer_multiplier;
191     struct aout_mixer_t    *p_mixer;
192
193     /* Output plug-in */
194     aout_output_t           output;
195 };
196
197 /**
198  * It describes the audio channel order VLC expect.
199  */
200 static const uint32_t pi_vlc_chan_order_wg4[] =
201 {
202     AOUT_CHAN_LEFT, AOUT_CHAN_RIGHT,
203     AOUT_CHAN_MIDDLELEFT, AOUT_CHAN_MIDDLERIGHT,
204     AOUT_CHAN_REARLEFT, AOUT_CHAN_REARRIGHT, AOUT_CHAN_REARCENTER,
205     AOUT_CHAN_CENTER, AOUT_CHAN_LFE, 0
206 };
207
208 /*****************************************************************************
209  * Prototypes
210  *****************************************************************************/
211
212 VLC_API aout_buffer_t * aout_OutputNextBuffer( aout_instance_t *, mtime_t, bool ) VLC_USED;
213
214 /**
215  * This function computes the reordering needed to go from pi_chan_order_in to
216  * pi_chan_order_out.
217  * If pi_chan_order_in or pi_chan_order_out is NULL, it will assume that vlc
218  * internal (WG4) order is requested.
219  */
220 VLC_API 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 );
221 VLC_API void aout_ChannelReorder( uint8_t *, int, int, const int *, int );
222
223 /**
224  * This fonction will compute the extraction parameter into pi_selection to go
225  * from i_channels with their type given by pi_order_src[] into the order
226  * describe by pi_order_dst.
227  * It will also set :
228  * - *pi_channels as the number of channels that will be extracted which is
229  * lower (in case of non understood channels type) or equal to i_channels.
230  * - the layout of the channels (*pi_layout).
231  *
232  * It will return true if channel extraction is really needed, in which case
233  * aout_ChannelExtract must be used
234  *
235  * XXX It must be used when the source may have channel type not understood
236  * by VLC. In this case the channel type pi_order_src[] must be set to 0.
237  * XXX It must also be used if multiple channels have the same type.
238  */
239 VLC_API bool aout_CheckChannelExtraction( int *pi_selection, uint32_t *pi_layout, int *pi_channels, const uint32_t pi_order_dst[AOUT_CHAN_MAX], const uint32_t *pi_order_src, int i_channels );
240
241 /**
242  * Do the actual channels extraction using the parameters created by
243  * aout_CheckChannelExtraction.
244  *
245  * XXX this function does not work in place (p_dst and p_src must not overlap).
246  * XXX Only 8, 16, 24, 32, 64 bits per sample are supported.
247  */
248 VLC_API void aout_ChannelExtract( void *p_dst, int i_dst_channels, const void *p_src, int i_src_channels, int i_sample_count, const int *pi_selection, int i_bits_per_sample );
249
250 /* */
251 static inline unsigned aout_FormatNbChannels(const audio_sample_format_t *fmt)
252 {
253     return popcount(fmt->i_physical_channels & AOUT_CHAN_PHYSMASK);
254 }
255
256 VLC_API unsigned int aout_BitsPerSample( vlc_fourcc_t i_format ) VLC_USED;
257 VLC_API void aout_FormatPrepare( audio_sample_format_t * p_format );
258 VLC_API void aout_FormatPrint( aout_instance_t * p_aout, const char * psz_text, const audio_sample_format_t * p_format );
259 VLC_API const char * aout_FormatPrintChannels( const audio_sample_format_t * ) VLC_USED;
260
261 VLC_API mtime_t aout_FifoFirstDate( const aout_fifo_t * ) VLC_USED;
262 VLC_API aout_buffer_t *aout_FifoPop( aout_fifo_t * p_fifo ) VLC_USED;
263
264 /* From intf.c : */
265 VLC_API void aout_VolumeSoftInit( aout_instance_t * );
266 VLC_API void aout_VolumeNoneInit( aout_instance_t * );
267 VLC_API audio_volume_t aout_VolumeGet( vlc_object_t * );
268 #define aout_VolumeGet(a) aout_VolumeGet(VLC_OBJECT(a))
269 VLC_API int aout_VolumeSet( vlc_object_t *, audio_volume_t );
270 #define aout_VolumeSet(a, b) aout_VolumeSet(VLC_OBJECT(a), b)
271 VLC_API int aout_VolumeUp( vlc_object_t *, int, audio_volume_t * );
272 #define aout_VolumeUp(a, b, c) aout_VolumeUp(VLC_OBJECT(a), b, c)
273 VLC_API int aout_VolumeDown( vlc_object_t *, int, audio_volume_t * );
274 #define aout_VolumeDown(a, b, c) aout_VolumeDown(VLC_OBJECT(a), b, c)
275 VLC_API int aout_ToggleMute( vlc_object_t *, audio_volume_t * );
276 #define aout_ToggleMute(a, b) aout_ToggleMute(VLC_OBJECT(a), b)
277 VLC_API int aout_SetMute( vlc_object_t *, audio_volume_t *, bool );
278 VLC_API bool aout_IsMuted( vlc_object_t * );
279 VLC_API int aout_ChannelsRestart( vlc_object_t *, const char *, vlc_value_t, vlc_value_t, void * );
280
281 VLC_API void aout_EnableFilter(vlc_object_t *, const char *, bool );
282 #define aout_EnableFilter( o, n, b ) \
283         aout_EnableFilter( VLC_OBJECT(o), n, b )
284
285 /* */
286 VLC_API vout_thread_t * aout_filter_RequestVout( filter_t *, vout_thread_t *p_vout, video_format_t *p_fmt ) VLC_USED;
287
288 # ifdef __cplusplus
289 }
290 # endif
291
292 #endif /* _VLC_AOUT_H */