Changeset 59378 in vbox for trunk/src/VBox/Devices/Audio
- Timestamp:
- Jan 18, 2016 1:58:08 PM (9 years ago)
- svn:sync-xref-src-repo-rev:
- 105069
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Devices/Audio/DrvHostCoreAudio.cpp
r59375 r59378 562 562 if (err != noErr) 563 563 { 564 Log FlowFunc(("Failed rendering audiodata (%RI32)\n", err));564 LogRel2(("CoreAudio: Failed rendering converted audio input data (%RI32)\n", err)); 565 565 rc = VERR_IO_GEN_FAILURE; /** @todo Improve this. */ 566 566 break; … … 623 623 else /* No converter being used. */ 624 624 { 625 AssertBreakStmt(pStreamIn->streamFormat.mChannelsPerFrame >= 1, rc = VERR_INVALID_PARAMETER); 626 AssertBreakStmt(pStreamIn->streamFormat.mBytesPerFrame >= 1, rc = VERR_INVALID_PARAMETER); 627 628 AssertBreakStmt(pStreamIn->bufferList.mNumberBuffers >= 1, rc = VERR_INVALID_PARAMETER); 629 AssertBreakStmt(pStreamIn->bufferList.mBuffers[0].mNumberChannels, rc = VERR_INVALID_PARAMETER); 630 625 631 pStreamIn->bufferList.mBuffers[0].mNumberChannels = pStreamIn->streamFormat.mChannelsPerFrame; 626 632 pStreamIn->bufferList.mBuffers[0].mDataByteSize = pStreamIn->streamFormat.mBytesPerFrame * cFrames; 627 AssertBreakStmt(pStreamIn->bufferList.mBuffers[0].mDataByteSize, rc = VERR_INVALID_PARAMETER);628 633 pStreamIn->bufferList.mBuffers[0].mData = RTMemAlloc(pStreamIn->bufferList.mBuffers[0].mDataByteSize); 629 634 if (!pStreamIn->bufferList.mBuffers[0].mData) … … 636 641 if (err != noErr) 637 642 { 638 Log FlowFunc(("Failed rendering audiodata (%RI32)\n", err));643 LogRel2(("CoreAudio: Failed rendering non-coverted audio input data (%RI32)\n", err)); 639 644 rc = VERR_IO_GEN_FAILURE; /** @todo Improve this. */ 640 645 break; 641 646 } 642 647 643 size_t cbAvail = RT_MIN(RTCircBufFree(pStreamIn->pBuf), pStreamIn->bufferList.mBuffers[0].mDataByteSize); 648 const uint32_t cbDataSize = pStreamIn->bufferList.mBuffers[0].mDataByteSize; 649 const size_t cbBufFree = RTCircBufFree(pStreamIn->pBuf); 650 size_t cbAvail = RT_MIN(cbDataSize, cbBufFree); 651 652 LogFlowFunc(("cbDataSize=%RU32, cbBufFree=%zu, cbAvail=%zu\n", cbDataSize, cbBufFree, cbAvail)); 644 653 645 654 /* Iterate as long as data is available. */ 646 655 uint8_t *puDst = NULL; 647 656 uint32_t cbWrittenTotal = 0; 648 while (cbAvail)657 while (cbAvail) 649 658 { 650 659 /* Try to acquire the necessary space from the ring buffer. */ … … 654 663 break; 655 664 656 /* Copy the data from the core audio buffer to the ring buffer. */665 /* Copy the data from the Core Audio buffer to the ring buffer. */ 657 666 memcpy(puDst, (uint8_t *)pStreamIn->bufferList.mBuffers[0].mData + cbWrittenTotal, cbToWrite); 658 667 … … 665 674 cbAvail -= cbToWrite; 666 675 } 676 677 LogFlowFunc(("cbWrittenTotal=%RU32, cbLeft=%zu\n", cbWrittenTotal, cbAvail)); 667 678 } 668 679 … … 675 686 } 676 687 688 LogFlowFuncLeaveRC(rc); 677 689 return err; 678 690 } … … 760 772 return VERR_AUDIO_BACKEND_INIT_FAILED; 761 773 } 774 775 LogFlowFunc(("cFrames=%RU32\n", cFrames)); 762 776 763 777 ComponentDescription cd; … … 882 896 /* Set the new input format description for the stream. */ 883 897 err = AudioUnitSetProperty(pStreamIn->audioUnit, kAudioUnitProperty_StreamFormat, kAudioUnitScope_Input, 884 1, &pStreamIn-> deviceFormat, sizeof(pStreamIn->deviceFormat));898 1, &pStreamIn->streamFormat, sizeof(pStreamIn->streamFormat)); 885 899 if (err != noErr) 886 900 { … … 898 912 LogRel(("CoreAudio: Input converter is active\n")); 899 913 } 900 901 /* Set the new output format description for the stream. */ 902 err = AudioUnitSetProperty(pStreamIn->audioUnit, kAudioUnitProperty_StreamFormat, kAudioUnitScope_Output, 903 1, &pStreamIn->deviceFormat, sizeof(pStreamIn->deviceFormat)); 904 if (err != noErr) 905 { 906 LogRel(("CoreAudio: Failed to set output format for input stream (%RI32)\n", err)); 907 return VERR_AUDIO_BACKEND_INIT_FAILED; 914 else 915 { 916 /* Set the new output format description for the stream. */ 917 err = AudioUnitSetProperty(pStreamIn->audioUnit, kAudioUnitProperty_StreamFormat, kAudioUnitScope_Output, 918 1, &pStreamIn->streamFormat, sizeof(pStreamIn->streamFormat)); 919 if (err != noErr) 920 { 921 LogRel(("CoreAudio: Failed to set output format for input stream (%RI32)\n", err)); 922 return VERR_AUDIO_BACKEND_INIT_FAILED; /** @todo Fudge! */ 923 } 908 924 } 909 925 … … 943 959 */ 944 960 uSize = sizeof(cFrames); 945 err = AudioUnitGetProperty(pStreamIn->audioUnit, kAudioUnitProperty_MaximumFramesPerSlice, kAudioUnitScope_Global,961 err = AudioUnitGetProperty(pStreamIn->audioUnit, kAudioUnitProperty_MaximumFramesPerSlice, kAudioUnitScope_Global, 946 962 0, &cFrames, &uSize); 947 963 if (err != noErr) … … 972 988 * samples count. 973 989 */ 974 UInt32 cSamples = cFrames * pStreamIn->streamFormat.mChannelsPerFrame; 990 UInt32 cSamples = RT_MAX(cFrames, 991 (cFrames * pStreamIn->deviceFormat.mBytesPerFrame * pStreamIn->sampleRatio) 992 / pStreamIn->streamFormat.mBytesPerFrame) 993 * pStreamIn->streamFormat.mChannelsPerFrame; 975 994 if (!cSamples) 976 995 { … … 1338 1357 { 1339 1358 size_t cbBuf = AudioMixBufSizeBytes(&pHstStrmIn->MixBuf); 1340 size_t cbToWrite = RT_MIN(cbBuf, RTCircBufFree(pStreamIn->pBuf)); 1341 LogFlowFunc(("cbToWrite=%zu\n", cbToWrite)); 1359 size_t cbToWrite = RT_MIN(cbBuf, RTCircBufUsed(pStreamIn->pBuf)); 1342 1360 1343 1361 uint32_t cWritten, cbWritten; … … 1345 1363 size_t cbToRead; 1346 1364 1365 LogFlowFunc(("cbBuf=%zu, cbToWrite=%zu\n", cbBuf, cbToWrite)); 1366 1347 1367 while (cbToWrite) 1348 1368 { … … 1365 1385 1366 1386 Assert(cbToWrite >= cbWritten); 1367 cbToWrite -= cbWritten;1387 cbToWrite -= cbWritten; 1368 1388 cbWrittenTotal += cbWritten; 1369 1389 } 1390 1391 LogFlowFunc(("cbToWrite=%zu, cbWrittenTotal=%RU32\n", cbToWrite, cbWrittenTotal)); 1370 1392 } 1371 1393 while (0); … … 1373 1395 if (RT_SUCCESS(rc)) 1374 1396 { 1397 uint32_t cCaptured = 0; 1375 1398 uint32_t cWrittenTotal = AUDIOMIXBUF_B2S(&pHstStrmIn->MixBuf, cbWrittenTotal); 1376 1399 if (cWrittenTotal) 1377 AudioMixBufFinish(&pHstStrmIn->MixBuf, cWrittenTotal);1378 1379 LogFlowFunc(("cWrittenTotal=%RU32 (%RU32 bytes) \n", cWrittenTotal, cbWrittenTotal));1400 rc = AudioMixBufMixToParent(&pHstStrmIn->MixBuf, cWrittenTotal, &cCaptured); 1401 1402 LogFlowFunc(("cWrittenTotal=%RU32 (%RU32 bytes), cCaptured, rc=%Rrc\n", cWrittenTotal, cbWrittenTotal, cCaptured, rc)); 1380 1403 1381 1404 if (pcSamplesCaptured) 1382 *pcSamplesCaptured = cWrittenTotal; 1383 } 1384 1405 *pcSamplesCaptured = cCaptured; 1406 } 1407 1408 LogFlowFuncLeaveRC(rc); 1385 1409 return rc; 1386 1410 }
Note:
See TracChangeset
for help on using the changeset viewer.