app: play a recording's own sound and read a pause's place from the player

The review screen carried two workarounds for rune's video player: tick
ignored the player's place while a clip was paused because the first
pause read zero, and the player was muted for good because its sound
never kept the clock, so the soundtrack came from an audio-only player
of the whole file, kept in step by keep_in_step.

Rune now holds the pause's picture and time and reads a video's sound
ahead of the clock, so the video player carries the sound of a
single-track recording itself, and tick reads the place whatever the
playback state. A recording with several tracks still cuts one player
per source, so the channels stay hearable apart; the video stays muted
and keep_in_step keeps those players with the pictures.
This commit is contained in:
vhaudiquet committed 2026-11-22 23:54:00 +01:00
1 parent 5bf262b82b
commit 5cbf284841
2 files changed
+33 -35

No files matched your search

+32 -29
View File
@@ -20,6 +20,10 @@ pub struct Review {
pub player: Option<Player>, pub player: Option<Player>,
/// The clip's audio tracks, one player each, so the channels are heard apart. /// The clip's audio tracks, one player each, so the channels are heard apart.
pub sounds: Vec<Channel>, pub sounds: Vec<Channel>,
/// The video player carries the clip's own sound: one track, or a recording made before
/// the recorder split them, so there is nothing to cut and no channel to hear apart. Off,
/// the video is muted and the cut tracks carry the sound.
pub video_sound: bool,
/// Tracks being cut out of the clip on a thread. `tick` opens their players when they land, /// Tracks being cut out of the clip on a thread. `tick` opens their players when they land,
/// so a long clip does not hold the frame while ffmpeg reads it. /// so a long clip does not hold the frame while ffmpeg reads it.
pub sound_rx: Option<Receiver<Result<Vec<std::path::PathBuf>, String>>>, pub sound_rx: Option<Receiver<Result<Vec<std::path::PathBuf>, String>>>,
@@ -54,17 +58,18 @@ pub struct Review {
} }
impl Review { impl Review {
/// The video player only draws; the audio players carry the gain and the mute.
fn mute_video(player: &Player) {
player.set_muted(true);
}
/// Set the gain from the transport bar. Sliding off zero is also how a viewer unmutes. /// Set the gain from the transport bar. Sliding off zero is also how a viewer unmutes.
pub fn set_volume(&mut self, volume: f32) { pub fn set_volume(&mut self, volume: f32) {
self.volume = volume.clamp(0.0, 1.0); self.volume = volume.clamp(0.0, 1.0);
if self.volume > 0.0 { if self.volume > 0.0 {
self.muted = false; self.muted = false;
} }
if self.video_sound
&& let Some(player) = &self.player
{
player.set_volume(self.volume);
player.set_muted(self.muted);
}
for channel in &self.sounds { for channel in &self.sounds {
channel.sound.set_volume(self.volume); channel.sound.set_volume(self.volume);
channel.sound.set_muted(!channel.heard(self.muted)); channel.sound.set_muted(!channel.heard(self.muted));
@@ -73,6 +78,11 @@ impl Review {
pub fn toggle_muted(&mut self) { pub fn toggle_muted(&mut self) {
self.muted = !self.muted; self.muted = !self.muted;
if self.video_sound
&& let Some(player) = &self.player
{
player.set_muted(self.muted);
}
for channel in &self.sounds { for channel in &self.sounds {
channel.sound.set_muted(!channel.heard(self.muted)); channel.sound.set_muted(!channel.heard(self.muted));
} }
@@ -107,13 +117,7 @@ impl Review {
let labels = self.track_labels(); let labels = self.track_labels();
if labels.len() < 2 { if labels.len() < 2 {
// One track, or a recording made before the recorder split them: the file's own // One track, or a recording made before the recorder split them: the file's own
// sound is the whole mix, and an audio player reads it as it is. // sound is the whole mix, and the video player reads it as it is.
let label = labels
.first()
.cloned()
.unwrap_or_else(|| "All audio".to_string());
let channel = self.channel(0, label, path);
self.sounds.push(channel);
return; return;
} }
let stem = self.stem(path); let stem = self.stem(path);
@@ -131,15 +135,14 @@ impl Review {
return; return;
} }
self.sound_tried = true; self.sound_tried = true;
let labels = self.track_labels(); if self.track_labels().len() < 2 {
if labels.len() < 2 { // The video player carries the whole mix itself.
self.open_sound(path);
return; return;
} }
self.channel_error = None; self.channel_error = None;
let path = path.to_string(); let path = path.to_string();
let stem = self.stem(&path); let stem = self.stem(&path);
let count = labels.len(); let count = self.track_labels().len();
let (tx, rx) = channel(); let (tx, rx) = channel();
std::thread::spawn(move || { std::thread::spawn(move || {
let _ = tx.send(crate::export::extract_tracks(&path, &stem, count)); let _ = tx.send(crate::export::extract_tracks(&path, &stem, count));
@@ -311,10 +314,6 @@ impl Review {
} }
/// One audio track of the clip, copied to a file of its own and played on its own, so the /// One audio track of the clip, copied to a file of its own and played on its own, so the
/// channels are heard apart and can be kept apart. /// channels are heard apart and can be kept apart.
/// Rune's video player asks Media Foundation for pictures and sound from one reader, and that
/// reader stamps the sound from its own clock instead of the clip's, so the sound never lines
/// up with the clock and plays silent. Audio-only players read one track each and need no
/// video, so their sound starts at zero.
pub struct Channel { pub struct Channel {
/// What the track carries, as the recorder named it. /// What the track carries, as the recorder named it.
pub label: String, pub label: String,
@@ -354,6 +353,7 @@ impl Default for Review {
sounds: Vec::new(), sounds: Vec::new(),
sound_rx: None, sound_rx: None,
sound_tried: false, sound_tried: false,
video_sound: false,
steady_at: 0.0, steady_at: 0.0,
time: 0.0, time: 0.0,
duration: 0.0, duration: 0.0,
@@ -425,15 +425,23 @@ pub fn show(app: &mut App, game: Timeline) {
app.review.sound_tried = false; app.review.sound_tried = false;
app.review.channel_error = None; app.review.channel_error = None;
app.review.steady_at = 0.0; app.review.steady_at = 0.0;
Review::mute_video(app.review.player.as_ref().expect("just set"));
// The timeline names several tracks, and cutting them is the slow part of opening a // The timeline names several tracks, and cutting them is the slow part of opening a
// recording. Start it on a thread now, while the first picture decodes. // recording. Start it on a thread now, while the first picture decodes.
let many_tracks = app let tracks = app
.review .review
.game .game
.as_ref() .as_ref()
.is_some_and(|game| game.audio_tracks.len() >= 2); .map(|game| game.audio_tracks.len())
if many_tracks { .unwrap_or_default();
// One track, or a recording made before the recorder split them: the clip's own sound is
// the whole mix, and the video player reads it as it is now that its sound keeps the
// clock. Several tracks: cut them, so the video is muted and the channels carry the sound.
app.review.video_sound = tracks < 2;
if let Some(player) = &app.review.player {
player.set_muted(app.review.muted || tracks >= 2);
player.set_volume(app.review.volume);
}
if tracks >= 2 {
app.review.request_sound(&path.to_string_lossy()); app.review.request_sound(&path.to_string_lossy());
} }
} }
@@ -507,16 +515,11 @@ fn keep_in_step(app: &mut App) {
pub fn tick(app: &mut App, tx: &mut Tx) -> bool { pub fn tick(app: &mut App, tx: &mut Tx) -> bool {
let mut changed = false; let mut changed = false;
if let Some(player) = &app.review.player { if let Some(player) = &app.review.player {
// Rune reads a layered clip's place from the compositor clock, and that clock stops with
// playback, so the first pause can read zero and send the scrubber to the start. While
// the clip is paused the place is ours: only a seek moves it.
if player.is_playing() {
let time = player.time(); let time = player.time();
if (time - app.review.time).abs() > 0.001 { if (time - app.review.time).abs() > 0.001 {
app.review.time = time; app.review.time = time;
changed = true; changed = true;
} }
}
if let Some(duration) = player.duration() if let Some(duration) = player.duration()
&& duration > 0.0 && duration > 0.0
&& (duration - app.review.duration).abs() > 0.05 && (duration - app.review.duration).abs() > 0.05
+1 -6
View File
@@ -30,8 +30,6 @@ Check: pause and ask `Player::time()`; it answers 0 while the clip sits near its
Fix: report nothing when the clip's clock has stopped, so `time()` falls back to the clip's own Fix: report nothing when the clip's clock has stopped, so `time()` falls back to the clip's own
place. place.
The app works around it in `app/src/screens/review.rs`: `tick` ignores the player's place while
the clip is paused and keeps its own.
## 3. One reader for pictures and sound stamps the sound wrong ## 3. One reader for pictures and sound stamps the sound wrong
@@ -39,9 +37,6 @@ A video player asks Media Foundation for both streams from one reader, and that
the sound from its own clock instead of the clip's. The sound then never lines up with the clock the sound from its own clock instead of the clip's. The sound then never lines up with the clock
and plays silent. and plays silent.
The app works around it in `app/src/screens/review.rs` with a second, audio-only player over the
same file, kept in step by `keep_in_step`.
## Cherry-picks on the vendored checkout ## Cherry-picks on the vendored checkout
Rune comes from `app/vendor/rune`, a checkout of `63ad0209` on branch `ported`, carrying two Rune comes from `app/vendor/rune`, a checkout of `63ad0209` on branch `ported`, carrying two
@@ -56,4 +51,4 @@ the refactors that landed since):
`app/Cargo.toml` points `rune`, `rune-kit` and `rune-notify` at the checkout's crates by path. `app/Cargo.toml` points `rune`, `rune-kit` and `rune-notify` at the checkout's crates by path.
To take a newer upstream rev: fetch in `app/vendor/rune`, rebase or re-apply the four commits To take a newer upstream rev: fetch in `app/vendor/rune`, rebase or re-apply the four commits
of `ported` on the new rev, and drop the workarounds below once the fixes arrive upstream. of `ported` on the new rev.