VirtualBox

Changeset 88004 in vbox


Ignore:
Timestamp:
Mar 8, 2021 11:55:51 AM (4 years ago)
Author:
vboxsync
Message:

Audio: DrvAudioHlpBytesIsAligned -> DrvAudioHlpIsBytesAligned; switched parameters, added div/0 check. bugref:9890

Location:
trunk/src/VBox/Devices/Audio
Files:
5 edited

Legend:

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

    r88002 r88004  
    940940               pStream->szName, DrvAudioHlpAudDirToStr(pStream->enmDir)));
    941941
    942     AssertMsg(DrvAudioHlpBytesIsAligned(cbBuf, &pStream->Guest.Cfg.Props),
     942    AssertMsg(DrvAudioHlpIsBytesAligned(cbBuf, &pStream->Guest.Cfg.Props),
    943943              ("Stream '%s' got a non-frame-aligned write (%RU32 bytes)\n", pStream->szName, cbBuf));
    944944
  • trunk/src/VBox/Devices/Audio/DrvAudio.h

    r88003 r88004  
    199199uint32_t DrvAudioHlpGetBitrate(PCPDMAUDIOPCMPROPS pProps);
    200200uint32_t DrvAudioHlpBytesAlign(uint32_t cbSize, PCPDMAUDIOPCMPROPS pProps);
    201 bool     DrvAudioHlpBytesIsAligned(uint32_t cbSize, PCPDMAUDIOPCMPROPS pProps);
     201bool     DrvAudioHlpIsBytesAligned(PCPDMAUDIOPCMPROPS pProps, uint32_t cb);
    202202uint32_t DrvAudioHlpBytesToFrames(uint32_t cbBytes, PCPDMAUDIOPCMPROPS pProps);
    203203uint64_t DrvAudioHlpBytesToMilli(PCPDMAUDIOPCMPROPS pProps, uint32_t cb);
  • trunk/src/VBox/Devices/Audio/DrvAudioCommon.cpp

    r88003 r88004  
    11771177
    11781178/**
    1179  * Returns if the the given size is properly aligned to the given PCM properties.
    1180  *
    1181  * @return  @c true if properly aligned, @c false if not.
    1182  * @param   cbSize              Size (in bytes) to check alignment for.
    1183  * @param   pProps              PCM properties to use for checking the alignment.
    1184  */
    1185 bool DrvAudioHlpBytesIsAligned(uint32_t cbSize, PCPDMAUDIOPCMPROPS pProps)
    1186 {
    1187     AssertPtrReturn(pProps, 0);
    1188 
    1189     if (!cbSize)
    1190         return true;
    1191 
    1192     return (cbSize % PDMAUDIOPCMPROPS_F2B(pProps, 1 /* Frame */) == 0);
     1179 * Checks if the given size is aligned on a frame boundrary.
     1180 *
     1181 * @returns @c true if properly aligned, @c false if not.
     1182 * @param   pProps      PCM properties to use.
     1183 * @param   cb          The size (in bytes) to check.
     1184 */
     1185bool DrvAudioHlpIsBytesAligned(PCPDMAUDIOPCMPROPS pProps, uint32_t cb)
     1186{
     1187    AssertPtrReturn(pProps, false);
     1188    uint32_t const cbFrame = PDMAUDIOPCMPROPS_F2B(pProps, 1 /* Frame */);
     1189    AssertReturn(cbFrame, false);
     1190    return cb % cbFrame == 0;
    11931191}
    11941192
  • trunk/src/VBox/Devices/Audio/HDAStream.cpp

    r88002 r88004  
    532532        if (cbTransferHeuristics >= 8)
    533533        {
    534             ASSERT_GUEST_LOGREL_MSG(DrvAudioHlpBytesIsAligned(cbTransferHeuristics, &pStreamR3->State.Mapping.PCMProps),
     534            ASSERT_GUEST_LOGREL_MSG(DrvAudioHlpIsBytesAligned(cbTransferHeuristics, &pStreamR3->State.Mapping.PCMProps),
    535535                                    ("We arrived at a misaligned transfer size for stream #%RU8: %#x (%u)\n",
    536536                                     uSD, cbTransferHeuristics, cbTransferHeuristics));
     
    549549            pStreamShared->State.cbTransferSize  = cbTransferHeuristics;
    550550            pStreamShared->State.cbTransferChunk = cbTransferHeuristics;
    551             ASSERT_GUEST_LOGREL_MSG(DrvAudioHlpBytesIsAligned(cbTransferHeuristics, &pStreamR3->State.Mapping.PCMProps),
     551            ASSERT_GUEST_LOGREL_MSG(DrvAudioHlpIsBytesAligned(cbTransferHeuristics, &pStreamR3->State.Mapping.PCMProps),
    552552                                    ("We arrived at a misaligned transfer size for stream #%RU8: %#x (%u)\n",
    553553                                     uSD, cbTransferHeuristics, cbTransferHeuristics));
  • trunk/src/VBox/Devices/Audio/testcase/tstAudioMixBuffer.cpp

    r88003 r88004  
    7171    RTTESTI_CHECK_MSG(PDMAUDIOPCMPROPS_F2B(&s_Cfg441StereoU32, 1) == 8,
    7272                      ("got %x, expected 4\n", PDMAUDIOPCMPROPS_F2B(&s_Cfg441StereoU32, 1)));
     73
     74    for (uint32_t i = 0; i < 256; i += 8)
     75    {
     76        RTTESTI_CHECK(DrvAudioHlpIsBytesAligned(&s_Cfg441StereoU32, i) == true);
     77        RTTESTI_CHECK(DrvAudioHlpIsBytesAligned(&s_Cfg441StereoU32, i+1) == false);
     78        RTTESTI_CHECK(DrvAudioHlpIsBytesAligned(&s_Cfg441StereoU32, i+2) == false);
     79        RTTESTI_CHECK(DrvAudioHlpIsBytesAligned(&s_Cfg441StereoU32, i+3) == false);
     80        RTTESTI_CHECK(DrvAudioHlpIsBytesAligned(&s_Cfg441StereoU32, i+4) == false);
     81        RTTESTI_CHECK(DrvAudioHlpIsBytesAligned(&s_Cfg441StereoU32, i+5) == false);
     82        RTTESTI_CHECK(DrvAudioHlpIsBytesAligned(&s_Cfg441StereoU32, i+6) == false);
     83        RTTESTI_CHECK(DrvAudioHlpIsBytesAligned(&s_Cfg441StereoU32, i+7) == false);
     84    }
     85    for (uint32_t i = 0; i < 4096; i += 4)
     86    {
     87        RTTESTI_CHECK(DrvAudioHlpIsBytesAligned(&s_Cfg441StereoS16, i) == true);
     88        RTTESTI_CHECK(DrvAudioHlpIsBytesAligned(&s_Cfg441StereoS16, i+1) == false);
     89        RTTESTI_CHECK(DrvAudioHlpIsBytesAligned(&s_Cfg441StereoS16, i+2) == false);
     90        RTTESTI_CHECK(DrvAudioHlpIsBytesAligned(&s_Cfg441StereoS16, i+3) == false);
     91    }
    7392
    7493    uint32_t u32;
Note: See TracChangeset for help on using the changeset viewer.

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette