video: Add AncillaryMeta bindings

Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer-rs/-/merge_requests/1393>
This commit is contained in:
Sebastian Dröge 2024-02-12 16:26:01 +02:00
parent 798ee29b98
commit 7f9dd58718
4 changed files with 293 additions and 0 deletions

View file

@ -18,6 +18,7 @@ external_libraries = [
] ]
generate = [ generate = [
"GstVideo.AncillaryMetaField",
"GstVideo.ColorBalance", "GstVideo.ColorBalance",
"GstVideo.ColorBalanceChannel", "GstVideo.ColorBalanceChannel",
"GstVideo.ColorBalanceType", "GstVideo.ColorBalanceType",

View file

@ -5,6 +5,124 @@
use glib::{prelude::*, translate::*, GStr}; use glib::{prelude::*, translate::*, GStr};
#[cfg(feature = "v1_24")]
#[cfg_attr(docsrs, doc(cfg(feature = "v1_24")))]
#[derive(Debug, Eq, PartialEq, Ord, PartialOrd, Hash, Clone, Copy)]
#[non_exhaustive]
#[doc(alias = "GstAncillaryMetaField")]
pub enum AncillaryMetaField {
#[doc(alias = "GST_ANCILLARY_META_FIELD_PROGRESSIVE")]
Progressive,
#[doc(alias = "GST_ANCILLARY_META_FIELD_INTERLACED_FIRST")]
InterlacedFirst,
#[doc(alias = "GST_ANCILLARY_META_FIELD_INTERLACED_SECOND")]
InterlacedSecond,
#[doc(hidden)]
__Unknown(i32),
}
#[cfg(feature = "v1_24")]
#[cfg_attr(docsrs, doc(cfg(feature = "v1_24")))]
#[doc(hidden)]
impl IntoGlib for AncillaryMetaField {
type GlibType = ffi::GstAncillaryMetaField;
#[inline]
fn into_glib(self) -> ffi::GstAncillaryMetaField {
match self {
Self::Progressive => ffi::GST_ANCILLARY_META_FIELD_PROGRESSIVE,
Self::InterlacedFirst => ffi::GST_ANCILLARY_META_FIELD_INTERLACED_FIRST,
Self::InterlacedSecond => ffi::GST_ANCILLARY_META_FIELD_INTERLACED_SECOND,
Self::__Unknown(value) => value,
}
}
}
#[cfg(feature = "v1_24")]
#[cfg_attr(docsrs, doc(cfg(feature = "v1_24")))]
#[doc(hidden)]
impl FromGlib<ffi::GstAncillaryMetaField> for AncillaryMetaField {
#[inline]
unsafe fn from_glib(value: ffi::GstAncillaryMetaField) -> Self {
skip_assert_initialized!();
match value {
ffi::GST_ANCILLARY_META_FIELD_PROGRESSIVE => Self::Progressive,
ffi::GST_ANCILLARY_META_FIELD_INTERLACED_FIRST => Self::InterlacedFirst,
ffi::GST_ANCILLARY_META_FIELD_INTERLACED_SECOND => Self::InterlacedSecond,
value => Self::__Unknown(value),
}
}
}
#[cfg(feature = "v1_24")]
#[cfg_attr(docsrs, doc(cfg(feature = "v1_24")))]
impl StaticType for AncillaryMetaField {
#[inline]
#[doc(alias = "gst_ancillary_meta_field_get_type")]
fn static_type() -> glib::Type {
unsafe { from_glib(ffi::gst_ancillary_meta_field_get_type()) }
}
}
#[cfg(feature = "v1_24")]
#[cfg_attr(docsrs, doc(cfg(feature = "v1_24")))]
impl glib::HasParamSpec for AncillaryMetaField {
type ParamSpec = glib::ParamSpecEnum;
type SetValue = Self;
type BuilderFn = fn(&str, Self) -> glib::ParamSpecEnumBuilder<Self>;
fn param_spec_builder() -> Self::BuilderFn {
Self::ParamSpec::builder_with_default
}
}
#[cfg(feature = "v1_24")]
#[cfg_attr(docsrs, doc(cfg(feature = "v1_24")))]
impl glib::value::ValueType for AncillaryMetaField {
type Type = Self;
}
#[cfg(feature = "v1_24")]
#[cfg_attr(docsrs, doc(cfg(feature = "v1_24")))]
unsafe impl<'a> glib::value::FromValue<'a> for AncillaryMetaField {
type Checker = glib::value::GenericValueTypeChecker<Self>;
#[inline]
unsafe fn from_value(value: &'a glib::Value) -> Self {
skip_assert_initialized!();
from_glib(glib::gobject_ffi::g_value_get_enum(value.to_glib_none().0))
}
}
#[cfg(feature = "v1_24")]
#[cfg_attr(docsrs, doc(cfg(feature = "v1_24")))]
impl ToValue for AncillaryMetaField {
#[inline]
fn to_value(&self) -> glib::Value {
let mut value = glib::Value::for_value_type::<Self>();
unsafe {
glib::gobject_ffi::g_value_set_enum(value.to_glib_none_mut().0, self.into_glib());
}
value
}
#[inline]
fn value_type(&self) -> glib::Type {
Self::static_type()
}
}
#[cfg(feature = "v1_24")]
#[cfg_attr(docsrs, doc(cfg(feature = "v1_24")))]
impl From<AncillaryMetaField> for glib::Value {
#[inline]
fn from(v: AncillaryMetaField) -> Self {
skip_assert_initialized!();
ToValue::to_value(&v)
}
}
#[derive(Debug, Eq, PartialEq, Ord, PartialOrd, Hash, Clone, Copy)] #[derive(Debug, Eq, PartialEq, Ord, PartialOrd, Hash, Clone, Copy)]
#[non_exhaustive] #[non_exhaustive]
#[doc(alias = "GstColorBalanceType")] #[doc(alias = "GstColorBalanceType")]

View file

@ -62,6 +62,9 @@ mod video_sink;
pub use self::video_sink::VideoSink; pub use self::video_sink::VideoSink;
mod enums; mod enums;
#[cfg(feature = "v1_24")]
#[cfg_attr(docsrs, doc(cfg(feature = "v1_24")))]
pub use self::enums::AncillaryMetaField;
pub use self::enums::ColorBalanceType; pub use self::enums::ColorBalanceType;
pub use self::enums::NavigationCommand; pub use self::enums::NavigationCommand;
pub use self::enums::NavigationEventType; pub use self::enums::NavigationEventType;

View file

@ -990,6 +990,177 @@ unsafe impl MetaAPI for VideoSeiUserDataUnregisteredMeta {
} }
} }
#[cfg(feature = "v1_24")]
#[cfg_attr(docsrs, doc(cfg(feature = "v1_24")))]
#[repr(transparent)]
#[doc(alias = "GstAncillaryMeta")]
pub struct AncillaryMeta(ffi::GstAncillaryMeta);
#[cfg(feature = "v1_24")]
#[cfg_attr(docsrs, doc(cfg(feature = "v1_24")))]
unsafe impl Send for AncillaryMeta {}
#[cfg(feature = "v1_24")]
#[cfg_attr(docsrs, doc(cfg(feature = "v1_24")))]
unsafe impl Sync for AncillaryMeta {}
#[cfg(feature = "v1_24")]
#[cfg_attr(docsrs, doc(cfg(feature = "v1_24")))]
impl AncillaryMeta {
#[doc(alias = "gst_buffer_add_ancillary_meta")]
pub fn add(buffer: &mut gst::BufferRef) -> gst::MetaRefMut<Self, gst::meta::Standalone> {
skip_assert_initialized!();
unsafe {
let meta = ffi::gst_buffer_add_ancillary_meta(buffer.as_mut_ptr());
Self::from_mut_ptr(buffer, meta)
}
}
#[inline]
pub fn field(&self) -> crate::AncillaryMetaField {
unsafe { from_glib(self.0.field) }
}
#[inline]
pub fn set_field(&mut self, field: crate::AncillaryMetaField) {
self.0.field = field.into_glib();
}
#[inline]
pub fn c_not_y_channel(&self) -> bool {
unsafe { from_glib(self.0.c_not_y_channel) }
}
#[inline]
pub fn set_c_not_y_channel(&mut self, c_not_y_channel: bool) {
self.0.c_not_y_channel = c_not_y_channel.into_glib();
}
#[inline]
pub fn line(&self) -> u16 {
self.0.line
}
#[inline]
pub fn set_line(&mut self, line: u16) {
self.0.line = line;
}
#[inline]
pub fn offset(&self) -> u16 {
self.0.offset
}
#[inline]
pub fn set_offset(&mut self, offset: u16) {
self.0.offset = offset;
}
#[inline]
pub fn did(&self) -> u16 {
self.0.DID
}
#[inline]
pub fn set_did(&mut self, did: u16) {
self.0.DID = did;
}
#[inline]
pub fn sdid_block_number(&self) -> u16 {
self.0.SDID_block_number
}
#[inline]
pub fn set_sdid_block_number(&mut self, sdid_block_number: u16) {
self.0.SDID_block_number = sdid_block_number;
}
#[inline]
pub fn data_count(&self) -> u16 {
self.0.data_count
}
#[inline]
pub fn checksum(&self) -> u16 {
self.0.checksum
}
#[inline]
pub fn set_checksum(&mut self, checksum: u16) {
self.0.checksum = checksum;
}
#[inline]
pub fn data(&self) -> &[u16] {
if self.0.data_count & 0xff == 0 {
return &[];
}
unsafe {
use std::slice;
slice::from_raw_parts(self.0.data, (self.0.data_count & 0xff) as usize)
}
}
#[inline]
pub fn data_mut(&mut self) -> &mut [u16] {
if self.0.data_count & 0xff == 0 {
return &mut [];
}
unsafe {
use std::slice;
slice::from_raw_parts_mut(self.0.data, (self.0.data_count & 0xff) as usize)
}
}
#[inline]
pub fn set_data(&mut self, data: glib::Slice<u16>) {
unsafe {
assert!(data.len() < 256);
self.0.data_count = data.len() as u16;
self.0.data = data.into_glib_ptr();
}
}
#[inline]
pub fn set_data_count_upper_two_bits(&mut self, upper_two_bits: u8) {
assert!(upper_two_bits & !0x03 == 0);
self.0.data_count = ((upper_two_bits as u16) << 8) | self.0.data_count & 0xff;
}
}
#[cfg(feature = "v1_24")]
#[cfg_attr(docsrs, doc(cfg(feature = "v1_24")))]
unsafe impl MetaAPI for AncillaryMeta {
type GstType = ffi::GstAncillaryMeta;
#[doc(alias = "gst_ancillary_meta_api_get_type")]
#[inline]
fn meta_api() -> glib::Type {
unsafe { from_glib(ffi::gst_ancillary_meta_api_get_type()) }
}
}
#[cfg(feature = "v1_24")]
#[cfg_attr(docsrs, doc(cfg(feature = "v1_24")))]
impl fmt::Debug for AncillaryMeta {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
f.debug_struct("AncillaryMeta")
.field("field", &self.field())
.field("c_not_y_channel", &self.c_not_y_channel())
.field("line", &self.line())
.field("offset", &self.offset())
.field("did", &self.did())
.field("sdid_block_number", &self.sdid_block_number())
.field("data_count", &self.data_count())
.field("data", &self.data())
.field("checksum", &self.checksum())
.finish()
}
}
#[cfg(test)] #[cfg(test)]
mod tests { mod tests {
use super::*; use super::*;