forked from mirrors/gstreamer-rs
rtsp-server: Add support for subclassing GstRtspMountPoints
Implement MountPointsImpl and MountPointsExt to allow subclassing. Update the example to show usage.
This commit is contained in:
parent
7bb9a0df70
commit
0adc8c44df
3 changed files with 131 additions and 0 deletions
|
@ -26,6 +26,10 @@ struct UsageError(#[error(not(source))] String);
|
|||
fn main_loop() -> Result<(), Error> {
|
||||
let main_loop = glib::MainLoop::new(None, false);
|
||||
let server = server::Server::default();
|
||||
|
||||
let mounts = mount_points::MountPoints::default();
|
||||
server.set_mount_points(Some(&mounts));
|
||||
|
||||
// Much like HTTP servers, RTSP servers have multiple endpoints that
|
||||
// provide different streams. Here, we ask our server to give
|
||||
// us a reference to his list of endpoints, so we can add our
|
||||
|
@ -329,6 +333,58 @@ mod client {
|
|||
}
|
||||
}
|
||||
|
||||
mod mount_points {
|
||||
use gst_rtsp_server::subclass::prelude::*;
|
||||
|
||||
mod imp {
|
||||
use super::*;
|
||||
|
||||
// This is the private data of our mount points
|
||||
#[derive(Default)]
|
||||
pub struct MountPoints {}
|
||||
|
||||
// This trait registers our type with the GObject object system and
|
||||
// provides the entry points for creating a new instance and setting
|
||||
// up the class data
|
||||
#[glib::object_subclass]
|
||||
impl ObjectSubclass for MountPoints {
|
||||
const NAME: &'static str = "RsRTSPMountPoints";
|
||||
type Type = super::MountPoints;
|
||||
type ParentType = gst_rtsp_server::RTSPMountPoints;
|
||||
}
|
||||
|
||||
// Implementation of glib::Object virtual methods
|
||||
impl ObjectImpl for MountPoints {}
|
||||
|
||||
// Implementation of gst_rtsp_server::RTSPClient virtual methods
|
||||
impl RTSPMountPointsImpl for MountPoints {
|
||||
fn make_path(
|
||||
&self,
|
||||
mount_points: &Self::Type,
|
||||
url: &gst_rtsp::RTSPUrl,
|
||||
) -> Option<glib::GString> {
|
||||
println!("Make path called for {:?} ", url);
|
||||
self.parent_make_path(mount_points, url)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
glib::wrapper! {
|
||||
pub struct MountPoints(ObjectSubclass<imp::MountPoints>) @extends gst_rtsp_server::RTSPMountPoints;
|
||||
}
|
||||
|
||||
// MountPoints must be Send+Sync, and ours is
|
||||
unsafe impl Send for MountPoints {}
|
||||
unsafe impl Sync for MountPoints {}
|
||||
|
||||
impl Default for MountPoints {
|
||||
// Creates a new instance of our factory
|
||||
fn default() -> Self {
|
||||
glib::Object::new(&[]).expect("Failed to create mount points")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fn example_main() -> Result<(), Error> {
|
||||
gst::init()?;
|
||||
main_loop()
|
||||
|
|
|
@ -5,6 +5,7 @@
|
|||
mod rtsp_client;
|
||||
mod rtsp_media;
|
||||
mod rtsp_media_factory;
|
||||
mod rtsp_mount_points;
|
||||
mod rtsp_server;
|
||||
|
||||
pub use self::rtsp_media::SDPInfo;
|
||||
|
@ -16,5 +17,6 @@ pub mod prelude {
|
|||
pub use super::rtsp_client::{RTSPClientImpl, RTSPClientImplExt};
|
||||
pub use super::rtsp_media::{RTSPMediaImpl, RTSPMediaImplExt};
|
||||
pub use super::rtsp_media_factory::{RTSPMediaFactoryImpl, RTSPMediaFactoryImplExt};
|
||||
pub use super::rtsp_mount_points::{RTSPMountPointsImpl, RTSPMountPointsImplExt};
|
||||
pub use super::rtsp_server::{RTSPServerImpl, RTSPServerImplExt};
|
||||
}
|
||||
|
|
73
gstreamer-rtsp-server/src/subclass/rtsp_mount_points.rs
Normal file
73
gstreamer-rtsp-server/src/subclass/rtsp_mount_points.rs
Normal file
|
@ -0,0 +1,73 @@
|
|||
// Take a look at the license at the top of the repository in the LICENSE file.
|
||||
|
||||
use glib::prelude::*;
|
||||
use glib::subclass::prelude::*;
|
||||
use glib::translate::*;
|
||||
use gst_rtsp::ffi::GstRTSPUrl;
|
||||
|
||||
use crate::RTSPMountPoints;
|
||||
|
||||
pub trait RTSPMountPointsImpl: RTSPMountPointsImplExt + ObjectImpl + Send + Sync {
|
||||
fn make_path(
|
||||
&self,
|
||||
mount_points: &Self::Type,
|
||||
url: &gst_rtsp::RTSPUrl,
|
||||
) -> Option<glib::GString> {
|
||||
self.parent_make_path(mount_points, url)
|
||||
}
|
||||
}
|
||||
|
||||
pub trait RTSPMountPointsImplExt: ObjectSubclass {
|
||||
fn parent_make_path(
|
||||
&self,
|
||||
mount_points: &Self::Type,
|
||||
url: &gst_rtsp::RTSPUrl,
|
||||
) -> Option<glib::GString>;
|
||||
}
|
||||
|
||||
impl<T: RTSPMountPointsImpl> RTSPMountPointsImplExt for T {
|
||||
fn parent_make_path(
|
||||
&self,
|
||||
mount_points: &Self::Type,
|
||||
url: &gst_rtsp::RTSPUrl,
|
||||
) -> Option<glib::GString> {
|
||||
unsafe {
|
||||
let data = Self::type_data();
|
||||
let parent_class = data.as_ref().parent_class() as *mut ffi::GstRTSPMountPointsClass;
|
||||
let f = (*parent_class)
|
||||
.make_path
|
||||
.expect("No `make_path` virtual method implementation in parent class");
|
||||
from_glib_full(f(
|
||||
mount_points
|
||||
.unsafe_cast_ref::<RTSPMountPoints>()
|
||||
.to_glib_none()
|
||||
.0,
|
||||
url.to_glib_none().0,
|
||||
))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
unsafe impl<T: RTSPMountPointsImpl> IsSubclassable<T> for RTSPMountPoints {
|
||||
fn class_init(klass: &mut glib::Class<Self>) {
|
||||
<glib::Object as IsSubclassable<T>>::class_init(klass);
|
||||
let klass = klass.as_mut();
|
||||
klass.make_path = Some(mount_points_make_path::<T>);
|
||||
}
|
||||
|
||||
fn instance_init(instance: &mut glib::subclass::InitializingObject<T>) {
|
||||
<glib::Object as IsSubclassable<T>>::instance_init(instance);
|
||||
}
|
||||
}
|
||||
|
||||
unsafe extern "C" fn mount_points_make_path<T: RTSPMountPointsImpl>(
|
||||
ptr: *mut ffi::GstRTSPMountPoints,
|
||||
url: *const GstRTSPUrl,
|
||||
) -> *mut std::os::raw::c_char {
|
||||
let instance = &*(ptr as *mut T::Instance);
|
||||
let imp = instance.impl_();
|
||||
let wrap: Borrowed<RTSPMountPoints> = from_glib_borrow(ptr);
|
||||
|
||||
imp.make_path(wrap.unsafe_cast_ref(), &from_glib_borrow(url))
|
||||
.to_glib_full()
|
||||
}
|
Loading…
Reference in a new issue