]> git.sesse.net Git - vlc/blob - include/audio_output.h
Fixed solaris libraries
[vlc] / include / audio_output.h
1 /*****************************************************************************
2  * audio_output.h : audio output thread interface
3  *****************************************************************************
4  * Copyright (C) 1999, 2000 VideoLAN
5  *
6  * Authors:
7  * 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  * Required headers:
26  * - "common.h"                                                   ( boolean_t )
27  * - "mtime.h"                                                      ( mtime_t )
28  * - "threads.h"                                               ( vlc_thread_t )
29  *****************************************************************************/
30
31 /* TODO :
32  *
33  * - Créer un flag destroy dans les fifos audio pour indiquer au thread audio
34  *   qu'il peut libérer la mémoire occupée par le buffer de la fifo lorsqu'il
35  *   le désire (fin du son ou fin du thread)
36  *
37  */
38
39 /*
40  * Macros
41  */
42 #define AOUT_FIFO_ISEMPTY( fifo )       ( (fifo).l_end_frame == (fifo).i_start_frame )
43 #define AOUT_FIFO_ISFULL( fifo )        ( ((((fifo).l_end_frame + 1) - (fifo).l_start_frame) & AOUT_FIFO_SIZE) == 0 )
44
45 /*****************************************************************************
46  * aout_increment_t
47  *****************************************************************************
48  * This structure is used to keep the progression of an index up-to-date, in
49  * order to avoid rounding problems and heavy computations, as the function
50  * that handles this structure only uses additions.
51  *****************************************************************************/
52 typedef struct
53 {
54     /* The remainder is used to keep track of the fractional part of the
55      * index. */
56     long                l_remainder;
57
58     /*
59      * The increment structure is initialized with the result of an euclidean
60      * division :
61      *
62      *  l_euclidean_numerator                           l_euclidean_remainder
63      * ----------------------- = l_euclidean_integer + -----------------------
64      * l_euclidean_denominator                         l_euclidean_denominator
65      *
66      */
67     long                l_euclidean_integer;
68     long                l_euclidean_remainder;
69     long                l_euclidean_denominator;
70
71 } aout_increment_t;
72
73 /*****************************************************************************
74  * aout_fifo_t
75  *****************************************************************************/
76 typedef struct
77 {
78     /* See the fifo types below */
79     int                 i_type;
80     boolean_t           b_die;
81
82     int                 i_channels;
83     boolean_t           b_stereo;
84     long                l_rate;
85
86     vlc_mutex_t         data_lock;
87     vlc_cond_t          data_wait;
88
89     long                l_frame_size;
90     void *              buffer;
91     mtime_t *           date;
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     long                l_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     long                l_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     long                l_end_frame;
105
106     long                l_unit;
107     aout_increment_t    unit_increment;
108     /* The following variable is used to store the number of remaining audio
109      * units in the current timestamped frame area. */
110     long                l_units;
111
112 } aout_fifo_t;
113
114 #define AOUT_EMPTY_FIFO         0
115 #define AOUT_INTF_MONO_FIFO     1
116 #define AOUT_INTF_STEREO_FIFO   2
117 #define AOUT_ADEC_MONO_FIFO     3
118 #define AOUT_ADEC_STEREO_FIFO   4
119
120 /*****************************************************************************
121  * aout_thread_t : audio output thread descriptor
122  *****************************************************************************/
123 typedef int  (aout_sys_open_t)           ( p_aout_thread_t p_aout );
124 typedef int  (aout_sys_reset_t)          ( p_aout_thread_t p_aout );
125 typedef int  (aout_sys_setformat_t)      ( p_aout_thread_t p_aout );
126 typedef int  (aout_sys_setchannels_t)    ( p_aout_thread_t p_aout );
127 typedef int  (aout_sys_setrate_t)        ( p_aout_thread_t p_aout );
128 typedef long (aout_sys_getbufinfo_t)     ( p_aout_thread_t p_aout,
129                                            long l_buffer_limit );
130 typedef void (aout_sys_playsamples_t)    ( p_aout_thread_t p_aout,
131                                            byte_t *buffer, int i_size );
132 typedef void (aout_sys_close_t)          ( p_aout_thread_t p_aout );
133
134 typedef struct aout_thread_s
135 {
136     vlc_thread_t        thread_id;
137     boolean_t           b_die;
138     boolean_t           b_active;
139
140     vlc_mutex_t         fifos_lock;
141     aout_fifo_t         fifo[ AOUT_MAX_FIFOS ];
142
143     /* Plugins */
144     aout_sys_open_t *           p_sys_open;
145     aout_sys_reset_t *          p_sys_reset;
146     aout_sys_setformat_t *      p_sys_setformat;
147     aout_sys_setchannels_t *    p_sys_setchannels;
148     aout_sys_setrate_t *        p_sys_setrate;
149     aout_sys_getbufinfo_t *     p_sys_getbufinfo;
150     aout_sys_playsamples_t *    p_sys_playsamples;
151     aout_sys_close_t *          p_sys_close;
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     long                l_units;
161     long                l_msleep;
162
163     /* date is the moment where the first audio unit of the output buffer
164      * will be played */
165     mtime_t             date;
166
167     /* Path to the audio output device (default is set to "/dev/dsp") */
168     char *              psz_device;
169     int                 i_fd;
170
171     /* Format of the audio output samples */
172     int                 i_format;
173     /* Number of channels */
174     int                 i_channels;
175     /* Mono or Stereo sound */
176     boolean_t           b_stereo;
177     /* Rate and gain of the audio output sound (in Hz) */
178     long                l_rate;
179     long                l_gain;
180
181     /* there might be some useful private structure, such as audio_buf_info
182      * for the OSS output */
183     p_aout_sys_t        p_sys;
184
185
186     /* there is the current volume */
187     int                 vol;
188
189 } aout_thread_t;
190
191 /* Those are from <linux/soundcard.h> but are needed because of formats
192  * on other platforms */
193 #define AOUT_FMT_U8          0x00000008
194 #define AOUT_FMT_S16_LE      0x00000010           /* Little endian signed 16 */
195 #define AOUT_FMT_S16_BE      0x00000020              /* Big endian signed 16 */
196 #define AOUT_FMT_S8          0x00000040
197 #define AOUT_FMT_U16_LE      0x00000080                 /* Little endian U16 */
198 #define AOUT_FMT_U16_BE      0x00000100                    /* Big endian U16 */
199
200 #if __BYTE_ORDER == __LITTLE_ENDIAN
201 #define AOUT_FMT_S16_NE      AOUT_FMT_S16_LE
202 #elif __BYTE_ORDER == __BIG_ENDIAN
203 #define AOUT_FMT_S16_NE      AOUT_FMT_S16_BE
204 #endif
205
206 /*****************************************************************************
207  * Prototypes
208  *****************************************************************************/
209 aout_thread_t * aout_CreateThread       ( int *pi_status );
210 void            aout_DestroyThread      ( aout_thread_t *p_aout, int *pi_status );
211
212
213 aout_fifo_t *   aout_CreateFifo         ( aout_thread_t *p_aout, aout_fifo_t *p_fifo );
214 void            aout_DestroyFifo        ( aout_fifo_t *p_fifo );