Changeset 89226 in vbox for trunk/src/VBox/ValidationKit/utils
- Timestamp:
- May 21, 2021 3:02:10 PM (4 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/ValidationKit/utils/audio/vkat.cpp
r89225 r89226 2484 2484 2485 2485 /** 2486 * Structure for keeping a user context for the test service callbacks. 2487 */ 2488 typedef struct ATSCALLBACKCTX 2489 { 2490 /** Driver stack to use. */ 2491 PAUDIOTESTDRVSTACK pDrvStack; 2492 /** Audio stream to use. */ 2493 PPDMAUDIOSTREAM pStream; 2494 } ATSCALLBACKCTX; 2495 typedef ATSCALLBACKCTX *PATSCALLBACKCTX; 2496 2497 /** 2498 * Note: Called within server (client serving) thread. 2499 */ 2500 static DECLCALLBACK(int) audioTestSvcTonePlayCallback(void const *pvUser, PPDMAUDIOSTREAMCFG pStreamCfg, PAUDIOTESTTONEPARMS pToneParms) 2501 { 2502 PATSCALLBACKCTX pCtx = (PATSCALLBACKCTX)pvUser; 2503 2504 AUDIOTESTTONE TstTone; 2505 AudioTestToneInitRandom(&TstTone, &pStreamCfg->Props); 2506 2507 int rc; 2508 2509 if (audioTestDriverStackStreamIsOkay(pCtx->pDrvStack, pCtx->pStream)) 2510 { 2511 uint32_t cbBuf; 2512 uint8_t abBuf[_4K]; 2513 2514 const uint64_t tsStartMs = RTTimeMilliTS(); 2515 const uint16_t cSchedulingMs = RTRandU32Ex(10, 80); /* Chose a random scheduling (in ms). */ 2516 const uint32_t cbPerMs = PDMAudioPropsMilliToBytes(&pCtx->pStream->Props, cSchedulingMs); 2517 2518 do 2519 { 2520 rc = AudioTestToneGenerate(&TstTone, abBuf, RT_MIN(cbPerMs, sizeof(abBuf)), &cbBuf); 2521 if (RT_SUCCESS(rc)) 2522 { 2523 uint32_t cbWritten; 2524 rc = audioTestDriverStackStreamPlay(pCtx->pDrvStack, pCtx->pStream, abBuf, cbBuf, &cbWritten); 2525 } 2526 2527 if (RTTimeMilliTS() - tsStartMs >= pToneParms->msDuration) 2528 break; 2529 2530 if (RT_FAILURE(rc)) 2531 break; 2532 2533 RTThreadSleep(cSchedulingMs); 2534 2535 } while (RT_SUCCESS(rc)); 2536 } 2537 else 2538 rc = VERR_AUDIO_STREAM_NOT_READY; 2539 2540 return rc; 2541 } 2542 2543 /** 2486 2544 * Tests the Audio Test Service (ATS). 2487 2545 * 2546 * @param pDrvReg Backend driver to use. 2488 2547 * @returns VBox status code. 2489 2548 */ 2490 static int audioTestDoSelftestSvc( void)2491 { 2492 A TSSERVER Srv;2493 int rc = AudioTestSvcInit(&Srv);2549 static int audioTestDoSelftestSvc(PCPDMDRVREG pDrvReg) 2550 { 2551 AUDIOTESTDRVSTACK DrvStack; 2552 int rc = audioTestDriverStackInit(&DrvStack, pDrvReg, true /* fWithDrvAudio */); 2494 2553 if (RT_SUCCESS(rc)) 2495 2554 { 2496 rc = AudioTestSvcStart(&Srv); 2555 PDMAUDIOPCMPROPS Props; 2556 PDMAudioPropsInit(&Props, 16 /* bit */ / 8, true /* fSigned */, 2 /* Channels */, 44100 /* Hz */); 2557 2558 PDMAUDIOSTREAMCFG CfgAcq; 2559 PPDMAUDIOSTREAM pStream = NULL; 2560 rc = audioTestDriverStackStreamCreateOutput(&DrvStack, &Props, 2561 UINT32_MAX /* cMsBufferSize */, 2562 UINT32_MAX /* cMsPreBuffer */, 2563 UINT32_MAX /* cMsSchedulingHint */, &pStream, &CfgAcq); 2497 2564 if (RT_SUCCESS(rc)) 2498 2565 { 2499 ATSCLIENT Conn; 2500 rc = AudioTestSvcClientConnect(&Conn, NULL); 2566 rc = audioTestDriverStackStreamEnable(&DrvStack, pStream); 2501 2567 if (RT_SUCCESS(rc)) 2502 2568 { 2503 rc = AudioTestSvcClientClose(&Conn); 2569 ATSCALLBACKCTX Ctx; 2570 Ctx.pDrvStack = &DrvStack; 2571 Ctx.pStream = pStream; 2572 2573 ATSCALLBACKS Callbacks; 2574 Callbacks.pfnTonePlay = audioTestSvcTonePlayCallback; 2575 Callbacks.pvUser = &Ctx; 2576 2577 ATSSERVER Srv; 2578 rc = AudioTestSvcInit(&Srv, &Callbacks); 2579 if (RT_SUCCESS(rc)) 2580 { 2581 rc = AudioTestSvcStart(&Srv); 2582 if (RT_SUCCESS(rc)) 2583 { 2584 ATSCLIENT Conn; 2585 rc = AudioTestSvcClientConnect(&Conn, NULL); 2586 if (RT_SUCCESS(rc)) 2587 { 2588 /* Do the bare minimum here to get a test tone out. */ 2589 AUDIOTESTTONEPARMS ToneParms = { 0 }; 2590 ToneParms.msDuration = 2000; 2591 memcpy(&ToneParms.Props, &CfgAcq.Props, sizeof(PDMAUDIOPCMPROPS)); 2592 2593 rc = AudioTestSvcClientTonePlay(&Conn, &CfgAcq, &ToneParms); 2594 2595 int rc2 = AudioTestSvcClientClose(&Conn); 2596 if (RT_SUCCESS(rc)) 2597 rc = rc2; 2598 } 2599 2600 int rc2 = AudioTestSvcShutdown(&Srv); 2601 if (RT_SUCCESS(rc)) 2602 rc = rc2; 2603 } 2604 2605 int rc2 = AudioTestSvcDestroy(&Srv); 2606 if (RT_SUCCESS(rc)) 2607 rc = rc2; 2608 } 2504 2609 } 2505 2506 int rc2 = AudioTestSvcShutdown(&Srv);2507 if (RT_SUCCESS(rc))2508 rc = rc2;2509 2610 } 2510 2511 int rc2 = AudioTestSvcDestroy(&Srv);2512 if (RT_SUCCESS(rc))2513 rc = rc2;2514 2611 } 2515 2612 … … 2521 2618 * 2522 2619 * @returns VBox status code. 2523 */ 2524 static int audioTestDoSelftest(void) 2525 { 2526 int rc = audioTestDoSelftestSvc(); 2620 * @param pDrvReg Backend driver to use. 2621 */ 2622 static int audioTestDoSelftest(PCPDMDRVREG pDrvReg) 2623 { 2624 int rc = audioTestDoSelftestSvc(pDrvReg); 2527 2625 if (RT_FAILURE(rc)) 2528 2626 RTTestFailed(g_hTest, "Self-test failed with: %Rrc", rc); … … 2579 2677 } 2580 2678 2581 audioTestDoSelftest( );2679 audioTestDoSelftest(pDrvReg); 2582 2680 /* 2583 2681 * Print summary and exit.
Note:
See TracChangeset
for help on using the changeset viewer.