]> git.sesse.net Git - vlc/blob - include/audio_output.h
* ALL: got rid of p_object->p_this which is now useless.
[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.48 2002/06/01 18:04:48 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_s
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_s
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_s
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_open )       ( aout_thread_t * );
124     int       ( *pf_setformat )  ( aout_thread_t * );
125     int       ( *pf_getbufinfo ) ( aout_thread_t * , int );
126     void      ( *pf_play )       ( aout_thread_t * , byte_t *, int );
127     void      ( *pf_close )      ( aout_thread_t * );
128
129     void *              buffer;
130     /* The s32 buffer is used to mix all the audio fifos together before
131      * converting them and storing them in the audio output buffer */
132     s32 *               s32_buffer;
133
134     /* The size of the audio output buffer is kept in audio units, as this is
135      * the only unit that is common with every audio decoder and audio fifo */
136     int                 i_units;
137
138     /* date is the moment where the first audio unit of the output buffer
139      * will be played */
140     mtime_t             date;
141
142     /* The current volume */
143     int                 i_volume;
144     int                 i_savedvolume;
145
146     /* Format of the audio output samples, number of channels, and
147      * rate and gain (in Hz) of the audio output sound */
148     int                 i_format;
149     int                 i_channels;
150     int                 i_rate;
151
152     /* Latency of the audio output plugin, in bytes */
153     int                 i_latency;
154
155     /* there might be some useful private structure, such as audio_buf_info
156      * for the OSS output */
157     aout_sys_t *        p_sys;
158 };
159
160 /* Those are from <linux/soundcard.h> but are needed because of formats
161  * on other platforms */
162 #define AOUT_FMT_U8          0x00000008
163 #define AOUT_FMT_S16_LE      0x00000010           /* Little endian signed 16 */
164 #define AOUT_FMT_S16_BE      0x00000020              /* Big endian signed 16 */
165 #define AOUT_FMT_S8          0x00000040
166 #define AOUT_FMT_U16_LE      0x00000080                 /* Little endian U16 */
167 #define AOUT_FMT_U16_BE      0x00000100                    /* Big endian U16 */
168 #define AOUT_FMT_AC3         0x00000400                 /* Dolby Digital AC3 */
169
170 #ifdef WORDS_BIGENDIAN
171 #define AOUT_FMT_S16_NE      AOUT_FMT_S16_BE
172 #else
173 #define AOUT_FMT_S16_NE      AOUT_FMT_S16_LE
174 #endif
175
176 /* Number of samples in an AC3 frame */
177 #define AC3_FRAME_SIZE      1536
178
179 /* Size of a frame for spdif output */
180 #define SPDIF_FRAME_SIZE    6144
181
182 /*****************************************************************************
183  * Prototypes
184  *****************************************************************************/
185 aout_thread_t * aout_CreateThread       ( vlc_object_t *, int, int );
186 void            aout_DestroyThread      ( aout_thread_t * );
187
188 #define aout_CreateFifo(a,b,c,d,e,f) __aout_CreateFifo(CAST_TO_VLC_OBJECT(a),b,c,d,e,f)
189 VLC_EXPORT( aout_fifo_t *, __aout_CreateFifo,  ( vlc_object_t *, int, int, int, int, void * ) );
190 VLC_EXPORT( void,            aout_DestroyFifo, ( aout_fifo_t *p_fifo ) );
191             void             aout_FreeFifo     ( aout_fifo_t *p_fifo );
192