From a2a1a87c4623b9d8fce1bd32d24959fd885ad637 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sebastian=20Dr=C3=B6ge?= Date: Fri, 14 Feb 2020 13:12:41 +0100 Subject: [PATCH] video/video-info: Don't use bool return of gst_video_info_set_format()/align() when running with GStreamer < 1.11.1 The bool return value was added in 1.11.1 and using the return value with older versions gives a random value that might be true or false, and then causes spurious errors. Fixes https://gitlab.freedesktop.org/gstreamer/gstreamer-rs/issues/236#note_399872 --- gstreamer-video/src/video_info.rs | 50 +++++++++++++++++++++++++++++-- 1 file changed, 48 insertions(+), 2 deletions(-) diff --git a/gstreamer-video/src/video_info.rs b/gstreamer-video/src/video_info.rs index c5814c4c5..486c07eac 100644 --- a/gstreamer-video/src/video_info.rs +++ b/gstreamer-video/src/video_info.rs @@ -267,7 +267,38 @@ impl<'a> VideoInfoBuilder<'a> { unsafe { let mut info = mem::MaybeUninit::uninit(); - #[cfg(not(feature = "v1_16"))] + #[cfg(not(feature = "v1_12"))] + let res: bool = { + // The bool return value is new with 1.11.1, see + // https://gitlab.freedesktop.org/gstreamer/gst-plugins-base/commit/17cdd369e6f2f73329d27dfceb50011f40f1ceb0 + let res = if gst::version() < (1, 11, 1, 0) { + gst_video_sys::gst_video_info_set_format( + info.as_mut_ptr(), + self.format.to_glib(), + self.width, + self.height, + ); + + true + } else { + from_glib(gst_video_sys::gst_video_info_set_format( + info.as_mut_ptr(), + self.format.to_glib(), + self.width, + self.height, + )) + }; + + if res { + if let Some(interlace_mode) = self.interlace_mode { + let info = info.as_mut_ptr(); + (*info).interlace_mode = interlace_mode.to_glib(); + } + } + + res + }; + #[cfg(all(feature = "v1_12", not(feature = "v1_16")))] let res: bool = { let res = from_glib(gst_video_sys::gst_video_info_set_format( info.as_mut_ptr(), @@ -710,8 +741,23 @@ impl VideoInfo { } } - #[cfg(any(feature = "v1_12", feature = "dox"))] pub fn align(&mut self, align: &mut ::VideoAlignment) -> bool { + #[cfg(not(feature = "v1_12"))] + unsafe { + // The bool return value is new with 1.11.1, see + // https://gitlab.freedesktop.org/gstreamer/gst-plugins-base/commit/17cdd369e6f2f73329d27dfceb50011f40f1ceb0 + if gst::version() < (1, 11, 1, 0) { + gst_video_sys::gst_video_info_align(&mut self.0, &mut align.0); + + true + } else { + from_glib(gst_video_sys::gst_video_info_align( + &mut self.0, + &mut align.0, + )) + } + } + #[cfg(feature = "v1_12")] unsafe { from_glib(gst_video_sys::gst_video_info_align( &mut self.0,