VirtualBox

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

Last change on this file since 66581 was 65695, checked in by vboxsync, 8 years ago

Audio: Adjusted PDMAUDIOSTRMSTS_VALID_MASK.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 45.9 KB
Line 
1/** @file
2 * PDM - Pluggable Device Manager, audio interfaces.
3 */
4
5/*
6 * Copyright (C) 2006-2017 Oracle Corporation
7 *
8 * This file is part of VirtualBox Open Source Edition (OSE), as
9 * available from http://www.virtualbox.org. This file is free software;
10 * you can redistribute it and/or modify it under the terms of the GNU
11 * General Public License (GPL) as published by the Free Software
12 * Foundation, in version 2 as it comes in the "COPYING" file of the
13 * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
14 * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
15 *
16 * The contents of this file may alternatively be used under the terms
17 * of the Common Development and Distribution License Version 1.0
18 * (CDDL) only, as it comes in the "COPYING.CDDL" file of the
19 * VirtualBox OSE distribution, in which case the provisions of the
20 * CDDL are applicable instead of those of the GPL.
21 *
22 * You may elect to license modified versions of this file under the
23 * terms and conditions of either the GPL or the CDDL or both.
24 */
25
26#ifndef ___VBox_vmm_pdmaudioifs_h
27#define ___VBox_vmm_pdmaudioifs_h
28
29#include <iprt/circbuf.h>
30#include <iprt/list.h>
31
32#include <VBox/types.h>
33#ifdef VBOX_WITH_STATISTICS
34# include <VBox/vmm/stam.h>
35#endif
36
37/** @defgroup grp_pdm_ifs_audio PDM Audio Interfaces
38 * @ingroup grp_pdm_interfaces
39 * @{
40 */
41
42/** PDM audio driver instance flags. */
43typedef uint32_t PDMAUDIODRVFLAGS;
44
45/** No flags set. */
46#define PDMAUDIODRVFLAGS_NONE 0
47/** Marks a primary audio driver which is critical
48 * when running the VM. */
49#define PDMAUDIODRVFLAGS_PRIMARY RT_BIT(0)
50
51/**
52 * Audio format in signed or unsigned variants.
53 */
54typedef enum PDMAUDIOFMT
55{
56 /** Invalid format, do not use. */
57 PDMAUDIOFMT_INVALID,
58 /** 8-bit, unsigned. */
59 PDMAUDIOFMT_U8,
60 /** 8-bit, signed. */
61 PDMAUDIOFMT_S8,
62 /** 16-bit, unsigned. */
63 PDMAUDIOFMT_U16,
64 /** 16-bit, signed. */
65 PDMAUDIOFMT_S16,
66 /** 32-bit, unsigned. */
67 PDMAUDIOFMT_U32,
68 /** 32-bit, signed. */
69 PDMAUDIOFMT_S32,
70 /** Hack to blow the type up to 32-bit. */
71 PDMAUDIOFMT_32BIT_HACK = 0x7fffffff
72} PDMAUDIOFMT;
73
74/**
75 * Audio direction.
76 */
77typedef enum PDMAUDIODIR
78{
79 /** Unknown direction. */
80 PDMAUDIODIR_UNKNOWN = 0,
81 /** Input. */
82 PDMAUDIODIR_IN = 1,
83 /** Output. */
84 PDMAUDIODIR_OUT = 2,
85 /** Duplex handling. */
86 PDMAUDIODIR_ANY = 3,
87 /** Hack to blow the type up to 32-bit. */
88 PDMAUDIODIR_32BIT_HACK = 0x7fffffff
89} PDMAUDIODIR;
90
91/** Device latency spec in milliseconds (ms). */
92typedef uint32_t PDMAUDIODEVLATSPECMS;
93
94/** Device latency spec in seconds (s). */
95typedef uint32_t PDMAUDIODEVLATSPECSEC;
96
97/** Audio device flags. Use with PDMAUDIODEV_FLAG_ flags. */
98typedef uint32_t PDMAUDIODEVFLAG;
99
100/** No flags set. */
101#define PDMAUDIODEV_FLAGS_NONE 0
102/** The device marks the default device within the host OS. */
103#define PDMAUDIODEV_FLAGS_DEFAULT RT_BIT(0)
104/** The device can be removed at any time and we have to deal with it. */
105#define PDMAUDIODEV_FLAGS_HOTPLUG RT_BIT(1)
106/** The device is known to be buggy and needs special treatment. */
107#define PDMAUDIODEV_FLAGS_BUGGY RT_BIT(2)
108/** Ignore the device, no matter what. */
109#define PDMAUDIODEV_FLAGS_IGNORE RT_BIT(3)
110/** The device is present but marked as locked by some other application. */
111#define PDMAUDIODEV_FLAGS_LOCKED RT_BIT(4)
112/** The device is present but not in an alive state (dead). */
113#define PDMAUDIODEV_FLAGS_DEAD RT_BIT(5)
114
115/**
116 * Audio device type.
117 */
118typedef enum PDMAUDIODEVICETYPE
119{
120 /** Unknown device type. This is the default. */
121 PDMAUDIODEVICETYPE_UNKNOWN = 0,
122 /** Dummy device; for backends which are not able to report
123 * actual device information (yet). */
124 PDMAUDIODEVICETYPE_DUMMY,
125 /** The device is built into the host (non-removable). */
126 PDMAUDIODEVICETYPE_BUILTIN,
127 /** The device is an (external) USB device. */
128 PDMAUDIODEVICETYPE_USB,
129 /** Hack to blow the type up to 32-bit. */
130 PDMAUDIODEVICETYPE_32BIT_HACK = 0x7fffffff
131} PDMAUDIODEVICETYPE;
132
133/**
134 * Audio device instance data.
135 */
136typedef struct PDMAUDIODEVICE
137{
138 /** List node. */
139 RTLISTNODE Node;
140 /** Friendly name of the device, if any. */
141 char szName[64];
142 /** The device type. */
143 PDMAUDIODEVICETYPE enmType;
144 /** Reference count indicating how many audio streams currently are relying on this device. */
145 uint8_t cRefCount;
146 /** Usage of the device. */
147 PDMAUDIODIR enmUsage;
148 /** Device flags. */
149 PDMAUDIODEVFLAG fFlags;
150 /** Maximum number of input audio channels the device supports. */
151 uint8_t cMaxInputChannels;
152 /** Maximum number of output audio channels the device supports. */
153 uint8_t cMaxOutputChannels;
154 /** Additional data which might be relevant for the current context. */
155 void *pvData;
156 /** Size of the additional data. */
157 size_t cbData;
158 /** Device type union, based on enmType. */
159 union
160 {
161 /** USB type specifics. */
162 struct
163 {
164 /** Vendor ID. */
165 int16_t VID;
166 /** Product ID. */
167 int16_t PID;
168 } USB;
169 } Type;
170} PDMAUDIODEVICE, *PPDMAUDIODEVICE;
171
172/**
173 * Structure for keeping an audio device enumeration.
174 */
175typedef struct PDMAUDIODEVICEENUM
176{
177 /** Number of audio devices in the list. */
178 uint16_t cDevices;
179 /** List of audio devices. */
180 RTLISTANCHOR lstDevices;
181} PDMAUDIODEVICEENUM, *PPDMAUDIODEVICEENUM;
182
183/**
184 * Audio (static) configuration of an audio host backend.
185 */
186typedef struct PDMAUDIOBACKENDCFG
187{
188 /** Size (in bytes) of the host backend's audio output stream structure. */
189 size_t cbStreamOut;
190 /** Size (in bytes) of the host backend's audio input stream structure. */
191 size_t cbStreamIn;
192 /** Number of concurrent output streams supported on the host.
193 * UINT32_MAX for unlimited concurrent streams, 0 if no concurrent input streams are supported. */
194 uint32_t cMaxStreamsOut;
195 /** Number of concurrent input streams supported on the host.
196 * UINT32_MAX for unlimited concurrent streams, 0 if no concurrent input streams are supported. */
197 uint32_t cMaxStreamsIn;
198} PDMAUDIOBACKENDCFG, *PPDMAUDIOBACKENDCFG;
199
200/**
201 * A single audio sample, representing left and right channels (stereo).
202 */
203typedef struct PDMAUDIOSAMPLE
204{
205 /** Left channel. */
206 int64_t i64LSample;
207 /** Right channel. */
208 int64_t i64RSample;
209} PDMAUDIOSAMPLE;
210/** Pointer to a single (stereo) audio sample. */
211typedef PDMAUDIOSAMPLE *PPDMAUDIOSAMPLE;
212/** Pointer to a const single (stereo) audio sample. */
213typedef PDMAUDIOSAMPLE const *PCPDMAUDIOSAMPLE;
214
215typedef enum PDMAUDIOENDIANNESS
216{
217 /** The usual invalid endian. */
218 PDMAUDIOENDIANNESS_INVALID,
219 /** Little endian. */
220 PDMAUDIOENDIANNESS_LITTLE,
221 /** Bit endian. */
222 PDMAUDIOENDIANNESS_BIG,
223 /** Endianness doesn't have a meaning in the context. */
224 PDMAUDIOENDIANNESS_NA,
225 /** The end of the valid endian values (exclusive). */
226 PDMAUDIOENDIANNESS_END,
227 /** Hack to blow the type up to 32-bit. */
228 PDMAUDIOENDIANNESS_32BIT_HACK = 0x7fffffff
229} PDMAUDIOENDIANNESS;
230
231/**
232 * Audio playback destinations.
233 */
234typedef enum PDMAUDIOPLAYBACKDEST
235{
236 /** Unknown destination. */
237 PDMAUDIOPLAYBACKDEST_UNKNOWN = 0,
238 /** Front channel. */
239 PDMAUDIOPLAYBACKDEST_FRONT,
240 /** Center / LFE (Subwoofer) channel. */
241 PDMAUDIOPLAYBACKDEST_CENTER_LFE,
242 /** Rear channel. */
243 PDMAUDIOPLAYBACKDEST_REAR,
244 /** Hack to blow the type up to 32-bit. */
245 PDMAUDIOPLAYBACKDEST_32BIT_HACK = 0x7fffffff
246} PDMAUDIOPLAYBACKDEST;
247
248/**
249 * Audio recording sources.
250 */
251typedef enum PDMAUDIORECSOURCE
252{
253 /** Unknown recording source. */
254 PDMAUDIORECSOURCE_UNKNOWN = 0,
255 /** Microphone-In. */
256 PDMAUDIORECSOURCE_MIC,
257 /** CD. */
258 PDMAUDIORECSOURCE_CD,
259 /** Video-In. */
260 PDMAUDIORECSOURCE_VIDEO,
261 /** AUX. */
262 PDMAUDIORECSOURCE_AUX,
263 /** Line-In. */
264 PDMAUDIORECSOURCE_LINE,
265 /** Phone-In. */
266 PDMAUDIORECSOURCE_PHONE,
267 /** Hack to blow the type up to 32-bit. */
268 PDMAUDIORECSOURCE_32BIT_HACK = 0x7fffffff
269} PDMAUDIORECSOURCE;
270
271/**
272 * Audio stream (data) layout.
273 */
274typedef enum PDMAUDIOSTREAMLAYOUT
275{
276 /** Unknown access type; do not use. */
277 PDMAUDIOSTREAMLAYOUT_UNKNOWN = 0,
278 /** Non-interleaved access, that is, consecutive
279 * access to the data. */
280 PDMAUDIOSTREAMLAYOUT_NON_INTERLEAVED,
281 /** Interleaved access, where the data can be
282 * mixed together with data of other audio streams. */
283 PDMAUDIOSTREAMLAYOUT_INTERLEAVED,
284 /** Complex layout, which does not fit into the
285 * interleaved / non-interleaved layouts. */
286 PDMAUDIOSTREAMLAYOUT_COMPLEX,
287 /** Raw (pass through) data, with no data layout processing done. */
288 PDMAUDIOSTREAMLAYOUT_RAW,
289 /** Hack to blow the type up to 32-bit. */
290 PDMAUDIOSTREAMLAYOUT_32BIT_HACK = 0x7fffffff
291} PDMAUDIOSTREAMLAYOUT, *PPDMAUDIOSTREAMLAYOUT;
292
293/** No stream channel data flags defined. */
294#define PDMAUDIOSTREAMCHANNELDATA_FLAG_NONE 0
295
296/**
297 * Structure for keeping a stream channel data block around.
298 */
299typedef struct PDMAUDIOSTREAMCHANNELDATA
300{
301 /** Circular buffer for the channel data. */
302 PRTCIRCBUF pCircBuf;
303 size_t cbAcq;
304 /** Channel data flags. */
305 uint32_t fFlags;
306} PDMAUDIOSTREAMCHANNELDATA, *PPDMAUDIOSTREAMCHANNELDATA;
307
308/**
309 * Structure for a single channel of an audio stream.
310 * An audio stream consists of one or multiple channels,
311 * depending on the configuration.
312 */
313typedef struct PDMAUDIOSTREAMCHANNEL
314{
315 /** Channel ID. */
316 uint8_t uChannel;
317 /** Step size (in bytes) to the channel's next frame. */
318 size_t cbStep;
319 /** Frame size (in bytes) of this channel. */
320 size_t cbFrame;
321 /** Offset (in bytes) to first sample in the data block. */
322 size_t cbFirst;
323 /** Currente offset (in bytes) in the data stream. */
324 size_t cbOff;
325 /** Associated data buffer. */
326 PDMAUDIOSTREAMCHANNELDATA Data;
327} PDMAUDIOSTREAMCHANNEL, *PPDMAUDIOSTREAMCHANNEL;
328
329/**
330 * Union for keeping an audio stream destination or source.
331 */
332typedef union PDMAUDIODESTSOURCE
333{
334 /** Desired playback destination (for an output stream). */
335 PDMAUDIOPLAYBACKDEST Dest;
336 /** Desired recording source (for an input stream). */
337 PDMAUDIORECSOURCE Source;
338} PDMAUDIODESTSOURCE, *PPDMAUDIODESTSOURCE;
339
340/**
341 * Properties of audio streams for host/guest
342 * for in or out directions.
343 */
344typedef struct PDMAUDIOPCMPROPS
345{
346 /** Sample width. Bits per sample. */
347 uint8_t cBits;
348 /** Signed or unsigned sample. */
349 bool fSigned;
350 /** Shift count used for faster calculation of various
351 * values, such as the alignment, bytes to samples and so on.
352 * Depends on number of stream channels and the stream format
353 * being used.
354 *
355 ** @todo Use some RTAsmXXX functions instead?
356 */
357 uint8_t cShift;
358 /** Number of audio channels. */
359 uint8_t cChannels;
360 /** Sample frequency in Hertz (Hz). */
361 uint32_t uHz;
362 /** Whether the endianness is swapped or not. */
363 bool fSwapEndian;
364} PDMAUDIOPCMPROPS, *PPDMAUDIOPCMPROPS;
365
366/** Calculates the cShift value of given samples bits and audio channels.
367 * Note: Does only support mono/stereo channels for now. */
368#define PDMAUDIOPCMPROPS_MAKE_SHIFT_PARMS(cBits, cChannels) ((cChannels == 2) + (cBits / 16))
369/** Calculates the cShift value of a PDMAUDIOPCMPROPS structure.
370 * Note: Does only support mono/stereo channels for now. */
371#define PDMAUDIOPCMPROPS_MAKE_SHIFT(pProps) PDMAUDIOPCMPROPS_MAKE_SHIFT_PARMS((pProps)->cChannels == 2) + (pProps)->cBits / 16)
372/** Converts (audio) samples to bytes.
373 * Needs the cShift value set correctly, using PDMAUDIOPCMPROPS_MAKE_SHIFT. */
374#define PDMAUDIOPCMPROPS_S2B(pProps, samples) ((samples) << (pProps)->cShift)
375/** Converts bytes to (audio) samples.
376 * Needs the cShift value set correctly, using PDMAUDIOPCMPROPS_MAKE_SHIFT. */
377#define PDMAUDIOPCMPROPS_B2S(pProps, cb) (cb >> (pProps)->cShift)
378
379/**
380 * Structure for keeping an audio stream configuration.
381 */
382typedef struct PDMAUDIOSTREAMCFG
383{
384 /** Friendly name of the stream. */
385 char szName[64];
386 /** Direction of the stream. */
387 PDMAUDIODIR enmDir;
388 /** Destination / source indicator, depending on enmDir. */
389 PDMAUDIODESTSOURCE DestSource;
390 /** The stream's PCM properties. */
391 PDMAUDIOPCMPROPS Props;
392 /** The stream's audio data layout.
393 * This indicates how the audio data buffers to/from the backend is being layouted.
394 *
395 * Currently, the following layouts are supported by the audio connector:
396 *
397 * PDMAUDIOSTREAMLAYOUT_NON_INTERLEAVED:
398 * One stream at once. The consecutive audio data is exactly in the format and sample width
399 * like defined in the PCM properties. This is the default.
400 *
401 * PDMAUDIOSTREAMLAYOUT_RAW:
402 * Can be one or many streams at once, depending on the stream's mixing buffer setup.
403 * The audio data will get handled as PDMAUDIOSAMPLE samples without any modification done. */
404 PDMAUDIOSTREAMLAYOUT enmLayout;
405 /** Hint about the optimal sample buffer size (in audio samples).
406 * 0 if no hint is given. */
407 uint32_t cSampleBufferHint;
408} PDMAUDIOSTREAMCFG, *PPDMAUDIOSTREAMCFG;
409
410/** Converts (audio) samples to bytes. */
411#define PDMAUDIOSTREAMCFG_S2B(pCfg, samples) ((samples) << (pCfg->Props).cShift)
412/** Converts bytes to (audio) samples. */
413#define PDMAUDIOSTREAMCFG_B2S(pCfg, cb) (cb >> (pCfg->Props).cShift)
414
415#if defined(RT_LITTLE_ENDIAN)
416# define PDMAUDIOHOSTENDIANNESS PDMAUDIOENDIANNESS_LITTLE
417#elif defined(RT_BIG_ENDIAN)
418# define PDMAUDIOHOSTENDIANNESS PDMAUDIOENDIANNESS_BIG
419#else
420# error "Port me!"
421#endif
422
423/**
424 * Audio mixer controls.
425 */
426typedef enum PDMAUDIOMIXERCTL
427{
428 /** Unknown mixer control. */
429 PDMAUDIOMIXERCTL_UNKNOWN = 0,
430 /** Master volume. */
431 PDMAUDIOMIXERCTL_VOLUME_MASTER,
432 /** Front. */
433 PDMAUDIOMIXERCTL_FRONT,
434 /** Center / LFE (Subwoofer). */
435 PDMAUDIOMIXERCTL_CENTER_LFE,
436 /** Rear. */
437 PDMAUDIOMIXERCTL_REAR,
438 /** Line-In. */
439 PDMAUDIOMIXERCTL_LINE_IN,
440 /** Microphone-In. */
441 PDMAUDIOMIXERCTL_MIC_IN,
442 /** Hack to blow the type up to 32-bit. */
443 PDMAUDIOMIXERCTL_32BIT_HACK = 0x7fffffff
444} PDMAUDIOMIXERCTL;
445
446/**
447 * Audio stream commands. Used in the audio connector
448 * as well as in the actual host backends.
449 */
450typedef enum PDMAUDIOSTREAMCMD
451{
452 /** Unknown command, do not use. */
453 PDMAUDIOSTREAMCMD_UNKNOWN = 0,
454 /** Enables the stream. */
455 PDMAUDIOSTREAMCMD_ENABLE,
456 /** Disables the stream. */
457 PDMAUDIOSTREAMCMD_DISABLE,
458 /** Pauses the stream. */
459 PDMAUDIOSTREAMCMD_PAUSE,
460 /** Resumes the stream. */
461 PDMAUDIOSTREAMCMD_RESUME,
462 /** Hack to blow the type up to 32-bit. */
463 PDMAUDIOSTREAMCMD_32BIT_HACK = 0x7fffffff
464} PDMAUDIOSTREAMCMD;
465
466/**
467 * Audio volume parameters.
468 */
469typedef struct PDMAUDIOVOLUME
470{
471 /** Set to @c true if this stream is muted, @c false if not. */
472 bool fMuted;
473 /** Left channel volume.
474 * Range is from [0 ... 255], whereas 0 specifies
475 * the most silent and 255 the loudest value. */
476 uint8_t uLeft;
477 /** Right channel volume.
478 * Range is from [0 ... 255], whereas 0 specifies
479 * the most silent and 255 the loudest value. */
480 uint8_t uRight;
481} PDMAUDIOVOLUME, *PPDMAUDIOVOLUME;
482
483/** Defines the minimum volume allowed. */
484#define PDMAUDIO_VOLUME_MIN (0)
485/** Defines the maximum volume allowed. */
486#define PDMAUDIO_VOLUME_MAX (255)
487
488/**
489 * Structure for holding rate processing information
490 * of a source + destination audio stream. This is needed
491 * because both streams can differ regarding their rates
492 * and therefore need to be treated accordingly.
493 */
494typedef struct PDMAUDIOSTRMRATE
495{
496 /** Current (absolute) offset in the output
497 * (destination) stream. */
498 uint64_t dstOffset;
499 /** Increment for moving dstOffset for the
500 * destination stream. This is needed because the
501 * source <-> destination rate might be different. */
502 uint64_t dstInc;
503 /** Current (absolute) offset in the input
504 * stream. */
505 uint32_t srcOffset;
506 /** Last processed sample of the input stream.
507 * Needed for interpolation. */
508 PDMAUDIOSAMPLE srcSampleLast;
509} PDMAUDIOSTRMRATE, *PPDMAUDIOSTRMRATE;
510
511/**
512 * Structure for holding mixing buffer volume parameters.
513 * The volume values are in fixed point style and must
514 * be converted to/from before using with e.g. PDMAUDIOVOLUME.
515 */
516typedef struct PDMAUDMIXBUFVOL
517{
518 /** Set to @c true if this stream is muted, @c false if not. */
519 bool fMuted;
520 /** Left volume to apply during conversion. Pass 0
521 * to convert the original values. May not apply to
522 * all conversion functions. */
523 uint32_t uLeft;
524 /** Right volume to apply during conversion. Pass 0
525 * to convert the original values. May not apply to
526 * all conversion functions. */
527 uint32_t uRight;
528} PDMAUDMIXBUFVOL, *PPDMAUDMIXBUFVOL;
529
530/**
531 * Structure for holding sample conversion parameters for
532 * the audioMixBufConvFromXXX / audioMixBufConvToXXX macros.
533 */
534typedef struct PDMAUDMIXBUFCONVOPTS
535{
536 /** Number of audio samples to convert. */
537 uint32_t cSamples;
538 union
539 {
540 struct
541 {
542 /** Volume to use for conversion. */
543 PDMAUDMIXBUFVOL Volume;
544 } From;
545 };
546} PDMAUDMIXBUFCONVOPTS;
547/** Pointer to conversion parameters for the audio mixer. */
548typedef PDMAUDMIXBUFCONVOPTS *PPDMAUDMIXBUFCONVOPTS;
549/** Pointer to const conversion parameters for the audio mixer. */
550typedef PDMAUDMIXBUFCONVOPTS const *PCPDMAUDMIXBUFCONVOPTS;
551
552/**
553 * Note: All internal handling is done in samples,
554 * not in bytes!
555 */
556typedef uint32_t PDMAUDIOMIXBUFFMT;
557typedef PDMAUDIOMIXBUFFMT *PPDMAUDIOMIXBUFFMT;
558
559/**
560 * Convertion-from function used by the PDM audio buffer mixer.
561 *
562 * @returns Number of samples returned.
563 * @param paDst Where to return the converted samples.
564 * @param pvSrc The source samples bytes.
565 * @param cbSrc Number of bytes to convert.
566 * @param pOpts Conversion options.
567 */
568typedef DECLCALLBACK(uint32_t) FNPDMAUDIOMIXBUFCONVFROM(PPDMAUDIOSAMPLE paDst, const void *pvSrc, uint32_t cbSrc,
569 PCPDMAUDMIXBUFCONVOPTS pOpts);
570/** Pointer to a convertion-from function used by the PDM audio buffer mixer. */
571typedef FNPDMAUDIOMIXBUFCONVFROM *PFNPDMAUDIOMIXBUFCONVFROM;
572
573/**
574 * Convertion-to function used by the PDM audio buffer mixer.
575 *
576 * @param pvDst Output buffer.
577 * @param paSrc The input samples.
578 * @param pOpts Conversion options.
579 */
580typedef DECLCALLBACK(void) FNPDMAUDIOMIXBUFCONVTO(void *pvDst, PCPDMAUDIOSAMPLE paSrc, PCPDMAUDMIXBUFCONVOPTS pOpts);
581/** Pointer to a convertion-to function used by the PDM audio buffer mixer. */
582typedef FNPDMAUDIOMIXBUFCONVTO *PFNPDMAUDIOMIXBUFCONVTO;
583
584typedef struct PDMAUDIOMIXBUF *PPDMAUDIOMIXBUF;
585typedef struct PDMAUDIOMIXBUF
586{
587 RTLISTNODE Node;
588 /** Name of the buffer. */
589 char *pszName;
590 /** Sample buffer. */
591 PPDMAUDIOSAMPLE pSamples;
592 /** Size of the sample buffer (in samples). */
593 uint32_t cSamples;
594 /** The current read position (in samples). */
595 uint32_t offRead;
596 /** The current write position (in samples). */
597 uint32_t offWrite;
598 /**
599 * Total samples already mixed down to the parent buffer (if any). Always starting at
600 * the parent's offRead position.
601 *
602 * Note: Count always is specified in parent samples, as the sample count can differ between parent
603 * and child.
604 */
605 uint32_t cMixed;
606 /** How much audio samples are currently being used
607 * in this buffer.
608 * Note: This also is known as the distance in ring buffer terms. */
609 uint32_t cUsed;
610 /** Pointer to parent buffer (if any). */
611 PPDMAUDIOMIXBUF pParent;
612 /** List of children mix buffers to keep in sync with (if being a parent buffer). */
613 RTLISTANCHOR lstChildren;
614 /** Intermediate structure for buffer conversion tasks. */
615 PPDMAUDIOSTRMRATE pRate;
616 /** Internal representation of current volume used for mixing. */
617 PDMAUDMIXBUFVOL Volume;
618 /** This buffer's audio format. */
619 PDMAUDIOMIXBUFFMT AudioFmt;
620 /** Standard conversion-to function for set AudioFmt. */
621 PFNPDMAUDIOMIXBUFCONVTO pfnConvTo;
622 /** Standard conversion-from function for set AudioFmt. */
623 PFNPDMAUDIOMIXBUFCONVFROM pfnConvFrom;
624 /**
625 * Ratio of the associated parent stream's frequency by this stream's
626 * frequency (1<<32), represented as a signed 64 bit integer.
627 *
628 * For example, if the parent stream has a frequency of 44 khZ, and this
629 * stream has a frequency of 11 kHz, the ration then would be
630 * (44/11 * (1 << 32)).
631 *
632 * Currently this does not get changed once assigned.
633 */
634 int64_t iFreqRatio;
635 /** For quickly converting samples <-> bytes and vice versa. */
636 uint8_t cShift;
637} PDMAUDIOMIXBUF;
638
639typedef uint32_t PDMAUDIOFILEFLAGS;
640
641/* No flags defined. */
642#define PDMAUDIOFILEFLAG_NONE 0
643
644/**
645 * Audio file types.
646 */
647typedef enum PDMAUDIOFILETYPE
648{
649 /** Unknown type, do not use. */
650 PDMAUDIOFILETYPE_UNKNOWN = 0,
651 /** Wave (.WAV) file. */
652 PDMAUDIOFILETYPE_WAV,
653 /** Hack to blow the type up to 32-bit. */
654 PDMAUDIOFILETYPE_32BIT_HACK = 0x7fffffff
655} PDMAUDIOFILETYPE;
656
657/**
658 * Structure for an audio file handle.
659 */
660typedef struct PDMAUDIOFILE
661{
662 /** Type of the audio file. */
663 PDMAUDIOFILETYPE enmType;
664 /** File name. */
665 char szName[255];
666 /** Actual file handle. */
667 RTFILE hFile;
668 /** Data needed for the specific audio file type implemented.
669 * Optional, can be NULL. */
670 void *pvData;
671 /** Data size (in bytes). */
672 size_t cbData;
673} PDMAUDIOFILE, *PPDMAUDIOFILE;
674
675/** Stream status flag. To be used with PDMAUDIOSTRMSTS_FLAG_ flags. */
676typedef uint32_t PDMAUDIOSTRMSTS;
677
678/** No flags being set. */
679#define PDMAUDIOSTRMSTS_FLAG_NONE 0
680/** Whether this stream has been initialized by the
681 * backend or not. */
682#define PDMAUDIOSTRMSTS_FLAG_INITIALIZED RT_BIT_32(0)
683/** Whether this stream is enabled or disabled. */
684#define PDMAUDIOSTRMSTS_FLAG_ENABLED RT_BIT_32(1)
685/** Whether this stream has been paused or not. This also implies
686 * that this is an enabled stream! */
687#define PDMAUDIOSTRMSTS_FLAG_PAUSED RT_BIT_32(2)
688/** Whether this stream was marked as being disabled
689 * but there are still associated guest output streams
690 * which rely on its data. */
691#define PDMAUDIOSTRMSTS_FLAG_PENDING_DISABLE RT_BIT_32(3)
692/** Whether this stream is in re-initialization phase.
693 * All other bits remain untouched to be able to restore
694 * the stream's state after the re-initialization bas been
695 * finished. */
696#define PDMAUDIOSTRMSTS_FLAG_PENDING_REINIT RT_BIT_32(4)
697/** Validation mask. */
698#define PDMAUDIOSTRMSTS_VALID_MASK UINT32_C(0x0000001F)
699
700/**
701 * Enumeration presenting a backend's current status.
702 */
703typedef enum PDMAUDIOBACKENDSTS
704{
705 /** Unknown/invalid status. */
706 PDMAUDIOBACKENDSTS_UNKNOWN = 0,
707 /** The backend is in its initialization phase.
708 * Not all backends support this status. */
709 PDMAUDIOBACKENDSTS_INITIALIZING,
710 /** The backend has stopped its operation. */
711 PDMAUDIOBACKENDSTS_STOPPED,
712 /** The backend is up and running. */
713 PDMAUDIOBACKENDSTS_RUNNING,
714 /** The backend ran into an error and is unable to recover.
715 * A manual re-initialization might help. */
716 PDMAUDIOBACKENDSTS_ERROR,
717 /** Hack to blow the type up to 32-bit. */
718 PDMAUDIOBACKENDSTS_32BIT_HACK = 0x7fffffff
719} PDMAUDIOBACKENDSTS;
720
721/**
722 * Audio stream context.
723 */
724typedef enum PDMAUDIOSTREAMCTX
725{
726 /** No context set / invalid. */
727 PDMAUDIOSTREAMCTX_UNKNOWN = 0,
728 /** Host stream, connected to a backend. */
729 PDMAUDIOSTREAMCTX_HOST,
730 /** Guest stream, connected to the device emulation. */
731 PDMAUDIOSTREAMCTX_GUEST,
732 /** Hack to blow the type up to 32-bit. */
733 PDMAUDIOSTREAMCTX_32BIT_HACK = 0x7fffffff
734} PDMAUDIOSTREAMCTX;
735
736/**
737 * Structure for keeping audio input stream specifics.
738 * Do not use directly. Instead, use PDMAUDIOSTREAM.
739 */
740typedef struct PDMAUDIOSTREAMIN
741{
742 /** Timestamp (in ms) since last read. */
743 uint64_t tsLastReadMS;
744#ifdef VBOX_WITH_STATISTICS
745 STAMCOUNTER StatBytesElapsed;
746 STAMCOUNTER StatBytesTotalRead;
747 STAMCOUNTER StatSamplesCaptured;
748#endif
749} PDMAUDIOSTREAMIN, *PPDMAUDIOSTREAMIN;
750
751/**
752 * Structure for keeping audio output stream specifics.
753 * Do not use directly. Instead, use PDMAUDIOSTREAM.
754 */
755typedef struct PDMAUDIOSTREAMOUT
756{
757 /** Timestamp (in ms) since last write. */
758 uint64_t tsLastWriteMS;
759#ifdef VBOX_WITH_STATISTICS
760 STAMCOUNTER StatBytesElapsed;
761 STAMCOUNTER StatBytesTotalWritten;
762 STAMCOUNTER StatSamplesPlayed;
763#endif
764} PDMAUDIOSTREAMOUT, *PPDMAUDIOSTREAMOUT;
765
766struct PDMAUDIOSTREAM;
767typedef PDMAUDIOSTREAM *PPDMAUDIOSTREAM;
768
769/**
770 * Structure for maintaining an nput/output audio stream.
771 */
772typedef struct PDMAUDIOSTREAM
773{
774 /** List node. */
775 RTLISTNODE Node;
776 /** Pointer to the other pair of this stream.
777 * This might be the host or guest side. */
778 PPDMAUDIOSTREAM pPair;
779 /** Name of this stream. */
780 char szName[64];
781 /** Number of references to this stream. Only can be
782 * destroyed if the reference count is reaching 0. */
783 uint32_t cRefs;
784 /** The stream's audio configuration. */
785 PDMAUDIOSTREAMCFG Cfg;
786 /** Stream status flag. */
787 PDMAUDIOSTRMSTS fStatus;
788 /** This stream's mixing buffer. */
789 PDMAUDIOMIXBUF MixBuf;
790 /** Audio direction of this stream. */
791 PDMAUDIODIR enmDir;
792 /** Context of this stream. */
793 PDMAUDIOSTREAMCTX enmCtx;
794 /** Timestamp (in ms) since last iteration. */
795 uint64_t tsLastIterateMS;
796 /** Union for input/output specifics. */
797 union
798 {
799 PDMAUDIOSTREAMIN In;
800 PDMAUDIOSTREAMOUT Out;
801 };
802 /** Data to backend-specific stream data.
803 * This data block will be casted by the backend to access its backend-dependent data.
804 *
805 * That way the backends do not have access to the audio connector's data. */
806 void *pvBackend;
807 /** Size (in bytes) of the backend-specific stream data. */
808 size_t cbBackend;
809} PDMAUDIOSTREAM, *PPDMAUDIOSTREAM;
810
811/** Pointer to a audio connector interface. */
812typedef struct PDMIAUDIOCONNECTOR *PPDMIAUDIOCONNECTOR;
813
814/**
815 * Audio callback types.
816 * Those callbacks are being sent from the backends to the audio connector.
817 */
818typedef enum PDMAUDIOCBTYPE
819{
820 /** Invalid, do not use. */
821 PDMAUDIOCBTYPE_INVALID = 0,
822 /** The backend's status has changed. */
823 PDMAUDIOCBTYPE_STATUS,
824 /** One or more host audio devices have changed. */
825 PDMAUDIOCBTYPE_DEVICES_CHANGED,
826 /** Data is availabe as input for passing to the device emulation. */
827 PDMAUDIOCBTYPE_DATA_INPUT,
828 /** Free data for the device emulation to write to the backend. */
829 PDMAUDIOCBTYPE_DATA_OUTPUT
830} PDMAUDIOCBTYPE;
831
832/**
833 * Callback data for audio input.
834 */
835typedef struct PDMAUDIOCBDATA_DATA_INPUT
836{
837 /** Input: How many bytes are availabe as input for passing
838 * to the device emulation. */
839 uint32_t cbInAvail;
840 /** Output: How many bytes have been read. */
841 uint32_t cbOutRead;
842} PDMAUDIOCBDATA_DATA_INPUT, *PPDMAUDIOCBDATA_DATA_INPUT;
843
844/**
845 * Callback data for audio output.
846 */
847typedef struct PDMAUDIOCBDATA_DATA_OUTPUT
848{
849 /** Input: How many bytes are free for the device emulation to write. */
850 uint32_t cbInFree;
851 /** Output: How many bytes were written by the device emulation. */
852 uint32_t cbOutWritten;
853} PDMAUDIOCBDATA_DATA_OUTPUT, *PPDMAUDIOCBDATA_DATA_OUTPUT;
854
855/** Pointer to a host audio interface. */
856typedef struct PDMIHOSTAUDIO *PPDMIHOSTAUDIO;
857
858/**
859 * Host audio (backend) callback function.
860 *
861 * @returns IPRT status code.
862 * @param pDrvIns Pointer to driver instance which called us.
863 * @param enmType Callback type.
864 * @param pvUser User argument.
865 * @param cbUser Size (in bytes) of user argument.
866 */
867typedef DECLCALLBACK(int) FNPDMHOSTAUDIOCALLBACK(PPDMDRVINS pDrvIns, PDMAUDIOCBTYPE enmType, void *pvUser, size_t cbUser);
868/** Pointer to a FNPDMHOSTAUDIOCALLBACK(). */
869typedef FNPDMHOSTAUDIOCALLBACK *PFNPDMHOSTAUDIOCALLBACK;
870
871#ifdef VBOX_WITH_AUDIO_DEVICE_CALLBACKS
872/**
873 * Structure for keeping a registered audio callback around.
874 */
875typedef struct PDMAUDIOCALLBACK
876{
877 /** List node. */
878 RTLISTANCHOR Node;
879 /** Callback type. */
880 PDMAUDIOCBTYPE enmType;
881 /** Pointer to context data. Optional. */
882 void *pvCtx;
883 /** Size (in bytes) of context data.
884 * Must be 0 if pvCtx is NULL. */
885 size_t cbCtx;
886 /** Actual callback function to call. */
887 PFNPDMAUDIOCALLBACK pFn;
888} PDMAUDIOCALLBACK, *PPDMAUDIOCALLBACK;
889#endif /* VBOX_WITH_AUDIO_DEVICE_CALLBACKS */
890
891#define PPDMAUDIOBACKENDSTREAM void *
892
893/**
894 * Audio connector interface (up).
895 */
896typedef struct PDMIAUDIOCONNECTOR
897{
898 /**
899 * Retrieves the current configuration of the host audio backend.
900 *
901 * @returns VBox status code.
902 * @param pInterface Pointer to the interface structure containing the called function pointer.
903 * @param pCfg Where to store the host audio backend configuration data.
904 */
905 DECLR3CALLBACKMEMBER(int, pfnGetConfig, (PPDMIAUDIOCONNECTOR pInterface, PPDMAUDIOBACKENDCFG pCfg));
906
907 /**
908 * Retrieves the current status of the host audio backend.
909 *
910 * @returns Status of the host audio backend.
911 * @param pInterface Pointer to the interface structure containing the called function pointer.
912 * @param enmDir Audio direction to check host audio backend for. Specify PDMAUDIODIR_ANY for the overall
913 * backend status.
914 */
915 DECLR3CALLBACKMEMBER(PDMAUDIOBACKENDSTS, pfnGetStatus, (PPDMIAUDIOCONNECTOR pInterface, PDMAUDIODIR enmDir));
916
917 /**
918 * Creates an audio stream.
919 *
920 * @returns VBox status code.
921 * @param pInterface Pointer to the interface structure containing the called function pointer.
922 * @param pCfgHost Stream configuration for host side.
923 * @param pCfgGuest Stream configuration for guest side.
924 * @param ppStream Pointer where to return the created audio stream on success.
925 */
926 DECLR3CALLBACKMEMBER(int, pfnStreamCreate, (PPDMIAUDIOCONNECTOR pInterface, PPDMAUDIOSTREAMCFG pCfgHost, PPDMAUDIOSTREAMCFG pCfgGuest, PPDMAUDIOSTREAM *ppStream));
927
928 /**
929 * Destroys an audio stream.
930 *
931 * @param pInterface Pointer to the interface structure containing the called function pointer.
932 * @param pStream Pointer to audio stream.
933 */
934 DECLR3CALLBACKMEMBER(int, pfnStreamDestroy, (PPDMIAUDIOCONNECTOR pInterface, PPDMAUDIOSTREAM pStream));
935
936 /**
937 * Adds a reference to the specified audio stream.
938 *
939 * @returns New reference count. UINT32_MAX on error.
940 * @param pInterface Pointer to the interface structure containing the called function pointer.
941 * @param pStream Pointer to audio stream adding the reference to.
942 */
943 DECLR3CALLBACKMEMBER(uint32_t, pfnStreamRetain, (PPDMIAUDIOCONNECTOR pInterface, PPDMAUDIOSTREAM pStream));
944
945 /**
946 * Releases a reference from the specified stream.
947 *
948 * @returns New reference count. UINT32_MAX on error.
949 * @param pInterface Pointer to the interface structure containing the called function pointer.
950 * @param pStream Pointer to audio stream releasing a reference from.
951 */
952 DECLR3CALLBACKMEMBER(uint32_t, pfnStreamRelease, (PPDMIAUDIOCONNECTOR pInterface, PPDMAUDIOSTREAM pStream));
953
954 /**
955 * Reads PCM audio data from the host (input).
956 *
957 * @returns VBox status code.
958 * @param pInterface Pointer to the interface structure containing the called function pointer.
959 * @param pStream Pointer to audio stream to write to.
960 * @param pvBuf Where to store the read data.
961 * @param cbBuf Number of bytes to read.
962 * @param pcbRead Bytes of audio data read. Optional.
963 */
964 DECLR3CALLBACKMEMBER(int, pfnStreamRead, (PPDMIAUDIOCONNECTOR pInterface, PPDMAUDIOSTREAM pStream, void *pvBuf, uint32_t cbBuf, uint32_t *pcbRead));
965
966 /**
967 * Writes PCM audio data to the host (output).
968 *
969 * @returns VBox status code.
970 * @param pInterface Pointer to the interface structure containing the called function pointer.
971 * @param pStream Pointer to audio stream to read from.
972 * @param pvBuf Audio data to be written.
973 * @param cbBuf Number of bytes to be written.
974 * @param pcbWritten Bytes of audio data written. Optional.
975 */
976 DECLR3CALLBACKMEMBER(int, pfnStreamWrite, (PPDMIAUDIOCONNECTOR pInterface, PPDMAUDIOSTREAM pStream, const void *pvBuf, uint32_t cbBuf, uint32_t *pcbWritten));
977
978 /**
979 * Controls a specific audio stream.
980 *
981 * @returns VBox status code.
982 * @param pInterface Pointer to the interface structure containing the called function pointer.
983 * @param pStream Pointer to audio stream.
984 * @param enmStreamCmd The stream command to issue.
985 */
986 DECLR3CALLBACKMEMBER(int, pfnStreamControl, (PPDMIAUDIOCONNECTOR pInterface, PPDMAUDIOSTREAM pStream, PDMAUDIOSTREAMCMD enmStreamCmd));
987
988 /**
989 * Processes stream data.
990 *
991 * @param pInterface Pointer to the interface structure containing the called function pointer.
992 * @param pStream Pointer to audio stream.
993 */
994 DECLR3CALLBACKMEMBER(int, pfnStreamIterate, (PPDMIAUDIOCONNECTOR pInterface, PPDMAUDIOSTREAM pStream));
995
996 /**
997 * Returns the number of readable data (in bytes) of a specific audio input stream.
998 *
999 * @returns Number of readable data (in bytes).
1000 * @param pInterface Pointer to the interface structure containing the called function pointer.
1001 * @param pStream Pointer to audio stream.
1002 */
1003 DECLR3CALLBACKMEMBER(uint32_t, pfnStreamGetReadable, (PPDMIAUDIOCONNECTOR pInterface, PPDMAUDIOSTREAM pStream));
1004
1005 /**
1006 * Returns the number of writable data (in bytes) of a specific audio output stream.
1007 *
1008 * @returns Number of writable data (in bytes).
1009 * @param pInterface Pointer to the interface structure containing the called function pointer.
1010 * @param pStream Pointer to audio stream.
1011 */
1012 DECLR3CALLBACKMEMBER(uint32_t, pfnStreamGetWritable, (PPDMIAUDIOCONNECTOR pInterface, PPDMAUDIOSTREAM pStream));
1013
1014 /**
1015 * Returns the status of a specific audio stream.
1016 *
1017 * @returns Audio stream status
1018 * @param pInterface Pointer to the interface structure containing the called function pointer.
1019 * @param pStream Pointer to audio stream.
1020 */
1021 DECLR3CALLBACKMEMBER(PDMAUDIOSTRMSTS, pfnStreamGetStatus, (PPDMIAUDIOCONNECTOR pInterface, PPDMAUDIOSTREAM pStream));
1022
1023 /**
1024 * Sets the audio volume of a specific audio stream.
1025 *
1026 * @returns VBox status code.
1027 * @param pInterface Pointer to the interface structure containing the called function pointer.
1028 * @param pStream Pointer to audio stream.
1029 * @param pVol Pointer to audio volume structure to set the stream's audio volume to.
1030 */
1031 DECLR3CALLBACKMEMBER(int, pfnStreamSetVolume, (PPDMIAUDIOCONNECTOR pInterface, PPDMAUDIOSTREAM pStream, PPDMAUDIOVOLUME pVol));
1032
1033 /**
1034 * Plays (transfers) available audio samples via the host backend. Only works with output streams.
1035 *
1036 * @returns VBox status code.
1037 * @param pInterface Pointer to the interface structure containing the called function pointer.
1038 * @param pStream Pointer to audio stream.
1039 * @param pcSamplesPlayed Number of samples played. Optional.
1040 */
1041 DECLR3CALLBACKMEMBER(int, pfnStreamPlay, (PPDMIAUDIOCONNECTOR pInterface, PPDMAUDIOSTREAM pStream, uint32_t *pcSamplesPlayed));
1042
1043 /**
1044 * Captures (transfers) available audio samples from the host backend. Only works with input streams.
1045 *
1046 * @returns VBox status code.
1047 * @param pInterface Pointer to the interface structure containing the called function pointer.
1048 * @param pStream Pointer to audio stream.
1049 * @param pcSamplesCaptured Number of samples captured. Optional.
1050 */
1051 DECLR3CALLBACKMEMBER(int, pfnStreamCapture, (PPDMIAUDIOCONNECTOR pInterface, PPDMAUDIOSTREAM pStream, uint32_t *pcSamplesCaptured));
1052
1053#ifdef VBOX_WITH_AUDIO_DEVICE_CALLBACKS
1054 DECLR3CALLBACKMEMBER(int, pfnRegisterCallbacks, (PPDMIAUDIOCONNECTOR pInterface, PPDMAUDIOCALLBACK paCallbacks, size_t cCallbacks));
1055 DECLR3CALLBACKMEMBER(int, pfnCallback, (PPDMIAUDIOCONNECTOR pInterface, PDMAUDIOCBTYPE enmType, void *pvUser, size_t cbUser));
1056#endif
1057
1058} PDMIAUDIOCONNECTOR;
1059
1060/** PDMIAUDIOCONNECTOR interface ID. */
1061#define PDMIAUDIOCONNECTOR_IID "FF2044D1-F8D9-4F42-BE9E-0E9AD14F4552"
1062
1063/**
1064 * Assigns all needed interface callbacks for an audio backend.
1065 *
1066 * @param a_Prefix The function name prefix.
1067 */
1068#define PDMAUDIO_IHOSTAUDIO_CALLBACKS(a_Prefix) \
1069 do { \
1070 pThis->IHostAudio.pfnInit = RT_CONCAT(a_Prefix,Init); \
1071 pThis->IHostAudio.pfnShutdown = RT_CONCAT(a_Prefix,Shutdown); \
1072 pThis->IHostAudio.pfnGetConfig = RT_CONCAT(a_Prefix,GetConfig); \
1073 /** @todo Add pfnGetDevices here as soon as supported by all backends. */ \
1074 pThis->IHostAudio.pfnGetStatus = RT_CONCAT(a_Prefix,GetStatus); \
1075 /** @todo Ditto for pfnSetCallback. */ \
1076 pThis->IHostAudio.pfnStreamCreate = RT_CONCAT(a_Prefix,StreamCreate); \
1077 pThis->IHostAudio.pfnStreamDestroy = RT_CONCAT(a_Prefix,StreamDestroy); \
1078 pThis->IHostAudio.pfnStreamControl = RT_CONCAT(a_Prefix,StreamControl); \
1079 pThis->IHostAudio.pfnStreamGetReadable = RT_CONCAT(a_Prefix,StreamGetReadable); \
1080 pThis->IHostAudio.pfnStreamGetWritable = RT_CONCAT(a_Prefix,StreamGetWritable); \
1081 pThis->IHostAudio.pfnStreamGetStatus = RT_CONCAT(a_Prefix,StreamGetStatus); \
1082 pThis->IHostAudio.pfnStreamIterate = RT_CONCAT(a_Prefix,StreamIterate); \
1083 pThis->IHostAudio.pfnStreamPlay = RT_CONCAT(a_Prefix,StreamPlay); \
1084 pThis->IHostAudio.pfnStreamCapture = RT_CONCAT(a_Prefix,StreamCapture); \
1085 } while (0)
1086
1087/**
1088 * PDM host audio interface.
1089 */
1090typedef struct PDMIHOSTAUDIO
1091{
1092 /**
1093 * Initializes the host backend (driver).
1094 *
1095 * @returns VBox status code.
1096 * @param pInterface Pointer to the interface structure containing the called function pointer.
1097 */
1098 DECLR3CALLBACKMEMBER(int, pfnInit, (PPDMIHOSTAUDIO pInterface));
1099
1100 /**
1101 * Shuts down the host backend (driver).
1102 *
1103 * @returns VBox status code.
1104 * @param pInterface Pointer to the interface structure containing the called function pointer.
1105 */
1106 DECLR3CALLBACKMEMBER(void, pfnShutdown, (PPDMIHOSTAUDIO pInterface));
1107
1108 /**
1109 * Returns the host backend's configuration (backend).
1110 *
1111 * @returns VBox status code.
1112 * @param pInterface Pointer to the interface structure containing the called function pointer.
1113 * @param pBackendCfg Where to store the backend audio configuration to.
1114 */
1115 DECLR3CALLBACKMEMBER(int, pfnGetConfig, (PPDMIHOSTAUDIO pInterface, PPDMAUDIOBACKENDCFG pBackendCfg));
1116
1117 /**
1118 * Returns (enumerates) host audio device information.
1119 *
1120 * @returns VBox status code.
1121 * @param pInterface Pointer to the interface structure containing the called function pointer.
1122 * @param pDeviceEnum Where to return the enumerated audio devices.
1123 */
1124 DECLR3CALLBACKMEMBER(int, pfnGetDevices, (PPDMIHOSTAUDIO pInterface, PPDMAUDIODEVICEENUM pDeviceEnum));
1125
1126 /**
1127 * Returns the current status from the audio backend.
1128 *
1129 * @returns PDMAUDIOBACKENDSTS enum.
1130 * @param pInterface Pointer to the interface structure containing the called function pointer.
1131 * @param enmDir Audio direction to get status for. Pass PDMAUDIODIR_ANY for overall status.
1132 */
1133 DECLR3CALLBACKMEMBER(PDMAUDIOBACKENDSTS, pfnGetStatus, (PPDMIHOSTAUDIO pInterface, PDMAUDIODIR enmDir));
1134
1135 /**
1136 * Sets a callback the audio backend can call. Optional.
1137 *
1138 * @returns VBox status code.
1139 * @param pInterface Pointer to the interface structure containing the called function pointer.
1140 * @param pfnCallback The callback function to use, or NULL when unregistering.
1141 */
1142 DECLR3CALLBACKMEMBER(int, pfnSetCallback, (PPDMIHOSTAUDIO pInterface, PFNPDMHOSTAUDIOCALLBACK pfnCallback));
1143
1144 /**
1145 * Creates an audio stream using the requested stream configuration.
1146 * If a backend is not able to create this configuration, it will return its best match in the acquired configuration
1147 * structure on success.
1148 *
1149 * @returns VBox status code.
1150 * @param pInterface Pointer to the interface structure containing the called function pointer.
1151 * @param pStream Pointer to audio stream.
1152 * @param pCfgReq Pointer to requested stream configuration.
1153 * @param pCfgAcq Pointer to acquired stream configuration.
1154 */
1155 DECLR3CALLBACKMEMBER(int, pfnStreamCreate, (PPDMIHOSTAUDIO pInterface, PPDMAUDIOBACKENDSTREAM pStream, PPDMAUDIOSTREAMCFG pCfgReq, PPDMAUDIOSTREAMCFG pCfgAcq));
1156
1157 /**
1158 * Destroys an audio stream.
1159 *
1160 * @returns VBox status code.
1161 * @param pInterface Pointer to the interface structure containing the called function pointer.
1162 * @param pStream Pointer to audio stream.
1163 */
1164 DECLR3CALLBACKMEMBER(int, pfnStreamDestroy, (PPDMIHOSTAUDIO pInterface, PPDMAUDIOBACKENDSTREAM pStream));
1165
1166 /**
1167 * Controls an audio stream.
1168 *
1169 * @returns VBox status code.
1170 * @param pInterface Pointer to the interface structure containing the called function pointer.
1171 * @param pStream Pointer to audio stream.
1172 * @param enmStreamCmd The stream command to issue.
1173 */
1174 DECLR3CALLBACKMEMBER(int, pfnStreamControl, (PPDMIHOSTAUDIO pInterface, PPDMAUDIOBACKENDSTREAM pStream, PDMAUDIOSTREAMCMD enmStreamCmd));
1175
1176 /**
1177 * Returns the number of bytes which are readable from the audio (input) stream.
1178 *
1179 * @returns Number of readable bytes.
1180 * @param pInterface Pointer to the interface structure containing the called function pointer.
1181 * @param pStream Pointer to audio stream.
1182 */
1183 DECLR3CALLBACKMEMBER(uint32_t, pfnStreamGetReadable, (PPDMIHOSTAUDIO pInterface, PPDMAUDIOBACKENDSTREAM pStream));
1184
1185 /**
1186 * Returns the number of bytes which are writable to the audio (output) stream.
1187 *
1188 * @returns Number of writable bytes.
1189 * @param pInterface Pointer to the interface structure containing the called function pointer.
1190 * @param pStream Pointer to audio stream.
1191 */
1192 DECLR3CALLBACKMEMBER(uint32_t, pfnStreamGetWritable, (PPDMIHOSTAUDIO pInterface, PPDMAUDIOBACKENDSTREAM pStream));
1193
1194 /**
1195 * Returns whether the specified audio direction in the backend is enabled or not.
1196 *
1197 * @returns PDMAUDIOSTRMSTS
1198 * @param pInterface Pointer to the interface structure containing the called function pointer.
1199 * @param pStream Pointer to audio stream.
1200 */
1201 DECLR3CALLBACKMEMBER(PDMAUDIOSTRMSTS, pfnStreamGetStatus, (PPDMIHOSTAUDIO pInterface, PPDMAUDIOBACKENDSTREAM pStream));
1202
1203 /**
1204 * Gives the host backend the chance to do some (necessary) iteration work.
1205 *
1206 * @returns VBox status code.
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, (PPDMIHOSTAUDIO pInterface, PPDMAUDIOBACKENDSTREAM pStream));
1211
1212 /**
1213 * Plays (writes to) an audio (output) stream.
1214 *
1215 * @returns VBox status code.
1216 * @param pInterface Pointer to the interface structure containing the called function pointer.
1217 * @param pStream Pointer to audio stream.
1218 * @param pvBuf Pointer to audio data buffer to play.
1219 * @param cbBuf Size (in bytes) of audio data buffer.
1220 * @param pcbWritten Returns number of bytes written. Optional.
1221 */
1222 DECLR3CALLBACKMEMBER(int, pfnStreamPlay, (PPDMIHOSTAUDIO pInterface, PPDMAUDIOBACKENDSTREAM pStream, const void *pvBuf, uint32_t cbBuf, uint32_t *pcbWritten));
1223
1224 /**
1225 * Captures (reads from) an audio (input) stream.
1226 *
1227 * @returns VBox status code.
1228 * @param pInterface Pointer to the interface structure containing the called function pointer.
1229 * @param pStream Pointer to audio stream.
1230 * @param pvBuf Buffer where to store read audio data.
1231 * @param cbBuf Size (in bytes) of buffer.
1232 * @param pcbRead Returns number of bytes read. Optional.
1233 */
1234 DECLR3CALLBACKMEMBER(int, pfnStreamCapture, (PPDMIHOSTAUDIO pInterface, PPDMAUDIOBACKENDSTREAM pStream, void *pvBuf, uint32_t cbBuf, uint32_t *pcbRead));
1235
1236} PDMIHOSTAUDIO;
1237
1238/** PDMIHOSTAUDIO interface ID. */
1239#define PDMIHOSTAUDIO_IID "12DF859E-416A-4332-9980-A049AC70D187"
1240
1241/** @} */
1242
1243#endif /* !___VBox_vmm_pdmaudioifs_h */
1244
Note: See TracBrowser for help on using the repository browser.

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