diff --git a/gstreamer/src/subclass/bin.rs b/gstreamer/src/subclass/bin.rs index 51b51f309..19d1e4762 100644 --- a/gstreamer/src/subclass/bin.rs +++ b/gstreamer/src/subclass/bin.rs @@ -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 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 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 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 = 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( let wrap: Borrowed = 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)) }); } diff --git a/gstreamer/src/subclass/child_proxy.rs b/gstreamer/src/subclass/child_proxy.rs index 853f5eab0..072fafa48 100644 --- a/gstreamer/src/subclass/child_proxy.rs +++ b/gstreamer/src/subclass/child_proxy.rs @@ -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 { + fn get_child_by_name(&self, object: &Self::Type, name: &str) -> Option { 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::().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; - fn get_children_count(&self, object: &ChildProxy) -> u32; + fn get_child_by_index(&self, object: &Self::Type, index: u32) -> Option; + 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 IsImplementable for ChildProxy { @@ -67,7 +68,7 @@ unsafe extern "C" fn child_proxy_get_child_by_name( 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( 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( @@ -90,7 +94,7 @@ unsafe extern "C" fn child_proxy_get_children_count( 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( @@ -102,7 +106,7 @@ unsafe extern "C" fn child_proxy_child_added( 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( 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), ) diff --git a/gstreamer/src/subclass/clock.rs b/gstreamer/src/subclass/clock.rs index 96133252b..cb01d1abc 100644 --- a/gstreamer/src/subclass/clock.rs +++ b/gstreamer/src/subclass/clock.rs @@ -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, ClockTimeDiff) { self.parent_wait(clock, id) } - fn wait_async(&self, clock: &Clock, id: &ClockId) -> Result { + fn wait_async(&self, clock: &Self::Type, id: &ClockId) -> Result { 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, ClockTimeDiff); - fn parent_wait_async(&self, clock: &Clock, id: &ClockId) -> Result; + fn parent_wait_async( + &self, + clock: &Self::Type, + id: &ClockId, + ) -> Result; - 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 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 ClockImplExt for T { if let Some(func) = (*parent_class).change_resolution { from_glib(func( - clock.to_glib_none().0, + clock.unsafe_cast_ref::().to_glib_none().0, old_resolution.to_glib(), new_resolution.to_glib(), )) @@ -107,7 +111,7 @@ impl 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 ClockImplExt for T { from_glib( (*parent_class) .get_resolution - .map(|f| f(clock.to_glib_none().0)) + .map(|f| f(clock.unsafe_cast_ref::().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 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::().to_glib_none().0)) .unwrap_or(0), ) } @@ -137,7 +141,7 @@ impl ClockImplExt for T { fn parent_wait( &self, - clock: &Clock, + clock: &Self::Type, id: &ClockId, ) -> (Result, ClockTimeDiff) { unsafe { @@ -151,7 +155,7 @@ impl ClockImplExt for T { .wait .map(|f| { f( - clock.to_glib_none().0, + clock.unsafe_cast_ref::().to_glib_none().0, id.to_glib_none().0 as *mut gst_sys::GstClockEntry, &mut jitter, ) @@ -164,7 +168,11 @@ impl ClockImplExt for T { } } - fn parent_wait_async(&self, clock: &Clock, id: &ClockId) -> Result { + fn parent_wait_async( + &self, + clock: &Self::Type, + id: &ClockId, + ) -> Result { 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 ClockImplExt for T { .wait_async .map(|f| { f( - clock.to_glib_none().0, + clock.unsafe_cast_ref::().to_glib_none().0, id.to_glib_none().0 as *mut gst_sys::GstClockEntry, ) }) @@ -183,13 +191,13 @@ impl 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::().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( let imp = instance.get_impl(); let wrap: Borrowed = 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( @@ -265,7 +277,7 @@ unsafe extern "C" fn clock_get_resolution( let imp = instance.get_impl(); let wrap: Borrowed = 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( @@ -275,7 +287,7 @@ unsafe extern "C" fn clock_get_internal_time( let imp = instance.get_impl(); let wrap: Borrowed = 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( @@ -287,7 +299,10 @@ unsafe extern "C" fn clock_wait( let imp = instance.get_impl(); let wrap: Borrowed = 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( let imp = instance.get_impl(); let wrap: Borrowed = 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( @@ -314,5 +333,8 @@ unsafe extern "C" fn clock_unschedule( let imp = instance.get_impl(); let wrap: Borrowed = 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), + ); } diff --git a/gstreamer/src/subclass/device.rs b/gstreamer/src/subclass/device.rs index 383dac0b8..25ba9c599 100644 --- a/gstreamer/src/subclass/device.rs +++ b/gstreamer/src/subclass/device.rs @@ -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 { 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; fn parent_reconfigure_element( &self, - device: &Device, + device: &Self::Type, element: &Element, ) -> Result<(), LoggableError>; } @@ -50,14 +54,17 @@ pub trait DeviceImplExt { impl DeviceImplExt for T { fn parent_create_element( &self, - device: &Device, + device: &Self::Type, name: Option<&str>, ) -> Result { 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::().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 DeviceImplExt for T { fn parent_reconfigure_element( &self, - device: &Device, + device: &Self::Type, element: &Element, ) -> Result<(), LoggableError> { unsafe { @@ -90,7 +97,10 @@ impl DeviceImplExt for T { ) })?; gst_result_from_gboolean!( - f(device.to_glib_none().0, element.to_glib_none().0), + f( + device.unsafe_cast_ref::().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( let wrap: Borrowed = from_glib_borrow(ptr); match imp.create_element( - &wrap, + wrap.unsafe_cast_ref(), Option::::from_glib_borrow(name) .as_ref() .as_ref() @@ -146,7 +156,7 @@ unsafe extern "C" fn device_reconfigure_element( let imp = instance.get_impl(); let wrap: Borrowed = 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); diff --git a/gstreamer/src/subclass/device_provider.rs b/gstreamer/src/subclass/device_provider.rs index 111193483..9b2e86584 100644 --- a/gstreamer/src/subclass/device_provider.rs +++ b/gstreamer/src/subclass/device_provider.rs @@ -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 { + fn probe(&self, device_provider: &Self::Type) -> Vec { 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; +pub trait DeviceProviderImplExt: ObjectSubclass { + fn parent_probe(&self, device_provider: &Self::Type) -> Vec; - 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 DeviceProviderImplExt for T { - fn parent_probe(&self, device_provider: &DeviceProvider) -> Vec { + fn parent_probe(&self, device_provider: &Self::Type) -> Vec { 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::() + .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 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::() + .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::() + .to_glib_none() + .0); } } } @@ -130,7 +139,7 @@ unsafe extern "C" fn device_provider_probe( let imp = instance.get_impl(); let wrap: Borrowed = 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( @@ -140,7 +149,7 @@ unsafe extern "C" fn device_provider_start( let imp = instance.get_impl(); let wrap: Borrowed = 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( let imp = instance.get_impl(); let wrap: Borrowed = from_glib_borrow(ptr); - imp.stop(&wrap); + imp.stop(wrap.unsafe_cast_ref()); } diff --git a/gstreamer/src/subclass/element.rs b/gstreamer/src/subclass/element.rs index df2997cc7..5ce19b3fb 100644 --- a/gstreamer/src/subclass/element.rs +++ b/gstreamer/src/subclass/element.rs @@ -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 { 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, 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; fn parent_request_new_pad( &self, - element: &::Element, + element: &Self::Type, templ: &::PadTemplate, name: Option, 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::value::SetValue, - >( + fn catch_panic R, G: FnOnce() -> R, P: IsA>( &self, element: &P, fallback: G, f: F, ) -> R; - fn catch_panic_pad_function R, G: FnOnce() -> R>( + fn catch_panic_pad_function 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 { 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::().to_glib_none().0, + transition.to_glib(), + )) + .into_result() } } fn parent_request_new_pad( &self, - element: &::Element, + element: &Self::Type, templ: &::PadTemplate, name: Option, 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::().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::().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::().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::().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::().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::().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::().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::().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::value::SetValue, - >( + fn catch_panic R, G: FnOnce() -> R, P: IsA>( &self, element: &P, fallback: G, @@ -275,23 +296,21 @@ where } } - fn catch_panic_pad_function R, G: FnOnce() -> R>( + fn catch_panic_pad_function 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::().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( } 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 = 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( let wrap: Borrowed = 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 = 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; type Class = subclass::simple::ClassStruct; glib_object_subclass!(); - fn with_class(klass: &subclass::simple::ClassStruct) -> 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) { + 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) @extends ::Element, ::Object; + pub struct TestElement(ObjectSubclass) @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(); diff --git a/gstreamer/src/subclass/pad.rs b/gstreamer/src/subclass/pad.rs index 89629ed6a..133659407 100644 --- a/gstreamer/src/subclass/pad.rs +++ b/gstreamer/src/subclass/pad.rs @@ -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 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::().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::().to_glib_none().0, + peer.to_glib_none().0, + ) + }) .unwrap_or(()) } } @@ -71,7 +81,7 @@ unsafe extern "C" fn pad_linked(ptr: *mut gst_sys::GstPad, peer: *mu let imp = instance.get_impl(); let wrap: Borrowed = 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( @@ -82,7 +92,7 @@ unsafe extern "C" fn pad_unlinked( let imp = instance.get_impl(); let wrap: Borrowed = 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; type Class = subclass::simple::ClassStruct; @@ -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) @extends ::Pad, ::Object; + pub struct TestPad(ObjectSubclass) @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(); diff --git a/gstreamer/src/subclass/uri_handler.rs b/gstreamer/src/subclass/uri_handler.rs index d37c66da8..27620e9a3 100644 --- a/gstreamer/src/subclass/uri_handler.rs +++ b/gstreamer/src/subclass/uri_handler.rs @@ -21,8 +21,8 @@ use URIHandler; use URIType; pub trait URIHandlerImpl: super::element::ElementImpl { - fn get_uri(&self, element: &URIHandler) -> Option; - fn set_uri(&self, element: &URIHandler, uri: &str) -> Result<(), glib::Error>; + fn get_uri(&self, element: &Self::Type) -> Option; + fn set_uri(&self, element: &Self::Type, uri: &str) -> Result<(), glib::Error>; fn get_uri_type() -> URIType; fn get_protocols() -> Vec; } @@ -72,7 +72,8 @@ unsafe extern "C" fn uri_handler_get_uri( 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( @@ -84,7 +85,7 @@ unsafe extern "C" fn uri_handler_set_uri( 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(),