Skip to content

Commit

Permalink
remove black frame
Browse files Browse the repository at this point in the history
  • Loading branch information
Brendonovich committed Jan 31, 2025
1 parent 27093d1 commit 4a3a4da
Showing 1 changed file with 9 additions and 10 deletions.
19 changes: 9 additions & 10 deletions crates/rendering/src/decoder/avassetreader.rs
Original file line number Diff line number Diff line change
Expand Up @@ -227,13 +227,13 @@ impl AVAssetReaderDecoder {
}
};

let black_frame = LazyCell::new(|| Arc::new(vec![0; (width * height * 4) as usize]));
// let black_frame = LazyCell::new(|| Arc::new(vec![0; (width * height * 4) as usize]));

let mut cache = BTreeMap::<u32, CachedFrame>::new();

let mut last_active_frame = None::<u32>;

let mut last_decoded_frame = None::<u32>;
let mut last_decoded_frame = None::<(u32, CachedFrame)>;
let mut last_sent_frame = None::<(u32, DecodedFrame)>;

while let Ok(r) = rx.recv() {
Expand Down Expand Up @@ -295,22 +295,21 @@ impl AVAssetReaderDecoder {
{
// Handles frame skips. requested_frame == last_decoded_frame should be handled by the frame cache.
if let Some((last_decoded_frame, sender)) = last_decoded_frame
.filter(|last_decoded_frame| {
requested_frame > *last_decoded_frame
.as_mut()
.filter(|(last_decoded_frame_i, _)| {
requested_frame > *last_decoded_frame_i
&& requested_frame < current_frame
})
.and_then(|l| Some((l, sender.take()?)))
{
let data = cache
.get_mut(&last_decoded_frame)
.map(|f| f.process())
.unwrap_or_else(|| black_frame.clone());
let (frame_number, frame) = last_decoded_frame;

last_sent_frame = Some((last_decoded_frame, data.clone()));
let data = frame.process();
last_sent_frame = Some((*frame_number, data.clone()));
sender.send(data).ok();
}

last_decoded_frame = Some(current_frame);
last_decoded_frame = Some((current_frame, cache_frame.clone()));

let exceeds_cache_bounds = current_frame > cache_max;
let too_small_for_cache_bounds = current_frame < cache_min;
Expand Down

1 comment on commit 4a3a4da

@vercel
Copy link

@vercel vercel bot commented on 4a3a4da Jan 31, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.