1 | /* $Id: DrvAudio.h 68136 2017-07-27 10:52:43Z vboxsync $ */
|
---|
2 | /** @file
|
---|
3 | * Intermediate audio driver header.
|
---|
4 | */
|
---|
5 |
|
---|
6 | /*
|
---|
7 | * Copyright (C) 2006-2017 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 | #ifdef DEBUG_andy
|
---|
33 | # define VBOX_AUDIO_DEBUG_DUMP_PCM_DATA
|
---|
34 | #endif
|
---|
35 |
|
---|
36 | #ifdef VBOX_AUDIO_DEBUG_DUMP_PCM_DATA
|
---|
37 | # ifdef RT_OS_WINDOWS
|
---|
38 | # define VBOX_AUDIO_DEBUG_DUMP_PCM_DATA_PATH "c:\\temp\\"
|
---|
39 | # else
|
---|
40 | # define VBOX_AUDIO_DEBUG_DUMP_PCM_DATA_PATH "/tmp/"
|
---|
41 | # endif
|
---|
42 | #endif /* VBOX_AUDIO_DEBUG_DUMP_PCM_DATA */
|
---|
43 |
|
---|
44 | typedef enum
|
---|
45 | {
|
---|
46 | AUD_OPT_INT,
|
---|
47 | AUD_OPT_FMT,
|
---|
48 | AUD_OPT_STR,
|
---|
49 | AUD_OPT_BOOL
|
---|
50 | } audio_option_tag_e;
|
---|
51 |
|
---|
52 | typedef struct audio_option
|
---|
53 | {
|
---|
54 | const char *name;
|
---|
55 | audio_option_tag_e tag;
|
---|
56 | void *valp;
|
---|
57 | const char *descr;
|
---|
58 | int *overridenp;
|
---|
59 | int overriden;
|
---|
60 | } audio_option;
|
---|
61 |
|
---|
62 | #ifdef VBOX_WITH_STATISTICS
|
---|
63 | /**
|
---|
64 | * Structure for keeping stream statistics for the
|
---|
65 | * statistic manager (STAM).
|
---|
66 | */
|
---|
67 | typedef struct DRVAUDIOSTATS
|
---|
68 | {
|
---|
69 | STAMCOUNTER TotalStreamsActive;
|
---|
70 | STAMCOUNTER TotalStreamsCreated;
|
---|
71 | STAMCOUNTER TotalFramesRead;
|
---|
72 | STAMCOUNTER TotalFramesWritten;
|
---|
73 | STAMCOUNTER TotalFramesMixedIn;
|
---|
74 | STAMCOUNTER TotalFramesMixedOut;
|
---|
75 | STAMCOUNTER TotalFramesLostIn;
|
---|
76 | STAMCOUNTER TotalFramesLostOut;
|
---|
77 | STAMCOUNTER TotalFramesOut;
|
---|
78 | STAMCOUNTER TotalFramesIn;
|
---|
79 | STAMCOUNTER TotalBytesRead;
|
---|
80 | STAMCOUNTER TotalBytesWritten;
|
---|
81 | /** How much delay (in ms) for input processing. */
|
---|
82 | STAMPROFILEADV DelayIn;
|
---|
83 | /** How much delay (in ms) for output processing. */
|
---|
84 | STAMPROFILEADV DelayOut;
|
---|
85 | } DRVAUDIOSTATS, *PDRVAUDIOSTATS;
|
---|
86 | #endif
|
---|
87 |
|
---|
88 | /**
|
---|
89 | * Audio driver instance data.
|
---|
90 | *
|
---|
91 | * @implements PDMIAUDIOCONNECTOR
|
---|
92 | */
|
---|
93 | typedef struct DRVAUDIO
|
---|
94 | {
|
---|
95 | /** Input/output processing thread. */
|
---|
96 | RTTHREAD hThread;
|
---|
97 | /** Critical section for serializing access. */
|
---|
98 | RTCRITSECT CritSect;
|
---|
99 | /** Shutdown indicator. */
|
---|
100 | bool fTerminate;
|
---|
101 | /** Our audio connector interface. */
|
---|
102 | PDMIAUDIOCONNECTOR IAudioConnector;
|
---|
103 | /** Pointer to the driver instance. */
|
---|
104 | PPDMDRVINS pDrvIns;
|
---|
105 | /** Pointer to audio driver below us. */
|
---|
106 | PPDMIHOSTAUDIO pHostDrvAudio;
|
---|
107 | /** List of host input/output audio streams. */
|
---|
108 | RTLISTANCHOR lstHstStreams;
|
---|
109 | /** List of guest input/output audio streams. */
|
---|
110 | RTLISTANCHOR lstGstStreams;
|
---|
111 | /** Max. number of free input streams.
|
---|
112 | * UINT32_MAX for unlimited streams. */
|
---|
113 | uint32_t cStreamsFreeIn;
|
---|
114 | /** Max. number of free output streams.
|
---|
115 | * UINT32_MAX for unlimited streams. */
|
---|
116 | uint32_t cStreamsFreeOut;
|
---|
117 | #ifdef VBOX_WITH_AUDIO_ENUM
|
---|
118 | /** Flag indicating to perform an (re-)enumeration of the host audio devices. */
|
---|
119 | bool fEnumerateDevices;
|
---|
120 | #endif
|
---|
121 | /** Audio configuration settings retrieved from the backend. */
|
---|
122 | PDMAUDIOBACKENDCFG BackendCfg;
|
---|
123 | #ifdef VBOX_WITH_AUDIO_DEVICE_CALLBACKS
|
---|
124 | /** @todo Use a map with primary key set to the callback type? */
|
---|
125 | RTLISTANCHOR lstCBIn;
|
---|
126 | RTLISTANCHOR lstCBOut;
|
---|
127 | #endif
|
---|
128 | #ifdef VBOX_WITH_STATISTICS
|
---|
129 | /** Statistics for the statistics manager (STAM). */
|
---|
130 | DRVAUDIOSTATS Stats;
|
---|
131 | #endif
|
---|
132 | } DRVAUDIO, *PDRVAUDIO;
|
---|
133 |
|
---|
134 | /** Makes a PDRVAUDIO out of a PPDMIAUDIOCONNECTOR. */
|
---|
135 | #define PDMIAUDIOCONNECTOR_2_DRVAUDIO(pInterface) \
|
---|
136 | ( (PDRVAUDIO)((uintptr_t)pInterface - RT_OFFSETOF(DRVAUDIO, IAudioConnector)) )
|
---|
137 |
|
---|
138 |
|
---|
139 | bool DrvAudioHlpAudFmtIsSigned(PDMAUDIOFMT enmFmt);
|
---|
140 | uint8_t DrvAudioHlpAudFmtToBits(PDMAUDIOFMT enmFmt);
|
---|
141 | const char *DrvAudioHlpAudFmtToStr(PDMAUDIOFMT enmFmt);
|
---|
142 | void DrvAudioHlpClearBuf(const PPDMAUDIOPCMPROPS pPCMInfo, void *pvBuf, size_t cbBuf, uint32_t cFrames);
|
---|
143 | uint32_t DrvAudioHlpCalcBitrate(uint8_t cBits, uint32_t uHz, uint8_t cChannels);
|
---|
144 | uint32_t DrvAudioHlpCalcBitrate(const PPDMAUDIOPCMPROPS pProps);
|
---|
145 | bool DrvAudioHlpPCMPropsAreEqual(const PPDMAUDIOPCMPROPS pPCMProps1, const PPDMAUDIOPCMPROPS pPCMProps2);
|
---|
146 | bool DrvAudioHlpPCMPropsAreEqual(const PPDMAUDIOPCMPROPS pPCMProps, const PPDMAUDIOSTREAMCFG pCfg);
|
---|
147 | bool DrvAudioHlpPCMPropsAreValid(const PPDMAUDIOPCMPROPS pProps);
|
---|
148 | void DrvAudioHlpPCMPropsPrint(const PPDMAUDIOPCMPROPS pProps);
|
---|
149 | int DrvAudioHlpPCMPropsToStreamCfg(const PPDMAUDIOPCMPROPS pPCMProps, PPDMAUDIOSTREAMCFG pCfg);
|
---|
150 | const char *DrvAudioHlpRecSrcToStr(const PDMAUDIORECSOURCE enmRecSource);
|
---|
151 | void DrvAudioHlpStreamCfgPrint(const PPDMAUDIOSTREAMCFG pCfg);
|
---|
152 | bool DrvAudioHlpStreamCfgIsValid(const PPDMAUDIOSTREAMCFG pCfg);
|
---|
153 | int DrvAudioHlpStreamCfgCopy(PPDMAUDIOSTREAMCFG pDstCfg, const PPDMAUDIOSTREAMCFG pSrcCfg);
|
---|
154 | PPDMAUDIOSTREAMCFG DrvAudioHlpStreamCfgDup(const PPDMAUDIOSTREAMCFG pCfg);
|
---|
155 | void DrvAudioHlpStreamCfgFree(PPDMAUDIOSTREAMCFG pCfg);
|
---|
156 | const char *DrvAudioHlpStreamCmdToStr(PDMAUDIOSTREAMCMD enmCmd);
|
---|
157 | PDMAUDIOFMT DrvAudioHlpStrToAudFmt(const char *pszFmt);
|
---|
158 |
|
---|
159 | int DrvAudioHlpSanitizeFileName(char *pszPath, size_t cbPath);
|
---|
160 | int DrvAudioHlpGetFileName(char *pszFile, size_t cchFile, const char *pszPath, const char *pszName, PDMAUDIOFILETYPE enmType);
|
---|
161 |
|
---|
162 | PPDMAUDIODEVICE DrvAudioHlpDeviceAlloc(size_t cbData);
|
---|
163 | void DrvAudioHlpDeviceFree(PPDMAUDIODEVICE pDev);
|
---|
164 | PPDMAUDIODEVICE DrvAudioHlpDeviceDup(const PPDMAUDIODEVICE pDev, bool fCopyUserData);
|
---|
165 |
|
---|
166 | int DrvAudioHlpDeviceEnumInit(PPDMAUDIODEVICEENUM pDevEnm);
|
---|
167 | void DrvAudioHlpDeviceEnumFree(PPDMAUDIODEVICEENUM pDevEnm);
|
---|
168 | int DrvAudioHlpDeviceEnumAdd(PPDMAUDIODEVICEENUM pDevEnm, PPDMAUDIODEVICE pDev);
|
---|
169 | int DrvAudioHlpDeviceEnumCopyEx(PPDMAUDIODEVICEENUM pDstDevEnm, const PPDMAUDIODEVICEENUM pSrcDevEnm, PDMAUDIODIR enmUsage);
|
---|
170 | int DrvAudioHlpDeviceEnumCopy(PPDMAUDIODEVICEENUM pDstDevEnm, const PPDMAUDIODEVICEENUM pSrcDevEnm);
|
---|
171 | PPDMAUDIODEVICEENUM DrvAudioHlpDeviceEnumDup(const PPDMAUDIODEVICEENUM pDevEnm);
|
---|
172 | int DrvAudioHlpDeviceEnumCopy(PPDMAUDIODEVICEENUM pDstDevEnm, const PPDMAUDIODEVICEENUM pSrcDevEnm);
|
---|
173 | int DrvAudioHlpDeviceEnumCopyEx(PPDMAUDIODEVICEENUM pDstDevEnm, const PPDMAUDIODEVICEENUM pSrcDevEnm, PDMAUDIODIR enmUsage, bool fCopyUserData);
|
---|
174 | PPDMAUDIODEVICE DrvAudioHlpDeviceEnumGetDefaultDevice(const PPDMAUDIODEVICEENUM pDevEnm, PDMAUDIODIR enmDir);
|
---|
175 | void DrvAudioHlpDeviceEnumPrint(const char *pszDesc, const PPDMAUDIODEVICEENUM pDevEnm);
|
---|
176 |
|
---|
177 | const char *DrvAudioHlpAudDirToStr(PDMAUDIODIR enmDir);
|
---|
178 | const char *DrvAudioHlpAudMixerCtlToStr(PDMAUDIOMIXERCTL enmMixerCtl);
|
---|
179 | char *DrvAudioHlpAudDevFlagsToStrA(PDMAUDIODEVFLAG fFlags);
|
---|
180 |
|
---|
181 | int DrvAudioHlpWAVFileOpen(PPDMAUDIOFILE pFile, const char *pszFile, uint32_t fOpen, const PPDMAUDIOPCMPROPS pProps, PDMAUDIOFILEFLAGS fFlags);
|
---|
182 | int DrvAudioHlpWAVFileClose(PPDMAUDIOFILE pFile);
|
---|
183 | size_t DrvAudioHlpWAVFileGetDataSize(PPDMAUDIOFILE pFile);
|
---|
184 | int DrvAudioHlpWAVFileWrite(PPDMAUDIOFILE pFile, const void *pvBuf, size_t cbBuf, uint32_t fFlags);
|
---|
185 |
|
---|
186 | #define AUDIO_MAKE_FOURCC(c0, c1, c2, c3) RT_H2LE_U32_C(RT_MAKE_U32_FROM_U8(c0, c1, c2, c3))
|
---|
187 |
|
---|
188 | #endif /* DRV_AUDIO_H */
|
---|
189 |
|
---|