1 | /*
|
---|
2 | * QEMU Audio subsystem header
|
---|
3 | *
|
---|
4 | * Copyright (c) 2003-2005 Vassili Karpov (malc)
|
---|
5 | *
|
---|
6 | * Permission is hereby granted, free of charge, to any person obtaining a copy
|
---|
7 | * of this software and associated documentation files (the "Software"), to deal
|
---|
8 | * in the Software without restriction, including without limitation the rights
|
---|
9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
---|
10 | * copies of the Software, and to permit persons to whom the Software is
|
---|
11 | * furnished to do so, subject to the following conditions:
|
---|
12 | *
|
---|
13 | * The above copyright notice and this permission notice shall be included in
|
---|
14 | * all copies or substantial portions of the Software.
|
---|
15 | *
|
---|
16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
---|
17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
---|
18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
|
---|
19 | * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
---|
20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
---|
21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
---|
22 | * THE SOFTWARE.
|
---|
23 | */
|
---|
24 | #ifndef QEMU_AUDIO_INT_H
|
---|
25 | #define QEMU_AUDIO_INT_H
|
---|
26 |
|
---|
27 | #ifdef CONFIG_COREAUDIO
|
---|
28 | #ifndef VBOX
|
---|
29 | #define FLOAT_MIXENG
|
---|
30 | #else
|
---|
31 | #undef FLOAT_MIXENG
|
---|
32 | #endif
|
---|
33 | /* #define RECIPROCAL */
|
---|
34 | #endif
|
---|
35 |
|
---|
36 | #include <limits.h>
|
---|
37 | #include "mixeng.h"
|
---|
38 |
|
---|
39 | #define qemu_malloc RTMemAlloc
|
---|
40 | #define qemu_mallocz RTMemAllocZ
|
---|
41 | #define qemu_free RTMemFree
|
---|
42 | #define qemu_strdup RTStrDup
|
---|
43 |
|
---|
44 | struct audio_pcm_ops;
|
---|
45 |
|
---|
46 | typedef enum {
|
---|
47 | AUD_OPT_INT,
|
---|
48 | AUD_OPT_FMT,
|
---|
49 | AUD_OPT_STR,
|
---|
50 | AUD_OPT_BOOL
|
---|
51 | } audio_option_tag_e;
|
---|
52 |
|
---|
53 | struct audio_option {
|
---|
54 | const char *name;
|
---|
55 | audio_option_tag_e tag;
|
---|
56 | void *valp;
|
---|
57 | const char *descr;
|
---|
58 | int *overridenp;
|
---|
59 | int overriden;
|
---|
60 | };
|
---|
61 |
|
---|
62 | struct audio_callback {
|
---|
63 | void *opaque;
|
---|
64 | audio_callback_fn_t fn;
|
---|
65 | };
|
---|
66 |
|
---|
67 | struct audio_pcm_info {
|
---|
68 | int bits;
|
---|
69 | int sign;
|
---|
70 | int freq;
|
---|
71 | int nchannels;
|
---|
72 | int align;
|
---|
73 | int shift;
|
---|
74 | int bytes_per_second;
|
---|
75 | int swap_endianness;
|
---|
76 | };
|
---|
77 |
|
---|
78 | typedef struct SWVoiceCap SWVoiceCap;
|
---|
79 |
|
---|
80 | typedef struct HWVoiceOut {
|
---|
81 | int enabled;
|
---|
82 | int pending_disable;
|
---|
83 | struct audio_pcm_info info;
|
---|
84 |
|
---|
85 | f_sample *clip;
|
---|
86 |
|
---|
87 | int rpos;
|
---|
88 | uint64_t ts_helper;
|
---|
89 |
|
---|
90 | st_sample_t *mix_buf;
|
---|
91 |
|
---|
92 | int samples;
|
---|
93 | LIST_HEAD (sw_out_listhead, SWVoiceOut) sw_head;
|
---|
94 | LIST_HEAD (sw_cap_listhead, SWVoiceCap) cap_head;
|
---|
95 | struct audio_pcm_ops *pcm_ops;
|
---|
96 | LIST_ENTRY (HWVoiceOut) entries;
|
---|
97 | } HWVoiceOut;
|
---|
98 |
|
---|
99 | typedef struct HWVoiceIn {
|
---|
100 | int enabled;
|
---|
101 | struct audio_pcm_info info;
|
---|
102 |
|
---|
103 | t_sample *conv;
|
---|
104 |
|
---|
105 | int wpos;
|
---|
106 | int total_samples_captured;
|
---|
107 | uint64_t ts_helper;
|
---|
108 |
|
---|
109 | st_sample_t *conv_buf;
|
---|
110 |
|
---|
111 | int samples;
|
---|
112 | LIST_HEAD (sw_in_listhead, SWVoiceIn) sw_head;
|
---|
113 | struct audio_pcm_ops *pcm_ops;
|
---|
114 | LIST_ENTRY (HWVoiceIn) entries;
|
---|
115 | } HWVoiceIn;
|
---|
116 |
|
---|
117 | struct SWVoiceOut {
|
---|
118 | struct audio_pcm_info info;
|
---|
119 | t_sample *conv;
|
---|
120 | int64_t ratio;
|
---|
121 | st_sample_t *buf;
|
---|
122 | void *rate;
|
---|
123 | int total_hw_samples_mixed;
|
---|
124 | int active;
|
---|
125 | int empty;
|
---|
126 | HWVoiceOut *hw;
|
---|
127 | char *name;
|
---|
128 | volume_t vol;
|
---|
129 | struct audio_callback callback;
|
---|
130 | LIST_ENTRY (SWVoiceOut) entries;
|
---|
131 | };
|
---|
132 |
|
---|
133 | struct SWVoiceIn {
|
---|
134 | int active;
|
---|
135 | struct audio_pcm_info info;
|
---|
136 | int64_t ratio;
|
---|
137 | void *rate;
|
---|
138 | int total_hw_samples_acquired;
|
---|
139 | st_sample_t *buf;
|
---|
140 | f_sample *clip;
|
---|
141 | HWVoiceIn *hw;
|
---|
142 | char *name;
|
---|
143 | volume_t vol;
|
---|
144 | struct audio_callback callback;
|
---|
145 | LIST_ENTRY (SWVoiceIn) entries;
|
---|
146 | };
|
---|
147 |
|
---|
148 | struct audio_driver {
|
---|
149 | const char *name;
|
---|
150 | const char *descr;
|
---|
151 | struct audio_option *options;
|
---|
152 | void *(*init) (void);
|
---|
153 | void (*fini) (void *);
|
---|
154 | struct audio_pcm_ops *pcm_ops;
|
---|
155 | int can_be_default;
|
---|
156 | int max_voices_out;
|
---|
157 | int max_voices_in;
|
---|
158 | int voice_size_out;
|
---|
159 | int voice_size_in;
|
---|
160 | };
|
---|
161 |
|
---|
162 | struct audio_pcm_ops {
|
---|
163 | int (*init_out)(HWVoiceOut *hw, audsettings_t *as);
|
---|
164 | void (*fini_out)(HWVoiceOut *hw);
|
---|
165 | int (*run_out) (HWVoiceOut *hw);
|
---|
166 | int (*write) (SWVoiceOut *sw, void *buf, int size);
|
---|
167 | int (*ctl_out) (HWVoiceOut *hw, int cmd, ...);
|
---|
168 |
|
---|
169 | int (*init_in) (HWVoiceIn *hw, audsettings_t *as);
|
---|
170 | void (*fini_in) (HWVoiceIn *hw);
|
---|
171 | int (*run_in) (HWVoiceIn *hw);
|
---|
172 | int (*read) (SWVoiceIn *sw, void *buf, int size);
|
---|
173 | int (*ctl_in) (HWVoiceIn *hw, int cmd, ...);
|
---|
174 | };
|
---|
175 |
|
---|
176 | struct capture_callback {
|
---|
177 | struct audio_capture_ops ops;
|
---|
178 | void *opaque;
|
---|
179 | LIST_ENTRY (capture_callback) entries;
|
---|
180 | };
|
---|
181 |
|
---|
182 | struct CaptureVoiceOut {
|
---|
183 | HWVoiceOut hw;
|
---|
184 | void *buf;
|
---|
185 | LIST_HEAD (cb_listhead, capture_callback) cb_head;
|
---|
186 | LIST_ENTRY (CaptureVoiceOut) entries;
|
---|
187 | };
|
---|
188 |
|
---|
189 | struct SWVoiceCap {
|
---|
190 | SWVoiceOut sw;
|
---|
191 | CaptureVoiceOut *cap;
|
---|
192 | LIST_ENTRY (SWVoiceCap) entries;
|
---|
193 | };
|
---|
194 |
|
---|
195 | struct AudioState {
|
---|
196 | struct audio_driver *drv;
|
---|
197 | void *drv_opaque;
|
---|
198 |
|
---|
199 | QEMUTimer *ts;
|
---|
200 | LIST_HEAD (card_listhead, QEMUSoundCard) card_head;
|
---|
201 | LIST_HEAD (hw_in_listhead, HWVoiceIn) hw_head_in;
|
---|
202 | LIST_HEAD (hw_out_listhead, HWVoiceOut) hw_head_out;
|
---|
203 | LIST_HEAD (cap_listhead, CaptureVoiceOut) cap_head;
|
---|
204 | int nb_hw_voices_out;
|
---|
205 | int nb_hw_voices_in;
|
---|
206 | PPDMDRVINS pDrvIns;
|
---|
207 | };
|
---|
208 |
|
---|
209 | extern struct audio_driver no_audio_driver;
|
---|
210 | extern struct audio_driver oss_audio_driver;
|
---|
211 | extern struct audio_driver sdl_audio_driver;
|
---|
212 | extern struct audio_driver wav_audio_driver;
|
---|
213 | extern struct audio_driver fmod_audio_driver;
|
---|
214 | extern struct audio_driver alsa_audio_driver;
|
---|
215 | extern struct audio_driver pulse_audio_driver;
|
---|
216 | extern struct audio_driver coreaudio_audio_driver;
|
---|
217 | extern struct audio_driver dsound_audio_driver;
|
---|
218 | extern struct audio_driver solaudio_audio_driver;
|
---|
219 | extern volume_t nominal_volume;
|
---|
220 | #ifdef VBOX
|
---|
221 | extern volume_t pcm_out_volume;
|
---|
222 | extern volume_t pcm_in_volume;
|
---|
223 | #endif
|
---|
224 |
|
---|
225 | uint64_t audio_get_clock (void);
|
---|
226 | uint64_t audio_get_ticks_per_sec (void);
|
---|
227 |
|
---|
228 | void audio_pcm_init_info (struct audio_pcm_info *info, audsettings_t *as);
|
---|
229 | void audio_pcm_info_clear_buf (struct audio_pcm_info *info, void *buf, int len);
|
---|
230 |
|
---|
231 | int audio_pcm_sw_write (SWVoiceOut *sw, void *buf, int len);
|
---|
232 | int audio_pcm_hw_get_live_in (HWVoiceIn *hw);
|
---|
233 |
|
---|
234 | int audio_pcm_sw_read (SWVoiceIn *sw, void *buf, int len);
|
---|
235 | int audio_pcm_hw_get_live_out (HWVoiceOut *hw);
|
---|
236 | int audio_pcm_hw_get_live_out2 (HWVoiceOut *hw, int *nb_live);
|
---|
237 |
|
---|
238 | int audio_bug (const char *funcname, int cond);
|
---|
239 | void *audio_calloc (const char *funcname, int nmemb, size_t size);
|
---|
240 |
|
---|
241 | #define VOICE_ENABLE 1
|
---|
242 | #define VOICE_DISABLE 2
|
---|
243 |
|
---|
244 | static inline int audio_ring_dist (int dst, int src, int len)
|
---|
245 | {
|
---|
246 | return (dst >= src) ? (dst - src) : (len - src + dst);
|
---|
247 | }
|
---|
248 |
|
---|
249 | #if defined __GNUC__ && !defined VBOX /* VBox: oh, please, just shut up. */
|
---|
250 | #define GCC_ATTR __attribute__ ((__unused__, __format__ (__printf__, 1, 2)))
|
---|
251 | #if __STDC_VERSION__ > 199901L
|
---|
252 | #define INIT_FIELD(f) . f
|
---|
253 | #else
|
---|
254 | #define INIT_FIELD(f) /**/
|
---|
255 | #endif
|
---|
256 | #define GCC_FMT_ATTR(n, m) __attribute__ ((__format__ (__printf__, n, m)))
|
---|
257 | #else
|
---|
258 | #define GCC_ATTR /**/
|
---|
259 | #define INIT_FIELD(f) /**/
|
---|
260 | #define GCC_FMT_ATTR(n, m)
|
---|
261 | #endif
|
---|
262 |
|
---|
263 | #ifndef VBOX
|
---|
264 | static void GCC_ATTR dolog (const char *fmt, ...)
|
---|
265 | #else
|
---|
266 | DECLINLINE(void) GCC_ATTR dolog (const char *fmt, ...) /* shuts up unused warnings. */
|
---|
267 | #endif
|
---|
268 | {
|
---|
269 | va_list ap;
|
---|
270 |
|
---|
271 | va_start (ap, fmt);
|
---|
272 | AUD_vlog (AUDIO_CAP, fmt, ap);
|
---|
273 | va_end (ap);
|
---|
274 | }
|
---|
275 |
|
---|
276 | #ifdef DEBUG
|
---|
277 | DECLINLINE(void) GCC_ATTR ldebug (const char *fmt, ...)
|
---|
278 | {
|
---|
279 | va_list ap;
|
---|
280 |
|
---|
281 | va_start (ap, fmt);
|
---|
282 | AUD_vlog (AUDIO_CAP, fmt, ap);
|
---|
283 | va_end (ap);
|
---|
284 | }
|
---|
285 | #else
|
---|
286 | #if defined NDEBUG && defined __GNUC__
|
---|
287 | #define ldebug(...)
|
---|
288 | #elif defined NDEBUG && defined _MSC_VER
|
---|
289 | #define ldebug __noop
|
---|
290 | #else
|
---|
291 | #ifndef VBOX
|
---|
292 | static void GCC_ATTR ldebug (const char *fmt, ...)
|
---|
293 | #else
|
---|
294 | DECLINLINE(void) GCC_ATTR ldebug (const char *fmt, ...) /* shuts up unused warnings. */
|
---|
295 | #endif
|
---|
296 | {
|
---|
297 | (void) fmt;
|
---|
298 | }
|
---|
299 | #endif
|
---|
300 | #endif
|
---|
301 |
|
---|
302 | #undef GCC_ATTR
|
---|
303 |
|
---|
304 | #define AUDIO_STRINGIFY_(n) #n
|
---|
305 | #define AUDIO_STRINGIFY(n) AUDIO_STRINGIFY_(n)
|
---|
306 |
|
---|
307 | #if defined _MSC_VER || defined __GNUC__
|
---|
308 | #define AUDIO_FUNC __FUNCTION__
|
---|
309 | #else
|
---|
310 | #define AUDIO_FUNC __FILE__ ":" AUDIO_STRINGIFY (__LINE__)
|
---|
311 | #endif
|
---|
312 |
|
---|
313 | DECLCALLBACK(bool) sniffer_run_out (HWVoiceOut *hw, void *pvSamples,
|
---|
314 | unsigned cSamples);
|
---|
315 |
|
---|
316 | /*
|
---|
317 | * Filter interface.
|
---|
318 | */
|
---|
319 | typedef DECLCALLBACK(int) FNAUDIOINPUTCALLBACK(void* pvCtx, uint32_t cbSamples, const void *pvSamples);
|
---|
320 | typedef FNAUDIOINPUTCALLBACK *PFNAUDIOINPUTCALLBACK;
|
---|
321 |
|
---|
322 | int filter_output_intercepted(void);
|
---|
323 | int filter_output_begin(void **ppvOutputCtx, struct audio_pcm_info *pinfo, int samples);
|
---|
324 | void filter_output_end(void *pvOutputCtx);
|
---|
325 |
|
---|
326 | int filter_input_intercepted(void);
|
---|
327 | int filter_input_begin(void **ppvInputCtx, PFNAUDIOINPUTCALLBACK pfnCallback, void *pvCallback, HWVoiceIn *phw, int samples);
|
---|
328 | void filter_input_end(void *pvInputCtx);
|
---|
329 |
|
---|
330 | struct audio_driver *filteraudio_install(struct audio_driver *pDrv, void *pDrvOpaque);
|
---|
331 |
|
---|
332 | #endif /* audio_int.h */
|
---|