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): RGB24 DIB orientation - top-down negotiation and a manual flip switch
Veyra Goal Agent87ad4cd0a223
diff --git a/apps/veyra/ui/AppShell.cpp b/apps/veyra/ui/AppShell.cppindex c72bc0c9..788d8922 100644--- a/apps/veyra/ui/AppShell.cpp+++ b/apps/veyra/ui/AppShell.cpp@@ -54,7 +54,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.captureCompatible=s.captureCompatible;effective.forceSdrPreview=s.forceSdrPreview;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.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;}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)};@@ -410,7 +410,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);});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 (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 Export:if(uiState.mode==veyra::ui::Mode::Professional)startVideoExport(false);break;case Info:showDiagnostics=!showDiagnostics;layout();break;}return 0;@@ -557,7 +557,21 @@ CoInitializeEx(nullptr,COINIT_APARTMENTTHREADED);initialOptions=veyra::engine::PlayerOptions::from(veyra::ui::defaultSettings());int argc=0;auto argv=CommandLineToArgvW(GetCommandLineW(),&argc);for(int i=1;i<argc;++i){const std::wstring arg=argv[i];if(arg==L"--export-worker"&&i+1<argc)workerMapping=reinterpret_cast<HANDLE>(_wcstoui64(argv[++i],nullptr,10));else if(arg==L"--smoke-view"&&i+1<argc)smokeView=argv[++i];else if(arg==L"--smoke-fg-only")smokeFgOnly=true;else if(arg==L"--smoke-transport")smokeTransport=true;else if(arg==L"--smoke-repair-ui")smokeRepair=true;else if(arg==L"--smoke-repair-ui-reject")smokeRepair=smokeRepairReject=true;else if(arg==L"--smoke-hover")smokeZoom=smokeHover=true;else if(arg==L"--smoke-protection")smokeProtection=true;else if(arg==L"--smoke-zoom")smokeZoom=true;else if(arg==L"--smoke-empty")smokeEmpty=true;else if(arg==L"--smoke-dual")smokeDual=true;else if(arg==L"--smoke-dual-pause"){smokeDual=smokeDualPause=true;}else if(arg==L"--smoke-master-reject")smokeMaster=smokeMasterReject=true;else if(arg==L"--smoke-master")smokeMaster=true;else if(arg==L"--smoke-audio")smokeAudio=true;else if(arg==L"--smoke-job-cancel")smokeJobCancel=true;else if(arg==L"--smoke-job-exit")smokeJobExit=true;else if(arg==L"--smoke-job")smokeJob=true;else if(arg==L"--smoke-dual-export"&&i+1<argc)smokeDualOutput=argv[++i];else if(arg==L"--smoke-seconds"&&i+1<argc)smokeSeconds=std::clamp(_wtoi(argv[++i]),1,240);else if(arg==L"--export-out"&&i+1<argc)exportOutput=argv[++i];else if(arg==L"--max-frames"&&i+1<argc)exportFrames=std::max(1,_wtoi(argv[++i]));else if(arg==L"--cancel-after-ms"&&i+1<argc)cancelAfterMs=std::clamp(_wtoi(argv[++i]),1,240000);else if(arg==L"--hevc")exportHevc=true;else if(arg==L"--smoke-rollback-flow"){smokeRollback=true;smokeRollbackFlow=true;}else if(arg==L"--smoke-rollback")smokeRollback=true;else if(arg==L"--smoke-ui")smokeUi=true;else if(arg==L"--no-fg")initialOptions.fg=false;else if(arg==L"--smoke-settings")smokeSettings=true;else if(arg==L"--smoke-screenshot")smokeScreenshot=true;else if(arg==L"--smoke-controls")smokeControls=true;else if(arg==L"--smoke-save"&&i+1<argc)smokeSave=argv[++i];else if(arg==L"--native")initialOptions.realtime=false;else if(arg==L"--realtime")initialOptions.realtime=true;else if(arg==L"--fg")initialOptions.fg=true;else if(arg==L"--fg-multiplier"&&i+1<argc){initialOptions.fgMultiplier=std::clamp(_wtoi(argv[++i]),2,4);initialOptions.fg=true;}else if(arg==L"--video-sr"&&i+1<argc){initialOptions.settings.videoSrQuality=std::clamp(_wtoi(argv[++i]),1,4);initialOptions.sr=true;}else if(arg==L"--nr-ampere")initialOptions.settings.nrRuntime=veyra::engine::NrRuntime::Ampere;else if(arg==L"--nr-community")initialOptions.settings.nrRuntime=veyra::engine::NrRuntime::Community;else if(arg==L"--nr-original")initialOptions.settings.nrRuntime=veyra::engine::NrRuntime::Original;else if(arg==L"--sr")initialOptions.sr=true;else if(arg==L"--no-nr")initialOptions.nr=false;else if(arg==L"--nr")initialOptions.nr=true;else if(arg==L"--no-sr")initialOptions.sr=false;else autoInput=arg;}LocalFree(argv);-if(workerMapping){const int code=veyra::engine::runExportWorker(workerMapping);CoUninitialize();return code;}+ // --capture-flip: diagnostics/smoke only; the interactive path uses the+ // capture panel checkbox and persists captureFlipVertical with presets.+ // The legacy parser above treats unknown flags as the input path, so when+ // this flag was last the positional argument is re-derived without it.+ {+ 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;+ if(autoInput==L"--capture-flip"){+ autoInput.clear();+ 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"--video-sr",L"--capture-audio"};+ for(int i=1;i<flipArgc;++i){const std::wstring arg=flipArgv[i];if(arg.starts_with(L"--")){for(const auto* flag:valueFlags)if(arg==flag){++i;break;}continue;}autoInput=arg;break;}+ }+ LocalFree(flipArgv);+ }+ if(workerMapping){const int code=veyra::engine::runExportWorker(workerMapping);CoUninitialize();return code;}if(smokeSeconds<=0&&exportOutput.empty()){uiPreferences=preferences.load();initialOptions=veyra::engine::PlayerOptions::from(preferences.startup(initialOptions.snapshot()));engine.setVolume(uiPreferences.volume,uiPreferences.muted);uiState.subtitles=uiPreferences.subtitles;subtitlePixels=uiPreferences.subtitleSize;}engine.requestSettings(initialOptions.snapshot());if(!exportOutput.empty()){std::atomic<bool> cancel{false},finished{false};std::thread cancelTimer;if(cancelAfterMs)cancelTimer=std::thread([&]{const auto start=GetTickCount64();while(!finished&&GetTickCount64()-start<cancelAfterMs)std::this_thread::sleep_for(std::chrono::milliseconds(5));if(!finished)cancel=true;});bool ok=veyra::engine::exportVideo(autoInput,exportOutput,initialOptions,exportHevc,cancel,[](double,const std::wstring& s){OutputDebugStringW(s.c_str());},exportFrames);finished=true;if(cancelTimer.joinable())cancelTimer.join();veyra::log::info("app",std::format("export result={}",ok));CoUninitialize();return ok?0:cancel?3:1;}diff --git a/apps/veyra/ui/CapturePanel.cpp b/apps/veyra/ui/CapturePanel.cppindex ae0136d6..d2c1560d 100644--- a/apps/veyra/ui/CapturePanel.cpp+++ b/apps/veyra/ui/CapturePanel.cpp@@ -16,6 +16,7 @@ std::vector<source::CaptureFormat> formats;std::vector<source::CaptureDevice> videoDevices,audioDevices;CapturePreferences remembered;std::function<bool()> readSdr;std::function<bool(bool)> setSdr;+std::function<bool()> readFlip;std::function<bool(bool)> setFlip;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();@@ -42,7 +43,7 @@ void query(int device){if(busy)return;busy=true;queriedDevice=device;queryStarteconst 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};for(int id=1;id<=12;++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)?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,470};for(int id=1;id<=13;++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)?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();@@ -51,12 +52,15 @@ case WM_CREATE:{window=h;font=makeFont(h);titleTheme(h);auto add=[&](const wcharadd(L"COMBOBOX",L"",10,CBS_DROPDOWNLIST|WS_VSCROLL|WS_TABSTOP);add(L"STATIC",L"输入颜色(变更需重连)",11,0);for(auto name:{L"自动识别 SDR / HDR · 设备元数据",L"手动 HDR10 / PQ · BT.2020",L"手动 HLG · BT.2020 / 1000nit参考"})SendDlgItemMessageW(h,10,CB_ADDSTRING,0,LPARAM(name));SendDlgItemMessageW(h,10,CB_SETCURSEL,0,0);add(L"BUTTON",L"转为 SDR 显示(所有预览,立即生效)",12,BS_AUTOCHECKBOX|WS_TABSTOP);SendDlgItemMessageW(h,12,BM_SETCHECK,readSdr()?BST_CHECKED:BST_UNCHECKED,0);+ add(L"BUTTON",L"画面上下翻转(采集画面倒置时勾选,立即生效)",13,BS_AUTOCHECKBOX|WS_TABSTOP);SendDlgItemMessageW(h,13,BM_SETCHECK,readFlip&&readFlip()?BST_CHECKED:BST_UNCHECKED,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,{{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,{{13,L"给方向声明和实际画面不一致的采集卡用:常见于某些 RGB24 格式——设备在媒体类型里写的是底行在前,实际送来的却是顶行在前,于是画面上下颠倒。勾选后把采集画面上下翻转一次,立即生效;只影响本机采集预览、截图和从这里导出的画面,不改设备也不动其他格式。画面正常时不要勾选;换成不颠倒的格式后记得取消。"}});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,13,BM_SETCHECK,readFlip()?BST_CHECKED:BST_UNCHECKED,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;}@@ -93,6 +97,10 @@ case WM_COMMAND:const bool enabled=SendDlgItemMessageW(h,12,BM_GETCHECK,0,0)==BST_CHECKED;if(!setSdr(enabled))SetDlgItemTextW(h,8,L"当前正在切换增强,请稍后再试。");SendDlgItemMessageW(h,12,BM_SETCHECK,readSdr()?BST_CHECKED:BST_UNCHECKED,0);+ }else if(LOWORD(wp)==13&&HIWORD(wp)==BN_CLICKED){+ const bool enabled=SendDlgItemMessageW(h,13,BM_GETCHECK,0,0)==BST_CHECKED;+ if(!setFlip||!setFlip(enabled))SetDlgItemTextW(h,8,L"当前正在切换增强,请稍后再试。");+ if(readFlip)SendDlgItemMessageW(h,13,BM_SETCHECK,readFlip()?BST_CHECKED:BST_UNCHECKED,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){@@ -123,5 +131,11 @@ 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);}}+// Extended entry point: stores the flip callbacks, then reuses the classic+// entry point below so the window/lifetime logic stays in one place.+void showCapturePanel(HWND parent,std::function<void(const std::wstring&)> callback,std::function<bool()> read,std::function<bool(bool)> write,std::function<bool()> readFlipped,std::function<bool(bool)> writeFlipped){+ readFlip=std::move(readFlipped);setFlip=std::move(writeFlipped);+ showCapturePanel(parent,std::move(callback),std::move(read),std::move(write));+}void showCapturePanel(HWND parent,std::function<void(const std::wstring&)> callback,std::function<bool()> read,std::function<bool(bool)> write){start=std::move(callback);readSdr=std::move(read);setSdr=std::move(write);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,514),parent,nullptr,wc.hInstance,nullptr);}}diff --git a/apps/veyra/ui/CapturePanel.h b/apps/veyra/ui/CapturePanel.hindex 5b830595..96e5d89c 100644--- a/apps/veyra/ui/CapturePanel.h+++ b/apps/veyra/ui/CapturePanel.h@@ -2,4 +2,11 @@#include <windows.h>#include <string>#include <functional>-namespace veyra::ui {void showCapturePanel(HWND,std::function<void(const std::wstring&)>,std::function<bool()> readSdr,std::function<bool(bool)> setSdr);}+// readFlip/setFlip toggle the manual vertical ingest flip for devices whose+// declared DIB orientation does not match their samples (RGB24 upside down).+namespace veyra::ui {+void showCapturePanel(HWND,std::function<void(const std::wstring&)>,std::function<bool()> readSdr,std::function<bool(bool)> setSdr);+// Extended entry point that also carries the capture flip callbacks.+void showCapturePanel(HWND,std::function<void(const std::wstring&)>,std::function<bool()> readSdr,std::function<bool(bool)> setSdr,+ std::function<bool()> readFlip,std::function<bool(bool)> setFlip);+}diff --git a/docs/CAPTURE_RGB24_ORIENTATION_2026-09-16.md b/docs/CAPTURE_RGB24_ORIENTATION_2026-09-16.mdnew file mode 100644index 00000000..cbac4322--- /dev/null+++ b/docs/CAPTURE_RGB24_ORIENTATION_2026-09-16.md@@ -0,0 +1,43 @@+# RGB24 采集倒像修复:直连 top-down 协商 + 手动上下翻转(2026-09-16)++用户报告:部分采集卡用 RGB24 时画面上下颠倒,其他格式正常、其他软件正常。用户选定 A+B 方案,明确不做 C(强制走系统 RGB32 转换,徒增一次系统转换与延迟)。++## 1. 根因判定++整条链路只有一处决定上下方向:`include/veyra/source/CaptureMediaType.h` 按 DIB 头 `biHeight` 符号给 RGB 打 `bottomUp`,`copyCaptureSample()` 据此整行倒序读取;GPU 上传与 `RgbToLinear.hlsl` 全程 top-down,没有第二次翻转。YUV 格式(YUY2/NV12/I420/P010…)按 DirectShow 惯例忽略符号、恒按 top-down 读,所以只有 RGB 家族会被方向声明影响。++被报告的设备在 RGB24 媒体类型里声明的方向与实际样本不一致(声明 bottom-up、实际 bottom-up 以外的顺序)。RGB24 自 1.1.0 起改为原生直连(1.0.x 走系统 RGB32 转换路径),把该矛盾暴露出来;其他软件通常经系统 Color Space Converter/渲染器,或在协商时明确要求 top-down,因此不暴露。FFmpeg 的 dshow 输入同样把 `biHeight>0` 标成 "BottomUp",可证明判断规则本身不是本项目独有的错误。++旧测试无法发现该问题:单元用例用同一公式计算期望(自证式),GPU 采集用例每行图案相同(上下翻转照样通过)。本轮补上了真正的方向断言。++## 2. 修复++**A. 直连 RGB DIB 先协商 top-down**(`src/source/CaptureCardSource.cpp`)++- caps 类型属于 Bgr32/Bgra32/Bgr24/RGB555/565 且 `biHeight>0` 时,先把 `biHeight` 取负再 `SetFormat`;+- 驱动接受 → 重新 `GetFormat` 并按实际连接类型解析(负高度 = 不翻转),说谎的卡被自动纠正;+- 驱动拒绝 → 恢复原符号,继续按声明符号翻转,诚实的 bottom-up 设备行为不变;+- 新增日志 `[capture] DIB top-down request hr=0x… subtype=0x… accepted=0/1 bottomUp=…`,用户抓一行即可判定。++**B. 采集面板"画面上下翻转"开关**(立即生效的兜底)++- `EnhancementSettings::captureFlipVertical`(默认关;加入实时字段集合,切换不重建增强图);+- `CaptureCardSource::setVerticalFlip`:原子标志,DirectShow 回调线程按样本生效;`copyCaptureSample()` 增加可选翻转参数,RGB 与 YUV 都支持,YUV 连色度行一起翻转;+- 引擎在 configure 前、start 前、重连、每帧与实时设置块同步;主增强开关"全关"(首次默认状态)时也会立即下发;+- 采集面板新增 checkbox 13(含帮助文本);`--capture-flip` 仅作诊断/烟测;+- 预设 schema v12→v13(行尾追加 bool;旧 v1–v12 文件仍可读,老版本读到 v13 会拒绝并保留原文件)。++## 3. 验证(main 分支)++- 构建:`cmd.exe /c out\build\veyra-build-x64-release.cmd` exit 0(166/166)。+- `veyra_capture_color_tests.exe`:failures=0;新增方向断言全部 PASS(bottom-up RGB24 读最后一行、top-down 直通、手动翻转对两种输入都反相、NV12 色度行跟随翻转)。+- `veyra_repair_contract_tests.exe`:145 checks 0 failures(含 `capture vertical flip defaults off`)。+- `veyra_repair_preset_tests.exe <tmp>`:48 组 v4–v11 迁移 + 全字段往返(含 v13 翻转字段)通过,exit 0。+- 实卡烟测:`veyra.exe "capture:0:0:-1:0" --smoke-seconds 8 --no-nr --no-sr --no-fg --capture-flip` exit 0、`frames=458`、`failed=false`、`captureDropped=0`,日志 `[capture-flip] manual vertical flip=1`(YUY2 路径翻转后仍稳定)。+- delivery 短测 23/23 PASS,48.69 秒,`logs/delivery/94abadd1321948ad84fb46a1c1920e0a/result.json`,EXE SHA256 `A7AF379D7DD7F6183965CED7E01CA7ED423EE747CBAB28AE514C65E3127B8CFD`(gate 自身仍标 `capture=awaiting_user_capture_test`)。++## 4. 边界与未执行++- 本机没有 RGB24 设备:"A 的 top-down 协商在问题卡上是否被驱动接受"须受影响用户实机确认;若被拒绝,用 B 的开关兜底。两个结果都能从 `DIB top-down request` 日志区分。+- 未打包、未发布、未推送。+- 相关但独立:PS5"无法打开视频"回归(隔离分支 1.3.1beta 的 dangling else)**不在 main**;main 原本没有该缺陷,本轮只把同一处 `else` 补了大括号防呆。分支上的两个修复存档在 `checkpoint/ps5-rgb24-fixes-20260916`(提交 `015f8a4`)。diff --git a/docs/WORKLOG.md b/docs/WORKLOG.mdindex 61fe066a..bcf35ae0 100644--- a/docs/WORKLOG.md+++ b/docs/WORKLOG.md@@ -1,5 +1,15 @@# 2026-09-11 继续修复目标模式执行中+## 2026-09-16 RGB24 采集倒像修复并入 main(用户选定 A+B,不做强制转换 C)++用户完成隔离分支上的两个修复后,要求把修复并入 main 并建立 git 存档。审计发现 main(693db07)**不包含** 2ffb5c7(采集音频手动入口),因此 PS5"无法打开视频"回归只存在于隔离分支与由其打出的 1.3.1beta 测试包;main 原本没有该缺陷。本次在 main 只移植 RGB24 方向修复,并把同一处 `else` 补上大括号防呆(行为不变)。++内容:直连 RGB DIB(RGB24/RGB32/ARGB32/555/565)且 `biHeight>0` 时先向驱动协商 top-down(`SetFormat` 负高度),接受则按实际连接类型不翻转,拒绝则保持原符号翻转;新增采集面板"画面上下翻转"开关(`captureFlipVertical`,按样本立即生效、预设 schema v12→v13、`--capture-flip` 仅诊断);`copyCaptureSample` 支持可选翻转参数(RGB 与 YUV 通用,YUV 色度行同步翻转);采集颜色测试补上真正的方向断言(此前单元用例自证式、GPU 用例每行相同,上下翻转测不出来)。++验证:`cmd.exe /c out\build\veyra-build-x64-release.cmd` exit 0(166/166);`veyra_capture_color_tests.exe` failures=0(新增方向用例全 PASS);`veyra_repair_contract_tests.exe` 145 checks 0 failures;`veyra_repair_preset_tests.exe <tmp>` 48 组迁移 + 全字段往返通过;实卡烟测 `capture:0:0:-1:0 --smoke-seconds 8 --capture-flip` exit 0、frames=458、failed=false、captureDropped=0,日志 `[capture-flip] manual vertical flip=1`;delivery 短测 23/23 PASS,48.69 秒,`logs/delivery/94abadd1321948ad84fb46a1c1920e0a/result.json`,EXE SHA256 `A7AF379D7DD7F6183965CED7E01CA7ED423EE747CBAB28AE514C65E3127B8CFD`。++未执行:本机无 RGB24 设备,`DIB top-down request` 协商是否被问题卡接受仍待受影响用户实机确认(被拒绝时用面板开关兜底);未打包、未发布、未 push。分支侧两个修复的存档为 `015f8a4` / tag `checkpoint/ps5-rgb24-fixes-20260916`,main 侧为 tag `checkpoint/main-rgb24-orientation-20260916`。完整记录见 [RGB24 采集倒像修复](CAPTURE_RGB24_ORIENTATION_2026-09-16.md)。+## 2026-09-15 采集卡直播窗口标题修复(第三方工具“识别不到 Veyra”)用户反馈除 OBS 外各平台直播工具无法识别“正在采集中的 Veyra”,且顺序敏感:先抓到窗口再开采集卡正常,先开采集卡再抓就抓不到。实机取证确认根因是 Veyra 自己:采集卡来源 `capture:`/`capture2:` 连接串被当文件名写进主窗口标题,实测标题长 776 字符(`Veyra — capture2:<十六进制设备路径>:...`),空闲/播放文件时为正常短名;直播伴侣日志把该标题截断到 259 字符后参与来源命名,其包内前端以 `${exe} ${title}` 命名来源。同场会话的 mediasdk_server 日志显示“采集卡已运行再添加 game 来源”的 hook 通路实际成功(`Load Shared Texture Success, size: 842 x 494`、`OnAutoSwitchMode from Window to Game`、GameSource 连续 60 秒以上有数据),因此本轮不做换链/画面的猜测性改动。diff --git a/include/veyra/engine/EnhancementSettings.h b/include/veyra/engine/EnhancementSettings.hindex d6853ce7..ceeaa525 100644--- a/include/veyra/engine/EnhancementSettings.h+++ b/include/veyra/engine/EnhancementSettings.h@@ -70,6 +70,12 @@ struct EnhancementSettings {bool lowLatency=false; // preview only: NR before SR, opt-inNrRuntime nrRuntime=NrRuntime::Original;bool captureCompatible=false;+ // 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,+ // this is the manual fallback when a driver still misreports. Applies to+ // the next sample, so it is a live edit, not a graph rebuild.+ bool captureFlipVertical=false;bool forceSdrPreview=false; // display only; retain actual HDR source metadatabool useHdrPreview(bool hdrInput,bool hdrDisplayActive)const{return hdrInput&&hdrDisplayActive&&!forceSdrPreview;}pipeline::SrTarget srTarget=pipeline::SrTarget::Uhd4K;@@ -89,6 +95,9 @@ struct EnhancementSettings {video.revision=other.revision;video.audioSync=other.audioSync;video.audioOffsetMs=other.audioOffsetMs;+ // Capture flip is applied per sample on the source's callback thread;+ // toggling it must not rebuild the graph.+ video.captureFlipVertical=other.captureFlipVertical;return video==other;}void rejectVideoRequest(const EnhancementSettings& attempted,const EnhancementSettings& previous) {diff --git a/include/veyra/source/CaptureCardSource.h b/include/veyra/source/CaptureCardSource.hindex e4c4f968..e4784a80 100644--- a/include/veyra/source/CaptureCardSource.h+++ b/include/veyra/source/CaptureCardSource.h@@ -42,6 +42,10 @@ public:// Owner-thread recovery of DirectShow audio pins; same video filter retained.void recoverAudio(float gain,unsigned syncMode,int offsetMs);bool setAudioGain(float); // call on the graph owner thread; never system volume+ // 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.+ void setVerticalFlip(bool enabled);CaptureMetrics metrics()const;void videoPresented(double ptsMs,int64_t host100ns,int64_t arrival100ns);void videoReset(bool resetAudio=true);diff --git a/include/veyra/source/CaptureMediaType.h b/include/veyra/source/CaptureMediaType.hindex d9669cf2..d48345aa 100644--- a/include/veyra/source/CaptureMediaType.h+++ b/include/veyra/source/CaptureMediaType.h@@ -22,6 +22,20 @@ struct CaptureMediaLayout {unsigned planes=1,chromaStride=0,chromaRowBytes=0;size_t chromaOffset=0,secondChromaOffset=0;};+// Walk the AM_MEDIA_TYPE's format block without assuming VideoInfo vs+// VideoInfo2; used to read/rewrite the DIB orientation flag in place.+inline BITMAPINFOHEADER* captureBitmapHeader(AM_MEDIA_TYPE& type){+ if(!type.pbFormat)return nullptr;+ if(type.formattype==FORMAT_VideoInfo&&type.cbFormat>=sizeof(VIDEOINFOHEADER))return &reinterpret_cast<VIDEOINFOHEADER*>(type.pbFormat)->bmiHeader;+ if(type.formattype==FORMAT_VideoInfo2&&type.cbFormat>=sizeof(VIDEOINFOHEADER2))return &reinterpret_cast<VIDEOINFOHEADER2*>(type.pbFormat)->bmiHeader;+ return nullptr;+}+// RGB DIB packings are the only ones whose biHeight sign describes storage+// order; YUV formats are always top-down (see captureMediaLayout).+constexpr bool captureIsRgbDib(CapturePacking packing){+ return packing==CapturePacking::Bgr32||packing==CapturePacking::Bgra32||packing==CapturePacking::Bgr24||+ packing==CapturePacking::Rgb555||packing==CapturePacking::Rgb565;+}// Parse negotiated memory layout, not the UI's requested dimensions. YUV is// top-down for either sign of biHeight; only RGB DIBs use bottom-up storage.inline bool captureMediaLayout(const AM_MEDIA_TYPE& type,CaptureMediaLayout& out){@@ -97,13 +111,17 @@ inline bool captureMediaLayout(const AM_MEDIA_TYPE& type,CaptureMediaLayout& out}return true;}-inline bool copyCaptureSample(const CaptureMediaLayout& layout,const uint8_t* src,size_t bytes,AVFrame& dst){+// flipVertical is the manual capture override: it inverts whatever the DIB+// header claims (and reverses chroma rows for planar YUV), so a device whose+// declared orientation does not match its samples can still be watched.+inline bool copyCaptureSample(const CaptureMediaLayout& layout,const uint8_t* src,size_t bytes,AVFrame& dst,bool flipVertical=false){if(!src||bytes<layout.sampleBytes||dst.format!=layout.format||dst.width!=int(layout.width)||dst.height!=int(layout.height)||!dst.data[0]||dst.linesize[0]<int(layout.rowBytes))return false;if(layout.format==AV_PIX_FMT_BGR0&&dst.linesize[0]<int(layout.width*4))return false;if(layout.planes>1&&(!dst.data[1]||dst.linesize[1]<int(layout.chromaRowBytes)))return false;if(layout.planes>2&&(!dst.data[2]||dst.linesize[2]<int(layout.chromaRowBytes)))return false;+ const bool flip=layout.bottomUp!=flipVertical;for(unsigned y=0;y<layout.height;++y){- const auto* s=src+size_t(layout.bottomUp?layout.height-1-y:y)*layout.stride;auto* d=dst.data[0]+ptrdiff_t(y)*dst.linesize[0];+ const auto* s=src+size_t(flip?layout.height-1-y:y)*layout.stride;auto* d=dst.data[0]+ptrdiff_t(y)*dst.linesize[0];if(layout.packing==CapturePacking::Bgr24){for(unsigned x=0;x<layout.width;++x){d[x*4]=s[x*3];d[x*4+1]=s[x*3+1];d[x*4+2]=s[x*3+2];d[x*4+3]=255;}}else if(layout.packing==CapturePacking::Rgb555||layout.packing==CapturePacking::Rgb565){const bool six=layout.packing==CapturePacking::Rgb565;@@ -113,7 +131,7 @@ inline bool copyCaptureSample(const CaptureMediaLayout& layout,const uint8_t* sr}else std::memcpy(d,s,layout.rowBytes);}for(unsigned p=1;p<layout.planes;++p)for(unsigned y=0;y<layout.height/2;++y){- const auto* s=src+(p==1?layout.chromaOffset:layout.secondChromaOffset)+size_t(y)*layout.chromaStride;auto* d=dst.data[p]+ptrdiff_t(y)*dst.linesize[p];+ const auto* s=src+(p==1?layout.chromaOffset:layout.secondChromaOffset)+size_t(flip?layout.height/2-1-y:y)*layout.chromaStride;auto* d=dst.data[p]+ptrdiff_t(y)*dst.linesize[p];if(layout.packing==CapturePacking::Nv21){for(unsigned x=0;x<layout.chromaRowBytes;x+=2){d[x]=s[x+1];d[x+1]=s[x];}}else std::memcpy(d,s,layout.chromaRowBytes);}diff --git a/src/engine/EngineController.cpp b/src/engine/EngineController.cppindex ad1ce2ab..8588b9f3 100644--- a/src/engine/EngineController.cpp+++ b/src/engine/EngineController.cpp@@ -166,6 +166,11 @@ void EngineController::run(HWND window,std::wstring path,PlayerOptions options,sif(!isCapture&&GetEnvironmentVariableW(L"VEYRA_TEST_FILE_HW_DECODE",nullptr,0)){od.preferHardwareDecode=true;od.d3d12Device=ctx.device();od.d3d12Queue=ctx.directQueue();}+ // Capture ingest flip is a per-sample source-side property; set+ // it before the branch chain so the first sample already honors+ // it. Never insert statements between `}else` and the open call+ // below: the `else` only binds to the next single statement.+ captureSource.setVerticalFlip(options.settings.captureFlipVertical);#ifdef VEYRA_ENABLE_REMOTEPLAYif(remote){status(L"正在连接 PS5…");@@ -182,9 +187,12 @@ void EngineController::run(HWND window,std::wstring path,PlayerOptions options,sstd::this_thread::sleep_for(std::chrono::milliseconds(2));}if(stop_||!cachedFrame)break;- }else+ }else{#endifif(!(physicalCapture?captureSource.configure(od):activeSource->open(od))){status(!isCapture&&!source.errorMessage().empty()?source.errorMessage():L"无法打开视频,请查看诊断",true);break;}+#ifdef VEYRA_ENABLE_REMOTEPLAY+ }+#endif// A file's actual decoded pixel format and HDR VUI are only// reliable on AVFrame. Prime one frame before constructing// the graph so AV1/MOV 10-bit and HDR inputs do not get an@@ -273,6 +281,7 @@ void EngineController::run(HWND window,std::wstring path,PlayerOptions options,sif(graph.xessEnabled()&&!presenter.xessActive())snapshot_.backendWarning=L"XeSS 初始化失败;当前为普通呈现";}captureSource.setAudioSync(unsigned(options.settings.audioSync),options.settings.audioOffsetMs);+ captureSource.setVerticalFlip(options.settings.captureFlipVertical);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(性能成本较高)"));@@ -486,6 +495,7 @@ void EngineController::run(HWND window,std::wstring path,PlayerOptions options,s++captureRetries;{std::lock_guard lock(mutex_);snapshot_.captureReconnectAttempts=captureRetries;}status(std::format(L"采集信号中断,正在重连原设备(第 {} 次)",captureRetries));+ captureSource.setVerticalFlip(options.settings.captureFlipVertical);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;}@@ -507,6 +517,7 @@ void EngineController::run(HWND window,std::wstring path,PlayerOptions options,sconst float gain=muted_?0.0f:volume_.load();audio.setGain(gain);if(physicalCapture)captureSource.recoverAudio(gain,unsigned(options.settings.audioSync),options.settings.audioOffsetMs);captureSource.setAudioSync(unsigned(options.settings.audioSync),options.settings.audioOffsetMs);+ captureSource.setVerticalFlip(options.settings.captureFlipVertical);if(physicalCapture){const bool available=captureSource.setAudioGain(gain);const auto audioState=captureSource.audioState();std::lock_guard lock(mutex_);snapshot_.audioAvailable=available;snapshot_.captureAudio=audioState;snapshot_.audioInputChannels=audioState.inputChannels;snapshot_.audioOutputChannels=audioState.outputChannels;}#ifdef VEYRA_ENABLE_REMOTEPLAYif(remote){remote->setAudioGain(gain);remote->setAudioSync(unsigned(options.settings.audioSync),options.settings.audioOffsetMs);@@ -524,6 +535,13 @@ void EngineController::run(HWND window,std::wstring path,PlayerOptions options,sif(requested.revision==options.settings.revision&&requested!=options.settings){options.settings.audioSync=requested.audioSync;options.settings.audioOffsetMs=requested.audioOffsetMs;captureSource.setAudioSync(unsigned(requested.audioSync),requested.audioOffsetMs);+ // The manual capture flip is applied per sample on the+ // DirectShow callback thread, so it is a live edit.+ if(requested.captureFlipVertical!=options.settings.captureFlipVertical){+ options.settings.captureFlipVertical=requested.captureFlipVertical;+ captureSource.setVerticalFlip(requested.captureFlipVertical);+ status(requested.captureFlipVertical?L"采集画面已上下翻转(仅影响本机采集画面)":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.cppindex fc01f761..b30a0858 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()!=Lstd::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 12\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<<'\n';}return o.str();+ std::ostringstream o;o.imbue(std::locale::classic());o<<std::setprecision(std::numeric_limits<float>::max_digits10)<<"VEYRA_PRESETS 13\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<<' '<<s.captureFlipVertical<<'\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>12)||!(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>13)||!(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;@@ -36,6 +36,8 @@ bool PresetStore::parse(const std::string& data,std::vector<UserPreset>& out,stdif(version>=10){int capture;if(!(in>>capture)||capture<0||capture>1)return false;s.captureCompatible=capture!=0;}if(version>=11){int low;if(!(in>>low)||low<0||low>1)return false;s.lowLatency=low!=0;}if(version>=12){int sdr;if(!(in>>sdr)||sdr<0||sdr>1)return false;s.forceSdrPreview=sdr!=0;}+ // v13 appends the manual capture vertical flip to the line.+ if(version>=13){int flip;if(!(in>>flip)||flip<0||flip>1)return false;s.captureFlipVertical=flip!=0;}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.cppindex 537d6a1a..bc828ec1 100644--- a/src/source/CaptureCardSource.cpp+++ b/src/source/CaptureCardSource.cpp@@ -123,6 +123,8 @@ struct CaptureCardSource::Impl:ISampleGrabberCB {Clock::time_point pendingArrival{},readArrival{},firstArrival{},latestArrival{};ComPtr<IGraphBuilder> graph;ComPtr<ICaptureGraphBuilder2> builder;ComPtr<IBaseFilter> device,grabFilter,nullFilter,audioFilter;ComPtr<IAMStreamConfig> config;ComPtr<ISampleGrabber> grab;ComPtr<IMediaControl> control;ComPtr<IMediaEvent> events;float lastAudioGain=-1;bool audioGainSupported=false;+ // Manual capture flip; read by the DirectShow callback thread.+ std::atomic<bool> verticalFlip{false};ComPtr<IBaseFilter> audioSink;ComPtr<IReferenceClock> referenceClock;std::unique_ptr<sink::CaptureAudioSession> audioSession;std::unique_ptr<WasapiAudioInput> wasapi;@@ -143,7 +145,7 @@ struct CaptureCardSource::Impl:ISampleGrabberCB {else {// Copy directly into our bounded mailbox; read() swaps frames// under this lock, so the frame consumed by the GPU is untouched.- if(!copyCaptureSample(layout,data,size_t(sample->GetActualDataLength()),*pendingFrame)){callbackError=true;wake.notify_one();return S_OK;}+ if(!copyCaptureSample(layout,data,size_t(sample->GetActualDataLength()),*pendingFrame,verticalFlip.load())){callbackError=true;wake.notify_one();return S_OK;}if(pending)++dropped;// Inspect consecutive callbacks, not consecutive mailbox reads.// Preserve a driver/clock break when its sample is overwritten.@@ -215,6 +217,11 @@ bool CaptureCardSource::setAudioGain(float gain){if(SUCCEEDED(hr)){long attenuation=gain<=0?-10000:long(std::clamp(2000.0*std::log10(double(gain)),-10000.0,0.0));hr=audio->put_Volume(attenuation);}p.lastAudioGain=gain;p.audioGainSupported=SUCCEEDED(hr);log::info("capture-audio",std::format("application gain={} hr=0x{:X}",gain,unsigned(hr)));return p.audioGainSupported;}+void CaptureCardSource::setVerticalFlip(bool enabled){+ auto& p=*p_;+ if(p.verticalFlip.exchange(enabled)==enabled)return;+ log::info("capture-flip",std::format("manual vertical flip={} (applies to the next sample; ingest only)",enabled?1:0));+}void CaptureCardSource::videoPresented(double pts,int64_t time,int64_t arrival){if(p_->wasapi)p_->wasapi->videoPresented(double(arrival)/10000,time,arrival);else if(p_->audioSession)p_->audioSession->videoPresented(pts,time,arrival);@@ -235,6 +242,28 @@ bool CaptureCardSource::configure(const SourceOpenDesc& desc){close();p_->lastAuCaptureMediaLayout nativeLayout;const bool nativeSupported=captureMediaLayout(*native,nativeLayout);if(!nativeSupported&&capturePacking(native->subtype)!=CapturePacking::Unknown){log::error("capture","Known raw format has unsupported layout/color metadata; refusing implicit RGB conversion");freeType(native);return false;}if(nativeSupported&&(nativeLayout.format==AV_PIX_FMT_P010||nativeLayout.format==AV_PIX_FMT_P016)&&desc.legacyCaptureRgbForDiagnostic){log::error("capture","10/16-bit capture cannot use the legacy 8-bit RGB diagnostic converter");freeType(native);return false;}+ // Some drivers advertise a bottom-up DIB (biHeight>0) while their samples+ // actually arrive top-down, which users reported as "RGB24 captures upside+ // down". Ask for an explicit top-down connection first: an accepted request+ // normalizes the mismatch (connected type is then negative and no flip is+ // applied), a refusal keeps the driver-declared sign and the existing flip.+ // Truthful bottom-up devices stay correct in both cases.+ if(nativeSupported&&captureIsRgbDib(nativeLayout.packing)){+ if(auto* header=captureBitmapHeader(*native);header&&header->biHeight>0){+ const LONG advertised=header->biHeight;header->biHeight=-advertised;+ const HRESULT topDownHr=p.config->SetFormat(native);+ if(SUCCEEDED(topDownHr)){+ AM_MEDIA_TYPE* refreshed=nullptr;CaptureMediaLayout refreshedLayout;+ if(SUCCEEDED(p.config->GetFormat(&refreshed))&&refreshed&&captureMediaLayout(*refreshed,refreshedLayout)){+ freeType(native);native=refreshed;nativeLayout=refreshedLayout;+ }else freeType(refreshed);+ log::info("capture",std::format("DIB top-down request hr=0x{:08X} subtype=0x{:08X} accepted=1 bottomUp={}",uint32_t(topDownHr),native->subtype.Data1,nativeLayout.bottomUp));+ }else{+ header->biHeight=advertised;+ log::info("capture",std::format("DIB top-down request hr=0x{:08X} subtype=0x{:08X} accepted=0 bottomUp={} (keeping driver-declared orientation)",uint32_t(topDownHr),native->subtype.Data1,nativeLayout.bottomUp));+ }+ }+ }const bool direct=nativeSupported&&!desc.legacyCaptureRgbForDiagnostic;AM_MEDIA_TYPE connected{};if(direct){diff --git a/tests/unit/CaptureFormatCases.h b/tests/unit/CaptureFormatCases.hindex 7d74790f..4b5989a4 100644--- a/tests/unit/CaptureFormatCases.h+++ b/tests/unit/CaptureFormatCases.h@@ -50,6 +50,28 @@ template<class Check> void captureFormatCases(Check check){for(unsigned y=0;y<4;++y){raw[y*l.stride]=0;raw[y*l.stride+1]=id==MEDIASUBTYPE_RGB565?0xf8:0x7c;}check(copyCaptureSample(l,raw.data(),raw.size(),*f)&&f->data[0][0]==0&&f->data[0][1]==0&&f->data[0][2]==255,"RGB555/565 red channel masks");av_frame_free(&f);}+ // Orientation contract: the DIB sign decides whether ingest flips, the+ // manual override inverts that decision, and planar chroma follows luma.+ {+ vi.bmiHeader.biWidth=4;vi.bmiHeader.biHeight=4;vi.bmiHeader.biSizeImage=0;t.subtype=MEDIASUBTYPE_RGB24;CaptureMediaLayout rgb;+ check(captureMediaLayout(t,rgb),"RGB24 bottom-up layout for the orientation cases");+ std::vector<uint8_t> raw(rgb.sampleBytes,0);+ for(unsigned y=0;y<4;++y)raw[size_t(y)*rgb.stride]=uint8_t(y+1);+ AVFrame* f=av_frame_alloc();f->width=4;f->height=4;f->format=rgb.format;av_frame_get_buffer(f,32);+ check(rgb.bottomUp&©CaptureSample(rgb,raw.data(),raw.size(),*f)&&f->data[0][0]==4,"bottom-up RGB24 ingest reads the last memory row first");+ check(copyCaptureSample(rgb,raw.data(),raw.size(),*f,true)&&f->data[0][0]==1,"manual flip inverts bottom-up RGB24 ingest");+ vi.bmiHeader.biHeight=-4;+ check(captureMediaLayout(t,rgb)&&!rgb.bottomUp&©CaptureSample(rgb,raw.data(),raw.size(),*f)&&f->data[0][0]==1,"top-down RGB24 ingest passes rows through");+ check(copyCaptureSample(rgb,raw.data(),raw.size(),*f,true)&&f->data[0][0]==4,"manual flip inverts top-down RGB24 ingest");+ av_frame_free(&f);+ t.subtype=fourcc("NV12");vi.bmiHeader.biWidth=4;vi.bmiHeader.biHeight=4;vi.bmiHeader.biSizeImage=0;CaptureMediaLayout yuv;+ check(captureMediaLayout(t,yuv),"NV12 layout for the chroma flip case");+ std::vector<uint8_t> plane(yuv.sampleBytes,0);plane[yuv.chromaOffset]=10;plane[yuv.chromaOffset+yuv.chromaStride]=11;+ AVFrame* g=av_frame_alloc();g->width=4;g->height=4;g->format=yuv.format;av_frame_get_buffer(g,32);+ check(copyCaptureSample(yuv,plane.data(),plane.size(),*g)&&g->data[1][0]==10,"YUV ingest stays top-down without the override");+ check(copyCaptureSample(yuv,plane.data(),plane.size(),*g,true)&&g->data[1][0]==11,"manual flip reverses chroma rows too");+ av_frame_free(&g);+ }t.subtype=fourcc("P010");DXVA2_ExtendedFormat ext{};ext.VideoTransferFunction=16;vi.dwControlFlags=ext.value|AMCONTROL_COLORINFO_PRESENT;check(captureMediaLayout(t,l)&&l.color.transfer==veyra::pipeline::TransferFunction::HLG&&!l.color.transferAssumed,"capture HLG metadata is retained, never silently interpreted as SDR");vi.dwControlFlags=0;t.subtype=fourcc("ABCD");check(capturePixelName(t.subtype)==L"ABCD"&&!captureMediaLayout(t,l),"unknown FourCC readable but not advertised as native");diff --git a/tests/unit/RepairContractTests.cpp b/tests/unit/RepairContractTests.cppindex 165b704f..fef6b14c 100644--- a/tests/unit/RepairContractTests.cpp+++ b/tests/unit/RepairContractTests.cpp@@ -148,6 +148,7 @@ int main(){check(pipeline::ResolutionPlan::make({1448,1086},true,pipeline::NrSizePolicy::Native,true,1,pipeline::SrTarget::Uhd8K).output==pipeline::Extent{5760,4320},"8K 4:3 aspect preserved");check(pipeline::ResolutionPlan::make({8000,2000},true,pipeline::NrSizePolicy::Native,true,1,pipeline::SrTarget::Qhd).output==pipeline::Extent{8000,2000},"small target never shrinks long image");engine::EnhancementSettings s;check(s.validate().empty(),"default settings valid");+ check(!s.captureFlipVertical,"capture vertical flip defaults off");auto audioOnly=s;audioOnly.revision=2;audioOnly.audioSync=engine::AudioSyncMode::Manual;audioOnly.audioOffsetMs=90;check(audioOnly.sameVideoConfiguration(s),"audio changes do not invalidate video configuration");auto attempted=audioOnly;attempted.model.style=1;diff --git a/tests/unit/RepairPresetTests.cpp b/tests/unit/RepairPresetTests.cppindex b6774c1d..4cde28dd 100644--- a/tests/unit/RepairPresetTests.cpp+++ b/tests/unit/RepairPresetTests.cpp@@ -35,7 +35,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!=12)return false;+ if(magic!="VEYRA_PRESETS"||savedVersion!=13)return false;PresetStore reloaded(path);if(!reloaded.load()||reloaded.defaultSettings()!=value)return false;}else{@@ -69,6 +69,9 @@ int main(int argc,char** argv){if(argc!=2)return 2;using namespace veyra::engineauto half=s;half.content=ContentRate::Capture60To30;ok=ok&&b.put(L"capture half rate",half);PresetStore halfReload(p);ok=ok&&halfReload.load()&&halfReload.entries().back().settings.content==ContentRate::Capture60To30&&b.erase(1);auto badSr=s;badSr.videoSrQuality=5;ok=ok&&!b.put(L"invalid video SR",badSr);auto invalid=s;invalid.model.tone=9;ok=ok&&!b.put(L"bad",invalid)&&b.entries().size()==1&&b.erase(0)&&b.entries().empty();+ // Manual capture vertical flip (v13) 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);auto badRegion=s;badRegion.protection.regions[0].left=2;ok=ok&&!b.put(L"invalid region",badRegion);{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);