VirtualBox

Changeset 68355 in vbox for trunk/src/VBox


Ignore:
Timestamp:
Aug 9, 2017 3:09:56 PM (7 years ago)
Author:
vboxsync
Message:

Audio/DrvHostPulseAudio.cpp: (Hopefully) fixes rare distortions.

File:
1 edited

Legend:

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

    r68303 r68355  
    6666    ( (PDRVHOSTPULSEAUDIO)((uintptr_t)pInterface - RT_OFFSETOF(DRVHOSTPULSEAUDIO, IHostAudio)) )
    6767
     68#define PULSEAUDIO_ASYNC
    6869
    6970/*********************************************************************************************************************************
     
    124125    /** Current latency (in us). */
    125126    uint64_t               curLatencyUs;
     127#ifdef LOG_ENABLED
    126128    /** Start time stamp (in us) of stream playback / recording. */
    127129    pa_usec_t              tsStartUs;
     130    /** Time stamp (in us) when last read from / written to the stream. */
     131    pa_usec_t              tsLastReadWrittenUs;
     132#endif
    128133} PULSEAUDIOSTREAM, *PPULSEAUDIOSTREAM;
    129134
     
    590595        }
    591596
     597#ifdef LOG_ENABLED
    592598        pStreamPA->tsStartUs = pa_rtclock_now();
    593 
     599#endif
    594600        if (RT_FAILURE(rc))
    595601            break;
     
    745751    pStreamPA->SampleSpec.channels = pCfgReq->Props.cChannels;
    746752
    747     pStreamPA->curLatencyUs        = 100 * 1000; /** 100ms latency by default. @todo Make this configurable. */
    748 
    749     LogRel2(("PulseAudio: Initial output latency is %RU64ms\n", pStreamPA->curLatencyUs / 1000 /* ms */));
    750 
    751     const uint32_t mixsize = pa_usec_to_bytes(pStreamPA->curLatencyUs, &pStreamPA->SampleSpec);
    752 
    753     pStreamPA->BufAttr.maxlength   = mixsize * 4;
    754     pStreamPA->BufAttr.tlength     = mixsize;
    755     pStreamPA->BufAttr.prebuf      = mixsize * 2;
    756     pStreamPA->BufAttr.minreq      = mixsize;
     753    pStreamPA->curLatencyUs        = 100 * 1000; /** 10ms latency by default. @todo Make this configurable. */
     754
     755    const uint32_t cbLatency = pa_usec_to_bytes(pStreamPA->curLatencyUs, &pStreamPA->SampleSpec);
     756
     757    LogRel2(("PulseAudio: Initial output latency is %RU64ms (%RU32 bytes)\n", pStreamPA->curLatencyUs / 1000 /* ms */, cbLatency));
     758
     759    pStreamPA->BufAttr.tlength     = cbLatency;
     760    pStreamPA->BufAttr.maxlength   = (pStreamPA->BufAttr.tlength * 3) / 2;
     761    pStreamPA->BufAttr.prebuf      = cbLatency;
     762    pStreamPA->BufAttr.minreq      = (uint32_t)-1;                 /* PulseAudio should set something sensible for minreq on it's own. */
    757763
    758764    LogFunc(("BufAttr tlength=%RU32, maxLength=%RU32, minReq=%RU32\n",
     
    951957                                                     uint32_t *pcxWritten)
    952958{
    953     RT_NOREF(pvBuf, cxBuf);
    954959    AssertPtrReturn(pInterface, VERR_INVALID_POINTER);
    955960    AssertPtrReturn(pStream,    VERR_INVALID_POINTER);
     
    967972    pa_threaded_mainloop_lock(pThis->pMainLoop);
    968973
     974#ifdef LOG_ENABLED
     975    const pa_usec_t tsNowUs         = pa_rtclock_now();
     976    const pa_usec_t tsDeltaPlayedUs = tsNowUs - pPAStream->tsLastReadWrittenUs;
     977
     978    Log3Func(("tsDeltaPlayedMs=%RU64\n", tsDeltaPlayedUs / 1000 /* ms */));
     979
     980    pPAStream->tsLastReadWrittenUs  = tsNowUs;
     981#endif
     982
    969983    do
    970984    {
     
    977991
    978992        size_t cbLeft = RT_MIN(cbWriteable, cxBuf);
     993        Assert(cbLeft); /* At this point we better have *something* to write. */
    979994
    980995        while (cbLeft)
    981996        {
    982             size_t cbToWrite = RT_MIN(cbLeft, pa_stream_writable_size(pPAStream->pStream));
    983             if (cbToWrite <= (size_t)0)
    984                 break;
    985 
    986             if (pa_stream_write(pPAStream->pStream, (uint8_t *)pvBuf + cbWrittenTotal, cbToWrite, NULL /* Cleanup callback */,
     997            uint32_t cbChunk = cbLeft; /* Write all at once for now. */
     998
     999            if (pa_stream_write(pPAStream->pStream, (uint8_t *)pvBuf + cbWrittenTotal, cbChunk, NULL /* Cleanup callback */,
    9871000                                0, PA_SEEK_RELATIVE) < 0)
    9881001            {
     
    9911004            }
    9921005
    993             Assert(cbLeft  >= cbToWrite);
    994             cbLeft         -= cbToWrite;
    995             cbWrittenTotal += cbToWrite;
     1006            Assert(cbLeft  >= cbChunk);
     1007            cbLeft         -= cbChunk;
     1008            cbWrittenTotal += cbChunk;
    9961009        }
    9971010
     
    12851298            else
    12861299            {
    1287                 rc = paWaitFor(pThis, pa_stream_cork(pStreamPA->pStream, 0, paStreamCbSuccess, pStreamPA));
     1300                /* Uncork (resume) stream. */
     1301                rc = paWaitFor(pThis, pa_stream_cork(pStreamPA->pStream, 0 /* Uncork */, paStreamCbSuccess, pStreamPA));
    12881302            }
    12891303
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