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. */
|
||||
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.
|
||||
Debug(1, "Waiting for decode");
|
||||
packetqueue.unlock(packet_lock); // This will delete packet_lock and notify_all
|
||||
packetqueue.wait();
|
||||
|
||||
// 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;
|
||||
// Everything may have changed, just return and start again. This needs to be more RAII
|
||||
return false;
|
||||
}
|
||||
} // end while ! decoded
|
||||
if (zm_terminate) {
|
||||
delete packet_lock;
|
||||
return false;
|
||||
}
|
||||
} // end if decoding enabled
|
||||
|
||||
SystemTimePoint timestamp = snap->timestamp;
|
||||
|
@ -1864,27 +1851,25 @@ bool Monitor::Analyse() {
|
|||
motion_frame_skip, capture_fps, analysis_fps_limit);
|
||||
}
|
||||
|
||||
if (!(analysis_image_count % (motion_frame_skip+1))) {
|
||||
if (snap->image) {
|
||||
// decoder may not have been able to provide an image
|
||||
if (!ref_image.Buffer()) {
|
||||
Debug(1, "Assigning instead of Detecting");
|
||||
ref_image.Assign(*(snap->image));
|
||||
} else {
|
||||
} else if (!(analysis_image_count % (motion_frame_skip+1))) {
|
||||
Debug(1, "Detecting motion on image %d, image %p", snap->image_index, snap->image);
|
||||
// Get new score.
|
||||
int motion_score = DetectMotion(*(snap->image), zoneSet);
|
||||
|
||||
// lets construct alarm cause. It will contain cause + names of zones alarmed
|
||||
std::string alarm_cause;
|
||||
snap->zone_stats.reserve(zones.size());
|
||||
for (const Zone &zone : zones) {
|
||||
const ZoneStats &stats = zone.GetStats();
|
||||
stats.DumpToLog("After detect motion");
|
||||
snap->zone_stats.push_back(stats);
|
||||
if (zone.Alarmed()) {
|
||||
if (!alarm_cause.empty()) alarm_cause += ",";
|
||||
alarm_cause += std::string(zone.Label());
|
||||
if (!snap->alarm_cause.empty()) snap->alarm_cause += ",";
|
||||
snap->alarm_cause += std::string(zone.Label());
|
||||
}
|
||||
}
|
||||
Debug(3, "After motion detection, score:%d last_motion_score(%d), new motion score(%d)",
|
||||
|
@ -1894,16 +1879,15 @@ bool Monitor::Analyse() {
|
|||
|
||||
if (motion_score) {
|
||||
if (cause.length()) cause += ", ";
|
||||
cause += MOTION_CAUSE+std::string(":")+alarm_cause;
|
||||
cause += MOTION_CAUSE+std::string(":")+snap->alarm_cause;
|
||||
noteSetMap[MOTION_CAUSE] = zoneSet;
|
||||
} // end if motion_score
|
||||
} else {
|
||||
Debug(1, "Skipped motion detection last motion score was %d", last_motion_score);
|
||||
}
|
||||
} else {
|
||||
Debug(1, "no image so skipping motion detection");
|
||||
} // end if has image
|
||||
} else {
|
||||
Debug(1, "Skipped motion detection last motion score was %d", last_motion_score);
|
||||
}
|
||||
score += last_motion_score;
|
||||
} else {
|
||||
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
|
||||
|
||||
|
||||
if (function == RECORD or function == MOCORD) {
|
||||
// If doing record, check to see if we need to close the event or not.
|
||||
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
|
||||
bool decoded;
|
||||
std::vector<ZoneStats> zone_stats;
|
||||
std::string alarm_cause;
|
||||
|
||||
public:
|
||||
AVPacket *av_packet() { return &packet; }
|
||||
|
|
Loading…
Reference in New Issue