Changeset 91912 in vbox
- Timestamp:
- Oct 20, 2021 7:09:54 PM (3 years ago)
- svn:sync-xref-src-repo-rev:
- 147717
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Devices/Audio/AudioTest.cpp
r91761 r91912 383 383 * Finds the next audible *or* silent audio sample and returns its offset. 384 384 * 385 * @returns Offset (in bytes) of the next found sample, or UINT64_MAXif not found / invalid parameters.385 * @returns Offset (in bytes) of the next found sample, or \a cbMax if not found / invalid parameters. 386 386 * @param hFile File handle of file to search in. 387 387 * @param fFindSilence Whether to search for a silent sample or not (i.e. audible). 388 388 * What a silent sample is depends on \a pToneParms PCM parameters. 389 389 * @param uOff Absolute offset (in bytes) to start searching from. 390 * @param cbMax Maximum amount of bytes to process. 390 391 * @param pToneParms Tone parameters to use. 391 392 * @param cbWindow Search window size (in bytes). 392 393 */ 393 static uint64_t audioTestToneFileFind(RTFILE hFile, bool fFindSilence, uint64_t uOff, PAUDIOTESTTONEPARMS pToneParms,394 size_t cbWindow)394 static uint64_t audioTestToneFileFind(RTFILE hFile, bool fFindSilence, uint64_t uOff, uint64_t cbMax, 395 PAUDIOTESTTONEPARMS pToneParms, size_t cbWindow) 395 396 { 396 397 int rc = RTFileSeek(hFile, uOff, RTFILE_SEEK_BEGIN, NULL); … … 422 423 bool const fIsSilence = PDMAudioPropsIsBufferSilence(&pToneParms->Props, (const uint8_t *)abBuf + i, cbWindow); 423 424 if (fIsSilence != fFindSilence) 425 { 426 AssertReturn(PDMAudioPropsIsSizeAligned(&pToneParms->Props, offFound), 0); 424 427 return offFound; 428 } 425 429 offFound += cbWindow; 426 430 } 427 431 } 428 432 429 AssertReturn(PDMAudioPropsIsSizeAligned(&pToneParms->Props, offFound), 0); 430 return UINT64_MAX; 433 return cbMax; 431 434 } 432 435 … … 2244 2247 uint64_t cbDiffs = 0; 2245 2248 2246 RT_NOREF(pToneParms);2247 2249 uint32_t const cbChunkSize = PDMAudioPropsFrameSize(&pToneParms->Props); /* Use the audio frame size as chunk size. */ 2248 2250 … … 2322 2324 * Verifies a pre/post beacon of a test tone. 2323 2325 * 2324 * @returns VBox status code .2326 * @returns VBox status code, VERR_NOT_FOUND if beacon was not found. 2325 2327 * @param pVerJob Verification job to verify PCM data for. 2326 2328 * @param fPre Set to \c true to verify a pre beacon, or \c false to verify a post beacon. 2327 2329 * @param pCmp File comparison parameters to file to verify beacon for. 2328 2330 * @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. 2330 2332 */ 2331 2333 static int audioTestToneVerifyBeacon(PAUDIOTESTVERIFYJOB pVerJob, … … 2392 2394 fPre ? "Pre" : "Post", cbBeacon ? "found" : "not found", cbBeacon, cbBeaconExpected); 2393 2395 AssertRC(rc2); 2396 return VERR_NOT_FOUND; 2394 2397 } 2395 2398 else … … 2461 2464 * Start with most obvious methods first. 2462 2465 */ 2463 uint64_t cb SizeA, cbSizeB;2464 rc = RTFileQuerySize(ObjA.File.hFile, &cb SizeA);2465 AssertRCReturn(rc, rc); 2466 rc = RTFileQuerySize(ObjB.File.hFile, &cb SizeB);2467 AssertRCReturn(rc, rc); 2468 2469 if (!cb SizeA)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) 2470 2473 { 2471 2474 int rc2 = audioTestErrorDescAddError(pVerJob->pErr, pVerJob->idxTest, "File '%s' is empty", ObjA.szName); … … 2473 2476 } 2474 2477 2475 if (!cb SizeB)2478 if (!cbFileSizeB) 2476 2479 { 2477 2480 int rc2 = audioTestErrorDescAddError(pVerJob->pErr, pVerJob->idxTest, "File '%s' is empty", ObjB.szName); … … 2479 2482 } 2480 2483 2481 if (cb SizeA != cbSizeB)2482 { 2483 size_t const cbDiffAbs = cb SizeA > cbSizeB ? cbSizeA - cbSizeB : cbSizeB - cbSizeA;2484 if (cbFileSizeA != cbFileSizeB) 2485 { 2486 size_t const cbDiffAbs = cbFileSizeA > cbFileSizeB ? cbFileSizeA - cbFileSizeB : cbFileSizeB - cbFileSizeA; 2484 2487 2485 2488 int rc2 = audioTestErrorDescAddInfo(pVerJob->pErr, pVerJob->idxTest, "File '%s': %zu bytes (%RU64ms)", 2486 ObjA.szName, cb SizeA, PDMAudioPropsBytesToMilli(&pVerJob->PCMProps, cbSizeA));2489 ObjA.szName, cbFileSizeA, PDMAudioPropsBytesToMilli(&pVerJob->PCMProps, cbFileSizeA)); 2487 2490 AssertRC(rc2); 2488 2491 rc2 = audioTestErrorDescAddInfo(pVerJob->pErr, pVerJob->idxTest, "File '%s': %zu bytes (%RU64ms)", 2489 ObjB.szName, cb SizeB, PDMAudioPropsBytesToMilli(&pVerJob->PCMProps, cbSizeB));2492 ObjB.szName, cbFileSizeB, PDMAudioPropsBytesToMilli(&pVerJob->PCMProps, cbFileSizeB)); 2490 2493 AssertRC(rc2); 2491 2494 2492 2495 uint8_t const uSizeDiffPercentAbs 2493 = cb SizeA > cbSizeB ? 100 - ((cbSizeB * 100) / cbSizeA) : 100 - ((cbSizeA * 100) / cbSizeB);2496 = cbFileSizeA > cbFileSizeB ? 100 - ((cbFileSizeB * 100) / cbFileSizeA) : 100 - ((cbFileSizeA * 100) / cbFileSizeB); 2494 2497 2495 2498 if (uSizeDiffPercentAbs > pVerJob->Opts.uMaxSizePercent) … … 2500 2503 uSizeDiffPercentAbs, 2501 2504 cbDiffAbs, PDMAudioPropsBytesToMilli(&pVerJob->PCMProps, (uint32_t)cbDiffAbs), 2502 cb SizeA > cbSizeB ? "bigger" : "smaller",2505 cbFileSizeA > cbFileSizeB ? "bigger" : "smaller", 2503 2506 ObjB.szName, pVerJob->Opts.uMaxSizePercent); 2504 2507 AssertRC(rc2); … … 2526 2529 FileA.pszName = ObjA.szName; 2527 2530 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); 2533 2536 2534 2537 AUDIOTESTTONEPARMS ToneParmsB; … … 2540 2543 FileB.pszName = ObjB.szName; 2541 2544 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); 2547 2550 2548 2551 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 } 2579 2581 } 2580 2582
Note:
See TracChangeset
for help on using the changeset viewer.