]> git.sesse.net Git - vlc/blob - include/audio_output.h
449a9921ef6ad5323f79f289478d0185a4d49169
[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.36 2001/05/30 05:19:03 stef Exp $
6  *
7  * Authors: Michel Kaempf <maxx@via.ecp.fr>
8  *
9  * This program is free software; you can redistribute it and/or modify
10  * it under the terms of the GNU General Public License as published by
11  * the Free Software Foundation; either version 2 of the License, or
12  * (at your option) any later version.
13  * 
14  * This program is distributed in the hope that it will be useful,
15  * but WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17  * GNU General Public License for more details.
18  *
19  * You should have received a copy of the GNU General Public License
20  * along with this program; if not, write to the Free Software
21  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111, USA.
22  *****************************************************************************/
23
24 /*****************************************************************************
25  * aout_bank_t, p_aout_bank (global variable)
26  *****************************************************************************
27  * This global variable is accessed by any function using the audio output.
28  *****************************************************************************/
29 typedef struct
30 {
31     /* Array to all the audio outputs */
32     struct aout_thread_s *pp_aout[ AOUT_MAX_THREADS ];
33
34     int                    i_count;
35     vlc_mutex_t            lock;  /* Global lock */
36
37 } aout_bank_t;
38
39 extern aout_bank_t *p_aout_bank;
40
41 /*****************************************************************************
42  * aout_increment_t
43  *****************************************************************************
44  * This structure is used to keep the progression of an index up-to-date, in
45  * order to avoid rounding problems and heavy computations, as the function
46  * that handles this structure only uses additions.
47  *****************************************************************************/
48 typedef struct aout_increment_s
49 {
50     /* The remainder is used to keep track of the fractional part of the
51      * index. */
52     long                l_remainder;
53
54     /*
55      * The increment structure is initialized with the result of an euclidean
56      * division :
57      *
58      *  l_euclidean_numerator                           l_euclidean_remainder
59      * ----------------------- = l_euclidean_integer + -----------------------
60      * l_euclidean_denominator                         l_euclidean_denominator
61      *
62      */
63     long                l_euclidean_integer;
64     long                l_euclidean_remainder;
65     long                l_euclidean_denominator;
66
67 } aout_increment_t;
68
69 /*****************************************************************************
70  * aout_fifo_t
71  *****************************************************************************/
72 typedef struct aout_fifo_s
73 {
74     /* See the fifo types below */
75     int                 i_type;
76     boolean_t           b_die;
77     int                 i_fifo;      /* Just to keep track of the fifo index */
78
79     int                 i_channels;
80     boolean_t           b_stereo;
81     long                l_rate;
82
83     vlc_mutex_t         data_lock;
84     vlc_cond_t          data_wait;
85
86     long                l_frame_size;
87     void *              buffer;
88     mtime_t *           date;
89     /* The start frame is the first frame in the buffer that contains decoded
90      * audio data. It it also the first frame in the current timestamped frame
91      * area, ie the first dated frame in the decoded part of the buffer. :-p */
92     long                l_start_frame;
93     boolean_t           b_start_frame;
94     /* The next frame is the end frame of the current timestamped frame area,
95      * ie the first dated frame after the start frame. */
96     long                l_next_frame;
97     boolean_t           b_next_frame;
98     /* The end frame is the first frame, after the start frame, that doesn't
99      * contain decoded audio data. That's why the end frame is the first frame
100      * where the audio decoder can store its decoded audio frames. */
101     long                l_end_frame;
102
103     long                l_unit;
104     aout_increment_t    unit_increment;
105     /* The following variable is used to store the number of remaining audio
106      * units in the current timestamped frame area. */
107     long                l_units;
108
109 } aout_fifo_t;
110
111 #define AOUT_FIFO_ISEMPTY( fifo ) \
112   ( (fifo).l_end_frame == (fifo).l_start_frame )
113
114 #define AOUT_FIFO_ISFULL( fifo ) \
115   ( ((((fifo).l_end_frame + 1) - (fifo).l_start_frame) & AOUT_FIFO_SIZE) == 0 )
116
117 #define AOUT_EMPTY_FIFO         0
118 #define AOUT_INTF_MONO_FIFO     1
119 #define AOUT_INTF_STEREO_FIFO   2
120 #define AOUT_ADEC_MONO_FIFO     3
121 #define AOUT_ADEC_STEREO_FIFO   4
122 #define AOUT_ADEC_SPDIF_FIFO    5
123
124 /*****************************************************************************
125  * aout_thread_t : audio output thread descriptor
126  *****************************************************************************/
127 typedef struct aout_thread_s
128 {
129     vlc_thread_t        thread_id;
130     boolean_t           b_die;
131     boolean_t           b_active;
132
133     vlc_mutex_t         fifos_lock;
134     aout_fifo_t         fifo[ AOUT_MAX_FIFOS ];
135
136     /* Plugin used and shortcuts to access its capabilities */
137     struct module_s *   p_module;
138     int              ( *pf_open )       ( p_aout_thread_t );
139     int              ( *pf_setformat )  ( p_aout_thread_t );
140     long             ( *pf_getbufinfo ) ( p_aout_thread_t, long );
141     void             ( *pf_play )       ( p_aout_thread_t, byte_t *, int );
142     void             ( *pf_close )      ( p_aout_thread_t );
143
144     void *              buffer;
145     /* The s32 buffer is used to mix all the audio fifos together before
146      * converting them and storing them in the audio output buffer */
147     s32 *               s32_buffer;
148
149     /* The size of the audio output buffer is kept in audio units, as this is
150      * the only unit that is common with every audio decoder and audio fifo */
151     long                l_units;
152     long                l_msleep;
153
154     /* date is the moment where the first audio unit of the output buffer
155      * will be played */
156     mtime_t             date;
157
158     /* Path to the audio output device (default is set to "/dev/dsp") */
159     char *              psz_device;
160     int                 i_fd;
161
162     /* The current volume */
163     int                 i_volume;
164     int                 i_savedvolume;
165     /* Format of the audio output samples */
166     int                 i_format;
167     /* Number of channels */
168     int                 i_channels;
169     /* Mono or Stereo sound */
170     boolean_t           b_stereo;
171     /* Rate and gain of the audio output sound (in Hz) */
172     long                l_rate;
173     long                l_gain;
174
175     /* there might be some useful private structure, such as audio_buf_info
176      * for the OSS output */
177     p_aout_sys_t        p_sys;
178
179 } aout_thread_t;
180
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 */
190
191 #ifdef WORDS_BIGENDIAN
192 #define AOUT_FMT_S16_NE      AOUT_FMT_S16_BE
193 #else
194 #define AOUT_FMT_S16_NE      AOUT_FMT_S16_LE
195 #endif
196
197 /* Number of samples in an AC3 frame */
198 #define AC3_FRAME_SIZE      1536
199
200 /* Size of a frame for spdif output */
201 #define SPDIF_FRAME_SIZE    6144
202
203 /*****************************************************************************
204  * Prototypes
205  *****************************************************************************/
206 void            aout_InitBank           ( void );
207 void            aout_EndBank            ( void );
208
209 aout_thread_t * aout_CreateThread       ( int *pi_status );
210 void            aout_DestroyThread      ( aout_thread_t *, int * );
211
212 aout_fifo_t *   aout_CreateFifo         ( int, int, long, long, long, void * );
213 void            aout_DestroyFifo        ( aout_fifo_t *p_fifo );
214 void            aout_FreeFifo           ( aout_fifo_t *p_fifo );
215