mirror of
https://github.com/ZoneMinder/zoneminder.git
synced 2026-02-05 12:01:25 -05:00
Queue packets instead of packet locks in event thread. Since we are using std::shared_ptr and not modifying the packet, should not need locking. Also, locking in one thread and unlocking in another is apparentlyundefined behaviour and doesn't work infreebsd.
This commit is contained in:
@@ -296,10 +296,11 @@ void Event::updateNotes(const StringSetMap &newNoteSetMap) {
|
||||
} // end if update
|
||||
} // void Event::updateNotes(const StringSetMap &newNoteSetMap)
|
||||
|
||||
void Event::AddPacket(ZMLockedPacket *packetlock) {
|
||||
void Event::AddPacket(const std::shared_ptr<ZMPacket>&packet) {
|
||||
{
|
||||
std::unique_lock<std::mutex> lck(packet_queue_mutex);
|
||||
packet_queue.push(packetlock);
|
||||
|
||||
packet_queue.push(std::move(packet));
|
||||
}
|
||||
packet_queue_condition.notify_one();
|
||||
}
|
||||
@@ -683,11 +684,10 @@ void Event::Run() {
|
||||
if (storage != monitor->getStorage())
|
||||
delete storage;
|
||||
|
||||
|
||||
// The idea is to process the queue no matter what so that all packets get processed.
|
||||
// We only break if the queue is empty
|
||||
while (true) {
|
||||
ZMLockedPacket * packet_lock = nullptr;
|
||||
std::shared_ptr<ZMPacket> packet = nullptr;
|
||||
{
|
||||
std::unique_lock<std::mutex> lck(packet_queue_mutex);
|
||||
|
||||
@@ -697,14 +697,13 @@ void Event::Run() {
|
||||
// Neccessary because we don't hold the lock in the while condition
|
||||
}
|
||||
if (!packet_queue.empty()) {
|
||||
// Packets on this queue are locked. They are locked by analysis thread
|
||||
packet_lock = packet_queue.front();
|
||||
packet = packet_queue.front();
|
||||
packet_queue.pop();
|
||||
}
|
||||
} // end lock scope
|
||||
if (packet_lock) {
|
||||
this->AddPacket_(packet_lock->packet_);
|
||||
delete packet_lock;
|
||||
if (packet) {
|
||||
Debug(1, "Adding packet %d", packet->image_index);
|
||||
this->AddPacket_(packet);
|
||||
}
|
||||
} // end while
|
||||
} // end Run()
|
||||
|
||||
@@ -106,7 +106,7 @@ class Event {
|
||||
|
||||
void createNotes(std::string ¬es);
|
||||
|
||||
std::queue<ZMLockedPacket *> packet_queue;
|
||||
std::queue<std::shared_ptr<ZMPacket>> packet_queue;
|
||||
std::mutex packet_queue_mutex;
|
||||
std::condition_variable packet_queue_condition;
|
||||
|
||||
@@ -135,7 +135,7 @@ class Event {
|
||||
SystemTimePoint EndTime() const { return end_time; }
|
||||
TimePoint::duration Duration() const { return end_time - start_time; };
|
||||
|
||||
void AddPacket(ZMLockedPacket *);
|
||||
void AddPacket(const std::shared_ptr<ZMPacket> &p);
|
||||
void AddPacket_(const std::shared_ptr<ZMPacket> &p);
|
||||
bool WritePacket(const std::shared_ptr<ZMPacket> &p);
|
||||
bool SendFrameImage(const Image *image, bool alarm_frame=false);
|
||||
|
||||
@@ -2263,7 +2263,7 @@ bool Monitor::Analyse() {
|
||||
}
|
||||
|
||||
if (event) {
|
||||
event->AddPacket(packet_lock);
|
||||
event->AddPacket(snap);
|
||||
} else {
|
||||
// In the case where people have pre-alarm frames, the web ui will generate the frame images
|
||||
// from the mp4. So no one will notice anyways.
|
||||
@@ -2283,9 +2283,9 @@ bool Monitor::Analyse() {
|
||||
// Free up the decoded frame as well, we won't be using it for anything at this time.
|
||||
snap->out_frame = nullptr;
|
||||
|
||||
delete packet_lock;
|
||||
}
|
||||
} // end scope for event_lock
|
||||
delete packet_lock;
|
||||
|
||||
packetqueue.increment_it(analysis_it);
|
||||
shared_data->last_read_time = std::chrono::system_clock::to_time_t(std::chrono::system_clock::now());
|
||||
@@ -2892,7 +2892,10 @@ Event * Monitor::openEvent(
|
||||
// Write out starting packets, do not modify packetqueue it will garbage collect itself
|
||||
while (starting_packet_lock && (*start_it != *analysis_it) && !zm_terminate) {
|
||||
ZM_DUMP_PACKET(starting_packet_lock->packet_->packet, "Queuing packet for event");
|
||||
event->AddPacket(starting_packet_lock);
|
||||
|
||||
event->AddPacket(starting_packet);
|
||||
delete starting_packet_lock;
|
||||
starting_packet_lock = nullptr;
|
||||
|
||||
packetqueue.increment_it(start_it);
|
||||
if ((*start_it) != *analysis_it) {
|
||||
|
||||
Reference in New Issue
Block a user