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:
1 parent
5bf262b82b
commit
5cbf284841
2 files changed
+33
-35
No files matched your search
+32
-29
@@ -20,6 +20,10 @@ pub struct Review {
|
||||
pub player: Option<Player>,
|
||||
/// The clip's audio tracks, one player each, so the channels are heard apart.
|
||||
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,
|
||||
/// so a long clip does not hold the frame while ffmpeg reads it.
|
||||
pub sound_rx: Option<Receiver<Result<Vec<std::path::PathBuf>, String>>>,
|
||||
@@ -54,17 +58,18 @@ pub struct 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.
|
||||
pub fn set_volume(&mut self, volume: f32) {
|
||||
self.volume = volume.clamp(0.0, 1.0);
|
||||
if self.volume > 0.0 {
|
||||
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 {
|
||||
channel.sound.set_volume(self.volume);
|
||||
channel.sound.set_muted(!channel.heard(self.muted));
|
||||
@@ -73,6 +78,11 @@ impl Review {
|
||||
|
||||
pub fn toggle_muted(&mut self) {
|
||||
self.muted = !self.muted;
|
||||
if self.video_sound
|
||||
&& let Some(player) = &self.player
|
||||
{
|
||||
player.set_muted(self.muted);
|
||||
}
|
||||
for channel in &self.sounds {
|
||||
channel.sound.set_muted(!channel.heard(self.muted));
|
||||
}
|
||||
@@ -107,13 +117,7 @@ impl Review {
|
||||
let labels = self.track_labels();
|
||||
if labels.len() < 2 {
|
||||
// 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.
|
||||
let label = labels
|
||||
.first()
|
||||
.cloned()
|
||||
.unwrap_or_else(|| "All audio".to_string());
|
||||
let channel = self.channel(0, label, path);
|
||||
self.sounds.push(channel);
|
||||
// sound is the whole mix, and the video player reads it as it is.
|
||||
return;
|
||||
}
|
||||
let stem = self.stem(path);
|
||||
@@ -131,15 +135,14 @@ impl Review {
|
||||
return;
|
||||
}
|
||||
self.sound_tried = true;
|
||||
let labels = self.track_labels();
|
||||
if labels.len() < 2 {
|
||||
self.open_sound(path);
|
||||
if self.track_labels().len() < 2 {
|
||||
// The video player carries the whole mix itself.
|
||||
return;
|
||||
}
|
||||
self.channel_error = None;
|
||||
let path = path.to_string();
|
||||
let stem = self.stem(&path);
|
||||
let count = labels.len();
|
||||
let count = self.track_labels().len();
|
||||
let (tx, rx) = channel();
|
||||
std::thread::spawn(move || {
|
||||
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
|
||||
/// 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 {
|
||||
/// What the track carries, as the recorder named it.
|
||||
pub label: String,
|
||||
@@ -354,6 +353,7 @@ impl Default for Review {
|
||||
sounds: Vec::new(),
|
||||
sound_rx: None,
|
||||
sound_tried: false,
|
||||
video_sound: false,
|
||||
steady_at: 0.0,
|
||||
time: 0.0,
|
||||
duration: 0.0,
|
||||
@@ -425,15 +425,23 @@ pub fn show(app: &mut App, game: Timeline) {
|
||||
app.review.sound_tried = false;
|
||||
app.review.channel_error = None;
|
||||
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
|
||||
// recording. Start it on a thread now, while the first picture decodes.
|
||||
let many_tracks = app
|
||||
let tracks = app
|
||||
.review
|
||||
.game
|
||||
.as_ref()
|
||||
.is_some_and(|game| game.audio_tracks.len() >= 2);
|
||||
if many_tracks {
|
||||
.map(|game| game.audio_tracks.len())
|
||||
.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());
|
||||
}
|
||||
}
|
||||
@@ -507,16 +515,11 @@ fn keep_in_step(app: &mut App) {
|
||||
pub fn tick(app: &mut App, tx: &mut Tx) -> bool {
|
||||
let mut changed = false;
|
||||
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();
|
||||
if (time - app.review.time).abs() > 0.001 {
|
||||
app.review.time = time;
|
||||
changed = true;
|
||||
}
|
||||
}
|
||||
if let Some(duration) = player.duration()
|
||||
&& duration > 0.0
|
||||
&& (duration - app.review.duration).abs() > 0.05
|
||||
|
||||
@@ -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
|
||||
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
|
||||
|
||||
@@ -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
|
||||
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
|
||||
|
||||
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.
|
||||
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.
|
||||
Reference in new issue
Block a user