]> git.basschouten.com Git - openhab-addons.git/commitdiff
[ipcamera] Fix for Instar and HLS. (#9766)
authorMatthew Skinner <matt@pcmus.com>
Wed, 13 Jan 2021 21:11:46 +0000 (08:11 +1100)
committerGitHub <noreply@github.com>
Wed, 13 Jan 2021 21:11:46 +0000 (22:11 +0100)
Signed-off-by: Matthew Skinner <matt@pcmus.com>
bundles/org.openhab.binding.ipcamera/src/main/java/org/openhab/binding/ipcamera/internal/Ffmpeg.java
bundles/org.openhab.binding.ipcamera/src/main/java/org/openhab/binding/ipcamera/internal/InstarHandler.java
bundles/org.openhab.binding.ipcamera/src/main/java/org/openhab/binding/ipcamera/internal/handler/IpCameraHandler.java

index c006d5b5cc210cca2908a57d0c346dca7734508c..bc5c960179e6daf6a2a1bb304c583e122034ce06 100644 (file)
@@ -51,7 +51,6 @@ public class Ffmpeg {
     private List<String> commandArrayList = new ArrayList<String>();
     private IpCameraFfmpegThread ipCameraFfmpegThread = new IpCameraFfmpegThread();
     private int keepAlive = 8;
-    private boolean running = false;
     private String password;
 
     public Ffmpeg(IpCameraHandler handle, FFmpegFormat format, String ffmpegLocation, String inputArguments,
@@ -85,10 +84,14 @@ public class Ffmpeg {
     }
 
     public void checkKeepAlive() {
-        if (keepAlive <= -1) {
-            return;
-        } else if (--keepAlive == 0) {
+        if (keepAlive == 1) {
             stopConverting();
+        } else if (keepAlive <= -1 && !getIsAlive()) {
+            logger.warn("HLS stream was not running, restarting it now.");
+            startConverting();
+        }
+        if (keepAlive > 0) {
+            keepAlive--;
         }
     }
 
@@ -172,7 +175,6 @@ public class Ffmpeg {
             ipCameraFfmpegThread = new IpCameraFfmpegThread();
             logger.debug("Starting ffmpeg with this command now:{}", ffmpegCommand.replaceAll(password, "********"));
             ipCameraFfmpegThread.start();
-            running = true;
             if (format.equals(FFmpegFormat.HLS)) {
                 ipCameraHandler.setChannelState(CHANNEL_START_STREAM, OnOffType.ON);
             }
@@ -183,7 +185,11 @@ public class Ffmpeg {
     }
 
     public boolean getIsAlive() {
-        return running;
+        Process localProcess = process;
+        if (localProcess != null) {
+            return localProcess.isAlive();
+        }
+        return false;
     }
 
     public void stopConverting() {
@@ -192,18 +198,10 @@ public class Ffmpeg {
             Process localProcess = process;
             if (localProcess != null) {
                 localProcess.destroyForcibly();
-                running = false;
             }
             if (format.equals(FFmpegFormat.HLS)) {
-                if (keepAlive == -1) {
-                    logger.warn("HLS stopped when Stream should be running non stop, restarting HLS now.");
-                    startConverting();
-                    return;
-                } else {
-                    ipCameraHandler.setChannelState(CHANNEL_START_STREAM, OnOffType.OFF);
-                }
+                ipCameraHandler.setChannelState(CHANNEL_START_STREAM, OnOffType.OFF);
             }
-            keepAlive = 8;
         }
     }
 }
index f8562dd1ecb9b1e490962241087607c12471a778..9cf6c0d9d20645f7e75fd11fbeca5000a578d771 100644 (file)
@@ -123,18 +123,6 @@ public class InstarHandler extends ChannelDuplexHandler {
     // This handles the commands that come from the Openhab event bus.
     public void handleCommand(ChannelUID channelUID, Command command) {
         if (command instanceof RefreshType) {
-            switch (channelUID.getId()) {
-                case CHANNEL_MOTION_ALARM:
-                    if (ipCameraHandler.cameraConfig.getServerPort() > 0) {
-                        ipCameraHandler.logger.info("Setting up the Alarm Server settings in the camera now");
-                        ipCameraHandler.sendHttpGET(
-                                "/param.cgi?cmd=setmdalarm&-aname=server2&-switch=on&-interval=1&cmd=setalarmserverattr&-as_index=3&-as_server="
-                                        + ipCameraHandler.hostIp + "&-as_port="
-                                        + ipCameraHandler.cameraConfig.getServerPort()
-                                        + "&-as_path=/instar&-as_queryattr1=&-as_queryval1=&-as_queryattr2=&-as_queryval2=&-as_queryattr3=&-as_queryval3=&-as_activequery=1&-as_auth=0&-as_query1=0&-as_query2=0&-as_query3=0");
-                        return;
-                    }
-            }
             return;
         } // end of "REFRESH"
         switch (channelUID.getId()) {
index f0ab97e55332555748fba95779962324b9eec8e9..ea43387e15c43c1a551f2d0a01e1d53308d00b61 100644 (file)
@@ -692,6 +692,13 @@ public class IpCameraHandler extends BaseThingHandler {
             } catch (Exception e) {
                 cameraConfigError("Exception when starting server. Try changing the Server Port to another number.");
             }
+            if (thing.getThingTypeUID().getId().equals(INSTAR_THING)) {
+                logger.debug("Setting up the Alarm Server settings in the camera now");
+                sendHttpGET(
+                        "/param.cgi?cmd=setmdalarm&-aname=server2&-switch=on&-interval=1&cmd=setalarmserverattr&-as_index=3&-as_server="
+                                + hostIp + "&-as_port=" + cameraConfig.getServerPort()
+                                + "&-as_path=/instar&-as_queryattr1=&-as_queryval1=&-as_queryattr2=&-as_queryval2=&-as_queryattr3=&-as_queryval3=&-as_activequery=1&-as_auth=0&-as_query1=0&-as_query2=0&-as_query3=0");
+            }
         }
     }