VirtualBox

Changeset 62336 in vbox


Ignore:
Timestamp:
Jul 19, 2016 6:56:44 PM (9 years ago)
Author:
vboxsync
svn:sync-xref-src-repo-rev:
108876
Message:

Audio/DrvHostCoreAudio.cpp: Brought back file in sync with 5.0.

File:
1 edited

Legend:

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

    r62117 r62336  
    644644                ASMAtomicXchgU32(&pStreamIn->status, CA_STATUS_REINIT);
    645645
    646                 LogRel(("CoreAudio: Capturing device stopped functioning\n"));
     646                LogRel(("CoreAudio: Recording device stopped functioning\n"));
    647647                break;
    648648            }
     
    709709                    if (pStreamIn->deviceID != uResp)
    710710                    {
    711                         LogRel2(("CoreAudio: Default device for recording has changed\n"));
     711                        LogRel(("CoreAudio: Default device for recording has changed\n"));
    712712
    713713                        /* We move the reinitialization to the next input event.
     
    738738                    if (pStreamOut->deviceID != uResp)
    739739                    {
    740                         LogRel2(("CoreAudio: Default device for playback has changed\n"));
     740                        LogRel(("CoreAudio: Default device for playback has changed\n"));
    741741
    742742                        /* We move the reinitialization to the next input event.
     
    999999                if (cbFree < cbDst)
    10001000                {
    1001                     LogRel2(("CoreAudio: Capturing is lagging behind (%zu bytes available but only %zu bytes free)\n",
     1001                    LogRel2(("CoreAudio: Recording is lagging behind (%zu bytes available but only %zu bytes free)\n",
    10021002                             cbDst, cbFree));
    10031003                    break;
     
    11541154                {
    11551155                    char *pszUID = NULL;
     1156
    11561157                    err = coreAudioCFStringToCString(strTemp, &pszUID);
    11571158                    if (err == noErr)
     
    15091510static int coreAudioInitOut(PDRVHOSTCOREAUDIO pThis, PPDMAUDIOSTREAM pStream, uint32_t *pcSamples)
    15101511{
    1511     PCOREAUDIOSTREAMOUT pStreamOut = (PCOREAUDIOSTREAMOUT)pStream;
    1512 
    1513     ASMAtomicXchgU32(&pStreamOut->status, CA_STATUS_IN_INIT);
     1512    int rc = VINF_SUCCESS;
     1513
     1514    PCOREAUDIOSTREAMOUT pStreamOut = (PCOREAUDIOSTREAMOUT)pHstStrmOut;
     1515    UInt32 cSamples = 0;
    15141516
    15151517    OSStatus err = noErr;
     1518    AudioDeviceID deviceID = pStreamOut->deviceID;
    15161519
    15171520    UInt32 uSize = 0;
     
    15301533    }
    15311534
    1532     /*
    1533      * Try to get the name of the playback device and log it. It's not fatal if it fails.
    1534      */
    1535     CFStringRef strTemp;
    1536 
    1537     AudioObjectPropertyAddress propAdr = { kAudioObjectPropertyName, kAudioObjectPropertyScopeGlobal,
    1538                                            kAudioObjectPropertyElementMaster };
    1539     uSize = sizeof(CFStringRef);
    1540     err = AudioObjectGetPropertyData(pStreamOut->deviceID, &propAdr, 0, NULL, &uSize, &strTemp);
    1541     if (err == noErr)
    1542     {
    1543         char *pszDevName = NULL;
    1544         err = coreAudioCFStringToCString(strTemp, &pszDevName);
     1535    if (deviceID == kAudioDeviceUnknown)
     1536    {
     1537        LogFlowFunc(("No default playback device found\n"));
     1538        return VERR_NOT_FOUND;
     1539    }
     1540
     1541    do
     1542    {
     1543        ASMAtomicXchgU32(&pStreamOut->status, CA_STATUS_IN_INIT);
     1544
     1545        /* Assign device ID. */
     1546        pStreamOut->deviceID = deviceID;
     1547
     1548        /*
     1549         * Try to get the name of the playback device and log it. It's not fatal if it fails.
     1550         */
     1551        CFStringRef strTemp;
     1552
     1553        AudioObjectPropertyAddress propAdr = { kAudioObjectPropertyName, kAudioObjectPropertyScopeGlobal,
     1554                                               kAudioObjectPropertyElementMaster };
     1555        uSize = sizeof(CFStringRef);
     1556        err = AudioObjectGetPropertyData(pStreamOut->deviceID, &propAdr, 0, NULL, &uSize, &strTemp);
    15451557        if (err == noErr)
    15461558        {
    1547             CFRelease(strTemp);
    1548 
    1549             /* Get the device' UUID. */
    1550             propAdr.mSelector = kAudioDevicePropertyDeviceUID;
    1551             err = AudioObjectGetPropertyData(pStreamOut->deviceID, &propAdr, 0, NULL, &uSize, &strTemp);
     1559            char *pszDevName = NULL;
     1560            err = coreAudioCFStringToCString(strTemp, &pszDevName);
    15521561            if (err == noErr)
    15531562            {
    1554                 char *pszUID = NULL;
    1555                 err = coreAudioCFStringToCString(strTemp, &pszUID);
     1563                CFRelease(strTemp);
     1564
     1565                /* Get the device' UUID. */
     1566                propAdr.mSelector = kAudioDevicePropertyDeviceUID;
     1567                err = AudioObjectGetPropertyData(pStreamOut->deviceID, &propAdr, 0, NULL, &uSize, &strTemp);
    15561568                if (err == noErr)
    15571569                {
    1558                     CFRelease(strTemp);
    1559                     LogRel(("CoreAudio: Using playback device: %s (UID: %s)\n", pszDevName, pszUID));
    1560 
    1561                     RTMemFree(pszUID);
     1570                    char *pszUID = NULL;
     1571                    err = coreAudioCFStringToCString(strTemp, &pszUID);
     1572                    if (err == noErr)
     1573                    {
     1574                        CFRelease(strTemp);
     1575                        LogRel(("CoreAudio: Using playback device: %s (UID: %s)\n", pszDevName, pszUID));
     1576
     1577                        RTMemFree(pszUID);
     1578                    }
    15621579                }
    1563             }
    1564 
    1565             RTMemFree(pszDevName);
    1566         }
    1567     }
    1568     else
    1569         LogRel(("CoreAudio: Unable to determine playback device name (%RI32)\n", err));
    1570 
    1571     /* Get the default frames buffer size, so that we can setup our internal buffers. */
    1572     UInt32 cFrames;
    1573     uSize = sizeof(cFrames);
    1574     propAdr.mSelector = kAudioDevicePropertyBufferFrameSize;
    1575     propAdr.mScope    = kAudioDevicePropertyScopeInput;
    1576     err = AudioObjectGetPropertyData(pStreamOut->deviceID, &propAdr, 0, NULL, &uSize, &cFrames);
    1577     if (err != noErr)
    1578     {
    1579         LogRel(("CoreAudio: Failed to determine frame buffer size of the audio playback device (%RI32)\n", err));
    1580         return VERR_AUDIO_BACKEND_INIT_FAILED;
    1581     }
    1582 
    1583     /* Set the frame buffer size and honor any minimum/maximum restrictions on the device. */
    1584     err = coreAudioSetFrameBufferSize(pStreamOut->deviceID, false /* fInput */, cFrames, &cFrames);
    1585     if (err != noErr)
    1586     {
    1587         LogRel(("CoreAudio: Failed to set frame buffer size for the audio playback device (%RI32)\n", err));
    1588         return VERR_AUDIO_BACKEND_INIT_FAILED;
    1589     }
    1590 
    1591     ComponentDescription cd;
    1592     RT_ZERO(cd);
    1593     cd.componentType         = kAudioUnitType_Output;
    1594     cd.componentSubType      = kAudioUnitSubType_HALOutput;
    1595     cd.componentManufacturer = kAudioUnitManufacturer_Apple;
    1596 
    1597     /* Try to find the default HAL output component. */
    1598     Component cp = FindNextComponent(NULL, &cd);
    1599     if (cp == 0)
    1600     {
    1601         LogRel(("CoreAudio: Failed to find HAL output component\n")); /** @todo Return error value? */
    1602         return VERR_AUDIO_BACKEND_INIT_FAILED;
    1603     }
    1604 
    1605     /* Open the default HAL output component. */
    1606     err = OpenAComponent(cp, &pStreamOut->audioUnit);
    1607     if (err != noErr)
    1608     {
    1609         LogRel(("CoreAudio: Failed to open output component (%RI32)\n", err));
    1610         return VERR_AUDIO_BACKEND_INIT_FAILED;
    1611     }
    1612 
    1613     /* Switch the I/O mode for output to on. */
    1614     UInt32 uFlag = 1;
    1615     err = AudioUnitSetProperty(pStreamOut->audioUnit, kAudioOutputUnitProperty_EnableIO, kAudioUnitScope_Output,
    1616                                0, &uFlag, sizeof(uFlag));
    1617     if (err != noErr)
    1618     {
    1619         LogRel(("CoreAudio: Failed to disable I/O mode for output stream (%RI32)\n", err));
    1620         return VERR_AUDIO_BACKEND_INIT_FAILED;
    1621     }
    1622 
    1623     /* Set the default audio playback device as the device for the new AudioUnit. */
    1624     err = AudioUnitSetProperty(pStreamOut->audioUnit, kAudioOutputUnitProperty_CurrentDevice, kAudioUnitScope_Global,
    1625                                0, &pStreamOut->deviceID, sizeof(pStreamOut->deviceID));
    1626     if (err != noErr)
    1627     {
    1628         LogRel(("CoreAudio: Failed to set current device for output stream (%RI32)\n", err));
    1629         return VERR_AUDIO_BACKEND_INIT_FAILED;
    1630     }
    1631 
    1632     /*
    1633      * CoreAudio will inform us on a second thread for new incoming audio data.
    1634      * Therefor register a callback function which will process the new data.
    1635      */
    1636     AURenderCallbackStruct cb;
    1637     RT_ZERO(cb);
    1638     cb.inputProc       = coreAudioPlaybackCb; /* pvUser */
    1639     cb.inputProcRefCon = pStreamOut;
    1640 
    1641     err = AudioUnitSetProperty(pStreamOut->audioUnit, kAudioUnitProperty_SetRenderCallback, kAudioUnitScope_Input,
    1642                                0, &cb, sizeof(cb));
    1643     if (err != noErr)
    1644     {
    1645         LogRel(("CoreAudio: Failed to register output callback (%RI32)\n", err));
    1646         return VERR_AUDIO_BACKEND_INIT_FAILED;
    1647     }
    1648 
    1649     /* Fetch the current stream format of the device. */
    1650     uSize = sizeof(pStreamOut->deviceFormat);
    1651     err = AudioUnitGetProperty(pStreamOut->audioUnit, kAudioUnitProperty_StreamFormat, kAudioUnitScope_Input,
    1652                                0, &pStreamOut->deviceFormat, &uSize);
    1653     if (err != noErr)
    1654     {
    1655         LogRel(("CoreAudio: Failed to get device format (%RI32)\n", err));
    1656         return VERR_AUDIO_BACKEND_INIT_FAILED;
    1657     }
    1658 
    1659     /* Create an AudioStreamBasicDescription based on our required audio settings. */
    1660     coreAudioPCMPropsToASBD(&pStreamOut->Stream.Props, &pStreamOut->streamFormat);
    1661 
    1662     coreAudioPrintASBD("CoreAudio: playback device", &pStreamOut->deviceFormat);
    1663     coreAudioPrintASBD("CoreAudio: Output format", &pStreamOut->streamFormat);
    1664 
    1665     /* Set the new output format description for the stream. */
    1666     err = AudioUnitSetProperty(pStreamOut->audioUnit, kAudioUnitProperty_StreamFormat, kAudioUnitScope_Input,
    1667                                0, &pStreamOut->streamFormat, sizeof(pStreamOut->streamFormat));
    1668     if (err != noErr)
    1669     {
    1670         LogRel(("CoreAudio: Failed to set stream format for output stream (%RI32)\n", err));
    1671         return VERR_AUDIO_BACKEND_INIT_FAILED;
    1672     }
    1673 
    1674     uSize = sizeof(pStreamOut->deviceFormat);
    1675     err = AudioUnitGetProperty(pStreamOut->audioUnit, kAudioUnitProperty_StreamFormat, kAudioUnitScope_Input,
    1676                                0, &pStreamOut->deviceFormat, &uSize);
    1677     if (err != noErr)
    1678     {
    1679         LogRel(("CoreAudio: Failed to retrieve device format for output stream (%RI32)\n", err));
    1680         return VERR_AUDIO_BACKEND_INIT_FAILED;
    1681     }
    1682 
    1683     /*
    1684      * Also set the frame buffer size off the device on our AudioUnit. This
    1685      * should make sure that the frames count which we receive in the render
    1686      * thread is as we like.
    1687      */
    1688     err = AudioUnitSetProperty(pStreamOut->audioUnit, kAudioUnitProperty_MaximumFramesPerSlice, kAudioUnitScope_Global,
    1689                                0, &cFrames, sizeof(cFrames));
    1690     if (err != noErr)
    1691     {
    1692         LogRel(("CoreAudio: Failed to set maximum frame buffer size for output AudioUnit (%RI32)\n", err));
    1693         return VERR_AUDIO_BACKEND_INIT_FAILED;
    1694     }
    1695 
    1696     /* Finally initialize the new AudioUnit. */
    1697     err = AudioUnitInitialize(pStreamOut->audioUnit);
    1698     if (err != noErr)
    1699     {
    1700         LogRel(("CoreAudio: Failed to initialize the output audio device (%RI32)\n", err));
    1701         return VERR_AUDIO_BACKEND_INIT_FAILED;
    1702     }
    1703 
    1704     /*
    1705      * There are buggy devices (e.g. my Bluetooth headset) which doesn't honor
    1706      * the frame buffer size set in the previous calls. So finally get the
    1707      * frame buffer size after the AudioUnit was initialized.
    1708      */
    1709     uSize = sizeof(cFrames);
    1710     err = AudioUnitGetProperty(pStreamOut->audioUnit, kAudioUnitProperty_MaximumFramesPerSlice, kAudioUnitScope_Global,
    1711                                0, &cFrames, &uSize);
    1712     if (err != noErr)
    1713     {
    1714         LogRel(("CoreAudio: Failed to get maximum frame buffer size from output audio device (%RI32)\n", err));
    1715 
    1716         AudioUnitUninitialize(pStreamOut->audioUnit);
    1717         return VERR_AUDIO_BACKEND_INIT_FAILED;
    1718     }
    1719 
    1720     /*
    1721      * Make sure that the ring buffer is big enough to hold the recording
    1722      * data. Compare the maximum frames per slice value with the frames
    1723      * necessary when using the converter where the sample rate could differ.
    1724      * The result is always multiplied by the channels per frame to get the
    1725      * samples count.
    1726      */
    1727     int rc = VINF_SUCCESS;
    1728 
    1729     UInt32 cSamples = cFrames * pStreamOut->streamFormat.mChannelsPerFrame;
    1730     if (!cSamples)
    1731     {
    1732         LogRel(("CoreAudio: Failed to determine samples buffer count output stream\n"));
    1733         rc = VERR_INVALID_PARAMETER;
    1734     }
    1735 
    1736     /* Destroy any former internal ring buffer. */
    1737     if (pStreamOut->pCircBuf)
    1738     {
    1739         RTCircBufDestroy(pStreamOut->pCircBuf);
    1740         pStreamOut->pCircBuf = NULL;
    1741     }
    1742 
    1743     /* Create the internal ring buffer. */
    1744     rc = RTCircBufCreate(&pStreamOut->pCircBuf, cSamples << pStream->Props.cShift);
    1745     if (RT_SUCCESS(rc))
    1746     {
     1580
     1581                RTMemFree(pszDevName);
     1582            }
     1583        }
     1584        else
     1585            LogRel(("CoreAudio: Unable to determine playback device name (%RI32)\n", err));
     1586
     1587        /* Get the default frames buffer size, so that we can setup our internal buffers. */
     1588        UInt32 cFrames;
     1589        uSize = sizeof(cFrames);
     1590        propAdr.mSelector = kAudioDevicePropertyBufferFrameSize;
     1591        propAdr.mScope    = kAudioDevicePropertyScopeInput;
     1592        err = AudioObjectGetPropertyData(pStreamOut->deviceID, &propAdr, 0, NULL, &uSize, &cFrames);
     1593        if (err != noErr)
     1594        {
     1595            LogRel(("CoreAudio: Failed to determine frame buffer size of the audio playback device (%RI32)\n", err));
     1596            CA_BREAK_STMT(rc = VERR_AUDIO_BACKEND_INIT_FAILED);
     1597        }
     1598
     1599        /* Set the frame buffer size and honor any minimum/maximum restrictions on the device. */
     1600        err = coreAudioSetFrameBufferSize(pStreamOut->deviceID, false /* fInput */, cFrames, &cFrames);
     1601        if (err != noErr)
     1602        {
     1603            LogRel(("CoreAudio: Failed to set frame buffer size for the audio playback device (%RI32)\n", err));
     1604            CA_BREAK_STMT(rc = VERR_AUDIO_BACKEND_INIT_FAILED);
     1605        }
     1606
     1607        ComponentDescription cd;
     1608        RT_ZERO(cd);
     1609        cd.componentType         = kAudioUnitType_Output;
     1610        cd.componentSubType      = kAudioUnitSubType_HALOutput;
     1611        cd.componentManufacturer = kAudioUnitManufacturer_Apple;
     1612
     1613        /* Try to find the default HAL output component. */
     1614        Component cp = FindNextComponent(NULL, &cd);
     1615        if (cp == 0)
     1616        {
     1617            LogRel(("CoreAudio: Failed to find HAL output component\n")); /** @todo Return error value? */
     1618            CA_BREAK_STMT(rc = VERR_AUDIO_BACKEND_INIT_FAILED);
     1619        }
     1620
     1621        /* Open the default HAL output component. */
     1622        err = OpenAComponent(cp, &pStreamOut->audioUnit);
     1623        if (err != noErr)
     1624        {
     1625            LogRel(("CoreAudio: Failed to open output component (%RI32)\n", err));
     1626            CA_BREAK_STMT(rc = VERR_AUDIO_BACKEND_INIT_FAILED);
     1627        }
     1628
     1629        /* Switch the I/O mode for output to on. */
     1630        UInt32 uFlag = 1;
     1631        err = AudioUnitSetProperty(pStreamOut->audioUnit, kAudioOutputUnitProperty_EnableIO, kAudioUnitScope_Output,
     1632                                   0, &uFlag, sizeof(uFlag));
     1633        if (err != noErr)
     1634        {
     1635            LogRel(("CoreAudio: Failed to disable I/O mode for output stream (%RI32)\n", err));
     1636            CA_BREAK_STMT(rc = VERR_AUDIO_BACKEND_INIT_FAILED);
     1637        }
     1638
     1639        /* Set the default audio playback device as the device for the new AudioUnit. */
     1640        err = AudioUnitSetProperty(pStreamOut->audioUnit, kAudioOutputUnitProperty_CurrentDevice, kAudioUnitScope_Global,
     1641                                   0, &pStreamOut->deviceID, sizeof(pStreamOut->deviceID));
     1642        if (err != noErr)
     1643        {
     1644            LogRel(("CoreAudio: Failed to set current device for output stream (%RI32)\n", err));
     1645            CA_BREAK_STMT(rc = VERR_AUDIO_BACKEND_INIT_FAILED);
     1646        }
     1647
    17471648        /*
    1748          * Register callbacks.
     1649         * CoreAudio will inform us on a second thread for new incoming audio data.
     1650         * Therefor register a callback function which will process the new data.
    17491651         */
     1652        AURenderCallbackStruct cb;
     1653        RT_ZERO(cb);
     1654        cb.inputProc       = coreAudioPlaybackCb; /* pvUser */
     1655        cb.inputProcRefCon = pStreamOut;
     1656
     1657        err = AudioUnitSetProperty(pStreamOut->audioUnit, kAudioUnitProperty_SetRenderCallback, kAudioUnitScope_Input,
     1658                                   0, &cb, sizeof(cb));
     1659        if (err != noErr)
     1660        {
     1661            LogRel(("CoreAudio: Failed to register output callback (%RI32)\n", err));
     1662            CA_BREAK_STMT(rc = VERR_AUDIO_BACKEND_INIT_FAILED);
     1663        }
     1664
     1665        /* Fetch the current stream format of the device. */
     1666        uSize = sizeof(pStreamOut->deviceFormat);
     1667        err = AudioUnitGetProperty(pStreamOut->audioUnit, kAudioUnitProperty_StreamFormat, kAudioUnitScope_Input,
     1668                                   0, &pStreamOut->deviceFormat, &uSize);
     1669        if (err != noErr)
     1670        {
     1671            LogRel(("CoreAudio: Failed to get device format (%RI32)\n", err));
     1672            CA_BREAK_STMT(rc = VERR_AUDIO_BACKEND_INIT_FAILED);
     1673        }
     1674
     1675        /* Create an AudioStreamBasicDescription based on our required audio settings. */
     1676        coreAudioPCMPropsToASBD(&pStreamOut->Stream.Props, &pStreamOut->streamFormat);
     1677
     1678        coreAudioPrintASBD("Playback device", &pStreamOut->deviceFormat);
     1679        coreAudioPrintASBD("Playback format", &pStreamOut->streamFormat);
     1680
     1681        /* Set the new output format description for the stream. */
     1682        err = AudioUnitSetProperty(pStreamOut->audioUnit, kAudioUnitProperty_StreamFormat, kAudioUnitScope_Input,
     1683                                   0, &pStreamOut->streamFormat, sizeof(pStreamOut->streamFormat));
     1684        if (err != noErr)
     1685        {
     1686            LogRel(("CoreAudio: Failed to set stream format for output stream (%RI32)\n", err));
     1687            CA_BREAK_STMT(rc = VERR_AUDIO_BACKEND_INIT_FAILED);
     1688        }
     1689
     1690        uSize = sizeof(pStreamOut->deviceFormat);
     1691        err = AudioUnitGetProperty(pStreamOut->audioUnit, kAudioUnitProperty_StreamFormat, kAudioUnitScope_Input,
     1692                                   0, &pStreamOut->deviceFormat, &uSize);
     1693        if (err != noErr)
     1694        {
     1695            LogRel(("CoreAudio: Failed to retrieve device format for output stream (%RI32)\n", err));
     1696            CA_BREAK_STMT(rc = VERR_AUDIO_BACKEND_INIT_FAILED);
     1697        }
     1698
     1699        /*
     1700         * Also set the frame buffer size off the device on our AudioUnit. This
     1701         * should make sure that the frames count which we receive in the render
     1702         * thread is as we like.
     1703         */
     1704        err = AudioUnitSetProperty(pStreamOut->audioUnit, kAudioUnitProperty_MaximumFramesPerSlice, kAudioUnitScope_Global,
     1705                                   0, &cFrames, sizeof(cFrames));
     1706        if (err != noErr)
     1707        {
     1708            LogRel(("CoreAudio: Failed to set maximum frame buffer size for output AudioUnit (%RI32)\n", err));
     1709            CA_BREAK_STMT(rc = VERR_AUDIO_BACKEND_INIT_FAILED);
     1710        }
     1711
     1712        /* Finally initialize the new AudioUnit. */
     1713        err = AudioUnitInitialize(pStreamOut->audioUnit);
     1714        if (err != noErr)
     1715        {
     1716            LogRel(("CoreAudio: Failed to initialize the output audio device (%RI32)\n", err));
     1717            CA_BREAK_STMT(rc = VERR_AUDIO_BACKEND_INIT_FAILED);
     1718        }
     1719
     1720        /*
     1721         * There are buggy devices (e.g. my Bluetooth headset) which doesn't honor
     1722         * the frame buffer size set in the previous calls. So finally get the
     1723         * frame buffer size after the AudioUnit was initialized.
     1724         */
     1725        uSize = sizeof(cFrames);
     1726        err = AudioUnitGetProperty(pStreamOut->audioUnit, kAudioUnitProperty_MaximumFramesPerSlice, kAudioUnitScope_Global,
     1727                                   0, &cFrames, &uSize);
     1728        if (err != noErr)
     1729        {
     1730            LogRel(("CoreAudio: Failed to get maximum frame buffer size from output audio device (%RI32)\n", err));
     1731
     1732            AudioUnitUninitialize(pStreamOut->audioUnit);
     1733            CA_BREAK_STMT(rc = VERR_AUDIO_BACKEND_INIT_FAILED);
     1734        }
     1735
     1736        /*
     1737         * Make sure that the ring buffer is big enough to hold the recording
     1738         * data. Compare the maximum frames per slice value with the frames
     1739         * necessary when using the converter where the sample rate could differ.
     1740         * The result is always multiplied by the channels per frame to get the
     1741         * samples count.
     1742         */
     1743        cSamples = cFrames * pStreamOut->streamFormat.mChannelsPerFrame;
     1744        if (!cSamples)
     1745        {
     1746            LogRel(("CoreAudio: Failed to determine samples buffer count output stream\n"));
     1747            CA_BREAK_STMT(rc = VERR_INVALID_PARAMETER);
     1748        }
     1749
     1750        /* Destroy any former internal ring buffer. */
     1751        if (pStreamOut->pCircBuf)
     1752        {
     1753            RTCircBufDestroy(pStreamOut->pCircBuf);
     1754            pStreamOut->pCircBuf = NULL;
     1755        }
     1756
     1757        /* Create the internal ring buffer. */
     1758        rc = RTCircBufCreate(&pStreamOut->pCircBuf, cSamples << pStream->Props.cShift);
     1759        if (RT_SUCCESS(rc))
     1760        {
     1761            /*
     1762             * Register callbacks.
     1763             */
    17501764#ifdef DEBUG
    1751         propAdr.mSelector = kAudioDeviceProcessorOverload;
    1752         propAdr.mScope    = kAudioUnitScope_Global;
    1753         err = AudioObjectAddPropertyListener(pStreamOut->deviceID, &propAdr,
    1754                                              coreAudioPlaybackAudioDevicePropertyChanged, (void *)pStreamOut);
    1755         if (err != noErr)
    1756             LogRel(("CoreAudio: Failed to register processor overload listener for output stream (%RI32)\n", err));
     1765            propAdr.mSelector = kAudioDeviceProcessorOverload;
     1766            propAdr.mScope    = kAudioUnitScope_Global;
     1767            err = AudioObjectAddPropertyListener(pStreamOut->deviceID, &propAdr,
     1768                                                 coreAudioPlaybackAudioDevicePropertyChanged, (void *)pStreamOut);
     1769            if (err != noErr)
     1770                LogRel(("CoreAudio: Failed to register processor overload listener for output stream (%RI32)\n", err));
    17571771#endif /* DEBUG */
    17581772
    1759         propAdr.mSelector = kAudioDevicePropertyNominalSampleRate;
    1760         propAdr.mScope    = kAudioUnitScope_Global;
    1761         err = AudioObjectAddPropertyListener(pStreamOut->deviceID, &propAdr,
    1762                                              coreAudioPlaybackAudioDevicePropertyChanged, (void *)pStreamOut);
    1763         /* Not fatal. */
    1764         if (err != noErr)
    1765             LogRel(("CoreAudio: Failed to register sample rate changed listener for output stream (%RI32)\n", err));
    1766     }
     1773            propAdr.mSelector = kAudioDevicePropertyNominalSampleRate;
     1774            propAdr.mScope    = kAudioUnitScope_Global;
     1775            err = AudioObjectAddPropertyListener(pStreamOut->deviceID, &propAdr,
     1776                                                 coreAudioPlaybackAudioDevicePropertyChanged, (void *)pStreamOut);
     1777            /* Not fatal. */
     1778            if (err != noErr)
     1779                LogRel(("CoreAudio: Failed to register sample rate changed listener for output stream (%RI32)\n", err));
     1780        }
     1781
     1782    } while (0);
    17671783
    17681784    if (RT_SUCCESS(rc))
     
    19101926    do
    19111927    {
    1912         size_t cbBuf = AudioMixBufSizeBytes(&pStream->MixBuf);
     1928        size_t cbBuf     = AudioMixBufSizeBytes(&pStream->MixBuf);
    19131929        size_t cbToWrite = RT_MIN(cbBuf, RTCircBufUsed(pStreamIn->pCircBuf));
    19141930
     
    19171933        size_t   cbToRead;
    19181934
    1919         Log3Func(("cbBuf=%zu, cbToWrite=%zu\n", cbBuf, cbToWrite));
     1935        Log3Func(("cbBuf=%zu, cbToWrite=%zu/%zu\n", cbBuf, cbToWrite, RTCircBufSize(pStreamIn->pCircBuf)));
    19201936
    19211937        while (cbToWrite)
     
    19291945            }
    19301946
     1947#ifdef DEBUG_DUMP_PCM_DATA
     1948            RTFILE fh;
     1949            rc = RTFileOpen(&fh, DEBUG_DUMP_PCM_DATA_PATH "ca-capture.pcm",
     1950                            RTFILE_O_OPEN_CREATE | RTFILE_O_APPEND | RTFILE_O_WRITE | RTFILE_O_DENY_NONE);
     1951            if (RT_SUCCESS(rc))
     1952            {
     1953                RTFileWrite(fh, puBuf + cbWrittenTotal, cbToRead, NULL);
     1954                RTFileClose(fh);
     1955            }
     1956            else
     1957                AssertFailed();
     1958#endif
    19311959            rc = AudioMixBufWriteCirc(&pStream->MixBuf, puBuf, cbToRead, &cWritten);
     1960
     1961            /* Release the read buffer, so it could be used for new data. */
     1962            RTCircBufReleaseReadBlock(pStreamIn->pCircBuf, cbToRead);
     1963
    19321964            if (   RT_FAILURE(rc)
    19331965                || !cWritten)
     
    20642096
    20652097    int rc = VINF_SUCCESS;
     2098
    20662099    OSStatus err;
    2067 
    20682100    switch (enmStreamCmd)
    20692101    {
     
    20832115
    20842116                err = AudioOutputUnitStart(pStreamOut->audioUnit);
    2085                 if (RT_UNLIKELY(err != noErr))
     2117                if (err != noErr)
    20862118                {
    20872119                    LogRel(("CoreAudio: Failed to start playback (%RI32)\n", err));
     
    21402172
    21412173    int rc = VINF_SUCCESS;
    2142     OSStatus err = noErr;
    2143 
     2174
     2175    OSStatus err;
    21442176    switch (enmStreamCmd)
    21452177    {
     
    21602192            }
    21612193
    2162             if (err != noErr)
    2163             {
    2164                 LogRel(("CoreAudio: Failed to start recording (%RI32)\n", err));
    2165                 rc = VERR_GENERAL_FAILURE; /** @todo Fudge! */
    2166             }
    21672194            break;
    21682195        }
     
    23082335    }
    23092336    else
    2310         LogRel(("CoreAudio: Failed to stop recording on uninit, rc=%Rrc\n", rc));
     2337    {
     2338        LogRel(("CoreAudio: Failed to stop recording on uninit (%RI32)\n", err));
     2339        rc = VERR_GENERAL_FAILURE; /** @todo Fudge! */
     2340    }
    23112341
    23122342    LogFlowFuncLeaveRC(rc);
     
    24232453    PCOREAUDIOSTREAMIN pStreamIn = (PCOREAUDIOSTREAMIN)pStream;
    24242454
     2455    LogFlowFunc(("enmRecSource=%RU32\n", pCfg->DestSource.Source));
     2456
    24252457    pStreamIn->deviceID            = kAudioDeviceUnknown;
    24262458    pStreamIn->audioUnit           = NULL;
     
    24392471    bool fDeviceByUser = false; /* Do we use a device which was set by the user? */
    24402472
    2441     LogFlowFunc(("enmRecSource=%RU32\n", pCfg->DestSource.Source));
    2442 
     2473    /* Initialize the hardware info section with the audio settings */
    24432474    int rc = DrvAudioHlpStreamCfgToProps(pCfg, &pStreamIn->Stream.Props);
    24442475    if (RT_SUCCESS(rc))
     
    25672598                                               kAudioObjectPropertyElementMaster };
    25682599        err = AudioObjectAddPropertyListener(pStreamOut->deviceID, &propAdr, drvHostCoreAudioDeviceStateChanged,
    2569                                              &pStreamOut->cbCtx);
     2600                                             (void *)&pStreamOut->cbCtx);
    25702601        if (err == noErr)
    25712602        {
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