Changeset 55030 in vbox
- Timestamp:
- Mar 31, 2015 1:20:21 PM (9 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Devices/Audio/DrvHostCoreAudio.cpp
r54851 r55030 268 268 { 269 269 /** Host stream out. */ 270 PDMAUDIOHSTSTRMOUT streamOut;270 PDMAUDIOHSTSTRMOUT streamOut; 271 271 /* Stream description which is default on the device */ 272 272 AudioStreamBasicDescription deviceFormat; … … 274 274 AudioStreamBasicDescription streamFormat; 275 275 /* The audio device ID of the currently used device */ 276 AudioDeviceID deviceID;276 AudioDeviceID deviceID; 277 277 /* The AudioUnit used */ 278 AudioUnit audioUnit;278 AudioUnit audioUnit; 279 279 /* A ring buffer for transferring data to the playback thread. */ 280 PRTCIRCBUF pBuf;280 PRTCIRCBUF pBuf; 281 281 /* Temporary buffer for copying over audio data into Core Audio. */ 282 void *pvPCMBuf;282 void *pvPCMBuf; 283 283 /** Size of the temporary buffer. */ 284 size_t cbPCMBuf;284 size_t cbPCMBuf; 285 285 /* Initialization status tracker. Used when some of the device parameters 286 286 * or the device itself is changed during the runtime. */ 287 volatile uint32_t status; 287 volatile uint32_t status; 288 /** Flag whether the "default device changed" listener was registered. */ 289 bool fDefDevChgListReg; 288 290 } COREAUDIOSTREAMOUT, *PCOREAUDIOSTREAMOUT; 289 291 … … 291 293 { 292 294 /** Host stream in. */ 293 PDMAUDIOHSTSTRMIN streamIn;295 PDMAUDIOHSTSTRMIN streamIn; 294 296 /* Stream description which is default on the device */ 295 297 AudioStreamBasicDescription deviceFormat; … … 297 299 AudioStreamBasicDescription streamFormat; 298 300 /* The audio device ID of the currently used device */ 299 AudioDeviceID deviceID;301 AudioDeviceID deviceID; 300 302 /* The AudioUnit used */ 301 AudioUnit audioUnit;303 AudioUnit audioUnit; 302 304 /* The audio converter if necessary */ 303 AudioConverterRef converter;305 AudioConverterRef converter; 304 306 /* A temporary position value used in the caConverterCallback function */ 305 uint32_t rpos;307 uint32_t rpos; 306 308 /* The ratio between the device & the stream sample rate */ 307 Float64 sampleRatio;309 Float64 sampleRatio; 308 310 /* An extra buffer used for render the audio data in the recording thread */ 309 AudioBufferList bufferList;311 AudioBufferList bufferList; 310 312 /* A ring buffer for transferring data from the recording thread */ 311 PRTCIRCBUF pBuf;313 PRTCIRCBUF pBuf; 312 314 /* Initialization status tracker. Used when some of the device parameters 313 315 * or the device itself is changed during the runtime. */ 314 volatile uint32_t status; 316 volatile uint32_t status; 317 /** Flag whether the "default device changed" listener was registered. */ 318 bool fDefDevChgListReg; 315 319 } COREAUDIOSTREAMIN, *PCOREAUDIOSTREAMIN; 316 320 … … 1227 1231 if (RT_SUCCESS(rc)) 1228 1232 { 1233 /* Allocate temporary buffer. */ 1234 pStreamOut->cbPCMBuf = _4K; /** @todo Make this configurable. */ 1235 pStreamOut->pvPCMBuf = RTMemAlloc(pStreamOut->cbPCMBuf); 1236 if (!pStreamOut->pvPCMBuf) 1237 rc = VERR_NO_MEMORY; 1238 } 1239 1240 if (RT_SUCCESS(rc)) 1241 { 1242 /* 1243 * Register callbacks. 1244 */ 1229 1245 #ifdef DEBUG 1230 1246 propAdr.mSelector = kAudioDeviceProcessorOverload; … … 1243 1259 if (err != noErr) 1244 1260 LogRel(("CoreAudio: Failed to register sample rate changed listener for output stream (%RI32)\n", err)); 1245 1246 /* Allocate temporary buffer. */1247 pStreamOut->cbPCMBuf = _4K; /** @todo Make this configurable. */1248 pStreamOut->pvPCMBuf = RTMemAlloc(pStreamOut->cbPCMBuf);1249 if (!pStreamOut->pvPCMBuf)1250 rc = VERR_NO_MEMORY;1251 1261 } 1252 1262 … … 1694 1704 { 1695 1705 ASMAtomicXchgU32(&pStreamIn->status, CA_STATUS_IN_UNINIT); 1706 1707 /* 1708 * Unregister input device callbacks. 1709 */ 1696 1710 AudioObjectPropertyAddress propAdr = { kAudioDeviceProcessorOverload, kAudioUnitScope_Global, 1697 1711 kAudioObjectPropertyElementMaster }; … … 1703 1717 LogRel(("CoreAudio: Failed to remove the processor overload listener (%RI32)\n", err)); 1704 1718 #endif /* DEBUG */ 1719 1705 1720 propAdr.mSelector = kAudioDevicePropertyNominalSampleRate; 1706 1721 err = AudioObjectRemovePropertyListener(pStreamIn->deviceID, &propAdr, … … 1710 1725 LogRel(("CoreAudio: Failed to remove the sample rate changed listener (%RI32)\n", err)); 1711 1726 1727 if (pStreamIn->fDefDevChgListReg) 1728 { 1729 err = AudioHardwareRemovePropertyListener(kAudioHardwarePropertyDefaultInputDevice, 1730 drvHostCoreAudioDefaultDeviceChanged); 1731 if (RT_LIKELY(err == noErr)) 1732 { 1733 pStreamIn->fDefDevChgListReg = false; 1734 } 1735 else 1736 LogRel(("CoreAudio: [Output] Failed to remove the default input device changed listener (%RI32)\n", err)); 1737 } 1738 1712 1739 if (pStreamIn->converter) 1713 1740 { … … 1715 1742 pStreamIn->converter = NULL; 1716 1743 } 1744 1717 1745 err = AudioUnitUninitialize(pStreamIn->audioUnit); 1718 1746 if (RT_LIKELY(err == noErr)) … … 1722 1750 { 1723 1751 RTCircBufDestroy(pStreamIn->pBuf); 1752 1724 1753 pStreamIn->audioUnit = NULL; 1725 1754 pStreamIn->deviceID = kAudioDeviceUnknown; … … 1727 1756 pStreamIn->sampleRatio = 1; 1728 1757 pStreamIn->rpos = 0; 1758 1729 1759 ASMAtomicXchgU32(&pStreamIn->status, CA_STATUS_UNINIT); 1730 1760 } … … 1771 1801 { 1772 1802 ASMAtomicXchgU32(&pStreamOut->status, CA_STATUS_IN_UNINIT); 1773 #if 0 1774 err = AudioDeviceRemovePropertyListener(pStreamOut->audioDeviceId, 0, false, 1775 kAudioDeviceProcessorOverload, drvHostCoreAudioPlaybackAudioDevicePropertyChanged); 1776 /* Not Fatal */ 1777 if (RT_UNLIKELY(err != noErr)) 1778 LogRel(("CoreAudio: Failed to remove the processor overload listener (%RI32)\n", err)); 1779 #endif /* DEBUG */ 1780 OSStatus err = AudioUnitUninitialize(pStreamOut->audioUnit); 1803 1804 OSStatus err; 1805 if (pStreamOut->fDefDevChgListReg) 1806 { 1807 err = AudioHardwareRemovePropertyListener(kAudioHardwarePropertyDefaultOutputDevice, 1808 drvHostCoreAudioDefaultDeviceChanged); 1809 if (RT_LIKELY(err == noErr)) 1810 { 1811 pStreamOut->fDefDevChgListReg = false; 1812 } 1813 else 1814 LogRel(("CoreAudio: [Output] Failed to remove the default playback device changed listener (%RI32)\n", err)); 1815 } 1816 1817 err = AudioUnitUninitialize(pStreamOut->audioUnit); 1781 1818 if (err == noErr) 1782 1819 { … … 1860 1897 drvHostCoreAudioDefaultDeviceChanged, (void *)pStreamIn); 1861 1898 /* Not fatal. */ 1862 if (err != noErr) 1863 LogRel(("CoreAudio: Failed to register the default input device changed listener (%RI32)\n", err)); 1899 if (RT_LIKELY(err == noErr)) 1900 { 1901 pStreamIn->fDefDevChgListReg = true; 1902 } 1903 else 1904 LogRel(("CoreAudio: Failed to add the default input device changed listener (%RI32)\n", err)); 1864 1905 } 1865 1906 } … … 1916 1957 drvHostCoreAudioDefaultDeviceChanged, (void *)pStreamOut); 1917 1958 /* Not fatal. */ 1918 if (err != noErr) 1919 LogRel(("CoreAudio: Failed to register default device changed listener (%RI32)\n", err)); 1959 if (RT_LIKELY(err == noErr)) 1960 { 1961 pStreamOut->fDefDevChgListReg = true; 1962 } 1963 else 1964 LogRel(("CoreAudio: Failed to add the default output device changed listener (%RI32)\n", err)); 1920 1965 } 1921 1966
Note:
See TracChangeset
for help on using the changeset viewer.

