1 | /* $Id: DrvAudioVRDE.cpp 61320 2016-05-31 08:43:19Z vboxsync $ */
|
---|
2 | /** @file
|
---|
3 | * VRDE audio backend for Main.
|
---|
4 | */
|
---|
5 |
|
---|
6 | /*
|
---|
7 | * Copyright (C) 2013-2016 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 |
|
---|
18 |
|
---|
19 | /*********************************************************************************************************************************
|
---|
20 | * Header Files *
|
---|
21 | *********************************************************************************************************************************/
|
---|
22 | #define LOG_GROUP LOG_GROUP_DRV_VRDE_AUDIO
|
---|
23 | #include <VBox/log.h>
|
---|
24 | #include "DrvAudioVRDE.h"
|
---|
25 | #include "ConsoleImpl.h"
|
---|
26 | #include "ConsoleVRDPServer.h"
|
---|
27 |
|
---|
28 | #include "Logging.h"
|
---|
29 |
|
---|
30 | #include "../../Devices/Audio/DrvAudio.h"
|
---|
31 | #include "../../Devices/Audio/AudioMixBuffer.h"
|
---|
32 |
|
---|
33 | #include <iprt/mem.h>
|
---|
34 | #include <iprt/cdefs.h>
|
---|
35 | #include <iprt/circbuf.h>
|
---|
36 |
|
---|
37 | #include <VBox/vmm/pdmaudioifs.h>
|
---|
38 | #include <VBox/vmm/pdmdrv.h>
|
---|
39 | #include <VBox/RemoteDesktop/VRDE.h>
|
---|
40 | #include <VBox/vmm/cfgm.h>
|
---|
41 | #include <VBox/err.h>
|
---|
42 |
|
---|
43 |
|
---|
44 | /*********************************************************************************************************************************
|
---|
45 | * Structures and Typedefs *
|
---|
46 | *********************************************************************************************************************************/
|
---|
47 | /**
|
---|
48 | * Audio VRDE driver instance data.
|
---|
49 | */
|
---|
50 | typedef struct DRVAUDIOVRDE
|
---|
51 | {
|
---|
52 | /** Pointer to audio VRDE object. */
|
---|
53 | AudioVRDE *pAudioVRDE;
|
---|
54 | PPDMDRVINS pDrvIns;
|
---|
55 | /** Pointer to the driver instance structure. */
|
---|
56 | PDMIHOSTAUDIO IHostAudio;
|
---|
57 | /** Pointer to the VRDP's console object. */
|
---|
58 | ConsoleVRDPServer *pConsoleVRDPServer;
|
---|
59 | /** Pointer to the DrvAudio port interface that is above us. */
|
---|
60 | PPDMIAUDIOCONNECTOR pDrvAudio;
|
---|
61 | /** Whether this driver is enabled or not. */
|
---|
62 | bool fEnabled;
|
---|
63 | } DRVAUDIOVRDE, *PDRVAUDIOVRDE;
|
---|
64 |
|
---|
65 | typedef struct VRDESTREAMIN
|
---|
66 | {
|
---|
67 | /** Associated host input stream.
|
---|
68 | * Note: Always must come first! */
|
---|
69 | PDMAUDIOSTREAM Stream;
|
---|
70 | /** Number of samples captured asynchronously in the
|
---|
71 | * onVRDEInputXXX callbacks. */
|
---|
72 | uint32_t cSamplesCaptured;
|
---|
73 | /** Critical section. */
|
---|
74 | RTCRITSECT CritSect;
|
---|
75 | } VRDESTREAMIN, *PVRDESTREAMIN;
|
---|
76 |
|
---|
77 | typedef struct VRDESTREAMOUT
|
---|
78 | {
|
---|
79 | /** Associated host output stream.
|
---|
80 | * Note: Always must come first! */
|
---|
81 | PDMAUDIOSTREAM Stream;
|
---|
82 | uint64_t old_ticks;
|
---|
83 | uint64_t cSamplesSentPerSec;
|
---|
84 | } VRDESTREAMOUT, *PVRDESTREAMOUT;
|
---|
85 |
|
---|
86 |
|
---|
87 | static int vrdeCreateStreamIn(PPDMIHOSTAUDIO pInterface,
|
---|
88 | PPDMAUDIOSTREAM pStream, PPDMAUDIOSTREAMCFG pCfg, uint32_t *pcSamples)
|
---|
89 | {
|
---|
90 | PDRVAUDIOVRDE pDrv = RT_FROM_MEMBER(pInterface, DRVAUDIOVRDE, IHostAudio);
|
---|
91 | AssertPtrReturn(pDrv, VERR_INVALID_POINTER);
|
---|
92 |
|
---|
93 | PVRDESTREAMIN pVRDEStrmIn = (PVRDESTREAMIN)pStream;
|
---|
94 | AssertPtrReturn(pVRDEStrmIn, VERR_INVALID_POINTER);
|
---|
95 |
|
---|
96 | if (pcSamples)
|
---|
97 | *pcSamples = _4K; /** @todo Make this configurable. */
|
---|
98 |
|
---|
99 | return DrvAudioHlpStreamCfgToProps(pCfg, &pVRDEStrmIn->Stream.Props);
|
---|
100 | }
|
---|
101 |
|
---|
102 | static int vrdeCreateStreamOut(PPDMIHOSTAUDIO pInterface,
|
---|
103 | PPDMAUDIOSTREAM pStream, PPDMAUDIOSTREAMCFG pCfg, uint32_t *pcSamples)
|
---|
104 | {
|
---|
105 | PDRVAUDIOVRDE pDrv = RT_FROM_MEMBER(pInterface, DRVAUDIOVRDE, IHostAudio);
|
---|
106 | AssertPtrReturn(pDrv, VERR_INVALID_POINTER);
|
---|
107 |
|
---|
108 | LogFlowFunc(("pStream=%p, pCfg=%p\n", pStream, pCfg));
|
---|
109 |
|
---|
110 | PVRDESTREAMOUT pVRDEStrmOut = (PVRDESTREAMOUT)pStream;
|
---|
111 | AssertPtrReturn(pVRDEStrmOut, VERR_INVALID_POINTER);
|
---|
112 |
|
---|
113 | if (pcSamples)
|
---|
114 | *pcSamples = _4K; /** @todo Make this configurable. */
|
---|
115 |
|
---|
116 | return DrvAudioHlpStreamCfgToProps(pCfg, &pVRDEStrmOut->Stream.Props);
|
---|
117 | }
|
---|
118 |
|
---|
119 | static int vrdeControlStreamOut(PPDMIHOSTAUDIO pInterface,
|
---|
120 | PPDMAUDIOSTREAM pStream, PDMAUDIOSTREAMCMD enmStreamCmd)
|
---|
121 | {
|
---|
122 | PDRVAUDIOVRDE pDrv = RT_FROM_MEMBER(pInterface, DRVAUDIOVRDE, IHostAudio);
|
---|
123 | AssertPtrReturn(pDrv, VERR_INVALID_POINTER);
|
---|
124 |
|
---|
125 | PVRDESTREAMOUT pVRDEStrmOut = (PVRDESTREAMOUT)pStream;
|
---|
126 | AssertPtrReturn(pVRDEStrmOut, VERR_INVALID_POINTER);
|
---|
127 |
|
---|
128 | LogFlowFunc(("enmStreamCmd=%ld\n", enmStreamCmd));
|
---|
129 |
|
---|
130 | AudioMixBufReset(&pStream->MixBuf);
|
---|
131 |
|
---|
132 | return VINF_SUCCESS;
|
---|
133 | }
|
---|
134 |
|
---|
135 | static int vrdeControlStreamIn(PPDMIHOSTAUDIO pInterface,
|
---|
136 | PPDMAUDIOSTREAM pStream, PDMAUDIOSTREAMCMD enmStreamCmd)
|
---|
137 | {
|
---|
138 | PDRVAUDIOVRDE pDrv = RT_FROM_MEMBER(pInterface, DRVAUDIOVRDE, IHostAudio);
|
---|
139 | AssertPtrReturn(pDrv, VERR_INVALID_POINTER);
|
---|
140 |
|
---|
141 | PVRDESTREAMIN pVRDEStrmIn = (PVRDESTREAMIN)pStream;
|
---|
142 | AssertPtrReturn(pVRDEStrmIn, VERR_INVALID_POINTER);
|
---|
143 |
|
---|
144 | LogFlowFunc(("enmStreamCmd=%ld\n", enmStreamCmd));
|
---|
145 |
|
---|
146 | if (!pDrv->pConsoleVRDPServer)
|
---|
147 | return VINF_SUCCESS;
|
---|
148 |
|
---|
149 | AudioMixBufReset(&pStream->MixBuf);
|
---|
150 |
|
---|
151 | /* Initialize only if not already done. */
|
---|
152 | int rc;
|
---|
153 | if (enmStreamCmd == PDMAUDIOSTREAMCMD_ENABLE)
|
---|
154 | {
|
---|
155 | rc = pDrv->pConsoleVRDPServer->SendAudioInputBegin(NULL, pVRDEStrmIn, AudioMixBufSize(&pStream->MixBuf),
|
---|
156 | pStream->Props.uHz,
|
---|
157 | pStream->Props.cChannels, pStream->Props.cBits);
|
---|
158 | if (rc == VERR_NOT_SUPPORTED)
|
---|
159 | {
|
---|
160 | LogFlowFunc(("No RDP client connected, so no input recording supported\n"));
|
---|
161 | rc = VINF_SUCCESS;
|
---|
162 | }
|
---|
163 | }
|
---|
164 | else if (enmStreamCmd == PDMAUDIOSTREAMCMD_DISABLE)
|
---|
165 | {
|
---|
166 | pDrv->pConsoleVRDPServer->SendAudioInputEnd(NULL /* pvUserCtx */);
|
---|
167 | rc = VINF_SUCCESS;
|
---|
168 | }
|
---|
169 | else
|
---|
170 | rc = VERR_INVALID_PARAMETER;
|
---|
171 |
|
---|
172 | return rc;
|
---|
173 | }
|
---|
174 |
|
---|
175 | static DECLCALLBACK(int) drvAudioVRDEInit(PPDMIHOSTAUDIO pInterface)
|
---|
176 | {
|
---|
177 | LogFlowFuncEnter();
|
---|
178 |
|
---|
179 | return VINF_SUCCESS;
|
---|
180 | }
|
---|
181 |
|
---|
182 | /**
|
---|
183 | * {FIXME - Missing brief description - FIXME}
|
---|
184 | *
|
---|
185 | * Transfers audio input formerly sent by a connected RDP client / VRDE backend
|
---|
186 | * (using the onVRDEInputXXX methods) over to the VRDE host (VM). The audio device
|
---|
187 | * emulation then will read and send the data to the guest.
|
---|
188 | *
|
---|
189 | * @return IPRT status code.
|
---|
190 | * @param pInterface
|
---|
191 | * @param pStream
|
---|
192 | * @param pcSamplesCaptured
|
---|
193 | */
|
---|
194 | static DECLCALLBACK(int) drvAudioVRDEStreamCapture(PPDMIHOSTAUDIO pInterface, PPDMAUDIOSTREAM pStream,
|
---|
195 | uint32_t *pcSamplesCaptured)
|
---|
196 | {
|
---|
197 | AssertPtrReturn(pInterface, VERR_INVALID_POINTER);
|
---|
198 | AssertPtrReturn(pStream, VERR_INVALID_POINTER);
|
---|
199 | AssertPtrReturn(pcSamplesCaptured, VERR_INVALID_POINTER);
|
---|
200 |
|
---|
201 | PDRVAUDIOVRDE pDrv = RT_FROM_MEMBER(pInterface, DRVAUDIOVRDE, IHostAudio);
|
---|
202 | AssertPtrReturn(pDrv, VERR_INVALID_POINTER);
|
---|
203 |
|
---|
204 | PVRDESTREAMIN pVRDEStrmIn = (PVRDESTREAMIN)pStream;
|
---|
205 | AssertPtrReturn(pVRDEStrmIn, VERR_INVALID_POINTER);
|
---|
206 |
|
---|
207 | /** @todo Use CritSect! */
|
---|
208 |
|
---|
209 | int rc;
|
---|
210 |
|
---|
211 | uint32_t cProcessed = 0;
|
---|
212 | if (pVRDEStrmIn->cSamplesCaptured)
|
---|
213 | {
|
---|
214 | rc = AudioMixBufMixToParent(&pVRDEStrmIn->Stream.MixBuf, pVRDEStrmIn->cSamplesCaptured,
|
---|
215 | &cProcessed);
|
---|
216 | }
|
---|
217 | else
|
---|
218 | rc = VINF_SUCCESS;
|
---|
219 |
|
---|
220 | if (RT_SUCCESS(rc))
|
---|
221 | {
|
---|
222 | *pcSamplesCaptured = cProcessed;
|
---|
223 |
|
---|
224 | Assert(pVRDEStrmIn->cSamplesCaptured >= cProcessed);
|
---|
225 | pVRDEStrmIn->cSamplesCaptured -= cProcessed;
|
---|
226 | }
|
---|
227 |
|
---|
228 | LogFlowFunc(("cSamplesCaptured=%RU32, cProcessed=%RU32 rc=%Rrc\n", pVRDEStrmIn->cSamplesCaptured, cProcessed, rc));
|
---|
229 | return rc;
|
---|
230 | }
|
---|
231 |
|
---|
232 | /**
|
---|
233 | * Transfers VM audio output to remote client.
|
---|
234 | *
|
---|
235 | * Transfers VM audio output over to the VRDE instance for playing remotely
|
---|
236 | * on the client.
|
---|
237 | *
|
---|
238 | * @return IPRT status code.
|
---|
239 | * @param pInterface
|
---|
240 | * @param pStream
|
---|
241 | * @param pcSamplesPlayed
|
---|
242 | */
|
---|
243 | static DECLCALLBACK(int) drvAudioVRDEStreamPlay(PPDMIHOSTAUDIO pInterface,
|
---|
244 | PPDMAUDIOSTREAM pStream, uint32_t *pcSamplesPlayed)
|
---|
245 | {
|
---|
246 | AssertPtrReturn(pInterface, VERR_INVALID_POINTER);
|
---|
247 | AssertPtrReturn(pStream, VERR_INVALID_POINTER);
|
---|
248 | /* pcSamplesPlayed is optional. */
|
---|
249 |
|
---|
250 | PDRVAUDIOVRDE pDrv = RT_FROM_MEMBER(pInterface, DRVAUDIOVRDE, IHostAudio);
|
---|
251 | AssertPtrReturn(pDrv, VERR_INVALID_POINTER);
|
---|
252 |
|
---|
253 | PVRDESTREAMOUT pVRDEStrmOut = (PVRDESTREAMOUT)pStream;
|
---|
254 | AssertPtrReturn(pVRDEStrmOut, VERR_INVALID_POINTER);
|
---|
255 |
|
---|
256 | uint32_t live = AudioMixBufAvail(&pStream->MixBuf);
|
---|
257 | uint64_t now = PDMDrvHlpTMGetVirtualTime(pDrv->pDrvIns);
|
---|
258 | uint64_t ticks = now - pVRDEStrmOut->old_ticks;
|
---|
259 | uint64_t ticks_per_second = PDMDrvHlpTMGetVirtualFreq(pDrv->pDrvIns);
|
---|
260 |
|
---|
261 | /* Minimize the rounding error: samples = int((ticks * freq) / ticks_per_second + 0.5). */
|
---|
262 | uint32_t cSamplesPlayed = (int)((2 * ticks * pStream->Props.uHz + ticks_per_second) / ticks_per_second / 2);
|
---|
263 |
|
---|
264 | /* Don't play more than available. */
|
---|
265 | if (cSamplesPlayed > live)
|
---|
266 | cSamplesPlayed = live;
|
---|
267 |
|
---|
268 | /* Remember when samples were consumed. */
|
---|
269 | pVRDEStrmOut->old_ticks = now;
|
---|
270 |
|
---|
271 | VRDEAUDIOFORMAT format = VRDE_AUDIO_FMT_MAKE(pStream->Props.uHz,
|
---|
272 | pStream->Props.cChannels,
|
---|
273 | pStream->Props.cBits,
|
---|
274 | pStream->Props.fSigned);
|
---|
275 |
|
---|
276 | int cSamplesToSend = cSamplesPlayed;
|
---|
277 |
|
---|
278 | LogFlowFunc(("uFreq=%RU32, cChan=%RU8, cBits=%RU8, fSigned=%RTbool, enmFormat=%ld, cSamplesToSend=%RU32\n",
|
---|
279 | pStream->Props.uHz, pStream->Props.cChannels,
|
---|
280 | pStream->Props.cBits, pStream->Props.fSigned,
|
---|
281 | format, cSamplesToSend));
|
---|
282 |
|
---|
283 | /*
|
---|
284 | * Call the VRDP server with the data.
|
---|
285 | */
|
---|
286 | uint32_t cReadTotal = 0;
|
---|
287 |
|
---|
288 | PPDMAUDIOSAMPLE pSamples;
|
---|
289 | uint32_t cRead;
|
---|
290 | int rc = AudioMixBufAcquire(&pStream->MixBuf, cSamplesToSend,
|
---|
291 | &pSamples, &cRead);
|
---|
292 | if ( RT_SUCCESS(rc)
|
---|
293 | && cRead)
|
---|
294 | {
|
---|
295 | cReadTotal = cRead;
|
---|
296 | pDrv->pConsoleVRDPServer->SendAudioSamples(pSamples, cRead, format);
|
---|
297 |
|
---|
298 | if (rc == VINF_TRY_AGAIN)
|
---|
299 | {
|
---|
300 | rc = AudioMixBufAcquire(&pStream->MixBuf, cSamplesToSend - cRead,
|
---|
301 | &pSamples, &cRead);
|
---|
302 | if (RT_SUCCESS(rc))
|
---|
303 | pDrv->pConsoleVRDPServer->SendAudioSamples(pSamples, cRead, format);
|
---|
304 |
|
---|
305 | cReadTotal += cRead;
|
---|
306 | }
|
---|
307 | }
|
---|
308 |
|
---|
309 | AudioMixBufFinish(&pStream->MixBuf, cSamplesToSend);
|
---|
310 |
|
---|
311 | /*
|
---|
312 | * Always report back all samples acquired, regardless of whether the
|
---|
313 | * VRDP server actually did process those.
|
---|
314 | */
|
---|
315 | if (pcSamplesPlayed)
|
---|
316 | *pcSamplesPlayed = cReadTotal;
|
---|
317 |
|
---|
318 | LogFlowFunc(("cReadTotal=%RU32, rc=%Rrc\n", cReadTotal, rc));
|
---|
319 | return rc;
|
---|
320 | }
|
---|
321 |
|
---|
322 | static int vrdeDestroyStreamIn(PPDMIHOSTAUDIO pInterface, PPDMAUDIOSTREAM pStream)
|
---|
323 | {
|
---|
324 | PDRVAUDIOVRDE pDrv = RT_FROM_MEMBER(pInterface, DRVAUDIOVRDE, IHostAudio);
|
---|
325 | AssertPtrReturn(pDrv, VERR_INVALID_POINTER);
|
---|
326 |
|
---|
327 | if (pDrv->pConsoleVRDPServer)
|
---|
328 | pDrv->pConsoleVRDPServer->SendAudioInputEnd(NULL);
|
---|
329 |
|
---|
330 | return VINF_SUCCESS;
|
---|
331 | }
|
---|
332 |
|
---|
333 | static int vrdeDestroyStreamOut(PPDMIHOSTAUDIO pInterface, PPDMAUDIOSTREAM pStream)
|
---|
334 | {
|
---|
335 | PDRVAUDIOVRDE pDrv = RT_FROM_MEMBER(pInterface, DRVAUDIOVRDE, IHostAudio);
|
---|
336 | AssertPtrReturn(pDrv, VERR_INVALID_POINTER);
|
---|
337 |
|
---|
338 | return VINF_SUCCESS;
|
---|
339 | }
|
---|
340 |
|
---|
341 | static DECLCALLBACK(int) drvAudioVRDEGetConfig(PPDMIHOSTAUDIO pInterface, PPDMAUDIOBACKENDCFG pCfg)
|
---|
342 | {
|
---|
343 | NOREF(pInterface);
|
---|
344 | AssertPtrReturn(pCfg, VERR_INVALID_POINTER);
|
---|
345 |
|
---|
346 | pCfg->cbStreamOut = sizeof(VRDESTREAMOUT);
|
---|
347 | pCfg->cbStreamIn = sizeof(VRDESTREAMIN);
|
---|
348 | pCfg->cMaxStreamsIn = UINT32_MAX;
|
---|
349 | pCfg->cMaxStreamsOut = UINT32_MAX;
|
---|
350 | pCfg->cSources = 1;
|
---|
351 | pCfg->cSinks = 1;
|
---|
352 |
|
---|
353 | return VINF_SUCCESS;
|
---|
354 | }
|
---|
355 |
|
---|
356 | static DECLCALLBACK(void) drvAudioVRDEShutdown(PPDMIHOSTAUDIO pInterface)
|
---|
357 | {
|
---|
358 | PDRVAUDIOVRDE pDrv = RT_FROM_MEMBER(pInterface, DRVAUDIOVRDE, IHostAudio);
|
---|
359 | AssertPtrReturnVoid(pDrv);
|
---|
360 |
|
---|
361 | if (pDrv->pConsoleVRDPServer)
|
---|
362 | pDrv->pConsoleVRDPServer->SendAudioInputEnd(NULL);
|
---|
363 | }
|
---|
364 |
|
---|
365 | static DECLCALLBACK(PDMAUDIOBACKENDSTS) drvAudioVRDEGetStatus(PPDMIHOSTAUDIO pInterface, PDMAUDIODIR enmDir)
|
---|
366 | {
|
---|
367 | AssertPtrReturn(pInterface, PDMAUDIOBACKENDSTS_UNKNOWN);
|
---|
368 |
|
---|
369 | return PDMAUDIOBACKENDSTS_RUNNING;
|
---|
370 | }
|
---|
371 |
|
---|
372 | static DECLCALLBACK(int) drvAudioVRDEStreamCreate(PPDMIHOSTAUDIO pInterface,
|
---|
373 | PPDMAUDIOSTREAM pStream, PPDMAUDIOSTREAMCFG pCfg, uint32_t *pcSamples)
|
---|
374 | {
|
---|
375 | AssertPtrReturn(pInterface, VERR_INVALID_POINTER);
|
---|
376 | AssertPtrReturn(pStream, VERR_INVALID_POINTER);
|
---|
377 | AssertPtrReturn(pCfg, VERR_INVALID_POINTER);
|
---|
378 |
|
---|
379 | int rc;
|
---|
380 | if (pCfg->enmDir == PDMAUDIODIR_IN)
|
---|
381 | rc = vrdeCreateStreamIn(pInterface, pStream, pCfg, pcSamples);
|
---|
382 | else
|
---|
383 | rc = vrdeCreateStreamOut(pInterface, pStream, pCfg, pcSamples);
|
---|
384 |
|
---|
385 | LogFlowFunc(("%s: rc=%Rrc\n", pStream->szName, rc));
|
---|
386 | return rc;
|
---|
387 | }
|
---|
388 |
|
---|
389 | static DECLCALLBACK(int) drvAudioVRDEStreamDestroy(PPDMIHOSTAUDIO pInterface, PPDMAUDIOSTREAM pStream)
|
---|
390 | {
|
---|
391 | AssertPtrReturn(pInterface, VERR_INVALID_POINTER);
|
---|
392 | AssertPtrReturn(pStream, VERR_INVALID_POINTER);
|
---|
393 |
|
---|
394 | int rc;
|
---|
395 | if (pStream->enmDir == PDMAUDIODIR_IN)
|
---|
396 | rc = vrdeDestroyStreamIn(pInterface, pStream);
|
---|
397 | else
|
---|
398 | rc = vrdeDestroyStreamOut(pInterface, pStream);
|
---|
399 |
|
---|
400 | return rc;
|
---|
401 | }
|
---|
402 |
|
---|
403 | static DECLCALLBACK(int) drvAudioVRDEStreamControl(PPDMIHOSTAUDIO pInterface,
|
---|
404 | PPDMAUDIOSTREAM pStream, PDMAUDIOSTREAMCMD enmStreamCmd)
|
---|
405 | {
|
---|
406 | AssertPtrReturn(pInterface, VERR_INVALID_POINTER);
|
---|
407 | AssertPtrReturn(pStream, VERR_INVALID_POINTER);
|
---|
408 |
|
---|
409 | Assert(pStream->enmCtx == PDMAUDIOSTREAMCTX_HOST);
|
---|
410 |
|
---|
411 | int rc;
|
---|
412 | if (pStream->enmDir == PDMAUDIODIR_IN)
|
---|
413 | rc = vrdeControlStreamIn(pInterface, pStream, enmStreamCmd);
|
---|
414 | else
|
---|
415 | rc = vrdeControlStreamOut(pInterface, pStream, enmStreamCmd);
|
---|
416 |
|
---|
417 | return rc;
|
---|
418 | }
|
---|
419 |
|
---|
420 | static DECLCALLBACK(PDMAUDIOSTRMSTS) drvAudioVRDEStreamGetStatus(PPDMIHOSTAUDIO pInterface, PPDMAUDIOSTREAM pStream)
|
---|
421 | {
|
---|
422 | NOREF(pInterface);
|
---|
423 | NOREF(pStream);
|
---|
424 |
|
---|
425 | return (PDMAUDIOSTRMSTS_FLAG_INITIALIZED | PDMAUDIOSTRMSTS_FLAG_ENABLED);
|
---|
426 | }
|
---|
427 |
|
---|
428 | static DECLCALLBACK(int) drvAudioVRDEStreamIterate(PPDMIHOSTAUDIO pInterface, PPDMAUDIOSTREAM pStream)
|
---|
429 | {
|
---|
430 | AssertPtrReturn(pInterface, VERR_INVALID_POINTER);
|
---|
431 | AssertPtrReturn(pStream, VERR_INVALID_POINTER);
|
---|
432 |
|
---|
433 | LogFlowFuncEnter();
|
---|
434 |
|
---|
435 | /* Nothing to do here for VRDE. */
|
---|
436 | return VINF_SUCCESS;
|
---|
437 | }
|
---|
438 |
|
---|
439 | /**
|
---|
440 | * @interface_method_impl{PDMIBASE,pfnQueryInterface}
|
---|
441 | */
|
---|
442 | static DECLCALLBACK(void *) drvAudioVRDEQueryInterface(PPDMIBASE pInterface, const char *pszIID)
|
---|
443 | {
|
---|
444 | PPDMDRVINS pDrvIns = PDMIBASE_2_PDMDRV(pInterface);
|
---|
445 | PDRVAUDIOVRDE pThis = PDMINS_2_DATA(pDrvIns, PDRVAUDIOVRDE);
|
---|
446 |
|
---|
447 | PDMIBASE_RETURN_INTERFACE(pszIID, PDMIBASE, &pDrvIns->IBase);
|
---|
448 | PDMIBASE_RETURN_INTERFACE(pszIID, PDMIHOSTAUDIO, &pThis->IHostAudio);
|
---|
449 | return NULL;
|
---|
450 | }
|
---|
451 |
|
---|
452 | AudioVRDE::AudioVRDE(Console *pConsole)
|
---|
453 | : mpDrv(NULL),
|
---|
454 | mParent(pConsole)
|
---|
455 | {
|
---|
456 | }
|
---|
457 |
|
---|
458 | AudioVRDE::~AudioVRDE(void)
|
---|
459 | {
|
---|
460 | if (mpDrv)
|
---|
461 | {
|
---|
462 | mpDrv->pAudioVRDE = NULL;
|
---|
463 | mpDrv = NULL;
|
---|
464 | }
|
---|
465 | }
|
---|
466 |
|
---|
467 | int AudioVRDE::onVRDEControl(bool fEnable, uint32_t uFlags)
|
---|
468 | {
|
---|
469 | LogFlowThisFunc(("fEnable=%RTbool, uFlags=0x%x\n", fEnable, uFlags));
|
---|
470 |
|
---|
471 | if (mpDrv == NULL)
|
---|
472 | return VERR_INVALID_STATE;
|
---|
473 |
|
---|
474 | mpDrv->fEnabled = fEnable;
|
---|
475 |
|
---|
476 | return VINF_SUCCESS; /* Never veto. */
|
---|
477 | }
|
---|
478 |
|
---|
479 | /**
|
---|
480 | * Marks the beginning of sending captured audio data from a connected
|
---|
481 | * RDP client.
|
---|
482 | *
|
---|
483 | * @return IPRT status code.
|
---|
484 | * @param pvContext The context; in this case a pointer to a
|
---|
485 | * VRDESTREAMIN structure.
|
---|
486 | * @param pVRDEAudioBegin Pointer to a VRDEAUDIOINBEGIN structure.
|
---|
487 | */
|
---|
488 | int AudioVRDE::onVRDEInputBegin(void *pvContext, PVRDEAUDIOINBEGIN pVRDEAudioBegin)
|
---|
489 | {
|
---|
490 | AssertPtrReturn(pvContext, VERR_INVALID_POINTER);
|
---|
491 | AssertPtrReturn(pVRDEAudioBegin, VERR_INVALID_POINTER);
|
---|
492 |
|
---|
493 | PVRDESTREAMIN pVRDEStrmIn = (PVRDESTREAMIN)pvContext;
|
---|
494 | AssertPtrReturn(pVRDEStrmIn, VERR_INVALID_POINTER);
|
---|
495 |
|
---|
496 | VRDEAUDIOFORMAT audioFmt = pVRDEAudioBegin->fmt;
|
---|
497 |
|
---|
498 | int iSampleHz = VRDE_AUDIO_FMT_SAMPLE_FREQ(audioFmt);
|
---|
499 | int cChannels = VRDE_AUDIO_FMT_CHANNELS(audioFmt);
|
---|
500 | int cBits = VRDE_AUDIO_FMT_BITS_PER_SAMPLE(audioFmt);
|
---|
501 | bool fUnsigned = VRDE_AUDIO_FMT_SIGNED(audioFmt);
|
---|
502 |
|
---|
503 | LogFlowFunc(("cbSample=%RU32, iSampleHz=%d, cChannels=%d, cBits=%d, fUnsigned=%RTbool\n",
|
---|
504 | VRDE_AUDIO_FMT_BYTES_PER_SAMPLE(audioFmt), iSampleHz, cChannels, cBits, fUnsigned));
|
---|
505 |
|
---|
506 | return VINF_SUCCESS;
|
---|
507 | }
|
---|
508 |
|
---|
509 | int AudioVRDE::onVRDEInputData(void *pvContext, const void *pvData, uint32_t cbData)
|
---|
510 | {
|
---|
511 | PVRDESTREAMIN pVRDEStrmIn = (PVRDESTREAMIN)pvContext;
|
---|
512 | AssertPtrReturn(pVRDEStrmIn, VERR_INVALID_POINTER);
|
---|
513 |
|
---|
514 | PPDMAUDIOSTREAM pStream = &pVRDEStrmIn->Stream;
|
---|
515 | AssertPtrReturn(pStream, VERR_INVALID_POINTER);
|
---|
516 |
|
---|
517 | /** @todo Use CritSect! */
|
---|
518 |
|
---|
519 | uint32_t cWritten;
|
---|
520 | int rc = AudioMixBufWriteCirc(&pStream->MixBuf, pvData, cbData, &cWritten);
|
---|
521 | if (RT_SUCCESS(rc))
|
---|
522 | pVRDEStrmIn->cSamplesCaptured += cWritten;
|
---|
523 |
|
---|
524 | LogFlowFunc(("cbData=%RU32, cWritten=%RU32, cSamplesCaptured=%RU32, rc=%Rrc\n",
|
---|
525 | cbData, cWritten, pVRDEStrmIn->cSamplesCaptured, rc));
|
---|
526 | return rc;
|
---|
527 | }
|
---|
528 |
|
---|
529 | int AudioVRDE::onVRDEInputEnd(void *pvContext)
|
---|
530 | {
|
---|
531 | NOREF(pvContext);
|
---|
532 |
|
---|
533 | return VINF_SUCCESS;
|
---|
534 | }
|
---|
535 |
|
---|
536 | int AudioVRDE::onVRDEInputIntercept(bool fEnabled)
|
---|
537 | {
|
---|
538 | return VINF_SUCCESS; /* Never veto. */
|
---|
539 | }
|
---|
540 |
|
---|
541 | /**
|
---|
542 | * Construct a VRDE audio driver instance.
|
---|
543 | *
|
---|
544 | * @copydoc FNPDMDRVCONSTRUCT
|
---|
545 | */
|
---|
546 | /* static */
|
---|
547 | DECLCALLBACK(int) AudioVRDE::drvConstruct(PPDMDRVINS pDrvIns, PCFGMNODE pCfg, uint32_t fFlags)
|
---|
548 | {
|
---|
549 | PDMDRV_CHECK_VERSIONS_RETURN(pDrvIns);
|
---|
550 | PDRVAUDIOVRDE pThis = PDMINS_2_DATA(pDrvIns, PDRVAUDIOVRDE);
|
---|
551 | AssertPtrReturn(pDrvIns, VERR_INVALID_POINTER);
|
---|
552 | AssertPtrReturn(pCfg, VERR_INVALID_POINTER);
|
---|
553 |
|
---|
554 | LogRel(("Audio: Initializing VRDE driver\n"));
|
---|
555 | LogFlowFunc(("fFlags=0x%x\n", fFlags));
|
---|
556 |
|
---|
557 | AssertMsgReturn(PDMDrvHlpNoAttach(pDrvIns) == VERR_PDM_NO_ATTACHED_DRIVER,
|
---|
558 | ("Configuration error: Not possible to attach anything to this driver!\n"),
|
---|
559 | VERR_PDM_DRVINS_NO_ATTACH);
|
---|
560 |
|
---|
561 | /*
|
---|
562 | * Init the static parts.
|
---|
563 | */
|
---|
564 | pThis->pDrvIns = pDrvIns;
|
---|
565 | /* IBase */
|
---|
566 | pDrvIns->IBase.pfnQueryInterface = drvAudioVRDEQueryInterface;
|
---|
567 | /* IHostAudio */
|
---|
568 | PDMAUDIO_IHOSTAUDIO_CALLBACKS(drvAudioVRDE);
|
---|
569 |
|
---|
570 | /* Init defaults. */
|
---|
571 | pThis->fEnabled = false;
|
---|
572 |
|
---|
573 | /*
|
---|
574 | * Get the ConsoleVRDPServer object pointer.
|
---|
575 | */
|
---|
576 | void *pvUser;
|
---|
577 | int rc = CFGMR3QueryPtr(pCfg, "ObjectVRDPServer", &pvUser);
|
---|
578 | AssertMsgRCReturn(rc, ("Confguration error: No/bad \"ObjectVRDPServer\" value, rc=%Rrc\n", rc), rc);
|
---|
579 |
|
---|
580 | /* CFGM tree saves the pointer to ConsoleVRDPServer in the Object node of AudioVRDE. */
|
---|
581 | pThis->pConsoleVRDPServer = (ConsoleVRDPServer *)pvUser;
|
---|
582 |
|
---|
583 | /*
|
---|
584 | * Get the AudioVRDE object pointer.
|
---|
585 | */
|
---|
586 | pvUser = NULL;
|
---|
587 | rc = CFGMR3QueryPtr(pCfg, "Object", &pvUser);
|
---|
588 | AssertMsgRCReturn(rc, ("Confguration error: No/bad \"Object\" value, rc=%Rrc\n", rc), rc);
|
---|
589 |
|
---|
590 | pThis->pAudioVRDE = (AudioVRDE *)pvUser;
|
---|
591 | pThis->pAudioVRDE->mpDrv = pThis;
|
---|
592 |
|
---|
593 | /*
|
---|
594 | * Get the interface for the above driver (DrvAudio) to make mixer/conversion calls.
|
---|
595 | * Described in CFGM tree.
|
---|
596 | */
|
---|
597 | pThis->pDrvAudio = PDMIBASE_QUERY_INTERFACE(pDrvIns->pUpBase, PDMIAUDIOCONNECTOR);
|
---|
598 | AssertMsgReturn(pThis->pDrvAudio, ("Configuration error: No upper interface specified!\n"), VERR_PDM_MISSING_INTERFACE_ABOVE);
|
---|
599 |
|
---|
600 | return VINF_SUCCESS;
|
---|
601 | }
|
---|
602 |
|
---|
603 |
|
---|
604 | /**
|
---|
605 | * @interface_method_impl{PDMDRVREG,pfnDestruct}
|
---|
606 | */
|
---|
607 | /* static */
|
---|
608 | DECLCALLBACK(void) AudioVRDE::drvDestruct(PPDMDRVINS pDrvIns)
|
---|
609 | {
|
---|
610 | PDMDRV_CHECK_VERSIONS_RETURN_VOID(pDrvIns);
|
---|
611 | PDRVAUDIOVRDE pThis = PDMINS_2_DATA(pDrvIns, PDRVAUDIOVRDE);
|
---|
612 | LogFlowFuncEnter();
|
---|
613 |
|
---|
614 | /*
|
---|
615 | * If the AudioVRDE object is still alive, we must clear it's reference to
|
---|
616 | * us since we'll be invalid when we return from this method.
|
---|
617 | */
|
---|
618 | if (pThis->pAudioVRDE)
|
---|
619 | {
|
---|
620 | pThis->pAudioVRDE->mpDrv = NULL;
|
---|
621 | pThis->pAudioVRDE = NULL;
|
---|
622 | }
|
---|
623 | }
|
---|
624 |
|
---|
625 |
|
---|
626 | /**
|
---|
627 | * VRDE audio driver registration record.
|
---|
628 | */
|
---|
629 | const PDMDRVREG AudioVRDE::DrvReg =
|
---|
630 | {
|
---|
631 | PDM_DRVREG_VERSION,
|
---|
632 | /* szName */
|
---|
633 | "AudioVRDE",
|
---|
634 | /* szRCMod */
|
---|
635 | "",
|
---|
636 | /* szR0Mod */
|
---|
637 | "",
|
---|
638 | /* pszDescription */
|
---|
639 | "Audio driver for VRDE backend",
|
---|
640 | /* fFlags */
|
---|
641 | PDM_DRVREG_FLAGS_HOST_BITS_DEFAULT,
|
---|
642 | /* fClass. */
|
---|
643 | PDM_DRVREG_CLASS_AUDIO,
|
---|
644 | /* cMaxInstances */
|
---|
645 | ~0U,
|
---|
646 | /* cbInstance */
|
---|
647 | sizeof(DRVAUDIOVRDE),
|
---|
648 | /* pfnConstruct */
|
---|
649 | AudioVRDE::drvConstruct,
|
---|
650 | /* pfnDestruct */
|
---|
651 | AudioVRDE::drvDestruct,
|
---|
652 | /* pfnRelocate */
|
---|
653 | NULL,
|
---|
654 | /* pfnIOCtl */
|
---|
655 | NULL,
|
---|
656 | /* pfnPowerOn */
|
---|
657 | NULL,
|
---|
658 | /* pfnReset */
|
---|
659 | NULL,
|
---|
660 | /* pfnSuspend */
|
---|
661 | NULL,
|
---|
662 | /* pfnResume */
|
---|
663 | NULL,
|
---|
664 | /* pfnAttach */
|
---|
665 | NULL,
|
---|
666 | /* pfnDetach */
|
---|
667 | NULL,
|
---|
668 | /* pfnPowerOff */
|
---|
669 | NULL,
|
---|
670 | /* pfnSoftReset */
|
---|
671 | NULL,
|
---|
672 | /* u32EndVersion */
|
---|
673 | PDM_DRVREG_VERSION
|
---|
674 | };
|
---|
675 |
|
---|