VirtualBox

source: vbox/trunk/src/VBox/Devices/Audio/DrvHostNullAudio.cpp@ 80596

Last change on this file since 80596 was 76553, checked in by vboxsync, 6 years ago

scm --update-copyright-year

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 11.7 KB
Line 
1/* $Id: DrvHostNullAudio.cpp 76553 2019-01-01 01:45:53Z vboxsync $ */
2/** @file
3 * NULL audio driver.
4 *
5 * This also acts as a fallback if no other backend is available.
6 */
7
8/*
9 * Copyright (C) 2006-2019 Oracle Corporation
10 *
11 * This file is part of VirtualBox Open Source Edition (OSE), as
12 * available from http://www.virtualbox.org. This file is free software;
13 * you can redistribute it and/or modify it under the terms of the GNU
14 * General Public License (GPL) as published by the Free Software
15 * Foundation, in version 2 as it comes in the "COPYING" file of the
16 * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
17 * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
18 * --------------------------------------------------------------------
19 *
20 * This code is based on: noaudio.c QEMU based code.
21 *
22 * QEMU Timer based audio emulation
23 *
24 * Copyright (c) 2004-2005 Vassili Karpov (malc)
25 *
26 * Permission is hereby granted, free of charge, to any person obtaining a copy
27 * of this software and associated documentation files (the "Software"), to deal
28 * in the Software without restriction, including without limitation the rights
29 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
30 * copies of the Software, and to permit persons to whom the Software is
31 * furnished to do so, subject to the following conditions:
32 *
33 * The above copyright notice and this permission notice shall be included in
34 * all copies or substantial portions of the Software.
35 *
36 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
37 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
38 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
39 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
40 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
41 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
42 * THE SOFTWARE.
43 */
44
45
46/*********************************************************************************************************************************
47* Header Files *
48*********************************************************************************************************************************/
49#include <iprt/mem.h>
50#include <iprt/uuid.h> /* For PDMIBASE_2_PDMDRV. */
51
52#define LOG_GROUP LOG_GROUP_DRV_HOST_AUDIO
53#include <VBox/log.h>
54#include <VBox/vmm/pdmaudioifs.h>
55
56#include "DrvAudio.h"
57#include "VBoxDD.h"
58
59
60/*********************************************************************************************************************************
61* Structures and Typedefs *
62*********************************************************************************************************************************/
63typedef struct NULLAUDIOSTREAM
64{
65 /** The stream's acquired configuration. */
66 PPDMAUDIOSTREAMCFG pCfg;
67} NULLAUDIOSTREAM, *PNULLAUDIOSTREAM;
68
69/**
70 * NULL audio driver instance data.
71 * @implements PDMIAUDIOCONNECTOR
72 */
73typedef 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
82
83/**
84 * @interface_method_impl{PDMIHOSTAUDIO,pfnGetConfig}
85 */
86static DECLCALLBACK(int) drvHostNullAudioGetConfig(PPDMIHOSTAUDIO pInterface, PPDMAUDIOBACKENDCFG pBackendCfg)
87{
88 NOREF(pInterface);
89 AssertPtrReturn(pBackendCfg, VERR_INVALID_POINTER);
90
91 RTStrPrintf2(pBackendCfg->szName, sizeof(pBackendCfg->szName), "NULL audio driver");
92
93 pBackendCfg->cbStreamOut = sizeof(NULLAUDIOSTREAM);
94 pBackendCfg->cbStreamIn = sizeof(NULLAUDIOSTREAM);
95
96 pBackendCfg->cMaxStreamsOut = 1; /* Output */
97 pBackendCfg->cMaxStreamsIn = 2; /* Line input + microphone input. */
98
99 return VINF_SUCCESS;
100}
101
102
103/**
104 * @interface_method_impl{PDMIHOSTAUDIO,pfnInit}
105 */
106static DECLCALLBACK(int) drvHostNullAudioInit(PPDMIHOSTAUDIO pInterface)
107{
108 NOREF(pInterface);
109
110 LogFlowFuncLeaveRC(VINF_SUCCESS);
111 return VINF_SUCCESS;
112}
113
114
115/**
116 * @interface_method_impl{PDMIHOSTAUDIO,pfnShutdown}
117 */
118static DECLCALLBACK(void) drvHostNullAudioShutdown(PPDMIHOSTAUDIO pInterface)
119{
120 RT_NOREF(pInterface);
121}
122
123
124/**
125 * @interface_method_impl{PDMIHOSTAUDIO,pfnGetStatus}
126 */
127static DECLCALLBACK(PDMAUDIOBACKENDSTS) drvHostNullAudioGetStatus(PPDMIHOSTAUDIO pInterface, PDMAUDIODIR enmDir)
128{
129 RT_NOREF(enmDir);
130 AssertPtrReturn(pInterface, PDMAUDIOBACKENDSTS_UNKNOWN);
131
132 return PDMAUDIOBACKENDSTS_RUNNING;
133}
134
135
136/**
137 * @interface_method_impl{PDMIHOSTAUDIO,pfnStreamPlay}
138 */
139static DECLCALLBACK(int) drvHostNullAudioStreamPlay(PPDMIHOSTAUDIO pInterface, PPDMAUDIOBACKENDSTREAM pStream,
140 const void *pvBuf, uint32_t cxBuf, uint32_t *pcxWritten)
141{
142 AssertPtrReturn(pInterface, VERR_INVALID_POINTER);
143 AssertPtrReturn(pStream, VERR_INVALID_POINTER);
144 AssertPtrReturn(pvBuf, VERR_INVALID_POINTER);
145 AssertReturn(cxBuf, VERR_INVALID_PARAMETER);
146
147 RT_NOREF(pInterface, pStream, pvBuf);
148
149 /* Note: No copying of samples needed here, as this a NULL backend. */
150
151 if (pcxWritten)
152 *pcxWritten = cxBuf; /* Return all bytes as written. */
153
154 return VINF_SUCCESS;
155}
156
157
158/**
159 * @interface_method_impl{PDMIHOSTAUDIO,pfnStreamCapture}
160 */
161static DECLCALLBACK(int) drvHostNullAudioStreamCapture(PPDMIHOSTAUDIO pInterface, PPDMAUDIOBACKENDSTREAM pStream,
162 void *pvBuf, uint32_t cxBuf, uint32_t *pcxRead)
163{
164 RT_NOREF(pInterface, pStream);
165
166 PNULLAUDIOSTREAM pStreamNull = (PNULLAUDIOSTREAM)pStream;
167
168 /* Return silence. */
169 Assert(pStreamNull->pCfg);
170 DrvAudioHlpClearBuf(&pStreamNull->pCfg->Props, pvBuf, cxBuf, PDMAUDIOPCMPROPS_B2F(&pStreamNull->pCfg->Props, cxBuf));
171
172 if (pcxRead)
173 *pcxRead = cxBuf;
174
175 return VINF_SUCCESS;
176}
177
178
179static int nullCreateStreamIn(PNULLAUDIOSTREAM pStreamNull, PPDMAUDIOSTREAMCFG pCfgReq, PPDMAUDIOSTREAMCFG pCfgAcq)
180{
181 RT_NOREF(pStreamNull, pCfgReq, pCfgAcq);
182
183 return VINF_SUCCESS;
184}
185
186
187static int nullCreateStreamOut(PNULLAUDIOSTREAM pStreamNull, PPDMAUDIOSTREAMCFG pCfgReq, PPDMAUDIOSTREAMCFG pCfgAcq)
188{
189 RT_NOREF(pStreamNull, pCfgReq, pCfgAcq);
190
191 return VINF_SUCCESS;
192}
193
194
195/**
196 * @interface_method_impl{PDMIHOSTAUDIO,pfnStreamCreate}
197 */
198static DECLCALLBACK(int) drvHostNullAudioStreamCreate(PPDMIHOSTAUDIO pInterface, PPDMAUDIOBACKENDSTREAM pStream,
199 PPDMAUDIOSTREAMCFG pCfgReq, PPDMAUDIOSTREAMCFG pCfgAcq)
200{
201 AssertPtrReturn(pInterface, VERR_INVALID_POINTER);
202 AssertPtrReturn(pStream, VERR_INVALID_POINTER);
203 AssertPtrReturn(pCfgReq, VERR_INVALID_POINTER);
204 AssertPtrReturn(pCfgAcq, VERR_INVALID_POINTER);
205
206 PNULLAUDIOSTREAM pStreamNull = (PNULLAUDIOSTREAM)pStream;
207
208 int rc;
209 if (pCfgReq->enmDir == PDMAUDIODIR_IN)
210 rc = nullCreateStreamIn( pStreamNull, pCfgReq, pCfgAcq);
211 else
212 rc = nullCreateStreamOut(pStreamNull, pCfgReq, pCfgAcq);
213
214 if (RT_SUCCESS(rc))
215 {
216 pStreamNull->pCfg = DrvAudioHlpStreamCfgDup(pCfgAcq);
217 if (!pStreamNull->pCfg)
218 rc = VERR_NO_MEMORY;
219 }
220
221 return rc;
222}
223
224
225static int nullDestroyStreamIn(void)
226{
227 LogFlowFuncLeaveRC(VINF_SUCCESS);
228 return VINF_SUCCESS;
229}
230
231
232static int nullDestroyStreamOut(PNULLAUDIOSTREAM pStreamNull)
233{
234 RT_NOREF(pStreamNull);
235 return VINF_SUCCESS;
236}
237
238
239/**
240 * @interface_method_impl{PDMIHOSTAUDIO,pfnStreamDestroy}
241 */
242static DECLCALLBACK(int) drvHostNullAudioStreamDestroy(PPDMIHOSTAUDIO pInterface, PPDMAUDIOBACKENDSTREAM pStream)
243{
244 AssertPtrReturn(pInterface, VERR_INVALID_POINTER);
245 AssertPtrReturn(pStream, VERR_INVALID_POINTER);
246
247 PNULLAUDIOSTREAM pStreamNull = (PNULLAUDIOSTREAM)pStream;
248
249 if (!pStreamNull->pCfg) /* Not (yet) configured? Skip. */
250 return VINF_SUCCESS;
251
252 int rc;
253 if (pStreamNull->pCfg->enmDir == PDMAUDIODIR_IN)
254 rc = nullDestroyStreamIn();
255 else
256 rc = nullDestroyStreamOut(pStreamNull);
257
258 if (RT_SUCCESS(rc))
259 {
260 DrvAudioHlpStreamCfgFree(pStreamNull->pCfg);
261 pStreamNull->pCfg = NULL;
262 }
263
264 return rc;
265}
266
267
268/**
269 * @interface_method_impl{PDMIHOSTAUDIO,pfnStreamControl}
270 */
271static DECLCALLBACK(int) drvHostNullAudioStreamControl(PPDMIHOSTAUDIO pInterface,
272 PPDMAUDIOBACKENDSTREAM pStream, PDMAUDIOSTREAMCMD enmStreamCmd)
273{
274 RT_NOREF(pInterface, pStream, enmStreamCmd);
275 return VINF_SUCCESS;
276}
277
278
279/**
280 * @interface_method_impl{PDMIHOSTAUDIO,pfnStreamGetReadable}
281 */
282static DECLCALLBACK(uint32_t) drvHostNullAudioStreamGetReadable(PPDMIHOSTAUDIO pInterface, PPDMAUDIOBACKENDSTREAM pStream)
283{
284 RT_NOREF(pInterface, pStream);
285
286 return UINT32_MAX;
287}
288
289
290/**
291 * @interface_method_impl{PDMIHOSTAUDIO,pfnStreamGetWritable}
292 */
293static DECLCALLBACK(uint32_t) drvHostNullAudioStreamGetWritable(PPDMIHOSTAUDIO pInterface, PPDMAUDIOBACKENDSTREAM pStream)
294{
295 RT_NOREF(pInterface, pStream);
296
297 return UINT32_MAX;
298}
299
300
301/**
302 * @interface_method_impl{PDMIHOSTAUDIO,pfnStreamGetStatus}
303 */
304static DECLCALLBACK(PDMAUDIOSTREAMSTS) drvHostNullAudioStreamGetStatus(PPDMIHOSTAUDIO pInterface, PPDMAUDIOBACKENDSTREAM pStream)
305{
306 RT_NOREF(pInterface, pStream);
307 return PDMAUDIOSTREAMSTS_FLAG_INITIALIZED | PDMAUDIOSTREAMSTS_FLAG_ENABLED;
308}
309
310
311/**
312 * @interface_method_impl{PDMIHOSTAUDIO,pfnStreamIterate}
313 */
314static DECLCALLBACK(int) drvHostNullAudioStreamIterate(PPDMIHOSTAUDIO pInterface, PPDMAUDIOBACKENDSTREAM pStream)
315{
316 NOREF(pInterface);
317 NOREF(pStream);
318
319 return VINF_SUCCESS;
320}
321
322
323/**
324 * @interface_method_impl{PDMIBASE,pfnQueryInterface}
325 */
326static DECLCALLBACK(void *) drvHostNullAudioQueryInterface(PPDMIBASE pInterface, const char *pszIID)
327{
328 PPDMDRVINS pDrvIns = PDMIBASE_2_PDMDRV(pInterface);
329 PDRVHOSTNULLAUDIO pThis = PDMINS_2_DATA(pDrvIns, PDRVHOSTNULLAUDIO);
330
331 PDMIBASE_RETURN_INTERFACE(pszIID, PDMIBASE, &pDrvIns->IBase);
332 PDMIBASE_RETURN_INTERFACE(pszIID, PDMIHOSTAUDIO, &pThis->IHostAudio);
333 return NULL;
334}
335
336
337/**
338 * Constructs a Null audio driver instance.
339 *
340 * @copydoc FNPDMDRVCONSTRUCT
341 */
342static DECLCALLBACK(int) drvHostNullAudioConstruct(PPDMDRVINS pDrvIns, PCFGMNODE pCfg, uint32_t fFlags)
343{
344 RT_NOREF(pCfg, fFlags);
345 PDMDRV_CHECK_VERSIONS_RETURN(pDrvIns);
346 AssertPtrReturn(pDrvIns, VERR_INVALID_POINTER);
347 /* pCfg is optional. */
348
349 PDRVHOSTNULLAUDIO pThis = PDMINS_2_DATA(pDrvIns, PDRVHOSTNULLAUDIO);
350 LogRel(("Audio: Initializing NULL driver\n"));
351
352 /*
353 * Init the static parts.
354 */
355 pThis->pDrvIns = pDrvIns;
356 /* IBase */
357 pDrvIns->IBase.pfnQueryInterface = drvHostNullAudioQueryInterface;
358 /* IHostAudio */
359 PDMAUDIO_IHOSTAUDIO_CALLBACKS(drvHostNullAudio);
360
361 return VINF_SUCCESS;
362}
363
364
365/**
366 * Char driver registration record.
367 */
368const PDMDRVREG g_DrvHostNullAudio =
369{
370 /* u32Version */
371 PDM_DRVREG_VERSION,
372 /* szName */
373 "NullAudio",
374 /* szRCMod */
375 "",
376 /* szR0Mod */
377 "",
378 /* pszDescription */
379 "NULL audio host driver",
380 /* fFlags */
381 PDM_DRVREG_FLAGS_HOST_BITS_DEFAULT,
382 /* fClass. */
383 PDM_DRVREG_CLASS_AUDIO,
384 /* cMaxInstances */
385 ~0U,
386 /* cbInstance */
387 sizeof(DRVHOSTNULLAUDIO),
388 /* pfnConstruct */
389 drvHostNullAudioConstruct,
390 /* pfnDestruct */
391 NULL,
392 /* pfnRelocate */
393 NULL,
394 /* pfnIOCtl */
395 NULL,
396 /* pfnPowerOn */
397 NULL,
398 /* pfnReset */
399 NULL,
400 /* pfnSuspend */
401 NULL,
402 /* pfnResume */
403 NULL,
404 /* pfnAttach */
405 NULL,
406 /* pfnDetach */
407 NULL,
408 /* pfnPowerOff */
409 NULL,
410 /* pfnSoftReset */
411 NULL,
412 /* u32EndVersion */
413 PDM_DRVREG_VERSION
414};
415
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