VirtualBox

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

Last change on this file since 61648 was 61609, checked in by vboxsync, 9 years ago

Audio: Update.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 8.0 KB
Line 
1/* $Id: AudioMixer.h 61609 2016-06-09 10:22:39Z 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 */
29typedef 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. */
49typedef struct AUDMIXSINK *PAUDMIXSINK;
50
51/**
52 * Structure for maintaining an audio mixer stream.
53 */
54typedef 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/** Defines an audio sink's current status. */
71#define AUDMIXSINKSTS uint32_t
72
73/** No status specified. */
74#define AUDMIXSINK_STS_NONE 0
75/** The sink is active and running. */
76#define AUDMIXSINK_STS_RUNNING RT_BIT(0)
77/** Dirty flag.
78 * For output sinks this means that there is data in the
79 * sink which has not been played yet.
80 * For input sinks this means that there is data in the
81 * sink which has been recorded but not transferred to the
82 * destination yet. */
83#define AUDMIXSINK_STS_DIRTY RT_BIT(1)
84
85/**
86 * Audio mixer sink direction.
87 */
88typedef enum AUDMIXSINKDIR
89{
90 AUDMIXSINKDIR_UNKNOWN = 0,
91 AUDMIXSINKDIR_INPUT,
92 AUDMIXSINKDIR_OUTPUT,
93 /** The usual 32-bit hack. */
94 AUDMIXSINKDIR_32BIT_HACK = 0x7fffffff
95} AUDMIXSINKDIR;
96
97/**
98 * Audio mixer sink command.
99 */
100typedef enum AUDMIXSINKCMD
101{
102 /** Unknown command, do not use. */
103 AUDMIXSINKCMD_UNKNOWN = 0,
104 /** Enables the sink. */
105 AUDMIXSINKCMD_ENABLE,
106 /** Disables the sink. */
107 AUDMIXSINKCMD_DISABLE,
108 /** Pauses the sink. */
109 AUDMIXSINKCMD_PAUSE,
110 /** Resumes the sink. */
111 AUDMIXSINKCMD_RESUME,
112 /** Hack to blow the type up to 32-bit. */
113 AUDMIXSINKCMD_32BIT_HACK = 0x7fffffff
114} AUDMIXSINKCMD;
115
116/**
117 * Structure for keeping audio input sink specifics.
118 * Do not use directly. Instead, use AUDMIXSINK.
119 */
120typedef struct AUDMIXSINKIN
121{
122#ifdef VBOX_AUDIO_MIXER_WITH_MIXBUF
123 /** This sink's mixing buffer, acting as
124 * a parent buffer for all streams this sink owns. */
125 PDMAUDIOMIXBUF MixBuf;
126#else
127 /** Number of bytes available to read from the sink. */
128 uint32_t cbReadable;
129#endif
130} AUDMIXSINKIN;
131
132/**
133 * Structure for keeping audio output sink specifics.
134 * Do not use directly. Instead, use AUDMIXSINK.
135 */
136typedef struct AUDMIXSINKOUT
137{
138#ifdef VBOX_AUDIO_MIXER_WITH_MIXBUF
139 /** This sink's mixing buffer, acting as
140 * a parent buffer for all streams this sink owns. */
141 PDMAUDIOMIXBUF MixBuf;
142#else
143 /** Number of bytes available to write to the sink. */
144 uint32_t cbWritable;
145#endif
146} AUDMIXSINKOUT;
147
148/**
149 * Structure for maintaining an audio mixer sink.
150 */
151typedef struct AUDMIXSINK
152{
153 RTLISTNODE Node;
154 /** Pointer to mixer object this sink is bound to. */
155 PAUDIOMIXER pParent;
156 /** Name of this sink. */
157 char *pszName;
158 /** The sink direction, that is,
159 * if this sink handles input or output. */
160 AUDMIXSINKDIR enmDir;
161 /** Union for input/output specifics. */
162 union
163 {
164 AUDMIXSINKIN In;
165 AUDMIXSINKOUT Out;
166 };
167 /** Sink status of type AUDMIXSINK_STS_XXX. */
168 AUDMIXSINKSTS fStatus;
169 /** The sink's PCM format. */
170 PDMPCMPROPS PCMProps;
171 /** Number of streams assigned. */
172 uint8_t cStreams;
173 /** List of assigned streams.
174 * Note: All streams have the same PCM properties, so the
175 * mixer does not do any conversion. */
176 /** @todo Use something faster -- vector maybe? */
177 RTLISTANCHOR lstStreams;
178 /** The volume of this sink. The volume always will
179 * be combined with the mixer's master volume. */
180 PDMAUDIOVOLUME Volume;
181 /** Timestamp (in ns) since last update. */
182 uint64_t tsLastUpdatedNS;
183} AUDMIXSINK, *PAUDMIXSINK;
184
185/**
186 * Audio mixer operation.
187 */
188typedef enum AUDMIXOP
189{
190 /** Invalid operation, do not use. */
191 AUDMIXOP_INVALID = 0,
192 AUDMIXOP_COPY,
193 AUDMIXOP_BLEND,
194 /** The usual 32-bit hack. */
195 AUDMIXOP_32BIT_HACK = 0x7fffffff
196} AUDMIXOP;
197
198/** No flags specified. */
199#define AUDMIXSTRMCTL_FLAG_NONE 0
200
201int AudioMixerCreate(const char *pszName, uint32_t uFlags, PAUDIOMIXER *ppMixer);
202int AudioMixerCreateSink(PAUDIOMIXER pMixer, const char *pszName, AUDMIXSINKDIR enmDir, PAUDMIXSINK *ppSink);
203void AudioMixerDestroy(PAUDIOMIXER pMixer);
204int AudioMixerGetDeviceFormat(PAUDIOMIXER pMixer, PPDMAUDIOSTREAMCFG pCfg);
205void AudioMixerInvalidate(PAUDIOMIXER pMixer);
206void AudioMixerRemoveSink(PAUDIOMIXER pMixer, PAUDMIXSINK pSink);
207int AudioMixerSetDeviceFormat(PAUDIOMIXER pMixer, PPDMAUDIOSTREAMCFG pCfg);
208int AudioMixerSetMasterVolume(PAUDIOMIXER pMixer, PPDMAUDIOVOLUME pVol);
209void AudioMixerDebug(PAUDIOMIXER pMixer, PCDBGFINFOHLP pHlp, const char *pszArgs);
210
211int AudioMixerSinkAddStream(PAUDMIXSINK pSink, PAUDMIXSTREAM pStream);
212int AudioMixerSinkCreateStream(PAUDMIXSINK pSink, PPDMIAUDIOCONNECTOR pConnector, PPDMAUDIOSTREAMCFG pCfg, uint32_t fFlags, PAUDMIXSTREAM *ppStream);
213int AudioMixerSinkCtl(PAUDMIXSINK pSink, AUDMIXSINKCMD enmCmd);
214void AudioMixerSinkDestroy(PAUDMIXSINK pSink);
215uint32_t AudioMixerSinkGetReadable(PAUDMIXSINK pSink);
216uint32_t AudioMixerSinkGetWritable(PAUDMIXSINK pSink);
217AUDMIXSINKDIR AudioMixerSinkGetDir(PAUDMIXSINK pSink);
218PAUDMIXSTREAM AudioMixerSinkGetStream(PAUDMIXSINK pSink, uint8_t uIndex);
219AUDMIXSINKSTS AudioMixerSinkGetStatus(PAUDMIXSINK pSink);
220uint8_t AudioMixerSinkGetStreamCount(PAUDMIXSINK pSink);
221int AudioMixerSinkRead(PAUDMIXSINK pSink, AUDMIXOP enmOp, void *pvBuf, uint32_t cbBuf, uint32_t *pcbRead);
222void AudioMixerSinkRemoveStream(PAUDMIXSINK pSink, PAUDMIXSTREAM pStream);
223void AudioMixerSinkRemoveAllStreams(PAUDMIXSINK pSink);
224int AudioMixerSinkSetFormat(PAUDMIXSINK pSink, PPDMPCMPROPS pPCMProps);
225int AudioMixerSinkSetVolume(PAUDMIXSINK pSink, PPDMAUDIOVOLUME pVol);
226void AudioMixerSinkTimerUpdate(PAUDMIXSINK pSink, uint64_t cTimerTicks, uint64_t cTicksElapsed, uint32_t *pcbToProcess);
227int AudioMixerSinkWrite(PAUDMIXSINK pSink, AUDMIXOP enmOp, const void *pvBuf, uint32_t cbBuf, uint32_t *pcbWritten);
228int AudioMixerSinkUpdate(PAUDMIXSINK pSink);
229
230int AudioMixerStreamCtl(PAUDMIXSTREAM pStream, PDMAUDIOSTREAMCMD enmCmd, uint32_t fCtl);
231void AudioMixerStreamDestroy(PAUDMIXSTREAM pStream);
232bool AudioMixerStreamIsActive(PAUDMIXSTREAM pStream);
233bool AudioMixerStreamIsValid(PAUDMIXSTREAM pStream);
234
235#endif /* AUDIO_MIXER_H */
236
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