From 1fcfed22dd19a0ef36ccea0304fa29c734047fcc Mon Sep 17 00:00:00 2001 From: mrgh97 <44031031+mrgh97@users.noreply.github.com> Date: Tue, 10 Nov 2026 19:14:08 +0800 Subject: [PATCH 1/5] fix: validate every Dora image in the USB stream sink --- .github/workflows/build-ubuntu20.yml | 4 +- Cargo.lock | 2 +- Cargo.toml | 2 +- README.md | 223 ++++++++------------------- README_zh.md | 194 +++++++++++++++++++++++ src/bin/usb_camera_test_sink.rs | 69 +++++++-- src/main.rs | 14 +- 7 files changed, 330 insertions(+), 178 deletions(-) create mode 100644 README_zh.md diff --git a/.github/workflows/build-ubuntu20.yml b/.github/workflows/build-ubuntu20.yml index 2c8f778..30dd3e8 100644 --- a/.github/workflows/build-ubuntu20.yml +++ b/.github/workflows/build-ubuntu20.yml @@ -6,11 +6,11 @@ on: ref: description: Git ref to build required: true - default: v2.1.1 + default: v2.1.2 version: description: USB camera version without the v prefix required: true - default: 2.1.1 + default: 2.1.2 upload_to_release: description: Attach verified archives to an existing draft release required: false diff --git a/Cargo.lock b/Cargo.lock index 917a302..2b75054 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1363,7 +1363,7 @@ checksum = "77ce24cb58228fbb8aa041425bb1050850ac19177686ea6e0f41a70416f56fdb" [[package]] name = "forge-devices-usb-camera" -version = "2.1.1" +version = "2.1.2" dependencies = [ "arrow-array", "bytes", diff --git a/Cargo.toml b/Cargo.toml index d71b8cb..c137bca 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "forge-devices-usb-camera" -version = "2.1.1" +version = "2.1.2" edition = "2024" rust-version = "1.97.1" description = "Linux USB/UVC camera capture and Dora streaming node built with Rust and V4L2." diff --git a/README.md b/README.md index b762df7..a918270 100644 --- a/README.md +++ b/README.md @@ -1,181 +1,88 @@ -# USB Camera +[English](README.md) | [中文](README_zh.md) -纯 Rust 的 Linux USB/UVC 彩色相机接入,保留独立的配置模型、采集 backend、CLI 和 Dora 节点。支持 V4L2 `/dev/video*`,不引入 Python。不同设备、固件和驱动组合仍需分别验证。 +# USB camera -## 支持范围 +Linux V4L2/UVC camera capture with raw RGB, JPEG and PNG Dora outputs. -- 传感器类型:通用 RGB USB/UVC 相机。 -- 连接方式:Linux V4L2 视频设备。 -- 构建:`cargo build --bins` 或 `cargo build --release --bins`。 -- 官方工具建议:使用发行版提供的 `v4l2-ctl --list-devices` 和 `v4l2-ctl --list-formats-ext -d /dev/videoN` 验证。 +## Migration status -## 二进制打包 +Target node version: **2.1.2**. These changes are candidates pending the platform, +hardware and sustained-stream acceptance gates below. A version declaration does not +mean a stable release has been accepted. -`.github/workflows/build-ubuntu20.yml` 在各自的原生 GitHub runner 上构建 x86_64 和 ARM64/aarch64,并统一使用 Ubuntu 20.04 容器保持 glibc 2.31 baseline。每次运行生成 `usb_camera-v-ubuntu20.04-x86_64.tar.gz` 和 `usb_camera-v-ubuntu20.04-arm64.tar.gz`,以及各自的 SHA-256 文件;完整发布步骤见 `RELEASING.md`。 +usb_camera_test_sink validates every frame, fails on malformed or insufficient input, and supports min_frames and delay_ms for slow-consumer tests. -## 安装与权限 +## Runtime and platform -安装 Rust 1.97.1 或更高版本的 toolchain、Linux V4L2 开发依赖和 `v4l-utils`。 -Ubuntu/Debian 可执行: +- First validation combination: Dora CLI/coordinator/daemon/node APIs 1.0.1, + Forge Msgs 2.0.0 and Common 2.1.0; use only the families required by this node. +- Forge wire schemas remain `forge_msgs.v1`. Dora 0.x and 1.x cannot share a runtime. +- Use Python 3.12 for Python builds. Camera-only Python packages may also declare + Python 3.11 support; test that interpreter separately before claiming it. +- Rust packages enable `arrow-v59`; the committed lock uses Arrow 59.3.0. +- Hardware camera/robot artifacts target Linux. macOS development tests do not + qualify Linux binaries. GPU/rendering and vendor SDK prerequisites still apply. +- Keep a recoverable `stable/1.x` runtime and artifact combination. -```bash -sudo apt install build-essential clang libclang-dev libv4l-dev v4l-utils -``` - -其他发行版的软件包名需由部署环境确认。 - -先执行不会打开设备的环境检查: - -```bash -cargo run --bin usb_camera -- check-environment -cargo run --bin usb_camera -- check-environment --json -``` - -该命令只读取 OS、`/dev/video*` 目录项和权限元数据,不调用设备 `open`/V4L2 ioctl。当前用户不属于 `video` 组时: - -```bash -sudo scripts/install_permissions.sh -``` - -重新登录后再次自检。脚本只把调用用户加入 `video` 组,不写入或覆盖系统 udev -规则,也不会安装厂商 SDK。 - -## 配置 - -唯一交付示例为 `config/sensor.example.yaml`: - -```bash -cargo run --bin usb_camera -- run --config config/sensor.example.yaml -``` - -也可设置 `USB_CAMERA_NODE_CONFIG`。字段如下: - -- `device`:设备路径或数字索引;示例 `/dev/video0`。 -- `output_id`:Dora output id,必须与 dataflow `outputs` 对齐。 -- `image_format`:`raw`、`jpeg`、`png`。 -- `image_jpeg_quality`:JPEG 质量 `1..=100`。 -- `width`/`height`:期望尺寸;驱动可能协商为其他实际值。 -- `fps`:期望设备帧率,必须至少为 1;Dora 输出节奏仍由 `tick` 决定。 - -配置修改后需要重启节点/采集会话;当前不支持运行中动态调参。 - -## 发现与单帧采集 - -设备发现会查询 V4L2 能力: - -```bash -cargo run --bin usb_camera -- list-devices -cargo run --bin usb_camera -- list-devices --json -``` +## Setup and commands -发现逻辑会排除 metadata 以及声明 GREY/Y10/Y16/Z16 等格式的深度、红外节点; -对于暴露多个 `/dev/video*` 的深度相机,仅返回可作为 RGB 彩色输入的节点。 +Run from the repository root: -采集 JPEG 单帧: - -```bash -cargo run --bin usb_camera -- snapshot \ - --config config/sensor.example.yaml \ - --output sample_output/snapshot.jpg -``` - -对应说明见 `examples/device_discovery/` 与 `examples/capture_sample/`。snapshot 会丢弃预热帧、跳过疑似黑帧并对间歇错误做有限重试,因此会实际打开硬件。 - -## Dora example - -`examples/dora_sensor_stream/` 提供完整 `sensor -> sink` 链路。先构建二进制,再进入该目录运行: - -```bash -cargo build --bins -cd examples/dora_sensor_stream -dora run dataflow.yaml +```sh +cargo build --locked +usb_camera --config config/sensor.example.yaml ``` -该示例的 `dataflow.yaml` 固定引用 `target/debug/`,因此必须使用不带 `--release` -的构建命令。若部署 release 产物,需将两个节点路径改为 `target/release/`。 - -sink 是 Rust 可执行节点,能解码 `forge_msgs.Image` 和 `forge_msgs.CompressedImage`,打印帧计数、编码、尺寸、数据字节数及 sink 接收时的 Unix 毫秒时间。 - -## 消息与时间戳语义 - -- `image_format: raw`:输出 `forge_msgs.Image`,当前编码为 `rgb8`,布局为 HWC、行连续。 -- `image_format: jpeg`:输出 `forge_msgs.CompressedImage(format="jpeg")`;有效 MJPEG 可校验后直通。 -- `image_format: png`:输出 `forge_msgs.CompressedImage(format="png")`;使用吞吐优先的快速、无滤波编码,文件可能接近 raw 大小。 -- JPEG 优先向设备请求 MJPG;raw/PNG 优先请求 YUYV,实际格式仍以驱动协商结果为准。 -- YUYV 转换使用驱动协商出的行步长、量化范围和色彩空间;启动日志会记录最终协商结果。 -- 消息本体没有独立采集时间戳字段;节点会尽力附加用户 metadata - `capture_timestamp_ns`。它是 V4L2 后端取得物理帧时记录的 Unix epoch 纳秒时间, - 是采集时刻的最佳估计;缓存帧重复返回时不会重新生成,也不替代 Dora 管理的消息时间戳。 -- 节点继续传递触发该帧的 Dora `tick` user metadata parameters,但相机产生的 - `capture_timestamp_ns` 是同名字段的权威值;没有有效帧时间时不会继承 tick 中的同名值。 -- test sink 的 `received_at_unix_ms` 是 sink 进程收到并处理消息时的系统墙钟时间,也不是硬件采集时间。 - -## 可选发布可观测性 +Use `usb_camera --help` (or `uv run --frozen usb_camera --help`) for supported CLI options. +The example configuration is `config/sensor.example.yaml`; choose the actual device and supported +stream profiles before starting. This command requires an appropriate Dora dataflow. -仅当节点启动时环境变量 **`FORGE_OBSERVABILITY=1`** 才启用;未设置、`0`、`true` -或其他值均关闭。默认保持原有发送和 metadata 行为,不采样可观测性时钟。 +## Message contract -启用时,每次 image payload 完整构建后、调用 Dora `send_output` 前,节点通过 -`forge_common::observability` 准备 `NewOrigin`,发送一次,再用同一发送结果完成观测。 -发送失败仍只告警、不重试、不计为成功。相机不继承 tick 的观测上下文:先移除 tick 的 -`forge_obs_version`、`forge_publish_time_ns`、`forge_origin_time_ns`、`forge_origin_id` -(包括未知版本),然后写入整数版本 `1` 和同次采样的 Unix 纳秒 publish/origin 时间。 -当前不生成 origin ID;时钟不可用时清除这些字段但仍发送图像。 +The configured output_id carries Forge Image or CompressedImage. Capture timestamps are preserved as user metadata. -`capture_timestamp_ns` 和其他业务 metadata 保留原有语义。采集时间不是发布 origin; -即使重复发送缓存帧,也会生成新的发布时间而保留该帧的采集时间。Dora 自带时间戳和 -Arrow 图像 payload/schema 均不变。当前只附加发布 metadata,不启用本地指标导出或后台线程; -示例 sink 仍只解码图像,不验证观测 metadata。 +Keep bounded queues for high-rate image consumers and document whether old images +are dropped or producers experience backpressure. Preserve image dimensions, dtype, +encoding, units and capture metadata across the node boundary. -USB Camera 2.1.0 的观测 API 使用已发布到 crates.io 的 `forgelab_common`,最低版本为 `2.1.0` -(代码中别名为 `forge_common`),无需本地源码或依赖补丁。运行时关闭观测也使用同一依赖。 -在本仓库目录使用提交的 `Cargo.lock` 构建和检查: +## Tests and build -```bash +```sh cargo test --locked -cargo clippy --all-targets --locked -- -D warnings -cargo build --locked --bins +cargo clippy --locked --all-targets --all-features -- -D warnings +cargo build --release --locked ``` -构建后,在 `examples/dora_sensor_stream/` 中执行以下命令会**实际打开相机**: +Use the committed `Cargo.lock` and frozen/locked installs. Python vendor SDK tests require +the supported SDK platform. For Linux headless MuJoCo rendering, install the required +EGL or OSMesa libraries and select the appropriate `MUJOCO_GL` backend. -```bash -FORGE_OBSERVABILITY=1 dora run dataflow.yaml -``` - -确保运行器将此环境变量传给 sensor 进程;也可在 dataflow 的 sensor 节点上设置 -`env: { FORGE_OBSERVABILITY: "1" }`。不设置该变量即可保持默认行为。 - -## 验证与交付文档 - - -- 样本策略:`sample_output/README.md` -- 资产策略:`assets/README.md` -- 无硬件测试:`cargo test` +Validate every delivered example or rendered template with: -## 常见问题与限制 - -- 仅实现 Linux V4L2 backend;其他系统的环境检查会报告不支持。 -- `Permission denied`:确认设备节点 group/mode、用户属于 `video` 组且已重新登录。 -- `Device or resource busy`:关闭浏览器、VLC 或其他相机进程。 -- 找不到设备:检查 USB、内核日志和 `/dev/video*`;再用官方工具确认。 -- 分辨率/帧率不符:配置是期望值,最终由设备驱动协商;以启动日志记录的实际结果为准。 -- 底部偶发闪烁色块:常见原因是 UVC/USB 等时传输丢包。backend 会丢弃驱动标记为损坏的帧,并输出 `dropping corrupted frame` 告警;若告警持续出现,请检查 USB 线材、Hub、接口带宽,并尝试降低分辨率或帧率。 -- 掉帧诊断:`sequence gap` 表示驱动帧序号跳变,`frame timeout` 表示连续 2 秒未取得帧,`long frame interval` 表示采集发生异常停顿。告警包含累计次数并已限频;单槽 latest-frame 队列为降低延迟而覆盖旧帧属于预期行为,不作为硬件掉帧告警。 -- MJPEG 必须包含起始 SOI 和 EOI;EOI 后的 UVC/驱动尾数据会被裁掉。真正缺少 EOI 的帧会在进入缓存前丢弃,避免把明显截断的帧显示成底部色块。节点不会自动补 EOI,因为缺失的图像数据无法通过补结束标记恢复。 -- `buffer near capacity` 仅用于可变长度 MJPEG,表示 `bytesused` 接近驱动协商的 `sizeimage`/mmap 容量;若同时缺少 EOI,说明不完整帧恰好顶满单帧 buffer,但仍应结合驱动和 USB 日志判断根因。 -- 启动日志记录请求/实际帧率和 `sizeimage`,首个有效 buffer 记录 mmap 容量;运行期间每 10 秒的 `camera_health` 汇总包含 accepted、invalid、last-good age、尾数据类型、最大 buffer 占用率及各类异常累计值。实际帧率偏差超过 5% 会告警,过高帧率可能增加 USB/CPU 压力。 -- 同一设备通常不能被多个进程同时采集。 -- 当前真机 640×480 下,完整 Dora sink 链路中 JPEG、raw 和快速 PNG 均约 - 30 FPS;快速 PNG 单帧约 922 KB,实时传输通常仍应优先使用 JPEG。 -- raw/jpeg/png、60 秒连续运行及异常退出重开已验证;拔插恢复、数分钟以上稳定性和 - 丢帧统计仍待人工验收。 - -## 贡献与权限 - -- 开发环境、检查命令和硬件变更要求见 `CONTRIBUTING.md`。 -- 加入 `video` 组会授予当前用户访问摄像头等视频设备的能力;只应向受信任用户授予该权限。 - -## 许可证 +```sh +dora validate path/to/dataflow.yaml +``` -本项目基于 Apache License 2.0 开源,完整条款见 `LICENSE`。 +Schema validation is followed by a real start, message exchange and stop test. +Keep the existing detailed configuration and device setup reference in +[the Chinese guide](README_zh.md) and the repository's `config/`, `examples/` and +`scripts/` directories where present. + +## Acceptance and release + +1. Build candidate archives from the selected commit/tag and record actual embedded + dependency versions, platform, archive SHA256 and unpacked executable SHA256. +2. Install the final archive into a clean supported environment. Verify the CLI, + message contract, resource cleanup and error exits. +3. For image producers, run real supported RGB/depth configurations for at least + four continuous hours after warmup. Exercise slow/multiple consumers, stalled + consumption, failures and repeated start/stop. Define throughput, latency and + memory limits before testing, and retain time series rather than frame payloads. +4. Exercise the relevant device; synthetic streams do not qualify hardware capture. + Demonstrate rollback to the complete old node/runtime combination. +5. Publish the exact accepted archive. Rebuilding invalidates that artifact's + acceptance; repeat it before publication. Never overwrite published tags/assets. + +## License + +Apache-2.0. See `LICENSE` and any bundled third-party notices. diff --git a/README_zh.md b/README_zh.md new file mode 100644 index 0000000..b13351c --- /dev/null +++ b/README_zh.md @@ -0,0 +1,194 @@ +[English](README.md) | 中文 + +# USB Camera + +纯 Rust 的 Linux USB/UVC 彩色相机接入,保留独立的配置模型、采集 backend、CLI 和 Dora 节点。支持 V4L2 `/dev/video*`,不引入 Python。不同设备、固件和驱动组合仍需分别验证。 + +## 支持范围 + +- 传感器类型:通用 RGB USB/UVC 相机。 +- 连接方式:Linux V4L2 视频设备。 +- 构建:`cargo build --bins` 或 `cargo build --release --bins`。 +- 官方工具建议:使用发行版提供的 `v4l2-ctl --list-devices` 和 `v4l2-ctl --list-formats-ext -d /dev/videoN` 验证。 + +## 二进制打包 + +`.github/workflows/build-ubuntu20.yml` 在各自的原生 GitHub runner 上构建 x86_64 和 ARM64/aarch64,并统一使用 Ubuntu 20.04 容器保持 glibc 2.31 baseline。每次运行生成 `usb_camera-v-ubuntu20.04-x86_64.tar.gz` 和 `usb_camera-v-ubuntu20.04-arm64.tar.gz`,以及各自的 SHA-256 文件;完整发布步骤见 `RELEASING.md`。 + +## 安装与权限 + +安装 Rust 1.97.1 或更高版本的 toolchain、Linux V4L2 开发依赖和 `v4l-utils`。 +Ubuntu/Debian 可执行: + +```bash +sudo apt install build-essential clang libclang-dev libv4l-dev v4l-utils +``` + +其他发行版的软件包名需由部署环境确认。 + +先执行不会打开设备的环境检查: + +```bash +cargo run --bin usb_camera -- check-environment +cargo run --bin usb_camera -- check-environment --json +``` + +该命令只读取 OS、`/dev/video*` 目录项和权限元数据,不调用设备 `open`/V4L2 ioctl。当前用户不属于 `video` 组时: + +```bash +sudo scripts/install_permissions.sh +``` + +重新登录后再次自检。脚本只把调用用户加入 `video` 组,不写入或覆盖系统 udev +规则,也不会安装厂商 SDK。 + +## 配置 + +唯一交付示例为 `config/sensor.example.yaml`: + +```bash +cargo run --bin usb_camera -- run --config config/sensor.example.yaml +``` + +也可设置 `USB_CAMERA_NODE_CONFIG`。字段如下: + +- `device`:设备路径或数字索引;示例 `/dev/video0`。 +- `output_id`:Dora output id,必须与 dataflow `outputs` 对齐。 +- `image_format`:`raw`、`jpeg`、`png`。 +- `image_jpeg_quality`:JPEG 质量 `1..=100`。 +- `width`/`height`:期望尺寸;驱动可能协商为其他实际值。 +- `fps`:期望设备帧率,必须至少为 1;Dora 输出节奏仍由 `tick` 决定。 + +配置修改后需要重启节点/采集会话;当前不支持运行中动态调参。 + +## 发现与单帧采集 + +设备发现会查询 V4L2 能力: + +```bash +cargo run --bin usb_camera -- list-devices +cargo run --bin usb_camera -- list-devices --json +``` + +发现逻辑会排除 metadata 以及声明 GREY/Y10/Y16/Z16 等格式的深度、红外节点; +对于暴露多个 `/dev/video*` 的深度相机,仅返回可作为 RGB 彩色输入的节点。 + +采集 JPEG 单帧: + +```bash +cargo run --bin usb_camera -- snapshot \ + --config config/sensor.example.yaml \ + --output sample_output/snapshot.jpg +``` + +对应说明见 `examples/device_discovery/` 与 `examples/capture_sample/`。snapshot 会丢弃预热帧、跳过疑似黑帧并对间歇错误做有限重试,因此会实际打开硬件。 + +## Dora example + +`examples/dora_sensor_stream/` 提供完整 `sensor -> sink` 链路。先构建二进制,再进入该目录运行: + +```bash +cargo build --bins +cd examples/dora_sensor_stream +dora run dataflow.yaml +``` + +该示例的 `dataflow.yaml` 固定引用 `target/debug/`,因此必须使用不带 `--release` +的构建命令。若部署 release 产物,需将两个节点路径改为 `target/release/`。 + +sink 是 Rust 可执行节点,能解码 `forge_msgs.Image` 和 `forge_msgs.CompressedImage`,打印帧计数、编码、尺寸、数据字节数及 sink 接收时的 Unix 毫秒时间。 + +## 消息与时间戳语义 + +- `image_format: raw`:输出 `forge_msgs.Image`,当前编码为 `rgb8`,布局为 HWC、行连续。 +- `image_format: jpeg`:输出 `forge_msgs.CompressedImage(format="jpeg")`;有效 MJPEG 可校验后直通。 +- `image_format: png`:输出 `forge_msgs.CompressedImage(format="png")`;使用吞吐优先的快速、无滤波编码,文件可能接近 raw 大小。 +- JPEG 优先向设备请求 MJPG;raw/PNG 优先请求 YUYV,实际格式仍以驱动协商结果为准。 +- YUYV 转换使用驱动协商出的行步长、量化范围和色彩空间;启动日志会记录最终协商结果。 +- 消息本体没有独立采集时间戳字段;节点会尽力附加用户 metadata + `capture_timestamp_ns`。它是 V4L2 后端取得物理帧时记录的 Unix epoch 纳秒时间, + 是采集时刻的最佳估计;缓存帧重复返回时不会重新生成,也不替代 Dora 管理的消息时间戳。 +- 节点继续传递触发该帧的 Dora `tick` user metadata parameters,但相机产生的 + `capture_timestamp_ns` 是同名字段的权威值;没有有效帧时间时不会继承 tick 中的同名值。 +- test sink 的 `received_at_unix_ms` 是 sink 进程收到并处理消息时的系统墙钟时间,也不是硬件采集时间。 + +## 可选发布可观测性 + +仅当节点启动时环境变量 **`FORGE_OBSERVABILITY=1`** 才启用;未设置、`0`、`true` +或其他值均关闭。默认保持原有发送和 metadata 行为,不采样可观测性时钟。 + +启用时,每次 image payload 完整构建后、调用 Dora `send_output` 前,节点通过 +`forge_common::observability` 准备 `NewOrigin`,发送一次,再用同一发送结果完成观测。 +发送失败仍只告警、不重试、不计为成功。相机不继承 tick 的观测上下文:先移除 tick 的 +`forge_obs_version`、`forge_publish_time_ns`、`forge_origin_time_ns`、`forge_origin_id` +(包括未知版本),然后写入整数版本 `1` 和同次采样的 Unix 纳秒 publish/origin 时间。 +当前不生成 origin ID;时钟不可用时清除这些字段但仍发送图像。 + +`capture_timestamp_ns` 和其他业务 metadata 保留原有语义。采集时间不是发布 origin; +即使重复发送缓存帧,也会生成新的发布时间而保留该帧的采集时间。Dora 自带时间戳和 +Arrow 图像 payload/schema 均不变。当前只附加发布 metadata,不启用本地指标导出或后台线程; +示例 sink 仍只解码图像,不验证观测 metadata。 + +USB Camera 2.1.0 的观测 API 使用已发布到 crates.io 的 `forgelab_common`,最低版本为 `2.1.0` +(代码中别名为 `forge_common`),无需本地源码或依赖补丁。运行时关闭观测也使用同一依赖。 +在本仓库目录使用提交的 `Cargo.lock` 构建和检查: + +```bash +cargo test --locked +cargo clippy --all-targets --locked -- -D warnings +cargo build --locked --bins +``` + +构建后,在 `examples/dora_sensor_stream/` 中执行以下命令会**实际打开相机**: + +```bash +FORGE_OBSERVABILITY=1 dora run dataflow.yaml +``` + +确保运行器将此环境变量传给 sensor 进程;也可在 dataflow 的 sensor 节点上设置 +`env: { FORGE_OBSERVABILITY: "1" }`。不设置该变量即可保持默认行为。 + +## 验证与交付文档 + + +- 样本策略:`sample_output/README.md` +- 资产策略:`assets/README.md` +- 无硬件测试:`cargo test` + +## 常见问题与限制 + +- 仅实现 Linux V4L2 backend;其他系统的环境检查会报告不支持。 +- `Permission denied`:确认设备节点 group/mode、用户属于 `video` 组且已重新登录。 +- `Device or resource busy`:关闭浏览器、VLC 或其他相机进程。 +- 找不到设备:检查 USB、内核日志和 `/dev/video*`;再用官方工具确认。 +- 分辨率/帧率不符:配置是期望值,最终由设备驱动协商;以启动日志记录的实际结果为准。 +- 底部偶发闪烁色块:常见原因是 UVC/USB 等时传输丢包。backend 会丢弃驱动标记为损坏的帧,并输出 `dropping corrupted frame` 告警;若告警持续出现,请检查 USB 线材、Hub、接口带宽,并尝试降低分辨率或帧率。 +- 掉帧诊断:`sequence gap` 表示驱动帧序号跳变,`frame timeout` 表示连续 2 秒未取得帧,`long frame interval` 表示采集发生异常停顿。告警包含累计次数并已限频;单槽 latest-frame 队列为降低延迟而覆盖旧帧属于预期行为,不作为硬件掉帧告警。 +- MJPEG 必须包含起始 SOI 和 EOI;EOI 后的 UVC/驱动尾数据会被裁掉。真正缺少 EOI 的帧会在进入缓存前丢弃,避免把明显截断的帧显示成底部色块。节点不会自动补 EOI,因为缺失的图像数据无法通过补结束标记恢复。 +- `buffer near capacity` 仅用于可变长度 MJPEG,表示 `bytesused` 接近驱动协商的 `sizeimage`/mmap 容量;若同时缺少 EOI,说明不完整帧恰好顶满单帧 buffer,但仍应结合驱动和 USB 日志判断根因。 +- 启动日志记录请求/实际帧率和 `sizeimage`,首个有效 buffer 记录 mmap 容量;运行期间每 10 秒的 `camera_health` 汇总包含 accepted、invalid、last-good age、尾数据类型、最大 buffer 占用率及各类异常累计值。实际帧率偏差超过 5% 会告警,过高帧率可能增加 USB/CPU 压力。 +- 同一设备通常不能被多个进程同时采集。 +- 当前真机 640×480 下,完整 Dora sink 链路中 JPEG、raw 和快速 PNG 均约 + 30 FPS;快速 PNG 单帧约 922 KB,实时传输通常仍应优先使用 JPEG。 +- raw/jpeg/png、60 秒连续运行及异常退出重开已验证;拔插恢复、数分钟以上稳定性和 + 丢帧统计仍待人工验收。 + +## 贡献与权限 + +- 开发环境、检查命令和硬件变更要求见 `CONTRIBUTING.md`。 +- 加入 `video` 组会授予当前用户访问摄像头等视频设备的能力;只应向受信任用户授予该权限。 + +## 许可证 + +本项目基于 Apache License 2.0 开源,完整条款见 `LICENSE`。 + + +## Forge 2 / Dora 1 迁移 + +目标版本:`2.1.2`,当前为待验收改动。首轮验证组合使用 Dora 1.0.1、Forge Msgs 2.0.0、Common 2.1.0;依赖与构建工具以提交的锁文件为准。原有消息规范继续使用 `forge_msgs.v1`。 + +本轮要求:检查所有示例最终 YAML,使用 `dora validate ` 验证,并实际执行消息往返。相机取流、资源释放和异常退出须分别验收;高吞吐图像链预热后连续测试至少 4 小时,覆盖慢消费者、扇出、退出与重启,记录实际内存占用。无硬件单测不能替代设备验收。 + +最终发布归档须先在声明支持的平台完成验收,记录源码与归档、可执行文件校验值;通过后发布同一份包,重建后重新验收。Linux 发布包仍需 Linux 验证,其他平台的开发测试不代表其已通过。 + +`usb_camera_test_sink` 对每帧校验,支持 `min_frames` 和 `delay_ms`,用于严格接收与慢消费者测试。 diff --git a/src/bin/usb_camera_test_sink.rs b/src/bin/usb_camera_test_sink.rs index 0b6d1e3..8c3692b 100644 --- a/src/bin/usb_camera_test_sink.rs +++ b/src/bin/usb_camera_test_sink.rs @@ -1,5 +1,5 @@ use std::path::PathBuf; -use std::time::{SystemTime, UNIX_EPOCH}; +use std::time::{Duration, SystemTime, UNIX_EPOCH}; use arrow_array::{RecordBatch, StructArray}; use clap::Parser; @@ -9,7 +9,7 @@ use forge_msgs::{CompressedImage, Image}; use serde::Deserialize; #[derive(Debug, Parser)] -#[command(about = "Decode and report USB camera Dora messages")] +#[command(version, about = "Decode and validate every USB camera Dora message")] struct Cli { #[arg(long)] config: PathBuf, @@ -21,6 +21,10 @@ struct SinkConfig { input_id: String, #[serde(default = "default_log_every")] log_every: u64, + #[serde(default = "default_min_frames")] + min_frames: u64, + #[serde(default)] + delay_ms: u64, } fn default_input_id() -> String { @@ -31,6 +35,17 @@ fn default_log_every() -> u64 { 30 } +fn default_min_frames() -> u64 { + 1 +} + +fn require_frames(count: u64, minimum: u64) -> Result<()> { + if count < minimum { + eyre::bail!("received {count} valid images; required at least {minimum}"); + } + Ok(()) +} + fn receive_time_ms() -> u128 { SystemTime::now() .duration_since(UNIX_EPOCH) @@ -87,18 +102,15 @@ fn main() -> Result<()> { while let Some(event) = events.recv() { match event { Event::Input { id, data, .. } if id.as_str() == config.input_id.as_str() => { + let description = decode_and_describe(&data) + .wrap_err_with(|| format!("invalid image on {}", config.input_id))?; count += 1; - if !should_log(count, config.log_every) { - continue; + if should_log(count, config.log_every) { + let received_at_ms = receive_time_ms(); + println!("count={count} received_at_unix_ms={received_at_ms} {description}"); } - let received_at_ms = receive_time_ms(); - match decode_and_describe(&data) { - Ok(description) => { - println!("count={count} received_at_unix_ms={received_at_ms} {description}") - } - Err(err) => eprintln!( - "count={count} received_at_unix_ms={received_at_ms} decode_error={err}" - ), + if config.delay_ms > 0 { + std::thread::sleep(Duration::from_millis(config.delay_ms)); } } Event::Stop(_) => break, @@ -106,5 +118,36 @@ fn main() -> Result<()> { _ => {} } } - Ok(()) + require_frames(count, config.min_frames) +} + +#[cfg(test)] +mod tests { + use super::*; + use bytes::Bytes; + use dora_node_api::IntoArrow; + + #[test] + fn no_frames_is_not_a_successful_stream_test() { + assert!(require_frames(0, 1).is_err()); + assert!(require_frames(1, 1).is_ok()); + } + + #[test] + fn raw_and_depth_images_are_validated() { + for (encoding, step, bytes) in [ + ("rgb8", 3, vec![1, 2, 3]), + ("32FC1", 4, 1.25_f32.to_le_bytes().to_vec()), + ] { + let image = Image::new(1, 1, encoding, step, Bytes::from(bytes)).unwrap(); + let array: StructArray = image.to_record_batch().unwrap().into(); + assert!(decode_and_describe(&array.into_arrow()).is_ok()); + } + } + + #[test] + fn malformed_input_is_rejected() { + let array = arrow_array::UInt8Array::from(vec![1_u8, 2, 3]); + assert!(decode_and_describe(&array.into_arrow()).is_err()); + } } diff --git a/src/main.rs b/src/main.rs index e9725cf..47adb90 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,7 +1,9 @@ +#[cfg_attr(not(target_os = "linux"), allow(dead_code))] mod backend; #[cfg(target_os = "linux")] mod backend_v4l; mod config; +#[cfg_attr(not(target_os = "linux"), allow(dead_code))] mod list_devices; mod observability; @@ -9,6 +11,7 @@ use std::fs; use std::io::Write; #[cfg(target_os = "linux")] use std::os::unix::fs::MetadataExt; +#[cfg(target_os = "linux")] use std::path::PathBuf; use std::time::Duration; @@ -188,6 +191,7 @@ struct VideoDevicePermission { fn inspect_environment() -> EnvironmentCheck { let supported = cfg!(target_os = "linux"); let mut notes = Vec::new(); + #[cfg_attr(not(target_os = "linux"), allow(unused_mut))] let mut video_devices = Vec::new(); if !supported { @@ -394,7 +398,9 @@ fn load_snapshot_config(config_path: Option<&str>, device: Option<&str>) -> Resu Ok(config) } (None, Some(device)) => CameraConfig::for_snapshot(device.to_string()), - (None, None) => eyre::bail!("snapshot requires --config or --device "), + (None, None) => Err(eyre::eyre!( + "snapshot requires --config or --device " + )), } } @@ -453,7 +459,7 @@ fn run_snapshot(config_path: Option<&str>, device: Option<&str>, output_path: &s } } } - eyre::bail!("snapshot: 重试用尽") + Err(eyre::eyre!("snapshot: 重试用尽")) } fn main() -> Result<()> { @@ -599,7 +605,9 @@ fn normalize_mjpeg_payload(data: Bytes) -> Result { return Ok(data.slice(..payload_len)); } - eyre::bail!("MJPEG 直通校验失败:缺少有效 JPEG EOI,帧可能已被截断") + Err(eyre::eyre!( + "MJPEG 直通校验失败:缺少有效 JPEG EOI,帧可能已被截断" + )) } fn image_from_captured_frame(frame: CapturedFrame, config: &CameraConfig) -> Result { From 6af57f42a06cdb2e88b41f5ddefad313f379540e Mon Sep 17 00:00:00 2001 From: mrgh97 <44031031+mrgh97@users.noreply.github.com> Date: Tue, 10 Nov 2026 19:17:52 +0800 Subject: [PATCH 2/5] test: derive USB CLI version from package metadata --- src/main.rs | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/main.rs b/src/main.rs index 47adb90..3ac936c 100644 --- a/src/main.rs +++ b/src/main.rs @@ -859,8 +859,10 @@ mod tests { .expect_err("--version should exit after displaying the version"); assert_eq!(error.kind(), ErrorKind::DisplayVersion); - assert_eq!(error.to_string(), "usb_camera 2.1.1\n"); - assert_eq!(env!("CARGO_PKG_VERSION"), "2.1.1"); + assert_eq!( + error.to_string(), + format!("usb_camera {}\n", env!("CARGO_PKG_VERSION")) + ); } #[test] From f14adc84cd2cbb1320d2198689a86ce474190fab Mon Sep 17 00:00:00 2001 From: mrgh97 <44031031+mrgh97@users.noreply.github.com> Date: Tue, 10 Nov 2026 19:35:21 +0800 Subject: [PATCH 3/5] fix: lock compatible transport security patches --- Cargo.lock | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 2b75054..daa41ae 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -3191,9 +3191,9 @@ dependencies = [ [[package]] name = "quinn-proto" -version = "0.11.17" +version = "0.11.18" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "04759210543be93709136e28212294a659ef5001836ff4eab4d663e4529bba83" +checksum = "a9746dbde176634f4f2f1faf2404e30a31b2bc1e9cafb5329c95d8177a18c9fc" dependencies = [ "bytes", "fastbloom", @@ -3547,9 +3547,9 @@ dependencies = [ [[package]] name = "rustls" -version = "0.23.45" +version = "0.23.46" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0d41d731c7d2f962d1ccc364cec258de3c0e93b38c2fb3ba97ac74513048d634" +checksum = "48e13bd8c0e9365c43cfa5c9e8f9ad49d3c8444926c9aac819e0e4dc503c8fdf" dependencies = [ "log", "once_cell", @@ -3620,9 +3620,9 @@ checksum = "f87165f0995f63a9fbeea62b64d10b4d9d8e78ec6d7d51fb2125fda7bb36788f" [[package]] name = "rustls-webpki" -version = "0.103.15" +version = "0.103.16" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f3c3cf1d8b1e7d4927e2d154c3fcb02979afb9939629c62cd9048d4f07b60ac2" +checksum = "4443b1b6d39d7c663139942cc4558262562d2c84123bb6282ef177009ca8b281" dependencies = [ "ring", "rustls-pki-types", @@ -4968,18 +4968,18 @@ dependencies = [ [[package]] name = "webpki-root-certs" -version = "1.0.9" +version = "1.0.10" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b96554aa2acc8ccdb7e1c9a58a7a68dd5d13bccc69cd124cb09406db612a1c9b" +checksum = "58ec80e73fd8baf57bf0d9615554c75348bda990d6d5bbeab964dd068319fecb" dependencies = [ "rustls-pki-types", ] [[package]] name = "webpki-roots" -version = "1.0.9" +version = "1.0.10" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7dcd9d09a39985f5344844e66b0c530a33843579125f23e21e9f0f220850f22a" +checksum = "1c1c8e20c8a38fc7d65abfe74eb7280e4aa667e8eec8bc84996d2874810748d9" dependencies = [ "rustls-pki-types", ] From 0f497aa2a1da711a56c936ed86fd0406438cc898 Mon Sep 17 00:00:00 2001 From: mrgh97 <44031031+mrgh97@users.noreply.github.com> Date: Thu, 12 Nov 2026 10:12:18 +0800 Subject: [PATCH 4/5] fix: reject zero-frame stream acceptance --- README.md | 2 +- README_zh.md | 2 +- migration/review-20261112.json | 287 ++++++++++++++++++++++++++++++++ src/bin/usb_camera_test_sink.rs | 4 + 4 files changed, 293 insertions(+), 2 deletions(-) create mode 100644 migration/review-20261112.json diff --git a/README.md b/README.md index a918270..14a0369 100644 --- a/README.md +++ b/README.md @@ -10,7 +10,7 @@ Target node version: **2.1.2**. These changes are candidates pending the platfor hardware and sustained-stream acceptance gates below. A version declaration does not mean a stable release has been accepted. -usb_camera_test_sink validates every frame, fails on malformed or insufficient input, and supports min_frames and delay_ms for slow-consumer tests. +usb_camera_test_sink validates every frame, fails on malformed or insufficient input, and supports positive min_frames and delay_ms for slow-consumer tests. A zero minimum cannot pass an empty stream. ## Runtime and platform diff --git a/README_zh.md b/README_zh.md index b13351c..dec85bb 100644 --- a/README_zh.md +++ b/README_zh.md @@ -191,4 +191,4 @@ FORGE_OBSERVABILITY=1 dora run dataflow.yaml 最终发布归档须先在声明支持的平台完成验收,记录源码与归档、可执行文件校验值;通过后发布同一份包,重建后重新验收。Linux 发布包仍需 Linux 验证,其他平台的开发测试不代表其已通过。 -`usb_camera_test_sink` 对每帧校验,支持 `min_frames` 和 `delay_ms`,用于严格接收与慢消费者测试。 +`usb_camera_test_sink` 对每帧校验,支持正数 `min_frames` 和 `delay_ms`,用于严格接收与慢消费者测试。最小帧数不能设为零来放过空流。 diff --git a/migration/review-20261112.json b/migration/review-20261112.json new file mode 100644 index 0000000..13d5818 --- /dev/null +++ b/migration/review-20261112.json @@ -0,0 +1,287 @@ +{ + "review_date": "2026-11-12", + "merge_recommendation": "hold", + "full_acceptance_complete": false, + "gitlab_sync": "not started; acceptance pending", + "repository": "adapter-camera-usb", + "changes": [ + "Reject min_frames=0 in the Rust stream sink; keep English/Chinese guidance aligned." + ], + "software_tests": { + "cargo_test": "27 passed (20 main, 3 sink, 4 contracts)", + "clippy": "passed: all targets/all features, warnings denied", + "format": "passed" + }, + "runtime_records": [ + { + "entry": "usb-camera", + "mode": "single", + "command": [ + "${WORKSPACE}/.test-env/bin/dora", + "run", + "${WORKSPACE}/validation/review-20261112/single/usb-camera/dataflow.yaml", + "--stop-after", + "4s" + ], + "exit_code": 1, + "elapsed_seconds": 1.903, + "passed": false, + "expected_negative_confirmed": true, + "scope": "Negative platform check: native Linux V4L2 capture is unavailable on macOS; not hardware acceptance.", + "log_file": "${WORKSPACE}/validation/review-20261112/single/usb-camera/dora.log" + }, + { + "entry": "usb-sink-empty", + "mode": "single", + "command": [ + "${WORKSPACE}/.test-env/bin/dora", + "run", + "${WORKSPACE}/validation/review-20261112/single/usb-sink-empty/dataflow.yaml", + "--stop-after", + "4s" + ], + "exit_code": 1, + "elapsed_seconds": 4.043, + "passed": false, + "expected_negative_confirmed": true, + "scope": "Negative empty-stream check: min_frames=0 must fail, not an accepted image stream.", + "log_file": "${WORKSPACE}/validation/review-20261112/single/usb-sink-empty/dora.log" + }, + { + "entry": "usb-camera", + "mode": "chain", + "command": [ + "${WORKSPACE}/.test-env/bin/dora", + "run", + "${WORKSPACE}/validation/review-20261112/blocked-chain/usb-camera/dataflow.yaml", + "--stop-after", + "4s" + ], + "includes_gateway": true, + "exit_code": 1, + "elapsed_seconds": 4.242, + "passed": false, + "scope": "Blocked platform/SDK prerequisite diagnostic; not successful transport or hardware acceptance.", + "log_file": "${WORKSPACE}/validation/review-20261112/blocked-chain/usb-camera/dora.log" + }, + { + "command": [ + "${WORKSPACE}/.test-env/bin/dora", + "run", + "${WORKSPACE}/validation/review-20261112/viewer-usb-gateway-bounded/dataflow.yaml", + "--stop-after", + "10s" + ], + "includes_gateway": true, + "passed": true, + "viewer_included": true, + "rust_sinks_included": true, + "gateway_images": { + "image/rgb": { + "shape": [ + 480, + 640, + 3 + ], + "format": "jpeg" + }, + "image/depth": { + "shape": [ + 480, + 640 + ], + "format": "jpeg" + } + }, + "exit_code": 0, + "checker": { + "passed": true, + "counts": { + "rgb": 215, + "depth": 210 + }, + "elapsed_seconds": 9.020368000026792, + "max_fixture_latency_ms": 550.413, + "error": null + }, + "report_file": "${WORKSPACE}/validation/review-20261112/viewer-usb-gateway-bounded/chain-report.json", + "log_file": "${WORKSPACE}/validation/review-20261112/viewer-usb-gateway-bounded/dora.log", + "log_transport_failures": [ + "2026-11-12T02:03:29.896195Z WARN dora_daemon::node_communication: failed to send NextEvent reply", + " 2: outgoing message size 90462638 exceeds maximum 67108864" + ], + "accepted_smoke": false, + "scope": "Generated RGB/depth short software run; no camera capture, Linux artifact or sustained-run acceptance." + }, + { + "command": [ + "${WORKSPACE}/.test-env/bin/dora", + "run", + "${WORKSPACE}/validation/review-20261112/viewer-usb-gateway-chain/dataflow.yaml", + "--stop-after", + "10s" + ], + "includes_gateway": true, + "passed": false, + "viewer_included": true, + "rust_sinks_included": true, + "error": "Gateway did not become healthy; inspect dora.log", + "report_file": "${WORKSPACE}/validation/review-20261112/viewer-usb-gateway-chain/chain-report.json", + "log_file": "${WORKSPACE}/validation/review-20261112/viewer-usb-gateway-chain/dora.log", + "log_transport_failures": [ + "10:01:51 stdout adapter-forge-gateway: 2026-11-12 10:01:51 - forge_gateway.cli - ERROR - gateway requires joint_order or an enabled Tool Gateway", + "2026-11-12T02:01:51.421651Z ERROR node_failure: dora_daemon::spawn::prepared: node exited with error: ExitCode(1) node_id=adapter-forge-gateway dataflow_id=01a1cd7d-6b32-78e4-8fcd-d9e4a9ef2744", + "10:01:51 ERROR adapter-forge-gateway: daemon exited with code 1", + "2026-11-12T02:01:53.000924Z ERROR node_failure: dora_daemon::spawn::prepared: node exited with error: ExitCode(1) node_id=rust-depth dataflow_id=01a1cd7d-6b32-78e4-8fcd-d9e4a9ef2744", + "10:01:53 ERROR rust-depth: daemon exited with code 1. This error occurred because node `adapter-forge-gateway` exited before connecting to dora." + ], + "accepted_smoke": false, + "scope": "Generated RGB/depth short software run; no camera capture, Linux artifact or sustained-run acceptance." + }, + { + "command": [ + "${WORKSPACE}/.test-env/bin/dora", + "run", + "${WORKSPACE}/validation/review-20261112/viewer-usb-gateway-chain-final/dataflow.yaml", + "--stop-after", + "10s" + ], + "includes_gateway": true, + "passed": true, + "viewer_included": true, + "rust_sinks_included": true, + "gateway_images": { + "image/rgb": { + "shape": [ + 480, + 640, + 3 + ], + "format": "jpeg" + }, + "image/depth": { + "shape": [ + 480, + 640 + ], + "format": "jpeg" + } + }, + "exit_code": 0, + "checker": { + "passed": true, + "counts": { + "rgb": 241, + "depth": 238 + }, + "elapsed_seconds": 9.78292604116723, + "max_fixture_latency_ms": 356.402, + "error": null + }, + "report_file": "${WORKSPACE}/validation/review-20261112/viewer-usb-gateway-chain-final/chain-report.json", + "log_file": "${WORKSPACE}/validation/review-20261112/viewer-usb-gateway-chain-final/dora.log", + "log_transport_failures": [ + "2026-11-12T02:02:44.756021Z WARN dora_daemon::node_communication: failed to send NextEvent reply", + " 2: outgoing message size 105544522 exceeds maximum 67108864" + ], + "accepted_smoke": false, + "scope": "Generated RGB/depth short software run; no camera capture, Linux artifact or sustained-run acceptance." + }, + { + "command": [ + "${WORKSPACE}/.test-env/bin/dora", + "run", + "${WORKSPACE}/validation/review-20261112/viewer-usb-gateway-strict-final/dataflow.yaml", + "--stop-after", + "10s" + ], + "includes_gateway": true, + "passed": true, + "viewer_included": true, + "rust_sinks_included": true, + "gateway_images": { + "image/rgb": { + "shape": [ + 480, + 640, + 3 + ], + "format": "jpeg" + }, + "image/depth": { + "shape": [ + 480, + 640 + ], + "format": "jpeg" + } + }, + "exit_code": 0, + "checker": { + "passed": true, + "counts": { + "rgb": 284, + "depth": 283 + }, + "elapsed_seconds": 9.758289957884699, + "max_fixture_latency_ms": 30.48, + "error": null + }, + "report_file": "${WORKSPACE}/validation/review-20261112/viewer-usb-gateway-strict-final/chain-report.json", + "log_file": "${WORKSPACE}/validation/review-20261112/viewer-usb-gateway-strict-final/dora.log", + "log_transport_failures": [], + "accepted_smoke": true, + "scope": "Generated RGB/depth short software run; no camera capture, Linux artifact or sustained-run acceptance." + }, + { + "command": [ + "${WORKSPACE}/.test-env/bin/dora", + "run", + "${WORKSPACE}/validation/review-20261112/viewer-usb-gateway-verified/dataflow.yaml", + "--stop-after", + "10s" + ], + "includes_gateway": true, + "passed": true, + "viewer_included": true, + "rust_sinks_included": true, + "gateway_images": { + "image/rgb": { + "shape": [ + 480, + 640, + 3 + ], + "format": "jpeg" + }, + "image/depth": { + "shape": [ + 480, + 640 + ], + "format": "jpeg" + } + }, + "exit_code": 0, + "checker": { + "passed": true, + "counts": { + "rgb": 284, + "depth": 283 + }, + "elapsed_seconds": 9.780401125084609, + "max_fixture_latency_ms": 52.973, + "error": null + }, + "report_file": "${WORKSPACE}/validation/review-20261112/viewer-usb-gateway-verified/chain-report.json", + "log_file": "${WORKSPACE}/validation/review-20261112/viewer-usb-gateway-verified/dora.log", + "log_transport_failures": [], + "accepted_smoke": true, + "scope": "Generated RGB/depth short software run; no camera capture, Linux artifact or sustained-run acceptance." + } + ], + "blockers": [ + "Intermittent Dora 1.0.1 64 MiB transport reply failure observed in 640x480 multi-consumer image runs, even with zero process exit. Later clean runs do not resolve it.", + "Native Linux V4L2 capture is unavailable on this macOS host; generated images only validate receiver paths." + ] +} diff --git a/src/bin/usb_camera_test_sink.rs b/src/bin/usb_camera_test_sink.rs index 8c3692b..31c541e 100644 --- a/src/bin/usb_camera_test_sink.rs +++ b/src/bin/usb_camera_test_sink.rs @@ -40,6 +40,9 @@ fn default_min_frames() -> u64 { } fn require_frames(count: u64, minimum: u64) -> Result<()> { + if minimum == 0 { + eyre::bail!("min_frames must be positive"); + } if count < minimum { eyre::bail!("received {count} valid images; required at least {minimum}"); } @@ -129,6 +132,7 @@ mod tests { #[test] fn no_frames_is_not_a_successful_stream_test() { + assert!(require_frames(0, 0).is_err()); assert!(require_frames(0, 1).is_err()); assert!(require_frames(1, 1).is_ok()); } From d5b9ae4fd8f618f2a158e4ee43ac87183aee78ed Mon Sep 17 00:00:00 2001 From: mrgh97 <44031031+mrgh97@users.noreply.github.com> Date: Thu, 12 Nov 2026 16:23:46 +0800 Subject: [PATCH 5/5] fix(deps): align Forge 2 nodes with Msgs 2.1 and document breaking deployment change --- README.md | 10 ++- README_zh.md | 10 ++- migration/msgs-2.1.0-report.json | 141 +++++++++++++++++++++++++++++++ 3 files changed, 159 insertions(+), 2 deletions(-) create mode 100644 migration/msgs-2.1.0-report.json diff --git a/README.md b/README.md index 14a0369..337296a 100644 --- a/README.md +++ b/README.md @@ -2,6 +2,14 @@ # USB camera +## BREAKING CHANGE: Forge 2.x / Dora 1.x migration + +This migration from Forge 1.x / Dora 0.4.x requires coordinated deployment. Align the Forge packages, Dora CLI/coordinator/daemon, this node and its peer nodes before connecting a dataflow; replacing only one node in a Forge 1.x deployment is unsupported. Rebuild and redeploy executable artifacts with the matching environment. Keep `stable/1.x` for deployments that still use the previous stack. + +The validated Python baseline is `forge-msgs==2.1.0`, `Pillow==13.0.0`, `forge-common==2.1.0`, the applicable `forge-robot` / `forge-policy` / `forge-kinematics` / `forge-tool` packages at `2.0.0`, and `dora-rs==1.0.1`. Respect this repository's Python and SDK platform requirements. Forge package families have independent versions. Rust nodes retain the published `forge_msgs` crate `2.0.0` with Dora `1.0.1`; Python Msgs `2.1.0` does not require a nonexistent Rust `2.1.0` release. The `forge_msgs.v1` message namespace remains unchanged. + +This notice describes the deployment break from the previous stack; it does not declare hardware, real-model or sustained-run acceptance complete. See [this round's verification report](migration/msgs-2.1.0-report.json) for actual tests and outstanding gates. + Linux V4L2/UVC camera capture with raw RGB, JPEG and PNG Dora outputs. ## Migration status @@ -15,7 +23,7 @@ usb_camera_test_sink validates every frame, fails on malformed or insufficient i ## Runtime and platform - First validation combination: Dora CLI/coordinator/daemon/node APIs 1.0.1, - Forge Msgs 2.0.0 and Common 2.1.0; use only the families required by this node. + Rust Msgs 2.0.0 / Python Msgs 2.1.0 and Common 2.1.0; use only the families required by this node. - Forge wire schemas remain `forge_msgs.v1`. Dora 0.x and 1.x cannot share a runtime. - Use Python 3.12 for Python builds. Camera-only Python packages may also declare Python 3.11 support; test that interpreter separately before claiming it. diff --git a/README_zh.md b/README_zh.md index dec85bb..e656dda 100644 --- a/README_zh.md +++ b/README_zh.md @@ -2,6 +2,14 @@ # USB Camera +## BREAKING CHANGE:Forge 2.x / Dora 1.x 迁移 + +本次从 Forge 1.x / Dora 0.4.x 升级需要协同部署。节点对接前必须对齐 Forge 包、Dora CLI/coordinator/daemon、本节点及上下游节点的版本;不支持在 Forge 1.x 部署中只替换单个节点。可执行产物也需要使用匹配环境重新构建和部署。仍使用旧技术栈的部署请保留在 `stable/1.x`。 + +本轮验证的 Python 基线为 `forge-msgs==2.1.0`、`Pillow==13.0.0`、`forge-common==2.1.0`、按需使用的 `forge-robot` / `forge-policy` / `forge-kinematics` / `forge-tool` 为 `2.0.0`,以及 `dora-rs==1.0.1`。同时遵守本仓库的 Python 和 SDK 平台要求。Forge 各包族独立发布,无需强行使用同一个版本号。Rust 节点继续使用已发布的 `forge_msgs` crate `2.0.0` 和 Dora `1.0.1`;Python Msgs `2.1.0` 不要求升级到尚未发布的 Rust `2.1.0`。消息命名空间 `forge_msgs.v1` 保持不变。 + +这里的 breaking change 指旧技术栈的部署迁移,不代表真机、真实模型或长时间运行已完成验收。实际测试和未完成项见[本轮验证报告](migration/msgs-2.1.0-report.json)。 + 纯 Rust 的 Linux USB/UVC 彩色相机接入,保留独立的配置模型、采集 backend、CLI 和 Dora 节点。支持 V4L2 `/dev/video*`,不引入 Python。不同设备、固件和驱动组合仍需分别验证。 ## 支持范围 @@ -185,7 +193,7 @@ FORGE_OBSERVABILITY=1 dora run dataflow.yaml ## Forge 2 / Dora 1 迁移 -目标版本:`2.1.2`,当前为待验收改动。首轮验证组合使用 Dora 1.0.1、Forge Msgs 2.0.0、Common 2.1.0;依赖与构建工具以提交的锁文件为准。原有消息规范继续使用 `forge_msgs.v1`。 +目标版本:`2.1.2`,当前为待验收改动。首轮验证组合使用 Dora 1.0.1、Rust Msgs 2.0.0 / Python Msgs 2.1.0、Common 2.1.0;依赖与构建工具以提交的锁文件为准。原有消息规范继续使用 `forge_msgs.v1`。 本轮要求:检查所有示例最终 YAML,使用 `dora validate ` 验证,并实际执行消息往返。相机取流、资源释放和异常退出须分别验收;高吞吐图像链预热后连续测试至少 4 小时,覆盖慢消费者、扇出、退出与重启,记录实际内存占用。无硬件单测不能替代设备验收。 diff --git a/migration/msgs-2.1.0-report.json b/migration/msgs-2.1.0-report.json new file mode 100644 index 0000000..eebd13f --- /dev/null +++ b/migration/msgs-2.1.0-report.json @@ -0,0 +1,141 @@ +{ + "repository": "adapter-camera-usb", + "round": "msgs-2.1.0 alignment / 2026-11-12", + "breaking_change": "Forge 1.x / Dora 0.4.x to Forge 2.x / Dora 1.x requires aligned Forge packages, runtime services, node peers and rebuilt artifacts. Forge families version independently. forge_msgs.v1 remains unchanged.", + "changes": [ + "Update paired README deployment/version compatibility notice", + "Keep published Rust forge_msgs 2.0.0 / Dora 1.0.1 crate baseline; no unavailable Rust 2.1.0 pin" + ], + "lock_updates": [], + "lock_checks": [], + "software_tests": { + "repo": "adapter-camera-usb", + "rust_tests": "27 passed", + "scope": "Cargo tests; fixture tests use a separate exact requirements environment." + }, + "dependency_audit": { + "scope": "Python runtime audit not applicable to Rust node; prior RustSec scope unchanged." + }, + "dora_run_records": [ + { + "entry": "usb-camera", + "mode": "single", + "command": [ + "${WORKSPACE}/.test-env/bin/dora", + "run", + "${WORKSPACE}/validation/downstream-msgs210-20261112/review-single/usb-camera/dataflow.yaml", + "--stop-after", + "4s" + ], + "exit_code": 1, + "elapsed_seconds": 3.951, + "passed": false, + "expected_negative_confirmed": true, + "scope": "Negative platform check: native Linux V4L2 capture is unavailable on macOS; not hardware acceptance.", + "repo": "adapter-camera-usb", + "source_report": "review-single/usb-camera/report.json", + "runtime_errors": [ + "2026-11-12T08:10:39.395710Z ERROR node_failure: dora_daemon::spawn::prepared: node exited with error: ExitCode(1) node_id=target dataflow_id=01a1cecf-030a-736e-a56e-751a6fd8d5b8", + "16:10:39 ERROR target: daemon exited with code 1 with stderr output:" + ], + "local_evidence": "Full original Dora log is retained under validation/downstream-msgs210-20261112/review-single/usb-camera/dora.log" + }, + { + "entry": "usb-sink-empty", + "mode": "single", + "command": [ + "${WORKSPACE}/.test-env/bin/dora", + "run", + "${WORKSPACE}/validation/downstream-msgs210-20261112/review-single/usb-sink-empty/dataflow.yaml", + "--stop-after", + "4s" + ], + "exit_code": 1, + "elapsed_seconds": 4.059, + "passed": false, + "expected_negative_confirmed": true, + "scope": "Negative empty-stream check: min_frames=0 must fail, not an accepted image stream.", + "repo": "adapter-camera-usb", + "source_report": "review-single/usb-sink-empty/report.json", + "runtime_errors": [ + "2026-11-12T08:10:43.491200Z ERROR node_failure: dora_daemon::spawn::prepared: node exited with error: ExitCode(1) node_id=target dataflow_id=01a1cecf-11fa-7a6d-a6aa-3c465f80e9c2", + "16:10:43 ERROR target: daemon exited with code 1 with stderr output:" + ], + "local_evidence": "Full original Dora log is retained under validation/downstream-msgs210-20261112/review-single/usb-sink-empty/dora.log" + }, + { + "entry": "usb-camera", + "mode": "chain", + "command": [ + "${WORKSPACE}/.test-env/bin/dora", + "run", + "${WORKSPACE}/validation/downstream-msgs210-20261112/review-chain/usb-camera/dataflow.yaml", + "--stop-after", + "4s" + ], + "includes_gateway": true, + "exit_code": 1, + "elapsed_seconds": 4.377, + "passed": false, + "scope": "Blocked platform/SDK prerequisite diagnostic; not successful transport or hardware acceptance.", + "repo": "adapter-camera-usb", + "source_report": "review-chain/usb-camera/report.json", + "runtime_errors": [ + "2026-11-12T08:10:45.929197Z ERROR node_failure: dora_daemon::spawn::prepared: node exited with error: ExitCode(1) node_id=target dataflow_id=01a1cecf-295f-718e-bb91-7b54a3dc4ffe", + "16:10:45 ERROR target: daemon exited with code 1 with stderr output:" + ], + "local_evidence": "Full original Dora log is retained under validation/downstream-msgs210-20261112/review-chain/usb-camera/dora.log" + }, + { + "command": [ + "${WORKSPACE}/.test-env/bin/dora", + "run", + "${WORKSPACE}/validation/downstream-msgs210-20261112/image-chain/dataflow.yaml", + "--stop-after", + "10s" + ], + "includes_gateway": true, + "passed": true, + "viewer_included": true, + "rust_sinks_included": true, + "gateway_images": { + "image/rgb": { + "shape": [ + 480, + 640, + 3 + ], + "format": "jpeg" + }, + "image/depth": { + "shape": [ + 480, + 640 + ], + "format": "jpeg" + } + }, + "exit_code": 0, + "checker": { + "passed": true, + "counts": { + "rgb": 284, + "depth": 284 + }, + "elapsed_seconds": 9.729441124945879, + "max_fixture_latency_ms": 24.139, + "error": null + }, + "mode": "chain", + "entry": "generated-images-viewer-rust-sinks-gateway", + "scope": "Generated 640x480 RGB/depth, Viewer and two Rust sinks plus Gateway, 10 seconds. No physical camera, hardware or sustained-run acceptance.", + "source_report": "image-chain/chain-report.json", + "repo": "adapter-camera-usb", + "local_evidence": "Full original Dora log is retained under validation/downstream-msgs210-20261112/image-chain/dora.log" + } + ], + "remaining": "Applicable actual hardware/model, final supported-platform artifacts, sustained run and rollback acceptance remain pending.", + "acceptance": "Pending; software checks, fake/dummy backends and negative prerequisite records are scoped evidence only. Every new multi-node graph contains adapter-forge-gateway.", + "gitlab_sync": "Not performed; follows completed acceptance.", + "log_publication": "Original logs remain in the local validation workspace. This public report publishes reviewed commands, outcomes, assertions and limitations only." +}