Changeset 59420 in vbox for trunk/src/VBox/Devices
- Timestamp:
- Jan 20, 2016 2:53:24 PM (9 years ago)
- Location:
- trunk/src/VBox/Devices/Audio
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Devices/Audio/DrvAudio.cpp
r59348 r59420 3 3 * Intermediate audio driver header. 4 4 * 5 * @remarks Intermediate audio driver having audio device as one of the sink and6 * host backend as other.5 * @remarks Intermediate audio driver for connecting the audio device emulation 6 * with the host backend. 7 7 */ 8 8 … … 388 388 AssertPtrReturn(pHstStrmIn, VERR_INVALID_POINTER); 389 389 390 int rc; 390 int rc = RTCritSectEnter(&pHstStrmIn->CritSect); 391 if (RT_FAILURE(rc)) 392 return rc; 391 393 392 394 switch (enmStreamCmd) … … 475 477 } 476 478 479 int rc2 = RTCritSectLeave(&pHstStrmIn->CritSect); 480 if (RT_SUCCESS(rc)) 481 rc = rc2; 482 477 483 return rc; 478 484 } … … 483 489 AssertPtrReturn(pHstStrmOut, VERR_INVALID_POINTER); 484 490 485 int rc; 491 int rc = RTCritSectEnter(&pHstStrmOut->CritSect); 492 if (RT_FAILURE(rc)) 493 return rc; 486 494 487 495 switch (enmStreamCmd) … … 575 583 } 576 584 585 int rc2 = RTCritSectLeave(&pHstStrmOut->CritSect); 586 if (RT_SUCCESS(rc)) 587 rc = rc2; 588 577 589 return rc; 578 590 } … … 595 607 /* Remove from driver instance list. */ 596 608 RTListNodeRemove(&pHstStrmOut->Node); 609 610 if (RTCritSectIsInitialized(&pHstStrmOut->CritSect)) 611 { 612 int rc2 = RTCritSectDelete(&pHstStrmOut->CritSect); 613 AssertRC(rc2); 614 } 597 615 598 616 RTMemFree(pHstStrmOut); … … 777 795 778 796 rc = AudioMixBufInit(&pHstStrmOut->MixBuf, pszTemp, &pHstStrmOut->Props, cSamples); 797 if (RT_SUCCESS(rc)) 798 rc = RTCritSectInit(&pHstStrmOut->CritSect); 799 779 800 if (RT_SUCCESS(rc)) 780 801 { … … 1030 1051 1031 1052 rc = AudioMixBufInit(&pHstStrmIn->MixBuf, pszTemp, &pHstStrmIn->Props, cSamples); 1053 if (RT_SUCCESS(rc)) 1054 rc = RTCritSectInit(&pHstStrmIn->CritSect); 1055 1032 1056 if (RT_SUCCESS(rc)) 1033 1057 { … … 1079 1103 1080 1104 AssertPtrReturn(pGstStrmOut, VERR_INVALID_POINTER); 1081 AssertPtrReturn(pvBuf, VERR_INVALID_POINTER);1082 AssertReturn(cbBuf, VERR_INVALID_PARAMETER);1105 AssertPtrReturn(pvBuf, VERR_INVALID_POINTER); 1106 AssertReturn(cbBuf, VERR_INVALID_PARAMETER); 1083 1107 /* pcbWritten is optional. */ 1084 1108 1109 int rc = RTCritSectEnter(&pThis->CritSect); 1110 if (RT_FAILURE(rc)) 1111 return rc; 1112 1085 1113 if (!pThis->pHostDrvAudio->pfnIsEnabled(pThis->pHostDrvAudio, PDMAUDIODIR_OUT)) 1114 { 1115 rc = RTCritSectLeave(&pThis->CritSect); 1116 AssertRC(rc); 1117 1086 1118 return VERR_NOT_AVAILABLE; 1119 } 1087 1120 1088 1121 PPDMAUDIOHSTSTRMOUT pHstStrmOut = pGstStrmOut->pHstStrmOut; … … 1097 1130 if (pcbWritten) 1098 1131 *pcbWritten = 0; 1099 return VINF_SUCCESS; 1132 1133 return RTCritSectLeave(&pThis->CritSect); 1100 1134 } 1101 1135 … … 1105 1139 */ 1106 1140 uint32_t cWritten; 1107 intrc = AudioMixBufWriteAt(&pGstStrmOut->MixBuf, 0 /* Offset in samples */, pvBuf, cbBuf, &cWritten);1141 rc = AudioMixBufWriteAt(&pGstStrmOut->MixBuf, 0 /* Offset in samples */, pvBuf, cbBuf, &cWritten); 1108 1142 1109 1143 /* … … 1134 1168 pGstStrmOut->MixBuf.pszName, pHstStrmOut->MixBuf.pszName, pvBuf, cbBuf, cWritten, 1135 1169 AUDIOMIXBUF_S2B(&pGstStrmOut->MixBuf, cWritten), cMixed, rc)); 1170 1171 int rc2 = RTCritSectLeave(&pThis->CritSect); 1172 if (RT_SUCCESS(rc)) 1173 rc = rc2; 1174 1136 1175 return rc; 1137 1176 } … … 1187 1226 { 1188 1227 drvAudioHstInFreeRes(pHstStrmIn); 1228 1229 if (RTCritSectIsInitialized(&pHstStrmIn->CritSect)) 1230 { 1231 int rc2 = RTCritSectDelete(&pHstStrmIn->CritSect); 1232 AssertRC(rc2); 1233 } 1189 1234 1190 1235 /* Remove from driver instance list. */ … … 1245 1290 PDRVAUDIO pThis = PDMIAUDIOCONNECTOR_2_DRVAUDIO(pInterface); 1246 1291 1247 int rc = VINF_SUCCESS; 1248 uint32_t cSamplesLive = 0; 1292 int rc = RTCritSectEnter(&pThis->CritSect); 1293 if (RT_FAILURE(rc)) 1294 return rc; 1249 1295 1250 1296 /* 1251 1297 * Playback. 1252 1298 */ 1253 uint32_t cbFreeOut = UINT32_MAX; 1299 uint32_t cSamplesLive = 0; 1300 uint32_t cbFreeOut = UINT32_MAX; 1254 1301 1255 1302 PPDMAUDIOHSTSTRMOUT pHstStrmOut = NULL; … … 1348 1395 } 1349 1396 1397 int rc2 = RTCritSectLeave(&pThis->CritSect); 1398 if (RT_SUCCESS(rc)) 1399 rc = rc2; 1400 1350 1401 return rc; 1351 1402 } … … 1358 1409 PDRVAUDIO pThis = PDMIAUDIOCONNECTOR_2_DRVAUDIO(pInterface); 1359 1410 1360 int rc = VINF_SUCCESS; 1361 uint32_t cSamplesPlayedMax = 0; 1411 int rc = RTCritSectEnter(&pThis->CritSect); 1412 if (RT_FAILURE(rc)) 1413 return rc; 1362 1414 1363 1415 /* 1364 1416 * Process all enabled host output streams. 1365 1417 */ 1366 PPDMAUDIOHSTSTRMOUT pHstStrmOut = NULL; 1418 uint32_t cSamplesPlayedMax = 0; 1419 PPDMAUDIOHSTSTRMOUT pHstStrmOut = NULL; 1367 1420 while ((pHstStrmOut = drvAudioHstFindAnyEnabledOut(pThis, pHstStrmOut))) 1368 1421 { … … 1437 1490 } 1438 1491 1492 int rc2 = RTCritSectLeave(&pThis->CritSect); 1493 if (RT_SUCCESS(rc)) 1494 rc = rc2; 1495 1439 1496 return rc; 1440 1497 } … … 1484 1541 1485 1542 PDRVAUDIO pThis = PDMIAUDIOCONNECTOR_2_DRVAUDIO(pInterface); 1486 int rc = VINF_SUCCESS; 1543 1544 int rc = RTCritSectEnter(&pThis->CritSect); 1545 if (RT_FAILURE(rc)) 1546 return rc; 1487 1547 1488 1548 for (size_t i = 0; i < cCallbacks; i++) … … 1512 1572 1513 1573 /** @todo Undo allocations on error. */ 1574 1575 int rc2 = RTCritSectLeave(&pThis->CritSect); 1576 if (RT_SUCCESS(rc)) 1577 rc = rc2; 1514 1578 1515 1579 return rc; … … 1696 1760 #endif 1697 1761 1698 int rc = VINF_SUCCESS;1762 int rc = RTCritSectInit(&pThis->CritSect); 1699 1763 1700 1764 /* Get the configuration data from the selected backend (if available). */ 1701 1765 AssertPtr(pThis->pHostDrvAudio); 1702 if (RT_LIKELY(pThis->pHostDrvAudio->pfnGetConf)) 1766 if ( RT_SUCCESS(rc) 1767 && RT_LIKELY(pThis->pHostDrvAudio->pfnGetConf)) 1703 1768 rc = pThis->pHostDrvAudio->pfnGetConf(pThis->pHostDrvAudio, &pThis->BackendCfg); 1704 1769 … … 1735 1800 1736 1801 AssertPtrReturn(pGstStrmIn, VERR_INVALID_POINTER); 1737 AssertPtrReturn(pvBuf, VERR_INVALID_POINTER);1738 AssertReturn(cbBuf, VERR_INVALID_PARAMETER);1802 AssertPtrReturn(pvBuf, VERR_INVALID_POINTER); 1803 AssertReturn(cbBuf, VERR_INVALID_PARAMETER); 1739 1804 /* pcbWritten is optional. */ 1805 1806 int rc = RTCritSectEnter(&pThis->CritSect); 1807 if (RT_FAILURE(rc)) 1808 return rc; 1740 1809 1741 1810 if (!pThis->pHostDrvAudio->pfnIsEnabled(pThis->pHostDrvAudio, PDMAUDIODIR_IN)) … … 1743 1812 if (pcbRead) 1744 1813 *pcbRead = 0; 1745 return VINF_SUCCESS; 1814 1815 return RTCritSectLeave(&pThis->CritSect); 1746 1816 } 1747 1817 … … 1757 1827 */ 1758 1828 uint32_t cRead; 1759 int rc = AudioMixBufReadCirc(&pGstStrmIn->MixBuf, 1760 pvBuf, cbBuf, &cRead); 1829 rc = AudioMixBufReadCirc(&pGstStrmIn->MixBuf, pvBuf, cbBuf, &cRead); 1761 1830 if (RT_SUCCESS(rc)) 1762 1831 { … … 1769 1838 LogFlowFunc(("cRead=%RU32 (%RU32 bytes), rc=%Rrc\n", 1770 1839 cRead, AUDIOMIXBUF_S2B(&pGstStrmIn->MixBuf, cRead), rc)); 1840 1841 int rc2 = RTCritSectLeave(&pThis->CritSect); 1842 if (RT_SUCCESS(rc)) 1843 rc = rc2; 1844 1771 1845 return rc; 1772 1846 } … … 1887 1961 PPDMAUDIOGSTSTRMIN *ppGstStrmIn) 1888 1962 { 1889 AssertPtrReturn(pInterface, VERR_INVALID_POINTER);1963 AssertPtrReturn(pInterface, VERR_INVALID_POINTER); 1890 1964 AssertPtrReturn(ppGstStrmIn, VERR_INVALID_POINTER); 1891 AssertPtrReturn(pszName, VERR_INVALID_POINTER);1892 AssertPtrReturn(pCfg, VERR_INVALID_POINTER);1965 AssertPtrReturn(pszName, VERR_INVALID_POINTER); 1966 AssertPtrReturn(pCfg, VERR_INVALID_POINTER); 1893 1967 AssertPtrReturn(ppGstStrmIn, VERR_INVALID_POINTER); 1894 1968 1895 1969 PDRVAUDIO pThis = PDMIAUDIOCONNECTOR_2_DRVAUDIO(pInterface); 1896 1970 1971 int rc = RTCritSectEnter(&pThis->CritSect); 1972 if (RT_FAILURE(rc)) 1973 return rc; 1974 1897 1975 LogFlowFunc(("pszName=%s, pCfg=%p\n", pszName, pCfg)); 1898 1976 … … 1900 1978 { 1901 1979 LogFunc(("Input stream configuration is not valid, bailing out\n")); 1902 r eturnVERR_INVALID_PARAMETER;1980 rc = VERR_INVALID_PARAMETER; 1903 1981 } 1904 1982 1905 1983 PPDMAUDIOGSTSTRMIN pGstStrmIn = *ppGstStrmIn; 1906 if ( pGstStrmIn 1984 if ( RT_SUCCESS(rc) 1985 && pGstStrmIn 1907 1986 && drvAudioPCMPropsAreEqual(&pGstStrmIn->Props, pCfg)) 1908 1987 { 1909 1988 LogFunc(("[%s] Exists and matches required configuration, skipping creation\n", 1910 1989 pGstStrmIn->MixBuf.pszName)); 1911 return VWRN_ALREADY_EXISTS; 1990 rc = VWRN_ALREADY_EXISTS; 1991 } 1992 1993 if (rc != VINF_SUCCESS) /* Note: Can be VWRN_ALREADY_EXISTS, so don't use VINF_SUCCESS here. */ 1994 { 1995 int rc2 = RTCritSectLeave(&pThis->CritSect); 1996 AssertRC(rc2); 1997 1998 return rc; 1912 1999 } 1913 2000 … … 1919 2006 } 1920 2007 1921 int rc;1922 1923 2008 if (pGstStrmIn) 1924 2009 { … … 1932 2017 { 1933 2018 RTMemFree(pGstStrmIn); 2019 2020 int rc2 = RTCritSectLeave(&pThis->CritSect); 2021 AssertRC(rc2); 2022 1934 2023 return VERR_NO_MEMORY; 1935 2024 } … … 1945 2034 *ppGstStrmIn = pGstStrmIn; 1946 2035 2036 int rc2 = RTCritSectLeave(&pThis->CritSect); 2037 if (RT_SUCCESS(rc)) 2038 rc = rc2; 2039 1947 2040 LogFlowFuncLeaveRC(rc); 1948 2041 return rc; … … 1952 2045 PPDMAUDIOSTREAMCFG pCfg, PPDMAUDIOGSTSTRMOUT *ppGstStrmOut) 1953 2046 { 1954 AssertPtrReturn(pInterface, VERR_INVALID_POINTER);1955 AssertPtrReturn(pszName, VERR_INVALID_POINTER);1956 AssertPtrReturn(pCfg, VERR_INVALID_POINTER);2047 AssertPtrReturn(pInterface, VERR_INVALID_POINTER); 2048 AssertPtrReturn(pszName, VERR_INVALID_POINTER); 2049 AssertPtrReturn(pCfg, VERR_INVALID_POINTER); 1957 2050 AssertPtrReturn(ppGstStrmOut, VERR_INVALID_POINTER); 1958 2051 1959 2052 PDRVAUDIO pThis = PDMIAUDIOCONNECTOR_2_DRVAUDIO(pInterface); 1960 2053 2054 int rc = RTCritSectEnter(&pThis->CritSect); 2055 if (RT_FAILURE(rc)) 2056 return rc; 2057 1961 2058 LogFlowFunc(("pszName=%s, pCfg=%p\n", pszName, pCfg)); 1962 2059 … … 1964 2061 { 1965 2062 LogFunc(("Output stream configuration is not valid, bailing out\n")); 1966 r eturnVERR_INVALID_PARAMETER;2063 rc = VERR_INVALID_PARAMETER; 1967 2064 } 1968 2065 1969 2066 PPDMAUDIOGSTSTRMOUT pGstStrmOut = *ppGstStrmOut; 1970 if ( pGstStrmOut 2067 if ( RT_SUCCESS(rc) 2068 && pGstStrmOut 1971 2069 && drvAudioPCMPropsAreEqual(&pGstStrmOut->Props, pCfg)) 1972 2070 { 1973 2071 LogFunc(("[%s] Exists and matches required configuration, skipping creation\n", 1974 2072 pGstStrmOut->MixBuf.pszName)); 1975 return VWRN_ALREADY_EXISTS; 2073 2074 rc = VWRN_ALREADY_EXISTS; 2075 } 2076 2077 if (rc != VINF_SUCCESS) /* Note: Can be VWRN_ALREADY_EXISTS, so don't use VINF_SUCCESS here. */ 2078 { 2079 int rc2 = RTCritSectLeave(&pThis->CritSect); 2080 AssertRC(rc2); 2081 2082 return rc; 1976 2083 } 1977 2084 … … 2003 2110 } 2004 2111 2005 int rc;2006 2112 if (pGstStrmOut) 2007 2113 { … … 2040 2146 } 2041 2147 2148 int rc2 = RTCritSectLeave(&pThis->CritSect); 2149 if (RT_SUCCESS(rc)) 2150 rc = rc2; 2151 2042 2152 LogFlowFuncLeaveRC(rc); 2043 2153 return rc; … … 2046 2156 static DECLCALLBACK(bool) drvAudioIsActiveIn(PPDMIAUDIOCONNECTOR pInterface, PPDMAUDIOGSTSTRMIN pGstStrmIn) 2047 2157 { 2048 return pGstStrmIn ? pGstStrmIn->State.fActive : false; 2158 AssertPtrReturn(pInterface, false); 2159 /* pGstStrmIn is optional. */ 2160 2161 PDRVAUDIO pThis = PDMIAUDIOCONNECTOR_2_DRVAUDIO(pInterface); 2162 2163 int rc2 = RTCritSectEnter(&pThis->CritSect); 2164 AssertRC(rc2); 2165 2166 bool fRet = pGstStrmIn ? pGstStrmIn->State.fActive : false; 2167 2168 rc2 = RTCritSectLeave(&pThis->CritSect); 2169 AssertRC(rc2); 2170 2171 return fRet; 2049 2172 } 2050 2173 2051 2174 static DECLCALLBACK(bool) drvAudioIsActiveOut(PPDMIAUDIOCONNECTOR pInterface, PPDMAUDIOGSTSTRMOUT pGstStrmOut) 2052 2175 { 2053 return pGstStrmOut ? pGstStrmOut->State.fActive : false; 2176 AssertPtrReturn(pInterface, false); 2177 /* pGstStrmOut is optional. */ 2178 2179 PDRVAUDIO pThis = PDMIAUDIOCONNECTOR_2_DRVAUDIO(pInterface); 2180 2181 int rc2 = RTCritSectEnter(&pThis->CritSect); 2182 AssertRC(rc2); 2183 2184 bool fRet = pGstStrmOut ? pGstStrmOut->State.fActive : false; 2185 2186 rc2 = RTCritSectLeave(&pThis->CritSect); 2187 AssertRC(rc2); 2188 2189 return fRet; 2054 2190 } 2055 2191 2056 2192 static DECLCALLBACK(void) drvAudioDestroyIn(PPDMIAUDIOCONNECTOR pInterface, PPDMAUDIOGSTSTRMIN pGstStrmIn) 2057 2193 { 2194 AssertPtrReturnVoid(pInterface); 2195 /* pGstStrmIn is optional. */ 2196 2058 2197 PDRVAUDIO pThis = PDMIAUDIOCONNECTOR_2_DRVAUDIO(pInterface); 2198 2199 int rc2 = RTCritSectEnter(&pThis->CritSect); 2200 AssertRC(rc2); 2201 2059 2202 if (pGstStrmIn) 2060 2203 drvAudioDestroyGstIn(pThis, pGstStrmIn); 2204 2205 rc2 = RTCritSectLeave(&pThis->CritSect); 2206 AssertRC(rc2); 2061 2207 } 2062 2208 2063 2209 static DECLCALLBACK(void) drvAudioDestroyOut(PPDMIAUDIOCONNECTOR pInterface, PPDMAUDIOGSTSTRMOUT pGstStrmOut) 2064 2210 { 2211 AssertPtrReturnVoid(pInterface); 2212 /* pGstStrmOut is optional. */ 2213 2065 2214 PDRVAUDIO pThis = PDMIAUDIOCONNECTOR_2_DRVAUDIO(pInterface); 2215 2216 int rc2 = RTCritSectEnter(&pThis->CritSect); 2217 AssertRC(rc2); 2218 2066 2219 if (pGstStrmOut) 2067 2220 drvAudioDestroyGstOut(pThis, pGstStrmOut); 2221 2222 rc2 = RTCritSectLeave(&pThis->CritSect); 2223 AssertRC(rc2); 2068 2224 } 2069 2225 … … 2206 2362 2207 2363 /** 2364 * Destructs an audio driver instance. 2365 * 2366 * @copydoc FNPDMDRVDESTRUCT 2367 */ 2368 static DECLCALLBACK(void) drvAudioDestruct(PPDMDRVINS pDrvIns) 2369 { 2370 LogFlowFuncEnter(); 2371 2372 PDMDRV_CHECK_VERSIONS_RETURN_VOID(pDrvIns); 2373 PDRVAUDIO pThis = PDMINS_2_DATA(pDrvIns, PDRVAUDIO); 2374 2375 if (RTCritSectIsInitialized(&pThis->CritSect)) 2376 { 2377 int rc2 = RTCritSectDelete(&pThis->CritSect); 2378 AssertRC(rc2); 2379 } 2380 } 2381 2382 /** 2208 2383 * Suspend notification. 2209 2384 * … … 2242 2417 /* fFlags */ 2243 2418 PDM_DRVREG_FLAGS_HOST_BITS_DEFAULT, 2244 /* fClass .*/2419 /* fClass */ 2245 2420 PDM_DRVREG_CLASS_AUDIO, 2246 2421 /* cMaxInstances */ … … 2251 2426 drvAudioConstruct, 2252 2427 /* pfnDestruct */ 2253 NULL,2428 drvAudioDestruct, 2254 2429 /* pfnRelocate */ 2255 2430 NULL, -
trunk/src/VBox/Devices/Audio/DrvAudio.h
r58744 r59420 5 5 6 6 /* 7 * Copyright (C) 2006-201 5Oracle Corporation7 * Copyright (C) 2006-2016 Oracle Corporation 8 8 * 9 9 * This file is part of VirtualBox Open Source Edition (OSE), as … … 47 47 48 48 #include <iprt/circbuf.h> 49 #include <iprt/critsect.h> 49 50 50 51 #include <VBox/vmm/pdmdev.h> … … 79 80 /** Input/output processing thread. */ 80 81 RTTHREAD hThread; 81 /** Event for input/ouput processing. */82 RT SEMEVENT hEvent;82 /** Critical section for serializing access. */ 83 RTCRITSECT CritSect; 83 84 /** Shutdown indicator. */ 84 85 bool fTerminate; … … 89 90 /** Pointer to audio driver below us. */ 90 91 PPDMIHOSTAUDIO pHostDrvAudio; 92 /** List of host input streams. */ 91 93 RTLISTANCHOR lstHstStrmIn; 94 /** List of host output streams. */ 92 95 RTLISTANCHOR lstHstStrmOut; 93 96 /** Max. number of free input streams. */ … … 95 98 /** Max. number of free output streams. */ 96 99 uint8_t cFreeOutputStreams; 97 /** Audio configuration settings retrieved 98 * from the backend. */ 100 /** Audio configuration settings retrieved from the backend. */ 99 101 PDMAUDIOBACKENDCFG BackendCfg; 100 102 #ifdef VBOX_WITH_AUDIO_CALLBACKS
Note:
See TracChangeset
for help on using the changeset viewer.