1 | /* $Id: AudioMixer.h 61166 2016-05-24 15:26:06Z vboxsync $ */
|
---|
2 | /** @file
|
---|
3 | * VBox audio: Mixing routines, mainly used by the various audio device
|
---|
4 | * emulations to achieve proper multiplexing from/to attached
|
---|
5 | * devices LUNs.
|
---|
6 | */
|
---|
7 |
|
---|
8 | /*
|
---|
9 | * Copyright (C) 2014-2016 Oracle Corporation
|
---|
10 | *
|
---|
11 | * This file is part of VirtualBox Open Source Edition (OSE), as
|
---|
12 | * available from http://www.virtualbox.org. This file is free software;
|
---|
13 | * you can redistribute it and/or modify it under the terms of the GNU
|
---|
14 | * General Public License (GPL) as published by the Free Software
|
---|
15 | * Foundation, in version 2 as it comes in the "COPYING" file of the
|
---|
16 | * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
|
---|
17 | * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
|
---|
18 | */
|
---|
19 |
|
---|
20 | #ifndef AUDIO_MIXER_H
|
---|
21 | #define AUDIO_MIXER_H
|
---|
22 |
|
---|
23 | #include <iprt/cdefs.h>
|
---|
24 | #include <VBox/vmm/pdmaudioifs.h>
|
---|
25 |
|
---|
26 | /**
|
---|
27 | * Structure for maintaining an audio mixer instance.
|
---|
28 | */
|
---|
29 | typedef struct AUDIOMIXER
|
---|
30 | {
|
---|
31 | /** Mixer name. */
|
---|
32 | char *pszName;
|
---|
33 | /** Format the mixer should convert/output
|
---|
34 | * data to so that the underlying device emulation
|
---|
35 | * can work with it. */
|
---|
36 | PDMAUDIOSTREAMCFG devFmt;
|
---|
37 | /** The master volume of this mixer. */
|
---|
38 | PDMAUDIOVOLUME VolMaster;
|
---|
39 | /* List of audio mixer sinks. */
|
---|
40 | RTLISTANCHOR lstSinks;
|
---|
41 | /** Number of used audio sinks. */
|
---|
42 | uint8_t cSinks;
|
---|
43 | } AUDIOMIXER, *PAUDIOMIXER;
|
---|
44 |
|
---|
45 | /** No flags specified. */
|
---|
46 | #define AUDMIXSTREAM_FLAG_NONE 0
|
---|
47 |
|
---|
48 | /** Prototype needed for AUDMIXSTREAM struct definition. */
|
---|
49 | typedef struct AUDMIXSINK *PAUDMIXSINK;
|
---|
50 |
|
---|
51 | /**
|
---|
52 | * Structure for maintaining an audio mixer stream.
|
---|
53 | */
|
---|
54 | typedef struct AUDMIXSTREAM
|
---|
55 | {
|
---|
56 | /** List node. */
|
---|
57 | RTLISTNODE Node;
|
---|
58 | /** Name of this stream. */
|
---|
59 | char *pszName;
|
---|
60 | /** Sink this stream is attached to. */
|
---|
61 | PAUDMIXSINK pSink;
|
---|
62 | /** Stream flags of type AUDMIXSTREAM_FLAG_. */
|
---|
63 | uint32_t fFlags;
|
---|
64 | /** Pointer to audio connector being used. */
|
---|
65 | PPDMIAUDIOCONNECTOR pConn;
|
---|
66 | /** Pointer to PDM audio stream this mixer stream handles. */
|
---|
67 | PPDMAUDIOSTREAM pStream;
|
---|
68 | } AUDMIXSTREAM, *PAUDMIXSTREAM;
|
---|
69 |
|
---|
70 | /** No flags specified. */
|
---|
71 | #define AUDMIXSINK_FLAG_NONE 0
|
---|
72 | /** Dirty flag. */
|
---|
73 | #define AUDMIXSINK_FLAG_DIRTY RT_BIT(0)
|
---|
74 |
|
---|
75 | /**
|
---|
76 | * Audio mixer sink direction.
|
---|
77 | */
|
---|
78 | typedef enum AUDMIXSINKDIR
|
---|
79 | {
|
---|
80 | AUDMIXSINKDIR_UNKNOWN = 0,
|
---|
81 | AUDMIXSINKDIR_INPUT,
|
---|
82 | AUDMIXSINKDIR_OUTPUT,
|
---|
83 | /** The usual 32-bit hack. */
|
---|
84 | AUDMIXSINKDIR_32BIT_HACK = 0x7fffffff
|
---|
85 | } AUDMIXSINKDIR;
|
---|
86 |
|
---|
87 | /**
|
---|
88 | * Audio mixer sink command.
|
---|
89 | */
|
---|
90 | typedef enum AUDMIXSINKCMD
|
---|
91 | {
|
---|
92 | /** Unknown command, do not use. */
|
---|
93 | AUDMIXSINKCMD_UNKNOWN = 0,
|
---|
94 | /** Enables the sink. */
|
---|
95 | AUDMIXSINKCMD_ENABLE,
|
---|
96 | /** Disables the sink. */
|
---|
97 | AUDMIXSINKCMD_DISABLE,
|
---|
98 | /** Pauses the sink. */
|
---|
99 | AUDMIXSINKCMD_PAUSE,
|
---|
100 | /** Resumes the sink. */
|
---|
101 | AUDMIXSINKCMD_RESUME,
|
---|
102 | /** Hack to blow the type up to 32-bit. */
|
---|
103 | AUDMIXSINKCMD_32BIT_HACK = 0x7fffffff
|
---|
104 | } AUDMIXSINKCMD;
|
---|
105 |
|
---|
106 | /**
|
---|
107 | * Structure for maintaining an audio mixer sink.
|
---|
108 | */
|
---|
109 | typedef struct AUDMIXSINK
|
---|
110 | {
|
---|
111 | RTLISTNODE Node;
|
---|
112 | /** Pointer to mixer object this sink is bound to. */
|
---|
113 | PAUDIOMIXER pParent;
|
---|
114 | /** Name of this sink. */
|
---|
115 | char *pszName;
|
---|
116 | /** The sink direction, that is,
|
---|
117 | * if this sink handles input or output. */
|
---|
118 | AUDMIXSINKDIR enmDir;
|
---|
119 | /** Sink flags of type AUDMIXSINK_FLAG_. */
|
---|
120 | uint32_t fFlags;
|
---|
121 | /** The sink's PCM format. */
|
---|
122 | PDMPCMPROPS PCMProps;
|
---|
123 | /** Number of streams assigned. */
|
---|
124 | uint8_t cStreams;
|
---|
125 | /** List of assigned streams.
|
---|
126 | * Note: All streams have the same PCM properties, so the
|
---|
127 | * mixer does not do any conversion. */
|
---|
128 | /** @todo Use something faster -- vector maybe? */
|
---|
129 | RTLISTANCHOR lstStreams;
|
---|
130 | #ifdef VBOX_AUDIO_MIXER_WITH_MIXBUF
|
---|
131 | /** This sink's mixing buffer, acting as
|
---|
132 | * a parent buffer for all streams this sink owns. */
|
---|
133 | PDMAUDIOMIXBUF MixBuf;
|
---|
134 | #endif
|
---|
135 | /** The volume of this sink. The volume always will
|
---|
136 | * be combined with the mixer's master volume. */
|
---|
137 | PDMAUDIOVOLUME Volume;
|
---|
138 | } AUDMIXSINK, *PAUDMIXSINK;
|
---|
139 |
|
---|
140 | /**
|
---|
141 | * Audio mixer operation.
|
---|
142 | */
|
---|
143 | typedef enum AUDMIXOP
|
---|
144 | {
|
---|
145 | /** Invalid operation, do not use. */
|
---|
146 | AUDMIXOP_INVALID = 0,
|
---|
147 | AUDMIXOP_COPY,
|
---|
148 | AUDMIXOP_BLEND,
|
---|
149 | /** The usual 32-bit hack. */
|
---|
150 | AUDMIXOP_32BIT_HACK = 0x7fffffff
|
---|
151 | } AUDMIXOP;
|
---|
152 |
|
---|
153 | /** No flags specified. */
|
---|
154 | #define AUDMIXSTRMCTL_FLAG_NONE 0
|
---|
155 |
|
---|
156 | int AudioMixerCreate(const char *pszName, uint32_t uFlags, PAUDIOMIXER *ppMixer);
|
---|
157 | int AudioMixerCreateSink(PAUDIOMIXER pMixer, const char *pszName, AUDMIXSINKDIR enmDir, PAUDMIXSINK *ppSink);
|
---|
158 | void AudioMixerDestroy(PAUDIOMIXER pMixer);
|
---|
159 | int AudioMixerGetDeviceFormat(PAUDIOMIXER pMixer, PPDMAUDIOSTREAMCFG pCfg);
|
---|
160 | void AudioMixerInvalidate(PAUDIOMIXER pMixer);
|
---|
161 | void AudioMixerRemoveSink(PAUDIOMIXER pMixer, PAUDMIXSINK pSink);
|
---|
162 | int AudioMixerSetDeviceFormat(PAUDIOMIXER pMixer, PPDMAUDIOSTREAMCFG pCfg);
|
---|
163 | int AudioMixerSetMasterVolume(PAUDIOMIXER pMixer, PPDMAUDIOVOLUME pVol);
|
---|
164 | void AudioMixerDebug(PAUDIOMIXER pMixer, PCDBGFINFOHLP pHlp, const char *pszArgs);
|
---|
165 |
|
---|
166 | int AudioMixerSinkAddStream(PAUDMIXSINK pSink, PAUDMIXSTREAM pStream);
|
---|
167 | int AudioMixerSinkCreateStream(PAUDMIXSINK pSink, PPDMIAUDIOCONNECTOR pConnector, PPDMAUDIOSTREAMCFG pCfg, uint32_t fFlags, PAUDMIXSTREAM *ppStream);
|
---|
168 | int AudioMixerSinkCtl(PAUDMIXSINK pSink, AUDMIXSINKCMD enmCmd);
|
---|
169 | void AudioMixerSinkDestroy(PAUDMIXSINK pSink);
|
---|
170 | AUDMIXSINKDIR AudioMixerSinkGetDir(PAUDMIXSINK pSink);
|
---|
171 | PAUDMIXSTREAM AudioMixerSinkGetStream(PAUDMIXSINK pSink, uint8_t uIndex);
|
---|
172 | uint8_t AudioMixerSinkGetStreamCount(PAUDMIXSINK pSink);
|
---|
173 | bool AudioMixerSinkHasData(PAUDMIXSINK pSink);
|
---|
174 | int AudioMixerSinkRead(PAUDMIXSINK pSink, AUDMIXOP enmOp, void *pvBuf, uint32_t cbBuf, uint32_t *pcbRead);
|
---|
175 | void AudioMixerSinkRemoveStream(PAUDMIXSINK pSink, PAUDMIXSTREAM pStream);
|
---|
176 | void AudioMixerSinkRemoveAllStreams(PAUDMIXSINK pSink);
|
---|
177 | int AudioMixerSinkSetFormat(PAUDMIXSINK pSink, PPDMPCMPROPS pPCMProps);
|
---|
178 | int AudioMixerSinkSetVolume(PAUDMIXSINK pSink, PPDMAUDIOVOLUME pVol);
|
---|
179 | void AudioMixerSinkTimerUpdate(PAUDMIXSINK pSink, uint64_t cTimerTicks, uint64_t cTicksElapsed, uint32_t *pcbData);
|
---|
180 | int AudioMixerSinkWrite(PAUDMIXSINK pSink, AUDMIXOP enmOp, const void *pvBuf, uint32_t cbBuf, uint32_t *pcbWritten);
|
---|
181 | int AudioMixerSinkUpdate(PAUDMIXSINK pSink);
|
---|
182 |
|
---|
183 | int AudioMixerStreamCtl(PAUDMIXSTREAM pStream, PDMAUDIOSTREAMCMD enmCmd, uint32_t fCtl);
|
---|
184 | void AudioMixerStreamDestroy(PAUDMIXSTREAM pStream);
|
---|
185 | bool AudioMixerStreamIsActive(PAUDMIXSTREAM pStream);
|
---|
186 | bool AudioMixerStreamIsValid(PAUDMIXSTREAM pStream);
|
---|
187 |
|
---|
188 | #endif /* AUDIO_MIXER_H */
|
---|
189 |
|
---|