Changeset 63922 in vbox
- Timestamp:
- Sep 21, 2016 1:55:55 PM (8 years ago)
- svn:sync-xref-src-repo-rev:
- 110805
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Devices/Audio/DrvHostCoreAudio.cpp
r63914 r63922 225 225 } 226 226 227 #ifndef VBOX_WITH_AUDIO_CA_QUEUES 227 228 static int coreAudioASBDToStreamCfg(AudioStreamBasicDescription *pASBD, PPDMAUDIOSTREAMCFG pCfg) 228 229 { … … 333 334 return err; 334 335 } 336 #endif 335 337 336 338 #if 0 /* unused */ … … 504 506 AudioQueueRef audioQueue; 505 507 /** The audio buffers which are used with the above audio queue. */ 506 AudioQueueBufferRef audioBuffer[2]; 508 AudioQueueBufferRef audioBuffer[3]; 509 AudioStreamBasicDescription asbdAcq; 507 510 #endif 508 511 /** The audio unit for this stream. */ … … 521 524 static int coreAudioStreamUninit(PCOREAUDIOSTREAM pCAStream); 522 525 526 #ifndef VBOX_WITH_AUDIO_CA_QUEUES 523 527 static int coreAudioStreamInitIn(PCOREAUDIOSTREAM pCAStream, PPDMAUDIOSTREAMCFG pCfgReq, PPDMAUDIOSTREAMCFG pCfgAcq); 524 528 static int coreAudioStreamInitOut(PCOREAUDIOSTREAM pCAStream, PPDMAUDIOSTREAMCFG pCfgReq, PPDMAUDIOSTREAMCFG pCfgAcq); 529 #endif 525 530 526 531 static int coreAudioStreamControl(PDRVHOSTCOREAUDIO pThis, PCOREAUDIOSTREAM pCAStream, PDMAUDIOSTREAMCMD enmStreamCmd); … … 531 536 532 537 static OSStatus coreAudioDevPropChgCb(AudioObjectID propertyID, UInt32 nAddresses, const AudioObjectPropertyAddress properties[], void *pvUser); 538 539 #ifndef VBOX_WITH_AUDIO_CA_QUEUES 533 540 static OSStatus coreAudioPlaybackCb(void *pvUser, AudioUnitRenderActionFlags *pActionFlags, const AudioTimeStamp *pAudioTS, UInt32 uBusID, UInt32 cFrames, AudioBufferList* pBufData); 534 541 #else 542 static void coreAudioInputQueueCb(void *pvUser, AudioQueueRef audioQueue, AudioQueueBufferRef audioBuffer, const AudioTimeStamp *pAudioTS, UInt32 cPacketDesc, const AudioStreamPacketDescription *paPacketDesc); 543 static void coreAudioOutputQueueCb(void *pvUser, AudioQueueRef audioQueue, AudioQueueBufferRef audioBuffer); 544 #endif 535 545 536 546 #ifndef VBOX_WITH_AUDIO_CA_QUEUES … … 1255 1265 PCOREAUDIOSTREAM pCAStream, PPDMAUDIODEVICE pDev, PPDMAUDIOSTREAMCFG pCfg) 1256 1266 { 1267 LogFunc(("pCAStream=%p\n", pCAStream)); 1268 1257 1269 int rc = coreAudioStreamUninit(pCAStream); 1258 1270 if (RT_SUCCESS(rc)) … … 1790 1802 AssertPtrReturn(pDev, VERR_INVALID_POINTER); 1791 1803 1792 #ifndef VBOX_WITH_AUDIO_CA_QUEUES1793 1804 Assert(pCAStream->Unit.pDevice == NULL); /* Make sure no device is assigned yet. */ 1794 #endif1795 1805 AssertPtr(pDev->pvData); 1796 1806 Assert(pDev->cbData == sizeof(COREAUDIODEVICEDATA)); … … 1801 1811 #endif 1802 1812 1803 #ifndef VBOX_WITH_AUDIO_CA_QUEUES1804 1813 pCAStream->Unit.pDevice = pDev; 1805 #endif1806 1814 pCAStream->pDrv = pThis; 1807 1815 … … 1816 1824 static DECLCALLBACK(int) coreAudioQueueThread(RTTHREAD hThreadSelf, void *pvUser) 1817 1825 { 1826 RT_NOREF(hThreadSelf); 1827 1818 1828 PCOREAUDIOSTREAM pCAStream = (PCOREAUDIOSTREAM)pvUser; 1819 1829 AssertPtr(pCAStream); 1820 1830 1821 1831 LogFunc(("Starting pCAStream=%p\n", pCAStream)); 1822 1823 RTThreadUserSignal(RTThreadSelf());1824 1825 const bool fIn = pCAStream->Stream.enmDir == PDMAUDIODIR_IN;1826 1827 while (!ASMAtomicReadBool(&pCAStream->fShutdown))1828 {1829 CFRunLoopRunInMode(kCFRunLoopDefaultMode, 0.10, 1);1830 }1831 1832 if (fIn)1833 {1834 AudioQueueStop(pCAStream->audioQueue, 1);1835 }1836 else1837 {1838 AudioQueueStop(pCAStream->audioQueue, 0);1839 CFRunLoopRunInMode(kCFRunLoopDefaultMode, 2, 0);1840 }1841 1842 LogFunc(("Ended pCAStream=%p\n", pCAStream));1843 return VINF_SUCCESS;1844 }1845 1846 static void coreAudioInputQueueCb(void *pvUser, AudioQueueRef audioQueue, AudioQueueBufferRef audioBuffer,1847 const AudioTimeStamp *pAudioTS,1848 UInt32 cPacketDes, const AudioStreamPacketDescription *pPacketDesc)1849 {1850 PCOREAUDIOSTREAM pCAStream = (PCOREAUDIOSTREAM)pvUser;1851 AssertPtr(pCAStream);1852 1853 int rc = RTCritSectEnter(&pCAStream->CritSect);1854 AssertRC(rc);1855 1856 size_t cbWritten = 0;1857 1858 if (pCAStream->fRunning)1859 {1860 PRTCIRCBUF pCircBuf = pCAStream->pCircBuf;1861 AssertPtr(pCircBuf);1862 1863 UInt8 *pvSrc = (UInt8 *)audioBuffer->mAudioData;1864 UInt8 *pvDst = NULL;1865 1866 size_t cbToWrite = audioBuffer->mAudioDataByteSize;1867 if (!cbToWrite)1868 return;1869 1870 size_t cbLeft = cbToWrite;1871 1872 while (cbLeft)1873 {1874 /* Try to acquire the necessary block from the ring buffer. */1875 RTCircBufAcquireWriteBlock(pCircBuf, cbLeft, (void **)&pvDst, &cbToWrite);1876 1877 /* Copy the data from our ring buffer to the core audio buffer. */1878 memcpy((UInt8 *)pvDst + cbWritten, pvSrc + cbWritten, cbToWrite);1879 1880 /* Release the read buffer, so it could be used for new data. */1881 RTCircBufReleaseReadBlock(pCircBuf, cbToWrite);1882 1883 cbWritten += cbToWrite;1884 1885 Assert(cbLeft >= cbToWrite);1886 cbLeft -= cbToWrite;1887 }1888 }1889 1890 OSStatus err = AudioQueueEnqueueBuffer(audioQueue, audioBuffer, 0, NULL);1891 1892 Log3Func(("pCAStream=%p, cbWritten=%zu, err=%RI32\n", pCAStream, cbWritten, err));1893 1894 rc = RTCritSectLeave(&pCAStream->CritSect);1895 AssertRC(rc);1896 }1897 1898 static void coreAudioOutputQueueCb(void *pvUser, AudioQueueRef audioQueue, AudioQueueBufferRef audioBuffer)1899 {1900 PCOREAUDIOSTREAM pCAStream = (PCOREAUDIOSTREAM)pvUser;1901 AssertPtr(pCAStream);1902 1903 int rc = RTCritSectEnter(&pCAStream->CritSect);1904 AssertRC(rc);1905 1906 if (!pCAStream->fRunning)1907 {1908 RT_BZERO(audioBuffer->mAudioData, audioBuffer->mAudioDataBytesCapacity);1909 return;1910 }1911 1912 PRTCIRCBUF pCircBuf = pCAStream->pCircBuf;1913 AssertPtr(pCircBuf);1914 1915 size_t cbToRead = RT_MIN(RTCircBufUsed(pCircBuf), audioBuffer->mAudioDataBytesCapacity);1916 if (!cbToRead)1917 return;1918 1919 UInt8 *pvSrc = NULL;1920 UInt8 *pvDst = (UInt8 *)audioBuffer->mAudioData;1921 1922 size_t cbRead = 0;1923 size_t cbLeft = cbToRead;1924 1925 while (cbLeft)1926 {1927 /* Try to acquire the necessary block from the ring buffer. */1928 RTCircBufAcquireReadBlock(pCircBuf, cbLeft, (void **)&pvSrc, &cbToRead);1929 1930 /* Break if nothing is used anymore. */1931 if (!cbToRead)1932 break;1933 1934 /* Copy the data from our ring buffer to the core audio buffer. */1935 memcpy((UInt8 *)pvDst + cbRead, pvSrc, cbToRead);1936 1937 /* Release the read buffer, so it could be used for new data. */1938 RTCircBufReleaseReadBlock(pCircBuf, cbToRead);1939 1940 /* Move offset. */1941 cbRead += cbToRead;1942 1943 Assert(cbToRead <= cbLeft);1944 cbLeft -= cbToRead;1945 }1946 1947 OSStatus err = AudioQueueEnqueueBuffer(audioQueue, audioBuffer, 0, NULL);1948 1949 Log3Func(("pCAStream=%p, cbRead=%zu, err=%RI32\n", pCAStream, cbRead, err));1950 1951 rc = RTCritSectLeave(&pCAStream->CritSect);1952 AssertRC(rc);1953 }1954 1955 static int coreAudioStreamInitQueue(PCOREAUDIOSTREAM pCAStream, PPDMAUDIOSTREAMCFG pCfgReq, PPDMAUDIOSTREAMCFG pCfgAcq)1956 {1957 LogFunc(("pCAStream=%p, pCfgReq=%p, pCfgAcq=%p\n", pCAStream, pCfgReq, pCfgAcq));1958 1959 const bool fIn = pCAStream->Stream.enmDir == PDMAUDIODIR_IN;1960 1961 /* Create the recording device's out format based on our required audio settings. */1962 AudioStreamBasicDescription reqFmt;1963 int rc = coreAudioStreamCfgToASBD(pCfgReq, &reqFmt);1964 if (RT_FAILURE(rc))1965 {1966 LogRel(("CoreAudio: Failed to convert requested %s format to native format (%Rrc)\n",1967 fIn ? "input" : "output", rc));1968 return rc;1969 }1970 1832 1971 1833 /* … … 1973 1835 */ 1974 1836 OSStatus err; 1975 if ( fIn)1976 err = AudioQueueNewInput(& reqFmt, coreAudioInputQueueCb, pCAStream /* pvData */,1837 if (pCAStream->enmDir == PDMAUDIODIR_IN) 1838 err = AudioQueueNewInput(&pCAStream->asbdAcq, coreAudioInputQueueCb, pCAStream /* pvData */, 1977 1839 CFRunLoopGetCurrent(), kCFRunLoopDefaultMode, 0, &pCAStream->audioQueue); 1978 1840 else 1979 err = AudioQueueNewOutput(& reqFmt, coreAudioOutputQueueCb, pCAStream /* pvData */,1841 err = AudioQueueNewOutput(&pCAStream->asbdAcq, coreAudioOutputQueueCb, pCAStream /* pvData */, 1980 1842 CFRunLoopGetCurrent(), kCFRunLoopDefaultMode, 0, &pCAStream->audioQueue); 1981 1843 … … 1986 1848 * Assign device to queue. 1987 1849 */ 1988 AssertPtr(pCAStream->Unit.pDevice);1989 1850 PCOREAUDIODEVICEDATA pData = (PCOREAUDIODEVICEDATA)pCAStream->Unit.pDevice->pvData; 1990 1851 AssertPtr(pData); … … 2016 1877 } 2017 1878 1879 if (err != noErr) 1880 return VERR_GENERAL_FAILURE; /** @todo Fudge! */ 1881 2018 1882 /* 2019 1883 * Start the queue. 2020 1884 */ 2021 if (err != noErr) 2022 { 2023 err = AudioQueueStart(pCAStream->audioQueue, NULL); 2024 } 1885 err = AudioQueueStart(pCAStream->audioQueue, NULL); 1886 1887 RTThreadUserSignal(RTThreadSelf()); 1888 1889 const bool fIn = pCAStream->enmDir == PDMAUDIODIR_IN; 1890 1891 while (!ASMAtomicReadBool(&pCAStream->fShutdown)) 1892 { 1893 CFRunLoopRunInMode(kCFRunLoopDefaultMode, 0.10, 1); 1894 } 1895 1896 if (fIn) 1897 { 1898 AudioQueueStop(pCAStream->audioQueue, 1); 1899 } 1900 else 1901 { 1902 AudioQueueStop(pCAStream->audioQueue, 0); 1903 } 1904 1905 for (size_t i = 0; i < RT_ELEMENTS(pCAStream->audioBuffer); i++) 1906 { 1907 if (pCAStream->audioBuffer[i]) 1908 AudioQueueFreeBuffer(pCAStream->audioQueue, pCAStream->audioBuffer[i]); 1909 } 1910 1911 AudioQueueDispose(pCAStream->audioQueue, 1); 1912 1913 LogFunc(("Ended pCAStream=%p\n", pCAStream)); 1914 return VINF_SUCCESS; 1915 } 1916 1917 static void coreAudioInputQueueCb(void *pvUser, AudioQueueRef audioQueue, AudioQueueBufferRef audioBuffer, 1918 const AudioTimeStamp *pAudioTS, 1919 UInt32 cPacketDesc, const AudioStreamPacketDescription *paPacketDesc) 1920 { 1921 RT_NOREF(pAudioTS, cPacketDesc, paPacketDesc); 1922 1923 PCOREAUDIOSTREAM pCAStream = (PCOREAUDIOSTREAM)pvUser; 1924 AssertPtr(pCAStream); 1925 1926 int rc = RTCritSectEnter(&pCAStream->CritSect); 1927 AssertRC(rc); 1928 1929 size_t cbWritten = 0; 1930 1931 const bool fRunning = ASMAtomicReadBool(&pCAStream->fRunning); 1932 1933 if (fRunning) 1934 { 1935 PRTCIRCBUF pCircBuf = pCAStream->pCircBuf; 1936 AssertPtr(pCircBuf); 1937 1938 UInt8 *pvSrc = (UInt8 *)audioBuffer->mAudioData; 1939 UInt8 *pvDst = NULL; 1940 1941 size_t cbToWrite = audioBuffer->mAudioDataByteSize; 1942 size_t cbLeft = cbToWrite; 1943 1944 while (cbLeft) 1945 { 1946 /* Try to acquire the necessary block from the ring buffer. */ 1947 RTCircBufAcquireWriteBlock(pCircBuf, cbLeft, (void **)&pvDst, &cbToWrite); 1948 1949 /* Copy the data from our ring buffer to the core audio buffer. */ 1950 memcpy((UInt8 *)pvDst + cbWritten, pvSrc + cbWritten, cbToWrite); 1951 1952 /* Release the read buffer, so it could be used for new data. */ 1953 RTCircBufReleaseReadBlock(pCircBuf, cbToWrite); 1954 1955 cbWritten += cbToWrite; 1956 1957 Assert(cbLeft >= cbToWrite); 1958 cbLeft -= cbToWrite; 1959 } 1960 } 1961 1962 if (cbWritten) 1963 { 1964 OSStatus err = AudioQueueEnqueueBuffer(audioQueue, audioBuffer, 0, NULL); 1965 if (err != noErr) 1966 LogFunc(("Failed writing %zu bytes\n", cbWritten)); 1967 } 1968 1969 LogFunc(("pCAStream=%p, fRunning=%RTbool, cbWritten=%zu\n", pCAStream, fRunning, cbWritten)); 1970 1971 rc = RTCritSectLeave(&pCAStream->CritSect); 1972 AssertRC(rc); 1973 } 1974 1975 static void coreAudioOutputQueueCb(void *pvUser, AudioQueueRef audioQueue, AudioQueueBufferRef audioBuffer) 1976 { 1977 PCOREAUDIOSTREAM pCAStream = (PCOREAUDIOSTREAM)pvUser; 1978 AssertPtr(pCAStream); 1979 1980 int rc = RTCritSectEnter(&pCAStream->CritSect); 1981 AssertRC(rc); 1982 1983 size_t cbRead = 0; 1984 1985 const bool fRunning = ASMAtomicReadBool(&pCAStream->fRunning); 1986 1987 if (fRunning) 1988 { 1989 PRTCIRCBUF pCircBuf = pCAStream->pCircBuf; 1990 AssertPtr(pCircBuf); 1991 1992 UInt8 *pvSrc = NULL; 1993 UInt8 *pvDst = (UInt8 *)audioBuffer->mAudioData; 1994 1995 size_t cbToRead = RT_MIN(RTCircBufUsed(pCircBuf), audioBuffer->mAudioDataBytesCapacity); 1996 size_t cbLeft = cbToRead; 1997 1998 while (cbLeft) 1999 { 2000 /* Try to acquire the necessary block from the ring buffer. */ 2001 RTCircBufAcquireReadBlock(pCircBuf, cbLeft, (void **)&pvSrc, &cbToRead); 2002 2003 /* Break if nothing is used anymore. */ 2004 if (!cbToRead) 2005 break; 2006 2007 /* Copy the data from our ring buffer to the core audio buffer. */ 2008 memcpy((UInt8 *)pvDst + cbRead, pvSrc, cbToRead); 2009 2010 /* Release the read buffer, so it could be used for new data. */ 2011 RTCircBufReleaseReadBlock(pCircBuf, cbToRead); 2012 2013 /* Move offset. */ 2014 cbRead += cbToRead; 2015 Assert(cbRead <= audioBuffer->mAudioDataBytesCapacity); 2016 2017 Assert(cbToRead <= cbLeft); 2018 cbLeft -= cbToRead; 2019 } 2020 } 2021 2022 audioBuffer->mAudioDataByteSize = cbRead; 2023 2024 if (audioBuffer->mAudioDataByteSize < audioBuffer->mAudioDataBytesCapacity) 2025 { 2026 RT_BZERO((UInt8 *)audioBuffer->mAudioData + audioBuffer->mAudioDataByteSize, 2027 audioBuffer->mAudioDataBytesCapacity - audioBuffer->mAudioDataByteSize); 2028 2029 audioBuffer->mAudioDataByteSize = audioBuffer->mAudioDataBytesCapacity; 2030 } 2031 2032 AudioQueueEnqueueBuffer(audioQueue, audioBuffer, 0, NULL); 2033 2034 LogFunc(("pCAStream=%p, fRunning=%RTbool, cbCapacity=%RU32, cbRead=%zu\n", 2035 pCAStream, fRunning, audioBuffer->mAudioDataBytesCapacity, cbRead)); 2036 2037 rc = RTCritSectLeave(&pCAStream->CritSect); 2038 AssertRC(rc); 2039 } 2040 2041 static int coreAudioStreamInitQueue(PCOREAUDIOSTREAM pCAStream, PPDMAUDIOSTREAMCFG pCfgReq, PPDMAUDIOSTREAMCFG pCfgAcq) 2042 { 2043 LogFunc(("pCAStream=%p, pCfgReq=%p, pCfgAcq=%p\n", pCAStream, pCfgReq, pCfgAcq)); 2044 2045 /* No device assigned? Bail out early. */ 2046 if (pCAStream->Unit.pDevice == NULL) 2047 return VERR_NOT_AVAILABLE; 2048 2049 pCAStream->enmDir = pCfgReq->enmDir; 2050 2051 const bool fIn = pCAStream->enmDir == PDMAUDIODIR_IN; 2052 2053 /* Create the recording device's out format based on our required audio settings. */ 2054 int rc = coreAudioStreamCfgToASBD(pCfgReq, &pCAStream->asbdAcq); 2055 if (RT_FAILURE(rc)) 2056 { 2057 LogRel(("CoreAudio: Failed to convert requested %s format to native format (%Rrc)\n", 2058 fIn ? "input" : "output", rc)); 2059 return rc; 2060 } 2061 2062 coreAudioPrintASBD( fIn 2063 ? "Capturing queue format" 2064 : "Playback queue format", &pCAStream->asbdAcq); 2065 2066 rc = RTCircBufCreate(&pCAStream->pCircBuf, 4096 << 1 /*pHstStrmIn->Props.cShift*/); /** @todo FIX THIS !!! */ 2067 if (RT_FAILURE(rc)) 2068 return rc; 2025 2069 2026 2070 /* 2027 2071 * Start the thread. 2028 2072 */ 2029 pCAStream->fShutdown = false; 2030 2031 if (err != noErr) 2032 { 2033 rc = RTThreadCreate(&pCAStream->hThread, coreAudioQueueThread, 2034 pCAStream /* pvUser */, 0 /* Default stack size */, 2035 RTTHREADTYPE_DEFAULT, RTTHREADFLAGS_WAITABLE, "CAQUEUE"); 2036 if (RT_SUCCESS(rc)) 2037 rc = RTThreadUserWait(pCAStream->hThread, 10 * 1000 /* 10s timeout */); 2038 } 2039 2073 rc = RTThreadCreate(&pCAStream->hThread, coreAudioQueueThread, 2074 pCAStream /* pvUser */, 0 /* Default stack size */, 2075 RTTHREADTYPE_DEFAULT, RTTHREADFLAGS_WAITABLE, "CAQUEUE"); 2076 if (RT_SUCCESS(rc)) 2077 rc = RTThreadUserWait(pCAStream->hThread, 10 * 1000 /* 10s timeout */); 2078 2079 LogFunc(("Returning %Rrc\n", rc)); 2040 2080 return rc; 2041 2081 } … … 2045 2085 LogFunc(("pCAStream=%p\n", pCAStream)); 2046 2086 2047 ASMAtomicXchgBool(&pCAStream->fShutdown, true); 2048 2049 int rcThread; 2050 int rc = RTThreadWait(pCAStream->hThread, 30 * 1000, &rcThread); 2051 if (RT_FAILURE(rc)) 2052 return rc; 2053 2054 RT_NOREF(rcThread); 2055 LogFunc(("Thread stopped with %Rrc\n", rcThread)); 2056 2057 if (pCAStream->audioQueue) 2058 { 2059 for (size_t i = 0; i < RT_ELEMENTS(pCAStream->audioBuffer); i++) 2060 { 2061 if (pCAStream->audioBuffer[i]) 2062 AudioQueueFreeBuffer(pCAStream->audioQueue, pCAStream->audioBuffer[i]); 2063 } 2064 2065 AudioQueueDispose(pCAStream->audioQueue, 1); 2066 } 2067 2087 int rc; 2088 2089 if (pCAStream->hThread != NIL_RTTHREAD) 2090 { 2091 LogFunc(("Waiting for thread ...\n")); 2092 2093 ASMAtomicXchgBool(&pCAStream->fShutdown, true); 2094 2095 int rcThread; 2096 rc = RTThreadWait(pCAStream->hThread, 30 * 1000, &rcThread); 2097 if (RT_FAILURE(rc)) 2098 return rc; 2099 2100 RT_NOREF(rcThread); 2101 LogFunc(("Thread stopped with %Rrc\n", rcThread)); 2102 2103 pCAStream->hThread = NIL_RTTHREAD; 2104 } 2105 2106 if (pCAStream->pCircBuf) 2107 { 2108 RTCircBufDestroy(pCAStream->pCircBuf); 2109 pCAStream->pCircBuf = NULL; 2110 } 2111 2112 LogFunc(("Returning\n")); 2068 2113 return VINF_SUCCESS; 2069 2114 } … … 2071 2116 static int coreAudioStreamUninit(PCOREAUDIOSTREAM pCAStream) 2072 2117 { 2073 int rc = coreAudioStreamUninitQueue(pCAStream); 2074 return rc; 2118 LogFunc(("pCAStream=%p\n", pCAStream)); 2119 2120 int rc = coreAudioStreamUninitQueue(pCAStream); 2121 return rc; 2075 2122 } 2076 2123 #else /* !VBOX_WITH_AUDIO_CA_QUEUES */ … … 2098 2145 do 2099 2146 { 2100 ASMAtomicXchgU32(&pCAStream->enmStatus, COREAUDIOSTATUS_IN_INIT);2101 2102 2147 /* Get the default frames buffer size, so that we can setup our internal buffers. */ 2103 2148 UInt32 cFrames; … … 2441 2486 pCfgAcq->cSampleBufferSize = cSamples; 2442 2487 } 2443 else2444 {2445 int rc2 = coreAudioStreamUninit(pCAStream);2446 AssertRC(rc2);2447 2448 ASMAtomicXchgU32(&pCAStream->enmStatus, COREAUDIOSTATUS_UNINIT);2449 }2450 2488 2451 2489 LogFunc(("cSamples=%RU32, rc=%Rrc\n", cSamples, rc)); … … 2475 2513 do 2476 2514 { 2477 ASMAtomicXchgU32(&pCAStream->enmStatus, COREAUDIOSTATUS_IN_INIT);2478 2479 2515 /* Get the default frames buffer size, so that we can setup our internal buffers. */ 2480 2516 UInt32 cFrames; … … 2679 2715 2680 2716 pCfgAcq->cSampleBufferSize = cSamples; 2681 }2682 else2683 {2684 int rc2 = coreAudioStreamUninit(pCAStream);2685 AssertRC(rc2);2686 2687 ASMAtomicXchgU32(&pCAStream->enmStatus, COREAUDIOSTATUS_UNINIT);2688 2717 } 2689 2718 … … 3219 3248 uint32_t cbReadTotal = 0; 3220 3249 3250 int rc = VINF_SUCCESS; 3251 3252 #ifdef VBOX_WITH_AUDIO_CA_QUEUES 3253 rc = RTCritSectEnter(&pCAStream->CritSect); 3254 AssertRC(rc); 3255 #endif 3256 3221 3257 size_t cbToRead = RT_MIN(cbLive, RTCircBufFree(pCAStream->pCircBuf)); 3222 Log3Func(("cbToRead=%zu\n", cbToRead)); 3223 3224 int rc = VINF_SUCCESS; 3258 Log3Func(("cbLive=%zu, cbToRead=%zu\n", cbLive, cbToRead)); 3225 3259 3226 3260 while (cbToRead) … … 3258 3292 } 3259 3293 3294 #ifdef VBOX_WITH_AUDIO_CA_QUEUES 3295 int rc2 = RTCritSectLeave(&pCAStream->CritSect); 3296 AssertRC(rc2); 3297 #endif 3298 3260 3299 if (RT_SUCCESS(rc)) 3261 3300 { … … 3293 3332 int rc = VINF_SUCCESS; 3294 3333 3295 OSStatus err;3296 3334 switch (enmStreamCmd) 3297 3335 { … … 3300 3338 { 3301 3339 #ifdef VBOX_WITH_AUDIO_CA_QUEUES 3340 LogFunc(("Queue enable/resume\n")); 3302 3341 ASMAtomicXchgBool(&pCAStream->fRunning, true); 3303 3342 #else … … 3305 3344 if (!coreAudioUnitIsRunning(pCAStream)) 3306 3345 { 3307 err = AudioUnitReset(pCAStream->Unit.audioUnit, kAudioUnitScope_Input, 0);3346 OSStatus err = AudioUnitReset(pCAStream->Unit.audioUnit, kAudioUnitScope_Input, 0); 3308 3347 if (err != noErr) 3309 3348 { … … 3329 3368 { 3330 3369 #ifdef VBOX_WITH_AUDIO_CA_QUEUES 3370 LogFunc(("Queue disable/pause\n")); 3331 3371 ASMAtomicXchgBool(&pCAStream->fRunning, false); 3332 3372 #else … … 3334 3374 if (coreAudioUnitIsRunning(pCAStream)) 3335 3375 { 3336 err = AudioOutputUnitStop(pCAStream->Unit.audioUnit);3376 OSStatus err = AudioOutputUnitStop(pCAStream->Unit.audioUnit); 3337 3377 if (err != noErr) 3338 3378 { … … 3492 3532 return rc; 3493 3533 3534 pCAStream->hThread = NIL_RTTHREAD; 3494 3535 pCAStream->fRunning = false; 3495 3536 pCAStream->fShutdown = false; … … 3506 3547 if (pDev) /* (Default) device available? */ 3507 3548 { 3549 /* Sanity. */ 3550 AssertPtr(pDev->pvData); 3551 Assert(pDev->cbData); 3552 3508 3553 /* Init the Core Audio stream. */ 3509 3554 rc = coreAudioStreamInit(pCAStream, pThis, pDev); 3510 3555 if (RT_SUCCESS(rc)) 3511 3556 { 3512 /* Sanity. */ 3513 AssertPtr(pDev->pvData); 3514 Assert(pDev->cbData); 3515 3557 #ifdef VBOX_WITH_AUDIO_CA_QUEUES 3558 ASMAtomicXchgU32(&pCAStream->enmStatus, COREAUDIOSTATUS_IN_INIT); 3559 3560 rc = coreAudioStreamInitQueue(pCAStream, pCfgReq, pCfgAcq); 3561 #else 3562 if (fIn) 3563 rc = coreAudioStreamInitIn (pCAStream, pCfgReq, pCfgAcq); 3564 else 3565 rc = coreAudioStreamInitOut(pCAStream, pCfgReq, pCfgAcq); 3566 #endif 3516 3567 if (RT_SUCCESS(rc)) 3517 3568 { 3518 #ifdef VBOX_WITH_AUDIO_CA_QUEUES 3519 rc = coreAudioStreamInitQueue(pCAStream, pCfgReq, pCfgAcq); 3520 #else 3521 if (fIn) 3522 rc = coreAudioStreamInitIn (pCAStream, pCfgReq, pCfgAcq); 3523 else 3524 rc = coreAudioStreamInitOut(pCAStream, pCfgReq, pCfgAcq); 3525 #endif 3526 if (RT_FAILURE(rc)) 3527 { 3528 int rc2 = coreAudioStreamUninit(pCAStream); 3529 AssertRC(rc2); 3530 } 3569 ASMAtomicXchgU32(&pCAStream->enmStatus, COREAUDIOSTATUS_INIT); 3570 } 3571 else 3572 { 3573 ASMAtomicXchgU32(&pCAStream->enmStatus, COREAUDIOSTATUS_IN_UNINIT); 3574 3575 int rc2 = coreAudioStreamUninit(pCAStream); 3576 AssertRC(rc2); 3577 3578 ASMAtomicXchgU32(&pCAStream->enmStatus, COREAUDIOSTATUS_UNINIT); 3531 3579 } 3532 3580 } … … 3561 3609 )) 3562 3610 { 3611 AssertFailed(); 3563 3612 return VINF_SUCCESS; 3564 3613 }
Note:
See TracChangeset
for help on using the changeset viewer.