From 823c126deaa68a52051e1daae9d8e6b36d10374b Mon Sep 17 00:00:00 2001 From: MrDave Date: Sun, 20 Dec 2020 12:47:04 -0700 Subject: [PATCH] Add watchdog timeout as parameter --- src/conf.cpp | 25 ++++++++++++++++++++++++- src/conf.hpp | 1 + src/motion_loop.cpp | 7 +++++-- src/motionplus.cpp | 4 ---- src/motionplus.hpp | 1 - 5 files changed, 30 insertions(+), 8 deletions(-) diff --git a/src/conf.cpp b/src/conf.cpp index b4b2ae2c..d3d0e244 100644 --- a/src/conf.cpp +++ b/src/conf.cpp @@ -84,12 +84,15 @@ struct ctx_parm config_parms[] = { "camera_id", "# Numeric identifier for the camera.", 0, PARM_TYP_INT,PARM_CAT_01,WEBUI_LEVEL_ADVANCED}, - /* camera and camera_dir must be last in this list */ { "target_dir", "# Target directory for pictures, snapshots and movies", 0,PARM_TYP_STRING,PARM_CAT_01, WEBUI_LEVEL_LIMITED }, { + "watchdog_tmo", + "# Timeout in seconds for thread response.", + 0, PARM_TYP_INT,PARM_CAT_01,WEBUI_LEVEL_LIMITED}, + { "v4l2_device", "# Video device (e.g. /dev/video0) to be used for capturing.", 0,PARM_TYP_STRING,PARM_CAT_01,WEBUI_LEVEL_ADVANCED @@ -1058,6 +1061,25 @@ static void conf_edit_target_dir(struct ctx_cam *cam, std::string &parm, enum PA MOTION_LOG(DBG, TYPE_ALL, NO_ERRNO,"%s:%s","target_dir",_("target_dir")); } +static void conf_edit_watchdog_tmo(struct ctx_cam *cam, std::string &parm, enum PARM_ACT pact) +{ + int parm_in; + if (pact == PARM_ACT_DFLT){ + cam->conf->watchdog_tmo = 30; + } else if (pact == PARM_ACT_SET){ + parm_in = atoi(parm.c_str()); + if (parm_in < 1) { + MOTION_LOG(NTC, TYPE_ALL, NO_ERRNO, _("Invalid watchdog timeout %d"),parm_in); + } else { + cam->conf->watchdog_tmo = parm_in; + } + } else if (pact == PARM_ACT_GET){ + parm = std::to_string(cam->conf->watchdog_tmo); + } + return; + MOTION_LOG(DBG, TYPE_ALL, NO_ERRNO,"%s:%s","watchdog_tmo",_("watchdog_tmo")); +} + static void conf_edit_v4l2_device(struct ctx_cam *cam, std::string &parm, enum PARM_ACT pact) { if (pact == PARM_ACT_DFLT) { @@ -3107,6 +3129,7 @@ static void conf_edit_cat01(struct ctx_cam *cam, std::string parm_nm, std::strin } else if (parm_nm == "camera_name"){ conf_edit_camera_name(cam, parm_val, pact); } else if (parm_nm == "camera_id"){ conf_edit_camera_id(cam, parm_val, pact); } else if (parm_nm == "target_dir"){ conf_edit_target_dir(cam, parm_val, pact); + } else if (parm_nm == "watchdog_tmo"){ conf_edit_watchdog_tmo(cam, parm_val, pact); } else if (parm_nm == "v4l2_device"){ conf_edit_v4l2_device(cam, parm_val, pact); } else if (parm_nm == "v4l2_params"){ conf_edit_v4l2_params(cam, parm_val, pact); } else if (parm_nm == "netcam_url"){ conf_edit_netcam_url(cam, parm_val, pact); diff --git a/src/conf.hpp b/src/conf.hpp index a2048f0e..63eeb931 100644 --- a/src/conf.hpp +++ b/src/conf.hpp @@ -31,6 +31,7 @@ int camera_id; std::string camera_dir; std::string target_dir; + int watchdog_tmo; /* Capture device configuration parameters */ std::string v4l2_device; diff --git a/src/motion_loop.cpp b/src/motion_loop.cpp index e5a019a6..3c2ca9fc 100644 --- a/src/motion_loop.cpp +++ b/src/motion_loop.cpp @@ -809,7 +809,7 @@ static void mlp_prepare(struct ctx_cam *cam) int frame_buffer_size; - cam->watchdog = WATCHDOG_TMO; + cam->watchdog = cam->conf->watchdog_tmo; cam->frame_last_ts.tv_sec = cam->frame_curr_ts.tv_sec; cam->frame_last_ts.tv_nsec = cam->frame_curr_ts.tv_nsec; @@ -1522,9 +1522,12 @@ static void mlp_frametiming(struct ctx_cam *cam) /** Thread function for each camera */ void *motion_loop(void *arg) { - struct ctx_cam *cam =(struct ctx_cam *) arg; + cam->restart_cam = TRUE; + cam->watchdog = cam->conf->watchdog_tmo; + cam->running_cam = TRUE; + if (mlp_init(cam) == 0){ while (!cam->finish_cam || cam->event_stop) { mlp_prepare(cam); diff --git a/src/motionplus.cpp b/src/motionplus.cpp index 09eee273..f52bf877 100644 --- a/src/motionplus.cpp +++ b/src/motionplus.cpp @@ -421,10 +421,6 @@ static void motion_start_thread(struct ctx_motapp *motapp, int indx) motapp->threads_running++; pthread_mutex_unlock(&motapp->global_lock); - motapp->cam_list[indx]->restart_cam = TRUE; - motapp->cam_list[indx]->watchdog = WATCHDOG_TMO; - motapp->cam_list[indx]->running_cam = TRUE; - pthread_attr_init(&thread_attr); pthread_attr_setdetachstate(&thread_attr, PTHREAD_CREATE_DETACHED); diff --git a/src/motionplus.hpp b/src/motionplus.hpp index 4b0f393b..3d4061de 100644 --- a/src/motionplus.hpp +++ b/src/motionplus.hpp @@ -87,7 +87,6 @@ struct ctx_v4l2cam; #define THRESHOLD_TUNE_LENGTH 256 #define MISSING_FRAMES_TIMEOUT 30 /* Frame count before grey lost image is used */ -#define WATCHDOG_TMO 30 /* 30 sec max motion_loop interval */ #define WATCHDOG_KILL -10 /* 10 sec grace period before calling thread cancel */ /* Filetype defines */