VirtualBox

Changeset 55030 in vbox


Ignore:
Timestamp:
Mar 31, 2015 1:20:21 PM (9 years ago)
Author:
vboxsync
Message:

PDM/CoreAudio: Unregister the Default Device Changed listener if we registered it successfully before. Should fix a crash where VBoxDD.dylib was already unloaded when the callback was called.

File:
1 edited

Legend:

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

    r54851 r55030  
    268268{
    269269    /** Host stream out. */
    270     PDMAUDIOHSTSTRMOUT streamOut;
     270    PDMAUDIOHSTSTRMOUT          streamOut;
    271271    /* Stream description which is default on the device */
    272272    AudioStreamBasicDescription deviceFormat;
     
    274274    AudioStreamBasicDescription streamFormat;
    275275    /* The audio device ID of the currently used device */
    276     AudioDeviceID deviceID;
     276    AudioDeviceID               deviceID;
    277277    /* The AudioUnit used */
    278     AudioUnit audioUnit;
     278    AudioUnit                   audioUnit;
    279279    /* A ring buffer for transferring data to the playback thread. */
    280     PRTCIRCBUF pBuf;
     280    PRTCIRCBUF                  pBuf;
    281281    /* Temporary buffer for copying over audio data into Core Audio. */
    282     void *pvPCMBuf;
     282    void                       *pvPCMBuf;
    283283    /** Size of the temporary buffer. */
    284     size_t cbPCMBuf;
     284    size_t                      cbPCMBuf;
    285285    /* Initialization status tracker. Used when some of the device parameters
    286286     * 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;
    288290} COREAUDIOSTREAMOUT, *PCOREAUDIOSTREAMOUT;
    289291
     
    291293{
    292294    /** Host stream in. */
    293     PDMAUDIOHSTSTRMIN streamIn;
     295    PDMAUDIOHSTSTRMIN           streamIn;
    294296    /* Stream description which is default on the device */
    295297    AudioStreamBasicDescription deviceFormat;
     
    297299    AudioStreamBasicDescription streamFormat;
    298300    /* The audio device ID of the currently used device */
    299     AudioDeviceID deviceID;
     301    AudioDeviceID               deviceID;
    300302    /* The AudioUnit used */
    301     AudioUnit audioUnit;
     303    AudioUnit                   audioUnit;
    302304    /* The audio converter if necessary */
    303     AudioConverterRef converter;
     305    AudioConverterRef           converter;
    304306    /* A temporary position value used in the caConverterCallback function */
    305     uint32_t rpos;
     307    uint32_t                    rpos;
    306308    /* The ratio between the device & the stream sample rate */
    307     Float64 sampleRatio;
     309    Float64                     sampleRatio;
    308310    /* An extra buffer used for render the audio data in the recording thread */
    309     AudioBufferList bufferList;
     311    AudioBufferList             bufferList;
    310312    /* A ring buffer for transferring data from the recording thread */
    311     PRTCIRCBUF pBuf;
     313    PRTCIRCBUF                  pBuf;
    312314    /* Initialization status tracker. Used when some of the device parameters
    313315     * 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;
    315319} COREAUDIOSTREAMIN, *PCOREAUDIOSTREAMIN;
    316320
     
    12271231    if (RT_SUCCESS(rc))
    12281232    {
     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         */
    12291245#ifdef DEBUG
    12301246        propAdr.mSelector = kAudioDeviceProcessorOverload;
     
    12431259        if (err != noErr)
    12441260            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;
    12511261    }
    12521262
     
    16941704    {
    16951705        ASMAtomicXchgU32(&pStreamIn->status, CA_STATUS_IN_UNINIT);
     1706
     1707        /*
     1708         * Unregister input device callbacks.
     1709         */
    16961710        AudioObjectPropertyAddress propAdr = { kAudioDeviceProcessorOverload, kAudioUnitScope_Global,
    16971711                                               kAudioObjectPropertyElementMaster };
     
    17031717            LogRel(("CoreAudio: Failed to remove the processor overload listener (%RI32)\n", err));
    17041718#endif /* DEBUG */
     1719
    17051720        propAdr.mSelector = kAudioDevicePropertyNominalSampleRate;
    17061721        err = AudioObjectRemovePropertyListener(pStreamIn->deviceID, &propAdr,
     
    17101725            LogRel(("CoreAudio: Failed to remove the sample rate changed listener (%RI32)\n", err));
    17111726
     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
    17121739        if (pStreamIn->converter)
    17131740        {
     
    17151742            pStreamIn->converter = NULL;
    17161743        }
     1744
    17171745        err = AudioUnitUninitialize(pStreamIn->audioUnit);
    17181746        if (RT_LIKELY(err == noErr))
     
    17221750            {
    17231751                RTCircBufDestroy(pStreamIn->pBuf);
     1752
    17241753                pStreamIn->audioUnit   = NULL;
    17251754                pStreamIn->deviceID    = kAudioDeviceUnknown;
     
    17271756                pStreamIn->sampleRatio = 1;
    17281757                pStreamIn->rpos        = 0;
     1758
    17291759                ASMAtomicXchgU32(&pStreamIn->status, CA_STATUS_UNINIT);
    17301760            }
     
    17711801    {
    17721802        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);
    17811818        if (err == noErr)
    17821819        {
     
    18601897                                                          drvHostCoreAudioDefaultDeviceChanged, (void *)pStreamIn);
    18611898            /* 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));
    18641905        }
    18651906    }
     
    19161957                                             drvHostCoreAudioDefaultDeviceChanged, (void *)pStreamOut);
    19171958        /* 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));
    19201965    }
    19211966
Note: See TracChangeset for help on using the changeset viewer.

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