VirtualBox

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

Last change on this file since 55339 was 54967, checked in by vboxsync, 10 years ago

DrvHostNullAudio.cpp: Always pretend consuming all output samples available at a time.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 8.4 KB
Line 
1/* $Id: DrvHostNullAudio.cpp 54967 2015-03-26 15:26:52Z 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 "AudioMixBuffer.h"
45
46#include "VBoxDD.h"
47#include "vl_vbox.h"
48
49#include <iprt/alloc.h>
50#include <iprt/uuid.h> /* For PDMIBASE_2_PDMDRV. */
51#include <VBox/vmm/pdmaudioifs.h>
52
53#ifdef LOG_GROUP
54# undef LOG_GROUP
55#endif
56#define LOG_GROUP LOG_GROUP_DEV_AUDIO
57#include <VBox/log.h>
58
59typedef struct NULLAUDIOSTREAMOUT
60{
61 /** Note: Always must come first! */
62 PDMAUDIOHSTSTRMOUT hw;
63} NULLAUDIOSTREAMOUT;
64
65typedef struct NULLAUDIOSTREAMIN
66{
67 /** Note: Always must come first! */
68 PDMAUDIOHSTSTRMIN hw;
69} NULLAUDIOSTREAMIN;
70
71/**
72 * NULL audio driver instance data.
73 * @implements PDMIAUDIOCONNECTOR
74 */
75typedef struct DRVHOSTNULLAUDIO
76{
77 /** Pointer to the driver instance structure. */
78 PPDMDRVINS pDrvIns;
79 /** Pointer to host audio interface. */
80 PDMIHOSTAUDIO IHostAudio;
81} DRVHOSTNULLAUDIO, *PDRVHOSTNULLAUDIO;
82
83/*******************************************PDM_AUDIO_DRIVER******************************/
84
85
86static DECLCALLBACK(int) drvHostNullAudioGetConf(PPDMIHOSTAUDIO pInterface, PPDMAUDIOBACKENDCFG pCfg)
87{
88 NOREF(pInterface);
89 AssertPtrReturn(pCfg, VERR_INVALID_POINTER);
90
91 pCfg->cbStreamOut = sizeof(NULLAUDIOSTREAMOUT);
92 pCfg->cbStreamIn = sizeof(NULLAUDIOSTREAMIN);
93
94 pCfg->cMaxHstStrmsOut = 1; /* Output */
95 pCfg->cMaxHstStrmsIn = 2; /* Line input + microphone input. */
96
97 return VINF_SUCCESS;
98}
99
100static DECLCALLBACK(int) drvHostNullAudioInit(PPDMIHOSTAUDIO pInterface)
101{
102 NOREF(pInterface);
103
104 return VINF_SUCCESS;
105}
106
107static DECLCALLBACK(int) drvHostNullAudioInitIn(PPDMIHOSTAUDIO pInterface,
108 PPDMAUDIOHSTSTRMIN pHstStrmIn, PPDMAUDIOSTREAMCFG pCfg,
109 PDMAUDIORECSOURCE enmRecSource,
110 uint32_t *pcSamples)
111{
112 NOREF(pInterface);
113 NOREF(enmRecSource);
114
115 /* Just adopt the wanted stream configuration. */
116 int rc = drvAudioStreamCfgToProps(pCfg, &pHstStrmIn->Props);
117 if (RT_SUCCESS(rc))
118 {
119 if (pcSamples)
120 *pcSamples = _1K;
121 }
122
123 return VINF_SUCCESS;
124}
125
126static DECLCALLBACK(int) drvHostNullAudioInitOut(PPDMIHOSTAUDIO pInterface,
127 PPDMAUDIOHSTSTRMOUT pHstStrmOut, PPDMAUDIOSTREAMCFG pCfg,
128 uint32_t *pcSamples)
129{
130 NOREF(pInterface);
131
132 /* Just adopt the wanted stream configuration. */
133 int rc = drvAudioStreamCfgToProps(pCfg, &pHstStrmOut->Props);
134 if (RT_SUCCESS(rc))
135 {
136 if (pcSamples)
137 *pcSamples = _1K;
138 }
139
140 return rc;
141}
142
143static DECLCALLBACK(bool) drvHostNullAudioIsEnabled(PPDMIHOSTAUDIO pInterface, PDMAUDIODIR enmDir)
144{
145 NOREF(pInterface);
146 NOREF(enmDir);
147 return true; /* Always all enabled. */
148}
149
150static DECLCALLBACK(int) drvHostNullAudioPlayOut(PPDMIHOSTAUDIO pInterface, PPDMAUDIOHSTSTRMOUT pHstStrmOut,
151 uint32_t *pcSamplesPlayed)
152{
153 /* Always pretend consuming all samples available at this time. */
154 const uint32_t cSamplesPlayed = audioMixBufSize(&pHstStrmOut->MixBuf);
155 audioMixBufFinish(&pHstStrmOut->MixBuf, cSamplesPlayed);
156
157 if (pcSamplesPlayed)
158 *pcSamplesPlayed = cSamplesPlayed;
159
160 return VINF_SUCCESS;
161}
162
163static DECLCALLBACK(int) drvHostNullAudioCaptureIn(PPDMIHOSTAUDIO pInterface, PPDMAUDIOHSTSTRMIN pHstStrmIn,
164 uint32_t *pcSamplesCaptured)
165{
166 /* Never capture anything. */
167 if (pcSamplesCaptured)
168 *pcSamplesCaptured = 0;
169
170 return VINF_SUCCESS;
171}
172
173static DECLCALLBACK(int) drvHostNullAudioControlIn(PPDMIHOSTAUDIO pInterface, PPDMAUDIOHSTSTRMIN pHstStrmIn,
174 PDMAUDIOSTREAMCMD enmStreamCmd)
175{
176 NOREF(pInterface);
177 NOREF(pHstStrmIn);
178 NOREF(enmStreamCmd);
179
180 return VINF_SUCCESS;
181}
182
183static DECLCALLBACK(int) drvHostNullAudioControlOut(PPDMIHOSTAUDIO pInterface, PPDMAUDIOHSTSTRMOUT pHstStrmOut,
184 PDMAUDIOSTREAMCMD enmStreamCmd)
185{
186 NOREF(pInterface);
187 NOREF(pHstStrmOut);
188 NOREF(enmStreamCmd);
189
190 return VINF_SUCCESS;
191}
192
193static DECLCALLBACK(int) drvHostNullAudioFiniIn(PPDMIHOSTAUDIO pInterface, PPDMAUDIOHSTSTRMIN pHstStrmIn)
194{
195 return VINF_SUCCESS;
196}
197
198static DECLCALLBACK(int) drvHostNullAudioFiniOut(PPDMIHOSTAUDIO pInterface, PPDMAUDIOHSTSTRMOUT pHstStrmOut)
199{
200 return VINF_SUCCESS;
201}
202
203/**
204 * @interface_method_impl{PDMIBASE,pfnQueryInterface}
205 */
206static DECLCALLBACK(void *) drvHostNullAudioQueryInterface(PPDMIBASE pInterface, const char *pszIID)
207{
208 PPDMDRVINS pDrvIns = PDMIBASE_2_PDMDRV(pInterface);
209 PDRVHOSTNULLAUDIO pThis = PDMINS_2_DATA(pDrvIns, PDRVHOSTNULLAUDIO);
210
211 PDMIBASE_RETURN_INTERFACE(pszIID, PDMIBASE, &pDrvIns->IBase);
212 PDMIBASE_RETURN_INTERFACE(pszIID, PDMIHOSTAUDIO, &pThis->IHostAudio);
213 return NULL;
214}
215
216static DECLCALLBACK(void) drvHostNullAudioShutdown(PPDMIHOSTAUDIO pInterface)
217{
218 NOREF(pInterface);
219}
220
221/**
222 * Constructs a Null audio driver instance.
223 *
224 * @copydoc FNPDMDRVCONSTRUCT
225 */
226static DECLCALLBACK(int) drvHostNullAudioConstruct(PPDMDRVINS pDrvIns, PCFGMNODE pCfg, uint32_t fFlags)
227{
228 AssertPtrReturn(pDrvIns, VERR_INVALID_POINTER);
229 /* pCfg is optional. */
230
231 PDRVHOSTNULLAUDIO pThis = PDMINS_2_DATA(pDrvIns, PDRVHOSTNULLAUDIO);
232 LogRel(("Audio: Initializing NULL driver\n"));
233
234 /*
235 * Init the static parts.
236 */
237 pThis->pDrvIns = pDrvIns;
238 /* IBase */
239 pDrvIns->IBase.pfnQueryInterface = drvHostNullAudioQueryInterface;
240 /* IHostAudio */
241 PDMAUDIO_IHOSTAUDIO_CALLBACKS(drvHostNullAudio);
242
243 return VINF_SUCCESS;
244}
245
246/**
247 * Char driver registration record.
248 */
249const PDMDRVREG g_DrvHostNullAudio =
250{
251 /* u32Version */
252 PDM_DRVREG_VERSION,
253 /* szName */
254 "NullAudio",
255 /* szRCMod */
256 "",
257 /* szR0Mod */
258 "",
259 /* pszDescription */
260 "NULL audio host driver",
261 /* fFlags */
262 PDM_DRVREG_FLAGS_HOST_BITS_DEFAULT,
263 /* fClass. */
264 PDM_DRVREG_CLASS_AUDIO,
265 /* cMaxInstances */
266 ~0U,
267 /* cbInstance */
268 sizeof(DRVHOSTNULLAUDIO),
269 /* pfnConstruct */
270 drvHostNullAudioConstruct,
271 /* pfnDestruct */
272 NULL,
273 /* pfnRelocate */
274 NULL,
275 /* pfnIOCtl */
276 NULL,
277 /* pfnPowerOn */
278 NULL,
279 /* pfnReset */
280 NULL,
281 /* pfnSuspend */
282 NULL,
283 /* pfnResume */
284 NULL,
285 /* pfnAttach */
286 NULL,
287 /* pfnDetach */
288 NULL,
289 /* pfnPowerOff */
290 NULL,
291 /* pfnSoftReset */
292 NULL,
293 /* u32EndVersion */
294 PDM_DRVREG_VERSION
295};
296
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