VirtualBox

Changeset 94993 in vbox


Ignore:
Timestamp:
May 12, 2022 1:57:54 PM (3 years ago)
Author:
vboxsync
svn:sync-xref-src-repo-rev:
151418
Message:

Audio: Resolved @todos regarding PDMAudioPropsAreValid() / AudioHlpPcmPropsAreValid():

  • Renamed AudioHlpPcmPropsAreValid() -> AudioHlpPcmPropsAreValidAndSupported().
  • Don't assert when not supported or invalid (i.e. not set) but just return false. The caller now is responsible for asserting now, if needed.
  • Also added unsigned samples support to AudioHlpPcmPropsAreValidAndSupported().
Location:
trunk
Files:
8 edited

Legend:

Unmodified
Added
Removed
  • trunk/include/VBox/vmm/pdmaudioinline.h

    r93115 r94993  
    11501150 * @param   pProps  The PCM properties to check.
    11511151 *
    1152  * @remarks This just performs a generic check of value ranges.  Further, it
    1153  *          will assert if the input is invalid.
     1152 * @remarks This just performs a generic check of value ranges.
    11541153 *
    11551154 * @sa      PDMAudioStrmCfgIsValid
     
    11591158    AssertPtrReturn(pProps, false);
    11601159
    1161     AssertReturn(pProps->cChannelsX != 0, false);
    1162     AssertReturn(pProps->cChannelsX <= PDMAUDIO_MAX_CHANNELS, false);
    1163     AssertMsgReturn(   pProps->cbSampleX == 1 || pProps->cbSampleX == 2 || pProps->cbSampleX == 4  || (pProps->cbSampleX == 8 && pProps->fRaw),
    1164                     ("%u\n", pProps->cbSampleX), false);
    1165     AssertMsgReturn(pProps->cbFrame == pProps->cbSampleX * pProps->cChannelsX,
    1166                     ("cbFrame=%u cbSample=%u cChannels=%u\n", pProps->cbFrame, pProps->cbSampleX, pProps->cChannelsX),
    1167                     false);
    1168     AssertMsgReturn(pProps->uHz >= 1000 && pProps->uHz < 1000000, ("%u\n", pProps->uHz), false);
    1169     AssertMsgReturn(pProps->cShiftX == PDMAUDIOPCMPROPS_MAKE_SHIFT(pProps),
    1170                     ("cShift=%u cbSample=%u cChannels=%u\n", pProps->cShiftX, pProps->cbSampleX, pProps->cChannelsX),
    1171                     false);
    1172     AssertReturn(!pProps->fRaw || (pProps->fSigned && pProps->cbSampleX == sizeof(int64_t)), false);
    1173     return true;
     1160        /* Channels. */
     1161    if (   pProps->cChannelsX != 0
     1162        && pProps->cChannelsX <= PDMAUDIO_MAX_CHANNELS
     1163        /* Sample size. */
     1164        && (   pProps->cbSampleX == 1
     1165            || pProps->cbSampleX == 2
     1166            || pProps->cbSampleX == 4
     1167            || (pProps->cbSampleX == 8 && pProps->fRaw))
     1168        /* Hertz rate. */
     1169        && pProps->uHz >= 1000
     1170        && pProps->uHz < 1000000
     1171        /* Raw format: Here we only support int64_t as sample size currently, if enabled. */
     1172        && (   !pProps->fRaw
     1173            || (pProps->fSigned && pProps->cbSampleX == sizeof(int64_t)))
     1174       )
     1175    {
     1176        /* A few more sanity checks to see if the structure has been properly initialized (via PDMAudioPropsInit[Ex]). */
     1177        AssertMsgReturn(pProps->cShiftX == PDMAUDIOPCMPROPS_MAKE_SHIFT(pProps),
     1178                        ("cShift=%u cbSample=%u cChannels=%u\n", pProps->cShiftX, pProps->cbSampleX, pProps->cChannelsX),
     1179                        false);
     1180        AssertMsgReturn(pProps->cbFrame == pProps->cbSampleX * pProps->cChannelsX,
     1181                        ("cbFrame=%u cbSample=%u cChannels=%u\n", pProps->cbFrame, pProps->cbSampleX, pProps->cChannelsX),
     1182                        false);
     1183
     1184        return true;
     1185    }
     1186
     1187    return false;
    11741188}
    11751189
  • trunk/src/VBox/Devices/Audio/AudioHlp.cpp

    r93115 r94993  
    128128            if (   pCfg->enmDir == PDMAUDIODIR_IN
    129129                || pCfg->enmDir == PDMAUDIODIR_OUT)
    130                 return AudioHlpPcmPropsAreValid(&pCfg->Props);
     130                return AudioHlpPcmPropsAreValidAndSupported(&pCfg->Props);
    131131        }
    132132    }
     
    152152
    153153/**
    154  * Checks whether given PCM properties are valid or not.
    155  *
    156  * @note  This is more of a supported than valid check.  There is code for
    157  *        unsigned samples elsewhere (like DrvAudioHlpClearBuf()), but this
    158  *        function will flag such properties as not valid.
    159  *
    160  * @todo  r=bird: See note and explain properly. Perhaps rename to
    161  *        AudioHlpPcmPropsAreValidAndSupported?
    162  *
    163  * @returns @c true if the properties are valid, @c false if not.
     154 * Checks whether given PCM properties are valid *and* supported by the audio stack or not.
     155 *
     156 * @returns @c true if the properties are valid and supported, @c false if not.
    164157 * @param   pProps      The PCM properties to check.
    165  */
    166 bool AudioHlpPcmPropsAreValid(PCPDMAUDIOPCMPROPS pProps)
     158 *
     159 * @note    Use PDMAudioPropsAreValid() to just check the validation bits.
     160 */
     161bool AudioHlpPcmPropsAreValidAndSupported(PCPDMAUDIOPCMPROPS pProps)
    167162{
    168163    AssertPtrReturn(pProps, false);
    169     AssertReturn(PDMAudioPropsAreValid(pProps), false);
    170 
     164
     165    if (!PDMAudioPropsAreValid(pProps))
     166        return false;
     167
     168    /* Properties seem valid, now check if we actually support those. */
    171169    switch (PDMAudioPropsSampleSize(pProps))
    172170    {
    173171        case 1: /* 8 bit */
    174            if (PDMAudioPropsIsSigned(pProps))
    175                return false;
    176            break;
     172            /* Signed / unsigned. */
     173            break;
    177174        case 2: /* 16 bit */
    178             if (!PDMAudioPropsIsSigned(pProps))
    179                 return false;
     175            /* Signed / unsigned. */
    180176            break;
    181177        /** @todo Do we need support for 24 bit samples? */
    182178        case 4: /* 32 bit */
    183             if (!PDMAudioPropsIsSigned(pProps))
    184                 return false;
     179            /* Signed / unsigned. */
    185180            break;
    186181        case 8: /* 64-bit raw */
  • trunk/src/VBox/Devices/Audio/AudioHlp.h

    r93115 r94993  
    3838/** @name Audio PCM properties helper methods.
    3939 * @{ */
    40 bool     AudioHlpPcmPropsAreValid(PCPDMAUDIOPCMPROPS pProps);
     40bool     AudioHlpPcmPropsAreValidAndSupported(PCPDMAUDIOPCMPROPS pProps);
    4141/** @}  */
    4242
  • trunk/src/VBox/Devices/Audio/AudioMixer.cpp

    r93115 r94993  
    958958    AssertReturn(pSink->uMagic == AUDMIXSINK_MAGIC, VERR_INVALID_MAGIC);
    959959    AssertPtrReturn(pProps, VERR_INVALID_POINTER);
    960     AssertReturn(AudioHlpPcmPropsAreValid(pProps), VERR_INVALID_PARAMETER);
     960    AssertReturn(AudioHlpPcmPropsAreValidAndSupported(pProps), VERR_INVALID_PARAMETER);
    961961
    962962    /*
     
    22872287                 *        mixing.  The mixing is done here and we bridge guest & host configs.)
    22882288                 */
    2289                 AssertMsg(AudioHlpPcmPropsAreValid(&pSink->PCMProps),
    2290                           ("%s: Does not (yet) have a format set when it must\n", pSink->pszName));
     2289                AssertMsg(AudioHlpPcmPropsAreValidAndSupported(&pSink->PCMProps),
     2290                          ("%s: Does not (yet) have a (valid and supported) format set when it must\n", pSink->pszName));
    22912291
    22922292                PDMAUDIOSTREAMCFG CfgHost;
  • trunk/src/VBox/Devices/Audio/DevHdaStream.cpp

    r93115 r94993  
    10561056        && pStreamR3->Dbg.Runtime.fEnabled)
    10571057    {
    1058         Assert(AudioHlpPcmPropsAreValid(&pStreamShared->State.Cfg.Props));
     1058        Assert(AudioHlpPcmPropsAreValidAndSupported(&pStreamShared->State.Cfg.Props));
    10591059
    10601060        if (fEnable)
  • trunk/src/VBox/Devices/Audio/DevSB16.cpp

    r94829 r94993  
    25232523    {
    25242524        /* Sanity: If stream is going be enabled, PCM props must be valid. Otherwise the saved state is borked somehow. */
    2525         AssertMsgReturn(AudioHlpPcmPropsAreValid(&pStream->Cfg.Props),
     2525        AssertMsgReturn(AudioHlpPcmPropsAreValidAndSupported(&pStream->Cfg.Props),
    25262526                        ("PCM properties for stream #%RU8 are invalid\n", pStream->uIdx), VERR_SSM_DATA_UNIT_FORMAT_CHANGED);
    25272527        sb16StreamControl(pDevIns, pThis, pStream, true /* fRun */);
  • trunk/src/VBox/Devices/Audio/DrvAudio.cpp

    r93115 r94993  
    10811081
    10821082    /* Validate PCM properties. */
    1083     if (!AudioHlpPcmPropsAreValid(&pCfg->Props))
     1083    if (!AudioHlpPcmPropsAreValidAndSupported(&pCfg->Props))
    10841084    {
    10851085        LogRel(("Audio: Invalid custom PCM properties set for stream '%s', cannot create stream\n", pszName));
  • trunk/src/VBox/Devices/Audio/testcase/tstAudioMixBuffer.cpp

    r93944 r94993  
    7878    RTTESTI_CHECK(PDMAudioPropsGetBitrate(&Cfg441StereoU32) == 44100*8*8);
    7979
    80     RTTESTI_CHECK(AudioHlpPcmPropsAreValid(&Cfg441StereoS16));
    81     RTTESTI_CHECK(AudioHlpPcmPropsAreValid(&Cfg441StereoU16) == false); /* go figure */
    82     RTTESTI_CHECK(AudioHlpPcmPropsAreValid(&Cfg441StereoU32) == false); /* go figure */
     80    RTTESTI_CHECK(AudioHlpPcmPropsAreValidAndSupported(&Cfg441StereoS16));
     81    RTTESTI_CHECK(AudioHlpPcmPropsAreValidAndSupported(&Cfg441StereoU16) == false); /* go figure */
     82    RTTESTI_CHECK(AudioHlpPcmPropsAreValidAndSupported(&Cfg441StereoU32) == false); /* go figure */
    8383
    8484
     
    210210    );
    211211
    212     RTTESTI_CHECK(AudioHlpPcmPropsAreValid(&config));
     212    RTTESTI_CHECK(AudioHlpPcmPropsAreValidAndSupported(&config));
    213213
    214214    uint32_t cBufSize = _1K;
     
    658658    uint32_t const         cFrames = RTRandU32Ex(16, RT_ELEMENTS(aSrcFrames));
    659659    PDMAUDIOPCMPROPS const CfgSrc  = PDMAUDIOPCMPROPS_INITIALIZER(2 /*cbSample*/, true /*fSigned*/, 2 /*ch*/, uFromHz, false /*fSwap*/);
    660     RTTESTI_CHECK(AudioHlpPcmPropsAreValid(&CfgSrc));
     660    RTTESTI_CHECK(AudioHlpPcmPropsAreValidAndSupported(&CfgSrc));
    661661    AUDIOMIXBUF MixBuf;
    662662    RTTESTI_CHECK_RC_OK_RETV(AudioMixBufInit(&MixBuf, "NewPeekMixBuf", &CfgSrc, cFrames));
     
    668668    /* Peek state (destination) is uToHz 2ch S16 */
    669669    PDMAUDIOPCMPROPS const CfgDst = PDMAUDIOPCMPROPS_INITIALIZER(2 /*cbSample*/, true /*fSigned*/, 2 /*ch*/, uToHz, false /*fSwap*/);
    670     RTTESTI_CHECK(AudioHlpPcmPropsAreValid(&CfgDst));
     670    RTTESTI_CHECK(AudioHlpPcmPropsAreValidAndSupported(&CfgDst));
    671671    AUDIOMIXBUFPEEKSTATE PeekState;
    672672    RTTESTI_CHECK_RC_OK_RETV(AudioMixBufInitPeekState(&MixBuf, &PeekState, &CfgDst));
Note: See TracChangeset for help on using the changeset viewer.

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