VirtualBox

source: vbox/trunk/src/VBox/ValidationKit/utils/audio/vkatDriverStack.cpp@ 91824

Last change on this file since 91824 was 91824, checked in by vboxsync, 3 years ago

Audio/Validation Kit: Added fail-safe for audio stacks and/or implementations which mess up draining. ​bugref:10008

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 57.4 KB
Line 
1/* $Id: vkatDriverStack.cpp 91824 2021-10-18 10:42:34Z vboxsync $ */
2/** @file
3 * Validation Kit Audio Test (VKAT) - Driver stack code.
4 */
5
6/*
7 * Copyright (C) 2021 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 * The contents of this file may alternatively be used under the terms
18 * of the Common Development and Distribution License Version 1.0
19 * (CDDL) only, as it comes in the "COPYING.CDDL" file of the
20 * VirtualBox OSE distribution, in which case the provisions of the
21 * CDDL are applicable instead of those of the GPL.
22 *
23 * You may elect to license modified versions of this file under the
24 * terms and conditions of either the GPL or the CDDL or both.
25 */
26
27
28/*********************************************************************************************************************************
29* Header Files *
30*********************************************************************************************************************************/
31#define LOG_GROUP LOG_GROUP_AUDIO_TEST
32#include <iprt/log.h>
33
34#include <iprt/errcore.h>
35#include <iprt/message.h>
36#include <iprt/stream.h>
37#include <iprt/string.h>
38#include <iprt/uuid.h>
39#include <iprt/test.h>
40
41
42/**
43 * Internal driver instance data
44 * @note This must be put here as it's needed before pdmdrv.h is included.
45 */
46typedef struct PDMDRVINSINT
47{
48 /** The stack the drive belongs to. */
49 struct AUDIOTESTDRVSTACK *pStack;
50} PDMDRVINSINT;
51#define PDMDRVINSINT_DECLARED
52
53#include "vkatInternal.h"
54#include "VBoxDD.h"
55
56
57
58/*********************************************************************************************************************************
59* Fake PDM Driver Handling. *
60*********************************************************************************************************************************/
61
62/** @name Driver Fakes/Stubs
63 *
64 * @note The VMM functions defined here will turn into driver helpers before
65 * long, as the drivers aren't supposed to import directly from the VMM in
66 * the future.
67 *
68 * @{ */
69
70VMMR3DECL(PCFGMNODE) CFGMR3GetChild(PCFGMNODE pNode, const char *pszPath)
71{
72 RT_NOREF(pNode, pszPath);
73 return NULL;
74}
75
76
77VMMR3DECL(int) CFGMR3QueryString(PCFGMNODE pNode, const char *pszName, char *pszString, size_t cchString)
78{
79 if (pNode != NULL)
80 {
81 PCPDMDRVREG pDrvReg = (PCPDMDRVREG)pNode;
82 if (g_uVerbosity > 2)
83 RTPrintf("debug: CFGMR3QueryString([%s], %s, %p, %#x)\n", pDrvReg->szName, pszName, pszString, cchString);
84
85 if ( ( strcmp(pDrvReg->szName, "PulseAudio") == 0
86 || strcmp(pDrvReg->szName, "HostAudioWas") == 0)
87 && strcmp(pszName, "VmName") == 0)
88 return RTStrCopy(pszString, cchString, "vkat");
89
90 if ( strcmp(pDrvReg->szName, "HostAudioWas") == 0
91 && strcmp(pszName, "VmUuid") == 0)
92 return RTStrCopy(pszString, cchString, "794c9192-d045-4f28-91ed-46253ac9998e");
93 }
94 else if (g_uVerbosity > 2)
95 RTPrintf("debug: CFGMR3QueryString(%p, %s, %p, %#x)\n", pNode, pszName, pszString, cchString);
96
97 return VERR_CFGM_VALUE_NOT_FOUND;
98}
99
100
101VMMR3DECL(int) CFGMR3QueryStringAlloc(PCFGMNODE pNode, const char *pszName, char **ppszString)
102{
103 char szStr[128];
104 int rc = CFGMR3QueryString(pNode, pszName, szStr, sizeof(szStr));
105 if (RT_SUCCESS(rc))
106 *ppszString = RTStrDup(szStr);
107
108 return rc;
109}
110
111
112VMMR3DECL(void) MMR3HeapFree(void *pv)
113{
114 /* counterpart to CFGMR3QueryStringAlloc */
115 RTStrFree((char *)pv);
116}
117
118
119VMMR3DECL(int) CFGMR3QueryStringDef(PCFGMNODE pNode, const char *pszName, char *pszString, size_t cchString, const char *pszDef)
120{
121 PCPDMDRVREG pDrvReg = (PCPDMDRVREG)pNode;
122 if (RT_VALID_PTR(pDrvReg))
123 {
124 const char *pszRet = pszDef;
125 if ( g_pszDrvAudioDebug
126 && strcmp(pDrvReg->szName, "AUDIO") == 0
127 && strcmp(pszName, "DebugPathOut") == 0)
128 pszRet = g_pszDrvAudioDebug;
129
130 int rc = RTStrCopy(pszString, cchString, pszRet);
131
132 if (g_uVerbosity > 2)
133 RTPrintf("debug: CFGMR3QueryStringDef([%s], %s, %p, %#x, %s) -> '%s' + %Rrc\n",
134 pDrvReg->szName, pszName, pszString, cchString, pszDef, pszRet, rc);
135 return rc;
136 }
137
138 if (g_uVerbosity > 2)
139 RTPrintf("debug: CFGMR3QueryStringDef(%p, %s, %p, %#x, %s)\n", pNode, pszName, pszString, cchString, pszDef);
140 return RTStrCopy(pszString, cchString, pszDef);
141}
142
143
144VMMR3DECL(int) CFGMR3QueryBoolDef(PCFGMNODE pNode, const char *pszName, bool *pf, bool fDef)
145{
146 PCPDMDRVREG pDrvReg = (PCPDMDRVREG)pNode;
147 if (RT_VALID_PTR(pDrvReg))
148 {
149 *pf = fDef;
150 if ( strcmp(pDrvReg->szName, "AUDIO") == 0
151 && strcmp(pszName, "DebugEnabled") == 0)
152 *pf = g_fDrvAudioDebug;
153
154 if (g_uVerbosity > 2)
155 RTPrintf("debug: CFGMR3QueryBoolDef([%s], %s, %p, %RTbool) -> %RTbool\n", pDrvReg->szName, pszName, pf, fDef, *pf);
156 return VINF_SUCCESS;
157 }
158 *pf = fDef;
159 return VINF_SUCCESS;
160}
161
162
163VMMR3DECL(int) CFGMR3QueryU8(PCFGMNODE pNode, const char *pszName, uint8_t *pu8)
164{
165 RT_NOREF(pNode, pszName, pu8);
166 return VERR_CFGM_VALUE_NOT_FOUND;
167}
168
169
170VMMR3DECL(int) CFGMR3QueryU32(PCFGMNODE pNode, const char *pszName, uint32_t *pu32)
171{
172 RT_NOREF(pNode, pszName, pu32);
173 return VERR_CFGM_VALUE_NOT_FOUND;
174}
175
176
177VMMR3DECL(int) CFGMR3ValidateConfig(PCFGMNODE pNode, const char *pszNode,
178 const char *pszValidValues, const char *pszValidNodes,
179 const char *pszWho, uint32_t uInstance)
180{
181 RT_NOREF(pNode, pszNode, pszValidValues, pszValidNodes, pszWho, uInstance);
182 return VINF_SUCCESS;
183}
184
185/** @} */
186
187/** @name Driver Helper Fakes
188 * @{ */
189
190static DECLCALLBACK(int) audioTestDrvHlp_Attach(PPDMDRVINS pDrvIns, uint32_t fFlags, PPDMIBASE *ppBaseInterface)
191{
192 /* DrvAudio must be allowed to attach the backend driver (paranoid
193 backend drivers may call us to check that nothing is attached). */
194 if (strcmp(pDrvIns->pReg->szName, "AUDIO") == 0)
195 {
196 PAUDIOTESTDRVSTACK pDrvStack = pDrvIns->Internal.s.pStack;
197 AssertReturn(pDrvStack->pDrvBackendIns == NULL, VERR_PDM_DRIVER_ALREADY_ATTACHED);
198
199 if (g_uVerbosity > 1)
200 RTMsgInfo("Attaching backend '%s' to DrvAudio...\n", pDrvStack->pDrvReg->szName);
201 int rc = audioTestDrvConstruct(pDrvStack, pDrvStack->pDrvReg, pDrvIns, &pDrvStack->pDrvBackendIns);
202 if (RT_SUCCESS(rc))
203 {
204 if (ppBaseInterface)
205 *ppBaseInterface = &pDrvStack->pDrvBackendIns->IBase;
206 }
207 else
208 RTMsgError("Failed to attach backend: %Rrc", rc);
209 return rc;
210 }
211 RT_NOREF(fFlags);
212 return VERR_PDM_NO_ATTACHED_DRIVER;
213}
214
215
216static DECLCALLBACK(void) audioTestDrvHlp_STAMRegister(PPDMDRVINS pDrvIns, void *pvSample, STAMTYPE enmType, const char *pszName,
217 STAMUNIT enmUnit, const char *pszDesc)
218{
219 RT_NOREF(pDrvIns, pvSample, enmType, pszName, enmUnit, pszDesc);
220}
221
222
223static DECLCALLBACK(void) audioTestDrvHlp_STAMRegisterF(PPDMDRVINS pDrvIns, void *pvSample, STAMTYPE enmType,
224 STAMVISIBILITY enmVisibility, STAMUNIT enmUnit, const char *pszDesc,
225 const char *pszName, ...)
226{
227 RT_NOREF(pDrvIns, pvSample, enmType, enmVisibility, enmUnit, pszDesc, pszName);
228}
229
230
231static DECLCALLBACK(void) audioTestDrvHlp_STAMRegisterV(PPDMDRVINS pDrvIns, void *pvSample, STAMTYPE enmType,
232 STAMVISIBILITY enmVisibility, STAMUNIT enmUnit, const char *pszDesc,
233 const char *pszName, va_list args)
234{
235 RT_NOREF(pDrvIns, pvSample, enmType, enmVisibility, enmUnit, pszDesc, pszName, args);
236}
237
238
239static DECLCALLBACK(int) audioTestDrvHlp_STAMDeregister(PPDMDRVINS pDrvIns, void *pvSample)
240{
241 RT_NOREF(pDrvIns, pvSample);
242 return VINF_SUCCESS;
243}
244
245
246static DECLCALLBACK(int) audioTestDrvHlp_STAMDeregisterByPrefix(PPDMDRVINS pDrvIns, const char *pszPrefix)
247{
248 RT_NOREF(pDrvIns, pszPrefix);
249 return VINF_SUCCESS;
250}
251
252/**
253 * Get the driver helpers.
254 */
255static const PDMDRVHLPR3 *audioTestFakeGetDrvHlp(void)
256{
257 /*
258 * Note! No initializer for s_DrvHlp (also why it's not a file global).
259 * We do not want to have to update this code every time PDMDRVHLPR3
260 * grows new entries or are otherwise modified. Only when the
261 * entries used by the audio driver changes do we want to change
262 * our code.
263 */
264 static PDMDRVHLPR3 s_DrvHlp;
265 if (s_DrvHlp.u32Version != PDM_DRVHLPR3_VERSION)
266 {
267 s_DrvHlp.u32Version = PDM_DRVHLPR3_VERSION;
268 s_DrvHlp.u32TheEnd = PDM_DRVHLPR3_VERSION;
269 s_DrvHlp.pfnAttach = audioTestDrvHlp_Attach;
270 s_DrvHlp.pfnSTAMRegister = audioTestDrvHlp_STAMRegister;
271 s_DrvHlp.pfnSTAMRegisterF = audioTestDrvHlp_STAMRegisterF;
272 s_DrvHlp.pfnSTAMRegisterV = audioTestDrvHlp_STAMRegisterV;
273 s_DrvHlp.pfnSTAMDeregister = audioTestDrvHlp_STAMDeregister;
274 s_DrvHlp.pfnSTAMDeregisterByPrefix = audioTestDrvHlp_STAMDeregisterByPrefix;
275 }
276 return &s_DrvHlp;
277}
278
279/** @} */
280
281
282/**
283 * Implementation of PDMIBASE::pfnQueryInterface for a fake device above
284 * DrvAudio.
285 */
286static DECLCALLBACK(void *) audioTestFakeDeviceIBaseQueryInterface(PPDMIBASE pInterface, const char *pszIID)
287{
288 PDMIBASE_RETURN_INTERFACE(pszIID, PDMIBASE, pInterface);
289 RTMsgWarning("audioTestFakeDeviceIBaseQueryInterface: Unknown interface: %s\n", pszIID);
290 return NULL;
291}
292
293/** IBase interface for a fake device above DrvAudio. */
294static PDMIBASE g_AudioTestFakeDeviceIBase = { audioTestFakeDeviceIBaseQueryInterface };
295
296
297static DECLCALLBACK(int) audioTestIHostAudioPort_DoOnWorkerThread(PPDMIHOSTAUDIOPORT pInterface, PPDMAUDIOBACKENDSTREAM pStream,
298 uintptr_t uUser, void *pvUser)
299{
300 RT_NOREF(pInterface, pStream, uUser, pvUser);
301 RTMsgWarning("audioTestIHostAudioPort_DoOnWorkerThread was called\n");
302 return VERR_NOT_IMPLEMENTED;
303}
304
305
306DECLCALLBACK(void) audioTestIHostAudioPort_NotifyDeviceChanged(PPDMIHOSTAUDIOPORT pInterface, PDMAUDIODIR enmDir, void *pvUser)
307{
308 RT_NOREF(pInterface, enmDir, pvUser);
309 RTMsgWarning("audioTestIHostAudioPort_NotifyDeviceChanged was called\n");
310}
311
312
313static DECLCALLBACK(void) audioTestIHostAudioPort_StreamNotifyPreparingDeviceSwitch(PPDMIHOSTAUDIOPORT pInterface,
314 PPDMAUDIOBACKENDSTREAM pStream)
315{
316 RT_NOREF(pInterface, pStream);
317 RTMsgWarning("audioTestIHostAudioPort_StreamNotifyPreparingDeviceSwitch was called\n");
318}
319
320
321static DECLCALLBACK(void) audioTestIHostAudioPort_StreamNotifyDeviceChanged(PPDMIHOSTAUDIOPORT pInterface,
322 PPDMAUDIOBACKENDSTREAM pStream, bool fReInit)
323{
324 RT_NOREF(pInterface, pStream, fReInit);
325 RTMsgWarning("audioTestIHostAudioPort_StreamNotifyDeviceChanged was called\n");
326}
327
328
329static DECLCALLBACK(void) audioTestIHostAudioPort_NotifyDevicesChanged(PPDMIHOSTAUDIOPORT pInterface)
330{
331 RT_NOREF(pInterface);
332 RTMsgWarning("audioTestIHostAudioPort_NotifyDevicesChanged was called\n");
333}
334
335
336static PDMIHOSTAUDIOPORT g_AudioTestIHostAudioPort =
337{
338 audioTestIHostAudioPort_DoOnWorkerThread,
339 audioTestIHostAudioPort_NotifyDeviceChanged,
340 audioTestIHostAudioPort_StreamNotifyPreparingDeviceSwitch,
341 audioTestIHostAudioPort_StreamNotifyDeviceChanged,
342 audioTestIHostAudioPort_NotifyDevicesChanged,
343};
344
345
346/**
347 * Implementation of PDMIBASE::pfnQueryInterface for a fake DrvAudio above a
348 * backend.
349 */
350static DECLCALLBACK(void *) audioTestFakeDrvAudioIBaseQueryInterface(PPDMIBASE pInterface, const char *pszIID)
351{
352 PDMIBASE_RETURN_INTERFACE(pszIID, PDMIBASE, pInterface);
353 PDMIBASE_RETURN_INTERFACE(pszIID, PDMIHOSTAUDIOPORT, &g_AudioTestIHostAudioPort);
354 RTMsgWarning("audioTestFakeDrvAudioIBaseQueryInterface: Unknown interface: %s\n", pszIID);
355 return NULL;
356}
357
358
359/** IBase interface for a fake DrvAudio above a lonesome backend. */
360static PDMIBASE g_AudioTestFakeDrvAudioIBase = { audioTestFakeDrvAudioIBaseQueryInterface };
361
362
363
364/**
365 * Constructs a PDM audio driver instance.
366 *
367 * @returns VBox status code.
368 * @param pDrvStack The stack this is associated with.
369 * @param pDrvReg PDM driver registration record to use for construction.
370 * @param pParentDrvIns The parent driver (if any).
371 * @param ppDrvIns Where to return the driver instance structure.
372 */
373int audioTestDrvConstruct(PAUDIOTESTDRVSTACK pDrvStack, PCPDMDRVREG pDrvReg, PPDMDRVINS pParentDrvIns,
374 PPPDMDRVINS ppDrvIns)
375{
376 /* The destruct function must have valid data to work with. */
377 *ppDrvIns = NULL;
378
379 /*
380 * Check registration structure validation (doesn't need to be too
381 * thorough, PDM check it in detail on every VM startup).
382 */
383 AssertPtrReturn(pDrvReg, VERR_INVALID_POINTER);
384 RTMsgInfo("Initializing backend '%s' ...\n", pDrvReg->szName);
385 AssertPtrReturn(pDrvReg->pfnConstruct, VERR_INVALID_PARAMETER);
386
387 /*
388 * Create the instance data structure.
389 */
390 PPDMDRVINS pDrvIns = (PPDMDRVINS)RTMemAllocZVar(RT_UOFFSETOF_DYN(PDMDRVINS, achInstanceData[pDrvReg->cbInstance]));
391 RTTEST_CHECK_RET(g_hTest, pDrvIns, VERR_NO_MEMORY);
392
393 pDrvIns->u32Version = PDM_DRVINS_VERSION;
394 pDrvIns->iInstance = 0;
395 pDrvIns->pHlpR3 = audioTestFakeGetDrvHlp();
396 pDrvIns->pvInstanceDataR3 = &pDrvIns->achInstanceData[0];
397 pDrvIns->pReg = pDrvReg;
398 pDrvIns->pCfg = (PCFGMNODE)pDrvReg;
399 pDrvIns->Internal.s.pStack = pDrvStack;
400 pDrvIns->pUpBase = NULL;
401 pDrvIns->pDownBase = NULL;
402 if (pParentDrvIns)
403 {
404 Assert(pParentDrvIns->pDownBase == NULL);
405 pParentDrvIns->pDownBase = &pDrvIns->IBase;
406 pDrvIns->pUpBase = &pParentDrvIns->IBase;
407 }
408 else if (strcmp(pDrvReg->szName, "AUDIO") == 0)
409 pDrvIns->pUpBase = &g_AudioTestFakeDeviceIBase;
410 else
411 pDrvIns->pUpBase = &g_AudioTestFakeDrvAudioIBase;
412
413 /*
414 * Invoke the constructor.
415 */
416 int rc = pDrvReg->pfnConstruct(pDrvIns, pDrvIns->pCfg, 0 /*fFlags*/);
417 if (RT_SUCCESS(rc))
418 {
419 *ppDrvIns = pDrvIns;
420 return VINF_SUCCESS;
421 }
422
423 if (pDrvReg->pfnDestruct)
424 pDrvReg->pfnDestruct(pDrvIns);
425 RTMemFree(pDrvIns);
426 return rc;
427}
428
429
430/**
431 * Destructs a PDM audio driver instance.
432 *
433 * @param pDrvIns Driver instance to destruct.
434 */
435static void audioTestDrvDestruct(PPDMDRVINS pDrvIns)
436{
437 if (pDrvIns)
438 {
439 Assert(pDrvIns->u32Version == PDM_DRVINS_VERSION);
440
441 if (pDrvIns->pReg->pfnDestruct)
442 pDrvIns->pReg->pfnDestruct(pDrvIns);
443
444 pDrvIns->u32Version = 0;
445 pDrvIns->pReg = NULL;
446 RTMemFree(pDrvIns);
447 }
448}
449
450
451/**
452 * Sends the PDM driver a power off notification.
453 *
454 * @param pDrvIns Driver instance to notify.
455 */
456static void audioTestDrvNotifyPowerOff(PPDMDRVINS pDrvIns)
457{
458 if (pDrvIns)
459 {
460 Assert(pDrvIns->u32Version == PDM_DRVINS_VERSION);
461 if (pDrvIns->pReg->pfnPowerOff)
462 pDrvIns->pReg->pfnPowerOff(pDrvIns);
463 }
464}
465
466
467/**
468 * Deletes a driver stack.
469 *
470 * This will power off and destroy the drivers.
471 */
472void audioTestDriverStackDelete(PAUDIOTESTDRVSTACK pDrvStack)
473{
474 /*
475 * Do power off notifications (top to bottom).
476 */
477 audioTestDrvNotifyPowerOff(pDrvStack->pDrvAudioIns);
478 audioTestDrvNotifyPowerOff(pDrvStack->pDrvBackendIns);
479
480 /*
481 * Drivers are destroyed from bottom to top (closest to the device).
482 */
483 audioTestDrvDestruct(pDrvStack->pDrvBackendIns);
484 pDrvStack->pDrvBackendIns = NULL;
485 pDrvStack->pIHostAudio = NULL;
486
487 audioTestDrvDestruct(pDrvStack->pDrvAudioIns);
488 pDrvStack->pDrvAudioIns = NULL;
489 pDrvStack->pIAudioConnector = NULL;
490
491 PDMAudioHostEnumDelete(&pDrvStack->DevEnum);
492}
493
494
495/**
496 * Initializes a driver stack, extended version.
497 *
498 * @returns VBox status code.
499 * @param pDrvStack The driver stack to initialize.
500 * @param pDrvReg The backend driver to use.
501 * @param fEnabledIn Whether input is enabled or not on creation time.
502 * @param fEnabledOut Whether output is enabled or not on creation time.
503 * @param fWithDrvAudio Whether to include DrvAudio in the stack or not.
504 */
505int audioTestDriverStackInitEx(PAUDIOTESTDRVSTACK pDrvStack, PCPDMDRVREG pDrvReg, bool fEnabledIn, bool fEnabledOut, bool fWithDrvAudio)
506{
507 int rc;
508
509 RT_ZERO(*pDrvStack);
510 pDrvStack->pDrvReg = pDrvReg;
511
512 PDMAudioHostEnumInit(&pDrvStack->DevEnum);
513
514 if (!fWithDrvAudio)
515 rc = audioTestDrvConstruct(pDrvStack, pDrvReg, NULL /*pParentDrvIns*/, &pDrvStack->pDrvBackendIns);
516 else
517 {
518 rc = audioTestDrvConstruct(pDrvStack, &g_DrvAUDIO, NULL /*pParentDrvIns*/, &pDrvStack->pDrvAudioIns);
519 if (RT_SUCCESS(rc))
520 {
521 Assert(pDrvStack->pDrvAudioIns);
522 PPDMIBASE const pIBase = &pDrvStack->pDrvAudioIns->IBase;
523 pDrvStack->pIAudioConnector = (PPDMIAUDIOCONNECTOR)pIBase->pfnQueryInterface(pIBase, PDMIAUDIOCONNECTOR_IID);
524 if (pDrvStack->pIAudioConnector)
525 {
526 /* Both input and output is disabled by default. */
527 if (fEnabledIn)
528 rc = pDrvStack->pIAudioConnector->pfnEnable(pDrvStack->pIAudioConnector, PDMAUDIODIR_IN, true);
529
530 if (RT_SUCCESS(rc))
531 {
532 if (fEnabledOut)
533 rc = pDrvStack->pIAudioConnector->pfnEnable(pDrvStack->pIAudioConnector, PDMAUDIODIR_OUT, true);
534 }
535
536 if (RT_FAILURE(rc))
537 {
538 RTTestFailed(g_hTest, "Failed to enabled input and output: %Rrc", rc);
539 audioTestDriverStackDelete(pDrvStack);
540 }
541 }
542 else
543 {
544 RTTestFailed(g_hTest, "Failed to query PDMIAUDIOCONNECTOR");
545 audioTestDriverStackDelete(pDrvStack);
546 rc = VERR_PDM_MISSING_INTERFACE;
547 }
548 }
549 }
550
551 /*
552 * Get the IHostAudio interface and check that the host driver is working.
553 */
554 if (RT_SUCCESS(rc))
555 {
556 PPDMIBASE const pIBase = &pDrvStack->pDrvBackendIns->IBase;
557 pDrvStack->pIHostAudio = (PPDMIHOSTAUDIO)pIBase->pfnQueryInterface(pIBase, PDMIHOSTAUDIO_IID);
558 if (pDrvStack->pIHostAudio)
559 {
560 PDMAUDIOBACKENDSTS enmStatus = pDrvStack->pIHostAudio->pfnGetStatus(pDrvStack->pIHostAudio, PDMAUDIODIR_OUT);
561 if (enmStatus == PDMAUDIOBACKENDSTS_RUNNING)
562 return VINF_SUCCESS;
563
564 RTTestFailed(g_hTest, "Expected backend status RUNNING, got %d instead", enmStatus);
565 }
566 else
567 RTTestFailed(g_hTest, "Failed to query PDMIHOSTAUDIO for '%s'", pDrvReg->szName);
568 audioTestDriverStackDelete(pDrvStack);
569 }
570
571 return rc;
572}
573
574
575/**
576 * Initializes a driver stack.
577 *
578 * @returns VBox status code.
579 * @param pDrvStack The driver stack to initialize.
580 * @param pDrvReg The backend driver to use.
581 * @param fEnabledIn Whether input is enabled or not on creation time.
582 * @param fEnabledOut Whether output is enabled or not on creation time.
583 * @param fWithDrvAudio Whether to include DrvAudio in the stack or not.
584 */
585int audioTestDriverStackInit(PAUDIOTESTDRVSTACK pDrvStack, PCPDMDRVREG pDrvReg, bool fWithDrvAudio)
586{
587 return audioTestDriverStackInitEx(pDrvStack, pDrvReg, true /* fEnabledIn */, true /* fEnabledOut */, fWithDrvAudio);
588}
589
590/**
591 * Initializes a driver stack by probing all backends in the order of appearance
592 * in the backends description table.
593 *
594 * @returns VBox status code.
595 * @param pDrvStack The driver stack to initialize.
596 * @param pDrvReg The backend driver to use.
597 * @param fEnabledIn Whether input is enabled or not on creation time.
598 * @param fEnabledOut Whether output is enabled or not on creation time.
599 * @param fWithDrvAudio Whether to include DrvAudio in the stack or not.
600 */
601int audioTestDriverStackProbe(PAUDIOTESTDRVSTACK pDrvStack, PCPDMDRVREG pDrvReg, bool fEnabledIn, bool fEnabledOut, bool fWithDrvAudio)
602{
603 int rc = VERR_IPE_UNINITIALIZED_STATUS; /* Shut up MSVC. */
604
605 for (size_t i = 0; i < g_cBackends; i++)
606 {
607 pDrvReg = g_aBackends[i].pDrvReg;
608 RTTestPrintf(g_hTest, RTTESTLVL_ALWAYS, "Probing for backend '%s' ...\n", g_aBackends[i].pszName);
609
610 rc = audioTestDriverStackInitEx(pDrvStack, pDrvReg, fEnabledIn, fEnabledOut, fWithDrvAudio); /** @todo Make in/out configurable, too. */
611 if (RT_SUCCESS(rc))
612 {
613 RTTestPrintf(g_hTest, RTTESTLVL_ALWAYS, "Probing backend '%s' successful\n", g_aBackends[i].pszName);
614 return rc;
615 }
616
617 RTTestPrintf(g_hTest, RTTESTLVL_ALWAYS, "Probing backend '%s' failed with %Rrc, trying next one\n",
618 g_aBackends[i].pszName, rc);
619 continue;
620 }
621
622 RTTestPrintf(g_hTest, RTTESTLVL_ALWAYS, "Probing all backends failed\n");
623 return rc;
624}
625
626/**
627 * Wrapper around PDMIHOSTAUDIO::pfnSetDevice.
628 */
629int audioTestDriverStackSetDevice(PAUDIOTESTDRVSTACK pDrvStack, PDMAUDIODIR enmDir, const char *pszDevId)
630{
631 int rc;
632 if ( pDrvStack->pIHostAudio
633 && pDrvStack->pIHostAudio->pfnSetDevice)
634 rc = pDrvStack->pIHostAudio->pfnSetDevice(pDrvStack->pIHostAudio, enmDir, pszDevId);
635 else if (!pszDevId || *pszDevId)
636 rc = VINF_SUCCESS;
637 else
638 rc = VERR_INVALID_FUNCTION;
639 return rc;
640}
641
642
643/**
644 * Common stream creation code.
645 *
646 * @returns VBox status code.
647 * @param pDrvStack The audio driver stack to create it via.
648 * @param pCfgReq The requested config.
649 * @param ppStream Where to return the stream pointer on success.
650 * @param pCfgAcq Where to return the actual (well, not necessarily when
651 * using DrvAudio, but probably the same) stream config on
652 * success (not used as input).
653 */
654static int audioTestDriverStackStreamCreate(PAUDIOTESTDRVSTACK pDrvStack, PCPDMAUDIOSTREAMCFG pCfgReq,
655 PPDMAUDIOSTREAM *ppStream, PPDMAUDIOSTREAMCFG pCfgAcq)
656{
657 char szTmp[PDMAUDIOSTRMCFGTOSTRING_MAX + 16];
658 int rc;
659 *ppStream = NULL;
660
661 if (pDrvStack->pIAudioConnector)
662 {
663 /*
664 * DrvAudio does most of the work here.
665 */
666 rc = pDrvStack->pIAudioConnector->pfnStreamCreate(pDrvStack->pIAudioConnector, 0 /*fFlags*/, pCfgReq, ppStream);
667 if (RT_SUCCESS(rc))
668 {
669 *pCfgAcq = (*ppStream)->Cfg;
670 RTMsgInfo("Created backend stream: %s\n", PDMAudioStrmCfgToString(pCfgReq, szTmp, sizeof(szTmp)));
671 return rc;
672 }
673 RTTestFailed(g_hTest, "pfnStreamCreate failed: %Rrc", rc);
674 }
675 else
676 {
677 /*
678 * Get the config so we can see how big the PDMAUDIOBACKENDSTREAM
679 * structure actually is for this backend.
680 */
681 PDMAUDIOBACKENDCFG BackendCfg;
682 rc = pDrvStack->pIHostAudio->pfnGetConfig(pDrvStack->pIHostAudio, &BackendCfg);
683 if (RT_SUCCESS(rc))
684 {
685 if (BackendCfg.cbStream >= sizeof(PDMAUDIOBACKENDSTREAM))
686 {
687 /*
688 * Allocate and initialize the stream.
689 */
690 uint32_t const cbStream = sizeof(AUDIOTESTDRVSTACKSTREAM) - sizeof(PDMAUDIOBACKENDSTREAM) + BackendCfg.cbStream;
691 PAUDIOTESTDRVSTACKSTREAM pStreamAt = (PAUDIOTESTDRVSTACKSTREAM)RTMemAllocZVar(cbStream);
692 if (pStreamAt)
693 {
694 pStreamAt->Core.uMagic = PDMAUDIOSTREAM_MAGIC;
695 pStreamAt->Core.Cfg = *pCfgReq;
696 pStreamAt->Core.cbBackend = cbStream;
697
698 pStreamAt->Backend.uMagic = PDMAUDIOBACKENDSTREAM_MAGIC;
699 pStreamAt->Backend.pStream = &pStreamAt->Core;
700
701 /*
702 * Call the backend to create the stream.
703 */
704 rc = pDrvStack->pIHostAudio->pfnStreamCreate(pDrvStack->pIHostAudio, &pStreamAt->Backend,
705 pCfgReq, &pStreamAt->Core.Cfg);
706 if (RT_SUCCESS(rc))
707 {
708 if (g_uVerbosity > 1)
709 RTMsgInfo("Created backend stream: %s\n",
710 PDMAudioStrmCfgToString(&pStreamAt->Core.Cfg, szTmp, sizeof(szTmp)));
711
712 /* Return if stream is ready: */
713 if (rc == VINF_SUCCESS)
714 {
715 *ppStream = &pStreamAt->Core;
716 *pCfgAcq = pStreamAt->Core.Cfg;
717 return VINF_SUCCESS;
718 }
719 if (rc == VINF_AUDIO_STREAM_ASYNC_INIT_NEEDED)
720 {
721 /*
722 * Do async init right here and now.
723 */
724 rc = pDrvStack->pIHostAudio->pfnStreamInitAsync(pDrvStack->pIHostAudio, &pStreamAt->Backend,
725 false /*fDestroyed*/);
726 if (RT_SUCCESS(rc))
727 {
728 *ppStream = &pStreamAt->Core;
729 *pCfgAcq = pStreamAt->Core.Cfg;
730 return VINF_SUCCESS;
731 }
732
733 RTTestFailed(g_hTest, "pfnStreamInitAsync failed: %Rrc\n", rc);
734 }
735 else
736 {
737 RTTestFailed(g_hTest, "pfnStreamCreate returned unexpected info status: %Rrc", rc);
738 rc = VERR_IPE_UNEXPECTED_INFO_STATUS;
739 }
740 pDrvStack->pIHostAudio->pfnStreamDestroy(pDrvStack->pIHostAudio, &pStreamAt->Backend, true /*fImmediate*/);
741 }
742 else
743 RTTestFailed(g_hTest, "pfnStreamCreate failed: %Rrc\n", rc);
744 }
745 else
746 {
747 RTTestFailed(g_hTest, "Out of memory!\n");
748 rc = VERR_NO_MEMORY;
749 }
750 RTMemFree(pStreamAt);
751 }
752 else
753 {
754 RTTestFailed(g_hTest, "cbStream=%#x is too small, min %#zx!\n", BackendCfg.cbStream, sizeof(PDMAUDIOBACKENDSTREAM));
755 rc = VERR_OUT_OF_RANGE;
756 }
757 }
758 else
759 RTTestFailed(g_hTest, "pfnGetConfig failed: %Rrc\n", rc);
760 }
761 return rc;
762}
763
764
765/**
766 * Creates an output stream.
767 *
768 * @returns VBox status code.
769 * @param pDrvStack The audio driver stack to create it via.
770 * @param pProps The audio properties to use.
771 * @param cMsBufferSize The buffer size in milliseconds.
772 * @param cMsPreBuffer The pre-buffering amount in milliseconds.
773 * @param cMsSchedulingHint The scheduling hint in milliseconds.
774 * @param ppStream Where to return the stream pointer on success.
775 * @param pCfgAcq Where to return the actual (well, not
776 * necessarily when using DrvAudio, but probably
777 * the same) stream config on success (not used as
778 * input).
779 */
780int audioTestDriverStackStreamCreateOutput(PAUDIOTESTDRVSTACK pDrvStack, PCPDMAUDIOPCMPROPS pProps,
781 uint32_t cMsBufferSize, uint32_t cMsPreBuffer, uint32_t cMsSchedulingHint,
782 PPDMAUDIOSTREAM *ppStream, PPDMAUDIOSTREAMCFG pCfgAcq)
783{
784 /*
785 * Calculate the stream config.
786 */
787 PDMAUDIOSTREAMCFG CfgReq;
788 int rc = PDMAudioStrmCfgInitWithProps(&CfgReq, pProps);
789 AssertRC(rc);
790 CfgReq.enmDir = PDMAUDIODIR_OUT;
791 CfgReq.enmPath = PDMAUDIOPATH_OUT_FRONT;
792 CfgReq.Device.cMsSchedulingHint = cMsSchedulingHint == UINT32_MAX || cMsSchedulingHint == 0
793 ? 10 : cMsSchedulingHint;
794 if (pDrvStack->pIAudioConnector && (cMsBufferSize == UINT32_MAX || cMsBufferSize == 0))
795 CfgReq.Backend.cFramesBufferSize = 0; /* DrvAudio picks the default */
796 else
797 CfgReq.Backend.cFramesBufferSize = PDMAudioPropsMilliToFrames(pProps,
798 cMsBufferSize == UINT32_MAX || cMsBufferSize == 0
799 ? 300 : cMsBufferSize);
800 if (cMsPreBuffer == UINT32_MAX)
801 CfgReq.Backend.cFramesPreBuffering = pDrvStack->pIAudioConnector ? UINT32_MAX /*DrvAudo picks the default */
802 : CfgReq.Backend.cFramesBufferSize * 2 / 3;
803 else
804 CfgReq.Backend.cFramesPreBuffering = PDMAudioPropsMilliToFrames(pProps, cMsPreBuffer);
805 if ( CfgReq.Backend.cFramesPreBuffering >= CfgReq.Backend.cFramesBufferSize + 16
806 && !pDrvStack->pIAudioConnector /*DrvAudio deals with it*/ )
807 {
808 RTMsgWarning("Cannot pre-buffer %#x frames with only %#x frames of buffer!",
809 CfgReq.Backend.cFramesPreBuffering, CfgReq.Backend.cFramesBufferSize);
810 CfgReq.Backend.cFramesPreBuffering = CfgReq.Backend.cFramesBufferSize > 16
811 ? CfgReq.Backend.cFramesBufferSize - 16 : 0;
812 }
813
814 static uint32_t s_idxStream = 0;
815 uint32_t const idxStream = s_idxStream++;
816 RTStrPrintf(CfgReq.szName, sizeof(CfgReq.szName), "out-%u", idxStream);
817
818 /*
819 * Call common code to do the actual work.
820 */
821 return audioTestDriverStackStreamCreate(pDrvStack, &CfgReq, ppStream, pCfgAcq);
822}
823
824
825/**
826 * Creates an input stream.
827 *
828 * @returns VBox status code.
829 * @param pDrvStack The audio driver stack to create it via.
830 * @param pProps The audio properties to use.
831 * @param cMsBufferSize The buffer size in milliseconds.
832 * @param cMsPreBuffer The pre-buffering amount in milliseconds.
833 * @param cMsSchedulingHint The scheduling hint in milliseconds.
834 * @param ppStream Where to return the stream pointer on success.
835 * @param pCfgAcq Where to return the actual (well, not
836 * necessarily when using DrvAudio, but probably
837 * the same) stream config on success (not used as
838 * input).
839 */
840int audioTestDriverStackStreamCreateInput(PAUDIOTESTDRVSTACK pDrvStack, PCPDMAUDIOPCMPROPS pProps,
841 uint32_t cMsBufferSize, uint32_t cMsPreBuffer, uint32_t cMsSchedulingHint,
842 PPDMAUDIOSTREAM *ppStream, PPDMAUDIOSTREAMCFG pCfgAcq)
843{
844 /*
845 * Calculate the stream config.
846 */
847 PDMAUDIOSTREAMCFG CfgReq;
848 int rc = PDMAudioStrmCfgInitWithProps(&CfgReq, pProps);
849 AssertRC(rc);
850 CfgReq.enmDir = PDMAUDIODIR_IN;
851 CfgReq.enmPath = PDMAUDIOPATH_IN_LINE;
852 CfgReq.Device.cMsSchedulingHint = cMsSchedulingHint == UINT32_MAX || cMsSchedulingHint == 0
853 ? 10 : cMsSchedulingHint;
854 if (pDrvStack->pIAudioConnector && (cMsBufferSize == UINT32_MAX || cMsBufferSize == 0))
855 CfgReq.Backend.cFramesBufferSize = 0; /* DrvAudio picks the default */
856 else
857 CfgReq.Backend.cFramesBufferSize = PDMAudioPropsMilliToFrames(pProps,
858 cMsBufferSize == UINT32_MAX || cMsBufferSize == 0
859 ? 300 : cMsBufferSize);
860 if (cMsPreBuffer == UINT32_MAX)
861 CfgReq.Backend.cFramesPreBuffering = pDrvStack->pIAudioConnector ? UINT32_MAX /*DrvAudio picks the default */
862 : CfgReq.Backend.cFramesBufferSize / 2;
863 else
864 CfgReq.Backend.cFramesPreBuffering = PDMAudioPropsMilliToFrames(pProps, cMsPreBuffer);
865 if ( CfgReq.Backend.cFramesPreBuffering >= CfgReq.Backend.cFramesBufferSize + 16 /** @todo way to little */
866 && !pDrvStack->pIAudioConnector /*DrvAudio deals with it*/ )
867 {
868 RTMsgWarning("Cannot pre-buffer %#x frames with only %#x frames of buffer!",
869 CfgReq.Backend.cFramesPreBuffering, CfgReq.Backend.cFramesBufferSize);
870 CfgReq.Backend.cFramesPreBuffering = CfgReq.Backend.cFramesBufferSize > 16
871 ? CfgReq.Backend.cFramesBufferSize - 16 : 0;
872 }
873
874 static uint32_t s_idxStream = 0;
875 uint32_t const idxStream = s_idxStream++;
876 RTStrPrintf(CfgReq.szName, sizeof(CfgReq.szName), "in-%u", idxStream);
877
878 /*
879 * Call common code to do the actual work.
880 */
881 return audioTestDriverStackStreamCreate(pDrvStack, &CfgReq, ppStream, pCfgAcq);
882}
883
884
885/**
886 * Destroys a stream.
887 */
888void audioTestDriverStackStreamDestroy(PAUDIOTESTDRVSTACK pDrvStack, PPDMAUDIOSTREAM pStream)
889{
890 if (pStream)
891 {
892 if (pDrvStack->pIAudioConnector)
893 {
894 RTTestPrintf(g_hTest, RTTESTLVL_ALWAYS, "Destroying stream '%s' (IAudioConnector) ...\n", pStream->Cfg.szName);
895 int rc = pDrvStack->pIAudioConnector->pfnStreamDestroy(pDrvStack->pIAudioConnector, pStream, true /*fImmediate*/);
896 if (RT_FAILURE(rc))
897 RTTestFailed(g_hTest, "pfnStreamDestroy failed: %Rrc", rc);
898 }
899 else
900 {
901 RTTestPrintf(g_hTest, RTTESTLVL_ALWAYS, "Destroying stream '%s' (IHostAudio) ...\n", pStream->Cfg.szName);
902 PAUDIOTESTDRVSTACKSTREAM pStreamAt = (PAUDIOTESTDRVSTACKSTREAM)pStream;
903 int rc = pDrvStack->pIHostAudio->pfnStreamDestroy(pDrvStack->pIHostAudio, &pStreamAt->Backend, true /*fImmediate*/);
904 if (RT_SUCCESS(rc))
905 {
906 pStreamAt->Core.uMagic = ~PDMAUDIOSTREAM_MAGIC;
907 pStreamAt->Backend.uMagic = ~PDMAUDIOBACKENDSTREAM_MAGIC;
908 RTMemFree(pStreamAt);
909 }
910 else
911 RTTestFailed(g_hTest, "PDMIHOSTAUDIO::pfnStreamDestroy failed: %Rrc", rc);
912 }
913
914 RTTestPrintf(g_hTest, RTTESTLVL_ALWAYS, "Destroying stream '%s' done\n", pStream->Cfg.szName);
915 }
916}
917
918
919/**
920 * Enables a stream.
921 */
922int audioTestDriverStackStreamEnable(PAUDIOTESTDRVSTACK pDrvStack, PPDMAUDIOSTREAM pStream)
923{
924 int rc;
925 if (pDrvStack->pIAudioConnector)
926 {
927 rc = pDrvStack->pIAudioConnector->pfnStreamControl(pDrvStack->pIAudioConnector, pStream, PDMAUDIOSTREAMCMD_ENABLE);
928 if (RT_FAILURE(rc))
929 RTTestFailed(g_hTest, "pfnStreamControl/ENABLE failed: %Rrc", rc);
930 }
931 else
932 {
933 PAUDIOTESTDRVSTACKSTREAM pStreamAt = (PAUDIOTESTDRVSTACKSTREAM)pStream;
934 rc = pDrvStack->pIHostAudio->pfnStreamEnable(pDrvStack->pIHostAudio, &pStreamAt->Backend);
935 if (RT_FAILURE(rc))
936 RTTestFailed(g_hTest, "PDMIHOSTAUDIO::pfnStreamEnable failed: %Rrc", rc);
937 }
938 return rc;
939}
940
941
942/**
943 * Disables a stream.
944 */
945int AudioTestDriverStackStreamDisable(PAUDIOTESTDRVSTACK pDrvStack, PPDMAUDIOSTREAM pStream)
946{
947 int rc;
948 if (pDrvStack->pIAudioConnector)
949 {
950 rc = pDrvStack->pIAudioConnector->pfnStreamControl(pDrvStack->pIAudioConnector, pStream, PDMAUDIOSTREAMCMD_DISABLE);
951 if (RT_FAILURE(rc))
952 RTTestFailed(g_hTest, "pfnStreamControl/DISABLE failed: %Rrc", rc);
953 }
954 else
955 {
956 PAUDIOTESTDRVSTACKSTREAM pStreamAt = (PAUDIOTESTDRVSTACKSTREAM)pStream;
957 rc = pDrvStack->pIHostAudio->pfnStreamDisable(pDrvStack->pIHostAudio, &pStreamAt->Backend);
958 if (RT_FAILURE(rc))
959 RTTestFailed(g_hTest, "PDMIHOSTAUDIO::pfnStreamDisable failed: %Rrc", rc);
960 }
961 return rc;
962}
963
964
965/**
966 * Drains an output stream.
967 */
968int audioTestDriverStackStreamDrain(PAUDIOTESTDRVSTACK pDrvStack, PPDMAUDIOSTREAM pStream, bool fSync)
969{
970 int rc;
971 if (pDrvStack->pIAudioConnector)
972 {
973 /*
974 * Issue the drain request.
975 */
976 rc = pDrvStack->pIAudioConnector->pfnStreamControl(pDrvStack->pIAudioConnector, pStream, PDMAUDIOSTREAMCMD_DRAIN);
977 if (RT_SUCCESS(rc) && fSync)
978 {
979 /*
980 * This is a synchronous drain, so wait for the driver to change state to inactive.
981 */
982 PDMAUDIOSTREAMSTATE enmState;
983 while ( (enmState = pDrvStack->pIAudioConnector->pfnStreamGetState(pDrvStack->pIAudioConnector, pStream))
984 >= PDMAUDIOSTREAMSTATE_ENABLED)
985 {
986 RTThreadSleep(2);
987 rc = pDrvStack->pIAudioConnector->pfnStreamIterate(pDrvStack->pIAudioConnector, pStream);
988 if (RT_FAILURE(rc))
989 {
990 RTTestFailed(g_hTest, "pfnStreamIterate/DRAIN failed: %Rrc", rc);
991 break;
992 }
993 }
994 if (enmState != PDMAUDIOSTREAMSTATE_INACTIVE)
995 {
996 RTTestFailed(g_hTest, "Stream state not INACTIVE after draining: %s", PDMAudioStreamStateGetName(enmState));
997 rc = VERR_AUDIO_STREAM_NOT_READY;
998 }
999 }
1000 else if (RT_FAILURE(rc))
1001 RTTestFailed(g_hTest, "pfnStreamControl/ENABLE failed: %Rrc", rc);
1002 }
1003 else
1004 {
1005 /*
1006 * Issue the drain request.
1007 */
1008 PAUDIOTESTDRVSTACKSTREAM pStreamAt = (PAUDIOTESTDRVSTACKSTREAM)pStream;
1009 rc = pDrvStack->pIHostAudio->pfnStreamDrain(pDrvStack->pIHostAudio, &pStreamAt->Backend);
1010 if (RT_SUCCESS(rc) && fSync)
1011 {
1012 RTMSINTERVAL const msTimeout = RT_MS_5MIN; /* 5 minutes should be really enough for draining our stuff. */
1013 uint64_t const tsStart = RTTimeMilliTS();
1014
1015 /*
1016 * This is a synchronous drain, so wait for the driver to change state to inactive.
1017 */
1018 PDMHOSTAUDIOSTREAMSTATE enmHostState;
1019 while ( (enmHostState = pDrvStack->pIHostAudio->pfnStreamGetState(pDrvStack->pIHostAudio, &pStreamAt->Backend))
1020 == PDMHOSTAUDIOSTREAMSTATE_DRAINING)
1021 {
1022 RTThreadSleep(2);
1023 uint32_t cbWritten = UINT32_MAX;
1024 rc = pDrvStack->pIHostAudio->pfnStreamPlay(pDrvStack->pIHostAudio, &pStreamAt->Backend,
1025 NULL /*pvBuf*/, 0 /*cbBuf*/, &cbWritten);
1026 if (RT_FAILURE(rc))
1027 {
1028 RTTestFailed(g_hTest, "pfnStreamPlay/DRAIN failed: %Rrc", rc);
1029 break;
1030 }
1031 if (cbWritten != 0)
1032 {
1033 RTTestFailed(g_hTest, "pfnStreamPlay/DRAIN did not set cbWritten to zero: %#x", cbWritten);
1034 rc = VERR_MISSING;
1035 break;
1036 }
1037
1038 /* Fail-safe for audio stacks and/or implementations which mess up draining. */
1039 if (RTTimeMilliTS() - tsStart > msTimeout)
1040 {
1041 RTTestFailed(g_hTest, "Draining stream took too long (timeout is %RU32ms), giving up", msTimeout);
1042 break;
1043 }
1044 }
1045 if (enmHostState != PDMHOSTAUDIOSTREAMSTATE_OKAY)
1046 {
1047 RTTestFailed(g_hTest, "Stream state not OKAY after draining: %s", PDMHostAudioStreamStateGetName(enmHostState));
1048 rc = VERR_AUDIO_STREAM_NOT_READY;
1049 }
1050 }
1051 else if (RT_FAILURE(rc))
1052 RTTestFailed(g_hTest, "PDMIHOSTAUDIO::pfnStreamControl/ENABLE failed: %Rrc", rc);
1053 }
1054 return rc;
1055}
1056
1057
1058/**
1059 * Checks if the stream is okay.
1060 * @returns true if okay, false if not.
1061 */
1062bool audioTestDriverStackStreamIsOkay(PAUDIOTESTDRVSTACK pDrvStack, PPDMAUDIOSTREAM pStream)
1063{
1064 /*
1065 * Get the stream status and check if it means is okay or not.
1066 */
1067 bool fRc = false;
1068 if (pDrvStack->pIAudioConnector)
1069 {
1070 PDMAUDIOSTREAMSTATE enmState = pDrvStack->pIAudioConnector->pfnStreamGetState(pDrvStack->pIAudioConnector, pStream);
1071 switch (enmState)
1072 {
1073 case PDMAUDIOSTREAMSTATE_NOT_WORKING:
1074 case PDMAUDIOSTREAMSTATE_NEED_REINIT:
1075 break;
1076 case PDMAUDIOSTREAMSTATE_INACTIVE:
1077 case PDMAUDIOSTREAMSTATE_ENABLED:
1078 case PDMAUDIOSTREAMSTATE_ENABLED_READABLE:
1079 case PDMAUDIOSTREAMSTATE_ENABLED_WRITABLE:
1080 fRc = true;
1081 break;
1082 /* no default */
1083 case PDMAUDIOSTREAMSTATE_INVALID:
1084 case PDMAUDIOSTREAMSTATE_END:
1085 case PDMAUDIOSTREAMSTATE_32BIT_HACK:
1086 break;
1087 }
1088 }
1089 else
1090 {
1091 PAUDIOTESTDRVSTACKSTREAM pStreamAt = (PAUDIOTESTDRVSTACKSTREAM)pStream;
1092 PDMHOSTAUDIOSTREAMSTATE enmHostState = pDrvStack->pIHostAudio->pfnStreamGetState(pDrvStack->pIHostAudio,
1093 &pStreamAt->Backend);
1094 switch (enmHostState)
1095 {
1096 case PDMHOSTAUDIOSTREAMSTATE_INITIALIZING:
1097 case PDMHOSTAUDIOSTREAMSTATE_NOT_WORKING:
1098 break;
1099 case PDMHOSTAUDIOSTREAMSTATE_OKAY:
1100 case PDMHOSTAUDIOSTREAMSTATE_DRAINING:
1101 case PDMHOSTAUDIOSTREAMSTATE_INACTIVE:
1102 fRc = true;
1103 break;
1104 /* no default */
1105 case PDMHOSTAUDIOSTREAMSTATE_INVALID:
1106 case PDMHOSTAUDIOSTREAMSTATE_END:
1107 case PDMHOSTAUDIOSTREAMSTATE_32BIT_HACK:
1108 break;
1109 }
1110 }
1111 return fRc;
1112}
1113
1114
1115/**
1116 * Gets the number of bytes it's currently possible to write to the stream.
1117 */
1118uint32_t audioTestDriverStackStreamGetWritable(PAUDIOTESTDRVSTACK pDrvStack, PPDMAUDIOSTREAM pStream)
1119{
1120 uint32_t cbWritable;
1121 if (pDrvStack->pIAudioConnector)
1122 cbWritable = pDrvStack->pIAudioConnector->pfnStreamGetWritable(pDrvStack->pIAudioConnector, pStream);
1123 else
1124 {
1125 PAUDIOTESTDRVSTACKSTREAM pStreamAt = (PAUDIOTESTDRVSTACKSTREAM)pStream;
1126 cbWritable = pDrvStack->pIHostAudio->pfnStreamGetWritable(pDrvStack->pIHostAudio, &pStreamAt->Backend);
1127 }
1128 return cbWritable;
1129}
1130
1131
1132/**
1133 * Tries to play the @a cbBuf bytes of samples in @a pvBuf.
1134 */
1135int audioTestDriverStackStreamPlay(PAUDIOTESTDRVSTACK pDrvStack, PPDMAUDIOSTREAM pStream,
1136 void const *pvBuf, uint32_t cbBuf, uint32_t *pcbPlayed)
1137{
1138 int rc;
1139 if (pDrvStack->pIAudioConnector)
1140 {
1141 rc = pDrvStack->pIAudioConnector->pfnStreamPlay(pDrvStack->pIAudioConnector, pStream, pvBuf, cbBuf, pcbPlayed);
1142 if (RT_FAILURE(rc))
1143 RTTestFailed(g_hTest, "pfnStreamPlay(,,,%#x,) failed: %Rrc", cbBuf, rc);
1144 }
1145 else
1146 {
1147 PAUDIOTESTDRVSTACKSTREAM pStreamAt = (PAUDIOTESTDRVSTACKSTREAM)pStream;
1148 rc = pDrvStack->pIHostAudio->pfnStreamPlay(pDrvStack->pIHostAudio, &pStreamAt->Backend, pvBuf, cbBuf, pcbPlayed);
1149 if (RT_FAILURE(rc))
1150 RTTestFailed(g_hTest, "PDMIHOSTAUDIO::pfnStreamPlay(,,,%#x,) failed: %Rrc", cbBuf, rc);
1151 }
1152 return rc;
1153}
1154
1155
1156/**
1157 * Gets the number of bytes it's currently possible to write to the stream.
1158 */
1159uint32_t audioTestDriverStackStreamGetReadable(PAUDIOTESTDRVSTACK pDrvStack, PPDMAUDIOSTREAM pStream)
1160{
1161 uint32_t cbReadable;
1162 if (pDrvStack->pIAudioConnector)
1163 cbReadable = pDrvStack->pIAudioConnector->pfnStreamGetReadable(pDrvStack->pIAudioConnector, pStream);
1164 else
1165 {
1166 PAUDIOTESTDRVSTACKSTREAM pStreamAt = (PAUDIOTESTDRVSTACKSTREAM)pStream;
1167 cbReadable = pDrvStack->pIHostAudio->pfnStreamGetReadable(pDrvStack->pIHostAudio, &pStreamAt->Backend);
1168 }
1169 return cbReadable;
1170}
1171
1172
1173/**
1174 * Tries to capture @a cbBuf bytes of samples in @a pvBuf.
1175 */
1176int audioTestDriverStackStreamCapture(PAUDIOTESTDRVSTACK pDrvStack, PPDMAUDIOSTREAM pStream,
1177 void *pvBuf, uint32_t cbBuf, uint32_t *pcbCaptured)
1178{
1179 int rc;
1180 if (pDrvStack->pIAudioConnector)
1181 {
1182 rc = pDrvStack->pIAudioConnector->pfnStreamCapture(pDrvStack->pIAudioConnector, pStream, pvBuf, cbBuf, pcbCaptured);
1183 if (RT_FAILURE(rc))
1184 RTTestFailed(g_hTest, "pfnStreamCapture(,,,%#x,) failed: %Rrc", cbBuf, rc);
1185 }
1186 else
1187 {
1188 PAUDIOTESTDRVSTACKSTREAM pStreamAt = (PAUDIOTESTDRVSTACKSTREAM)pStream;
1189 rc = pDrvStack->pIHostAudio->pfnStreamCapture(pDrvStack->pIHostAudio, &pStreamAt->Backend, pvBuf, cbBuf, pcbCaptured);
1190 if (RT_FAILURE(rc))
1191 RTTestFailed(g_hTest, "PDMIHOSTAUDIO::pfnStreamCapture(,,,%#x,) failed: %Rrc", cbBuf, rc);
1192 }
1193 return rc;
1194}
1195
1196
1197/*********************************************************************************************************************************
1198* Mixed streams *
1199*********************************************************************************************************************************/
1200
1201/**
1202 * Initializing mixing for a stream.
1203 *
1204 * This can be used as a do-nothing wrapper for the stack.
1205 *
1206 * @returns VBox status code.
1207 * @param pMix The mixing state.
1208 * @param pStream The stream to mix to/from.
1209 * @param pProps The mixer properties. Pass NULL for no mixing, just
1210 * wrap the driver stack functionality.
1211 * @param cMsBuffer The buffer size.
1212 */
1213int AudioTestMixStreamInit(PAUDIOTESTDRVMIXSTREAM pMix, PAUDIOTESTDRVSTACK pDrvStack, PPDMAUDIOSTREAM pStream,
1214 PCPDMAUDIOPCMPROPS pProps, uint32_t cMsBuffer)
1215{
1216 RT_ZERO(*pMix);
1217
1218 AssertReturn(pDrvStack, VERR_INVALID_PARAMETER);
1219 AssertReturn(pStream, VERR_INVALID_PARAMETER);
1220
1221 pMix->pDrvStack = pDrvStack;
1222 pMix->pStream = pStream;
1223 if (!pProps)
1224 {
1225 pMix->pProps = &pStream->Cfg.Props;
1226 return VINF_SUCCESS;
1227 }
1228
1229 /*
1230 * Okay, we're doing mixing so we need to set up the mixer buffer
1231 * and associated states.
1232 */
1233 pMix->fDoMixing = true;
1234 int rc = AudioMixBufInit(&pMix->MixBuf, "mixer", pProps, PDMAudioPropsMilliToFrames(pProps, cMsBuffer));
1235 if (RT_SUCCESS(rc))
1236 {
1237 pMix->pProps = &pMix->MixBuf.Props;
1238
1239 if (pStream->Cfg.enmDir == PDMAUDIODIR_IN)
1240 {
1241 rc = AudioMixBufInitPeekState(&pMix->MixBuf, &pMix->PeekState, &pMix->MixBuf.Props);
1242 if (RT_SUCCESS(rc))
1243 {
1244 rc = AudioMixBufInitWriteState(&pMix->MixBuf, &pMix->WriteState, &pStream->Cfg.Props);
1245 if (RT_SUCCESS(rc))
1246 return rc;
1247 }
1248 }
1249 else if (pStream->Cfg.enmDir == PDMAUDIODIR_OUT)
1250 {
1251 rc = AudioMixBufInitWriteState(&pMix->MixBuf, &pMix->WriteState, &pMix->MixBuf.Props);
1252 if (RT_SUCCESS(rc))
1253 {
1254 rc = AudioMixBufInitPeekState(&pMix->MixBuf, &pMix->PeekState, &pStream->Cfg.Props);
1255 if (RT_SUCCESS(rc))
1256 return rc;
1257 }
1258 }
1259 else
1260 {
1261 RTTestFailed(g_hTest, "Bogus stream direction!");
1262 rc = VERR_INVALID_STATE;
1263 }
1264 }
1265 else
1266 RTTestFailed(g_hTest, "AudioMixBufInit failed: %Rrc", rc);
1267 RT_ZERO(*pMix);
1268 return rc;
1269}
1270
1271
1272/**
1273 * Terminate mixing (leaves the stream untouched).
1274 *
1275 * @param pMix The mixing state.
1276 */
1277void AudioTestMixStreamTerm(PAUDIOTESTDRVMIXSTREAM pMix)
1278{
1279 if (pMix->fDoMixing)
1280 {
1281 AudioMixBufTerm(&pMix->MixBuf);
1282 pMix->pStream = NULL;
1283 }
1284 RT_ZERO(*pMix);
1285}
1286
1287
1288/**
1289 * Worker that transports data between the mixer buffer and the drivers.
1290 *
1291 * @returns VBox status code.
1292 * @param pMix The mixer stream setup to do transfers for.
1293 */
1294static int audioTestMixStreamTransfer(PAUDIOTESTDRVMIXSTREAM pMix)
1295{
1296 uint8_t abBuf[16384];
1297 if (pMix->pStream->Cfg.enmDir == PDMAUDIODIR_IN)
1298 {
1299 /*
1300 * Try fill up the mixer buffer as much as possible.
1301 *
1302 * Slight fun part is that we have to calculate conversion
1303 * ratio and be rather pessimistic about it.
1304 */
1305 uint32_t const cbBuf = PDMAudioPropsFloorBytesToFrame(&pMix->pStream->Cfg.Props, sizeof(abBuf));
1306 for (;;)
1307 {
1308 /*
1309 * Figure out how much we can move in this iteration.
1310 */
1311 uint32_t cDstFrames = AudioMixBufFree(&pMix->MixBuf);
1312 if (!cDstFrames)
1313 break;
1314
1315 uint32_t cbReadable = audioTestDriverStackStreamGetReadable(pMix->pDrvStack, pMix->pStream);
1316 if (!cbReadable)
1317 break;
1318
1319 uint32_t cbToRead;
1320 if (PDMAudioPropsHz(&pMix->pStream->Cfg.Props) == PDMAudioPropsHz(&pMix->MixBuf.Props))
1321 cbToRead = PDMAudioPropsFramesToBytes(&pMix->pStream->Cfg.Props, cDstFrames);
1322 else
1323 cbToRead = PDMAudioPropsFramesToBytes(&pMix->pStream->Cfg.Props,
1324 (uint64_t)cDstFrames * PDMAudioPropsHz(&pMix->pStream->Cfg.Props)
1325 / PDMAudioPropsHz(&pMix->MixBuf.Props));
1326 cbToRead = RT_MIN(cbToRead, RT_MIN(cbReadable, cbBuf));
1327 if (!cbToRead)
1328 break;
1329
1330 /*
1331 * Get the data.
1332 */
1333 uint32_t cbCaptured = 0;
1334 int rc = audioTestDriverStackStreamCapture(pMix->pDrvStack, pMix->pStream, abBuf, cbToRead, &cbCaptured);
1335 if (RT_FAILURE(rc))
1336 return rc;
1337 Assert(cbCaptured == cbToRead);
1338 AssertBreak(cbCaptured > 0);
1339
1340 /*
1341 * Feed it to the mixer.
1342 */
1343 uint32_t cDstFramesWritten = 0;
1344 if ((abBuf[0] >> 4) & 1) /* some cheap random */
1345 AudioMixBufWrite(&pMix->MixBuf, &pMix->WriteState, abBuf, cbCaptured,
1346 0 /*offDstFrame*/, cDstFrames, &cDstFramesWritten);
1347 else
1348 {
1349 AudioMixBufSilence(&pMix->MixBuf, &pMix->WriteState, 0 /*offFrame*/, cDstFrames);
1350 AudioMixBufBlend(&pMix->MixBuf, &pMix->WriteState, abBuf, cbCaptured,
1351 0 /*offDstFrame*/, cDstFrames, &cDstFramesWritten);
1352 }
1353 AudioMixBufCommit(&pMix->MixBuf, cDstFramesWritten);
1354 }
1355 }
1356 else
1357 {
1358 /*
1359 * The goal here is to empty the mixer buffer by transfering all
1360 * the data to the drivers.
1361 */
1362 uint32_t const cbBuf = PDMAudioPropsFloorBytesToFrame(&pMix->MixBuf.Props, sizeof(abBuf));
1363 for (;;)
1364 {
1365 uint32_t cFrames = AudioMixBufUsed(&pMix->MixBuf);
1366 if (!cFrames)
1367 break;
1368
1369 uint32_t cbWritable = audioTestDriverStackStreamGetWritable(pMix->pDrvStack, pMix->pStream);
1370 if (!cbWritable)
1371 break;
1372
1373 uint32_t cSrcFramesPeeked;
1374 uint32_t cbDstPeeked;
1375 AudioMixBufPeek(&pMix->MixBuf, 0 /*offSrcFrame*/, cFrames, &cSrcFramesPeeked,
1376 &pMix->PeekState, abBuf, RT_MIN(cbBuf, cbWritable), &cbDstPeeked);
1377 AudioMixBufAdvance(&pMix->MixBuf, cSrcFramesPeeked);
1378
1379 if (!cbDstPeeked)
1380 break;
1381
1382 uint32_t offBuf = 0;
1383 while (offBuf < cbDstPeeked)
1384 {
1385 uint32_t cbPlayed = 0;
1386 int rc = audioTestDriverStackStreamPlay(pMix->pDrvStack, pMix->pStream,
1387 &abBuf[offBuf], cbDstPeeked - offBuf, &cbPlayed);
1388 if (RT_FAILURE(rc))
1389 return rc;
1390 if (!cbPlayed)
1391 RTThreadSleep(1);
1392 offBuf += cbPlayed;
1393 }
1394 }
1395 }
1396 return VINF_SUCCESS;
1397}
1398
1399
1400/**
1401 * Same as audioTestDriverStackStreamEnable.
1402 */
1403int AudioTestMixStreamEnable(PAUDIOTESTDRVMIXSTREAM pMix)
1404{
1405 return audioTestDriverStackStreamEnable(pMix->pDrvStack, pMix->pStream);
1406}
1407
1408
1409/**
1410 * Same as audioTestDriverStackStreamDrain.
1411 */
1412int AudioTestMixStreamDrain(PAUDIOTESTDRVMIXSTREAM pMix, bool fSync)
1413{
1414 /*
1415 * If we're mixing, we must first make sure the buffer is empty.
1416 */
1417 if (pMix->fDoMixing)
1418 {
1419 audioTestMixStreamTransfer(pMix);
1420 while (AudioMixBufUsed(&pMix->MixBuf) > 0)
1421 {
1422 RTThreadSleep(1);
1423 audioTestMixStreamTransfer(pMix);
1424 }
1425 }
1426
1427 /*
1428 * Then we do the regular work.
1429 */
1430 return audioTestDriverStackStreamDrain(pMix->pDrvStack, pMix->pStream, fSync);
1431}
1432
1433/**
1434 * Same as audioTestDriverStackStreamDisable.
1435 */
1436int AudioTestMixStreamDisable(PAUDIOTESTDRVMIXSTREAM pMix)
1437{
1438 return AudioTestDriverStackStreamDisable(pMix->pDrvStack, pMix->pStream);
1439}
1440
1441
1442/**
1443 * Same as audioTestDriverStackStreamIsOkay.
1444 */
1445bool AudioTestMixStreamIsOkay(PAUDIOTESTDRVMIXSTREAM pMix)
1446{
1447 return audioTestDriverStackStreamIsOkay(pMix->pDrvStack, pMix->pStream);
1448}
1449
1450
1451/**
1452 * Same as audioTestDriverStackStreamGetWritable
1453 */
1454uint32_t AudioTestMixStreamGetWritable(PAUDIOTESTDRVMIXSTREAM pMix)
1455{
1456 if (!pMix->fDoMixing)
1457 return audioTestDriverStackStreamGetWritable(pMix->pDrvStack, pMix->pStream);
1458 uint32_t cbRet = AudioMixBufFreeBytes(&pMix->MixBuf);
1459 if (!cbRet)
1460 {
1461 audioTestMixStreamTransfer(pMix);
1462 cbRet = AudioMixBufFreeBytes(&pMix->MixBuf);
1463 }
1464 return cbRet;
1465}
1466
1467
1468
1469
1470/**
1471 * Same as audioTestDriverStackStreamPlay.
1472 */
1473int AudioTestMixStreamPlay(PAUDIOTESTDRVMIXSTREAM pMix, void const *pvBuf, uint32_t cbBuf, uint32_t *pcbPlayed)
1474{
1475 if (!pMix->fDoMixing)
1476 return audioTestDriverStackStreamPlay(pMix->pDrvStack, pMix->pStream, pvBuf, cbBuf, pcbPlayed);
1477
1478 *pcbPlayed = 0;
1479
1480 int rc = audioTestMixStreamTransfer(pMix);
1481 if (RT_FAILURE(rc))
1482 return rc;
1483
1484 uint32_t const cbFrame = PDMAudioPropsFrameSize(&pMix->MixBuf.Props);
1485 while (cbBuf >= cbFrame)
1486 {
1487 uint32_t const cFrames = AudioMixBufFree(&pMix->MixBuf);
1488 if (!cFrames)
1489 break;
1490 uint32_t cbToWrite = PDMAudioPropsFramesToBytes(&pMix->MixBuf.Props, cFrames);
1491 cbToWrite = RT_MIN(cbToWrite, cbBuf);
1492 cbToWrite = PDMAudioPropsFloorBytesToFrame(&pMix->MixBuf.Props, cbToWrite);
1493
1494 uint32_t cFramesWritten = 0;
1495 AudioMixBufWrite(&pMix->MixBuf, &pMix->WriteState, pvBuf, cbToWrite, 0 /*offDstFrame*/, cFrames, &cFramesWritten);
1496 Assert(cFramesWritten == PDMAudioPropsBytesToFrames(&pMix->MixBuf.Props, cbToWrite));
1497 AudioMixBufCommit(&pMix->MixBuf, cFramesWritten);
1498
1499 *pcbPlayed += cbToWrite;
1500 cbBuf -= cbToWrite;
1501 pvBuf = (uint8_t const *)pvBuf + cbToWrite;
1502
1503 rc = audioTestMixStreamTransfer(pMix);
1504 if (RT_FAILURE(rc))
1505 return *pcbPlayed ? VINF_SUCCESS : rc;
1506 }
1507
1508 return VINF_SUCCESS;
1509}
1510
1511
1512/**
1513 * Same as audioTestDriverStackStreamGetReadable
1514 */
1515uint32_t AudioTestMixStreamGetReadable(PAUDIOTESTDRVMIXSTREAM pMix)
1516{
1517 if (!pMix->fDoMixing)
1518 return audioTestDriverStackStreamGetReadable(pMix->pDrvStack, pMix->pStream);
1519
1520 audioTestMixStreamTransfer(pMix);
1521 uint32_t cbRet = AudioMixBufUsedBytes(&pMix->MixBuf);
1522 return cbRet;
1523}
1524
1525
1526
1527
1528/**
1529 * Same as audioTestDriverStackStreamCapture.
1530 */
1531int AudioTestMixStreamCapture(PAUDIOTESTDRVMIXSTREAM pMix, void *pvBuf, uint32_t cbBuf, uint32_t *pcbCaptured)
1532{
1533 if (!pMix->fDoMixing)
1534 return audioTestDriverStackStreamCapture(pMix->pDrvStack, pMix->pStream, pvBuf, cbBuf, pcbCaptured);
1535
1536 *pcbCaptured = 0;
1537
1538 int rc = audioTestMixStreamTransfer(pMix);
1539 if (RT_FAILURE(rc))
1540 return rc;
1541
1542 uint32_t const cbFrame = PDMAudioPropsFrameSize(&pMix->MixBuf.Props);
1543 while (cbBuf >= cbFrame)
1544 {
1545 uint32_t const cFrames = AudioMixBufUsed(&pMix->MixBuf);
1546 if (!cFrames)
1547 break;
1548 uint32_t cbToRead = PDMAudioPropsFramesToBytes(&pMix->MixBuf.Props, cFrames);
1549 cbToRead = RT_MIN(cbToRead, cbBuf);
1550 cbToRead = PDMAudioPropsFloorBytesToFrame(&pMix->MixBuf.Props, cbToRead);
1551
1552 uint32_t cFramesPeeked = 0;
1553 uint32_t cbPeeked = 0;
1554 AudioMixBufPeek(&pMix->MixBuf, 0 /*offSrcFrame*/, cFrames, &cFramesPeeked, &pMix->PeekState, pvBuf, cbToRead, &cbPeeked);
1555 Assert(cFramesPeeked == PDMAudioPropsBytesToFrames(&pMix->MixBuf.Props, cbPeeked));
1556 AudioMixBufAdvance(&pMix->MixBuf, cFramesPeeked);
1557
1558 *pcbCaptured += cbToRead;
1559 cbBuf -= cbToRead;
1560 pvBuf = (uint8_t *)pvBuf + cbToRead;
1561
1562 rc = audioTestMixStreamTransfer(pMix);
1563 if (RT_FAILURE(rc))
1564 return *pcbCaptured ? VINF_SUCCESS : rc;
1565 }
1566
1567 return VINF_SUCCESS;
1568}
1569
1570/**
1571 * Sets the volume of a mixing stream.
1572 *
1573 * @param pMix Mixing stream to set volume for.
1574 * @param uVolumePercent Volume to set (in percent, 0-100).
1575 */
1576void AudioTestMixStreamSetVolume(PAUDIOTESTDRVMIXSTREAM pMix, uint8_t uVolumePercent)
1577{
1578 AssertReturnVoid(pMix->fDoMixing);
1579
1580 uint8_t const uVol = (PDMAUDIO_VOLUME_MAX / 100) * uVolumePercent;
1581
1582 PDMAUDIOVOLUME Vol;
1583 RT_ZERO(Vol);
1584 for (size_t i = 0; i < RT_ELEMENTS(Vol.auChannels); i++)
1585 Vol.auChannels[i] = uVol;
1586 AudioMixBufSetVolume(&pMix->MixBuf, &Vol);
1587}
1588
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