diff --git a/src/zm_event.cpp b/src/zm_event.cpp index b9b5f3925..b77ba43e9 100644 --- a/src/zm_event.cpp +++ b/src/zm_event.cpp @@ -454,14 +454,12 @@ void Event::WriteDbFrames() { while (frame_data.size()) { Frame *frame = frame_data.front(); frame_data.pop(); - frame_insert_sql += stringtf("\n( %" PRIu64 ", %d, '%s', from_unixtime( %ld ), %s%ld.%02ld, %d ),", - id, frame->frame_id, - frame_type_names[frame->type], - frame->timestamp.tv_sec, - frame->delta.positive ? "" : "-", - frame->delta.sec, - frame->delta.fsec, - frame->score); + frame_insert_sql += stringtf("\n( %" PRIu64 ", %d, '%s', from_unixtime( %ld ), %.2f, %d ),", + id, frame->frame_id, + frame_type_names[frame->type], + frame->timestamp.tv_sec, + std::chrono::duration_cast(frame->delta).count(), + frame->score); if (config.record_event_stats and frame->zone_stats.size()) { for (ZoneStats &stats : frame->zone_stats) { stats_insert_sql += stringtf("\n(%" PRIu64 ",%d,%u,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%u),", @@ -591,13 +589,7 @@ void Event::AddFrame( Milliseconds delta_time_ms = std::chrono::duration_cast(delta_time); // The idea is to write out 1/sec - frame_data.push(new Frame(id, - frames, - frame_type, - timestamp, - zm::chrono::duration_cast(delta_time_ms), - score, - zone_stats)); + frame_data.push(new Frame(id, frames, frame_type, timestamp, delta_time_ms, score, zone_stats)); double fps = monitor->get_capture_fps(); if (write_to_db or diff --git a/src/zm_frame.cpp b/src/zm_frame.cpp index 79873efd0..2b28a62b1 100644 --- a/src/zm_frame.cpp +++ b/src/zm_frame.cpp @@ -4,7 +4,7 @@ Frame::Frame(event_id_t p_event_id, int p_frame_id, FrameType p_type, struct timeval p_timestamp, - const DeltaTimeval &p_delta, + Milliseconds p_delta, int p_score, std::vector p_stats) : event_id(p_event_id), diff --git a/src/zm_frame.h b/src/zm_frame.h index 05f49791c..87769711b 100644 --- a/src/zm_frame.h +++ b/src/zm_frame.h @@ -42,7 +42,7 @@ class Frame { int p_frame_id, FrameType p_type, struct timeval p_timestamp, - const DeltaTimeval &p_delta, + Milliseconds p_delta, int p_score, std::vector p_stats ); @@ -51,7 +51,7 @@ class Frame { int frame_id; FrameType type; struct timeval timestamp; - struct DeltaTimeval delta; + Milliseconds delta; int score; std::vector zone_stats; }; diff --git a/src/zm_monitor.cpp b/src/zm_monitor.cpp index 74093859e..d79afbe21 100644 --- a/src/zm_monitor.cpp +++ b/src/zm_monitor.cpp @@ -484,8 +484,8 @@ void Monitor::Load(MYSQL_ROW dbrow, bool load_zones=true, Purpose p = QUERY) { /* "AnalysisFPSLimit, AnalysisUpdateDelay, MaxFPS, AlarmMaxFPS," */ analysis_fps_limit = dbrow[col] ? strtod(dbrow[col], nullptr) : 0.0; col++; analysis_update_delay = strtoul(dbrow[col++], nullptr, 0); - capture_delay = (dbrow[col] && atof(dbrow[col])>0.0)?int(DT_PREC_6/atof(dbrow[col])):0; col++; - alarm_capture_delay = (dbrow[col] && atof(dbrow[col])>0.0)?int(DT_PREC_6/atof(dbrow[col])):0; col++; + capture_delay = (dbrow[col] && atof(dbrow[col]) > 0.0) ? int(Microseconds::period::den / atof(dbrow[col])) : 0; col++; + alarm_capture_delay = (dbrow[col] && atof(dbrow[col]) > 0.0) ? int(Microseconds::period::den / atof(dbrow[col])) : 0; col++; /* "Device, Channel, Format, V4LMultiBuffer, V4LCapturesPerFrame, " // V4L Settings */ device = dbrow[col] ? dbrow[col] : ""; col++; @@ -2963,8 +2963,8 @@ bool Monitor::DumpSettings(char *output, bool verbose) { sprintf(output+strlen(output), "Alarm Frame Count : %d\n", alarm_frame_count ); sprintf(output+strlen(output), "Section Length : %d\n", section_length); sprintf(output+strlen(output), "Min Section Length : %d\n", min_section_length); - sprintf(output+strlen(output), "Maximum FPS : %.2f\n", capture_delay?(double)DT_PREC_3/capture_delay:0.0); - sprintf(output+strlen(output), "Alarm Maximum FPS : %.2f\n", alarm_capture_delay?(double)DT_PREC_3/alarm_capture_delay:0.0); + sprintf(output+strlen(output), "Maximum FPS : %.2f\n", capture_delay ? (double) Microseconds::period::den / capture_delay : 0.0); + sprintf(output+strlen(output), "Alarm Maximum FPS : %.2f\n", alarm_capture_delay ? (double) Microseconds::period::den / alarm_capture_delay : 0.0); sprintf(output+strlen(output), "Reference Blend %%ge : %d\n", ref_blend_perc); sprintf(output+strlen(output), "Alarm Reference Blend %%ge : %d\n", alarm_ref_blend_perc); sprintf(output+strlen(output), "Track Motion : %d\n", track_motion); diff --git a/src/zm_time.h b/src/zm_time.h index d263dfb41..0df20345a 100644 --- a/src/zm_time.h +++ b/src/zm_time.h @@ -23,33 +23,6 @@ #include #include -// Structure used for storing the results of the subtraction -// of one struct timeval from another - -struct DeltaTimeval -{ - bool positive; - unsigned long delta; - unsigned long sec; - unsigned long fsec; - unsigned long prec; -}; - -#define DT_GRAN_1000000 1000000 -#define DT_PREC_6 DT_GRAN_1000000 -#define DT_GRAN_100000 100000 -#define DT_PREC_5 DT_GRAN_100000 -#define DT_GRAN_10000 10000 -#define DT_PREC_4 DT_GRAN_10000 -#define DT_GRAN_1000 1000 -#define DT_PREC_3 DT_GRAN_1000 -#define DT_GRAN_100 100 -#define DT_PREC_2 DT_GRAN_100 -#define DT_GRAN_10 10 -#define DT_PREC_1 DT_GRAN_10 - -#define DT_MAXGRAN DT_GRAN_1000000 - inline struct timeval tvNow() { timeval t = {}; gettimeofday(&t, nullptr); @@ -99,27 +72,6 @@ struct posix_duration_cast> { ); } }; - -// chrono -> DeltaTimeval caster -template -struct posix_duration_cast, DeltaTimeval> { - template - static DeltaTimeval cast(std::chrono::duration const &d) { - typedef std::chrono::duration> fsec_t; - DeltaTimeval res = {}; - - Seconds secs = std::chrono::duration_cast(d); - fsec_t fsec = std::chrono::duration_cast>(d - secs); - - res.positive = fsec >= Seconds::zero(); - res.delta = abs((secs + fsec).count()); - res.sec = secs.count(); - res.fsec = fsec.count(); - res.prec = Prec; - - return res; - } -}; } // chrono -> timeval @@ -134,13 +86,6 @@ template Duration duration_cast(timeval const &tv) { return impl::posix_duration_cast::cast(tv); } - -// chrono -> DeltaTimeval -template -auto duration_cast(std::chrono::duration const &d) --> typename std::enable_if::value, DeltaTimeval>::type { - return impl::posix_duration_cast, DeltaTimeval>::template cast(d); -} } }