mirror of
https://gitlab.freedesktop.org/gstreamer/gstreamer-rs.git
synced 2024-11-22 01:21:05 +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) }
|
||||
}
|
||||
|
||||
pub fn copy_part(&self, offset: isize, size: Option<usize>) -> Memory {
|
||||
let pos_sz = match size {
|
||||
Some(val) => val as isize,
|
||||
None => 0,
|
||||
#[doc(alias = "gst_memory_copy")]
|
||||
pub fn copy_range(&self, offset: isize, size: Option<usize>) -> Memory {
|
||||
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!(offset + pos_sz < (self.maxsize() as isize));
|
||||
|
||||
assert!(new_offset + size.unwrap_or(0) < self.maxsize());
|
||||
|
||||
unsafe {
|
||||
from_glib_full(ffi::gst_memory_copy(
|
||||
self.as_mut_ptr(),
|
||||
|
@ -291,11 +298,17 @@ impl MemoryRef {
|
|||
|
||||
#[doc(alias = "gst_memory_share")]
|
||||
pub fn share(&self, offset: isize, size: Option<usize>) -> Memory {
|
||||
let pos_sz = match size {
|
||||
Some(val) => val as isize,
|
||||
None => 0,
|
||||
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!(offset + pos_sz < (self.maxsize() as isize));
|
||||
|
||||
assert!(new_offset + size.unwrap_or(0) < self.maxsize());
|
||||
|
||||
unsafe {
|
||||
from_glib_full(ffi::gst_memory_share(
|
||||
self.as_ptr() as *mut _,
|
||||
|
@ -310,7 +323,17 @@ impl MemoryRef {
|
|||
|
||||
#[doc(alias = "gst_memory_resize")]
|
||||
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) }
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue