Bring PS5 GTA6 to 120FPS with DLSS 5. An advanced Windows video player and capture enhancement tool featuring real-time preview for videos, images, and capture card sources. Combine AI-powered Super Resolution, DLSS5 image enhancement, and Frame Generation to deliver a next-generation visual experience.
C++
fix(capture): serialize passthrough arming before vendor monitoring
Veyra Goal Agent1708aa316998
diff --git a/include/veyra/source/AverMediaAudioSwitch.h b/include/veyra/source/AverMediaAudioSwitch.hindex 971adb7f..aed0046f 100644--- a/include/veyra/source/AverMediaAudioSwitch.h+++ b/include/veyra/source/AverMediaAudioSwitch.h@@ -88,7 +88,9 @@ public:// Loads the component (once) and arms non-PCM passthrough for the card// behind `devicePath`. Never throws; failures are reported in status().- bool apply(const std::wstring& deviceName, const std::wstring& devicePath);+ // Vendor audio graph setup defers monitoring until after Start so its+ // conditional enable cannot race the component's own monitor thread.+ bool apply(const std::wstring& deviceName, const std::wstring& devicePath,bool monitor=true);// Starts the vendor monitor thread that re-applies the switch when the// console changes audio format. Called by apply(); idempotent.void startMonitoring();diff --git a/src/source/AverMediaAudioSwitch.cpp b/src/source/AverMediaAudioSwitch.cppindex 1576e2a0..bc67022f 100644--- a/src/source/AverMediaAudioSwitch.cpp+++ b/src/source/AverMediaAudioSwitch.cpp@@ -523,8 +523,16 @@ const AverMediaUsbFunction* AverMediaAudioSwitch::pickAudioFunction(const std::vreturn functions.size() == 1 ? &functions.front() : nullptr;}-bool AverMediaAudioSwitch::apply(const std::wstring& deviceName, const std::wstring& devicePath) {+bool AverMediaAudioSwitch::apply(const std::wstring& deviceName, const std::wstring& devicePath,bool monitor) {auto& impl = *p_;+ // A graph rebuild reuses this SDK object. Quiesce its old monitor before+ // reading the flag and conditionally enabling; never contend with our own+ // monitoring thread between the read and the write.+ if(!monitor&&impl.checking){+ RawCall stop{impl.exports.stopChecking,impl.opener()};std::string error;+ if(!callVendor(stop,error)){impl.status.detail="StopChecking before graph setup failed: "+error;log::warn("capture-audio-vendor",impl.status.detail);return false;}+ impl.checking=false;+ }if (impl.sdkInitialized && !devicePath.empty() && devicePath == impl.lastAppliedPath) {// Already armed (for example after an audio reconnect); the vendor// monitor thread keeps the mode applied, so refreshing the status is@@ -615,7 +623,7 @@ bool AverMediaAudioSwitch::apply(const std::wstring& deviceName, const std::wstrformatByte == kChipFormatNonPcm ? " (non-PCM/Dolby)" : " (PCM)");impl.status.state = AverMediaSwitchState::Switched;impl.lastAppliedPath = devicePath;- startMonitoring();+ if(monitor)startMonitoring();return true;}diff --git a/src/source/AverMediaVendorAudio.cpp b/src/source/AverMediaVendorAudio.cppindex 4015e26a..862f76a9 100644--- a/src/source/AverMediaVendorAudio.cpp+++ b/src/source/AverMediaVendorAudio.cpp@@ -131,7 +131,7 @@ struct AverMediaVendorAudio::Impl {// AudioDevice only drives the capture graph. As in the public OBS// Activate path, DeviceOpener must also arm/monitor non-PCM on this// exact card. Keep its potentially slow SDK initialization on our STA.- if(!nonPcmSwitch.apply(chosen.friendlyName,chosen.devicePath))+ if(!nonPcmSwitch.apply(chosen.friendlyName,chosen.devicePath,false))log::warn("capture-audio-vendor",std::string("non-PCM switch unavailable; PCM capture remains possible: ")+nonPcmSwitch.status().detail);else nonPcmSwitch.alignPassthroughOnce();if(stopRequested)return false;@@ -140,6 +140,7 @@ struct AverMediaVendorAudio::Impl {||!call(Connect)||!call(SetCallback,&dealer)||!call(Start)){recordError("vendor audio graph setup/start failed");return false;}+ nonPcmSwitch.startMonitoring();// The watchdog begins after Start, not during its 5-13 second preroll.lastCallbackAt=nowSeconds();{std::lock_guard lock(mutex);state.device=chosen.friendlyName;state.starting=false;state.started=state.running=true;}diff --git a/tests/fixtures/FakeAverMediaSdk.cpp b/tests/fixtures/FakeAverMediaSdk.cppindex 93d12cf0..4576364b 100644--- a/tests/fixtures/FakeAverMediaSdk.cpp+++ b/tests/fixtures/FakeAverMediaSdk.cpp@@ -3,11 +3,11 @@#include <string>namespace {int format=-236,armed=0,queryError=0,writeError=0,applyWrite=1,initialized=0;-unsigned writes=0,disarms=0,inits=0,ctors=0;+unsigned writes=0,disarms=0,inits=0,ctors=0,monitorStarts=0;}extern "C" {__declspec(dllexport) void FakeConfigure(int f,int a,int q,int w,int update){format=f;armed=a;queryError=q;writeError=w;applyWrite=update;writes=disarms=0;}-__declspec(dllexport) unsigned FakeCount(unsigned n){return n==0?writes:n==1?disarms:n==2?inits:ctors;}+__declspec(dllexport) unsigned FakeCount(unsigned n){return n==0?writes:n==1?disarms:n==2?inits:n==4?monitorStarts:ctors;}void* SdkCtor(void* self,const char*){++ctors;return self;}void SdkDtor(void*){}int SdkInitialize(void*){initialized=1;++inits;return 0;}@@ -21,6 +21,6 @@ void OpenerDtor(void*){}void OpenerBind(void*,void*){}void OpenerSwitch(void*,const void*){}bool OpenerNonPcm(void*){return (format&255)==20;}-void OpenerStart(void*){}+void OpenerStart(void*){++monitorStarts;}void OpenerStop(void*){}}diff --git a/tests/unit/AverMediaPassthroughTests.cpp b/tests/unit/AverMediaPassthroughTests.cppindex b22a27a1..774c1755 100644--- a/tests/unit/AverMediaPassthroughTests.cpp+++ b/tests/unit/AverMediaPassthroughTests.cpp@@ -18,7 +18,8 @@ int wmain(int argc,wchar_t** argv){try{auto count=reinterpret_cast<unsigned(*)(unsigned)>(GetProcAddress(module,"FakeCount"));require(config&&count,"fixture control exports");using veyra::source::AverMediaAudioSwitch;AverMediaAudioSwitch audio;const std::wstring name=L"Live Gamer Ultra 2.1-Audio",path=L"\\\\?\\usb#vid_07ca&pid_2553&mi_02#5&card&0&0002#{guid}";- config(-236,0,0,0,1);require(audio.apply(name,path),"optional exports do not prevent old component load");+ config(-236,0,0,0,1);require(audio.apply(name,path,false),"optional exports do not prevent old component load");+ require(!audio.active()&&count(4)==0,"graph setup defers the monitor while reading and arming");require(audio.sourceIsBitstream(),"negative sign-extended format low byte is non-PCM");audio.alignPassthroughOnce();if(variant==L"no-get"){@@ -30,6 +31,10 @@ int wmain(int argc,wchar_t** argv){try{}else{require(variant==L"complete","known variant");require(count(0)==1&&audio.status().passthroughKnown&&audio.passthroughEnabled(),"off is armed once and read back");+ audio.startMonitoring();require(audio.active()&&count(4)==1,"monitor starts only after explicit graph setup completion");+ require(audio.apply(name,path,false)&&!audio.active(),"graph rebuild pauses the previous monitor on the same card");+ audio.alignPassthroughOnce();require(count(0)==1,"rebuild of armed card does not force enable");+ audio.startMonitoring();require(audio.active()&&count(4)==2,"monitor resumes after rebuild");audio.alignPassthroughOnce();require(count(0)==1,"already armed is never forced again");require(!audio.setPassthrough(false)&&count(1)==0,"never disarm an active source");config(20,1,0,0,1);audio.alignPassthroughOnce();require(count(0)==0,"positive format and armed state preserved");