VirtualBox

Changeset 91912 in vbox


Ignore:
Timestamp:
Oct 20, 2021 7:09:54 PM (3 years ago)
Author:
vboxsync
svn:sync-xref-src-repo-rev:
147717
Message:

Audio/Validation Kit: Cleaned up the test tone validation code a bit. ​bugref:10008

File:
1 edited

Legend:

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

    r91761 r91912  
    383383 * Finds the next audible *or* silent audio sample and returns its offset.
    384384 *
    385  * @returns Offset (in bytes) of the next found sample, or UINT64_MAX if not found / invalid parameters.
     385 * @returns Offset (in bytes) of the next found sample, or \a cbMax if not found / invalid parameters.
    386386 * @param   hFile               File handle of file to search in.
    387387 * @param   fFindSilence        Whether to search for a silent sample or not (i.e. audible).
    388388 *                              What a silent sample is depends on \a pToneParms PCM parameters.
    389389 * @param   uOff                Absolute offset (in bytes) to start searching from.
     390 * @param   cbMax               Maximum amount of bytes to process.
    390391 * @param   pToneParms          Tone parameters to use.
    391392 * @param   cbWindow            Search window size (in bytes).
    392393 */
    393 static uint64_t audioTestToneFileFind(RTFILE hFile, bool fFindSilence, uint64_t uOff, PAUDIOTESTTONEPARMS pToneParms,
    394                                       size_t cbWindow)
     394static uint64_t audioTestToneFileFind(RTFILE hFile, bool fFindSilence, uint64_t uOff, uint64_t cbMax,
     395                                      PAUDIOTESTTONEPARMS pToneParms, size_t cbWindow)
    395396{
    396397    int rc = RTFileSeek(hFile, uOff, RTFILE_SEEK_BEGIN, NULL);
     
    422423            bool const fIsSilence = PDMAudioPropsIsBufferSilence(&pToneParms->Props, (const uint8_t *)abBuf + i, cbWindow);
    423424            if (fIsSilence != fFindSilence)
     425            {
     426                AssertReturn(PDMAudioPropsIsSizeAligned(&pToneParms->Props, offFound), 0);
    424427                return offFound;
     428            }
    425429            offFound += cbWindow;
    426430        }
    427431    }
    428432
    429     AssertReturn(PDMAudioPropsIsSizeAligned(&pToneParms->Props, offFound), 0);
    430     return UINT64_MAX;
     433    return cbMax;
    431434}
    432435
     
    22442247    uint64_t cbDiffs = 0;
    22452248
    2246     RT_NOREF(pToneParms);
    22472249    uint32_t const cbChunkSize = PDMAudioPropsFrameSize(&pToneParms->Props); /* Use the audio frame size as chunk size. */
    22482250
     
    23222324 * Verifies a pre/post beacon of a test tone.
    23232325 *
    2324  * @returns VBox status code.
     2326 * @returns VBox status code, VERR_NOT_FOUND if beacon was not found.
    23252327 * @param   pVerJob             Verification job to verify PCM data for.
    23262328 * @param   fPre                Set to \c true to verify a pre beacon, or \c false to verify a post beacon.
    23272329 * @param   pCmp                File comparison parameters to file to verify beacon for.
    23282330 * @param   pToneParms          Tone parameters to use for verification.
    2329  * @param   puOff               Where to return the file offset (in bytes) right after the found beacon.
     2331 * @param   puOff               Where to return the absolute file offset (in bytes) right after the found beacon on success.
    23302332 */
    23312333static int audioTestToneVerifyBeacon(PAUDIOTESTVERIFYJOB pVerJob,
     
    23922394                                             fPre ? "Pre" : "Post", cbBeacon ? "found" : "not found", cbBeacon, cbBeaconExpected);
    23932395        AssertRC(rc2);
     2396        return VERR_NOT_FOUND;
    23942397    }
    23952398    else
     
    24612464     * Start with most obvious methods first.
    24622465     */
    2463     uint64_t cbSizeA, cbSizeB;
    2464     rc = RTFileQuerySize(ObjA.File.hFile, &cbSizeA);
    2465     AssertRCReturn(rc, rc);
    2466     rc = RTFileQuerySize(ObjB.File.hFile, &cbSizeB);
    2467     AssertRCReturn(rc, rc);
    2468 
    2469     if (!cbSizeA)
     2466    uint64_t cbFileSizeA, cbFileSizeB;
     2467    rc = RTFileQuerySize(ObjA.File.hFile, &cbFileSizeA);
     2468    AssertRCReturn(rc, rc);
     2469    rc = RTFileQuerySize(ObjB.File.hFile, &cbFileSizeB);
     2470    AssertRCReturn(rc, rc);
     2471
     2472    if (!cbFileSizeA)
    24702473    {
    24712474        int rc2 = audioTestErrorDescAddError(pVerJob->pErr, pVerJob->idxTest, "File '%s' is empty", ObjA.szName);
     
    24732476    }
    24742477
    2475     if (!cbSizeB)
     2478    if (!cbFileSizeB)
    24762479    {
    24772480        int rc2 = audioTestErrorDescAddError(pVerJob->pErr, pVerJob->idxTest, "File '%s' is empty", ObjB.szName);
     
    24792482    }
    24802483
    2481     if (cbSizeA != cbSizeB)
    2482     {
    2483         size_t const cbDiffAbs = cbSizeA > cbSizeB ? cbSizeA - cbSizeB : cbSizeB - cbSizeA;
     2484    if (cbFileSizeA != cbFileSizeB)
     2485    {
     2486        size_t const cbDiffAbs = cbFileSizeA > cbFileSizeB ? cbFileSizeA - cbFileSizeB : cbFileSizeB - cbFileSizeA;
    24842487
    24852488        int rc2 = audioTestErrorDescAddInfo(pVerJob->pErr, pVerJob->idxTest, "File '%s': %zu bytes (%RU64ms)",
    2486                                             ObjA.szName, cbSizeA, PDMAudioPropsBytesToMilli(&pVerJob->PCMProps, cbSizeA));
     2489                                            ObjA.szName, cbFileSizeA, PDMAudioPropsBytesToMilli(&pVerJob->PCMProps, cbFileSizeA));
    24872490        AssertRC(rc2);
    24882491        rc2 = audioTestErrorDescAddInfo(pVerJob->pErr, pVerJob->idxTest, "File '%s': %zu bytes (%RU64ms)",
    2489                                         ObjB.szName, cbSizeB, PDMAudioPropsBytesToMilli(&pVerJob->PCMProps, cbSizeB));
     2492                                        ObjB.szName, cbFileSizeB, PDMAudioPropsBytesToMilli(&pVerJob->PCMProps, cbFileSizeB));
    24902493        AssertRC(rc2);
    24912494
    24922495        uint8_t const uSizeDiffPercentAbs
    2493             = cbSizeA > cbSizeB ? 100 - ((cbSizeB * 100) / cbSizeA) : 100 - ((cbSizeA * 100) / cbSizeB);
     2496            = cbFileSizeA > cbFileSizeB ? 100 - ((cbFileSizeB * 100) / cbFileSizeA) : 100 - ((cbFileSizeA * 100) / cbFileSizeB);
    24942497
    24952498        if (uSizeDiffPercentAbs > pVerJob->Opts.uMaxSizePercent)
     
    25002503                                             uSizeDiffPercentAbs,
    25012504                                             cbDiffAbs, PDMAudioPropsBytesToMilli(&pVerJob->PCMProps, (uint32_t)cbDiffAbs),
    2502                                              cbSizeA > cbSizeB ? "bigger" : "smaller",
     2505                                             cbFileSizeA > cbFileSizeB ? "bigger" : "smaller",
    25032506                                             ObjB.szName, pVerJob->Opts.uMaxSizePercent);
    25042507            AssertRC(rc2);
     
    25262529    FileA.pszName   = ObjA.szName;
    25272530    FileA.hFile     = ObjA.File.hFile;
    2528     FileA.offStart  =        audioTestToneFileFind(ObjA.File.hFile,
    2529                                                    true /* fFindSilence */, 0 /* uOff */, &ToneParmsA, cbSearchWindow);
    2530     FileA.cbSize    = RT_MIN(audioTestToneFileFind(ObjA.File.hFile,
    2531                                                    false /* fFindSilence */, FileA.offStart, &ToneParmsA, cbSearchWindow),
    2532                              cbSizeA - FileA.offStart);
     2531    FileA.offStart  = audioTestToneFileFind(ObjA.File.hFile, true /* fFindSilence */,
     2532                                            0 /* uOff */, cbFileSizeA /* cbMax */, &ToneParmsA, cbSearchWindow);
     2533    FileA.cbSize    = audioTestToneFileFind(ObjA.File.hFile, false /* fFindSilence */,
     2534                                            FileA.offStart /* uOff */, cbFileSizeA - FileA.offStart /* cbMax */, &ToneParmsA, cbSearchWindow);
     2535    AssertReturn(FileA.offStart + FileA.cbSize <= cbFileSizeA, VERR_INTERNAL_ERROR);
    25332536
    25342537    AUDIOTESTTONEPARMS ToneParmsB;
     
    25402543    FileB.pszName   = ObjB.szName;
    25412544    FileB.hFile     = ObjB.File.hFile;
    2542     FileB.offStart  =        audioTestToneFileFind(ObjB.File.hFile,
    2543                                                    true /* fFindSilence */, 0 /* uOff */, &ToneParmsB, cbSearchWindow);
    2544     FileB.cbSize    = RT_MIN(audioTestToneFileFind(ObjB.File.hFile,
    2545                                                    false /* fFindSilence */, FileB.offStart, &ToneParmsB, cbSearchWindow),
    2546                              cbSizeB - FileB.offStart);
     2545    FileB.offStart  = audioTestToneFileFind(ObjB.File.hFile, true /* fFindSilence */,
     2546                                            0 /* uOff */, cbFileSizeB /* cbMax */, &ToneParmsB, cbSearchWindow);
     2547    FileB.cbSize    = audioTestToneFileFind(ObjB.File.hFile, false /* fFindSilence */,
     2548                                            FileB.offStart /* uOff */, cbFileSizeB - FileB.offStart /* cbMax */, &ToneParmsB, cbSearchWindow);
     2549    AssertReturn(FileB.offStart + FileB.cbSize <= cbFileSizeB, VERR_INTERNAL_ERROR);
    25472550
    25482551    int rc2;
    2549 #ifdef DEBUG
    2550     rc2 = audioTestErrorDescAddInfo(pVerJob->pErr, pVerJob->idxTest, "File A ('%s'): uOff=%RU64 (%#x), cbSize=%RU64 (%#x), cbFileSize=%RU64\n",
    2551                                     ObjA.szName, FileA.offStart, FileA.offStart, FileA.cbSize, FileA.cbSize, cbSizeA);
    2552     AssertRC(rc2);
    2553 
    2554     rc2 = audioTestErrorDescAddInfo(pVerJob->pErr, pVerJob->idxTest, "File B ('%s'): uOff=%RU64 (%#x), cbSize=%RU64 (%#x), cbFileSize=%RU64\n",
    2555                                     ObjB.szName, FileB.offStart, FileB.offStart, FileB.cbSize, FileB.cbSize, cbSizeB);
    2556     AssertRC(rc2);
    2557 #endif
    2558 
    2559     rc = audioTestToneVerifyBeacon(pVerJob, true  /* fPre */,  &FileA, &ToneParmsA, &FileA.offStart /* Save new offset after pre beacon */);
    2560     AssertRC(rc);
    2561     rc = audioTestToneVerifyBeacon(pVerJob, false /* fPost */, &FileA, &ToneParmsA, NULL);
    2562     AssertRC(rc);
    2563     rc = audioTestToneVerifyBeacon(pVerJob, true  /* fPre */,  &FileB, &ToneParmsB, &FileB.offStart /* Save new offset after pre beacon */);
    2564     AssertRC(rc);
    2565     rc = audioTestToneVerifyBeacon(pVerJob, false /* fPost */, &FileB, &ToneParmsB, NULL);
    2566     AssertRC(rc);
    2567 
    2568     /* Note! When finding the pre/post beacons fail it's mostly pointless to comparing the files in any way,
    2569      *       as this would be the strongest hint that testing failed as a whole. We do it anyway for now, to
    2570      *       just get a clue what's going on. Might be disabled lateron. */
    2571     uint32_t const cDiffs = audioTestFilesFindDiffsBinary(pVerJob, &FileA, &FileB, &ToneParmsA);
    2572 
    2573     if (cDiffs > pVerJob->Opts.cMaxDiff)
    2574     {
    2575         rc2 = audioTestErrorDescAddError(pVerJob->pErr, pVerJob->idxTest,
    2576                                          "Files '%s' and '%s' have too many different chunks (got %RU32, expected %RU32)",
    2577                                          ObjA.szName, ObjB.szName, cDiffs, pVerJob->Opts.cMaxDiff);
    2578         AssertRC(rc2);
     2552
     2553    uint64_t offBeaconAbs;
     2554    rc = audioTestToneVerifyBeacon(pVerJob, true  /* fPre */,  &FileA, &ToneParmsA, &offBeaconAbs);
     2555    if (RT_SUCCESS(rc))
     2556    {
     2557        FileA.offStart = offBeaconAbs;
     2558        FileA.cbSize   = cbFileSizeA - FileA.offStart;
     2559        rc = audioTestToneVerifyBeacon(pVerJob, false /* fPost */, &FileA, &ToneParmsA, NULL);
     2560    }
     2561
     2562    rc = audioTestToneVerifyBeacon(pVerJob, true  /* fPre */,  &FileB, &ToneParmsB, &offBeaconAbs);
     2563    if (RT_SUCCESS(rc))
     2564    {
     2565        FileB.offStart = offBeaconAbs;
     2566        FileB.cbSize   = cbFileSizeB - FileB.offStart;
     2567        rc = audioTestToneVerifyBeacon(pVerJob, false /* fPost */, &FileB, &ToneParmsB, NULL);
     2568    }
     2569
     2570    if (RT_SUCCESS(rc))
     2571    {
     2572        uint32_t const cDiffs = audioTestFilesFindDiffsBinary(pVerJob, &FileA, &FileB, &ToneParmsA);
     2573
     2574        if (cDiffs > pVerJob->Opts.cMaxDiff)
     2575        {
     2576            rc2 = audioTestErrorDescAddError(pVerJob->pErr, pVerJob->idxTest,
     2577                                             "Files '%s' and '%s' have too many different chunks (got %RU32, expected %RU32)",
     2578                                             ObjA.szName, ObjB.szName, cDiffs, pVerJob->Opts.cMaxDiff);
     2579            AssertRC(rc2);
     2580        }
    25792581    }
    25802582
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