From 2dcc2f3314cb4fc484f06db59b16ff39cad129b1 Mon Sep 17 00:00:00 2001 From: Isaac Connor Date: Tue, 29 Sep 2026 19:07:07 -0400 Subject: [PATCH] fix: only downgrade the short pre-event warning when the queue was never trimmed get_event_start_packet_it() logged "Hit end of packetqueue before satisfying pre_event_count" at Debug when packet->image_index was below pre_event_count, assuming that meant zmc had just started. image_index comes from shared_data->image_count, which is not reset when a capture reconnect runs Monitor::Pause() and clears the packetqueue. An event opened on the first frames after a reconnect therefore logged a Warning for a short pre-event buffer that cannot be avoided. Record the queue_index of the first packet queued since the last clear() and log at Debug when the walk back stops on that packet, i.e. nothing has been trimmed since startup or the reconnect. A Warning now means packets really were removed below the pre-event count. Co-Authored-By: Claude Opus 5.5 --- src/zm_packetqueue.cpp | 9 ++++++--- src/zm_packetqueue.h | 1 + 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/src/zm_packetqueue.cpp b/src/zm_packetqueue.cpp index 145243e35..f0c5218c6 100644 --- a/src/zm_packetqueue.cpp +++ b/src/zm_packetqueue.cpp @@ -41,7 +41,8 @@ PacketQueue::PacketQueue(): max_keyframe_interval_(0), frames_since_last_keyframe_(0), clear_packets_pending_(false), - next_queue_index_(0) + next_queue_index_(0), + first_queue_index_(0) { } @@ -465,6 +466,7 @@ void PacketQueue::clear() { packet_counts.reset(); max_stream_id = -1; max_keyframe_interval_ = 0; + first_queue_index_ = next_queue_index_; Debug(1, "Packetqueue is clear, notifying"); condition.notify_all(); @@ -678,8 +680,9 @@ packetqueue_iterator *PacketQueue::get_event_start_packet_it( } if (pre_event_count) { - if (packet->image_index < (int)pre_event_count) { - // probably just starting up + if (packet->queue_index == first_queue_index_) { + // Nothing has been trimmed since startup or the last clear() (e.g. a + // capture reconnect), so the queue never held enough packets. Debug(1, "Hit end of packetqueue before satisfying pre_event_count. Needed %d more video frames", pre_event_count); } else { Warning("Hit end of packetqueue before satisfying pre_event_count. Needed %d more video frames", pre_event_count); diff --git a/src/zm_packetqueue.h b/src/zm_packetqueue.h index cbd945f66..dc301fc74 100644 --- a/src/zm_packetqueue.h +++ b/src/zm_packetqueue.h @@ -55,6 +55,7 @@ class PacketQueue { int frames_since_last_keyframe_; std::atomic clear_packets_pending_; uint64_t next_queue_index_; + uint64_t first_queue_index_; // queue_index of the first packet queued since the last clear() public: PacketQueue();