A new parameter was added to adjust the threshold when detecting that a stream was closed

This commit is contained in:
Daniel Vilar 2018-12-05 12:55:01 +01:00
parent 227080e32d
commit 192253ab05
2 changed files with 66 additions and 2 deletions

View file

@ -26,6 +26,7 @@ use hashmap_receivers;
struct Settings { struct Settings {
stream_name: String, stream_name: String,
ip: String, ip: String,
loss_threshold: u32,
id_receiver: i8, id_receiver: i8,
latency: Option<gst::ClockTime>, latency: Option<gst::ClockTime>,
} }
@ -35,13 +36,14 @@ impl Default for Settings {
Settings { Settings {
stream_name: String::from("Fixed ndi stream name"), stream_name: String::from("Fixed ndi stream name"),
ip: String::from(""), ip: String::from(""),
loss_threshold: 5,
id_receiver: 0, id_receiver: 0,
latency: None, latency: None,
} }
} }
} }
static PROPERTIES: [Property; 2] = [ static PROPERTIES: [Property; 3] = [
Property::String( Property::String(
"stream-name", "stream-name",
"Sream Name", "Sream Name",
@ -56,6 +58,14 @@ static PROPERTIES: [Property; 2] = [
None, None,
PropertyMutability::ReadWrite, PropertyMutability::ReadWrite,
), ),
Property::UInt(
"loss-threshold",
"Loss threshold",
"Loss threshold",
(0, 60),
5,
PropertyMutability::ReadWrite,
),
]; ];
struct State { struct State {
@ -172,6 +182,19 @@ impl ObjectImpl<BaseSrc> for NdiAudioSrc {
let _ = let _ =
element.post_message(&gst::Message::new_latency().src(Some(&element)).build()); element.post_message(&gst::Message::new_latency().src(Some(&element)).build());
} }
Property::UInt("loss-threshold", ..) => {
let mut settings = self.settings.lock().unwrap();
let loss_threshold = value.get().unwrap();
gst_debug!(
self.cat,
obj: &element,
"Changing loss threshold from {} to {}",
settings.loss_threshold,
loss_threshold
);
settings.loss_threshold = loss_threshold;
drop(settings);
}
_ => unimplemented!(), _ => unimplemented!(),
} }
} }
@ -188,6 +211,10 @@ impl ObjectImpl<BaseSrc> for NdiAudioSrc {
let settings = self.settings.lock().unwrap(); let settings = self.settings.lock().unwrap();
Ok(settings.ip.to_value()) Ok(settings.ip.to_value())
} }
Property::UInt("loss-threshold", ..) => {
let settings = self.settings.lock().unwrap();
Ok(settings.loss_threshold.to_value())
}
_ => unimplemented!(), _ => unimplemented!(),
} }
} }
@ -360,12 +387,17 @@ impl BaseSrcImpl<BaseSrc> for NdiAudioSrc {
let time = ndi_struct.initial_timestamp; let time = ndi_struct.initial_timestamp;
let mut skip_frame = true; let mut skip_frame = true;
let mut count_frame_none = 0;
while skip_frame { while skip_frame {
let frame_type = let frame_type =
NDIlib_recv_capture_v2(pNDI_recv, ptr::null(), &audio_frame, ptr::null(), 1000); NDIlib_recv_capture_v2(pNDI_recv, ptr::null(), &audio_frame, ptr::null(), 1000);
if frame_type == NDIlib_frame_type_e::NDIlib_frame_type_none if frame_type == NDIlib_frame_type_e::NDIlib_frame_type_none
|| frame_type == NDIlib_frame_type_e::NDIlib_frame_type_error || frame_type == NDIlib_frame_type_e::NDIlib_frame_type_error
{ {
if count_frame_none < _settings.loss_threshold{
count_frame_none += 1;
continue;
}
gst_element_error!(element, gst::ResourceError::Read, ["NDI frame type none received, assuming that the source closed the stream...."]); gst_element_error!(element, gst::ResourceError::Read, ["NDI frame type none received, assuming that the source closed the stream...."]);
return Err(gst::FlowReturn::CustomError); return Err(gst::FlowReturn::CustomError);
} }

View file

@ -27,6 +27,7 @@ use hashmap_receivers;
struct Settings { struct Settings {
stream_name: String, stream_name: String,
ip: String, ip: String,
loss_threshold: u32,
id_receiver: i8, id_receiver: i8,
latency: Option<gst::ClockTime>, latency: Option<gst::ClockTime>,
} }
@ -36,13 +37,14 @@ impl Default for Settings {
Settings { Settings {
stream_name: String::from("Fixed ndi stream name"), stream_name: String::from("Fixed ndi stream name"),
ip: String::from(""), ip: String::from(""),
loss_threshold: 5,
id_receiver: 0, id_receiver: 0,
latency: None, latency: None,
} }
} }
} }
static PROPERTIES: [Property; 2] = [ static PROPERTIES: [Property; 3] = [
Property::String( Property::String(
"stream-name", "stream-name",
"Sream Name", "Sream Name",
@ -57,6 +59,14 @@ static PROPERTIES: [Property; 2] = [
None, None,
PropertyMutability::ReadWrite, PropertyMutability::ReadWrite,
), ),
Property::UInt(
"loss-threshold",
"Loss threshold",
"Loss threshold",
(0, 60),
5,
PropertyMutability::ReadWrite,
),
]; ];
struct State { struct State {
@ -175,6 +185,19 @@ impl ObjectImpl<BaseSrc> for NdiVideoSrc {
settings.ip = ip; settings.ip = ip;
drop(settings); drop(settings);
} }
Property::UInt("loss-threshold", ..) => {
let mut settings = self.settings.lock().unwrap();
let loss_threshold = value.get().unwrap();
gst_debug!(
self.cat,
obj: &element,
"Changing loss threshold from {} to {}",
settings.loss_threshold,
loss_threshold
);
settings.loss_threshold = loss_threshold;
drop(settings);
}
_ => unimplemented!(), _ => unimplemented!(),
} }
} }
@ -191,6 +214,10 @@ impl ObjectImpl<BaseSrc> for NdiVideoSrc {
let settings = self.settings.lock().unwrap(); let settings = self.settings.lock().unwrap();
Ok(settings.ip.to_value()) Ok(settings.ip.to_value())
} }
Property::UInt("loss-threshold", ..) => {
let settings = self.settings.lock().unwrap();
Ok(settings.loss_threshold.to_value())
}
_ => unimplemented!(), _ => unimplemented!(),
} }
} }
@ -364,12 +391,17 @@ impl BaseSrcImpl<BaseSrc> for NdiVideoSrc {
let time = ndi_struct.initial_timestamp; let time = ndi_struct.initial_timestamp;
let mut skip_frame = true; let mut skip_frame = true;
let mut count_frame_none = 0;
while skip_frame { while skip_frame {
let frame_type = let frame_type =
NDIlib_recv_capture_v2(pNDI_recv, &video_frame, ptr::null(), ptr::null(), 1000); NDIlib_recv_capture_v2(pNDI_recv, &video_frame, ptr::null(), ptr::null(), 1000);
if frame_type == NDIlib_frame_type_e::NDIlib_frame_type_none if frame_type == NDIlib_frame_type_e::NDIlib_frame_type_none
|| frame_type == NDIlib_frame_type_e::NDIlib_frame_type_error || frame_type == NDIlib_frame_type_e::NDIlib_frame_type_error
{ {
if count_frame_none < _settings.loss_threshold{
count_frame_none += 1;
continue;
}
gst_element_error!(element, gst::ResourceError::Read, ["NDI frame type none received, assuming that the source closed the stream...."]); gst_element_error!(element, gst::ResourceError::Read, ["NDI frame type none received, assuming that the source closed the stream...."]);
return Err(gst::FlowReturn::CustomError); return Err(gst::FlowReturn::CustomError);
} }