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