VirtualBox

source: vbox/trunk/include/VBox/vmm/pdmaudioifs.h@ 89229

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

Audio: Must have a PDMAUDIOHOSTDEV_F_DEFAULT flag for each direction or we'll mess up when two duplex devices are default devices for one direction each. Added a pszId member to the enumeration entires. Rewrote the core audio enumeration code. bugref:9890

  • 屬性 svn:eol-style 設為 native
  • 屬性 svn:keywords 設為 Author Date Id Revision
檔案大小: 66.9 KB
 
1/** @file
2 * PDM - Pluggable Device Manager, Audio interfaces.
3 */
4
5/*
6 * Copyright (C) 2006-2020 Oracle Corporation
7 *
8 * This file is part of VirtualBox Open Source Edition (OSE), as
9 * available from http://www.alldomusa.eu.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/** @page pg_pdm_audio PDM Audio
27 *
28 * @section sec_pdm_audio_overview Audio architecture overview
29 *
30 * The audio architecture mainly consists of two PDM interfaces,
31 * PDMIAUDIOCONNECTOR and PDMIHOSTAUDIO.
32 *
33 * The PDMIAUDIOCONNECTOR interface is responsible of connecting a device
34 * emulation, such as SB16, AC'97 and HDA to one or multiple audio backend(s).
35 * Its API abstracts audio stream handling and I/O functions, device enumeration
36 * and so on.
37 *
38 * The PDMIHOSTAUDIO interface must be implemented by all audio backends to
39 * provide an abstract and common way of accessing needed functions, such as
40 * transferring output audio data for playing audio or recording input from the
41 * host.
42 *
43 * A device emulation can have one or more LUNs attached to it, whereas these
44 * LUNs in turn then all have their own PDMIAUDIOCONNECTOR, making it possible
45 * to connect multiple backends to a certain device emulation stream
46 * (multiplexing).
47 *
48 * An audio backend's job is to record and/or play audio data (depending on its
49 * capabilities). It highly depends on the host it's running on and needs very
50 * specific (host-OS-dependent) code. The backend itself only has very limited
51 * ways of accessing and/or communicating with the PDMIAUDIOCONNECTOR interface
52 * via callbacks, but never directly with the device emulation or other parts of
53 * the audio sub system.
54 *
55 *
56 * @section sec_pdm_audio_mixing Mixing
57 *
58 * The AUDIOMIXER API is optionally available to create and manage virtual audio
59 * mixers. Such an audio mixer in turn then can be used by the device emulation
60 * code to manage all the multiplexing to/from the connected LUN audio streams.
61 *
62 * Currently only input and output stream are supported. Duplex stream are not
63 * supported yet.
64 *
65 * This also is handy if certain LUN audio streams should be added or removed
66 * during runtime.
67 *
68 * To create a group of either input or output streams the AUDMIXSINK API can be
69 * used.
70 *
71 * For example: The device emulation has one hardware output stream (HW0), and
72 * that output stream shall be available to all connected LUN backends. For that
73 * to happen, an AUDMIXSINK sink has to be created and attached to the device's
74 * AUDIOMIXER object.
75 *
76 * As every LUN has its own AUDMIXSTREAM object, adding all those
77 * objects to the just created audio mixer sink will do the job.
78 *
79 * @note The AUDIOMIXER API is purely optional and is not used by all currently
80 * implemented device emulations (e.g. SB16).
81 *
82 *
83 * @section sec_pdm_audio_data_processing Data processing
84 *
85 * Audio input / output data gets handed off to/from the device emulation in an
86 * unmodified (raw) way. The actual audio frame / sample conversion is done via
87 * the AUDIOMIXBUF API.
88 *
89 * This concentrates the audio data processing in one place and makes it easier
90 * to test / benchmark such code.
91 *
92 * A PDMAUDIOFRAME is the internal representation of a single audio frame, which
93 * consists of a single left and right audio sample in time. Only mono (1) and
94 * stereo (2) channel(s) currently are supported.
95 *
96 *
97 * @section sec_pdm_audio_timing Timing
98 *
99 * Handling audio data in a virtual environment is hard, as the human perception
100 * is very sensitive to the slightest cracks and stutters in the audible data.
101 * This can happen if the VM's timing is lagging behind or not within the
102 * expected time frame.
103 *
104 * The two main components which unfortunately contradict each other is a) the
105 * audio device emulation and b) the audio backend(s) on the host. Those need to
106 * be served in a timely manner to function correctly. To make e.g. the device
107 * emulation rely on the pace the host backend(s) set - or vice versa - will not
108 * work, as the guest's audio system / drivers then will not be able to
109 * compensate this accordingly.
110 *
111 * So each component, the device emulation, the audio connector(s) and the
112 * backend(s) must do its thing *when* it needs to do it, independently of the
113 * others. For that we use various (small) ring buffers to (hopefully) serve all
114 * components with the amount of data *when* they need it.
115 *
116 * Additionally, the device emulation can run with a different audio frame size,
117 * while the backends(s) may require a different frame size (16 bit stereo
118 * -> 8 bit mono, for example).
119 *
120 * The device emulation can give the audio connector(s) a scheduling hint
121 * (optional), e.g. in which interval it expects any data processing.
122 *
123 * A data transfer for playing audio data from the guest on the host looks like
124 * this: (RB = Ring Buffer, MB = Mixing Buffer)
125 *
126 * (A) Device DMA -> (B) Device RB -> (C) Audio Connector %Guest MB -> (D) Audio
127 * Connector %Host MB -> (E) Backend RB (optional, up to the backend) -> (F)
128 * Backend audio framework.
129 *
130 * When capturing audio data the chain is similar to the above one, just in a
131 * different direction, of course.
132 *
133 * The audio connector hereby plays a key role when it comes to (pre-)buffering
134 * data to minimize any audio stutters and/or cracks. The following values,
135 * which also can be tweaked via CFGM / extra-data are available:
136 *
137 * - The pre-buffering time (in ms): Audio data which needs to be buffered
138 * before any playback (or capturing) can happen.
139 * - The actual buffer size (in ms): How big the mixing buffer (for C and D)
140 * will be.
141 * - The period size (in ms): How big a chunk of audio (often called period or
142 * fragment) for F must be to get handled correctly.
143 *
144 * The above values can be set on a per-driver level, whereas input and output
145 * streams for a driver also can be handled set independently. The verbose audio
146 * (release) log will tell about the (final) state of each audio stream.
147 *
148 *
149 * @section sec_pdm_audio_diagram Diagram
150 *
151 * @todo r=bird: Not quite able to make sense of this, esp. the
152 * AUDMIXSINK/AUDIOMIXER bits crossing the LUN connections.
153 *
154 * @verbatim
155 +----------------------------------+
156 |Device (SB16 / AC'97 / HDA) |
157 |----------------------------------|
158 |AUDIOMIXER (Optional) |
159 |AUDMIXSINK0 (Optional) |
160 |AUDMIXSINK1 (Optional) |
161 |AUDMIXSINKn (Optional) |
162 | |
163 | L L L |
164 | U U U |
165 | N N N |
166 | 0 1 n |
167 +-----+----+----+------------------+
168 | | |
169 | | |
170 +--------------+ | | | +-------------+
171 |AUDMIXSINK | | | | |AUDIOMIXER |
172 |--------------| | | | |-------------|
173 |AUDMIXSTREAM0 |+-|----|----|-->|AUDMIXSINK0 |
174 |AUDMIXSTREAM1 |+-|----|----|-->|AUDMIXSINK1 |
175 |AUDMIXSTREAMn |+-|----|----|-->|AUDMIXSINKn |
176 +--------------+ | | | +-------------+
177 | | |
178 | | |
179 +----+----+----+----+
180 |LUN |
181 |-------------------|
182 |PDMIAUDIOCONNECTOR |
183 |AUDMIXSTREAM |
184 | +------+
185 | | |
186 | | |
187 | | |
188 +-------------------+ |
189 |
190 +-------------------------+ |
191 +-------------------------+ +----+--------------------+
192 |PDMAUDIOSTREAM | |PDMIAUDIOCONNECTOR |
193 |-------------------------| |-------------------------|
194 |AUDIOMIXBUF |+------>|PDMAUDIOSTREAM Host |
195 |PDMAUDIOSTREAMCFG |+------>|PDMAUDIOSTREAM Guest |
196 | | |Device capabilities |
197 | | |Device configuration |
198 | | | |
199 | | +--+|PDMIHOSTAUDIO |
200 | | | |+-----------------------+|
201 +-------------------------+ | ||Backend storage space ||
202 | |+-----------------------+|
203 | +-------------------------+
204 |
205 +---------------------+ |
206 |PDMIHOSTAUDIO | |
207 |+--------------+ | |
208 ||DirectSound | | |
209 |+--------------+ | |
210 | | |
211 |+--------------+ | |
212 ||PulseAudio | | |
213 |+--------------+ |+-------+
214 | |
215 |+--------------+ |
216 ||Core Audio | |
217 |+--------------+ |
218 | |
219 | |
220 | |
221 | |
222 +---------------------+
223 @endverbatim
224 */
225
226#ifndef VBOX_INCLUDED_vmm_pdmaudioifs_h
227#define VBOX_INCLUDED_vmm_pdmaudioifs_h
228#ifndef RT_WITHOUT_PRAGMA_ONCE
229# pragma once
230#endif
231
232#include <iprt/assertcompile.h>
233#include <iprt/critsect.h>
234#include <iprt/circbuf.h>
235#include <iprt/list.h>
236#include <iprt/path.h>
237
238#include <VBox/types.h>
239#include <VBox/vmm/pdmcommon.h>
240#include <VBox/vmm/stam.h>
241
242/** @defgroup grp_pdm_ifs_audio PDM Audio Interfaces
243 * @ingroup grp_pdm_interfaces
244 * @{
245 */
246
247#ifndef VBOX_AUDIO_DEBUG_DUMP_PCM_DATA_PATH
248# if defined(RT_OS_WINDOWS) || defined(RT_OS_OS2)
249# define VBOX_AUDIO_DEBUG_DUMP_PCM_DATA_PATH "c:\\temp\\"
250# else
251# define VBOX_AUDIO_DEBUG_DUMP_PCM_DATA_PATH "/tmp/"
252# endif
253#endif
254
255/** PDM audio driver instance flags. */
256typedef uint32_t PDMAUDIODRVFLAGS;
257
258/** No flags set. */
259#define PDMAUDIODRVFLAGS_NONE 0
260/** Marks a primary audio driver which is critical
261 * when running the VM. */
262#define PDMAUDIODRVFLAGS_PRIMARY RT_BIT(0)
263
264/**
265 * Audio format in signed or unsigned variants.
266 */
267typedef enum PDMAUDIOFMT
268{
269 /** Invalid format, do not use. */
270 PDMAUDIOFMT_INVALID = 0,
271 /** 8-bit, unsigned. */
272 PDMAUDIOFMT_U8,
273 /** 8-bit, signed. */
274 PDMAUDIOFMT_S8,
275 /** 16-bit, unsigned. */
276 PDMAUDIOFMT_U16,
277 /** 16-bit, signed. */
278 PDMAUDIOFMT_S16,
279 /** 32-bit, unsigned. */
280 PDMAUDIOFMT_U32,
281 /** 32-bit, signed. */
282 PDMAUDIOFMT_S32,
283 /** End of valid values. */
284 PDMAUDIOFMT_END,
285 /** Hack to blow the type up to 32-bit. */
286 PDMAUDIOFMT_32BIT_HACK = 0x7fffffff
287} PDMAUDIOFMT;
288
289/**
290 * Audio direction.
291 */
292typedef enum PDMAUDIODIR
293{
294 /** Invalid zero value as per usual (guards against using unintialized values). */
295 PDMAUDIODIR_INVALID = 0,
296 /** Unknown direction. */
297 PDMAUDIODIR_UNKNOWN,
298 /** Input. */
299 PDMAUDIODIR_IN,
300 /** Output. */
301 PDMAUDIODIR_OUT,
302 /** Duplex handling. */
303 PDMAUDIODIR_DUPLEX,
304 /** End of valid values. */
305 PDMAUDIODIR_END,
306 /** Hack to blow the type up to 32-bit. */
307 PDMAUDIODIR_32BIT_HACK = 0x7fffffff
308} PDMAUDIODIR;
309
310
311/** @name PDMAUDIOHOSTDEV_F_XXX
312 * @{ */
313/** No flags set. */
314#define PDMAUDIOHOSTDEV_F_NONE UINT32_C(0)
315/** The default input (capture/recording) device (for the user). */
316#define PDMAUDIOHOSTDEV_F_DEFAULT_IN RT_BIT_32(0)
317/** The default output (playback) device (for the user). */
318#define PDMAUDIOHOSTDEV_F_DEFAULT_OUT RT_BIT_32(1)
319/** The device can be removed at any time and we have to deal with it. */
320#define PDMAUDIOHOSTDEV_F_HOTPLUG RT_BIT_32(2)
321/** The device is known to be buggy and needs special treatment. */
322#define PDMAUDIOHOSTDEV_F_BUGGY RT_BIT_32(3)
323/** Ignore the device, no matter what. */
324#define PDMAUDIOHOSTDEV_F_IGNORE RT_BIT_32(4)
325/** The device is present but marked as locked by some other application. */
326#define PDMAUDIOHOSTDEV_F_LOCKED RT_BIT_32(5)
327/** The device is present but not in an alive state (dead). */
328#define PDMAUDIOHOSTDEV_F_DEAD RT_BIT_32(6)
329/** Set if the extra backend specific data cannot be duplicated. */
330#define PDMAUDIOHOSTDEV_F_NO_DUP RT_BIT_32(31)
331/** @} */
332
333/**
334 * Audio device type.
335 */
336typedef enum PDMAUDIODEVICETYPE
337{
338 /** Invalid zero value as per usual (guards against using unintialized values). */
339 PDMAUDIODEVICETYPE_INVALID = 0,
340 /** Unknown device type. This is the default. */
341 PDMAUDIODEVICETYPE_UNKNOWN,
342 /** Dummy device; for backends which are not able to report
343 * actual device information (yet). */
344 PDMAUDIODEVICETYPE_DUMMY,
345 /** The device is built into the host (non-removable). */
346 PDMAUDIODEVICETYPE_BUILTIN,
347 /** The device is an (external) USB device. */
348 PDMAUDIODEVICETYPE_USB,
349 /** End of valid values. */
350 PDMAUDIODEVICETYPE_END,
351 /** Hack to blow the type up to 32-bit. */
352 PDMAUDIODEVICETYPE_32BIT_HACK = 0x7fffffff
353} PDMAUDIODEVICETYPE;
354
355/**
356 * Host audio device info, part of enumeration result.
357 *
358 * @sa PDMAUDIOHOSTENUM, PDMIHOSTAUDIO::pfnGetDevices
359 */
360typedef struct PDMAUDIOHOSTDEV
361{
362 /** List entry (like PDMAUDIOHOSTENUM::LstDevices). */
363 RTLISTNODE ListEntry;
364 /** Magic value (PDMAUDIOHOSTDEV_MAGIC). */
365 uint32_t uMagic;
366 /** Size of this structure and whatever backend specific data that follows it. */
367 uint32_t cbSelf;
368 /** The device type. */
369 PDMAUDIODEVICETYPE enmType;
370 /** Usage of the device. */
371 PDMAUDIODIR enmUsage;
372 /** Device flags, PDMAUDIOHOSTDEV_F_XXX. */
373 uint32_t fFlags;
374 /** Maximum number of input audio channels the device supports. */
375 uint8_t cMaxInputChannels;
376 /** Maximum number of output audio channels the device supports. */
377 uint8_t cMaxOutputChannels;
378 uint8_t abAlignment[ARCH_BITS == 32 ? 2 + 12 : 2];
379 /** Device identifier, OS specific, can be NULL. It it isn't, it'll point to
380 * the non-public part (or into szName if creative). */
381 const char *pszId;
382 /** Friendly name of the device, if any. Could be truncated. */
383 char szName[64];
384} PDMAUDIOHOSTDEV;
385AssertCompileSizeAlignment(PDMAUDIOHOSTDEV, 16);
386/** Pointer to audio device info (enumeration result). */
387typedef PDMAUDIOHOSTDEV *PPDMAUDIOHOSTDEV;
388/** Pointer to a const audio device info (enumeration result). */
389typedef PDMAUDIOHOSTDEV const *PCPDMAUDIOHOSTDEV;
390
391/** Magic value for PDMAUDIOHOSTDEV. */
392#define PDMAUDIOHOSTDEV_MAGIC PDM_VERSION_MAKE(0xa0d0, 2, 0)
393
394
395/**
396 * A host audio device enumeration result.
397 *
398 * @sa PDMIHOSTAUDIO::pfnGetDevices
399 */
400typedef struct PDMAUDIOHOSTENUM
401{
402 /** Magic value (PDMAUDIOHOSTENUM_MAGIC). */
403 uint32_t uMagic;
404 /** Number of audio devices in the list. */
405 uint32_t cDevices;
406 /** List of audio devices (PDMAUDIOHOSTDEV). */
407 RTLISTANCHOR LstDevices;
408} PDMAUDIOHOSTENUM;
409/** Pointer to an audio device enumeration result. */
410typedef PDMAUDIOHOSTENUM *PPDMAUDIOHOSTENUM;
411/** Pointer to a const audio device enumeration result. */
412typedef PDMAUDIOHOSTENUM const *PCPDMAUDIOHOSTENUM;
413
414/** Magic for the host audio device enumeration. */
415#define PDMAUDIOHOSTENUM_MAGIC PDM_VERSION_MAKE(0xa0d1, 1, 0)
416
417
418/**
419 * Audio configuration (static) of an audio host backend.
420 */
421typedef struct PDMAUDIOBACKENDCFG
422{
423 /** The backend's friendly name. */
424 char szName[32];
425 /** The size of the backend specific stream data (in bytes). */
426 uint32_t cbStream;
427 /** PDMAUDIOBACKEND_F_XXX. */
428 uint32_t fFlags;
429 /** Number of concurrent output (playback) streams supported on the host.
430 * UINT32_MAX for unlimited concurrent streams, 0 if no concurrent input streams are supported. */
431 uint32_t cMaxStreamsOut;
432 /** Number of concurrent input (recording) streams supported on the host.
433 * UINT32_MAX for unlimited concurrent streams, 0 if no concurrent input streams are supported. */
434 uint32_t cMaxStreamsIn;
435} PDMAUDIOBACKENDCFG;
436/** Pointer to a static host audio audio configuration. */
437typedef PDMAUDIOBACKENDCFG *PPDMAUDIOBACKENDCFG;
438
439/** @name PDMAUDIOBACKEND_F_XXX - PDMAUDIOBACKENDCFG::fFlags
440 * @{ */
441/** PDMIHOSTAUDIO::pfnStreamConfigHint should preferably be called on a
442 * worker thread rather than EMT as it may take a good while. */
443#define PDMAUDIOBACKEND_F_ASYNC_HINT RT_BIT_32(0)
444/** PDMIHOSTAUDIO::pfnStreamDestroy and any preceeding
445 * PDMIHOSTAUDIO::pfnStreamControl/DISABLE should be preferably be called on a
446 * worker thread rather than EMT as it may take a good while. */
447#define PDMAUDIOBACKEND_F_ASYNC_STREAM_DESTROY RT_BIT_32(1)
448/** @} */
449
450
451/**
452 * A single audio frame.
453 *
454 * Currently only two (2) channels, left and right, are supported.
455 *
456 * @note When changing this structure, make sure to also handle
457 * VRDP's input / output processing in DrvAudioVRDE, as VRDP
458 * expects audio data in st_sample_t format (historical reasons)
459 * which happens to be the same as PDMAUDIOFRAME for now.
460 *
461 * @todo r=bird: This is an internal AudioMixBuffer structure which should not
462 * be exposed here, I think. Only used to some sizeof statements in VRDE.
463 * (The problem with exposing it, is that we would like to move away from
464 * stereo and instead to anything from 1 to 16 channels. That means
465 * removing this structure entirely.)
466 */
467typedef struct PDMAUDIOFRAME
468{
469 /** Left channel. */
470 int64_t i64LSample;
471 /** Right channel. */
472 int64_t i64RSample;
473} PDMAUDIOFRAME;
474/** Pointer to a single (stereo) audio frame. */
475typedef PDMAUDIOFRAME *PPDMAUDIOFRAME;
476/** Pointer to a const single (stereo) audio frame. */
477typedef PDMAUDIOFRAME const *PCPDMAUDIOFRAME;
478
479
480/**
481 * Audio path: input sources and playback destinations.
482 *
483 * Think of this as the name of the socket you plug the virtual audio stream
484 * jack into.
485 *
486 * @note Not quite sure what the purpose of this type is. It used to be two
487 * separate enums (PDMAUDIOPLAYBACKDST & PDMAUDIORECSRC) without overlapping
488 * values and most commonly used in a union (PDMAUDIODSTSRCUNION). The output
489 * values were designated "channel" (e.g. "Front channel"), whereas this was not
490 * done to the input ones. So, I'm (bird) a little confused what the actual
491 * meaning was.
492 */
493typedef enum PDMAUDIOPATH
494{
495 /** Customary invalid zero value. */
496 PDMAUDIOPATH_INVALID = 0,
497
498 /** Unknown path / Doesn't care. */
499 PDMAUDIOPATH_UNKNOWN,
500
501 /** First output value. */
502 PDMAUDIOPATH_OUT_FIRST,
503 /** Output: Front. */
504 PDMAUDIOPATH_OUT_FRONT = PDMAUDIOPATH_OUT_FIRST,
505 /** Output: Center / LFE (Subwoofer). */
506 PDMAUDIOPATH_OUT_CENTER_LFE,
507 /** Output: Rear. */
508 PDMAUDIOPATH_OUT_REAR,
509 /** Last output value (inclusive) */
510 PDMAUDIOPATH_OUT_END = PDMAUDIOPATH_OUT_REAR,
511
512 /** First input value. */
513 PDMAUDIOPATH_IN_FIRST,
514 /** Input: Microphone. */
515 PDMAUDIOPATH_IN_MIC = PDMAUDIOPATH_IN_FIRST,
516 /** Input: CD. */
517 PDMAUDIOPATH_IN_CD,
518 /** Input: Video-In. */
519 PDMAUDIOPATH_IN_VIDEO,
520 /** Input: AUX. */
521 PDMAUDIOPATH_IN_AUX,
522 /** Input: Line-In. */
523 PDMAUDIOPATH_IN_LINE,
524 /** Input: Phone-In. */
525 PDMAUDIOPATH_IN_PHONE,
526 /** Last intput value (inclusive). */
527 PDMAUDIOPATH_IN_LAST = PDMAUDIOPATH_IN_PHONE,
528
529 /** End of valid values. */
530 PDMAUDIOPATH_END,
531 /** Hack to blow the typ up to 32 bits. */
532 PDMAUDIOPATH_32BIT_HACK = 0x7fffffff
533} PDMAUDIOPATH;
534
535/**
536 * Audio stream (data) layout.
537 */
538typedef enum PDMAUDIOSTREAMLAYOUT
539{
540 /** Invalid zero value as per usual (guards against using unintialized values). */
541 PDMAUDIOSTREAMLAYOUT_INVALID = 0,
542 /** Unknown access type; do not use (hdaR3StreamMapReset uses it). */
543 PDMAUDIOSTREAMLAYOUT_UNKNOWN,
544 /** Non-interleaved access, that is, consecutive access to the data.
545 * @todo r=bird: For plain stereo this is actually interleaves left/right. What
546 * I guess non-interleaved means, is that there are no additional
547 * information interleaved next to the interleaved stereo.
548 * https://stackoverflow.com/questions/17879933/whats-the-interleaved-audio */
549 PDMAUDIOSTREAMLAYOUT_NON_INTERLEAVED,
550 /** Interleaved access, where the data can be mixed together with data of other audio streams. */
551 PDMAUDIOSTREAMLAYOUT_INTERLEAVED,
552 /** Complex layout, which does not fit into the interleaved / non-interleaved layouts. */
553 PDMAUDIOSTREAMLAYOUT_COMPLEX,
554 /** Raw (pass through) data, with no data layout processing done.
555 *
556 * This means that this stream will operate on PDMAUDIOFRAME data
557 * directly. Don't use this if you don't have to.
558 *
559 * @deprecated Replaced by S64 (signed, 64-bit sample size). */
560 PDMAUDIOSTREAMLAYOUT_RAW,
561 /** End of valid values. */
562 PDMAUDIOSTREAMLAYOUT_END,
563 /** Hack to blow the type up to 32-bit. */
564 PDMAUDIOSTREAMLAYOUT_32BIT_HACK = 0x7fffffff
565} PDMAUDIOSTREAMLAYOUT;
566
567/**
568 * Stream channel data block.
569 */
570typedef struct PDMAUDIOSTREAMCHANNELDATA
571{
572 /** Circular buffer for the channel data. */
573 PRTCIRCBUF pCircBuf;
574 /** Amount of audio data (in bytes) acquired for reading. */
575 size_t cbAcq;
576 /** Channel data flags, PDMAUDIOSTREAMCHANNELDATA_FLAGS_XXX. */
577 uint32_t fFlags;
578} PDMAUDIOSTREAMCHANNELDATA;
579/** Pointer to audio stream channel data buffer. */
580typedef PDMAUDIOSTREAMCHANNELDATA *PPDMAUDIOSTREAMCHANNELDATA;
581
582/** @name PDMAUDIOSTREAMCHANNELDATA_FLAGS_XXX
583 * @{ */
584/** No stream channel data flags defined. */
585#define PDMAUDIOSTREAMCHANNELDATA_FLAGS_NONE UINT32_C(0)
586/** @} */
587
588/**
589 * Standard speaker channel IDs.
590 *
591 * This can cover up to 11.0 surround sound.
592 *
593 * @note Any of those channels can be marked / used as the LFE channel (played
594 * through the subwoofer).
595 */
596typedef enum PDMAUDIOSTREAMCHANNELID
597{
598 /** Invalid zero value as per usual (guards against using unintialized values). */
599 PDMAUDIOSTREAMCHANNELID_INVALID = 0,
600 /** Unknown / not set channel ID. */
601 PDMAUDIOSTREAMCHANNELID_UNKNOWN,
602 /** Front left channel. */
603 PDMAUDIOSTREAMCHANNELID_FRONT_LEFT,
604 /** Front right channel. */
605 PDMAUDIOSTREAMCHANNELID_FRONT_RIGHT,
606 /** Front center channel. */
607 PDMAUDIOSTREAMCHANNELID_FRONT_CENTER,
608 /** Low frequency effects (subwoofer) channel. */
609 PDMAUDIOSTREAMCHANNELID_LFE,
610 /** Rear left channel. */
611 PDMAUDIOSTREAMCHANNELID_REAR_LEFT,
612 /** Rear right channel. */
613 PDMAUDIOSTREAMCHANNELID_REAR_RIGHT,
614 /** Front left of center channel. */
615 PDMAUDIOSTREAMCHANNELID_FRONT_LEFT_OF_CENTER,
616 /** Front right of center channel. */
617 PDMAUDIOSTREAMCHANNELID_FRONT_RIGHT_OF_CENTER,
618 /** Rear center channel. */
619 PDMAUDIOSTREAMCHANNELID_REAR_CENTER,
620 /** Side left channel. */
621 PDMAUDIOSTREAMCHANNELID_SIDE_LEFT,
622 /** Side right channel. */
623 PDMAUDIOSTREAMCHANNELID_SIDE_RIGHT,
624 /** Left height channel. */
625 PDMAUDIOSTREAMCHANNELID_LEFT_HEIGHT,
626 /** Right height channel. */
627 PDMAUDIOSTREAMCHANNELID_RIGHT_HEIGHT,
628 /** End of valid values. */
629 PDMAUDIOSTREAMCHANNELID_END,
630 /** Hack to blow the type up to 32-bit. */
631 PDMAUDIOSTREAMCHANNELID_32BIT_HACK = 0x7fffffff
632} PDMAUDIOSTREAMCHANNELID;
633
634/**
635 * Mappings channels onto an audio stream.
636 *
637 * The mappings are either for a single (mono) or dual (stereo) channels onto an
638 * audio stream (aka stream profile). An audio stream consists of one or
639 * multiple channels (e.g. 1 for mono, 2 for stereo), depending on the
640 * configuration.
641 */
642typedef struct PDMAUDIOSTREAMMAP
643{
644 /** Array of channel IDs being handled.
645 * @note The first (zero-based) index specifies the leftmost channel. */
646 PDMAUDIOSTREAMCHANNELID aenmIDs[2];
647 /** Step size (in bytes) to the channel's next frame. */
648 uint32_t cbStep;
649 /** Frame size (in bytes) of this channel. */
650 uint32_t cbFrame;
651 /** Byte offset to the first frame in the data block. */
652 uint32_t offFirst;
653 /** Byte offset to the next frame in the data block. */
654 uint32_t offNext;
655 /** Associated data buffer. */
656 PDMAUDIOSTREAMCHANNELDATA Data;
657
658 /** @todo r=bird: I'd structure this very differently.
659 * I would've had an array of channel descriptors like this:
660 *
661 * struct PDMAUDIOCHANNELDESC
662 * {
663 * uint8_t off; //< Stream offset in bytes.
664 * uint8_t id; //< PDMAUDIOSTREAMCHANNELID
665 * };
666 *
667 * And I'd baked it into PDMAUDIOPCMPROPS as a fixed sized array with 16 entries
668 * (max HDA channel count IIRC). */
669} PDMAUDIOSTREAMMAP;
670/** Pointer to an audio stream channel mapping. */
671typedef PDMAUDIOSTREAMMAP *PPDMAUDIOSTREAMMAP;
672
673/**
674 * Properties of audio streams for host/guest for in or out directions.
675 */
676typedef struct PDMAUDIOPCMPROPS
677{
678 /** The frame size. */
679 uint8_t cbFrame;
680 /** Shift count used with PDMAUDIOPCMPROPS_F2B and PDMAUDIOPCMPROPS_B2F.
681 * Depends on number of stream channels and the stream format being used, calc
682 * value using PDMAUDIOPCMPROPS_MAKE_SHIFT.
683 * @sa PDMAUDIOSTREAMCFG_B2F, PDMAUDIOSTREAMCFG_F2B */
684 uint8_t cShiftX;
685 /** Sample width (in bytes). */
686 RT_GCC_EXTENSION
687 uint8_t cbSampleX : 4;
688 /** Number of audio channels. */
689 RT_GCC_EXTENSION
690 uint8_t cChannelsX : 4;
691 /** Signed or unsigned sample. */
692 bool fSigned : 1;
693 /** Whether the endianness is swapped or not. */
694 bool fSwapEndian : 1;
695 /** Raw mixer frames, only applicable for signed 64-bit samples. */
696 bool fRaw : 1;
697 /** Sample frequency in Hertz (Hz). */
698 uint32_t uHz;
699} PDMAUDIOPCMPROPS;
700AssertCompileSize(PDMAUDIOPCMPROPS, 8);
701AssertCompileSizeAlignment(PDMAUDIOPCMPROPS, 8);
702/** Pointer to audio stream properties. */
703typedef PDMAUDIOPCMPROPS *PPDMAUDIOPCMPROPS;
704/** Pointer to const audio stream properties. */
705typedef PDMAUDIOPCMPROPS const *PCPDMAUDIOPCMPROPS;
706
707/** @name Macros for use with PDMAUDIOPCMPROPS
708 * @{ */
709/** Initializer for PDMAUDIOPCMPROPS. */
710#define PDMAUDIOPCMPROPS_INITIALIZER(a_cbSample, a_fSigned, a_cChannels, a_uHz, a_fSwapEndian) \
711 { (a_cbSample) * (a_cChannels), PDMAUDIOPCMPROPS_MAKE_SHIFT_PARMS(a_cbSample, a_cChannels), a_cbSample, a_cChannels, \
712 a_fSigned, a_fSwapEndian, false /*fRaw*/, a_uHz }
713/** Calculates the cShift value of given sample bits and audio channels.
714 * @note Does only support mono/stereo channels for now, for non-stereo/mono we
715 * returns a special value which the two conversion functions detect
716 * and make them fall back on cbSample * cChannels. */
717#define PDMAUDIOPCMPROPS_MAKE_SHIFT_PARMS(cbSample, cChannels) \
718 ( RT_IS_POWER_OF_TWO((unsigned)((cChannels) * (cbSample))) \
719 ? (uint8_t)(ASMBitFirstSetU32((unsigned)((cChannels) * (cbSample))) - 1) : (uint8_t)UINT8_MAX )
720/** Calculates the cShift value of a PDMAUDIOPCMPROPS structure. */
721#define PDMAUDIOPCMPROPS_MAKE_SHIFT(pProps) \
722 PDMAUDIOPCMPROPS_MAKE_SHIFT_PARMS((pProps)->cbSampleX, (pProps)->cChannelsX)
723/** Converts (audio) frames to bytes.
724 * @note Requires properly initialized properties, i.e. cbFrames correctly calculated
725 * and cShift set using PDMAUDIOPCMPROPS_MAKE_SHIFT. */
726#define PDMAUDIOPCMPROPS_F2B(pProps, cFrames) \
727 ( (pProps)->cShiftX != UINT8_MAX ? (cFrames) << (pProps)->cShiftX : (cFrames) * (pProps)->cbFrame )
728/** Converts bytes to (audio) frames.
729 * @note Requires properly initialized properties, i.e. cbFrames correctly calculated
730 * and cShift set using PDMAUDIOPCMPROPS_MAKE_SHIFT. */
731#define PDMAUDIOPCMPROPS_B2F(pProps, cb) \
732 ( (pProps)->cShiftX != UINT8_MAX ? (cb) >> (pProps)->cShiftX : (cb) / (pProps)->cbFrame )
733/** @} */
734
735/**
736 * An audio stream configuration.
737 */
738typedef struct PDMAUDIOSTREAMCFG
739{
740 /** Direction of the stream. */
741 PDMAUDIODIR enmDir;
742 /** Destination / source path. */
743 PDMAUDIOPATH enmPath;
744 /** The stream's PCM properties. */
745 PDMAUDIOPCMPROPS Props;
746 /** The stream's audio data layout.
747 * This indicates how the audio data buffers to/from the backend is being layouted.
748 *
749 * Currently, the following layouts are supported by the audio connector:
750 *
751 * PDMAUDIOSTREAMLAYOUT_NON_INTERLEAVED:
752 * One stream at once. The consecutive audio data is exactly in the format and frame width
753 * like defined in the PCM properties. This is the default.
754 *
755 * PDMAUDIOSTREAMLAYOUT_RAW:
756 * Can be one or many streams at once, depending on the stream's mixing buffer setup.
757 * The audio data will get handled as PDMAUDIOFRAME frames without any modification done.
758 *
759 * @todo r=bird: See PDMAUDIOSTREAMLAYOUT comments. */
760 PDMAUDIOSTREAMLAYOUT enmLayout;
761 /** Device emulation-specific data needed for the audio connector. */
762 struct
763 {
764 /** Scheduling hint set by the device emulation about when this stream is being served on average (in ms).
765 * Can be 0 if not hint given or some other mechanism (e.g. callbacks) is being used. */
766 uint32_t cMsSchedulingHint;
767 } Device;
768 /**
769 * Backend-specific data for the stream.
770 * On input (requested configuration) those values are set by the audio connector to let the backend know what we expect.
771 * On output (acquired configuration) those values reflect the values set and used by the backend.
772 * Set by the backend on return. Not all backends support all values / features.
773 */
774 struct
775 {
776 /** Period size of the stream (in audio frames).
777 * This value reflects the number of audio frames in between each hardware interrupt on the
778 * backend (host) side. 0 if not set / available by the backend. */
779 uint32_t cFramesPeriod;
780 /** (Ring) buffer size (in audio frames). Often is a multiple of cFramesPeriod.
781 * 0 if not set / available by the backend. */
782 uint32_t cFramesBufferSize;
783 /** Pre-buffering size (in audio frames). Frames needed in buffer before the stream becomes active (pre buffering).
784 * The bigger this value is, the more latency for the stream will occur.
785 * 0 if not set / available by the backend. UINT32_MAX if not defined (yet). */
786 uint32_t cFramesPreBuffering;
787 } Backend;
788 uint32_t u32Padding;
789 /** Friendly name of the stream. */
790 char szName[64];
791} PDMAUDIOSTREAMCFG;
792AssertCompileSizeAlignment(PDMAUDIOSTREAMCFG, 8);
793/** Pointer to audio stream configuration keeper. */
794typedef PDMAUDIOSTREAMCFG *PPDMAUDIOSTREAMCFG;
795/** Pointer to a const audio stream configuration keeper. */
796typedef PDMAUDIOSTREAMCFG const *PCPDMAUDIOSTREAMCFG;
797
798/** Converts (audio) frames to bytes. */
799#define PDMAUDIOSTREAMCFG_F2B(pCfg, frames) PDMAUDIOPCMPROPS_F2B(&(pCfg)->Props, (frames))
800/** Converts bytes to (audio) frames. */
801#define PDMAUDIOSTREAMCFG_B2F(pCfg, cb) PDMAUDIOPCMPROPS_B2F(&(pCfg)->Props, (cb))
802
803/**
804 * Audio mixer controls.
805 */
806typedef enum PDMAUDIOMIXERCTL
807{
808 /** Invalid zero value as per usual (guards against using unintialized values). */
809 PDMAUDIOMIXERCTL_INVALID = 0,
810 /** Unknown mixer control. */
811 PDMAUDIOMIXERCTL_UNKNOWN,
812 /** Master volume. */
813 PDMAUDIOMIXERCTL_VOLUME_MASTER,
814 /** Front. */
815 PDMAUDIOMIXERCTL_FRONT,
816 /** Center / LFE (Subwoofer). */
817 PDMAUDIOMIXERCTL_CENTER_LFE,
818 /** Rear. */
819 PDMAUDIOMIXERCTL_REAR,
820 /** Line-In. */
821 PDMAUDIOMIXERCTL_LINE_IN,
822 /** Microphone-In. */
823 PDMAUDIOMIXERCTL_MIC_IN,
824 /** End of valid values. */
825 PDMAUDIOMIXERCTL_END,
826 /** Hack to blow the type up to 32-bit. */
827 PDMAUDIOMIXERCTL_32BIT_HACK = 0x7fffffff
828} PDMAUDIOMIXERCTL;
829
830/**
831 * Audio stream commands.
832 *
833 * Used in the audio connector as well as in the actual host backends.
834 */
835typedef enum PDMAUDIOSTREAMCMD
836{
837 /** Invalid zero value as per usual (guards against using unintialized values). */
838 PDMAUDIOSTREAMCMD_INVALID = 0,
839 /** Enables the stream. */
840 PDMAUDIOSTREAMCMD_ENABLE,
841 /** Pauses the stream.
842 * This is currently only issued when the VM is suspended (paused).
843 * @remarks This is issued by DrvAudio, never by the mixer or devices. */
844 PDMAUDIOSTREAMCMD_PAUSE,
845 /** Resumes the stream.
846 * This is currently only issued when the VM is resumed.
847 * @remarks This is issued by DrvAudio, never by the mixer or devices. */
848 PDMAUDIOSTREAMCMD_RESUME,
849 /** Drain the stream, that is, play what's in the buffers and then stop.
850 *
851 * There will be no more samples written after this command is issued.
852 * PDMIAUDIOCONNECTOR::pfnStreamIterate will drive progress for DrvAudio and
853 * calls to PDMIHOSTAUDIO::pfnStreamPlay with a zero sized buffer will provide
854 * the backend with a way to drive it forwards. These calls will come at a
855 * frequency set by the device and be on an asynchronous I/O thread.
856 *
857 * A DISABLE command maybe submitted if the device/mixer wants to re-enable the
858 * stream while it's still draining or if it gets impatient and thinks the
859 * draining has been going on too long, in which case the stream should stop
860 * immediately.
861 *
862 * @note This should not wait for the stream to finish draining, just change
863 * the state. (The caller could be an EMT and it must not block for
864 * hundreds of milliseconds of buffer to finish draining.)
865 *
866 * @note Does not apply to input streams. Backends should refuse such requests. */
867 PDMAUDIOSTREAMCMD_DRAIN,
868 /** Stops the stream immediately w/o any draining. */
869 PDMAUDIOSTREAMCMD_DISABLE,
870 /** End of valid values. */
871 PDMAUDIOSTREAMCMD_END,
872 /** Hack to blow the type up to 32-bit. */
873 PDMAUDIOSTREAMCMD_32BIT_HACK = 0x7fffffff
874} PDMAUDIOSTREAMCMD;
875
876/**
877 * Audio volume parameters.
878 */
879typedef struct PDMAUDIOVOLUME
880{
881 /** Set to @c true if this stream is muted, @c false if not. */
882 bool fMuted;
883 /** Left channel volume.
884 * Range is from [0 ... 255], whereas 0 specifies
885 * the most silent and 255 the loudest value. */
886 uint8_t uLeft;
887 /** Right channel volume.
888 * Range is from [0 ... 255], whereas 0 specifies
889 * the most silent and 255 the loudest value. */
890 uint8_t uRight;
891} PDMAUDIOVOLUME;
892/** Pointer to audio volume settings. */
893typedef PDMAUDIOVOLUME *PPDMAUDIOVOLUME;
894/** Pointer to const audio volume settings. */
895typedef PDMAUDIOVOLUME const *PCPDMAUDIOVOLUME;
896
897/** Defines the minimum volume allowed. */
898#define PDMAUDIO_VOLUME_MIN (0)
899/** Defines the maximum volume allowed. */
900#define PDMAUDIO_VOLUME_MAX (255)
901
902
903/**
904 * Backend status.
905 */
906typedef enum PDMAUDIOBACKENDSTS
907{
908 /** Unknown/invalid status. */
909 PDMAUDIOBACKENDSTS_UNKNOWN = 0,
910 /** No backend attached. */
911 PDMAUDIOBACKENDSTS_NOT_ATTACHED,
912 /** The backend is in its initialization phase.
913 * Not all backends support this status. */
914 PDMAUDIOBACKENDSTS_INITIALIZING,
915 /** The backend has stopped its operation. */
916 PDMAUDIOBACKENDSTS_STOPPED,
917 /** The backend is up and running. */
918 PDMAUDIOBACKENDSTS_RUNNING,
919 /** The backend ran into an error and is unable to recover.
920 * A manual re-initialization might help. */
921 PDMAUDIOBACKENDSTS_ERROR,
922 /** Hack to blow the type up to 32-bit. */
923 PDMAUDIOBACKENDSTS_32BIT_HACK = 0x7fffffff
924} PDMAUDIOBACKENDSTS;
925
926/**
927 * PDM audio stream state.
928 *
929 * This is all the mixer/device needs. The PDMAUDIOSTREAM_STS_XXX stuff will
930 * become DrvAudio internal state once the backend stuff is destilled out of it.
931 *
932 * @note The value order is significant, don't change it willy-nilly.
933 */
934typedef enum PDMAUDIOSTREAMSTATE
935{
936 /** Invalid state value. */
937 PDMAUDIOSTREAMSTATE_INVALID = 0,
938 /** The stream is not operative and cannot be enabled. */
939 PDMAUDIOSTREAMSTATE_NOT_WORKING,
940 /** The stream needs to be re-initialized by the device/mixer
941 * (i.e. call PDMIAUDIOCONNECTOR::pfnStreamReInit). */
942 PDMAUDIOSTREAMSTATE_NEED_REINIT,
943 /** The stream is inactive (not enabled). */
944 PDMAUDIOSTREAMSTATE_INACTIVE,
945 /** The stream is enabled but nothing to read/write.
946 * @todo not sure if we need this variant... */
947 PDMAUDIOSTREAMSTATE_ENABLED,
948 /** The stream is enabled and captured samples can be read. */
949 PDMAUDIOSTREAMSTATE_ENABLED_READABLE,
950 /** The stream is enabled and samples can be written for playback. */
951 PDMAUDIOSTREAMSTATE_ENABLED_WRITABLE,
952 /** End of valid states. */
953 PDMAUDIOSTREAMSTATE_END,
954 /** Make sure the type is 32-bit wide. */
955 PDMAUDIOSTREAMSTATE_32BIT_HACK = 0x7fffffff
956} PDMAUDIOSTREAMSTATE;
957
958/** @name PDMAUDIOSTREAM_CREATE_F_XXX
959 * @{ */
960/** Does not need any mixing buffers, the device takes care of all conversion. */
961#define PDMAUDIOSTREAM_CREATE_F_NO_MIXBUF RT_BIT_32(0)
962/** @} */
963
964/** @name PDMAUDIOSTREAM_WARN_FLAGS_XXX
965 * @{ */
966/** No stream warning flags set. */
967#define PDMAUDIOSTREAM_WARN_FLAGS_NONE 0
968/** Warned about a disabled stream. */
969#define PDMAUDIOSTREAM_WARN_FLAGS_DISABLED RT_BIT(0)
970/** @} */
971
972/**
973 * An input or output audio stream.
974 */
975typedef struct PDMAUDIOSTREAM
976{
977 /** Critical section protecting the stream.
978 *
979 * When not otherwise stated, DrvAudio will enter this before calling the
980 * backend. The backend and device/mixer can normally safely enter it prior to
981 * a DrvAudio call, however not to pfnStreamDestroy, pfnStreamRelease or
982 * anything that may access the stream list.
983 *
984 * @note Lock ordering:
985 * - After DRVAUDIO::CritSectGlobals.
986 * - Before DRVAUDIO::CritSectHotPlug. */
987 RTCRITSECT CritSect;
988 /** Magic value (PDMAUDIOSTREAM_MAGIC). */
989 uint32_t uMagic;
990 /** Audio direction of this stream. */
991 PDMAUDIODIR enmDir;
992 /** Size (in bytes) of the backend-specific stream data. */
993 uint32_t cbBackend;
994 /** Warnings shown already in the release log.
995 * See PDMAUDIOSTREAM_WARN_FLAGS_XXX. */
996 uint32_t fWarningsShown;
997 /** The stream properties (both sides when PDMAUDIOSTREAM_CREATE_F_NO_MIXBUF
998 * is used, otherwise the guest side). */
999 PDMAUDIOPCMPROPS Props;
1000
1001 /** Name of this stream. */
1002 char szName[64];
1003} PDMAUDIOSTREAM;
1004/** Pointer to an audio stream. */
1005typedef struct PDMAUDIOSTREAM *PPDMAUDIOSTREAM;
1006/** Pointer to a const audio stream. */
1007typedef struct PDMAUDIOSTREAM const *PCPDMAUDIOSTREAM;
1008
1009/** Magic value for PDMAUDIOSTREAM. */
1010#define PDMAUDIOSTREAM_MAGIC PDM_VERSION_MAKE(0xa0d3, 5, 0)
1011
1012
1013
1014/** Pointer to a audio connector interface. */
1015typedef struct PDMIAUDIOCONNECTOR *PPDMIAUDIOCONNECTOR;
1016
1017/**
1018 * Audio connector interface (up).
1019 */
1020typedef struct PDMIAUDIOCONNECTOR
1021{
1022 /**
1023 * Enables or disables the given audio direction for this driver.
1024 *
1025 * When disabled, assiociated output streams consume written audio without passing them further down to the backends.
1026 * Associated input streams then return silence when read from those.
1027 *
1028 * @returns VBox status code.
1029 * @param pInterface Pointer to the interface structure containing the called function pointer.
1030 * @param enmDir Audio direction to enable or disable driver for.
1031 * @param fEnable Whether to enable or disable the specified audio direction.
1032 *
1033 * @note Be very careful when using this function, as this could
1034 * violate / run against the (global) VM settings. See @bugref{9882}.
1035 */
1036 DECLR3CALLBACKMEMBER(int, pfnEnable, (PPDMIAUDIOCONNECTOR pInterface, PDMAUDIODIR enmDir, bool fEnable));
1037
1038 /**
1039 * Returns whether the given audio direction for this driver is enabled or not.
1040 *
1041 * @returns True if audio is enabled for the given direction, false if not.
1042 * @param pInterface Pointer to the interface structure containing the called function pointer.
1043 * @param enmDir Audio direction to retrieve enabled status for.
1044 */
1045 DECLR3CALLBACKMEMBER(bool, pfnIsEnabled, (PPDMIAUDIOCONNECTOR pInterface, PDMAUDIODIR enmDir));
1046
1047 /**
1048 * Retrieves the current configuration of the host audio backend.
1049 *
1050 * @returns VBox status code.
1051 * @param pInterface Pointer to the interface structure containing the called function pointer.
1052 * @param pCfg Where to store the host audio backend configuration data.
1053 */
1054 DECLR3CALLBACKMEMBER(int, pfnGetConfig, (PPDMIAUDIOCONNECTOR pInterface, PPDMAUDIOBACKENDCFG pCfg));
1055
1056 /**
1057 * Retrieves the current status of the host audio backend.
1058 *
1059 * @returns Status of the host audio backend.
1060 * @param pInterface Pointer to the interface structure containing the called function pointer.
1061 * @param enmDir Audio direction to check host audio backend for. Specify PDMAUDIODIR_DUPLEX for the overall
1062 * backend status.
1063 */
1064 DECLR3CALLBACKMEMBER(PDMAUDIOBACKENDSTS, pfnGetStatus, (PPDMIAUDIOCONNECTOR pInterface, PDMAUDIODIR enmDir));
1065
1066 /**
1067 * Gives the audio drivers a hint about a typical configuration.
1068 *
1069 * This is a little hack for windows (and maybe other hosts) where stream
1070 * creation can take a relatively long time, making it very unsuitable for EMT.
1071 * The audio backend can use this hint to cache pre-configured stream setups,
1072 * so that when the guest actually wants to play something EMT won't be blocked
1073 * configuring host audio.
1074 *
1075 * @param pInterface Pointer to this interface.
1076 * @param pCfg The typical configuration. Can be modified by the
1077 * drivers in unspecified ways.
1078 */
1079 DECLR3CALLBACKMEMBER(void, pfnStreamConfigHint, (PPDMIAUDIOCONNECTOR pInterface, PPDMAUDIOSTREAMCFG pCfg));
1080
1081 /**
1082 * Creates an audio stream.
1083 *
1084 * @returns VBox status code.
1085 * @param pInterface Pointer to the interface structure containing the called function pointer.
1086 * @param fFlags PDMAUDIOSTREAM_CREATE_F_XXX.
1087 * @param pCfgHost Stream configuration for host side.
1088 * @param pCfgGuest Stream configuration for guest side.
1089 * @param ppStream Pointer where to return the created audio stream on success.
1090 * @todo r=bird: It is not documented how pCfgHost and pCfgGuest can be
1091 * modified the DrvAudio...
1092 */
1093 DECLR3CALLBACKMEMBER(int, pfnStreamCreate, (PPDMIAUDIOCONNECTOR pInterface, uint32_t fFlags, PPDMAUDIOSTREAMCFG pCfgHost,
1094 PPDMAUDIOSTREAMCFG pCfgGuest, PPDMAUDIOSTREAM *ppStream));
1095
1096
1097 /**
1098 * Destroys an audio stream.
1099 *
1100 * @param pInterface Pointer to the interface structure containing the called function pointer.
1101 * @param pStream Pointer to audio stream.
1102 * @param fImmediate Whether to immdiately stop and destroy a draining
1103 * stream (@c true), or to allow it to complete
1104 * draining first (@c false) if that's feasable.
1105 * The latter depends on the draining stage and what
1106 * the backend is capable of.
1107 */
1108 DECLR3CALLBACKMEMBER(int, pfnStreamDestroy, (PPDMIAUDIOCONNECTOR pInterface, PPDMAUDIOSTREAM pStream, bool fImmediate));
1109
1110 /**
1111 * Re-initializes the stream in response to PDMAUDIOSTREAM_STS_NEED_REINIT.
1112 *
1113 * @returns VBox status code.
1114 * @param pInterface Pointer to this interface.
1115 * @param pStream The audio stream needing re-initialization.
1116 */
1117 DECLR3CALLBACKMEMBER(int, pfnStreamReInit, (PPDMIAUDIOCONNECTOR pInterface, PPDMAUDIOSTREAM pStream));
1118
1119 /**
1120 * Adds a reference to the specified audio stream.
1121 *
1122 * @returns New reference count. UINT32_MAX on error.
1123 * @param pInterface Pointer to the interface structure containing the called function pointer.
1124 * @param pStream Pointer to audio stream adding the reference to.
1125 */
1126 DECLR3CALLBACKMEMBER(uint32_t, pfnStreamRetain, (PPDMIAUDIOCONNECTOR pInterface, PPDMAUDIOSTREAM pStream));
1127
1128 /**
1129 * Releases a reference from the specified stream.
1130 *
1131 * @returns New reference count. UINT32_MAX on error.
1132 * @param pInterface Pointer to the interface structure containing the called function pointer.
1133 * @param pStream Pointer to audio stream releasing a reference from.
1134 */
1135 DECLR3CALLBACKMEMBER(uint32_t, pfnStreamRelease, (PPDMIAUDIOCONNECTOR pInterface, PPDMAUDIOSTREAM pStream));
1136
1137 /**
1138 * Controls a specific audio stream.
1139 *
1140 * @returns VBox status code.
1141 * @param pInterface Pointer to the interface structure containing the called function pointer.
1142 * @param pStream Pointer to audio stream.
1143 * @param enmStreamCmd The stream command to issue.
1144 */
1145 DECLR3CALLBACKMEMBER(int, pfnStreamControl, (PPDMIAUDIOCONNECTOR pInterface, PPDMAUDIOSTREAM pStream,
1146 PDMAUDIOSTREAMCMD enmStreamCmd));
1147
1148 /**
1149 * Processes stream data.
1150 *
1151 * @param pInterface Pointer to the interface structure containing the called function pointer.
1152 * @param pStream Pointer to audio stream.
1153 */
1154 DECLR3CALLBACKMEMBER(int, pfnStreamIterate, (PPDMIAUDIOCONNECTOR pInterface, PPDMAUDIOSTREAM pStream));
1155
1156 /**
1157 * Returns the number of readable data (in bytes) of a specific audio input stream.
1158 *
1159 * @returns Number of bytes of readable data.
1160 * @param pInterface Pointer to the interface structure containing the called function pointer.
1161 * @param pStream Pointer to audio stream.
1162 */
1163 DECLR3CALLBACKMEMBER(uint32_t, pfnStreamGetReadable, (PPDMIAUDIOCONNECTOR pInterface, PPDMAUDIOSTREAM pStream));
1164
1165 /**
1166 * Returns the number of writable data (in bytes) of a specific audio output stream.
1167 *
1168 * @returns Number of bytes writable data.
1169 * @param pInterface Pointer to the interface structure containing the called function pointer.
1170 * @param pStream Pointer to audio stream.
1171 */
1172 DECLR3CALLBACKMEMBER(uint32_t, pfnStreamGetWritable, (PPDMIAUDIOCONNECTOR pInterface, PPDMAUDIOSTREAM pStream));
1173
1174 /**
1175 * Returns the state of a specific audio stream (destilled status).
1176 *
1177 * @returns PDMAUDIOSTREAMSTATE value.
1178 * @retval PDMAUDIOSTREAMSTATE_INVALID if the input isn't valid (w/ assertion).
1179 * @param pInterface Pointer to the interface structure containing the called function pointer.
1180 * @param pStream Pointer to audio stream.
1181 */
1182 DECLR3CALLBACKMEMBER(PDMAUDIOSTREAMSTATE, pfnStreamGetState, (PPDMIAUDIOCONNECTOR pInterface, PPDMAUDIOSTREAM pStream));
1183
1184 /**
1185 * Sets the audio volume of a specific audio stream.
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.
1190 * @param pVol Pointer to audio volume structure to set the stream's audio volume to.
1191 */
1192 DECLR3CALLBACKMEMBER(int, pfnStreamSetVolume, (PPDMIAUDIOCONNECTOR pInterface, PPDMAUDIOSTREAM pStream, PPDMAUDIOVOLUME pVol));
1193
1194 /**
1195 * Plays (writes to) an audio (output) stream.
1196 *
1197 * @returns VBox status code.
1198 * @param pInterface Pointer to the interface structure containing the called function pointer.
1199 * @param pStream Pointer to audio stream to read from.
1200 * @param pvBuf Audio data to be written.
1201 * @param cbBuf Number of bytes to be written.
1202 * @param pcbWritten Bytes of audio data written. Optional.
1203 */
1204 DECLR3CALLBACKMEMBER(int, pfnStreamPlay, (PPDMIAUDIOCONNECTOR pInterface, PPDMAUDIOSTREAM pStream,
1205 const void *pvBuf, uint32_t cbBuf, uint32_t *pcbWritten));
1206
1207 /**
1208 * Reads PCM audio data from the host (input).
1209 *
1210 * @returns VBox status code.
1211 * @param pInterface Pointer to the interface structure containing the called function pointer.
1212 * @param pStream Pointer to audio stream to write to.
1213 * @param pvBuf Where to store the read data.
1214 * @param cbBuf Number of bytes to read.
1215 * @param pcbRead Bytes of audio data read. Optional.
1216 */
1217 DECLR3CALLBACKMEMBER(int, pfnStreamRead, (PPDMIAUDIOCONNECTOR pInterface, PPDMAUDIOSTREAM pStream,
1218 void *pvBuf, uint32_t cbBuf, uint32_t *pcbRead));
1219
1220 /**
1221 * Captures (transfers) available audio frames from the host backend.
1222 *
1223 * Only works with input streams.
1224 *
1225 * @returns VBox status code.
1226 * @param pInterface Pointer to the interface structure containing the called function pointer.
1227 * @param pStream Pointer to audio stream.
1228 * @param pcFramesCaptured Number of frames captured. Optional.
1229 */
1230 DECLR3CALLBACKMEMBER(int, pfnStreamCapture, (PPDMIAUDIOCONNECTOR pInterface, PPDMAUDIOSTREAM pStream,
1231 uint32_t *pcFramesCaptured));
1232
1233} PDMIAUDIOCONNECTOR;
1234
1235/** PDMIAUDIOCONNECTOR interface ID. */
1236#define PDMIAUDIOCONNECTOR_IID "ff9cabf0-4138-4c3a-aa99-28bf7a6feae7"
1237
1238
1239/**
1240 * Host audio backend specific stream data.
1241 *
1242 * The backend will put this as the first member of it's own data structure.
1243 */
1244typedef struct PDMAUDIOBACKENDSTREAM
1245{
1246 /** Magic value (PDMAUDIOBACKENDSTREAM_MAGIC). */
1247 uint32_t uMagic;
1248 /** Explicit zero padding - do not touch! */
1249 uint32_t uReserved;
1250 /** Pointer to the stream this backend data is associated with. */
1251 PPDMAUDIOSTREAM pStream;
1252 /** Reserved for future use (zeroed) - do not touch. */
1253 void *apvReserved[2];
1254} PDMAUDIOBACKENDSTREAM;
1255/** Pointer to host audio specific stream data! */
1256typedef PDMAUDIOBACKENDSTREAM *PPDMAUDIOBACKENDSTREAM;
1257
1258/** Magic value for PDMAUDIOBACKENDSTREAM. */
1259#define PDMAUDIOBACKENDSTREAM_MAGIC PDM_VERSION_MAKE(0xa0d4, 1, 0)
1260
1261/**
1262 * Host audio (backend) stream state returned by PDMIHOSTAUDIO::pfnStreamGetState.
1263 */
1264typedef enum PDMHOSTAUDIOSTREAMSTATE
1265{
1266 /** Invalid zero value, as per usual. */
1267 PDMHOSTAUDIOSTREAMSTATE_INVALID = 0,
1268 /** The stream is being initialized.
1269 * This should also be used when switching to a new device and the stream
1270 * stops to work with the old device while the new one being configured. */
1271 PDMHOSTAUDIOSTREAMSTATE_INITIALIZING,
1272 /** The stream does not work (async init failed, audio subsystem gone
1273 * fishing, or similar). */
1274 PDMHOSTAUDIOSTREAMSTATE_NOT_WORKING,
1275 /** Backend is working okay. */
1276 PDMHOSTAUDIOSTREAMSTATE_OKAY,
1277 /** Backend is working okay, but currently draining the stream. */
1278 PDMHOSTAUDIOSTREAMSTATE_DRAINING,
1279 /** Backend is working but doesn't want any commands or data reads/writes. */
1280 PDMHOSTAUDIOSTREAMSTATE_INACTIVE,
1281 /** End of valid values. */
1282 PDMHOSTAUDIOSTREAMSTATE_END,
1283 /** Blow the type up to 32 bits. */
1284 PDMHOSTAUDIOSTREAMSTATE_32BIT_HACK = 0x7fffffff
1285} PDMHOSTAUDIOSTREAMSTATE;
1286
1287
1288/** Pointer to a host audio interface. */
1289typedef struct PDMIHOSTAUDIO *PPDMIHOSTAUDIO;
1290
1291/**
1292 * PDM host audio interface.
1293 */
1294typedef struct PDMIHOSTAUDIO
1295{
1296 /**
1297 * Returns the host backend's configuration (backend).
1298 *
1299 * @returns VBox status code.
1300 * @param pInterface Pointer to the interface structure containing the called function pointer.
1301 * @param pBackendCfg Where to store the backend audio configuration to.
1302 */
1303 DECLR3CALLBACKMEMBER(int, pfnGetConfig, (PPDMIHOSTAUDIO pInterface, PPDMAUDIOBACKENDCFG pBackendCfg));
1304
1305 /**
1306 * Returns (enumerates) host audio device information (optional).
1307 *
1308 * @returns VBox status code.
1309 * @param pInterface Pointer to the interface structure containing the called function pointer.
1310 * @param pDeviceEnum Where to return the enumerated audio devices.
1311 */
1312 DECLR3CALLBACKMEMBER(int, pfnGetDevices, (PPDMIHOSTAUDIO pInterface, PPDMAUDIOHOSTENUM pDeviceEnum));
1313
1314 /**
1315 * Returns the current status from the audio backend (optional).
1316 *
1317 * @returns PDMAUDIOBACKENDSTS enum.
1318 * @param pInterface Pointer to the interface structure containing the called function pointer.
1319 * @param enmDir Audio direction to get status for. Pass PDMAUDIODIR_DUPLEX for overall status.
1320 */
1321 DECLR3CALLBACKMEMBER(PDMAUDIOBACKENDSTS, pfnGetStatus, (PPDMIHOSTAUDIO pInterface, PDMAUDIODIR enmDir));
1322
1323 /**
1324 * Callback for genric on-worker-thread requests initiated by the backend itself.
1325 *
1326 * This is the counterpart to PDMIHOSTAUDIOPORT::pfnDoOnWorkerThread that will
1327 * be invoked on a worker thread when the backend requests it - optional.
1328 *
1329 * This does not return a value, so the backend must keep track of
1330 * failure/success on its own.
1331 *
1332 * This method is optional. A non-NULL will, together with pfnStreamInitAsync
1333 * and PDMAUDIOBACKEND_F_ASYNC_HINT, force DrvAudio to create the thread pool.
1334 *
1335 * @param pInterface Pointer to this interface.
1336 * @param pStream Optionally a backend stream if specified in the
1337 * PDMIHOSTAUDIOPORT::pfnDoOnWorkerThread() call.
1338 * @param uUser User specific value as specified in the
1339 * PDMIHOSTAUDIOPORT::pfnDoOnWorkerThread() call.
1340 * @param pvUser User specific pointer as specified in the
1341 * PDMIHOSTAUDIOPORT::pfnDoOnWorkerThread() call.
1342 */
1343 DECLR3CALLBACKMEMBER(void, pfnDoOnWorkerThread,(PPDMIHOSTAUDIO pInterface, PPDMAUDIOBACKENDSTREAM pStream,
1344 uintptr_t uUser, void *pvUser));
1345
1346 /**
1347 * Gives the audio backend a hint about a typical configuration (optional).
1348 *
1349 * This is a little hack for windows (and maybe other hosts) where stream
1350 * creation can take a relatively long time, making it very unsuitable for EMT.
1351 * The audio backend can use this hint to cache pre-configured stream setups,
1352 * so that when the guest actually wants to play something EMT won't be blocked
1353 * configuring host audio.
1354 *
1355 * The backend can return PDMAUDIOBACKEND_F_ASYNC_HINT in
1356 * PDMIHOSTAUDIO::pfnGetConfig to avoid having EMT making this call and thereby
1357 * speeding up VM construction.
1358 *
1359 * @param pInterface Pointer to this interface.
1360 * @param pCfg The typical configuration. (Feel free to change it
1361 * to the actual stream config that would be used,
1362 * however caller will probably ignore this.)
1363 */
1364 DECLR3CALLBACKMEMBER(void, pfnStreamConfigHint, (PPDMIHOSTAUDIO pInterface, PPDMAUDIOSTREAMCFG pCfg));
1365
1366 /**
1367 * Creates an audio stream using the requested stream configuration.
1368 *
1369 * If a backend is not able to create this configuration, it will return its
1370 * best match in the acquired configuration structure on success.
1371 *
1372 * @returns VBox status code.
1373 * @retval VINF_AUDIO_STREAM_ASYNC_INIT_NEEDED if
1374 * PDMIHOSTAUDIO::pfnStreamInitAsync should be called.
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 * @todo r=bird: Implementation (at least Alsa) seems to make undocumented
1380 * assumptions about the content of @a pCfgAcq.
1381 */
1382 DECLR3CALLBACKMEMBER(int, pfnStreamCreate, (PPDMIHOSTAUDIO pInterface, PPDMAUDIOBACKENDSTREAM pStream,
1383 PPDMAUDIOSTREAMCFG pCfgReq, PPDMAUDIOSTREAMCFG pCfgAcq));
1384
1385 /**
1386 * Asynchronous stream initialization step, optional.
1387 *
1388 * This is called on a worker thread iff the PDMIHOSTAUDIO::pfnStreamCreate
1389 * method returns VINF_AUDIO_STREAM_ASYNC_INIT_NEEDED.
1390 *
1391 * @returns VBox status code.
1392 * @param pInterface Pointer to this interface.
1393 * @param pStream Pointer to audio stream to continue
1394 * initialization of.
1395 * @param fDestroyed Set to @c true if the stream has been destroyed
1396 * before the worker thread got to making this
1397 * call. The backend should just ready the stream
1398 * for destruction in that case.
1399 */
1400 DECLR3CALLBACKMEMBER(int, pfnStreamInitAsync, (PPDMIHOSTAUDIO pInterface, PPDMAUDIOBACKENDSTREAM pStream, bool fDestroyed));
1401
1402 /**
1403 * Destroys an audio stream.
1404 *
1405 * @returns VBox status code.
1406 * @param pInterface Pointer to the interface containing the called function.
1407 * @param pStream Pointer to audio stream.
1408 * @param fImmediate Whether to immdiately stop and destroy a draining
1409 * stream (@c true), or to allow it to complete
1410 * draining first (@c false) if that's feasable.
1411 */
1412 DECLR3CALLBACKMEMBER(int, pfnStreamDestroy, (PPDMIHOSTAUDIO pInterface, PPDMAUDIOBACKENDSTREAM pStream, bool fImmediate));
1413
1414 /**
1415 * Called from PDMIHOSTAUDIOPORT::pfnNotifyDeviceChanged so the backend can start
1416 * the device change for a stream.
1417 *
1418 * This is mainly to avoid the need for a list of streams in the backend.
1419 *
1420 * @param pInterface Pointer to this interface.
1421 * @param pStream Pointer to audio stream (locked).
1422 * @param pvUser Backend specific parameter from the call to
1423 * PDMIHOSTAUDIOPORT::pfnNotifyDeviceChanged.
1424 */
1425 DECLR3CALLBACKMEMBER(void, pfnStreamNotifyDeviceChanged,(PPDMIHOSTAUDIO pInterface,
1426 PPDMAUDIOBACKENDSTREAM pStream, void *pvUser));
1427
1428 /**
1429 * Controls an audio stream.
1430 *
1431 * @returns VBox status code.
1432 * @retval VERR_AUDIO_STREAM_NOT_READY if stream is not ready for required operation (yet).
1433 * @param pInterface Pointer to the interface structure containing the called function pointer.
1434 * @param pStream Pointer to audio stream.
1435 * @param enmStreamCmd The stream command to issue.
1436 */
1437 DECLR3CALLBACKMEMBER(int, pfnStreamControl, (PPDMIHOSTAUDIO pInterface, PPDMAUDIOBACKENDSTREAM pStream,
1438 PDMAUDIOSTREAMCMD enmStreamCmd));
1439
1440 /**
1441 * Returns the amount which is readable from the audio (input) stream.
1442 *
1443 * @returns For non-raw layout streams: Number of readable bytes.
1444 * for raw layout streams : Number of readable audio frames.
1445 * @param pInterface Pointer to the interface structure containing the called function pointer.
1446 * @param pStream Pointer to audio stream.
1447 */
1448 DECLR3CALLBACKMEMBER(uint32_t, pfnStreamGetReadable, (PPDMIHOSTAUDIO pInterface, PPDMAUDIOBACKENDSTREAM pStream));
1449
1450 /**
1451 * Returns the amount which is writable to the audio (output) stream.
1452 *
1453 * @returns Number of writable bytes.
1454 * @param pInterface Pointer to the interface structure containing the called function pointer.
1455 * @param pStream Pointer to audio stream.
1456 */
1457 DECLR3CALLBACKMEMBER(uint32_t, pfnStreamGetWritable, (PPDMIHOSTAUDIO pInterface, PPDMAUDIOBACKENDSTREAM pStream));
1458
1459 /**
1460 * Returns the number of buffered bytes that hasn't been played yet (optional).
1461 *
1462 * Is not valid on an input stream, implementions shall assert and return zero.
1463 *
1464 * @returns Number of pending bytes.
1465 * @param pInterface Pointer to this interface.
1466 * @param pStream Pointer to audio stream.
1467 *
1468 * @todo This is no longer not used by DrvAudio and can probably be removed.
1469 */
1470 DECLR3CALLBACKMEMBER(uint32_t, pfnStreamGetPending, (PPDMIHOSTAUDIO pInterface, PPDMAUDIOBACKENDSTREAM pStream));
1471
1472 /**
1473 * Returns the current state of the given backend stream.
1474 *
1475 * @returns PDMHOSTAUDIOSTREAMSTATE value.
1476 * @retval PDMHOSTAUDIOSTREAMSTATE_INVALID if invalid stream.
1477 * @param pInterface Pointer to the interface structure containing the called function pointer.
1478 * @param pStream Pointer to audio stream.
1479 */
1480 DECLR3CALLBACKMEMBER(PDMHOSTAUDIOSTREAMSTATE, pfnStreamGetState, (PPDMIHOSTAUDIO pInterface, PPDMAUDIOBACKENDSTREAM pStream));
1481
1482 /**
1483 * Plays (writes to) an audio (output) stream.
1484 *
1485 * This is always called with data in the buffer, except after
1486 * PDMAUDIOSTREAMCMD_DRAIN is issued when it's called every so often to assist
1487 * the backend with moving the draining operation forward (kind of like
1488 * PDMIAUDIOCONNECTOR::pfnStreamIterate).
1489 *
1490 * @returns VBox status code.
1491 * @param pInterface Pointer to the interface structure containing the called function pointer.
1492 * @param pStream Pointer to audio stream.
1493 * @param pvBuf Pointer to audio data buffer to play. This will be NULL
1494 * when called to assist draining the stream.
1495 * @param cbBuf The number of bytes of audio data to play. This will be
1496 * zero when called to assist draining the stream.
1497 * @param pcbWritten Where to return the actual number of bytes played.
1498 */
1499 DECLR3CALLBACKMEMBER(int, pfnStreamPlay, (PPDMIHOSTAUDIO pInterface, PPDMAUDIOBACKENDSTREAM pStream,
1500 const void *pvBuf, uint32_t cbBuf, uint32_t *pcbWritten));
1501
1502 /**
1503 * Captures (reads from) an audio (input) stream.
1504 *
1505 * @returns VBox status code.
1506 * @param pInterface Pointer to the interface structure containing the called function pointer.
1507 * @param pStream Pointer to audio stream.
1508 * @param pvBuf Buffer where to store read audio data.
1509 * @param cbBuf Size of the audio data buffer in bytes.
1510 * @param pcbRead Where to return the number of bytes actually captured.
1511 */
1512 DECLR3CALLBACKMEMBER(int, pfnStreamCapture, (PPDMIHOSTAUDIO pInterface, PPDMAUDIOBACKENDSTREAM pStream,
1513 void *pvBuf, uint32_t cbBuf, uint32_t *pcbRead));
1514} PDMIHOSTAUDIO;
1515
1516/** PDMIHOSTAUDIO interface ID. */
1517#define PDMIHOSTAUDIO_IID "a6b33abc-1393-4548-92ab-a308d54de1e8"
1518
1519
1520/** Pointer to a audio notify from host interface. */
1521typedef struct PDMIHOSTAUDIOPORT *PPDMIHOSTAUDIOPORT;
1522
1523/**
1524 * PDM host audio port interface, upwards sibling of PDMIHOSTAUDIO.
1525 */
1526typedef struct PDMIHOSTAUDIOPORT
1527{
1528 /**
1529 * Ask DrvAudio to call PDMIHOSTAUDIO::pfnDoOnWorkerThread on a worker thread.
1530 *
1531 * Generic method for doing asynchronous work using the DrvAudio thread pool.
1532 *
1533 * This function will not wait for PDMIHOSTAUDIO::pfnDoOnWorkerThread to
1534 * complete, but returns immediately after submitting the request to the thread
1535 * pool.
1536 *
1537 * @returns VBox status code.
1538 * @param pInterface Pointer to this interface.
1539 * @param pStream Optional backend stream structure to pass along. The
1540 * reference count will be increased till the call
1541 * completes to make sure the stream stays valid.
1542 * @param uUser User specific value.
1543 * @param pvUser User specific pointer.
1544 */
1545 DECLR3CALLBACKMEMBER(int, pfnDoOnWorkerThread,(PPDMIHOSTAUDIOPORT pInterface, PPDMAUDIOBACKENDSTREAM pStream,
1546 uintptr_t uUser, void *pvUser));
1547
1548 /**
1549 * The device for the given direction changed.
1550 *
1551 * The driver above backend (DrvAudio) will call the backend back
1552 * (PDMIHOSTAUDIO::pfnStreamNotifyDeviceChanged) for all open streams in the
1553 * given direction. (This ASSUMES the backend uses one output device and one
1554 * input devices for all streams.)
1555 *
1556 * @param pInterface Pointer to this interface.
1557 * @param enmDir The audio direction.
1558 * @param pvUser Backend specific parameter for
1559 * PDMIHOSTAUDIO::pfnStreamNotifyDeviceChanged.
1560 */
1561 DECLR3CALLBACKMEMBER(void, pfnNotifyDeviceChanged,(PPDMIHOSTAUDIOPORT pInterface, PDMAUDIODIR enmDir, void *pvUser));
1562
1563 /**
1564 * Notification that the stream is about to change device in a bit.
1565 *
1566 * This will assume PDMAUDIOSTREAM_STS_PREPARING_SWITCH will be set when
1567 * PDMIHOSTAUDIO::pfnStreamGetStatus is next called and change the stream state
1568 * accordingly.
1569 *
1570 * @param pInterface Pointer to this interface.
1571 * @param pStream The stream that changed device (backend variant).
1572 */
1573 DECLR3CALLBACKMEMBER(void, pfnStreamNotifyPreparingDeviceSwitch,(PPDMIHOSTAUDIOPORT pInterface,
1574 PPDMAUDIOBACKENDSTREAM pStream));
1575
1576 /**
1577 * The stream has changed its device and left the
1578 * PDMAUDIOSTREAM_STS_PREPARING_SWITCH state (if it entered it at all).
1579 *
1580 * @param pInterface Pointer to this interface.
1581 * @param pStream The stream that changed device (backend variant).
1582 * @param fReInit Set if a re-init is required, clear if not.
1583 */
1584 DECLR3CALLBACKMEMBER(void, pfnStreamNotifyDeviceChanged,(PPDMIHOSTAUDIOPORT pInterface,
1585 PPDMAUDIOBACKENDSTREAM pStream, bool fReInit));
1586
1587 /**
1588 * One or more audio devices have changed in some way.
1589 *
1590 * The upstream driver/device should re-evaluate the devices they're using.
1591 *
1592 * @todo r=bird: The upstream driver/device does not know which host audio
1593 * devices they are using. This is mainly for triggering enumeration and
1594 * logging of the audio devices.
1595 *
1596 * @param pInterface Pointer to this interface.
1597 */
1598 DECLR3CALLBACKMEMBER(void, pfnNotifyDevicesChanged,(PPDMIHOSTAUDIOPORT pInterface));
1599} PDMIHOSTAUDIOPORT;
1600
1601/** PDMIHOSTAUDIOPORT interface ID. */
1602#define PDMIHOSTAUDIOPORT_IID "9f91ec59-95ba-4925-92dc-e75be1c63352"
1603
1604/** @} */
1605
1606#endif /* !VBOX_INCLUDED_vmm_pdmaudioifs_h */
1607
注意: 瀏覽 TracBrowser 來幫助您使用儲存庫瀏覽器

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