Changeset 63444 in vbox for trunk/src/VBox/Devices/Audio
- Timestamp:
- Aug 14, 2016 11:11:25 PM (9 years ago)
- svn:sync-xref-src-repo-rev:
- 110091
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Devices/Audio/DrvHostCoreAudio.cpp
r63362 r63444 1 1 /* $Id$ */ 2 2 /** @file 3 * VBox audio devices :Mac OS X CoreAudio audio driver.3 * VBox audio devices - Mac OS X CoreAudio audio driver. 4 4 */ 5 5 … … 15 15 * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind. 16 16 */ 17 18 /********************************************************************************************************************************* 19 * Header Files * 20 *********************************************************************************************************************************/ 17 21 #define LOG_GROUP LOG_GROUP_DRV_HOST_AUDIO 18 22 #include <VBox/log.h> … … 59 63 */ 60 64 61 /**62 * Host Coreaudio driver instance data.63 * @implements PDMIAUDIOCONNECTOR64 */65 typedef struct DRVHOSTCOREAUDIO66 {67 /** Pointer to the driver instance structure. */68 PPDMDRVINS pDrvIns;69 /** Pointer to host audio interface. */70 PDMIHOSTAUDIO IHostAudio;71 } DRVHOSTCOREAUDIO, *PDRVHOSTCOREAUDIO;72 65 73 66 /******************************************************************************* … … 76 69 * 77 70 ******************************************************************************/ 71 72 /* Move these down below the internal function prototypes... */ 78 73 79 74 static void coreAudioPrintASBD(const char *pszDesc, const AudioStreamBasicDescription *pASBD) … … 261 256 } 262 257 263 /******************************************************************************* 264 * 265 * Global structures section 266 * 267 ******************************************************************************/ 268 269 /* Initialization status indicator used for the recreation of the AudioUnits. */ 270 #define CA_STATUS_UNINIT UINT32_C(0) /* The device is uninitialized */ 271 #define CA_STATUS_IN_INIT UINT32_C(1) /* The device is currently initializing */ 272 #define CA_STATUS_INIT UINT32_C(2) /* The device is initialized */ 273 #define CA_STATUS_IN_UNINIT UINT32_C(3) /* The device is currently uninitializing */ 274 #define CA_STATUS_REINIT UINT32_C(4) /* The device has to be reinitialized */ 275 258 /********************************************************************************************************************************* 259 * Defined Constants And Macros * 260 *********************************************************************************************************************************/ 261 /** @todo r=bird: The three API calls we use for finding, opening and closing 262 * the default audio component are deprecated since 10.8. This define switches 263 * over to using the replacement/renamed APIs introduced in 10.6+ */ 264 #ifdef DEBUG_bird 265 # define USE_NON_DEPRECATED_APIS 266 #endif 267 268 /** @name Initialization status indicator used for the recreation of the AudioUnits. 269 * @{ */ 270 #define CA_STATUS_UNINIT UINT32_C(0) /**< The device is uninitialized */ 271 #define CA_STATUS_IN_INIT UINT32_C(1) /**< The device is currently initializing */ 272 #define CA_STATUS_INIT UINT32_C(2) /**< The device is initialized */ 273 #define CA_STATUS_IN_UNINIT UINT32_C(3) /**< The device is currently uninitializing */ 274 #define CA_STATUS_REINIT UINT32_C(4) /**< The device has to be reinitialized */ 275 /** @} */ 276 277 278 /********************************************************************************************************************************* 279 * Global Variables * 280 *********************************************************************************************************************************/ 276 281 /* Error code which indicates "End of data" */ 277 static const OSStatus caConverterEOFDErr = 0x656F6664; /* 'eofd' */ 278 282 static const OSStatus g_caConverterEOFDErr = 0x656F6664; /* 'eofd' */ 283 284 285 /********************************************************************************************************************************* 286 * Structures and Typedefs * 287 *********************************************************************************************************************************/ 279 288 /* Prototypes needed for COREAUDIOSTREAMCBCTX. */ 280 289 struct COREAUDIOSTREAMIN; … … 282 291 struct COREAUDIOSTREAMOUT; 283 292 typedef struct COREAUDIOSTREAMOUT *PCOREAUDIOSTREAMOUT; 293 294 /** 295 * Host Coreaudio driver instance data. 296 * @implements PDMIAUDIOCONNECTOR 297 */ 298 typedef struct DRVHOSTCOREAUDIO 299 { 300 /** Pointer to the driver instance structure. */ 301 PPDMDRVINS pDrvIns; 302 /** Pointer to host audio interface. */ 303 PDMIHOSTAUDIO IHostAudio; 304 } DRVHOSTCOREAUDIO, *PDRVHOSTCOREAUDIO; 305 284 306 285 307 /** … … 388 410 389 411 412 /********************************************************************************************************************************* 413 * Internal Functions * 414 *********************************************************************************************************************************/ 390 415 static int coreAudioInitIn(PDRVHOSTCOREAUDIO pThis, PPDMAUDIOSTREAM pStream, PPDMAUDIOSTREAMCFG pCfgReq, PPDMAUDIOSTREAMCFG pCfgAcq); 391 416 static int coreAudioInitOut(PDRVHOSTCOREAUDIO pThis, PPDMAUDIOSTREAM pStream, PPDMAUDIOSTREAMCFG pCfgReq, PPDMAUDIOSTREAMCFG pCfgAcq); … … 399 424 static OSStatus coreAudioPlaybackAudioDevicePropertyChanged(AudioObjectID propertyID, UInt32 nAddresses, const AudioObjectPropertyAddress properties[], void *pvUser); 400 425 static OSStatus coreAudioPlaybackCb(void *pvUser, AudioUnitRenderActionFlags *pActionFlags, const AudioTimeStamp *pAudioTS, UInt32 uBusID, UInt32 cFrames, AudioBufferList* pBufData); 426 401 427 402 428 /** … … 807 833 void *pvUser) 808 834 { 809 AssertPtrReturn(ioNumberDataPackets, caConverterEOFDErr);810 AssertPtrReturn(ioData, caConverterEOFDErr);835 AssertPtrReturn(ioNumberDataPackets, g_caConverterEOFDErr); 836 AssertPtrReturn(ioData, g_caConverterEOFDErr); 811 837 812 838 PCOREAUDIOCONVCBCTX pConvCbCtx = (PCOREAUDIOCONVCBCTX)pvUser; … … 1088 1114 } 1089 1115 1090 # define CA_BREAK_STMT(stmt) \ 1091 stmt; \ 1092 break; 1116 #define CA_BREAK_STMT(stmt) if (true) \ 1117 { \ 1118 stmt; \ 1119 break; \ 1120 } else do { } while (0) 1093 1121 1094 1122 /** @todo Eventually split up this function, as this already is huge! */ … … 1204 1232 LogFlowFunc(("cFrames=%RU32\n", cFrames)); 1205 1233 1234 /* Try to find the default HAL output component. */ 1235 #ifdef USE_NON_DEPRECATED_APIS 1236 AudioComponentDescription cd; 1237 #else 1206 1238 ComponentDescription cd; 1239 #endif 1207 1240 RT_ZERO(cd); 1208 1241 cd.componentType = kAudioUnitType_Output; 1209 1242 cd.componentSubType = kAudioUnitSubType_HALOutput; 1210 1243 cd.componentManufacturer = kAudioUnitManufacturer_Apple; 1211 1212 /* Try to find the default HAL output component. */ 1244 #ifdef USE_NON_DEPRECATED_APIS 1245 AudioComponent cp = AudioComponentFindNext(NULL, &cd); 1246 #else 1213 1247 Component cp = FindNextComponent(NULL, &cd); 1248 #endif 1214 1249 if (cp == 0) 1215 1250 { … … 1219 1254 1220 1255 /* Open the default HAL output component. */ 1256 #ifdef USE_NON_DEPRECATED_APIS 1257 err = AudioComponentInstanceNew(cp, &pStreamIn->audioUnit); 1258 #else 1221 1259 err = OpenAComponent(cp, &pStreamIn->audioUnit); 1260 #endif 1222 1261 if (err != noErr) 1223 1262 { … … 1617 1656 } 1618 1657 1658 /* Try to find the default HAL output component. */ 1659 #ifdef USE_NON_DEPRECATED_APIS 1660 AudioComponentDescription cd; 1661 #else 1619 1662 ComponentDescription cd; 1663 #endif 1620 1664 RT_ZERO(cd); 1621 1665 cd.componentType = kAudioUnitType_Output; 1622 1666 cd.componentSubType = kAudioUnitSubType_HALOutput; 1623 1667 cd.componentManufacturer = kAudioUnitManufacturer_Apple; 1624 1625 /* Try to find the default HAL output component. */ 1668 #ifdef USE_NON_DEPRECATED_APIS 1669 AudioComponent cp = AudioComponentFindNext(NULL, &cd); 1670 #else 1626 1671 Component cp = FindNextComponent(NULL, &cd); 1672 #endif 1627 1673 if (cp == 0) 1628 1674 { … … 1632 1678 1633 1679 /* Open the default HAL output component. */ 1680 #ifdef USE_NON_DEPRECATED_APIS 1681 err = AudioComponentInstanceNew(cp, &pStreamOut->audioUnit); 1682 #else 1634 1683 err = OpenAComponent(cp, &pStreamOut->audioUnit); 1684 #endif 1635 1685 if (err != noErr) 1636 1686 { … … 1905 1955 } 1906 1956 1957 1958 /** 1959 * @interface_method_impl{PDMIHOSTAUDIO, pfnInit} 1960 * 1961 * @todo Please put me next to the shutdown function, because then it would be 1962 * clear why I'm empty. While at it, it would be nice if you also 1963 * reordered my PDMIHOSTAUDIO sibilings according to the interface 1964 * (doesn't matter if it's reversed (like all other PDM drivers and 1965 * devices) or not). 1966 */ 1907 1967 static DECLCALLBACK(int) drvHostCoreAudioInit(PPDMIHOSTAUDIO pInterface) 1908 1968 { … … 1914 1974 } 1915 1975 1976 /** 1977 * @interface_method_impl{PDMIHOSTAUDIO, pfnStreamCapture} 1978 */ 1916 1979 static DECLCALLBACK(int) drvHostCoreAudioStreamCapture(PPDMIHOSTAUDIO pInterface, PPDMAUDIOSTREAM pStream, 1917 1980 void *pvBuf, uint32_t cbBuf, uint32_t *pcbRead) 1918 1981 { 1982 RT_NOREF(pvBuf, cbBuf); /** @todo r=bird: this looks totally weird at first glance! */ 1983 1919 1984 AssertPtrReturn(pInterface, VERR_INVALID_POINTER); 1920 1985 AssertPtrReturn(pStream, VERR_INVALID_POINTER); … … 1942 2007 do 1943 2008 { 1944 size_t cb Buf= AudioMixBufSizeBytes(&pStream->MixBuf);1945 size_t cbToWrite = RT_MIN(cb Buf, RTCircBufUsed(pStreamIn->pCircBuf));2009 size_t cbMixBuf = AudioMixBufSizeBytes(&pStream->MixBuf); 2010 size_t cbToWrite = RT_MIN(cbMixBuf, RTCircBufUsed(pStreamIn->pCircBuf)); 1946 2011 1947 2012 uint32_t cWritten, cbWritten; … … 1949 2014 size_t cbToRead; 1950 2015 1951 Log3Func(("cb Buf=%zu, cbToWrite=%zu/%zu\n", cbBuf, cbToWrite, RTCircBufSize(pStreamIn->pCircBuf)));2016 Log3Func(("cbMixBuf=%zu, cbToWrite=%zu/%zu\n", cbMixBuf, cbToWrite, RTCircBufSize(pStreamIn->pCircBuf))); 1952 2017 1953 2018 while (cbToWrite) … … 2021 2086 } 2022 2087 2088 /** 2089 * @interface_method_impl{PDMIHOSTAUDIO, pfnStreamPlay} 2090 */ 2023 2091 PDMAUDIO_IHOSTAUDIO_EMIT_STREAMPLAY(drvHostCoreAudio) 2024 2092 { … … 2331 2399 err = AudioUnitUninitialize(pStreamIn->audioUnit); 2332 2400 if (err == noErr) 2401 #ifdef USE_NON_DEPRECATED_APIS 2402 err = AudioComponentInstanceDispose(pStreamIn->audioUnit); 2403 #else 2333 2404 err = CloseComponent(pStreamIn->audioUnit); 2405 #endif 2334 2406 2335 2407 if ( err != noErr … … 2442 2514 err = AudioUnitUninitialize(pStreamOut->audioUnit); 2443 2515 if (err == noErr) 2516 #ifdef USE_NON_DEPRECATED_APIS 2517 err = AudioComponentInstanceDispose(pStreamOut->audioUnit); 2518 #else 2444 2519 err = CloseComponent(pStreamOut->audioUnit); 2520 #endif 2445 2521 2446 2522 if ( err != noErr … … 2633 2709 } 2634 2710 2711 2712 /** 2713 * @interface_method_impl{PDMIHOSTAUDIO, pfnGetConfig} 2714 */ 2635 2715 PDMAUDIO_IHOSTAUDIO_EMIT_GETCONFIG(drvHostCoreAudio) 2636 2716 { … … 2644 2724 } 2645 2725 2726 2727 /** 2728 * @interface_method_impl{PDMIHOSTAUDIO, pfnStreamGetStatus} 2729 */ 2646 2730 PDMAUDIO_IHOSTAUDIO_EMIT_GETSTATUS(drvHostCoreAudio) 2647 2731 { … … 2651 2735 } 2652 2736 2737 2738 /** 2739 * @interface_method_impl{PDMIHOSTAUDIO, pfnStreamCreate} 2740 */ 2653 2741 PDMAUDIO_IHOSTAUDIO_EMIT_STREAMCREATE(drvHostCoreAudio) 2654 2742 { … … 2671 2759 } 2672 2760 2761 2762 /** 2763 * @interface_method_impl{PDMIHOSTAUDIO, pfnStreamDestroy} 2764 */ 2673 2765 PDMAUDIO_IHOSTAUDIO_EMIT_STREAMDESTROY(drvHostCoreAudio) 2674 2766 { … … 2688 2780 } 2689 2781 2782 2783 /** 2784 * @interface_method_impl{PDMIHOSTAUDIO, pfnStreamControl} 2785 */ 2690 2786 PDMAUDIO_IHOSTAUDIO_EMIT_STREAMCONTROL(drvHostCoreAudio) 2691 2787 { … … 2707 2803 } 2708 2804 2805 2806 /** 2807 * @interface_method_impl{PDMIHOSTAUDIO, pfnStreamGetStatus} 2808 */ 2709 2809 PDMAUDIO_IHOSTAUDIO_EMIT_STREAMGETSTATUS(drvHostCoreAudio) 2710 2810 { … … 2742 2842 } 2743 2843 2844 2845 /** 2846 * @interface_method_impl{PDMIHOSTAUDIO, pfnStreamIterate} 2847 */ 2744 2848 PDMAUDIO_IHOSTAUDIO_EMIT_STREAMITERATE(drvHostCoreAudio) 2745 2849 { … … 2751 2855 } 2752 2856 2857 2858 /** 2859 * @interface_method_impl{PDMIHOSTAUDIO, pfnShutdown} 2860 */ 2753 2861 PDMAUDIO_IHOSTAUDIO_EMIT_SHUTDOWN(drvHostCoreAudio) 2754 2862 { … … 2756 2864 } 2757 2865 2866 2867 /** 2868 * @interface_method_impl{PDMIBASE,pfnQueryInterface} 2869 */ 2758 2870 static DECLCALLBACK(void *) drvHostCoreAudioQueryInterface(PPDMIBASE pInterface, const char *pszIID) 2759 2871 { 2760 PPDMDRVINS pDrvIns= PDMIBASE_2_PDMDRV(pInterface);2761 PDRVHOSTCOREAUDIO pThis= PDMINS_2_DATA(pDrvIns, PDRVHOSTCOREAUDIO);2872 PPDMDRVINS pDrvIns = PDMIBASE_2_PDMDRV(pInterface); 2873 PDRVHOSTCOREAUDIO pThis = PDMINS_2_DATA(pDrvIns, PDRVHOSTCOREAUDIO); 2762 2874 2763 2875 PDMIBASE_RETURN_INTERFACE(pszIID, PDMIBASE, &pDrvIns->IBase); … … 2767 2879 } 2768 2880 2769 /* Construct a DirectSound Audio driver instance.2770 * 2771 * @copydoc FNPDMDRVCONSTRUCT2881 /** 2882 * @callback_method_impl{FNPDMDRVCONSTRUCT, 2883 * Construct a DirectSound Audio driver instance.} 2772 2884 */ 2773 2885 static DECLCALLBACK(int) drvHostCoreAudioConstruct(PPDMDRVINS pDrvIns, PCFGMNODE pCfg, uint32_t fFlags) 2774 2886 { 2887 RT_NOREF(pCfg, fFlags); 2888 PDMDRV_CHECK_VERSIONS_RETURN(pDrvIns); 2775 2889 PDRVHOSTCOREAUDIO pThis = PDMINS_2_DATA(pDrvIns, PDRVHOSTCOREAUDIO); 2776 2890 LogRel(("Audio: Initializing Core Audio driver\n"));
Note:
See TracChangeset
for help on using the changeset viewer.