@@ -141,10 +141,9 @@ public enum RequestType {
141
141
private IpCameraHandler ipCameraHandler ;
142
142
// Use/skip events even if camera support them. API cameras skip, as their own methods give better results.
143
143
private boolean usingEvents = false ;
144
- private int onvifEventServiceType = 0 ; // 0 = disabled , 1 = PullMessages , 2 = WSBaseSubscription
144
+ private int onvifEventServiceType = 0 ; // 0 = auto detect , 1 = disabled , 2 = PullMessages, 3 = WSBaseSubscription
145
145
public AtomicInteger pullMessageRequests = new AtomicInteger ();
146
146
private long createSubscriptionTimestamp ;
147
- public long lastPullMessageReceivedTimestamp ;
148
147
149
148
// These hold the cameras PTZ position in the range that the camera uses, ie
150
149
// mine is -1 to +1
@@ -425,13 +424,18 @@ public void processReply(RequestType requestType, String message) {
425
424
426
425
private void setOnvifEventServiceType (boolean cameraSupportsPullPointSupport ,
427
426
boolean cameraSupportsSubscriptionPolicySupport ) {
428
- if (cameraSupportsPullPointSupport && ipCameraHandler .cameraConfig .getOnvifEventServiceType () == 0
429
- || ipCameraHandler .cameraConfig .getOnvifEventServiceType () == 2 ) {
430
- onvifEventServiceType = 1 ;
431
- } else if (cameraSupportsSubscriptionPolicySupport
432
- && ipCameraHandler .cameraConfig .getOnvifEventServiceType () == 0
433
- || ipCameraHandler .cameraConfig .getOnvifEventServiceType () == 3 ) {
427
+ // 0 = auto detect, 1 = disabled, 2 = PullMessages, 3 = WSBaseSubscription
428
+ if (cameraSupportsPullPointSupport && ipCameraHandler .cameraConfig .getOnvifEventServiceType () == 0 ) {
434
429
onvifEventServiceType = 2 ;
430
+ } else if (cameraSupportsSubscriptionPolicySupport
431
+ && ipCameraHandler .cameraConfig .getOnvifEventServiceType () == 0 ) {
432
+ onvifEventServiceType = 3 ;
433
+ } else if (ipCameraHandler .cameraConfig .getOnvifEventServiceType () == 0 ) {
434
+ logger .warn (
435
+ "Camera at {} could not auto detect the ONVIF event method the camera supports, try setting the configuration away from auto to remove this message by forcing an option." ,
436
+ ipAddress );
437
+ } else {
438
+ onvifEventServiceType = ipCameraHandler .cameraConfig .getOnvifEventServiceType ();
435
439
}
436
440
}
437
441
@@ -480,7 +484,7 @@ void setSubscriptionXAddr(String message) {
480
484
481
485
public void createSubscription () {
482
486
if (!getEventsSupported ()) {
483
- // ONVIF events are disabled or not supported.
487
+ logger . debug ( " ONVIF events are disabled or not supported for camera at {}" , ipAddress );
484
488
return ;
485
489
}
486
490
@@ -495,9 +499,9 @@ public void createSubscription() {
495
499
496
500
// Prefer PullPoint events over WSBaseSubscription because there is no way to check if a WSBaseSubscription is
497
501
// already registered on the camera.
498
- if (onvifEventServiceType == 1 ) {
502
+ if (onvifEventServiceType == 2 ) {
499
503
sendOnvifRequest (RequestType .CreatePullPointSubscription , eventXAddr );
500
- } else if (onvifEventServiceType == 2 ) {
504
+ } else if (onvifEventServiceType == 3 ) {
501
505
sendOnvifRequest (RequestType .Subscribe , eventXAddr );
502
506
}
503
507
}
@@ -507,20 +511,20 @@ public void createSubscription() {
507
511
* needed.
508
512
*/
509
513
public void checkAndRenewEventSubscription () {
510
- if (getEventsSupported ()) {
511
- // If we get events via PullMessages check if a PullMessages request is running or we just received an
512
- // answer in the last second. If this is not the case create a new PullMessages subscription.
513
- if (onvifEventServiceType == 1 && pullMessageRequests .intValue () == 0
514
- && System .currentTimeMillis () - lastPullMessageReceivedTimestamp > 1000 ) {
515
- logger .debug ("The alarm stream was not running for camera {}, re-starting it now" , ipAddress );
516
- createSubscription ();
517
- } else if (!subscriptionXAddr .isEmpty ()) {
518
- // Renew the active subscription.
519
- sendOnvifRequest (RequestType .Renew , subscriptionXAddr );
520
- } else {
514
+ if (getEventsSupported () && onvifEventServiceType == 2 ) {
515
+ if (subscriptionXAddr .isEmpty ()) {
521
516
// The camera claims to have event support, but no subscription was created yet. Try to create a new
522
517
// subscription.
523
518
createSubscription ();
519
+ } else if (pullMessageRequests .intValue () == 0 ) {
520
+ // If we get events via PullMessages, check if a PullMessages request is running. Netty's
521
+ // IdleStateHandler
522
+ // will know if any request fails after a set time expires.
523
+ sendOnvifRequest (RequestType .Renew , subscriptionXAddr );
524
+ logger .debug ("The alarm stream was not running for camera {}, re-starting it now" , ipAddress );
525
+ sendOnvifRequest (RequestType .PullMessages , subscriptionXAddr );
526
+ } else {
527
+ sendOnvifRequest (RequestType .Renew , subscriptionXAddr );
524
528
}
525
529
}
526
530
}
@@ -828,16 +832,8 @@ public void eventReceived(String eventMessage) {
828
832
Element topicElement = (Element ) notificationMessageElement .getElementsByTagName ("wsnt:Topic" ).item (0 );
829
833
String topic = topicElement .getFirstChild ().getNodeValue ().replace ("tns1:" , "" );
830
834
831
- String sourceName = "" ;
832
- String sourceValue = "" ;
833
835
Element sourceElement = (Element ) notificationMessageElement .getElementsByTagName ("tt:Source" ).item (0 );
834
836
835
- if (sourceElement != null ) {
836
- Element sourceItemElement = (Element ) sourceElement .getElementsByTagName ("tt:SimpleItem" ).item (0 );
837
- sourceName = sourceItemElement .getAttributes ().getNamedItem ("Name" ).getNodeValue ();
838
- sourceValue = sourceItemElement .getAttributes ().getNamedItem ("Value" ).getNodeValue ();
839
- }
840
-
841
837
Element dataElement = (Element ) notificationMessageElement .getElementsByTagName ("tt:Data" ).item (0 );
842
838
843
839
if (dataElement == null ) {
@@ -850,8 +846,7 @@ public void eventReceived(String eventMessage) {
850
846
String dataName = dataItemElement .getAttributes ().getNamedItem ("Name" ).getNodeValue ();
851
847
String dataValue = dataItemElement .getAttributes ().getNamedItem ("Value" ).getNodeValue ();
852
848
853
- logger .debug ("ONVIF Event Topic: {}, Source name: {}, Source value: {}, Data name: {}, Data value: {}" ,
854
- topic , sourceName , sourceValue , dataName , dataValue );
849
+ logger .debug ("ONVIF Event Topic: {}, Data name: {}, Data value: {}" , topic , dataName , dataValue );
855
850
switch (topic ) {
856
851
case "RuleEngine/CellMotionDetector/Motion" :
857
852
if ("true" .equals (dataValue )) {
@@ -1165,7 +1160,7 @@ public boolean isConnected() {
1165
1160
}
1166
1161
1167
1162
public boolean getEventsSupported () {
1168
- return onvifEventServiceType > 0 ;
1163
+ return onvifEventServiceType > 1 ; // 0 = auto detect, 1 = disabled, 2 = PullMessages, 3 = WSBaseSubscription
1169
1164
}
1170
1165
1171
1166
public void setIsConnected (boolean isConnected ) {
0 commit comments