onvifmetadataparse: Skip metadata frames with unrepresentable UTC time

Previously we would panic, which causes the element to post an error
message. Instead, simply skip metadata frames if their UTC time since
the UNIX epoch can't be represented as nanoseconds in u64.

Part-of: <https://gitlab.freedesktop.org/gstreamer/gst-plugins-rs/-/merge_requests/1326>
This commit is contained in:
Sebastian Dröge 2023-09-16 10:59:27 +03:00
parent 225482f7ed
commit b12278e334
2 changed files with 14 additions and 3 deletions

View file

@ -14,7 +14,7 @@ gst-rtp = { package = "gstreamer-rtp", git = "https://gitlab.freedesktop.org/gst
gst-base = { package = "gstreamer-base", git = "https://gitlab.freedesktop.org/gstreamer/gstreamer-rs", features = ["v1_20"] }
gst-video = { package = "gstreamer-video", git = "https://gitlab.freedesktop.org/gstreamer/gstreamer-rs", features = ["v1_20"] }
xmlparser = "0.13"
chrono = { version = "0.4", default-features = false }
chrono = { version = "0.4.31", default-features = false }
cairo-rs = { git = "https://github.com/gtk-rs/gtk-rs-core", features=["use_glib"] }
pango = { git = "https://github.com/gtk-rs/gtk-rs-core" }
pangocairo = { git = "https://github.com/gtk-rs/gtk-rs-core" }

View file

@ -359,8 +359,19 @@ impl OnvifMetadataParse {
gst::FlowError::Error
})?;
let dt_unix_ns =
(dt.timestamp_nanos() as u64).nseconds() + crate::PRIME_EPOCH_OFFSET;
let dt_unix_ns = dt
.timestamp_nanos_opt()
.and_then(|ns| u64::try_from(ns).ok())
.and_then(|ns| ns.nseconds().checked_add(crate::PRIME_EPOCH_OFFSET));
let Some(dt_unix_ns) = dt_unix_ns else {
gst::warning!(CAT,
imp: self,
"Frame with unrepresentable UTC time {}",
dt,
);
continue;
};
gst::trace!(
CAT,