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): N3 format ordering and latency tiers with a one-time cost hint

Veyra Goal Agent0157bd926868
diff --git a/apps/veyra/ui/CapturePanel.cpp b/apps/veyra/ui/CapturePanel.cpp
index 546026aa..540ce620 100644
--- a/apps/veyra/ui/CapturePanel.cpp
+++ b/apps/veyra/ui/CapturePanel.cpp
@@ -5,6 +5,7 @@
#include "veyra/RuntimePaths.h"
#include "veyra/Log.h"
#include "veyra/source/CaptureCardSource.h"
+#include "veyra/source/CaptureFormatRank.h"
#include <future>
#include <format>
namespace veyra::ui {
@@ -40,6 +41,16 @@ int selectedAudio(HWND h,int device){
if(videoSelected&&selection==1)return source::kCaptureAudioFromVideoDevice;
return selection-1-(videoSelected?1:0);
}
+void maybeShowFormatHint(HWND h){
+ const int index=int(SendDlgItemMessageW(h,2,CB_GETCURSEL,0,0));
+ if(index<0||size_t(index)>=formats.size()||remembered.formatHintDismissed)return;
+ const auto& format=formats[size_t(index)];
+ const auto tier=static_cast<source::CaptureFormatTier>(format.tier);
+ if(!source::captureFormatNeedsCostHint(tier))return;
+ SetDlgItemTextW(h,8,std::format(L"提示:{} 在高分辨率/高帧率下比低延迟格式多一道处理环节({})。建议优先选低延迟格式;此提示只出现一次。",format.label,source::captureFormatTierLabel(tier)).c_str());
+ remembered.formatHintDismissed=true;
+ CapturePreferenceStore(runtime::localDataDirectory()).save(remembered);
+}
void query(int device){if(busy)return;busy=true;queriedDevice=device;queryStarted=GetTickCount64();SetDlgItemTextW(window,8,L"正在查询设备能力…当前播放继续");EnableWindow(GetDlgItem(window,4),FALSE);EnableWindow(GetDlgItem(window,5),FALSE);EnableWindow(GetDlgItem(window,1),FALSE);
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;});
@@ -120,6 +131,7 @@ case WM_COMMAND:
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){
EnableWindow(GetDlgItem(h,4),!busy&&SendDlgItemMessageW(h,2,CB_GETCURSEL,0,0)!=CB_ERR&&SendDlgItemMessageW(h,3,CB_GETCURSEL,0,0)!=CB_ERR);
+ if(LOWORD(wp)==2)maybeShowFormatHint(h);
}else if(LOWORD(wp)==5){
query(-1);
}else if(LOWORD(wp)==4){
@@ -131,7 +143,7 @@ case WM_COMMAND:
const auto* audioDevice=audio>=0?&audioDevices[size_t(audio)]:nullptr;
const auto path=source::CaptureCardSource::makeCapturePath(unsigned(device),videoDevices[size_t(device)],formats[size_t(format)].index,audio,audioDevice,unsigned(SendDlgItemMessageW(h,10,CB_GETCURSEL,0,0)));
if(!path.empty()){
- remembered={videoDevices[size_t(device)].path,formats[size_t(format)].key,audioDevice?audioDevice->path:L"",audioDevice?(audioDevice->wasapi?source::kCaptureAudioWasapi:0):audio,unsigned(SendDlgItemMessageW(h,10,CB_GETCURSEL,0,0))};
+ remembered={videoDevices[size_t(device)].path,formats[size_t(format)].key,audioDevice?audioDevice->path:L"",audioDevice?(audioDevice->wasapi?source::kCaptureAudioWasapi:0):audio,unsigned(SendDlgItemMessageW(h,10,CB_GETCURSEL,0,0)),remembered.formatHintDismissed};
if(!CapturePreferenceStore(runtime::localDataDirectory()).save(remembered))log::warn("capture","Failed to save capture selection");
start(path);DestroyWindow(h);
}
diff --git a/apps/veyra/ui/CapturePreferenceStore.h b/apps/veyra/ui/CapturePreferenceStore.h
index 8e55345f..38785a89 100644
--- a/apps/veyra/ui/CapturePreferenceStore.h
+++ b/apps/veyra/ui/CapturePreferenceStore.h
@@ -11,6 +11,8 @@ struct CapturePreferences {
std::wstring videoPath,formatKey,audioPath;
int audioMode=-1;
unsigned colorOverride=0;
+ // N3: the one-time "this format is high cost" hint was already shown.
+ bool formatHintDismissed=false;
};
class CapturePreferenceStore {
std::filesystem::path path_;
@@ -25,13 +27,14 @@ public:
if(!file.read(reinterpret_cast<char*>(data.data()),size))return {};
std::wistringstream in(data);std::wstring magic;int version=0;CapturePreferences result;
if(!(in>>magic>>version>>std::quoted(result.videoPath)>>std::quoted(result.formatKey)>>result.audioMode>>std::quoted(result.audioPath)>>result.colorOverride)||
- magic!=L"VEYRA_CAPTURE"||version!=1||result.audioMode< -3||result.audioMode>0||result.colorOverride>2)return {};
+ magic!=L"VEYRA_CAPTURE"||(version!=1&&version!=2)||result.audioMode< -3||result.audioMode>0||result.colorOverride>2)return {};
+ if(version>=2){int dismissed=0;if(!(in>>dismissed)||(dismissed!=0&&dismissed!=1))return {};result.formatHintDismissed=dismissed!=0;}
in>>std::ws;return in.eof()?result:CapturePreferences{};
}
bool save(const CapturePreferences& p)const {
if(p.audioMode< -3||p.audioMode>0||p.colorOverride>2)return false;
std::error_code ec;std::filesystem::create_directories(path_.parent_path(),ec);if(ec)return false;
- std::wostringstream out;out<<L"VEYRA_CAPTURE 1\n"<<std::quoted(p.videoPath)<<L' '<<std::quoted(p.formatKey)<<L' '<<p.audioMode<<L' '<<std::quoted(p.audioPath)<<L' '<<p.colorOverride<<L'\n';
+ std::wostringstream out;out<<L"VEYRA_CAPTURE 2\n"<<std::quoted(p.videoPath)<<L' '<<std::quoted(p.formatKey)<<L' '<<p.audioMode<<L' '<<std::quoted(p.audioPath)<<L' '<<p.colorOverride<<L' '<<(p.formatHintDismissed?1:0)<<L'\n';
const auto data=out.str();if(data.size()>65536/sizeof(wchar_t))return false;const DWORD bytes=DWORD(data.size()*sizeof(wchar_t));
auto tmp=path_;tmp+=L".tmp-"+std::to_wstring(GetCurrentProcessId());
HANDLE file=CreateFileW(tmp.c_str(),GENERIC_WRITE,0,nullptr,CREATE_ALWAYS,FILE_ATTRIBUTE_NORMAL,nullptr);if(file==INVALID_HANDLE_VALUE)return false;
diff --git a/docs/WORKLOG.md b/docs/WORKLOG.md
index 903815ed..30ea375f 100644
--- a/docs/WORKLOG.md
+++ b/docs/WORKLOG.md
@@ -1,5 +1,13 @@
# 2026-09-11 继续修复目标模式执行中
+## 2026-09-16 采集链路 N3:格式排序与延迟标注
+
+- `include/veyra/source/CaptureFormatRank.h`(新):`captureFormatRank` / `captureFormatTier` / `captureFormatTierLabel` / `captureFormatNeedsCostHint`。推荐顺序:NV12/P010 → YUY2 → RGB24/RGB32/ARGB32 → UYVY/YVYU/RGB555/RGB565 → 压缩/需解码(rank 100)。
+- `enumerateFormats`:按 rank `stable_sort`(同 rank 保留驱动枚举顺序),每行 label 追加延迟档位(低延迟 / 中延迟 / 高延迟·需 CPU 拆包 / 需系统解码·较高延迟);`CaptureFormat` 增加 `rank`/`tier` 字段供面板使用。
+- 采集面板:选中高成本或解码格式时给**一次性**提示(`CapturePreferences` v1→v2,新增 `formatHintDismissed`,v1 旧文件仍可读);提示写入状态栏并持久化"只提示一次"。
+- 验证:构建 exit 0;修复合同 191 项 0 失败(新增 4 项:rank 链 NV12<YUY2<RGB24<RGB565<解码、tier 分级、提示门槛、合成列表里 YUY2 排在 RGB565 前);预设 66 组 exit 0。真卡 `veyra_capture_tests --list`:YUY2(0–23,含 4K18)排在 MJPEG(24+)之前,每行带档位标注(控制台中文乱码是既有 probe 编码问题,GUI 走 wstring)。
+- 未做(如实):UI 提示的自动化点击测试(判定逻辑已被单元测试覆盖);N1/N2 与压缩解码链路尚未开工。
+
## 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 顺序开工。
diff --git a/include/veyra/source/CaptureCardSource.h b/include/veyra/source/CaptureCardSource.h
index 437d6cd1..e91319a5 100644
--- a/include/veyra/source/CaptureCardSource.h
+++ b/include/veyra/source/CaptureCardSource.h
@@ -6,7 +6,7 @@
#include "veyra/sink/CaptureAudioSession.h"
#include "veyra/source/AudioInputRecovery.h"
namespace veyra::source {
-struct CaptureFormat {int index=0;unsigned width=0,height=0;double fps=0;std::wstring label;std::wstring key;};
+struct CaptureFormat {int index=0;unsigned width=0,height=0;double fps=0;std::wstring label;std::wstring key;int rank=0;int tier=0;};
struct CaptureDevice {
std::wstring name;
// DirectShow moniker DevicePath/display name. This is stable across a
diff --git a/include/veyra/source/CaptureFormatRank.h b/include/veyra/source/CaptureFormatRank.h
new file mode 100644
index 00000000..77149380
--- /dev/null
+++ b/include/veyra/source/CaptureFormatRank.h
@@ -0,0 +1,59 @@
+#pragma once
+#include <string_view>
+#include "veyra/source/CapturePixelFormat.h"
+
+namespace veyra::source {
+// N3: format-list ordering and cost labels (plan 2026-09-16, section 8 N3).
+// Lower rank sorts first. Plan order: NV12/P010 < YUY2 < RGB24/RGB32 <
+// repack-heavy packed formats < compressed (needs a decoder).
+enum class CaptureFormatTier { Low = 0, Medium = 1, High = 2, Decoded = 3 };
+
+constexpr int captureFormatRank(CapturePacking packing) {
+ switch (packing) {
+ case CapturePacking::Nv12: return 0;
+ case CapturePacking::P010: return 1;
+ case CapturePacking::Nv21: return 2;
+ case CapturePacking::I420: return 3;
+ case CapturePacking::Yv12: return 4;
+ case CapturePacking::P016: return 5;
+ case CapturePacking::Yuy2: return 10;
+ case CapturePacking::Bgr24: return 20; // RGB24 DIB
+ case CapturePacking::Bgr32: return 21; // RGB32 DIB
+ case CapturePacking::Bgra32: return 22; // ARGB32 DIB
+ case CapturePacking::Uyvy: return 30;
+ case CapturePacking::Yvyu: return 31;
+ case CapturePacking::Rgb555: return 32;
+ case CapturePacking::Rgb565: return 33;
+ case CapturePacking::Unknown: break;
+ }
+ return 100; // compressed or unknown: needs a decoder / system conversion
+}
+
+constexpr CaptureFormatTier captureFormatTier(CapturePacking packing) {
+ switch (captureFormatRank(packing)) {
+ case 0: case 1: case 2: case 3: case 4: case 5: case 10:
+ return CaptureFormatTier::Low;
+ case 20: case 21: case 22:
+ return CaptureFormatTier::Medium;
+ case 30: case 31: case 32: case 33:
+ return CaptureFormatTier::High;
+ default: break;
+ }
+ return CaptureFormatTier::Decoded;
+}
+
+constexpr std::wstring_view captureFormatTierLabel(CaptureFormatTier tier) {
+ switch (tier) {
+ case CaptureFormatTier::Low: return L"低延迟";
+ case CaptureFormatTier::Medium: return L"中延迟";
+ case CaptureFormatTier::High: return L"高延迟·需 CPU 拆包";
+ case CaptureFormatTier::Decoded: break;
+ }
+ return L"需系统解码·较高延迟";
+}
+
+// One-time hint when the user selects a high-cost or decoder-backed format.
+constexpr bool captureFormatNeedsCostHint(CaptureFormatTier tier) {
+ return tier >= CaptureFormatTier::High;
+}
+}
diff --git a/src/source/CaptureCardSource.cpp b/src/source/CaptureCardSource.cpp
index ea56f733..c12a3caa 100644
--- a/src/source/CaptureCardSource.cpp
+++ b/src/source/CaptureCardSource.cpp
@@ -4,6 +4,7 @@
#include "veyra/source/CaptureMediaType.h"
#include "veyra/source/NativeCaptureSink.h"
#include "veyra/source/CaptureBuffer.h"
+#include "veyra/source/CaptureFormatRank.h"
#include "veyra/pipeline/ColorMetadata.h"
#include "veyra/Log.h"
#include "veyra/sink/AudioFormat.h"
@@ -218,12 +219,17 @@ std::vector<CaptureFormat> enumerateFormats(IAMStreamConfig* config){
if(bitmap&&bitmap->biWidth>0&&bitmap->biWidth<=3840&&std::abs(int64_t(bitmap->biHeight))>0&&std::abs(int64_t(bitmap->biHeight))<=2160&&duration>0){unsigned width=bitmap->biWidth,height=unsigned(std::abs(int64_t(bitmap->biHeight)));double fps=1e7/duration;
const auto pixel=capturePixelName(type->subtype);CaptureMediaLayout layout;const bool valid=captureMediaLayout(*type,layout);const bool knownRaw=capturePacking(type->subtype)!=CapturePacking::Unknown;
const wchar_t* support=valid?((layout.format==AV_PIX_FMT_P010||layout.format==AV_PIX_FMT_P016)?L"原生 · SDR":L"原生"):knownRaw?L"布局/颜色暂不支持":L"需系统解码/转换";
+ // N3: latency tier + recommended rank; compressed/unknown sorts last.
+ const auto tier=valid?captureFormatTier(layout.packing):CaptureFormatTier::Decoded;
+ const int rank=valid?captureFormatRank(layout.packing):captureFormatRank(CapturePacking::Unknown);
wchar_t subtype[40]{},formatType[40]{};StringFromGUID2(type->subtype,subtype,40);StringFromGUID2(type->formattype,formatType,40);
const auto key=std::format(L"{}:{}:{}:{}:{}:{}:{}",width,bitmap->biHeight,duration,subtype,formatType,bitmap->biBitCount,bitmap->biCompression);
- out.push_back({i,width,height,fps,std::format(L"{} x {} @ {:.2f} fps · {} · {} [format {}]",width,height,fps,pixel,support,i),key});
+ out.push_back({i,width,height,fps,std::format(L"{} x {} @ {:.2f} fps · {} · {} · {} [format {}]",width,height,fps,pixel,support,captureFormatTierLabel(tier),i),key,rank,int(tier)});
}
freeType(type);
}
+ // Recommended order first; equal ranks keep the driver's enumeration order.
+ std::stable_sort(out.begin(),out.end(),[](const CaptureFormat& a,const CaptureFormat& b){return a.rank<b.rank;});
return out;
}
std::vector<CaptureFormat> CaptureCardSource::formats(unsigned device){ComPtr<IGraphBuilder> g;ComPtr<ICaptureGraphBuilder2>b;ComPtr<IBaseFilter>f;ComPtr<IAMStreamConfig>c;if(!configuration(device,g,b,f,c))return {};return enumerateFormats(c.Get());}
diff --git a/tests/unit/RepairContractTests.cpp b/tests/unit/RepairContractTests.cpp
index e20d510a..b29cc133 100644
--- a/tests/unit/RepairContractTests.cpp
+++ b/tests/unit/RepairContractTests.cpp
@@ -8,9 +8,12 @@
#include "veyra/engine/FrameFlowWindow.h"
#include "veyra/engine/EnhancementDelayEstimate.h"
#include "veyra/ThunkHook.h"
+#include "veyra/source/CaptureFormatRank.h"
#include <iostream>
#include <filesystem>
#include <fstream>
+#include <algorithm>
+#include <vector>
namespace {
int thunkHookCalls = 0;
@@ -229,6 +232,26 @@ int main(){
veyra::source::captureDesiredVideoBuffers(veyra::source::CaptureBufferMode::DriverDefault,1920,1080)==0,
"capture buffer policy: auto 2/3 by size, minimum 1, driver default none");
}
+ {
+ using veyra::source::CaptureFormatTier;
+ using veyra::source::CapturePacking;
+ check(veyra::source::captureFormatRank(CapturePacking::Nv12)<veyra::source::captureFormatRank(CapturePacking::Yuy2)&&
+ veyra::source::captureFormatRank(CapturePacking::Yuy2)<veyra::source::captureFormatRank(CapturePacking::Bgr24)&&
+ veyra::source::captureFormatRank(CapturePacking::Bgr24)<veyra::source::captureFormatRank(CapturePacking::Rgb565)&&
+ veyra::source::captureFormatRank(CapturePacking::Rgb565)<veyra::source::captureFormatRank(CapturePacking::Unknown),
+ "format rank: NV12 < YUY2 < RGB24 < RGB565 < decoded");
+ check(veyra::source::captureFormatTier(CapturePacking::Nv12)==CaptureFormatTier::Low&&
+ veyra::source::captureFormatTier(CapturePacking::Bgr24)==CaptureFormatTier::Medium&&
+ veyra::source::captureFormatTier(CapturePacking::Rgb565)==CaptureFormatTier::High&&
+ veyra::source::captureFormatTier(CapturePacking::Unknown)==CaptureFormatTier::Decoded,
+ "format tiers: low/medium/high/decoded");
+ check(veyra::source::captureFormatNeedsCostHint(CaptureFormatTier::High)&&veyra::source::captureFormatNeedsCostHint(CaptureFormatTier::Decoded)&&
+ !veyra::source::captureFormatNeedsCostHint(CaptureFormatTier::Medium),"cost hint only for high/decoded formats");
+ std::vector<CapturePacking> order{CapturePacking::Rgb565,CapturePacking::Unknown,CapturePacking::Yuy2,CapturePacking::Nv12};
+ std::stable_sort(order.begin(),order.end(),[](CapturePacking a,CapturePacking b){return veyra::source::captureFormatRank(a)<veyra::source::captureFormatRank(b);});
+ check(order[0]==CapturePacking::Nv12&&order[1]==CapturePacking::Yuy2&&order[2]==CapturePacking::Rgb565&&order[3]==CapturePacking::Unknown,
+ "recommended order: a device offering YUY2 and RGB565 lists YUY2 first");
+ }
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)");