mirror of
https://gitlab.freedesktop.org/gstreamer/gst-plugins-rs.git
synced 2025-02-17 05:15:14 +00:00
Clean comments
This commit is contained in:
parent
8ce45f4f0d
commit
a41f33ae08
4 changed files with 10 additions and 175 deletions
|
@ -1,8 +1,8 @@
|
|||
[package]
|
||||
name = "gst-plugin-ndi"
|
||||
version = "0.1.0"
|
||||
version = "1.0.0"
|
||||
authors = ["Ruben Gonzalez <rubenrua@teltek.es>", "Daniel Vilar <daniel.peiteado@teltek.es>"]
|
||||
repository = "https://gitlab.teltek.es/rubenrua/ndi-rs.git"
|
||||
repository = "https://github.com/teltek/gst-plugin-ndi"
|
||||
license = "LGPL"
|
||||
|
||||
[dependencies]
|
||||
|
|
|
@ -1,13 +1,5 @@
|
|||
#![allow(non_camel_case_types, non_upper_case_globals, non_snake_case)]
|
||||
|
||||
// Copyright (C) 2017 Sebastian Dröge <sebastian@centricular.com>
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
|
||||
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
|
||||
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
|
||||
// option. This file may not be copied, modified, or distributed
|
||||
// except according to those terms.
|
||||
|
||||
extern crate glib;
|
||||
extern crate gobject_subclass;
|
||||
|
||||
|
@ -36,8 +28,6 @@ use std::sync::Mutex;
|
|||
|
||||
use gst::GstObjectExt;
|
||||
|
||||
// Plugin entry point that should register all elements provided by this plugin,
|
||||
// and everything else that this plugin might provide (e.g. typefinders or device providers).
|
||||
fn plugin_init(plugin: &gst::Plugin) -> bool {
|
||||
ndivideosrc::register(plugin);
|
||||
ndiaudiosrc::register(plugin);
|
||||
|
@ -107,21 +97,17 @@ fn connect_ndi(cat: gst::DebugCategory, element: &BaseSrc, ip: &str, stream_name
|
|||
gst::CoreError::Negotiation,
|
||||
["Cannot run NDI: NDIlib_initialize error"]
|
||||
);
|
||||
// return false;
|
||||
return 0;
|
||||
}
|
||||
|
||||
//TODO default values
|
||||
let NDI_find_create_desc: NDIlib_find_create_t = Default::default();
|
||||
let pNDI_find = NDIlib_find_create_v2(&NDI_find_create_desc);
|
||||
//let ip_ptr = CString::new(ip.clone()).unwrap();
|
||||
if pNDI_find.is_null() {
|
||||
gst_element_error!(
|
||||
element,
|
||||
gst::CoreError::Negotiation,
|
||||
["Cannot run NDI: NDIlib_find_create_v2 error"]
|
||||
);
|
||||
// return false;
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
@ -139,7 +125,6 @@ fn connect_ndi(cat: gst::DebugCategory, element: &BaseSrc, ip: &str, stream_name
|
|||
gst::CoreError::Negotiation,
|
||||
["Error getting NDIlib_find_get_current_sources"]
|
||||
);
|
||||
// return false;
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
@ -160,7 +145,6 @@ fn connect_ndi(cat: gst::DebugCategory, element: &BaseSrc, ip: &str, stream_name
|
|||
}
|
||||
if no_source == -1 {
|
||||
gst_element_error!(element, gst::ResourceError::OpenRead, ["Stream not found"]);
|
||||
// return false;
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
@ -186,9 +170,6 @@ fn connect_ndi(cat: gst::DebugCategory, element: &BaseSrc, ip: &str, stream_name
|
|||
.to_string_lossy()
|
||||
.into_owned();
|
||||
|
||||
// We now have at least one source, so we create a receiver to look at it.
|
||||
// We tell it that we prefer YCbCr video since it is more efficient for us. If the source has an alpha channel
|
||||
// it will still be provided in BGRA
|
||||
let p_ndi_name = CString::new("Galicaster NDI Receiver").unwrap();
|
||||
let NDI_recv_create_desc = NDIlib_recv_create_v3_t {
|
||||
source_to_connect_to: source,
|
||||
|
@ -198,26 +179,19 @@ fn connect_ndi(cat: gst::DebugCategory, element: &BaseSrc, ip: &str, stream_name
|
|||
|
||||
let pNDI_recv = NDIlib_recv_create_v3(&NDI_recv_create_desc);
|
||||
if pNDI_recv.is_null() {
|
||||
//println!("Cannot run NDI: NDIlib_recv_create_v3 error.");
|
||||
gst_element_error!(
|
||||
element,
|
||||
gst::CoreError::Negotiation,
|
||||
["Cannot run NDI: NDIlib_recv_create_v3 error"]
|
||||
);
|
||||
// return false;
|
||||
return 0;
|
||||
}
|
||||
|
||||
// Destroy the NDI finder. We needed to have access to the pointers to p_sources[0]
|
||||
NDIlib_find_destroy(pNDI_find);
|
||||
|
||||
// We are now going to mark this source as being on program output for tally purposes (but not on preview)
|
||||
let tally_state: NDIlib_tally_t = Default::default();
|
||||
NDIlib_recv_set_tally(pNDI_recv, &tally_state);
|
||||
|
||||
// Enable Hardware Decompression support if this support has it. Please read the caveats in the documentation
|
||||
// regarding this. There are times in which it might reduce the performance although on small stream numbers
|
||||
// it almost always yields the same or better performance.
|
||||
let data = CString::new("<ndi_hwaccel enabled=\"true\"/>").unwrap();
|
||||
let enable_hw_accel = NDIlib_metadata_frame_t {
|
||||
length: data.to_bytes().len() as i32,
|
||||
|
@ -240,12 +214,6 @@ fn connect_ndi(cat: gst::DebugCategory, element: &BaseSrc, ip: &str, stream_name
|
|||
},
|
||||
);
|
||||
|
||||
// let start = SystemTime::now();
|
||||
// let since_the_epoch = start.duration_since(UNIX_EPOCH)
|
||||
// .expect("Time went backwards");
|
||||
// println!("{:?}", since_the_epoch);
|
||||
// ndi_struct.start_pts = Some(since_the_epoch.as_secs() * 1000000000 +
|
||||
// since_the_epoch.subsec_nanos() as u64);
|
||||
gst_debug!(cat, obj: element, "Started NDI connection");
|
||||
id_receiver
|
||||
}
|
||||
|
@ -278,19 +246,14 @@ fn stop_ndi(cat: gst::DebugCategory, element: &BaseSrc, id: i8) -> bool {
|
|||
true
|
||||
}
|
||||
|
||||
// Static plugin metdata that is directly stored in the plugin shared object and read by GStreamer
|
||||
// upon loading.
|
||||
// Plugin name, plugin description, plugin entry point function, version number of this plugin,
|
||||
// license of the plugin, source package name, binary package name, origin where it comes from
|
||||
// and the date/time of release.
|
||||
plugin_define!(
|
||||
b"ndi\0",
|
||||
b"NewTek NDI Plugin\0",
|
||||
plugin_init,
|
||||
b"1.0\0",
|
||||
b"MIT/X11\0",
|
||||
b"1.0.0\0",
|
||||
b"LGPL\0",
|
||||
b"ndi\0",
|
||||
b"ndi\0",
|
||||
b"https://gitlab.teltek.es/rubenrua/ndi-rs.git\0",
|
||||
b"https://github.com/teltek/gst-plugin-ndi\0",
|
||||
b"2018-04-09\0"
|
||||
);
|
||||
|
|
|
@ -22,7 +22,6 @@ use stop_ndi;
|
|||
|
||||
use hashmap_receivers;
|
||||
|
||||
// Property value storage
|
||||
#[derive(Debug, Clone)]
|
||||
struct Settings {
|
||||
stream_name: String,
|
||||
|
@ -40,7 +39,6 @@ impl Default for Settings {
|
|||
}
|
||||
}
|
||||
|
||||
// Metadata for the properties
|
||||
static PROPERTIES: [Property; 2] = [
|
||||
Property::String(
|
||||
"stream-name",
|
||||
|
@ -58,8 +56,6 @@ static PROPERTIES: [Property; 2] = [
|
|||
),
|
||||
];
|
||||
|
||||
// Stream-specific state, i.e. audio format configuration
|
||||
// and sample offset
|
||||
struct State {
|
||||
info: Option<gst_audio::AudioInfo>,
|
||||
}
|
||||
|
@ -74,7 +70,6 @@ struct TimestampData {
|
|||
offset: u64,
|
||||
}
|
||||
|
||||
// Struct containing all the element data
|
||||
struct NdiAudioSrc {
|
||||
cat: gst::DebugCategory,
|
||||
settings: Mutex<Settings>,
|
||||
|
@ -83,10 +78,7 @@ struct NdiAudioSrc {
|
|||
}
|
||||
|
||||
impl NdiAudioSrc {
|
||||
// Called when a new instance is to be created
|
||||
fn new(element: &BaseSrc) -> Box<BaseSrcImpl<BaseSrc>> {
|
||||
// Initialize live-ness and notify the base class that
|
||||
// we'd like to operate in Time format
|
||||
element.set_live(true);
|
||||
element.set_format(gst::Format::Time);
|
||||
|
||||
|
@ -102,16 +94,6 @@ impl NdiAudioSrc {
|
|||
})
|
||||
}
|
||||
|
||||
// Called exactly once when registering the type. Used for
|
||||
// setting up metadata for all instances, e.g. the name and
|
||||
// classification and the pad templates with their caps.
|
||||
//
|
||||
// Actual instances can create pads based on those pad templates
|
||||
// with a subset of the caps given here. In case of basesrc,
|
||||
// a "src" and "sink" pad template are required here and the base class
|
||||
// will automatically instantiate pads for them.
|
||||
//
|
||||
// Our element here can output f32 and f64
|
||||
fn class_init(klass: &mut BaseSrcClass) {
|
||||
klass.set_metadata(
|
||||
"NewTek NDI Audio Source",
|
||||
|
@ -120,15 +102,13 @@ impl NdiAudioSrc {
|
|||
"Ruben Gonzalez <rubenrua@teltek.es>, Daniel Vilar <daniel.peiteado@teltek.es>",
|
||||
);
|
||||
|
||||
// On the src pad, we can produce F32/F64 with any sample rate
|
||||
// and any number of channels
|
||||
let caps = gst::Caps::new_simple(
|
||||
"audio/x-raw",
|
||||
&[
|
||||
(
|
||||
"format",
|
||||
&gst::List::new(&[
|
||||
//TODO add all formats?
|
||||
//TODO add more formats?
|
||||
&gst_audio::AUDIO_FORMAT_F32.to_string(),
|
||||
&gst_audio::AUDIO_FORMAT_F64.to_string(),
|
||||
&gst_audio::AUDIO_FORMAT_S16.to_string(),
|
||||
|
@ -139,26 +119,20 @@ impl NdiAudioSrc {
|
|||
("layout", &"interleaved"),
|
||||
],
|
||||
);
|
||||
// The src pad template must be named "src" for basesrc
|
||||
// and specific a pad that is always there
|
||||
|
||||
let src_pad_template = gst::PadTemplate::new(
|
||||
"src",
|
||||
gst::PadDirection::Src,
|
||||
gst::PadPresence::Always,
|
||||
&caps,
|
||||
//&gst::Caps::new_any(),
|
||||
);
|
||||
klass.add_pad_template(src_pad_template);
|
||||
|
||||
// Install all our properties
|
||||
klass.install_properties(&PROPERTIES);
|
||||
}
|
||||
}
|
||||
|
||||
// Virtual methods of GObject itself
|
||||
impl ObjectImpl<BaseSrc> for NdiAudioSrc {
|
||||
// Called whenever a value of a property is changed. It can be called
|
||||
// at any time from any thread.
|
||||
fn set_property(&self, obj: &glib::Object, id: u32, value: &glib::Value) {
|
||||
let prop = &PROPERTIES[id as usize];
|
||||
let element = obj.clone().downcast::<BaseSrc>().unwrap();
|
||||
|
@ -200,20 +174,16 @@ impl ObjectImpl<BaseSrc> for NdiAudioSrc {
|
|||
}
|
||||
}
|
||||
|
||||
// Called whenever a value of a property is read. It can be called
|
||||
// at any time from any thread.
|
||||
fn get_property(&self, _obj: &glib::Object, id: u32) -> Result<glib::Value, ()> {
|
||||
let prop = &PROPERTIES[id as usize];
|
||||
|
||||
match *prop {
|
||||
Property::String("stream-name", ..) => {
|
||||
let settings = self.settings.lock().unwrap();
|
||||
//TODO to_value supongo que solo funciona con numeros
|
||||
Ok(settings.stream_name.to_value())
|
||||
}
|
||||
Property::String("ip", ..) => {
|
||||
let settings = self.settings.lock().unwrap();
|
||||
//TODO to_value supongo que solo funciona con numeros
|
||||
Ok(settings.ip.to_value())
|
||||
}
|
||||
_ => unimplemented!(),
|
||||
|
@ -221,7 +191,6 @@ impl ObjectImpl<BaseSrc> for NdiAudioSrc {
|
|||
}
|
||||
}
|
||||
|
||||
// Virtual methods of gst::Element. We override none
|
||||
impl ElementImpl<BaseSrc> for NdiAudioSrc {
|
||||
fn change_state(
|
||||
&self,
|
||||
|
@ -261,14 +230,7 @@ impl ElementImpl<BaseSrc> for NdiAudioSrc {
|
|||
}
|
||||
}
|
||||
|
||||
// Virtual methods of gst_base::BaseSrc
|
||||
impl BaseSrcImpl<BaseSrc> for NdiAudioSrc {
|
||||
// Called whenever the input/output caps are changing, i.e. in the very beginning before data
|
||||
// flow happens and whenever the situation in the pipeline is changing. All buffers after this
|
||||
// call have the caps given here.
|
||||
//
|
||||
// We simply remember the resulting AudioInfo from the caps to be able to use this for knowing
|
||||
// the sample rate, etc. when creating buffers
|
||||
fn set_caps(&self, element: &BaseSrc, caps: &gst::CapsRef) -> bool {
|
||||
let info = match gst_audio::AudioInfo::from_caps(caps) {
|
||||
None => return false,
|
||||
|
@ -277,16 +239,13 @@ impl BaseSrcImpl<BaseSrc> for NdiAudioSrc {
|
|||
|
||||
gst_debug!(self.cat, obj: element, "Configuring for caps {}", caps);
|
||||
|
||||
// TODO Puede que falle si no creamos la estructura de cero, pero si lo hacemos no podemos poner recv a none
|
||||
let mut state = self.state.lock().unwrap();
|
||||
state.info = Some(info);
|
||||
|
||||
true
|
||||
}
|
||||
|
||||
// Called when starting, so we can initialize all stream-related state to its defaults
|
||||
fn start(&self, element: &BaseSrc) -> bool {
|
||||
// Reset state
|
||||
*self.state.lock().unwrap() = Default::default();
|
||||
|
||||
let mut settings = self.settings.lock().unwrap();
|
||||
|
@ -300,9 +259,7 @@ impl BaseSrcImpl<BaseSrc> for NdiAudioSrc {
|
|||
settings.id_receiver != 0
|
||||
}
|
||||
|
||||
// Called when shutting down the element so we can release all stream-related state
|
||||
fn stop(&self, element: &BaseSrc) -> bool {
|
||||
// Reset state
|
||||
*self.state.lock().unwrap() = Default::default();
|
||||
|
||||
let settings = self.settings.lock().unwrap();
|
||||
|
@ -323,7 +280,6 @@ impl BaseSrcImpl<BaseSrc> for NdiAudioSrc {
|
|||
}
|
||||
|
||||
fn fixate(&self, element: &BaseSrc, caps: gst::Caps) -> gst::Caps {
|
||||
//We need to set the correct caps resolution and framerate
|
||||
let receivers = hashmap_receivers.lock().unwrap();
|
||||
let settings = self.settings.lock().unwrap();
|
||||
|
||||
|
@ -345,31 +301,23 @@ impl BaseSrcImpl<BaseSrc> for NdiAudioSrc {
|
|||
{
|
||||
let caps = caps.make_mut();
|
||||
let s = caps.get_mut_structure(0).unwrap();
|
||||
//s.fixate_field_nearest_int("rate", audio_frame.sample_rate);
|
||||
s.fixate_field_nearest_int("rate", audio_frame.sample_rate / audio_frame.no_channels);
|
||||
s.fixate_field_nearest_int("channels", audio_frame.no_channels);
|
||||
}
|
||||
|
||||
// Let BaseSrc fixate anything else for us. We could've alternatively have
|
||||
// called Caps::fixate() here
|
||||
element.parent_fixate(caps)
|
||||
// }
|
||||
}
|
||||
|
||||
//Creates the audio buffers
|
||||
fn create(
|
||||
&self,
|
||||
element: &BaseSrc,
|
||||
_offset: u64,
|
||||
_length: u32,
|
||||
) -> Result<gst::Buffer, gst::FlowReturn> {
|
||||
// Keep a local copy of the values of all our properties at this very moment. This
|
||||
// ensures that the mutex is never locked for long and the application wouldn't
|
||||
// have to block until this function returns when getting/setting property values
|
||||
let _settings = &*self.settings.lock().unwrap();
|
||||
|
||||
let mut timestamp_data = self.timestamp_data.lock().unwrap();
|
||||
// Get a locked reference to our state, i.e. the input and output AudioInfo
|
||||
|
||||
let state = self.state.lock().unwrap();
|
||||
let _info = match state.info {
|
||||
None => {
|
||||
|
@ -440,16 +388,8 @@ impl BaseSrcImpl<BaseSrc> for NdiAudioSrc {
|
|||
}
|
||||
}
|
||||
|
||||
// This zero-sized struct is containing the static metadata of our element. It is only necessary to
|
||||
// be able to implement traits on it, but e.g. a plugin that registers multiple elements with the
|
||||
// same code would use this struct to store information about the concrete element. An example of
|
||||
// this would be a plugin that wraps around a library that has multiple decoders with the same API,
|
||||
// but wants (as it should) a separate element registered for each decoder.
|
||||
struct NdiAudioSrcStatic;
|
||||
|
||||
// The basic trait for registering the type: This returns a name for the type and registers the
|
||||
// instance and class initializations functions with the type system, thus hooking everything
|
||||
// together.
|
||||
impl ImplTypeStatic<BaseSrc> for NdiAudioSrcStatic {
|
||||
fn get_name(&self) -> &str {
|
||||
"NdiAudioSrc"
|
||||
|
@ -464,9 +404,6 @@ impl ImplTypeStatic<BaseSrc> for NdiAudioSrcStatic {
|
|||
}
|
||||
}
|
||||
|
||||
// Registers the type for our element, and then registers in GStreamer under
|
||||
// the name NdiAudioSrc for being able to instantiate it via e.g.
|
||||
// gst::ElementFactory::make().
|
||||
pub fn register(plugin: &gst::Plugin) {
|
||||
let type_ = register_type(NdiAudioSrcStatic);
|
||||
gst::Element::register(plugin, "ndiaudiosrc", 0, type_);
|
||||
|
|
|
@ -23,7 +23,6 @@ use stop_ndi;
|
|||
|
||||
use hashmap_receivers;
|
||||
|
||||
// Property value storage
|
||||
#[derive(Debug, Clone)]
|
||||
struct Settings {
|
||||
stream_name: String,
|
||||
|
@ -43,7 +42,6 @@ impl Default for Settings {
|
|||
}
|
||||
}
|
||||
|
||||
// Metadata for the properties
|
||||
static PROPERTIES: [Property; 2] = [
|
||||
Property::String(
|
||||
"stream-name",
|
||||
|
@ -61,8 +59,6 @@ static PROPERTIES: [Property; 2] = [
|
|||
),
|
||||
];
|
||||
|
||||
// Stream-specific state, i.e. audio format configuration
|
||||
// and sample offset
|
||||
struct State {
|
||||
info: Option<gst_video::VideoInfo>,
|
||||
}
|
||||
|
@ -77,7 +73,6 @@ struct TimestampData {
|
|||
offset: u64,
|
||||
}
|
||||
|
||||
// Struct containing all the element data
|
||||
struct NdiVideoSrc {
|
||||
cat: gst::DebugCategory,
|
||||
settings: Mutex<Settings>,
|
||||
|
@ -86,10 +81,7 @@ struct NdiVideoSrc {
|
|||
}
|
||||
|
||||
impl NdiVideoSrc {
|
||||
// Called when a new instance is to be created
|
||||
fn new(element: &BaseSrc) -> Box<BaseSrcImpl<BaseSrc>> {
|
||||
// Initialize live-ness and notify the base class that
|
||||
// we'd like to operate in Time format
|
||||
element.set_live(true);
|
||||
element.set_format(gst::Format::Time);
|
||||
|
||||
|
@ -105,16 +97,6 @@ impl NdiVideoSrc {
|
|||
})
|
||||
}
|
||||
|
||||
// Called exactly once when registering the type. Used for
|
||||
// setting up metadata for all instances, e.g. the name and
|
||||
// classification and the pad templates with their caps.
|
||||
//
|
||||
// Actual instances can create pads based on those pad templates
|
||||
// with a subset of the caps given here. In case of basesrc,
|
||||
// a "src" and "sink" pad template are required here and the base class
|
||||
// will automatically instantiate pads for them.
|
||||
//
|
||||
// Our element here can output f32 and f64
|
||||
fn class_init(klass: &mut BaseSrcClass) {
|
||||
klass.set_metadata(
|
||||
"NewTek NDI Video Source",
|
||||
|
@ -131,7 +113,7 @@ impl NdiVideoSrc {
|
|||
(
|
||||
"format",
|
||||
&gst::List::new(&[
|
||||
//TODO add all formats?
|
||||
//TODO add all formats
|
||||
&gst_video::VideoFormat::Uyvy.to_string(),
|
||||
//&gst_video::VideoFormat::Rgb.to_string(),
|
||||
//&gst_video::VideoFormat::Gray8.to_string(),
|
||||
|
@ -148,26 +130,20 @@ impl NdiVideoSrc {
|
|||
),
|
||||
],
|
||||
);
|
||||
// The src pad template must be named "src" for basesrc
|
||||
// and specific a pad that is always there
|
||||
|
||||
let src_pad_template = gst::PadTemplate::new(
|
||||
"src",
|
||||
gst::PadDirection::Src,
|
||||
gst::PadPresence::Always,
|
||||
&caps,
|
||||
//&gst::Caps::new_any(),
|
||||
);
|
||||
klass.add_pad_template(src_pad_template);
|
||||
|
||||
// Install all our properties
|
||||
klass.install_properties(&PROPERTIES);
|
||||
}
|
||||
}
|
||||
|
||||
// Virtual methods of GObject itself
|
||||
impl ObjectImpl<BaseSrc> for NdiVideoSrc {
|
||||
// Called whenever a value of a property is changed. It can be called
|
||||
// at any time from any thread.
|
||||
fn set_property(&self, obj: &glib::Object, id: u32, value: &glib::Value) {
|
||||
let prop = &PROPERTIES[id as usize];
|
||||
let element = obj.clone().downcast::<BaseSrc>().unwrap();
|
||||
|
@ -185,9 +161,6 @@ impl ObjectImpl<BaseSrc> for NdiVideoSrc {
|
|||
);
|
||||
settings.stream_name = stream_name;
|
||||
drop(settings);
|
||||
|
||||
// let _ =
|
||||
// element.post_message(&gst::Message::new_latency().src(Some(&element)).build());
|
||||
}
|
||||
Property::String("ip", ..) => {
|
||||
let mut settings = self.settings.lock().unwrap();
|
||||
|
@ -201,16 +174,11 @@ impl ObjectImpl<BaseSrc> for NdiVideoSrc {
|
|||
);
|
||||
settings.ip = ip;
|
||||
drop(settings);
|
||||
|
||||
// let _ =
|
||||
// element.post_message(&gst::Message::new_latency().src(Some(&element)).build());
|
||||
}
|
||||
_ => unimplemented!(),
|
||||
}
|
||||
}
|
||||
|
||||
// Called whenever a value of a property is read. It can be called
|
||||
// at any time from any thread.
|
||||
fn get_property(&self, _obj: &glib::Object, id: u32) -> Result<glib::Value, ()> {
|
||||
let prop = &PROPERTIES[id as usize];
|
||||
|
||||
|
@ -228,7 +196,6 @@ impl ObjectImpl<BaseSrc> for NdiVideoSrc {
|
|||
}
|
||||
}
|
||||
|
||||
// Virtual methods of gst::Element. We override none
|
||||
impl ElementImpl<BaseSrc> for NdiVideoSrc {
|
||||
fn change_state(
|
||||
&self,
|
||||
|
@ -268,14 +235,7 @@ impl ElementImpl<BaseSrc> for NdiVideoSrc {
|
|||
}
|
||||
}
|
||||
|
||||
// Virtual methods of gst_base::BaseSrc
|
||||
impl BaseSrcImpl<BaseSrc> for NdiVideoSrc {
|
||||
// Called whenever the input/output caps are changing, i.e. in the very beginning before data
|
||||
// flow happens and whenever the situation in the pipeline is changing. All buffers after this
|
||||
// call have the caps given here.
|
||||
//
|
||||
// We simply remember the resulting AudioInfo from the caps to be able to use this for knowing
|
||||
// the sample rate, etc. when creating buffers
|
||||
fn set_caps(&self, element: &BaseSrc, caps: &gst::CapsRef) -> bool {
|
||||
let info = match gst_video::VideoInfo::from_caps(caps) {
|
||||
None => return false,
|
||||
|
@ -283,16 +243,13 @@ impl BaseSrcImpl<BaseSrc> for NdiVideoSrc {
|
|||
};
|
||||
gst_debug!(self.cat, obj: element, "Configuring for caps {}", caps);
|
||||
|
||||
// TODO Puede que falle si no creamos la estructura de cero, pero si lo hacemos no podemos poner recv a none
|
||||
let mut state = self.state.lock().unwrap();
|
||||
state.info = Some(info);
|
||||
let _ = element.post_message(&gst::Message::new_latency().src(Some(element)).build());
|
||||
true
|
||||
}
|
||||
|
||||
// Called when starting, so we can initialize all stream-related state to its defaults
|
||||
fn start(&self, element: &BaseSrc) -> bool {
|
||||
// Reset state
|
||||
*self.state.lock().unwrap() = Default::default();
|
||||
let mut settings = self.settings.lock().unwrap();
|
||||
settings.id_receiver = connect_ndi(
|
||||
|
@ -305,9 +262,7 @@ impl BaseSrcImpl<BaseSrc> for NdiVideoSrc {
|
|||
settings.id_receiver != 0
|
||||
}
|
||||
|
||||
// Called when shutting down the element so we can release all stream-related state
|
||||
fn stop(&self, element: &BaseSrc) -> bool {
|
||||
// Reset state
|
||||
*self.state.lock().unwrap() = Default::default();
|
||||
|
||||
let settings = self.settings.lock().unwrap();
|
||||
|
@ -328,7 +283,6 @@ impl BaseSrcImpl<BaseSrc> for NdiVideoSrc {
|
|||
}
|
||||
|
||||
fn fixate(&self, element: &BaseSrc, caps: gst::Caps) -> gst::Caps {
|
||||
//We need to set the correct caps resolution and framerate
|
||||
let receivers = hashmap_receivers.lock().unwrap();
|
||||
let settings = self.settings.lock().unwrap();
|
||||
|
||||
|
@ -358,9 +312,6 @@ impl BaseSrcImpl<BaseSrc> for NdiVideoSrc {
|
|||
);
|
||||
}
|
||||
|
||||
// Let BaseSrc fixate anything else for us. We could've alternatively have
|
||||
// called Caps::fixate() here
|
||||
|
||||
let _ = element.post_message(&gst::Message::new_latency().src(Some(element)).build());
|
||||
element.parent_fixate(caps)
|
||||
}
|
||||
|
@ -372,13 +323,9 @@ impl BaseSrcImpl<BaseSrc> for NdiVideoSrc {
|
|||
_offset: u64,
|
||||
_length: u32,
|
||||
) -> Result<gst::Buffer, gst::FlowReturn> {
|
||||
// Keep a local copy of the values of all our properties at this very moment. This
|
||||
// ensures that the mutex is never locked for long and the application wouldn't
|
||||
// have to block until this function returns when getting/setting property values
|
||||
let _settings = &*self.settings.lock().unwrap();
|
||||
|
||||
let mut timestamp_data = self.timestamp_data.lock().unwrap();
|
||||
// Get a locked reference to our state, i.e. the input and output AudioInfo
|
||||
let state = self.state.lock().unwrap();
|
||||
let _info = match state.info {
|
||||
None => {
|
||||
|
@ -387,7 +334,6 @@ impl BaseSrcImpl<BaseSrc> for NdiVideoSrc {
|
|||
}
|
||||
Some(ref info) => info.clone(),
|
||||
};
|
||||
// unsafe{
|
||||
let receivers = hashmap_receivers.lock().unwrap();
|
||||
|
||||
let recv = &receivers.get(&_settings.id_receiver).unwrap().ndi_instance;
|
||||
|
@ -450,16 +396,8 @@ impl BaseSrcImpl<BaseSrc> for NdiVideoSrc {
|
|||
}
|
||||
}
|
||||
|
||||
// This zero-sized struct is containing the static metadata of our element. It is only necessary to
|
||||
// be able to implement traits on it, but e.g. a plugin that registers multiple elements with the
|
||||
// same code would use this struct to store information about the concrete element. An example of
|
||||
// this would be a plugin that wraps around a library that has multiple decoders with the same API,
|
||||
// but wants (as it should) a separate element registered for each decoder.
|
||||
struct NdiVideoSrcStatic;
|
||||
|
||||
// The basic trait for registering the type: This returns a name for the type and registers the
|
||||
// instance and class initializations functions with the type system, thus hooking everything
|
||||
// together.
|
||||
impl ImplTypeStatic<BaseSrc> for NdiVideoSrcStatic {
|
||||
fn get_name(&self) -> &str {
|
||||
"NdiVideoSrc"
|
||||
|
@ -474,9 +412,6 @@ impl ImplTypeStatic<BaseSrc> for NdiVideoSrcStatic {
|
|||
}
|
||||
}
|
||||
|
||||
// Registers the type for our element, and then registers in GStreamer under
|
||||
// the name NdiVideoSrc for being able to instantiate it via e.g.
|
||||
// gst::ElementFactory::make().
|
||||
pub fn register(plugin: &gst::Plugin) {
|
||||
let type_ = register_type(NdiVideoSrcStatic);
|
||||
gst::Element::register(plugin, "ndivideosrc", 0, type_);
|
||||
|
|
Loading…
Reference in a new issue