mirror of
https://gitlab.freedesktop.org/gstreamer/gstreamer-rs.git
synced 2024-11-22 09:31:06 +00:00
gstreamer: bufferlist: Change remove function to take a range instead of index + length
Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer-rs/-/merge_requests/1444>
This commit is contained in:
parent
a0e58ec359
commit
805cd6c591
1 changed files with 20 additions and 5 deletions
|
@ -1,6 +1,10 @@
|
|||
// Take a look at the license at the top of the repository in the LICENSE file.
|
||||
|
||||
use std::{fmt, ops::ControlFlow, ptr};
|
||||
use std::{
|
||||
fmt,
|
||||
ops::{ControlFlow, RangeBounds},
|
||||
ptr,
|
||||
};
|
||||
|
||||
use glib::translate::*;
|
||||
|
||||
|
@ -43,12 +47,23 @@ impl BufferListRef {
|
|||
}
|
||||
|
||||
#[doc(alias = "gst_buffer_list_remove")]
|
||||
pub fn remove(&mut self, idx: u32, len: u32) {
|
||||
pub fn remove(&mut self, range: impl RangeBounds<u32>) {
|
||||
let n = self.len() as u32;
|
||||
assert!(idx < n);
|
||||
assert!(idx.checked_add(len).unwrap() <= n);
|
||||
let start_idx = match range.start_bound() {
|
||||
std::ops::Bound::Included(idx) => *idx,
|
||||
std::ops::Bound::Excluded(idx) => idx.checked_add(1).unwrap(),
|
||||
std::ops::Bound::Unbounded => 0,
|
||||
};
|
||||
assert!(start_idx < n);
|
||||
|
||||
unsafe { ffi::gst_buffer_list_remove(self.as_mut_ptr(), idx, len) }
|
||||
let end_idx = match range.end_bound() {
|
||||
std::ops::Bound::Included(idx) => *idx,
|
||||
std::ops::Bound::Excluded(idx) => idx.checked_add(1).unwrap(),
|
||||
std::ops::Bound::Unbounded => n,
|
||||
};
|
||||
assert!(end_idx <= n);
|
||||
|
||||
unsafe { ffi::gst_buffer_list_remove(self.as_mut_ptr(), start_idx, end_idx - start_idx) }
|
||||
}
|
||||
|
||||
#[doc(alias = "gst_buffer_list_get")]
|
||||
|
|
Loading…
Reference in a new issue