1 | /* $Id: DrvAudioVRDE.cpp 53442 2014-12-04 13:49:43Z vboxsync $ */
|
---|
2 | /** @file
|
---|
3 | * VRDE audio backend for Main.
|
---|
4 | */
|
---|
5 |
|
---|
6 | /*
|
---|
7 | * Copyright (C) 2013-2014 Oracle Corporation
|
---|
8 | *
|
---|
9 | * This file is part of VirtualBox Open Source Edition (OSE), as
|
---|
10 | * available from http://www.virtualbox.org. This file is free software;
|
---|
11 | * you can redistribute it and/or modify it under the terms of the GNU
|
---|
12 | * General Public License (GPL) as published by the Free Software
|
---|
13 | * Foundation, in version 2 as it comes in the "COPYING" file of the
|
---|
14 | * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
|
---|
15 | * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
|
---|
16 | */
|
---|
17 | #include "DrvAudioVRDE.h"
|
---|
18 | #include "ConsoleImpl.h"
|
---|
19 | #include "ConsoleVRDPServer.h"
|
---|
20 |
|
---|
21 | #include "Logging.h"
|
---|
22 |
|
---|
23 | #include "../../Devices/Audio/DrvAudio.h"
|
---|
24 | #include "../../Devices/Audio/AudioMixBuffer.h"
|
---|
25 |
|
---|
26 | #include <iprt/mem.h>
|
---|
27 | #include <iprt/cdefs.h>
|
---|
28 | #include <iprt/circbuf.h>
|
---|
29 |
|
---|
30 | #include <VBox/vmm/pdmaudioifs.h>
|
---|
31 | #include <VBox/vmm/pdmdrv.h>
|
---|
32 | #include <VBox/RemoteDesktop/VRDE.h>
|
---|
33 | #include <VBox/vmm/cfgm.h>
|
---|
34 | #include <VBox/err.h>
|
---|
35 |
|
---|
36 | #ifdef LOG_GROUP
|
---|
37 | #undef LOG_GROUP
|
---|
38 | #endif
|
---|
39 | #define LOG_GROUP LOG_GROUP_DEV_AUDIO
|
---|
40 | #include <VBox/log.h>
|
---|
41 |
|
---|
42 | /**
|
---|
43 | * Audio VRDE driver instance data.
|
---|
44 | */
|
---|
45 | typedef struct DRVAUDIOVRDE
|
---|
46 | {
|
---|
47 | /** Pointer to audio VRDE object. */
|
---|
48 | AudioVRDE *pAudioVRDE;
|
---|
49 | PPDMDRVINS pDrvIns;
|
---|
50 | /** Pointer to the driver instance structure. */
|
---|
51 | PDMIHOSTAUDIO IHostAudioR3;
|
---|
52 | ConsoleVRDPServer *pConsoleVRDPServer;
|
---|
53 | /** Pointer to the DrvAudio port interface that is above it. */
|
---|
54 | PPDMIAUDIOCONNECTOR pDrvAudio;
|
---|
55 | } DRVAUDIOVRDE, *PDRVAUDIOVRDE;
|
---|
56 |
|
---|
57 | typedef struct VRDESTREAMIN
|
---|
58 | {
|
---|
59 | /** Associated host input stream. */
|
---|
60 | PDMAUDIOHSTSTRMIN HstStrmIn;
|
---|
61 | /** Number of samples captured asynchronously in the
|
---|
62 | * onVRDEInputXXX callbacks. */
|
---|
63 | uint32_t cSamplesCaptured;
|
---|
64 | /** Critical section. */
|
---|
65 | RTCRITSECT CritSect;
|
---|
66 |
|
---|
67 | } VRDESTREAMIN, *PVRDESTREAMIN;
|
---|
68 |
|
---|
69 | typedef struct VRDESTREAMOUT
|
---|
70 | {
|
---|
71 | /** Associated host output stream. */
|
---|
72 | PDMAUDIOHSTSTRMOUT HstStrmOut;
|
---|
73 | uint64_t old_ticks;
|
---|
74 | uint64_t cSamplesSentPerSec;
|
---|
75 | } VRDESTREAMOUT, *PVRDESTREAMOUT;
|
---|
76 |
|
---|
77 | static DECLCALLBACK(int) drvAudioVRDEInit(PPDMIHOSTAUDIO pInterface)
|
---|
78 | {
|
---|
79 | LogFlowFuncEnter();
|
---|
80 |
|
---|
81 | return VINF_SUCCESS;
|
---|
82 | }
|
---|
83 |
|
---|
84 | static DECLCALLBACK(int) drvAudioVRDEInitOut(PPDMIHOSTAUDIO pInterface,
|
---|
85 | PPDMAUDIOHSTSTRMOUT pHstStrmOut, PPDMAUDIOSTREAMCFG pCfg,
|
---|
86 | uint32_t *pcSamples)
|
---|
87 | {
|
---|
88 | PDRVAUDIOVRDE pDrv = RT_FROM_MEMBER(pInterface, DRVAUDIOVRDE, IHostAudioR3);
|
---|
89 | AssertPtrReturn(pDrv, VERR_INVALID_POINTER);
|
---|
90 |
|
---|
91 | LogFlowFunc(("pHstStrmOut=%p, pCfg=%p\n", pHstStrmOut, pCfg));
|
---|
92 |
|
---|
93 | PVRDESTREAMOUT pVRDEStrmOut = (PVRDESTREAMOUT)pHstStrmOut;
|
---|
94 | AssertPtrReturn(pVRDEStrmOut, VERR_INVALID_POINTER);
|
---|
95 |
|
---|
96 | if (pcSamples)
|
---|
97 | *pcSamples = _4K; /** @todo Make this configurable. */
|
---|
98 |
|
---|
99 | return drvAudioStreamCfgToProps(pCfg, &pVRDEStrmOut->HstStrmOut.Props);
|
---|
100 | }
|
---|
101 |
|
---|
102 | static DECLCALLBACK(int) drvAudioVRDEInitIn(PPDMIHOSTAUDIO pInterface,
|
---|
103 | PPDMAUDIOHSTSTRMIN pHstStrmIn, PPDMAUDIOSTREAMCFG pCfg,
|
---|
104 | PDMAUDIORECSOURCE enmRecSource,
|
---|
105 | uint32_t *pcSamples)
|
---|
106 | {
|
---|
107 | PDRVAUDIOVRDE pDrv = RT_FROM_MEMBER(pInterface, DRVAUDIOVRDE, IHostAudioR3);
|
---|
108 | AssertPtrReturn(pDrv, VERR_INVALID_POINTER);
|
---|
109 |
|
---|
110 | PVRDESTREAMIN pVRDEStrmIn = (PVRDESTREAMIN)pHstStrmIn;
|
---|
111 | AssertPtrReturn(pVRDEStrmIn, VERR_INVALID_POINTER);
|
---|
112 |
|
---|
113 | if (pcSamples)
|
---|
114 | *pcSamples = _4K; /** @todo Make this configurable. */
|
---|
115 |
|
---|
116 | return drvAudioStreamCfgToProps(pCfg, &pVRDEStrmIn->HstStrmIn.Props);
|
---|
117 | }
|
---|
118 |
|
---|
119 | /**
|
---|
120 | * Transfers audio input formerly sent by a connected RDP client / VRDE backend
|
---|
121 | * (using the onVRDEInputXXX methods) over to the VRDE host (VM). The audio device
|
---|
122 | * emulation then will read and send the data to the guest.
|
---|
123 | *
|
---|
124 | * @return IPRT status code.
|
---|
125 | * @param pInterface
|
---|
126 | * @param pHstStrmIn
|
---|
127 | * @param pcSamplesCaptured
|
---|
128 | */
|
---|
129 | static DECLCALLBACK(int) drvAudioVRDECaptureIn(PPDMIHOSTAUDIO pInterface, PPDMAUDIOHSTSTRMIN pHstStrmIn,
|
---|
130 | uint32_t *pcSamplesCaptured)
|
---|
131 | {
|
---|
132 | AssertPtrReturn(pInterface, VERR_INVALID_POINTER);
|
---|
133 | AssertPtrReturn(pHstStrmIn, VERR_INVALID_POINTER);
|
---|
134 | AssertPtrReturn(pcSamplesCaptured, VERR_INVALID_POINTER);
|
---|
135 |
|
---|
136 | PDRVAUDIOVRDE pDrv = RT_FROM_MEMBER(pInterface, DRVAUDIOVRDE, IHostAudioR3);
|
---|
137 | AssertPtrReturn(pDrv, VERR_INVALID_POINTER);
|
---|
138 |
|
---|
139 | PVRDESTREAMIN pVRDEStrmIn = (PVRDESTREAMIN)pHstStrmIn;
|
---|
140 | AssertPtrReturn(pVRDEStrmIn, VERR_INVALID_POINTER);
|
---|
141 |
|
---|
142 | /** @todo Use CritSect! */
|
---|
143 |
|
---|
144 | int rc;
|
---|
145 |
|
---|
146 | uint32_t cProcessed = 0;
|
---|
147 | if (pVRDEStrmIn->cSamplesCaptured)
|
---|
148 | {
|
---|
149 | rc = audioMixBufMixToParent(&pVRDEStrmIn->HstStrmIn.MixBuf, pVRDEStrmIn->cSamplesCaptured,
|
---|
150 | &cProcessed);
|
---|
151 | }
|
---|
152 | else
|
---|
153 | rc = VINF_SUCCESS;
|
---|
154 |
|
---|
155 | if (RT_SUCCESS(rc))
|
---|
156 | {
|
---|
157 | *pcSamplesCaptured = cProcessed;
|
---|
158 |
|
---|
159 | Assert(pVRDEStrmIn->cSamplesCaptured >= cProcessed);
|
---|
160 | pVRDEStrmIn->cSamplesCaptured -= cProcessed;
|
---|
161 | }
|
---|
162 |
|
---|
163 | LogFlowFunc(("cSamplesCaptured=%RU32, cProcessed=%RU32\n",
|
---|
164 | pVRDEStrmIn->cSamplesCaptured, cProcessed, rc));
|
---|
165 | return rc;
|
---|
166 | }
|
---|
167 |
|
---|
168 | /**
|
---|
169 | * Transfers VM audio output over to the VRDE instance for playing remotely
|
---|
170 | * on the client.
|
---|
171 | *
|
---|
172 | * @return IPRT status code.
|
---|
173 | * @param pInterface
|
---|
174 | * @param pHstStrmOut
|
---|
175 | * @param pcSamplesPlayed
|
---|
176 | */
|
---|
177 | static DECLCALLBACK(int) drvAudioVRDEPlayOut(PPDMIHOSTAUDIO pInterface, PPDMAUDIOHSTSTRMOUT pHstStrmOut,
|
---|
178 | uint32_t *pcSamplesPlayed)
|
---|
179 | {
|
---|
180 | AssertPtrReturn(pInterface, VERR_INVALID_POINTER);
|
---|
181 | AssertPtrReturn(pHstStrmOut, VERR_INVALID_POINTER);
|
---|
182 | /* pcSamplesPlayed is optional. */
|
---|
183 |
|
---|
184 | PDRVAUDIOVRDE pDrv = RT_FROM_MEMBER(pInterface, DRVAUDIOVRDE, IHostAudioR3);
|
---|
185 | AssertPtrReturn(pDrv, VERR_INVALID_POINTER);
|
---|
186 | PVRDESTREAMOUT pVRDEStrmOut = (PVRDESTREAMOUT)pHstStrmOut;
|
---|
187 | AssertPtrReturn(pVRDEStrmOut, VERR_INVALID_POINTER);
|
---|
188 |
|
---|
189 | /*
|
---|
190 | * Just call the VRDP server with the data.
|
---|
191 | */
|
---|
192 | uint32_t live = drvAudioHstOutSamplesLive(pHstStrmOut, NULL /* pcStreamsLive */);
|
---|
193 | uint64_t now = PDMDrvHlpTMGetVirtualTime(pDrv->pDrvIns);
|
---|
194 | uint64_t ticks = now - pVRDEStrmOut->old_ticks;
|
---|
195 | uint64_t ticks_per_second = PDMDrvHlpTMGetVirtualFreq(pDrv->pDrvIns);
|
---|
196 |
|
---|
197 | uint32_t cSamplesPlayed = (int)((2 * ticks * pHstStrmOut->Props.uHz + ticks_per_second) / ticks_per_second / 2);
|
---|
198 | if (!cSamplesPlayed)
|
---|
199 | cSamplesPlayed = live;
|
---|
200 |
|
---|
201 | VRDEAUDIOFORMAT format = VRDE_AUDIO_FMT_MAKE(pHstStrmOut->Props.uHz,
|
---|
202 | pHstStrmOut->Props.cChannels,
|
---|
203 | pHstStrmOut->Props.cBits,
|
---|
204 | pHstStrmOut->Props.fSigned);
|
---|
205 |
|
---|
206 | LogFlowFunc(("hz=%d, chan=%d, cBits=%d, fSigned=%RTbool, format=%ld\n",
|
---|
207 | pHstStrmOut->Props.uHz, pHstStrmOut->Props.cChannels,
|
---|
208 | pHstStrmOut->Props.cBits, pHstStrmOut->Props.fSigned,
|
---|
209 | format));
|
---|
210 |
|
---|
211 | pVRDEStrmOut->old_ticks = now;
|
---|
212 | int cSamplesToSend = RT_MIN(live, cSamplesPlayed);
|
---|
213 |
|
---|
214 | uint32_t cReadTotal = 0;
|
---|
215 |
|
---|
216 | PPDMAUDIOSAMPLE pSamples;
|
---|
217 | uint32_t cRead;
|
---|
218 | int rc = audioMixBufAcquire(&pHstStrmOut->MixBuf, cSamplesToSend,
|
---|
219 | &pSamples, &cRead);
|
---|
220 | if (RT_SUCCESS(rc))
|
---|
221 | {
|
---|
222 | cReadTotal = cRead;
|
---|
223 | pDrv->pConsoleVRDPServer->SendAudioSamples(pSamples, cRead, format);
|
---|
224 |
|
---|
225 | if (rc == VINF_TRY_AGAIN)
|
---|
226 | {
|
---|
227 | rc = audioMixBufAcquire(&pHstStrmOut->MixBuf, cSamplesToSend - cRead,
|
---|
228 | &pSamples, &cRead);
|
---|
229 | if (RT_SUCCESS(rc))
|
---|
230 | {
|
---|
231 | cReadTotal += cRead;
|
---|
232 | pDrv->pConsoleVRDPServer->SendAudioSamples(pSamples, cRead, format);
|
---|
233 | }
|
---|
234 | }
|
---|
235 | }
|
---|
236 |
|
---|
237 | audioMixBufFinish(&pHstStrmOut->MixBuf, cReadTotal);
|
---|
238 |
|
---|
239 | if (pcSamplesPlayed)
|
---|
240 | *pcSamplesPlayed = cReadTotal;
|
---|
241 |
|
---|
242 | LogFlowFunc(("cSamplesToSend=%RU32, rc=%Rrc\n", cSamplesToSend, rc));
|
---|
243 | return rc;
|
---|
244 | }
|
---|
245 |
|
---|
246 | static DECLCALLBACK(int) drvAudioVRDEFiniIn(PPDMIHOSTAUDIO pInterface, PPDMAUDIOHSTSTRMIN pHstStrmIn)
|
---|
247 | {
|
---|
248 | PDRVAUDIOVRDE pDrv = RT_FROM_MEMBER(pInterface, DRVAUDIOVRDE, IHostAudioR3);
|
---|
249 | AssertPtrReturn(pDrv, VERR_INVALID_POINTER);
|
---|
250 |
|
---|
251 | if (pDrv->pConsoleVRDPServer)
|
---|
252 | pDrv->pConsoleVRDPServer->SendAudioInputEnd(NULL);
|
---|
253 |
|
---|
254 | return VINF_SUCCESS;
|
---|
255 | }
|
---|
256 |
|
---|
257 | static DECLCALLBACK(int) drvAudioVRDEFiniOut(PPDMIHOSTAUDIO pInterface, PPDMAUDIOHSTSTRMOUT pHstStrmOut)
|
---|
258 | {
|
---|
259 | PDRVAUDIOVRDE pDrv = RT_FROM_MEMBER(pInterface, DRVAUDIOVRDE, IHostAudioR3);
|
---|
260 | AssertPtrReturn(pDrv, VERR_INVALID_POINTER);
|
---|
261 |
|
---|
262 | return VINF_SUCCESS;
|
---|
263 | }
|
---|
264 |
|
---|
265 | static DECLCALLBACK(int) drvAudioVRDEControlOut(PPDMIHOSTAUDIO pInterface, PPDMAUDIOHSTSTRMOUT pHstStrmOut,
|
---|
266 | PDMAUDIOSTREAMCMD enmStreamCmd)
|
---|
267 | {
|
---|
268 | PDRVAUDIOVRDE pDrv = RT_FROM_MEMBER(pInterface, DRVAUDIOVRDE, IHostAudioR3);
|
---|
269 | AssertPtrReturn(pDrv, VERR_INVALID_POINTER);
|
---|
270 |
|
---|
271 | LogFlowFunc(("enmStreamCmd=%ld\n", enmStreamCmd));
|
---|
272 |
|
---|
273 | return VINF_SUCCESS;
|
---|
274 | }
|
---|
275 |
|
---|
276 | static DECLCALLBACK(int) drvAudioVRDEControlIn(PPDMIHOSTAUDIO pInterface, PPDMAUDIOHSTSTRMIN pHstStrmIn2, /** @todo Fix param types! */
|
---|
277 | PDMAUDIOSTREAMCMD enmStreamCmd)
|
---|
278 | {
|
---|
279 | PDRVAUDIOVRDE pDrv = RT_FROM_MEMBER(pInterface, DRVAUDIOVRDE, IHostAudioR3);
|
---|
280 | AssertPtrReturn(pDrv, VERR_INVALID_POINTER);
|
---|
281 |
|
---|
282 | PVRDESTREAMIN pVRDEStrmIn = (PVRDESTREAMIN)pHstStrmIn2;
|
---|
283 | AssertPtrReturn(pVRDEStrmIn, VERR_INVALID_POINTER);
|
---|
284 |
|
---|
285 | PPDMAUDIOHSTSTRMIN pHstStrmIn = &pVRDEStrmIn->HstStrmIn;
|
---|
286 |
|
---|
287 | LogFlowFunc(("enmStreamCmd=%ld\n", enmStreamCmd));
|
---|
288 |
|
---|
289 | /* Initialize only if not already done. */
|
---|
290 | if (enmStreamCmd == PDMAUDIOSTREAMCMD_ENABLE)
|
---|
291 | {
|
---|
292 | int rc2 = pDrv->pConsoleVRDPServer->SendAudioInputBegin(NULL, pVRDEStrmIn, audioMixBufSize(&pHstStrmIn->MixBuf),
|
---|
293 | pHstStrmIn->Props.uHz,
|
---|
294 | pHstStrmIn->Props.cChannels, pHstStrmIn->Props.cBits);
|
---|
295 | #ifdef DEBUG
|
---|
296 | if (rc2 == VERR_NOT_SUPPORTED)
|
---|
297 | LogFlowFunc(("No RDP client connected, so no input recording supported\n"));
|
---|
298 | #endif
|
---|
299 | }
|
---|
300 | else if (enmStreamCmd == PDMAUDIOSTREAMCMD_DISABLE)
|
---|
301 | pDrv->pConsoleVRDPServer->SendAudioInputEnd(NULL /* pvUserCtx */);
|
---|
302 |
|
---|
303 | return VINF_SUCCESS;
|
---|
304 | }
|
---|
305 |
|
---|
306 | static DECLCALLBACK(int) drvAudioVRDEGetConf(PPDMIHOSTAUDIO pInterface, PPDMAUDIOBACKENDCFG pCfg)
|
---|
307 | {
|
---|
308 | pCfg->cbStreamOut = sizeof(VRDESTREAMOUT);
|
---|
309 | pCfg->cbStreamIn = sizeof(VRDESTREAMIN);
|
---|
310 | pCfg->cMaxHstStrmsOut = 1;
|
---|
311 | pCfg->cMaxHstStrmsIn = 2; /* Microphone in + line in. */
|
---|
312 |
|
---|
313 | return VINF_SUCCESS;
|
---|
314 | }
|
---|
315 |
|
---|
316 | /**
|
---|
317 | * @interface_method_impl{PDMIBASE,pfnQueryInterface}
|
---|
318 | */
|
---|
319 | static DECLCALLBACK(void *) drvAudioVRDEQueryInterface(PPDMIBASE pInterface, const char *pszIID)
|
---|
320 | {
|
---|
321 | PPDMDRVINS pDrvIns = PDMIBASE_2_PDMDRV(pInterface);
|
---|
322 | PDRVAUDIOVRDE pThis = PDMINS_2_DATA(pDrvIns, PDRVAUDIOVRDE);
|
---|
323 |
|
---|
324 | PDMIBASE_RETURN_INTERFACE(pszIID, PDMIBASE, &pDrvIns->IBase);
|
---|
325 | PDMIBASE_RETURN_INTERFACE(pszIID, PDMIHOSTAUDIO, &pThis->IHostAudioR3);
|
---|
326 | return NULL;
|
---|
327 | }
|
---|
328 |
|
---|
329 | AudioVRDE::AudioVRDE(Console *pConsole)
|
---|
330 | : mpDrv(NULL),
|
---|
331 | mParent(pConsole)
|
---|
332 | {
|
---|
333 | }
|
---|
334 |
|
---|
335 | AudioVRDE::~AudioVRDE(void)
|
---|
336 | {
|
---|
337 | if (mpDrv)
|
---|
338 | {
|
---|
339 | mpDrv->pAudioVRDE = NULL;
|
---|
340 | mpDrv = NULL;
|
---|
341 | }
|
---|
342 | }
|
---|
343 |
|
---|
344 | int AudioVRDE::onVRDEInputIntercept(bool fIntercept)
|
---|
345 | {
|
---|
346 | LogFlowThisFunc(("fIntercept=%RTbool\n", fIntercept));
|
---|
347 | return VINF_SUCCESS; /* Never veto. */
|
---|
348 | }
|
---|
349 |
|
---|
350 | /**
|
---|
351 | * Marks the beginning of sending captured audio data from a connected
|
---|
352 | * RDP client.
|
---|
353 | *
|
---|
354 | * @return IPRT status code.
|
---|
355 | * @param pvContext The context; in this case a pointer to a
|
---|
356 | * VRDESTREAMIN structure.
|
---|
357 | * @param pVRDEAudioBegin Pointer to a VRDEAUDIOINBEGIN structure.
|
---|
358 | */
|
---|
359 | int AudioVRDE::onVRDEInputBegin(void *pvContext, PVRDEAUDIOINBEGIN pVRDEAudioBegin)
|
---|
360 | {
|
---|
361 | AssertPtrReturn(pvContext, VERR_INVALID_POINTER);
|
---|
362 | AssertPtrReturn(pVRDEAudioBegin, VERR_INVALID_POINTER);
|
---|
363 |
|
---|
364 | PVRDESTREAMIN pVRDEStrmIn = (PVRDESTREAMIN)pvContext;
|
---|
365 | AssertPtrReturn(pVRDEStrmIn, VERR_INVALID_POINTER);
|
---|
366 |
|
---|
367 | VRDEAUDIOFORMAT audioFmt = pVRDEAudioBegin->fmt;
|
---|
368 |
|
---|
369 | int iSampleHz = VRDE_AUDIO_FMT_SAMPLE_FREQ(audioFmt);
|
---|
370 | int cChannels = VRDE_AUDIO_FMT_CHANNELS(audioFmt);
|
---|
371 | int cBits = VRDE_AUDIO_FMT_BITS_PER_SAMPLE(audioFmt);
|
---|
372 | bool fUnsigned = VRDE_AUDIO_FMT_SIGNED(audioFmt);
|
---|
373 |
|
---|
374 | /*pVRDEStrmIn->cbSample = VRDE_AUDIO_FMT_BYTES_PER_SAMPLE(audioFmt);
|
---|
375 | pVRDEStrmIn->uHz = iSampleHz;*/
|
---|
376 |
|
---|
377 | LogFlowFunc(("cbSample=%RU32, iSampleHz=%d, cChannels=%d, cBits=%d, fUnsigned=%RTbool\n",
|
---|
378 | VRDE_AUDIO_FMT_BYTES_PER_SAMPLE(audioFmt), iSampleHz, cChannels, cBits, fUnsigned));
|
---|
379 |
|
---|
380 | return VINF_SUCCESS;
|
---|
381 | }
|
---|
382 |
|
---|
383 | int AudioVRDE::onVRDEInputData(void *pvContext, const void *pvData, uint32_t cbData)
|
---|
384 | {
|
---|
385 | PVRDESTREAMIN pVRDEStrmIn = (PVRDESTREAMIN)pvContext;
|
---|
386 | AssertPtrReturn(pVRDEStrmIn, VERR_INVALID_POINTER);
|
---|
387 |
|
---|
388 | PPDMAUDIOHSTSTRMIN pHstStrmIn = &pVRDEStrmIn->HstStrmIn;
|
---|
389 | AssertPtrReturn(pHstStrmIn, VERR_INVALID_POINTER);
|
---|
390 |
|
---|
391 | /** @todo Use CritSect! */
|
---|
392 |
|
---|
393 | uint32_t cWritten;
|
---|
394 | int rc = audioMixBufWriteCirc(&pHstStrmIn->MixBuf, pvData, cbData, &cWritten);
|
---|
395 | if (RT_SUCCESS(rc))
|
---|
396 | pVRDEStrmIn->cSamplesCaptured += cWritten;
|
---|
397 |
|
---|
398 | LogFlowFunc(("cbData=%RU32, cWritten=%RU32, cSamplesCaptured=%RU32, rc=%Rrc\n",
|
---|
399 | cbData, cWritten, pVRDEStrmIn->cSamplesCaptured, rc));
|
---|
400 | return rc;
|
---|
401 | }
|
---|
402 |
|
---|
403 | int AudioVRDE::onVRDEInputEnd(void *pvContext)
|
---|
404 | {
|
---|
405 | NOREF(pvContext);
|
---|
406 |
|
---|
407 | return VINF_SUCCESS;
|
---|
408 | }
|
---|
409 |
|
---|
410 | /**
|
---|
411 | * Construct a VRDE audio driver instance.
|
---|
412 | *
|
---|
413 | * @copydoc FNPDMDRVCONSTRUCT
|
---|
414 | */
|
---|
415 | /* static */
|
---|
416 | DECLCALLBACK(int) AudioVRDE::drvConstruct(PPDMDRVINS pDrvIns, PCFGMNODE pCfg, uint32_t fFlags)
|
---|
417 | {
|
---|
418 | PDRVAUDIOVRDE pThis = PDMINS_2_DATA(pDrvIns, PDRVAUDIOVRDE);
|
---|
419 | LogRel(("Audio: Initializing VRDE driver\n"));
|
---|
420 | LogFlowFunc(("fFlags=0x%x\n", fFlags));
|
---|
421 |
|
---|
422 | AssertMsgReturn(PDMDrvHlpNoAttach(pDrvIns) == VERR_PDM_NO_ATTACHED_DRIVER,
|
---|
423 | ("Configuration error: Not possible to attach anything to this driver!\n"),
|
---|
424 | VERR_PDM_DRVINS_NO_ATTACH);
|
---|
425 |
|
---|
426 | /*
|
---|
427 | * Init the static parts.
|
---|
428 | */
|
---|
429 | pThis->pDrvIns = pDrvIns;
|
---|
430 | /* IBase */
|
---|
431 | pDrvIns->IBase.pfnQueryInterface = drvAudioVRDEQueryInterface;
|
---|
432 | pThis->IHostAudioR3.pfnInitIn = drvAudioVRDEInitIn;
|
---|
433 | pThis->IHostAudioR3.pfnInitOut = drvAudioVRDEInitOut;
|
---|
434 | pThis->IHostAudioR3.pfnControlOut = drvAudioVRDEControlOut;
|
---|
435 | pThis->IHostAudioR3.pfnControlIn = drvAudioVRDEControlIn;
|
---|
436 | pThis->IHostAudioR3.pfnFiniIn = drvAudioVRDEFiniIn;
|
---|
437 | pThis->IHostAudioR3.pfnFiniOut = drvAudioVRDEFiniOut;
|
---|
438 | pThis->IHostAudioR3.pfnCaptureIn = drvAudioVRDECaptureIn;
|
---|
439 | pThis->IHostAudioR3.pfnPlayOut = drvAudioVRDEPlayOut;
|
---|
440 | pThis->IHostAudioR3.pfnGetConf = drvAudioVRDEGetConf;
|
---|
441 | pThis->IHostAudioR3.pfnInit = drvAudioVRDEInit;
|
---|
442 |
|
---|
443 | /* Get VRDPServer pointer. */
|
---|
444 | void *pvUser;
|
---|
445 | int rc = CFGMR3QueryPtr(pCfg, "ObjectVRDPServer", &pvUser);
|
---|
446 | if (RT_FAILURE(rc))
|
---|
447 | {
|
---|
448 | AssertMsgFailed(("Confguration error: No/bad \"ObjectVRDPServer\" value, rc=%Rrc\n", rc));
|
---|
449 | return rc;
|
---|
450 | }
|
---|
451 |
|
---|
452 | /* CFGM tree saves the pointer to ConsoleVRDPServer in the Object node of AudioVRDE. */
|
---|
453 | pThis->pConsoleVRDPServer = (ConsoleVRDPServer *)pvUser;
|
---|
454 |
|
---|
455 | pvUser = NULL;
|
---|
456 | rc = CFGMR3QueryPtr(pCfg, "Object", &pvUser);
|
---|
457 | if (RT_FAILURE(rc))
|
---|
458 | {
|
---|
459 | AssertMsgFailed(("Confguration error: No/bad \"Object\" value, rc=%Rrc\n", rc));
|
---|
460 | return rc;
|
---|
461 | }
|
---|
462 |
|
---|
463 | pThis->pAudioVRDE = (AudioVRDE *)pvUser;
|
---|
464 | pThis->pAudioVRDE->mpDrv = pThis;
|
---|
465 |
|
---|
466 | /*
|
---|
467 | * Get the interface for the above driver (DrvAudio) to make mixer/conversion calls.
|
---|
468 | * Described in CFGM tree.
|
---|
469 | */
|
---|
470 | pThis->pDrvAudio = PDMIBASE_QUERY_INTERFACE(pDrvIns->pUpBase, PDMIAUDIOCONNECTOR);
|
---|
471 | if (!pThis->pDrvAudio)
|
---|
472 | {
|
---|
473 | AssertMsgFailed(("Configuration error: No upper interface specified!\n"));
|
---|
474 | return VERR_PDM_MISSING_INTERFACE_ABOVE;
|
---|
475 | }
|
---|
476 |
|
---|
477 | return VINF_SUCCESS;
|
---|
478 | }
|
---|
479 |
|
---|
480 | /* static */
|
---|
481 | DECLCALLBACK(void) AudioVRDE::drvDestruct(PPDMDRVINS pDrvIns)
|
---|
482 | {
|
---|
483 | LogFlowFuncEnter();
|
---|
484 | }
|
---|
485 |
|
---|
486 | /**
|
---|
487 | * VRDE audio driver registration record.
|
---|
488 | */
|
---|
489 | const PDMDRVREG AudioVRDE::DrvReg =
|
---|
490 | {
|
---|
491 | PDM_DRVREG_VERSION,
|
---|
492 | /* szName */
|
---|
493 | "AudioVRDE",
|
---|
494 | /* szRCMod */
|
---|
495 | "",
|
---|
496 | /* szR0Mod */
|
---|
497 | "",
|
---|
498 | /* pszDescription */
|
---|
499 | "Audio driver for VRDE backend",
|
---|
500 | /* fFlags */
|
---|
501 | PDM_DRVREG_FLAGS_HOST_BITS_DEFAULT,
|
---|
502 | /* fClass. */
|
---|
503 | PDM_DRVREG_CLASS_AUDIO,
|
---|
504 | /* cMaxInstances */
|
---|
505 | ~0U,
|
---|
506 | /* cbInstance */
|
---|
507 | sizeof(DRVAUDIOVRDE),
|
---|
508 | /* pfnConstruct */
|
---|
509 | AudioVRDE::drvConstruct,
|
---|
510 | /* pfnDestruct */
|
---|
511 | AudioVRDE::drvDestruct,
|
---|
512 | /* pfnRelocate */
|
---|
513 | NULL,
|
---|
514 | /* pfnIOCtl */
|
---|
515 | NULL,
|
---|
516 | /* pfnPowerOn */
|
---|
517 | NULL,
|
---|
518 | /* pfnReset */
|
---|
519 | NULL,
|
---|
520 | /* pfnSuspend */
|
---|
521 | NULL,
|
---|
522 | /* pfnResume */
|
---|
523 | NULL,
|
---|
524 | /* pfnAttach */
|
---|
525 | NULL,
|
---|
526 | /* pfnDetach */
|
---|
527 | NULL,
|
---|
528 | /* pfnPowerOff */
|
---|
529 | NULL,
|
---|
530 | /* pfnSoftReset */
|
---|
531 | NULL,
|
---|
532 | /* u32EndVersion */
|
---|
533 | PDM_DRVREG_VERSION
|
---|
534 | };
|
---|
535 |
|
---|