Skip to main content

Module recording

Module recording 

Source
Expand description

M-RECORD.0 — RecordingSession state machine + shared monotonic clock for the coordinated recording lifecycle (M-RECORD-EXPORT).

This module is pure Rust — no Tauri types, no I/O. It defines:

  • SessionStateIdle → Starting → Running → Stopping → Idle. Mirrors the per-channel MicLifecycle / ScreenLifecycle shape so the M-RECORD.2 LED renderer can reuse the same colour map.
  • StreamKind — which of the four input streams (camera, screen, microphone, system audio) a StreamHealth refers to.
  • StreamHealth — per-stream health snapshot (lifecycle + cumulative frame count + last-frame timestamp). Built fresh by M-RECORD.1’s recording_status IPC every 500 ms.
  • SessionStreams — which streams the user enabled for this session (boolean flags). Doesn’t own the actual pipelines — those stay in their existing Tauri-managed State<> handles; the session just coordinates their lifecycles.
  • RecordingSession — the orchestrator type itself. Wraps the four state pieces above into one immutable-once-started struct with a shared started_at: Instant clock used by the M-EXPORT encoder to compute per-frame PTS.
M-RECORD.0 lands the **types + state machine** only. The Tauri
`start_recording` / `stop_recording` / `recording_status` IPC and
the 500 ms event-push task that consumes this state live in
M-RECORD.1. Splitting the chunks keeps the state machine
unit-testable without Tauri's `AppHandle`.

Structs§

EncoderHandle
Live encoder + its background feed-thread cancel flag. Owned by RecordingState::encoder for the duration of a session.
PendingExport
A finished recording sitting in the scratch directory, awaiting the user’s format choice in the Save panel (M-SAVE.1). Held in RecordingState::pending_export between stop_recording and export_recording / discard_recording. Pure Rust — no Tauri / serde; the IPC-facing mirror is PendingExportView.
PendingExportView
IPC mirror of PendingExport. Carries only what the Save panel needs — never the internal scratch path.
RecordingConfig
start_recording argument. Carries which streams to enable + the per-channel picker selections + the output target. M-EXPORT.4 extends output_path / format semantics; here they’re carried through unchanged so the IPC seam doesn’t need to break later.
RecordingSession
One coordinated recording session — the orchestrator owned by RecordingState (M-RECORD.1) for the lifetime of one start → stop cycle.
RecordingState
Tauri-managed wrapper around the optional active session. Held in tauri::State so the start_recording / stop_recording / recording_status IPC commands + the 500 ms event-push task share one source of truth. Mirror of MicCaptureState / ScreenCaptureState.
RecordingStatusView
Snapshot of the active session for the recording_status IPC
RecordingSummary
Result of a successful stop_recording. Distinct from RecordingStatusView because it’s a final summary (no live state) — fields the UI uses to show the post-record toast + “Reveal in Finder” button (M-EXPORT.4).
SessionStreams
Which streams the user enabled at session-start time. Doesn’t own the actual pipeline handles — those stay in their existing Tauri-managed State<> wrappers; the session just remembers which channels to start + stop together.
StreamHealth
Per-stream health snapshot for the recording-status event push. Built fresh every 500 ms by M-RECORD.1.

Enums§

SessionState
Master state of a RecordingSession. Mirrors the per-channel MicLifecycle / ScreenLifecycle shape (and renders with the same LED colour map in M-RECORD.2).
StreamKind
Which of the four input streams a StreamHealth describes. Sent across the IPC seam so the Leptos <RecorderControls /> can colour the right LED.

Constants§

DEFAULT_AUDIO_CHANNELS 🔒
Default audio mixer channel count (stereo). Matches the EncoderConfig default + the SCK / mic worker output formats.

Statics§

NEXT_SESSION_ID 🔒
Monotonically-increasing session id. Resets per process start; the id only needs to be unique within a single app run so the recording-status event consumer can ignore stale events from a previous session.

Functions§

cfr_catchup_frames 🔒
How many video frames a constant-frame-rate stream should have emitted by elapsed (at frame_interval), minus those already pushed — i.e. the number to push this tick to keep the encoder’s frame count locked to wall-clock. The live encoder timestamps frames by count at a fixed rate, so a compose pump that can’t sustain that rate must duplicate the last frame to fill the deficit, or the recording plays fast. Bounded by max_burst so a long stall can’t emit an unbounded catch-up burst.
feed_real_capture 🔒
Real-capture feed loop (M-PIX.6) — pulls composed frames from crate::recording_compose::RecordingCompose + mixed audio from the shared SharedAudioMixer until cancel fires.
feed_test_pattern 🔒
Test-pattern feed loop running on a dedicated thread. Pushes a solid colour BGRA frame at the encoder’s framerate (and a chunk of silence at the audio sample rate) until cancel fires.
new_audio_mixer
Construct a fresh shared mixer with the default channel count.
new_frame_slot
Construct a fresh frame slot — Arc<Mutex<None>>.

Type Aliases§

FrameSlot
Latest-frame-wins slot the capture pipelines write into and the encoder feed thread reads from (M-PIX.0). None until the first frame; the capture pipeline overwrites with each new frame; the encoder reads (cloned) at render time.
SharedAudioMixer
Shared audio mixer (M-PIX.0) the mic worker + SCK audio delegate push samples into, and the encoder feed thread drains via AudioMixer::pull().