From 595bb2f565b88548dfe94b5cd7034529bd21de53 Mon Sep 17 00:00:00 2001 From: Isaac Connor Date: Thu, 7 Jan 2021 09:47:53 -0500 Subject: [PATCH] Open/CLose RTSP with analysis thread when opening and closing monitor. We have to have successfully PrimeCapture before adding streams to RTSP Server and need to shut it down when closing the monitor because the packetqueue goes away --- src/zmc.cpp | 60 +++++++++++++++++++++++++++++++++++++++-------------- 1 file changed, 44 insertions(+), 16 deletions(-) diff --git a/src/zmc.cpp b/src/zmc.cpp index 6fff9edd5..734cf0795 100644 --- a/src/zmc.cpp +++ b/src/zmc.cpp @@ -238,17 +238,6 @@ int main(int argc, char *argv[]) { int prime_capture_log_count = 0; - -#if HAVE_RTSP_SERVER -#if 0 - RTSPServerThread **rtsp_server_threads = new RTSPServerThread *[n_monitors]; - for ( int i = 0; i < n_monitors; i++ ) { - rtsp_server_threads[i] = new RTSPServerThread(monitors[i]); - rtsp_server_threads[i]->start(); - } -#endif -#endif - while ( !zm_terminate ) { result = 0; static char sql[ZM_SQL_SML_BUFSIZ]; @@ -292,6 +281,10 @@ int main(int argc, char *argv[]) { } } +#if HAVE_RTSP_SERVER + RTSPServerThread ** rtsp_server_threads = nullptr; + rtsp_server_threads = new RTSPServerThread *[n_monitors]; +#endif AnalysisThread **analysis_threads = new AnalysisThread *[n_monitors]; int *capture_delays = new int[n_monitors]; int *alarm_capture_delays = new int[n_monitors]; @@ -310,6 +303,18 @@ int main(int argc, char *argv[]) { } else { analysis_threads[i] = NULL; } +#if HAVE_RTSP_SERVER + if ( rtsp_server_threads ) { + for ( int i = 0; i < n_monitors; i++ ) { + rtsp_server_threads[i] = new RTSPServerThread(monitors[i]); + Camera *camera = monitors[i]->getCamera(); + rtsp_server_threads[i]->addStream(camera->get_VideoStream()); + if ( camera->get_AudioStreamId() ) + rtsp_server_threads[i]->addStream(camera->get_AudioStream()); + rtsp_server_threads[i]->start(); + } + } +#endif } // end foreach monitor struct timeval now; @@ -388,22 +393,45 @@ int main(int argc, char *argv[]) { for ( int i = 0; i < n_monitors; i++ ) { if ( analysis_threads[i] ) { analysis_threads[i]->stop(); - analysis_threads[i]->join(); - delete analysis_threads[i]; - analysis_threads[i] = 0; } - } // end foreach monitor - delete [] analysis_threads; +#if HAVE_RTSP_SERVER + if ( rtsp_server_threads ) { + rtsp_server_threads[i]->stop(); + } +#endif + } for ( int i = 0; i < n_monitors; i++ ) { monitors[i]->Close(); } + // Killoff the analysis threads. Don't need them spinning while we try to reconnect + for ( int i = 0; i < n_monitors; i++ ) { + if ( analysis_threads[i] ) { + analysis_threads[i]->join(); + delete analysis_threads[i]; + analysis_threads[i] = nullptr; + } + } // end foreach monitor + delete [] analysis_threads; +#if HAVE_RTSP_SERVER + if ( rtsp_server_threads ) { + for ( int i = 0; i < n_monitors; i++ ) { + rtsp_server_threads[i]->join();; + delete rtsp_server_threads[i]; + rtsp_server_threads[i] = nullptr; + } + delete[] rtsp_server_threads; + rtsp_server_threads = nullptr; + } +#endif + delete [] alarm_capture_delays; delete [] capture_delays; delete [] last_capture_times; } // end while ! zm_terminate outer connection loop + Debug(1,"Updating Monitor status"); for ( int i = 0; i < n_monitors; i++ ) {