VirtualBox

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

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

Audio: Unified audio debug / dumping code to also get device DMA data when enabled at runtime.

  • 屬性 svn:eol-style 設為 native
  • 屬性 svn:keywords 設為 Author Date Id Revision
檔案大小: 60.3 KB
 
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.alldomusa.eu.org. This file is free software;
10 * you can redistribute it and/or modify it under the terms of the GNU
11 * General Public License (GPL) as published by the Free Software
12 * Foundation, in version 2 as it comes in the "COPYING" file of the
13 * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
14 * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
15 *
16 * The contents of this file may alternatively be used under the terms
17 * of the Common Development and Distribution License Version 1.0
18 * (CDDL) only, as it comes in the "COPYING.CDDL" file of the
19 * VirtualBox OSE distribution, in which case the provisions of the
20 * CDDL are applicable instead of those of the GPL.
21 *
22 * You may elect to license modified versions of this file under the
23 * terms and conditions of either the GPL or the CDDL or both.
24 */
25
26/**
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 * Note: Does only support mono/stereo channels for now. */
498#define PDMAUDIOPCMPROPS_MAKE_SHIFT(pProps) PDMAUDIOPCMPROPS_MAKE_SHIFT_PARMS((pProps)->cChannels == 2) + (pProps)->cBits / 16)
499/** Converts (audio) frames to bytes.
500 * Needs the cShift value set correctly, using PDMAUDIOPCMPROPS_MAKE_SHIFT. */
501#define PDMAUDIOPCMPROPS_F2B(pProps, frames) ((frames) << (pProps)->cShift)
502/** Converts bytes to (audio) frames.
503 * Needs the cShift value set correctly, using PDMAUDIOPCMPROPS_MAKE_SHIFT. */
504#define PDMAUDIOPCMPROPS_B2F(pProps, cb) (cb >> (pProps)->cShift)
505
506/**
507 * Structure for keeping an audio stream configuration.
508 */
509typedef struct PDMAUDIOSTREAMCFG
510{
511 /** Friendly name of the stream. */
512 char szName[64];
513 /** Direction of the stream. */
514 PDMAUDIODIR enmDir;
515 /** Destination / source indicator, depending on enmDir. */
516 PDMAUDIODESTSOURCE DestSource;
517 /** The stream's PCM properties. */
518 PDMAUDIOPCMPROPS Props;
519 /** The stream's audio data layout.
520 * This indicates how the audio data buffers to/from the backend is being layouted.
521 *
522 * Currently, the following layouts are supported by the audio connector:
523 *
524 * PDMAUDIOSTREAMLAYOUT_NON_INTERLEAVED:
525 * One stream at once. The consecutive audio data is exactly in the format and frame width
526 * like defined in the PCM properties. This is the default.
527 *
528 * PDMAUDIOSTREAMLAYOUT_RAW:
529 * Can be one or many streams at once, depending on the stream's mixing buffer setup.
530 * The audio data will get handled as PDMAUDIOFRAME frames without any modification done. */
531 PDMAUDIOSTREAMLAYOUT enmLayout;
532 /** Hint about the optimal frame buffer size (in audio frames).
533 * 0 if no hint is given. */
534 uint32_t cFrameBufferHint;
535} PDMAUDIOSTREAMCFG, *PPDMAUDIOSTREAMCFG;
536
537/** Converts (audio) frames to bytes. */
538#define PDMAUDIOSTREAMCFG_F2B(pCfg, frames) ((frames) << (pCfg->Props).cShift)
539/** Converts bytes to (audio) frames. */
540#define PDMAUDIOSTREAMCFG_B2F(pCfg, cb) (cb >> (pCfg->Props).cShift)
541
542#if defined(RT_LITTLE_ENDIAN)
543# define PDMAUDIOHOSTENDIANNESS PDMAUDIOENDIANNESS_LITTLE
544#elif defined(RT_BIG_ENDIAN)
545# define PDMAUDIOHOSTENDIANNESS PDMAUDIOENDIANNESS_BIG
546#else
547# error "Port me!"
548#endif
549
550/**
551 * Audio mixer controls.
552 */
553typedef enum PDMAUDIOMIXERCTL
554{
555 /** Unknown mixer control. */
556 PDMAUDIOMIXERCTL_UNKNOWN = 0,
557 /** Master volume. */
558 PDMAUDIOMIXERCTL_VOLUME_MASTER,
559 /** Front. */
560 PDMAUDIOMIXERCTL_FRONT,
561 /** Center / LFE (Subwoofer). */
562 PDMAUDIOMIXERCTL_CENTER_LFE,
563 /** Rear. */
564 PDMAUDIOMIXERCTL_REAR,
565 /** Line-In. */
566 PDMAUDIOMIXERCTL_LINE_IN,
567 /** Microphone-In. */
568 PDMAUDIOMIXERCTL_MIC_IN,
569 /** Hack to blow the type up to 32-bit. */
570 PDMAUDIOMIXERCTL_32BIT_HACK = 0x7fffffff
571} PDMAUDIOMIXERCTL;
572
573/**
574 * Audio stream commands. Used in the audio connector
575 * as well as in the actual host backends.
576 */
577typedef enum PDMAUDIOSTREAMCMD
578{
579 /** Unknown command, do not use. */
580 PDMAUDIOSTREAMCMD_UNKNOWN = 0,
581 /** Enables the stream. */
582 PDMAUDIOSTREAMCMD_ENABLE,
583 /** Disables the stream. */
584 PDMAUDIOSTREAMCMD_DISABLE,
585 /** Pauses the stream. */
586 PDMAUDIOSTREAMCMD_PAUSE,
587 /** Resumes the stream. */
588 PDMAUDIOSTREAMCMD_RESUME,
589 /** Hack to blow the type up to 32-bit. */
590 PDMAUDIOSTREAMCMD_32BIT_HACK = 0x7fffffff
591} PDMAUDIOSTREAMCMD;
592
593/**
594 * Audio volume parameters.
595 */
596typedef struct PDMAUDIOVOLUME
597{
598 /** Set to @c true if this stream is muted, @c false if not. */
599 bool fMuted;
600 /** Left channel volume.
601 * Range is from [0 ... 255], whereas 0 specifies
602 * the most silent and 255 the loudest value. */
603 uint8_t uLeft;
604 /** Right channel volume.
605 * Range is from [0 ... 255], whereas 0 specifies
606 * the most silent and 255 the loudest value. */
607 uint8_t uRight;
608} PDMAUDIOVOLUME, *PPDMAUDIOVOLUME;
609
610/** Defines the minimum volume allowed. */
611#define PDMAUDIO_VOLUME_MIN (0)
612/** Defines the maximum volume allowed. */
613#define PDMAUDIO_VOLUME_MAX (255)
614
615/**
616 * Structure for holding rate processing information
617 * of a source + destination audio stream. This is needed
618 * because both streams can differ regarding their rates
619 * and therefore need to be treated accordingly.
620 */
621typedef struct PDMAUDIOSTREAMRATE
622{
623 /** Current (absolute) offset in the output
624 * (destination) stream. */
625 uint64_t dstOffset;
626 /** Increment for moving dstOffset for the
627 * destination stream. This is needed because the
628 * source <-> destination rate might be different. */
629 uint64_t dstInc;
630 /** Current (absolute) offset in the input
631 * stream. */
632 uint32_t srcOffset;
633 /** Last processed frame of the input stream.
634 * Needed for interpolation. */
635 PDMAUDIOFRAME srcFrameLast;
636} PDMAUDIOSTREAMRATE, *PPDMAUDIOSTREAMRATE;
637
638/**
639 * Structure for holding mixing buffer volume parameters.
640 * The volume values are in fixed point style and must
641 * be converted to/from before using with e.g. PDMAUDIOVOLUME.
642 */
643typedef struct PDMAUDMIXBUFVOL
644{
645 /** Set to @c true if this stream is muted, @c false if not. */
646 bool fMuted;
647 /** Left volume to apply during conversion. Pass 0
648 * to convert the original values. May not apply to
649 * all conversion functions. */
650 uint32_t uLeft;
651 /** Right volume to apply during conversion. Pass 0
652 * to convert the original values. May not apply to
653 * all conversion functions. */
654 uint32_t uRight;
655} PDMAUDMIXBUFVOL, *PPDMAUDMIXBUFVOL;
656
657/**
658 * Structure for holding frame conversion parameters for
659 * the audioMixBufConvFromXXX / audioMixBufConvToXXX macros.
660 */
661typedef struct PDMAUDMIXBUFCONVOPTS
662{
663 /** Number of audio frames to convert. */
664 uint32_t cFrames;
665 union
666 {
667 struct
668 {
669 /** Volume to use for conversion. */
670 PDMAUDMIXBUFVOL Volume;
671 } From;
672 } RT_UNION_NM(u);
673} PDMAUDMIXBUFCONVOPTS;
674/** Pointer to conversion parameters for the audio mixer. */
675typedef PDMAUDMIXBUFCONVOPTS *PPDMAUDMIXBUFCONVOPTS;
676/** Pointer to const conversion parameters for the audio mixer. */
677typedef PDMAUDMIXBUFCONVOPTS const *PCPDMAUDMIXBUFCONVOPTS;
678
679/**
680 * Note: All internal handling is done in audio frames,
681 * not in bytes!
682 */
683typedef uint32_t PDMAUDIOMIXBUFFMT;
684typedef PDMAUDIOMIXBUFFMT *PPDMAUDIOMIXBUFFMT;
685
686/**
687 * Convertion-from function used by the PDM audio buffer mixer.
688 *
689 * @returns Number of audio frames returned.
690 * @param paDst Where to return the converted frames.
691 * @param pvSrc The source frame bytes.
692 * @param cbSrc Number of bytes to convert.
693 * @param pOpts Conversion options.
694 */
695typedef DECLCALLBACK(uint32_t) FNPDMAUDIOMIXBUFCONVFROM(PPDMAUDIOFRAME paDst, const void *pvSrc, uint32_t cbSrc,
696 PCPDMAUDMIXBUFCONVOPTS pOpts);
697/** Pointer to a convertion-from function used by the PDM audio buffer mixer. */
698typedef FNPDMAUDIOMIXBUFCONVFROM *PFNPDMAUDIOMIXBUFCONVFROM;
699
700/**
701 * Convertion-to function used by the PDM audio buffer mixer.
702 *
703 * @param pvDst Output buffer.
704 * @param paSrc The input frames.
705 * @param pOpts Conversion options.
706 */
707typedef DECLCALLBACK(void) FNPDMAUDIOMIXBUFCONVTO(void *pvDst, PCPDMAUDIOFRAME paSrc, PCPDMAUDMIXBUFCONVOPTS pOpts);
708/** Pointer to a convertion-to function used by the PDM audio buffer mixer. */
709typedef FNPDMAUDIOMIXBUFCONVTO *PFNPDMAUDIOMIXBUFCONVTO;
710
711typedef struct PDMAUDIOMIXBUF *PPDMAUDIOMIXBUF;
712typedef struct PDMAUDIOMIXBUF
713{
714 RTLISTNODE Node;
715 /** Name of the buffer. */
716 char *pszName;
717 /** Frame buffer. */
718 PPDMAUDIOFRAME pFrames;
719 /** Size of the frame buffer (in audio frames). */
720 uint32_t cFrames;
721 /** The current read position (in frames). */
722 uint32_t offRead;
723 /** The current write position (in frames). */
724 uint32_t offWrite;
725 /**
726 * Total frames already mixed down to the parent buffer (if any). Always starting at
727 * the parent's offRead position.
728 *
729 * Note: Count always is specified in parent frames, as the sample count can differ between parent
730 * and child.
731 */
732 uint32_t cMixed;
733 /** How much audio frames are currently being used
734 * in this buffer.
735 * Note: This also is known as the distance in ring buffer terms. */
736 uint32_t cUsed;
737 /** Pointer to parent buffer (if any). */
738 PPDMAUDIOMIXBUF pParent;
739 /** List of children mix buffers to keep in sync with (if being a parent buffer). */
740 RTLISTANCHOR lstChildren;
741 /** Number of children mix buffers kept in lstChildren. */
742 uint32_t cChildren;
743 /** Intermediate structure for buffer conversion tasks. */
744 PPDMAUDIOSTREAMRATE pRate;
745 /** Internal representation of current volume used for mixing. */
746 PDMAUDMIXBUFVOL Volume;
747 /** This buffer's audio format. */
748 PDMAUDIOMIXBUFFMT AudioFmt;
749 /** Standard conversion-to function for set AudioFmt. */
750 PFNPDMAUDIOMIXBUFCONVTO pfnConvTo;
751 /** Standard conversion-from function for set AudioFmt. */
752 PFNPDMAUDIOMIXBUFCONVFROM pfnConvFrom;
753 /**
754 * Ratio of the associated parent stream's frequency by this stream's
755 * frequency (1<<32), represented as a signed 64 bit integer.
756 *
757 * For example, if the parent stream has a frequency of 44 khZ, and this
758 * stream has a frequency of 11 kHz, the ration then would be
759 * (44/11 * (1 << 32)).
760 *
761 * Currently this does not get changed once assigned.
762 */
763 int64_t iFreqRatio;
764 /** For quickly converting frames <-> bytes and vice versa. */
765 uint8_t cShift;
766} PDMAUDIOMIXBUF;
767
768typedef uint32_t PDMAUDIOFILEFLAGS;
769
770/** No flags defined. */
771#define PDMAUDIOFILE_FLAG_NONE 0
772/** Keep the audio file even if it contains no audio data. */
773#define PDMAUDIOFILE_FLAG_KEEP_IF_EMPTY RT_BIT(0)
774/** Audio file flag validation mask. */
775#define PDMAUDIOFILE_FLAG_VALID_MASK 0x1
776
777/**
778 * Audio file types.
779 */
780typedef enum PDMAUDIOFILETYPE
781{
782 /** Unknown type, do not use. */
783 PDMAUDIOFILETYPE_UNKNOWN = 0,
784 /** Raw (PCM) file. */
785 PDMAUDIOFILETYPE_RAW,
786 /** Wave (.WAV) file. */
787 PDMAUDIOFILETYPE_WAV,
788 /** Hack to blow the type up to 32-bit. */
789 PDMAUDIOFILETYPE_32BIT_HACK = 0x7fffffff
790} PDMAUDIOFILETYPE;
791
792typedef uint32_t PDMAUDIOFILENAMEFLAGS;
793
794/** No flags defined. */
795#define PDMAUDIOFILENAME_FLAG_NONE 0
796/** Adds an ISO timestamp to the file name. */
797#define PDMAUDIOFILENAME_FLAG_TS RT_BIT(0)
798
799/**
800 * Structure for an audio file handle.
801 */
802typedef struct PDMAUDIOFILE
803{
804 /** Type of the audio file. */
805 PDMAUDIOFILETYPE enmType;
806 /** Audio file flags. */
807 PDMAUDIOFILEFLAGS fFlags;
808 /** File name and path. */
809 char szName[RTPATH_MAX + 1];
810 /** Actual file handle. */
811 RTFILE hFile;
812 /** Data needed for the specific audio file type implemented.
813 * Optional, can be NULL. */
814 void *pvData;
815 /** Data size (in bytes). */
816 size_t cbData;
817} PDMAUDIOFILE, *PPDMAUDIOFILE;
818
819/** Stream status flag. To be used with PDMAUDIOSTRMSTS_FLAG_ flags. */
820typedef uint32_t PDMAUDIOSTREAMSTS;
821
822/** No flags being set. */
823#define PDMAUDIOSTREAMSTS_FLAG_NONE 0
824/** Whether this stream has been initialized by the
825 * backend or not. */
826#define PDMAUDIOSTREAMSTS_FLAG_INITIALIZED RT_BIT_32(0)
827/** Whether this stream is enabled or disabled. */
828#define PDMAUDIOSTREAMSTS_FLAG_ENABLED RT_BIT_32(1)
829/** Whether this stream has been paused or not. This also implies
830 * that this is an enabled stream! */
831#define PDMAUDIOSTREAMSTS_FLAG_PAUSED RT_BIT_32(2)
832/** Whether this stream was marked as being disabled
833 * but there are still associated guest output streams
834 * which rely on its data. */
835#define PDMAUDIOSTREAMSTS_FLAG_PENDING_DISABLE RT_BIT_32(3)
836/** Whether this stream is in re-initialization phase.
837 * All other bits remain untouched to be able to restore
838 * the stream's state after the re-initialization bas been
839 * finished. */
840#define PDMAUDIOSTREAMSTS_FLAG_PENDING_REINIT RT_BIT_32(4)
841/** Validation mask. */
842#define PDMAUDIOSTREAMSTS_VALID_MASK UINT32_C(0x0000001F)
843
844/**
845 * Enumeration presenting a backend's current status.
846 */
847typedef enum PDMAUDIOBACKENDSTS
848{
849 /** Unknown/invalid status. */
850 PDMAUDIOBACKENDSTS_UNKNOWN = 0,
851 /** The backend is in its initialization phase.
852 * Not all backends support this status. */
853 PDMAUDIOBACKENDSTS_INITIALIZING,
854 /** The backend has stopped its operation. */
855 PDMAUDIOBACKENDSTS_STOPPED,
856 /** The backend is up and running. */
857 PDMAUDIOBACKENDSTS_RUNNING,
858 /** The backend ran into an error and is unable to recover.
859 * A manual re-initialization might help. */
860 PDMAUDIOBACKENDSTS_ERROR,
861 /** Hack to blow the type up to 32-bit. */
862 PDMAUDIOBACKENDSTS_32BIT_HACK = 0x7fffffff
863} PDMAUDIOBACKENDSTS;
864
865/**
866 * Audio stream context.
867 */
868typedef enum PDMAUDIOSTREAMCTX
869{
870 /** No context set / invalid. */
871 PDMAUDIOSTREAMCTX_UNKNOWN = 0,
872 /** Host stream, connected to a backend. */
873 PDMAUDIOSTREAMCTX_HOST,
874 /** Guest stream, connected to the device emulation. */
875 PDMAUDIOSTREAMCTX_GUEST,
876 /** Hack to blow the type up to 32-bit. */
877 PDMAUDIOSTREAMCTX_32BIT_HACK = 0x7fffffff
878} PDMAUDIOSTREAMCTX;
879
880/**
881 * Structure for keeping audio input stream specifics.
882 * Do not use directly. Instead, use PDMAUDIOSTREAM.
883 */
884typedef struct PDMAUDIOSTREAMIN
885{
886 /** Timestamp (in ms) since last read. */
887 uint64_t tsLastReadMS;
888#ifdef VBOX_WITH_STATISTICS
889 STAMCOUNTER StatBytesElapsed;
890 STAMCOUNTER StatBytesTotalRead;
891 STAMCOUNTER StatFramesCaptured;
892#endif
893 struct
894 {
895 /** File for writing stream reads. */
896 PPDMAUDIOFILE pFileStreamRead;
897 /** File for writing non-interleaved captures. */
898 PPDMAUDIOFILE pFileCaptureNonInterleaved;
899 } Dbg;
900} PDMAUDIOSTREAMIN, *PPDMAUDIOSTREAMIN;
901
902/**
903 * Structure for keeping audio output stream specifics.
904 * Do not use directly. Instead, use PDMAUDIOSTREAM.
905 */
906typedef struct PDMAUDIOSTREAMOUT
907{
908 /** Timestamp (in ms) since last write. */
909 uint64_t tsLastWriteMS;
910#ifdef VBOX_WITH_STATISTICS
911 STAMCOUNTER StatBytesElapsed;
912 STAMCOUNTER StatBytesTotalWritten;
913 STAMCOUNTER StatFramesPlayed;
914#endif
915 struct
916 {
917 /** File for writing stream writes. */
918 PPDMAUDIOFILE pFileStreamWrite;
919 /** File for writing stream playback. */
920 PPDMAUDIOFILE pFilePlayNonInterleaved;
921 } Dbg;
922} PDMAUDIOSTREAMOUT, *PPDMAUDIOSTREAMOUT;
923
924typedef struct PDMAUDIOSTREAM *PPDMAUDIOSTREAM;
925
926/**
927 * Structure for maintaining an nput/output audio stream.
928 */
929typedef struct PDMAUDIOSTREAM
930{
931 /** List node. */
932 RTLISTNODE Node;
933 /** Pointer to the other pair of this stream.
934 * This might be the host or guest side. */
935 PPDMAUDIOSTREAM pPair;
936 /** Name of this stream. */
937 char szName[64];
938 /** Number of references to this stream. Only can be
939 * destroyed if the reference count is reaching 0. */
940 uint32_t cRefs;
941 /** The stream's audio configuration. */
942 PDMAUDIOSTREAMCFG Cfg;
943 /** Stream status flag. */
944 PDMAUDIOSTREAMSTS fStatus;
945 /** This stream's mixing buffer. */
946 PDMAUDIOMIXBUF MixBuf;
947 /** Audio direction of this stream. */
948 PDMAUDIODIR enmDir;
949 /** Context of this stream. */
950 PDMAUDIOSTREAMCTX enmCtx;
951 /** Timestamp (in ms) since last iteration. */
952 uint64_t tsLastIterateMS;
953 /** Union for input/output specifics. */
954 union
955 {
956 PDMAUDIOSTREAMIN In;
957 PDMAUDIOSTREAMOUT Out;
958 } RT_UNION_NM(u);
959 /** Data to backend-specific stream data.
960 * This data block will be casted by the backend to access its backend-dependent data.
961 *
962 * That way the backends do not have access to the audio connector's data. */
963 void *pvBackend;
964 /** Size (in bytes) of the backend-specific stream data. */
965 size_t cbBackend;
966} PDMAUDIOSTREAM;
967
968/** Pointer to a audio connector interface. */
969typedef struct PDMIAUDIOCONNECTOR *PPDMIAUDIOCONNECTOR;
970
971/**
972 * Enumeration for an audio callback source.
973 */
974typedef enum PDMAUDIOCBSOURCE
975{
976 /** Invalid, do not use. */
977 PDMAUDIOCBSOURCE_INVALID = 0,
978 /** Device emulation. */
979 PDMAUDIOCBSOURCE_DEVICE = 1,
980 /** Audio connector interface. */
981 PDMAUDIOCBSOURCE_CONNECTOR = 2,
982 /** Backend (lower). */
983 PDMAUDIOCBSOURCE_BACKEND = 3,
984 /** Hack to blow the type up to 32-bit. */
985 PDMAUDIOCBSOURCE_32BIT_HACK = 0x7fffffff
986} PDMAUDIOCBSOURCE;
987
988/**
989 * Audio device callback types.
990 * Those callbacks are being sent from the audio connector -> device emulation.
991 */
992typedef enum PDMAUDIODEVICECBTYPE
993{
994 /** Invalid, do not use. */
995 PDMAUDIODEVICECBTYPE_INVALID = 0,
996 /** Data is availabe as input for passing to the device emulation. */
997 PDMAUDIODEVICECBTYPE_DATA_INPUT,
998 /** Free data for the device emulation to write to the backend. */
999 PDMAUDIODEVICECBTYPE_DATA_OUTPUT,
1000 /** Hack to blow the type up to 32-bit. */
1001 PDMAUDIODEVICECBTYPE_32BIT_HACK = 0x7fffffff
1002} PDMAUDIODEVICECBTYPE;
1003
1004/**
1005 * Device callback data for audio input.
1006 */
1007typedef struct PDMAUDIODEVICECBDATA_DATA_INPUT
1008{
1009 /** Input: How many bytes are availabe as input for passing
1010 * to the device emulation. */
1011 uint32_t cbInAvail;
1012 /** Output: How many bytes have been read. */
1013 uint32_t cbOutRead;
1014} PDMAUDIODEVICECBDATA_DATA_INPUT, *PPDMAUDIODEVICECBDATA_DATA_INPUT;
1015
1016/**
1017 * Device callback data for audio output.
1018 */
1019typedef struct PDMAUDIODEVICECBDATA_DATA_OUTPUT
1020{
1021 /** Input: How many bytes are free for the device emulation to write. */
1022 uint32_t cbInFree;
1023 /** Output: How many bytes were written by the device emulation. */
1024 uint32_t cbOutWritten;
1025} PDMAUDIODEVICECBDATA_DATA_OUTPUT, *PPDMAUDIODEVICECBDATA_DATA_OUTPUT;
1026
1027/**
1028 * Audio backend callback types.
1029 * Those callbacks are being sent from the backend -> audio connector.
1030 */
1031typedef enum PDMAUDIOBACKENDCBTYPE
1032{
1033 /** Invalid, do not use. */
1034 PDMAUDIOBACKENDCBTYPE_INVALID = 0,
1035 /** The backend's status has changed. */
1036 PDMAUDIOBACKENDCBTYPE_STATUS,
1037 /** One or more host audio devices have changed. */
1038 PDMAUDIOBACKENDCBTYPE_DEVICES_CHANGED,
1039 /** Hack to blow the type up to 32-bit. */
1040 PDMAUDIOBACKENDCBTYPE_32BIT_HACK = 0x7fffffff
1041} PDMAUDIOBACKENDCBTYPE;
1042
1043/** Pointer to a host audio interface. */
1044typedef struct PDMIHOSTAUDIO *PPDMIHOSTAUDIO;
1045
1046/**
1047 * Host audio callback function.
1048 * This function will be called from a backend to communicate with the host audio interface.
1049 *
1050 * @returns IPRT status code.
1051 * @param pDrvIns Pointer to driver instance which called us.
1052 * @param enmType Callback type.
1053 * @param pvUser User argument.
1054 * @param cbUser Size (in bytes) of user argument.
1055 */
1056typedef DECLCALLBACK(int) FNPDMHOSTAUDIOCALLBACK(PPDMDRVINS pDrvIns, PDMAUDIOBACKENDCBTYPE enmType, void *pvUser, size_t cbUser);
1057/** Pointer to a FNPDMHOSTAUDIOCALLBACK(). */
1058typedef FNPDMHOSTAUDIOCALLBACK *PFNPDMHOSTAUDIOCALLBACK;
1059
1060/**
1061 * Audio callback registration record.
1062 */
1063typedef struct PDMAUDIOCBRECORD
1064{
1065 /** List node. */
1066 RTLISTANCHOR Node;
1067 /** Callback source. */
1068 PDMAUDIOCBSOURCE enmSource;
1069 /** Callback type, based on the given source. */
1070 union
1071 {
1072 /** Device callback stuff. */
1073 struct
1074 {
1075 PDMAUDIODEVICECBTYPE enmType;
1076 } Device;
1077 } RT_UNION_NM(u);
1078 /** Pointer to context data. Optional. */
1079 void *pvCtx;
1080 /** Size (in bytes) of context data.
1081 * Must be 0 if pvCtx is NULL. */
1082 size_t cbCtx;
1083} PDMAUDIOCBRECORD, *PPDMAUDIOCBRECORD;
1084
1085#define PPDMAUDIOBACKENDSTREAM void *
1086
1087/**
1088 * Audio connector interface (up).
1089 */
1090typedef struct PDMIAUDIOCONNECTOR
1091{
1092 /**
1093 * Enables or disables the given audio direction for this driver.
1094 *
1095 * When disabled, assiociated output streams consume written audio without passing them further down to the backends.
1096 * Associated input streams then return silence when read from those.
1097 *
1098 * @returns VBox status code.
1099 * @param pInterface Pointer to the interface structure containing the called function pointer.
1100 * @param enmDir Audio direction to enable or disable driver for.
1101 * @param fEnable Whether to enable or disable the specified audio direction.
1102 */
1103 DECLR3CALLBACKMEMBER(int, pfnEnable, (PPDMIAUDIOCONNECTOR pInterface, PDMAUDIODIR enmDir, bool fEnable));
1104
1105 /**
1106 * Returns whether the given audio direction for this driver is enabled or not.
1107 *
1108 * @returns True if audio is enabled for the given direction, false if not.
1109 * @param pInterface Pointer to the interface structure containing the called function pointer.
1110 * @param enmDir Audio direction to retrieve enabled status for.
1111 */
1112 DECLR3CALLBACKMEMBER(bool, pfnIsEnabled, (PPDMIAUDIOCONNECTOR pInterface, PDMAUDIODIR enmDir));
1113
1114 /**
1115 * Retrieves the current configuration of the host audio backend.
1116 *
1117 * @returns VBox status code.
1118 * @param pInterface Pointer to the interface structure containing the called function pointer.
1119 * @param pCfg Where to store the host audio backend configuration data.
1120 */
1121 DECLR3CALLBACKMEMBER(int, pfnGetConfig, (PPDMIAUDIOCONNECTOR pInterface, PPDMAUDIOBACKENDCFG pCfg));
1122
1123 /**
1124 * Retrieves the current status of the host audio backend.
1125 *
1126 * @returns Status of the host audio backend.
1127 * @param pInterface Pointer to the interface structure containing the called function pointer.
1128 * @param enmDir Audio direction to check host audio backend for. Specify PDMAUDIODIR_ANY for the overall
1129 * backend status.
1130 */
1131 DECLR3CALLBACKMEMBER(PDMAUDIOBACKENDSTS, pfnGetStatus, (PPDMIAUDIOCONNECTOR pInterface, PDMAUDIODIR enmDir));
1132
1133 /**
1134 * Creates an audio stream.
1135 *
1136 * @returns VBox status code.
1137 * @param pInterface Pointer to the interface structure containing the called function pointer.
1138 * @param pCfgHost Stream configuration for host side.
1139 * @param pCfgGuest Stream configuration for guest side.
1140 * @param ppStream Pointer where to return the created audio stream on success.
1141 */
1142 DECLR3CALLBACKMEMBER(int, pfnStreamCreate, (PPDMIAUDIOCONNECTOR pInterface, PPDMAUDIOSTREAMCFG pCfgHost, PPDMAUDIOSTREAMCFG pCfgGuest, PPDMAUDIOSTREAM *ppStream));
1143
1144 /**
1145 * Destroys an audio stream.
1146 *
1147 * @param pInterface Pointer to the interface structure containing the called function pointer.
1148 * @param pStream Pointer to audio stream.
1149 */
1150 DECLR3CALLBACKMEMBER(int, pfnStreamDestroy, (PPDMIAUDIOCONNECTOR pInterface, PPDMAUDIOSTREAM pStream));
1151
1152 /**
1153 * Adds a reference to the specified audio stream.
1154 *
1155 * @returns New reference count. UINT32_MAX on error.
1156 * @param pInterface Pointer to the interface structure containing the called function pointer.
1157 * @param pStream Pointer to audio stream adding the reference to.
1158 */
1159 DECLR3CALLBACKMEMBER(uint32_t, pfnStreamRetain, (PPDMIAUDIOCONNECTOR pInterface, PPDMAUDIOSTREAM pStream));
1160
1161 /**
1162 * Releases a reference from the specified stream.
1163 *
1164 * @returns New reference count. UINT32_MAX on error.
1165 * @param pInterface Pointer to the interface structure containing the called function pointer.
1166 * @param pStream Pointer to audio stream releasing a reference from.
1167 */
1168 DECLR3CALLBACKMEMBER(uint32_t, pfnStreamRelease, (PPDMIAUDIOCONNECTOR pInterface, PPDMAUDIOSTREAM pStream));
1169
1170 /**
1171 * Reads PCM audio data from the host (input).
1172 *
1173 * @returns VBox status code.
1174 * @param pInterface Pointer to the interface structure containing the called function pointer.
1175 * @param pStream Pointer to audio stream to write to.
1176 * @param pvBuf Where to store the read data.
1177 * @param cbBuf Number of bytes to read.
1178 * @param pcbRead Bytes of audio data read. Optional.
1179 */
1180 DECLR3CALLBACKMEMBER(int, pfnStreamRead, (PPDMIAUDIOCONNECTOR pInterface, PPDMAUDIOSTREAM pStream, void *pvBuf, uint32_t cbBuf, uint32_t *pcbRead));
1181
1182 /**
1183 * Writes PCM audio data to the host (output).
1184 *
1185 * @returns VBox status code.
1186 * @param pInterface Pointer to the interface structure containing the called function pointer.
1187 * @param pStream Pointer to audio stream to read from.
1188 * @param pvBuf Audio data to be written.
1189 * @param cbBuf Number of bytes to be written.
1190 * @param pcbWritten Bytes of audio data written. Optional.
1191 */
1192 DECLR3CALLBACKMEMBER(int, pfnStreamWrite, (PPDMIAUDIOCONNECTOR pInterface, PPDMAUDIOSTREAM pStream, const void *pvBuf, uint32_t cbBuf, uint32_t *pcbWritten));
1193
1194 /**
1195 * Controls a specific audio stream.
1196 *
1197 * @returns VBox status code.
1198 * @param pInterface Pointer to the interface structure containing the called function pointer.
1199 * @param pStream Pointer to audio stream.
1200 * @param enmStreamCmd The stream command to issue.
1201 */
1202 DECLR3CALLBACKMEMBER(int, pfnStreamControl, (PPDMIAUDIOCONNECTOR pInterface, PPDMAUDIOSTREAM pStream, PDMAUDIOSTREAMCMD enmStreamCmd));
1203
1204 /**
1205 * Processes stream data.
1206 *
1207 * @param pInterface Pointer to the interface structure containing the called function pointer.
1208 * @param pStream Pointer to audio stream.
1209 */
1210 DECLR3CALLBACKMEMBER(int, pfnStreamIterate, (PPDMIAUDIOCONNECTOR pInterface, PPDMAUDIOSTREAM pStream));
1211
1212 /**
1213 * Returns the number of readable data (in bytes) of a specific audio input stream.
1214 *
1215 * @returns Number of readable data (in bytes).
1216 * @param pInterface Pointer to the interface structure containing the called function pointer.
1217 * @param pStream Pointer to audio stream.
1218 */
1219 DECLR3CALLBACKMEMBER(uint32_t, pfnStreamGetReadable, (PPDMIAUDIOCONNECTOR pInterface, PPDMAUDIOSTREAM pStream));
1220
1221 /**
1222 * Returns the number of writable data (in bytes) of a specific audio output stream.
1223 *
1224 * @returns Number of writable data (in bytes).
1225 * @param pInterface Pointer to the interface structure containing the called function pointer.
1226 * @param pStream Pointer to audio stream.
1227 */
1228 DECLR3CALLBACKMEMBER(uint32_t, pfnStreamGetWritable, (PPDMIAUDIOCONNECTOR pInterface, PPDMAUDIOSTREAM pStream));
1229
1230 /**
1231 * Returns the status of a specific audio stream.
1232 *
1233 * @returns Audio stream status
1234 * @param pInterface Pointer to the interface structure containing the called function pointer.
1235 * @param pStream Pointer to audio stream.
1236 */
1237 DECLR3CALLBACKMEMBER(PDMAUDIOSTREAMSTS, pfnStreamGetStatus, (PPDMIAUDIOCONNECTOR pInterface, PPDMAUDIOSTREAM pStream));
1238
1239 /**
1240 * Sets the audio volume of a specific audio stream.
1241 *
1242 * @returns VBox status code.
1243 * @param pInterface Pointer to the interface structure containing the called function pointer.
1244 * @param pStream Pointer to audio stream.
1245 * @param pVol Pointer to audio volume structure to set the stream's audio volume to.
1246 */
1247 DECLR3CALLBACKMEMBER(int, pfnStreamSetVolume, (PPDMIAUDIOCONNECTOR pInterface, PPDMAUDIOSTREAM pStream, PPDMAUDIOVOLUME pVol));
1248
1249 /**
1250 * Plays (transfers) available audio frames via the host backend. Only works with output streams.
1251 *
1252 * @returns VBox status code.
1253 * @param pInterface Pointer to the interface structure containing the called function pointer.
1254 * @param pStream Pointer to audio stream.
1255 * @param pcFramesPlayed Number of frames played. Optional.
1256 */
1257 DECLR3CALLBACKMEMBER(int, pfnStreamPlay, (PPDMIAUDIOCONNECTOR pInterface, PPDMAUDIOSTREAM pStream, uint32_t *pcFramesPlayed));
1258
1259 /**
1260 * Captures (transfers) available audio frames from the host backend. Only works with input streams.
1261 *
1262 * @returns VBox status code.
1263 * @param pInterface Pointer to the interface structure containing the called function pointer.
1264 * @param pStream Pointer to audio stream.
1265 * @param pcFramesCaptured Number of frames captured. Optional.
1266 */
1267 DECLR3CALLBACKMEMBER(int, pfnStreamCapture, (PPDMIAUDIOCONNECTOR pInterface, PPDMAUDIOSTREAM pStream, uint32_t *pcFramesCaptured));
1268
1269 /**
1270 * Registers (device) callbacks.
1271 * This is handy for letting the device emulation know of certain events, e.g. processing input / output data
1272 * or configuration changes.
1273 *
1274 * @returns VBox status code.
1275 * @param pInterface Pointer to the interface structure containing the called function pointer.
1276 * @param paCallbacks Pointer to array of callbacks to register.
1277 * @param cCallbacks Number of callbacks to register.
1278 */
1279 DECLR3CALLBACKMEMBER(int, pfnRegisterCallbacks, (PPDMIAUDIOCONNECTOR pInterface, PPDMAUDIOCBRECORD paCallbacks, size_t cCallbacks));
1280
1281} PDMIAUDIOCONNECTOR;
1282
1283/** PDMIAUDIOCONNECTOR interface ID. */
1284#define PDMIAUDIOCONNECTOR_IID "A643B40C-733F-4307-9549-070AF0EE0ED6"
1285
1286/**
1287 * Assigns all needed interface callbacks for an audio backend.
1288 *
1289 * @param a_Prefix The function name prefix.
1290 */
1291#define PDMAUDIO_IHOSTAUDIO_CALLBACKS(a_Prefix) \
1292 do { \
1293 pThis->IHostAudio.pfnInit = RT_CONCAT(a_Prefix,Init); \
1294 pThis->IHostAudio.pfnShutdown = RT_CONCAT(a_Prefix,Shutdown); \
1295 pThis->IHostAudio.pfnGetConfig = RT_CONCAT(a_Prefix,GetConfig); \
1296 /** @todo Add pfnGetDevices here as soon as supported by all backends. */ \
1297 pThis->IHostAudio.pfnGetStatus = RT_CONCAT(a_Prefix,GetStatus); \
1298 /** @todo Ditto for pfnSetCallback. */ \
1299 pThis->IHostAudio.pfnStreamCreate = RT_CONCAT(a_Prefix,StreamCreate); \
1300 pThis->IHostAudio.pfnStreamDestroy = RT_CONCAT(a_Prefix,StreamDestroy); \
1301 pThis->IHostAudio.pfnStreamControl = RT_CONCAT(a_Prefix,StreamControl); \
1302 pThis->IHostAudio.pfnStreamGetReadable = RT_CONCAT(a_Prefix,StreamGetReadable); \
1303 pThis->IHostAudio.pfnStreamGetWritable = RT_CONCAT(a_Prefix,StreamGetWritable); \
1304 pThis->IHostAudio.pfnStreamGetStatus = RT_CONCAT(a_Prefix,StreamGetStatus); \
1305 pThis->IHostAudio.pfnStreamIterate = RT_CONCAT(a_Prefix,StreamIterate); \
1306 pThis->IHostAudio.pfnStreamPlay = RT_CONCAT(a_Prefix,StreamPlay); \
1307 pThis->IHostAudio.pfnStreamCapture = RT_CONCAT(a_Prefix,StreamCapture); \
1308 } while (0)
1309
1310/**
1311 * PDM host audio interface.
1312 */
1313typedef struct PDMIHOSTAUDIO
1314{
1315 /**
1316 * Initializes the host backend (driver).
1317 *
1318 * @returns VBox status code.
1319 * @param pInterface Pointer to the interface structure containing the called function pointer.
1320 */
1321 DECLR3CALLBACKMEMBER(int, pfnInit, (PPDMIHOSTAUDIO pInterface));
1322
1323 /**
1324 * Shuts down the host backend (driver).
1325 *
1326 * @returns VBox status code.
1327 * @param pInterface Pointer to the interface structure containing the called function pointer.
1328 */
1329 DECLR3CALLBACKMEMBER(void, pfnShutdown, (PPDMIHOSTAUDIO pInterface));
1330
1331 /**
1332 * Returns the host backend's configuration (backend).
1333 *
1334 * @returns VBox status code.
1335 * @param pInterface Pointer to the interface structure containing the called function pointer.
1336 * @param pBackendCfg Where to store the backend audio configuration to.
1337 */
1338 DECLR3CALLBACKMEMBER(int, pfnGetConfig, (PPDMIHOSTAUDIO pInterface, PPDMAUDIOBACKENDCFG pBackendCfg));
1339
1340 /**
1341 * Returns (enumerates) host audio device information.
1342 *
1343 * @returns VBox status code.
1344 * @param pInterface Pointer to the interface structure containing the called function pointer.
1345 * @param pDeviceEnum Where to return the enumerated audio devices.
1346 */
1347 DECLR3CALLBACKMEMBER(int, pfnGetDevices, (PPDMIHOSTAUDIO pInterface, PPDMAUDIODEVICEENUM pDeviceEnum));
1348
1349 /**
1350 * Returns the current status from the audio backend.
1351 *
1352 * @returns PDMAUDIOBACKENDSTS enum.
1353 * @param pInterface Pointer to the interface structure containing the called function pointer.
1354 * @param enmDir Audio direction to get status for. Pass PDMAUDIODIR_ANY for overall status.
1355 */
1356 DECLR3CALLBACKMEMBER(PDMAUDIOBACKENDSTS, pfnGetStatus, (PPDMIHOSTAUDIO pInterface, PDMAUDIODIR enmDir));
1357
1358 /**
1359 * Sets a callback the audio backend can call. Optional.
1360 *
1361 * @returns VBox status code.
1362 * @param pInterface Pointer to the interface structure containing the called function pointer.
1363 * @param pfnCallback The callback function to use, or NULL when unregistering.
1364 */
1365 DECLR3CALLBACKMEMBER(int, pfnSetCallback, (PPDMIHOSTAUDIO pInterface, PFNPDMHOSTAUDIOCALLBACK pfnCallback));
1366
1367 /**
1368 * Creates an audio stream using the requested stream configuration.
1369 * If a backend is not able to create this configuration, it will return its best match in the acquired configuration
1370 * structure on success.
1371 *
1372 * @returns VBox status code.
1373 * @param pInterface Pointer to the interface structure containing the called function pointer.
1374 * @param pStream Pointer to audio stream.
1375 * @param pCfgReq Pointer to requested stream configuration.
1376 * @param pCfgAcq Pointer to acquired stream configuration.
1377 */
1378 DECLR3CALLBACKMEMBER(int, pfnStreamCreate, (PPDMIHOSTAUDIO pInterface, PPDMAUDIOBACKENDSTREAM pStream, PPDMAUDIOSTREAMCFG pCfgReq, PPDMAUDIOSTREAMCFG pCfgAcq));
1379
1380 /**
1381 * Destroys an audio stream.
1382 *
1383 * @returns VBox status code.
1384 * @param pInterface Pointer to the interface structure containing the called function pointer.
1385 * @param pStream Pointer to audio stream.
1386 */
1387 DECLR3CALLBACKMEMBER(int, pfnStreamDestroy, (PPDMIHOSTAUDIO pInterface, PPDMAUDIOBACKENDSTREAM pStream));
1388
1389 /**
1390 * Controls an audio stream.
1391 *
1392 * @returns VBox status code.
1393 * @param pInterface Pointer to the interface structure containing the called function pointer.
1394 * @param pStream Pointer to audio stream.
1395 * @param enmStreamCmd The stream command to issue.
1396 */
1397 DECLR3CALLBACKMEMBER(int, pfnStreamControl, (PPDMIHOSTAUDIO pInterface, PPDMAUDIOBACKENDSTREAM pStream, PDMAUDIOSTREAMCMD enmStreamCmd));
1398
1399 /**
1400 * Returns the amount which is readable from the audio (input) stream.
1401 *
1402 * @returns For non-raw layout streams: Number of readable bytes.
1403 * for raw layout streams : Number of readable audio frames.
1404 * @param pInterface Pointer to the interface structure containing the called function pointer.
1405 * @param pStream Pointer to audio stream.
1406 */
1407 DECLR3CALLBACKMEMBER(uint32_t, pfnStreamGetReadable, (PPDMIHOSTAUDIO pInterface, PPDMAUDIOBACKENDSTREAM pStream));
1408
1409 /**
1410 * Returns the amount which is writable to the audio (output) stream.
1411 *
1412 * @returns For non-raw layout streams: Number of writable bytes.
1413 * for raw layout streams : Number of writable audio frames.
1414 * @param pInterface Pointer to the interface structure containing the called function pointer.
1415 * @param pStream Pointer to audio stream.
1416 */
1417 DECLR3CALLBACKMEMBER(uint32_t, pfnStreamGetWritable, (PPDMIHOSTAUDIO pInterface, PPDMAUDIOBACKENDSTREAM pStream));
1418
1419 /**
1420 * Returns the amount which is pending (in other words has not yet been processed) by/from the backend yet.
1421 * Optional.
1422 *
1423 * For input streams this is read audio data by the backend which has not been processed by the host yet.
1424 * For output streams this is written audio data to the backend which has not been processed by the backend yet.
1425 *
1426 * @returns For non-raw layout streams: Number of pending bytes.
1427 * for raw layout streams : Number of pending audio frames.
1428 * @param pInterface Pointer to the interface structure containing the called function pointer.
1429 * @param pStream Pointer to audio stream.
1430 */
1431 DECLR3CALLBACKMEMBER(uint32_t, pfnStreamGetPending, (PPDMIHOSTAUDIO pInterface, PPDMAUDIOBACKENDSTREAM pStream));
1432
1433 /**
1434 * Returns the current status of the given backend stream.
1435 *
1436 * @returns PDMAUDIOSTREAMSTS
1437 * @param pInterface Pointer to the interface structure containing the called function pointer.
1438 * @param pStream Pointer to audio stream.
1439 */
1440 DECLR3CALLBACKMEMBER(PDMAUDIOSTREAMSTS, pfnStreamGetStatus, (PPDMIHOSTAUDIO pInterface, PPDMAUDIOBACKENDSTREAM pStream));
1441
1442 /**
1443 * Gives the host backend the chance to do some (necessary) iteration work.
1444 *
1445 * @returns VBox status code.
1446 * @param pInterface Pointer to the interface structure containing the called function pointer.
1447 * @param pStream Pointer to audio stream.
1448 */
1449 DECLR3CALLBACKMEMBER(int, pfnStreamIterate, (PPDMIHOSTAUDIO pInterface, PPDMAUDIOBACKENDSTREAM pStream));
1450
1451 /**
1452 * Signals the backend that the host wants to begin playing for this iteration. Optional.
1453 *
1454 * @param pInterface Pointer to the interface structure containing the called function pointer.
1455 * @param pStream Pointer to audio stream.
1456 */
1457 DECLR3CALLBACKMEMBER(void, pfnStreamPlayBegin, (PPDMIHOSTAUDIO pInterface, PPDMAUDIOBACKENDSTREAM pStream));
1458
1459 /**
1460 * Plays (writes to) an audio (output) stream.
1461 *
1462 * @returns VBox status code.
1463 * @param pInterface Pointer to the interface structure containing the called function pointer.
1464 * @param pStream Pointer to audio stream.
1465 * @param pvBuf Pointer to audio data buffer to play.
1466 * @param cxBuf For non-raw layout streams: Size (in bytes) of audio data buffer,
1467 * for raw layout streams : Size (in audio frames) of audio data buffer.
1468 * @param pcxWritten For non-raw layout streams: Returns number of bytes written. Optional.
1469 * for raw layout streams : Returns number of frames written. Optional.
1470 */
1471 DECLR3CALLBACKMEMBER(int, pfnStreamPlay, (PPDMIHOSTAUDIO pInterface, PPDMAUDIOBACKENDSTREAM pStream, const void *pvBuf, uint32_t cxBuf, uint32_t *pcxWritten));
1472
1473 /**
1474 * Signals the backend that the host finished playing for this iteration. Optional.
1475 *
1476 * @param pInterface Pointer to the interface structure containing the called function pointer.
1477 * @param pStream Pointer to audio stream.
1478 */
1479 DECLR3CALLBACKMEMBER(void, pfnStreamPlayEnd, (PPDMIHOSTAUDIO pInterface, PPDMAUDIOBACKENDSTREAM pStream));
1480
1481 /**
1482 * Signals the backend that the host wants to begin capturing for this iteration. Optional.
1483 *
1484 * @param pInterface Pointer to the interface structure containing the called function pointer.
1485 * @param pStream Pointer to audio stream.
1486 */
1487 DECLR3CALLBACKMEMBER(void, pfnStreamCaptureBegin, (PPDMIHOSTAUDIO pInterface, PPDMAUDIOBACKENDSTREAM pStream));
1488
1489 /**
1490 * Captures (reads from) an audio (input) stream.
1491 *
1492 * @returns VBox status code.
1493 * @param pInterface Pointer to the interface structure containing the called function pointer.
1494 * @param pStream Pointer to audio stream.
1495 * @param pvBuf Buffer where to store read audio data.
1496 * @param cxBuf For non-raw layout streams: Size (in bytes) of audio data buffer,
1497 * for raw layout streams : Size (in audio frames) of audio data buffer.
1498 * @param pcxRead For non-raw layout streams: Returns number of bytes read. Optional.
1499 * for raw layout streams : Returns number of frames read. Optional.
1500 */
1501 DECLR3CALLBACKMEMBER(int, pfnStreamCapture, (PPDMIHOSTAUDIO pInterface, PPDMAUDIOBACKENDSTREAM pStream, void *pvBuf, uint32_t cxBuf, uint32_t *pcxRead));
1502
1503 /**
1504 * Signals the backend that the host finished capturing for this iteration. Optional.
1505 *
1506 * @param pInterface Pointer to the interface structure containing the called function pointer.
1507 * @param pStream Pointer to audio stream.
1508 */
1509 DECLR3CALLBACKMEMBER(void, pfnStreamCaptureEnd, (PPDMIHOSTAUDIO pInterface, PPDMAUDIOBACKENDSTREAM pStream));
1510
1511} PDMIHOSTAUDIO;
1512
1513/** PDMIHOSTAUDIO interface ID. */
1514#define PDMIHOSTAUDIO_IID "640F5A31-8245-491C-538F-29A0F9D08881"
1515
1516/** @} */
1517
1518#endif /* !___VBox_vmm_pdmaudioifs_h */
1519
注意: 瀏覽 TracBrowser 來幫助您使用儲存庫瀏覽器

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