]> git.sesse.net Git - vlc/blob - include/audio_output.h
* ALL: new module API. Makes a few things a lot simpler, and we gain
[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.50 2002/07/31 20:56:50 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_increment_t
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
33 {
34     /* The remainder is used to keep track of the fractional part of the
35      * index. */
36     int i_r;
37
38     /*
39      * The increment structure is initialized with the result of an euclidean
40      * division :
41      *
42      *  i_x           i_b
43      * ----- = i_a + -----
44      *  i_y           i_c
45      *
46      */
47     int i_a, i_b, i_c;
48
49 } aout_increment_t;
50
51 /*****************************************************************************
52  * aout_fifo_t
53  *****************************************************************************/
54 struct aout_fifo_t
55 {
56     /* See the fifo formats below */
57     int                 i_format;
58     int                 i_channels;
59     int                 i_rate;
60     int                 i_frame_size;
61
62     vlc_bool_t          b_die;
63     int                 i_fifo;      /* Just to keep track of the fifo index */
64
65     vlc_mutex_t         data_lock;
66     vlc_cond_t          data_wait;
67
68     u8 *                buffer;
69     mtime_t *           date;
70
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 */
74     int                 i_start_frame;
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. */
78     int                 i_next_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. */
83     int                 i_end_frame;
84
85     /* Current index in p_aout->buffer */
86     int                 i_unit;
87     /* Max index in p_aout->buffer */
88     int                 i_unit_limit;
89     /* Structure used to calculate i_unit with a Bresenham algorithm */
90     aout_increment_t    unit_increment;
91
92     /* The following variable is used to store the number of remaining audio
93      * units in the current timestamped frame area. */
94     int                 i_units;
95 };
96
97 #define AOUT_FIFO_ISEMPTY( fifo ) \
98   ( (fifo).i_end_frame == (fifo).i_start_frame )
99
100 #define AOUT_FIFO_ISFULL( fifo ) \
101   ( ((((fifo).i_end_frame + 1) - (fifo).i_start_frame) & AOUT_FIFO_SIZE) == 0 )
102
103 #define AOUT_FIFO_INC( i_index ) \
104   ( ((i_index) + 1) & AOUT_FIFO_SIZE )
105
106 /* List of known fifo formats */
107 #define AOUT_FIFO_NONE    0
108 #define AOUT_FIFO_PCM     1
109 #define AOUT_FIFO_SPDIF   2
110
111 /*****************************************************************************
112  * aout_thread_t : audio output thread descriptor
113  *****************************************************************************/
114 struct aout_thread_t
115 {
116     VLC_COMMON_MEMBERS
117
118     vlc_mutex_t         fifos_lock;
119     aout_fifo_t         fifo[ AOUT_MAX_FIFOS ];
120
121     /* Plugin used and shortcuts to access its capabilities */
122     module_t *   p_module;
123     int       ( *pf_setformat )  ( aout_thread_t * );
124     int       ( *pf_getbufinfo ) ( aout_thread_t * , int );
125     void      ( *pf_play )       ( aout_thread_t * , byte_t *, int );
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     int                 i_units;
135
136     /* date is the moment where the first audio unit of the output buffer
137      * will be played */
138     mtime_t             date;
139
140     /* The current volume */
141     int                 i_volume;
142     int                 i_savedvolume;
143
144     /* Format of the audio output samples, number of channels, and
145      * rate and gain (in Hz) of the audio output sound */
146     int                 i_format;
147     int                 i_channels;
148     int                 i_rate;
149
150     /* Latency of the audio output plugin, in bytes */
151     int                 i_latency;
152
153     /* there might be some useful private structure, such as audio_buf_info
154      * for the OSS output */
155     aout_sys_t *        p_sys;
156 };
157
158 /* Those are from <linux/soundcard.h> but are needed because of formats
159  * on other platforms */
160 #define AOUT_FMT_U8          0x00000008
161 #define AOUT_FMT_S16_LE      0x00000010           /* Little endian signed 16 */
162 #define AOUT_FMT_S16_BE      0x00000020              /* Big endian signed 16 */
163 #define AOUT_FMT_S8          0x00000040
164 #define AOUT_FMT_U16_LE      0x00000080                 /* Little endian U16 */
165 #define AOUT_FMT_U16_BE      0x00000100                    /* Big endian U16 */
166 #define AOUT_FMT_AC3         0x00000400                 /* Dolby Digital AC3 */
167
168 #ifdef WORDS_BIGENDIAN
169 #define AOUT_FMT_S16_NE      AOUT_FMT_S16_BE
170 #else
171 #define AOUT_FMT_S16_NE      AOUT_FMT_S16_LE
172 #endif
173
174 /* Number of samples in an AC3 frame */
175 #define AC3_FRAME_SIZE      1536
176
177 /* Size of a frame for spdif output */
178 #define SPDIF_FRAME_SIZE    6144
179
180 /*****************************************************************************
181  * Prototypes
182  *****************************************************************************/
183 aout_thread_t * aout_CreateThread       ( vlc_object_t *, int, int );
184 void            aout_DestroyThread      ( aout_thread_t * );
185
186 #define aout_CreateFifo(a,b,c,d,e,f) __aout_CreateFifo(VLC_OBJECT(a),b,c,d,e,f)
187 VLC_EXPORT( aout_fifo_t *, __aout_CreateFifo,  ( vlc_object_t *, int, int, int, int, void * ) );
188 VLC_EXPORT( void,            aout_DestroyFifo, ( aout_fifo_t *p_fifo ) );
189             void             aout_FreeFifo     ( aout_fifo_t *p_fifo );
190