Return early if packetqueue is empty instead of getting the lock. Return early in clear() if we are not initialised

This commit is contained in:
Isaac Connor 2021-06-13 14:04:40 -04:00
parent 28d813b95a
commit 9f8c8a2664
1 changed files with 3 additions and 1 deletions

View File

@ -179,6 +179,7 @@ void PacketQueue::clearPackets(const std::shared_ptr<ZMPacket> &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<ZMPacket> &add_packet) {
return;
}
std::unique_lock<std::mutex> 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<ZMPacket> &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<std::mutex> lck(mutex);