Skip to content

Commit

Permalink
stream: video_stream_udp: Check for stream position to restart stream
Browse files Browse the repository at this point in the history
Signed-off-by: Patrick José Pereira <patrickelectric@gmail.com>
  • Loading branch information
patrickelectric committed Apr 2, 2021
1 parent a8c4b37 commit b31c6fb
Showing 1 changed file with 27 additions and 0 deletions.
27 changes: 27 additions & 0 deletions src/stream/video_stream_udp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,7 @@ fn run_video_stream_udp(
);

// Check if we need to break external loop
let mut previous_position: Option<gstreamer::ClockTime> = None;
'innerLoop: loop {
if state.lock().unwrap().kill {
break 'externalLoop;
Expand All @@ -168,6 +169,32 @@ fn run_video_stream_udp(
break 'innerLoop;
}

// Restart pipeline if pipeline position do not change,
// occur if usb connection is lost and gstreamer do not detect it
match pipeline
.as_ref()
.unwrap()
.query_position::<gstreamer::ClockTime>()
{
Some(position) => {
previous_position = match previous_position {
Some(current_previous_position) => {
if current_previous_position.nanoseconds() != Some(0)
&& current_previous_position.nanoseconds() == position.nanoseconds()
{
let _ = channel
.send(format!("Position did not change, restarting pipeline"));
break 'innerLoop;
}

Some(position)
}
None => Some(position),
}
}
None => {}
}

for msg in bus.timed_pop(gstreamer::ClockTime::from_mseconds(100)) {
use gstreamer::MessageView;

Expand Down

0 comments on commit b31c6fb

Please sign in to comment.