meta: Replace to_raw with as_ptr in MetaTransform

Simplifies the API

Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer-rs/-/merge_requests/1776>
This commit is contained in:
Olivier Crête 2025-08-20 08:25:08 -04:00 committed by GStreamer Marge Bot
parent ccd799a0c2
commit f323ed0587
2 changed files with 13 additions and 24 deletions

View file

@ -1218,7 +1218,7 @@ impl VideoMetaTransformScale {
}
}
unsafe impl<'a> gst::meta::MetaTransform<'a> for VideoMetaTransformScale {
unsafe impl gst::meta::MetaTransform for VideoMetaTransformScale {
type GLibType = ffi::GstVideoMetaTransform;
#[doc(alias = "gst_video_meta_transform_scale_get_quark")]
@ -1226,11 +1226,8 @@ unsafe impl<'a> gst::meta::MetaTransform<'a> for VideoMetaTransformScale {
unsafe { from_glib(ffi::gst_video_meta_transform_scale_get_quark()) }
}
fn to_raw<T: MetaAPI>(
&self,
_meta: &gst::MetaRef<T>,
) -> Result<ffi::GstVideoMetaTransform, glib::BoolError> {
Ok(self.0)
fn as_ptr(&self) -> *const ffi::GstVideoMetaTransform {
&self.0
}
}

View file

@ -235,7 +235,7 @@ impl<'a, T> MetaRef<'a, T> {
pub fn transform<MT>(&self, buffer: &mut BufferRef, data: &'a MT) -> Result<(), glib::BoolError>
where
T: MetaAPI,
MT: MetaTransform<'a>,
MT: MetaTransform,
{
unsafe {
let info = *(*self.upcast_ref().as_ptr()).info;
@ -245,15 +245,13 @@ impl<'a, T> MetaRef<'a, T> {
));
};
let data = data.to_raw(self)?;
glib::result_from_gboolean!(
transform_func(
buffer.as_mut_ptr(),
mut_override(self.upcast_ref().as_ptr()),
mut_override(self.buffer.as_ptr()),
MT::quark().into_glib(),
mut_override(&data) as *mut _,
mut_override(data.as_ptr() as *mut _),
),
"Failed to transform meta"
)
@ -493,7 +491,7 @@ impl<'a, T, U> MetaRefMut<'a, T, U> {
) -> Result<(), glib::BoolError>
where
T: MetaAPI,
MT: MetaTransform<'a>,
MT: MetaTransform,
{
self.as_meta_ref().transform(buffer, data)
}
@ -1103,10 +1101,10 @@ pub mod tags {
);
}
pub unsafe trait MetaTransform<'a> {
pub unsafe trait MetaTransform {
type GLibType;
fn quark() -> glib::Quark;
fn to_raw<T: MetaAPI>(&self, meta: &MetaRef<T>) -> Result<Self::GLibType, glib::BoolError>;
fn as_ptr(&self) -> *const Self::GLibType;
}
#[repr(transparent)]
@ -1137,18 +1135,15 @@ impl MetaTransformCopy {
}
}
unsafe impl MetaTransform<'_> for MetaTransformCopy {
unsafe impl MetaTransform for MetaTransformCopy {
type GLibType = ffi::GstMetaTransformCopy;
fn quark() -> glib::Quark {
static QUARK: std::sync::OnceLock<glib::Quark> = std::sync::OnceLock::new();
*QUARK.get_or_init(|| glib::Quark::from_static_str(glib::gstr!("gst-copy")))
}
fn to_raw<T: MetaAPI>(
&self,
_meta: &MetaRef<T>,
) -> Result<ffi::GstMetaTransformCopy, glib::BoolError> {
Ok(self.0)
fn as_ptr(&self) -> *const ffi::GstMetaTransformCopy {
&self.0
}
}
@ -1310,11 +1305,8 @@ mod tests {
{
let meta = buffer.meta::<ReferenceTimestampMeta>().unwrap();
let buffer_dest = buffer_dest.get_mut().unwrap();
meta.transform(
buffer_dest,
&MetaTransformCopy::new(false, ..),
)
.unwrap();
meta.transform(buffer_dest, &MetaTransformCopy::new(false, ..))
.unwrap();
}
let meta = buffer_dest.meta::<ReferenceTimestampMeta>().unwrap();