VirtualBox

Ignore:
Timestamp:
Nov 3, 2021 5:27:10 PM (3 years ago)
Author:
vboxsync
svn:sync-xref-src-repo-rev:
148025
Message:

Audio/Validation Kit: More code for audio data beacon handling. Now has dedicated beacons for recording / playback tests. bugref:10008

File:
1 edited

Legend:

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

    r92058 r92195  
    525525        uint32_t cbPlayedTotal  = 0;
    526526
    527         /* We play a pre + post beacon before + after the actual test tone
    528          * with exactly AUDIOTEST_BEACON_SIZE_FRAMES audio frames. */
    529         uint32_t const cbBeacon       = PDMAudioPropsFramesToBytes(&pStream->Cfg.Props, AUDIOTEST_BEACON_SIZE_FRAMES);
    530         uint32_t       cbBeaconToPlay = cbBeacon;
    531         uint32_t       cbBeaconPlayed = 0;
    532 
     527        /* We play a pre + post beacon before + after the actual test tone.
     528         * We always start with the pre beacon. */
     529        AUDIOTESTTONEBEACON Beacon;
     530        AudioTestBeaconInit(&Beacon, AUDIOTESTTONEBEACONTYPE_PLAY_PRE, &pStream->Cfg.Props);
     531
     532        uint32_t const cbBeacon = AudioTestBeaconGetSize(&Beacon);
    533533        if (cbBeacon)
    534534        {
    535             RTTestPrintf(g_hTest, RTTESTLVL_ALWAYS, "Playing 2 x %RU32 bytes pre/post beacons\n", cbBeaconToPlay);
     535            RTTestPrintf(g_hTest, RTTESTLVL_ALWAYS, "Playing 2 x %RU32 bytes pre/post beacons\n", cbBeacon);
    536536            cbToPlayTotal += cbBeacon * 2 /* Pre + post beacon */;
    537537        }
     
    539539        if (pTstEnv)
    540540        {
     541            AudioTestObjAddMetadataStr(Obj, "beacon_type=%RU32\n", (uint32_t)AudioTestBeaconGetType(&Beacon));
    541542            AudioTestObjAddMetadataStr(Obj, "beacon_pre_bytes=%RU32\n", cbBeacon);
    542543            AudioTestObjAddMetadataStr(Obj, "beacon_post_bytes=%RU32\n", cbBeacon);
     
    591592
    592593                /* Any beacon to play? */
    593                 if (   cbBeaconToPlay
    594                     && cbBeaconPlayed < cbBeaconToPlay)
     594                uint32_t const cbBeaconRemaining = AudioTestBeaconGetRemaining(&Beacon);
     595                if (cbBeaconRemaining)
    595596                {
    596597                    /* Limit to exactly one beacon (pre or post). */
    597                     cbToPlay = RT_MIN(sizeof(abBuf), RT_MIN(cbCanWrite, cbBeaconToPlay - cbBeaconPlayed));
    598                     memset(abBuf,
    599                            cbPlayedTotal >= cbToPlayTotal - cbBeaconToPlay ? AUDIOTEST_BEACON_BYTE_POST : AUDIOTEST_BEACON_BYTE_PRE,
    600                            cbToPlay);
    601 
    602                     rc = AudioTestMixStreamPlay(&pStream->Mix, abBuf, cbToPlay, &cbPlayed);
     598                    cbToPlay = RT_MIN(sizeof(abBuf), RT_MIN(cbCanWrite, cbBeaconRemaining));
     599                    rc = AudioTestBeaconWrite(&Beacon, abBuf, cbToPlay);
     600                    if (RT_SUCCESS(rc))
     601                        rc = AudioTestMixStreamPlay(&pStream->Mix, abBuf, cbToPlay, &cbPlayed);
    603602                    if (RT_FAILURE(rc))
    604603                        break;
     
    611610                        rc = AudioTestObjWrite(Obj, abBuf, cbPlayed);
    612611                    }
    613 
    614                     cbBeaconPlayed += cbPlayed;
    615                     cbPlayedTotal  += cbPlayed;
    616                     continue;
    617612                }
    618 
    619                 /* Start playing the post beacon? */
    620                 if (cbPlayedTotal == cbToPlayTotal - cbBeaconToPlay)
     613                else /* Play test tone */
    621614                {
    622                     cbBeaconPlayed = 0;
    623                     continue;
    624                 }
    625 
    626                 if (RT_FAILURE(rc))
    627                     break;
    628 
    629                 uint32_t const cbToGenerate = RT_MIN(RT_MIN(cbToPlayTotal - cbPlayedTotal - cbBeaconToPlay, sizeof(abBuf)),
    630                                                      cbCanWrite);
    631                 rc = AudioTestToneGenerate(&TstTone, abBuf, cbToGenerate, &cbToPlay);
    632                 if (RT_SUCCESS(rc))
    633                 {
    634                     if (pTstEnv)
     615                    uint32_t const cbTestToneToPlay = cbToPlayTotal - cbPlayedTotal - (cbBeacon /* Pre / post beacon */);
     616                    if (cbTestToneToPlay == 0) /* Done playing the test tone? */
    635617                    {
    636                         /* Write stuff to disk before trying to play it. Help analysis later. */
    637                         rc = AudioTestObjWrite(Obj, abBuf, cbToPlay);
     618                        if (AudioTestBeaconGetSize(&Beacon)) /* Play the post beacon, if any. */
     619                        {
     620                            AudioTestBeaconInit(&Beacon, AUDIOTESTTONEBEACONTYPE_PLAY_POST, &pStream->Cfg.Props);
     621                            continue;
     622                        }
     623
     624                        break;
    638625                    }
     626
     627                    uint32_t const cbToGenerate = RT_MIN(RT_MIN(cbTestToneToPlay, sizeof(abBuf)), cbCanWrite);
     628                    rc = AudioTestToneGenerate(&TstTone, abBuf, cbToGenerate, &cbToPlay);
    639629                    if (RT_SUCCESS(rc))
    640630                    {
    641                         rc = AudioTestMixStreamPlay(&pStream->Mix, abBuf, cbToPlay, &cbPlayed);
     631                        if (pTstEnv)
     632                        {
     633                            /* Write stuff to disk before trying to play it. Help analysis later. */
     634                            rc = AudioTestObjWrite(Obj, abBuf, cbToPlay);
     635                        }
    642636                        if (RT_SUCCESS(rc))
    643637                        {
    644                             AssertBreakStmt(cbPlayed <= cbToPlay, rc = VERR_TOO_MUCH_DATA);
    645 
    646                             offStream += cbPlayed;
    647 
    648                             if (cbPlayed != cbToPlay)
    649                                 RTTestFailed(g_hTest, "Only played %RU32/%RU32 bytes", cbPlayed, cbToPlay);
    650 
    651                             if (cbPlayed)
    652                                 nsLastWrite = nsNow;
     638                            rc = AudioTestMixStreamPlay(&pStream->Mix, abBuf, cbToPlay, &cbPlayed);
     639                            if (RT_SUCCESS(rc))
     640                            {
     641                                AssertBreakStmt(cbPlayed <= cbToPlay, rc = VERR_TOO_MUCH_DATA);
     642
     643                                offStream += cbPlayed;
     644
     645                                if (cbPlayed != cbToPlay)
     646                                    RTTestFailed(g_hTest, "Only played %RU32/%RU32 bytes", cbPlayed, cbToPlay);
     647
     648                                if (cbPlayed)
     649                                    nsLastWrite = nsNow;
     650                            }
    653651                        }
    654652                    }
     
    746744    if (RT_SUCCESS(rc))
    747745    {
    748         uint64_t cbToRecTotal = PDMAudioPropsMilliToBytes(&pStream->Cfg.Props, pParms->msDuration);
    749 
    750         /* We record a pre + post beacon before + after the actual test tone
    751          * with exactly AUDIOTEST_BEACON_SIZE_FRAMES audio frames. */
    752         uint32_t const cbBeacon = PDMAudioPropsFramesToBytes(&pStream->Cfg.Props, AUDIOTEST_BEACON_SIZE_FRAMES);
     746        uint64_t cbRecTotal  = 0; /* Counts everything, including silence / whatever. */
     747        uint64_t cbTestToRec = PDMAudioPropsMilliToBytes(&pStream->Cfg.Props, pParms->msDuration);
     748
     749        /* We expect a pre + post beacon before + after the actual test tone.
     750         * We always start with the pre beacon. */
     751        AUDIOTESTTONEBEACON Beacon;
     752        AudioTestBeaconInit(&Beacon, AUDIOTESTTONEBEACONTYPE_PLAY_PRE, &pStream->Cfg.Props);
     753
     754        uint32_t const cbBeacon = AudioTestBeaconGetSize(&Beacon);
    753755        if (cbBeacon)
    754756        {
    755             RTTestPrintf(g_hTest, RTTESTLVL_ALWAYS, "Recording 2 x %RU32 bytes pre/post beacons\n", cbBeacon);
    756             cbToRecTotal += cbBeacon * 2 /* Pre + post beacon */;
    757 
    758             AudioTestObjAddMetadataStr(Obj, "beacon_pre_bytes=%RU32\n", cbBeacon);
    759             AudioTestObjAddMetadataStr(Obj, "beacon_post_bytes=%RU32\n", cbBeacon);
    760         }
    761 
    762         AudioTestObjAddMetadataStr(Obj, "stream_to_record_bytes=%RU32\n", cbToRecTotal);
     757            RTTestPrintf(g_hTest, RTTESTLVL_ALWAYS, "Expecting 2 x %RU32 bytes pre/post beacons\n", cbBeacon);
     758            cbTestToRec = cbBeacon * 2 /* Pre + post beacon */;
     759        }
     760
     761        AudioTestObjAddMetadataStr(Obj, "beacon_type=%RU32\n", (uint32_t)AudioTestBeaconGetType(&Beacon));
     762        AudioTestObjAddMetadataStr(Obj, "beacon_pre_bytes=%RU32\n", cbBeacon);
     763        AudioTestObjAddMetadataStr(Obj, "beacon_post_bytes=%RU32\n", cbBeacon);
     764        AudioTestObjAddMetadataStr(Obj, "stream_to_record_bytes=%RU32\n", cbTestToRec);
    763765        AudioTestObjAddMetadataStr(Obj, "stream_buffer_size_ms=%RU32\n", pIoOpts->cMsBufferSize);
    764766        AudioTestObjAddMetadataStr(Obj, "stream_prebuf_size_ms=%RU32\n", pIoOpts->cMsPreBuffer);
     
    767769        AudioTestObjAddMetadataStr(Obj, "device_scheduling_hint_ms=%RU32\n", pIoOpts->cMsSchedulingHint);
    768770
    769         RTTestPrintf(g_hTest, RTTESTLVL_DEBUG, "Recording %RU32 bytes total\n", cbToRecTotal);
     771        RTTestPrintf(g_hTest, RTTESTLVL_DEBUG, "Recording %RU32 bytes total\n", cbTestToRec);
    770772
    771773        uint8_t         abSamples[16384];
    772         uint32_t const  cbSamplesAligned = PDMAudioPropsFloorBytesToFrame(pMix->pProps, sizeof(abSamples));
    773         uint64_t        cbRecTotal  = 0;
     774        uint32_t const  cbSamplesAligned  = PDMAudioPropsFloorBytesToFrame(pMix->pProps, sizeof(abSamples));
     775        uint64_t        cbTestRec         = 0;
    774776
    775777        uint64_t const  nsStarted         = RTTimeNanoTS();
     
    778780        uint64_t        nsLastMsgCantRead = 0; /* Timestamp (in ns) when the last message of an unreadable stream was shown. */
    779781
    780         while (!g_fTerminate && cbRecTotal < cbToRecTotal)
     782        while (!g_fTerminate && cbTestRec < cbTestToRec)
    781783        {
    782784            uint64_t const nsNow = RTTimeNanoTS();
     
    799801                    if (cbRecorded)
    800802                    {
     803                        cbRecTotal += cbRecorded;
     804
    801805                        rc = AudioTestObjWrite(Obj, abSamples, cbRecorded);
    802806                        if (RT_SUCCESS(rc))
    803807                        {
    804                             cbRecTotal += cbRecorded;
    805 
    806                             /** @todo Clamp result? */
     808                            if (AudioTestBeaconGetSize(&Beacon))
     809                            {
     810                                if (!AudioTestBeaconIsComplete(&Beacon))
     811                                {
     812                                    bool const fStarted = AudioTestBeaconGetRemaining(&Beacon) == AudioTestBeaconGetSize(&Beacon);
     813
     814                                    uint32_t const cbToAddMax = RT_MIN(cbRecorded, AudioTestBeaconGetRemaining(&Beacon));
     815
     816                                    uint32_t const cbAdded = AudioTestBeaconAddConsecutive(&Beacon, abSamples, cbToAddMax);
     817                                    if (cbAdded)
     818                                        cbTestRec += cbAdded; /* Only count data which belongs to a (complete test tone). */
     819
     820                                    if (   fStarted
     821                                        && g_uVerbosity >= 2)
     822                                        RTTestPrintf(g_hTest, RTTESTLVL_ALWAYS,
     823                                                     "Detection of %s playback beacon started (%RU32ms recorded so far)\n",
     824                                                     AudioTestBeaconTypeGetName(Beacon.enmType),
     825                                                     PDMAudioPropsBytesToMilli(&pStream->pStream->Cfg.Props, cbRecTotal));
     826
     827                                    if (AudioTestBeaconIsComplete(&Beacon))
     828                                    {
     829                                        if (g_uVerbosity >= 2)
     830                                            RTTestPrintf(g_hTest, RTTESTLVL_ALWAYS, "Detection of %s playback beacon ended\n",
     831                                                         AudioTestBeaconTypeGetName(Beacon.enmType));
     832                                    }
     833                                }
     834                                else
     835                                {
     836                                    uint32_t const cbTestToneToRec = cbTestToRec - cbTestRec - cbBeacon;
     837                                    if (cbTestToneToRec == 0) /* Done recording the test tone? */
     838                                    {
     839                                        AudioTestBeaconInit(&Beacon, AUDIOTESTTONEBEACONTYPE_PLAY_POST, &pStream->Cfg.Props);
     840                                    }
     841                                    else /* Count test tone data. */
     842                                        cbTestRec += cbRecorded;
     843                                }
     844                            }
    807845                        }
    808846                    }
     
    836874        }
    837875
    838         if (cbRecTotal != cbToRecTotal)
    839             RTTestFailed(g_hTest, "Recording ended unexpectedly (%RU32/%RU32 recorded)\n", cbRecTotal, cbToRecTotal);
     876        if (cbTestRec != cbTestToRec)
     877            RTTestFailed(g_hTest, "Recording ended unexpectedly (%RU32/%RU32 recorded)\n", cbTestRec, cbTestToRec);
    840878
    841879        int rc2 = AudioTestMixStreamDisable(pMix);
Note: See TracChangeset for help on using the changeset viewer.

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