VirtualBox

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


Ignore:
Timestamp:
Feb 25, 2015 6:08:56 PM (10 years ago)
Author:
vboxsync
svn:sync-xref-src-repo-rev:
98618
Message:

PDM/Audio: Update for Core Audio backend.

File:
1 edited

Legend:

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

    r54491 r54508  
    693693
    694694            /* Get the device' UUID. */
    695             propAdr.mSelector = kAudioObjectPropertyName;
     695            propAdr.mSelector = kAudioDevicePropertyDeviceUID;
    696696            err = AudioObjectGetPropertyData(pStreamIn->deviceID, &propAdr, 0, NULL, &uSize, &strTemp);
    697697            if (err == noErr)
     
    10071007    {
    10081008        /* Fetch the default audio input device currently in use. */
    1009         AudioObjectPropertyAddress propAdr = { kAudioHardwarePropertyDefaultInputDevice,
     1009        AudioObjectPropertyAddress propAdr = { kAudioHardwarePropertyDefaultOutputDevice,
    10101010                                               kAudioObjectPropertyScopeGlobal, kAudioObjectPropertyElementMaster };
    10111011        uSize = sizeof(pStreamOut->deviceID);
    1012         err = AudioObjectGetPropertyData(kAudioObjectSystemObject, &propAdr, 0, NULL, &uSize,  &pStreamOut->deviceID);
     1012        err = AudioObjectGetPropertyData(kAudioObjectSystemObject, &propAdr, 0, NULL, &uSize, &pStreamOut->deviceID);
    10131013        if (err != noErr)
    10141014        {
     
    10191019
    10201020    /*
    1021      * Try to get the name of the input device and log it. It's not fatal if it fails.
     1021     * Try to get the name of the output device and log it. It's not fatal if it fails.
    10221022     */
    10231023    CFStringRef strTemp;
     
    10361036
    10371037            /* Get the device' UUID. */
    1038             propAdr.mSelector = kAudioObjectPropertyName;
     1038            propAdr.mSelector = kAudioDevicePropertyDeviceUID;
    10391039            err = AudioObjectGetPropertyData(pStreamOut->deviceID, &propAdr, 0, NULL, &uSize, &strTemp);
    10401040            if (err == noErr)
     
    15451545
    15461546    int rc = VINF_SUCCESS;
     1547    OSStatus err;
    15471548
    15481549    switch (enmStreamCmd)
     
    15531554            if (!drvHostCoreAudioIsRunning(pStreamOut->deviceID))
    15541555            {
    1555                 OSStatus err = AudioUnitReset(pStreamOut->audioUnit, kAudioUnitScope_Input, 0);
     1556                err = AudioUnitReset(pStreamOut->audioUnit, kAudioUnitScope_Input, 0);
    15561557                if (err != noErr)
    15571558                {
     
    15651566                {
    15661567                    LogRel(("CoreAudio: Failed to start playback (%RI32)\n", err));
    1567                     return VERR_GENERAL_FAILURE; /** @todo Fudge! */
     1568                    rc = VERR_GENERAL_FAILURE; /** @todo Fudge! */
    15681569                }
    15691570            }
     
    15761577            if (drvHostCoreAudioIsRunning(pStreamOut->deviceID))
    15771578            {
    1578                 OSStatus err = AudioOutputUnitStop(pStreamOut->audioUnit);
     1579                err = AudioOutputUnitStop(pStreamOut->audioUnit);
    15791580                if (err != noErr)
    15801581                {
    15811582                    LogRel(("CoreAudio: Failed to stop playback (%RI32)\n", err));
    1582                     return VERR_GENERAL_FAILURE; /** @todo Fudge! */
     1583                    rc = VERR_GENERAL_FAILURE; /** @todo Fudge! */
     1584                    break;
    15831585                }
    15841586
     
    15871589                {
    15881590                    LogRel(("CoreAudio: Failed to reset AudioUnit (%RI32)\n", err));
    1589                     return VERR_GENERAL_FAILURE; /** @todo Fudge! */
     1591                    rc = VERR_GENERAL_FAILURE; /** @todo Fudge! */
    15901592                }
    15911593            }
     
    15981600    }
    15991601
     1602    LogFlowFuncLeaveRC(rc);
    16001603    return rc;
    16011604}
     
    16161619
    16171620    int rc = VINF_SUCCESS;
     1621    OSStatus err;
    16181622
    16191623    switch (enmStreamCmd)
     
    16211625        case PDMAUDIOSTREAMCMD_ENABLE:
    16221626        {
    1623             OSStatus err;
    1624 
    16251627            /* Only start the device if it is actually stopped */
    16261628            if (!drvHostCoreAudioIsRunning(pStreamIn->deviceID))
     
    16281630                RTCircBufReset(pStreamIn->pBuf);
    16291631                err = AudioOutputUnitStart(pStreamIn->audioUnit);
     1632                if (err != noErr)
     1633                {
     1634                    LogRel(("CoreAudio: Failed to start recording (%RI32)\n", err));
     1635                    rc = VERR_GENERAL_FAILURE; /** @todo Fudge! */
     1636                    break;
     1637                }
    16301638            }
    16311639
     
    16431651            if (drvHostCoreAudioIsRunning(pStreamIn->deviceID))
    16441652            {
    1645                 OSStatus err = AudioOutputUnitStop(pStreamIn->audioUnit);
    1646                 if (RT_UNLIKELY(err != noErr))
     1653                err = AudioOutputUnitStop(pStreamIn->audioUnit);
     1654                if (err != noErr)
    16471655                {
    16481656                    LogRel(("CoreAudio: Failed to stop recording (%RI32)\n", err));
    1649                     return VERR_GENERAL_FAILURE; /** @todo Fudge! */
     1657                    rc = VERR_GENERAL_FAILURE; /** @todo Fudge! */
     1658                    break;
    16501659                }
    16511660
    16521661                err = AudioUnitReset(pStreamIn->audioUnit, kAudioUnitScope_Input, 0);
    1653                 if (RT_UNLIKELY(err != noErr))
     1662                if (err != noErr)
    16541663                {
    16551664                    LogRel(("CoreAudio: Failed to reset AudioUnit (%RI32)\n", err));
    1656                     return VERR_GENERAL_FAILURE; /** @todo Fudge! */
     1665                    rc = VERR_GENERAL_FAILURE; /** @todo Fudge! */
     1666                    break;
    16571667                }
    16581668            }
     
    16651675    }
    16661676
     1677    LogFlowFuncLeaveRC(rc);
    16671678    return rc;
    16681679}
     
    16701681static DECLCALLBACK(int) drvHostCoreAudioFiniIn(PPDMIHOSTAUDIO pInterface, PPDMAUDIOHSTSTRMIN pHstStrmIn)
    16711682{
    1672     int rc = 0;
    1673     OSStatus err = noErr;
    1674     uint32_t status;
    1675 
    16761683    PCOREAUDIOSTREAMIN pStreamIn = (PCOREAUDIOSTREAMIN) pHstStrmIn;
    16771684
     
    16791686    PDRVHOSTCOREAUDIO  pThis   = PDMINS_2_DATA(pDrvIns, PDRVHOSTCOREAUDIO);
    16801687
    1681     LogFlow(("drvHostCoreAudioFiniIn \n"));
    1682 
    1683     status = ASMAtomicReadU32(&pStreamIn->status);
     1688    LogFlowFuncEnter();
     1689
     1690    uint32_t status = ASMAtomicReadU32(&pStreamIn->status);
    16841691    if (!(   status == CA_STATUS_INIT
    16851692          || status == CA_STATUS_REINIT))
     
    16881695    }
    16891696
    1690     rc = drvHostCoreAudioControlIn(pInterface, &pStreamIn->streamIn, PDMAUDIOSTREAMCMD_DISABLE);
     1697    OSStatus err = noErr;
     1698
     1699    int rc = drvHostCoreAudioControlIn(pInterface, &pStreamIn->streamIn, PDMAUDIOSTREAMCMD_DISABLE);
    16911700    if (RT_SUCCESS(rc))
    16921701    {
     
    17071716        if (RT_UNLIKELY(err != noErr))
    17081717            LogRel(("CoreAudio: Failed to remove the sample rate changed listener (%RI32)\n", err));
     1718
    17091719        if (pStreamIn->converter)
    17101720        {
     
    17271737            }
    17281738            else
     1739            {
    17291740                LogRel(("CoreAudio: Failed to close the AudioUnit (%RI32)\n", err));
     1741                rc = VERR_GENERAL_FAILURE; /** @todo Fudge! */
     1742            }
    17301743        }
    17311744        else
     1745        {
    17321746            LogRel(("CoreAudio: Failed to uninitialize the AudioUnit (%RI32)\n", err));
     1747            rc = VERR_GENERAL_FAILURE; /** @todo Fudge! */
     1748        }
    17331749    }
    17341750    else
     1751    {
    17351752        LogRel(("CoreAudio: Failed to stop recording (%RI32)\n", err));
    1736 
    1737     return VINF_SUCCESS;
     1753        rc = VERR_GENERAL_FAILURE; /** @todo Fudge! */
     1754    }
     1755
     1756    LogFlowFuncLeaveRC(rc);
     1757    return rc;
    17381758}
    17391759
     
    17951815        LogRel(("CoreAudio: Failed to stop playback, rc=%Rrc\n", rc));
    17961816
    1797     return VINF_SUCCESS;
     1817    LogFlowFuncLeaveRC(rc);
     1818    return rc;
    17981819}
    17991820
     
    18031824                                                uint32_t *pcSamples)
    18041825{
    1805     OSStatus err = noErr;
    1806     int rc = -1;
     1826    PCOREAUDIOSTREAMIN pStreamIn = (PCOREAUDIOSTREAMIN)pHstStrmIn;
     1827
     1828    LogFlowFunc(("enmRecSource=%ld\n"));
     1829
     1830    ASMAtomicXchgU32(&pStreamIn->status, CA_STATUS_UNINIT);
     1831
     1832    pStreamIn->audioUnit   = NULL;
     1833    pStreamIn->deviceID    = kAudioDeviceUnknown;
     1834    pStreamIn->converter   = NULL;
     1835    pStreamIn->sampleRatio = 1;
     1836    pStreamIn->rpos        = 0;
     1837
    18071838    bool fDeviceByUser = false;
    18081839
    1809     PCOREAUDIOSTREAMIN pStreamIn = (PCOREAUDIOSTREAMIN)pHstStrmIn;
    1810 
    1811     LogFlow(("drvHostCoreAudioInitIn \n"));
    1812 
    1813     ASMAtomicXchgU32(&pStreamIn->status, CA_STATUS_UNINIT);
    1814     pStreamIn->audioUnit = NULL;
    1815     pStreamIn->deviceID = kAudioDeviceUnknown;
    1816     pStreamIn->converter = NULL;
    1817     pStreamIn->sampleRatio = 1;
    1818     pStreamIn->rpos = 0;
    1819 
    1820     LogFlow(("drvHostCoreAudioInitIn \n"));
    18211840    /* Initialize the hardware info section with the audio settings */
    1822     drvAudioStreamCfgToProps(pCfg, &pStreamIn->streamIn.Props);
    1823 
     1841    int rc = drvAudioStreamCfgToProps(pCfg, &pStreamIn->streamIn.Props);
     1842    if (RT_SUCCESS(rc))
     1843    {
    18241844#if 0
    1825     /* Try to find the audio device set by the user */
    1826     if (DeviceUID.pszInputDeviceUID)
    1827     {
    1828         pStreamIn->deviceID = drvHostCoreAudioDeviceUIDtoID(DeviceUID.pszInputDeviceUID);
    1829         /* Not fatal */
    1830         if (pStreamIn->deviceID == kAudioDeviceUnknown)
    1831             LogRel(("CoreAudio: Unable to find input device %s. Falling back to the default audio device. \n", DeviceUID.pszInputDeviceUID));
    1832         else
    1833             fDeviceByUser = true;
    1834     }
     1845        /* Try to find the audio device set by the user */
     1846        if (DeviceUID.pszInputDeviceUID)
     1847        {
     1848            pStreamIn->deviceID = drvHostCoreAudioDeviceUIDtoID(DeviceUID.pszInputDeviceUID);
     1849            /* Not fatal */
     1850            if (pStreamIn->deviceID == kAudioDeviceUnknown)
     1851                LogRel(("CoreAudio: Unable to find input device %s. Falling back to the default audio device. \n", DeviceUID.pszInputDeviceUID));
     1852            else
     1853                fDeviceByUser = true;
     1854        }
    18351855#endif
    1836 
    1837     rc = drvHostCoreAudioInitInput(&pStreamIn->streamIn, pcSamples);
    1838     if (RT_FAILURE(rc))
    1839         return rc;
    1840 
    1841     /* When the devices isn't forced by the user, we want default device change notifications. */
    1842     if (!fDeviceByUser)
    1843     {
    1844         AudioObjectPropertyAddress propAdr = { kAudioHardwarePropertyDefaultInputDevice, kAudioObjectPropertyScopeGlobal,
    1845                                                kAudioObjectPropertyElementMaster };
    1846         err = AudioObjectAddPropertyListener(kAudioObjectSystemObject, &propAdr,
    1847                                              drvHostCoreAudioDefaultDeviceChanged, (void *)pStreamIn);
    1848         /* Not fatal. */
    1849         if (err != noErr)
    1850             LogRel(("CoreAudio: Failed to register the default input device changed listener (%RI32)\n", err));
    1851     }
    1852 
    1853     return VINF_SUCCESS;
     1856        rc = drvHostCoreAudioInitInput(&pStreamIn->streamIn, pcSamples);
     1857    }
     1858
     1859    if (RT_SUCCESS(rc))
     1860    {
     1861        /* When the devices isn't forced by the user, we want default device change notifications. */
     1862        if (!fDeviceByUser)
     1863        {
     1864            AudioObjectPropertyAddress propAdr = { kAudioHardwarePropertyDefaultInputDevice, kAudioObjectPropertyScopeGlobal,
     1865                                                   kAudioObjectPropertyElementMaster };
     1866            OSStatus err = AudioObjectAddPropertyListener(kAudioObjectSystemObject, &propAdr,
     1867                                                          drvHostCoreAudioDefaultDeviceChanged, (void *)pStreamIn);
     1868            /* Not fatal. */
     1869            if (err != noErr)
     1870                LogRel(("CoreAudio: Failed to register the default input device changed listener (%RI32)\n", err));
     1871        }
     1872    }
     1873
     1874    LogFlowFuncLeaveRC(rc);
     1875    return rc;
    18541876}
    18551877
     
    18641886    bool fDeviceByUser = false; /* use we a device which was set by the user? */
    18651887
    1866     LogFlow(("drvHostCoreAudioInitOut\n"));
     1888    LogFlowFuncEnter();
    18671889
    18681890    ASMAtomicXchgU32(&pStreamOut->status, CA_STATUS_UNINIT);
    18691891
    18701892    pStreamOut->audioUnit = NULL;
    1871     pStreamOut->deviceID = kAudioDeviceUnknown;
     1893    pStreamOut->deviceID  = kAudioDeviceUnknown;
    18721894
    18731895    /* Initialize the hardware info section with the audio settings */
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