VirtualBox

source: vbox/trunk/src/VBox/Devices/Audio/DrvAudio.h@ 78229

Last change on this file since 78229 was 76990, checked in by vboxsync, 6 years ago

Audio/DrvAudio.h: Naming nit.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 11.3 KB
Line 
1/* $Id: DrvAudio.h 76990 2019-01-25 13:51:22Z vboxsync $ */
2/** @file
3 * Intermediate audio driver header.
4 */
5
6/*
7 * Copyright (C) 2006-2019 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 VBOX_INCLUDED_SRC_Audio_DrvAudio_h
19#define VBOX_INCLUDED_SRC_Audio_DrvAudio_h
20#ifndef RT_WITHOUT_PRAGMA_ONCE
21# pragma once
22#endif
23
24#include <limits.h>
25
26#include <iprt/circbuf.h>
27#include <iprt/critsect.h>
28#include <iprt/file.h>
29#include <iprt/path.h>
30
31#include <VBox/vmm/pdmdev.h>
32#include <VBox/vmm/pdm.h>
33#include <VBox/vmm/pdmaudioifs.h>
34
35typedef enum
36{
37 AUD_OPT_INT,
38 AUD_OPT_FMT,
39 AUD_OPT_STR,
40 AUD_OPT_BOOL
41} audio_option_tag_e;
42
43typedef struct audio_option
44{
45 const char *name;
46 audio_option_tag_e tag;
47 void *valp;
48 const char *descr;
49 int *overridenp;
50 int overriden;
51} audio_option;
52
53#ifdef VBOX_WITH_STATISTICS
54/**
55 * Structure for keeping stream statistics for the
56 * statistic manager (STAM).
57 */
58typedef struct DRVAUDIOSTATS
59{
60 STAMCOUNTER TotalStreamsActive;
61 STAMCOUNTER TotalStreamsCreated;
62 STAMCOUNTER TotalFramesRead;
63 STAMCOUNTER TotalFramesWritten;
64 STAMCOUNTER TotalFramesMixedIn;
65 STAMCOUNTER TotalFramesMixedOut;
66 STAMCOUNTER TotalFramesLostIn;
67 STAMCOUNTER TotalFramesLostOut;
68 STAMCOUNTER TotalFramesOut;
69 STAMCOUNTER TotalFramesIn;
70 STAMCOUNTER TotalBytesRead;
71 STAMCOUNTER TotalBytesWritten;
72 /** How much delay (in ms) for input processing. */
73 STAMPROFILEADV DelayIn;
74 /** How much delay (in ms) for output processing. */
75 STAMPROFILEADV DelayOut;
76} DRVAUDIOSTATS, *PDRVAUDIOSTATS;
77#endif
78
79/**
80 * Audio driver configuration data, tweakable via CFGM.
81 */
82typedef struct DRVAUDIOCFG
83{
84 /** Configures the period size (in ms).
85 * This value reflects the time in between each hardware interrupt on the
86 * backend (host) side. */
87 uint32_t uPeriodSizeMs;
88 /** Configures the (ring) buffer size (in ms). Often is a multiple of uPeriodMs. */
89 uint32_t uBufferSizeMs;
90 /** Configures the pre-buffering size (in ms).
91 * Time needed in buffer before the stream becomes active (pre buffering).
92 * The bigger this value is, the more latency for the stream will occur.
93 * Set to 0 to disable pre-buffering completely.
94 * By default set to UINT32_MAX if not set to a custom value. */
95 uint32_t uPreBufSizeMs;
96 /** The driver's debugging configuration. */
97 struct
98 {
99 /** Whether audio debugging is enabled or not. */
100 bool fEnabled;
101 /** Where to store the debugging files.
102 * Defaults to VBOX_AUDIO_DEBUG_DUMP_PCM_DATA_PATH if not set. */
103 char szPathOut[RTPATH_MAX + 1];
104 } Dbg;
105} DRVAUDIOCFG, *PDRVAUDIOCFG;
106
107/**
108 * Audio driver instance data.
109 *
110 * @implements PDMIAUDIOCONNECTOR
111 */
112typedef struct DRVAUDIO
113{
114 /** Friendly name of the driver. */
115 char szName[64];
116 /** Critical section for serializing access. */
117 RTCRITSECT CritSect;
118 /** Shutdown indicator. */
119 bool fTerminate;
120 /** Our audio connector interface. */
121 PDMIAUDIOCONNECTOR IAudioConnector;
122 /** Pointer to the driver instance. */
123 PPDMDRVINS pDrvIns;
124 /** Pointer to audio driver below us. */
125 PPDMIHOSTAUDIO pHostDrvAudio;
126 /** Pointer to CFGM configuration node of this driver. */
127 PCFGMNODE pCFGMNode;
128 /** List of audio streams. */
129 RTLISTANCHOR lstStreams;
130#ifdef VBOX_WITH_AUDIO_ENUM
131 /** Flag indicating to perform an (re-)enumeration of the host audio devices. */
132 bool fEnumerateDevices;
133#endif
134 /** Audio configuration settings retrieved from the backend. */
135 PDMAUDIOBACKENDCFG BackendCfg;
136#ifdef VBOX_WITH_STATISTICS
137 /** Statistics for the statistics manager (STAM). */
138 DRVAUDIOSTATS Stats;
139#endif
140 struct
141 {
142 /** Whether this driver's input streams are enabled or not.
143 * This flag overrides all the attached stream statuses. */
144 bool fEnabled;
145 /** Max. number of free input streams.
146 * UINT32_MAX for unlimited streams. */
147 uint32_t cStreamsFree;
148#ifdef VBOX_WITH_AUDIO_CALLBACKS
149 RTLISTANCHOR lstCB;
150#endif
151 /** The driver's input confguration (tweakable via CFGM). */
152 DRVAUDIOCFG Cfg;
153 } In;
154 struct
155 {
156 /** Whether this driver's output streams are enabled or not.
157 * This flag overrides all the attached stream statuses. */
158 bool fEnabled;
159 /** Max. number of free output streams.
160 * UINT32_MAX for unlimited streams. */
161 uint32_t cStreamsFree;
162#ifdef VBOX_WITH_AUDIO_CALLBACKS
163 RTLISTANCHOR lstCB;
164#endif
165 /** The driver's output confguration (tweakable via CFGM). */
166 DRVAUDIOCFG Cfg;
167 } Out;
168} DRVAUDIO, *PDRVAUDIO;
169
170/** Makes a PDRVAUDIO out of a PPDMIAUDIOCONNECTOR. */
171#define PDMIAUDIOCONNECTOR_2_DRVAUDIO(pInterface) \
172 ( (PDRVAUDIO)((uintptr_t)pInterface - RT_UOFFSETOF(DRVAUDIO, IAudioConnector)) )
173
174/** @name Audio format helper methods.
175 * @{ */
176const char *DrvAudioHlpAudDirToStr(PDMAUDIODIR enmDir);
177const char *DrvAudioHlpAudFmtToStr(PDMAUDIOFMT enmFmt);
178bool DrvAudioHlpAudFmtIsSigned(PDMAUDIOFMT enmFmt);
179uint8_t DrvAudioHlpAudFmtToBits(PDMAUDIOFMT enmFmt);
180/** @} */
181
182/** @name Audio calculation helper methods.
183 * @{ */
184void DrvAudioHlpClearBuf(const PPDMAUDIOPCMPROPS pPCMProps, void *pvBuf, size_t cbBuf, uint32_t cFrames);
185uint32_t DrvAudioHlpCalcBitrate(uint8_t cBits, uint32_t uHz, uint8_t cChannels);
186uint32_t DrvAudioHlpCalcBitrate(const PPDMAUDIOPCMPROPS pProps);
187uint32_t DrvAudioHlpBytesAlign(uint32_t cbSize, const PPDMAUDIOPCMPROPS pProps);
188bool DrvAudioHlpBytesIsAligned(uint32_t cbSize, const PPDMAUDIOPCMPROPS pProps);
189uint32_t DrvAudioHlpBytesToFrames(uint32_t cbBytes, const PPDMAUDIOPCMPROPS pProps);
190uint64_t DrvAudioHlpBytesToMilli(uint32_t cbBytes, const PPDMAUDIOPCMPROPS pProps);
191uint64_t DrvAudioHlpBytesToMicro(uint32_t cbBytes, const PPDMAUDIOPCMPROPS pProps);
192uint64_t DrvAudioHlpBytesToNano(uint32_t cbBytes, const PPDMAUDIOPCMPROPS pProps);
193uint32_t DrvAudioHlpFramesToBytes(uint32_t cFrames, const PPDMAUDIOPCMPROPS pProps);
194uint64_t DrvAudioHlpFramesToMilli(uint32_t cFrames, const PPDMAUDIOPCMPROPS pProps);
195uint64_t DrvAudioHlpFramesToNano(uint32_t cFrames, const PPDMAUDIOPCMPROPS pProps);
196uint32_t DrvAudioHlpMilliToBytes(uint64_t uMs, const PPDMAUDIOPCMPROPS pProps);
197uint32_t DrvAudioHlpNanoToBytes(uint64_t uNs, const PPDMAUDIOPCMPROPS pProps);
198uint32_t DrvAudioHlpMilliToFrames(uint64_t uMs, const PPDMAUDIOPCMPROPS pProps);
199uint32_t DrvAudioHlpNanoToFrames(uint64_t uNs, const PPDMAUDIOPCMPROPS pProps);
200/** @} */
201
202/** @name Audio PCM properties helper methods.
203 * @{ */
204bool DrvAudioHlpPCMPropsAreEqual(const PPDMAUDIOPCMPROPS pPCMProps1, const PPDMAUDIOPCMPROPS pPCMProps2);
205bool DrvAudioHlpPCMPropsAreEqual(const PPDMAUDIOPCMPROPS pPCMProps, const PPDMAUDIOSTREAMCFG pCfg);
206bool DrvAudioHlpPCMPropsAreValid(const PPDMAUDIOPCMPROPS pProps);
207uint32_t DrvAudioHlpPCMPropsBytesPerFrame(const PPDMAUDIOPCMPROPS pProps);
208void DrvAudioHlpPCMPropsPrint(const PPDMAUDIOPCMPROPS pProps);
209int DrvAudioHlpPCMPropsToStreamCfg(const PPDMAUDIOPCMPROPS pPCMProps, PPDMAUDIOSTREAMCFG pCfg);
210/** @} */
211
212/** @name Audio configuration helper methods.
213 * @{ */
214void DrvAudioHlpStreamCfgInit(PPDMAUDIOSTREAMCFG pCfg);
215bool DrvAudioHlpStreamCfgIsValid(const PPDMAUDIOSTREAMCFG pCfg);
216int DrvAudioHlpStreamCfgCopy(PPDMAUDIOSTREAMCFG pDstCfg, const PPDMAUDIOSTREAMCFG pSrcCfg);
217PPDMAUDIOSTREAMCFG DrvAudioHlpStreamCfgDup(const PPDMAUDIOSTREAMCFG pCfg);
218void DrvAudioHlpStreamCfgFree(PPDMAUDIOSTREAMCFG pCfg);
219void DrvAudioHlpStreamCfgPrint(const PPDMAUDIOSTREAMCFG pCfg);
220/** @} */
221
222/** @name Audio stream command helper methods.
223 * @{ */
224const char *DrvAudioHlpStreamCmdToStr(PDMAUDIOSTREAMCMD enmCmd);
225/** @} */
226
227/** @name Audio stream status helper methods.
228 * @{ */
229bool DrvAudioHlpStreamStatusCanRead(PDMAUDIOSTREAMSTS enmStatus);
230bool DrvAudioHlpStreamStatusCanWrite(PDMAUDIOSTREAMSTS enmStatus);
231bool DrvAudioHlpStreamStatusIsReady(PDMAUDIOSTREAMSTS enmStatus);
232/** @} */
233
234/** @name Audio file (name) helper methods.
235 * @{ */
236int DrvAudioHlpFileNameSanitize(char *pszPath, size_t cbPath);
237int DrvAudioHlpFileNameGet(char *pszFile, size_t cchFile, const char *pszPath, const char *pszName, uint32_t uInstance, PDMAUDIOFILETYPE enmType, PDMAUDIOFILENAMEFLAGS fFlags);
238/** @} */
239
240/** @name Audio device methods.
241 * @{ */
242PPDMAUDIODEVICE DrvAudioHlpDeviceAlloc(size_t cbData);
243void DrvAudioHlpDeviceFree(PPDMAUDIODEVICE pDev);
244PPDMAUDIODEVICE DrvAudioHlpDeviceDup(const PPDMAUDIODEVICE pDev, bool fCopyUserData);
245/** @} */
246
247/** @name Audio device enumartion methods.
248 * @{ */
249int DrvAudioHlpDeviceEnumInit(PPDMAUDIODEVICEENUM pDevEnm);
250void DrvAudioHlpDeviceEnumFree(PPDMAUDIODEVICEENUM pDevEnm);
251int DrvAudioHlpDeviceEnumAdd(PPDMAUDIODEVICEENUM pDevEnm, PPDMAUDIODEVICE pDev);
252int DrvAudioHlpDeviceEnumCopyEx(PPDMAUDIODEVICEENUM pDstDevEnm, const PPDMAUDIODEVICEENUM pSrcDevEnm, PDMAUDIODIR enmUsage);
253int DrvAudioHlpDeviceEnumCopy(PPDMAUDIODEVICEENUM pDstDevEnm, const PPDMAUDIODEVICEENUM pSrcDevEnm);
254PPDMAUDIODEVICEENUM DrvAudioHlpDeviceEnumDup(const PPDMAUDIODEVICEENUM pDevEnm);
255int DrvAudioHlpDeviceEnumCopy(PPDMAUDIODEVICEENUM pDstDevEnm, const PPDMAUDIODEVICEENUM pSrcDevEnm);
256int DrvAudioHlpDeviceEnumCopyEx(PPDMAUDIODEVICEENUM pDstDevEnm, const PPDMAUDIODEVICEENUM pSrcDevEnm, PDMAUDIODIR enmUsage, bool fCopyUserData);
257PPDMAUDIODEVICE DrvAudioHlpDeviceEnumGetDefaultDevice(const PPDMAUDIODEVICEENUM pDevEnm, PDMAUDIODIR enmDir);
258uint16_t DrvAudioHlpDeviceEnumGetDeviceCount(const PPDMAUDIODEVICEENUM pDevEnm, PDMAUDIODIR enmUsage);
259void DrvAudioHlpDeviceEnumPrint(const char *pszDesc, const PPDMAUDIODEVICEENUM pDevEnm);
260/** @} */
261
262/** @name Audio string-ify methods.
263 * @{ */
264const char *DrvAudioHlpAudMixerCtlToStr(PDMAUDIOMIXERCTL enmMixerCtl);
265const char *DrvAudioHlpPlaybackDstToStr(const PDMAUDIOPLAYBACKDEST enmPlaybackDst);
266const char *DrvAudioHlpRecSrcToStr(const PDMAUDIORECSOURCE enmRecSource);
267PDMAUDIOFMT DrvAudioHlpStrToAudFmt(const char *pszFmt);
268char *DrvAudioHlpAudDevFlagsToStrA(PDMAUDIODEVFLAG fFlags);
269/** @} */
270
271/** @name Audio file methods.
272 * @{ */
273int DrvAudioHlpFileCreate(PDMAUDIOFILETYPE enmType, const char *pszFile, PDMAUDIOFILEFLAGS fFlags, PPDMAUDIOFILE *ppFile);
274void DrvAudioHlpFileDestroy(PPDMAUDIOFILE pFile);
275int DrvAudioHlpFileOpen(PPDMAUDIOFILE pFile, uint32_t fOpen, const PPDMAUDIOPCMPROPS pProps);
276int DrvAudioHlpFileClose(PPDMAUDIOFILE pFile);
277int DrvAudioHlpFileDelete(PPDMAUDIOFILE pFile);
278size_t DrvAudioHlpFileGetDataSize(PPDMAUDIOFILE pFile);
279bool DrvAudioHlpFileIsOpen(PPDMAUDIOFILE pFile);
280int DrvAudioHlpFileWrite(PPDMAUDIOFILE pFile, const void *pvBuf, size_t cbBuf, uint32_t fFlags);
281/** @} */
282
283#define AUDIO_MAKE_FOURCC(c0, c1, c2, c3) RT_H2LE_U32_C(RT_MAKE_U32_FROM_U8(c0, c1, c2, c3))
284
285#endif /* !VBOX_INCLUDED_SRC_Audio_DrvAudio_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