Changeset 92211 in vbox for trunk/src/VBox/ValidationKit
- Timestamp:
- Nov 4, 2021 2:15:01 PM (3 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/ValidationKit/utils/audio/vkatCommon.cpp
r92195 r92211 744 744 if (RT_SUCCESS(rc)) 745 745 { 746 uint64_t cbRecTotal = 0; /* Counts everything, including silence / whatever. */ 747 uint64_t cbTestToRec = PDMAudioPropsMilliToBytes(&pStream->Cfg.Props, pParms->msDuration); 746 uint32_t cbRecTotal = 0; /* Counts everything, including silence / whatever. */ 747 uint32_t cbTestToRec = PDMAudioPropsMilliToBytes(&pStream->Cfg.Props, pParms->msDuration); 748 uint32_t cbTestRec = 0; 749 750 RTTestPrintf(g_hTest, RTTESTLVL_ALWAYS, "Recording %RU32 bytes total\n", cbTestToRec); 748 751 749 752 /* We expect a pre + post beacon before + after the actual test tone. … … 754 757 uint32_t const cbBeacon = AudioTestBeaconGetSize(&Beacon); 755 758 if (cbBeacon) 756 {757 759 RTTestPrintf(g_hTest, RTTESTLVL_ALWAYS, "Expecting 2 x %RU32 bytes pre/post beacons\n", cbBeacon); 758 cbTestToRec = cbBeacon * 2 /* Pre + post beacon */;759 }760 760 761 761 AudioTestObjAddMetadataStr(Obj, "beacon_type=%RU32\n", (uint32_t)AudioTestBeaconGetType(&Beacon)); … … 769 769 AudioTestObjAddMetadataStr(Obj, "device_scheduling_hint_ms=%RU32\n", pIoOpts->cMsSchedulingHint); 770 770 771 RTTestPrintf(g_hTest, RTTESTLVL_DEBUG, "Recording %RU32 bytes total\n", cbTestToRec);772 773 771 uint8_t abSamples[16384]; 774 772 uint32_t const cbSamplesAligned = PDMAudioPropsFloorBytesToFrame(pMix->pProps, sizeof(abSamples)); 775 uint64_t cbTestRec = 0;776 773 777 774 uint64_t const nsStarted = RTTimeNanoTS(); … … 780 777 uint64_t nsLastMsgCantRead = 0; /* Timestamp (in ns) when the last message of an unreadable stream was shown. */ 781 778 782 while (!g_fTerminate && cbTestRec < cbTestToRec) 779 AUDIOTESTSTATE enmState = AUDIOTESTSTATE_PRE; 780 781 while (!g_fTerminate) 783 782 { 784 783 uint64_t const nsNow = RTTimeNanoTS(); … … 799 798 if (RT_SUCCESS(rc)) 800 799 { 801 if (cbRecorded) 800 /* Flag indicating whether the whole block we're going to play is silence or not. */ 801 bool const fIsAllSilence = PDMAudioPropsIsBufferSilence(&pStream->pStream->Cfg.Props, abSamples, cbRecorded); 802 803 cbRecTotal += cbRecorded; /* Do a bit of accounting. */ 804 805 /* Always write (record) everything, no matter if the current audio contains complete silence or not. 806 * Might be also become handy later if we want to have a look at start/stop timings and so on. */ 807 rc = AudioTestObjWrite(Obj, abSamples, cbRecorded); 808 AssertRCBreak(rc); 809 810 switch (enmState) 802 811 { 803 cbRecTotal += cbRecorded; 804 805 rc = AudioTestObjWrite(Obj, abSamples, cbRecorded); 806 if (RT_SUCCESS(rc)) 812 case AUDIOTESTSTATE_PRE: 813 RT_FALL_THROUGH(); 814 case AUDIOTESTSTATE_POST: 807 815 { 808 if (AudioTestBeaconGetSize(&Beacon)) 816 if ( AudioTestBeaconGetSize(&Beacon) 817 && !AudioTestBeaconIsComplete(&Beacon)) 809 818 { 810 if (!AudioTestBeaconIsComplete(&Beacon)) 819 bool const fStarted = AudioTestBeaconGetRemaining(&Beacon) == AudioTestBeaconGetSize(&Beacon); 820 821 /* Limit adding data to the beacon size. */ 822 uint32_t const cbToAddMax = RT_MIN(cbRecorded, AudioTestBeaconGetRemaining(&Beacon)); 823 824 AudioTestBeaconAddConsecutive(&Beacon, abSamples, cbToAddMax); 825 /** @todo Take left-over data into account (and stash them away for the test tone)? */ 826 827 if ( fStarted 828 && g_uVerbosity >= 2) 829 RTTestPrintf(g_hTest, RTTESTLVL_ALWAYS, 830 "Detection of %s beacon started (%RU32ms recorded so far)\n", 831 AudioTestBeaconTypeGetName(Beacon.enmType), 832 PDMAudioPropsBytesToMilli(&pStream->pStream->Cfg.Props, cbRecTotal)); 833 834 if (AudioTestBeaconIsComplete(&Beacon)) 811 835 { 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; 836 if (g_uVerbosity >= 2) 837 RTTestPrintf(g_hTest, RTTESTLVL_ALWAYS, "Detection of %s beacon ended\n", 838 AudioTestBeaconTypeGetName(Beacon.enmType)); 839 840 if (enmState == AUDIOTESTSTATE_PRE) 841 enmState = AUDIOTESTSTATE_RUN; 842 else if (enmState == AUDIOTESTSTATE_POST) 843 enmState = AUDIOTESTSTATE_DONE; 843 844 } 844 845 } 846 break; 845 847 } 848 849 case AUDIOTESTSTATE_RUN: 850 { 851 /* Whether we count all silence as recorded data or not. 852 * Currently we don't, as otherwise consequtively played tones will be cut off in the end. */ 853 if (!fIsAllSilence) 854 cbTestRec += cbRecorded; 855 856 if (cbTestToRec - cbTestRec == 0) /* Done recording the test tone? */ 857 { 858 enmState = AUDIOTESTSTATE_POST; 859 /* Re-use the beacon object, but this time it's the post beacon. */ 860 AudioTestBeaconInit(&Beacon, AUDIOTESTTONEBEACONTYPE_PLAY_POST, &pStream->Cfg.Props); 861 } 862 } 863 864 case AUDIOTESTSTATE_DONE: 865 { 866 /* Nothing to do here. */ 867 break; 868 } 869 870 default: 871 AssertFailed(); 872 break; 846 873 } 847 874 } 875 876 if (enmState == AUDIOTESTSTATE_DONE) 877 break; 848 878 } 849 879 else if (AudioTestMixStreamIsOkay(pMix)) … … 874 904 } 875 905 906 if (g_uVerbosity >= 2) 907 RTTestPrintf(g_hTest, RTTESTLVL_ALWAYS, "Recorded %RU32 bytes total\n", cbRecTotal); 876 908 if (cbTestRec != cbTestToRec) 909 { 877 910 RTTestFailed(g_hTest, "Recording ended unexpectedly (%RU32/%RU32 recorded)\n", cbTestRec, cbTestToRec); 911 rc = VERR_WRONG_ORDER; /** @todo Find a better rc. */ 912 } 913 914 if (RT_FAILURE(rc)) 915 RTTestFailed(g_hTest, "Recording failed (state is '%s')\n", AudioTestStateToStr(enmState)); 878 916 879 917 int rc2 = AudioTestMixStreamDisable(pMix);
Note:
See TracChangeset
for help on using the changeset viewer.