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(audio): use the device-tree name, adopt the vendor's init timing, and surface its own log
Veyra Goal Agentc566dda30a95
diff --git a/docs/AVERMEDIA_5P1_SWITCH_IMPLEMENTATION_2026-09-17.md b/docs/AVERMEDIA_5P1_SWITCH_IMPLEMENTATION_2026-09-17.mdindex faad7a40..761dfc61 100644--- a/docs/AVERMEDIA_5P1_SWITCH_IMPLEMENTATION_2026-09-17.md+++ b/docs/AVERMEDIA_5P1_SWITCH_IMPLEMENTATION_2026-09-17.md@@ -307,3 +307,50 @@ delivery 短测:PASS(logs\delivery\ac2283ab2a9d4f9e90738120ad79aada\result.j往上找到第一个含 `runtime_local` 的目录,于是两个会话**共用同一份 UI 设置/预设**:门禁里的`--smoke-color` 因此出现一次假失败(共享状态漂移),改成"只硬链接运行库、不共享状态文件"后复跑PASS。隔离工作区可以共享二进制依赖,**不能共享状态**。++---++## 附录 D:第二次真机日志(5.1.log)与修复++### D1 这次进步很大:卡被认出来了++```+[capture-audio-vendor] device tree: instance="USB\VID_07CA&PID_2553&MI_02\9&249B832B&0&0002" friendly="Live Gamer Ultra 2.1-Audio"+[capture-audio-vendor] device tree: instance="USB\VID_07CA&PID_2553&MI_00\9&249B832B&0&0000" friendly="Live Gamer Ultra 2.1-Video"+[capture-audio-vendor] using device-tree audio function instance="USB\VID_07CA&PID_2553&MI_02\..." for selected device="HDMI/Line In (Live Gamer Ultra 2.1-Audio)"+[capture-audio-vendor] non-PCM switch unavailable ... componentFound=1 dllsLoaded=1 detail="card not reached: getAudioFormat ret=5"+```++设备树兜底生效(r2 的修复方向正确),组件也加载了,但 SDK 没能跟卡说上话。++### D2 反汇编给出的两条线索++1. **名字**:`DeviceOpenerParam::getDeviceSwitchParam` 里有 `-Audio` / `-Video` 两个常量——它把+ 名字里的 `-Audio` 换成 `-Video` 去找 UVC 设备。我们当时传的是 DirectShow 端点名+ `HDMI/Line In (Live Gamer Ultra 2.1-Audio)`,换完变成+ `HDMI/Line In (Live Gamer Ultra 2.1-Video)`,而真实视频功能叫 `Live Gamer Ultra 2.1-Video`+ —— **对不上**。现在改用设备树里的 `Live Gamer Ultra 2.1-Audio`。+2. **路径**:同类函数找的是 `\\?\` 前缀与 `#{` 分隔符;我们传的真实接口路径+ `\\?\usb#vid_07ca&pid_2553&mi_02#...#{...}\global` 同时具备这两者,**方向是对的**。++### D3 本轮修复++1. **接上厂商自己的日志**(`DeviceOpener::SetLogHandler`,带 SEH/异常兜底):下次失败日志里会出现+ `vendor: DeviceOpener::OpenDevice, SDK setDevice ret: N` 这类行,直接指出是哪一步被拒。+ 本机用真实组件验证过:这些行确实进了 Veyra 日志(`vendor: DeviceOpener::OpenDevice, devicePath: ...`+ `vendor: DeviceOpener::OpenDevice, SDK setDevice ret: 4`)。+2. **补上 `initialize()` 之后的 1 秒等待**:厂商插件在初始化后固定 `Sleep(1000)` 才动手,+ 拆除时也是 `closePort → Sleep(1000) → uninitialize`。我方原先初始化完立刻切卡——这是最可疑的+ 失败原因,已按厂商节奏对齐。+3. **同一次连接内多试一个功能**:音频功能被拒时,自动改用卡的另一个 USB 功能再试一次(不用多跑一趟)。+4. 名字统一取设备树的 `...-Audio`,并在日志里同时保留 DirectShow 名字以便对照。++### D4 本机验证++```+veyra_avermedia_switch_tests:PASS(真实组件在场时能读到 vendor: 行,无卡时 getAudioFormat ret=5)+veyra_iec61937_probe_tests:PASS+delivery 短测:PASS(logs\delivery\7028a66ae7b24f6581993ac60de9dafc\result.json)+```++仍未验证:真卡上的实际切换结果。r3 包把能自证的都自证了,剩下这一步只能由带卡的机器回答。diff --git a/src/source/AverMediaAudioSwitch.cpp b/src/source/AverMediaAudioSwitch.cppindex e165f469..3b8c6ed3 100644--- a/src/source/AverMediaAudioSwitch.cpp+++ b/src/source/AverMediaAudioSwitch.cpp@@ -6,7 +6,9 @@#include <setupapi.h>#include <cstdint>+#include <cstdio>#include <format>+#include <functional>#include <string>#include <vector>@@ -102,6 +104,47 @@ constexpr const char* kExportOpenerSwitch = "?SwitchDeviceThenDetectAudioFormat@constexpr const char* kExportOpenerIsNonPcm = "?IsAudioFormatNonPcm@DeviceOpener@AVerMedia@@QEBA_NXZ";constexpr const char* kExportOpenerStartChecking = "?StartChecking@DeviceOpener@AVerMedia@@QEAAXXZ";constexpr const char* kExportOpenerStopChecking = "?StopChecking@DeviceOpener@AVerMedia@@QEAAXXZ";+// Static log sinks of the component. Plain function pointers (not+// std::function), so installing them crosses no C++ ABI that could bite us.+// Their own plugin installs the same four before it calls anything else.+constexpr const char* kExportSetDebugHandler = "?setDebugHandler@LogHelper@@YAXP6AXPEBDPEAD@Z@Z";+constexpr const char* kExportSetErrorHandler = "?setErrorHandler@LogHelper@@YAXP6AXPEBDPEAD@Z@Z";+constexpr const char* kExportSetInfoHandler = "?setInfoHandler@LogHelper@@YAXP6AXPEBDPEAD@Z@Z";+constexpr const char* kExportSetWarningHandler = "?setWarningHandler@LogHelper@@YAXP6AXPEBDPEAD@Z@Z";++// The component prints its diagnostics through these; without them the reason a+// switch failed stays invisible (the 2026-09-17 run only ever showed our own+// "card not reached" line). Signature matches their void(const char*, va_list).+void vendorLogSink(const char* format, char* args) noexcept {+ if (format == nullptr) return;+ char buffer[1024] = {};+ try {+ if (args != nullptr) vsnprintf(buffer, sizeof(buffer), format, args);+ else snprintf(buffer, sizeof(buffer), "%s", format);+ } catch (...) {+ return;+ }+ veyra::log::info("capture-audio-vendor", std::string("vendor: ") + buffer);+}++using SetVendorLogHandler = void (*)(void (*)(const char*, char*));++// DeviceOpener's own sink: the documented way their plugin collects these+// messages ("SetLogHandler" with a std::function<void(int,const char*)>).+// std::wstring already crossed this boundary correctly (the component read the+// DeviceOpenerParam we built), and the call is guarded, so a surprise here is+// reported instead of fatal.+constexpr const char* kExportOpenerSetLogHandler =+ "?SetLogHandler@DeviceOpener@AVerMedia@@QEAAXAEBV?$function@$$A6AXHPEBD@Z@std@@@Z";++void vendorOpenerLog(int level, const char* message) noexcept {+ if (message == nullptr) return;+ try {+ if (level == 1) veyra::log::warn("capture-audio-vendor", std::string("vendor: ") + message);+ else veyra::log::info("capture-audio-vendor", std::string("vendor: ") + message);+ } catch (...) {+ }+}// The chip reports this value while the HDMI source sends a compressed// (non-PCM) stream; their enable path refuses to switch for anything else.@@ -215,9 +258,14 @@ struct AverMediaAudioSwitch::Impl {RawFn openerDtor = nullptr;RawFn setVendorSdk = nullptr;RawFn switchDevice = nullptr;+ RawFn setLogHandler = nullptr; // optionalRawFn isNonPcm = nullptr;RawFn startChecking = nullptr;RawFn stopChecking = nullptr;+ SetVendorLogHandler setDebugHandler = nullptr;+ SetVendorLogHandler setErrorHandler = nullptr;+ SetVendorLogHandler setInfoHandler = nullptr;+ SetVendorLogHandler setWarningHandler = nullptr;bool complete() const {return vendorCtor && vendorDtor && initialize && uninitialize && closePort && getAudioFormat &&openerCtor && openerDtor && setVendorSdk && switchDevice && isNonPcm &&@@ -238,6 +286,7 @@ struct AverMediaAudioSwitch::Impl {bool openerConstructed = false;bool sdkInitialized = false;bool checking = false;+ std::wstring lastAppliedPath;void* sdk() noexcept { return sdkStorage.raw(); }void* opener() noexcept { return openerStorage.raw(); }@@ -255,6 +304,7 @@ struct AverMediaAudioSwitch::Impl {{kExportOpenerDtor, &exports.openerDtor},{kExportOpenerSetVendorSdk, &exports.setVendorSdk},{kExportOpenerSwitch, &exports.switchDevice},+ {kExportOpenerSetLogHandler, &exports.setLogHandler},{kExportOpenerIsNonPcm, &exports.isNonPcm},{kExportOpenerStartChecking, &exports.startChecking},{kExportOpenerStopChecking, &exports.stopChecking},@@ -262,6 +312,9 @@ struct AverMediaAudioSwitch::Impl {for (const Entry& entry : entries) {FARPROC address = GetProcAddress(avtModule, entry.name);if (address == nullptr) {+ // The log sink is optional: keep working with components that+ // do not export it, we just lose their internal trace.+ if (entry.target == &exports.setLogHandler) continue;status.detail = std::format("missing export {}", entry.name);return false;}@@ -270,6 +323,22 @@ struct AverMediaAudioSwitch::Impl {return true;}+ // Log sinks are optional: an older component without them must still load.+ void installLogSinks() {+ const struct { const char* name; SetVendorLogHandler* slot; } sinks[] = {+ {kExportSetDebugHandler, &exports.setDebugHandler},+ {kExportSetErrorHandler, &exports.setErrorHandler},+ {kExportSetInfoHandler, &exports.setInfoHandler},+ {kExportSetWarningHandler, &exports.setWarningHandler},+ };+ for (const auto& sink : sinks) {+ const FARPROC address = GetProcAddress(avtModule, sink.name);+ if (address == nullptr) continue;+ *sink.slot = reinterpret_cast<SetVendorLogHandler>(address);+ (*sink.slot)(vendorLogSink);+ }+ }+bool loadComponent() {if (avtModule != nullptr) return true;componentRoot = AverMediaAudioSwitch::locateComponentRoot();@@ -301,6 +370,10 @@ struct AverMediaAudioSwitch::Impl {if (qtModule != nullptr) { FreeLibrary(qtModule); qtModule = nullptr; }return false;}+ // Do this before anything else calls into the component: from here on+ // its own diagnostics land in the Veyra log instead of a console the+ // GUI process does not have.+ installLogSinks();return true;}};@@ -442,7 +515,7 @@ const AverMediaUsbFunction* AverMediaAudioSwitch::pickAudioFunction(const std::vbool AverMediaAudioSwitch::apply(const std::wstring& deviceName, const std::wstring& devicePath) {auto& impl = *p_;- if (impl.sdkInitialized && !devicePath.empty()) {+ 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// enough. This deliberately avoids a second setDevice/setPort cycle.@@ -471,6 +544,11 @@ bool AverMediaAudioSwitch::apply(const std::wstring& deviceName, const std::wstrimpl.status.state = AverMediaSwitchState::Failed;return false;}+ // Their own plugin sleeps one second after initialize() before it+ // touches the device; without it the SDK is not ready yet and+ // setDevice/getAudioFormat fail ("card not reached"). Same one second+ // on teardown, between closePort and uninitialize.+ Sleep(1000);impl.sdkInitialized = true;impl.status.sdkReady = true;}@@ -488,6 +566,15 @@ bool AverMediaAudioSwitch::apply(const std::wstring& deviceName, const std::wstrimpl.status.state = AverMediaSwitchState::Failed;return false;}+ if (impl.exports.setLogHandler != nullptr) {+ std::function<void(int, const char*)> sink = vendorOpenerLog;+ RawCall attachLog{impl.exports.setLogHandler, impl.opener(), &sink};+ std::string logError;+ if (!callVendor(attachLog, logError)) {+ // Losing the trace is not fatal, but say so.+ log::warn("capture-audio-vendor", std::string("component log sink could not be attached: ") + logError);+ }+ }}VendorDeviceOpenerParam param{deviceName, devicePath};RawCall switchCall{impl.exports.switchDevice, impl.opener(), ¶m};@@ -515,6 +602,7 @@ bool AverMediaAudioSwitch::apply(const std::wstring& deviceName, const std::wstrimpl.status.detail = std::format("chipAudioFormat={}{}", chipFormat,chipFormat == kChipFormatNonPcm ? " (non-PCM/Dolby)" : " (PCM)");impl.status.state = AverMediaSwitchState::Switched;+ impl.lastAppliedPath = devicePath;startMonitoring();return true;}@@ -533,6 +621,7 @@ void AverMediaAudioSwitch::stop() noexcept {RawCall close{impl.exports.closePort, impl.sdk()};std::string error;callVendor(close, error);+ Sleep(1000); // matches the component's own unload sequenceRawCall uninitialize{impl.exports.uninitialize, impl.sdk()};callVendor(uninitialize, error);impl.sdkInitialized = false;diff --git a/src/source/CaptureCardSource.cpp b/src/source/CaptureCardSource.cppindex 90b7397f..a0fc2cfe 100644--- a/src/source/CaptureCardSource.cpp+++ b/src/source/CaptureCardSource.cpp@@ -698,6 +698,7 @@ bool CaptureCardSource::configure(const SourceOpenDesc& desc){close();p_->lastAubool CaptureCardSource::applyVendorAudioSwitch(const std::wstring& audioName,const std::wstring& audioPath){auto& p=*p_;std::wstring name=audioName,path=audioPath;+ bool applied=false;if(!AverMediaAudioSwitch::isAverMediaDevicePath(path)){// These cards' DirectShow audio monikers often carry no DevicePath, so// the stored path is the class-manager display name@@ -715,12 +716,33 @@ bool CaptureCardSource::applyVendorAudioSwitch(const std::wstring& audioName,connarrowForLog(name),pathTag(path)));return false;}- if(name.empty())name=chosen->friendlyName;+ // Use the *device-tree* name, not the DirectShow endpoint name. The+ // component turns the UVC name into the camera name by replacing+ // "-Audio" with "-Video"; the DirectShow name here is+ // "HDMI/Line In (Live Gamer Ultra 2.1-Audio)", which would map to+ // "HDMI/Line In (Live Gamer Ultra 2.1-Video)" and never match the real+ // "Live Gamer Ultra 2.1-Video" function.+ const std::wstring directShowName=name;+ if(!chosen->friendlyName.empty())name=chosen->friendlyName;path=chosen->interfacePath.empty()?chosen->instanceId:chosen->interfacePath;- log::info("capture-audio-vendor",std::format("using device-tree audio function instance=\"{}\" for selected device=\"{}\"",- narrowForLog(chosen->instanceId),narrowForLog(name)));+ log::info("capture-audio-vendor",std::format("using device-tree audio function instance=\"{}\" name=\"{}\" (directShowName=\"{}\")",+ narrowForLog(chosen->instanceId),narrowForLog(name),narrowForLog(directShowName)));+ // One hedge, no extra round trip: if the audio function is refused, try+ // the card's other USB function before giving up. The component maps+ // "-Audio" to "-Video" internally, so both are plausible inputs.+ applied=p.averMediaSwitch.apply(name,path);+ if(!applied){+ for(const auto& function:functions){+ if(&function==chosen)continue;+ std::wstring fallbackName=function.friendlyName.empty()?directShowName:function.friendlyName;+ const std::wstring fallbackPath=function.interfacePath.empty()?function.instanceId:function.interfacePath;+ log::info("capture-audio-vendor",std::format("retrying switch with function instance=\"{}\" name=\"{}\"",+ narrowForLog(function.instanceId),narrowForLog(fallbackName)));+ if(p.averMediaSwitch.apply(fallbackName,fallbackPath)){applied=true;name=fallbackName;path=fallbackPath;break;}+ }+ }}- const bool applied=p.averMediaSwitch.apply(name,path);+ else applied=p.averMediaSwitch.apply(name,path);const auto& status=p.averMediaSwitch.status();if(applied){log::info("capture-audio-vendor",std::format("non-PCM switch armed device=\"{}\" component=\"{}\" chipFormat={} nonPcmNow={} monitoring={}",