diff --git a/src/zm_analysis_thread.cpp b/src/zm_analysis_thread.cpp index 7aa037074..c207f7fd5 100644 --- a/src/zm_analysis_thread.cpp +++ b/src/zm_analysis_thread.cpp @@ -15,6 +15,11 @@ AnalysisThread::~AnalysisThread() { thread_.join(); } +void AnalysisThread::Start() { + terminate_ = false; + thread_ = std::thread(&AnalysisThread::Run, this); +} + void AnalysisThread::Run() { Debug(2, "AnalysisThread::Run() for %d", monitor_->Id()); diff --git a/src/zm_analysis_thread.h b/src/zm_analysis_thread.h index e5b95601f..a402207c1 100644 --- a/src/zm_analysis_thread.h +++ b/src/zm_analysis_thread.h @@ -14,6 +14,7 @@ class AnalysisThread { AnalysisThread(AnalysisThread &rhs) = delete; AnalysisThread(AnalysisThread &&rhs) = delete; + void Start(); void Stop() { terminate_ = true; } private: diff --git a/src/zm_decoder_thread.cpp b/src/zm_decoder_thread.cpp index ae5c8edc1..2bf1f3c2b 100644 --- a/src/zm_decoder_thread.cpp +++ b/src/zm_decoder_thread.cpp @@ -14,6 +14,10 @@ DecoderThread::~DecoderThread() { thread_.join(); } +void DecoderThread::Start() { + terminate_ = false; + thread_ = std::thread(&DecoderThread::Run, this); +} void DecoderThread::Run() { Debug(2, "DecoderThread::Run() for %d", monitor_->Id()); diff --git a/src/zm_decoder_thread.h b/src/zm_decoder_thread.h index 24e155c72..62b2f0d23 100644 --- a/src/zm_decoder_thread.h +++ b/src/zm_decoder_thread.h @@ -14,6 +14,7 @@ class DecoderThread { DecoderThread(DecoderThread &rhs) = delete; DecoderThread(DecoderThread &&rhs) = delete; + void Start(); void Stop() { terminate_ = true; } private: diff --git a/src/zm_monitor.cpp b/src/zm_monitor.cpp index 19593c145..ff221055c 100644 --- a/src/zm_monitor.cpp +++ b/src/zm_monitor.cpp @@ -3182,13 +3182,19 @@ int Monitor::PrimeCapture() { if (decoding_enabled) { if (!decoder_it) decoder_it = packetqueue.get_video_it(false); - if (!decoder) decoder = ZM::make_unique(this); + if (!decoder) { + decoder = ZM::make_unique(this); + } else { + decoder->Start(); + } } if (!analysis_it) analysis_it = packetqueue.get_video_it(false); if (!analysis_thread) { Debug(1, "Starting an analysis thread for monitor (%d)", id); analysis_thread = ZM::make_unique(this); + } else { + analysis_thread->Start(); } } else {