mirror of
https://gitlab.freedesktop.org/gstreamer/gstreamer-rs.git
synced 2025-09-02 01:43:49 +00:00
memory: Don't store the memory / memory reference in the map info a second time
It's already stored in the C map info struct. Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer-rs/-/merge_requests/1734>
This commit is contained in:
parent
1b80213f9d
commit
dbe6282cc6
1 changed files with 15 additions and 18 deletions
|
@ -17,15 +17,13 @@ mini_object_wrapper!(Memory, MemoryRef, ffi::GstMemory, || {
|
||||||
});
|
});
|
||||||
|
|
||||||
pub struct MemoryMap<'a, T> {
|
pub struct MemoryMap<'a, T> {
|
||||||
memory: &'a MemoryRef,
|
|
||||||
map_info: ffi::GstMapInfo,
|
map_info: ffi::GstMapInfo,
|
||||||
phantom: PhantomData<T>,
|
phantom: PhantomData<(&'a MemoryRef, T)>,
|
||||||
}
|
}
|
||||||
|
|
||||||
pub struct MappedMemory<T> {
|
pub struct MappedMemory<T> {
|
||||||
memory: Memory,
|
|
||||||
map_info: ffi::GstMapInfo,
|
map_info: ffi::GstMapInfo,
|
||||||
phantom: PhantomData<T>,
|
phantom: PhantomData<(Memory, T)>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl fmt::Debug for Memory {
|
impl fmt::Debug for Memory {
|
||||||
|
@ -80,20 +78,20 @@ impl Memory {
|
||||||
#[inline]
|
#[inline]
|
||||||
pub fn into_mapped_memory_readable(self) -> Result<MappedMemory<Readable>, Self> {
|
pub fn into_mapped_memory_readable(self) -> Result<MappedMemory<Readable>, Self> {
|
||||||
unsafe {
|
unsafe {
|
||||||
|
let s = mem::ManuallyDrop::new(self);
|
||||||
let mut map_info = mem::MaybeUninit::uninit();
|
let mut map_info = mem::MaybeUninit::uninit();
|
||||||
let res: bool = from_glib(ffi::gst_memory_map(
|
let res: bool = from_glib(ffi::gst_memory_map(
|
||||||
self.as_mut_ptr(),
|
s.as_mut_ptr(),
|
||||||
map_info.as_mut_ptr(),
|
map_info.as_mut_ptr(),
|
||||||
ffi::GST_MAP_READ,
|
ffi::GST_MAP_READ,
|
||||||
));
|
));
|
||||||
if res {
|
if res {
|
||||||
Ok(MappedMemory {
|
Ok(MappedMemory {
|
||||||
memory: self,
|
|
||||||
map_info: map_info.assume_init(),
|
map_info: map_info.assume_init(),
|
||||||
phantom: PhantomData,
|
phantom: PhantomData,
|
||||||
})
|
})
|
||||||
} else {
|
} else {
|
||||||
Err(self)
|
Err(mem::ManuallyDrop::into_inner(s))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -101,20 +99,20 @@ impl Memory {
|
||||||
#[inline]
|
#[inline]
|
||||||
pub fn into_mapped_memory_writable(self) -> Result<MappedMemory<Writable>, Self> {
|
pub fn into_mapped_memory_writable(self) -> Result<MappedMemory<Writable>, Self> {
|
||||||
unsafe {
|
unsafe {
|
||||||
|
let s = mem::ManuallyDrop::new(self);
|
||||||
let mut map_info = mem::MaybeUninit::uninit();
|
let mut map_info = mem::MaybeUninit::uninit();
|
||||||
let res: bool = from_glib(ffi::gst_memory_map(
|
let res: bool = from_glib(ffi::gst_memory_map(
|
||||||
self.as_mut_ptr(),
|
s.as_mut_ptr(),
|
||||||
map_info.as_mut_ptr(),
|
map_info.as_mut_ptr(),
|
||||||
ffi::GST_MAP_READWRITE,
|
ffi::GST_MAP_READWRITE,
|
||||||
));
|
));
|
||||||
if res {
|
if res {
|
||||||
Ok(MappedMemory {
|
Ok(MappedMemory {
|
||||||
memory: self,
|
|
||||||
map_info: map_info.assume_init(),
|
map_info: map_info.assume_init(),
|
||||||
phantom: PhantomData,
|
phantom: PhantomData,
|
||||||
})
|
})
|
||||||
} else {
|
} else {
|
||||||
Err(self)
|
Err(mem::ManuallyDrop::into_inner(s))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -278,7 +276,6 @@ impl MemoryRef {
|
||||||
ffi::gst_memory_map(self.as_mut_ptr(), map_info.as_mut_ptr(), ffi::GST_MAP_READ);
|
ffi::gst_memory_map(self.as_mut_ptr(), map_info.as_mut_ptr(), ffi::GST_MAP_READ);
|
||||||
if res == glib::ffi::GTRUE {
|
if res == glib::ffi::GTRUE {
|
||||||
Ok(MemoryMap {
|
Ok(MemoryMap {
|
||||||
memory: self,
|
|
||||||
map_info: map_info.assume_init(),
|
map_info: map_info.assume_init(),
|
||||||
phantom: PhantomData,
|
phantom: PhantomData,
|
||||||
})
|
})
|
||||||
|
@ -299,7 +296,6 @@ impl MemoryRef {
|
||||||
);
|
);
|
||||||
if res == glib::ffi::GTRUE {
|
if res == glib::ffi::GTRUE {
|
||||||
Ok(MemoryMap {
|
Ok(MemoryMap {
|
||||||
memory: self,
|
|
||||||
map_info: map_info.assume_init(),
|
map_info: map_info.assume_init(),
|
||||||
phantom: PhantomData,
|
phantom: PhantomData,
|
||||||
})
|
})
|
||||||
|
@ -362,7 +358,7 @@ impl<T> MemoryMap<'_, T> {
|
||||||
#[doc(alias = "get_memory")]
|
#[doc(alias = "get_memory")]
|
||||||
#[inline]
|
#[inline]
|
||||||
pub fn memory(&self) -> &MemoryRef {
|
pub fn memory(&self) -> &MemoryRef {
|
||||||
self.memory
|
unsafe { MemoryRef::from_ptr(self.map_info.memory) }
|
||||||
}
|
}
|
||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
|
@ -432,7 +428,7 @@ impl<T> Drop for MemoryMap<'_, T> {
|
||||||
#[inline]
|
#[inline]
|
||||||
fn drop(&mut self) {
|
fn drop(&mut self) {
|
||||||
unsafe {
|
unsafe {
|
||||||
ffi::gst_memory_unmap(self.memory.as_mut_ptr(), &mut self.map_info);
|
ffi::gst_memory_unmap(self.map_info.memory, &mut self.map_info);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -458,15 +454,15 @@ impl<T> MappedMemory<T> {
|
||||||
#[doc(alias = "get_memory")]
|
#[doc(alias = "get_memory")]
|
||||||
#[inline]
|
#[inline]
|
||||||
pub fn memory(&self) -> &MemoryRef {
|
pub fn memory(&self) -> &MemoryRef {
|
||||||
self.memory.as_ref()
|
unsafe { MemoryRef::from_ptr(self.map_info.memory) }
|
||||||
}
|
}
|
||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
pub fn into_memory(self) -> Memory {
|
pub fn into_memory(self) -> Memory {
|
||||||
let mut s = mem::ManuallyDrop::new(self);
|
let mut s = mem::ManuallyDrop::new(self);
|
||||||
let memory = unsafe { ptr::read(&s.memory) };
|
let memory = unsafe { from_glib_full(s.map_info.memory) };
|
||||||
unsafe {
|
unsafe {
|
||||||
ffi::gst_memory_unmap(memory.as_mut_ptr(), &mut s.map_info);
|
ffi::gst_memory_unmap(s.map_info.memory, &mut s.map_info);
|
||||||
}
|
}
|
||||||
|
|
||||||
memory
|
memory
|
||||||
|
@ -517,7 +513,8 @@ impl<T> Drop for MappedMemory<T> {
|
||||||
#[inline]
|
#[inline]
|
||||||
fn drop(&mut self) {
|
fn drop(&mut self) {
|
||||||
unsafe {
|
unsafe {
|
||||||
ffi::gst_memory_unmap(self.memory.as_mut_ptr(), &mut self.map_info);
|
let _memory = Memory::from_glib_full(self.map_info.memory);
|
||||||
|
ffi::gst_memory_unmap(self.map_info.memory, &mut self.map_info);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue