Merge branch 'master' into lazy-load-images

This commit is contained in:
Ben Dailey 2022-02-22 08:47:26 -05:00
commit b2428b5522
8 changed files with 50 additions and 17 deletions

View File

@ -108,8 +108,8 @@ bool zmDbConnect() {
}
void zmDbClose() {
if (zmDbConnected) {
std::lock_guard<std::mutex> lck(db_mutex);
if (zmDbConnected) {
mysql_close(&dbconn);
// mysql_init() call implicitly mysql_library_init() but
// mysql_close() does not call mysql_library_end()
@ -238,8 +238,13 @@ zmDbQueue::~zmDbQueue() {
}
void zmDbQueue::stop() {
{
std::unique_lock<std::mutex> lock(mMutex);
mTerminate = true;
}
mCondition.notify_all();
if (mThread.joinable()) mThread.join();
}

View File

@ -699,3 +699,6 @@ Debug(1, "wakeing");
}
}
}
int Event::MonitorId() {
return monitor->Id();
}

View File

@ -192,5 +192,6 @@ class Event {
void SavePreAlarmFrames() {
EmptyPreAlarmFrames();
}
int MonitorId();
};
#endif // ZM_EVENT_H

View File

@ -98,7 +98,7 @@ void Image::update_function_pointers() {
delta8_abgr = &std_delta8_abgr;
delta8_gray8 = &std_delta8_gray8;
blend = &std_blend;
Warning("Using slow std functions because pixels %d mod 4=%d", pixels, pixels%4);
Debug(1, "Using slow std functions because pixels %d mod 4=%d", pixels, pixels%4);
} else {
// Use either sse or neon, or loop unrolled version
delta8_rgb = fptr_delta8_rgb;
@ -1090,14 +1090,16 @@ bool Image::WriteJpeg(const std::string &filename,
const int &quality_override,
SystemTimePoint timestamp,
bool on_blocking_abort) const {
// jpeg libs are not thread safe
std::unique_lock<std::mutex> lck(jpeg_mutex);
if (config.colour_jpeg_files && (colours == ZM_COLOUR_GRAY8)) {
Image temp_image(*this);
temp_image.Colourise(ZM_COLOUR_RGB24, ZM_SUBPIX_ORDER_RGB);
return temp_image.WriteJpeg(filename, quality_override, timestamp, on_blocking_abort);
}
// jpeg libs are not thread safe
std::unique_lock<std::mutex> lck(jpeg_mutex);
int quality = quality_override ? quality_override : config.jpeg_file_quality;
jpeg_compress_struct *cinfo = writejpg_ccinfo[quality];
@ -1167,7 +1169,7 @@ bool Image::WriteJpeg(const std::string &filename,
} else if (subpixelorder == ZM_SUBPIX_ORDER_ABGR) {
cinfo->in_color_space = JCS_EXT_XBGR;
} else {
Warning("Unknwon subpixelorder %d", subpixelorder);
Warning("Unknown subpixelorder %d", subpixelorder);
/* Assume RGBA */
cinfo->in_color_space = JCS_EXT_RGBX;
}

View File

@ -1822,8 +1822,8 @@ bool Monitor::Analyse() {
Debug(1, "Linked monitor %d %s is connected",
linked_monitors[i]->Id(), linked_monitors[i]->Name());
if (linked_monitors[i]->hasAlarmed()) {
Debug(1, "Linked monitor %d %s is alarmed",
linked_monitors[i]->Id(), linked_monitors[i]->Name());
Debug(1, "Linked monitor %d %s is alarmed score will be %d",
linked_monitors[i]->Id(), linked_monitors[i]->Name(), linked_monitors[i]->lastFrameScore());
if (!event) {
if (first_link) {
if (cause.length())
@ -1948,6 +1948,9 @@ bool Monitor::Analyse() {
} // end if active and doing motion detection
// Set this before any state changes so that it's value is picked up immediately by linked monitors
shared_data->last_frame_score = score;
// If motion detecting, score will be > 0 on motion, but if skipping frames, might not be. So also test snap->score
if ((score > 0) or ((snap->score > 0) and (function != MONITOR))) {
if ((state == IDLE) || (state == TAPE) || (state == PREALARM)) {
@ -2160,7 +2163,6 @@ bool Monitor::Analyse() {
last_signal = signal;
} // end if videostream
} // end if signal
shared_data->last_frame_score = score;
} else {
Debug(3, "trigger == off");
if (event) {
@ -2766,7 +2768,11 @@ Event * Monitor::openEvent(
if (!event_start_command.empty()) {
if (fork() == 0) {
execlp(event_start_command.c_str(), event_start_command.c_str(), std::to_string(event->Id()).c_str(), nullptr);
execlp(event_start_command.c_str(),
event_start_command.c_str(),
std::to_string(event->Id()).c_str(),
std::to_string(event->MonitorId()).c_str(),
nullptr);
Error("Error execing %s", event_start_command.c_str());
}
}
@ -2806,11 +2812,15 @@ void Monitor::closeEvent() {
Debug(1, "Starting thread to close event");
close_event_thread = std::thread([](Event *e, const std::string &command){
int64_t event_id = e->Id();
int monitor_id = e->MonitorId();
delete e;
if (!command.empty()) {
if (fork() == 0) {
execlp(command.c_str(), command.c_str(), std::to_string(event_id).c_str(), nullptr);
execlp(command.c_str(), command.c_str(),
std::to_string(event_id).c_str(),
std::to_string(monitor_id).c_str(), // monitor id
nullptr);
Error("Error execing %s", command.c_str());
}
}

View File

@ -26,7 +26,7 @@ function MonitorStream(monitorData) {
this.buttons = {}; // index by name
this.setButton = function(name, element) {
this.buttons.name = element;
this.buttons[name] = element;
};
this.element = null;
@ -380,6 +380,8 @@ function MonitorStream(monitorData) {
if ('enableAlarmButton' in this.buttons) {
this.buttons.enableAlarmButton.addClass('disabled');
this.buttons.enableAlarmButton.prop('title', disableAlarmsStr);
} else {
console.log('enableAlarmButton not found in buttons');
}
if ('forceAlarmButton' in this.buttons) {
if (streamStatus.forced) {
@ -390,8 +392,11 @@ function MonitorStream(monitorData) {
this.buttons.forceAlarmButton.prop('title', forceAlarmStr);
}
this.buttons.forceAlarmButton.prop('disabled', false);
} else {
console.log('forceAlarmButton not found in buttons');
}
} else {
console.log("streamStatus not enabled");
if ('enableAlarmButton' in this.buttons) {
this.buttons.enableAlarmButton.removeClass('disabled');
this.buttons.enableAlarmButton.prop('title', enableAlarmsStr);
@ -462,6 +467,8 @@ function MonitorStream(monitorData) {
this.alarmCommand = function(command) {
if (this.ajaxQueue) {
console.log("Aborting in progress ajax for alarm");
// Doing this for responsiveness, but we could be aborting something important. Need smarter logic
this.ajaxQueue.abort();
}
const alarmCmdParms = Object.assign({}, this.streamCmdParms);
@ -485,9 +492,6 @@ function MonitorStream(monitorData) {
}
this.streamCmdReq = function(streamCmdParms) {
if (this.ajaxQueue) {
this.ajaxQueue.abort();
}
this.ajaxQueue = jQuery.ajaxQueue({url: this.url, data: streamCmdParms, dataType: "json"})
.done(this.getStreamCmdResponse.bind(this))
.fail(this.onFailure.bind(this));

View File

@ -833,6 +833,14 @@ function initPage() {
monitorStream.setButton('enableAlarmButton', enableAlmBtn);
monitorStream.setButton('forceAlarmButton', forceAlmBtn);
monitorStream.setButton('zoomOutButton', $j('zoomOutBtn'));
if (canEdit.Monitors) {
// Will be enabled by streamStatus ajax
enableAlmBtn.on('click', cmdAlarm);
forceAlmBtn.on('click', cmdForce);
} else {
forceAlmBtn.prop('title', forceAlmBtn.prop('title') + ': disabled because cannot edit Monitors');
enableAlmBtn.prop('title', enableAlmBtn.prop('title') + ': disabled because cannot edit Monitors');
}
/*
if (streamMode == 'single') {

View File

@ -159,8 +159,8 @@ xhtmlHeaders(__FILE__, $monitor->Name().' - '.translate('Feed'));
<button type="button" id="backBtn" class="btn btn-normal" data-toggle="tooltip" data-placement="top" title="<?php echo translate('Back') ?>" disabled><i class="fa fa-arrow-left"></i></button>
<button type="button" id="refreshBtn" class="btn btn-normal" data-toggle="tooltip" data-placement="top" title="<?php echo translate('Refresh') ?>" ><i class="fa fa-refresh"></i></button>
<button type="button" id="settingsBtn" class="btn btn-normal" data-toggle="tooltip" data-placement="top" title="<?php echo translate('Settings') ?>" disabled><i class="fa fa-sliders"></i></button>
<button type="button" id="enableAlmBtn" class="btn btn-normal" data-on-click="cmdAlarm" data-toggle="tooltip" data-placement="top" title="<?php echo translate('DisableAlarms') ?>" disabled><i class="fa fa-bell"></i></button>
<button type="button" id="forceAlmBtn" class="btn btn-danger" data-on-click="cmdForce" data-toggle="tooltip" data-placement="top" title="<?php echo translate('ForceAlarm') ?>" disabled><i class="fa fa-exclamation-circle"></i></button>
<button type="button" id="enableAlmBtn" class="btn btn-normal" data-toggle="tooltip" data-placement="top" title="<?php echo translate('DisableAlarms') ?>" disabled><i class="fa fa-bell"></i></button>
<button type="button" id="forceAlmBtn" class="btn btn-danger" data-toggle="tooltip" data-placement="top" title="<?php echo translate('ForceAlarm') ?>" disabled><i class="fa fa-exclamation-circle"></i></button>
</div>
<div id="headerButtons">
<!--