VirtualBox

Changeset 89531 in vbox for trunk/src/VBox/Devices


Ignore:
Timestamp:
Jun 7, 2021 12:12:46 AM (4 years ago)
Author:
vboxsync
Message:

DrvHostAudioPulseAudio: Don't trigger the stream unnecessarily when draining. Added an offInternal member to the stream like in most other backends and use it for deciding whether we've passed the PA pre-buffering threshold or not. bugref:9890

File:
1 edited

Legend:

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

    r89528 r89531  
    154154     * won't do any after-freed accesses.) */
    155155    pa_operation           *pTriggerOp;
    156     /** Output: Current latency (in microsecs). */
    157     uint64_t                cUsLatency;
     156    /** Internal byte offset. */
     157    uint64_t                offInternal;
    158158#ifdef LOG_ENABLED
    159159    /** Creation timestamp (in microsecs) of stream playback / recording. */
     
    12521252            LogRel2(("PulseAudio: Requesting: BufAttr: tlength=%#RX32 minReq=%#RX32 prebuf=%#RX32 maxLength=%#RX32\n",
    12531253                     pStreamPA->BufAttr.tlength, pStreamPA->BufAttr.minreq, pStreamPA->BufAttr.prebuf, pStreamPA->BufAttr.maxlength));
    1254 
    1255             /* This (cUsLatency) isn't used for anything. */
    1256             pStreamPA->cUsLatency = PDMAudioPropsFramesToMicro(&pCfgAcq->Props, pCfgReq->Backend.cFramesBufferSize);
    1257             LogRel2(("PulseAudio: Initial output latency is %RU64 us (%RU32 bytes)\n",
    1258                      pStreamPA->cUsLatency, pStreamPA->BufAttr.tlength));
    12591254        }
    12601255
     
    12921287                pCfgAcq->Backend.cFramesBufferSize   = PDMAudioPropsBytesToFrames(&pCfgAcq->Props, pStreamPA->BufAttr.tlength);
    12931288                pCfgAcq->Backend.cFramesPreBuffering = PDMAudioPropsBytesToFrames(&pCfgAcq->Props, pStreamPA->BufAttr.prebuf);
     1289
     1290                LogRel2(("PulseAudio: Initial output latency is %RU64 us (%RU32 bytes)\n",
     1291                         PDMAudioPropsBytesToMicro(&pCfgAcq->Props, pStreamPA->BufAttr.tlength), pStreamPA->BufAttr.tlength));
    12941292            }
    12951293
     
    14361434                 : drvHstAudPaError(pThis, "pa_stream_cork('%s', 0 /*uncork it*/,,) failed", pStreamPA->Cfg.szName);
    14371435
     1436    pStreamPA->offInternal = 0;
    14381437
    14391438    pa_threaded_mainloop_unlock(pThis->pMainLoop);
     
    16121611     */
    16131612    int rc = VINF_SUCCESS;
    1614     if (true /** @todo skip this if we're already playing or haven't written any data to the stream since xxxx. */)
     1613    if (  pStreamPA->offInternal
     1614        < PDMAudioPropsFramesToBytes(&pStreamPA->Cfg.Props, pStreamPA->Cfg.Backend.cFramesPreBuffering) * 2)
    16151615    {
    16161616        if (pStreamPA->pTriggerOp)
     
    17811781#ifdef LOG_ENABLED
    17821782    const pa_usec_t tsNowUs = pa_rtclock_now();
    1783     Log3Func(("play delta: %'RI64 us; cbBuf=%#x\n",
    1784               pStreamPA->tsLastReadWrittenUs ? tsNowUs - pStreamPA->tsLastReadWrittenUs : -1, cbBuf));
     1783    Log3Func(("play delta: %'RI64 us; cbBuf=%#x @%#RX64\n",
     1784              pStreamPA->tsLastReadWrittenUs ? tsNowUs - pStreamPA->tsLastReadWrittenUs : -1, cbBuf, pStreamPA->offInternal));
    17851785    pStreamPA->tsLastReadWrittenUs = tsNowUs;
    17861786#endif
     
    18021802            if (pa_stream_write(pStreamPA->pStream, pvBuf, cbToWrite, NULL /*pfnFree*/, 0 /*offset*/, PA_SEEK_RELATIVE) >= 0)
    18031803            {
    1804                 cbTotalWritten += cbToWrite;
    1805                 cbBuf          -= cbToWrite;
     1804                cbTotalWritten         += cbToWrite;
     1805                cbBuf                  -= cbToWrite;
     1806                pStreamPA->offInternal += cbToWrite;
    18061807                if (!cbBuf)
    18071808                    break;
     
    18331834        rc = VINF_SUCCESS;
    18341835    }
    1835     Log3Func(("returns %Rrc *pcbWritten=%#x iLoop=%u\n", rc, cbTotalWritten, iLoop));
     1836    Log3Func(("returns %Rrc *pcbWritten=%#x iLoop=%u @%#RX64\n", rc, cbTotalWritten, iLoop, pStreamPA->offInternal));
    18361837    return rc;
    18371838}
     
    18931894#ifdef LOG_ENABLED
    18941895    const pa_usec_t tsNowUs = pa_rtclock_now();
    1895     Log3Func(("capture delta: %'RI64 us; cbBuf=%#x\n",
    1896               pStreamPA->tsLastReadWrittenUs ? tsNowUs - pStreamPA->tsLastReadWrittenUs : -1, cbBuf));
     1896    Log3Func(("capture delta: %'RI64 us; cbBuf=%#x @%#RX64\n",
     1897              pStreamPA->tsLastReadWrittenUs ? tsNowUs - pStreamPA->tsLastReadWrittenUs : -1, cbBuf, pStreamPA->offInternal));
    18971898    pStreamPA->tsLastReadWrittenUs = tsNowUs;
    18981899#endif
     
    19101911        {
    19111912            memcpy(pvBuf, &pStreamPA->pbPeekBuf[pStreamPA->offPeekBuf], cbBuf);
    1912             pStreamPA->offPeekBuf += cbBuf;
    1913             *pcbRead               = cbBuf;
     1913            pStreamPA->offPeekBuf  += cbBuf;
     1914            pStreamPA->offInternal += cbBuf;
     1915            *pcbRead                = cbBuf;
     1916
    19141917            if (cbToCopy == cbBuf)
    19151918            {
     
    19201923                pa_threaded_mainloop_unlock(pThis->pMainLoop);
    19211924            }
    1922             Log3Func(("returns *pcbRead=%#x from prev peek buf (%#x/%#x)\n", cbBuf, pStreamPA->offPeekBuf, pStreamPA->cbPeekBuf));
     1925            Log3Func(("returns *pcbRead=%#x from prev peek buf (%#x/%#x) @%#RX64\n",
     1926                      cbBuf, pStreamPA->offPeekBuf, pStreamPA->cbPeekBuf, pStreamPA->offInternal));
    19231927            return VINF_SUCCESS;
    19241928        }
     
    19701974                        {
    19711975                            memcpy(pvBuf, pStreamPA->pbPeekBuf, cbBuf);
    1972                             cbTotalRead          += cbBuf;
    1973                             pStreamPA->offPeekBuf = cbBuf;
     1976                            cbTotalRead            += cbBuf;
     1977                            pStreamPA->offPeekBuf   = cbBuf;
     1978                            pStreamPA->offInternal += cbBuf;
    19741979                            cbBuf = 0;
    19751980                            break;
    19761981                        }
    19771982                        memcpy(pvBuf, pStreamPA->pbPeekBuf, pStreamPA->cbPeekBuf);
    1978                         cbBuf       -= pStreamPA->cbPeekBuf;
    1979                         pvBuf        = (uint8_t *)pvBuf + pStreamPA->cbPeekBuf;
    1980                         cbTotalRead += pStreamPA->cbPeekBuf;
    1981 
    1982                         pStreamPA->pbPeekBuf = NULL;
     1983                        cbBuf                  -= pStreamPA->cbPeekBuf;
     1984                        pvBuf                   = (uint8_t *)pvBuf + pStreamPA->cbPeekBuf;
     1985                        cbTotalRead            += pStreamPA->cbPeekBuf;
     1986                        pStreamPA->offInternal += cbBuf;
     1987
     1988                        pStreamPA->pbPeekBuf    = NULL;
    19831989                    }
    19841990                    else
     
    20262032        rc = VINF_SUCCESS;
    20272033    }
    2028     Log3Func(("returns %Rrc *pcbRead=%#x (%#x left, peek %#x/%#x)\n",
    2029               rc, cbTotalRead, cbBuf, pStreamPA->offPeekBuf, pStreamPA->cbPeekBuf));
     2034    Log3Func(("returns %Rrc *pcbRead=%#x (%#x left, peek %#x/%#x) @%#RX64\n",
     2035              rc, cbTotalRead, cbBuf, pStreamPA->offPeekBuf, pStreamPA->cbPeekBuf, pStreamPA->offInternal));
    20302036    return rc;
    20312037}
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