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: negotiate low-latency capture audio blocks and log ingress timing

Veyra Goal Agent79734ff51f14
diff --git a/docs/CAPTURE_AUDIO_LATENCY_2026-09-13.md b/docs/CAPTURE_AUDIO_LATENCY_2026-09-13.md
new file mode 100644
index 00000000..ac5c27be
--- /dev/null
+++ b/docs/CAPTURE_AUDIO_LATENCY_2026-09-13.md
@@ -0,0 +1,43 @@
+# 采集卡音频高延迟排查与修复
+
+用户反馈:同一采集卡在 OBS 正常,Veyra 音频延迟明显。未收到反馈者日志、增强设置或实际延迟测量,不能断言单一根因已经在其设备复现。开工存档 `checkpoint/capture-audio-latency-20260913`。保留工作区先前的缓存清理记录。
+
+## 已确认的实现缺口
+
+`CaptureCardSource` 在音频输出 pin 上直接 ConnectDirect,未调用 IAMBufferNegotiation。`NativeCaptureSink` 音频 allocator 仅要求一个 PCM sample 的最小字节数,未提供有效的实时块长要求。驱动可能按其默认大块交付,软件收到数据前就已经发生批量等待。
+
+OBS 的 libdshowcapture 固定提交 `c13d4b7b0c66979396ba0a9060c9aafc15bb7b22`,`source/device.cpp` 的 SetAudioBuffering 在连接前调用 SuggestAllocatorProperties,普通设备默认请求10ms;有设备兼容例外。这是公开 API 调用方式参考,本次不复制其实现。
+
+- [OBS 实现](https://github.com/obsproject/libdshowcapture/blob/c13d4b7b0c66979396ba0a9060c9aafc15bb7b22/source/device.cpp)
+- [Microsoft 缓冲协商](https://learn.microsoft.com/en-us/windows/win32/api/strmif/nf-strmif-iambuffernegotiation-suggestallocatorproperties):须在连接前调用,建议值不保证驱动遵守。
+- [Microsoft Live Sources](https://learn.microsoft.com/en-us/windows/win32/directshow/live-sources):音频与视频来源可能有不同缓冲延迟;相同采集设备不保证两者缓冲相同。
+
+WASAPI 当前请求10ms共享事件缓冲,实际大小由设备决定;1500ms自动同步、2000ms PCM是上限,不是每次固定插入的延迟。自动补偿基于视频呈现时间/PTS和音频到达映射,不能用它消除驱动在交付PCM前的等待。继续保留正常播放的连续重采样,不因未取得的日志猜测而整体重写同步。
+
+## 本次范围
+
+1. 连接音频前按协商格式请求帧对齐的10ms PCM块,驱动不支持/拒绝时明确日志并继续兼容连接。
+2. 音频接收器给出一致的10ms allocator要求,记录实际allocator容量;视频allocator不变。
+3. 记录实际收到的PCM块时长、回调间隔和数量,与补偿、PCM队列、输出端队列同时输出,区分采集交付慢与软件堆积。
+4. 使用产品接收器/COM协商测试、真实WASAPI合成PCM回归和完整构建验证。单次测试低于300秒,不抢占用户设备、不宣称实卡声学验证。
+
+## 验证记录
+
+待追加。本次不发布新Release,不改已发布1.0.0资产,不修改SDK或运行时。
+
+## 本轮实际结果
+
+- 先只修改产品接收器的10ms要求断言,旧实现测试32 PASS / 1 FAIL,contract-before.log,失败点正是旧cbBuffer=4而非1920。它证明合同缺口,不能冒充实卡500ms复现。
+- 完整增量构建100步通过:cmd.exe /c out\gpu-dis-build-all.cmd,build-after.log。最初使用out/xxx.cmd的cmd路径被当作命令out拒绝,改为Windows反斜杠后正常;未改变编译器或运行时。
+- 使用scripts/run-short-test.ps1包装产品测试,contract-after 38 PASS;覆盖上游接口缺失、请求成功、驱动拒绝后的兼容连接、48k16bit/32bit及11025采样率的帧对齐请求,实际COM内存allocator及PCM输入。mock返回0x80004002/0x80004005/0均如实日志,非物理驱动验证。
+- veyra_capture_audio_tests.exe --software-delay,60s外部上限,16 PASS:80/160/400/900ms软件延迟与900ms共同输入偏移,后者没有重复计入补偿;手动/关闭、重锚、断流和队列边界通过。mode off/手动负值及刻意断流中有underrun计数,不宣称所有模式无缺音。
+- --jitter,30s外部上限,5秒真实WASAPI合成PCM:additionalResets=0、additionalUnderruns=0、missing=0、p95SkewMs=29.4802,实际inputBlocks=500、inputBlockMs=10、inputIntervalMs=9.8056。视频延迟30/35ms交替;这不是扬声器到屏幕测量。
+- --endpoint-loss,30s外部上限,PASS;重连2次,平均软件偏差9.61721ms,无overflow/underrun。
+- scripts/gates/delivery.ps1 -Root . -BuildDirectory out/remoteplay/product-repair:23/23 PASS,53.123279秒,logs/delivery/c7ecf48ee7ae44a99cc3eb6f971d61fc/result.json。真实NR Init/Create Feature18 result=0x1、handle非空、seh=0,含NVOF/4K/呈现和导出检查,不是实卡音频验收。
+- 当前EXE SHA256 B847BFAA3440548C8494DB5DE90280BAB76609DB5B5DECCFF3ABB0870C6DB89A;patched avcodec SHA256仍0710F0D87A7FFCC9F998F1A35D0500345F6C66EB9A5A39C51D60D293142BD84F。
+
+证据统一位于logs/capture-audio-latency-20260913/。修改NativeCaptureSink(.h/.cpp)、CaptureCardSource.cpp、CaptureAudioSession(.h/.cpp)、CaptureColorContractTests.cpp、CaptureAudioTests.cpp及本记录/WORKLOG;不修改实际音频补偿、重采样、呈现/FG调度。没有SDK/runtime修改或新增。仅本地修复,无push或Release资产更新。
+
+## 待反馈者验收
+
+仍缺反馈者日志、使用设置、音频来源以及同源OBS/本程序的声学测量。请求10ms不等于端到端10ms,也不保证每个驱动遵守;实际allocator容量、inputBlockMs/inputIntervalMs与compensationMs/pcmMs/endpointMs/skewMs应一起判断。如小块已生效仍延迟大,下一步按日志区分软件补偿、PCM堆积、输出设备固定延迟及采集音视频PTS差异,不能继续盲目减小同步上限或停声音。反馈者所下载的公开1.0.0尚未包含此修复。
diff --git a/docs/WORKLOG.md b/docs/WORKLOG.md
index a9e2c3c0..ea551503 100644
--- a/docs/WORKLOG.md
+++ b/docs/WORKLOG.md
@@ -1858,3 +1858,19 @@ GitHub Release https://github.com/Likely7/Veyra-NRVideo/releases/tag/v1.0.0 于
## 2026-09-13 README 项目来源与致谢
按用户要求,在中英文 README 最底部补齐实际集成/复用、架构与实现参考、已搁置 AMD NR 调研来源及各项目链接。依据 THIRD_PARTY_NOTICES、GPU DIS provenance、竞品/性能/采集审计与质量/AMD NR 方案核对,区分依赖和研究,不把尚未接入的算法宣传为现有功能。保留完整许可证及对应源码入口。仅文档改动,执行 Markdown 本地链接与双语项目 URL 一致性检查、git diff --check;无需重建或改动 1.0.0 包与标签。
+
+## 2026-09-13 本地缓存与重复产物清理
+
+用户授权检查并清理项目缓存。清理前扫描24.758GiB,执行out/cleanup-20260913.ps1预览和-Apply后移除1833个目标、12.656GiB,失败0;复扫12.103GiB。路径均解析为项目内out/logs,预检Git无跟踪文件、无重解析点、无正在运行的目标EXE。安全预览脚本首次祖先遍历未终止,已终止预览进程并修正为显式GetDirectoryName/Get-Item逐级验证;此前未发生删除。最终预览约3秒、清理约9秒。
+
+删除:out/build旧构建;旧Release展开目录、0.0.2候选、1.0.0首轮候选ZIP(保留该目录内正式FFmpeg源码ZIP);1.0.0最终包重复展开/验证目录;release-audit/package与旧audit/P1 build;RemotePlay关闭功能的验证构建;logs/delivery、optimization-goal-20260908、phase5中的合成PNG/JPG/MP4/partial/bin。对应.log/.json、测试源码保留;delivery的92e09ba3556148a9b9275d2ba1ef1bfe及ca204954e1e64ee4aeddf7a41cf5f1e6整轮产物保留。历史文档中指向已清理旧二进制/图片的路径不再存在,不代表重新测试或修改旧结论。
+
+保留:当前out/remoteplay/product-repair完整构建与桌面快捷方式目标、chiaki-msvc-stage、SDK/模型/runtime_local、Git历史、源代码、真实captures、loop/local回归输入、正式1.0.0三个ZIP及旧最终版本ZIP备份。清理没有访问用户数据目录中的PS5配对/PSN凭据。当前构建仍使用外部C:/veyra-deps依赖,不退回stock FFmpeg。
+
+验证:当前EXE、patched avcodec-63.dll和1.0.0 portable/RemotePlay-source/FFmpeg-source ZIP逐项SHA256与清理前相同;current CMakeCache、chiaki stage、最终delivery result存在;清理后git status无变更(本记录落盘前)、git diff --check通过。未运行产品或重新构建,因为没有改动产品文件。详细清单及哈希位于logs/cleanup-20260913/{plan.json,result.json,protected-before.json,after-size.json},仅本地保存。旧out/build路径需重新配置/构建后才能使用,后续开发优先使用保留的out/remoteplay/product-repair。未修改GitHub Release资产。
+
+## 2026-09-13 采集卡音频高延迟排查
+
+用户反馈OBS音频正常、Veyra延迟高。确认产品音频ConnectDirect前缺少IAMBufferNegotiation,音频sink仅请求1个sample最小字节。参考OBS libdshowcapture固定c13d4b7及Microsoft API,独立增加连接前10ms帧对齐请求、失败兼容继续、实际allocator容量日志;新增实际inputBlockMs/inputIntervalMs/inputBlocks诊断,不改自动补偿和音频重采样。不能推定反馈者驱动确实500ms,未取得其日志/实卡听测。
+
+开工tag checkpoint/capture-audio-latency-20260913。旧产品合同32 PASS/1 FAIL验证缺口;修后38 PASS,完整构建100步成功;合成PCM+真实WASAPI同步16 PASS、抖动5秒additionalReset/underrun/missing全0、设备恢复PASS。delivery 23/23、53.123279秒,logs/delivery/c7ecf48ee7ae44a99cc3eb6f971d61fc/result.json,NR实际Create/Evaluate成功、SEH0。当前EXE B847BFAA3440548C8494DB5DE90280BAB76609DB5B5DECCFF3ABB0870C6DB89A,FFmpeg slice补丁DLL哈希不变。详细命令、失败、修改文件与验证边界见docs/CAPTURE_AUDIO_LATENCY_2026-09-13.md和logs/capture-audio-latency-20260913/。未修改发布包、SDK或运行时,无push。下一步反馈者新版实卡测试与日志,10ms请求不是总延迟承诺。
diff --git a/include/veyra/sink/CaptureAudioSession.h b/include/veyra/sink/CaptureAudioSession.h
index 2cac0df4..e53fcae6 100644
--- a/include/veyra/sink/CaptureAudioSession.h
+++ b/include/veyra/sink/CaptureAudioSession.h
@@ -10,6 +10,8 @@ struct CaptureAudioState {
bool available=false,running=false,clockEstimated=true,limited=false;
double compensationMs=0,bufferedMs=0,bufferHighWaterMs=0,endpointBufferedMs=0;
double driftCorrectionPpm=0;
+ double inputBlockMs=0,inputIntervalMs=0;
+ uint64_t inputBlocks=0;
std::optional<double> skewMs;
uint64_t resets=0,overflows=0,underruns=0,endpointRetries=0;
std::wstring error;
diff --git a/include/veyra/source/NativeCaptureSink.h b/include/veyra/source/NativeCaptureSink.h
index 87edf05d..fea12b0d 100644
--- a/include/veyra/source/NativeCaptureSink.h
+++ b/include/veyra/source/NativeCaptureSink.h
@@ -1,6 +1,7 @@
#pragma once
#include <windows.h>
#include <dshow.h>
+#include <mmreg.h>
#include <wrl/client.h>
#include <functional>
namespace veyra::source {
@@ -8,4 +9,7 @@ namespace veyra::source {
// restriction, conversion filter or extra queue. Callback borrows the sample.
HRESULT createNativeCaptureSink(const AM_MEDIA_TYPE&,std::function<HRESULT(IMediaSample*)>,Microsoft::WRL::ComPtr<IBaseFilter>&,Microsoft::WRL::ComPtr<IPin>&);
HRESULT createNativeAudioSink(const AM_MEDIA_TYPE&,std::function<HRESULT(IMediaSample*)>,Microsoft::WRL::ComPtr<IBaseFilter>&,Microsoft::WRL::ComPtr<IPin>&);
+// Advisory request on the upstream output pin, before ConnectDirect. Failure
+// does not invalidate the device; callers retain the compatible connection.
+HRESULT suggestCaptureAudioBuffering(IPin*,const WAVEFORMATEX&);
}
diff --git a/src/sink/CaptureAudioSession.cpp b/src/sink/CaptureAudioSession.cpp
index ecaaab1e..f33082f0 100644
--- a/src/sink/CaptureAudioSession.cpp
+++ b/src/sink/CaptureAudioSession.cpp
@@ -225,7 +225,7 @@ struct CaptureAudioSession::Impl : AudioPcmSource {
state.skewMs=fresh&&std::isfinite(audioPts)?std::optional<double>(audioPts-(vPts+observedNow-vHost)):std::nullopt;
if(hostTime()>=nextSyncLog){
nextSyncLog=hostTime()+20000000;
- log::info("live-audio-sync",std::format("videoPtsMs={:.3f} videoHostMs={:.3f} audioIngressMapMs={:.3f} compensationMs={:.3f} pcmMs={:.3f} endpointMs={:.3f} skewMs={:.3f} correctionPpm={:.1f} resets={} (local clock alignment, not GPU execution time)",vPts,vHost,ingress,target,state.bufferedMs,state.endpointBufferedMs,state.skewMs.value_or(-999),state.driftCorrectionPpm,state.resets));
+ log::info("live-audio-sync",std::format("videoPtsMs={:.3f} videoHostMs={:.3f} audioIngressMapMs={:.3f} compensationMs={:.3f} pcmMs={:.3f} endpointMs={:.3f} skewMs={:.3f} correctionPpm={:.1f} resets={} inputBlockMs={:.3f} inputIntervalMs={:.3f} inputBlocks={} (local clock alignment, not GPU execution time)",vPts,vHost,ingress,target,state.bufferedMs,state.endpointBufferedMs,state.skewMs.value_or(-999),state.driftCorrectionPpm,state.resets,state.inputBlockMs,state.inputIntervalMs,state.inputBlocks));
}
}
}
@@ -255,7 +255,10 @@ bool CaptureAudioSession::push(const void* data,size_t bytes,double pts,bool dis
std::lock_guard lock(p.mutex);
if(p.stop||!p.state.error.empty())return true;
if(discontinuity){p.input.clear();p.inputBytes=0;p.pendingReset=true;p.haveVideo=false;}
- p.lastArrival=hostTime();
+ const auto arrival=hostTime();
+ p.state.inputIntervalMs=p.state.inputBlocks&&!discontinuity?double(arrival-p.lastArrival)/10000:0;
+ p.state.inputBlockMs=1000.0*bytes/p.format.nAvgBytesPerSec;++p.state.inputBlocks;
+ p.lastArrival=arrival;
if(!p.haveIngress||discontinuity){p.ingressClock.reset();p.haveIngress=true;}
p.ingressMapping=p.ingressClock.observe(double(p.lastArrival)/10000,pts);
const double blockMs=1000.0*bytes/p.format.nAvgBytesPerSec;
diff --git a/src/source/CaptureCardSource.cpp b/src/source/CaptureCardSource.cpp
index 0bdf6dff..d0ba0e2c 100644
--- a/src/source/CaptureCardSource.cpp
+++ b/src/source/CaptureCardSource.cpp
@@ -155,6 +155,10 @@ bool CaptureCardSource::configure(const SourceOpenDesc& desc){close();p_->lastAu
return target->push(bytes,size_t(sample->GetActualDataLength()),double(begin)/10000,sample->IsDiscontinuity()==S_OK)?S_OK:E_FAIL;
},candidate,terminal);
if(SUCCEEDED(hr))hr=p.graph->AddFilter(candidate.Get(),L"Veyra audio PCM");
+ // Request small input blocks before connection; downstream
+ // playback cannot undo time spent filling a driver buffer.
+ // Some devices reject this advisory API, so do not fail capture.
+ if(SUCCEEDED(hr))suggestCaptureAudioBuffering(audioPin.Get(),*reinterpret_cast<const WAVEFORMATEX*>(type->pbFormat));
if(SUCCEEDED(hr))hr=p.graph->ConnectDirect(audioPin.Get(),terminal.Get(),type);
if(SUCCEEDED(hr)){p.audioSink=candidate;p.audioSession=std::move(session);connectedAudio=true;}
else if(candidate)p.graph->RemoveFilter(candidate.Get());
diff --git a/src/source/NativeCaptureSink.cpp b/src/source/NativeCaptureSink.cpp
index 5abf965d..af105507 100644
--- a/src/source/NativeCaptureSink.cpp
+++ b/src/source/NativeCaptureSink.cpp
@@ -10,6 +10,10 @@
namespace veyra::source {
using Microsoft::WRL::ComPtr;
namespace {
+LONG audioBlockBytes(const WAVEFORMATEX& f){
+ // Round up to whole sample frames, including uncommon rates such as 11025.
+ return LONG(((uint64_t(f.nSamplesPerSec)+99)/100)*f.nBlockAlign);
+}
void clearType(AM_MEDIA_TYPE& t){CoTaskMemFree(t.pbFormat);if(t.pUnk)t.pUnk->Release();t={};}
HRESULT copyType(AM_MEDIA_TYPE& dst,const AM_MEDIA_TYPE& src){
dst=src;dst.pbFormat=nullptr;dst.pUnk=nullptr;
@@ -110,8 +114,19 @@ public:
HRESULT STDMETHODCALLTYPE EndFlush()override{std::lock_guard lock(mutex_);flushing_=false;return S_OK;}
HRESULT STDMETHODCALLTYPE NewSegment(REFERENCE_TIME,REFERENCE_TIME,double)override{return S_OK;}
HRESULT STDMETHODCALLTYPE GetAllocator(IMemAllocator** p)override{if(!p)return E_POINTER;std::lock_guard lock(mutex_);if(!allocator_){const auto hr=CoCreateInstance(CLSID_MemoryAllocator,nullptr,CLSCTX_INPROC_SERVER,IID_PPV_ARGS(&allocator_));if(FAILED(hr))return hr;}return allocator_.CopyTo(p);}
- HRESULT STDMETHODCALLTYPE NotifyAllocator(IMemAllocator* p,BOOL)override{if(!p)return E_POINTER;std::lock_guard lock(mutex_);allocator_=p;return S_OK;}
- HRESULT STDMETHODCALLTYPE GetAllocatorRequirements(ALLOCATOR_PROPERTIES* p)override{if(!p)return E_POINTER;std::lock_guard lock(mutex_);*p={3,LONG(layout_.sampleBytes),1,0};return S_OK;}
+ HRESULT STDMETHODCALLTYPE NotifyAllocator(IMemAllocator* p,BOOL)override{
+ if(!p)return E_POINTER;std::lock_guard lock(mutex_);allocator_=p;
+ if(audio_){
+ ALLOCATOR_PROPERTIES actual{};const auto hr=p->GetProperties(&actual);
+ const auto& f=*reinterpret_cast<const WAVEFORMATEX*>(desired_.pbFormat);
+ log::info("capture-audio-buffer",std::format("actual allocator hr=0x{:08X} buffers={} bytes={} capacityPerBlockMs={:.3f} (capacity, not measured latency)",uint32_t(hr),actual.cBuffers,actual.cbBuffer,SUCCEEDED(hr)?1000.0*actual.cbBuffer/f.nAvgBytesPerSec:0.0));
+ }
+ return S_OK;
+ }
+ HRESULT STDMETHODCALLTYPE GetAllocatorRequirements(ALLOCATOR_PROPERTIES* p)override{
+ if(!p)return E_POINTER;std::lock_guard lock(mutex_);
+ *p={3,audio_?audioBlockBytes(*reinterpret_cast<const WAVEFORMATEX*>(desired_.pbFormat)):LONG(layout_.sampleBytes),1,0};return S_OK;
+ }
HRESULT STDMETHODCALLTYPE Receive(IMediaSample* sample)override{
if(!sample)return E_POINTER;std::lock_guard lock(mutex_);if(flushing_)return S_FALSE;if(state_==State_Stopped)return VFW_E_WRONG_STATE;
// A device mode change needs full source/graph recreation, never a
@@ -130,6 +145,21 @@ public:
HRESULT STDMETHODCALLTYPE ReceiveCanBlock()override{return S_OK;}
};
}
+HRESULT suggestCaptureAudioBuffering(IPin* pin,const WAVEFORMATEX& format){
+ if(!pin)return E_POINTER;
+ if(!format.nBlockAlign||format.nSamplesPerSec<8000||format.nSamplesPerSec>192000||format.nBlockAlign>8||
+ format.nAvgBytesPerSec!=uint64_t(format.nSamplesPerSec)*format.nBlockAlign)return E_INVALIDARG;
+ ComPtr<IAMBufferNegotiation> negotiation;
+ const auto queryHr=pin->QueryInterface(IID_PPV_ARGS(&negotiation));
+ if(FAILED(queryHr)){
+ log::warn("capture-audio-buffer",std::format("upstream buffer negotiation unavailable hr=0x{:08X}; retain driver defaults",uint32_t(queryHr)));
+ return queryHr;
+ }
+ const ALLOCATOR_PROPERTIES wanted{-1,audioBlockBytes(format),-1,-1};
+ const auto hr=negotiation->SuggestAllocatorProperties(&wanted);
+ log::info("capture-audio-buffer",std::format("upstream request bytes={} blockMs={:.3f} rate={} channels={} bits={} hr=0x{:08X} (advisory; actual callbacks logged separately)",wanted.cbBuffer,1000.0*wanted.cbBuffer/format.nAvgBytesPerSec,format.nSamplesPerSec,format.nChannels,format.wBitsPerSample,uint32_t(hr)));
+ return hr;
+}
HRESULT createNativeCaptureSink(const AM_MEDIA_TYPE& type,std::function<HRESULT(IMediaSample*)> callback,ComPtr<IBaseFilter>& filter,ComPtr<IPin>& pin){
filter.Reset();pin.Reset();CaptureMediaLayout layout;if(!captureMediaLayout(type,layout))return VFW_E_INVALIDMEDIATYPE;
try{filter.Attach(new NativeSink(type,std::move(callback)));return filter.As(&pin);}catch(...){return E_OUTOFMEMORY;}
diff --git a/tests/integration/CaptureAudioTests.cpp b/tests/integration/CaptureAudioTests.cpp
index 079efba8..6a93f087 100644
--- a/tests/integration/CaptureAudioTests.cpp
+++ b/tests/integration/CaptureAudioTests.cpp
@@ -42,8 +42,9 @@ int main(int argc,char** argv){
}
const auto s=audio.snapshot();audio.stop();std::sort(errors.begin(),errors.end());
const double p95=errors.empty()?999:errors[(errors.size()*95+99)/100-1];
- const bool pass=missing==0&&s.resets==settledResets&&s.underruns==settledUnderruns&&s.overflows==0&&p95<35;
- std::cout<<(pass?"PASS ":"FAIL ")<<"CAPTURE_JITTER additionalResets="<<s.resets-settledResets<<" additionalUnderruns="<<s.underruns-settledUnderruns<<" missing="<<missing<<" p95SkewMs="<<p95<<'\n';
+ const bool inputTelemetry=s.inputBlocks==500&&std::abs(s.inputBlockMs-10)<.001&&s.inputIntervalMs>=0&&s.inputIntervalMs<100;
+ const bool pass=inputTelemetry&&missing==0&&s.resets==settledResets&&s.underruns==settledUnderruns&&s.overflows==0&&p95<35;
+ std::cout<<(pass?"PASS ":"FAIL ")<<"CAPTURE_JITTER additionalResets="<<s.resets-settledResets<<" additionalUnderruns="<<s.underruns-settledUnderruns<<" missing="<<missing<<" p95SkewMs="<<p95<<" inputBlocks="<<s.inputBlocks<<" inputBlockMs="<<s.inputBlockMs<<" inputIntervalMs="<<s.inputIntervalMs<<'\n';
return pass?0:1;
}
if(driftTest){
diff --git a/tests/unit/CaptureColorContractTests.cpp b/tests/unit/CaptureColorContractTests.cpp
index 4729f8cf..bb6cb5ae 100644
--- a/tests/unit/CaptureColorContractTests.cpp
+++ b/tests/unit/CaptureColorContractTests.cpp
@@ -6,9 +6,12 @@
using namespace veyra;
using Microsoft::WRL::ComPtr;
// Minimal upstream peer: the production input pin must validate its direction.
-struct OutputPin final:IPin {
+struct OutputPin final:IPin,IAMBufferNegotiation {
std::atomic<ULONG> refs{1};
- HRESULT STDMETHODCALLTYPE QueryInterface(REFIID id,void** p)override{if(!p)return E_POINTER;*p=nullptr;if(id!=IID_IUnknown&&id!=IID_IPin)return E_NOINTERFACE;*p=this;AddRef();return S_OK;}
+ bool supportsBuffering=false;HRESULT bufferResult=S_OK;unsigned suggestions=0;ALLOCATOR_PROPERTIES suggested{};
+ HRESULT STDMETHODCALLTYPE QueryInterface(REFIID id,void** p)override{if(!p)return E_POINTER;*p=nullptr;if(id==IID_IUnknown||id==IID_IPin)*p=static_cast<IPin*>(this);else if(id==IID_IAMBufferNegotiation&&supportsBuffering)*p=static_cast<IAMBufferNegotiation*>(this);else return E_NOINTERFACE;AddRef();return S_OK;}
+ HRESULT STDMETHODCALLTYPE SuggestAllocatorProperties(const ALLOCATOR_PROPERTIES* p)override{if(!p)return E_POINTER;suggested=*p;++suggestions;return bufferResult;}
+ HRESULT STDMETHODCALLTYPE GetAllocatorProperties(ALLOCATOR_PROPERTIES* p)override{if(!p)return E_POINTER;*p=suggested;return S_OK;}
ULONG STDMETHODCALLTYPE AddRef()override{return ++refs;}ULONG STDMETHODCALLTYPE Release()override{auto n=--refs;if(!n)delete this;return n;}
HRESULT STDMETHODCALLTYPE Connect(IPin*,const AM_MEDIA_TYPE*)override{return E_NOTIMPL;}
HRESULT STDMETHODCALLTYPE ReceiveConnection(IPin*,const AM_MEDIA_TYPE*)override{return E_NOTIMPL;}
@@ -75,11 +78,21 @@ int main(){
WAVEFORMATEX wave{};wave.wFormatTag=WAVE_FORMAT_PCM;wave.nChannels=2;wave.nSamplesPerSec=48000;wave.wBitsPerSample=16;wave.nBlockAlign=4;wave.nAvgBytesPerSec=192000;
AM_MEDIA_TYPE audio{};audio.majortype=MEDIATYPE_Audio;audio.subtype=MEDIASUBTYPE_PCM;audio.formattype=FORMAT_WaveFormatEx;audio.cbFormat=sizeof(wave);audio.pbFormat=reinterpret_cast<BYTE*>(&wave);
output.Attach(new OutputPin);unsigned audioReceived=0;
+ auto* audioPeer=static_cast<OutputPin*>(output.Get());
+ check(source::suggestCaptureAudioBuffering(output.Get(),wave)==E_NOINTERFACE,"missing upstream negotiation reports fallback without requesting allocator");
+ audioPeer->supportsBuffering=true;
+ check(source::suggestCaptureAudioBuffering(output.Get(),wave)==S_OK&&audioPeer->suggestions==1&&audioPeer->suggested.cbBuffer==1920&&audioPeer->suggested.cBuffers==-1&&audioPeer->suggested.cbAlign==-1&&audioPeer->suggested.cbPrefix==-1,"upstream 48k stereo16 request is 10ms with driver-owned pool and alignment");
+ auto unusual=wave;unusual.nSamplesPerSec=11025;unusual.nAvgBytesPerSec=44100;
+ check(source::suggestCaptureAudioBuffering(output.Get(),unusual)==S_OK&&audioPeer->suggested.cbBuffer==444,"uncommon rate rounds up to whole PCM frames");
+ auto floatStereo=wave;floatStereo.wFormatTag=WAVE_FORMAT_IEEE_FLOAT;floatStereo.wBitsPerSample=32;floatStereo.nBlockAlign=8;floatStereo.nAvgBytesPerSec=384000;
+ check(source::suggestCaptureAudioBuffering(output.Get(),floatStereo)==S_OK&&audioPeer->suggested.cbBuffer==3840,"float stereo uses byte rate rather than hardcoded 1920 bytes");
+ audioPeer->bufferResult=E_FAIL;
+ check(source::suggestCaptureAudioBuffering(output.Get(),wave)==E_FAIL,"driver rejection is visible to diagnostics");
check(SUCCEEDED(source::createNativeAudioSink(audio,[&](IMediaSample*){++audioReceived;return S_OK;},filter,input)),"create shared native PCM terminal");
- check(filter&&SUCCEEDED(filter.As(&memory))&&input->ReceiveConnection(output.Get(),&audio)==S_OK,"PCM format is accepted explicitly");
+ check(filter&&SUCCEEDED(filter.As(&memory))&&input->ReceiveConnection(output.Get(),&audio)==S_OK,"PCM connection remains supported after rejected advisory request");
wave.nSamplesPerSec=44100;wave.nAvgBytesPerSec=176400;check(input->QueryAccept(&audio)==S_FALSE,"audio rate change requires reconnect");wave.nSamplesPerSec=48000;wave.nAvgBytesPerSec=192000;
ALLOCATOR_PROPERTIES audioWanted{},audioActual{};
- check(memory->GetAllocatorRequirements(&audioWanted)==S_OK&&audioWanted.cbBuffer==4,"audio allocator retains frame alignment after connection");
+ check(memory->GetAllocatorRequirements(&audioWanted)==S_OK&&audioWanted.cbBuffer==1920&&audioWanted.cbBuffer%wave.nBlockAlign==0,"audio allocator requests aligned 10ms blocks instead of a single sample");
audioWanted.cbBuffer=1920;
bool audioReady=memory->GetAllocator(&allocator)==S_OK&&allocator->SetProperties(&audioWanted,&audioActual)==S_OK&&allocator->Commit()==S_OK;
check(audioReady,"PCM allocator initialized");