VirtualBox

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

Last change on this file since 73406 was 73402, checked in by vboxsync, 7 years ago

Audio/DrvAudio: Put the stream's statistics stuff into an own struct.

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