Time: Replace remaining DeltaTimeval usage with std::chrono
This commit is contained in:
parent
6c68397249
commit
d8d27bcc92
|
@ -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<FPSeconds>(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<Milliseconds>(delta_time);
|
||||
// The idea is to write out 1/sec
|
||||
frame_data.push(new Frame(id,
|
||||
frames,
|
||||
frame_type,
|
||||
timestamp,
|
||||
zm::chrono::duration_cast<DeltaTimeval, DT_PREC_3>(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
|
||||
|
|
|
@ -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<ZoneStats> p_stats)
|
||||
: event_id(p_event_id),
|
||||
|
|
|
@ -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<ZoneStats> 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<ZoneStats> zone_stats;
|
||||
};
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -23,33 +23,6 @@
|
|||
#include <chrono>
|
||||
#include <sys/time.h>
|
||||
|
||||
// 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<timeval, std::chrono::duration<Rep, Period>> {
|
|||
);
|
||||
}
|
||||
};
|
||||
|
||||
// chrono -> DeltaTimeval caster
|
||||
template<typename Rep, typename Period>
|
||||
struct posix_duration_cast<std::chrono::duration<Rep, Period>, DeltaTimeval> {
|
||||
template<uint32 Prec>
|
||||
static DeltaTimeval cast(std::chrono::duration<Rep, Period> const &d) {
|
||||
typedef std::chrono::duration<int64, std::ratio<1, Prec>> fsec_t;
|
||||
DeltaTimeval res = {};
|
||||
|
||||
Seconds secs = std::chrono::duration_cast<Seconds>(d);
|
||||
fsec_t fsec = std::chrono::duration_cast<fsec_t, int64, std::ratio<1, Prec>>(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<typename Duration>
|
|||
Duration duration_cast(timeval const &tv) {
|
||||
return impl::posix_duration_cast<timeval, Duration>::cast(tv);
|
||||
}
|
||||
|
||||
// chrono -> DeltaTimeval
|
||||
template<typename T, uint32 Prec, typename Rep, typename Period>
|
||||
auto duration_cast(std::chrono::duration<Rep, Period> const &d)
|
||||
-> typename std::enable_if<std::is_same<T, DeltaTimeval>::value, DeltaTimeval>::type {
|
||||
return impl::posix_duration_cast<std::chrono::duration<Rep, Period>, DeltaTimeval>::template cast<Prec>(d);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue