VirtualBox

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

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

Audio: Update.

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