2017-07-28 17:20:11 +00:00
|
|
|
// Copyright (C) 2017 Sebastian Dröge <sebastian@centricular.com>
|
|
|
|
//
|
|
|
|
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
|
|
|
|
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
|
|
|
|
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
|
|
|
|
// option. This file may not be copied, modified, or distributed
|
|
|
|
// except according to those terms.
|
|
|
|
|
|
|
|
use ffi;
|
|
|
|
use glib;
|
|
|
|
use glib::StaticType;
|
2017-07-31 11:16:42 +00:00
|
|
|
use glib::translate::{from_glib, from_glib_full, from_glib_none};
|
2017-07-28 17:20:11 +00:00
|
|
|
|
|
|
|
use miniobject::*;
|
|
|
|
use Buffer;
|
|
|
|
use BufferRef;
|
|
|
|
|
|
|
|
pub type BufferList = GstRc<BufferListRef>;
|
|
|
|
pub struct BufferListRef(ffi::GstBufferList);
|
|
|
|
|
|
|
|
unsafe impl MiniObject for BufferListRef {
|
|
|
|
type GstType = ffi::GstBufferList;
|
|
|
|
}
|
|
|
|
|
|
|
|
impl GstRc<BufferListRef> {
|
|
|
|
pub fn new() -> Self {
|
|
|
|
assert_initialized_main_thread!();
|
|
|
|
unsafe { from_glib_full(ffi::gst_buffer_list_new()) }
|
|
|
|
}
|
|
|
|
|
|
|
|
pub fn new_sized(size: usize) -> Self {
|
|
|
|
assert_initialized_main_thread!();
|
|
|
|
unsafe { from_glib_full(ffi::gst_buffer_list_new_sized(size as u32)) }
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
impl BufferListRef {
|
|
|
|
pub fn insert(&mut self, idx: i32, buffer: Buffer) {
|
|
|
|
unsafe {
|
|
|
|
ffi::gst_buffer_list_insert(self.as_mut_ptr(), idx, buffer.into_ptr());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
pub fn add(&mut self, buffer: Buffer) {
|
|
|
|
self.insert(-1, buffer);
|
|
|
|
}
|
|
|
|
|
|
|
|
pub fn copy_deep(&self) -> BufferList {
|
2017-07-31 11:16:42 +00:00
|
|
|
unsafe { from_glib_full(ffi::gst_buffer_list_copy_deep(self.as_ptr())) }
|
2017-07-28 17:20:11 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
pub fn remove(&mut self, idx: u32, len: u32) {
|
2017-07-31 11:16:42 +00:00
|
|
|
unsafe { ffi::gst_buffer_list_remove(self.as_mut_ptr(), idx, len) }
|
2017-07-28 17:20:11 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
pub fn get(&self, idx: u32) -> Option<&BufferRef> {
|
|
|
|
unsafe {
|
|
|
|
let ptr = ffi::gst_buffer_list_get(self.as_mut_ptr(), idx);
|
|
|
|
if ptr.is_null() {
|
|
|
|
None
|
|
|
|
} else {
|
|
|
|
Some(BufferRef::from_ptr(ptr))
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
pub fn len(&self) -> usize {
|
2017-07-31 11:16:42 +00:00
|
|
|
unsafe { ffi::gst_buffer_list_length(self.as_mut_ptr()) as usize }
|
2017-07-28 17:20:11 +00:00
|
|
|
}
|
|
|
|
|
2017-08-02 16:40:31 +00:00
|
|
|
pub fn iter(&self) -> Iter {
|
2017-07-28 17:20:11 +00:00
|
|
|
Iter::new(self)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
impl ToOwned for BufferListRef {
|
|
|
|
type Owned = GstRc<BufferListRef>;
|
|
|
|
|
|
|
|
fn to_owned(&self) -> GstRc<BufferListRef> {
|
|
|
|
unsafe { from_glib_none(self.as_ptr()) }
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
impl StaticType for BufferListRef {
|
|
|
|
fn static_type() -> glib::Type {
|
2017-07-31 11:16:42 +00:00
|
|
|
unsafe { from_glib(ffi::gst_buffer_list_get_type()) }
|
2017-07-28 17:20:11 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
unsafe impl Sync for BufferListRef {}
|
|
|
|
unsafe impl Send for BufferListRef {}
|
|
|
|
|
|
|
|
pub struct Iter<'a> {
|
|
|
|
list: &'a BufferListRef,
|
|
|
|
idx: u32,
|
|
|
|
size: u32,
|
|
|
|
}
|
|
|
|
|
|
|
|
impl<'a> Iter<'a> {
|
|
|
|
fn new(list: &'a BufferListRef) -> Iter<'a> {
|
|
|
|
Iter {
|
|
|
|
list: list,
|
|
|
|
idx: 0,
|
|
|
|
size: list.len() as u32,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-07-31 11:16:42 +00:00
|
|
|
impl<'a> Iterator for Iter<'a> {
|
2017-07-28 17:20:11 +00:00
|
|
|
type Item = &'a BufferRef;
|
|
|
|
|
|
|
|
fn next(&mut self) -> Option<Self::Item> {
|
|
|
|
if self.idx >= self.size {
|
|
|
|
return None;
|
|
|
|
}
|
|
|
|
|
|
|
|
let item = self.list.get(self.idx);
|
|
|
|
self.idx += 1;
|
|
|
|
|
|
|
|
item
|
|
|
|
}
|
|
|
|
|
|
|
|
fn size_hint(&self) -> (usize, Option<usize>) {
|
|
|
|
if self.idx == self.size {
|
|
|
|
return (0, Some(0));
|
|
|
|
}
|
|
|
|
|
|
|
|
let remaining = (self.size - self.idx) as usize;
|
|
|
|
|
|
|
|
(remaining, Some(remaining))
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-07-31 11:16:42 +00:00
|
|
|
impl<'a> DoubleEndedIterator for Iter<'a> {
|
2017-07-28 17:20:11 +00:00
|
|
|
fn next_back(&mut self) -> Option<Self::Item> {
|
|
|
|
if self.idx == self.size {
|
|
|
|
return None;
|
|
|
|
}
|
|
|
|
|
|
|
|
self.size -= 1;
|
|
|
|
self.list.get(self.size)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-07-31 11:16:42 +00:00
|
|
|
impl<'a> ExactSizeIterator for Iter<'a> {}
|