vbox的更動 60305 路徑 trunk/src/VBox/Devices
- 時間撮記:
- 2016-4-4 下午03:19:44 (9 年 以前)
- 檔案:
-
- 修改 1 筆資料
圖例:
- 未更動
- 新增
- 刪除
-
trunk/src/VBox/Devices/Audio/DrvHostCoreAudio.cpp
r59991 r60305 295 295 AudioUnit audioUnit; 296 296 /** The audio converter if necessary. */ 297 AudioConverterRef converter;297 AudioConverterRef pConverter; 298 298 /** Native buffer used for render the audio data in the recording thread. */ 299 299 AudioBufferList bufferList; … … 411 411 PCOREAUDIOSTREAMIN pStreamIn = (PCOREAUDIOSTREAMIN)pHstStrmIn; 412 412 413 drvHostCoreAudioFiniIn(pInterface, &pStreamIn->streamIn); 414 415 coreAudioInitIn(&pStreamIn->streamIn, NULL /* pcSamples */); 416 drvHostCoreAudioControlIn(pInterface, &pStreamIn->streamIn, PDMAUDIOSTREAMCMD_ENABLE); 417 418 return VINF_SUCCESS; 413 int rc = drvHostCoreAudioFiniIn(pInterface, &pStreamIn->streamIn); 414 if (RT_SUCCESS(rc)) 415 { 416 rc = coreAudioInitIn(&pStreamIn->streamIn, NULL /* pcSamples */); 417 if (RT_SUCCESS(rc)) 418 rc = drvHostCoreAudioControlIn(pInterface, &pStreamIn->streamIn, PDMAUDIOSTREAMCMD_ENABLE); 419 } 420 421 if (RT_FAILURE(rc)) 422 LogRel(("CoreAudio: Unable to re-init input stream: %Rrc\n", rc)); 423 424 return rc; 419 425 } 420 426 … … 426 432 PCOREAUDIOSTREAMOUT pStreamOut = (PCOREAUDIOSTREAMOUT)pHstStrmOut; 427 433 428 drvHostCoreAudioFiniOut(pInterface, &pStreamOut->streamOut); 429 430 coreAudioInitOut(&pStreamOut->streamOut, NULL /* pcSamples */); 431 drvHostCoreAudioControlOut(pInterface, &pStreamOut->streamOut, PDMAUDIOSTREAMCMD_ENABLE); 432 433 return VINF_SUCCESS; 434 int rc = drvHostCoreAudioFiniOut(pInterface, &pStreamOut->streamOut); 435 if (RT_SUCCESS(rc)) 436 { 437 rc = coreAudioInitOut(&pStreamOut->streamOut, NULL /* pcSamples */); 438 if (RT_SUCCESS(rc)) 439 rc = drvHostCoreAudioControlOut(pInterface, &pStreamOut->streamOut, PDMAUDIOSTREAMCMD_ENABLE); 440 } 441 442 if (RT_FAILURE(rc)) 443 LogRel(("CoreAudio: Unable to re-init output stream: %Rrc\n", rc)); 444 445 return rc; 434 446 } 435 447 … … 548 560 { 549 561 /* Are we using a converter? */ 550 if (pStreamIn-> converter)562 if (pStreamIn->pConverter) 551 563 { 552 564 /* First, render the data as usual. */ … … 598 610 tmpList.mBuffers[0].mData = puDst; 599 611 600 AudioConverterReset(pStreamIn-> converter);601 602 err = AudioConverterFillComplexBuffer(pStreamIn-> converter, coreAudioConverterCb, pStreamIn,612 AudioConverterReset(pStreamIn->pConverter); 613 614 err = AudioConverterFillComplexBuffer(pStreamIn->pConverter, coreAudioConverterCb, pStreamIn, 603 615 &ioOutputDataPacketSize, &tmpList, NULL); 604 616 if( err != noErr … … 871 883 LogRel(("CoreAudio: Input converter is active\n")); 872 884 873 err = AudioConverterNew(&pStreamIn->deviceFormat, &pStreamIn->streamFormat, &pStreamIn-> converter);885 err = AudioConverterNew(&pStreamIn->deviceFormat, &pStreamIn->streamFormat, &pStreamIn->pConverter); 874 886 if (RT_UNLIKELY(err != noErr)) 875 887 { … … 890 902 const SInt32 channelMap[2] = {0, 0}; /* Channel map for mono -> stereo, */ 891 903 892 err = AudioConverterSetProperty(pStreamIn-> converter, kAudioConverterChannelMap, sizeof(channelMap), channelMap);904 err = AudioConverterSetProperty(pStreamIn->pConverter, kAudioConverterChannelMap, sizeof(channelMap), channelMap); 893 905 if (err != noErr) 894 906 { … … 987 999 } 988 1000 1001 /* Destroy any former internal ring buffer. */ 1002 if (pStreamIn->pBuf) 1003 { 1004 RTCircBufDestroy(pStreamIn->pBuf); 1005 pStreamIn->pBuf = NULL; 1006 } 1007 989 1008 /* Calculate the ratio between the device and the stream sample rate. */ 990 1009 pStreamIn->sampleRatio = pStreamIn->streamFormat.mSampleRate / pStreamIn->deviceFormat.mSampleRate; 991 1010 992 /* Set to zero first */993 pStreamIn->pBuf = NULL;994 1011 /* Create the AudioBufferList structure with one buffer. */ 995 1012 pStreamIn->bufferList.mNumberBuffers = 1; … … 1290 1307 } 1291 1308 1309 /* Destroy any former internal ring buffer. */ 1310 if (pStreamOut->pBuf) 1311 { 1312 RTCircBufDestroy(pStreamOut->pBuf); 1313 pStreamOut->pBuf = NULL; 1314 } 1315 1292 1316 /* Create the internal ring buffer. */ 1293 1317 rc = RTCircBufCreate(&pStreamOut->pBuf, cSamples << pHstStrmOut->Props.cShift); … … 1803 1827 } 1804 1828 1805 if (pStreamIn-> converter)1806 { 1807 AudioConverterDispose(pStreamIn-> converter);1808 pStreamIn-> converter = NULL;1829 if (pStreamIn->pConverter) 1830 { 1831 AudioConverterDispose(pStreamIn->pConverter); 1832 pStreamIn->pConverter = NULL; 1809 1833 } 1810 1834 … … 1815 1839 if (RT_LIKELY(err == noErr)) 1816 1840 { 1817 RTCircBufDestroy(pStreamIn->pBuf); 1818 1841 pStreamIn->deviceID = kAudioDeviceUnknown; 1819 1842 pStreamIn->audioUnit = NULL; 1820 pStreamIn->deviceID = kAudioDeviceUnknown; 1821 pStreamIn->pBuf = NULL; 1843 pStreamIn->offBufferRead = 0; 1822 1844 pStreamIn->sampleRatio = 1; 1823 pStreamIn->offBufferRead = 0; 1845 if (pStreamIn->pBuf) 1846 { 1847 RTCircBufDestroy(pStreamIn->pBuf); 1848 pStreamIn->pBuf = NULL; 1849 } 1824 1850 1825 1851 ASMAtomicXchgU32(&pStreamIn->status, CA_STATUS_UNINIT); … … 1911 1937 if (err == noErr) 1912 1938 { 1913 RTCircBufDestroy(pStreamOut->pBuf); 1914 pStreamOut->pBuf = NULL; 1915 1939 pStreamOut->deviceID = kAudioDeviceUnknown; 1916 1940 pStreamOut->audioUnit = NULL; 1917 pStreamOut->deviceID = kAudioDeviceUnknown; 1941 if (pStreamOut->pBuf) 1942 { 1943 RTCircBufDestroy(pStreamOut->pBuf); 1944 pStreamOut->pBuf = NULL; 1945 } 1918 1946 1919 1947 ASMAtomicXchgU32(&pStreamOut->status, CA_STATUS_UNINIT); … … 1939 1967 PCOREAUDIOSTREAMIN pStreamIn = (PCOREAUDIOSTREAMIN)pHstStrmIn; 1940 1968 1941 LogFlowFunc(("enmRecSource=%ld\n")); 1942 1943 ASMAtomicXchgU32(&pStreamIn->status, CA_STATUS_UNINIT); 1944 1945 pStreamIn->audioUnit = NULL; 1946 pStreamIn->deviceID = kAudioDeviceUnknown; 1947 pStreamIn->converter = NULL; 1948 pStreamIn->sampleRatio = 1; 1949 pStreamIn->offBufferRead = 0; 1950 1951 bool fDeviceByUser = false; 1969 LogFlowFunc(("enmRecSource=%ld\n", enmRecSource)); 1970 1971 pStreamIn->deviceID = kAudioDeviceUnknown; 1972 pStreamIn->audioUnit = NULL; 1973 pStreamIn->pConverter = NULL; 1974 pStreamIn->bufferList.mNumberBuffers = 0; 1975 pStreamIn->offBufferRead = 0; 1976 pStreamIn->sampleRatio = 1; 1977 pStreamIn->pBuf = NULL; 1978 pStreamIn->status = CA_STATUS_UNINIT; 1979 pStreamIn->fDefDevChgListReg = false; 1980 1981 bool fDeviceByUser = false; /* Do we use a device which was set by the user? */ 1952 1982 1953 1983 /* Initialize the hardware info section with the audio settings */ … … 1999 2029 PCOREAUDIOSTREAMOUT pStreamOut = (PCOREAUDIOSTREAMOUT)pHstStrmOut; 2000 2030 2001 OSStatus err = noErr;2002 int rc = 0;2003 bool fDeviceByUser = false; /* use we a device which was set by the user? */2004 2005 2031 LogFlowFuncEnter(); 2006 2032 2007 ASMAtomicXchgU32(&pStreamOut->status, CA_STATUS_UNINIT); 2008 2009 pStreamOut->audioUnit = NULL; 2010 pStreamOut->deviceID = kAudioDeviceUnknown; 2033 pStreamOut->deviceID = kAudioDeviceUnknown; 2034 pStreamOut->audioUnit = NULL; 2035 pStreamOut->pBuf = NULL; 2036 pStreamOut->status = CA_STATUS_UNINIT; 2037 pStreamOut->fDefDevChgListReg = false; 2038 2039 bool fDeviceByUser = false; /* Do we use a device which was set by the user? */ 2011 2040 2012 2041 /* Initialize the hardware info section with the audio settings */ 2013 DrvAudioStreamCfgToProps(pCfg, &pStreamOut->streamOut.Props); 2014 2042 int rc = DrvAudioStreamCfgToProps(pCfg, &pStreamOut->streamOut.Props); 2043 if (RT_SUCCESS(rc)) 2044 { 2015 2045 #if 0 2016 /* Try to find the audio device set by the user. Use2017 * export VBOX_COREAUDIO_OUTPUT_DEVICE_UID=AppleHDAEngineOutput:02018 * to set it. */2019 if (DeviceUID.pszOutputDeviceUID)2020 {2021 pStreamOut->audioDeviceId = drvHostCoreAudioDeviceUIDtoID(DeviceUID.pszOutputDeviceUID);2022 /* Not fatal */2023 if (pStreamOut->audioDeviceId == kAudioDeviceUnknown)2024 LogRel(("CoreAudio: Unable to find output device %s. Falling back to the default audio device. \n", DeviceUID.pszOutputDeviceUID));2025 else2026 fDeviceByUser = true;2027 }2046 /* Try to find the audio device set by the user. Use 2047 * export VBOX_COREAUDIO_OUTPUT_DEVICE_UID=AppleHDAEngineOutput:0 2048 * to set it. */ 2049 if (DeviceUID.pszOutputDeviceUID) 2050 { 2051 pStreamOut->audioDeviceId = drvHostCoreAudioDeviceUIDtoID(DeviceUID.pszOutputDeviceUID); 2052 /* Not fatal */ 2053 if (pStreamOut->audioDeviceId == kAudioDeviceUnknown) 2054 LogRel(("CoreAudio: Unable to find output device %s. Falling back to the default audio device. \n", DeviceUID.pszOutputDeviceUID)); 2055 else 2056 fDeviceByUser = true; 2057 } 2028 2058 #endif 2029 2030 rc = coreAudioInitOut(pHstStrmOut, pcSamples); 2031 if (RT_FAILURE(rc)) 2032 return rc; 2033 2034 /* When the devices isn't forced by the user, we want default device change notifications. */ 2035 if (!fDeviceByUser) 2036 { 2037 AudioObjectPropertyAddress propAdr = { kAudioHardwarePropertyDefaultOutputDevice, kAudioObjectPropertyScopeGlobal, 2038 kAudioObjectPropertyElementMaster }; 2039 err = AudioObjectAddPropertyListener(kAudioObjectSystemObject, &propAdr, 2040 coreAudioDefaultDeviceChanged, (void *)pStreamOut); 2041 /* Not fatal. */ 2042 if (RT_LIKELY(err == noErr)) 2043 { 2044 pStreamOut->fDefDevChgListReg = true; 2045 } 2046 else 2047 LogRel(("CoreAudio: Failed to add the default output device changed listener (%RI32)\n", err)); 2048 } 2049 2050 return VINF_SUCCESS; 2059 rc = coreAudioInitOut(pHstStrmOut, pcSamples); 2060 } 2061 2062 if (RT_SUCCESS(rc)) 2063 { 2064 /* When the devices isn't forced by the user, we want default device change notifications. */ 2065 if (!fDeviceByUser) 2066 { 2067 AudioObjectPropertyAddress propAdr = { kAudioHardwarePropertyDefaultOutputDevice, kAudioObjectPropertyScopeGlobal, 2068 kAudioObjectPropertyElementMaster }; 2069 OSStatus err = AudioObjectAddPropertyListener(kAudioObjectSystemObject, &propAdr, 2070 coreAudioDefaultDeviceChanged, (void *)pStreamOut); 2071 /* Not fatal. */ 2072 if (RT_LIKELY(err == noErr)) 2073 { 2074 pStreamOut->fDefDevChgListReg = true; 2075 } 2076 else 2077 LogRel(("CoreAudio: Failed to add the default output device changed listener (%RI32)\n", err)); 2078 } 2079 } 2080 2081 LogFlowFuncLeaveRC(rc); 2082 return rc; 2051 2083 } 2052 2084
注意:
瀏覽 TracChangeset
來幫助您使用更動檢視器