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