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++
Correct mismatched capture timestamps on the preview clock
Veyra Goal Agent1b6a4e2cc36d
diff --git a/docs/WORKLOG.md b/docs/WORKLOG.mdindex 4f728d14..aa6bc7ab 100644--- a/docs/WORKLOG.md+++ b/docs/WORKLOG.md@@ -967,3 +967,14 @@ VB-Audio 许可允许在符合捐赠软件条款时附带原安装包,未找回执 `E:/项目/Veyra/reports/codex-capture-dedup-pacing-20261110/FINAL.json`,逐帧日志在同任务 `logs` 目录。独立启动入口 `E:/项目/Veyra/tests/codex-capture-dedup-pacing-20261110/启动去重补帧测试.cmd`。验收后核对 QML 探针已恢复,E:/App 的正式 EXE 哈希保持发布值。用户恢复画面后复测。初轮输入几乎静止,补帧状态退出导致夹具终止。重测的起始信号切换期有 8 次采集丢弃记录,未纳入稳态。04:41:32.000–04:42:01.809(PST)稳态 29.809 秒,采集内容 40.02 FPS、提交 119.90 FPS、1% low 中位 109.75、提交间隔 P99 9.11 ms,采集丢弃、邮箱覆盖、补帧降档和过期均无新增。复测日志 logs/codex-capture-dedup-pacing-20261110/fixed-soak-retry/engine.log,同任务 FINAL.json 已补充逐帧统计。+++## 2026-11-10 59.94 采集的异常预览时间戳校正++隔离分支 `codex/capture-pts-clock-20261110` 基于已验的去重呈现分支 `8b20d55`。针对原生 59–61 FPS 物理采集预览,在内容去重及 60→30 之前比较驱动 PTS、序号和单调回调时间。协商速率附近的稳定回调在跨 16 个采集序号的窗口内,与 PTS 累计跨度偏差达到 12.5% 才锁定校正。校正时间轴以采集序号推进,缓慢跟随回调时钟并抑制单帧抖动。正常 PTS 保留,持续恢复正常或真实断档时退回原时间轴并显式断开图历史。音频路径仍使用驱动原始时间和到达时间。++复用 `build/codex-capture-dedup-pacing-20261110`,用 `scripts/acceptance/build-recording-handoff.py` 固定依赖重新配置显示版号 2.1.4-capture-clock-test,构建 veyra_qml_ui 和 veyra_live_timing_tests。首次 82.7 秒,恢复无注入版本后增量 13.4 秒。时序 172 项通过,包含正常 59.94、真实可变到达、20.83 ms 错标、531 ms 断流、原 PTS 恢复和邮箱跳号。++T911 实卡 4K NV12 接受指定 59.94,协商 59.939820,正常回调和驱动帧长约 16.68 ms。默认格式协商 60.000240,实际回调也约 60。两个正常输入都没有触发校正。保持 T911 59.94 回调、60→30、FSR 3.1 2X,用独立测试编译把视频 PTS 改成 20.8333 ms。20 秒 A/B 原帧 749→600,提交 67.884→59.942 FPS,提交间隔 P99 27.33→17.33 ms,生成帧过期 135→0。最终测试程序不含注入代码,独立 QML 探针已恢复。未复测故障用户的 Elgato/AMD 或物理屏幕扫描。++入口 `E:/项目/Veyra/tests/codex-capture-pts-clock-20261110/启动采集时钟测试.cmd`。回执 `E:/项目/Veyra/reports/codex-capture-pts-clock-20261110/FINAL.json`,原始逐帧日志在同任务 logs 目录。diff --git a/include/veyra/engine/CapturePreviewClock.h b/include/veyra/engine/CapturePreviewClock.hnew file mode 100644index 00000000..2ec2276d--- /dev/null+++ b/include/veyra/engine/CapturePreviewClock.h@@ -0,0 +1,84 @@+#pragma once+#include <algorithm>+#include <cstdint>+#include <cstdlib>++namespace veyra::engine {+// Preview-only correction for a raw capture clock whose timestamps drift+// significantly from a stable callback cadence. Times are in 100 ns units.+class CapturePreviewClock {+ struct Sample {+ uint64_t sequence = 0;+ int64_t pts = 0;+ int64_t arrival = 0;+ };+ Sample previous_, window_;+ int64_t correctedPts_ = 0;+ int64_t anchorPts_ = 0;+ int64_t anchorArrival_ = 0;+ bool correcting_ = false;++public:+ struct Result {+ int64_t pts;+ bool corrected;+ bool discontinuity;+ };++ bool correcting() const { return correcting_; }++ Result observe(uint64_t sequence, int64_t pts, int64_t arrival, int64_t period, bool boundary) {+ const Sample sample{sequence, pts, arrival};+ if (!previous_.sequence || boundary || sequence <= previous_.sequence || period <= 0 ||+ arrival <= previous_.arrival || pts <= previous_.pts) {+ return restart(sample, correcting_);+ }++ const auto count = sequence - previous_.sequence;+ const int64_t arrivalSpan = arrival - previous_.arrival;+ const int64_t expected = static_cast<int64_t>(count) * period;+ const int64_t slack = period / 3 + expected / 40;+ if (std::llabs(arrivalSpan - expected) > slack) {+ // Sequence gaps can come from a late reader. Only excess wall time+ // establishes a source stall when the driver's PTS hides it.+ return restart(sample, correcting_ || arrivalSpan - expected > 1000000);+ }++ bool changed = false;+ const auto windowCount = sequence - window_.sequence;+ if (windowCount >= 16) {+ const int64_t hostSpan = arrival - window_.arrival;+ const int64_t ptsSpan = pts - window_.pts;+ const int64_t expectedSpan = static_cast<int64_t>(windowCount) * period;+ const bool stable = std::llabs(hostSpan - expectedSpan) <= expectedSpan / 40;+ const int64_t error = std::llabs(ptsSpan - hostSpan);+ if (correcting_ && (!stable || error <= hostSpan / 20))+ return restart(sample, true);+ if (!correcting_ && stable && error >= hostSpan / 8) {+ correcting_ = changed = true;+ anchorPts_ = correctedPts_ = previous_.pts + expected;+ anchorArrival_ = arrival;+ }+ window_ = sample;+ }++ previous_ = sample;+ if (!correcting_) return {pts, false, false};+ if (!changed) {+ correctedPts_ += expected;+ // Follow slow drift against the callback clock while rejecting the+ // per-frame delivery jitter. The result advances monotonically.+ const auto phaseError = anchorPts_ + arrival - anchorArrival_ - correctedPts_;+ correctedPts_ += std::clamp(phaseError / 16, -period / 64, period / 64);+ }+ return {correctedPts_, true, changed};+ }++private:+ Result restart(Sample sample, bool discontinuity) {+ previous_ = window_ = sample;+ correcting_ = false;+ return {sample.pts, false, discontinuity};+ }+};+}diff --git a/src/engine/EngineController.cpp b/src/engine/EngineController.cppindex 7985e09f..21b81a46 100644--- a/src/engine/EngineController.cpp+++ b/src/engine/EngineController.cpp@@ -24,6 +24,7 @@#include "veyra/engine/RealtimePreviewScheduling.h"#include "veyra/engine/CaptureHalfRate.h"#include "veyra/engine/ContentDedup.h"+#include "veyra/engine/CapturePreviewClock.h"#include "veyra/engine/DisplayFgBudget.h"#include "veyra/source/MediaFileSource.h"#include "veyra/source/CaptureCardSource.h"@@ -1109,6 +1110,7 @@ void EngineController::run(HWND window,std::wstring path,PlayerOptions options,suint64_t fedXessPresented=0,fedXessGenerated=0;double playbackSpeedLastPts=0;Clock::time_point playbackSpeedLastWall{};CaptureHalfRate captureSampler;+ CapturePreviewClock capturePreviewClock;// Content cadence for live sources (ContentDedup.h): in the auto / 30 / 50 /// 60 fps content modes, repeated pictures (every component within the// capture-noise band, PictureCompare.h) are dropped before any GPU work and@@ -2087,10 +2089,28 @@ void EngineController::run(HWND window,std::wstring path,PlayerOptions options,sconst bool dedupActive=isCapture&&!isImage&&!legacyCadence&&dedupContent(options.settings.content);// The callback compares whole pictures only while dedup or the 60->30 phase needs them.if(physicalCapture)captureSource.setPictureCompare(dedupActive||halfRate);+ const int64_t driverPts100ns=pkt.pts.isUnknown()?0:pkt.pts.to100ns();+ const auto capturePeriod=liveSourceInterval100ns(pipeline::Rational::unknown(),activeSource->info().averageFps);+ bool captureClockCorrected=false;+ if(physicalCapture&&!nativeCapture&&!captureSource.compressedVideo()&&!rereadCached&&+ CaptureHalfRate::supported(activeSource->info().averageFps)&&!pkt.pts.isUnknown()&&pkt.arrivalHost100ns>0){+ const bool wasCorrecting=capturePreviewClock.correcting();+ const auto flagsWithoutDrop=pkt.flags&~static_cast<pipeline::FrameFlags>(pipeline::FrameFlagBits::Drop);+ const auto clock=capturePreviewClock.observe(pkt.sequence,driverPts100ns,pkt.arrivalHost100ns,capturePeriod,+ pipeline::breaksHistory(flagsWithoutDrop)||pipeline::hasFrameFlag(pkt.flags,pipeline::FrameFlagBits::Open));+ captureClockCorrected=clock.corrected;+ if(clock.discontinuity)pkt.flags|=static_cast<pipeline::FrameFlags>(pipeline::FrameFlagBits::Discontinuity);+ if(wasCorrecting!=clock.corrected)+ veyra::log::info("capture-preview-clock",std::format("source={} corrected={} driverPts100ns={} previewPts100ns={} nominalPeriod100ns={} (video scheduling only)",pkt.sequence,clock.corrected,driverPts100ns,clock.pts,capturePeriod));+ if(clock.corrected){+ pkt.pts={clock.pts,10000000};+ pkt.duration={capturePeriod,10000000};+ }+ }if(reset||pipeline::breaksHistory(pkt.flags))captureSampler.reset();- const int64_t samplePts100ns=pkt.pts.isUnknown()?0:pkt.pts.to100ns();+ const int64_t samplePts100ns=captureClockCorrected?pkt.pts.to100ns():driverPts100ns;if(dedupActive&&!rereadCached&&!pkt.pts.isUnknown()){- const auto interval=liveSourceInterval100ns(pipeline::Rational::unknown(),activeSource->info().averageFps);+ const auto interval=capturePeriod;pipeline::PictureReference::Result picture;const auto compareStart=Clock::now();const bool pictured=pipeline::captureFramePicture(frame,enginePictures,gd.packedInput==6||gd.packedInput==7,picture);@@ -2108,10 +2128,10 @@ void EngineController::run(HWND window,std::wstring path,PlayerOptions options,spkt.pts={decision.contentPts,10000000};if(decision.interval>0)pkt.duration={decision.interval,10000000};}else if(halfRate&&!rereadCached){- // 60->30: every second sample by timestamp, original PTS, a steady 30.+ // 60->30: every second sample on the effective capture clock.// Only a number the capture callback already computed is used, so the// engine thread never compares a whole picture for this.- const auto interval=liveSourceInterval100ns(pipeline::Rational::unknown(),activeSource->info().averageFps);+ const auto interval=capturePeriod;const auto* upload=pipeline::captureUploadFrame(frame);const uint64_t* picture=upload&&upload->pictureValid?&upload->pictureId:nullptr;const auto shifts=captureSampler.shifts();@@ -2125,7 +2145,7 @@ void EngineController::run(HWND window,std::wstring path,PlayerOptions options,s}if(!halfRate)captureSampler.reset();if(isCapture&&!rereadCached&&veyra::log::verboseFrameLogs())- veyra::log::info("cadence-input",std::format("source={} samplePts100ns={} pts100ns={} dedup={} halfRate={}",pkt.sequence,samplePts100ns,pkt.pts.isUnknown()?0:pkt.pts.to100ns(),dedupActive,halfRate));+ veyra::log::info("cadence-input",std::format("source={} driverPts100ns={} samplePts100ns={} pts100ns={} clockCorrected={} dedup={} halfRate={}",pkt.sequence,driverPts100ns,samplePts100ns,pkt.pts.isUnknown()?0:pkt.pts.to100ns(),captureClockCorrected,dedupActive,halfRate));if(isImage)pkt.sequence=1;#ifdef VEYRA_ENABLE_XBOXif(xb&&!rereadCached)xboxReconnectBudget.decoded(monotonic100ns());@@ -2592,7 +2612,7 @@ void EngineController::run(HWND window,std::wstring path,PlayerOptions options,spreviewSkippedSinceSubmit=0;if(transaction||frames==0){std::lock_guard lock(mutex_);snapshot_.captureHalfRate=halfRate;- veyra::log::info("capture-rate",std::format("revision={} requested60To30={} active={} transportFps={} originalPtsPreserved=true",options.settings.revision,options.settings.content==ContentRate::Capture60To30,halfRate,isCapture?activeSource->info().averageFps:0));+ veyra::log::info("capture-rate",std::format("revision={} requested60To30={} active={} transportFps={} originalPtsPreserved={}",options.settings.revision,options.settings.content==ContentRate::Capture60To30,halfRate,isCapture?activeSource->info().averageFps:0,!captureClockCorrected));}const bool pairPacing=pairAnchoredLive&&options.fg;// File replay has no device pacing and still needs its PTS clock.@@ -2659,7 +2679,7 @@ void EngineController::run(HWND window,std::wstring path,PlayerOptions options,s#ifdef VEYRA_ENABLE_XBOX&xb,#endif- &seekDecoded,&seekStarted,&audio,&audioPipe,&audioStarted,&cadence,&ctx,&fileAudioAlignPending,&fileAwaitingVideo,&fileInputEnded,&generatedDropCap,&generatedDropCapacity,&generatedDropDeadline,&playbackRate,&frameFlow,&graph,&host100ns,&isCapture,&isImage,&liveArrival,&livePresent,&liveScheduler,&nextFgDeadlineLog,&nowMs,&options,&pendingCompletions,&physicalCapture,&presentEntryDeviation,&presentReturnDeviation,&presentationEffective,&presentationGeneration,&presentationSkippedGenerated,&presenter,&ring,&runSessionId,&seekPreviewPending,&traceFrame,&traceSubframes,watch,step,timeline,captureArrival,baselineReady,delayEnhanced,activeSeekId,lineage,jobGeneration,rereadCached,sourceIntervalMs,submitThenPresent,generatedGrace=liveGeneratedGrace,smoothTransportAnchor,flow=frameFlow](int64_t now)->LiveGpuScheduler::Step{+ &seekDecoded,&seekStarted,&audio,&audioPipe,&audioStarted,&cadence,&ctx,&fileAudioAlignPending,&fileAwaitingVideo,&fileInputEnded,&generatedDropCap,&generatedDropCapacity,&generatedDropDeadline,&playbackRate,&frameFlow,&graph,&host100ns,&isCapture,&isImage,&liveArrival,&livePresent,&liveScheduler,&nextFgDeadlineLog,&nowMs,&options,&pendingCompletions,&physicalCapture,&presentEntryDeviation,&presentReturnDeviation,&presentationEffective,&presentationGeneration,&presentationSkippedGenerated,&presenter,&ring,&runSessionId,&seekPreviewPending,&traceFrame,&traceSubframes,watch,step,timeline,captureArrival,baselineReady,delayEnhanced,activeSeekId,lineage,jobGeneration,rereadCached,sourceIntervalMs,submitThenPresent,generatedGrace=liveGeneratedGrace,smoothTransportAnchor,captureClockCorrected,driverPts100ns,flow=frameFlow](int64_t now)->LiveGpuScheduler::Step{using State=LiveGpuScheduler::State;auto& batch=watch->output;auto& s=*step;auto updatePending=[&](LiveStepState*){unsigned left=0;for(unsigned i=s.next;i<batch.batch.count;++i)if(batch.batch.frames[i].kind!=pipeline::FrameKind::Generated||batch.batch.frames[i].validity==pipeline::GenerationValidity::Valid)++left;@@ -2812,7 +2832,7 @@ void EngineController::run(HWND window,std::wstring path,PlayerOptions options,s}// Real B owns captureArrival. Generated A/B frames and// paused cached frames must not invent input anchors.- if(didPresent&&physicalCapture&&!generated&&!rereadCached)captureSource.videoPresented(double(item.pts100ns)/10000,host100ns(),captureArrival);+ if(didPresent&&physicalCapture&&!generated&&!rereadCached)captureSource.videoPresented(double(captureClockCorrected?driverPts100ns:item.pts100ns)/10000,host100ns(),captureArrival);#ifdef VEYRA_ENABLE_REMOTEPLAYif(didPresent&&remote)remote->videoPresented(double(item.pts100ns)/10000,host100ns());#endifdiff --git a/tests/unit/LivePresentationTimingTests.cpp b/tests/unit/LivePresentationTimingTests.cppindex 4dccbe38..e3cf37c6 100644--- a/tests/unit/LivePresentationTimingTests.cpp+++ b/tests/unit/LivePresentationTimingTests.cpp@@ -4,6 +4,7 @@#include "veyra/engine/LivePresentationResetPolicy.h"#include "veyra/source/CaptureTiming.h"#include "veyra/engine/CaptureHalfRate.h"+#include "veyra/engine/CapturePreviewClock.h"#include "veyra/engine/ContentDedup.h"#include "veyra/pipeline/PictureCompare.h"#include "veyra/pipeline/FrameBatch.h"@@ -89,6 +90,59 @@ int main(){check(rate.rate(10000000)==1000,"completion rate has no 60 or 120fps cap");using veyra::source::captureDuration;using veyra::engine::liveSourceInterval100ns;using veyra::source::captureDiscontinuity;+ {+ using veyra::engine::CapturePreviewClock;+ constexpr int64_t period=166834, hostStart=10000000, wrongPeriod=208333;+ CapturePreviewClock normal, vrr, broken;+ CaptureHalfRate rawSampler, fixedSampler;+ bool original=true, variable=true, stable=true;+ unsigned transitions=0, rawKept=0, fixedKept=0;+ int64_t lastFixed=0, vrrPts=0;+ for(uint64_t i=1;i<=1200;++i){+ const auto frame=static_cast<int64_t>(i);+ const auto jitter=(frame%3-1)*2500;+ const auto correctPts=frame*period;+ const auto arrival=hostStart+correctPts+jitter;+ const auto raw=frame*wrongPeriod;+ const auto unchanged=normal.observe(i,correctPts,arrival,period,false);+ original&=!unchanged.corrected&&!unchanged.discontinuity&&unchanged.pts==correctPts;+ vrrPts+=frame%2?208333:166834;+ const auto variableFrame=vrr.observe(i,vrrPts,hostStart+vrrPts,period,false);+ variable&=!variableFrame.corrected&&!variableFrame.discontinuity&&variableFrame.pts==vrrPts;+ const auto fixed=broken.observe(i,raw,arrival,period,false);+ if(fixed.discontinuity){++transitions;fixedSampler.reset();}+ if(i>120){+ stable&=fixed.corrected&&std::llabs(fixed.pts-lastFixed-period)<=period/64;+ rawKept+=rawSampler.accept(raw,period,false);+ fixedKept+=fixedSampler.accept(fixed.pts,period,false);+ }+ lastFixed=fixed.pts;+ }+ check(original,"capture preview clock leaves normal 59.94 PTS intact");+ check(variable,"capture preview clock preserves genuine varying arrival and PTS intervals");+ check(stable&&transitions==1&&fixedKept==540&&rawKept>=670,+ "capture preview clock restores 59.94 and 29.97 sampling with 20.83 ms driver PTS");+ const auto stalled=broken.observe(1201,1200*wrongPeriod+10000,hostStart+1200*period+5310000,period,false);+ check(!stalled.corrected&&stalled.discontinuity,"capture preview clock preserves a real 531 ms stall even when PTS hides it");++ CapturePreviewClock recovered;+ for(uint64_t i=1;i<=64;++i)recovered.observe(i,int64_t(i)*wrongPeriod,hostStart+int64_t(i)*period,period,false);+ bool restored=false;+ for(uint64_t i=65;i<=112;++i){+ const int64_t raw=64*wrongPeriod+int64_t(i-64)*period;+ const auto f=recovered.observe(i,raw,hostStart+int64_t(i)*period,period,false);+ restored|=f.discontinuity&&!f.corrected&&f.pts==raw;+ }+ check(restored&&!recovered.correcting(),"capture preview clock returns to recovered driver timing");++ CapturePreviewClock skipped;+ bool corrected=false;+ for(uint64_t i=1;i<=64;++i){+ if(i%4==0)continue;+ corrected=skipped.observe(i,int64_t(i)*wrongPeriod,hostStart+int64_t(i)*period,period,false).corrected;+ }+ check(corrected,"capture preview clock accounts for skipped mailbox sequence numbers");+ }veyra::source::CaptureDriverDiscontinuity driverFlag;auto flag=[&](bool flagged=true,bool native=true,bool timed=true,double pts=1.0/60,double arrival=1.0/60){return driverFlag.observe(flagged,native,timed,true,pts,arrival,60);