Skip to content

Commit

Permalink
handle exit and gstreamer state safer
Browse files Browse the repository at this point in the history
  • Loading branch information
ltn-chriskennedy committed Aug 22, 2024
1 parent 6a8de8d commit 70c895f
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 16 deletions.
36 changes: 21 additions & 15 deletions src/bin/probe.rs
Original file line number Diff line number Diff line change
Expand Up @@ -969,7 +969,9 @@ async fn rsprobe(running: Arc<AtomicBool>) {
let kafka_topic_clone = args.kafka_topic.clone();
let kafka_topic_clone1 = args.kafka_topic.clone();
let kafka_topic_clone2 = args.kafka_topic.clone();
let kafka_topic_clone3 = args.kafka_topic.clone();
let kafka_broker_clone2 = args.kafka_broker.clone();
let kafka_broker_clone3 = args.kafka_broker.clone();

let kafka_thread = tokio::spawn(async move {
// exit thread if kafka_broker is not set
Expand Down Expand Up @@ -2020,29 +2022,33 @@ async fn rsprobe(running: Arc<AtomicBool>) {
// Stop the pipeline when done
#[cfg(feature = "gst")]
if args.extract_images {
match pipeline.set_state(gst::State::Null) {
Ok(_) => (),
Err(err) => {
eprintln!("Failed to set the pipeline state to Null: {}", err);
if gstreamer_playing == true {
match pipeline.set_state(gst::State::Null) {
Ok(_) => (),
Err(err) => {
eprintln!("Failed to set the pipeline state to Null: {}", err);
}
}
}
}

println!("\nWaiting for threads to finish...");

// Send Kafka stop signal
let _ = ktx_clone2.try_send((
Vec::new(),
Vec::new(),
Vec::new(),
AHashMap::new(),
Tr101290Errors::new(),
));
drop(ktx_clone2);

// Wait for the kafka thread to finish
if !kafka_broker_clone3.is_empty() && !kafka_topic_clone3.is_empty() {
let _ = ktx_clone2.try_send((
Vec::new(),
Vec::new(),
Vec::new(),
AHashMap::new(),
Tr101290Errors::new(),
));
drop(ktx_clone2);
// Wait for the kafka thread to finish
kafka_thread.await.unwrap();
}

capture_task.await.unwrap();
kafka_thread.await.unwrap();

println!("\nThreads finished, exiting rsprobe");
}
2 changes: 1 addition & 1 deletion src/stream_data.rs
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@ pub fn process_video_packets(
if let Err(err) = appsrc.push_buffer(buffer) {
log::warn!("Buffer full, dropping packet: {}", err);
errors += 1;
if errors > 100 {
if errors > 1000 {
break;
}
} else {
Expand Down

0 comments on commit 70c895f

Please sign in to comment.