Changeset 54508 in vbox for trunk/src/VBox/Devices/Audio
- Timestamp:
- Feb 25, 2015 6:08:56 PM (10 years ago)
- svn:sync-xref-src-repo-rev:
- 98618
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Devices/Audio/DrvHostCoreAudio.cpp
r54491 r54508 693 693 694 694 /* Get the device' UUID. */ 695 propAdr.mSelector = kAudio ObjectPropertyName;695 propAdr.mSelector = kAudioDevicePropertyDeviceUID; 696 696 err = AudioObjectGetPropertyData(pStreamIn->deviceID, &propAdr, 0, NULL, &uSize, &strTemp); 697 697 if (err == noErr) … … 1007 1007 { 1008 1008 /* Fetch the default audio input device currently in use. */ 1009 AudioObjectPropertyAddress propAdr = { kAudioHardwarePropertyDefault InputDevice,1009 AudioObjectPropertyAddress propAdr = { kAudioHardwarePropertyDefaultOutputDevice, 1010 1010 kAudioObjectPropertyScopeGlobal, kAudioObjectPropertyElementMaster }; 1011 1011 uSize = sizeof(pStreamOut->deviceID); 1012 err = AudioObjectGetPropertyData(kAudioObjectSystemObject, &propAdr, 0, NULL, &uSize, 1012 err = AudioObjectGetPropertyData(kAudioObjectSystemObject, &propAdr, 0, NULL, &uSize, &pStreamOut->deviceID); 1013 1013 if (err != noErr) 1014 1014 { … … 1019 1019 1020 1020 /* 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. 1022 1022 */ 1023 1023 CFStringRef strTemp; … … 1036 1036 1037 1037 /* Get the device' UUID. */ 1038 propAdr.mSelector = kAudio ObjectPropertyName;1038 propAdr.mSelector = kAudioDevicePropertyDeviceUID; 1039 1039 err = AudioObjectGetPropertyData(pStreamOut->deviceID, &propAdr, 0, NULL, &uSize, &strTemp); 1040 1040 if (err == noErr) … … 1545 1545 1546 1546 int rc = VINF_SUCCESS; 1547 OSStatus err; 1547 1548 1548 1549 switch (enmStreamCmd) … … 1553 1554 if (!drvHostCoreAudioIsRunning(pStreamOut->deviceID)) 1554 1555 { 1555 OSStatuserr = AudioUnitReset(pStreamOut->audioUnit, kAudioUnitScope_Input, 0);1556 err = AudioUnitReset(pStreamOut->audioUnit, kAudioUnitScope_Input, 0); 1556 1557 if (err != noErr) 1557 1558 { … … 1565 1566 { 1566 1567 LogRel(("CoreAudio: Failed to start playback (%RI32)\n", err)); 1567 r eturnVERR_GENERAL_FAILURE; /** @todo Fudge! */1568 rc = VERR_GENERAL_FAILURE; /** @todo Fudge! */ 1568 1569 } 1569 1570 } … … 1576 1577 if (drvHostCoreAudioIsRunning(pStreamOut->deviceID)) 1577 1578 { 1578 OSStatuserr = AudioOutputUnitStop(pStreamOut->audioUnit);1579 err = AudioOutputUnitStop(pStreamOut->audioUnit); 1579 1580 if (err != noErr) 1580 1581 { 1581 1582 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; 1583 1585 } 1584 1586 … … 1587 1589 { 1588 1590 LogRel(("CoreAudio: Failed to reset AudioUnit (%RI32)\n", err)); 1589 r eturnVERR_GENERAL_FAILURE; /** @todo Fudge! */1591 rc = VERR_GENERAL_FAILURE; /** @todo Fudge! */ 1590 1592 } 1591 1593 } … … 1598 1600 } 1599 1601 1602 LogFlowFuncLeaveRC(rc); 1600 1603 return rc; 1601 1604 } … … 1616 1619 1617 1620 int rc = VINF_SUCCESS; 1621 OSStatus err; 1618 1622 1619 1623 switch (enmStreamCmd) … … 1621 1625 case PDMAUDIOSTREAMCMD_ENABLE: 1622 1626 { 1623 OSStatus err;1624 1625 1627 /* Only start the device if it is actually stopped */ 1626 1628 if (!drvHostCoreAudioIsRunning(pStreamIn->deviceID)) … … 1628 1630 RTCircBufReset(pStreamIn->pBuf); 1629 1631 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 } 1630 1638 } 1631 1639 … … 1643 1651 if (drvHostCoreAudioIsRunning(pStreamIn->deviceID)) 1644 1652 { 1645 OSStatuserr = AudioOutputUnitStop(pStreamIn->audioUnit);1646 if ( RT_UNLIKELY(err != noErr))1653 err = AudioOutputUnitStop(pStreamIn->audioUnit); 1654 if (err != noErr) 1647 1655 { 1648 1656 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; 1650 1659 } 1651 1660 1652 1661 err = AudioUnitReset(pStreamIn->audioUnit, kAudioUnitScope_Input, 0); 1653 if ( RT_UNLIKELY(err != noErr))1662 if (err != noErr) 1654 1663 { 1655 1664 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; 1657 1667 } 1658 1668 } … … 1665 1675 } 1666 1676 1677 LogFlowFuncLeaveRC(rc); 1667 1678 return rc; 1668 1679 } … … 1670 1681 static DECLCALLBACK(int) drvHostCoreAudioFiniIn(PPDMIHOSTAUDIO pInterface, PPDMAUDIOHSTSTRMIN pHstStrmIn) 1671 1682 { 1672 int rc = 0;1673 OSStatus err = noErr;1674 uint32_t status;1675 1676 1683 PCOREAUDIOSTREAMIN pStreamIn = (PCOREAUDIOSTREAMIN) pHstStrmIn; 1677 1684 … … 1679 1686 PDRVHOSTCOREAUDIO pThis = PDMINS_2_DATA(pDrvIns, PDRVHOSTCOREAUDIO); 1680 1687 1681 LogFlow (("drvHostCoreAudioFiniIn \n"));1682 1683 status = ASMAtomicReadU32(&pStreamIn->status);1688 LogFlowFuncEnter(); 1689 1690 uint32_t status = ASMAtomicReadU32(&pStreamIn->status); 1684 1691 if (!( status == CA_STATUS_INIT 1685 1692 || status == CA_STATUS_REINIT)) … … 1688 1695 } 1689 1696 1690 rc = drvHostCoreAudioControlIn(pInterface, &pStreamIn->streamIn, PDMAUDIOSTREAMCMD_DISABLE); 1697 OSStatus err = noErr; 1698 1699 int rc = drvHostCoreAudioControlIn(pInterface, &pStreamIn->streamIn, PDMAUDIOSTREAMCMD_DISABLE); 1691 1700 if (RT_SUCCESS(rc)) 1692 1701 { … … 1707 1716 if (RT_UNLIKELY(err != noErr)) 1708 1717 LogRel(("CoreAudio: Failed to remove the sample rate changed listener (%RI32)\n", err)); 1718 1709 1719 if (pStreamIn->converter) 1710 1720 { … … 1727 1737 } 1728 1738 else 1739 { 1729 1740 LogRel(("CoreAudio: Failed to close the AudioUnit (%RI32)\n", err)); 1741 rc = VERR_GENERAL_FAILURE; /** @todo Fudge! */ 1742 } 1730 1743 } 1731 1744 else 1745 { 1732 1746 LogRel(("CoreAudio: Failed to uninitialize the AudioUnit (%RI32)\n", err)); 1747 rc = VERR_GENERAL_FAILURE; /** @todo Fudge! */ 1748 } 1733 1749 } 1734 1750 else 1751 { 1735 1752 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; 1738 1758 } 1739 1759 … … 1795 1815 LogRel(("CoreAudio: Failed to stop playback, rc=%Rrc\n", rc)); 1796 1816 1797 return VINF_SUCCESS; 1817 LogFlowFuncLeaveRC(rc); 1818 return rc; 1798 1819 } 1799 1820 … … 1803 1824 uint32_t *pcSamples) 1804 1825 { 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 1807 1838 bool fDeviceByUser = false; 1808 1839 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"));1821 1840 /* 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 { 1824 1844 #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 else1833 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 } 1835 1855 #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; 1854 1876 } 1855 1877 … … 1864 1886 bool fDeviceByUser = false; /* use we a device which was set by the user? */ 1865 1887 1866 LogFlow (("drvHostCoreAudioInitOut\n"));1888 LogFlowFuncEnter(); 1867 1889 1868 1890 ASMAtomicXchgU32(&pStreamOut->status, CA_STATUS_UNINIT); 1869 1891 1870 1892 pStreamOut->audioUnit = NULL; 1871 pStreamOut->deviceID = kAudioDeviceUnknown;1893 pStreamOut->deviceID = kAudioDeviceUnknown; 1872 1894 1873 1895 /* Initialize the hardware info section with the audio settings */
Note:
See TracChangeset
for help on using the changeset viewer.