Changeset 64171 in vbox for trunk/src/VBox
- Timestamp:
- Oct 6, 2016 4:26:14 PM (8 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Devices/Audio/DrvHostCoreAudio.cpp
r64063 r64171 57 57 /** @todo Needs more investigation and testing first before enabling. */ 58 58 //# define VBOX_WITH_AUDIO_CA_CONVERTER 59 60 #ifdef DEBUG_andy61 /** Enables support for Audio Queues. */62 # define VBOX_WITH_AUDIO_CA_QUEUES63 #endif64 59 65 60 #ifdef DEBUG_andy … … 477 472 typedef struct COREAUDIOSTREAM 478 473 { 479 /** Host input stream.474 /** PDM audio stream data. 480 475 * Note: Always must come first in this structure! */ 481 PDMAUDIOSTREAM Stream;482 /** Note: This *always* must come first!*/476 PDMAUDIOSTREAM Stream; 477 /** Stream-specific data, depending on the stream type. */ 483 478 union 484 479 { 485 COREAUDIOSTREAMIN In;486 COREAUDIOSTREAMOUT Out;480 COREAUDIOSTREAMIN In; 481 COREAUDIOSTREAMOUT Out; 487 482 }; 488 483 /** List node for the device's stream list. */ 489 RTLISTNODE Node;484 RTLISTNODE Node; 490 485 /** Pointer to driver instance this stream is bound to. */ 491 PDRVHOSTCOREAUDIO pDrv;486 PDRVHOSTCOREAUDIO pDrv; 492 487 /** The stream's direction. */ 493 PDMAUDIODIR enmDir;488 PDMAUDIODIR enmDir; 494 489 #ifdef VBOX_WITH_AUDIO_CA_QUEUES 495 490 /** The stream's thread handle for maintaining the audio queue. */ 496 RTTHREAD hThread;491 RTTHREAD hThread; 497 492 /** Flag indicating to start a stream's data processing. */ 498 bool fRun;493 bool fRun; 499 494 /** Whether the stream is in a running (active) state or not. 500 495 * For playback streams this means that audio data can be (or is being) played, 501 496 * for capturing streams this means that audio data is being captured (if available). */ 502 bool fIsRunning;497 bool fIsRunning; 503 498 /** Thread shutdown indicator. */ 504 bool fShutdown;499 bool fShutdown; 505 500 /** Critical section for serializing access between thread + callbacks. */ 506 RTCRITSECT CritSect;501 RTCRITSECT CritSect; 507 502 /** The actual audio queue being used. */ 508 AudioQueueRef audioQueue;503 AudioQueueRef audioQueue; 509 504 /** The audio buffers which are used with the above audio queue. */ 510 AudioQueueBufferRef audioBuffer[3]; 511 AudioStreamBasicDescription asbdAcq; 505 AudioQueueBufferRef audioBuffer[3]; 506 /** The acquired (final) audio format for this stream. */ 507 AudioStreamBasicDescription asbdStream; 512 508 #endif 513 509 /** The audio unit for this stream. */ 514 COREAUDIOUNIT Unit;510 COREAUDIOUNIT Unit; 515 511 /** Initialization status tracker. Used when some of the device parameters 516 512 * or the device itself is changed during the runtime. */ 517 volatile uint32_t enmStatus;513 volatile uint32_t enmStatus; 518 514 /** An internal ring buffer for transferring data from/to the rendering callbacks. */ 519 PRTCIRCBUF pCircBuf;515 PRTCIRCBUF pCircBuf; 520 516 } COREAUDIOSTREAM, *PCOREAUDIOSTREAM; 521 517 … … 1847 1843 OSStatus err; 1848 1844 if (pCAStream->enmDir == PDMAUDIODIR_IN) 1849 err = AudioQueueNewInput(&pCAStream->asbd Acq, coreAudioInputQueueCb, pCAStream /* pvData */,1845 err = AudioQueueNewInput(&pCAStream->asbdStream, coreAudioInputQueueCb, pCAStream /* pvData */, 1850 1846 CFRunLoopGetCurrent(), kCFRunLoopDefaultMode, 0, &pCAStream->audioQueue); 1851 1847 else 1852 err = AudioQueueNewOutput(&pCAStream->asbd Acq, coreAudioOutputQueueCb, pCAStream /* pvData */,1848 err = AudioQueueNewOutput(&pCAStream->asbdStream, coreAudioOutputQueueCb, pCAStream /* pvData */, 1853 1849 CFRunLoopGetCurrent(), kCFRunLoopDefaultMode, 0, &pCAStream->audioQueue); 1854 1850 … … 2143 2139 2144 2140 /* Create the recording device's out format based on our required audio settings. */ 2145 int rc = coreAudioStreamCfgToASBD(pCfgReq, &pCAStream->asbd Acq);2141 int rc = coreAudioStreamCfgToASBD(pCfgReq, &pCAStream->asbdStream); 2146 2142 if (RT_FAILURE(rc)) 2147 2143 { … … 2153 2149 coreAudioPrintASBD( fIn 2154 2150 ? "Capturing queue format" 2155 : "Playback queue format", &pCAStream->asbd Acq);2151 : "Playback queue format", &pCAStream->asbdStream); 2156 2152 2157 2153 rc = RTCircBufCreate(&pCAStream->pCircBuf, 8096 << 1 /*pHstStrmIn->Props.cShift*/); /** @todo FIX THIS !!! */ … … 3242 3238 3243 3239 uint32_t csWritten, cbWritten; 3244 uint8_t *puBuf; 3240 3241 uint8_t *pvChunk; 3242 size_t cbChunk; 3245 3243 3246 3244 Log3Func(("cbMixBuf=%zu, cbToWrite=%zu/%zu\n", cbMixBuf, cbToWrite, RTCircBufSize(pCAStream->pCircBuf))); … … 3249 3247 { 3250 3248 /* Try to acquire the necessary block from the ring buffer. */ 3251 size_t cbChunk; 3252 RTCircBufAcquireReadBlock(pCAStream->pCircBuf, cbToWrite, (void **)&puBuf, &cbChunk); 3249 RTCircBufAcquireReadBlock(pCAStream->pCircBuf, cbToWrite, (void **)&pvChunk, &cbChunk); 3253 3250 if (cbChunk) 3254 3251 { … … 3259 3256 if (RT_SUCCESS(rc)) 3260 3257 { 3261 RTFileWrite(fh, p uBuf, cbChunk, NULL);3258 RTFileWrite(fh, pvChunk, cbChunk, NULL); 3262 3259 RTFileClose(fh); 3263 3260 } … … 3265 3262 AssertFailed(); 3266 3263 #endif 3267 rc = AudioMixBufWriteCirc(&pStream->MixBuf, p uBuf, cbChunk, &csWritten);3264 rc = AudioMixBufWriteCirc(&pStream->MixBuf, pvChunk, cbChunk, &csWritten); 3268 3265 if (rc == VERR_BUFFER_OVERFLOW) 3269 3266 { … … 3296 3293 #ifdef LOG_ENABLED 3297 3294 uint32_t cbWrittenTotal = AUDIOMIXBUF_S2B(&pStream->MixBuf, csWrittenTotal); 3298 #endif3299 3295 Log3Func(("csWrittenTotal=%RU32 (%RU32 bytes), rc=%Rrc\n", csWrittenTotal, cbWrittenTotal, rc)); 3296 #endif 3300 3297 3301 3298 if (RT_SUCCESS(rc)) … … 3377 3374 Log3Func(("cbLive=%zu, cbToRead=%zu\n", cbLive, cbToRead)); 3378 3375 3376 uint8_t *pvChunk; 3377 size_t cbChunk; 3378 3379 3379 while (cbToRead) 3380 3380 { 3381 3381 uint32_t cRead, cbRead; 3382 uint8_t *puBuf;3383 size_t cbCopy;3384 3382 3385 3383 /* Try to acquire the necessary space from the ring buffer. */ 3386 RTCircBufAcquireWriteBlock(pCAStream->pCircBuf, cbToRead, (void **)&p uBuf, &cbCopy);3387 if (!cbC opy)3388 { 3389 RTCircBufReleaseWriteBlock(pCAStream->pCircBuf, cbC opy);3384 RTCircBufAcquireWriteBlock(pCAStream->pCircBuf, cbToRead, (void **)&pvChunk, &cbChunk); 3385 if (!cbChunk) 3386 { 3387 RTCircBufReleaseWriteBlock(pCAStream->pCircBuf, cbChunk); 3390 3388 break; 3391 3389 } 3392 3390 3393 Assert(cbCopy <= cbToRead); 3394 3395 rc = AudioMixBufReadCirc(&pStream->MixBuf, puBuf, cbCopy, &cRead); 3396 if ( RT_FAILURE(rc) 3397 || !cRead) 3398 { 3399 RTCircBufReleaseWriteBlock(pCAStream->pCircBuf, 0); 3391 Assert(cbChunk <= cbToRead); 3392 3393 rc = AudioMixBufReadCirc(&pStream->MixBuf, pvChunk, cbChunk, &cRead); 3394 3395 cbRead = AUDIOMIXBUF_S2B(&pStream->MixBuf, cRead); 3396 3397 /* Release the ring buffer, so the read thread could start reading this data. */ 3398 RTCircBufReleaseWriteBlock(pCAStream->pCircBuf, cbChunk); 3399 3400 if (RT_FAILURE(rc)) 3400 3401 break; 3401 }3402 3403 cbRead = AUDIOMIXBUF_S2B(&pStream->MixBuf, cRead);3404 3405 /* Release the ring buffer, so the read thread could start reading this data. */3406 RTCircBufReleaseWriteBlock(pCAStream->pCircBuf, cbRead);3407 3402 3408 3403 Assert(cbToRead >= cbRead); … … 3511 3506 3512 3507 case PDMAUDIOSTREAMCMD_DISABLE: 3513 {3514 3508 #ifdef VBOX_WITH_AUDIO_CA_QUEUES 3509 { 3515 3510 LogFunc(("Queue disable\n")); 3516 3511 AudioQueueStop(pCAStream->audioQueue, 1 /* Immediately */); 3517 3512 ASMAtomicXchgBool(&pCAStream->fRun, false); 3518 3513 ASMAtomicXchgBool(&pCAStream->fIsRunning, false); 3519 #endif3520 3514 break; 3521 3515 } 3522 3516 #endif 3523 3517 case PDMAUDIOSTREAMCMD_PAUSE: 3524 3518 { … … 3713 3707 if (RT_SUCCESS(rc)) 3714 3708 { 3709 ASMAtomicXchgU32(&pCAStream->enmStatus, COREAUDIOSTATUS_IN_INIT); 3710 3715 3711 #ifdef VBOX_WITH_AUDIO_CA_QUEUES 3716 ASMAtomicXchgU32(&pCAStream->enmStatus, COREAUDIOSTATUS_IN_INIT);3717 3718 3712 rc = coreAudioStreamInitQueue(pCAStream, pCfgReq, pCfgAcq); 3719 3720 pCfgAcq->cSampleBufferSize = _4K; /** @todo FIX THIS !!! */ 3713 if (RT_SUCCESS(rc)) 3714 { 3715 pCfgAcq->cSampleBufferSize = _4K; /** @todo FIX THIS !!! */ 3716 } 3721 3717 #else 3722 3718 if (fIn)
Note:
See TracChangeset
for help on using the changeset viewer.