diff --git a/src/alg.cpp b/src/alg.cpp index e133babe..c1ae8498 100644 --- a/src/alg.cpp +++ b/src/alg.cpp @@ -124,7 +124,7 @@ void cls_alg::threshold_tune() sum = top * 2; } - if (sum < cfg_threshold) { + if (sum < cam->cfg->threshold) { cam->threshold = (cam->threshold + sum) / 2; } } @@ -507,7 +507,7 @@ void cls_alg::despeckle() uint i, len; u_char *out, *common_buffer; - if ((cfg_despeckle_filter == "") || cam->current_image->diffs <= 0) { + if ((cam->cfg->despeckle_filter == "") || cam->current_image->diffs <= 0) { if (cam->imgs.labelsize_max) { cam->imgs.labelsize_max = 0; } @@ -519,13 +519,13 @@ void cls_alg::despeckle() width = cam->imgs.width; height = cam->imgs.height; done = 0; - len = (uint)cfg_despeckle_filter.length(); + len = (uint)cam->cfg->despeckle_filter.length(); common_buffer = cam->imgs.common_buffer; cam->current_image->total_labels = 0; cam->imgs.largest_label = 0; for (i = 0; i < len; i++) { - switch (cfg_despeckle_filter[i]) { + switch (cam->cfg->despeckle_filter[i]) { case 'E': diffs = erode9(out, width, height, common_buffer, 0); if (diffs == 0) { @@ -576,9 +576,9 @@ void cls_alg::tune_smartmask() int i; u_char diff; int motionsize = cam->imgs.motionsize; - int sensitivity = cam->lastrate * (11 - cfg_smart_mask_speed); + int sensitivity = cam->lastrate * (11 - cam->cfg->smart_mask_speed); - if ((cfg_smart_mask_speed == 0) || + if ((cam->cfg->smart_mask_speed == 0) || (cam->event_curr_nbr == cam->event_prev_nbr) || (--smartmask_count)) { return; @@ -612,7 +612,7 @@ void cls_alg::tune_smartmask() cam->imgs.common_buffer, 255); erode5(smartmask_final, cam->imgs.width, cam->imgs.height, cam->imgs.common_buffer, 255); - smartmask_count = 5 * cam->lastrate * (11 - cfg_smart_mask_speed); + smartmask_count = 5 * cam->lastrate * (11 - cam->cfg->smart_mask_speed); } void cls_alg::diff_nomask() @@ -625,7 +625,7 @@ void cls_alg::diff_nomask() int imgsz = cam->imgs.motionsize; int diffs = 0, diffs_net = 0; int noise = cam->noise; - int lrgchg = cfg_threshold_ratio_change; + int lrgchg = cam->cfg->threshold_ratio_change; memset(out + imgsz, 128, (uint)(imgsz / 2)); memset(out, 0, (uint)imgsz); @@ -668,7 +668,7 @@ void cls_alg::diff_mask() int imgsz = cam->imgs.motionsize; int diffs = 0, diffs_net = 0; int noise = cam->noise; - int lrgchg = cfg_threshold_ratio_change; + int lrgchg = cam->cfg->threshold_ratio_change; memset(out + imgsz, 128, (uint)(imgsz / 2)); memset(out, 0, (uint)imgsz); @@ -719,7 +719,7 @@ void cls_alg::diff_smart() int diffs = 0, diffs_net = 0; int noise = cam->noise; int *mask_buffer = smartmask_buffer; - int lrgchg = cfg_threshold_ratio_change; + int lrgchg = cam->cfg->threshold_ratio_change; imgsz = cam->imgs.motionsize; memset(out + imgsz, 128, (uint)(imgsz / 2)); @@ -727,7 +727,7 @@ void cls_alg::diff_smart() for (i = 0; i < imgsz; i++) { curdiff = (*ref - *new_img); - if (cfg_smart_mask_speed) { + if (cam->cfg->smart_mask_speed) { if (abs(curdiff) > noise) { if (cam->event_curr_nbr != cam->event_prev_nbr) { (*mask_buffer) += SMARTMASK_SENSITIVITY_INCR; @@ -777,7 +777,7 @@ void cls_alg::diff_masksmart() int diffs = 0, diffs_net = 0; int noise = cam->noise; int *mask_buffer = smartmask_buffer; - int lrgchg = cfg_threshold_ratio_change; + int lrgchg = cam->cfg->threshold_ratio_change; imgsz= cam->imgs.motionsize; memset(out + imgsz, 128, ((uint)imgsz / 2)); @@ -789,7 +789,7 @@ void cls_alg::diff_masksmart() curdiff = ((curdiff * *mask) / 255); } - if (cfg_smart_mask_speed) { + if (cam->cfg->smart_mask_speed) { if (abs(curdiff) > noise) { if (cam->event_curr_nbr != cam->event_prev_nbr) { (*mask_buffer) += SMARTMASK_SENSITIVITY_INCR; @@ -837,7 +837,7 @@ bool cls_alg::diff_fast() int i, curdiff, diffs = 0; int step = cam->imgs.motionsize / 10000; int noise = cam->noise; - int max_n_changes = cfg_threshold / 2; + int max_n_changes = cam->cfg->threshold / 2; u_char *ref = imgs->ref; u_char *new_img = cam->imgs.image_vprvcy; @@ -866,7 +866,7 @@ bool cls_alg::diff_fast() void cls_alg::diff_standard() { - if (cfg_smart_mask_speed == 0) { + if (cam->cfg->smart_mask_speed == 0) { if (cam->imgs.mask == NULL) { diff_nomask(); } else { @@ -883,11 +883,11 @@ void cls_alg::diff_standard() void cls_alg::lightswitch() { - if (cfg_lightswitch_percent >= 1 && !cam->lost_connection) { - if (cam->current_image->diffs > (cam->imgs.motionsize * cfg_lightswitch_percent / 100)) { + if (cam->cfg->lightswitch_percent >= 1 && !cam->lost_connection) { + if (cam->current_image->diffs > (cam->imgs.motionsize * cam->cfg->lightswitch_percent / 100)) { MOTPLS_LOG(INF, TYPE_ALL, NO_ERRNO, _("Lightswitch detected")); - if (cam->frame_skip < cfg_lightswitch_frames) { - cam->frame_skip = cfg_lightswitch_frames; + if (cam->frame_skip < cam->cfg->lightswitch_frames) { + cam->frame_skip = cam->cfg->lightswitch_frames; } cam->current_image->diffs = 0; ref_frame_update(); @@ -897,7 +897,7 @@ void cls_alg::lightswitch() void cls_alg::ref_frame_update() { - int accept_timer = cam->lastrate * cfg_static_object_time; + int accept_timer = cam->lastrate * cam->cfg->static_object_time; int i, threshold_ref; int *ref_dyn = cam->imgs.ref_dyn; u_char *image_virgin = cam->imgs.image_vprvcy; @@ -1177,18 +1177,18 @@ void cls_alg::stddev() if (calc_stddev == false) { return; } - if (cfg_threshold_sdevx > 0) { - if (cam->current_image->location.stddev_x > cfg_threshold_sdevx) { + if (cam->cfg->threshold_sdevx > 0) { + if (cam->current_image->location.stddev_x > cam->cfg->threshold_sdevx) { cam->current_image->diffs = 0; return; } - } else if (cfg_threshold_sdevy > 0) { - if (cam->current_image->location.stddev_y > cfg_threshold_sdevy) { + } else if (cam->cfg->threshold_sdevy > 0) { + if (cam->current_image->location.stddev_y > cam->cfg->threshold_sdevy) { cam->current_image->diffs = 0; return; } - } else if (cfg_threshold_sdevxy > 0) { - if (cam->current_image->location.stddev_xy > cfg_threshold_sdevxy) { + } else if (cam->cfg->threshold_sdevxy > 0) { + if (cam->current_image->location.stddev_xy > cam->cfg->threshold_sdevxy) { cam->current_image->diffs = 0; return; } @@ -1212,31 +1212,15 @@ void cls_alg::diff() despeckle(); } -void cls_alg::init_conf() -{ - cfg_threshold_sdevx = cam->conf->threshold_sdevx; - cfg_threshold_sdevy = cam->conf->threshold_sdevy; - cfg_threshold_sdevxy = cam->conf->threshold_sdevxy; - cfg_threshold = cam->conf->threshold; - cfg_despeckle_filter = cam->conf->despeckle_filter; - cfg_threshold_ratio_change = cam->conf->threshold_ratio_change; - cfg_lightswitch_percent = cam->conf->lightswitch_percent; - cfg_lightswitch_frames = cam->conf->lightswitch_frames; - cfg_static_object_time = cam->conf->static_object_time; - cfg_smart_mask_speed = cam->conf->smart_mask_speed; -} - cls_alg::cls_alg(cls_camera *p_cam) { int i; cam = p_cam; - init_conf(); - - if ((cfg_threshold_sdevx == 0) && - (cfg_threshold_sdevy == 0) && - (cfg_threshold_sdevxy == 0)) { + if ((cam->cfg->threshold_sdevx == 0) && + (cam->cfg->threshold_sdevy == 0) && + (cam->cfg->threshold_sdevxy == 0)) { calc_stddev = false; } else { calc_stddev = true; diff --git a/src/alg.hpp b/src/alg.hpp index c904c15e..e4583395 100644 --- a/src/alg.hpp +++ b/src/alg.hpp @@ -39,19 +39,7 @@ u_char *smartmask; int *smartmask_buffer; int diffs_last[THRESHOLD_TUNE_LENGTH]; - - int cfg_threshold_sdevx; - int cfg_threshold_sdevy; - int cfg_threshold_sdevxy; - int cfg_threshold; - std::string cfg_despeckle_filter; - int cfg_threshold_ratio_change; - int cfg_lightswitch_percent; - int cfg_lightswitch_frames; - int cfg_static_object_time; - int cfg_smart_mask_speed; - - bool calc_stddev; + bool calc_stddev; int iflood(int x, int y, int width, int height, u_char *out, int *labels, int newvalue, int oldvalue); @@ -72,7 +60,6 @@ void location_dist_stddev(); void location_dist_basic(); void location_minmax(); - void init_conf(); }; diff --git a/src/alg_sec.cpp b/src/alg_sec.cpp index 0586c6b8..a8ec32ed 100644 --- a/src/alg_sec.cpp +++ b/src/alg_sec.cpp @@ -504,7 +504,7 @@ void cls_algsec::load_params() { pthread_mutex_init(&mutex, NULL); - method = cam->conf->secondary_method; + method = cam->cfg->secondary_method; handler_finished = true; image_norm = nullptr; params = nullptr; @@ -515,9 +515,9 @@ void cls_algsec::load_params() too_slow = 0; in_process = false; handler_stop = false; - cfg_framerate = cam->conf->framerate; - cfg_log_level = cam->motapp->conf->log_level; - cfg_target_dir = cam->conf->target_dir; + cfg_framerate = cam->cfg->framerate; + cfg_log_level = cam->motapp->cfg->log_level; + cfg_target_dir = cam->cfg->target_dir; if (method == "none") { return; @@ -528,7 +528,7 @@ void cls_algsec::load_params() params = new ctx_params; params->update_params = true; util_parms_parse(params, "secondary_params" - , cam->conf->secondary_params); + , cam->cfg->secondary_params); params_defaults(); @@ -672,10 +672,10 @@ cls_algsec::cls_algsec(cls_camera *p_cam) { #ifdef HAVE_OPENCV cam = p_cam; - mythreadname_set("cv",cam->device_id, cam->conf->device_name.c_str()); + mythreadname_set("cv",cam->device_id, cam->cfg->device_name.c_str()); load_params(); start_model(); - mythreadname_set("cl",cam->device_id, cam->conf->device_name.c_str()); + mythreadname_set("cl",cam->device_id, cam->cfg->device_name.c_str()); #else (void)p_cam; #endif diff --git a/src/camera.cpp b/src/camera.cpp index 8a2c9a85..69aec16e 100644 --- a/src/camera.cpp +++ b/src/camera.cpp @@ -48,7 +48,7 @@ void cls_camera::ring_resize() int i, new_size; ctx_image_data *tmp; - new_size = conf->pre_capture + conf->minimum_motion_frames; + new_size = cfg->pre_capture + cfg->minimum_motion_frames; if (new_size < 1) { new_size = 1; } @@ -155,8 +155,8 @@ void cls_camera::ring_process() current_image = &imgs.image_ring[imgs.ring_out]; - if (current_image->shot <= conf->framerate) { - if (motapp->conf->log_level >= DBG) { + if (current_image->shot <= cfg->framerate) { + if (motapp->cfg->log_level >= DBG) { ring_process_debug(); } ring_process_image(); @@ -165,12 +165,12 @@ void cls_camera::ring_process() current_image->flags |= IMAGE_SAVED; if (current_image->flags & IMAGE_MOTION) { - if (conf->picture_output == "best") { + if (cfg->picture_output == "best") { if (current_image->diffs > imgs.image_preview.diffs) { picture->save_preview(); } } - if (conf->picture_output == "center") { + if (cfg->picture_output == "center") { if (current_image->cent_dist < imgs.image_preview.cent_dist) { picture->save_preview(); } @@ -239,23 +239,23 @@ void cls_camera::detected_trigger() mystrftime(this, text_event_string , sizeof(text_event_string) - , conf->text_event.c_str(), NULL); + , cfg->text_event.c_str(), NULL); - if (conf->on_event_start != "") { - util_exec_command(this, conf->on_event_start.c_str(), NULL); + if (cfg->on_event_start != "") { + util_exec_command(this, cfg->on_event_start.c_str(), NULL); } movie_start(); motapp->dbse->exec(this, "", "event_start"); - if ((conf->picture_output == "first") || - (conf->picture_output == "best") || - (conf->picture_output == "center")) { + if ((cfg->picture_output == "first") || + (cfg->picture_output == "best") || + (cfg->picture_output == "center")) { picture->save_preview(); } } - if (conf->on_motion_detected != "") { - util_exec_command(this, conf->on_motion_detected.c_str(), NULL); + if (cfg->on_motion_detected != "") { + util_exec_command(this, cfg->on_motion_detected.c_str(), NULL); } } } @@ -263,22 +263,22 @@ void cls_camera::detected_trigger() /* call ptz camera center */ void cls_camera::track_center() { - if ((conf->ptz_auto_track) && (conf->ptz_move_track != "")) { + if ((cfg->ptz_auto_track) && (cfg->ptz_move_track != "")) { track_posx = 0; track_posy = 0; - util_exec_command(this, conf->ptz_move_track.c_str(), NULL); - frame_skip = conf->ptz_wait; + util_exec_command(this, cfg->ptz_move_track.c_str(), NULL); + frame_skip = cfg->ptz_wait; } } /* call ptz camera move */ void cls_camera::track_move() { - if ((conf->ptz_auto_track) && (conf->ptz_move_track != "")) { + if ((cfg->ptz_auto_track) && (cfg->ptz_move_track != "")) { track_posx += current_image->location.x; track_posy += current_image->location.y; - util_exec_command(this, conf->ptz_move_track.c_str(), NULL); - frame_skip = conf->ptz_wait; + util_exec_command(this, cfg->ptz_move_track.c_str(), NULL); + frame_skip = cfg->ptz_wait; } } @@ -290,7 +290,7 @@ void cls_camera::detected() draw->locate(); /* Calculate how centric motion is if configured preview center*/ - if (conf->picture_output == "center") { + if (cfg->picture_output == "center") { distX = (uint)abs((imgs.width / 2) - current_image->location.x ); distY = (uint)abs((imgs.height / 2) - current_image->location.y); current_image->cent_dist = distX * distX + distY * distY; @@ -298,8 +298,8 @@ void cls_camera::detected() detected_trigger(); - if (current_image->shot <= conf->framerate) { - if ((conf->stream_motion == true) && + if (current_image->shot <= cfg->framerate) { + if ((cfg->stream_motion == true) && (current_image->shot != 1)) { webu_getimg_main(this); } @@ -405,13 +405,13 @@ void cls_camera::cam_close() /* Start camera */ void cls_camera::cam_start() { - watchdog = conf->watchdog_tmo; + watchdog = cfg->watchdog_tmo; if (camera_type == CAMERA_TYPE_LIBCAM) { libcam = new cls_libcam(this); } else if (camera_type == CAMERA_TYPE_NETCAM) { netcam = new cls_netcam(this, false); - if (conf->netcam_high_url != "") { - watchdog = conf->watchdog_tmo; + if (cfg->netcam_high_url != "") { + watchdog = cfg->watchdog_tmo; netcam_high = new cls_netcam(this, true); } } else if (camera_type == CAMERA_TYPE_V4L2) { @@ -421,7 +421,7 @@ void cls_camera::cam_start() ,_("No Camera device specified")); device_status = STATUS_CLOSED; } - watchdog = conf->watchdog_tmo; + watchdog = cfg->watchdog_tmo; } /* Get next image from camera */ @@ -451,11 +451,11 @@ int cls_camera::cam_next(ctx_image_data *img_data) /* Assign the camera type */ void cls_camera::init_camera_type() { - if (conf->libcam_device != "") { + if (cfg->libcam_device != "") { camera_type = CAMERA_TYPE_LIBCAM; - } else if (conf->netcam_url != "") { + } else if (cfg->netcam_url != "") { camera_type = CAMERA_TYPE_NETCAM; - } else if (conf->v4l2_device != "") { + } else if (cfg->v4l2_device != "") { camera_type = CAMERA_TYPE_V4L2; } else { MOTPLS_LOG(ERR, TYPE_ALL, NO_ERRNO @@ -501,10 +501,10 @@ void cls_camera::init_firstimage() } } - noise = conf->noise_level; - threshold = conf->threshold; - if (conf->threshold_maximum > conf->threshold ) { - threshold_maximum = conf->threshold_maximum; + noise = cfg->noise_level; + threshold = cfg->threshold; + if (cfg->threshold_maximum > cfg->threshold ) { + threshold_maximum = cfg->threshold_maximum; } else { threshold_maximum = (imgs.height * imgs.width * 3) / 2; } @@ -587,27 +587,27 @@ void cls_camera::init_values() event_curr_nbr = 1; event_prev_nbr = 0; - watchdog = conf->watchdog_tmo; + watchdog = cfg->watchdog_tmo; clock_gettime(CLOCK_MONOTONIC, &frame_curr_ts); clock_gettime(CLOCK_MONOTONIC, &frame_last_ts); - noise = conf->noise_level; + noise = cfg->noise_level; passflag = false; motapp->all_sizes->reset= true; - threshold = conf->threshold; + threshold = cfg->threshold; device_status = STATUS_CLOSED; - startup_frames = (conf->framerate * 2) + conf->pre_capture + conf->minimum_motion_frames; + startup_frames = (cfg->framerate * 2) + cfg->pre_capture + cfg->minimum_motion_frames; missing_frame_counter = 0; frame_skip = 0; detecting_motion = false; shots_mt = 0; - lastrate = conf->framerate; + lastrate = cfg->framerate; event_user = false; lasttime = frame_curr_ts.tv_sec; postcap = 0; - movie_passthrough = conf->movie_passthrough; + movie_passthrough = cfg->movie_passthrough; if ((camera_type != CAMERA_TYPE_NETCAM) && (movie_passthrough)) { MOTPLS_LOG(WRN, TYPE_ALL, NO_ERRNO,_("Pass-through processing disabled.")); @@ -616,7 +616,7 @@ void cls_camera::init_values() if (motapp->pause) { pause = true; } else { - pause = conf->pause; + pause = cfg->pause; } v4l2cam = nullptr; netcam = nullptr; @@ -647,8 +647,8 @@ void cls_camera::init_cam_start() if (device_status == STATUS_CLOSED) { MOTPLS_LOG(ERR, TYPE_ALL, NO_ERRNO,_("Failed to start camera.")); - imgs.width = conf->width; - imgs.height = conf->height; + imgs.width = cfg->width; + imgs.height = cfg->height; } imgs.motionsize = (imgs.width * imgs.height); @@ -682,8 +682,8 @@ void cls_camera::cleanup() picture->process_preview(); imgs.image_preview.diffs = 0; } - if (conf->on_event_end != "") { - util_exec_command(this, conf->on_event_end.c_str(), NULL); + if (cfg->on_event_end != "") { + util_exec_command(this, cfg->on_event_end.c_str(), NULL); } movie_end(); motapp->dbse->exec(this, "", "event_end"); @@ -746,11 +746,17 @@ void cls_camera::init() if (restart == true) { cleanup(); + restart = false; } - restart = false; + + cfg->parms_copy(conf_src); + + mythreadname_set("cl",cfg->device_id, cfg->device_name.c_str()); MOTPLS_LOG(INF, TYPE_ALL, NO_ERRNO,_("Initialize Camera")); + cfg->parms_copy(conf_src); + init_camera_type(); init_values(); @@ -788,7 +794,7 @@ void cls_camera::init() ,_("Camera %d started: motion detection %s"), device_id, pause ? _("Disabled"):_("Enabled")); - if (conf->emulate_motion) { + if (cfg->emulate_motion) { MOTPLS_LOG(INF, TYPE_ALL, NO_ERRNO, _("Emulating motion")); } } @@ -800,19 +806,19 @@ void cls_camera::areadetect() { int i, j, z = 0; - if ((conf->area_detect != "" ) && + if ((cfg->area_detect != "" ) && (event_curr_nbr != areadetect_eventnbr) && (current_image->flags & IMAGE_TRIGGER)) { - j = (int)conf->area_detect.length(); + j = (int)cfg->area_detect.length(); for (i = 0; i < j; i++) { - z = conf->area_detect[(uint)i] - 49; /* characters are stored as ascii 48-57 (0-9) */ + z = cfg->area_detect[(uint)i] - 49; /* characters are stored as ascii 48-57 (0-9) */ if ((z >= 0) && (z < 9)) { if (current_image->location.x > area_minx[z] && current_image->location.x < area_maxx[z] && current_image->location.y > area_miny[z] && current_image->location.y < area_maxy[z]) { - if (conf->on_area_detected != "") { - util_exec_command(this, conf->on_area_detected.c_str(), NULL); + if (cfg->on_area_detected != "") { + util_exec_command(this, cfg->on_area_detected.c_str(), NULL); } areadetect_eventnbr = event_curr_nbr; /* Fire script only once per event */ MOTPLS_LOG(DBG, TYPE_ALL, NO_ERRNO @@ -827,7 +833,7 @@ void cls_camera::areadetect() /* Prepare for the next iteration of loop*/ void cls_camera::prepare() { - watchdog = conf->watchdog_tmo; + watchdog = cfg->watchdog_tmo; frame_last_ts.tv_sec = frame_curr_ts.tv_sec; frame_last_ts.tv_nsec = frame_curr_ts.tv_nsec; @@ -839,8 +845,8 @@ void cls_camera::prepare() } shots_mt++; - if (conf->pre_capture < 0) { - conf->pre_capture = 0; + if (cfg->pre_capture < 0) { + cfg->pre_capture = 0; } if (startup_frames > 0) { @@ -901,7 +907,7 @@ void cls_camera::retry() check_szimg(); - if (imgs.width != conf->width || imgs.height != conf->height) { + if (imgs.width != cfg->width || imgs.height != cfg->height) { MOTPLS_LOG(NTC, TYPE_ALL, NO_ERRNO,_("Resetting image buffers")); device_status = STATUS_CLOSED; restart = true; @@ -937,10 +943,10 @@ int cls_camera::capture() lost_connection = 0; connectionlosttime.tv_sec = 0; - if (missing_frame_counter >= (conf->device_tmo * conf->framerate)) { + if (missing_frame_counter >= (cfg->device_tmo * cfg->framerate)) { MOTPLS_LOG(NTC, TYPE_ALL, NO_ERRNO, _("Video signal re-acquired")); - if (conf->on_camera_found != "") { - util_exec_command(this, conf->on_camera_found.c_str(), NULL); + if (cfg->on_camera_found != "") { + util_exec_command(this, cfg->on_camera_found.c_str(), NULL); } } missing_frame_counter = 0; @@ -959,7 +965,7 @@ int cls_camera::capture() if ((device_status == STATUS_OPENED) && (missing_frame_counter < - (conf->device_tmo * conf->framerate))) { + (cfg->device_tmo * cfg->framerate))) { memcpy(current_image->image_norm, imgs.image_vprvcy , (uint)imgs.size_norm); } else { @@ -979,16 +985,16 @@ int cls_camera::capture() , tmpout, text_scale); /* Write error message only once */ - if (missing_frame_counter == (conf->device_tmo * conf->framerate)) { + if (missing_frame_counter == (cfg->device_tmo * cfg->framerate)) { MOTPLS_LOG(NTC, TYPE_ALL, NO_ERRNO ,_("Video signal lost - Adding grey image")); - if (conf->on_camera_lost != "") { - util_exec_command(this, conf->on_camera_lost.c_str(), NULL); + if (cfg->on_camera_lost != "") { + util_exec_command(this, cfg->on_camera_lost.c_str(), NULL); } } if ((device_status == STATUS_OPENED) && - (missing_frame_counter == ((conf->device_tmo * 4) * conf->framerate))) { + (missing_frame_counter == ((cfg->device_tmo * 4) * cfg->framerate))) { MOTPLS_LOG(ERR, TYPE_ALL, NO_ERRNO ,_("Video signal still lost - Trying to close video device")); cam_close(); @@ -1020,12 +1026,12 @@ void cls_camera::detection() /* tune the detection parameters*/ void cls_camera::tuning() { - if ((conf->noise_tune && shots_mt == 0) && + if ((cfg->noise_tune && shots_mt == 0) && (!detecting_motion && (current_image->diffs <= threshold))) { alg->noise_tune(); } - if (conf->threshold_tune) { + if (cfg->threshold_tune) { alg->threshold_tune(); } @@ -1036,7 +1042,7 @@ void cls_camera::tuning() } - if (current_image->diffs_ratio < conf->threshold_ratio) { + if (current_image->diffs_ratio < cfg->threshold_ratio) { current_image->diffs = 0; } @@ -1054,31 +1060,31 @@ void cls_camera::overlay() { char tmp[PATH_MAX]; - if ((conf->smart_mask_speed >0) && - ((conf->picture_output_motion != "off") || - conf->movie_output_motion || + if ((cfg->smart_mask_speed >0) && + ((cfg->picture_output_motion != "off") || + cfg->movie_output_motion || (stream.motion.jpg_cnct > 0) || (stream.motion.ts_cnct > 0))) { draw->smartmask(); } if (imgs.largest_label && - ((conf->picture_output_motion != "off") || - conf->movie_output_motion || + ((cfg->picture_output_motion != "off") || + cfg->movie_output_motion || (stream.motion.jpg_cnct > 0) || (stream.motion.ts_cnct > 0))) { draw->largest_label(); } if (imgs.mask && - ((conf->picture_output_motion != "off") || - conf->movie_output_motion || + ((cfg->picture_output_motion != "off") || + cfg->movie_output_motion || (stream.motion.jpg_cnct > 0) || (stream.motion.ts_cnct > 0))) { draw->fixed_mask(); } - if (conf->text_changes) { + if (cfg->text_changes) { if (pause == false) { sprintf(tmp, "%d", current_image->diffs); } else { @@ -1108,8 +1114,8 @@ void cls_camera::overlay() } /* Add text in lower left corner of the pictures */ - if (conf->text_left != "") { - mystrftime(this, tmp, sizeof(tmp), conf->text_left.c_str(), NULL); + if (cfg->text_left != "") { + mystrftime(this, tmp, sizeof(tmp), cfg->text_left.c_str(), NULL); draw->text(current_image->image_norm , imgs.width, imgs.height , 10, imgs.height - (10 * text_scale) @@ -1117,8 +1123,8 @@ void cls_camera::overlay() } /* Add text in lower right corner of the pictures */ - if (conf->text_right != "") { - mystrftime(this, tmp, sizeof(tmp), conf->text_right.c_str(), NULL); + if (cfg->text_right != "") { + mystrftime(this, tmp, sizeof(tmp), cfg->text_right.c_str(), NULL); draw->text(current_image->image_norm , imgs.width, imgs.height , imgs.width - 10, imgs.height - (10 * text_scale) @@ -1142,8 +1148,8 @@ void cls_camera::actions_emulate() } detecting_motion = true; - if (conf->post_capture > 0) { - postcap = conf->post_capture; + if (cfg->post_capture > 0) { + postcap = cfg->post_capture; } current_image->flags |= (IMAGE_TRIGGER | IMAGE_SAVE); @@ -1161,7 +1167,7 @@ void cls_camera::actions_motion() int indx, frame_count = 0; int pos = imgs.ring_in; - for (indx = 0; indx < conf->minimum_motion_frames; indx++) { + for (indx = 0; indx < cfg->minimum_motion_frames; indx++) { if (imgs.image_ring[pos].flags & IMAGE_MOTION) { frame_count++; } @@ -1172,7 +1178,7 @@ void cls_camera::actions_motion() } } - if (frame_count >= conf->minimum_motion_frames) { + if (frame_count >= cfg->minimum_motion_frames) { current_image->flags |= (IMAGE_TRIGGER | IMAGE_SAVE); @@ -1185,7 +1191,7 @@ void cls_camera::actions_motion() movie_motion->reset_start_time(&imgs.image_motion.imgts); } detecting_motion = true; - postcap = conf->post_capture; + postcap = cfg->post_capture; for (indx = 0; indx < imgs.ring_size; indx++) { imgs.image_ring[indx].flags |= IMAGE_SAVE; @@ -1205,8 +1211,8 @@ void cls_camera::actions_motion() /* call the event actions*/ void cls_camera::actions_event() { - if ((conf->event_gap > 0) && - ((frame_curr_ts.tv_sec - lasttime ) >= conf->event_gap)) { + if ((cfg->event_gap > 0) && + ((frame_curr_ts.tv_sec - lasttime ) >= cfg->event_gap)) { event_stop = true; } @@ -1219,8 +1225,8 @@ void cls_camera::actions_event() picture->process_preview(); imgs.image_preview.diffs = 0; } - if (conf->on_event_end != "") { - util_exec_command(this, conf->on_event_end.c_str(), NULL); + if (cfg->on_event_end != "") { + util_exec_command(this, cfg->on_event_end.c_str(), NULL); } movie_end(); motapp->dbse->exec(this, "", "event_end"); @@ -1230,9 +1236,9 @@ void cls_camera::actions_event() if (algsec->detected) { MOTPLS_LOG(NTC, TYPE_EVENTS , NO_ERRNO, _("Secondary detect")); - if (conf->on_secondary_detect != "") { + if (cfg->on_secondary_detect != "") { util_exec_command(this - , conf->on_secondary_detect.c_str() + , cfg->on_secondary_detect.c_str() , NULL); } } @@ -1248,10 +1254,10 @@ void cls_camera::actions_event() event_user = false; } - if ((conf->movie_max_time > 0) && + if ((cfg->movie_max_time > 0) && (event_curr_nbr == event_prev_nbr) && ((frame_curr_ts.tv_sec - movie_start_time) >= - conf->movie_max_time) && + cfg->movie_max_time) && ( !(current_image->flags & IMAGE_POSTCAP)) && ( !(current_image->flags & IMAGE_PRECAP))) { movie_end(); @@ -1285,7 +1291,7 @@ void cls_camera::actions() */ } - if ((conf->emulate_motion || event_user) && (startup_frames == 0)) { + if ((cfg->emulate_motion || event_user) && (startup_frames == 0)) { actions_emulate(); } else if ((current_image->flags & IMAGE_MOTION) && (startup_frames == 0)) { actions_motion(); @@ -1294,7 +1300,7 @@ void cls_camera::actions() postcap--; } else { current_image->flags |= IMAGE_PRECAP; - if ((conf->event_gap == 0) && detecting_motion) { + if ((cfg->event_gap == 0) && detecting_motion) { event_stop = true; } detecting_motion = false; @@ -1319,9 +1325,9 @@ void cls_camera::actions() /* Snapshot interval*/ void cls_camera::snapshot() { - if ((conf->snapshot_interval > 0 && shots_mt == 0 && - frame_curr_ts.tv_sec % conf->snapshot_interval <= - frame_last_ts.tv_sec % conf->snapshot_interval) || + if ((cfg->snapshot_interval > 0 && shots_mt == 0 && + frame_curr_ts.tv_sec % cfg->snapshot_interval <= + frame_last_ts.tv_sec % cfg->snapshot_interval) || action_snapshot) { picture->process_snapshot(); action_snapshot = false; @@ -1333,28 +1339,28 @@ void cls_camera::timelapse() { struct tm timestamp_tm; - if (conf->timelapse_interval) { + if (cfg->timelapse_interval) { localtime_r(¤t_image->imgts.tv_sec, ×tamp_tm); if (timestamp_tm.tm_min == 0 && (frame_curr_ts.tv_sec % 60 < frame_last_ts.tv_sec % 60) && shots_mt == 0) { - if (conf->timelapse_mode == "daily") { + if (cfg->timelapse_mode == "daily") { if (timestamp_tm.tm_hour == 0) { movie_timelapse->stop(); } - } else if (conf->timelapse_mode == "hourly") { + } else if (cfg->timelapse_mode == "hourly") { movie_timelapse->stop(); - } else if (conf->timelapse_mode == "weekly-sunday") { + } else if (cfg->timelapse_mode == "weekly-sunday") { if (timestamp_tm.tm_wday == 0 && timestamp_tm.tm_hour == 0) { movie_timelapse->stop(); } - } else if (conf->timelapse_mode == "weekly-monday") { + } else if (cfg->timelapse_mode == "weekly-monday") { if (timestamp_tm.tm_wday == 1 && timestamp_tm.tm_hour == 0) { movie_timelapse->stop(); } - } else if (conf->timelapse_mode == "monthly") { + } else if (cfg->timelapse_mode == "monthly") { if (timestamp_tm.tm_mday == 1 && timestamp_tm.tm_hour == 0) { movie_timelapse->stop(); } @@ -1362,8 +1368,8 @@ void cls_camera::timelapse() } if (shots_mt == 0 && - frame_curr_ts.tv_sec % conf->timelapse_interval <= - frame_last_ts.tv_sec % conf->timelapse_interval) { + frame_curr_ts.tv_sec % cfg->timelapse_interval <= + frame_last_ts.tv_sec % cfg->timelapse_interval) { movie_timelapse->start(); if (movie_timelapse->put_image( current_image, ¤t_image->imgts) == -1) { @@ -1387,7 +1393,7 @@ void cls_camera::loopback() vlp_putpipe(this); - if (!conf->stream_motion || shots_mt == 0) { + if (!cfg->stream_motion || shots_mt == 0) { webu_getimg_main(this); } @@ -1405,8 +1411,8 @@ void cls_camera::frametiming() frame_wait[indx]=frame_wait[indx+1]; } - if (conf->framerate) { - frame_wait[AVGCNT-1] = 1000000L / conf->framerate; + if (cfg->framerate) { + frame_wait[AVGCNT-1] = 1000000L / cfg->framerate; } else { frame_wait[AVGCNT-1] = 0; } @@ -1435,7 +1441,7 @@ void cls_camera::frametiming() void cls_camera::handler() { - mythreadname_set("cl", conf->device_id, conf->device_name.c_str()); + mythreadname_set("cl", cfg->device_id, cfg->device_name.c_str()); device_status = STATUS_INIT; while (handler_stop == false) { @@ -1490,23 +1496,23 @@ void cls_camera::stop() if (handler_finished == false) { handler_stop = true; waitcnt = 0; - while ((handler_finished == false) && (waitcnt < conf->watchdog_tmo)){ + while ((handler_finished == false) && (waitcnt < cfg->watchdog_tmo)){ SLEEP(1,0) waitcnt++; } - if (waitcnt == conf->watchdog_tmo) { + if (waitcnt == cfg->watchdog_tmo) { MOTPLS_LOG(ERR, TYPE_ALL, NO_ERRNO , _("Normal shutdown of camera failed")); - if (conf->watchdog_kill > 0) { + if (cfg->watchdog_kill > 0) { MOTPLS_LOG(ERR, TYPE_ALL, NO_ERRNO ,_("Waiting additional %d seconds (watchdog_kill).") - ,conf->watchdog_kill); + ,cfg->watchdog_kill); waitcnt = 0; - while ((handler_finished == false) && (waitcnt < conf->watchdog_kill)){ + while ((handler_finished == false) && (waitcnt < cfg->watchdog_kill)){ SLEEP(1,0) waitcnt++; } - if (waitcnt == conf->watchdog_kill) { + if (waitcnt == cfg->watchdog_kill) { MOTPLS_LOG(ERR, TYPE_ALL, NO_ERRNO , _("No response to shutdown. Killing it.")); MOTPLS_LOG(ERR, TYPE_ALL, NO_ERRNO @@ -1520,7 +1526,7 @@ void cls_camera::stop() } } handler_finished = true; - watchdog = conf->watchdog_tmo; + watchdog = cfg->watchdog_tmo; } } @@ -1537,5 +1543,6 @@ cls_camera::cls_camera(ctx_motapp *p_motapp) cls_camera::~cls_camera() { - mydelete(conf); + mydelete(conf_src); + mydelete(cfg); } diff --git a/src/camera.hpp b/src/camera.hpp index 609a57ea..21a0e0c3 100644 --- a/src/camera.hpp +++ b/src/camera.hpp @@ -122,7 +122,8 @@ class cls_camera { void stop(); ctx_motapp *motapp; - cls_config *conf; + cls_config *cfg; + cls_config *conf_src; ctx_images imgs; ctx_stream stream; ctx_image_data *current_image; @@ -207,6 +208,7 @@ class cls_camera { int areadetect_eventnbr; int previous_diffs, previous_location_x, previous_location_y; + void ring_resize(); void ring_destroy(); void ring_process_debug(); @@ -231,6 +233,7 @@ class cls_camera { void init_values(); void init_cam_start(); void init_ref(); + void init_conf(); void cleanup(); void init(); void areadetect(); diff --git a/src/conf.cpp b/src/conf.cpp index c4120df5..27feb267 100644 --- a/src/conf.cpp +++ b/src/conf.cpp @@ -16,6 +16,17 @@ * */ +/* +Notes: +This needs additional work. +Create a vector/list from config_params. +Reassign class categories to group together those applicable to application vs camera vs sound. +Create a class of just the parms/edits to segregate from the config file processes +Perhaps a lightweight class of just the parms. Use this instead of full class for the config + parms that are being used "live" with devices + (currently called "cfg" in the camera,sound and motionplus classes) +Remove the depreceated parameters from old Motion. +*/ #include "motionplus.hpp" #include "util.hpp" #include "logger.hpp" @@ -3590,18 +3601,18 @@ void cls_config::camera_filenm(ctx_motapp *motapp) struct stat statbuf; size_t lstpos; - lstpos = motapp->conf->conf_filename.find_last_of("/"); + lstpos = motapp->conf_src->conf_filename.find_last_of("/"); if (lstpos != std::string::npos) { lstpos++; } - dirnm = motapp->conf->conf_filename.substr(0, lstpos); + dirnm = motapp->conf_src->conf_filename.substr(0, lstpos); indx_cam = 1; fullnm = ""; while (fullnm == "") { fullnm = dirnm + "camera" + std::to_string(indx_cam) + ".conf"; for (indx = 0; indxcam_cnt; indx++) { - if (fullnm == motapp->cam_list[indx]->conf->conf_filename) { + if (fullnm == motapp->cam_list[indx]->conf_src->conf_filename) { fullnm = ""; } } @@ -3629,13 +3640,13 @@ int cls_config::get_next_devid(ctx_motapp *motapp) dev_id++; chkid = false; for (indx = 0; indxcam_cnt;indx++) { - if ((motapp->cam_list[indx]->conf->device_id == dev_id) || + if ((motapp->cam_list[indx]->conf_src->device_id == dev_id) || (motapp->cam_list[indx]->device_id == dev_id)) { chkid = true; } } for (indx = 0; indxsnd_cnt;indx++) { - if ((motapp->snd_list[indx]->conf->device_id == dev_id) || + if ((motapp->snd_list[indx]->conf_src->device_id == dev_id) || (motapp->snd_list[indx]->device_id == dev_id)) { chkid = true; } @@ -3654,32 +3665,35 @@ void cls_config::camera_add(ctx_motapp *motapp, std::string fname, bool srcdir) cls_camera *cam_cls; cam_cls = new cls_camera(motapp); - cam_cls->conf = new cls_config; + cam_cls->conf_src = new cls_config; indx = 0; while (config_parms[indx].parm_name != "") { parm_nm =config_parms[indx].parm_name; if (parm_nm != "device_id") { - motapp->conf->edit_get(parm_nm, parm_val, config_parms[indx].parm_cat); - cam_cls->conf->edit_set(parm_nm, parm_val); + motapp->conf_src->edit_get(parm_nm, parm_val, config_parms[indx].parm_cat); + cam_cls->conf_src->edit_set(parm_nm, parm_val); } indx++; } - cam_cls->conf->from_conf_dir = srcdir; - cam_cls->conf->conf_filename = fname; - cam_cls->conf->device_id = get_next_devid(motapp); - cam_cls->device_id = cam_cls->conf->device_id; + cam_cls->conf_src->from_conf_dir = srcdir; + cam_cls->conf_src->conf_filename = fname; + cam_cls->conf_src->device_id = get_next_devid(motapp); + cam_cls->device_id = cam_cls->conf_src->device_id; if (fname == "") { - cam_cls->conf->camera_filenm(motapp); + cam_cls->conf_src->camera_filenm(motapp); } else if (stat(fname.c_str(), &statbuf) != 0) { MOTPLS_LOG(ALR, TYPE_ALL, SHOW_ERRNO ,_("Camera config file %s not found"), fname.c_str()); } else { - cam_cls->conf->process(motapp); + cam_cls->conf_src->process(motapp); } + cam_cls->cfg = new cls_config; + cam_cls->cfg->parms_copy(cam_cls->conf_src); + motapp->cam_list.push_back(cam_cls); motapp->cam_cnt = (int)motapp->cam_list.size(); } @@ -3692,18 +3706,18 @@ void cls_config::sound_filenm(ctx_motapp *motapp) struct stat statbuf; size_t lstpos; - lstpos = motapp->conf->conf_filename.find_last_of("/"); + lstpos = motapp->conf_src->conf_filename.find_last_of("/"); if (lstpos != std::string::npos) { lstpos++; } - dirnm = motapp->conf->conf_filename.substr(0, lstpos); + dirnm = motapp->conf_src->conf_filename.substr(0, lstpos); indx_snd = 1; fullnm = ""; while (fullnm == "") { fullnm = dirnm + "sound" + std::to_string(indx_snd) + ".conf"; for (indx = 0; indxsnd_cnt; indx++) { - if (fullnm == motapp->snd_list[indx]->conf->conf_filename) { + if (fullnm == motapp->snd_list[indx]->conf_src->conf_filename) { fullnm = ""; } } @@ -3728,32 +3742,35 @@ void cls_config::sound_add(ctx_motapp *motapp, std::string fname, bool srcdir) cls_sound *snd_cls; snd_cls = new cls_sound(motapp); - snd_cls->conf = new cls_config; + snd_cls->conf_src = new cls_config; indx = 0; while (config_parms[indx].parm_name != "") { parm_nm =config_parms[indx].parm_name; if (parm_nm != "device_id") { - motapp->conf->edit_get(parm_nm, parm_val, config_parms[indx].parm_cat); - snd_cls->conf->edit_set(parm_nm, parm_val); + motapp->conf_src->edit_get(parm_nm, parm_val, config_parms[indx].parm_cat); + snd_cls->conf_src->edit_set(parm_nm, parm_val); } indx++; } - snd_cls->conf->from_conf_dir = srcdir; - snd_cls->conf->conf_filename = fname; - snd_cls->conf->device_id = get_next_devid(motapp); - snd_cls->device_id = snd_cls->conf->device_id; + snd_cls->conf_src->from_conf_dir = srcdir; + snd_cls->conf_src->conf_filename = fname; + snd_cls->conf_src->device_id = get_next_devid(motapp); + snd_cls->device_id = snd_cls->conf_src->device_id; if (fname == "") { - snd_cls->conf->sound_filenm(motapp); + snd_cls->conf_src->sound_filenm(motapp); } else if (stat(fname.c_str(), &statbuf) != 0) { MOTPLS_LOG(ALR, TYPE_ALL, SHOW_ERRNO ,_("Sound config file %s not found"), fname.c_str()); } else { - snd_cls->conf->process(motapp); + snd_cls->conf_src->process(motapp); } + snd_cls->cfg = new cls_config; + snd_cls->cfg->parms_copy(snd_cls->conf_src); + motapp->snd_list.push_back(snd_cls); motapp->snd_cnt = (int)motapp->snd_list.size(); } @@ -3831,11 +3848,11 @@ void cls_config::process(ctx_motapp *motapp) parm_vl = line.substr(stpos+1, line.length()-stpos); myunquote(parm_nm); myunquote(parm_vl); - if ((parm_nm == "camera") && (motapp->conf == this)) { + if ((parm_nm == "camera") && (motapp->conf_src == this)) { camera_add(motapp, parm_vl, false); - } else if ((parm_nm == "sound") && (motapp->conf == this)) { + } else if ((parm_nm == "sound") && (motapp->conf_src == this)) { sound_add(motapp, parm_vl, false); - } else if ((parm_nm == "config_dir") && (motapp->conf == this)){ + } else if ((parm_nm == "config_dir") && (motapp->conf_src == this)){ config_dir_parm(motapp, parm_vl); } else if ((parm_nm != "camera") && (parm_nm != "sound") && (parm_nm != "config_dir")) { @@ -3892,7 +3909,7 @@ void cls_config::parms_log(ctx_motapp *motapp) ,_("Logging configuration parameters from all files")); MOTPLS_SHT(INF, TYPE_ALL, NO_ERRNO - , _("Config file: %s"), motapp->conf->conf_filename.c_str()); + , _("Config file: %s"), motapp->conf_src->conf_filename.c_str()); i = 0; while (config_parms[i].parm_name != "") { @@ -3903,11 +3920,11 @@ void cls_config::parms_log(ctx_motapp *motapp) if ((parm_nm != "camera") && (parm_nm != "sound") && (parm_nm != "config_dir") && (parm_nm != "conf_filename") && (parm_typ != PARM_TYP_ARRAY)) { - motapp->conf->edit_get(parm_nm,parm_vl, parm_ct); + motapp->conf_src->edit_get(parm_nm,parm_vl, parm_ct); parms_log_parm(parm_nm, parm_vl); } if (parm_typ == PARM_TYP_ARRAY) { - motapp->conf->edit_get(parm_nm, parm_array, parm_ct); + motapp->conf_src->edit_get(parm_nm, parm_array, parm_ct); for (it = parm_array.begin(); it != parm_array.end(); it++) { parms_log_parm(parm_nm, it->c_str()); } @@ -3918,22 +3935,22 @@ void cls_config::parms_log(ctx_motapp *motapp) for (indx=0; indxcam_cnt; indx++) { MOTPLS_SHT(INF, TYPE_ALL, NO_ERRNO , _("Camera config file: %s") - , motapp->cam_list[indx]->conf->conf_filename.c_str()); + , motapp->cam_list[indx]->conf_src->conf_filename.c_str()); i = 0; while (config_parms[i].parm_name != "") { parm_nm=config_parms[i].parm_name; parm_ct=config_parms[i].parm_cat; parm_typ=config_parms[i].parm_type; - motapp->conf->edit_get(parm_nm, parm_main, parm_ct); + motapp->conf_src->edit_get(parm_nm, parm_main, parm_ct); - motapp->cam_list[indx]->conf->edit_get(parm_nm, parm_vl, parm_ct); + motapp->cam_list[indx]->conf_src->edit_get(parm_nm, parm_vl, parm_ct); if ((parm_nm != "camera") && (parm_nm != "sound") && (parm_nm != "config_dir") && (parm_nm != "conf_filename") && (parm_main != parm_vl) && (parm_typ != PARM_TYP_ARRAY) ) { parms_log_parm(parm_nm, parm_vl); } if (parm_typ == PARM_TYP_ARRAY) { - motapp->cam_list[indx]->conf->edit_get(parm_nm, parm_array, parm_ct); + motapp->cam_list[indx]->conf_src->edit_get(parm_nm, parm_array, parm_ct); for (it = parm_array.begin(); it != parm_array.end(); it++) { parms_log_parm(parm_nm, it->c_str()); } @@ -3945,21 +3962,21 @@ void cls_config::parms_log(ctx_motapp *motapp) for (indx=0; indxsnd_cnt; indx++) { MOTPLS_SHT(INF, TYPE_ALL, NO_ERRNO , _("Sound config file: %s") - , motapp->snd_list[indx]->conf->conf_filename.c_str()); + , motapp->snd_list[indx]->conf_src->conf_filename.c_str()); i = 0; while (config_parms[i].parm_name != "") { parm_nm=config_parms[i].parm_name; parm_ct=config_parms[i].parm_cat; parm_typ=config_parms[i].parm_type; - motapp->conf->edit_get(parm_nm, parm_main, parm_ct); - motapp->snd_list[indx]->conf->edit_get(parm_nm, parm_vl, parm_ct); + motapp->conf_src->edit_get(parm_nm, parm_main, parm_ct); + motapp->snd_list[indx]->conf_src->edit_get(parm_nm, parm_vl, parm_ct); if ((parm_nm != "camera") && (parm_nm != "sound") && (parm_nm != "config_dir") && (parm_nm != "conf_filename") && (parm_main != parm_vl) && (parm_typ != PARM_TYP_ARRAY) ) { parms_log_parm(parm_nm, parm_vl); } if (parm_typ == PARM_TYP_ARRAY) { - motapp->snd_list[indx]->conf->edit_get(parm_nm, parm_array, parm_ct); + motapp->snd_list[indx]->conf_src->edit_get(parm_nm, parm_array, parm_ct); for (it = parm_array.begin(); it != parm_array.end(); it++) { parms_log_parm(parm_nm, it->c_str()); } @@ -4008,15 +4025,15 @@ void cls_config::parms_write_app(ctx_motapp *motapp) time_t now = time(0); strftime(timestamp, 32, "%Y-%m-%dT%H:%M:%S", localtime(&now)); - conffile = myfopen(motapp->conf->conf_filename.c_str(), "we"); + conffile = myfopen(motapp->conf_src->conf_filename.c_str(), "we"); if (conffile == NULL) { MOTPLS_LOG(NTC, TYPE_ALL, NO_ERRNO , _("Failed to write configuration to %s") - , motapp->conf->conf_filename.c_str()); + , motapp->conf_src->conf_filename.c_str()); return; } - fprintf(conffile, "; %s\n", motapp->conf->conf_filename.c_str()); + fprintf(conffile, "; %s\n", motapp->conf_src->conf_filename.c_str()); fprintf(conffile, ";\n; This config file was generated by MotionPlus " VERSION "\n"); fprintf(conffile, "; at %s\n", timestamp); fprintf(conffile, "\n\n"); @@ -4031,11 +4048,11 @@ void cls_config::parms_write_app(ctx_motapp *motapp) if ((parm_nm != "camera") && (parm_nm != "sound") && (parm_nm != "config_dir") && (parm_nm != "conf_filename") && (parm_typ != PARM_TYP_ARRAY)) { - motapp->conf->edit_get(parm_nm, parm_vl, parm_ct); + motapp->conf_src->edit_get(parm_nm, parm_vl, parm_ct); parms_write_parms(conffile, parm_nm, parm_vl, parm_ct, false); } if (parm_typ == PARM_TYP_ARRAY) { - motapp->conf->edit_get(parm_nm, parm_array, parm_ct); + motapp->conf_src->edit_get(parm_nm, parm_array, parm_ct); for (it = parm_array.begin(); it != parm_array.end(); it++) { parms_write_parms(conffile, parm_nm, it->c_str(), parm_ct, false); } @@ -4044,24 +4061,24 @@ void cls_config::parms_write_app(ctx_motapp *motapp) } for (indx=0; indxcam_cnt; indx++) { - if (motapp->cam_list[indx]->conf->from_conf_dir == false) { + if (motapp->cam_list[indx]->conf_src->from_conf_dir == false) { parms_write_parms(conffile, "camera" - , motapp->cam_list[indx]->conf->conf_filename + , motapp->cam_list[indx]->conf_src->conf_filename , PARM_CAT_01, false); } } for (indx=0; indxsnd_cnt; indx++) { - if (motapp->snd_list[indx]->conf->from_conf_dir == false) { + if (motapp->snd_list[indx]->conf_src->from_conf_dir == false) { parms_write_parms(conffile, "sound" - , motapp->snd_list[indx]->conf->conf_filename + , motapp->snd_list[indx]->conf_src->conf_filename , PARM_CAT_01, false); } } fprintf(conffile, "\n"); - motapp->conf->edit_get("config_dir", parm_vl, PARM_CAT_01); + motapp->conf_src->edit_get("config_dir", parm_vl, PARM_CAT_01); parms_write_parms(conffile, "config_dir", parm_vl, PARM_CAT_01, false); fprintf(conffile, "\n"); @@ -4069,7 +4086,7 @@ void cls_config::parms_write_app(ctx_motapp *motapp) MOTPLS_LOG(NTC, TYPE_ALL, NO_ERRNO , _("Configuration written to %s") - , motapp->conf->conf_filename.c_str()); + , motapp->conf_src->conf_filename.c_str()); } @@ -4088,14 +4105,14 @@ void cls_config::parms_write_cam(ctx_motapp *motapp) strftime(timestamp, 32, "%Y-%m-%dT%H:%M:%S", localtime(&now)); for (indx=0; indxcam_cnt; indx++) { - conffile = myfopen(motapp->cam_list[indx]->conf->conf_filename.c_str(), "we"); + conffile = myfopen(motapp->cam_list[indx]->conf_src->conf_filename.c_str(), "we"); if (conffile == NULL) { MOTPLS_LOG(NTC, TYPE_ALL, NO_ERRNO , _("Failed to write configuration to %s") - , motapp->cam_list[indx]->conf->conf_filename.c_str()); + , motapp->cam_list[indx]->conf_src->conf_filename.c_str()); return; } - fprintf(conffile, "; %s\n", motapp->cam_list[indx]->conf->conf_filename.c_str()); + fprintf(conffile, "; %s\n", motapp->cam_list[indx]->conf_src->conf_filename.c_str()); fprintf(conffile, ";\n; This config file was generated by MotionPlus " VERSION "\n"); fprintf(conffile, "; at %s\n", timestamp); fprintf(conffile, "\n\n"); @@ -4109,14 +4126,14 @@ void cls_config::parms_write_cam(ctx_motapp *motapp) if ((parm_nm != "camera") && (parm_nm != "sound") && (parm_nm != "config_dir") && (parm_nm != "conf_filename") && (parm_typ != PARM_TYP_ARRAY) ) { - motapp->conf->edit_get(parm_nm, parm_main, parm_ct); - motapp->cam_list[indx]->conf->edit_get(parm_nm, parm_vl, parm_ct); + motapp->conf_src->edit_get(parm_nm, parm_main, parm_ct); + motapp->cam_list[indx]->conf_src->edit_get(parm_nm, parm_vl, parm_ct); if (parm_main != parm_vl) { parms_write_parms(conffile, parm_nm, parm_vl, parm_ct, false); } } if (parm_typ == PARM_TYP_ARRAY) { - motapp->conf->edit_get(parm_nm, parm_array, parm_ct); + motapp->conf_src->edit_get(parm_nm, parm_array, parm_ct); for (it = parm_array.begin(); it != parm_array.end(); it++) { parms_write_parms(conffile, parm_nm, it->c_str(), parm_ct, false); } @@ -4128,7 +4145,7 @@ void cls_config::parms_write_cam(ctx_motapp *motapp) MOTPLS_LOG(NTC, TYPE_ALL, NO_ERRNO , _("Configuration written to %s") - , motapp->cam_list[indx]->conf->conf_filename.c_str()); + , motapp->cam_list[indx]->conf_src->conf_filename.c_str()); } } @@ -4148,14 +4165,14 @@ void cls_config::parms_write_snd(ctx_motapp *motapp) strftime(timestamp, 32, "%Y-%m-%dT%H:%M:%S", localtime(&now)); for (indx=0; indxsnd_cnt; indx++) { - conffile = myfopen(motapp->snd_list[indx]->conf->conf_filename.c_str(), "we"); + conffile = myfopen(motapp->snd_list[indx]->conf_src->conf_filename.c_str(), "we"); if (conffile == NULL) { MOTPLS_LOG(NTC, TYPE_ALL, NO_ERRNO , _("Failed to write configuration to %s") - , motapp->snd_list[indx]->conf->conf_filename.c_str()); + , motapp->snd_list[indx]->conf_src->conf_filename.c_str()); return; } - fprintf(conffile, "; %s\n", motapp->snd_list[indx]->conf->conf_filename.c_str()); + fprintf(conffile, "; %s\n", motapp->snd_list[indx]->conf_src->conf_filename.c_str()); fprintf(conffile, ";\n; This config file was generated by MotionPlus " VERSION "\n"); fprintf(conffile, "; at %s\n", timestamp); fprintf(conffile, "\n\n"); @@ -4169,14 +4186,14 @@ void cls_config::parms_write_snd(ctx_motapp *motapp) if ((parm_nm != "camera") && (parm_nm != "sound") && (parm_nm != "config_dir") && (parm_nm != "conf_filename") && (parm_typ != PARM_TYP_ARRAY)) { - motapp->conf->edit_get(parm_nm, parm_main, parm_ct); - motapp->snd_list[indx]->conf->edit_get(parm_nm, parm_vl, parm_ct); + motapp->conf_src->edit_get(parm_nm, parm_main, parm_ct); + motapp->snd_list[indx]->conf_src->edit_get(parm_nm, parm_vl, parm_ct); if (parm_main != parm_vl) { parms_write_parms(conffile, parm_nm, parm_vl, parm_ct, false); } } if (parm_typ == PARM_TYP_ARRAY) { - motapp->conf->edit_get(parm_nm, parm_array, parm_ct); + motapp->conf_src->edit_get(parm_nm, parm_array, parm_ct); for (it = parm_array.begin(); it != parm_array.end(); ++it) { parms_write_parms(conffile, parm_nm, it->c_str(), parm_ct, false); } @@ -4188,15 +4205,30 @@ void cls_config::parms_write_snd(ctx_motapp *motapp) MOTPLS_LOG(NTC, TYPE_ALL, NO_ERRNO , _("Configuration written to %s") - , motapp->snd_list[indx]->conf->conf_filename.c_str()); + , motapp->snd_list[indx]->conf_src->conf_filename.c_str()); } } + void cls_config::parms_write(ctx_motapp *motapp) { parms_write_app(motapp); parms_write_cam(motapp); parms_write_snd(motapp); +} + +void cls_config::parms_copy(cls_config *src) +{ + int indx; + std::string parm_nm, parm_val; + + indx = 0; + while (config_parms[indx].parm_name != "") { + parm_nm =config_parms[indx].parm_name; + src->edit_get(parm_nm, parm_val, config_parms[indx].parm_cat); + edit_set(parm_nm, parm_val); + indx++; + } } @@ -4212,8 +4244,8 @@ void cls_config::init(ctx_motapp *motapp) cmdline(motapp); filename = ""; - if (motapp->conf->conf_filename != "") { - filename = motapp->conf->conf_filename; + if (motapp->conf_src->conf_filename != "") { + filename = motapp->conf_src->conf_filename; if (stat(filename.c_str(), &statbuf) != 0) { filename=""; } @@ -4252,7 +4284,7 @@ void cls_config::init(ctx_motapp *motapp) edit_set("conf_filename", filename); - motapp->conf->process(motapp); + motapp->conf_src->process(motapp); cmdline(motapp); diff --git a/src/conf.hpp b/src/conf.hpp index fed44082..8fbd991f 100644 --- a/src/conf.hpp +++ b/src/conf.hpp @@ -291,6 +291,7 @@ void init(ctx_motapp *motapp); void parms_log(ctx_motapp *motapp); void parms_write(ctx_motapp *motapp); + void parms_copy(cls_config *src); private: void cmdline(ctx_motapp *motapp); diff --git a/src/dbse.cpp b/src/dbse.cpp index e2e70e68..b48c62c4 100644 --- a/src/dbse.cpp +++ b/src/dbse.cpp @@ -119,27 +119,27 @@ void cls_dbse::sql_motpls(std::string &sql) sql = ""; if (dbse_action == DBSE_TBL_CHECK) { - if (cfg_database_type == "mariadb") { + if (motapp->cfg->database_type == "mariadb") { sql = "Select table_name " " from information_schema.tables " " where table_name = 'motionplus';"; - } else if (cfg_database_type == "postgresql") { + } else if (motapp->cfg->database_type == "postgresql") { sql = " select tablename as table_nm " " from pg_catalog.pg_tables " " where schemaname != 'pg_catalog' " " and schemaname != 'information_schema' " " and tablename = 'motionplus';"; - } else if (cfg_database_type == "sqlite3") { + } else if (motapp->cfg->database_type == "sqlite3") { sql = "select name from sqlite_master" " where type='table' " " and name='motionplus';"; } } else if (dbse_action == DBSE_TBL_CREATE) { sql = "create table motionplus ("; - if ((cfg_database_type == "mariadb") || - (cfg_database_type == "postgresql")) { + if ((motapp->cfg->database_type == "mariadb") || + (motapp->cfg->database_type == "postgresql")) { sql += " record_id serial "; - } else if (cfg_database_type == "sqlite3") { + } else if (motapp->cfg->database_type == "sqlite3") { /* Autoincrement is discouraged but I want compatibility*/ sql += " record_id integer primary key autoincrement "; } @@ -293,26 +293,26 @@ void cls_dbse::sqlite3db_init() database_sqlite3db = nullptr; - if (cfg_database_type != "sqlite3") { + if (motapp->cfg->database_type != "sqlite3") { return; } MOTPLS_LOG(NTC, TYPE_DB, NO_ERRNO , _("SQLite3 Database filename %s") - , cfg_database_dbname.c_str()); + , motapp->cfg->database_dbname.c_str()); retcd = sqlite3_open( - cfg_database_dbname.c_str() + motapp->cfg->database_dbname.c_str() , &database_sqlite3db); if (retcd != SQLITE_OK) { err_open =sqlite3_errmsg(database_sqlite3db); MOTPLS_LOG(ERR, TYPE_DB, NO_ERRNO , _("Can't open database %s : %s") - , cfg_database_dbname.c_str() + , motapp->cfg->database_dbname.c_str() , err_open); sqlite3_close(database_sqlite3db); MOTPLS_LOG(ERR, TYPE_DB, NO_ERRNO , _("Could not initialize database %s") - , cfg_database_dbname.c_str()); + , motapp->cfg->database_dbname.c_str()); is_open = false; database_sqlite3db = nullptr; return; @@ -321,8 +321,8 @@ void cls_dbse::sqlite3db_init() is_open = true; MOTPLS_LOG(NTC, TYPE_DB, NO_ERRNO , _("database_busy_timeout %d msec") - , cfg_database_busy_timeout); - retcd = sqlite3_busy_timeout(database_sqlite3db, cfg_database_busy_timeout); + , motapp->cfg->database_busy_timeout); + retcd = sqlite3_busy_timeout(database_sqlite3db, motapp->cfg->database_busy_timeout); if (retcd != SQLITE_OK) { err_open = sqlite3_errmsg(database_sqlite3db); MOTPLS_LOG(ERR, TYPE_DB, NO_ERRNO @@ -385,7 +385,7 @@ void cls_dbse::sqlite3db_movielist() void cls_dbse::sqlite3db_close() { - if (cfg_database_type == "sqlite3") { + if (motapp->cfg->database_type == "sqlite3") { if (database_sqlite3db != nullptr) { sqlite3_close(database_sqlite3db); database_sqlite3db = nullptr; @@ -560,14 +560,14 @@ void cls_dbse::mariadb_init() database_mariadb = nullptr; - if (cfg_database_type != "mariadb") { + if (motapp->cfg->database_type != "mariadb") { return; } if (mysql_library_init(0, nullptr, nullptr)) { MOTPLS_LOG(ERR, TYPE_DB, NO_ERRNO , _("Could not initialize database %s") - , cfg_database_type.c_str()); + , motapp->cfg->database_type.c_str()); is_open = false; return; } @@ -577,17 +577,17 @@ void cls_dbse::mariadb_init() if (mysql_real_connect( database_mariadb - , cfg_database_host.c_str() - , cfg_database_user.c_str() - , cfg_database_password.c_str() - , cfg_database_dbname.c_str() - , (uint)cfg_database_port, nullptr, 0) == nullptr) { + , motapp->cfg->database_host.c_str() + , motapp->cfg->database_user.c_str() + , motapp->cfg->database_password.c_str() + , motapp->cfg->database_dbname.c_str() + , (uint)motapp->cfg->database_port, nullptr, 0) == nullptr) { MOTPLS_LOG(ERR, TYPE_DB, NO_ERRNO , _("Cannot connect to MariaDB database %s on host %s with user %s") - , cfg_database_dbname.c_str() - , cfg_database_host.c_str() - , cfg_database_user.c_str()); + , motapp->cfg->database_dbname.c_str() + , motapp->cfg->database_host.c_str() + , motapp->cfg->database_user.c_str()); MOTPLS_LOG(ERR, TYPE_DB, NO_ERRNO , _("MariaDB error was %s") , mysql_error(database_mariadb)); @@ -602,12 +602,12 @@ void cls_dbse::mariadb_init() MOTPLS_LOG(INF, TYPE_DB, NO_ERRNO , _("%s database opened") - , cfg_database_dbname.c_str() ); + , motapp->cfg->database_dbname.c_str() ); } void cls_dbse::mariadb_close() { - if (cfg_database_type == "mariadb") { + if (motapp->cfg->database_type == "mariadb") { mysql_library_end(); if (database_mariadb != nullptr) { mysql_close(database_mariadb); @@ -649,13 +649,13 @@ void cls_dbse::pgsqldb_exec(std::string sql) if (PQstatus(database_pgsqldb) == CONNECTION_BAD) { MOTPLS_LOG(ERR, TYPE_DB, NO_ERRNO , _("Connection to PostgreSQL database '%s' failed: %s") - , cfg_database_dbname.c_str() + , motapp->cfg->database_dbname.c_str() , PQerrorMessage(database_pgsqldb)); PQreset(database_pgsqldb); if (PQstatus(database_pgsqldb) == CONNECTION_BAD) { MOTPLS_LOG(ERR, TYPE_DB, NO_ERRNO , _("Re-Connection to PostgreSQL database '%s' failed: %s") - , cfg_database_dbname.c_str() + , motapp->cfg->database_dbname.c_str() , PQerrorMessage(database_pgsqldb)); PQclear(res); dbse_close(); @@ -663,7 +663,7 @@ void cls_dbse::pgsqldb_exec(std::string sql) } else { MOTPLS_LOG(INF, TYPE_DB, NO_ERRNO , _("Re-Connection to PostgreSQL database '%s' Succeed") - , cfg_database_dbname.c_str()); + , motapp->cfg->database_dbname.c_str()); } } else if (!(PQresultStatus(res) == PGRES_COMMAND_OK || PQresultStatus(res) == PGRES_TUPLES_OK)) { MOTPLS_LOG(ERR, TYPE_DB, SHOW_ERRNO @@ -677,7 +677,7 @@ void cls_dbse::pgsqldb_exec(std::string sql) void cls_dbse::pgsqldb_close() { - if (cfg_database_type == "postgresql") { + if (motapp->cfg->database_type == "postgresql") { if (database_pgsqldb != nullptr) { PQfinish(database_pgsqldb); database_pgsqldb = nullptr; @@ -799,20 +799,20 @@ void cls_dbse::pgsqldb_init() database_pgsqldb = nullptr; - if (cfg_database_type != "postgresql") { + if (motapp->cfg->database_type != "postgresql") { return; } - constr = "dbname='" + cfg_database_dbname + "' "; - constr += " host='" + cfg_database_host + "' "; - constr += " user='" + cfg_database_user + "' "; - constr += " password='" + cfg_database_password + "' "; - constr += " port="+std::to_string(cfg_database_port) + " "; + constr = "dbname='" + motapp->cfg->database_dbname + "' "; + constr += " host='" + motapp->cfg->database_host + "' "; + constr += " user='" + motapp->cfg->database_user + "' "; + constr += " password='" + motapp->cfg->database_password + "' "; + constr += " port="+std::to_string(motapp->cfg->database_port) + " "; database_pgsqldb = PQconnectdb(constr.c_str()); if (PQstatus(database_pgsqldb) == CONNECTION_BAD) { MOTPLS_LOG(ERR, TYPE_DB, NO_ERRNO , _("Connection to PostgreSQL database '%s' failed: %s") - , cfg_database_dbname.c_str() + , motapp->cfg->database_dbname.c_str() , PQerrorMessage(database_pgsqldb)); dbse_close(); return; @@ -823,7 +823,7 @@ void cls_dbse::pgsqldb_init() MOTPLS_LOG(INF, TYPE_DB, NO_ERRNO , _("%s database opened") - , cfg_database_dbname.c_str() ); + , motapp->cfg->database_dbname.c_str() ); } void cls_dbse::pgsqldb_movielist() @@ -848,7 +848,7 @@ bool cls_dbse::dbse_open() return true; } - if (cfg_database_type == "") { + if (motapp->cfg->database_type == "") { is_open = false; return false; } @@ -857,17 +857,17 @@ bool cls_dbse::dbse_open() MOTPLS_LOG(DBG, TYPE_DB, NO_ERRNO,_("Opening database")); #ifdef HAVE_MARIADB - if (cfg_database_type == "mariadb") { + if (motapp->cfg->database_type == "mariadb") { mariadb_init(); } #endif #ifdef HAVE_PGSQLDB - if (cfg_database_type == "postgresql") { + if (motapp->cfg->database_type == "postgresql") { pgsqldb_init(); } #endif #ifdef HAVE_SQLITE3DB - if (cfg_database_type == "sqlite3") { + if (motapp->cfg->database_type == "sqlite3") { sqlite3db_init(); } #endif @@ -889,17 +889,17 @@ void cls_dbse::movielist_get(int p_device_id, lst_movies *p_movielist) movielist->clear(); #ifdef HAVE_MARIADB - if (cfg_database_type == "mariadb") { + if (motapp->cfg->database_type == "mariadb") { mariadb_movielist(); } #endif #ifdef HAVE_PGSQLDB - if (cfg_database_type == "postgresql") { + if (motapp->cfg->database_type == "postgresql") { pgsqldb_movielist(); } #endif #ifdef HAVE_SQLITE3DB - if (cfg_database_type == "sqlite3") { + if (motapp->cfg->database_type == "sqlite3") { sqlite3db_movielist(); } #endif @@ -928,17 +928,17 @@ void cls_dbse::exec_sql(std::string sql) pthread_mutex_lock(&mutex_dbse); #ifdef HAVE_MARIADB - if (cfg_database_type == "mariadb") { + if (motapp->cfg->database_type == "mariadb") { mariadb_exec(sql); } #endif #ifdef HAVE_PGSQLDB - if (cfg_database_type == "postgresql") { + if (motapp->cfg->database_type == "postgresql") { pgsqldb_exec(sql); } #endif #ifdef HAVE_SQLITE3DB - if (cfg_database_type == "sqlite3") { + if (motapp->cfg->database_type == "sqlite3") { sqlite3db_exec(sql); } #endif @@ -958,15 +958,15 @@ void cls_dbse::exec(cls_camera *cam, std::string fname, std::string cmd) } if (cmd == "pic_save") { - mystrftime(cam, sql, cam->conf->sql_pic_save, fname); + mystrftime(cam, sql, cam->cfg->sql_pic_save, fname); } else if (cmd == "movie_start") { - mystrftime(cam, sql, cam->conf->sql_movie_start, fname); + mystrftime(cam, sql, cam->cfg->sql_movie_start, fname); } else if (cmd == "movie_end") { - mystrftime(cam, sql, cam->conf->sql_movie_end, fname); + mystrftime(cam, sql, cam->cfg->sql_movie_end, fname); } else if (cmd == "event_start") { - mystrftime(cam, sql, cam->conf->sql_event_start, fname); + mystrftime(cam, sql, cam->cfg->sql_event_start, fname); } else if (cmd == "event_end") { - mystrftime(cam, sql, cam->conf->sql_event_end, fname); + mystrftime(cam, sql, cam->cfg->sql_event_end, fname); } if (sql == "") { @@ -1043,55 +1043,49 @@ void cls_dbse::dbse_edits() { int retcd = 0; - if ((cfg_database_type != "") && - (cfg_database_dbname == "")) { + if ((motapp->cfg->database_type != "") && + (motapp->cfg->database_dbname == "")) { MOTPLS_LOG(ERR, TYPE_DB, NO_ERRNO , _("Invalid database name")); retcd = -1; } - if ((cfg_database_type != "mariadb") && - (cfg_database_type != "postgresql") && - (cfg_database_type != "sqlite3") && - (cfg_database_type != "")) { + if ((motapp->cfg->database_type != "mariadb") && + (motapp->cfg->database_type != "postgresql") && + (motapp->cfg->database_type != "sqlite3") && + (motapp->cfg->database_type != "")) { MOTPLS_LOG(ERR, TYPE_DB, NO_ERRNO ,_("Invalid database_type %s") - , cfg_database_type.c_str()); + , motapp->cfg->database_type.c_str()); retcd = -1; } - if (((cfg_database_type == "mariadb") || - (cfg_database_type == "postgresql")) && - (cfg_database_port == 0)) { + if (((motapp->cfg->database_type == "mariadb") || + (motapp->cfg->database_type == "postgresql")) && + (motapp->cfg->database_port == 0)) { MOTPLS_LOG(ERR, TYPE_DB, NO_ERRNO ,_("Must specify database port for mariadb/pgsql")); retcd = -1; } - if ((cfg_database_type == "sqlite3") && - (cfg_database_dbname == "")) { + if ((motapp->cfg->database_type == "sqlite3") && + (motapp->cfg->database_dbname == "")) { MOTPLS_LOG(ERR, TYPE_DB, NO_ERRNO ,_("Must specify database name for sqlite3")); retcd = -1; } - if ((cfg_database_type != "") && (retcd == -1)) { + if ((motapp->cfg->database_type != "") && (retcd == -1)) { MOTPLS_LOG(ERR, TYPE_DB, NO_ERRNO ,_("Database functionality disabled.")); - cfg_database_type = ""; + motapp->cfg->database_type = ""; } } cls_dbse::cls_dbse(ctx_motapp *p_motapp) { - cfg_database_busy_timeout = p_motapp->conf->database_busy_timeout; - cfg_database_dbname = p_motapp->conf->database_dbname; - cfg_database_host = p_motapp->conf->database_host; - cfg_database_password = p_motapp->conf->database_password; - cfg_database_port = p_motapp->conf->database_port; - cfg_database_type = p_motapp->conf->database_type; - cfg_database_user = p_motapp->conf->database_user; + motapp = p_motapp; is_open = false; diff --git a/src/dbse.hpp b/src/dbse.hpp index dcd31235..45bd1b07 100644 --- a/src/dbse.hpp +++ b/src/dbse.hpp @@ -89,16 +89,7 @@ void pgsqldb_init(); void pgsqldb_movielist(); #endif - - std::string cfg_database_type; - std::string cfg_database_dbname; - std::string cfg_database_host; - std::string cfg_database_user; - std::string cfg_database_password; - - int cfg_database_port; - int cfg_database_busy_timeout; - + ctx_motapp *motapp; enum DBSE_ACT dbse_action; /* action to perform with query*/ bool table_ok; /* bool of whether table exists*/ bool is_open; diff --git a/src/draw.cpp b/src/draw.cpp index aa14d9b7..d8fee81d 100644 --- a/src/draw.cpp +++ b/src/draw.cpp @@ -1215,7 +1215,7 @@ void cls_draw::init_chars(void) void cls_draw::init_scale() { - cam->text_scale = cfg_text_scale; + cam->text_scale = cam->cfg->text_scale; if (cam->text_scale <= 0) { cam->text_scale = 1; } @@ -1239,7 +1239,7 @@ void cls_draw::init_scale() } /* If we had to modify the scale, change conf so we don't get another message */ - cfg_text_scale = cam->text_scale; + cam->cfg->text_scale = cam->text_scale; } @@ -1271,7 +1271,7 @@ void cls_draw::location(ctx_coord *cent, ctx_images *imgs out[width_maxx_y] =~out[width_maxx_y]; } - if (cfg_locate_motion_style == "box") { + if (cam->cfg->locate_motion_style == "box") { width_miny = width * cent->miny; width_maxy = width * cent->maxy; @@ -1288,7 +1288,7 @@ void cls_draw::location(ctx_coord *cent, ctx_images *imgs new_var[width_minx_y] =~new_var[width_minx_y]; new_var[width_maxx_y] =~new_var[width_maxx_y]; } - } else if (cfg_locate_motion_style == "cross") { + } else if (cam->cfg->locate_motion_style == "cross") { centy = cent->y * width; for (x = cent->x - 10; x <= cent->x + 10; x++) { new_var[centy + x] =~new_var[centy + x]; @@ -1340,7 +1340,7 @@ void cls_draw::red_location(ctx_coord *cent out[width_maxx_y] =~out[width_maxx_y]; } - if (cfg_locate_motion_style == "redbox") { + if (cam->cfg->locate_motion_style == "redbox") { width_miny = width * cent->miny; width_maxy = width * cent->maxy; cwidth_miny = cwidth * (cent->miny / 2); @@ -1393,7 +1393,7 @@ void cls_draw::red_location(ctx_coord *cent new_var[width_minx_y + width + 1] = 128; new_var[width_maxx_y + width + 1] = 128; } - } else if (cfg_locate_motion_style == "redcross") { + } else if (cam->cfg->locate_motion_style == "redcross") { cwidth_maxy = cwidth * (cent->y / 2); for (x = cent->x - 10; x <= cent->x + 10; x += 2) { @@ -1416,11 +1416,11 @@ void cls_draw::locate() ctx_coord *p_loc; u_char *image_norm; - if (cfg_locate_motion_mode == "preview") { + if (cam->cfg->locate_motion_mode == "preview") { imgs = &cam->imgs; p_loc = &cam->imgs.image_preview.location; image_norm = cam->imgs.image_preview.image_norm; - } else if (cfg_locate_motion_mode == "on") { + } else if (cam->cfg->locate_motion_mode == "on") { imgs = &cam->imgs; p_loc = &cam->current_image->location; image_norm = cam->current_image->image_norm; @@ -1428,11 +1428,11 @@ void cls_draw::locate() return; } - if ((cfg_locate_motion_style == "box") || - (cfg_locate_motion_style == "cross")) { + if ((cam->cfg->locate_motion_style == "box") || + (cam->cfg->locate_motion_style == "cross")) { location(p_loc, imgs, imgs->width, image_norm); - } else if ((cfg_locate_motion_style == "redbox")|| - (cfg_locate_motion_style == "redcross")) { + } else if ((cam->cfg->locate_motion_style == "redbox")|| + (cam->cfg->locate_motion_style == "redcross")) { red_location(p_loc, imgs, imgs->width, image_norm); } @@ -1561,10 +1561,6 @@ void cls_draw::largest_label() cls_draw::cls_draw(cls_camera *p_cam) { cam = p_cam; - cfg_text_scale = cam->conf->text_scale; - cfg_locate_motion_mode = cam->conf->locate_motion_mode; - cfg_locate_motion_style = cam->conf->locate_motion_style; - init_chars(); init_scale(); diff --git a/src/draw.hpp b/src/draw.hpp index 0f4b9121..178fe855 100644 --- a/src/draw.hpp +++ b/src/draw.hpp @@ -38,10 +38,6 @@ u_char *char_arr_ptr[ASCII_MAX]; - int cfg_text_scale; - std::string cfg_locate_motion_mode; - std::string cfg_locate_motion_style; - int textn(u_char *image , int startx, int starty, int width , const char *text, int len, int factor); diff --git a/src/jpegutils.cpp b/src/jpegutils.cpp index 490cebcb..b7d80884 100644 --- a/src/jpegutils.cpp +++ b/src/jpegutils.cpp @@ -209,10 +209,10 @@ void jpgutl_exif_date(ctx_exif_info *exif_info) exif_info->subtime = nullptr; - if (exif_info->cam->conf->picture_exif != "") { + if (exif_info->cam->cfg->picture_exif != "") { exif_info->description =(char*)mymalloc(PATH_MAX); mystrftime(exif_info->cam, exif_info->description, PATH_MAX-1 - , exif_info->cam->conf->picture_exif.c_str(), NULL); + , exif_info->cam->cfg->picture_exif.c_str(), NULL); } else { exif_info->description = nullptr; } diff --git a/src/libcam.cpp b/src/libcam.cpp index 6c79c278..a15caa22 100644 --- a/src/libcam.cpp +++ b/src/libcam.cpp @@ -216,7 +216,7 @@ void cls_libcam::start_params() params = new ctx_params; params->update_params = true; - util_parms_parse(params,"libcam_params", conf_libcam_params); + util_parms_parse(params,"libcam_params", cam->cfg->libcam_params); lst = ¶ms->params_array; @@ -244,7 +244,7 @@ int cls_libcam::start_mgr() MOTPLS_LOG(NTC, TYPE_VIDEO, NO_ERRNO, "cam_mgr started."); - if (conf_libcam_device == "camera0"){ + if (cam->cfg->libcam_device == "camera0"){ if (cam_mgr->cameras().size() == 0) { MOTPLS_LOG(ERR, TYPE_VIDEO, NO_ERRNO , "No camera devices found"); @@ -254,7 +254,7 @@ int cls_libcam::start_mgr() } else { MOTPLS_LOG(ERR, TYPE_VIDEO, NO_ERRNO , "Invalid libcam_device '%s'. The only name supported is 'camera0' " - ,conf_libcam_device.c_str()); + ,cam->cfg->libcam_device.c_str()); return -1; } camera = cam_mgr->get(camid); @@ -550,8 +550,8 @@ int cls_libcam::start_config() config->at(0).pixelFormat = PixelFormat::fromString("YUV420"); - config->at(0).size.width = (uint)conf_width; - config->at(0).size.height = (uint)conf_height; + config->at(0).size.width = (uint)cam->cfg->width; + config->at(0).size.height = (uint)cam->cfg->height; config->at(0).bufferCount = 1; config->at(0).stride = 0; @@ -575,11 +575,11 @@ int cls_libcam::start_config() return -1; } - if ((config->at(0).size.width != (unsigned int)conf_width) || - (config->at(0).size.height != (unsigned int)conf_height)) { + if ((config->at(0).size.width != (uint)cam->cfg->width) || + (config->at(0).size.height != (uint)cam->cfg->height)) { MOTPLS_LOG(NTC, TYPE_VIDEO, NO_ERRNO , "Image size adjusted from %d x %d to %d x %d" - , conf_width, conf_height + , cam->cfg->width, cam->cfg->height , config->at(0).size.width, config->at(0).size.height); } @@ -830,11 +830,6 @@ cls_libcam::cls_libcam(cls_camera *p_cam) MOTPLS_LOG(NTC, TYPE_VIDEO, NO_ERRNO,_("Opening libcam")); cam = p_cam; params = nullptr; - conf_libcam_params = cam->conf->libcam_params; - conf_libcam_device = cam->conf->libcam_device; - conf_width = cam->conf->width; - conf_height = cam->conf->height; - if (libcam_start() < 0) { MOTPLS_LOG(ERR, TYPE_VIDEO, NO_ERRNO,_("libcam failed to open")); diff --git a/src/libcam.hpp b/src/libcam.hpp index df1d35ae..d38d7047 100644 --- a/src/libcam.hpp +++ b/src/libcam.hpp @@ -37,7 +37,7 @@ ~cls_libcam(); int next(ctx_image_data *img_data); private: - cls_camera *cam; + cls_camera *cam; ctx_params *params; std::unique_ptr cam_mgr; @@ -54,11 +54,6 @@ bool started_aqr; bool started_req; - std::string conf_libcam_params; - std::string conf_libcam_device; - int conf_width; - int conf_height; - void log_orientation(); void log_controls(); void log_draft(); diff --git a/src/motionplus.cpp b/src/motionplus.cpp index 5bb8bd43..5b25d909 100644 --- a/src/motionplus.cpp +++ b/src/motionplus.cpp @@ -154,18 +154,18 @@ static void motpls_pid_write(ctx_motapp *motapp) { FILE *pidf = NULL; - if (motapp->conf->pid_file != "") { - pidf = myfopen(motapp->conf->pid_file.c_str(), "w+e"); + if (motapp->cfg->pid_file != "") { + pidf = myfopen(motapp->cfg->pid_file.c_str(), "w+e"); if (pidf) { (void)fprintf(pidf, "%d\n", getpid()); myfclose(pidf); MOTPLS_LOG(NTC, TYPE_ALL, NO_ERRNO ,_("Created process id file %s. Process ID is %d") - ,motapp->conf->pid_file.c_str(), getpid()); + ,motapp->cfg->pid_file.c_str(), getpid()); } else { MOTPLS_LOG(EMG, TYPE_ALL, SHOW_ERRNO , _("Cannot create process id file (pid file) %s") - , motapp->conf->pid_file.c_str()); + , motapp->cfg->pid_file.c_str()); } } @@ -176,9 +176,9 @@ static void motpls_pid_write(ctx_motapp *motapp) /** Remove the process id file ( pid file ) before MotionPlus exit. */ static void motpls_pid_remove(ctx_motapp *motapp) { - if ((motapp->conf->pid_file != "") && + if ((motapp->cfg->pid_file != "") && (motapp->reload_all == false)) { - if (!unlink(motapp->conf->pid_file.c_str())) { + if (!unlink(motapp->cfg->pid_file.c_str())) { MOTPLS_LOG(NTC, TYPE_ALL, NO_ERRNO, _("Removed process id file (pid file).")); } else{ MOTPLS_LOG(ERR, TYPE_ALL, SHOW_ERRNO, _("Error removing pid file")); @@ -294,12 +294,12 @@ static void motpls_allcams_init(ctx_motapp *motapp) motapp->cam_list[indx]->all_loc.offset_user_col = 0; motapp->cam_list[indx]->all_loc.offset_user_row = 0; motapp->cam_list[indx]->all_loc.scale = - motapp->cam_list[indx]->conf->stream_preview_scale; + motapp->cam_list[indx]->cfg->stream_preview_scale; params_loc->update_params = true; util_parms_parse(params_loc , "stream_preview_location" - , motapp->cam_list[indx]->conf->stream_preview_location); + , motapp->cam_list[indx]->cfg->stream_preview_location); lst = ¶ms_loc->params_array; for (it = lst->begin(); it != lst->end(); it++) { @@ -340,7 +340,7 @@ static void motpls_allcams_init(ctx_motapp *motapp) cfg_valid = false; MOTPLS_LOG(NTC, TYPE_ALL, NO_ERRNO , "No stream_preview_location for cam %d" - , motapp->cam_list[indx]->conf->device_id); + , motapp->cam_list[indx]->cfg->device_id); } else { for (indx1=0; indx1cam_cnt; indx1++) { if ((motapp->cam_list[indx]->all_loc.col == @@ -351,8 +351,8 @@ static void motpls_allcams_init(ctx_motapp *motapp) MOTPLS_LOG(NTC, TYPE_ALL, NO_ERRNO , "Duplicate stream_preview_location " " cam %d, cam %d row %d col %d" - , motapp->cam_list[indx]->conf->device_id - , motapp->cam_list[indx1]->conf->device_id + , motapp->cam_list[indx]->cfg->device_id + , motapp->cam_list[indx1]->cfg->device_id , motapp->cam_list[indx]->all_loc.row , motapp->cam_list[indx]->all_loc.col); cfg_valid = false; @@ -362,14 +362,14 @@ static void motpls_allcams_init(ctx_motapp *motapp) if (motapp->cam_list[indx]->all_loc.row == 0) { MOTPLS_LOG(NTC, TYPE_ALL, NO_ERRNO , "Invalid stream_preview_location row cam %d, row %d" - , motapp->cam_list[indx]->conf->device_id + , motapp->cam_list[indx]->cfg->device_id , motapp->cam_list[indx]->all_loc.row); cfg_valid = false; } if (motapp->cam_list[indx]->all_loc.col == 0) { MOTPLS_LOG(NTC, TYPE_ALL, NO_ERRNO , "Invalid stream_preview_location col cam %d, col %d" - , motapp->cam_list[indx]->conf->device_id + , motapp->cam_list[indx]->cfg->device_id , motapp->cam_list[indx]->all_loc.col); cfg_valid = false; } @@ -441,15 +441,15 @@ static void motpls_device_ids(ctx_motapp *motapp) /* Defaults */ for (indx=0; indxcam_cnt; indx++) { - if (motapp->cam_list[indx]->conf->device_id != 0) { - motapp->cam_list[indx]->device_id = motapp->cam_list[indx]->conf->device_id; + if (motapp->cam_list[indx]->cfg->device_id != 0) { + motapp->cam_list[indx]->device_id = motapp->cam_list[indx]->cfg->device_id; } else { motapp->cam_list[indx]->device_id = (int)indx + 1; } } for (indx=0; indxsnd_cnt; indx++) { - if (motapp->snd_list[indx]->conf->device_id != 0) { - motapp->snd_list[indx]->device_id = motapp->snd_list[indx]->conf->device_id; + if (motapp->snd_list[indx]->cfg->device_id != 0) { + motapp->snd_list[indx]->device_id = motapp->snd_list[indx]->cfg->device_id; } else { motapp->snd_list[indx]->device_id = (int)(motapp->cam_cnt + indx + 1); } @@ -656,7 +656,8 @@ static void motpls_init(ctx_motapp *motapp, int argc, char *argv[]) motapp->cam_delete = -1; motapp->cam_cnt = 0; motapp->snd_cnt = 0; - motapp->conf = nullptr; + motapp->conf_src = nullptr; + motapp->cfg = nullptr; motapp->dbse = nullptr; motapp->webu = nullptr; @@ -665,23 +666,26 @@ static void motpls_init(ctx_motapp *motapp, int argc, char *argv[]) pthread_mutex_init(&motapp->mutex_camlst, NULL); pthread_mutex_init(&motapp->mutex_post, NULL); - motapp->conf = new cls_config; - motapp->conf->init(motapp); + motapp->conf_src = new cls_config; + motapp->conf_src->init(motapp); - motlog->log_level = motapp->conf->log_level; - motlog->log_fflevel = motapp->conf->log_fflevel; - motlog->set_log_file(motapp->conf->log_file); + motapp->cfg = new cls_config; + motapp->cfg->parms_copy(motapp->conf_src); + + motlog->log_level = motapp->cfg->log_level; + motlog->log_fflevel = motapp->cfg->log_fflevel; + motlog->set_log_file(motapp->cfg->log_file); mytranslate_init(); - mytranslate_text("",motapp->conf->native_language); + mytranslate_text("",motapp->cfg->native_language); - if (motapp->conf->daemon) { + if (motapp->cfg->daemon) { motpls_daemon(); MOTPLS_LOG(NTC, TYPE_ALL, NO_ERRNO, _("MotionPlus running as daemon process")); } - motapp->conf->parms_log(motapp); + motapp->cfg->parms_log(motapp); motpls_pid_write(motapp); @@ -721,7 +725,8 @@ static void motpls_deinit(ctx_motapp *motapp) mydelete(motapp->webu); mydelete(motapp->dbse); - mydelete(motapp->conf); + mydelete(motapp->conf_src); + mydelete(motapp->cfg); mydelete(motapp->all_sizes); for (indx = 0; indx < motapp->cam_cnt;indx++) { @@ -746,7 +751,7 @@ static void motpls_cam_add(ctx_motapp *motapp) } pthread_mutex_lock(&motapp->mutex_camlst); - motapp->conf->camera_add(motapp, "", false); + motapp->cfg->camera_add(motapp, "", false); pthread_mutex_unlock(&motapp->mutex_camlst); motapp->cam_add = false; @@ -773,7 +778,7 @@ static void motpls_cam_delete(ctx_motapp *motapp) cam = motapp->cam_list[motapp->cam_delete]; MOTPLS_LOG(NTC, TYPE_STREAM, NO_ERRNO, _("Stopping %s device_id %d") - , cam->conf->device_name.c_str(), cam->device_id); + , cam->cfg->device_name.c_str(), cam->device_id); cam->stop(); diff --git a/src/motionplus.hpp b/src/motionplus.hpp index 3ce91217..4926692e 100644 --- a/src/motionplus.hpp +++ b/src/motionplus.hpp @@ -302,7 +302,8 @@ struct ctx_motapp { char **argv; bool pause; - cls_config *conf; + cls_config *conf_src; + cls_config *cfg; ctx_all_sizes *all_sizes; cls_webu *webu; cls_dbse *dbse; diff --git a/src/movie.cpp b/src/movie.cpp index 0ff67257..939ddc6d 100644 --- a/src/movie.cpp +++ b/src/movie.cpp @@ -283,7 +283,7 @@ int cls_movie::set_quality() int quality; opts = 0; - quality = conf_movie_quality; + quality = cam->cfg->movie_quality; if (quality > 100) { quality = 100; } @@ -418,7 +418,7 @@ int cls_movie::set_codec() ctx_codec->codec_id = codec->id; ctx_codec->codec_type = AVMEDIA_TYPE_VIDEO; - ctx_codec->bit_rate = conf_movie_bps; + ctx_codec->bit_rate = cam->cfg->movie_bps; ctx_codec->width = width; ctx_codec->height = height; ctx_codec->time_base.num = 1; @@ -562,9 +562,9 @@ int cls_movie::set_picture() return -1; } - if (conf_movie_quality) { + if (cam->cfg->movie_quality) { picture->quality = (int)(FF_LAMBDA_MAX * - (float)((100-conf_movie_quality)/100))+1; + (float)((100-cam->cfg->movie_quality)/100))+1; } picture->linesize[0] = ctx_codec->width; @@ -1163,16 +1163,16 @@ void cls_movie::put_pix_yuv420(ctx_image_data *img_data) void cls_movie::on_movie_start() { MOTPLS_LOG(DBG, TYPE_EVENTS, NO_ERRNO, _("Creating movie: %s"),full_nm.c_str()); - if (conf_on_movie_start != "") { - util_exec_command(cam, conf_on_movie_start.c_str(), full_nm.c_str()); + if (cam->cfg->on_movie_start != "") { + util_exec_command(cam, cam->cfg->on_movie_start.c_str(), full_nm.c_str()); } } void cls_movie::on_movie_end() { MOTPLS_LOG(DBG, TYPE_EVENTS, NO_ERRNO, _("Finished movie: %s"),full_nm.c_str()); - if (conf_on_movie_end != "") { - util_exec_command(cam, conf_on_movie_end.c_str(), full_nm.c_str()); + if (cam->cfg->on_movie_end != "") { + util_exec_command(cam, cam->cfg->on_movie_end.c_str(), full_nm.c_str()); } } @@ -1273,7 +1273,7 @@ void cls_movie::stop() cam->filetype = FTYPE_MOVIE; on_movie_end(); cam->motapp->dbse->exec(cam, full_nm, "movie_end"); - if ((conf_movie_retain == "secondary") && + if ((cam->cfg->movie_retain == "secondary") && (cam->algsec->detected == false) && (cam->algsec->method != "none")) { if (remove(full_nm.c_str()) != 0) { @@ -1401,7 +1401,7 @@ void cls_movie::init_container() int codenbr; size_t col_pos; - if (conf_container == "test") { + if (cam->cfg->movie_container == "test") { MOTPLS_LOG(NTC, TYPE_ENCODER, NO_ERRNO, "Running test of the various output formats."); codenbr = cam->event_curr_nbr % 10; if (codenbr == 1) { @@ -1426,7 +1426,7 @@ void cls_movie::init_container() container = "mkv"; } } else { - container = conf_container; + container = cam->cfg->movie_container; } col_pos = container.find(":"); @@ -1443,17 +1443,17 @@ void cls_movie::start_norm() { char tmp[PATH_MAX]; - if (conf_movie_output == false) { + if (cam->cfg->movie_output == false) { is_running = false; return; } init_container(); - mystrftime(cam, tmp, sizeof(tmp), conf_movie_filename.c_str(), nullptr); + mystrftime(cam, tmp, sizeof(tmp), cam->cfg->movie_filename.c_str(), nullptr); movie_nm = tmp; - movie_dir = conf_target_dir; + movie_dir = cam->cfg->target_dir; if (container =="test") { full_nm = movie_dir + "/" + container + "_" + movie_nm; } else { @@ -1480,7 +1480,7 @@ void cls_movie::start_norm() base_pts = 0; gop_cnt = 0; - if (conf_container == "test") { + if (cam->cfg->movie_container == "test") { test_mode = true; } else { test_mode = false; @@ -1509,7 +1509,7 @@ void cls_movie::start_motion() char tmp[PATH_MAX]; ctx_image_data save_data; - if (conf_movie_output_motion == false) { + if (cam->cfg->movie_output_motion == false) { is_running = false; return; } @@ -1519,11 +1519,11 @@ void cls_movie::start_motion() memcpy(&save_data, cam->current_image, sizeof(ctx_image_data)); memcpy(cam->current_image, &cam->imgs.image_motion, sizeof(ctx_image_data)); mystrftime(cam, tmp, sizeof(tmp) - , conf_movie_filename.c_str(), nullptr); + , cam->cfg->movie_filename.c_str(), nullptr); memcpy(cam->current_image, &save_data, sizeof(ctx_image_data)); movie_nm.assign(tmp).append("m"); - movie_dir = conf_target_dir; + movie_dir = cam->cfg->target_dir; if (container =="test") { full_nm = movie_dir + "/" + container + "_" + movie_nm; } else { @@ -1567,10 +1567,10 @@ void cls_movie::start_timelapse() { char tmp[PATH_MAX]; - mystrftime(cam, tmp, sizeof(tmp), conf_timelapse_filename.c_str(), nullptr); + mystrftime(cam, tmp, sizeof(tmp), cam->cfg->timelapse_filename.c_str(), nullptr); movie_nm = tmp; - movie_dir = conf_target_dir.c_str(); + movie_dir = cam->cfg->target_dir.c_str(); full_nm = movie_dir + "/" + movie_nm; if ((cam->imgs.size_high > 0) && (cam->movie_passthrough == false)) { @@ -1583,7 +1583,7 @@ void cls_movie::start_timelapse() high_resolution = false; } pkt = nullptr; - fps = conf_timelapse_fps; + fps = cam->cfg->timelapse_fps; start_time.tv_sec = cam->current_image->imgts.tv_sec; start_time.tv_nsec = cam->current_image->imgts.tv_nsec; last_pts = -1; @@ -1594,7 +1594,7 @@ void cls_movie::start_timelapse() passthrough = false; netcam_data = nullptr; - if (conf_timelapse_container == "mpg") { + if (cam->cfg->timelapse_container == "mpg") { MOTPLS_LOG(NTC, TYPE_EVENTS, NO_ERRNO, _("Timelapse using mpg container.")); MOTPLS_LOG(NTC, TYPE_EVENTS, NO_ERRNO, _("Events will be appended to file")); tlapse = TIMELAPSE_APPEND; @@ -1623,17 +1623,17 @@ void cls_movie::start_extpipe() { char tmp[PATH_MAX]; - if (conf_movie_extpipe_use == false) { + if (cam->cfg->movie_extpipe_use == false) { is_running = false; return; } - mystrftime(cam, tmp, sizeof(tmp), conf_movie_filename.c_str(), nullptr); + mystrftime(cam, tmp, sizeof(tmp), cam->cfg->movie_filename.c_str(), nullptr); movie_nm = tmp; - movie_dir = conf_target_dir; + movie_dir = cam->cfg->target_dir; - if (conf_movie_output) { + if (cam->cfg->movie_output) { MOTPLS_LOG(NTC, TYPE_STREAM, NO_ERRNO , _("Requested extpipe in addition to movie_output.")); MOTPLS_LOG(NTC, TYPE_STREAM, NO_ERRNO @@ -1650,7 +1650,7 @@ void cls_movie::start_extpipe() memset(&tmp,0,PATH_MAX); mystrftime(cam, tmp, sizeof(tmp) - , conf_movie_extpipe.c_str(), full_nm.c_str()); + , cam->cfg->movie_extpipe.c_str(), full_nm.c_str()); MOTPLS_LOG(NTC, TYPE_EVENTS, NO_ERRNO, _("extpipe cmd: %s"), tmp); @@ -1684,27 +1684,6 @@ void cls_movie::start() } } -void cls_movie::init_conf() -{ - /* copy conf parms so we do not conflict with web updates*/ - conf_container = cam->conf->movie_container; - conf_target_dir = cam->conf->target_dir; - conf_movie_filename = cam->conf->movie_filename; - conf_timelapse_filename = cam->conf->timelapse_filename; - conf_timelapse_container = cam->conf->timelapse_container; - conf_movie_quality = cam->conf->movie_quality; - conf_movie_bps = cam->conf->movie_bps; - conf_timelapse_fps = cam->conf->timelapse_fps; - conf_movie_output = cam->conf->movie_output; - conf_movie_output_motion = cam->conf->movie_output_motion; - conf_movie_extpipe_use = cam->conf->movie_extpipe_use; - conf_movie_extpipe = cam->conf->movie_extpipe; - conf_movie_retain = cam->conf->movie_retain; - conf_on_movie_start = cam->conf->on_movie_start; - conf_on_movie_end = cam->conf->on_movie_end; - -} - void cls_movie::init_vars() { cb_st_ts.tv_nsec = 0; @@ -1756,8 +1735,6 @@ cls_movie::cls_movie(cls_camera *p_cam, std::string pmovie_type) movie_type = pmovie_type; - init_conf(); - init_vars(); } diff --git a/src/movie.hpp b/src/movie.hpp index 978296fe..1403ddd7 100644 --- a/src/movie.hpp +++ b/src/movie.hpp @@ -62,7 +62,6 @@ class cls_movie { int movie_open(); void init_container(); void init_vars(); - void init_conf(); void passthru_reset(); int passthru_pktpts(); @@ -114,22 +113,6 @@ class cls_movie { std::string preferred_codec; std::string movie_type; - std::string conf_container; - std::string conf_target_dir; - std::string conf_movie_filename; - std::string conf_timelapse_filename; - std::string conf_timelapse_container; - int conf_movie_quality; - int conf_movie_bps; - int conf_timelapse_fps; - bool conf_movie_output; - bool conf_movie_output_motion; - bool conf_movie_extpipe_use; - std::string conf_movie_extpipe; - std::string conf_movie_retain; - std::string conf_on_movie_start; - std::string conf_on_movie_end; - }; #endif /* #define _INCLUDE_MOVIE_HPP_ */ diff --git a/src/netcam.cpp b/src/netcam.cpp index 433fb078..36be606d 100644 --- a/src/netcam.cpp +++ b/src/netcam.cpp @@ -1572,13 +1572,13 @@ void cls_netcam::set_path () path = ""; if (high_resolution) { - url_parse(&url, cam->conf->netcam_high_url); + url_parse(&url, cam->cfg->netcam_high_url); } else { - url_parse(&url, cam->conf->netcam_url); + url_parse(&url, cam->cfg->netcam_url); } - if (cam->conf->netcam_userpass != "") { - url.userpass = cam->conf->netcam_userpass; + if (cam->cfg->netcam_userpass != "") { + url.userpass = cam->cfg->netcam_userpass; } if (url.service == "v4l2") { @@ -1620,9 +1620,9 @@ void cls_netcam::set_parms () context_null(); threadnbr = cam->device_id; - cfg_width = cam->conf->width; - cfg_height = cam->conf->height; - cfg_framerate = cam->conf->framerate; + cfg_width = cam->cfg->width; + cfg_height = cam->cfg->height; + cfg_framerate = cam->cfg->framerate; cam->imgs.width = cfg_width; cam->imgs.height = cfg_height; @@ -1637,7 +1637,7 @@ void cls_netcam::set_parms () imgsize.width = 0; imgsize.height = 0; cameratype = _("High"); - cfg_params = cam->conf->netcam_high_params; + cfg_params = cam->cfg->netcam_high_params; params->update_params = true; util_parms_parse(params ,"netcam_high_params", cfg_params); @@ -1645,12 +1645,12 @@ void cls_netcam::set_parms () imgsize.width = cfg_width; imgsize.height = cfg_height; cameratype = _("Norm"); - cfg_params = cam->conf->netcam_params; + cfg_params = cam->cfg->netcam_params; params->update_params = true; util_parms_parse(params ,"netcam_params", cfg_params); } - camera_name = cam->conf->device_name; + camera_name = cam->cfg->device_name; MOTPLS_LOG(INF, TYPE_NETCAM, NO_ERRNO , _("%s:Setting up camera(%s).") @@ -1704,7 +1704,7 @@ void cls_netcam::set_parms () /* If this is the norm and we have a highres, then disable passthru on the norm */ if ((high_resolution == false) && - (cam->conf->netcam_high_url != "")) { + (cam->cfg->netcam_high_url != "")) { passthrough = false; } else { passthrough = cam->movie_passthrough; diff --git a/src/picture.cpp b/src/picture.cpp index 7b2319c0..911dd5f0 100644 --- a/src/picture.cpp +++ b/src/picture.cpp @@ -36,7 +36,7 @@ void cls_picture::picname(char* fullname, std::string fmtstr mystrftime(cam, filename, sizeof(filename) , basename.c_str(), NULL); retcd = snprintf(fullname, PATH_MAX, fmtstr.c_str() - , cfg_target_dir.c_str(), filename, extname.c_str()); + , cam->cfg->target_dir.c_str(), filename, extname.c_str()); if ((retcd < 0) || (retcd >= PATH_MAX)) { MOTPLS_LOG(ERR, TYPE_EVENTS, NO_ERRNO ,_("Error creating picture file name")); @@ -48,8 +48,8 @@ void cls_picture::on_picture_save_command(char *fname) { MOTPLS_LOG(NTC, TYPE_EVENTS, NO_ERRNO, _("File saved to: %s"), fname); - if (cfg_on_picture_save != "") { - util_exec_command(cam, cfg_on_picture_save.c_str(), fname); + if (cam->cfg->on_picture_save != "") { + util_exec_command(cam, cam->cfg->on_picture_save.c_str(), fname); } } @@ -57,10 +57,10 @@ void cls_picture::process_norm() { char filename[PATH_MAX]; - if (cfg_picture_output == "on") { + if (cam->cfg->picture_output == "on") { picname(filename,"%s/%s.%s" - , cfg_picture_filename - , cfg_picture_type); + , cam->cfg->picture_filename + , cam->cfg->picture_type); cam->filetype = FTYPE_IMAGE; if ((cam->imgs.size_high > 0) && (cam->movie_passthrough == false)) { save_norm(filename, cam->current_image->image_high); @@ -76,15 +76,15 @@ void cls_picture::process_motion() { char filename[PATH_MAX]; - if (cfg_picture_output_motion == "on") { - picname(filename,"%s/%sm.%s", cfg_picture_filename, cfg_picture_type); + if (cam->cfg->picture_output_motion == "on") { + picname(filename,"%s/%sm.%s", cam->cfg->picture_filename, cam->cfg->picture_type); cam->filetype = FTYPE_IMAGE_MOTION; save_norm(filename, cam->imgs.image_motion.image_norm); on_picture_save_command(filename); cam->motapp->dbse->exec(cam, filename, "pic_save"); - } else if (cfg_picture_output_motion == "roi") { - picname(filename,"%s/%sr.%s", cfg_picture_filename, cfg_picture_type); + } else if (cam->cfg->picture_output_motion == "roi") { + picname(filename,"%s/%sr.%s", cam->cfg->picture_filename, cam->cfg->picture_type); cam->filetype = FTYPE_IMAGE_ROI; save_roi(filename, cam->current_image->image_norm); on_picture_save_command(filename); @@ -98,15 +98,15 @@ void cls_picture::process_snapshot() char linkpath[PATH_MAX]; int offset; - offset = (int)cfg_snapshot_filename.length() - 8; + offset = (int)cam->cfg->snapshot_filename.length() - 8; if (offset < 0) { offset = 1; } - if (cfg_snapshot_filename.compare((uint)offset, 8, "lastsnap") != 0) { + if (cam->cfg->snapshot_filename.compare((uint)offset, 8, "lastsnap") != 0) { picname(filename,"%s/%s.%s" - , cfg_snapshot_filename - , cfg_picture_type); + , cam->cfg->snapshot_filename + , cam->cfg->picture_type); cam->filetype = FTYPE_IMAGE_SNAPSHOT; if ((cam->imgs.size_high > 0) && (cam->movie_passthrough == false)) { save_norm(filename, cam->current_image->image_high); @@ -118,7 +118,7 @@ void cls_picture::process_snapshot() /* Update symbolic link */ picname(linkpath,"%s/%s.%s" - , "lastsnap", cfg_picture_type); + , "lastsnap", cam->cfg->picture_type); remove(linkpath); if (symlink(filename, linkpath)) { MOTPLS_LOG(ERR, TYPE_EVENTS, SHOW_ERRNO @@ -128,8 +128,8 @@ void cls_picture::process_snapshot() } else { picname(filename,"%s/%s.%s" - , cfg_snapshot_filename - , cfg_picture_type); + , cam->cfg->snapshot_filename + , cam->cfg->picture_type); remove(filename); cam->filetype = FTYPE_IMAGE_SNAPSHOT; if ((cam->imgs.size_high > 0) && (cam->movie_passthrough == false)) { @@ -157,8 +157,8 @@ void cls_picture::process_preview() cam->current_image->imgts = cam->imgs.image_preview.imgts; picname(filename,"%s/%s.%s" - , cfg_picture_filename - , cfg_picture_type); + , cam->cfg->picture_filename + , cam->cfg->picture_type); cam->filetype = FTYPE_IMAGE; if ((cam->imgs.size_high > 0) && (cam->movie_passthrough == false)) { @@ -206,7 +206,7 @@ void cls_picture::save_webp(FILE *fp, u_char *image, int width, int height /* Create a config present and check for compatible library version */ WebPConfig webp_config; if (!WebPConfigPreset(&webp_config, WEBP_PRESET_DEFAULT - , (float) cfg_picture_quality)) { + , (float) cam->cfg->picture_quality)) { MOTPLS_LOG(ERR, TYPE_CORE, NO_ERRNO, _("libwebp version error")); return; } @@ -297,7 +297,7 @@ void cls_picture::save_yuv420p(FILE *fp, u_char *image, int width, int height u_char *buf =(u_char*) mymalloc((uint)image_size); sz = jpgutl_put_yuv420p(buf, image_size, image, width, height - , cfg_picture_quality, cam ,ts1, box); + , cam->cfg->picture_quality, cam ,ts1, box); fwrite(buf, (uint)sz, 1, fp); free(buf); @@ -315,7 +315,7 @@ void cls_picture::save_grey(FILE *picture, u_char *image, int width, int height u_char *buf =(u_char*) mymalloc((uint)image_size); sz = jpgutl_put_grey(buf, image_size, image, width, height - , cfg_picture_quality, cam ,ts1, box); + , cam->cfg->picture_quality, cam ,ts1, box); fwrite(buf, (uint)sz, 1, picture); free(buf); @@ -394,7 +394,7 @@ int cls_picture::put_memory(u_char *img_dst, int image_size int retcd; clock_gettime(CLOCK_REALTIME, &ts1); - if (cfg_stream_grey) { + if (cam->cfg->stream_grey) { retcd = jpgutl_put_grey(img_dst, image_size, image , width, height, quality, cam, &ts1, NULL); } else { @@ -419,12 +419,12 @@ void cls_picture::pic_write(FILE *picture, u_char *image) height = cam->imgs.height; } - if (cfg_picture_type == "ppm") { + if (cam->cfg->picture_type == "ppm") { save_ppm(picture, image, width, height); - } else if (cfg_picture_type == "webp") { + } else if (cam->cfg->picture_type == "webp") { save_webp(picture, image, width, height , &(cam->current_image->imgts), &(cam->current_image->location)); - } else if (cfg_picture_type == "grey") { + } else if (cam->cfg->picture_type == "grey") { save_grey(picture, image, width, height , &(cam->current_image->imgts), &(cam->current_image->location)); } else { @@ -484,7 +484,7 @@ void cls_picture::save_roi(char *file, u_char *image) sz = jpgutl_put_grey(buf, image_size, img , bx->width, bx->height - , cfg_picture_quality, cam + , cam->cfg->picture_quality, cam ,&(cam->current_image->imgts), bx); fwrite(buf, (uint)sz, 1, picture); @@ -607,11 +607,11 @@ void cls_picture::write_mask(const char *file) /* Write pgm-header. */ fprintf(picture, "P5\n"); - fprintf(picture, "%d %d\n", cfg_w, cfg_h); + fprintf(picture, "%d %d\n", cam->cfg->width, cam->cfg->height); fprintf(picture, "%d\n", 255); /* Write pgm image data at once. */ - if ((int)fwrite(cam->imgs.image_motion.image_norm, (uint)cfg_w, (uint)cfg_h, picture) != cfg_h) { + if ((int)fwrite(cam->imgs.image_motion.image_norm, (uint)cam->cfg->width, (uint)cam->cfg->height, picture) != cam->cfg->height) { MOTPLS_LOG(ERR, TYPE_ALL, SHOW_ERRNO ,_("Failed writing default mask as pgm file")); return; @@ -621,7 +621,7 @@ void cls_picture::write_mask(const char *file) MOTPLS_LOG(ERR, TYPE_ALL, NO_ERRNO ,_("Creating empty mask %s\nPlease edit this file and " - "re-run motion to enable mask feature"), cfg_mask_file.c_str()); + "re-run motion to enable mask feature"), cam->cfg->mask_file.c_str()); } void cls_picture::scale_img(int width_src, int height_src, u_char *img_src, u_char *img_dst) @@ -695,8 +695,8 @@ void cls_picture::init_privacy() cam->imgs.mask_privacy_high = NULL; cam->imgs.mask_privacy_high_uv = NULL; - if (cfg_mask_privacy != "") { - if ((picture = myfopen(cfg_mask_privacy.c_str(), "rbe"))) { + if (cam->cfg->mask_privacy != "") { + if ((picture = myfopen(cam->cfg->mask_privacy.c_str(), "rbe"))) { MOTPLS_LOG(INF, TYPE_ALL, NO_ERRNO, _("Opening privacy mask file")); /* * NOTE: The mask is expected to have the output dimensions. I.e., the mask @@ -720,9 +720,9 @@ void cls_picture::init_privacy() myfclose(picture); } else { MOTPLS_LOG(ERR, TYPE_ALL, SHOW_ERRNO - ,_("Error opening mask file %s"), cfg_mask_privacy.c_str()); + ,_("Error opening mask file %s"), cam->cfg->mask_privacy.c_str()); /* Try to write an empty mask file to make it easier for the user to edit it */ - write_mask(cfg_mask_privacy.c_str() ); + write_mask(cam->cfg->mask_privacy.c_str() ); } if (!cam->imgs.mask_privacy) { @@ -730,7 +730,7 @@ void cls_picture::init_privacy() ,_("Failed to read mask privacy image. Mask privacy feature disabled.")); } else { MOTPLS_LOG(INF, TYPE_ALL, NO_ERRNO - ,_("Mask privacy file \"%s\" loaded."), cfg_mask_privacy.c_str()); + ,_("Mask privacy file \"%s\" loaded."), cam->cfg->mask_privacy.c_str()); indx_img = 1; if (cam->imgs.size_high > 0) { @@ -793,8 +793,8 @@ void cls_picture::init_mask() FILE *picture; /* Load the mask file if any */ - if (cfg_mask_file != "") { - if ((picture = myfopen(cfg_mask_file.c_str(), "rbe"))) { + if (cam->cfg->mask_file != "") { + if ((picture = myfopen(cam->cfg->mask_file.c_str(), "rbe"))) { /* * NOTE: The mask is expected to have the output dimensions. I.e., the mask * applies to the already rotated image, not the capture image. Thus, use @@ -805,12 +805,12 @@ void cls_picture::init_mask() } else { MOTPLS_LOG(ERR, TYPE_ALL, SHOW_ERRNO ,_("Error opening mask file %s") - ,cfg_mask_file.c_str()); + ,cam->cfg->mask_file.c_str()); /* * Try to write an empty mask file to make it easier * for the user to edit it */ - write_mask(cfg_mask_file.c_str()); + write_mask(cam->cfg->mask_file.c_str()); } if (!cam->imgs.mask) { @@ -819,38 +819,18 @@ void cls_picture::init_mask() } else { MOTPLS_LOG(INF, TYPE_ALL, NO_ERRNO ,_("Maskfile \"%s\" loaded.") - ,cfg_mask_file.c_str()); + ,cam->cfg->mask_file.c_str()); } } else { cam->imgs.mask = NULL; } } -void cls_picture::init_cfg() -{ - /* Isolate config params from webcontrol changes*/ - cfg_stream_grey = cam->conf->stream_grey; - cfg_picture_type = cam->conf->picture_type; - cfg_mask_file = cam->conf->mask_file; - cfg_mask_privacy = cam->conf->mask_privacy; - cfg_w = cam->conf->width; - cfg_h = cam->conf->height; - cfg_picture_quality = cam->conf->picture_quality; - cfg_on_picture_save = cam->conf->on_picture_save; - cfg_target_dir = cam->conf->target_dir; - cfg_picture_filename = cam->conf->picture_filename; - cfg_snapshot_filename = cam->conf->snapshot_filename; - cfg_picture_output_motion = cam->conf->picture_output_motion; - cfg_picture_output = cam->conf->picture_output; -} - cls_picture::cls_picture(cls_camera *p_cam) { cam = p_cam; - init_cfg(); init_mask(); init_privacy(); - } cls_picture::~cls_picture() diff --git a/src/picture.hpp b/src/picture.hpp index 334ad0b8..3d80100a 100644 --- a/src/picture.hpp +++ b/src/picture.hpp @@ -41,20 +41,6 @@ class cls_picture { private: cls_camera *cam; - int cfg_w; - int cfg_h; - int cfg_picture_quality; - bool cfg_stream_grey; - std::string cfg_mask_file; - std::string cfg_mask_privacy; - std::string cfg_on_picture_save; - std::string cfg_target_dir; - std::string cfg_picture_filename; - std::string cfg_picture_type; - std::string cfg_snapshot_filename; - std::string cfg_picture_output_motion; - std::string cfg_picture_output; - #ifdef HAVE_WEBP void webp_exif(WebPMux* webp_mux , timespec *ts1, ctx_coord *box); diff --git a/src/rotate.cpp b/src/rotate.cpp index 843371f3..661b7d72 100644 --- a/src/rotate.cpp +++ b/src/rotate.cpp @@ -222,19 +222,19 @@ cls_rotate::cls_rotate(cls_camera *p_cam) buffer_norm = nullptr; buffer_high = nullptr; - if ((cam->conf->rotate % 90) > 0) { + if ((cam->cfg->rotate % 90) > 0) { MOTPLS_LOG(WRN, TYPE_ALL, NO_ERRNO ,_("Config option \"rotate\" not a multiple of 90: %d") - ,cam->conf->rotate); - cam->conf->rotate = 0; /* Disable rotation. */ + ,cam->cfg->rotate); + cam->cfg->rotate = 0; /* Disable rotation. */ degrees = 0; /* Force return below. */ } else { - degrees = cam->conf->rotate % 360; /* Range: 0..359 */ + degrees = cam->cfg->rotate % 360; /* Range: 0..359 */ } - if (cam->conf->flip_axis == "horizontal") { + if (cam->cfg->flip_axis == "horizontal") { axis = FLIP_TYPE_HORIZONTAL; - } else if (cam->conf->flip_axis == "vertical") { + } else if (cam->cfg->flip_axis == "vertical") { axis = FLIP_TYPE_VERTICAL; } else { axis = FLIP_TYPE_NONE; diff --git a/src/sound.cpp b/src/sound.cpp index 4ff8533b..0fa0afbf 100644 --- a/src/sound.cpp +++ b/src/sound.cpp @@ -23,16 +23,6 @@ #include "util.hpp" #include "sound.hpp" -void cls_sound::init_conf() -{ - cfg_snd_params = conf->snd_params; - cfg_snd_device = conf->snd_device; - cfg_snd_window = conf->snd_window; - cfg_snd_show = conf->snd_show; - cfg_on_sound_alert = conf->on_sound_alert; - -} - void cls_sound::init_values() { #ifdef HAVE_FFTW3 @@ -127,7 +117,7 @@ void cls_sound::load_alerts() ctx_params *tmp_params; p_it it; - conf->edit_get("snd_alerts", parm_val, PARM_CAT_18); + cfg->edit_get("snd_alerts", parm_val, PARM_CAT_18); tmp_params = new ctx_params; for (it_a=parm_val.begin(); it_a!=parm_val.end(); it_a++) { @@ -175,7 +165,7 @@ void cls_sound::load_params() p_lst *lst; snd_info->params->update_params = true; - util_parms_parse(snd_info->params,"snd_params", cfg_snd_params); + util_parms_parse(snd_info->params,"snd_params", cfg->snd_params); util_parms_add_default(snd_info->params,"source","alsa"); util_parms_add_default(snd_info->params,"channels","1"); @@ -337,11 +327,11 @@ void cls_sound::alsa_start() smpl_rate = (unsigned int)snd_info->sample_rate; retcd = snd_pcm_open(&alsa->pcm_dev - , cfg_snd_device.c_str(), SND_PCM_STREAM_CAPTURE, 0); + , cfg->snd_device.c_str(), SND_PCM_STREAM_CAPTURE, 0); if (retcd < 0) { MOTPLS_LOG(ERR, TYPE_ALL, NO_ERRNO , _("error: snd_pcm_open device %s (%s)") - , cfg_snd_device.c_str(), snd_strerror (retcd)); + , cfg->snd_device.c_str(), snd_strerror (retcd)); device_status = STATUS_CLOSED; return; } @@ -561,7 +551,7 @@ void cls_sound::pulse_init() snd_info->snd_pulse->dev = pa_simple_new( (snd_info->pulse_server=="" ? NULL : snd_info->pulse_server.c_str()) , "motionplus", PA_STREAM_RECORD - , (cfg_snd_device=="" ? NULL : cfg_snd_device.c_str()) + , (cfg->snd_device=="" ? NULL : cfg->snd_device.c_str()) , "motionplus", &specs, NULL, NULL, &errcd); if (snd_info->snd_pulse->dev == NULL) { MOTPLS_LOG(ERR, TYPE_ALL, NO_ERRNO @@ -665,10 +655,10 @@ void cls_sound::check_alerts() struct timespec trig_ts; for (indx=0;indx frames;indx++){ - if (cfg_snd_window == "hamming") { + if (cfg->snd_window == "hamming") { snd_info->snd_fftw->ff_in[indx] = snd_info->buffer[indx] * HammingWindow(indx, snd_info->frames); - } else if (cfg_snd_window == "hann") { + } else if (cfg->snd_window == "hann") { snd_info->snd_fftw->ff_in[indx] = snd_info->buffer[indx] * HannWindow(indx, snd_info->frames); } else { @@ -694,7 +684,7 @@ void cls_sound::check_alerts() freq_value = (snd_info->snd_fftw->bin_size * pMaxBinIndex * snd_info->channels); - if (cfg_snd_show) { + if (cfg->snd_show) { MOTPLS_LOG(INF, TYPE_ALL, NO_ERRNO , _("Freq: %.4f threshold: %d count: %d maximum: %d") , freq_value, snd_info->vol_min @@ -730,11 +720,11 @@ void cls_sound::check_alerts() , it->alert_id ,it->alert_nm.c_str() , it->volume_level, chkcnt , snd_info->vol_max); - if (cfg_on_sound_alert != "") { + if (cfg->on_sound_alert != "") { snd_info->trig_freq =std::to_string(freq_value); snd_info->trig_nbr = std::to_string(it->alert_id); snd_info->trig_nm = it->alert_nm; - util_exec_command(this, cfg_on_sound_alert); + util_exec_command(this, cfg->on_sound_alert); } } } @@ -798,9 +788,11 @@ void cls_sound::init() restart = false; } - mythreadname_set("sl", threadnr, conf->device_name.c_str()); + cfg->parms_copy(conf_src); - MOTPLS_LOG(INF, TYPE_ALL, NO_ERRNO,_("Initialize")); + mythreadname_set("sl",cfg->device_id, cfg->device_name.c_str()); + + MOTPLS_LOG(INF, TYPE_ALL, NO_ERRNO,_("Initialize sound frequency")); snd_info = new ctx_snd_info; snd_info->params = new ctx_params; @@ -808,7 +800,6 @@ void cls_sound::init() snd_info->snd_alsa = new ctx_snd_alsa; snd_info->snd_pulse = new ctx_snd_pulse; - init_conf(); init_values(); load_params(); load_alerts(); @@ -923,6 +914,7 @@ cls_sound::cls_sound(ctx_motapp *p_motapp) cls_sound::~cls_sound() { - mydelete(conf); + mydelete(conf_src); + mydelete(cfg); } diff --git a/src/sound.hpp b/src/sound.hpp index 53f0992a..f8b35cad 100644 --- a/src/sound.hpp +++ b/src/sound.hpp @@ -97,7 +97,8 @@ class cls_sound { enum DEVICE_STATUS device_status; - cls_config *conf; + cls_config *conf_src; + cls_config *cfg; int device_id; std::string device_name; ctx_snd_info *snd_info; @@ -109,16 +110,9 @@ class cls_sound { private: ctx_motapp *motapp; std::thread handler_thread; - std::string cfg_snd_params; - std::string cfg_snd_device; - std::string cfg_snd_window; - bool cfg_snd_show; - std::string cfg_on_sound_alert; - void cleanup(); void handler(); - void init_conf(); void init_values(); void init(); void init_alerts(ctx_snd_alert *tmp_alert); diff --git a/src/util.cpp b/src/util.cpp index 29a2783a..6c6fa3ad 100644 --- a/src/util.cpp +++ b/src/util.cpp @@ -494,8 +494,8 @@ size_t mystrftime_base(cls_camera *cam, char *s, size_t max break; case '$': // thread name - if (cam->conf->device_name != "") { - cam->conf->device_name.copy(tempstr, PATH_MAX); + if (cam->cfg->device_name != "") { + cam->cfg->device_name.copy(tempstr, PATH_MAX); } else { ++pos_userformat; } diff --git a/src/video_loopback.cpp b/src/video_loopback.cpp index 9c580f99..10da7fe7 100644 --- a/src/video_loopback.cpp +++ b/src/video_loopback.cpp @@ -260,12 +260,12 @@ void vlp_init(cls_camera *cam) { #if defined(HAVE_V4L2) && !defined(BSD) /* open video loopback devices if enabled */ - if (cam->conf->video_pipe != "") { + if (cam->cfg->video_pipe != "") { MOTPLS_LOG(NTC, TYPE_ALL, NO_ERRNO ,_("Opening video loopback device for normal pictures")); /* vid_startpipe should get the output dimensions */ - cam->pipe = vlp_startpipe(cam->conf->video_pipe.c_str(), cam->imgs.width, cam->imgs.height); + cam->pipe = vlp_startpipe(cam->cfg->video_pipe.c_str(), cam->imgs.width, cam->imgs.height); if (cam->pipe < 0) { MOTPLS_LOG(ERR, TYPE_ALL, NO_ERRNO @@ -276,12 +276,12 @@ void vlp_init(cls_camera *cam) cam->pipe = -1; } - if (cam->conf->video_pipe_motion != "") { + if (cam->cfg->video_pipe_motion != "") { MOTPLS_LOG(NTC, TYPE_ALL, NO_ERRNO ,_("Opening video loopback device for motion pictures")); /* vid_startpipe should get the output dimensions */ - cam->mpipe = vlp_startpipe(cam->conf->video_pipe_motion.c_str(), cam->imgs.width, cam->imgs.height); + cam->mpipe = vlp_startpipe(cam->cfg->video_pipe_motion.c_str(), cam->imgs.width, cam->imgs.height); if (cam->mpipe < 0) { MOTPLS_LOG(ERR, TYPE_ALL, NO_ERRNO diff --git a/src/video_v4l2.cpp b/src/video_v4l2.cpp index 78d5867f..83fbb332 100644 --- a/src/video_v4l2.cpp +++ b/src/video_v4l2.cpp @@ -456,8 +456,8 @@ int cls_v4l2cam::pixfmt_try(uint pixformat) memset(&vidfmt, 0, sizeof(struct v4l2_format)); vidfmt.type = V4L2_BUF_TYPE_VIDEO_CAPTURE; - vidfmt.fmt.pix.width = (uint)width; - vidfmt.fmt.pix.height = (uint)height; + vidfmt.fmt.pix.width = (uint)cam->cfg->width; + vidfmt.fmt.pix.height = (uint)cam->cfg->height; vidfmt.fmt.pix.pixelformat = pixformat; vidfmt.fmt.pix.field = V4L2_FIELD_ANY; @@ -467,7 +467,7 @@ int cls_v4l2cam::pixfmt_try(uint pixformat) ,_("Unable to use palette %c%c%c%c (%dx%d)") ,pixformat >> 0, pixformat >> 8 ,pixformat >> 16, pixformat >> 24 - ,width, height); + ,cam->cfg->width, cam->cfg->height); return -1; } @@ -475,7 +475,7 @@ int cls_v4l2cam::pixfmt_try(uint pixformat) ,_("Testing palette %c%c%c%c (%dx%d)") ,pixformat >> 0, pixformat >> 8 ,pixformat >> 16, pixformat >> 24 - ,width, height); + ,cam->cfg->width, cam->cfg->height); return 0; } @@ -484,15 +484,15 @@ int cls_v4l2cam::pixfmt_stride() { int wd, bpl, wps; - width = (int)vidfmt.fmt.pix.width; - height = (int)vidfmt.fmt.pix.height; + cam->cfg->width = (int)vidfmt.fmt.pix.width; + cam->cfg->height = (int)vidfmt.fmt.pix.height; bpl = (int)vidfmt.fmt.pix.bytesperline; - wd = width; + wd = cam->cfg->width; MOTPLS_LOG(DBG, TYPE_VIDEO, NO_ERRNO , _("Checking image size %dx%d with stride %d") - , width, height, bpl); + , cam->cfg->width, cam->cfg->height, bpl); if (bpl == 0) { MOTPLS_LOG(DBG, TYPE_VIDEO, NO_ERRNO @@ -526,7 +526,7 @@ int cls_v4l2cam::pixfmt_stride() MOTPLS_LOG(WRN, TYPE_VIDEO, NO_ERRNO , _("Image width will be padded %d bytes"), ((bpl % wd)/wps)); - width = wd + ((bpl % wd)/wps); + cam->cfg->width = wd + ((bpl % wd)/wps); return 0; @@ -534,19 +534,19 @@ int cls_v4l2cam::pixfmt_stride() int cls_v4l2cam::pixfmt_adjust() { - if ((vidfmt.fmt.pix.width != (uint)width) || - (vidfmt.fmt.pix.height != (uint)height)) { + if ((vidfmt.fmt.pix.width != (uint)cam->cfg->width) || + (vidfmt.fmt.pix.height != (uint)cam->cfg->height)) { MOTPLS_LOG(WRN, TYPE_VIDEO, NO_ERRNO ,_("Adjusting resolution from %ix%i to %ix%i.") - ,width, height + ,cam->cfg->width, cam->cfg->height ,vidfmt.fmt.pix.width ,vidfmt.fmt.pix.height); - width = (int)vidfmt.fmt.pix.width; - height = (int)vidfmt.fmt.pix.height; + cam->cfg->width = (int)vidfmt.fmt.pix.width; + cam->cfg->height = (int)vidfmt.fmt.pix.height; - if ((width % 8) || (height % 8)) { + if ((cam->cfg->width % 8) || (cam->cfg->height % 8)) { MOTPLS_LOG(ERR, TYPE_VIDEO, NO_ERRNO ,_("Adjusted resolution not modulo 8.")); MOTPLS_LOG(ERR, TYPE_VIDEO, NO_ERRNO @@ -588,7 +588,7 @@ int cls_v4l2cam::pixfmt_set(uint pixformat) ,_("Using palette %c%c%c%c (%dx%d)") ,pixformat >> 0 , pixformat >> 8 ,pixformat >> 16, pixformat >> 24 - ,width, height); + ,cam->cfg->width, cam->cfg->height); return 0; } @@ -600,20 +600,20 @@ void cls_v4l2cam::params_check() p_lst *lst = ¶ms->params_array; p_it it; - if (width % 8) { + if (cam->cfg->width % 8) { MOTPLS_LOG(ERR, TYPE_VIDEO, NO_ERRNO - ,_("config image width (%d) is not modulo 8"), width); - width = width - (width % 8) + 8; + ,_("config image width (%d) is not modulo 8"), cam->cfg->width); + cam->cfg->width = cam->cfg->width - (cam->cfg->width % 8) + 8; MOTPLS_LOG(WRN, TYPE_VIDEO, NO_ERRNO - , _("Adjusting to width (%d)"), width); + , _("Adjusting to width (%d)"), cam->cfg->width); } - if (height % 8) { + if (cam->cfg->height % 8) { MOTPLS_LOG(ERR, TYPE_VIDEO, NO_ERRNO - ,_("config image height (%d) is not modulo 8"), height); - height = height - (height % 8) + 8; + ,_("config image height (%d) is not modulo 8"), cam->cfg->height); + cam->cfg->height = cam->cfg->height - (cam->cfg->height % 8) + 8; MOTPLS_LOG(WRN, TYPE_VIDEO, NO_ERRNO - ,_("Adjusting to height (%d)"), height); + ,_("Adjusting to height (%d)"), cam->cfg->height); } spec = 17; @@ -696,7 +696,7 @@ void cls_v4l2cam::palette_set() MOTPLS_LOG(NTC, TYPE_VIDEO, NO_ERRNO ,_("Configuration palette index %d (%s) for %dx%d doesn't work.") , indxp, palette[(uint)indxp].fourcc.c_str() - ,width, height); + ,cam->cfg->width, cam->cfg->height); indxp = pixfmt_list(); if (indxp < 0) { @@ -834,14 +834,12 @@ void cls_v4l2cam::set_imgs() if (fd_device == -1) { return; } - cam->imgs.width = width; - cam->imgs.height = height; + cam->imgs.width = cam->cfg->width; + cam->imgs.height = cam->cfg->height; cam->imgs.motionsize = cam->imgs.width * cam->imgs.height; cam->imgs.size_norm = (cam->imgs.motionsize * 3) / 2; - cam->conf->width = width; - cam->conf->height = height; - convert = new cls_convert(cam, pixfmt_src, width, height); + convert = new cls_convert(cam, pixfmt_src, cam->cfg->width, cam->cfg->height); } @@ -899,16 +897,10 @@ void cls_v4l2cam::init_vars() buffers = nullptr; convert = nullptr; - height = cam->conf->height; - width = cam->conf->width; - fps =cam->conf->framerate; - v4l2_device = cam->conf->v4l2_device; - v4l2_params = cam->conf->v4l2_params; - params = new ctx_params; params->params_count = 0; params->update_params = true; - util_parms_parse(params, "v4l2_params", v4l2_params); + util_parms_parse(params, "v4l2_params", cam->cfg->v4l2_params); util_parms_add_default(params, "input", "-1"); util_parms_add_default(params, "palette", "17"); util_parms_add_default(params, "norm", "0"); @@ -922,14 +914,14 @@ void cls_v4l2cam::device_open() { MOTPLS_LOG(NTC, TYPE_VIDEO, NO_ERRNO , _("Opening video device %s") - , v4l2_device.c_str()); + , cam->cfg->v4l2_device.c_str()); cam->watchdog = 60; - fd_device = open(v4l2_device.c_str(), O_RDWR|O_CLOEXEC); + fd_device = open(cam->cfg->v4l2_device.c_str(), O_RDWR|O_CLOEXEC); if (fd_device <= 0) { MOTPLS_LOG(ALR, TYPE_VIDEO, SHOW_ERRNO , _("Failed to open video device %s") - , v4l2_device.c_str()); + , cam->cfg->v4l2_device.c_str()); fd_device = -1; return; } @@ -1072,7 +1064,7 @@ void cls_v4l2cam::set_fps() setfps.type = V4L2_BUF_TYPE_VIDEO_CAPTURE; setfps.parm.capture.timeperframe.numerator = 1; - setfps.parm.capture.timeperframe.denominator = (uint)fps; + setfps.parm.capture.timeperframe.denominator = (uint)cam->cfg->framerate; MOTPLS_LOG(INF, TYPE_VIDEO, NO_ERRNO , _("Trying to set fps to %d") @@ -1096,7 +1088,7 @@ void cls_v4l2cam::stop_cam() int indx; MOTPLS_LOG(NTC, TYPE_VIDEO, NO_ERRNO - ,_("Closing video device %s"), v4l2_device.c_str()); + ,_("Closing video device %s"), cam->cfg->v4l2_device.c_str()); p_type = V4L2_BUF_TYPE_VIDEO_CAPTURE; diff --git a/src/video_v4l2.hpp b/src/video_v4l2.hpp index eb0a0b91..279c2b64 100644 --- a/src/video_v4l2.hpp +++ b/src/video_v4l2.hpp @@ -61,13 +61,6 @@ class cls_v4l2cam { cls_camera *cam; cls_convert *convert; - /* Isolated variables from user config*/ - int width; - int height; - int fps; - std::string v4l2_device; - std::string v4l2_params; - int fd_device; int pixfmt_src; int buffer_count; diff --git a/src/webu.cpp b/src/webu.cpp index e0525a7f..9d9c8586 100644 --- a/src/webu.cpp +++ b/src/webu.cpp @@ -92,9 +92,9 @@ void cls_webu::mhd_features_basic() if (retcd == MHD_YES) { MOTPLS_LOG(DBG, TYPE_STREAM, NO_ERRNO ,_("Basic authentication: available")); } else { - if (c_motapp->conf->webcontrol_auth_method == "basic") { + if (c_motapp->cfg->webcontrol_auth_method == "basic") { MOTPLS_LOG(NTC, TYPE_STREAM, NO_ERRNO ,_("Basic authentication: disabled")); - c_motapp->conf->webcontrol_auth_method = "none"; + c_motapp->cfg->webcontrol_auth_method = "none"; } else { MOTPLS_LOG(INF, TYPE_STREAM, NO_ERRNO ,_("Basic authentication: disabled")); } @@ -113,9 +113,9 @@ void cls_webu::mhd_features_digest() if (retcd == MHD_YES) { MOTPLS_LOG(DBG, TYPE_STREAM, NO_ERRNO ,_("Digest authentication: available")); } else { - if (c_motapp->conf->webcontrol_auth_method == "digest") { + if (c_motapp->cfg->webcontrol_auth_method == "digest") { MOTPLS_LOG(NTC, TYPE_STREAM, NO_ERRNO ,_("Digest authentication: disabled")); - c_motapp->conf->webcontrol_auth_method = "none"; + c_motapp->cfg->webcontrol_auth_method = "none"; } else { MOTPLS_LOG(INF, TYPE_STREAM, NO_ERRNO ,_("Digest authentication: disabled")); } @@ -218,12 +218,12 @@ void cls_webu::mhd_loadfile(std::string fname,std::string &filestr) void cls_webu::mhd_checktls() { if (mhdst->tls_use) { - if ((c_motapp->conf->webcontrol_cert == "") || (mhdst->tls_cert == "")) { + if ((c_motapp->cfg->webcontrol_cert == "") || (mhdst->tls_cert == "")) { MOTPLS_LOG(NTC, TYPE_STREAM, NO_ERRNO ,_("SSL/TLS requested but no cert file provided. SSL/TLS disabled")); mhdst->tls_use = false; } - if ((c_motapp->conf->webcontrol_key == "") || (mhdst->tls_key == "")) { + if ((c_motapp->cfg->webcontrol_key == "") || (mhdst->tls_key == "")) { MOTPLS_LOG(NTC, TYPE_STREAM, NO_ERRNO ,_("SSL/TLS requested but no key file provided. SSL/TLS disabled")); mhdst->tls_use = false; @@ -254,11 +254,11 @@ void cls_webu::mhd_opts_deinit() /* Set the MHD option on acceptable connections */ void cls_webu::mhd_opts_localhost() { - if (c_motapp->conf->webcontrol_localhost) { + if (c_motapp->cfg->webcontrol_localhost) { if (mhdst->ipv6) { memset(&mhdst->lpbk_ipv6, 0, sizeof(struct sockaddr_in6)); mhdst->lpbk_ipv6.sin6_family = AF_INET6; - mhdst->lpbk_ipv6.sin6_port = htons((uint16_t)c_motapp->conf->webcontrol_port); + mhdst->lpbk_ipv6.sin6_port = htons((uint16_t)c_motapp->cfg->webcontrol_port); mhdst->lpbk_ipv6.sin6_addr = in6addr_loopback; mhdst->mhd_ops[mhdst->mhd_opt_nbr].option = MHD_OPTION_SOCK_ADDR; @@ -269,7 +269,7 @@ void cls_webu::mhd_opts_localhost() } else { memset(&mhdst->lpbk_ipv4, 0, sizeof(struct sockaddr_in)); mhdst->lpbk_ipv4.sin_family = AF_INET; - mhdst->lpbk_ipv4.sin_port = htons((uint16_t)c_motapp->conf->webcontrol_port); + mhdst->lpbk_ipv4.sin_port = htons((uint16_t)c_motapp->cfg->webcontrol_port); mhdst->lpbk_ipv4.sin_addr.s_addr = htonl(INADDR_LOOPBACK); mhdst->mhd_ops[mhdst->mhd_opt_nbr].option = MHD_OPTION_SOCK_ADDR; @@ -284,7 +284,7 @@ void cls_webu::mhd_opts_localhost() /* Set the mhd digest options */ void cls_webu::mhd_opts_digest() { - if (c_motapp->conf->webcontrol_auth_method == "digest") { + if (c_motapp->cfg->webcontrol_auth_method == "digest") { mhdst->mhd_ops[mhdst->mhd_opt_nbr].option = MHD_OPTION_DIGEST_AUTH_RANDOM; mhdst->mhd_ops[mhdst->mhd_opt_nbr].value = sizeof(wb_digest_rand); @@ -364,9 +364,9 @@ void cls_webu::init_actions() wb_actions = new ctx_params; wb_actions->update_params = true; util_parms_parse(wb_actions - ,"webcontrol_actions", c_motapp->conf->webcontrol_actions); + ,"webcontrol_actions", c_motapp->cfg->webcontrol_actions); - if (c_motapp->conf->webcontrol_parms == 0) { + if (c_motapp->cfg->webcontrol_parms == 0) { parm_vl = "off"; } else { parm_vl = "on"; @@ -390,10 +390,10 @@ void cls_webu::start_daemon_port1() { mhdst = new ctx_mhdstart; - mhd_loadfile(c_motapp->conf->webcontrol_cert, mhdst->tls_cert); - mhd_loadfile(c_motapp->conf->webcontrol_key, mhdst->tls_key); - mhdst->ipv6 = c_motapp->conf->webcontrol_ipv6; - mhdst->tls_use = c_motapp->conf->webcontrol_tls; + mhd_loadfile(c_motapp->cfg->webcontrol_cert, mhdst->tls_cert); + mhd_loadfile(c_motapp->cfg->webcontrol_key, mhdst->tls_key); + mhdst->ipv6 = c_motapp->cfg->webcontrol_ipv6; + mhdst->tls_use = c_motapp->cfg->webcontrol_tls; mhdst->mhd_ops =(struct MHD_OptionItem*)mymalloc(sizeof(struct MHD_OptionItem) * WEBUI_MHD_OPTS); mhd_features(); @@ -402,7 +402,7 @@ void cls_webu::start_daemon_port1() wb_daemon = MHD_start_daemon ( mhdst->mhd_flags - , (uint16_t)c_motapp->conf->webcontrol_port + , (uint16_t)c_motapp->cfg->webcontrol_port , NULL, NULL , &mhd_answer, c_motapp , MHD_OPTION_ARRAY, mhdst->mhd_ops @@ -414,7 +414,7 @@ void cls_webu::start_daemon_port1() } else { MOTPLS_LOG(NTC, TYPE_STREAM, NO_ERRNO ,_("Started webcontrol on port %d") - ,c_motapp->conf->webcontrol_port); + ,c_motapp->cfg->webcontrol_port); } delete mhdst; mhdst = nullptr; @@ -422,26 +422,26 @@ void cls_webu::start_daemon_port1() void cls_webu::start_daemon_port2() { - if ((c_motapp->conf->webcontrol_port2 == 0 ) || - (c_motapp->conf->webcontrol_port2 == c_motapp->conf->webcontrol_port)) { + if ((c_motapp->cfg->webcontrol_port2 == 0 ) || + (c_motapp->cfg->webcontrol_port2 == c_motapp->cfg->webcontrol_port)) { return; } MOTPLS_LOG(NTC, TYPE_STREAM, NO_ERRNO , _("Starting secondary webcontrol on port %d") - , c_motapp->conf->webcontrol_port2); + , c_motapp->cfg->webcontrol_port2); mhdst = new ctx_mhdstart; - mhd_loadfile(c_motapp->conf->webcontrol_cert, mhdst->tls_cert); - mhd_loadfile(c_motapp->conf->webcontrol_key, mhdst->tls_key); - mhdst->ipv6 = c_motapp->conf->webcontrol_ipv6; + mhd_loadfile(c_motapp->cfg->webcontrol_cert, mhdst->tls_cert); + mhd_loadfile(c_motapp->cfg->webcontrol_key, mhdst->tls_key); + mhdst->ipv6 = c_motapp->cfg->webcontrol_ipv6; mhdst->tls_use = false; - if (c_motapp->conf->webcontrol_tls) { + if (c_motapp->cfg->webcontrol_tls) { MOTPLS_LOG(NTC, TYPE_STREAM, NO_ERRNO , _("TLS will be disabled on webcontrol port %d") - , c_motapp->conf->webcontrol_port2); + , c_motapp->cfg->webcontrol_port2); } mhdst->mhd_ops =(struct MHD_OptionItem*)mymalloc(sizeof(struct MHD_OptionItem)*WEBUI_MHD_OPTS); @@ -450,7 +450,7 @@ void cls_webu::start_daemon_port2() wb_daemon2 = MHD_start_daemon ( mhdst->mhd_flags - , (uint16_t)c_motapp->conf->webcontrol_port2 + , (uint16_t)c_motapp->cfg->webcontrol_port2 , NULL, NULL //, &webu_answer, motapp->cam_list , &mhd_answer, c_motapp @@ -463,7 +463,7 @@ void cls_webu::start_daemon_port2() } else { MOTPLS_LOG(NTC, TYPE_STREAM, NO_ERRNO ,_("Started webcontrol on port %d") - ,c_motapp->conf->webcontrol_port2); + ,c_motapp->cfg->webcontrol_port2); } delete mhdst; @@ -481,18 +481,18 @@ void cls_webu::webu_start() memset(wb_digest_rand, 0, sizeof(wb_digest_rand)); - if (c_motapp->conf->webcontrol_port == 0 ) { + if (c_motapp->cfg->webcontrol_port == 0 ) { return; } MOTPLS_LOG(NTC, TYPE_STREAM, NO_ERRNO , _("Starting webcontrol on port %d") - , c_motapp->conf->webcontrol_port); + , c_motapp->cfg->webcontrol_port); wb_headers = new ctx_params; wb_headers->update_params = true; util_parms_parse(wb_headers - , "webcontrol_headers", c_motapp->conf->webcontrol_headers); + , "webcontrol_headers", c_motapp->cfg->webcontrol_headers); init_actions(); diff --git a/src/webu_ans.cpp b/src/webu_ans.cpp index cd3e1a86..94a2f29c 100644 --- a/src/webu_ans.cpp +++ b/src/webu_ans.cpp @@ -57,7 +57,7 @@ int cls_webu_ans::parseurl() MOTPLS_LOG(DBG, TYPE_STREAM, NO_ERRNO, _("Decoded url: %s"),url.c_str()); - baselen = app->conf->webcontrol_base_path.length(); + baselen = app->cfg->webcontrol_base_path.length(); if (url.length() < baselen) { return -1; @@ -68,7 +68,7 @@ int cls_webu_ans::parseurl() } if (url.substr(0, baselen) != - app->conf->webcontrol_base_path) { + app->cfg->webcontrol_base_path) { return -1; } @@ -184,7 +184,7 @@ void cls_webu_ans::clientip_get() int is_ipv6; is_ipv6 = false; - if (app->conf->webcontrol_ipv6) { + if (app->cfg->webcontrol_ipv6) { is_ipv6 = true; } @@ -220,11 +220,11 @@ void cls_webu_ans::hostname_get() hdr = MHD_lookup_connection_value(connection, MHD_HEADER_KIND, MHD_HTTP_HEADER_HOST); if (hdr == NULL) { hostfull = "//localhost:" + - std::to_string(app->conf->webcontrol_port) + - app->conf->webcontrol_base_path; + std::to_string(app->cfg->webcontrol_port) + + app->cfg->webcontrol_base_path; } else { hostfull = "//" + std::string(hdr) + - app->conf->webcontrol_base_path; + app->cfg->webcontrol_base_path; } MOTPLS_LOG(DBG,TYPE_ALL, NO_ERRNO, _("Full Host: %s"), hostfull.c_str()); @@ -286,7 +286,7 @@ void cls_webu_ans::client_connect() it = webu->wb_clients.begin(); while (it != webu->wb_clients.end()) { if ((tm_cnct.tv_sec - it->conn_time.tv_sec) >= - (app->conf->webcontrol_lock_minutes*60)) { + (app->cfg->webcontrol_lock_minutes*60)) { it = webu->wb_clients.erase(it); } it++; @@ -341,21 +341,21 @@ mhdrslt cls_webu_ans::failauth_check() while (it != webu->wb_clients.end()) { if ((it->clientip == clientip) && ((tm_cnct.tv_sec - it->conn_time.tv_sec) < - (app->conf->webcontrol_lock_minutes*60)) && + (app->cfg->webcontrol_lock_minutes*60)) && (it->authenticated == false) && - (it->conn_nbr > app->conf->webcontrol_lock_attempts)) { + (it->conn_nbr > app->cfg->webcontrol_lock_attempts)) { MOTPLS_LOG(EMG, TYPE_STREAM, NO_ERRNO , "Ignoring connection from: %s" , clientip.c_str()); it->conn_time = tm_cnct; - if (app->conf->webcontrol_lock_script != "") { - tmp = app->conf->webcontrol_lock_script + " " + + if (app->cfg->webcontrol_lock_script != "") { + tmp = app->cfg->webcontrol_lock_script + " " + std::to_string(it->userid_fail_nbr) + " " + clientip; util_exec_command(cam, tmp.c_str(), NULL); } return MHD_NO; } else if ((tm_cnct.tv_sec - it->conn_time.tv_sec) >= - (app->conf->webcontrol_lock_minutes*60)) { + (app->cfg->webcontrol_lock_minutes*60)) { it = webu->wb_clients.erase(it); } else { it++; @@ -501,19 +501,19 @@ void cls_webu_ans::mhd_auth_parse() myfree(auth_user); myfree(auth_pass); - auth_len = (int)app->conf->webcontrol_authentication.length(); - col_pos =(char*) strstr(app->conf->webcontrol_authentication.c_str() ,":"); + auth_len = (int)app->cfg->webcontrol_authentication.length(); + col_pos =(char*) strstr(app->cfg->webcontrol_authentication.c_str() ,":"); if (col_pos == NULL) { auth_user = (char*)mymalloc((uint)(auth_len+1)); auth_pass = (char*)mymalloc(2); snprintf(auth_user, (uint)auth_len + 1, "%s" - ,app->conf->webcontrol_authentication.c_str()); + ,app->cfg->webcontrol_authentication.c_str()); snprintf(auth_pass, 2, "%s",""); } else { auth_user = (char*)mymalloc((uint)auth_len - strlen(col_pos) + 1); auth_pass =(char*)mymalloc(strlen(col_pos)); snprintf(auth_user, (uint)auth_len - strlen(col_pos) + 1, "%s" - ,app->conf->webcontrol_authentication.c_str()); + ,app->cfg->webcontrol_authentication.c_str()); snprintf(auth_pass, strlen(col_pos), "%s", col_pos + 1); } } @@ -530,9 +530,9 @@ mhdrslt cls_webu_ans::mhd_auth() snprintf(auth_realm, WEBUI_LEN_PARM, "%s","Motion"); - if (app->conf->webcontrol_authentication == "") { + if (app->cfg->webcontrol_authentication == "") { authenticated = true; - if (app->conf->webcontrol_auth_method != "none") { + if (app->cfg->webcontrol_auth_method != "none") { MOTPLS_LOG(NTC, TYPE_STREAM, NO_ERRNO ,_("No webcontrol user:pass provided")); } return MHD_YES; @@ -542,9 +542,9 @@ mhdrslt cls_webu_ans::mhd_auth() mhd_auth_parse(); } - if (app->conf->webcontrol_auth_method == "basic") { + if (app->cfg->webcontrol_auth_method == "basic") { return mhd_basic(); - } else if (app->conf->webcontrol_auth_method == "digest") { + } else if (app->cfg->webcontrol_auth_method == "digest") { return mhd_digest(); } diff --git a/src/webu_common.cpp b/src/webu_common.cpp index 86ff576d..fdab65a5 100644 --- a/src/webu_common.cpp +++ b/src/webu_common.cpp @@ -52,10 +52,10 @@ bool cls_webu_common::check_finish() void cls_webu_common::set_fps() { if ((webua->cam->detecting_motion == false) && - (app->cam_list[webua->camindx]->conf->stream_motion)) { + (app->cam_list[webua->camindx]->cfg->stream_motion)) { stream_fps = 1; } else { - stream_fps = app->cam_list[webua->camindx]->conf->stream_maxrate; + stream_fps = app->cam_list[webua->camindx]->cfg->stream_maxrate; } } diff --git a/src/webu_getimg.cpp b/src/webu_getimg.cpp index 467647f4..4e4188ed 100644 --- a/src/webu_getimg.cpp +++ b/src/webu_getimg.cpp @@ -119,7 +119,7 @@ static void webu_getimg_norm(cls_camera *cam) cam->stream.norm.jpg_data ,cam->imgs.size_norm ,cam->current_image->image_norm - ,cam->conf->stream_quality + ,cam->cfg->stream_quality ,cam->imgs.width ,cam->imgs.height); cam->stream.norm.consumed = false; @@ -169,7 +169,7 @@ static void webu_getimg_sub(cls_camera *cam) cam->stream.sub.jpg_data ,subsize ,cam->imgs.image_substream - ,cam->conf->stream_quality + ,cam->cfg->stream_quality ,(cam->imgs.width / 2) ,(cam->imgs.height / 2)); } else { @@ -178,7 +178,7 @@ static void webu_getimg_sub(cls_camera *cam) cam->stream.sub.jpg_data ,cam->imgs.size_norm ,cam->current_image->image_norm - ,cam->conf->stream_quality + ,cam->cfg->stream_quality ,cam->imgs.width ,cam->imgs.height); } @@ -227,7 +227,7 @@ static void webu_getimg_motion(cls_camera *cam) cam->stream.motion.jpg_data ,cam->imgs.size_norm ,cam->imgs.image_motion.image_norm - ,cam->conf->stream_quality + ,cam->cfg->stream_quality ,cam->imgs.width ,cam->imgs.height); cam->stream.motion.consumed = false; @@ -261,7 +261,7 @@ static void webu_getimg_source(cls_camera *cam) cam->stream.source.jpg_data ,cam->imgs.size_norm ,cam->imgs.image_virgin - ,cam->conf->stream_quality + ,cam->cfg->stream_quality ,cam->imgs.width ,cam->imgs.height); cam->stream.source.consumed = false; diff --git a/src/webu_html.cpp b/src/webu_html.cpp index 0323db5c..66ab8ee2 100644 --- a/src/webu_html.cpp +++ b/src/webu_html.cpp @@ -1442,11 +1442,11 @@ void cls_webu_html::user_page() FILE *fp = NULL; webua->resp_page = ""; - fp = myfopen(app->conf->webcontrol_html.c_str(), "re"); + fp = myfopen(app->cfg->webcontrol_html.c_str(), "re"); if (fp == NULL) { MOTPLS_LOG(ERR, TYPE_STREAM, NO_ERRNO , _("Invalid user html file: %s") - , app->conf->webcontrol_html.c_str()); + , app->cfg->webcontrol_html.c_str()); } else { while (fgets(response, PATH_MAX-1, fp)) { webua->resp_page += response; @@ -1458,7 +1458,7 @@ void cls_webu_html::user_page() void cls_webu_html::main() { pthread_mutex_lock(&app->mutex_post); - if (app->conf->webcontrol_interface == "user") { + if (app->cfg->webcontrol_interface == "user") { user_page(); } else { default_page(); diff --git a/src/webu_json.cpp b/src/webu_json.cpp index ab0e608d..e362a1e7 100644 --- a/src/webu_json.cpp +++ b/src/webu_json.cpp @@ -36,7 +36,7 @@ void cls_webu_json::parms_item(cls_config *conf, int indx_parm) parm_val = ""; parm_list = ""; - if (app->conf->webcontrol_parms < WEBUI_LEVEL_LIMITED) { + if (app->cfg->webcontrol_parms < WEBUI_LEVEL_LIMITED) { parm_enable = "false"; } else { parm_enable = "true"; @@ -130,7 +130,7 @@ void cls_webu_json::parms_one(cls_config *conf) } /* Allow limited parameters to be read only to the web page */ if ((config_parms[indx_parm].webui_level > - app->conf->webcontrol_parms) && + app->cfg->webcontrol_parms) && (config_parms[indx_parm].webui_level > WEBUI_LEVEL_LIMITED)) { webua->resp_page += @@ -159,12 +159,12 @@ void cls_webu_json::parms_all() webua->resp_page += "{"; webua->resp_page += "\"default\": "; - parms_one(app->conf); + parms_one(app->cfg); for (indx_cam=0; indx_camcam_cnt; indx_cam++) { webua->resp_page += ",\"cam" + std::to_string(app->cam_list[indx_cam]->device_id) + "\": "; - parms_one(app->cam_list[indx_cam]->conf); + parms_one(app->cam_list[indx_cam]->cfg); } webua->resp_page += "}"; } @@ -182,10 +182,10 @@ void cls_webu_json::cameras_list() cam = app->cam_list[indx_cam]; strid =std::to_string(cam->device_id); webua->resp_page += ",\"" + std::to_string(indx_cam) + "\":"; - if (cam->conf->device_name == "") { + if (cam->cfg->device_name == "") { webua->resp_page += "{\"name\": \"camera " + strid + "\""; } else { - webua->resp_page += "{\"name\": \"" + cam->conf->device_name + "\""; + webua->resp_page += "{\"name\": \"" + cam->cfg->device_name + "\""; } webua->resp_page += ",\"id\": " + strid; webua->resp_page += ",\"url\": \"" + webua->hostfull + "/" + strid + "/\"} "; @@ -208,8 +208,8 @@ void cls_webu_json::categories_list() } webua->resp_page += "\"" + std::to_string(indx_cat) + "\": "; - catnm_long = webua->app->conf->cat_desc((enum PARM_CAT)indx_cat, false); - catnm_short = webua->app->conf->cat_desc((enum PARM_CAT)indx_cat, true); + catnm_long = webua->app->cfg->cat_desc((enum PARM_CAT)indx_cat, false); + catnm_short = webua->app->cfg->cat_desc((enum PARM_CAT)indx_cat, true); webua->resp_page += "{\"name\":\"" + catnm_short + "\",\"display\":\"" + catnm_long + "\"}"; @@ -358,7 +358,7 @@ void cls_webu_json::status_vars(int indx_cam) webua->resp_page += "{"; - webua->resp_page += "\"name\":\"" + cam->conf->device_name+"\""; + webua->resp_page += "\"name\":\"" + cam->cfg->device_name+"\""; webua->resp_page += ",\"id\":" + std::to_string(cam->device_id); webua->resp_page += ",\"width\":" + std::to_string(cam->imgs.width); webua->resp_page += ",\"height\":" + std::to_string(cam->imgs.height); diff --git a/src/webu_post.cpp b/src/webu_post.cpp index bfa53346..b5c30747 100644 --- a/src/webu_post.cpp +++ b/src/webu_post.cpp @@ -418,7 +418,7 @@ void cls_webu_post::action_user() MOTPLS_LOG(NTC, TYPE_STREAM, NO_ERRNO , _("Executing user action on cam %d") , cam->device_id); - util_exec_command(cam, cam->conf->on_action_user.c_str(), NULL); + util_exec_command(cam, cam->cfg->on_action_user.c_str(), NULL); } } else { cam = app->cam_list[webua->camindx]; @@ -441,7 +441,7 @@ void cls_webu_post::action_user() MOTPLS_LOG(NTC, TYPE_STREAM, NO_ERRNO , _("Executing user action on cam %d") , cam->device_id); - util_exec_command(cam, cam->conf->on_action_user.c_str(), NULL); + util_exec_command(cam, cam->cfg->on_action_user.c_str(), NULL); } } @@ -463,7 +463,7 @@ void cls_webu_post::write_config() } } - app->conf->parms_write(app); + app->conf_src->parms_write(app); } @@ -507,7 +507,7 @@ void cls_webu_post::config() /* Ignore any requests for parms above webcontrol_parms level. */ indx2=0; while (config_parms[indx2].parm_name != "") { - if ((config_parms[indx2].webui_level > app->conf->webcontrol_parms) || + if ((config_parms[indx2].webui_level > app->conf_src->webcontrol_parms) || (config_parms[indx2].webui_level == WEBUI_LEVEL_NEVER) ) { indx2++; continue; @@ -520,11 +520,11 @@ void cls_webu_post::config() if (config_parms[indx2].parm_name != "") { if (config_parms[indx2].parm_cat == PARM_CAT_00) { - app->conf->edit_set( + app->conf_src->edit_set( config_parms[indx2].parm_name , post_info[indx].key_val); } else { - app->cam_list[webua->camindx]->conf->edit_set( + app->cam_list[webua->camindx]->conf_src->edit_set( config_parms[indx2].parm_name , post_info[indx].key_val); } @@ -558,34 +558,34 @@ void cls_webu_post::ptz() cam = app->cam_list[webua->camindx]; if ((post_cmd == "pan_left") && - (cam->conf->ptz_pan_left != "")) { - cam->frame_skip = cam->conf->ptz_wait; - util_exec_command(cam, cam->conf->ptz_pan_left.c_str(), NULL); + (cam->cfg->ptz_pan_left != "")) { + cam->frame_skip = cam->cfg->ptz_wait; + util_exec_command(cam, cam->cfg->ptz_pan_left.c_str(), NULL); } else if ((post_cmd == "pan_right") && - (cam->conf->ptz_pan_right != "")) { - cam->frame_skip = cam->conf->ptz_wait; - util_exec_command(cam, cam->conf->ptz_pan_right.c_str(), NULL); + (cam->cfg->ptz_pan_right != "")) { + cam->frame_skip = cam->cfg->ptz_wait; + util_exec_command(cam, cam->cfg->ptz_pan_right.c_str(), NULL); } else if ((post_cmd == "tilt_up") && - (cam->conf->ptz_tilt_up != "")) { - cam->frame_skip = cam->conf->ptz_wait; - util_exec_command(cam, cam->conf->ptz_tilt_up.c_str(), NULL); + (cam->cfg->ptz_tilt_up != "")) { + cam->frame_skip = cam->cfg->ptz_wait; + util_exec_command(cam, cam->cfg->ptz_tilt_up.c_str(), NULL); } else if ((post_cmd == "tilt_down") && - (cam->conf->ptz_tilt_down != "")) { - cam->frame_skip = cam->conf->ptz_wait; - util_exec_command(cam, cam->conf->ptz_tilt_down.c_str(), NULL); + (cam->cfg->ptz_tilt_down != "")) { + cam->frame_skip = cam->cfg->ptz_wait; + util_exec_command(cam, cam->cfg->ptz_tilt_down.c_str(), NULL); } else if ((post_cmd == "zoom_in") && - (cam->conf->ptz_zoom_in != "")) { - cam->frame_skip = cam->conf->ptz_wait; - util_exec_command(cam, cam->conf->ptz_zoom_in.c_str(), NULL); + (cam->cfg->ptz_zoom_in != "")) { + cam->frame_skip = cam->cfg->ptz_wait; + util_exec_command(cam, cam->cfg->ptz_zoom_in.c_str(), NULL); } else if ((post_cmd == "zoom_out") && - (cam->conf->ptz_zoom_out != "")) { - cam->frame_skip = cam->conf->ptz_wait; - util_exec_command(cam, cam->conf->ptz_zoom_out.c_str(), NULL); + (cam->cfg->ptz_zoom_out != "")) { + cam->frame_skip = cam->cfg->ptz_wait; + util_exec_command(cam, cam->cfg->ptz_zoom_out.c_str(), NULL); } else { return;