From b673526098f7f5504084a92b91bd8993613c045e Mon Sep 17 00:00:00 2001 From: Thomas Heck Date: Sat, 19 Dec 2020 16:08:08 +0100 Subject: [PATCH] limit task progress ratio range to prevent ui crashes when the progress data requested from gstreamer is somehow broken --- src/main.rs | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/src/main.rs b/src/main.rs index abc334d..f04a358 100644 --- a/src/main.rs +++ b/src/main.rs @@ -454,11 +454,18 @@ async fn transcode( .and_then(|time| time.nanoseconds()); let ratio = dur.and_then(|dur| { + if dur == 0 { + return None; + } + let pos = decodebin .query_position::() .and_then(|time| time.nanoseconds()); - pos.map(|pos| pos as f64 / dur as f64) + pos.map(|pos| { + let ratio = pos as f64 / dur as f64; + ratio.max(0.0).min(1.0) + }) }); if let Some(ratio) = ratio {