From efa264e0c7ae633bcc5ea7111dbb53157c739bbb Mon Sep 17 00:00:00 2001 From: Isaac Connor Date: Fri, 16 Aug 2019 10:24:51 -0400 Subject: [PATCH 1/8] Fix playing in reverse. Fix not sending first frame. Fix sql problem with backticks. Not being able to open a frame image is now non-fatal. --- src/zm_eventstream.cpp | 37 ++++++++++++++++++++----------------- src/zm_stream.h | 1 + 2 files changed, 21 insertions(+), 17 deletions(-) diff --git a/src/zm_eventstream.cpp b/src/zm_eventstream.cpp index 4b894c153..6bbfbe5c2 100644 --- a/src/zm_eventstream.cpp +++ b/src/zm_eventstream.cpp @@ -116,7 +116,7 @@ bool EventStream::loadEventData(uint64_t event_id) { snprintf(sql, sizeof(sql), "SELECT `MonitorId`, `StorageId`, `Frames`, unix_timestamp( `StartTime` ) AS StartTimestamp, " - "(SELECT max(`Delta`)-min(`Delta`) FROM `Frames` WHERE `EventId`=`Events.Id`) AS Duration, " + "(SELECT max(`Delta`)-min(`Delta`) FROM `Frames` WHERE `EventId`=`Events`.`Id`) AS Duration, " "`DefaultVideo`, `Scheme`, `SaveJPEGs` FROM `Events` WHERE `Id` = %" PRIu64, event_id); if ( mysql_query(&dbconn, sql) ) { @@ -674,7 +674,7 @@ bool EventStream::sendFrame(int delta_us) { fdj = fopen(filepath, "rb"); if ( !fdj ) { Error("Can't open %s: %s", filepath, strerror(errno)); - return false; + return true; // returning false will cause us to terminate. } #if HAVE_SENDFILE if ( fstat(fileno(fdj),&filestat) < 0 ) { @@ -829,12 +829,6 @@ void EventStream::runStream() { Debug(2, "Not checking command queue"); } - //if ( step != 0 )// Adding 0 is cheaper than an if 0 - // curr_frame_id starts at 1 though, so we might skip the first frame? - curr_frame_id += step; - - // Detects when we hit end of event and will load the next event or previous event - checkEventLoaded(); // Get current frame data FrameData *frame_data = &event_data->frames[curr_frame_id-1]; @@ -926,7 +920,6 @@ void EventStream::runStream() { } // end if streaming stepping or doing nothing if ( send_frame ) { - //Debug(3,"sending frame"); if ( !sendFrame(delta_us) ) zm_terminate = true; } @@ -958,8 +951,11 @@ void EventStream::runStream() { // or calc the relationship from the last frame. I think from the start is better as it self-corrects if ( send_frame && type != STREAM_MPEG ) { - if ( delta_us > 0 ) { - Debug(3, "dUs: %d", delta_us); + if ( delta_us > 0) { + if ( delta_us > MAX_SLEEP_USEC ) { + Debug(1, "Limiting sleep to %d because calculated sleep is too long %d", MAX_SLEEP_USEC, delta_us); + delta_us = MAX_SLEEP_USEC; + } usleep(delta_us); Debug(3, "Done sleeping: %d usec", delta_us); } @@ -971,16 +967,23 @@ void EventStream::runStream() { (unsigned long)((1000000 * ZM_RATE_BASE)/((base_fps?base_fps:1)*abs(replay_rate*2))), ZM_RATE_BASE, (base_fps?base_fps:1), - (replay_rate?abs(replay_rate*2):200) + (replay_rate?abs(replay_rate*2):0) ); - if ( delta_us > 0 and delta_us < 500000 ) { + if ( delta_us > 0 ) { + if ( delta_us > MAX_SLEEP_USEC ) { + Debug(1, "Limiting sleep to %d because calculated sleep is too long %d", MAX_SLEEP_USEC, delta_us); + delta_us = MAX_SLEEP_USEC; + } usleep(delta_us); - } else { - // Never want to sleep for too long, limit to .1s - Warning("sleeping .5s because delta_us (%d) not good!", delta_us); - usleep(500000); } } // end if !paused + + //if ( step != 0 )// Adding 0 is cheaper than an if 0 + // curr_frame_id starts at 1 though, so we might skip the first frame? + curr_frame_id += step; + + // Detects when we hit end of event and will load the next event or previous event + checkEventLoaded(); } // end while ! zm_terminate #if HAVE_LIBAVCODEC if ( type == STREAM_MPEG ) diff --git a/src/zm_stream.h b/src/zm_stream.h index 4f4f144a3..d4443cb39 100644 --- a/src/zm_stream.h +++ b/src/zm_stream.h @@ -36,6 +36,7 @@ public: protected: static const int MAX_STREAM_DELAY = 5; // Seconds + static const int MAX_SLEEP_USEC = 500000; // .5 Seconds static const StreamType DEFAULT_TYPE = STREAM_JPEG; enum { DEFAULT_RATE=ZM_RATE_BASE }; From f813741730de4e0b6af2f09ec386aba8d495a0cc Mon Sep 17 00:00:00 2001 From: Isaac Connor Date: Fri, 16 Aug 2019 11:31:27 -0400 Subject: [PATCH 2/8] Add maxage 7 to logrotate config so that it will clear out all the zms_e logs. --- distros/ubuntu1204/zoneminder.logrotate | 1 + distros/ubuntu1604/zoneminder.logrotate | 1 + 2 files changed, 2 insertions(+) diff --git a/distros/ubuntu1204/zoneminder.logrotate b/distros/ubuntu1204/zoneminder.logrotate index 846abd4fb..3195d0fb2 100644 --- a/distros/ubuntu1204/zoneminder.logrotate +++ b/distros/ubuntu1204/zoneminder.logrotate @@ -9,4 +9,5 @@ endscript daily rotate 7 + maxage 7 } diff --git a/distros/ubuntu1604/zoneminder.logrotate b/distros/ubuntu1604/zoneminder.logrotate index 59238b7fe..6162e9c4d 100644 --- a/distros/ubuntu1604/zoneminder.logrotate +++ b/distros/ubuntu1604/zoneminder.logrotate @@ -9,4 +9,5 @@ endscript daily rotate 7 + maxage 7 } From 376b8af88900b04ebadf1c280ed48d31e8788cb3 Mon Sep 17 00:00:00 2001 From: Isaac Connor Date: Fri, 16 Aug 2019 11:40:38 -0400 Subject: [PATCH 3/8] Make links in donate text actual links --- web/lang/en_gb.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/web/lang/en_gb.php b/web/lang/en_gb.php index 0e575fd1f..18a1d72dd 100644 --- a/web/lang/en_gb.php +++ b/web/lang/en_gb.php @@ -300,7 +300,7 @@ $SLANG = array( 'Display' => 'Display', 'Displaying' => 'Displaying', 'DonateAlready' => 'No, I\'ve already donated', - 'DonateEnticement' => 'You\'ve been running ZoneMinder for a while now and hopefully are finding it a useful addition to your home or workplace security. Although ZoneMinder is, and will remain, free and open source, it costs money to develop and support. If you would like to help support future development and new features then please consider donating. Donating is, of course, optional but very much appreciated and you can donate as much or as little as you like.

If you would like to donate please select the option below or go to https://zoneminder.com/donate/ in your browser.

Thank you for using ZoneMinder and don\'t forget to visit the forums on ZoneMinder.com for support or suggestions about how to make your ZoneMinder experience even better.', + 'DonateEnticement' => 'You\'ve been running ZoneMinder for a while now and hopefully are finding it a useful addition to your home or workplace security. Although ZoneMinder is, and will remain, free and open source, it costs money to develop and support. If you would like to help support future development and new features then please consider donating. Donating is, of course, optional but very much appreciated and you can donate as much or as little as you like.

If you would like to donate please select the option below or go to https://zoneminder.com/donate/ in your browser.

Thank you for using ZoneMinder and don\'t forget to visit the forums on ZoneMinder.com for support or suggestions about how to make your ZoneMinder experience even better.', 'Donate' => 'Please Donate', 'DonateRemindDay' => 'Not yet, remind again in 1 day', 'DonateRemindHour' => 'Not yet, remind again in 1 hour', From 503cf6cd249d2a76d84ad01d646d96f24120561f Mon Sep 17 00:00:00 2001 From: Isaac Connor Date: Sat, 17 Aug 2019 14:36:52 -0400 Subject: [PATCH 4/8] More backticking of SQL --- src/zm_monitor.cpp | 38 ++++++++++++++++++++++---------------- 1 file changed, 22 insertions(+), 16 deletions(-) diff --git a/src/zm_monitor.cpp b/src/zm_monitor.cpp index 1b9442f75..f8f32ecd7 100644 --- a/src/zm_monitor.cpp +++ b/src/zm_monitor.cpp @@ -965,7 +965,7 @@ void Monitor::actionEnable() { db_mutex.lock(); static char sql[ZM_SQL_SML_BUFSIZ]; - snprintf(sql, sizeof(sql), "UPDATE Monitors SET Enabled = 1 WHERE Id = %d", id); + snprintf(sql, sizeof(sql), "UPDATE `Monitors` SET `Enabled` = 1 WHERE `Id` = %d", id); if ( mysql_query(&dbconn, sql) ) { Error("Can't run query: %s", mysql_error(&dbconn)); } @@ -976,7 +976,7 @@ void Monitor::actionDisable() { shared_data->action |= RELOAD; static char sql[ZM_SQL_SML_BUFSIZ]; - snprintf(sql, sizeof(sql), "update Monitors set Enabled = 0 where Id = %d", id); + snprintf(sql, sizeof(sql), "UPDATE `Monitors` SET i`Enabled` = 0 WHERE `Id` = %d", id); db_mutex.lock(); if ( mysql_query(&dbconn, sql) ) { Error("Can't run query: %s", mysql_error(&dbconn)); @@ -1946,7 +1946,13 @@ void Monitor::ReloadLinkedMonitors(const char *p_linked_monitors) { db_mutex.lock(); static char sql[ZM_SQL_SML_BUFSIZ]; - snprintf(sql, sizeof(sql), "select Id, Name from Monitors where Id = %d and Function != 'None' and Function != 'Monitor' and Enabled = 1", link_ids[i] ); + snprintf(sql, sizeof(sql), + "SELECT `Id`, `Name` FROM `Monitors`" + " WHERE `Id` = %d" + " AND `Function` != 'None'" + " AND `Function` != 'Monitor'" + " AND `Enabled`=1", + link_ids[i] ); if ( mysql_query(&dbconn, sql) ) { db_mutex.unlock(); Error("Can't run query: %s", mysql_error(&dbconn)); @@ -2003,44 +2009,44 @@ int Monitor::LoadMonitors(std::string sql, Monitor **&monitors, Purpose purpose) #if ZM_HAS_V4L int Monitor::LoadLocalMonitors(const char *device, Monitor **&monitors, Purpose purpose) { - std::string sql = load_monitor_sql + " WHERE Function != 'None' AND Type = 'Local'"; + std::string sql = load_monitor_sql + " WHERE `Function` != 'None' AND `Type` = 'Local'"; if ( device[0] ) - sql += " AND Device='" + std::string(device) + "'"; + sql += " AND `Device`='" + std::string(device) + "'"; if ( staticConfig.SERVER_ID ) - sql += stringtf(" AND ServerId=%d", staticConfig.SERVER_ID); + sql += stringtf(" AND `ServerId`=%d", staticConfig.SERVER_ID); return LoadMonitors(sql, monitors, purpose); } // end int Monitor::LoadLocalMonitors(const char *device, Monitor **&monitors, Purpose purpose) #endif // ZM_HAS_V4L int Monitor::LoadRemoteMonitors(const char *protocol, const char *host, const char *port, const char *path, Monitor **&monitors, Purpose purpose) { - std::string sql = load_monitor_sql + " WHERE Function != 'None' AND Type = 'Remote'"; + std::string sql = load_monitor_sql + " WHERE `Function` != 'None' AND `Type` = 'Remote'"; if ( staticConfig.SERVER_ID ) - sql += stringtf(" AND ServerId=%d", staticConfig.SERVER_ID); + sql += stringtf(" AND `ServerId`=%d", staticConfig.SERVER_ID); if ( protocol ) - sql += stringtf(" AND Protocol = '%s' and Host = '%s' and Port = '%s' and Path = '%s'", protocol, host, port, path); + sql += stringtf(" AND `Protocol` = '%s' AND `Host` = '%s' AND `Port` = '%s' AND `Path` = '%s'", protocol, host, port, path); return LoadMonitors(sql, monitors, purpose); } // end int Monitor::LoadRemoteMonitors int Monitor::LoadFileMonitors(const char *file, Monitor **&monitors, Purpose purpose) { - std::string sql = load_monitor_sql + " WHERE Function != 'None' AND Type = 'File'"; + std::string sql = load_monitor_sql + " WHERE `Function` != 'None' AND `Type` = 'File'"; if ( file[0] ) - sql += " AND Path='" + std::string(file) + "'"; + sql += " AND `Path`='" + std::string(file) + "'"; if ( staticConfig.SERVER_ID ) { - sql += stringtf(" AND ServerId=%d", staticConfig.SERVER_ID); + sql += stringtf(" AND `ServerId`=%d", staticConfig.SERVER_ID); } return LoadMonitors(sql, monitors, purpose); } // end int Monitor::LoadFileMonitors #if HAVE_LIBAVFORMAT int Monitor::LoadFfmpegMonitors(const char *file, Monitor **&monitors, Purpose purpose) { - std::string sql = load_monitor_sql + " WHERE Function != 'None' AND Type = 'Ffmpeg'"; + std::string sql = load_monitor_sql + " WHERE `Function` != 'None' AND `Type` = 'Ffmpeg'"; if ( file[0] ) - sql += " AND Path = '" + std::string(file) + "'"; + sql += " AND `Path` = '" + std::string(file) + "'"; if ( staticConfig.SERVER_ID ) { - sql += stringtf(" AND ServerId=%d", staticConfig.SERVER_ID); + sql += stringtf(" AND `ServerId`=%d", staticConfig.SERVER_ID); } return LoadMonitors(sql, monitors, purpose); } // end int Monitor::LoadFfmpegMonitors @@ -2380,7 +2386,7 @@ Monitor *Monitor::Load(MYSQL_ROW dbrow, bool load_zones, Purpose purpose) { } // end Monitor *Monitor::Load(MYSQL_ROW dbrow, bool load_zones, Purpose purpose) Monitor *Monitor::Load(unsigned int p_id, bool load_zones, Purpose purpose) { - std::string sql = load_monitor_sql + stringtf(" WHERE Id=%d", p_id); + std::string sql = load_monitor_sql + stringtf(" WHERE `Id`=%d", p_id); zmDbRow dbrow; if ( ! dbrow.fetch(sql.c_str()) ) { From 369dd03909c7a2476eff4f7ad72e24f530918f16 Mon Sep 17 00:00:00 2001 From: Isaac Connor Date: Sun, 18 Aug 2019 21:32:19 -0400 Subject: [PATCH 5/8] remove errant i --- src/zm_monitor.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/zm_monitor.cpp b/src/zm_monitor.cpp index f8f32ecd7..d8d06016a 100644 --- a/src/zm_monitor.cpp +++ b/src/zm_monitor.cpp @@ -976,7 +976,7 @@ void Monitor::actionDisable() { shared_data->action |= RELOAD; static char sql[ZM_SQL_SML_BUFSIZ]; - snprintf(sql, sizeof(sql), "UPDATE `Monitors` SET i`Enabled` = 0 WHERE `Id` = %d", id); + snprintf(sql, sizeof(sql), "UPDATE `Monitors` SET `Enabled` = 0 WHERE `Id` = %d", id); db_mutex.lock(); if ( mysql_query(&dbconn, sql) ) { Error("Can't run query: %s", mysql_error(&dbconn)); From 239c68dd7f91fb0dff30c5c07f1b627b90fcf13d Mon Sep 17 00:00:00 2001 From: Isaac Connor Date: Mon, 19 Aug 2019 08:58:52 -0400 Subject: [PATCH 6/8] add .. to fix #2686 --- web/skins/classic/css/classic/skin.css | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/web/skins/classic/css/classic/skin.css b/web/skins/classic/css/classic/skin.css index b90412093..6f3ed4b97 100644 --- a/web/skins/classic/css/classic/skin.css +++ b/web/skins/classic/css/classic/skin.css @@ -324,14 +324,14 @@ th.table-th-sort span.table-th-sort-span { float: right; width: 12px; height: 12px; - background: url("/skins/classic/graphics/arrow-s-u.png") no-repeat 0 0; + background: url("../skins/classic/graphics/arrow-s-u.png") no-repeat 0 0; } th.table-th-sort-rev span.table-th-sort-span { float: right; width: 12px; height: 12px; - background: url("/skins/classic/graphics/arrow-s-d.png") no-repeat 0 0; + background: url("../skins/classic/graphics/arrow-s-d.png") no-repeat 0 0; } .table-tr-odd { From ca0b5830073002e7b3a03ce931b7fe8c74dfb12c Mon Sep 17 00:00:00 2001 From: Isaac Connor Date: Mon, 19 Aug 2019 08:59:15 -0400 Subject: [PATCH 7/8] Use material icons for sort because they look nicer --- web/skins/classic/views/console.php | 3 ++- web/skins/classic/views/js/console.js | 8 ++++---- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/web/skins/classic/views/console.php b/web/skins/classic/views/console.php index c4c99e166..b1cc51215 100644 --- a/web/skins/classic/views/console.php +++ b/web/skins/classic/views/console.php @@ -328,7 +328,8 @@ for( $monitor_i = 0; $monitor_i < count($displayMonitors); $monitor_i += 1 ) { ?> disabled="disabled"/> - + +swap_vert Date: Mon, 19 Aug 2019 11:12:47 -0400 Subject: [PATCH 8/8] fix typo --- src/zm_ffmpeg_camera.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/zm_ffmpeg_camera.cpp b/src/zm_ffmpeg_camera.cpp index d9736d6a3..686123ce3 100644 --- a/src/zm_ffmpeg_camera.cpp +++ b/src/zm_ffmpeg_camera.cpp @@ -482,7 +482,7 @@ int FfmpegCamera::OpenFfmpeg() { hw_pix_fmt = find_fmt_by_hw_type(type); #endif if ( hw_pix_fmt != AV_PIX_FMT_NONE ) { - Debug(1, "Selected gw_pix_fmt %d %s", + Debug(1, "Selected hw_pix_fmt %d %s", hw_pix_fmt, av_get_pix_fmt_name(hw_pix_fmt));