VirtualBox

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

最後變更 在這個檔案從73471是 73464,由 vboxsync 提交於 7 年 前

Audio/VRDE: Fixed setting the shift parameter of the acquired stream configuration in vrdeCreateStreamIn().

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

© 2025 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette