Keep capture_delay in useconds instead of msecs. Fix fps by adding back in the previous sleep_time. Fix crash due to capture_image not being asigned for local cameras
This commit is contained in:
parent
224fcd2cd3
commit
3ce4b3e657
|
@ -446,8 +446,8 @@ void Monitor::Load(MYSQL_ROW dbrow, bool load_zones=true, Purpose p = QUERY) {
|
|||
|
||||
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_3/atof(dbrow[col])):0; col++;
|
||||
alarm_capture_delay = (dbrow[col] && atof(dbrow[col])>0.0)?int(DT_PREC_3/atof(dbrow[col])):0; col++;
|
||||
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++;
|
||||
|
||||
if ( dbrow[col] )
|
||||
strncpy(device, dbrow[col], sizeof(device)-1);
|
||||
|
@ -1686,7 +1686,8 @@ void Monitor::UpdateCaptureFPS() {
|
|||
unsigned int new_capture_bandwidth = (new_camera_bytes-last_camera_bytes)/elapsed;
|
||||
last_camera_bytes = new_camera_bytes;
|
||||
|
||||
Debug(4, "%s: %d - now:%lf, last %lf, elapsed %lf = %lffps", "Capturing", image_count,
|
||||
Debug(4, "%s: %d - last %d = %d now:%lf, last %lf, elapsed %lf = %lffps", "Capturing", image_count,
|
||||
last_capture_image_count, image_count - last_capture_image_count,
|
||||
now_double, last_analysis_fps_time,
|
||||
elapsed, new_capture_fps
|
||||
);
|
||||
|
@ -2462,9 +2463,8 @@ int Monitor::Capture() {
|
|||
return 0;
|
||||
}
|
||||
} else {
|
||||
Debug(4, "Capturing");
|
||||
captureResult = camera->Capture(*packet);
|
||||
Debug(4, "Back from capture result=%d", captureResult);
|
||||
Debug(4, "Back from capture result=%d image %d", captureResult, image_count);
|
||||
|
||||
if ( captureResult < 0 ) {
|
||||
Debug(2, "failed capture");
|
||||
|
@ -2534,6 +2534,7 @@ int Monitor::Capture() {
|
|||
} // end if need to decode
|
||||
|
||||
if ( packet->image ) {
|
||||
capture_image = packet->image;
|
||||
|
||||
/* Deinterlacing */
|
||||
if ( deinterlacing_value ) {
|
||||
|
|
29
src/zmc.cpp
29
src/zmc.cpp
|
@ -308,6 +308,7 @@ int main(int argc, char *argv[]) {
|
|||
|
||||
struct timeval now;
|
||||
struct DeltaTimeval delta_time;
|
||||
int sleep_time = 0;
|
||||
|
||||
while (!zm_terminate) {
|
||||
//sigprocmask(SIG_BLOCK, &block_set, 0);
|
||||
|
@ -334,31 +335,31 @@ int main(int argc, char *argv[]) {
|
|||
}
|
||||
|
||||
gettimeofday(&now, nullptr);
|
||||
// capture_delay is the amount of time we should sleep to achieve the desired framerate.
|
||||
int delay = monitors[i]->GetState() == Monitor::ALARM ? alarm_capture_delays[i] : capture_delays[i];
|
||||
// capture_delay is the amount of time we should sleep in useconds to achieve the desired framerate.
|
||||
int delay = (monitors[i]->GetState() == Monitor::ALARM) ? alarm_capture_delays[i] : capture_delays[i];
|
||||
if (delay && last_capture_times[i].tv_sec) {
|
||||
int sleep_time;
|
||||
DELTA_TIMEVAL(delta_time, now, last_capture_times[i], DT_PREC_3);
|
||||
// DT_PREC_3 means that the value will be in thousands of a second
|
||||
DELTA_TIMEVAL(delta_time, now, last_capture_times[i], DT_PREC_6);
|
||||
|
||||
sleep_time = delay - delta_time.delta;
|
||||
Debug(3, "Sleep time is %d from now:%d.%d last:%d.%d delay: %d",
|
||||
// You have to add back in the previous sleep time
|
||||
sleep_time = delay - (delta_time.delta - sleep_time);
|
||||
Debug(4, "Sleep time is %d from now:%d.%d last:%d.%d delta %d delay: %d",
|
||||
sleep_time,
|
||||
now.tv_sec, now.tv_usec,
|
||||
last_capture_times[i].tv_sec, last_capture_times[i].tv_usec,
|
||||
delta_time.delta,
|
||||
delay
|
||||
);
|
||||
|
||||
if (sleep_time < 0) {
|
||||
sleep_time = 0;
|
||||
} else if (sleep_time > 0) {
|
||||
Debug(2,"usleeping (%d)", sleep_time*(DT_MAXGRAN/DT_PREC_3) );
|
||||
usleep(sleep_time*(DT_MAXGRAN/DT_PREC_3));
|
||||
if (sleep_time > 0) {
|
||||
Debug(4, "usleeping (%d)", sleep_time);
|
||||
usleep(sleep_time);
|
||||
}
|
||||
} // end if has a last_capture time
|
||||
} // end if has a last_capture time
|
||||
last_capture_times[i] = now;
|
||||
} // end foreach n_monitors
|
||||
} // end foreach n_monitors
|
||||
|
||||
if (result < 0 or zm_reload) {
|
||||
if ((result < 0) or zm_reload) {
|
||||
// Failure, try reconnecting
|
||||
break;
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue