Port to new glib subclassing API #13

This commit is contained in:
Daniel Vilar 2018-12-11 17:47:03 +01:00
parent c12f216b59
commit d3ba5efff8
4 changed files with 705 additions and 699 deletions

View file

@ -6,13 +6,11 @@ repository = "https://github.com/teltek/gst-plugin-ndi"
license = "LGPL"
[dependencies]
gobject-subclass = "0.2"
gst-plugin = "0.3"
glib = "0.6"
gstreamer = "0.12"
gstreamer-base = "0.12"
gstreamer-video = "0.12"
gstreamer-audio = "0.12"
glib = { git = "https://github.com/gtk-rs/glib", features = ["subclassing"] }
gstreamer = { git = "https://gitlab.freedesktop.org/gstreamer/gstreamer-rs", features = ["subclassing"] }
gstreamer-base = { git = "https://gitlab.freedesktop.org/gstreamer/gstreamer-rs", features = ["subclassing"] }
gstreamer-video = { git = "https://gitlab.freedesktop.org/gstreamer/gstreamer-rs" }
gstreamer-audio = { git = "https://gitlab.freedesktop.org/gstreamer/gstreamer-rs" }
lazy_static = "1.1.0"
[lib]

View file

@ -1,10 +1,7 @@
#![allow(non_camel_case_types, non_upper_case_globals, non_snake_case)]
extern crate glib;
extern crate gobject_subclass;
#[macro_use]
extern crate gst_plugin;
extern crate glib;
#[macro_use]
extern crate gstreamer as gst;
use gst::prelude::*;
@ -19,7 +16,7 @@ mod ndiaudiosrc;
pub mod ndisys;
mod ndivideosrc;
use gst_plugin::base_src::*;
// use gst_plugin::base_src::*;
use ndisys::*;
use std::ffi::{CStr, CString};
use std::{thread, time};
@ -29,10 +26,10 @@ use std::sync::Mutex;
use gst::GstObjectExt;
fn plugin_init(plugin: &gst::Plugin) -> bool {
ndivideosrc::register(plugin);
ndiaudiosrc::register(plugin);
true
fn plugin_init(plugin: &gst::Plugin) -> Result<(), glib::BoolError> {
ndivideosrc::register(plugin)?;
ndiaudiosrc::register(plugin)?;
Ok(())
}
struct ndi_receiver_info {
@ -62,7 +59,7 @@ lazy_static! {
static mut id_receiver: i8 = 0;
fn connect_ndi(cat: gst::DebugCategory, element: &BaseSrc, ip: &str, stream_name: &str) -> i8 {
fn connect_ndi(cat: gst::DebugCategory, element: &gst_base::BaseSrc, ip: &str, stream_name: &str) -> i8 {
gst_debug!(cat, obj: element, "Starting NDI connection...");
let mut receivers = hashmap_receivers.lock().unwrap();
@ -223,7 +220,7 @@ fn connect_ndi(cat: gst::DebugCategory, element: &BaseSrc, ip: &str, stream_name
}
}
fn stop_ndi(cat: gst::DebugCategory, element: &BaseSrc, id: i8) -> bool {
fn stop_ndi(cat: gst::DebugCategory, element: &gst_base::BaseSrc, id: i8) -> bool {
gst_debug!(cat, obj: element, "Closing NDI connection...");
let mut receivers = hashmap_receivers.lock().unwrap();
{
@ -250,14 +247,14 @@ fn stop_ndi(cat: gst::DebugCategory, element: &BaseSrc, id: i8) -> bool {
true
}
plugin_define!(
b"ndi\0",
b"NewTek NDI Plugin\0",
gst_plugin_define!(
"ndi",
"NewTek NDI Plugin",
plugin_init,
b"1.0.0\0",
b"LGPL\0",
b"ndi\0",
b"ndi\0",
b"https://github.com/teltek/gst-plugin-ndi\0",
b"2018-04-09\0"
"1.0.0",
"LGPL",
"ndi",
"ndi",
"https://github.com/teltek/gst-plugin-ndi",
"2018-04-09"
);

View file

@ -1,14 +1,15 @@
#![allow(non_camel_case_types, non_upper_case_globals, non_snake_case)]
#![allow(non_camel_case_types, non_upper_case_globals, non_snake_case, cast_ptr_alignment)]
use glib;
use glib::subclass;
use glib::subclass::prelude::*;
use gst;
use gst::prelude::*;
use gst::subclass::prelude::*;
use gst_audio;
use gst_base;
use gst_base::prelude::*;
use gobject_subclass::object::*;
use gst_plugin::base_src::*;
use gst_plugin::element::*;
use gst_base::subclass::prelude::*;
use std::sync::Mutex;
use std::{i32, u32};
@ -43,29 +44,36 @@ impl Default for Settings {
}
}
static PROPERTIES: [Property; 3] = [
Property::String(
static PROPERTIES: [subclass::Property; 3] = [
subclass::Property("stream-name", || {
glib::ParamSpec::string(
"stream-name",
"Sream Name",
"Name of the streaming device",
None,
PropertyMutability::ReadWrite,
),
Property::String(
glib::ParamFlags::READWRITE,
)
}),
subclass::Property("ip", || {
glib::ParamSpec::string(
"ip",
"Stream IP",
"IP of the streaming device. Ex: 127.0.0.1:5961",
None,
PropertyMutability::ReadWrite,
),
Property::UInt(
glib::ParamFlags::READWRITE,
)
}),
subclass::Property("loss-threshold", || {
glib::ParamSpec::uint(
"loss-threshold",
"Loss threshold",
"Loss threshold. If 0 the stream is never closed by the element",
(0, 60),
"Loss threshold",
0,
60,
5,
PropertyMutability::ReadWrite,
),
glib::ParamFlags::READWRITE,
)
}),
];
struct State {
@ -89,12 +97,17 @@ struct NdiAudioSrc {
timestamp_data: Mutex<TimestampData>,
}
impl NdiAudioSrc {
fn new(element: &BaseSrc) -> Box<BaseSrcImpl<BaseSrc>> {
element.set_live(true);
element.set_format(gst::Format::Time);
impl ObjectSubclass for NdiAudioSrc {
Box::new(Self {
const NAME: &'static str = "NdiAudioSrc";
type ParentType = gst_base::BaseSrc;
type Instance = gst::subclass::ElementInstanceStruct<Self>;
type Class = subclass::simple::ClassStruct<Self>;
glib_object_subclass!();
fn new() -> Self {
Self {
cat: gst::DebugCategory::new(
"ndiaudiosrc",
gst::DebugColorFlags::empty(),
@ -103,10 +116,10 @@ impl NdiAudioSrc {
settings: Mutex::new(Default::default()),
state: Mutex::new(Default::default()),
timestamp_data: Mutex::new(TimestampData { offset: 0}),
})
}
}
fn class_init(klass: &mut BaseSrcClass) {
fn class_init(klass: &mut subclass::simple::ClassStruct<Self>) {
klass.set_metadata(
"NewTek NDI Audio Source",
"Source",
@ -145,50 +158,56 @@ impl NdiAudioSrc {
}
}
impl ObjectImpl<BaseSrc> for NdiAudioSrc {
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();
impl ObjectImpl for NdiAudioSrc {
glib_object_impl!();
fn constructed(&self, obj: &glib::Object) {
self.parent_constructed(obj);
let basesrc = obj.downcast_ref::<gst_base::BaseSrc>().unwrap();
// Initialize live-ness and notify the base class that
// we'd like to operate in Time format
basesrc.set_live(true);
basesrc.set_format(gst::Format::Time);
}
fn set_property(&self, obj: &glib::Object, id: usize, value: &glib::Value) {
let prop = &PROPERTIES[id];
let basesrc = obj.downcast_ref::<gst_base::BaseSrc>().unwrap();
match *prop {
Property::String("stream-name", ..) => {
subclass::Property("stream-name", ..) => {
let mut settings = self.settings.lock().unwrap();
let stream_name = value.get().unwrap();
gst_debug!(
self.cat,
obj: &element,
obj: basesrc,
"Changing stream-name from {} to {}",
settings.stream_name,
stream_name
);
settings.stream_name = stream_name;
drop(settings);
let _ =
element.post_message(&gst::Message::new_latency().src(Some(&element)).build());
}
Property::String("ip", ..) => {
subclass::Property("ip", ..) => {
let mut settings = self.settings.lock().unwrap();
let ip = value.get().unwrap();
gst_debug!(
self.cat,
obj: &element,
obj: basesrc,
"Changing ip from {} to {}",
settings.ip,
ip
);
settings.ip = ip;
drop(settings);
let _ =
element.post_message(&gst::Message::new_latency().src(Some(&element)).build());
}
Property::UInt("loss-threshold", ..) => {
subclass::Property("loss-threshold", ..) => {
let mut settings = self.settings.lock().unwrap();
let loss_threshold = value.get().unwrap();
gst_debug!(
self.cat,
obj: &element,
obj: basesrc,
"Changing loss threshold from {} to {}",
settings.loss_threshold,
loss_threshold
@ -200,19 +219,19 @@ impl ObjectImpl<BaseSrc> for NdiAudioSrc {
}
}
fn get_property(&self, _obj: &glib::Object, id: u32) -> Result<glib::Value, ()> {
let prop = &PROPERTIES[id as usize];
fn get_property(&self, _obj: &glib::Object, id: usize) -> Result<glib::Value, ()> {
let prop = &PROPERTIES[id];
match *prop {
Property::String("stream-name", ..) => {
subclass::Property("stream-name", ..) => {
let settings = self.settings.lock().unwrap();
Ok(settings.stream_name.to_value())
}
Property::String("ip", ..) => {
subclass::Property("ip", ..) => {
let settings = self.settings.lock().unwrap();
Ok(settings.ip.to_value())
}
Property::UInt("loss-threshold", ..) => {
subclass::Property("loss-threshold", ..) => {
let settings = self.settings.lock().unwrap();
Ok(settings.loss_threshold.to_value())
}
@ -221,10 +240,10 @@ impl ObjectImpl<BaseSrc> for NdiAudioSrc {
}
}
impl ElementImpl<BaseSrc> for NdiAudioSrc {
impl ElementImpl for NdiAudioSrc {
fn change_state(
&self,
element: &BaseSrc,
element: &gst::Element,
transition: gst::StateChange,
) -> gst::StateChangeReturn {
if transition == gst::StateChange::PausedToPlaying {
@ -258,12 +277,12 @@ impl ElementImpl<BaseSrc> for NdiAudioSrc {
gst_debug!(self.cat, obj: element, "Setting initial timestamp to {}", receiver.initial_timestamp);
}
}
element.parent_change_state(transition)
self.parent_change_state(element, transition)
}
}
impl BaseSrcImpl<BaseSrc> for NdiAudioSrc {
fn set_caps(&self, element: &BaseSrc, caps: &gst::CapsRef) -> bool {
impl BaseSrcImpl for NdiAudioSrc {
fn set_caps(&self, element: &gst_base::BaseSrc, caps: &gst::CapsRef) -> bool {
let info = match gst_audio::AudioInfo::from_caps(caps) {
None => return false,
Some(info) => info,
@ -277,7 +296,7 @@ impl BaseSrcImpl<BaseSrc> for NdiAudioSrc {
true
}
fn start(&self, element: &BaseSrc) -> bool {
fn start(&self, element: &gst_base::BaseSrc) -> bool {
*self.state.lock().unwrap() = Default::default();
let mut settings = self.settings.lock().unwrap();
@ -291,7 +310,7 @@ impl BaseSrcImpl<BaseSrc> for NdiAudioSrc {
settings.id_receiver != 0
}
fn stop(&self, element: &BaseSrc) -> bool {
fn stop(&self, element: &gst_base::BaseSrc) -> bool {
*self.state.lock().unwrap() = Default::default();
let settings = self.settings.lock().unwrap();
@ -301,7 +320,7 @@ impl BaseSrcImpl<BaseSrc> for NdiAudioSrc {
true
}
fn query(&self, element: &BaseSrc, query: &mut gst::QueryRef) -> bool {
fn query(&self, element: &gst_base::BaseSrc, query: &mut gst::QueryRef) -> bool {
use gst::QueryView;
if let QueryView::Scheduling(ref mut q) = query.view_mut() {
q.set(gst::SchedulingFlags::SEQUENTIAL, 1, -1, 0);
@ -321,10 +340,10 @@ impl BaseSrcImpl<BaseSrc> for NdiAudioSrc {
return false;
}
}
BaseSrcBase::parent_query(element, query)
BaseSrcImpl::parent_query(self, element, query)
}
fn fixate(&self, element: &BaseSrc, caps: gst::Caps) -> gst::Caps {
fn fixate(&self, element: &gst_base::BaseSrc, caps: gst::Caps) -> gst::Caps {
let receivers = hashmap_receivers.lock().unwrap();
let mut settings = self.settings.lock().unwrap();
@ -359,15 +378,15 @@ impl BaseSrcImpl<BaseSrc> for NdiAudioSrc {
}
let _ = element.post_message(&gst::Message::new_latency().src(Some(element)).build());
element.parent_fixate(caps)
self.parent_fixate(element, caps)
}
fn create(
&self,
element: &BaseSrc,
element: &gst_base::BaseSrc,
_offset: u64,
_length: u32,
) -> Result<gst::Buffer, gst::FlowReturn> {
) -> Result<gst::Buffer, gst::FlowError> {
let _settings = &*self.settings.lock().unwrap();
let mut timestamp_data = self.timestamp_data.lock().unwrap();
@ -376,7 +395,7 @@ impl BaseSrcImpl<BaseSrc> for NdiAudioSrc {
let _info = match state.info {
None => {
gst_element_error!(element, gst::CoreError::Negotiation, ["Have no caps yet"]);
return Err(gst::FlowReturn::NotNegotiated);
return Err(gst::FlowError::NotNegotiated);
}
Some(ref info) => info.clone(),
};
@ -404,15 +423,14 @@ impl BaseSrcImpl<BaseSrc> for NdiAudioSrc {
continue;
}
gst_element_error!(element, gst::ResourceError::Read, ["NDI frame type none or error received, assuming that the source closed the stream...."]);
return Err(gst::FlowReturn::CustomError);
return Err(gst::FlowError::CustomError);
}
else{
if frame_type == NDIlib_frame_type_e::NDIlib_frame_type_none && _settings.loss_threshold == 0{
else if frame_type == NDIlib_frame_type_e::NDIlib_frame_type_none && _settings.loss_threshold == 0{
gst_debug!(self.cat, obj: element, "No audio frame received, sending empty buffer");
let buffer = gst::Buffer::with_size(0).unwrap();
return Ok(buffer)
}
}
if time >= (audio_frame.timestamp as u64) {
gst_debug!(self.cat, obj: element, "Frame timestamp ({:?}) is lower than received in the first frame from NDI ({:?}), so skiping...", (audio_frame.timestamp as u64), time);
} else {
@ -464,23 +482,6 @@ impl BaseSrcImpl<BaseSrc> for NdiAudioSrc {
}
}
struct NdiAudioSrcStatic;
impl ImplTypeStatic<BaseSrc> for NdiAudioSrcStatic {
fn get_name(&self) -> &str {
"NdiAudioSrc"
}
fn new(&self, element: &BaseSrc) -> Box<BaseSrcImpl<BaseSrc>> {
NdiAudioSrc::new(element)
}
fn class_init(&self, klass: &mut BaseSrcClass) {
NdiAudioSrc::class_init(klass);
}
}
pub fn register(plugin: &gst::Plugin) {
let type_ = register_type(NdiAudioSrcStatic);
gst::Element::register(plugin, "ndiaudiosrc", 0, type_);
pub fn register(plugin: &gst::Plugin) -> Result<(), glib::BoolError> {
gst::Element::register(plugin, "ndiaudiosrc", 0, NdiAudioSrc::get_type())
}

View file

@ -1,15 +1,17 @@
#![allow(non_camel_case_types, non_upper_case_globals, non_snake_case)]
use glib;
use glib::subclass;
use glib::subclass::prelude::*;
use gst;
use gst::prelude::*;
use gst::Fraction;
use gst::subclass::prelude::*;
use gst_base;
use gst_base::prelude::*;
use gst_video;
use gst_base::subclass::prelude::*;
use gobject_subclass::object::*;
use gst_plugin::base_src::*;
use gst_plugin::element::*;
use gst::Fraction;
use gst_video;
use std::sync::Mutex;
use std::{i32, u32};
@ -44,29 +46,36 @@ impl Default for Settings {
}
}
static PROPERTIES: [Property; 3] = [
Property::String(
static PROPERTIES: [subclass::Property; 3] = [
subclass::Property("stream-name", || {
glib::ParamSpec::string(
"stream-name",
"Stream Name",
"Name of the streaming device",
None,
PropertyMutability::ReadWrite,
),
Property::String(
glib::ParamFlags::READWRITE,
)
}),
subclass::Property("ip", || {
glib::ParamSpec::string(
"ip",
"Stream IP",
"IP of the streaming device. Ex: 127.0.0.1:5961",
None,
PropertyMutability::ReadWrite,
),
Property::UInt(
glib::ParamFlags::READWRITE,
)
}),
subclass::Property("loss-threshold", || {
glib::ParamSpec::uint(
"loss-threshold",
"Loss threshold",
"Loss threshold. If 0 the stream is never closed by the element",
(0, 60),
"Loss threshold",
0,
60,
5,
PropertyMutability::ReadWrite,
),
glib::ParamFlags::READWRITE,
)
}),
];
struct State {
@ -90,12 +99,17 @@ struct NdiVideoSrc {
timestamp_data: Mutex<TimestampData>,
}
impl NdiVideoSrc {
fn new(element: &BaseSrc) -> Box<BaseSrcImpl<BaseSrc>> {
element.set_live(true);
element.set_format(gst::Format::Time);
impl ObjectSubclass for NdiVideoSrc {
Box::new(Self {
const NAME: &'static str = "NdiVideoSrc";
type ParentType = gst_base::BaseSrc;
type Instance = gst::subclass::ElementInstanceStruct<Self>;
type Class = subclass::simple::ClassStruct<Self>;
glib_object_subclass!();
fn new() -> Self {
Self {
cat: gst::DebugCategory::new(
"ndivideosrc",
gst::DebugColorFlags::empty(),
@ -104,10 +118,10 @@ impl NdiVideoSrc {
settings: Mutex::new(Default::default()),
state: Mutex::new(Default::default()),
timestamp_data: Mutex::new(TimestampData { offset: 0 }),
})
}
}
fn class_init(klass: &mut BaseSrcClass) {
fn class_init(klass: &mut subclass::simple::ClassStruct<Self>) {
klass.set_metadata(
"NewTek NDI Video Source",
"Source",
@ -153,18 +167,32 @@ impl NdiVideoSrc {
}
}
impl ObjectImpl<BaseSrc> for NdiVideoSrc {
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();
impl ObjectImpl for NdiVideoSrc {
glib_object_impl!();
fn constructed(&self, obj: &glib::Object) {
self.parent_constructed(obj);
let basesrc = obj.downcast_ref::<gst_base::BaseSrc>().unwrap();
// Initialize live-ness and notify the base class that
// we'd like to operate in Time format
basesrc.set_live(true);
basesrc.set_format(gst::Format::Time);
}
fn set_property(&self, obj: &glib::Object, id: usize, value: &glib::Value) {
let prop = &PROPERTIES[id];
let basesrc = obj.downcast_ref::<gst_base::BaseSrc>().unwrap();
match *prop {
Property::String("stream-name", ..) => {
subclass::Property("stream-name", ..) => {
let mut settings = self.settings.lock().unwrap();
let stream_name = value.get().unwrap();
gst_debug!(
self.cat,
obj: &element,
obj: basesrc,
"Changing stream-name from {} to {}",
settings.stream_name,
stream_name
@ -172,12 +200,12 @@ impl ObjectImpl<BaseSrc> for NdiVideoSrc {
settings.stream_name = stream_name;
drop(settings);
}
Property::String("ip", ..) => {
subclass::Property("ip", ..) => {
let mut settings = self.settings.lock().unwrap();
let ip = value.get().unwrap();
gst_debug!(
self.cat,
obj: &element,
obj: basesrc,
"Changing ip from {} to {}",
settings.ip,
ip
@ -185,12 +213,12 @@ impl ObjectImpl<BaseSrc> for NdiVideoSrc {
settings.ip = ip;
drop(settings);
}
Property::UInt("loss-threshold", ..) => {
subclass::Property("loss-threshold", ..) => {
let mut settings = self.settings.lock().unwrap();
let loss_threshold = value.get().unwrap();
gst_debug!(
self.cat,
obj: &element,
obj: basesrc,
"Changing loss threshold from {} to {}",
settings.loss_threshold,
loss_threshold
@ -202,19 +230,19 @@ impl ObjectImpl<BaseSrc> for NdiVideoSrc {
}
}
fn get_property(&self, _obj: &glib::Object, id: u32) -> Result<glib::Value, ()> {
let prop = &PROPERTIES[id as usize];
fn get_property(&self, _obj: &glib::Object, id: usize) -> Result<glib::Value, ()> {
let prop = &PROPERTIES[id];
match *prop {
Property::String("stream-name", ..) => {
subclass::Property("stream-name", ..) => {
let settings = self.settings.lock().unwrap();
Ok(settings.stream_name.to_value())
}
Property::String("ip", ..) => {
subclass::Property("ip", ..) => {
let settings = self.settings.lock().unwrap();
Ok(settings.ip.to_value())
}
Property::UInt("loss-threshold", ..) => {
subclass::Property("loss-threshold", ..) => {
let settings = self.settings.lock().unwrap();
Ok(settings.loss_threshold.to_value())
}
@ -223,10 +251,10 @@ impl ObjectImpl<BaseSrc> for NdiVideoSrc {
}
}
impl ElementImpl<BaseSrc> for NdiVideoSrc {
impl ElementImpl for NdiVideoSrc {
fn change_state(
&self,
element: &BaseSrc,
element: &gst::Element,
transition: gst::StateChange,
) -> gst::StateChangeReturn {
if transition == gst::StateChange::PausedToPlaying {
@ -260,12 +288,12 @@ impl ElementImpl<BaseSrc> for NdiVideoSrc {
gst_debug!(self.cat, obj: element, "Setting initial timestamp to {}", receiver.initial_timestamp);
}
}
element.parent_change_state(transition)
self.parent_change_state(element, transition)
}
}
impl BaseSrcImpl<BaseSrc> for NdiVideoSrc {
fn set_caps(&self, element: &BaseSrc, caps: &gst::CapsRef) -> bool {
impl BaseSrcImpl for NdiVideoSrc {
fn set_caps(&self, element: &gst_base::BaseSrc, caps: &gst::CapsRef) -> bool {
let info = match gst_video::VideoInfo::from_caps(caps) {
None => return false,
Some(info) => info,
@ -278,7 +306,7 @@ impl BaseSrcImpl<BaseSrc> for NdiVideoSrc {
true
}
fn start(&self, element: &BaseSrc) -> bool {
fn start(&self, element: &gst_base::BaseSrc) -> bool {
*self.state.lock().unwrap() = Default::default();
let mut settings = self.settings.lock().unwrap();
settings.id_receiver = connect_ndi(
@ -291,7 +319,7 @@ impl BaseSrcImpl<BaseSrc> for NdiVideoSrc {
settings.id_receiver != 0
}
fn stop(&self, element: &BaseSrc) -> bool {
fn stop(&self, element: &gst_base::BaseSrc) -> bool {
*self.state.lock().unwrap() = Default::default();
let settings = self.settings.lock().unwrap();
@ -301,7 +329,7 @@ impl BaseSrcImpl<BaseSrc> for NdiVideoSrc {
true
}
fn query(&self, element: &BaseSrc, query: &mut gst::QueryRef) -> bool {
fn query(&self, element: &gst_base::BaseSrc, query: &mut gst::QueryRef) -> bool {
use gst::QueryView;
if let QueryView::Scheduling(ref mut q) = query.view_mut() {
q.set(gst::SchedulingFlags::SEQUENTIAL, 1, -1, 0);
@ -321,10 +349,10 @@ impl BaseSrcImpl<BaseSrc> for NdiVideoSrc {
return false;
}
}
BaseSrcBase::parent_query(element, query)
BaseSrcImpl::parent_query(self, element, query)
}
fn fixate(&self, element: &BaseSrc, caps: gst::Caps) -> gst::Caps {
fn fixate(&self, element: &gst_base::BaseSrc, caps: gst::Caps) -> gst::Caps {
let receivers = hashmap_receivers.lock().unwrap();
let mut settings = self.settings.lock().unwrap();
@ -361,16 +389,16 @@ impl BaseSrcImpl<BaseSrc> for NdiVideoSrc {
}
let _ = element.post_message(&gst::Message::new_latency().src(Some(element)).build());
element.parent_fixate(caps)
self.parent_fixate(element, caps)
}
//Creates the video buffers
fn create(
&self,
element: &BaseSrc,
element: &gst_base::BaseSrc,
_offset: u64,
_length: u32,
) -> Result<gst::Buffer, gst::FlowReturn> {
) -> Result<gst::Buffer, gst::FlowError> {
let _settings = &*self.settings.lock().unwrap();
let mut timestamp_data = self.timestamp_data.lock().unwrap();
@ -378,7 +406,7 @@ impl BaseSrcImpl<BaseSrc> for NdiVideoSrc {
let _info = match state.info {
None => {
gst_element_error!(element, gst::CoreError::Negotiation, ["Have no caps yet"]);
return Err(gst::FlowReturn::NotNegotiated);
return Err(gst::FlowError::NotNegotiated);
}
Some(ref info) => info.clone(),
};
@ -406,15 +434,14 @@ impl BaseSrcImpl<BaseSrc> for NdiVideoSrc {
continue;
}
gst_element_error!(element, gst::ResourceError::Read, ["NDI frame type none or error received, assuming that the source closed the stream...."]);
return Err(gst::FlowReturn::CustomError);
return Err(gst::FlowError::CustomError);
}
else{
if frame_type == NDIlib_frame_type_e::NDIlib_frame_type_none && _settings.loss_threshold == 0{
else if frame_type == NDIlib_frame_type_e::NDIlib_frame_type_none && _settings.loss_threshold == 0{
gst_debug!(self.cat, obj: element, "No video frame received, sending empty buffer");
let buffer = gst::Buffer::with_size(0).unwrap();
return Ok(buffer)
}
}
if time >= (video_frame.timestamp as u64) {
gst_debug!(self.cat, obj: element, "Frame timestamp ({:?}) is lower than received in the first frame from NDI ({:?}), so skiping...", (video_frame.timestamp as u64), time);
} else {
@ -461,23 +488,6 @@ impl BaseSrcImpl<BaseSrc> for NdiVideoSrc {
}
}
struct NdiVideoSrcStatic;
impl ImplTypeStatic<BaseSrc> for NdiVideoSrcStatic {
fn get_name(&self) -> &str {
"NdiVideoSrc"
}
fn new(&self, element: &BaseSrc) -> Box<BaseSrcImpl<BaseSrc>> {
NdiVideoSrc::new(element)
}
fn class_init(&self, klass: &mut BaseSrcClass) {
NdiVideoSrc::class_init(klass);
}
}
pub fn register(plugin: &gst::Plugin) {
let type_ = register_type(NdiVideoSrcStatic);
gst::Element::register(plugin, "ndivideosrc", 0, type_);
pub fn register(plugin: &gst::Plugin) -> Result<(), glib::BoolError> {
gst::Element::register(plugin, "ndivideosrc", 0, NdiVideoSrc::get_type())
}