1 /*****************************************************************************
2 * audio_output.h : audio output thread interface
3 *****************************************************************************
4 * Copyright (C) 1999, 2000 VideoLAN
5 * $Id: audio_output.h,v 1.49 2002/07/20 18:01:41 sam 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 /*****************************************************************************
27 *****************************************************************************
28 * This structure is used to keep the progression of an index up-to-date, in
29 * order to avoid rounding problems and heavy computations, as the function
30 * that handles this structure only uses additions.
31 *****************************************************************************/
32 typedef struct aout_increment_t
34 /* The remainder is used to keep track of the fractional part of the
39 * The increment structure is initialized with the result of an euclidean
51 /*****************************************************************************
53 *****************************************************************************/
56 /* See the fifo formats below */
63 int i_fifo; /* Just to keep track of the fifo index */
65 vlc_mutex_t data_lock;
71 /* The start frame is the first frame in the buffer that contains decoded
72 * audio data. It it also the first frame in the current timestamped frame
73 * area, ie the first dated frame in the decoded part of the buffer. :-p */
75 vlc_bool_t b_start_frame;
76 /* The next frame is the end frame of the current timestamped frame area,
77 * ie the first dated frame after the start frame. */
79 vlc_bool_t b_next_frame;
80 /* The end frame is the first frame, after the start frame, that doesn't
81 * contain decoded audio data. That's why the end frame is the first frame
82 * where the audio decoder can store its decoded audio frames. */
85 /* Current index in p_aout->buffer */
87 /* Max index in p_aout->buffer */
89 /* Structure used to calculate i_unit with a Bresenham algorithm */
90 aout_increment_t unit_increment;
92 /* The following variable is used to store the number of remaining audio
93 * units in the current timestamped frame area. */
97 #define AOUT_FIFO_ISEMPTY( fifo ) \
98 ( (fifo).i_end_frame == (fifo).i_start_frame )
100 #define AOUT_FIFO_ISFULL( fifo ) \
101 ( ((((fifo).i_end_frame + 1) - (fifo).i_start_frame) & AOUT_FIFO_SIZE) == 0 )
103 #define AOUT_FIFO_INC( i_index ) \
104 ( ((i_index) + 1) & AOUT_FIFO_SIZE )
106 /* List of known fifo formats */
107 #define AOUT_FIFO_NONE 0
108 #define AOUT_FIFO_PCM 1
109 #define AOUT_FIFO_SPDIF 2
111 /*****************************************************************************
112 * aout_thread_t : audio output thread descriptor
113 *****************************************************************************/
118 vlc_mutex_t fifos_lock;
119 aout_fifo_t fifo[ AOUT_MAX_FIFOS ];
121 /* Plugin used and shortcuts to access its capabilities */
123 int ( *pf_open ) ( aout_thread_t * );
124 int ( *pf_setformat ) ( aout_thread_t * );
125 int ( *pf_getbufinfo ) ( aout_thread_t * , int );
126 void ( *pf_play ) ( aout_thread_t * , byte_t *, int );
127 void ( *pf_close ) ( aout_thread_t * );
130 /* The s32 buffer is used to mix all the audio fifos together before
131 * converting them and storing them in the audio output buffer */
134 /* The size of the audio output buffer is kept in audio units, as this is
135 * the only unit that is common with every audio decoder and audio fifo */
138 /* date is the moment where the first audio unit of the output buffer
142 /* The current volume */
146 /* Format of the audio output samples, number of channels, and
147 * rate and gain (in Hz) of the audio output sound */
152 /* Latency of the audio output plugin, in bytes */
155 /* there might be some useful private structure, such as audio_buf_info
156 * for the OSS output */
160 /* Those are from <linux/soundcard.h> but are needed because of formats
161 * on other platforms */
162 #define AOUT_FMT_U8 0x00000008
163 #define AOUT_FMT_S16_LE 0x00000010 /* Little endian signed 16 */
164 #define AOUT_FMT_S16_BE 0x00000020 /* Big endian signed 16 */
165 #define AOUT_FMT_S8 0x00000040
166 #define AOUT_FMT_U16_LE 0x00000080 /* Little endian U16 */
167 #define AOUT_FMT_U16_BE 0x00000100 /* Big endian U16 */
168 #define AOUT_FMT_AC3 0x00000400 /* Dolby Digital AC3 */
170 #ifdef WORDS_BIGENDIAN
171 #define AOUT_FMT_S16_NE AOUT_FMT_S16_BE
173 #define AOUT_FMT_S16_NE AOUT_FMT_S16_LE
176 /* Number of samples in an AC3 frame */
177 #define AC3_FRAME_SIZE 1536
179 /* Size of a frame for spdif output */
180 #define SPDIF_FRAME_SIZE 6144
182 /*****************************************************************************
184 *****************************************************************************/
185 aout_thread_t * aout_CreateThread ( vlc_object_t *, int, int );
186 void aout_DestroyThread ( aout_thread_t * );
188 #define aout_CreateFifo(a,b,c,d,e,f) __aout_CreateFifo(CAST_TO_VLC_OBJECT(a),b,c,d,e,f)
189 VLC_EXPORT( aout_fifo_t *, __aout_CreateFifo, ( vlc_object_t *, int, int, int, int, void * ) );
190 VLC_EXPORT( void, aout_DestroyFifo, ( aout_fifo_t *p_fifo ) );
191 void aout_FreeFifo ( aout_fifo_t *p_fifo );