2022-02-26 15:16:35 +00:00
|
|
|
use std::{fmt, os::unix::prelude::RawFd};
|
|
|
|
|
|
|
|
use glib::{translate::*, Cast};
|
|
|
|
use gst::{Memory, MemoryRef};
|
|
|
|
|
|
|
|
use crate::{FdAllocator, FdMemoryFlags};
|
|
|
|
|
|
|
|
gst::memory_object_wrapper!(
|
|
|
|
FdMemory,
|
|
|
|
FdMemoryRef,
|
|
|
|
gst::ffi::GstMemory,
|
|
|
|
|mem: &gst::MemoryRef| { unsafe { from_glib(ffi::gst_is_fd_memory(mem.as_mut_ptr())) } },
|
|
|
|
Memory,
|
|
|
|
MemoryRef,
|
|
|
|
);
|
|
|
|
|
|
|
|
impl fmt::Debug for FdMemory {
|
|
|
|
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
|
|
|
FdMemoryRef::fmt(self, f)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
impl fmt::Debug for FdMemoryRef {
|
|
|
|
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
|
|
|
f.debug_struct("FdMemory")
|
2022-08-11 14:02:02 +00:00
|
|
|
.field("ptr", &self.as_ptr())
|
2022-02-26 15:16:35 +00:00
|
|
|
.field("allocator", &self.allocator())
|
|
|
|
.field("parent", &self.parent())
|
|
|
|
.field("maxsize", &self.maxsize())
|
|
|
|
.field("align", &self.align())
|
|
|
|
.field("offset", &self.offset())
|
|
|
|
.field("size", &self.size())
|
|
|
|
.field("flags", &self.flags())
|
|
|
|
.field("fd", &self.fd())
|
|
|
|
.finish()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
impl FdMemoryRef {
|
|
|
|
#[doc(alias = "gst_fd_memory_get_fd")]
|
|
|
|
pub fn fd(&self) -> RawFd {
|
2022-12-25 10:47:02 +00:00
|
|
|
skip_assert_initialized!();
|
2022-02-26 15:16:35 +00:00
|
|
|
unsafe { ffi::gst_fd_memory_get_fd(self.as_mut_ptr()) }
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
impl FdAllocator {
|
|
|
|
#[doc(alias = "gst_fd_allocator_alloc")]
|
2022-10-18 11:16:04 +00:00
|
|
|
pub unsafe fn alloc(
|
|
|
|
&self,
|
|
|
|
fd: RawFd,
|
|
|
|
size: usize,
|
|
|
|
flags: FdMemoryFlags,
|
|
|
|
) -> Result<gst::Memory, glib::BoolError> {
|
2022-12-25 10:47:02 +00:00
|
|
|
skip_assert_initialized!();
|
2022-10-18 11:16:04 +00:00
|
|
|
Option::<_>::from_glib_full(ffi::gst_fd_allocator_alloc(
|
2022-02-26 15:16:35 +00:00
|
|
|
self.unsafe_cast_ref::<gst::Allocator>().to_glib_none().0,
|
|
|
|
fd,
|
|
|
|
size,
|
|
|
|
flags.into_glib(),
|
|
|
|
))
|
2022-10-18 11:16:04 +00:00
|
|
|
.ok_or_else(|| glib::bool_error!("Failed to allocate memory"))
|
2022-02-26 15:16:35 +00:00
|
|
|
}
|
|
|
|
}
|