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

This commit is contained in:
Isaac Connor 2021-01-07 09:47:53 -05:00
parent c6d15f193a
commit 595bb2f565
1 changed files with 44 additions and 16 deletions

View File

@ -238,17 +238,6 @@ int main(int argc, char *argv[]) {
int prime_capture_log_count = 0; 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 ) { while ( !zm_terminate ) {
result = 0; result = 0;
static char sql[ZM_SQL_SML_BUFSIZ]; 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]; AnalysisThread **analysis_threads = new AnalysisThread *[n_monitors];
int *capture_delays = new int[n_monitors]; int *capture_delays = new int[n_monitors];
int *alarm_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 { } else {
analysis_threads[i] = NULL; 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 } // end foreach monitor
struct timeval now; struct timeval now;
@ -388,22 +393,45 @@ int main(int argc, char *argv[]) {
for ( int i = 0; i < n_monitors; i++ ) { for ( int i = 0; i < n_monitors; i++ ) {
if ( analysis_threads[i] ) { if ( analysis_threads[i] ) {
analysis_threads[i]->stop(); analysis_threads[i]->stop();
analysis_threads[i]->join();
delete analysis_threads[i];
analysis_threads[i] = 0;
} }
} // end foreach monitor #if HAVE_RTSP_SERVER
delete [] analysis_threads; if ( rtsp_server_threads ) {
rtsp_server_threads[i]->stop();
}
#endif
}
for ( int i = 0; i < n_monitors; i++ ) { for ( int i = 0; i < n_monitors; i++ ) {
monitors[i]->Close(); 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 [] alarm_capture_delays;
delete [] capture_delays; delete [] capture_delays;
delete [] last_capture_times; delete [] last_capture_times;
} // end while ! zm_terminate outer connection loop } // end while ! zm_terminate outer connection loop
Debug(1,"Updating Monitor status"); Debug(1,"Updating Monitor status");
for ( int i = 0; i < n_monitors; i++ ) { for ( int i = 0; i < n_monitors; i++ ) {