VirtualBox

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

Last change on this file since 89797 was 89797, checked in by vboxsync, 3 years ago

pdmaudioifs.h: doxygen. bugref:9890

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

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