VirtualBox

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

Last change on this file since 82331 was 82255, checked in by vboxsync, 5 years ago

vmm/pdmaudioifs.h: More of the same. bugref:9218

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 13.1 KB
Line 
1/* $Id: DrvHostNullAudio.cpp 82255 2019-11-27 23:20:26Z 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) drvHostNullAudioHA_GetConfig(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) drvHostNullAudioHA_Init(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) drvHostNullAudioHA_Shutdown(PPDMIHOSTAUDIO pInterface)
119{
120 RT_NOREF(pInterface);
121}
122
123
124/**
125 * @interface_method_impl{PDMIHOSTAUDIO,pfnGetStatus}
126 */
127static DECLCALLBACK(PDMAUDIOBACKENDSTS) drvHostNullAudioHA_GetStatus(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) drvHostNullAudioHA_StreamPlay(PPDMIHOSTAUDIO pInterface, PPDMAUDIOBACKENDSTREAM pStream,
140 const void *pvBuf, uint32_t uBufSize, uint32_t *puWritten)
141{
142 AssertPtrReturn(pInterface, VERR_INVALID_POINTER);
143 AssertPtrReturn(pStream, VERR_INVALID_POINTER);
144 AssertPtrReturn(pvBuf, VERR_INVALID_POINTER);
145 AssertReturn(uBufSize, 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 (puWritten)
152 *puWritten = uBufSize; /* Return all bytes as written. */
153
154 return VINF_SUCCESS;
155}
156
157
158/**
159 * @interface_method_impl{PDMIHOSTAUDIO,pfnStreamCapture}
160 */
161static DECLCALLBACK(int) drvHostNullAudioHA_StreamCapture(PPDMIHOSTAUDIO pInterface, PPDMAUDIOBACKENDSTREAM pStream,
162 void *pvBuf, uint32_t uBufSize, uint32_t *puRead)
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, uBufSize, PDMAUDIOPCMPROPS_B2F(&pStreamNull->pCfg->Props, uBufSize));
171
172 if (puRead)
173 *puRead = uBufSize;
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) drvHostNullAudioHA_StreamCreate(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) drvHostNullAudioHA_StreamDestroy(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) drvHostNullAudioHA_StreamControl(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) drvHostNullAudioHA_StreamGetReadable(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) drvHostNullAudioHA_StreamGetWritable(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) drvHostNullAudioHA_StreamGetStatus(PPDMIHOSTAUDIO pInterface, PPDMAUDIOBACKENDSTREAM pStream)
305{
306 RT_NOREF(pInterface, pStream);
307 return PDMAUDIOSTREAMSTS_FLAGS_INITIALIZED | PDMAUDIOSTREAMSTS_FLAGS_ENABLED;
308}
309
310
311/**
312 * @interface_method_impl{PDMIHOSTAUDIO,pfnStreamIterate}
313 */
314static DECLCALLBACK(int) drvHostNullAudioHA_StreamIterate(PPDMIHOSTAUDIO pInterface, PPDMAUDIOBACKENDSTREAM pStream)
315{
316 RT_NOREF(pInterface, pStream);
317 return VINF_SUCCESS;
318}
319
320
321/**
322 * @interface_method_impl{PDMIBASE,pfnQueryInterface}
323 */
324static DECLCALLBACK(void *) drvHostNullAudioQueryInterface(PPDMIBASE pInterface, const char *pszIID)
325{
326 PPDMDRVINS pDrvIns = PDMIBASE_2_PDMDRV(pInterface);
327 PDRVHOSTNULLAUDIO pThis = PDMINS_2_DATA(pDrvIns, PDRVHOSTNULLAUDIO);
328
329 PDMIBASE_RETURN_INTERFACE(pszIID, PDMIBASE, &pDrvIns->IBase);
330 PDMIBASE_RETURN_INTERFACE(pszIID, PDMIHOSTAUDIO, &pThis->IHostAudio);
331 return NULL;
332}
333
334
335/**
336 * Constructs a Null audio driver instance.
337 *
338 * @copydoc FNPDMDRVCONSTRUCT
339 */
340static DECLCALLBACK(int) drvHostNullAudioConstruct(PPDMDRVINS pDrvIns, PCFGMNODE pCfg, uint32_t fFlags)
341{
342 RT_NOREF(pCfg, fFlags);
343 PDMDRV_CHECK_VERSIONS_RETURN(pDrvIns);
344 AssertPtrReturn(pDrvIns, VERR_INVALID_POINTER);
345 /* pCfg is optional. */
346
347 PDRVHOSTNULLAUDIO pThis = PDMINS_2_DATA(pDrvIns, PDRVHOSTNULLAUDIO);
348 LogRel(("Audio: Initializing NULL driver\n"));
349
350 /*
351 * Init the static parts.
352 */
353 pThis->pDrvIns = pDrvIns;
354 /* IBase */
355 pDrvIns->IBase.pfnQueryInterface = drvHostNullAudioQueryInterface;
356 /* IHostAudio */
357 pThis->IHostAudio.pfnInit = drvHostNullAudioHA_Init;
358 pThis->IHostAudio.pfnShutdown = drvHostNullAudioHA_Shutdown;
359 pThis->IHostAudio.pfnGetConfig = drvHostNullAudioHA_GetConfig;
360 pThis->IHostAudio.pfnGetStatus = drvHostNullAudioHA_GetStatus;
361 pThis->IHostAudio.pfnStreamCreate = drvHostNullAudioHA_StreamCreate;
362 pThis->IHostAudio.pfnStreamDestroy = drvHostNullAudioHA_StreamDestroy;
363 pThis->IHostAudio.pfnStreamControl = drvHostNullAudioHA_StreamControl;
364 pThis->IHostAudio.pfnStreamGetReadable = drvHostNullAudioHA_StreamGetReadable;
365 pThis->IHostAudio.pfnStreamGetWritable = drvHostNullAudioHA_StreamGetWritable;
366 pThis->IHostAudio.pfnStreamGetStatus = drvHostNullAudioHA_StreamGetStatus;
367 pThis->IHostAudio.pfnStreamIterate = drvHostNullAudioHA_StreamIterate;
368 pThis->IHostAudio.pfnStreamPlay = drvHostNullAudioHA_StreamPlay;
369 pThis->IHostAudio.pfnStreamCapture = drvHostNullAudioHA_StreamCapture;
370 pThis->IHostAudio.pfnSetCallback = NULL;
371 pThis->IHostAudio.pfnGetDevices = NULL;
372 pThis->IHostAudio.pfnStreamGetPending = NULL;
373 pThis->IHostAudio.pfnStreamPlayBegin = NULL;
374 pThis->IHostAudio.pfnStreamPlayEnd = NULL;
375 pThis->IHostAudio.pfnStreamCaptureBegin = NULL;
376 pThis->IHostAudio.pfnStreamCaptureEnd = NULL;
377
378 return VINF_SUCCESS;
379}
380
381
382/**
383 * Char driver registration record.
384 */
385const PDMDRVREG g_DrvHostNullAudio =
386{
387 /* u32Version */
388 PDM_DRVREG_VERSION,
389 /* szName */
390 "NullAudio",
391 /* szRCMod */
392 "",
393 /* szR0Mod */
394 "",
395 /* pszDescription */
396 "NULL audio host driver",
397 /* fFlags */
398 PDM_DRVREG_FLAGS_HOST_BITS_DEFAULT,
399 /* fClass. */
400 PDM_DRVREG_CLASS_AUDIO,
401 /* cMaxInstances */
402 ~0U,
403 /* cbInstance */
404 sizeof(DRVHOSTNULLAUDIO),
405 /* pfnConstruct */
406 drvHostNullAudioConstruct,
407 /* pfnDestruct */
408 NULL,
409 /* pfnRelocate */
410 NULL,
411 /* pfnIOCtl */
412 NULL,
413 /* pfnPowerOn */
414 NULL,
415 /* pfnReset */
416 NULL,
417 /* pfnSuspend */
418 NULL,
419 /* pfnResume */
420 NULL,
421 /* pfnAttach */
422 NULL,
423 /* pfnDetach */
424 NULL,
425 /* pfnPowerOff */
426 NULL,
427 /* pfnSoftReset */
428 NULL,
429 /* u32EndVersion */
430 PDM_DRVREG_VERSION
431};
432
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