VirtualBox

Changeset 91665 in vbox


Ignore:
Timestamp:
Oct 11, 2021 4:55:35 PM (3 years ago)
Author:
vboxsync
Message:

Audio/Validation Kit: Implemented (simple) pre/post test tone beacon verification. ​bugref:10008

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Devices/Audio/AudioTest.cpp

    r91662 r91665  
    22052205typedef struct AUDIOTESTFILECMPPARMS
    22062206{
     2207    /** File name for logging purposes. */
     2208    const char *pszName;
    22072209    /** File handle to file to compare. */
    2208     RTFILE   hFile;
     2210    RTFILE      hFile;
    22092211    /** Absolute offset (in bytes) to start comparing.
    22102212     *  Ignored when set to 0. */
    2211     uint64_t offStart;
     2213    uint64_t    offStart;
    22122214    /** Size (in bytes) of area to compare.
    22132215     *  Starts at \a offStart. */
    2214     uint64_t cbSize;
     2216    uint64_t    cbSize;
    22152217} AUDIOTESTFILECMPPARMS;
    22162218/** Pointer to file comparison parameters for one file. */
     
    23172319}
    23182320
     2321/**
     2322 * Verifies a pre/post beacon of a test tone.
     2323 *
     2324 * @returns VBox status code.
     2325 * @param   pVerJob             Verification job to verify PCM data for.
     2326 * @param   fPre                Set to \c true to verify a pre beacon, or \c false to verify a post beacon.
     2327 * @param   pCmp                File comparison parameters to file to verify beacon for.
     2328 * @param   pToneParms          Tone parameters to use for verification.
     2329 */
     2330static int audioTestToneVerifyBeacon(PAUDIOTESTVERIFYJOB pVerJob,
     2331                                     bool fPre, PAUDIOTESTFILECMPPARMS pCmp, PAUDIOTESTTONEPARMS pToneParms)
     2332{
     2333    int rc = RTFileSeek(pCmp->hFile, pCmp->offStart, RTFILE_SEEK_BEGIN, NULL);
     2334    AssertRCReturn(rc, rc);
     2335
     2336    uint8_t        auBuf[64];
     2337    uint64_t       cbToCompare = pCmp->cbSize;
     2338    uint32_t const cbFrameSize = PDMAudioPropsFrameSize(&pToneParms->Props); /* Use the audio frame size as chunk size. */
     2339    bool           fInBeacon   = false;
     2340    uint32_t       cbBeacon    = 0;
     2341
     2342    uint8_t const  byBeacon    = fPre ? AUDIOTEST_BEACON_BYTE_PRE : AUDIOTEST_BEACON_BYTE_POST;
     2343
     2344    AssertReturn(cbFrameSize == 4, VERR_NOT_SUPPORTED); /* Otherwise the stuff below won't work. */
     2345
     2346    /* Slow as heck, but does the job for now. */
     2347    while (cbToCompare)
     2348    {
     2349        size_t cbRead;
     2350        rc = RTFileRead(pCmp->hFile, auBuf, RT_MIN(cbToCompare, cbFrameSize), &cbRead);
     2351        AssertRCBreak(rc);
     2352
     2353        if (cbRead < cbFrameSize)
     2354            break;
     2355
     2356        for (size_t i = 0; i < cbRead; i += cbFrameSize)
     2357        {
     2358            if (   auBuf[i]     == byBeacon
     2359                && auBuf[i + 1] == byBeacon
     2360                && auBuf[i + 2] == byBeacon
     2361                && auBuf[i + 3] == byBeacon)
     2362            {
     2363                if (!fInBeacon)
     2364                {
     2365                    cbBeacon  = 0;
     2366                    fInBeacon = true;
     2367                }
     2368                cbBeacon += cbFrameSize;
     2369            }
     2370            else
     2371            {
     2372                if (fInBeacon)
     2373                {
     2374                    fInBeacon = false;
     2375                    continue;
     2376                }
     2377            }
     2378        }
     2379
     2380        cbToCompare -= cbRead;
     2381    }
     2382
     2383    uint32_t const cbBeaconExpected = PDMAudioPropsFramesToBytes(&pToneParms->Props, AUDIOTEST_BEACON_SIZE_FRAMES);
     2384    bool     const fValid           = cbBeacon == cbBeaconExpected;
     2385    if (!fValid)
     2386    {
     2387        int rc2 = audioTestErrorDescAddError(pVerJob->pErr, pVerJob->idxTest, "File '%s': %s beacon %s (got %RU32 bytes, expected %RU32)",
     2388                                             pCmp->pszName,
     2389                                             fPre ? "Pre" : "Post", cbBeacon ? "found" : "not found", cbBeacon, cbBeaconExpected);
     2390        AssertRC(rc2);
     2391    }
     2392
     2393    return rc;
     2394}
     2395
    23192396#define CHECK_RC_MAYBE_RET(a_rc, a_pVerJob) \
    23202397    if (RT_FAILURE(a_rc)) \
     
    23942471        size_t const cbDiffAbs = cbSizeA > cbSizeB ? cbSizeA - cbSizeB : cbSizeB - cbSizeA;
    23952472
    2396         int rc2 = audioTestErrorDescAddInfo(pVerJob->pErr, pVerJob->idxTest, "File '%s' is %zu bytes (%RU64ms)",
     2473        int rc2 = audioTestErrorDescAddInfo(pVerJob->pErr, pVerJob->idxTest, "File '%s': %zu bytes (%RU64ms)",
    23972474                                            ObjA.szName, cbSizeA, PDMAudioPropsBytesToMilli(&pVerJob->PCMProps, cbSizeA));
    23982475        AssertRC(rc2);
    2399         rc2 = audioTestErrorDescAddInfo(pVerJob->pErr, pVerJob->idxTest, "File '%s' is %zu bytes (%RU64ms)",
     2476        rc2 = audioTestErrorDescAddInfo(pVerJob->pErr, pVerJob->idxTest, "File '%s': %zu bytes (%RU64ms)",
    24002477                                        ObjB.szName, cbSizeB, PDMAudioPropsBytesToMilli(&pVerJob->PCMProps, cbSizeB));
    24012478        AssertRC(rc2);
     
    24352512    AUDIOTESTFILECMPPARMS FileA;
    24362513    RT_ZERO(FileA);
     2514    FileA.pszName   = ObjA.szName;
    24372515    FileA.hFile     = ObjA.File.hFile;
    24382516    FileA.offStart  =        audioTestToneFileFind(ObjA.File.hFile,
     
    24482526    AUDIOTESTFILECMPPARMS FileB;
    24492527    RT_ZERO(FileB);
     2528    FileB.pszName   = ObjB.szName;
    24502529    FileB.hFile     = ObjB.File.hFile;
    24512530    FileB.offStart  =        audioTestToneFileFind(ObjB.File.hFile,
     
    24612540    AssertRC(rc2);
    24622541
    2463     rc = audioTestErrorDescAddInfo(pVerJob->pErr, pVerJob->idxTest, "File B ('%s'): uOff=%RU64 (%#x), cbSize=%RU64 (%#x), cbFileSize=%RU64\n",
    2464                                    ObjB.szName, FileB.offStart, FileB.offStart, FileB.cbSize, FileB.cbSize, cbSizeB);
     2542    rc2 = audioTestErrorDescAddInfo(pVerJob->pErr, pVerJob->idxTest, "File B ('%s'): uOff=%RU64 (%#x), cbSize=%RU64 (%#x), cbFileSize=%RU64\n",
     2543                                    ObjB.szName, FileB.offStart, FileB.offStart, FileB.cbSize, FileB.cbSize, cbSizeB);
    24652544    AssertRC(rc2);
    24662545#endif
    24672546
     2547    rc = audioTestToneVerifyBeacon(pVerJob, true  /* fPre */,  &FileA, &ToneParmsA);
     2548    AssertRC(rc);
     2549    rc = audioTestToneVerifyBeacon(pVerJob, false /* fPost */, &FileA, &ToneParmsA);
     2550    AssertRC(rc);
     2551    rc = audioTestToneVerifyBeacon(pVerJob, true  /* fPre */,  &FileB, &ToneParmsB);
     2552    AssertRC(rc);
     2553    rc = audioTestToneVerifyBeacon(pVerJob, false /* fPost */, &FileB, &ToneParmsB);
     2554    AssertRC(rc);
     2555
     2556    /* Note! When finding the pre/post beacons fail it's mostly pointless to comparing the files in any way,
     2557     *       as this would be the strongest hint that testing failed as a whole. We do it anyway for now, to
     2558     *       just get a clue what's going on. Might be disabled lateron. */
    24682559    uint32_t const cDiffs = audioTestFilesFindDiffsBinary(pVerJob, &FileA, &FileB, &ToneParmsA);
    24692560
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