VirtualBox

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

Last change on this file since 61541 was 61523, 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: 7.0 KB
Line 
1/* $Id: AudioMixer.h 61523 2016-06-07 09:47:21Z 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 maintaining an audio mixer sink.
118 */
119typedef struct AUDMIXSINK
120{
121 RTLISTNODE Node;
122 /** Pointer to mixer object this sink is bound to. */
123 PAUDIOMIXER pParent;
124 /** Name of this sink. */
125 char *pszName;
126 /** The sink direction, that is,
127 * if this sink handles input or output. */
128 AUDMIXSINKDIR enmDir;
129 /** Sink status of type AUDMIXSINK_STS_XXX. */
130 AUDMIXSINKSTS fStatus;
131 /** The sink's PCM format. */
132 PDMPCMPROPS PCMProps;
133 /** Number of streams assigned. */
134 uint8_t cStreams;
135 /** List of assigned streams.
136 * Note: All streams have the same PCM properties, so the
137 * mixer does not do any conversion. */
138 /** @todo Use something faster -- vector maybe? */
139 RTLISTANCHOR lstStreams;
140#ifdef VBOX_AUDIO_MIXER_WITH_MIXBUF
141 /** This sink's mixing buffer, acting as
142 * a parent buffer for all streams this sink owns. */
143 PDMAUDIOMIXBUF MixBuf;
144#endif
145 /** The volume of this sink. The volume always will
146 * be combined with the mixer's master volume. */
147 PDMAUDIOVOLUME Volume;
148} AUDMIXSINK, *PAUDMIXSINK;
149
150/**
151 * Audio mixer operation.
152 */
153typedef enum AUDMIXOP
154{
155 /** Invalid operation, do not use. */
156 AUDMIXOP_INVALID = 0,
157 AUDMIXOP_COPY,
158 AUDMIXOP_BLEND,
159 /** The usual 32-bit hack. */
160 AUDMIXOP_32BIT_HACK = 0x7fffffff
161} AUDMIXOP;
162
163/** No flags specified. */
164#define AUDMIXSTRMCTL_FLAG_NONE 0
165
166int AudioMixerCreate(const char *pszName, uint32_t uFlags, PAUDIOMIXER *ppMixer);
167int AudioMixerCreateSink(PAUDIOMIXER pMixer, const char *pszName, AUDMIXSINKDIR enmDir, PAUDMIXSINK *ppSink);
168void AudioMixerDestroy(PAUDIOMIXER pMixer);
169int AudioMixerGetDeviceFormat(PAUDIOMIXER pMixer, PPDMAUDIOSTREAMCFG pCfg);
170void AudioMixerInvalidate(PAUDIOMIXER pMixer);
171void AudioMixerRemoveSink(PAUDIOMIXER pMixer, PAUDMIXSINK pSink);
172int AudioMixerSetDeviceFormat(PAUDIOMIXER pMixer, PPDMAUDIOSTREAMCFG pCfg);
173int AudioMixerSetMasterVolume(PAUDIOMIXER pMixer, PPDMAUDIOVOLUME pVol);
174void AudioMixerDebug(PAUDIOMIXER pMixer, PCDBGFINFOHLP pHlp, const char *pszArgs);
175
176int AudioMixerSinkAddStream(PAUDMIXSINK pSink, PAUDMIXSTREAM pStream);
177int AudioMixerSinkCreateStream(PAUDMIXSINK pSink, PPDMIAUDIOCONNECTOR pConnector, PPDMAUDIOSTREAMCFG pCfg, uint32_t fFlags, PAUDMIXSTREAM *ppStream);
178int AudioMixerSinkCtl(PAUDMIXSINK pSink, AUDMIXSINKCMD enmCmd);
179void AudioMixerSinkDestroy(PAUDMIXSINK pSink);
180AUDMIXSINKDIR AudioMixerSinkGetDir(PAUDMIXSINK pSink);
181PAUDMIXSTREAM AudioMixerSinkGetStream(PAUDMIXSINK pSink, uint8_t uIndex);
182AUDMIXSINKSTS AudioMixerSinkGetStatus(PAUDMIXSINK pSink);
183uint8_t AudioMixerSinkGetStreamCount(PAUDMIXSINK pSink);
184int AudioMixerSinkRead(PAUDMIXSINK pSink, AUDMIXOP enmOp, void *pvBuf, uint32_t cbBuf, uint32_t *pcbRead);
185void AudioMixerSinkRemoveStream(PAUDMIXSINK pSink, PAUDMIXSTREAM pStream);
186void AudioMixerSinkRemoveAllStreams(PAUDMIXSINK pSink);
187int AudioMixerSinkSetFormat(PAUDMIXSINK pSink, PPDMPCMPROPS pPCMProps);
188int AudioMixerSinkSetVolume(PAUDMIXSINK pSink, PPDMAUDIOVOLUME pVol);
189void AudioMixerSinkTimerUpdate(PAUDMIXSINK pSink, uint64_t cTimerTicks, uint64_t cTicksElapsed);
190int AudioMixerSinkWrite(PAUDMIXSINK pSink, AUDMIXOP enmOp, const void *pvBuf, uint32_t cbBuf, uint32_t *pcbWritten);
191int AudioMixerSinkUpdate(PAUDMIXSINK pSink);
192
193int AudioMixerStreamCtl(PAUDMIXSTREAM pStream, PDMAUDIOSTREAMCMD enmCmd, uint32_t fCtl);
194void AudioMixerStreamDestroy(PAUDMIXSTREAM pStream);
195bool AudioMixerStreamIsActive(PAUDMIXSTREAM pStream);
196bool AudioMixerStreamIsValid(PAUDMIXSTREAM pStream);
197
198#endif /* AUDIO_MIXER_H */
199
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