Skip to content

Commit

Permalink
stream: video_stream_udp: Check for 10 lost timestamps before restart…
Browse files Browse the repository at this point in the history
…ing pipeline

Some cameras are terrible and have duplicated timestamps

Signed-off-by: Patrick José Pereira <[email protected]>
  • Loading branch information
patrickelectric committed Jun 15, 2021
1 parent c2080d5 commit b8ee312
Showing 1 changed file with 18 additions and 2 deletions.
20 changes: 18 additions & 2 deletions src/stream/video_stream_udp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -159,8 +159,14 @@ fn run_video_stream_udp(
"pipeline-started-video-stream-udp",
);

// Check if we need to break external loop
// Check if we need to break external loop.
// Some cameras have a duplicated timestamp when starting.
// to avoid restarting the camera once and once again,
// this checks for a maximum of 10 lost before restarting.
let mut previous_position: Option<gstreamer::ClockTime> = None;
let mut lost_timestamps: usize = 0;
let max_lost_timestamps: usize = 10;

'innerLoop: loop {
if state.lock().unwrap().kill {
break 'externalLoop;
Expand All @@ -182,8 +188,18 @@ fn run_video_stream_udp(
if current_previous_position.nanoseconds() != Some(0)
&& current_previous_position.nanoseconds() == position.nanoseconds()
{
lost_timestamps += 1;
let message =
format!("Position did not change {}", lost_timestamps);
let _ = channel.send(message);
let _ = channel
.send(format!("Position did not change, restarting pipeline"));
.send("Lost camera communication, restarting pipeline!".into());
} else {
// We are back in track, erase lost timestamps
lost_timestamps = 0;
}

if lost_timestamps > max_lost_timestamps {
break 'innerLoop;
}

Expand Down

0 comments on commit b8ee312

Please sign in to comment.