1 | /* $Id: DrvHostNullAudio.cpp 54491 2015-02-25 13:23:21Z vboxsync $ */
|
---|
2 | /** @file
|
---|
3 | * NULL audio driver -- also acts as a fallback if no
|
---|
4 | * other backend is available.
|
---|
5 | */
|
---|
6 |
|
---|
7 | /*
|
---|
8 | * Copyright (C) 2006-2015 Oracle Corporation
|
---|
9 | *
|
---|
10 | * This file is part of VirtualBox Open Source Edition (OSE), as
|
---|
11 | * available from http://www.virtualbox.org. This file is free software;
|
---|
12 | * you can redistribute it and/or modify it under the terms of the GNU
|
---|
13 | * General Public License (GPL) as published by the Free Software
|
---|
14 | * Foundation, in version 2 as it comes in the "COPYING" file of the
|
---|
15 | * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
|
---|
16 | * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
|
---|
17 | * --------------------------------------------------------------------
|
---|
18 | *
|
---|
19 | * This code is based on: noaudio.c QEMU based code.
|
---|
20 | *
|
---|
21 | * QEMU Timer based audio emulation
|
---|
22 | *
|
---|
23 | * Copyright (c) 2004-2005 Vassili Karpov (malc)
|
---|
24 | *
|
---|
25 | * Permission is hereby granted, free of charge, to any person obtaining a copy
|
---|
26 | * of this software and associated documentation files (the "Software"), to deal
|
---|
27 | * in the Software without restriction, including without limitation the rights
|
---|
28 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
---|
29 | * copies of the Software, and to permit persons to whom the Software is
|
---|
30 | * furnished to do so, subject to the following conditions:
|
---|
31 | *
|
---|
32 | * The above copyright notice and this permission notice shall be included in
|
---|
33 | * all copies or substantial portions of the Software.
|
---|
34 | *
|
---|
35 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
---|
36 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
---|
37 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
|
---|
38 | * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
---|
39 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
---|
40 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
---|
41 | * THE SOFTWARE.
|
---|
42 | */
|
---|
43 | #include "DrvAudio.h"
|
---|
44 | #include "VBoxDD.h"
|
---|
45 | #include "vl_vbox.h"
|
---|
46 |
|
---|
47 | #include <iprt/alloc.h>
|
---|
48 | #include <iprt/uuid.h> /* For PDMIBASE_2_PDMDRV. */
|
---|
49 | #include <VBox/vmm/pdmaudioifs.h>
|
---|
50 |
|
---|
51 | #ifdef LOG_GROUP
|
---|
52 | # undef LOG_GROUP
|
---|
53 | #endif
|
---|
54 | #define LOG_GROUP LOG_GROUP_DEV_AUDIO
|
---|
55 | #include <VBox/log.h>
|
---|
56 |
|
---|
57 | typedef struct NULLAUDIOSTREAMOUT
|
---|
58 | {
|
---|
59 | /** Note: Always must come first! */
|
---|
60 | PDMAUDIOHSTSTRMOUT hw;
|
---|
61 | } NULLAUDIOSTREAMOUT;
|
---|
62 |
|
---|
63 | typedef struct NULLAUDIOSTREAMIN
|
---|
64 | {
|
---|
65 | /** Note: Always must come first! */
|
---|
66 | PDMAUDIOHSTSTRMIN hw;
|
---|
67 | } NULLAUDIOSTREAMIN;
|
---|
68 |
|
---|
69 | /**
|
---|
70 | * NULL audio driver instance data.
|
---|
71 | * @implements PDMIAUDIOCONNECTOR
|
---|
72 | */
|
---|
73 | typedef struct DRVHOSTNULLAUDIO
|
---|
74 | {
|
---|
75 | /** Pointer to the driver instance structure. */
|
---|
76 | PPDMDRVINS pDrvIns;
|
---|
77 | /** Pointer to host audio interface. */
|
---|
78 | PDMIHOSTAUDIO IHostAudio;
|
---|
79 | } DRVHOSTNULLAUDIO, *PDRVHOSTNULLAUDIO;
|
---|
80 |
|
---|
81 | /*******************************************PDM_AUDIO_DRIVER******************************/
|
---|
82 |
|
---|
83 |
|
---|
84 | static DECLCALLBACK(int) drvHostNullAudioGetConf(PPDMIHOSTAUDIO pInterface, PPDMAUDIOBACKENDCFG pCfg)
|
---|
85 | {
|
---|
86 | NOREF(pInterface);
|
---|
87 | AssertPtrReturn(pCfg, VERR_INVALID_POINTER);
|
---|
88 |
|
---|
89 | pCfg->cbStreamOut = sizeof(NULLAUDIOSTREAMOUT);
|
---|
90 | pCfg->cbStreamIn = sizeof(NULLAUDIOSTREAMIN);
|
---|
91 |
|
---|
92 | pCfg->cMaxHstStrmsOut = 1; /* Output */
|
---|
93 | pCfg->cMaxHstStrmsIn = 2; /* Line input + microphone input. */
|
---|
94 |
|
---|
95 | return VINF_SUCCESS;
|
---|
96 | }
|
---|
97 |
|
---|
98 | static DECLCALLBACK(int) drvHostNullAudioInit(PPDMIHOSTAUDIO pInterface)
|
---|
99 | {
|
---|
100 | NOREF(pInterface);
|
---|
101 |
|
---|
102 | return VINF_SUCCESS;
|
---|
103 | }
|
---|
104 |
|
---|
105 | static DECLCALLBACK(int) drvHostNullAudioInitIn(PPDMIHOSTAUDIO pInterface,
|
---|
106 | PPDMAUDIOHSTSTRMIN pHstStrmIn, PPDMAUDIOSTREAMCFG pCfg,
|
---|
107 | PDMAUDIORECSOURCE enmRecSource,
|
---|
108 | uint32_t *pcSamples)
|
---|
109 | {
|
---|
110 | NOREF(pInterface);
|
---|
111 | NOREF(enmRecSource);
|
---|
112 |
|
---|
113 | /* Just adopt the wanted stream configuration. */
|
---|
114 | int rc = drvAudioStreamCfgToProps(pCfg, &pHstStrmIn->Props);
|
---|
115 | if (RT_SUCCESS(rc))
|
---|
116 | {
|
---|
117 | if (pcSamples)
|
---|
118 | *pcSamples = 256;
|
---|
119 | }
|
---|
120 |
|
---|
121 | return VINF_SUCCESS;
|
---|
122 | }
|
---|
123 |
|
---|
124 | static DECLCALLBACK(int) drvHostNullAudioInitOut(PPDMIHOSTAUDIO pInterface,
|
---|
125 | PPDMAUDIOHSTSTRMOUT pHstStrmOut, PPDMAUDIOSTREAMCFG pCfg,
|
---|
126 | uint32_t *pcSamples)
|
---|
127 | {
|
---|
128 | NOREF(pInterface);
|
---|
129 |
|
---|
130 | /* Just adopt the wanted stream configuration. */
|
---|
131 | int rc = drvAudioStreamCfgToProps(pCfg, &pHstStrmOut->Props);
|
---|
132 | if (RT_SUCCESS(rc))
|
---|
133 | {
|
---|
134 | if (pcSamples)
|
---|
135 | *pcSamples = 256;
|
---|
136 | }
|
---|
137 |
|
---|
138 | return rc;
|
---|
139 | }
|
---|
140 |
|
---|
141 | static DECLCALLBACK(bool) drvHostNullAudioIsEnabled(PPDMIHOSTAUDIO pInterface, PDMAUDIODIR enmDir)
|
---|
142 | {
|
---|
143 | NOREF(pInterface);
|
---|
144 | NOREF(enmDir);
|
---|
145 | return true; /* Always all enabled. */
|
---|
146 | }
|
---|
147 |
|
---|
148 | static DECLCALLBACK(int) drvHostNullAudioPlayOut(PPDMIHOSTAUDIO pInterface, PPDMAUDIOHSTSTRMOUT pHstStrmOut,
|
---|
149 | uint32_t *pcSamplesPlayed)
|
---|
150 | {
|
---|
151 | if (pcSamplesPlayed)
|
---|
152 | *pcSamplesPlayed = UINT32_MAX;
|
---|
153 |
|
---|
154 | return VINF_SUCCESS;
|
---|
155 | }
|
---|
156 |
|
---|
157 | static DECLCALLBACK(int) drvHostNullAudioCaptureIn(PPDMIHOSTAUDIO pInterface, PPDMAUDIOHSTSTRMIN pHstStrmIn,
|
---|
158 | uint32_t *pcSamplesCaptured)
|
---|
159 | {
|
---|
160 | if (pcSamplesCaptured)
|
---|
161 | *pcSamplesCaptured = 0;
|
---|
162 |
|
---|
163 | return VINF_SUCCESS;
|
---|
164 | }
|
---|
165 |
|
---|
166 | static DECLCALLBACK(int) drvHostNullAudioControlIn(PPDMIHOSTAUDIO pInterface, PPDMAUDIOHSTSTRMIN pHstStrmIn,
|
---|
167 | PDMAUDIOSTREAMCMD enmStreamCmd)
|
---|
168 | {
|
---|
169 | NOREF(pInterface);
|
---|
170 | NOREF(pHstStrmIn);
|
---|
171 | NOREF(enmStreamCmd);
|
---|
172 |
|
---|
173 | return VINF_SUCCESS;
|
---|
174 | }
|
---|
175 |
|
---|
176 | static DECLCALLBACK(int) drvHostNullAudioControlOut(PPDMIHOSTAUDIO pInterface, PPDMAUDIOHSTSTRMOUT pHstStrmOut,
|
---|
177 | PDMAUDIOSTREAMCMD enmStreamCmd)
|
---|
178 | {
|
---|
179 | NOREF(pInterface);
|
---|
180 | NOREF(pHstStrmOut);
|
---|
181 | NOREF(enmStreamCmd);
|
---|
182 |
|
---|
183 | return VINF_SUCCESS;
|
---|
184 | }
|
---|
185 |
|
---|
186 | static DECLCALLBACK(int) drvHostNullAudioFiniIn(PPDMIHOSTAUDIO pInterface, PPDMAUDIOHSTSTRMIN pHstStrmIn)
|
---|
187 | {
|
---|
188 | return VINF_SUCCESS;
|
---|
189 | }
|
---|
190 |
|
---|
191 | static DECLCALLBACK(int) drvHostNullAudioFiniOut(PPDMIHOSTAUDIO pInterface, PPDMAUDIOHSTSTRMOUT pHstStrmOut)
|
---|
192 | {
|
---|
193 | return VINF_SUCCESS;
|
---|
194 | }
|
---|
195 |
|
---|
196 | /**
|
---|
197 | * @interface_method_impl{PDMIBASE,pfnQueryInterface}
|
---|
198 | */
|
---|
199 | static DECLCALLBACK(void *) drvHostNullAudioQueryInterface(PPDMIBASE pInterface, const char *pszIID)
|
---|
200 | {
|
---|
201 | PPDMDRVINS pDrvIns = PDMIBASE_2_PDMDRV(pInterface);
|
---|
202 | PDRVHOSTNULLAUDIO pThis = PDMINS_2_DATA(pDrvIns, PDRVHOSTNULLAUDIO);
|
---|
203 |
|
---|
204 | PDMIBASE_RETURN_INTERFACE(pszIID, PDMIBASE, &pDrvIns->IBase);
|
---|
205 | PDMIBASE_RETURN_INTERFACE(pszIID, PDMIHOSTAUDIO, &pThis->IHostAudio);
|
---|
206 | return NULL;
|
---|
207 | }
|
---|
208 |
|
---|
209 | static DECLCALLBACK(void) drvHostNullAudioShutdown(PPDMIHOSTAUDIO pInterface)
|
---|
210 | {
|
---|
211 | NOREF(pInterface);
|
---|
212 | }
|
---|
213 |
|
---|
214 | /**
|
---|
215 | * Constructs a Null audio driver instance.
|
---|
216 | *
|
---|
217 | * @copydoc FNPDMDRVCONSTRUCT
|
---|
218 | */
|
---|
219 | static DECLCALLBACK(int) drvHostNullAudioConstruct(PPDMDRVINS pDrvIns, PCFGMNODE pCfg, uint32_t fFlags)
|
---|
220 | {
|
---|
221 | AssertPtrReturn(pDrvIns, VERR_INVALID_POINTER);
|
---|
222 | /* pCfg is optional. */
|
---|
223 |
|
---|
224 | PDRVHOSTNULLAUDIO pThis = PDMINS_2_DATA(pDrvIns, PDRVHOSTNULLAUDIO);
|
---|
225 | LogRel(("Audio: Initializing NULL driver\n"));
|
---|
226 |
|
---|
227 | /*
|
---|
228 | * Init the static parts.
|
---|
229 | */
|
---|
230 | pThis->pDrvIns = pDrvIns;
|
---|
231 | /* IBase */
|
---|
232 | pDrvIns->IBase.pfnQueryInterface = drvHostNullAudioQueryInterface;
|
---|
233 | /* IHostAudio */
|
---|
234 | PDMAUDIO_IHOSTAUDIO_CALLBACKS(drvHostNullAudio);
|
---|
235 |
|
---|
236 | return VINF_SUCCESS;
|
---|
237 | }
|
---|
238 |
|
---|
239 | /**
|
---|
240 | * Char driver registration record.
|
---|
241 | */
|
---|
242 | const PDMDRVREG g_DrvHostNullAudio =
|
---|
243 | {
|
---|
244 | /* u32Version */
|
---|
245 | PDM_DRVREG_VERSION,
|
---|
246 | /* szName */
|
---|
247 | "NullAudio",
|
---|
248 | /* szRCMod */
|
---|
249 | "",
|
---|
250 | /* szR0Mod */
|
---|
251 | "",
|
---|
252 | /* pszDescription */
|
---|
253 | "NULL audio host driver",
|
---|
254 | /* fFlags */
|
---|
255 | PDM_DRVREG_FLAGS_HOST_BITS_DEFAULT,
|
---|
256 | /* fClass. */
|
---|
257 | PDM_DRVREG_CLASS_AUDIO,
|
---|
258 | /* cMaxInstances */
|
---|
259 | ~0U,
|
---|
260 | /* cbInstance */
|
---|
261 | sizeof(DRVHOSTNULLAUDIO),
|
---|
262 | /* pfnConstruct */
|
---|
263 | drvHostNullAudioConstruct,
|
---|
264 | /* pfnDestruct */
|
---|
265 | NULL,
|
---|
266 | /* pfnRelocate */
|
---|
267 | NULL,
|
---|
268 | /* pfnIOCtl */
|
---|
269 | NULL,
|
---|
270 | /* pfnPowerOn */
|
---|
271 | NULL,
|
---|
272 | /* pfnReset */
|
---|
273 | NULL,
|
---|
274 | /* pfnSuspend */
|
---|
275 | NULL,
|
---|
276 | /* pfnResume */
|
---|
277 | NULL,
|
---|
278 | /* pfnAttach */
|
---|
279 | NULL,
|
---|
280 | /* pfnDetach */
|
---|
281 | NULL,
|
---|
282 | /* pfnPowerOff */
|
---|
283 | NULL,
|
---|
284 | /* pfnSoftReset */
|
---|
285 | NULL,
|
---|
286 | /* u32EndVersion */
|
---|
287 | PDM_DRVREG_VERSION
|
---|
288 | };
|
---|
289 |
|
---|