Changeset 87875 in vbox for trunk/src/VBox/Devices/Audio
- Timestamp:
- Feb 25, 2021 4:35:19 PM (4 years ago)
- Location:
- trunk/src/VBox/Devices/Audio
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Devices/Audio/DrvAudio.cpp
r87862 r87875 1352 1352 uint32_t cfPlayedTotal = 0; 1353 1353 1354 uint8_t auBuf[256]; /** @todo Get rid of this here. */1355 1356 1354 uint32_t cfLeft = cfToPlay; 1357 uint32_t cbChunk = sizeof(auBuf); 1355 1356 uint8_t *pvChunk = (uint8_t *)pThis->pvScratchBuf; 1357 uint32_t cbChunk = pThis->cbScratchBuf; 1358 1358 1359 1359 while (cfLeft) … … 1361 1361 uint32_t cfRead = 0; 1362 1362 rc = AudioMixBufAcquireReadBlock(&pStream->Host.MixBuf, 1363 auBuf, RT_MIN(cbChunk, AUDIOMIXBUF_F2B(&pStream->Host.MixBuf, cfLeft)),1363 pvChunk, RT_MIN(cbChunk, AUDIOMIXBUF_F2B(&pStream->Host.MixBuf, cfLeft)), 1364 1364 &cfRead); 1365 1365 if (RT_FAILURE(rc)) … … 1372 1372 uint32_t cbPlayed = 0; 1373 1373 rc = pThis->pHostDrvAudio->pfnStreamPlay(pThis->pHostDrvAudio, pStream->pvBackend, 1374 auBuf, cbRead, &cbPlayed);1374 pvChunk, cbRead, &cbPlayed); 1375 1375 if ( RT_SUCCESS(rc) 1376 1376 && cbPlayed) 1377 1377 { 1378 1378 if (pThis->Out.Cfg.Dbg.fEnabled) 1379 DrvAudioHlpFileWrite(pStream->Out.Dbg.pFilePlayNonInterleaved, auBuf, cbPlayed, 0 /* fFlags */);1379 DrvAudioHlpFileWrite(pStream->Out.Dbg.pFilePlayNonInterleaved, pvChunk, cbPlayed, 0 /* fFlags */); 1380 1380 1381 1381 if (cbRead != cbPlayed) … … 1438 1438 uint32_t cfPlayedTotal = 0; 1439 1439 1440 PDMAUDIOFRAME aFrameBuf[_4K]; /** @todo Get rid of this here. */ 1440 PPDMAUDIOFRAME paFrames = (PPDMAUDIOFRAME)pThis->pvScratchBuf; 1441 const size_t cFrames = pThis->cbScratchBuf / sizeof(PDMAUDIOFRAME); 1441 1442 1442 1443 uint32_t cfLeft = cfToPlay; … … 1444 1445 { 1445 1446 uint32_t cfRead = 0; 1446 rc = AudioMixBufPeek(&pStream->Host.MixBuf, cfLeft, aFrameBuf,1447 RT_MIN(cfLeft, RT_ELEMENTS(aFrameBuf)), &cfRead);1447 rc = AudioMixBufPeek(&pStream->Host.MixBuf, cfLeft, paFrames, 1448 RT_MIN(cfLeft, cFrames), &cfRead); 1448 1449 1449 1450 if (RT_SUCCESS(rc)) … … 1455 1456 /* Note: As the stream layout is RPDMAUDIOSTREAMLAYOUT_RAW, operate on audio frames 1456 1457 * rather on bytes. */ 1457 Assert(cfRead <= RT_ELEMENTS(aFrameBuf));1458 Assert(cfRead <= cFrames); 1458 1459 rc = pThis->pHostDrvAudio->pfnStreamPlay(pThis->pHostDrvAudio, pStream->pvBackend, 1459 aFrameBuf, cfRead, &cfPlayed);1460 paFrames, cfRead, &cfPlayed); 1460 1461 if ( RT_FAILURE(rc) 1461 1462 || !cfPlayed) … … 1724 1725 AssertPtr(pThis->pHostDrvAudio->pfnStreamGetReadable); 1725 1726 1726 uint8_t auBuf[_1K]; /** @todo Get rid of this. */1727 uint32_t cbBuf = sizeof(auBuf);1728 1729 1727 uint32_t cbReadable = pThis->pHostDrvAudio->pfnStreamGetReadable(pThis->pHostDrvAudio, pStream->pvBackend); 1730 1728 if (!cbReadable) … … 1742 1740 uint32_t cbCaptured; 1743 1741 rc = pThis->pHostDrvAudio->pfnStreamCapture(pThis->pHostDrvAudio, pStream->pvBackend, 1744 auBuf, RT_MIN(cbReadable, cbBuf), &cbCaptured);1742 pThis->pvScratchBuf, RT_MIN(cbReadable, pThis->cbScratchBuf), &cbCaptured); 1745 1743 if (RT_FAILURE(rc)) 1746 1744 { … … 1751 1749 } 1752 1750 1753 Assert(cbCaptured <= cbBuf);1754 if (cbCaptured > cbBuf) /* Paranoia. */1755 cbCaptured = cbBuf;1751 Assert(cbCaptured <= pThis->cbScratchBuf); 1752 if (cbCaptured > pThis->cbScratchBuf) /* Paranoia. */ 1753 cbCaptured = pThis->cbScratchBuf; 1756 1754 1757 1755 if (!cbCaptured) /* Nothing captured? Take a shortcut. */ … … 1761 1759 * (first) processing (if needed), so always write the incoming data at offset 0. */ 1762 1760 uint32_t cfHstWritten = 0; 1763 rc = AudioMixBufWriteAt(&pStream->Host.MixBuf, 0 /* offFrames */, auBuf, cbCaptured, &cfHstWritten);1761 rc = AudioMixBufWriteAt(&pStream->Host.MixBuf, 0 /* offFrames */, pThis->pvScratchBuf, cbCaptured, &cfHstWritten); 1764 1762 if ( RT_FAILURE(rc) 1765 1763 || !cfHstWritten) … … 1771 1769 1772 1770 if (pThis->In.Cfg.Dbg.fEnabled) 1773 DrvAudioHlpFileWrite(pStream->In.Dbg.pFileCaptureNonInterleaved, auBuf, cbCaptured, 0 /* fFlags */);1771 DrvAudioHlpFileWrite(pStream->In.Dbg.pFileCaptureNonInterleaved, pThis->pvScratchBuf, cbCaptured, 0 /* fFlags */); 1774 1772 1775 1773 uint32_t cfHstMixed = 0; … … 2381 2379 int rc = RTCritSectInit(&pThis->CritSect); 2382 2380 AssertRCReturn(rc, rc); 2381 2382 const size_t cbScratchBuf = _4K; /** @todo Make this configurable? */ 2383 pThis->pvScratchBuf = RTMemAlloc(cbScratchBuf); 2384 AssertPtrReturn(pThis->pvScratchBuf, VERR_NO_MEMORY); 2385 pThis->cbScratchBuf = cbScratchBuf; 2383 2386 2384 2387 /* … … 3732 3735 drvAudioCallbackDestroy(pCB); 3733 3736 #endif 3737 3738 if (pThis->pvScratchBuf) 3739 { 3740 Assert(pThis->cbScratchBuf); 3741 3742 RTMemFree(pThis->pvScratchBuf); 3743 pThis->pvScratchBuf = NULL; 3744 } 3734 3745 3735 3746 if (RTCritSectIsInitialized(&pThis->CritSect)) -
trunk/src/VBox/Devices/Audio/DrvAudio.h
r87861 r87875 143 143 /** Audio configuration settings retrieved from the backend. */ 144 144 PDMAUDIOBACKENDCFG BackendCfg; 145 /** Commonly used scratch buffer. */ 146 void *pvScratchBuf; 147 /** Size (in bytes) of commonly used scratch buffer. */ 148 size_t cbScratchBuf; 145 149 #ifdef VBOX_WITH_STATISTICS 146 150 /** Statistics for the statistics manager (STAM). */
Note:
See TracChangeset
for help on using the changeset viewer.