Skip to content

Commit cbc0f6b

Browse files
committed
Implement updating many of the parameters via the webcontrol without restarting camera
1 parent 39bd063 commit cbc0f6b

22 files changed

Lines changed: 834 additions & 547 deletions

doc/motion_config.html

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1235,7 +1235,11 @@ <h3><a name="v4l2_params"></a>v4l2_params</h3>
12351235
<h3><a name="libcam_device"></a>libcam_device</h3>
12361236
<ul>
12371237
<li> Values: String | Default: Not Defined </li>
1238-
The libcamera device. The value of 'camera0' is the only currently supported device.
1238+
The libcamera device. The log will list the availble devices. If
1239+
the user specifies 'camera0' the first device found will be used. (Useful
1240+
when there is only one camera on system). Otherwise, the specify the
1241+
device description in the log or using the command <code>cam -l</code> Note that
1242+
you can also specify v4l2 devices(webcams) for the libcam_device.
12391243
</ul>
12401244
<p></p>
12411245

@@ -1246,6 +1250,10 @@ <h3><a name="libcam_params"></a>libcam_params</h3>
12461250
Comma separated list of configuration parameters (aka controls) for the libcamera device.
12471251
</ul>
12481252
<ul>
1253+
<i><h4>pixelformat</h4></i>
1254+
User requested pixelformat to use. Default of YU12 is most efficient. Usually
1255+
this parameter is specified as the fourcc character code.
1256+
12491257
<i><h4> Transform(string)</h4></i>
12501258
(These are libcamera transform and rotate options and may not provide result you anticipate.)
12511259
<div><ul>

src/camera.cpp

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1154,6 +1154,7 @@ void cls_camera::init()
11541154
}
11551155

11561156
cfg->parms_copy(conf_src);
1157+
conf_chg = false;
11571158

11581159
mythreadname_set("cl",cfg->device_id, cfg->device_name.c_str());
11591160

@@ -1864,6 +1865,54 @@ void cls_camera::check_schedule()
18641865
*/
18651866
}
18661867

1868+
/* Apply any changes to the configuration parameters set by webcontrol*/
1869+
void cls_camera::check_config()
1870+
{
1871+
std::string parm_nm, parm_vl_cur, parm_vl_src;
1872+
PARM_CAT parm_ct;
1873+
PARM_CHG parm_ch;
1874+
int indx;
1875+
1876+
if ((restart == true) || (handler_stop == true) || (conf_chg == false)) {
1877+
return;
1878+
}
1879+
1880+
indx=0;
1881+
while (config_parms[indx].parm_name != "") {
1882+
parm_nm = config_parms[indx].parm_name;
1883+
parm_ct = config_parms[indx].parm_cat;
1884+
parm_ch = config_parms[indx].parm_chg;
1885+
conf_src->edit_get(parm_nm, parm_vl_src, parm_ct);
1886+
cfg->edit_get(parm_nm, parm_vl_cur, parm_ct);
1887+
if (parm_vl_cur != parm_vl_src) {
1888+
if (parm_ch == PARM_CHG_COPY) {
1889+
cfg->edit_set(parm_nm, parm_vl_src);
1890+
MOTION_LOG(INF, TYPE_EVENTS, NO_ERRNO
1891+
, _("%s:%s applied")
1892+
, parm_nm.c_str(), parm_vl_src.c_str());
1893+
} else if (parm_ch == PARM_CHG_CODE) {
1894+
if ((parm_nm == "v4l2_params") &&
1895+
(camera_type == CAMERA_TYPE_V4L2)) {
1896+
v4l2cam->parms_update();
1897+
} else if ((parm_nm == "libcam_params") &&
1898+
(camera_type == CAMERA_TYPE_LIBCAM)) {
1899+
libcam->parms_update();
1900+
} else {
1901+
MOTION_LOG(ERR, TYPE_ALL, NO_ERRNO
1902+
, _("Programming error for changes to parameter %s")
1903+
,parm_nm.c_str());
1904+
}
1905+
cfg->edit_set(parm_nm, parm_vl_src);
1906+
MOTION_LOG(INF, TYPE_EVENTS, NO_ERRNO
1907+
, _("%s:%s applied")
1908+
, parm_nm.c_str(), parm_vl_src.c_str());
1909+
}
1910+
}
1911+
indx++;
1912+
}
1913+
conf_chg = false;
1914+
}
1915+
18671916
/* sleep the loop to get framerate requested */
18681917
void cls_camera::frametiming()
18691918
{
@@ -1908,6 +1957,7 @@ void cls_camera::handler()
19081957
timelapse();
19091958
loopback();
19101959
check_schedule();
1960+
check_config();
19111961
frametiming();
19121962
}
19131963

