]> git.sesse.net Git - vlc/blob - include/audio_output.h
Bon. On ne rit pas, je m'�tais juste plant� dans l'en-t�te des
[vlc] / include / audio_output.h
1 /*****************************************************************************
2  * audio_output.h : audio output thread interface
3  *****************************************************************************
4  * Copyright (C) 1999, 2000 VideoLAN
5  *
6  * Authors:
7  *
8  * This program is free software; you can redistribute it and/or modify
9  * it under the terms of the GNU General Public License as published by
10  * the Free Software Foundation; either version 2 of the License, or
11  * (at your option) any later version.
12  * 
13  * This program is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16  * GNU General Public License for more details.
17  *
18  * You should have received a copy of the GNU General Public License
19  * along with this program; if not, write to the Free Software
20  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111, USA.
21  *****************************************************************************/
22
23 /*****************************************************************************
24  * Required headers:
25  * - "common.h"                                                   ( boolean_t )
26  * - "mtime.h"                                                      ( mtime_t )
27  * - "threads.h"                                               ( vlc_thread_t )
28  *****************************************************************************/
29
30 /* TODO :
31  *
32  * - Créer un flag destroy dans les fifos audio pour indiquer au thread audio
33  *   qu'il peut libérer la mémoire occupée par le buffer de la fifo lorsqu'il
34  *   le désire (fin du son ou fin du thread)
35  * - Redéplacer les #define dans config.h
36  *
37  */
38
39 /*
40  * Defines => "config.h"
41  */
42
43 /* Default output device. You probably should not change this. */
44 #define AOUT_DEFAULT_DEVICE     "/dev/dsp"
45
46 /* Default audio output format (AOUT_FMT_S16_NE = Native Endianess) */
47 #define AOUT_DEFAULT_FORMAT     AOUT_FMT_S16_NE
48
49 /* #define AOUT_DEFAULT_FORMAT     AOUT_FMT_S8 */
50 /* #define AOUT_DEFAULT_FORMAT     AOUT_FMT_U8 */
51 /* #define AOUT_DEFAULT_FORMAT     AOUT_FMT_S16_BE */
52 /* #define AOUT_DEFAULT_FORMAT     AOUT_FMT_S16_LE */
53 /* #define AOUT_DEFAULT_FORMAT     AOUT_FMT_U16_BE */
54 /* #define AOUT_DEFAULT_FORMAT     AOUT_FMT_U16_LE */
55
56
57 /* Default stereo mode (0 stands for mono, 1 for stereo) */
58 #define AOUT_DEFAULT_STEREO     1
59 /* #define AOUT_DEFAULT_STEREO     0 */
60
61 /* Audio output rate, in Hz */
62 #define AOUT_MIN_RATE           22050 /* XXX?? */
63 #define AOUT_DEFAULT_RATE       44100
64 #define AOUT_MAX_RATE           48000
65
66
67 /* Volume (default 100) */
68 #define VOL 100
69 #define VOLSTEP 5
70 #define VOLMAX 300
71
72 /* Number of audio output frames contained in an audio output fifo.
73  * (AOUT_FIFO_SIZE + 1) must be a power of 2, in order to optimise the
74  * %(AOUT_FIFO_SIZE + 1) operation with an &AOUT_FIFO_SIZE.
75  * With 511 we have at least 511*384/2/48000=2 seconds of sound */
76 #define AOUT_FIFO_SIZE          511
77
78 /* Maximum number of audio fifos. The value of AOUT_MAX_FIFOS should be a power
79  * of two, in order to optimize the '/AOUT_MAX_FIFOS' and '*AOUT_MAX_FIFOS'
80  * operations with '>>' and '<<' (gcc changes this at compilation-time) */
81 #define AOUT_MAX_FIFOS          2
82
83 /* Duration (in microseconds) of an audio output buffer should be :
84  * - short, in order to be able to play a new song very quickly (especially a
85  *   song from the interface)
86  * - long, in order to perform the buffer calculations as few as possible */
87 #define AOUT_BUFFER_DURATION    100000
88
89 /*
90  * Macros
91  */
92 #define AOUT_FIFO_ISEMPTY( fifo )       ( (fifo).l_end_frame == (fifo).i_start_frame )
93 #define AOUT_FIFO_ISFULL( fifo )        ( ((((fifo).l_end_frame + 1) - (fifo).l_start_frame) & AOUT_FIFO_SIZE) == 0 )
94
95 /*****************************************************************************
96  * aout_increment_t
97  *****************************************************************************
98  * This structure is used to keep the progression of an index up-to-date, in
99  * order to avoid rounding problems and heavy computations, as the function
100  * that handles this structure only uses additions.
101  *****************************************************************************/
102 typedef struct
103 {
104     /* The remainder is used to keep track of the fractional part of the
105      * index. */
106     long                l_remainder;
107
108     /*
109      * The increment structure is initialized with the result of an euclidean
110      * division :
111      *
112      *  l_euclidean_numerator                           l_euclidean_remainder
113      * ----------------------- = l_euclidean_integer + -----------------------
114      * l_euclidean_denominator                         l_euclidean_denominator
115      *
116      */
117     long                l_euclidean_integer;
118     long                l_euclidean_remainder;
119     long                l_euclidean_denominator;
120
121 } aout_increment_t;
122
123 /*****************************************************************************
124  * aout_fifo_t
125  *****************************************************************************/
126 typedef struct
127 {
128     /* See the fifo types below */
129     int                 i_type;
130     boolean_t           b_die;
131
132     int                 i_channels;
133     boolean_t           b_stereo;
134     long                l_rate;
135
136     vlc_mutex_t         data_lock;
137     vlc_cond_t          data_wait;
138
139     long                l_frame_size;
140     void *              buffer;
141     mtime_t *           date;
142     /* The start frame is the first frame in the buffer that contains decoded
143      * audio data. It it also the first frame in the current timestamped frame
144      * area, ie the first dated frame in the decoded part of the buffer. :-p */
145     long                l_start_frame;
146     boolean_t           b_start_frame;
147     /* The next frame is the end frame of the current timestamped frame area,
148      * ie the first dated frame after the start frame. */
149     long                l_next_frame;
150     boolean_t           b_next_frame;
151     /* The end frame is the first frame, after the start frame, that doesn't
152      * contain decoded audio data. That's why the end frame is the first frame
153      * where the audio decoder can store its decoded audio frames. */
154     long                l_end_frame;
155
156     long                l_unit;
157     aout_increment_t    unit_increment;
158     /* The following variable is used to store the number of remaining audio
159      * units in the current timestamped frame area. */
160     long                l_units;
161
162 } aout_fifo_t;
163
164 #define AOUT_EMPTY_FIFO         0
165 #define AOUT_INTF_MONO_FIFO     1
166 #define AOUT_INTF_STEREO_FIFO   2
167 #define AOUT_ADEC_MONO_FIFO     3
168 #define AOUT_ADEC_STEREO_FIFO   4
169
170 /*****************************************************************************
171  * aout_thread_t : audio output thread descriptor
172  *****************************************************************************/
173 typedef int  (aout_sys_open_t)           ( p_aout_thread_t p_aout );
174 typedef int  (aout_sys_reset_t)          ( p_aout_thread_t p_aout );
175 typedef int  (aout_sys_setformat_t)      ( p_aout_thread_t p_aout );
176 typedef int  (aout_sys_setchannels_t)    ( p_aout_thread_t p_aout );
177 typedef int  (aout_sys_setrate_t)        ( p_aout_thread_t p_aout );
178 typedef long (aout_sys_getbufinfo_t)     ( p_aout_thread_t p_aout,
179                                            long l_buffer_limit );
180 typedef void (aout_sys_playsamples_t)    ( p_aout_thread_t p_aout,
181                                            byte_t *buffer, int i_size );
182 typedef void (aout_sys_close_t)          ( p_aout_thread_t p_aout );
183
184 typedef struct aout_thread_s
185 {
186     vlc_thread_t        thread_id;
187     boolean_t           b_die;
188     boolean_t           b_active;
189
190     vlc_mutex_t         fifos_lock;
191     aout_fifo_t         fifo[ AOUT_MAX_FIFOS ];
192
193     /* Plugins */
194     plugin_id_t                 aout_plugin;          /* video output plugin */
195     aout_sys_open_t *           p_sys_open;
196     aout_sys_reset_t *          p_sys_reset;
197     aout_sys_setformat_t *      p_sys_setformat;
198     aout_sys_setchannels_t *    p_sys_setchannels;
199     aout_sys_setrate_t *        p_sys_setrate;
200     aout_sys_getbufinfo_t *     p_sys_getbufinfo;
201     aout_sys_playsamples_t *    p_sys_playsamples;
202     aout_sys_close_t *          p_sys_close;
203
204     void *              buffer;
205     /* The s32 buffer is used to mix all the audio fifos together before
206      * converting them and storing them in the audio output buffer */
207     s32 *               s32_buffer;
208
209     /* The size of the audio output buffer is kept in audio units, as this is
210      * the only unit that is common with every audio decoder and audio fifo */
211     long                l_units;
212     long                l_msleep;
213
214     /* date is the moment where the first audio unit of the output buffer
215      * will be played */
216     mtime_t             date;
217
218     /* Path to the audio output device (default is set to "/dev/dsp") */
219     char *              psz_device;
220     int                 i_fd;
221
222     /* Format of the audio output samples */
223     int                 i_format;
224     /* Number of channels */
225     int                 i_channels;
226     /* Mono or Stereo sound */
227     boolean_t           b_stereo;
228     /* Rate and gain of the audio output sound (in Hz) */
229     long                l_rate;
230     long                l_gain;
231
232     /* there might be some useful private structure, such as audio_buf_info
233      * for the OSS output */
234     p_aout_sys_t        p_sys;
235
236
237     /* there is the current volume */
238     int                 vol;
239
240 } aout_thread_t;
241
242 /* Those are from <linux/soundcard.h> but are needed because of formats
243  * on other platforms */
244 #define AOUT_FMT_U8          0x00000008
245 #define AOUT_FMT_S16_LE      0x00000010           /* Little endian signed 16 */
246 #define AOUT_FMT_S16_BE      0x00000020              /* Big endian signed 16 */
247 #define AOUT_FMT_S8          0x00000040
248 #define AOUT_FMT_U16_LE      0x00000080                 /* Little endian U16 */
249 #define AOUT_FMT_U16_BE      0x00000100                    /* Big endian U16 */
250
251 #if __BYTE_ORDER == __LITTLE_ENDIAN
252 #define AOUT_FMT_S16_NE      AOUT_FMT_S16_LE
253 #elif __BYTE_ORDER == __BIG_ENDIAN
254 #define AOUT_FMT_S16_NE      AOUT_FMT_S16_BE
255 #endif
256
257 /*****************************************************************************
258  * Prototypes
259  *****************************************************************************/
260 aout_thread_t * aout_CreateThread       ( int *pi_status );
261 void            aout_DestroyThread      ( aout_thread_t *p_aout, int *pi_status );
262
263
264 aout_fifo_t *   aout_CreateFifo         ( aout_thread_t *p_aout, aout_fifo_t *p_fifo );
265 void            aout_DestroyFifo        ( aout_fifo_t *p_fifo );