2020-12-15 10:53:31 +00:00
|
|
|
// Take a look at the license at the top of the repository in the LICENSE file.
|
2018-09-29 08:13:57 +00:00
|
|
|
|
2023-05-04 05:55:48 +00:00
|
|
|
#[cfg(feature = "v1_20")]
|
|
|
|
#[cfg_attr(docsrs, doc(cfg(feature = "v1_20")))]
|
2022-09-28 17:10:54 +00:00
|
|
|
use std::ptr;
|
2023-12-10 18:35:43 +00:00
|
|
|
use std::{
|
|
|
|
fmt,
|
|
|
|
marker::PhantomData,
|
|
|
|
ops::{self, RangeBounds},
|
|
|
|
};
|
2018-09-29 08:13:57 +00:00
|
|
|
|
2021-09-19 11:19:45 +00:00
|
|
|
use glib::translate::*;
|
2018-09-29 08:13:57 +00:00
|
|
|
|
2023-01-03 18:58:25 +00:00
|
|
|
use crate::{Buffer, BufferRef, Caps, CapsRef, ClockTime};
|
|
|
|
|
2019-12-18 15:04:42 +00:00
|
|
|
pub unsafe trait MetaAPI: Sync + Send + Sized {
|
2018-09-29 08:13:57 +00:00
|
|
|
type GstType;
|
|
|
|
|
2021-05-02 09:41:18 +00:00
|
|
|
#[doc(alias = "get_meta_api")]
|
2021-04-20 10:23:24 +00:00
|
|
|
fn meta_api() -> glib::Type;
|
2023-06-30 05:50:03 +00:00
|
|
|
}
|
2018-09-29 08:13:57 +00:00
|
|
|
|
2023-06-30 05:50:03 +00:00
|
|
|
pub trait MetaAPIExt: MetaAPI {
|
2022-12-18 08:18:31 +00:00
|
|
|
#[inline]
|
2018-10-11 08:30:54 +00:00
|
|
|
unsafe fn from_ptr(buffer: &BufferRef, ptr: *const Self::GstType) -> MetaRef<Self> {
|
2022-12-25 10:47:02 +00:00
|
|
|
debug_assert!(!ptr.is_null());
|
2018-09-29 08:13:57 +00:00
|
|
|
|
2021-04-20 10:24:17 +00:00
|
|
|
let meta_api = Self::meta_api();
|
2021-02-25 10:38:10 +00:00
|
|
|
if meta_api != glib::Type::INVALID {
|
2022-12-25 10:47:02 +00:00
|
|
|
debug_assert_eq!(
|
2018-09-29 08:13:57 +00:00
|
|
|
meta_api,
|
2020-11-21 13:46:48 +00:00
|
|
|
from_glib((*(*(ptr as *const ffi::GstMeta)).info).api)
|
2018-09-29 08:13:57 +00:00
|
|
|
)
|
|
|
|
}
|
|
|
|
|
|
|
|
MetaRef {
|
2018-10-11 08:31:28 +00:00
|
|
|
meta: &*(ptr as *const Self),
|
2018-09-29 08:13:57 +00:00
|
|
|
buffer,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-12-18 08:18:31 +00:00
|
|
|
#[inline]
|
2018-10-11 08:30:54 +00:00
|
|
|
unsafe fn from_mut_ptr<T>(
|
|
|
|
buffer: &mut BufferRef,
|
2018-09-29 08:13:57 +00:00
|
|
|
ptr: *mut Self::GstType,
|
2018-10-11 08:30:54 +00:00
|
|
|
) -> MetaRefMut<Self, T> {
|
2022-12-25 10:47:02 +00:00
|
|
|
debug_assert!(!ptr.is_null());
|
2018-09-29 08:13:57 +00:00
|
|
|
|
2021-04-20 10:24:17 +00:00
|
|
|
let meta_api = Self::meta_api();
|
2021-02-25 10:38:10 +00:00
|
|
|
if meta_api != glib::Type::INVALID {
|
2022-12-25 10:47:02 +00:00
|
|
|
debug_assert_eq!(
|
2018-09-29 08:13:57 +00:00
|
|
|
meta_api,
|
2020-11-21 13:46:48 +00:00
|
|
|
from_glib((*(*(ptr as *const ffi::GstMeta)).info).api)
|
2018-09-29 08:13:57 +00:00
|
|
|
)
|
|
|
|
}
|
|
|
|
|
|
|
|
MetaRefMut {
|
2018-10-11 08:31:28 +00:00
|
|
|
meta: &mut *(ptr as *mut Self),
|
2018-09-29 08:13:57 +00:00
|
|
|
buffer,
|
|
|
|
mode: PhantomData,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-10-16 12:19:52 +00:00
|
|
|
impl<A: MetaAPI> MetaAPIExt for A {}
|
|
|
|
|
2023-05-04 05:55:48 +00:00
|
|
|
#[cfg(feature = "v1_16")]
|
|
|
|
#[cfg_attr(docsrs, doc(cfg(feature = "v1_16")))]
|
2020-01-24 15:46:18 +00:00
|
|
|
#[derive(Debug, Clone, Copy, PartialOrd, Ord, PartialEq, Eq)]
|
|
|
|
pub struct MetaSeqnum(u64);
|
|
|
|
|
2021-09-19 11:19:45 +00:00
|
|
|
pub struct MetaRef<'a, T: 'a> {
|
2018-09-29 08:13:57 +00:00
|
|
|
meta: &'a T,
|
2018-09-29 22:17:12 +00:00
|
|
|
buffer: &'a BufferRef,
|
2018-09-29 08:13:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
pub enum Standalone {}
|
|
|
|
pub enum Iterated {}
|
|
|
|
|
2021-09-19 11:19:45 +00:00
|
|
|
pub struct MetaRefMut<'a, T: 'a, U> {
|
2018-09-29 08:13:57 +00:00
|
|
|
meta: &'a mut T,
|
2018-09-29 22:17:12 +00:00
|
|
|
buffer: &'a mut BufferRef,
|
2018-09-29 08:13:57 +00:00
|
|
|
mode: PhantomData<U>,
|
|
|
|
}
|
|
|
|
|
2021-09-19 11:19:45 +00:00
|
|
|
impl<'a, T: fmt::Debug + 'a> fmt::Debug for MetaRef<'a, T> {
|
2020-01-22 17:08:27 +00:00
|
|
|
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
|
|
|
f.debug_struct("MetaRef")
|
|
|
|
.field("meta", &self.meta)
|
|
|
|
.field("buffer", &self.buffer)
|
|
|
|
.finish()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-09-19 11:19:45 +00:00
|
|
|
impl<'a, T: fmt::Debug + 'a, U> fmt::Debug for MetaRefMut<'a, T, U> {
|
2020-01-22 17:08:27 +00:00
|
|
|
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
|
|
|
f.debug_struct("MetaRef")
|
|
|
|
.field("meta", &self.meta)
|
|
|
|
.field("buffer", &self.buffer)
|
|
|
|
.field("mode", &self.mode)
|
|
|
|
.finish()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-09-19 11:19:45 +00:00
|
|
|
impl<'a, T> ops::Deref for MetaRef<'a, T> {
|
2018-09-29 08:13:57 +00:00
|
|
|
type Target = T;
|
|
|
|
|
2022-12-18 08:18:31 +00:00
|
|
|
#[inline]
|
2018-09-29 08:13:57 +00:00
|
|
|
fn deref(&self) -> &T {
|
|
|
|
self.meta
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-09-19 11:19:45 +00:00
|
|
|
impl<'a, T> AsRef<MetaRef<'a, T>> for MetaRef<'a, T> {
|
2022-12-18 08:18:31 +00:00
|
|
|
#[inline]
|
2018-09-29 08:13:57 +00:00
|
|
|
fn as_ref(&self) -> &MetaRef<'a, T> {
|
|
|
|
self
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-10-26 10:38:07 +00:00
|
|
|
impl<'a, T> AsRef<T> for MetaRef<'a, T> {
|
|
|
|
#[inline]
|
|
|
|
fn as_ref(&self) -> &T {
|
|
|
|
self.meta
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-12-04 16:18:09 +00:00
|
|
|
impl<'a, T: 'a> Clone for MetaRef<'a, T> {
|
|
|
|
fn clone(&self) -> Self {
|
|
|
|
MetaRef {
|
|
|
|
meta: self.meta,
|
|
|
|
buffer: self.buffer,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-09-19 11:19:45 +00:00
|
|
|
impl<'a, T, U> ops::Deref for MetaRefMut<'a, T, U> {
|
2018-09-29 08:13:57 +00:00
|
|
|
type Target = T;
|
|
|
|
|
2022-12-18 08:18:31 +00:00
|
|
|
#[inline]
|
2018-09-29 08:13:57 +00:00
|
|
|
fn deref(&self) -> &T {
|
|
|
|
self.meta
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-09-19 11:19:45 +00:00
|
|
|
impl<'a, T, U> ops::DerefMut for MetaRefMut<'a, T, U> {
|
2022-12-18 08:18:31 +00:00
|
|
|
#[inline]
|
2018-09-29 08:13:57 +00:00
|
|
|
fn deref_mut(&mut self) -> &mut T {
|
|
|
|
self.meta
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-09-19 11:19:45 +00:00
|
|
|
impl<'a, T, U> AsRef<MetaRef<'a, T>> for MetaRefMut<'a, T, U> {
|
2022-12-18 08:18:31 +00:00
|
|
|
#[inline]
|
2018-09-29 08:13:57 +00:00
|
|
|
fn as_ref(&self) -> &MetaRef<'a, T> {
|
2018-10-11 08:31:28 +00:00
|
|
|
unsafe { &*(self as *const MetaRefMut<'a, T, U> as *const MetaRef<'a, T>) }
|
2018-09-29 08:13:57 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-10-26 10:38:07 +00:00
|
|
|
impl<'a, T, U> AsMut<T> for MetaRefMut<'a, T, U> {
|
|
|
|
#[inline]
|
|
|
|
fn as_mut(&mut self) -> &mut T {
|
|
|
|
self.meta
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-09-19 11:19:45 +00:00
|
|
|
impl<'a, T> MetaRef<'a, T> {
|
2021-05-02 09:41:18 +00:00
|
|
|
#[doc(alias = "get_api")]
|
2022-12-18 08:18:31 +00:00
|
|
|
#[inline]
|
2021-04-11 19:39:50 +00:00
|
|
|
pub fn api(&self) -> glib::Type {
|
2018-09-29 08:13:57 +00:00
|
|
|
unsafe {
|
2020-11-21 13:46:48 +00:00
|
|
|
let meta = self.meta as *const _ as *const ffi::GstMeta;
|
2018-09-29 08:13:57 +00:00
|
|
|
let info = (*meta).info;
|
|
|
|
glib::Type::from_glib((*info).api)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-12-18 08:18:31 +00:00
|
|
|
#[inline]
|
2021-11-16 11:05:47 +00:00
|
|
|
pub fn flags(&self) -> crate::MetaFlags {
|
|
|
|
unsafe {
|
|
|
|
let meta = self.meta as *const _ as *const ffi::GstMeta;
|
|
|
|
from_glib((*meta).flags)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-12-18 08:18:31 +00:00
|
|
|
#[inline]
|
2021-09-19 11:55:29 +00:00
|
|
|
pub fn type_(&self) -> glib::Type {
|
|
|
|
unsafe {
|
|
|
|
let meta = self.meta as *const _ as *const ffi::GstMeta;
|
|
|
|
let info = (*meta).info;
|
|
|
|
glib::Type::from_glib((*info).type_)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-05-04 05:55:48 +00:00
|
|
|
#[cfg(feature = "v1_16")]
|
|
|
|
#[cfg_attr(docsrs, doc(cfg(feature = "v1_16")))]
|
2021-05-02 09:41:18 +00:00
|
|
|
#[doc(alias = "get_seqnum")]
|
2021-05-19 20:35:47 +00:00
|
|
|
#[doc(alias = "gst_meta_get_seqnum")]
|
2022-12-18 08:18:31 +00:00
|
|
|
#[inline]
|
2021-04-11 19:39:50 +00:00
|
|
|
pub fn seqnum(&self) -> MetaSeqnum {
|
2019-04-23 16:53:10 +00:00
|
|
|
unsafe {
|
2020-11-21 13:46:48 +00:00
|
|
|
let meta = self.meta as *const _ as *const ffi::GstMeta;
|
|
|
|
MetaSeqnum(ffi::gst_meta_get_seqnum(meta))
|
2019-04-23 16:53:10 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-10-26 10:40:12 +00:00
|
|
|
#[inline]
|
|
|
|
#[doc(alias = "gst_meta_api_type_has_tag")]
|
|
|
|
pub fn has_tag(&self, tag: glib::Quark) -> bool {
|
|
|
|
unsafe {
|
|
|
|
from_glib(ffi::gst_meta_api_type_has_tag(
|
|
|
|
self.api().into_glib(),
|
|
|
|
tag.into_glib(),
|
|
|
|
))
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#[inline]
|
|
|
|
#[doc(alias = "gst_meta_api_type_get_tags")]
|
2023-11-03 09:48:23 +00:00
|
|
|
pub fn tags<'b>(&self) -> &'b [glib::GStringPtr] {
|
2023-10-26 10:40:12 +00:00
|
|
|
unsafe {
|
|
|
|
glib::StrV::from_glib_borrow(ffi::gst_meta_api_type_get_tags(self.api().into_glib()))
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-10-26 10:39:44 +00:00
|
|
|
#[inline]
|
|
|
|
pub fn upcast_ref(&self) -> &MetaRef<'a, Meta> {
|
|
|
|
unsafe { &*(self as *const MetaRef<'a, T> as *const MetaRef<'a, Meta>) }
|
|
|
|
}
|
|
|
|
|
2023-11-03 09:55:20 +00:00
|
|
|
pub fn copy(
|
|
|
|
&self,
|
|
|
|
buffer: &mut BufferRef,
|
|
|
|
region: bool,
|
2023-12-10 18:35:43 +00:00
|
|
|
range: impl RangeBounds<usize>,
|
2023-11-03 09:55:20 +00:00
|
|
|
) -> Result<(), glib::BoolError>
|
|
|
|
where
|
|
|
|
T: MetaAPI,
|
|
|
|
{
|
2024-01-29 16:31:21 +00:00
|
|
|
static TRANSFORM_COPY: std::sync::OnceLock<glib::Quark> = std::sync::OnceLock::new();
|
2023-11-03 09:55:20 +00:00
|
|
|
|
2024-01-29 16:31:21 +00:00
|
|
|
let transform_copy = TRANSFORM_COPY.get_or_init(|| glib::Quark::from_str("gst-copy"));
|
2023-11-03 09:55:20 +00:00
|
|
|
|
2023-12-10 18:35:43 +00:00
|
|
|
let (offset, size) = self.buffer.byte_range_into_offset_len(range)?;
|
|
|
|
|
2023-11-03 09:55:20 +00:00
|
|
|
unsafe {
|
|
|
|
let info = *(*self.upcast_ref().as_ptr()).info;
|
|
|
|
let Some(transform_func) = info.transform_func else {
|
|
|
|
return Err(glib::bool_error!(
|
|
|
|
"Can't copy meta without transform function"
|
|
|
|
));
|
|
|
|
};
|
|
|
|
|
|
|
|
let mut copy_data = ffi::GstMetaTransformCopy {
|
|
|
|
region: region.into_glib(),
|
|
|
|
offset,
|
2023-12-10 18:35:43 +00:00
|
|
|
size,
|
2023-11-03 09:55:20 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
glib::result_from_gboolean!(
|
|
|
|
transform_func(
|
|
|
|
buffer.as_mut_ptr(),
|
|
|
|
mut_override(self.upcast_ref().as_ptr()),
|
|
|
|
mut_override(self.buffer.as_ptr()),
|
2024-01-29 16:31:21 +00:00
|
|
|
transform_copy.into_glib(),
|
2023-11-03 09:55:20 +00:00
|
|
|
&mut copy_data as *mut _ as *mut _,
|
|
|
|
),
|
|
|
|
"Failed to copy meta"
|
|
|
|
)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-12-18 08:18:31 +00:00
|
|
|
#[inline]
|
2021-09-19 11:19:45 +00:00
|
|
|
pub fn as_ptr(&self) -> *const T::GstType
|
|
|
|
where
|
|
|
|
T: MetaAPI,
|
|
|
|
{
|
2018-09-29 08:13:57 +00:00
|
|
|
self.meta as *const _ as *const <T as MetaAPI>::GstType
|
|
|
|
}
|
2023-12-19 10:12:58 +00:00
|
|
|
|
|
|
|
#[cfg(feature = "v1_24")]
|
|
|
|
#[cfg_attr(docsrs, doc(cfg(feature = "v1_24")))]
|
|
|
|
#[doc(alias = "gst_meta_serialize")]
|
|
|
|
pub fn serialize<B: ByteArrayInterface + ?Sized>(
|
|
|
|
&self,
|
|
|
|
writer: &mut B,
|
|
|
|
) -> Result<usize, glib::BoolError> {
|
|
|
|
unsafe {
|
|
|
|
#[repr(C)]
|
|
|
|
struct Writer<'a, B: ?Sized> {
|
|
|
|
iface_: ffi::GstByteArrayInterface,
|
|
|
|
writer: &'a mut B,
|
|
|
|
}
|
|
|
|
|
|
|
|
unsafe extern "C" fn resize<B: ByteArrayInterface + ?Sized>(
|
|
|
|
iface_: *mut ffi::GstByteArrayInterface,
|
|
|
|
size: usize,
|
|
|
|
) -> glib::ffi::gboolean {
|
|
|
|
let iface_ = &mut *(iface_ as *mut Writer<B>);
|
|
|
|
|
|
|
|
match iface_.writer.resize(size) {
|
|
|
|
Some(new_data) => {
|
|
|
|
iface_.iface_.data = new_data.as_mut_ptr();
|
|
|
|
iface_.iface_.len = size;
|
|
|
|
|
|
|
|
glib::ffi::GTRUE
|
|
|
|
}
|
|
|
|
None => glib::ffi::GFALSE,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
let initial_len = writer.initial_len();
|
|
|
|
|
|
|
|
let mut iface_ = Writer {
|
|
|
|
iface_: ffi::GstByteArrayInterface {
|
|
|
|
data: writer.as_mut().as_mut_ptr(),
|
|
|
|
len: initial_len,
|
|
|
|
resize: Some(resize::<B>),
|
|
|
|
_gst_reserved: [ptr::null_mut(); 4],
|
|
|
|
},
|
|
|
|
writer: &mut *writer,
|
|
|
|
};
|
|
|
|
|
|
|
|
let res = bool::from_glib(ffi::gst_meta_serialize(
|
|
|
|
self.meta as *const T as *const ffi::GstMeta,
|
|
|
|
&mut iface_.iface_,
|
|
|
|
));
|
|
|
|
|
|
|
|
if !res {
|
|
|
|
return Err(glib::bool_error!("Failed to serialize meta"));
|
|
|
|
}
|
|
|
|
|
|
|
|
assert!(iface_.iface_.len >= initial_len);
|
|
|
|
|
|
|
|
Ok(iface_.iface_.len - initial_len)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#[cfg(feature = "v1_24")]
|
|
|
|
#[cfg_attr(docsrs, doc(cfg(feature = "v1_24")))]
|
|
|
|
pub trait ByteArrayInterface: AsMut<[u8]> {
|
|
|
|
fn initial_len(&self) -> usize;
|
|
|
|
fn resize(&mut self, size: usize) -> Option<&mut [u8]>;
|
|
|
|
}
|
|
|
|
|
|
|
|
#[cfg(feature = "v1_24")]
|
|
|
|
#[cfg_attr(docsrs, doc(cfg(feature = "v1_24")))]
|
|
|
|
impl ByteArrayInterface for Vec<u8> {
|
|
|
|
fn initial_len(&self) -> usize {
|
|
|
|
self.len()
|
|
|
|
}
|
|
|
|
|
|
|
|
fn resize(&mut self, size: usize) -> Option<&mut [u8]> {
|
|
|
|
self.resize(size, 0);
|
|
|
|
Some(&mut self[0..size])
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#[cfg(feature = "v1_24")]
|
|
|
|
#[cfg_attr(docsrs, doc(cfg(feature = "v1_24")))]
|
|
|
|
impl<A: smallvec::Array<Item = u8>> ByteArrayInterface for smallvec::SmallVec<A> {
|
|
|
|
fn initial_len(&self) -> usize {
|
|
|
|
self.len()
|
|
|
|
}
|
|
|
|
|
|
|
|
fn resize(&mut self, size: usize) -> Option<&mut [u8]> {
|
|
|
|
self.resize(size, 0);
|
|
|
|
Some(&mut self[0..size])
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#[cfg(feature = "v1_24")]
|
|
|
|
#[cfg_attr(docsrs, doc(cfg(feature = "v1_24")))]
|
|
|
|
impl ByteArrayInterface for &mut [u8] {
|
|
|
|
fn initial_len(&self) -> usize {
|
|
|
|
0
|
|
|
|
}
|
|
|
|
|
|
|
|
fn resize(&mut self, size: usize) -> Option<&mut [u8]> {
|
|
|
|
if self.len() < size {
|
|
|
|
return None;
|
|
|
|
}
|
|
|
|
|
|
|
|
Some(&mut self[0..size])
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#[cfg(feature = "v1_24")]
|
|
|
|
#[cfg_attr(docsrs, doc(cfg(feature = "v1_24")))]
|
|
|
|
impl<const N: usize> ByteArrayInterface for [u8; N] {
|
|
|
|
fn initial_len(&self) -> usize {
|
|
|
|
0
|
|
|
|
}
|
|
|
|
|
|
|
|
fn resize(&mut self, size: usize) -> Option<&mut [u8]> {
|
|
|
|
if N < size {
|
|
|
|
return None;
|
|
|
|
}
|
|
|
|
|
|
|
|
Some(&mut self[0..size])
|
|
|
|
}
|
2018-09-29 08:13:57 +00:00
|
|
|
}
|
|
|
|
|
2018-09-29 22:17:12 +00:00
|
|
|
impl<'a> MetaRef<'a, Meta> {
|
2022-12-18 08:18:31 +00:00
|
|
|
#[inline]
|
2018-09-29 08:13:57 +00:00
|
|
|
pub fn downcast_ref<T: MetaAPI>(&self) -> Option<&MetaRef<'a, T>> {
|
2021-04-20 10:24:17 +00:00
|
|
|
let target_type = T::meta_api();
|
2021-04-11 19:39:50 +00:00
|
|
|
let type_ = self.api();
|
2018-09-29 08:13:57 +00:00
|
|
|
|
2021-02-25 10:38:10 +00:00
|
|
|
if type_ == glib::Type::INVALID || target_type == type_ {
|
2018-10-11 08:31:28 +00:00
|
|
|
Some(unsafe { &*(self as *const MetaRef<'a, Meta> as *const MetaRef<'a, T>) })
|
2018-09-29 08:13:57 +00:00
|
|
|
} else {
|
|
|
|
None
|
|
|
|
}
|
|
|
|
}
|
2021-09-19 11:19:58 +00:00
|
|
|
|
2023-05-04 05:55:48 +00:00
|
|
|
#[cfg(feature = "v1_20")]
|
|
|
|
#[cfg_attr(docsrs, doc(cfg(feature = "v1_20")))]
|
2022-12-18 08:18:31 +00:00
|
|
|
#[inline]
|
2021-09-19 11:19:58 +00:00
|
|
|
pub fn try_as_custom_meta(&self) -> Option<&MetaRef<'a, CustomMeta>> {
|
|
|
|
unsafe {
|
|
|
|
if ffi::gst_meta_info_is_custom(&*self.0.info) == glib::ffi::GFALSE {
|
|
|
|
return None;
|
|
|
|
}
|
|
|
|
|
|
|
|
Some(&*(self as *const MetaRef<'a, Meta> as *const MetaRef<'a, CustomMeta>))
|
|
|
|
}
|
|
|
|
}
|
2018-09-29 08:13:57 +00:00
|
|
|
}
|
|
|
|
|
2021-09-19 11:19:45 +00:00
|
|
|
impl<'a, T, U> MetaRefMut<'a, T, U> {
|
2021-05-02 09:41:18 +00:00
|
|
|
#[doc(alias = "get_api")]
|
2022-12-18 08:18:31 +00:00
|
|
|
#[inline]
|
2021-04-11 19:39:50 +00:00
|
|
|
pub fn api(&self) -> glib::Type {
|
2023-11-03 09:49:41 +00:00
|
|
|
self.as_meta_ref().api()
|
2018-09-29 08:13:57 +00:00
|
|
|
}
|
|
|
|
|
2022-12-18 08:18:31 +00:00
|
|
|
#[inline]
|
2021-11-16 11:05:47 +00:00
|
|
|
pub fn flags(&self) -> crate::MetaFlags {
|
2023-11-03 09:49:41 +00:00
|
|
|
self.as_meta_ref().flags()
|
2021-11-16 11:05:47 +00:00
|
|
|
}
|
|
|
|
|
2022-12-18 08:18:31 +00:00
|
|
|
#[inline]
|
2021-09-19 11:55:29 +00:00
|
|
|
pub fn type_(&self) -> glib::Type {
|
2023-11-03 09:49:41 +00:00
|
|
|
self.as_meta_ref().type_()
|
2021-09-19 11:55:29 +00:00
|
|
|
}
|
|
|
|
|
2023-05-04 05:55:48 +00:00
|
|
|
#[cfg(feature = "v1_16")]
|
|
|
|
#[cfg_attr(docsrs, doc(cfg(feature = "v1_16")))]
|
2021-05-02 09:41:18 +00:00
|
|
|
#[doc(alias = "get_seqnum")]
|
2021-05-19 20:35:47 +00:00
|
|
|
#[doc(alias = "gst_meta_get_seqnum")]
|
2022-12-18 08:18:31 +00:00
|
|
|
#[inline]
|
2023-11-03 09:49:41 +00:00
|
|
|
pub fn seqnum(&self) -> MetaSeqnum {
|
|
|
|
self.as_meta_ref().seqnum()
|
2019-04-23 16:53:10 +00:00
|
|
|
}
|
|
|
|
|
2023-10-26 10:40:12 +00:00
|
|
|
#[inline]
|
|
|
|
#[doc(alias = "gst_meta_api_type_has_tag")]
|
|
|
|
pub fn has_tag(&self, tag: glib::Quark) -> bool {
|
2023-11-03 09:49:41 +00:00
|
|
|
self.as_meta_ref().has_tag(tag)
|
2023-10-26 10:40:12 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#[inline]
|
|
|
|
#[doc(alias = "gst_meta_api_type_get_tags")]
|
2023-11-03 09:48:23 +00:00
|
|
|
pub fn tags<'b>(&self) -> &'b [glib::GStringPtr] {
|
2023-11-03 09:49:41 +00:00
|
|
|
self.as_meta_ref().tags()
|
2023-10-26 10:40:12 +00:00
|
|
|
}
|
|
|
|
|
2022-12-18 08:18:31 +00:00
|
|
|
#[inline]
|
2023-10-26 10:39:44 +00:00
|
|
|
pub fn upcast_ref(&self) -> &MetaRef<'a, Meta> {
|
|
|
|
unsafe { &*(self as *const MetaRefMut<'a, T, U> as *const MetaRef<'a, Meta>) }
|
|
|
|
}
|
|
|
|
|
|
|
|
#[inline]
|
2024-02-09 08:24:40 +00:00
|
|
|
pub fn upcast_mut(&mut self) -> &mut MetaRefMut<'a, Meta, U> {
|
2023-10-26 10:39:44 +00:00
|
|
|
unsafe { &mut *(self as *mut MetaRefMut<'a, T, U> as *mut MetaRefMut<'a, Meta, U>) }
|
|
|
|
}
|
|
|
|
|
2023-11-03 09:49:41 +00:00
|
|
|
#[inline]
|
|
|
|
pub fn as_meta_ref(&self) -> MetaRef<T> {
|
|
|
|
MetaRef {
|
|
|
|
meta: self.meta,
|
|
|
|
buffer: self.buffer,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-11-03 09:55:20 +00:00
|
|
|
pub fn copy(
|
|
|
|
&self,
|
|
|
|
buffer: &mut BufferRef,
|
|
|
|
region: bool,
|
2023-12-10 18:35:43 +00:00
|
|
|
range: impl RangeBounds<usize>,
|
2023-11-03 09:55:20 +00:00
|
|
|
) -> Result<(), glib::BoolError>
|
|
|
|
where
|
|
|
|
T: MetaAPI,
|
|
|
|
{
|
2023-12-10 18:35:43 +00:00
|
|
|
self.as_meta_ref().copy(buffer, region, range)
|
2023-11-03 09:55:20 +00:00
|
|
|
}
|
|
|
|
|
2023-10-26 10:39:44 +00:00
|
|
|
#[inline]
|
2021-09-19 11:19:45 +00:00
|
|
|
pub fn as_ptr(&self) -> *const T::GstType
|
|
|
|
where
|
|
|
|
T: MetaAPI,
|
|
|
|
{
|
2018-09-29 08:13:57 +00:00
|
|
|
self.meta as *const _ as *const <T as MetaAPI>::GstType
|
|
|
|
}
|
|
|
|
|
2022-12-18 08:18:31 +00:00
|
|
|
#[inline]
|
2021-09-19 11:19:45 +00:00
|
|
|
pub fn as_mut_ptr(&mut self) -> *mut T::GstType
|
|
|
|
where
|
|
|
|
T: MetaAPI,
|
|
|
|
{
|
2018-09-29 08:13:57 +00:00
|
|
|
self.meta as *mut _ as *mut <T as MetaAPI>::GstType
|
|
|
|
}
|
2023-12-19 10:12:58 +00:00
|
|
|
|
|
|
|
#[cfg(feature = "v1_24")]
|
|
|
|
#[cfg_attr(docsrs, doc(cfg(feature = "v1_24")))]
|
|
|
|
#[doc(alias = "gst_meta_serialize")]
|
|
|
|
pub fn serialize<B: ByteArrayInterface + ?Sized>(
|
|
|
|
&self,
|
|
|
|
writer: &mut B,
|
|
|
|
) -> Result<usize, glib::BoolError> {
|
|
|
|
self.as_meta_ref().serialize(writer)
|
|
|
|
}
|
2024-02-09 08:25:02 +00:00
|
|
|
|
|
|
|
#[cfg(feature = "v1_24")]
|
|
|
|
#[cfg_attr(docsrs, doc(cfg(feature = "v1_24")))]
|
|
|
|
pub fn clear(&mut self) -> Result<(), glib::BoolError>
|
|
|
|
where
|
|
|
|
T: MetaAPI,
|
|
|
|
{
|
|
|
|
unsafe {
|
|
|
|
let info = *(*self.upcast_ref().as_ptr()).info;
|
|
|
|
|
|
|
|
if let Some(clear_func) = info.clear_func {
|
|
|
|
clear_func(self.buffer.as_mut_ptr(), self.upcast_mut().as_mut_ptr());
|
|
|
|
Ok(())
|
|
|
|
} else {
|
|
|
|
Err(glib::bool_error!("Failed to clear meta"))
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2018-09-29 08:13:57 +00:00
|
|
|
}
|
|
|
|
|
2021-09-19 11:19:45 +00:00
|
|
|
impl<'a, T> MetaRefMut<'a, T, Standalone> {
|
2021-05-19 20:35:47 +00:00
|
|
|
#[doc(alias = "gst_buffer_remove_meta")]
|
2021-11-16 11:08:23 +00:00
|
|
|
pub fn remove(self) -> Result<(), glib::BoolError> {
|
|
|
|
if self.flags().contains(crate::MetaFlags::LOCKED) {
|
|
|
|
return Err(glib::bool_error!("Can't remove locked meta"));
|
|
|
|
}
|
|
|
|
|
2018-09-29 08:13:57 +00:00
|
|
|
unsafe {
|
2020-11-21 13:46:48 +00:00
|
|
|
let res = ffi::gst_buffer_remove_meta(
|
2018-09-29 22:17:12 +00:00
|
|
|
self.buffer.as_mut_ptr(),
|
2021-09-19 11:19:45 +00:00
|
|
|
self.meta as *mut T as *mut ffi::GstMeta,
|
2018-09-29 22:17:12 +00:00
|
|
|
);
|
2022-12-25 10:47:02 +00:00
|
|
|
debug_assert_ne!(res, glib::ffi::GFALSE);
|
2021-11-16 11:08:23 +00:00
|
|
|
|
|
|
|
Ok(())
|
2018-09-29 08:13:57 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-09-29 22:17:12 +00:00
|
|
|
impl<'a, U> MetaRefMut<'a, Meta, U> {
|
2022-12-18 08:18:31 +00:00
|
|
|
#[inline]
|
2018-09-29 08:13:57 +00:00
|
|
|
pub fn downcast_ref<T: MetaAPI>(&mut self) -> Option<&MetaRefMut<'a, T, U>> {
|
2021-04-20 10:24:17 +00:00
|
|
|
let target_type = T::meta_api();
|
2021-04-11 19:39:50 +00:00
|
|
|
let type_ = self.api();
|
2018-09-29 08:13:57 +00:00
|
|
|
|
2021-02-25 10:38:10 +00:00
|
|
|
if type_ == glib::Type::INVALID || target_type == type_ {
|
2018-10-11 08:31:28 +00:00
|
|
|
Some(unsafe { &*(self as *mut MetaRefMut<'a, Meta, U> as *const MetaRefMut<'a, T, U>) })
|
2018-09-29 08:13:57 +00:00
|
|
|
} else {
|
|
|
|
None
|
|
|
|
}
|
|
|
|
}
|
2021-09-19 11:19:45 +00:00
|
|
|
|
2022-12-18 08:18:31 +00:00
|
|
|
#[inline]
|
2021-09-19 11:19:45 +00:00
|
|
|
pub fn downcast_mut<T: MetaAPI>(&mut self) -> Option<&mut MetaRefMut<'a, T, U>> {
|
|
|
|
let target_type = T::meta_api();
|
|
|
|
let type_ = self.api();
|
|
|
|
|
|
|
|
if type_ == glib::Type::INVALID || target_type == type_ {
|
|
|
|
Some(unsafe {
|
|
|
|
&mut *(self as *mut MetaRefMut<'a, Meta, U> as *mut MetaRefMut<'a, T, U>)
|
|
|
|
})
|
|
|
|
} else {
|
|
|
|
None
|
|
|
|
}
|
|
|
|
}
|
2021-09-19 11:19:58 +00:00
|
|
|
|
2023-05-04 05:55:48 +00:00
|
|
|
#[cfg(feature = "v1_20")]
|
|
|
|
#[cfg_attr(docsrs, doc(cfg(feature = "v1_20")))]
|
2022-12-18 08:18:31 +00:00
|
|
|
#[inline]
|
2021-09-19 11:19:58 +00:00
|
|
|
pub fn try_as_custom_meta(&self) -> Option<&MetaRefMut<'a, CustomMeta, U>> {
|
|
|
|
unsafe {
|
|
|
|
if ffi::gst_meta_info_is_custom(&*self.0.info) == glib::ffi::GFALSE {
|
|
|
|
return None;
|
|
|
|
}
|
|
|
|
|
|
|
|
Some(&*(self as *const MetaRefMut<'a, Meta, U> as *const MetaRefMut<'a, CustomMeta, U>))
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-05-04 05:55:48 +00:00
|
|
|
#[cfg(feature = "v1_20")]
|
|
|
|
#[cfg_attr(docsrs, doc(cfg(feature = "v1_20")))]
|
2022-12-18 08:18:31 +00:00
|
|
|
#[inline]
|
2021-09-19 11:19:58 +00:00
|
|
|
pub fn try_as_mut_custom_meta(&mut self) -> Option<&mut MetaRefMut<'a, CustomMeta, U>> {
|
|
|
|
unsafe {
|
|
|
|
if ffi::gst_meta_info_is_custom(&*self.0.info) == glib::ffi::GFALSE {
|
|
|
|
return None;
|
|
|
|
}
|
|
|
|
|
|
|
|
Some(&mut *(self as *mut MetaRefMut<'a, Meta, U> as *mut MetaRefMut<'a, CustomMeta, U>))
|
|
|
|
}
|
|
|
|
}
|
2018-09-29 08:13:57 +00:00
|
|
|
}
|
|
|
|
|
2020-10-24 17:06:59 +00:00
|
|
|
#[repr(transparent)]
|
2021-06-01 13:15:59 +00:00
|
|
|
#[doc(alias = "GstMeta")]
|
2020-11-21 13:46:48 +00:00
|
|
|
pub struct Meta(ffi::GstMeta);
|
2018-09-29 08:13:57 +00:00
|
|
|
|
2019-12-18 15:04:42 +00:00
|
|
|
unsafe impl Send for Meta {}
|
|
|
|
unsafe impl Sync for Meta {}
|
|
|
|
|
2018-09-29 22:17:12 +00:00
|
|
|
unsafe impl MetaAPI for Meta {
|
2020-11-21 13:46:48 +00:00
|
|
|
type GstType = ffi::GstMeta;
|
2018-09-29 08:13:57 +00:00
|
|
|
|
2022-12-18 08:18:31 +00:00
|
|
|
#[inline]
|
2021-04-20 10:23:24 +00:00
|
|
|
fn meta_api() -> glib::Type {
|
2021-02-25 10:38:10 +00:00
|
|
|
glib::Type::INVALID
|
2018-09-29 08:13:57 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-09-29 22:17:12 +00:00
|
|
|
impl fmt::Debug for Meta {
|
2018-09-29 08:13:57 +00:00
|
|
|
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
2023-10-26 10:38:43 +00:00
|
|
|
f.debug_struct("Meta")
|
|
|
|
.field("api", &unsafe { glib::Type::from_glib((*self.0.info).api) })
|
|
|
|
.field("type", &unsafe {
|
|
|
|
glib::Type::from_glib((*self.0.info).type_)
|
|
|
|
})
|
|
|
|
.field("flags", &unsafe {
|
|
|
|
crate::MetaFlags::from_glib(self.0.flags)
|
|
|
|
})
|
|
|
|
.finish()
|
2018-09-29 08:13:57 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-12-19 10:12:58 +00:00
|
|
|
impl Meta {
|
|
|
|
#[cfg(feature = "v1_24")]
|
|
|
|
#[cfg_attr(docsrs, doc(cfg(feature = "v1_24")))]
|
|
|
|
#[doc(alias = "gst_meta_deserialize")]
|
|
|
|
pub fn deserialize<'a>(
|
|
|
|
buffer: &'a mut BufferRef,
|
|
|
|
data: &[u8],
|
|
|
|
consumed: &mut usize,
|
|
|
|
) -> Result<MetaRefMut<'a, Self, Standalone>, glib::BoolError> {
|
|
|
|
skip_assert_initialized!();
|
|
|
|
|
|
|
|
unsafe {
|
|
|
|
use std::mem;
|
|
|
|
|
|
|
|
let mut consumed_u32 = mem::MaybeUninit::uninit();
|
|
|
|
|
|
|
|
let res = ffi::gst_meta_deserialize(
|
|
|
|
buffer.as_mut_ptr(),
|
|
|
|
data.as_ptr(),
|
|
|
|
data.len(),
|
|
|
|
consumed_u32.as_mut_ptr(),
|
|
|
|
);
|
|
|
|
|
|
|
|
*consumed = consumed_u32.assume_init() as usize;
|
|
|
|
|
|
|
|
if res.is_null() {
|
|
|
|
return Err(glib::bool_error!("Failed to deserialize meta"));
|
|
|
|
}
|
|
|
|
|
|
|
|
Ok(MetaRefMut {
|
|
|
|
meta: &mut *(res as *mut Self),
|
|
|
|
buffer,
|
|
|
|
mode: PhantomData,
|
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-10-24 17:06:59 +00:00
|
|
|
#[repr(transparent)]
|
2021-06-01 13:15:59 +00:00
|
|
|
#[doc(alias = "GstParentBufferMeta")]
|
2020-11-21 13:46:48 +00:00
|
|
|
pub struct ParentBufferMeta(ffi::GstParentBufferMeta);
|
2018-09-29 08:13:57 +00:00
|
|
|
|
2019-12-18 15:04:42 +00:00
|
|
|
unsafe impl Send for ParentBufferMeta {}
|
|
|
|
unsafe impl Sync for ParentBufferMeta {}
|
|
|
|
|
2018-09-29 22:17:12 +00:00
|
|
|
impl ParentBufferMeta {
|
2021-05-19 20:35:47 +00:00
|
|
|
#[doc(alias = "gst_buffer_add_parent_buffer_meta")]
|
2019-05-23 11:28:09 +00:00
|
|
|
pub fn add<'a>(buffer: &'a mut BufferRef, parent: &Buffer) -> MetaRefMut<'a, Self, Standalone> {
|
2020-03-22 14:18:47 +00:00
|
|
|
skip_assert_initialized!();
|
2018-09-29 08:13:57 +00:00
|
|
|
unsafe {
|
2020-11-21 13:46:48 +00:00
|
|
|
let meta = ffi::gst_buffer_add_parent_buffer_meta(
|
2019-03-19 07:58:20 +00:00
|
|
|
buffer.as_mut_ptr(),
|
2019-05-23 11:28:09 +00:00
|
|
|
parent.to_glib_none().0,
|
2019-03-19 07:58:20 +00:00
|
|
|
);
|
2018-09-29 08:13:57 +00:00
|
|
|
|
2018-09-29 22:17:12 +00:00
|
|
|
Self::from_mut_ptr(buffer, meta)
|
2018-09-29 08:13:57 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-05-02 09:41:18 +00:00
|
|
|
#[doc(alias = "get_parent")]
|
2022-12-18 08:18:31 +00:00
|
|
|
#[inline]
|
2021-04-11 19:39:50 +00:00
|
|
|
pub fn parent(&self) -> &BufferRef {
|
2018-09-29 08:13:57 +00:00
|
|
|
unsafe { BufferRef::from_ptr(self.0.buffer) }
|
|
|
|
}
|
2019-05-23 11:28:09 +00:00
|
|
|
|
2021-05-02 09:41:18 +00:00
|
|
|
#[doc(alias = "get_parent_owned")]
|
2022-12-18 08:18:31 +00:00
|
|
|
#[inline]
|
2021-04-11 19:39:50 +00:00
|
|
|
pub fn parent_owned(&self) -> Buffer {
|
2019-05-23 11:28:09 +00:00
|
|
|
unsafe { from_glib_none(self.0.buffer) }
|
|
|
|
}
|
2018-09-29 08:13:57 +00:00
|
|
|
}
|
|
|
|
|
2018-09-29 22:17:12 +00:00
|
|
|
unsafe impl MetaAPI for ParentBufferMeta {
|
2020-11-21 13:46:48 +00:00
|
|
|
type GstType = ffi::GstParentBufferMeta;
|
2018-09-29 08:13:57 +00:00
|
|
|
|
2021-05-19 20:35:47 +00:00
|
|
|
#[doc(alias = "gst_parent_buffer_meta_api_get_type")]
|
2022-12-18 08:18:31 +00:00
|
|
|
#[inline]
|
2021-04-20 10:23:24 +00:00
|
|
|
fn meta_api() -> glib::Type {
|
2020-11-21 13:46:48 +00:00
|
|
|
unsafe { from_glib(ffi::gst_parent_buffer_meta_api_get_type()) }
|
2018-09-29 08:13:57 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-09-29 22:17:12 +00:00
|
|
|
impl fmt::Debug for ParentBufferMeta {
|
2018-09-29 08:13:57 +00:00
|
|
|
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
|
|
|
f.debug_struct("ParentBufferMeta")
|
2021-04-11 19:39:50 +00:00
|
|
|
.field("parent", &self.parent())
|
2018-09-29 08:13:57 +00:00
|
|
|
.finish()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-10-24 17:06:59 +00:00
|
|
|
#[repr(transparent)]
|
2021-06-01 13:15:59 +00:00
|
|
|
#[doc(alias = "GstProtectionMeta")]
|
2020-11-21 13:46:48 +00:00
|
|
|
pub struct ProtectionMeta(ffi::GstProtectionMeta);
|
2020-06-01 20:25:49 +00:00
|
|
|
|
|
|
|
unsafe impl Send for ProtectionMeta {}
|
|
|
|
unsafe impl Sync for ProtectionMeta {}
|
|
|
|
|
|
|
|
impl ProtectionMeta {
|
2021-05-19 20:35:47 +00:00
|
|
|
#[doc(alias = "gst_buffer_add_protection_meta")]
|
2020-11-21 13:46:48 +00:00
|
|
|
pub fn add(buffer: &mut BufferRef, info: crate::Structure) -> MetaRefMut<Self, Standalone> {
|
2020-06-01 20:25:49 +00:00
|
|
|
skip_assert_initialized!();
|
|
|
|
unsafe {
|
2022-05-06 19:41:15 +00:00
|
|
|
let meta =
|
|
|
|
ffi::gst_buffer_add_protection_meta(buffer.as_mut_ptr(), info.into_glib_ptr());
|
2020-06-01 20:25:49 +00:00
|
|
|
|
|
|
|
Self::from_mut_ptr(buffer, meta)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-05-02 09:41:18 +00:00
|
|
|
#[doc(alias = "get_info")]
|
2022-12-18 08:18:31 +00:00
|
|
|
#[inline]
|
2021-04-11 19:39:50 +00:00
|
|
|
pub fn info(&self) -> &crate::StructureRef {
|
2020-11-21 13:46:48 +00:00
|
|
|
unsafe { crate::StructureRef::from_glib_borrow(self.0.info) }
|
2020-06-01 20:25:49 +00:00
|
|
|
}
|
|
|
|
|
2021-05-02 09:41:18 +00:00
|
|
|
#[doc(alias = "get_info_mut")]
|
2022-12-18 08:18:31 +00:00
|
|
|
#[inline]
|
2021-04-11 19:39:50 +00:00
|
|
|
pub fn info_mut(&mut self) -> &mut crate::StructureRef {
|
2020-11-21 13:46:48 +00:00
|
|
|
unsafe { crate::StructureRef::from_glib_borrow_mut(self.0.info) }
|
2020-06-01 20:25:49 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
unsafe impl MetaAPI for ProtectionMeta {
|
2020-11-21 13:46:48 +00:00
|
|
|
type GstType = ffi::GstProtectionMeta;
|
2020-06-01 20:25:49 +00:00
|
|
|
|
2021-05-19 20:35:47 +00:00
|
|
|
#[doc(alias = "gst_protection_meta_api_get_type")]
|
2022-12-18 08:18:31 +00:00
|
|
|
#[inline]
|
2021-04-20 10:23:24 +00:00
|
|
|
fn meta_api() -> glib::Type {
|
2020-11-21 13:46:48 +00:00
|
|
|
unsafe { from_glib(ffi::gst_protection_meta_api_get_type()) }
|
2020-06-01 20:25:49 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
impl fmt::Debug for ProtectionMeta {
|
|
|
|
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
|
|
|
f.debug_struct("ProtectionMeta")
|
2021-04-11 19:39:50 +00:00
|
|
|
.field("info", &self.info())
|
2020-06-01 20:25:49 +00:00
|
|
|
.finish()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-10-24 17:06:59 +00:00
|
|
|
#[repr(transparent)]
|
2021-06-01 13:15:59 +00:00
|
|
|
#[doc(alias = "GstReferenceTimestampMeta")]
|
2020-11-21 13:46:48 +00:00
|
|
|
pub struct ReferenceTimestampMeta(ffi::GstReferenceTimestampMeta);
|
2019-07-14 19:32:10 +00:00
|
|
|
|
2019-12-18 15:04:42 +00:00
|
|
|
unsafe impl Send for ReferenceTimestampMeta {}
|
|
|
|
unsafe impl Sync for ReferenceTimestampMeta {}
|
|
|
|
|
2019-07-14 19:32:10 +00:00
|
|
|
impl ReferenceTimestampMeta {
|
2021-05-19 20:35:47 +00:00
|
|
|
#[doc(alias = "gst_buffer_add_reference_timestamp_meta")]
|
2019-07-14 19:32:10 +00:00
|
|
|
pub fn add<'a>(
|
|
|
|
buffer: &'a mut BufferRef,
|
|
|
|
reference: &Caps,
|
|
|
|
timestamp: ClockTime,
|
2020-10-27 17:27:16 +00:00
|
|
|
duration: impl Into<Option<ClockTime>>,
|
2019-07-14 19:32:10 +00:00
|
|
|
) -> MetaRefMut<'a, Self, Standalone> {
|
2020-03-22 14:18:47 +00:00
|
|
|
skip_assert_initialized!();
|
2019-07-14 19:32:10 +00:00
|
|
|
unsafe {
|
2020-11-21 13:46:48 +00:00
|
|
|
let meta = ffi::gst_buffer_add_reference_timestamp_meta(
|
2019-07-14 19:32:10 +00:00
|
|
|
buffer.as_mut_ptr(),
|
|
|
|
reference.to_glib_none().0,
|
2021-04-27 15:15:46 +00:00
|
|
|
timestamp.into_glib(),
|
2020-10-27 17:27:16 +00:00
|
|
|
duration.into().into_glib(),
|
2019-07-14 19:32:10 +00:00
|
|
|
);
|
|
|
|
|
|
|
|
Self::from_mut_ptr(buffer, meta)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-05-02 09:41:18 +00:00
|
|
|
#[doc(alias = "get_reference")]
|
2022-12-18 08:18:31 +00:00
|
|
|
#[inline]
|
2021-04-11 19:39:50 +00:00
|
|
|
pub fn reference(&self) -> &CapsRef {
|
2019-07-14 19:32:10 +00:00
|
|
|
unsafe { CapsRef::from_ptr(self.0.reference) }
|
|
|
|
}
|
|
|
|
|
2023-10-16 12:45:12 +00:00
|
|
|
#[doc(alias = "get_reference_owned")]
|
2022-12-18 08:18:31 +00:00
|
|
|
#[inline]
|
2023-10-16 12:45:12 +00:00
|
|
|
pub fn reference_owned(&self) -> Caps {
|
2019-07-14 19:32:10 +00:00
|
|
|
unsafe { from_glib_none(self.0.reference) }
|
|
|
|
}
|
|
|
|
|
2021-05-02 09:41:18 +00:00
|
|
|
#[doc(alias = "get_timestamp")]
|
2022-12-18 08:18:31 +00:00
|
|
|
#[inline]
|
2021-04-28 22:29:13 +00:00
|
|
|
pub fn timestamp(&self) -> ClockTime {
|
|
|
|
unsafe { try_from_glib(self.0.timestamp).expect("undefined timestamp") }
|
2019-07-14 19:32:10 +00:00
|
|
|
}
|
|
|
|
|
2021-05-02 09:41:18 +00:00
|
|
|
#[doc(alias = "get_duration")]
|
2022-12-18 08:18:31 +00:00
|
|
|
#[inline]
|
2020-10-27 17:27:16 +00:00
|
|
|
pub fn duration(&self) -> Option<ClockTime> {
|
2020-12-08 14:07:12 +00:00
|
|
|
unsafe { from_glib(self.0.duration) }
|
2019-07-14 19:32:10 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
unsafe impl MetaAPI for ReferenceTimestampMeta {
|
2020-11-21 13:46:48 +00:00
|
|
|
type GstType = ffi::GstReferenceTimestampMeta;
|
2019-07-14 19:32:10 +00:00
|
|
|
|
2021-05-19 20:35:47 +00:00
|
|
|
#[doc(alias = "gst_reference_timestamp_meta_api_get_type")]
|
2022-12-18 08:18:31 +00:00
|
|
|
#[inline]
|
2021-04-20 10:23:24 +00:00
|
|
|
fn meta_api() -> glib::Type {
|
2020-11-21 13:46:48 +00:00
|
|
|
unsafe { from_glib(ffi::gst_reference_timestamp_meta_api_get_type()) }
|
2019-07-14 19:32:10 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
impl fmt::Debug for ReferenceTimestampMeta {
|
|
|
|
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
2020-10-27 17:27:16 +00:00
|
|
|
use crate::utils::Displayable;
|
|
|
|
|
2019-07-14 19:32:10 +00:00
|
|
|
f.debug_struct("ReferenceTimestampMeta")
|
2021-04-11 19:39:50 +00:00
|
|
|
.field("reference", &self.reference())
|
2021-09-22 21:07:28 +00:00
|
|
|
.field("timestamp", &self.timestamp().display())
|
|
|
|
.field("duration", &self.duration().display())
|
2019-07-14 19:32:10 +00:00
|
|
|
.finish()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-05-04 05:55:48 +00:00
|
|
|
#[cfg(feature = "v1_20")]
|
|
|
|
#[cfg_attr(docsrs, doc(cfg(feature = "v1_20")))]
|
2021-09-19 11:19:58 +00:00
|
|
|
#[repr(transparent)]
|
|
|
|
#[doc(alias = "GstCustomMeta")]
|
|
|
|
pub struct CustomMeta(ffi::GstCustomMeta);
|
|
|
|
|
2023-05-04 05:55:48 +00:00
|
|
|
#[cfg(feature = "v1_20")]
|
|
|
|
#[cfg_attr(docsrs, doc(cfg(feature = "v1_20")))]
|
2021-09-19 11:19:58 +00:00
|
|
|
unsafe impl Send for CustomMeta {}
|
2023-05-04 05:55:48 +00:00
|
|
|
#[cfg(feature = "v1_20")]
|
|
|
|
#[cfg_attr(docsrs, doc(cfg(feature = "v1_20")))]
|
2021-09-19 11:19:58 +00:00
|
|
|
unsafe impl Sync for CustomMeta {}
|
|
|
|
|
2023-05-04 05:55:48 +00:00
|
|
|
#[cfg(feature = "v1_20")]
|
|
|
|
#[cfg_attr(docsrs, doc(cfg(feature = "v1_20")))]
|
2021-09-19 11:19:58 +00:00
|
|
|
impl CustomMeta {
|
|
|
|
#[doc(alias = "gst_meta_register_custom")]
|
2022-09-28 17:10:54 +00:00
|
|
|
pub fn register(name: &str, tags: &[&str]) {
|
|
|
|
assert_initialized_main_thread!();
|
|
|
|
unsafe {
|
|
|
|
ffi::gst_meta_register_custom(
|
|
|
|
name.to_glib_none().0,
|
|
|
|
tags.to_glib_none().0,
|
|
|
|
None,
|
|
|
|
ptr::null_mut(),
|
|
|
|
None,
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#[doc(alias = "gst_meta_register_custom")]
|
|
|
|
pub fn register_with_transform<
|
2021-09-19 11:19:58 +00:00
|
|
|
F: Fn(&mut BufferRef, &CustomMeta, &BufferRef, glib::Quark) -> bool + Send + Sync + 'static,
|
|
|
|
>(
|
|
|
|
name: &str,
|
|
|
|
tags: &[&str],
|
|
|
|
transform_func: F,
|
|
|
|
) {
|
2022-09-28 17:10:54 +00:00
|
|
|
assert_initialized_main_thread!();
|
2021-09-19 11:19:58 +00:00
|
|
|
unsafe extern "C" fn transform_func_trampoline<
|
|
|
|
F: Fn(&mut BufferRef, &CustomMeta, &BufferRef, glib::Quark) -> bool
|
|
|
|
+ Send
|
|
|
|
+ Sync
|
|
|
|
+ 'static,
|
|
|
|
>(
|
|
|
|
dest: *mut ffi::GstBuffer,
|
|
|
|
meta: *mut ffi::GstCustomMeta,
|
|
|
|
src: *mut ffi::GstBuffer,
|
|
|
|
type_: glib::ffi::GQuark,
|
|
|
|
_data: glib::ffi::gpointer,
|
|
|
|
user_data: glib::ffi::gpointer,
|
|
|
|
) -> glib::ffi::gboolean {
|
|
|
|
let func = &*(user_data as *const F);
|
|
|
|
let res = func(
|
|
|
|
BufferRef::from_mut_ptr(dest),
|
|
|
|
&*(meta as *const CustomMeta),
|
|
|
|
BufferRef::from_ptr(src),
|
|
|
|
from_glib(type_),
|
|
|
|
);
|
|
|
|
res.into_glib()
|
|
|
|
}
|
|
|
|
|
|
|
|
unsafe extern "C" fn transform_func_free<F>(ptr: glib::ffi::gpointer) {
|
|
|
|
let _ = Box::from_raw(ptr as *mut F);
|
|
|
|
}
|
|
|
|
|
|
|
|
unsafe {
|
|
|
|
ffi::gst_meta_register_custom(
|
|
|
|
name.to_glib_none().0,
|
|
|
|
tags.to_glib_none().0,
|
|
|
|
Some(transform_func_trampoline::<F>),
|
|
|
|
Box::into_raw(Box::new(transform_func)) as glib::ffi::gpointer,
|
|
|
|
Some(transform_func_free::<F>),
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-10-02 16:50:41 +00:00
|
|
|
#[doc(alias = "gst_meta_register_simple")]
|
|
|
|
pub fn register_simple(name: &str) {
|
|
|
|
assert_initialized_main_thread!();
|
|
|
|
unsafe {
|
|
|
|
ffi::gst_meta_register_custom(
|
|
|
|
name.to_glib_none().0,
|
|
|
|
ptr::null_mut(),
|
|
|
|
None,
|
|
|
|
ptr::null_mut(),
|
|
|
|
None,
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-09-19 11:19:58 +00:00
|
|
|
#[doc(alias = "gst_buffer_add_custom_meta")]
|
|
|
|
pub fn add<'a>(
|
|
|
|
buffer: &'a mut BufferRef,
|
|
|
|
name: &str,
|
|
|
|
) -> Result<MetaRefMut<'a, Self, Standalone>, glib::BoolError> {
|
|
|
|
skip_assert_initialized!();
|
|
|
|
unsafe {
|
|
|
|
let meta = ffi::gst_buffer_add_custom_meta(buffer.as_mut_ptr(), name.to_glib_none().0);
|
|
|
|
|
|
|
|
if meta.is_null() {
|
|
|
|
return Err(glib::bool_error!("Failed to add custom meta"));
|
|
|
|
}
|
|
|
|
|
|
|
|
Ok(MetaRefMut {
|
|
|
|
meta: &mut *(meta as *mut Self),
|
|
|
|
buffer,
|
|
|
|
mode: PhantomData,
|
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#[doc(alias = "gst_buffer_get_custom_meta")]
|
|
|
|
pub fn from_buffer<'a>(
|
|
|
|
buffer: &'a BufferRef,
|
|
|
|
name: &str,
|
|
|
|
) -> Result<MetaRef<'a, Self>, glib::BoolError> {
|
|
|
|
skip_assert_initialized!();
|
|
|
|
unsafe {
|
|
|
|
let meta = ffi::gst_buffer_get_custom_meta(buffer.as_mut_ptr(), name.to_glib_none().0);
|
|
|
|
|
|
|
|
if meta.is_null() {
|
|
|
|
return Err(glib::bool_error!("Failed to get custom meta"));
|
|
|
|
}
|
|
|
|
|
|
|
|
Ok(MetaRef {
|
|
|
|
meta: &*(meta as *const Self),
|
|
|
|
buffer,
|
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#[doc(alias = "gst_buffer_get_custom_meta")]
|
|
|
|
pub fn from_mut_buffer<'a>(
|
|
|
|
buffer: &'a mut BufferRef,
|
|
|
|
name: &str,
|
|
|
|
) -> Result<MetaRefMut<'a, Self, Standalone>, glib::BoolError> {
|
|
|
|
skip_assert_initialized!();
|
|
|
|
unsafe {
|
|
|
|
let meta = ffi::gst_buffer_get_custom_meta(buffer.as_mut_ptr(), name.to_glib_none().0);
|
|
|
|
|
|
|
|
if meta.is_null() {
|
|
|
|
return Err(glib::bool_error!("Failed to get custom meta"));
|
|
|
|
}
|
|
|
|
|
|
|
|
Ok(MetaRefMut {
|
|
|
|
meta: &mut *(meta as *mut Self),
|
|
|
|
buffer,
|
|
|
|
mode: PhantomData,
|
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#[doc(alias = "gst_custom_meta_get_structure")]
|
2022-12-18 08:18:31 +00:00
|
|
|
#[inline]
|
2021-09-19 11:19:58 +00:00
|
|
|
pub fn structure(&self) -> &crate::StructureRef {
|
|
|
|
unsafe {
|
|
|
|
crate::StructureRef::from_glib_borrow(ffi::gst_custom_meta_get_structure(mut_override(
|
|
|
|
&self.0,
|
|
|
|
)))
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#[doc(alias = "gst_custom_meta_get_structure")]
|
2022-12-18 08:18:31 +00:00
|
|
|
#[inline]
|
2021-09-19 11:19:58 +00:00
|
|
|
pub fn mut_structure(&mut self) -> &mut crate::StructureRef {
|
|
|
|
unsafe {
|
|
|
|
crate::StructureRef::from_glib_borrow_mut(ffi::gst_custom_meta_get_structure(
|
|
|
|
&mut self.0,
|
|
|
|
))
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#[doc(alias = "gst_custom_meta_has_name")]
|
2022-12-18 08:18:31 +00:00
|
|
|
#[inline]
|
2021-09-19 11:19:58 +00:00
|
|
|
pub fn has_name(&self, name: &str) -> bool {
|
|
|
|
unsafe {
|
|
|
|
from_glib(ffi::gst_custom_meta_has_name(
|
|
|
|
mut_override(&self.0),
|
|
|
|
name.to_glib_none().0,
|
|
|
|
))
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-09-29 08:13:57 +00:00
|
|
|
#[cfg(test)]
|
|
|
|
mod tests {
|
|
|
|
use super::*;
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn test_add_get_iterate_meta() {
|
2020-11-21 13:46:48 +00:00
|
|
|
crate::init().unwrap();
|
2018-09-29 08:13:57 +00:00
|
|
|
|
2020-11-21 13:46:48 +00:00
|
|
|
let mut buffer = crate::Buffer::new();
|
|
|
|
let parent = crate::Buffer::new();
|
2018-09-29 08:13:57 +00:00
|
|
|
{
|
2019-05-23 11:28:09 +00:00
|
|
|
let meta = ParentBufferMeta::add(buffer.get_mut().unwrap(), &parent);
|
2022-08-11 14:02:02 +00:00
|
|
|
assert_eq!(meta.parent().as_ptr(), parent.as_ptr());
|
2018-09-29 08:13:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
{
|
2020-10-09 08:00:15 +00:00
|
|
|
let metas = buffer.iter_meta::<Meta>();
|
|
|
|
assert_eq!(metas.count(), 1);
|
2018-09-29 08:13:57 +00:00
|
|
|
}
|
|
|
|
{
|
2020-10-09 08:00:15 +00:00
|
|
|
let metas = buffer.get_mut().unwrap().iter_meta_mut::<Meta>();
|
|
|
|
assert_eq!(metas.count(), 1);
|
2018-09-29 08:13:57 +00:00
|
|
|
}
|
|
|
|
{
|
|
|
|
let metas = buffer.iter_meta::<ParentBufferMeta>().collect::<Vec<_>>();
|
|
|
|
assert_eq!(metas.len(), 1);
|
2022-08-11 14:02:02 +00:00
|
|
|
assert_eq!(metas[0].parent().as_ptr(), parent.as_ptr());
|
2018-09-29 08:13:57 +00:00
|
|
|
}
|
|
|
|
{
|
|
|
|
let metas = buffer
|
|
|
|
.get_mut()
|
|
|
|
.unwrap()
|
|
|
|
.iter_meta_mut::<ParentBufferMeta>()
|
|
|
|
.collect::<Vec<_>>();
|
|
|
|
assert_eq!(metas.len(), 1);
|
2022-08-11 14:02:02 +00:00
|
|
|
assert_eq!(metas[0].parent().as_ptr(), parent.as_ptr());
|
2023-06-29 14:58:51 +00:00
|
|
|
assert!(!metas[0].has_tag(glib::Quark::from_str("video")));
|
|
|
|
assert!(metas[0].has_tag(glib::Quark::from_str("memory-reference")));
|
|
|
|
assert_eq!(metas[0].tags().len(), 1);
|
2023-10-26 10:40:12 +00:00
|
|
|
|
|
|
|
assert_eq!(metas[0].tags(), metas[0].upcast_ref().tags());
|
2018-09-29 08:13:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
{
|
|
|
|
let meta = buffer
|
|
|
|
.get_mut()
|
|
|
|
.unwrap()
|
2021-04-20 10:24:17 +00:00
|
|
|
.meta_mut::<ParentBufferMeta>()
|
2018-09-29 08:13:57 +00:00
|
|
|
.unwrap();
|
2022-08-11 14:02:02 +00:00
|
|
|
assert_eq!(meta.parent().as_ptr(), parent.as_ptr());
|
2021-11-16 11:08:23 +00:00
|
|
|
meta.remove().unwrap();
|
2018-09-29 08:13:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
{
|
2020-10-09 08:00:15 +00:00
|
|
|
let metas = buffer.iter_meta::<Meta>();
|
|
|
|
assert_eq!(metas.count(), 0);
|
2018-09-29 08:13:57 +00:00
|
|
|
}
|
|
|
|
{
|
2020-10-09 08:00:15 +00:00
|
|
|
let metas = buffer.get_mut().unwrap().iter_meta_mut::<Meta>();
|
|
|
|
assert_eq!(metas.count(), 0);
|
2018-09-29 08:13:57 +00:00
|
|
|
}
|
|
|
|
{
|
2020-10-09 08:00:15 +00:00
|
|
|
let metas = buffer.iter_meta::<ParentBufferMeta>();
|
|
|
|
assert_eq!(metas.count(), 0);
|
2018-09-29 08:13:57 +00:00
|
|
|
}
|
|
|
|
{
|
|
|
|
let metas = buffer
|
|
|
|
.get_mut()
|
|
|
|
.unwrap()
|
2020-10-09 08:00:15 +00:00
|
|
|
.iter_meta_mut::<ParentBufferMeta>();
|
|
|
|
assert_eq!(metas.count(), 0);
|
2018-09-29 08:13:57 +00:00
|
|
|
}
|
|
|
|
|
2021-04-20 10:24:17 +00:00
|
|
|
assert!(buffer.meta::<ParentBufferMeta>().is_none());
|
2018-09-29 08:13:57 +00:00
|
|
|
}
|
2023-11-03 09:55:20 +00:00
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn test_copy_reference_timestamp_meta() {
|
|
|
|
crate::init().unwrap();
|
|
|
|
|
|
|
|
let caps = crate::Caps::new_empty_simple("timestamp/x-ntp");
|
|
|
|
let mut buffer = crate::Buffer::new();
|
|
|
|
{
|
|
|
|
ReferenceTimestampMeta::add(
|
|
|
|
buffer.get_mut().unwrap(),
|
|
|
|
&caps,
|
|
|
|
crate::ClockTime::from_seconds(1),
|
|
|
|
crate::ClockTime::NONE,
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
let mut buffer_dest = crate::Buffer::new();
|
|
|
|
{
|
|
|
|
let meta = buffer.meta::<ReferenceTimestampMeta>().unwrap();
|
|
|
|
let buffer_dest = buffer_dest.get_mut().unwrap();
|
2023-12-10 18:35:43 +00:00
|
|
|
meta.copy(buffer_dest, false, ..).unwrap();
|
2023-11-03 09:55:20 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
let meta = buffer_dest.meta::<ReferenceTimestampMeta>().unwrap();
|
|
|
|
assert_eq!(meta.reference(), &caps);
|
|
|
|
assert_eq!(meta.timestamp(), crate::ClockTime::from_seconds(1));
|
|
|
|
assert_eq!(meta.duration(), crate::ClockTime::NONE);
|
|
|
|
}
|
2023-12-19 10:12:58 +00:00
|
|
|
|
|
|
|
#[cfg(feature = "v1_24")]
|
|
|
|
#[cfg_attr(docsrs, doc(cfg(feature = "v1_24")))]
|
|
|
|
#[test]
|
|
|
|
fn test_meta_serialize() {
|
|
|
|
use smallvec::SmallVec;
|
|
|
|
|
|
|
|
crate::init().unwrap();
|
|
|
|
|
|
|
|
let caps = crate::Caps::new_empty_simple("timestamp/x-ntp");
|
|
|
|
let mut buffer = crate::Buffer::new();
|
|
|
|
|
|
|
|
let meta = ReferenceTimestampMeta::add(
|
|
|
|
buffer.get_mut().unwrap(),
|
|
|
|
&caps,
|
|
|
|
crate::ClockTime::from_seconds(1),
|
|
|
|
crate::ClockTime::NONE,
|
|
|
|
);
|
|
|
|
|
|
|
|
let mut data_1 = Vec::new();
|
|
|
|
let mut data_2 = [0u8; 128];
|
|
|
|
let mut data_3 = SmallVec::<[u8; 128]>::new();
|
|
|
|
|
|
|
|
let len_1 = meta.serialize(&mut data_1).unwrap();
|
|
|
|
let len_2 = meta.serialize(&mut data_2).unwrap();
|
|
|
|
let len_3 = meta.serialize(&mut data_3).unwrap();
|
|
|
|
assert_eq!(&data_1[..len_1], &data_2[..len_2]);
|
|
|
|
assert_eq!(&data_1[..len_1], &data_3[..len_3]);
|
|
|
|
|
|
|
|
assert!(meta.serialize(&mut [0]).is_err());
|
|
|
|
|
|
|
|
let mut buffer_dest = crate::Buffer::new();
|
|
|
|
let mut consumed = 0;
|
|
|
|
let mut meta =
|
|
|
|
Meta::deserialize(buffer_dest.get_mut().unwrap(), &data_1, &mut consumed).unwrap();
|
|
|
|
assert_eq!(consumed, len_1);
|
|
|
|
|
|
|
|
let meta = meta.downcast_ref::<ReferenceTimestampMeta>().unwrap();
|
|
|
|
assert_eq!(meta.reference(), &caps);
|
|
|
|
assert_eq!(meta.timestamp(), crate::ClockTime::from_seconds(1));
|
|
|
|
assert_eq!(meta.duration(), crate::ClockTime::NONE);
|
|
|
|
|
|
|
|
let mut consumed = 0;
|
|
|
|
assert!(
|
|
|
|
Meta::deserialize(buffer_dest.get_mut().unwrap(), &[0, 1, 2], &mut consumed).is_err()
|
|
|
|
);
|
|
|
|
assert_eq!(consumed, 0);
|
|
|
|
}
|
2018-09-29 08:13:57 +00:00
|
|
|
}
|