From 19e4ef99bc62db308c283191ee504ac8b4ae9e4f Mon Sep 17 00:00:00 2001 From: Isaac Connor Date: Sun, 16 Dec 2018 16:18:50 -0500 Subject: [PATCH] add get_fps to Monitor and use it to adjust the # of frames to cache before writing to db --- src/zm_event.cpp | 3 ++- src/zm_monitor.cpp | 19 ++++++++++--------- src/zm_monitor.h | 3 +++ 3 files changed, 15 insertions(+), 10 deletions(-) diff --git a/src/zm_event.cpp b/src/zm_event.cpp index 6da57c29e..757cd505d 100644 --- a/src/zm_event.cpp +++ b/src/zm_event.cpp @@ -582,7 +582,8 @@ Debug(3, "Writing video"); static char sql[ZM_SQL_MED_BUFSIZ]; frame_data.push( new Frame(id, frames, frame_type, timestamp, delta_time, score ) ); - if ( frame_data.size() > 10 ) { + // The idea is to write out 1/sec + if ( frame_data.size() > (int)monitor->get_fps() ) { WriteDbFrames(); Debug(1, "Adding 10 frames to DB"); last_db_frame = frames; diff --git a/src/zm_monitor.cpp b/src/zm_monitor.cpp index 9f2d92102..9ad0ba9f9 100644 --- a/src/zm_monitor.cpp +++ b/src/zm_monitor.cpp @@ -1689,18 +1689,19 @@ Error("Creating new event when one exists"); event->AddFrame( snap_image, *timestamp, score ); } } else { - for( int i = 0; i < n_zones; i++ ) { - if ( zones[i]->Alarmed() ) { - if ( config.record_event_stats && state == ALARM ) { - zones[i]->RecordStats( event ); + if ( state == ALARM ) { + if ( config.record_event_stats ) { + for( int i = 0; i < n_zones; i++ ) { + if ( zones[i]->Alarmed() ) { + zones[i]->RecordStats( event ); + } } } - } - if ( state == PREALARM ) - Event::AddPreAlarmFrame( snap_image, *timestamp, score ); - else event->AddFrame( snap_image, *timestamp, score ); - } + } else { // ( state == PREALARM ) + Event::AddPreAlarmFrame( snap_image, *timestamp, score ); + } + } // end if analysis_images if ( event && noteSetMap.size() > 0 ) event->updateNotes( noteSetMap ); } else if ( state == ALERT ) { diff --git a/src/zm_monitor.h b/src/zm_monitor.h index d7be9555e..573c79770 100644 --- a/src/zm_monitor.h +++ b/src/zm_monitor.h @@ -530,6 +530,9 @@ public: #if HAVE_LIBAVCODEC //void StreamMpeg( const char *format, int scale=100, int maxfps=10, int bitrate=100000 ); #endif // HAVE_LIBAVCODEC + double get_fps( ) const { + return fps; + } }; #define MOD_ADD( var, delta, limit ) (((var)+(limit)+(delta))%(limit))