Repository navigation
cvcGL: camera_source — SDL3 camera as a stream frame_source (Phase 3b) - #532
Merged
Merged
Conversation
…, 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
enabled auto-merge
October 2, 2026 05:36
# Conflicts: # src/cvcGL/CMakeLists.txt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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 acvc::ariadne::stream::frame_sourceproducing dense rgba8. A stream and its sinks never know the frames came from a camera; drive it withstream::start_producer().Lives in cvcGL because SDL3 is cvcGL's peripheral seam — the
cvcmonolith 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(), andpump_events(). SDL is kept out of the header.src/cvcGL/capture/camera_source.cpp(newcapture/*.cppglob; SDL-gated onCVC_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_Cameraare released in the source dtor, wherestart_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 underCVC_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 bystream_test'sStreamProducer.*viasynthetic_source.Adversarial review (SDL resource-ownership focus) is running; I'll fold findings before auto-merge.