Add alarm_cause to zm_packet. Clean up code dealing with decoding not being ready
This commit is contained in:
parent
a59e33d8b0
commit
198ee73d0e
|
@ -1828,27 +1828,14 @@ bool Monitor::Analyse() {
|
||||||
|
|
||||||
/* try to stay behind the decoder. */
|
/* try to stay behind the decoder. */
|
||||||
if (decoding_enabled) {
|
if (decoding_enabled) {
|
||||||
while (!snap->decoded and !zm_terminate and !analysis_thread->Stopped()) {
|
if (!snap->decoded and !zm_terminate and !analysis_thread->Stopped()) {
|
||||||
// Need to wait for the decoder thread.
|
// Need to wait for the decoder thread.
|
||||||
Debug(1, "Waiting for decode");
|
Debug(1, "Waiting for decode");
|
||||||
packetqueue.unlock(packet_lock); // This will delete packet_lock and notify_all
|
packetqueue.unlock(packet_lock); // This will delete packet_lock and notify_all
|
||||||
packetqueue.wait();
|
packetqueue.wait();
|
||||||
|
// Everything may have changed, just return and start again. This needs to be more RAII
|
||||||
// Another thread may have moved our it. Unlikely but possible
|
|
||||||
packet_lock = packetqueue.get_packet(analysis_it);
|
|
||||||
if (!packet_lock) return false;
|
|
||||||
snap = packet_lock->packet_;
|
|
||||||
|
|
||||||
if (!snap->image and snap->decoded) {
|
|
||||||
Debug(1, "No image but was decoded, giving up");
|
|
||||||
delete packet_lock;
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
} // end while ! decoded
|
|
||||||
if (zm_terminate) {
|
|
||||||
delete packet_lock;
|
|
||||||
return false;
|
return false;
|
||||||
}
|
} // end while ! decoded
|
||||||
} // end if decoding enabled
|
} // end if decoding enabled
|
||||||
|
|
||||||
SystemTimePoint timestamp = snap->timestamp;
|
SystemTimePoint timestamp = snap->timestamp;
|
||||||
|
@ -1864,46 +1851,43 @@ bool Monitor::Analyse() {
|
||||||
motion_frame_skip, capture_fps, analysis_fps_limit);
|
motion_frame_skip, capture_fps, analysis_fps_limit);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!(analysis_image_count % (motion_frame_skip+1))) {
|
if (snap->image) {
|
||||||
if (snap->image) {
|
// decoder may not have been able to provide an image
|
||||||
// decoder may not have been able to provide an image
|
if (!ref_image.Buffer()) {
|
||||||
if (!ref_image.Buffer()) {
|
Debug(1, "Assigning instead of Detecting");
|
||||||
Debug(1, "Assigning instead of Detecting");
|
ref_image.Assign(*(snap->image));
|
||||||
ref_image.Assign(*(snap->image));
|
} else if (!(analysis_image_count % (motion_frame_skip+1))) {
|
||||||
} else {
|
Debug(1, "Detecting motion on image %d, image %p", snap->image_index, snap->image);
|
||||||
Debug(1, "Detecting motion on image %d, image %p", snap->image_index, snap->image);
|
// Get new score.
|
||||||
// Get new score.
|
int motion_score = DetectMotion(*(snap->image), zoneSet);
|
||||||
int motion_score = DetectMotion(*(snap->image), zoneSet);
|
|
||||||
|
|
||||||
// lets construct alarm cause. It will contain cause + names of zones alarmed
|
// lets construct alarm cause. It will contain cause + names of zones alarmed
|
||||||
std::string alarm_cause;
|
snap->zone_stats.reserve(zones.size());
|
||||||
snap->zone_stats.reserve(zones.size());
|
for (const Zone &zone : zones) {
|
||||||
for (const Zone &zone : zones) {
|
const ZoneStats &stats = zone.GetStats();
|
||||||
const ZoneStats &stats = zone.GetStats();
|
stats.DumpToLog("After detect motion");
|
||||||
stats.DumpToLog("After detect motion");
|
snap->zone_stats.push_back(stats);
|
||||||
snap->zone_stats.push_back(stats);
|
if (zone.Alarmed()) {
|
||||||
if (zone.Alarmed()) {
|
if (!snap->alarm_cause.empty()) snap->alarm_cause += ",";
|
||||||
if (!alarm_cause.empty()) alarm_cause += ",";
|
snap->alarm_cause += std::string(zone.Label());
|
||||||
alarm_cause += std::string(zone.Label());
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
Debug(3, "After motion detection, score:%d last_motion_score(%d), new motion score(%d)",
|
|
||||||
score, last_motion_score, motion_score);
|
|
||||||
motion_frame_count += 1;
|
|
||||||
last_motion_score = motion_score;
|
|
||||||
|
|
||||||
if (motion_score) {
|
|
||||||
if (cause.length()) cause += ", ";
|
|
||||||
cause += MOTION_CAUSE+std::string(":")+alarm_cause;
|
|
||||||
noteSetMap[MOTION_CAUSE] = zoneSet;
|
|
||||||
} // end if motion_score
|
|
||||||
}
|
}
|
||||||
|
Debug(3, "After motion detection, score:%d last_motion_score(%d), new motion score(%d)",
|
||||||
|
score, last_motion_score, motion_score);
|
||||||
|
motion_frame_count += 1;
|
||||||
|
last_motion_score = motion_score;
|
||||||
|
|
||||||
|
if (motion_score) {
|
||||||
|
if (cause.length()) cause += ", ";
|
||||||
|
cause += MOTION_CAUSE+std::string(":")+snap->alarm_cause;
|
||||||
|
noteSetMap[MOTION_CAUSE] = zoneSet;
|
||||||
|
} // end if motion_score
|
||||||
} else {
|
} else {
|
||||||
Debug(1, "no image so skipping motion detection");
|
Debug(1, "Skipped motion detection last motion score was %d", last_motion_score);
|
||||||
} // end if has image
|
}
|
||||||
} else {
|
} else {
|
||||||
Debug(1, "Skipped motion detection last motion score was %d", last_motion_score);
|
Debug(1, "no image so skipping motion detection");
|
||||||
}
|
} // end if has image
|
||||||
score += last_motion_score;
|
score += last_motion_score;
|
||||||
} else {
|
} else {
|
||||||
Debug(1, "Not Active(%d) enabled %d active %d doing motion detection: %d",
|
Debug(1, "Not Active(%d) enabled %d active %d doing motion detection: %d",
|
||||||
|
@ -1912,7 +1896,6 @@ bool Monitor::Analyse() {
|
||||||
);
|
);
|
||||||
} // end if active and doing motion detection
|
} // end if active and doing motion detection
|
||||||
|
|
||||||
|
|
||||||
if (function == RECORD or function == MOCORD) {
|
if (function == RECORD or function == MOCORD) {
|
||||||
// If doing record, check to see if we need to close the event or not.
|
// If doing record, check to see if we need to close the event or not.
|
||||||
if (event) {
|
if (event) {
|
||||||
|
|
|
@ -57,6 +57,7 @@ class ZMPacket {
|
||||||
int64_t pts; // pts in the packet can be in another time base. This MUST be in AV_TIME_BASE_Q
|
int64_t pts; // pts in the packet can be in another time base. This MUST be in AV_TIME_BASE_Q
|
||||||
bool decoded;
|
bool decoded;
|
||||||
std::vector<ZoneStats> zone_stats;
|
std::vector<ZoneStats> zone_stats;
|
||||||
|
std::string alarm_cause;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
AVPacket *av_packet() { return &packet; }
|
AVPacket *av_packet() { return &packet; }
|
||||||
|
|
Loading…
Reference in New Issue