From 459ee8d7cdd6dac91813c7e8d909668a75b9c639 Mon Sep 17 00:00:00 2001 From: Matthew Skinner Date: Mon, 19 Oct 2020 04:40:00 +1100 Subject: [PATCH] [ipcamera] Refactor labels and defaults for openHAB 3 (#8752) Signed-off-by: Matthew Skinner --- .../org.openhab.binding.ipcamera/README.md | 216 ++++-------------- .../ipcamera/internal/AmcrestHandler.java | 1 - .../binding/ipcamera/internal/Helper.java | 1 - .../ipcamera/internal/HikvisionHandler.java | 1 - .../internal/IpCameraBindingConstants.java | 9 +- .../internal/IpCameraDiscoveryService.java | 4 +- .../ipcamera/internal/MyNettyAuthHandler.java | 5 +- .../internal/StreamServerHandler.java | 15 +- .../handler/IpCameraGroupHandler.java | 3 +- .../internal/handler/IpCameraHandler.java | 41 ++-- .../main/resources/OH-INF/binding/binding.xml | 2 +- .../resources/OH-INF/thing/thing-types.xml | 176 +++++++------- 12 files changed, 165 insertions(+), 309 deletions(-) diff --git a/bundles/org.openhab.binding.ipcamera/README.md b/bundles/org.openhab.binding.ipcamera/README.md index a2571b381..ff25ddce0 100644 --- a/bundles/org.openhab.binding.ipcamera/README.md +++ b/bundles/org.openhab.binding.ipcamera/README.md @@ -34,9 +34,22 @@ Some cameras allow the key frame to be created every second or a different amoun ### ESP32 Cameras These cameras do not have the ability to create H.264 streams and hence can not be used with HLS, however all other features should work. -See the [Full Example](#full-example) section for how to setup these cameras. Due to many custom firmwares available, you may need to ask the firmware developer what the URLs are for snapshots and MJPEG streams if they have changed the defaults from what the Arduino IDE sample code uses. +Example: + +``` +Thing ipcamera:generic:Esp32Cam +[ + ipAddress="192.168.1.181", serverPort=54322, + gifPreroll=1, + snapshotUrl="http://192.168.1.181/capture", + mjpegUrl="http://192.168.1.181:81/stream", + ffmpegInputOptions="-f mjpeg", + ffmpegOutput="/tmp/Esp32Camera/", ffmpegInput="http://192.168.1.181:81/stream" +] +``` + ### Amcrest It is better to always setup your Amcrest camera as a `dahua` thing type. @@ -115,9 +128,11 @@ Thing ipcamera:hikvision:West "West Camera" ## Discovery The discovery feature of openHAB can be used to find and setup any ONVIF cameras. -This method should be preferred as it will discover the camera, ports and URLs for you, making the setup much easier. +This method should be preferred as it will discover the cameras IP, ports and URLs for you, making the setup much easier. +The binding needs to use UDP port 3702 to discover the cameras with, so this port needs to be unblocked by your firewall or add the camera manually if the camera is not auto found. To use the discovery, just press the `+` icon located in the Inbox, then select the IpCamera binding from the list of installed bindings. -If your camera is not found after a few searches, it may not be ONVIF and in this case you will need to manually add via the UI your camera as a `generic` thing type and provide the URLs manually. +If your camera is not found after a few searches, it may not be ONVIF and in this case you will need to manually add the camera via the UI. +Cameras that are not ONVIF should be added as a `generic` thing type and you will need to provide the URLs manually. ## Supported Things @@ -662,197 +677,48 @@ end This section is about how to get things working in HABpanel. -I highly recommend you check out the easy to use WIDGETS of which there are now 3 that are discussed on the forum here. +I highly recommend you check out the easy to use widgets of which there are now 3 that are discussed on the forum here. The widgets in the link above are the easiest way to get an advanced stream working in openHAB and you are welcome to open them up, look at how they work and change them to something even better that suits your needs. ## Group Displays -The [Full Example](#full-example) section shows how to setup a group of cameras to be displayed like they are a single camera. +The `group` thing allows up to 4 cameras to be displayed like they are a single camera that rotates from one to the next. +The display order can be allowed to change if one or more of the cameras detects motion. -Some additional things to check to get it working are: +Some additional checks to get it working are: + If using the groups HLS feature, the poll time of the group must be the same or less than the total time contained in each cameras m3u8 file. If you have 3 seconds worth of video segments in each cameras HLS stream, this is the max you can set the poll time of the group to. + All cameras in a group should have the same HLS segment size setting, 1 and 2 second long segments have been tested to work. ++ Mixing cameras with different aspect ratios may cause issues when cast. -This is still a very new feature and if you have any issues, please send some TRACE level log output of when the problem occurs. +## Sitemap Example -## Full Example - -Use the following examples to base your setup on to save some time if you wish to use textual config. -Textual config should only be used by advanced users as the [Discovery](#discovery) method should be preferred by new users. - -You can do a find and replace on the thing type from `dahua`, as all cameras use consistent naming of channels and configs so changing between them is easy. - -In the examples you will see the format is: `bindingID:thingType:UID` [param1="string",param2=x,param3=x] - -bindingID: is always ipcamera. -thingType: is found listed above under [Supported Things](#supported-things). -UID: Can be made up but it must be UNIQUE, hence why it is called uniqueID. - -openHAB's discovery method will use the IP address with the dots removed as the UID. -By using textual config, you can name it something useful like "DrivewayCamera" if you wish, or stick with the same convention. - -*.things - -```java - -Thing ipcamera:group:OutsideCameras -[ - pollTime=2000, serverPort=54320, - ffmpegOutput="/tmpfs/OutsideGroup/", - firstCamera="001", - secondCamera="002", - thirdCamera="TestCam", - forthCamera="", - motionChangesOrder=true -] - -Thing ipcamera:dahua:001 -[ - ipAddress="192.168.0.5", password="suitcase123456", - username="admin", - serverPort=54321, - ffmpegOutput="/tmpfs/camera1/" -] - -Thing ipcamera:hikvision:002 -[ - ipAddress="192.168.0.6", password="suitcase123456", - username="admin", - serverPort=54322, - ffmpegOutput="/tmpfs/camera2/" -] - -Thing ipcamera:generic:TestCam -[ - ipAddress="192.168.0.7", password="pass123", username="admin", serverPort=54323, - snapshotUrl="http://192.168.1.65/tmpfs/snap.jpg", //remove this line if your camera has none - mjpegUrl="ffmpeg", - ffmpegOutput="/tmpfs/HttpTest/", - ffmpegInput="rtsp://192.168.1.65:554/11" -] - -Thing ipcamera:generic:TTGoCamera "ESP32 TTGo Camera" @ "Cameras" -[ - ipAddress="192.168.1.181", - serverPort=51321, - port=80, - gifPreroll=1, - snapshotUrl="http://192.168.1.181/capture", - mjpegUrl="http://192.168.1.181:81/stream", - ffmpegOutput="/tmpfs/TTGoCamera/", - ffmpegInput="http://192.168.1.181:81/stream", - ffmpegInputOptions="-f mjpeg", - ipWhitelist="(192.168.2.8)(192.168.2.83)(192.168.2.99)" -] - -``` - -*.items - -```java - -Number BabyCamDirection "Camera Direction" -Switch BabyCamEnableMotion "MotionAlarm on/off" { channel="ipcamera:dahua:001:enableMotionAlarm" } -Switch BabyCamMotionAlarm "Motion detected" { channel="ipcamera:dahua:001:motionAlarm" } -Switch BabyCamEnableAudioAlarm "AudioAlarm on/off" { channel="ipcamera:dahua:001:enableAudioAlarm" } -Switch BabyCamAudioAlarm "Audio detected" { channel="ipcamera:dahua:001:audioAlarm" } -Dimmer BabyCamAudioThreshold "Audio Threshold [%d]" { channel="ipcamera:dahua:001:thresholdAudioAlarm" } -Dimmer BabyCamLED "IR LED [%d]" { channel="ipcamera:dahua:001:enableLED" } -Switch BabyCamAutoLED "Auto IR LED" { channel="ipcamera:dahua:001:autoLED" } -String BabyCamTextOverlay "Text to overlay" { channel="ipcamera:dahua:001:textOverlay" } -String BabyCamHlsUrl "HLS Stream" { channel="ipcamera:dahua:BabyCamera:hlsUrl" } -DateTime BabyCamLastMotionTime "Time motion was last detected [%1$ta %1$tR]" -String BabyCamLastMotionType "Last Motion Type" { channel="ipcamera:dahua:BabyCamera:lastMotionType" } -Switch BabyCamStartHLS { channel="ipcamera:dahua:BabyCamera:startStream" } - -Dimmer GenericMotionControl "Motion Threshold [%d]" { channel="ipcamera:generic:TestCam:ffmpegMotionControl" } -Switch GenericMotionAlarm "Motion detected" { channel="ipcamera:generic:TestCam:motionAlarm" } -Dimmer GenericAudioThreshold "Audio Threshold [%d]" { channel="ipcamera:generic:TestCam:thresholdAudioAlarm" } -Switch GenericAudioAlarm "Audio detected" { channel="ipcamera:generic:TestCam:audioAlarm" } - -String OutsideCameraGroupHlsUrl "Outside Cameras" { channel="ipcamera:group:OutsideCameras:hlsUrl", ga="Camera" [ protocols="hls" ] } -Switch OutsideCameraGroupStartHLS "Start outside HLS" { channel="ipcamera:group:OutsideCameras:startStream" } - -``` +Use the following example to base your sitemap on to save some time. +If you use the `Create Equipment from Thing` feature to auto create your items, the following will need minimal editing to change the camera name from `BabyCam` to what you choose to name the camera. *.sitemap ```java -Text label="Outside Camera Group" icon="camera"{Image url="http://192.168.0.2:54320/ipcamera.jpg" refresh=1000} Text label="BabyMonitor" icon="camera"{ - Default item=BabyCamMotionAlarm icon=siren - Default item=BabyCamAudioAlarm icon=siren - Text label="Advanced Controls" icon="settings"{ - Switch item=BabyCamEnableMotion - Default item=BabyCamEnableAudioAlarm - Default item=BabyCamAudioThreshold icon=recorder - Slider item=BabyCamLED - Default item=BabyCamAutoLED - } - Text label="Last Movement" icon="motion"{ - Webview url="http://192.168.0.2:54321/ipcamera.gif" height=9 - Default item=BabyCamMotionAlarm icon=siren - Default item=BabyCamLastMotionTime - Default item=BabyCamLastMotionType - } - Text label="Cameras MJPEG Stream" icon="camera"{Video url="http://192.168.0.2:54321/ipcamera.mjpeg" encoding="mjpeg"} - Text label="Snapshot 1FPS Stream" icon="camera"{Video url="http://192.168.0.2:54321/snapshots.mjpeg" encoding="mjpeg"} - Text label="autofps Stream" icon="camera"{Video url="http://192.168.0.2:54321/autofps.mjpeg" encoding="mjpeg"} - Text label="HLS Video Stream" icon="camera"{Video url="http://192.168.0.2:54321/ipcamera.m3u8" encoding="hls"} - Text label="HLS Webview Stream" icon="camera"{Webview url="http://192.168.0.2:54321/ipcamera.m3u8" height=15} - Text label="Image using JPG method" icon="camera"{Image url="http://192.168.0.2:54321/ipcamera.jpg" refresh=2000} - } - - Text label="Generic Camera" icon="camera"{ - Switch item=GenericMotionControl - Slider item=GenericMotionControl - Default item=GenericMotionAlarm - Switch item=GenericAudioThreshold - Slider item=GenericAudioThreshold - Default item=GenericAudioAlarm - Text label="MJPEG Stream" icon="camera"{Video url="http://192.168.0.2:54323/ipcamera.mjpeg" encoding="mjpeg"} - Text label="snapshots 1FPS Stream" icon="camera"{Video url="http://192.168.0.2:54323/snapshots.mjpeg" encoding="mjpeg"} - Text label="autofps Stream" icon="camera"{Video url="http://192.168.0.2:54323/autofps.mjpeg" encoding="mjpeg"} - Text label="HLS Video Stream" icon="camera"{Video url="http://192.168.0.2:54323/ipcamera.m3u8" encoding="hls"} - Text label="HLS Stream" icon="camera"{Webview url="http://192.168.0.2:54323/ipcamera.m3u8" height=15} - Text label="Image JPG method" icon="camera"{Image url="http://192.168.0.2:54323/ipcamera.jpg" refresh=1000} + Switch item=BabyCam_GoToPreset icon=movecontrol label="Camera Direction" mappings=[1="Room", 2="Chair", 3="Cot"] + Text label="Advanced Controls" icon="settings"{ + Default item=BabyCam_AutoLED + Default item=BabyCam_AudioAlarmThreshold icon=recorder + Switch item=BabyCam_AudioAlarm + Default item=BabyCam_EnableMotionAlarm + Default item=BabyCam_MotionAlarm + Slider item=BabyCam_Pan icon=movecontrol + Slider item=BabyCam_Tilt icon=movecontrol + Slider item=BabyCam_Zoom icon=zoom } - -``` - -*.rules - -```java -rule "Camera detected crying" -when - Item BabyCamAudioAlarm changed from OFF to ON -then -if(BabyMonitor.state==ON){ - - if(MumAlerts.state==ON){ - sendNotification("mum@parentCo.com", "Mum, the baby is awake.") - } - - if(DadAlerts.state==ON){ - sendNotification("dad@parentCo.com", "Dad, the baby is awake.") - } - - if(TvAlerts.state==ON){ - myKodi_notification.sendCommand("Baby is crying.") - } -} -end - -rule "Create time of last movement" - when - Item BabyCamLastMotionType received update - then - BabyCamLastMotionTime.postUpdate( new DateTimeType() ) -end + Default item=BabyCam_StartHLSStream + Text label="Mjpeg Stream" icon="camera"{Video url="http://192.168.0.2:54321/ipcamera.mjpeg" encoding="mjpeg"} + Text label="HLS Stream" icon="camera"{Webview url="http://192.168.0.2:54321/ipcamera.m3u8" height=15} + Video url="http://192.168.0.2:54321/autofps.mjpeg" encoding="mjpeg" + } ``` diff --git a/bundles/org.openhab.binding.ipcamera/src/main/java/org/openhab/binding/ipcamera/internal/AmcrestHandler.java b/bundles/org.openhab.binding.ipcamera/src/main/java/org/openhab/binding/ipcamera/internal/AmcrestHandler.java index a0350dfcd..687453ec5 100644 --- a/bundles/org.openhab.binding.ipcamera/src/main/java/org/openhab/binding/ipcamera/internal/AmcrestHandler.java +++ b/bundles/org.openhab.binding.ipcamera/src/main/java/org/openhab/binding/ipcamera/internal/AmcrestHandler.java @@ -96,7 +96,6 @@ public class AmcrestHandler extends ChannelDuplexHandler { String value = ipCameraHandler.returnValueFromString(content, "table.AudioDetect[0].MutationThreold="); ipCameraHandler.setChannelState(CHANNEL_THRESHOLD_AUDIO_ALARM, PercentType.valueOf(value)); } - } finally { ReferenceCountUtil.release(msg); ctx.close(); diff --git a/bundles/org.openhab.binding.ipcamera/src/main/java/org/openhab/binding/ipcamera/internal/Helper.java b/bundles/org.openhab.binding.ipcamera/src/main/java/org/openhab/binding/ipcamera/internal/Helper.java index 027ad398a..abbd07bc1 100644 --- a/bundles/org.openhab.binding.ipcamera/src/main/java/org/openhab/binding/ipcamera/internal/Helper.java +++ b/bundles/org.openhab.binding.ipcamera/src/main/java/org/openhab/binding/ipcamera/internal/Helper.java @@ -110,7 +110,6 @@ public class Helper { try { processed = URLEncoder.encode(text, "UTF-8").replace("+", "%20"); } catch (UnsupportedEncodingException e) { - } return processed; } diff --git a/bundles/org.openhab.binding.ipcamera/src/main/java/org/openhab/binding/ipcamera/internal/HikvisionHandler.java b/bundles/org.openhab.binding.ipcamera/src/main/java/org/openhab/binding/ipcamera/internal/HikvisionHandler.java index 2e1a51a19..8521f97e4 100644 --- a/bundles/org.openhab.binding.ipcamera/src/main/java/org/openhab/binding/ipcamera/internal/HikvisionHandler.java +++ b/bundles/org.openhab.binding.ipcamera/src/main/java/org/openhab/binding/ipcamera/internal/HikvisionHandler.java @@ -230,7 +230,6 @@ public class HikvisionHandler extends ChannelDuplexHandler { // This does debouncing of the alarms void countDown() { - if (lineCount > 1) { lineCount--; } else if (lineCount == 1) { diff --git a/bundles/org.openhab.binding.ipcamera/src/main/java/org/openhab/binding/ipcamera/internal/IpCameraBindingConstants.java b/bundles/org.openhab.binding.ipcamera/src/main/java/org/openhab/binding/ipcamera/internal/IpCameraBindingConstants.java index 802b47f6c..676c8c1b0 100644 --- a/bundles/org.openhab.binding.ipcamera/src/main/java/org/openhab/binding/ipcamera/internal/IpCameraBindingConstants.java +++ b/bundles/org.openhab.binding.ipcamera/src/main/java/org/openhab/binding/ipcamera/internal/IpCameraBindingConstants.java @@ -28,12 +28,11 @@ import org.openhab.core.thing.ThingTypeUID; */ @NonNullByDefault public class IpCameraBindingConstants { - private static final String BINDING_ID = "ipcamera"; - public final static String AUTH_HANDLER = "authorizationHandler"; - public final static String AMCREST_HANDLER = "amcrestHandler"; - public final static String COMMON_HANDLER = "commonHandler"; - public final static String INSTAR_HANDLER = "instarHandler"; + public static final String AUTH_HANDLER = "authorizationHandler"; + public static final String AMCREST_HANDLER = "amcrestHandler"; + public static final String COMMON_HANDLER = "commonHandler"; + public static final String INSTAR_HANDLER = "instarHandler"; public static enum FFmpegFormat { HLS, diff --git a/bundles/org.openhab.binding.ipcamera/src/main/java/org/openhab/binding/ipcamera/internal/IpCameraDiscoveryService.java b/bundles/org.openhab.binding.ipcamera/src/main/java/org/openhab/binding/ipcamera/internal/IpCameraDiscoveryService.java index 0578ff7ae..24cce552f 100644 --- a/bundles/org.openhab.binding.ipcamera/src/main/java/org/openhab/binding/ipcamera/internal/IpCameraDiscoveryService.java +++ b/bundles/org.openhab.binding.ipcamera/src/main/java/org/openhab/binding/ipcamera/internal/IpCameraDiscoveryService.java @@ -42,7 +42,7 @@ public class IpCameraDiscoveryService extends AbstractDiscoveryService { private final Logger logger = LoggerFactory.getLogger(IpCameraDiscoveryService.class); public IpCameraDiscoveryService() { - super(SUPPORTED_THING_TYPES, 30, false); + super(SUPPORTED_THING_TYPES, 0, false); } @Override @@ -69,10 +69,10 @@ public class IpCameraDiscoveryService extends AbstractDiscoveryService { OnvifDiscovery onvifDiscovery = new OnvifDiscovery(this); try { onvifDiscovery.discoverCameras(3702);// WS discovery - onvifDiscovery.discoverCameras(1900);// SSDP } catch (UnknownHostException | InterruptedException e) { logger.warn( "IpCamera Discovery has an issue discovering the network settings to find cameras with. Try setting up the camera manually."); } + stopScan(); } } diff --git a/bundles/org.openhab.binding.ipcamera/src/main/java/org/openhab/binding/ipcamera/internal/MyNettyAuthHandler.java b/bundles/org.openhab.binding.ipcamera/src/main/java/org/openhab/binding/ipcamera/internal/MyNettyAuthHandler.java index 0eefa1c54..90732b256 100644 --- a/bundles/org.openhab.binding.ipcamera/src/main/java/org/openhab/binding/ipcamera/internal/MyNettyAuthHandler.java +++ b/bundles/org.openhab.binding.ipcamera/src/main/java/org/openhab/binding/ipcamera/internal/MyNettyAuthHandler.java @@ -76,7 +76,7 @@ public class MyNettyAuthHandler extends ChannelDuplexHandler { // nonce is reused if authenticate is null so the NC needs to increment to allow this// public void processAuth(String authenticate, String httpMethod, String requestURI, boolean reSend) { if (authenticate.contains("Basic realm=\"")) { - if (ipCameraHandler.useDigestAuth == true) { + if (ipCameraHandler.useDigestAuth) { // Possible downgrade authenticate attack avoided. return; } @@ -106,8 +106,7 @@ public class MyNettyAuthHandler extends ChannelDuplexHandler { } String stale = Helper.searchString(authenticate, "stale=\""); - if (stale.isEmpty()) { - } else if (stale.equalsIgnoreCase("true")) { + if (stale.equalsIgnoreCase("true")) { logger.debug("Camera reported stale=true which normally means the NONCE has expired."); } diff --git a/bundles/org.openhab.binding.ipcamera/src/main/java/org/openhab/binding/ipcamera/internal/StreamServerHandler.java b/bundles/org.openhab.binding.ipcamera/src/main/java/org/openhab/binding/ipcamera/internal/StreamServerHandler.java index f578b76a2..194827f8e 100644 --- a/bundles/org.openhab.binding.ipcamera/src/main/java/org/openhab/binding/ipcamera/internal/StreamServerHandler.java +++ b/bundles/org.openhab.binding.ipcamera/src/main/java/org/openhab/binding/ipcamera/internal/StreamServerHandler.java @@ -177,19 +177,14 @@ public class StreamServerHandler extends ChannelInboundHandlerAdapter { } if (msg instanceof HttpContent) { HttpContent content = (HttpContent) msg; - int index = 0; if (recievedBytes == 0) { - incomingJpeg = new byte[content.content().capacity()]; + incomingJpeg = new byte[content.content().readableBytes()]; + content.content().getBytes(0, incomingJpeg, 0, content.content().readableBytes()); } else { byte[] temp = incomingJpeg; - incomingJpeg = new byte[recievedBytes + content.content().capacity()]; - - for (; index < temp.length; index++) { - incomingJpeg[index] = temp[index]; - } - } - for (int i = 0; i < content.content().capacity(); i++) { - incomingJpeg[index++] = content.content().getByte(i); + incomingJpeg = new byte[recievedBytes + content.content().readableBytes()]; + System.arraycopy(temp, 0, incomingJpeg, 0, temp.length); + content.content().getBytes(0, incomingJpeg, temp.length, content.content().readableBytes()); } recievedBytes = incomingJpeg.length; if (content instanceof LastHttpContent) { diff --git a/bundles/org.openhab.binding.ipcamera/src/main/java/org/openhab/binding/ipcamera/internal/handler/IpCameraGroupHandler.java b/bundles/org.openhab.binding.ipcamera/src/main/java/org/openhab/binding/ipcamera/internal/handler/IpCameraGroupHandler.java index c073df0e8..3420c65f3 100644 --- a/bundles/org.openhab.binding.ipcamera/src/main/java/org/openhab/binding/ipcamera/internal/handler/IpCameraGroupHandler.java +++ b/bundles/org.openhab.binding.ipcamera/src/main/java/org/openhab/binding/ipcamera/internal/handler/IpCameraGroupHandler.java @@ -326,11 +326,10 @@ public class IpCameraGroupHandler extends BaseThingHandler { for (IpCameraHandler handler : cameraOrder) { String channelPrefix = "ipcamera:" + handler.getThing().getThingTypeUID() + ":" + handler.getThing().getUID().getId() + ":"; - handler.handleCommand(new ChannelUID(channelPrefix + CHANNEL_START_STREAM), OnOffType.ON); } } else { - // TODO: Do we turn all controls OFF or do we remember the state before we turned them all on? + // Do we turn all controls OFF, or do we remember the state before we turned them all on? hlsTurnedOn = false; } } diff --git a/bundles/org.openhab.binding.ipcamera/src/main/java/org/openhab/binding/ipcamera/internal/handler/IpCameraHandler.java b/bundles/org.openhab.binding.ipcamera/src/main/java/org/openhab/binding/ipcamera/internal/handler/IpCameraHandler.java index c9ace9d58..2e16e0419 100644 --- a/bundles/org.openhab.binding.ipcamera/src/main/java/org/openhab/binding/ipcamera/internal/handler/IpCameraHandler.java +++ b/bundles/org.openhab.binding.ipcamera/src/main/java/org/openhab/binding/ipcamera/internal/handler/IpCameraHandler.java @@ -161,7 +161,6 @@ public class IpCameraHandler extends BaseThingHandler { private String mp4Filename = "ipcamera"; private int mp4RecordTime; private int gifRecordTime = 5; - private int mp4Preroll; private LinkedList fifoSnapshotBuffer = new LinkedList(); private int snapCount; private boolean updateImageChannel = false; @@ -409,7 +408,7 @@ public class IpCameraHandler extends BaseThingHandler { // false clears the stored user/pass hash, true creates the hash public boolean setBasicAuth(boolean useBasic) { - if (useBasic == false) { + if (!useBasic) { logger.debug("Clearing out the stored BASIC auth now."); basicAuth = ""; return false; @@ -495,7 +494,6 @@ public class IpCameraHandler extends BaseThingHandler { // The authHandler will generate a digest string and re-send using this same function when needed. @SuppressWarnings("null") public void sendHttpRequest(String httpMethod, String httpRequestURLFull, @Nullable String digestString) { - int port = getPortFromShortenedUrl(httpRequestURLFull); String httpRequestURL = getTinyUrl(httpRequestURLFull); @@ -818,8 +816,8 @@ public class IpCameraHandler extends BaseThingHandler { // sends direct to ctx so can be either snapshots.mjpeg or normal mjpeg stream public void sendMjpegFirstPacket(ChannelHandlerContext ctx) { - final String BOUNDARY = "thisMjpegStream"; - String contentType = "multipart/x-mixed-replace; boundary=" + BOUNDARY; + final String boundary = "thisMjpegStream"; + String contentType = "multipart/x-mixed-replace; boundary=" + boundary; HttpResponse response = new DefaultHttpResponse(HttpVersion.HTTP_1_1, HttpResponseStatus.OK); response.headers().add(HttpHeaderNames.CONTENT_TYPE, contentType); response.headers().set(HttpHeaderNames.CACHE_CONTROL, HttpHeaderValues.NO_CACHE); @@ -830,10 +828,10 @@ public class IpCameraHandler extends BaseThingHandler { } public void sendMjpegFrame(byte[] jpg, ChannelGroup channelGroup) { - final String BOUNDARY = "thisMjpegStream"; + final String boundary = "thisMjpegStream"; ByteBuf imageByteBuf = Unpooled.copiedBuffer(jpg); int length = imageByteBuf.readableBytes(); - String header = "--" + BOUNDARY + "\r\n" + "content-type: image/jpeg" + "\r\n" + "content-length: " + length + String header = "--" + boundary + "\r\n" + "content-type: image/jpeg" + "\r\n" + "content-length: " + length + "\r\n\r\n"; ByteBuf headerBbuf = Unpooled.copiedBuffer(header, 0, header.length(), StandardCharsets.UTF_8); ByteBuf footerBbuf = Unpooled.copiedBuffer("\r\n", 0, 2, StandardCharsets.UTF_8); @@ -959,22 +957,17 @@ public class IpCameraHandler extends BaseThingHandler { ffmpegRecord = new Ffmpeg(this, format, cameraConfig.getFfmpegLocation(), inputOptions, rtspUri, cameraConfig.getMp4OutOptions(), cameraConfig.getFfmpegOutput() + mp4Filename + ".mp4", cameraConfig.getUser(), cameraConfig.getPassword()); - if (mp4Preroll > 0) { - // fetchFromHLS(); todo: not done yet - } - if (ffmpegRecord != null) { - ffmpegRecord.startConverting(); - if (mp4History.isEmpty()) { - mp4History = mp4Filename; - } else if (!mp4Filename.equals("ipcamera")) { - mp4History = mp4Filename + "," + mp4History; - if (mp4HistoryLength > 49) { - int endIndex = mp4History.lastIndexOf(","); - mp4History = mp4History.substring(0, endIndex); - } + ffmpegRecord.startConverting(); + if (mp4History.isEmpty()) { + mp4History = mp4Filename; + } else if (!mp4Filename.equals("ipcamera")) { + mp4History = mp4Filename + "," + mp4History; + if (mp4HistoryLength > 49) { + int endIndex = mp4History.lastIndexOf(","); + mp4History = mp4History.substring(0, endIndex); } - setChannelState(CHANNEL_MP4_HISTORY, new StringType(mp4History)); } + setChannelState(CHANNEL_MP4_HISTORY, new StringType(mp4History)); break; case RTSP_ALARMS: if (ffmpegRtspHelper != null) { @@ -984,7 +977,7 @@ public class IpCameraHandler extends BaseThingHandler { } } String input = (cameraConfig.getAlarmInputUrl().isEmpty()) ? rtspUri : cameraConfig.getAlarmInputUrl(); - String OutputOptions = "-f null -"; + String outputOptions = "-f null -"; String filterOptions = ""; if (!audioAlarmEnabled) { filterOptions = "-an"; @@ -993,7 +986,7 @@ public class IpCameraHandler extends BaseThingHandler { } if (!motionAlarmEnabled && !ffmpegSnapshotGeneration) { filterOptions = filterOptions.concat(" -vn"); - } else if (motionAlarmEnabled == true) { + } else if (motionAlarmEnabled) { filterOptions = filterOptions .concat(" -vf select='gte(scene," + motionThreshold + ")',metadata=print"); } @@ -1001,7 +994,7 @@ public class IpCameraHandler extends BaseThingHandler { filterOptions += " ";// add space as the Framework does not allow spaces at start of config. } ffmpegRtspHelper = new Ffmpeg(this, format, cameraConfig.getFfmpegLocation(), inputOptions, input, - filterOptions + cameraConfig.getMotionOptions(), OutputOptions, cameraConfig.getUser(), + filterOptions + cameraConfig.getMotionOptions(), outputOptions, cameraConfig.getUser(), cameraConfig.getPassword()); ffmpegRtspHelper.startConverting(); break; diff --git a/bundles/org.openhab.binding.ipcamera/src/main/resources/OH-INF/binding/binding.xml b/bundles/org.openhab.binding.ipcamera/src/main/resources/OH-INF/binding/binding.xml index c1d3b7420..b886e72d1 100644 --- a/bundles/org.openhab.binding.ipcamera/src/main/resources/OH-INF/binding/binding.xml +++ b/bundles/org.openhab.binding.ipcamera/src/main/resources/OH-INF/binding/binding.xml @@ -4,6 +4,6 @@ xsi:schemaLocation="https://openhab.org/schemas/binding/v1.0.0 https://openhab.org/schemas/binding-1.0.0.xsd"> IpCamera Binding - This binding helps you to use IP Cameras in Openhab 2. + This binding interfaces IP cameras of various vendors via open protocols. Matthew Skinner diff --git a/bundles/org.openhab.binding.ipcamera/src/main/resources/OH-INF/thing/thing-types.xml b/bundles/org.openhab.binding.ipcamera/src/main/resources/OH-INF/thing/thing-types.xml index 0c114b6c7..c88b0ad28 100644 --- a/bundles/org.openhab.binding.ipcamera/src/main/resources/OH-INF/thing/thing-types.xml +++ b/bundles/org.openhab.binding.ipcamera/src/main/resources/OH-INF/thing/thing-types.xml @@ -79,7 +79,7 @@ The full path where FFmpeg has the ability to write files to ending with a slash. For windows use this format, c:\openhabconf\html\ipcamera\ - /etc/openhab2/html/camera1/ + /etc/openhab/html/camera1/ @@ -151,6 +151,7 @@ per the readme. 0 + true @@ -220,7 +221,7 @@ The full path where FFmpeg has the ability to write files to ending with a slash. For windows use this format, c:\openhabconf\html\ipcamera\ - /etc/openhab2/html/camera1/ + /etc/openhab/html/camera1/ @@ -391,6 +392,7 @@ per the readme. 0 + true @@ -440,7 +442,7 @@ The full path where FFmpeg has the ability to write files to ending with a slash. For windows use this format, c:\openhabconf\html\ipcamera\ - /etc/openhab2/html/camera1/ + /etc/openhab/html/camera1/ @@ -683,7 +685,7 @@ The full path where FFmpeg has the ability to write files to ending with a slash. For windows use this format, c:\openhabconf\html\ipcamera\ - /etc/openhab2/html/camera1/ + /etc/openhab/html/camera1/ @@ -767,6 +769,7 @@ per the readme. 0 + true @@ -966,7 +969,7 @@ The full path where FFmpeg has the ability to write files to ending with a slash. For windows use this format, c:\openhabconf\html\ipcamera\ - /etc/openhab2/html/camera1/ + /etc/openhab/html/camera1/ @@ -1034,6 +1037,7 @@ per the readme. 0 + true @@ -1231,7 +1235,7 @@ The full path where FFmpeg has the ability to write files to ending with a slash. For windows use this format, c:\openhabconf\html\ipcamera\ - /etc/openhab2/html/camera1/ + /etc/openhab/html/camera1/ @@ -1315,6 +1319,7 @@ per the readme. 0 + true @@ -1493,7 +1498,7 @@ The full path where FFmpeg has the ability to write files to ending with a slash. For windows use this format, c:\openhabconf\html\ipcamera\ - /etc/openhab2/html/camera1/ + /etc/openhab/html/camera1/ @@ -1577,6 +1582,7 @@ per the readme. 0 + true @@ -1780,7 +1786,7 @@ The full path where FFmpeg has the ability to write files to ending with a slash. For windows use this format, c:\openhabconf\html\ipcamera\ - /etc/openhab2/html/camera1/ + /etc/openhab/html/camera1/ @@ -1864,6 +1870,7 @@ per the readme. 0 + true @@ -2054,7 +2061,7 @@ The full path where FFmpeg has the ability to write files to ending with a slash. For windows use this format, c:\openhabconf\html\ipcamera\ - /etc/openhab2/html/camera1/ + /etc/openhab/html/camera1/ @@ -2138,6 +2145,7 @@ per the readme. 0 + true @@ -2225,14 +2233,14 @@ - + Image Low frame rate image from your camera. Recommend this is NOT used unless you have large pollTime. Camera - + Switch This can be used to trigger snapshot updates when an external PIR, button or other form of sensor turns @@ -2241,7 +2249,7 @@ Number - + Indicates how long the recording will occur for and when the file is created, the channel will change to 0 by itself. @@ -2249,13 +2257,13 @@ - + String - + A history of the last GIFs created in a CSV formatted string. - + Number How many GIFs are stored in the history. @@ -2263,7 +2271,7 @@ Number - + Indicates how long the recording will occur for and when the file is created, the channel will change to 0 by itself. @@ -2271,15 +2279,15 @@ - + String - + A history of the last mp4 recordings created in a CSV formatted string. - + Number - + How many mp4 recordings are stored in the history. @@ -2291,7 +2299,7 @@ - + String A link that the camera uses for RTSP. @@ -2309,34 +2317,34 @@ String - + A link you can use in openHAB to cast video feeds. Camera - + Dimmer Pan the camera to a new position. MoveControl - + Dimmer Tilt the camera to a new position. MoveControl - + Dimmer Zoom the camera to a new value. Zoom - + String A string that contains the type of motion alarm that was last triggered. @@ -2351,36 +2359,36 @@ - + Switch - + Intrusion has detected movement. AKA Field Detection Alarm. Motion - + Switch - + By using this feature you can stop the camera from sending e-mails when you are actually home. - + Switch - + Enable/Disable the PIR Alarm. Motion Switch - + Cell based motion has been detected. Motion - + Switch PIR motion has been detected. @@ -2388,7 +2396,7 @@ - + Switch Camera may be stolen or damaged. @@ -2396,7 +2404,7 @@ - + Switch Image is too dark. @@ -2404,7 +2412,7 @@ - + Switch Camera may have been moved. @@ -2412,7 +2420,7 @@ - + Switch Image is too bright. @@ -2420,7 +2428,7 @@ - + Switch Image is out of focus. @@ -2428,7 +2436,7 @@ - + Switch An issue with the cameras storage has been reported. @@ -2436,7 +2444,7 @@ - + Switch FFmpeg has detected motion. @@ -2452,7 +2460,7 @@ - + Switch A face has been detected. @@ -2460,7 +2468,7 @@ - + Switch An item has been left. @@ -2468,15 +2476,15 @@ - + Switch - - A car has triggered the ParkingDetection. + + A car has triggered the Parking Detection. Alarm - + Switch An item may have been stolen. @@ -2484,7 +2492,7 @@ - + Switch Audio has triggered an Alarm. @@ -2492,29 +2500,29 @@ - + Switch - + Turn the External Alarm Input feature on and off. - + Switch Change the External Alarm Input to trigger on high or low states. - + Switch - + Some cameras have alarm input wires which can be used to connect to door bells or external PIR sensors. Alarm - + Switch - + Some cameras have alarm input wires which can be used to connect to door bells or external PIR sensors. Alarm @@ -2522,56 +2530,56 @@ Switch - + By using this feature you can stop the camera from sending e-mails when you are actually home. Motion - + Switch - - Use other sensors external to the camera like a ZWave PIR sensor to flag that the camera has motion in + + Use any external sensor like a ZWave PIR sensor to flag that the camera has motion in its field of view. Motion - + Dimmer - + Enable/Disable the motion alarm and control the sensitivity. Motion Switch - + By using this feature you can stop the camera from sending e-mails when you are actually home. Motion - + Switch - + By using this feature you can stop the camera from sending e-mails when you are having a party. SoundVolume - + Dimmer - + By moving this control you should be able to change how sensitive the audio alarm is to soft or loud noises. SoundVolume - + Switch You can use the cameras output to trigger a device like a burglar alarm. Alarm - + Switch You can use the cameras output 2 to trigger a device like a burglar alarm. @@ -2580,46 +2588,46 @@ Switch - + Lower the delay to start casting the camera by creating the files non stop in case they are needed. - + Dimmer - - Turn the LED on and off and if supported allow Dimming. + + Turn the LED ON and OFF and if supported also 0-100% dimming. Light - + Switch - - Turn automatic mode for the LED on and off. + + Turn the automatic mode for the LED ON and OFF. - + Switch - - Turn the lights on and off. + + Turn the relay for external lights ON and OFF. Light - + Switch - + The button has been pushed. - + String - Some custom text you wish to overlay over the cameras snapshot and video streams. + Enter some text you wish to overlay on top of the cameras snapshot and video streams. - + String - + Move a P.T.Z camera to this ONVIF preset location.