VirtualBox

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

Last change on this file since 73768 was 73653, checked in by vboxsync, 6 years ago

Audio/DrvAudio: Bugfixes for drvAudioStreamPlay(); play (transfer) as much as possible /according to the backend) after buffering is complete; added debug logging.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 65.9 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 (playback) 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 (recording) 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 (in bytes). */
514 uint8_t cBytes;
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_cBytes, a_fSigned, a_cCannels, a_uHz, a_cShift, a_fSwapEndian) \
538 { a_cBytes, 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(cBytes, cChannels) ((cChannels == 2) + (cBytes / 2))
542/** Calculates the cShift value of a PDMAUDIOPCMPROPS structure. */
543#define PDMAUDIOPCMPROPS_MAKE_SHIFT(pProps) PDMAUDIOPCMPROPS_MAKE_SHIFT_PARMS((pProps)->cBytes, (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 * Structure for keeping audio input stream specifics.
956 * Do not use directly. Instead, use PDMAUDIOSTREAM.
957 */
958typedef struct PDMAUDIOSTREAMIN
959{
960#ifdef VBOX_WITH_STATISTICS
961 struct
962 {
963 STAMCOUNTER BytesElapsed;
964 STAMCOUNTER BytesTotalRead;
965 STAMCOUNTER FramesCaptured;
966 } Stats;
967#endif
968 struct
969 {
970 /** File for writing stream reads. */
971 PPDMAUDIOFILE pFileStreamRead;
972 /** File for writing non-interleaved captures. */
973 PPDMAUDIOFILE pFileCaptureNonInterleaved;
974 } Dbg;
975} PDMAUDIOSTREAMIN, *PPDMAUDIOSTREAMIN;
976
977/**
978 * Structure for keeping audio output stream specifics.
979 * Do not use directly. Instead, use PDMAUDIOSTREAM.
980 */
981typedef struct PDMAUDIOSTREAMOUT
982{
983#ifdef VBOX_WITH_STATISTICS
984 struct
985 {
986 STAMCOUNTER BytesElapsed;
987 STAMCOUNTER BytesTotalWritten;
988 STAMCOUNTER FramesPlayed;
989 } Stats;
990#endif
991 struct
992 {
993#ifdef DEBUG
994 /** Number of audio frames written since the last playback (transfer)
995 * to the backend. */
996 uint64_t cfWrittenSinceLastPlay;
997#endif
998 /** File for writing stream writes. */
999 PPDMAUDIOFILE pFileStreamWrite;
1000 /** File for writing stream playback. */
1001 PPDMAUDIOFILE pFilePlayNonInterleaved;
1002 } Dbg;
1003} PDMAUDIOSTREAMOUT, *PPDMAUDIOSTREAMOUT;
1004
1005/** Pointer to an audio stream. */
1006typedef struct PDMAUDIOSTREAM *PPDMAUDIOSTREAM;
1007
1008/**
1009 * Audio stream context.
1010 * Needed for separating data from the guest and host side (per stream).
1011 */
1012typedef struct PDMAUDIOSTREAMCTX
1013{
1014 /** The stream's audio configuration. */
1015 PDMAUDIOSTREAMCFG Cfg;
1016 /** This stream's mixing buffer. */
1017 PDMAUDIOMIXBUF MixBuf;
1018} PDMAUDIOSTREAMCTX;
1019
1020/** Pointer to an audio stream context. */
1021typedef struct PDMAUDIOSTREAM *PPDMAUDIOSTREAMCTX;
1022
1023/**
1024 * Structure for maintaining an input/output audio stream.
1025 */
1026typedef struct PDMAUDIOSTREAM
1027{
1028 /** List node. */
1029 RTLISTNODE Node;
1030 /** Name of this stream. */
1031 char szName[64];
1032 /** Number of references to this stream. Only can be
1033 * destroyed if the reference count is reaching 0. */
1034 uint32_t cRefs;
1035 /** Stream status flag. */
1036 PDMAUDIOSTREAMSTS fStatus;
1037 /** Audio direction of this stream. */
1038 PDMAUDIODIR enmDir;
1039 /** The guest side of the stream. */
1040 PDMAUDIOSTREAMCTX Guest;
1041 /** The host side of the stream. */
1042 PDMAUDIOSTREAMCTX Host;
1043 /** Union for input/output specifics (based on enmDir). */
1044 union
1045 {
1046 PDMAUDIOSTREAMIN In;
1047 PDMAUDIOSTREAMOUT Out;
1048 } RT_UNION_NM(u);
1049 /** Timestamp (in ns) since last iteration. */
1050 uint64_t tsLastIteratedNs;
1051 /** Timestamp (in ns) since last playback / capture. */
1052 uint64_t tsLastPlayedCapturedNs;
1053 /** Timestamp (in ns) since last read (input streams) or
1054 * write (output streams). */
1055 uint64_t tsLastReadWrittenNs;
1056 /** For output streams this indicates whether the stream has reached
1057 * its playback threshold, e.g. is playing audio.
1058 * For input streams this indicates whether the stream has enough input
1059 * data to actually start reading audio. */
1060 bool fThresholdReached;
1061 /** Data to backend-specific stream data.
1062 * This data block will be casted by the backend to access its backend-dependent data.
1063 *
1064 * That way the backends do not have access to the audio connector's data. */
1065 void *pvBackend;
1066 /** Size (in bytes) of the backend-specific stream data. */
1067 size_t cbBackend;
1068} PDMAUDIOSTREAM;
1069
1070/** Pointer to a audio connector interface. */
1071typedef struct PDMIAUDIOCONNECTOR *PPDMIAUDIOCONNECTOR;
1072
1073/**
1074 * Enumeration for an audio callback source.
1075 */
1076typedef enum PDMAUDIOCBSOURCE
1077{
1078 /** Invalid, do not use. */
1079 PDMAUDIOCBSOURCE_INVALID = 0,
1080 /** Device emulation. */
1081 PDMAUDIOCBSOURCE_DEVICE = 1,
1082 /** Audio connector interface. */
1083 PDMAUDIOCBSOURCE_CONNECTOR = 2,
1084 /** Backend (lower). */
1085 PDMAUDIOCBSOURCE_BACKEND = 3,
1086 /** Hack to blow the type up to 32-bit. */
1087 PDMAUDIOCBSOURCE_32BIT_HACK = 0x7fffffff
1088} PDMAUDIOCBSOURCE;
1089
1090/**
1091 * Audio device callback types.
1092 * Those callbacks are being sent from the audio connector -> device emulation.
1093 */
1094typedef enum PDMAUDIODEVICECBTYPE
1095{
1096 /** Invalid, do not use. */
1097 PDMAUDIODEVICECBTYPE_INVALID = 0,
1098 /** Data is availabe as input for passing to the device emulation. */
1099 PDMAUDIODEVICECBTYPE_DATA_INPUT,
1100 /** Free data for the device emulation to write to the backend. */
1101 PDMAUDIODEVICECBTYPE_DATA_OUTPUT,
1102 /** Hack to blow the type up to 32-bit. */
1103 PDMAUDIODEVICECBTYPE_32BIT_HACK = 0x7fffffff
1104} PDMAUDIODEVICECBTYPE;
1105
1106/**
1107 * Device callback data for audio input.
1108 */
1109typedef struct PDMAUDIODEVICECBDATA_DATA_INPUT
1110{
1111 /** Input: How many bytes are availabe as input for passing
1112 * to the device emulation. */
1113 uint32_t cbInAvail;
1114 /** Output: How many bytes have been read. */
1115 uint32_t cbOutRead;
1116} PDMAUDIODEVICECBDATA_DATA_INPUT, *PPDMAUDIODEVICECBDATA_DATA_INPUT;
1117
1118/**
1119 * Device callback data for audio output.
1120 */
1121typedef struct PDMAUDIODEVICECBDATA_DATA_OUTPUT
1122{
1123 /** Input: How many bytes are free for the device emulation to write. */
1124 uint32_t cbInFree;
1125 /** Output: How many bytes were written by the device emulation. */
1126 uint32_t cbOutWritten;
1127} PDMAUDIODEVICECBDATA_DATA_OUTPUT, *PPDMAUDIODEVICECBDATA_DATA_OUTPUT;
1128
1129/**
1130 * Audio backend callback types.
1131 * Those callbacks are being sent from the backend -> audio connector.
1132 */
1133typedef enum PDMAUDIOBACKENDCBTYPE
1134{
1135 /** Invalid, do not use. */
1136 PDMAUDIOBACKENDCBTYPE_INVALID = 0,
1137 /** The backend's status has changed. */
1138 PDMAUDIOBACKENDCBTYPE_STATUS,
1139 /** One or more host audio devices have changed. */
1140 PDMAUDIOBACKENDCBTYPE_DEVICES_CHANGED,
1141 /** Hack to blow the type up to 32-bit. */
1142 PDMAUDIOBACKENDCBTYPE_32BIT_HACK = 0x7fffffff
1143} PDMAUDIOBACKENDCBTYPE;
1144
1145/** Pointer to a host audio interface. */
1146typedef struct PDMIHOSTAUDIO *PPDMIHOSTAUDIO;
1147
1148/**
1149 * Host audio callback function.
1150 * This function will be called from a backend to communicate with the host audio interface.
1151 *
1152 * @returns IPRT status code.
1153 * @param pDrvIns Pointer to driver instance which called us.
1154 * @param enmType Callback type.
1155 * @param pvUser User argument.
1156 * @param cbUser Size (in bytes) of user argument.
1157 */
1158typedef DECLCALLBACK(int) FNPDMHOSTAUDIOCALLBACK(PPDMDRVINS pDrvIns, PDMAUDIOBACKENDCBTYPE enmType, void *pvUser, size_t cbUser);
1159/** Pointer to a FNPDMHOSTAUDIOCALLBACK(). */
1160typedef FNPDMHOSTAUDIOCALLBACK *PFNPDMHOSTAUDIOCALLBACK;
1161
1162/**
1163 * Audio callback registration record.
1164 */
1165typedef struct PDMAUDIOCBRECORD
1166{
1167 /** List node. */
1168 RTLISTANCHOR Node;
1169 /** Callback source. */
1170 PDMAUDIOCBSOURCE enmSource;
1171 /** Callback type, based on the given source. */
1172 union
1173 {
1174 /** Device callback stuff. */
1175 struct
1176 {
1177 PDMAUDIODEVICECBTYPE enmType;
1178 } Device;
1179 } RT_UNION_NM(u);
1180 /** Pointer to context data. Optional. */
1181 void *pvCtx;
1182 /** Size (in bytes) of context data.
1183 * Must be 0 if pvCtx is NULL. */
1184 size_t cbCtx;
1185} PDMAUDIOCBRECORD, *PPDMAUDIOCBRECORD;
1186
1187#define PPDMAUDIOBACKENDSTREAM void *
1188
1189/**
1190 * Audio connector interface (up).
1191 */
1192typedef struct PDMIAUDIOCONNECTOR
1193{
1194 /**
1195 * Enables or disables the given audio direction for this driver.
1196 *
1197 * When disabled, assiociated output streams consume written audio without passing them further down to the backends.
1198 * Associated input streams then return silence when read from those.
1199 *
1200 * @returns VBox status code.
1201 * @param pInterface Pointer to the interface structure containing the called function pointer.
1202 * @param enmDir Audio direction to enable or disable driver for.
1203 * @param fEnable Whether to enable or disable the specified audio direction.
1204 */
1205 DECLR3CALLBACKMEMBER(int, pfnEnable, (PPDMIAUDIOCONNECTOR pInterface, PDMAUDIODIR enmDir, bool fEnable));
1206
1207 /**
1208 * Returns whether the given audio direction for this driver is enabled or not.
1209 *
1210 * @returns True if audio is enabled for the given direction, false if not.
1211 * @param pInterface Pointer to the interface structure containing the called function pointer.
1212 * @param enmDir Audio direction to retrieve enabled status for.
1213 */
1214 DECLR3CALLBACKMEMBER(bool, pfnIsEnabled, (PPDMIAUDIOCONNECTOR pInterface, PDMAUDIODIR enmDir));
1215
1216 /**
1217 * Retrieves the current configuration of the host audio backend.
1218 *
1219 * @returns VBox status code.
1220 * @param pInterface Pointer to the interface structure containing the called function pointer.
1221 * @param pCfg Where to store the host audio backend configuration data.
1222 */
1223 DECLR3CALLBACKMEMBER(int, pfnGetConfig, (PPDMIAUDIOCONNECTOR pInterface, PPDMAUDIOBACKENDCFG pCfg));
1224
1225 /**
1226 * Retrieves the current status of the host audio backend.
1227 *
1228 * @returns Status of the host audio backend.
1229 * @param pInterface Pointer to the interface structure containing the called function pointer.
1230 * @param enmDir Audio direction to check host audio backend for. Specify PDMAUDIODIR_ANY for the overall
1231 * backend status.
1232 */
1233 DECLR3CALLBACKMEMBER(PDMAUDIOBACKENDSTS, pfnGetStatus, (PPDMIAUDIOCONNECTOR pInterface, PDMAUDIODIR enmDir));
1234
1235 /**
1236 * Creates an audio stream.
1237 *
1238 * @returns VBox status code.
1239 * @param pInterface Pointer to the interface structure containing the called function pointer.
1240 * @param pCfgHost Stream configuration for host side.
1241 * @param pCfgGuest Stream configuration for guest side.
1242 * @param ppStream Pointer where to return the created audio stream on success.
1243 */
1244 DECLR3CALLBACKMEMBER(int, pfnStreamCreate, (PPDMIAUDIOCONNECTOR pInterface, PPDMAUDIOSTREAMCFG pCfgHost, PPDMAUDIOSTREAMCFG pCfgGuest, PPDMAUDIOSTREAM *ppStream));
1245
1246 /**
1247 * Destroys an audio stream.
1248 *
1249 * @param pInterface Pointer to the interface structure containing the called function pointer.
1250 * @param pStream Pointer to audio stream.
1251 */
1252 DECLR3CALLBACKMEMBER(int, pfnStreamDestroy, (PPDMIAUDIOCONNECTOR pInterface, PPDMAUDIOSTREAM pStream));
1253
1254 /**
1255 * Adds a reference to the specified audio stream.
1256 *
1257 * @returns New reference count. UINT32_MAX on error.
1258 * @param pInterface Pointer to the interface structure containing the called function pointer.
1259 * @param pStream Pointer to audio stream adding the reference to.
1260 */
1261 DECLR3CALLBACKMEMBER(uint32_t, pfnStreamRetain, (PPDMIAUDIOCONNECTOR pInterface, PPDMAUDIOSTREAM pStream));
1262
1263 /**
1264 * Releases a reference from the specified stream.
1265 *
1266 * @returns New reference count. UINT32_MAX on error.
1267 * @param pInterface Pointer to the interface structure containing the called function pointer.
1268 * @param pStream Pointer to audio stream releasing a reference from.
1269 */
1270 DECLR3CALLBACKMEMBER(uint32_t, pfnStreamRelease, (PPDMIAUDIOCONNECTOR pInterface, PPDMAUDIOSTREAM pStream));
1271
1272 /**
1273 * Reads PCM audio data from the host (input).
1274 *
1275 * @returns VBox status code.
1276 * @param pInterface Pointer to the interface structure containing the called function pointer.
1277 * @param pStream Pointer to audio stream to write to.
1278 * @param pvBuf Where to store the read data.
1279 * @param cbBuf Number of bytes to read.
1280 * @param pcbRead Bytes of audio data read. Optional.
1281 */
1282 DECLR3CALLBACKMEMBER(int, pfnStreamRead, (PPDMIAUDIOCONNECTOR pInterface, PPDMAUDIOSTREAM pStream, void *pvBuf, uint32_t cbBuf, uint32_t *pcbRead));
1283
1284 /**
1285 * Writes PCM audio data to the host (output).
1286 *
1287 * @returns VBox status code.
1288 * @param pInterface Pointer to the interface structure containing the called function pointer.
1289 * @param pStream Pointer to audio stream to read from.
1290 * @param pvBuf Audio data to be written.
1291 * @param cbBuf Number of bytes to be written.
1292 * @param pcbWritten Bytes of audio data written. Optional.
1293 */
1294 DECLR3CALLBACKMEMBER(int, pfnStreamWrite, (PPDMIAUDIOCONNECTOR pInterface, PPDMAUDIOSTREAM pStream, const void *pvBuf, uint32_t cbBuf, uint32_t *pcbWritten));
1295
1296 /**
1297 * Controls a specific audio stream.
1298 *
1299 * @returns VBox status code.
1300 * @param pInterface Pointer to the interface structure containing the called function pointer.
1301 * @param pStream Pointer to audio stream.
1302 * @param enmStreamCmd The stream command to issue.
1303 */
1304 DECLR3CALLBACKMEMBER(int, pfnStreamControl, (PPDMIAUDIOCONNECTOR pInterface, PPDMAUDIOSTREAM pStream, PDMAUDIOSTREAMCMD enmStreamCmd));
1305
1306 /**
1307 * Processes stream data.
1308 *
1309 * @param pInterface Pointer to the interface structure containing the called function pointer.
1310 * @param pStream Pointer to audio stream.
1311 */
1312 DECLR3CALLBACKMEMBER(int, pfnStreamIterate, (PPDMIAUDIOCONNECTOR pInterface, PPDMAUDIOSTREAM pStream));
1313
1314 /**
1315 * Returns the number of readable data (in bytes) of a specific audio input stream.
1316 *
1317 * @returns Number of readable data (in bytes).
1318 * @param pInterface Pointer to the interface structure containing the called function pointer.
1319 * @param pStream Pointer to audio stream.
1320 */
1321 DECLR3CALLBACKMEMBER(uint32_t, pfnStreamGetReadable, (PPDMIAUDIOCONNECTOR pInterface, PPDMAUDIOSTREAM pStream));
1322
1323 /**
1324 * Returns the number of writable data (in bytes) of a specific audio output stream.
1325 *
1326 * @returns Number of writable data (in bytes).
1327 * @param pInterface Pointer to the interface structure containing the called function pointer.
1328 * @param pStream Pointer to audio stream.
1329 */
1330 DECLR3CALLBACKMEMBER(uint32_t, pfnStreamGetWritable, (PPDMIAUDIOCONNECTOR pInterface, PPDMAUDIOSTREAM pStream));
1331
1332 /**
1333 * Returns the status of a specific audio stream.
1334 *
1335 * @returns Audio stream status
1336 * @param pInterface Pointer to the interface structure containing the called function pointer.
1337 * @param pStream Pointer to audio stream.
1338 */
1339 DECLR3CALLBACKMEMBER(PDMAUDIOSTREAMSTS, pfnStreamGetStatus, (PPDMIAUDIOCONNECTOR pInterface, PPDMAUDIOSTREAM pStream));
1340
1341 /**
1342 * Sets the audio volume of a specific audio stream.
1343 *
1344 * @returns VBox status code.
1345 * @param pInterface Pointer to the interface structure containing the called function pointer.
1346 * @param pStream Pointer to audio stream.
1347 * @param pVol Pointer to audio volume structure to set the stream's audio volume to.
1348 */
1349 DECLR3CALLBACKMEMBER(int, pfnStreamSetVolume, (PPDMIAUDIOCONNECTOR pInterface, PPDMAUDIOSTREAM pStream, PPDMAUDIOVOLUME pVol));
1350
1351 /**
1352 * Plays (transfers) available audio frames to the host backend. Only works with output streams.
1353 *
1354 * @returns VBox status code.
1355 * @param pInterface Pointer to the interface structure containing the called function pointer.
1356 * @param pStream Pointer to audio stream.
1357 * @param pcFramesPlayed Number of frames played. Optional.
1358 */
1359 DECLR3CALLBACKMEMBER(int, pfnStreamPlay, (PPDMIAUDIOCONNECTOR pInterface, PPDMAUDIOSTREAM pStream, uint32_t *pcFramesPlayed));
1360
1361 /**
1362 * Captures (transfers) available audio frames from the host backend. Only works with input streams.
1363 *
1364 * @returns VBox status code.
1365 * @param pInterface Pointer to the interface structure containing the called function pointer.
1366 * @param pStream Pointer to audio stream.
1367 * @param pcFramesCaptured Number of frames captured. Optional.
1368 */
1369 DECLR3CALLBACKMEMBER(int, pfnStreamCapture, (PPDMIAUDIOCONNECTOR pInterface, PPDMAUDIOSTREAM pStream, uint32_t *pcFramesCaptured));
1370
1371 /**
1372 * Registers (device) callbacks.
1373 * This is handy for letting the device emulation know of certain events, e.g. processing input / output data
1374 * or configuration changes.
1375 *
1376 * @returns VBox status code.
1377 * @param pInterface Pointer to the interface structure containing the called function pointer.
1378 * @param paCallbacks Pointer to array of callbacks to register.
1379 * @param cCallbacks Number of callbacks to register.
1380 */
1381 DECLR3CALLBACKMEMBER(int, pfnRegisterCallbacks, (PPDMIAUDIOCONNECTOR pInterface, PPDMAUDIOCBRECORD paCallbacks, size_t cCallbacks));
1382
1383} PDMIAUDIOCONNECTOR;
1384
1385/** PDMIAUDIOCONNECTOR interface ID. */
1386#define PDMIAUDIOCONNECTOR_IID "A643B40C-733F-4307-9549-070AF0EE0ED6"
1387
1388/**
1389 * Assigns all needed interface callbacks for an audio backend.
1390 *
1391 * @param a_Prefix The function name prefix.
1392 */
1393#define PDMAUDIO_IHOSTAUDIO_CALLBACKS(a_Prefix) \
1394 do { \
1395 pThis->IHostAudio.pfnInit = RT_CONCAT(a_Prefix,Init); \
1396 pThis->IHostAudio.pfnShutdown = RT_CONCAT(a_Prefix,Shutdown); \
1397 pThis->IHostAudio.pfnGetConfig = RT_CONCAT(a_Prefix,GetConfig); \
1398 /** @todo Add pfnGetDevices here as soon as supported by all backends. */ \
1399 pThis->IHostAudio.pfnGetStatus = RT_CONCAT(a_Prefix,GetStatus); \
1400 /** @todo Ditto for pfnSetCallback. */ \
1401 pThis->IHostAudio.pfnStreamCreate = RT_CONCAT(a_Prefix,StreamCreate); \
1402 pThis->IHostAudio.pfnStreamDestroy = RT_CONCAT(a_Prefix,StreamDestroy); \
1403 pThis->IHostAudio.pfnStreamControl = RT_CONCAT(a_Prefix,StreamControl); \
1404 pThis->IHostAudio.pfnStreamGetReadable = RT_CONCAT(a_Prefix,StreamGetReadable); \
1405 pThis->IHostAudio.pfnStreamGetWritable = RT_CONCAT(a_Prefix,StreamGetWritable); \
1406 pThis->IHostAudio.pfnStreamGetStatus = RT_CONCAT(a_Prefix,StreamGetStatus); \
1407 pThis->IHostAudio.pfnStreamIterate = RT_CONCAT(a_Prefix,StreamIterate); \
1408 pThis->IHostAudio.pfnStreamPlay = RT_CONCAT(a_Prefix,StreamPlay); \
1409 pThis->IHostAudio.pfnStreamCapture = RT_CONCAT(a_Prefix,StreamCapture); \
1410 } while (0)
1411
1412/**
1413 * PDM host audio interface.
1414 */
1415typedef struct PDMIHOSTAUDIO
1416{
1417 /**
1418 * Initializes the host backend (driver).
1419 *
1420 * @returns VBox status code.
1421 * @param pInterface Pointer to the interface structure containing the called function pointer.
1422 */
1423 DECLR3CALLBACKMEMBER(int, pfnInit, (PPDMIHOSTAUDIO pInterface));
1424
1425 /**
1426 * Shuts down the host backend (driver).
1427 *
1428 * @returns VBox status code.
1429 * @param pInterface Pointer to the interface structure containing the called function pointer.
1430 */
1431 DECLR3CALLBACKMEMBER(void, pfnShutdown, (PPDMIHOSTAUDIO pInterface));
1432
1433 /**
1434 * Returns the host backend's configuration (backend).
1435 *
1436 * @returns VBox status code.
1437 * @param pInterface Pointer to the interface structure containing the called function pointer.
1438 * @param pBackendCfg Where to store the backend audio configuration to.
1439 */
1440 DECLR3CALLBACKMEMBER(int, pfnGetConfig, (PPDMIHOSTAUDIO pInterface, PPDMAUDIOBACKENDCFG pBackendCfg));
1441
1442 /**
1443 * Returns (enumerates) host audio device information.
1444 *
1445 * @returns VBox status code.
1446 * @param pInterface Pointer to the interface structure containing the called function pointer.
1447 * @param pDeviceEnum Where to return the enumerated audio devices.
1448 */
1449 DECLR3CALLBACKMEMBER(int, pfnGetDevices, (PPDMIHOSTAUDIO pInterface, PPDMAUDIODEVICEENUM pDeviceEnum));
1450
1451 /**
1452 * Returns the current status from the audio backend.
1453 *
1454 * @returns PDMAUDIOBACKENDSTS enum.
1455 * @param pInterface Pointer to the interface structure containing the called function pointer.
1456 * @param enmDir Audio direction to get status for. Pass PDMAUDIODIR_ANY for overall status.
1457 */
1458 DECLR3CALLBACKMEMBER(PDMAUDIOBACKENDSTS, pfnGetStatus, (PPDMIHOSTAUDIO pInterface, PDMAUDIODIR enmDir));
1459
1460 /**
1461 * Sets a callback the audio backend can call. Optional.
1462 *
1463 * @returns VBox status code.
1464 * @param pInterface Pointer to the interface structure containing the called function pointer.
1465 * @param pfnCallback The callback function to use, or NULL when unregistering.
1466 */
1467 DECLR3CALLBACKMEMBER(int, pfnSetCallback, (PPDMIHOSTAUDIO pInterface, PFNPDMHOSTAUDIOCALLBACK pfnCallback));
1468
1469 /**
1470 * Creates an audio stream using the requested stream configuration.
1471 * If a backend is not able to create this configuration, it will return its best match in the acquired configuration
1472 * structure on success.
1473 *
1474 * @returns VBox status code.
1475 * @param pInterface Pointer to the interface structure containing the called function pointer.
1476 * @param pStream Pointer to audio stream.
1477 * @param pCfgReq Pointer to requested stream configuration.
1478 * @param pCfgAcq Pointer to acquired stream configuration.
1479 */
1480 DECLR3CALLBACKMEMBER(int, pfnStreamCreate, (PPDMIHOSTAUDIO pInterface, PPDMAUDIOBACKENDSTREAM pStream, PPDMAUDIOSTREAMCFG pCfgReq, PPDMAUDIOSTREAMCFG pCfgAcq));
1481
1482 /**
1483 * Destroys an audio stream.
1484 *
1485 * @returns VBox status code.
1486 * @param pInterface Pointer to the interface structure containing the called function pointer.
1487 * @param pStream Pointer to audio stream.
1488 */
1489 DECLR3CALLBACKMEMBER(int, pfnStreamDestroy, (PPDMIHOSTAUDIO pInterface, PPDMAUDIOBACKENDSTREAM pStream));
1490
1491 /**
1492 * Controls an audio stream.
1493 *
1494 * @returns VBox status code.
1495 * @param pInterface Pointer to the interface structure containing the called function pointer.
1496 * @param pStream Pointer to audio stream.
1497 * @param enmStreamCmd The stream command to issue.
1498 */
1499 DECLR3CALLBACKMEMBER(int, pfnStreamControl, (PPDMIHOSTAUDIO pInterface, PPDMAUDIOBACKENDSTREAM pStream, PDMAUDIOSTREAMCMD enmStreamCmd));
1500
1501 /**
1502 * Returns the amount which is readable from the audio (input) stream.
1503 *
1504 * @returns For non-raw layout streams: Number of readable bytes.
1505 * for raw layout streams : Number of readable audio frames.
1506 * @param pInterface Pointer to the interface structure containing the called function pointer.
1507 * @param pStream Pointer to audio stream.
1508 */
1509 DECLR3CALLBACKMEMBER(uint32_t, pfnStreamGetReadable, (PPDMIHOSTAUDIO pInterface, PPDMAUDIOBACKENDSTREAM pStream));
1510
1511 /**
1512 * Returns the amount which is writable to the audio (output) stream.
1513 *
1514 * @returns For non-raw layout streams: Number of writable bytes.
1515 * for raw layout streams : Number of writable audio frames.
1516 * @param pInterface Pointer to the interface structure containing the called function pointer.
1517 * @param pStream Pointer to audio stream.
1518 */
1519 DECLR3CALLBACKMEMBER(uint32_t, pfnStreamGetWritable, (PPDMIHOSTAUDIO pInterface, PPDMAUDIOBACKENDSTREAM pStream));
1520
1521 /**
1522 * Returns the amount which is pending (in other words has not yet been processed) by/from the backend yet.
1523 * Optional.
1524 *
1525 * For input streams this is read audio data by the backend which has not been processed by the host yet.
1526 * For output streams this is written audio data to the backend which has not been processed by the backend yet.
1527 *
1528 * @returns For non-raw layout streams: Number of pending bytes.
1529 * for raw layout streams : Number of pending audio frames.
1530 * @param pInterface Pointer to the interface structure containing the called function pointer.
1531 * @param pStream Pointer to audio stream.
1532 */
1533 DECLR3CALLBACKMEMBER(uint32_t, pfnStreamGetPending, (PPDMIHOSTAUDIO pInterface, PPDMAUDIOBACKENDSTREAM pStream));
1534
1535 /**
1536 * Returns the current status of the given backend stream.
1537 *
1538 * @returns PDMAUDIOSTREAMSTS
1539 * @param pInterface Pointer to the interface structure containing the called function pointer.
1540 * @param pStream Pointer to audio stream.
1541 */
1542 DECLR3CALLBACKMEMBER(PDMAUDIOSTREAMSTS, pfnStreamGetStatus, (PPDMIHOSTAUDIO pInterface, PPDMAUDIOBACKENDSTREAM pStream));
1543
1544 /**
1545 * Gives the host backend the chance to do some (necessary) iteration work.
1546 *
1547 * @returns VBox status code.
1548 * @param pInterface Pointer to the interface structure containing the called function pointer.
1549 * @param pStream Pointer to audio stream.
1550 */
1551 DECLR3CALLBACKMEMBER(int, pfnStreamIterate, (PPDMIHOSTAUDIO pInterface, PPDMAUDIOBACKENDSTREAM pStream));
1552
1553 /**
1554 * Signals the backend that the host wants to begin playing for this iteration. Optional.
1555 *
1556 * @param pInterface Pointer to the interface structure containing the called function pointer.
1557 * @param pStream Pointer to audio stream.
1558 */
1559 DECLR3CALLBACKMEMBER(void, pfnStreamPlayBegin, (PPDMIHOSTAUDIO pInterface, PPDMAUDIOBACKENDSTREAM pStream));
1560
1561 /**
1562 * Plays (writes to) an audio (output) stream.
1563 *
1564 * @returns VBox status code.
1565 * @param pInterface Pointer to the interface structure containing the called function pointer.
1566 * @param pStream Pointer to audio stream.
1567 * @param pvBuf Pointer to audio data buffer to play.
1568 * @param cxBuf For non-raw layout streams: Size (in bytes) of audio data buffer,
1569 * for raw layout streams : Size (in audio frames) of audio data buffer.
1570 * @param pcxWritten For non-raw layout streams: Returns number of bytes written. Optional.
1571 * for raw layout streams : Returns number of frames written. Optional.
1572 */
1573 DECLR3CALLBACKMEMBER(int, pfnStreamPlay, (PPDMIHOSTAUDIO pInterface, PPDMAUDIOBACKENDSTREAM pStream, const void *pvBuf, uint32_t cxBuf, uint32_t *pcxWritten));
1574
1575 /**
1576 * Signals the backend that the host finished playing for this iteration. Optional.
1577 *
1578 * @param pInterface Pointer to the interface structure containing the called function pointer.
1579 * @param pStream Pointer to audio stream.
1580 */
1581 DECLR3CALLBACKMEMBER(void, pfnStreamPlayEnd, (PPDMIHOSTAUDIO pInterface, PPDMAUDIOBACKENDSTREAM pStream));
1582
1583 /**
1584 * Signals the backend that the host wants to begin capturing for this iteration. Optional.
1585 *
1586 * @param pInterface Pointer to the interface structure containing the called function pointer.
1587 * @param pStream Pointer to audio stream.
1588 */
1589 DECLR3CALLBACKMEMBER(void, pfnStreamCaptureBegin, (PPDMIHOSTAUDIO pInterface, PPDMAUDIOBACKENDSTREAM pStream));
1590
1591 /**
1592 * Captures (reads from) an audio (input) stream.
1593 *
1594 * @returns VBox status code.
1595 * @param pInterface Pointer to the interface structure containing the called function pointer.
1596 * @param pStream Pointer to audio stream.
1597 * @param pvBuf Buffer where to store read audio data.
1598 * @param cxBuf For non-raw layout streams: Size (in bytes) of audio data buffer,
1599 * for raw layout streams : Size (in audio frames) of audio data buffer.
1600 * @param pcxRead For non-raw layout streams: Returns number of bytes read. Optional.
1601 * for raw layout streams : Returns number of frames read. Optional.
1602 */
1603 DECLR3CALLBACKMEMBER(int, pfnStreamCapture, (PPDMIHOSTAUDIO pInterface, PPDMAUDIOBACKENDSTREAM pStream, void *pvBuf, uint32_t cxBuf, uint32_t *pcxRead));
1604
1605 /**
1606 * Signals the backend that the host finished capturing for this iteration. Optional.
1607 *
1608 * @param pInterface Pointer to the interface structure containing the called function pointer.
1609 * @param pStream Pointer to audio stream.
1610 */
1611 DECLR3CALLBACKMEMBER(void, pfnStreamCaptureEnd, (PPDMIHOSTAUDIO pInterface, PPDMAUDIOBACKENDSTREAM pStream));
1612
1613} PDMIHOSTAUDIO;
1614
1615/** PDMIHOSTAUDIO interface ID. */
1616#define PDMIHOSTAUDIO_IID "640F5A31-8245-491C-538F-29A0F9D08881"
1617
1618/** @} */
1619
1620#endif /* !___VBox_vmm_pdmaudioifs_h */
1621
Note: See TracBrowser for help on using the repository browser.

© 2023 Oracle
ContactPrivacy policyTerms of Use