]> git.sesse.net Git - vlc/blob - include/audio_output.h
beba49e0637a13e79039d66153870bfc583812d1
[vlc] / include / audio_output.h
1 /*****************************************************************************
2  * audio_output.h : audio output thread interface
3  *****************************************************************************
4  * Copyright (C) 1999, 2000 VideoLAN
5  * $Id: audio_output.h,v 1.46 2002/04/24 00:36:24 sam Exp $
6  *
7  * Authors: Michel Kaempf <maxx@via.ecp.fr>
8  *          Cyril Deguet <asmax@via.ecp.fr>
9  *
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.
14  * 
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.
19  *
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  *****************************************************************************/
24
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
31 {
32     /* Array to all the audio outputs */
33     struct aout_thread_s *pp_aout[ AOUT_MAX_THREADS ];
34
35     int                    i_count;
36     vlc_mutex_t            lock;  /* Global lock */
37
38 } aout_bank_t;
39
40 #ifndef __PLUGIN__
41 extern aout_bank_t *p_aout_bank;
42 #else
43 #   define p_aout_bank (p_symbols->p_aout_bank)
44 #endif
45
46 /*****************************************************************************
47  * aout_increment_t
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
54 {
55     /* The remainder is used to keep track of the fractional part of the
56      * index. */
57     int i_r;
58
59     /*
60      * The increment structure is initialized with the result of an euclidean
61      * division :
62      *
63      *  i_x           i_b
64      * ----- = i_a + -----
65      *  i_y           i_c
66      *
67      */
68     int i_a, i_b, i_c;
69
70 } aout_increment_t;
71
72 /*****************************************************************************
73  * aout_fifo_t
74  *****************************************************************************/
75 typedef struct aout_fifo_s
76 {
77     /* See the fifo formats below */
78     int                 i_format;
79     int                 i_channels;
80     int                 i_rate;
81     int                 i_frame_size;
82
83     boolean_t           b_die;
84     int                 i_fifo;      /* Just to keep track of the fifo index */
85
86     vlc_mutex_t         data_lock;
87     vlc_cond_t          data_wait;
88
89     u8 *                buffer;
90     mtime_t *           date;
91
92     /* The start frame is the first frame in the buffer that contains decoded
93      * audio data. It it also the first frame in the current timestamped frame
94      * area, ie the first dated frame in the decoded part of the buffer. :-p */
95     int                 i_start_frame;
96     boolean_t           b_start_frame;
97     /* The next frame is the end frame of the current timestamped frame area,
98      * ie the first dated frame after the start frame. */
99     int                 i_next_frame;
100     boolean_t           b_next_frame;
101     /* The end frame is the first frame, after the start frame, that doesn't
102      * contain decoded audio data. That's why the end frame is the first frame
103      * where the audio decoder can store its decoded audio frames. */
104     int                 i_end_frame;
105
106     /* Current index in p_aout->buffer */
107     int                 i_unit;
108     /* Max index in p_aout->buffer */
109     int                 i_unit_limit;
110     /* Structure used to calculate i_unit with a Bresenham algorithm */
111     aout_increment_t    unit_increment;
112
113     /* The following variable is used to store the number of remaining audio
114      * units in the current timestamped frame area. */
115     int                 i_units;
116
117 } aout_fifo_t;
118
119 #define AOUT_FIFO_ISEMPTY( fifo ) \
120   ( (fifo).i_end_frame == (fifo).i_start_frame )
121
122 #define AOUT_FIFO_ISFULL( fifo ) \
123   ( ((((fifo).i_end_frame + 1) - (fifo).i_start_frame) & AOUT_FIFO_SIZE) == 0 )
124
125 #define AOUT_FIFO_INC( i_index ) \
126   ( ((i_index) + 1) & AOUT_FIFO_SIZE )
127
128 /* List of known fifo formats */
129 #define AOUT_FIFO_NONE    0
130 #define AOUT_FIFO_PCM     1
131 #define AOUT_FIFO_SPDIF   2
132
133 /*****************************************************************************
134  * aout_thread_t : audio output thread descriptor
135  *****************************************************************************/
136 typedef struct aout_thread_s
137 {
138     vlc_thread_t        thread_id;
139     boolean_t           b_die;
140     boolean_t           b_active;
141
142     vlc_mutex_t         fifos_lock;
143     aout_fifo_t         fifo[ AOUT_MAX_FIFOS ];
144
145     /* Plugin used and shortcuts to access its capabilities */
146     struct module_s *   p_module;
147     int              ( *pf_open )       ( p_aout_thread_t );
148     int              ( *pf_setformat )  ( p_aout_thread_t );
149     int              ( *pf_getbufinfo ) ( p_aout_thread_t, int );
150     void             ( *pf_play )       ( p_aout_thread_t, byte_t *, int );
151     void             ( *pf_close )      ( p_aout_thread_t );
152
153     void *              buffer;
154     /* The s32 buffer is used to mix all the audio fifos together before
155      * converting them and storing them in the audio output buffer */
156     s32 *               s32_buffer;
157
158     /* The size of the audio output buffer is kept in audio units, as this is
159      * the only unit that is common with every audio decoder and audio fifo */
160     int                 i_units;
161
162     /* date is the moment where the first audio unit of the output buffer
163      * will be played */
164     mtime_t             date;
165
166     /* The current volume */
167     int                 i_volume;
168     int                 i_savedvolume;
169
170     /* Format of the audio output samples, number of channels, and
171      * rate and gain (in Hz) of the audio output sound */
172     int                 i_format;
173     int                 i_channels;
174     int                 i_rate;
175
176     /* Latency of the audio output plugin, in bytes */
177     int                 i_latency;
178
179     /* there might be some useful private structure, such as audio_buf_info
180      * for the OSS output */
181     p_aout_sys_t        p_sys;
182
183 } aout_thread_t;
184
185 /* Those are from <linux/soundcard.h> but are needed because of formats
186  * on other platforms */
187 #define AOUT_FMT_U8          0x00000008
188 #define AOUT_FMT_S16_LE      0x00000010           /* Little endian signed 16 */
189 #define AOUT_FMT_S16_BE      0x00000020              /* Big endian signed 16 */
190 #define AOUT_FMT_S8          0x00000040
191 #define AOUT_FMT_U16_LE      0x00000080                 /* Little endian U16 */
192 #define AOUT_FMT_U16_BE      0x00000100                    /* Big endian U16 */
193 #define AOUT_FMT_AC3         0x00000400                 /* Dolby Digital AC3 */
194
195 #ifdef WORDS_BIGENDIAN
196 #define AOUT_FMT_S16_NE      AOUT_FMT_S16_BE
197 #else
198 #define AOUT_FMT_S16_NE      AOUT_FMT_S16_LE
199 #endif
200
201 /* Number of samples in an AC3 frame */
202 #define AC3_FRAME_SIZE      1536
203
204 /* Size of a frame for spdif output */
205 #define SPDIF_FRAME_SIZE    6144
206
207 /*****************************************************************************
208  * Prototypes
209  *****************************************************************************/
210 #ifndef __PLUGIN__
211 void            aout_InitBank           ( void );
212 void            aout_EndBank            ( void );
213
214 aout_thread_t * aout_CreateThread       ( int *, int, int );
215 void            aout_DestroyThread      ( aout_thread_t *, int * );
216
217 aout_fifo_t *   aout_CreateFifo         ( int, int, int, int, void * );
218 void            aout_DestroyFifo        ( aout_fifo_t *p_fifo );
219 void            aout_FreeFifo           ( aout_fifo_t *p_fifo );
220 #else
221 #   define aout_CreateFifo p_symbols->aout_CreateFifo
222 #   define aout_DestroyFifo p_symbols->aout_DestroyFifo
223 #endif
224