Monitor: Make decoder a unique_ptr

The DecoderThread object is owned by the Monitor. Signal this by using unique_ptr.
This commit is contained in:
Peter Keresztes Schmidt 2021-03-21 23:32:22 +01:00
parent fee5ecd72f
commit 817da4e621
4 changed files with 6 additions and 42 deletions

View File

@ -3,10 +3,8 @@
#include "zm_monitor.h"
#include "zm_signal.h"
//DecoderThread::DecoderThread(std::shared_ptr<Monitor> monitor) :
DecoderThread::DecoderThread(Monitor * monitor) :
DecoderThread::DecoderThread(Monitor *monitor) :
monitor_(monitor), terminate_(false) {
//monitor_(std::move(monitor)), terminate_(false) {
thread_ = std::thread(&DecoderThread::Run, this);
}
@ -19,35 +17,7 @@ DecoderThread::~DecoderThread() {
void DecoderThread::Run() {
Debug(2, "DecoderThread::Run() for %d", monitor_->Id());
//Microseconds decoder_rate = Microseconds(monitor_->GetDecoderRate());
//Seconds decoder_update_delay = Seconds(monitor_->GetDecoderUpdateDelay());
//Debug(2, "DecoderThread::Run() have update delay %d", decoder_update_delay);
//TimePoint last_decoder_update_time = std::chrono::steady_clock::now();
//TimePoint cur_time;
while (!(terminate_ or zm_terminate)) {
// Some periodic updates are required for variable capturing framerate
//if (decoder_update_delay != Seconds::zero()) {
//cur_time = std::chrono::steady_clock::now();
//Debug(2, "Updating adaptive skip");
//if ((cur_time - last_decoder_update_time) > decoder_update_delay) {
//decoder_rate = Microseconds(monitor_->GetDecoderRate());
//last_decoder_update_time = cur_time;
//}
//}
if (!monitor_->Decode()) {
//if ( !(terminate_ or zm_terminate) ) {
//Microseconds sleep_for = monitor_->Active() ? Microseconds(ZM_SAMPLE_RATE) : Microseconds(ZM_SUSPENDED_RATE);
//Debug(2, "Sleeping for %" PRId64 "us", int64(sleep_for.count()));
//std::this_thread::sleep_for(sleep_for);
//}
//} else if (decoder_rate != Microseconds::zero()) {
//Debug(2, "Sleeping for %" PRId64 " us", int64(decoder_rate.count()));
//std::this_thread::sleep_for(decoder_rate);
//} else {
//Debug(2, "Not sleeping");
}
monitor_->Decode();
}
}

View File

@ -9,8 +9,7 @@ class Monitor;
class DecoderThread {
public:
explicit DecoderThread(Monitor* monitor);
//explicit DecoderThread(std::shared_ptr<Monitor> monitor);
explicit DecoderThread(Monitor *monitor);
~DecoderThread();
DecoderThread(DecoderThread &rhs) = delete;
DecoderThread(DecoderThread &&rhs) = delete;
@ -20,8 +19,7 @@ class DecoderThread {
private:
void Run();
Monitor* monitor_;
//std::shared_ptr<Monitor> monitor_;
Monitor *monitor_;
std::atomic<bool> terminate_;
std::thread thread_;
};

View File

@ -3210,7 +3210,7 @@ int Monitor::PrimeCapture() {
if (decoding_enabled) {
if (!decoder_it) decoder_it = packetqueue.get_video_it(false);
if (!decoder) decoder = new DecoderThread(this);
if (!decoder) decoder = ZM::make_unique<DecoderThread>(this);
}
if (!analysis_it) analysis_it = packetqueue.get_video_it(false);
@ -3237,10 +3237,6 @@ int Monitor::Close() {
}
packetqueue.clear();
if (decoder) {
delete decoder;
decoder = nullptr;
}
std::lock_guard<std::mutex> lck(event_mutex);
if (event) {
Info("%s: image_count:%d - Closing event %" PRIu64 ", shutting down", name, image_count, event->Id());

View File

@ -378,7 +378,7 @@ protected:
packetqueue_iterator *analysis_it;
std::unique_ptr<AnalysisThread> analysis_thread;
packetqueue_iterator *decoder_it;
DecoderThread *decoder;
std::unique_ptr<DecoderThread> decoder;
AVFrame *dest_frame; // Used by decoding thread doing colorspace conversions
SwsContext *convert_context;
std::thread close_event_thread;