VirtualBox

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

Last change on this file since 63534 was 63534, checked in by vboxsync, 9 years ago

Audio: Renaming.

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