Changeset 68393 in vbox for trunk/src/VBox/Main
- Timestamp:
- Aug 11, 2017 12:41:23 PM (8 years ago)
- svn:sync-xref-src-repo-rev:
- 117525
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Main/src-client/DrvAudioVRDE.cpp
r68391 r68393 71 71 /** Number of audio frames this stream can handle at once. */ 72 72 uint32_t cfMax; 73 /** Circular buffer for holding the recorded audio samples from the host. */73 /** Circular buffer for holding the recorded audio frames from the host. */ 74 74 PRTCIRCBUF pCircBuf; 75 75 } In; … … 78 78 /** Timestamp (in virtual time ticks) of the last audio playback (of the VRDP server). */ 79 79 uint64_t ticksPlayedLast; 80 /** Internal counter (in audio samples) to track if and how much we can write to the VRDP server80 /** Internal counter (in audio frames) to track if and how much we can write to the VRDP server 81 81 * for the current time period. */ 82 uint64_t c sToWrite;82 uint64_t cfToWrite; 83 83 } Out; 84 84 }; … … 269 269 return VERR_NOT_AVAILABLE; 270 270 271 /* Note: We get the number of * samples* in cbBuf271 /* Note: We get the number of *frames* in cxBuf 272 272 * (since we specified PDMAUDIOSTREAMLAYOUT_RAW as the audio data layout) on stream creation. */ 273 uint32_t c sLive = cxBuf;273 uint32_t cfLive = cxBuf; 274 274 275 275 PPDMAUDIOPCMPROPS pProps = &pStreamVRDE->pCfg->Props; … … 282 282 /* Use the internal counter to track if we (still) can write to the VRDP server 283 283 * or if we need to wait another round (time slot). */ 284 uint32_t c sToWrite = pStreamVRDE->Out.csToWrite;285 286 Log3Func(("c sLive=%RU32, csToWrite=%RU32\n", csLive, csToWrite));284 uint32_t cfToWrite = pStreamVRDE->Out.cfToWrite; 285 286 Log3Func(("cfLive=%RU32, cfToWrite=%RU32\n", cfLive, cfToWrite)); 287 287 288 288 /* Don't play more than available. */ 289 if (c sToWrite > csLive)290 c sToWrite = csLive;289 if (cfToWrite > cfLive) 290 cfToWrite = cfLive; 291 291 292 292 int rc = VINF_SUCCESS; … … 298 298 * Call the VRDP server with the data. 299 299 */ 300 uint32_t c sWritten = 0;301 while (c sToWrite)302 { 303 uint32_t c sChunk = csToWrite; /** @todo For now write all at once. */304 305 if (!c sChunk) /* Nothing to send. Bail out. */300 uint32_t cfWritten = 0; 301 while (cfToWrite) 302 { 303 uint32_t cfChunk = cfToWrite; /** @todo For now write all at once. */ 304 305 if (!cfChunk) /* Nothing to send. Bail out. */ 306 306 break; 307 307 308 308 /* Note: The VRDP server expects int64_t samples per channel, regardless of the actual 309 309 * sample bits (e.g 8 or 16 bits). */ 310 pDrv->pConsoleVRDPServer->SendAudioSamples(paSampleBuf + c sWritten, csChunk /* Samples */, format);311 312 c sWritten += csChunk;313 Assert(c sWritten <= csLive);314 315 Assert(c sToWrite >= csChunk);316 c sToWrite -= csChunk;310 pDrv->pConsoleVRDPServer->SendAudioSamples(paSampleBuf + cfWritten, cfChunk /* Frames */, format); 311 312 cfWritten += cfChunk; 313 Assert(cfWritten <= cfLive); 314 315 Assert(cfToWrite >= cfChunk); 316 cfToWrite -= cfChunk; 317 317 } 318 318 319 319 if (RT_SUCCESS(rc)) 320 320 { 321 /* Subtract written samples from the counter. */322 Assert(pStreamVRDE->Out.c sToWrite >= csWritten);323 pStreamVRDE->Out.c sToWrite -= csWritten;324 325 /* Remember when samples were consumed. */321 /* Subtract written frames from the counter. */ 322 Assert(pStreamVRDE->Out.cfToWrite >= cfWritten); 323 pStreamVRDE->Out.cfToWrite -= cfWritten; 324 325 /* Remember when frames were consumed. */ 326 326 pStreamVRDE->Out.ticksPlayedLast = PDMDrvHlpTMGetVirtualTime(pDrv->pDrvIns); 327 327 328 /* Return samples instead of bytes here328 /* Return frames instead of bytes here 329 329 * (since we specified PDMAUDIOSTREAMLAYOUT_RAW as the audio data layout). */ 330 330 if (pcxWritten) 331 *pcxWritten = c sWritten;331 *pcxWritten = cfWritten; 332 332 } 333 333 … … 499 499 if (pStreamVRDE->pCfg->enmDir == PDMAUDIODIR_IN) 500 500 { 501 /* Return samples instead of bytes here501 /* Return frames instead of bytes here 502 502 * (since we specified PDMAUDIOSTREAMLAYOUT_RAW as the audio data layout). */ 503 503 return (uint32_t)PDMAUDIOSTREAMCFG_B2F(pStreamVRDE->pCfg, RTCircBufUsed(pStreamVRDE->In.pCircBuf)); … … 522 522 PPDMAUDIOPCMPROPS pProps = &pStreamVRDE->pCfg->Props; 523 523 524 /* Minimize the rounding error: samples = int((ticks * freq) / ticks_per_second + 0.5). */525 pStreamVRDE->Out.c sToWrite = (int)((2 * ticksElapsed * pProps->uHz + ticksPerSec) / ticksPerSec / 2);526 527 /* Return samples instead of bytes here524 /* Minimize the rounding error: frames = int((ticks * freq) / ticks_per_second + 0.5). */ 525 pStreamVRDE->Out.cfToWrite = (int)((2 * ticksElapsed * pProps->uHz + ticksPerSec) / ticksPerSec / 2); 526 527 /* Return frames instead of bytes here 528 528 * (since we specified PDMAUDIOSTREAMLAYOUT_RAW as the audio data layout). */ 529 return pStreamVRDE->Out.c sToWrite;529 return pStreamVRDE->Out.cfToWrite; 530 530 } 531 531
Note:
See TracChangeset
for help on using the changeset viewer.