VirtualBox

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

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

Audio: Eliminated AUDMIXSINKDIR and AUDMIXSINKCMD, using PDMAUDIODIR and PDMAUDIOSTREAMCMD instead. bugref:9890

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 9.7 KB
Line 
1/* $Id: AudioMixer.h 88916 2021-05-06 19:55:49Z 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/** @name AUDMIXSTREAM_STATUS_XXX - mixer stream status.
73 * (This is a destilled version of PDMAUDIOSTREAM_STS_XXX.)
74 * @{ */
75/** No status set. */
76#define AUDMIXSTREAM_STATUS_NONE 0
77/** The mixing stream is enabled (active). */
78#define AUDMIXSTREAM_STATUS_ENABLED RT_BIT(0)
79/** The mixing stream can be read from.
80 * Always set together with AUDMIXSTREAM_STATUS_ENABLED. */
81#define AUDMIXSTREAM_STATUS_CAN_READ RT_BIT(1)
82/** The mixing stream can be written to.
83 * Always set together with AUDMIXSTREAM_STATUS_ENABLED. */
84#define AUDMIXSTREAM_STATUS_CAN_WRITE RT_BIT(2)
85/** @} */
86
87
88/**
89 * Audio mixer stream.
90 */
91typedef struct AUDMIXSTREAM
92{
93 /** List node. */
94 RTLISTNODE Node;
95 /** Name of this stream. */
96 char *pszName;
97 /** The statistics prefix. */
98 char *pszStatPrefix;
99 /** Sink this stream is attached to. */
100 PAUDMIXSINK pSink;
101 /** Stream flags of type AUDMIXSTREAM_F_. */
102 uint32_t fFlags;
103 /** Stream status of type AUDMIXSTREAM_STATUS_. */
104 uint32_t fStatus;
105 /** Number of writable/readable frames the last time we checked. */
106 uint32_t cFramesLastAvail;
107 /** Set if the stream has been found unreliable wrt. consuming/producing
108 * samples, and that we shouldn't consider it when deciding how much to move
109 * from the mixer buffer and to the drivers. */
110 bool fUnreliable;
111 /** Pointer to audio connector being used. */
112 PPDMIAUDIOCONNECTOR pConn;
113 /** Pointer to PDM audio stream this mixer stream handles. */
114 PPDMAUDIOSTREAM pStream;
115 /** Mixing buffer peeking state & config. */
116 AUDIOMIXBUFPEEKSTATE PeekState;
117 /** Last read (recording) / written (playback) timestamp (in ns). */
118 uint64_t tsLastReadWrittenNs;
119 /** The streams's critical section. */
120 RTCRITSECT CritSect;
121} AUDMIXSTREAM, *PAUDMIXSTREAM;
122
123/** Defines an audio sink's current status. */
124#define AUDMIXSINKSTS uint32_t
125
126/** No status specified. */
127#define AUDMIXSINK_STS_NONE 0
128/** The sink is active and running. */
129#define AUDMIXSINK_STS_RUNNING RT_BIT(0)
130/** The sink is in a pending disable state. */
131#define AUDMIXSINK_STS_PENDING_DISABLE RT_BIT(1)
132/** Dirty flag.
133 * - For output sinks this means that there is data in the sink which has not
134 * been played yet.
135 * - For input sinks this means that there is data in the sink which has been
136 * recorded but not transferred to the destination yet. */
137#define AUDMIXSINK_STS_DIRTY RT_BIT(2)
138
139/**
140 * Audio input sink specifics.
141 *
142 * Do not use directly. Instead, use AUDMIXSINK.
143 */
144typedef struct AUDMIXSINKIN
145{
146 /** The current recording source. Can be NULL if not set. */
147 PAUDMIXSTREAM pStreamRecSource;
148} AUDMIXSINKIN;
149
150/**
151 * Audio output sink specifics.
152 *
153 * Do not use directly. Instead, use AUDMIXSINK.
154 */
155typedef struct AUDMIXSINKOUT
156{
157} AUDMIXSINKOUT;
158
159/**
160 * Audio mixer sink.
161 */
162typedef struct AUDMIXSINK
163{
164 RTLISTNODE Node;
165 /** Pointer to mixer object this sink is bound to. */
166 PAUDIOMIXER pParent;
167 /** Name of this sink. */
168 char *pszName;
169 /** The sink direction (either PDMAUDIODIR_IN or PDMAUDIODIR_OUT). */
170 PDMAUDIODIR enmDir;
171 /** The sink's critical section. */
172 RTCRITSECT CritSect;
173 /** This sink's mixing buffer, acting as
174 * a parent buffer for all streams this sink owns. */
175 AUDIOMIXBUF MixBuf;
176 /** Scratch buffer for multiplexing / mixing. Might be NULL if not needed. */
177 uint8_t *pabScratchBuf;
178 /** Size (in bytes) of pabScratchBuf. Might be 0 if not needed. */
179 size_t cbScratchBuf;
180 /** Union for input/output specifics. */
181 union
182 {
183 AUDMIXSINKIN In;
184 AUDMIXSINKOUT Out;
185 };
186 /** Sink status of type AUDMIXSINK_STS_XXX. */
187 AUDMIXSINKSTS fStatus;
188 /** The sink's PCM format. */
189 PDMAUDIOPCMPROPS PCMProps;
190 /** Number of streams assigned. */
191 uint8_t cStreams;
192 /** List of assigned streams.
193 * @note All streams have the same PCM properties, so the mixer does not do
194 * any conversion. */
195 /** @todo Use something faster -- vector maybe? */
196 RTLISTANCHOR lstStreams;
197 /** The volume of this sink. The volume always will
198 * be combined with the mixer's master volume. */
199 PDMAUDIOVOLUME Volume;
200 /** The volume of this sink, combined with the last set master volume. */
201 PDMAUDIOVOLUME VolumeCombined;
202 /** Timestamp since last update (in ms). */
203 uint64_t tsLastUpdatedMs;
204 /** Last read (recording) / written (playback) timestamp (in ns). */
205 uint64_t tsLastReadWrittenNs;
206 struct
207 {
208 PAUDIOHLPFILE pFile;
209 } Dbg;
210} AUDMIXSINK;
211
212/**
213 * Audio mixer operation.
214 */
215typedef enum AUDMIXOP
216{
217 /** Invalid operation, do not use. */
218 AUDMIXOP_INVALID = 0,
219 /** Copy data from A to B, overwriting data in B. */
220 AUDMIXOP_COPY,
221 /** Blend data from A with (existing) data in B. */
222 AUDMIXOP_BLEND,
223 /** The usual 32-bit hack. */
224 AUDMIXOP_32BIT_HACK = 0x7fffffff
225} AUDMIXOP;
226
227/** No mixer flags specified. */
228#define AUDMIXER_FLAGS_NONE 0
229/** Debug mode enabled.
230 * This writes .WAV file to the host, usually to the temporary directory. */
231#define AUDMIXER_FLAGS_DEBUG RT_BIT(0)
232/** Validation mask. */
233#define AUDMIXER_FLAGS_VALID_MASK UINT32_C(0x00000001)
234
235int AudioMixerCreate(const char *pszName, uint32_t fFlags, PAUDIOMIXER *ppMixer);
236int AudioMixerCreateSink(PAUDIOMIXER pMixer, const char *pszName, PDMAUDIODIR enmDir, PPDMDEVINS pDevIns, PAUDMIXSINK *ppSink);
237void AudioMixerDestroy(PAUDIOMIXER pMixer, PPDMDEVINS pDevIns);
238void AudioMixerInvalidate(PAUDIOMIXER pMixer);
239int AudioMixerSetMasterVolume(PAUDIOMIXER pMixer, PPDMAUDIOVOLUME pVol);
240void AudioMixerDebug(PAUDIOMIXER pMixer, PCDBGFINFOHLP pHlp, const char *pszArgs);
241
242int AudioMixerSinkAddStream(PAUDMIXSINK pSink, PAUDMIXSTREAM pStream);
243int AudioMixerSinkCreateStream(PAUDMIXSINK pSink, PPDMIAUDIOCONNECTOR pConnector, PPDMAUDIOSTREAMCFG pCfg,
244 AUDMIXSTREAMFLAGS fFlags, PPDMDEVINS pDevIns, PAUDMIXSTREAM *ppStream);
245int AudioMixerSinkCtl(PAUDMIXSINK pSink, PDMAUDIOSTREAMCMD enmCmd);
246void AudioMixerSinkDestroy(PAUDMIXSINK pSink, PPDMDEVINS pDevIns);
247uint32_t AudioMixerSinkGetReadable(PAUDMIXSINK pSink);
248uint32_t AudioMixerSinkGetWritable(PAUDMIXSINK pSink);
249PDMAUDIODIR AudioMixerSinkGetDir(PAUDMIXSINK pSink);
250PAUDMIXSTREAM AudioMixerSinkGetRecordingSource(PAUDMIXSINK pSink);
251AUDMIXSINKSTS AudioMixerSinkGetStatus(PAUDMIXSINK pSink);
252bool AudioMixerSinkIsActive(PAUDMIXSINK pSink);
253int AudioMixerSinkRead(PAUDMIXSINK pSink, AUDMIXOP enmOp, void *pvBuf, uint32_t cbBuf, uint32_t *pcbRead);
254void AudioMixerSinkRemoveStream(PAUDMIXSINK pSink, PAUDMIXSTREAM pStream);
255void AudioMixerSinkRemoveAllStreams(PAUDMIXSINK pSink);
256void AudioMixerSinkReset(PAUDMIXSINK pSink);
257int AudioMixerSinkSetFormat(PAUDMIXSINK pSink, PCPDMAUDIOPCMPROPS pPCMProps);
258int AudioMixerSinkSetRecordingSource(PAUDMIXSINK pSink, PAUDMIXSTREAM pStream);
259int AudioMixerSinkSetVolume(PAUDMIXSINK pSink, PPDMAUDIOVOLUME pVol);
260int AudioMixerSinkWrite(PAUDMIXSINK pSink, AUDMIXOP enmOp, const void *pvBuf, uint32_t cbBuf, uint32_t *pcbWritten);
261int AudioMixerSinkUpdate(PAUDMIXSINK pSink);
262
263void AudioMixerStreamDestroy(PAUDMIXSTREAM pStream, PPDMDEVINS pDevIns);
264
265#endif /* !VBOX_INCLUDED_SRC_Audio_AudioMixer_h */
266
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