diff --git a/Gir_GstVideo.toml b/Gir_GstVideo.toml index 555950c7e..798476d54 100644 --- a/Gir_GstVideo.toml +++ b/Gir_GstVideo.toml @@ -35,6 +35,7 @@ generate = [ "GstVideo.VideoFilter", "GstVideo.VideoOverlayFormatFlags", "GstVideo.VideoTimeCodeFlags", + "GstVideo.VideoCaptionType", ] manual = [ diff --git a/gstreamer-video/src/auto/enums.rs b/gstreamer-video/src/auto/enums.rs index b20e2c449..6f004d1a3 100644 --- a/gstreamer-video/src/auto/enums.rs +++ b/gstreamer-video/src/auto/enums.rs @@ -12,6 +12,80 @@ use glib::value::Value; use gobject_sys; use gst_video_sys; +#[cfg(any(feature = "v1_16", feature = "dox"))] +#[derive(Debug, Eq, PartialEq, Ord, PartialOrd, Hash)] +#[derive(Clone, Copy)] +pub enum VideoCaptionType { + Unknown, + Cea608Raw, + Cea608S3341a, + Cea708Raw, + Cea708Cdp, + #[doc(hidden)] + __Unknown(i32), +} + +#[cfg(any(feature = "v1_16", feature = "dox"))] +#[doc(hidden)] +impl ToGlib for VideoCaptionType { + type GlibType = gst_video_sys::GstVideoCaptionType; + + fn to_glib(&self) -> gst_video_sys::GstVideoCaptionType { + match *self { + VideoCaptionType::Unknown => gst_video_sys::GST_VIDEO_CAPTION_TYPE_UNKNOWN, + VideoCaptionType::Cea608Raw => gst_video_sys::GST_VIDEO_CAPTION_TYPE_CEA608_RAW, + VideoCaptionType::Cea608S3341a => gst_video_sys::GST_VIDEO_CAPTION_TYPE_CEA608_S334_1A, + VideoCaptionType::Cea708Raw => gst_video_sys::GST_VIDEO_CAPTION_TYPE_CEA708_RAW, + VideoCaptionType::Cea708Cdp => gst_video_sys::GST_VIDEO_CAPTION_TYPE_CEA708_CDP, + VideoCaptionType::__Unknown(value) => value + } + } +} + +#[cfg(any(feature = "v1_16", feature = "dox"))] +#[doc(hidden)] +impl FromGlib for VideoCaptionType { + fn from_glib(value: gst_video_sys::GstVideoCaptionType) -> Self { + skip_assert_initialized!(); + match value { + 0 => VideoCaptionType::Unknown, + 1 => VideoCaptionType::Cea608Raw, + 2 => VideoCaptionType::Cea608S3341a, + 3 => VideoCaptionType::Cea708Raw, + 4 => VideoCaptionType::Cea708Cdp, + value => VideoCaptionType::__Unknown(value), + } + } +} + +#[cfg(any(feature = "v1_16", feature = "dox"))] +impl StaticType for VideoCaptionType { + fn static_type() -> Type { + unsafe { from_glib(gst_video_sys::gst_video_caption_type_get_type()) } + } +} + +#[cfg(any(feature = "v1_16", feature = "dox"))] +impl<'a> FromValueOptional<'a> for VideoCaptionType { + unsafe fn from_value_optional(value: &Value) -> Option { + Some(FromValue::from_value(value)) + } +} + +#[cfg(any(feature = "v1_16", feature = "dox"))] +impl<'a> FromValue<'a> for VideoCaptionType { + unsafe fn from_value(value: &Value) -> Self { + from_glib(gobject_sys::g_value_get_enum(value.to_glib_none().0)) + } +} + +#[cfg(any(feature = "v1_16", feature = "dox"))] +impl SetValue for VideoCaptionType { + unsafe fn set_value(value: &mut Value, this: &Self) { + gobject_sys::g_value_set_enum(value.to_glib_none_mut().0, this.to_glib()) + } +} + #[derive(Debug, Eq, PartialEq, Ord, PartialOrd, Hash)] #[derive(Clone, Copy)] pub enum VideoColorMatrix { diff --git a/gstreamer-video/src/auto/mod.rs b/gstreamer-video/src/auto/mod.rs index d2bab3029..413b58c44 100644 --- a/gstreamer-video/src/auto/mod.rs +++ b/gstreamer-video/src/auto/mod.rs @@ -10,6 +10,8 @@ pub use self::video_overlay::{VideoOverlay, NONE_VIDEO_OVERLAY}; pub use self::video_overlay::VideoOverlayExt; mod enums; +#[cfg(any(feature = "v1_16", feature = "dox"))] +pub use self::enums::VideoCaptionType; pub use self::enums::VideoColorMatrix; pub use self::enums::VideoColorPrimaries; #[cfg(any(feature = "v1_12", feature = "dox"))] diff --git a/gstreamer-video/src/video_meta.rs b/gstreamer-video/src/video_meta.rs index 4eacb9cb1..747ed7db7 100644 --- a/gstreamer-video/src/video_meta.rs +++ b/gstreamer-video/src/video_meta.rs @@ -179,6 +179,61 @@ impl fmt::Debug for VideoOverlayCompositionMeta { } } +#[cfg(any(feature = "v1_16", feature = "dox"))] +#[repr(C)] +pub struct VideoCaptionMeta(gst_video_sys::GstVideoCaptionMeta); + +#[cfg(any(feature = "v1_16", feature = "dox"))] +impl VideoCaptionMeta { + pub fn add<'a>( + buffer: &'a mut gst::BufferRef, + caption_type: ::VideoCaptionType, + data: &[u8], + ) -> gst::MetaRefMut<'a, Self, gst::meta::Standalone> { + unsafe { + let meta = gst_video_sys::gst_buffer_add_video_caption_meta( + buffer.as_mut_ptr(), + caption_type.to_glib(), + data.as_ptr(), + data.len(), + ); + + Self::from_mut_ptr(buffer, meta) + } + } + + pub fn get_caption_type(&self) -> ::VideoCaptionType { + from_glib(self.0.caption_type) + } + + pub fn get_data(&self) -> &[u8] { + unsafe { + use std::slice; + + slice::from_raw_parts(self.0.data, self.0.size) + } + } +} + +#[cfg(any(feature = "v1_16", feature = "dox"))] +unsafe impl MetaAPI for VideoCaptionMeta { + type GstType = gst_video_sys::GstVideoCaptionMeta; + + fn get_meta_api() -> glib::Type { + unsafe { from_glib(gst_video_sys::gst_video_caption_meta_api_get_type()) } + } +} + +#[cfg(any(feature = "v1_16", feature = "dox"))] +impl fmt::Debug for VideoCaptionMeta { + fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + f.debug_struct("VideoCaptionMeta") + .field("caption_type", &self.get_caption_type()) + .field("data", &self.get_data()) + .finish() + } +} + #[cfg(test)] mod tests { use super::*;