Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 16 additions & 2 deletions crates/rendering/src/decoder/avassetreader.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,17 @@ use cidre::{
use ffmpeg::{Rational, format, frame};
use tokio::{runtime::Handle as TokioHandle, sync::oneshot};

use crate::DecodedFrame;

use super::frame_converter::{FrameConverter, copy_rgba_plane};
use super::{FRAME_CACHE_SIZE, VideoDecoderMessage, pts_to_frame};

#[derive(Clone)]
struct ProcessedFrame {
number: u32,
data: Arc<Vec<u8>>,
width: u32,
height: u32,
}

#[derive(Clone)]
Expand Down Expand Up @@ -151,6 +155,8 @@ impl CachedFrame {
let data = ProcessedFrame {
number: *number,
data: Arc::new(frame_buffer),
width: image_buf.width() as u32,
height: image_buf.height() as u32,
};

*self = Self::Processed(data.clone());
Expand Down Expand Up @@ -227,14 +233,22 @@ impl AVAssetReaderDecoder {
let mut sender = if let Some(cached) = cache.get_mut(&requested_frame) {
let data = cached.process(&mut processor);

sender.send(data.data.clone()).ok();
let _ = sender.send(DecodedFrame {
data: data.data.clone(),
width: data.width,
height: data.height,
});
*last_sent_frame.borrow_mut() = Some(data);
continue;
} else {
let last_sent_frame = last_sent_frame.clone();
Some(move |data: ProcessedFrame| {
*last_sent_frame.borrow_mut() = Some(data.clone());
let _ = sender.send(data.data);
let _ = sender.send(DecodedFrame {
data: data.data.clone(),
width: data.width,
height: data.height,
});
})
};

Expand Down
18 changes: 16 additions & 2 deletions crates/rendering/src/decoder/ffmpeg.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,16 @@ use std::{
};
use tokio::sync::oneshot;

use crate::DecodedFrame;

use super::{FRAME_CACHE_SIZE, VideoDecoderMessage, frame_converter::FrameConverter, pts_to_frame};

#[derive(Clone)]
struct ProcessedFrame {
number: u32,
data: Arc<Vec<u8>>,
width: u32,
height: u32,
}

impl CachedFrame {
Expand All @@ -25,6 +29,8 @@ impl CachedFrame {
let data = ProcessedFrame {
data: Arc::new(frame_buffer),
number: *number,
width: frame.width(),
height: frame.height(),
};

*self = Self::Processed(data.clone());
Expand Down Expand Up @@ -99,14 +105,22 @@ impl FfmpegDecoder {
let mut sender = if let Some(cached) = cache.get_mut(&requested_frame) {
let data = cached.process(&mut converter);

sender.send(data.data.clone()).ok();
let _ = sender.send(DecodedFrame {
data: data.data.clone(),
width: data.width,
height: data.height,
});
*last_sent_frame.borrow_mut() = Some(data);
continue;
} else {
let last_sent_frame = last_sent_frame.clone();
Some(move |data: ProcessedFrame| {
*last_sent_frame.borrow_mut() = Some(data.clone());
let _ = sender.send(data.data);
let _ = sender.send(DecodedFrame {
data: data.data.clone(),
width: data.width,
height: data.height,
});
})
};

Expand Down
20 changes: 19 additions & 1 deletion crates/rendering/src/decoder/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,25 @@ mod avassetreader;
mod ffmpeg;
mod frame_converter;

pub type DecodedFrame = Arc<Vec<u8>>;
pub struct DecodedFrame {
data: Arc<Vec<u8>>,
width: u32,
height: u32,
}

impl DecodedFrame {
pub fn data(&self) -> &[u8] {
&self.data
}

pub fn width(&self) -> u32 {
self.width
}

pub fn height(&self) -> u32 {
self.height
}
}

pub enum VideoDecoderMessage {
GetFrame(f32, tokio::sync::oneshot::Sender<DecodedFrame>),
Expand Down
2 changes: 1 addition & 1 deletion crates/rendering/src/layers/camera.rs
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ impl CameraLayer {
origin: wgpu::Origin3d::ZERO,
aspect: wgpu::TextureAspect::All,
},
camera_frame,
camera_frame.data(),
wgpu::TexelCopyBufferLayout {
offset: 0,
bytes_per_row: Some(frame_size.x * 4),
Expand Down
2 changes: 1 addition & 1 deletion crates/rendering/src/layers/display.rs
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ impl DisplayLayer {
origin: wgpu::Origin3d::ZERO,
aspect: wgpu::TextureAspect::All,
},
&segment_frames.screen_frame,
segment_frames.screen_frame.data(),
wgpu::TexelCopyBufferLayout {
offset: 0,
bytes_per_row: Some(frame_size.x * 4),
Expand Down
3 changes: 2 additions & 1 deletion turbo.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,8 @@
"cache": false
},
"db:push": {
"cache": false
"cache": false,
"interactive": true
},
"dev": {
"dependsOn": ["db:push"],
Expand Down
Loading