From 1be8ec691e7c6da91f31cdb0db615c7efef664ba Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sebastian=20Dr=C3=B6ge?= Date: Thu, 16 May 2019 02:18:26 +0300 Subject: [PATCH] gstreamer-video: Add support for the AFD and Bar metas --- Gir_GstVideo.toml | 2 + gstreamer-video/src/auto/enums.rs | 157 ++++++++++++++++++++++++++++++ gstreamer-video/src/auto/mod.rs | 3 + gstreamer-video/src/video_meta.rs | 135 +++++++++++++++++++++++++ 4 files changed, 297 insertions(+) diff --git a/Gir_GstVideo.toml b/Gir_GstVideo.toml index 3f2472551..8760e5eb1 100644 --- a/Gir_GstVideo.toml +++ b/Gir_GstVideo.toml @@ -47,6 +47,8 @@ generate = [ "GstVideo.VideoPrimariesMode", "GstVideo.VideoResamplerMethod", "GstVideo.VideoDitherMethod", + "GstVideo.VideoAFDValue", + "GstVideo.VideoAFDSpec", ] manual = [ diff --git a/gstreamer-video/src/auto/enums.rs b/gstreamer-video/src/auto/enums.rs index 1df0c952f..294686e9b 100644 --- a/gstreamer-video/src/auto/enums.rs +++ b/gstreamer-video/src/auto/enums.rs @@ -73,6 +73,163 @@ impl SetValue for VideoAlphaMode { } } +#[derive(Debug, Eq, PartialEq, Ord, PartialOrd, Hash, Clone, Copy)] +pub enum VideoAFDSpec { + DvbEtsi, + AtscA53, + SmpteSt20161, + #[doc(hidden)] + __Unknown(i32), +} + +#[doc(hidden)] +impl ToGlib for VideoAFDSpec { + type GlibType = gst_video_sys::GstVideoAFDSpec; + + fn to_glib(&self) -> gst_video_sys::GstVideoAFDSpec { + match *self { + VideoAFDSpec::DvbEtsi => gst_video_sys::GST_VIDEO_AFD_SPEC_DVB_ETSI, + VideoAFDSpec::AtscA53 => gst_video_sys::GST_VIDEO_AFD_SPEC_ATSC_A53, + VideoAFDSpec::SmpteSt20161 => gst_video_sys::GST_VIDEO_AFD_SPEC_SMPTE_ST2016_1, + VideoAFDSpec::__Unknown(value) => value, + } + } +} + +#[doc(hidden)] +impl FromGlib for VideoAFDSpec { + fn from_glib(value: gst_video_sys::GstVideoAFDSpec) -> Self { + skip_assert_initialized!(); + match value { + 0 => VideoAFDSpec::DvbEtsi, + 1 => VideoAFDSpec::AtscA53, + 2 => VideoAFDSpec::SmpteSt20161, + value => VideoAFDSpec::__Unknown(value), + } + } +} + +impl StaticType for VideoAFDSpec { + fn static_type() -> Type { + unsafe { from_glib(gst_video_sys::gst_video_afd_spec_get_type()) } + } +} + +impl<'a> FromValueOptional<'a> for VideoAFDSpec { + unsafe fn from_value_optional(value: &Value) -> Option { + Some(FromValue::from_value(value)) + } +} + +impl<'a> FromValue<'a> for VideoAFDSpec { + unsafe fn from_value(value: &Value) -> Self { + from_glib(gobject_sys::g_value_get_enum(value.to_glib_none().0)) + } +} + +impl SetValue for VideoAFDSpec { + unsafe fn set_value(value: &mut Value, this: &Self) { + gobject_sys::g_value_set_enum(value.to_glib_none_mut().0, this.to_glib()) + } +} + +#[cfg(any(feature = "v1_18", feature = "dox"))] +#[derive(Debug, Eq, PartialEq, Ord, PartialOrd, Hash, Clone, Copy)] +pub enum VideoAFDValue { + Unavailable, + _169TopAligned, + _149TopAligned, + GreaterThan169, + _43Full169Full, + _43Full43Pillar, + _169Letter169Full, + _149Letter149Pillar, + _43Full149Center, + _169Letter149Center, + _169Letter43Center, + #[doc(hidden)] + __Unknown(i32), +} + +#[cfg(any(feature = "v1_18", feature = "dox"))] +#[doc(hidden)] +impl ToGlib for VideoAFDValue { + type GlibType = gst_video_sys::GstVideoAFDValue; + + fn to_glib(&self) -> gst_video_sys::GstVideoAFDValue { + match *self { + VideoAFDValue::Unavailable => gst_video_sys::GST_VIDEO_AFD_UNAVAILABLE, + VideoAFDValue::_169TopAligned => gst_video_sys::GST_VIDEO_AFD_16_9_TOP_ALIGNED, + VideoAFDValue::_149TopAligned => gst_video_sys::GST_VIDEO_AFD_14_9_TOP_ALIGNED, + VideoAFDValue::GreaterThan169 => gst_video_sys::GST_VIDEO_AFD_GREATER_THAN_16_9, + VideoAFDValue::_43Full169Full => gst_video_sys::GST_VIDEO_AFD_4_3_FULL_16_9_FULL, + VideoAFDValue::_43Full43Pillar => gst_video_sys::GST_VIDEO_AFD_4_3_FULL_4_3_PILLAR, + VideoAFDValue::_169Letter169Full => gst_video_sys::GST_VIDEO_AFD_16_9_LETTER_16_9_FULL, + VideoAFDValue::_149Letter149Pillar => { + gst_video_sys::GST_VIDEO_AFD_14_9_LETTER_14_9_PILLAR + } + VideoAFDValue::_43Full149Center => gst_video_sys::GST_VIDEO_AFD_4_3_FULL_14_9_CENTER, + VideoAFDValue::_169Letter149Center => { + gst_video_sys::GST_VIDEO_AFD_16_9_LETTER_14_9_CENTER + } + VideoAFDValue::_169Letter43Center => { + gst_video_sys::GST_VIDEO_AFD_16_9_LETTER_4_3_CENTER + } + VideoAFDValue::__Unknown(value) => value, + } + } +} + +#[cfg(any(feature = "v1_18", feature = "dox"))] +#[doc(hidden)] +impl FromGlib for VideoAFDValue { + fn from_glib(value: gst_video_sys::GstVideoAFDValue) -> Self { + skip_assert_initialized!(); + match value { + 0 => VideoAFDValue::Unavailable, + 2 => VideoAFDValue::_169TopAligned, + 3 => VideoAFDValue::_149TopAligned, + 4 => VideoAFDValue::GreaterThan169, + 8 => VideoAFDValue::_43Full169Full, + 9 => VideoAFDValue::_43Full43Pillar, + 10 => VideoAFDValue::_169Letter169Full, + 11 => VideoAFDValue::_149Letter149Pillar, + 13 => VideoAFDValue::_43Full149Center, + 14 => VideoAFDValue::_169Letter149Center, + 15 => VideoAFDValue::_169Letter43Center, + value => VideoAFDValue::__Unknown(value), + } + } +} + +#[cfg(any(feature = "v1_18", feature = "dox"))] +impl StaticType for VideoAFDValue { + fn static_type() -> Type { + unsafe { from_glib(gst_video_sys::gst_video_afd_value_get_type()) } + } +} + +#[cfg(any(feature = "v1_18", feature = "dox"))] +impl<'a> FromValueOptional<'a> for VideoAFDValue { + unsafe fn from_value_optional(value: &Value) -> Option { + Some(FromValue::from_value(value)) + } +} + +#[cfg(any(feature = "v1_18", feature = "dox"))] +impl<'a> FromValue<'a> for VideoAFDValue { + unsafe fn from_value(value: &Value) -> Self { + from_glib(gobject_sys::g_value_get_enum(value.to_glib_none().0)) + } +} + +#[cfg(any(feature = "v1_18", feature = "dox"))] +impl SetValue for VideoAFDValue { + unsafe fn set_value(value: &mut Value, this: &Self) { + gobject_sys::g_value_set_enum(value.to_glib_none_mut().0, this.to_glib()) + } +} + #[cfg(any(feature = "v1_16", feature = "dox"))] #[derive(Debug, Eq, PartialEq, Ord, PartialOrd, Hash, Clone, Copy)] #[non_exhaustive] diff --git a/gstreamer-video/src/auto/mod.rs b/gstreamer-video/src/auto/mod.rs index 8b89478ad..20df2fd7f 100644 --- a/gstreamer-video/src/auto/mod.rs +++ b/gstreamer-video/src/auto/mod.rs @@ -21,6 +21,9 @@ pub use self::video_overlay::VideoOverlayExt; pub use self::video_overlay::{VideoOverlay, NONE_VIDEO_OVERLAY}; mod enums; +pub use self::enums::VideoAFDSpec; +#[cfg(any(feature = "v1_18", feature = "dox"))] +pub use self::enums::VideoAFDValue; pub use self::enums::VideoAlphaMode; #[cfg(any(feature = "v1_16", feature = "dox"))] pub use self::enums::VideoCaptionType; diff --git a/gstreamer-video/src/video_meta.rs b/gstreamer-video/src/video_meta.rs index d6074111a..0aa028e16 100644 --- a/gstreamer-video/src/video_meta.rs +++ b/gstreamer-video/src/video_meta.rs @@ -255,6 +255,141 @@ impl fmt::Debug for VideoCaptionMeta { } } +#[cfg(any(feature = "v1_18", feature = "dox"))] +#[repr(C)] +pub struct VideoAFDMeta(gst_video_sys::GstVideoAFDMeta); + +#[cfg(any(feature = "v1_18", feature = "dox"))] +unsafe impl Send for VideoAFDMeta {} +#[cfg(any(feature = "v1_18", feature = "dox"))] +unsafe impl Sync for VideoAFDMeta {} + +#[cfg(any(feature = "v1_18", feature = "dox"))] +impl VideoAFDMeta { + pub fn add( + buffer: &mut gst::BufferRef, + field: u8, + spec: ::VideoAFDSpec, + afd: ::VideoAFDValue, + ) -> gst::MetaRefMut { + skip_assert_initialized!(); + + unsafe { + let meta = gst_video_sys::gst_buffer_add_video_afd_meta( + buffer.as_mut_ptr(), + field, + spec.to_glib(), + afd.to_glib(), + ); + + Self::from_mut_ptr(buffer, meta) + } + } + + pub fn get_field(&self) -> u8 { + self.0.field + } + + pub fn get_spec(&self) -> ::VideoAFDSpec { + from_glib(self.0.spec) + } + + pub fn get_afd(&self) -> ::VideoAFDValue { + from_glib(self.0.afd) + } +} + +#[cfg(any(feature = "v1_18", feature = "dox"))] +unsafe impl MetaAPI for VideoAFDMeta { + type GstType = gst_video_sys::GstVideoAFDMeta; + + fn get_meta_api() -> glib::Type { + unsafe { from_glib(gst_video_sys::gst_video_afd_meta_api_get_type()) } + } +} + +#[cfg(any(feature = "v1_18", feature = "dox"))] +impl fmt::Debug for VideoAFDMeta { + fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + f.debug_struct("VideoAFDMeta") + .field("field", &self.get_field()) + .field("spec", &self.get_spec()) + .field("afd", &self.get_afd()) + .finish() + } +} + +#[cfg(any(feature = "v1_18", feature = "dox"))] +#[repr(C)] +pub struct VideoBarMeta(gst_video_sys::GstVideoBarMeta); + +#[cfg(any(feature = "v1_18", feature = "dox"))] +unsafe impl Send for VideoBarMeta {} +#[cfg(any(feature = "v1_18", feature = "dox"))] +unsafe impl Sync for VideoBarMeta {} + +#[cfg(any(feature = "v1_18", feature = "dox"))] +impl VideoBarMeta { + pub fn add( + buffer: &mut gst::BufferRef, + field: u8, + is_letterbox: bool, + bar_data1: u32, + bar_data2: u32, + ) -> gst::MetaRefMut { + skip_assert_initialized!(); + + unsafe { + let meta = gst_video_sys::gst_buffer_add_video_bar_meta( + buffer.as_mut_ptr(), + field, + is_letterbox.to_glib(), + bar_data1, + bar_data2, + ); + + Self::from_mut_ptr(buffer, meta) + } + } + + pub fn get_field(&self) -> u8 { + self.0.field + } + + pub fn is_letterbox(&self) -> bool { + from_glib(self.0.is_letterbox) + } + + pub fn get_bar_data1(&self) -> u32 { + self.0.bar_data1 + } + + pub fn get_bar_data2(&self) -> u32 { + self.0.bar_data2 + } +} + +#[cfg(any(feature = "v1_18", feature = "dox"))] +unsafe impl MetaAPI for VideoBarMeta { + type GstType = gst_video_sys::GstVideoBarMeta; + + fn get_meta_api() -> glib::Type { + unsafe { from_glib(gst_video_sys::gst_video_bar_meta_api_get_type()) } + } +} + +#[cfg(any(feature = "v1_18", feature = "dox"))] +impl fmt::Debug for VideoBarMeta { + fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + f.debug_struct("VideoBarMeta") + .field("field", &self.get_field()) + .field("is_letterbox", &self.is_letterbox()) + .field("bar_data1", &self.get_bar_data1()) + .field("bar_data2", &self.get_bar_data2()) + .finish() + } +} + #[cfg(test)] mod tests { use super::*;