VirtualBox

Changeset 89564 in vbox


Ignore:
Timestamp:
Jun 8, 2021 9:24:27 AM (4 years ago)
Author:
vboxsync
Message:

DrvAudio: Change the default for cFramesPeriod to be 1/4 of the buffer size instead of a fixed 150ms. Don't fail on misconfigured period/buffer/pre-buffer size relationships, just adjust and continue. bugref:9890

File:
1 edited

Legend:

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

    r89556 r89564  
    10911091
    10921092    /*
     1093     * Buffer size
     1094     */
     1095    const char *pszWhat = "device-specific";
     1096    if (pDrvCfg->uBufferSizeMs)
     1097    {
     1098        pCfg->Backend.cFramesBufferSize = PDMAudioPropsMilliToFrames(&pCfg->Props, pDrvCfg->uBufferSizeMs);
     1099        pszWhat = "custom";
     1100    }
     1101
     1102    if (!pCfg->Backend.cFramesBufferSize) /* Set default buffer size if nothing explicitly is set. */
     1103    {
     1104        pCfg->Backend.cFramesBufferSize = PDMAudioPropsMilliToFrames(&pCfg->Props, 300 /*ms*/);
     1105        pszWhat = "default";
     1106    }
     1107
     1108    LogRel2(("Audio: Using %s buffer size %RU64 ms / %RU32 frames for stream '%s'\n",
     1109             pszWhat, PDMAudioPropsFramesToMilli(&pCfg->Props, pCfg->Backend.cFramesBufferSize),
     1110             pCfg->Backend.cFramesBufferSize, pszName));
     1111
     1112    /*
    10931113     * Period size
    10941114     */
    1095     const char *pszWhat = "device-specific";
     1115    pszWhat = "device-specific";
    10961116    if (pDrvCfg->uPeriodSizeMs)
    10971117    {
     
    11021122    if (!pCfg->Backend.cFramesPeriod) /* Set default period size if nothing explicitly is set. */
    11031123    {
    1104         pCfg->Backend.cFramesPeriod = PDMAudioPropsMilliToFrames(&pCfg->Props, 150 /*ms*/);
     1124        pCfg->Backend.cFramesPeriod = pCfg->Backend.cFramesBufferSize / 4;
    11051125        pszWhat = "default";
     1126    }
     1127
     1128    if (pCfg->Backend.cFramesPeriod >= pCfg->Backend.cFramesBufferSize / 2)
     1129    {
     1130        LogRel(("Audio: Warning! Stream '%s': The stream period size (%RU64ms, %s) cannot be more than half the buffer size (%RU64ms)!\n",
     1131                pszName, PDMAudioPropsFramesToMilli(&pCfg->Props, pCfg->Backend.cFramesPeriod), pszWhat,
     1132                PDMAudioPropsFramesToMilli(&pCfg->Props, pCfg->Backend.cFramesBufferSize)));
     1133        pCfg->Backend.cFramesPeriod = pCfg->Backend.cFramesBufferSize / 2;
    11061134    }
    11071135
     
    11091137             pszWhat, PDMAudioPropsFramesToMilli(&pCfg->Props, pCfg->Backend.cFramesPeriod),
    11101138             pCfg->Backend.cFramesPeriod, pszName));
    1111 
    1112     /*
    1113      * Buffer size
    1114      */
    1115     pszWhat = "device-specific";
    1116     if (pDrvCfg->uBufferSizeMs)
    1117     {
    1118         pCfg->Backend.cFramesBufferSize = PDMAudioPropsMilliToFrames(&pCfg->Props, pDrvCfg->uBufferSizeMs);
    1119         pszWhat = "custom";
    1120     }
    1121 
    1122     if (!pCfg->Backend.cFramesBufferSize) /* Set default buffer size if nothing explicitly is set. */
    1123     {
    1124         pCfg->Backend.cFramesBufferSize = PDMAudioPropsMilliToFrames(&pCfg->Props, 300 /*ms*/);
    1125         pszWhat = "default";
    1126     }
    1127 
    1128     LogRel2(("Audio: Using %s buffer size %RU64 ms / %RU32 frames for stream '%s'\n",
    1129              pszWhat, PDMAudioPropsFramesToMilli(&pCfg->Props, pCfg->Backend.cFramesBufferSize),
    1130              pCfg->Backend.cFramesBufferSize, pszName));
    11311139
    11321140    /*
     
    11541162    }
    11551163
     1164    if (pCfg->Backend.cFramesPreBuffering >= pCfg->Backend.cFramesBufferSize)
     1165    {
     1166        LogRel(("Audio: Warning! Stream '%s': Pre-buffering (%RU64ms, %s) cannot equal or exceed the buffer size (%RU64ms)!\n",
     1167                pszName,  PDMAudioPropsFramesToMilli(&pCfg->Props, pCfg->Backend.cFramesBufferSize), pszWhat,
     1168                PDMAudioPropsFramesToMilli(&pCfg->Props, pCfg->Backend.cFramesPreBuffering) ));
     1169        pCfg->Backend.cFramesPreBuffering = pCfg->Backend.cFramesBufferSize - 1;
     1170    }
     1171
    11561172    LogRel2(("Audio: Using %s pre-buffering size %RU64 ms / %RU32 frames for stream '%s'\n",
    11571173             pszWhat, PDMAudioPropsFramesToMilli(&pCfg->Props, pCfg->Backend.cFramesPreBuffering),
    11581174             pCfg->Backend.cFramesPreBuffering, pszName));
    1159 
    1160     /*
    1161      * Validate input.
    1162      */
    1163     if (pCfg->Backend.cFramesBufferSize < pCfg->Backend.cFramesPeriod)
    1164     {
    1165         LogRel(("Audio: Error for stream '%s': Buffering size (%RU64ms) must not be smaller than the period size (%RU64ms)\n",
    1166                 pszName, PDMAudioPropsFramesToMilli(&pCfg->Props, pCfg->Backend.cFramesBufferSize),
    1167                 PDMAudioPropsFramesToMilli(&pCfg->Props, pCfg->Backend.cFramesPeriod)));
    1168         return VERR_INVALID_PARAMETER;
    1169     }
    1170 
    1171     if (   pCfg->Backend.cFramesPreBuffering != UINT32_MAX /* Custom pre-buffering set? */
    1172         && pCfg->Backend.cFramesPreBuffering)
    1173     {
    1174         if (pCfg->Backend.cFramesBufferSize < pCfg->Backend.cFramesPreBuffering)
    1175         {
    1176             LogRel(("Audio: Error for stream '%s': Buffering size (%RU64ms) must not be smaller than the pre-buffering size (%RU64ms)\n",
    1177                     pszName, PDMAudioPropsFramesToMilli(&pCfg->Props, pCfg->Backend.cFramesPreBuffering),
    1178                     PDMAudioPropsFramesToMilli(&pCfg->Props, pCfg->Backend.cFramesBufferSize)));
    1179             return VERR_INVALID_PARAMETER;
    1180         }
    1181     }
    11821175
    11831176    return VINF_SUCCESS;
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