@@ -175,6 +175,8 @@ Monitor::Monitor() :
175175 user(),
176176 pass(),
177177 // path
178+ onvif_event_listener(false ),
179+ use_Amcrest_API(false ),
178180 // device
179181 palette(0 ),
180182 channel(0 ),
@@ -1172,20 +1174,18 @@ bool Monitor::connect() {
11721174 // Janus_Manager->add_to_janus();
11731175 }
11741176
1175- // ONVIF and Amcrest Setup
1176- // For now, only support one event type per camera, so share some state.
1177- if (onvif_event_listener) { //
1177+ if (use_Amcrest_API) {
1178+ Amcrest_Manager = new AmcrestAPI (this );
1179+ }
1180+
1181+ if (onvif_event_listener) { //
11781182 Debug (1 , " Starting ONVIF" );
11791183 if (onvif_options.find (" closes_event" ) !=
11801184 std::string::npos) { // Option to indicate that ONVIF will send a
11811185 // close event message
11821186 Event_Poller_Closes_Event = true ;
11831187 }
1184- if (use_Amcrest_API) {
1185- Amcrest_Manager = new AmcrestAPI (this );
1186- } else { // using GSOAP
1187- onvif = new ONVIF (this );
1188- } // end if Armcrest or GSOAP
1188+ onvif = new ONVIF (this );
11891189 } else {
11901190 Debug (1 , " Not Starting ONVIF" );
11911191 } // End ONVIF Setup
@@ -2000,7 +2000,7 @@ int Monitor::Analyse() {
20002000
20012001#ifdef WITH_GSOAP
20022002 if (onvif_event_listener) {
2003- if (( onvif and onvif->isAlarmed ()) or (Amcrest_Manager and Amcrest_Manager-> isAlarmed () )) {
2003+ if (onvif and onvif->isAlarmed ()) {
20042004 score += 9 ;
20052005 Debug (4 , " Triggered on ONVIF" );
20062006 Event::StringSet noteSet;
@@ -2015,6 +2015,16 @@ int Monitor::Analyse() {
20152015 } // end if (onvif_event_listener && Event_Poller_Healthy)
20162016#endif
20172017
2018+ if (Amcrest_Manager and Amcrest_Manager->isAlarmed ()) {
2019+ score += 9 ;
2020+ Debug (4 , " Triggered on AMCREST" );
2021+ Event::StringSet noteSet;
2022+ noteSet.insert (" AMCREST" );
2023+ Amcrest_Manager->setNotes (noteSet);
2024+ noteSetMap[MOTION_CAUSE] = noteSet;
2025+ cause += " AMCREST" ;
2026+ }
2027+
20182028 // Specifically told to be on. Setting the score here is not enough to trigger the alarm. Must jump directly to ALARM
20192029 if (trigger_data->trigger_state == TriggerState::TRIGGER_ON) {
20202030 score += trigger_data->trigger_score ;
@@ -2353,14 +2363,13 @@ int Monitor::Analyse() {
23532363 } else if (event_close_mode == CLOSE_TIME) {
23542364 Debug (1 , " CLOSE_MODE Time" );
23552365 if (std::chrono::duration_cast<Seconds>(packet->timestamp .time_since_epoch ()) % section_length == Seconds (0 )) {
2356- Info (" %s: %03d - Closing event %" PRIu64 " , section end forced %" PRIi64 " - % " PRIi64 " = %" PRIi64 " >= % " PRIi64 ,
2366+ Info (" %s: %03d - Closing event %" PRIu64 " , section end forced %" PRIi64 " %% %" PRIi64 " = 0 " ,
23572367 name.c_str (),
23582368 packet->image_index ,
23592369 event->Id (),
23602370 static_cast <int64>(std::chrono::duration_cast<Seconds>(packet->timestamp .time_since_epoch ()).count ()),
2361- static_cast <int64>(std::chrono::duration_cast<Seconds>(event->StartTime ().time_since_epoch ()).count ()),
2362- static_cast <int64>(std::chrono::duration_cast<Seconds>(packet->timestamp - event->StartTime ()).count ()),
2363- static_cast <int64>(Seconds (section_length).count ()));
2371+ static_cast <int64>(Seconds (section_length).count ())
2372+ );
23642373 closeEvent ();
23652374 }
23662375 } else if (event_close_mode == CLOSE_IDLE) {
@@ -3800,14 +3809,21 @@ Event * Monitor::openEvent(
38003809 *analysis_it,
38013810 (cause == " Continuous" ? 0 : (pre_event_count > alarm_frame_count ? pre_event_count : alarm_frame_count))
38023811 );
3803- auto packet = *(*start_it);
3804- auto av_packet = packet->av_packet ();
3805-
3812+ auto starting_packet = *(*start_it);
3813+ auto av_packet = starting_packet->av_packet ();
38063814 ZM_DUMP_PACKET (av_packet, " start packet" );
38073815
3808- auto starting_packet = *start_it;
3809- event = new Event (this , start_it, (*starting_packet)->timestamp , cause, noteSetMap);
3810- SetVideoWriterStartTime ((*starting_packet)->timestamp );
3816+ event = new Event (this , start_it, starting_packet->timestamp , cause, noteSetMap);
3817+ SetVideoWriterStartTime (starting_packet->timestamp );
3818+
3819+ float start_duration = FPSeconds (packet_lock->packet_ ->timestamp - starting_packet->timestamp ).count ();
3820+ Debug (1 , " Event duration at start: %.2f" , start_duration);
3821+ if (start_duration >= Seconds (min_section_length).count ()) {
3822+ Warning (" Starting keyframe packet is more than %" PRId64 " seconds ago. Keyframe interval must be larger than that. "
3823+ " Either increase min_section_length or decrease keyframe interval. Automatically increasing min_section_length to %d seconds" ,
3824+ static_cast <int64>(Seconds (min_section_length).count ()), static_cast <int >(ceil (start_duration)));
3825+ min_section_length = Seconds (static_cast <int >(ceil (start_duration)) + 1 );
3826+ }
38113827
38123828 shared_data->last_event_id = event->Id ();
38133829 strncpy (shared_data->alarm_cause , cause.c_str (),
0 commit comments