VirtualBox

Ignore:
Timestamp:
May 21, 2021 3:02:10 PM (4 years ago)
Author:
vboxsync
Message:

Audio/ValKit: Initial support for the audio test execution service (ATS) to support playing test tones. bugref:10008

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/ValidationKit/utils/audio/vkat.cpp

    r89225 r89226  
    24842484
    24852485/**
     2486 * Structure for keeping a user context for the test service callbacks.
     2487 */
     2488typedef struct ATSCALLBACKCTX
     2489{
     2490    /** Driver stack to use. */
     2491    PAUDIOTESTDRVSTACK pDrvStack;
     2492    /** Audio stream to use. */
     2493    PPDMAUDIOSTREAM    pStream;
     2494} ATSCALLBACKCTX;
     2495typedef ATSCALLBACKCTX *PATSCALLBACKCTX;
     2496
     2497/**
     2498 * Note: Called within server (client serving) thread.
     2499 */
     2500static 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/**
    24862544 * Tests the Audio Test Service (ATS).
    24872545 *
     2546 * @param   pDrvReg             Backend driver to use.
    24882547 * @returns VBox status code.
    24892548 */
    2490 static int audioTestDoSelftestSvc(void)
    2491 {
    2492     ATSSERVER Srv;
    2493     int rc = AudioTestSvcInit(&Srv);
     2549static int audioTestDoSelftestSvc(PCPDMDRVREG pDrvReg)
     2550{
     2551    AUDIOTESTDRVSTACK DrvStack;
     2552    int rc = audioTestDriverStackInit(&DrvStack, pDrvReg, true /* fWithDrvAudio */);
    24942553    if (RT_SUCCESS(rc))
    24952554    {
    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);
    24972564        if (RT_SUCCESS(rc))
    24982565        {
    2499             ATSCLIENT Conn;
    2500             rc = AudioTestSvcClientConnect(&Conn, NULL);
     2566            rc = audioTestDriverStackStreamEnable(&DrvStack, pStream);
    25012567            if (RT_SUCCESS(rc))
    25022568            {
    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                }
    25042609            }
    2505 
    2506             int rc2 = AudioTestSvcShutdown(&Srv);
    2507             if (RT_SUCCESS(rc))
    2508                 rc = rc2;
    25092610        }
    2510 
    2511         int rc2 = AudioTestSvcDestroy(&Srv);
    2512         if (RT_SUCCESS(rc))
    2513             rc = rc2;
    25142611    }
    25152612
     
    25212618 *
    25222619 * @returns VBox status code.
    2523  */
    2524 static int audioTestDoSelftest(void)
    2525 {
    2526     int rc = audioTestDoSelftestSvc();
     2620 * @param   pDrvReg             Backend driver to use.
     2621 */
     2622static int audioTestDoSelftest(PCPDMDRVREG pDrvReg)
     2623{
     2624    int rc = audioTestDoSelftestSvc(pDrvReg);
    25272625    if (RT_FAILURE(rc))
    25282626        RTTestFailed(g_hTest, "Self-test failed with: %Rrc", rc);
     
    25792677    }
    25802678
    2581     audioTestDoSelftest();
     2679    audioTestDoSelftest(pDrvReg);
    25822680        /*
    25832681     * Print summary and exit.
Note: See TracChangeset for help on using the changeset viewer.

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