We cannot delete from the queue when capturing. Just do the waiting. Reduce severity of logs. Make more use of auto. Realise that no other iterators can be pointing into the queue.
This commit is contained in:
parent
c2f4d65860
commit
e6b67dcdc2
|
@ -92,48 +92,9 @@ bool PacketQueue::queuePacket(std::shared_ptr<ZMPacket> add_packet) {
|
||||||
Warning("You have set the max video packets in the queue to %u."
|
Warning("You have set the max video packets in the queue to %u."
|
||||||
" The queue is full. Either Analysis is not keeping up or"
|
" The queue is full. Either Analysis is not keeping up or"
|
||||||
" your camera's keyframe interval is larger than this setting."
|
" your camera's keyframe interval is larger than this setting."
|
||||||
" We are dropping packets.", max_video_packet_count);
|
, max_video_packet_count);
|
||||||
if (add_packet->keyframe) {
|
|
||||||
// Have a new keyframe, so delete everything
|
|
||||||
while ((*pktQueue.begin() != add_packet) and (packet_counts[video_stream_id] > max_video_packet_count)) {
|
|
||||||
std::shared_ptr <ZMPacket>zm_packet = *pktQueue.begin();
|
|
||||||
ZMLockedPacket *lp = new ZMLockedPacket(zm_packet);
|
|
||||||
if (!lp->trylock()) {
|
|
||||||
Debug(1, "Found locked packet when trying to free up video packets. Can't continue");
|
|
||||||
delete lp;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
delete lp;
|
|
||||||
|
|
||||||
for (
|
|
||||||
std::list<packetqueue_iterator *>::iterator iterators_it = iterators.begin();
|
|
||||||
iterators_it != iterators.end();
|
|
||||||
++iterators_it
|
|
||||||
) {
|
|
||||||
packetqueue_iterator *iterator_it = *iterators_it;
|
|
||||||
// Have to check each iterator and make sure it doesn't point to the packet we are about to delete
|
|
||||||
if ( *(*iterator_it) == zm_packet ) {
|
|
||||||
Debug(1, "Bumping IT because it is at the front that we are deleting");
|
|
||||||
++(*iterators_it);
|
|
||||||
}
|
|
||||||
} // end foreach iterator
|
|
||||||
|
|
||||||
pktQueue.pop_front();
|
|
||||||
packet_counts[zm_packet->packet.stream_index] -= 1;
|
|
||||||
Debug(1,
|
|
||||||
"Deleting a packet with stream index:%d image_index:%d with keyframe:%d, video frames in queue:%d max: %d, queuesize:%zu",
|
|
||||||
zm_packet->packet.stream_index,
|
|
||||||
zm_packet->image_index,
|
|
||||||
zm_packet->keyframe,
|
|
||||||
packet_counts[video_stream_id],
|
|
||||||
max_video_packet_count,
|
|
||||||
pktQueue.size());
|
|
||||||
} // end while
|
|
||||||
}
|
|
||||||
} // end if too many video packets
|
|
||||||
if (max_video_packet_count > 0) {
|
|
||||||
while (packet_counts[video_stream_id] > max_video_packet_count) {
|
while (packet_counts[video_stream_id] > max_video_packet_count) {
|
||||||
Error("Unable to free up older packets. Waiting.");
|
Debug(1, "Capture waiting for room in the queue.");
|
||||||
condition.wait(lck);
|
condition.wait(lck);
|
||||||
if (deleting or zm_terminate)
|
if (deleting or zm_terminate)
|
||||||
return false;
|
return false;
|
||||||
|
@ -148,16 +109,13 @@ bool PacketQueue::queuePacket(std::shared_ptr<ZMPacket> add_packet) {
|
||||||
packet_counts[add_packet->packet.stream_index]);
|
packet_counts[add_packet->packet.stream_index]);
|
||||||
|
|
||||||
for (
|
for (
|
||||||
std::list<packetqueue_iterator *>::iterator iterators_it = iterators.begin();
|
auto iterators_it = iterators.begin();
|
||||||
iterators_it != iterators.end();
|
iterators_it != iterators.end();
|
||||||
++iterators_it
|
++iterators_it
|
||||||
) {
|
) {
|
||||||
packetqueue_iterator *iterator_it = *iterators_it;
|
packetqueue_iterator *iterator_it = *iterators_it;
|
||||||
if (*iterator_it == pktQueue.end()) {
|
if (*iterator_it == pktQueue.end()) {
|
||||||
Debug(4, "pointing it %p to back", iterator_it);
|
|
||||||
--(*iterator_it);
|
--(*iterator_it);
|
||||||
} else {
|
|
||||||
Debug(4, "it %p not at end", iterator_it);
|
|
||||||
}
|
}
|
||||||
} // end foreach iterator
|
} // end foreach iterator
|
||||||
} // end lock scope
|
} // end lock scope
|
||||||
|
@ -166,7 +124,7 @@ bool PacketQueue::queuePacket(std::shared_ptr<ZMPacket> add_packet) {
|
||||||
condition.notify_all();
|
condition.notify_all();
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
} // end bool PacketQueue::queuePacket(ZMPacket* zm_packet)
|
} // end bool PacketQueue::queuePacket(ZMPacket* zm_packet)
|
||||||
|
|
||||||
void PacketQueue::clearPackets(const std::shared_ptr<ZMPacket> &add_packet) {
|
void PacketQueue::clearPackets(const std::shared_ptr<ZMPacket> &add_packet) {
|
||||||
// Only do queueCleaning if we are adding a video keyframe, so that we guarantee that there is one.
|
// Only do queueCleaning if we are adding a video keyframe, so that we guarantee that there is one.
|
||||||
|
@ -240,8 +198,8 @@ void PacketQueue::clearPackets(const std::shared_ptr<ZMPacket> &add_packet) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
packetqueue_iterator it = pktQueue.begin();
|
auto it = pktQueue.begin();
|
||||||
packetqueue_iterator next_front = pktQueue.begin();
|
auto next_front = pktQueue.begin();
|
||||||
|
|
||||||
// First packet is special because we know it is a video keyframe and only need to check for lock
|
// First packet is special because we know it is a video keyframe and only need to check for lock
|
||||||
std::shared_ptr<ZMPacket> zm_packet = *it;
|
std::shared_ptr<ZMPacket> zm_packet = *it;
|
||||||
|
@ -249,18 +207,13 @@ void PacketQueue::clearPackets(const std::shared_ptr<ZMPacket> &add_packet) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
Debug(1, "trying lock on first packet");
|
|
||||||
ZMLockedPacket *lp = new ZMLockedPacket(zm_packet);
|
ZMLockedPacket *lp = new ZMLockedPacket(zm_packet);
|
||||||
if (lp->trylock()) {
|
if (lp->trylock()) {
|
||||||
int video_packets_to_delete = 0; // This is a count of how many packets we will delete so we know when to stop looking
|
int video_packets_to_delete = 0; // This is a count of how many packets we will delete so we know when to stop looking
|
||||||
Debug(1, "Have lock on first packet");
|
Debug(4, "Have lock on first packet");
|
||||||
++it;
|
++it;
|
||||||
delete lp;
|
delete lp;
|
||||||
|
|
||||||
if (it == pktQueue.end()) {
|
|
||||||
Debug(1, "Hit end already");
|
|
||||||
it = pktQueue.begin();
|
|
||||||
} else {
|
|
||||||
// Since we have many packets in the queue, we should NOT be pointing at end so don't need to test for that
|
// Since we have many packets in the queue, we should NOT be pointing at end so don't need to test for that
|
||||||
while (*it != add_packet) {
|
while (*it != add_packet) {
|
||||||
zm_packet = *it;
|
zm_packet = *it;
|
||||||
|
@ -271,10 +224,14 @@ void PacketQueue::clearPackets(const std::shared_ptr<ZMPacket> &add_packet) {
|
||||||
}
|
}
|
||||||
delete lp;
|
delete lp;
|
||||||
|
|
||||||
if (is_there_an_iterator_pointing_to_packet(zm_packet) and (pktQueue.begin() == next_front)) {
|
#if 0
|
||||||
Warning("Found iterator at beginning of queue. Some thread isn't keeping up");
|
// There are no threads that follow analysis thread. So there cannot be an it pointing here
|
||||||
|
if (is_there_an_iterator_pointing_to_packet(zm_packet)) {
|
||||||
|
if (pktQueue.begin() == next_front)
|
||||||
|
Warning("Found iterator at beginning of queue. Some thread isn't keeping up");
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
if (zm_packet->packet.stream_index == video_stream_id) {
|
if (zm_packet->packet.stream_index == video_stream_id) {
|
||||||
if (zm_packet->keyframe) {
|
if (zm_packet->keyframe) {
|
||||||
|
@ -282,15 +239,14 @@ void PacketQueue::clearPackets(const std::shared_ptr<ZMPacket> &add_packet) {
|
||||||
next_front = it;
|
next_front = it;
|
||||||
}
|
}
|
||||||
++video_packets_to_delete;
|
++video_packets_to_delete;
|
||||||
Debug(4, "Counted %d video packets. Which would leave %d in packetqueue tail count is %d",
|
Debug(4, "Counted %d video packets. Which would leave %d in packetqueue tail count is %d",
|
||||||
video_packets_to_delete, packet_counts[video_stream_id]-video_packets_to_delete, tail_count);
|
video_packets_to_delete, packet_counts[video_stream_id]-video_packets_to_delete, tail_count);
|
||||||
if (packet_counts[video_stream_id] - video_packets_to_delete <= pre_event_video_packet_count + tail_count) {
|
if (packet_counts[video_stream_id] - video_packets_to_delete <= pre_event_video_packet_count + tail_count) {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
++it;
|
++it;
|
||||||
} // end while
|
} // end while
|
||||||
}
|
|
||||||
} // end if first packet not locked
|
} // end if first packet not locked
|
||||||
Debug(1, "Resulting pointing at latest packet? %d, next front points to begin? %d",
|
Debug(1, "Resulting pointing at latest packet? %d, next front points to begin? %d",
|
||||||
( *it == add_packet ),
|
( *it == add_packet ),
|
||||||
|
|
Loading…
Reference in New Issue