From 32e1d68d364e1b1dfe07da38ab52a7088664c0e9 Mon Sep 17 00:00:00 2001 From: Vivia Nikolaidou Date: Sun, 12 May 2019 16:38:40 +0300 Subject: [PATCH] allocator: Expose GstAllocator --- gstreamer/src/allocator.rs | 42 +++++++++++++++++++++++ gstreamer/src/auto/allocator.rs | 61 +++++++++++++++++++++++++++++++++ gstreamer/src/auto/mod.rs | 5 +++ gstreamer/src/lib.rs | 1 + 4 files changed, 109 insertions(+) create mode 100644 gstreamer/src/allocator.rs create mode 100644 gstreamer/src/auto/allocator.rs diff --git a/gstreamer/src/allocator.rs b/gstreamer/src/allocator.rs new file mode 100644 index 000000000..1a935bb22 --- /dev/null +++ b/gstreamer/src/allocator.rs @@ -0,0 +1,42 @@ +// Copyright (C) 2019 Vivia Nikolaidou +// +// Licensed under the Apache License, Version 2.0 or the MIT license +// , 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; +} + +impl> AllocatorExtManual for O { + fn alloc(&self, size: usize, params: Option<&AllocationParams>) -> Option { + 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)) + } + } + } +} diff --git a/gstreamer/src/auto/allocator.rs b/gstreamer/src/auto/allocator.rs new file mode 100644 index 000000000..6f1a5c6f5 --- /dev/null +++ b/gstreamer/src/auto/allocator.rs @@ -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) @extends Object; + + match fn { + get_type => || gst_sys::gst_allocator_get_type(), + } +} + +impl Allocator { + pub fn find(name: Option<&str>) -> Option { + assert_initialized_main_thread!(); + unsafe { + from_glib_full(gst_sys::gst_allocator_find(name.to_glib_none().0)) + } + } + + pub fn register>(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; + + //fn free(&self, memory: /*Ignored*/&mut Memory); + + fn set_default(&self); +} + +impl> AllocatorExt for O { + //fn alloc(&self, size: usize, params: Option<&mut AllocationParams>) -> /*Ignored*/Option { + // 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()); + } + } +} diff --git a/gstreamer/src/auto/mod.rs b/gstreamer/src/auto/mod.rs index ad312de65..28a9a9de3 100644 --- a/gstreamer/src/auto/mod.rs +++ b/gstreamer/src/auto/mod.rs @@ -2,6 +2,10 @@ // from gir-files (https://github.com/gtk-rs/gir-files) // DO NOT EDIT +mod allocator; +pub use self::allocator::{Allocator, AllocatorClass, NONE_ALLOCATOR}; +pub use self::allocator::AllocatorExt; + mod bin; pub use self::bin::{Bin, BinClass, NONE_BIN}; pub use self::bin::GstBinExt; @@ -189,6 +193,7 @@ pub mod functions; #[doc(hidden)] pub mod traits { + pub use super::AllocatorExt; pub use super::GstBinExt; pub use super::BufferPoolExt; pub use super::ChildProxyExt; diff --git a/gstreamer/src/lib.rs b/gstreamer/src/lib.rs index 117a58e01..930d48f50 100644 --- a/gstreamer/src/lib.rs +++ b/gstreamer/src/lib.rs @@ -155,6 +155,7 @@ mod element; mod bin; +mod allocator; mod pipeline; mod allocation_params;