VirtualBox

Changeset 54910 in vbox


Ignore:
Timestamp:
Mar 23, 2015 2:38:39 PM (10 years ago)
Author:
vboxsync
Message:

DrvHostPulseAudio.cpp: Remember allocation size for scratch buffer.

File:
1 edited

Legend:

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

    r54882 r54910  
    8989    PDRVHOSTPULSEAUDIO     pDrv;
    9090    /** DAC/ADC buffer. */
    91     void                  *pPCMBuf;
     91    void                  *pvPCMBuf;
     92    /** Size (in bytes) of DAC/ADC buffer. */
     93    uint32_t               cbPCMBuf;
    9294    /** Pointer to opaque PulseAudio stream. */
    9395    pa_stream             *pStream;
     
    598600    if (RT_SUCCESS(rc))
    599601    {
    600         int cbBuf = RT_MIN(pThisStrmOut->BufAttr.tlength * 2, pThisStrmOut->BufAttr.maxlength);
    601 
    602         pThisStrmOut->pPCMBuf = RTMemAllocZ(cbBuf);
    603         if (pThisStrmOut->pPCMBuf)
    604         {
    605             if (pcSamples)
    606                 *pcSamples = cbBuf >> pHstStrmOut->Props.cShift;
     602        uint32_t cbBuf  = RT_MIN(pThisStrmOut->BufAttr.tlength * 2,
     603                                 pThisStrmOut->BufAttr.maxlength); /** @todo Make this configurable! */
     604        if (cbBuf)
     605        {
     606            pThisStrmOut->pvPCMBuf = RTMemAllocZ(cbBuf);
     607            if (pThisStrmOut->pvPCMBuf)
     608            {
     609                pThisStrmOut->cbPCMBuf = cbBuf;
     610
     611                uint32_t cSamples = cbBuf >> pHstStrmOut->Props.cShift;
     612                if (pcSamples)
     613                    *pcSamples = cSamples;
     614
     615                LogFunc(("cbBuf=%RU32, cSamples=%RU32\n", cbBuf, cSamples));
     616            }
     617            else
     618                rc = VERR_NO_MEMORY;
    607619        }
    608620        else
    609             rc = VERR_NO_MEMORY;
     621            rc = VERR_INVALID_PARAMETER;
    610622    }
    611623
     
    810822    uint32_t cbReadTotal = 0;
    811823
    812     uint32_t cLive = drvAudioHstOutSamplesLive(pHstStrmOut,
    813                                                NULL /* pcStreamsLive */);
     824    uint32_t cLive = drvAudioHstOutSamplesLive(pHstStrmOut, NULL /* pcStreamsLive */);
    814825    if (!cLive)
    815826    {
     
    841852        while (cbToRead)
    842853        {
    843             rc = audioMixBufReadCirc(&pHstStrmOut->MixBuf, pThisStrmOut->pPCMBuf, cbToRead, &cRead);
    844             if (RT_FAILURE(rc))
     854            rc = audioMixBufReadCirc(&pHstStrmOut->MixBuf, pThisStrmOut->pvPCMBuf,
     855                                     RT_MIN(cbToRead, pThisStrmOut->cbPCMBuf), &cRead);
     856            if (   !cRead
     857                || RT_FAILURE(rc))
     858            {
    845859                break;
     860            }
    846861
    847862            cbRead = AUDIOMIXBUF_S2B(&pHstStrmOut->MixBuf, cRead);
    848             if (pa_stream_write(pThisStrmOut->pStream, pThisStrmOut->pPCMBuf, cbRead,
    849                                 NULL /* Cleanup callback */, 0, PA_SEEK_RELATIVE) < 0)
     863            if (pa_stream_write(pThisStrmOut->pStream, pThisStrmOut->pvPCMBuf, cbRead, NULL /* Cleanup callback */,
     864                                0, PA_SEEK_RELATIVE) < 0)
    850865            {
    851866                rc = drvHostPulseAudioError(pThisStrmOut->pDrv, "Failed to write to output stream");
     
    854869
    855870            Assert(cbToRead >= cRead);
    856             cbToRead -= cbRead;
     871            cbToRead    -= cbRead;
    857872            cbReadTotal += cbRead;
     873
     874            LogFlowFunc(("\tcRead=%RU32 (%zu bytes) cbReadTotal=%RU32, cbToRead=%RU32\n",
     875                         cRead, AUDIOMIXBUF_S2B(&pHstStrmOut->MixBuf, cRead), cbReadTotal, cbToRead));
    858876        }
    859877
     
    871889            *pcSamplesPlayed = cReadTotal;
    872890
    873         LogFlowFunc(("cReadTotal=%RU32 (%RU32 bytes), rc=%Rrc\n",
    874                      cReadTotal, cbReadTotal, rc));
     891        LogFlowFunc(("cReadTotal=%RU32 (%RU32 bytes), rc=%Rrc\n", cReadTotal, cbReadTotal, rc));
    875892    }
    876893
     
    934951    }
    935952
    936     if (pThisStrmOut->pPCMBuf)
    937     {
    938         RTMemFree(pThisStrmOut->pPCMBuf);
    939         pThisStrmOut->pPCMBuf = NULL;
     953    if (pThisStrmOut->pvPCMBuf)
     954    {
     955        RTMemFree(pThisStrmOut->pvPCMBuf);
     956        pThisStrmOut->pvPCMBuf = NULL;
     957
     958        pThisStrmOut->cbPCMBuf = 0;
    940959    }
    941960
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