diff options
author | vboxsync <vboxsync@cfe28804-0f27-0410-a406-dd0f0b0b656f> | 2021-03-08 11:55:51 +0000 |
---|---|---|
committer | vboxsync <vboxsync@cfe28804-0f27-0410-a406-dd0f0b0b656f> | 2021-03-08 11:55:51 +0000 |
commit | a241b443a825d7ce33487f311baf68d20394a0a7 (patch) | |
tree | 8a7ef3e63fdac74100630b40c1849fbe581e0b28 /src/VBox | |
parent | 24992eb336b4c9a7065d3088924d30534b334bb1 (diff) | |
download | VirtualBox-svn-a241b443a825d7ce33487f311baf68d20394a0a7.tar.gz |
Audio: DrvAudioHlpBytesIsAligned -> DrvAudioHlpIsBytesAligned; switched parameters, added div/0 check. bugref:9890
git-svn-id: https://www.virtualbox.org/svn/vbox/trunk@88004 cfe28804-0f27-0410-a406-dd0f0b0b656f
Diffstat (limited to 'src/VBox')
-rw-r--r-- | src/VBox/Devices/Audio/DrvAudio.cpp | 2 | ||||
-rw-r--r-- | src/VBox/Devices/Audio/DrvAudio.h | 2 | ||||
-rw-r--r-- | src/VBox/Devices/Audio/DrvAudioCommon.cpp | 20 | ||||
-rw-r--r-- | src/VBox/Devices/Audio/HDAStream.cpp | 4 | ||||
-rw-r--r-- | src/VBox/Devices/Audio/testcase/tstAudioMixBuffer.cpp | 19 |
5 files changed, 32 insertions, 15 deletions
diff --git a/src/VBox/Devices/Audio/DrvAudio.cpp b/src/VBox/Devices/Audio/DrvAudio.cpp index 5713a1dac14..c7c416c0afd 100644 --- a/src/VBox/Devices/Audio/DrvAudio.cpp +++ b/src/VBox/Devices/Audio/DrvAudio.cpp @@ -939,7 +939,7 @@ static DECLCALLBACK(int) drvAudioStreamWrite(PPDMIAUDIOCONNECTOR pInterface, PPD ("Stream '%s' is not an output stream and therefore cannot be written to (direction is '%s')\n", pStream->szName, DrvAudioHlpAudDirToStr(pStream->enmDir))); - AssertMsg(DrvAudioHlpBytesIsAligned(cbBuf, &pStream->Guest.Cfg.Props), + AssertMsg(DrvAudioHlpIsBytesAligned(cbBuf, &pStream->Guest.Cfg.Props), ("Stream '%s' got a non-frame-aligned write (%RU32 bytes)\n", pStream->szName, cbBuf)); uint32_t cbWrittenTotal = 0; diff --git a/src/VBox/Devices/Audio/DrvAudio.h b/src/VBox/Devices/Audio/DrvAudio.h index fe7d569fd85..8b82b33881b 100644 --- a/src/VBox/Devices/Audio/DrvAudio.h +++ b/src/VBox/Devices/Audio/DrvAudio.h @@ -198,7 +198,7 @@ void DrvAudioHlpClearBuf(PCPDMAUDIOPCMPROPS pPCMProps, void *pvBuf, size_t c uint32_t DrvAudioHlpCalcBitrate(uint8_t cBits, uint32_t uHz, uint8_t cChannels); uint32_t DrvAudioHlpGetBitrate(PCPDMAUDIOPCMPROPS pProps); uint32_t DrvAudioHlpBytesAlign(uint32_t cbSize, PCPDMAUDIOPCMPROPS pProps); -bool DrvAudioHlpBytesIsAligned(uint32_t cbSize, PCPDMAUDIOPCMPROPS pProps); +bool DrvAudioHlpIsBytesAligned(PCPDMAUDIOPCMPROPS pProps, uint32_t cb); uint32_t DrvAudioHlpBytesToFrames(uint32_t cbBytes, PCPDMAUDIOPCMPROPS pProps); uint64_t DrvAudioHlpBytesToMilli(PCPDMAUDIOPCMPROPS pProps, uint32_t cb); uint64_t DrvAudioHlpBytesToMicro(PCPDMAUDIOPCMPROPS pProps, uint32_t cb); diff --git a/src/VBox/Devices/Audio/DrvAudioCommon.cpp b/src/VBox/Devices/Audio/DrvAudioCommon.cpp index b508b0229b4..6ee39c9831b 100644 --- a/src/VBox/Devices/Audio/DrvAudioCommon.cpp +++ b/src/VBox/Devices/Audio/DrvAudioCommon.cpp @@ -1176,20 +1176,18 @@ uint32_t DrvAudioHlpBytesAlign(uint32_t cbSize, PCPDMAUDIOPCMPROPS pProps) } /** - * Returns if the the given size is properly aligned to the given PCM properties. + * Checks if the given size is aligned on a frame boundrary. * - * @return @c true if properly aligned, @c false if not. - * @param cbSize Size (in bytes) to check alignment for. - * @param pProps PCM properties to use for checking the alignment. + * @returns @c true if properly aligned, @c false if not. + * @param pProps PCM properties to use. + * @param cb The size (in bytes) to check. */ -bool DrvAudioHlpBytesIsAligned(uint32_t cbSize, PCPDMAUDIOPCMPROPS pProps) +bool DrvAudioHlpIsBytesAligned(PCPDMAUDIOPCMPROPS pProps, uint32_t cb) { - AssertPtrReturn(pProps, 0); - - if (!cbSize) - return true; - - return (cbSize % PDMAUDIOPCMPROPS_F2B(pProps, 1 /* Frame */) == 0); + AssertPtrReturn(pProps, false); + uint32_t const cbFrame = PDMAUDIOPCMPROPS_F2B(pProps, 1 /* Frame */); + AssertReturn(cbFrame, false); + return cb % cbFrame == 0; } /** diff --git a/src/VBox/Devices/Audio/HDAStream.cpp b/src/VBox/Devices/Audio/HDAStream.cpp index 32719fe9376..bdce644fc11 100644 --- a/src/VBox/Devices/Audio/HDAStream.cpp +++ b/src/VBox/Devices/Audio/HDAStream.cpp @@ -531,7 +531,7 @@ int hdaR3StreamSetUp(PPDMDEVINS pDevIns, PHDASTATE pThis, PHDASTREAM pStreamShar /* Paranoia (fall back on I/O timer Hz if this happens). */ if (cbTransferHeuristics >= 8) { - ASSERT_GUEST_LOGREL_MSG(DrvAudioHlpBytesIsAligned(cbTransferHeuristics, &pStreamR3->State.Mapping.PCMProps), + ASSERT_GUEST_LOGREL_MSG(DrvAudioHlpIsBytesAligned(cbTransferHeuristics, &pStreamR3->State.Mapping.PCMProps), ("We arrived at a misaligned transfer size for stream #%RU8: %#x (%u)\n", uSD, cbTransferHeuristics, cbTransferHeuristics)); @@ -548,7 +548,7 @@ int hdaR3StreamSetUp(PPDMDEVINS pDevIns, PHDASTATE pThis, PHDASTREAM pStreamShar /* Set the transfer size per timer callout. (No chunking, so same.) */ pStreamShared->State.cbTransferSize = cbTransferHeuristics; pStreamShared->State.cbTransferChunk = cbTransferHeuristics; - ASSERT_GUEST_LOGREL_MSG(DrvAudioHlpBytesIsAligned(cbTransferHeuristics, &pStreamR3->State.Mapping.PCMProps), + ASSERT_GUEST_LOGREL_MSG(DrvAudioHlpIsBytesAligned(cbTransferHeuristics, &pStreamR3->State.Mapping.PCMProps), ("We arrived at a misaligned transfer size for stream #%RU8: %#x (%u)\n", uSD, cbTransferHeuristics, cbTransferHeuristics)); diff --git a/src/VBox/Devices/Audio/testcase/tstAudioMixBuffer.cpp b/src/VBox/Devices/Audio/testcase/tstAudioMixBuffer.cpp index 5c642206efa..d17e5966e1b 100644 --- a/src/VBox/Devices/Audio/testcase/tstAudioMixBuffer.cpp +++ b/src/VBox/Devices/Audio/testcase/tstAudioMixBuffer.cpp @@ -71,6 +71,25 @@ static void tstBasics(RTTEST hTest) RTTESTI_CHECK_MSG(PDMAUDIOPCMPROPS_F2B(&s_Cfg441StereoU32, 1) == 8, ("got %x, expected 4\n", PDMAUDIOPCMPROPS_F2B(&s_Cfg441StereoU32, 1))); + for (uint32_t i = 0; i < 256; i += 8) + { + RTTESTI_CHECK(DrvAudioHlpIsBytesAligned(&s_Cfg441StereoU32, i) == true); + RTTESTI_CHECK(DrvAudioHlpIsBytesAligned(&s_Cfg441StereoU32, i+1) == false); + RTTESTI_CHECK(DrvAudioHlpIsBytesAligned(&s_Cfg441StereoU32, i+2) == false); + RTTESTI_CHECK(DrvAudioHlpIsBytesAligned(&s_Cfg441StereoU32, i+3) == false); + RTTESTI_CHECK(DrvAudioHlpIsBytesAligned(&s_Cfg441StereoU32, i+4) == false); + RTTESTI_CHECK(DrvAudioHlpIsBytesAligned(&s_Cfg441StereoU32, i+5) == false); + RTTESTI_CHECK(DrvAudioHlpIsBytesAligned(&s_Cfg441StereoU32, i+6) == false); + RTTESTI_CHECK(DrvAudioHlpIsBytesAligned(&s_Cfg441StereoU32, i+7) == false); + } + for (uint32_t i = 0; i < 4096; i += 4) + { + RTTESTI_CHECK(DrvAudioHlpIsBytesAligned(&s_Cfg441StereoS16, i) == true); + RTTESTI_CHECK(DrvAudioHlpIsBytesAligned(&s_Cfg441StereoS16, i+1) == false); + RTTESTI_CHECK(DrvAudioHlpIsBytesAligned(&s_Cfg441StereoS16, i+2) == false); + RTTESTI_CHECK(DrvAudioHlpIsBytesAligned(&s_Cfg441StereoS16, i+3) == false); + } + uint32_t u32; RTTESTI_CHECK_MSG((u32 = DrvAudioHlpFramesToBytes(&s_Cfg441StereoS16, 44100)) == 44100 * 2 * 2, ("cb=%RU32\n", u32)); |