VirtualBox

Changeset 73645 in vbox for trunk


Ignore:
Timestamp:
Aug 14, 2018 11:22:28 AM (6 years ago)
Author:
vboxsync
Message:

Audio/Mixer: Cleanup / renaming for audioMixerSinkWriteToStreams().

File:
1 edited

Legend:

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

    r73582 r73645  
    17091709        size_t cbChunk;
    17101710
    1711         uint32_t cbWritten = 0;
    1712         uint32_t cbToWrite = RT_MIN(cbBuf, (uint32_t)RTCircBufFree(pCircBuf));
    1713         while (cbToWrite)
    1714         {
    1715             RTCircBufAcquireWriteBlock(pCircBuf, cbToWrite, &pvChunk, &cbChunk);
     1711        uint32_t cbWrittenBuf = 0;
     1712        uint32_t cbToWriteBuf = RT_MIN(cbBuf, (uint32_t)RTCircBufFree(pCircBuf));
     1713        while (cbToWriteBuf)
     1714        {
     1715            RTCircBufAcquireWriteBlock(pCircBuf, cbToWriteBuf, &pvChunk, &cbChunk);
    17161716
    17171717            if (cbChunk)
    1718                 memcpy(pvChunk, (uint8_t *)pvBuf + cbWritten, cbChunk);
     1718                memcpy(pvChunk, (uint8_t *)pvBuf + cbWrittenBuf, cbChunk);
    17191719
    17201720            RTCircBufReleaseWriteBlock(pCircBuf, cbChunk);
    17211721
    1722             cbWritten += (uint32_t)cbChunk;
    1723             Assert(cbWritten <= cbBuf);
    1724 
    1725             Assert(cbToWrite >= cbChunk);
    1726             cbToWrite -= (uint32_t)cbChunk;
    1727         }
    1728 
    1729         if (cbWritten < cbBuf)
     1722            cbWrittenBuf += (uint32_t)cbChunk;
     1723            Assert(cbWrittenBuf <= cbBuf);
     1724
     1725            Assert(cbToWriteBuf >= cbChunk);
     1726            cbToWriteBuf -= (uint32_t)cbChunk;
     1727        }
     1728
     1729        cbWrittenMin = RT_MIN(cbWrittenMin, cbWrittenBuf);
     1730
     1731        if (cbWrittenBuf) /* Update the mixer stream's last written time stamp. */
     1732            pMixStream->tsLastReadWrittenNs = RTTimeNanoTS();
     1733
     1734        uint32_t cbToWriteStream = DrvAudioHlpBytesAlign(cbWrittenBuf, &pSink->PCMProps);
     1735        uint32_t cbWrittenStream = 0;
     1736
     1737        int rc2 = VINF_SUCCESS;
     1738
     1739        while (cbToWriteStream)
     1740        {
     1741            RTCircBufAcquireReadBlock(pCircBuf, cbToWriteStream, &pvChunk, &cbChunk);
     1742
     1743            uint32_t cbChunkWritten = 0;
     1744            if (cbChunk)
     1745            {
     1746                rc2 = pMixStream->pConn->pfnStreamWrite(pMixStream->pConn, pMixStream->pStream, pvChunk, (uint32_t)cbChunk,
     1747                                                        &cbChunkWritten);
     1748                if (RT_FAILURE(rc2))
     1749                    LogFunc(("[%s] Failed writing to stream '%s': %Rrc\n", pSink->pszName, pMixStream->pszName, rc2));
     1750#ifdef DEBUG_andy
     1751                AssertRC(rc2);
     1752#endif
     1753            }
     1754
     1755            RTCircBufReleaseReadBlock(pCircBuf, cbChunkWritten);
     1756
     1757            if (RT_FAILURE(rc2))
     1758                break;
     1759
     1760            Assert(cbToWriteStream >= cbChunk);
     1761            cbToWriteStream -= (uint32_t)cbChunk;
     1762
     1763            cbWrittenStream += cbChunk;
     1764            Assert(cbWrittenStream <= cbBuf);
     1765        }
     1766
     1767        Log3Func(("[%s] cbBuf=%RU32, cbWrittenBuf=%RU32, cbWrittenStream=%RU32\n",
     1768                  pMixStream->pszName, cbBuf, cbWrittenBuf, cbWrittenStream));
     1769
     1770        if (cbWrittenBuf < cbBuf)
    17301771        {
    17311772            LogFunc(("[%s] Warning: Only written %RU32/%RU32 bytes for stream '%s'\n",
    1732                      pSink->pszName, cbWritten, cbBuf, pMixStream->pszName));
     1773                     pSink->pszName, cbWrittenBuf, cbBuf, pMixStream->pszName));
    17331774            LogRel2(("Mixer: Buffer overrun for mixer stream '%s' (sink '%s')\n", pMixStream->pszName, pSink->pszName));
    17341775#ifdef DEBUG_andy
    17351776            AssertFailed();
    17361777#endif
    1737         }
    1738 
    1739         cbWrittenMin = RT_MIN(cbWrittenMin, cbWritten);
    1740 
    1741         if (cbWritten) /* Update the mixer stream's last written time stamp. */
    1742             pMixStream->tsLastReadWrittenNs = RTTimeNanoTS();
    1743 
    1744         cbToWrite = RT_MIN(pMixStream->pConn->pfnStreamGetWritable(pMixStream->pConn, pMixStream->pStream),
    1745                            (uint32_t)RTCircBufUsed(pCircBuf));
    1746         cbToWrite = DrvAudioHlpBytesAlign(cbToWrite, &pSink->PCMProps);
    1747 
    1748         int rc2 = VINF_SUCCESS;
    1749 
    1750         while (cbToWrite)
    1751         {
    1752             RTCircBufAcquireReadBlock(pCircBuf, cbToWrite, &pvChunk, &cbChunk);
    1753 
    1754             if (cbChunk)
    1755             {
    1756                 rc2 = pMixStream->pConn->pfnStreamWrite(pMixStream->pConn, pMixStream->pStream, pvChunk, (uint32_t)cbChunk,
    1757                                                         &cbWritten);
    1758                 if (RT_FAILURE(rc2))
    1759                     LogFunc(("[%s] Failed writing to stream '%s': %Rrc\n", pSink->pszName, pMixStream->pszName, rc2));
    1760             }
    1761 
    1762             RTCircBufReleaseReadBlock(pCircBuf, cbWritten);
    1763 
    1764             if (   !cbWritten
    1765                 || cbWritten < cbChunk)
    1766             {
    1767 #ifdef DEBUG_andy
    1768                 AssertFailed();
    1769 #endif
    1770                 break;
    1771             }
    1772 
    1773             if (RT_FAILURE(rc2))
    1774                 break;
    1775 
    1776             Assert(cbToWrite >= cbChunk);
    1777             cbToWrite -= (uint32_t)cbChunk;
    17781778        }
    17791779    }
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