1 | /* $Id: DrvAudio.h 73220 2018-07-18 16:37:46Z vboxsync $ */
|
---|
2 | /** @file
|
---|
3 | * Intermediate audio driver header.
|
---|
4 | */
|
---|
5 |
|
---|
6 | /*
|
---|
7 | * Copyright (C) 2006-2018 Oracle Corporation
|
---|
8 | *
|
---|
9 | * This file is part of VirtualBox Open Source Edition (OSE), as
|
---|
10 | * available from http://www.virtualbox.org. This file is free software;
|
---|
11 | * you can redistribute it and/or modify it under the terms of the GNU
|
---|
12 | * General Public License (GPL) as published by the Free Software
|
---|
13 | * Foundation, in version 2 as it comes in the "COPYING" file of the
|
---|
14 | * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
|
---|
15 | * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
|
---|
16 | */
|
---|
17 |
|
---|
18 | #ifndef DRV_AUDIO_H
|
---|
19 | #define DRV_AUDIO_H
|
---|
20 |
|
---|
21 | #include <limits.h>
|
---|
22 |
|
---|
23 | #include <iprt/circbuf.h>
|
---|
24 | #include <iprt/critsect.h>
|
---|
25 | #include <iprt/file.h>
|
---|
26 | #include <iprt/path.h>
|
---|
27 |
|
---|
28 | #include <VBox/vmm/pdmdev.h>
|
---|
29 | #include <VBox/vmm/pdm.h>
|
---|
30 | #include <VBox/vmm/pdmaudioifs.h>
|
---|
31 |
|
---|
32 | typedef enum
|
---|
33 | {
|
---|
34 | AUD_OPT_INT,
|
---|
35 | AUD_OPT_FMT,
|
---|
36 | AUD_OPT_STR,
|
---|
37 | AUD_OPT_BOOL
|
---|
38 | } audio_option_tag_e;
|
---|
39 |
|
---|
40 | typedef struct audio_option
|
---|
41 | {
|
---|
42 | const char *name;
|
---|
43 | audio_option_tag_e tag;
|
---|
44 | void *valp;
|
---|
45 | const char *descr;
|
---|
46 | int *overridenp;
|
---|
47 | int overriden;
|
---|
48 | } audio_option;
|
---|
49 |
|
---|
50 | #ifdef VBOX_WITH_STATISTICS
|
---|
51 | /**
|
---|
52 | * Structure for keeping stream statistics for the
|
---|
53 | * statistic manager (STAM).
|
---|
54 | */
|
---|
55 | typedef struct DRVAUDIOSTATS
|
---|
56 | {
|
---|
57 | STAMCOUNTER TotalStreamsActive;
|
---|
58 | STAMCOUNTER TotalStreamsCreated;
|
---|
59 | STAMCOUNTER TotalFramesRead;
|
---|
60 | STAMCOUNTER TotalFramesWritten;
|
---|
61 | STAMCOUNTER TotalFramesMixedIn;
|
---|
62 | STAMCOUNTER TotalFramesMixedOut;
|
---|
63 | STAMCOUNTER TotalFramesLostIn;
|
---|
64 | STAMCOUNTER TotalFramesLostOut;
|
---|
65 | STAMCOUNTER TotalFramesOut;
|
---|
66 | STAMCOUNTER TotalFramesIn;
|
---|
67 | STAMCOUNTER TotalBytesRead;
|
---|
68 | STAMCOUNTER TotalBytesWritten;
|
---|
69 | /** How much delay (in ms) for input processing. */
|
---|
70 | STAMPROFILEADV DelayIn;
|
---|
71 | /** How much delay (in ms) for output processing. */
|
---|
72 | STAMPROFILEADV DelayOut;
|
---|
73 | } DRVAUDIOSTATS, *PDRVAUDIOSTATS;
|
---|
74 | #endif
|
---|
75 |
|
---|
76 | /**
|
---|
77 | * Audio driver instance data.
|
---|
78 | *
|
---|
79 | * @implements PDMIAUDIOCONNECTOR
|
---|
80 | */
|
---|
81 | typedef struct DRVAUDIO
|
---|
82 | {
|
---|
83 | /** Friendly name of the driver. */
|
---|
84 | char szName[64];
|
---|
85 | /** Critical section for serializing access. */
|
---|
86 | RTCRITSECT CritSect;
|
---|
87 | /** Shutdown indicator. */
|
---|
88 | bool fTerminate;
|
---|
89 | /** Our audio connector interface. */
|
---|
90 | PDMIAUDIOCONNECTOR IAudioConnector;
|
---|
91 | /** Pointer to the driver instance. */
|
---|
92 | PPDMDRVINS pDrvIns;
|
---|
93 | /** Pointer to audio driver below us. */
|
---|
94 | PPDMIHOSTAUDIO pHostDrvAudio;
|
---|
95 | /** Pointer to CFGM configuration node of this driver. */
|
---|
96 | PCFGMNODE pCFGMNode;
|
---|
97 | /** List of host input/output audio streams. */
|
---|
98 | RTLISTANCHOR lstHstStreams;
|
---|
99 | /** List of guest input/output audio streams. */
|
---|
100 | RTLISTANCHOR lstGstStreams;
|
---|
101 | #ifdef VBOX_WITH_AUDIO_ENUM
|
---|
102 | /** Flag indicating to perform an (re-)enumeration of the host audio devices. */
|
---|
103 | bool fEnumerateDevices;
|
---|
104 | #endif
|
---|
105 | /** Audio configuration settings retrieved from the backend. */
|
---|
106 | PDMAUDIOBACKENDCFG BackendCfg;
|
---|
107 | #ifdef VBOX_WITH_STATISTICS
|
---|
108 | /** Statistics for the statistics manager (STAM). */
|
---|
109 | DRVAUDIOSTATS Stats;
|
---|
110 | #endif
|
---|
111 | struct
|
---|
112 | {
|
---|
113 | /** Whether this driver's input streams are enabled or not.
|
---|
114 | * This flag overrides all the attached stream statuses. */
|
---|
115 | bool fEnabled;
|
---|
116 | /** Max. number of free input streams.
|
---|
117 | * UINT32_MAX for unlimited streams. */
|
---|
118 | uint32_t cStreamsFree;
|
---|
119 | #ifdef VBOX_WITH_AUDIO_CALLBACKS
|
---|
120 | RTLISTANCHOR lstCB;
|
---|
121 | #endif
|
---|
122 | } In;
|
---|
123 | struct
|
---|
124 | {
|
---|
125 | /** Whether this driver's output streams are enabled or not.
|
---|
126 | * This flag overrides all the attached stream statuses. */
|
---|
127 | bool fEnabled;
|
---|
128 | /** Max. number of free output streams.
|
---|
129 | * UINT32_MAX for unlimited streams. */
|
---|
130 | uint32_t cStreamsFree;
|
---|
131 | #ifdef VBOX_WITH_AUDIO_CALLBACKS
|
---|
132 | RTLISTANCHOR lstCB;
|
---|
133 | #endif
|
---|
134 | } Out;
|
---|
135 | struct
|
---|
136 | {
|
---|
137 | /** Whether audio debugging is enabled or not. */
|
---|
138 | bool fEnabled;
|
---|
139 | /** Where to store the debugging files.
|
---|
140 | * Defaults to VBOX_AUDIO_DEBUG_DUMP_PCM_DATA_PATH if not set. */
|
---|
141 | char szPathOut[RTPATH_MAX + 1];
|
---|
142 | } Dbg;
|
---|
143 | } DRVAUDIO, *PDRVAUDIO;
|
---|
144 |
|
---|
145 | /** Makes a PDRVAUDIO out of a PPDMIAUDIOCONNECTOR. */
|
---|
146 | #define PDMIAUDIOCONNECTOR_2_DRVAUDIO(pInterface) \
|
---|
147 | ( (PDRVAUDIO)((uintptr_t)pInterface - RT_UOFFSETOF(DRVAUDIO, IAudioConnector)) )
|
---|
148 |
|
---|
149 | /** @name Audio format helper methods.
|
---|
150 | * @{ */
|
---|
151 | const char *DrvAudioHlpAudDirToStr(PDMAUDIODIR enmDir);
|
---|
152 | const char *DrvAudioHlpAudFmtToStr(PDMAUDIOFMT enmFmt);
|
---|
153 | bool DrvAudioHlpAudFmtIsSigned(PDMAUDIOFMT enmFmt);
|
---|
154 | uint8_t DrvAudioHlpAudFmtToBits(PDMAUDIOFMT enmFmt);
|
---|
155 | /** @} */
|
---|
156 |
|
---|
157 | /** @name Audio calculation helper methods.
|
---|
158 | * @{ */
|
---|
159 | void DrvAudioHlpClearBuf(const PPDMAUDIOPCMPROPS pPCMInfo, void *pvBuf, size_t cbBuf, uint32_t cFrames);
|
---|
160 | uint32_t DrvAudioHlpCalcBitrate(uint8_t cBits, uint32_t uHz, uint8_t cChannels);
|
---|
161 | uint32_t DrvAudioHlpCalcBitrate(const PPDMAUDIOPCMPROPS pProps);
|
---|
162 | uint32_t DrvAudioHlpBytesToFrames(const PPDMAUDIOPCMPROPS pProps, uint32_t cbBytes);
|
---|
163 | uint64_t DrvAudioHlpBytesToMs(const PPDMAUDIOPCMPROPS pProps, uint32_t cbBytes);
|
---|
164 | uint32_t DrvAudioHlpFramesToBytes(const PPDMAUDIOPCMPROPS pProps, uint32_t cFrames);
|
---|
165 | uint64_t DrvAudioHlpFramesToMs(const PPDMAUDIOPCMPROPS pProps, uint32_t cFrames);
|
---|
166 | uint32_t DrvAudioHlpMsToBytes(const PPDMAUDIOPCMPROPS pProps, uint32_t uMs);
|
---|
167 | uint32_t DrvAudioHlpMsToFrames(const PPDMAUDIOPCMPROPS pProps, uint32_t uMs);
|
---|
168 | /** @} */
|
---|
169 |
|
---|
170 | /** @name Audio PCM properties helper methods.
|
---|
171 | * @{ */
|
---|
172 | bool DrvAudioHlpPCMPropsAreEqual(const PPDMAUDIOPCMPROPS pPCMProps1, const PPDMAUDIOPCMPROPS pPCMProps2);
|
---|
173 | bool DrvAudioHlpPCMPropsAreEqual(const PPDMAUDIOPCMPROPS pPCMProps, const PPDMAUDIOSTREAMCFG pCfg);
|
---|
174 | bool DrvAudioHlpPCMPropsAreValid(const PPDMAUDIOPCMPROPS pProps);
|
---|
175 | uint32_t DrvAudioHlpPCMPropsBytesPerFrame(const PPDMAUDIOPCMPROPS pProps);
|
---|
176 | void DrvAudioHlpPCMPropsPrint(const PPDMAUDIOPCMPROPS pProps);
|
---|
177 | int DrvAudioHlpPCMPropsToStreamCfg(const PPDMAUDIOPCMPROPS pPCMProps, PPDMAUDIOSTREAMCFG pCfg);
|
---|
178 | /** @} */
|
---|
179 |
|
---|
180 | /** @name Audio stream helper methods.
|
---|
181 | * @{ */
|
---|
182 | void DrvAudioHlpStreamCfgPrint(const PPDMAUDIOSTREAMCFG pCfg);
|
---|
183 | bool DrvAudioHlpStreamCfgIsValid(const PPDMAUDIOSTREAMCFG pCfg);
|
---|
184 | int DrvAudioHlpStreamCfgCopy(PPDMAUDIOSTREAMCFG pDstCfg, const PPDMAUDIOSTREAMCFG pSrcCfg);
|
---|
185 | PPDMAUDIOSTREAMCFG DrvAudioHlpStreamCfgDup(const PPDMAUDIOSTREAMCFG pCfg);
|
---|
186 | void DrvAudioHlpStreamCfgFree(PPDMAUDIOSTREAMCFG pCfg);
|
---|
187 | const char *DrvAudioHlpStreamCmdToStr(PDMAUDIOSTREAMCMD enmCmd);
|
---|
188 | /** @} */
|
---|
189 |
|
---|
190 | /** @name Audio file (name) helper methods.
|
---|
191 | * @{ */
|
---|
192 | int DrvAudioHlpSanitizeFileName(char *pszPath, size_t cbPath);
|
---|
193 | int DrvAudioHlpGetFileName(char *pszFile, size_t cchFile, const char *pszPath, const char *pszName, uint32_t uInstance, PDMAUDIOFILETYPE enmType, PDMAUDIOFILENAMEFLAGS fFlags);
|
---|
194 | /** @} */
|
---|
195 |
|
---|
196 | /** @name Audio device methods.
|
---|
197 | * @{ */
|
---|
198 | PPDMAUDIODEVICE DrvAudioHlpDeviceAlloc(size_t cbData);
|
---|
199 | void DrvAudioHlpDeviceFree(PPDMAUDIODEVICE pDev);
|
---|
200 | PPDMAUDIODEVICE DrvAudioHlpDeviceDup(const PPDMAUDIODEVICE pDev, bool fCopyUserData);
|
---|
201 | /** @} */
|
---|
202 |
|
---|
203 | /** @name Audio device enumartion methods.
|
---|
204 | * @{ */
|
---|
205 | int DrvAudioHlpDeviceEnumInit(PPDMAUDIODEVICEENUM pDevEnm);
|
---|
206 | void DrvAudioHlpDeviceEnumFree(PPDMAUDIODEVICEENUM pDevEnm);
|
---|
207 | int DrvAudioHlpDeviceEnumAdd(PPDMAUDIODEVICEENUM pDevEnm, PPDMAUDIODEVICE pDev);
|
---|
208 | int DrvAudioHlpDeviceEnumCopyEx(PPDMAUDIODEVICEENUM pDstDevEnm, const PPDMAUDIODEVICEENUM pSrcDevEnm, PDMAUDIODIR enmUsage);
|
---|
209 | int DrvAudioHlpDeviceEnumCopy(PPDMAUDIODEVICEENUM pDstDevEnm, const PPDMAUDIODEVICEENUM pSrcDevEnm);
|
---|
210 | PPDMAUDIODEVICEENUM DrvAudioHlpDeviceEnumDup(const PPDMAUDIODEVICEENUM pDevEnm);
|
---|
211 | int DrvAudioHlpDeviceEnumCopy(PPDMAUDIODEVICEENUM pDstDevEnm, const PPDMAUDIODEVICEENUM pSrcDevEnm);
|
---|
212 | int DrvAudioHlpDeviceEnumCopyEx(PPDMAUDIODEVICEENUM pDstDevEnm, const PPDMAUDIODEVICEENUM pSrcDevEnm, PDMAUDIODIR enmUsage, bool fCopyUserData);
|
---|
213 | PPDMAUDIODEVICE DrvAudioHlpDeviceEnumGetDefaultDevice(const PPDMAUDIODEVICEENUM pDevEnm, PDMAUDIODIR enmDir);
|
---|
214 | void DrvAudioHlpDeviceEnumPrint(const char *pszDesc, const PPDMAUDIODEVICEENUM pDevEnm);
|
---|
215 | /** @} */
|
---|
216 |
|
---|
217 | /** @name Audio string-ify methods.
|
---|
218 | * @{ */
|
---|
219 | const char *DrvAudioHlpAudMixerCtlToStr(PDMAUDIOMIXERCTL enmMixerCtl);
|
---|
220 | const char *DrvAudioHlpPlaybackDstToStr(const PDMAUDIOPLAYBACKDEST enmPlaybackDst);
|
---|
221 | const char *DrvAudioHlpRecSrcToStr(const PDMAUDIORECSOURCE enmRecSource);
|
---|
222 | PDMAUDIOFMT DrvAudioHlpStrToAudFmt(const char *pszFmt);
|
---|
223 | char *DrvAudioHlpAudDevFlagsToStrA(PDMAUDIODEVFLAG fFlags);
|
---|
224 | /** @} */
|
---|
225 |
|
---|
226 | /** @name Audio file methods.
|
---|
227 | * @{ */
|
---|
228 | int DrvAudioHlpFileCreate(PDMAUDIOFILETYPE enmType, const char *pszFile, PDMAUDIOFILEFLAGS fFlags, PPDMAUDIOFILE *ppFile);
|
---|
229 | void DrvAudioHlpFileDestroy(PPDMAUDIOFILE pFile);
|
---|
230 | int DrvAudioHlpFileOpen(PPDMAUDIOFILE pFile, uint32_t fOpen, const PPDMAUDIOPCMPROPS pProps);
|
---|
231 | int DrvAudioHlpFileClose(PPDMAUDIOFILE pFile);
|
---|
232 | int DrvAudioHlpFileDelete(PPDMAUDIOFILE pFile);
|
---|
233 | size_t DrvAudioHlpFileGetDataSize(PPDMAUDIOFILE pFile);
|
---|
234 | bool DrvAudioHlpFileIsOpen(PPDMAUDIOFILE pFile);
|
---|
235 | int DrvAudioHlpFileWrite(PPDMAUDIOFILE pFile, const void *pvBuf, size_t cbBuf, uint32_t fFlags);
|
---|
236 | /** @} */
|
---|
237 |
|
---|
238 | #define AUDIO_MAKE_FOURCC(c0, c1, c2, c3) RT_H2LE_U32_C(RT_MAKE_U32_FROM_U8(c0, c1, c2, c3))
|
---|
239 |
|
---|
240 | #endif /* !DRV_AUDIO_H */
|
---|
241 |
|
---|