diff --git a/examples/src/bin/rtsp-server-subclass.rs b/examples/src/bin/rtsp-server-subclass.rs index c4f646050..2229b5327 100644 --- a/examples/src/bin/rtsp-server-subclass.rs +++ b/examples/src/bin/rtsp-server-subclass.rs @@ -129,7 +129,7 @@ mod media_factory { impl RTSPMediaFactoryImpl for Factory { fn create_element( &self, - _factory: &gst_rtsp_server::RTSPMediaFactory, + _factory: &Self::Type, _url: &gst_rtsp::RTSPUrl, ) -> Option { // Create a simple VP8 videotestsrc input @@ -218,7 +218,7 @@ mod media { impl RTSPMediaImpl for Media { fn setup_sdp( &self, - media: &gst_rtsp_server::RTSPMedia, + media: &Self::Type, sdp: &mut gst_sdp::SDPMessageRef, info: &gst_rtsp_server::subclass::SDPInfo, ) -> Result<(), gst::LoggableError> { @@ -284,10 +284,7 @@ mod server { // Implementation of gst_rtsp_server::RTSPServer virtual methods impl RTSPServerImpl for Server { - fn create_client( - &self, - server: &gst_rtsp_server::RTSPServer, - ) -> Option { + fn create_client(&self, server: &Self::Type) -> Option { let client = super::client::Client::default(); // Duplicated from the default implementation @@ -299,11 +296,7 @@ mod server { Some(client.upcast()) } - fn client_connected( - &self, - server: &gst_rtsp_server::RTSPServer, - client: &gst_rtsp_server::RTSPClient, - ) { + fn client_connected(&self, server: &Self::Type, client: &gst_rtsp_server::RTSPClient) { self.parent_client_connected(server, client); println!("Client {:?} connected", client); } @@ -372,7 +365,7 @@ mod client { // Implementation of gst_rtsp_server::RTSPClient virtual methods impl RTSPClientImpl for Client { - fn closed(&self, client: &gst_rtsp_server::RTSPClient) { + fn closed(&self, client: &Self::Type) { self.parent_closed(client); println!("Client {:?} closed", client); } diff --git a/gstreamer-rtsp-server/src/subclass/rtsp_client.rs b/gstreamer-rtsp-server/src/subclass/rtsp_client.rs index 3263c185b..820716cb2 100644 --- a/gstreamer-rtsp-server/src/subclass/rtsp_client.rs +++ b/gstreamer-rtsp-server/src/subclass/rtsp_client.rs @@ -8,6 +8,7 @@ use gst_rtsp_server_sys; +use glib::prelude::*; use glib::subclass::prelude::*; use glib::translate::*; @@ -16,13 +17,13 @@ use std::mem; use RTSPClient; pub trait RTSPClientImpl: RTSPClientImplExt + ObjectImpl + Send + Sync { - fn create_sdp(&self, client: &RTSPClient, media: &::RTSPMedia) -> Option { + fn create_sdp(&self, client: &Self::Type, media: &::RTSPMedia) -> Option { self.parent_create_sdp(client, media) } fn configure_client_media( &self, - client: &RTSPClient, + client: &Self::Type, media: &::RTSPMedia, stream: &::RTSPStream, ctx: &::RTSPContext, @@ -32,71 +33,71 @@ pub trait RTSPClientImpl: RTSPClientImplExt + ObjectImpl + Send + Sync { // TODO: configure_client_transport - fn params_set(&self, client: &RTSPClient, ctx: &::RTSPContext) -> gst_rtsp::RTSPResult { + fn params_set(&self, client: &Self::Type, ctx: &::RTSPContext) -> gst_rtsp::RTSPResult { self.parent_params_set(client, ctx) } - fn params_get(&self, client: &RTSPClient, ctx: &::RTSPContext) -> gst_rtsp::RTSPResult { + fn params_get(&self, client: &Self::Type, ctx: &::RTSPContext) -> gst_rtsp::RTSPResult { self.parent_params_get(client, ctx) } fn make_path_from_uri( &self, - client: &RTSPClient, + client: &Self::Type, url: &gst_rtsp::RTSPUrl, ) -> Option { self.parent_make_path_from_uri(client, url) } - fn closed(&self, client: &RTSPClient) { + fn closed(&self, client: &Self::Type) { self.parent_closed(client); } - fn new_session(&self, client: &RTSPClient, session: &::RTSPSession) { + fn new_session(&self, client: &Self::Type, session: &::RTSPSession) { self.parent_new_session(client, session); } - fn options_request(&self, client: &RTSPClient, ctx: &::RTSPContext) { + fn options_request(&self, client: &Self::Type, ctx: &::RTSPContext) { self.parent_options_request(client, ctx); } - fn describe_request(&self, client: &RTSPClient, ctx: &::RTSPContext) { + fn describe_request(&self, client: &Self::Type, ctx: &::RTSPContext) { self.parent_describe_request(client, ctx); } - fn setup_request(&self, client: &RTSPClient, ctx: &::RTSPContext) { + fn setup_request(&self, client: &Self::Type, ctx: &::RTSPContext) { self.parent_setup_request(client, ctx); } - fn play_request(&self, client: &RTSPClient, ctx: &::RTSPContext) { + fn play_request(&self, client: &Self::Type, ctx: &::RTSPContext) { self.parent_play_request(client, ctx); } - fn pause_request(&self, client: &RTSPClient, ctx: &::RTSPContext) { + fn pause_request(&self, client: &Self::Type, ctx: &::RTSPContext) { self.parent_pause_request(client, ctx); } - fn teardown_request(&self, client: &RTSPClient, ctx: &::RTSPContext) { + fn teardown_request(&self, client: &Self::Type, ctx: &::RTSPContext) { self.parent_teardown_request(client, ctx); } - fn set_parameter_request(&self, client: &RTSPClient, ctx: &::RTSPContext) { + fn set_parameter_request(&self, client: &Self::Type, ctx: &::RTSPContext) { self.parent_set_parameter_request(client, ctx); } - fn get_parameter_request(&self, client: &RTSPClient, ctx: &::RTSPContext) { + fn get_parameter_request(&self, client: &Self::Type, ctx: &::RTSPContext) { self.parent_get_parameter_request(client, ctx); } - fn announce_request(&self, client: &RTSPClient, ctx: &::RTSPContext) { + fn announce_request(&self, client: &Self::Type, ctx: &::RTSPContext) { self.parent_announce_request(client, ctx); } - fn record_request(&self, client: &RTSPClient, ctx: &::RTSPContext) { + fn record_request(&self, client: &Self::Type, ctx: &::RTSPContext) { self.parent_record_request(client, ctx); } - fn handle_response(&self, client: &RTSPClient, ctx: &::RTSPContext) { + fn handle_response(&self, client: &Self::Type, ctx: &::RTSPContext) { self.parent_handle_response(client, ctx); } @@ -105,7 +106,7 @@ pub trait RTSPClientImpl: RTSPClientImplExt + ObjectImpl + Send + Sync { fn handle_sdp( &self, - client: &RTSPClient, + client: &Self::Type, ctx: &::RTSPContext, media: &::RTSPMedia, sdp: &gst_sdp::SDPMessageRef, @@ -115,7 +116,7 @@ pub trait RTSPClientImpl: RTSPClientImplExt + ObjectImpl + Send + Sync { fn check_requirements( &self, - client: &RTSPClient, + client: &Self::Type, ctx: &::RTSPContext, arr: &[String], ) -> Option { @@ -124,7 +125,7 @@ pub trait RTSPClientImpl: RTSPClientImplExt + ObjectImpl + Send + Sync { fn pre_options_request( &self, - client: &RTSPClient, + client: &Self::Type, ctx: &::RTSPContext, ) -> gst_rtsp::RTSPStatusCode { self.parent_pre_options_request(client, ctx) @@ -132,7 +133,7 @@ pub trait RTSPClientImpl: RTSPClientImplExt + ObjectImpl + Send + Sync { fn pre_describe_request( &self, - client: &RTSPClient, + client: &Self::Type, ctx: &::RTSPContext, ) -> gst_rtsp::RTSPStatusCode { self.parent_pre_describe_request(client, ctx) @@ -140,7 +141,7 @@ pub trait RTSPClientImpl: RTSPClientImplExt + ObjectImpl + Send + Sync { fn pre_setup_request( &self, - client: &RTSPClient, + client: &Self::Type, ctx: &::RTSPContext, ) -> gst_rtsp::RTSPStatusCode { self.parent_pre_setup_request(client, ctx) @@ -148,7 +149,7 @@ pub trait RTSPClientImpl: RTSPClientImplExt + ObjectImpl + Send + Sync { fn pre_play_request( &self, - client: &RTSPClient, + client: &Self::Type, ctx: &::RTSPContext, ) -> gst_rtsp::RTSPStatusCode { self.parent_pre_play_request(client, ctx) @@ -156,7 +157,7 @@ pub trait RTSPClientImpl: RTSPClientImplExt + ObjectImpl + Send + Sync { fn pre_pause_request( &self, - client: &RTSPClient, + client: &Self::Type, ctx: &::RTSPContext, ) -> gst_rtsp::RTSPStatusCode { self.parent_pre_pause_request(client, ctx) @@ -164,7 +165,7 @@ pub trait RTSPClientImpl: RTSPClientImplExt + ObjectImpl + Send + Sync { fn pre_teardown_request( &self, - client: &RTSPClient, + client: &Self::Type, ctx: &::RTSPContext, ) -> gst_rtsp::RTSPStatusCode { self.parent_pre_teardown_request(client, ctx) @@ -172,7 +173,7 @@ pub trait RTSPClientImpl: RTSPClientImplExt + ObjectImpl + Send + Sync { fn pre_set_parameter_request( &self, - client: &RTSPClient, + client: &Self::Type, ctx: &::RTSPContext, ) -> gst_rtsp::RTSPStatusCode { self.parent_pre_set_parameter_request(client, ctx) @@ -180,7 +181,7 @@ pub trait RTSPClientImpl: RTSPClientImplExt + ObjectImpl + Send + Sync { fn pre_get_parameter_request( &self, - client: &RTSPClient, + client: &Self::Type, ctx: &::RTSPContext, ) -> gst_rtsp::RTSPStatusCode { self.parent_pre_get_parameter_request(client, ctx) @@ -188,7 +189,7 @@ pub trait RTSPClientImpl: RTSPClientImplExt + ObjectImpl + Send + Sync { fn pre_announce_request( &self, - client: &RTSPClient, + client: &Self::Type, ctx: &::RTSPContext, ) -> gst_rtsp::RTSPStatusCode { self.parent_pre_announce_request(client, ctx) @@ -196,23 +197,23 @@ pub trait RTSPClientImpl: RTSPClientImplExt + ObjectImpl + Send + Sync { fn pre_record_request( &self, - client: &RTSPClient, + client: &Self::Type, ctx: &::RTSPContext, ) -> gst_rtsp::RTSPStatusCode { self.parent_pre_record_request(client, ctx) } } -pub trait RTSPClientImplExt { +pub trait RTSPClientImplExt: ObjectSubclass { fn parent_create_sdp( &self, - client: &RTSPClient, + client: &Self::Type, media: &::RTSPMedia, ) -> Option; fn parent_configure_client_media( &self, - client: &RTSPClient, + client: &Self::Type, media: &::RTSPMedia, stream: &::RTSPStream, ctx: &::RTSPContext, @@ -220,48 +221,48 @@ pub trait RTSPClientImplExt { // TODO: configure_client_transport - fn parent_params_set(&self, client: &RTSPClient, ctx: &::RTSPContext) -> gst_rtsp::RTSPResult; + fn parent_params_set(&self, client: &Self::Type, ctx: &::RTSPContext) -> gst_rtsp::RTSPResult; - fn parent_params_get(&self, client: &RTSPClient, ctx: &::RTSPContext) -> gst_rtsp::RTSPResult; + fn parent_params_get(&self, client: &Self::Type, ctx: &::RTSPContext) -> gst_rtsp::RTSPResult; fn parent_make_path_from_uri( &self, - client: &RTSPClient, + client: &Self::Type, url: &gst_rtsp::RTSPUrl, ) -> Option; - fn parent_closed(&self, client: &RTSPClient); + fn parent_closed(&self, client: &Self::Type); - fn parent_new_session(&self, client: &RTSPClient, session: &::RTSPSession); + fn parent_new_session(&self, client: &Self::Type, session: &::RTSPSession); - fn parent_options_request(&self, client: &RTSPClient, ctx: &::RTSPContext); + fn parent_options_request(&self, client: &Self::Type, ctx: &::RTSPContext); - fn parent_describe_request(&self, client: &RTSPClient, ctx: &::RTSPContext); + fn parent_describe_request(&self, client: &Self::Type, ctx: &::RTSPContext); - fn parent_setup_request(&self, client: &RTSPClient, ctx: &::RTSPContext); + fn parent_setup_request(&self, client: &Self::Type, ctx: &::RTSPContext); - fn parent_play_request(&self, client: &RTSPClient, ctx: &::RTSPContext); + fn parent_play_request(&self, client: &Self::Type, ctx: &::RTSPContext); - fn parent_pause_request(&self, client: &RTSPClient, ctx: &::RTSPContext); + fn parent_pause_request(&self, client: &Self::Type, ctx: &::RTSPContext); - fn parent_teardown_request(&self, client: &RTSPClient, ctx: &::RTSPContext); + fn parent_teardown_request(&self, client: &Self::Type, ctx: &::RTSPContext); - fn parent_set_parameter_request(&self, client: &RTSPClient, ctx: &::RTSPContext); + fn parent_set_parameter_request(&self, client: &Self::Type, ctx: &::RTSPContext); - fn parent_get_parameter_request(&self, client: &RTSPClient, ctx: &::RTSPContext); + fn parent_get_parameter_request(&self, client: &Self::Type, ctx: &::RTSPContext); - fn parent_announce_request(&self, client: &RTSPClient, ctx: &::RTSPContext); + fn parent_announce_request(&self, client: &Self::Type, ctx: &::RTSPContext); - fn parent_record_request(&self, client: &RTSPClient, ctx: &::RTSPContext); + fn parent_record_request(&self, client: &Self::Type, ctx: &::RTSPContext); - fn parent_handle_response(&self, client: &RTSPClient, ctx: &::RTSPContext); + fn parent_handle_response(&self, client: &Self::Type, ctx: &::RTSPContext); // TODO: tunnel_http_response // TODO: send_message fn parent_handle_sdp( &self, - client: &RTSPClient, + client: &Self::Type, ctx: &::RTSPContext, media: &::RTSPMedia, sdp: &gst_sdp::SDPMessageRef, @@ -269,68 +270,68 @@ pub trait RTSPClientImplExt { fn parent_check_requirements( &self, - client: &RTSPClient, + client: &Self::Type, ctx: &::RTSPContext, arr: &[String], ) -> Option; fn parent_pre_options_request( &self, - client: &RTSPClient, + client: &Self::Type, ctx: &::RTSPContext, ) -> gst_rtsp::RTSPStatusCode; fn parent_pre_describe_request( &self, - client: &RTSPClient, + client: &Self::Type, ctx: &::RTSPContext, ) -> gst_rtsp::RTSPStatusCode; fn parent_pre_setup_request( &self, - client: &RTSPClient, + client: &Self::Type, ctx: &::RTSPContext, ) -> gst_rtsp::RTSPStatusCode; fn parent_pre_play_request( &self, - client: &RTSPClient, + client: &Self::Type, ctx: &::RTSPContext, ) -> gst_rtsp::RTSPStatusCode; fn parent_pre_pause_request( &self, - client: &RTSPClient, + client: &Self::Type, ctx: &::RTSPContext, ) -> gst_rtsp::RTSPStatusCode; fn parent_pre_teardown_request( &self, - client: &RTSPClient, + client: &Self::Type, ctx: &::RTSPContext, ) -> gst_rtsp::RTSPStatusCode; fn parent_pre_set_parameter_request( &self, - client: &RTSPClient, + client: &Self::Type, ctx: &::RTSPContext, ) -> gst_rtsp::RTSPStatusCode; fn parent_pre_get_parameter_request( &self, - client: &RTSPClient, + client: &Self::Type, ctx: &::RTSPContext, ) -> gst_rtsp::RTSPStatusCode; fn parent_pre_announce_request( &self, - client: &RTSPClient, + client: &Self::Type, ctx: &::RTSPContext, ) -> gst_rtsp::RTSPStatusCode; fn parent_pre_record_request( &self, - client: &RTSPClient, + client: &Self::Type, ctx: &::RTSPContext, ) -> gst_rtsp::RTSPStatusCode; } @@ -338,7 +339,7 @@ pub trait RTSPClientImplExt { impl RTSPClientImplExt for T { fn parent_create_sdp( &self, - client: &RTSPClient, + client: &Self::Type, media: &::RTSPMedia, ) -> Option { unsafe { @@ -349,13 +350,16 @@ impl RTSPClientImplExt for T { .create_sdp .expect("No `create_rtpbin` virtual method implementation in parent class"); - from_glib_full(f(client.to_glib_none().0, media.to_glib_none().0)) + from_glib_full(f( + client.unsafe_cast_ref::().to_glib_none().0, + media.to_glib_none().0, + )) } } fn parent_configure_client_media( &self, - client: &RTSPClient, + client: &Self::Type, media: &::RTSPMedia, stream: &::RTSPStream, ctx: &::RTSPContext, @@ -370,7 +374,7 @@ impl RTSPClientImplExt for T { gst_result_from_gboolean!( f( - client.to_glib_none().0, + client.unsafe_cast_ref::().to_glib_none().0, media.to_glib_none().0, stream.to_glib_none().0, ctx.to_glib_none().0 @@ -383,7 +387,7 @@ impl RTSPClientImplExt for T { // TODO: configure_client_transport - fn parent_params_set(&self, client: &RTSPClient, ctx: &::RTSPContext) -> gst_rtsp::RTSPResult { + fn parent_params_set(&self, client: &Self::Type, ctx: &::RTSPContext) -> gst_rtsp::RTSPResult { unsafe { let data = T::type_data(); let parent_class = @@ -392,11 +396,14 @@ impl RTSPClientImplExt for T { .params_set .expect("No `params_set` virtual method implementation in parent class"); - from_glib(f(client.to_glib_none().0, ctx.to_glib_none().0)) + from_glib(f( + client.unsafe_cast_ref::().to_glib_none().0, + ctx.to_glib_none().0, + )) } } - fn parent_params_get(&self, client: &RTSPClient, ctx: &::RTSPContext) -> gst_rtsp::RTSPResult { + fn parent_params_get(&self, client: &Self::Type, ctx: &::RTSPContext) -> gst_rtsp::RTSPResult { unsafe { let data = T::type_data(); let parent_class = @@ -405,13 +412,16 @@ impl RTSPClientImplExt for T { .params_get .expect("No `params_get` virtual method implementation in parent class"); - from_glib(f(client.to_glib_none().0, ctx.to_glib_none().0)) + from_glib(f( + client.unsafe_cast_ref::().to_glib_none().0, + ctx.to_glib_none().0, + )) } } fn parent_make_path_from_uri( &self, - client: &RTSPClient, + client: &Self::Type, url: &gst_rtsp::RTSPUrl, ) -> Option { unsafe { @@ -422,149 +432,188 @@ impl RTSPClientImplExt for T { .make_path_from_uri .expect("No `make_path_from_uri` virtual method implementation in parent class"); - from_glib_full(f(client.to_glib_none().0, url.to_glib_none().0)) + from_glib_full(f( + client.unsafe_cast_ref::().to_glib_none().0, + url.to_glib_none().0, + )) } } - fn parent_closed(&self, client: &RTSPClient) { + fn parent_closed(&self, client: &Self::Type) { unsafe { let data = T::type_data(); let parent_class = data.as_ref().get_parent_class() as *mut gst_rtsp_server_sys::GstRTSPClientClass; if let Some(f) = (*parent_class).closed { - f(client.to_glib_none().0); + f(client.unsafe_cast_ref::().to_glib_none().0); } } } - fn parent_new_session(&self, client: &RTSPClient, session: &::RTSPSession) { + fn parent_new_session(&self, client: &Self::Type, session: &::RTSPSession) { unsafe { let data = T::type_data(); let parent_class = data.as_ref().get_parent_class() as *mut gst_rtsp_server_sys::GstRTSPClientClass; if let Some(f) = (*parent_class).new_session { - f(client.to_glib_none().0, session.to_glib_none().0); + f( + client.unsafe_cast_ref::().to_glib_none().0, + session.to_glib_none().0, + ); } } } - fn parent_options_request(&self, client: &RTSPClient, ctx: &::RTSPContext) { + fn parent_options_request(&self, client: &Self::Type, ctx: &::RTSPContext) { unsafe { let data = T::type_data(); let parent_class = data.as_ref().get_parent_class() as *mut gst_rtsp_server_sys::GstRTSPClientClass; if let Some(f) = (*parent_class).options_request { - f(client.to_glib_none().0, ctx.to_glib_none().0); + f( + client.unsafe_cast_ref::().to_glib_none().0, + ctx.to_glib_none().0, + ); } } } - fn parent_describe_request(&self, client: &RTSPClient, ctx: &::RTSPContext) { + fn parent_describe_request(&self, client: &Self::Type, ctx: &::RTSPContext) { unsafe { let data = T::type_data(); let parent_class = data.as_ref().get_parent_class() as *mut gst_rtsp_server_sys::GstRTSPClientClass; if let Some(f) = (*parent_class).describe_request { - f(client.to_glib_none().0, ctx.to_glib_none().0); + f( + client.unsafe_cast_ref::().to_glib_none().0, + ctx.to_glib_none().0, + ); } } } - fn parent_setup_request(&self, client: &RTSPClient, ctx: &::RTSPContext) { + fn parent_setup_request(&self, client: &Self::Type, ctx: &::RTSPContext) { unsafe { let data = T::type_data(); let parent_class = data.as_ref().get_parent_class() as *mut gst_rtsp_server_sys::GstRTSPClientClass; if let Some(f) = (*parent_class).setup_request { - f(client.to_glib_none().0, ctx.to_glib_none().0); + f( + client.unsafe_cast_ref::().to_glib_none().0, + ctx.to_glib_none().0, + ); } } } - fn parent_play_request(&self, client: &RTSPClient, ctx: &::RTSPContext) { + fn parent_play_request(&self, client: &Self::Type, ctx: &::RTSPContext) { unsafe { let data = T::type_data(); let parent_class = data.as_ref().get_parent_class() as *mut gst_rtsp_server_sys::GstRTSPClientClass; if let Some(f) = (*parent_class).play_request { - f(client.to_glib_none().0, ctx.to_glib_none().0); + f( + client.unsafe_cast_ref::().to_glib_none().0, + ctx.to_glib_none().0, + ); } } } - fn parent_pause_request(&self, client: &RTSPClient, ctx: &::RTSPContext) { + fn parent_pause_request(&self, client: &Self::Type, ctx: &::RTSPContext) { unsafe { let data = T::type_data(); let parent_class = data.as_ref().get_parent_class() as *mut gst_rtsp_server_sys::GstRTSPClientClass; if let Some(f) = (*parent_class).pause_request { - f(client.to_glib_none().0, ctx.to_glib_none().0); + f( + client.unsafe_cast_ref::().to_glib_none().0, + ctx.to_glib_none().0, + ); } } } - fn parent_teardown_request(&self, client: &RTSPClient, ctx: &::RTSPContext) { + fn parent_teardown_request(&self, client: &Self::Type, ctx: &::RTSPContext) { unsafe { let data = T::type_data(); let parent_class = data.as_ref().get_parent_class() as *mut gst_rtsp_server_sys::GstRTSPClientClass; if let Some(f) = (*parent_class).teardown_request { - f(client.to_glib_none().0, ctx.to_glib_none().0); + f( + client.unsafe_cast_ref::().to_glib_none().0, + ctx.to_glib_none().0, + ); } } } - fn parent_set_parameter_request(&self, client: &RTSPClient, ctx: &::RTSPContext) { + fn parent_set_parameter_request(&self, client: &Self::Type, ctx: &::RTSPContext) { unsafe { let data = T::type_data(); let parent_class = data.as_ref().get_parent_class() as *mut gst_rtsp_server_sys::GstRTSPClientClass; if let Some(f) = (*parent_class).set_parameter_request { - f(client.to_glib_none().0, ctx.to_glib_none().0); + f( + client.unsafe_cast_ref::().to_glib_none().0, + ctx.to_glib_none().0, + ); } } } - fn parent_get_parameter_request(&self, client: &RTSPClient, ctx: &::RTSPContext) { + fn parent_get_parameter_request(&self, client: &Self::Type, ctx: &::RTSPContext) { unsafe { let data = T::type_data(); let parent_class = data.as_ref().get_parent_class() as *mut gst_rtsp_server_sys::GstRTSPClientClass; if let Some(f) = (*parent_class).get_parameter_request { - f(client.to_glib_none().0, ctx.to_glib_none().0); + f( + client.unsafe_cast_ref::().to_glib_none().0, + ctx.to_glib_none().0, + ); } } } - fn parent_announce_request(&self, client: &RTSPClient, ctx: &::RTSPContext) { + fn parent_announce_request(&self, client: &Self::Type, ctx: &::RTSPContext) { unsafe { let data = T::type_data(); let parent_class = data.as_ref().get_parent_class() as *mut gst_rtsp_server_sys::GstRTSPClientClass; if let Some(f) = (*parent_class).announce_request { - f(client.to_glib_none().0, ctx.to_glib_none().0); + f( + client.unsafe_cast_ref::().to_glib_none().0, + ctx.to_glib_none().0, + ); } } } - fn parent_record_request(&self, client: &RTSPClient, ctx: &::RTSPContext) { + fn parent_record_request(&self, client: &Self::Type, ctx: &::RTSPContext) { unsafe { let data = T::type_data(); let parent_class = data.as_ref().get_parent_class() as *mut gst_rtsp_server_sys::GstRTSPClientClass; if let Some(f) = (*parent_class).record_request { - f(client.to_glib_none().0, ctx.to_glib_none().0); + f( + client.unsafe_cast_ref::().to_glib_none().0, + ctx.to_glib_none().0, + ); } } } - fn parent_handle_response(&self, client: &RTSPClient, ctx: &::RTSPContext) { + fn parent_handle_response(&self, client: &Self::Type, ctx: &::RTSPContext) { unsafe { let data = T::type_data(); let parent_class = data.as_ref().get_parent_class() as *mut gst_rtsp_server_sys::GstRTSPClientClass; if let Some(f) = (*parent_class).handle_response { - f(client.to_glib_none().0, ctx.to_glib_none().0); + f( + client.unsafe_cast_ref::().to_glib_none().0, + ctx.to_glib_none().0, + ); } } } @@ -574,7 +623,7 @@ impl RTSPClientImplExt for T { fn parent_handle_sdp( &self, - client: &RTSPClient, + client: &Self::Type, ctx: &::RTSPContext, media: &::RTSPMedia, sdp: &gst_sdp::SDPMessageRef, @@ -589,7 +638,7 @@ impl RTSPClientImplExt for T { gst_result_from_gboolean!( f( - client.to_glib_none().0, + client.unsafe_cast_ref::().to_glib_none().0, ctx.to_glib_none().0, media.to_glib_none().0, sdp as *const _ as *mut _ @@ -602,7 +651,7 @@ impl RTSPClientImplExt for T { fn parent_check_requirements( &self, - client: &RTSPClient, + client: &Self::Type, ctx: &::RTSPContext, arr: &[String], ) -> Option { @@ -612,7 +661,7 @@ impl RTSPClientImplExt for T { data.as_ref().get_parent_class() as *mut gst_rtsp_server_sys::GstRTSPClientClass; if let Some(f) = (*parent_class).check_requirements { from_glib_full(f( - client.to_glib_none().0, + client.unsafe_cast_ref::().to_glib_none().0, ctx.to_glib_none().0, arr.to_glib_none().0, )) @@ -624,7 +673,7 @@ impl RTSPClientImplExt for T { fn parent_pre_options_request( &self, - client: &RTSPClient, + client: &Self::Type, ctx: &::RTSPContext, ) -> gst_rtsp::RTSPStatusCode { unsafe { @@ -632,7 +681,10 @@ impl RTSPClientImplExt for T { let parent_class = data.as_ref().get_parent_class() as *mut gst_rtsp_server_sys::GstRTSPClientClass; if let Some(f) = (*parent_class).pre_options_request { - from_glib(f(client.to_glib_none().0, ctx.to_glib_none().0)) + from_glib(f( + client.unsafe_cast_ref::().to_glib_none().0, + ctx.to_glib_none().0, + )) } else { gst_rtsp::RTSPStatusCode::Ok } @@ -641,7 +693,7 @@ impl RTSPClientImplExt for T { fn parent_pre_describe_request( &self, - client: &RTSPClient, + client: &Self::Type, ctx: &::RTSPContext, ) -> gst_rtsp::RTSPStatusCode { unsafe { @@ -649,7 +701,10 @@ impl RTSPClientImplExt for T { let parent_class = data.as_ref().get_parent_class() as *mut gst_rtsp_server_sys::GstRTSPClientClass; if let Some(f) = (*parent_class).pre_describe_request { - from_glib(f(client.to_glib_none().0, ctx.to_glib_none().0)) + from_glib(f( + client.unsafe_cast_ref::().to_glib_none().0, + ctx.to_glib_none().0, + )) } else { gst_rtsp::RTSPStatusCode::Ok } @@ -658,7 +713,7 @@ impl RTSPClientImplExt for T { fn parent_pre_setup_request( &self, - client: &RTSPClient, + client: &Self::Type, ctx: &::RTSPContext, ) -> gst_rtsp::RTSPStatusCode { unsafe { @@ -666,7 +721,10 @@ impl RTSPClientImplExt for T { let parent_class = data.as_ref().get_parent_class() as *mut gst_rtsp_server_sys::GstRTSPClientClass; if let Some(f) = (*parent_class).pre_setup_request { - from_glib(f(client.to_glib_none().0, ctx.to_glib_none().0)) + from_glib(f( + client.unsafe_cast_ref::().to_glib_none().0, + ctx.to_glib_none().0, + )) } else { gst_rtsp::RTSPStatusCode::Ok } @@ -675,7 +733,7 @@ impl RTSPClientImplExt for T { fn parent_pre_play_request( &self, - client: &RTSPClient, + client: &Self::Type, ctx: &::RTSPContext, ) -> gst_rtsp::RTSPStatusCode { unsafe { @@ -683,7 +741,10 @@ impl RTSPClientImplExt for T { let parent_class = data.as_ref().get_parent_class() as *mut gst_rtsp_server_sys::GstRTSPClientClass; if let Some(f) = (*parent_class).pre_play_request { - from_glib(f(client.to_glib_none().0, ctx.to_glib_none().0)) + from_glib(f( + client.unsafe_cast_ref::().to_glib_none().0, + ctx.to_glib_none().0, + )) } else { gst_rtsp::RTSPStatusCode::Ok } @@ -692,7 +753,7 @@ impl RTSPClientImplExt for T { fn parent_pre_pause_request( &self, - client: &RTSPClient, + client: &Self::Type, ctx: &::RTSPContext, ) -> gst_rtsp::RTSPStatusCode { unsafe { @@ -700,7 +761,10 @@ impl RTSPClientImplExt for T { let parent_class = data.as_ref().get_parent_class() as *mut gst_rtsp_server_sys::GstRTSPClientClass; if let Some(f) = (*parent_class).pre_pause_request { - from_glib(f(client.to_glib_none().0, ctx.to_glib_none().0)) + from_glib(f( + client.unsafe_cast_ref::().to_glib_none().0, + ctx.to_glib_none().0, + )) } else { gst_rtsp::RTSPStatusCode::Ok } @@ -709,7 +773,7 @@ impl RTSPClientImplExt for T { fn parent_pre_teardown_request( &self, - client: &RTSPClient, + client: &Self::Type, ctx: &::RTSPContext, ) -> gst_rtsp::RTSPStatusCode { unsafe { @@ -717,7 +781,10 @@ impl RTSPClientImplExt for T { let parent_class = data.as_ref().get_parent_class() as *mut gst_rtsp_server_sys::GstRTSPClientClass; if let Some(f) = (*parent_class).pre_teardown_request { - from_glib(f(client.to_glib_none().0, ctx.to_glib_none().0)) + from_glib(f( + client.unsafe_cast_ref::().to_glib_none().0, + ctx.to_glib_none().0, + )) } else { gst_rtsp::RTSPStatusCode::Ok } @@ -726,7 +793,7 @@ impl RTSPClientImplExt for T { fn parent_pre_set_parameter_request( &self, - client: &RTSPClient, + client: &Self::Type, ctx: &::RTSPContext, ) -> gst_rtsp::RTSPStatusCode { unsafe { @@ -734,7 +801,10 @@ impl RTSPClientImplExt for T { let parent_class = data.as_ref().get_parent_class() as *mut gst_rtsp_server_sys::GstRTSPClientClass; if let Some(f) = (*parent_class).pre_set_parameter_request { - from_glib(f(client.to_glib_none().0, ctx.to_glib_none().0)) + from_glib(f( + client.unsafe_cast_ref::().to_glib_none().0, + ctx.to_glib_none().0, + )) } else { gst_rtsp::RTSPStatusCode::Ok } @@ -743,7 +813,7 @@ impl RTSPClientImplExt for T { fn parent_pre_get_parameter_request( &self, - client: &RTSPClient, + client: &Self::Type, ctx: &::RTSPContext, ) -> gst_rtsp::RTSPStatusCode { unsafe { @@ -751,7 +821,10 @@ impl RTSPClientImplExt for T { let parent_class = data.as_ref().get_parent_class() as *mut gst_rtsp_server_sys::GstRTSPClientClass; if let Some(f) = (*parent_class).pre_get_parameter_request { - from_glib(f(client.to_glib_none().0, ctx.to_glib_none().0)) + from_glib(f( + client.unsafe_cast_ref::().to_glib_none().0, + ctx.to_glib_none().0, + )) } else { gst_rtsp::RTSPStatusCode::Ok } @@ -760,7 +833,7 @@ impl RTSPClientImplExt for T { fn parent_pre_announce_request( &self, - client: &RTSPClient, + client: &Self::Type, ctx: &::RTSPContext, ) -> gst_rtsp::RTSPStatusCode { unsafe { @@ -768,7 +841,10 @@ impl RTSPClientImplExt for T { let parent_class = data.as_ref().get_parent_class() as *mut gst_rtsp_server_sys::GstRTSPClientClass; if let Some(f) = (*parent_class).pre_announce_request { - from_glib(f(client.to_glib_none().0, ctx.to_glib_none().0)) + from_glib(f( + client.unsafe_cast_ref::().to_glib_none().0, + ctx.to_glib_none().0, + )) } else { gst_rtsp::RTSPStatusCode::Ok } @@ -777,7 +853,7 @@ impl RTSPClientImplExt for T { fn parent_pre_record_request( &self, - client: &RTSPClient, + client: &Self::Type, ctx: &::RTSPContext, ) -> gst_rtsp::RTSPStatusCode { unsafe { @@ -785,7 +861,10 @@ impl RTSPClientImplExt for T { let parent_class = data.as_ref().get_parent_class() as *mut gst_rtsp_server_sys::GstRTSPClientClass; if let Some(f) = (*parent_class).pre_record_request { - from_glib(f(client.to_glib_none().0, ctx.to_glib_none().0)) + from_glib(f( + client.unsafe_cast_ref::().to_glib_none().0, + ctx.to_glib_none().0, + )) } else { gst_rtsp::RTSPStatusCode::Ok } @@ -837,7 +916,8 @@ unsafe extern "C" fn client_create_sdp( let imp = instance.get_impl(); let wrap: Borrowed = from_glib_borrow(ptr); - let sdp = mem::ManuallyDrop::new(imp.create_sdp(&wrap, &from_glib_borrow(media))); + let sdp = + mem::ManuallyDrop::new(imp.create_sdp(wrap.unsafe_cast_ref(), &from_glib_borrow(media))); let ptr = sdp.to_glib_none().0; ptr as *mut _ @@ -854,7 +934,7 @@ unsafe extern "C" fn client_configure_client_media( let wrap: Borrowed = from_glib_borrow(ptr); match imp.configure_client_media( - &wrap, + wrap.unsafe_cast_ref(), &from_glib_borrow(media), &from_glib_borrow(stream), &from_glib_borrow(ctx), @@ -875,7 +955,8 @@ unsafe extern "C" fn client_params_set( let imp = instance.get_impl(); let wrap: Borrowed = from_glib_borrow(ptr); - imp.params_set(&wrap, &from_glib_borrow(ctx)).to_glib() + imp.params_set(wrap.unsafe_cast_ref(), &from_glib_borrow(ctx)) + .to_glib() } unsafe extern "C" fn client_params_get( @@ -886,7 +967,8 @@ unsafe extern "C" fn client_params_get( let imp = instance.get_impl(); let wrap: Borrowed = from_glib_borrow(ptr); - imp.params_get(&wrap, &from_glib_borrow(ctx)).to_glib() + imp.params_get(wrap.unsafe_cast_ref(), &from_glib_borrow(ctx)) + .to_glib() } unsafe extern "C" fn client_make_path_from_uri( @@ -897,7 +979,7 @@ unsafe extern "C" fn client_make_path_from_uri( let imp = instance.get_impl(); let wrap: Borrowed = from_glib_borrow(ptr); - imp.make_path_from_uri(&wrap, &from_glib_borrow(url)) + imp.make_path_from_uri(wrap.unsafe_cast_ref(), &from_glib_borrow(url)) .to_glib_full() } @@ -908,7 +990,7 @@ unsafe extern "C" fn client_closed( let imp = instance.get_impl(); let wrap: Borrowed = from_glib_borrow(ptr); - imp.closed(&wrap); + imp.closed(wrap.unsafe_cast_ref()); } unsafe extern "C" fn client_new_session( @@ -919,7 +1001,7 @@ unsafe extern "C" fn client_new_session( let imp = instance.get_impl(); let wrap: Borrowed = from_glib_borrow(ptr); - imp.new_session(&wrap, &from_glib_borrow(session)); + imp.new_session(wrap.unsafe_cast_ref(), &from_glib_borrow(session)); } unsafe extern "C" fn client_options_request( @@ -930,7 +1012,7 @@ unsafe extern "C" fn client_options_request( let imp = instance.get_impl(); let wrap: Borrowed = from_glib_borrow(ptr); - imp.options_request(&wrap, &from_glib_borrow(ctx)); + imp.options_request(wrap.unsafe_cast_ref(), &from_glib_borrow(ctx)); } unsafe extern "C" fn client_describe_request( @@ -941,7 +1023,7 @@ unsafe extern "C" fn client_describe_request( let imp = instance.get_impl(); let wrap: Borrowed = from_glib_borrow(ptr); - imp.describe_request(&wrap, &from_glib_borrow(ctx)); + imp.describe_request(wrap.unsafe_cast_ref(), &from_glib_borrow(ctx)); } unsafe extern "C" fn client_setup_request( @@ -952,7 +1034,7 @@ unsafe extern "C" fn client_setup_request( let imp = instance.get_impl(); let wrap: Borrowed = from_glib_borrow(ptr); - imp.setup_request(&wrap, &from_glib_borrow(ctx)); + imp.setup_request(wrap.unsafe_cast_ref(), &from_glib_borrow(ctx)); } unsafe extern "C" fn client_play_request( @@ -963,7 +1045,7 @@ unsafe extern "C" fn client_play_request( let imp = instance.get_impl(); let wrap: Borrowed = from_glib_borrow(ptr); - imp.play_request(&wrap, &from_glib_borrow(ctx)); + imp.play_request(wrap.unsafe_cast_ref(), &from_glib_borrow(ctx)); } unsafe extern "C" fn client_pause_request( @@ -974,7 +1056,7 @@ unsafe extern "C" fn client_pause_request( let imp = instance.get_impl(); let wrap: Borrowed = from_glib_borrow(ptr); - imp.pause_request(&wrap, &from_glib_borrow(ctx)); + imp.pause_request(wrap.unsafe_cast_ref(), &from_glib_borrow(ctx)); } unsafe extern "C" fn client_teardown_request( @@ -985,7 +1067,7 @@ unsafe extern "C" fn client_teardown_request( let imp = instance.get_impl(); let wrap: Borrowed = from_glib_borrow(ptr); - imp.teardown_request(&wrap, &from_glib_borrow(ctx)); + imp.teardown_request(wrap.unsafe_cast_ref(), &from_glib_borrow(ctx)); } unsafe extern "C" fn client_set_parameter_request( @@ -996,7 +1078,7 @@ unsafe extern "C" fn client_set_parameter_request( let imp = instance.get_impl(); let wrap: Borrowed = from_glib_borrow(ptr); - imp.set_parameter_request(&wrap, &from_glib_borrow(ctx)); + imp.set_parameter_request(wrap.unsafe_cast_ref(), &from_glib_borrow(ctx)); } unsafe extern "C" fn client_get_parameter_request( @@ -1007,7 +1089,7 @@ unsafe extern "C" fn client_get_parameter_request( let imp = instance.get_impl(); let wrap: Borrowed = from_glib_borrow(ptr); - imp.get_parameter_request(&wrap, &from_glib_borrow(ctx)); + imp.get_parameter_request(wrap.unsafe_cast_ref(), &from_glib_borrow(ctx)); } unsafe extern "C" fn client_announce_request( @@ -1018,7 +1100,7 @@ unsafe extern "C" fn client_announce_request( let imp = instance.get_impl(); let wrap: Borrowed = from_glib_borrow(ptr); - imp.announce_request(&wrap, &from_glib_borrow(ctx)); + imp.announce_request(wrap.unsafe_cast_ref(), &from_glib_borrow(ctx)); } unsafe extern "C" fn client_record_request( @@ -1029,7 +1111,7 @@ unsafe extern "C" fn client_record_request( let imp = instance.get_impl(); let wrap: Borrowed = from_glib_borrow(ptr); - imp.record_request(&wrap, &from_glib_borrow(ctx)); + imp.record_request(wrap.unsafe_cast_ref(), &from_glib_borrow(ctx)); } unsafe extern "C" fn client_handle_response( @@ -1040,7 +1122,7 @@ unsafe extern "C" fn client_handle_response( let imp = instance.get_impl(); let wrap: Borrowed = from_glib_borrow(ptr); - imp.handle_response(&wrap, &from_glib_borrow(ctx)); + imp.handle_response(wrap.unsafe_cast_ref(), &from_glib_borrow(ctx)); } unsafe extern "C" fn client_handle_sdp( @@ -1054,7 +1136,7 @@ unsafe extern "C" fn client_handle_sdp( let wrap: Borrowed = from_glib_borrow(ptr); match imp.handle_sdp( - &wrap, + wrap.unsafe_cast_ref(), &from_glib_borrow(ctx), &from_glib_borrow(media), &*(sdp as *mut _), @@ -1077,7 +1159,7 @@ unsafe extern "C" fn client_check_requirements( let wrap: Borrowed = from_glib_borrow(ptr); imp.check_requirements( - &wrap, + wrap.unsafe_cast_ref(), &from_glib_borrow(ctx), Vec::from_glib_none(arr).as_slice(), ) @@ -1092,7 +1174,7 @@ unsafe extern "C" fn client_pre_options_request( let imp = instance.get_impl(); let wrap: Borrowed = from_glib_borrow(ptr); - imp.pre_options_request(&wrap, &from_glib_borrow(ctx)) + imp.pre_options_request(wrap.unsafe_cast_ref(), &from_glib_borrow(ctx)) .to_glib() } @@ -1104,7 +1186,7 @@ unsafe extern "C" fn client_pre_describe_request( let imp = instance.get_impl(); let wrap: Borrowed = from_glib_borrow(ptr); - imp.pre_describe_request(&wrap, &from_glib_borrow(ctx)) + imp.pre_describe_request(wrap.unsafe_cast_ref(), &from_glib_borrow(ctx)) .to_glib() } @@ -1116,7 +1198,7 @@ unsafe extern "C" fn client_pre_setup_request( let imp = instance.get_impl(); let wrap: Borrowed = from_glib_borrow(ptr); - imp.pre_setup_request(&wrap, &from_glib_borrow(ctx)) + imp.pre_setup_request(wrap.unsafe_cast_ref(), &from_glib_borrow(ctx)) .to_glib() } @@ -1128,7 +1210,7 @@ unsafe extern "C" fn client_pre_play_request( let imp = instance.get_impl(); let wrap: Borrowed = from_glib_borrow(ptr); - imp.pre_play_request(&wrap, &from_glib_borrow(ctx)) + imp.pre_play_request(wrap.unsafe_cast_ref(), &from_glib_borrow(ctx)) .to_glib() } @@ -1140,7 +1222,7 @@ unsafe extern "C" fn client_pre_pause_request( let imp = instance.get_impl(); let wrap: Borrowed = from_glib_borrow(ptr); - imp.pre_pause_request(&wrap, &from_glib_borrow(ctx)) + imp.pre_pause_request(wrap.unsafe_cast_ref(), &from_glib_borrow(ctx)) .to_glib() } @@ -1152,7 +1234,7 @@ unsafe extern "C" fn client_pre_teardown_request( let imp = instance.get_impl(); let wrap: Borrowed = from_glib_borrow(ptr); - imp.pre_teardown_request(&wrap, &from_glib_borrow(ctx)) + imp.pre_teardown_request(wrap.unsafe_cast_ref(), &from_glib_borrow(ctx)) .to_glib() } @@ -1164,7 +1246,7 @@ unsafe extern "C" fn client_pre_set_parameter_request( let imp = instance.get_impl(); let wrap: Borrowed = from_glib_borrow(ptr); - imp.pre_set_parameter_request(&wrap, &from_glib_borrow(ctx)) + imp.pre_set_parameter_request(wrap.unsafe_cast_ref(), &from_glib_borrow(ctx)) .to_glib() } @@ -1176,7 +1258,7 @@ unsafe extern "C" fn client_pre_get_parameter_request( let imp = instance.get_impl(); let wrap: Borrowed = from_glib_borrow(ptr); - imp.pre_get_parameter_request(&wrap, &from_glib_borrow(ctx)) + imp.pre_get_parameter_request(wrap.unsafe_cast_ref(), &from_glib_borrow(ctx)) .to_glib() } @@ -1188,7 +1270,7 @@ unsafe extern "C" fn client_pre_announce_request( let imp = instance.get_impl(); let wrap: Borrowed = from_glib_borrow(ptr); - imp.pre_announce_request(&wrap, &from_glib_borrow(ctx)) + imp.pre_announce_request(wrap.unsafe_cast_ref(), &from_glib_borrow(ctx)) .to_glib() } @@ -1200,6 +1282,6 @@ unsafe extern "C" fn client_pre_record_request( let imp = instance.get_impl(); let wrap: Borrowed = from_glib_borrow(ptr); - imp.pre_record_request(&wrap, &from_glib_borrow(ctx)) + imp.pre_record_request(wrap.unsafe_cast_ref(), &from_glib_borrow(ctx)) .to_glib() } diff --git a/gstreamer-rtsp-server/src/subclass/rtsp_media.rs b/gstreamer-rtsp-server/src/subclass/rtsp_media.rs index eff908c51..179d717dd 100644 --- a/gstreamer-rtsp-server/src/subclass/rtsp_media.rs +++ b/gstreamer-rtsp-server/src/subclass/rtsp_media.rs @@ -8,6 +8,7 @@ use gst_rtsp_server_sys; +use glib::prelude::*; use glib::subclass::prelude::*; use glib::translate::*; @@ -33,43 +34,43 @@ impl SDPInfo { } pub trait RTSPMediaImpl: RTSPMediaImplExt + ObjectImpl + Send + Sync { - fn handle_message(&self, media: &RTSPMedia, message: &gst::MessageRef) -> bool { + fn handle_message(&self, media: &Self::Type, message: &gst::MessageRef) -> bool { self.parent_handle_message(media, message) } - fn prepare(&self, media: &RTSPMedia, thread: &RTSPThread) -> Result<(), gst::LoggableError> { + fn prepare(&self, media: &Self::Type, thread: &RTSPThread) -> Result<(), gst::LoggableError> { self.parent_prepare(media, thread) } - fn unprepare(&self, media: &RTSPMedia) -> Result<(), gst::LoggableError> { + fn unprepare(&self, media: &Self::Type) -> Result<(), gst::LoggableError> { self.parent_unprepare(media) } - fn suspend(&self, media: &RTSPMedia) -> Result<(), gst::LoggableError> { + fn suspend(&self, media: &Self::Type) -> Result<(), gst::LoggableError> { self.parent_suspend(media) } - fn unsuspend(&self, media: &RTSPMedia) -> Result<(), gst::LoggableError> { + fn unsuspend(&self, media: &Self::Type) -> Result<(), gst::LoggableError> { self.parent_unsuspend(media) } // TODO missing: convert_range - fn query_position(&self, media: &RTSPMedia) -> Option { + fn query_position(&self, media: &Self::Type) -> Option { self.parent_query_position(media) } - fn query_stop(&self, media: &RTSPMedia) -> Option { + fn query_stop(&self, media: &Self::Type) -> Option { self.parent_query_stop(media) } - fn create_rtpbin(&self, media: &RTSPMedia) -> Option { + fn create_rtpbin(&self, media: &Self::Type) -> Option { self.parent_create_rtpbin(media) } fn setup_rtpbin( &self, - media: &RTSPMedia, + media: &Self::Type, rtpbin: &gst::Element, ) -> Result<(), gst::LoggableError> { self.parent_setup_rtpbin(media, rtpbin) @@ -77,93 +78,96 @@ pub trait RTSPMediaImpl: RTSPMediaImplExt + ObjectImpl + Send + Sync { fn setup_sdp( &self, - media: &RTSPMedia, + media: &Self::Type, sdp: &mut gst_sdp::SDPMessageRef, info: &SDPInfo, ) -> Result<(), gst::LoggableError> { self.parent_setup_sdp(media, sdp, info) } - fn new_stream(&self, media: &RTSPMedia, stream: &::RTSPStream) { + fn new_stream(&self, media: &Self::Type, stream: &::RTSPStream) { self.parent_new_stream(media, stream); } - fn removed_stream(&self, media: &RTSPMedia, stream: &::RTSPStream) { + fn removed_stream(&self, media: &Self::Type, stream: &::RTSPStream) { self.parent_removed_stream(media, stream); } - fn prepared(&self, media: &RTSPMedia) { + fn prepared(&self, media: &Self::Type) { self.parent_prepared(media); } - fn unprepared(&self, media: &RTSPMedia) { + fn unprepared(&self, media: &Self::Type) { self.parent_unprepared(media); } - fn target_state(&self, media: &RTSPMedia, state: gst::State) { + fn target_state(&self, media: &Self::Type, state: gst::State) { self.parent_target_state(media, state); } - fn new_state(&self, media: &RTSPMedia, state: gst::State) { + fn new_state(&self, media: &Self::Type, state: gst::State) { self.parent_new_state(media, state); } fn handle_sdp( &self, - media: &RTSPMedia, + media: &Self::Type, sdp: &gst_sdp::SDPMessageRef, ) -> Result<(), gst::LoggableError> { self.parent_handle_sdp(media, sdp) } } -pub trait RTSPMediaImplExt { - fn parent_handle_message(&self, media: &RTSPMedia, message: &gst::MessageRef) -> bool; +pub trait RTSPMediaImplExt: ObjectSubclass { + fn parent_handle_message(&self, media: &Self::Type, message: &gst::MessageRef) -> bool; fn parent_prepare( &self, - media: &RTSPMedia, + media: &Self::Type, thread: &RTSPThread, ) -> Result<(), gst::LoggableError>; - fn parent_unprepare(&self, media: &RTSPMedia) -> Result<(), gst::LoggableError>; - fn parent_suspend(&self, media: &RTSPMedia) -> Result<(), gst::LoggableError>; - fn parent_unsuspend(&self, media: &RTSPMedia) -> Result<(), gst::LoggableError>; + fn parent_unprepare(&self, media: &Self::Type) -> Result<(), gst::LoggableError>; + fn parent_suspend(&self, media: &Self::Type) -> Result<(), gst::LoggableError>; + fn parent_unsuspend(&self, media: &Self::Type) -> Result<(), gst::LoggableError>; // TODO missing: convert_range - fn parent_query_position(&self, media: &RTSPMedia) -> Option; - fn parent_query_stop(&self, media: &RTSPMedia) -> Option; - fn parent_create_rtpbin(&self, media: &RTSPMedia) -> Option; + fn parent_query_position(&self, media: &Self::Type) -> Option; + fn parent_query_stop(&self, media: &Self::Type) -> Option; + fn parent_create_rtpbin(&self, media: &Self::Type) -> Option; fn parent_setup_rtpbin( &self, - media: &RTSPMedia, + media: &Self::Type, rtpbin: &gst::Element, ) -> Result<(), gst::LoggableError>; fn parent_setup_sdp( &self, - media: &RTSPMedia, + media: &Self::Type, sdp: &mut gst_sdp::SDPMessageRef, info: &SDPInfo, ) -> Result<(), gst::LoggableError>; - fn parent_new_stream(&self, media: &RTSPMedia, stream: &::RTSPStream); - fn parent_removed_stream(&self, media: &RTSPMedia, stream: &::RTSPStream); - fn parent_prepared(&self, media: &RTSPMedia); - fn parent_unprepared(&self, media: &RTSPMedia); - fn parent_target_state(&self, media: &RTSPMedia, state: gst::State); - fn parent_new_state(&self, media: &RTSPMedia, state: gst::State); + fn parent_new_stream(&self, media: &Self::Type, stream: &::RTSPStream); + fn parent_removed_stream(&self, media: &Self::Type, stream: &::RTSPStream); + fn parent_prepared(&self, media: &Self::Type); + fn parent_unprepared(&self, media: &Self::Type); + fn parent_target_state(&self, media: &Self::Type, state: gst::State); + fn parent_new_state(&self, media: &Self::Type, state: gst::State); fn parent_handle_sdp( &self, - media: &RTSPMedia, + media: &Self::Type, sdp: &gst_sdp::SDPMessageRef, ) -> Result<(), gst::LoggableError>; } impl RTSPMediaImplExt for T { - fn parent_handle_message(&self, media: &RTSPMedia, message: &gst::MessageRef) -> bool { + fn parent_handle_message(&self, media: &Self::Type, message: &gst::MessageRef) -> bool { unsafe { let data = T::type_data(); let parent_class = data.as_ref().get_parent_class() as *mut gst_rtsp_server_sys::GstRTSPMediaClass; if let Some(f) = (*parent_class).handle_message { - from_glib(f(media.to_glib_none().0, message.as_ptr() as *mut _)) + from_glib(f( + media.unsafe_cast_ref::().to_glib_none().0, + message.as_ptr() as *mut _, + )) } else { false } @@ -172,7 +176,7 @@ impl RTSPMediaImplExt for T { fn parent_prepare( &self, - media: &RTSPMedia, + media: &Self::Type, thread: &RTSPThread, ) -> Result<(), gst::LoggableError> { unsafe { @@ -181,7 +185,10 @@ impl RTSPMediaImplExt for T { data.as_ref().get_parent_class() as *mut gst_rtsp_server_sys::GstRTSPMediaClass; if let Some(f) = (*parent_class).prepare { gst_result_from_gboolean!( - f(media.to_glib_none().0, thread.to_glib_none().0), + f( + media.unsafe_cast_ref::().to_glib_none().0, + thread.to_glib_none().0 + ), gst::CAT_RUST, "Parent function `prepare` failed" ) @@ -191,14 +198,14 @@ impl RTSPMediaImplExt for T { } } - fn parent_unprepare(&self, media: &RTSPMedia) -> Result<(), gst::LoggableError> { + fn parent_unprepare(&self, media: &Self::Type) -> Result<(), gst::LoggableError> { unsafe { let data = T::type_data(); let parent_class = data.as_ref().get_parent_class() as *mut gst_rtsp_server_sys::GstRTSPMediaClass; if let Some(f) = (*parent_class).unprepare { gst_result_from_gboolean!( - f(media.to_glib_none().0), + f(media.unsafe_cast_ref::().to_glib_none().0), gst::CAT_RUST, "Parent function `unprepare` failed" ) @@ -208,14 +215,14 @@ impl RTSPMediaImplExt for T { } } - fn parent_suspend(&self, media: &RTSPMedia) -> Result<(), gst::LoggableError> { + fn parent_suspend(&self, media: &Self::Type) -> Result<(), gst::LoggableError> { unsafe { let data = T::type_data(); let parent_class = data.as_ref().get_parent_class() as *mut gst_rtsp_server_sys::GstRTSPMediaClass; if let Some(f) = (*parent_class).suspend { gst_result_from_gboolean!( - f(media.to_glib_none().0), + f(media.unsafe_cast_ref::().to_glib_none().0), gst::CAT_RUST, "Parent function `suspend` failed" ) @@ -225,14 +232,14 @@ impl RTSPMediaImplExt for T { } } - fn parent_unsuspend(&self, media: &RTSPMedia) -> Result<(), gst::LoggableError> { + fn parent_unsuspend(&self, media: &Self::Type) -> Result<(), gst::LoggableError> { unsafe { let data = T::type_data(); let parent_class = data.as_ref().get_parent_class() as *mut gst_rtsp_server_sys::GstRTSPMediaClass; if let Some(f) = (*parent_class).unsuspend { gst_result_from_gboolean!( - f(media.to_glib_none().0), + f(media.unsafe_cast_ref::().to_glib_none().0), gst::CAT_RUST, "Parent function `unsuspend` failed" ) @@ -244,7 +251,7 @@ impl RTSPMediaImplExt for T { // TODO missing: convert_range - fn parent_query_position(&self, media: &RTSPMedia) -> Option { + fn parent_query_position(&self, media: &Self::Type) -> Option { unsafe { use std::mem; @@ -253,7 +260,11 @@ impl RTSPMediaImplExt for T { data.as_ref().get_parent_class() as *mut gst_rtsp_server_sys::GstRTSPMediaClass; if let Some(f) = (*parent_class).query_position { let mut position = mem::MaybeUninit::uninit(); - if f(media.to_glib_none().0, position.as_mut_ptr()) == glib_sys::GFALSE { + if f( + media.unsafe_cast_ref::().to_glib_none().0, + position.as_mut_ptr(), + ) == glib_sys::GFALSE + { None } else { Some(from_glib(position.assume_init() as u64)) @@ -264,7 +275,7 @@ impl RTSPMediaImplExt for T { } } - fn parent_query_stop(&self, media: &RTSPMedia) -> Option { + fn parent_query_stop(&self, media: &Self::Type) -> Option { unsafe { use std::mem; @@ -273,7 +284,11 @@ impl RTSPMediaImplExt for T { data.as_ref().get_parent_class() as *mut gst_rtsp_server_sys::GstRTSPMediaClass; if let Some(f) = (*parent_class).query_stop { let mut stop = mem::MaybeUninit::uninit(); - if f(media.to_glib_none().0, stop.as_mut_ptr()) == glib_sys::GFALSE { + if f( + media.unsafe_cast_ref::().to_glib_none().0, + stop.as_mut_ptr(), + ) == glib_sys::GFALSE + { None } else { Some(from_glib(stop.assume_init() as u64)) @@ -284,7 +299,7 @@ impl RTSPMediaImplExt for T { } } - fn parent_create_rtpbin(&self, media: &RTSPMedia) -> Option { + fn parent_create_rtpbin(&self, media: &Self::Type) -> Option { unsafe { let data = T::type_data(); let parent_class = @@ -293,13 +308,13 @@ impl RTSPMediaImplExt for T { .create_rtpbin .expect("No `create_rtpbin` virtual method implementation in parent class"); - from_glib_none(f(media.to_glib_none().0)) + from_glib_none(f(media.unsafe_cast_ref::().to_glib_none().0)) } } fn parent_setup_rtpbin( &self, - media: &RTSPMedia, + media: &Self::Type, rtpbin: &gst::Element, ) -> Result<(), gst::LoggableError> { unsafe { @@ -313,7 +328,7 @@ impl RTSPMediaImplExt for T { gobject_sys::g_object_force_floating(ptr as *mut _); let res = gst_result_from_gboolean!( - f(media.to_glib_none().0, ptr), + f(media.unsafe_cast_ref::().to_glib_none().0, ptr), gst::CAT_RUST, "Parent function `setup_sdp` failed" ); @@ -334,7 +349,7 @@ impl RTSPMediaImplExt for T { fn parent_setup_sdp( &self, - media: &RTSPMedia, + media: &Self::Type, sdp: &mut gst_sdp::SDPMessageRef, info: &SDPInfo, ) -> Result<(), gst::LoggableError> { @@ -348,7 +363,7 @@ impl RTSPMediaImplExt for T { gst_result_from_gboolean!( f( - media.to_glib_none().0, + media.unsafe_cast_ref::().to_glib_none().0, sdp as *mut _ as *mut gst_sdp_sys::GstSDPMessage, info.0.as_ptr() ), @@ -358,75 +373,87 @@ impl RTSPMediaImplExt for T { } } - fn parent_new_stream(&self, media: &RTSPMedia, stream: &::RTSPStream) { + fn parent_new_stream(&self, media: &Self::Type, stream: &::RTSPStream) { unsafe { let data = T::type_data(); let parent_class = data.as_ref().get_parent_class() as *mut gst_rtsp_server_sys::GstRTSPMediaClass; if let Some(f) = (*parent_class).new_stream { - f(media.to_glib_none().0, stream.to_glib_none().0); + f( + media.unsafe_cast_ref::().to_glib_none().0, + stream.to_glib_none().0, + ); } } } - fn parent_removed_stream(&self, media: &RTSPMedia, stream: &::RTSPStream) { + fn parent_removed_stream(&self, media: &Self::Type, stream: &::RTSPStream) { unsafe { let data = T::type_data(); let parent_class = data.as_ref().get_parent_class() as *mut gst_rtsp_server_sys::GstRTSPMediaClass; if let Some(f) = (*parent_class).removed_stream { - f(media.to_glib_none().0, stream.to_glib_none().0); + f( + media.unsafe_cast_ref::().to_glib_none().0, + stream.to_glib_none().0, + ); } } } - fn parent_prepared(&self, media: &RTSPMedia) { + fn parent_prepared(&self, media: &Self::Type) { unsafe { let data = T::type_data(); let parent_class = data.as_ref().get_parent_class() as *mut gst_rtsp_server_sys::GstRTSPMediaClass; if let Some(f) = (*parent_class).prepared { - f(media.to_glib_none().0); + f(media.unsafe_cast_ref::().to_glib_none().0); } } } - fn parent_unprepared(&self, media: &RTSPMedia) { + fn parent_unprepared(&self, media: &Self::Type) { unsafe { let data = T::type_data(); let parent_class = data.as_ref().get_parent_class() as *mut gst_rtsp_server_sys::GstRTSPMediaClass; if let Some(f) = (*parent_class).unprepared { - f(media.to_glib_none().0); + f(media.unsafe_cast_ref::().to_glib_none().0); } } } - fn parent_target_state(&self, media: &RTSPMedia, state: gst::State) { + fn parent_target_state(&self, media: &Self::Type, state: gst::State) { unsafe { let data = T::type_data(); let parent_class = data.as_ref().get_parent_class() as *mut gst_rtsp_server_sys::GstRTSPMediaClass; if let Some(f) = (*parent_class).target_state { - f(media.to_glib_none().0, state.to_glib()); + f( + media.unsafe_cast_ref::().to_glib_none().0, + state.to_glib(), + ); } } } - fn parent_new_state(&self, media: &RTSPMedia, state: gst::State) { + fn parent_new_state(&self, media: &Self::Type, state: gst::State) { unsafe { let data = T::type_data(); let parent_class = data.as_ref().get_parent_class() as *mut gst_rtsp_server_sys::GstRTSPMediaClass; if let Some(f) = (*parent_class).new_state { - f(media.to_glib_none().0, state.to_glib()); + f( + media.unsafe_cast_ref::().to_glib_none().0, + state.to_glib(), + ); } } } fn parent_handle_sdp( &self, - media: &RTSPMedia, + media: &Self::Type, sdp: &gst_sdp::SDPMessageRef, ) -> Result<(), gst::LoggableError> { unsafe { @@ -439,7 +466,7 @@ impl RTSPMediaImplExt for T { gst_result_from_gboolean!( f( - media.to_glib_none().0, + media.unsafe_cast_ref::().to_glib_none().0, sdp as *const _ as *mut gst_sdp_sys::GstSDPMessage ), gst::CAT_RUST, @@ -480,7 +507,7 @@ unsafe extern "C" fn media_handle_message( let imp = instance.get_impl(); let wrap: Borrowed = from_glib_borrow(ptr); - imp.handle_message(&wrap, gst::MessageRef::from_ptr(message)) + imp.handle_message(wrap.unsafe_cast_ref(), gst::MessageRef::from_ptr(message)) .to_glib() } @@ -492,7 +519,7 @@ unsafe extern "C" fn media_prepare( let imp = instance.get_impl(); let wrap: Borrowed = from_glib_borrow(ptr); - match imp.prepare(&wrap, &from_glib_borrow(thread)) { + match imp.prepare(wrap.unsafe_cast_ref(), &from_glib_borrow(thread)) { Ok(()) => glib_sys::GTRUE, Err(err) => { err.log_with_object(&*wrap); @@ -508,7 +535,7 @@ unsafe extern "C" fn media_unprepare( let imp = instance.get_impl(); let wrap: Borrowed = from_glib_borrow(ptr); - match imp.unprepare(&wrap) { + match imp.unprepare(wrap.unsafe_cast_ref()) { Ok(()) => glib_sys::GTRUE, Err(err) => { err.log_with_object(&*wrap); @@ -524,7 +551,7 @@ unsafe extern "C" fn media_suspend( let imp = instance.get_impl(); let wrap: Borrowed = from_glib_borrow(ptr); - match imp.suspend(&wrap) { + match imp.suspend(wrap.unsafe_cast_ref()) { Ok(()) => glib_sys::GTRUE, Err(err) => { err.log_with_object(&*wrap); @@ -540,7 +567,7 @@ unsafe extern "C" fn media_unsuspend( let imp = instance.get_impl(); let wrap: Borrowed = from_glib_borrow(ptr); - match imp.unsuspend(&wrap) { + match imp.unsuspend(wrap.unsafe_cast_ref()) { Ok(()) => glib_sys::GTRUE, Err(err) => { err.log_with_object(&*wrap); @@ -557,7 +584,7 @@ unsafe extern "C" fn media_query_position( let imp = instance.get_impl(); let wrap: Borrowed = from_glib_borrow(ptr); - match imp.query_position(&wrap) { + match imp.query_position(wrap.unsafe_cast_ref()) { Some(pos) => { *position = pos.to_glib() as i64; glib_sys::GTRUE @@ -574,7 +601,7 @@ unsafe extern "C" fn media_query_stop( let imp = instance.get_impl(); let wrap: Borrowed = from_glib_borrow(ptr); - match imp.query_stop(&wrap) { + match imp.query_stop(wrap.unsafe_cast_ref()) { Some(s) => { *stop = s.to_glib() as i64; glib_sys::GTRUE @@ -590,7 +617,7 @@ unsafe extern "C" fn media_create_rtpbin( let imp = instance.get_impl(); let wrap: Borrowed = from_glib_borrow(ptr); - let res: *mut gst_sys::GstElement = imp.create_rtpbin(&wrap).to_glib_full(); + let res: *mut gst_sys::GstElement = imp.create_rtpbin(wrap.unsafe_cast_ref()).to_glib_full(); if !res.is_null() { gobject_sys::g_object_force_floating(res as *mut _); @@ -613,7 +640,7 @@ unsafe extern "C" fn media_setup_rtpbin( gobject_sys::g_object_ref_sink(rtpbin as *mut _); } - let res = match imp.setup_rtpbin(&wrap, &from_glib_borrow(rtpbin)) { + let res = match imp.setup_rtpbin(wrap.unsafe_cast_ref(), &from_glib_borrow(rtpbin)) { Ok(()) => glib_sys::GTRUE, Err(err) => { err.log_with_object(&*wrap); @@ -637,7 +664,7 @@ unsafe extern "C" fn media_setup_sdp( let wrap: Borrowed = from_glib_borrow(ptr); match imp.setup_sdp( - &wrap, + wrap.unsafe_cast_ref(), &mut *(sdp as *mut gst_sdp::SDPMessageRef), &SDPInfo(ptr::NonNull::new(info).expect("NULL SDPInfo")), ) { @@ -657,7 +684,7 @@ unsafe extern "C" fn media_new_stream( let imp = instance.get_impl(); let wrap: Borrowed = from_glib_borrow(ptr); - imp.new_stream(&wrap, &from_glib_borrow(stream)); + imp.new_stream(wrap.unsafe_cast_ref(), &from_glib_borrow(stream)); } unsafe extern "C" fn media_removed_stream( @@ -668,7 +695,7 @@ unsafe extern "C" fn media_removed_stream( let imp = instance.get_impl(); let wrap: Borrowed = from_glib_borrow(ptr); - imp.removed_stream(&wrap, &from_glib_borrow(stream)); + imp.removed_stream(wrap.unsafe_cast_ref(), &from_glib_borrow(stream)); } unsafe extern "C" fn media_prepared(ptr: *mut gst_rtsp_server_sys::GstRTSPMedia) { @@ -676,7 +703,7 @@ unsafe extern "C" fn media_prepared(ptr: *mut gst_rtsp_server_ let imp = instance.get_impl(); let wrap: Borrowed = from_glib_borrow(ptr); - imp.prepared(&wrap); + imp.prepared(wrap.unsafe_cast_ref()); } unsafe extern "C" fn media_unprepared( @@ -686,7 +713,7 @@ unsafe extern "C" fn media_unprepared( let imp = instance.get_impl(); let wrap: Borrowed = from_glib_borrow(ptr); - imp.unprepared(&wrap); + imp.unprepared(wrap.unsafe_cast_ref()); } unsafe extern "C" fn media_target_state( @@ -697,7 +724,7 @@ unsafe extern "C" fn media_target_state( let imp = instance.get_impl(); let wrap: Borrowed = from_glib_borrow(ptr); - imp.target_state(&wrap, from_glib(state)); + imp.target_state(wrap.unsafe_cast_ref(), from_glib(state)); } unsafe extern "C" fn media_new_state( @@ -708,7 +735,7 @@ unsafe extern "C" fn media_new_state( let imp = instance.get_impl(); let wrap: Borrowed = from_glib_borrow(ptr); - imp.new_state(&wrap, from_glib(state)); + imp.new_state(wrap.unsafe_cast_ref(), from_glib(state)); } unsafe extern "C" fn media_handle_sdp( @@ -719,7 +746,10 @@ unsafe extern "C" fn media_handle_sdp( let imp = instance.get_impl(); let wrap: Borrowed = from_glib_borrow(ptr); - match imp.handle_sdp(&wrap, &*(sdp as *const gst_sdp::SDPMessageRef)) { + match imp.handle_sdp( + wrap.unsafe_cast_ref(), + &*(sdp as *const gst_sdp::SDPMessageRef), + ) { Ok(()) => glib_sys::GTRUE, Err(err) => { err.log_with_object(&*wrap); diff --git a/gstreamer-rtsp-server/src/subclass/rtsp_media_factory.rs b/gstreamer-rtsp-server/src/subclass/rtsp_media_factory.rs index 8a1b6d877..29fc2b2ca 100644 --- a/gstreamer-rtsp-server/src/subclass/rtsp_media_factory.rs +++ b/gstreamer-rtsp-server/src/subclass/rtsp_media_factory.rs @@ -8,96 +8,85 @@ use gst_rtsp_server_sys; -use glib::translate::*; -use gst_rtsp; - +use glib::prelude::*; use glib::subclass::prelude::*; +use glib::translate::*; + +use gst_rtsp; use RTSPMediaFactory; use std::mem::transmute; pub trait RTSPMediaFactoryImpl: RTSPMediaFactoryImplExt + ObjectImpl + Send + Sync { - fn gen_key( - &self, - factory: &RTSPMediaFactory, - url: &gst_rtsp::RTSPUrl, - ) -> Option { + fn gen_key(&self, factory: &Self::Type, url: &gst_rtsp::RTSPUrl) -> Option { self.parent_gen_key(factory, url) } fn create_element( &self, - factory: &RTSPMediaFactory, + factory: &Self::Type, url: &gst_rtsp::RTSPUrl, ) -> Option { self.parent_create_element(factory, url) } - fn construct( - &self, - factory: &RTSPMediaFactory, - url: &gst_rtsp::RTSPUrl, - ) -> Option<::RTSPMedia> { + fn construct(&self, factory: &Self::Type, url: &gst_rtsp::RTSPUrl) -> Option<::RTSPMedia> { self.parent_construct(factory, url) } - fn create_pipeline( - &self, - factory: &RTSPMediaFactory, - media: &::RTSPMedia, - ) -> Option { + fn create_pipeline(&self, factory: &Self::Type, media: &::RTSPMedia) -> Option { self.parent_create_pipeline(factory, media) } - fn configure(&self, factory: &RTSPMediaFactory, media: &::RTSPMedia) { + fn configure(&self, factory: &Self::Type, media: &::RTSPMedia) { self.parent_configure(factory, media) } - fn media_constructed(&self, factory: &RTSPMediaFactory, media: &::RTSPMedia) { + fn media_constructed(&self, factory: &Self::Type, media: &::RTSPMedia) { self.parent_media_constructed(factory, media) } - fn media_configure(&self, factory: &RTSPMediaFactory, media: &::RTSPMedia) { + fn media_configure(&self, factory: &Self::Type, media: &::RTSPMedia) { self.parent_media_configure(factory, media) } } -pub trait RTSPMediaFactoryImplExt { +pub trait RTSPMediaFactoryImplExt: ObjectSubclass { fn parent_gen_key( &self, - factory: &RTSPMediaFactory, + factory: &Self::Type, url: &gst_rtsp::RTSPUrl, ) -> Option; fn parent_create_element( &self, - factory: &RTSPMediaFactory, + factory: &Self::Type, url: &gst_rtsp::RTSPUrl, ) -> Option; fn parent_construct( &self, - factory: &RTSPMediaFactory, + factory: &Self::Type, url: &gst_rtsp::RTSPUrl, ) -> Option<::RTSPMedia>; fn parent_create_pipeline( &self, - factory: &RTSPMediaFactory, + factory: &Self::Type, media: &::RTSPMedia, ) -> Option; - fn parent_configure(&self, factory: &RTSPMediaFactory, media: &::RTSPMedia); + fn parent_configure(&self, factory: &Self::Type, media: &::RTSPMedia); - fn parent_media_constructed(&self, factory: &RTSPMediaFactory, media: &::RTSPMedia); - fn parent_media_configure(&self, factory: &RTSPMediaFactory, media: &::RTSPMedia); + fn parent_media_constructed(&self, factory: &Self::Type, media: &::RTSPMedia); + fn parent_media_configure(&self, factory: &Self::Type, media: &::RTSPMedia); } impl RTSPMediaFactoryImplExt for T { fn parent_gen_key( &self, - factory: &RTSPMediaFactory, + factory: &Self::Type, url: &gst_rtsp::RTSPUrl, ) -> Option { unsafe { @@ -106,14 +95,22 @@ impl RTSPMediaFactoryImplExt for T { as *mut gst_rtsp_server_sys::GstRTSPMediaFactoryClass; (*parent_class) .gen_key - .map(|f| from_glib_full(f(factory.to_glib_none().0, url.to_glib_none().0))) + .map(|f| { + from_glib_full(f( + factory + .unsafe_cast_ref::() + .to_glib_none() + .0, + url.to_glib_none().0, + )) + }) .unwrap_or(None) } } fn parent_create_element( &self, - factory: &RTSPMediaFactory, + factory: &Self::Type, url: &gst_rtsp::RTSPUrl, ) -> Option { unsafe { @@ -122,14 +119,22 @@ impl RTSPMediaFactoryImplExt for T { as *mut gst_rtsp_server_sys::GstRTSPMediaFactoryClass; (*parent_class) .create_element - .map(|f| from_glib_none(f(factory.to_glib_none().0, url.to_glib_none().0))) + .map(|f| { + from_glib_none(f( + factory + .unsafe_cast_ref::() + .to_glib_none() + .0, + url.to_glib_none().0, + )) + }) .unwrap_or(None) } } fn parent_construct( &self, - factory: &RTSPMediaFactory, + factory: &Self::Type, url: &gst_rtsp::RTSPUrl, ) -> Option<::RTSPMedia> { unsafe { @@ -138,14 +143,22 @@ impl RTSPMediaFactoryImplExt for T { as *mut gst_rtsp_server_sys::GstRTSPMediaFactoryClass; (*parent_class) .construct - .map(|f| from_glib_full(f(factory.to_glib_none().0, url.to_glib_none().0))) + .map(|f| { + from_glib_full(f( + factory + .unsafe_cast_ref::() + .to_glib_none() + .0, + url.to_glib_none().0, + )) + }) .unwrap_or(None) } } fn parent_create_pipeline( &self, - factory: &RTSPMediaFactory, + factory: &Self::Type, media: &::RTSPMedia, ) -> Option { unsafe { @@ -155,8 +168,13 @@ impl RTSPMediaFactoryImplExt for T { (*parent_class) .create_pipeline .map(|f| { - let ptr = f(factory.to_glib_none().0, media.to_glib_none().0) - as *mut gst_sys::GstPipeline; + let ptr = f( + factory + .unsafe_cast_ref::() + .to_glib_none() + .0, + media.to_glib_none().0, + ) as *mut gst_sys::GstPipeline; // See https://gitlab.freedesktop.org/gstreamer/gst-rtsp-server/merge_requests/109 if gobject_sys::g_object_is_floating(ptr as *mut _) != glib_sys::GFALSE { @@ -168,35 +186,53 @@ impl RTSPMediaFactoryImplExt for T { } } - fn parent_configure(&self, factory: &RTSPMediaFactory, media: &::RTSPMedia) { + fn parent_configure(&self, factory: &Self::Type, media: &::RTSPMedia) { unsafe { let data = T::type_data(); let parent_class = data.as_ref().get_parent_class() as *mut gst_rtsp_server_sys::GstRTSPMediaFactoryClass; if let Some(f) = (*parent_class).configure { - f(factory.to_glib_none().0, media.to_glib_none().0); + f( + factory + .unsafe_cast_ref::() + .to_glib_none() + .0, + media.to_glib_none().0, + ); } } } - fn parent_media_constructed(&self, factory: &RTSPMediaFactory, media: &::RTSPMedia) { + fn parent_media_constructed(&self, factory: &Self::Type, media: &::RTSPMedia) { unsafe { let data = T::type_data(); let parent_class = data.as_ref().get_parent_class() as *mut gst_rtsp_server_sys::GstRTSPMediaFactoryClass; if let Some(f) = (*parent_class).media_constructed { - f(factory.to_glib_none().0, media.to_glib_none().0); + f( + factory + .unsafe_cast_ref::() + .to_glib_none() + .0, + media.to_glib_none().0, + ); } } } - fn parent_media_configure(&self, factory: &RTSPMediaFactory, media: &::RTSPMedia) { + fn parent_media_configure(&self, factory: &Self::Type, media: &::RTSPMedia) { unsafe { let data = T::type_data(); let parent_class = data.as_ref().get_parent_class() as *mut gst_rtsp_server_sys::GstRTSPMediaFactoryClass; if let Some(f) = (*parent_class).media_configure { - f(factory.to_glib_none().0, media.to_glib_none().0); + f( + factory + .unsafe_cast_ref::() + .to_glib_none() + .0, + media.to_glib_none().0, + ); } } } @@ -223,7 +259,8 @@ unsafe extern "C" fn factory_gen_key( let imp = instance.get_impl(); let wrap: Borrowed = from_glib_borrow(ptr); - imp.gen_key(&wrap, &from_glib_borrow(url)).to_glib_full() + imp.gen_key(wrap.unsafe_cast_ref(), &from_glib_borrow(url)) + .to_glib_full() } unsafe extern "C" fn factory_create_element( @@ -235,7 +272,7 @@ unsafe extern "C" fn factory_create_element( let wrap: Borrowed = from_glib_borrow(ptr); let element = imp - .create_element(&wrap, &from_glib_borrow(url)) + .create_element(wrap.unsafe_cast_ref(), &from_glib_borrow(url)) .to_glib_full(); gobject_sys::g_object_force_floating(element as *mut _); element @@ -249,7 +286,8 @@ unsafe extern "C" fn factory_construct( let imp = instance.get_impl(); let wrap: Borrowed = from_glib_borrow(ptr); - imp.construct(&wrap, &from_glib_borrow(url)).to_glib_full() + imp.construct(wrap.unsafe_cast_ref(), &from_glib_borrow(url)) + .to_glib_full() } unsafe extern "C" fn factory_create_pipeline( @@ -266,7 +304,7 @@ unsafe extern "C" fn factory_create_pipeline( let wrap: Borrowed = from_glib_borrow(ptr); let pipeline: *mut gst_sys::GstPipeline = imp - .create_pipeline(&wrap, &from_glib_borrow(media)) + .create_pipeline(wrap.unsafe_cast_ref(), &from_glib_borrow(media)) .to_glib_full(); // FIXME We somehow need to ensure the pipeline actually stays alive... @@ -290,7 +328,7 @@ unsafe extern "C" fn factory_configure( let imp = instance.get_impl(); let wrap: Borrowed = from_glib_borrow(ptr); - imp.configure(&wrap, &from_glib_borrow(media)); + imp.configure(wrap.unsafe_cast_ref(), &from_glib_borrow(media)); } unsafe extern "C" fn factory_media_constructed( @@ -301,7 +339,7 @@ unsafe extern "C" fn factory_media_constructed( let imp = instance.get_impl(); let wrap: Borrowed = from_glib_borrow(ptr); - imp.media_constructed(&wrap, &from_glib_borrow(media)); + imp.media_constructed(wrap.unsafe_cast_ref(), &from_glib_borrow(media)); } unsafe extern "C" fn factory_media_configure( @@ -312,5 +350,5 @@ unsafe extern "C" fn factory_media_configure( let imp = instance.get_impl(); let wrap: Borrowed = from_glib_borrow(ptr); - imp.media_configure(&wrap, &from_glib_borrow(media)); + imp.media_configure(wrap.unsafe_cast_ref(), &from_glib_borrow(media)); } diff --git a/gstreamer-rtsp-server/src/subclass/rtsp_server.rs b/gstreamer-rtsp-server/src/subclass/rtsp_server.rs index af5b691a8..c01b9baf3 100644 --- a/gstreamer-rtsp-server/src/subclass/rtsp_server.rs +++ b/gstreamer-rtsp-server/src/subclass/rtsp_server.rs @@ -8,29 +8,30 @@ use gst_rtsp_server_sys; +use glib::prelude::*; use glib::subclass::prelude::*; use glib::translate::*; use RTSPServer; pub trait RTSPServerImpl: RTSPServerImplExt + ObjectImpl + Send + Sync { - fn create_client(&self, server: &RTSPServer) -> Option<::RTSPClient> { + fn create_client(&self, server: &Self::Type) -> Option<::RTSPClient> { self.parent_create_client(server) } - fn client_connected(&self, server: &RTSPServer, client: &::RTSPClient) { + fn client_connected(&self, server: &Self::Type, client: &::RTSPClient) { self.parent_client_connected(server, client); } } -pub trait RTSPServerImplExt { - fn parent_create_client(&self, server: &RTSPServer) -> Option<::RTSPClient>; +pub trait RTSPServerImplExt: ObjectSubclass { + fn parent_create_client(&self, server: &Self::Type) -> Option<::RTSPClient>; - fn parent_client_connected(&self, server: &RTSPServer, client: &::RTSPClient); + fn parent_client_connected(&self, server: &Self::Type, client: &::RTSPClient); } impl RTSPServerImplExt for T { - fn parent_create_client(&self, server: &RTSPServer) -> Option<::RTSPClient> { + fn parent_create_client(&self, server: &Self::Type) -> Option<::RTSPClient> { unsafe { let data = T::type_data(); let parent_class = @@ -38,17 +39,20 @@ impl RTSPServerImplExt for T { let f = (*parent_class) .create_client .expect("No `create_client` virtual method implementation in parent class"); - from_glib_full(f(server.to_glib_none().0)) + from_glib_full(f(server.unsafe_cast_ref::().to_glib_none().0)) } } - fn parent_client_connected(&self, server: &RTSPServer, client: &::RTSPClient) { + fn parent_client_connected(&self, server: &Self::Type, client: &::RTSPClient) { unsafe { let data = T::type_data(); let parent_class = data.as_ref().get_parent_class() as *mut gst_rtsp_server_sys::GstRTSPServerClass; if let Some(f) = (*parent_class).client_connected { - f(server.to_glib_none().0, client.to_glib_none().0) + f( + server.unsafe_cast_ref::().to_glib_none().0, + client.to_glib_none().0, + ) } } } @@ -69,7 +73,7 @@ unsafe extern "C" fn server_create_client( let imp = instance.get_impl(); let wrap: Borrowed = from_glib_borrow(ptr); - imp.create_client(&wrap).to_glib_full() + imp.create_client(wrap.unsafe_cast_ref()).to_glib_full() } unsafe extern "C" fn server_client_connected( @@ -80,5 +84,5 @@ unsafe extern "C" fn server_client_connected( let imp = instance.get_impl(); let wrap: Borrowed = from_glib_borrow(ptr); - imp.client_connected(&wrap, &from_glib_borrow(client)); + imp.client_connected(wrap.unsafe_cast_ref(), &from_glib_borrow(client)); }