Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added parameter to adjust threshold when detecting that a stream was closed #11

Merged
merged 2 commits into from
Dec 5, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 34 additions & 2 deletions src/ndiaudiosrc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ use hashmap_receivers;
struct Settings {
stream_name: String,
ip: String,
loss_threshold: u32,
id_receiver: i8,
latency: Option<gst::ClockTime>,
}
Expand All @@ -35,13 +36,14 @@ impl Default for Settings {
Settings {
stream_name: String::from("Fixed ndi stream name"),
ip: String::from(""),
loss_threshold: 5,
id_receiver: 0,
latency: None,
}
}
}

static PROPERTIES: [Property; 2] = [
static PROPERTIES: [Property; 3] = [
Property::String(
"stream-name",
"Sream Name",
Expand All @@ -56,6 +58,14 @@ static PROPERTIES: [Property; 2] = [
None,
PropertyMutability::ReadWrite,
),
Property::UInt(
"loss-threshold",
"Loss threshold",
"Loss threshold",
(0, 60),
5,
PropertyMutability::ReadWrite,
),
];

struct State {
Expand Down Expand Up @@ -172,6 +182,19 @@ impl ObjectImpl<BaseSrc> for NdiAudioSrc {
let _ =
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!(),
}
}
Expand All @@ -188,6 +211,10 @@ impl ObjectImpl<BaseSrc> for NdiAudioSrc {
let settings = self.settings.lock().unwrap();
Ok(settings.ip.to_value())
}
Property::UInt("loss-threshold", ..) => {
let settings = self.settings.lock().unwrap();
Ok(settings.loss_threshold.to_value())
}
_ => unimplemented!(),
}
}
Expand Down Expand Up @@ -360,12 +387,17 @@ impl BaseSrcImpl<BaseSrc> for NdiAudioSrc {
let time = ndi_struct.initial_timestamp;

let mut skip_frame = true;
let mut count_frame_none = 0;
while skip_frame {
let frame_type =
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 && _settings.loss_threshold != 0)
|| 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...."]);
return Err(gst::FlowReturn::CustomError);
}
Expand Down
36 changes: 34 additions & 2 deletions src/ndivideosrc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ use hashmap_receivers;
struct Settings {
stream_name: String,
ip: String,
loss_threshold: u32,
id_receiver: i8,
latency: Option<gst::ClockTime>,
}
Expand All @@ -36,13 +37,14 @@ impl Default for Settings {
Settings {
stream_name: String::from("Fixed ndi stream name"),
ip: String::from(""),
loss_threshold: 5,
id_receiver: 0,
latency: None,
}
}
}

static PROPERTIES: [Property; 2] = [
static PROPERTIES: [Property; 3] = [
Property::String(
"stream-name",
"Sream Name",
Expand All @@ -57,6 +59,14 @@ static PROPERTIES: [Property; 2] = [
None,
PropertyMutability::ReadWrite,
),
Property::UInt(
"loss-threshold",
"Loss threshold",
"Loss threshold",
(0, 60),
5,
PropertyMutability::ReadWrite,
),
];

struct State {
Expand Down Expand Up @@ -175,6 +185,19 @@ impl ObjectImpl<BaseSrc> for NdiVideoSrc {
settings.ip = ip;
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!(),
}
}
Expand All @@ -191,6 +214,10 @@ impl ObjectImpl<BaseSrc> for NdiVideoSrc {
let settings = self.settings.lock().unwrap();
Ok(settings.ip.to_value())
}
Property::UInt("loss-threshold", ..) => {
let settings = self.settings.lock().unwrap();
Ok(settings.loss_threshold.to_value())
}
_ => unimplemented!(),
}
}
Expand Down Expand Up @@ -364,12 +391,17 @@ impl BaseSrcImpl<BaseSrc> for NdiVideoSrc {
let time = ndi_struct.initial_timestamp;

let mut skip_frame = true;
let mut count_frame_none = 0;
while skip_frame {
let frame_type =
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 && _settings.loss_threshold != 0)
|| 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...."]);
return Err(gst::FlowReturn::CustomError);
}
Expand Down