Changeset 65567 in vbox for trunk/src/VBox/Devices
- Timestamp:
- Feb 1, 2017 2:37:13 PM (8 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Devices/Audio/DrvHostCoreAudio.cpp
r65565 r65567 203 203 } 204 204 205 static int coreAudioStreamCfgToASBD(PPDMAUDIOSTREAMCFG pCfg, AudioStreamBasicDescription *pASBD)206 {207 AssertPtrReturn(pCfg, VERR_INVALID_PARAMETER);208 AssertPtrReturn(pASBD, VERR_INVALID_PARAMETER);209 210 PDMAUDIOPCMPROPS Props;211 int rc = DrvAudioHlpStreamCfgToProps(pCfg, &Props);212 if (RT_SUCCESS(rc))213 coreAudioPCMPropsToASBD(&Props, pASBD);214 215 return rc;216 }217 218 205 #ifndef VBOX_WITH_AUDIO_CALLBACKS 219 206 static int coreAudioASBDToStreamCfg(AudioStreamBasicDescription *pASBD, PPDMAUDIOSTREAMCFG pCfg) … … 408 395 /** Pointer to driver instance this stream is bound to. */ 409 396 PDRVHOSTCOREAUDIO pDrv; 397 /** The PCM properties of this stream. */ 398 PDMAUDIOPCMPROPS Props; 410 399 /** The stream's direction. */ 411 400 PDMAUDIODIR enmDir; … … 1624 1613 1625 1614 /* Create the recording device's out format based on our required audio settings. */ 1626 int rc = coreAudioStreamCfgToASBD(pCfgReq, &pCAStream->asbdStream);1615 int rc = DrvAudioHlpStreamCfgToProps(pCfgReq, &pCAStream->Props); 1627 1616 if (RT_FAILURE(rc)) 1628 1617 { 1629 LogRel(("CoreAudio: Failed to convert requested %s format to native format (%Rrc)\n", 1630 fIn ? "input" : "output", rc)); 1618 LogRel(("CoreAudio: Failed to convert requested %s format to native format (%Rrc)\n", fIn ? "input" : "output", rc)); 1631 1619 return rc; 1632 1620 } 1621 1622 coreAudioPCMPropsToASBD(&pCAStream->Props, &pCAStream->asbdStream); 1633 1623 1634 1624 coreAudioPrintASBD( fIn … … 1935 1925 void *pvBuf, uint32_t cbBuf, uint32_t *pcbRead) 1936 1926 { 1937 RT_NOREF(pvBuf, cbBuf); /** @todo r=bird: this looks totally weird at first glance! */1938 1939 1927 AssertPtrReturn(pInterface, VERR_INVALID_POINTER); 1940 1928 AssertPtrReturn(pStream, VERR_INVALID_POINTER); … … 1970 1958 1971 1959 int rc = VINF_SUCCESS; 1972 uint32_t csWrittenTotal = 0; 1960 1961 uint32_t cbReadTotal = 0; 1973 1962 1974 1963 rc = RTCritSectEnter(&pCAStream->CritSect); … … 1977 1966 do 1978 1967 { 1979 size_t cbMixBuf = AudioMixBufSizeBytes(&pStream->MixBuf); 1980 size_t cbToWrite = RT_MIN(cbMixBuf, RTCircBufUsed(pCAStream->pCircBuf)); 1981 1982 uint32_t csWritten, cbWritten; 1968 size_t cbToWrite = RT_MIN(cbBuf, RTCircBufUsed(pCAStream->pCircBuf)); 1983 1969 1984 1970 uint8_t *pvChunk; 1985 1971 size_t cbChunk; 1986 1972 1987 Log3Func(("cb MixBuf=%zu, cbToWrite=%zu/%zu\n", cbMixBuf, cbToWrite, RTCircBufSize(pCAStream->pCircBuf)));1973 Log3Func(("cbToWrite=%zu/%zu\n", cbToWrite, RTCircBufSize(pCAStream->pCircBuf))); 1988 1974 1989 1975 while (cbToWrite) … … 2005 1991 AssertFailed(); 2006 1992 #endif 2007 rc = AudioMixBufWriteCirc(&pStream->MixBuf, pvChunk, cbChunk, &csWritten); 2008 if (rc == VERR_BUFFER_OVERFLOW) 2009 { 2010 LogRel2(("Core Audio: Capturing host buffer full\n")); 2011 rc = VINF_SUCCESS; 2012 } 1993 memcpy((uint8_t *)pvBuf + cbReadTotal, pvChunk, cbChunk); 2013 1994 } 2014 1995 … … 2019 2000 break; 2020 2001 2021 cbWritten = AUDIOMIXBUF_S2B(&pStream->MixBuf, csWritten); 2022 2023 Assert(cbToWrite >= cbWritten); 2024 cbToWrite -= cbWritten; 2025 2026 csWrittenTotal += csWritten; 2002 Assert(cbToWrite >= cbChunk); 2003 cbToWrite -= cbChunk; 2004 2005 cbReadTotal += cbChunk; 2027 2006 } 2028 2007 } … … 2032 2011 AssertRC(rc2); 2033 2012 2034 #ifdef LOG_ENABLED2035 uint32_t cbWrittenTotal = AUDIOMIXBUF_S2B(&pStream->MixBuf, csWrittenTotal);2036 Log3Func(("csWrittenTotal=%RU32 (%RU32 bytes), rc=%Rrc\n", csWrittenTotal, cbWrittenTotal, rc));2037 #endif2038 2039 2013 if (RT_SUCCESS(rc)) 2040 2014 { 2041 uint32_t csMixed = 0;2042 2043 if (csWrittenTotal)2044 rc = AudioMixBufMixToParent(&pStream->MixBuf, csWrittenTotal, &csMixed);2045 2046 Log3Func(("csMixed=%RU32\n", csMixed));2047 2048 2015 if (pcbRead) 2049 *pcbRead = csMixed; 2050 } 2051 2052 if (RT_FAILURE(rc)) 2053 LogFunc(("Failed with rc=%Rrc\n", rc)); 2016 *pcbRead = cbReadTotal; 2017 } 2054 2018 2055 2019 return rc; … … 2063 2027 uint32_t *pcbWritten) 2064 2028 { 2065 RT_NOREF(pvBuf, cbBuf);2066 2067 2029 PDRVHOSTCOREAUDIO pThis = PDMIHOSTAUDIO_2_DRVHOSTCOREAUDIO(pInterface); 2068 2030 PCOREAUDIOSTREAM pCAStream = (PCOREAUDIOSTREAM)pStream; … … 2093 2055 } 2094 2056 2095 uint32_t cLive = AudioMixBufLive(&pStream->MixBuf); 2096 if (!cLive) /* Not live samples to play? Bail out. */ 2097 { 2098 if (pcbWritten) 2099 *pcbWritten = 0; 2100 return VINF_SUCCESS; 2101 } 2102 2103 size_t cbLive = AUDIOMIXBUF_S2B(&pStream->MixBuf, cLive); 2104 2105 uint32_t cbReadTotal = 0; 2057 uint32_t cbWrittenTotal = 0; 2106 2058 2107 2059 int rc = VINF_SUCCESS; … … 2110 2062 AssertRC(rc); 2111 2063 2112 size_t cbTo Read = RT_MIN(cbLive, RTCircBufFree(pCAStream->pCircBuf));2113 Log3Func(("cb Live=%zu, cbToRead=%zu\n", cbLive, cbToRead));2064 size_t cbToWrite = RT_MIN(cbBuf, RTCircBufFree(pCAStream->pCircBuf)); 2065 Log3Func(("cbToWrite=%zu\n", cbToWrite)); 2114 2066 2115 2067 uint8_t *pvChunk; 2116 2068 size_t cbChunk; 2117 2069 2118 while (cbToRead) 2119 { 2120 uint32_t cRead, cbRead; 2121 2070 while (cbToWrite) 2071 { 2122 2072 /* Try to acquire the necessary space from the ring buffer. */ 2123 RTCircBufAcquireWriteBlock(pCAStream->pCircBuf, cbTo Read, (void **)&pvChunk, &cbChunk);2073 RTCircBufAcquireWriteBlock(pCAStream->pCircBuf, cbToWrite, (void **)&pvChunk, &cbChunk); 2124 2074 if (!cbChunk) 2125 2075 { … … 2128 2078 } 2129 2079 2130 Assert(cbChunk <= cbToRead); 2131 2132 rc = AudioMixBufReadCirc(&pStream->MixBuf, pvChunk, cbChunk, &cRead); 2133 2134 cbRead = AUDIOMIXBUF_S2B(&pStream->MixBuf, cRead); 2080 Assert(cbChunk <= cbToWrite); 2081 Assert(cbWrittenTotal + cbChunk <= cbBuf); 2082 2083 memcpy((uint8_t *)pvBuf + cbWrittenTotal, pvChunk, cbChunk); 2135 2084 2136 2085 /* Release the ring buffer, so the read thread could start reading this data. */ … … 2140 2089 break; 2141 2090 2142 Assert(cbToRead >= cbRead); 2143 cbToRead -= cbRead; 2144 cbReadTotal += cbRead; 2091 Assert(cbToWrite >= cbChunk); 2092 cbToWrite -= cbChunk; 2093 2094 cbWrittenTotal += cbChunk; 2145 2095 } 2146 2096 … … 2163 2113 if (RT_SUCCESS(rc)) 2164 2114 { 2165 uint32_t cReadTotal = AUDIOMIXBUF_B2S(&pStream->MixBuf, cbReadTotal);2166 if (cReadTotal)2167 AudioMixBufFinish(&pStream->MixBuf, cReadTotal);2168 2169 Log3Func(("cReadTotal=%RU32 (%RU32 bytes)\n", cReadTotal, cbReadTotal));2170 2171 2115 if (pcbWritten) 2172 *pcbWritten = c ReadTotal;2116 *pcbWritten = cbWrittenTotal; 2173 2117 } 2174 2118
Note:
See TracChangeset
for help on using the changeset viewer.