1 /******************************************************************************
2 * audio_output.h : audio output thread interface
4 ******************************************************************************
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 ******************************************************************************/
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
22 * Defines => "config.h"
25 /* Default output device. You probably should not change this. */
26 #define AOUT_DEFAULT_DEVICE "/dev/dsp"
28 /* Default audio output format (AFMT_S16_NE = Native Endianess) */
29 #define AOUT_DEFAULT_FORMAT AFMT_S16_NE
31 /* Default stereo mode (0 stands for mono, 1 for stereo) */
32 #define AOUT_DEFAULT_STEREO 1
34 /* Audio output rate, in Hz */
35 #define AOUT_MIN_RATE 22050 /* ?? */
36 #define AOUT_DEFAULT_RATE 44100
37 #define AOUT_MAX_RATE 48000
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 */
43 #define AOUT_FRAME_SIZE 384
46 /* Number of audio output frames contained in an audio output fifo.
47 * (AOUT_FIFO_SIZE + 1) must be a power of 2, in order to optimise the
48 * %(AOUT_FIFO_SIZE + 1) operation with an &AOUT_FIFO_SIZE.
49 * With 511 we have at least 511*384/2/48000=2 seconds of sound */
50 #define AOUT_FIFO_SIZE 511
52 /* Maximum number of audio fifos. The value of AOUT_MAX_FIFOS should be a power
53 * of two, in order to optimize the '/AOUT_MAX_FIFOS' and '*AOUT_MAX_FIFOS'
54 * operations with '>>' and '<<' (gcc changes this at compilation-time) */
55 #define AOUT_MAX_FIFOS 2
57 /* Duration (in microseconds) of an audio output buffer should be :
58 * - short, in order to be able to play a new song very quickly (especially a
59 * song from the interface)
60 * - long, in order to perform the buffer calculations as few as possible */
61 #define AOUT_BUFFER_DURATION 100000
66 #define AOUT_FIFO_ISEMPTY( fifo ) ( (fifo).l_end_frame == (fifo).i_start_frame )
67 #define AOUT_FIFO_ISFULL( fifo ) ( ((((fifo).l_end_frame + 1) - (fifo).l_start_frame) & AOUT_FIFO_SIZE) == 0 )
69 /******************************************************************************
71 ******************************************************************************/
74 /* Path to the audio output device (default is set to "/dev/dsp") */
78 /* Format of the audio output samples (see <sys/soundcard.h>) */
80 /* Following boolean is set to 0 if output sound is mono, 1 if stereo */
82 /* Rate of the audio output sound (in Hz) */
85 /* Buffer information structure, used by aout_dspGetBufInfo() to store the
86 * current state of the internal sound card buffer */
87 audio_buf_info buf_info;
91 /******************************************************************************
93 ******************************************************************************
94 * This structure is used to keep the progression of an index up-to-date, in
95 * order to avoid rounding problems and heavy computations, as the function
96 * that handles this structure only uses additions.
97 ******************************************************************************/
100 /* The remainder is used to keep track of the fractional part of the
105 * The increment structure is initialized with the result of an euclidean
108 * l_euclidean_numerator l_euclidean_remainder
109 * ----------------------- = l_euclidean_integer + -----------------------
110 * l_euclidean_denominator l_euclidean_denominator
113 long l_euclidean_integer;
114 long l_euclidean_remainder;
115 long l_euclidean_denominator;
119 /******************************************************************************
121 ******************************************************************************/
122 /*typedef s16 aout_frame_t[ AOUT_FRAME_SIZE ];*/
124 /******************************************************************************
126 ******************************************************************************/
129 /* See the fifo types below */
136 vlc_mutex_t data_lock;
137 vlc_cond_t data_wait;
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 */
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. */
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. */
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. */
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
170 /******************************************************************************
172 ******************************************************************************/
173 typedef struct aout_thread_s
175 vlc_thread_t thread_id;
180 vlc_mutex_t fifos_lock;
181 aout_fifo_t fifo[ AOUT_MAX_FIFOS ];
184 /* The s32 buffer is used to mix all the audio fifos together before
185 * converting them and storing them in the audio output buffer */
188 /* The size of the audio output buffer is kept in audio units, as this is
189 * the only unit that is common with every audio decoder and audio fifo */
193 /* date is the moment where the first audio unit of the output buffer
194 * should be played and is kept up-to-date with the following incremental
196 aout_increment_t date_increment;
200 /******************************************************************************
202 ******************************************************************************/
203 aout_thread_t * aout_CreateThread ( int *pi_status );
204 void aout_DestroyThread ( aout_thread_t *p_aout, int *pi_status );
207 aout_fifo_t * aout_CreateFifo ( aout_thread_t *p_aout, aout_fifo_t *p_fifo );
208 void aout_DestroyFifo ( aout_fifo_t *p_fifo );