-
Notifications
You must be signed in to change notification settings - Fork 30
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
src: stream: Add Custom RTSP Media Factory
- Loading branch information
1 parent
2d09e91
commit 21614db
Showing
2 changed files
with
79 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,2 @@ | ||
mod rtsp_media_factory; | ||
pub mod rtsp_server; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
/// /References: | ||
/// 1 - https://gitlab.freedesktop.org/slomo/rtp-rapid-sync-example | ||
/// 2 - https://github.com/gtk-rs/gtk3-rs/blob/master/examples/list_box_model/row_data/imp.rs | ||
mod imp { | ||
use std::sync::{Arc, Mutex}; | ||
|
||
use once_cell::sync::Lazy; | ||
|
||
use gst::{ | ||
glib::{self, subclass::prelude::*, *}, | ||
prelude::*, | ||
}; | ||
use gst_rtsp_server::subclass::prelude::*; | ||
|
||
// The actual data structure that stores our values. This is not accessible | ||
// directly from the outside. | ||
#[derive(Default)] | ||
pub struct Factory { | ||
bin: Arc<Mutex<gst::Bin>>, | ||
} | ||
|
||
// Basic declaration of our type for the GObject type system | ||
#[glib::object_subclass] | ||
impl ObjectSubclass for Factory { | ||
const NAME: &'static str = "RTSPMediaFactoryFromBin"; | ||
type Type = super::Factory; | ||
type ParentType = gst_rtsp_server::RTSPMediaFactory; | ||
} | ||
|
||
// The ObjectImpl trait provides the setters/getters for GObject properties. | ||
// Here we need to provide the values that are internally stored back to the | ||
// caller, or store whatever new value the caller is providing. | ||
// | ||
// This maps between the GObject properties and our internal storage of the | ||
// corresponding values of the properties. | ||
impl ObjectImpl for Factory { | ||
fn properties() -> &'static [glib::ParamSpec] { | ||
static PROPERTIES: Lazy<Vec<glib::ParamSpec>> = Lazy::new(|| { | ||
vec![glib::ParamSpecObject::builder::<gst::Bin>("bin") | ||
.construct_only() | ||
.build()] | ||
}); | ||
|
||
PROPERTIES.as_ref() | ||
} | ||
|
||
fn set_property(&self, _id: usize, value: &glib::Value, pspec: &glib::ParamSpec) { | ||
match pspec.name() { | ||
"bin" => { | ||
let bin = value.get().unwrap(); | ||
self.bin.set(bin); | ||
} | ||
_ => unimplemented!(), | ||
} | ||
} | ||
} | ||
|
||
impl RTSPMediaFactoryImpl for Factory { | ||
// Create the custom stream producer bin. | ||
fn create_element(&self, _url: &gst_rtsp::RTSPUrl) -> Option<gst::Element> { | ||
let bin = self.bin.lock().unwrap(); | ||
bin.debug_to_dot_file_with_ts(gst::DebugGraphDetails::all(), "rtsp-bin-created"); | ||
|
||
Some(bin.to_owned().upcast()) | ||
} | ||
} | ||
} | ||
|
||
gst::glib::wrapper! { | ||
pub struct Factory(ObjectSubclass<imp::Factory>) @extends gst_rtsp_server::RTSPMediaFactory; | ||
} | ||
|
||
// Trivial constructor for the media factory. | ||
impl Factory { | ||
pub fn new(bin: gst::Bin) -> Self { | ||
gst::glib::Object::builder().property("bin", bin).build() | ||
} | ||
} |