Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[ipcamera] Fixes for Instar and HLS. #9766

Merged
merged 2 commits into from
Jan 13, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -85,10 +84,14 @@ public void setKeepAlive(int numberOfEightSeconds) {
}

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--;
}
}

Expand Down Expand Up @@ -172,7 +175,6 @@ public void startConverting() {
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);
}
Expand All @@ -183,7 +185,11 @@ public void startConverting() {
}

public boolean getIsAlive() {
return running;
Process localProcess = process;
if (localProcess != null) {
return localProcess.isAlive();
}
return false;
}

public void stopConverting() {
Expand All @@ -192,18 +198,10 @@ 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;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -123,18 +123,6 @@ public void channelRead(@Nullable ChannelHandlerContext ctx, @Nullable Object ms
// 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()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -692,6 +692,13 @@ protected void initChannel(SocketChannel socketChannel) throws Exception {
} 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");
}
}
}

Expand Down