Allow more skipping if video is behind

This commit is contained in:
Jeremy Soller 2024-01-25 21:31:12 -07:00
parent 8eface2200
commit c726fca224
2 changed files with 9 additions and 5 deletions

View file

@ -298,16 +298,21 @@ impl Application for App {
Message::Tick(frame_time) => {
let start = Instant::now();
let mut video_frame_opt = None;
let mut video_frame_opt: Option<VideoFrame> = None;
{
let mut video_frames = self.flags.video_frames_lock.lock().unwrap();
if let Some(video_frame) = video_frames.pop_front() {
while let Some(video_frame) = video_frames.pop_front() {
if video_frame.1.unwrap_or(frame_time) <= frame_time {
if let Some(old_frame) = video_frame_opt {
//TODO: log this outside of locking video_frames_lock?
log::warn!("skipping video frame {:?}", old_frame.0.pts());
}
// Frame is ready to be shown
video_frame_opt = Some(video_frame)
} else {
// Put frame back
// Put frame back and exit loop
video_frames.push_front(video_frame);
break;
}
}
}

View file

@ -233,8 +233,7 @@ fn ffmpeg_thread<P: AsRef<Path>>(
}
})?;
// This is a sync channel to reduce skipping
let (gpu_frame_tx, gpu_frame_rx) = mpsc::sync_channel::<(Video, Option<Instant>)>(1);
let (gpu_frame_tx, gpu_frame_rx) = mpsc::channel::<(Video, Option<Instant>)>();
thread::Builder::new()
.name("video_map_gpu_cpu".to_string())
.spawn(move || {