From 8e96888c6365ab202f7450c94235bf091e0cc0d7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sebastian=20Dr=C3=B6ge?= Date: Tue, 26 May 2020 18:35:35 +0300 Subject: [PATCH] video/videoconverter: Add TryFrom and inverse From impl for VideoConverterConfig Allows converting between both types interchangebly. --- gstreamer-video/src/video_converter.rs | 30 ++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/gstreamer-video/src/video_converter.rs b/gstreamer-video/src/video_converter.rs index c24f2bb65..c5b52b5ea 100644 --- a/gstreamer-video/src/video_converter.rs +++ b/gstreamer-video/src/video_converter.rs @@ -12,6 +12,7 @@ use glib; use glib::translate::ToGlibPtr; use gst; +use std::convert; use std::ops; use std::ptr; @@ -138,6 +139,35 @@ impl Default for VideoConverterConfig { } } +impl convert::TryFrom for VideoConverterConfig { + type Error = glib::BoolError; + + fn try_from(v: gst::Structure) -> Result { + skip_assert_initialized!(); + if v.get_name() == "GstVideoConverter" { + Ok(VideoConverterConfig(v)) + } else { + Err(glib_bool_error!("Structure is no VideoConverterConfig")) + } + } +} + +impl<'a> convert::TryFrom<&'a gst::StructureRef> for VideoConverterConfig { + type Error = glib::BoolError; + + fn try_from(v: &'a gst::StructureRef) -> Result { + skip_assert_initialized!(); + VideoConverterConfig::try_from(v.to_owned()) + } +} + +impl From for gst::Structure { + fn from(v: VideoConverterConfig) -> gst::Structure { + skip_assert_initialized!(); + v.0 + } +} + impl VideoConverterConfig { pub fn new() -> Self { VideoConverterConfig(gst::Structure::new_empty("GstVideoConverter"))