VirtualBox

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

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

VMM/pdmaudioifs.h: Docs.

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

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