]> git.sesse.net Git - vlc/blob - include/audio_output.h
* Mandatory step for video output IV and the audio output quality
[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.33 2001/05/01 04:18:17 sam 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_increment_t
26  *****************************************************************************
27  * This structure is used to keep the progression of an index up-to-date, in
28  * order to avoid rounding problems and heavy computations, as the function
29  * that handles this structure only uses additions.
30  *****************************************************************************/
31 typedef struct aout_increment_s
32 {
33     /* The remainder is used to keep track of the fractional part of the
34      * index. */
35     long                l_remainder;
36
37     /*
38      * The increment structure is initialized with the result of an euclidean
39      * division :
40      *
41      *  l_euclidean_numerator                           l_euclidean_remainder
42      * ----------------------- = l_euclidean_integer + -----------------------
43      * l_euclidean_denominator                         l_euclidean_denominator
44      *
45      */
46     long                l_euclidean_integer;
47     long                l_euclidean_remainder;
48     long                l_euclidean_denominator;
49
50 } aout_increment_t;
51
52 /*****************************************************************************
53  * aout_fifo_t
54  *****************************************************************************/
55 typedef struct aout_fifo_s
56 {
57     /* See the fifo types below */
58     int                 i_type;
59     boolean_t           b_die;
60     int                 i_fifo;      /* Just to keep track of the fifo index */
61
62     int                 i_channels;
63     boolean_t           b_stereo;
64     long                l_rate;
65
66     vlc_mutex_t         data_lock;
67     vlc_cond_t          data_wait;
68
69     long                l_frame_size;
70     void *              buffer;
71     mtime_t *           date;
72     /* The start frame is the first frame in the buffer that contains decoded
73      * audio data. It it also the first frame in the current timestamped frame
74      * area, ie the first dated frame in the decoded part of the buffer. :-p */
75     long                l_start_frame;
76     boolean_t           b_start_frame;
77     /* The next frame is the end frame of the current timestamped frame area,
78      * ie the first dated frame after the start frame. */
79     long                l_next_frame;
80     boolean_t           b_next_frame;
81     /* The end frame is the first frame, after the start frame, that doesn't
82      * contain decoded audio data. That's why the end frame is the first frame
83      * where the audio decoder can store its decoded audio frames. */
84     long                l_end_frame;
85
86     long                l_unit;
87     aout_increment_t    unit_increment;
88     /* The following variable is used to store the number of remaining audio
89      * units in the current timestamped frame area. */
90     long                l_units;
91
92 } aout_fifo_t;
93
94 #define AOUT_FIFO_ISEMPTY( fifo ) \
95   ( (fifo).l_end_frame == (fifo).l_start_frame )
96
97 #define AOUT_FIFO_ISFULL( fifo ) \
98   ( ((((fifo).l_end_frame + 1) - (fifo).l_start_frame) & AOUT_FIFO_SIZE) == 0 )
99
100 #define AOUT_EMPTY_FIFO         0
101 #define AOUT_INTF_MONO_FIFO     1
102 #define AOUT_INTF_STEREO_FIFO   2
103 #define AOUT_ADEC_MONO_FIFO     3
104 #define AOUT_ADEC_STEREO_FIFO   4
105 #define AOUT_ADEC_SPDIF_FIFO    5
106
107 /*****************************************************************************
108  * aout_thread_t : audio output thread descriptor
109  *****************************************************************************/
110 typedef struct aout_thread_s
111 {
112     vlc_thread_t        thread_id;
113     boolean_t           b_die;
114     boolean_t           b_active;
115
116     vlc_mutex_t         fifos_lock;
117     aout_fifo_t         fifo[ AOUT_MAX_FIFOS ];
118
119     /* Plugin used and shortcuts to access its capabilities */
120     struct module_s *   p_module;
121     int              ( *pf_open )       ( p_aout_thread_t );
122     int              ( *pf_setformat )  ( p_aout_thread_t );
123     long             ( *pf_getbufinfo ) ( p_aout_thread_t, long );
124     void             ( *pf_play )       ( p_aout_thread_t, byte_t *, int );
125     void             ( *pf_close )      ( p_aout_thread_t );
126
127     void *              buffer;
128     /* The s32 buffer is used to mix all the audio fifos together before
129      * converting them and storing them in the audio output buffer */
130     s32 *               s32_buffer;
131
132     /* The size of the audio output buffer is kept in audio units, as this is
133      * the only unit that is common with every audio decoder and audio fifo */
134     long                l_units;
135     long                l_msleep;
136
137     /* date is the moment where the first audio unit of the output buffer
138      * will be played */
139     mtime_t             date;
140
141     /* Path to the audio output device (default is set to "/dev/dsp") */
142     char *              psz_device;
143     int                 i_fd;
144
145     /* The current volume */
146     int                 i_vol;
147     /* Format of the audio output samples */
148     int                 i_format;
149     /* Number of channels */
150     int                 i_channels;
151     /* Mono or Stereo sound */
152     boolean_t           b_stereo;
153     /* Rate and gain of the audio output sound (in Hz) */
154     long                l_rate;
155     long                l_gain;
156
157     /* there might be some useful private structure, such as audio_buf_info
158      * for the OSS output */
159     p_aout_sys_t        p_sys;
160
161 } aout_thread_t;
162
163 /* Those are from <linux/soundcard.h> but are needed because of formats
164  * on other platforms */
165 #define AOUT_FMT_U8          0x00000008
166 #define AOUT_FMT_S16_LE      0x00000010           /* Little endian signed 16 */
167 #define AOUT_FMT_S16_BE      0x00000020              /* Big endian signed 16 */
168 #define AOUT_FMT_S8          0x00000040
169 #define AOUT_FMT_U16_LE      0x00000080                 /* Little endian U16 */
170 #define AOUT_FMT_U16_BE      0x00000100                    /* Big endian U16 */
171 #define AOUT_FMT_AC3         0x00000400                 /* Dolby Digital AC3 */
172
173
174 #ifdef WORDS_BIGENDIAN
175 #define AOUT_FMT_S16_NE      AOUT_FMT_S16_BE
176 #else
177 #define AOUT_FMT_S16_NE      AOUT_FMT_S16_LE
178 #endif
179
180 /*****************************************************************************
181  * Prototypes
182  *****************************************************************************/
183 aout_thread_t * aout_CreateThread       ( int *pi_status );
184 void            aout_DestroyThread      ( aout_thread_t *, int * );
185
186 aout_fifo_t *   aout_CreateFifo         ( int, int, long, long, long, void * );
187 void            aout_DestroyFifo        ( aout_fifo_t *p_fifo );
188 void            aout_FreeFifo           ( aout_fifo_t *p_fifo );
189