VirtualBox

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

Last change on this file since 69119 was 69119, checked in by vboxsync, 7 years ago

Audio: More cleanups (missing keywords, incorrect #endif docs, stuff)

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 11.6 KB
Line 
1/* $Id: DrvHostNullAudio.cpp 69119 2017-10-17 19:08:38Z 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-2017 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 pBackendCfg->cbStreamOut = sizeof(NULLAUDIOSTREAM);
92 pBackendCfg->cbStreamIn = sizeof(NULLAUDIOSTREAM);
93
94 pBackendCfg->cMaxStreamsOut = 1; /* Output */
95 pBackendCfg->cMaxStreamsIn = 2; /* Line input + microphone input. */
96
97 return VINF_SUCCESS;
98}
99
100
101/**
102 * @interface_method_impl{PDMIHOSTAUDIO,pfnInit}
103 */
104static DECLCALLBACK(int) drvHostNullAudioInit(PPDMIHOSTAUDIO pInterface)
105{
106 NOREF(pInterface);
107
108 LogFlowFuncLeaveRC(VINF_SUCCESS);
109 return VINF_SUCCESS;
110}
111
112
113/**
114 * @interface_method_impl{PDMIHOSTAUDIO,pfnShutdown}
115 */
116static DECLCALLBACK(void) drvHostNullAudioShutdown(PPDMIHOSTAUDIO pInterface)
117{
118 RT_NOREF(pInterface);
119}
120
121
122/**
123 * @interface_method_impl{PDMIHOSTAUDIO,pfnGetStatus}
124 */
125static DECLCALLBACK(PDMAUDIOBACKENDSTS) drvHostNullAudioGetStatus(PPDMIHOSTAUDIO pInterface, PDMAUDIODIR enmDir)
126{
127 RT_NOREF(enmDir);
128 AssertPtrReturn(pInterface, PDMAUDIOBACKENDSTS_UNKNOWN);
129
130 return PDMAUDIOBACKENDSTS_RUNNING;
131}
132
133
134/**
135 * @interface_method_impl{PDMIHOSTAUDIO,pfnStreamPlay}
136 */
137static DECLCALLBACK(int) drvHostNullAudioStreamPlay(PPDMIHOSTAUDIO pInterface, PPDMAUDIOBACKENDSTREAM pStream,
138 const void *pvBuf, uint32_t cxBuf, uint32_t *pcxWritten)
139{
140 AssertPtrReturn(pInterface, VERR_INVALID_POINTER);
141 AssertPtrReturn(pStream, VERR_INVALID_POINTER);
142 AssertPtrReturn(pvBuf, VERR_INVALID_POINTER);
143 AssertReturn(cxBuf, VERR_INVALID_PARAMETER);
144
145 RT_NOREF(pInterface, pStream, pvBuf);
146
147 /* Note: No copying of samples needed here, as this a NULL backend. */
148
149 if (pcxWritten)
150 *pcxWritten = cxBuf; /* Return all bytes as written. */
151
152 return VINF_SUCCESS;
153}
154
155
156/**
157 * @interface_method_impl{PDMIHOSTAUDIO,pfnStreamCapture}
158 */
159static DECLCALLBACK(int) drvHostNullAudioStreamCapture(PPDMIHOSTAUDIO pInterface, PPDMAUDIOBACKENDSTREAM pStream,
160 void *pvBuf, uint32_t cxBuf, uint32_t *pcxRead)
161{
162 RT_NOREF(pInterface, pStream);
163
164 /* Return silence. */
165 RT_BZERO(pvBuf, cxBuf);
166
167 if (pcxRead)
168 *pcxRead = cxBuf;
169
170 return VINF_SUCCESS;
171}
172
173
174static int nullCreateStreamIn(PNULLAUDIOSTREAM pStreamNull, PPDMAUDIOSTREAMCFG pCfgReq, PPDMAUDIOSTREAMCFG pCfgAcq)
175{
176 RT_NOREF(pStreamNull, pCfgReq);
177
178 if (pCfgAcq)
179 pCfgAcq->cFrameBufferHint = _1K;
180
181 return VINF_SUCCESS;
182}
183
184
185static int nullCreateStreamOut(PNULLAUDIOSTREAM pStreamNull, PPDMAUDIOSTREAMCFG pCfgReq, PPDMAUDIOSTREAMCFG pCfgAcq)
186{
187 RT_NOREF(pStreamNull, pCfgReq);
188
189 if (pCfgAcq)
190 pCfgAcq->cFrameBufferHint = _1K; /** @todo Make this configurable. */
191
192 return VINF_SUCCESS;
193}
194
195
196/**
197 * @interface_method_impl{PDMIHOSTAUDIO,pfnStreamCreate}
198 */
199static DECLCALLBACK(int) drvHostNullAudioStreamCreate(PPDMIHOSTAUDIO pInterface, PPDMAUDIOBACKENDSTREAM pStream,
200 PPDMAUDIOSTREAMCFG pCfgReq, PPDMAUDIOSTREAMCFG pCfgAcq)
201{
202 AssertPtrReturn(pInterface, VERR_INVALID_POINTER);
203 AssertPtrReturn(pStream, VERR_INVALID_POINTER);
204 AssertPtrReturn(pCfgReq, VERR_INVALID_POINTER);
205 AssertPtrReturn(pCfgAcq, VERR_INVALID_POINTER);
206
207 PNULLAUDIOSTREAM pStreamNull = (PNULLAUDIOSTREAM)pStream;
208
209 int rc;
210 if (pCfgReq->enmDir == PDMAUDIODIR_IN)
211 rc = nullCreateStreamIn( pStreamNull, pCfgReq, pCfgAcq);
212 else
213 rc = nullCreateStreamOut(pStreamNull, pCfgReq, pCfgAcq);
214
215 if (RT_SUCCESS(rc))
216 {
217 pStreamNull->pCfg = DrvAudioHlpStreamCfgDup(pCfgAcq);
218 if (!pStreamNull->pCfg)
219 rc = VERR_NO_MEMORY;
220 }
221
222 return rc;
223}
224
225
226static int nullDestroyStreamIn(void)
227{
228 LogFlowFuncLeaveRC(VINF_SUCCESS);
229 return VINF_SUCCESS;
230}
231
232
233static int nullDestroyStreamOut(PNULLAUDIOSTREAM pStreamNull)
234{
235 RT_NOREF(pStreamNull);
236 return VINF_SUCCESS;
237}
238
239
240/**
241 * @interface_method_impl{PDMIHOSTAUDIO,pfnStreamDestroy}
242 */
243static DECLCALLBACK(int) drvHostNullAudioStreamDestroy(PPDMIHOSTAUDIO pInterface, PPDMAUDIOBACKENDSTREAM pStream)
244{
245 AssertPtrReturn(pInterface, VERR_INVALID_POINTER);
246 AssertPtrReturn(pStream, VERR_INVALID_POINTER);
247
248 PNULLAUDIOSTREAM pStreamNull = (PNULLAUDIOSTREAM)pStream;
249
250 if (!pStreamNull->pCfg) /* Not (yet) configured? Skip. */
251 return VINF_SUCCESS;
252
253 int rc;
254 if (pStreamNull->pCfg->enmDir == PDMAUDIODIR_IN)
255 rc = nullDestroyStreamIn();
256 else
257 rc = nullDestroyStreamOut(pStreamNull);
258
259 if (RT_SUCCESS(rc))
260 {
261 DrvAudioHlpStreamCfgFree(pStreamNull->pCfg);
262 pStreamNull->pCfg = NULL;
263 }
264
265 return rc;
266}
267
268
269/**
270 * @interface_method_impl{PDMIHOSTAUDIO,pfnStreamControl}
271 */
272static DECLCALLBACK(int) drvHostNullAudioStreamControl(PPDMIHOSTAUDIO pInterface,
273 PPDMAUDIOBACKENDSTREAM pStream, PDMAUDIOSTREAMCMD enmStreamCmd)
274{
275 RT_NOREF(pInterface, pStream, enmStreamCmd);
276 return VINF_SUCCESS;
277}
278
279
280/**
281 * @interface_method_impl{PDMIHOSTAUDIO,pfnStreamGetReadable}
282 */
283static DECLCALLBACK(uint32_t) drvHostNullAudioStreamGetReadable(PPDMIHOSTAUDIO pInterface, PPDMAUDIOBACKENDSTREAM pStream)
284{
285 RT_NOREF(pInterface, pStream);
286
287 return UINT32_MAX;
288}
289
290
291/**
292 * @interface_method_impl{PDMIHOSTAUDIO,pfnStreamGetWritable}
293 */
294static DECLCALLBACK(uint32_t) drvHostNullAudioStreamGetWritable(PPDMIHOSTAUDIO pInterface, PPDMAUDIOBACKENDSTREAM pStream)
295{
296 RT_NOREF(pInterface, pStream);
297
298 return UINT32_MAX;
299}
300
301
302/**
303 * @interface_method_impl{PDMIHOSTAUDIO,pfnStreamGetStatus}
304 */
305static DECLCALLBACK(PDMAUDIOSTREAMSTS) drvHostNullAudioStreamGetStatus(PPDMIHOSTAUDIO pInterface, PPDMAUDIOBACKENDSTREAM pStream)
306{
307 RT_NOREF(pInterface, pStream);
308 return PDMAUDIOSTREAMSTS_FLAG_INITIALIZED | PDMAUDIOSTREAMSTS_FLAG_ENABLED;
309}
310
311
312/**
313 * @interface_method_impl{PDMIHOSTAUDIO,pfnStreamIterate}
314 */
315static DECLCALLBACK(int) drvHostNullAudioStreamIterate(PPDMIHOSTAUDIO pInterface, PPDMAUDIOBACKENDSTREAM pStream)
316{
317 NOREF(pInterface);
318 NOREF(pStream);
319
320 return VINF_SUCCESS;
321}
322
323
324/**
325 * @interface_method_impl{PDMIBASE,pfnQueryInterface}
326 */
327static DECLCALLBACK(void *) drvHostNullAudioQueryInterface(PPDMIBASE pInterface, const char *pszIID)
328{
329 PPDMDRVINS pDrvIns = PDMIBASE_2_PDMDRV(pInterface);
330 PDRVHOSTNULLAUDIO pThis = PDMINS_2_DATA(pDrvIns, PDRVHOSTNULLAUDIO);
331
332 PDMIBASE_RETURN_INTERFACE(pszIID, PDMIBASE, &pDrvIns->IBase);
333 PDMIBASE_RETURN_INTERFACE(pszIID, PDMIHOSTAUDIO, &pThis->IHostAudio);
334 return NULL;
335}
336
337
338/**
339 * Constructs a Null audio driver instance.
340 *
341 * @copydoc FNPDMDRVCONSTRUCT
342 */
343static DECLCALLBACK(int) drvHostNullAudioConstruct(PPDMDRVINS pDrvIns, PCFGMNODE pCfg, uint32_t fFlags)
344{
345 RT_NOREF(pCfg, fFlags);
346 PDMDRV_CHECK_VERSIONS_RETURN(pDrvIns);
347 AssertPtrReturn(pDrvIns, VERR_INVALID_POINTER);
348 /* pCfg is optional. */
349
350 PDRVHOSTNULLAUDIO pThis = PDMINS_2_DATA(pDrvIns, PDRVHOSTNULLAUDIO);
351 LogRel(("Audio: Initializing NULL driver\n"));
352
353 /*
354 * Init the static parts.
355 */
356 pThis->pDrvIns = pDrvIns;
357 /* IBase */
358 pDrvIns->IBase.pfnQueryInterface = drvHostNullAudioQueryInterface;
359 /* IHostAudio */
360 PDMAUDIO_IHOSTAUDIO_CALLBACKS(drvHostNullAudio);
361
362 return VINF_SUCCESS;
363}
364
365
366/**
367 * Char driver registration record.
368 */
369const PDMDRVREG g_DrvHostNullAudio =
370{
371 /* u32Version */
372 PDM_DRVREG_VERSION,
373 /* szName */
374 "NullAudio",
375 /* szRCMod */
376 "",
377 /* szR0Mod */
378 "",
379 /* pszDescription */
380 "NULL audio host driver",
381 /* fFlags */
382 PDM_DRVREG_FLAGS_HOST_BITS_DEFAULT,
383 /* fClass. */
384 PDM_DRVREG_CLASS_AUDIO,
385 /* cMaxInstances */
386 ~0U,
387 /* cbInstance */
388 sizeof(DRVHOSTNULLAUDIO),
389 /* pfnConstruct */
390 drvHostNullAudioConstruct,
391 /* pfnDestruct */
392 NULL,
393 /* pfnRelocate */
394 NULL,
395 /* pfnIOCtl */
396 NULL,
397 /* pfnPowerOn */
398 NULL,
399 /* pfnReset */
400 NULL,
401 /* pfnSuspend */
402 NULL,
403 /* pfnResume */
404 NULL,
405 /* pfnAttach */
406 NULL,
407 /* pfnDetach */
408 NULL,
409 /* pfnPowerOff */
410 NULL,
411 /* pfnSoftReset */
412 NULL,
413 /* u32EndVersion */
414 PDM_DRVREG_VERSION
415};
416
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