Changeset 92195 in vbox for trunk/src/VBox/ValidationKit/utils
- Timestamp:
- Nov 3, 2021 5:27:10 PM (3 years ago)
- svn:sync-xref-src-repo-rev:
- 148025
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/ValidationKit/utils/audio/vkatCommon.cpp
r92058 r92195 525 525 uint32_t cbPlayedTotal = 0; 526 526 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); 533 533 if (cbBeacon) 534 534 { 535 RTTestPrintf(g_hTest, RTTESTLVL_ALWAYS, "Playing 2 x %RU32 bytes pre/post beacons\n", cbBeacon ToPlay);535 RTTestPrintf(g_hTest, RTTESTLVL_ALWAYS, "Playing 2 x %RU32 bytes pre/post beacons\n", cbBeacon); 536 536 cbToPlayTotal += cbBeacon * 2 /* Pre + post beacon */; 537 537 } … … 539 539 if (pTstEnv) 540 540 { 541 AudioTestObjAddMetadataStr(Obj, "beacon_type=%RU32\n", (uint32_t)AudioTestBeaconGetType(&Beacon)); 541 542 AudioTestObjAddMetadataStr(Obj, "beacon_pre_bytes=%RU32\n", cbBeacon); 542 543 AudioTestObjAddMetadataStr(Obj, "beacon_post_bytes=%RU32\n", cbBeacon); … … 591 592 592 593 /* Any beacon to play? */ 593 if ( cbBeaconToPlay594 && cbBeaconPlayed < cbBeaconToPlay)594 uint32_t const cbBeaconRemaining = AudioTestBeaconGetRemaining(&Beacon); 595 if (cbBeaconRemaining) 595 596 { 596 597 /* 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); 603 602 if (RT_FAILURE(rc)) 604 603 break; … … 611 610 rc = AudioTestObjWrite(Obj, abBuf, cbPlayed); 612 611 } 613 614 cbBeaconPlayed += cbPlayed;615 cbPlayedTotal += cbPlayed;616 continue;617 612 } 618 619 /* Start playing the post beacon? */ 620 if (cbPlayedTotal == cbToPlayTotal - cbBeaconToPlay) 613 else /* Play test tone */ 621 614 { 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? */ 635 617 { 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; 638 625 } 626 627 uint32_t const cbToGenerate = RT_MIN(RT_MIN(cbTestToneToPlay, sizeof(abBuf)), cbCanWrite); 628 rc = AudioTestToneGenerate(&TstTone, abBuf, cbToGenerate, &cbToPlay); 639 629 if (RT_SUCCESS(rc)) 640 630 { 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 } 642 636 if (RT_SUCCESS(rc)) 643 637 { 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 } 653 651 } 654 652 } … … 746 744 if (RT_SUCCESS(rc)) 747 745 { 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); 753 755 if (cbBeacon) 754 756 { 755 RTTestPrintf(g_hTest, RTTESTLVL_ALWAYS, " Recording 2 x %RU32 bytes pre/post beacons\n", cbBeacon);756 cbT oRecTotal += 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", cbT oRecTotal);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); 763 765 AudioTestObjAddMetadataStr(Obj, "stream_buffer_size_ms=%RU32\n", pIoOpts->cMsBufferSize); 764 766 AudioTestObjAddMetadataStr(Obj, "stream_prebuf_size_ms=%RU32\n", pIoOpts->cMsPreBuffer); … … 767 769 AudioTestObjAddMetadataStr(Obj, "device_scheduling_hint_ms=%RU32\n", pIoOpts->cMsSchedulingHint); 768 770 769 RTTestPrintf(g_hTest, RTTESTLVL_DEBUG, "Recording %RU32 bytes total\n", cbT oRecTotal);771 RTTestPrintf(g_hTest, RTTESTLVL_DEBUG, "Recording %RU32 bytes total\n", cbTestToRec); 770 772 771 773 uint8_t abSamples[16384]; 772 uint32_t const cbSamplesAligned = PDMAudioPropsFloorBytesToFrame(pMix->pProps, sizeof(abSamples));773 uint64_t cb RecTotal= 0;774 uint32_t const cbSamplesAligned = PDMAudioPropsFloorBytesToFrame(pMix->pProps, sizeof(abSamples)); 775 uint64_t cbTestRec = 0; 774 776 775 777 uint64_t const nsStarted = RTTimeNanoTS(); … … 778 780 uint64_t nsLastMsgCantRead = 0; /* Timestamp (in ns) when the last message of an unreadable stream was shown. */ 779 781 780 while (!g_fTerminate && cb RecTotal < cbToRecTotal)782 while (!g_fTerminate && cbTestRec < cbTestToRec) 781 783 { 782 784 uint64_t const nsNow = RTTimeNanoTS(); … … 799 801 if (cbRecorded) 800 802 { 803 cbRecTotal += cbRecorded; 804 801 805 rc = AudioTestObjWrite(Obj, abSamples, cbRecorded); 802 806 if (RT_SUCCESS(rc)) 803 807 { 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 } 807 845 } 808 846 } … … 836 874 } 837 875 838 if (cb RecTotal != cbToRecTotal)839 RTTestFailed(g_hTest, "Recording ended unexpectedly (%RU32/%RU32 recorded)\n", cb RecTotal, cbToRecTotal);876 if (cbTestRec != cbTestToRec) 877 RTTestFailed(g_hTest, "Recording ended unexpectedly (%RU32/%RU32 recorded)\n", cbTestRec, cbTestToRec); 840 878 841 879 int rc2 = AudioTestMixStreamDisable(pMix);
Note:
See TracChangeset
for help on using the changeset viewer.