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,
}
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--;
}
}
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);
}
}
public boolean getIsAlive() {
- return running;
+ Process localProcess = process;
+ if (localProcess != null) {
+ return localProcess.isAlive();
+ }
+ return false;
}
public void stopConverting() {
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;
}
}
}
// 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()) {
} 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");
+ }
}
}