]> git.sesse.net Git - vlc/blob - include/audio_output.h
Encapsulation des pthread qui sont maintenant remplac�es par les vlc_thread.
[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 (AFMT_S16_NE = Native Endianess) */
29 #define AOUT_DEFAULT_FORMAT     AFMT_S16_NE
30
31 /* Default stereo mode (0 stands for mono, 1 for stereo) */
32 #define AOUT_DEFAULT_STEREO     1
33
34 /* Audio output rate, in Hz */
35 #define AOUT_MIN_RATE           22050 /* ?? */
36 #define AOUT_DEFAULT_RATE       44100
37 #define AOUT_MAX_RATE           48000
38
39 /* Number of audio samples (s16 integers) contained in an audio output frame...
40  * - Layer I        : a decoded frame contains 384 samples
41  * - Layer II & III : a decoded frame contains 1152 = 3*384 samples */
42 #define AOUT_FRAME_SIZE         384
43
44 /* Number of audio output frames contained in an audio output fifo.
45  * (AOUT_FIFO_SIZE + 1) must be a power of 2, in order to optimise the
46  * %(AOUT_FIFO_SIZE + 1) operation with an &AOUT_FIFO_SIZE.
47  * With 511 we have at least 511*384/2/48000=2 seconds of sound */
48 #define AOUT_FIFO_SIZE          511
49
50 /* Maximum number of audio fifos. The value of AOUT_MAX_FIFOS should be a power
51  * of two, in order to optimize the '/AOUT_MAX_FIFOS' and '*AOUT_MAX_FIFOS'
52  * operations with '>>' and '<<' (gcc changes this at compilation-time) */
53 #define AOUT_MAX_FIFOS          2
54
55 /* Duration (in microseconds) of an audio output buffer should be :
56  * - short, in order to be able to play a new song very quickly (especially a
57  *   song from the interface)
58  * - long, in order to perform the buffer calculations as few as possible */
59 #define AOUT_BUFFER_DURATION    100000
60
61 /*
62  * Macros
63  */
64 #define AOUT_FIFO_ISEMPTY( fifo )       ( (fifo).l_end_frame == (fifo).i_start_frame )
65 #define AOUT_FIFO_ISFULL( fifo )        ( ((((fifo).l_end_frame + 1) - (fifo).l_start_frame) & AOUT_FIFO_SIZE) == 0 )
66
67 /******************************************************************************
68  * aout_dsp_t
69  ******************************************************************************/
70 typedef struct
71 {
72     /* Path to the audio output device (default is set to "/dev/dsp") */
73     char *              psz_device;
74     int                 i_fd;
75
76     /* Format of the audio output samples (see <sys/soundcard.h>) */
77     int                 i_format;
78     /* Following boolean is set to 0 if output sound is mono, 1 if stereo */
79     boolean_t           b_stereo;
80     /* Rate of the audio output sound (in Hz) */
81     long                l_rate;
82
83     /* Buffer information structure, used by aout_dspGetBufInfo() to store the
84      * current state of the internal sound card buffer */
85     audio_buf_info      buf_info;
86
87 } aout_dsp_t;
88
89 /******************************************************************************
90  * aout_increment_t
91  ******************************************************************************
92  * This structure is used to keep the progression of an index up-to-date, in
93  * order to avoid rounding problems and heavy computations, as the function
94  * that handles this structure only uses additions.
95  ******************************************************************************/
96 typedef struct
97 {
98     /* The remainder is used to keep track of the fractional part of the
99      * index. */
100     long                l_remainder;
101
102     /*
103      * The increment structure is initialized with the result of an euclidean
104      * division :
105      *
106      *  l_euclidean_numerator                           l_euclidean_remainder
107      * ----------------------- = l_euclidean_integer + -----------------------
108      * l_euclidean_denominator                         l_euclidean_denominator
109      *
110      */
111     long                l_euclidean_integer;
112     long                l_euclidean_remainder;
113     long                l_euclidean_denominator;
114
115 } aout_increment_t;
116
117 /******************************************************************************
118  * aout_frame_t
119  ******************************************************************************/
120 typedef s16 aout_frame_t[ AOUT_FRAME_SIZE ];
121
122 /******************************************************************************
123  * aout_fifo_t
124  ******************************************************************************/
125 typedef struct
126 {
127     /* See the fifo types below */
128     int                 i_type;
129     boolean_t           b_die;
130
131     boolean_t           b_stereo;
132     long                l_rate;
133
134     vlc_mutex_t         data_lock;
135     vlc_cond_t          data_wait;
136
137     void *              buffer;
138     mtime_t *           date;
139     /* The start frame is the first frame in the buffer that contains decoded
140      * audio data. It it also the first frame in the current timestamped frame
141      * area, ie the first dated frame in the decoded part of the buffer. :-p */
142     long                l_start_frame;
143     boolean_t           b_start_frame;
144     /* The next frame is the end frame of the current timestamped frame area,
145      * ie the first dated frame after the start frame. */
146     long                l_next_frame;
147     boolean_t           b_next_frame;
148     /* The end frame is the first frame, after the start frame, that doesn't
149      * contain decoded audio data. That's why the end frame is the first frame
150      * where the audio decoder can store its decoded audio frames. */
151     long                l_end_frame;
152
153     long                l_unit;
154     aout_increment_t    unit_increment;
155     /* The following variable is used to store the number of remaining audio
156      * units in the current timestamped frame area. */
157     long                l_units;
158
159 } aout_fifo_t;
160
161 #define AOUT_EMPTY_FIFO         0
162 #define AOUT_INTF_MONO_FIFO     1
163 #define AOUT_INTF_STEREO_FIFO   2
164 #define AOUT_ADEC_MONO_FIFO     3
165 #define AOUT_ADEC_STEREO_FIFO   4
166
167 /******************************************************************************
168  * aout_thread_t
169  ******************************************************************************/
170 typedef struct aout_thread_s
171 {
172     vlc_thread_t        thread_id;
173     boolean_t           b_die;
174
175     aout_dsp_t          dsp;
176
177     vlc_mutex_t         fifos_lock;
178     aout_fifo_t         fifo[ AOUT_MAX_FIFOS ];
179
180     void *              buffer;
181     /* The s32 buffer is used to mix all the audio fifos together before
182      * converting them and storing them in the audio output buffer */
183     s32 *               s32_buffer;
184
185     /* The size of the audio output buffer is kept in audio units, as this is
186      * the only unit that is common with every audio decoder and audio fifo */
187     long                l_units;
188
189     mtime_t             date;
190     /* date is the moment where the first audio unit of the output buffer
191      * should be played and is kept up-to-date with the following incremental
192      * structure */
193     aout_increment_t    date_increment;
194
195 } aout_thread_t;
196
197 /******************************************************************************
198  * Prototypes
199  ******************************************************************************/
200 int             aout_Open               ( aout_thread_t *p_aout );
201 int             aout_SpawnThread        ( aout_thread_t *p_aout );
202 void            aout_CancelThread       ( aout_thread_t *p_aout );
203 void            aout_Close              ( aout_thread_t *p_aout );
204
205 aout_fifo_t *   aout_CreateFifo         ( aout_thread_t *p_aout, aout_fifo_t *p_fifo );
206 void            aout_DestroyFifo        ( aout_fifo_t *p_fifo );