VirtualBox

vbox的更動 60305 路徑 trunk/src/VBox/Devices


忽略:
時間撮記:
2016-4-4 下午03:19:44 (9 年 以前)
作者:
vboxsync
訊息:

Forward-ported r106360 (Audio/DrvHostCoreAudio.cpp: Fixes for ​bugref:8311. Untested).

檔案:
修改 1 筆資料

圖例:

未更動
新增
刪除
  • trunk/src/VBox/Devices/Audio/DrvHostCoreAudio.cpp

    r59991 r60305  
    295295    AudioUnit                   audioUnit;
    296296    /** The audio converter if necessary. */
    297     AudioConverterRef           converter;
     297    AudioConverterRef           pConverter;
    298298    /** Native buffer used for render the audio data in the recording thread. */
    299299    AudioBufferList             bufferList;
     
    411411    PCOREAUDIOSTREAMIN pStreamIn = (PCOREAUDIOSTREAMIN)pHstStrmIn;
    412412
    413     drvHostCoreAudioFiniIn(pInterface, &pStreamIn->streamIn);
    414 
    415     coreAudioInitIn(&pStreamIn->streamIn, NULL /* pcSamples */);
    416     drvHostCoreAudioControlIn(pInterface, &pStreamIn->streamIn, PDMAUDIOSTREAMCMD_ENABLE);
    417 
    418     return VINF_SUCCESS;
     413    int rc = drvHostCoreAudioFiniIn(pInterface, &pStreamIn->streamIn);
     414    if (RT_SUCCESS(rc))
     415    {
     416        rc = coreAudioInitIn(&pStreamIn->streamIn, NULL /* pcSamples */);
     417        if (RT_SUCCESS(rc))
     418            rc = drvHostCoreAudioControlIn(pInterface, &pStreamIn->streamIn, PDMAUDIOSTREAMCMD_ENABLE);
     419    }
     420
     421    if (RT_FAILURE(rc))
     422        LogRel(("CoreAudio: Unable to re-init input stream: %Rrc\n", rc));
     423
     424    return rc;
    419425}
    420426
     
    426432    PCOREAUDIOSTREAMOUT pStreamOut = (PCOREAUDIOSTREAMOUT)pHstStrmOut;
    427433
    428     drvHostCoreAudioFiniOut(pInterface, &pStreamOut->streamOut);
    429 
    430     coreAudioInitOut(&pStreamOut->streamOut, NULL /* pcSamples */);
    431     drvHostCoreAudioControlOut(pInterface, &pStreamOut->streamOut, PDMAUDIOSTREAMCMD_ENABLE);
    432 
    433     return VINF_SUCCESS;
     434    int rc = drvHostCoreAudioFiniOut(pInterface, &pStreamOut->streamOut);
     435    if (RT_SUCCESS(rc))
     436    {
     437        rc = coreAudioInitOut(&pStreamOut->streamOut, NULL /* pcSamples */);
     438        if (RT_SUCCESS(rc))
     439            rc = drvHostCoreAudioControlOut(pInterface, &pStreamOut->streamOut, PDMAUDIOSTREAMCMD_ENABLE);
     440    }
     441
     442    if (RT_FAILURE(rc))
     443        LogRel(("CoreAudio: Unable to re-init output stream: %Rrc\n", rc));
     444
     445    return rc;
    434446}
    435447
     
    548560    {
    549561        /* Are we using a converter? */
    550         if (pStreamIn->converter)
     562        if (pStreamIn->pConverter)
    551563        {
    552564            /* First, render the data as usual. */
     
    598610                tmpList.mBuffers[0].mData         = puDst;
    599611
    600                 AudioConverterReset(pStreamIn->converter);
    601 
    602                 err = AudioConverterFillComplexBuffer(pStreamIn->converter, coreAudioConverterCb, pStreamIn,
     612                AudioConverterReset(pStreamIn->pConverter);
     613
     614                err = AudioConverterFillComplexBuffer(pStreamIn->pConverter, coreAudioConverterCb, pStreamIn,
    603615                                                      &ioOutputDataPacketSize, &tmpList, NULL);
    604616                if(   err != noErr
     
    871883        LogRel(("CoreAudio: Input converter is active\n"));
    872884
    873         err = AudioConverterNew(&pStreamIn->deviceFormat, &pStreamIn->streamFormat, &pStreamIn->converter);
     885        err = AudioConverterNew(&pStreamIn->deviceFormat, &pStreamIn->streamFormat, &pStreamIn->pConverter);
    874886        if (RT_UNLIKELY(err != noErr))
    875887        {
     
    890902            const SInt32 channelMap[2] = {0, 0}; /* Channel map for mono -> stereo, */
    891903
    892             err = AudioConverterSetProperty(pStreamIn->converter, kAudioConverterChannelMap, sizeof(channelMap), channelMap);
     904            err = AudioConverterSetProperty(pStreamIn->pConverter, kAudioConverterChannelMap, sizeof(channelMap), channelMap);
    893905            if (err != noErr)
    894906            {
     
    987999    }
    9881000
     1001    /* Destroy any former internal ring buffer. */
     1002    if (pStreamIn->pBuf)
     1003    {
     1004        RTCircBufDestroy(pStreamIn->pBuf);
     1005        pStreamIn->pBuf = NULL;
     1006    }
     1007
    9891008    /* Calculate the ratio between the device and the stream sample rate. */
    9901009    pStreamIn->sampleRatio = pStreamIn->streamFormat.mSampleRate / pStreamIn->deviceFormat.mSampleRate;
    9911010
    992     /* Set to zero first */
    993     pStreamIn->pBuf = NULL;
    9941011    /* Create the AudioBufferList structure with one buffer. */
    9951012    pStreamIn->bufferList.mNumberBuffers = 1;
     
    12901307    }
    12911308
     1309    /* Destroy any former internal ring buffer. */
     1310    if (pStreamOut->pBuf)
     1311    {
     1312        RTCircBufDestroy(pStreamOut->pBuf);
     1313        pStreamOut->pBuf = NULL;
     1314    }
     1315
    12921316    /* Create the internal ring buffer. */
    12931317    rc = RTCircBufCreate(&pStreamOut->pBuf, cSamples << pHstStrmOut->Props.cShift);
     
    18031827        }
    18041828
    1805         if (pStreamIn->converter)
    1806         {
    1807             AudioConverterDispose(pStreamIn->converter);
    1808             pStreamIn->converter = NULL;
     1829        if (pStreamIn->pConverter)
     1830        {
     1831            AudioConverterDispose(pStreamIn->pConverter);
     1832            pStreamIn->pConverter = NULL;
    18091833        }
    18101834
     
    18151839            if (RT_LIKELY(err == noErr))
    18161840            {
    1817                 RTCircBufDestroy(pStreamIn->pBuf);
    1818 
     1841                pStreamIn->deviceID      = kAudioDeviceUnknown;
    18191842                pStreamIn->audioUnit     = NULL;
    1820                 pStreamIn->deviceID      = kAudioDeviceUnknown;
    1821                 pStreamIn->pBuf          = NULL;
     1843                pStreamIn->offBufferRead = 0;
    18221844                pStreamIn->sampleRatio   = 1;
    1823                 pStreamIn->offBufferRead = 0;
     1845                if (pStreamIn->pBuf)
     1846                {
     1847                    RTCircBufDestroy(pStreamIn->pBuf);
     1848                    pStreamIn->pBuf = NULL;
     1849                }
    18241850
    18251851                ASMAtomicXchgU32(&pStreamIn->status, CA_STATUS_UNINIT);
     
    19111937            if (err == noErr)
    19121938            {
    1913                 RTCircBufDestroy(pStreamOut->pBuf);
    1914                 pStreamOut->pBuf      = NULL;
    1915 
     1939                pStreamOut->deviceID  = kAudioDeviceUnknown;
    19161940                pStreamOut->audioUnit = NULL;
    1917                 pStreamOut->deviceID  = kAudioDeviceUnknown;
     1941                if (pStreamOut->pBuf)
     1942                {
     1943                    RTCircBufDestroy(pStreamOut->pBuf);
     1944                    pStreamOut->pBuf = NULL;
     1945                }
    19181946
    19191947                ASMAtomicXchgU32(&pStreamOut->status, CA_STATUS_UNINIT);
     
    19391967    PCOREAUDIOSTREAMIN pStreamIn = (PCOREAUDIOSTREAMIN)pHstStrmIn;
    19401968
    1941     LogFlowFunc(("enmRecSource=%ld\n"));
    1942 
    1943     ASMAtomicXchgU32(&pStreamIn->status, CA_STATUS_UNINIT);
    1944 
    1945     pStreamIn->audioUnit     = NULL;
    1946     pStreamIn->deviceID      = kAudioDeviceUnknown;
    1947     pStreamIn->converter     = NULL;
    1948     pStreamIn->sampleRatio   = 1;
    1949     pStreamIn->offBufferRead = 0;
    1950 
    1951     bool fDeviceByUser = false;
     1969    LogFlowFunc(("enmRecSource=%ld\n", enmRecSource));
     1970
     1971    pStreamIn->deviceID                  = kAudioDeviceUnknown;
     1972    pStreamIn->audioUnit                 = NULL;
     1973    pStreamIn->pConverter                = NULL;
     1974    pStreamIn->bufferList.mNumberBuffers = 0;
     1975    pStreamIn->offBufferRead             = 0;
     1976    pStreamIn->sampleRatio               = 1;
     1977    pStreamIn->pBuf                      = NULL;
     1978    pStreamIn->status                    = CA_STATUS_UNINIT;
     1979    pStreamIn->fDefDevChgListReg         = false;
     1980
     1981    bool fDeviceByUser = false; /* Do we use a device which was set by the user? */
    19521982
    19531983    /* Initialize the hardware info section with the audio settings */
     
    19992029    PCOREAUDIOSTREAMOUT pStreamOut = (PCOREAUDIOSTREAMOUT)pHstStrmOut;
    20002030
    2001     OSStatus err = noErr;
    2002     int rc = 0;
    2003     bool fDeviceByUser = false; /* use we a device which was set by the user? */
    2004 
    20052031    LogFlowFuncEnter();
    20062032
    2007     ASMAtomicXchgU32(&pStreamOut->status, CA_STATUS_UNINIT);
    2008 
    2009     pStreamOut->audioUnit = NULL;
    2010     pStreamOut->deviceID  = kAudioDeviceUnknown;
     2033    pStreamOut->deviceID                  = kAudioDeviceUnknown;
     2034    pStreamOut->audioUnit                 = NULL;
     2035    pStreamOut->pBuf                      = NULL;
     2036    pStreamOut->status                    = CA_STATUS_UNINIT;
     2037    pStreamOut->fDefDevChgListReg         = false;
     2038
     2039    bool fDeviceByUser = false; /* Do we use a device which was set by the user? */
    20112040
    20122041    /* Initialize the hardware info section with the audio settings */
    2013     DrvAudioStreamCfgToProps(pCfg, &pStreamOut->streamOut.Props);
    2014 
     2042    int rc = DrvAudioStreamCfgToProps(pCfg, &pStreamOut->streamOut.Props);
     2043    if (RT_SUCCESS(rc))
     2044    {
    20152045#if 0
    2016     /* Try to find the audio device set by the user. Use
    2017      * export VBOX_COREAUDIO_OUTPUT_DEVICE_UID=AppleHDAEngineOutput:0
    2018      * to set it. */
    2019     if (DeviceUID.pszOutputDeviceUID)
    2020     {
    2021         pStreamOut->audioDeviceId = drvHostCoreAudioDeviceUIDtoID(DeviceUID.pszOutputDeviceUID);
    2022         /* Not fatal */
    2023         if (pStreamOut->audioDeviceId == kAudioDeviceUnknown)
    2024             LogRel(("CoreAudio: Unable to find output device %s. Falling back to the default audio device. \n", DeviceUID.pszOutputDeviceUID));
    2025         else
    2026             fDeviceByUser = true;
    2027     }
     2046        /* Try to find the audio device set by the user. Use
     2047         * export VBOX_COREAUDIO_OUTPUT_DEVICE_UID=AppleHDAEngineOutput:0
     2048         * to set it. */
     2049        if (DeviceUID.pszOutputDeviceUID)
     2050        {
     2051            pStreamOut->audioDeviceId = drvHostCoreAudioDeviceUIDtoID(DeviceUID.pszOutputDeviceUID);
     2052            /* Not fatal */
     2053            if (pStreamOut->audioDeviceId == kAudioDeviceUnknown)
     2054                LogRel(("CoreAudio: Unable to find output device %s. Falling back to the default audio device. \n", DeviceUID.pszOutputDeviceUID));
     2055            else
     2056                fDeviceByUser = true;
     2057        }
    20282058#endif
    2029 
    2030     rc = coreAudioInitOut(pHstStrmOut, pcSamples);
    2031     if (RT_FAILURE(rc))
    2032         return rc;
    2033 
    2034     /* When the devices isn't forced by the user, we want default device change notifications. */
    2035     if (!fDeviceByUser)
    2036     {
    2037         AudioObjectPropertyAddress propAdr = { kAudioHardwarePropertyDefaultOutputDevice, kAudioObjectPropertyScopeGlobal,
    2038                                                kAudioObjectPropertyElementMaster };
    2039         err = AudioObjectAddPropertyListener(kAudioObjectSystemObject, &propAdr,
    2040                                              coreAudioDefaultDeviceChanged, (void *)pStreamOut);
    2041         /* Not fatal. */
    2042         if (RT_LIKELY(err == noErr))
    2043         {
    2044             pStreamOut->fDefDevChgListReg = true;
    2045         }
    2046         else
    2047             LogRel(("CoreAudio: Failed to add the default output device changed listener (%RI32)\n", err));
    2048     }
    2049 
    2050     return VINF_SUCCESS;
     2059        rc = coreAudioInitOut(pHstStrmOut, pcSamples);
     2060    }
     2061
     2062    if (RT_SUCCESS(rc))
     2063    {
     2064        /* When the devices isn't forced by the user, we want default device change notifications. */
     2065        if (!fDeviceByUser)
     2066        {
     2067            AudioObjectPropertyAddress propAdr = { kAudioHardwarePropertyDefaultOutputDevice, kAudioObjectPropertyScopeGlobal,
     2068                                                   kAudioObjectPropertyElementMaster };
     2069            OSStatus err = AudioObjectAddPropertyListener(kAudioObjectSystemObject, &propAdr,
     2070                                                          coreAudioDefaultDeviceChanged, (void *)pStreamOut);
     2071            /* Not fatal. */
     2072            if (RT_LIKELY(err == noErr))
     2073            {
     2074                pStreamOut->fDefDevChgListReg = true;
     2075            }
     2076            else
     2077                LogRel(("CoreAudio: Failed to add the default output device changed listener (%RI32)\n", err));
     2078        }
     2079    }
     2080
     2081    LogFlowFuncLeaveRC(rc);
     2082    return rc;
    20512083}
    20522084
注意: 瀏覽 TracChangeset 來幫助您使用更動檢視器

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