VirtualBox

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

Last change on this file since 87994 was 87994, checked in by vboxsync, 4 years ago

Audio: Switched DrvAudioHlpFramesToBytes parameters. bugref:9890

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 11.8 KB
Line 
1/* $Id: DrvAudio.h 87994 2021-03-07 15:22:36Z vboxsync $ */
2/** @file
3 * Intermediate audio driver header.
4 */
5
6/*
7 * Copyright (C) 2006-2020 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 /** PCM properties to use. */
85 PDMAUDIOPCMPROPS Props;
86 /** Whether using signed sample data or not.
87 * Needed in order to know whether there is a custom value set in CFGM or not.
88 * By default set to UINT8_MAX if not set to a custom value. */
89 uint8_t uSigned;
90 /** Whether swapping endianess of sample data or not.
91 * Needed in order to know whether there is a custom value set in CFGM or not.
92 * By default set to UINT8_MAX if not set to a custom value. */
93 uint8_t uSwapEndian;
94 /** Configures the period size (in ms).
95 * This value reflects the time in between each hardware interrupt on the
96 * backend (host) side. */
97 uint32_t uPeriodSizeMs;
98 /** Configures the (ring) buffer size (in ms). Often is a multiple of uPeriodMs. */
99 uint32_t uBufferSizeMs;
100 /** Configures the pre-buffering size (in ms).
101 * Time needed in buffer before the stream becomes active (pre buffering).
102 * The bigger this value is, the more latency for the stream will occur.
103 * Set to 0 to disable pre-buffering completely.
104 * By default set to UINT32_MAX if not set to a custom value. */
105 uint32_t uPreBufSizeMs;
106 /** The driver's debugging configuration. */
107 struct
108 {
109 /** Whether audio debugging is enabled or not. */
110 bool fEnabled;
111 /** Where to store the debugging files. */
112 char szPathOut[RTPATH_MAX];
113 } Dbg;
114} DRVAUDIOCFG, *PDRVAUDIOCFG;
115
116/**
117 * Audio driver instance data.
118 *
119 * @implements PDMIAUDIOCONNECTOR
120 */
121typedef struct DRVAUDIO
122{
123 /** Friendly name of the driver. */
124 char szName[64];
125 /** Critical section for serializing access. */
126 RTCRITSECT CritSect;
127 /** Shutdown indicator. */
128 bool fTerminate;
129 /** Our audio connector interface. */
130 PDMIAUDIOCONNECTOR IAudioConnector;
131 /** Pointer to the driver instance. */
132 PPDMDRVINS pDrvIns;
133 /** Pointer to audio driver below us. */
134 PPDMIHOSTAUDIO pHostDrvAudio;
135 /** Pointer to CFGM configuration node of this driver. */
136 PCFGMNODE pCFGMNode;
137 /** List of audio streams. */
138 RTLISTANCHOR lstStreams;
139#ifdef VBOX_WITH_AUDIO_ENUM
140 /** Flag indicating to perform an (re-)enumeration of the host audio devices. */
141 bool fEnumerateDevices;
142#endif
143 /** Audio configuration settings retrieved from the backend. */
144 PDMAUDIOBACKENDCFG BackendCfg;
145 /** Commonly used scratch buffer. */
146 void *pvScratchBuf;
147 /** Size (in bytes) of commonly used scratch buffer. */
148 size_t cbScratchBuf;
149#ifdef VBOX_WITH_STATISTICS
150 /** Statistics for the statistics manager (STAM). */
151 DRVAUDIOSTATS Stats;
152#endif
153 struct
154 {
155 /** Whether this driver's input streams are enabled or not.
156 * This flag overrides all the attached stream statuses. */
157 bool fEnabled;
158 /** Max. number of free input streams.
159 * UINT32_MAX for unlimited streams. */
160 uint32_t cStreamsFree;
161#ifdef VBOX_WITH_AUDIO_CALLBACKS
162 RTLISTANCHOR lstCB;
163#endif
164 /** The driver's input confguration (tweakable via CFGM). */
165 DRVAUDIOCFG Cfg;
166 } In;
167 struct
168 {
169 /** Whether this driver's output streams are enabled or not.
170 * This flag overrides all the attached stream statuses. */
171 bool fEnabled;
172 /** Max. number of free output streams.
173 * UINT32_MAX for unlimited streams. */
174 uint32_t cStreamsFree;
175#ifdef VBOX_WITH_AUDIO_CALLBACKS
176 RTLISTANCHOR lstCB;
177#endif
178 /** The driver's output confguration (tweakable via CFGM). */
179 DRVAUDIOCFG Cfg;
180 } Out;
181} DRVAUDIO, *PDRVAUDIO;
182
183/** Makes a PDRVAUDIO out of a PPDMIAUDIOCONNECTOR. */
184#define PDMIAUDIOCONNECTOR_2_DRVAUDIO(pInterface) \
185 ( (PDRVAUDIO)((uintptr_t)pInterface - RT_UOFFSETOF(DRVAUDIO, IAudioConnector)) )
186
187/** @name Audio format helper methods.
188 * @{ */
189const char *DrvAudioHlpAudDirToStr(PDMAUDIODIR enmDir);
190const char *DrvAudioHlpAudFmtToStr(PDMAUDIOFMT enmFmt);
191bool DrvAudioHlpAudFmtIsSigned(PDMAUDIOFMT enmFmt);
192uint8_t DrvAudioHlpAudFmtToBits(PDMAUDIOFMT enmFmt);
193/** @} */
194
195/** @name Audio calculation helper methods.
196 * @{ */
197void DrvAudioHlpClearBuf(PCPDMAUDIOPCMPROPS pPCMProps, void *pvBuf, size_t cbBuf, uint32_t cFrames);
198uint32_t DrvAudioHlpCalcBitrate(uint8_t cBits, uint32_t uHz, uint8_t cChannels);
199uint32_t DrvAudioHlpCalcBitrate(PCPDMAUDIOPCMPROPS pProps);
200uint32_t DrvAudioHlpBytesAlign(uint32_t cbSize, PCPDMAUDIOPCMPROPS pProps);
201bool DrvAudioHlpBytesIsAligned(uint32_t cbSize, PCPDMAUDIOPCMPROPS pProps);
202uint32_t DrvAudioHlpBytesToFrames(uint32_t cbBytes, PCPDMAUDIOPCMPROPS pProps);
203uint64_t DrvAudioHlpBytesToMilli(PCPDMAUDIOPCMPROPS pProps, uint32_t cb);
204uint64_t DrvAudioHlpBytesToMicro(PCPDMAUDIOPCMPROPS pProps, uint32_t cb);
205uint64_t DrvAudioHlpBytesToNano(PCPDMAUDIOPCMPROPS pProps, uint32_t cb);
206uint32_t DrvAudioHlpFramesToBytes(PCPDMAUDIOPCMPROPS pProps, uint32_t cFrames);
207uint64_t DrvAudioHlpFramesToMilli(PCPDMAUDIOPCMPROPS pProps, uint32_t cFrames);
208uint64_t DrvAudioHlpFramesToNano(PCPDMAUDIOPCMPROPS pProps, uint32_t cFrames);
209uint32_t DrvAudioHlpMilliToBytes(uint64_t uMs, PCPDMAUDIOPCMPROPS pProps);
210uint32_t DrvAudioHlpNanoToBytes(uint64_t uNs, PCPDMAUDIOPCMPROPS pProps);
211uint32_t DrvAudioHlpMilliToFrames(uint64_t uMs, PCPDMAUDIOPCMPROPS pProps);
212uint32_t DrvAudioHlpNanoToFrames(uint64_t uNs, PCPDMAUDIOPCMPROPS pProps);
213/** @} */
214
215/** @name Audio PCM properties helper methods.
216 * @{ */
217bool DrvAudioHlpPCMPropsAreEqual(PCPDMAUDIOPCMPROPS pPCMProps1, PCPDMAUDIOPCMPROPS pPCMProps2);
218bool DrvAudioHlpPCMPropsAreEqual(PCPDMAUDIOPCMPROPS pPCMProps, PCPDMAUDIOSTREAMCFG pCfg);
219bool DrvAudioHlpPCMPropsAreValid(PCPDMAUDIOPCMPROPS pProps);
220uint32_t DrvAudioHlpPCMPropsBytesPerFrame(PCPDMAUDIOPCMPROPS pProps);
221void DrvAudioHlpPCMPropsPrint(PCPDMAUDIOPCMPROPS pProps);
222int DrvAudioHlpPCMPropsToStreamCfg(PCPDMAUDIOPCMPROPS pPCMProps, PPDMAUDIOSTREAMCFG pCfg);
223/** @} */
224
225/** @name Audio configuration helper methods.
226 * @{ */
227void DrvAudioHlpStreamCfgInit(PPDMAUDIOSTREAMCFG pCfg);
228bool DrvAudioHlpStreamCfgIsValid(PCPDMAUDIOSTREAMCFG pCfg);
229int DrvAudioHlpStreamCfgCopy(PPDMAUDIOSTREAMCFG pDstCfg, PCPDMAUDIOSTREAMCFG pSrcCfg);
230PPDMAUDIOSTREAMCFG DrvAudioHlpStreamCfgDup(PCPDMAUDIOSTREAMCFG pCfg);
231void DrvAudioHlpStreamCfgFree(PPDMAUDIOSTREAMCFG pCfg);
232void DrvAudioHlpStreamCfgPrint(PCPDMAUDIOSTREAMCFG pCfg);
233/** @} */
234
235/** @name Audio stream command helper methods.
236 * @{ */
237const char *DrvAudioHlpStreamCmdToStr(PDMAUDIOSTREAMCMD enmCmd);
238/** @} */
239
240/** @name Audio stream status helper methods.
241 * @{ */
242bool DrvAudioHlpStreamStatusCanRead(PDMAUDIOSTREAMSTS fStatus);
243bool DrvAudioHlpStreamStatusCanWrite(PDMAUDIOSTREAMSTS fStatus);
244bool DrvAudioHlpStreamStatusIsReady(PDMAUDIOSTREAMSTS fStatus);
245/** @} */
246
247/** @name Audio file (name) helper methods.
248 * @{ */
249int DrvAudioHlpFileNameSanitize(char *pszPath, size_t cbPath);
250int DrvAudioHlpFileNameGet(char *pszFile, size_t cchFile, const char *pszPath, const char *pszName, uint32_t uInstance,
251 PDMAUDIOFILETYPE enmType, uint32_t fFlags);
252/** @} */
253
254/** @name Audio device methods.
255 * @{ */
256PPDMAUDIODEVICE DrvAudioHlpDeviceAlloc(size_t cbData);
257void DrvAudioHlpDeviceFree(PPDMAUDIODEVICE pDev);
258PPDMAUDIODEVICE DrvAudioHlpDeviceDup(const PPDMAUDIODEVICE pDev, bool fCopyUserData);
259/** @} */
260
261/** @name Audio device enumartion methods.
262 * @{ */
263int DrvAudioHlpDeviceEnumInit(PPDMAUDIODEVICEENUM pDevEnm);
264void DrvAudioHlpDeviceEnumFree(PPDMAUDIODEVICEENUM pDevEnm);
265int DrvAudioHlpDeviceEnumAdd(PPDMAUDIODEVICEENUM pDevEnm, PPDMAUDIODEVICE pDev);
266int DrvAudioHlpDeviceEnumCopyEx(PPDMAUDIODEVICEENUM pDstDevEnm, const PPDMAUDIODEVICEENUM pSrcDevEnm, PDMAUDIODIR enmUsage);
267int DrvAudioHlpDeviceEnumCopy(PPDMAUDIODEVICEENUM pDstDevEnm, const PPDMAUDIODEVICEENUM pSrcDevEnm);
268PPDMAUDIODEVICEENUM DrvAudioHlpDeviceEnumDup(const PPDMAUDIODEVICEENUM pDevEnm);
269int DrvAudioHlpDeviceEnumCopy(PPDMAUDIODEVICEENUM pDstDevEnm, const PPDMAUDIODEVICEENUM pSrcDevEnm);
270int DrvAudioHlpDeviceEnumCopyEx(PPDMAUDIODEVICEENUM pDstDevEnm, const PPDMAUDIODEVICEENUM pSrcDevEnm, PDMAUDIODIR enmUsage, bool fCopyUserData);
271PPDMAUDIODEVICE DrvAudioHlpDeviceEnumGetDefaultDevice(const PPDMAUDIODEVICEENUM pDevEnm, PDMAUDIODIR enmDir);
272uint16_t DrvAudioHlpDeviceEnumGetDeviceCount(const PPDMAUDIODEVICEENUM pDevEnm, PDMAUDIODIR enmUsage);
273void DrvAudioHlpDeviceEnumPrint(const char *pszDesc, const PPDMAUDIODEVICEENUM pDevEnm);
274/** @} */
275
276/** @name Audio string-ify methods.
277 * @{ */
278const char *DrvAudioHlpAudMixerCtlToStr(PDMAUDIOMIXERCTL enmMixerCtl);
279const char *DrvAudioHlpPlaybackDstToStr(const PDMAUDIOPLAYBACKDST enmPlaybackDst);
280const char *DrvAudioHlpRecSrcToStr(const PDMAUDIORECSRC enmRecSource);
281PDMAUDIOFMT DrvAudioHlpStrToAudFmt(const char *pszFmt);
282char *DrvAudioHlpAudDevFlagsToStrA(uint32_t fFlags);
283/** @} */
284
285/** @name Audio file methods.
286 * @{ */
287int DrvAudioHlpFileCreate(PDMAUDIOFILETYPE enmType, const char *pszFile, uint32_t fFlags, PPDMAUDIOFILE *ppFile);
288void DrvAudioHlpFileDestroy(PPDMAUDIOFILE pFile);
289int DrvAudioHlpFileOpen(PPDMAUDIOFILE pFile, uint32_t fOpen, PCPDMAUDIOPCMPROPS pProps);
290int DrvAudioHlpFileClose(PPDMAUDIOFILE pFile);
291int DrvAudioHlpFileDelete(PPDMAUDIOFILE pFile);
292size_t DrvAudioHlpFileGetDataSize(PPDMAUDIOFILE pFile);
293bool DrvAudioHlpFileIsOpen(PPDMAUDIOFILE pFile);
294int DrvAudioHlpFileWrite(PPDMAUDIOFILE pFile, const void *pvBuf, size_t cbBuf, uint32_t fFlags);
295/** @} */
296
297#define AUDIO_MAKE_FOURCC(c0, c1, c2, c3) RT_H2LE_U32_C(RT_MAKE_U32_FROM_U8(c0, c1, c2, c3))
298
299#endif /* !VBOX_INCLUDED_SRC_Audio_DrvAudio_h */
300
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