From de0f228075cb35cc27d46b2aec83aa1b7f4db2c9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sebastian=20Dr=C3=B6ge?= Date: Sun, 7 Jun 2020 14:13:39 +0300 Subject: [PATCH] video: Add VideoInfo::is_valid() and guard against finfo being NULL when retrieving the video format --- gstreamer-video/src/video_info.rs | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/gstreamer-video/src/video_info.rs b/gstreamer-video/src/video_info.rs index 486c07eac..8223e4fb5 100644 --- a/gstreamer-video/src/video_info.rs +++ b/gstreamer-video/src/video_info.rs @@ -557,6 +557,10 @@ impl VideoInfo { } } + pub fn is_valid(&self) -> bool { + !self.0.finfo.is_null() && self.0.width > 0 && self.0.height > 0 && self.0.size > 0 + } + pub fn from_caps(caps: &gst::CapsRef) -> Result { skip_assert_initialized!(); @@ -586,6 +590,10 @@ impl VideoInfo { } pub fn format(&self) -> ::VideoFormat { + if self.0.finfo.is_null() { + return ::VideoFormat::Unknown; + } + unsafe { from_glib((*self.0.finfo).format) } }