Skip to content

refactor(camera): move the lores encoder hooks into StreamingCameraBackend - #60

Merged
simonvanlierde merged 2 commits into
mainfrom
move-lores-encoder-streaming
Oct 23, 2026
Merged

simonvanlierde merged 2 commits into
mainfrom
move-lores-encoder-streaming

Conversation

@simonvanlierde

Copy link
Copy Markdown
Contributor

This moves the H264 lores encoder methods out of the core CameraBackend protocol and into StreamingCameraBackend. Before this, every backend had to implement them, even a stills-only sensor with no preview stream. A backend without them crashed the preview pipeline with an AttributeError.

  • CameraBackend declared start_lores_encoder and stop_lores_encoder. They now live on StreamingCameraBackend. StreamingNotSupportedError moved next to the protocols, and the manager imports it from there.
  • The preview pipeline called the hooks on any CameraBackend. It now narrows to StreamingCameraBackend and raises StreamingNotSupportedError for a backend without them.
  • The preview sleeper and thermal governor passed any backend on to the pipeline. They now skip a backend without the hooks, so a core-only camera does not log a warning every tick.
  • The worker and pipeline test mocks were plain MagicMocks, which fail a runtime protocol check. They now use a StreamingCameraBackend spec. I also updated the backend paragraph in ARCHITECTURE.md.

No test runs Picamera2Backend on a Pi, so the hardware path is unchecked. Picamera2Backend already subclasses StreamingCameraBackend and keeps both methods unchanged.

Tests:

  • just check: exit 0
    Required test coverage of 80.0% reached. Total coverage: 94.87%
    ======================== 840 passed, 1 skipped in 8.03s ========================
    
    ruff and ty check both reported "All checks passed!".
  • ! sed -n '/^class CameraBackend/,/^class StreamingCameraBackend/p' app/camera/services/backend.py | grep -q 'lores_encoder': exit 0, no output.

I ran the two new tests on the code before the change and both failed. test_start_raises_streaming_not_supported failed with AttributeError: '_StillOnlyBackend' object has no attribute 'start_lores_encoder'. test_tick_is_noop_for_backend_without_lores_encoder failed with Expected 'start' to not have been called. Called 1 times.


…ckend

- Move start_lores_encoder and stop_lores_encoder from CameraBackend to
  StreamingCameraBackend, so a core-only backend no longer has to stub them.
- Move StreamingNotSupportedError next to the protocols. The manager still
  imports it from there.
- The preview pipeline narrows to StreamingCameraBackend and raises
  StreamingNotSupportedError instead of an AttributeError.
- The preview sleeper and thermal governor skip a backend without the hooks.
- Give the worker and pipeline test mocks a StreamingCameraBackend spec and
  add tests for the core-only backend path.
@codspeed

codspeed Bot commented Oct 22, 2026 •

Copy link
Copy Markdown

Merging this PR will not alter performance

1 warning

⚠️ 2 benchmarks are dominated by system calls

System calls cannot be simulated consistently and are left out of the measure. The reported value understates the real cost. Switch to the Walltime instrument to measure them.

Learn more about system calls

See affected benchmarks

✅ 10 untouched benchmarks


Comparing move-lores-encoder-streaming (c88559d) with main (da58389)

Open in CodSpeed

@codecov

codecov Bot commented Oct 22, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

@simonvanlierde
simonvanlierde merged commit 681004c into main Oct 23, 2026
10 checks passed
@simonvanlierde
simonvanlierde deleted the move-lores-encoder-streaming branch October 23, 2026 19:41
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