VirtualBox

source: vbox/trunk/src/VBox/Main/src-client/DrvAudioVRDE.cpp@ 68393

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

Main/DrvAudioVRDE: Renaming.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 23.6 KB
Line 
1/* $Id: DrvAudioVRDE.cpp 68393 2017-08-11 12:41:23Z vboxsync $ */
2/** @file
3 * VRDE audio backend for Main.
4 */
5
6/*
7 * Copyright (C) 2013-2017 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_HOST_AUDIO
23#include "LoggingNew.h"
24
25#include <VBox/log.h>
26#include "DrvAudioVRDE.h"
27#include "ConsoleImpl.h"
28#include "ConsoleVRDPServer.h"
29
30#include "../../Devices/Audio/DrvAudio.h"
31
32#include <iprt/mem.h>
33#include <iprt/cdefs.h>
34#include <iprt/circbuf.h>
35
36#include <VBox/vmm/pdmaudioifs.h>
37#include <VBox/vmm/pdmdrv.h>
38#include <VBox/RemoteDesktop/VRDE.h>
39#include <VBox/vmm/cfgm.h>
40#include <VBox/err.h>
41
42
43/*********************************************************************************************************************************
44* Structures and Typedefs *
45*********************************************************************************************************************************/
46/**
47 * Audio VRDE driver instance data.
48 */
49typedef struct DRVAUDIOVRDE
50{
51 /** Pointer to audio VRDE object. */
52 AudioVRDE *pAudioVRDE;
53 /** Pointer to the driver instance structure. */
54 PPDMDRVINS pDrvIns;
55 /** Pointer to host audio interface. */
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} DRVAUDIOVRDE, *PDRVAUDIOVRDE;
62
63typedef struct VRDESTREAM
64{
65 /** The stream's acquired configuration. */
66 PPDMAUDIOSTREAMCFG pCfg;
67 union
68 {
69 struct
70 {
71 /** Number of audio frames this stream can handle at once. */
72 uint32_t cfMax;
73 /** Circular buffer for holding the recorded audio frames from the host. */
74 PRTCIRCBUF pCircBuf;
75 } In;
76 struct
77 {
78 /** Timestamp (in virtual time ticks) of the last audio playback (of the VRDP server). */
79 uint64_t ticksPlayedLast;
80 /** Internal counter (in audio frames) to track if and how much we can write to the VRDP server
81 * for the current time period. */
82 uint64_t cfToWrite;
83 } Out;
84 };
85} VRDESTREAM, *PVRDESTREAM;
86
87/* Sanity. */
88AssertCompileSize(PDMAUDIOFRAME, sizeof(int64_t) * 2 /* st_sample_t using by VRDP server */);
89
90static int vrdeCreateStreamIn(PVRDESTREAM pStreamVRDE, PPDMAUDIOSTREAMCFG pCfgReq, PPDMAUDIOSTREAMCFG pCfgAcq)
91{
92 pStreamVRDE->In.cfMax = _1K; /** @todo Make this configurable. */
93
94 int rc = RTCircBufCreate(&pStreamVRDE->In.pCircBuf, pStreamVRDE->In.cfMax * (pCfgReq->Props.cBits / 8) /* Bytes */);
95 if (RT_SUCCESS(rc))
96 {
97 if (pCfgAcq)
98 {
99 /*
100 * Because of historical reasons the VRDP server operates on st_sample_t structures internally,
101 * which is 2 * int64_t for left/right (stereo) channels.
102 *
103 * As the audio connector also uses this format, set the layout to "raw" and just let pass through
104 * the data without any layout modification needed.
105 */
106 pCfgAcq->enmLayout = PDMAUDIOSTREAMLAYOUT_RAW;
107 pCfgAcq->cFrameBufferHint = pStreamVRDE->In.cfMax;
108 }
109 }
110
111 return rc;
112}
113
114
115static int vrdeCreateStreamOut(PVRDESTREAM pStreamVRDE, PPDMAUDIOSTREAMCFG pCfgReq, PPDMAUDIOSTREAMCFG pCfgAcq)
116{
117 RT_NOREF(pStreamVRDE, pCfgReq);
118
119 if (pCfgAcq)
120 {
121 /*
122 * Because of historical reasons the VRDP server operates on st_sample_t structures internally,
123 * which is 2 * int64_t for left/right (stereo) channels.
124 *
125 * As the audio connector also uses this format, set the layout to "raw" and just let pass through
126 * the data without any layout modification needed.
127 */
128 pCfgAcq->enmLayout = PDMAUDIOSTREAMLAYOUT_RAW;
129 pCfgAcq->cFrameBufferHint = _4K; /** @todo Make this configurable. */
130 }
131
132 return VINF_SUCCESS;
133}
134
135
136static int vrdeControlStreamOut(PDRVAUDIOVRDE pDrv, PVRDESTREAM pStreamVRDE, PDMAUDIOSTREAMCMD enmStreamCmd)
137{
138 RT_NOREF(pDrv, pStreamVRDE, enmStreamCmd);
139
140 LogFlowFunc(("enmStreamCmd=%ld\n", enmStreamCmd));
141
142 return VINF_SUCCESS;
143}
144
145
146static int vrdeControlStreamIn(PDRVAUDIOVRDE pDrv, PVRDESTREAM pStreamVRDE, PDMAUDIOSTREAMCMD enmStreamCmd)
147{
148 LogFlowFunc(("enmStreamCmd=%ld\n", enmStreamCmd));
149
150 if (!pDrv->pConsoleVRDPServer)
151 return VINF_SUCCESS;
152
153 int rc;
154
155 /* Initialize only if not already done. */
156 switch (enmStreamCmd)
157 {
158 case PDMAUDIOSTREAMCMD_ENABLE:
159 {
160 rc = pDrv->pConsoleVRDPServer->SendAudioInputBegin(NULL, pStreamVRDE, pStreamVRDE->In.cfMax,
161 pStreamVRDE->pCfg->Props.uHz, pStreamVRDE->pCfg->Props.cChannels,
162 pStreamVRDE->pCfg->Props.cBits);
163 if (rc == VERR_NOT_SUPPORTED)
164 {
165 LogFunc(("No RDP client connected, so no input recording supported\n"));
166 rc = VINF_SUCCESS;
167 }
168
169 break;
170 }
171
172 case PDMAUDIOSTREAMCMD_DISABLE:
173 {
174 pDrv->pConsoleVRDPServer->SendAudioInputEnd(NULL /* pvUserCtx */);
175 rc = VINF_SUCCESS;
176
177 break;
178 }
179
180 case PDMAUDIOSTREAMCMD_PAUSE:
181 {
182 rc = VINF_SUCCESS;
183 break;
184 }
185
186 case PDMAUDIOSTREAMCMD_RESUME:
187 {
188 rc = VINF_SUCCESS;
189 break;
190 }
191
192 default:
193 {
194 rc = VERR_NOT_SUPPORTED;
195 break;
196 }
197 }
198
199 if (RT_FAILURE(rc))
200 LogFunc(("Failed with %Rrc\n", rc));
201
202 return rc;
203}
204
205
206/**
207 * @interface_method_impl{PDMIHOSTAUDIO,pfnInit}
208 */
209static DECLCALLBACK(int) drvAudioVRDEInit(PPDMIHOSTAUDIO pInterface)
210{
211 RT_NOREF(pInterface);
212 LogFlowFuncEnter();
213
214 return VINF_SUCCESS;
215}
216
217
218/**
219 * @interface_method_impl{PDMIHOSTAUDIO,pfnStreamCapture}
220 */
221static DECLCALLBACK(int) drvAudioVRDEStreamCapture(PPDMIHOSTAUDIO pInterface,
222 PPDMAUDIOBACKENDSTREAM pStream, void *pvBuf, uint32_t cxBuf, uint32_t *pcxRead)
223{
224 AssertPtrReturn(pInterface, VERR_INVALID_POINTER);
225 AssertPtrReturn(pStream, VERR_INVALID_POINTER);
226 AssertPtrReturn(pvBuf, VERR_INVALID_POINTER);
227 AssertReturn(cxBuf, VERR_INVALID_PARAMETER);
228 /* pcxRead is optional. */
229
230 PVRDESTREAM pStreamVRDE = (PVRDESTREAM)pStream;
231
232 size_t cbData = 0;
233
234 if (RTCircBufUsed(pStreamVRDE->In.pCircBuf))
235 {
236 void *pvData;
237
238 RTCircBufAcquireReadBlock(pStreamVRDE->In.pCircBuf, cxBuf, &pvData, &cbData);
239
240 if (cbData)
241 memcpy(pvBuf, pvData, cbData);
242
243 RTCircBufReleaseReadBlock(pStreamVRDE->In.pCircBuf, cbData);
244 }
245
246 if (pcxRead)
247 *pcxRead = (uint32_t)cbData;
248
249 return VINF_SUCCESS;
250}
251
252
253/**
254 * @interface_method_impl{PDMIHOSTAUDIO,pfnStreamPlay}
255 */
256static DECLCALLBACK(int) drvAudioVRDEStreamPlay(PPDMIHOSTAUDIO pInterface, PPDMAUDIOBACKENDSTREAM pStream,
257 const void *pvBuf, uint32_t cxBuf, uint32_t *pcxWritten)
258{
259 AssertPtrReturn(pInterface, VERR_INVALID_POINTER);
260 AssertPtrReturn(pStream, VERR_INVALID_POINTER);
261 AssertPtrReturn(pvBuf, VERR_INVALID_POINTER);
262 AssertReturn(cxBuf, VERR_INVALID_PARAMETER);
263 /* pcxWritten is optional. */
264
265 PDRVAUDIOVRDE pDrv = RT_FROM_MEMBER(pInterface, DRVAUDIOVRDE, IHostAudio);
266 PVRDESTREAM pStreamVRDE = (PVRDESTREAM)pStream;
267
268 if (!pDrv->pConsoleVRDPServer)
269 return VERR_NOT_AVAILABLE;
270
271 /* Note: We get the number of *frames* in cxBuf
272 * (since we specified PDMAUDIOSTREAMLAYOUT_RAW as the audio data layout) on stream creation. */
273 uint32_t cfLive = cxBuf;
274
275 PPDMAUDIOPCMPROPS pProps = &pStreamVRDE->pCfg->Props;
276
277 VRDEAUDIOFORMAT format = VRDE_AUDIO_FMT_MAKE(pProps->uHz,
278 pProps->cChannels,
279 pProps->cBits,
280 pProps->fSigned);
281
282 /* Use the internal counter to track if we (still) can write to the VRDP server
283 * or if we need to wait another round (time slot). */
284 uint32_t cfToWrite = pStreamVRDE->Out.cfToWrite;
285
286 Log3Func(("cfLive=%RU32, cfToWrite=%RU32\n", cfLive, cfToWrite));
287
288 /* Don't play more than available. */
289 if (cfToWrite > cfLive)
290 cfToWrite = cfLive;
291
292 int rc = VINF_SUCCESS;
293
294 PPDMAUDIOFRAME paSampleBuf = (PPDMAUDIOFRAME)pvBuf;
295 AssertPtr(paSampleBuf);
296
297 /*
298 * Call the VRDP server with the data.
299 */
300 uint32_t cfWritten = 0;
301 while (cfToWrite)
302 {
303 uint32_t cfChunk = cfToWrite; /** @todo For now write all at once. */
304
305 if (!cfChunk) /* Nothing to send. Bail out. */
306 break;
307
308 /* Note: The VRDP server expects int64_t samples per channel, regardless of the actual
309 * sample bits (e.g 8 or 16 bits). */
310 pDrv->pConsoleVRDPServer->SendAudioSamples(paSampleBuf + cfWritten, cfChunk /* Frames */, format);
311
312 cfWritten += cfChunk;
313 Assert(cfWritten <= cfLive);
314
315 Assert(cfToWrite >= cfChunk);
316 cfToWrite -= cfChunk;
317 }
318
319 if (RT_SUCCESS(rc))
320 {
321 /* Subtract written frames from the counter. */
322 Assert(pStreamVRDE->Out.cfToWrite >= cfWritten);
323 pStreamVRDE->Out.cfToWrite -= cfWritten;
324
325 /* Remember when frames were consumed. */
326 pStreamVRDE->Out.ticksPlayedLast = PDMDrvHlpTMGetVirtualTime(pDrv->pDrvIns);
327
328 /* Return frames instead of bytes here
329 * (since we specified PDMAUDIOSTREAMLAYOUT_RAW as the audio data layout). */
330 if (pcxWritten)
331 *pcxWritten = cfWritten;
332 }
333
334 return rc;
335}
336
337
338static int vrdeDestroyStreamIn(PDRVAUDIOVRDE pDrv, PVRDESTREAM pStreamVRDE)
339{
340 if (pDrv->pConsoleVRDPServer)
341 pDrv->pConsoleVRDPServer->SendAudioInputEnd(NULL);
342
343 if (pStreamVRDE->In.pCircBuf)
344 {
345 RTCircBufDestroy(pStreamVRDE->In.pCircBuf);
346 pStreamVRDE->In.pCircBuf = NULL;
347 }
348
349 return VINF_SUCCESS;
350}
351
352
353static int vrdeDestroyStreamOut(PDRVAUDIOVRDE pDrv, PVRDESTREAM pStreamVRDE)
354{
355 RT_NOREF(pDrv, pStreamVRDE);
356
357 return VINF_SUCCESS;
358}
359
360
361/**
362 * @interface_method_impl{PDMIHOSTAUDIO,pfnGetConfig}
363 */
364static DECLCALLBACK(int) drvAudioVRDEGetConfig(PPDMIHOSTAUDIO pInterface, PPDMAUDIOBACKENDCFG pBackendCfg)
365{
366 RT_NOREF(pInterface);
367 AssertPtrReturn(pBackendCfg, VERR_INVALID_POINTER);
368
369 pBackendCfg->cbStreamOut = sizeof(VRDESTREAM);
370 pBackendCfg->cbStreamIn = sizeof(VRDESTREAM);
371 pBackendCfg->cMaxStreamsIn = UINT32_MAX;
372 pBackendCfg->cMaxStreamsOut = UINT32_MAX;
373
374 return VINF_SUCCESS;
375}
376
377
378/**
379 * @interface_method_impl{PDMIHOSTAUDIO,pfnShutdown}
380 */
381static DECLCALLBACK(void) drvAudioVRDEShutdown(PPDMIHOSTAUDIO pInterface)
382{
383 PDRVAUDIOVRDE pDrv = RT_FROM_MEMBER(pInterface, DRVAUDIOVRDE, IHostAudio);
384 AssertPtrReturnVoid(pDrv);
385
386 if (pDrv->pConsoleVRDPServer)
387 pDrv->pConsoleVRDPServer->SendAudioInputEnd(NULL);
388}
389
390
391/**
392 * @interface_method_impl{PDMIHOSTAUDIO,pfnGetStatus}
393 */
394static DECLCALLBACK(PDMAUDIOBACKENDSTS) drvAudioVRDEGetStatus(PPDMIHOSTAUDIO pInterface, PDMAUDIODIR enmDir)
395{
396 RT_NOREF(enmDir);
397 AssertPtrReturn(pInterface, PDMAUDIOBACKENDSTS_UNKNOWN);
398
399 return PDMAUDIOBACKENDSTS_RUNNING;
400}
401
402
403/**
404 * @interface_method_impl{PDMIHOSTAUDIO,pfnStreamCreate}
405 */
406static DECLCALLBACK(int) drvAudioVRDEStreamCreate(PPDMIHOSTAUDIO pInterface, PPDMAUDIOBACKENDSTREAM pStream,
407 PPDMAUDIOSTREAMCFG pCfgReq, PPDMAUDIOSTREAMCFG pCfgAcq)
408{
409 AssertPtrReturn(pInterface, VERR_INVALID_POINTER);
410 AssertPtrReturn(pStream, VERR_INVALID_POINTER);
411 AssertPtrReturn(pCfgReq, VERR_INVALID_POINTER);
412 AssertPtrReturn(pCfgAcq, VERR_INVALID_POINTER);
413
414 RT_NOREF(pInterface);
415
416 PVRDESTREAM pStreamVRDE = (PVRDESTREAM)pStream;
417
418 int rc;
419 if (pCfgReq->enmDir == PDMAUDIODIR_IN)
420 rc = vrdeCreateStreamIn (pStreamVRDE, pCfgReq, pCfgAcq);
421 else
422 rc = vrdeCreateStreamOut(pStreamVRDE, pCfgReq, pCfgAcq);
423
424 if (RT_SUCCESS(rc))
425 {
426 pStreamVRDE->pCfg = DrvAudioHlpStreamCfgDup(pCfgAcq);
427 if (!pStreamVRDE->pCfg)
428 rc = VERR_NO_MEMORY;
429 }
430
431 return rc;
432}
433
434
435/**
436 * @interface_method_impl{PDMIHOSTAUDIO,pfnStreamDestroy}
437 */
438static DECLCALLBACK(int) drvAudioVRDEStreamDestroy(PPDMIHOSTAUDIO pInterface, PPDMAUDIOBACKENDSTREAM pStream)
439{
440 RT_NOREF(pInterface);
441 AssertPtrReturn(pStream, VERR_INVALID_POINTER);
442
443 PDRVAUDIOVRDE pDrv = RT_FROM_MEMBER(pInterface, DRVAUDIOVRDE, IHostAudio);
444 PVRDESTREAM pStreamVRDE = (PVRDESTREAM)pStream;
445
446 if (!pStreamVRDE->pCfg) /* Not (yet) configured? Skip. */
447 return VINF_SUCCESS;
448
449 int rc;
450 if (pStreamVRDE->pCfg->enmDir == PDMAUDIODIR_IN)
451 rc = vrdeDestroyStreamIn(pDrv, pStreamVRDE);
452 else
453 rc = vrdeDestroyStreamOut(pDrv, pStreamVRDE);
454
455 if (RT_SUCCESS(rc))
456 {
457 DrvAudioHlpStreamCfgFree(pStreamVRDE->pCfg);
458 pStreamVRDE->pCfg = NULL;
459 }
460
461 return rc;
462}
463
464
465/**
466 * @interface_method_impl{PDMIHOSTAUDIO,pfnStreamControl}
467 */
468static DECLCALLBACK(int) drvAudioVRDEStreamControl(PPDMIHOSTAUDIO pInterface,
469 PPDMAUDIOBACKENDSTREAM pStream, PDMAUDIOSTREAMCMD enmStreamCmd)
470{
471 AssertPtrReturn(pInterface, VERR_INVALID_POINTER);
472 AssertPtrReturn(pStream, VERR_INVALID_POINTER);
473
474 PDRVAUDIOVRDE pDrv = RT_FROM_MEMBER(pInterface, DRVAUDIOVRDE, IHostAudio);
475 PVRDESTREAM pStreamVRDE = (PVRDESTREAM)pStream;
476
477 if (!pStreamVRDE->pCfg) /* Not (yet) configured? Skip. */
478 return VINF_SUCCESS;
479
480 int rc;
481 if (pStreamVRDE->pCfg->enmDir == PDMAUDIODIR_IN)
482 rc = vrdeControlStreamIn(pDrv, pStreamVRDE, enmStreamCmd);
483 else
484 rc = vrdeControlStreamOut(pDrv, pStreamVRDE, enmStreamCmd);
485
486 return rc;
487}
488
489
490/**
491 * @interface_method_impl{PDMIHOSTAUDIO,pfnStreamGetReadable}
492 */
493static DECLCALLBACK(uint32_t) drvAudioVRDEStreamGetReadable(PPDMIHOSTAUDIO pInterface, PPDMAUDIOBACKENDSTREAM pStream)
494{
495 RT_NOREF(pInterface);
496
497 PVRDESTREAM pStreamVRDE = (PVRDESTREAM)pStream;
498
499 if (pStreamVRDE->pCfg->enmDir == PDMAUDIODIR_IN)
500 {
501 /* Return frames instead of bytes here
502 * (since we specified PDMAUDIOSTREAMLAYOUT_RAW as the audio data layout). */
503 return (uint32_t)PDMAUDIOSTREAMCFG_B2F(pStreamVRDE->pCfg, RTCircBufUsed(pStreamVRDE->In.pCircBuf));
504 }
505
506 return 0;
507}
508
509
510/**
511 * @interface_method_impl{PDMIHOSTAUDIO,pfnStreamGetWritable}
512 */
513static DECLCALLBACK(uint32_t) drvAudioVRDEStreamGetWritable(PPDMIHOSTAUDIO pInterface, PPDMAUDIOBACKENDSTREAM pStream)
514{
515 PDRVAUDIOVRDE pDrv = RT_FROM_MEMBER(pInterface, DRVAUDIOVRDE, IHostAudio);
516 PVRDESTREAM pStreamVRDE = (PVRDESTREAM)pStream;
517
518 const uint64_t ticksNow = PDMDrvHlpTMGetVirtualTime(pDrv->pDrvIns);
519 const uint64_t ticksElapsed = ticksNow - pStreamVRDE->Out.ticksPlayedLast;
520 const uint64_t ticksPerSec = PDMDrvHlpTMGetVirtualFreq(pDrv->pDrvIns);
521
522 PPDMAUDIOPCMPROPS pProps = &pStreamVRDE->pCfg->Props;
523
524 /* Minimize the rounding error: frames = int((ticks * freq) / ticks_per_second + 0.5). */
525 pStreamVRDE->Out.cfToWrite = (int)((2 * ticksElapsed * pProps->uHz + ticksPerSec) / ticksPerSec / 2);
526
527 /* Return frames instead of bytes here
528 * (since we specified PDMAUDIOSTREAMLAYOUT_RAW as the audio data layout). */
529 return pStreamVRDE->Out.cfToWrite;
530}
531
532
533/**
534 * @interface_method_impl{PDMIHOSTAUDIO,pfnStreamGetStatus}
535 */
536static DECLCALLBACK(PDMAUDIOSTREAMSTS) drvAudioVRDEStreamGetStatus(PPDMIHOSTAUDIO pInterface, PPDMAUDIOBACKENDSTREAM pStream)
537{
538 RT_NOREF(pInterface, pStream);
539
540 return (PDMAUDIOSTREAMSTS_FLAG_INITIALIZED | PDMAUDIOSTREAMSTS_FLAG_ENABLED);
541}
542
543
544/**
545 * @interface_method_impl{PDMIHOSTAUDIO,pfnStreamIterate}
546 */
547static DECLCALLBACK(int) drvAudioVRDEStreamIterate(PPDMIHOSTAUDIO pInterface, PPDMAUDIOBACKENDSTREAM pStream)
548{
549 AssertPtrReturn(pInterface, VERR_INVALID_POINTER);
550 AssertPtrReturn(pStream, VERR_INVALID_POINTER);
551
552 /* Nothing to do here for VRDE. */
553 return VINF_SUCCESS;
554}
555
556
557/**
558 * @interface_method_impl{PDMIBASE,pfnQueryInterface}
559 */
560static DECLCALLBACK(void *) drvAudioVRDEQueryInterface(PPDMIBASE pInterface, const char *pszIID)
561{
562 PPDMDRVINS pDrvIns = PDMIBASE_2_PDMDRV(pInterface);
563 PDRVAUDIOVRDE pThis = PDMINS_2_DATA(pDrvIns, PDRVAUDIOVRDE);
564
565 PDMIBASE_RETURN_INTERFACE(pszIID, PDMIBASE, &pDrvIns->IBase);
566 PDMIBASE_RETURN_INTERFACE(pszIID, PDMIHOSTAUDIO, &pThis->IHostAudio);
567 return NULL;
568}
569
570
571AudioVRDE::AudioVRDE(Console *pConsole)
572 : mpDrv(NULL),
573 mParent(pConsole)
574{
575}
576
577
578AudioVRDE::~AudioVRDE(void)
579{
580 if (mpDrv)
581 {
582 mpDrv->pAudioVRDE = NULL;
583 mpDrv = NULL;
584 }
585}
586
587
588int AudioVRDE::onVRDEControl(bool fEnable, uint32_t uFlags)
589{
590 RT_NOREF(fEnable, uFlags);
591 LogFlowThisFunc(("fEnable=%RTbool, uFlags=0x%x\n", fEnable, uFlags));
592
593 if (mpDrv == NULL)
594 return VERR_INVALID_STATE;
595
596 return VINF_SUCCESS; /* Never veto. */
597}
598
599
600/**
601 * Marks the beginning of sending captured audio data from a connected
602 * RDP client.
603 *
604 * @return IPRT status code.
605 * @param pvContext The context; in this case a pointer to a
606 * VRDESTREAMIN structure.
607 * @param pVRDEAudioBegin Pointer to a VRDEAUDIOINBEGIN structure.
608 */
609int AudioVRDE::onVRDEInputBegin(void *pvContext, PVRDEAUDIOINBEGIN pVRDEAudioBegin)
610{
611 AssertPtrReturn(pvContext, VERR_INVALID_POINTER);
612 AssertPtrReturn(pVRDEAudioBegin, VERR_INVALID_POINTER);
613
614 PVRDESTREAM pVRDEStrmIn = (PVRDESTREAM)pvContext;
615 AssertPtrReturn(pVRDEStrmIn, VERR_INVALID_POINTER);
616
617 VRDEAUDIOFORMAT audioFmt = pVRDEAudioBegin->fmt;
618
619 int iSampleHz = VRDE_AUDIO_FMT_SAMPLE_FREQ(audioFmt); RT_NOREF(iSampleHz);
620 int cChannels = VRDE_AUDIO_FMT_CHANNELS(audioFmt); RT_NOREF(cChannels);
621 int cBits = VRDE_AUDIO_FMT_BITS_PER_SAMPLE(audioFmt); RT_NOREF(cBits);
622 bool fUnsigned = VRDE_AUDIO_FMT_SIGNED(audioFmt); RT_NOREF(fUnsigned);
623
624 LogFlowFunc(("cbSample=%RU32, iSampleHz=%d, cChannels=%d, cBits=%d, fUnsigned=%RTbool\n",
625 VRDE_AUDIO_FMT_BYTES_PER_SAMPLE(audioFmt), iSampleHz, cChannels, cBits, fUnsigned));
626
627 return VINF_SUCCESS;
628}
629
630
631int AudioVRDE::onVRDEInputData(void *pvContext, const void *pvData, uint32_t cbData)
632{
633 PVRDESTREAM pStreamVRDE = (PVRDESTREAM)pvContext;
634 AssertPtrReturn(pStreamVRDE, VERR_INVALID_POINTER);
635
636 void *pvBuf;
637 size_t cbBuf;
638
639 RTCircBufAcquireWriteBlock(pStreamVRDE->In.pCircBuf, cbData, &pvBuf, &cbBuf);
640
641 if (cbBuf)
642 memcpy(pvBuf, pvData, cbBuf);
643
644 RTCircBufReleaseWriteBlock(pStreamVRDE->In.pCircBuf, cbBuf);
645
646 if (cbBuf < cbData)
647 LogRel(("VRDE: Capturing audio data lost %zu bytes\n", cbData - cbBuf)); /** @todo Use an error counter. */
648
649 return VINF_SUCCESS; /** @todo r=andy How to tell the caller if we were not able to handle *all* input data? */
650}
651
652
653int AudioVRDE::onVRDEInputEnd(void *pvContext)
654{
655 RT_NOREF(pvContext);
656
657 return VINF_SUCCESS;
658}
659
660
661int AudioVRDE::onVRDEInputIntercept(bool fEnabled)
662{
663 RT_NOREF(fEnabled);
664 return VINF_SUCCESS; /* Never veto. */
665}
666
667
668/**
669 * Construct a VRDE audio driver instance.
670 *
671 * @copydoc FNPDMDRVCONSTRUCT
672 */
673/* static */
674DECLCALLBACK(int) AudioVRDE::drvConstruct(PPDMDRVINS pDrvIns, PCFGMNODE pCfg, uint32_t fFlags)
675{
676 RT_NOREF(fFlags);
677
678 PDMDRV_CHECK_VERSIONS_RETURN(pDrvIns);
679 PDRVAUDIOVRDE pThis = PDMINS_2_DATA(pDrvIns, PDRVAUDIOVRDE);
680
681 AssertPtrReturn(pDrvIns, VERR_INVALID_POINTER);
682 AssertPtrReturn(pCfg, VERR_INVALID_POINTER);
683
684 LogRel(("Audio: Initializing VRDE driver\n"));
685 LogFlowFunc(("fFlags=0x%x\n", fFlags));
686
687 AssertMsgReturn(PDMDrvHlpNoAttach(pDrvIns) == VERR_PDM_NO_ATTACHED_DRIVER,
688 ("Configuration error: Not possible to attach anything to this driver!\n"),
689 VERR_PDM_DRVINS_NO_ATTACH);
690
691 /*
692 * Init the static parts.
693 */
694 pThis->pDrvIns = pDrvIns;
695 /* IBase */
696 pDrvIns->IBase.pfnQueryInterface = drvAudioVRDEQueryInterface;
697 /* IHostAudio */
698 PDMAUDIO_IHOSTAUDIO_CALLBACKS(drvAudioVRDE);
699
700 /*
701 * Get the ConsoleVRDPServer object pointer.
702 */
703 void *pvUser;
704 int rc = CFGMR3QueryPtr(pCfg, "ObjectVRDPServer", &pvUser); /** @todo r=andy Get rid of this hack and use IHostAudio::SetCallback. */
705 AssertMsgRCReturn(rc, ("Confguration error: No/bad \"ObjectVRDPServer\" value, rc=%Rrc\n", rc), rc);
706
707 /* CFGM tree saves the pointer to ConsoleVRDPServer in the Object node of AudioVRDE. */
708 pThis->pConsoleVRDPServer = (ConsoleVRDPServer *)pvUser;
709
710 /*
711 * Get the AudioVRDE object pointer.
712 */
713 pvUser = NULL;
714 rc = CFGMR3QueryPtr(pCfg, "Object", &pvUser); /** @todo r=andy Get rid of this hack and use IHostAudio::SetCallback. */
715 AssertMsgRCReturn(rc, ("Confguration error: No/bad \"Object\" value, rc=%Rrc\n", rc), rc);
716
717 pThis->pAudioVRDE = (AudioVRDE *)pvUser;
718 pThis->pAudioVRDE->mpDrv = pThis;
719
720 /*
721 * Get the interface for the above driver (DrvAudio) to make mixer/conversion calls.
722 * Described in CFGM tree.
723 */
724 pThis->pDrvAudio = PDMIBASE_QUERY_INTERFACE(pDrvIns->pUpBase, PDMIAUDIOCONNECTOR);
725 AssertMsgReturn(pThis->pDrvAudio, ("Configuration error: No upper interface specified!\n"), VERR_PDM_MISSING_INTERFACE_ABOVE);
726
727 return VINF_SUCCESS;
728}
729
730
731/**
732 * @interface_method_impl{PDMDRVREG,pfnDestruct}
733 */
734/* static */
735DECLCALLBACK(void) AudioVRDE::drvDestruct(PPDMDRVINS pDrvIns)
736{
737 PDMDRV_CHECK_VERSIONS_RETURN_VOID(pDrvIns);
738 PDRVAUDIOVRDE pThis = PDMINS_2_DATA(pDrvIns, PDRVAUDIOVRDE);
739 LogFlowFuncEnter();
740
741 /*
742 * If the AudioVRDE object is still alive, we must clear it's reference to
743 * us since we'll be invalid when we return from this method.
744 */
745 if (pThis->pAudioVRDE)
746 {
747 pThis->pAudioVRDE->mpDrv = NULL;
748 pThis->pAudioVRDE = NULL;
749 }
750}
751
752
753/**
754 * VRDE audio driver registration record.
755 */
756const PDMDRVREG AudioVRDE::DrvReg =
757{
758 PDM_DRVREG_VERSION,
759 /* szName */
760 "AudioVRDE",
761 /* szRCMod */
762 "",
763 /* szR0Mod */
764 "",
765 /* pszDescription */
766 "Audio driver for VRDE backend",
767 /* fFlags */
768 PDM_DRVREG_FLAGS_HOST_BITS_DEFAULT,
769 /* fClass. */
770 PDM_DRVREG_CLASS_AUDIO,
771 /* cMaxInstances */
772 ~0U,
773 /* cbInstance */
774 sizeof(DRVAUDIOVRDE),
775 /* pfnConstruct */
776 AudioVRDE::drvConstruct,
777 /* pfnDestruct */
778 AudioVRDE::drvDestruct,
779 /* pfnRelocate */
780 NULL,
781 /* pfnIOCtl */
782 NULL,
783 /* pfnPowerOn */
784 NULL,
785 /* pfnReset */
786 NULL,
787 /* pfnSuspend */
788 NULL,
789 /* pfnResume */
790 NULL,
791 /* pfnAttach */
792 NULL,
793 /* pfnDetach */
794 NULL,
795 /* pfnPowerOff */
796 NULL,
797 /* pfnSoftReset */
798 NULL,
799 /* u32EndVersion */
800 PDM_DRVREG_VERSION
801};
802
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