Skip to content

cvcGL: camera_source — SDL3 camera as a stream frame_source (Phase 3b) - #532

Merged
transfix merged 3 commits into
masterfrom
feat/stream-camera
Oct 2, 2026
Merged

transfix merged 3 commits into
masterfrom
feat/stream-camera

Conversation

@transfix

@transfix transfix commented Oct 2, 2026

Copy link
Copy Markdown
Owner

Summary

Phase-3b — the first device member of the generalized video-source family (docs/STREAMING.md): cvc::gl::capture::camera_source, an SDL3 camera exposed as a cvc::ariadne::stream::frame_source producing dense rgba8. A stream and its sinks never know the frames came from a camera; drive it with stream::start_producer().

Lives in cvcGL because SDL3 is cvcGL's peripheral seam — the cvc monolith doesn't link SDL (adding it there would be a libcvc recipe dependency change across the fleet). The virtual/pure video members — a multiplexer and an ffmpeg process-pipe source — are cvc-core (no SDL, fully testable) and land next.

What's new

  • inc/cvc/gl/capture/camera_source.h — open_camera(device_index) → { source, width, height, fps, name } (empty result if SDL is absent / index out of range / open fails), list_cameras(), and pump_events(). SDL is kept out of the header.
  • src/cvcGL/capture/camera_source.cpp (new capture/*.cpp glob; SDL-gated on CVC_ENABLE_SDL, a graceful no-op without SDL): open negotiates the camera's native format, waits (bounded, pumping events) for SDL's async permission approval, and reports the actual w/h/fps so the caller sizes its stream to match. fill() acquires a frame, converts to byte-order RGBA32, copies it densely into the pool slab, and releases — never blocking (no frame yet ⇒ skip). The subsystem ref + SDL_Camera are released in the source dtor, where start_producer's join-before-free has already stopped the producer.

Host contract

SDL delivers camera approval and frame readiness through its event system, so the app's main thread must pump SDL events for a camera source to produce frames — a cvcGL app already does this via its input loop; pump_events() is provided for a host/test without one. Documented in the header and STREAMING.md.

Testing

cvcgl_camera_source (device-gated): always enumerates (passive); opens + exercises the live acquire→convert→copy path only under CVC_TEST_CAMERA=1 (opening activates the device), and is soft on frame arrival (permission/session/headless variance). Verified on this machine: compiles against SDL3, opens a real UVC camera, gets approval, negotiates 1280×960@30, and runs the capture loop crash-free. Actual frame bytes need a real desktop session (the SDL V4L2/pipewire backend doesn't stream in a headless test process), which a cvcGL app provides. The transport side (producer thread, pool, drop-at-source, join-on-close) is covered hardware-free by stream_test's StreamProducer.* via synthetic_source.

Adversarial review (SDL resource-ownership focus) is running; I'll fold findings before auto-merge.

…, video)

The first DEVICE member of the generalized video-source family (docs/STREAMING.md): an SDL3 camera
exposed as a cvc::ariadne::stream::frame_source producing dense rgba8, so a stream and its sinks never
know the frames came from a camera. Lives in cvcGL because SDL3 is cvcGL's peripheral seam; the cvc
monolith does not link SDL (adding it there would be a libcvc recipe dep change across the fleet).
The virtual/pure video members (a multiplexer, an ffmpeg process-pipe source) are cvc-core and land
next.

- inc/cvc/gl/capture/camera_source.h: open_camera(device_index) -> { source, width, height, fps,
  name } (empty result if SDL absent / index OOR / open fails), list_cameras(), and pump_events().
  SDL is kept out of the header.
- src/cvcGL/capture/camera_source.cpp (new capture/*.cpp glob; SDL-gated on CVC_ENABLE_SDL, graceful
  no-op without SDL): open negotiates the camera's native format, WAITS (bounded, pumping events)
  for SDL's async permission approval, and reports the actual w/h/fps so the caller sizes its stream
  to match. fill() SDL_AcquireCameraFrame -> SDL_ConvertSurface to byte-order RGBA32 -> dense copy
  into the pool slab -> SDL_ReleaseCameraFrame; never blocks (no frame yet => skip). The camera
  subsystem ref + the SDL_Camera are released in the source dtor, where start_producer's
  join-before-free has already stopped the producer.
- HOST CONTRACT: SDL delivers camera approval + frames through its event system, so the app's main
  thread must pump SDL events (a cvcGL app already does via its input loop; pump_events() is provided
  for a host/test without one).

Test cvcgl_camera_source (device-gated): always enumerates (passive); opens + exercises the live
acquire->convert->copy path only under CVC_TEST_CAMERA=1 (opening activates the device), and is soft
on frame arrival (permission/session/headless variance). Verified here: compiles against SDL3, opens
a real UVC camera, approves, negotiates 1280x960@30, runs the capture loop crash-free; actual frame
bytes require a real desktop session (the SDL V4L2/pipewire backend does not stream in a headless
test process) — which a cvcGL app provides.
Adversarial review (SDL resource-ownership focus) verified the Init/Quit refcount balance, the
acquire/convert/release ownership, fill() bounds, the approval-wait, and teardown all correct. Folded:

- MUST-FIX: inc/cvc/gl/capture/camera_source.h now INCLUDES cvc/ariadne/stream/frame_source.h instead
  of forward-declaring it. camera_open holds a unique_ptr<frame_source>, so ~camera_open needs the
  complete type; the forward-decl made any TU merely holding a camera_open fail to compile at scope
  exit (the test only built because it also included frame_source.h). frame_source.h pulls no SDL, so
  the header stays SDL-free. Verified self-contained (a TU including only the header + a camera_open
  local now compiles).
- Documented the thread contract: open_camera()/list_cameras()/destroying the owning stream all touch
  the non-thread-safe SDL camera subsystem, so they run on the SDL main thread (same as ~stream);
  only fill() runs on the producer thread.
- Use SDL_CAMERA_PERMISSION_STATE_PENDING/_APPROVED instead of magic 0/1.
- Comment the mid-stream resolution-change case (w/h-guard -> clean skip, never OOB).

(The improbable make_unique-throw leak the review rated negligible is left as noted.)
@transfix
transfix merged commit 2edd899 into master Oct 2, 2026
12 of 13 checks passed
@transfix
transfix deleted the feat/stream-camera branch October 29, 2026 20:53
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant