Skip to content

Commit

Permalink
[ipcamera] Add a check to see if FFmpeg is frozen for mjpeg creation (#…
Browse files Browse the repository at this point in the history
…13896)

* check if ffmpegMjpeg is frozen

Signed-off-by: Matthew Skinner <matt@pcmus.com>
  • Loading branch information
Skinah authored Dec 10, 2022
1 parent 00d99e1 commit 2a7b6bf
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ public void run() {
BufferedReader bufferedReader = new BufferedReader(errorStreamReader);
String line = null;
while ((line = bufferedReader.readLine()) != null) {
logger.debug("{}", line);
logger.trace("{}", line);
switch (format) {
case RTSP_ALARMS:
if (line.contains("lavfi.")) {
Expand Down Expand Up @@ -172,8 +172,9 @@ public void run() {
} else if (line.contains("silence_end")) {
ipCameraHandler.audioDetected();
}
case MJPEG:
case SNAPSHOT:
notFrozen = true;// RTSP_ALARMS and SNAPSHOT both set this to true as there is no break.
notFrozen = true;// RTSP_ALARMS, MJPEG and SNAPSHOT all set this to true, no break.
break;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,16 @@ public void channelRead(@Nullable ChannelHandlerContext ctx, @Nullable Object ms
&& content.contains("response=\"200\";")) {// new
ipCameraHandler.newInstarApi = true;
ipCameraHandler.logger.debug("Alarm server sucessfully setup for a 2k+ Instar camera");
if (ipCameraHandler.cameraConfig.getFfmpegInput().isEmpty()) {
ipCameraHandler.rtspUri = "rtsp://" + ipCameraHandler.cameraConfig.getIp()
+ "/livestream/12";
}
if (ipCameraHandler.cameraConfig.getMjpegUrl().isEmpty()) {
ipCameraHandler.mjpegUri = "/livestream/12?action=play&media=mjpeg";
}
if (ipCameraHandler.cameraConfig.getSnapshotUrl().isEmpty()) {
ipCameraHandler.snapshotUri = "/snap.cgi?chn=12";
}
} else if (requestUrl.startsWith("/param.cgi?cmd=setmdalarm&-aname=server2&-switch=on&-interval=1")
&& content.startsWith("[Succeed]set ok")) {
ipCameraHandler.newInstarApi = false;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -906,9 +906,9 @@ public void setupFfmpegFormat(FFmpegFormat format) {
case MJPEG:
if (ffmpegMjpeg == null) {
if (inputOptions.isEmpty()) {
inputOptions = "-hide_banner -loglevel warning";
inputOptions = "-hide_banner";
} else {
inputOptions += " -hide_banner -loglevel warning";
inputOptions += " -hide_banner";
}
ffmpegMjpeg = new Ffmpeg(this, format, cameraConfig.getFfmpegLocation(), inputOptions, rtspUri,
cameraConfig.getMjpegOptions(), "http://127.0.0.1:" + SERVLET_PORT + "/ipcamera/"
Expand Down Expand Up @@ -1575,6 +1575,12 @@ void pollCameraRunnable() {
setupFfmpegFormat(FFmpegFormat.RTSP_ALARMS);
}
}
// check if the thread has frozen due to camera doing a soft reboot
localFfmpeg = ffmpegMjpeg;
if (localFfmpeg != null && !localFfmpeg.getIsAlive()) {
logger.debug("MJPEG was not being produced by FFmpeg when it should have been, restarting FFmpeg.");
setupFfmpegFormat(FFmpegFormat.MJPEG);
}
if (openChannels.size() > 10) {
logger.debug("There are {} open Channels being tracked.", openChannels.size());
cleanChannels();
Expand Down

0 comments on commit 2a7b6bf

Please sign in to comment.