VirtualBox

source: vbox/trunk/src/VBox/Devices/Audio/audio_int.h@ 47006

Last change on this file since 47006 was 35487, checked in by vboxsync, 14 years ago

Devices/Audio: fixed fallback to nul host audio driver. Added the fallback to HDA audio device. (xTracker 5404).

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 8.8 KB
Line 
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#define qemu_strfree RTStrFree
44#define asprintf RTStrAPrintf
45
46struct audio_pcm_ops;
47
48typedef enum {
49 AUD_OPT_INT,
50 AUD_OPT_FMT,
51 AUD_OPT_STR,
52 AUD_OPT_BOOL
53} audio_option_tag_e;
54
55struct audio_option {
56 const char *name;
57 audio_option_tag_e tag;
58 void *valp;
59 const char *descr;
60 int *overridenp;
61 int overriden;
62};
63
64struct audio_callback {
65 void *opaque;
66 audio_callback_fn_t fn;
67};
68
69struct audio_pcm_info {
70 int bits;
71 int sign;
72 int freq;
73 int nchannels;
74 int align;
75 int shift;
76 int bytes_per_second;
77 int swap_endianness;
78};
79
80typedef struct SWVoiceCap SWVoiceCap;
81
82typedef struct HWVoiceOut {
83 int enabled;
84 int pending_disable;
85 struct audio_pcm_info info;
86
87 f_sample *clip;
88
89 int rpos;
90 uint64_t ts_helper;
91
92 st_sample_t *mix_buf;
93
94 int samples;
95 LIST_HEAD (sw_out_listhead, SWVoiceOut) sw_head;
96 LIST_HEAD (sw_cap_listhead, SWVoiceCap) cap_head;
97 struct audio_pcm_ops *pcm_ops;
98 LIST_ENTRY (HWVoiceOut) entries;
99} HWVoiceOut;
100
101typedef struct HWVoiceIn {
102 int enabled;
103 struct audio_pcm_info info;
104
105 t_sample *conv;
106
107 int wpos;
108 int total_samples_captured;
109 uint64_t ts_helper;
110
111 st_sample_t *conv_buf;
112
113 int samples;
114 LIST_HEAD (sw_in_listhead, SWVoiceIn) sw_head;
115 struct audio_pcm_ops *pcm_ops;
116 LIST_ENTRY (HWVoiceIn) entries;
117} HWVoiceIn;
118
119struct SWVoiceOut {
120 struct audio_pcm_info info;
121 t_sample *conv;
122 int64_t ratio;
123 st_sample_t *buf;
124 int buf_samples;
125 void *rate;
126 int total_hw_samples_mixed;
127 int active;
128 int empty;
129 HWVoiceOut *hw;
130 char *name;
131 volume_t vol;
132 struct audio_callback callback;
133 LIST_ENTRY (SWVoiceOut) entries;
134};
135
136struct SWVoiceIn {
137 int active;
138 struct audio_pcm_info info;
139 int64_t ratio;
140 void *rate;
141 int total_hw_samples_acquired;
142 st_sample_t *buf;
143 int buf_samples; /* for debugging only */
144 f_sample *clip;
145 HWVoiceIn *hw;
146 char *name;
147 volume_t vol;
148 struct audio_callback callback;
149 LIST_ENTRY (SWVoiceIn) entries;
150};
151
152struct audio_driver {
153 const char *name;
154 const char *descr;
155 struct audio_option *options;
156 void *(*init) (void);
157 void (*fini) (void *);
158 struct audio_pcm_ops *pcm_ops;
159 int can_be_default;
160 int max_voices_out;
161 int max_voices_in;
162 int voice_size_out;
163 int voice_size_in;
164};
165
166struct audio_pcm_ops {
167 int (*init_out)(HWVoiceOut *hw, audsettings_t *as);
168 void (*fini_out)(HWVoiceOut *hw);
169 int (*run_out) (HWVoiceOut *hw);
170 int (*write) (SWVoiceOut *sw, void *buf, int size);
171 int (*ctl_out) (HWVoiceOut *hw, int cmd, ...);
172
173 int (*init_in) (HWVoiceIn *hw, audsettings_t *as);
174 void (*fini_in) (HWVoiceIn *hw);
175 int (*run_in) (HWVoiceIn *hw);
176 int (*read) (SWVoiceIn *sw, void *buf, int size);
177 int (*ctl_in) (HWVoiceIn *hw, int cmd, ...);
178};
179
180struct capture_callback {
181 struct audio_capture_ops ops;
182 void *opaque;
183 LIST_ENTRY (capture_callback) entries;
184};
185
186struct CaptureVoiceOut {
187 HWVoiceOut hw;
188 void *buf;
189 LIST_HEAD (cb_listhead, capture_callback) cb_head;
190 LIST_ENTRY (CaptureVoiceOut) entries;
191};
192
193struct SWVoiceCap {
194 SWVoiceOut sw;
195 CaptureVoiceOut *cap;
196 LIST_ENTRY (SWVoiceCap) entries;
197};
198
199struct AudioState {
200 struct audio_driver *drv;
201 void *drv_opaque;
202
203 QEMUTimer *ts;
204 LIST_HEAD (card_listhead, QEMUSoundCard) card_head;
205 LIST_HEAD (hw_in_listhead, HWVoiceIn) hw_head_in;
206 LIST_HEAD (hw_out_listhead, HWVoiceOut) hw_head_out;
207 LIST_HEAD (cap_listhead, CaptureVoiceOut) cap_head;
208 int nb_hw_voices_out;
209 int nb_hw_voices_in;
210 PPDMDRVINS pDrvIns;
211};
212
213extern struct audio_driver no_audio_driver;
214extern struct audio_driver oss_audio_driver;
215extern struct audio_driver sdl_audio_driver;
216extern struct audio_driver wav_audio_driver;
217extern struct audio_driver fmod_audio_driver;
218extern struct audio_driver alsa_audio_driver;
219extern struct audio_driver pulse_audio_driver;
220extern struct audio_driver coreaudio_audio_driver;
221extern struct audio_driver dsound_audio_driver;
222extern struct audio_driver solaudio_audio_driver;
223extern volume_t nominal_volume;
224#ifdef VBOX
225extern volume_t pcm_out_volume;
226extern volume_t pcm_in_volume;
227#endif
228
229uint64_t audio_get_clock (void);
230uint64_t audio_get_ticks_per_sec (void);
231
232void audio_pcm_init_info (struct audio_pcm_info *info, audsettings_t *as);
233void audio_pcm_info_clear_buf (struct audio_pcm_info *info, void *buf, int len);
234
235int audio_pcm_sw_write (SWVoiceOut *sw, void *buf, int len);
236int audio_pcm_hw_get_live_in (HWVoiceIn *hw);
237
238int audio_pcm_sw_read (SWVoiceIn *sw, void *buf, int len);
239int audio_pcm_hw_get_live_out (HWVoiceOut *hw);
240int audio_pcm_hw_get_live_out2 (HWVoiceOut *hw, int *nb_live);
241
242int audio_bug (const char *funcname, int cond);
243void *audio_calloc (const char *funcname, int nmemb, size_t size);
244
245#define VOICE_ENABLE 1
246#define VOICE_DISABLE 2
247
248static inline int audio_ring_dist (int dst, int src, int len)
249{
250 return (dst >= src) ? (dst - src) : (len - src + dst);
251}
252
253#if defined __GNUC__ && !defined VBOX /* VBox: oh, please, just shut up. */
254#define GCC_ATTR __attribute__ ((__unused__, __format__ (__printf__, 1, 2)))
255#if __STDC_VERSION__ > 199901L
256#define INIT_FIELD(f) . f
257#else
258#define INIT_FIELD(f) /**/
259#endif
260#define GCC_FMT_ATTR(n, m) __attribute__ ((__format__ (__printf__, n, m)))
261#else
262#define GCC_ATTR /**/
263#define INIT_FIELD(f) /**/
264#define GCC_FMT_ATTR(n, m)
265#endif
266
267#ifndef VBOX
268static void GCC_ATTR dolog (const char *fmt, ...)
269#else
270DECLINLINE(void) GCC_ATTR dolog (const char *fmt, ...) /* shuts up unused warnings. */
271#endif
272{
273 va_list ap;
274
275 va_start (ap, fmt);
276 AUD_vlog (AUDIO_CAP, fmt, ap);
277 va_end (ap);
278}
279
280#ifdef DEBUG
281DECLINLINE(void) GCC_ATTR ldebug (const char *fmt, ...)
282{
283 va_list ap;
284
285 va_start (ap, fmt);
286 AUD_vlog (AUDIO_CAP, fmt, ap);
287 va_end (ap);
288}
289#else
290#if defined NDEBUG && defined __GNUC__
291#define ldebug(...)
292#elif defined NDEBUG && defined _MSC_VER
293#define ldebug __noop
294#else
295#ifndef VBOX
296static void GCC_ATTR ldebug (const char *fmt, ...)
297#else
298DECLINLINE(void) GCC_ATTR ldebug (const char *fmt, ...) /* shuts up unused warnings. */
299#endif
300{
301 (void) fmt;
302}
303#endif
304#endif
305
306#undef GCC_ATTR
307
308#define AUDIO_STRINGIFY_(n) #n
309#define AUDIO_STRINGIFY(n) AUDIO_STRINGIFY_(n)
310
311#if defined _MSC_VER || defined __GNUC__
312#define AUDIO_FUNC __FUNCTION__
313#else
314#define AUDIO_FUNC __FILE__ ":" AUDIO_STRINGIFY (__LINE__)
315#endif
316
317DECLCALLBACK(bool) sniffer_run_out (HWVoiceOut *hw, void *pvSamples,
318 unsigned cSamples);
319
320/*
321 * Filter interface.
322 */
323typedef DECLCALLBACK(int) FNAUDIOINPUTCALLBACK(void* pvCtx, uint32_t cbSamples, const void *pvSamples);
324typedef FNAUDIOINPUTCALLBACK *PFNAUDIOINPUTCALLBACK;
325
326int filter_output_intercepted(void);
327int filter_output_begin(void **ppvOutputCtx, struct audio_pcm_info *pinfo, int samples);
328void filter_output_end(void *pvOutputCtx);
329
330int filter_input_intercepted(void);
331int filter_input_begin(void **ppvInputCtx, PFNAUDIOINPUTCALLBACK pfnCallback, void *pvCallback, HWVoiceIn *phw, int samples);
332void filter_input_end(void *pvInputCtx);
333
334struct audio_driver *filteraudio_install(struct audio_driver *pDrv, void *pDrvOpaque);
335int filteraudio_is_host_voice_in_ok(struct audio_driver *pDrv, HWVoiceIn *phw);
336int filteraudio_is_host_voice_out_ok(struct audio_driver *pDrv, HWVoiceOut *phw);
337
338#endif /* audio_int.h */
Note: See TracBrowser for help on using the repository browser.

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette