mirror of
https://gitlab.freedesktop.org/gstreamer/gstreamer-rs.git
synced 2025-01-11 01:35:26 +00:00
Port Bin subclassing
This commit is contained in:
parent
0a8d34bc23
commit
55dac7eeb4
6 changed files with 170 additions and 3 deletions
|
@ -83,6 +83,7 @@ conversion_type = "scalar"
|
||||||
|
|
||||||
[[object]]
|
[[object]]
|
||||||
name = "Gst.Bin"
|
name = "Gst.Bin"
|
||||||
|
subclassing = true
|
||||||
status = "generate"
|
status = "generate"
|
||||||
trait_name = "GstBinExt"
|
trait_name = "GstBinExt"
|
||||||
[[object.function]]
|
[[object.function]]
|
||||||
|
|
|
@ -2,6 +2,7 @@
|
||||||
// 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
|
||||||
|
|
||||||
|
use BinClass;
|
||||||
use ChildProxy;
|
use ChildProxy;
|
||||||
use Element;
|
use Element;
|
||||||
#[cfg(any(feature = "v1_10", feature = "dox"))]
|
#[cfg(any(feature = "v1_10", feature = "dox"))]
|
||||||
|
@ -26,7 +27,7 @@ use std::mem::transmute;
|
||||||
use std::ptr;
|
use std::ptr;
|
||||||
|
|
||||||
glib_wrapper! {
|
glib_wrapper! {
|
||||||
pub struct Bin(Object<ffi::GstBin, ffi::GstBinClass>): Element, Object, ChildProxy;
|
pub struct Bin(Object<ffi::GstBin, ffi::GstBinClass, BinClass>): Element, Object, ChildProxy;
|
||||||
|
|
||||||
match fn {
|
match fn {
|
||||||
get_type => || ffi::gst_bin_get_type(),
|
get_type => || ffi::gst_bin_get_type(),
|
||||||
|
|
|
@ -11,10 +11,11 @@ use Element;
|
||||||
|
|
||||||
use glib;
|
use glib;
|
||||||
use glib::translate::{from_glib, from_glib_full, FromGlibPtrContainer, ToGlib, ToGlibPtr};
|
use glib::translate::{from_glib, from_glib_full, FromGlibPtrContainer, ToGlib, ToGlibPtr};
|
||||||
use glib::IsA;
|
use glib::{IsA, IsClassFor};
|
||||||
|
|
||||||
use ffi;
|
use ffi;
|
||||||
|
|
||||||
|
use std::ops;
|
||||||
use std::path;
|
use std::path;
|
||||||
|
|
||||||
pub trait GstBinExtManual {
|
pub trait GstBinExtManual {
|
||||||
|
@ -124,6 +125,30 @@ impl<O: IsA<Bin>> GstBinExtManual for O {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[repr(C)]
|
||||||
|
pub struct BinClass(ffi::GstBinClass);
|
||||||
|
|
||||||
|
unsafe impl IsClassFor for BinClass {
|
||||||
|
type Instance = ::Bin;
|
||||||
|
}
|
||||||
|
|
||||||
|
unsafe impl Send for BinClass {}
|
||||||
|
unsafe impl Sync for BinClass {}
|
||||||
|
|
||||||
|
impl ops::Deref for BinClass {
|
||||||
|
type Target = ::ElementClass;
|
||||||
|
|
||||||
|
fn deref(&self) -> &Self::Target {
|
||||||
|
self.upcast_ref()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl ops::DerefMut for BinClass {
|
||||||
|
fn deref_mut(&mut self) -> &mut Self::Target {
|
||||||
|
self.upcast_ref_mut()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod tests {
|
mod tests {
|
||||||
use super::*;
|
use super::*;
|
||||||
|
|
|
@ -145,11 +145,13 @@ mod promise;
|
||||||
#[cfg(any(feature = "v1_14", feature = "dox"))]
|
#[cfg(any(feature = "v1_14", feature = "dox"))]
|
||||||
pub use promise::*;
|
pub use promise::*;
|
||||||
|
|
||||||
mod bin;
|
|
||||||
mod bus;
|
mod bus;
|
||||||
mod element;
|
mod element;
|
||||||
pub use element::ElementClass;
|
pub use element::ElementClass;
|
||||||
|
|
||||||
|
mod bin;
|
||||||
|
pub use bin::BinClass;
|
||||||
|
|
||||||
// OS dependent Bus extensions (also import the other plateform mod for doc)
|
// OS dependent Bus extensions (also import the other plateform mod for doc)
|
||||||
#[cfg(any(feature = "v1_14", feature = "dox"))]
|
#[cfg(any(feature = "v1_14", feature = "dox"))]
|
||||||
cfg_if! {
|
cfg_if! {
|
||||||
|
|
136
gstreamer/src/subclass/bin.rs
Normal file
136
gstreamer/src/subclass/bin.rs
Normal file
|
@ -0,0 +1,136 @@
|
||||||
|
// Copyright (C) 2017,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 ffi;
|
||||||
|
use glib_ffi;
|
||||||
|
|
||||||
|
use glib::translate::*;
|
||||||
|
|
||||||
|
use super::prelude::*;
|
||||||
|
use glib::subclass::prelude::*;
|
||||||
|
|
||||||
|
use Bin;
|
||||||
|
use BinClass;
|
||||||
|
use Element;
|
||||||
|
use Message;
|
||||||
|
|
||||||
|
pub trait BinImpl: ElementImpl + Send + Sync + 'static {
|
||||||
|
fn add_element(&self, bin: &Bin, element: &Element) -> bool {
|
||||||
|
self.parent_add_element(bin, element)
|
||||||
|
}
|
||||||
|
|
||||||
|
fn remove_element(&self, bin: &Bin, element: &Element) -> bool {
|
||||||
|
self.parent_remove_element(bin, element)
|
||||||
|
}
|
||||||
|
|
||||||
|
fn handle_message(&self, bin: &Bin, message: Message) {
|
||||||
|
self.parent_handle_message(bin, message)
|
||||||
|
}
|
||||||
|
|
||||||
|
fn parent_add_element(&self, bin: &Bin, element: &Element) -> bool {
|
||||||
|
unsafe {
|
||||||
|
let data = self.get_type_data();
|
||||||
|
let parent_class = data.as_ref().get_parent_class() as *mut ffi::GstBinClass;
|
||||||
|
(*parent_class)
|
||||||
|
.add_element
|
||||||
|
.map(|f| from_glib(f(bin.to_glib_none().0, element.to_glib_none().0)))
|
||||||
|
.unwrap_or(false)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fn parent_remove_element(&self, bin: &Bin, element: &Element) -> bool {
|
||||||
|
unsafe {
|
||||||
|
let data = self.get_type_data();
|
||||||
|
let parent_class = data.as_ref().get_parent_class() as *mut ffi::GstBinClass;
|
||||||
|
(*parent_class)
|
||||||
|
.remove_element
|
||||||
|
.map(|f| from_glib(f(bin.to_glib_none().0, element.to_glib_none().0)))
|
||||||
|
.unwrap_or(false)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fn parent_handle_message(&self, bin: &Bin, message: Message) {
|
||||||
|
unsafe {
|
||||||
|
let data = self.get_type_data();
|
||||||
|
let parent_class = data.as_ref().get_parent_class() as *mut ffi::GstBinClass;
|
||||||
|
(*parent_class)
|
||||||
|
.handle_message
|
||||||
|
.map(move |f| f(bin.to_glib_none().0, message.into_ptr()));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
unsafe impl<T: ObjectSubclass + BinImpl> IsSubclassable<T> for BinClass
|
||||||
|
where
|
||||||
|
<T as ObjectSubclass>::Instance: PanicPoison,
|
||||||
|
{
|
||||||
|
fn override_vfuncs(&mut self) {
|
||||||
|
<::ElementClass as IsSubclassable<T>>::override_vfuncs(self);
|
||||||
|
unsafe {
|
||||||
|
let klass = &mut *(self as *const Self as *mut ffi::GstBinClass);
|
||||||
|
klass.add_element = Some(bin_add_element::<T>);
|
||||||
|
klass.remove_element = Some(bin_remove_element::<T>);
|
||||||
|
klass.handle_message = Some(bin_handle_message::<T>);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
unsafe extern "C" fn bin_add_element<T: ObjectSubclass>(
|
||||||
|
ptr: *mut ffi::GstBin,
|
||||||
|
element: *mut ffi::GstElement,
|
||||||
|
) -> glib_ffi::gboolean
|
||||||
|
where
|
||||||
|
T: BinImpl,
|
||||||
|
T::Instance: PanicPoison,
|
||||||
|
{
|
||||||
|
glib_floating_reference_guard!(ptr);
|
||||||
|
let instance = &*(ptr as *mut T::Instance);
|
||||||
|
let imp = instance.get_impl();
|
||||||
|
let wrap: Bin = from_glib_borrow(ptr);
|
||||||
|
|
||||||
|
gst_panic_to_error!(&wrap, &instance.panicked(), false, {
|
||||||
|
imp.add_element(&wrap, &from_glib_borrow(element))
|
||||||
|
})
|
||||||
|
.to_glib()
|
||||||
|
}
|
||||||
|
|
||||||
|
unsafe extern "C" fn bin_remove_element<T: ObjectSubclass>(
|
||||||
|
ptr: *mut ffi::GstBin,
|
||||||
|
element: *mut ffi::GstElement,
|
||||||
|
) -> glib_ffi::gboolean
|
||||||
|
where
|
||||||
|
T: BinImpl,
|
||||||
|
T::Instance: PanicPoison,
|
||||||
|
{
|
||||||
|
glib_floating_reference_guard!(ptr);
|
||||||
|
let instance = &*(ptr as *mut T::Instance);
|
||||||
|
let imp = instance.get_impl();
|
||||||
|
let wrap: Bin = from_glib_borrow(ptr);
|
||||||
|
|
||||||
|
gst_panic_to_error!(&wrap, &instance.panicked(), false, {
|
||||||
|
imp.remove_element(&wrap, &from_glib_borrow(element))
|
||||||
|
})
|
||||||
|
.to_glib()
|
||||||
|
}
|
||||||
|
|
||||||
|
unsafe extern "C" fn bin_handle_message<T: ObjectSubclass>(
|
||||||
|
ptr: *mut ffi::GstBin,
|
||||||
|
message: *mut ffi::GstMessage,
|
||||||
|
) where
|
||||||
|
T: BinImpl,
|
||||||
|
T::Instance: PanicPoison,
|
||||||
|
{
|
||||||
|
glib_floating_reference_guard!(ptr);
|
||||||
|
let instance = &*(ptr as *mut T::Instance);
|
||||||
|
let imp = instance.get_impl();
|
||||||
|
let wrap: Bin = from_glib_borrow(ptr);
|
||||||
|
|
||||||
|
gst_panic_to_error!(&wrap, &instance.panicked(), (), {
|
||||||
|
imp.handle_message(&wrap, from_glib_full(message))
|
||||||
|
});
|
||||||
|
}
|
|
@ -13,11 +13,13 @@ pub mod error;
|
||||||
#[macro_use]
|
#[macro_use]
|
||||||
pub mod plugin;
|
pub mod plugin;
|
||||||
|
|
||||||
|
pub mod bin;
|
||||||
pub mod child_proxy;
|
pub mod child_proxy;
|
||||||
pub mod element;
|
pub mod element;
|
||||||
pub mod uri_handler;
|
pub mod uri_handler;
|
||||||
|
|
||||||
pub mod prelude {
|
pub mod prelude {
|
||||||
|
pub use super::bin::BinImpl;
|
||||||
pub use super::child_proxy::ChildProxyImpl;
|
pub use super::child_proxy::ChildProxyImpl;
|
||||||
pub use super::element::{ElementClassSubclassExt, ElementImpl, ElementImplExt};
|
pub use super::element::{ElementClassSubclassExt, ElementImpl, ElementImplExt};
|
||||||
pub use super::uri_handler::URIHandlerImpl;
|
pub use super::uri_handler::URIHandlerImpl;
|
||||||
|
|
Loading…
Reference in a new issue