diff --git a/Cargo.lock b/Cargo.lock
index bf4fa058..5867e389 100644
--- a/Cargo.lock
+++ b/Cargo.lock
@@ -4694,6 +4694,7 @@ dependencies = [
"raw-window-handle",
"resvg 0.50.0",
"rune-fx",
+ "rustix 1.1.6",
"same-file",
"serde",
"tempfile",
diff --git a/README.md b/README.md
index c167c06d..5fb33f92 100644
--- a/README.md
+++ b/README.md
@@ -32,7 +32,7 @@ cargo run --release -p moq-studio --features capture,openh264 -- \
- `show.toml` is the scene collection. If it does not exist yet,
[guided setup](#first-launch) proposes one and creates it. Changes are saved
to it a second after you stop editing, with no save step.
-- `--recordings
` is where recordings are saved, by default beside
+- `--recordings ` is where recordings and clips are saved, by default beside
`show.toml`.
- Without `--connect`, the studio composes, previews, and records but
publishes nothing, and broadcast sources stay offline.
@@ -141,9 +141,9 @@ macOS the system's buttons and edges stay. It holds, from the left:
- The health dot, the stream's worst grade at a glance. Click it for each
relay, who is watching, the encoder, and each problem, and **Details** for
the [Health](#health) window. It reads **Not live** without `--connect`.
-- Record, which starts or stops a [recording](#recording) with REVIEW's
- picks. Its dot pulses while recording, and says for how long under the
- pointer.
+- Record, which starts or stops a [recording](#recording) from any page, with
+ the picks in Settings' Recording tab. Its dot pulses while recording, with
+ how long it has been recording beside it.
- The live control: **LIVE** and how long the studio has been live, with
`--connect`, or **NOT LIVE** without it. The studio goes live at launch,
so it starts and ends nothing yet.
@@ -184,7 +184,7 @@ The **strip** holds:
| LIVE | Watch the program while on air, and TAKE or AUTO a cued scene. |
| BUILD | Edit the scene on program, or the one open off air, shown in the middle, with its layers and what can be added on the left and the inspector on the right (see [BUILD](#build)). |
| MIX | Add, rename, reorder, and remove audio scenes, pick the audio scene on program and the one to listen to and on which output, set each sound's gain, pan, mute, and delay, and send each sound and audio scene into audio scenes, with a meter on every one. The program shows small in the strip's place for the sound. |
-| REVIEW | Replay the last moments of the program or a source in a replay source, slowed down if you like, or save them as a clip (see [Replay](#replay)), and start and stop recording and pick the picture and the audio scene it records (see [Recording](#recording)), beside the program. |
+| REVIEW | Pick a stretch of the last 30 seconds of the program or a source from a strip of its pictures, and replay it in a replay source, slowed down if you like, or save it as a clip (see [Replay](#replay)). Beside it, this show's recordings and clips as cards with their length and size, one repaired after a crash marked so, and **Open the folder**. The program's card is the live picture. |
The layout follows the program's shape and the window's size, giving the
picture the most room it can. A landscape program sits above the strip; a
@@ -297,6 +297,7 @@ the [hotkeys](#hotkeys), not in the scene file.
| Tab | Use it to |
| --- | --- |
| Show | Set the canvas size and frame rate and each scene's size, see the broadcast path, whether the program is encoding, the encoder sessions open, and the encoder work of the program, the recording, and each published scene, and turn the virtual camera of the program or of each published scene on. |
+| Recording | See and open the recordings folder, and pick the picture and the audio scene a recording holds, and whether each source records a file of its own too (see [Recording](#recording)). |
| Hotkeys | Bind keys to the panic key, TAKE, AUTO, Studio mode, replay, save a clip, start or stop recording, and take or cue each scene, and clear them (see [Hotkeys](#hotkeys)). |
| Effects | Pick how the window's [effects](#effects) move. |
| Advanced | See the sources, scenes, and audio scenes as nodes, wired left to right to what draws or holds them, and wire them there (see [Scene graph](#scene-graph)). |
@@ -503,7 +504,7 @@ each other audio scene. A source added from BUILD's Add, or
pasted, is sent to the audio scene on program, so it is heard at once.
**On program** picks the audio scene the broadcast carries, and switching
it, or editing an audio scene, never drops or repeats audio. A recording holds
-the audio scene on program unless REVIEW picks another, such as one
+the audio scene on program unless Settings' Recording tab picks another, such as one
keeping music the stream leaves out, and each published scene carries the one
on program unless BUILD's inspector picks another beside its **Publish** switch;
switching either while it runs never drops or repeats audio either. The audio
@@ -1143,7 +1144,7 @@ placed, and so does every audio scene's mix. The studio draws it only as
viewers will: over the program, on every page and in the program's
virtual camera, so both show what viewers see. It goes over every other layer of its scene, and over the always-on-top layers,
however the scene stacks it. Recordings hold the program as published,
-without it, and recording **each source too** gives a published camera,
+without it, and recording **Each source too** gives a published camera,
display, window, or microphone a file of its own. Published and recorded
scenes, and a scene that shows the program, leave it out too. While viewers read its track, it claims its bitrate of the connection beside the program's, and its video encodes at what the connection grants it. Its track carries one rendition, the
plain capture before any filter or gain, and encodes for as long as it is
@@ -1228,14 +1229,14 @@ once `moq play` plays layers.
### Recording
-**Start recording** on REVIEW, or record in the title bar, saves the program at the canvas size,
-or the scene picked beside it at its own size,
+The record button in the title bar, on any page, saves the program at the
+canvas size, or the scene picked in Settings' Recording tab at its own size,
to `.mp4` in the `--recordings` directory,
live or not. The recording has an encoder of its own, opened only while it
records, at full quality whatever the uplink grants the live stream, as OBS's
advanced output mode records apart from streaming. It costs one more encode
session and one more copy of each program frame while recording. With
-**each source too**, every camera, display, window, microphone, and system
+**Each source too** in Settings' Recording tab, every camera, display, window, microphone, and system
audio records its own track into a file of its own beside it,
`.mp4`, holding the capture before
any filter, or the sound before its gain and mute; a source being recorded
@@ -1258,7 +1259,7 @@ program and local sources are read from the studio's own broadcasts, never what
the relay serves, so a recording starts and stops without touching the live
stream. The audio scene it holds is
encoded a second time for it while recording: the one on program, so the file
-holds what viewers hear, or the one REVIEW picks, which viewers never
+holds what viewers hear, or the one Settings' Recording tab picks, which viewers never
can. Without `--connect`, only the
recording's encoder encodes the program.
@@ -1275,7 +1276,7 @@ beside it, numbered if a file already has that name, a regular MP4 of
everything the file holds up to its last complete fragment, leaves the
original untouched, and removes the marker, so the file is repaired
only once. The repair runs in the background and appears at the top of the
-Health window and in the log. A file another studio is still recording into the
+Health window and in the log, and REVIEW marks its card **Repaired after a crash**. A file another studio is still recording into the
same directory is left alone.
### Source frames
@@ -1303,8 +1304,10 @@ which its key takes, or cues in Studio mode, as its pad does; the tab says
which. Press **Bind**, then the key with any modifiers; Escape, or leaving
the window or the tab, cancels. Every action starts unbound, so no key a game
uses is taken unasked, and a key bound to one action is refused for another
-until it is cleared there. Replay, Save clip, and a recording use REVIEW's
-picks.
+until it is cleared there. Replay and Save clip use REVIEW's picks, but take
+the last seconds as long as the stretch picked there, so a key pressed from
+another page acts on what just happened, as the clip button beside the panic
+key does; a recording uses Settings' Recording tab.
The key pressed is the key that fires, wherever it sits, on any keyboard layout
and after a layout change: the tab names it as the layout printed it when it
@@ -1362,19 +1365,27 @@ and on Linux the desktop's, through its Settings portal.
## Replay
Add a `replay` source and place it like any other, such as full screen in a
-scene of its own. On REVIEW, pick the program or a source, a length
-up to 30 seconds, and a speed of 100%, 50%, or 25%, then **Replay** plays that
-many seconds up to the click in the replay source, which is transparent before
-and after. Take its scene to put it on program. Sound replays only at
-100%, through the replay source's strip on MIX, so a replay of a
-microphone or system audio, which has only sound, plays only at 100%. A new
-replay cuts
-off the one playing, and a stretch the source was offline or paused replays
-as the gap it was.
-
-**Save clip** writes the same seconds, in real time, beside the scene file as a
-regular MP4: `show-clip-1.mp4` for `show.toml`, then `show-clip-2.mp4`, and so
-on. Nothing is re-encoded, so a clip starts at the keyframe before those
+scene of its own. On REVIEW, pick what to replay, the program or a source, by
+its card, and a speed of 100%, 50%, or 25%. The strip shows the last 30
+seconds of what is picked, a picture each time its track starts a group,
+which is each keyframe. Drag the amber handles to pick any stretch of it,
+and click or drag elsewhere on the strip to move the scrub head: the large
+picture is the one under the head. With the right handle at the strip's right
+edge, the stretch is the last that many seconds up to the click; dragged
+left of it, the stretch stays on the moments picked as time goes on, until it
+ages out of the 30 seconds. **Replay** plays the stretch in the replay source,
+which is transparent before and after; with more than one replay source,
+pick which one under the speed. Take its scene to put it on program.
+Sound replays only at 100%, through the replay source's strip on MIX, so a
+replay of a microphone or system audio, which has only sound, plays only at
+100%. A new replay cuts off the one playing, and a stretch the source was
+offline or paused replays as the gap it was. When Replay or Save clip cannot
+act, such as off air with no relay or for a source with no past, it says why
+in place of what it would do.
+
+**Save clip** writes the same stretch, in real time, into the recordings
+folder as a regular MP4: `show-clip-1.mp4` for `show.toml`, then
+`show-clip-2.mp4`, and so on. Nothing is re-encoded, so a clip starts at the keyframe before those
seconds, up to one keyframe interval earlier. It shows nothing after them, so
video with B-frames can end early: the pictures shown before the end that refer
to one shown after it are left out, along with everything decoded after that
diff --git a/quest/m0/ux/review.md b/quest/m0/ux/review.md
deleted file mode 100644
index 1e2ee4d2..00000000
--- a/quest/m0/ux/review.md
+++ /dev/null
@@ -1,42 +0,0 @@
-# [M] The REVIEW page
-
-## Goal
-
-The REVIEW page of [`mock/review.html`](/quest/m0/ux/mock/review.html)
-replaces the Replay panel and the recording half of the Output panel: the
-last 30 seconds as a strip to pick a stretch from, what to replay (the
-program or a source), the speed, and Replay and Save clip; beside it, this
-show's recordings and clips as cards with a picture, a length, and a size,
-one that was repaired after a crash marked as such, and a button that opens
-their folder.
-
-The bottom strip stays, and the program's card in "replay what" is the live
-picture, so looking back never hides what is on air.
-
-The title bar's record button starts and stops a recording from any page and
-shows its clock while recording.
-
-## Plan
-
-Recording and repair behave as `README.md` has them; this is their place and
-look. Recommended, not decided: Replay and Save clip take any stretch of the
-last 30 seconds, picked with two handles, where today they take the last N
-seconds up to the click. The track already holds the 30 seconds. The
-alternative pins the right handle to now. The strip's pictures are frames the program's track
-already keeps for late viewers, decoded at a low rate while the page is
-shown, and nothing records in the background for it.
-
-- The large picture is the frame under the scrub head, so the choice is
- seen before it is replayed. The program's card keeps its ON AIR tag, so the
- live picture never leaves the screen.
-- A replay that cannot play says why where the button is: off air with no
- relay, a source with no past, a speed that drops the sound.
-- A recording's card comes from the files in the recordings folder that
- carry this show's name. Reading their length and a first picture must not
- hold up the page.
-- Which picture and audio scene a recording holds are Settings, Recording.
-
-[Markers and clips](/quest/m2/markers.md) later adds markers to the strip
-and chapters to a recording.
-
-Human check: scrubbing and picking a stretch by feel.
diff --git a/quest/m0/ux/try-review.md b/quest/m0/ux/try-review.md
new file mode 100644
index 00000000..ac83c985
--- /dev/null
+++ b/quest/m0/ux/try-review.md
@@ -0,0 +1,30 @@
+# [XS] Try the REVIEW page
+
+## Goal
+
+The maintainer tries the REVIEW page on their own machine and either signs it
+off or files what they find as quests: what the epic's
+[What a person must check](/quest/m0/ux/README.md) asks of it, which no
+headless run exercises.
+
+## Plan
+
+The REVIEW page is on `main` (`cargo run -p moq-studio --features capture`).
+What to try, on a show going live to a relay:
+
+- **Feel:** scrubbing the strip's head and dragging the two amber handles to
+ pick a stretch, then Replay and Save clip; whether the strip keeps up.
+- **Look:** whether the page reads like its
+ [mock-up](/quest/m0/ux/mock/review-review.webp).
+- **Readability:** the strip's ruler and AIR/AGO labels, and the cards'
+ length, size, and age, at a normal window size.
+
+An agent then turns each finding into a quest, or an edit to the quest that
+owns that part of the page, and deletes this one.
+
+## Waiting
+
+- Maintainer: try the REVIEW page as the Plan lists and report what to change,
+ or that nothing needs to. An agent cannot judge feel or taste; a kittest run
+ and `just shots` already cover the clicks and the layout. Check: a comment
+ or quest records the result.
diff --git a/quest/m2/markers.md b/quest/m2/markers.md
index dfb3535b..73648af3 100644
--- a/quest/m2/markers.md
+++ b/quest/m2/markers.md
@@ -17,7 +17,3 @@ Planned 2026-11-09 (maintainer, /quest-plan), and held for later: ✅ m2
same keyframe limits apply.
- Chapters are written when a recording becomes a regular MP4.
- Marker is a hotkey action.
-
-## Required
-
-- [The REVIEW page](/quest/m0/ux/review.md) - the strip and the list markers appear on
diff --git a/quest/m3/card-pictures.md b/quest/m3/card-pictures.md
new file mode 100644
index 00000000..b2b11fad
--- /dev/null
+++ b/quest/m3/card-pictures.md
@@ -0,0 +1,24 @@
+# [S] Pictures on REVIEW's recording and clip cards
+
+## Goal
+
+Each finished recording's and clip's card on the REVIEW page of
+[`mock/review.html`](/quest/m0/ux/mock/review.html) shows the file's first
+picture, where it shows a placeholder tile today.
+
+## Plan
+
+Decided 2026-11-15 (agent's recommendation on moq-dev/studio#177, which the
+maintainer kept when picking it to merge): ✅ decode through moq-mux's regular MP4 import
+(rejected: reading the first sample here with `mp4-atom`, since demuxing
+belongs in moq; dropping the pictures from the mock-up).
+
+The picture is the file's first video sample, imported through moq-mux and
+decoded small once per file in the shelf's background listing
+(`rs/moq-studio/src/shelf.rs`), as the strip decodes keyframes
+(`rs/moq-studio/src/past.rs`). A recording under way already shows the live
+picture. The placeholder is painted in `rs/moq-studio/src/ui/review.rs`.
+
+## Required
+
+- [MP4 import pinned](/quest/m3/pin-mp4-import.md) - brings moq-mux's regular MP4 import into the `moq` submodule
diff --git a/quest/m3/pin-mp4-import.md b/quest/m3/pin-mp4-import.md
new file mode 100644
index 00000000..18579c6c
--- /dev/null
+++ b/quest/m3/pin-mp4-import.md
@@ -0,0 +1,22 @@
+# [XS] moq-mux's regular MP4 import is pinned
+
+## Goal
+
+The `moq` submodule includes moq-mux's import of a regular, non-fragmented
+MP4, from
+[moq-mux imports a regular MP4](https://github.com/moq-dev/moq/blob/main/quest/m3/mp4-import.md).
+
+## Plan
+
+Once the wait clears, advance it with `just upgrade-moq` in its own PR,
+fixing whatever the new API breaks here.
+
+Here in m3 because the upstream quest is in moq's m3 (maintainer, 2026-11-05);
+move both up together if the studio needs it sooner.
+
+## Waiting
+
+- moq-dev/moq: the upstream quest above lands. Check: that quest's PR has
+ merged on moq's `main`, deleting its file, and `ContainerFormat` in
+ `rs/moq-mux/src/import/format.rs` offers regular MP4. A quest file that
+ moved, or went away without its work landing, does not count.
diff --git a/rs/moq-studio/Cargo.toml b/rs/moq-studio/Cargo.toml
index a6f3b012..f11020a5 100644
--- a/rs/moq-studio/Cargo.toml
+++ b/rs/moq-studio/Cargo.toml
@@ -68,6 +68,9 @@ moq-scene = { workspace = true }
moq-stats = { workspace = true, features = ["async"] }
moq-tokio = { workspace = true, default-features = false, features = ["net"] }
moq-video = { workspace = true }
+# A recording's length, from its movie header; the version moq-mux writes it
+# with.
+mp4-atom = "0.17.0"
pollster = { workspace = true }
# The join link's QR code. No dependencies of its own.
qrcodegen = "1.8"
@@ -110,6 +113,10 @@ raw-window-handle = "0.6"
# tells a held key's repeats from new presses.
x11rb = { version = "0.13", features = ["xkb"] }
+[target.'cfg(unix)'.dependencies]
+# The room left on the recordings folder's disk. moq-scene's release.
+rustix = { version = "1", features = ["fs"] }
+
[target.'cfg(any(target_os = "macos", windows))'.dependencies]
# System-wide hotkeys on macOS and Windows; X11 grabs keys itself, and Wayland
# goes through the GlobalShortcuts portal.
@@ -123,8 +130,9 @@ objc2-app-kit = { version = "0.3", default-features = false, features = ["std",
[target.'cfg(windows)'.dependencies]
# Which virtual key the foreground window's layout puts on each key, so a
# hotkey registers the key pressed, and whether the system asks apps to
-# reduce motion, for the effects.
-windows-sys = { version = "0.61", features = ["Win32_UI_Input_KeyboardAndMouse", "Win32_UI_WindowsAndMessaging"] }
+# reduce motion, for the effects, and the room left on the recordings folder's
+# disk.
+windows-sys = { version = "0.61", features = ["Win32_Storage_FileSystem", "Win32_UI_Input_KeyboardAndMouse", "Win32_UI_WindowsAndMessaging"] }
[build-dependencies]
# Rasterizes the app icon's SVG for the window. No text or embedded images, so
@@ -138,8 +146,6 @@ egui_kittest = { version = "0.36", features = ["eframe", "wgpu"] }
image = { version = "0.25", default-features = false, features = ["png"] }
# A clock that moves wall time too, which renewed tokens' expiries read.
kio = { workspace = true, features = ["manual"] }
-# Reads a saved clip's timeline back; the version moq-mux writes it with.
-mp4-atom = "0.17.0"
# The auth server a test relay verifies guest tokens with.
moq-auth = { workspace = true, features = ["serve"] }
moq-relay = { workspace = true, features = ["test-support"] }
diff --git a/rs/moq-studio/assets/icons/download.svg b/rs/moq-studio/assets/icons/download.svg
new file mode 100644
index 00000000..6472b987
--- /dev/null
+++ b/rs/moq-studio/assets/icons/download.svg
@@ -0,0 +1,16 @@
+
+
diff --git a/rs/moq-studio/assets/icons/folder.svg b/rs/moq-studio/assets/icons/folder.svg
new file mode 100644
index 00000000..7e5cb44b
--- /dev/null
+++ b/rs/moq-studio/assets/icons/folder.svg
@@ -0,0 +1,14 @@
+
+
diff --git a/rs/moq-studio/src/controls.rs b/rs/moq-studio/src/controls.rs
index 73fa847d..bee7e2a5 100644
--- a/rs/moq-studio/src/controls.rs
+++ b/rs/moq-studio/src/controls.rs
@@ -24,9 +24,9 @@ pub enum Action {
Scene(String),
/// Turn Studio mode on or off.
StudioMode,
- /// Play the recent past the Replay panel picks in its replay source.
+ /// Play the stretch of the recent past REVIEW picks in its replay source.
Replay,
- /// Save the recent past the Replay panel picks as a clip.
+ /// Save the stretch of the recent past REVIEW picks as a clip.
SaveClip,
/// Start recording, or stop the recording under way.
Record,
@@ -77,7 +77,7 @@ impl std::fmt::Display for Action {
pub struct Controls {
pub engine: Arc,
runtime: tokio::runtime::Handle,
- /// The Replay panel's picks, which a replay or clip from a hotkey takes too.
+ /// REVIEW's replay picks, which a replay or clip from a hotkey takes too.
pub replay: Mutex,
/// Whether the next recording gives each source a file of its own too.
pub record_sources: AtomicBool,
@@ -88,10 +88,10 @@ pub struct Controls {
fired: Arc>>>,
}
-/// The Replay panel's choices, and how the last replay or clip went.
+/// REVIEW's replay choices, and how the last replay or clip went.
pub struct Replay {
pub of: replay::Of,
- pub length: std::time::Duration,
+ pub stretch: replay::Stretch,
pub speed: f32,
/// The replay source a replay plays in.
pub into: Option,
@@ -103,7 +103,7 @@ impl Default for Replay {
fn default() -> Self {
Self {
of: replay::Of::Program,
- length: replay::LENGTHS[1],
+ stretch: replay::Stretch::default(),
speed: replay::SPEEDS[0],
into: None,
outcome: Arc::default(),
@@ -192,15 +192,15 @@ impl Controls {
}
}
- /// Play the Replay panel's pick in its replay source, or save it as a
+ /// Play REVIEW's pick in its replay source, or save it as a
/// clip. Copied now, without waiting on anything, so the span ends here and
/// replays apply in the order they were asked for. How it went shows in
- /// the Replay panel, and in the status bar too when a hotkey `pressed` it,
+ /// REVIEW, and in the status bar too when a hotkey `pressed` it,
/// since the panel may be hidden.
fn replay(&self, play: bool, pressed: bool) -> anyhow::Result {
let replay = self.replay.lock().unwrap();
let action = if play { Action::Replay } else { Action::SaveClip };
- let taken = self.take(&replay, play);
+ let taken = self.take(&replay, play, pressed);
let message = taken
.as_ref()
.map(|(message, _)| message.clone())
@@ -225,16 +225,24 @@ impl Controls {
}
/// What a replay or clip does at once, and the save a clip still runs.
+ /// One `pressed` from outside REVIEW's own buttons, by a hotkey or the
+ /// shell's clip button, takes the last stretch as long as the one picked.
fn take(
&self,
replay: &Replay,
play: bool,
+ pressed: bool,
) -> anyhow::Result<(String, Option> + use<>>)> {
let into = match play {
true => Some(self.replay_source(replay.into.as_deref())?),
false => None,
};
- let take = replay::take(&self.engine, &replay.of, replay.length, into.is_some())?;
+ let stretch = match pressed {
+ true => replay.stretch.last(),
+ false => replay.stretch,
+ };
+ let (ago, length) = stretch.span(kio::clock::Instant::now())?;
+ let take = replay::take(&self.engine, &replay.of, ago, length, into.is_some())?;
let of = replay.of.clone();
if let Some(into) = into {
replay::play(&self.engine, take, replay.speed, &into)?;
@@ -243,7 +251,8 @@ impl Controls {
let saving = format!("saving {of}");
let engine = self.engine.clone();
let save = async move {
- let path = replay::save(take, engine.autosave.path()).await?;
+ let recorder = &engine.recorder;
+ let path = replay::save(take, recorder.dir(), recorder.show()).await?;
Ok(format!("saved {of} to {}", path.display()))
};
Ok((saving, Some(save)))
diff --git a/rs/moq-studio/src/engine.rs b/rs/moq-studio/src/engine.rs
index 390e6d81..3ab8d18b 100644
--- a/rs/moq-studio/src/engine.rs
+++ b/rs/moq-studio/src/engine.rs
@@ -5096,15 +5096,45 @@ mod tests {
assert!(engine.stats.error().is_none());
// The program's recent past saves as a clip, from the groups it holds.
- let take = crate::replay::take(&engine, &crate::replay::Of::Program, Duration::from_secs(1), false)
+ let of = crate::replay::Of::Program;
+ let take = crate::replay::take(&engine, &of, Duration::ZERO, Duration::from_secs(1), false)
.expect("the program's past");
assert!(take.video.is_some(), "the canvas size holds video");
- let clip = kio::clock::timeout(TIMEOUT, crate::replay::save(take, engine.autosave.path()))
+ let (folder, show) = (engine.recorder.dir(), engine.recorder.show());
+ let clip = kio::clock::timeout(TIMEOUT, crate::replay::save(take, folder, show))
.await
.expect("the clip saves")
.expect("a clip");
assert_eq!(clip, dir.path().join("show-clip-1.mp4"));
+ // REVIEW's strip decodes the keyframe each held group opens with, small,
+ // and it is the picture composed: the red canvas.
+ let view = tokio::task::spawn_blocking({
+ let engine = engine.clone();
+ move || crate::past::sample(&engine, &of)
+ })
+ .await
+ .unwrap();
+ let held = view.held.expect("sampled").expect("the program's past");
+ assert!(held.video);
+ assert!(!view.pictures.is_empty(), "a keyframe of the past");
+ for picture in &view.pictures {
+ assert_eq!(picture.size[0], 480, "decoded small");
+ assert!(held.oldest <= picture.at && picture.at <= kio::clock::Instant::now());
+ let middle = (picture.size[1] / 2 * picture.size[0] + picture.size[0] / 2) * 4;
+ let [r, g, b, _] = picture.rgba[middle..middle + 4] else {
+ unreachable!()
+ };
+ assert!(r > 200 && g < 60 && b < 60, "red, not {r} {g} {b}");
+ }
+ let times: Vec<_> = view.pictures.iter().map(|picture| picture.at).collect();
+ assert!(times.is_sorted(), "oldest first");
+ // And its sound, a packet at a time: the program's mix, silent here.
+ let sound = view.sound.expect("the program's sound");
+ assert!(sound.len() > 10, "{} packets", sound.len());
+ assert!(sound.iter().all(|(_, peak)| (0.0..=1.0).contains(peak)));
+ assert!(sound.iter().map(|(at, _)| *at).is_sorted(), "oldest first");
+
// Quitting ends the program's video and audio cleanly once the encoders
// published what they were handed, then its catalog in each format, and
// closes the relay session only once the relay has them, rather than
diff --git a/rs/moq-studio/src/kit/icon.rs b/rs/moq-studio/src/kit/icon.rs
index 02869bf6..8074423f 100644
--- a/rs/moq-studio/src/kit/icon.rs
+++ b/rs/moq-studio/src/kit/icon.rs
@@ -61,12 +61,15 @@ pub enum Icon {
Broadcast,
Scene,
Replay,
+ Folder,
+ Save,
+ Repaired,
}
impl Icon {
/// Every icon, for the gallery.
#[cfg(test)]
- pub const ALL: [Self; 50] = [
+ pub const ALL: [Self; 53] = [
Self::Undo,
Self::Redo,
Self::Settings,
@@ -117,6 +120,9 @@ impl Icon {
Self::Broadcast,
Self::Scene,
Self::Replay,
+ Self::Folder,
+ Self::Save,
+ Self::Repaired,
];
fn source(self) -> ImageSource<'static> {
@@ -171,6 +177,9 @@ impl Icon {
Self::Broadcast => include_image!("../../assets/icons/radio-tower.svg"),
Self::Scene => include_image!("../../assets/icons/layers.svg"),
Self::Replay => include_image!("../../assets/icons/rewind.svg"),
+ Self::Folder => include_image!("../../assets/icons/folder.svg"),
+ Self::Save => include_image!("../../assets/icons/download.svg"),
+ Self::Repaired => include_image!("../../assets/icons/shield.svg"),
}
}
diff --git a/rs/moq-studio/src/main.rs b/rs/moq-studio/src/main.rs
index d79966e9..30c6a29c 100644
--- a/rs/moq-studio/src/main.rs
+++ b/rs/moq-studio/src/main.rs
@@ -27,9 +27,11 @@ mod interact;
mod kit;
mod ladder;
mod mix;
+mod past;
mod record;
mod replay;
mod setup;
+mod shelf;
#[cfg(test)]
mod shots;
mod snap;
@@ -67,7 +69,7 @@ pub struct Config {
#[usage(long)]
pub on_demand: bool,
- /// The directory recordings are saved in. Defaults to the scene file's.
+ /// The directory recordings and clips are saved in. Defaults to the scene file's.
#[usage(long, value_hint = usage_rs::ValueHint::DirPath)]
pub recordings: Option,
diff --git a/rs/moq-studio/src/past.rs b/rs/moq-studio/src/past.rs
new file mode 100644
index 00000000..5753a688
--- /dev/null
+++ b/rs/moq-studio/src/past.rs
@@ -0,0 +1,438 @@
+//! The last 30 seconds of what REVIEW replays, as pictures to scrub.
+//!
+//! Nothing records for it. About once a second while the page is shown, a
+//! thread of its own takes the window the way a replay does, from the groups
+//! the tracks keep for late viewers anyway, and decodes the keyframe each
+//! group opens with, small and on the CPU, once per keyframe. A picture is
+//! the moment its group starts, so the strip is as fine as the track's
+//! keyframe interval. The sound is decoded too, once per group, down to the
+//! loudest sample of each packet.
+
+use std::collections::BTreeMap;
+use std::sync::atomic::{AtomicU64, Ordering};
+use std::sync::{Arc, Condvar, Mutex};
+use std::task::Poll;
+use std::time::Duration;
+
+use anyhow::Context;
+use kio::clock::Instant;
+use moq_mux::container::Container as _;
+
+use crate::engine::Engine;
+use crate::replay::{self, Of};
+
+/// How often the window is taken again while it is watched.
+const PERIOD: Duration = Duration::from_secs(1);
+
+/// How long the thread keeps going once the page stops asking.
+const LINGER: Duration = Duration::from_secs(2);
+
+/// The last [`Picture::id`] handed out, shared by every worker the page
+/// starts, since the window keeps textures across them.
+static LAST_ID: AtomicU64 = AtomicU64::new(0);
+
+/// How wide a picture is decoded: enough for the page's large picture.
+const WIDTH: u32 = 480;
+
+/// The recent past of one thing REVIEW replays, kept fresh while watched.
+pub struct Past {
+ shared: Arc,
+}
+
+struct Shared {
+ engine: Arc,
+ watch: Mutex,
+ /// Wakes the thread early, when what it watches changes.
+ wake: Condvar,
+}
+
+struct Watch {
+ of: Of,
+ /// When the page last asked, after which the thread lingers and stops.
+ seen: Instant,
+ running: bool,
+ view: Arc,
+}
+
+/// What the window held when last taken.
+pub struct View {
+ /// What it is of, which lags a change of pick by a sample.
+ pub of: Of,
+ /// The keyframe each group opens with, oldest first.
+ pub pictures: Vec>,
+ /// The loudest sample of each packet of sound, from 0 to 1, oldest first,
+ /// or why the sound could not be read.
+ pub sound: Result, String>,
+ /// How far back it reaches, or why there is nothing to replay.
+ pub held: Option>,
+}
+
+impl Default for View {
+ fn default() -> Self {
+ Self {
+ of: Of::Program,
+ pictures: Vec::new(),
+ sound: Ok(Vec::new()),
+ held: None,
+ }
+ }
+}
+
+/// How much of the window a sample found.
+#[derive(Clone, Copy, Debug)]
+pub struct Held {
+ /// The oldest moment held.
+ pub oldest: Instant,
+ /// Whether it holds pictures, rather than sound alone.
+ pub video: bool,
+}
+
+/// A decoded keyframe.
+pub struct Picture {
+ /// Unique for as long as the studio runs, so the window uploads it once.
+ pub id: u64,
+ /// When it was shown.
+ pub at: Instant,
+ pub size: [usize; 2],
+ /// Tightly packed RGBA.
+ pub rgba: Vec,
+}
+
+impl Past {
+ pub fn new(engine: Arc) -> Self {
+ let watch = Watch {
+ of: Of::Program,
+ seen: Instant::now(),
+ running: false,
+ view: Arc::default(),
+ };
+ Self {
+ shared: Arc::new(Shared {
+ engine,
+ watch: Mutex::new(watch),
+ wake: Condvar::new(),
+ }),
+ }
+ }
+
+ /// Keep the past of `of` fresh, for a frame that shows it, and what the
+ /// last sample found.
+ pub fn watch(&self, of: &Of) -> Arc {
+ let mut watch = self.shared.watch.lock().unwrap();
+ watch.seen = Instant::now();
+ if watch.of != *of {
+ watch.of = of.clone();
+ self.shared.wake.notify_all();
+ }
+ if !watch.running {
+ watch.running = true;
+ let shared = self.shared.clone();
+ let spawned = std::thread::Builder::new()
+ .name("review-past".into())
+ .spawn(move || run(&shared));
+ if let Err(err) = spawned {
+ watch.running = false;
+ watch.view = Arc::new(View {
+ of: of.clone(),
+ held: Some(Err(format!("cannot start the strip's decoder: {err}"))),
+ ..View::default()
+ });
+ }
+ }
+ watch.view.clone()
+ }
+
+ /// Show `view` as if sampled, for the window's views.
+ #[cfg(test)]
+ pub fn seed(&self, view: View) {
+ let mut watch = self.shared.watch.lock().unwrap();
+ // A thread that runs would replace it.
+ watch.running = true;
+ watch.of = view.of.clone();
+ watch.view = Arc::new(view);
+ }
+}
+
+/// Take the window of `of` once, on a decoder of its own, as the thread does.
+#[cfg(test)]
+pub fn sample(engine: &Engine, of: &Of) -> View {
+ Decoding::default().sample(engine, of)
+}
+
+/// Take the window about once a [`PERIOD`] while watched.
+fn run(shared: &Shared) {
+ let mut decoding = Decoding::default();
+ let mut watch = shared.watch.lock().unwrap();
+ loop {
+ if watch.seen.elapsed() > LINGER {
+ watch.running = false;
+ return;
+ }
+ let of = watch.of.clone();
+ drop(watch);
+ let view = decoding.sample(&shared.engine, &of);
+ watch = shared.watch.lock().unwrap();
+ watch.view = Arc::new(view);
+ if watch.of == of {
+ watch = shared.wake.wait_timeout(watch, PERIOD).unwrap().0;
+ }
+ }
+}
+
+/// The decoder and the pictures already decoded, of one rendition.
+#[derive(Default)]
+struct Decoding {
+ /// What they are of: the pick, and the rendition's name and config.
+ key: Option<(Of, String, hang::catalog::VideoConfig)>,
+ decoder: Option,
+ /// By the keyframe's timestamp, in microseconds on its broadcast's timeline.
+ pictures: BTreeMap>,
+ /// The same for the sound: what it is of, its decoder, and each group's
+ /// peaks by the group's sequence.
+ sound_key: Option<(Of, String, hang::catalog::AudioConfig)>,
+ sound_decoder: Option,
+ peaks: BTreeMap>,
+}
+
+impl Decoding {
+ fn sample(&mut self, engine: &Engine, of: &Of) -> View {
+ let mut view = View {
+ of: of.clone(),
+ ..View::default()
+ };
+ let now = Instant::now();
+ let take = match replay::take(engine, of, Duration::ZERO, replay::WINDOW, true) {
+ Ok(take) => take,
+ Err(err) => {
+ self.reset();
+ view.held = Some(Err(format!("{err:#}")));
+ return view;
+ }
+ };
+ // The moment a timestamp of the take's broadcast was shown.
+ let end = Duration::from(take.end);
+ let at = |timestamp: moq_net::Timestamp| now.saturating_sub(end.saturating_sub(Duration::from(timestamp)));
+ let broadcast = take.consume();
+ let mut oldest = None;
+ if let Some((name, config)) = &take.audio {
+ view.sound = self
+ .sound(&broadcast, of, name, config, &at)
+ .map_err(|err| format!("{err:#}"));
+ oldest = view
+ .sound
+ .as_ref()
+ .ok()
+ .and_then(|sound| sound.first())
+ .map(|(at, _)| *at);
+ }
+ if let Some((name, config)) = &take.video {
+ match self.pictures(&broadcast, of, name, config, &at) {
+ Ok(pictures) => view.pictures = pictures,
+ Err(err) => {
+ view.held = Some(Err(format!("{err:#}")));
+ return view;
+ }
+ }
+ let first = view.pictures.first().map(|picture| picture.at);
+ oldest = oldest.into_iter().chain(first).min();
+ }
+ view.held = Some(Ok(Held {
+ oldest: oldest.unwrap_or(now),
+ video: take.video.is_some(),
+ }));
+ view
+ }
+
+ /// The keyframe of each group of the video `name`, decoding those not
+ /// decoded yet and letting go of those the window no longer holds.
+ fn pictures(
+ &mut self,
+ broadcast: &moq_net::broadcast::Consumer,
+ of: &Of,
+ name: &str,
+ config: &hang::catalog::VideoConfig,
+ at: &impl Fn(moq_net::Timestamp) -> Instant,
+ ) -> anyhow::Result>> {
+ let key = Some((of.clone(), name.to_string(), config.clone()));
+ if self.key != key {
+ self.reset();
+ self.key = key;
+ }
+ let container = moq_mux::catalog::hang::Container::try_from(config)?;
+ let mut kept = BTreeMap::new();
+ for frame in firsts(broadcast, name, container)? {
+ let micros = frame.timestamp.as_micros();
+ let picture = match self.pictures.remove(µs) {
+ Some(picture) => picture,
+ None => {
+ let Some(rgba) = self.decode(config, &frame)? else {
+ continue;
+ };
+ let size = rgba.size();
+ Arc::new(Picture {
+ id: LAST_ID.fetch_add(1, Ordering::Relaxed) + 1,
+ at: at(frame.timestamp),
+ size: [size.width as usize, size.height as usize],
+ rgba: rgba.into_data(),
+ })
+ }
+ };
+ kept.insert(micros, picture);
+ }
+ self.pictures = kept;
+ Ok(self.pictures.values().cloned().collect())
+ }
+
+ /// Decode one keyframe on its own, small, or `None` if the decoder gave
+ /// back no picture for it.
+ fn decode(
+ &mut self,
+ config: &hang::catalog::VideoConfig,
+ frame: &moq_mux::container::Frame,
+ ) -> anyhow::Result