video: Add VideoInfo::is_valid() and guard against finfo being NULL when retrieving the video format

This commit is contained in:
Sebastian Dröge 2020-06-07 14:13:39 +03:00
parent 51024345f8
commit de0f228075

View file

@ -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<Self, glib::error::BoolError> {
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) }
}