VirtualBox

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

Last change on this file since 76882 was 76777, checked in by vboxsync, 6 years ago

Audio/Mixer: Removed VBOX_AUDIO_MIXER_WITH_MIXBUF define, as this is the default anyway since quite a while.

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