Skip to content

Bring PS5 GTA6 to 120FPS with DLSS 5. An advanced Windows video player and capture enhancement tool featuring real-time preview for videos, images, and capture card sources. Combine AI-powered Super Resolution, DLSS5 image enhancement, and Frame Generation to deliver a next-generation visual experience.

C++

fix(cadence): judge repeats per pixel within the capture-noise band

Veyra Goal Agent8d11cadbe0af
diff --git a/AGENTS.md b/AGENTS.md
index e4fc7ddd..db150598 100644
--- a/AGENTS.md
+++ b/AGENTS.md
@@ -1,6 +1,6 @@
# Veyra 项目 Agent 执行规则
-> **2026-10-12 内容节奏修正(Claude)**:用户实测 2.0.7:“采集 60→30”被植入内容节奏判断、原始帧率跳动,要求还原为最简单的 60 帧 AABBCCDD→ABCD 稳定隔帧;新“自动识别内容节奏”去重不稳定(VFG 耗时、GPU 占用忽高忽低),游戏运行中出现 6fps,怀疑不是百分百相同的帧也被去掉。存档 `checkpoint/pre-claude-cadence-exact-20261012`(main 05bc4b5)与 `archives/claude-cadence-exact-20261012`,分支 `claude/cadence-exact-20261012`。60→30 恢复 `CaptureHalfRate`(与 85cbd5a 之前相同、不经去重);内容模式只去掉与上一张保留画面逐字节完全相同的帧(`PictureFingerprint.h` 整画面指纹,采集回调仅在内容去重开启时对驱动样本计算,CPU 帧在引擎端计算),静止画面按内容节奏保留。见 docs/CONTENT_CADENCE_EXACT_2026-10-12.md。用户 2.0.7 会话运行期间只做 CPU/轻 GPU 测试;不改默认设置、NR/SR/FG 模型、运行库、用户配置;无 merge/push/Release/子 Agent。
+> **2026-10-12 内容节奏修正(Claude)**:用户实测 2.0.7:“采集 60→30”被植入内容节奏判断、原始帧率跳动,要求还原为最简单的 60 帧 AABBCCDD→ABCD 稳定隔帧;新“自动识别内容节奏”去重不稳定(VFG 耗时、GPU 占用忽高忽低),游戏运行中出现 6fps,怀疑不是百分百相同的帧也被去掉。追加授权关闭用户正在运行的 Veyra、直接用 T911 实卡(2K60 NV12、游戏 30 帧)测试。存档 `checkpoint/pre-claude-cadence-exact-20261012`(main 05bc4b5)与 `archives/claude-cadence-exact-20261012`,分支 `claude/cadence-exact-20261012`。60→30 恢复 `CaptureHalfRate`(与 85cbd5a 之前相同、不经去重);内容模式整画面逐像素与上一张新画面比较,每个分量都在 ±3 级(8 位刻度)以内才算重复(`PictureCompare.h`,采集回调只在去重开启时比较驱动样本并给帧编画面号);逐字节相同在实卡上从不成立(T911 重复帧 ±1–2 级噪声),该版本已被实卡数据否决。见 docs/CONTENT_CADENCE_EXACT_2026-10-12.md。不改默认设置、NR/SR/FG 模型、运行库;用户设置只读取并复制进测试包;无 merge/push/Release/子 Agent。
> **2026-10-12 构建前采集格式追加授权**:用户要求分辨率先行、MJPEG 标红(不建议使用)、无效组合明确弹错且不自动路由其他格式。允许最小 UI/桥接/采集协商修复和有关回归,保留有效上次配置;与本轮整合一起本地合入 main 和 2.0.7 测试包。
diff --git a/docs/CONTENT_CADENCE_2026-10-11.md b/docs/CONTENT_CADENCE_2026-10-11.md
index 80172f18..2314cbeb 100644
--- a/docs/CONTENT_CADENCE_2026-10-11.md
+++ b/docs/CONTENT_CADENCE_2026-10-11.md
@@ -1,6 +1,6 @@
# 补帧内容节奏:去除重复帧重新设计(2026-10-11)
-> 2026-10-12 修正(docs/CONTENT_CADENCE_EXACT_2026-10-12.md):“采集 60→30”已恢复为按时间戳隔帧(CaptureHalfRate),不再去重;内容模式不再用 64×36 采样点与变化门限,只去掉与上一张保留画面逐字节完全相同的帧,静止画面按内容节奏保留。下文是 10-11 版本的记录。
+> 2026-10-12 修正(docs/CONTENT_CADENCE_EXACT_2026-10-12.md):“采集 60→30”已恢复为按时间戳隔帧(CaptureHalfRate),不再去重;内容模式不再用 64×36 采样点与变化门限,改为整画面逐像素与上一张新画面比较(每个分量都在采集噪声 ±3 级以内才算重复),静止画面按内容节奏保留。下文是 10-11 版本的记录。
## 授权与范围
diff --git a/docs/CONTENT_CADENCE_EXACT_2026-10-12.md b/docs/CONTENT_CADENCE_EXACT_2026-10-12.md
index 2595cda0..3f246152 100644
--- a/docs/CONTENT_CADENCE_EXACT_2026-10-12.md
+++ b/docs/CONTENT_CADENCE_EXACT_2026-10-12.md
@@ -1,57 +1,62 @@
-# 内容节奏修正:60→30 还原,去重只认完全相同的画面(2026-10-12)
+# 内容节奏修正:60→30 还原,去重改为整画面逐像素比较(2026-10-12)
## 授权与问题
-- 用户(2.0.7 测试包实测,MCS T911 2560×1440@60 P010 HDR):“采集 60→30”被植入了内容节奏判断,原始帧率也在跳,要求还原为最简单的 60 帧 AABBCCDD → ABCD 并且稳定;新的“自动识别内容节奏”去除重复帧的频率变化太快、不稳定,导致 VFG 耗时乱跳、GPU 占用忽高忽低;游戏一直在运行却出现 6fps,怀疑不是百分百相同的帧也被去掉了。
+- 用户(2.0.7 测试包实测,MCS T911 2560×1440@60 P010 HDR):“采集 60→30”被植入了内容节奏判断,原始帧率也在跳,要求还原为最简单的 60 帧 AABBCCDD → ABCD 并且稳定;新的“自动识别内容节奏”去重频率变化太快、不稳定,VFG 耗时乱跳、GPU 占用忽高忽低;游戏一直在运行却出现 6fps,怀疑不是百分百相同的帧也被去掉了。
+- 追加授权:“你帮我现在开着的软件直接关了,然后直接拿采集卡测试一下……2K60,NV12,实际游戏画面是 30 帧。”
- 沿用规则:先存档、开分支,负优化就退回;每种测试一个;不 merge/push/Release;不打扰 Codex。
-- 存档:标签 `checkpoint/pre-claude-cadence-exact-20261012`(main 05bc4b5);`archives/claude-cadence-exact-20261012/`(start.json、source-before.bundle 已 verify)。分支 `claude/cadence-exact-20261012`,工作树 `worktrees/cadence-exact-20261012`。
+- 存档:标签 `checkpoint/pre-claude-cadence-exact-20261012`(main 05bc4b5);`archives/claude-cadence-exact-20261012/`(start.json、source-before/after bundle 已 verify)。分支 `claude/cadence-exact-20261012`,工作树 `worktrees/cadence-exact-20261012`。
## 原因(用户日志 test-2.0.7 包 logs/veyra-qml.log)
- 60→30(mode=5):`[content-dedup] observed=70 kept=7 repeats=63 held=7`,每秒只留 6–16 帧。85cbd5a 把 60→30 改成“去重 + 30 上限”,所以它跟着去重一起出错。
- 自动(mode=1)同样出现 `kept=6~7 held=6~7`:所有帧都被判成重复,只靠 150–250 ms 的保持上限偶尔放行一帧。
-- 判重方法:只比较 64×36 个单像素采样点(2560×1440 下每 40×40 取 1 个,P010 只取高 8 位),变化超过 8 级才算新画面。站在原地时游戏里的小动作(角色待机、植被、粒子、HDR 暗部的细微变化)碰不到采样点或不到 8 级,被当成重复去掉。旧文档的“未验证与边界”已写到“采样点碰不到的极小变化会被当成重复”,实机上这种情况是常态。
+- 判重方法:只比较 64×36 个单像素采样点(2560×1440 下每 40×40 取 1 个,P010 只取高 8 位),变化超过 8 级才算新画面。站在原地时游戏里的小动作碰不到采样点或不到 8 级,被当成重复去掉。
## 修正
-1. **采集 60→30**:回到 `CaptureHalfRate`(与 85cbd5a 之前的代码相同):按时间戳每两帧取一帧、保留原始时间戳、稳定 30 帧;不再经过任何画面判断。
-2. **自动识别 / 识别 30·50·60fps 内容**:一帧只有与上一张保留的画面**逐字节完全相同**(整张画面、所有像素、所有平面)才算重复。
- - `include/veyra/pipeline/PictureFingerprint.h`:8 路 128 位 AES 状态、每 16 字节两轮,每一步都是状态的双射,任何一个字节不同都会让指纹不同;128 字节状态整体比较,没有任何阈值。
- - 采集回调在内容去重开启时(`CaptureCardSource::setPictureFingerprints`)对驱动样本计算(不读写合并的上传缓冲),1440p P010 约 0.2 ms、4K P010 约 0.5 ms(本机 9700X),关闭去重时为 0;MJPEG 解码画面同样在解码线程计算;其他 CPU 帧(转换后的帧、测试回放)在引擎端计算(`captureFrameFingerprint`);硬件解码的帧没有 CPU 画面,不去重(与以前相同)。
- - 卡顿:同一画面持续不到 2.5 个内容周期时仍去掉重复帧(下一张新画面覆盖整个等待时间)。超过后视为静止画面(暂停、菜单),按内容节奏的时间网格保留(30/40/60 帧内容静止时仍是 30/40/60),不再每秒只留 4–7 帧,NR/补帧的 GPU 工作量保持稳定。
- - 内容时间戳(回归周期、夹在采样窗口内)不变。
-3. 删除不再使用的 `EnhanceGraph::lumaSignature`;内容节奏提示文字(四语)改为“只去掉与上一张完全相同的画面;采集 60→30 固定每两帧取一帧,稳定 30 帧”。
-4. 测试开关 `VEYRA_TEST_CONTENT_DEDUP_LEGACY=1` 仍恢复只统计不去重的旧内容模式;60→30 不再受它影响。
+1. **采集 60→30**:回到 `CaptureHalfRate`(与 85cbd5a 之前的代码相同):按时间戳每两帧取一帧、保留原始时间戳、稳定 30 帧;不经过任何画面判断。
+2. **自动识别 / 识别 30·50·60fps 内容**:每一帧整张画面(所有像素、所有平面)与“上一张新画面”逐像素比较,**每个像素的差都在 ±3 级以内**(8 位刻度;10 位为 12 级)才算重复;只要有一个像素超出就是新画面(`include/veyra/pipeline/PictureCompare.h`)。
+ - 为什么不是“逐字节完全相同”:第一版这样做了(整画面指纹),在 T911 上**一张也匹配不上**——采集卡对同一画面每次输出都带噪声。实测(`tests/claude-cadence-exact-20261012/harness/card_diff.py`,FFmpeg 直接读卡 2560×1440@60 NV12,游戏 30 帧、站在原地,173 对相邻帧):重复画面约 18% 的像素差 1 级、几百个差 2 级、偶尔 1 个像素差 3 级,从不超过 3;新画面至少 240 个像素差超过 2 级,最大差 6–16 级。
+ - 与“上一张新画面”比较,缓慢变化会累积超过 ±3 级,不会一点点溜过去;v210/RGB10/RGB555/565 这类字节不是分量的打包格式按完全相同比较。
+ - 采集回调在内容去重开启时(`CaptureCardSource::setPictureCompare`)直接比较驱动样本(不读写合并的上传缓冲),给每帧编“画面号”;引擎只看画面号是否与上一张保留的相同(读不到某张画面的第一帧时,第二帧仍算新画面)。其他 CPU 帧(转换后的帧、测试回放)在引擎端比较;硬件解码帧和 MJPEG 没有 CPU 原始画面,不去重。
+ - 卡顿:同一画面持续不到 2.5 个内容周期时去掉重复帧;超过后视为静止画面(暂停、菜单),按内容节奏网格保留(30/40/60 帧内容静止时仍是 30/40/60),GPU 工作量保持稳定。
+3. 删除 `EnhanceGraph::lumaSignature`;内容节奏提示文字(四语)改为“只去掉与上一张相同的画面;采集 60→30 固定每两帧取一帧,稳定 30 帧”。日志 `[content-dedup]` 每秒一行增加 `repeatMaxDiff`(重复帧的最大差,8 位刻度)、`newMinOver`(新画面超出范围的最少像素数)与 `band`。
-## 测试(每种一个)
+## 实卡测试(T911,2560×1440@60,游戏 30 帧,NR 实时 + VFG 4X 质量 3,私有 profile)
-| 类型 | 内容 | 结果 |
-| --- | --- | --- |
-| 单元 | `veyra_live_timing_tests`:30-in-60/58、40-in-60、真 60、带噪声重复帧、卡顿、1440p P010 尺寸画面只改 1 字节、静止画面(30/40 帧内容之后、无周期时)、无 CPU 画面;CaptureHalfRate 原有用例 | 92 项全部通过 |
-| 离线同帧 A/B(只用 CPU) | 同一批解码帧同时送旧版(64×36 点)和新版(整画面指纹),`reports/claude-cadence-exact-20261012/offline-ab.json` | 见下表 |
-| 引擎回放(不开补帧,轻 GPU) | `veyra_live_presentation_tests --dedup-auto-nofg / --dedup-half-nofg`,静止画面 + 小物体素材 | 自动:540/540 真实画面、0 丢失、0 重复、每秒恒 30、内容间隔恒 33.333 ms;60→30:每秒恒 30、0 丢失、0 重复 |
-| 回归 | 原有 `--half-rate`(60→30 采样 + 热切换 NR/2X/关闭/切回原节奏) | 34 项全部通过,30 fps→切回 60 fps |
-| 界面 | `veyra_ui_contract_tests`;新 EXE 私有 profile 冷启动 15 秒 | 通过;无 QML 错误 |
+`tests/claude-cadence-exact-20261012/harness/capture.py`(正常界面桥接:选卡→选格式→开始采集,内容节奏在运行中切换,每段 40 秒,去掉前 2 秒;nvidia-smi 每秒采样)。
-离线 A/B(20 秒,60 Hz 采样,1920×1080):
+| 版本 / 模式 | 每秒保留 | 每秒去重 | 补帧输出 fps | VFG P95 ms | GPU 占用 |
+| --- | --- | --- | --- | --- | --- |
+| 本版 NV12 自动 | 30–31 | 29–31 | 119.7 ± 1.1 | 21.64 ± 0.02 | 84.8% ± 2.6 |
+| 本版 NV12 60→30 | 恒 30(GPU 完成 30.0 ± 0) | — | 119.9 ± 0.6 | 21.65 ± 0.01 | 85.7% ± 0.8 |
+| 本版 P010 自动 | 30–31 | 30–31 | 119.7 ± 1.1 | 21.52 ± 0.01 | 86.5% ± 0.6 |
+| 第一版(逐字节相同)NV12 自动 | ~60(每秒只匹配 0.08 张) | 0.08 | 100 ± 8.4,补帧调度降档 | 21.70 | 82.8% ± 8.8 |
+| 2.0.7 原版 NV12 自动(同一场景) | 30–31 | 30–31 | 118.5 ± 2.0 | 21.58 | 88.1% ± 4.6 |
-| 素材 | 旧版保留 / 丢失真实画面 / 每秒 | 新版保留 / 丢失 / 每秒 |
-| --- | --- | --- |
-| 静止画面 + 20×20 低对比度移动方块,30→60 无损 | 134 / **465** / 6–7 | **600 / 0 / 恒 30** |
-| GTA6 30→60 无损 | 598 / 0 / 30 | 598 / 0 / 30 |
-| GTA6 30→60 有损 x264(重复帧不逐字节相同) | 598 / 0 / 30(留 4 张重复) | 1196 / 0 / 60(不去重) |
+- 本版日志:NV12 重复帧最大差 2–3 级、新画面每张至少 25–287 个像素超出范围;P010 重复帧最大差约 1 级、新画面至少 1.3 万个分量超出。界面:“自动识别内容节奏 · 去重后约 30 fps”“采集 60→30 · 当前约 30 fps”,状态正常。
+- 同一场景下 2.0.7 原版也稳定 30:用户之前的 6fps 出现在 P010 HDR、原地站立时(旧方法只看高 8 位、8 级门限,更容易漏);新方法逐像素比较,与场景无关。
+- 采集回调耗时(进入→复制完成):NV12 约 0.27 → 0.5–0.8 ms,P010 约 0.6 → 1.35–1.6 ms;只在自动 / 识别 xx fps 模式下增加,60→30 与采用源时间戳不变。
+- 日志:`logs/claude-cadence-exact-20261012/capture-*-{new-nv12,band-nv12,old-nv12,band-p010}/`(receipt.json、player.log)、`card/nv12-diff.json`。
-指纹耗时(1080p CPU 帧)P50 约 0.06 ms,引擎内 P50 0.21 ms / P99 0.47 ms(软件解码帧,含缓存未命中)。
+## 其他测试
-日志:`logs/claude-cadence-exact-20261012/replay-20261012-204924`(自动/60→30/单元/界面)、`replay-20261012-205028`(half-rate)、`gui-smoke-*`;构建 `build-20261012-204834/receipt.json`。素材 `tests/claude-cadence-exact-20261012/media`(ffmpeg 无损生成,framemd5 确认每张画面恰好两帧)。
+| 类型 | 内容 | 结果 |
+| --- | --- | --- |
+| 单元 | `veyra_live_timing_tests`:PictureCompare(范围内噪声、单像素超出、缓慢渐变累积、P010 字、打包格式、布局变化、画面号不冲突);ContentDedup(30-in-60/58、40-in-60、真 60、范围内/外噪声、卡顿、首帧未读到、静止画面 30/40/无周期、无 CPU 画面);CaptureHalfRate 原有用例 | 100 项全部通过 |
+| 离线同帧 A/B(只用 CPU) | `reports/claude-cadence-exact-20261012/offline-ab-band.json` | 静止画面 + 20×20 低对比度(8%)移动方块:旧版 600 张真实画面只留 134(每秒 6–7),本版 598(每秒 29–30;2 张的变化本身不超过 3 级,与噪声无法区分);GTA6 无损 30→60 两者 598/598;有损 x264 重复帧的压缩差异超出范围,本版基本全部保留 |
+| 引擎回放(不开补帧) | 同上素材,`--dedup-auto-nofg` / `--dedup-half-nofg` | 自动每秒 29–30、0 重复;60→30 恒 30 |
+| 回归 | 原有 `--half-rate`(60→30 采样 + 热切换) | 34 项通过(逐字节版本时运行,60→30 路径之后未改) |
+| 界面 | `veyra_ui_contract_tests`、私有 profile 冷启动 | 通过 |
## 测试包
-`tests/claude-cadence-exact-20261012/Veyra-2.0.7-test-cadence-NVIDIA`:2.0.7 NVIDIA 测试包全量复制(1639 个文件),只换 `veyra_qml_ui.exe`(显示版本 2.0.7-test-cadence)与 `qml/Veyra/ProPage.qml`;设置与 2.0.7 测试包共用(`%LOCALAPPDATA%` 下 user-data-2.0.0)。
+`tests/claude-cadence-exact-20261012/Veyra-2.0.7-test-cadence-NVIDIA`:2.0.7 NVIDIA 测试包全量复制,只换 `veyra_qml_ui.exe`(显示版本 2.0.7-test-cadence)与 `qml/Veyra/ProPage.qml`;`runtime_local/user-data-2.0.0` 复制了用户 2.0.7 包关闭后的设置(设置在各自包内,原包未改)。
## 未验证与边界
-- 没有用实卡验证:用户的 2.0.7 会话一直占用 T911;采集回调里的指纹路径只经代码审查与同算法离线/回放验证。
-- 采集卡对同一画面输出的数据如果不是逐字节相同(压缩/带噪声,例如 MJPEG 或有损串流),自动识别不会去掉任何帧(等同“采用源时间戳”,日志 `repeats=0`)——这是“只去百分百相同的帧”的代价,不会丢真实画面。
-- 静止画面按内容节奏保留意味着暂停/菜单时 GPU 仍按 30/40/60 帧工作(为了稳定);旧版此时只有 4–7 帧。
-- 硬件解码的串流(PS5 Remote Play、Moonlight、Xbox)不去重,60→30 对它们按时间戳隔帧,与以前相同。
+- ±3 级以内的变化与采集卡噪声无法区分:整张画面每个像素都只变了 1–3 级的新画面会被当成重复(实测原地站立时的新画面最大差 ≥ 6 级)。
+- 噪声更大的来源(MJPEG、压缩串流、带噪声的模拟采集)重复帧超出范围,自动模式基本不去重,等同“采用源时间戳”,不会丢真实画面。
+- 只在 T911 的 NV12 / P010 2560×1440@60 上实测;其他采集卡的噪声范围未测。
+- 硬件解码的串流(PS5 Remote Play、Moonlight、Xbox)和 MJPEG 不去重;60→30 对它们按时间戳隔帧,与以前相同。
diff --git a/docs/WORKLOG.md b/docs/WORKLOG.md
index c1f59894..a6141b89 100644
--- a/docs/WORKLOG.md
+++ b/docs/WORKLOG.md
@@ -9303,3 +9303,10 @@ audit.py核对测试/GUI/所有app原件、两份旧final、旧JSON和源码bund
- 修正:60→30 回到 CaptureHalfRate;内容模式用 PictureFingerprint(整画面所有平面逐字节,8 路 AES),完全相同才去掉;采集回调只在去重开启时计算(1440p P010 约 0.2 ms),MJPEG 解码帧同样,其他 CPU 帧引擎端算;静止画面超过 2.5 个内容周期后按内容节奏网格保留。删除 EnhanceGraph::lumaSignature,提示文字四语更新。
- 结果:离线同帧 A/B 静止画面+小低对比移动物体(无损 30→60)旧版 600 张真实画面只留 134(每秒 6–7),新版 600/600 每秒恒 30;GTA6 无损 30→60 两者 598/598;有损 x264 重复帧不逐字节相同,新版全部保留。引擎回放(不开补帧)自动 540/540、0 丢失 0 重复、每秒恒 30、间隔恒 33.333 ms;60→30 每秒恒 30。单测 92、--half-rate 34、ui-contracts、新 EXE 冷启动通过。构建 py -3.11 -I tmp/claude-cadence-exact-20261012/build.py(复用 build/test-2.0.7-20261012 对象,只读)。
- 测试包 tests/claude-cadence-exact-20261012/Veyra-2.0.7-test-cadence-NVIDIA(2.0.7 NVIDIA 包全量复制,只换 EXE 与 ProPage.qml,共用用户设置)。实卡未验(用户会话占用 T911);采集卡重复帧若非逐字节相同则自动模式不去重(repeats=0)。无 merge/push/Release。
+
+### 2026-10-12 内容节奏修正续:实卡测试与噪声范围(Claude)
+
+- 用户授权关闭正在运行的 Veyra(正常关闭)并用 T911 2560×1440@60 NV12(游戏 30 帧)实测。逐字节相同版本在实卡上每秒只匹配 0.08 张,自动模式保留约 60 帧、VFG 4X 跟不上(补帧调度降档)。
+- FFmpeg 直接读卡测相邻帧(harness/card_diff.py,173 对):重复画面 ±1–2 级噪声(约 18% 像素差 1 级,偶尔 1 个像素差 3 级),新画面原地站立也至少 240 个像素差超过 2 级、最大 6–16 级。改为 PictureCompare.h:整画面每个分量都在 ±3 级(8 位刻度,10 位 12 级)以内才算重复,采集回调比较驱动样本并给帧编画面号,引擎按画面号去重;删除整画面指纹。
+- 实卡结果(NR 实时 + VFG 4X 质量 3,harness/capture.py):NV12 自动每秒保留 30–31、去重 29–31,补帧输出 119.7±1.1 fps,VFG P95 21.64±0.02 ms,GPU 84.8%±2.6;60→30 恒 30、输出 119.9±0.6;P010 自动每秒 30–31,重复帧最大差约 1 级。同场景 2.0.7 原版也稳定 30(用户之前 6fps 为 P010 HDR 原地站立)。采集回调耗时 NV12 +0.3 ms、P010 约 +0.9 ms,仅在内容去重模式。单测 100 项、离线 A/B(静止+小物体:旧 134/600,本版 598/600)、回放、界面通过。
+- 测试包 EXE 已更新并复制了用户 2.0.7 包关闭后的设置(runtime_local/user-data-2.0.0,原包未改)。±3 级以内的整画面变化与噪声无法区分;其他采集卡噪声未测。无 merge/push/Release。
diff --git a/include/veyra/engine/ContentDedup.h b/include/veyra/engine/ContentDedup.h
index 84f6e24d..eb8e82b4 100644
--- a/include/veyra/engine/ContentDedup.h
+++ b/include/veyra/engine/ContentDedup.h
@@ -1,5 +1,4 @@
#pragma once
-#include "veyra/pipeline/PictureFingerprint.h"
#include <algorithm>
#include <array>
#include <cmath>
@@ -16,12 +15,14 @@ namespace veyra::engine {
// 30 / 50 / 60 fps) drop a sample here when its picture repeats the last kept
// one; "60->30" is the plain every-second-sample CaptureHalfRate, not this.
//
-// A repeat is a picture whose every byte of every plane equals the last kept
-// picture (PictureFingerprint.h). The first version judged 64x36 sampled points
-// with an 8-level gate: a running HDR game seen from a still position lost most
-// real pictures (6-16 kept of 60 per second, field log 2026-10-12). Anything
-// that is not bit-identical is a new picture now, so a noisy or re-encoded
-// source simply keeps every sample.
+// A repeat is a sample with the same picture number as the last kept one: the
+// capture callback (or the engine, for CPU frames) compares every component of
+// the whole picture with the last new picture and only a sample entirely within
+// the capture-noise band keeps its number (PictureCompare.h). The first version
+// judged 64x36 sampled points with an 8-level gate: a running HDR game seen
+// from a still position lost most real pictures (6-16 kept of 60 per second,
+// field log 2026-10-12). Numbers rather than pictures also keep a picture whose
+// first sample the engine never read (mailbox overwrite).
//
// Kept frames get a content timestamp from a clamped phase-locked cadence: the
// picture changed after the previous sample and no later than this one, so the
@@ -50,9 +51,9 @@ public:
haveKept_ = haveContent_ = skipSpan_ = holding_ = false; prevSample_ = 0; lastKeptSample_ = 0; lastContent_ = 0;
timeCount_ = 0; timeHead_ = 0; period_ = 0; misses_ = 0;
}
- // picture: exact identity of the sample, or nullptr (no CPU picture: keep everything).
+ // picture: picture number of the sample, or nullptr (no CPU picture: keep everything).
// hintPeriod: expected content period of the selected content rate, 0 = unknown.
- Decision observe(const pipeline::PictureFingerprint* picture, int64_t pts, int64_t transport, bool boundary, int64_t hintPeriod = 0) {
+ Decision observe(const uint64_t* picture, int64_t pts, int64_t transport, bool boundary, int64_t hintPeriod = 0) {
Decision d;
++stats_.observed;
if (transport <= 0) transport = 166667;
@@ -95,7 +96,7 @@ public:
private:
enum class Timing { Sample, Cadence };
static constexpr unsigned kTimes = 48;
- Decision& keep(Decision& d, int64_t pts, int64_t previous, int64_t transport, const pipeline::PictureFingerprint* picture, Timing timing,
+ Decision& keep(Decision& d, int64_t pts, int64_t previous, int64_t transport, const uint64_t* picture, Timing timing,
const char* reason, int64_t hint = 0) {
d.keep = true; d.reason = reason; ++stats_.kept;
int64_t content = pts;
@@ -147,7 +148,7 @@ private:
void push(int64_t time) { times_[timeHead_] = time; timeHead_ = (timeHead_ + 1) % kTimes; timeCount_ = std::min(timeCount_ + 1, kTimes); }
- pipeline::PictureFingerprint kept_{};
+ uint64_t kept_ = 0;
std::array<int64_t, kTimes> times_{};
unsigned timeCount_ = 0, timeHead_ = 0, misses_ = 0;
bool haveKept_ = false, haveContent_ = false, skipSpan_ = false, holding_ = false;
diff --git a/include/veyra/pipeline/CaptureUploadFrame.h b/include/veyra/pipeline/CaptureUploadFrame.h
index 5279e9da..73a01181 100644
--- a/include/veyra/pipeline/CaptureUploadFrame.h
+++ b/include/veyra/pipeline/CaptureUploadFrame.h
@@ -24,10 +24,11 @@
// - The 64x36 points the graph analyses are sampled in the callback from the
// driver sample (raw pixel bytes, same packing as the frame), never read
// back from the upload buffer.
-// - While content dedup runs (ContentDedup.h) the callback also fingerprints
-// the whole driver sample, every payload byte of every plane, for the same
-// reason: the engine decides on repeats without touching the upload buffer.
-#include "veyra/pipeline/PictureFingerprint.h"
+// - While content dedup runs (ContentDedup.h) the callback also compares the
+// whole driver sample with the last new picture (PictureCompare.h) and tags
+// the frame with a picture number, for the same reason: the engine decides
+// on repeats without touching the upload buffer.
+#include "veyra/pipeline/PictureCompare.h"
#include <d3d12.h>
#include <wrl/client.h>
#include <cstdint>
@@ -62,9 +63,11 @@ struct CaptureUploadFrame {
// proxyPitch(): a tiny frame with the same packing as the real one.
uint8_t proxy[kProxyWidth * kProxyHeight * kMaxPixelBytes] = {};
int proxyPitch() const { return int(kProxyWidth * pixelBytes); }
- // Exact identity of the picture (content dedup only; see the rules above).
- bool fingerprintValid = false;
- PictureFingerprint fingerprint;
+ // Picture number (content dedup only; see the rules above): frames with equal
+ // numbers show the same picture within the capture-noise band.
+ bool pictureValid = false, pictureRepeat = false;
+ uint64_t pictureId = 0, pictureOver = 0;
+ unsigned pictureMax8 = 0;
uint64_t fallbacks = 0;
// Last GPU list that reads the upload buffer (set by the graph).
@@ -143,7 +146,7 @@ inline void selectCaptureUploadTarget(AVFrame& frame) {
auto* info = captureUploadFrame(&frame);
if (!info) return;
uint8_t* base = info->mapped;
- info->direct = true; info->proxyValid = false; info->fingerprintValid = false;
+ info->direct = true; info->proxyValid = false; info->pictureValid = false;
if (info->gpuBusy()) {
if (!info->cpu) { info->cpu = static_cast<uint8_t*>(av_malloc(size_t(info->bytes))); if (info->cpu) std::memset(info->cpu, 0, size_t(info->bytes)); }
if (info->cpu) { base = info->cpu; info->direct = false; ++info->fallbacks; }
@@ -159,7 +162,7 @@ inline void useCaptureUploadCpuPlanes(AVFrame& frame) {
if (!info) return;
if (!info->cpu) { info->cpu = static_cast<uint8_t*>(av_malloc(size_t(info->bytes))); if (info->cpu) std::memset(info->cpu, 0, size_t(info->bytes)); }
if (!info->cpu) return;
- info->direct = false; info->proxyValid = false; info->fingerprintValid = false;
+ info->direct = false; info->proxyValid = false; info->pictureValid = false;
frame.data[0] = info->cpu;
if (info->planes == 2) frame.data[1] = info->cpu + info->chromaOffset;
}
@@ -183,29 +186,36 @@ inline void sampleCaptureUploadProxy(AVFrame& frame, const uint8_t* source, size
info->proxyValid = true;
}
-// Content dedup (ContentDedup.h): exact identity of the whole picture. An
-// upload-backed frame carries the capture callback's fingerprint of the driver
-// sample and is never read back; any other CPU frame (CPU planes, decoded or
-// converted frames, test replay) is hashed here, every payload byte of every
-// plane. Hardware frames, and upload buffers written without a fingerprint,
-// have none: the caller keeps the sample.
-inline bool captureFrameFingerprint(const AVFrame* frame, PictureFingerprint& out) {
+// Content dedup (ContentDedup.h): the picture number of a frame. An upload-
+// backed frame carries the capture callback's comparison of the driver sample
+// and is never read back; any other CPU frame (CPU planes, converted frames,
+// test replay) is compared here with `reference`, every component of every
+// plane. Hardware frames, packed carriers and upload buffers written without a
+// comparison have none: the caller keeps the sample.
+inline bool captureFramePicture(const AVFrame* frame, PictureReference& reference, bool packedCarrier, PictureReference::Result& out) {
if (!frame || !frame->data[0] || frame->width <= 0 || frame->height <= 0) return false;
if (const auto* info = captureUploadFrame(frame)) {
- if (info->fingerprintValid) { out = info->fingerprint; return true; }
+ if (info->pictureValid) { out = {info->pictureId, info->pictureRepeat, info->pictureOver, info->pictureMax8}; return true; }
if (info->direct) return false;
}
const auto format = AVPixelFormat(frame->format);
const auto* desc = av_pix_fmt_desc_get(format);
- if (!desc || (desc->flags & (AV_PIX_FMT_FLAG_HWACCEL | AV_PIX_FMT_FLAG_BITSTREAM | AV_PIX_FMT_FLAG_PAL))) return false;
- PictureHasher hasher;
- for (int plane = 0, planes = av_pix_fmt_count_planes(format); plane < planes; ++plane) {
+ if (packedCarrier || !desc || (desc->flags & (AV_PIX_FMT_FLAG_HWACCEL | AV_PIX_FMT_FLAG_BITSTREAM | AV_PIX_FMT_FLAG_PAL))) return false;
+ // 8-bit components compare bytewise and little-endian 16-bit containers as
+ // words; anything else (5/6-bit RGB, 10-bit fields packed in 32 bits) exactly.
+ const unsigned depth = desc->comp[0].depth;
+ bool words = depth > 8 && !(desc->flags & AV_PIX_FMT_FLAG_BE);
+ for (int c = 0; c < desc->nb_components; ++c)
+ words = words && desc->comp[c].depth + desc->comp[c].shift <= 16 && desc->comp[c].step % 2 == 0 && desc->comp[c].offset % 2 == 0;
+ const auto kind = depth == 8 ? PictureComponents::Bytes : words ? PictureComponents::Words : PictureComponents::Exact;
+ PicturePlane planes[4]; unsigned count = 0;
+ for (int plane = 0, total = av_pix_fmt_count_planes(format); plane < total && plane < 4; ++plane) {
const int bytes = av_image_get_linesize(format, frame->width, plane);
const int rows = plane == 1 || plane == 2 ? -((-frame->height) >> desc->log2_chroma_h) : frame->height;
if (bytes <= 0 || !frame->data[plane] || frame->linesize[plane] < bytes) return false;
- hasher.rows(frame->data[plane], size_t(frame->linesize[plane]), size_t(bytes), unsigned(rows));
+ planes[count++] = {frame->data[plane], size_t(frame->linesize[plane]), size_t(bytes), unsigned(rows)};
}
- out = hasher.finish();
+ out = reference.observe(planes, count, kind, PictureReference::bandFor(depth, desc->comp[0].shift));
return true;
}
diff --git a/include/veyra/pipeline/PictureCompare.h b/include/veyra/pipeline/PictureCompare.h
new file mode 100644
index 00000000..a5947581
--- /dev/null
+++ b/include/veyra/pipeline/PictureCompare.h
@@ -0,0 +1,124 @@
+#pragma once
+// Repeated-picture detection with a capture-noise band (2026-10-12).
+//
+// Content dedup (ContentDedup.h) has to know whether a sample shows the same
+// picture as the last new one. Two earlier answers failed on a real card:
+// - 64x36 sampled points with an 8-level gate (2026-10-11) missed small real
+// motion seen from a still position and dropped real pictures (6 fps).
+// - Byte-identical whole pictures never matched: the MCS T911 at 2560x1440@60
+// NV12 changes ~18% of the pixels of a repeated console frame by 1 level, a
+// few hundred by 2 and at most one by 3, while a new 30 fps game frame seen
+// from a still position has at least 240 pixels beyond 2 levels and peaks at
+// 6-16 (tests/claude-cadence-exact-20261012/harness/card_diff.py, 173 pairs).
+// A sample repeats the reference only when EVERY component of every plane of
+// the whole picture is within 3 levels on an 8-bit scale (bandFor(): the same
+// fraction of a deeper component); one component beyond it makes a new picture. Packed
+// layouts whose bytes are not components (v210, RGB10, RGB555/565) compare
+// exactly. The reference is the last NEW picture, so a slow change accumulates
+// past the band instead of slipping through it one small step at a time.
+#include <algorithm>
+#include <cstddef>
+#include <cstdint>
+#include <cstring>
+#include <emmintrin.h>
+#include <intrin.h>
+#include <smmintrin.h>
+#include <vector>
+
+namespace veyra::pipeline {
+
+struct PicturePlane {
+ const uint8_t* data = nullptr;
+ size_t pitch = 0, rowBytes = 0;
+ unsigned rows = 0;
+};
+enum class PictureComponents { Bytes, Words, Exact };
+
+class PictureReference {
+public:
+ static constexpr unsigned kBand8 = 3; // levels on an 8-bit scale
+ // The band for components of `depth` bits stored `shift` bits up (P010: 10, 6 -> 768).
+ static constexpr unsigned bandFor(unsigned depth, unsigned shift) {
+ return depth <= 8 ? kBand8 : ((kBand8 * ((1u << depth) - 1) + 127) / 255) << shift;
+ }
+ struct Result {
+ uint64_t id = 0; // picture number; equal ids show the same picture
+ bool repeat = false; // every component within the band of the reference
+ uint64_t over = 0; // components beyond the band (0 for a repeat)
+ unsigned max8 = 0; // largest difference, 8-bit scale
+ };
+ // Ids of different references never collide (space in the top byte).
+ explicit PictureReference(unsigned space = 0) : space_(uint64_t(space & 0xFF) << 56) {}
+ void reset() { valid_ = false; }
+
+ // band: per-component tolerance in the stored unit (bandFor(); ignored for Exact).
+ Result observe(const PicturePlane* planes, unsigned count, PictureComponents kind, unsigned band = kBand8) {
+ if (kind == PictureComponents::Exact) band = 0;
+ Result r;
+ size_t total = 0;
+ for (unsigned p = 0; p < count; ++p) total += planes[p].rowBytes * planes[p].rows;
+ if (valid_ && total == bytes_ && kind == kind_ && band == band_) {
+ const uint8_t* ref = reference_.data(); unsigned max = 0;
+ for (unsigned p = 0; p < count; ++p)
+ for (unsigned y = 0; y < planes[p].rows; ++y, ref += planes[p].rowBytes) {
+ const uint8_t* row = planes[p].data + size_t(y) * planes[p].pitch;
+ if (kind == PictureComponents::Words) compareWords(row, ref, planes[p].rowBytes, band, r.over, max);
+ else compareBytes(row, ref, planes[p].rowBytes, band, r.over, max);
+ }
+ r.max8 = band ? (max * kBand8 + band / 2) / band : max;
+ if (r.over == 0) { r.id = space_ | id_; r.repeat = true; return r; }
+ }
+ // A new picture becomes the reference.
+ if (reference_.size() < total) reference_.resize(total);
+ uint8_t* ref = reference_.data();
+ for (unsigned p = 0; p < count; ++p)
+ for (unsigned y = 0; y < planes[p].rows; ++y, ref += planes[p].rowBytes)
+ std::memcpy(ref, planes[p].data + size_t(y) * planes[p].pitch, planes[p].rowBytes);
+ bytes_ = total; kind_ = kind; band_ = band; valid_ = true; id_ = (id_ + 1) & 0x00FFFFFFFFFFFFFFull;
+ r.id = space_ | id_;
+ return r;
+ }
+
+private:
+ static void compareBytes(const uint8_t* a, const uint8_t* b, size_t n, unsigned band, uint64_t& over, unsigned& max) {
+ const __m128i limit = _mm_set1_epi8(char(band)), zero = _mm_setzero_si128();
+ __m128i peak = zero; size_t i = 0; uint64_t count = 0;
+ for (; i + 16 <= n; i += 16) {
+ const __m128i x = _mm_loadu_si128(reinterpret_cast<const __m128i*>(a + i)), y = _mm_loadu_si128(reinterpret_cast<const __m128i*>(b + i));
+ const __m128i d = _mm_or_si128(_mm_subs_epu8(x, y), _mm_subs_epu8(y, x));
+ peak = _mm_max_epu8(peak, d);
+ count += __popcnt(~unsigned(_mm_movemask_epi8(_mm_cmpeq_epi8(_mm_subs_epu8(d, limit), zero))) & 0xFFFFu);
+ }
+ for (; i < n; ++i) { const unsigned d = a[i] > b[i] ? a[i] - b[i] : b[i] - a[i]; max = std::max(max, d); count += d > band; }
+ alignas(16) uint8_t lanes[16]; _mm_store_si128(reinterpret_cast<__m128i*>(lanes), peak);
+ for (const uint8_t v : lanes) max = std::max<unsigned>(max, v);
+ over += count;
+ }
+ // Little-endian 16-bit components (P010/P016 and >8-bit planar frames).
+ static void compareWords(const uint8_t* a, const uint8_t* b, size_t n, unsigned band, uint64_t& over, unsigned& max) {
+ const __m128i limit = _mm_set1_epi16(short(band)), zero = _mm_setzero_si128();
+ __m128i peak = zero; size_t i = 0; uint64_t count = 0;
+ for (; i + 16 <= n; i += 16) {
+ const __m128i x = _mm_loadu_si128(reinterpret_cast<const __m128i*>(a + i)), y = _mm_loadu_si128(reinterpret_cast<const __m128i*>(b + i));
+ const __m128i d = _mm_or_si128(_mm_subs_epu16(x, y), _mm_subs_epu16(y, x));
+ peak = _mm_max_epu16(peak, d);
+ count += __popcnt(~unsigned(_mm_movemask_epi8(_mm_cmpeq_epi16(_mm_subs_epu16(d, limit), zero))) & 0xFFFFu) / 2;
+ }
+ for (; i + 2 <= n; i += 2) {
+ const unsigned x = a[i] | (unsigned(a[i + 1]) << 8), y = b[i] | (unsigned(b[i + 1]) << 8), d = x > y ? x - y : y - x;
+ max = std::max(max, d); count += d > band;
+ }
+ alignas(16) uint16_t lanes[8]; _mm_store_si128(reinterpret_cast<__m128i*>(lanes), peak);
+ for (const uint16_t v : lanes) max = std::max<unsigned>(max, v);
+ over += count;
+ }
+
+ std::vector<uint8_t> reference_;
+ size_t bytes_ = 0;
+ uint64_t id_ = 0, space_ = 0;
+ unsigned band_ = 0;
+ bool valid_ = false;
+ PictureComponents kind_ = PictureComponents::Bytes;
+};
+
+} // namespace veyra::pipeline
diff --git a/include/veyra/pipeline/PictureFingerprint.h b/include/veyra/pipeline/PictureFingerprint.h
deleted file mode 100644
index 52e8ee15..00000000
--- a/include/veyra/pipeline/PictureFingerprint.h
+++ /dev/null
@@ -1,86 +0,0 @@
-#pragma once
-// Exact picture identity for repeated-frame removal (2026-10-12).
-//
-// ContentDedup judged a repeat on 64x36 sampled points with a change gate of 8
-// levels, so a still scene with small real motion lost real pictures (field log
-// 2026-10-12: a running 1440p P010 HDR game kept 6-16 of 60 frames). A picture
-// now repeats only when every byte of every plane is identical: rows are
-// absorbed into eight 128-bit lanes, two AES rounds per 16 bytes. Each step is a
-// bijection of the lane state, so a changed byte changes its lane and the lanes
-// re-converge only if a later difference cancels a pseudo-random 128-bit state
-// difference exactly. The 128-byte state is compared whole; nothing is
-// thresholded. ~0.2 ms for a 1440p P010 picture on one core (bench 2026-10-12).
-#include <array>
-#include <cstddef>
-#include <cstdint>
-#include <cstring>
-#include <emmintrin.h>
-#include <intrin.h>
-#include <wmmintrin.h>
-
-namespace veyra::pipeline {
-
-struct PictureFingerprint {
- std::array<uint64_t, 16> words{};
- bool operator==(const PictureFingerprint&) const = default;
-};
-
-class PictureHasher {
-public:
- static constexpr unsigned kLanes = 8;
- PictureHasher() {
- for (unsigned i = 0; i < kLanes; ++i) {
- lanes_[i] = _mm_set_epi64x(int64_t(0x9E3779B97F4A7C15ull * (i + 1)), int64_t(0xC2B2AE3D27D4EB4Full ^ (i * 0x165667B19E3779F9ull)));
- scalar_[2 * i] = 0x9E3779B97F4A7C15ull * (2 * i + 1); scalar_[2 * i + 1] = 0xC2B2AE3D27D4EB4Full * (2 * i + 2);
- }
- }
- // One row (or any byte run); call in the same order for every picture.
- void absorb(const uint8_t* data, size_t bytes) {
- total_ += bytes;
- if (!aes()) { absorbScalar(data, bytes); return; }
- const __m128i k1 = _mm_set_epi64x(0x243F6A8885A308D3ll, 0x13198A2E03707344ll), k2 = _mm_set_epi64x(int64_t(0xA4093822299F31D0ull), 0x082EFA98EC4E6C89ll);
- size_t offset = 0;
- // Lanes stay in registers across the row (a member array is reloaded every block).
- __m128i a = lanes_[0], b = lanes_[1], c = lanes_[2], d = lanes_[3], e = lanes_[4], f = lanes_[5], g = lanes_[6], h = lanes_[7];
- const auto mix = [&](__m128i s, size_t at) { return _mm_aesenc_si128(_mm_aesenc_si128(_mm_xor_si128(s, _mm_loadu_si128(reinterpret_cast<const __m128i*>(data + at))), k1), k2); };
- for (; offset + 16 * kLanes <= bytes; offset += 16 * kLanes) {
- a = mix(a, offset); b = mix(b, offset + 16); c = mix(c, offset + 32); d = mix(d, offset + 48);
- e = mix(e, offset + 64); f = mix(f, offset + 80); g = mix(g, offset + 96); h = mix(h, offset + 112);
- }
- lanes_[0] = a; lanes_[1] = b; lanes_[2] = c; lanes_[3] = d; lanes_[4] = e; lanes_[5] = f; lanes_[6] = g; lanes_[7] = h;
- for (unsigned i = 0; offset < bytes; ++i, offset += 16) {
- alignas(16) uint8_t tail[16] = {};
- std::memcpy(tail, data + offset, bytes - offset < 16 ? bytes - offset : 16);
- lanes_[i] = _mm_aesenc_si128(_mm_aesenc_si128(_mm_xor_si128(lanes_[i], _mm_load_si128(reinterpret_cast<const __m128i*>(tail))), k1), k2);
- }
- }
- void rows(const uint8_t* base, size_t pitch, size_t rowBytes, unsigned count) {
- for (unsigned y = 0; y < count; ++y) absorb(base + size_t(y) * pitch, rowBytes);
- }
- PictureFingerprint finish() const {
- PictureFingerprint out;
- if (aes()) for (unsigned i = 0; i < kLanes; ++i) _mm_storeu_si128(reinterpret_cast<__m128i*>(out.words.data() + 2 * i), lanes_[i]);
- else out.words = scalar_;
- out.words[0] ^= total_;
- return out;
- }
- static bool aes() {
- static const bool available = [] { int info[4] = {}; __cpuid(info, 1); return (info[2] & (1 << 25)) != 0; }();
- return available;
- }
-
-private:
- // CPUs without AES-NI: sixteen 64-bit lanes, xor-multiply-rotate-multiply per word (each a bijection).
- void absorbScalar(const uint8_t* data, size_t bytes) {
- for (size_t offset = 0; offset < bytes; offset += 8) {
- uint64_t word = 0; std::memcpy(&word, data + offset, bytes - offset < 8 ? bytes - offset : 8);
- uint64_t& lane = scalar_[(offset / 8) % scalar_.size()];
- lane = _rotl64((lane ^ word) * 0x9FB21C651E98DF25ull, 29) * 0xD6E8FEB86659FD93ull;
- }
- }
- __m128i lanes_[kLanes];
- std::array<uint64_t, 16> scalar_{};
- uint64_t total_ = 0;
-};
-
-} // namespace veyra::pipeline
diff --git a/include/veyra/source/CaptureCardSource.h b/include/veyra/source/CaptureCardSource.h
index 732f23e0..c5557748 100644
--- a/include/veyra/source/CaptureCardSource.h
+++ b/include/veyra/source/CaptureCardSource.h
@@ -56,9 +56,9 @@ public:
// 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);
- // Content dedup: fingerprint every sample's whole picture (CaptureUploadFrame.h).
- // Any thread; applies to the next sample.
- void setPictureFingerprints(bool enabled);
+ // Content dedup: compare every sample's whole picture with the last new one and
+ // number the pictures (CaptureUploadFrame.h). Any thread; applies to the next sample.
+ void setPictureCompare(bool enabled);
// N1 diagnostic: keep the legacy per-pixel CPU unpack (BGR0/YUY2 targets)
// instead of the GPU unpack path. Applied on the next connect.
void setCpuUnpack(bool enabled);
diff --git a/include/veyra/source/CaptureCompressedDecoder.h b/include/veyra/source/CaptureCompressedDecoder.h
index 76373ad5..7c97295d 100644
--- a/include/veyra/source/CaptureCompressedDecoder.h
+++ b/include/veyra/source/CaptureCompressedDecoder.h
@@ -69,9 +69,6 @@ public:
bool hardwareActive() const;
bool waitingForInput() const;
void recoverAtKeyframe();
- // Content dedup: fingerprint each software-decoded MJPEG picture written to an
- // upload-backed target (CaptureUploadFrame.h). Call on the decoding thread.
- void setPictureFingerprints(bool enabled);
const char* backendName() const;
const std::string& lastError() const;
uint64_t framesDecoded() const;
diff --git a/src/engine/EngineController.cpp b/src/engine/EngineController.cpp
index b016002f..e87c4444 100644
--- a/src/engine/EngineController.cpp
+++ b/src/engine/EngineController.cpp
@@ -934,15 +934,19 @@ void EngineController::run(HWND window,std::wstring path,PlayerOptions options,s
double playbackSpeedLastPts=0;Clock::time_point playbackSpeedLastWall{};
CaptureHalfRate captureSampler;
// Content cadence for live sources (ContentDedup.h): in the auto / 30 / 50 /
- // 60 fps content modes, bit-identical repeated pictures are dropped before
- // any GPU work and kept frames get content timestamps. "60->30" is the
- // plain every-second-sample CaptureHalfRate again (user 2026-10-12).
+ // 60 fps content modes, repeated pictures (every component within the
+ // capture-noise band, PictureCompare.h) are dropped before any GPU work and
+ // kept frames get content timestamps. "60->30" is the plain
+ // every-second-sample CaptureHalfRate again (user 2026-10-12).
// VEYRA_TEST_CONTENT_DEDUP_LEGACY=1 restores the report-only content modes
// for A/B runs.
ContentDedup contentDedup;uint64_t dedupRevision=0;
ContentDedup::Stats dedupLogged{};
static const bool legacyCadence=GetEnvironmentVariableW(L"VEYRA_TEST_CONTENT_DEDUP_LEGACY",nullptr,0)>0;
const auto dedupContent=[](ContentRate content){return content!=ContentRate::Transport&&content!=ContentRate::Capture60To30;};
+ // CPU frames are compared here; capture-card frames arrive numbered by the callback.
+ pipeline::PictureReference enginePictures{2};
+ unsigned dedupRepeatMax8=0;uint64_t dedupNewMinOver=UINT64_MAX;
FrameLineageTracker lineageTracker;
auto completedProcessing=[&](pipeline::FrameIdentity id){std::lock_guard lock(mutex_);if(snapshot_.applied.revision==id.settingsRevision)++snapshot_.processedCompleted;};
auto host100ns=[](){return std::chrono::duration_cast<std::chrono::nanoseconds>(Clock::now().time_since_epoch()).count()/100;};
@@ -1703,23 +1707,25 @@ void EngineController::run(HWND window,std::wstring path,PlayerOptions options,s
const bool halfRate=isCapture&&options.settings.content==ContentRate::Capture60To30&&
CaptureHalfRate::supported(activeSource->info().averageFps);
const bool dedupActive=isCapture&&!isImage&&!legacyCadence&&dedupContent(options.settings.content);
- // The callback fingerprints whole pictures only while dedup needs them.
- if(physicalCapture)captureSource.setPictureFingerprints(dedupActive);
+ // The callback compares whole pictures only while dedup needs them.
+ if(physicalCapture)captureSource.setPictureCompare(dedupActive);
if(reset||pipeline::breaksHistory(pkt.flags))captureSampler.reset();
const int64_t samplePts100ns=pkt.pts.isUnknown()?0:pkt.pts.to100ns();
if(dedupActive&&!rereadCached&&!pkt.pts.isUnknown()){
const auto interval=liveSourceInterval100ns(pipeline::Rational::unknown(),activeSource->info().averageFps);
- pipeline::PictureFingerprint picture;
- const auto fingerprintStart=Clock::now();
- const bool pictured=pipeline::captureFrameFingerprint(frame,picture);
+ pipeline::PictureReference::Result picture;
+ const auto compareStart=Clock::now();
+ const bool pictured=pipeline::captureFramePicture(frame,enginePictures,gd.packedInput==6||gd.packedInput==7,picture);
+ if(pictured&&picture.repeat)dedupRepeatMax8=std::max(dedupRepeatMax8,picture.max8);
+ else if(pictured&&picture.over)dedupNewMinOver=std::min(dedupNewMinOver,picture.over);
const bool boundary=reset||pipeline::breaksHistory(pkt.flags)||dedupRevision!=options.settings.revision;
dedupRevision=options.settings.revision;
const auto content=options.settings.content;
const int64_t hint=content==ContentRate::Fps30?333333:content==ContentRate::Fps50?200000:content==ContentRate::Fps60?166667:0;
- const auto decision=contentDedup.observe(pictured?&picture:nullptr,pkt.pts.to100ns(),interval,boundary,hint);
- const double dedupUs=elapsedMs(fingerprintStart)*1000;
- if(veyra::log::verboseFrameLogs())veyra::log::info("content-dedup-frame",std::format("source={} pts100ns={} keep={} reason={} picture={:016x} contentPts100ns={} intervalMs={:.3f} cpuUs={:.1f}",
- pkt.sequence,pkt.pts.to100ns(),decision.keep,decision.reason,pictured?picture.words[1]:0,decision.contentPts,decision.interval/1e4,dedupUs));
+ const auto decision=contentDedup.observe(pictured?&picture.id:nullptr,pkt.pts.to100ns(),interval,boundary,hint);
+ const double dedupUs=elapsedMs(compareStart)*1000;
+ if(veyra::log::verboseFrameLogs())veyra::log::info("content-dedup-frame",std::format("source={} pts100ns={} keep={} reason={} picture={:x} withinBand={} over={} maxDiff={} contentPts100ns={} intervalMs={:.3f} cpuUs={:.1f}",
+ pkt.sequence,pkt.pts.to100ns(),decision.keep,decision.reason,pictured?picture.id:0,picture.repeat,picture.over,picture.max8,decision.contentPts,decision.interval/1e4,dedupUs));
if(!decision.keep){std::lock_guard lock(mutex_);++snapshot_.captureRateSkipped;continue;}
pkt.pts={decision.contentPts,10000000};
if(decision.interval>0)pkt.duration={decision.interval,10000000};
@@ -2492,10 +2498,10 @@ void EngineController::run(HWND window,std::wstring path,PlayerOptions options,s
veyra::log::info("frame-rate",std::format("revision={} gpuCompletedFps={:.2f} completedReal={} capture60To30={} rateSkipped={} presentSubmitFps={:.2f} windowMs=1000 vramMiB={} budgetMiB={} (not scanout FPS)",options.settings.revision,rates.fps,rates.processedCompleted,rates.captureHalfRate,rates.captureRateSkipped,rates.submissionFps.value_or(0),vramUsage>>20,vramBudget>>20));
if(isCapture&&dedupContent(options.settings.content)&&!legacyCadence){
const auto& st=contentDedup.stats();
- veyra::log::info("content-dedup",std::format("revision={} mode={} observed={} kept={} repeats={} held={} blind={} regular={} irregular={} contentFps={:.2f} maxShiftMs={:.2f} (per second; only bit-identical repeats are dropped, before GPU work; kept frames carry content timestamps)",
+ veyra::log::info("content-dedup",std::format("revision={} mode={} observed={} kept={} repeats={} held={} blind={} regular={} irregular={} contentFps={:.2f} maxShiftMs={:.2f} repeatMaxDiff={} newMinOver={} band={} (per second; a repeat has every component of the whole picture within the band of the last new one, dropped before GPU work; kept frames carry content timestamps)",
options.settings.revision,int(options.settings.content),st.observed-dedupLogged.observed,st.kept-dedupLogged.kept,st.repeats-dedupLogged.repeats,st.held-dedupLogged.held,st.blind-dedupLogged.blind,
- st.regular-dedupLogged.regular,st.irregular-dedupLogged.irregular,contentDedup.contentFps(),st.maxShiftMs));
- dedupLogged=st;
+ st.regular-dedupLogged.regular,st.irregular-dedupLogged.irregular,contentDedup.contentFps(),st.maxShiftMs,dedupRepeatMax8,dedupNewMinOver==UINT64_MAX?0:dedupNewMinOver,pipeline::PictureReference::kBand8));
+ dedupLogged=st;dedupRepeatMax8=0;dedupNewMinOver=UINT64_MAX;
}
veyra::log::info("capture-timing",std::format("revision={} received={} processed={} dropped={} callbackFps={:.2f} readAgeMs={:.3f} callbackToPresentReturnP95Ms={:.3f} processCpuP95Ms={:.3f} gpuReadyP95Ms={:.3f} schedulingWaitP95Ms={:.3f} presentCpuP95Ms={:.3f} gpuColorP95Ms={:.3f} gpuSrP95Ms={:.3f} gpuFlowP95Ms={:.3f} gpuNrP95Ms={:.3f} gpuResidualP95Ms={:.3f} gpuFgBatchP95Ms={:.3f} gpuBlitP95Ms={:.3f} slotWaits={} slotWaitMs={:.3f} commandSubmits={} displaySubmits={} expiredGenerated={} nr={} nvof={} generated={} historyResets={} presentationDrains={} presentationCompletedReal={} presentationSkippedGenerated={} presentationCancelledJobs={} singleGpuOwner=1 batchCapacity=2 (not HDMI-to-display latency)",options.settings.revision,captureStats.received,sourceFrames-statsSourceBase,captureStats.dropped,captureStats.callbackFps,captureStats.readAgeMs,ageP95,processTimes.p95(),liveScheduler?completed.readyP95:gpuReadyTimes.p95(),waitP95,presentP95,gpuP95(diagnostics::GpuStage::Color),gpuP95(diagnostics::GpuStage::Sr),gpuP95(diagnostics::GpuStage::Flow),gpuP95(diagnostics::GpuStage::Nr),gpuP95(diagnostics::GpuStage::Residual),gpuP95(diagnostics::GpuStage::FgBatch),gpuP95(diagnostics::GpuStage::Blit),slotWaitCount,slotWaitMilliseconds,commandSubmits,submitted,expired,graphStats.nrEvaluateCount,graphStats.nvofExecuteCount,graphStats.fgGeneratedFrames,historyResets.load(),presentationDrains.load(),presentationCompletedReal.load(),presentationSkippedGenerated.load(),presentationCancelledJobs.load()));
nextTimingLog=Clock::now()+std::chrono::seconds(1);
diff --git a/src/source/CaptureCardSource.cpp b/src/source/CaptureCardSource.cpp
index 4919c094..dad3fa04 100644
--- a/src/source/CaptureCardSource.cpp
+++ b/src/source/CaptureCardSource.cpp
@@ -260,22 +260,28 @@ bool parseCapturePath(std::wstring_view path,CaptureSelection& selection){
selection.videoIndex=videoIndex;selection.format=format;selection.audio=audio;selection.colorOverride=fields>=4?colorOverride:0;return true;
}
}
-// Content dedup (ContentDedup.h): exact identity of the driver sample, every
-// payload byte of every plane in source order, never the write-combined copy.
-// About 0.2 ms for 1440p P010 and 0.5 ms for 4K P010 (bench 2026-10-12), so
-// only while a content mode asks for it.
-static void fingerprintCaptureSample(const CaptureMediaLayout& layout,const uint8_t* data,AVFrame& frame){
+// Content dedup (ContentDedup.h): compares the driver sample - every payload
+// component of every plane, never the write-combined copy - with the last new
+// picture (PictureCompare.h) and tags the frame with its picture number. About
+// 0.3 ms for 1440p NV12 plus a copy of each new picture, so only while a
+// content mode asks for it.
+static void compareCaptureSample(const CaptureMediaLayout& layout,const uint8_t* data,AVFrame& frame,pipeline::PictureReference& reference){
auto* info=pipeline::captureUploadFrame(&frame);if(!info)return;
- pipeline::PictureHasher hasher;
- hasher.rows(data,layout.stride,layout.rowBytes,layout.height);
- for(unsigned p=1;p<layout.planes;++p)hasher.rows(data+(p==1?layout.chromaOffset:layout.secondChromaOffset),layout.chromaStride,layout.chromaRowBytes,layout.height/2);
- info->fingerprint=hasher.finish();info->fingerprintValid=true;
+ pipeline::PicturePlane planes[3]{{data,layout.stride,layout.rowBytes,layout.height}};unsigned count=1;
+ for(unsigned p=1;p<layout.planes&&p<3;++p)planes[count++]={data+(p==1?layout.chromaOffset:layout.secondChromaOffset),layout.chromaStride,layout.chromaRowBytes,layout.height/2};
+ // P010/P016 are 16-bit words; packed 10-bit and 5/6-bit RGB fields compare exactly; the rest are 8-bit components.
+ const bool p016=layout.packing==CapturePacking::P016,words=p016||layout.packing==CapturePacking::P010;
+ const bool exact=layout.packing==CapturePacking::V210||layout.packing==CapturePacking::Rgb10xLE||layout.packing==CapturePacking::Rgb555||
+ layout.packing==CapturePacking::Rgb565||layout.packing==CapturePacking::Unknown;
+ const auto r=reference.observe(planes,count,exact?pipeline::PictureComponents::Exact:words?pipeline::PictureComponents::Words:pipeline::PictureComponents::Bytes,
+ words?pipeline::PictureReference::bandFor(p016?16:10,p016?0:6):pipeline::PictureReference::kBand8);
+ info->pictureId=r.id;info->pictureRepeat=r.repeat;info->pictureOver=r.over;info->pictureMax8=r.max8;info->pictureValid=true;
}
// One native sample into a mailbox frame. Upload-backed frames
// (CaptureUploadFrame.h) are written once, straight into GPU upload memory, or
// into their CPU planes while the GPU still reads the buffer; planar I420/YV12
// is interleaved into the frame's NV12 layout here instead of in the graph.
-static bool writeCaptureFrame(const CaptureMediaLayout& layout,const uint8_t* data,size_t bytes,AVFrame& frame,bool flipRows,bool fingerprint){
+static bool writeCaptureFrame(const CaptureMediaLayout& layout,const uint8_t* data,size_t bytes,AVFrame& frame,bool flipRows,pipeline::PictureReference* pictures){
pipeline::selectCaptureUploadTarget(frame);
const bool flip=layout.bottomUp!=flipRows;
if(layout.planes==3&&frame.format==AV_PIX_FMT_NV12&&pipeline::captureUploadFrame(&frame)){
@@ -284,7 +290,7 @@ static bool writeCaptureFrame(const CaptureMediaLayout& layout,const uint8_t* da
}else if(!copyCaptureSample(layout,data,bytes,frame,flipRows))return false;
if(layout.packing==CapturePacking::V210)pipeline::sampleCaptureV210Proxy(frame,data,layout.stride,flip);
else pipeline::sampleCaptureUploadProxy(frame,data,layout.stride,flip);
- if(fingerprint)fingerprintCaptureSample(layout,data,frame);
+ if(pictures)compareCaptureSample(layout,data,frame,*pictures);
return true;
}
struct CaptureCardSource::Impl:ISampleGrabberCB {
@@ -385,8 +391,9 @@ struct CaptureCardSource::Impl:ISampleGrabberCB {
std::vector<AVFrame*> compressedFree;
// Manual capture flip; read by the DirectShow callback thread.
std::atomic<bool> verticalFlip{false};
- // Content dedup wants picture fingerprints; read by the callback and MJPEG workers.
- std::atomic<bool> pictureFingerprints{false};
+ // Content dedup wants picture numbers; the reference lives on the callback thread.
+ std::atomic<bool> pictureCompare{false};
+ pipeline::PictureReference pictureReference{1};
std::unique_ptr<WasapiAudioInput> wasapi;
std::unique_ptr<decklink::Capture> decklink;
std::wstring audioError;
@@ -431,7 +438,7 @@ struct CaptureCardSource::Impl:ISampleGrabberCB {
externalFrames.fetch_add(1,std::memory_order_relaxed);
AVFrame* staged=nullptr;bool written=false;
{std::lock_guard lock(mutex);if(stagingFrame&&!stagingBusy){stagingBusy=true;staged=stagingFrame;}}
- if(staged)written=writeCaptureFrame(layout,data,bytes,*staged,verticalFlip.load(),pictureFingerprints.load(std::memory_order_relaxed));
+ if(staged)written=writeCaptureFrame(layout,data,bytes,*staged,verticalFlip.load(),pictureCompare.load(std::memory_order_relaxed)?&pictureReference:nullptr);
{
std::lock_guard lock(mutex);
if(staged)stagingBusy=false;
@@ -506,7 +513,6 @@ struct CaptureCardSource::Impl:ISampleGrabberCB {
}
// Upload-backed target: written once, straight into GPU upload memory.
pipeline::selectCaptureUploadTarget(*target);
- decoder.setPictureFingerprints(pictureFingerprints.load(std::memory_order_relaxed));
AVFrame* decodedFrame=nullptr;bool hardware=false;
const bool produced=decoder.decode(sample.payload.data(),sample.payload.size(),int64_t(sample.time*1e7),target,&decodedFrame,hardware)&&!hardware;
{
@@ -628,7 +634,7 @@ struct CaptureCardSource::Impl:ISampleGrabberCB {
{std::lock_guard lock(mutex);if(stagingFrame&&!stagingBusy){stagingBusy=true;staged=stagingFrame;}
if(signalProbeEnabled&&arrival>=nextSignalProbe){nextSignalProbe=arrival+std::chrono::seconds(1);probeNow=true;}}
if(probeNow)signalSample=sampleCaptureSignal(layout,data,size_t(sample->GetActualDataLength()));
- if(staged)stagedOk=writeCaptureFrame(layout,data,size_t(sample->GetActualDataLength()),*staged,verticalFlip.load(),pictureFingerprints.load(std::memory_order_relaxed));
+ if(staged)stagedOk=writeCaptureFrame(layout,data,size_t(sample->GetActualDataLength()),*staged,verticalFlip.load(),pictureCompare.load(std::memory_order_relaxed)?&pictureReference:nullptr);
}
{
std::lock_guard lock(mutex);
@@ -703,7 +709,7 @@ struct CaptureCardSource::Impl:ISampleGrabberCB {
}else{
// Staging frame unavailable (should not happen once
// configured); keep the locked copy as a safe fallback.
- if(!writeCaptureFrame(layout,data,size_t(sample->GetActualDataLength()),*pendingFrame,verticalFlip.load(),pictureFingerprints.load(std::memory_order_relaxed))){callbackError=true;wake.notify_one();return S_OK;}
+ if(!writeCaptureFrame(layout,data,size_t(sample->GetActualDataLength()),*pendingFrame,verticalFlip.load(),pictureCompare.load(std::memory_order_relaxed)?&pictureReference:nullptr)){callbackError=true;wake.notify_one();return S_OK;}
}
if(pending)++dropped;
// Inspect consecutive callbacks, not consecutive mailbox reads.
@@ -872,8 +878,8 @@ void CaptureCardSource::setVerticalFlip(bool enabled){
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::setPictureFingerprints(bool enabled){
- if(p_->pictureFingerprints.exchange(enabled)!=enabled)log::info("capture-dedup",std::format("picture fingerprints={} (whole driver sample, content dedup)",enabled?1:0));
+void CaptureCardSource::setPictureCompare(bool enabled){
+ if(p_->pictureCompare.exchange(enabled)!=enabled)log::info("capture-dedup",std::format("picture compare={} (whole driver sample against the last new picture, band {} levels of 255; content dedup)",enabled?1:0,pipeline::PictureReference::kBand8));
}
void CaptureCardSource::setCpuUnpack(bool enabled){
auto& p=*p_;
diff --git a/src/source/CaptureCompressedDecoder.cpp b/src/source/CaptureCompressedDecoder.cpp
index c2728235..38ae9430 100644
--- a/src/source/CaptureCompressedDecoder.cpp
+++ b/src/source/CaptureCompressedDecoder.cpp
@@ -67,7 +67,6 @@ struct CaptureCompressedDecoder::Impl {
bool hardwareChecked = false;
bool waiting = false;
bool depthWarningLogged = false;
- bool fingerprints = false; // content dedup: fingerprint each decoded picture
std::string error;
uint64_t frames = 0, failures = 0, fallbacks = 0;
double decodeMs = 0, convertMs = 0;
@@ -109,16 +108,6 @@ struct CaptureCompressedDecoder::Impl {
}
}
pipeline::sampleCaptureUploadProxy(*target, frame.data[0], size_t(frame.linesize[0]), false);
- // Content dedup (ContentDedup.h): the decoded picture, every byte of every
- // plane; the upload buffer written above is never read back.
- if (auto* info = fingerprints ? pipeline::captureUploadFrame(target) : nullptr) {
- pipeline::PictureHasher hasher;
- const unsigned chromaRows = is422 ? height : height / 2;
- hasher.rows(frame.data[0], size_t(frame.linesize[0]), width, height);
- hasher.rows(frame.data[1], size_t(frame.linesize[1]), width / 2, chromaRows);
- hasher.rows(frame.data[2], size_t(frame.linesize[2]), width / 2, chromaRows);
- info->fingerprint = hasher.finish(); info->fingerprintValid = true;
- }
return true;
}
@@ -393,7 +382,6 @@ bool CaptureCompressedDecoder::opened() const { return p_->decoder.opened(); }
bool CaptureCompressedDecoder::hardwareActive() const { return p_->hardware; }
bool CaptureCompressedDecoder::waitingForInput() const { return p_->waiting; }
void CaptureCompressedDecoder::recoverAtKeyframe() { p_->decoder.recoverAtKeyframe(); }
-void CaptureCompressedDecoder::setPictureFingerprints(bool enabled) { p_->fingerprints = enabled; }
const char* CaptureCompressedDecoder::backendName() const
{
if (p_->hardware) return p_->stream && p_->codec == CaptureCodec::Hevc ? "d3d11va" : "d3d12va";
diff --git a/tests/unit/LivePresentationTimingTests.cpp b/tests/unit/LivePresentationTimingTests.cpp
index ecc0ee40..a0775f4e 100644
--- a/tests/unit/LivePresentationTimingTests.cpp
+++ b/tests/unit/LivePresentationTimingTests.cpp
@@ -4,7 +4,7 @@
#include "veyra/source/CaptureTiming.h"
#include "veyra/engine/CaptureHalfRate.h"
#include "veyra/engine/ContentDedup.h"
-#include "veyra/pipeline/PictureFingerprint.h"
+#include "veyra/pipeline/PictureCompare.h"
#include <algorithm>
#include <array>
#include <vector>
@@ -150,31 +150,60 @@ int main(){
check(livePairHoldMs(true,10,20)==0,"backwards PTS cannot sleep negatively");
check(livePairHoldMs(true,std::numeric_limits<double>::infinity(),0)==0,"nonfinite PTS rejected");
{
- // ContentDedup: synthetic pictures sampled at a capture rate, identified by
- // their exact fingerprint (PictureFingerprint.h). "60->30" is CaptureHalfRate
- // (tested above), not this.
- using veyra::engine::ContentDedup;using veyra::pipeline::PictureFingerprint;using veyra::pipeline::PictureHasher;
- // A 64x36 picture per id; noise makes every sample differ a little, so no two are bit-identical.
+ // PictureCompare.h: a sample repeats the last new picture only when every
+ // component of the whole picture is within the capture-noise band.
+ using veyra::pipeline::PictureReference;using veyra::pipeline::PicturePlane;using veyra::pipeline::PictureComponents;
+ std::vector<uint8_t> base(256*64);for(size_t i=0;i<base.size();++i)base[i]=uint8_t(40+(i*7919)%160);
+ auto bytes=[](PictureReference& r,const std::vector<uint8_t>& picture,unsigned rows=64){PicturePlane plane{picture.data(),256,256,rows};return r.observe(&plane,1,PictureComponents::Bytes);};
+ PictureReference ref;const auto first=bytes(ref,base);
+ // T911 1440p NV12 repeats: ~18% of pixels +-1, a few hundred +-2, rarely one at 3.
+ auto noisy=base;for(size_t i=0;i<noisy.size();i+=5)noisy[i]=uint8_t(noisy[i]+(i%3==0?2:i%3==1?-2:1));noisy[777]=uint8_t(noisy[777]+3);
+ const auto repeat=bytes(ref,noisy);
+ check(repeat.repeat&&repeat.id==first.id&&repeat.max8==3&&repeat.over==0,"picture within the noise band everywhere keeps its number");
+ auto moved=base;moved[4321]=uint8_t(moved[4321]+4);
+ const auto changed=bytes(ref,moved);
+ check(!changed.repeat&&changed.id!=first.id&&changed.over==1,"one component beyond the band is a new picture");
+ // +1 level per sample, judged against the last NEW picture: every 4th sample is new.
+ PictureReference drift;auto fade=base;int fresh=0;
+ for(int k=0;k<12;++k){for(auto& v:fade)v=uint8_t(v+1);fresh+=!bytes(drift,fade).repeat;}
+ check(fresh==3,"a slow fade accumulates past the band instead of slipping through it");
+ std::vector<uint16_t> deep(128*32);for(size_t i=0;i<deep.size();++i)deep[i]=uint16_t((64+(i*31)%800)<<6);
+ PictureReference words;const unsigned band=PictureReference::bandFor(10,6);
+ auto observeWords=[&](const std::vector<uint16_t>& picture){PicturePlane plane{reinterpret_cast<const uint8_t*>(picture.data()),256,256,32};return words.observe(&plane,1,PictureComponents::Words,band);};
+ const auto w0=observeWords(deep);auto wNoise=deep;for(size_t i=0;i<wNoise.size();i+=3)wNoise[i]=uint16_t(wNoise[i]+(12<<6));
+ const auto w1=observeWords(wNoise);auto wMove=deep;wMove[100]=uint16_t(wMove[100]+(13<<6));const auto w2=observeWords(wMove);
+ check(band==768&&w1.repeat&&w1.id==w0.id&&!w2.repeat&&w2.over==1,"P010: 12 levels of a 10-bit value are within the band, 13 are not");
+ PictureReference exact;PicturePlane e0{base.data(),256,256,64},e1{noisy.data(),256,256,64};exact.observe(&e0,1,PictureComponents::Exact);
+ check(!exact.observe(&e1,1,PictureComponents::Exact).repeat,"packed 10-bit / 5-6-bit layouts compare exactly");
+ check(!bytes(ref,base,32).repeat,"a different layout is a new picture");
+ PictureReference one{1},two{2};check(bytes(one,base).id!=bytes(two,base).id,"picture numbers of different references never collide");
+ }
+ {
+ // ContentDedup on picture numbers: synthetic pictures sampled at a capture rate.
+ // "60->30" is CaptureHalfRate (tested above), not this.
+ using veyra::engine::ContentDedup;using veyra::pipeline::PictureReference;using veyra::pipeline::PicturePlane;using veyra::pipeline::PictureComponents;
+ // A 64x36 picture per id; noise changes every component of every sample by up to +-noise.
auto picture=[](uint64_t id,int noise,uint64_t sample){
std::array<uint8_t,64*36> pixels{};
for(unsigned i=0;i<pixels.size();++i){
uint64_t h=(id+1)*0x9E3779B97F4A7C15ull+i*0xBF58476D1CE4E5B9ull;h^=h>>31;h*=0x94D049BB133111EBull;h^=h>>29;
- int v=int(h&0xFF);
+ int v=16+int(h%224);
if(noise){uint64_t n=(sample+7)*0xD6E8FEB86659FD93ull+i*0x2545F4914F6CDD1Dull;n^=n>>32;v+=int(n%unsigned(2*noise+1))-noise;}
pixels[i]=uint8_t(std::clamp(v,0,255));
}
- PictureHasher hasher;hasher.rows(pixels.data(),64,64,36);return hasher.finish();
+ return pixels;
};
+ auto number=[](PictureReference& numbers,const std::array<uint8_t,64*36>& pixels){PicturePlane plane{pixels.data(),64,64,36};return numbers.observe(&plane,1,PictureComponents::Bytes).id;};
struct Run{int kept=0,keptRepeats=0,droppedReal=0,regularSpans=0,spans=0;bool monotonic=true,neverLate=true;std::vector<int64_t> intervals;};
// contentOf(sample) gives the picture shown by sample i (ground truth).
auto run=[&](double captureFps,auto contentOf,int count,int noise,int64_t hint,int64_t expectedPeriod){
- ContentDedup dedup;Run r;
+ ContentDedup dedup;PictureReference numbers;Run r;
const int64_t dt=int64_t(std::llround(1e7/captureFps));int64_t lastContent=-1;int64_t lastPicture=-1;int64_t pendingPicture=-1;
for(int i=0;i<count;++i){
- const int64_t pts=int64_t(i)*dt+1000;const int64_t id=contentOf(i);const auto fingerprint=picture(uint64_t(id),noise,uint64_t(i));
- const auto d=dedup.observe(&fingerprint,pts,dt,i==0,hint);
+ const int64_t pts=int64_t(i)*dt+1000;const int64_t id=contentOf(i);const uint64_t shown=number(numbers,picture(uint64_t(id),noise,uint64_t(i)));
+ const auto d=dedup.observe(&shown,pts,dt,i==0,hint);
if(d.keep){
- ++r.kept;if(id==lastPicture&&!noise)++r.keptRepeats;
+ ++r.kept;if(id==lastPicture)++r.keptRepeats;
if(pendingPicture>=0&&pendingPicture!=id)++r.droppedReal; // a newer picture superseded an unkept one
pendingPicture=-1;lastPicture=id;
r.monotonic&=d.contentPts>lastContent;r.neverLate&=d.contentPts<=pts;lastContent=d.contentPts;
@@ -195,31 +224,29 @@ int main(){
check(r.monotonic&&r.neverLate&&r.regularSpans*100>=r.spans*95,"dedup 40-in-60: alternating 33/17 ms samples become even 25 ms content spans");}
{const auto r=run(60.0,[](int i){return int64_t(i);},n,0,0,166667);
check(r.kept==n&&r.regularSpans==r.spans,"dedup true 60: nothing dropped, timing unchanged");}
- {const auto r=run(60.0,[](int i){return int64_t(i/2);},n,1,0,333333);
- check(r.kept==n&&r.droppedReal==0,"dedup 30-in-60 with capture noise: repeats that are not bit-identical are all kept");}
- {// Hitch: one picture shown for three samples, then the 30 fps cadence resumes one slot later.
+ {// +-1 per sample: two samples of one picture differ by up to 2, like the T911 (card_diff.py).
+ const auto r=run(60.0,[](int i){return int64_t(i/2);},n,1,0,333333);
+ check(r.kept==n/2&&r.keptRepeats==0&&r.droppedReal==0,"dedup 30-in-60 with capture noise inside the band: repeats dropped, real pictures kept");}
+ {const auto r=run(60.0,[](int i){return int64_t(i/2);},n,6,0,333333);
+ check(r.kept==n&&r.droppedReal==0,"dedup 30-in-60 with noise beyond the band: every sample kept, nothing lost");}
+ {// Hitch: one picture shown for four samples, then the 30 fps cadence resumes one slot later.
const auto r=run(60.0,[](int i){return int64_t(i<301?i/2:(i<304?150:(i-1)/2));},n,0,0,333333);
check(r.keptRepeats==0&&r.droppedReal==0&&r.monotonic&&r.neverLate,"dedup hitch: no real picture lost, timestamps stay ordered and never late");}
- {// A still 1440p P010-sized scene where one byte changes per new picture: the
- // 64x36 points of the first version lost such pictures (field log 2026-10-12).
- std::vector<uint8_t> frame(size_t(5120)*1440,90);ContentDedup dedup;int kept=0;
- for(int i=0;i<120;++i){
- if(i%2==0)frame[size_t(i)*7919%frame.size()]^=1;
- PictureHasher hasher;hasher.rows(frame.data(),5120,5120,1440);const auto fingerprint=hasher.finish();
- kept+=dedup.observe(&fingerprint,i*166667+1000,166667,i==0).keep;
- }
- check(kept==60,"dedup: a picture that differs in one byte is new, its exact repeat is dropped");}
+ {// Mailbox overwrite: the first sample of a picture is never read; its second still counts as new.
+ ContentDedup dedup;int kept=0;
+ for(int i=0;i<120;++i){if(i%4==2)continue;const uint64_t shown=uint64_t(i/2);kept+=dedup.observe(&shown,i*166667+1000,166667,i==0).keep;}
+ check(kept==60,"dedup keeps a picture whose first sample the engine never read");}
{// Still picture after 30 fps content: held on the 33.3 ms cadence (steady GPU work), not once per 150-250 ms.
ContentDedup dedup;int kept=0;
- for(int i=0;i<600;++i){const auto fingerprint=picture(i<240?uint64_t(i/2):1000u,0,0);const bool keep=dedup.observe(&fingerprint,i*166667+1000,166667,i==0).keep;if(i>=300)kept+=keep;}
+ for(int i=0;i<600;++i){const uint64_t shown=i<240?uint64_t(i/2):1000u;const bool keep=dedup.observe(&shown,i*166667+1000,166667,i==0).keep;if(i>=300)kept+=keep;}
check(kept>=148&&kept<=152&&dedup.stats().held>=140,"dedup still picture after 30 fps content is held at a steady 30 fps");}
{// Still picture after 40 fps content in 60 Hz: held on the 25 ms grid (33/17 ms samples).
ContentDedup dedup;int kept=0;
- for(int i=0;i<600;++i){const auto fingerprint=picture(i<240?uint64_t(std::floor(i*40.0/60.0+1e-9)):1000u,0,0);const bool keep=dedup.observe(&fingerprint,i*166667+1000,166667,i==0).keep;if(i>=300)kept+=keep;}
+ for(int i=0;i<600;++i){const uint64_t shown=i<240?uint64_t(std::floor(i*40.0/60.0+1e-9)):1000u;const bool keep=dedup.observe(&shown,i*166667+1000,166667,i==0).keep;if(i>=300)kept+=keep;}
check(kept>=196&&kept<=204,"dedup still picture after 40 fps content is held at 40 fps");}
{// Still picture from the start, no learned rate: half the 60 Hz transport.
- ContentDedup dedup;const auto fingerprint=picture(3,0,0);int kept=0;
- for(int i=0;i<240;++i)kept+=dedup.observe(&fingerprint,i*166667+1000,166667,i==0).keep;
+ ContentDedup dedup;const uint64_t shown=3;int kept=0;
+ for(int i=0;i<240;++i)kept+=dedup.observe(&shown,i*166667+1000,166667,i==0).keep;
check(kept>=116&&kept<=122,"dedup still picture with no learned rate keeps 30 of a 60 Hz capture");}
{// No CPU picture: everything is kept.
ContentDedup dedup;int kept=0;for(int i=0;i<60;++i)kept+=dedup.observe(nullptr,i*166667+1000,166667,i==0).keep;