VirtualBox

Changeset 73574 in vbox for trunk/src/VBox


Ignore:
Timestamp:
Aug 8, 2018 4:16:00 PM (6 years ago)
Author:
vboxsync
Message:

Audio/DrvAudio: Made drvAudioStreamCaptureNonInterleaved() more resilient against backends which offer more (fake) data than actually needed / available (e.g. the NULL backend).

File:
1 edited

Legend:

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

    r73570 r73574  
    15861586    size_t  cbBuf = sizeof(auBuf);
    15871587
    1588     for (;;)
    1589     {
    1590         uint32_t cbReadable = pThis->pHostDrvAudio->pfnStreamGetReadable(pThis->pHostDrvAudio, pStream->pvBackend);
    1591         if (!cbReadable)
    1592         {
    1593             Log2Func(("[%s] No readable data available, skipping\n", pStream->szName));
    1594             break;
    1595         }
    1596 
    1597         uint32_t cbFree = AUDIOMIXBUF_F2B(&pStream->Host.MixBuf, AudioMixBufFree(&pStream->Host.MixBuf));
    1598         if (!cbFree)
    1599         {
    1600             Log2Func(("[%s] Host buffer full, skipping\n", pStream->szName));
    1601             break;
    1602         }
    1603 
    1604         if (cbFree < cbReadable) /* More data captured than we can read? */
    1605         {
    1606             /** @todo Warn? */
    1607         }
    1608 
    1609         if (cbFree > cbBuf) /* Limit to buffer size. */
    1610             cbFree = (uint32_t)cbBuf;
    1611 
     1588    uint32_t cbReadable = pThis->pHostDrvAudio->pfnStreamGetReadable(pThis->pHostDrvAudio, pStream->pvBackend);
     1589    if (!cbReadable)
     1590        Log2Func(("[%s] No readable data available\n", pStream->szName));
     1591
     1592    uint32_t cbFree = AudioMixBufFreeBytes(&pStream->Guest.MixBuf); /* Parent */
     1593    if (!cbFree)
     1594        Log2Func(("[%s] Buffer full\n", pStream->szName));
     1595
     1596    if (cbReadable > cbFree) /* More data readable than we can store at the moment? Limit. */
     1597        cbReadable = cbFree;
     1598
     1599    while (cbReadable)
     1600    {
    16121601        uint32_t cbCaptured;
    16131602        rc = pThis->pHostDrvAudio->pfnStreamCapture(pThis->pHostDrvAudio, pStream->pvBackend,
    1614                                                     auBuf, cbFree, &cbCaptured);
     1603                                                    auBuf, RT_MIN(cbReadable, cbBuf), &cbCaptured);
    16151604        if (RT_FAILURE(rc))
    16161605        {
    16171606            int rc2 = drvAudioStreamControlInternalBackend(pThis, pStream, PDMAUDIOSTREAMCMD_DISABLE);
    16181607            AssertRC(rc2);
    1619         }
    1620         else if (cbCaptured)
    1621         {
    1622             Assert(cbCaptured <= cbBuf);
    1623             if (cbCaptured > cbBuf) /* Paranoia. */
    1624                 cbCaptured = (uint32_t)cbBuf;
    1625 
    1626             /* We use the host side mixing buffer as an intermediate buffer to do some
    1627              * (first) processing (if needed), so always write the incoming data at offset 0. */
    1628             uint32_t cfHstWritten = 0;
    1629             rc = AudioMixBufWriteAt(&pStream->Host.MixBuf, 0 /* offFrames */, auBuf, cbCaptured, &cfHstWritten);
    1630             if (   RT_FAILURE(rc)
    1631                 || !cfHstWritten)
    1632             {
    1633                 AssertMsgFailed(("[%s] Write failed: cbCaptured=%RU32, cfHstWritten=%RU32, rc=%Rrc\n",
    1634                                  pStream->szName, cbCaptured, cfHstWritten, rc));
    1635                 break;
    1636             }
    1637 
    1638             if (pThis->In.Cfg.Dbg.fEnabled)
    1639                 DrvAudioHlpFileWrite(pStream->In.Dbg.pFileCaptureNonInterleaved, auBuf, cbCaptured, 0 /* fFlags */);
    1640 
    1641             uint32_t cfHstMixed = 0;
    1642             if (cfHstWritten)
    1643             {
    1644                 int rc2 = AudioMixBufMixToParentEx(&pStream->Host.MixBuf, 0 /* cSrcOffset */, cfHstWritten /* cSrcFrames */,
    1645                                                    &cfHstMixed /* pcSrcMixed */);
    1646                 Log3Func(("[%s] cbCaptured=%RU32, cfWritten=%RU32, cfMixed=%RU32, rc=%Rrc\n",
    1647                           pStream->szName, cbCaptured, cfHstWritten, cfHstMixed, rc2));
    1648                 AssertRC(rc2);
    1649             }
    1650 
    1651             cfCapturedTotal += cfHstMixed;
    1652         }
    1653         else /* Nothing captured -- bail out. */
     1608
    16541609            break;
    1655 
    1656         if (RT_FAILURE(rc))
     1610        }
     1611
     1612        Assert(cbCaptured <= cbBuf);
     1613        if (cbCaptured > cbBuf) /* Paranoia. */
     1614            cbCaptured = (uint32_t)cbBuf;
     1615
     1616        /* We use the host side mixing buffer as an intermediate buffer to do some
     1617         * (first) processing (if needed), so always write the incoming data at offset 0. */
     1618        uint32_t cfHstWritten = 0;
     1619        rc = AudioMixBufWriteAt(&pStream->Host.MixBuf, 0 /* offFrames */, auBuf, cbCaptured, &cfHstWritten);
     1620        if (   RT_FAILURE(rc)
     1621            || !cfHstWritten)
     1622        {
     1623            AssertMsgFailed(("[%s] Write failed: cbCaptured=%RU32, cfHstWritten=%RU32, rc=%Rrc\n",
     1624                             pStream->szName, cbCaptured, cfHstWritten, rc));
    16571625            break;
     1626        }
     1627
     1628        if (pThis->In.Cfg.Dbg.fEnabled)
     1629            DrvAudioHlpFileWrite(pStream->In.Dbg.pFileCaptureNonInterleaved, auBuf, cbCaptured, 0 /* fFlags */);
     1630
     1631        uint32_t cfHstMixed = 0;
     1632        if (cfHstWritten)
     1633        {
     1634            int rc2 = AudioMixBufMixToParentEx(&pStream->Host.MixBuf, 0 /* cSrcOffset */, cfHstWritten /* cSrcFrames */,
     1635                                               &cfHstMixed /* pcSrcMixed */);
     1636            Log3Func(("[%s] cbCaptured=%RU32, cfWritten=%RU32, cfMixed=%RU32, rc=%Rrc\n",
     1637                      pStream->szName, cbCaptured, cfHstWritten, cfHstMixed, rc2));
     1638            AssertRC(rc2);
     1639        }
     1640
     1641        Assert(cbReadable >= cbCaptured);
     1642        cbReadable      -= cbCaptured;
     1643        cfCapturedTotal += cfHstMixed;
    16581644    }
    16591645
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