Changeset 64034 in vbox for trunk/src/VBox/Devices
- Timestamp:
- Sep 27, 2016 10:19:28 AM (8 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Devices/Audio/DrvHostCoreAudio.cpp
r63958 r64034 42 42 #endif 43 43 44 #if 044 #if 1 45 45 # include <iprt/file.h> 46 46 # define DEBUG_DUMP_PCM_DATA … … 1928 1928 int coreAudioInputQueueProcBuffer(PCOREAUDIOSTREAM pCAStream, AudioQueueBufferRef audioBuffer) 1929 1929 { 1930 size_t cbWritten = 0;1931 1932 1930 PRTCIRCBUF pCircBuf = pCAStream->pCircBuf; 1933 1931 AssertPtr(pCircBuf); … … 1936 1934 UInt8 *pvDst = NULL; 1937 1935 1936 size_t cbWritten = 0; 1937 1938 1938 size_t cbToWrite = audioBuffer->mAudioDataByteSize; 1939 1939 size_t cbLeft = cbToWrite; … … 1959 1959 } 1960 1960 1961 audioBuffer->mAudioDataByteSize = cbWritten; 1962 1963 Log3Func(("pCAStream=%p, cbWritten=%zu\n", pCAStream, cbWritten)); 1961 Log3Func(("pCAStream=%p, cbBuffer=%RU32/%zu, cbWritten=%zu\n", 1962 pCAStream, audioBuffer->mAudioDataByteSize, audioBuffer->mAudioDataBytesCapacity, cbWritten)); 1964 1963 1965 1964 return VINF_SUCCESS; … … 2096 2095 if (pCAStream->enmDir == PDMAUDIODIR_IN) 2097 2096 { 2097 int rc2 = coreAudioInputQueueProcBuffer(pCAStream, pBuf); 2098 if (RT_SUCCESS(rc2)) 2099 { 2100 AudioQueueEnqueueBuffer(pCAStream->audioQueue, pBuf, 0, NULL); 2101 } 2098 2102 } 2099 2103 else if (pCAStream->enmDir == PDMAUDIODIR_OUT) … … 3223 3227 3224 3228 int rc = VINF_SUCCESS; 3225 uint32_t c bWrittenTotal = 0;3229 uint32_t csWrittenTotal = 0; 3226 3230 3227 3231 #ifdef VBOX_WITH_AUDIO_CA_QUEUES … … 3235 3239 size_t cbToWrite = RT_MIN(cbMixBuf, RTCircBufUsed(pCAStream->pCircBuf)); 3236 3240 3237 uint32_t c Written, cbWritten;3241 uint32_t csWritten, cbWritten; 3238 3242 uint8_t *puBuf; 3239 size_t cbToRead = 0;3240 3243 3241 3244 Log3Func(("cbMixBuf=%zu, cbToWrite=%zu/%zu\n", cbMixBuf, cbToWrite, RTCircBufSize(pCAStream->pCircBuf))); … … 3244 3247 { 3245 3248 /* Try to acquire the necessary block from the ring buffer. */ 3246 RTCircBufAcquireReadBlock(pCAStream->pCircBuf, cbToWrite, (void **)&puBuf, &cbToRead); 3247 if (!cbToRead) 3249 size_t cbChunk; 3250 RTCircBufAcquireReadBlock(pCAStream->pCircBuf, cbToWrite, (void **)&puBuf, &cbChunk); 3251 if (cbChunk) 3252 { 3253 #ifdef DEBUG_DUMP_PCM_DATA 3254 RTFILE fh; 3255 rc = RTFileOpen(&fh, DEBUG_DUMP_PCM_DATA_PATH "ca-capture.pcm", 3256 RTFILE_O_OPEN_CREATE | RTFILE_O_APPEND | RTFILE_O_WRITE | RTFILE_O_DENY_NONE); 3257 if (RT_SUCCESS(rc)) 3258 { 3259 RTFileWrite(fh, puBuf, cbChunk, NULL); 3260 RTFileClose(fh); 3261 } 3262 else 3263 AssertFailed(); 3264 #endif 3265 rc = AudioMixBufWriteCirc(&pStream->MixBuf, puBuf, cbChunk, &csWritten); 3266 if (rc == VERR_BUFFER_OVERFLOW) 3267 { 3268 LogRel2(("Core Audio: Capturing host buffer full\n")); 3269 rc = VINF_SUCCESS; 3270 } 3271 } 3272 3273 /* Release the read buffer, so it could be used for new data. */ 3274 RTCircBufReleaseReadBlock(pCAStream->pCircBuf, cbChunk); 3275 3276 if (RT_FAILURE(rc)) 3248 3277 break; 3249 3278 3250 #ifdef DEBUG_DUMP_PCM_DATA 3251 RTFILE fh; 3252 rc = RTFileOpen(&fh, DEBUG_DUMP_PCM_DATA_PATH "ca-capture.pcm", 3253 RTFILE_O_OPEN_CREATE | RTFILE_O_APPEND | RTFILE_O_WRITE | RTFILE_O_DENY_NONE); 3254 if (RT_SUCCESS(rc)) 3255 { 3256 RTFileWrite(fh, puBuf + cbWrittenTotal, cbToRead, NULL); 3257 RTFileClose(fh); 3258 } 3259 else 3260 AssertFailed(); 3261 #endif 3262 rc = AudioMixBufWriteCirc(&pStream->MixBuf, puBuf + cbWrittenTotal, cbToRead, &cWritten); 3263 3264 /* Release the read buffer, so it could be used for new data. */ 3265 RTCircBufReleaseReadBlock(pCAStream->pCircBuf, cbToRead); 3266 3267 if ( RT_FAILURE(rc) 3268 || !cWritten) 3269 { 3270 break; 3271 } 3272 3273 cbWritten = AUDIOMIXBUF_S2B(&pStream->MixBuf, cWritten); 3279 cbWritten = AUDIOMIXBUF_S2B(&pStream->MixBuf, csWritten); 3274 3280 3275 3281 Assert(cbToWrite >= cbWritten); 3276 3282 cbToWrite -= cbWritten; 3277 cbWrittenTotal += cbWritten; 3278 } 3279 3280 Log3Func(("cbToWrite=%zu, cbToRead=%zu, cbWrittenTotal=%RU32, rc=%Rrc\n", cbToWrite, cbToRead, cbWrittenTotal, rc)); 3283 3284 csWrittenTotal += csWritten; 3285 } 3281 3286 } 3282 3287 while (0); … … 3287 3292 #endif 3288 3293 3294 uint32_t cbWrittenTotal = AUDIOMIXBUF_S2B(&pStream->MixBuf, csWrittenTotal); 3295 3296 Log3Func(("csWrittenTotal=%RU32 (%RU32 bytes), rc=%Rrc\n", csWrittenTotal, cbWrittenTotal, rc)); 3297 3289 3298 if (RT_SUCCESS(rc)) 3290 3299 { 3291 uint32_t c Captured= 0;3292 uint32_t cWrittenTotal = AUDIOMIXBUF_B2S(&pStream->MixBuf, cbWrittenTotal); 3293 if (c WrittenTotal)3294 rc = AudioMixBufMixToParent(&pStream->MixBuf, cWrittenTotal, &cCaptured);3295 3296 Log3Func(("cWrittenTotal=%RU32 (%RU32 bytes), cCaptured=%RU32, rc=%Rrc\n", cWrittenTotal, cbWrittenTotal, cCaptured, rc));3297 3298 if (cCaptured) 3299 LogFlowFunc(("%RU32 samples captured\n", cCaptured));3300 uint32_t csMixed = 0; 3301 3302 if (csWrittenTotal) 3303 { 3304 RT_BREAKPOINT(); 3305 rc = AudioMixBufMixToParent(&pStream->MixBuf, csWrittenTotal, &csMixed); 3306 } 3307 3308 Log3Func(("csMixed=%RU32\n", csMixed)); 3300 3309 3301 3310 if (pcbRead) 3302 *pcbRead = c Captured;3311 *pcbRead = csMixed; 3303 3312 } 3304 3313 … … 3462 3471 #ifdef VBOX_WITH_AUDIO_CA_QUEUES 3463 3472 LogFunc(("Queue enable\n")); 3464 ASMAtomicXchgBool(&pCAStream->fRun, true); 3473 if (pCAStream->enmDir == PDMAUDIODIR_IN) 3474 { 3475 rc = coreAudioStreamInvalidateQueue(pCAStream); 3476 if (RT_SUCCESS(rc)) 3477 { 3478 /* Start the audio queue immediately. */ 3479 AudioQueueStart(pCAStream->audioQueue, NULL); 3480 } 3481 } 3482 if (pCAStream->enmDir == PDMAUDIODIR_OUT) 3483 { 3484 /* Touch the run flag to start the audio queue as soon as 3485 * we have anough data to actually play something. */ 3486 ASMAtomicXchgBool(&pCAStream->fRun, true); 3487 } 3465 3488 #else 3466 3489 /* Only start the device if it is actually stopped */
Note:
See TracChangeset
for help on using the changeset viewer.