mikael-lovqvists-claude-agent 32d31cbd1e Add display sink: START_DISPLAY/STOP_DISPLAY, multi-window xorg, random port
Protocol:
- Add PROTO_CMD_START_DISPLAY (0x000A) and PROTO_CMD_STOP_DISPLAY (0x000B)
  with write/read functions; Proto_Start_Display carries stream_id, window
  position/size, scale and anchor; PROTO_DISPLAY_SCALE_*/ANCHOR_* constants

Node display sink:
- Display_Slot struct with wanted_state/current_state (DISP_CLOSED/DISP_OPEN);
  handlers set wanted state, display_loop_tick on main thread reconciles
- Up to MAX_DISPLAYS (4) simultaneous viewer windows
- on_frame routes incoming VIDEO_FRAME messages to matching display slot;
  transport thread deposits payload, main thread consumes without holding lock
  during JPEG decode/upload
- Main thread runs GL event loop when xorg is available; headless fallback
  joins reconciler timer thread as before

Xorg multi-window:
- Ref-count glfwInit/glfwTerminate via glfw_acquire/glfw_release so closing
  one viewer does not terminate GLFW for remaining windows
- Add glfwMakeContextCurrent before GL calls in push_yuv420, push_bgra,
  push_mjpeg and poll so each viewer uses its own GL context correctly

Transport random port:
- Bind port 0 lets the OS assign a free port; getsockname reads it back
  into server->bound_port after bind
- Add transport_server_get_port() accessor
- Default tcp_port changed from 8000 to 0 (random); node prints actual
  port after server start so it is always visible in output
- Add --port PORT CLI override (before config-file argument)

controller_cli:
- Add start-display and stop-display commands

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-03-29 08:03:21 +00:00

video-setup

A graph-based multi-peer video routing system written in C11. Nodes are media processes connected by typed transport edges; the graph carries video streams between sources, relays, and sinks with priority as a first-class property — so a low-latency monitoring feed and a high-quality archival feed can coexist on the same source.

Designed to run on resource-constrained hardware (Raspberry Pi capturing raw MJPEG, forwarding over TCP) alongside more capable machines that handle processing, relay, display, and archival.

Documentation

  • architecture.md — system design: graph model, transport protocol, relay design, codec layer, discovery, multi-site plan, device resilience, X11 integration
  • docs/protocol.md — wire protocol reference: frame format, all message types, payload schemas, stream lifecycle, discovery
  • planning.md — module build order and current status
  • conventions.md — C code and project conventions

CLI Tools

  • docs/cli/media_ctrl_cli.md — media device and topology tool
  • docs/cli/v4l2_ctrl_cli.md — V4L2 camera control tool
  • test_image_cli — generate test patterns and write PPM output for visual inspection
  • xorg_cli — display a test pattern in the viewer window; exercises scale/anchor modes and text overlays
  • v4l2_view_cli — live camera viewer; auto-selects highest-FPS format, displays FPS overlay
  • stream_send_cli — capture MJPEG from V4L2, connect to a receiver over TCP, stream VIDEO_FRAME messages with per-stream stats
  • stream_recv_cli — listen for incoming TCP stream, display received MJPEG frames with fps/Mbps overlay

Structure

src/modules/     C modules, one directory each
include/         public headers
dev/cli/         CLI driver programs for each module
dev/web/         development web UI (Node.js/Express) — connects to live nodes for V4L2 inspection and control
tools/           build-time code generators (e.g. gen_font_atlas — bitmap font atlas for xorg text overlays)
docs/            documentation

Status

Core modules and the video node binary are working. The node can be queried over the wire protocol for device enumeration and V4L2 camera control. The development web UI connects to live nodes for inspection and control. The xorg viewer sink is implemented (GLFW+OpenGL, all scale/anchor modes, bitmap font atlas text overlays). A V4L2 capture viewer (v4l2_view_cli) demonstrates live camera display without going through the node system. Frame ingest-to-wire and relay have not started.

Module Status Notes
common done Error types, base definitions
config done INI file loader, schema-driven defaults, typed getters
media_ctrl done Media Controller topology, pad format config
v4l2_ctrl done V4L2 control enumeration, get/set
serial done Little-endian binary serialization primitives
transport done Framed TCP stream, single-write send
discovery done UDP multicast announcements, peer table, found/lost callbacks
protocol done Typed write/read functions for all message types
node done Video node binary — config, discovery, transport server, V4L2/media request handlers
dev/web done Development web UI — connects to live nodes, V4L2 inspection and control
test_image done Test pattern generator — colour bars, luminance ramp, grid; YUV420/BGRA output
xorg done GLFW+OpenGL viewer sink — YUV420/BGRA/MJPEG input, all scale/anchor modes, bitmap font atlas text overlays; screen grab and XRandR queries not yet implemented
frame_alloc not started Per-frame allocation with byte budget and ref counting
relay not started Input dispatch to output queues (low-latency and completeness modes)
ingest not started V4L2 capture loop — dequeue buffers, emit frames
archive not started Write frames to disk, control messages to binary log
codec not started Per-frame encode/decode (MJPEG, QOI, ZSTD-raw, VA-API H.264)
web node not started Node.js peer — binary protocol socket side + HTTP/WebSocket to browser
Description
Graph-based multi-peer video routing system
Readme 1 MiB
Languages
C 83.7%
JavaScript 8.3%
Makefile 3.7%
Python 2.1%
CSS 1.7%
Other 0.5%