Skip to content

armgit / Cap

Public Imported from GitHub
0

Open source Loom alternative. Beautiful, shareable screen recordings.

perf(rendering): tighten initial decode fallback distance

Richie McIlroy769dc988428b
diff --git a/crates/rendering/src/decoder/avassetreader.rs b/crates/rendering/src/decoder/avassetreader.rs
index 96905f85f..4b9f6649d 100644
--- a/crates/rendering/src/decoder/avassetreader.rs
+++ b/crates/rendering/src/decoder/avassetreader.rs
@@ -647,6 +647,11 @@ impl AVAssetReaderDecoder {
let max_requested_frame = pending_requests.iter().map(|r| r.frame).max().unwrap();
let requested_frame = min_requested_frame;
let requested_time = requested_frame as f32 / fps as f32;
+ let minimum_fallback_frame = pending_requests
+ .iter()
+ .map(|r| r.frame.saturating_sub(r.max_fallback_distance))
+ .min()
+ .unwrap_or(requested_frame);
let (decoder_idx, was_reset) = this.select_best_decoder(requested_time, is_scrubbing);
@@ -695,6 +700,12 @@ impl AVAssetReaderDecoder {
pts_to_frame(frame.pts().value, Rational::new(1, frame.pts().scale), fps);
let position_secs = current_frame as f32 / fps as f32;
+ last_decoded_position = Some(position_secs);
+ decoder.is_done = false;
+
+ if current_frame < minimum_fallback_frame {
+ continue;
+ }
let Some(frame) = frame.image_buf() else {
tracing::debug!(
@@ -704,16 +715,12 @@ impl AVAssetReaderDecoder {
continue;
};
- last_decoded_position = Some(position_secs);
-
let cache_frame = CachedFrame::new(&processor, frame.retained(), current_frame);
if first_ever_frame.borrow().is_none() {
*first_ever_frame.borrow_mut() = Some(cache_frame.data().clone());
}
- decoder.is_done = false;
-
let exceeds_cache_bounds = current_frame > cache_max;
let too_small_for_cache_bounds = current_frame < cache_min;
diff --git a/crates/rendering/src/decoder/mod.rs b/crates/rendering/src/decoder/mod.rs
index 5595024f6..44456cea0 100644
--- a/crates/rendering/src/decoder/mod.rs
+++ b/crates/rendering/src/decoder/mod.rs
@@ -459,6 +459,7 @@ pub struct AsyncVideoDecoderHandle {
impl AsyncVideoDecoderHandle {
const INITIAL_SEEK_TIMEOUT_MS: u64 = 10000;
+ const INITIAL_MAX_FALLBACK_DISTANCE: u32 = 2;
fn normal_timeout_ms(&self) -> u64 {
let pixels = (self.status.video_width as u64) * (self.status.video_height as u64);
@@ -472,16 +473,26 @@ impl AsyncVideoDecoderHandle {
}
pub async fn get_frame(&self, time: f32) -> Option<DecodedFrame> {
- self.get_frame_with_timeout(time, self.normal_timeout_ms())
+ self.get_frame_with_timeout(time, self.normal_timeout_ms(), self.max_fallback_distance)
.await
}
pub async fn get_frame_initial(&self, time: f32) -> Option<DecodedFrame> {
- self.get_frame_with_timeout(time, Self::INITIAL_SEEK_TIMEOUT_MS)
- .await
- }
-
- async fn get_frame_with_timeout(&self, time: f32, timeout_ms: u64) -> Option<DecodedFrame> {
+ self.get_frame_with_timeout(
+ time,
+ Self::INITIAL_SEEK_TIMEOUT_MS,
+ self.max_fallback_distance
+ .min(Self::INITIAL_MAX_FALLBACK_DISTANCE),
+ )
+ .await
+ }
+
+ async fn get_frame_with_timeout(
+ &self,
+ time: f32,
+ timeout_ms: u64,
+ max_fallback_distance: u32,
+ ) -> Option<DecodedFrame> {
let (tx, rx) = tokio::sync::oneshot::channel();
let adjusted_time = self.get_time(time);
@@ -489,7 +500,7 @@ impl AsyncVideoDecoderHandle {
.sender
.send(VideoDecoderMessage::GetFrame(
adjusted_time,
- self.max_fallback_distance,
+ max_fallback_distance,
tx,
))
.is_err()