Screen share 1: fluxer-video crate — frames, conversions, FrameBus, test pattern, preview JPEG #148

Closed
opened 2026-11-12 02:06:53 +00:00 by charles · 0 comments
Owner

Files:

  • Create: crates/fluxer-video/{Cargo.toml,README.md}, src/{lib.rs,frame.rs,convert.rs,scale.rs,bus.rs,pattern.rs,jpeg.rs}
  • Modify: workspace Cargo.toml (member; image gains the jpeg encoder feature if it lacks it)
  • Test: crates/fluxer-video/tests/{convert.rs,bus.rs,jpeg.rs}

Interfaces:

  • Produces: VideoFrame { width: u32, height: u32, timestamp_us: i64, data: FrameData } (Clone is cheap: Arc planes); FrameData::{I420 { y, u, v, strides }, Nv12 { y, uv, strides }, Bgra { data, stride }, Rgba { data, stride }}; convert::{bgra_to_i420, i420_to_rgba, nv12_to_i420} (BT.601 limited range, the libyuv convention); scale::area_downscale(&VideoFrame, max_w, max_h) -> VideoFrame (keeps aspect, even dimensions); pattern::TestPattern::new(w, h).frame(n) -> VideoFrame (moving bars + frame counter blocks, decodable back to n within ±1 after lossy coding: pattern::read_counter(&VideoFrame) -> Option<u32>); jpeg::preview_jpeg(&VideoFrame) -> Result<Vec<u8>, JpegError> with spec §3.6's budget (≤ 640 px, ≥ 160 px, quality 0.7→0.4 step 0.15, then ×0.8, ≤ 6 attempts, ≤ 1 000 000 bytes); VideoKey::{Remote { sid: String }, LocalCapture, Preview { stream_key: String }, Source { id: String }}; FrameBus (Clone, Send + Sync): publish(key, VideoFrame), get(&key) -> Option<(u64 /*generation*/, VideoFrame)>, generation(&key) -> Option<u64>, remove(&key), keys().

  • Step 1: Write failing tests: bgra_i420_round_trip_within_2_levels, i420_to_rgba_known_colours (pure red/green/blue/grey to the libyuv values), area_downscale_keeps_aspect_and_even_dims, pattern_counter_survives_blur_and_downscale, preview_jpeg_respects_size_and_bytes_budget (a 4K noise frame), bus_latest_frame_wins, bus_reader_never_blocks_writer (writer thread at 1 kHz, reader asserts monotonically increasing generations and no stalls > 5 ms over 2 s), bus_remove_forgets_key.

  • Step 2–5: FAIL → implement → PASS → commit feat(video): frames, conversions, frame bus, test pattern and preview JPEG.

Depends on: nothing (can start at once)

Plan: https://git.forked.io/charles/fluxer-native/src/branch/main/docs/superpowers/plans/2026-11-11-screenshare.md
Spec: https://git.forked.io/charles/fluxer-native/src/branch/main/docs/superpowers/specs/2026-11-11-fluxer-native-screenshare-design.md

**Files:** - Create: `crates/fluxer-video/{Cargo.toml,README.md}`, `src/{lib.rs,frame.rs,convert.rs,scale.rs,bus.rs,pattern.rs,jpeg.rs}` - Modify: workspace `Cargo.toml` (member; `image` gains the `jpeg` encoder feature if it lacks it) - Test: `crates/fluxer-video/tests/{convert.rs,bus.rs,jpeg.rs}` **Interfaces:** - Produces: `VideoFrame { width: u32, height: u32, timestamp_us: i64, data: FrameData }` (`Clone` is cheap: `Arc` planes); `FrameData::{I420 { y, u, v, strides }, Nv12 { y, uv, strides }, Bgra { data, stride }, Rgba { data, stride }}`; `convert::{bgra_to_i420, i420_to_rgba, nv12_to_i420}` (BT.601 limited range, the libyuv convention); `scale::area_downscale(&VideoFrame, max_w, max_h) -> VideoFrame` (keeps aspect, even dimensions); `pattern::TestPattern::new(w, h).frame(n) -> VideoFrame` (moving bars + frame counter blocks, decodable back to `n` within ±1 after lossy coding: `pattern::read_counter(&VideoFrame) -> Option<u32>`); `jpeg::preview_jpeg(&VideoFrame) -> Result<Vec<u8>, JpegError>` with spec §3.6's budget (≤ 640 px, ≥ 160 px, quality 0.7→0.4 step 0.15, then ×0.8, ≤ 6 attempts, ≤ 1 000 000 bytes); `VideoKey::{Remote { sid: String }, LocalCapture, Preview { stream_key: String }, Source { id: String }}`; `FrameBus` (`Clone`, `Send + Sync`): `publish(key, VideoFrame)`, `get(&key) -> Option<(u64 /*generation*/, VideoFrame)>`, `generation(&key) -> Option<u64>`, `remove(&key)`, `keys()`. - [ ] **Step 1: Write failing tests**: `bgra_i420_round_trip_within_2_levels`, `i420_to_rgba_known_colours` (pure red/green/blue/grey to the libyuv values), `area_downscale_keeps_aspect_and_even_dims`, `pattern_counter_survives_blur_and_downscale`, `preview_jpeg_respects_size_and_bytes_budget` (a 4K noise frame), `bus_latest_frame_wins`, `bus_reader_never_blocks_writer` (writer thread at 1 kHz, reader asserts monotonically increasing generations and no stalls > 5 ms over 2 s), `bus_remove_forgets_key`. - [ ] **Step 2–5:** FAIL → implement → PASS → commit `feat(video): frames, conversions, frame bus, test pattern and preview JPEG`. Depends on: nothing (can start at once) Plan: https://git.forked.io/charles/fluxer-native/src/branch/main/docs/superpowers/plans/2026-11-11-screenshare.md Spec: https://git.forked.io/charles/fluxer-native/src/branch/main/docs/superpowers/specs/2026-11-11-fluxer-native-screenshare-design.md
charles added this to the Screen share milestone 2026-11-12 02:06:53 +00:00
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
charles/fluxer-native#148
No description provided.