video/videoconverter: Add TryFrom<Structure> and inverse From impl for VideoConverterConfig

Allows converting between both types interchangebly.
This commit is contained in:
Sebastian Dröge 2020-05-26 18:35:35 +03:00
parent 02a43819a7
commit f0e12bbf24

View file

@ -12,6 +12,7 @@ use glib;
use glib::translate::ToGlibPtr;
use gst;
use std::convert;
use std::ops;
use std::ptr;
@ -139,6 +140,35 @@ impl Default for VideoConverterConfig {
}
}
impl convert::TryFrom<gst::Structure> for VideoConverterConfig {
type Error = glib::BoolError;
fn try_from(v: gst::Structure) -> Result<VideoConverterConfig, Self::Error> {
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<VideoConverterConfig, Self::Error> {
skip_assert_initialized!();
VideoConverterConfig::try_from(v.to_owned())
}
}
impl From<VideoConverterConfig> 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"))