1 | /** @file
|
---|
2 | * PDM - Pluggable Device Manager, audio interfaces.
|
---|
3 | */
|
---|
4 |
|
---|
5 | /*
|
---|
6 | * Copyright (C) 2006-2017 Oracle Corporation
|
---|
7 | *
|
---|
8 | * This file is part of VirtualBox Open Source Edition (OSE), as
|
---|
9 | * available from http://www.virtualbox.org. This file is free software;
|
---|
10 | * you can redistribute it and/or modify it under the terms of the GNU
|
---|
11 | * General Public License (GPL) as published by the Free Software
|
---|
12 | * Foundation, in version 2 as it comes in the "COPYING" file of the
|
---|
13 | * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
|
---|
14 | * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
|
---|
15 | *
|
---|
16 | * The contents of this file may alternatively be used under the terms
|
---|
17 | * of the Common Development and Distribution License Version 1.0
|
---|
18 | * (CDDL) only, as it comes in the "COPYING.CDDL" file of the
|
---|
19 | * VirtualBox OSE distribution, in which case the provisions of the
|
---|
20 | * CDDL are applicable instead of those of the GPL.
|
---|
21 | *
|
---|
22 | * You may elect to license modified versions of this file under the
|
---|
23 | * terms and conditions of either the GPL or the CDDL or both.
|
---|
24 | */
|
---|
25 |
|
---|
26 | /**
|
---|
27 | * == Audio architecture overview
|
---|
28 | *
|
---|
29 | * The audio architecture mainly consists of two PDM interfaces, PDMAUDIOCONNECTOR
|
---|
30 | * and PDMIHOSTAUDIO.
|
---|
31 | *
|
---|
32 | * The PDMAUDIOCONNECTOR interface is responsible of connecting a device emulation, such
|
---|
33 | * as SB16, AC'97 and HDA to one or multiple audio backend(s). Its API abstracts audio
|
---|
34 | * stream handling and I/O functions, device enumeration and so on.
|
---|
35 | *
|
---|
36 | * The PDMIHOSTAUDIO interface must be implemented by all audio backends to provide an
|
---|
37 | * abstract and common way of accessing needed functions, such as transferring output audio
|
---|
38 | * data for playing audio or recording input from the host.
|
---|
39 | *
|
---|
40 | * A device emulation can have one or more LUNs attached to it, whereas these LUNs in turn
|
---|
41 | * then all have their own PDMIAUDIOCONNECTOR, making it possible to connect multiple backends
|
---|
42 | * to a certain device emulation stream (multiplexing).
|
---|
43 | *
|
---|
44 | * An audio backend's job is to record and/or play audio data (depending on its capabilities).
|
---|
45 | * It highly depends on the host it's running on and needs very specific (host-OS-dependent) code.
|
---|
46 | * The backend itself only has very limited ways of accessing and/or communicating with the
|
---|
47 | * PDMIAUDIOCONNECTOR interface via callbacks, but never directly with the device emulation or
|
---|
48 | * other parts of the audio sub system.
|
---|
49 | *
|
---|
50 | *
|
---|
51 | * == Mixing
|
---|
52 | *
|
---|
53 | * The AUDIOMIXER API is optionally available to create and manage virtual audio mixers.
|
---|
54 | * Such an audio mixer in turn then can be used by the device emulation code to manage all
|
---|
55 | * the multiplexing to/from the connected LUN audio streams.
|
---|
56 | *
|
---|
57 | * Currently only input and output stream are supported. Duplex stream are not supported yet.
|
---|
58 | *
|
---|
59 | * This also is handy if certain LUN audio streams should be added or removed during runtime.
|
---|
60 | *
|
---|
61 | * To create a group of either input or output streams the AUDMIXSINK API can be used.
|
---|
62 | *
|
---|
63 | * For example: The device emulation has one hardware output stream (HW0), and that output
|
---|
64 | * stream shall be available to all connected LUN backends. For that to happen,
|
---|
65 | * an AUDMIXSINK sink has to be created and attached to the device's AUDIOMIXER object.
|
---|
66 | *
|
---|
67 | * As every LUN has its own AUDMIXSTREAM object, adding all those objects to the
|
---|
68 | * just created audio mixer sink will do the job.
|
---|
69 | *
|
---|
70 | * Note: The AUDIOMIXER API is purely optional and is not used by all currently implemented
|
---|
71 | * device emulations (e.g. SB16).
|
---|
72 | *
|
---|
73 | *
|
---|
74 | * == Data processing
|
---|
75 | *
|
---|
76 | * Audio input / output data gets handed-off to/from the device emulation in an unmodified
|
---|
77 | * - that is, raw - way. The actual audio frame / sample conversion is done via the PDMAUDIOMIXBUF API.
|
---|
78 | *
|
---|
79 | * This concentrates the audio data processing in one place and makes it easier to test / benchmark
|
---|
80 | * such code.
|
---|
81 | *
|
---|
82 | * A PDMAUDIOFRAME is the internal representation of a single audio frame, which consists of a single left
|
---|
83 | * and right audio sample in time. Only mono (1) and stereo (2) channel(s) currently are supported.
|
---|
84 | *
|
---|
85 | *
|
---|
86 | * == Diagram
|
---|
87 | *
|
---|
88 | * +-------------------------+
|
---|
89 | * +-------------------------+ +-------------------------+ +-------------------+
|
---|
90 | * |PDMAUDIOSTREAM | |PDMAUDIOCONNECTOR | + ++|LUN |
|
---|
91 | * |-------------------------| |-------------------------| | |||-------------------|
|
---|
92 | * |PDMAUDIOMIXBUF |+------>|PDMAUDIOSTREAM Host |+---|-|||PDMIAUDIOCONNECTOR |
|
---|
93 | * |PDMAUDIOSTREAMCFG |+------>|PDMAUDIOSTREAM Guest | | |||AUDMIXSTREAM |
|
---|
94 | * | | |Device capabilities | | ||| |
|
---|
95 | * | | |Device configuration | | ||| |
|
---|
96 | * | | | | | ||| |
|
---|
97 | * | | +|PDMIHOSTAUDIO | | ||| |
|
---|
98 | * | | ||+-----------------------+| | ||+-------------------+
|
---|
99 | * +-------------------------+ |||Backend storage space || | ||
|
---|
100 | * ||+-----------------------+| | ||
|
---|
101 | * |+-------------------------+ | ||
|
---|
102 | * | | ||
|
---|
103 | * +---------------------+ | | ||
|
---|
104 | * |PDMIHOSTAUDIO | | | ||
|
---|
105 | * |+--------------+ | | +-------------------+ | || +-------------+
|
---|
106 | * ||DirectSound | | | |AUDMIXSINK | | || |AUDIOMIXER |
|
---|
107 | * |+--------------+ | | |-------------------| | || |-------------|
|
---|
108 | * | | | |AUDMIXSTREAM0 |+---|-||----->|AUDMIXSINK0 |
|
---|
109 | * |+--------------+ | | |AUDMIXSTREAM1 |+---|-||----->|AUDMIXSINK1 |
|
---|
110 | * ||PulseAudio | | | |AUDMIXSTREAMn |+---|-||----->|AUDMIXSINKn |
|
---|
111 | * |+--------------+ |+----------+ +-------------------+ | || +-------------+
|
---|
112 | * | | | ||
|
---|
113 | * |+--------------+ | | ||
|
---|
114 | * ||Core Audio | | | ||
|
---|
115 | * |+--------------+ | | ||
|
---|
116 | * | | | ||
|
---|
117 | * | | | ||+----------------------------------+
|
---|
118 | * | | | |||Device (SB16 / AC'97 / HDA) |
|
---|
119 | * | | | |||----------------------------------|
|
---|
120 | * +---------------------+ | |||AUDIOMIXER (Optional) |
|
---|
121 | * | |||AUDMIXSINK0 (Optional) |
|
---|
122 | * | |||AUDMIXSINK1 (Optional) |
|
---|
123 | * | |||AUDMIXSINKn (Optional) |
|
---|
124 | * | ||| |
|
---|
125 | * | |+|LUN0 |
|
---|
126 | * | ++|LUN1 |
|
---|
127 | * +--+|LUNn |
|
---|
128 | * | |
|
---|
129 | * | |
|
---|
130 | * | |
|
---|
131 | * +----------------------------------+
|
---|
132 | */
|
---|
133 |
|
---|
134 | #ifndef ___VBox_vmm_pdmaudioifs_h
|
---|
135 | #define ___VBox_vmm_pdmaudioifs_h
|
---|
136 |
|
---|
137 | #include <iprt/circbuf.h>
|
---|
138 | #include <iprt/list.h>
|
---|
139 | #include <iprt/path.h>
|
---|
140 |
|
---|
141 | #include <VBox/types.h>
|
---|
142 | #ifdef VBOX_WITH_STATISTICS
|
---|
143 | # include <VBox/vmm/stam.h>
|
---|
144 | #endif
|
---|
145 |
|
---|
146 | /** @defgroup grp_pdm_ifs_audio PDM Audio Interfaces
|
---|
147 | * @ingroup grp_pdm_interfaces
|
---|
148 | * @{
|
---|
149 | */
|
---|
150 |
|
---|
151 | #ifndef VBOX_AUDIO_DEBUG_DUMP_PCM_DATA_PATH
|
---|
152 | # ifdef RT_OS_WINDOWS
|
---|
153 | # define VBOX_AUDIO_DEBUG_DUMP_PCM_DATA_PATH "c:\\temp\\"
|
---|
154 | # else
|
---|
155 | # define VBOX_AUDIO_DEBUG_DUMP_PCM_DATA_PATH "/tmp/"
|
---|
156 | # endif
|
---|
157 | #endif
|
---|
158 |
|
---|
159 | /** PDM audio driver instance flags. */
|
---|
160 | typedef uint32_t PDMAUDIODRVFLAGS;
|
---|
161 |
|
---|
162 | /** No flags set. */
|
---|
163 | #define PDMAUDIODRVFLAGS_NONE 0
|
---|
164 | /** Marks a primary audio driver which is critical
|
---|
165 | * when running the VM. */
|
---|
166 | #define PDMAUDIODRVFLAGS_PRIMARY RT_BIT(0)
|
---|
167 |
|
---|
168 | /**
|
---|
169 | * Audio format in signed or unsigned variants.
|
---|
170 | */
|
---|
171 | typedef enum PDMAUDIOFMT
|
---|
172 | {
|
---|
173 | /** Invalid format, do not use. */
|
---|
174 | PDMAUDIOFMT_INVALID,
|
---|
175 | /** 8-bit, unsigned. */
|
---|
176 | PDMAUDIOFMT_U8,
|
---|
177 | /** 8-bit, signed. */
|
---|
178 | PDMAUDIOFMT_S8,
|
---|
179 | /** 16-bit, unsigned. */
|
---|
180 | PDMAUDIOFMT_U16,
|
---|
181 | /** 16-bit, signed. */
|
---|
182 | PDMAUDIOFMT_S16,
|
---|
183 | /** 32-bit, unsigned. */
|
---|
184 | PDMAUDIOFMT_U32,
|
---|
185 | /** 32-bit, signed. */
|
---|
186 | PDMAUDIOFMT_S32,
|
---|
187 | /** Hack to blow the type up to 32-bit. */
|
---|
188 | PDMAUDIOFMT_32BIT_HACK = 0x7fffffff
|
---|
189 | } PDMAUDIOFMT;
|
---|
190 |
|
---|
191 | /**
|
---|
192 | * Audio direction.
|
---|
193 | */
|
---|
194 | typedef enum PDMAUDIODIR
|
---|
195 | {
|
---|
196 | /** Unknown direction. */
|
---|
197 | PDMAUDIODIR_UNKNOWN = 0,
|
---|
198 | /** Input. */
|
---|
199 | PDMAUDIODIR_IN = 1,
|
---|
200 | /** Output. */
|
---|
201 | PDMAUDIODIR_OUT = 2,
|
---|
202 | /** Duplex handling. */
|
---|
203 | PDMAUDIODIR_ANY = 3,
|
---|
204 | /** Hack to blow the type up to 32-bit. */
|
---|
205 | PDMAUDIODIR_32BIT_HACK = 0x7fffffff
|
---|
206 | } PDMAUDIODIR;
|
---|
207 |
|
---|
208 | /** Device latency spec in milliseconds (ms). */
|
---|
209 | typedef uint32_t PDMAUDIODEVLATSPECMS;
|
---|
210 |
|
---|
211 | /** Device latency spec in seconds (s). */
|
---|
212 | typedef uint32_t PDMAUDIODEVLATSPECSEC;
|
---|
213 |
|
---|
214 | /** Audio device flags. Use with PDMAUDIODEV_FLAG_ flags. */
|
---|
215 | typedef uint32_t PDMAUDIODEVFLAG;
|
---|
216 |
|
---|
217 | /** No flags set. */
|
---|
218 | #define PDMAUDIODEV_FLAGS_NONE 0
|
---|
219 | /** The device marks the default device within the host OS. */
|
---|
220 | #define PDMAUDIODEV_FLAGS_DEFAULT RT_BIT(0)
|
---|
221 | /** The device can be removed at any time and we have to deal with it. */
|
---|
222 | #define PDMAUDIODEV_FLAGS_HOTPLUG RT_BIT(1)
|
---|
223 | /** The device is known to be buggy and needs special treatment. */
|
---|
224 | #define PDMAUDIODEV_FLAGS_BUGGY RT_BIT(2)
|
---|
225 | /** Ignore the device, no matter what. */
|
---|
226 | #define PDMAUDIODEV_FLAGS_IGNORE RT_BIT(3)
|
---|
227 | /** The device is present but marked as locked by some other application. */
|
---|
228 | #define PDMAUDIODEV_FLAGS_LOCKED RT_BIT(4)
|
---|
229 | /** The device is present but not in an alive state (dead). */
|
---|
230 | #define PDMAUDIODEV_FLAGS_DEAD RT_BIT(5)
|
---|
231 |
|
---|
232 | /**
|
---|
233 | * Audio device type.
|
---|
234 | */
|
---|
235 | typedef enum PDMAUDIODEVICETYPE
|
---|
236 | {
|
---|
237 | /** Unknown device type. This is the default. */
|
---|
238 | PDMAUDIODEVICETYPE_UNKNOWN = 0,
|
---|
239 | /** Dummy device; for backends which are not able to report
|
---|
240 | * actual device information (yet). */
|
---|
241 | PDMAUDIODEVICETYPE_DUMMY,
|
---|
242 | /** The device is built into the host (non-removable). */
|
---|
243 | PDMAUDIODEVICETYPE_BUILTIN,
|
---|
244 | /** The device is an (external) USB device. */
|
---|
245 | PDMAUDIODEVICETYPE_USB,
|
---|
246 | /** Hack to blow the type up to 32-bit. */
|
---|
247 | PDMAUDIODEVICETYPE_32BIT_HACK = 0x7fffffff
|
---|
248 | } PDMAUDIODEVICETYPE;
|
---|
249 |
|
---|
250 | /**
|
---|
251 | * Audio device instance data.
|
---|
252 | */
|
---|
253 | typedef struct PDMAUDIODEVICE
|
---|
254 | {
|
---|
255 | /** List node. */
|
---|
256 | RTLISTNODE Node;
|
---|
257 | /** Friendly name of the device, if any. */
|
---|
258 | char szName[64];
|
---|
259 | /** The device type. */
|
---|
260 | PDMAUDIODEVICETYPE enmType;
|
---|
261 | /** Reference count indicating how many audio streams currently are relying on this device. */
|
---|
262 | uint8_t cRefCount;
|
---|
263 | /** Usage of the device. */
|
---|
264 | PDMAUDIODIR enmUsage;
|
---|
265 | /** Device flags. */
|
---|
266 | PDMAUDIODEVFLAG fFlags;
|
---|
267 | /** Maximum number of input audio channels the device supports. */
|
---|
268 | uint8_t cMaxInputChannels;
|
---|
269 | /** Maximum number of output audio channels the device supports. */
|
---|
270 | uint8_t cMaxOutputChannels;
|
---|
271 | /** Additional data which might be relevant for the current context. */
|
---|
272 | void *pvData;
|
---|
273 | /** Size of the additional data. */
|
---|
274 | size_t cbData;
|
---|
275 | /** Device type union, based on enmType. */
|
---|
276 | union
|
---|
277 | {
|
---|
278 | /** USB type specifics. */
|
---|
279 | struct
|
---|
280 | {
|
---|
281 | /** Vendor ID. */
|
---|
282 | int16_t VID;
|
---|
283 | /** Product ID. */
|
---|
284 | int16_t PID;
|
---|
285 | } USB;
|
---|
286 | } Type;
|
---|
287 | } PDMAUDIODEVICE, *PPDMAUDIODEVICE;
|
---|
288 |
|
---|
289 | /**
|
---|
290 | * Structure for keeping an audio device enumeration.
|
---|
291 | */
|
---|
292 | typedef struct PDMAUDIODEVICEENUM
|
---|
293 | {
|
---|
294 | /** Number of audio devices in the list. */
|
---|
295 | uint16_t cDevices;
|
---|
296 | /** List of audio devices. */
|
---|
297 | RTLISTANCHOR lstDevices;
|
---|
298 | } PDMAUDIODEVICEENUM, *PPDMAUDIODEVICEENUM;
|
---|
299 |
|
---|
300 | /**
|
---|
301 | * Audio (static) configuration of an audio host backend.
|
---|
302 | */
|
---|
303 | typedef struct PDMAUDIOBACKENDCFG
|
---|
304 | {
|
---|
305 | /** Size (in bytes) of the host backend's audio output stream structure. */
|
---|
306 | size_t cbStreamOut;
|
---|
307 | /** Size (in bytes) of the host backend's audio input stream structure. */
|
---|
308 | size_t cbStreamIn;
|
---|
309 | /** Number of concurrent output streams supported on the host.
|
---|
310 | * UINT32_MAX for unlimited concurrent streams, 0 if no concurrent input streams are supported. */
|
---|
311 | uint32_t cMaxStreamsOut;
|
---|
312 | /** Number of concurrent input streams supported on the host.
|
---|
313 | * UINT32_MAX for unlimited concurrent streams, 0 if no concurrent input streams are supported. */
|
---|
314 | uint32_t cMaxStreamsIn;
|
---|
315 | } PDMAUDIOBACKENDCFG, *PPDMAUDIOBACKENDCFG;
|
---|
316 |
|
---|
317 | /**
|
---|
318 | * A single audio frame.
|
---|
319 | *
|
---|
320 | * Currently only two (2) channels, left and right, are supported.
|
---|
321 | *
|
---|
322 | * Note: When changing this structure, make sure to also handle
|
---|
323 | * VRDP's input / output processing in DrvAudioVRDE, as VRDP
|
---|
324 | * expects audio data in st_sample_t format (historical reasons)
|
---|
325 | * which happens to be the same as PDMAUDIOFRAME for now.
|
---|
326 | */
|
---|
327 | typedef struct PDMAUDIOFRAME
|
---|
328 | {
|
---|
329 | /** Left channel. */
|
---|
330 | int64_t i64LSample;
|
---|
331 | /** Right channel. */
|
---|
332 | int64_t i64RSample;
|
---|
333 | } PDMAUDIOFRAME;
|
---|
334 | /** Pointer to a single (stereo) audio frame. */
|
---|
335 | typedef PDMAUDIOFRAME *PPDMAUDIOFRAME;
|
---|
336 | /** Pointer to a const single (stereo) audio frame. */
|
---|
337 | typedef PDMAUDIOFRAME const *PCPDMAUDIOFRAME;
|
---|
338 |
|
---|
339 | typedef enum PDMAUDIOENDIANNESS
|
---|
340 | {
|
---|
341 | /** The usual invalid endian. */
|
---|
342 | PDMAUDIOENDIANNESS_INVALID,
|
---|
343 | /** Little endian. */
|
---|
344 | PDMAUDIOENDIANNESS_LITTLE,
|
---|
345 | /** Bit endian. */
|
---|
346 | PDMAUDIOENDIANNESS_BIG,
|
---|
347 | /** Endianness doesn't have a meaning in the context. */
|
---|
348 | PDMAUDIOENDIANNESS_NA,
|
---|
349 | /** The end of the valid endian values (exclusive). */
|
---|
350 | PDMAUDIOENDIANNESS_END,
|
---|
351 | /** Hack to blow the type up to 32-bit. */
|
---|
352 | PDMAUDIOENDIANNESS_32BIT_HACK = 0x7fffffff
|
---|
353 | } PDMAUDIOENDIANNESS;
|
---|
354 |
|
---|
355 | /**
|
---|
356 | * Audio playback destinations.
|
---|
357 | */
|
---|
358 | typedef enum PDMAUDIOPLAYBACKDEST
|
---|
359 | {
|
---|
360 | /** Unknown destination. */
|
---|
361 | PDMAUDIOPLAYBACKDEST_UNKNOWN = 0,
|
---|
362 | /** Front channel. */
|
---|
363 | PDMAUDIOPLAYBACKDEST_FRONT,
|
---|
364 | /** Center / LFE (Subwoofer) channel. */
|
---|
365 | PDMAUDIOPLAYBACKDEST_CENTER_LFE,
|
---|
366 | /** Rear channel. */
|
---|
367 | PDMAUDIOPLAYBACKDEST_REAR,
|
---|
368 | /** Hack to blow the type up to 32-bit. */
|
---|
369 | PDMAUDIOPLAYBACKDEST_32BIT_HACK = 0x7fffffff
|
---|
370 | } PDMAUDIOPLAYBACKDEST;
|
---|
371 |
|
---|
372 | /**
|
---|
373 | * Audio recording sources.
|
---|
374 | */
|
---|
375 | typedef enum PDMAUDIORECSOURCE
|
---|
376 | {
|
---|
377 | /** Unknown recording source. */
|
---|
378 | PDMAUDIORECSOURCE_UNKNOWN = 0,
|
---|
379 | /** Microphone-In. */
|
---|
380 | PDMAUDIORECSOURCE_MIC,
|
---|
381 | /** CD. */
|
---|
382 | PDMAUDIORECSOURCE_CD,
|
---|
383 | /** Video-In. */
|
---|
384 | PDMAUDIORECSOURCE_VIDEO,
|
---|
385 | /** AUX. */
|
---|
386 | PDMAUDIORECSOURCE_AUX,
|
---|
387 | /** Line-In. */
|
---|
388 | PDMAUDIORECSOURCE_LINE,
|
---|
389 | /** Phone-In. */
|
---|
390 | PDMAUDIORECSOURCE_PHONE,
|
---|
391 | /** Hack to blow the type up to 32-bit. */
|
---|
392 | PDMAUDIORECSOURCE_32BIT_HACK = 0x7fffffff
|
---|
393 | } PDMAUDIORECSOURCE;
|
---|
394 |
|
---|
395 | /**
|
---|
396 | * Audio stream (data) layout.
|
---|
397 | */
|
---|
398 | typedef enum PDMAUDIOSTREAMLAYOUT
|
---|
399 | {
|
---|
400 | /** Unknown access type; do not use. */
|
---|
401 | PDMAUDIOSTREAMLAYOUT_UNKNOWN = 0,
|
---|
402 | /** Non-interleaved access, that is, consecutive
|
---|
403 | * access to the data. */
|
---|
404 | PDMAUDIOSTREAMLAYOUT_NON_INTERLEAVED,
|
---|
405 | /** Interleaved access, where the data can be
|
---|
406 | * mixed together with data of other audio streams. */
|
---|
407 | PDMAUDIOSTREAMLAYOUT_INTERLEAVED,
|
---|
408 | /** Complex layout, which does not fit into the
|
---|
409 | * interleaved / non-interleaved layouts. */
|
---|
410 | PDMAUDIOSTREAMLAYOUT_COMPLEX,
|
---|
411 | /** Raw (pass through) data, with no data layout processing done.
|
---|
412 | *
|
---|
413 | * This means that this stream will operate on PDMAUDIOFRAME data
|
---|
414 | * directly. Don't use this if you don't have to. */
|
---|
415 | PDMAUDIOSTREAMLAYOUT_RAW,
|
---|
416 | /** Hack to blow the type up to 32-bit. */
|
---|
417 | PDMAUDIOSTREAMLAYOUT_32BIT_HACK = 0x7fffffff
|
---|
418 | } PDMAUDIOSTREAMLAYOUT, *PPDMAUDIOSTREAMLAYOUT;
|
---|
419 |
|
---|
420 | /** No stream channel data flags defined. */
|
---|
421 | #define PDMAUDIOSTREAMCHANNELDATA_FLAG_NONE 0
|
---|
422 |
|
---|
423 | /**
|
---|
424 | * Structure for keeping a stream channel data block around.
|
---|
425 | */
|
---|
426 | typedef struct PDMAUDIOSTREAMCHANNELDATA
|
---|
427 | {
|
---|
428 | /** Circular buffer for the channel data. */
|
---|
429 | PRTCIRCBUF pCircBuf;
|
---|
430 | size_t cbAcq;
|
---|
431 | /** Channel data flags. */
|
---|
432 | uint32_t fFlags;
|
---|
433 | } PDMAUDIOSTREAMCHANNELDATA, *PPDMAUDIOSTREAMCHANNELDATA;
|
---|
434 |
|
---|
435 | /**
|
---|
436 | * Structure for a single channel of an audio stream.
|
---|
437 | * An audio stream consists of one or multiple channels,
|
---|
438 | * depending on the configuration.
|
---|
439 | */
|
---|
440 | typedef struct PDMAUDIOSTREAMCHANNEL
|
---|
441 | {
|
---|
442 | /** Channel ID. */
|
---|
443 | uint8_t uChannel;
|
---|
444 | /** Step size (in bytes) to the channel's next frame. */
|
---|
445 | size_t cbStep;
|
---|
446 | /** Frame size (in bytes) of this channel. */
|
---|
447 | size_t cbFrame;
|
---|
448 | /** Offset (in bytes) to first frame in the data block. */
|
---|
449 | size_t cbFirst;
|
---|
450 | /** Currente offset (in bytes) in the data stream. */
|
---|
451 | size_t cbOff;
|
---|
452 | /** Associated data buffer. */
|
---|
453 | PDMAUDIOSTREAMCHANNELDATA Data;
|
---|
454 | } PDMAUDIOSTREAMCHANNEL, *PPDMAUDIOSTREAMCHANNEL;
|
---|
455 |
|
---|
456 | /**
|
---|
457 | * Union for keeping an audio stream destination or source.
|
---|
458 | */
|
---|
459 | typedef union PDMAUDIODESTSOURCE
|
---|
460 | {
|
---|
461 | /** Desired playback destination (for an output stream). */
|
---|
462 | PDMAUDIOPLAYBACKDEST Dest;
|
---|
463 | /** Desired recording source (for an input stream). */
|
---|
464 | PDMAUDIORECSOURCE Source;
|
---|
465 | } PDMAUDIODESTSOURCE, *PPDMAUDIODESTSOURCE;
|
---|
466 |
|
---|
467 | /**
|
---|
468 | * Properties of audio streams for host/guest
|
---|
469 | * for in or out directions.
|
---|
470 | */
|
---|
471 | typedef struct PDMAUDIOPCMPROPS
|
---|
472 | {
|
---|
473 | /** Sample width. Bits per sample. */
|
---|
474 | uint8_t cBits;
|
---|
475 | /** Signed or unsigned sample. */
|
---|
476 | bool fSigned;
|
---|
477 | /** Number of audio channels. */
|
---|
478 | uint8_t cChannels;
|
---|
479 | /** Sample frequency in Hertz (Hz). */
|
---|
480 | uint32_t uHz;
|
---|
481 | /** Shift count used for faster calculation of various
|
---|
482 | * values, such as the alignment, bytes to frames and so on.
|
---|
483 | * Depends on number of stream channels and the stream format
|
---|
484 | * being used.
|
---|
485 | *
|
---|
486 | ** @todo Use some RTAsmXXX functions instead?
|
---|
487 | */
|
---|
488 | uint8_t cShift;
|
---|
489 | /** Whether the endianness is swapped or not. */
|
---|
490 | bool fSwapEndian;
|
---|
491 | } PDMAUDIOPCMPROPS, *PPDMAUDIOPCMPROPS;
|
---|
492 |
|
---|
493 | /** Calculates the cShift value of given sample bits and audio channels.
|
---|
494 | * Note: Does only support mono/stereo channels for now. */
|
---|
495 | #define PDMAUDIOPCMPROPS_MAKE_SHIFT_PARMS(cBits, cChannels) ((cChannels == 2) + (cBits / 16))
|
---|
496 | /** Calculates the cShift value of a PDMAUDIOPCMPROPS structure. */
|
---|
497 | #define PDMAUDIOPCMPROPS_MAKE_SHIFT(pProps) PDMAUDIOPCMPROPS_MAKE_SHIFT_PARMS((pProps)->cBits, (pProps)->cChannels)
|
---|
498 | /** Converts (audio) frames to bytes.
|
---|
499 | * Needs the cShift value set correctly, using PDMAUDIOPCMPROPS_MAKE_SHIFT. */
|
---|
500 | #define PDMAUDIOPCMPROPS_F2B(pProps, frames) ((frames) << (pProps)->cShift)
|
---|
501 | /** Converts bytes to (audio) frames.
|
---|
502 | * Needs the cShift value set correctly, using PDMAUDIOPCMPROPS_MAKE_SHIFT. */
|
---|
503 | #define PDMAUDIOPCMPROPS_B2F(pProps, cb) (cb >> (pProps)->cShift)
|
---|
504 |
|
---|
505 | /**
|
---|
506 | * Structure for keeping an audio stream configuration.
|
---|
507 | */
|
---|
508 | typedef struct PDMAUDIOSTREAMCFG
|
---|
509 | {
|
---|
510 | /** Friendly name of the stream. */
|
---|
511 | char szName[64];
|
---|
512 | /** Direction of the stream. */
|
---|
513 | PDMAUDIODIR enmDir;
|
---|
514 | /** Destination / source indicator, depending on enmDir. */
|
---|
515 | PDMAUDIODESTSOURCE DestSource;
|
---|
516 | /** The stream's PCM properties. */
|
---|
517 | PDMAUDIOPCMPROPS Props;
|
---|
518 | /** The stream's audio data layout.
|
---|
519 | * This indicates how the audio data buffers to/from the backend is being layouted.
|
---|
520 | *
|
---|
521 | * Currently, the following layouts are supported by the audio connector:
|
---|
522 | *
|
---|
523 | * PDMAUDIOSTREAMLAYOUT_NON_INTERLEAVED:
|
---|
524 | * One stream at once. The consecutive audio data is exactly in the format and frame width
|
---|
525 | * like defined in the PCM properties. This is the default.
|
---|
526 | *
|
---|
527 | * PDMAUDIOSTREAMLAYOUT_RAW:
|
---|
528 | * Can be one or many streams at once, depending on the stream's mixing buffer setup.
|
---|
529 | * The audio data will get handled as PDMAUDIOFRAME frames without any modification done. */
|
---|
530 | PDMAUDIOSTREAMLAYOUT enmLayout;
|
---|
531 | /** Hint about the optimal frame buffer size (in audio frames).
|
---|
532 | * 0 if no hint is given. */
|
---|
533 | uint32_t cFrameBufferHint;
|
---|
534 | } PDMAUDIOSTREAMCFG, *PPDMAUDIOSTREAMCFG;
|
---|
535 |
|
---|
536 | /** Converts (audio) frames to bytes. */
|
---|
537 | #define PDMAUDIOSTREAMCFG_F2B(pCfg, frames) ((frames) << (pCfg->Props).cShift)
|
---|
538 | /** Converts bytes to (audio) frames. */
|
---|
539 | #define PDMAUDIOSTREAMCFG_B2F(pCfg, cb) (cb >> (pCfg->Props).cShift)
|
---|
540 |
|
---|
541 | #if defined(RT_LITTLE_ENDIAN)
|
---|
542 | # define PDMAUDIOHOSTENDIANNESS PDMAUDIOENDIANNESS_LITTLE
|
---|
543 | #elif defined(RT_BIG_ENDIAN)
|
---|
544 | # define PDMAUDIOHOSTENDIANNESS PDMAUDIOENDIANNESS_BIG
|
---|
545 | #else
|
---|
546 | # error "Port me!"
|
---|
547 | #endif
|
---|
548 |
|
---|
549 | /**
|
---|
550 | * Audio mixer controls.
|
---|
551 | */
|
---|
552 | typedef enum PDMAUDIOMIXERCTL
|
---|
553 | {
|
---|
554 | /** Unknown mixer control. */
|
---|
555 | PDMAUDIOMIXERCTL_UNKNOWN = 0,
|
---|
556 | /** Master volume. */
|
---|
557 | PDMAUDIOMIXERCTL_VOLUME_MASTER,
|
---|
558 | /** Front. */
|
---|
559 | PDMAUDIOMIXERCTL_FRONT,
|
---|
560 | /** Center / LFE (Subwoofer). */
|
---|
561 | PDMAUDIOMIXERCTL_CENTER_LFE,
|
---|
562 | /** Rear. */
|
---|
563 | PDMAUDIOMIXERCTL_REAR,
|
---|
564 | /** Line-In. */
|
---|
565 | PDMAUDIOMIXERCTL_LINE_IN,
|
---|
566 | /** Microphone-In. */
|
---|
567 | PDMAUDIOMIXERCTL_MIC_IN,
|
---|
568 | /** Hack to blow the type up to 32-bit. */
|
---|
569 | PDMAUDIOMIXERCTL_32BIT_HACK = 0x7fffffff
|
---|
570 | } PDMAUDIOMIXERCTL;
|
---|
571 |
|
---|
572 | /**
|
---|
573 | * Audio stream commands. Used in the audio connector
|
---|
574 | * as well as in the actual host backends.
|
---|
575 | */
|
---|
576 | typedef enum PDMAUDIOSTREAMCMD
|
---|
577 | {
|
---|
578 | /** Unknown command, do not use. */
|
---|
579 | PDMAUDIOSTREAMCMD_UNKNOWN = 0,
|
---|
580 | /** Enables the stream. */
|
---|
581 | PDMAUDIOSTREAMCMD_ENABLE,
|
---|
582 | /** Disables the stream. */
|
---|
583 | PDMAUDIOSTREAMCMD_DISABLE,
|
---|
584 | /** Pauses the stream. */
|
---|
585 | PDMAUDIOSTREAMCMD_PAUSE,
|
---|
586 | /** Resumes the stream. */
|
---|
587 | PDMAUDIOSTREAMCMD_RESUME,
|
---|
588 | /** Hack to blow the type up to 32-bit. */
|
---|
589 | PDMAUDIOSTREAMCMD_32BIT_HACK = 0x7fffffff
|
---|
590 | } PDMAUDIOSTREAMCMD;
|
---|
591 |
|
---|
592 | /**
|
---|
593 | * Audio volume parameters.
|
---|
594 | */
|
---|
595 | typedef struct PDMAUDIOVOLUME
|
---|
596 | {
|
---|
597 | /** Set to @c true if this stream is muted, @c false if not. */
|
---|
598 | bool fMuted;
|
---|
599 | /** Left channel volume.
|
---|
600 | * Range is from [0 ... 255], whereas 0 specifies
|
---|
601 | * the most silent and 255 the loudest value. */
|
---|
602 | uint8_t uLeft;
|
---|
603 | /** Right channel volume.
|
---|
604 | * Range is from [0 ... 255], whereas 0 specifies
|
---|
605 | * the most silent and 255 the loudest value. */
|
---|
606 | uint8_t uRight;
|
---|
607 | } PDMAUDIOVOLUME, *PPDMAUDIOVOLUME;
|
---|
608 |
|
---|
609 | /** Defines the minimum volume allowed. */
|
---|
610 | #define PDMAUDIO_VOLUME_MIN (0)
|
---|
611 | /** Defines the maximum volume allowed. */
|
---|
612 | #define PDMAUDIO_VOLUME_MAX (255)
|
---|
613 |
|
---|
614 | /**
|
---|
615 | * Structure for holding rate processing information
|
---|
616 | * of a source + destination audio stream. This is needed
|
---|
617 | * because both streams can differ regarding their rates
|
---|
618 | * and therefore need to be treated accordingly.
|
---|
619 | */
|
---|
620 | typedef struct PDMAUDIOSTREAMRATE
|
---|
621 | {
|
---|
622 | /** Current (absolute) offset in the output
|
---|
623 | * (destination) stream. */
|
---|
624 | uint64_t dstOffset;
|
---|
625 | /** Increment for moving dstOffset for the
|
---|
626 | * destination stream. This is needed because the
|
---|
627 | * source <-> destination rate might be different. */
|
---|
628 | uint64_t dstInc;
|
---|
629 | /** Current (absolute) offset in the input
|
---|
630 | * stream. */
|
---|
631 | uint32_t srcOffset;
|
---|
632 | /** Last processed frame of the input stream.
|
---|
633 | * Needed for interpolation. */
|
---|
634 | PDMAUDIOFRAME srcFrameLast;
|
---|
635 | } PDMAUDIOSTREAMRATE, *PPDMAUDIOSTREAMRATE;
|
---|
636 |
|
---|
637 | /**
|
---|
638 | * Structure for holding mixing buffer volume parameters.
|
---|
639 | * The volume values are in fixed point style and must
|
---|
640 | * be converted to/from before using with e.g. PDMAUDIOVOLUME.
|
---|
641 | */
|
---|
642 | typedef struct PDMAUDMIXBUFVOL
|
---|
643 | {
|
---|
644 | /** Set to @c true if this stream is muted, @c false if not. */
|
---|
645 | bool fMuted;
|
---|
646 | /** Left volume to apply during conversion. Pass 0
|
---|
647 | * to convert the original values. May not apply to
|
---|
648 | * all conversion functions. */
|
---|
649 | uint32_t uLeft;
|
---|
650 | /** Right volume to apply during conversion. Pass 0
|
---|
651 | * to convert the original values. May not apply to
|
---|
652 | * all conversion functions. */
|
---|
653 | uint32_t uRight;
|
---|
654 | } PDMAUDMIXBUFVOL, *PPDMAUDMIXBUFVOL;
|
---|
655 |
|
---|
656 | /**
|
---|
657 | * Structure for holding frame conversion parameters for
|
---|
658 | * the audioMixBufConvFromXXX / audioMixBufConvToXXX macros.
|
---|
659 | */
|
---|
660 | typedef struct PDMAUDMIXBUFCONVOPTS
|
---|
661 | {
|
---|
662 | /** Number of audio frames to convert. */
|
---|
663 | uint32_t cFrames;
|
---|
664 | union
|
---|
665 | {
|
---|
666 | struct
|
---|
667 | {
|
---|
668 | /** Volume to use for conversion. */
|
---|
669 | PDMAUDMIXBUFVOL Volume;
|
---|
670 | } From;
|
---|
671 | } RT_UNION_NM(u);
|
---|
672 | } PDMAUDMIXBUFCONVOPTS;
|
---|
673 | /** Pointer to conversion parameters for the audio mixer. */
|
---|
674 | typedef PDMAUDMIXBUFCONVOPTS *PPDMAUDMIXBUFCONVOPTS;
|
---|
675 | /** Pointer to const conversion parameters for the audio mixer. */
|
---|
676 | typedef PDMAUDMIXBUFCONVOPTS const *PCPDMAUDMIXBUFCONVOPTS;
|
---|
677 |
|
---|
678 | /**
|
---|
679 | * Note: All internal handling is done in audio frames,
|
---|
680 | * not in bytes!
|
---|
681 | */
|
---|
682 | typedef uint32_t PDMAUDIOMIXBUFFMT;
|
---|
683 | typedef PDMAUDIOMIXBUFFMT *PPDMAUDIOMIXBUFFMT;
|
---|
684 |
|
---|
685 | /**
|
---|
686 | * Convertion-from function used by the PDM audio buffer mixer.
|
---|
687 | *
|
---|
688 | * @returns Number of audio frames returned.
|
---|
689 | * @param paDst Where to return the converted frames.
|
---|
690 | * @param pvSrc The source frame bytes.
|
---|
691 | * @param cbSrc Number of bytes to convert.
|
---|
692 | * @param pOpts Conversion options.
|
---|
693 | */
|
---|
694 | typedef DECLCALLBACK(uint32_t) FNPDMAUDIOMIXBUFCONVFROM(PPDMAUDIOFRAME paDst, const void *pvSrc, uint32_t cbSrc,
|
---|
695 | PCPDMAUDMIXBUFCONVOPTS pOpts);
|
---|
696 | /** Pointer to a convertion-from function used by the PDM audio buffer mixer. */
|
---|
697 | typedef FNPDMAUDIOMIXBUFCONVFROM *PFNPDMAUDIOMIXBUFCONVFROM;
|
---|
698 |
|
---|
699 | /**
|
---|
700 | * Convertion-to function used by the PDM audio buffer mixer.
|
---|
701 | *
|
---|
702 | * @param pvDst Output buffer.
|
---|
703 | * @param paSrc The input frames.
|
---|
704 | * @param pOpts Conversion options.
|
---|
705 | */
|
---|
706 | typedef DECLCALLBACK(void) FNPDMAUDIOMIXBUFCONVTO(void *pvDst, PCPDMAUDIOFRAME paSrc, PCPDMAUDMIXBUFCONVOPTS pOpts);
|
---|
707 | /** Pointer to a convertion-to function used by the PDM audio buffer mixer. */
|
---|
708 | typedef FNPDMAUDIOMIXBUFCONVTO *PFNPDMAUDIOMIXBUFCONVTO;
|
---|
709 |
|
---|
710 | typedef struct PDMAUDIOMIXBUF *PPDMAUDIOMIXBUF;
|
---|
711 | typedef struct PDMAUDIOMIXBUF
|
---|
712 | {
|
---|
713 | RTLISTNODE Node;
|
---|
714 | /** Name of the buffer. */
|
---|
715 | char *pszName;
|
---|
716 | /** Frame buffer. */
|
---|
717 | PPDMAUDIOFRAME pFrames;
|
---|
718 | /** Size of the frame buffer (in audio frames). */
|
---|
719 | uint32_t cFrames;
|
---|
720 | /** The current read position (in frames). */
|
---|
721 | uint32_t offRead;
|
---|
722 | /** The current write position (in frames). */
|
---|
723 | uint32_t offWrite;
|
---|
724 | /**
|
---|
725 | * Total frames already mixed down to the parent buffer (if any). Always starting at
|
---|
726 | * the parent's offRead position.
|
---|
727 | *
|
---|
728 | * Note: Count always is specified in parent frames, as the sample count can differ between parent
|
---|
729 | * and child.
|
---|
730 | */
|
---|
731 | uint32_t cMixed;
|
---|
732 | /** How much audio frames are currently being used
|
---|
733 | * in this buffer.
|
---|
734 | * Note: This also is known as the distance in ring buffer terms. */
|
---|
735 | uint32_t cUsed;
|
---|
736 | /** Pointer to parent buffer (if any). */
|
---|
737 | PPDMAUDIOMIXBUF pParent;
|
---|
738 | /** List of children mix buffers to keep in sync with (if being a parent buffer). */
|
---|
739 | RTLISTANCHOR lstChildren;
|
---|
740 | /** Number of children mix buffers kept in lstChildren. */
|
---|
741 | uint32_t cChildren;
|
---|
742 | /** Intermediate structure for buffer conversion tasks. */
|
---|
743 | PPDMAUDIOSTREAMRATE pRate;
|
---|
744 | /** Internal representation of current volume used for mixing. */
|
---|
745 | PDMAUDMIXBUFVOL Volume;
|
---|
746 | /** This buffer's audio format. */
|
---|
747 | PDMAUDIOMIXBUFFMT AudioFmt;
|
---|
748 | /** Standard conversion-to function for set AudioFmt. */
|
---|
749 | PFNPDMAUDIOMIXBUFCONVTO pfnConvTo;
|
---|
750 | /** Standard conversion-from function for set AudioFmt. */
|
---|
751 | PFNPDMAUDIOMIXBUFCONVFROM pfnConvFrom;
|
---|
752 | /**
|
---|
753 | * Ratio of the associated parent stream's frequency by this stream's
|
---|
754 | * frequency (1<<32), represented as a signed 64 bit integer.
|
---|
755 | *
|
---|
756 | * For example, if the parent stream has a frequency of 44 khZ, and this
|
---|
757 | * stream has a frequency of 11 kHz, the ration then would be
|
---|
758 | * (44/11 * (1 << 32)).
|
---|
759 | *
|
---|
760 | * Currently this does not get changed once assigned.
|
---|
761 | */
|
---|
762 | int64_t iFreqRatio;
|
---|
763 | /** For quickly converting frames <-> bytes and vice versa. */
|
---|
764 | uint8_t cShift;
|
---|
765 | } PDMAUDIOMIXBUF;
|
---|
766 |
|
---|
767 | typedef uint32_t PDMAUDIOFILEFLAGS;
|
---|
768 |
|
---|
769 | /** No flags defined. */
|
---|
770 | #define PDMAUDIOFILE_FLAG_NONE 0
|
---|
771 | /** Keep the audio file even if it contains no audio data. */
|
---|
772 | #define PDMAUDIOFILE_FLAG_KEEP_IF_EMPTY RT_BIT(0)
|
---|
773 | /** Audio file flag validation mask. */
|
---|
774 | #define PDMAUDIOFILE_FLAG_VALID_MASK 0x1
|
---|
775 |
|
---|
776 | /** Audio file default open flags. */
|
---|
777 | #define PDMAUDIOFILE_DEFAULT_OPEN_FLAGS (RTFILE_O_OPEN_CREATE | RTFILE_O_APPEND | RTFILE_O_WRITE | RTFILE_O_DENY_WRITE)
|
---|
778 |
|
---|
779 | /**
|
---|
780 | * Audio file types.
|
---|
781 | */
|
---|
782 | typedef enum PDMAUDIOFILETYPE
|
---|
783 | {
|
---|
784 | /** Unknown type, do not use. */
|
---|
785 | PDMAUDIOFILETYPE_UNKNOWN = 0,
|
---|
786 | /** Raw (PCM) file. */
|
---|
787 | PDMAUDIOFILETYPE_RAW,
|
---|
788 | /** Wave (.WAV) file. */
|
---|
789 | PDMAUDIOFILETYPE_WAV,
|
---|
790 | /** Hack to blow the type up to 32-bit. */
|
---|
791 | PDMAUDIOFILETYPE_32BIT_HACK = 0x7fffffff
|
---|
792 | } PDMAUDIOFILETYPE;
|
---|
793 |
|
---|
794 | typedef uint32_t PDMAUDIOFILENAMEFLAGS;
|
---|
795 |
|
---|
796 | /** No flags defined. */
|
---|
797 | #define PDMAUDIOFILENAME_FLAG_NONE 0
|
---|
798 | /** Adds an ISO timestamp to the file name. */
|
---|
799 | #define PDMAUDIOFILENAME_FLAG_TS RT_BIT(0)
|
---|
800 |
|
---|
801 | /**
|
---|
802 | * Structure for an audio file handle.
|
---|
803 | */
|
---|
804 | typedef struct PDMAUDIOFILE
|
---|
805 | {
|
---|
806 | /** Type of the audio file. */
|
---|
807 | PDMAUDIOFILETYPE enmType;
|
---|
808 | /** Audio file flags. */
|
---|
809 | PDMAUDIOFILEFLAGS fFlags;
|
---|
810 | /** File name and path. */
|
---|
811 | char szName[RTPATH_MAX + 1];
|
---|
812 | /** Actual file handle. */
|
---|
813 | RTFILE hFile;
|
---|
814 | /** Data needed for the specific audio file type implemented.
|
---|
815 | * Optional, can be NULL. */
|
---|
816 | void *pvData;
|
---|
817 | /** Data size (in bytes). */
|
---|
818 | size_t cbData;
|
---|
819 | } PDMAUDIOFILE, *PPDMAUDIOFILE;
|
---|
820 |
|
---|
821 | /** Stream status flag. To be used with PDMAUDIOSTRMSTS_FLAG_ flags. */
|
---|
822 | typedef uint32_t PDMAUDIOSTREAMSTS;
|
---|
823 |
|
---|
824 | /** No flags being set. */
|
---|
825 | #define PDMAUDIOSTREAMSTS_FLAG_NONE 0
|
---|
826 | /** Whether this stream has been initialized by the
|
---|
827 | * backend or not. */
|
---|
828 | #define PDMAUDIOSTREAMSTS_FLAG_INITIALIZED RT_BIT_32(0)
|
---|
829 | /** Whether this stream is enabled or disabled. */
|
---|
830 | #define PDMAUDIOSTREAMSTS_FLAG_ENABLED RT_BIT_32(1)
|
---|
831 | /** Whether this stream has been paused or not. This also implies
|
---|
832 | * that this is an enabled stream! */
|
---|
833 | #define PDMAUDIOSTREAMSTS_FLAG_PAUSED RT_BIT_32(2)
|
---|
834 | /** Whether this stream was marked as being disabled
|
---|
835 | * but there are still associated guest output streams
|
---|
836 | * which rely on its data. */
|
---|
837 | #define PDMAUDIOSTREAMSTS_FLAG_PENDING_DISABLE RT_BIT_32(3)
|
---|
838 | /** Whether this stream is in re-initialization phase.
|
---|
839 | * All other bits remain untouched to be able to restore
|
---|
840 | * the stream's state after the re-initialization bas been
|
---|
841 | * finished. */
|
---|
842 | #define PDMAUDIOSTREAMSTS_FLAG_PENDING_REINIT RT_BIT_32(4)
|
---|
843 | /** Validation mask. */
|
---|
844 | #define PDMAUDIOSTREAMSTS_VALID_MASK UINT32_C(0x0000001F)
|
---|
845 |
|
---|
846 | /**
|
---|
847 | * Enumeration presenting a backend's current status.
|
---|
848 | */
|
---|
849 | typedef enum PDMAUDIOBACKENDSTS
|
---|
850 | {
|
---|
851 | /** Unknown/invalid status. */
|
---|
852 | PDMAUDIOBACKENDSTS_UNKNOWN = 0,
|
---|
853 | /** The backend is in its initialization phase.
|
---|
854 | * Not all backends support this status. */
|
---|
855 | PDMAUDIOBACKENDSTS_INITIALIZING,
|
---|
856 | /** The backend has stopped its operation. */
|
---|
857 | PDMAUDIOBACKENDSTS_STOPPED,
|
---|
858 | /** The backend is up and running. */
|
---|
859 | PDMAUDIOBACKENDSTS_RUNNING,
|
---|
860 | /** The backend ran into an error and is unable to recover.
|
---|
861 | * A manual re-initialization might help. */
|
---|
862 | PDMAUDIOBACKENDSTS_ERROR,
|
---|
863 | /** Hack to blow the type up to 32-bit. */
|
---|
864 | PDMAUDIOBACKENDSTS_32BIT_HACK = 0x7fffffff
|
---|
865 | } PDMAUDIOBACKENDSTS;
|
---|
866 |
|
---|
867 | /**
|
---|
868 | * Audio stream context.
|
---|
869 | */
|
---|
870 | typedef enum PDMAUDIOSTREAMCTX
|
---|
871 | {
|
---|
872 | /** No context set / invalid. */
|
---|
873 | PDMAUDIOSTREAMCTX_UNKNOWN = 0,
|
---|
874 | /** Host stream, connected to a backend. */
|
---|
875 | PDMAUDIOSTREAMCTX_HOST,
|
---|
876 | /** Guest stream, connected to the device emulation. */
|
---|
877 | PDMAUDIOSTREAMCTX_GUEST,
|
---|
878 | /** Hack to blow the type up to 32-bit. */
|
---|
879 | PDMAUDIOSTREAMCTX_32BIT_HACK = 0x7fffffff
|
---|
880 | } PDMAUDIOSTREAMCTX;
|
---|
881 |
|
---|
882 | /**
|
---|
883 | * Structure for keeping audio input stream specifics.
|
---|
884 | * Do not use directly. Instead, use PDMAUDIOSTREAM.
|
---|
885 | */
|
---|
886 | typedef struct PDMAUDIOSTREAMIN
|
---|
887 | {
|
---|
888 | /** Timestamp (in ms) since last read. */
|
---|
889 | uint64_t tsLastReadMS;
|
---|
890 | #ifdef VBOX_WITH_STATISTICS
|
---|
891 | STAMCOUNTER StatBytesElapsed;
|
---|
892 | STAMCOUNTER StatBytesTotalRead;
|
---|
893 | STAMCOUNTER StatFramesCaptured;
|
---|
894 | #endif
|
---|
895 | struct
|
---|
896 | {
|
---|
897 | /** File for writing stream reads. */
|
---|
898 | PPDMAUDIOFILE pFileStreamRead;
|
---|
899 | /** File for writing non-interleaved captures. */
|
---|
900 | PPDMAUDIOFILE pFileCaptureNonInterleaved;
|
---|
901 | } Dbg;
|
---|
902 | } PDMAUDIOSTREAMIN, *PPDMAUDIOSTREAMIN;
|
---|
903 |
|
---|
904 | /**
|
---|
905 | * Structure for keeping audio output stream specifics.
|
---|
906 | * Do not use directly. Instead, use PDMAUDIOSTREAM.
|
---|
907 | */
|
---|
908 | typedef struct PDMAUDIOSTREAMOUT
|
---|
909 | {
|
---|
910 | /** Timestamp (in ms) since last write. */
|
---|
911 | uint64_t tsLastWriteMS;
|
---|
912 | #ifdef VBOX_WITH_STATISTICS
|
---|
913 | STAMCOUNTER StatBytesElapsed;
|
---|
914 | STAMCOUNTER StatBytesTotalWritten;
|
---|
915 | STAMCOUNTER StatFramesPlayed;
|
---|
916 | #endif
|
---|
917 | struct
|
---|
918 | {
|
---|
919 | /** File for writing stream writes. */
|
---|
920 | PPDMAUDIOFILE pFileStreamWrite;
|
---|
921 | /** File for writing stream playback. */
|
---|
922 | PPDMAUDIOFILE pFilePlayNonInterleaved;
|
---|
923 | } Dbg;
|
---|
924 | } PDMAUDIOSTREAMOUT, *PPDMAUDIOSTREAMOUT;
|
---|
925 |
|
---|
926 | typedef struct PDMAUDIOSTREAM *PPDMAUDIOSTREAM;
|
---|
927 |
|
---|
928 | /**
|
---|
929 | * Structure for maintaining an nput/output audio stream.
|
---|
930 | */
|
---|
931 | typedef struct PDMAUDIOSTREAM
|
---|
932 | {
|
---|
933 | /** List node. */
|
---|
934 | RTLISTNODE Node;
|
---|
935 | /** Pointer to the other pair of this stream.
|
---|
936 | * This might be the host or guest side. */
|
---|
937 | PPDMAUDIOSTREAM pPair;
|
---|
938 | /** Name of this stream. */
|
---|
939 | char szName[64];
|
---|
940 | /** Number of references to this stream. Only can be
|
---|
941 | * destroyed if the reference count is reaching 0. */
|
---|
942 | uint32_t cRefs;
|
---|
943 | /** The stream's audio configuration. */
|
---|
944 | PDMAUDIOSTREAMCFG Cfg;
|
---|
945 | /** Stream status flag. */
|
---|
946 | PDMAUDIOSTREAMSTS fStatus;
|
---|
947 | /** This stream's mixing buffer. */
|
---|
948 | PDMAUDIOMIXBUF MixBuf;
|
---|
949 | /** Audio direction of this stream. */
|
---|
950 | PDMAUDIODIR enmDir;
|
---|
951 | /** Context of this stream. */
|
---|
952 | PDMAUDIOSTREAMCTX enmCtx;
|
---|
953 | /** Timestamp (in ms) since last iteration. */
|
---|
954 | uint64_t tsLastIterateMS;
|
---|
955 | /** Union for input/output specifics. */
|
---|
956 | union
|
---|
957 | {
|
---|
958 | PDMAUDIOSTREAMIN In;
|
---|
959 | PDMAUDIOSTREAMOUT Out;
|
---|
960 | } RT_UNION_NM(u);
|
---|
961 | /** Data to backend-specific stream data.
|
---|
962 | * This data block will be casted by the backend to access its backend-dependent data.
|
---|
963 | *
|
---|
964 | * That way the backends do not have access to the audio connector's data. */
|
---|
965 | void *pvBackend;
|
---|
966 | /** Size (in bytes) of the backend-specific stream data. */
|
---|
967 | size_t cbBackend;
|
---|
968 | } PDMAUDIOSTREAM;
|
---|
969 |
|
---|
970 | /** Pointer to a audio connector interface. */
|
---|
971 | typedef struct PDMIAUDIOCONNECTOR *PPDMIAUDIOCONNECTOR;
|
---|
972 |
|
---|
973 | /**
|
---|
974 | * Enumeration for an audio callback source.
|
---|
975 | */
|
---|
976 | typedef enum PDMAUDIOCBSOURCE
|
---|
977 | {
|
---|
978 | /** Invalid, do not use. */
|
---|
979 | PDMAUDIOCBSOURCE_INVALID = 0,
|
---|
980 | /** Device emulation. */
|
---|
981 | PDMAUDIOCBSOURCE_DEVICE = 1,
|
---|
982 | /** Audio connector interface. */
|
---|
983 | PDMAUDIOCBSOURCE_CONNECTOR = 2,
|
---|
984 | /** Backend (lower). */
|
---|
985 | PDMAUDIOCBSOURCE_BACKEND = 3,
|
---|
986 | /** Hack to blow the type up to 32-bit. */
|
---|
987 | PDMAUDIOCBSOURCE_32BIT_HACK = 0x7fffffff
|
---|
988 | } PDMAUDIOCBSOURCE;
|
---|
989 |
|
---|
990 | /**
|
---|
991 | * Audio device callback types.
|
---|
992 | * Those callbacks are being sent from the audio connector -> device emulation.
|
---|
993 | */
|
---|
994 | typedef enum PDMAUDIODEVICECBTYPE
|
---|
995 | {
|
---|
996 | /** Invalid, do not use. */
|
---|
997 | PDMAUDIODEVICECBTYPE_INVALID = 0,
|
---|
998 | /** Data is availabe as input for passing to the device emulation. */
|
---|
999 | PDMAUDIODEVICECBTYPE_DATA_INPUT,
|
---|
1000 | /** Free data for the device emulation to write to the backend. */
|
---|
1001 | PDMAUDIODEVICECBTYPE_DATA_OUTPUT,
|
---|
1002 | /** Hack to blow the type up to 32-bit. */
|
---|
1003 | PDMAUDIODEVICECBTYPE_32BIT_HACK = 0x7fffffff
|
---|
1004 | } PDMAUDIODEVICECBTYPE;
|
---|
1005 |
|
---|
1006 | /**
|
---|
1007 | * Device callback data for audio input.
|
---|
1008 | */
|
---|
1009 | typedef struct PDMAUDIODEVICECBDATA_DATA_INPUT
|
---|
1010 | {
|
---|
1011 | /** Input: How many bytes are availabe as input for passing
|
---|
1012 | * to the device emulation. */
|
---|
1013 | uint32_t cbInAvail;
|
---|
1014 | /** Output: How many bytes have been read. */
|
---|
1015 | uint32_t cbOutRead;
|
---|
1016 | } PDMAUDIODEVICECBDATA_DATA_INPUT, *PPDMAUDIODEVICECBDATA_DATA_INPUT;
|
---|
1017 |
|
---|
1018 | /**
|
---|
1019 | * Device callback data for audio output.
|
---|
1020 | */
|
---|
1021 | typedef struct PDMAUDIODEVICECBDATA_DATA_OUTPUT
|
---|
1022 | {
|
---|
1023 | /** Input: How many bytes are free for the device emulation to write. */
|
---|
1024 | uint32_t cbInFree;
|
---|
1025 | /** Output: How many bytes were written by the device emulation. */
|
---|
1026 | uint32_t cbOutWritten;
|
---|
1027 | } PDMAUDIODEVICECBDATA_DATA_OUTPUT, *PPDMAUDIODEVICECBDATA_DATA_OUTPUT;
|
---|
1028 |
|
---|
1029 | /**
|
---|
1030 | * Audio backend callback types.
|
---|
1031 | * Those callbacks are being sent from the backend -> audio connector.
|
---|
1032 | */
|
---|
1033 | typedef enum PDMAUDIOBACKENDCBTYPE
|
---|
1034 | {
|
---|
1035 | /** Invalid, do not use. */
|
---|
1036 | PDMAUDIOBACKENDCBTYPE_INVALID = 0,
|
---|
1037 | /** The backend's status has changed. */
|
---|
1038 | PDMAUDIOBACKENDCBTYPE_STATUS,
|
---|
1039 | /** One or more host audio devices have changed. */
|
---|
1040 | PDMAUDIOBACKENDCBTYPE_DEVICES_CHANGED,
|
---|
1041 | /** Hack to blow the type up to 32-bit. */
|
---|
1042 | PDMAUDIOBACKENDCBTYPE_32BIT_HACK = 0x7fffffff
|
---|
1043 | } PDMAUDIOBACKENDCBTYPE;
|
---|
1044 |
|
---|
1045 | /** Pointer to a host audio interface. */
|
---|
1046 | typedef struct PDMIHOSTAUDIO *PPDMIHOSTAUDIO;
|
---|
1047 |
|
---|
1048 | /**
|
---|
1049 | * Host audio callback function.
|
---|
1050 | * This function will be called from a backend to communicate with the host audio interface.
|
---|
1051 | *
|
---|
1052 | * @returns IPRT status code.
|
---|
1053 | * @param pDrvIns Pointer to driver instance which called us.
|
---|
1054 | * @param enmType Callback type.
|
---|
1055 | * @param pvUser User argument.
|
---|
1056 | * @param cbUser Size (in bytes) of user argument.
|
---|
1057 | */
|
---|
1058 | typedef DECLCALLBACK(int) FNPDMHOSTAUDIOCALLBACK(PPDMDRVINS pDrvIns, PDMAUDIOBACKENDCBTYPE enmType, void *pvUser, size_t cbUser);
|
---|
1059 | /** Pointer to a FNPDMHOSTAUDIOCALLBACK(). */
|
---|
1060 | typedef FNPDMHOSTAUDIOCALLBACK *PFNPDMHOSTAUDIOCALLBACK;
|
---|
1061 |
|
---|
1062 | /**
|
---|
1063 | * Audio callback registration record.
|
---|
1064 | */
|
---|
1065 | typedef struct PDMAUDIOCBRECORD
|
---|
1066 | {
|
---|
1067 | /** List node. */
|
---|
1068 | RTLISTANCHOR Node;
|
---|
1069 | /** Callback source. */
|
---|
1070 | PDMAUDIOCBSOURCE enmSource;
|
---|
1071 | /** Callback type, based on the given source. */
|
---|
1072 | union
|
---|
1073 | {
|
---|
1074 | /** Device callback stuff. */
|
---|
1075 | struct
|
---|
1076 | {
|
---|
1077 | PDMAUDIODEVICECBTYPE enmType;
|
---|
1078 | } Device;
|
---|
1079 | } RT_UNION_NM(u);
|
---|
1080 | /** Pointer to context data. Optional. */
|
---|
1081 | void *pvCtx;
|
---|
1082 | /** Size (in bytes) of context data.
|
---|
1083 | * Must be 0 if pvCtx is NULL. */
|
---|
1084 | size_t cbCtx;
|
---|
1085 | } PDMAUDIOCBRECORD, *PPDMAUDIOCBRECORD;
|
---|
1086 |
|
---|
1087 | #define PPDMAUDIOBACKENDSTREAM void *
|
---|
1088 |
|
---|
1089 | /**
|
---|
1090 | * Audio connector interface (up).
|
---|
1091 | */
|
---|
1092 | typedef struct PDMIAUDIOCONNECTOR
|
---|
1093 | {
|
---|
1094 | /**
|
---|
1095 | * Enables or disables the given audio direction for this driver.
|
---|
1096 | *
|
---|
1097 | * When disabled, assiociated output streams consume written audio without passing them further down to the backends.
|
---|
1098 | * Associated input streams then return silence when read from those.
|
---|
1099 | *
|
---|
1100 | * @returns VBox status code.
|
---|
1101 | * @param pInterface Pointer to the interface structure containing the called function pointer.
|
---|
1102 | * @param enmDir Audio direction to enable or disable driver for.
|
---|
1103 | * @param fEnable Whether to enable or disable the specified audio direction.
|
---|
1104 | */
|
---|
1105 | DECLR3CALLBACKMEMBER(int, pfnEnable, (PPDMIAUDIOCONNECTOR pInterface, PDMAUDIODIR enmDir, bool fEnable));
|
---|
1106 |
|
---|
1107 | /**
|
---|
1108 | * Returns whether the given audio direction for this driver is enabled or not.
|
---|
1109 | *
|
---|
1110 | * @returns True if audio is enabled for the given direction, false if not.
|
---|
1111 | * @param pInterface Pointer to the interface structure containing the called function pointer.
|
---|
1112 | * @param enmDir Audio direction to retrieve enabled status for.
|
---|
1113 | */
|
---|
1114 | DECLR3CALLBACKMEMBER(bool, pfnIsEnabled, (PPDMIAUDIOCONNECTOR pInterface, PDMAUDIODIR enmDir));
|
---|
1115 |
|
---|
1116 | /**
|
---|
1117 | * Retrieves the current configuration of the host audio backend.
|
---|
1118 | *
|
---|
1119 | * @returns VBox status code.
|
---|
1120 | * @param pInterface Pointer to the interface structure containing the called function pointer.
|
---|
1121 | * @param pCfg Where to store the host audio backend configuration data.
|
---|
1122 | */
|
---|
1123 | DECLR3CALLBACKMEMBER(int, pfnGetConfig, (PPDMIAUDIOCONNECTOR pInterface, PPDMAUDIOBACKENDCFG pCfg));
|
---|
1124 |
|
---|
1125 | /**
|
---|
1126 | * Retrieves the current status of the host audio backend.
|
---|
1127 | *
|
---|
1128 | * @returns Status of the host audio backend.
|
---|
1129 | * @param pInterface Pointer to the interface structure containing the called function pointer.
|
---|
1130 | * @param enmDir Audio direction to check host audio backend for. Specify PDMAUDIODIR_ANY for the overall
|
---|
1131 | * backend status.
|
---|
1132 | */
|
---|
1133 | DECLR3CALLBACKMEMBER(PDMAUDIOBACKENDSTS, pfnGetStatus, (PPDMIAUDIOCONNECTOR pInterface, PDMAUDIODIR enmDir));
|
---|
1134 |
|
---|
1135 | /**
|
---|
1136 | * Creates an audio stream.
|
---|
1137 | *
|
---|
1138 | * @returns VBox status code.
|
---|
1139 | * @param pInterface Pointer to the interface structure containing the called function pointer.
|
---|
1140 | * @param pCfgHost Stream configuration for host side.
|
---|
1141 | * @param pCfgGuest Stream configuration for guest side.
|
---|
1142 | * @param ppStream Pointer where to return the created audio stream on success.
|
---|
1143 | */
|
---|
1144 | DECLR3CALLBACKMEMBER(int, pfnStreamCreate, (PPDMIAUDIOCONNECTOR pInterface, PPDMAUDIOSTREAMCFG pCfgHost, PPDMAUDIOSTREAMCFG pCfgGuest, PPDMAUDIOSTREAM *ppStream));
|
---|
1145 |
|
---|
1146 | /**
|
---|
1147 | * Destroys an audio stream.
|
---|
1148 | *
|
---|
1149 | * @param pInterface Pointer to the interface structure containing the called function pointer.
|
---|
1150 | * @param pStream Pointer to audio stream.
|
---|
1151 | */
|
---|
1152 | DECLR3CALLBACKMEMBER(int, pfnStreamDestroy, (PPDMIAUDIOCONNECTOR pInterface, PPDMAUDIOSTREAM pStream));
|
---|
1153 |
|
---|
1154 | /**
|
---|
1155 | * Adds a reference to the specified audio stream.
|
---|
1156 | *
|
---|
1157 | * @returns New reference count. UINT32_MAX on error.
|
---|
1158 | * @param pInterface Pointer to the interface structure containing the called function pointer.
|
---|
1159 | * @param pStream Pointer to audio stream adding the reference to.
|
---|
1160 | */
|
---|
1161 | DECLR3CALLBACKMEMBER(uint32_t, pfnStreamRetain, (PPDMIAUDIOCONNECTOR pInterface, PPDMAUDIOSTREAM pStream));
|
---|
1162 |
|
---|
1163 | /**
|
---|
1164 | * Releases a reference from the specified stream.
|
---|
1165 | *
|
---|
1166 | * @returns New reference count. UINT32_MAX on error.
|
---|
1167 | * @param pInterface Pointer to the interface structure containing the called function pointer.
|
---|
1168 | * @param pStream Pointer to audio stream releasing a reference from.
|
---|
1169 | */
|
---|
1170 | DECLR3CALLBACKMEMBER(uint32_t, pfnStreamRelease, (PPDMIAUDIOCONNECTOR pInterface, PPDMAUDIOSTREAM pStream));
|
---|
1171 |
|
---|
1172 | /**
|
---|
1173 | * Reads PCM audio data from the host (input).
|
---|
1174 | *
|
---|
1175 | * @returns VBox status code.
|
---|
1176 | * @param pInterface Pointer to the interface structure containing the called function pointer.
|
---|
1177 | * @param pStream Pointer to audio stream to write to.
|
---|
1178 | * @param pvBuf Where to store the read data.
|
---|
1179 | * @param cbBuf Number of bytes to read.
|
---|
1180 | * @param pcbRead Bytes of audio data read. Optional.
|
---|
1181 | */
|
---|
1182 | DECLR3CALLBACKMEMBER(int, pfnStreamRead, (PPDMIAUDIOCONNECTOR pInterface, PPDMAUDIOSTREAM pStream, void *pvBuf, uint32_t cbBuf, uint32_t *pcbRead));
|
---|
1183 |
|
---|
1184 | /**
|
---|
1185 | * Writes PCM audio data to the host (output).
|
---|
1186 | *
|
---|
1187 | * @returns VBox status code.
|
---|
1188 | * @param pInterface Pointer to the interface structure containing the called function pointer.
|
---|
1189 | * @param pStream Pointer to audio stream to read from.
|
---|
1190 | * @param pvBuf Audio data to be written.
|
---|
1191 | * @param cbBuf Number of bytes to be written.
|
---|
1192 | * @param pcbWritten Bytes of audio data written. Optional.
|
---|
1193 | */
|
---|
1194 | DECLR3CALLBACKMEMBER(int, pfnStreamWrite, (PPDMIAUDIOCONNECTOR pInterface, PPDMAUDIOSTREAM pStream, const void *pvBuf, uint32_t cbBuf, uint32_t *pcbWritten));
|
---|
1195 |
|
---|
1196 | /**
|
---|
1197 | * Controls a specific audio stream.
|
---|
1198 | *
|
---|
1199 | * @returns VBox status code.
|
---|
1200 | * @param pInterface Pointer to the interface structure containing the called function pointer.
|
---|
1201 | * @param pStream Pointer to audio stream.
|
---|
1202 | * @param enmStreamCmd The stream command to issue.
|
---|
1203 | */
|
---|
1204 | DECLR3CALLBACKMEMBER(int, pfnStreamControl, (PPDMIAUDIOCONNECTOR pInterface, PPDMAUDIOSTREAM pStream, PDMAUDIOSTREAMCMD enmStreamCmd));
|
---|
1205 |
|
---|
1206 | /**
|
---|
1207 | * Processes stream data.
|
---|
1208 | *
|
---|
1209 | * @param pInterface Pointer to the interface structure containing the called function pointer.
|
---|
1210 | * @param pStream Pointer to audio stream.
|
---|
1211 | */
|
---|
1212 | DECLR3CALLBACKMEMBER(int, pfnStreamIterate, (PPDMIAUDIOCONNECTOR pInterface, PPDMAUDIOSTREAM pStream));
|
---|
1213 |
|
---|
1214 | /**
|
---|
1215 | * Returns the number of readable data (in bytes) of a specific audio input stream.
|
---|
1216 | *
|
---|
1217 | * @returns Number of readable data (in bytes).
|
---|
1218 | * @param pInterface Pointer to the interface structure containing the called function pointer.
|
---|
1219 | * @param pStream Pointer to audio stream.
|
---|
1220 | */
|
---|
1221 | DECLR3CALLBACKMEMBER(uint32_t, pfnStreamGetReadable, (PPDMIAUDIOCONNECTOR pInterface, PPDMAUDIOSTREAM pStream));
|
---|
1222 |
|
---|
1223 | /**
|
---|
1224 | * Returns the number of writable data (in bytes) of a specific audio output stream.
|
---|
1225 | *
|
---|
1226 | * @returns Number of writable data (in bytes).
|
---|
1227 | * @param pInterface Pointer to the interface structure containing the called function pointer.
|
---|
1228 | * @param pStream Pointer to audio stream.
|
---|
1229 | */
|
---|
1230 | DECLR3CALLBACKMEMBER(uint32_t, pfnStreamGetWritable, (PPDMIAUDIOCONNECTOR pInterface, PPDMAUDIOSTREAM pStream));
|
---|
1231 |
|
---|
1232 | /**
|
---|
1233 | * Returns the status of a specific audio stream.
|
---|
1234 | *
|
---|
1235 | * @returns Audio stream status
|
---|
1236 | * @param pInterface Pointer to the interface structure containing the called function pointer.
|
---|
1237 | * @param pStream Pointer to audio stream.
|
---|
1238 | */
|
---|
1239 | DECLR3CALLBACKMEMBER(PDMAUDIOSTREAMSTS, pfnStreamGetStatus, (PPDMIAUDIOCONNECTOR pInterface, PPDMAUDIOSTREAM pStream));
|
---|
1240 |
|
---|
1241 | /**
|
---|
1242 | * Sets the audio volume of a specific audio stream.
|
---|
1243 | *
|
---|
1244 | * @returns VBox status code.
|
---|
1245 | * @param pInterface Pointer to the interface structure containing the called function pointer.
|
---|
1246 | * @param pStream Pointer to audio stream.
|
---|
1247 | * @param pVol Pointer to audio volume structure to set the stream's audio volume to.
|
---|
1248 | */
|
---|
1249 | DECLR3CALLBACKMEMBER(int, pfnStreamSetVolume, (PPDMIAUDIOCONNECTOR pInterface, PPDMAUDIOSTREAM pStream, PPDMAUDIOVOLUME pVol));
|
---|
1250 |
|
---|
1251 | /**
|
---|
1252 | * Plays (transfers) available audio frames via the host backend. Only works with output streams.
|
---|
1253 | *
|
---|
1254 | * @returns VBox status code.
|
---|
1255 | * @param pInterface Pointer to the interface structure containing the called function pointer.
|
---|
1256 | * @param pStream Pointer to audio stream.
|
---|
1257 | * @param pcFramesPlayed Number of frames played. Optional.
|
---|
1258 | */
|
---|
1259 | DECLR3CALLBACKMEMBER(int, pfnStreamPlay, (PPDMIAUDIOCONNECTOR pInterface, PPDMAUDIOSTREAM pStream, uint32_t *pcFramesPlayed));
|
---|
1260 |
|
---|
1261 | /**
|
---|
1262 | * Captures (transfers) available audio frames from the host backend. Only works with input streams.
|
---|
1263 | *
|
---|
1264 | * @returns VBox status code.
|
---|
1265 | * @param pInterface Pointer to the interface structure containing the called function pointer.
|
---|
1266 | * @param pStream Pointer to audio stream.
|
---|
1267 | * @param pcFramesCaptured Number of frames captured. Optional.
|
---|
1268 | */
|
---|
1269 | DECLR3CALLBACKMEMBER(int, pfnStreamCapture, (PPDMIAUDIOCONNECTOR pInterface, PPDMAUDIOSTREAM pStream, uint32_t *pcFramesCaptured));
|
---|
1270 |
|
---|
1271 | /**
|
---|
1272 | * Registers (device) callbacks.
|
---|
1273 | * This is handy for letting the device emulation know of certain events, e.g. processing input / output data
|
---|
1274 | * or configuration changes.
|
---|
1275 | *
|
---|
1276 | * @returns VBox status code.
|
---|
1277 | * @param pInterface Pointer to the interface structure containing the called function pointer.
|
---|
1278 | * @param paCallbacks Pointer to array of callbacks to register.
|
---|
1279 | * @param cCallbacks Number of callbacks to register.
|
---|
1280 | */
|
---|
1281 | DECLR3CALLBACKMEMBER(int, pfnRegisterCallbacks, (PPDMIAUDIOCONNECTOR pInterface, PPDMAUDIOCBRECORD paCallbacks, size_t cCallbacks));
|
---|
1282 |
|
---|
1283 | } PDMIAUDIOCONNECTOR;
|
---|
1284 |
|
---|
1285 | /** PDMIAUDIOCONNECTOR interface ID. */
|
---|
1286 | #define PDMIAUDIOCONNECTOR_IID "A643B40C-733F-4307-9549-070AF0EE0ED6"
|
---|
1287 |
|
---|
1288 | /**
|
---|
1289 | * Assigns all needed interface callbacks for an audio backend.
|
---|
1290 | *
|
---|
1291 | * @param a_Prefix The function name prefix.
|
---|
1292 | */
|
---|
1293 | #define PDMAUDIO_IHOSTAUDIO_CALLBACKS(a_Prefix) \
|
---|
1294 | do { \
|
---|
1295 | pThis->IHostAudio.pfnInit = RT_CONCAT(a_Prefix,Init); \
|
---|
1296 | pThis->IHostAudio.pfnShutdown = RT_CONCAT(a_Prefix,Shutdown); \
|
---|
1297 | pThis->IHostAudio.pfnGetConfig = RT_CONCAT(a_Prefix,GetConfig); \
|
---|
1298 | /** @todo Add pfnGetDevices here as soon as supported by all backends. */ \
|
---|
1299 | pThis->IHostAudio.pfnGetStatus = RT_CONCAT(a_Prefix,GetStatus); \
|
---|
1300 | /** @todo Ditto for pfnSetCallback. */ \
|
---|
1301 | pThis->IHostAudio.pfnStreamCreate = RT_CONCAT(a_Prefix,StreamCreate); \
|
---|
1302 | pThis->IHostAudio.pfnStreamDestroy = RT_CONCAT(a_Prefix,StreamDestroy); \
|
---|
1303 | pThis->IHostAudio.pfnStreamControl = RT_CONCAT(a_Prefix,StreamControl); \
|
---|
1304 | pThis->IHostAudio.pfnStreamGetReadable = RT_CONCAT(a_Prefix,StreamGetReadable); \
|
---|
1305 | pThis->IHostAudio.pfnStreamGetWritable = RT_CONCAT(a_Prefix,StreamGetWritable); \
|
---|
1306 | pThis->IHostAudio.pfnStreamGetStatus = RT_CONCAT(a_Prefix,StreamGetStatus); \
|
---|
1307 | pThis->IHostAudio.pfnStreamIterate = RT_CONCAT(a_Prefix,StreamIterate); \
|
---|
1308 | pThis->IHostAudio.pfnStreamPlay = RT_CONCAT(a_Prefix,StreamPlay); \
|
---|
1309 | pThis->IHostAudio.pfnStreamCapture = RT_CONCAT(a_Prefix,StreamCapture); \
|
---|
1310 | } while (0)
|
---|
1311 |
|
---|
1312 | /**
|
---|
1313 | * PDM host audio interface.
|
---|
1314 | */
|
---|
1315 | typedef struct PDMIHOSTAUDIO
|
---|
1316 | {
|
---|
1317 | /**
|
---|
1318 | * Initializes the host backend (driver).
|
---|
1319 | *
|
---|
1320 | * @returns VBox status code.
|
---|
1321 | * @param pInterface Pointer to the interface structure containing the called function pointer.
|
---|
1322 | */
|
---|
1323 | DECLR3CALLBACKMEMBER(int, pfnInit, (PPDMIHOSTAUDIO pInterface));
|
---|
1324 |
|
---|
1325 | /**
|
---|
1326 | * Shuts down the host backend (driver).
|
---|
1327 | *
|
---|
1328 | * @returns VBox status code.
|
---|
1329 | * @param pInterface Pointer to the interface structure containing the called function pointer.
|
---|
1330 | */
|
---|
1331 | DECLR3CALLBACKMEMBER(void, pfnShutdown, (PPDMIHOSTAUDIO pInterface));
|
---|
1332 |
|
---|
1333 | /**
|
---|
1334 | * Returns the host backend's configuration (backend).
|
---|
1335 | *
|
---|
1336 | * @returns VBox status code.
|
---|
1337 | * @param pInterface Pointer to the interface structure containing the called function pointer.
|
---|
1338 | * @param pBackendCfg Where to store the backend audio configuration to.
|
---|
1339 | */
|
---|
1340 | DECLR3CALLBACKMEMBER(int, pfnGetConfig, (PPDMIHOSTAUDIO pInterface, PPDMAUDIOBACKENDCFG pBackendCfg));
|
---|
1341 |
|
---|
1342 | /**
|
---|
1343 | * Returns (enumerates) host audio device information.
|
---|
1344 | *
|
---|
1345 | * @returns VBox status code.
|
---|
1346 | * @param pInterface Pointer to the interface structure containing the called function pointer.
|
---|
1347 | * @param pDeviceEnum Where to return the enumerated audio devices.
|
---|
1348 | */
|
---|
1349 | DECLR3CALLBACKMEMBER(int, pfnGetDevices, (PPDMIHOSTAUDIO pInterface, PPDMAUDIODEVICEENUM pDeviceEnum));
|
---|
1350 |
|
---|
1351 | /**
|
---|
1352 | * Returns the current status from the audio backend.
|
---|
1353 | *
|
---|
1354 | * @returns PDMAUDIOBACKENDSTS enum.
|
---|
1355 | * @param pInterface Pointer to the interface structure containing the called function pointer.
|
---|
1356 | * @param enmDir Audio direction to get status for. Pass PDMAUDIODIR_ANY for overall status.
|
---|
1357 | */
|
---|
1358 | DECLR3CALLBACKMEMBER(PDMAUDIOBACKENDSTS, pfnGetStatus, (PPDMIHOSTAUDIO pInterface, PDMAUDIODIR enmDir));
|
---|
1359 |
|
---|
1360 | /**
|
---|
1361 | * Sets a callback the audio backend can call. Optional.
|
---|
1362 | *
|
---|
1363 | * @returns VBox status code.
|
---|
1364 | * @param pInterface Pointer to the interface structure containing the called function pointer.
|
---|
1365 | * @param pfnCallback The callback function to use, or NULL when unregistering.
|
---|
1366 | */
|
---|
1367 | DECLR3CALLBACKMEMBER(int, pfnSetCallback, (PPDMIHOSTAUDIO pInterface, PFNPDMHOSTAUDIOCALLBACK pfnCallback));
|
---|
1368 |
|
---|
1369 | /**
|
---|
1370 | * Creates an audio stream using the requested stream configuration.
|
---|
1371 | * If a backend is not able to create this configuration, it will return its best match in the acquired configuration
|
---|
1372 | * structure on success.
|
---|
1373 | *
|
---|
1374 | * @returns VBox status code.
|
---|
1375 | * @param pInterface Pointer to the interface structure containing the called function pointer.
|
---|
1376 | * @param pStream Pointer to audio stream.
|
---|
1377 | * @param pCfgReq Pointer to requested stream configuration.
|
---|
1378 | * @param pCfgAcq Pointer to acquired stream configuration.
|
---|
1379 | */
|
---|
1380 | DECLR3CALLBACKMEMBER(int, pfnStreamCreate, (PPDMIHOSTAUDIO pInterface, PPDMAUDIOBACKENDSTREAM pStream, PPDMAUDIOSTREAMCFG pCfgReq, PPDMAUDIOSTREAMCFG pCfgAcq));
|
---|
1381 |
|
---|
1382 | /**
|
---|
1383 | * Destroys an audio stream.
|
---|
1384 | *
|
---|
1385 | * @returns VBox status code.
|
---|
1386 | * @param pInterface Pointer to the interface structure containing the called function pointer.
|
---|
1387 | * @param pStream Pointer to audio stream.
|
---|
1388 | */
|
---|
1389 | DECLR3CALLBACKMEMBER(int, pfnStreamDestroy, (PPDMIHOSTAUDIO pInterface, PPDMAUDIOBACKENDSTREAM pStream));
|
---|
1390 |
|
---|
1391 | /**
|
---|
1392 | * Controls an audio stream.
|
---|
1393 | *
|
---|
1394 | * @returns VBox status code.
|
---|
1395 | * @param pInterface Pointer to the interface structure containing the called function pointer.
|
---|
1396 | * @param pStream Pointer to audio stream.
|
---|
1397 | * @param enmStreamCmd The stream command to issue.
|
---|
1398 | */
|
---|
1399 | DECLR3CALLBACKMEMBER(int, pfnStreamControl, (PPDMIHOSTAUDIO pInterface, PPDMAUDIOBACKENDSTREAM pStream, PDMAUDIOSTREAMCMD enmStreamCmd));
|
---|
1400 |
|
---|
1401 | /**
|
---|
1402 | * Returns the amount which is readable from the audio (input) stream.
|
---|
1403 | *
|
---|
1404 | * @returns For non-raw layout streams: Number of readable bytes.
|
---|
1405 | * for raw layout streams : Number of readable audio frames.
|
---|
1406 | * @param pInterface Pointer to the interface structure containing the called function pointer.
|
---|
1407 | * @param pStream Pointer to audio stream.
|
---|
1408 | */
|
---|
1409 | DECLR3CALLBACKMEMBER(uint32_t, pfnStreamGetReadable, (PPDMIHOSTAUDIO pInterface, PPDMAUDIOBACKENDSTREAM pStream));
|
---|
1410 |
|
---|
1411 | /**
|
---|
1412 | * Returns the amount which is writable to the audio (output) stream.
|
---|
1413 | *
|
---|
1414 | * @returns For non-raw layout streams: Number of writable bytes.
|
---|
1415 | * for raw layout streams : Number of writable audio frames.
|
---|
1416 | * @param pInterface Pointer to the interface structure containing the called function pointer.
|
---|
1417 | * @param pStream Pointer to audio stream.
|
---|
1418 | */
|
---|
1419 | DECLR3CALLBACKMEMBER(uint32_t, pfnStreamGetWritable, (PPDMIHOSTAUDIO pInterface, PPDMAUDIOBACKENDSTREAM pStream));
|
---|
1420 |
|
---|
1421 | /**
|
---|
1422 | * Returns the amount which is pending (in other words has not yet been processed) by/from the backend yet.
|
---|
1423 | * Optional.
|
---|
1424 | *
|
---|
1425 | * For input streams this is read audio data by the backend which has not been processed by the host yet.
|
---|
1426 | * For output streams this is written audio data to the backend which has not been processed by the backend yet.
|
---|
1427 | *
|
---|
1428 | * @returns For non-raw layout streams: Number of pending bytes.
|
---|
1429 | * for raw layout streams : Number of pending audio frames.
|
---|
1430 | * @param pInterface Pointer to the interface structure containing the called function pointer.
|
---|
1431 | * @param pStream Pointer to audio stream.
|
---|
1432 | */
|
---|
1433 | DECLR3CALLBACKMEMBER(uint32_t, pfnStreamGetPending, (PPDMIHOSTAUDIO pInterface, PPDMAUDIOBACKENDSTREAM pStream));
|
---|
1434 |
|
---|
1435 | /**
|
---|
1436 | * Returns the current status of the given backend stream.
|
---|
1437 | *
|
---|
1438 | * @returns PDMAUDIOSTREAMSTS
|
---|
1439 | * @param pInterface Pointer to the interface structure containing the called function pointer.
|
---|
1440 | * @param pStream Pointer to audio stream.
|
---|
1441 | */
|
---|
1442 | DECLR3CALLBACKMEMBER(PDMAUDIOSTREAMSTS, pfnStreamGetStatus, (PPDMIHOSTAUDIO pInterface, PPDMAUDIOBACKENDSTREAM pStream));
|
---|
1443 |
|
---|
1444 | /**
|
---|
1445 | * Gives the host backend the chance to do some (necessary) iteration work.
|
---|
1446 | *
|
---|
1447 | * @returns VBox status code.
|
---|
1448 | * @param pInterface Pointer to the interface structure containing the called function pointer.
|
---|
1449 | * @param pStream Pointer to audio stream.
|
---|
1450 | */
|
---|
1451 | DECLR3CALLBACKMEMBER(int, pfnStreamIterate, (PPDMIHOSTAUDIO pInterface, PPDMAUDIOBACKENDSTREAM pStream));
|
---|
1452 |
|
---|
1453 | /**
|
---|
1454 | * Signals the backend that the host wants to begin playing for this iteration. Optional.
|
---|
1455 | *
|
---|
1456 | * @param pInterface Pointer to the interface structure containing the called function pointer.
|
---|
1457 | * @param pStream Pointer to audio stream.
|
---|
1458 | */
|
---|
1459 | DECLR3CALLBACKMEMBER(void, pfnStreamPlayBegin, (PPDMIHOSTAUDIO pInterface, PPDMAUDIOBACKENDSTREAM pStream));
|
---|
1460 |
|
---|
1461 | /**
|
---|
1462 | * Plays (writes to) an audio (output) stream.
|
---|
1463 | *
|
---|
1464 | * @returns VBox status code.
|
---|
1465 | * @param pInterface Pointer to the interface structure containing the called function pointer.
|
---|
1466 | * @param pStream Pointer to audio stream.
|
---|
1467 | * @param pvBuf Pointer to audio data buffer to play.
|
---|
1468 | * @param cxBuf For non-raw layout streams: Size (in bytes) of audio data buffer,
|
---|
1469 | * for raw layout streams : Size (in audio frames) of audio data buffer.
|
---|
1470 | * @param pcxWritten For non-raw layout streams: Returns number of bytes written. Optional.
|
---|
1471 | * for raw layout streams : Returns number of frames written. Optional.
|
---|
1472 | */
|
---|
1473 | DECLR3CALLBACKMEMBER(int, pfnStreamPlay, (PPDMIHOSTAUDIO pInterface, PPDMAUDIOBACKENDSTREAM pStream, const void *pvBuf, uint32_t cxBuf, uint32_t *pcxWritten));
|
---|
1474 |
|
---|
1475 | /**
|
---|
1476 | * Signals the backend that the host finished playing for this iteration. Optional.
|
---|
1477 | *
|
---|
1478 | * @param pInterface Pointer to the interface structure containing the called function pointer.
|
---|
1479 | * @param pStream Pointer to audio stream.
|
---|
1480 | */
|
---|
1481 | DECLR3CALLBACKMEMBER(void, pfnStreamPlayEnd, (PPDMIHOSTAUDIO pInterface, PPDMAUDIOBACKENDSTREAM pStream));
|
---|
1482 |
|
---|
1483 | /**
|
---|
1484 | * Signals the backend that the host wants to begin capturing for this iteration. Optional.
|
---|
1485 | *
|
---|
1486 | * @param pInterface Pointer to the interface structure containing the called function pointer.
|
---|
1487 | * @param pStream Pointer to audio stream.
|
---|
1488 | */
|
---|
1489 | DECLR3CALLBACKMEMBER(void, pfnStreamCaptureBegin, (PPDMIHOSTAUDIO pInterface, PPDMAUDIOBACKENDSTREAM pStream));
|
---|
1490 |
|
---|
1491 | /**
|
---|
1492 | * Captures (reads from) an audio (input) stream.
|
---|
1493 | *
|
---|
1494 | * @returns VBox status code.
|
---|
1495 | * @param pInterface Pointer to the interface structure containing the called function pointer.
|
---|
1496 | * @param pStream Pointer to audio stream.
|
---|
1497 | * @param pvBuf Buffer where to store read audio data.
|
---|
1498 | * @param cxBuf For non-raw layout streams: Size (in bytes) of audio data buffer,
|
---|
1499 | * for raw layout streams : Size (in audio frames) of audio data buffer.
|
---|
1500 | * @param pcxRead For non-raw layout streams: Returns number of bytes read. Optional.
|
---|
1501 | * for raw layout streams : Returns number of frames read. Optional.
|
---|
1502 | */
|
---|
1503 | DECLR3CALLBACKMEMBER(int, pfnStreamCapture, (PPDMIHOSTAUDIO pInterface, PPDMAUDIOBACKENDSTREAM pStream, void *pvBuf, uint32_t cxBuf, uint32_t *pcxRead));
|
---|
1504 |
|
---|
1505 | /**
|
---|
1506 | * Signals the backend that the host finished capturing for this iteration. Optional.
|
---|
1507 | *
|
---|
1508 | * @param pInterface Pointer to the interface structure containing the called function pointer.
|
---|
1509 | * @param pStream Pointer to audio stream.
|
---|
1510 | */
|
---|
1511 | DECLR3CALLBACKMEMBER(void, pfnStreamCaptureEnd, (PPDMIHOSTAUDIO pInterface, PPDMAUDIOBACKENDSTREAM pStream));
|
---|
1512 |
|
---|
1513 | } PDMIHOSTAUDIO;
|
---|
1514 |
|
---|
1515 | /** PDMIHOSTAUDIO interface ID. */
|
---|
1516 | #define PDMIHOSTAUDIO_IID "640F5A31-8245-491C-538F-29A0F9D08881"
|
---|
1517 |
|
---|
1518 | /** @} */
|
---|
1519 |
|
---|
1520 | #endif /* !___VBox_vmm_pdmaudioifs_h */
|
---|
1521 |
|
---|