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

This commit is contained in:
Sebastian Dröge 2020-11-14 18:31:21 +02:00
parent b861f724c4
commit 3d3bdf9aa3
5 changed files with 459 additions and 312 deletions

View file

@ -129,7 +129,7 @@ mod media_factory {
impl RTSPMediaFactoryImpl for Factory { impl RTSPMediaFactoryImpl for Factory {
fn create_element( fn create_element(
&self, &self,
_factory: &gst_rtsp_server::RTSPMediaFactory, _factory: &Self::Type,
_url: &gst_rtsp::RTSPUrl, _url: &gst_rtsp::RTSPUrl,
) -> Option<gst::Element> { ) -> Option<gst::Element> {
// Create a simple VP8 videotestsrc input // Create a simple VP8 videotestsrc input
@ -218,7 +218,7 @@ mod media {
impl RTSPMediaImpl for Media { impl RTSPMediaImpl for Media {
fn setup_sdp( fn setup_sdp(
&self, &self,
media: &gst_rtsp_server::RTSPMedia, media: &Self::Type,
sdp: &mut gst_sdp::SDPMessageRef, sdp: &mut gst_sdp::SDPMessageRef,
info: &gst_rtsp_server::subclass::SDPInfo, info: &gst_rtsp_server::subclass::SDPInfo,
) -> Result<(), gst::LoggableError> { ) -> Result<(), gst::LoggableError> {
@ -284,10 +284,7 @@ mod server {
// Implementation of gst_rtsp_server::RTSPServer virtual methods // Implementation of gst_rtsp_server::RTSPServer virtual methods
impl RTSPServerImpl for Server { impl RTSPServerImpl for Server {
fn create_client( fn create_client(&self, server: &Self::Type) -> Option<gst_rtsp_server::RTSPClient> {
&self,
server: &gst_rtsp_server::RTSPServer,
) -> Option<gst_rtsp_server::RTSPClient> {
let client = super::client::Client::default(); let client = super::client::Client::default();
// Duplicated from the default implementation // Duplicated from the default implementation
@ -299,11 +296,7 @@ mod server {
Some(client.upcast()) Some(client.upcast())
} }
fn client_connected( fn client_connected(&self, server: &Self::Type, client: &gst_rtsp_server::RTSPClient) {
&self,
server: &gst_rtsp_server::RTSPServer,
client: &gst_rtsp_server::RTSPClient,
) {
self.parent_client_connected(server, client); self.parent_client_connected(server, client);
println!("Client {:?} connected", client); println!("Client {:?} connected", client);
} }
@ -372,7 +365,7 @@ mod client {
// Implementation of gst_rtsp_server::RTSPClient virtual methods // Implementation of gst_rtsp_server::RTSPClient virtual methods
impl RTSPClientImpl for Client { impl RTSPClientImpl for Client {
fn closed(&self, client: &gst_rtsp_server::RTSPClient) { fn closed(&self, client: &Self::Type) {
self.parent_closed(client); self.parent_closed(client);
println!("Client {:?} closed", client); println!("Client {:?} closed", client);
} }

File diff suppressed because it is too large Load diff

View file

@ -8,6 +8,7 @@
use gst_rtsp_server_sys; use gst_rtsp_server_sys;
use glib::prelude::*;
use glib::subclass::prelude::*; use glib::subclass::prelude::*;
use glib::translate::*; use glib::translate::*;
@ -33,43 +34,43 @@ impl SDPInfo {
} }
pub trait RTSPMediaImpl: RTSPMediaImplExt + ObjectImpl + Send + Sync { 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) 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) 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) 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) 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) self.parent_unsuspend(media)
} }
// TODO missing: convert_range // TODO missing: convert_range
fn query_position(&self, media: &RTSPMedia) -> Option<gst::ClockTime> { fn query_position(&self, media: &Self::Type) -> Option<gst::ClockTime> {
self.parent_query_position(media) self.parent_query_position(media)
} }
fn query_stop(&self, media: &RTSPMedia) -> Option<gst::ClockTime> { fn query_stop(&self, media: &Self::Type) -> Option<gst::ClockTime> {
self.parent_query_stop(media) self.parent_query_stop(media)
} }
fn create_rtpbin(&self, media: &RTSPMedia) -> Option<gst::Element> { fn create_rtpbin(&self, media: &Self::Type) -> Option<gst::Element> {
self.parent_create_rtpbin(media) self.parent_create_rtpbin(media)
} }
fn setup_rtpbin( fn setup_rtpbin(
&self, &self,
media: &RTSPMedia, media: &Self::Type,
rtpbin: &gst::Element, rtpbin: &gst::Element,
) -> Result<(), gst::LoggableError> { ) -> Result<(), gst::LoggableError> {
self.parent_setup_rtpbin(media, rtpbin) self.parent_setup_rtpbin(media, rtpbin)
@ -77,93 +78,96 @@ pub trait RTSPMediaImpl: RTSPMediaImplExt + ObjectImpl + Send + Sync {
fn setup_sdp( fn setup_sdp(
&self, &self,
media: &RTSPMedia, media: &Self::Type,
sdp: &mut gst_sdp::SDPMessageRef, sdp: &mut gst_sdp::SDPMessageRef,
info: &SDPInfo, info: &SDPInfo,
) -> Result<(), gst::LoggableError> { ) -> Result<(), gst::LoggableError> {
self.parent_setup_sdp(media, sdp, info) 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); 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); self.parent_removed_stream(media, stream);
} }
fn prepared(&self, media: &RTSPMedia) { fn prepared(&self, media: &Self::Type) {
self.parent_prepared(media); self.parent_prepared(media);
} }
fn unprepared(&self, media: &RTSPMedia) { fn unprepared(&self, media: &Self::Type) {
self.parent_unprepared(media); 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); 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); self.parent_new_state(media, state);
} }
fn handle_sdp( fn handle_sdp(
&self, &self,
media: &RTSPMedia, media: &Self::Type,
sdp: &gst_sdp::SDPMessageRef, sdp: &gst_sdp::SDPMessageRef,
) -> Result<(), gst::LoggableError> { ) -> Result<(), gst::LoggableError> {
self.parent_handle_sdp(media, sdp) self.parent_handle_sdp(media, sdp)
} }
} }
pub trait RTSPMediaImplExt { pub trait RTSPMediaImplExt: ObjectSubclass {
fn parent_handle_message(&self, media: &RTSPMedia, message: &gst::MessageRef) -> bool; fn parent_handle_message(&self, media: &Self::Type, message: &gst::MessageRef) -> bool;
fn parent_prepare( fn parent_prepare(
&self, &self,
media: &RTSPMedia, media: &Self::Type,
thread: &RTSPThread, thread: &RTSPThread,
) -> Result<(), gst::LoggableError>; ) -> Result<(), gst::LoggableError>;
fn parent_unprepare(&self, media: &RTSPMedia) -> Result<(), gst::LoggableError>; fn parent_unprepare(&self, media: &Self::Type) -> Result<(), gst::LoggableError>;
fn parent_suspend(&self, media: &RTSPMedia) -> Result<(), gst::LoggableError>; fn parent_suspend(&self, media: &Self::Type) -> Result<(), gst::LoggableError>;
fn parent_unsuspend(&self, media: &RTSPMedia) -> Result<(), gst::LoggableError>; fn parent_unsuspend(&self, media: &Self::Type) -> Result<(), gst::LoggableError>;
// TODO missing: convert_range // TODO missing: convert_range
fn parent_query_position(&self, media: &RTSPMedia) -> Option<gst::ClockTime>; fn parent_query_position(&self, media: &Self::Type) -> Option<gst::ClockTime>;
fn parent_query_stop(&self, media: &RTSPMedia) -> Option<gst::ClockTime>; fn parent_query_stop(&self, media: &Self::Type) -> Option<gst::ClockTime>;
fn parent_create_rtpbin(&self, media: &RTSPMedia) -> Option<gst::Element>; fn parent_create_rtpbin(&self, media: &Self::Type) -> Option<gst::Element>;
fn parent_setup_rtpbin( fn parent_setup_rtpbin(
&self, &self,
media: &RTSPMedia, media: &Self::Type,
rtpbin: &gst::Element, rtpbin: &gst::Element,
) -> Result<(), gst::LoggableError>; ) -> Result<(), gst::LoggableError>;
fn parent_setup_sdp( fn parent_setup_sdp(
&self, &self,
media: &RTSPMedia, media: &Self::Type,
sdp: &mut gst_sdp::SDPMessageRef, sdp: &mut gst_sdp::SDPMessageRef,
info: &SDPInfo, info: &SDPInfo,
) -> Result<(), gst::LoggableError>; ) -> Result<(), gst::LoggableError>;
fn parent_new_stream(&self, media: &RTSPMedia, stream: &::RTSPStream); fn parent_new_stream(&self, media: &Self::Type, stream: &::RTSPStream);
fn parent_removed_stream(&self, media: &RTSPMedia, stream: &::RTSPStream); fn parent_removed_stream(&self, media: &Self::Type, stream: &::RTSPStream);
fn parent_prepared(&self, media: &RTSPMedia); fn parent_prepared(&self, media: &Self::Type);
fn parent_unprepared(&self, media: &RTSPMedia); fn parent_unprepared(&self, media: &Self::Type);
fn parent_target_state(&self, media: &RTSPMedia, state: gst::State); fn parent_target_state(&self, media: &Self::Type, state: gst::State);
fn parent_new_state(&self, media: &RTSPMedia, state: gst::State); fn parent_new_state(&self, media: &Self::Type, state: gst::State);
fn parent_handle_sdp( fn parent_handle_sdp(
&self, &self,
media: &RTSPMedia, media: &Self::Type,
sdp: &gst_sdp::SDPMessageRef, sdp: &gst_sdp::SDPMessageRef,
) -> Result<(), gst::LoggableError>; ) -> Result<(), gst::LoggableError>;
} }
impl<T: RTSPMediaImpl> RTSPMediaImplExt for T { impl<T: RTSPMediaImpl> 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 { unsafe {
let data = T::type_data(); let data = T::type_data();
let parent_class = let parent_class =
data.as_ref().get_parent_class() as *mut gst_rtsp_server_sys::GstRTSPMediaClass; data.as_ref().get_parent_class() as *mut gst_rtsp_server_sys::GstRTSPMediaClass;
if let Some(f) = (*parent_class).handle_message { 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::<RTSPMedia>().to_glib_none().0,
message.as_ptr() as *mut _,
))
} else { } else {
false false
} }
@ -172,7 +176,7 @@ impl<T: RTSPMediaImpl> RTSPMediaImplExt for T {
fn parent_prepare( fn parent_prepare(
&self, &self,
media: &RTSPMedia, media: &Self::Type,
thread: &RTSPThread, thread: &RTSPThread,
) -> Result<(), gst::LoggableError> { ) -> Result<(), gst::LoggableError> {
unsafe { unsafe {
@ -181,7 +185,10 @@ impl<T: RTSPMediaImpl> RTSPMediaImplExt for T {
data.as_ref().get_parent_class() as *mut gst_rtsp_server_sys::GstRTSPMediaClass; data.as_ref().get_parent_class() as *mut gst_rtsp_server_sys::GstRTSPMediaClass;
if let Some(f) = (*parent_class).prepare { if let Some(f) = (*parent_class).prepare {
gst_result_from_gboolean!( gst_result_from_gboolean!(
f(media.to_glib_none().0, thread.to_glib_none().0), f(
media.unsafe_cast_ref::<RTSPMedia>().to_glib_none().0,
thread.to_glib_none().0
),
gst::CAT_RUST, gst::CAT_RUST,
"Parent function `prepare` failed" "Parent function `prepare` failed"
) )
@ -191,14 +198,14 @@ impl<T: RTSPMediaImpl> RTSPMediaImplExt for T {
} }
} }
fn parent_unprepare(&self, media: &RTSPMedia) -> Result<(), gst::LoggableError> { fn parent_unprepare(&self, media: &Self::Type) -> Result<(), gst::LoggableError> {
unsafe { unsafe {
let data = T::type_data(); let data = T::type_data();
let parent_class = let parent_class =
data.as_ref().get_parent_class() as *mut gst_rtsp_server_sys::GstRTSPMediaClass; data.as_ref().get_parent_class() as *mut gst_rtsp_server_sys::GstRTSPMediaClass;
if let Some(f) = (*parent_class).unprepare { if let Some(f) = (*parent_class).unprepare {
gst_result_from_gboolean!( gst_result_from_gboolean!(
f(media.to_glib_none().0), f(media.unsafe_cast_ref::<RTSPMedia>().to_glib_none().0),
gst::CAT_RUST, gst::CAT_RUST,
"Parent function `unprepare` failed" "Parent function `unprepare` failed"
) )
@ -208,14 +215,14 @@ impl<T: RTSPMediaImpl> RTSPMediaImplExt for T {
} }
} }
fn parent_suspend(&self, media: &RTSPMedia) -> Result<(), gst::LoggableError> { fn parent_suspend(&self, media: &Self::Type) -> Result<(), gst::LoggableError> {
unsafe { unsafe {
let data = T::type_data(); let data = T::type_data();
let parent_class = let parent_class =
data.as_ref().get_parent_class() as *mut gst_rtsp_server_sys::GstRTSPMediaClass; data.as_ref().get_parent_class() as *mut gst_rtsp_server_sys::GstRTSPMediaClass;
if let Some(f) = (*parent_class).suspend { if let Some(f) = (*parent_class).suspend {
gst_result_from_gboolean!( gst_result_from_gboolean!(
f(media.to_glib_none().0), f(media.unsafe_cast_ref::<RTSPMedia>().to_glib_none().0),
gst::CAT_RUST, gst::CAT_RUST,
"Parent function `suspend` failed" "Parent function `suspend` failed"
) )
@ -225,14 +232,14 @@ impl<T: RTSPMediaImpl> RTSPMediaImplExt for T {
} }
} }
fn parent_unsuspend(&self, media: &RTSPMedia) -> Result<(), gst::LoggableError> { fn parent_unsuspend(&self, media: &Self::Type) -> Result<(), gst::LoggableError> {
unsafe { unsafe {
let data = T::type_data(); let data = T::type_data();
let parent_class = let parent_class =
data.as_ref().get_parent_class() as *mut gst_rtsp_server_sys::GstRTSPMediaClass; data.as_ref().get_parent_class() as *mut gst_rtsp_server_sys::GstRTSPMediaClass;
if let Some(f) = (*parent_class).unsuspend { if let Some(f) = (*parent_class).unsuspend {
gst_result_from_gboolean!( gst_result_from_gboolean!(
f(media.to_glib_none().0), f(media.unsafe_cast_ref::<RTSPMedia>().to_glib_none().0),
gst::CAT_RUST, gst::CAT_RUST,
"Parent function `unsuspend` failed" "Parent function `unsuspend` failed"
) )
@ -244,7 +251,7 @@ impl<T: RTSPMediaImpl> RTSPMediaImplExt for T {
// TODO missing: convert_range // TODO missing: convert_range
fn parent_query_position(&self, media: &RTSPMedia) -> Option<gst::ClockTime> { fn parent_query_position(&self, media: &Self::Type) -> Option<gst::ClockTime> {
unsafe { unsafe {
use std::mem; use std::mem;
@ -253,7 +260,11 @@ impl<T: RTSPMediaImpl> RTSPMediaImplExt for T {
data.as_ref().get_parent_class() as *mut gst_rtsp_server_sys::GstRTSPMediaClass; data.as_ref().get_parent_class() as *mut gst_rtsp_server_sys::GstRTSPMediaClass;
if let Some(f) = (*parent_class).query_position { if let Some(f) = (*parent_class).query_position {
let mut position = mem::MaybeUninit::uninit(); 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::<RTSPMedia>().to_glib_none().0,
position.as_mut_ptr(),
) == glib_sys::GFALSE
{
None None
} else { } else {
Some(from_glib(position.assume_init() as u64)) Some(from_glib(position.assume_init() as u64))
@ -264,7 +275,7 @@ impl<T: RTSPMediaImpl> RTSPMediaImplExt for T {
} }
} }
fn parent_query_stop(&self, media: &RTSPMedia) -> Option<gst::ClockTime> { fn parent_query_stop(&self, media: &Self::Type) -> Option<gst::ClockTime> {
unsafe { unsafe {
use std::mem; use std::mem;
@ -273,7 +284,11 @@ impl<T: RTSPMediaImpl> RTSPMediaImplExt for T {
data.as_ref().get_parent_class() as *mut gst_rtsp_server_sys::GstRTSPMediaClass; data.as_ref().get_parent_class() as *mut gst_rtsp_server_sys::GstRTSPMediaClass;
if let Some(f) = (*parent_class).query_stop { if let Some(f) = (*parent_class).query_stop {
let mut stop = mem::MaybeUninit::uninit(); 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::<RTSPMedia>().to_glib_none().0,
stop.as_mut_ptr(),
) == glib_sys::GFALSE
{
None None
} else { } else {
Some(from_glib(stop.assume_init() as u64)) Some(from_glib(stop.assume_init() as u64))
@ -284,7 +299,7 @@ impl<T: RTSPMediaImpl> RTSPMediaImplExt for T {
} }
} }
fn parent_create_rtpbin(&self, media: &RTSPMedia) -> Option<gst::Element> { fn parent_create_rtpbin(&self, media: &Self::Type) -> Option<gst::Element> {
unsafe { unsafe {
let data = T::type_data(); let data = T::type_data();
let parent_class = let parent_class =
@ -293,13 +308,13 @@ impl<T: RTSPMediaImpl> RTSPMediaImplExt for T {
.create_rtpbin .create_rtpbin
.expect("No `create_rtpbin` virtual method implementation in parent class"); .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::<RTSPMedia>().to_glib_none().0))
} }
} }
fn parent_setup_rtpbin( fn parent_setup_rtpbin(
&self, &self,
media: &RTSPMedia, media: &Self::Type,
rtpbin: &gst::Element, rtpbin: &gst::Element,
) -> Result<(), gst::LoggableError> { ) -> Result<(), gst::LoggableError> {
unsafe { unsafe {
@ -313,7 +328,7 @@ impl<T: RTSPMediaImpl> RTSPMediaImplExt for T {
gobject_sys::g_object_force_floating(ptr as *mut _); gobject_sys::g_object_force_floating(ptr as *mut _);
let res = gst_result_from_gboolean!( let res = gst_result_from_gboolean!(
f(media.to_glib_none().0, ptr), f(media.unsafe_cast_ref::<RTSPMedia>().to_glib_none().0, ptr),
gst::CAT_RUST, gst::CAT_RUST,
"Parent function `setup_sdp` failed" "Parent function `setup_sdp` failed"
); );
@ -334,7 +349,7 @@ impl<T: RTSPMediaImpl> RTSPMediaImplExt for T {
fn parent_setup_sdp( fn parent_setup_sdp(
&self, &self,
media: &RTSPMedia, media: &Self::Type,
sdp: &mut gst_sdp::SDPMessageRef, sdp: &mut gst_sdp::SDPMessageRef,
info: &SDPInfo, info: &SDPInfo,
) -> Result<(), gst::LoggableError> { ) -> Result<(), gst::LoggableError> {
@ -348,7 +363,7 @@ impl<T: RTSPMediaImpl> RTSPMediaImplExt for T {
gst_result_from_gboolean!( gst_result_from_gboolean!(
f( f(
media.to_glib_none().0, media.unsafe_cast_ref::<RTSPMedia>().to_glib_none().0,
sdp as *mut _ as *mut gst_sdp_sys::GstSDPMessage, sdp as *mut _ as *mut gst_sdp_sys::GstSDPMessage,
info.0.as_ptr() info.0.as_ptr()
), ),
@ -358,75 +373,87 @@ impl<T: RTSPMediaImpl> RTSPMediaImplExt for T {
} }
} }
fn parent_new_stream(&self, media: &RTSPMedia, stream: &::RTSPStream) { fn parent_new_stream(&self, media: &Self::Type, stream: &::RTSPStream) {
unsafe { unsafe {
let data = T::type_data(); let data = T::type_data();
let parent_class = let parent_class =
data.as_ref().get_parent_class() as *mut gst_rtsp_server_sys::GstRTSPMediaClass; data.as_ref().get_parent_class() as *mut gst_rtsp_server_sys::GstRTSPMediaClass;
if let Some(f) = (*parent_class).new_stream { if let Some(f) = (*parent_class).new_stream {
f(media.to_glib_none().0, stream.to_glib_none().0); f(
media.unsafe_cast_ref::<RTSPMedia>().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 { unsafe {
let data = T::type_data(); let data = T::type_data();
let parent_class = let parent_class =
data.as_ref().get_parent_class() as *mut gst_rtsp_server_sys::GstRTSPMediaClass; data.as_ref().get_parent_class() as *mut gst_rtsp_server_sys::GstRTSPMediaClass;
if let Some(f) = (*parent_class).removed_stream { if let Some(f) = (*parent_class).removed_stream {
f(media.to_glib_none().0, stream.to_glib_none().0); f(
media.unsafe_cast_ref::<RTSPMedia>().to_glib_none().0,
stream.to_glib_none().0,
);
} }
} }
} }
fn parent_prepared(&self, media: &RTSPMedia) { fn parent_prepared(&self, media: &Self::Type) {
unsafe { unsafe {
let data = T::type_data(); let data = T::type_data();
let parent_class = let parent_class =
data.as_ref().get_parent_class() as *mut gst_rtsp_server_sys::GstRTSPMediaClass; data.as_ref().get_parent_class() as *mut gst_rtsp_server_sys::GstRTSPMediaClass;
if let Some(f) = (*parent_class).prepared { if let Some(f) = (*parent_class).prepared {
f(media.to_glib_none().0); f(media.unsafe_cast_ref::<RTSPMedia>().to_glib_none().0);
} }
} }
} }
fn parent_unprepared(&self, media: &RTSPMedia) { fn parent_unprepared(&self, media: &Self::Type) {
unsafe { unsafe {
let data = T::type_data(); let data = T::type_data();
let parent_class = let parent_class =
data.as_ref().get_parent_class() as *mut gst_rtsp_server_sys::GstRTSPMediaClass; data.as_ref().get_parent_class() as *mut gst_rtsp_server_sys::GstRTSPMediaClass;
if let Some(f) = (*parent_class).unprepared { if let Some(f) = (*parent_class).unprepared {
f(media.to_glib_none().0); f(media.unsafe_cast_ref::<RTSPMedia>().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 { unsafe {
let data = T::type_data(); let data = T::type_data();
let parent_class = let parent_class =
data.as_ref().get_parent_class() as *mut gst_rtsp_server_sys::GstRTSPMediaClass; data.as_ref().get_parent_class() as *mut gst_rtsp_server_sys::GstRTSPMediaClass;
if let Some(f) = (*parent_class).target_state { if let Some(f) = (*parent_class).target_state {
f(media.to_glib_none().0, state.to_glib()); f(
media.unsafe_cast_ref::<RTSPMedia>().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 { unsafe {
let data = T::type_data(); let data = T::type_data();
let parent_class = let parent_class =
data.as_ref().get_parent_class() as *mut gst_rtsp_server_sys::GstRTSPMediaClass; data.as_ref().get_parent_class() as *mut gst_rtsp_server_sys::GstRTSPMediaClass;
if let Some(f) = (*parent_class).new_state { if let Some(f) = (*parent_class).new_state {
f(media.to_glib_none().0, state.to_glib()); f(
media.unsafe_cast_ref::<RTSPMedia>().to_glib_none().0,
state.to_glib(),
);
} }
} }
} }
fn parent_handle_sdp( fn parent_handle_sdp(
&self, &self,
media: &RTSPMedia, media: &Self::Type,
sdp: &gst_sdp::SDPMessageRef, sdp: &gst_sdp::SDPMessageRef,
) -> Result<(), gst::LoggableError> { ) -> Result<(), gst::LoggableError> {
unsafe { unsafe {
@ -439,7 +466,7 @@ impl<T: RTSPMediaImpl> RTSPMediaImplExt for T {
gst_result_from_gboolean!( gst_result_from_gboolean!(
f( f(
media.to_glib_none().0, media.unsafe_cast_ref::<RTSPMedia>().to_glib_none().0,
sdp as *const _ as *mut gst_sdp_sys::GstSDPMessage sdp as *const _ as *mut gst_sdp_sys::GstSDPMessage
), ),
gst::CAT_RUST, gst::CAT_RUST,
@ -480,7 +507,7 @@ unsafe extern "C" fn media_handle_message<T: RTSPMediaImpl>(
let imp = instance.get_impl(); let imp = instance.get_impl();
let wrap: Borrowed<RTSPMedia> = from_glib_borrow(ptr); let wrap: Borrowed<RTSPMedia> = 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() .to_glib()
} }
@ -492,7 +519,7 @@ unsafe extern "C" fn media_prepare<T: RTSPMediaImpl>(
let imp = instance.get_impl(); let imp = instance.get_impl();
let wrap: Borrowed<RTSPMedia> = from_glib_borrow(ptr); let wrap: Borrowed<RTSPMedia> = 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, Ok(()) => glib_sys::GTRUE,
Err(err) => { Err(err) => {
err.log_with_object(&*wrap); err.log_with_object(&*wrap);
@ -508,7 +535,7 @@ unsafe extern "C" fn media_unprepare<T: RTSPMediaImpl>(
let imp = instance.get_impl(); let imp = instance.get_impl();
let wrap: Borrowed<RTSPMedia> = from_glib_borrow(ptr); let wrap: Borrowed<RTSPMedia> = from_glib_borrow(ptr);
match imp.unprepare(&wrap) { match imp.unprepare(wrap.unsafe_cast_ref()) {
Ok(()) => glib_sys::GTRUE, Ok(()) => glib_sys::GTRUE,
Err(err) => { Err(err) => {
err.log_with_object(&*wrap); err.log_with_object(&*wrap);
@ -524,7 +551,7 @@ unsafe extern "C" fn media_suspend<T: RTSPMediaImpl>(
let imp = instance.get_impl(); let imp = instance.get_impl();
let wrap: Borrowed<RTSPMedia> = from_glib_borrow(ptr); let wrap: Borrowed<RTSPMedia> = from_glib_borrow(ptr);
match imp.suspend(&wrap) { match imp.suspend(wrap.unsafe_cast_ref()) {
Ok(()) => glib_sys::GTRUE, Ok(()) => glib_sys::GTRUE,
Err(err) => { Err(err) => {
err.log_with_object(&*wrap); err.log_with_object(&*wrap);
@ -540,7 +567,7 @@ unsafe extern "C" fn media_unsuspend<T: RTSPMediaImpl>(
let imp = instance.get_impl(); let imp = instance.get_impl();
let wrap: Borrowed<RTSPMedia> = from_glib_borrow(ptr); let wrap: Borrowed<RTSPMedia> = from_glib_borrow(ptr);
match imp.unsuspend(&wrap) { match imp.unsuspend(wrap.unsafe_cast_ref()) {
Ok(()) => glib_sys::GTRUE, Ok(()) => glib_sys::GTRUE,
Err(err) => { Err(err) => {
err.log_with_object(&*wrap); err.log_with_object(&*wrap);
@ -557,7 +584,7 @@ unsafe extern "C" fn media_query_position<T: RTSPMediaImpl>(
let imp = instance.get_impl(); let imp = instance.get_impl();
let wrap: Borrowed<RTSPMedia> = from_glib_borrow(ptr); let wrap: Borrowed<RTSPMedia> = from_glib_borrow(ptr);
match imp.query_position(&wrap) { match imp.query_position(wrap.unsafe_cast_ref()) {
Some(pos) => { Some(pos) => {
*position = pos.to_glib() as i64; *position = pos.to_glib() as i64;
glib_sys::GTRUE glib_sys::GTRUE
@ -574,7 +601,7 @@ unsafe extern "C" fn media_query_stop<T: RTSPMediaImpl>(
let imp = instance.get_impl(); let imp = instance.get_impl();
let wrap: Borrowed<RTSPMedia> = from_glib_borrow(ptr); let wrap: Borrowed<RTSPMedia> = from_glib_borrow(ptr);
match imp.query_stop(&wrap) { match imp.query_stop(wrap.unsafe_cast_ref()) {
Some(s) => { Some(s) => {
*stop = s.to_glib() as i64; *stop = s.to_glib() as i64;
glib_sys::GTRUE glib_sys::GTRUE
@ -590,7 +617,7 @@ unsafe extern "C" fn media_create_rtpbin<T: RTSPMediaImpl>(
let imp = instance.get_impl(); let imp = instance.get_impl();
let wrap: Borrowed<RTSPMedia> = from_glib_borrow(ptr); let wrap: Borrowed<RTSPMedia> = 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() { if !res.is_null() {
gobject_sys::g_object_force_floating(res as *mut _); gobject_sys::g_object_force_floating(res as *mut _);
@ -613,7 +640,7 @@ unsafe extern "C" fn media_setup_rtpbin<T: RTSPMediaImpl>(
gobject_sys::g_object_ref_sink(rtpbin as *mut _); 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, Ok(()) => glib_sys::GTRUE,
Err(err) => { Err(err) => {
err.log_with_object(&*wrap); err.log_with_object(&*wrap);
@ -637,7 +664,7 @@ unsafe extern "C" fn media_setup_sdp<T: RTSPMediaImpl>(
let wrap: Borrowed<RTSPMedia> = from_glib_borrow(ptr); let wrap: Borrowed<RTSPMedia> = from_glib_borrow(ptr);
match imp.setup_sdp( match imp.setup_sdp(
&wrap, wrap.unsafe_cast_ref(),
&mut *(sdp as *mut gst_sdp::SDPMessageRef), &mut *(sdp as *mut gst_sdp::SDPMessageRef),
&SDPInfo(ptr::NonNull::new(info).expect("NULL SDPInfo")), &SDPInfo(ptr::NonNull::new(info).expect("NULL SDPInfo")),
) { ) {
@ -657,7 +684,7 @@ unsafe extern "C" fn media_new_stream<T: RTSPMediaImpl>(
let imp = instance.get_impl(); let imp = instance.get_impl();
let wrap: Borrowed<RTSPMedia> = from_glib_borrow(ptr); let wrap: Borrowed<RTSPMedia> = 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<T: RTSPMediaImpl>( unsafe extern "C" fn media_removed_stream<T: RTSPMediaImpl>(
@ -668,7 +695,7 @@ unsafe extern "C" fn media_removed_stream<T: RTSPMediaImpl>(
let imp = instance.get_impl(); let imp = instance.get_impl();
let wrap: Borrowed<RTSPMedia> = from_glib_borrow(ptr); let wrap: Borrowed<RTSPMedia> = 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<T: RTSPMediaImpl>(ptr: *mut gst_rtsp_server_sys::GstRTSPMedia) { unsafe extern "C" fn media_prepared<T: RTSPMediaImpl>(ptr: *mut gst_rtsp_server_sys::GstRTSPMedia) {
@ -676,7 +703,7 @@ unsafe extern "C" fn media_prepared<T: RTSPMediaImpl>(ptr: *mut gst_rtsp_server_
let imp = instance.get_impl(); let imp = instance.get_impl();
let wrap: Borrowed<RTSPMedia> = from_glib_borrow(ptr); let wrap: Borrowed<RTSPMedia> = from_glib_borrow(ptr);
imp.prepared(&wrap); imp.prepared(wrap.unsafe_cast_ref());
} }
unsafe extern "C" fn media_unprepared<T: RTSPMediaImpl>( unsafe extern "C" fn media_unprepared<T: RTSPMediaImpl>(
@ -686,7 +713,7 @@ unsafe extern "C" fn media_unprepared<T: RTSPMediaImpl>(
let imp = instance.get_impl(); let imp = instance.get_impl();
let wrap: Borrowed<RTSPMedia> = from_glib_borrow(ptr); let wrap: Borrowed<RTSPMedia> = from_glib_borrow(ptr);
imp.unprepared(&wrap); imp.unprepared(wrap.unsafe_cast_ref());
} }
unsafe extern "C" fn media_target_state<T: RTSPMediaImpl>( unsafe extern "C" fn media_target_state<T: RTSPMediaImpl>(
@ -697,7 +724,7 @@ unsafe extern "C" fn media_target_state<T: RTSPMediaImpl>(
let imp = instance.get_impl(); let imp = instance.get_impl();
let wrap: Borrowed<RTSPMedia> = from_glib_borrow(ptr); let wrap: Borrowed<RTSPMedia> = 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<T: RTSPMediaImpl>( unsafe extern "C" fn media_new_state<T: RTSPMediaImpl>(
@ -708,7 +735,7 @@ unsafe extern "C" fn media_new_state<T: RTSPMediaImpl>(
let imp = instance.get_impl(); let imp = instance.get_impl();
let wrap: Borrowed<RTSPMedia> = from_glib_borrow(ptr); let wrap: Borrowed<RTSPMedia> = 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<T: RTSPMediaImpl>( unsafe extern "C" fn media_handle_sdp<T: RTSPMediaImpl>(
@ -719,7 +746,10 @@ unsafe extern "C" fn media_handle_sdp<T: RTSPMediaImpl>(
let imp = instance.get_impl(); let imp = instance.get_impl();
let wrap: Borrowed<RTSPMedia> = from_glib_borrow(ptr); let wrap: Borrowed<RTSPMedia> = 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, Ok(()) => glib_sys::GTRUE,
Err(err) => { Err(err) => {
err.log_with_object(&*wrap); err.log_with_object(&*wrap);

View file

@ -8,96 +8,85 @@
use gst_rtsp_server_sys; use gst_rtsp_server_sys;
use glib::translate::*; use glib::prelude::*;
use gst_rtsp;
use glib::subclass::prelude::*; use glib::subclass::prelude::*;
use glib::translate::*;
use gst_rtsp;
use RTSPMediaFactory; use RTSPMediaFactory;
use std::mem::transmute; use std::mem::transmute;
pub trait RTSPMediaFactoryImpl: RTSPMediaFactoryImplExt + ObjectImpl + Send + Sync { pub trait RTSPMediaFactoryImpl: RTSPMediaFactoryImplExt + ObjectImpl + Send + Sync {
fn gen_key( fn gen_key(&self, factory: &Self::Type, url: &gst_rtsp::RTSPUrl) -> Option<glib::GString> {
&self,
factory: &RTSPMediaFactory,
url: &gst_rtsp::RTSPUrl,
) -> Option<glib::GString> {
self.parent_gen_key(factory, url) self.parent_gen_key(factory, url)
} }
fn create_element( fn create_element(
&self, &self,
factory: &RTSPMediaFactory, factory: &Self::Type,
url: &gst_rtsp::RTSPUrl, url: &gst_rtsp::RTSPUrl,
) -> Option<gst::Element> { ) -> Option<gst::Element> {
self.parent_create_element(factory, url) self.parent_create_element(factory, url)
} }
fn construct( fn construct(&self, factory: &Self::Type, url: &gst_rtsp::RTSPUrl) -> Option<::RTSPMedia> {
&self,
factory: &RTSPMediaFactory,
url: &gst_rtsp::RTSPUrl,
) -> Option<::RTSPMedia> {
self.parent_construct(factory, url) self.parent_construct(factory, url)
} }
fn create_pipeline( fn create_pipeline(&self, factory: &Self::Type, media: &::RTSPMedia) -> Option<gst::Pipeline> {
&self,
factory: &RTSPMediaFactory,
media: &::RTSPMedia,
) -> Option<gst::Pipeline> {
self.parent_create_pipeline(factory, media) 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) 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) 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) self.parent_media_configure(factory, media)
} }
} }
pub trait RTSPMediaFactoryImplExt { pub trait RTSPMediaFactoryImplExt: ObjectSubclass {
fn parent_gen_key( fn parent_gen_key(
&self, &self,
factory: &RTSPMediaFactory, factory: &Self::Type,
url: &gst_rtsp::RTSPUrl, url: &gst_rtsp::RTSPUrl,
) -> Option<glib::GString>; ) -> Option<glib::GString>;
fn parent_create_element( fn parent_create_element(
&self, &self,
factory: &RTSPMediaFactory, factory: &Self::Type,
url: &gst_rtsp::RTSPUrl, url: &gst_rtsp::RTSPUrl,
) -> Option<gst::Element>; ) -> Option<gst::Element>;
fn parent_construct( fn parent_construct(
&self, &self,
factory: &RTSPMediaFactory, factory: &Self::Type,
url: &gst_rtsp::RTSPUrl, url: &gst_rtsp::RTSPUrl,
) -> Option<::RTSPMedia>; ) -> Option<::RTSPMedia>;
fn parent_create_pipeline( fn parent_create_pipeline(
&self, &self,
factory: &RTSPMediaFactory, factory: &Self::Type,
media: &::RTSPMedia, media: &::RTSPMedia,
) -> Option<gst::Pipeline>; ) -> Option<gst::Pipeline>;
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_constructed(&self, factory: &Self::Type, media: &::RTSPMedia);
fn parent_media_configure(&self, factory: &RTSPMediaFactory, media: &::RTSPMedia); fn parent_media_configure(&self, factory: &Self::Type, media: &::RTSPMedia);
} }
impl<T: RTSPMediaFactoryImpl> RTSPMediaFactoryImplExt for T { impl<T: RTSPMediaFactoryImpl> RTSPMediaFactoryImplExt for T {
fn parent_gen_key( fn parent_gen_key(
&self, &self,
factory: &RTSPMediaFactory, factory: &Self::Type,
url: &gst_rtsp::RTSPUrl, url: &gst_rtsp::RTSPUrl,
) -> Option<glib::GString> { ) -> Option<glib::GString> {
unsafe { unsafe {
@ -106,14 +95,22 @@ impl<T: RTSPMediaFactoryImpl> RTSPMediaFactoryImplExt for T {
as *mut gst_rtsp_server_sys::GstRTSPMediaFactoryClass; as *mut gst_rtsp_server_sys::GstRTSPMediaFactoryClass;
(*parent_class) (*parent_class)
.gen_key .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::<RTSPMediaFactory>()
.to_glib_none()
.0,
url.to_glib_none().0,
))
})
.unwrap_or(None) .unwrap_or(None)
} }
} }
fn parent_create_element( fn parent_create_element(
&self, &self,
factory: &RTSPMediaFactory, factory: &Self::Type,
url: &gst_rtsp::RTSPUrl, url: &gst_rtsp::RTSPUrl,
) -> Option<gst::Element> { ) -> Option<gst::Element> {
unsafe { unsafe {
@ -122,14 +119,22 @@ impl<T: RTSPMediaFactoryImpl> RTSPMediaFactoryImplExt for T {
as *mut gst_rtsp_server_sys::GstRTSPMediaFactoryClass; as *mut gst_rtsp_server_sys::GstRTSPMediaFactoryClass;
(*parent_class) (*parent_class)
.create_element .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::<RTSPMediaFactory>()
.to_glib_none()
.0,
url.to_glib_none().0,
))
})
.unwrap_or(None) .unwrap_or(None)
} }
} }
fn parent_construct( fn parent_construct(
&self, &self,
factory: &RTSPMediaFactory, factory: &Self::Type,
url: &gst_rtsp::RTSPUrl, url: &gst_rtsp::RTSPUrl,
) -> Option<::RTSPMedia> { ) -> Option<::RTSPMedia> {
unsafe { unsafe {
@ -138,14 +143,22 @@ impl<T: RTSPMediaFactoryImpl> RTSPMediaFactoryImplExt for T {
as *mut gst_rtsp_server_sys::GstRTSPMediaFactoryClass; as *mut gst_rtsp_server_sys::GstRTSPMediaFactoryClass;
(*parent_class) (*parent_class)
.construct .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::<RTSPMediaFactory>()
.to_glib_none()
.0,
url.to_glib_none().0,
))
})
.unwrap_or(None) .unwrap_or(None)
} }
} }
fn parent_create_pipeline( fn parent_create_pipeline(
&self, &self,
factory: &RTSPMediaFactory, factory: &Self::Type,
media: &::RTSPMedia, media: &::RTSPMedia,
) -> Option<gst::Pipeline> { ) -> Option<gst::Pipeline> {
unsafe { unsafe {
@ -155,8 +168,13 @@ impl<T: RTSPMediaFactoryImpl> RTSPMediaFactoryImplExt for T {
(*parent_class) (*parent_class)
.create_pipeline .create_pipeline
.map(|f| { .map(|f| {
let ptr = f(factory.to_glib_none().0, media.to_glib_none().0) let ptr = f(
as *mut gst_sys::GstPipeline; factory
.unsafe_cast_ref::<RTSPMediaFactory>()
.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 // 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 { if gobject_sys::g_object_is_floating(ptr as *mut _) != glib_sys::GFALSE {
@ -168,35 +186,53 @@ impl<T: RTSPMediaFactoryImpl> RTSPMediaFactoryImplExt for T {
} }
} }
fn parent_configure(&self, factory: &RTSPMediaFactory, media: &::RTSPMedia) { fn parent_configure(&self, factory: &Self::Type, media: &::RTSPMedia) {
unsafe { unsafe {
let data = T::type_data(); let data = T::type_data();
let parent_class = data.as_ref().get_parent_class() let parent_class = data.as_ref().get_parent_class()
as *mut gst_rtsp_server_sys::GstRTSPMediaFactoryClass; as *mut gst_rtsp_server_sys::GstRTSPMediaFactoryClass;
if let Some(f) = (*parent_class).configure { if let Some(f) = (*parent_class).configure {
f(factory.to_glib_none().0, media.to_glib_none().0); f(
factory
.unsafe_cast_ref::<RTSPMediaFactory>()
.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 { unsafe {
let data = T::type_data(); let data = T::type_data();
let parent_class = data.as_ref().get_parent_class() let parent_class = data.as_ref().get_parent_class()
as *mut gst_rtsp_server_sys::GstRTSPMediaFactoryClass; as *mut gst_rtsp_server_sys::GstRTSPMediaFactoryClass;
if let Some(f) = (*parent_class).media_constructed { if let Some(f) = (*parent_class).media_constructed {
f(factory.to_glib_none().0, media.to_glib_none().0); f(
factory
.unsafe_cast_ref::<RTSPMediaFactory>()
.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 { unsafe {
let data = T::type_data(); let data = T::type_data();
let parent_class = data.as_ref().get_parent_class() let parent_class = data.as_ref().get_parent_class()
as *mut gst_rtsp_server_sys::GstRTSPMediaFactoryClass; as *mut gst_rtsp_server_sys::GstRTSPMediaFactoryClass;
if let Some(f) = (*parent_class).media_configure { if let Some(f) = (*parent_class).media_configure {
f(factory.to_glib_none().0, media.to_glib_none().0); f(
factory
.unsafe_cast_ref::<RTSPMediaFactory>()
.to_glib_none()
.0,
media.to_glib_none().0,
);
} }
} }
} }
@ -223,7 +259,8 @@ unsafe extern "C" fn factory_gen_key<T: RTSPMediaFactoryImpl>(
let imp = instance.get_impl(); let imp = instance.get_impl();
let wrap: Borrowed<RTSPMediaFactory> = from_glib_borrow(ptr); let wrap: Borrowed<RTSPMediaFactory> = 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<T: RTSPMediaFactoryImpl>( unsafe extern "C" fn factory_create_element<T: RTSPMediaFactoryImpl>(
@ -235,7 +272,7 @@ unsafe extern "C" fn factory_create_element<T: RTSPMediaFactoryImpl>(
let wrap: Borrowed<RTSPMediaFactory> = from_glib_borrow(ptr); let wrap: Borrowed<RTSPMediaFactory> = from_glib_borrow(ptr);
let element = imp let element = imp
.create_element(&wrap, &from_glib_borrow(url)) .create_element(wrap.unsafe_cast_ref(), &from_glib_borrow(url))
.to_glib_full(); .to_glib_full();
gobject_sys::g_object_force_floating(element as *mut _); gobject_sys::g_object_force_floating(element as *mut _);
element element
@ -249,7 +286,8 @@ unsafe extern "C" fn factory_construct<T: RTSPMediaFactoryImpl>(
let imp = instance.get_impl(); let imp = instance.get_impl();
let wrap: Borrowed<RTSPMediaFactory> = from_glib_borrow(ptr); let wrap: Borrowed<RTSPMediaFactory> = 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<T: RTSPMediaFactoryImpl>( unsafe extern "C" fn factory_create_pipeline<T: RTSPMediaFactoryImpl>(
@ -266,7 +304,7 @@ unsafe extern "C" fn factory_create_pipeline<T: RTSPMediaFactoryImpl>(
let wrap: Borrowed<RTSPMediaFactory> = from_glib_borrow(ptr); let wrap: Borrowed<RTSPMediaFactory> = from_glib_borrow(ptr);
let pipeline: *mut gst_sys::GstPipeline = imp 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(); .to_glib_full();
// FIXME We somehow need to ensure the pipeline actually stays alive... // FIXME We somehow need to ensure the pipeline actually stays alive...
@ -290,7 +328,7 @@ unsafe extern "C" fn factory_configure<T: RTSPMediaFactoryImpl>(
let imp = instance.get_impl(); let imp = instance.get_impl();
let wrap: Borrowed<RTSPMediaFactory> = from_glib_borrow(ptr); let wrap: Borrowed<RTSPMediaFactory> = 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<T: RTSPMediaFactoryImpl>( unsafe extern "C" fn factory_media_constructed<T: RTSPMediaFactoryImpl>(
@ -301,7 +339,7 @@ unsafe extern "C" fn factory_media_constructed<T: RTSPMediaFactoryImpl>(
let imp = instance.get_impl(); let imp = instance.get_impl();
let wrap: Borrowed<RTSPMediaFactory> = from_glib_borrow(ptr); let wrap: Borrowed<RTSPMediaFactory> = 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<T: RTSPMediaFactoryImpl>( unsafe extern "C" fn factory_media_configure<T: RTSPMediaFactoryImpl>(
@ -312,5 +350,5 @@ unsafe extern "C" fn factory_media_configure<T: RTSPMediaFactoryImpl>(
let imp = instance.get_impl(); let imp = instance.get_impl();
let wrap: Borrowed<RTSPMediaFactory> = from_glib_borrow(ptr); let wrap: Borrowed<RTSPMediaFactory> = from_glib_borrow(ptr);
imp.media_configure(&wrap, &from_glib_borrow(media)); imp.media_configure(wrap.unsafe_cast_ref(), &from_glib_borrow(media));
} }

View file

@ -8,29 +8,30 @@
use gst_rtsp_server_sys; use gst_rtsp_server_sys;
use glib::prelude::*;
use glib::subclass::prelude::*; use glib::subclass::prelude::*;
use glib::translate::*; use glib::translate::*;
use RTSPServer; use RTSPServer;
pub trait RTSPServerImpl: RTSPServerImplExt + ObjectImpl + Send + Sync { 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) 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); self.parent_client_connected(server, client);
} }
} }
pub trait RTSPServerImplExt { pub trait RTSPServerImplExt: ObjectSubclass {
fn parent_create_client(&self, server: &RTSPServer) -> Option<::RTSPClient>; 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<T: RTSPServerImpl> RTSPServerImplExt for T { impl<T: RTSPServerImpl> RTSPServerImplExt for T {
fn parent_create_client(&self, server: &RTSPServer) -> Option<::RTSPClient> { fn parent_create_client(&self, server: &Self::Type) -> Option<::RTSPClient> {
unsafe { unsafe {
let data = T::type_data(); let data = T::type_data();
let parent_class = let parent_class =
@ -38,17 +39,20 @@ impl<T: RTSPServerImpl> RTSPServerImplExt for T {
let f = (*parent_class) let f = (*parent_class)
.create_client .create_client
.expect("No `create_client` virtual method implementation in parent class"); .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::<RTSPServer>().to_glib_none().0))
} }
} }
fn parent_client_connected(&self, server: &RTSPServer, client: &::RTSPClient) { fn parent_client_connected(&self, server: &Self::Type, client: &::RTSPClient) {
unsafe { unsafe {
let data = T::type_data(); let data = T::type_data();
let parent_class = let parent_class =
data.as_ref().get_parent_class() as *mut gst_rtsp_server_sys::GstRTSPServerClass; data.as_ref().get_parent_class() as *mut gst_rtsp_server_sys::GstRTSPServerClass;
if let Some(f) = (*parent_class).client_connected { if let Some(f) = (*parent_class).client_connected {
f(server.to_glib_none().0, client.to_glib_none().0) f(
server.unsafe_cast_ref::<RTSPServer>().to_glib_none().0,
client.to_glib_none().0,
)
} }
} }
} }
@ -69,7 +73,7 @@ unsafe extern "C" fn server_create_client<T: RTSPServerImpl>(
let imp = instance.get_impl(); let imp = instance.get_impl();
let wrap: Borrowed<RTSPServer> = from_glib_borrow(ptr); let wrap: Borrowed<RTSPServer> = 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<T: RTSPServerImpl>( unsafe extern "C" fn server_client_connected<T: RTSPServerImpl>(
@ -80,5 +84,5 @@ unsafe extern "C" fn server_client_connected<T: RTSPServerImpl>(
let imp = instance.get_impl(); let imp = instance.get_impl();
let wrap: Borrowed<RTSPServer> = from_glib_borrow(ptr); let wrap: Borrowed<RTSPServer> = from_glib_borrow(ptr);
imp.client_connected(&wrap, &from_glib_borrow(client)); imp.client_connected(wrap.unsafe_cast_ref(), &from_glib_borrow(client));
} }