mirror of
https://gitlab.freedesktop.org/gstreamer/gstreamer-rs.git
synced 2024-11-25 11:01:10 +00:00
gstreamer: Use usize instead of u32 for various indices
This affects buffers, caps, caps features, structures and tag lists and makes it easier to use them with other Rust APIs that use usize-based indicing. Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer-rs/-/merge_requests/1445>
This commit is contained in:
parent
4cda565a39
commit
9e2c6268cb
8 changed files with 183 additions and 179 deletions
|
@ -209,9 +209,10 @@ impl BufferRef {
|
||||||
|
|
||||||
fn memory_range_into_idx_len(
|
fn memory_range_into_idx_len(
|
||||||
&self,
|
&self,
|
||||||
range: impl RangeBounds<u32>,
|
range: impl RangeBounds<usize>,
|
||||||
) -> Result<(u32, i32), glib::BoolError> {
|
) -> Result<(u32, i32), glib::BoolError> {
|
||||||
let n_memory = self.n_memory();
|
let n_memory = self.n_memory();
|
||||||
|
debug_assert!(n_memory <= u32::MAX as usize);
|
||||||
|
|
||||||
let start_idx = match range.start_bound() {
|
let start_idx = match range.start_bound() {
|
||||||
ops::Bound::Included(idx) if *idx >= n_memory => {
|
ops::Bound::Included(idx) if *idx >= n_memory => {
|
||||||
|
@ -238,7 +239,7 @@ impl BufferRef {
|
||||||
};
|
};
|
||||||
|
|
||||||
Ok((
|
Ok((
|
||||||
start_idx,
|
start_idx as u32,
|
||||||
i32::try_from(end_idx - start_idx).map_err(|_| glib::bool_error!("Too large range"))?,
|
i32::try_from(end_idx - start_idx).map_err(|_| glib::bool_error!("Too large range"))?,
|
||||||
))
|
))
|
||||||
}
|
}
|
||||||
|
@ -247,7 +248,7 @@ impl BufferRef {
|
||||||
#[inline]
|
#[inline]
|
||||||
pub fn map_range_readable(
|
pub fn map_range_readable(
|
||||||
&self,
|
&self,
|
||||||
range: impl RangeBounds<u32>,
|
range: impl RangeBounds<usize>,
|
||||||
) -> Result<BufferMap<Readable>, glib::BoolError> {
|
) -> Result<BufferMap<Readable>, glib::BoolError> {
|
||||||
let (idx, len) = self.memory_range_into_idx_len(range)?;
|
let (idx, len) = self.memory_range_into_idx_len(range)?;
|
||||||
unsafe {
|
unsafe {
|
||||||
|
@ -275,7 +276,7 @@ impl BufferRef {
|
||||||
#[inline]
|
#[inline]
|
||||||
pub fn map_range_writable(
|
pub fn map_range_writable(
|
||||||
&mut self,
|
&mut self,
|
||||||
range: impl RangeBounds<u32>,
|
range: impl RangeBounds<usize>,
|
||||||
) -> Result<BufferMap<Writable>, glib::BoolError> {
|
) -> Result<BufferMap<Writable>, glib::BoolError> {
|
||||||
let (idx, len) = self.memory_range_into_idx_len(range)?;
|
let (idx, len) = self.memory_range_into_idx_len(range)?;
|
||||||
unsafe {
|
unsafe {
|
||||||
|
@ -656,7 +657,7 @@ impl BufferRef {
|
||||||
}
|
}
|
||||||
|
|
||||||
#[doc(alias = "gst_buffer_find_memory")]
|
#[doc(alias = "gst_buffer_find_memory")]
|
||||||
pub fn find_memory(&self, range: impl RangeBounds<usize>) -> Option<(Range<u32>, usize)> {
|
pub fn find_memory(&self, range: impl RangeBounds<usize>) -> Option<(Range<usize>, usize)> {
|
||||||
let (offset, size) = self.byte_range_into_offset_len(range).ok()?;
|
let (offset, size) = self.byte_range_into_offset_len(range).ok()?;
|
||||||
|
|
||||||
unsafe {
|
unsafe {
|
||||||
|
@ -674,8 +675,8 @@ impl BufferRef {
|
||||||
));
|
));
|
||||||
|
|
||||||
if res {
|
if res {
|
||||||
let idx = idx.assume_init();
|
let idx = idx.assume_init() as usize;
|
||||||
let length = length.assume_init();
|
let length = length.assume_init() as usize;
|
||||||
let skip = skip.assume_init();
|
let skip = skip.assume_init();
|
||||||
Some((idx..(idx + length), skip))
|
Some((idx..(idx + length), skip))
|
||||||
} else {
|
} else {
|
||||||
|
@ -687,56 +688,43 @@ impl BufferRef {
|
||||||
#[doc(alias = "get_all_memory")]
|
#[doc(alias = "get_all_memory")]
|
||||||
#[doc(alias = "gst_buffer_get_all_memory")]
|
#[doc(alias = "gst_buffer_get_all_memory")]
|
||||||
pub fn all_memory(&self) -> Option<Memory> {
|
pub fn all_memory(&self) -> Option<Memory> {
|
||||||
unsafe {
|
unsafe { from_glib_full(ffi::gst_buffer_get_all_memory(self.as_mut_ptr())) }
|
||||||
let res = ffi::gst_buffer_get_all_memory(self.as_mut_ptr());
|
|
||||||
if res.is_null() {
|
|
||||||
None
|
|
||||||
} else {
|
|
||||||
Some(from_glib_full(res))
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#[doc(alias = "get_max_memory")]
|
#[doc(alias = "get_max_memory")]
|
||||||
#[doc(alias = "gst_buffer_get_max_memory")]
|
#[doc(alias = "gst_buffer_get_max_memory")]
|
||||||
pub fn max_memory() -> u32 {
|
pub fn max_memory() -> usize {
|
||||||
unsafe { ffi::gst_buffer_get_max_memory() }
|
unsafe { ffi::gst_buffer_get_max_memory() as usize }
|
||||||
}
|
}
|
||||||
|
|
||||||
#[doc(alias = "get_memory")]
|
#[doc(alias = "get_memory")]
|
||||||
#[doc(alias = "gst_buffer_get_memory")]
|
#[doc(alias = "gst_buffer_get_memory")]
|
||||||
pub fn memory(&self, idx: u32) -> Option<Memory> {
|
pub fn memory(&self, idx: usize) -> Option<Memory> {
|
||||||
if idx >= self.n_memory() {
|
if idx >= self.n_memory() {
|
||||||
None
|
return None;
|
||||||
} else {
|
}
|
||||||
unsafe {
|
unsafe {
|
||||||
let res = ffi::gst_buffer_get_memory(self.as_mut_ptr(), idx);
|
let res = ffi::gst_buffer_get_memory(self.as_mut_ptr(), idx as u32);
|
||||||
if res.is_null() {
|
|
||||||
None
|
|
||||||
} else {
|
|
||||||
Some(from_glib_full(res))
|
Some(from_glib_full(res))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#[doc(alias = "get_memory_range")]
|
#[doc(alias = "get_memory_range")]
|
||||||
#[doc(alias = "gst_buffer_get_memory_range")]
|
#[doc(alias = "gst_buffer_get_memory_range")]
|
||||||
pub fn memory_range(&self, range: impl RangeBounds<u32>) -> Option<Memory> {
|
pub fn memory_range(&self, range: impl RangeBounds<usize>) -> Option<Memory> {
|
||||||
let (idx, len) = self.memory_range_into_idx_len(range).ok()?;
|
let (idx, len) = self.memory_range_into_idx_len(range).ok()?;
|
||||||
|
|
||||||
unsafe {
|
unsafe {
|
||||||
let res = ffi::gst_buffer_get_memory_range(self.as_mut_ptr(), idx, len);
|
let res = ffi::gst_buffer_get_memory_range(self.as_mut_ptr(), idx, len);
|
||||||
if res.is_null() {
|
from_glib_full(res)
|
||||||
None
|
|
||||||
} else {
|
|
||||||
Some(from_glib_full(res))
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[doc(alias = "gst_buffer_insert_memory")]
|
#[doc(alias = "gst_buffer_insert_memory")]
|
||||||
pub fn insert_memory(&mut self, idx: u32, mem: Memory) {
|
pub fn insert_memory(&mut self, idx: impl Into<Option<usize>>, mem: Memory) {
|
||||||
|
let n_memory = self.n_memory();
|
||||||
|
let idx = idx.into();
|
||||||
|
let idx = idx.unwrap_or(n_memory);
|
||||||
assert!(idx <= self.n_memory());
|
assert!(idx <= self.n_memory());
|
||||||
unsafe { ffi::gst_buffer_insert_memory(self.as_mut_ptr(), idx as i32, mem.into_glib_ptr()) }
|
unsafe { ffi::gst_buffer_insert_memory(self.as_mut_ptr(), idx as i32, mem.into_glib_ptr()) }
|
||||||
}
|
}
|
||||||
|
@ -747,7 +735,7 @@ impl BufferRef {
|
||||||
}
|
}
|
||||||
|
|
||||||
#[doc(alias = "gst_buffer_is_memory_range_writable")]
|
#[doc(alias = "gst_buffer_is_memory_range_writable")]
|
||||||
pub fn is_memory_range_writable(&self, range: impl RangeBounds<u32>) -> bool {
|
pub fn is_memory_range_writable(&self, range: impl RangeBounds<usize>) -> bool {
|
||||||
let Some((idx, len)) = self.memory_range_into_idx_len(range).ok() else {
|
let Some((idx, len)) = self.memory_range_into_idx_len(range).ok() else {
|
||||||
return false;
|
return false;
|
||||||
};
|
};
|
||||||
|
@ -762,28 +750,25 @@ impl BufferRef {
|
||||||
}
|
}
|
||||||
|
|
||||||
#[doc(alias = "gst_buffer_n_memory")]
|
#[doc(alias = "gst_buffer_n_memory")]
|
||||||
pub fn n_memory(&self) -> u32 {
|
pub fn n_memory(&self) -> usize {
|
||||||
unsafe { ffi::gst_buffer_n_memory(self.as_ptr() as *mut _) }
|
unsafe { ffi::gst_buffer_n_memory(self.as_ptr() as *mut _) as usize }
|
||||||
}
|
}
|
||||||
|
|
||||||
#[doc(alias = "gst_buffer_peek_memory")]
|
#[doc(alias = "gst_buffer_peek_memory")]
|
||||||
pub fn peek_memory(&self, idx: u32) -> &MemoryRef {
|
pub fn peek_memory(&self, idx: usize) -> &MemoryRef {
|
||||||
assert!(idx < self.n_memory());
|
assert!(idx < self.n_memory());
|
||||||
unsafe { MemoryRef::from_ptr(ffi::gst_buffer_peek_memory(self.as_mut_ptr(), idx)) }
|
unsafe { MemoryRef::from_ptr(ffi::gst_buffer_peek_memory(self.as_mut_ptr(), idx as u32)) }
|
||||||
}
|
}
|
||||||
|
|
||||||
#[doc(alias = "gst_buffer_peek_memory")]
|
#[doc(alias = "gst_buffer_peek_memory")]
|
||||||
pub fn peek_memory_mut(&mut self, idx: u32) -> Result<&mut MemoryRef, glib::BoolError> {
|
pub fn peek_memory_mut(&mut self, idx: usize) -> Result<&mut MemoryRef, glib::BoolError> {
|
||||||
assert!(idx < self.n_memory());
|
assert!(idx < self.n_memory());
|
||||||
unsafe {
|
unsafe {
|
||||||
let mem = ffi::gst_buffer_peek_memory(self.as_mut_ptr(), idx);
|
let mem = ffi::gst_buffer_peek_memory(self.as_mut_ptr(), idx as u32);
|
||||||
if ffi::gst_mini_object_is_writable(mem as *mut _) == glib::ffi::GFALSE {
|
if ffi::gst_mini_object_is_writable(mem as *mut _) == glib::ffi::GFALSE {
|
||||||
Err(glib::bool_error!("Memory not writable"))
|
Err(glib::bool_error!("Memory not writable"))
|
||||||
} else {
|
} else {
|
||||||
Ok(MemoryRef::from_mut_ptr(ffi::gst_buffer_peek_memory(
|
Ok(MemoryRef::from_mut_ptr(mem))
|
||||||
self.as_mut_ptr(),
|
|
||||||
idx,
|
|
||||||
)))
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -799,13 +784,13 @@ impl BufferRef {
|
||||||
}
|
}
|
||||||
|
|
||||||
#[doc(alias = "gst_buffer_remove_memory")]
|
#[doc(alias = "gst_buffer_remove_memory")]
|
||||||
pub fn remove_memory(&mut self, idx: u32) {
|
pub fn remove_memory(&mut self, idx: usize) {
|
||||||
assert!(idx < self.n_memory());
|
assert!(idx < self.n_memory());
|
||||||
unsafe { ffi::gst_buffer_remove_memory(self.as_mut_ptr(), idx) }
|
unsafe { ffi::gst_buffer_remove_memory(self.as_mut_ptr(), idx as u32) }
|
||||||
}
|
}
|
||||||
|
|
||||||
#[doc(alias = "gst_buffer_remove_memory_range")]
|
#[doc(alias = "gst_buffer_remove_memory_range")]
|
||||||
pub fn remove_memory_range(&mut self, range: impl RangeBounds<u32>) {
|
pub fn remove_memory_range(&mut self, range: impl RangeBounds<usize>) {
|
||||||
let (idx, len) = self
|
let (idx, len) = self
|
||||||
.memory_range_into_idx_len(range)
|
.memory_range_into_idx_len(range)
|
||||||
.expect("Invalid memory range");
|
.expect("Invalid memory range");
|
||||||
|
@ -819,13 +804,15 @@ impl BufferRef {
|
||||||
}
|
}
|
||||||
|
|
||||||
#[doc(alias = "gst_buffer_replace_memory")]
|
#[doc(alias = "gst_buffer_replace_memory")]
|
||||||
pub fn replace_memory(&mut self, idx: u32, mem: Memory) {
|
pub fn replace_memory(&mut self, idx: usize, mem: Memory) {
|
||||||
assert!(idx < self.n_memory());
|
assert!(idx < self.n_memory());
|
||||||
unsafe { ffi::gst_buffer_replace_memory(self.as_mut_ptr(), idx, mem.into_glib_ptr()) }
|
unsafe {
|
||||||
|
ffi::gst_buffer_replace_memory(self.as_mut_ptr(), idx as u32, mem.into_glib_ptr())
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[doc(alias = "gst_buffer_replace_memory_range")]
|
#[doc(alias = "gst_buffer_replace_memory_range")]
|
||||||
pub fn replace_memory_range(&mut self, range: impl RangeBounds<u32>, mem: Memory) {
|
pub fn replace_memory_range(&mut self, range: impl RangeBounds<usize>, mem: Memory) {
|
||||||
let (idx, len) = self
|
let (idx, len) = self
|
||||||
.memory_range_into_idx_len(range)
|
.memory_range_into_idx_len(range)
|
||||||
.expect("Invalid memory range");
|
.expect("Invalid memory range");
|
||||||
|
@ -984,7 +971,7 @@ macro_rules! define_iter(
|
||||||
$name {
|
$name {
|
||||||
buffer,
|
buffer,
|
||||||
idx: 0,
|
idx: 0,
|
||||||
n_memory: n_memory as usize,
|
n_memory,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1000,7 +987,7 @@ macro_rules! define_iter(
|
||||||
|
|
||||||
#[allow(unused_unsafe)]
|
#[allow(unused_unsafe)]
|
||||||
unsafe {
|
unsafe {
|
||||||
let item = $get_item(self.buffer, self.idx as u32).unwrap();
|
let item = $get_item(self.buffer, self.idx).unwrap();
|
||||||
self.idx += 1;
|
self.idx += 1;
|
||||||
Some(item)
|
Some(item)
|
||||||
}
|
}
|
||||||
|
@ -1025,7 +1012,7 @@ macro_rules! define_iter(
|
||||||
#[allow(unused_unsafe)]
|
#[allow(unused_unsafe)]
|
||||||
unsafe {
|
unsafe {
|
||||||
self.idx = end + 1;
|
self.idx = end + 1;
|
||||||
Some($get_item(self.buffer, end as u32).unwrap())
|
Some($get_item(self.buffer, end).unwrap())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1036,7 +1023,7 @@ macro_rules! define_iter(
|
||||||
} else {
|
} else {
|
||||||
#[allow(unused_unsafe)]
|
#[allow(unused_unsafe)]
|
||||||
unsafe {
|
unsafe {
|
||||||
Some($get_item(self.buffer, self.n_memory as u32 - 1).unwrap())
|
Some($get_item(self.buffer, self.n_memory - 1).unwrap())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1052,7 +1039,7 @@ macro_rules! define_iter(
|
||||||
#[allow(unused_unsafe)]
|
#[allow(unused_unsafe)]
|
||||||
unsafe {
|
unsafe {
|
||||||
self.n_memory -= 1;
|
self.n_memory -= 1;
|
||||||
Some($get_item(self.buffer, self.n_memory as u32).unwrap())
|
Some($get_item(self.buffer, self.n_memory).unwrap())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1065,7 +1052,7 @@ macro_rules! define_iter(
|
||||||
#[allow(unused_unsafe)]
|
#[allow(unused_unsafe)]
|
||||||
unsafe {
|
unsafe {
|
||||||
self.n_memory = end - 1;
|
self.n_memory = end - 1;
|
||||||
Some($get_item(self.buffer, self.n_memory as u32).unwrap())
|
Some($get_item(self.buffer, self.n_memory).unwrap())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1082,7 +1069,7 @@ define_iter!(
|
||||||
&'a BufferRef,
|
&'a BufferRef,
|
||||||
&'a MemoryRef,
|
&'a MemoryRef,
|
||||||
|buffer: &BufferRef, idx| {
|
|buffer: &BufferRef, idx| {
|
||||||
let ptr = ffi::gst_buffer_peek_memory(buffer.as_mut_ptr(), idx);
|
let ptr = ffi::gst_buffer_peek_memory(buffer.as_mut_ptr(), idx as u32);
|
||||||
if ptr.is_null() {
|
if ptr.is_null() {
|
||||||
None
|
None
|
||||||
} else {
|
} else {
|
||||||
|
@ -1096,7 +1083,7 @@ define_iter!(
|
||||||
&'a mut BufferRef,
|
&'a mut BufferRef,
|
||||||
&'a mut MemoryRef,
|
&'a mut MemoryRef,
|
||||||
|buffer: &mut BufferRef, idx| {
|
|buffer: &mut BufferRef, idx| {
|
||||||
let ptr = ffi::gst_buffer_peek_memory(buffer.as_mut_ptr(), idx);
|
let ptr = ffi::gst_buffer_peek_memory(buffer.as_mut_ptr(), idx as u32);
|
||||||
if ptr.is_null() {
|
if ptr.is_null() {
|
||||||
None
|
None
|
||||||
} else {
|
} else {
|
||||||
|
@ -1457,8 +1444,8 @@ pub struct Dump<'a> {
|
||||||
|
|
||||||
struct BufferChunked16Iter<'a> {
|
struct BufferChunked16Iter<'a> {
|
||||||
buffer: &'a BufferRef,
|
buffer: &'a BufferRef,
|
||||||
mem_idx: u32,
|
mem_idx: usize,
|
||||||
mem_len: u32,
|
mem_len: usize,
|
||||||
map: Option<crate::memory::MemoryMap<'a, crate::memory::Readable>>,
|
map: Option<crate::memory::MemoryMap<'a, crate::memory::Readable>>,
|
||||||
map_offset: usize,
|
map_offset: usize,
|
||||||
len: usize,
|
len: usize,
|
||||||
|
|
|
@ -10,8 +10,8 @@ use crate::{
|
||||||
pub struct BufferCursor<T> {
|
pub struct BufferCursor<T> {
|
||||||
buffer: Option<Buffer>,
|
buffer: Option<Buffer>,
|
||||||
size: u64,
|
size: u64,
|
||||||
num_mem: u32,
|
num_mem: usize,
|
||||||
cur_mem_idx: u32,
|
cur_mem_idx: usize,
|
||||||
cur_offset: u64,
|
cur_offset: u64,
|
||||||
cur_mem_offset: usize,
|
cur_mem_offset: usize,
|
||||||
map_info: ffi::GstMapInfo,
|
map_info: ffi::GstMapInfo,
|
||||||
|
@ -21,8 +21,8 @@ pub struct BufferCursor<T> {
|
||||||
pub struct BufferRefCursor<T> {
|
pub struct BufferRefCursor<T> {
|
||||||
buffer: T,
|
buffer: T,
|
||||||
size: u64,
|
size: u64,
|
||||||
num_mem: u32,
|
num_mem: usize,
|
||||||
cur_mem_idx: u32,
|
cur_mem_idx: usize,
|
||||||
cur_offset: u64,
|
cur_offset: u64,
|
||||||
cur_mem_offset: usize,
|
cur_mem_offset: usize,
|
||||||
map_info: ffi::GstMapInfo,
|
map_info: ffi::GstMapInfo,
|
||||||
|
@ -112,7 +112,7 @@ macro_rules! define_read_write_fn_impl(
|
||||||
let buffer_ref: fn(&Self) -> &BufferRef = $get_buffer_ref;
|
let buffer_ref: fn(&Self) -> &BufferRef = $get_buffer_ref;
|
||||||
let memory = ffi::gst_buffer_peek_memory(
|
let memory = ffi::gst_buffer_peek_memory(
|
||||||
buffer_ref($self).as_mut_ptr(),
|
buffer_ref($self).as_mut_ptr(),
|
||||||
$self.cur_mem_idx,
|
$self.cur_mem_idx as u32,
|
||||||
);
|
);
|
||||||
debug_assert!(!memory.is_null());
|
debug_assert!(!memory.is_null());
|
||||||
|
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
// Take a look at the license at the top of the repository in the LICENSE file.
|
// Take a look at the license at the top of the repository in the LICENSE file.
|
||||||
|
|
||||||
use std::{
|
use std::{
|
||||||
fmt,
|
cmp, fmt,
|
||||||
ops::{ControlFlow, RangeBounds},
|
ops::{ControlFlow, RangeBounds},
|
||||||
ptr,
|
ptr,
|
||||||
};
|
};
|
||||||
|
@ -24,21 +24,26 @@ impl BufferList {
|
||||||
#[doc(alias = "gst_buffer_list_new_sized")]
|
#[doc(alias = "gst_buffer_list_new_sized")]
|
||||||
pub fn new_sized(size: usize) -> Self {
|
pub fn new_sized(size: usize) -> Self {
|
||||||
assert_initialized_main_thread!();
|
assert_initialized_main_thread!();
|
||||||
unsafe { from_glib_full(ffi::gst_buffer_list_new_sized(size as u32)) }
|
unsafe { from_glib_full(ffi::gst_buffer_list_new_sized(u32::try_from(size).unwrap())) }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl BufferListRef {
|
impl BufferListRef {
|
||||||
#[doc(alias = "gst_buffer_list_insert")]
|
#[doc(alias = "gst_buffer_list_insert")]
|
||||||
pub fn insert(&mut self, idx: i32, buffer: Buffer) {
|
pub fn insert(&mut self, idx: impl Into<Option<usize>>, buffer: Buffer) {
|
||||||
unsafe {
|
unsafe {
|
||||||
|
let len = self.len();
|
||||||
|
debug_assert!(len <= u32::MAX as usize);
|
||||||
|
|
||||||
|
let idx = idx.into();
|
||||||
|
let idx = cmp::min(idx.unwrap_or(len), len) as i32;
|
||||||
ffi::gst_buffer_list_insert(self.as_mut_ptr(), idx, buffer.into_glib_ptr());
|
ffi::gst_buffer_list_insert(self.as_mut_ptr(), idx, buffer.into_glib_ptr());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[doc(alias = "gst_buffer_list_add")]
|
#[doc(alias = "gst_buffer_list_add")]
|
||||||
pub fn add(&mut self, buffer: Buffer) {
|
pub fn add(&mut self, buffer: Buffer) {
|
||||||
self.insert(-1, buffer);
|
self.insert(None, buffer);
|
||||||
}
|
}
|
||||||
|
|
||||||
#[doc(alias = "gst_buffer_list_copy_deep")]
|
#[doc(alias = "gst_buffer_list_copy_deep")]
|
||||||
|
@ -47,8 +52,10 @@ impl BufferListRef {
|
||||||
}
|
}
|
||||||
|
|
||||||
#[doc(alias = "gst_buffer_list_remove")]
|
#[doc(alias = "gst_buffer_list_remove")]
|
||||||
pub fn remove(&mut self, range: impl RangeBounds<u32>) {
|
pub fn remove(&mut self, range: impl RangeBounds<usize>) {
|
||||||
let n = self.len() as u32;
|
let n = self.len();
|
||||||
|
debug_assert!(n <= u32::MAX as usize);
|
||||||
|
|
||||||
let start_idx = match range.start_bound() {
|
let start_idx = match range.start_bound() {
|
||||||
std::ops::Bound::Included(idx) => *idx,
|
std::ops::Bound::Included(idx) => *idx,
|
||||||
std::ops::Bound::Excluded(idx) => idx.checked_add(1).unwrap(),
|
std::ops::Bound::Excluded(idx) => idx.checked_add(1).unwrap(),
|
||||||
|
@ -63,39 +70,45 @@ impl BufferListRef {
|
||||||
};
|
};
|
||||||
assert!(end_idx <= n);
|
assert!(end_idx <= n);
|
||||||
|
|
||||||
unsafe { ffi::gst_buffer_list_remove(self.as_mut_ptr(), start_idx, end_idx - start_idx) }
|
unsafe {
|
||||||
|
ffi::gst_buffer_list_remove(
|
||||||
|
self.as_mut_ptr(),
|
||||||
|
start_idx as u32,
|
||||||
|
(end_idx - start_idx) as u32,
|
||||||
|
)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[doc(alias = "gst_buffer_list_get")]
|
#[doc(alias = "gst_buffer_list_get")]
|
||||||
pub fn get(&self, idx: u32) -> Option<&BufferRef> {
|
pub fn get(&self, idx: usize) -> Option<&BufferRef> {
|
||||||
unsafe {
|
unsafe {
|
||||||
if idx as usize >= self.len() {
|
if idx >= self.len() {
|
||||||
return None;
|
return None;
|
||||||
}
|
}
|
||||||
let ptr = ffi::gst_buffer_list_get(self.as_mut_ptr(), idx);
|
let ptr = ffi::gst_buffer_list_get(self.as_mut_ptr(), idx as u32);
|
||||||
Some(BufferRef::from_ptr(ptr))
|
Some(BufferRef::from_ptr(ptr))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[doc(alias = "gst_buffer_list_get")]
|
#[doc(alias = "gst_buffer_list_get")]
|
||||||
pub fn get_owned(&self, idx: u32) -> Option<Buffer> {
|
pub fn get_owned(&self, idx: usize) -> Option<Buffer> {
|
||||||
unsafe {
|
unsafe {
|
||||||
if idx as usize >= self.len() {
|
if idx >= self.len() {
|
||||||
return None;
|
return None;
|
||||||
}
|
}
|
||||||
let ptr = ffi::gst_buffer_list_get(self.as_mut_ptr(), idx);
|
let ptr = ffi::gst_buffer_list_get(self.as_mut_ptr(), idx as u32);
|
||||||
Some(from_glib_none(ptr))
|
Some(from_glib_none(ptr))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[doc(alias = "gst_buffer_list_get_writable")]
|
#[doc(alias = "gst_buffer_list_get_writable")]
|
||||||
#[doc(alias = "get_writable")]
|
#[doc(alias = "get_writable")]
|
||||||
pub fn get_mut(&mut self, idx: u32) -> Option<&mut BufferRef> {
|
pub fn get_mut(&mut self, idx: usize) -> Option<&mut BufferRef> {
|
||||||
unsafe {
|
unsafe {
|
||||||
if idx as usize >= self.len() {
|
if idx >= self.len() {
|
||||||
return None;
|
return None;
|
||||||
}
|
}
|
||||||
let ptr = ffi::gst_buffer_list_get_writable(self.as_mut_ptr(), idx);
|
let ptr = ffi::gst_buffer_list_get_writable(self.as_mut_ptr(), idx as u32);
|
||||||
Some(BufferRef::from_mut_ptr(ptr))
|
Some(BufferRef::from_mut_ptr(ptr))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -123,14 +136,14 @@ impl BufferListRef {
|
||||||
}
|
}
|
||||||
|
|
||||||
#[doc(alias = "gst_buffer_list_foreach")]
|
#[doc(alias = "gst_buffer_list_foreach")]
|
||||||
pub fn foreach<F: FnMut(&Buffer, u32) -> ControlFlow<(), ()>>(&self, func: F) -> bool {
|
pub fn foreach<F: FnMut(&Buffer, usize) -> ControlFlow<(), ()>>(&self, func: F) -> bool {
|
||||||
unsafe extern "C" fn trampoline<F: FnMut(&Buffer, u32) -> ControlFlow<(), ()>>(
|
unsafe extern "C" fn trampoline<F: FnMut(&Buffer, usize) -> ControlFlow<(), ()>>(
|
||||||
buffer: *mut *mut ffi::GstBuffer,
|
buffer: *mut *mut ffi::GstBuffer,
|
||||||
idx: u32,
|
idx: u32,
|
||||||
user_data: glib::ffi::gpointer,
|
user_data: glib::ffi::gpointer,
|
||||||
) -> glib::ffi::gboolean {
|
) -> glib::ffi::gboolean {
|
||||||
let func = user_data as *mut F;
|
let func = user_data as *mut F;
|
||||||
let res = (*func)(&Buffer::from_glib_borrow(*buffer), idx);
|
let res = (*func)(&Buffer::from_glib_borrow(*buffer), idx as usize);
|
||||||
|
|
||||||
matches!(res, ControlFlow::Continue(_)).into_glib()
|
matches!(res, ControlFlow::Continue(_)).into_glib()
|
||||||
}
|
}
|
||||||
|
@ -147,12 +160,12 @@ impl BufferListRef {
|
||||||
}
|
}
|
||||||
|
|
||||||
#[doc(alias = "gst_buffer_list_foreach")]
|
#[doc(alias = "gst_buffer_list_foreach")]
|
||||||
pub fn foreach_mut<F: FnMut(Buffer, u32) -> ControlFlow<Option<Buffer>, Option<Buffer>>>(
|
pub fn foreach_mut<F: FnMut(Buffer, usize) -> ControlFlow<Option<Buffer>, Option<Buffer>>>(
|
||||||
&mut self,
|
&mut self,
|
||||||
func: F,
|
func: F,
|
||||||
) -> bool {
|
) -> bool {
|
||||||
unsafe extern "C" fn trampoline<
|
unsafe extern "C" fn trampoline<
|
||||||
F: FnMut(Buffer, u32) -> ControlFlow<Option<Buffer>, Option<Buffer>>,
|
F: FnMut(Buffer, usize) -> ControlFlow<Option<Buffer>, Option<Buffer>>,
|
||||||
>(
|
>(
|
||||||
buffer: *mut *mut ffi::GstBuffer,
|
buffer: *mut *mut ffi::GstBuffer,
|
||||||
idx: u32,
|
idx: u32,
|
||||||
|
@ -164,7 +177,7 @@ impl BufferListRef {
|
||||||
buffer as *mut *const ffi::GstBuffer,
|
buffer as *mut *const ffi::GstBuffer,
|
||||||
ptr::null_mut::<ffi::GstBuffer>(),
|
ptr::null_mut::<ffi::GstBuffer>(),
|
||||||
)),
|
)),
|
||||||
idx,
|
idx as usize,
|
||||||
);
|
);
|
||||||
|
|
||||||
let (cont, res_buffer) = match res {
|
let (cont, res_buffer) = match res {
|
||||||
|
@ -243,7 +256,7 @@ macro_rules! define_iter(
|
||||||
$name {
|
$name {
|
||||||
list,
|
list,
|
||||||
idx: 0,
|
idx: 0,
|
||||||
size: list.len() as usize,
|
size: list.len(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -257,7 +270,7 @@ macro_rules! define_iter(
|
||||||
return None;
|
return None;
|
||||||
}
|
}
|
||||||
|
|
||||||
let item = $get_item(self.list, self.idx as u32).unwrap();
|
let item = $get_item(self.list, self.idx).unwrap();
|
||||||
self.idx += 1;
|
self.idx += 1;
|
||||||
|
|
||||||
Some(item)
|
Some(item)
|
||||||
|
@ -280,7 +293,7 @@ macro_rules! define_iter(
|
||||||
None
|
None
|
||||||
} else {
|
} else {
|
||||||
self.idx = end + 1;
|
self.idx = end + 1;
|
||||||
Some($get_item(self.list, end as u32).unwrap())
|
Some($get_item(self.list, end).unwrap())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -288,7 +301,7 @@ macro_rules! define_iter(
|
||||||
if self.idx == self.size {
|
if self.idx == self.size {
|
||||||
None
|
None
|
||||||
} else {
|
} else {
|
||||||
Some($get_item(self.list, self.size as u32 - 1).unwrap())
|
Some($get_item(self.list, self.size - 1).unwrap())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -301,7 +314,7 @@ macro_rules! define_iter(
|
||||||
}
|
}
|
||||||
|
|
||||||
self.size -= 1;
|
self.size -= 1;
|
||||||
Some($get_item(self.list, self.size as u32).unwrap())
|
Some($get_item(self.list, self.size).unwrap())
|
||||||
}
|
}
|
||||||
|
|
||||||
fn nth_back(&mut self, n: usize) -> Option<Self::Item> {
|
fn nth_back(&mut self, n: usize) -> Option<Self::Item> {
|
||||||
|
@ -311,7 +324,7 @@ macro_rules! define_iter(
|
||||||
None
|
None
|
||||||
} else {
|
} else {
|
||||||
self.size = end - 1;
|
self.size = end - 1;
|
||||||
Some($get_item(self.list, self.size as u32).unwrap())
|
Some($get_item(self.list, self.size).unwrap())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -316,13 +316,13 @@ impl CapsRef {
|
||||||
|
|
||||||
#[doc(alias = "get_structure")]
|
#[doc(alias = "get_structure")]
|
||||||
#[doc(alias = "gst_caps_get_structure")]
|
#[doc(alias = "gst_caps_get_structure")]
|
||||||
pub fn structure(&self, idx: u32) -> Option<&StructureRef> {
|
pub fn structure(&self, idx: usize) -> Option<&StructureRef> {
|
||||||
if idx >= self.size() {
|
if idx >= self.size() {
|
||||||
return None;
|
return None;
|
||||||
}
|
}
|
||||||
|
|
||||||
unsafe {
|
unsafe {
|
||||||
let structure = ffi::gst_caps_get_structure(self.as_ptr(), idx);
|
let structure = ffi::gst_caps_get_structure(self.as_ptr(), idx as u32);
|
||||||
if structure.is_null() {
|
if structure.is_null() {
|
||||||
return None;
|
return None;
|
||||||
}
|
}
|
||||||
|
@ -333,13 +333,13 @@ impl CapsRef {
|
||||||
|
|
||||||
#[doc(alias = "get_mut_structure")]
|
#[doc(alias = "get_mut_structure")]
|
||||||
#[doc(alias = "gst_caps_get_structure")]
|
#[doc(alias = "gst_caps_get_structure")]
|
||||||
pub fn structure_mut(&mut self, idx: u32) -> Option<&mut StructureRef> {
|
pub fn structure_mut(&mut self, idx: usize) -> Option<&mut StructureRef> {
|
||||||
if idx >= self.size() {
|
if idx >= self.size() {
|
||||||
return None;
|
return None;
|
||||||
}
|
}
|
||||||
|
|
||||||
unsafe {
|
unsafe {
|
||||||
let structure = ffi::gst_caps_get_structure(self.as_ptr(), idx);
|
let structure = ffi::gst_caps_get_structure(self.as_ptr(), idx as u32);
|
||||||
if structure.is_null() {
|
if structure.is_null() {
|
||||||
return None;
|
return None;
|
||||||
}
|
}
|
||||||
|
@ -350,38 +350,38 @@ impl CapsRef {
|
||||||
|
|
||||||
#[doc(alias = "get_features")]
|
#[doc(alias = "get_features")]
|
||||||
#[doc(alias = "gst_caps_get_features")]
|
#[doc(alias = "gst_caps_get_features")]
|
||||||
pub fn features(&self, idx: u32) -> Option<&CapsFeaturesRef> {
|
pub fn features(&self, idx: usize) -> Option<&CapsFeaturesRef> {
|
||||||
if idx >= self.size() {
|
if idx >= self.size() {
|
||||||
return None;
|
return None;
|
||||||
}
|
}
|
||||||
|
|
||||||
unsafe {
|
unsafe {
|
||||||
let features = ffi::gst_caps_get_features(self.as_ptr(), idx);
|
let features = ffi::gst_caps_get_features(self.as_ptr(), idx as u32);
|
||||||
Some(CapsFeaturesRef::from_glib_borrow(features))
|
Some(CapsFeaturesRef::from_glib_borrow(features))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[doc(alias = "get_mut_features")]
|
#[doc(alias = "get_mut_features")]
|
||||||
#[doc(alias = "gst_caps_get_features")]
|
#[doc(alias = "gst_caps_get_features")]
|
||||||
pub fn features_mut(&mut self, idx: u32) -> Option<&mut CapsFeaturesRef> {
|
pub fn features_mut(&mut self, idx: usize) -> Option<&mut CapsFeaturesRef> {
|
||||||
if idx >= self.size() {
|
if idx >= self.size() {
|
||||||
return None;
|
return None;
|
||||||
}
|
}
|
||||||
|
|
||||||
unsafe {
|
unsafe {
|
||||||
let features = ffi::gst_caps_get_features(self.as_ptr(), idx);
|
let features = ffi::gst_caps_get_features(self.as_ptr(), idx as u32);
|
||||||
Some(CapsFeaturesRef::from_glib_borrow_mut(features))
|
Some(CapsFeaturesRef::from_glib_borrow_mut(features))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[doc(alias = "gst_caps_set_features")]
|
#[doc(alias = "gst_caps_set_features")]
|
||||||
pub fn set_features(&mut self, idx: u32, features: Option<CapsFeatures>) {
|
pub fn set_features(&mut self, idx: usize, features: Option<CapsFeatures>) {
|
||||||
assert!(idx < self.size());
|
assert!(idx < self.size());
|
||||||
|
|
||||||
unsafe {
|
unsafe {
|
||||||
ffi::gst_caps_set_features(
|
ffi::gst_caps_set_features(
|
||||||
self.as_mut_ptr(),
|
self.as_mut_ptr(),
|
||||||
idx,
|
idx as u32,
|
||||||
features
|
features
|
||||||
.map(|f| f.into_glib_ptr())
|
.map(|f| f.into_glib_ptr())
|
||||||
.unwrap_or(ptr::null_mut()),
|
.unwrap_or(ptr::null_mut()),
|
||||||
|
@ -405,8 +405,12 @@ impl CapsRef {
|
||||||
|
|
||||||
#[doc(alias = "get_size")]
|
#[doc(alias = "get_size")]
|
||||||
#[doc(alias = "gst_caps_get_size")]
|
#[doc(alias = "gst_caps_get_size")]
|
||||||
pub fn size(&self) -> u32 {
|
pub fn size(&self) -> usize {
|
||||||
unsafe { ffi::gst_caps_get_size(self.as_ptr()) }
|
unsafe { ffi::gst_caps_get_size(self.as_ptr()) as usize }
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn len(&self) -> usize {
|
||||||
|
self.size()
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn iter(&self) -> Iter {
|
pub fn iter(&self) -> Iter {
|
||||||
|
@ -444,8 +448,10 @@ impl CapsRef {
|
||||||
}
|
}
|
||||||
|
|
||||||
#[doc(alias = "gst_caps_remove_structure")]
|
#[doc(alias = "gst_caps_remove_structure")]
|
||||||
pub fn remove_structure(&mut self, idx: u32) {
|
pub fn remove_structure(&mut self, idx: usize) {
|
||||||
unsafe { ffi::gst_caps_remove_structure(self.as_mut_ptr(), idx) }
|
assert!(idx < self.size());
|
||||||
|
|
||||||
|
unsafe { ffi::gst_caps_remove_structure(self.as_mut_ptr(), idx as u32) }
|
||||||
}
|
}
|
||||||
|
|
||||||
#[doc(alias = "gst_caps_append")]
|
#[doc(alias = "gst_caps_append")]
|
||||||
|
@ -704,7 +710,7 @@ macro_rules! define_iter(
|
||||||
}
|
}
|
||||||
|
|
||||||
unsafe {
|
unsafe {
|
||||||
let item = $get_item(self.caps, self.idx as u32).unwrap();
|
let item = $get_item(self.caps, self.idx).unwrap();
|
||||||
self.idx += 1;
|
self.idx += 1;
|
||||||
Some(item)
|
Some(item)
|
||||||
}
|
}
|
||||||
|
@ -728,7 +734,7 @@ macro_rules! define_iter(
|
||||||
} else {
|
} else {
|
||||||
unsafe {
|
unsafe {
|
||||||
self.idx = end + 1;
|
self.idx = end + 1;
|
||||||
Some($get_item(self.caps, end as u32).unwrap())
|
Some($get_item(self.caps, end).unwrap())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -738,7 +744,7 @@ macro_rules! define_iter(
|
||||||
None
|
None
|
||||||
} else {
|
} else {
|
||||||
unsafe {
|
unsafe {
|
||||||
Some($get_item(self.caps, self.n_structures as u32 - 1).unwrap())
|
Some($get_item(self.caps, self.n_structures - 1).unwrap())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -754,7 +760,7 @@ macro_rules! define_iter(
|
||||||
self.n_structures -= 1;
|
self.n_structures -= 1;
|
||||||
|
|
||||||
unsafe {
|
unsafe {
|
||||||
Some($get_item(self.caps, self.n_structures as u32).unwrap())
|
Some($get_item(self.caps, self.n_structures).unwrap())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -766,7 +772,7 @@ macro_rules! define_iter(
|
||||||
} else {
|
} else {
|
||||||
self.n_structures = end - 1;
|
self.n_structures = end - 1;
|
||||||
unsafe {
|
unsafe {
|
||||||
Some($get_item(self.caps, self.n_structures as u32).unwrap())
|
Some($get_item(self.caps, self.n_structures).unwrap())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -783,7 +789,7 @@ define_iter!(
|
||||||
&'a CapsRef,
|
&'a CapsRef,
|
||||||
&'a StructureRef,
|
&'a StructureRef,
|
||||||
|caps: &CapsRef, idx| {
|
|caps: &CapsRef, idx| {
|
||||||
let ptr = ffi::gst_caps_get_structure(caps.as_ptr(), idx);
|
let ptr = ffi::gst_caps_get_structure(caps.as_ptr(), idx as u32);
|
||||||
if ptr.is_null() {
|
if ptr.is_null() {
|
||||||
None
|
None
|
||||||
} else {
|
} else {
|
||||||
|
@ -798,7 +804,7 @@ define_iter!(
|
||||||
&'a mut CapsRef,
|
&'a mut CapsRef,
|
||||||
&'a mut StructureRef,
|
&'a mut StructureRef,
|
||||||
|caps: &CapsRef, idx| {
|
|caps: &CapsRef, idx| {
|
||||||
let ptr = ffi::gst_caps_get_structure(caps.as_ptr(), idx);
|
let ptr = ffi::gst_caps_get_structure(caps.as_ptr(), idx as u32);
|
||||||
if ptr.is_null() {
|
if ptr.is_null() {
|
||||||
None
|
None
|
||||||
} else {
|
} else {
|
||||||
|
@ -811,8 +817,8 @@ define_iter!(
|
||||||
&'a CapsRef,
|
&'a CapsRef,
|
||||||
(&'a StructureRef, &'a CapsFeaturesRef),
|
(&'a StructureRef, &'a CapsFeaturesRef),
|
||||||
|caps: &CapsRef, idx| {
|
|caps: &CapsRef, idx| {
|
||||||
let ptr1 = ffi::gst_caps_get_structure(caps.as_ptr(), idx);
|
let ptr1 = ffi::gst_caps_get_structure(caps.as_ptr(), idx as u32);
|
||||||
let ptr2 = ffi::gst_caps_get_features(caps.as_ptr(), idx);
|
let ptr2 = ffi::gst_caps_get_features(caps.as_ptr(), idx as u32);
|
||||||
if ptr1.is_null() || ptr2.is_null() {
|
if ptr1.is_null() || ptr2.is_null() {
|
||||||
None
|
None
|
||||||
} else {
|
} else {
|
||||||
|
@ -828,8 +834,8 @@ define_iter!(
|
||||||
&'a mut CapsRef,
|
&'a mut CapsRef,
|
||||||
(&'a mut StructureRef, &'a mut CapsFeaturesRef),
|
(&'a mut StructureRef, &'a mut CapsFeaturesRef),
|
||||||
|caps: &CapsRef, idx| {
|
|caps: &CapsRef, idx| {
|
||||||
let ptr1 = ffi::gst_caps_get_structure(caps.as_ptr(), idx);
|
let ptr1 = ffi::gst_caps_get_structure(caps.as_ptr(), idx as u32);
|
||||||
let ptr2 = ffi::gst_caps_get_features(caps.as_ptr(), idx);
|
let ptr2 = ffi::gst_caps_get_features(caps.as_ptr(), idx as u32);
|
||||||
if ptr1.is_null() || ptr2.is_null() {
|
if ptr1.is_null() || ptr2.is_null() {
|
||||||
None
|
None
|
||||||
} else {
|
} else {
|
||||||
|
|
|
@ -383,19 +383,19 @@ impl CapsFeaturesRef {
|
||||||
|
|
||||||
#[doc(alias = "get_size")]
|
#[doc(alias = "get_size")]
|
||||||
#[doc(alias = "gst_caps_features_get_size")]
|
#[doc(alias = "gst_caps_features_get_size")]
|
||||||
pub fn size(&self) -> u32 {
|
pub fn size(&self) -> usize {
|
||||||
unsafe { ffi::gst_caps_features_get_size(self.as_ptr()) }
|
unsafe { ffi::gst_caps_features_get_size(self.as_ptr()) as usize }
|
||||||
}
|
}
|
||||||
|
|
||||||
#[doc(alias = "get_nth")]
|
#[doc(alias = "get_nth")]
|
||||||
#[doc(alias = "gst_caps_features_get_nth")]
|
#[doc(alias = "gst_caps_features_get_nth")]
|
||||||
pub fn nth(&self, idx: u32) -> Option<&glib::GStr> {
|
pub fn nth(&self, idx: usize) -> Option<&glib::GStr> {
|
||||||
if idx >= self.size() {
|
if idx >= self.size() {
|
||||||
return None;
|
return None;
|
||||||
}
|
}
|
||||||
|
|
||||||
unsafe {
|
unsafe {
|
||||||
let feature = ffi::gst_caps_features_get_nth(self.as_ptr(), idx);
|
let feature = ffi::gst_caps_features_get_nth(self.as_ptr(), idx as u32);
|
||||||
if feature.is_null() {
|
if feature.is_null() {
|
||||||
return None;
|
return None;
|
||||||
}
|
}
|
||||||
|
@ -405,13 +405,13 @@ impl CapsFeaturesRef {
|
||||||
}
|
}
|
||||||
|
|
||||||
#[doc(alias = "gst_caps_features_get_nth_id")]
|
#[doc(alias = "gst_caps_features_get_nth_id")]
|
||||||
pub fn nth_quark(&self, idx: u32) -> Option<glib::Quark> {
|
pub fn nth_quark(&self, idx: usize) -> Option<glib::Quark> {
|
||||||
if idx >= self.size() {
|
if idx >= self.size() {
|
||||||
return None;
|
return None;
|
||||||
}
|
}
|
||||||
|
|
||||||
unsafe {
|
unsafe {
|
||||||
let feature = ffi::gst_caps_features_get_nth_id(self.as_ptr(), idx);
|
let feature = ffi::gst_caps_features_get_nth_id(self.as_ptr(), idx as u32);
|
||||||
Some(from_glib(feature))
|
Some(from_glib(feature))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -552,7 +552,7 @@ impl<'a> Iter<'a> {
|
||||||
Iter {
|
Iter {
|
||||||
caps_features,
|
caps_features,
|
||||||
idx: 0,
|
idx: 0,
|
||||||
n_features: n_features as usize,
|
n_features,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -658,13 +658,13 @@ impl StructureRef {
|
||||||
|
|
||||||
#[doc(alias = "get_nth_field_name")]
|
#[doc(alias = "get_nth_field_name")]
|
||||||
#[doc(alias = "gst_structure_nth_field_name")]
|
#[doc(alias = "gst_structure_nth_field_name")]
|
||||||
pub fn nth_field_name<'a>(&self, idx: u32) -> Option<&'a glib::GStr> {
|
pub fn nth_field_name<'a>(&self, idx: usize) -> Option<&'a glib::GStr> {
|
||||||
if idx >= self.n_fields() {
|
if idx >= self.n_fields() {
|
||||||
return None;
|
return None;
|
||||||
}
|
}
|
||||||
|
|
||||||
unsafe {
|
unsafe {
|
||||||
let field_name = ffi::gst_structure_nth_field_name(&self.0, idx);
|
let field_name = ffi::gst_structure_nth_field_name(&self.0, idx as u32);
|
||||||
debug_assert!(!field_name.is_null());
|
debug_assert!(!field_name.is_null());
|
||||||
|
|
||||||
Some(glib::GStr::from_ptr(field_name))
|
Some(glib::GStr::from_ptr(field_name))
|
||||||
|
@ -672,8 +672,16 @@ impl StructureRef {
|
||||||
}
|
}
|
||||||
|
|
||||||
#[doc(alias = "gst_structure_n_fields")]
|
#[doc(alias = "gst_structure_n_fields")]
|
||||||
pub fn n_fields(&self) -> u32 {
|
pub fn n_fields(&self) -> usize {
|
||||||
unsafe { ffi::gst_structure_n_fields(&self.0) as u32 }
|
unsafe { ffi::gst_structure_n_fields(&self.0) as usize }
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn len(&self) -> usize {
|
||||||
|
self.n_fields()
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn is_empty(&self) -> bool {
|
||||||
|
self.n_fields() == 0
|
||||||
}
|
}
|
||||||
|
|
||||||
#[doc(alias = "gst_structure_can_intersect")]
|
#[doc(alias = "gst_structure_can_intersect")]
|
||||||
|
@ -1001,7 +1009,7 @@ impl<'a> FieldIterator<'a> {
|
||||||
FieldIterator {
|
FieldIterator {
|
||||||
structure,
|
structure,
|
||||||
idx: 0,
|
idx: 0,
|
||||||
n_fields: n_fields as usize,
|
n_fields,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1014,7 +1022,7 @@ impl<'a> Iterator for FieldIterator<'a> {
|
||||||
return None;
|
return None;
|
||||||
}
|
}
|
||||||
|
|
||||||
let field_name = self.structure.nth_field_name(self.idx as u32).unwrap();
|
let field_name = self.structure.nth_field_name(self.idx).unwrap();
|
||||||
self.idx += 1;
|
self.idx += 1;
|
||||||
|
|
||||||
Some(field_name)
|
Some(field_name)
|
||||||
|
@ -1034,7 +1042,7 @@ impl<'a> DoubleEndedIterator for FieldIterator<'a> {
|
||||||
}
|
}
|
||||||
|
|
||||||
self.n_fields -= 1;
|
self.n_fields -= 1;
|
||||||
Some(self.structure.nth_field_name(self.n_fields as u32).unwrap())
|
Some(self.structure.nth_field_name(self.n_fields).unwrap())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -464,18 +464,18 @@ impl TagListRef {
|
||||||
}
|
}
|
||||||
|
|
||||||
#[doc(alias = "gst_tag_list_n_tags")]
|
#[doc(alias = "gst_tag_list_n_tags")]
|
||||||
pub fn n_tags(&self) -> u32 {
|
pub fn n_tags(&self) -> usize {
|
||||||
unsafe { ffi::gst_tag_list_n_tags(self.as_ptr()) as u32 }
|
unsafe { ffi::gst_tag_list_n_tags(self.as_ptr()) as usize }
|
||||||
}
|
}
|
||||||
|
|
||||||
#[doc(alias = "gst_tag_list_nth_tag_name")]
|
#[doc(alias = "gst_tag_list_nth_tag_name")]
|
||||||
pub fn nth_tag_name(&self, idx: u32) -> Option<&glib::GStr> {
|
pub fn nth_tag_name(&self, idx: usize) -> Option<&glib::GStr> {
|
||||||
if idx >= self.n_tags() {
|
if idx >= self.n_tags() {
|
||||||
return None;
|
return None;
|
||||||
}
|
}
|
||||||
|
|
||||||
unsafe {
|
unsafe {
|
||||||
let name = ffi::gst_tag_list_nth_tag_name(self.as_ptr(), idx);
|
let name = ffi::gst_tag_list_nth_tag_name(self.as_ptr(), idx as u32);
|
||||||
debug_assert!(!name.is_null());
|
debug_assert!(!name.is_null());
|
||||||
Some(glib::GStr::from_ptr(name))
|
Some(glib::GStr::from_ptr(name))
|
||||||
}
|
}
|
||||||
|
@ -483,7 +483,7 @@ impl TagListRef {
|
||||||
|
|
||||||
#[doc(alias = "get_index")]
|
#[doc(alias = "get_index")]
|
||||||
#[doc(alias = "gst_tag_list_get_index")]
|
#[doc(alias = "gst_tag_list_get_index")]
|
||||||
pub fn index<'a, T: Tag<'a>>(&self, idx: u32) -> Option<&'a TagValue<T::TagType>> {
|
pub fn index<'a, T: Tag<'a>>(&self, idx: usize) -> Option<&'a TagValue<T::TagType>> {
|
||||||
self.index_generic(T::TAG_NAME, idx).map(|value| {
|
self.index_generic(T::TAG_NAME, idx).map(|value| {
|
||||||
if !value.is::<T::TagType>() {
|
if !value.is::<T::TagType>() {
|
||||||
panic!(
|
panic!(
|
||||||
|
@ -498,8 +498,9 @@ impl TagListRef {
|
||||||
|
|
||||||
#[doc(alias = "get_index_generic")]
|
#[doc(alias = "get_index_generic")]
|
||||||
#[doc(alias = "gst_tag_list_get_index")]
|
#[doc(alias = "gst_tag_list_get_index")]
|
||||||
pub fn index_generic(&self, tag_name: impl IntoGStr, idx: u32) -> Option<&SendValue> {
|
pub fn index_generic(&self, tag_name: impl IntoGStr, idx: usize) -> Option<&SendValue> {
|
||||||
unsafe {
|
unsafe {
|
||||||
|
let idx = u32::try_from(idx).ok()?;
|
||||||
let value = tag_name.run_with_gstr(|tag_name| {
|
let value = tag_name.run_with_gstr(|tag_name| {
|
||||||
ffi::gst_tag_list_get_value_index(self.as_ptr(), tag_name.as_ptr(), idx)
|
ffi::gst_tag_list_get_value_index(self.as_ptr(), tag_name.as_ptr(), idx)
|
||||||
});
|
});
|
||||||
|
@ -514,16 +515,16 @@ impl TagListRef {
|
||||||
|
|
||||||
#[doc(alias = "get_size")]
|
#[doc(alias = "get_size")]
|
||||||
#[doc(alias = "gst_tag_list_get_tag_size")]
|
#[doc(alias = "gst_tag_list_get_tag_size")]
|
||||||
pub fn size<'a, T: Tag<'a>>(&self) -> u32 {
|
pub fn size<'a, T: Tag<'a>>(&self) -> usize {
|
||||||
self.size_by_name(T::TAG_NAME)
|
self.size_by_name(T::TAG_NAME)
|
||||||
}
|
}
|
||||||
|
|
||||||
#[doc(alias = "get_size_by_name")]
|
#[doc(alias = "get_size_by_name")]
|
||||||
#[doc(alias = "gst_tag_list_get_tag_size")]
|
#[doc(alias = "gst_tag_list_get_tag_size")]
|
||||||
pub fn size_by_name(&self, tag_name: impl IntoGStr) -> u32 {
|
pub fn size_by_name(&self, tag_name: impl IntoGStr) -> usize {
|
||||||
unsafe {
|
unsafe {
|
||||||
tag_name.run_with_gstr(|tag_name| {
|
tag_name.run_with_gstr(|tag_name| {
|
||||||
ffi::gst_tag_list_get_tag_size(self.as_ptr(), tag_name.as_ptr())
|
ffi::gst_tag_list_get_tag_size(self.as_ptr(), tag_name.as_ptr()) as usize
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -648,7 +649,7 @@ impl<'a, T: Tag<'a>> TagIter<'a, T> {
|
||||||
TagIter {
|
TagIter {
|
||||||
taglist,
|
taglist,
|
||||||
idx: 0,
|
idx: 0,
|
||||||
size: taglist.size::<T>() as usize,
|
size: taglist.size::<T>(),
|
||||||
phantom: PhantomData,
|
phantom: PhantomData,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -666,7 +667,7 @@ where
|
||||||
return None;
|
return None;
|
||||||
}
|
}
|
||||||
|
|
||||||
let item = self.taglist.index::<T>(self.idx as u32).unwrap();
|
let item = self.taglist.index::<T>(self.idx).unwrap();
|
||||||
self.idx += 1;
|
self.idx += 1;
|
||||||
|
|
||||||
Some(item)
|
Some(item)
|
||||||
|
@ -689,7 +690,7 @@ where
|
||||||
None
|
None
|
||||||
} else {
|
} else {
|
||||||
self.idx = end + 1;
|
self.idx = end + 1;
|
||||||
Some(self.taglist.index::<T>(end as u32).unwrap())
|
Some(self.taglist.index::<T>(end).unwrap())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -697,7 +698,7 @@ where
|
||||||
if self.idx == self.size {
|
if self.idx == self.size {
|
||||||
None
|
None
|
||||||
} else {
|
} else {
|
||||||
Some(self.taglist.index::<T>(self.size as u32 - 1).unwrap())
|
Some(self.taglist.index::<T>(self.size - 1).unwrap())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -713,7 +714,7 @@ where
|
||||||
}
|
}
|
||||||
|
|
||||||
self.size -= 1;
|
self.size -= 1;
|
||||||
Some(self.taglist.index::<T>(self.size as u32).unwrap())
|
Some(self.taglist.index::<T>(self.size).unwrap())
|
||||||
}
|
}
|
||||||
|
|
||||||
fn nth_back(&mut self, n: usize) -> Option<Self::Item> {
|
fn nth_back(&mut self, n: usize) -> Option<Self::Item> {
|
||||||
|
@ -723,7 +724,7 @@ where
|
||||||
None
|
None
|
||||||
} else {
|
} else {
|
||||||
self.size = end - 1;
|
self.size = end - 1;
|
||||||
Some(self.taglist.index::<T>(self.size as u32).unwrap())
|
Some(self.taglist.index::<T>(self.size).unwrap())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -757,7 +758,7 @@ impl<'a> GenericTagIter<'a> {
|
||||||
taglist,
|
taglist,
|
||||||
name,
|
name,
|
||||||
idx: 0,
|
idx: 0,
|
||||||
size: taglist.size_by_name(name) as usize,
|
size: taglist.size_by_name(name),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -770,10 +771,7 @@ impl<'a> Iterator for GenericTagIter<'a> {
|
||||||
return None;
|
return None;
|
||||||
}
|
}
|
||||||
|
|
||||||
let item = self
|
let item = self.taglist.index_generic(self.name, self.idx).unwrap();
|
||||||
.taglist
|
|
||||||
.index_generic(self.name, self.idx as u32)
|
|
||||||
.unwrap();
|
|
||||||
self.idx += 1;
|
self.idx += 1;
|
||||||
|
|
||||||
Some(item)
|
Some(item)
|
||||||
|
@ -796,7 +794,7 @@ impl<'a> Iterator for GenericTagIter<'a> {
|
||||||
None
|
None
|
||||||
} else {
|
} else {
|
||||||
self.idx = end + 1;
|
self.idx = end + 1;
|
||||||
Some(self.taglist.index_generic(self.name, end as u32).unwrap())
|
Some(self.taglist.index_generic(self.name, end).unwrap())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -806,7 +804,7 @@ impl<'a> Iterator for GenericTagIter<'a> {
|
||||||
} else {
|
} else {
|
||||||
Some(
|
Some(
|
||||||
self.taglist
|
self.taglist
|
||||||
.index_generic(self.name, self.size as u32 - 1)
|
.index_generic(self.name, self.size - 1)
|
||||||
.unwrap(),
|
.unwrap(),
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
@ -820,11 +818,7 @@ impl<'a> DoubleEndedIterator for GenericTagIter<'a> {
|
||||||
}
|
}
|
||||||
|
|
||||||
self.size -= 1;
|
self.size -= 1;
|
||||||
Some(
|
Some(self.taglist.index_generic(self.name, self.size).unwrap())
|
||||||
self.taglist
|
|
||||||
.index_generic(self.name, self.size as u32)
|
|
||||||
.unwrap(),
|
|
||||||
)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fn nth_back(&mut self, n: usize) -> Option<Self::Item> {
|
fn nth_back(&mut self, n: usize) -> Option<Self::Item> {
|
||||||
|
@ -834,11 +828,7 @@ impl<'a> DoubleEndedIterator for GenericTagIter<'a> {
|
||||||
None
|
None
|
||||||
} else {
|
} else {
|
||||||
self.size = end - 1;
|
self.size = end - 1;
|
||||||
Some(
|
Some(self.taglist.index_generic(self.name, self.size).unwrap())
|
||||||
self.taglist
|
|
||||||
.index_generic(self.name, self.size as u32)
|
|
||||||
.unwrap(),
|
|
||||||
)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -861,7 +851,7 @@ impl<'a> GenericIter<'a> {
|
||||||
GenericIter {
|
GenericIter {
|
||||||
taglist,
|
taglist,
|
||||||
idx: 0,
|
idx: 0,
|
||||||
size: if size > 0 { size as usize } else { 0 },
|
size: if size > 0 { size } else { 0 },
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -874,7 +864,7 @@ impl<'a> Iterator for GenericIter<'a> {
|
||||||
return None;
|
return None;
|
||||||
}
|
}
|
||||||
|
|
||||||
let name = self.taglist.nth_tag_name(self.idx as u32).unwrap();
|
let name = self.taglist.nth_tag_name(self.idx).unwrap();
|
||||||
let item = (name, self.taglist.iter_tag_generic(name));
|
let item = (name, self.taglist.iter_tag_generic(name));
|
||||||
self.idx += 1;
|
self.idx += 1;
|
||||||
|
|
||||||
|
@ -898,7 +888,7 @@ impl<'a> Iterator for GenericIter<'a> {
|
||||||
None
|
None
|
||||||
} else {
|
} else {
|
||||||
self.idx = end + 1;
|
self.idx = end + 1;
|
||||||
let name = self.taglist.nth_tag_name(end as u32).unwrap();
|
let name = self.taglist.nth_tag_name(end).unwrap();
|
||||||
Some((name, self.taglist.iter_tag_generic(name)))
|
Some((name, self.taglist.iter_tag_generic(name)))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -907,7 +897,7 @@ impl<'a> Iterator for GenericIter<'a> {
|
||||||
if self.idx == self.size {
|
if self.idx == self.size {
|
||||||
None
|
None
|
||||||
} else {
|
} else {
|
||||||
let name = self.taglist.nth_tag_name(self.size as u32 - 1).unwrap();
|
let name = self.taglist.nth_tag_name(self.size - 1).unwrap();
|
||||||
Some((name, self.taglist.iter_tag_generic(name)))
|
Some((name, self.taglist.iter_tag_generic(name)))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -920,7 +910,7 @@ impl<'a> DoubleEndedIterator for GenericIter<'a> {
|
||||||
}
|
}
|
||||||
|
|
||||||
self.size -= 1;
|
self.size -= 1;
|
||||||
let name = self.taglist.nth_tag_name(self.idx as u32).unwrap();
|
let name = self.taglist.nth_tag_name(self.idx).unwrap();
|
||||||
Some((name, self.taglist.iter_tag_generic(name)))
|
Some((name, self.taglist.iter_tag_generic(name)))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -931,7 +921,7 @@ impl<'a> DoubleEndedIterator for GenericIter<'a> {
|
||||||
None
|
None
|
||||||
} else {
|
} else {
|
||||||
self.size = end - 1;
|
self.size = end - 1;
|
||||||
let name = self.taglist.nth_tag_name(self.size as u32).unwrap();
|
let name = self.taglist.nth_tag_name(self.size).unwrap();
|
||||||
Some((name, self.taglist.iter_tag_generic(name)))
|
Some((name, self.taglist.iter_tag_generic(name)))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -955,7 +945,7 @@ impl<'a> Iter<'a> {
|
||||||
Iter {
|
Iter {
|
||||||
taglist,
|
taglist,
|
||||||
idx: 0,
|
idx: 0,
|
||||||
size: if size > 0 { size as usize } else { 0 },
|
size: if size > 0 { size } else { 0 },
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -968,7 +958,7 @@ impl<'a> Iterator for Iter<'a> {
|
||||||
return None;
|
return None;
|
||||||
}
|
}
|
||||||
|
|
||||||
let name = self.taglist.nth_tag_name(self.idx as u32).unwrap();
|
let name = self.taglist.nth_tag_name(self.idx).unwrap();
|
||||||
let item = (name, self.taglist.generic(name).unwrap());
|
let item = (name, self.taglist.generic(name).unwrap());
|
||||||
self.idx += 1;
|
self.idx += 1;
|
||||||
|
|
||||||
|
@ -992,7 +982,7 @@ impl<'a> Iterator for Iter<'a> {
|
||||||
None
|
None
|
||||||
} else {
|
} else {
|
||||||
self.idx = end + 1;
|
self.idx = end + 1;
|
||||||
let name = self.taglist.nth_tag_name(end as u32).unwrap();
|
let name = self.taglist.nth_tag_name(end).unwrap();
|
||||||
Some((name, self.taglist.generic(name).unwrap()))
|
Some((name, self.taglist.generic(name).unwrap()))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1001,7 +991,7 @@ impl<'a> Iterator for Iter<'a> {
|
||||||
if self.idx == self.size {
|
if self.idx == self.size {
|
||||||
None
|
None
|
||||||
} else {
|
} else {
|
||||||
let name = self.taglist.nth_tag_name(self.size as u32 - 1).unwrap();
|
let name = self.taglist.nth_tag_name(self.size - 1).unwrap();
|
||||||
Some((name, self.taglist.generic(name).unwrap()))
|
Some((name, self.taglist.generic(name).unwrap()))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1014,7 +1004,7 @@ impl<'a> DoubleEndedIterator for Iter<'a> {
|
||||||
}
|
}
|
||||||
|
|
||||||
self.size -= 1;
|
self.size -= 1;
|
||||||
let name = self.taglist.nth_tag_name(self.idx as u32).unwrap();
|
let name = self.taglist.nth_tag_name(self.idx).unwrap();
|
||||||
Some((name, self.taglist.generic(name).unwrap()))
|
Some((name, self.taglist.generic(name).unwrap()))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1025,7 +1015,7 @@ impl<'a> DoubleEndedIterator for Iter<'a> {
|
||||||
None
|
None
|
||||||
} else {
|
} else {
|
||||||
self.size = end - 1;
|
self.size = end - 1;
|
||||||
let name = self.taglist.nth_tag_name(self.size as u32).unwrap();
|
let name = self.taglist.nth_tag_name(self.size).unwrap();
|
||||||
Some((name, self.taglist.generic(name).unwrap()))
|
Some((name, self.taglist.generic(name).unwrap()))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -117,7 +117,7 @@ impl<'a> Serialize for TagListSer<'a> {
|
||||||
let tag_count = self.0.n_tags();
|
let tag_count = self.0.n_tags();
|
||||||
match tag_count.cmp(&0) {
|
match tag_count.cmp(&0) {
|
||||||
cmp::Ordering::Greater => {
|
cmp::Ordering::Greater => {
|
||||||
let mut seq = serializer.serialize_seq(Some(tag_count as usize))?;
|
let mut seq = serializer.serialize_seq(Some(tag_count))?;
|
||||||
let tag_list_iter = self.0.iter_generic();
|
let tag_list_iter = self.0.iter_generic();
|
||||||
for (tag_name, tag_iter) in tag_list_iter {
|
for (tag_name, tag_iter) in tag_list_iter {
|
||||||
seq.serialize_element(&TagsSer::new(tag_name, tag_iter))?;
|
seq.serialize_element(&TagsSer::new(tag_name, tag_iter))?;
|
||||||
|
|
Loading…
Reference in a new issue