2018-11-18 14:36:28 +00:00
|
|
|
// 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.
|
|
|
|
|
2019-03-19 07:58:20 +00:00
|
|
|
use glib_sys;
|
|
|
|
use gobject_sys;
|
|
|
|
use gst_sys;
|
2018-11-18 14:36:28 +00:00
|
|
|
|
|
|
|
use glib;
|
|
|
|
use glib::subclass::prelude::*;
|
|
|
|
use glib::translate::*;
|
|
|
|
|
|
|
|
use libc;
|
|
|
|
|
|
|
|
use ChildProxy;
|
|
|
|
|
2020-07-25 08:02:04 +00:00
|
|
|
pub trait ChildProxyImpl: ObjectImpl + Send + Sync {
|
2018-11-18 14:36:28 +00:00
|
|
|
fn get_child_by_name(&self, object: &ChildProxy, name: &str) -> Option<glib::Object> {
|
|
|
|
unsafe {
|
2019-03-19 07:58:20 +00:00
|
|
|
let type_ = gst_sys::gst_child_proxy_get_type();
|
|
|
|
let iface = gobject_sys::g_type_default_interface_ref(type_)
|
|
|
|
as *mut gst_sys::GstChildProxyInterface;
|
2018-11-18 14:36:28 +00:00
|
|
|
assert!(!iface.is_null());
|
|
|
|
|
|
|
|
let ret = ((*iface).get_child_by_name.as_ref().unwrap())(
|
|
|
|
object.to_glib_none().0,
|
|
|
|
name.to_glib_none().0,
|
|
|
|
);
|
|
|
|
|
2019-03-19 07:58:20 +00:00
|
|
|
gobject_sys::g_type_default_interface_unref(iface as glib_sys::gpointer);
|
2018-11-18 14:36:28 +00:00
|
|
|
|
|
|
|
from_glib_full(ret)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
fn get_child_by_index(&self, object: &ChildProxy, index: u32) -> Option<glib::Object>;
|
|
|
|
fn get_children_count(&self, object: &ChildProxy) -> u32;
|
|
|
|
|
2020-01-22 17:14:48 +00:00
|
|
|
fn child_added(&self, _object: &ChildProxy, _child: &glib::Object, _name: &str) {}
|
|
|
|
fn child_removed(&self, _object: &ChildProxy, _child: &glib::Object, _name: &str) {}
|
2018-11-18 14:36:28 +00:00
|
|
|
}
|
|
|
|
|
2020-07-25 08:02:04 +00:00
|
|
|
unsafe impl<T: ChildProxyImpl> IsImplementable<T> for ChildProxy {
|
2018-12-18 23:15:23 +00:00
|
|
|
unsafe extern "C" fn interface_init(
|
2019-03-19 07:58:20 +00:00
|
|
|
iface: glib_sys::gpointer,
|
|
|
|
_iface_data: glib_sys::gpointer,
|
2018-12-18 23:15:23 +00:00
|
|
|
) {
|
2019-03-19 07:58:20 +00:00
|
|
|
let child_proxy_iface = &mut *(iface as *mut gst_sys::GstChildProxyInterface);
|
2018-12-18 23:15:23 +00:00
|
|
|
|
|
|
|
child_proxy_iface.get_child_by_name = Some(child_proxy_get_child_by_name::<T>);
|
|
|
|
child_proxy_iface.get_child_by_index = Some(child_proxy_get_child_by_index::<T>);
|
|
|
|
child_proxy_iface.get_children_count = Some(child_proxy_get_children_count::<T>);
|
|
|
|
child_proxy_iface.child_added = Some(child_proxy_child_added::<T>);
|
|
|
|
child_proxy_iface.child_removed = Some(child_proxy_child_removed::<T>);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-07-25 08:02:04 +00:00
|
|
|
unsafe extern "C" fn child_proxy_get_child_by_name<T: ChildProxyImpl>(
|
2019-03-19 07:58:20 +00:00
|
|
|
child_proxy: *mut gst_sys::GstChildProxy,
|
2018-11-18 14:36:28 +00:00
|
|
|
name: *const libc::c_char,
|
2020-07-25 08:02:04 +00:00
|
|
|
) -> *mut gobject_sys::GObject {
|
2018-11-18 14:36:28 +00:00
|
|
|
let instance = &*(child_proxy as *mut T::Instance);
|
|
|
|
let imp = instance.get_impl();
|
|
|
|
|
|
|
|
imp.get_child_by_name(
|
|
|
|
&from_glib_borrow(child_proxy),
|
2020-04-05 14:52:56 +00:00
|
|
|
&glib::GString::from_glib_borrow(name),
|
2018-11-18 14:36:28 +00:00
|
|
|
)
|
|
|
|
.to_glib_full()
|
|
|
|
}
|
|
|
|
|
2020-07-25 08:02:04 +00:00
|
|
|
unsafe extern "C" fn child_proxy_get_child_by_index<T: ChildProxyImpl>(
|
2019-03-19 07:58:20 +00:00
|
|
|
child_proxy: *mut gst_sys::GstChildProxy,
|
2018-11-18 14:36:28 +00:00
|
|
|
index: u32,
|
2020-07-25 08:02:04 +00:00
|
|
|
) -> *mut gobject_sys::GObject {
|
2018-11-18 14:36:28 +00:00
|
|
|
let instance = &*(child_proxy as *mut T::Instance);
|
|
|
|
let imp = instance.get_impl();
|
|
|
|
|
|
|
|
imp.get_child_by_index(&from_glib_borrow(child_proxy), index)
|
|
|
|
.to_glib_full()
|
|
|
|
}
|
|
|
|
|
2020-07-25 08:02:04 +00:00
|
|
|
unsafe extern "C" fn child_proxy_get_children_count<T: ChildProxyImpl>(
|
2019-03-19 07:58:20 +00:00
|
|
|
child_proxy: *mut gst_sys::GstChildProxy,
|
2020-07-25 08:02:04 +00:00
|
|
|
) -> u32 {
|
2018-11-18 14:36:28 +00:00
|
|
|
let instance = &*(child_proxy as *mut T::Instance);
|
|
|
|
let imp = instance.get_impl();
|
|
|
|
|
|
|
|
imp.get_children_count(&from_glib_borrow(child_proxy))
|
|
|
|
}
|
|
|
|
|
2020-07-25 08:02:04 +00:00
|
|
|
unsafe extern "C" fn child_proxy_child_added<T: ChildProxyImpl>(
|
2019-03-19 07:58:20 +00:00
|
|
|
child_proxy: *mut gst_sys::GstChildProxy,
|
|
|
|
child: *mut gobject_sys::GObject,
|
2018-11-18 14:36:28 +00:00
|
|
|
name: *const libc::c_char,
|
2020-07-25 08:02:04 +00:00
|
|
|
) {
|
2018-11-18 14:36:28 +00:00
|
|
|
let instance = &*(child_proxy as *mut T::Instance);
|
|
|
|
let imp = instance.get_impl();
|
|
|
|
|
|
|
|
imp.child_added(
|
|
|
|
&from_glib_borrow(child_proxy),
|
|
|
|
&from_glib_borrow(child),
|
2020-04-05 14:52:56 +00:00
|
|
|
&glib::GString::from_glib_borrow(name),
|
2018-11-18 14:36:28 +00:00
|
|
|
)
|
|
|
|
}
|
|
|
|
|
2020-07-25 08:02:04 +00:00
|
|
|
unsafe extern "C" fn child_proxy_child_removed<T: ChildProxyImpl>(
|
2019-03-19 07:58:20 +00:00
|
|
|
child_proxy: *mut gst_sys::GstChildProxy,
|
|
|
|
child: *mut gobject_sys::GObject,
|
2018-11-18 14:36:28 +00:00
|
|
|
name: *const libc::c_char,
|
2020-07-25 08:02:04 +00:00
|
|
|
) {
|
2018-11-18 14:36:28 +00:00
|
|
|
let instance = &*(child_proxy as *mut T::Instance);
|
|
|
|
let imp = instance.get_impl();
|
|
|
|
|
|
|
|
imp.child_removed(
|
|
|
|
&from_glib_borrow(child_proxy),
|
|
|
|
&from_glib_borrow(child),
|
2020-04-05 14:52:56 +00:00
|
|
|
&glib::GString::from_glib_borrow(name),
|
2018-11-18 14:36:28 +00:00
|
|
|
)
|
|
|
|
}
|