reduce CPU usage
This commit is contained in:
parent
be2b7d9257
commit
760b09a8b0
2 changed files with 14 additions and 9 deletions
|
@ -209,6 +209,7 @@ impl Video {
|
|||
let framerate = s
|
||||
.get::<gst::Fraction>("framerate")
|
||||
.map_err(|_| Error::Caps)?;
|
||||
let framerate = framerate.numer() as f64 / framerate.denom() as f64;
|
||||
|
||||
let duration = std::time::Duration::from_nanos(
|
||||
pipeline
|
||||
|
@ -231,7 +232,8 @@ impl Video {
|
|||
let alive_ref = Arc::clone(&alive);
|
||||
|
||||
let worker = std::thread::spawn(move || {
|
||||
while alive_ref.load(Ordering::SeqCst) {
|
||||
while alive_ref.load(Ordering::Acquire) {
|
||||
std::thread::sleep(std::time::Duration::from_secs_f64(1.0 / framerate));
|
||||
if let Err(gst::FlowError::Error) = (|| -> Result<(), gst::FlowError> {
|
||||
let sample = app_sink.pull_sample().map_err(|_| gst::FlowError::Eos)?;
|
||||
|
||||
|
@ -260,7 +262,7 @@ impl Video {
|
|||
|
||||
width,
|
||||
height,
|
||||
framerate: framerate.numer() as f64 / framerate.denom() as f64,
|
||||
framerate,
|
||||
duration,
|
||||
speed: 1.0,
|
||||
|
||||
|
|
|
@ -233,13 +233,16 @@ where
|
|||
inner.set_paused(true);
|
||||
}
|
||||
|
||||
let redraw_interval = 1.0 / inner.framerate;
|
||||
shell.request_redraw(iced::window::RedrawRequest::At(
|
||||
now + Duration::from_secs_f64(redraw_interval),
|
||||
));
|
||||
|
||||
if let Some(on_new_frame) = self.on_new_frame.clone() {
|
||||
shell.publish(on_new_frame);
|
||||
if inner.upload_frame.load(Ordering::SeqCst) {
|
||||
shell.request_redraw(iced::window::RedrawRequest::NextFrame);
|
||||
if let Some(on_new_frame) = self.on_new_frame.clone() {
|
||||
shell.publish(on_new_frame);
|
||||
}
|
||||
} else {
|
||||
let redraw_interval = 1.0 / inner.framerate;
|
||||
shell.request_redraw(iced::window::RedrawRequest::At(
|
||||
now + Duration::from_secs_f64(redraw_interval),
|
||||
));
|
||||
}
|
||||
}
|
||||
Status::Captured
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue