VirtualBox

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

最後變更 在這個檔案從35050是 35050,由 vboxsync 提交於 14 年 前

Audio: uses RTStrFree for strings allocated via RTStrDup.

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

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