1 /*****************************************************************************
2 * audio_output.h : audio output thread interface
3 *****************************************************************************
4 * Copyright (C) 1999, 2000 VideoLAN
5 * $Id: audio_output.h,v 1.42 2002/02/24 20:51:09 gbazin Exp $
7 * Authors: Michel Kaempf <maxx@via.ecp.fr>
8 * Cyril Deguet <asmax@via.ecp.fr>
10 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License as published by
12 * the Free Software Foundation; either version 2 of the License, or
13 * (at your option) any later version.
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
20 * You should have received a copy of the GNU General Public License
21 * along with this program; if not, write to the Free Software
22 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111, USA.
23 *****************************************************************************/
25 /*****************************************************************************
26 * aout_bank_t, p_aout_bank (global variable)
27 *****************************************************************************
28 * This global variable is accessed by any function using the audio output.
29 *****************************************************************************/
30 typedef struct aout_bank_s
32 /* Array to all the audio outputs */
33 struct aout_thread_s *pp_aout[ AOUT_MAX_THREADS ];
36 vlc_mutex_t lock; /* Global lock */
41 extern aout_bank_t *p_aout_bank;
43 # define p_aout_bank (p_symbols->p_aout_bank)
46 /*****************************************************************************
48 *****************************************************************************
49 * This structure is used to keep the progression of an index up-to-date, in
50 * order to avoid rounding problems and heavy computations, as the function
51 * that handles this structure only uses additions.
52 *****************************************************************************/
53 typedef struct aout_increment_s
55 /* The remainder is used to keep track of the fractional part of the
60 * The increment structure is initialized with the result of an euclidean
63 * l_euclidean_numerator l_euclidean_remainder
64 * ----------------------- = l_euclidean_integer + -----------------------
65 * l_euclidean_denominator l_euclidean_denominator
68 long l_euclidean_integer;
69 long l_euclidean_remainder;
70 long l_euclidean_denominator;
74 /*****************************************************************************
76 *****************************************************************************/
77 typedef struct aout_fifo_s
79 /* See the fifo types below */
82 int i_fifo; /* Just to keep track of the fifo index */
88 vlc_mutex_t data_lock;
94 /* The start frame is the first frame in the buffer that contains decoded
95 * audio data. It it also the first frame in the current timestamped frame
96 * area, ie the first dated frame in the decoded part of the buffer. :-p */
98 boolean_t b_start_frame;
99 /* The next frame is the end frame of the current timestamped frame area,
100 * ie the first dated frame after the start frame. */
102 boolean_t b_next_frame;
103 /* The end frame is the first frame, after the start frame, that doesn't
104 * contain decoded audio data. That's why the end frame is the first frame
105 * where the audio decoder can store its decoded audio frames. */
109 aout_increment_t unit_increment;
110 /* The following variable is used to store the number of remaining audio
111 * units in the current timestamped frame area. */
116 #define AOUT_FIFO_ISEMPTY( fifo ) \
117 ( (fifo).l_end_frame == (fifo).l_start_frame )
119 #define AOUT_FIFO_ISFULL( fifo ) \
120 ( ((((fifo).l_end_frame + 1) - (fifo).l_start_frame) & AOUT_FIFO_SIZE) == 0 )
122 #define AOUT_EMPTY_FIFO 0
123 #define AOUT_ADEC_MONO_FIFO 1
124 #define AOUT_ADEC_STEREO_FIFO 2
125 #define AOUT_ADEC_SPDIF_FIFO 3
127 /*****************************************************************************
128 * aout_thread_t : audio output thread descriptor
129 *****************************************************************************/
130 typedef struct aout_thread_s
132 vlc_thread_t thread_id;
136 vlc_mutex_t fifos_lock;
137 aout_fifo_t fifo[ AOUT_MAX_FIFOS ];
139 /* Plugin used and shortcuts to access its capabilities */
140 struct module_s * p_module;
141 int ( *pf_open ) ( p_aout_thread_t );
142 int ( *pf_setformat ) ( p_aout_thread_t );
143 long ( *pf_getbufinfo ) ( p_aout_thread_t, long );
144 void ( *pf_play ) ( p_aout_thread_t, byte_t *, int );
145 void ( *pf_close ) ( p_aout_thread_t );
148 /* The s32 buffer is used to mix all the audio fifos together before
149 * converting them and storing them in the audio output buffer */
152 /* The size of the audio output buffer is kept in audio units, as this is
153 * the only unit that is common with every audio decoder and audio fifo */
157 /* date is the moment where the first audio unit of the output buffer
161 /* The current volume */
164 /* Format of the audio output samples */
166 /* Number of channels */
168 /* Mono or Stereo sound */
170 /* Rate and gain of the audio output sound (in Hz) */
175 /* there might be some useful private structure, such as audio_buf_info
176 * for the OSS output */
181 /* Those are from <linux/soundcard.h> but are needed because of formats
182 * on other platforms */
183 #define AOUT_FMT_U8 0x00000008
184 #define AOUT_FMT_S16_LE 0x00000010 /* Little endian signed 16 */
185 #define AOUT_FMT_S16_BE 0x00000020 /* Big endian signed 16 */
186 #define AOUT_FMT_S8 0x00000040
187 #define AOUT_FMT_U16_LE 0x00000080 /* Little endian U16 */
188 #define AOUT_FMT_U16_BE 0x00000100 /* Big endian U16 */
189 #define AOUT_FMT_AC3 0x00000400 /* Dolby Digital AC3 */
191 #ifdef WORDS_BIGENDIAN
192 #define AOUT_FMT_S16_NE AOUT_FMT_S16_BE
194 #define AOUT_FMT_S16_NE AOUT_FMT_S16_LE
197 /* Number of samples in an AC3 frame */
198 #define AC3_FRAME_SIZE 1536
200 /* Size of a frame for spdif output */
201 #define SPDIF_FRAME_SIZE 6144
203 /*****************************************************************************
205 *****************************************************************************/
207 void aout_InitBank ( void );
208 void aout_EndBank ( void );
210 aout_thread_t * aout_CreateThread ( int *pi_status, int i_channels,
212 void aout_DestroyThread ( aout_thread_t *, int * );
214 aout_fifo_t * aout_CreateFifo ( int, int, long, long, long, void * );
215 void aout_DestroyFifo ( aout_fifo_t *p_fifo );
216 void aout_FreeFifo ( aout_fifo_t *p_fifo );
218 # define aout_CreateFifo p_symbols->aout_CreateFifo
219 # define aout_DestroyFifo p_symbols->aout_DestroyFifo