mirror of
https://gitlab.freedesktop.org/gstreamer/gstreamer-rs.git
synced 2024-11-22 09:31:06 +00:00
gstreamer: memory: Fix assertions for copy_range/resize/share functions
Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer-rs/-/merge_requests/1392>
This commit is contained in:
parent
8cceb92d5f
commit
b9307ca258
1 changed files with 33 additions and 10 deletions
|
@ -207,12 +207,19 @@ impl MemoryRef {
|
||||||
unsafe { from_glib(self.0.mini_object.flags) }
|
unsafe { from_glib(self.0.mini_object.flags) }
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn copy_part(&self, offset: isize, size: Option<usize>) -> Memory {
|
#[doc(alias = "gst_memory_copy")]
|
||||||
let pos_sz = match size {
|
pub fn copy_range(&self, offset: isize, size: Option<usize>) -> Memory {
|
||||||
Some(val) => val as isize,
|
let new_offset = if offset < 0 {
|
||||||
None => 0,
|
assert!((-offset) as usize >= self.offset());
|
||||||
|
self.offset() - (-offset as usize)
|
||||||
|
} else {
|
||||||
|
self.offset()
|
||||||
|
.checked_add(offset as usize)
|
||||||
|
.expect("Too large offset")
|
||||||
};
|
};
|
||||||
assert!(offset + pos_sz < (self.maxsize() as isize));
|
|
||||||
|
assert!(new_offset + size.unwrap_or(0) < self.maxsize());
|
||||||
|
|
||||||
unsafe {
|
unsafe {
|
||||||
from_glib_full(ffi::gst_memory_copy(
|
from_glib_full(ffi::gst_memory_copy(
|
||||||
self.as_mut_ptr(),
|
self.as_mut_ptr(),
|
||||||
|
@ -291,11 +298,17 @@ impl MemoryRef {
|
||||||
|
|
||||||
#[doc(alias = "gst_memory_share")]
|
#[doc(alias = "gst_memory_share")]
|
||||||
pub fn share(&self, offset: isize, size: Option<usize>) -> Memory {
|
pub fn share(&self, offset: isize, size: Option<usize>) -> Memory {
|
||||||
let pos_sz = match size {
|
let new_offset = if offset < 0 {
|
||||||
Some(val) => val as isize,
|
assert!((-offset) as usize >= self.offset());
|
||||||
None => 0,
|
self.offset() - (-offset as usize)
|
||||||
|
} else {
|
||||||
|
self.offset()
|
||||||
|
.checked_add(offset as usize)
|
||||||
|
.expect("Too large offset")
|
||||||
};
|
};
|
||||||
assert!(offset + pos_sz < (self.maxsize() as isize));
|
|
||||||
|
assert!(new_offset + size.unwrap_or(0) < self.maxsize());
|
||||||
|
|
||||||
unsafe {
|
unsafe {
|
||||||
from_glib_full(ffi::gst_memory_share(
|
from_glib_full(ffi::gst_memory_share(
|
||||||
self.as_ptr() as *mut _,
|
self.as_ptr() as *mut _,
|
||||||
|
@ -310,7 +323,17 @@ impl MemoryRef {
|
||||||
|
|
||||||
#[doc(alias = "gst_memory_resize")]
|
#[doc(alias = "gst_memory_resize")]
|
||||||
pub fn resize(&mut self, offset: isize, size: usize) {
|
pub fn resize(&mut self, offset: isize, size: usize) {
|
||||||
assert!(offset + (size as isize) < (self.maxsize() as isize));
|
let new_offset = if offset < 0 {
|
||||||
|
assert!((-offset) as usize >= self.offset());
|
||||||
|
self.offset() - (-offset as usize)
|
||||||
|
} else {
|
||||||
|
self.offset()
|
||||||
|
.checked_add(offset as usize)
|
||||||
|
.expect("Too large offset")
|
||||||
|
};
|
||||||
|
|
||||||
|
assert!(new_offset + size < self.maxsize());
|
||||||
|
|
||||||
unsafe { ffi::gst_memory_resize(self.as_mut_ptr(), offset, size) }
|
unsafe { ffi::gst_memory_resize(self.as_mut_ptr(), offset, size) }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue