From 33c903a6440acea934b0114b3a476faad97d5c6f Mon Sep 17 00:00:00 2001 From: Isaac Connor Date: Mon, 15 Oct 2018 11:13:10 -0400 Subject: [PATCH 1/3] properly initialize packet_counts --- src/zm_packetqueue.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/zm_packetqueue.cpp b/src/zm_packetqueue.cpp index 3fc4d72e9..8a14c3a5e 100644 --- a/src/zm_packetqueue.cpp +++ b/src/zm_packetqueue.cpp @@ -25,7 +25,7 @@ zm_packetqueue::zm_packetqueue( int p_max_stream_id ) { max_stream_id = p_max_stream_id; packet_counts = new int[max_stream_id+1]; for ( int i=0; i <= max_stream_id; ++i ) - packet_counts = 0; + packet_counts[i] = 0; } zm_packetqueue::~zm_packetqueue() { From dae31d226b74065df8334e74d139161a0ad3e85b Mon Sep 17 00:00:00 2001 From: Isaac Connor Date: Mon, 15 Oct 2018 11:33:16 -0400 Subject: [PATCH 2/3] add GetImageBufferCount to monitor --- src/zm_monitor.h | 1 + 1 file changed, 1 insertion(+) diff --git a/src/zm_monitor.h b/src/zm_monitor.h index b98f5953f..2f3b43637 100644 --- a/src/zm_monitor.h +++ b/src/zm_monitor.h @@ -456,6 +456,7 @@ public: void SetVideoWriterEventId( unsigned long long p_event_id ) { video_store_data->current_event = p_event_id; } unsigned int GetPreEventCount() const { return pre_event_count; }; + int GetImageBufferCount() const { return image_buffer_count; }; State GetState() const; int GetImage( int index=-1, int scale=100 ); Snapshot *getSnapshot() const; From 990c4b1b45618f211ae55e47eb53a5aef9adefce Mon Sep 17 00:00:00 2001 From: Isaac Connor Date: Mon, 15 Oct 2018 11:33:58 -0400 Subject: [PATCH 3/3] Add a warning when there are more videoframes in the packetqueue than image_buffers --- src/zm_ffmpeg_camera.cpp | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/zm_ffmpeg_camera.cpp b/src/zm_ffmpeg_camera.cpp index 146bd3856..66391862e 100644 --- a/src/zm_ffmpeg_camera.cpp +++ b/src/zm_ffmpeg_camera.cpp @@ -867,6 +867,10 @@ int FfmpegCamera::CaptureAndRecord( Image &image, timeval recording, char* event if ( packet.stream_index == mVideoStreamId ) { if ( keyframe ) { Debug(3, "Clearing queue"); + if ( packetqueue->packet_count(mVideoStreamId) >= monitor->GetImageBufferCount() ) { + Warning("ImageBufferCount is too small. Either increase it or decrease time between keyframes"); + } + packetqueue->clearQueue(monitor->GetPreEventCount(), mVideoStreamId); packetqueue->queuePacket(&packet); } else if ( packetqueue->size() ) {