VirtualBox

Changeset 87270 in vbox


Ignore:
Timestamp:
Jan 15, 2021 1:06:46 PM (4 years ago)
Author:
vboxsync
svn:sync-xref-src-repo-rev:
142229
Message:

Audio/Mixer: Got rid of the stack-allocated scratch buffer when mixing / multiplexing stuff. Instead, each sink has a heap allocated one now, to avoid hammering the stack. ticketoem2ref:36

Location:
trunk/src/VBox/Devices/Audio
Files:
2 edited

Legend:

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

    r87173 r87270  
    847847        pSink->VolumeCombined.uLeft  = PDMAUDIO_VOLUME_MAX;
    848848        pSink->VolumeCombined.uRight = PDMAUDIO_VOLUME_MAX;
     849
     850        const size_t cbScratchBuf = _1K; /** @todo Make this configurable? */
     851
     852        pSink->pabScratchBuf = (uint8_t *)RTMemAlloc(cbScratchBuf);
     853        AssertPtrReturn(pSink->pabScratchBuf, VERR_NO_MEMORY);
     854        pSink->cbScratchBuf  = cbScratchBuf;
    849855    }
    850856
     
    916922        RTStrFree(pSink->pszName);
    917923        pSink->pszName = NULL;
     924    }
     925
     926    if (pSink->pabScratchBuf)
     927    {
     928        Assert(pSink->cbScratchBuf);
     929
     930        RTMemFree(pSink->pabScratchBuf);
     931        pSink->pabScratchBuf = NULL;
     932
     933        pSink->cbScratchBuf = 0;
    918934    }
    919935
     
    16751691        return rc;
    16761692
     1693    /* Sanity. */
     1694    AssertPtr(pSink->pabScratchBuf);
     1695    Assert(pSink->cbScratchBuf);
     1696
    16771697    /* Update each mixing sink stream's status. */
    16781698    PAUDMIXSTREAM pMixStream;
     
    16891709    uint32_t cbToWriteToStreams = AudioMixBufUsedBytes(&pSink->MixBuf);
    16901710
    1691     uint8_t arrChunkBuf[_1K]; /** @todo Hm ... some zero copy / shared buffers would be nice! */
    16921711    while (cbToWriteToStreams)
    16931712    {
    16941713        uint32_t cfChunk;
    1695         rc  = AudioMixBufAcquireReadBlock(&pSink->MixBuf, arrChunkBuf, RT_MIN(cbToWriteToStreams, sizeof(arrChunkBuf)), &cfChunk);
     1714        rc  = AudioMixBufAcquireReadBlock(&pSink->MixBuf, pSink->pabScratchBuf, RT_MIN(cbToWriteToStreams, pSink->cbScratchBuf),
     1715                                          &cfChunk);
    16961716        if (RT_FAILURE(rc))
    16971717            break;
    16981718
    16991719        const uint32_t cbChunk = DrvAudioHlpFramesToBytes(cfChunk, &pSink->PCMProps);
    1700         Assert(cbChunk <= sizeof(arrChunkBuf));
     1720        Assert(cbChunk <= pSink->cbScratchBuf);
    17011721
    17021722        /* Multiplex the current chunk in a synchronized fashion to all connected streams. */
    17031723        uint32_t cbChunkWrittenMin = 0;
    1704         rc = audioMixerSinkMultiplexSync(pSink, AUDMIXOP_COPY, arrChunkBuf, cbChunk, &cbChunkWrittenMin);
     1724        rc = audioMixerSinkMultiplexSync(pSink, AUDMIXOP_COPY, pSink->pabScratchBuf, cbChunk, &cbChunkWrittenMin);
    17051725        if (RT_SUCCESS(rc))
    17061726        {
  • trunk/src/VBox/Devices/Audio/AudioMixer.h

    r82968 r87270  
    194194     * a parent buffer for all streams this sink owns. */
    195195    PDMAUDIOMIXBUF          MixBuf;
     196    /** Scratch buffer for multiplexing / mixing. Might be NULL if not needed. */
     197    uint8_t                *pabScratchBuf;
     198    /** Size (in bytes) of pabScratchBuf. Might be 0 if not needed. */
     199    size_t                  cbScratchBuf;
    196200    /** Union for input/output specifics. */
    197201    union
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