forked from mirrors/gstreamer-rs
Add initial BufferPool bindings
This commit is contained in:
parent
9448f1cc3e
commit
de8f4694f5
6 changed files with 486 additions and 0 deletions
34
Gir_Gst.toml
34
Gir_Gst.toml
|
@ -70,6 +70,7 @@ generate = [
|
|||
"Gst.PluginDependencyFlags",
|
||||
"Gst.DateTime",
|
||||
"Gst.TypeFindProbability",
|
||||
"Gst.BufferPoolAcquireFlags",
|
||||
]
|
||||
|
||||
manual = [
|
||||
|
@ -767,6 +768,39 @@ trait = false
|
|||
[object.function.return]
|
||||
bool_return_is_error = "Failed to add plugin"
|
||||
|
||||
[[object]]
|
||||
name = "Gst.BufferPool"
|
||||
status = "generate"
|
||||
[[object.function]]
|
||||
pattern = "config_.*"
|
||||
# A different type
|
||||
ignore = true
|
||||
|
||||
[[object.function]]
|
||||
name = "get_config"
|
||||
# A different type
|
||||
ignore = true
|
||||
|
||||
[[object.function]]
|
||||
name = "set_config"
|
||||
# Takes ownership
|
||||
ignore = true
|
||||
|
||||
[[object.function]]
|
||||
name = "acquire_buffer"
|
||||
# Params and return value
|
||||
ignore = true
|
||||
|
||||
[[object.function]]
|
||||
name = "release_buffer"
|
||||
# Takes ownership
|
||||
ignore = true
|
||||
|
||||
[[object.function]]
|
||||
name = "set_active"
|
||||
[object.function.return]
|
||||
bool_return_is_error = "Failed to activate buffer pool"
|
||||
|
||||
[[object]]
|
||||
name = "Gst.Preset"
|
||||
status = "generate"
|
||||
|
|
83
gstreamer/src/auto/buffer_pool.rs
Normal file
83
gstreamer/src/auto/buffer_pool.rs
Normal file
|
@ -0,0 +1,83 @@
|
|||
// This file was generated by gir (https://github.com/gtk-rs/gir @ fbb95f4)
|
||||
// from gir-files (https://github.com/gtk-rs/gir-files @ ???)
|
||||
// DO NOT EDIT
|
||||
|
||||
use Object;
|
||||
use ffi;
|
||||
use glib;
|
||||
use glib::object::IsA;
|
||||
use glib::translate::*;
|
||||
use glib_ffi;
|
||||
use gobject_ffi;
|
||||
use std::mem;
|
||||
use std::ptr;
|
||||
|
||||
glib_wrapper! {
|
||||
pub struct BufferPool(Object<ffi::GstBufferPool, ffi::GstBufferPoolClass>): Object;
|
||||
|
||||
match fn {
|
||||
get_type => || ffi::gst_buffer_pool_get_type(),
|
||||
}
|
||||
}
|
||||
|
||||
impl BufferPool {
|
||||
pub fn new() -> BufferPool {
|
||||
assert_initialized_main_thread!();
|
||||
unsafe {
|
||||
from_glib_full(ffi::gst_buffer_pool_new())
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl Default for BufferPool {
|
||||
fn default() -> Self {
|
||||
Self::new()
|
||||
}
|
||||
}
|
||||
|
||||
unsafe impl Send for BufferPool {}
|
||||
unsafe impl Sync for BufferPool {}
|
||||
|
||||
pub trait BufferPoolExt {
|
||||
fn get_options(&self) -> Vec<String>;
|
||||
|
||||
fn has_option(&self, option: &str) -> bool;
|
||||
|
||||
fn is_active(&self) -> bool;
|
||||
|
||||
fn set_active(&self, active: bool) -> Result<(), glib::error::BoolError>;
|
||||
|
||||
fn set_flushing(&self, flushing: bool);
|
||||
}
|
||||
|
||||
impl<O: IsA<BufferPool>> BufferPoolExt for O {
|
||||
fn get_options(&self) -> Vec<String> {
|
||||
unsafe {
|
||||
FromGlibPtrContainer::from_glib_none(ffi::gst_buffer_pool_get_options(self.to_glib_none().0))
|
||||
}
|
||||
}
|
||||
|
||||
fn has_option(&self, option: &str) -> bool {
|
||||
unsafe {
|
||||
from_glib(ffi::gst_buffer_pool_has_option(self.to_glib_none().0, option.to_glib_none().0))
|
||||
}
|
||||
}
|
||||
|
||||
fn is_active(&self) -> bool {
|
||||
unsafe {
|
||||
from_glib(ffi::gst_buffer_pool_is_active(self.to_glib_none().0))
|
||||
}
|
||||
}
|
||||
|
||||
fn set_active(&self, active: bool) -> Result<(), glib::error::BoolError> {
|
||||
unsafe {
|
||||
glib::error::BoolError::from_glib(ffi::gst_buffer_pool_set_active(self.to_glib_none().0, active.to_glib()), "Failed to activate buffer pool")
|
||||
}
|
||||
}
|
||||
|
||||
fn set_flushing(&self, flushing: bool) {
|
||||
unsafe {
|
||||
ffi::gst_buffer_pool_set_flushing(self.to_glib_none().0, flushing.to_glib());
|
||||
}
|
||||
}
|
||||
}
|
|
@ -124,6 +124,57 @@ impl SetValue for BufferFlags {
|
|||
}
|
||||
}
|
||||
|
||||
bitflags! {
|
||||
pub struct BufferPoolAcquireFlags: u32 {
|
||||
const NONE = 0;
|
||||
const KEY_UNIT = 1;
|
||||
const DONTWAIT = 2;
|
||||
const DISCONT = 4;
|
||||
const LAST = 65536;
|
||||
}
|
||||
}
|
||||
|
||||
#[doc(hidden)]
|
||||
impl ToGlib for BufferPoolAcquireFlags {
|
||||
type GlibType = ffi::GstBufferPoolAcquireFlags;
|
||||
|
||||
fn to_glib(&self) -> ffi::GstBufferPoolAcquireFlags {
|
||||
ffi::GstBufferPoolAcquireFlags::from_bits_truncate(self.bits())
|
||||
}
|
||||
}
|
||||
|
||||
#[doc(hidden)]
|
||||
impl FromGlib<ffi::GstBufferPoolAcquireFlags> for BufferPoolAcquireFlags {
|
||||
fn from_glib(value: ffi::GstBufferPoolAcquireFlags) -> BufferPoolAcquireFlags {
|
||||
skip_assert_initialized!();
|
||||
BufferPoolAcquireFlags::from_bits_truncate(value.bits())
|
||||
}
|
||||
}
|
||||
|
||||
impl StaticType for BufferPoolAcquireFlags {
|
||||
fn static_type() -> Type {
|
||||
unsafe { from_glib(ffi::gst_buffer_pool_acquire_flags_get_type()) }
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a> FromValueOptional<'a> for BufferPoolAcquireFlags {
|
||||
unsafe fn from_value_optional(value: &Value) -> Option<Self> {
|
||||
Some(FromValue::from_value(value))
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a> FromValue<'a> for BufferPoolAcquireFlags {
|
||||
unsafe fn from_value(value: &Value) -> Self {
|
||||
from_glib(ffi::GstBufferPoolAcquireFlags::from_bits_truncate(gobject_ffi::g_value_get_flags(value.to_glib_none().0)))
|
||||
}
|
||||
}
|
||||
|
||||
impl SetValue for BufferPoolAcquireFlags {
|
||||
unsafe fn set_value(value: &mut Value, this: &Self) {
|
||||
gobject_ffi::g_value_set_flags(value.to_glib_none_mut().0, this.to_glib().bits())
|
||||
}
|
||||
}
|
||||
|
||||
bitflags! {
|
||||
pub struct DebugColorFlags: u32 {
|
||||
const FG_BLACK = 0;
|
||||
|
|
|
@ -6,6 +6,10 @@ mod bin;
|
|||
pub use self::bin::Bin;
|
||||
pub use self::bin::BinExt;
|
||||
|
||||
mod buffer_pool;
|
||||
pub use self::buffer_pool::BufferPool;
|
||||
pub use self::buffer_pool::BufferPoolExt;
|
||||
|
||||
mod bus;
|
||||
pub use self::bus::Bus;
|
||||
|
||||
|
@ -150,6 +154,7 @@ pub use self::enums::URIType;
|
|||
mod flags;
|
||||
pub use self::flags::BufferCopyFlags;
|
||||
pub use self::flags::BufferFlags;
|
||||
pub use self::flags::BufferPoolAcquireFlags;
|
||||
pub use self::flags::DebugColorFlags;
|
||||
pub use self::flags::DebugGraphDetails;
|
||||
pub use self::flags::ElementFlags;
|
||||
|
@ -175,6 +180,7 @@ pub mod functions;
|
|||
#[doc(hidden)]
|
||||
pub mod traits {
|
||||
pub use super::BinExt;
|
||||
pub use super::BufferPoolExt;
|
||||
pub use super::ChildProxyExt;
|
||||
pub use super::ClockExt;
|
||||
pub use super::DeviceExt;
|
||||
|
|
308
gstreamer/src/buffer_pool.rs
Normal file
308
gstreamer/src/buffer_pool.rs
Normal file
|
@ -0,0 +1,308 @@
|
|||
// Copyright (C) 2018 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 BufferPool;
|
||||
use Structure;
|
||||
|
||||
use glib;
|
||||
use glib::IsA;
|
||||
use glib::translate::{from_glib, from_glib_full, from_glib_none, ToGlib, ToGlibPtr, ToGlibPtrMut};
|
||||
|
||||
use ffi;
|
||||
|
||||
use std::mem;
|
||||
use std::ptr;
|
||||
use std::ops;
|
||||
|
||||
#[derive(Debug, PartialEq, Eq)]
|
||||
pub struct BufferPoolConfig(Structure);
|
||||
|
||||
impl ops::Deref for BufferPoolConfig {
|
||||
type Target = ::StructureRef;
|
||||
|
||||
fn deref(&self) -> &::StructureRef {
|
||||
self.0.deref()
|
||||
}
|
||||
}
|
||||
|
||||
impl ops::DerefMut for BufferPoolConfig {
|
||||
fn deref_mut(&mut self) -> &mut ::StructureRef {
|
||||
self.0.deref_mut()
|
||||
}
|
||||
}
|
||||
|
||||
impl AsRef<::StructureRef> for BufferPoolConfig {
|
||||
fn as_ref(&self) -> &::StructureRef {
|
||||
self.0.as_ref()
|
||||
}
|
||||
}
|
||||
|
||||
impl AsMut<::StructureRef> for BufferPoolConfig {
|
||||
fn as_mut(&mut self) -> &mut ::StructureRef {
|
||||
self.0.as_mut()
|
||||
}
|
||||
}
|
||||
|
||||
impl BufferPoolConfig {
|
||||
pub fn add_option(&mut self, option: &str) {
|
||||
unsafe {
|
||||
ffi::gst_buffer_pool_config_add_option(
|
||||
self.0.to_glib_none_mut().0,
|
||||
option.to_glib_none().0,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
pub fn has_option(&self, option: &str) -> bool {
|
||||
unsafe {
|
||||
from_glib(ffi::gst_buffer_pool_config_has_option(
|
||||
self.0.to_glib_none().0,
|
||||
option.to_glib_none().0,
|
||||
))
|
||||
}
|
||||
}
|
||||
|
||||
pub fn get_options(&self) -> Vec<String> {
|
||||
unsafe {
|
||||
let n = ffi::gst_buffer_pool_config_n_options(self.0.to_glib_none().0) as usize;
|
||||
let mut options = Vec::with_capacity(n);
|
||||
|
||||
for i in 0..n {
|
||||
options.push(from_glib_none(ffi::gst_buffer_pool_config_get_option(
|
||||
self.0.to_glib_none().0,
|
||||
i as u32,
|
||||
)));
|
||||
}
|
||||
|
||||
options
|
||||
}
|
||||
}
|
||||
|
||||
pub fn set_params<'a, T: Into<Option<&'a ::Caps>>>(
|
||||
&mut self,
|
||||
caps: T,
|
||||
size: u32,
|
||||
min_buffers: u32,
|
||||
max_buffers: u32,
|
||||
) {
|
||||
let caps = caps.into();
|
||||
|
||||
unsafe {
|
||||
ffi::gst_buffer_pool_config_set_params(
|
||||
self.0.to_glib_none_mut().0,
|
||||
caps.to_glib_none().0,
|
||||
size,
|
||||
min_buffers,
|
||||
max_buffers,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
pub fn get_params(&self) -> Option<(Option<::Caps>, u32, u32, u32)> {
|
||||
unsafe {
|
||||
let mut caps = ptr::null_mut();
|
||||
let mut size = mem::uninitialized();
|
||||
let mut min_buffers = mem::uninitialized();
|
||||
let mut max_buffers = mem::uninitialized();
|
||||
|
||||
let ret: bool = from_glib(ffi::gst_buffer_pool_config_get_params(
|
||||
self.0.to_glib_none().0,
|
||||
&mut caps,
|
||||
&mut size,
|
||||
&mut min_buffers,
|
||||
&mut max_buffers,
|
||||
));
|
||||
if !ret {
|
||||
return None;
|
||||
}
|
||||
|
||||
Some((from_glib_none(caps), size, min_buffers, max_buffers))
|
||||
}
|
||||
}
|
||||
|
||||
pub fn validate_params<'a, T: Into<Option<&'a ::Caps>>>(
|
||||
&self,
|
||||
caps: T,
|
||||
size: u32,
|
||||
min_buffers: u32,
|
||||
max_buffers: u32,
|
||||
) -> bool {
|
||||
let caps = caps.into();
|
||||
|
||||
unsafe {
|
||||
from_glib(ffi::gst_buffer_pool_config_validate_params(
|
||||
self.0.to_glib_none().0,
|
||||
caps.to_glib_none().0,
|
||||
size,
|
||||
min_buffers,
|
||||
max_buffers,
|
||||
))
|
||||
}
|
||||
}
|
||||
|
||||
// TODO: get_allocator / set_allocator
|
||||
// TODO: options iterator
|
||||
}
|
||||
|
||||
#[derive(Debug)]
|
||||
pub struct BufferPoolAcquireParams(ffi::GstBufferPoolAcquireParams);
|
||||
|
||||
impl BufferPoolAcquireParams {
|
||||
pub fn with_flags(flags: ::BufferPoolAcquireFlags) -> Self {
|
||||
BufferPoolAcquireParams(ffi::GstBufferPoolAcquireParams {
|
||||
format: ffi::GST_FORMAT_UNDEFINED,
|
||||
start: -1,
|
||||
stop: -1,
|
||||
flags: flags.to_glib(),
|
||||
_gst_reserved: [ptr::null_mut(); 4],
|
||||
})
|
||||
}
|
||||
|
||||
pub fn with_start_stop<T: ::SpecificFormattedValue>(
|
||||
start: T,
|
||||
stop: T,
|
||||
flags: ::BufferPoolAcquireFlags,
|
||||
) -> Self {
|
||||
unsafe {
|
||||
BufferPoolAcquireParams(ffi::GstBufferPoolAcquireParams {
|
||||
format: start.get_format().to_glib(),
|
||||
start: start.to_raw_value(),
|
||||
stop: stop.to_raw_value(),
|
||||
flags: flags.to_glib(),
|
||||
_gst_reserved: [ptr::null_mut(); 4],
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
pub fn flags(&self) -> ::BufferPoolAcquireFlags {
|
||||
from_glib(self.0.flags)
|
||||
}
|
||||
|
||||
pub fn format(&self) -> ::Format {
|
||||
from_glib(self.0.format)
|
||||
}
|
||||
|
||||
pub fn start(&self) -> ::GenericFormattedValue {
|
||||
::GenericFormattedValue::new(from_glib(self.0.format), self.0.start)
|
||||
}
|
||||
|
||||
pub fn stop(&self) -> ::GenericFormattedValue {
|
||||
::GenericFormattedValue::new(from_glib(self.0.format), self.0.stop)
|
||||
}
|
||||
}
|
||||
|
||||
impl PartialEq for BufferPoolAcquireParams {
|
||||
fn eq(&self, other: &Self) -> bool {
|
||||
self.format() == other.format() && self.start() == other.start()
|
||||
&& self.stop() == other.stop()
|
||||
}
|
||||
}
|
||||
|
||||
impl Eq for BufferPoolAcquireParams {}
|
||||
|
||||
pub trait BufferPoolExtManual {
|
||||
fn get_config(&self) -> BufferPoolConfig;
|
||||
fn set_config(&self, config: BufferPoolConfig) -> Result<(), glib::error::BoolError>;
|
||||
|
||||
fn is_flushing(&self) -> bool;
|
||||
|
||||
fn acquire_buffer<'a, P: Into<Option<&'a BufferPoolAcquireParams>>>(
|
||||
&self,
|
||||
params: P,
|
||||
) -> Result<::Buffer, ::FlowReturn>;
|
||||
fn release_buffer(&self, buffer: ::Buffer);
|
||||
}
|
||||
|
||||
impl<O: IsA<BufferPool>> BufferPoolExtManual for O {
|
||||
fn get_config(&self) -> BufferPoolConfig {
|
||||
unsafe {
|
||||
let ptr = ffi::gst_buffer_pool_get_config(self.to_glib_none().0);
|
||||
BufferPoolConfig(from_glib_full(ptr))
|
||||
}
|
||||
}
|
||||
|
||||
fn set_config(&self, config: BufferPoolConfig) -> Result<(), glib::error::BoolError> {
|
||||
unsafe {
|
||||
glib::error::BoolError::from_glib(
|
||||
ffi::gst_buffer_pool_set_config(self.to_glib_none().0, config.0.into_ptr()),
|
||||
"Failed to set config",
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
fn is_flushing(&self) -> bool {
|
||||
unsafe {
|
||||
let stash = self.to_glib_none();
|
||||
let ptr: *mut ffi::GstBufferPool = stash.0;
|
||||
|
||||
from_glib((*ptr).flushing)
|
||||
}
|
||||
}
|
||||
|
||||
fn acquire_buffer<'a, P: Into<Option<&'a BufferPoolAcquireParams>>>(
|
||||
&self,
|
||||
params: P,
|
||||
) -> Result<::Buffer, ::FlowReturn> {
|
||||
let params = params.into();
|
||||
let params_ptr = match params {
|
||||
Some(params) => ¶ms.0 as *const _ as *mut _,
|
||||
None => ptr::null_mut(),
|
||||
};
|
||||
|
||||
unsafe {
|
||||
let mut buffer = ptr::null_mut();
|
||||
let ret = from_glib(ffi::gst_buffer_pool_acquire_buffer(
|
||||
self.to_glib_none().0,
|
||||
&mut buffer,
|
||||
params_ptr,
|
||||
));
|
||||
|
||||
if ret == ::FlowReturn::Ok {
|
||||
Ok(from_glib_full(buffer))
|
||||
} else {
|
||||
Err(ret)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fn release_buffer(&self, buffer: ::Buffer) {
|
||||
unsafe {
|
||||
ffi::gst_buffer_pool_release_buffer(self.to_glib_none().0, buffer.into_ptr());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
use prelude::*;
|
||||
|
||||
#[test]
|
||||
fn test_pool() {
|
||||
::init().unwrap();
|
||||
|
||||
let pool = ::BufferPool::new();
|
||||
let mut config = pool.get_config();
|
||||
config.set_params(Some(&::Caps::new_simple("foo/bar", &[])), 1024, 0, 2);
|
||||
pool.set_config(config).unwrap();
|
||||
|
||||
pool.set_active(true).unwrap();
|
||||
|
||||
let params = ::BufferPoolAcquireParams::with_flags(::BufferPoolAcquireFlags::DONTWAIT);
|
||||
|
||||
let _buf1 = pool.acquire_buffer(¶ms).unwrap();
|
||||
let buf2 = pool.acquire_buffer(¶ms).unwrap();
|
||||
|
||||
assert!(pool.acquire_buffer(¶ms).is_err());
|
||||
|
||||
drop(buf2);
|
||||
let _buf2 = pool.acquire_buffer(¶ms).unwrap();
|
||||
|
||||
pool.set_active(false).unwrap();
|
||||
}
|
||||
}
|
|
@ -150,6 +150,9 @@ pub use toc::{Toc, TocEntry, TocEntryRef, TocRef};
|
|||
mod clock;
|
||||
pub use clock::{ClockExtManual, ClockId};
|
||||
|
||||
mod buffer_pool;
|
||||
pub use buffer_pool::*;
|
||||
|
||||
pub mod functions;
|
||||
pub use functions::*;
|
||||
|
||||
|
@ -203,6 +206,7 @@ pub mod prelude {
|
|||
pub use device_provider::DeviceProviderExtManual;
|
||||
pub use clock::ClockExtManual;
|
||||
pub use value::GstValueExt;
|
||||
pub use buffer_pool::BufferPoolExtManual;
|
||||
|
||||
pub use tags::Tag;
|
||||
pub use miniobject::MiniObject;
|
||||
|
|
Loading…
Reference in a new issue