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