From 505a3844b162efc96baa3b9b036f16ee8576fdc6 Mon Sep 17 00:00:00 2001 From: m-sanchez-rico Date: Thu, 23 May 2024 15:25:13 +0200 Subject: [PATCH 1/2] add several attemps to conect rtsp streams --- src/video_stream.cpp | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/src/video_stream.cpp b/src/video_stream.cpp index f6979fc..b94dd6a 100644 --- a/src/video_stream.cpp +++ b/src/video_stream.cpp @@ -239,6 +239,25 @@ virtual void subscribe() { } catch (std::invalid_argument &ex) { NODELET_INFO_STREAM("Opening VideoCapture with provider: " << video_stream_provider); cap->open(video_stream_provider); + + if(!cap->isOpened() && video_stream_provider_type == "rtsp_stream") + { + int maxAttempts = 20; // Set the maximum number of attempts + int attempts = 0; + bool isOpened = false; + do + { + ros::Duration(5).sleep(); + isOpened = cap->open(video_stream_provider); + if(!isOpened) + NODELET_WARN_STREAM("Failed to open video stream provider: " << video_stream_provider << ". Attempting to open again in 5 second."); + else + NODELET_INFO_STREAM("Opened video stream provider: " << video_stream_provider); + + attempts++; + } while(!isOpened && attempts < maxAttempts); + } + if(video_stream_provider_type == "videofile" ) { // We can only check the number of frames when we actually open the video file From 13a45b401c21c516dae037295809e85b6dcbefce Mon Sep 17 00:00:00 2001 From: m-sanchez-rico Date: Thu, 23 May 2024 15:33:38 +0200 Subject: [PATCH 2/2] remove unsignificant comment --- src/video_stream.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/video_stream.cpp b/src/video_stream.cpp index b94dd6a..02e9f75 100644 --- a/src/video_stream.cpp +++ b/src/video_stream.cpp @@ -242,7 +242,7 @@ virtual void subscribe() { if(!cap->isOpened() && video_stream_provider_type == "rtsp_stream") { - int maxAttempts = 20; // Set the maximum number of attempts + int maxAttempts = 20; int attempts = 0; bool isOpened = false; do