VirtualBox

Changeset 63922 in vbox


Ignore:
Timestamp:
Sep 21, 2016 1:55:55 PM (8 years ago)
Author:
vboxsync
svn:sync-xref-src-repo-rev:
110805
Message:

Audio/DrvHostCoreAudio.cpp: Update on Audio Queues (work in progress, not yet enabled by default).

File:
1 edited

Legend:

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

    r63914 r63922  
    225225}
    226226
     227#ifndef VBOX_WITH_AUDIO_CA_QUEUES
    227228static int coreAudioASBDToStreamCfg(AudioStreamBasicDescription *pASBD, PPDMAUDIOSTREAMCFG pCfg)
    228229{
     
    333334    return err;
    334335}
     336#endif
    335337
    336338#if 0 /* unused */
     
    504506    AudioQueueRef           audioQueue;
    505507    /** The audio buffers which are used with the above audio queue. */
    506     AudioQueueBufferRef     audioBuffer[2];
     508    AudioQueueBufferRef     audioBuffer[3];
     509    AudioStreamBasicDescription asbdAcq;
    507510#endif
    508511    /** The audio unit for this stream. */
     
    521524static int coreAudioStreamUninit(PCOREAUDIOSTREAM pCAStream);
    522525
     526#ifndef VBOX_WITH_AUDIO_CA_QUEUES
    523527static int coreAudioStreamInitIn(PCOREAUDIOSTREAM pCAStream, PPDMAUDIOSTREAMCFG pCfgReq, PPDMAUDIOSTREAMCFG pCfgAcq);
    524528static int coreAudioStreamInitOut(PCOREAUDIOSTREAM pCAStream, PPDMAUDIOSTREAMCFG pCfgReq, PPDMAUDIOSTREAMCFG pCfgAcq);
     529#endif
    525530
    526531static int coreAudioStreamControl(PDRVHOSTCOREAUDIO pThis, PCOREAUDIOSTREAM pCAStream, PDMAUDIOSTREAMCMD enmStreamCmd);
     
    531536
    532537static OSStatus coreAudioDevPropChgCb(AudioObjectID propertyID, UInt32 nAddresses, const AudioObjectPropertyAddress properties[], void *pvUser);
     538
     539#ifndef VBOX_WITH_AUDIO_CA_QUEUES
    533540static OSStatus coreAudioPlaybackCb(void *pvUser, AudioUnitRenderActionFlags *pActionFlags, const AudioTimeStamp *pAudioTS, UInt32 uBusID, UInt32 cFrames, AudioBufferList* pBufData);
    534 
     541#else
     542static void coreAudioInputQueueCb(void *pvUser, AudioQueueRef audioQueue, AudioQueueBufferRef audioBuffer, const AudioTimeStamp *pAudioTS, UInt32 cPacketDesc, const AudioStreamPacketDescription *paPacketDesc);
     543static void coreAudioOutputQueueCb(void *pvUser, AudioQueueRef audioQueue, AudioQueueBufferRef audioBuffer);
     544#endif
    535545
    536546#ifndef VBOX_WITH_AUDIO_CA_QUEUES
     
    12551265                                   PCOREAUDIOSTREAM pCAStream, PPDMAUDIODEVICE pDev, PPDMAUDIOSTREAMCFG pCfg)
    12561266{
     1267    LogFunc(("pCAStream=%p\n", pCAStream));
     1268
    12571269    int rc = coreAudioStreamUninit(pCAStream);
    12581270    if (RT_SUCCESS(rc))
     
    17901802    AssertPtrReturn(pDev,      VERR_INVALID_POINTER);
    17911803
    1792 #ifndef VBOX_WITH_AUDIO_CA_QUEUES
    17931804    Assert(pCAStream->Unit.pDevice == NULL); /* Make sure no device is assigned yet. */
    1794 #endif
    17951805    AssertPtr(pDev->pvData);
    17961806    Assert(pDev->cbData == sizeof(COREAUDIODEVICEDATA));
     
    18011811#endif
    18021812
    1803 #ifndef VBOX_WITH_AUDIO_CA_QUEUES
    18041813    pCAStream->Unit.pDevice = pDev;
    1805 #endif
    18061814    pCAStream->pDrv = pThis;
    18071815
     
    18161824static DECLCALLBACK(int) coreAudioQueueThread(RTTHREAD hThreadSelf, void *pvUser)
    18171825{
     1826    RT_NOREF(hThreadSelf);
     1827
    18181828    PCOREAUDIOSTREAM pCAStream = (PCOREAUDIOSTREAM)pvUser;
    18191829    AssertPtr(pCAStream);
    18201830
    18211831    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     else
    1837     {
    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     }
    19701832
    19711833    /*
     
    19731835     */
    19741836    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 */,
    19771839                                 CFRunLoopGetCurrent(), kCFRunLoopDefaultMode, 0, &pCAStream->audioQueue);
    19781840    else
    1979         err = AudioQueueNewOutput(&reqFmt, coreAudioOutputQueueCb, pCAStream /* pvData */,
     1841        err = AudioQueueNewOutput(&pCAStream->asbdAcq, coreAudioOutputQueueCb, pCAStream /* pvData */,
    19801842                                  CFRunLoopGetCurrent(), kCFRunLoopDefaultMode, 0, &pCAStream->audioQueue);
    19811843
     
    19861848     * Assign device to queue.
    19871849     */
    1988     AssertPtr(pCAStream->Unit.pDevice);
    19891850    PCOREAUDIODEVICEDATA pData = (PCOREAUDIODEVICEDATA)pCAStream->Unit.pDevice->pvData;
    19901851    AssertPtr(pData);
     
    20161877    }
    20171878
     1879    if (err != noErr)
     1880        return VERR_GENERAL_FAILURE; /** @todo Fudge! */
     1881
    20181882    /*
    20191883     * Start the queue.
    20201884     */
    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
     1917static 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
     1975static 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
     2041static 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;
    20252069
    20262070    /*
    20272071     * Start the thread.
    20282072     */
    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));
    20402080    return rc;
    20412081}
     
    20452085    LogFunc(("pCAStream=%p\n", pCAStream));
    20462086
    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"));
    20682113    return VINF_SUCCESS;
    20692114}
     
    20712116static int coreAudioStreamUninit(PCOREAUDIOSTREAM pCAStream)
    20722117{
    2073    int rc = coreAudioStreamUninitQueue(pCAStream);
    2074    return rc;
     2118    LogFunc(("pCAStream=%p\n", pCAStream));
     2119
     2120    int rc = coreAudioStreamUninitQueue(pCAStream);
     2121    return rc;
    20752122}
    20762123#else /* !VBOX_WITH_AUDIO_CA_QUEUES */
     
    20982145    do
    20992146    {
    2100         ASMAtomicXchgU32(&pCAStream->enmStatus, COREAUDIOSTATUS_IN_INIT);
    2101 
    21022147        /* Get the default frames buffer size, so that we can setup our internal buffers. */
    21032148        UInt32 cFrames;
     
    24412486        pCfgAcq->cSampleBufferSize = cSamples;
    24422487    }
    2443     else
    2444     {
    2445         int rc2 = coreAudioStreamUninit(pCAStream);
    2446         AssertRC(rc2);
    2447 
    2448         ASMAtomicXchgU32(&pCAStream->enmStatus, COREAUDIOSTATUS_UNINIT);
    2449     }
    24502488
    24512489    LogFunc(("cSamples=%RU32, rc=%Rrc\n", cSamples, rc));
     
    24752513    do
    24762514    {
    2477         ASMAtomicXchgU32(&pCAStream->enmStatus, COREAUDIOSTATUS_IN_INIT);
    2478 
    24792515        /* Get the default frames buffer size, so that we can setup our internal buffers. */
    24802516        UInt32 cFrames;
     
    26792715
    26802716        pCfgAcq->cSampleBufferSize = cSamples;
    2681     }
    2682     else
    2683     {
    2684         int rc2 = coreAudioStreamUninit(pCAStream);
    2685         AssertRC(rc2);
    2686 
    2687         ASMAtomicXchgU32(&pCAStream->enmStatus, COREAUDIOSTATUS_UNINIT);
    26882717    }
    26892718
     
    32193248    uint32_t cbReadTotal = 0;
    32203249
     3250    int rc = VINF_SUCCESS;
     3251
     3252#ifdef VBOX_WITH_AUDIO_CA_QUEUES
     3253    rc = RTCritSectEnter(&pCAStream->CritSect);
     3254    AssertRC(rc);
     3255#endif
     3256
    32213257    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));
    32253259
    32263260    while (cbToRead)
     
    32583292    }
    32593293
     3294#ifdef VBOX_WITH_AUDIO_CA_QUEUES
     3295    int rc2 = RTCritSectLeave(&pCAStream->CritSect);
     3296    AssertRC(rc2);
     3297#endif
     3298
    32603299    if (RT_SUCCESS(rc))
    32613300    {
     
    32933332    int rc = VINF_SUCCESS;
    32943333
    3295     OSStatus err;
    32963334    switch (enmStreamCmd)
    32973335    {
     
    33003338        {
    33013339#ifdef VBOX_WITH_AUDIO_CA_QUEUES
     3340            LogFunc(("Queue enable/resume\n"));
    33023341            ASMAtomicXchgBool(&pCAStream->fRunning, true);
    33033342#else
     
    33053344            if (!coreAudioUnitIsRunning(pCAStream))
    33063345            {
    3307                 err = AudioUnitReset(pCAStream->Unit.audioUnit, kAudioUnitScope_Input, 0);
     3346                OSStatus err = AudioUnitReset(pCAStream->Unit.audioUnit, kAudioUnitScope_Input, 0);
    33083347                if (err != noErr)
    33093348                {
     
    33293368        {
    33303369#ifdef VBOX_WITH_AUDIO_CA_QUEUES
     3370            LogFunc(("Queue disable/pause\n"));
    33313371            ASMAtomicXchgBool(&pCAStream->fRunning, false);
    33323372#else
     
    33343374            if (coreAudioUnitIsRunning(pCAStream))
    33353375            {
    3336                 err = AudioOutputUnitStop(pCAStream->Unit.audioUnit);
     3376                OSStatus err = AudioOutputUnitStop(pCAStream->Unit.audioUnit);
    33373377                if (err != noErr)
    33383378                {
     
    34923532        return rc;
    34933533
     3534    pCAStream->hThread   = NIL_RTTHREAD;
    34943535    pCAStream->fRunning  = false;
    34953536    pCAStream->fShutdown = false;
     
    35063547    if (pDev) /* (Default) device available? */
    35073548    {
     3549        /* Sanity. */
     3550        AssertPtr(pDev->pvData);
     3551        Assert(pDev->cbData);
     3552
    35083553        /* Init the Core Audio stream. */
    35093554        rc = coreAudioStreamInit(pCAStream, pThis, pDev);
    35103555        if (RT_SUCCESS(rc))
    35113556        {
    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
    35163567            if (RT_SUCCESS(rc))
    35173568            {
    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);
    35313579            }
    35323580        }
     
    35613609          ))
    35623610    {
     3611        AssertFailed();
    35633612        return VINF_SUCCESS;
    35643613    }
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