Camera 7: fluxer-core the own camera (#959) #981

Closed
charles wants to merge 0 commits from camera-7-core-the-own-camera into camera
Owner

What this builds

Camera plan Task 7 (spec §6.1, §11, §12 "Status API", §13.1–2): the own camera's machine in fluxer-core.

  • voice::camera::own: OwnCamera::{Off, Previewing { error }, Starting, Live { sid }}, OwnCapture, CameraNotice + NoticeView, timers CAPTURE_RESTART_TIMEOUT (5 s), STALL_GRACE (3 s after the backend's Stalled), RECONNECT_TIMEOUT (30 s), PUBLISH_TIMEOUT (10 s), and the strings. Voice::reduce_own_camera runs after the screen share.
    • The capture is open exactly while the preview (with no error) or the camera being on uses it. Start is sent when the first use begins, Stop when the last one ends. "Turn on camera" in the preview keeps the running capture.
    • Turning on: first frame → PublishCamera { id, codec, encode } → room confirms → op 4 self_video: true → Chime::CameraOn. Turning off: Stop → op 4 self_video: false → UnpublishCamera → Chime::CameraOff.
    • Every ending of §6.1 and row of §11: leave, lost, failed or logged out (the capture stops in close() before the room or the gateway is told). Also a move or a replaced room, STREAM lost, the gateway clearing an accepted self_video, device lost or stalled, capture failure, publish refused or dropped, VOICE_CAMERA_USER_LIMIT, and the reconnect timeout.
    • Reconnect: the capture stays open. A publication the room lost is republished (new CameraId, no second chime), and op 4 is re-sent.
    • Device or quality chosen while the capture is open: Stop + Start. The publication is kept and UpdateCameraEncoding follows the new frames.
    • TurnOffDevice / TurnOffAllDevices: op 4 for the user's other connections, with their own switches and self_video: false (updateConnectionProperty).
    • The preview closes when the window is hidden or the session locks or suspends. A stored device that is not listed opens the system's camera and the stored choice is kept (D6).
  • voice::camera::params: the row 21 presets (360p20 450k, 720p30 1.7M, 1080p30 3M; 1080p needs feature_higher_video_quality), the row 22 codec rule (preference if encodable → VP9 → H.264 on Windows → VP8; codec_for takes the OS so the rule is testable), layers (Svc("L3T3_KEY") for VP9/AV1, Simulcast for the others), bitrate factor 85 % for VP9 and 70 % for AV1 (spikes §3.2).
  • voice::camera::limits: camera_button(app) (control bar), camera_button_on(app, CameraSurface), camera_block(app, surface) → CameraDisabled::{NotConnected, Unsupported, NoPermission, TooManyParticipants, CameraLimit} in the original's selectCameraLabel order. The voice panel has no participant check (row 6). The reducer refuses Toggle by the control bar's rules and TurnOn by the voice panel's (the original's preview checks only the cap and the permission).
  • connection::Announced gains self_video, so every op 4 carries it. voice_status.selfVideo and the local cameraOn are true from Starting on (§12). keep_awake counts the own camera's open capture.

Strings copied from the fork: "Turn on camera", "Turn off camera", "You can't turn on your camera in this channel", "Cameras are off above {25} participants", "Camera limit reached — up to {25} people can share video in this channel.", "Waiting for connection...", "Camera error", "Failed to start camera preview. Check your camera permissions.", "Failed to enable camera.", "Something went wrong", "Camera permission required", "{productName} needs access to your camera. Allow camera access in your operating system privacy settings and restart the app."
New strings, marked in the code: "Your camera is being used by another app. Close it and try again." (D4), "Your camera was disconnected." (D5), and one more not listed in the spec: "Camera capture isn't available on this system." This is the tooltip for spec §11's last row (CameraFailure::Unsupported carries no text).

How it was tested

  • crates/fluxer-core/tests/camera_own.rs (30 tests): every test the plan names, plus late publications, the window and lock closing the preview, stalls, a missing stored device, logout and room replacement. Also the proptest capture_is_open_iff_something_uses_it: 256 sequences of up to 40 user, capture, room, gateway, permission and timer events. It checks that what the backend was told to hold equals in_use() and capture_open(), and that no op 4 of this connection says self_video: true while unpublished.
  • camera_limits.rs (9) and camera_params.rs (6): the button and preset/codec tables.
  • camera_ports.rs: the stub test became logged_out_reducers_change_nothing, because the logged-in reducers now do something.
  • FLUXER_SCREENSHOT_TESTS=1 cargo xtask ci green locally. No camera, display or server was used. Nothing here runs on a desktop (no FLUXER_DESKTOP_TESTS tests).

Deviations from the plan, and things to look at

  • Publish refused is a 10 s PUBLISH_TIMEOUT, because the session reports nothing for a failed publication (as for the screen share). If Camera 9 adds an explicit failure event, the reducer can end the camera at once.
  • Files outside the list:
    • app.rs: one call. The reducer needs me, guilds, channels and the quality entitlement, and it sits beside reduce_camera, which keeps its signature for Task 8.
    • persist.rs: one arm, so CameraAction::SelectDevice saves video_device.
    • voice/mod.rs: clear_account drops the camera.
  • camera::mod.rs: OwnCamera moved to own.rs (re-exported at the same path). CameraState gains notice and a private link.
  • Sounds: CameraOff plays when the user turns the camera off, on device loss, capture failure, publish refusal and the limit. It does not play when the camera ends with the connection, a move, STREAM loss or the gateway clearing the flag, where the disconnect sound or silence applies.
  • Spec §6.2 says self_video follows Live, §12 says from Starting. This follows §12.
  • keep_awake.rs is also in Task 8's file list. The change here is one line in camera_keeps_display_awake.

Closes #959

🤖 Generated with Claude Code

https://claude.ai/code/session_0161qMQMsCyJhjYw4gqa6e4K

## What this builds Camera plan Task 7 (spec §6.1, §11, §12 "Status API", §13.1–2): the own camera's machine in `fluxer-core`. - `voice::camera::own`: `OwnCamera::{Off, Previewing { error }, Starting, Live { sid }}`, `OwnCapture`, `CameraNotice` + `NoticeView`, timers `CAPTURE_RESTART_TIMEOUT` (5 s), `STALL_GRACE` (3 s after the backend's `Stalled`), `RECONNECT_TIMEOUT` (30 s), `PUBLISH_TIMEOUT` (10 s), and the strings. `Voice::reduce_own_camera` runs after the screen share. - The capture is open exactly while the preview (with no error) or the camera being on uses it. `Start` is sent when the first use begins, `Stop` when the last one ends. "Turn on camera" in the preview keeps the running capture. - Turning on: first frame → `PublishCamera { id, codec, encode }` → room confirms → op 4 `self_video: true` → `Chime::CameraOn`. Turning off: `Stop` → op 4 `self_video: false` → `UnpublishCamera` → `Chime::CameraOff`. - Every ending of §6.1 and row of §11: leave, lost, failed or logged out (the capture stops in `close()` before the room or the gateway is told). Also a move or a replaced room, STREAM lost, the gateway clearing an accepted `self_video`, device lost or stalled, capture failure, publish refused or dropped, `VOICE_CAMERA_USER_LIMIT`, and the reconnect timeout. - Reconnect: the capture stays open. A publication the room lost is republished (new `CameraId`, no second chime), and op 4 is re-sent. - Device or quality chosen while the capture is open: `Stop` + `Start`. The publication is kept and `UpdateCameraEncoding` follows the new frames. - `TurnOffDevice` / `TurnOffAllDevices`: op 4 for the user's other connections, with their own switches and `self_video: false` (`updateConnectionProperty`). - The preview closes when the window is hidden or the session locks or suspends. A stored device that is not listed opens the system's camera and the stored choice is kept (D6). - `voice::camera::params`: the row 21 presets (360p20 450k, 720p30 1.7M, 1080p30 3M; 1080p needs `feature_higher_video_quality`), the row 22 codec rule (preference if encodable → VP9 → H.264 on Windows → VP8; `codec_for` takes the OS so the rule is testable), layers (`Svc("L3T3_KEY")` for VP9/AV1, `Simulcast` for the others), bitrate factor 85 % for VP9 and 70 % for AV1 (*spikes §3.2*). - `voice::camera::limits`: `camera_button(app)` (control bar), `camera_button_on(app, CameraSurface)`, `camera_block(app, surface)` → `CameraDisabled::{NotConnected, Unsupported, NoPermission, TooManyParticipants, CameraLimit}` in the original's `selectCameraLabel` order. The voice panel has no participant check (row 6). The reducer refuses `Toggle` by the control bar's rules and `TurnOn` by the voice panel's (the original's preview checks only the cap and the permission). - `connection::Announced` gains `self_video`, so every op 4 carries it. `voice_status.selfVideo` and the local `cameraOn` are true from `Starting` on (§12). `keep_awake` counts the own camera's open capture. Strings copied from the fork: "Turn on camera", "Turn off camera", "You can't turn on your camera in this channel", "Cameras are off above {25} participants", "Camera limit reached — up to {25} people can share video in this channel.", "Waiting for connection...", "Camera error", "Failed to start camera preview. Check your camera permissions.", "Failed to enable camera.", "Something went wrong", "Camera permission required", "{productName} needs access to your camera. Allow camera access in your operating system privacy settings and restart the app." New strings, marked in the code: "Your camera is being used by another app. Close it and try again." (D4), "Your camera was disconnected." (D5), and **one more not listed in the spec:** "Camera capture isn't available on this system." This is the tooltip for spec §11's last row (`CameraFailure::Unsupported` carries no text). ## How it was tested - `crates/fluxer-core/tests/camera_own.rs` (30 tests): every test the plan names, plus late publications, the window and lock closing the preview, stalls, a missing stored device, logout and room replacement. Also the proptest `capture_is_open_iff_something_uses_it`: 256 sequences of up to 40 user, capture, room, gateway, permission and timer events. It checks that what the backend was told to hold equals `in_use()` and `capture_open()`, and that no op 4 of this connection says `self_video: true` while unpublished. - `camera_limits.rs` (9) and `camera_params.rs` (6): the button and preset/codec tables. - `camera_ports.rs`: the stub test became `logged_out_reducers_change_nothing`, because the logged-in reducers now do something. - `FLUXER_SCREENSHOT_TESTS=1 cargo xtask ci` green locally. No camera, display or server was used. Nothing here runs on a desktop (no `FLUXER_DESKTOP_TESTS` tests). ## Deviations from the plan, and things to look at - **Publish refused** is a 10 s `PUBLISH_TIMEOUT`, because the session reports nothing for a failed publication (as for the screen share). If Camera 9 adds an explicit failure event, the reducer can end the camera at once. - **Files outside the list**: - `app.rs`: one call. The reducer needs `me`, guilds, channels and the quality entitlement, and it sits beside `reduce_camera`, which keeps its signature for Task 8. - `persist.rs`: one arm, so `CameraAction::SelectDevice` saves `video_device`. - `voice/mod.rs`: `clear_account` drops the camera. - `camera::mod.rs`: `OwnCamera` moved to `own.rs` (re-exported at the same path). `CameraState` gains `notice` and a private `link`. - Sounds: `CameraOff` plays when the user turns the camera off, on device loss, capture failure, publish refusal and the limit. It does not play when the camera ends with the connection, a move, STREAM loss or the gateway clearing the flag, where the disconnect sound or silence applies. - Spec §6.2 says `self_video` follows `Live`, §12 says from `Starting`. This follows §12. - `keep_awake.rs` is also in Task 8's file list. The change here is one line in `camera_keeps_display_awake`. Closes #959 🤖 Generated with [Claude Code](https://claude.com/claude-code) https://claude.ai/code/session_0161qMQMsCyJhjYw4gqa6e4K
The machine of spec §6.1, the limits of rows 2-3, the presets and codec
rule of rows 21-22, every ending and notice of spec §11, and the
property test that the capture is open exactly while something uses it.

Refs #959

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_0161qMQMsCyJhjYw4gqa6e4K
The own camera's machine of spec §6.1 (voice:📷:own): the
capture is open exactly while the preview or the camera being on uses
it; turning on publishes after the first frame and says self_video in
op 4 only once the room confirmed it; turning off stops the capture,
then op 4, then unpublishes. Every ending of §6.1 and row of §11 (leave,
move, room lost or replaced, STREAM lost, gateway clearing the flag,
device lost or stalled, capture failure, publish refused or dropped,
VOICE_CAMERA_USER_LIMIT, logout), reconnect republishing, device and
quality restarts that keep the publication, the other devices' op 4s,
and the notices with the original's strings and the two new ones.

voice:📷:params: presets of row 21, the codec rule of row 22,
L3T3_KEY for VP9/AV1 and simulcast otherwise, the 1080p entitlement.
voice:📷:limits: the camera button of the control bar and the
voice panel (rows 2-3, 6) and the same rules in the reducer.
voice_status.self_video and the local cameraOn follow the machine;
keep_awake counts the own camera's open capture.

Outside the task's files: one call in app.rs (the reducer needs the
guilds, channels and the quality entitlement) and one arm in persist.rs
(SelectDevice saves the settings), clear_account drops the camera.

Refs #959

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_0161qMQMsCyJhjYw4gqa6e4K
Author
Owner

Merged into camera by hand. Conflicts with Camera 8 resolved: camera_keeps_display_awake counts the own voice state, the open capture and shown remote cameras; reduce_camera keeps the remote reducer; the own reducer ignores Focus/Unfocus. Clippy for the workspace and the core, app and UI tests pass on the merged tree.

Merged into `camera` by hand. Conflicts with Camera 8 resolved: `camera_keeps_display_awake` counts the own voice state, the open capture and shown remote cameras; `reduce_camera` keeps the remote reducer; the own reducer ignores `Focus`/`Unfocus`. Clippy for the workspace and the core, app and UI tests pass on the merged tree.
charles closed this pull request 2026-11-20 00:11:24 +00:00

Pull request closed

Sign in to join this conversation.
No description provided.