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] Add a check to see if FFmpeg is frozen for mjpeg creation #13896

Merged
merged 2 commits into from
Dec 10, 2022
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 @@ -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