VirtualBox

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

Last change on this file since 82406 was 82406, checked in by vboxsync, 5 years ago

DevHDA: Cleanups. bugref:9218

  • 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 82406 2019-12-05 00:47:02Z 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-2019 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
32
33/** Pointer to an audio mixer sink. */
34typedef struct AUDMIXSINK *PAUDMIXSINK;
35
36
37/**
38 * Audio mixer instance.
39 */
40typedef struct AUDIOMIXER
41{
42 /** The mixer's name. */
43 char *pszName;
44 /** The mixer's critical section. */
45 RTCRITSECT CritSect;
46 /** The master volume of this mixer. */
47 PDMAUDIOVOLUME VolMaster;
48 /** List of audio mixer sinks. */
49 RTLISTANCHOR lstSinks;
50 /** Number of used audio sinks. */
51 uint8_t cSinks;
52} AUDIOMIXER;
53/** Pointer to an audio mixer instance. */
54typedef AUDIOMIXER *PAUDIOMIXER;
55
56/** Defines an audio mixer stream's flags. */
57#define AUDMIXSTREAMFLAGS uint32_t
58
59/** No flags specified. */
60#define AUDMIXSTREAM_F_NONE 0
61/** The mixing stream is flagged as being enabled (active). */
62#define AUDMIXSTREAM_F_ENABLED RT_BIT(0)
63
64/** Defines an audio mixer stream's internal status. */
65#define AUDMIXSTREAMSTATUS uint32_t
66
67/** No status set. */
68#define AUDMIXSTREAM_STATUS_NONE 0
69/** The mixing stream is enabled (active). */
70#define AUDMIXSTREAM_STATUS_ENABLED RT_BIT(0)
71/** The mixing stream can be read from. */
72#define AUDMIXSTREAM_STATUS_CAN_READ RT_BIT(1)
73/** The mixing stream can be written to. */
74#define AUDMIXSTREAM_STATUS_CAN_WRITE RT_BIT(2)
75
76
77/**
78 * Audio mixer stream.
79 */
80typedef struct AUDMIXSTREAM
81{
82 /** List node. */
83 RTLISTNODE Node;
84 /** Name of this stream. */
85 char *pszName;
86 /** The streams's critical section. */
87 RTCRITSECT CritSect;
88 /** Sink this stream is attached to. */
89 PAUDMIXSINK pSink;
90 /** Stream flags of type AUDMIXSTREAM_F_. */
91 uint32_t fFlags;
92 /** Stream status of type AUDMIXSTREAM_STATUS_. */
93 uint32_t fStatus;
94 /** Pointer to audio connector being used. */
95 PPDMIAUDIOCONNECTOR pConn;
96 /** Pointer to PDM audio stream this mixer stream handles. */
97 PPDMAUDIOSTREAM pStream;
98 /** Last read (recording) / written (playback) timestamp (in ns). */
99 uint64_t tsLastReadWrittenNs;
100 /** The stream's circular buffer for temporarily
101 * holding (raw) device audio data. */
102 PRTCIRCBUF pCircBuf;
103} AUDMIXSTREAM, *PAUDMIXSTREAM;
104
105/** Defines an audio sink's current status. */
106#define AUDMIXSINKSTS uint32_t
107
108/** No status specified. */
109#define AUDMIXSINK_STS_NONE 0
110/** The sink is active and running. */
111#define AUDMIXSINK_STS_RUNNING RT_BIT(0)
112/** The sink is in a pending disable state. */
113#define AUDMIXSINK_STS_PENDING_DISABLE RT_BIT(1)
114/** Dirty flag.
115 * For output sinks this means that there is data in the
116 * sink which has not been played yet.
117 * For input sinks this means that there is data in the
118 * sink which has been recorded but not transferred to the
119 * destination yet. */
120#define AUDMIXSINK_STS_DIRTY RT_BIT(2)
121
122/**
123 * Audio mixer sink direction.
124 */
125typedef enum AUDMIXSINKDIR
126{
127 /** Unknown direction. */
128 AUDMIXSINKDIR_UNKNOWN = 0,
129 /** Input (capturing from a device). */
130 AUDMIXSINKDIR_INPUT,
131 /** Output (playing to a device). */
132 AUDMIXSINKDIR_OUTPUT,
133 /** The usual 32-bit hack. */
134 AUDMIXSINKDIR_32BIT_HACK = 0x7fffffff
135} AUDMIXSINKDIR;
136
137/**
138 * Audio mixer sink command.
139 */
140typedef enum AUDMIXSINKCMD
141{
142 /** Unknown command, do not use. */
143 AUDMIXSINKCMD_UNKNOWN = 0,
144 /** Enables the sink. */
145 AUDMIXSINKCMD_ENABLE,
146 /** Disables the sink. */
147 AUDMIXSINKCMD_DISABLE,
148 /** Pauses the sink. */
149 AUDMIXSINKCMD_PAUSE,
150 /** Resumes the sink. */
151 AUDMIXSINKCMD_RESUME,
152 /** Tells the sink's streams to drop all (buffered) data immediately. */
153 AUDMIXSINKCMD_DROP,
154 /** Hack to blow the type up to 32-bit. */
155 AUDMIXSINKCMD_32BIT_HACK = 0x7fffffff
156} AUDMIXSINKCMD;
157
158/**
159 * Audio input sink specifics.
160 *
161 * Do not use directly. Instead, use AUDMIXSINK.
162 */
163typedef struct AUDMIXSINKIN
164{
165 /** The current recording source. Can be NULL if not set. */
166 PAUDMIXSTREAM pStreamRecSource;
167} AUDMIXSINKIN;
168
169/**
170 * Audio output sink specifics.
171 *
172 * Do not use directly. Instead, use AUDMIXSINK.
173 */
174typedef struct AUDMIXSINKOUT
175{
176} AUDMIXSINKOUT;
177
178/**
179 * Audio mixer sink.
180 */
181typedef struct AUDMIXSINK
182{
183 RTLISTNODE Node;
184 /** Pointer to mixer object this sink is bound to. */
185 PAUDIOMIXER pParent;
186 /** Name of this sink. */
187 char *pszName;
188 /** The sink direction, that is,
189 * if this sink handles input or output. */
190 AUDMIXSINKDIR enmDir;
191 /** The sink's critical section. */
192 RTCRITSECT CritSect;
193 /** This sink's mixing buffer, acting as
194 * a parent buffer for all streams this sink owns. */
195 PDMAUDIOMIXBUF MixBuf;
196 /** Union for input/output specifics. */
197 union
198 {
199 AUDMIXSINKIN In;
200 AUDMIXSINKOUT Out;
201 };
202 /** Sink status of type AUDMIXSINK_STS_XXX. */
203 AUDMIXSINKSTS fStatus;
204 /** The sink's PCM format. */
205 PDMAUDIOPCMPROPS PCMProps;
206 /** Number of streams assigned. */
207 uint8_t cStreams;
208 /** List of assigned streams.
209 * Note: All streams have the same PCM properties, so the
210 * mixer does not do any conversion. */
211 /** @todo Use something faster -- vector maybe? */
212 RTLISTANCHOR lstStreams;
213 /** The volume of this sink. The volume always will
214 * be combined with the mixer's master volume. */
215 PDMAUDIOVOLUME Volume;
216 /** The volume of this sink, combined with the last set master volume. */
217 PDMAUDIOVOLUME VolumeCombined;
218 /** Timestamp since last update (in ms). */
219 uint64_t tsLastUpdatedMs;
220 /** Last read (recording) / written (playback) timestamp (in ns). */
221 uint64_t tsLastReadWrittenNs;
222#ifdef VBOX_AUDIO_MIXER_DEBUG
223 struct
224 {
225 PPDMAUDIOFILE pFile;
226 } Dbg;
227#endif
228} AUDMIXSINK;
229
230/**
231 * Audio mixer operation.
232 */
233typedef enum AUDMIXOP
234{
235 /** Invalid operation, do not use. */
236 AUDMIXOP_INVALID = 0,
237 /** Copy data from A to B, overwriting data in B. */
238 AUDMIXOP_COPY,
239 /** Blend data from A with (existing) data in B. */
240 AUDMIXOP_BLEND,
241 /** The usual 32-bit hack. */
242 AUDMIXOP_32BIT_HACK = 0x7fffffff
243} AUDMIXOP;
244
245/** No flags specified. */
246#define AUDMIXSTRMCTL_F_NONE 0
247
248int AudioMixerCreate(const char *pszName, uint32_t uFlags, PAUDIOMIXER *ppMixer);
249int AudioMixerCreateSink(PAUDIOMIXER pMixer, const char *pszName, AUDMIXSINKDIR enmDir, PAUDMIXSINK *ppSink);
250void AudioMixerDestroy(PAUDIOMIXER pMixer);
251void AudioMixerInvalidate(PAUDIOMIXER pMixer);
252void AudioMixerRemoveSink(PAUDIOMIXER pMixer, PAUDMIXSINK pSink);
253int AudioMixerSetMasterVolume(PAUDIOMIXER pMixer, PPDMAUDIOVOLUME pVol);
254void AudioMixerDebug(PAUDIOMIXER pMixer, PCDBGFINFOHLP pHlp, const char *pszArgs);
255
256int AudioMixerSinkAddStream(PAUDMIXSINK pSink, PAUDMIXSTREAM pStream);
257int AudioMixerSinkCreateStream(PAUDMIXSINK pSink, PPDMIAUDIOCONNECTOR pConnector, PPDMAUDIOSTREAMCFG pCfg, AUDMIXSTREAMFLAGS fFlags, PAUDMIXSTREAM *ppStream);
258int AudioMixerSinkCtl(PAUDMIXSINK pSink, AUDMIXSINKCMD enmCmd);
259void AudioMixerSinkDestroy(PAUDMIXSINK pSink);
260uint32_t AudioMixerSinkGetReadable(PAUDMIXSINK pSink);
261uint32_t AudioMixerSinkGetWritable(PAUDMIXSINK pSink);
262AUDMIXSINKDIR AudioMixerSinkGetDir(PAUDMIXSINK pSink);
263const char *AudioMixerSinkGetName(const PAUDMIXSINK pSink);
264PAUDMIXSTREAM AudioMixerSinkGetRecordingSource(PAUDMIXSINK pSink);
265PAUDMIXSTREAM AudioMixerSinkGetStream(PAUDMIXSINK pSink, uint8_t uIndex);
266AUDMIXSINKSTS AudioMixerSinkGetStatus(PAUDMIXSINK pSink);
267uint8_t AudioMixerSinkGetStreamCount(PAUDMIXSINK pSink);
268bool AudioMixerSinkIsActive(PAUDMIXSINK pSink);
269int AudioMixerSinkRead(PAUDMIXSINK pSink, AUDMIXOP enmOp, void *pvBuf, uint32_t cbBuf, uint32_t *pcbRead);
270void AudioMixerSinkRemoveStream(PAUDMIXSINK pSink, PAUDMIXSTREAM pStream);
271void AudioMixerSinkRemoveAllStreams(PAUDMIXSINK pSink);
272void AudioMixerSinkReset(PAUDMIXSINK pSink);
273void AudioMixerSinkGetFormat(PAUDMIXSINK pSink, PPDMAUDIOPCMPROPS pPCMProps);
274int AudioMixerSinkSetFormat(PAUDMIXSINK pSink, PPDMAUDIOPCMPROPS pPCMProps);
275int AudioMixerSinkSetRecordingSource(PAUDMIXSINK pSink, PAUDMIXSTREAM pStream);
276int AudioMixerSinkSetVolume(PAUDMIXSINK pSink, PPDMAUDIOVOLUME pVol);
277int AudioMixerSinkWrite(PAUDMIXSINK pSink, AUDMIXOP enmOp, const void *pvBuf, uint32_t cbBuf, uint32_t *pcbWritten);
278int AudioMixerSinkUpdate(PAUDMIXSINK pSink);
279
280int AudioMixerStreamCtl(PAUDMIXSTREAM pStream, PDMAUDIOSTREAMCMD enmCmd, uint32_t fCtl);
281void AudioMixerStreamDestroy(PAUDMIXSTREAM pStream);
282bool AudioMixerStreamIsActive(PAUDMIXSTREAM pStream);
283bool AudioMixerStreamIsValid(PAUDMIXSTREAM pStream);
284
285#endif /* !VBOX_INCLUDED_SRC_Audio_AudioMixer_h */
286
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