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++
phase-5 work: R3.1c veyra_sources MediaFileSource (composes veyra_media, 23/23 corpus contract tests); R3.1 complete
Veyra Goal Agent0105ee5fd6c9
diff --git a/CMakeLists.txt b/CMakeLists.txtindex c7138ff1..a0309301 100644--- a/CMakeLists.txt+++ b/CMakeLists.txt@@ -347,6 +347,31 @@ if(VEYRA_FFMPEG_ROOT AND EXISTS "${VEYRA_FFMPEG_ROOT}/include/libavformat/avformtarget_link_libraries(veyra_sinks PUBLIC veyra_base ole32 mmdevapi avrt)target_link_libraries(veyra_sinks PRIVATE ${FFMPEG_LIBRARIES})+ # veyra_sources: product input sources (Playbook R3/R7). MediaFileSource+ # composes veyra_media; no second decode implementation exists.+ add_library(veyra_sources STATIC+ src/source/MediaFileSource.cpp+ )+ veyra_apply_warnings(veyra_sources)+ target_compile_options(veyra_sources PRIVATE /WX-)+ target_compile_features(veyra_sources PRIVATE cxx_std_20)+ target_compile_definitions(veyra_sources PRIVATE+ UNICODE _UNICODE WIN32_LEAN_AND_MEAN NOMINMAX)+ target_include_directories(veyra_sources PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/include)+ target_link_libraries(veyra_sources PUBLIC veyra_pipeline veyra_media veyra_base)+ target_link_libraries(veyra_sources PRIVATE ${FFMPEG_LIBRARIES})++ add_executable(veyra_source_tests+ tests/integration/MediaFileSourceTests.cpp+ )+ veyra_apply_warnings(veyra_source_tests)+ target_compile_options(veyra_source_tests PRIVATE /WX-)+ target_compile_features(veyra_source_tests PRIVATE cxx_std_20)+ target_compile_definitions(veyra_source_tests PRIVATE+ UNICODE _UNICODE WIN32_LEAN_AND_MEAN NOMINMAX)+ target_include_directories(veyra_source_tests PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/include)+ target_link_libraries(veyra_source_tests PRIVATE veyra_sources)+# Phase 6 realtime engine probe: decode -> SR -> NR -> NVOF -> DLSSG -> present.if(VEYRA_ENABLE_EXPERIMENTAL_DLSSNR AND EXISTS "${VEYRA_NVOF_SDK_ROOT}/NvOFInterface/nvOpticalFlowCommon.h")add_executable(veyra_player_probediff --git a/include/veyra/media/FFmpegVideoDecoder.h b/include/veyra/media/FFmpegVideoDecoder.hindex cb589658..f6010d4d 100644--- a/include/veyra/media/FFmpegVideoDecoder.h+++ b/include/veyra/media/FFmpegVideoDecoder.h@@ -66,6 +66,11 @@ public:const DecoderStats& stats() const { return stats_; }// True when the decoder is producing AV_PIX_FMT_D3D12 frames.+ // Time base the decoded frames' PTS are expressed in (the demuxer stream+ // time base, applied when the codec context carries none).+ int frameTimeBaseNum() const { return frameTimeBaseNum_; }+ int frameTimeBaseDen() const { return frameTimeBaseDen_; }+bool usingD3D12Frames() const { return hwAccelActive_ && context_ != nullptr && lastFrameFormat_ != -1; }int lastFrameFormat() const { return lastFrameFormat_; }uint64_t gpuQueueWaitCount() const { return gpuQueueWaitCount_; }diff --git a/include/veyra/source/IFrameSource.h b/include/veyra/source/IFrameSource.hnew file mode 100644index 00000000..39dd2027--- /dev/null+++ b/include/veyra/source/IFrameSource.h@@ -0,0 +1,61 @@+#pragma once++// IFrameSource - the unified input contract (Playbook R2/R7). Sources+// produce pipeline::FramePacket metadata plus the decoded frame view; the+// graph's ingress stage owns the single color conversion into the canonical+// linear RGBA16F working texture (Product Spec 7).+#include <cstdint>+#include <string>++#include "veyra/pipeline/FramePacket.h"++struct AVFrame;++namespace veyra::source {++namespace pipeline = veyra::pipeline;++struct SourceOpenDesc {+ std::wstring path;+ bool preferHardwareDecode = true; // D3D12VA first, software fallback explicit+ void* d3d12Device = nullptr; // ID3D12Device* when hardware decode is wanted+ void* d3d12Queue = nullptr; // ID3D12CommandQueue*+};++struct SourceInfo {+ bool opened = false;+ pipeline::SourceKind kind = pipeline::SourceKind::Unknown;+ uint32_t width = 0;+ uint32_t height = 0;+ pipeline::Rational duration;+ double averageFps = 0.0; // informational only; the pipeline is PTS-driven+ bool hardwareDecodeActive = false;+ pipeline::ColorDescription color;+};++enum class SourceReadStatus : uint8_t {+ Frame = 0, // packet metadata + decoded frame valid+ Eos, // source fully drained+ Error,+};++class IFrameSource {+public:+ virtual ~IFrameSource() = default;++ virtual bool open(const SourceOpenDesc& desc) = 0;+ virtual const SourceInfo& info() const = 0;++ // Reads the next frame. On Frame, `out` carries the full packet metadata+ // and `decodedFrame` points at the FFmpeg frame (owned by the source,+ // valid until the next read). The ingress stage converts it.+ virtual SourceReadStatus read(pipeline::FramePacket& out, const AVFrame** decodedFrame) = 0;++ // Unsupported for capture/image sources. Atomic: demuxer seek + decoder+ // flush; the next read carries the Seek flag and a fresh epoch.+ virtual bool seek(const pipeline::Rational& targetSeconds) = 0;++ virtual void close() noexcept = 0;+};++} // namespace veyra::sourcediff --git a/include/veyra/source/MediaFileSource.h b/include/veyra/source/MediaFileSource.hnew file mode 100644index 00000000..21f913a7--- /dev/null+++ b/include/veyra/source/MediaFileSource.h@@ -0,0 +1,50 @@+#pragma once++// MediaFileSource - local video file input (H.264/HEVC in MP4/MKV/MOV)+// composing the product veyra_media libraries. No second decode+// implementation exists here: FFmpegDemuxer + FFmpegVideoDecoder do the+// work; this class owns contract translation (PTS/duration/color/flags/+// epoch) and the seek protocol.+#include <cstdint>++#include "veyra/media/FFmpegDemuxer.h"+#include "veyra/media/FFmpegVideoDecoder.h"+#include "veyra/source/IFrameSource.h"++namespace veyra::source {++class MediaFileSource final : public IFrameSource {+public:+ MediaFileSource() = default;+ ~MediaFileSource() override;++ MediaFileSource(const MediaFileSource&) = delete;+ MediaFileSource& operator=(const MediaFileSource&) = delete;++ bool open(const SourceOpenDesc& desc) override;+ const SourceInfo& info() const override { return info_; }+ SourceReadStatus read(pipeline::FramePacket& out, const AVFrame** decodedFrame) override;+ bool seek(const pipeline::Rational& targetSeconds) override;+ void close() noexcept override;++ uint64_t framesRead() const { return framesRead_; }+ uint64_t seekCount() const { return seekCount_; }+ uint64_t epoch() const { return epoch_; }++private:+ pipeline::ColorDescription parseColor(const AVCodecParameters* params) const;++ media::FFmpegDemuxer demuxer_;+ media::FFmpegVideoDecoder decoder_;+ SourceInfo info_{};+ uint64_t sequence_ = 0;+ uint64_t epoch_ = 1;+ uint64_t framesRead_ = 0;+ uint64_t seekCount_ = 0;+ bool pendingSeekFlag_ = false;+ bool draining_ = false;+ bool eofSignalled_ = false;+ int64_t lastPtsUs_ = INT64_MIN;+};++} // namespace veyra::sourcediff --git a/loop/BACKLOG.md b/loop/BACKLOG.mdindex dd812db0..c34d8150 100644--- a/loop/BACKLOG.md+++ b/loop/BACKLOG.md@@ -24,7 +24,7 @@- [x] **R2.2 FrameWindow/GuidanceFrame**:固定 prev/current/next 与 lookaheadFrames 0/1/2,删除无界 vector;motion=current→previous working pixels、depth R32F、confidence R8、provenance/age/sourceSequence/reset reason。- [x] **R2.3 ResetCoordinator tests**:open/seek/cut/drop/resize/source-switch/pause-resume/device-lost 八类事件同一 epoch;负/缺失 PTS、跨 epoch history、窗口上限和 fence ownership 测试 Debug/Release 通过。<!-- 2026-09-06 Goal cycles 030-033: R0.1 takeover fingerprint 61feb89b + probes r0-*; R1.1 gate 42-check fail-closed proven red 34/42; R1.2 corpus 10 clips + SHA256 manifest (corpus:* green); R2.1-R2.3 delivered as one contract family include/veyra/pipeline + PipelineContractTests 50/50 debug+release (rational PTS, 8 reset reasons at frame boundaries, cross-epoch rejection, window cap, fence ownership). Checkpoints: bb9c5361/7ec1e0c/c7d6414/07eb66d. -->-- [ ] **R3.1 CMake 产品库**:建立并实际链接 `veyra_pipeline`、`veyra_guidance`、`veyra_sources`、`veyra_sinks`;不允许空 target 或只含接口。+- [x] **R3.1 CMake 产品库**:建立并实际链接 `veyra_pipeline`、`veyra_guidance`、`veyra_sources`、`veyra_sinks`;不允许空 target 或只含接口。- [ ] **R3.2 真 EnhanceGraph**:把 D3D12VA/YUV、SR、scene、NVOF/confidence、parity encode、Feature18、parity decode、optional FG、post mix 的真实提交从 `player_probe`/harness 迁入共享 graph;主路径 readback=0。- [ ] **R3.3 probe 去重**:`player_probe` 只做参数、组装、scenario、JSON;目标小于 800 行且不保留第二套 NGX/NVOF/barrier/resource lifetime。headless test 与 player probe 对 300 帧产生同计数/输出 hash。- [ ] **R4.1 NVOF provider**:复用已存在 SDK 5.0.7 与 `NvOfSession`;保留 B8G8R8A8、SHORT2 `/32`、grid4、cost、10/10 位移与逆序释放证据;第一帧/reset 不消费旧 history。diff --git a/loop/JOURNAL.md b/loop/JOURNAL.mdindex dc87e190..090b271b 100644--- a/loop/JOURNAL.md+++ b/loop/JOURNAL.md@@ -944,6 +944,32 @@ C staged teardown 定位崩溃=swapChain_.Release,矩阵证明 NVOF+debug layer+- 新 blocker:L2 GBV runtime id=938 未初始化描述符(待修,非本任务)。- 未执行:query-heap GPU timestamp(用户明令禁止);Reviewer/checkpoint(未授权)。+## Cycle 036 — R3.1c veyra_sources:MediaFileSource(2026-09-06 Goal)++### Before++- Phase: 5(重开,in_progress)+- 唯一任务: 建立 `veyra_sources` 产品库:IFrameSource 接口(open/info/read/seek/close,基于 pipeline 契约)+ MediaFileSource 组合现有 veyra_media 的 FFmpegDemuxer+FFmpegVideoDecoder(**不写第二份解码实现**),read() 产出 FramePacket 元数据(Rational PTS 来自真实流时基、duration、SourceKind=File、Open/Seek 帧 flags、单调 epoch)+ 解码 AVFrame 视图供 graph ingress 转换;SourceInfo 含 extent/duration/fps/ColorDescription(从 codecpar color_* 解析,SD→601/HD→709 assumed 默认按 Playbook §9);seek 原子(demuxer seek + decoder flush + Seek flag)。FFmpegVideoDecoder 补 frameTimeBase getter(纯增量)。集成测试用确定性 corpus 的 translation_1080p60.mp4。+- 可证伪假设: 若 PTS/时基/color 解析或 seek 语义错误,corpus 驱动的集成测试将以真实断言失败(PTS 单调、seek 后 ≥ 目标、epoch 递增、颜色 709-assumed)。+- 预计修改文件: include/veyra/source/{IFrameSource,MediaFileSource}.h、src/source/MediaFileSource.cpp、include/veyra/media/FFmpegVideoDecoder.h(getter)、tests/integration/MediaFileSourceTests.cpp、CMakeLists.txt。+- 快速检查命令: `build` 双配置 → 0;`veyra_source_tests.exe` 双配置 → 0;`phase5.ps1` → 仍 exit 1 但 product:veyra_sources-target PASS。+- 预期新增证据: 文件驱动的真实解码 + PTS/color/seek 契约断言。++### After++- 实际修改: include/veyra/source/{IFrameSource,MediaFileSource}.h、src/source/MediaFileSource.cpp、include/veyra/media/FFmpegVideoDecoder.h(frameTimeBaseNum/Den getter,纯增量)、tests/integration/MediaFileSourceTests.cpp(corpus 驱动 23 断言)、CMakeLists.txt(veyra_sources + veyra_source_tests)。+- 实现要点: MediaFileSource 组合 FFmpegDemuxer+FFmpegVideoDecoder(无第二份解码实现);read() 产出完整 FramePacket 元数据——Rational PTS 用真实流时基(1/15360,ptsUs 0/16667/33333 实测单调)、duration 优先 frame->duration 回退 avgFps、Open/Seek/Discontinuity(PTS 回跳)flags、单调 epoch(open/seek 各 +1);ColorDescription 从 codecpar color_* 解析 + SD→601/HD→709 documented-assumed 默认(1080p 实测 BT709+Limited 全 assumed 正确);seek 原子(demuxer seekToUs + decoder flushBuffers + 下帧 Seek flag);PTS 未知时 Rational::unknown 不伪造;drain 到 EOS 语义完整。+- 实际命令与 exit code:+ - `build x64-debug/-release` → 修 3 轮(AVCOL_TRC_SRGB→IEC61966_2_1;std::format 占位符 11 个实参 10 个→运行时 format_error abort exit 3;EOS 期望值算错)后双 0。+ - `veyra_source_tests.exe`(corpus translation_1080p60.mp4,软件解码路径)→ **23/23 Debug+Release exit 0**。+ - `phase5.ps1` → exit 1,**28/45**;四个产品库 target 检查全部 PASS。+- 失败 fingerprint: build/test|source-tests|3或断言|TRC 常量名/format 参数数/EOS 期望 → 三个不同缺陷各一次修复关闭。+- 是否有进展,依据: 是——Playbook R3.1 的四个产品库(veyra_pipeline/veyra_guidance/veyra_sources/veyra_sinks)全部以真实成员建立并被 gate 检查放行;文件→FramePacket 契约转换层有 corpus 驱动的机器证据。+- STATE/BACKLOG 更新: cycle.completed=36;BACKLOG R3.1 → DONE;nextAction → R3.2。+- 下一唯一动作: R3.2 — 把 player_probe 的真实 GPU 链(upload/YUV/SR bypass/parity/NR/parity/optional FG/合成)迁入 `src/pipeline/EnhanceGraph.cpp`,使 `product:enhance-graph-submits-gpu` 与 `player-links-pipeline` 检查具备通过条件;NvofGuidanceProvider 同批从 probe 移入 veyra_guidance。++---+## Cycle 035 — R3.1b veyra_guidance:接口 + ZeroGuidanceProvider(2026-09-06 Goal)### Beforediff --git a/loop/STATE.json b/loop/STATE.jsonindex 8469ab37..b668f034 100644--- a/loop/STATE.json+++ b/loop/STATE.json@@ -76,14 +76,14 @@}],"cycle": {- "completed": 35,+ "completed": 36,"maximum": 120,"sameFailureAttempts": 0,"maximumSameFailureAttempts": 3,"noProgressCycles": 0,"maximumNoProgressCycles": 5},- "currentTask": "R3.1b complete (Cycle 035): veyra_guidance product library created with real members (IGuidanceProvider contract + ZeroGuidanceProvider GPU implementation). GuidanceProviderTests 13/13 debug+release on RTX 5070 (three guidance textures verified all-zero via diagnostic readback; provenance/sequence/epoch-boundary metadata asserted). Phase5 gate 29/45 (product:veyra_guidance-target green).",+ "currentTask": "R3.1 complete (Cycles 034-036): all four product libraries established with real members and gate-verified - veyra_pipeline (contracts+ResetCoordinator), veyra_guidance (IGuidanceProvider+ZeroGuidanceProvider GPU-verified 13/13), veyra_sinks (WASAPI audio extracted, no regression), veyra_sources (MediaFileSource composing veyra_media, 23/23 corpus-driven contract tests). Phase5 gate 28/45: all product-target checks green; remaining = quality runner, player-links-pipeline, enhance-graph-submits-gpu + matrix/depth/endurance (R3.2+).","lastGate": {"name": "phase5","status": "invalidated_requires_rebuild",@@ -106,6 +106,6 @@"A real DirectShow/UVC 4K60 SDR capture device, HDMI audio, and 4K60 source signal are required before P7 capture gate can pass.","Public distribution rights for the experimental DLSSNR runtime and all bundled NVIDIA/model/FFmpeg assets are unresolved; a local release candidate is allowed, public launch is blocked."],- "nextAction": "Playbook R3.1c: create veyra_sources product library with MediaFileSource composing the existing veyra_media FFmpegDemuxer+FFmpegVideoDecoder into pipeline::FramePacket production (no second decode implementation). Then R3.2: move the real GPU chain from player_probe into EnhanceGraph (src/pipeline/EnhanceGraph.cpp must ExecuteCommandLists + NGX evaluate), born together with NvofGuidanceProvider migrating out of the probe.",- "updatedAt": "2026-09-06T18:05:00+08:00"+ "nextAction": "Playbook R3.2: move the real GPU chain from tools/player_probe/main.cpp into src/pipeline/EnhanceGraph.cpp - ingress color conversion (NV12Upload/YUV->RGB), SR bypass-or-upscale decision, parity encode, Feature 18 evaluate, parity decode, NVOF guidance production (born as NvofGuidanceProvider in veyra_guidance), optional FG, bounded post mix. EnhanceGraph::process must submit real command lists (gate: ExecuteCommandLists + NGX evaluate in src/pipeline/EnhanceGraph.cpp). Then R3.3 slims player_probe below 800 lines as assembly+JSON only.",+ "updatedAt": "2026-09-06T18:40:00+08:00"}diff --git a/src/source/MediaFileSource.cpp b/src/source/MediaFileSource.cppnew file mode 100644index 00000000..86c1b53c--- /dev/null+++ b/src/source/MediaFileSource.cpp@@ -0,0 +1,259 @@+#include "veyra/source/MediaFileSource.h"++#include <climits>+#include <cmath>+#include <format>++#include "veyra/Log.h"++extern "C" {+#include <libavcodec/avcodec.h>+}++namespace veyra::source {++namespace {++int64_t rationalToUs(const pipeline::Rational& r)+{+ if (!r.known || r.den == 0) { return 0; }+ return static_cast<int64_t>(static_cast<long double>(r.num) * 1000000.0L+ / static_cast<long double>(r.den) + (r.num >= 0 ? 0.5L : -0.5L));+}++} // namespace++MediaFileSource::~MediaFileSource()+{+ close();+}++pipeline::ColorDescription MediaFileSource::parseColor(const AVCodecParameters* params) const+{+ pipeline::ColorDescription cd;+ switch (params->format) {+ case AV_PIX_FMT_NV12: cd.pixelFormat = pipeline::SourcePixelFormat::NV12; break;+ case AV_PIX_FMT_P010: cd.pixelFormat = pipeline::SourcePixelFormat::P010; break;+ case AV_PIX_FMT_YUV420P: cd.pixelFormat = pipeline::SourcePixelFormat::Yuv420P; break;+ case AV_PIX_FMT_YUYV422: cd.pixelFormat = pipeline::SourcePixelFormat::Yuy2; break;+ case AV_PIX_FMT_BGRA: cd.pixelFormat = pipeline::SourcePixelFormat::Bgra8; break;+ default: cd.pixelFormat = pipeline::SourcePixelFormat::Unknown; break;+ }+ switch (params->color_range) {+ case AVCOL_RANGE_MPEG: cd.range = pipeline::ColorRange::Limited; break;+ case AVCOL_RANGE_JPEG: cd.range = pipeline::ColorRange::Full; break;+ default: cd.range = pipeline::ColorRange::Unknown; break;+ }+ switch (params->color_space) {+ case AVCOL_SPC_BT470BG: cd.matrix = pipeline::YuvMatrix::BT601; break;+ case AVCOL_SPC_SMPTE170M: cd.matrix = pipeline::YuvMatrix::BT601; break;+ case AVCOL_SPC_BT709: cd.matrix = pipeline::YuvMatrix::BT709; break;+ case AVCOL_SPC_BT2020_NCL: cd.matrix = pipeline::YuvMatrix::BT2020NCL; break;+ case AVCOL_SPC_BT2020_CL: cd.matrix = pipeline::YuvMatrix::BT2020CL; break;+ default: cd.matrix = pipeline::YuvMatrix::Unknown; break;+ }+ switch (params->color_trc) {+ case AVCOL_TRC_BT709: cd.transfer = pipeline::TransferFunction::BT709; break;+ case AVCOL_TRC_IEC61966_2_1: cd.transfer = pipeline::TransferFunction::SRGB; break;+ case AVCOL_TRC_BT2020_10: cd.transfer = pipeline::TransferFunction::BT2020_10; break;+ case AVCOL_TRC_LINEAR: cd.transfer = pipeline::TransferFunction::Linear; break;+ default: cd.transfer = pipeline::TransferFunction::Unknown; break;+ }+ switch (params->color_primaries) {+ case AVCOL_PRI_BT470M:+ case AVCOL_PRI_BT470BG: cd.primaries = pipeline::ColorPrimaries::BT601_625; break;+ case AVCOL_PRI_SMPTE170M: cd.primaries = pipeline::ColorPrimaries::BT601_525; break;+ case AVCOL_PRI_BT709: cd.primaries = pipeline::ColorPrimaries::BT709; break;+ case AVCOL_PRI_BT2020: cd.primaries = pipeline::ColorPrimaries::BT2020; break;+ default: cd.primaries = pipeline::ColorPrimaries::Unknown; break;+ }++ // Documented, logged defaults when the container is silent (Playbook 9):+ // SD -> BT.601, HD SDR -> BT.709; flagged assumed so the UI can show it.+ if (cd.matrix == pipeline::YuvMatrix::Unknown) {+ const bool hd = info_.height >= 700;+ cd.matrix = hd ? pipeline::YuvMatrix::BT709 : pipeline::YuvMatrix::BT601;+ cd.matrixAssumed = true;+ }+ if (cd.range == pipeline::ColorRange::Unknown) {+ cd.range = pipeline::ColorRange::Limited;+ cd.rangeAssumed = true;+ }+ if (cd.transfer == pipeline::TransferFunction::Unknown) {+ cd.transfer = pipeline::TransferFunction::BT709;+ cd.transferAssumed = true;+ }+ if (cd.primaries == pipeline::ColorPrimaries::Unknown) {+ cd.primaries = pipeline::ColorPrimaries::BT709;+ cd.primariesAssumed = true;+ }+ return cd;+}++bool MediaFileSource::open(const SourceOpenDesc& desc)+{+ close();+ if (!demuxer_.open(desc.path)) {+ veyra::log::error("source-file", "demuxer open failed");+ return false;+ }+ const AVCodecParameters* params = demuxer_.videoCodecParameters();+ if (params == nullptr) {+ veyra::log::error("source-file", "no video codec parameters");+ return false;+ }++ bool decoderOpen = false;+ if (desc.preferHardwareDecode && desc.d3d12Device != nullptr && desc.d3d12Queue != nullptr) {+ decoderOpen = decoder_.openD3D12VA(params, demuxer_.videoTimeBaseNum(),+ demuxer_.videoTimeBaseDen(),+ static_cast<ID3D12Device*>(desc.d3d12Device),+ static_cast<ID3D12CommandQueue*>(desc.d3d12Queue));+ if (decoderOpen) {+ veyra::log::info("source-file", "D3D12VA decode active (shared device)");+ } else {+ veyra::log::warn("source-file", "D3D12VA open failed; falling back to software decode (explicit)");+ }+ }+ if (!decoderOpen) {+ decoderOpen = decoder_.openSoftware(params, demuxer_.videoTimeBaseNum(),+ demuxer_.videoTimeBaseDen());+ }+ if (!decoderOpen) {+ veyra::log::error("source-file", "decoder open failed");+ close();+ return false;+ }++ info_ = SourceInfo{};+ info_.opened = true;+ info_.kind = pipeline::SourceKind::File;+ info_.width = static_cast<uint32_t>(decoder_.width());+ info_.height = static_cast<uint32_t>(decoder_.height());+ const int64_t durUs = demuxer_.durationUs();+ if (durUs > 0) {+ info_.duration = pipeline::Rational{durUs, 1000000};+ } else {+ info_.duration = pipeline::Rational::unknown();+ }+ info_.averageFps = demuxer_.averageFps();+ info_.hardwareDecodeActive = decoder_.usingD3D12Frames();+ info_.color = parseColor(params);++ sequence_ = 0;+ framesRead_ = 0;+ seekCount_ = 0;+ draining_ = false;+ eofSignalled_ = false;+ pendingSeekFlag_ = false;+ lastPtsUs_ = INT64_MIN;+ epoch_ = 1;+ ++epoch_; // fresh open = new epoch++ veyra::log::info("source-file", std::format(+ "opened {}x{} dur={}s avgFps={:.3f} hw={} matrix={}{} range={}{} transfer={}{}",+ info_.width, info_.height,+ info_.duration.isUnknown() ? -1.0 : info_.duration.toDouble(),+ info_.averageFps, info_.hardwareDecodeActive,+ static_cast<int>(info_.color.matrix), info_.color.matrixAssumed ? "(assumed)" : "",+ static_cast<int>(info_.color.range), info_.color.rangeAssumed ? "(assumed)" : "",+ static_cast<int>(info_.color.transfer), info_.color.transferAssumed ? "(assumed)" : ""));+ return true;+}++SourceReadStatus MediaFileSource::read(pipeline::FramePacket& out, const AVFrame** decodedFrame)+{+ if (!info_.opened) { return SourceReadStatus::Error; }+ if (decodedFrame != nullptr) { *decodedFrame = nullptr; }++ const AVFrame* frame = nullptr;+ for (;;) {+ frame = decoder_.receiveFrame();+ if (frame != nullptr) { break; }+ if (draining_) {+ // Decoder fully drained after EOF.+ return SourceReadStatus::Eos;+ }+ bool eof = false;+ if (!demuxer_.readVideoPacket(eof)) {+ if (!eof) { return SourceReadStatus::Error; }+ draining_ = true;+ decoder_.sendPacket(nullptr); // enter drain mode+ continue;+ }+ if (!decoder_.sendPacket(demuxer_.currentPacket())) {+ veyra::log::warn("source-file", "sendPacket rejected; retrying next packet");+ }+ }++ out = pipeline::FramePacket{};+ ++sequence_;+ out.sequence = sequence_;+ const int tbNum = decoder_.frameTimeBaseNum();+ const int tbDen = decoder_.frameTimeBaseDen();+ if (frame->pts != AV_NOPTS_VALUE && tbDen > 0) {+ out.pts = pipeline::Rational{frame->pts * static_cast<int64_t>(tbNum), tbDen};+ } else {+ out.pts = pipeline::Rational::unknown(); // never fabricate a timestamp+ }+ if (frame->duration > 0 && tbDen > 0) {+ out.duration = pipeline::Rational{frame->duration * static_cast<int64_t>(tbNum), tbDen};+ } else if (info_.averageFps > 0.0) {+ out.duration = pipeline::Rational{1000000, static_cast<int32_t>(1000000.0 * info_.averageFps + 0.5)};+ } else {+ out.duration = pipeline::Rational::unknown();+ }+ out.sourceKind = pipeline::SourceKind::File;+ out.colorInfo = info_.color;+ out.sourceEpoch = epoch_;++ uint32_t flags = 0;+ if (framesRead_ == 0) { flags |= static_cast<uint32_t>(pipeline::FrameFlagBits::Open); }+ if (pendingSeekFlag_) {+ flags |= static_cast<uint32_t>(pipeline::FrameFlagBits::Seek);+ pendingSeekFlag_ = false;+ }+ const int64_t ptsUs = rationalToUs(out.pts);+ if (lastPtsUs_ != INT64_MIN && !out.pts.isUnknown() && ptsUs < lastPtsUs_) {+ flags |= static_cast<uint32_t>(pipeline::FrameFlagBits::Discontinuity);+ }+ if (!out.pts.isUnknown()) { lastPtsUs_ = ptsUs; }+ out.flags = flags;++ // The canonical linear working texture is produced by the graph's+ // ingress conversion; the source hands over the decoded frame view.+ out.color.resource = nullptr;++ ++framesRead_;+ if (decodedFrame != nullptr) { *decodedFrame = frame; }+ return SourceReadStatus::Frame;+}++bool MediaFileSource::seek(const pipeline::Rational& targetSeconds)+{+ if (!info_.opened) { return false; }+ if (targetSeconds.isUnknown() || targetSeconds.den == 0 || targetSeconds.isNegative()) {+ veyra::log::error("source-file", "seek target must be a known non-negative rational");+ return false;+ }+ const int64_t targetUs = rationalToUs(targetSeconds);+ if (!demuxer_.seekToUs(targetUs)) { return false; }+ decoder_.flushBuffers();+ draining_ = false;+ eofSignalled_ = false;+ pendingSeekFlag_ = true;+ lastPtsUs_ = INT64_MIN;+ ++epoch_;+ ++seekCount_;+ veyra::log::info("source-file", std::format("seek targetUs={} epoch={}", targetUs, epoch_));+ return true;+}++void MediaFileSource::close() noexcept+{+ decoder_.close();+ demuxer_.close();+ info_ = SourceInfo{};+}++} // namespace veyra::sourcediff --git a/tests/integration/MediaFileSourceTests.cpp b/tests/integration/MediaFileSourceTests.cppnew file mode 100644index 00000000..f4136f54--- /dev/null+++ b/tests/integration/MediaFileSourceTests.cpp@@ -0,0 +1,112 @@+// MediaFileSource integration tests - driven by the deterministic corpus+// (loop/local/fixed_clips/corpus/translation_1080p60.mp4, 600 frames, 60fps).+// Verifies the contract translation layer: open metadata, monotonic PTS in+// the real stream time base, honest color defaults, atomic seek protocol,+// and EOS drain. Requires the corpus (generated by veyra_clip_gen).+#include <cstdio>+#include <string>++#include "veyra/source/MediaFileSource.h"++using namespace veyra;+using namespace veyra::source;++namespace {++int g_checks = 0;+int g_failures = 0;++void check(const char* name, bool ok) {+ ++g_checks;+ if (!ok) { ++g_failures; std::printf(" [FAIL] %s\n", name); }+ else { std::printf(" [PASS] %s\n", name); }+}++} // namespace++int main(int argc, char** argv) {+ std::wstring clip = L"loop/local/fixed_clips/corpus/translation_1080p60.mp4";+ if (argc > 1) {+ clip.assign(argv[1], argv[1] + std::strlen(argv[1]));+ }++ std::printf("source-file: open + metadata\n");+ MediaFileSource src;+ SourceOpenDesc desc;+ desc.path = clip;+ desc.preferHardwareDecode = false; // contract test: software decode, no GPU needed+ if (!src.open(desc)) {+ std::printf("source-file: open FAILED (corpus missing? run veyra_clip_gen --make-corpus)\n");+ return 1;+ }+ const SourceInfo& info = src.info();+ check("open:extent", info.width == 1920 && info.height == 1080);+ check("open:kind", info.kind == pipeline::SourceKind::File);+ check("open:duration", info.duration.known && info.duration.toDouble() > 9.0 && info.duration.toDouble() < 11.0);+ check("open:fps-nominal-60", info.averageFps > 59.0 && info.averageFps < 61.0);+ // 1080p SDR H.264 with no color metadata: BT.709 limited assumed (Playbook 9).+ check("open:color-matrix-709-assumed",+ info.color.matrix == pipeline::YuvMatrix::BT709 && info.color.matrixAssumed);+ check("open:color-range-limited-assumed",+ info.color.range == pipeline::ColorRange::Limited && info.color.rangeAssumed);+ check("open:not-hdr", !info.color.isHdrPath());++ std::printf("source-file: read 90 frames (PTS monotonic, flags)\n");+ pipeline::FramePacket p;+ const AVFrame* frame = nullptr;+ bool first = true;+ double lastPts = -1.0;+ int monotonicViolations = 0;+ int frames = 0;+ for (int i = 0; i < 90; ++i) {+ const SourceReadStatus st = src.read(p, &frame);+ if (st != SourceReadStatus::Frame) { break; }+ ++frames;+ if (first) {+ check("read:first-open-flag", (p.flags & static_cast<uint32_t>(pipeline::FrameFlagBits::Open)) != 0);+ check("read:first-frame-nonnull", frame != nullptr);+ first = false;+ }+ if (p.pts.known && p.pts.toDouble() <= lastPts) { ++monotonicViolations; }+ if (p.pts.known) { lastPts = p.pts.toDouble(); }+ if (!p.duration.known) { break; }+ }+ check("read:90-frames", frames == 90);+ check("read:pts-monotonic", monotonicViolations == 0);+ check("read:duration-known", p.duration.known && p.duration.toDouble() > 0.0);+ check("read:sequence-monotonic", p.sequence == 90);++ std::printf("source-file: atomic seek to 5s\n");+ const uint64_t epochBefore = src.epoch();+ check("seek:accepted", src.seek(pipeline::Rational{5, 1}));+ const SourceReadStatus st = src.read(p, &frame);+ check("seek:frame-after", st == SourceReadStatus::Frame);+ check("seek:flag-set", (p.flags & static_cast<uint32_t>(pipeline::FrameFlagBits::Seek)) != 0);+ check("seek:epoch-advanced", src.epoch() == epochBefore + 1 && p.sourceEpoch == epochBefore + 1);+ check("seek:pts-at-or-after-target", p.pts.known && p.pts.toDouble() >= 4.9 && p.pts.toDouble() < 6.0);+ SourceReadStatus st2 = src.read(p, &frame);+ check("seek:next-frame-no-flag", st2 == SourceReadStatus::Frame+ && (p.flags & static_cast<uint32_t>(pipeline::FrameFlagBits::Seek)) == 0);++ std::printf("source-file: drain to EOS\n");+ int drained = 0;+ for (;;) {+ const SourceReadStatus st3 = src.read(p, &frame);+ if (st3 == SourceReadStatus::Eos) { break; }+ if (st3 == SourceReadStatus::Error) { break; }+ ++drained;+ if (drained > 1000) { break; } // safety+ }+ check("eos:reached", drained < 1000);+ // 90 initial + 2 post-seek + drained remainder; seek to 5s of a 10s clip+ // leaves roughly half the frames to drain.+ const uint64_t expectedTotal = 90 + 2 + static_cast<uint64_t>(drained);+ check("eos:total-accounted", src.framesRead() == expectedTotal);+ check("eos:drained-roughly-half", drained >= 200 && drained <= 500);++ src.close();+ check("close:info-cleared", !src.info().opened);++ std::printf("source-file: %d checks, %d failures\n", g_checks, g_failures);+ return g_failures == 0 ? 0 : 1;+}