VirtualBox

Changeset 63444 in vbox for trunk/src/VBox/Devices/Audio


Ignore:
Timestamp:
Aug 14, 2016 11:11:25 PM (9 years ago)
Author:
vboxsync
svn:sync-xref-src-repo-rev:
110091
Message:

DrvHostCoreAudio.cpp: Outlined how to avoid using three APIs that has been deprecated since 10.8; fixed warnings, added some missing doxygen. (Resisted moving things around in a more natural order, assuming someone might have pending changes.)

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Devices/Audio/DrvHostCoreAudio.cpp

    r63362 r63444  
    11/* $Id$ */
    22/** @file
    3  * VBox audio devices: Mac OS X CoreAudio audio driver.
     3 * VBox audio devices - Mac OS X CoreAudio audio driver.
    44 */
    55
     
    1515 * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
    1616 */
     17
     18/*********************************************************************************************************************************
     19*   Header Files                                                                                                                 *
     20*********************************************************************************************************************************/
    1721#define LOG_GROUP LOG_GROUP_DRV_HOST_AUDIO
    1822#include <VBox/log.h>
     
    5963 */
    6064
    61 /**
    62  * Host Coreaudio driver instance data.
    63  * @implements PDMIAUDIOCONNECTOR
    64  */
    65 typedef struct DRVHOSTCOREAUDIO
    66 {
    67     /** Pointer to the driver instance structure. */
    68     PPDMDRVINS    pDrvIns;
    69     /** Pointer to host audio interface. */
    70     PDMIHOSTAUDIO IHostAudio;
    71 } DRVHOSTCOREAUDIO, *PDRVHOSTCOREAUDIO;
    7265
    7366/*******************************************************************************
     
    7669 *
    7770 ******************************************************************************/
     71
     72/* Move these down below the internal function prototypes... */
    7873
    7974static void coreAudioPrintASBD(const char *pszDesc, const AudioStreamBasicDescription *pASBD)
     
    261256}
    262257
    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*********************************************************************************************************************************/
    276281/* Error code which indicates "End of data" */
    277 static const OSStatus caConverterEOFDErr = 0x656F6664; /* 'eofd' */
    278 
     282static const OSStatus g_caConverterEOFDErr = 0x656F6664; /* 'eofd' */
     283
     284
     285/*********************************************************************************************************************************
     286*   Structures and Typedefs                                                                                                      *
     287*********************************************************************************************************************************/
    279288/* Prototypes needed for COREAUDIOSTREAMCBCTX. */
    280289struct COREAUDIOSTREAMIN;
     
    282291struct COREAUDIOSTREAMOUT;
    283292typedef struct COREAUDIOSTREAMOUT *PCOREAUDIOSTREAMOUT;
     293
     294/**
     295 * Host Coreaudio driver instance data.
     296 * @implements PDMIAUDIOCONNECTOR
     297 */
     298typedef 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
    284306
    285307/**
     
    388410
    389411
     412/*********************************************************************************************************************************
     413*   Internal Functions                                                                                                           *
     414*********************************************************************************************************************************/
    390415static int coreAudioInitIn(PDRVHOSTCOREAUDIO pThis, PPDMAUDIOSTREAM pStream, PPDMAUDIOSTREAMCFG pCfgReq, PPDMAUDIOSTREAMCFG pCfgAcq);
    391416static int coreAudioInitOut(PDRVHOSTCOREAUDIO pThis, PPDMAUDIOSTREAM pStream, PPDMAUDIOSTREAMCFG pCfgReq, PPDMAUDIOSTREAMCFG pCfgAcq);
     
    399424static OSStatus coreAudioPlaybackAudioDevicePropertyChanged(AudioObjectID propertyID, UInt32 nAddresses, const AudioObjectPropertyAddress properties[], void *pvUser);
    400425static OSStatus coreAudioPlaybackCb(void *pvUser, AudioUnitRenderActionFlags *pActionFlags, const AudioTimeStamp *pAudioTS, UInt32 uBusID, UInt32 cFrames, AudioBufferList* pBufData);
     426
    401427
    402428/**
     
    807833                                                         void                          *pvUser)
    808834{
    809     AssertPtrReturn(ioNumberDataPackets, caConverterEOFDErr);
    810     AssertPtrReturn(ioData,              caConverterEOFDErr);
     835    AssertPtrReturn(ioNumberDataPackets, g_caConverterEOFDErr);
     836    AssertPtrReturn(ioData,              g_caConverterEOFDErr);
    811837
    812838    PCOREAUDIOCONVCBCTX pConvCbCtx = (PCOREAUDIOCONVCBCTX)pvUser;
     
    10881114}
    10891115
    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)
    10931121
    10941122/** @todo Eventually split up this function, as this already is huge! */
     
    12041232        LogFlowFunc(("cFrames=%RU32\n", cFrames));
    12051233
     1234        /* Try to find the default HAL output component. */
     1235#ifdef USE_NON_DEPRECATED_APIS
     1236        AudioComponentDescription cd;
     1237#else
    12061238        ComponentDescription cd;
     1239#endif
    12071240        RT_ZERO(cd);
    12081241        cd.componentType         = kAudioUnitType_Output;
    12091242        cd.componentSubType      = kAudioUnitSubType_HALOutput;
    12101243        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
    12131247        Component cp = FindNextComponent(NULL, &cd);
     1248#endif
    12141249        if (cp == 0)
    12151250        {
     
    12191254
    12201255        /* Open the default HAL output component. */
     1256#ifdef USE_NON_DEPRECATED_APIS
     1257        err = AudioComponentInstanceNew(cp, &pStreamIn->audioUnit);
     1258#else
    12211259        err = OpenAComponent(cp, &pStreamIn->audioUnit);
     1260#endif
    12221261        if (err != noErr)
    12231262        {
     
    16171656        }
    16181657
     1658        /* Try to find the default HAL output component. */
     1659#ifdef USE_NON_DEPRECATED_APIS
     1660        AudioComponentDescription cd;
     1661#else
    16191662        ComponentDescription cd;
     1663#endif
    16201664        RT_ZERO(cd);
    16211665        cd.componentType         = kAudioUnitType_Output;
    16221666        cd.componentSubType      = kAudioUnitSubType_HALOutput;
    16231667        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
    16261671        Component cp = FindNextComponent(NULL, &cd);
     1672#endif
    16271673        if (cp == 0)
    16281674        {
     
    16321678
    16331679        /* Open the default HAL output component. */
     1680#ifdef USE_NON_DEPRECATED_APIS
     1681        err = AudioComponentInstanceNew(cp, &pStreamOut->audioUnit);
     1682#else
    16341683        err = OpenAComponent(cp, &pStreamOut->audioUnit);
     1684#endif
    16351685        if (err != noErr)
    16361686        {
     
    19051955}
    19061956
     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 */
    19071967static DECLCALLBACK(int) drvHostCoreAudioInit(PPDMIHOSTAUDIO pInterface)
    19081968{
     
    19141974}
    19151975
     1976/**
     1977 * @interface_method_impl{PDMIHOSTAUDIO, pfnStreamCapture}
     1978 */
    19161979static DECLCALLBACK(int) drvHostCoreAudioStreamCapture(PPDMIHOSTAUDIO pInterface, PPDMAUDIOSTREAM pStream,
    19171980                                                       void *pvBuf, uint32_t cbBuf, uint32_t *pcbRead)
    19181981{
     1982    RT_NOREF(pvBuf, cbBuf); /** @todo r=bird: this looks totally weird at first glance! */
     1983
    19191984    AssertPtrReturn(pInterface, VERR_INVALID_POINTER);
    19201985    AssertPtrReturn(pStream,    VERR_INVALID_POINTER);
     
    19422007    do
    19432008    {
    1944         size_t cbBuf     = AudioMixBufSizeBytes(&pStream->MixBuf);
    1945         size_t cbToWrite = RT_MIN(cbBuf, RTCircBufUsed(pStreamIn->pCircBuf));
     2009        size_t cbMixBuf  = AudioMixBufSizeBytes(&pStream->MixBuf);
     2010        size_t cbToWrite = RT_MIN(cbMixBuf, RTCircBufUsed(pStreamIn->pCircBuf));
    19462011
    19472012        uint32_t cWritten, cbWritten;
     
    19492014        size_t   cbToRead;
    19502015
    1951         Log3Func(("cbBuf=%zu, cbToWrite=%zu/%zu\n", cbBuf, cbToWrite, RTCircBufSize(pStreamIn->pCircBuf)));
     2016        Log3Func(("cbMixBuf=%zu, cbToWrite=%zu/%zu\n", cbMixBuf, cbToWrite, RTCircBufSize(pStreamIn->pCircBuf)));
    19522017
    19532018        while (cbToWrite)
     
    20212086}
    20222087
     2088/**
     2089 * @interface_method_impl{PDMIHOSTAUDIO, pfnStreamPlay}
     2090 */
    20232091PDMAUDIO_IHOSTAUDIO_EMIT_STREAMPLAY(drvHostCoreAudio)
    20242092{
     
    23312399        err = AudioUnitUninitialize(pStreamIn->audioUnit);
    23322400        if (err == noErr)
     2401#ifdef USE_NON_DEPRECATED_APIS
     2402            err = AudioComponentInstanceDispose(pStreamIn->audioUnit);
     2403#else
    23332404            err = CloseComponent(pStreamIn->audioUnit);
     2405#endif
    23342406
    23352407        if (   err != noErr
     
    24422514        err = AudioUnitUninitialize(pStreamOut->audioUnit);
    24432515        if (err == noErr)
     2516#ifdef USE_NON_DEPRECATED_APIS
     2517            err = AudioComponentInstanceDispose(pStreamOut->audioUnit);
     2518#else
    24442519            err = CloseComponent(pStreamOut->audioUnit);
     2520#endif
    24452521
    24462522        if (   err != noErr
     
    26332709}
    26342710
     2711
     2712/**
     2713 * @interface_method_impl{PDMIHOSTAUDIO, pfnGetConfig}
     2714 */
    26352715PDMAUDIO_IHOSTAUDIO_EMIT_GETCONFIG(drvHostCoreAudio)
    26362716{
     
    26442724}
    26452725
     2726
     2727/**
     2728 * @interface_method_impl{PDMIHOSTAUDIO, pfnStreamGetStatus}
     2729 */
    26462730PDMAUDIO_IHOSTAUDIO_EMIT_GETSTATUS(drvHostCoreAudio)
    26472731{
     
    26512735}
    26522736
     2737
     2738/**
     2739 * @interface_method_impl{PDMIHOSTAUDIO, pfnStreamCreate}
     2740 */
    26532741PDMAUDIO_IHOSTAUDIO_EMIT_STREAMCREATE(drvHostCoreAudio)
    26542742{
     
    26712759}
    26722760
     2761
     2762/**
     2763 * @interface_method_impl{PDMIHOSTAUDIO, pfnStreamDestroy}
     2764 */
    26732765PDMAUDIO_IHOSTAUDIO_EMIT_STREAMDESTROY(drvHostCoreAudio)
    26742766{
     
    26882780}
    26892781
     2782
     2783/**
     2784 * @interface_method_impl{PDMIHOSTAUDIO, pfnStreamControl}
     2785 */
    26902786PDMAUDIO_IHOSTAUDIO_EMIT_STREAMCONTROL(drvHostCoreAudio)
    26912787{
     
    27072803}
    27082804
     2805
     2806/**
     2807 * @interface_method_impl{PDMIHOSTAUDIO, pfnStreamGetStatus}
     2808 */
    27092809PDMAUDIO_IHOSTAUDIO_EMIT_STREAMGETSTATUS(drvHostCoreAudio)
    27102810{
     
    27422842}
    27432843
     2844
     2845/**
     2846 * @interface_method_impl{PDMIHOSTAUDIO, pfnStreamIterate}
     2847 */
    27442848PDMAUDIO_IHOSTAUDIO_EMIT_STREAMITERATE(drvHostCoreAudio)
    27452849{
     
    27512855}
    27522856
     2857
     2858/**
     2859 * @interface_method_impl{PDMIHOSTAUDIO, pfnShutdown}
     2860 */
    27532861PDMAUDIO_IHOSTAUDIO_EMIT_SHUTDOWN(drvHostCoreAudio)
    27542862{
     
    27562864}
    27572865
     2866
     2867/**
     2868 * @interface_method_impl{PDMIBASE,pfnQueryInterface}
     2869 */
    27582870static DECLCALLBACK(void *) drvHostCoreAudioQueryInterface(PPDMIBASE pInterface, const char *pszIID)
    27592871{
    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);
    27622874
    27632875    PDMIBASE_RETURN_INTERFACE(pszIID, PDMIBASE, &pDrvIns->IBase);
     
    27672879}
    27682880
    2769 /* Construct a DirectSound Audio driver instance.
    2770  *
    2771  * @copydoc FNPDMDRVCONSTRUCT
     2881/**
     2882 * @callback_method_impl{FNPDMDRVCONSTRUCT,
     2883 *      Construct a DirectSound Audio driver instance.}
    27722884 */
    27732885static DECLCALLBACK(int) drvHostCoreAudioConstruct(PPDMDRVINS pDrvIns, PCFGMNODE pCfg, uint32_t fFlags)
    27742886{
     2887    RT_NOREF(pCfg, fFlags);
     2888    PDMDRV_CHECK_VERSIONS_RETURN(pDrvIns);
    27752889    PDRVHOSTCOREAUDIO pThis = PDMINS_2_DATA(pDrvIns, PDRVHOSTCOREAUDIO);
    27762890    LogRel(("Audio: Initializing Core Audio driver\n"));
Note: See TracChangeset for help on using the changeset viewer.

© 2025 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette