VirtualBox

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

Last change on this file since 71695 was 70641, checked in by vboxsync, 7 years ago

Audio: Added VERR_AUDIO_BACKEND_NOT_ATTACHED and support for it in PDMIAUDIOCONNECTOR::pfnGetStatus() and AudioMixerSinkCreateStream().

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