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++

feat(capture): N4 video-pin buffer negotiation with honest requested/actual reporting

Veyra Goal Agent345d42a1e797
diff --git a/AGENTS.md b/AGENTS.md
index db2d32a0..a29b357e 100644
--- a/AGENTS.md
+++ b/AGENTS.md
@@ -6,6 +6,8 @@
> 2026-09-16 用户授权合并到 main:隔离分支 `codex/framegen-fsr-dolby-20260916`(tip `ad7442d`)已合并(merge `24e7de7`)。存档 tag:合并前 `checkpoint/pre-merge-framegen-20260916`(main `87ad4cd`)、分支 tip `checkpoint/framegen-fsr-dolby-branch-tip-20260916`、合并后 `checkpoint/merged-framegen-20260916`;分支保留不删。冲突统一取分支原版实现,main 侧 RGB24 移植 `87ad4cd` 被 `015f8a4` 取代(其说明文档保留)。**未推送、未发布;push/Release 仍需当前对话明确授权。** N1–N4 本体未开工;40/30 系、真实位流卡与 AMD/Intel 导出实机验收仍待用户。
+> 2026-09-16 用户授权开启采集链路优化(新隔离分支):从 main `2406f81` 开 `codex/capture-decode-latency-20260916`(tag `checkpoint/pre-capture-decode-latency-20260916`),按 `docs/CAPTURE_DECODE_LATENCY_PLAN_2026-09-16.md` 施工:压缩解码架构(压缩直连 → D3D12VA 硬解 → MJPEG 并行软解)与原生 N1–N4(N4 缓冲协商 → N3 格式排序 → N1 逐像素转 GPU → N2 拷贝合并)。全部在隔离区,人工验收合格前不得合并 main;N1 必须保留 RGB24 方向契约(`015f8a4`)。真机验收用本机 USB3 卡 + 受影响用户;未生效的优化不得计入收益。
+
> 2026-09-14 用户授权实施 HDR 全增强与文件/采集 5.1,PS5 串流真实多声道不在本次范围。按 docs/HDR_ALL_EFFECTS_MULTICHANNEL_RESEARCH_PLAN_2026-09-14.md 施工,经过显式颜色合同扩展旧 SDR 边界;HDR 基底保留合成不宣称 NR 模型原生 HDR 推理。默认效果全关、共享处理图、直接 NGX、现有运行组件身份及 patched FFmpeg 保持。未授权新发布。
> 2026-09-14 用户授权发布1.1.1到Likely7/Veyra-NRVideo,包含RTX30 NR实验选项和首次效果全关。发布范围新增用户已指定的NeuralScreen1.8.2 NR原件:DCC0DC2414AEDEC4A8E084647070383BE068554042587180C20C784D4772D36F / 165840496 bytes / 310.8.0.0 / HashMismatch,独立放在Release的runtime/experimental/nr-ampere/,逐文件manifest记录;原七组件与patched FFmpeg沿用。此授权扩展上次仅本地范围,不允许修改DLL或进入源码Git。RTX30实卡尚未验收,不能宣称全型号成功。更新双语README、完整便携包和对应源码;本轮未请求关机。
diff --git a/apps/veyra/ui/AppShell.cpp b/apps/veyra/ui/AppShell.cpp
index 9f42128d..3e51aa15 100644
--- a/apps/veyra/ui/AppShell.cpp
+++ b/apps/veyra/ui/AppShell.cpp
@@ -60,7 +60,7 @@ std::wstring smokeView;bool smokeViewApplied=false;
std::wstring smokeDualOutput;bool smokeEmpty=false;DWORD modeGdiStart=0,modeHandlesStart=0;SIZE_T modePrivateStart=0;
bool smokeDual=false,smokeDualPause=false,smokeMaster=false,smokeMasterReject=false,smokeAudio=false,smokeJob=false,smokeJobCancel=false,smokeJobExit=false;int dualStep=0,masterStep=0,audioStep=0,jobStep=0;double pausedPosition=-1,jobPosition=0;uint64_t pausedFrames=0;ULONGLONG jobPauseTick=0;HANDLE workerMapping=nullptr;
void switchMode();void selectInspector(int);void refreshDailyPresets();
-bool applySettings(veyra::engine::EnhancementSettings s){if(masterPendingRevision)return false;uiState.configured=s;if(uiState.enhanced)engine.requestSettings(s);else {auto effective=engine.snapshot().desired;if(effective.captureCompatible!=s.captureCompatible||effective.forceSdrPreview!=s.forceSdrPreview||effective.captureFlipVertical!=s.captureFlipVertical){effective.captureCompatible=s.captureCompatible;effective.forceSdrPreview=s.forceSdrPreview;effective.captureFlipVertical=s.captureFlipVertical;engine.requestSettings(effective);}veyra::log::info("ui-settings","enhancement off: draft saved; presentation setting applied independently");}veyra::ui::settingsEnabled(uiState.enhanced,uiState.configured);return true;}
+bool applySettings(veyra::engine::EnhancementSettings s){if(masterPendingRevision)return false;uiState.configured=s;if(uiState.enhanced)engine.requestSettings(s);else {auto effective=engine.snapshot().desired;if(effective.captureCompatible!=s.captureCompatible||effective.forceSdrPreview!=s.forceSdrPreview||effective.captureFlipVertical!=s.captureFlipVertical||effective.captureBuffer!=s.captureBuffer){effective.captureCompatible=s.captureCompatible;effective.forceSdrPreview=s.forceSdrPreview;effective.captureFlipVertical=s.captureFlipVertical;effective.captureBuffer=s.captureBuffer;engine.requestSettings(effective);}veyra::log::info("ui-settings","enhancement off: draft saved; presentation setting applied independently");}veyra::ui::settingsEnabled(uiState.enhanced,uiState.configured);return true;}
struct ToolbarItem{HWND hwnd;int width;};std::vector<ToolbarItem> toolbar;
bool full=false,holdOriginal=false,referenceBase=false;int compareMode=0;float compareSplit=.5f;WINDOWPLACEMENT windowPlacement{sizeof(windowPlacement)};
@@ -587,7 +587,7 @@ case RemotePlay:veyra::ui::showRemotePlayPanel(hwnd,[](veyra::source::RemotePlay
}return result;
},[]{engine.stop();},[]{return remoteController.calibrate();});break;
#endif
-case Capture:case ProRailCapture:veyra::ui::showCapturePanel(hwnd,[](const std::wstring& path){openFile(path);layout();},[]{return (uiState.enhanced?engine.snapshot().desired:uiState.configured).forceSdrPreview;},[](bool enabled){auto s=uiState.enhanced?engine.snapshot().desired:uiState.configured;s.forceSdrPreview=enabled;return applySettings(s);},[]{return int((uiState.enhanced?engine.snapshot().desired:uiState.configured).captureAudio);},[](int mode){auto s=uiState.enhanced?engine.snapshot().desired:uiState.configured;s.captureAudio=static_cast<veyra::engine::CaptureAudioIngress>(std::clamp(mode,0,2));return applySettings(s);},[]{return (uiState.enhanced?engine.snapshot().desired:uiState.configured).captureFlipVertical;},[](bool enabled){auto s=uiState.enhanced?engine.snapshot().desired:uiState.configured;s.captureFlipVertical=enabled;return applySettings(s);});break;
+case Capture:case ProRailCapture:veyra::ui::showCapturePanel(hwnd,[](const std::wstring& path){openFile(path);layout();},[]{return (uiState.enhanced?engine.snapshot().desired:uiState.configured).forceSdrPreview;},[](bool enabled){auto s=uiState.enhanced?engine.snapshot().desired:uiState.configured;s.forceSdrPreview=enabled;return applySettings(s);},[]{return int((uiState.enhanced?engine.snapshot().desired:uiState.configured).captureAudio);},[](int mode){auto s=uiState.enhanced?engine.snapshot().desired:uiState.configured;s.captureAudio=static_cast<veyra::engine::CaptureAudioIngress>(std::clamp(mode,0,2));return applySettings(s);},[]{return (uiState.enhanced?engine.snapshot().desired:uiState.configured).captureFlipVertical;},[](bool enabled){auto s=uiState.enhanced?engine.snapshot().desired:uiState.configured;s.captureFlipVertical=enabled;return applySettings(s);},[]{return int((uiState.enhanced?engine.snapshot().desired:uiState.configured).captureBuffer);},[](int mode){auto s=uiState.enhanced?engine.snapshot().desired:uiState.configured;s.captureBuffer=static_cast<veyra::source::CaptureBufferMode>(std::clamp(mode,0,2));return applySettings(s);});break;
case Export:if(uiState.mode==veyra::ui::Mode::Professional)startVideoExport(false);break;
case Info:showDiagnostics=!showDiagnostics;layout();break;
}return 0;
@@ -790,7 +790,7 @@ int argc=0;auto argv=CommandLineToArgvW(GetCommandLineW(),&argc);for(int i=1;i<a
{
// --capture-flip: diagnostics/smoke only; the interactive path uses the
// capture panel checkbox and persists captureFlipVertical with presets.
- {int flipArgc=0;auto flipArgv=CommandLineToArgvW(GetCommandLineW(),&flipArgc);for(int i=1;i<flipArgc;++i)if(!_wcsicmp(flipArgv[i],L"--capture-flip"))initialOptions.settings.captureFlipVertical=true;LocalFree(flipArgv);}
+ {int flipArgc=0;auto flipArgv=CommandLineToArgvW(GetCommandLineW(),&flipArgc);for(int i=1;i<flipArgc;++i){if(!_wcsicmp(flipArgv[i],L"--capture-flip"))initialOptions.settings.captureFlipVertical=true;else if(!wcsncmp(flipArgv[i],L"--capture-buffer=",17)){const wchar_t* value=flipArgv[i]+17;if(!_wcsicmp(value,L"auto"))initialOptions.settings.captureBuffer=veyra::source::CaptureBufferMode::Auto;else if(!_wcsicmp(value,L"minimum"))initialOptions.settings.captureBuffer=veyra::source::CaptureBufferMode::Minimum;else if(!_wcsicmp(value,L"driver"))initialOptions.settings.captureBuffer=veyra::source::CaptureBufferMode::DriverDefault;}}LocalFree(flipArgv);}
int positionalArgc=0;auto positionalArgv=CommandLineToArgvW(GetCommandLineW(),&positionalArgc);std::wstring positional;
const wchar_t* valueFlags[]={L"--export-worker",L"--smoke-view",L"--smoke-dual-export",L"--smoke-seconds",L"--export-out",L"--max-frames",L"--cancel-after-ms",L"--smoke-save",L"--fg-multiplier",L"--capture-audio",L"--video-sr",L"--bitrate-mbps",L"--subtitle-primary",L"--subtitle-secondary",L"--subtitle-offset-ms",L"--subtitle-font-size"};
for(int i=1;i<positionalArgc;++i){const std::wstring a=positionalArgv[i];
diff --git a/apps/veyra/ui/CapturePanel.cpp b/apps/veyra/ui/CapturePanel.cpp
index 0cea3a32..546026aa 100644
--- a/apps/veyra/ui/CapturePanel.cpp
+++ b/apps/veyra/ui/CapturePanel.cpp
@@ -17,6 +17,7 @@ std::vector<source::CaptureDevice> videoDevices,audioDevices;
CapturePreferences remembered;
std::function<bool()> readSdr;std::function<bool(bool)> setSdr;std::function<int()> readAudioIngress;std::function<bool(int)> setAudioIngress;
std::function<bool()> readFlip;std::function<bool(bool)> setFlip;
+std::function<int()> readBuffer;std::function<bool(int)> setBuffer;
void rebuildAudioList(HWND h,int device){
SendDlgItemMessageW(h,3,CB_RESETCONTENT,0,0);SendDlgItemMessageW(h,3,CB_ADDSTRING,0,LPARAM(L"不监听音频"));
const bool videoSelected=device>=0&&size_t(device)<videoDevices.size();
@@ -43,7 +44,7 @@ void query(int device){if(busy)return;busy=true;queriedDevice=device;queryStarte
const std::wstring videoPath=device>=0&&size_t(device)<videoDevices.size()?videoDevices[size_t(device)].path:L"";
pending=std::async(std::launch::async,[device,videoPath]{CoInitializeEx(nullptr,COINIT_MULTITHREADED);Query result;result.device=device;try{if(device<0){result.video=source::CaptureCardSource::deviceDetails();result.audio=source::CaptureCardSource::deviceDetails(true);}else result.formats=videoPath.empty()?source::CaptureCardSource::formats(unsigned(device)):source::CaptureCardSource::formatsByPath(videoPath);}catch(...){}CoUninitialize();return result;});
}
-void arrange(){RECT r{};GetClientRect(window,&r);const int width=MulDiv(r.right,96,veyra::ui::layoutDpi(window));const int ys[]={0,44,114,184,412,412,14,84,344,154,254,224,294,478,448,512};for(int id=1;id<=15;++id){int x=id==5?width-152:16;int w=id==4?width-184:id==5?136:width-32;MoveWindow(GetDlgItem(window,id),dip(window,x),dip(window,ys[id]),dip(window,w),dip(window,(id<=3||id==10||id==13)?180:id==8?56:id==4||id==5?36:24),TRUE);}}
+void arrange(){RECT r{};GetClientRect(window,&r);const int width=MulDiv(r.right,96,veyra::ui::layoutDpi(window));const int ys[]={0,44,114,184,412,412,14,84,344,154,254,224,294,478,448,566,530,506};for(int id=1;id<=17;++id){int x=id==5?width-152:16;int w=id==4?width-184:id==5?136:width-32;MoveWindow(GetDlgItem(window,id),dip(window,x),dip(window,ys[id]),dip(window,w),dip(window,(id<=3||id==10||id==13||id==16)?180:id==8?56:id==4||id==5?36:24),TRUE);}}
LRESULT CALLBACK proc(HWND h,UINT msg,WPARAM wp,LPARAM lp){switch(msg){
case WM_CREATE:{window=h;font=makeFont(h);titleTheme(h);auto add=[&](const wchar_t* cls,const wchar_t* label,int id,DWORD style){auto c=CreateWindowExW(0,cls,label,WS_CHILD|WS_VISIBLE|style,0,0,1,1,h,HMENU(INT_PTR(id)),GetModuleHandleW(nullptr),nullptr);SendMessageW(c,WM_SETFONT,WPARAM(font),TRUE);themeControl(c);};
remembered=CapturePreferenceStore(runtime::localDataDirectory()).load();
@@ -56,13 +57,17 @@ case WM_CREATE:{window=h;font=makeFont(h);titleTheme(h);auto add=[&](const wchar
for(auto name:{L"自动:优先线性 PCM,必要时 Dolby/DTS 位流解码",L"强制线性 PCM(不接受 Dolby/DTS 位流)",L"位流优先:优先直通给功放(无直通时解码为 PCM)"})SendDlgItemMessageW(h,13,CB_ADDSTRING,0,LPARAM(name));
SendDlgItemMessageW(h,13,CB_SETCURSEL,WPARAM(std::clamp(readAudioIngress?readAudioIngress():0,0,2)),0);
add(L"BUTTON",L"画面上下翻转(采集画面倒置时勾选,立即生效)",15,BS_AUTOCHECKBOX|WS_TABSTOP);SendDlgItemMessageW(h,15,BM_SETCHECK,readFlip&&readFlip()?BST_CHECKED:BST_UNCHECKED,0);
+ add(L"COMBOBOX",L"",16,CBS_DROPDOWNLIST|WS_VSCROLL|WS_TABSTOP);add(L"STATIC",L"设备缓冲(变更需重连)",17,0);
+ for(auto name:{L"自动:1080p 及以下 2 帧,更高分辨率 3 帧",L"最小:1 帧缓冲(延迟最低,高负载可能丢帧)",L"驱动默认:不做建议,沿用设备自身设置"})SendDlgItemMessageW(h,16,CB_ADDSTRING,0,LPARAM(name));
+ SendDlgItemMessageW(h,16,CB_SETCURSEL,WPARAM(std::clamp(readBuffer?readBuffer():0,0,2)),0);
add(L"BUTTON",L"连接并开始观看",4,BS_PUSHBUTTON|WS_TABSTOP);marked(GetDlgItem(h,4));add(L"BUTTON",L"刷新设备",5,BS_PUSHBUTTON|WS_TABSTOP);
add(L"STATIC",L"视频输入设备",6,0);add(L"STATIC",L"设备实际支持的格式",7,0);add(L"STATIC",L"",8,0);add(L"STATIC",L"音频监听(仅采集所选输入,默认关闭)",9,0);
- installDialogHelp(h,{{15,L"给方向声明和实际画面不一致的采集卡用:常见于某些 RGB24 格式——设备在媒体类型里写的是底行在前,实际送来的却是顶行在前,于是画面上下颠倒。勾选后把采集画面上下翻转一次,立即生效;只影响本机采集预览、截图和从这里导出的画面,不改设备也不动其他格式。画面正常时不要勾选;换成不颠倒的格式后记得取消。"},{13,L"采集卡把 Dolby Atmos / Dolby Audio / DTS 以位流送来时,这里决定用哪条路。设备本身的音频格式不受影响;改这个要重新连接采集卡。自动优先 PCM,PCM 不可用时才走位流解码;位流优先则反过来:先尝试把位流原样直通给功放/回音壁(独占输出,卡不经过软件解码,只有接收端才能解出 Atmos/DTS:X 的对象声场;需要输出设备支持,探测见日志 bitstream-out),没有支持的输出端点时自动回退到解码。适合 PS5 已设成 Dolby 输出、但设备同时提供 PCM 的情况。"},{12,L"收到HDR也转成SDR显示,不用改PS5或Windows。增强照常用;只改预览,视频导出不受影响。切换会短暂停顿,截图跟随当前画面。关闭后跟随显示器。"},{10,L"设备没报HDR信息时手动指定,需选P010/P016。P010也可能装SDR,别给普通画面强戴HDR帽子。"},{1,L"选采集卡的视频设备。别把摄像头误请来直播PS5。"},{2,L"选设备真实提供的分辨率、帧率和像素格式。清晰度、带宽和延迟都受它影响。"},{3,L"如果设备自带 HDMI 音频,会显示“使用视频设备内置音频”;否则选择独立音频设备,也可不采声音。"},{4,L"按当前格式连接采集卡,并应用当前增强设置。"},{5,L"重新扫描设备和格式。设备被其他软件占用时,刷新不一定能抢回来。"}});
+ installDialogHelp(h,{{16,L"采集卡往软件送帧用的驱动缓冲数量。缓冲越多,卡可以提前排队,但每多一帧就多一帧的等待;缓冲太少,驱动来不及取走就会丢帧。自动:1080p 及以下建议 2 帧、更高分辨率建议 3 帧;最小:1 帧,延迟最低但高负载可能丢帧;驱动默认:不干预。改这个要重新连接采集卡,连接日志里会写建议值和驱动实际给的值(协商未生效时如实标注)。"},{15,L"给方向声明和实际画面不一致的采集卡用:常见于某些 RGB24 格式——设备在媒体类型里写的是底行在前,实际送来的却是顶行在前,于是画面上下颠倒。勾选后把采集画面上下翻转一次,立即生效;只影响本机采集预览、截图和从这里导出的画面,不改设备也不动其他格式。画面正常时不要勾选;换成不颠倒的格式后记得取消。"},{13,L"采集卡把 Dolby Atmos / Dolby Audio / DTS 以位流送来时,这里决定用哪条路。设备本身的音频格式不受影响;改这个要重新连接采集卡。自动优先 PCM,PCM 不可用时才走位流解码;位流优先则反过来:先尝试把位流原样直通给功放/回音壁(独占输出,卡不经过软件解码,只有接收端才能解出 Atmos/DTS:X 的对象声场;需要输出设备支持,探测见日志 bitstream-out),没有支持的输出端点时自动回退到解码。适合 PS5 已设成 Dolby 输出、但设备同时提供 PCM 的情况。"},{12,L"收到HDR也转成SDR显示,不用改PS5或Windows。增强照常用;只改预览,视频导出不受影响。切换会短暂停顿,截图跟随当前画面。关闭后跟随显示器。"},{10,L"设备没报HDR信息时手动指定,需选P010/P016。P010也可能装SDR,别给普通画面强戴HDR帽子。"},{1,L"选采集卡的视频设备。别把摄像头误请来直播PS5。"},{2,L"选设备真实提供的分辨率、帧率和像素格式。清晰度、带宽和延迟都受它影响。"},{3,L"如果设备自带 HDMI 音频,会显示“使用视频设备内置音频”;否则选择独立音频设备,也可不采声音。"},{4,L"按当前格式连接采集卡,并应用当前增强设置。"},{5,L"重新扫描设备和格式。设备被其他软件占用时,刷新不一定能抢回来。"}});
EnableWindow(GetDlgItem(h,4),FALSE);arrange();SetTimer(h,1,100,nullptr);if(!busy)query(-1);return 0;}
case WM_TIMER:
SendDlgItemMessageW(h,12,BM_SETCHECK,readSdr()?BST_CHECKED:BST_UNCHECKED,0);
if(readFlip)SendDlgItemMessageW(h,15,BM_SETCHECK,readFlip()?BST_CHECKED:BST_UNCHECKED,0);
+ if(readBuffer)SendDlgItemMessageW(h,16,CB_SETCURSEL,WPARAM(std::clamp(readBuffer(),0,2)),0);
if(busy&&pending.wait_for(std::chrono::seconds(0))==std::future_status::ready){
auto result=pending.get();busy=false;EnableWindow(GetDlgItem(h,5),TRUE);EnableWindow(GetDlgItem(h,1),TRUE);
if(refreshAfterQuery){refreshAfterQuery=false;query(-1);return 0;}
@@ -107,6 +112,10 @@ case WM_COMMAND:
const int mode=int(SendDlgItemMessageW(h,13,CB_GETCURSEL,0,0));
if(mode>=0&&setAudioIngress&&!setAudioIngress(mode))SetDlgItemTextW(h,8,L"当前正在切换增强或采集;请稍后再试。");
if(readAudioIngress)SendDlgItemMessageW(h,13,CB_SETCURSEL,WPARAM(std::clamp(readAudioIngress(),0,2)),0);
+ }else if(LOWORD(wp)==16&&HIWORD(wp)==CBN_SELCHANGE){
+ const int mode=int(SendDlgItemMessageW(h,16,CB_GETCURSEL,0,0));
+ if(mode>=0&&setBuffer&&!setBuffer(mode))SetDlgItemTextW(h,8,L"当前正在切换增强或采集;请稍后再试。");
+ if(readBuffer)SendDlgItemMessageW(h,16,CB_SETCURSEL,WPARAM(std::clamp(readBuffer(),0,2)),0);
}else if(LOWORD(wp)==1&&HIWORD(wp)==CBN_SELCHANGE){
const int device=int(SendDlgItemMessageW(h,1,CB_GETCURSEL,0,0));rebuildAudioList(h,device);query(device);
}else if((LOWORD(wp)==2||LOWORD(wp)==3)&&HIWORD(wp)==CBN_SELCHANGE){
@@ -137,5 +146,5 @@ case WM_CLOSE:DestroyWindow(h);return 0;
case WM_DESTROY:KillTimer(h,1);DeleteObject(font);window=nullptr;return 0;
}return DefWindowProcW(h,msg,wp,lp);}
}
-void showCapturePanel(HWND parent,std::function<void(const std::wstring&)> callback,std::function<bool()> read,std::function<bool(bool)> write,std::function<int()> readIngress,std::function<bool(int)> writeIngress,std::function<bool()> readFlipped,std::function<bool(bool)> writeFlipped){start=std::move(callback);readSdr=std::move(read);setSdr=std::move(write);readAudioIngress=std::move(readIngress);setAudioIngress=std::move(writeIngress);readFlip=std::move(readFlipped);setFlip=std::move(writeFlipped);if(window){SetForegroundWindow(window);return;}WNDCLASSW wc{};wc.lpfnWndProc=proc;wc.hInstance=GetModuleHandleW(nullptr);wc.lpszClassName=L"VeyraCaptureSetup";wc.hbrBackground=panelBrush();wc.hCursor=LoadCursorW(nullptr,IDC_ARROW);RegisterClassW(&wc);CreateWindowExW(WS_EX_TOOLWINDOW,wc.lpszClassName,L"采集卡 · 连接设置",WS_OVERLAPPED|WS_CAPTION|WS_SYSMENU|WS_VISIBLE,CW_USEDEFAULT,CW_USEDEFAULT,dip(parent,560),dip(parent,600),parent,nullptr,wc.hInstance,nullptr);}
+void showCapturePanel(HWND parent,std::function<void(const std::wstring&)> callback,std::function<bool()> read,std::function<bool(bool)> write,std::function<int()> readIngress,std::function<bool(int)> writeIngress,std::function<bool()> readFlipped,std::function<bool(bool)> writeFlipped,std::function<int()> readBuffered,std::function<bool(int)> writeBuffered){start=std::move(callback);readSdr=std::move(read);setSdr=std::move(write);readAudioIngress=std::move(readIngress);setAudioIngress=std::move(writeIngress);readFlip=std::move(readFlipped);setFlip=std::move(writeFlipped);readBuffer=std::move(readBuffered);setBuffer=std::move(writeBuffered);if(window){SetForegroundWindow(window);return;}WNDCLASSW wc{};wc.lpfnWndProc=proc;wc.hInstance=GetModuleHandleW(nullptr);wc.lpszClassName=L"VeyraCaptureSetup";wc.hbrBackground=panelBrush();wc.hCursor=LoadCursorW(nullptr,IDC_ARROW);RegisterClassW(&wc);CreateWindowExW(WS_EX_TOOLWINDOW,wc.lpszClassName,L"采集卡 · 连接设置",WS_OVERLAPPED|WS_CAPTION|WS_SYSMENU|WS_VISIBLE,CW_USEDEFAULT,CW_USEDEFAULT,dip(parent,560),dip(parent,640),parent,nullptr,wc.hInstance,nullptr);}
}
diff --git a/apps/veyra/ui/CapturePanel.h b/apps/veyra/ui/CapturePanel.h
index 47f29b50..254ca739 100644
--- a/apps/veyra/ui/CapturePanel.h
+++ b/apps/veyra/ui/CapturePanel.h
@@ -10,5 +10,6 @@ namespace veyra::ui {
// declared DIB orientation does not match their samples (RGB24 upside down).
void showCapturePanel(HWND,std::function<void(const std::wstring&)>,std::function<bool()> readSdr,std::function<bool(bool)> setSdr,
std::function<int()> readAudioIngress,std::function<bool(int)> setAudioIngress,
- std::function<bool()> readFlip,std::function<bool(bool)> setFlip);
+ std::function<bool()> readFlip,std::function<bool(bool)> setFlip,
+ std::function<int()> readBuffer,std::function<bool(int)> setBuffer);
}
diff --git a/docs/WORKLOG.md b/docs/WORKLOG.md
index 6e998e08..903815ed 100644
--- a/docs/WORKLOG.md
+++ b/docs/WORKLOG.md
@@ -1,5 +1,29 @@
# 2026-09-11 继续修复目标模式执行中
+## 2026-09-16 采集链路优化开工:隔离分支 + N4 视频 pin 缓冲协商
+
+用户指令:"直接开隔离区分支,开始优化采集链路"。已建 tag `checkpoint/pre-capture-decode-latency-20260916`(main `2406f81`)与分支 `codex/capture-decode-latency-20260916`,按 `docs/CAPTURE_DECODE_LATENCY_PLAN_2026-09-16.md` 的 N4→N3→N1→N2 顺序开工。
+
+**N4 实现**:
+
+- `include/veyra/source/CaptureBuffer.h`(新):`CaptureBufferMode{Auto,Minimum,DriverDefault}` + 策略 `captureDesiredVideoBuffers`(Auto:≤1080p 2、>1080p 3;Minimum:1;DriverDefault:0 不干预)。
+- `NativeCaptureSink`:新增 `suggestCaptureVideoBuffering`(连前对视频输出 pin 调 `IAMBufferNegotiation::SuggestAllocatorProperties`)与 `queryCaptureAllocatorProperties`(连后读实际 allocator 属性)。
+- `CaptureCardSource`:新增 `setBufferMode`;直连路径连前建议、连后记录 `[capture-buffer] mode=… requested=… actual buffers=… bytes=… align=…`,驱动忽略时标注 `(driver ignored; negotiation not applied)`。
+- 设置/持久化/UI/CLI:`EnhancementSettings::captureBuffer`(重连生效)、预设 schema v16→v17、采集面板新增"设备缓冲(变更需重连)"三档下拉与帮助、`--capture-buffer=auto|minimum|driver` 诊断开关;总增强开关关闭(首次默认状态)时也一并下发。
+- 测试:构建 93/93 exit 0;修复合同 187 项 0 失败(新增 6 项:默认 auto、三档 validate、超范围拒绝、策略 2/3/1/0);预设 66 组迁移 + v17 往返 exit 0;采集颜色测试 failures=0。
+
+**真机 A/B(本机 ¥30 USB3 卡,1080p60 YUY2,三档各 10 秒,串行执行)**:
+
+| 模式 | 请求 | 实际 | 结果 |
+| --- | --- | --- | --- |
+| auto | 2 | **10** | 驱动忽略建议;frames=578、dropped=0、callback→Present P95 2.615ms、readAgeMs 0.47–1.45ms |
+| minimum | 1 | **10** | 同上;P95 2.597ms、dropped=0 |
+| driver | 0(不干预) | 10 | 基线;P95 2.601ms、dropped=0 |
+
+结论:**这张卡的驱动接受调用但忽略建议(S_OK 后仍分配 10 个缓冲)**,N4 在它身上无收益,如实记录(符合方案的"该卡无收益"边界);档位、requested/actual 日志与"协商未生效"标注可用,等待支持协商的卡验证 `cBuffers≤2` 的收益。三档均 0 丢帧,无回归。首轮三进程并行启动互相抢卡导致 `Run hr=0x800705AA`,已改串行 `Start-Process -Wait` 重跑;失败记录保留在 `logs/veyra-app.log`(13:15 段)。
+
+**未做(如实)**:`GetAllocatorRequirements` 强制要求属于"驱动忽略时的二级手段",风险高,留待评估;N3/N1/N2 与压缩解码链路尚未开工。
+
## 2026-09-16 隔离分支合并到 main(用户授权)
用户指令:"先把这些修复合并到main吧,然后创建好git存档,更新项目日志和各文档,先把工作区弄干净。"本轮在 main 上执行合并、存档与文档同步:
diff --git a/include/veyra/engine/EnhancementSettings.h b/include/veyra/engine/EnhancementSettings.h
index dde112b4..c5f51270 100644
--- a/include/veyra/engine/EnhancementSettings.h
+++ b/include/veyra/engine/EnhancementSettings.h
@@ -5,6 +5,7 @@
#include <string>
#include <string_view>
#include "veyra/pipeline/ResolutionPlan.h"
+#include "veyra/source/CaptureBuffer.h"
namespace veyra::engine {
enum class FrameGenerationBackend { Dlss, XeSS, Fsr };
// Frame generation that runs inside the present sink (external frame
@@ -105,6 +106,9 @@ struct EnhancementSettings {
// Capture audio ingress; requires a reconnect to take effect (the media type
// is negotiated when the graph is built).
CaptureAudioIngress captureAudio=CaptureAudioIngress::Auto;
+ // Capture video-pin allocator policy; requires a reconnect to take effect
+ // (the allocator is created while the capture graph is built).
+ source::CaptureBufferMode captureBuffer=source::CaptureBufferMode::Auto;
// Capture ingest only: flip the incoming frame vertically. Exists because
// some devices declare a DIB orientation that does not match their samples
// (RGB24 upside-down reports); the capture source asks for top-down first,
@@ -156,6 +160,7 @@ struct EnhancementSettings {
if(!revision)return "settingsRevision must be nonzero";
if(nrRuntime!=NrRuntime::Original&&nrRuntime!=NrRuntime::Community&&nrRuntime!=NrRuntime::Ampere)return "invalid NR runtime";
if(captureAudio<CaptureAudioIngress::Auto||captureAudio>CaptureAudioIngress::BitstreamPreferred)return "invalid capture audio ingress mode";
+ if(captureBuffer<source::CaptureBufferMode::Auto||captureBuffer>source::CaptureBufferMode::DriverDefault)return "invalid capture buffer mode";
if(audioSync<AudioSyncMode::Automatic||audioSync>AudioSyncMode::Off||audioOffsetMs<-250||audioOffsetMs>250)return "invalid audio sync setting";
if(!range(model.intensity,1)||!range(model.tone,1)||!range(model.structure,1))return "model parameter out of range";
if(model.skin!=-1&&!range(model.skin,2))return "skin parameter out of range";
diff --git a/include/veyra/source/CaptureBuffer.h b/include/veyra/source/CaptureBuffer.h
new file mode 100644
index 00000000..eb35499f
--- /dev/null
+++ b/include/veyra/source/CaptureBuffer.h
@@ -0,0 +1,41 @@
+#pragma once
+#include <string_view>
+
+namespace veyra::source {
+// Video-pin allocator policy for the DirectShow direct-connect capture paths.
+// Persisted with the settings and applied on the next connect: the allocator is
+// created while the capture graph is built, so this cannot be a live edit.
+enum class CaptureBufferMode { Auto = 0, Minimum = 1, DriverDefault = 2 };
+
+constexpr std::wstring_view captureBufferModeName(CaptureBufferMode mode) {
+ switch (mode) {
+ case CaptureBufferMode::Minimum: return L"最小(1 帧缓冲)";
+ case CaptureBufferMode::DriverDefault: return L"驱动默认(不干预)";
+ case CaptureBufferMode::Auto: break;
+ }
+ return L"自动(按分辨率)";
+}
+
+// Narrow key for logs and CLI parsing.
+constexpr const char* captureBufferModeKey(CaptureBufferMode mode) {
+ switch (mode) {
+ case CaptureBufferMode::Minimum: return "minimum";
+ case CaptureBufferMode::DriverDefault: return "driver";
+ case CaptureBufferMode::Auto: break;
+ }
+ return "auto";
+}
+
+// Auto keeps two buffers at 1080p and below, three above it: one slot is always
+// being filled while the callback drains the other, and a >1080p frame takes
+// longer over USB, so starving the device there costs dropped frames. Minimum
+// asks for a single buffer; DriverDefault makes no suggestion (0).
+constexpr long captureDesiredVideoBuffers(CaptureBufferMode mode, long width, long height) {
+ switch (mode) {
+ case CaptureBufferMode::Minimum: return 1;
+ case CaptureBufferMode::Auto: return (width > 1920 || height > 1080) ? 3 : 2;
+ case CaptureBufferMode::DriverDefault: break;
+ }
+ return 0;
+}
+}
diff --git a/include/veyra/source/CaptureCardSource.h b/include/veyra/source/CaptureCardSource.h
index 502de936..437d6cd1 100644
--- a/include/veyra/source/CaptureCardSource.h
+++ b/include/veyra/source/CaptureCardSource.h
@@ -45,6 +45,9 @@ public:
// 0 automatic, 1 PCM only, 2 bitstream preferred. Takes effect on the next
// connect/reconnect because the audio media type is negotiated there.
void setAudioIngress(unsigned mode);
+ // 0 auto, 1 minimum, 2 driver default (see CaptureBuffer.h). Applied on the
+ // next connect: the allocator is created while the graph is built.
+ void setBufferMode(unsigned mode);
// Manual ingest flip for devices whose declared DIB orientation does not
// match the samples (RGB24 upside-down reports). Applies to the next
// sample; works for RGB and YUV without touching the device.
diff --git a/include/veyra/source/NativeCaptureSink.h b/include/veyra/source/NativeCaptureSink.h
index fea12b0d..6bff2325 100644
--- a/include/veyra/source/NativeCaptureSink.h
+++ b/include/veyra/source/NativeCaptureSink.h
@@ -12,4 +12,9 @@ HRESULT createNativeAudioSink(const AM_MEDIA_TYPE&,std::function<HRESULT(IMediaS
// 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&);
+// Advisory video-pin request (N4): suggest the driver's allocator buffer count
+// and per-frame byte size before ConnectDirect. Failure is logged and ignored.
+HRESULT suggestCaptureVideoBuffering(IPin*,long buffers,long bytes);
+// Reads the allocator actually in use on our input pin after ConnectDirect.
+HRESULT queryCaptureAllocatorProperties(IPin*,ALLOCATOR_PROPERTIES&);
}
diff --git a/src/engine/EngineController.cpp b/src/engine/EngineController.cpp
index 8351e531..b69764a1 100644
--- a/src/engine/EngineController.cpp
+++ b/src/engine/EngineController.cpp
@@ -202,6 +202,7 @@ void EngineController::run(HWND window,std::wstring path,PlayerOptions options,s
// through to the file open check (fixed 2026-09-16).
if(physicalCapture)captureSource.setAudioIngress(unsigned(options.settings.captureAudio));
if(physicalCapture)captureSource.setVerticalFlip(options.settings.captureFlipVertical);
+ if(physicalCapture)captureSource.setBufferMode(unsigned(options.settings.captureBuffer));
#ifdef VEYRA_ENABLE_REMOTEPLAY
if(remote){
status(L"正在连接 PS5…");
@@ -374,6 +375,7 @@ void EngineController::run(HWND window,std::wstring path,PlayerOptions options,s
captureSource.setAudioSync(unsigned(options.settings.audioSync),options.settings.audioOffsetMs);
captureSource.setAudioIngress(unsigned(options.settings.captureAudio));
captureSource.setVerticalFlip(options.settings.captureFlipVertical);
+ captureSource.setBufferMode(unsigned(options.settings.captureBuffer));
if(physicalCapture&&!captureSource.start()){status(L"无法启动采集,请查看诊断",true);break;}
{std::lock_guard lock(mutex_);snapshot_.duration=duration;snapshot_.nominalSourceFps=isImage?0:activeSource->info().averageFps;snapshot_.running=true;snapshot_.transport=TransportState::Playing;snapshot_.image=isImage;snapshot_.capture=isCapture;snapshot_.applied=options.snapshot();snapshot_.desired=desired_;}
status(isImage?L"图片已增强,可保存PNG/JPEG":std::format(L"{} | 输入 {}×{} / 底图 {}×{} / NR {}×{} / 光流 {}×{} / FG与输出 {}×{} | {}",isRemote?L"PS5 串流":isCapture?L"实时采集":L"播放",width,height,gd.workWidth,gd.workHeight,gd.nrWidth,gd.nrHeight,gd.flowWidth,gd.flowHeight,gd.workWidth,gd.workHeight,gd.nrBeforeSr?L"低延迟 · NR先行后超分":gd.nrWidth<gd.workWidth?L"实时内部处理并回填":L"原生NR(性能成本较高)"));
@@ -599,6 +601,7 @@ void EngineController::run(HWND window,std::wstring path,PlayerOptions options,s
status(std::format(L"采集信号中断,正在重连原设备(第 {} 次)",captureRetries));
captureSource.setAudioIngress(unsigned(options.settings.captureAudio));
captureSource.setVerticalFlip(options.settings.captureFlipVertical);
+ captureSource.setBufferMode(unsigned(options.settings.captureBuffer));
if(captureSource.reconnect(muted_?0.0f:volume_.load(),unsigned(options.settings.audioSync),options.settings.audioOffsetMs)){
captureRecovering=false;reset=true;pendingResetCause=pipeline::ResetReason::DeviceLost;captureSampler.reset();
{std::lock_guard lock(mutex_);snapshot_.captureRecovering=false;}
@@ -653,6 +656,14 @@ void EngineController::run(HWND window,std::wstring path,PlayerOptions options,s
captureSource.setVerticalFlip(requested.captureFlipVertical);
status(requested.captureFlipVertical?L"采集画面已上下翻转(仅影响本机采集画面)":L"采集画面方向已恢复",false);
}
+ // The video-pin allocator is created while the graph is
+ // built: record the mode now and let the reconnect below
+ // (or the next connect) apply it.
+ if(requested.captureBuffer!=options.settings.captureBuffer){
+ options.settings.captureBuffer=requested.captureBuffer;
+ captureSource.setBufferMode(unsigned(requested.captureBuffer));
+ status(L"设备缓冲模式已记录;重新连接采集卡后生效",false);
+ }
std::lock_guard lock(mutex_);snapshot_.applied=options.snapshot();snapshot_.applying=desired_!=snapshot_.applied;
veyra::log::info("settings",std::format("Audio applied videoRevision={} mode={} offsetMs={} (video history retained)",requested.revision,unsigned(requested.audioSync),requested.audioOffsetMs));
}
diff --git a/src/engine/PresetStore.cpp b/src/engine/PresetStore.cpp
index 7bbedf2c..06597404 100644
--- a/src/engine/PresetStore.cpp
+++ b/src/engine/PresetStore.cpp
@@ -13,12 +13,12 @@ bool nameOk(const std::wstring& s){return !s.empty()&&s.size()<=48&&s.front()!=L
std::wstring trim(std::wstring s){auto a=s.find_first_not_of(L" \t\r\n");if(a==s.npos)return {};auto b=s.find_last_not_of(L" \t\r\n");return s.substr(a,b-a+1);}
}
std::string PresetStore::serialize()const{
- std::ostringstream o;o.imbue(std::locale::classic());o<<std::setprecision(std::numeric_limits<float>::max_digits10)<<"VEYRA_PRESETS 16\n"<<std::quoted(utf8(default_))<<' '<<entries_.size()<<'\n';
- for(auto& p:entries_){const auto& s=p.settings;const auto& m=s.model;const auto& r=s.residual;o<<std::quoted(utf8(p.name))<<' '<<m.intensity<<' '<<m.tone<<' '<<m.structure<<' '<<m.skin<<' '<<m.style<<' '<<m.autoMask<<' '<<m.uiCorrection<<' '<<r.total<<' '<<r.darken<<' '<<r.brighten<<' '<<r.color<<' '<<r.luminance<<' '<<s.nr<<' '<<s.sr<<' '<<s.multiplier<<' '<<int(s.nrPolicy)<<' '<<int(s.flow)<<' '<<int(s.content)<<' '<<s.protection.enabled<<' '<<s.protection.featherPixels;for(auto q:s.protection.regions)o<<' '<<q.left<<' '<<q.top<<' '<<q.right<<' '<<q.bottom;o<<' '<<s.videoSrQuality<<' '<<int(s.frameGenerationBackend)<<' '<<int(s.srTarget)<<' '<<int(s.opticalFlowBackend)<<' '<<s.amdFlowHalfResolution<<' '<<int(s.audioSync)<<' '<<s.audioOffsetMs<<' '<<int(s.nrRuntime)<<' '<<s.captureCompatible<<' '<<s.lowLatency<<' '<<s.forceSdrPreview<<' '<<int(s.captureAudio)<<' '<<s.exportBitrateMbps<<' '<<s.captureFlipVertical<<'\n';}return o.str();
+ std::ostringstream o;o.imbue(std::locale::classic());o<<std::setprecision(std::numeric_limits<float>::max_digits10)<<"VEYRA_PRESETS 17\n"<<std::quoted(utf8(default_))<<' '<<entries_.size()<<'\n';
+ for(auto& p:entries_){const auto& s=p.settings;const auto& m=s.model;const auto& r=s.residual;o<<std::quoted(utf8(p.name))<<' '<<m.intensity<<' '<<m.tone<<' '<<m.structure<<' '<<m.skin<<' '<<m.style<<' '<<m.autoMask<<' '<<m.uiCorrection<<' '<<r.total<<' '<<r.darken<<' '<<r.brighten<<' '<<r.color<<' '<<r.luminance<<' '<<s.nr<<' '<<s.sr<<' '<<s.multiplier<<' '<<int(s.nrPolicy)<<' '<<int(s.flow)<<' '<<int(s.content)<<' '<<s.protection.enabled<<' '<<s.protection.featherPixels;for(auto q:s.protection.regions)o<<' '<<q.left<<' '<<q.top<<' '<<q.right<<' '<<q.bottom;o<<' '<<s.videoSrQuality<<' '<<int(s.frameGenerationBackend)<<' '<<int(s.srTarget)<<' '<<int(s.opticalFlowBackend)<<' '<<s.amdFlowHalfResolution<<' '<<int(s.audioSync)<<' '<<s.audioOffsetMs<<' '<<int(s.nrRuntime)<<' '<<s.captureCompatible<<' '<<s.lowLatency<<' '<<s.forceSdrPreview<<' '<<int(s.captureAudio)<<' '<<s.exportBitrateMbps<<' '<<s.captureFlipVertical<<' '<<int(s.captureBuffer)<<'\n';}return o.str();
}
bool PresetStore::parse(const std::string& data,std::vector<UserPreset>& out,std::wstring& def){
if(data.size()>65536)return false;std::istringstream in(data);in.imbue(std::locale::classic());std::string magic,d;int version=0;size_t count=0;
- if(!(in>>magic>>version)||magic!="VEYRA_PRESETS"||(version<1||version>16)||!(in>>std::quoted(d)>>count)||count>64)return false;def=wide(d);if(!d.empty()&&def.empty())return false;
+ if(!(in>>magic>>version)||magic!="VEYRA_PRESETS"||(version<1||version>17)||!(in>>std::quoted(d)>>count)||count>64)return false;def=wide(d);if(!d.empty()&&def.empty())return false;
for(size_t i=0;i<count;++i){UserPreset p;std::string n;int policy,flow,content,nr,sr;auto& s=p.settings;auto& m=s.model;auto& r=s.residual;
if(!(in>>std::quoted(n)>>m.intensity>>m.tone>>m.structure>>m.skin>>m.style>>m.autoMask>>m.uiCorrection>>r.total>>r.darken>>r.brighten>>r.color>>r.luminance>>nr>>sr>>s.multiplier>>policy>>flow>>content))return false;
if(version>=2){int enabled;if(!(in>>enabled>>s.protection.featherPixels)||enabled<0||enabled>1)return false;s.protection.enabled=enabled!=0;
@@ -41,6 +41,8 @@ bool PresetStore::parse(const std::string& data,std::vector<UserPreset>& out,std
if(version>=15){if(!(in>>s.exportBitrateMbps))return false;}
// v16 appends the manual capture vertical flip after the bitrate.
if(version>=16){int flip;if(!(in>>flip)||flip<0||flip>1)return false;s.captureFlipVertical=flip!=0;}
+ // v17 appends the capture video-pin buffer policy.
+ if(version>=17){int buffer;if(!(in>>buffer)||buffer<0||buffer>2)return false;s.captureBuffer=static_cast<veyra::source::CaptureBufferMode>(buffer);}
p.name=wide(n);if(!nameOk(p.name)||std::any_of(out.begin(),out.end(),[&](auto& a){return a.name==p.name;})||nr<0||nr>1||sr<0||sr>1)return false;
s.nr=nr;s.sr=sr;s.nrPolicy=static_cast<pipeline::NrSizePolicy>(policy);s.flow=static_cast<FlowQuality>(flow);s.content=static_cast<ContentRate>(content);
if(!s.validate().empty())return false;out.push_back(std::move(p));
diff --git a/src/source/CaptureCardSource.cpp b/src/source/CaptureCardSource.cpp
index 714cea8e..ea56f733 100644
--- a/src/source/CaptureCardSource.cpp
+++ b/src/source/CaptureCardSource.cpp
@@ -3,6 +3,7 @@
#include "veyra/source/CaptureTiming.h"
#include "veyra/source/CaptureMediaType.h"
#include "veyra/source/NativeCaptureSink.h"
+#include "veyra/source/CaptureBuffer.h"
#include "veyra/pipeline/ColorMetadata.h"
#include "veyra/Log.h"
#include "veyra/sink/AudioFormat.h"
@@ -141,6 +142,9 @@ struct CaptureCardSource::Impl:ISampleGrabberCB {
// 0 automatic, 1 PCM only, 2 bitstream preferred (see
// engine::CaptureAudioIngress). Read when the audio graph is built.
unsigned audioIngressMode=0;
+ // Video-pin allocator policy (0 auto, 1 minimum, 2 driver default); read
+ // when the capture graph is built. See CaptureBuffer.h.
+ unsigned bufferMode=0;
// Manual capture flip; read by the DirectShow callback thread.
std::atomic<bool> verticalFlip{false};
std::unique_ptr<WasapiAudioInput> wasapi;
@@ -233,6 +237,14 @@ void CaptureCardSource::setAudioIngress(unsigned mode){
log::info("capture-audio-ingress",std::format("mode={} ({}) takes effect on the next connect",clamped,
clamped==1?"PCM only":clamped==2?"bitstream preferred":"automatic"));
}
+void CaptureCardSource::setBufferMode(unsigned mode){
+ auto& p=*p_;
+ const unsigned clamped=mode>2?0:mode;
+ if(p.bufferMode==clamped)return;
+ p.bufferMode=clamped;
+ const auto policy=static_cast<CaptureBufferMode>(clamped);
+ log::info("capture-buffer",std::format("mode={} ({}) takes effect on the next connect",clamped,captureBufferModeKey(policy)));
+}
void CaptureCardSource::setVerticalFlip(bool enabled){
auto& p=*p_;
if(p.verticalFlip.exchange(enabled)==enabled)return;
@@ -291,12 +303,25 @@ bool CaptureCardSource::configure(const SourceOpenDesc& desc){close();p_->lastAu
const bool direct=nativeSupported&&!desc.legacyCaptureRgbForDiagnostic;
AM_MEDIA_TYPE connected{};
if(direct){
+ // N4: suggest the video-pin allocator size before ConnectDirect. The
+ // suggestion is advisory; a refusal keeps the driver's defaults and is
+ // reported after the connect instead of failing the device.
+ const auto bufferPolicy=static_cast<CaptureBufferMode>(p.bufferMode);
+ const long suggestedBuffers=captureDesiredVideoBuffers(bufferPolicy,long(nativeLayout.width),long(nativeLayout.height));
ComPtr<IPin> input,output;
hr=createNativeCaptureSink(*native,[&p](IMediaSample* sample){REFERENCE_TIME a=0,b=0;const auto timeHr=sample->GetTime(&a,&b);if(FAILED(timeHr))return timeHr;return p.SampleCB(double(a)/1e7,sample);},p.grabFilter,input);
if(SUCCEEDED(hr))hr=p.graph->AddFilter(p.grabFilter.Get(),L"Native frame mailbox");
if(SUCCEEDED(hr))hr=p.builder->FindPin(p.device.Get(),PINDIR_OUTPUT,&PIN_CATEGORY_CAPTURE,&MEDIATYPE_Video,FALSE,0,&output);
+ if(SUCCEEDED(hr)&&suggestedBuffers>0)suggestCaptureVideoBuffering(output.Get(),suggestedBuffers,LONG(nativeLayout.sampleBytes));
if(SUCCEEDED(hr))hr=p.graph->ConnectDirect(output.Get(),input.Get(),native);
if(SUCCEEDED(hr))hr=input->ConnectionMediaType(&connected);
+ if(SUCCEEDED(hr)){
+ ALLOCATOR_PROPERTIES actual{};
+ const auto allocatorHr=queryCaptureAllocatorProperties(input.Get(),actual);
+ const bool negotiated=suggestedBuffers>0;
+ const bool honored=negotiated&&SUCCEEDED(allocatorHr)&&actual.cBuffers==suggestedBuffers;
+ log::info("capture-buffer",std::format("mode={} requested={} actual buffers={} bytes={} align={} hr=0x{:08X} {}",captureBufferModeKey(bufferPolicy),suggestedBuffers,actual.cBuffers,actual.cbBuffer,actual.cbAlign,uint32_t(allocatorHr),!negotiated?"(driver default)":honored?"(driver honored)":"(driver ignored; negotiation not applied)"));
+ }
log::info("capture",std::format("native ConnectDirect subtype=0x{:08X} hr=0x{:08X} converters=0",native->subtype.Data1,uint32_t(hr)));
}else{
log::warn("capture",std::format("explicit RGB32 compatibility path subtype=0x{:08X} diagnostic={} (decoder/color converter may be inserted)",requestedSubtype.Data1,desc.legacyCaptureRgbForDiagnostic));
diff --git a/src/source/NativeCaptureSink.cpp b/src/source/NativeCaptureSink.cpp
index 6b753116..ef393e3f 100644
--- a/src/source/NativeCaptureSink.cpp
+++ b/src/source/NativeCaptureSink.cpp
@@ -158,6 +158,31 @@ HRESULT suggestCaptureAudioBuffering(IPin* pin,const WAVEFORMATEX& format){
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 suggestCaptureVideoBuffering(IPin* pin,long buffers,long bytes){
+ if(!pin)return E_POINTER;
+ if(buffers<=0||bytes<=0)return E_INVALIDARG;
+ ComPtr<IAMBufferNegotiation> negotiation;
+ const auto queryHr=pin->QueryInterface(IID_PPV_ARGS(&negotiation));
+ if(FAILED(queryHr)){
+ log::warn("capture-buffer",std::format("upstream negotiation unavailable hr=0x{:08X}; driver defaults retained",uint32_t(queryHr)));
+ return queryHr;
+ }
+ const ALLOCATOR_PROPERTIES wanted{buffers,bytes,-1,-1};
+ const auto hr=negotiation->SuggestAllocatorProperties(&wanted);
+ log::info("capture-buffer",std::format("upstream request buffers={} bytes={} hr=0x{:08X} (advisory; actual allocator logged after connect)",buffers,bytes,uint32_t(hr)));
+ return hr;
+}
+HRESULT queryCaptureAllocatorProperties(IPin* pin,ALLOCATOR_PROPERTIES& out){
+ out={};
+ if(!pin)return E_POINTER;
+ ComPtr<IMemInputPin> input;
+ auto hr=pin->QueryInterface(IID_PPV_ARGS(&input));
+ if(FAILED(hr))return hr;
+ ComPtr<IMemAllocator> allocator;
+ hr=input->GetAllocator(&allocator);
+ if(FAILED(hr))return hr;
+ return allocator->GetProperties(&out);
+}
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/unit/RepairContractTests.cpp b/tests/unit/RepairContractTests.cpp
index 1130dca0..e20d510a 100644
--- a/tests/unit/RepairContractTests.cpp
+++ b/tests/unit/RepairContractTests.cpp
@@ -214,6 +214,21 @@ int main(){
settings.captureAudio=static_cast<engine::CaptureAudioIngress>(3);
check(!settings.validate().empty(),"capture audio ingress outside the enum is rejected");
}
+ {
+ engine::EnhancementSettings settings;
+ check(settings.captureBuffer==veyra::source::CaptureBufferMode::Auto,"capture buffer mode defaults to auto");
+ for(auto mode:{veyra::source::CaptureBufferMode::Auto,veyra::source::CaptureBufferMode::Minimum,veyra::source::CaptureBufferMode::DriverDefault}){
+ settings.captureBuffer=mode;
+ check(settings.validate().empty(),"capture buffer modes validate");
+ }
+ settings.captureBuffer=static_cast<veyra::source::CaptureBufferMode>(3);
+ check(!settings.validate().empty(),"capture buffer mode outside the enum is rejected");
+ check(veyra::source::captureDesiredVideoBuffers(veyra::source::CaptureBufferMode::Auto,1920,1080)==2&&
+ veyra::source::captureDesiredVideoBuffers(veyra::source::CaptureBufferMode::Auto,3840,2160)==3&&
+ veyra::source::captureDesiredVideoBuffers(veyra::source::CaptureBufferMode::Minimum,3840,2160)==1&&
+ veyra::source::captureDesiredVideoBuffers(veyra::source::CaptureBufferMode::DriverDefault,1920,1080)==0,
+ "capture buffer policy: auto 2/3 by size, minimum 1, driver default none");
+ }
check(engine::opticalFlowBackendName(engine::OpticalFlowBackend::Nvidia)=="NVIDIA_NVOF"&&engine::opticalFlowBackendName(engine::OpticalFlowBackend::AmdFidelityFx)=="AMD_FIDELITYFX_OF","optical-flow backend names identify every backend");
s.model.intensity=std::numeric_limits<float>::quiet_NaN();check(!s.validate().empty(),"reject NaN transaction");
s={};s.multiplier=5;check(s.validate().empty(),"5X multiplier accepted by the API guard (6X ceiling)");
diff --git a/tests/unit/RepairPresetTests.cpp b/tests/unit/RepairPresetTests.cpp
index 0de202d2..ef677136 100644
--- a/tests/unit/RepairPresetTests.cpp
+++ b/tests/unit/RepairPresetTests.cpp
@@ -42,7 +42,7 @@ bool legacyBackends(const std::filesystem::path& path) {
if(version>=7&&(value.audioSync!=AudioSyncMode::Manual||value.audioOffsetMs!=137))return false;
if(!store.put(L"legacy",value,true))return false;
std::ifstream file(path);std::string magic;int savedVersion=0;file>>magic>>savedVersion;
- if(magic!="VEYRA_PRESETS"||savedVersion!=16)return false;
+ if(magic!="VEYRA_PRESETS"||savedVersion!=17)return false;
PresetStore reloaded(path);
if(!reloaded.load()||reloaded.defaultSettings()!=value)return false;
}else{
@@ -109,6 +109,10 @@ ok=ok&&a.put(L"test",s)&&a.setDefault(0)&&!a.put(L"test",s);PresetStore b(p);ok=
// Manual capture vertical flip (v16) round-trips with the rest of the preset.
auto flipped=s;flipped.captureFlipVertical=true;ok=ok&&b.put(L"capture flip",flipped);
PresetStore flipReload(p);ok=ok&&flipReload.load()&&flipReload.entries().size()==1&&flipReload.entries().back().settings.captureFlipVertical&&b.erase(0);
+ // Capture video-pin buffer policy (v17) round-trips with the rest of the preset.
+ auto buffers=s;buffers.captureBuffer=veyra::source::CaptureBufferMode::Minimum;ok=ok&&b.put(L"capture buffer",buffers);
+ PresetStore bufferReload(p);ok=ok&&bufferReload.load()&&bufferReload.entries().size()==1&&bufferReload.entries().back().settings.captureBuffer==veyra::source::CaptureBufferMode::Minimum&&b.erase(0);
+ auto badBuffer=s;badBuffer.captureBuffer=static_cast<veyra::source::CaptureBufferMode>(3);ok=ok&&!b.put(L"invalid buffer",badBuffer);
{std::ofstream legacy(p);legacy<<"VEYRA_PRESETS 1\n\"legacy\" 1\n\"legacy\" 1 1 1 -1 0 0 0 1 1 1 1 1 1 0 1 0 1 0\n";}
PresetStore old(p);ok=ok&&old.load()&&!old.defaultSettings().protection.enabled&&old.defaultSettings().srTarget==veyra::pipeline::SrTarget::Uhd4K&&old.put(L"v2",s);
PresetStore upgraded(p);ok=ok&&upgraded.load()&&upgraded.entries().size()==2&&upgraded.entries()[1].settings==s;