@@ -2036,6 +2086,7 @@ cls_camera::cls_camera(cls_motapp *p_app)
20362086
handler_stop = true;
20372087
restart = false;
20382088
finish = false;
2089+
conf_chg = false;
20392090
watchdog = 90;
20402091
passflag = false;
20412092
pthread_mutex_init(&stream.mutex, NULL);

src/camera.hpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -158,6 +158,7 @@ class cls_camera {
158158

159159
bool restart;
160160
bool finish;
161+
bool conf_chg;
161162
int threadnr;
162163
int noise;
163164
bool detecting_motion;
@@ -265,6 +266,7 @@ class cls_camera {
265266
void timelapse();
266267
void loopback();
267268
void check_schedule();
269+
void check_config();
268270
void frametiming();
269271
};
270272

src/conf.cpp

Lines changed: 176 additions & 187 deletions
Large diffs are not rendered by default.

src/conf.hpp

Lines changed: 17 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -51,21 +51,27 @@
5151
, PARM_TYP_ARRAY
5252
, PARM_TYP_PARAMS
5353
};
54-
enum PARM_LEVEL{
55-
PARM_LEVEL_ALWAYS = 0
56-
,PARM_LEVEL_LIMITED = 1
57-
,PARM_LEVEL_ADVANCED = 2
58-
,PARM_LEVEL_SCRIPTS = 3
59-
,PARM_LEVEL_RESTRICTED = 4
60-
,PARM_LEVEL_NEVER = 99
54+
enum PARM_LVL{
55+
PARM_LVL_00 = 0 /*Webcontrol Always Available Parameters*/
56+
,PARM_LVL_01 = 1 /*Webcontrol Limited Parameters */
57+
,PARM_LVL_02 = 2 /*Webcontrol Advanced Parameters*/
58+
,PARM_LVL_03 = 3 /*Webcontrol Scripts Parameters*/
59+
,PARM_LVL_04 = 4 /*Webcontrol Restricted Parameters*/
60+
,PARM_LVL_99 = 99 /*Webcontrol Never Available Parameters*/
61+
};
62+
enum PARM_CHG{ /*Method to apply webcontrol changes to parameter*/
63+
PARM_CHG_COPY = 0 /* Copy the new value to cfg to apply new value*/
64+
,PARM_CHG_CODE = 1 /* A specific procedure is written to apply new values */
65+
,PARM_CHG_RESTART = 2 /* Restart of the thread is required*/
6166
};
6267

6368
/** Current parameters in the config file */
6469
struct ctx_parm {
65-
const std::string parm_name; /* name for this parameter */
66-
enum PARM_TYP parm_type; /* enum of parm_typ for bool,int or string. */
67-
enum PARM_CAT parm_cat; /* enum of parm_cat for grouping. */
68-
int webui_level; /* Enum to display in webui: 0,1,2,3,99(always to never)*/
70+
const std::string parm_name; /* name for this parameter */
71+
enum PARM_TYP parm_type; /* enum of parm_typ for bool,int or string. */
72+
enum PARM_CAT parm_cat; /* enum of parm_cat for grouping. */
73+
int parm_lvl; /* Enum of parm_lvl for webui*/
74+
enum PARM_CHG parm_chg; /* Enum for whether a restart is needed to implement changes*/
6975
};
7076

7177
enum PARM_ACT{

src/dbse.hpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,7 @@ class cls_dbse {
9090
void filelist_get(std::string sql, vec_files &p_flst);
9191
bool restart;
9292
bool finish;
93+
bool conf_chg;
9394
void shutdown();
9495
void startup();
9596

src/jpegutils.cpp

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -631,18 +631,15 @@ static void jpgutl_error_exit(j_common_ptr cinfo)
631631
*/
632632
static void jpgutl_emit_message(j_common_ptr cinfo, int msg_level)
633633
{
634-
char buffer[JMSG_LENGTH_MAX];
635-
/* cinfo->err really points to a jpgutl_error_mgr struct, so coerce pointer. */
636634
struct jpgutl_error_mgr *myerr = (struct jpgutl_error_mgr *) cinfo->err;
637635
/*
638636
* The JWRN_EXTRANEOUS_DATA is sent a lot without any particular negative effect.
639637
* There are some messages above zero but they are just informational and not something
640638
* that we are interested in.
641639
*/
642-
if ((cinfo->err->msg_code != JWRN_EXTRANEOUS_DATA) && (msg_level < 0) ) {
640+
if ((cinfo->err->msg_code != JWRN_EXTRANEOUS_DATA) && (msg_level < 0)) {
643641
myerr->warning_seen++ ;
644-
(*cinfo->err->format_message) (cinfo, buffer);
645-
MOTION_LOG(DBG, TYPE_VIDEO, NO_ERRNO, "msg_level: %d, %s", msg_level, buffer);
642+
MOTION_LOG(DBG, TYPE_VIDEO, NO_ERRNO, "msg_level: %d, Corrupt JPEG data", msg_level);
646643
}
647644

648645
}

0 commit comments

Comments
 (0)