VirtualBox

Changeset 89736 in vbox for trunk/src/VBox/Devices


Ignore:
Timestamp:
Jun 16, 2021 8:31:29 AM (4 years ago)
Author:
vboxsync
svn:sync-xref-src-repo-rev:
145187
Message:

DevIchAc97: Don't recreate the driver streams just because the DMA buffer size changed. Don't reset the DMA buffer in ichac97R3StreamEnable, because ichac97R3StreamSetUp will either re-create it or reset it. bugref:9890

File:
1 edited

Legend:

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

    r89733 r89736  
    19971997{
    19981998    /*
    1999      * Assemble the stream config and get the associate mixer sink.
     1999     * Assemble the stream config and get the associated mixer sink.
    20002000     */
    20012001    PDMAUDIOPCMPROPS    PropsTmp;
    20022002    PDMAUDIOSTREAMCFG   Cfg;
    20032003    PDMAudioStrmCfgInitWithProps(&Cfg, ichach97R3CalcStreamProps(pThis, pStream->u8SD, &PropsTmp));
     2004    Assert(Cfg.enmDir != PDMAUDIODIR_UNKNOWN);
    20042005
    20052006    PAUDMIXSINK         pMixSink;
     
    21562157    uint32_t const cbCircBuf = PDMAudioPropsMilliToBytes(&Cfg.Props, cMsCircBuf);
    21572158
     2159    LogFlowFunc(("Stream %u: uTimerHz: %u -> %u; cMsSchedulingHint: %u -> %u; cbCircBuf: %#zx -> %#x (%u ms, cMsDmaMinBuf=%u)%s\n",
     2160                 pStreamCC->State.uTimerHz, uTimerHz, Cfg.Device.cMsSchedulingHint, cMsSchedulingHint,
     2161                 pStreamCC->State.pCircBuf ? RTCircBufSize(pStreamCC->State.pCircBuf) : 0, cbCircBuf, cMsCircBuf, cMsDmaMinBuf,
     2162                 !pStreamCC->State.pCircBuf || RTCircBufSize(pStreamCC->State.pCircBuf) != cbCircBuf  ? " - re-creating DMA buffer" : ""));
     2163
     2164    /*
     2165     * Set the stream's timer rate and scheduling hint.
     2166     */
     2167    pStreamCC->State.uTimerHz    = uTimerHz;
     2168    Cfg.Device.cMsSchedulingHint = cMsSchedulingHint;
     2169
     2170    /*
     2171     * Re-create the circular buffer if necessary, resetting if not.
     2172     */
     2173    if (   pStreamCC->State.pCircBuf
     2174        && RTCircBufSize(pStreamCC->State.pCircBuf) == cbCircBuf)
     2175        RTCircBufReset(pStreamCC->State.pCircBuf);
     2176    else
     2177    {
     2178        if (pStreamCC->State.pCircBuf)
     2179            RTCircBufDestroy(pStreamCC->State.pCircBuf);
     2180
     2181        int rc = RTCircBufCreate(&pStreamCC->State.pCircBuf, cbCircBuf);
     2182        AssertRCReturnStmt(rc, pStreamCC->State.pCircBuf = NULL, rc);
     2183
     2184        pStreamCC->State.StatDmaBufSize = (uint32_t)RTCircBufSize(pStreamCC->State.pCircBuf);
     2185    }
     2186    Assert(pStreamCC->State.StatDmaBufSize == cbCircBuf);
     2187
    21582188    /*
    21592189     * Only (re-)create the stream (and driver chain) if we really have to.
    21602190     * Otherwise avoid this and just reuse it, as this costs performance.
    21612191     */
     2192    char szTmp[PDMAUDIOSTRMCFGTOSTRING_MAX];
    21622193    int rc = VINF_SUCCESS;
    21632194    if (   fForce
    2164         || !PDMAudioStrmCfgMatchesProps(&Cfg, &pStreamCC->State.Cfg.Props)
    2165         || !pStreamCC->State.pCircBuf
    2166         || cbCircBuf != RTCircBufSize(pStreamCC->State.pCircBuf))
    2167     {
    2168         LogRel2(("AC97: (Re-)Opening stream '%s' (%RU32Hz, %RU8 channels, %s%RU8)\n", Cfg.szName, Cfg.Props.uHz,
    2169                  PDMAudioPropsChannels(&Cfg.Props), Cfg.Props.fSigned ? "S" : "U",  PDMAudioPropsSampleBits(&Cfg.Props)));
    2170 
    2171         LogFlowFunc(("[SD%RU8] uHz=%RU32\n", pStream->u8SD, Cfg.Props.uHz));
    2172 
    2173         Assert(Cfg.enmDir != PDMAUDIODIR_UNKNOWN);
    2174 
    2175         /*
    2176          * Set the stream's timer rate and scheduling hint.
    2177          */
    2178         pStreamCC->State.uTimerHz    = uTimerHz;
    2179         Cfg.Device.cMsSchedulingHint = cMsSchedulingHint;
    2180 
    2181         /*
    2182          * Re-create the circular buffer if necessary.
    2183          */
    2184         if (pStreamCC->State.pCircBuf && RTCircBufSize(pStreamCC->State.pCircBuf) == cbCircBuf)
    2185             RTCircBufReset(pStreamCC->State.pCircBuf);
    2186         else
    2187         {
    2188             LogFlowFunc(("Re-creating circular buffer with size %u ms / %#x bytes (was %#x); cMsSchedulingHint=%u cMsDmaMinBuf=%u cMsCircBufXxx=%u\n",
    2189                          cMsCircBuf, cbCircBuf, pStreamCC->State.StatDmaBufSize, Cfg.Device.cMsSchedulingHint, cMsDmaMinBuf,
    2190                          Cfg.enmDir == PDMAUDIODIR_IN ? pThis->cMsCircBufIn : pThis->cMsCircBufOut));
    2191             if (pStreamCC->State.pCircBuf)
    2192                 RTCircBufDestroy(pStreamCC->State.pCircBuf);
    2193 
    2194             rc = RTCircBufCreate(&pStreamCC->State.pCircBuf, cbCircBuf);
    2195             AssertRCReturnStmt(rc, pStreamCC->State.pCircBuf = NULL, rc);
    2196 
    2197             pStreamCC->State.StatDmaBufSize = (uint32_t)RTCircBufSize(pStreamCC->State.pCircBuf);
    2198         }
    2199         Assert(pStreamCC->State.StatDmaBufSize == cbCircBuf);
    2200 
    2201         /*
    2202          * <there should be a comment here>
    2203          */
     2195        || !PDMAudioStrmCfgMatchesProps(&Cfg, &pStreamCC->State.Cfg.Props))
     2196    {
     2197        LogRel2(("AC97: Setting up stream #%u: %s\n", pStreamCC->u8SD, PDMAudioStrmCfgToString(&Cfg, szTmp, sizeof(szTmp)) ));
     2198
    22042199        ichac97R3MixerRemoveDrvStreams(pDevIns, pThisCC, pMixSink, Cfg.enmDir, Cfg.enmPath);
    22052200        rc = ichac97R3MixerAddDrvStreams(pDevIns, pThisCC, pMixSink, &Cfg);
    22062201        if (RT_SUCCESS(rc))
    2207             rc = PDMAudioStrmCfgCopy(&pStreamCC->State.Cfg, &Cfg);
    2208 
    2209         LogFlowFunc(("[SD%RU8] rc=%Rrc\n", pStream->u8SD, rc));
     2202        {
     2203            PDMAudioStrmCfgCopy(&pStreamCC->State.Cfg, &Cfg);
     2204            LogFlowFunc(("[SD%RU8] success (uHz=%u)\n", pStreamCC->u8SD, rc, PDMAudioPropsHz(&Cfg.Props)));
     2205        }
     2206        else
     2207        {
     2208            LogFunc(("[SD%RU8] ichac97R3MixerAddDrvStreams failed: %Rrc (uHz=%u)\n",
     2209                     pStreamCC->u8SD, rc, PDMAudioPropsHz(&Cfg.Props)));
     2210            /** @todo r=bird: we should remember this somehow and prevent things from
     2211             *        working and ensure that we redo setup the next time the guest
     2212             *        tries to play/record something with this stream... */
     2213        }
    22102214    }
    22112215    else
    2212         LogFlowFunc(("[SD%RU8] Skipping (re-)creation\n", pStream->u8SD));
     2216        LogFlowFunc(("[SD%RU8] Skipping set-up (unchanged: %s)\n",
     2217                     pStreamCC->u8SD, PDMAudioStrmCfgToString(&Cfg, szTmp, sizeof(szTmp))));
    22132218    return rc;
    22142219}
     
    22782283    if (fEnable)
    22792284    {
    2280         /* Reset some of the state. */
     2285        /* Reset the input pre-buffering state. */
    22812286        pStreamCC->State.fInputPreBuffered = false;
    2282         if (pStreamCC->State.pCircBuf)
    2283             RTCircBufReset(pStreamCC->State.pCircBuf);
    22842287
    22852288        /* (Re-)Open the stream if necessary. */
     
    24302433    {
    24312434        char szFile[64];
    2432 
    24332435        if (ichac97R3GetDirFromSD(pStream->u8SD) == PDMAUDIODIR_IN)
    24342436            RTStrPrintf(szFile, sizeof(szFile), "ac97StreamWriteSD%RU8", pStream->u8SD);
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