From 947132284d2a2a5bda192838e22671d0d20b0793 Mon Sep 17 00:00:00 2001 From: Isaac Connor Date: Mon, 10 Jan 2022 14:44:52 -0500 Subject: [PATCH 1/6] When transitioning from ALERT to IDLE, close the event if CLOSE_MODE is IDLE as well as ALARM. --- src/zm_monitor.cpp | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/zm_monitor.cpp b/src/zm_monitor.cpp index e07b872fc..093a32ad7 100644 --- a/src/zm_monitor.cpp +++ b/src/zm_monitor.cpp @@ -2132,8 +2132,11 @@ bool Monitor::Analyse() { ((timestamp - event->StartTime()) >= min_section_length)) { Info("%s: %03d - Left alarm state (%" PRIu64 ") - %d(%d) images", name.c_str(), analysis_image_count, event->Id(), event->Frames(), event->AlarmFrames()); - //if ( function != MOCORD || event_close_mode == CLOSE_ALARM || event->Cause() == SIGNAL_CAUSE ) - if ( (function != RECORD && function != MOCORD ) || event_close_mode == CLOSE_ALARM ) { + if ( + (function != RECORD && function != MOCORD) + || + (event_close_mode == CLOSE_ALARM || event_close_mode=CLOSE_IDLE) + ) { shared_data->state = state = IDLE; Info("%s: %03d - Closing event %" PRIu64 ", alarm end%s", name.c_str(), analysis_image_count, event->Id(), (function==MOCORD)?", section truncated":"" ); From a0c34f0d96deea7015e60f7f8629e30fd3696966 Mon Sep 17 00:00:00 2001 From: Isaac Connor Date: Mon, 10 Jan 2022 18:33:01 -0500 Subject: [PATCH 2/6] Fix. cppcheck was wrong about divider being able to go into deeper scope. --- src/zm_image.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/zm_image.cpp b/src/zm_image.cpp index 99fcf4ee1..1c58130cc 100644 --- a/src/zm_image.cpp +++ b/src/zm_image.cpp @@ -3306,9 +3306,9 @@ void neon32_armv7_fastblend(const uint8_t* col1, const uint8_t* col2, uint8_t* r __attribute__((noinline)) void neon64_armv8_fastblend(const uint8_t* col1, const uint8_t* col2, uint8_t* result, unsigned long count, double blendpercent) { #if (defined(__aarch64__) && !defined(ZM_STRIP_NEON)) static double current_blendpercent = 0.0; + static int8_t divider = 0; if (current_blendpercent != blendpercent) { - static int8_t divider = 0; /* Attempt to match the blending percent to one of the possible values */ if(blendpercent < 2.34375) { // 1.5625% blending From cb30f7639f29ec21214450094ea3ddd4f4505273 Mon Sep 17 00:00:00 2001 From: Isaac Connor Date: Mon, 10 Jan 2022 18:47:26 -0500 Subject: [PATCH 3/6] revert broken commit. Isaac doesn't know what he's doing. --- src/zm_utils.cpp | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/src/zm_utils.cpp b/src/zm_utils.cpp index bc17e5758..6ea4e0dae 100644 --- a/src/zm_utils.cpp +++ b/src/zm_utils.cpp @@ -120,16 +120,18 @@ std::string Join(const StringVector &values, const std::string &delim) { std::string stringtf(const char* format, ...) { va_list args; va_start(args, format); - int size = vsnprintf(nullptr, 0, format, args) + 1; // Extra space for '\0' - va_end(args); - - if (size <= 0) { - throw std::runtime_error("Error during formatting."); - } - - std::unique_ptr buf(new char[size]); va_list args2; va_copy(args2, args); + int size = vsnprintf(nullptr, 0, format, args); + va_end(args); + + if (size < 0) { + va_end(args2); + throw std::runtime_error("Error during formatting."); + } + size += 1; // Extra space for '\0' + + std::unique_ptr buf(new char[size]); vsnprintf(buf.get(), size, format, args2); va_end(args2); From 81fc392bc2184a4bc84808701eae518acad8f313 Mon Sep 17 00:00:00 2001 From: Isaac Connor Date: Mon, 10 Jan 2022 19:56:00 -0500 Subject: [PATCH 4/6] If error is ENOSPACE just give up. ffmpeg crashes if we try again. --- src/zm_videostore.cpp | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/src/zm_videostore.cpp b/src/zm_videostore.cpp index ad401b22c..0038348ef 100644 --- a/src/zm_videostore.cpp +++ b/src/zm_videostore.cpp @@ -497,8 +497,14 @@ bool VideoStore::open() { Debug(1, "using movflags %s", movflags_entry->value); } if ((ret = avformat_write_header(oc, &opts)) < 0) { - Warning("Unable to set movflags trying with defaults."); - ret = avformat_write_header(oc, nullptr); + // we crash if we try again + if (ENOSPC != ret) { + Warning("Unable to set movflags trying with defaults.%d %s", + ret, av_make_error_string(ret).c_str()); + + ret = avformat_write_header(oc, nullptr); + Debug(1, "Done %d", ret); + } } else if (av_dict_count(opts) != 0) { Info("some options not used, turn on debugging for a list."); AVDictionaryEntry *e = nullptr; From 90cbf5a018b615c67be312d0d169354058673cdd Mon Sep 17 00:00:00 2001 From: Isaac Connor Date: Tue, 11 Jan 2022 09:06:43 -0500 Subject: [PATCH 5/6] Fix == instead of = --- 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 9cf2acdce..4feea00fe 100644 --- a/src/zm_monitor.cpp +++ b/src/zm_monitor.cpp @@ -2135,7 +2135,7 @@ bool Monitor::Analyse() { if ( (function != RECORD && function != MOCORD) || - (event_close_mode == CLOSE_ALARM || event_close_mode=CLOSE_IDLE) + (event_close_mode == CLOSE_ALARM || event_close_mode==CLOSE_IDLE) ) { shared_data->state = state = IDLE; Info("%s: %03d - Closing event %" PRIu64 ", alarm end%s", From aaaf87abdbcea02d110da556e95b11931ae78b96 Mon Sep 17 00:00:00 2001 From: Isaac Connor Date: Tue, 11 Jan 2022 09:08:01 -0500 Subject: [PATCH 6/6] Don't try again if the error was ENOSPACE. it crashes and there is just no point. --- src/zm_videostore.cpp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/zm_videostore.cpp b/src/zm_videostore.cpp index 01e46d9c7..249ff222a 100644 --- a/src/zm_videostore.cpp +++ b/src/zm_videostore.cpp @@ -508,6 +508,8 @@ bool VideoStore::open() { ret = avformat_write_header(oc, nullptr); Debug(1, "Done %d", ret); + } else { + Error("ENOSPC. fail"); } } else if (av_dict_count(opts) != 0) { Info("some options not used, turn on debugging for a list.");