Changeset 68046 in vbox
- Timestamp:
- Jul 19, 2017 12:54:21 PM (8 years ago)
- svn:sync-xref-src-repo-rev:
- 117070
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Main/src-client/DrvAudioVRDE.cpp
r67914 r68046 70 70 { 71 71 /** Number of samples this stream can handle at once. */ 72 uint32_t c SamplesMax;72 uint32_t csMax; 73 73 /** Circular buffer for holding the recorded audio samples from the host. */ 74 74 PRTCIRCBUF pCircBuf; … … 76 76 struct 77 77 { 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. */ 79 82 uint64_t csToWrite; 80 83 } Out; … … 87 90 static int vrdeCreateStreamIn(PVRDESTREAM pStreamVRDE, PPDMAUDIOSTREAMCFG pCfgReq, PPDMAUDIOSTREAMCFG pCfgAcq) 88 91 { 89 pStreamVRDE->In.c SamplesMax = _1K; /** @todo Make this configurable. */90 91 int rc = RTCircBufCreate(&pStreamVRDE->In.pCircBuf, pStreamVRDE->In.c SamplesMax * (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 */); 92 95 if (RT_SUCCESS(rc)) 93 96 { … … 102 105 */ 103 106 pCfgAcq->enmLayout = PDMAUDIOSTREAMLAYOUT_RAW; 104 pCfgAcq->cSampleBufferHint = pStreamVRDE->In.c SamplesMax;107 pCfgAcq->cSampleBufferHint = pStreamVRDE->In.csMax; 105 108 } 106 109 } … … 155 158 case PDMAUDIOSTREAMCMD_ENABLE: 156 159 { 157 rc = pDrv->pConsoleVRDPServer->SendAudioInputBegin(NULL, pStreamVRDE, pStreamVRDE->In.c SamplesMax,160 rc = pDrv->pConsoleVRDPServer->SendAudioInputBegin(NULL, pStreamVRDE, pStreamVRDE->In.csMax, 158 161 pStreamVRDE->pCfg->Props.uHz, pStreamVRDE->pCfg->Props.cChannels, 159 162 pStreamVRDE->pCfg->Props.cBits); … … 277 280 pProps->fSigned); 278 281 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). */ 289 284 uint32_t csToWrite = pStreamVRDE->Out.csToWrite; 290 285 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)); 294 287 295 288 /* Don't play more than available. */ 296 289 if (csToWrite > csLive) 297 {298 LogFunc(("Expected at least %RU32 audio samples, but only got %RU32\n", csToWrite, csLive));299 290 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);307 291 308 292 int rc = VINF_SUCCESS; … … 335 319 if (RT_SUCCESS(rc)) 336 320 { 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 337 328 /* Return samples instead of bytes here 338 329 * (since we specified PDMAUDIOSTREAMLAYOUT_RAW as the audio data layout). */ … … 525 516 PVRDESTREAM pStreamVRDE = (PVRDESTREAM)pStream; 526 517 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); 530 521 531 522 PPDMAUDIOPCMPROPS pProps = &pStreamVRDE->pCfg->Props; 532 523 533 524 /* 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); 535 526 536 527 /* Return samples instead of bytes here
Note:
See TracChangeset
for help on using the changeset viewer.