VirtualBox

Changeset 68046 in vbox


Ignore:
Timestamp:
Jul 19, 2017 12:54:21 PM (8 years ago)
Author:
vboxsync
svn:sync-xref-src-repo-rev:
117070
Message:

Audio/DrvAudioVRDE: Changed internal counter to subtract played samples instead of zeroing all at once; this should fix the rest of the reported stuttering when VRDP is enabled. Renaming + comments.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Main/src-client/DrvAudioVRDE.cpp

    r67914 r68046  
    7070        {
    7171            /** Number of samples this stream can handle at once. */
    72             uint32_t    cSamplesMax;
     72            uint32_t    csMax;
    7373            /** Circular buffer for holding the recorded audio samples from the host. */
    7474            PRTCIRCBUF  pCircBuf;
     
    7676        struct
    7777        {
    78             uint64_t    old_ticks;
     78            /** Timestamp (in virtual time ticks) of the last audio playback (of the VRDP server). */
     79            uint64_t    ticksPlayedLast;
     80            /** Internal counter (in audio samples) to track if and how much we can write to the VRDP server
     81             *  for the current time period. */
    7982            uint64_t    csToWrite;
    8083        } Out;
     
    8790static int vrdeCreateStreamIn(PVRDESTREAM pStreamVRDE, PPDMAUDIOSTREAMCFG pCfgReq, PPDMAUDIOSTREAMCFG pCfgAcq)
    8891{
    89     pStreamVRDE->In.cSamplesMax = _1K; /** @todo Make this configurable. */
    90 
    91     int rc = RTCircBufCreate(&pStreamVRDE->In.pCircBuf, pStreamVRDE->In.cSamplesMax * (pCfgReq->Props.cBits / 8) /* Bytes */);
     92    pStreamVRDE->In.csMax = _1K; /** @todo Make this configurable. */
     93
     94    int rc = RTCircBufCreate(&pStreamVRDE->In.pCircBuf, pStreamVRDE->In.csMax * (pCfgReq->Props.cBits / 8) /* Bytes */);
    9295    if (RT_SUCCESS(rc))
    9396    {
     
    102105             */
    103106            pCfgAcq->enmLayout         = PDMAUDIOSTREAMLAYOUT_RAW;
    104             pCfgAcq->cSampleBufferHint = pStreamVRDE->In.cSamplesMax;
     107            pCfgAcq->cSampleBufferHint = pStreamVRDE->In.csMax;
    105108        }
    106109    }
     
    155158        case PDMAUDIOSTREAMCMD_ENABLE:
    156159        {
    157             rc = pDrv->pConsoleVRDPServer->SendAudioInputBegin(NULL, pStreamVRDE, pStreamVRDE->In.cSamplesMax,
     160            rc = pDrv->pConsoleVRDPServer->SendAudioInputBegin(NULL, pStreamVRDE, pStreamVRDE->In.csMax,
    158161                                                               pStreamVRDE->pCfg->Props.uHz, pStreamVRDE->pCfg->Props.cChannels,
    159162                                                               pStreamVRDE->pCfg->Props.cBits);
     
    277280                                                 pProps->fSigned);
    278281
    279 #ifdef DEBUG
    280     uint64_t now              = PDMDrvHlpTMGetVirtualTime(pDrv->pDrvIns);
    281     uint64_t ticks            = now  - pStreamVRDE->Out.old_ticks;
    282     uint64_t ticks_per_second = PDMDrvHlpTMGetVirtualFreq(pDrv->pDrvIns);
    283 
    284     /* Minimize the rounding error: samples = int((ticks * freq) / ticks_per_second + 0.5). */
    285     uint32_t csExpected = (int)((2 * ticks * pProps->uHz + ticks_per_second) / ticks_per_second / 2);
    286     LogFunc(("csExpected=%RU32\n", csExpected));
    287 #endif
    288 
     282    /* Use the internal counter to track if we (still) can write to the VRDP server
     283     * or if we need to wait another round (time slot). */
    289284    uint32_t csToWrite = pStreamVRDE->Out.csToWrite;
    290285
    291     Log2Func(("uFreq=%RU32, cChan=%RU8, cBits=%RU8 (%d BPP), fSigned=%RTbool, enmFormat=%ld, csLive=%RU32, csToWrite=%RU32\n",
    292               pProps->uHz, pProps->cChannels, pProps->cBits, VRDE_AUDIO_FMT_BYTES_PER_SAMPLE(format),
    293               pProps->fSigned, format, csLive, csToWrite));
     286    Log3Func(("csLive=%RU32, csToWrite=%RU32\n", csLive, csToWrite));
    294287
    295288    /* Don't play more than available. */
    296289    if (csToWrite > csLive)
    297     {
    298         LogFunc(("Expected at least %RU32 audio samples, but only got %RU32\n", csToWrite, csLive));
    299290        csToWrite = csLive;
    300     }
    301 
    302     /* Reset to-write sample count. */
    303     pStreamVRDE->Out.csToWrite = 0;
    304 
    305     /* Remember when samples were consumed. */
    306     pStreamVRDE->Out.old_ticks = PDMDrvHlpTMGetVirtualTime(pDrv->pDrvIns);
    307291
    308292    int rc = VINF_SUCCESS;
     
    335319    if (RT_SUCCESS(rc))
    336320    {
     321        /* Subtract written samples from the counter. */
     322        Assert(pStreamVRDE->Out.csToWrite >= csWritten);
     323        pStreamVRDE->Out.csToWrite      -= csWritten;
     324
     325        /* Remember when samples were consumed. */
     326        pStreamVRDE->Out.ticksPlayedLast = PDMDrvHlpTMGetVirtualTime(pDrv->pDrvIns);
     327
    337328        /* Return samples instead of bytes here
    338329         * (since we specified PDMAUDIOSTREAMLAYOUT_RAW as the audio data layout). */
     
    525516    PVRDESTREAM   pStreamVRDE = (PVRDESTREAM)pStream;
    526517
    527     uint64_t now              = PDMDrvHlpTMGetVirtualTime(pDrv->pDrvIns);
    528     uint64_t ticks            = now  - pStreamVRDE->Out.old_ticks;
    529     uint64_t ticks_per_second = PDMDrvHlpTMGetVirtualFreq(pDrv->pDrvIns);
     518    const uint64_t ticksNow     = PDMDrvHlpTMGetVirtualTime(pDrv->pDrvIns);
     519    const uint64_t ticksElapsed = ticksNow  - pStreamVRDE->Out.ticksPlayedLast;
     520    const uint64_t ticksPerSec = PDMDrvHlpTMGetVirtualFreq(pDrv->pDrvIns);
    530521
    531522    PPDMAUDIOPCMPROPS pProps  = &pStreamVRDE->pCfg->Props;
    532523
    533524    /* Minimize the rounding error: samples = int((ticks * freq) / ticks_per_second + 0.5). */
    534     pStreamVRDE->Out.csToWrite = (int)((2 * ticks * pProps->uHz + ticks_per_second) / ticks_per_second / 2);
     525    pStreamVRDE->Out.csToWrite = (int)((2 * ticksElapsed * pProps->uHz + ticksPerSec) / ticksPerSec / 2);
    535526
    536527    /* Return samples instead of bytes here
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