- Timestamp:
- Mar 12, 2025 7:34:43 PM (2 months ago)
- svn:sync-xref-src-repo-rev:
- 167928
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Devices/Audio/DrvHostAudioWasApi.cpp
r108508 r108536 1153 1153 * If lookup fails, a new entry will be created. 1154 1154 * 1155 * @note Called holding the cache's lock , returning without holding it!1155 * @note Called holding the cache's lock (if \a fUseCache is @true), returning without holding it! 1156 1156 */ 1157 1157 static int drvHostAudioWasCacheLookupOrCreateConfig(PDRVHOSTAUDIOWAS pThis, PDRVHOSTAUDIOWASCACHEDEV pDevEntry, 1158 PCPDMAUDIOSTREAMCFG pCfgReq, bool f OnWorker,1158 PCPDMAUDIOSTREAMCFG pCfgReq, bool fUseCache, bool fOnWorker, 1159 1159 PDRVHOSTAUDIOWASCACHEDEVCFG *ppDevCfg) 1160 1160 { … … 1164 1164 * Check if we've got a matching config. 1165 1165 */ 1166 if ( pThis->fCacheEnabled)1166 if (fUseCache) 1167 1167 { 1168 1168 pDevCfg = drvHostAudioWasCacheLookupLocked(pDevEntry, &pCfgReq->Props); … … 1193 1193 pDevCfg->nsLastUsed = pDevCfg->nsCreated; 1194 1194 1195 if ( pThis->fCacheEnabled)1195 if (fUseCache) 1196 1196 { 1197 1197 uint32_t cCacheEntries; … … 1257 1257 *ppDevCfg = NULL; 1258 1258 1259 LogRel2(("WasAPI: Looking up or creating cache entry (caching is set to %s, iface %p)\n", 1260 pThis->fCacheEnabled ? "enabled" : "disabled", pIDevice)); 1261 1259 1262 /* 1260 1263 * Get the device ID so we can perform the lookup. … … 1267 1270 bool fLookupOrCreateInCache = pThis->fCacheEnabled; /* Whether to lookup and/or create the device in our cache. */ 1268 1271 1269 /* First, try retrieving the current device state here as a yet another meassure for1272 /* First, try retrieving the current device state of the passed device here as a yet another meassure for 1270 1273 * AUDCLNT_E_DEVICE_INVALIDATED errors. We try not to cache malfunctioning devices here. See @bugref{10844} */ 1271 1274 DWORD dwState; … … 1286 1289 } 1287 1290 1288 PDRVHOSTAUDIOWASCACHEDEV pDevEntry ;1289 size_t const cwcDevId = RTUtf16Len(pwszDevId);1291 PDRVHOSTAUDIOWASCACHEDEV pDevEntry = NULL; 1292 size_t const cwcDevId = RTUtf16Len(pwszDevId); 1290 1293 1291 1294 if (fLookupOrCreateInCache) … … 1293 1296 LogRel2(("WasAPI: Checking for cached device '%ls' ...\n", pwszDevId)); 1294 1297 1298 #define DEVICE_STALE_OR_INVALID_BREAK(a_LogRel2What) \ 1299 { \ 1300 LogRel2(a_LogRel2What); \ 1301 LogRel(("WasAPI: Stale or invalid audio interface '%ls' detected!\n", pDevEntry->wszDevId)); \ 1302 rc = VERR_AUDIO_STREAM_NOT_READY; \ 1303 break; \ 1304 } 1295 1305 /* 1296 1306 * The cache has two levels, so first the device entry. … … 1305 1315 { 1306 1316 /* 1307 * Cache hit -- here we now need to also check if the device interface we want to look up 1317 * Cache hit. 1318 * First we need to check if the cached device interface is in a working (active) shape. 1319 */ 1320 AssertPtrBreakStmt(pDevEntry->pIDevice, rc = VERR_AUDIO_STREAM_NOT_READY); /* Paranoia. */ 1321 hrc = pDevEntry->pIDevice->GetState(&dwState); 1322 if (SUCCEEDED(hrc)) 1323 { 1324 if (dwState != DEVICE_STATE_ACTIVE) 1325 DEVICE_STALE_OR_INVALID_BREAK(("WasAPI: Cache hit for device '%ls': Is in non-active state (state is %s)\n", 1326 pDevEntry->wszDevId, drvHostAudioWasMMDeviceStateToString(dwState))); 1327 } 1328 else 1329 DEVICE_STALE_OR_INVALID_BREAK(("WasAPI: Cache hit for device '%ls': Unable to retrieve state (hr=%#x)\n", 1330 pDevEntry->wszDevId, hrc)); 1331 /* 1332 * Next we now need to also check if the device interface we want to look up 1308 1333 * actually matches the one we have in the cache entry. 1309 1334 * … … 1314 1339 */ 1315 1340 if (pDevEntry->pIDevice != pIDevice) 1316 LogRel2(("WasAPI: Cache hit for device '%ls': Stale interface(new: %p, old: %p)\n",1317 pDevEntry->wszDevId, pIDevice, pDevEntry->pIDevice));1341 DEVICE_STALE_OR_INVALID_BREAK(("WasAPI: Cache hit for device '%ls': Stale interface detected (new: %p, old: %p)\n", 1342 pDevEntry->wszDevId, pIDevice, pDevEntry->pIDevice)); 1318 1343 1319 1344 LogRel2(("WasAPI: Cache hit for device '%ls' (iface %p)\n", pwszDevId, pIDevice)); … … 1322 1347 pwszDevId = NULL; 1323 1348 1324 return drvHostAudioWasCacheLookupOrCreateConfig(pThis, pDevEntry, pCfgReq, fOnWorker, ppDevCfg); 1349 return drvHostAudioWasCacheLookupOrCreateConfig(pThis, pDevEntry, pCfgReq, 1350 true /* fUseCache */, fOnWorker, ppDevCfg); 1325 1351 } 1326 1352 } 1327 1353 RTCritSectLeave(&pThis->CritSectCache); 1328 1354 1329 LogRel2(("WasAPI: Cache miss for device '%ls' (iface %p)\n", pwszDevId, pIDevice)); 1330 1331 #undef LOG_STALE_DEVICE_BREAK 1332 #undef LOG_STALE_DEVICE 1333 1334 } 1335 else 1336 LogRel2(("WasAPI: Not caching device '%ls' (iface %p)\n", pwszDevId, pIDevice)); 1355 if (!pDevEntry) 1356 LogRel2(("WasAPI: Cache miss for device '%ls' (iface %p)\n", pwszDevId, pIDevice)); 1357 1358 #undef DEVICE_STALE_OR_INVALID_BREAK 1359 } 1337 1360 1338 1361 /* 1339 * Device not in the cache, add it. 1362 * If we got a stale or somehow other invalid cache entry, remove it first. 1363 */ 1364 if ( pThis->fCacheEnabled 1365 && pDevEntry /* Cache hit? */ 1366 && rc == VERR_AUDIO_STREAM_NOT_READY) 1367 { 1368 LogRel2(("WasAPI: Removing stale device '%ls' from cache (iface %p)\n", pDevEntry->wszDevId, pDevEntry->pIDevice)); 1369 1370 RTCritSectEnter(&pThis->CritSectCache); 1371 RTListNodeRemove(&pDevEntry->ListEntry); 1372 RTCritSectLeave(&pThis->CritSectCache); 1373 1374 drvHostAudioWasCacheDestroyDevEntry(pThis, pDevEntry); 1375 pDevEntry = NULL; 1376 1377 rc = VINF_SUCCESS; 1378 } 1379 1380 /* 1381 * Device not in the cache (anymore), (re-)add it. 1340 1382 */ 1341 1383 pDevEntry = (PDRVHOSTAUDIOWASCACHEDEV)RTMemAllocZVar(RT_UOFFSETOF_DYN(DRVHOSTAUDIOWASCACHEDEV, wszDevId[cwcDevId + 1])); … … 1360 1402 if (fLookupOrCreateInCache) 1361 1403 { 1404 /* Make sure to enter the cache's critsect again for the following calls. */ 1405 RTCritSectEnter(&pThis->CritSectCache); 1406 1362 1407 /* 1363 1408 * Before adding the device to the cache, check that someone didn't race us adding it. 1364 1409 */ 1365 RTCritSectEnter(&pThis->CritSectCache);1366 1410 PDRVHOSTAUDIOWASCACHEDEV pDevEntry2; 1367 1411 RTListForEach(&pThis->CacheHead, pDevEntry2, DRVHOSTAUDIOWASCACHEDEV, ListEntry) … … 1379 1423 1380 1424 LogRel2(("WasAPI: Lost race adding device '%ls' (node %p)\n", pDevEntry2->wszDevId, pDevEntry2)); 1381 return drvHostAudioWasCacheLookupOrCreateConfig(pThis, pDevEntry2, pCfgReq, fOnWorker, ppDevCfg); 1425 return drvHostAudioWasCacheLookupOrCreateConfig(pThis, pDevEntry2, pCfgReq, 1426 true /* fUseCache */, fOnWorker, ppDevCfg); 1382 1427 } 1383 1428 } … … 1386 1431 LogRel2(("WasAPI: Added device '%ls' to cache (node %p)\n", pDevEntry->wszDevId, pDevEntry)); 1387 1432 } 1388 1389 return drvHostAudioWasCacheLookupOrCreateConfig(pThis, pDevEntry, pCfgReq, fOnWorker, ppDevCfg); 1433 else 1434 LogRel2(("WasAPI: Not caching device '%ls' (iface %p)\n", pDevEntry->wszDevId, pIDevice)); 1435 1436 return drvHostAudioWasCacheLookupOrCreateConfig(pThis, pDevEntry, pCfgReq, 1437 fLookupOrCreateInCache /* fUseCache */, fOnWorker, ppDevCfg); 1390 1438 } 1391 1439 CoTaskMemFree(pwszDevId); … … 1681 1729 rc = RTUtf16ToUtf8Ex(pDev->wszDevId, RTSTR_MAX, &pDev->Core.pszId, cbId, NULL); 1682 1730 if (RT_SUCCESS(rc)) 1731 { 1683 1732 PDMAudioHostEnumAppend(pDevEnm, &pDev->Core); 1733 LogRel2(("WasAPI: Device '%ls': %p\n", pDev->wszDevId, pIDevice)); 1734 } 1684 1735 else 1685 1736 PDMAudioHostDevFree(&pDev->Core); … … 2657 2708 cbPending = PDMAudioPropsFramesToBytes(&pStreamWas->Cfg.Props, RT_MIN(cFramesPending, VBOX_WASAPI_MAX_PADDING)); 2658 2709 } 2659 else 2660 LogRel Max(64, ("WasAPI: GetCurrentPaddingfailed on '%s': %Rhrc\n", pStreamWas->Cfg.szName, hrc));2710 else /* Don't use LogRelMax here to get a more accurate tracking about when this works again wrt recovery. */ 2711 LogRel2(("WasAPI: GetCurrentPadding[R] failed on '%s': %Rhrc\n", pStreamWas->Cfg.szName, hrc)); 2661 2712 } 2662 2713 } … … 2701 2752 } 2702 2753 } 2703 else 2704 LogRel Max(64, ("WasAPI: GetCurrentPaddingfailed on '%s': %Rhrc\n", pStreamWas->Cfg.szName, hrc));2754 else /* Don't use LogRelMax here to get a more accurate tracking about when this works again wrt recovery. */ 2755 LogRel2(("WasAPI: GetCurrentPadding[W] failed on '%s': %Rhrc\n", pStreamWas->Cfg.szName, hrc)); 2705 2756 } 2706 2757
Note:
See TracChangeset
for help on using the changeset viewer.