mirror of
https://gitlab.freedesktop.org/gstreamer/gstreamer-rs.git
synced 2024-12-23 16:40:35 +00:00
allocator: Expose GstAllocator
This commit is contained in:
parent
922af1d606
commit
32e1d68d36
4 changed files with 109 additions and 0 deletions
42
gstreamer/src/allocator.rs
Normal file
42
gstreamer/src/allocator.rs
Normal file
|
@ -0,0 +1,42 @@
|
||||||
|
// Copyright (C) 2019 Vivia Nikolaidou <vivia@ahiru.eu>
|
||||||
|
//
|
||||||
|
// 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 std::ptr;
|
||||||
|
|
||||||
|
use gst_sys;
|
||||||
|
|
||||||
|
use glib::translate::{from_glib_full, ToGlibPtr};
|
||||||
|
use glib::IsA;
|
||||||
|
|
||||||
|
use AllocationParams;
|
||||||
|
use Allocator;
|
||||||
|
use Memory;
|
||||||
|
|
||||||
|
pub trait AllocatorExtManual: 'static {
|
||||||
|
fn alloc(&self, size: usize, params: Option<&AllocationParams>) -> Option<Memory>;
|
||||||
|
}
|
||||||
|
|
||||||
|
impl<O: IsA<Allocator>> AllocatorExtManual for O {
|
||||||
|
fn alloc(&self, size: usize, params: Option<&AllocationParams>) -> Option<Memory> {
|
||||||
|
unsafe {
|
||||||
|
let ret = gst_sys::gst_allocator_alloc(
|
||||||
|
self.as_ptr() as *mut _,
|
||||||
|
size,
|
||||||
|
match params {
|
||||||
|
Some(val) => val.to_glib_none().0 as *mut _,
|
||||||
|
None => ptr::null_mut(),
|
||||||
|
},
|
||||||
|
);
|
||||||
|
if ret.is_null() {
|
||||||
|
None
|
||||||
|
} else {
|
||||||
|
Some(from_glib_full(ret))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
61
gstreamer/src/auto/allocator.rs
Normal file
61
gstreamer/src/auto/allocator.rs
Normal file
|
@ -0,0 +1,61 @@
|
||||||
|
// This file was generated by gir (https://github.com/gtk-rs/gir)
|
||||||
|
// from gir-files (https://github.com/gtk-rs/gir-files)
|
||||||
|
// DO NOT EDIT
|
||||||
|
|
||||||
|
use Object;
|
||||||
|
use glib::object::IsA;
|
||||||
|
use glib::translate::*;
|
||||||
|
use gst_sys;
|
||||||
|
|
||||||
|
glib_wrapper! {
|
||||||
|
pub struct Allocator(Object<gst_sys::GstAllocator, gst_sys::GstAllocatorClass, AllocatorClass>) @extends Object;
|
||||||
|
|
||||||
|
match fn {
|
||||||
|
get_type => || gst_sys::gst_allocator_get_type(),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Allocator {
|
||||||
|
pub fn find(name: Option<&str>) -> Option<Allocator> {
|
||||||
|
assert_initialized_main_thread!();
|
||||||
|
unsafe {
|
||||||
|
from_glib_full(gst_sys::gst_allocator_find(name.to_glib_none().0))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn register<P: IsA<Allocator>>(name: &str, allocator: &P) {
|
||||||
|
skip_assert_initialized!();
|
||||||
|
unsafe {
|
||||||
|
gst_sys::gst_allocator_register(name.to_glib_none().0, allocator.as_ref().to_glib_full());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
unsafe impl Send for Allocator {}
|
||||||
|
unsafe impl Sync for Allocator {}
|
||||||
|
|
||||||
|
pub const NONE_ALLOCATOR: Option<&Allocator> = None;
|
||||||
|
|
||||||
|
pub trait AllocatorExt: 'static {
|
||||||
|
//fn alloc(&self, size: usize, params: Option<&mut AllocationParams>) -> /*Ignored*/Option<Memory>;
|
||||||
|
|
||||||
|
//fn free(&self, memory: /*Ignored*/&mut Memory);
|
||||||
|
|
||||||
|
fn set_default(&self);
|
||||||
|
}
|
||||||
|
|
||||||
|
impl<O: IsA<Allocator>> AllocatorExt for O {
|
||||||
|
//fn alloc(&self, size: usize, params: Option<&mut AllocationParams>) -> /*Ignored*/Option<Memory> {
|
||||||
|
// unsafe { TODO: call gst_sys:gst_allocator_alloc() }
|
||||||
|
//}
|
||||||
|
|
||||||
|
//fn free(&self, memory: /*Ignored*/&mut Memory) {
|
||||||
|
// unsafe { TODO: call gst_sys:gst_allocator_free() }
|
||||||
|
//}
|
||||||
|
|
||||||
|
fn set_default(&self) {
|
||||||
|
unsafe {
|
||||||
|
gst_sys::gst_allocator_set_default(self.as_ref().to_glib_full());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -2,6 +2,10 @@
|
||||||
// from gir-files (https://github.com/gtk-rs/gir-files)
|
// from gir-files (https://github.com/gtk-rs/gir-files)
|
||||||
// DO NOT EDIT
|
// DO NOT EDIT
|
||||||
|
|
||||||
|
mod allocator;
|
||||||
|
pub use self::allocator::{Allocator, AllocatorClass, NONE_ALLOCATOR};
|
||||||
|
pub use self::allocator::AllocatorExt;
|
||||||
|
|
||||||
mod bin;
|
mod bin;
|
||||||
pub use self::bin::{Bin, BinClass, NONE_BIN};
|
pub use self::bin::{Bin, BinClass, NONE_BIN};
|
||||||
pub use self::bin::GstBinExt;
|
pub use self::bin::GstBinExt;
|
||||||
|
@ -189,6 +193,7 @@ pub mod functions;
|
||||||
|
|
||||||
#[doc(hidden)]
|
#[doc(hidden)]
|
||||||
pub mod traits {
|
pub mod traits {
|
||||||
|
pub use super::AllocatorExt;
|
||||||
pub use super::GstBinExt;
|
pub use super::GstBinExt;
|
||||||
pub use super::BufferPoolExt;
|
pub use super::BufferPoolExt;
|
||||||
pub use super::ChildProxyExt;
|
pub use super::ChildProxyExt;
|
||||||
|
|
|
@ -155,6 +155,7 @@ mod element;
|
||||||
|
|
||||||
mod bin;
|
mod bin;
|
||||||
|
|
||||||
|
mod allocator;
|
||||||
mod pipeline;
|
mod pipeline;
|
||||||
|
|
||||||
mod allocation_params;
|
mod allocation_params;
|
||||||
|
|
Loading…
Reference in a new issue