From ae90ebf74f51a61967f87bc70daa1193dbeb1492 Mon Sep 17 00:00:00 2001 From: Isaac Connor Date: Sun, 13 Jun 2021 14:04:40 -0400 Subject: [PATCH] Return early if packetqueue is empty instead of getting the lock. Return early in clear() if we are not initialised --- src/zm_packetqueue.cpp | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/zm_packetqueue.cpp b/src/zm_packetqueue.cpp index 9662e4958..b18fdc266 100644 --- a/src/zm_packetqueue.cpp +++ b/src/zm_packetqueue.cpp @@ -179,6 +179,7 @@ void PacketQueue::clearPackets(const std::shared_ptr &add_packet) { // So start at the beginning, counting video packets until the next keyframe. // Then if deleting those packets doesn't break 1 and 2, then go ahead and delete them. if (deleting) return; + if (!pktQueue.size()) return; if (keep_keyframes and ! ( add_packet->packet.stream_index == video_stream_id @@ -197,7 +198,6 @@ void PacketQueue::clearPackets(const std::shared_ptr &add_packet) { return; } std::unique_lock lck(mutex); - if (!pktQueue.size()) return; // If analysis_it isn't at the end, we need to keep that many additional packets int tail_count = 0; @@ -325,6 +325,8 @@ void PacketQueue::clearPackets(const std::shared_ptr &add_packet) { void PacketQueue::clear() { deleting = true; condition.notify_all(); + if (!packet_counts) // special case, not initialised + return; Debug(1, "Clearing packetqueue"); std::unique_lock lck(mutex);