@@ -214,10 +214,15 @@ def run(self):
214214 # Connect to video stream
215215 video_stream = VideoStream (self ._rtsp_url )
216216
217- # TODO: add retry limit and timeout
217+ # Timeout if video not available
218+ video_last_update_time = time .time ()
219+ video_timeout_period = 5.0
218220 print ("Waiting for video stream" )
219221 while not video_stream .frame_available ():
220222 print ("." , end = "" )
223+ if (time .time () - video_last_update_time ) > video_timeout_period :
224+ print ("\n Video stream not avaialble - restarting" )
225+ return
221226 time .sleep (0.1 )
222227 print ("\n Video stream available" )
223228
@@ -246,8 +251,8 @@ def run(self):
246251 fps = 50
247252 update_rate = fps
248253 update_period = 1.0 / update_rate
254+
249255 frame_count = 0
250- av_update_time = 0.0
251256 while True :
252257 start_time = time .time ()
253258
@@ -317,7 +322,6 @@ def __compare_rect(rect1, rect2):
317322 elapsed_time = time .time () - start_time
318323 sleep_time = max (0.0 , update_period - elapsed_time )
319324 time .sleep (sleep_time )
320- av_update_time += elapsed_time
321325
322326
323327class VideoStream :
@@ -1038,6 +1042,8 @@ def set_normalised_roi(self, nroi):
10381042
10391043
10401044if __name__ == "__main__" :
1045+ import os
1046+ import sys
10411047 from optparse import OptionParser
10421048
10431049 parser = OptionParser ("onboard_controller.py [options]" )
@@ -1062,4 +1068,10 @@ def set_normalised_roi(self, nroi):
10621068 controller = OnboardController (
10631069 opts .master , opts .sysid , opts .cmpid , opts .rtsp_server
10641070 )
1065- controller .run ()
1071+
1072+ while True :
1073+ try :
1074+ controller .run ()
1075+ except KeyboardInterrupt :
1076+ EXIT_CODE_CTRL_C = 130
1077+ sys .exit (EXIT_CODE_CTRL_C )
0 commit comments