VirtualBox

source: vbox/trunk/src/VBox/Devices/Audio/AudioMixer.h@ 88390

Last change on this file since 88390 was 88357, checked in by vboxsync, 4 years ago

Audio: Moved PDMAUDIOFILE and associated stuff out of pdmaudioifs.h and into AudioHlp.h, renaming the typedefs & defines. bugref:9890

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 10.8 KB
Line 
1/* $Id: AudioMixer.h 88357 2021-04-04 22:58:35Z vboxsync $ */
2/** @file
3 * VBox audio - Mixing routines.
4 *
5 * The mixing routines are mainly used by the various audio device emulations
6 * to achieve proper multiplexing from/to attached devices LUNs.
7 */
8
9/*
10 * Copyright (C) 2014-2020 Oracle Corporation
11 *
12 * This file is part of VirtualBox Open Source Edition (OSE), as
13 * available from http://www.virtualbox.org. This file is free software;
14 * you can redistribute it and/or modify it under the terms of the GNU
15 * General Public License (GPL) as published by the Free Software
16 * Foundation, in version 2 as it comes in the "COPYING" file of the
17 * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
18 * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
19 */
20
21#ifndef VBOX_INCLUDED_SRC_Audio_AudioMixer_h
22#define VBOX_INCLUDED_SRC_Audio_AudioMixer_h
23#ifndef RT_WITHOUT_PRAGMA_ONCE
24# pragma once
25#endif
26
27#include <iprt/cdefs.h>
28#include <iprt/critsect.h>
29
30#include <VBox/vmm/pdmaudioifs.h>
31#include "AudioMixBuffer.h"
32#include "AudioHlp.h"
33
34
35/** Pointer to an audio mixer sink. */
36typedef struct AUDMIXSINK *PAUDMIXSINK;
37
38
39/**
40 * Audio mixer instance.
41 */
42typedef struct AUDIOMIXER
43{
44 /** The mixer's name. */
45 char *pszName;
46 /** The mixer's critical section. */
47 RTCRITSECT CritSect;
48 /** The master volume of this mixer. */
49 PDMAUDIOVOLUME VolMaster;
50 /** List of audio mixer sinks. */
51 RTLISTANCHOR lstSinks;
52 /** Number of used audio sinks. */
53 uint8_t cSinks;
54 /** Mixer flags. See AUDMIXER_FLAGS_XXX. */
55 uint32_t fFlags;
56} AUDIOMIXER;
57/** Pointer to an audio mixer instance. */
58typedef AUDIOMIXER *PAUDIOMIXER;
59
60
61/** Defines an audio mixer stream's flags. */
62#define AUDMIXSTREAMFLAGS uint32_t
63
64/** No flags specified. */
65#define AUDMIXSTREAM_F_NONE 0
66/** The mixing stream is flagged as being enabled (active). */
67#define AUDMIXSTREAM_F_ENABLED RT_BIT(0)
68
69/** Defines an audio mixer stream's internal status. */
70#define AUDMIXSTREAMSTATUS uint32_t
71
72/** No status set. */
73#define AUDMIXSTREAM_STATUS_NONE 0
74/** The mixing stream is enabled (active). */
75#define AUDMIXSTREAM_STATUS_ENABLED RT_BIT(0)
76/** The mixing stream can be read from. */
77#define AUDMIXSTREAM_STATUS_CAN_READ RT_BIT(1)
78/** The mixing stream can be written to. */
79#define AUDMIXSTREAM_STATUS_CAN_WRITE RT_BIT(2)
80
81
82/**
83 * Audio mixer stream.
84 */
85typedef struct AUDMIXSTREAM
86{
87 /** List node. */
88 RTLISTNODE Node;
89 /** Name of this stream. */
90 char *pszName;
91 /** The statistics prefix. */
92 char *pszStatPrefix;
93 /** The streams's critical section. */
94 RTCRITSECT CritSect;
95 /** Sink this stream is attached to. */
96 PAUDMIXSINK pSink;
97 /** Stream flags of type AUDMIXSTREAM_F_. */
98 uint32_t fFlags;
99 /** Stream status of type AUDMIXSTREAM_STATUS_. */
100 uint32_t fStatus;
101 /** Pointer to audio connector being used. */
102 PPDMIAUDIOCONNECTOR pConn;
103 /** Pointer to PDM audio stream this mixer stream handles. */
104 PPDMAUDIOSTREAM pStream;
105 /** Last read (recording) / written (playback) timestamp (in ns). */
106 uint64_t tsLastReadWrittenNs;
107 /** The stream's circular buffer for temporarily
108 * holding (raw) device audio data. */
109 PRTCIRCBUF pCircBuf;
110 /** Stats: Number of bytes used in the circular buffer. */
111 uint32_t StatsCircBufUsed;
112 /** Stats: Size of circular buffer. */
113 uint32_t StatsCircBufSize;
114} AUDMIXSTREAM, *PAUDMIXSTREAM;
115
116/** Defines an audio sink's current status. */
117#define AUDMIXSINKSTS uint32_t
118
119/** No status specified. */
120#define AUDMIXSINK_STS_NONE 0
121/** The sink is active and running. */
122#define AUDMIXSINK_STS_RUNNING RT_BIT(0)
123/** The sink is in a pending disable state. */
124#define AUDMIXSINK_STS_PENDING_DISABLE RT_BIT(1)
125/** Dirty flag.
126 * For output sinks this means that there is data in the
127 * sink which has not been played yet.
128 * For input sinks this means that there is data in the
129 * sink which has been recorded but not transferred to the
130 * destination yet. */
131#define AUDMIXSINK_STS_DIRTY RT_BIT(2)
132
133/**
134 * Audio mixer sink direction.
135 */
136typedef enum AUDMIXSINKDIR
137{
138 /** Unknown direction. */
139 AUDMIXSINKDIR_UNKNOWN = 0,
140 /** Input (capturing from a device). */
141 AUDMIXSINKDIR_INPUT,
142 /** Output (playing to a device). */
143 AUDMIXSINKDIR_OUTPUT,
144 /** The usual 32-bit hack. */
145 AUDMIXSINKDIR_32BIT_HACK = 0x7fffffff
146} AUDMIXSINKDIR;
147
148/**
149 * Audio mixer sink command.
150 */
151typedef enum AUDMIXSINKCMD
152{
153 /** Unknown command, do not use. */
154 AUDMIXSINKCMD_UNKNOWN = 0,
155 /** Enables the sink. */
156 AUDMIXSINKCMD_ENABLE,
157 /** Disables the sink. */
158 AUDMIXSINKCMD_DISABLE,
159 /** Pauses the sink. */
160 AUDMIXSINKCMD_PAUSE,
161 /** Resumes the sink. */
162 AUDMIXSINKCMD_RESUME,
163 /** Tells the sink's streams to drop all (buffered) data immediately. */
164 AUDMIXSINKCMD_DROP,
165 /** Hack to blow the type up to 32-bit. */
166 AUDMIXSINKCMD_32BIT_HACK = 0x7fffffff
167} AUDMIXSINKCMD;
168
169/**
170 * Audio input sink specifics.
171 *
172 * Do not use directly. Instead, use AUDMIXSINK.
173 */
174typedef struct AUDMIXSINKIN
175{
176 /** The current recording source. Can be NULL if not set. */
177 PAUDMIXSTREAM pStreamRecSource;
178} AUDMIXSINKIN;
179
180/**
181 * Audio output sink specifics.
182 *
183 * Do not use directly. Instead, use AUDMIXSINK.
184 */
185typedef struct AUDMIXSINKOUT
186{
187} AUDMIXSINKOUT;
188
189/**
190 * Audio mixer sink.
191 */
192typedef struct AUDMIXSINK
193{
194 RTLISTNODE Node;
195 /** Pointer to mixer object this sink is bound to. */
196 PAUDIOMIXER pParent;
197 /** Name of this sink. */
198 char *pszName;
199 /** The sink direction, that is,
200 * if this sink handles input or output. */
201 AUDMIXSINKDIR enmDir;
202 /** The sink's critical section. */
203 RTCRITSECT CritSect;
204 /** This sink's mixing buffer, acting as
205 * a parent buffer for all streams this sink owns. */
206 AUDIOMIXBUF MixBuf;
207 /** Scratch buffer for multiplexing / mixing. Might be NULL if not needed. */
208 uint8_t *pabScratchBuf;
209 /** Size (in bytes) of pabScratchBuf. Might be 0 if not needed. */
210 size_t cbScratchBuf;
211 /** Union for input/output specifics. */
212 union
213 {
214 AUDMIXSINKIN In;
215 AUDMIXSINKOUT Out;
216 };
217 /** Sink status of type AUDMIXSINK_STS_XXX. */
218 AUDMIXSINKSTS fStatus;
219 /** The sink's PCM format. */
220 PDMAUDIOPCMPROPS PCMProps;
221 /** Number of streams assigned. */
222 uint8_t cStreams;
223 /** List of assigned streams.
224 * @note All streams have the same PCM properties, so the mixer does not do
225 * any conversion. */
226 /** @todo Use something faster -- vector maybe? */
227 RTLISTANCHOR lstStreams;
228 /** The volume of this sink. The volume always will
229 * be combined with the mixer's master volume. */
230 PDMAUDIOVOLUME Volume;
231 /** The volume of this sink, combined with the last set master volume. */
232 PDMAUDIOVOLUME VolumeCombined;
233 /** Timestamp since last update (in ms). */
234 uint64_t tsLastUpdatedMs;
235 /** Last read (recording) / written (playback) timestamp (in ns). */
236 uint64_t tsLastReadWrittenNs;
237 struct
238 {
239 PAUDIOHLPFILE pFile;
240 } Dbg;
241} AUDMIXSINK;
242
243/**
244 * Audio mixer operation.
245 */
246typedef enum AUDMIXOP
247{
248 /** Invalid operation, do not use. */
249 AUDMIXOP_INVALID = 0,
250 /** Copy data from A to B, overwriting data in B. */
251 AUDMIXOP_COPY,
252 /** Blend data from A with (existing) data in B. */
253 AUDMIXOP_BLEND,
254 /** The usual 32-bit hack. */
255 AUDMIXOP_32BIT_HACK = 0x7fffffff
256} AUDMIXOP;
257
258/** No flags specified. */
259#define AUDMIXSTRMCTL_F_NONE 0
260
261/** No mixer flags specified. */
262#define AUDMIXER_FLAGS_NONE 0
263/** Debug mode enabled.
264 * This writes .WAV file to the host, usually to the temporary directory. */
265#define AUDMIXER_FLAGS_DEBUG RT_BIT(0)
266/** Validation mask. */
267#define AUDMIXER_FLAGS_VALID_MASK UINT32_C(0x00000001)
268
269int AudioMixerCreate(const char *pszName, uint32_t fFlags, PAUDIOMIXER *ppMixer);
270int AudioMixerCreateSink(PAUDIOMIXER pMixer, const char *pszName, AUDMIXSINKDIR enmDir, PPDMDEVINS pDevIns, PAUDMIXSINK *ppSink);
271void AudioMixerDestroy(PAUDIOMIXER pMixer, PPDMDEVINS pDevIns);
272void AudioMixerInvalidate(PAUDIOMIXER pMixer);
273void AudioMixerRemoveSink(PAUDIOMIXER pMixer, PAUDMIXSINK pSink);
274int AudioMixerSetMasterVolume(PAUDIOMIXER pMixer, PPDMAUDIOVOLUME pVol);
275void AudioMixerDebug(PAUDIOMIXER pMixer, PCDBGFINFOHLP pHlp, const char *pszArgs);
276
277int AudioMixerSinkAddStream(PAUDMIXSINK pSink, PAUDMIXSTREAM pStream);
278int AudioMixerSinkCreateStream(PAUDMIXSINK pSink, PPDMIAUDIOCONNECTOR pConnector, PPDMAUDIOSTREAMCFG pCfg,
279 AUDMIXSTREAMFLAGS fFlags, PPDMDEVINS pDevIns, PAUDMIXSTREAM *ppStream);
280int AudioMixerSinkCtl(PAUDMIXSINK pSink, AUDMIXSINKCMD enmCmd);
281void AudioMixerSinkDestroy(PAUDMIXSINK pSink, PPDMDEVINS pDevIns);
282uint32_t AudioMixerSinkGetReadable(PAUDMIXSINK pSink);
283uint32_t AudioMixerSinkGetWritable(PAUDMIXSINK pSink);
284AUDMIXSINKDIR AudioMixerSinkGetDir(PAUDMIXSINK pSink);
285const char *AudioMixerSinkGetName(const PAUDMIXSINK pSink);
286PAUDMIXSTREAM AudioMixerSinkGetRecordingSource(PAUDMIXSINK pSink);
287PAUDMIXSTREAM AudioMixerSinkGetStream(PAUDMIXSINK pSink, uint8_t uIndex);
288AUDMIXSINKSTS AudioMixerSinkGetStatus(PAUDMIXSINK pSink);
289uint8_t AudioMixerSinkGetStreamCount(PAUDMIXSINK pSink);
290bool AudioMixerSinkIsActive(PAUDMIXSINK pSink);
291int AudioMixerSinkRead(PAUDMIXSINK pSink, AUDMIXOP enmOp, void *pvBuf, uint32_t cbBuf, uint32_t *pcbRead);
292void AudioMixerSinkRemoveStream(PAUDMIXSINK pSink, PAUDMIXSTREAM pStream);
293void AudioMixerSinkRemoveAllStreams(PAUDMIXSINK pSink);
294void AudioMixerSinkReset(PAUDMIXSINK pSink);
295void AudioMixerSinkGetFormat(PAUDMIXSINK pSink, PPDMAUDIOPCMPROPS pPCMProps);
296int AudioMixerSinkSetFormat(PAUDMIXSINK pSink, PCPDMAUDIOPCMPROPS pPCMProps);
297int AudioMixerSinkSetRecordingSource(PAUDMIXSINK pSink, PAUDMIXSTREAM pStream);
298int AudioMixerSinkSetVolume(PAUDMIXSINK pSink, PPDMAUDIOVOLUME pVol);
299int AudioMixerSinkWrite(PAUDMIXSINK pSink, AUDMIXOP enmOp, const void *pvBuf, uint32_t cbBuf, uint32_t *pcbWritten);
300int AudioMixerSinkUpdate(PAUDMIXSINK pSink);
301
302int AudioMixerStreamCtl(PAUDMIXSTREAM pStream, PDMAUDIOSTREAMCMD enmCmd, uint32_t fCtl);
303void AudioMixerStreamDestroy(PAUDMIXSTREAM pStream, PPDMDEVINS pDevIns);
304bool AudioMixerStreamIsActive(PAUDMIXSTREAM pStream);
305bool AudioMixerStreamIsValid(PAUDMIXSTREAM pStream);
306
307#endif /* !VBOX_INCLUDED_SRC_Audio_AudioMixer_h */
308
Note: See TracBrowser for help on using the repository browser.

© 2025 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette