mirror of
https://gitlab.freedesktop.org/gstreamer/gstreamer-rs.git
synced 2025-02-27 16:26:22 +00:00
tracer: Add memory init/free hooks
Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer-rs/-/merge_requests/1655>
This commit is contained in:
parent
e9e4b970fa
commit
3f220ce5d9
3 changed files with 112 additions and 0 deletions
|
@ -131,6 +131,9 @@ mod buffer_cursor;
|
||||||
pub use crate::buffer_cursor::{BufferCursor, BufferRefCursor};
|
pub use crate::buffer_cursor::{BufferCursor, BufferRefCursor};
|
||||||
pub mod memory;
|
pub mod memory;
|
||||||
mod memory_wrapped;
|
mod memory_wrapped;
|
||||||
|
#[cfg(feature = "v1_26")]
|
||||||
|
#[cfg_attr(docsrs, doc(cfg(feature = "v1_26")))]
|
||||||
|
pub use crate::memory::MemoryRefTrace;
|
||||||
pub use crate::memory::{MappedMemory, Memory, MemoryMap, MemoryRef};
|
pub use crate::memory::{MappedMemory, Memory, MemoryMap, MemoryRef};
|
||||||
#[cfg(feature = "serde")]
|
#[cfg(feature = "serde")]
|
||||||
mod buffer_serde;
|
mod buffer_serde;
|
||||||
|
|
|
@ -949,6 +949,88 @@ macro_rules! memory_object_wrapper {
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[cfg(feature = "v1_26")]
|
||||||
|
#[cfg_attr(docsrs, doc(cfg(feature = "v1_26")))]
|
||||||
|
#[doc(alias = "GstMemory")]
|
||||||
|
pub struct MemoryRefTrace(ffi::GstMemory);
|
||||||
|
#[cfg(feature = "v1_26")]
|
||||||
|
#[cfg_attr(docsrs, doc(cfg(feature = "v1_26")))]
|
||||||
|
impl MemoryRefTrace {
|
||||||
|
pub unsafe fn from_ptr<'a>(ptr: *mut ffi::GstMemory) -> &'a MemoryRefTrace {
|
||||||
|
assert!(!ptr.is_null());
|
||||||
|
|
||||||
|
&*(ptr as *const Self)
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn as_ptr(&self) -> *const ffi::GstMemory {
|
||||||
|
self as *const Self as *const ffi::GstMemory
|
||||||
|
}
|
||||||
|
|
||||||
|
#[doc(alias = "get_allocator")]
|
||||||
|
#[inline]
|
||||||
|
pub fn allocator(&self) -> Option<&Allocator> {
|
||||||
|
unsafe {
|
||||||
|
if self.0.allocator.is_null() {
|
||||||
|
None
|
||||||
|
} else {
|
||||||
|
Some(&*(&self.0.allocator as *const *mut ffi::GstAllocator as *const Allocator))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#[doc(alias = "get_parent")]
|
||||||
|
#[inline]
|
||||||
|
pub fn parent(&self) -> Option<&MemoryRef> {
|
||||||
|
unsafe {
|
||||||
|
if self.0.parent.is_null() {
|
||||||
|
None
|
||||||
|
} else {
|
||||||
|
Some(MemoryRef::from_ptr(self.0.parent))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#[doc(alias = "get_maxsize")]
|
||||||
|
#[inline]
|
||||||
|
pub fn maxsize(&self) -> usize {
|
||||||
|
self.0.maxsize
|
||||||
|
}
|
||||||
|
|
||||||
|
#[doc(alias = "get_align")]
|
||||||
|
#[inline]
|
||||||
|
pub fn align(&self) -> usize {
|
||||||
|
self.0.align
|
||||||
|
}
|
||||||
|
|
||||||
|
#[doc(alias = "get_offset")]
|
||||||
|
#[inline]
|
||||||
|
pub fn offset(&self) -> usize {
|
||||||
|
self.0.offset
|
||||||
|
}
|
||||||
|
|
||||||
|
#[doc(alias = "get_size")]
|
||||||
|
#[inline]
|
||||||
|
pub fn size(&self) -> usize {
|
||||||
|
self.0.size
|
||||||
|
}
|
||||||
|
|
||||||
|
#[doc(alias = "get_flags")]
|
||||||
|
#[inline]
|
||||||
|
pub fn flags(&self) -> crate::MemoryFlags {
|
||||||
|
unsafe { from_glib(self.0.mini_object.flags) }
|
||||||
|
}
|
||||||
|
|
||||||
|
#[doc(alias = "gst_memory_is_type")]
|
||||||
|
pub fn is_type(&self, mem_type: &str) -> bool {
|
||||||
|
unsafe {
|
||||||
|
from_glib(ffi::gst_memory_is_type(
|
||||||
|
self as *const Self as *mut ffi::GstMemory,
|
||||||
|
mem_type.to_glib_none().0,
|
||||||
|
))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod tests {
|
mod tests {
|
||||||
#[test]
|
#[test]
|
||||||
|
|
|
@ -89,6 +89,15 @@ pub trait TracerImpl: TracerImplExt + GstObjectImpl + Send + Sync {
|
||||||
#[cfg(feature = "v1_20")]
|
#[cfg(feature = "v1_20")]
|
||||||
#[cfg_attr(docsrs, doc(cfg(feature = "v1_20")))]
|
#[cfg_attr(docsrs, doc(cfg(feature = "v1_20")))]
|
||||||
fn plugin_feature_loaded(&self, ts: u64, feature: &crate::PluginFeature) {}
|
fn plugin_feature_loaded(&self, ts: u64, feature: &crate::PluginFeature) {}
|
||||||
|
#[cfg(feature = "v1_26")]
|
||||||
|
#[cfg_attr(docsrs, doc(cfg(feature = "v1_26")))]
|
||||||
|
fn memory_init(&self, ts: u64, mem: &crate::MemoryRefTrace) {}
|
||||||
|
#[cfg(feature = "v1_26")]
|
||||||
|
#[cfg_attr(docsrs, doc(cfg(feature = "v1_26")))]
|
||||||
|
fn memory_free_pre(&self, ts: u64, mem: &crate::MemoryRef) {}
|
||||||
|
#[cfg(feature = "v1_26")]
|
||||||
|
#[cfg_attr(docsrs, doc(cfg(feature = "v1_26")))]
|
||||||
|
fn memory_free_post(&self, ts: u64, mem: std::ptr::NonNull<ffi::GstMemory>) {}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(not(feature = "v1_26"))]
|
#[cfg(not(feature = "v1_26"))]
|
||||||
|
@ -476,4 +485,22 @@ define_tracer_hooks! {
|
||||||
let feature = crate::PluginFeature::from_glib_borrow(feature);
|
let feature = crate::PluginFeature::from_glib_borrow(feature);
|
||||||
this.plugin_feature_loaded(ts, &feature)
|
this.plugin_feature_loaded(ts, &feature)
|
||||||
};
|
};
|
||||||
|
|
||||||
|
#[cfg(feature = "v1_26")]
|
||||||
|
#[cfg_attr(docsrs, doc(cfg(feature = "v1_26")))]
|
||||||
|
MemoryInit("memory-init") = |this, ts, memory: *mut ffi::GstMemory| {
|
||||||
|
let memory = crate::MemoryRefTrace::from_ptr(memory);
|
||||||
|
this.memory_init(ts, memory)
|
||||||
|
};
|
||||||
|
#[cfg(feature = "v1_26")]
|
||||||
|
#[cfg_attr(docsrs, doc(cfg(feature = "v1_26")))]
|
||||||
|
MemoryFreePre("memory-free-pre") = |this, ts, memory: *mut ffi::GstMemory| {
|
||||||
|
let memory = crate::MemoryRef::from_ptr(memory);
|
||||||
|
this.memory_free_pre(ts, memory)
|
||||||
|
};
|
||||||
|
#[cfg(feature = "v1_26")]
|
||||||
|
#[cfg_attr(docsrs, doc(cfg(feature = "v1_26")))]
|
||||||
|
MemoryFreePost("memory-free-post") = |this, ts, memory: *mut ffi::GstMemory| {
|
||||||
|
this.memory_free_post(ts, std::ptr::NonNull::new_unchecked(memory))
|
||||||
|
};
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue