gstreamer: Make virtual methods take wrapper of type, not parent

This commit is contained in:
Sebastian Dröge 2020-11-14 17:34:41 +02:00
parent 1d53b66858
commit 4eaf574cf8
8 changed files with 303 additions and 195 deletions

View file

@ -9,6 +9,7 @@
use glib_sys;
use gst_sys;
use glib::prelude::*;
use glib::translate::*;
use super::prelude::*;
@ -20,29 +21,33 @@ use LoggableError;
use Message;
pub trait BinImpl: BinImplExt + ElementImpl {
fn add_element(&self, bin: &Bin, element: &Element) -> Result<(), LoggableError> {
fn add_element(&self, bin: &Self::Type, element: &Element) -> Result<(), LoggableError> {
self.parent_add_element(bin, element)
}
fn remove_element(&self, bin: &Bin, element: &Element) -> Result<(), LoggableError> {
fn remove_element(&self, bin: &Self::Type, element: &Element) -> Result<(), LoggableError> {
self.parent_remove_element(bin, element)
}
fn handle_message(&self, bin: &Bin, message: Message) {
fn handle_message(&self, bin: &Self::Type, message: Message) {
self.parent_handle_message(bin, message)
}
}
pub trait BinImplExt {
fn parent_add_element(&self, bin: &Bin, element: &Element) -> Result<(), LoggableError>;
pub trait BinImplExt: ObjectSubclass {
fn parent_add_element(&self, bin: &Self::Type, element: &Element) -> Result<(), LoggableError>;
fn parent_remove_element(&self, bin: &Bin, element: &Element) -> Result<(), LoggableError>;
fn parent_remove_element(
&self,
bin: &Self::Type,
element: &Element,
) -> Result<(), LoggableError>;
fn parent_handle_message(&self, bin: &Bin, message: Message);
fn parent_handle_message(&self, bin: &Self::Type, message: Message);
}
impl<T: BinImpl> BinImplExt for T {
fn parent_add_element(&self, bin: &Bin, element: &Element) -> Result<(), LoggableError> {
fn parent_add_element(&self, bin: &Self::Type, element: &Element) -> Result<(), LoggableError> {
unsafe {
let data = T::type_data();
let parent_class = data.as_ref().get_parent_class() as *mut gst_sys::GstBinClass;
@ -50,14 +55,21 @@ impl<T: BinImpl> BinImplExt for T {
gst_loggable_error!(::CAT_RUST, "Parent function `add_element` is not defined")
})?;
gst_result_from_gboolean!(
f(bin.to_glib_none().0, element.to_glib_none().0),
f(
bin.unsafe_cast_ref::<::Bin>().to_glib_none().0,
element.to_glib_none().0
),
::CAT_RUST,
"Failed to add the element using the parent function"
)
}
}
fn parent_remove_element(&self, bin: &Bin, element: &Element) -> Result<(), LoggableError> {
fn parent_remove_element(
&self,
bin: &Self::Type,
element: &Element,
) -> Result<(), LoggableError> {
unsafe {
let data = T::type_data();
let parent_class = data.as_ref().get_parent_class() as *mut gst_sys::GstBinClass;
@ -68,19 +80,25 @@ impl<T: BinImpl> BinImplExt for T {
)
})?;
gst_result_from_gboolean!(
f(bin.to_glib_none().0, element.to_glib_none().0),
f(
bin.unsafe_cast_ref::<::Bin>().to_glib_none().0,
element.to_glib_none().0
),
::CAT_RUST,
"Failed to remove the element using the parent function"
)
}
}
fn parent_handle_message(&self, bin: &Bin, message: Message) {
fn parent_handle_message(&self, bin: &Self::Type, message: Message) {
unsafe {
let data = T::type_data();
let parent_class = data.as_ref().get_parent_class() as *mut gst_sys::GstBinClass;
if let Some(ref f) = (*parent_class).handle_message {
f(bin.to_glib_none().0, message.into_ptr());
f(
bin.unsafe_cast_ref::<::Bin>().to_glib_none().0,
message.into_ptr(),
);
}
}
}
@ -111,7 +129,7 @@ where
let wrap: Borrowed<Bin> = from_glib_borrow(ptr);
gst_panic_to_error!(&wrap, &instance.panicked(), false, {
match imp.add_element(&wrap, &from_glib_none(element)) {
match imp.add_element(wrap.unsafe_cast_ref(), &from_glib_none(element)) {
Ok(()) => true,
Err(err) => {
err.log_with_object(&*wrap);
@ -141,7 +159,7 @@ where
}
gst_panic_to_error!(&wrap, &instance.panicked(), false, {
match imp.remove_element(&wrap, &from_glib_none(element)) {
match imp.remove_element(wrap.unsafe_cast_ref(), &from_glib_none(element)) {
Ok(()) => true,
Err(err) => {
err.log_with_object(&*wrap);
@ -163,6 +181,6 @@ unsafe extern "C" fn bin_handle_message<T: BinImpl>(
let wrap: Borrowed<Bin> = from_glib_borrow(ptr);
gst_panic_to_error!(&wrap, &instance.panicked(), (), {
imp.handle_message(&wrap, from_glib_full(message))
imp.handle_message(wrap.unsafe_cast_ref(), from_glib_full(message))
});
}

View file

@ -11,6 +11,7 @@ use gobject_sys;
use gst_sys;
use glib;
use glib::prelude::*;
use glib::subclass::prelude::*;
use glib::translate::*;
@ -19,7 +20,7 @@ use libc;
use ChildProxy;
pub trait ChildProxyImpl: ObjectImpl + Send + Sync {
fn get_child_by_name(&self, object: &ChildProxy, name: &str) -> Option<glib::Object> {
fn get_child_by_name(&self, object: &Self::Type, name: &str) -> Option<glib::Object> {
unsafe {
let type_ = gst_sys::gst_child_proxy_get_type();
let iface = gobject_sys::g_type_default_interface_ref(type_)
@ -27,7 +28,7 @@ pub trait ChildProxyImpl: ObjectImpl + Send + Sync {
assert!(!iface.is_null());
let ret = ((*iface).get_child_by_name.as_ref().unwrap())(
object.to_glib_none().0,
object.unsafe_cast_ref::<ChildProxy>().to_glib_none().0,
name.to_glib_none().0,
);
@ -37,11 +38,11 @@ pub trait ChildProxyImpl: ObjectImpl + Send + Sync {
}
}
fn get_child_by_index(&self, object: &ChildProxy, index: u32) -> Option<glib::Object>;
fn get_children_count(&self, object: &ChildProxy) -> u32;
fn get_child_by_index(&self, object: &Self::Type, index: u32) -> Option<glib::Object>;
fn get_children_count(&self, object: &Self::Type) -> u32;
fn child_added(&self, _object: &ChildProxy, _child: &glib::Object, _name: &str) {}
fn child_removed(&self, _object: &ChildProxy, _child: &glib::Object, _name: &str) {}
fn child_added(&self, _object: &Self::Type, _child: &glib::Object, _name: &str) {}
fn child_removed(&self, _object: &Self::Type, _child: &glib::Object, _name: &str) {}
}
unsafe impl<T: ChildProxyImpl> IsImplementable<T> for ChildProxy {
@ -67,7 +68,7 @@ unsafe extern "C" fn child_proxy_get_child_by_name<T: ChildProxyImpl>(
let imp = instance.get_impl();
imp.get_child_by_name(
&from_glib_borrow(child_proxy),
&from_glib_borrow::<_, ChildProxy>(child_proxy).unsafe_cast_ref(),
&glib::GString::from_glib_borrow(name),
)
.to_glib_full()
@ -80,8 +81,11 @@ unsafe extern "C" fn child_proxy_get_child_by_index<T: ChildProxyImpl>(
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()
imp.get_child_by_index(
&from_glib_borrow::<_, ChildProxy>(child_proxy).unsafe_cast_ref(),
index,
)
.to_glib_full()
}
unsafe extern "C" fn child_proxy_get_children_count<T: ChildProxyImpl>(
@ -90,7 +94,7 @@ unsafe extern "C" fn child_proxy_get_children_count<T: ChildProxyImpl>(
let instance = &*(child_proxy as *mut T::Instance);
let imp = instance.get_impl();
imp.get_children_count(&from_glib_borrow(child_proxy))
imp.get_children_count(&from_glib_borrow::<_, ChildProxy>(child_proxy).unsafe_cast_ref())
}
unsafe extern "C" fn child_proxy_child_added<T: ChildProxyImpl>(
@ -102,7 +106,7 @@ unsafe extern "C" fn child_proxy_child_added<T: ChildProxyImpl>(
let imp = instance.get_impl();
imp.child_added(
&from_glib_borrow(child_proxy),
&from_glib_borrow::<_, ChildProxy>(child_proxy).unsafe_cast_ref(),
&from_glib_borrow(child),
&glib::GString::from_glib_borrow(name),
)
@ -117,7 +121,7 @@ unsafe extern "C" fn child_proxy_child_removed<T: ChildProxyImpl>(
let imp = instance.get_impl();
imp.child_removed(
&from_glib_borrow(child_proxy),
&from_glib_borrow::<_, ChildProxy>(child_proxy).unsafe_cast_ref(),
&from_glib_borrow(child),
&glib::GString::from_glib_borrow(name),
)

View file

@ -24,59 +24,63 @@ use ClockTimeDiff;
pub trait ClockImpl: ClockImplExt + ObjectImpl + Send + Sync {
fn change_resolution(
&self,
clock: &Clock,
clock: &Self::Type,
old_resolution: ClockTime,
new_resolution: ClockTime,
) -> ClockTime {
self.parent_change_resolution(clock, old_resolution, new_resolution)
}
fn get_resolution(&self, clock: &Clock) -> ClockTime {
fn get_resolution(&self, clock: &Self::Type) -> ClockTime {
self.parent_get_resolution(clock)
}
fn get_internal_time(&self, clock: &Clock) -> ClockTime {
fn get_internal_time(&self, clock: &Self::Type) -> ClockTime {
self.parent_get_internal_time(clock)
}
fn wait(
&self,
clock: &Clock,
clock: &Self::Type,
id: &ClockId,
) -> (Result<ClockSuccess, ClockError>, ClockTimeDiff) {
self.parent_wait(clock, id)
}
fn wait_async(&self, clock: &Clock, id: &ClockId) -> Result<ClockSuccess, ClockError> {
fn wait_async(&self, clock: &Self::Type, id: &ClockId) -> Result<ClockSuccess, ClockError> {
self.parent_wait_async(clock, id)
}
fn unschedule(&self, clock: &Clock, id: &ClockId) {
fn unschedule(&self, clock: &Self::Type, id: &ClockId) {
self.parent_unschedule(clock, id)
}
}
pub trait ClockImplExt {
pub trait ClockImplExt: ObjectSubclass {
fn parent_change_resolution(
&self,
clock: &Clock,
clock: &Self::Type,
old_resolution: ClockTime,
new_resolution: ClockTime,
) -> ClockTime;
fn parent_get_resolution(&self, clock: &Clock) -> ClockTime;
fn parent_get_resolution(&self, clock: &Self::Type) -> ClockTime;
fn parent_get_internal_time(&self, clock: &Clock) -> ClockTime;
fn parent_get_internal_time(&self, clock: &Self::Type) -> ClockTime;
fn parent_wait(
&self,
clock: &Clock,
clock: &Self::Type,
id: &ClockId,
) -> (Result<ClockSuccess, ClockError>, ClockTimeDiff);
fn parent_wait_async(&self, clock: &Clock, id: &ClockId) -> Result<ClockSuccess, ClockError>;
fn parent_wait_async(
&self,
clock: &Self::Type,
id: &ClockId,
) -> Result<ClockSuccess, ClockError>;
fn parent_unschedule(&self, clock: &Clock, id: &ClockId);
fn parent_unschedule(&self, clock: &Self::Type, id: &ClockId);
fn wake_id(&self, id: &ClockId)
where
@ -87,7 +91,7 @@ pub trait ClockImplExt {
impl<T: ClockImpl> ClockImplExt for T {
fn parent_change_resolution(
&self,
clock: &Clock,
clock: &Self::Type,
old_resolution: ClockTime,
new_resolution: ClockTime,
) -> ClockTime {
@ -97,7 +101,7 @@ impl<T: ClockImpl> ClockImplExt for T {
if let Some(func) = (*parent_class).change_resolution {
from_glib(func(
clock.to_glib_none().0,
clock.unsafe_cast_ref::<Clock>().to_glib_none().0,
old_resolution.to_glib(),
new_resolution.to_glib(),
))
@ -107,7 +111,7 @@ impl<T: ClockImpl> ClockImplExt for T {
}
}
fn parent_get_resolution(&self, clock: &Clock) -> ClockTime {
fn parent_get_resolution(&self, clock: &Self::Type) -> ClockTime {
unsafe {
let data = T::type_data();
let parent_class = data.as_ref().get_parent_class() as *mut gst_sys::GstClockClass;
@ -115,13 +119,13 @@ impl<T: ClockImpl> ClockImplExt for T {
from_glib(
(*parent_class)
.get_resolution
.map(|f| f(clock.to_glib_none().0))
.map(|f| f(clock.unsafe_cast_ref::<Clock>().to_glib_none().0))
.unwrap_or(1),
)
}
}
fn parent_get_internal_time(&self, clock: &Clock) -> ClockTime {
fn parent_get_internal_time(&self, clock: &Self::Type) -> ClockTime {
unsafe {
let data = T::type_data();
let parent_class = data.as_ref().get_parent_class() as *mut gst_sys::GstClockClass;
@ -129,7 +133,7 @@ impl<T: ClockImpl> ClockImplExt for T {
from_glib(
(*parent_class)
.get_internal_time
.map(|f| f(clock.to_glib_none().0))
.map(|f| f(clock.unsafe_cast_ref::<Clock>().to_glib_none().0))
.unwrap_or(0),
)
}
@ -137,7 +141,7 @@ impl<T: ClockImpl> ClockImplExt for T {
fn parent_wait(
&self,
clock: &Clock,
clock: &Self::Type,
id: &ClockId,
) -> (Result<ClockSuccess, ClockError>, ClockTimeDiff) {
unsafe {
@ -151,7 +155,7 @@ impl<T: ClockImpl> ClockImplExt for T {
.wait
.map(|f| {
f(
clock.to_glib_none().0,
clock.unsafe_cast_ref::<Clock>().to_glib_none().0,
id.to_glib_none().0 as *mut gst_sys::GstClockEntry,
&mut jitter,
)
@ -164,7 +168,11 @@ impl<T: ClockImpl> ClockImplExt for T {
}
}
fn parent_wait_async(&self, clock: &Clock, id: &ClockId) -> Result<ClockSuccess, ClockError> {
fn parent_wait_async(
&self,
clock: &Self::Type,
id: &ClockId,
) -> Result<ClockSuccess, ClockError> {
unsafe {
let data = T::type_data();
let parent_class = data.as_ref().get_parent_class() as *mut gst_sys::GstClockClass;
@ -173,7 +181,7 @@ impl<T: ClockImpl> ClockImplExt for T {
.wait_async
.map(|f| {
f(
clock.to_glib_none().0,
clock.unsafe_cast_ref::<Clock>().to_glib_none().0,
id.to_glib_none().0 as *mut gst_sys::GstClockEntry,
)
})
@ -183,13 +191,13 @@ impl<T: ClockImpl> ClockImplExt for T {
}
}
fn parent_unschedule(&self, clock: &Clock, id: &ClockId) {
fn parent_unschedule(&self, clock: &Self::Type, id: &ClockId) {
unsafe {
let data = T::type_data();
let parent_class = data.as_ref().get_parent_class() as *mut gst_sys::GstClockClass;
if let Some(func) = (*parent_class).unschedule {
func(
clock.to_glib_none().0,
clock.unsafe_cast_ref::<Clock>().to_glib_none().0,
id.to_glib_none().0 as *mut gst_sys::GstClockEntry,
);
}
@ -254,8 +262,12 @@ unsafe extern "C" fn clock_change_resolution<T: ClockImpl>(
let imp = instance.get_impl();
let wrap: Borrowed<Clock> = from_glib_borrow(ptr);
imp.change_resolution(&wrap, from_glib(old_resolution), from_glib(new_resolution))
.to_glib()
imp.change_resolution(
wrap.unsafe_cast_ref(),
from_glib(old_resolution),
from_glib(new_resolution),
)
.to_glib()
}
unsafe extern "C" fn clock_get_resolution<T: ClockImpl>(
@ -265,7 +277,7 @@ unsafe extern "C" fn clock_get_resolution<T: ClockImpl>(
let imp = instance.get_impl();
let wrap: Borrowed<Clock> = from_glib_borrow(ptr);
imp.get_resolution(&wrap).to_glib()
imp.get_resolution(wrap.unsafe_cast_ref()).to_glib()
}
unsafe extern "C" fn clock_get_internal_time<T: ClockImpl>(
@ -275,7 +287,7 @@ unsafe extern "C" fn clock_get_internal_time<T: ClockImpl>(
let imp = instance.get_impl();
let wrap: Borrowed<Clock> = from_glib_borrow(ptr);
imp.get_internal_time(&wrap).to_glib()
imp.get_internal_time(wrap.unsafe_cast_ref()).to_glib()
}
unsafe extern "C" fn clock_wait<T: ClockImpl>(
@ -287,7 +299,10 @@ unsafe extern "C" fn clock_wait<T: ClockImpl>(
let imp = instance.get_impl();
let wrap: Borrowed<Clock> = from_glib_borrow(ptr);
let (res, j) = imp.wait(&wrap, &from_glib_borrow(id as gst_sys::GstClockID));
let (res, j) = imp.wait(
wrap.unsafe_cast_ref(),
&from_glib_borrow(id as gst_sys::GstClockID),
);
if !jitter.is_null() {
*jitter = j;
}
@ -303,7 +318,11 @@ unsafe extern "C" fn clock_wait_async<T: ClockImpl>(
let imp = instance.get_impl();
let wrap: Borrowed<Clock> = from_glib_borrow(ptr);
ClockReturn::from(imp.wait_async(&wrap, &from_glib_borrow(id as gst_sys::GstClockID))).to_glib()
ClockReturn::from(imp.wait_async(
wrap.unsafe_cast_ref(),
&from_glib_borrow(id as gst_sys::GstClockID),
))
.to_glib()
}
unsafe extern "C" fn clock_unschedule<T: ClockImpl>(
@ -314,5 +333,8 @@ unsafe extern "C" fn clock_unschedule<T: ClockImpl>(
let imp = instance.get_impl();
let wrap: Borrowed<Clock> = from_glib_borrow(ptr);
imp.unschedule(&wrap, &from_glib_borrow(id as gst_sys::GstClockID));
imp.unschedule(
wrap.unsafe_cast_ref(),
&from_glib_borrow(id as gst_sys::GstClockID),
);
}

View file

@ -9,9 +9,9 @@
use glib_sys;
use gst_sys;
use glib::translate::*;
use glib::prelude::*;
use glib::subclass::prelude::*;
use glib::translate::*;
use Device;
use Element;
@ -22,27 +22,31 @@ use std::ptr;
pub trait DeviceImpl: DeviceImplExt + ObjectImpl + Send + Sync {
fn create_element(
&self,
device: &Device,
device: &Self::Type,
name: Option<&str>,
) -> Result<Element, LoggableError> {
self.parent_create_element(device, name)
}
fn reconfigure_element(&self, device: &Device, element: &Element) -> Result<(), LoggableError> {
fn reconfigure_element(
&self,
device: &Self::Type,
element: &Element,
) -> Result<(), LoggableError> {
self.parent_reconfigure_element(device, element)
}
}
pub trait DeviceImplExt {
pub trait DeviceImplExt: ObjectSubclass {
fn parent_create_element(
&self,
device: &Device,
device: &Self::Type,
name: Option<&str>,
) -> Result<Element, LoggableError>;
fn parent_reconfigure_element(
&self,
device: &Device,
device: &Self::Type,
element: &Element,
) -> Result<(), LoggableError>;
}
@ -50,14 +54,17 @@ pub trait DeviceImplExt {
impl<T: DeviceImpl> DeviceImplExt for T {
fn parent_create_element(
&self,
device: &Device,
device: &Self::Type,
name: Option<&str>,
) -> Result<Element, LoggableError> {
unsafe {
let data = T::type_data();
let parent_class = data.as_ref().get_parent_class() as *mut gst_sys::GstDeviceClass;
if let Some(f) = (*parent_class).create_element {
let ptr = f(device.to_glib_none().0, name.to_glib_none().0);
let ptr = f(
device.unsafe_cast_ref::<Device>().to_glib_none().0,
name.to_glib_none().0,
);
// Don't steal floating reference here but pass it further to the caller
Option::<_>::from_glib_full(ptr).ok_or_else(|| {
@ -77,7 +84,7 @@ impl<T: DeviceImpl> DeviceImplExt for T {
fn parent_reconfigure_element(
&self,
device: &Device,
device: &Self::Type,
element: &Element,
) -> Result<(), LoggableError> {
unsafe {
@ -90,7 +97,10 @@ impl<T: DeviceImpl> DeviceImplExt for T {
)
})?;
gst_result_from_gboolean!(
f(device.to_glib_none().0, element.to_glib_none().0),
f(
device.unsafe_cast_ref::<Device>().to_glib_none().0,
element.to_glib_none().0
),
::CAT_RUST,
"Failed to reconfigure the element using the parent function"
)
@ -116,7 +126,7 @@ unsafe extern "C" fn device_create_element<T: DeviceImpl>(
let wrap: Borrowed<Device> = from_glib_borrow(ptr);
match imp.create_element(
&wrap,
wrap.unsafe_cast_ref(),
Option::<glib::GString>::from_glib_borrow(name)
.as_ref()
.as_ref()
@ -146,7 +156,7 @@ unsafe extern "C" fn device_reconfigure_element<T: DeviceImpl>(
let imp = instance.get_impl();
let wrap: Borrowed<Device> = from_glib_borrow(ptr);
match imp.reconfigure_element(&wrap, &from_glib_borrow(element)) {
match imp.reconfigure_element(wrap.unsafe_cast_ref(), &from_glib_borrow(element)) {
Ok(()) => true,
Err(err) => {
err.log_with_object(&*wrap);

View file

@ -9,51 +9,54 @@
use glib_sys;
use gst_sys;
use glib::translate::*;
use glib::prelude::*;
use glib::subclass::prelude::*;
use glib::translate::*;
use Device;
use DeviceProvider;
use LoggableError;
pub trait DeviceProviderImpl: DeviceProviderImplExt + ObjectImpl + Send + Sync {
fn probe(&self, device_provider: &DeviceProvider) -> Vec<Device> {
fn probe(&self, device_provider: &Self::Type) -> Vec<Device> {
self.parent_probe(device_provider)
}
fn start(&self, device_provider: &DeviceProvider) -> Result<(), LoggableError> {
fn start(&self, device_provider: &Self::Type) -> Result<(), LoggableError> {
self.parent_start(device_provider)
}
fn stop(&self, device_provider: &DeviceProvider) {
fn stop(&self, device_provider: &Self::Type) {
self.parent_stop(device_provider)
}
}
pub trait DeviceProviderImplExt {
fn parent_probe(&self, device_provider: &DeviceProvider) -> Vec<Device>;
pub trait DeviceProviderImplExt: ObjectSubclass {
fn parent_probe(&self, device_provider: &Self::Type) -> Vec<Device>;
fn parent_start(&self, device_provider: &DeviceProvider) -> Result<(), LoggableError>;
fn parent_start(&self, device_provider: &Self::Type) -> Result<(), LoggableError>;
fn parent_stop(&self, device_provider: &DeviceProvider);
fn parent_stop(&self, device_provider: &Self::Type);
}
impl<T: DeviceProviderImpl> DeviceProviderImplExt for T {
fn parent_probe(&self, device_provider: &DeviceProvider) -> Vec<Device> {
fn parent_probe(&self, device_provider: &Self::Type) -> Vec<Device> {
unsafe {
let data = T::type_data();
let parent_class =
data.as_ref().get_parent_class() as *mut gst_sys::GstDeviceProviderClass;
if let Some(f) = (*parent_class).probe {
FromGlibPtrContainer::from_glib_full(f(device_provider.to_glib_none().0))
FromGlibPtrContainer::from_glib_full(f(device_provider
.unsafe_cast_ref::<DeviceProvider>()
.to_glib_none()
.0))
} else {
Vec::new()
}
}
}
fn parent_start(&self, device_provider: &DeviceProvider) -> Result<(), LoggableError> {
fn parent_start(&self, device_provider: &Self::Type) -> Result<(), LoggableError> {
unsafe {
let data = T::type_data();
let parent_class =
@ -62,20 +65,26 @@ impl<T: DeviceProviderImpl> DeviceProviderImplExt for T {
gst_loggable_error!(::CAT_RUST, "Parent function `start` is not defined")
})?;
gst_result_from_gboolean!(
f(device_provider.to_glib_none().0),
f(device_provider
.unsafe_cast_ref::<DeviceProvider>()
.to_glib_none()
.0),
::CAT_RUST,
"Failed to start the device provider using the parent function"
)
}
}
fn parent_stop(&self, device_provider: &DeviceProvider) {
fn parent_stop(&self, device_provider: &Self::Type) {
unsafe {
let data = T::type_data();
let parent_class =
data.as_ref().get_parent_class() as *mut gst_sys::GstDeviceProviderClass;
if let Some(f) = (*parent_class).stop {
f(device_provider.to_glib_none().0);
f(device_provider
.unsafe_cast_ref::<DeviceProvider>()
.to_glib_none()
.0);
}
}
}
@ -130,7 +139,7 @@ unsafe extern "C" fn device_provider_probe<T: DeviceProviderImpl>(
let imp = instance.get_impl();
let wrap: Borrowed<DeviceProvider> = from_glib_borrow(ptr);
imp.probe(&wrap).to_glib_full()
imp.probe(wrap.unsafe_cast_ref()).to_glib_full()
}
unsafe extern "C" fn device_provider_start<T: DeviceProviderImpl>(
@ -140,7 +149,7 @@ unsafe extern "C" fn device_provider_start<T: DeviceProviderImpl>(
let imp = instance.get_impl();
let wrap: Borrowed<DeviceProvider> = from_glib_borrow(ptr);
match imp.start(&wrap) {
match imp.start(wrap.unsafe_cast_ref()) {
Ok(()) => true,
Err(err) => {
err.log_with_object(&*wrap);
@ -157,5 +166,5 @@ unsafe extern "C" fn device_provider_stop<T: DeviceProviderImpl>(
let imp = instance.get_impl();
let wrap: Borrowed<DeviceProvider> = from_glib_borrow(ptr);
imp.stop(&wrap);
imp.stop(wrap.unsafe_cast_ref());
}

View file

@ -30,7 +30,7 @@ use StateChangeSuccess;
pub trait ElementImpl: ElementImplExt + ObjectImpl + Send + Sync {
fn change_state(
&self,
element: &::Element,
element: &Self::Type,
transition: StateChange,
) -> Result<StateChangeSuccess, StateChangeError> {
self.parent_change_state(element, transition)
@ -38,7 +38,7 @@ pub trait ElementImpl: ElementImplExt + ObjectImpl + Send + Sync {
fn request_new_pad(
&self,
element: &::Element,
element: &Self::Type,
templ: &::PadTemplate,
name: Option<String>,
caps: Option<&::Caps>,
@ -46,77 +46,72 @@ pub trait ElementImpl: ElementImplExt + ObjectImpl + Send + Sync {
self.parent_request_new_pad(element, templ, name, caps)
}
fn release_pad(&self, element: &::Element, pad: &::Pad) {
fn release_pad(&self, element: &Self::Type, pad: &::Pad) {
self.parent_release_pad(element, pad)
}
fn send_event(&self, element: &::Element, event: Event) -> bool {
fn send_event(&self, element: &Self::Type, event: Event) -> bool {
self.parent_send_event(element, event)
}
fn query(&self, element: &::Element, query: &mut QueryRef) -> bool {
fn query(&self, element: &Self::Type, query: &mut QueryRef) -> bool {
self.parent_query(element, query)
}
fn set_context(&self, element: &::Element, context: &::Context) {
fn set_context(&self, element: &Self::Type, context: &::Context) {
self.parent_set_context(element, context)
}
fn set_clock(&self, element: &::Element, clock: Option<&::Clock>) -> bool {
fn set_clock(&self, element: &Self::Type, clock: Option<&::Clock>) -> bool {
self.parent_set_clock(element, clock)
}
fn provide_clock(&self, element: &::Element) -> Option<::Clock> {
fn provide_clock(&self, element: &Self::Type) -> Option<::Clock> {
self.parent_provide_clock(element)
}
fn post_message(&self, element: &::Element, msg: ::Message) -> bool {
fn post_message(&self, element: &Self::Type, msg: ::Message) -> bool {
self.parent_post_message(element, msg)
}
}
pub trait ElementImplExt {
pub trait ElementImplExt: ObjectSubclass {
fn parent_change_state(
&self,
element: &::Element,
element: &Self::Type,
transition: StateChange,
) -> Result<StateChangeSuccess, StateChangeError>;
fn parent_request_new_pad(
&self,
element: &::Element,
element: &Self::Type,
templ: &::PadTemplate,
name: Option<String>,
caps: Option<&::Caps>,
) -> Option<::Pad>;
fn parent_release_pad(&self, element: &::Element, pad: &::Pad);
fn parent_release_pad(&self, element: &Self::Type, pad: &::Pad);
fn parent_send_event(&self, element: &::Element, event: Event) -> bool;
fn parent_send_event(&self, element: &Self::Type, event: Event) -> bool;
fn parent_query(&self, element: &::Element, query: &mut QueryRef) -> bool;
fn parent_query(&self, element: &Self::Type, query: &mut QueryRef) -> bool;
fn parent_set_context(&self, element: &::Element, context: &::Context);
fn parent_set_context(&self, element: &Self::Type, context: &::Context);
fn parent_set_clock(&self, element: &::Element, clock: Option<&::Clock>) -> bool;
fn parent_set_clock(&self, element: &Self::Type, clock: Option<&::Clock>) -> bool;
fn parent_provide_clock(&self, element: &::Element) -> Option<::Clock>;
fn parent_provide_clock(&self, element: &Self::Type) -> Option<::Clock>;
fn parent_post_message(&self, element: &::Element, msg: ::Message) -> bool;
fn parent_post_message(&self, element: &Self::Type, msg: ::Message) -> bool;
fn catch_panic<
R,
F: FnOnce(&Self) -> R,
G: FnOnce() -> R,
P: IsA<::Element> + IsA<glib::Object> + glib::value::SetValue,
>(
fn catch_panic<R, F: FnOnce(&Self) -> R, G: FnOnce() -> R, P: IsA<Element>>(
&self,
element: &P,
fallback: G,
f: F,
) -> R;
fn catch_panic_pad_function<R, F: FnOnce(&Self, &::Element) -> R, G: FnOnce() -> R>(
fn catch_panic_pad_function<R, F: FnOnce(&Self, &Self::Type) -> R, G: FnOnce() -> R>(
parent: Option<&::Object>,
fallback: G,
f: F,
@ -129,7 +124,7 @@ where
{
fn parent_change_state(
&self,
element: &::Element,
element: &Self::Type,
transition: StateChange,
) -> Result<StateChangeSuccess, StateChangeError> {
unsafe {
@ -139,14 +134,17 @@ where
let f = (*parent_class)
.change_state
.expect("Missing parent function `change_state`");
StateChangeReturn::from_glib(f(element.to_glib_none().0, transition.to_glib()))
.into_result()
StateChangeReturn::from_glib(f(
element.unsafe_cast_ref::<Element>().to_glib_none().0,
transition.to_glib(),
))
.into_result()
}
}
fn parent_request_new_pad(
&self,
element: &::Element,
element: &Self::Type,
templ: &::PadTemplate,
name: Option<String>,
caps: Option<&::Caps>,
@ -159,7 +157,7 @@ where
.request_new_pad
.map(|f| {
from_glib_none(f(
element.to_glib_none().0,
element.unsafe_cast_ref::<Element>().to_glib_none().0,
templ.to_glib_none().0,
name.to_glib_full(),
caps.to_glib_none().0,
@ -169,97 +167,120 @@ where
}
}
fn parent_release_pad(&self, element: &::Element, pad: &::Pad) {
fn parent_release_pad(&self, element: &Self::Type, pad: &::Pad) {
unsafe {
let data = T::type_data();
let parent_class = data.as_ref().get_parent_class() as *mut gst_sys::GstElementClass;
(*parent_class)
.release_pad
.map(|f| f(element.to_glib_none().0, pad.to_glib_none().0))
.map(|f| {
f(
element.unsafe_cast_ref::<Element>().to_glib_none().0,
pad.to_glib_none().0,
)
})
.unwrap_or(())
}
}
fn parent_send_event(&self, element: &::Element, event: Event) -> bool {
fn parent_send_event(&self, element: &Self::Type, event: Event) -> bool {
unsafe {
let data = T::type_data();
let parent_class = data.as_ref().get_parent_class() as *mut gst_sys::GstElementClass;
(*parent_class)
.send_event
.map(|f| from_glib(f(element.to_glib_none().0, event.into_ptr())))
.map(|f| {
from_glib(f(
element.unsafe_cast_ref::<Element>().to_glib_none().0,
event.into_ptr(),
))
})
.unwrap_or(false)
}
}
fn parent_query(&self, element: &::Element, query: &mut QueryRef) -> bool {
fn parent_query(&self, element: &Self::Type, query: &mut QueryRef) -> bool {
unsafe {
let data = T::type_data();
let parent_class = data.as_ref().get_parent_class() as *mut gst_sys::GstElementClass;
(*parent_class)
.query
.map(|f| from_glib(f(element.to_glib_none().0, query.as_mut_ptr())))
.map(|f| {
from_glib(f(
element.unsafe_cast_ref::<Element>().to_glib_none().0,
query.as_mut_ptr(),
))
})
.unwrap_or(false)
}
}
fn parent_set_context(&self, element: &::Element, context: &::Context) {
fn parent_set_context(&self, element: &Self::Type, context: &::Context) {
unsafe {
let data = T::type_data();
let parent_class = data.as_ref().get_parent_class() as *mut gst_sys::GstElementClass;
(*parent_class)
.set_context
.map(|f| f(element.to_glib_none().0, context.to_glib_none().0))
.map(|f| {
f(
element.unsafe_cast_ref::<Element>().to_glib_none().0,
context.to_glib_none().0,
)
})
.unwrap_or(())
}
}
fn parent_set_clock(&self, element: &::Element, clock: Option<&::Clock>) -> bool {
fn parent_set_clock(&self, element: &Self::Type, clock: Option<&::Clock>) -> bool {
unsafe {
let data = T::type_data();
let parent_class = data.as_ref().get_parent_class() as *mut gst_sys::GstElementClass;
(*parent_class)
.set_clock
.map(|f| from_glib(f(element.to_glib_none().0, clock.to_glib_none().0)))
.map(|f| {
from_glib(f(
element.unsafe_cast_ref::<Element>().to_glib_none().0,
clock.to_glib_none().0,
))
})
.unwrap_or(false)
}
}
fn parent_provide_clock(&self, element: &::Element) -> Option<::Clock> {
fn parent_provide_clock(&self, element: &Self::Type) -> Option<::Clock> {
unsafe {
let data = T::type_data();
let parent_class = data.as_ref().get_parent_class() as *mut gst_sys::GstElementClass;
(*parent_class)
.provide_clock
.map(|f| from_glib_none(f(element.to_glib_none().0)))
.map(|f| from_glib_none(f(element.unsafe_cast_ref::<Element>().to_glib_none().0)))
.unwrap_or(None)
}
}
fn parent_post_message(&self, element: &::Element, msg: ::Message) -> bool {
fn parent_post_message(&self, element: &Self::Type, msg: ::Message) -> bool {
unsafe {
let data = T::type_data();
let parent_class = data.as_ref().get_parent_class() as *mut gst_sys::GstElementClass;
if let Some(f) = (*parent_class).post_message {
from_glib(f(element.to_glib_none().0, msg.into_ptr()))
from_glib(f(
element.unsafe_cast_ref::<Element>().to_glib_none().0,
msg.into_ptr(),
))
} else {
false
}
}
}
fn catch_panic<
R,
F: FnOnce(&Self) -> R,
G: FnOnce() -> R,
P: IsA<::Element> + IsA<glib::Object> + glib::value::SetValue,
>(
fn catch_panic<R, F: FnOnce(&Self) -> R, G: FnOnce() -> R, P: IsA<Element>>(
&self,
element: &P,
fallback: G,
@ -275,23 +296,21 @@ where
}
}
fn catch_panic_pad_function<R, F: FnOnce(&Self, &::Element) -> R, G: FnOnce() -> R>(
fn catch_panic_pad_function<R, F: FnOnce(&Self, &Self::Type) -> R, G: FnOnce() -> R>(
parent: Option<&::Object>,
fallback: G,
f: F,
) -> R {
unsafe {
let wrap = parent
.as_ref()
.unwrap()
.downcast_ref::<::Element>()
.unwrap();
let wrap = parent.as_ref().unwrap().downcast_ref::<Element>().unwrap();
assert!(wrap.get_type().is_a(&T::get_type()));
let ptr: *mut gst_sys::GstElement = wrap.to_glib_none().0;
let instance = &*(ptr as *mut T::Instance);
let imp = instance.get_impl();
gst_panic_to_error!(wrap, &instance.panicked(), fallback(), { f(&imp, &wrap) })
gst_panic_to_error!(wrap, &instance.panicked(), fallback(), {
f(&imp, wrap.unsafe_cast_ref())
})
}
}
}
@ -378,7 +397,7 @@ where
};
gst_panic_to_error!(&wrap, &instance.panicked(), fallback, {
imp.change_state(&wrap, transition).into()
imp.change_state(wrap.unsafe_cast_ref(), transition).into()
})
.to_glib()
}
@ -402,7 +421,7 @@ where
// See https://bugzilla.gnome.org/show_bug.cgi?id=791193
let pad = gst_panic_to_error!(&wrap, &instance.panicked(), None, {
imp.request_new_pad(
&wrap,
wrap.unsafe_cast_ref(),
&from_glib_borrow(templ),
from_glib_none(name),
caps.as_ref().as_ref(),
@ -437,7 +456,7 @@ unsafe extern "C" fn element_release_pad<T: ElementImpl>(
}
gst_panic_to_error!(&wrap, &instance.panicked(), (), {
imp.release_pad(&wrap, &from_glib_none(pad))
imp.release_pad(wrap.unsafe_cast_ref(), &from_glib_none(pad))
})
}
@ -453,7 +472,7 @@ where
let wrap: Borrowed<Element> = from_glib_borrow(ptr);
gst_panic_to_error!(&wrap, &instance.panicked(), false, {
imp.send_event(&wrap, from_glib_full(event))
imp.send_event(wrap.unsafe_cast_ref(), from_glib_full(event))
})
.to_glib()
}
@ -471,7 +490,7 @@ where
let query = QueryRef::from_mut_ptr(query);
gst_panic_to_error!(&wrap, &instance.panicked(), false, {
imp.query(&wrap, query)
imp.query(wrap.unsafe_cast_ref(), query)
})
.to_glib()
}
@ -487,7 +506,7 @@ unsafe extern "C" fn element_set_context<T: ElementImpl>(
let wrap: Borrowed<Element> = from_glib_borrow(ptr);
gst_panic_to_error!(&wrap, &instance.panicked(), (), {
imp.set_context(&wrap, &from_glib_borrow(context))
imp.set_context(wrap.unsafe_cast_ref(), &from_glib_borrow(context))
})
}
@ -505,7 +524,7 @@ where
let clock = Option::<::Clock>::from_glib_borrow(clock);
gst_panic_to_error!(&wrap, &instance.panicked(), false, {
imp.set_clock(&wrap, clock.as_ref().as_ref())
imp.set_clock(wrap.unsafe_cast_ref(), clock.as_ref().as_ref())
})
.to_glib()
}
@ -521,7 +540,7 @@ where
let wrap: Borrowed<Element> = from_glib_borrow(ptr);
gst_panic_to_error!(&wrap, &instance.panicked(), None, {
imp.provide_clock(&wrap)
imp.provide_clock(wrap.unsafe_cast_ref())
})
.to_glib_full()
}
@ -539,7 +558,8 @@ where
// Can't catch panics here as posting the error message would cause
// this code to be called again recursively forever.
imp.post_message(&wrap, from_glib_full(msg)).to_glib()
imp.post_message(wrap.unsafe_cast_ref(), from_glib_full(msg))
.to_glib()
}
#[cfg(test)]
@ -549,6 +569,8 @@ mod tests {
use glib::subclass;
use std::sync::atomic;
use ElementFactory;
pub mod imp {
use super::*;
@ -563,34 +585,44 @@ mod tests {
fn sink_chain(
&self,
_pad: &::Pad,
_element: &::Element,
_element: &super::TestElement,
buffer: ::Buffer,
) -> Result<::FlowSuccess, ::FlowError> {
self.n_buffers.fetch_add(1, atomic::Ordering::SeqCst);
self.srcpad.push(buffer)
}
fn sink_event(&self, _pad: &::Pad, _element: &::Element, event: ::Event) -> bool {
fn sink_event(
&self,
_pad: &::Pad,
_element: &super::TestElement,
event: ::Event,
) -> bool {
self.srcpad.push_event(event)
}
fn sink_query(
&self,
_pad: &::Pad,
_element: &::Element,
_element: &super::TestElement,
query: &mut ::QueryRef,
) -> bool {
self.srcpad.peer_query(query)
}
fn src_event(&self, _pad: &::Pad, _element: &::Element, event: ::Event) -> bool {
fn src_event(
&self,
_pad: &::Pad,
_element: &super::TestElement,
event: ::Event,
) -> bool {
self.sinkpad.push_event(event)
}
fn src_query(
&self,
_pad: &::Pad,
_element: &::Element,
_element: &super::TestElement,
query: &mut ::QueryRef,
) -> bool {
self.sinkpad.peer_query(query)
@ -600,13 +632,13 @@ mod tests {
impl ObjectSubclass for TestElement {
const NAME: &'static str = "TestElement";
type Type = super::TestElement;
type ParentType = ::Element;
type ParentType = Element;
type Instance = ::subclass::ElementInstanceStruct<Self>;
type Class = subclass::simple::ClassStruct<Self>;
glib_object_subclass!();
fn with_class(klass: &subclass::simple::ClassStruct<Self>) -> Self {
fn with_class(klass: &Self::Class) -> Self {
let templ = klass.get_pad_template("sink").unwrap();
let sinkpad = ::Pad::builder_with_template(&templ, Some("sink"))
.chain_function(|pad, parent, buffer| {
@ -658,7 +690,7 @@ mod tests {
}
}
fn class_init(klass: &mut subclass::simple::ClassStruct<Self>) {
fn class_init(klass: &mut Self::Class) {
klass.set_metadata(
"Test Element",
"Generic",
@ -691,7 +723,7 @@ mod tests {
impl ElementImpl for TestElement {
fn change_state(
&self,
element: &::Element,
element: &Self::Type,
transition: ::StateChange,
) -> Result<::StateChangeSuccess, ::StateChangeError> {
let res = self.parent_change_state(element, transition)?;
@ -706,7 +738,7 @@ mod tests {
}
glib_wrapper! {
pub struct TestElement(ObjectSubclass<imp::TestElement>) @extends ::Element, ::Object;
pub struct TestElement(ObjectSubclass<imp::TestElement>) @extends Element, ::Object;
}
unsafe impl Send for TestElement {}
@ -735,15 +767,15 @@ mod tests {
);
let pipeline = ::Pipeline::new(None);
let src = ::ElementFactory::make("fakesrc", None).unwrap();
let sink = ::ElementFactory::make("fakesink", None).unwrap();
let src = ElementFactory::make("fakesrc", None).unwrap();
let sink = ElementFactory::make("fakesink", None).unwrap();
src.set_property("num-buffers", &100i32).unwrap();
pipeline
.add_many(&[&src, &element.upcast_ref(), &sink])
.unwrap();
::Element::link_many(&[&src, &element.upcast_ref(), &sink]).unwrap();
Element::link_many(&[&src, &element.upcast_ref(), &sink]).unwrap();
pipeline.set_state(::State::Playing).unwrap();
let bus = pipeline.get_bus().unwrap();

View file

@ -9,49 +9,59 @@
use gst_sys;
use glib;
use glib::translate::*;
use glib::prelude::*;
use glib::subclass::prelude::*;
use glib::translate::*;
use Pad;
pub trait PadImpl: PadImplExt + ObjectImpl + Send + Sync {
fn linked(&self, pad: &Pad, peer: &Pad) {
fn linked(&self, pad: &Self::Type, peer: &Pad) {
self.parent_linked(pad, peer)
}
fn unlinked(&self, pad: &Pad, peer: &Pad) {
fn unlinked(&self, pad: &Self::Type, peer: &Pad) {
self.parent_unlinked(pad, peer)
}
}
pub trait PadImplExt {
fn parent_linked(&self, pad: &Pad, peer: &Pad);
pub trait PadImplExt: ObjectSubclass {
fn parent_linked(&self, pad: &Self::Type, peer: &Pad);
fn parent_unlinked(&self, pad: &Pad, peer: &Pad);
fn parent_unlinked(&self, pad: &Self::Type, peer: &Pad);
}
impl<T: PadImpl> PadImplExt for T {
fn parent_linked(&self, pad: &Pad, peer: &Pad) {
fn parent_linked(&self, pad: &Self::Type, peer: &Pad) {
unsafe {
let data = T::type_data();
let parent_class = data.as_ref().get_parent_class() as *mut gst_sys::GstPadClass;
(*parent_class)
.linked
.map(|f| f(pad.to_glib_none().0, peer.to_glib_none().0))
.map(|f| {
f(
pad.unsafe_cast_ref::<Pad>().to_glib_none().0,
peer.to_glib_none().0,
)
})
.unwrap_or(())
}
}
fn parent_unlinked(&self, pad: &Pad, peer: &Pad) {
fn parent_unlinked(&self, pad: &Self::Type, peer: &Pad) {
unsafe {
let data = T::type_data();
let parent_class = data.as_ref().get_parent_class() as *mut gst_sys::GstPadClass;
(*parent_class)
.unlinked
.map(|f| f(pad.to_glib_none().0, peer.to_glib_none().0))
.map(|f| {
f(
pad.unsafe_cast_ref::<Pad>().to_glib_none().0,
peer.to_glib_none().0,
)
})
.unwrap_or(())
}
}
@ -71,7 +81,7 @@ unsafe extern "C" fn pad_linked<T: PadImpl>(ptr: *mut gst_sys::GstPad, peer: *mu
let imp = instance.get_impl();
let wrap: Borrowed<Pad> = from_glib_borrow(ptr);
imp.linked(&wrap, &from_glib_borrow(peer))
imp.linked(wrap.unsafe_cast_ref(), &from_glib_borrow(peer))
}
unsafe extern "C" fn pad_unlinked<T: PadImpl>(
@ -82,7 +92,7 @@ unsafe extern "C" fn pad_unlinked<T: PadImpl>(
let imp = instance.get_impl();
let wrap: Borrowed<Pad> = from_glib_borrow(ptr);
imp.unlinked(&wrap, &from_glib_borrow(peer))
imp.unlinked(wrap.unsafe_cast_ref(), &from_glib_borrow(peer))
}
#[cfg(test)]
@ -93,6 +103,8 @@ mod tests {
use glib::subclass;
use std::sync::atomic;
use PadDirection;
pub mod imp {
use super::*;
@ -104,7 +116,7 @@ mod tests {
impl ObjectSubclass for TestPad {
const NAME: &'static str = "TestPad";
type Type = super::TestPad;
type ParentType = ::Pad;
type ParentType = Pad;
type Instance = subclass::simple::InstanceStruct<Self>;
type Class = subclass::simple::ClassStruct<Self>;
@ -121,12 +133,12 @@ mod tests {
impl ObjectImpl for TestPad {}
impl PadImpl for TestPad {
fn linked(&self, pad: &Pad, peer: &Pad) {
fn linked(&self, pad: &Self::Type, peer: &Pad) {
self.linked.store(true, atomic::Ordering::SeqCst);
self.parent_linked(pad, peer)
}
fn unlinked(&self, pad: &Pad, peer: &Pad) {
fn unlinked(&self, pad: &Self::Type, peer: &Pad) {
self.unlinked.store(true, atomic::Ordering::SeqCst);
self.parent_unlinked(pad, peer)
}
@ -134,14 +146,14 @@ mod tests {
}
glib_wrapper! {
pub struct TestPad(ObjectSubclass<imp::TestPad>) @extends ::Pad, ::Object;
pub struct TestPad(ObjectSubclass<imp::TestPad>) @extends Pad, ::Object;
}
unsafe impl Send for TestPad {}
unsafe impl Sync for TestPad {}
impl TestPad {
pub fn new(name: &str, direction: ::PadDirection) -> Self {
pub fn new(name: &str, direction: PadDirection) -> Self {
glib::Object::new(
TestPad::static_type(),
&[("name", &name), ("direction", &direction)],
@ -156,11 +168,11 @@ mod tests {
fn test_pad_subclass() {
::init().unwrap();
let pad = TestPad::new("test", ::PadDirection::Src);
let pad = TestPad::new("test", PadDirection::Src);
assert_eq!(pad.get_name(), "test");
let otherpad = ::Pad::new(Some("other-test"), ::PadDirection::Sink);
let otherpad = Pad::new(Some("other-test"), PadDirection::Sink);
pad.link(&otherpad).unwrap();
pad.unlink(&otherpad).unwrap();

View file

@ -21,8 +21,8 @@ use URIHandler;
use URIType;
pub trait URIHandlerImpl: super::element::ElementImpl {
fn get_uri(&self, element: &URIHandler) -> Option<String>;
fn set_uri(&self, element: &URIHandler, uri: &str) -> Result<(), glib::Error>;
fn get_uri(&self, element: &Self::Type) -> Option<String>;
fn set_uri(&self, element: &Self::Type, uri: &str) -> Result<(), glib::Error>;
fn get_uri_type() -> URIType;
fn get_protocols() -> Vec<String>;
}
@ -72,7 +72,8 @@ unsafe extern "C" fn uri_handler_get_uri<T: URIHandlerImpl>(
let instance = &*(uri_handler as *mut T::Instance);
let imp = instance.get_impl();
imp.get_uri(&from_glib_borrow(uri_handler)).to_glib_full()
imp.get_uri(&from_glib_borrow::<_, URIHandler>(uri_handler).unsafe_cast_ref())
.to_glib_full()
}
unsafe extern "C" fn uri_handler_set_uri<T: URIHandlerImpl>(
@ -84,7 +85,7 @@ unsafe extern "C" fn uri_handler_set_uri<T: URIHandlerImpl>(
let imp = instance.get_impl();
match imp.set_uri(
&from_glib_borrow(uri_handler),
&from_glib_borrow::<_, URIHandler>(uri_handler).unsafe_cast_ref(),
glib::GString::from_glib_borrow(uri).as_str(),
) {
Ok(()) => true.to_glib(),