Skip to content

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): adapt PR64 SDK readback and bounded audio delivery recovery

Veyra Goal Agent2ac8dca045e4
diff --git a/AGENTS.md b/AGENTS.md
index 0ef86788..b72c98f7 100644
--- a/AGENTS.md
+++ b/AGENTS.md
@@ -1,5 +1,7 @@
# Veyra 项目 Agent 执行规则
+> **2026-10-19 PR64授权**:用户要求继续合并适配PR64的PR63音频修正,按docs/PR64_AVERMEDIA_PLAN_2026-10-19.md在独立codex/pr64-avermedia-20261019实施;允许圆刚开关/载波/位流解码/会话交付及必要测试/CMake/文档适配,覆盖这些接点旧冻结。存档91旧树104分支/509脏路径(桌面466),无Agent、全E盘、构建-j2≤900秒/测试≤300秒,保留UI33ms/250ms及其他链路/运行库/真实配置。通过定向验收后允许本PR及适配合本地/远端main正常push;不夹带Claude及其他工作、不发布/代发/关机,无圆刚实卡不宣称硬件通过。
+
> **2026-10-18 PR63接入授权**:用户明确要求合并适配PR63(圆刚厂商音频图)。按docs/PR63_AVERMEDIA_AUDIO_PLAN_2026-10-18.md在codex/pr63-avermedia-audio-20261018实施,允许音频源/位流解码/会话/状态及必要CMake/测试/文档适配,覆盖这些接点的旧冻结。先存档90工作树/103分支状态与哈希、旧桌面509脏文件ZIP,另记录Claude美颜21在改文件;保留PR57和其他未合分支,不碰Claude施工。通过本机Windows定向验收后允许合并本PR和适配到main、普通GitHub同步,不发布/代发评论/关机。厂商DLL只可读本机已安装原件、无实卡不虚报;专有文件不改不进Git,产物全E盘,构建≤900秒/测试≤300秒、限-j2、无Agent/UI频率变更。
> **2026-10-17 PR57本机接入授权**:用户要求合入其云端Agent的PR57并做好测试。按docs/PR57_INTEGRATION_PLAN_2026-10-17.md,从main d68d6be在codex/pr57-capture-window-20261017保留原head09ac54b/1295d6b整合;允许窗口捕获游戏输入/缩放/resize及采集能力/精确格式/旧版选择入口的必要适配、源/引擎快照/bridge/QML/CMake/翻译/回归接点,覆盖这些范围历史冻结。本机Windows构建/实测通过后允许本地main正常合并与普通GitHub同步以完成PR57;不发布新版本、不改已发2.0.9资产/标签、不代发评论/关闭无关issue/派Agent/关机。84旧树/96旧分支/509脏文件与PR/源码bundle先存档;全E盘,测试≤300秒/构建≤900秒,UI33ms/250ms、既有低延迟/运行组件/模型/驱动/真实配置保持。云端测试待办不扩展当前授权,实卡未覆盖项须明示。
diff --git a/CMakeLists.txt b/CMakeLists.txt
index 0d5ca466..3cd46f11 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -814,6 +814,18 @@ if(VEYRA_FFMPEG_ROOT AND EXISTS "${VEYRA_FFMPEG_ROOT}/include/libavformat/avform
target_compile_options(veyra_avermedia_vendor_tests PRIVATE /utf-8)
target_compile_definitions(veyra_avermedia_vendor_tests PRIVATE NOMINMAX WIN32_LEAN_AND_MEAN UNICODE _UNICODE)
target_link_libraries(veyra_avermedia_vendor_tests PRIVATE veyra_sources)
+ foreach(sdk_variant IN ITEMS Full NoGet NoSet)
+ string(TOLOWER ${sdk_variant} sdk_variant_lower)
+ set(sdk_target veyra_avermedia_fake_sdk_${sdk_variant_lower})
+ add_library(${sdk_target} SHARED tests/fixtures/FakeAverMediaSdk.cpp tests/fixtures/FakeAverMediaSdk${sdk_variant}.def)
+ target_compile_features(${sdk_target} PRIVATE cxx_std_20)
+ target_compile_definitions(${sdk_target} PRIVATE NOMINMAX WIN32_LEAN_AND_MEAN)
+ endforeach()
+ add_executable(veyra_avermedia_passthrough_tests tests/unit/AverMediaPassthroughTests.cpp)
+ target_compile_features(veyra_avermedia_passthrough_tests PRIVATE cxx_std_20)
+ target_compile_options(veyra_avermedia_passthrough_tests PRIVATE /utf-8)
+ target_compile_definitions(veyra_avermedia_passthrough_tests PRIVATE NOMINMAX WIN32_LEAN_AND_MEAN UNICODE _UNICODE)
+ target_link_libraries(veyra_avermedia_passthrough_tests PRIVATE veyra_sources)
add_executable(veyra_iec61937_probe_tests tests/unit/Iec61937ProbeTests.cpp)
target_compile_features(veyra_iec61937_probe_tests PRIVATE cxx_std_20)
target_compile_definitions(veyra_iec61937_probe_tests PRIVATE NOMINMAX WIN32_LEAN_AND_MEAN UNICODE _UNICODE)
diff --git a/THIRD_PARTY_NOTICES.md b/THIRD_PARTY_NOTICES.md
index 4c781cd6..748891b6 100644
--- a/THIRD_PARTY_NOTICES.md
+++ b/THIRD_PARTY_NOTICES.md
@@ -940,6 +940,8 @@ Changes to `libavfilter/vf_deinterlace_d3d12.c` are supplied as `scripts/ffmpeg/
Redistribution of this module must include `COPYING.LGPLv2.1`, the FFmpeg license notice, the actual configuration/hash/patch manifest and the complete corresponding-source archive generated by that script. Build/use boundaries and rebuild instructions: `docs/BUILD_DEINTERLACE_2026-10-16.md`. MediaMTX v1.21.2 (MIT, https://github.com/bluenviron/mediamtx/releases/tag/v1.21.2) is used only as a loopback RTSP regression server and is not shipped in the player.
## AVerMedia vendor audio graph (PR63)
+Follow-up: [PR64](https://github.com/Likely7/Veyra-NRVideo/pull/64), fixed commit `a7034d67ab75e16f85a17e123b9b07d391a7c75c`, contributes conditional non-PCM arming, sign-extended format classification, framed decode and nonfatal PCM delivery rejection. Veyra adapts unknown/failed optional SDK queries, verified readback, bounded rejection recovery and complete multi-frame payload tests. ABI reference additionally includes `avt_device_opener/include/AVerMediaVendorSdkLoader.h` at the same fixed AVerMedia public commit below; no vendor implementation or binary is copied. SDK/DeviceOpener test fixtures are independently authored source-only doubles.
+
- Integration source: [Se7eNHea7eN/Veyra-NRVideo PR63](https://github.com/Likely7/Veyra-NRVideo/pull/63), fixed commit `4db24dada13748364d7e613bc4160224b330a7d2`, Veyra GPL-3.0 repository. The original graph adapter is credited to that contribution.
- Adapted files: `include/veyra/source/AverMediaVendorAudio.h`, `src/source/AverMediaVendorAudio.cpp`, `src/source/CaptureCardSource.cpp`, and CMake. Veyra additions split bounded carrier handling into `AverMediaAudioCarrier`, add strict identity/public-ABI declarations in `AverMediaVendorProtocol`, format-aware decoding in `BitstreamAudio`, and source-only test doubles/codec tests.
- ABI reference only: AVerMedia's [obs-MultichannelAudio public headers](https://github.com/AVerMedia-Technologies-Inc/obs-MultichannelAudio/tree/7d1250b42e42f964b4fa3a6bcb7269cc09a1e798/avt_dshow_core/include), fixed commit `7d1250b42e42f964b4fa3a6bcb7269cc09a1e798`. Its repository contains a GPL-2.0 license. No OBS implementation source or proprietary vendor implementation is copied into Veyra; local declarations describe the public x64 call contract (`AudioDevice`, `AudioDealer`, `AUDIO_SAMPLE_INFO`, `DeviceInfo`, and `LogHelper`).
diff --git a/docs/PR64_AVERMEDIA_PLAN_2026-10-19.md b/docs/PR64_AVERMEDIA_PLAN_2026-10-19.md
new file mode 100644
index 00000000..c36e57ea
--- /dev/null
+++ b/docs/PR64_AVERMEDIA_PLAN_2026-10-19.md
@@ -0,0 +1,11 @@
+# PR64 圆刚音频修正适配
+
+用户授权继续合并适配 PR64;基线 main786efeb,原 PR head a7034d67ab75e16f85a17e123b9b07d391a7c75c。在 codex/pr64-avermedia-20261019 保留原提交合入、补必要音频源/解码器/状态/测试/CMake/文档接点,验收后合并本地和 GitHub main、正常 push;不发布、不改其他分支、不代发消息、不关机、不派 Agent。
+
+存档 E:/项目/Veyra/archives/pr64-avermedia-20261019:91旧工作树、104分支、509个脏路径哈希(桌面466个,其他旧工作树43个)、桌面既有脏文件ZIP对照、全引用bundle verify及原PR。旧工作树/配置/运行库/SDK不修改,Claude工作保持独立。
+
+1. 保留 PR 的 non-PCM flag 查询/条件开启、芯片格式低字节识别。补未知/查询失败/旧组件缺可选导出时不盲写;禁止关闭已开启的 passthrough,开启后回读验证,清理重用状态。以本机自写 SDK ABI 夹具验证正/负格式、已开启、关闭、失败及缺导出;不以模拟代替圆刚实卡。
+2. 保留完整编码帧直送解码器,真实编码检查 AC3 首帧即时1536采样、原解析流需下一帧;验证 EAC3 合并负载是否全部解出,不能把一个 IEC 突发一律当一个编码帧丢尾音频。保留普通原始流/分片流解析器契约。
+3. 单块 PCM 拒收不拆源;补连续拒收的有限恢复和断点,避免永久吞错、无限刷日志或跨缺口续接旧时钟。
+4. 完整Windows应用构建、相关单元/真实编解码/ABI/现有音频和 T911 实卡回归;UI33ms/250ms、NR/SR/FG/视频队列保持。不制造竞争负载。全产物E盘任务目录,构建-j2/≤900秒,每测试≤300秒。
+5. 逐项记录来源、测试/失败与修正、未测圆刚硬件及驱动边界;合并前重核原 PR/main head,元数据合并需与已验树一致;禁止force或夹带AMD/全屏/Claude工作。
diff --git a/docs/WORKLOG.md b/docs/WORKLOG.md
index da52387b..5572d976 100644
--- a/docs/WORKLOG.md
+++ b/docs/WORKLOG.md
@@ -1,5 +1,10 @@
# WORKLOG
+## 2026-10-19 PR64开工
+
+从main786efeb隔离合入PR64 a7034d6,已存档91旧树/104分支状态、509脏路径哈希(桌面466)和源码bundle verify。按PR64_AVERMEDIA_PLAN_2026-10-19.md补可选查询的未知状态保护、完整包解码边界、单块拒收与连续错误恢复及真实编码/模拟SDK/实卡回归。保持其他工作树和运行库,验收后只正常合并同步main。
+
+
## 2026-10-18 PR63 适配验收完成并合并
原PR提交4db24da保留;验收代码3a77635。GitHub PR63已合并642f608,整合提交8463a60与已验树内容完全相同,本记录随main正常同步;最终远端核对在E:/项目/Veyra/reports/pr63-avermedia-audio-20261018/merge.json。按官方固定ABI补精确设备、non-PCM arming、STA/150ms初始等待/有限恢复、格式切换与回调生命周期、载波有界/坏流无进展、实际声道mask及FFmpeg padding/reset。最终14目标MSVC构建通过;12组音频/采集回归全过;本机T911 1080p60含重连60.049599/60.050652FPS、HDMI音频48kHz/16bit/63块/0underruns通过。无圆刚实卡,不能代替GC553G2等实机验收;厂商Stop失败隔离保留和同步调用无法硬取消的边界见报告。
diff --git a/include/veyra/sink/BitstreamAudio.h b/include/veyra/sink/BitstreamAudio.h
index d87e71a3..b4e4b23f 100644
--- a/include/veyra/sink/BitstreamAudio.h
+++ b/include/veyra/sink/BitstreamAudio.h
@@ -89,9 +89,9 @@ public:
// is also stored in lastError(). The AC-3 parser holds a complete frame
// until the next frame header arrives, so this path is one frame behind.
bool push(const uint8_t* data, size_t bytes, std::vector<float>& out);
- // One complete codec frame, already split by the caller (an IEC 61937
- // payload is one). Sent straight to the decoder, so the frame is not held
- // for the following header.
+ // Complete codec packet, already delimited by the caller (e.g. an IEC
+ // payload, which may aggregate frames). It does not wait for the next
+ // packet's header. Do not mix this with push() without reset().
bool pushFramed(const uint8_t* data, size_t bytes, std::vector<float>& out);
// Drops codec state (seek / discontinuity): the next bytes start a new
// stream, which is what happens when the console switches audio format.
diff --git a/include/veyra/source/AverMediaAudioSwitch.h b/include/veyra/source/AverMediaAudioSwitch.h
index 368aa272..971adb7f 100644
--- a/include/veyra/source/AverMediaAudioSwitch.h
+++ b/include/veyra/source/AverMediaAudioSwitch.h
@@ -56,6 +56,7 @@ struct AverMediaSwitchStatus {
bool sdkReady = false;
bool nonPcmActive = false; // what the chip reports *now* (source format)
bool passthroughEnabled = false; // VendorSdk::getNonPcmOnOff (the armed mode)
+ bool passthroughKnown = false; // missing/failed query is not "off"
int chipAudioFormat = -1; // raw AT_Audio_Get_HdmiRX_AudioFormat value
std::wstring componentRoot; // folder that owns obs-plugins\64bit
std::string detail; // last result/error, for the log
@@ -104,7 +105,7 @@ public:
bool passthroughEnabled() const;
// VendorSdk::setNonPcmOnOff. Callers arm only when the flag is off:
// forcing the call while the chip already reports armed left the pin
- // silent (2026-10-01). This never disarms.
+ // silent (2026-10-01). False is rejected; this API never disarms.
bool setPassthrough(bool enable);
// One alignment after apply(), before the vendor graph starts. Arms
// passthrough when the flag is off. The OBS plugin makes the same call
diff --git a/include/veyra/source/CaptureAudioDeliveryPolicy.h b/include/veyra/source/CaptureAudioDeliveryPolicy.h
new file mode 100644
index 00000000..d4a7f8b6
--- /dev/null
+++ b/include/veyra/source/CaptureAudioDeliveryPolicy.h
@@ -0,0 +1,21 @@
+#pragma once
+
+namespace veyra::source {
+// One malformed/rejected delivery must not tear down a healthy source. A
+// persistent format/PTS error must not be hidden forever either. This state
+// belongs to the serialized vendor callback, never to a UI/render timer.
+class CaptureAudioDeliveryPolicy {
+public:
+ static constexpr unsigned kRecoveryThreshold=30;
+ bool discontinuity(bool source)const{return source||gap_;}
+ bool delivered(bool accepted){
+ if(accepted){rejected_=0;gap_=false;return true;}
+ gap_=true;return ++rejected_<kRecoveryThreshold;
+ }
+ bool logRejection()const{return rejected_==1||rejected_%kRecoveryThreshold==0;}
+ unsigned rejected()const{return rejected_;}
+private:
+ unsigned rejected_=0;
+ bool gap_=false;
+};
+}
diff --git a/src/sink/BitstreamAudio.cpp b/src/sink/BitstreamAudio.cpp
index 55572158..4d3d8fa8 100644
--- a/src/sink/BitstreamAudio.cpp
+++ b/src/sink/BitstreamAudio.cpp
@@ -382,8 +382,9 @@ bool BitstreamDecoder::push(const uint8_t* data, size_t bytes, std::vector<float
bool BitstreamDecoder::pushFramed(const uint8_t* data, size_t bytes, std::vector<float>& out) {
auto& p = *p_;
- if (p.context == nullptr) return false;
- if (data == nullptr || bytes == 0) return true;
+ if (p.context == nullptr) {p.lastError="decoder not opened";return false;}
+ if (bytes == 0) return true;
+ if (data == nullptr) {p.lastError="null framed packet";return false;}
if (bytes > size_t(INT_MAX)) {
p.lastError = "framed packet is too large";
return false;
diff --git a/src/source/AverMediaAudioCarrier.cpp b/src/source/AverMediaAudioCarrier.cpp
index 2e4bc26e..dcd55781 100644
--- a/src/source/AverMediaAudioCarrier.cpp
+++ b/src/source/AverMediaAudioCarrier.cpp
@@ -54,8 +54,8 @@ bool AverMediaAudioCarrier::emitBurst(std::span<const uint8_t> words,size_t payl
for(size_t i=0;i+1<words.size();i+=2){packet_[i]=words[i+1];packet_[i+1]=words[i];}
packet_.resize(payloadBytes); // Odd byte payloads include a padded carrier word.
pcm_.clear();
- // One IEC payload is one codec frame. push() would keep an AC-3 frame
- // until the next header, which is another 32 ms on every block.
+ // IEC supplies a complete payload boundary (EAC3 can aggregate frames).
+ // push() would retain AC3 until the next header: 32ms at 48kHz.
if(!decoder_->pushFramed(packet_.data(),packet_.size(),pcm_)){state_.error=decoder_->lastError();return false;}
if(pcm_.empty()){
if(++undecodedBursts_>=64){state_.error="no decoded audio after 64 carrier bursts";return false;}
diff --git a/src/source/AverMediaAudioSwitch.cpp b/src/source/AverMediaAudioSwitch.cpp
index 7cb72138..7df397c1 100644
--- a/src/source/AverMediaAudioSwitch.cpp
+++ b/src/source/AverMediaAudioSwitch.cpp
@@ -97,8 +97,8 @@ constexpr const char* kExportSdkInitialize = "?initialize@VendorSdk@AVerMedia@@Q
constexpr const char* kExportSdkUninitialize = "?uninitialize@VendorSdk@AVerMedia@@QEAAHXZ";
constexpr const char* kExportSdkClosePort = "?closePort@VendorSdk@AVerMedia@@QEAAHXZ";
constexpr const char* kExportSdkGetAudioFormat = "?getAudioFormat@VendorSdk@AVerMedia@@QEAAHPEAH@Z";
-// Passthrough control. Present in 1.0.15 (verified against the installed
-// avt_device_opener.dll); resolved as optional so older components still load.
+// Public SDK signatures; PR64's author reports verification on 1.0.15.
+// Optional so older components still load. No real component on our test host.
constexpr const char* kExportSdkGetNonPcmOnOff = "?getNonPcmOnOff@VendorSdk@AVerMedia@@QEAAHPEAI@Z";
constexpr const char* kExportSdkSetNonPcmOnOff = "?setNonPcmOnOff@VendorSdk@AVerMedia@@QEAAHH@Z";
constexpr const char* kExportOpenerCtor = "??0DeviceOpener@AVerMedia@@QEAA@XZ";
@@ -637,6 +637,7 @@ void AverMediaAudioSwitch::stop() noexcept {
RawCall uninitialize{impl.exports.uninitialize, impl.sdk()};
callVendor(uninitialize, error);
impl.sdkInitialized = false;
+ impl.status.sdkReady = false;
}
if (impl.openerConstructed) {
RawCall dtor{impl.exports.openerDtor, impl.opener()};
@@ -654,6 +655,9 @@ void AverMediaAudioSwitch::stop() noexcept {
// Teardown must never throw; the vendors' worker threads are already
// stopped by the calls above.
}
+ impl.lastAppliedPath.clear();
+ impl.status.passthroughKnown=false;impl.status.passthroughEnabled=false;
+ impl.status.chipAudioFormat=-1;impl.status.nonPcmActive=false;
// The modules stay loaded on purpose: their monitor thread and the Qt
// runtime are not safe to unload while other threads may still touch them.
}
@@ -661,6 +665,9 @@ void AverMediaAudioSwitch::stop() noexcept {
bool AverMediaAudioSwitch::refreshChipState() {
if (!p_) return false;
auto& impl = *p_;
+ impl.status.passthroughKnown=false;
+ impl.status.passthroughEnabled=false;
+ impl.status.chipAudioFormat=-1;
if (!impl.sdkInitialized || impl.exports.getAudioFormat == nullptr) return false;
std::string error;
int chipFormat = -1;
@@ -672,6 +679,7 @@ bool AverMediaAudioSwitch::refreshChipState() {
RawCall onOffCall{impl.exports.getNonPcmOnOff, impl.sdk(), &onOff};
if (callVendor(onOffCall, error) && onOffCall.result == 0) {
impl.status.passthroughEnabled = onOff != 0;
+ impl.status.passthroughKnown=true;
}
}
return formatOk;
@@ -686,9 +694,13 @@ bool AverMediaAudioSwitch::passthroughEnabled() const {
}
bool AverMediaAudioSwitch::setPassthrough(bool enable) {
- if (!p_) return false;
+ if (!p_ || !enable) return false;
auto& impl = *p_;
- if (!impl.sdkInitialized || impl.exports.setNonPcmOnOff == nullptr) return false;
+ if (!refreshChipState() || !impl.status.passthroughKnown) {
+ log::warn("capture-audio-vendor","passthrough query unavailable/failed; refusing a blind forced enable");return false;
+ }
+ if(impl.status.passthroughEnabled)return true;
+ if(impl.exports.setNonPcmOnOff == nullptr){log::warn("capture-audio-vendor","setNonPcmOnOff export unavailable; leaving current mode unchanged");return false;}
// The raw invoker passes void* arguments; an int parameter travels in the
// low 32 bits of the register on x64, which is how the component reads it.
RawCall call{impl.exports.setNonPcmOnOff, impl.sdk(),
@@ -697,8 +709,10 @@ bool AverMediaAudioSwitch::setPassthrough(bool enable) {
const bool ok = callVendor(call, error) && call.result == 0;
log::info("capture-audio-vendor", std::format("setNonPcmOnOff({}) result={}{}",
enable ? 1 : 0, call.result, ok ? "" : (error.empty() ? " failed" : " failed: " + error)));
- if (ok) impl.status.passthroughEnabled = enable;
- return ok;
+ // A successful write is not proof that the chip actually armed.
+ const bool readback=ok&&refreshChipState()&&impl.status.passthroughKnown&&impl.status.passthroughEnabled;
+ if(ok&&!readback)log::warn("capture-audio-vendor","passthrough enable did not read back as armed");
+ return readback;
}
void AverMediaAudioSwitch::alignPassthroughOnce() {
@@ -706,12 +720,13 @@ void AverMediaAudioSwitch::alignPassthroughOnce() {
const bool bitstream = sourceIsBitstream();
const bool armed = passthroughEnabled();
log::info("capture-audio-vendor", std::format(
- "HDMI source audio format: chipFormat={} ({}); passthrough reports armed={}",
- p_->status.chipAudioFormat, bitstream ? "bitstream" : "PCM", armed ? 1 : 0));
+ "HDMI source audio format: chipFormat={} ({}); passthrough known={} armed={}",
+ p_->status.chipAudioFormat, bitstream ? "bitstream" : "PCM/unknown",p_->status.passthroughKnown, armed ? 1 : 0));
// Forcing this call when the component already reports armed left the KS
// pin silent (2026-10-01). Only top it up when it is actually off, and
// never disarm: the monitor thread treats a disarm as something to undo.
- if (!armed) setPassthrough(true);
+ if (p_->status.passthroughKnown&&!armed) setPassthrough(true);
+ else if(!p_->status.passthroughKnown)log::warn("capture-audio-vendor","passthrough flag unknown; preserving existing mode");
}
void AverMediaAudioSwitch::startMonitoring() {
diff --git a/src/source/CaptureCardSource.cpp b/src/source/CaptureCardSource.cpp
index d2278de4..0f5468db 100644
--- a/src/source/CaptureCardSource.cpp
+++ b/src/source/CaptureCardSource.cpp
@@ -18,6 +18,7 @@
#include "veyra/source/CaptureCompressedDecoder.h"
#include "veyra/source/AverMediaAudioSwitch.h"
#include "veyra/source/AverMediaVendorAudio.h"
+#include "veyra/source/CaptureAudioDeliveryPolicy.h"
#include "veyra/source/ElgatoHdrControl.h"
#include "veyra/pipeline/ColorMetadata.h"
#include "veyra/Log.h"
@@ -1489,7 +1490,7 @@ bool CaptureCardSource::connectVendorAudio(const std::wstring& deviceName,const
auto session=std::make_unique<sink::CaptureAudioSession>();
auto vendor=std::make_unique<AverMediaVendorAudio>();
auto* target=session.get();
- struct FormatState {unsigned channels=0;uint32_t rate=0,mask=0;CaptureAudioClock clock;};
+ struct FormatState {unsigned channels=0;uint32_t rate=0,mask=0;CaptureAudioClock clock;CaptureAudioDeliveryPolicy delivery;};
auto format=std::make_shared<FormatState>();
auto delivering=std::make_shared<std::atomic<bool>>(false);
const bool started=vendor->start([target,format,delivering](const VendorPcmBlock& block){
@@ -1512,14 +1513,15 @@ bool CaptureCardSource::connectVendorAudio(const std::wstring& deviceName,const
log::info("capture-audio-vendor",std::format("session format channels={} mask=0x{:X} rate={} float=1",block.channels,block.mask,block.rate));
}
target->setInputBitstream(std::wstring(block.codec.begin(),block.codec.end()));
- const bool discontinuity=changed||block.discontinuity;
+ const bool discontinuity=format->delivery.discontinuity(changed||block.discontinuity);
const double arrival=std::chrono::duration<double,std::milli>(std::chrono::steady_clock::now().time_since_epoch()).count();
const double pts=format->clock.observe(std::nullopt,arrival,1000.0*double(block.frames)/block.rate,discontinuity);
const size_t bytes=block.frames*block.channels*sizeof(float);
- if(!target->push(block.samples,bytes,pts,discontinuity)){
- log::warn("capture-audio-vendor",std::format("audio session rejected one block bytes={} channels={} rate={}; keeping the stream",bytes,block.channels,block.rate));
- }
- return true;
+ const bool accepted=target->push(block.samples,bytes,pts,discontinuity);
+ const bool keep=format->delivery.delivered(accepted);
+ if(!accepted&&format->delivery.logRejection())
+ log::warn("capture-audio-vendor",std::format("audio session rejected block bytes={} channels={} rate={} consecutive={} keepingStream={}",bytes,block.channels,block.rate,format->delivery.rejected(),keep));
+ return keep;
},preferName,preferPath);
const auto state=vendor->state();
if(!started){
diff --git a/tests/fixtures/FakeAverMediaSdk.cpp b/tests/fixtures/FakeAverMediaSdk.cpp
new file mode 100644
index 00000000..93d12cf0
--- /dev/null
+++ b/tests/fixtures/FakeAverMediaSdk.cpp
@@ -0,0 +1,26 @@
+// Source-only test double for the public VendorSdk / DeviceOpener ABI.
+#include <windows.h>
+#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;
+}
+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;}
+void* SdkCtor(void* self,const char*){++ctors;return self;}
+void SdkDtor(void*){}
+int SdkInitialize(void*){initialized=1;++inits;return 0;}
+int SdkUninitialize(void*){initialized=0;return 0;}
+int SdkClose(void*){return 0;}
+int SdkFormat(void*,int* value){if(!initialized||queryError==2)return -1;*value=format;return 0;}
+int SdkGet(void*,unsigned* value){if(queryError==3)RaiseException(0xC0000005,0,0,nullptr);if(!initialized||queryError==1)return -1;*value=unsigned(armed);return 0;}
+int SdkSet(void*,int value){++writes;if(!value)++disarms;if(!initialized||writeError)return -1;if(applyWrite)armed=value;return 0;}
+void* OpenerCtor(void* self){return self;}
+void OpenerDtor(void*){}
+void OpenerBind(void*,void*){}
+void OpenerSwitch(void*,const void*){}
+bool OpenerNonPcm(void*){return (format&255)==20;}
+void OpenerStart(void*){}
+void OpenerStop(void*){}
+}
diff --git a/tests/fixtures/FakeAverMediaSdkFull.def b/tests/fixtures/FakeAverMediaSdkFull.def
new file mode 100644
index 00000000..4092658c
--- /dev/null
+++ b/tests/fixtures/FakeAverMediaSdkFull.def
@@ -0,0 +1,16 @@
+EXPORTS
+ ??0VendorSdk@AVerMedia@@QEAA@PEBD@Z=SdkCtor
+ ??1VendorSdk@AVerMedia@@QEAA@XZ=SdkDtor
+ ?initialize@VendorSdk@AVerMedia@@QEAAHXZ=SdkInitialize
+ ?uninitialize@VendorSdk@AVerMedia@@QEAAHXZ=SdkUninitialize
+ ?closePort@VendorSdk@AVerMedia@@QEAAHXZ=SdkClose
+ ?getAudioFormat@VendorSdk@AVerMedia@@QEAAHPEAH@Z=SdkFormat
+ ?getNonPcmOnOff@VendorSdk@AVerMedia@@QEAAHPEAI@Z=SdkGet
+ ?setNonPcmOnOff@VendorSdk@AVerMedia@@QEAAHH@Z=SdkSet
+ ??0DeviceOpener@AVerMedia@@QEAA@XZ=OpenerCtor
+ ??1DeviceOpener@AVerMedia@@QEAA@XZ=OpenerDtor
+ ?SetVendorSdk@DeviceOpener@AVerMedia@@QEAAXPEAVVendorSdk@2@@Z=OpenerBind
+ ?SwitchDeviceThenDetectAudioFormat@DeviceOpener@AVerMedia@@QEAAXAEBUDeviceOpenerParam@2@@Z=OpenerSwitch
+ ?IsAudioFormatNonPcm@DeviceOpener@AVerMedia@@QEBA_NXZ=OpenerNonPcm
+ ?StartChecking@DeviceOpener@AVerMedia@@QEAAXXZ=OpenerStart
+ ?StopChecking@DeviceOpener@AVerMedia@@QEAAXXZ=OpenerStop
diff --git a/tests/fixtures/FakeAverMediaSdkNoGet.def b/tests/fixtures/FakeAverMediaSdkNoGet.def
new file mode 100644
index 00000000..87c310d1
--- /dev/null
+++ b/tests/fixtures/FakeAverMediaSdkNoGet.def
@@ -0,0 +1,15 @@
+EXPORTS
+ ??0VendorSdk@AVerMedia@@QEAA@PEBD@Z=SdkCtor
+ ??1VendorSdk@AVerMedia@@QEAA@XZ=SdkDtor
+ ?initialize@VendorSdk@AVerMedia@@QEAAHXZ=SdkInitialize
+ ?uninitialize@VendorSdk@AVerMedia@@QEAAHXZ=SdkUninitialize
+ ?closePort@VendorSdk@AVerMedia@@QEAAHXZ=SdkClose
+ ?getAudioFormat@VendorSdk@AVerMedia@@QEAAHPEAH@Z=SdkFormat
+ ?setNonPcmOnOff@VendorSdk@AVerMedia@@QEAAHH@Z=SdkSet
+ ??0DeviceOpener@AVerMedia@@QEAA@XZ=OpenerCtor
+ ??1DeviceOpener@AVerMedia@@QEAA@XZ=OpenerDtor
+ ?SetVendorSdk@DeviceOpener@AVerMedia@@QEAAXPEAVVendorSdk@2@@Z=OpenerBind
+ ?SwitchDeviceThenDetectAudioFormat@DeviceOpener@AVerMedia@@QEAAXAEBUDeviceOpenerParam@2@@Z=OpenerSwitch
+ ?IsAudioFormatNonPcm@DeviceOpener@AVerMedia@@QEBA_NXZ=OpenerNonPcm
+ ?StartChecking@DeviceOpener@AVerMedia@@QEAAXXZ=OpenerStart
+ ?StopChecking@DeviceOpener@AVerMedia@@QEAAXXZ=OpenerStop
diff --git a/tests/fixtures/FakeAverMediaSdkNoSet.def b/tests/fixtures/FakeAverMediaSdkNoSet.def
new file mode 100644
index 00000000..4827cc3b
--- /dev/null
+++ b/tests/fixtures/FakeAverMediaSdkNoSet.def
@@ -0,0 +1,15 @@
+EXPORTS
+ ??0VendorSdk@AVerMedia@@QEAA@PEBD@Z=SdkCtor
+ ??1VendorSdk@AVerMedia@@QEAA@XZ=SdkDtor
+ ?initialize@VendorSdk@AVerMedia@@QEAAHXZ=SdkInitialize
+ ?uninitialize@VendorSdk@AVerMedia@@QEAAHXZ=SdkUninitialize
+ ?closePort@VendorSdk@AVerMedia@@QEAAHXZ=SdkClose
+ ?getAudioFormat@VendorSdk@AVerMedia@@QEAAHPEAH@Z=SdkFormat
+ ?getNonPcmOnOff@VendorSdk@AVerMedia@@QEAAHPEAI@Z=SdkGet
+ ??0DeviceOpener@AVerMedia@@QEAA@XZ=OpenerCtor
+ ??1DeviceOpener@AVerMedia@@QEAA@XZ=OpenerDtor
+ ?SetVendorSdk@DeviceOpener@AVerMedia@@QEAAXPEAVVendorSdk@2@@Z=OpenerBind
+ ?SwitchDeviceThenDetectAudioFormat@DeviceOpener@AVerMedia@@QEAAXAEBUDeviceOpenerParam@2@@Z=OpenerSwitch
+ ?IsAudioFormatNonPcm@DeviceOpener@AVerMedia@@QEBA_NXZ=OpenerNonPcm
+ ?StartChecking@DeviceOpener@AVerMedia@@QEAAXXZ=OpenerStart
+ ?StopChecking@DeviceOpener@AVerMedia@@QEAAXXZ=OpenerStop
diff --git a/tests/unit/AverMediaCarrierTests.cpp b/tests/unit/AverMediaCarrierTests.cpp
index 7ccc4c10..bb212de5 100644
--- a/tests/unit/AverMediaCarrierTests.cpp
+++ b/tests/unit/AverMediaCarrierTests.cpp
@@ -1,8 +1,10 @@
#include "veyra/source/AverMediaAudioCarrier.h"
+#include "veyra/source/CaptureAudioDeliveryPolicy.h"
#include <algorithm>
#include <bit>
#include <cmath>
#include <iostream>
+#include <climits>
#include <stdexcept>
extern "C" {
#include <libavcodec/avcodec.h>
@@ -56,6 +58,36 @@ CodecFormat referenceFormat(AVCodecID id,const std::vector<std::vector<uint8_t>>
}
}
int main(){try{
+ source::CaptureAudioDeliveryPolicy delivery;
+ require(delivery.delivered(false)&&delivery.discontinuity(false),"one rejected block keeps stream and marks next discontinuity");
+ require(delivery.delivered(true)&&!delivery.discontinuity(false),"accepted block clears rejection gap");
+ for(unsigned n=1;n<delivery.kRecoveryThreshold;++n)require(delivery.delivered(false),"temporary rejected blocks do not rebuild graph");
+ require(!delivery.delivered(false),"persistent rejected blocks request bounded recovery");
+ require(delivery.delivered(true)&&delivery.rejected()==0,"successful delivery restores budget");
+ for(auto codec:{AV_CODEC_ID_AC3,AV_CODEC_ID_EAC3}){
+ const auto packets=encode(codec,0x60f,48000);
+ const auto kind=codec==AV_CODEC_ID_AC3?sink::BitstreamKind::Ac3:sink::BitstreamKind::Eac3;
+ sink::BitstreamDecoder direct,parsed;std::vector<float> a,b;
+ require(direct.open(kind)&&parsed.open(kind),"latency comparison decoders");
+ require(direct.pushFramed(packets[0].data(),packets[0].size(),a),"complete codec frame directly accepted");
+ require(direct.decodedFrames()==1536&&a.size()==1536*6,"complete frame emits immediately without next header");
+ require(parsed.push(packets[0].data(),packets[0].size(),b)&&parsed.decodedFrames()==0,"byte-stream parser keeps one frame");
+ require(parsed.push(packets[1].data(),packets[1].size(),b)&&parsed.decodedFrames()==1536,"byte-stream parser emits after next header");
+ std::cout<<"FRAMED "<<avcodec_get_name(codec)<<" immediateFrames="<<direct.decodedFrames()<<" parserFirst=0 parserSecond="<<parsed.decodedFrames()<<" samplesPerFrame=1536 rate=48000\n";
+ std::vector<uint8_t> joined;for(size_t n=0;n<6;++n)joined.insert(joined.end(),packets[n].begin(),packets[n].end());
+ sink::BitstreamDecoder aggregate;require(aggregate.open(kind),"aggregate decoder");a.clear();
+ require(aggregate.pushFramed(joined.data(),joined.size(),a),"complete multi-frame packet accepted");
+ std::cout<<"AGGREGATE "<<avcodec_get_name(codec)<<" frames="<<aggregate.decodedFrames()<<" expected="<<1536*6<<'\n';
+ require(aggregate.decodedFrames()==1536*6&&a.size()==1536*6*6,"every frame in complete aggregate decoded");
+ if(codec==AV_CODEC_ID_EAC3){
+ uint64_t frames=0;source::AverMediaAudioCarrier grouped([&](const source::VendorPcmBlock& block){frames+=block.frames;return true;});
+ const auto wire=burst(joined,0x15);
+ require(grouped.feed(wire,{2,16,48000},0)&&grouped.feed(wire,{2,16,48000},.2),"EAC3 multi-frame IEC bursts");
+ require(frames==1536*6,"EAC3 carrier does not discard aggregate tail");
+ }
+ uint8_t byte=0;require(!direct.pushFramed(&byte,size_t(INT_MAX)+1,a),"oversized framed packet rejected before allocation");
+ require(!direct.pushFramed(nullptr,1,a),"null non-empty framed packet rejected");
+ }
using source::avermedia::DeviceInfo;
const std::wstring video=L"\\\\?\\usb#vid_07ca&pid_2553&mi_00#5&abc&0&0000#{guid}";
const std::wstring audio=L"\\\\?\\usb#vid_07ca&pid_2553&mi_02#5&abc&0&0002#{guid}";
diff --git a/tests/unit/AverMediaPassthroughTests.cpp b/tests/unit/AverMediaPassthroughTests.cpp
new file mode 100644
index 00000000..b22a27a1
--- /dev/null
+++ b/tests/unit/AverMediaPassthroughTests.cpp
@@ -0,0 +1,48 @@
+#include "veyra/source/AverMediaAudioSwitch.h"
+#include <windows.h>
+#include <filesystem>
+#include <fstream>
+#include <iostream>
+#include <stdexcept>
+namespace {unsigned checks=0;void require(bool value,const char* text){++checks;if(!value)throw std::runtime_error(text);}}
+int wmain(int argc,wchar_t** argv){try{
+ require(argc==4,"usage: sdk.dll test-root complete|no-get|no-set");
+ const auto root=std::filesystem::absolute(argv[2]);const std::wstring variant=argv[3];
+ std::filesystem::create_directories(root/L"obs-plugins/64bit");std::filesystem::create_directories(root/L"data/obs-plugins/AVerMediaMultichannelAudio");
+ const auto dll=root/L"obs-plugins/64bit/avt_device_opener.dll";
+ std::filesystem::copy_file(argv[1],dll,std::filesystem::copy_options::overwrite_existing);
+ for(auto name:{L"RTICE_SDK_x64.dll",L"RTK_IO_x64.dll"})std::ofstream(root/L"data/obs-plugins/AVerMediaMultichannelAudio"/name).put('\0');
+ SetEnvironmentVariableW(L"VEYRA_AVERMEDIA_COMPONENT",root.c_str());
+ const auto module=LoadLibraryExW(dll.c_str(),nullptr,LOAD_LIBRARY_SEARCH_DLL_LOAD_DIR|LOAD_LIBRARY_SEARCH_DEFAULT_DIRS);require(module!=nullptr,"load own SDK fixture");
+ auto config=reinterpret_cast<void(*)(int,int,int,int,int)>(GetProcAddress(module,"FakeConfigure"));
+ 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");
+ require(audio.sourceIsBitstream(),"negative sign-extended format low byte is non-PCM");
+ audio.alignPassthroughOnce();
+ if(variant==L"no-get"){
+ require(!audio.status().passthroughKnown&&count(0)==0,"missing query must not force already-armed hardware");
+ require(!audio.setPassthrough(true)&&count(0)==0,"explicit enable cannot bypass unknown query");
+ }else if(variant==L"no-set"){
+ require(audio.status().passthroughKnown&&!audio.passthroughEnabled(),"read-only component still reports state");
+ require(!audio.setPassthrough(true)&&count(0)==0,"missing setter leaves mode unchanged");
+ }else{
+ require(variant==L"complete","known variant");
+ require(count(0)==1&&audio.status().passthroughKnown&&audio.passthroughEnabled(),"off is armed once and read back");
+ 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");
+ config(2,0,0,0,1);require(!audio.sourceIsBitstream(),"PCM classification remains PCM");
+ config(-236,1,1,0,1);audio.alignPassthroughOnce();require(!audio.status().passthroughKnown&&count(0)==0,"failed query clears stale state and never forces");
+ config(-236,0,2,0,1);require(!audio.setPassthrough(true)&&count(0)==0,"unreachable chip cannot be forced");
+ config(-236,0,3,0,1);audio.alignPassthroughOnce();require(!audio.status().passthroughKnown&&count(0)==0,"query SEH handled without forcing");
+ config(-236,0,0,1,1);require(!audio.setPassthrough(true)&&!audio.passthroughEnabled(),"setter failure not marked enabled");
+ config(-236,0,0,0,0);require(!audio.setPassthrough(true)&&!audio.passthroughEnabled(),"successful write needs actual readback");
+ config(-236,0,0,0,1);require(audio.setPassthrough(true)&&audio.passthroughEnabled(),"query/write can recover after failure");
+ const auto initialized=count(2);audio.stop();require(!audio.status().sdkReady&&!audio.status().passthroughKnown,"stop invalidates SDK/readback state");
+ require(audio.apply(name,path)&&count(2)==initialized+1,"stopped object can initialize same card again");
+ }
+ audio.stop();SetEnvironmentVariableW(L"VEYRA_AVERMEDIA_COMPONENT",nullptr);FreeLibrary(module);
+ std::cout<<"PASS "<<checks<<" passthrough ABI checks\n";return 0;
+}catch(const std::exception& e){std::cerr<<"FAIL "<<e.what()<<" after "<<checks<<" checks\n";return 1;}}