VirtualBox

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

Last change on this file since 67989 was 67695, checked in by vboxsync, 7 years ago

Audio: vmm/pdmaudioifs.h: Shuffle parameters around in PDMAUDIOPCMPROPS.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 46.0 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 /** Number of audio channels. */
351 uint8_t cChannels;
352 /** Sample frequency in Hertz (Hz). */
353 uint32_t uHz;
354 /** Shift count used for faster calculation of various
355 * values, such as the alignment, bytes to samples and so on.
356 * Depends on number of stream channels and the stream format
357 * being used.
358 *
359 ** @todo Use some RTAsmXXX functions instead?
360 */
361 uint8_t cShift;
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 /** Number of children mix buffers kept in lstChildren. */
615 uint32_t cChildren;
616 /** Intermediate structure for buffer conversion tasks. */
617 PPDMAUDIOSTRMRATE pRate;
618 /** Internal representation of current volume used for mixing. */
619 PDMAUDMIXBUFVOL Volume;
620 /** This buffer's audio format. */
621 PDMAUDIOMIXBUFFMT AudioFmt;
622 /** Standard conversion-to function for set AudioFmt. */
623 PFNPDMAUDIOMIXBUFCONVTO pfnConvTo;
624 /** Standard conversion-from function for set AudioFmt. */
625 PFNPDMAUDIOMIXBUFCONVFROM pfnConvFrom;
626 /**
627 * Ratio of the associated parent stream's frequency by this stream's
628 * frequency (1<<32), represented as a signed 64 bit integer.
629 *
630 * For example, if the parent stream has a frequency of 44 khZ, and this
631 * stream has a frequency of 11 kHz, the ration then would be
632 * (44/11 * (1 << 32)).
633 *
634 * Currently this does not get changed once assigned.
635 */
636 int64_t iFreqRatio;
637 /** For quickly converting samples <-> bytes and vice versa. */
638 uint8_t cShift;
639} PDMAUDIOMIXBUF;
640
641typedef uint32_t PDMAUDIOFILEFLAGS;
642
643/* No flags defined. */
644#define PDMAUDIOFILEFLAG_NONE 0
645
646/**
647 * Audio file types.
648 */
649typedef enum PDMAUDIOFILETYPE
650{
651 /** Unknown type, do not use. */
652 PDMAUDIOFILETYPE_UNKNOWN = 0,
653 /** Wave (.WAV) file. */
654 PDMAUDIOFILETYPE_WAV,
655 /** Hack to blow the type up to 32-bit. */
656 PDMAUDIOFILETYPE_32BIT_HACK = 0x7fffffff
657} PDMAUDIOFILETYPE;
658
659/**
660 * Structure for an audio file handle.
661 */
662typedef struct PDMAUDIOFILE
663{
664 /** Type of the audio file. */
665 PDMAUDIOFILETYPE enmType;
666 /** File name. */
667 char szName[255];
668 /** Actual file handle. */
669 RTFILE hFile;
670 /** Data needed for the specific audio file type implemented.
671 * Optional, can be NULL. */
672 void *pvData;
673 /** Data size (in bytes). */
674 size_t cbData;
675} PDMAUDIOFILE, *PPDMAUDIOFILE;
676
677/** Stream status flag. To be used with PDMAUDIOSTRMSTS_FLAG_ flags. */
678typedef uint32_t PDMAUDIOSTRMSTS;
679
680/** No flags being set. */
681#define PDMAUDIOSTRMSTS_FLAG_NONE 0
682/** Whether this stream has been initialized by the
683 * backend or not. */
684#define PDMAUDIOSTRMSTS_FLAG_INITIALIZED RT_BIT_32(0)
685/** Whether this stream is enabled or disabled. */
686#define PDMAUDIOSTRMSTS_FLAG_ENABLED RT_BIT_32(1)
687/** Whether this stream has been paused or not. This also implies
688 * that this is an enabled stream! */
689#define PDMAUDIOSTRMSTS_FLAG_PAUSED RT_BIT_32(2)
690/** Whether this stream was marked as being disabled
691 * but there are still associated guest output streams
692 * which rely on its data. */
693#define PDMAUDIOSTRMSTS_FLAG_PENDING_DISABLE RT_BIT_32(3)
694/** Whether this stream is in re-initialization phase.
695 * All other bits remain untouched to be able to restore
696 * the stream's state after the re-initialization bas been
697 * finished. */
698#define PDMAUDIOSTRMSTS_FLAG_PENDING_REINIT RT_BIT_32(4)
699/** Validation mask. */
700#define PDMAUDIOSTRMSTS_VALID_MASK UINT32_C(0x0000001F)
701
702/**
703 * Enumeration presenting a backend's current status.
704 */
705typedef enum PDMAUDIOBACKENDSTS
706{
707 /** Unknown/invalid status. */
708 PDMAUDIOBACKENDSTS_UNKNOWN = 0,
709 /** The backend is in its initialization phase.
710 * Not all backends support this status. */
711 PDMAUDIOBACKENDSTS_INITIALIZING,
712 /** The backend has stopped its operation. */
713 PDMAUDIOBACKENDSTS_STOPPED,
714 /** The backend is up and running. */
715 PDMAUDIOBACKENDSTS_RUNNING,
716 /** The backend ran into an error and is unable to recover.
717 * A manual re-initialization might help. */
718 PDMAUDIOBACKENDSTS_ERROR,
719 /** Hack to blow the type up to 32-bit. */
720 PDMAUDIOBACKENDSTS_32BIT_HACK = 0x7fffffff
721} PDMAUDIOBACKENDSTS;
722
723/**
724 * Audio stream context.
725 */
726typedef enum PDMAUDIOSTREAMCTX
727{
728 /** No context set / invalid. */
729 PDMAUDIOSTREAMCTX_UNKNOWN = 0,
730 /** Host stream, connected to a backend. */
731 PDMAUDIOSTREAMCTX_HOST,
732 /** Guest stream, connected to the device emulation. */
733 PDMAUDIOSTREAMCTX_GUEST,
734 /** Hack to blow the type up to 32-bit. */
735 PDMAUDIOSTREAMCTX_32BIT_HACK = 0x7fffffff
736} PDMAUDIOSTREAMCTX;
737
738/**
739 * Structure for keeping audio input stream specifics.
740 * Do not use directly. Instead, use PDMAUDIOSTREAM.
741 */
742typedef struct PDMAUDIOSTREAMIN
743{
744 /** Timestamp (in ms) since last read. */
745 uint64_t tsLastReadMS;
746#ifdef VBOX_WITH_STATISTICS
747 STAMCOUNTER StatBytesElapsed;
748 STAMCOUNTER StatBytesTotalRead;
749 STAMCOUNTER StatSamplesCaptured;
750#endif
751} PDMAUDIOSTREAMIN, *PPDMAUDIOSTREAMIN;
752
753/**
754 * Structure for keeping audio output stream specifics.
755 * Do not use directly. Instead, use PDMAUDIOSTREAM.
756 */
757typedef struct PDMAUDIOSTREAMOUT
758{
759 /** Timestamp (in ms) since last write. */
760 uint64_t tsLastWriteMS;
761#ifdef VBOX_WITH_STATISTICS
762 STAMCOUNTER StatBytesElapsed;
763 STAMCOUNTER StatBytesTotalWritten;
764 STAMCOUNTER StatSamplesPlayed;
765#endif
766} PDMAUDIOSTREAMOUT, *PPDMAUDIOSTREAMOUT;
767
768struct PDMAUDIOSTREAM;
769typedef PDMAUDIOSTREAM *PPDMAUDIOSTREAM;
770
771/**
772 * Structure for maintaining an nput/output audio stream.
773 */
774typedef struct PDMAUDIOSTREAM
775{
776 /** List node. */
777 RTLISTNODE Node;
778 /** Pointer to the other pair of this stream.
779 * This might be the host or guest side. */
780 PPDMAUDIOSTREAM pPair;
781 /** Name of this stream. */
782 char szName[64];
783 /** Number of references to this stream. Only can be
784 * destroyed if the reference count is reaching 0. */
785 uint32_t cRefs;
786 /** The stream's audio configuration. */
787 PDMAUDIOSTREAMCFG Cfg;
788 /** Stream status flag. */
789 PDMAUDIOSTRMSTS fStatus;
790 /** This stream's mixing buffer. */
791 PDMAUDIOMIXBUF MixBuf;
792 /** Audio direction of this stream. */
793 PDMAUDIODIR enmDir;
794 /** Context of this stream. */
795 PDMAUDIOSTREAMCTX enmCtx;
796 /** Timestamp (in ms) since last iteration. */
797 uint64_t tsLastIterateMS;
798 /** Union for input/output specifics. */
799 union
800 {
801 PDMAUDIOSTREAMIN In;
802 PDMAUDIOSTREAMOUT Out;
803 };
804 /** Data to backend-specific stream data.
805 * This data block will be casted by the backend to access its backend-dependent data.
806 *
807 * That way the backends do not have access to the audio connector's data. */
808 void *pvBackend;
809 /** Size (in bytes) of the backend-specific stream data. */
810 size_t cbBackend;
811} PDMAUDIOSTREAM, *PPDMAUDIOSTREAM;
812
813/** Pointer to a audio connector interface. */
814typedef struct PDMIAUDIOCONNECTOR *PPDMIAUDIOCONNECTOR;
815
816/**
817 * Audio callback types.
818 * Those callbacks are being sent from the backends to the audio connector.
819 */
820typedef enum PDMAUDIOCBTYPE
821{
822 /** Invalid, do not use. */
823 PDMAUDIOCBTYPE_INVALID = 0,
824 /** The backend's status has changed. */
825 PDMAUDIOCBTYPE_STATUS,
826 /** One or more host audio devices have changed. */
827 PDMAUDIOCBTYPE_DEVICES_CHANGED,
828 /** Data is availabe as input for passing to the device emulation. */
829 PDMAUDIOCBTYPE_DATA_INPUT,
830 /** Free data for the device emulation to write to the backend. */
831 PDMAUDIOCBTYPE_DATA_OUTPUT
832} PDMAUDIOCBTYPE;
833
834/**
835 * Callback data for audio input.
836 */
837typedef struct PDMAUDIOCBDATA_DATA_INPUT
838{
839 /** Input: How many bytes are availabe as input for passing
840 * to the device emulation. */
841 uint32_t cbInAvail;
842 /** Output: How many bytes have been read. */
843 uint32_t cbOutRead;
844} PDMAUDIOCBDATA_DATA_INPUT, *PPDMAUDIOCBDATA_DATA_INPUT;
845
846/**
847 * Callback data for audio output.
848 */
849typedef struct PDMAUDIOCBDATA_DATA_OUTPUT
850{
851 /** Input: How many bytes are free for the device emulation to write. */
852 uint32_t cbInFree;
853 /** Output: How many bytes were written by the device emulation. */
854 uint32_t cbOutWritten;
855} PDMAUDIOCBDATA_DATA_OUTPUT, *PPDMAUDIOCBDATA_DATA_OUTPUT;
856
857/** Pointer to a host audio interface. */
858typedef struct PDMIHOSTAUDIO *PPDMIHOSTAUDIO;
859
860/**
861 * Host audio (backend) callback function.
862 *
863 * @returns IPRT status code.
864 * @param pDrvIns Pointer to driver instance which called us.
865 * @param enmType Callback type.
866 * @param pvUser User argument.
867 * @param cbUser Size (in bytes) of user argument.
868 */
869typedef DECLCALLBACK(int) FNPDMHOSTAUDIOCALLBACK(PPDMDRVINS pDrvIns, PDMAUDIOCBTYPE enmType, void *pvUser, size_t cbUser);
870/** Pointer to a FNPDMHOSTAUDIOCALLBACK(). */
871typedef FNPDMHOSTAUDIOCALLBACK *PFNPDMHOSTAUDIOCALLBACK;
872
873#ifdef VBOX_WITH_AUDIO_DEVICE_CALLBACKS
874/**
875 * Structure for keeping a registered audio callback around.
876 */
877typedef struct PDMAUDIOCALLBACK
878{
879 /** List node. */
880 RTLISTANCHOR Node;
881 /** Callback type. */
882 PDMAUDIOCBTYPE enmType;
883 /** Pointer to context data. Optional. */
884 void *pvCtx;
885 /** Size (in bytes) of context data.
886 * Must be 0 if pvCtx is NULL. */
887 size_t cbCtx;
888 /** Actual callback function to call. */
889 PFNPDMAUDIOCALLBACK pFn;
890} PDMAUDIOCALLBACK, *PPDMAUDIOCALLBACK;
891#endif /* VBOX_WITH_AUDIO_DEVICE_CALLBACKS */
892
893#define PPDMAUDIOBACKENDSTREAM void *
894
895/**
896 * Audio connector interface (up).
897 */
898typedef struct PDMIAUDIOCONNECTOR
899{
900 /**
901 * Retrieves the current configuration of the host audio backend.
902 *
903 * @returns VBox status code.
904 * @param pInterface Pointer to the interface structure containing the called function pointer.
905 * @param pCfg Where to store the host audio backend configuration data.
906 */
907 DECLR3CALLBACKMEMBER(int, pfnGetConfig, (PPDMIAUDIOCONNECTOR pInterface, PPDMAUDIOBACKENDCFG pCfg));
908
909 /**
910 * Retrieves the current status of the host audio backend.
911 *
912 * @returns Status of the host audio backend.
913 * @param pInterface Pointer to the interface structure containing the called function pointer.
914 * @param enmDir Audio direction to check host audio backend for. Specify PDMAUDIODIR_ANY for the overall
915 * backend status.
916 */
917 DECLR3CALLBACKMEMBER(PDMAUDIOBACKENDSTS, pfnGetStatus, (PPDMIAUDIOCONNECTOR pInterface, PDMAUDIODIR enmDir));
918
919 /**
920 * Creates an audio stream.
921 *
922 * @returns VBox status code.
923 * @param pInterface Pointer to the interface structure containing the called function pointer.
924 * @param pCfgHost Stream configuration for host side.
925 * @param pCfgGuest Stream configuration for guest side.
926 * @param ppStream Pointer where to return the created audio stream on success.
927 */
928 DECLR3CALLBACKMEMBER(int, pfnStreamCreate, (PPDMIAUDIOCONNECTOR pInterface, PPDMAUDIOSTREAMCFG pCfgHost, PPDMAUDIOSTREAMCFG pCfgGuest, PPDMAUDIOSTREAM *ppStream));
929
930 /**
931 * Destroys an audio stream.
932 *
933 * @param pInterface Pointer to the interface structure containing the called function pointer.
934 * @param pStream Pointer to audio stream.
935 */
936 DECLR3CALLBACKMEMBER(int, pfnStreamDestroy, (PPDMIAUDIOCONNECTOR pInterface, PPDMAUDIOSTREAM pStream));
937
938 /**
939 * Adds a reference to the specified audio stream.
940 *
941 * @returns New reference count. UINT32_MAX on error.
942 * @param pInterface Pointer to the interface structure containing the called function pointer.
943 * @param pStream Pointer to audio stream adding the reference to.
944 */
945 DECLR3CALLBACKMEMBER(uint32_t, pfnStreamRetain, (PPDMIAUDIOCONNECTOR pInterface, PPDMAUDIOSTREAM pStream));
946
947 /**
948 * Releases a reference from the specified stream.
949 *
950 * @returns New reference count. UINT32_MAX on error.
951 * @param pInterface Pointer to the interface structure containing the called function pointer.
952 * @param pStream Pointer to audio stream releasing a reference from.
953 */
954 DECLR3CALLBACKMEMBER(uint32_t, pfnStreamRelease, (PPDMIAUDIOCONNECTOR pInterface, PPDMAUDIOSTREAM pStream));
955
956 /**
957 * Reads PCM audio data from the host (input).
958 *
959 * @returns VBox status code.
960 * @param pInterface Pointer to the interface structure containing the called function pointer.
961 * @param pStream Pointer to audio stream to write to.
962 * @param pvBuf Where to store the read data.
963 * @param cbBuf Number of bytes to read.
964 * @param pcbRead Bytes of audio data read. Optional.
965 */
966 DECLR3CALLBACKMEMBER(int, pfnStreamRead, (PPDMIAUDIOCONNECTOR pInterface, PPDMAUDIOSTREAM pStream, void *pvBuf, uint32_t cbBuf, uint32_t *pcbRead));
967
968 /**
969 * Writes PCM audio data to the host (output).
970 *
971 * @returns VBox status code.
972 * @param pInterface Pointer to the interface structure containing the called function pointer.
973 * @param pStream Pointer to audio stream to read from.
974 * @param pvBuf Audio data to be written.
975 * @param cbBuf Number of bytes to be written.
976 * @param pcbWritten Bytes of audio data written. Optional.
977 */
978 DECLR3CALLBACKMEMBER(int, pfnStreamWrite, (PPDMIAUDIOCONNECTOR pInterface, PPDMAUDIOSTREAM pStream, const void *pvBuf, uint32_t cbBuf, uint32_t *pcbWritten));
979
980 /**
981 * Controls a specific audio stream.
982 *
983 * @returns VBox status code.
984 * @param pInterface Pointer to the interface structure containing the called function pointer.
985 * @param pStream Pointer to audio stream.
986 * @param enmStreamCmd The stream command to issue.
987 */
988 DECLR3CALLBACKMEMBER(int, pfnStreamControl, (PPDMIAUDIOCONNECTOR pInterface, PPDMAUDIOSTREAM pStream, PDMAUDIOSTREAMCMD enmStreamCmd));
989
990 /**
991 * Processes stream data.
992 *
993 * @param pInterface Pointer to the interface structure containing the called function pointer.
994 * @param pStream Pointer to audio stream.
995 */
996 DECLR3CALLBACKMEMBER(int, pfnStreamIterate, (PPDMIAUDIOCONNECTOR pInterface, PPDMAUDIOSTREAM pStream));
997
998 /**
999 * Returns the number of readable data (in bytes) of a specific audio input stream.
1000 *
1001 * @returns Number of readable data (in bytes).
1002 * @param pInterface Pointer to the interface structure containing the called function pointer.
1003 * @param pStream Pointer to audio stream.
1004 */
1005 DECLR3CALLBACKMEMBER(uint32_t, pfnStreamGetReadable, (PPDMIAUDIOCONNECTOR pInterface, PPDMAUDIOSTREAM pStream));
1006
1007 /**
1008 * Returns the number of writable data (in bytes) of a specific audio output stream.
1009 *
1010 * @returns Number of writable data (in bytes).
1011 * @param pInterface Pointer to the interface structure containing the called function pointer.
1012 * @param pStream Pointer to audio stream.
1013 */
1014 DECLR3CALLBACKMEMBER(uint32_t, pfnStreamGetWritable, (PPDMIAUDIOCONNECTOR pInterface, PPDMAUDIOSTREAM pStream));
1015
1016 /**
1017 * Returns the status of a specific audio stream.
1018 *
1019 * @returns Audio stream status
1020 * @param pInterface Pointer to the interface structure containing the called function pointer.
1021 * @param pStream Pointer to audio stream.
1022 */
1023 DECLR3CALLBACKMEMBER(PDMAUDIOSTRMSTS, pfnStreamGetStatus, (PPDMIAUDIOCONNECTOR pInterface, PPDMAUDIOSTREAM pStream));
1024
1025 /**
1026 * Sets the audio volume of a specific audio stream.
1027 *
1028 * @returns VBox status code.
1029 * @param pInterface Pointer to the interface structure containing the called function pointer.
1030 * @param pStream Pointer to audio stream.
1031 * @param pVol Pointer to audio volume structure to set the stream's audio volume to.
1032 */
1033 DECLR3CALLBACKMEMBER(int, pfnStreamSetVolume, (PPDMIAUDIOCONNECTOR pInterface, PPDMAUDIOSTREAM pStream, PPDMAUDIOVOLUME pVol));
1034
1035 /**
1036 * Plays (transfers) available audio samples via the host backend. Only works with output streams.
1037 *
1038 * @returns VBox status code.
1039 * @param pInterface Pointer to the interface structure containing the called function pointer.
1040 * @param pStream Pointer to audio stream.
1041 * @param pcSamplesPlayed Number of samples played. Optional.
1042 */
1043 DECLR3CALLBACKMEMBER(int, pfnStreamPlay, (PPDMIAUDIOCONNECTOR pInterface, PPDMAUDIOSTREAM pStream, uint32_t *pcSamplesPlayed));
1044
1045 /**
1046 * Captures (transfers) available audio samples from the host backend. Only works with input streams.
1047 *
1048 * @returns VBox status code.
1049 * @param pInterface Pointer to the interface structure containing the called function pointer.
1050 * @param pStream Pointer to audio stream.
1051 * @param pcSamplesCaptured Number of samples captured. Optional.
1052 */
1053 DECLR3CALLBACKMEMBER(int, pfnStreamCapture, (PPDMIAUDIOCONNECTOR pInterface, PPDMAUDIOSTREAM pStream, uint32_t *pcSamplesCaptured));
1054
1055#ifdef VBOX_WITH_AUDIO_DEVICE_CALLBACKS
1056 DECLR3CALLBACKMEMBER(int, pfnRegisterCallbacks, (PPDMIAUDIOCONNECTOR pInterface, PPDMAUDIOCALLBACK paCallbacks, size_t cCallbacks));
1057 DECLR3CALLBACKMEMBER(int, pfnCallback, (PPDMIAUDIOCONNECTOR pInterface, PDMAUDIOCBTYPE enmType, void *pvUser, size_t cbUser));
1058#endif
1059
1060} PDMIAUDIOCONNECTOR;
1061
1062/** PDMIAUDIOCONNECTOR interface ID. */
1063#define PDMIAUDIOCONNECTOR_IID "FF2044D1-F8D9-4F42-BE9E-0E9AD14F4552"
1064
1065/**
1066 * Assigns all needed interface callbacks for an audio backend.
1067 *
1068 * @param a_Prefix The function name prefix.
1069 */
1070#define PDMAUDIO_IHOSTAUDIO_CALLBACKS(a_Prefix) \
1071 do { \
1072 pThis->IHostAudio.pfnInit = RT_CONCAT(a_Prefix,Init); \
1073 pThis->IHostAudio.pfnShutdown = RT_CONCAT(a_Prefix,Shutdown); \
1074 pThis->IHostAudio.pfnGetConfig = RT_CONCAT(a_Prefix,GetConfig); \
1075 /** @todo Add pfnGetDevices here as soon as supported by all backends. */ \
1076 pThis->IHostAudio.pfnGetStatus = RT_CONCAT(a_Prefix,GetStatus); \
1077 /** @todo Ditto for pfnSetCallback. */ \
1078 pThis->IHostAudio.pfnStreamCreate = RT_CONCAT(a_Prefix,StreamCreate); \
1079 pThis->IHostAudio.pfnStreamDestroy = RT_CONCAT(a_Prefix,StreamDestroy); \
1080 pThis->IHostAudio.pfnStreamControl = RT_CONCAT(a_Prefix,StreamControl); \
1081 pThis->IHostAudio.pfnStreamGetReadable = RT_CONCAT(a_Prefix,StreamGetReadable); \
1082 pThis->IHostAudio.pfnStreamGetWritable = RT_CONCAT(a_Prefix,StreamGetWritable); \
1083 pThis->IHostAudio.pfnStreamGetStatus = RT_CONCAT(a_Prefix,StreamGetStatus); \
1084 pThis->IHostAudio.pfnStreamIterate = RT_CONCAT(a_Prefix,StreamIterate); \
1085 pThis->IHostAudio.pfnStreamPlay = RT_CONCAT(a_Prefix,StreamPlay); \
1086 pThis->IHostAudio.pfnStreamCapture = RT_CONCAT(a_Prefix,StreamCapture); \
1087 } while (0)
1088
1089/**
1090 * PDM host audio interface.
1091 */
1092typedef struct PDMIHOSTAUDIO
1093{
1094 /**
1095 * Initializes the host backend (driver).
1096 *
1097 * @returns VBox status code.
1098 * @param pInterface Pointer to the interface structure containing the called function pointer.
1099 */
1100 DECLR3CALLBACKMEMBER(int, pfnInit, (PPDMIHOSTAUDIO pInterface));
1101
1102 /**
1103 * Shuts down the host backend (driver).
1104 *
1105 * @returns VBox status code.
1106 * @param pInterface Pointer to the interface structure containing the called function pointer.
1107 */
1108 DECLR3CALLBACKMEMBER(void, pfnShutdown, (PPDMIHOSTAUDIO pInterface));
1109
1110 /**
1111 * Returns the host backend's configuration (backend).
1112 *
1113 * @returns VBox status code.
1114 * @param pInterface Pointer to the interface structure containing the called function pointer.
1115 * @param pBackendCfg Where to store the backend audio configuration to.
1116 */
1117 DECLR3CALLBACKMEMBER(int, pfnGetConfig, (PPDMIHOSTAUDIO pInterface, PPDMAUDIOBACKENDCFG pBackendCfg));
1118
1119 /**
1120 * Returns (enumerates) host audio device information.
1121 *
1122 * @returns VBox status code.
1123 * @param pInterface Pointer to the interface structure containing the called function pointer.
1124 * @param pDeviceEnum Where to return the enumerated audio devices.
1125 */
1126 DECLR3CALLBACKMEMBER(int, pfnGetDevices, (PPDMIHOSTAUDIO pInterface, PPDMAUDIODEVICEENUM pDeviceEnum));
1127
1128 /**
1129 * Returns the current status from the audio backend.
1130 *
1131 * @returns PDMAUDIOBACKENDSTS enum.
1132 * @param pInterface Pointer to the interface structure containing the called function pointer.
1133 * @param enmDir Audio direction to get status for. Pass PDMAUDIODIR_ANY for overall status.
1134 */
1135 DECLR3CALLBACKMEMBER(PDMAUDIOBACKENDSTS, pfnGetStatus, (PPDMIHOSTAUDIO pInterface, PDMAUDIODIR enmDir));
1136
1137 /**
1138 * Sets a callback the audio backend can call. Optional.
1139 *
1140 * @returns VBox status code.
1141 * @param pInterface Pointer to the interface structure containing the called function pointer.
1142 * @param pfnCallback The callback function to use, or NULL when unregistering.
1143 */
1144 DECLR3CALLBACKMEMBER(int, pfnSetCallback, (PPDMIHOSTAUDIO pInterface, PFNPDMHOSTAUDIOCALLBACK pfnCallback));
1145
1146 /**
1147 * Creates an audio stream using the requested stream configuration.
1148 * If a backend is not able to create this configuration, it will return its best match in the acquired configuration
1149 * structure on success.
1150 *
1151 * @returns VBox status code.
1152 * @param pInterface Pointer to the interface structure containing the called function pointer.
1153 * @param pStream Pointer to audio stream.
1154 * @param pCfgReq Pointer to requested stream configuration.
1155 * @param pCfgAcq Pointer to acquired stream configuration.
1156 */
1157 DECLR3CALLBACKMEMBER(int, pfnStreamCreate, (PPDMIHOSTAUDIO pInterface, PPDMAUDIOBACKENDSTREAM pStream, PPDMAUDIOSTREAMCFG pCfgReq, PPDMAUDIOSTREAMCFG pCfgAcq));
1158
1159 /**
1160 * Destroys an audio stream.
1161 *
1162 * @returns VBox status code.
1163 * @param pInterface Pointer to the interface structure containing the called function pointer.
1164 * @param pStream Pointer to audio stream.
1165 */
1166 DECLR3CALLBACKMEMBER(int, pfnStreamDestroy, (PPDMIHOSTAUDIO pInterface, PPDMAUDIOBACKENDSTREAM pStream));
1167
1168 /**
1169 * Controls an audio stream.
1170 *
1171 * @returns VBox status code.
1172 * @param pInterface Pointer to the interface structure containing the called function pointer.
1173 * @param pStream Pointer to audio stream.
1174 * @param enmStreamCmd The stream command to issue.
1175 */
1176 DECLR3CALLBACKMEMBER(int, pfnStreamControl, (PPDMIHOSTAUDIO pInterface, PPDMAUDIOBACKENDSTREAM pStream, PDMAUDIOSTREAMCMD enmStreamCmd));
1177
1178 /**
1179 * Returns the number of bytes which are readable from the audio (input) stream.
1180 *
1181 * @returns Number of readable bytes.
1182 * @param pInterface Pointer to the interface structure containing the called function pointer.
1183 * @param pStream Pointer to audio stream.
1184 */
1185 DECLR3CALLBACKMEMBER(uint32_t, pfnStreamGetReadable, (PPDMIHOSTAUDIO pInterface, PPDMAUDIOBACKENDSTREAM pStream));
1186
1187 /**
1188 * Returns the number of bytes which are writable to the audio (output) stream.
1189 *
1190 * @returns Number of writable bytes.
1191 * @param pInterface Pointer to the interface structure containing the called function pointer.
1192 * @param pStream Pointer to audio stream.
1193 */
1194 DECLR3CALLBACKMEMBER(uint32_t, pfnStreamGetWritable, (PPDMIHOSTAUDIO pInterface, PPDMAUDIOBACKENDSTREAM pStream));
1195
1196 /**
1197 * Returns whether the specified audio direction in the backend is enabled or not.
1198 *
1199 * @returns PDMAUDIOSTRMSTS
1200 * @param pInterface Pointer to the interface structure containing the called function pointer.
1201 * @param pStream Pointer to audio stream.
1202 */
1203 DECLR3CALLBACKMEMBER(PDMAUDIOSTRMSTS, pfnStreamGetStatus, (PPDMIHOSTAUDIO pInterface, PPDMAUDIOBACKENDSTREAM pStream));
1204
1205 /**
1206 * Gives the host backend the chance to do some (necessary) iteration work.
1207 *
1208 * @returns VBox status code.
1209 * @param pInterface Pointer to the interface structure containing the called function pointer.
1210 * @param pStream Pointer to audio stream.
1211 */
1212 DECLR3CALLBACKMEMBER(int, pfnStreamIterate, (PPDMIHOSTAUDIO pInterface, PPDMAUDIOBACKENDSTREAM pStream));
1213
1214 /**
1215 * Plays (writes to) an audio (output) stream.
1216 *
1217 * @returns VBox status code.
1218 * @param pInterface Pointer to the interface structure containing the called function pointer.
1219 * @param pStream Pointer to audio stream.
1220 * @param pvBuf Pointer to audio data buffer to play.
1221 * @param cbBuf Size (in bytes) of audio data buffer.
1222 * @param pcbWritten Returns number of bytes written. Optional.
1223 */
1224 DECLR3CALLBACKMEMBER(int, pfnStreamPlay, (PPDMIHOSTAUDIO pInterface, PPDMAUDIOBACKENDSTREAM pStream, const void *pvBuf, uint32_t cbBuf, uint32_t *pcbWritten));
1225
1226 /**
1227 * Captures (reads from) an audio (input) stream.
1228 *
1229 * @returns VBox status code.
1230 * @param pInterface Pointer to the interface structure containing the called function pointer.
1231 * @param pStream Pointer to audio stream.
1232 * @param pvBuf Buffer where to store read audio data.
1233 * @param cbBuf Size (in bytes) of buffer.
1234 * @param pcbRead Returns number of bytes read. Optional.
1235 */
1236 DECLR3CALLBACKMEMBER(int, pfnStreamCapture, (PPDMIHOSTAUDIO pInterface, PPDMAUDIOBACKENDSTREAM pStream, void *pvBuf, uint32_t cbBuf, uint32_t *pcbRead));
1237
1238} PDMIHOSTAUDIO;
1239
1240/** PDMIHOSTAUDIO interface ID. */
1241#define PDMIHOSTAUDIO_IID "12DF859E-416A-4332-9980-A049AC70D187"
1242
1243/** @} */
1244
1245#endif /* !___VBox_vmm_pdmaudioifs_h */
1246
Note: See TracBrowser for help on using the repository browser.

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