From dac08d3ccb5026bf003ef55bd902dc32a6ff73e1 Mon Sep 17 00:00:00 2001 From: MrDave Date: Mon, 22 Mar 2021 16:07:19 -0600 Subject: [PATCH] Use braces on if statements --- src/alg.cpp | 78 ++- src/alg_sec.cpp | 12 +- src/conf.cpp | 1096 ++++++++++++++++++++-------------------- src/dbse.cpp | 12 +- src/draw.cpp | 51 +- src/event.cpp | 104 ++-- src/exif.cpp | 15 +- src/jpegutils.cpp | 13 +- src/logger.cpp | 28 +- src/mmalcam.cpp | 8 +- src/motion_loop.cpp | 269 ++++++---- src/motionplus.cpp | 38 +- src/movie.cpp | 282 ++++++----- src/netcam.cpp | 348 ++++++++----- src/picture.cpp | 69 ++- src/rotate.cpp | 31 +- src/util.cpp | 36 +- src/video_common.cpp | 2 +- src/video_loopback.cpp | 13 +- src/webu_stream.cpp | 94 ++-- 20 files changed, 1486 insertions(+), 1113 deletions(-) diff --git a/src/alg.cpp b/src/alg.cpp index 97a6a671..f8a1ac80 100644 --- a/src/alg.cpp +++ b/src/alg.cpp @@ -652,7 +652,9 @@ void alg_despeckle(struct ctx_cam *cam) unsigned char *out, *common_buffer; if ((cam->conf->despeckle_filter == "") || cam->current_image->diffs <= 0) { - if (cam->imgs.labelsize_max) cam->imgs.labelsize_max = 0; + if (cam->imgs.labelsize_max) { + cam->imgs.labelsize_max = 0; + } return; } @@ -671,12 +673,16 @@ void alg_despeckle(struct ctx_cam *cam) switch (cam->conf->despeckle_filter[i]) { case 'E': diffs = alg_erode9(out, width, height, common_buffer, 0); - if (diffs == 0) i = len; + if (diffs == 0) { + i = len; + } done = 1; break; case 'e': diffs = alg_erode5(out, width, height, common_buffer, 0); - if (diffs == 0) i = len; + if (diffs == 0) { + i = len; + } done = 1; break; case 'D': @@ -698,7 +704,9 @@ void alg_despeckle(struct ctx_cam *cam) /* If conf.despeckle_filter contains any valid action EeDdl */ if (done) { - if (done != 2) cam->imgs.labelsize_max = 0; // Disable Labeling + if (done != 2) { + cam->imgs.labelsize_max = 0; // Disable Labeling + } cam->current_image->diffs = diffs; return; } else { @@ -725,8 +733,9 @@ void alg_tune_smartmask(struct ctx_cam *cam) for (i = 0; i < motionsize; i++) { /* Decrease smart_mask sensitivity every 5*speed seconds only. */ - if (smartmask[i] > 0) + if (smartmask[i] > 0) { smartmask[i]--; + } /* Increase smart_mask sensitivity based on the buffered values. */ diff = smartmask_buffer[i] / sensitivity; @@ -896,7 +905,9 @@ static int alg_diff_masksmart(struct ctx_cam *cam, unsigned char *new_img) if (cam->event_nr != cam->prev_event) { (*smartmask_buffer) += SMARTMASK_SENSITIVITY_INCR; } - if (!*smartmask_final) curdiff = 0; + if (!*smartmask_final) { + curdiff = 0; + } } smartmask_final++; smartmask_buffer++; @@ -926,7 +937,9 @@ static char alg_diff_fast(struct ctx_cam *cam, int max_n_changes, unsigned char unsigned char *ref = imgs->ref; int curdiff; - if (!step % 2) step++; + if (!step % 2) { + step++; + } max_n_changes /= step; @@ -936,7 +949,7 @@ static char alg_diff_fast(struct ctx_cam *cam, int max_n_changes, unsigned char curdiff = abs(*ref - *new_var); /* Using a temp variable is 12% faster. */ if (curdiff > noise) { diffs++; - if (diffs > max_n_changes){ + if (diffs > max_n_changes) { //MOTION_LOG(ERR, TYPE_ALL, NO_ERRNO //,"Lots of fast diffs %d detected.", diffs); @@ -957,7 +970,7 @@ static char alg_diff_fast(struct ctx_cam *cam, int max_n_changes, unsigned char static void alg_diff_standard(struct ctx_cam *cam) { - if (cam->smartmask_speed == 0){ + if (cam->smartmask_speed == 0) { if (cam->imgs.mask == NULL) { cam->current_image->diffs = alg_diff_nomask(cam, cam->imgs.image_vprvcy); } else { @@ -993,8 +1006,9 @@ void alg_lightswitch(struct ctx_cam *cam) if (cam->conf->lightswitch_percent >= 1 && !cam->lost_connection) { if (cam->current_image->diffs > (cam->imgs.motionsize * cam->conf->lightswitch_percent / 100)) { MOTION_LOG(INF, TYPE_ALL, NO_ERRNO, _("Lightswitch detected")); - if (cam->frame_skip < (unsigned int)cam->conf->lightswitch_frames) + if (cam->frame_skip < (unsigned int)cam->conf->lightswitch_frames) { cam->frame_skip = (unsigned int)cam->conf->lightswitch_frames; + } cam->current_image->diffs = 0; alg_update_reference_frame(cam, RESET_REF_FRAME); } @@ -1024,8 +1038,10 @@ void alg_update_reference_frame(struct ctx_cam *cam, int action) unsigned char *smartmask = cam->imgs.smartmask_final; unsigned char *out = cam->imgs.image_motion.image_norm; - if (cam->lastrate > 5) /* Match rate limit */ + if (cam->lastrate > 5) { + /* Match rate limit */ accept_timer /= (cam->lastrate / 3); + } if (action == UPDATE_REF_FRAME) { /* Black&white only for better performance. */ threshold_ref = cam->noise * EXCLUDE_LEVEL_PERCENT / 100; @@ -1102,10 +1118,18 @@ static void alg_new_location_center(ctx_cam *cam) } /* This allows for the redcross and boxes to be drawn*/ - if (cent->x < 10) cent->x = 15; - if (cent->y < 10) cent->y = 15; - if ((cent->x + 10) > width) cent->x = width - 15; - if ((cent->y + 10) > height) cent->y = height - 15; + if (cent->x < 10) { + cent->x = 15; + } + if (cent->y < 10) { + cent->y = 15; + } + if ((cent->x + 10) > width) { + cent->x = width - 15; + } + if ((cent->y + 10) > height) { + cent->y = height - 15; + } } @@ -1141,15 +1165,15 @@ static void alg_new_location_dist(ctx_cam *cam) /* ToDo: We should store this number for the variance calc...*/ distance_mean += sqrt(pow((x - cent->x), 2) + pow((y - cent->y), 2)); - if (x > cent->x){ + if (x > cent->x) { xdist += x - cent->x; - } else if (x < cent->x){ + } else if (x < cent->x) { xdist += cent->x - x; } - if (y > cent->y){ + if (y > cent->y) { ydist += y - cent->y; - } else if (y < cent->y){ + } else if (y < cent->y) { ydist += cent->y - y; } @@ -1198,27 +1222,27 @@ static void alg_new_location_minmax(ctx_cam *cam) int height = cam->imgs.height; ctx_coord *cent = &cam->current_image->location; - if (cent->maxx > width - 1){ + if (cent->maxx > width - 1) { cent->maxx = width - 1; - } else if (cent->maxx < 0){ + } else if (cent->maxx < 0) { cent->maxx = 0; } - if (cent->maxy > height - 1){ + if (cent->maxy > height - 1) { cent->maxy = height - 1; - } else if (cent->maxy < 0){ + } else if (cent->maxy < 0) { cent->maxy = 0; } - if (cent->minx > width - 1){ + if (cent->minx > width - 1) { cent->minx = width - 1; - } else if (cent->minx < 0){ + } else if (cent->minx < 0) { cent->minx = 0; } - if (cent->miny > height - 1){ + if (cent->miny > height - 1) { cent->miny = height - 1; - } else if (cent->miny < 0){ + } else if (cent->miny < 0) { cent->miny = 0; } diff --git a/src/alg_sec.cpp b/src/alg_sec.cpp index 39f823a6..7898299c 100644 --- a/src/alg_sec.cpp +++ b/src/alg_sec.cpp @@ -62,7 +62,9 @@ static void algsec_img_show(ctx_cam *cam, Mat &mat_src double w = src_weights[indx0]; for (indx1=0; indx1 algmdl.threshold_motion)) { fltr_pos.push_back(r); @@ -482,7 +484,9 @@ static void *algsec_handler(void *arg) } cam->algsec->detecting = false; /*Set the event based isdetected bool */ - if (cam->algsec->models.isdetected) cam->algsec->isdetected = true; + if (cam->algsec->models.isdetected) { + cam->algsec->isdetected = true; + } } else { SLEEP(0,interval) } @@ -578,7 +582,9 @@ void algsec_detect(ctx_cam *cam) { /*This function runs on the camera thread */ #ifdef HAVE_OPENCV - if (cam->algsec->frame_cnt > 0) cam->algsec->frame_cnt--; + if (cam->algsec->frame_cnt > 0) { + cam->algsec->frame_cnt--; + } if (cam->algsec->frame_cnt == 0){ diff --git a/src/conf.cpp b/src/conf.cpp index bb9e7476..63be0691 100644 --- a/src/conf.cpp +++ b/src/conf.cpp @@ -879,7 +879,7 @@ static void conf_edit_set_bool(int &parm_dest, std::string &parm_in) static void conf_edit_get_bool(std::string &parm_dest, int &parm_in) { - if (parm_in == TRUE){ + if (parm_in == TRUE) { parm_dest = "on"; } else { parm_dest = "off"; @@ -888,11 +888,11 @@ static void conf_edit_get_bool(std::string &parm_dest, int &parm_in) static void conf_edit_daemon(struct ctx_motapp *motapp, std::string &parm, enum PARM_ACT pact) { - if (pact == PARM_ACT_DFLT){ + if (pact == PARM_ACT_DFLT) { motapp->daemon = FALSE; - } else if (pact == PARM_ACT_SET){ + } else if (pact == PARM_ACT_SET) { conf_edit_set_bool(motapp->daemon, parm); - } else if (pact == PARM_ACT_GET){ + } else if (pact == PARM_ACT_GET) { conf_edit_get_bool(parm, motapp->daemon); } return; @@ -901,11 +901,11 @@ static void conf_edit_daemon(struct ctx_motapp *motapp, std::string &parm, enum static void conf_edit_setup_mode(struct ctx_motapp *motapp, std::string &parm, int pact) { - if (pact == PARM_ACT_DFLT){ + if (pact == PARM_ACT_DFLT) { motapp->setup_mode = FALSE; - } else if (pact == PARM_ACT_SET){ + } else if (pact == PARM_ACT_SET) { conf_edit_set_bool(motapp->setup_mode, parm); - } else if (pact == PARM_ACT_GET){ + } else if (pact == PARM_ACT_GET) { conf_edit_get_bool(parm, motapp->setup_mode); } return; @@ -916,9 +916,9 @@ static void conf_edit_conf_filename(struct ctx_motapp *motapp, std::string &parm { if (pact == PARM_ACT_DFLT) { motapp->conf_filename = ""; - } else if (pact == PARM_ACT_SET){ + } else if (pact == PARM_ACT_SET) { motapp->conf_filename = parm; - } else if (pact == PARM_ACT_GET){ + } else if (pact == PARM_ACT_GET) { parm = motapp->conf_filename; } return; @@ -929,9 +929,9 @@ static void conf_edit_pid_file(struct ctx_motapp *motapp, std::string &parm, int { if (pact == PARM_ACT_DFLT) { motapp->pid_file = ""; - } else if (pact == PARM_ACT_SET){ + } else if (pact == PARM_ACT_SET) { motapp->pid_file = parm; - } else if (pact == PARM_ACT_GET){ + } else if (pact == PARM_ACT_GET) { parm = motapp->pid_file; } return; @@ -942,9 +942,9 @@ static void conf_edit_log_file(struct ctx_motapp *motapp, std::string &parm, enu { if (pact == PARM_ACT_DFLT) { motapp->log_file = ""; - } else if (pact == PARM_ACT_SET){ + } else if (pact == PARM_ACT_SET) { motapp->log_file = parm; - } else if (pact == PARM_ACT_GET){ + } else if (pact == PARM_ACT_GET) { parm = motapp->log_file; } return; @@ -954,18 +954,18 @@ static void conf_edit_log_file(struct ctx_motapp *motapp, std::string &parm, enu static void conf_edit_log_level(struct ctx_motapp *motapp, std::string &parm, enum PARM_ACT pact) { int parm_in; - if (pact == PARM_ACT_DFLT){ + if (pact == PARM_ACT_DFLT) { motapp->log_level = 6; - } else if (pact == PARM_ACT_SET){ + } else if (pact == PARM_ACT_SET) { parm_in = atoi(parm.c_str()); if ((parm_in < 1) || (parm_in > 9)) { MOTION_LOG(NTC, TYPE_ALL, NO_ERRNO, _("Invalid log_level %d"),parm_in); } else { motapp->log_level = parm_in; } - } else if (pact == PARM_ACT_GET){ + } else if (pact == PARM_ACT_GET) { parm = std::to_string(motapp->log_level); - } else if (pact == PARM_ACT_LIST){ + } else if (pact == PARM_ACT_LIST) { parm = "["; parm = parm + "\"1\",\"2\",\"3\",\"4\",\"5\""; parm = parm + ",\"6\",\"7\",\"8\",\"9\""; @@ -978,9 +978,9 @@ static void conf_edit_log_level(struct ctx_motapp *motapp, std::string &parm, en static void conf_edit_log_type(struct ctx_motapp *motapp, std::string &parm, enum PARM_ACT pact) { - if (pact == PARM_ACT_DFLT){ + if (pact == PARM_ACT_DFLT) { motapp->log_type_str = "ALL"; - } else if (pact == PARM_ACT_SET){ + } else if (pact == PARM_ACT_SET) { if ((parm == "ALL") || (parm == "COR") || (parm == "STR") || (parm == "ENC") || (parm == "NET") || (parm == "DBL") || @@ -990,9 +990,9 @@ static void conf_edit_log_type(struct ctx_motapp *motapp, std::string &parm, enu } else { MOTION_LOG(NTC, TYPE_ALL, NO_ERRNO, _("Invalid log_type %s"),parm.c_str()); } - } else if (pact == PARM_ACT_GET){ + } else if (pact == PARM_ACT_GET) { parm = motapp->log_type_str; - } else if (pact == PARM_ACT_LIST){ + } else if (pact == PARM_ACT_LIST) { parm = "["; parm = parm + "\"ALL\",\"COR\",\"STR\",\"ENC\",\"NET\""; parm = parm + ",\"DBL\",\"EVT\",\"TRK\",\"VID\""; @@ -1004,11 +1004,11 @@ static void conf_edit_log_type(struct ctx_motapp *motapp, std::string &parm, enu static void conf_edit_native_language(struct ctx_motapp *motapp, std::string &parm, enum PARM_ACT pact) { - if (pact == PARM_ACT_DFLT){ + if (pact == PARM_ACT_DFLT) { motapp->native_language = TRUE; - } else if (pact == PARM_ACT_SET){ + } else if (pact == PARM_ACT_SET) { conf_edit_set_bool(motapp->native_language, parm); - } else if (pact == PARM_ACT_GET){ + } else if (pact == PARM_ACT_GET) { conf_edit_get_bool(parm, motapp->native_language); } return; @@ -1023,9 +1023,9 @@ static void conf_edit_camera_name(struct ctx_cam *cam, std::string &parm, enum P { if (pact == PARM_ACT_DFLT) { cam->conf->camera_name= ""; - } else if (pact == PARM_ACT_SET){ + } else if (pact == PARM_ACT_SET) { cam->conf->camera_name = parm; - } else if (pact == PARM_ACT_GET){ + } else if (pact == PARM_ACT_GET) { parm = cam->conf->camera_name; } return; @@ -1044,14 +1044,14 @@ static void conf_edit_camera_id(struct ctx_cam *cam, std::string &parm, enum PAR if (pact == PARM_ACT_DFLT) { cam->conf->camera_id = minval; - } else if (pact == PARM_ACT_SET){ + } else if (pact == PARM_ACT_SET) { parm_in = atoi(parm.c_str()); if (parm_in < minval) { MOTION_LOG(NTC, TYPE_ALL, NO_ERRNO, _("Invalid camera_id %d"),parm_in); } else { cam->conf->camera_id = parm_in; } - } else if (pact == PARM_ACT_GET){ + } else if (pact == PARM_ACT_GET) { parm = std::to_string(cam->conf->camera_id); } return; @@ -1061,16 +1061,16 @@ static void conf_edit_camera_id(struct ctx_cam *cam, std::string &parm, enum PAR static void conf_edit_camera_tmo(struct ctx_cam *cam, std::string &parm, enum PARM_ACT pact) { int parm_in; - if (pact == PARM_ACT_DFLT){ + if (pact == PARM_ACT_DFLT) { cam->conf->camera_tmo = 30; - } else if (pact == PARM_ACT_SET){ + } else if (pact == PARM_ACT_SET) { parm_in = atoi(parm.c_str()); if (parm_in < 1) { MOTION_LOG(NTC, TYPE_ALL, NO_ERRNO, _("Invalid camera_tmo %d"),parm_in); } else { cam->conf->camera_tmo = parm_in; } - } else if (pact == PARM_ACT_GET){ + } else if (pact == PARM_ACT_GET) { parm = std::to_string(cam->conf->camera_tmo); } return; @@ -1081,9 +1081,9 @@ static void conf_edit_camera_dir(struct ctx_cam *cam, std::string &parm, enum PA { if (pact == PARM_ACT_DFLT) { cam->conf->camera_dir = ""; - } else if (pact == PARM_ACT_SET){ + } else if (pact == PARM_ACT_SET) { cam->conf->camera_dir = parm; - } else if (pact == PARM_ACT_GET){ + } else if (pact == PARM_ACT_GET) { parm = cam->conf->camera_dir; } return; @@ -1094,9 +1094,9 @@ static void conf_edit_target_dir(struct ctx_cam *cam, std::string &parm, enum PA { if (pact == PARM_ACT_DFLT) { cam->conf->target_dir = "."; - } else if (pact == PARM_ACT_SET){ + } else if (pact == PARM_ACT_SET) { cam->conf->target_dir = parm; - } else if (pact == PARM_ACT_GET){ + } else if (pact == PARM_ACT_GET) { parm = cam->conf->target_dir; } return; @@ -1106,16 +1106,16 @@ static void conf_edit_target_dir(struct ctx_cam *cam, std::string &parm, enum PA static void conf_edit_watchdog_tmo(struct ctx_cam *cam, std::string &parm, enum PARM_ACT pact) { int parm_in; - if (pact == PARM_ACT_DFLT){ + if (pact == PARM_ACT_DFLT) { cam->conf->watchdog_tmo = 30; - } else if (pact == PARM_ACT_SET){ + } else if (pact == PARM_ACT_SET) { parm_in = atoi(parm.c_str()); if (parm_in < 1) { MOTION_LOG(NTC, TYPE_ALL, NO_ERRNO, _("Invalid watchdog timeout %d"),parm_in); } else { cam->conf->watchdog_tmo = parm_in; } - } else if (pact == PARM_ACT_GET){ + } else if (pact == PARM_ACT_GET) { parm = std::to_string(cam->conf->watchdog_tmo); } return; @@ -1125,16 +1125,16 @@ static void conf_edit_watchdog_tmo(struct ctx_cam *cam, std::string &parm, enum static void conf_edit_watchdog_kill(struct ctx_cam *cam, std::string &parm, enum PARM_ACT pact) { int parm_in; - if (pact == PARM_ACT_DFLT){ + if (pact == PARM_ACT_DFLT) { cam->conf->watchdog_kill = 10; - } else if (pact == PARM_ACT_SET){ + } else if (pact == PARM_ACT_SET) { parm_in = atoi(parm.c_str()); if (parm_in < 1) { MOTION_LOG(NTC, TYPE_ALL, NO_ERRNO, _("Invalid watchdog kill timeout %d"),parm_in); } else { cam->conf->watchdog_kill = parm_in; } - } else if (pact == PARM_ACT_GET){ + } else if (pact == PARM_ACT_GET) { parm = std::to_string(cam->conf->watchdog_kill); } return; @@ -1145,9 +1145,9 @@ static void conf_edit_v4l2_device(struct ctx_cam *cam, std::string &parm, enum P { if (pact == PARM_ACT_DFLT) { cam->conf->v4l2_device = "/dev/video0"; - } else if (pact == PARM_ACT_SET){ + } else if (pact == PARM_ACT_SET) { cam->conf->v4l2_device = parm; - } else if (pact == PARM_ACT_GET){ + } else if (pact == PARM_ACT_GET) { parm = cam->conf->v4l2_device; } return; @@ -1158,9 +1158,9 @@ static void conf_edit_v4l2_params(struct ctx_cam *cam, std::string &parm, enum P { if (pact == PARM_ACT_DFLT) { cam->conf->v4l2_params = ""; - } else if (pact == PARM_ACT_SET){ + } else if (pact == PARM_ACT_SET) { cam->conf->v4l2_params = parm; - } else if (pact == PARM_ACT_GET){ + } else if (pact == PARM_ACT_GET) { parm = cam->conf->v4l2_params; } return; @@ -1171,9 +1171,9 @@ static void conf_edit_netcam_url(struct ctx_cam *cam, std::string &parm, enum PA { if (pact == PARM_ACT_DFLT) { cam->conf->netcam_url = ""; - } else if (pact == PARM_ACT_SET){ + } else if (pact == PARM_ACT_SET) { cam->conf->netcam_url = parm; - } else if (pact == PARM_ACT_GET){ + } else if (pact == PARM_ACT_GET) { parm = cam->conf->netcam_url; } return; @@ -1184,9 +1184,9 @@ static void conf_edit_netcam_params(struct ctx_cam *cam, std::string &parm, enum { if (pact == PARM_ACT_DFLT) { cam->conf->netcam_params = ""; - } else if (pact == PARM_ACT_SET){ + } else if (pact == PARM_ACT_SET) { cam->conf->netcam_params = parm; - } else if (pact == PARM_ACT_GET){ + } else if (pact == PARM_ACT_GET) { parm = cam->conf->netcam_params; } return; @@ -1197,9 +1197,9 @@ static void conf_edit_netcam_high_url(struct ctx_cam *cam, std::string &parm, en { if (pact == PARM_ACT_DFLT) { cam->conf->netcam_high_url = ""; - } else if (pact == PARM_ACT_SET){ + } else if (pact == PARM_ACT_SET) { cam->conf->netcam_high_url = parm; - } else if (pact == PARM_ACT_GET){ + } else if (pact == PARM_ACT_GET) { parm = cam->conf->netcam_high_url; } return; @@ -1210,9 +1210,9 @@ static void conf_edit_netcam_high_params(struct ctx_cam *cam, std::string &parm, { if (pact == PARM_ACT_DFLT) { cam->conf->netcam_high_params = ""; - } else if (pact == PARM_ACT_SET){ + } else if (pact == PARM_ACT_SET) { cam->conf->netcam_high_params = parm; - } else if (pact == PARM_ACT_GET){ + } else if (pact == PARM_ACT_GET) { parm = cam->conf->netcam_high_params; } return; @@ -1223,9 +1223,9 @@ static void conf_edit_netcam_userpass(struct ctx_cam *cam, std::string &parm, en { if (pact == PARM_ACT_DFLT) { cam->conf->netcam_userpass = ""; - } else if (pact == PARM_ACT_SET){ + } else if (pact == PARM_ACT_SET) { cam->conf->netcam_userpass = parm; - } else if (pact == PARM_ACT_GET){ + } else if (pact == PARM_ACT_GET) { parm = cam->conf->netcam_userpass; } return; @@ -1236,9 +1236,9 @@ static void conf_edit_mmalcam_name(struct ctx_cam *cam, std::string &parm, enum { if (pact == PARM_ACT_DFLT) { cam->conf->mmalcam_name = ""; - } else if (pact == PARM_ACT_SET){ + } else if (pact == PARM_ACT_SET) { cam->conf->mmalcam_name = parm; - } else if (pact == PARM_ACT_GET){ + } else if (pact == PARM_ACT_GET) { parm = cam->conf->mmalcam_name; } return; @@ -1249,9 +1249,9 @@ static void conf_edit_mmalcam_params(struct ctx_cam *cam, std::string &parm, enu { if (pact == PARM_ACT_DFLT) { cam->conf->mmalcam_params = ""; - } else if (pact == PARM_ACT_SET){ + } else if (pact == PARM_ACT_SET) { cam->conf->mmalcam_params = parm; - } else if (pact == PARM_ACT_GET){ + } else if (pact == PARM_ACT_GET) { parm = cam->conf->mmalcam_params; } return; @@ -1261,9 +1261,9 @@ static void conf_edit_mmalcam_params(struct ctx_cam *cam, std::string &parm, enu static void conf_edit_width(struct ctx_cam *cam, std::string &parm, enum PARM_ACT pact) { int parm_in; - if (pact == PARM_ACT_DFLT){ + if (pact == PARM_ACT_DFLT) { cam->conf->width = 640; - } else if (pact == PARM_ACT_SET){ + } else if (pact == PARM_ACT_SET) { parm_in = atoi(parm.c_str()); if ((parm_in < 64) || (parm_in > 9999)) { MOTION_LOG(NTC, TYPE_ALL, NO_ERRNO, _("Invalid width %d"),parm_in); @@ -1277,7 +1277,7 @@ static void conf_edit_width(struct ctx_cam *cam, std::string &parm, enum PARM_AC } else { cam->conf->width = parm_in; } - } else if (pact == PARM_ACT_GET){ + } else if (pact == PARM_ACT_GET) { parm = std::to_string(cam->conf->width); } return; @@ -1287,9 +1287,9 @@ static void conf_edit_width(struct ctx_cam *cam, std::string &parm, enum PARM_AC static void conf_edit_height(struct ctx_cam *cam, std::string &parm, enum PARM_ACT pact) { int parm_in; - if (pact == PARM_ACT_DFLT){ + if (pact == PARM_ACT_DFLT) { cam->conf->height = 480; - } else if (pact == PARM_ACT_SET){ + } else if (pact == PARM_ACT_SET) { parm_in = atoi(parm.c_str()); if ((parm_in < 64) || (parm_in > 9999)) { MOTION_LOG(NTC, TYPE_ALL, NO_ERRNO, _("Invalid height %d"),parm_in); @@ -1303,7 +1303,7 @@ static void conf_edit_height(struct ctx_cam *cam, std::string &parm, enum PARM_A } else { cam->conf->height = parm_in; } - } else if (pact == PARM_ACT_GET){ + } else if (pact == PARM_ACT_GET) { parm = std::to_string(cam->conf->height); } return; @@ -1313,16 +1313,16 @@ static void conf_edit_height(struct ctx_cam *cam, std::string &parm, enum PARM_A static void conf_edit_framerate(struct ctx_cam *cam, std::string &parm, enum PARM_ACT pact) { int parm_in; - if (pact == PARM_ACT_DFLT){ + if (pact == PARM_ACT_DFLT) { cam->conf->framerate = 15; - } else if (pact == PARM_ACT_SET){ + } else if (pact == PARM_ACT_SET) { parm_in = atoi(parm.c_str()); if ((parm_in < 2) || (parm_in > 100)) { MOTION_LOG(NTC, TYPE_ALL, NO_ERRNO, _("Invalid framerate %d"),parm_in); } else { cam->conf->framerate = parm_in; } - } else if (pact == PARM_ACT_GET){ + } else if (pact == PARM_ACT_GET) { parm = std::to_string(cam->conf->framerate); } return; @@ -1332,16 +1332,16 @@ static void conf_edit_framerate(struct ctx_cam *cam, std::string &parm, enum PAR static void conf_edit_minimum_frame_time(struct ctx_cam *cam, std::string &parm, enum PARM_ACT pact) { int parm_in; - if (pact == PARM_ACT_DFLT){ + if (pact == PARM_ACT_DFLT) { cam->conf->minimum_frame_time = 0; - } else if (pact == PARM_ACT_SET){ + } else if (pact == PARM_ACT_SET) { parm_in = atoi(parm.c_str()); if ((parm_in < 0) || (parm_in > 2147483647)) { MOTION_LOG(NTC, TYPE_ALL, NO_ERRNO, _("Invalid minimum_frame_time %d"),parm_in); } else { cam->conf->minimum_frame_time = parm_in; } - } else if (pact == PARM_ACT_GET){ + } else if (pact == PARM_ACT_GET) { parm = std::to_string(cam->conf->minimum_frame_time); } return; @@ -1351,9 +1351,9 @@ static void conf_edit_minimum_frame_time(struct ctx_cam *cam, std::string &parm, static void conf_edit_rotate(struct ctx_cam *cam, std::string &parm, enum PARM_ACT pact) { int parm_in; - if (pact == PARM_ACT_DFLT){ + if (pact == PARM_ACT_DFLT) { cam->conf->rotate = 0; - } else if (pact == PARM_ACT_SET){ + } else if (pact == PARM_ACT_SET) { parm_in = atoi(parm.c_str()); if ((parm_in != 0) && (parm_in != 90) && (parm_in != 180) && (parm_in != 270) ) { @@ -1361,7 +1361,7 @@ static void conf_edit_rotate(struct ctx_cam *cam, std::string &parm, enum PARM_A } else { cam->conf->rotate = parm_in; } - } else if (pact == PARM_ACT_GET){ + } else if (pact == PARM_ACT_GET) { parm = std::to_string(cam->conf->rotate); } else if (pact == PARM_ACT_LIST) { parm = "[\"0\",\"90\",\"180\",\"270\"]"; @@ -1374,7 +1374,7 @@ static void conf_edit_flip_axis(struct ctx_cam *cam, std::string &parm, enum PAR { if (pact == PARM_ACT_DFLT) { cam->conf->flip_axis = "none"; - } else if (pact == PARM_ACT_SET){ + } else if (pact == PARM_ACT_SET) { if ((parm == "none") || (parm == "v") || (parm == "h")) { cam->conf->flip_axis = parm; } else if (parm == "") { @@ -1382,7 +1382,7 @@ static void conf_edit_flip_axis(struct ctx_cam *cam, std::string &parm, enum PAR } else { MOTION_LOG(NTC, TYPE_ALL, NO_ERRNO, _("Invalid flip_axis %s"), parm.c_str()); } - } else if (pact == PARM_ACT_GET){ + } else if (pact == PARM_ACT_GET) { parm = cam->conf->flip_axis; } else if (pact == PARM_ACT_LIST) { parm = "[\"none\",\"v\",\"h\"]"; @@ -1396,7 +1396,7 @@ static void conf_edit_locate_motion_mode(struct ctx_cam *cam, std::string &parm, { if (pact == PARM_ACT_DFLT) { cam->conf->locate_motion_mode = "off"; - } else if (pact == PARM_ACT_SET){ + } else if (pact == PARM_ACT_SET) { if ((parm == "off") || (parm == "on") || (parm == "preview")) { cam->conf->locate_motion_mode = parm; } else if (parm == "") { @@ -1404,7 +1404,7 @@ static void conf_edit_locate_motion_mode(struct ctx_cam *cam, std::string &parm, } else { MOTION_LOG(NTC, TYPE_ALL, NO_ERRNO, _("Invalid locate_motion_mode %s"), parm.c_str()); } - } else if (pact == PARM_ACT_GET){ + } else if (pact == PARM_ACT_GET) { parm = cam->conf->locate_motion_mode; } else if (pact == PARM_ACT_LIST) { parm = "[\"off\",\"on\",\"preview\"]"; @@ -1417,7 +1417,7 @@ static void conf_edit_locate_motion_style(struct ctx_cam *cam, std::string &parm { if (pact == PARM_ACT_DFLT) { cam->conf->locate_motion_style = "box"; - } else if (pact == PARM_ACT_SET){ + } else if (pact == PARM_ACT_SET) { if ((parm == "box") || (parm == "redbox") || (parm == "cross") || (parm == "redcross")) { cam->conf->locate_motion_style = parm; @@ -1426,7 +1426,7 @@ static void conf_edit_locate_motion_style(struct ctx_cam *cam, std::string &parm } else { MOTION_LOG(NTC, TYPE_ALL, NO_ERRNO, _("Invalid locate_motion_style %s"), parm.c_str()); } - } else if (pact == PARM_ACT_GET){ + } else if (pact == PARM_ACT_GET) { parm = cam->conf->locate_motion_style; } else if (pact == PARM_ACT_LIST) { parm = "[\"box\",\"redbox\",\"cross\",\"redcross\"]"; @@ -1439,9 +1439,9 @@ static void conf_edit_text_left(struct ctx_cam *cam, std::string &parm, enum PAR { if (pact == PARM_ACT_DFLT) { cam->conf->text_left = ""; - } else if (pact == PARM_ACT_SET){ + } else if (pact == PARM_ACT_SET) { cam->conf->text_left = parm; - } else if (pact == PARM_ACT_GET){ + } else if (pact == PARM_ACT_GET) { parm = cam->conf->text_left; } return; @@ -1452,9 +1452,9 @@ static void conf_edit_text_right(struct ctx_cam *cam, std::string &parm, enum PA { if (pact == PARM_ACT_DFLT) { cam->conf->text_right = "%Y-%m-%d\\n%T"; - } else if (pact == PARM_ACT_SET){ + } else if (pact == PARM_ACT_SET) { cam->conf->text_right = parm; - } else if (pact == PARM_ACT_GET){ + } else if (pact == PARM_ACT_GET) { parm = cam->conf->text_right; } return; @@ -1463,11 +1463,11 @@ static void conf_edit_text_right(struct ctx_cam *cam, std::string &parm, enum PA static void conf_edit_text_changes(struct ctx_cam *cam, std::string &parm, enum PARM_ACT pact) { - if (pact == PARM_ACT_DFLT){ + if (pact == PARM_ACT_DFLT) { cam->conf->text_changes = FALSE; - } else if (pact == PARM_ACT_SET){ + } else if (pact == PARM_ACT_SET) { conf_edit_set_bool(cam->conf->text_changes, parm); - } else if (pact == PARM_ACT_GET){ + } else if (pact == PARM_ACT_GET) { conf_edit_get_bool(parm, cam->conf->text_changes); } return; @@ -1477,18 +1477,18 @@ static void conf_edit_text_changes(struct ctx_cam *cam, std::string &parm, enum static void conf_edit_text_scale(struct ctx_cam *cam, std::string &parm, enum PARM_ACT pact) { int parm_in; - if (pact == PARM_ACT_DFLT){ + if (pact == PARM_ACT_DFLT) { cam->conf->text_scale = 1; - } else if (pact == PARM_ACT_SET){ + } else if (pact == PARM_ACT_SET) { parm_in = atoi(parm.c_str()); if ((parm_in < 1) || (parm_in > 10)) { MOTION_LOG(NTC, TYPE_ALL, NO_ERRNO, _("Invalid text_scale %d"),parm_in); } else { cam->conf->text_scale = parm_in; } - } else if (pact == PARM_ACT_GET){ + } else if (pact == PARM_ACT_GET) { parm = std::to_string(cam->conf->text_scale); - } else if (pact == PARM_ACT_LIST){ + } else if (pact == PARM_ACT_LIST) { parm = "["; parm = parm + "\"1\",\"2\",\"3\",\"4\",\"5\""; parm = parm + ",\"6\",\"7\",\"8\",\"9\",\"10\""; @@ -1502,9 +1502,9 @@ static void conf_edit_text_event(struct ctx_cam *cam, std::string &parm, enum PA { if (pact == PARM_ACT_DFLT) { cam->conf->text_event = "%Y%m%d%H%M%S"; - } else if (pact == PARM_ACT_SET){ + } else if (pact == PARM_ACT_SET) { cam->conf->text_event = parm; - } else if (pact == PARM_ACT_GET){ + } else if (pact == PARM_ACT_GET) { parm = cam->conf->text_event; } return; @@ -1513,11 +1513,11 @@ static void conf_edit_text_event(struct ctx_cam *cam, std::string &parm, enum PA static void conf_edit_emulate_motion(struct ctx_cam *cam, std::string &parm, enum PARM_ACT pact) { - if (pact == PARM_ACT_DFLT){ + if (pact == PARM_ACT_DFLT) { cam->conf->emulate_motion = FALSE; - } else if (pact == PARM_ACT_SET){ + } else if (pact == PARM_ACT_SET) { conf_edit_set_bool(cam->conf->emulate_motion, parm); - } else if (pact == PARM_ACT_GET){ + } else if (pact == PARM_ACT_GET) { conf_edit_get_bool(parm, cam->conf->emulate_motion); } return; @@ -1527,16 +1527,16 @@ static void conf_edit_emulate_motion(struct ctx_cam *cam, std::string &parm, enu static void conf_edit_primary_method(struct ctx_cam *cam, std::string &parm, enum PARM_ACT pact) { int parm_in; - if (pact == PARM_ACT_DFLT){ + if (pact == PARM_ACT_DFLT) { cam->conf->primary_method = 0; - } else if (pact == PARM_ACT_SET){ + } else if (pact == PARM_ACT_SET) { parm_in = atoi(parm.c_str()); if ((parm_in < 0) || (parm_in > 2)) { MOTION_LOG(NTC, TYPE_ALL, NO_ERRNO, _("Invalid primary method %d"),parm_in); } else { cam->conf->primary_method = parm_in; } - } else if (pact == PARM_ACT_GET){ + } else if (pact == PARM_ACT_GET) { parm = std::to_string(cam->conf->primary_method); } return; @@ -1546,16 +1546,16 @@ static void conf_edit_primary_method(struct ctx_cam *cam, std::string &parm, enu static void conf_edit_threshold(struct ctx_cam *cam, std::string &parm, enum PARM_ACT pact) { int parm_in; - if (pact == PARM_ACT_DFLT){ + if (pact == PARM_ACT_DFLT) { cam->conf->threshold = 1500; - } else if (pact == PARM_ACT_SET){ + } else if (pact == PARM_ACT_SET) { parm_in = atoi(parm.c_str()); if ((parm_in < 1) || (parm_in > 2147483647)) { MOTION_LOG(NTC, TYPE_ALL, NO_ERRNO, _("Invalid threshold %d"),parm_in); } else { cam->conf->threshold = parm_in; } - } else if (pact == PARM_ACT_GET){ + } else if (pact == PARM_ACT_GET) { parm = std::to_string(cam->conf->threshold); } return; @@ -1565,16 +1565,16 @@ static void conf_edit_threshold(struct ctx_cam *cam, std::string &parm, enum PAR static void conf_edit_threshold_maximum(struct ctx_cam *cam, std::string &parm, enum PARM_ACT pact) { int parm_in; - if (pact == PARM_ACT_DFLT){ + if (pact == PARM_ACT_DFLT) { cam->conf->threshold_maximum = 0; - } else if (pact == PARM_ACT_SET){ + } else if (pact == PARM_ACT_SET) { parm_in = atoi(parm.c_str()); if ((parm_in < 0) ) { MOTION_LOG(NTC, TYPE_ALL, NO_ERRNO, _("Invalid threshold_maximum %d"),parm_in); } else { cam->conf->threshold_maximum = parm_in; } - } else if (pact == PARM_ACT_GET){ + } else if (pact == PARM_ACT_GET) { parm = std::to_string(cam->conf->threshold_maximum); } return; @@ -1584,16 +1584,16 @@ static void conf_edit_threshold_maximum(struct ctx_cam *cam, std::string &parm, static void conf_edit_threshold_sdevx(struct ctx_cam *cam, std::string &parm, enum PARM_ACT pact) { int parm_in; - if (pact == PARM_ACT_DFLT){ + if (pact == PARM_ACT_DFLT) { cam->conf->threshold_sdevx = 0; - } else if (pact == PARM_ACT_SET){ + } else if (pact == PARM_ACT_SET) { parm_in = atoi(parm.c_str()); if ((parm_in < 0) ) { MOTION_LOG(NTC, TYPE_ALL, NO_ERRNO, _("Invalid threshold_sdevx %d"),parm_in); } else { cam->conf->threshold_sdevx = parm_in; } - } else if (pact == PARM_ACT_GET){ + } else if (pact == PARM_ACT_GET) { parm = std::to_string(cam->conf->threshold_sdevx); } return; @@ -1603,16 +1603,16 @@ static void conf_edit_threshold_sdevx(struct ctx_cam *cam, std::string &parm, en static void conf_edit_threshold_sdevy(struct ctx_cam *cam, std::string &parm, enum PARM_ACT pact) { int parm_in; - if (pact == PARM_ACT_DFLT){ + if (pact == PARM_ACT_DFLT) { cam->conf->threshold_sdevy = 0; - } else if (pact == PARM_ACT_SET){ + } else if (pact == PARM_ACT_SET) { parm_in = atoi(parm.c_str()); if ((parm_in < 0) ) { MOTION_LOG(NTC, TYPE_ALL, NO_ERRNO, _("Invalid threshold_sdevy %d"),parm_in); } else { cam->conf->threshold_sdevy = parm_in; } - } else if (pact == PARM_ACT_GET){ + } else if (pact == PARM_ACT_GET) { parm = std::to_string(cam->conf->threshold_sdevy); } return; @@ -1622,16 +1622,16 @@ static void conf_edit_threshold_sdevy(struct ctx_cam *cam, std::string &parm, en static void conf_edit_threshold_sdevxy(struct ctx_cam *cam, std::string &parm, enum PARM_ACT pact) { int parm_in; - if (pact == PARM_ACT_DFLT){ + if (pact == PARM_ACT_DFLT) { cam->conf->threshold_sdevxy = 0; - } else if (pact == PARM_ACT_SET){ + } else if (pact == PARM_ACT_SET) { parm_in = atoi(parm.c_str()); if ((parm_in < 0) ) { MOTION_LOG(NTC, TYPE_ALL, NO_ERRNO, _("Invalid threshold_sdevxy %d"),parm_in); } else { cam->conf->threshold_sdevxy = parm_in; } - } else if (pact == PARM_ACT_GET){ + } else if (pact == PARM_ACT_GET) { parm = std::to_string(cam->conf->threshold_sdevxy); } return; @@ -1641,16 +1641,16 @@ static void conf_edit_threshold_sdevxy(struct ctx_cam *cam, std::string &parm, e static void conf_edit_threshold_ratio(struct ctx_cam *cam, std::string &parm, enum PARM_ACT pact) { int parm_in; - if (pact == PARM_ACT_DFLT){ + if (pact == PARM_ACT_DFLT) { cam->conf->threshold_ratio = 999999; /* Arbitrary large value */ - } else if (pact == PARM_ACT_SET){ + } else if (pact == PARM_ACT_SET) { parm_in = atoi(parm.c_str()); if ((parm_in < 0) ) { MOTION_LOG(NTC, TYPE_ALL, NO_ERRNO, _("Invalid threshold_ratio %d"),parm_in); } else { cam->conf->threshold_ratio = parm_in; } - } else if (pact == PARM_ACT_GET){ + } else if (pact == PARM_ACT_GET) { parm = std::to_string(cam->conf->threshold_ratio); } return; @@ -1659,11 +1659,11 @@ static void conf_edit_threshold_ratio(struct ctx_cam *cam, std::string &parm, en static void conf_edit_threshold_tune(struct ctx_cam *cam, std::string &parm, enum PARM_ACT pact) { - if (pact == PARM_ACT_DFLT){ + if (pact == PARM_ACT_DFLT) { cam->conf->threshold_tune = FALSE; - } else if (pact == PARM_ACT_SET){ + } else if (pact == PARM_ACT_SET) { conf_edit_set_bool(cam->conf->threshold_tune, parm); - } else if (pact == PARM_ACT_GET){ + } else if (pact == PARM_ACT_GET) { conf_edit_get_bool(parm, cam->conf->threshold_tune); } return; @@ -1673,16 +1673,16 @@ static void conf_edit_threshold_tune(struct ctx_cam *cam, std::string &parm, enu static void conf_edit_secondary_interval(struct ctx_cam *cam, std::string &parm, enum PARM_ACT pact) { int parm_in; - if (pact == PARM_ACT_DFLT){ + if (pact == PARM_ACT_DFLT) { cam->conf->secondary_interval = 0; - } else if (pact == PARM_ACT_SET){ + } else if (pact == PARM_ACT_SET) { parm_in = atoi(parm.c_str()); if ((parm_in < 0) ) { MOTION_LOG(NTC, TYPE_ALL, NO_ERRNO, _("Invalid secondary_interval %d"),parm_in); } else { cam->conf->secondary_interval = parm_in; } - } else if (pact == PARM_ACT_GET){ + } else if (pact == PARM_ACT_GET) { parm = std::to_string(cam->conf->secondary_interval); } return; @@ -1692,16 +1692,16 @@ static void conf_edit_secondary_interval(struct ctx_cam *cam, std::string &parm, static void conf_edit_secondary_method(struct ctx_cam *cam, std::string &parm, enum PARM_ACT pact) { int parm_in; - if (pact == PARM_ACT_DFLT){ + if (pact == PARM_ACT_DFLT) { cam->conf->secondary_method = 0; - } else if (pact == PARM_ACT_SET){ + } else if (pact == PARM_ACT_SET) { parm_in = atoi(parm.c_str()); if ((parm_in < 0) ) { MOTION_LOG(NTC, TYPE_ALL, NO_ERRNO, _("Invalid secondary_method %d"),parm_in); } else { cam->conf->secondary_method = parm_in; } - } else if (pact == PARM_ACT_GET){ + } else if (pact == PARM_ACT_GET) { parm = std::to_string(cam->conf->secondary_method); } return; @@ -1712,9 +1712,9 @@ static void conf_edit_secondary_params(struct ctx_cam *cam, std::string &parm, e { if (pact == PARM_ACT_DFLT) { cam->conf->secondary_params = ""; - } else if (pact == PARM_ACT_SET){ + } else if (pact == PARM_ACT_SET) { cam->conf->secondary_params = parm; - } else if (pact == PARM_ACT_GET){ + } else if (pact == PARM_ACT_GET) { parm = cam->conf->secondary_params; } return; @@ -1724,16 +1724,16 @@ static void conf_edit_secondary_params(struct ctx_cam *cam, std::string &parm, e static void conf_edit_noise_level(struct ctx_cam *cam, std::string &parm, enum PARM_ACT pact) { int parm_in; - if (pact == PARM_ACT_DFLT){ + if (pact == PARM_ACT_DFLT) { cam->conf->noise_level = 32; - } else if (pact == PARM_ACT_SET){ + } else if (pact == PARM_ACT_SET) { parm_in = atoi(parm.c_str()); if ((parm_in < 1) || (parm_in > 255)) { MOTION_LOG(NTC, TYPE_ALL, NO_ERRNO, _("Invalid noise_level %d"),parm_in); } else { cam->conf->noise_level = parm_in; } - } else if (pact == PARM_ACT_GET){ + } else if (pact == PARM_ACT_GET) { parm = std::to_string(cam->conf->noise_level); } return; @@ -1742,11 +1742,11 @@ static void conf_edit_noise_level(struct ctx_cam *cam, std::string &parm, enum P static void conf_edit_noise_tune(struct ctx_cam *cam, std::string &parm, enum PARM_ACT pact) { - if (pact == PARM_ACT_DFLT){ + if (pact == PARM_ACT_DFLT) { cam->conf->noise_tune = TRUE; - } else if (pact == PARM_ACT_SET){ + } else if (pact == PARM_ACT_SET) { conf_edit_set_bool(cam->conf->noise_tune, parm); - } else if (pact == PARM_ACT_GET){ + } else if (pact == PARM_ACT_GET) { conf_edit_get_bool(parm, cam->conf->noise_tune); } return; @@ -1757,9 +1757,9 @@ static void conf_edit_despeckle_filter(struct ctx_cam *cam, std::string &parm, e { if (pact == PARM_ACT_DFLT) { cam->conf->despeckle_filter = ""; - } else if (pact == PARM_ACT_SET){ + } else if (pact == PARM_ACT_SET) { cam->conf->despeckle_filter = parm; - } else if (pact == PARM_ACT_GET){ + } else if (pact == PARM_ACT_GET) { parm = cam->conf->despeckle_filter; } return; @@ -1770,9 +1770,9 @@ static void conf_edit_area_detect(struct ctx_cam *cam, std::string &parm, enum P { if (pact == PARM_ACT_DFLT) { cam->conf->area_detect = ""; - } else if (pact == PARM_ACT_SET){ + } else if (pact == PARM_ACT_SET) { cam->conf->area_detect = parm; - } else if (pact == PARM_ACT_GET){ + } else if (pact == PARM_ACT_GET) { parm = cam->conf->area_detect; } return; @@ -1783,9 +1783,9 @@ static void conf_edit_mask_file(struct ctx_cam *cam, std::string &parm, enum PAR { if (pact == PARM_ACT_DFLT) { cam->conf->mask_file = ""; - } else if (pact == PARM_ACT_SET){ + } else if (pact == PARM_ACT_SET) { cam->conf->mask_file = parm; - } else if (pact == PARM_ACT_GET){ + } else if (pact == PARM_ACT_GET) { parm = cam->conf->mask_file; } return; @@ -1796,9 +1796,9 @@ static void conf_edit_mask_privacy(struct ctx_cam *cam, std::string &parm, enum { if (pact == PARM_ACT_DFLT) { cam->conf->mask_privacy = ""; - } else if (pact == PARM_ACT_SET){ + } else if (pact == PARM_ACT_SET) { cam->conf->mask_privacy = parm; - } else if (pact == PARM_ACT_GET){ + } else if (pact == PARM_ACT_GET) { parm = cam->conf->mask_privacy; } return; @@ -1808,18 +1808,18 @@ static void conf_edit_mask_privacy(struct ctx_cam *cam, std::string &parm, enum static void conf_edit_smart_mask_speed(struct ctx_cam *cam, std::string &parm, enum PARM_ACT pact) { int parm_in; - if (pact == PARM_ACT_DFLT){ + if (pact == PARM_ACT_DFLT) { cam->conf->smart_mask_speed = 0; - } else if (pact == PARM_ACT_SET){ + } else if (pact == PARM_ACT_SET) { parm_in = atoi(parm.c_str()); if ((parm_in < 0) || (parm_in > 10)) { MOTION_LOG(NTC, TYPE_ALL, NO_ERRNO, _("Invalid smart_mask_speed %d"),parm_in); } else { cam->conf->smart_mask_speed = parm_in; } - } else if (pact == PARM_ACT_GET){ + } else if (pact == PARM_ACT_GET) { parm = std::to_string(cam->conf->smart_mask_speed); - } else if (pact == PARM_ACT_LIST){ + } else if (pact == PARM_ACT_LIST) { parm = "["; parm = parm + "\"0\",\"1\",\"2\",\"3\",\"4\",\"5\""; parm = parm + ",\"6\",\"7\",\"8\",\"9\",\"10\""; @@ -1832,16 +1832,16 @@ static void conf_edit_smart_mask_speed(struct ctx_cam *cam, std::string &parm, e static void conf_edit_lightswitch_percent(struct ctx_cam *cam, std::string &parm, enum PARM_ACT pact) { int parm_in; - if (pact == PARM_ACT_DFLT){ + if (pact == PARM_ACT_DFLT) { cam->conf->lightswitch_percent = 0; - } else if (pact == PARM_ACT_SET){ + } else if (pact == PARM_ACT_SET) { parm_in = atoi(parm.c_str()); if ((parm_in < 0) || (parm_in > 100)) { MOTION_LOG(NTC, TYPE_ALL, NO_ERRNO, _("Invalid lightswitch_percent %d"),parm_in); } else { cam->conf->lightswitch_percent = parm_in; } - } else if (pact == PARM_ACT_GET){ + } else if (pact == PARM_ACT_GET) { parm = std::to_string(cam->conf->lightswitch_percent); } return; @@ -1851,16 +1851,16 @@ static void conf_edit_lightswitch_percent(struct ctx_cam *cam, std::string &parm static void conf_edit_lightswitch_frames(struct ctx_cam *cam, std::string &parm, enum PARM_ACT pact) { int parm_in; - if (pact == PARM_ACT_DFLT){ + if (pact == PARM_ACT_DFLT) { cam->conf->lightswitch_frames = 5; - } else if (pact == PARM_ACT_SET){ + } else if (pact == PARM_ACT_SET) { parm_in = atoi(parm.c_str()); if ((parm_in < 1) || (parm_in > 1000)) { MOTION_LOG(NTC, TYPE_ALL, NO_ERRNO, _("Invalid lightswitch_frames %d"),parm_in); } else { cam->conf->lightswitch_frames = parm_in; } - } else if (pact == PARM_ACT_GET){ + } else if (pact == PARM_ACT_GET) { parm = std::to_string(cam->conf->lightswitch_frames); } return; @@ -1870,16 +1870,16 @@ static void conf_edit_lightswitch_frames(struct ctx_cam *cam, std::string &parm, static void conf_edit_minimum_motion_frames(struct ctx_cam *cam, std::string &parm, enum PARM_ACT pact) { int parm_in; - if (pact == PARM_ACT_DFLT){ + if (pact == PARM_ACT_DFLT) { cam->conf->minimum_motion_frames = 1; - } else if (pact == PARM_ACT_SET){ + } else if (pact == PARM_ACT_SET) { parm_in = atoi(parm.c_str()); if ((parm_in < 1) || (parm_in > 10000)) { MOTION_LOG(NTC, TYPE_ALL, NO_ERRNO, _("Invalid minimum_motion_frames %d"),parm_in); } else { cam->conf->minimum_motion_frames = parm_in; } - } else if (pact == PARM_ACT_GET){ + } else if (pact == PARM_ACT_GET) { parm = std::to_string(cam->conf->minimum_motion_frames); } return; @@ -1889,16 +1889,16 @@ static void conf_edit_minimum_motion_frames(struct ctx_cam *cam, std::string &pa static void conf_edit_static_object_time(struct ctx_cam *cam, std::string &parm, enum PARM_ACT pact) { int parm_in; - if (pact == PARM_ACT_DFLT){ + if (pact == PARM_ACT_DFLT) { cam->conf->static_object_time = 10; - } else if (pact == PARM_ACT_SET){ + } else if (pact == PARM_ACT_SET) { parm_in = atoi(parm.c_str()); if (parm_in < 1) { MOTION_LOG(NTC, TYPE_ALL, NO_ERRNO, _("Invalid static_object_time %d"),parm_in); } else { cam->conf->static_object_time = parm_in; } - } else if (pact == PARM_ACT_GET){ + } else if (pact == PARM_ACT_GET) { parm = std::to_string(cam->conf->static_object_time); } return; @@ -1908,16 +1908,16 @@ static void conf_edit_static_object_time(struct ctx_cam *cam, std::string &parm, static void conf_edit_event_gap(struct ctx_cam *cam, std::string &parm, enum PARM_ACT pact) { int parm_in; - if (pact == PARM_ACT_DFLT){ + if (pact == PARM_ACT_DFLT) { cam->conf->event_gap = 60; - } else if (pact == PARM_ACT_SET){ + } else if (pact == PARM_ACT_SET) { parm_in = atoi(parm.c_str()); if ((parm_in < 0) || (parm_in > 2147483647)) { MOTION_LOG(NTC, TYPE_ALL, NO_ERRNO, _("Invalid event_gap %d"),parm_in); } else { cam->conf->event_gap = parm_in; } - } else if (pact == PARM_ACT_GET){ + } else if (pact == PARM_ACT_GET) { parm = std::to_string(cam->conf->event_gap); } return; @@ -1927,16 +1927,16 @@ static void conf_edit_event_gap(struct ctx_cam *cam, std::string &parm, enum PAR static void conf_edit_pre_capture(struct ctx_cam *cam, std::string &parm, enum PARM_ACT pact) { int parm_in; - if (pact == PARM_ACT_DFLT){ + if (pact == PARM_ACT_DFLT) { cam->conf->pre_capture = 0; - } else if (pact == PARM_ACT_SET){ + } else if (pact == PARM_ACT_SET) { parm_in = atoi(parm.c_str()); if ((parm_in < 0) || (parm_in > 1000)) { MOTION_LOG(NTC, TYPE_ALL, NO_ERRNO, _("Invalid pre_capture %d"),parm_in); } else { cam->conf->pre_capture = parm_in; } - } else if (pact == PARM_ACT_GET){ + } else if (pact == PARM_ACT_GET) { parm = std::to_string(cam->conf->pre_capture); } return; @@ -1946,16 +1946,16 @@ static void conf_edit_pre_capture(struct ctx_cam *cam, std::string &parm, enum P static void conf_edit_post_capture(struct ctx_cam *cam, std::string &parm, enum PARM_ACT pact) { int parm_in; - if (pact == PARM_ACT_DFLT){ + if (pact == PARM_ACT_DFLT) { cam->conf->post_capture = 0; - } else if (pact == PARM_ACT_SET){ + } else if (pact == PARM_ACT_SET) { parm_in = atoi(parm.c_str()); if ((parm_in < 0) || (parm_in > 2147483647)) { MOTION_LOG(NTC, TYPE_ALL, NO_ERRNO, _("Invalid post_capture %d"),parm_in); } else { cam->conf->post_capture = parm_in; } - } else if (pact == PARM_ACT_GET){ + } else if (pact == PARM_ACT_GET) { parm = std::to_string(cam->conf->post_capture); } return; @@ -1966,9 +1966,9 @@ static void conf_edit_on_event_start(struct ctx_cam *cam, std::string &parm, enu { if (pact == PARM_ACT_DFLT) { cam->conf->on_event_start = ""; - } else if (pact == PARM_ACT_SET){ + } else if (pact == PARM_ACT_SET) { cam->conf->on_event_start = parm; - } else if (pact == PARM_ACT_GET){ + } else if (pact == PARM_ACT_GET) { parm = cam->conf->on_event_start; } return; @@ -1979,9 +1979,9 @@ static void conf_edit_on_event_end(struct ctx_cam *cam, std::string &parm, enum { if (pact == PARM_ACT_DFLT) { cam->conf->on_event_end = ""; - } else if (pact == PARM_ACT_SET){ + } else if (pact == PARM_ACT_SET) { cam->conf->on_event_end = parm; - } else if (pact == PARM_ACT_GET){ + } else if (pact == PARM_ACT_GET) { parm = cam->conf->on_event_end; } return; @@ -1992,9 +1992,9 @@ static void conf_edit_on_picture_save(struct ctx_cam *cam, std::string &parm, en { if (pact == PARM_ACT_DFLT) { cam->conf->on_picture_save = ""; - } else if (pact == PARM_ACT_SET){ + } else if (pact == PARM_ACT_SET) { cam->conf->on_picture_save = parm; - } else if (pact == PARM_ACT_GET){ + } else if (pact == PARM_ACT_GET) { parm = cam->conf->on_picture_save; } return; @@ -2005,9 +2005,9 @@ static void conf_edit_on_area_detected(struct ctx_cam *cam, std::string &parm, e { if (pact == PARM_ACT_DFLT) { cam->conf->on_area_detected = ""; - } else if (pact == PARM_ACT_SET){ + } else if (pact == PARM_ACT_SET) { cam->conf->on_area_detected = parm; - } else if (pact == PARM_ACT_GET){ + } else if (pact == PARM_ACT_GET) { parm = cam->conf->on_area_detected; } return; @@ -2018,9 +2018,9 @@ static void conf_edit_on_motion_detected(struct ctx_cam *cam, std::string &parm, { if (pact == PARM_ACT_DFLT) { cam->conf->on_motion_detected = ""; - } else if (pact == PARM_ACT_SET){ + } else if (pact == PARM_ACT_SET) { cam->conf->on_motion_detected = parm; - } else if (pact == PARM_ACT_GET){ + } else if (pact == PARM_ACT_GET) { parm = cam->conf->on_motion_detected; } return; @@ -2031,9 +2031,9 @@ static void conf_edit_on_movie_start(struct ctx_cam *cam, std::string &parm, enu { if (pact == PARM_ACT_DFLT) { cam->conf->on_movie_start = ""; - } else if (pact == PARM_ACT_SET){ + } else if (pact == PARM_ACT_SET) { cam->conf->on_movie_start = parm; - } else if (pact == PARM_ACT_GET){ + } else if (pact == PARM_ACT_GET) { parm = cam->conf->on_movie_start; } return; @@ -2044,9 +2044,9 @@ static void conf_edit_on_movie_end(struct ctx_cam *cam, std::string &parm, enum { if (pact == PARM_ACT_DFLT) { cam->conf->on_movie_end = ""; - } else if (pact == PARM_ACT_SET){ + } else if (pact == PARM_ACT_SET) { cam->conf->on_movie_end = parm; - } else if (pact == PARM_ACT_GET){ + } else if (pact == PARM_ACT_GET) { parm = cam->conf->on_movie_end; } return; @@ -2057,9 +2057,9 @@ static void conf_edit_on_camera_lost(struct ctx_cam *cam, std::string &parm, enu { if (pact == PARM_ACT_DFLT) { cam->conf->on_camera_lost = ""; - } else if (pact == PARM_ACT_SET){ + } else if (pact == PARM_ACT_SET) { cam->conf->on_camera_lost = parm; - } else if (pact == PARM_ACT_GET){ + } else if (pact == PARM_ACT_GET) { parm = cam->conf->on_camera_lost; } return; @@ -2070,9 +2070,9 @@ static void conf_edit_on_camera_found(struct ctx_cam *cam, std::string &parm, en { if (pact == PARM_ACT_DFLT) { cam->conf->on_camera_found = ""; - } else if (pact == PARM_ACT_SET){ + } else if (pact == PARM_ACT_SET) { cam->conf->on_camera_found = parm; - } else if (pact == PARM_ACT_GET){ + } else if (pact == PARM_ACT_GET) { parm = cam->conf->on_camera_found; } return; @@ -2083,9 +2083,9 @@ static void conf_edit_on_secondary_detect(struct ctx_cam *cam, std::string &parm { if (pact == PARM_ACT_DFLT) { cam->conf->on_secondary_detect = ""; - } else if (pact == PARM_ACT_SET){ + } else if (pact == PARM_ACT_SET) { cam->conf->on_secondary_detect = parm; - } else if (pact == PARM_ACT_GET){ + } else if (pact == PARM_ACT_GET) { parm = cam->conf->on_secondary_detect; } return; @@ -2096,7 +2096,7 @@ static void conf_edit_picture_output(struct ctx_cam *cam, std::string &parm, enu { if (pact == PARM_ACT_DFLT) { cam->conf->picture_output = "off"; - } else if (pact == PARM_ACT_SET){ + } else if (pact == PARM_ACT_SET) { if ((parm == "on") || (parm == "off") || (parm == "first") || (parm == "best")) { cam->conf->picture_output = parm; @@ -2105,9 +2105,9 @@ static void conf_edit_picture_output(struct ctx_cam *cam, std::string &parm, enu } else { MOTION_LOG(NTC, TYPE_ALL, NO_ERRNO, _("Invalid picture_output %s"), parm.c_str()); } - } else if (pact == PARM_ACT_GET){ + } else if (pact == PARM_ACT_GET) { parm = cam->conf->picture_output; - } else if (pact == PARM_ACT_LIST){ + } else if (pact == PARM_ACT_LIST) { parm = "["; parm = parm + "\"on\",\"off\",\"first\",\"best\""; parm = parm + "]"; @@ -2120,7 +2120,7 @@ static void conf_edit_picture_output_motion(struct ctx_cam *cam, std::string &pa { if (pact == PARM_ACT_DFLT) { cam->conf->picture_output_motion = "off"; - } else if (pact == PARM_ACT_SET){ + } else if (pact == PARM_ACT_SET) { if ((parm == "on") || (parm == "off") || (parm == "roi")) { cam->conf->picture_output_motion = parm; } else if (parm == "") { @@ -2128,9 +2128,9 @@ static void conf_edit_picture_output_motion(struct ctx_cam *cam, std::string &pa } else { MOTION_LOG(NTC, TYPE_ALL, NO_ERRNO, _("Invalid picture_output_motion %s"), parm.c_str()); } - } else if (pact == PARM_ACT_GET){ + } else if (pact == PARM_ACT_GET) { parm = cam->conf->picture_output; - } else if (pact == PARM_ACT_LIST){ + } else if (pact == PARM_ACT_LIST) { parm = "["; parm = parm + "\"on\",\"off\",\"roi\""; parm = parm + "]"; @@ -2143,7 +2143,7 @@ static void conf_edit_picture_type(struct ctx_cam *cam, std::string &parm, enum { if (pact == PARM_ACT_DFLT) { cam->conf->picture_type = "jpeg"; - } else if (pact == PARM_ACT_SET){ + } else if (pact == PARM_ACT_SET) { if ((parm == "jpeg") || (parm == "webp") || (parm == "ppm")) { cam->conf->picture_type = parm; } else if (parm == "") { @@ -2151,9 +2151,9 @@ static void conf_edit_picture_type(struct ctx_cam *cam, std::string &parm, enum } else { MOTION_LOG(NTC, TYPE_ALL, NO_ERRNO, _("Invalid picture_type %s"), parm.c_str()); } - } else if (pact == PARM_ACT_GET){ + } else if (pact == PARM_ACT_GET) { parm = cam->conf->picture_type; - } else if (pact == PARM_ACT_LIST){ + } else if (pact == PARM_ACT_LIST) { parm = "["; parm = parm + "\"jpeg\",\"webp\",\"ppm\""; parm = parm + "]"; @@ -2165,16 +2165,16 @@ static void conf_edit_picture_type(struct ctx_cam *cam, std::string &parm, enum static void conf_edit_picture_quality(struct ctx_cam *cam, std::string &parm, enum PARM_ACT pact) { int parm_in; - if (pact == PARM_ACT_DFLT){ + if (pact == PARM_ACT_DFLT) { cam->conf->picture_quality = 75; - } else if (pact == PARM_ACT_SET){ + } else if (pact == PARM_ACT_SET) { parm_in = atoi(parm.c_str()); if ((parm_in < 1) || (parm_in > 100)) { MOTION_LOG(NTC, TYPE_ALL, NO_ERRNO, _("Invalid picture_quality %d"),parm_in); } else { cam->conf->picture_quality = parm_in; } - } else if (pact == PARM_ACT_GET){ + } else if (pact == PARM_ACT_GET) { parm = std::to_string(cam->conf->picture_quality); } return; @@ -2185,9 +2185,9 @@ static void conf_edit_picture_exif(struct ctx_cam *cam, std::string &parm, enum { if (pact == PARM_ACT_DFLT) { cam->conf->picture_exif = ""; - } else if (pact == PARM_ACT_SET){ + } else if (pact == PARM_ACT_SET) { cam->conf->picture_exif = parm; - } else if (pact == PARM_ACT_GET){ + } else if (pact == PARM_ACT_GET) { parm = cam->conf->picture_exif; } return; @@ -2198,9 +2198,9 @@ static void conf_edit_picture_filename(struct ctx_cam *cam, std::string &parm, e { if (pact == PARM_ACT_DFLT) { cam->conf->picture_filename = "%v-%Y%m%d%H%M%S-%q"; - } else if (pact == PARM_ACT_SET){ + } else if (pact == PARM_ACT_SET) { cam->conf->picture_filename = parm; - } else if (pact == PARM_ACT_GET){ + } else if (pact == PARM_ACT_GET) { parm = cam->conf->picture_filename; } return; @@ -2210,16 +2210,16 @@ static void conf_edit_picture_filename(struct ctx_cam *cam, std::string &parm, e static void conf_edit_snapshot_interval(struct ctx_cam *cam, std::string &parm, enum PARM_ACT pact) { int parm_in; - if (pact == PARM_ACT_DFLT){ + if (pact == PARM_ACT_DFLT) { cam->conf->snapshot_interval = 0; - } else if (pact == PARM_ACT_SET){ + } else if (pact == PARM_ACT_SET) { parm_in = atoi(parm.c_str()); if ((parm_in < 0) || (parm_in > 2147483647)) { MOTION_LOG(NTC, TYPE_ALL, NO_ERRNO, _("Invalid snapshot_interval %d"),parm_in); } else { cam->conf->snapshot_interval = parm_in; } - } else if (pact == PARM_ACT_GET){ + } else if (pact == PARM_ACT_GET) { parm = std::to_string(cam->conf->snapshot_interval); } return; @@ -2230,9 +2230,9 @@ static void conf_edit_snapshot_filename(struct ctx_cam *cam, std::string &parm, { if (pact == PARM_ACT_DFLT) { cam->conf->snapshot_filename = "%v-%Y%m%d%H%M%S-snapshot"; - } else if (pact == PARM_ACT_SET){ + } else if (pact == PARM_ACT_SET) { cam->conf->snapshot_filename = parm; - } else if (pact == PARM_ACT_GET){ + } else if (pact == PARM_ACT_GET) { parm = cam->conf->snapshot_filename; } return; @@ -2241,11 +2241,11 @@ static void conf_edit_snapshot_filename(struct ctx_cam *cam, std::string &parm, static void conf_edit_movie_output(struct ctx_cam *cam, std::string &parm, enum PARM_ACT pact) { - if (pact == PARM_ACT_DFLT){ + if (pact == PARM_ACT_DFLT) { cam->conf->movie_output = TRUE; - } else if (pact == PARM_ACT_SET){ + } else if (pact == PARM_ACT_SET) { conf_edit_set_bool(cam->conf->movie_output, parm); - } else if (pact == PARM_ACT_GET){ + } else if (pact == PARM_ACT_GET) { conf_edit_get_bool(parm, cam->conf->movie_output); } return; @@ -2254,11 +2254,11 @@ static void conf_edit_movie_output(struct ctx_cam *cam, std::string &parm, enum static void conf_edit_movie_output_motion(struct ctx_cam *cam, std::string &parm, enum PARM_ACT pact) { - if (pact == PARM_ACT_DFLT){ + if (pact == PARM_ACT_DFLT) { cam->conf->movie_output_motion = FALSE; - } else if (pact == PARM_ACT_SET){ + } else if (pact == PARM_ACT_SET) { conf_edit_set_bool(cam->conf->movie_output_motion, parm); - } else if (pact == PARM_ACT_GET){ + } else if (pact == PARM_ACT_GET) { conf_edit_get_bool(parm, cam->conf->movie_output_motion); } return; @@ -2268,16 +2268,16 @@ static void conf_edit_movie_output_motion(struct ctx_cam *cam, std::string &parm static void conf_edit_movie_max_time(struct ctx_cam *cam, std::string &parm, enum PARM_ACT pact) { int parm_in; - if (pact == PARM_ACT_DFLT){ + if (pact == PARM_ACT_DFLT) { cam->conf->movie_max_time = 120; - } else if (pact == PARM_ACT_SET){ + } else if (pact == PARM_ACT_SET) { parm_in = atoi(parm.c_str()); if ((parm_in < 0) || (parm_in > 2147483647)) { MOTION_LOG(NTC, TYPE_ALL, NO_ERRNO, _("Invalid movie_max_time %d"),parm_in); } else { cam->conf->movie_max_time = parm_in; } - } else if (pact == PARM_ACT_GET){ + } else if (pact == PARM_ACT_GET) { parm = std::to_string(cam->conf->movie_max_time); } return; @@ -2287,16 +2287,16 @@ static void conf_edit_movie_max_time(struct ctx_cam *cam, std::string &parm, enu static void conf_edit_movie_bps(struct ctx_cam *cam, std::string &parm, enum PARM_ACT pact) { int parm_in; - if (pact == PARM_ACT_DFLT){ + if (pact == PARM_ACT_DFLT) { cam->conf->movie_bps = 400000; - } else if (pact == PARM_ACT_SET){ + } else if (pact == PARM_ACT_SET) { parm_in = atoi(parm.c_str()); if ((parm_in < 0) || (parm_in > 9999999)) { MOTION_LOG(NTC, TYPE_ALL, NO_ERRNO, _("Invalid movie_bps %d"),parm_in); } else { cam->conf->movie_bps = parm_in; } - } else if (pact == PARM_ACT_GET){ + } else if (pact == PARM_ACT_GET) { parm = std::to_string(cam->conf->movie_bps); } return; @@ -2306,16 +2306,16 @@ static void conf_edit_movie_bps(struct ctx_cam *cam, std::string &parm, enum PAR static void conf_edit_movie_quality(struct ctx_cam *cam, std::string &parm, enum PARM_ACT pact) { int parm_in; - if (pact == PARM_ACT_DFLT){ + if (pact == PARM_ACT_DFLT) { cam->conf->movie_quality = 60; - } else if (pact == PARM_ACT_SET){ + } else if (pact == PARM_ACT_SET) { parm_in = atoi(parm.c_str()); if ((parm_in < 0) || (parm_in > 100)) { MOTION_LOG(NTC, TYPE_ALL, NO_ERRNO, _("Invalid movie_quality %d"),parm_in); } else { cam->conf->movie_quality = parm_in; } - } else if (pact == PARM_ACT_GET){ + } else if (pact == PARM_ACT_GET) { parm = std::to_string(cam->conf->movie_quality); } return; @@ -2326,9 +2326,9 @@ static void conf_edit_movie_codec(struct ctx_cam *cam, std::string &parm, enum P { if (pact == PARM_ACT_DFLT) { cam->conf->movie_codec = "mkv"; - } else if (pact == PARM_ACT_SET){ + } else if (pact == PARM_ACT_SET) { cam->conf->movie_codec = parm; - } else if (pact == PARM_ACT_GET){ + } else if (pact == PARM_ACT_GET) { parm = cam->conf->movie_codec; } return; @@ -2337,11 +2337,11 @@ static void conf_edit_movie_codec(struct ctx_cam *cam, std::string &parm, enum P static void conf_edit_movie_passthrough(struct ctx_cam *cam, std::string &parm, enum PARM_ACT pact) { - if (pact == PARM_ACT_DFLT){ + if (pact == PARM_ACT_DFLT) { cam->conf->movie_passthrough = FALSE; - } else if (pact == PARM_ACT_SET){ + } else if (pact == PARM_ACT_SET) { conf_edit_set_bool(cam->conf->movie_passthrough, parm); - } else if (pact == PARM_ACT_GET){ + } else if (pact == PARM_ACT_GET) { conf_edit_get_bool(parm, cam->conf->movie_passthrough); } return; @@ -2352,9 +2352,9 @@ static void conf_edit_movie_filename(struct ctx_cam *cam, std::string &parm, enu { if (pact == PARM_ACT_DFLT) { cam->conf->movie_filename = "%v-%Y%m%d%H%M%S"; - } else if (pact == PARM_ACT_SET){ + } else if (pact == PARM_ACT_SET) { cam->conf->movie_filename = parm; - } else if (pact == PARM_ACT_GET){ + } else if (pact == PARM_ACT_GET) { parm = cam->conf->movie_filename; } return; @@ -2363,11 +2363,11 @@ static void conf_edit_movie_filename(struct ctx_cam *cam, std::string &parm, enu static void conf_edit_movie_extpipe_use(struct ctx_cam *cam, std::string &parm, enum PARM_ACT pact) { - if (pact == PARM_ACT_DFLT){ + if (pact == PARM_ACT_DFLT) { cam->conf->movie_extpipe_use = FALSE; - } else if (pact == PARM_ACT_SET){ + } else if (pact == PARM_ACT_SET) { conf_edit_set_bool(cam->conf->movie_extpipe_use, parm); - } else if (pact == PARM_ACT_GET){ + } else if (pact == PARM_ACT_GET) { conf_edit_get_bool(parm, cam->conf->movie_extpipe_use); } return; @@ -2378,9 +2378,9 @@ static void conf_edit_movie_extpipe(struct ctx_cam *cam, std::string &parm, enum { if (pact == PARM_ACT_DFLT) { cam->conf->movie_extpipe = ""; - } else if (pact == PARM_ACT_SET){ + } else if (pact == PARM_ACT_SET) { cam->conf->movie_extpipe = parm; - } else if (pact == PARM_ACT_GET){ + } else if (pact == PARM_ACT_GET) { parm = cam->conf->movie_extpipe; } return; @@ -2390,16 +2390,16 @@ static void conf_edit_movie_extpipe(struct ctx_cam *cam, std::string &parm, enum static void conf_edit_timelapse_interval(struct ctx_cam *cam, std::string &parm, enum PARM_ACT pact) { int parm_in; - if (pact == PARM_ACT_DFLT){ + if (pact == PARM_ACT_DFLT) { cam->conf->timelapse_interval = 0; - } else if (pact == PARM_ACT_SET){ + } else if (pact == PARM_ACT_SET) { parm_in = atoi(parm.c_str()); if ((parm_in < 0) || (parm_in > 2147483647)) { MOTION_LOG(NTC, TYPE_ALL, NO_ERRNO, _("Invalid timelapse_interval %d"),parm_in); } else { cam->conf->timelapse_interval = parm_in; } - } else if (pact == PARM_ACT_GET){ + } else if (pact == PARM_ACT_GET) { parm = std::to_string(cam->conf->timelapse_interval); } return; @@ -2410,7 +2410,7 @@ static void conf_edit_timelapse_mode(struct ctx_cam *cam, std::string &parm, enu { if (pact == PARM_ACT_DFLT) { cam->conf->timelapse_mode = "daily"; - } else if (pact == PARM_ACT_SET){ + } else if (pact == PARM_ACT_SET) { if ((parm == "hourly") || (parm == "daily") || (parm == "weekly-sunday") || (parm == "weekly-monday") || (parm == "monthly") || (parm == "manual")) { @@ -2420,9 +2420,9 @@ static void conf_edit_timelapse_mode(struct ctx_cam *cam, std::string &parm, enu } else { MOTION_LOG(NTC, TYPE_ALL, NO_ERRNO, _("Invalid timelapse_mode %s"), parm.c_str()); } - } else if (pact == PARM_ACT_GET){ + } else if (pact == PARM_ACT_GET) { parm = cam->conf->timelapse_mode; - } else if (pact == PARM_ACT_LIST){ + } else if (pact == PARM_ACT_LIST) { parm = "["; parm = parm + "\"hourly\",\"daily\",\"weekly-sunday\""; parm = parm + ",\"weekly-monday\",\"monthly\",\"manual\""; @@ -2435,16 +2435,16 @@ static void conf_edit_timelapse_mode(struct ctx_cam *cam, std::string &parm, enu static void conf_edit_timelapse_fps(struct ctx_cam *cam, std::string &parm, enum PARM_ACT pact) { int parm_in; - if (pact == PARM_ACT_DFLT){ + if (pact == PARM_ACT_DFLT) { cam->conf->timelapse_fps = 30; - } else if (pact == PARM_ACT_SET){ + } else if (pact == PARM_ACT_SET) { parm_in = atoi(parm.c_str()); if ((parm_in < 2) || (parm_in > 100)) { MOTION_LOG(NTC, TYPE_ALL, NO_ERRNO, _("Invalid timelapse_fps %d"),parm_in); } else { cam->conf->timelapse_fps = parm_in; } - } else if (pact == PARM_ACT_GET){ + } else if (pact == PARM_ACT_GET) { parm = std::to_string(cam->conf->timelapse_fps); } return; @@ -2455,7 +2455,7 @@ static void conf_edit_timelapse_codec(struct ctx_cam *cam, std::string &parm, en { if (pact == PARM_ACT_DFLT) { cam->conf->timelapse_codec = "mpg"; - } else if (pact == PARM_ACT_SET){ + } else if (pact == PARM_ACT_SET) { if ((parm == "mpg") || (parm == "mpeg4")) { cam->conf->timelapse_codec = parm; } else if (parm == "") { @@ -2463,9 +2463,9 @@ static void conf_edit_timelapse_codec(struct ctx_cam *cam, std::string &parm, en } else { MOTION_LOG(NTC, TYPE_ALL, NO_ERRNO, _("Invalid timelapse_codec %s"), parm.c_str()); } - } else if (pact == PARM_ACT_GET){ + } else if (pact == PARM_ACT_GET) { parm = cam->conf->timelapse_codec; - } else if (pact == PARM_ACT_LIST){ + } else if (pact == PARM_ACT_LIST) { parm = "["; parm = parm + "\"mpg\",\"mpeg4\""; parm = parm + "]"; @@ -2478,9 +2478,9 @@ static void conf_edit_timelapse_filename(struct ctx_cam *cam, std::string &parm, { if (pact == PARM_ACT_DFLT) { cam->conf->timelapse_filename = "%Y%m%d-timelapse"; - } else if (pact == PARM_ACT_SET){ + } else if (pact == PARM_ACT_SET) { cam->conf->timelapse_filename = parm; - } else if (pact == PARM_ACT_GET){ + } else if (pact == PARM_ACT_GET) { parm = cam->conf->timelapse_filename; } return; @@ -2491,9 +2491,9 @@ static void conf_edit_video_pipe(struct ctx_cam *cam, std::string &parm, enum PA { if (pact == PARM_ACT_DFLT) { cam->conf->video_pipe = ""; - } else if (pact == PARM_ACT_SET){ + } else if (pact == PARM_ACT_SET) { cam->conf->video_pipe = parm; - } else if (pact == PARM_ACT_GET){ + } else if (pact == PARM_ACT_GET) { parm = cam->conf->video_pipe; } return; @@ -2504,9 +2504,9 @@ static void conf_edit_video_pipe_motion(struct ctx_cam *cam, std::string &parm, { if (pact == PARM_ACT_DFLT) { cam->conf->video_pipe_motion = ""; - } else if (pact == PARM_ACT_SET){ + } else if (pact == PARM_ACT_SET) { cam->conf->video_pipe_motion = parm; - } else if (pact == PARM_ACT_GET){ + } else if (pact == PARM_ACT_GET) { parm = cam->conf->video_pipe_motion; } return; @@ -2516,16 +2516,16 @@ static void conf_edit_video_pipe_motion(struct ctx_cam *cam, std::string &parm, static void conf_edit_webcontrol_port(struct ctx_cam *cam, std::string &parm, enum PARM_ACT pact) { int parm_in; - if (pact == PARM_ACT_DFLT){ + if (pact == PARM_ACT_DFLT) { cam->conf->webcontrol_port = 0; - } else if (pact == PARM_ACT_SET){ + } else if (pact == PARM_ACT_SET) { parm_in = atoi(parm.c_str()); if ((parm_in < 0) || (parm_in > 65535)) { MOTION_LOG(NTC, TYPE_ALL, NO_ERRNO, _("Invalid webcontrol_port %d"),parm_in); } else { cam->conf->webcontrol_port = parm_in; } - } else if (pact == PARM_ACT_GET){ + } else if (pact == PARM_ACT_GET) { parm = std::to_string(cam->conf->webcontrol_port); } return; @@ -2534,11 +2534,11 @@ static void conf_edit_webcontrol_port(struct ctx_cam *cam, std::string &parm, en static void conf_edit_webcontrol_ipv6(struct ctx_cam *cam, std::string &parm, enum PARM_ACT pact) { - if (pact == PARM_ACT_DFLT){ + if (pact == PARM_ACT_DFLT) { cam->conf->webcontrol_ipv6 = FALSE; - } else if (pact == PARM_ACT_SET){ + } else if (pact == PARM_ACT_SET) { conf_edit_set_bool(cam->conf->webcontrol_ipv6, parm); - } else if (pact == PARM_ACT_GET){ + } else if (pact == PARM_ACT_GET) { conf_edit_get_bool(parm, cam->conf->webcontrol_ipv6); } return; @@ -2547,11 +2547,11 @@ static void conf_edit_webcontrol_ipv6(struct ctx_cam *cam, std::string &parm, en static void conf_edit_webcontrol_localhost(struct ctx_cam *cam, std::string &parm, enum PARM_ACT pact) { - if (pact == PARM_ACT_DFLT){ + if (pact == PARM_ACT_DFLT) { cam->conf->webcontrol_localhost = TRUE; - } else if (pact == PARM_ACT_SET){ + } else if (pact == PARM_ACT_SET) { conf_edit_set_bool(cam->conf->webcontrol_localhost, parm); - } else if (pact == PARM_ACT_GET){ + } else if (pact == PARM_ACT_GET) { conf_edit_get_bool(parm, cam->conf->webcontrol_localhost); } return; @@ -2561,18 +2561,18 @@ static void conf_edit_webcontrol_localhost(struct ctx_cam *cam, std::string &par static void conf_edit_webcontrol_parms(struct ctx_cam *cam, std::string &parm, enum PARM_ACT pact) { int parm_in; - if (pact == PARM_ACT_DFLT){ + if (pact == PARM_ACT_DFLT) { cam->conf->webcontrol_parms = 0; - } else if (pact == PARM_ACT_SET){ + } else if (pact == PARM_ACT_SET) { parm_in = atoi(parm.c_str()); if ((parm_in < 0) || (parm_in > 3)) { MOTION_LOG(NTC, TYPE_ALL, NO_ERRNO, _("Invalid webcontrol_parms %d"),parm_in); } else { cam->conf->webcontrol_parms = parm_in; } - } else if (pact == PARM_ACT_GET){ + } else if (pact == PARM_ACT_GET) { parm = std::to_string(cam->conf->webcontrol_parms); - } else if (pact == PARM_ACT_LIST){ + } else if (pact == PARM_ACT_LIST) { parm = "["; parm = parm + "\"0\",\"1\",\"2\",\"3\""; parm = parm + "]"; @@ -2584,18 +2584,18 @@ static void conf_edit_webcontrol_parms(struct ctx_cam *cam, std::string &parm, e static void conf_edit_webcontrol_interface(struct ctx_cam *cam, std::string &parm, enum PARM_ACT pact) { int parm_in; - if (pact == PARM_ACT_DFLT){ + if (pact == PARM_ACT_DFLT) { cam->conf->webcontrol_interface = 0; - } else if (pact == PARM_ACT_SET){ + } else if (pact == PARM_ACT_SET) { parm_in = atoi(parm.c_str()); if ((parm_in < 0) || (parm_in > 3)) { MOTION_LOG(NTC, TYPE_ALL, NO_ERRNO, _("Invalid webcontrol_interface %d"),parm_in); } else { cam->conf->webcontrol_interface = parm_in; } - } else if (pact == PARM_ACT_GET){ + } else if (pact == PARM_ACT_GET) { parm = std::to_string(cam->conf->webcontrol_interface); - } else if (pact == PARM_ACT_LIST){ + } else if (pact == PARM_ACT_LIST) { parm = "["; parm = parm + "\"0\",\"1\",\"2\",\"3\""; parm = parm + "]"; @@ -2607,18 +2607,18 @@ static void conf_edit_webcontrol_interface(struct ctx_cam *cam, std::string &par static void conf_edit_webcontrol_auth_method(struct ctx_cam *cam, std::string &parm, enum PARM_ACT pact) { int parm_in; - if (pact == PARM_ACT_DFLT){ + if (pact == PARM_ACT_DFLT) { cam->conf->webcontrol_auth_method = 0; - } else if (pact == PARM_ACT_SET){ + } else if (pact == PARM_ACT_SET) { parm_in = atoi(parm.c_str()); if ((parm_in < 0) || (parm_in > 2)) { MOTION_LOG(NTC, TYPE_ALL, NO_ERRNO, _("Invalid webcontrol_auth_method %d"),parm_in); } else { cam->conf->webcontrol_auth_method = parm_in; } - } else if (pact == PARM_ACT_GET){ + } else if (pact == PARM_ACT_GET) { parm = std::to_string(cam->conf->webcontrol_auth_method); - } else if (pact == PARM_ACT_LIST){ + } else if (pact == PARM_ACT_LIST) { parm = "["; parm = parm + "\"0\",\"1\",\"2\""; parm = parm + "]"; @@ -2631,9 +2631,9 @@ static void conf_edit_webcontrol_authentication(struct ctx_cam *cam, std::string { if (pact == PARM_ACT_DFLT) { cam->conf->webcontrol_authentication = ""; - } else if (pact == PARM_ACT_SET){ + } else if (pact == PARM_ACT_SET) { cam->conf->webcontrol_authentication = parm; - } else if (pact == PARM_ACT_GET){ + } else if (pact == PARM_ACT_GET) { parm = cam->conf->webcontrol_authentication; } return; @@ -2642,11 +2642,11 @@ static void conf_edit_webcontrol_authentication(struct ctx_cam *cam, std::string static void conf_edit_webcontrol_tls(struct ctx_cam *cam, std::string &parm, enum PARM_ACT pact) { - if (pact == PARM_ACT_DFLT){ + if (pact == PARM_ACT_DFLT) { cam->conf->webcontrol_tls = FALSE; - } else if (pact == PARM_ACT_SET){ + } else if (pact == PARM_ACT_SET) { conf_edit_set_bool(cam->conf->webcontrol_tls, parm); - } else if (pact == PARM_ACT_GET){ + } else if (pact == PARM_ACT_GET) { conf_edit_get_bool(parm, cam->conf->webcontrol_tls); } return; @@ -2657,9 +2657,9 @@ static void conf_edit_webcontrol_cert(struct ctx_cam *cam, std::string &parm, en { if (pact == PARM_ACT_DFLT) { cam->conf->webcontrol_cert = ""; - } else if (pact == PARM_ACT_SET){ + } else if (pact == PARM_ACT_SET) { cam->conf->webcontrol_cert = parm; - } else if (pact == PARM_ACT_GET){ + } else if (pact == PARM_ACT_GET) { parm = cam->conf->webcontrol_cert; } return; @@ -2670,9 +2670,9 @@ static void conf_edit_webcontrol_key(struct ctx_cam *cam, std::string &parm, enu { if (pact == PARM_ACT_DFLT) { cam->conf->webcontrol_key = ""; - } else if (pact == PARM_ACT_SET){ + } else if (pact == PARM_ACT_SET) { cam->conf->webcontrol_key = parm; - } else if (pact == PARM_ACT_GET){ + } else if (pact == PARM_ACT_GET) { parm = cam->conf->webcontrol_key; } return; @@ -2684,7 +2684,7 @@ static void conf_edit_webcontrol_cors_header(struct ctx_cam *cam, std::string &p int retcd; if (pact == PARM_ACT_DFLT) { cam->conf->webcontrol_cors_header = ""; - } else if (pact == PARM_ACT_SET){ + } else if (pact == PARM_ACT_SET) { const char *regex_str = "(http|https)://(((.*):(.*))@)?([^/:]|[-_.a-z0-9]+)(:([0-9]+))?($|(/[^*]*))"; regex_t regex; if (regcomp(®ex, regex_str, REG_EXTENDED) != 0) { @@ -2698,7 +2698,7 @@ static void conf_edit_webcontrol_cors_header(struct ctx_cam *cam, std::string &p } cam->conf->webcontrol_cors_header = parm; regfree(®ex); - } else if (pact == PARM_ACT_GET){ + } else if (pact == PARM_ACT_GET) { parm = cam->conf->webcontrol_cors_header; } return; @@ -2709,9 +2709,9 @@ static void conf_edit_webcontrol_html(struct ctx_cam *cam, std::string &parm, en { if (pact == PARM_ACT_DFLT) { cam->conf->webcontrol_html = ""; - } else if (pact == PARM_ACT_SET){ + } else if (pact == PARM_ACT_SET) { cam->conf->webcontrol_html = parm; - } else if (pact == PARM_ACT_GET){ + } else if (pact == PARM_ACT_GET) { parm = cam->conf->webcontrol_html; } return; @@ -2721,16 +2721,16 @@ static void conf_edit_webcontrol_html(struct ctx_cam *cam, std::string &parm, en static void conf_edit_stream_preview_scale(struct ctx_cam *cam, std::string &parm, enum PARM_ACT pact) { int parm_in; - if (pact == PARM_ACT_DFLT){ + if (pact == PARM_ACT_DFLT) { cam->conf->stream_preview_scale = 25; - } else if (pact == PARM_ACT_SET){ + } else if (pact == PARM_ACT_SET) { parm_in = atoi(parm.c_str()); if ((parm_in < 1) || (parm_in > 1000)) { MOTION_LOG(NTC, TYPE_ALL, NO_ERRNO, _("Invalid stream_preview_scale %d"),parm_in); } else { cam->conf->stream_preview_scale = parm_in; } - } else if (pact == PARM_ACT_GET){ + } else if (pact == PARM_ACT_GET) { parm = std::to_string(cam->conf->stream_preview_scale); } return; @@ -2739,11 +2739,11 @@ static void conf_edit_stream_preview_scale(struct ctx_cam *cam, std::string &par static void conf_edit_stream_preview_newline(struct ctx_cam *cam, std::string &parm, enum PARM_ACT pact) { - if (pact == PARM_ACT_DFLT){ + if (pact == PARM_ACT_DFLT) { cam->conf->stream_preview_newline = FALSE; - } else if (pact == PARM_ACT_SET){ + } else if (pact == PARM_ACT_SET) { conf_edit_set_bool(cam->conf->stream_preview_newline, parm); - } else if (pact == PARM_ACT_GET){ + } else if (pact == PARM_ACT_GET) { conf_edit_get_bool(parm, cam->conf->stream_preview_newline); } return; @@ -2753,18 +2753,18 @@ static void conf_edit_stream_preview_newline(struct ctx_cam *cam, std::string &p static void conf_edit_stream_preview_method(struct ctx_cam *cam, std::string &parm, enum PARM_ACT pact) { int parm_in; - if (pact == PARM_ACT_DFLT){ + if (pact == PARM_ACT_DFLT) { cam->conf->stream_preview_method = 0; - } else if (pact == PARM_ACT_SET){ + } else if (pact == PARM_ACT_SET) { parm_in = atoi(parm.c_str()); if ((parm_in < 0) || (parm_in > 4)) { MOTION_LOG(NTC, TYPE_ALL, NO_ERRNO, _("Invalid stream_preview_method %d"),parm_in); } else { cam->conf->stream_preview_method = parm_in; } - } else if (pact == PARM_ACT_GET){ + } else if (pact == PARM_ACT_GET) { parm = std::to_string(cam->conf->stream_preview_method); - } else if (pact == PARM_ACT_LIST){ + } else if (pact == PARM_ACT_LIST) { parm = "["; parm = parm + "\"0\",\"1\",\"2\",\"3\",\"4\""; parm = parm + "]"; @@ -2775,11 +2775,11 @@ static void conf_edit_stream_preview_method(struct ctx_cam *cam, std::string &pa static void conf_edit_stream_preview_ptz(struct ctx_cam *cam, std::string &parm, enum PARM_ACT pact) { - if (pact == PARM_ACT_DFLT){ + if (pact == PARM_ACT_DFLT) { cam->conf->stream_preview_ptz = true; - } else if (pact == PARM_ACT_SET){ + } else if (pact == PARM_ACT_SET) { conf_edit_set_bool(cam->conf->stream_preview_ptz, parm); - } else if (pact == PARM_ACT_GET){ + } else if (pact == PARM_ACT_GET) { conf_edit_get_bool(parm, cam->conf->stream_preview_ptz); } return; @@ -2789,16 +2789,16 @@ static void conf_edit_stream_preview_ptz(struct ctx_cam *cam, std::string &parm, static void conf_edit_stream_quality(struct ctx_cam *cam, std::string &parm, enum PARM_ACT pact) { int parm_in; - if (pact == PARM_ACT_DFLT){ + if (pact == PARM_ACT_DFLT) { cam->conf->stream_quality = 50; - } else if (pact == PARM_ACT_SET){ + } else if (pact == PARM_ACT_SET) { parm_in = atoi(parm.c_str()); if ((parm_in < 1) || (parm_in > 100)) { MOTION_LOG(NTC, TYPE_ALL, NO_ERRNO, _("Invalid stream_quality %d"),parm_in); } else { cam->conf->stream_quality = parm_in; } - } else if (pact == PARM_ACT_GET){ + } else if (pact == PARM_ACT_GET) { parm = std::to_string(cam->conf->stream_quality); } return; @@ -2807,11 +2807,11 @@ static void conf_edit_stream_quality(struct ctx_cam *cam, std::string &parm, enu static void conf_edit_stream_grey(struct ctx_cam *cam, std::string &parm, enum PARM_ACT pact) { - if (pact == PARM_ACT_DFLT){ + if (pact == PARM_ACT_DFLT) { cam->conf->stream_grey = FALSE; - } else if (pact == PARM_ACT_SET){ + } else if (pact == PARM_ACT_SET) { conf_edit_set_bool(cam->conf->stream_grey, parm); - } else if (pact == PARM_ACT_GET){ + } else if (pact == PARM_ACT_GET) { conf_edit_get_bool(parm, cam->conf->stream_grey); } return; @@ -2820,11 +2820,11 @@ static void conf_edit_stream_grey(struct ctx_cam *cam, std::string &parm, enum P static void conf_edit_stream_motion(struct ctx_cam *cam, std::string &parm, enum PARM_ACT pact) { - if (pact == PARM_ACT_DFLT){ + if (pact == PARM_ACT_DFLT) { cam->conf->stream_motion = FALSE; - } else if (pact == PARM_ACT_SET){ + } else if (pact == PARM_ACT_SET) { conf_edit_set_bool(cam->conf->stream_motion, parm); - } else if (pact == PARM_ACT_GET){ + } else if (pact == PARM_ACT_GET) { conf_edit_get_bool(parm, cam->conf->stream_motion); } return; @@ -2834,16 +2834,16 @@ static void conf_edit_stream_motion(struct ctx_cam *cam, std::string &parm, enum static void conf_edit_stream_maxrate(struct ctx_cam *cam, std::string &parm, enum PARM_ACT pact) { int parm_in; - if (pact == PARM_ACT_DFLT){ + if (pact == PARM_ACT_DFLT) { cam->conf->stream_maxrate = 1; - } else if (pact == PARM_ACT_SET){ + } else if (pact == PARM_ACT_SET) { parm_in = atoi(parm.c_str()); if ((parm_in < 1) || (parm_in > 100)) { MOTION_LOG(NTC, TYPE_ALL, NO_ERRNO, _("Invalid stream_maxrate %d"),parm_in); } else { cam->conf->stream_maxrate = parm_in; } - } else if (pact == PARM_ACT_GET){ + } else if (pact == PARM_ACT_GET) { parm = std::to_string(cam->conf->stream_maxrate); } return; @@ -2854,16 +2854,16 @@ static void conf_edit_database_type(struct ctx_cam *cam, std::string &parm, enum { if (pact == PARM_ACT_DFLT) { cam->conf->database_type = ""; - } else if (pact == PARM_ACT_SET){ + } else if (pact == PARM_ACT_SET) { if ((parm == "mysql") || (parm == "mariadb") || (parm == "") || (parm == "postgresql") || (parm == "sqlite3")) { cam->conf->database_type = parm; } else { MOTION_LOG(NTC, TYPE_ALL, NO_ERRNO, _("Invalid database_type %s"), parm.c_str()); } - } else if (pact == PARM_ACT_GET){ + } else if (pact == PARM_ACT_GET) { parm = cam->conf->database_type; - } else if (pact == PARM_ACT_LIST){ + } else if (pact == PARM_ACT_LIST) { parm = "["; parm = parm + "\"\",\"mysql\",\"mariadb\",\"postgresql\",\"sqlite3\""; parm = parm + "]"; @@ -2876,9 +2876,9 @@ static void conf_edit_database_dbname(struct ctx_cam *cam, std::string &parm, en { if (pact == PARM_ACT_DFLT) { cam->conf->database_dbname = ""; - } else if (pact == PARM_ACT_SET){ + } else if (pact == PARM_ACT_SET) { cam->conf->database_dbname = parm; - } else if (pact == PARM_ACT_GET){ + } else if (pact == PARM_ACT_GET) { parm = cam->conf->database_dbname; } return; @@ -2889,9 +2889,9 @@ static void conf_edit_database_host(struct ctx_cam *cam, std::string &parm, enum { if (pact == PARM_ACT_DFLT) { cam->conf->database_host = "localhost"; - } else if (pact == PARM_ACT_SET){ + } else if (pact == PARM_ACT_SET) { cam->conf->database_host = parm; - } else if (pact == PARM_ACT_GET){ + } else if (pact == PARM_ACT_GET) { parm = cam->conf->database_host; } return; @@ -2901,16 +2901,16 @@ static void conf_edit_database_host(struct ctx_cam *cam, std::string &parm, enum static void conf_edit_database_port(struct ctx_cam *cam, std::string &parm, enum PARM_ACT pact) { int parm_in; - if (pact == PARM_ACT_DFLT){ + if (pact == PARM_ACT_DFLT) { cam->conf->database_port = 0; - } else if (pact == PARM_ACT_SET){ + } else if (pact == PARM_ACT_SET) { parm_in = atoi(parm.c_str()); if ((parm_in < 0) || (parm_in > 65535)) { MOTION_LOG(NTC, TYPE_ALL, NO_ERRNO, _("Invalid database_port %d"),parm_in); } else { cam->conf->database_port = parm_in; } - } else if (pact == PARM_ACT_GET){ + } else if (pact == PARM_ACT_GET) { parm = std::to_string(cam->conf->database_port); } return; @@ -2921,9 +2921,9 @@ static void conf_edit_database_user(struct ctx_cam *cam, std::string &parm, enum { if (pact == PARM_ACT_DFLT) { cam->conf->database_user = ""; - } else if (pact == PARM_ACT_SET){ + } else if (pact == PARM_ACT_SET) { cam->conf->database_user = parm; - } else if (pact == PARM_ACT_GET){ + } else if (pact == PARM_ACT_GET) { parm = cam->conf->database_user; } return; @@ -2934,9 +2934,9 @@ static void conf_edit_database_password(struct ctx_cam *cam, std::string &parm, { if (pact == PARM_ACT_DFLT) { cam->conf->database_password = ""; - } else if (pact == PARM_ACT_SET){ + } else if (pact == PARM_ACT_SET) { cam->conf->database_password = parm; - } else if (pact == PARM_ACT_GET){ + } else if (pact == PARM_ACT_GET) { parm = cam->conf->database_password; } return; @@ -2946,16 +2946,16 @@ static void conf_edit_database_password(struct ctx_cam *cam, std::string &parm, static void conf_edit_database_busy_timeout(struct ctx_cam *cam, std::string &parm, enum PARM_ACT pact) { int parm_in; - if (pact == PARM_ACT_DFLT){ + if (pact == PARM_ACT_DFLT) { cam->conf->database_busy_timeout = 0; - } else if (pact == PARM_ACT_SET){ + } else if (pact == PARM_ACT_SET) { parm_in = atoi(parm.c_str()); if ((parm_in < 0) || (parm_in > 10000)) { MOTION_LOG(NTC, TYPE_ALL, NO_ERRNO, _("Invalid database_busy_timeout %d"),parm_in); } else { cam->conf->database_busy_timeout = parm_in; } - } else if (pact == PARM_ACT_GET){ + } else if (pact == PARM_ACT_GET) { parm = std::to_string(cam->conf->database_busy_timeout); } return; @@ -2964,11 +2964,11 @@ static void conf_edit_database_busy_timeout(struct ctx_cam *cam, std::string &pa static void conf_edit_sql_log_picture(struct ctx_cam *cam, std::string &parm, enum PARM_ACT pact) { - if (pact == PARM_ACT_DFLT){ + if (pact == PARM_ACT_DFLT) { cam->conf->sql_log_picture = FALSE; - } else if (pact == PARM_ACT_SET){ + } else if (pact == PARM_ACT_SET) { conf_edit_set_bool(cam->conf->sql_log_picture, parm); - } else if (pact == PARM_ACT_GET){ + } else if (pact == PARM_ACT_GET) { conf_edit_get_bool(parm, cam->conf->sql_log_picture); } return; @@ -2977,11 +2977,11 @@ static void conf_edit_sql_log_picture(struct ctx_cam *cam, std::string &parm, en static void conf_edit_sql_log_snapshot(struct ctx_cam *cam, std::string &parm, enum PARM_ACT pact) { - if (pact == PARM_ACT_DFLT){ + if (pact == PARM_ACT_DFLT) { cam->conf->sql_log_snapshot = FALSE; - } else if (pact == PARM_ACT_SET){ + } else if (pact == PARM_ACT_SET) { conf_edit_set_bool(cam->conf->sql_log_snapshot, parm); - } else if (pact == PARM_ACT_GET){ + } else if (pact == PARM_ACT_GET) { conf_edit_get_bool(parm, cam->conf->sql_log_snapshot); } return; @@ -2990,11 +2990,11 @@ static void conf_edit_sql_log_snapshot(struct ctx_cam *cam, std::string &parm, e static void conf_edit_sql_log_movie(struct ctx_cam *cam, std::string &parm, enum PARM_ACT pact) { - if (pact == PARM_ACT_DFLT){ + if (pact == PARM_ACT_DFLT) { cam->conf->sql_log_movie = FALSE; - } else if (pact == PARM_ACT_SET){ + } else if (pact == PARM_ACT_SET) { conf_edit_set_bool(cam->conf->sql_log_movie, parm); - } else if (pact == PARM_ACT_GET){ + } else if (pact == PARM_ACT_GET) { conf_edit_get_bool(parm, cam->conf->sql_log_movie); } return; @@ -3003,11 +3003,11 @@ static void conf_edit_sql_log_movie(struct ctx_cam *cam, std::string &parm, enum static void conf_edit_sql_log_timelapse(struct ctx_cam *cam, std::string &parm, enum PARM_ACT pact) { - if (pact == PARM_ACT_DFLT){ + if (pact == PARM_ACT_DFLT) { cam->conf->sql_log_timelapse = FALSE; - } else if (pact == PARM_ACT_SET){ + } else if (pact == PARM_ACT_SET) { conf_edit_set_bool(cam->conf->sql_log_timelapse, parm); - } else if (pact == PARM_ACT_GET){ + } else if (pact == PARM_ACT_GET) { conf_edit_get_bool(parm, cam->conf->sql_log_timelapse); } return; @@ -3018,9 +3018,9 @@ static void conf_edit_sql_query_start(struct ctx_cam *cam, std::string &parm, en { if (pact == PARM_ACT_DFLT) { cam->conf->sql_query_start = ""; - } else if (pact == PARM_ACT_SET){ + } else if (pact == PARM_ACT_SET) { cam->conf->sql_query_start = parm; - } else if (pact == PARM_ACT_GET){ + } else if (pact == PARM_ACT_GET) { parm = cam->conf->sql_query_start; } return; @@ -3031,9 +3031,9 @@ static void conf_edit_sql_query_stop(struct ctx_cam *cam, std::string &parm, enu { if (pact == PARM_ACT_DFLT) { cam->conf->sql_query_stop = ""; - } else if (pact == PARM_ACT_SET){ + } else if (pact == PARM_ACT_SET) { cam->conf->sql_query_stop = parm; - } else if (pact == PARM_ACT_GET){ + } else if (pact == PARM_ACT_GET) { parm = cam->conf->sql_query_stop; } return; @@ -3044,9 +3044,9 @@ static void conf_edit_sql_query(struct ctx_cam *cam, std::string &parm, enum PAR { if (pact == PARM_ACT_DFLT) { cam->conf->sql_query = ""; - } else if (pact == PARM_ACT_SET){ + } else if (pact == PARM_ACT_SET) { cam->conf->sql_query = parm; - } else if (pact == PARM_ACT_GET){ + } else if (pact == PARM_ACT_GET) { parm = cam->conf->sql_query; } return; @@ -3055,11 +3055,11 @@ static void conf_edit_sql_query(struct ctx_cam *cam, std::string &parm, enum PAR static void conf_edit_ptz_auto_track(struct ctx_cam *cam, std::string &parm, enum PARM_ACT pact) { - if (pact == PARM_ACT_DFLT){ + if (pact == PARM_ACT_DFLT) { cam->conf->ptz_auto_track = FALSE; - } else if (pact == PARM_ACT_SET){ + } else if (pact == PARM_ACT_SET) { conf_edit_set_bool(cam->conf->ptz_auto_track, parm); - } else if (pact == PARM_ACT_GET){ + } else if (pact == PARM_ACT_GET) { conf_edit_get_bool(parm, cam->conf->ptz_auto_track); } return; @@ -3069,16 +3069,16 @@ static void conf_edit_ptz_auto_track(struct ctx_cam *cam, std::string &parm, enu static void conf_edit_ptz_wait(struct ctx_cam *cam, std::string &parm, enum PARM_ACT pact) { int parm_in; - if (pact == PARM_ACT_DFLT){ + if (pact == PARM_ACT_DFLT) { cam->conf->ptz_wait = 0; - } else if (pact == PARM_ACT_SET){ + } else if (pact == PARM_ACT_SET) { parm_in = atoi(parm.c_str()); if ((parm_in < 0) || (parm_in > 2147483647)) { MOTION_LOG(NTC, TYPE_ALL, NO_ERRNO, _("Invalid ptz_wait %d"),parm_in); } else { cam->conf->ptz_wait = parm_in; } - } else if (pact == PARM_ACT_GET){ + } else if (pact == PARM_ACT_GET) { parm = std::to_string(cam->conf->ptz_wait); } return; @@ -3089,9 +3089,9 @@ static void conf_edit_ptz_move_track(struct ctx_cam *cam, std::string &parm, enu { if (pact == PARM_ACT_DFLT) { cam->conf->ptz_move_track = ""; - } else if (pact == PARM_ACT_SET){ + } else if (pact == PARM_ACT_SET) { cam->conf->ptz_move_track = parm; - } else if (pact == PARM_ACT_GET){ + } else if (pact == PARM_ACT_GET) { parm = cam->conf->ptz_move_track; } return; @@ -3102,9 +3102,9 @@ static void conf_edit_ptz_pan_left(struct ctx_cam *cam, std::string &parm, enum { if (pact == PARM_ACT_DFLT) { cam->conf->ptz_pan_left = ""; - } else if (pact == PARM_ACT_SET){ + } else if (pact == PARM_ACT_SET) { cam->conf->ptz_pan_left = parm; - } else if (pact == PARM_ACT_GET){ + } else if (pact == PARM_ACT_GET) { parm = cam->conf->ptz_pan_left; } return; @@ -3115,9 +3115,9 @@ static void conf_edit_ptz_pan_right(struct ctx_cam *cam, std::string &parm, enum { if (pact == PARM_ACT_DFLT) { cam->conf->ptz_pan_right = ""; - } else if (pact == PARM_ACT_SET){ + } else if (pact == PARM_ACT_SET) { cam->conf->ptz_pan_right = parm; - } else if (pact == PARM_ACT_GET){ + } else if (pact == PARM_ACT_GET) { parm = cam->conf->ptz_pan_right; } return; @@ -3128,9 +3128,9 @@ static void conf_edit_ptz_tilt_up(struct ctx_cam *cam, std::string &parm, enum P { if (pact == PARM_ACT_DFLT) { cam->conf->ptz_tilt_up = ""; - } else if (pact == PARM_ACT_SET){ + } else if (pact == PARM_ACT_SET) { cam->conf->ptz_tilt_up = parm; - } else if (pact == PARM_ACT_GET){ + } else if (pact == PARM_ACT_GET) { parm = cam->conf->ptz_tilt_up; } return; @@ -3141,9 +3141,9 @@ static void conf_edit_ptz_tilt_down(struct ctx_cam *cam, std::string &parm, enum { if (pact == PARM_ACT_DFLT) { cam->conf->ptz_tilt_down = ""; - } else if (pact == PARM_ACT_SET){ + } else if (pact == PARM_ACT_SET) { cam->conf->ptz_tilt_down = parm; - } else if (pact == PARM_ACT_GET){ + } else if (pact == PARM_ACT_GET) { parm = cam->conf->ptz_tilt_down; } return; @@ -3154,9 +3154,9 @@ static void conf_edit_ptz_zoom_in(struct ctx_cam *cam, std::string &parm, enum P { if (pact == PARM_ACT_DFLT) { cam->conf->ptz_zoom_in = ""; - } else if (pact == PARM_ACT_SET){ + } else if (pact == PARM_ACT_SET) { cam->conf->ptz_zoom_in = parm; - } else if (pact == PARM_ACT_GET){ + } else if (pact == PARM_ACT_GET) { parm = cam->conf->ptz_zoom_in; } return; @@ -3167,9 +3167,9 @@ static void conf_edit_ptz_zoom_out(struct ctx_cam *cam, std::string &parm, enum { if (pact == PARM_ACT_DFLT) { cam->conf->ptz_zoom_out = ""; - } else if (pact == PARM_ACT_SET){ + } else if (pact == PARM_ACT_SET) { cam->conf->ptz_zoom_out = parm; - } else if (pact == PARM_ACT_GET){ + } else if (pact == PARM_ACT_GET) { parm = cam->conf->ptz_zoom_out; } return; @@ -3180,14 +3180,14 @@ static void conf_edit_ptz_zoom_out(struct ctx_cam *cam, std::string &parm, enum static void conf_edit_cat00(struct ctx_motapp *motapp, std::string cmd , std::string &parm_val, enum PARM_ACT pact) { - if (cmd == "daemon") { conf_edit_daemon(motapp, parm_val, pact); - } else if (cmd == "conf_filename"){ conf_edit_conf_filename(motapp, parm_val, pact); - } else if (cmd == "setup_mode") { conf_edit_setup_mode(motapp, parm_val, pact); - } else if (cmd == "pid_file"){ conf_edit_pid_file(motapp, parm_val, pact); - } else if (cmd == "log_file"){ conf_edit_log_file(motapp, parm_val, pact); - } else if (cmd == "log_level"){ conf_edit_log_level(motapp, parm_val, pact); - } else if (cmd == "log_type"){ conf_edit_log_type(motapp, parm_val, pact); - } else if (cmd == "native_language"){ conf_edit_native_language(motapp, parm_val, pact); + if (cmd == "daemon") { conf_edit_daemon(motapp, parm_val, pact); + } else if (cmd == "conf_filename") { conf_edit_conf_filename(motapp, parm_val, pact); + } else if (cmd == "setup_mode") { conf_edit_setup_mode(motapp, parm_val, pact); + } else if (cmd == "pid_file") { conf_edit_pid_file(motapp, parm_val, pact); + } else if (cmd == "log_file") { conf_edit_log_file(motapp, parm_val, pact); + } else if (cmd == "log_level") { conf_edit_log_level(motapp, parm_val, pact); + } else if (cmd == "log_type") { conf_edit_log_type(motapp, parm_val, pact); + } else if (cmd == "native_language") { conf_edit_native_language(motapp, parm_val, pact); } } @@ -3195,13 +3195,13 @@ static void conf_edit_cat00(struct ctx_motapp *motapp, std::string cmd static void conf_edit_cat01(struct ctx_cam *cam, std::string parm_nm , std::string &parm_val, enum PARM_ACT pact) { - if (parm_nm == "camera_dir"){ conf_edit_camera_dir(cam, parm_val, pact); - } else if (parm_nm == "camera_name"){ conf_edit_camera_name(cam, parm_val, pact); - } else if (parm_nm == "camera_id"){ conf_edit_camera_id(cam, parm_val, pact); - } else if (parm_nm == "camera_tmo"){ conf_edit_camera_tmo(cam, parm_val, pact); - } else if (parm_nm == "target_dir"){ conf_edit_target_dir(cam, parm_val, pact); - } else if (parm_nm == "watchdog_tmo"){ conf_edit_watchdog_tmo(cam, parm_val, pact); - } else if (parm_nm == "watchdog_kill"){ conf_edit_watchdog_kill(cam, parm_val, pact); + if (parm_nm == "camera_dir") { conf_edit_camera_dir(cam, parm_val, pact); + } else if (parm_nm == "camera_name") { conf_edit_camera_name(cam, parm_val, pact); + } else if (parm_nm == "camera_id") { conf_edit_camera_id(cam, parm_val, pact); + } else if (parm_nm == "camera_tmo") { conf_edit_camera_tmo(cam, parm_val, pact); + } else if (parm_nm == "target_dir") { conf_edit_target_dir(cam, parm_val, pact); + } else if (parm_nm == "watchdog_tmo") { conf_edit_watchdog_tmo(cam, parm_val, pact); + } else if (parm_nm == "watchdog_kill") { conf_edit_watchdog_kill(cam, parm_val, pact); } } @@ -3210,15 +3210,15 @@ static void conf_edit_cat02(struct ctx_cam *cam, std::string parm_nm , std::string &parm_val, enum PARM_ACT pact) { - if (parm_nm == "v4l2_device"){ conf_edit_v4l2_device(cam, parm_val, pact); - } else if (parm_nm == "v4l2_params"){ conf_edit_v4l2_params(cam, parm_val, pact); - } else if (parm_nm == "netcam_url"){ conf_edit_netcam_url(cam, parm_val, pact); - } else if (parm_nm == "netcam_params"){ conf_edit_netcam_params(cam, parm_val, pact); - } else if (parm_nm == "netcam_high_url"){ conf_edit_netcam_high_url(cam, parm_val, pact); - } else if (parm_nm == "netcam_high_params"){ conf_edit_netcam_high_params(cam, parm_val, pact); - } else if (parm_nm == "netcam_userpass"){ conf_edit_netcam_userpass(cam, parm_val, pact); - } else if (parm_nm == "mmalcam_name"){ conf_edit_mmalcam_name(cam, parm_val, pact); - } else if (parm_nm == "mmalcam_params"){ conf_edit_mmalcam_params(cam, parm_val, pact); + if (parm_nm == "v4l2_device") { conf_edit_v4l2_device(cam, parm_val, pact); + } else if (parm_nm == "v4l2_params") { conf_edit_v4l2_params(cam, parm_val, pact); + } else if (parm_nm == "netcam_url") { conf_edit_netcam_url(cam, parm_val, pact); + } else if (parm_nm == "netcam_params") { conf_edit_netcam_params(cam, parm_val, pact); + } else if (parm_nm == "netcam_high_url") { conf_edit_netcam_high_url(cam, parm_val, pact); + } else if (parm_nm == "netcam_high_params") { conf_edit_netcam_high_params(cam, parm_val, pact); + } else if (parm_nm == "netcam_userpass") { conf_edit_netcam_userpass(cam, parm_val, pact); + } else if (parm_nm == "mmalcam_name") { conf_edit_mmalcam_name(cam, parm_val, pact); + } else if (parm_nm == "mmalcam_params") { conf_edit_mmalcam_params(cam, parm_val, pact); } } @@ -3226,12 +3226,12 @@ static void conf_edit_cat02(struct ctx_cam *cam, std::string parm_nm static void conf_edit_cat03(struct ctx_cam *cam, std::string parm_nm , std::string &parm_val, enum PARM_ACT pact) { - if (parm_nm == "width"){ conf_edit_width(cam, parm_val, pact); - } else if (parm_nm == "height"){ conf_edit_height(cam, parm_val, pact); - } else if (parm_nm == "framerate"){ conf_edit_framerate(cam, parm_val, pact); - } else if (parm_nm == "minimum_frame_time"){ conf_edit_minimum_frame_time(cam, parm_val, pact); - } else if (parm_nm == "rotate"){ conf_edit_rotate(cam, parm_val, pact); - } else if (parm_nm == "flip_axis"){ conf_edit_flip_axis(cam, parm_val, pact); + if (parm_nm == "width") { conf_edit_width(cam, parm_val, pact); + } else if (parm_nm == "height") { conf_edit_height(cam, parm_val, pact); + } else if (parm_nm == "framerate") { conf_edit_framerate(cam, parm_val, pact); + } else if (parm_nm == "minimum_frame_time") { conf_edit_minimum_frame_time(cam, parm_val, pact); + } else if (parm_nm == "rotate") { conf_edit_rotate(cam, parm_val, pact); + } else if (parm_nm == "flip_axis") { conf_edit_flip_axis(cam, parm_val, pact); } } @@ -3239,13 +3239,13 @@ static void conf_edit_cat03(struct ctx_cam *cam, std::string parm_nm static void conf_edit_cat04(struct ctx_cam *cam, std::string parm_nm , std::string &parm_val, enum PARM_ACT pact) { - if (parm_nm == "locate_motion_mode"){ conf_edit_locate_motion_mode(cam, parm_val, pact); - } else if (parm_nm == "locate_motion_style"){ conf_edit_locate_motion_style(cam, parm_val, pact); - } else if (parm_nm == "text_left"){ conf_edit_text_left(cam, parm_val, pact); - } else if (parm_nm == "text_right"){ conf_edit_text_right(cam, parm_val, pact); - } else if (parm_nm == "text_changes"){ conf_edit_text_changes(cam, parm_val, pact); - } else if (parm_nm == "text_scale"){ conf_edit_text_scale(cam, parm_val, pact); - } else if (parm_nm == "text_event"){ conf_edit_text_event(cam, parm_val, pact); + if (parm_nm == "locate_motion_mode") { conf_edit_locate_motion_mode(cam, parm_val, pact); + } else if (parm_nm == "locate_motion_style") { conf_edit_locate_motion_style(cam, parm_val, pact); + } else if (parm_nm == "text_left") { conf_edit_text_left(cam, parm_val, pact); + } else if (parm_nm == "text_right") { conf_edit_text_right(cam, parm_val, pact); + } else if (parm_nm == "text_changes") { conf_edit_text_changes(cam, parm_val, pact); + } else if (parm_nm == "text_scale") { conf_edit_text_scale(cam, parm_val, pact); + } else if (parm_nm == "text_event") { conf_edit_text_event(cam, parm_val, pact); } } @@ -3253,18 +3253,18 @@ static void conf_edit_cat04(struct ctx_cam *cam, std::string parm_nm static void conf_edit_cat05(struct ctx_cam *cam, std::string parm_nm , std::string &parm_val, enum PARM_ACT pact) { - if (parm_nm == "emulate_motion"){ conf_edit_emulate_motion(cam, parm_val, pact); - } else if (parm_nm == "primary_method"){ conf_edit_primary_method(cam, parm_val, pact); - } else if (parm_nm == "threshold"){ conf_edit_threshold(cam, parm_val, pact); - } else if (parm_nm == "threshold_maximum"){ conf_edit_threshold_maximum(cam, parm_val, pact); - } else if (parm_nm == "threshold_sdevx"){ conf_edit_threshold_sdevx(cam, parm_val, pact); - } else if (parm_nm == "threshold_sdevy"){ conf_edit_threshold_sdevy(cam, parm_val, pact); - } else if (parm_nm == "threshold_sdevxy"){ conf_edit_threshold_sdevxy(cam, parm_val, pact); - } else if (parm_nm == "threshold_ratio"){ conf_edit_threshold_ratio(cam, parm_val, pact); - } else if (parm_nm == "threshold_tune"){ conf_edit_threshold_tune(cam, parm_val, pact); - } else if (parm_nm == "secondary_interval"){ conf_edit_secondary_interval(cam, parm_val, pact); - } else if (parm_nm == "secondary_method"){ conf_edit_secondary_method(cam, parm_val, pact); - } else if (parm_nm == "secondary_params"){ conf_edit_secondary_params(cam, parm_val, pact); + if (parm_nm == "emulate_motion") { conf_edit_emulate_motion(cam, parm_val, pact); + } else if (parm_nm == "primary_method") { conf_edit_primary_method(cam, parm_val, pact); + } else if (parm_nm == "threshold") { conf_edit_threshold(cam, parm_val, pact); + } else if (parm_nm == "threshold_maximum") { conf_edit_threshold_maximum(cam, parm_val, pact); + } else if (parm_nm == "threshold_sdevx") { conf_edit_threshold_sdevx(cam, parm_val, pact); + } else if (parm_nm == "threshold_sdevy") { conf_edit_threshold_sdevy(cam, parm_val, pact); + } else if (parm_nm == "threshold_sdevxy") { conf_edit_threshold_sdevxy(cam, parm_val, pact); + } else if (parm_nm == "threshold_ratio") { conf_edit_threshold_ratio(cam, parm_val, pact); + } else if (parm_nm == "threshold_tune") { conf_edit_threshold_tune(cam, parm_val, pact); + } else if (parm_nm == "secondary_interval") { conf_edit_secondary_interval(cam, parm_val, pact); + } else if (parm_nm == "secondary_method") { conf_edit_secondary_method(cam, parm_val, pact); + } else if (parm_nm == "secondary_params") { conf_edit_secondary_params(cam, parm_val, pact); } } @@ -3272,13 +3272,13 @@ static void conf_edit_cat05(struct ctx_cam *cam, std::string parm_nm static void conf_edit_cat06(struct ctx_cam *cam, std::string parm_nm , std::string &parm_val, enum PARM_ACT pact) { - if (parm_nm == "noise_level"){ conf_edit_noise_level(cam, parm_val, pact); - } else if (parm_nm == "noise_tune"){ conf_edit_noise_tune(cam, parm_val, pact); - } else if (parm_nm == "despeckle_filter"){ conf_edit_despeckle_filter(cam, parm_val, pact); - } else if (parm_nm == "area_detect"){ conf_edit_area_detect(cam, parm_val, pact); - } else if (parm_nm == "mask_file"){ conf_edit_mask_file(cam, parm_val, pact); - } else if (parm_nm == "mask_privacy"){ conf_edit_mask_privacy(cam, parm_val, pact); - } else if (parm_nm == "smart_mask_speed"){ conf_edit_smart_mask_speed(cam, parm_val, pact); + if (parm_nm == "noise_level") { conf_edit_noise_level(cam, parm_val, pact); + } else if (parm_nm == "noise_tune") { conf_edit_noise_tune(cam, parm_val, pact); + } else if (parm_nm == "despeckle_filter") { conf_edit_despeckle_filter(cam, parm_val, pact); + } else if (parm_nm == "area_detect") { conf_edit_area_detect(cam, parm_val, pact); + } else if (parm_nm == "mask_file") { conf_edit_mask_file(cam, parm_val, pact); + } else if (parm_nm == "mask_privacy") { conf_edit_mask_privacy(cam, parm_val, pact); + } else if (parm_nm == "smart_mask_speed") { conf_edit_smart_mask_speed(cam, parm_val, pact); } } @@ -3286,13 +3286,13 @@ static void conf_edit_cat06(struct ctx_cam *cam, std::string parm_nm static void conf_edit_cat07(struct ctx_cam *cam, std::string parm_nm , std::string &parm_val, enum PARM_ACT pact) { - if (parm_nm == "lightswitch_percent"){ conf_edit_lightswitch_percent(cam, parm_val, pact); - } else if (parm_nm == "lightswitch_frames"){ conf_edit_lightswitch_frames(cam, parm_val, pact); - } else if (parm_nm == "minimum_motion_frames"){ conf_edit_minimum_motion_frames(cam, parm_val, pact); - } else if (parm_nm == "static_object_time"){ conf_edit_static_object_time(cam, parm_val, pact); - } else if (parm_nm == "event_gap"){ conf_edit_event_gap(cam, parm_val, pact); - } else if (parm_nm == "pre_capture"){ conf_edit_pre_capture(cam, parm_val, pact); - } else if (parm_nm == "post_capture"){ conf_edit_post_capture(cam, parm_val, pact); + if (parm_nm == "lightswitch_percent") { conf_edit_lightswitch_percent(cam, parm_val, pact); + } else if (parm_nm == "lightswitch_frames") { conf_edit_lightswitch_frames(cam, parm_val, pact); + } else if (parm_nm == "minimum_motion_frames") { conf_edit_minimum_motion_frames(cam, parm_val, pact); + } else if (parm_nm == "static_object_time") { conf_edit_static_object_time(cam, parm_val, pact); + } else if (parm_nm == "event_gap") { conf_edit_event_gap(cam, parm_val, pact); + } else if (parm_nm == "pre_capture") { conf_edit_pre_capture(cam, parm_val, pact); + } else if (parm_nm == "post_capture") { conf_edit_post_capture(cam, parm_val, pact); } } @@ -3300,16 +3300,16 @@ static void conf_edit_cat07(struct ctx_cam *cam, std::string parm_nm static void conf_edit_cat08(struct ctx_cam *cam, std::string parm_nm , std::string &parm_val, enum PARM_ACT pact) { - if (parm_nm == "on_event_start"){ conf_edit_on_event_start(cam, parm_val, pact); - } else if (parm_nm == "on_event_end"){ conf_edit_on_event_end(cam, parm_val, pact); - } else if (parm_nm == "on_picture_save"){ conf_edit_on_picture_save(cam, parm_val, pact); - } else if (parm_nm == "on_area_detected"){ conf_edit_on_area_detected(cam, parm_val, pact); - } else if (parm_nm == "on_motion_detected"){ conf_edit_on_motion_detected(cam, parm_val, pact); - } else if (parm_nm == "on_movie_start"){ conf_edit_on_movie_start(cam, parm_val, pact); - } else if (parm_nm == "on_movie_end"){ conf_edit_on_movie_end(cam, parm_val, pact); - } else if (parm_nm == "on_camera_lost"){ conf_edit_on_camera_lost(cam, parm_val, pact); - } else if (parm_nm == "on_camera_found"){ conf_edit_on_camera_found(cam, parm_val, pact); - } else if (parm_nm == "on_secondary_detect"){ conf_edit_on_secondary_detect(cam, parm_val, pact); + if (parm_nm == "on_event_start") { conf_edit_on_event_start(cam, parm_val, pact); + } else if (parm_nm == "on_event_end") { conf_edit_on_event_end(cam, parm_val, pact); + } else if (parm_nm == "on_picture_save") { conf_edit_on_picture_save(cam, parm_val, pact); + } else if (parm_nm == "on_area_detected") { conf_edit_on_area_detected(cam, parm_val, pact); + } else if (parm_nm == "on_motion_detected") { conf_edit_on_motion_detected(cam, parm_val, pact); + } else if (parm_nm == "on_movie_start") { conf_edit_on_movie_start(cam, parm_val, pact); + } else if (parm_nm == "on_movie_end") { conf_edit_on_movie_end(cam, parm_val, pact); + } else if (parm_nm == "on_camera_lost") { conf_edit_on_camera_lost(cam, parm_val, pact); + } else if (parm_nm == "on_camera_found") { conf_edit_on_camera_found(cam, parm_val, pact); + } else if (parm_nm == "on_secondary_detect") { conf_edit_on_secondary_detect(cam, parm_val, pact); } } @@ -3317,14 +3317,14 @@ static void conf_edit_cat08(struct ctx_cam *cam, std::string parm_nm static void conf_edit_cat09(struct ctx_cam *cam, std::string parm_nm , std::string &parm_val, enum PARM_ACT pact) { - if (parm_nm == "picture_output"){ conf_edit_picture_output(cam, parm_val, pact); - } else if (parm_nm == "picture_output_motion"){ conf_edit_picture_output_motion(cam, parm_val, pact); - } else if (parm_nm == "picture_type"){ conf_edit_picture_type(cam, parm_val, pact); - } else if (parm_nm == "picture_quality"){ conf_edit_picture_quality(cam, parm_val, pact); - } else if (parm_nm == "picture_exif"){ conf_edit_picture_exif(cam, parm_val, pact); - } else if (parm_nm == "picture_filename"){ conf_edit_picture_filename(cam, parm_val, pact); - } else if (parm_nm == "snapshot_interval"){ conf_edit_snapshot_interval(cam, parm_val, pact); - } else if (parm_nm == "snapshot_filename"){ conf_edit_snapshot_filename(cam, parm_val, pact); + if (parm_nm == "picture_output") { conf_edit_picture_output(cam, parm_val, pact); + } else if (parm_nm == "picture_output_motion") { conf_edit_picture_output_motion(cam, parm_val, pact); + } else if (parm_nm == "picture_type") { conf_edit_picture_type(cam, parm_val, pact); + } else if (parm_nm == "picture_quality") { conf_edit_picture_quality(cam, parm_val, pact); + } else if (parm_nm == "picture_exif") { conf_edit_picture_exif(cam, parm_val, pact); + } else if (parm_nm == "picture_filename") { conf_edit_picture_filename(cam, parm_val, pact); + } else if (parm_nm == "snapshot_interval") { conf_edit_snapshot_interval(cam, parm_val, pact); + } else if (parm_nm == "snapshot_filename") { conf_edit_snapshot_filename(cam, parm_val, pact); } } @@ -3332,16 +3332,16 @@ static void conf_edit_cat09(struct ctx_cam *cam, std::string parm_nm static void conf_edit_cat10(struct ctx_cam *cam, std::string parm_nm , std::string &parm_val, enum PARM_ACT pact) { - if (parm_nm == "movie_output"){ conf_edit_movie_output(cam, parm_val, pact); - } else if (parm_nm == "movie_output_motion"){ conf_edit_movie_output_motion(cam, parm_val, pact); - } else if (parm_nm == "movie_max_time"){ conf_edit_movie_max_time(cam, parm_val, pact); - } else if (parm_nm == "movie_bps"){ conf_edit_movie_bps(cam, parm_val, pact); - } else if (parm_nm == "movie_quality"){ conf_edit_movie_quality(cam, parm_val, pact); - } else if (parm_nm == "movie_codec"){ conf_edit_movie_codec(cam, parm_val, pact); - } else if (parm_nm == "movie_passthrough"){ conf_edit_movie_passthrough(cam, parm_val, pact); - } else if (parm_nm == "movie_filename"){ conf_edit_movie_filename(cam, parm_val, pact); - } else if (parm_nm == "movie_extpipe_use"){ conf_edit_movie_extpipe_use(cam, parm_val, pact); - } else if (parm_nm == "movie_extpipe"){ conf_edit_movie_extpipe(cam, parm_val, pact); + if (parm_nm == "movie_output") { conf_edit_movie_output(cam, parm_val, pact); + } else if (parm_nm == "movie_output_motion") { conf_edit_movie_output_motion(cam, parm_val, pact); + } else if (parm_nm == "movie_max_time") { conf_edit_movie_max_time(cam, parm_val, pact); + } else if (parm_nm == "movie_bps") { conf_edit_movie_bps(cam, parm_val, pact); + } else if (parm_nm == "movie_quality") { conf_edit_movie_quality(cam, parm_val, pact); + } else if (parm_nm == "movie_codec") { conf_edit_movie_codec(cam, parm_val, pact); + } else if (parm_nm == "movie_passthrough") { conf_edit_movie_passthrough(cam, parm_val, pact); + } else if (parm_nm == "movie_filename") { conf_edit_movie_filename(cam, parm_val, pact); + } else if (parm_nm == "movie_extpipe_use") { conf_edit_movie_extpipe_use(cam, parm_val, pact); + } else if (parm_nm == "movie_extpipe") { conf_edit_movie_extpipe(cam, parm_val, pact); } } @@ -3349,11 +3349,11 @@ static void conf_edit_cat10(struct ctx_cam *cam, std::string parm_nm static void conf_edit_cat11(struct ctx_cam *cam, std::string parm_nm , std::string &parm_val, enum PARM_ACT pact) { - if (parm_nm == "timelapse_interval"){ conf_edit_timelapse_interval(cam, parm_val, pact); - } else if (parm_nm == "timelapse_mode"){ conf_edit_timelapse_mode(cam, parm_val, pact); - } else if (parm_nm == "timelapse_fps"){ conf_edit_timelapse_fps(cam, parm_val, pact); - } else if (parm_nm == "timelapse_codec"){ conf_edit_timelapse_codec(cam, parm_val, pact); - } else if (parm_nm == "timelapse_filename"){ conf_edit_timelapse_filename(cam, parm_val, pact); + if (parm_nm == "timelapse_interval") { conf_edit_timelapse_interval(cam, parm_val, pact); + } else if (parm_nm == "timelapse_mode") { conf_edit_timelapse_mode(cam, parm_val, pact); + } else if (parm_nm == "timelapse_fps") { conf_edit_timelapse_fps(cam, parm_val, pact); + } else if (parm_nm == "timelapse_codec") { conf_edit_timelapse_codec(cam, parm_val, pact); + } else if (parm_nm == "timelapse_filename") { conf_edit_timelapse_filename(cam, parm_val, pact); } } @@ -3361,8 +3361,8 @@ static void conf_edit_cat11(struct ctx_cam *cam, std::string parm_nm static void conf_edit_cat12(struct ctx_cam *cam, std::string parm_nm , std::string &parm_val, enum PARM_ACT pact) { - if (parm_nm == "video_pipe"){ conf_edit_video_pipe(cam, parm_val, pact); - } else if (parm_nm == "video_pipe_motion"){ conf_edit_video_pipe_motion(cam, parm_val, pact); + if (parm_nm == "video_pipe") { conf_edit_video_pipe(cam, parm_val, pact); + } else if (parm_nm == "video_pipe_motion") { conf_edit_video_pipe_motion(cam, parm_val, pact); } } @@ -3370,18 +3370,18 @@ static void conf_edit_cat12(struct ctx_cam *cam, std::string parm_nm static void conf_edit_cat13(struct ctx_cam *cam, std::string parm_nm , std::string &parm_val, enum PARM_ACT pact) { - if (parm_nm == "webcontrol_port"){ conf_edit_webcontrol_port(cam, parm_val, pact); - } else if (parm_nm == "webcontrol_ipv6"){ conf_edit_webcontrol_ipv6(cam, parm_val, pact); - } else if (parm_nm == "webcontrol_localhost"){ conf_edit_webcontrol_localhost(cam, parm_val, pact); - } else if (parm_nm == "webcontrol_parms"){ conf_edit_webcontrol_parms(cam, parm_val, pact); - } else if (parm_nm == "webcontrol_interface"){ conf_edit_webcontrol_interface(cam, parm_val, pact); - } else if (parm_nm == "webcontrol_auth_method"){ conf_edit_webcontrol_auth_method(cam, parm_val, pact); - } else if (parm_nm == "webcontrol_authentication"){ conf_edit_webcontrol_authentication(cam, parm_val, pact); - } else if (parm_nm == "webcontrol_tls"){ conf_edit_webcontrol_tls(cam, parm_val, pact); - } else if (parm_nm == "webcontrol_cert"){ conf_edit_webcontrol_cert(cam, parm_val, pact); - } else if (parm_nm == "webcontrol_key"){ conf_edit_webcontrol_key(cam, parm_val, pact); - } else if (parm_nm == "webcontrol_cors_header"){ conf_edit_webcontrol_cors_header(cam, parm_val, pact); - } else if (parm_nm == "webcontrol_html"){ conf_edit_webcontrol_html(cam, parm_val, pact); + if (parm_nm == "webcontrol_port") { conf_edit_webcontrol_port(cam, parm_val, pact); + } else if (parm_nm == "webcontrol_ipv6") { conf_edit_webcontrol_ipv6(cam, parm_val, pact); + } else if (parm_nm == "webcontrol_localhost") { conf_edit_webcontrol_localhost(cam, parm_val, pact); + } else if (parm_nm == "webcontrol_parms") { conf_edit_webcontrol_parms(cam, parm_val, pact); + } else if (parm_nm == "webcontrol_interface") { conf_edit_webcontrol_interface(cam, parm_val, pact); + } else if (parm_nm == "webcontrol_auth_method") { conf_edit_webcontrol_auth_method(cam, parm_val, pact); + } else if (parm_nm == "webcontrol_authentication") { conf_edit_webcontrol_authentication(cam, parm_val, pact); + } else if (parm_nm == "webcontrol_tls") { conf_edit_webcontrol_tls(cam, parm_val, pact); + } else if (parm_nm == "webcontrol_cert") { conf_edit_webcontrol_cert(cam, parm_val, pact); + } else if (parm_nm == "webcontrol_key") { conf_edit_webcontrol_key(cam, parm_val, pact); + } else if (parm_nm == "webcontrol_cors_header") { conf_edit_webcontrol_cors_header(cam, parm_val, pact); + } else if (parm_nm == "webcontrol_html") { conf_edit_webcontrol_html(cam, parm_val, pact); } } @@ -3389,27 +3389,27 @@ static void conf_edit_cat13(struct ctx_cam *cam, std::string parm_nm static void conf_edit_cat14(struct ctx_cam *cam, std::string parm_nm , std::string &parm_val, enum PARM_ACT pact) { - if (parm_nm == "stream_preview_scale"){ conf_edit_stream_preview_scale(cam, parm_val, pact); - } else if (parm_nm == "stream_preview_newline"){ conf_edit_stream_preview_newline(cam, parm_val, pact); - } else if (parm_nm == "stream_preview_method"){ conf_edit_stream_preview_method(cam, parm_val, pact); - } else if (parm_nm == "stream_preview_ptz"){ conf_edit_stream_preview_ptz(cam, parm_val, pact); - } else if (parm_nm == "stream_quality"){ conf_edit_stream_quality(cam, parm_val, pact); - } else if (parm_nm == "stream_grey"){ conf_edit_stream_grey(cam, parm_val, pact); - } else if (parm_nm == "stream_motion"){ conf_edit_stream_motion(cam, parm_val, pact); - } else if (parm_nm == "stream_maxrate"){ conf_edit_stream_maxrate(cam, parm_val, pact); + if (parm_nm == "stream_preview_scale") { conf_edit_stream_preview_scale(cam, parm_val, pact); + } else if (parm_nm == "stream_preview_newline") { conf_edit_stream_preview_newline(cam, parm_val, pact); + } else if (parm_nm == "stream_preview_method") { conf_edit_stream_preview_method(cam, parm_val, pact); + } else if (parm_nm == "stream_preview_ptz") { conf_edit_stream_preview_ptz(cam, parm_val, pact); + } else if (parm_nm == "stream_quality") { conf_edit_stream_quality(cam, parm_val, pact); + } else if (parm_nm == "stream_grey") { conf_edit_stream_grey(cam, parm_val, pact); + } else if (parm_nm == "stream_motion") { conf_edit_stream_motion(cam, parm_val, pact); + } else if (parm_nm == "stream_maxrate") { conf_edit_stream_maxrate(cam, parm_val, pact); } } static void conf_edit_cat15(struct ctx_cam *cam, std::string parm_nm, std::string &parm_val, enum PARM_ACT pact) { - if (parm_nm == "database_type"){ conf_edit_database_type(cam, parm_val, pact); - } else if (parm_nm == "database_dbname"){ conf_edit_database_dbname(cam, parm_val, pact); - } else if (parm_nm == "database_host"){ conf_edit_database_host(cam, parm_val, pact); - } else if (parm_nm == "database_port"){ conf_edit_database_port(cam, parm_val, pact); - } else if (parm_nm == "database_user"){ conf_edit_database_user(cam, parm_val, pact); - } else if (parm_nm == "database_password"){ conf_edit_database_password(cam, parm_val, pact); - } else if (parm_nm == "database_busy_timeout"){ conf_edit_database_busy_timeout(cam, parm_val, pact); + if (parm_nm == "database_type") { conf_edit_database_type(cam, parm_val, pact); + } else if (parm_nm == "database_dbname") { conf_edit_database_dbname(cam, parm_val, pact); + } else if (parm_nm == "database_host") { conf_edit_database_host(cam, parm_val, pact); + } else if (parm_nm == "database_port") { conf_edit_database_port(cam, parm_val, pact); + } else if (parm_nm == "database_user") { conf_edit_database_user(cam, parm_val, pact); + } else if (parm_nm == "database_password") { conf_edit_database_password(cam, parm_val, pact); + } else if (parm_nm == "database_busy_timeout") { conf_edit_database_busy_timeout(cam, parm_val, pact); } } @@ -3417,13 +3417,13 @@ static void conf_edit_cat15(struct ctx_cam *cam, std::string parm_nm, std::strin static void conf_edit_cat16(struct ctx_cam *cam, std::string parm_nm , std::string &parm_val, enum PARM_ACT pact) { - if (parm_nm == "sql_log_picture"){ conf_edit_sql_log_picture(cam, parm_val, pact); - } else if (parm_nm == "sql_log_snapshot"){ conf_edit_sql_log_snapshot(cam, parm_val, pact); - } else if (parm_nm == "sql_log_movie"){ conf_edit_sql_log_movie(cam, parm_val, pact); - } else if (parm_nm == "sql_log_timelapse"){ conf_edit_sql_log_timelapse(cam, parm_val, pact); - } else if (parm_nm == "sql_query_start"){ conf_edit_sql_query_start(cam, parm_val, pact); - } else if (parm_nm == "sql_query_stop"){ conf_edit_sql_query_stop(cam, parm_val, pact); - } else if (parm_nm == "sql_query"){ conf_edit_sql_query(cam, parm_val, pact); + if (parm_nm == "sql_log_picture") { conf_edit_sql_log_picture(cam, parm_val, pact); + } else if (parm_nm == "sql_log_snapshot") { conf_edit_sql_log_snapshot(cam, parm_val, pact); + } else if (parm_nm == "sql_log_movie") { conf_edit_sql_log_movie(cam, parm_val, pact); + } else if (parm_nm == "sql_log_timelapse") { conf_edit_sql_log_timelapse(cam, parm_val, pact); + } else if (parm_nm == "sql_query_start") { conf_edit_sql_query_start(cam, parm_val, pact); + } else if (parm_nm == "sql_query_stop") { conf_edit_sql_query_stop(cam, parm_val, pact); + } else if (parm_nm == "sql_query") { conf_edit_sql_query(cam, parm_val, pact); } } @@ -3431,15 +3431,15 @@ static void conf_edit_cat16(struct ctx_cam *cam, std::string parm_nm static void conf_edit_cat17(struct ctx_cam *cam, std::string parm_nm , std::string &parm_val, enum PARM_ACT pact) { - if (parm_nm == "ptz_auto_track"){ conf_edit_ptz_auto_track(cam, parm_val, pact); - } else if (parm_nm == "ptz_wait"){ conf_edit_ptz_wait(cam, parm_val, pact); - } else if (parm_nm == "ptz_move_track"){ conf_edit_ptz_move_track(cam, parm_val, pact); - } else if (parm_nm == "ptz_pan_left"){ conf_edit_ptz_pan_left(cam, parm_val, pact); - } else if (parm_nm == "ptz_pan_right"){ conf_edit_ptz_pan_right(cam, parm_val, pact); - } else if (parm_nm == "ptz_tilt_up"){ conf_edit_ptz_tilt_up(cam, parm_val, pact); - } else if (parm_nm == "ptz_tilt_down"){ conf_edit_ptz_tilt_down(cam, parm_val, pact); - } else if (parm_nm == "ptz_zoom_in"){ conf_edit_ptz_zoom_in(cam, parm_val, pact); - } else if (parm_nm == "ptz_zoom_out"){ conf_edit_ptz_zoom_out(cam, parm_val, pact); + if (parm_nm == "ptz_auto_track") { conf_edit_ptz_auto_track(cam, parm_val, pact); + } else if (parm_nm == "ptz_wait") { conf_edit_ptz_wait(cam, parm_val, pact); + } else if (parm_nm == "ptz_move_track") { conf_edit_ptz_move_track(cam, parm_val, pact); + } else if (parm_nm == "ptz_pan_left") { conf_edit_ptz_pan_left(cam, parm_val, pact); + } else if (parm_nm == "ptz_pan_right") { conf_edit_ptz_pan_right(cam, parm_val, pact); + } else if (parm_nm == "ptz_tilt_up") { conf_edit_ptz_tilt_up(cam, parm_val, pact); + } else if (parm_nm == "ptz_tilt_down") { conf_edit_ptz_tilt_down(cam, parm_val, pact); + } else if (parm_nm == "ptz_zoom_in") { conf_edit_ptz_zoom_in(cam, parm_val, pact); + } else if (parm_nm == "ptz_zoom_out") { conf_edit_ptz_zoom_out(cam, parm_val, pact); } } @@ -3543,14 +3543,14 @@ static void conf_edit_depr_vid(struct ctx_motapp *motapp, int threadnbr std::string parm_curr, parm_new; conf_edit_v4l2_params(motapp->cam_list[threadnbr], parm_curr, PARM_ACT_GET); - if (parm_curr == ""){ - if (parm_nm == "power_line_frequency"){ + if (parm_curr == "") { + if (parm_nm == "power_line_frequency") { parm_new = "\"power line frequency\"=" + parm_val; } else { parm_new = parm_nm + "=" + parm_val; } } else { - if (parm_nm == "power_line_frequency"){ + if (parm_nm == "power_line_frequency") { parm_new = parm_curr + ", \"power line frequency\"=" + parm_val; } else { parm_new = parm_curr +", " + parm_nm + "=" + parm_val; @@ -3651,11 +3651,15 @@ void conf_edit_get(struct ctx_cam *cam, std::string parm_nm, char *parm_chr, enu void conf_edit_set(struct ctx_motapp *motapp, bool ismotapp, int threadnbr ,std::string parm_nm, std::string parm_val) { - if (conf_edit_set_active(motapp, ismotapp, threadnbr, parm_nm, parm_val) == 0) return; + if (conf_edit_set_active(motapp, ismotapp, threadnbr, parm_nm, parm_val) == 0) { + return; + } - if (conf_edit_set_depr(motapp, ismotapp, threadnbr, parm_nm, parm_val) == 0) return; + if (conf_edit_set_depr(motapp, ismotapp, threadnbr, parm_nm, parm_val) == 0) { + return; + } - if (ismotapp == false){ + if (ismotapp == false) { MOTION_LOG(ALR, TYPE_ALL, NO_ERRNO, _("Unknown config option \"%s\""), parm_nm.c_str()); } @@ -3667,11 +3671,15 @@ void conf_edit_set(struct ctx_motapp *motapp, bool ismotapp, int threadnbr { std::string parm_nm(parm_nm_chr); - if (conf_edit_set_active(motapp, ismotapp, threadnbr, parm_nm, parm_val) == 0) return; + if (conf_edit_set_active(motapp, ismotapp, threadnbr, parm_nm, parm_val) == 0) { + return; + } - if (conf_edit_set_depr(motapp, ismotapp, threadnbr, parm_nm, parm_val) == 0) return; + if (conf_edit_set_depr(motapp, ismotapp, threadnbr, parm_nm, parm_val) == 0) { + return; + } - if (ismotapp == false){ + if (ismotapp == false) { MOTION_LOG(ALR, TYPE_ALL, NO_ERRNO, _("Unknown config option \"%s\""), parm_nm.c_str()); } @@ -3683,11 +3691,15 @@ void conf_edit_set(struct ctx_motapp *motapp, bool ismotapp, int threadnbr { std::string parm_val(parm_val_chr); - if (conf_edit_set_active(motapp, ismotapp, threadnbr, parm_nm, parm_val) == 0) return; + if (conf_edit_set_active(motapp, ismotapp, threadnbr, parm_nm, parm_val) == 0) { + return; + } - if (conf_edit_set_depr(motapp, ismotapp, threadnbr, parm_nm, parm_val) == 0) return; + if (conf_edit_set_depr(motapp, ismotapp, threadnbr, parm_nm, parm_val) == 0) { + return; + } - if (ismotapp == false){ + if (ismotapp == false) { MOTION_LOG(ALR, TYPE_ALL, NO_ERRNO, _("Unknown config option \"%s\""), parm_nm.c_str()); } @@ -3700,11 +3712,15 @@ void conf_edit_set(struct ctx_motapp *motapp, bool ismotapp, int threadnbr std::string parm_val(parm_val_chr); std::string parm_nm(parm_nm_chr); - if (conf_edit_set_active(motapp, ismotapp, threadnbr, parm_nm, parm_val) == 0) return; + if (conf_edit_set_active(motapp, ismotapp, threadnbr, parm_nm, parm_val) == 0) { + return; + } - if (conf_edit_set_depr(motapp, ismotapp, threadnbr, parm_nm, parm_val) == 0) return; + if (conf_edit_set_depr(motapp, ismotapp, threadnbr, parm_nm, parm_val) == 0) { + return; + } - if (ismotapp == false){ + if (ismotapp == false) { MOTION_LOG(ALR, TYPE_ALL, NO_ERRNO, _("Unknown config option \"%s\""), parm_nm.c_str()); } @@ -3863,7 +3879,7 @@ void conf_camera_add(struct ctx_motapp *motapp) /* Find the number of cameras defined. */ indx_cams = 0; - while (motapp->cam_list[indx_cams] != NULL){ + while (motapp->cam_list[indx_cams] != NULL) { indx_cams++; }; @@ -3987,21 +4003,23 @@ void conf_process(struct ctx_motapp *motapp, bool ismotapp, FILE *fp, int threa /* Trim white space and any CR or LF at the end of the line. */ end = line + strlen(line) - 1; /* Point to the last non-null character in the string. */ - while (end >= line && (*end == ' ' || *end == '\t' || *end == '\n' || *end == '\r')){ + while (end >= line && (*end == ' ' || *end == '\t' || *end == '\n' || *end == '\r')) { end--; } *(end+1) = '\0'; - if (strlen(line) == 0) continue; + if (strlen(line) == 0) { + continue; + } /* Trim leading whitespace from the line and find command. */ beg = line; - while (*beg == ' ' || *beg == '\t'){ + while (*beg == ' ' || *beg == '\t') { beg++; } cmd = beg; /* Command starts here. */ - while (*beg != ' ' && *beg != '\t' && *beg != '=' && *beg != '\0'){ + while (*beg != ' ' && *beg != '\t' && *beg != '=' && *beg != '\0') { beg++; } *beg = '\0'; /* Command string terminates here. */ @@ -4010,7 +4028,7 @@ void conf_process(struct ctx_motapp *motapp, bool ismotapp, FILE *fp, int threa beg++; if (strlen(beg) > 0) { - while (*beg == ' ' || *beg == '\t' || *beg == '=' || *beg == '\n' || *beg == '\r'){ + while (*beg == ' ' || *beg == '\t' || *beg == '=' || *beg == '\n' || *beg == '\r') { beg++; } @@ -4025,7 +4043,7 @@ void conf_process(struct ctx_motapp *motapp, bool ismotapp, FILE *fp, int threa } /* Ignore camera/dir in sub files */ parm_nm = std::string(cmd); - if (arg1 == NULL){ + if (arg1 == NULL) { parm_val= std::string(""); } else { parm_val= std::string(arg1); @@ -4053,7 +4071,7 @@ void conf_parms_log(struct ctx_cam **cam_list) MOTION_LOG(INF, TYPE_ALL, NO_ERRNO ,_("Logging configuration parameters from all files")); threadnbr = 0; - while (cam_list[threadnbr]!= NULL){ + while (cam_list[threadnbr]!= NULL) { motion_log(INF, TYPE_ALL, NO_ERRNO,0 ,_("Camera %d - Config file: %s"), threadnbr, cam_list[threadnbr]->conf_filename); i = 0; @@ -4061,10 +4079,12 @@ void conf_parms_log(struct ctx_cam **cam_list) diff_val = TRUE; conf_edit_get(cam_list[threadnbr], config_parms[i].parm_name , parm_val ,config_parms[i].parm_cat); - if (threadnbr > 0){ + if (threadnbr > 0) { conf_edit_get(cam_list[0], config_parms[i].parm_name , parm_main ,config_parms[i].parm_cat); - if (parm_val == parm_main) diff_val = FALSE; + if (parm_val == parm_main) { + diff_val = FALSE; + } } if (diff_val) { if ((config_parms[i].parm_name == "netcam_url") || @@ -4081,7 +4101,7 @@ void conf_parms_log(struct ctx_cam **cam_list) ,_("%-25s "), config_parms[i].parm_name.c_str()); } else { if ((config_parms[i].parm_name.compare(0,4,"text") == 0) || - (parm_val.compare(0,1, " ") != 0)){ + (parm_val.compare(0,1, " ") != 0)) { motion_log(INF, TYPE_ALL, NO_ERRNO,0, "%-25s %s" , config_parms[i].parm_name.c_str(), parm_val.c_str()); } else { @@ -4125,7 +4145,7 @@ void conf_parms_write(struct ctx_motapp *motapp) fprintf(conffile, "\n\n"); indx = 0; - while (config_parms[indx].parm_name != ""){ + while (config_parms[indx].parm_name != "") { conf_edit_get(motapp->cam_list[indx_cam], config_parms[indx].parm_name , parm_val, config_parms[indx].parm_cat); conf_edit_get(motapp->cam_list[0], config_parms[indx].parm_name @@ -4228,7 +4248,7 @@ void conf_init_app(struct ctx_motapp *motapp, int argc, char *argv[]) fp = fopen(filename.c_str(), "r"); } - if (!fp){ + if (!fp) { MOTION_LOG(ALR, TYPE_ALL, SHOW_ERRNO ,_("could not open configfile %s"), filename.c_str()); } @@ -4287,7 +4307,7 @@ void conf_init_cams(struct ctx_motapp *motapp) } indx=0; - while (motapp->cam_list[indx] != NULL){ + while (motapp->cam_list[indx] != NULL) { motapp->cam_list[indx]->pause = motapp->pause; motapp->cam_list[indx]->threadnr = indx; indx++; @@ -4301,7 +4321,7 @@ void conf_deinit(struct ctx_motapp *motapp) int indx; indx = 0; - while (motapp->cam_list[indx] != NULL){ + while (motapp->cam_list[indx] != NULL) { delete motapp->cam_list[indx]->conf; delete motapp->cam_list[indx]; indx++; diff --git a/src/dbse.cpp b/src/dbse.cpp index 992e1367..c4865781 100644 --- a/src/dbse.cpp +++ b/src/dbse.cpp @@ -29,7 +29,7 @@ static int dbse_global_edits(struct ctx_cam **cam_list) int retcd = 0; - if (cam_list[0]->conf->database_dbname == ""){ + if (cam_list[0]->conf->database_dbname == "") { MOTION_LOG(ERR, TYPE_DB, NO_ERRNO ,_("Invalid database name")); retcd = -1; @@ -37,13 +37,13 @@ static int dbse_global_edits(struct ctx_cam **cam_list) if ((((cam_list[0]->conf->database_type == "mysql")) || ((cam_list[0]->conf->database_type == "mariadb")) || ((cam_list[0]->conf->database_type == "pgsql"))) && - (cam_list[0]->conf->database_port == 0)){ + (cam_list[0]->conf->database_port == 0)) { MOTION_LOG(ERR, TYPE_DB, NO_ERRNO ,_("Must specify database port for mysql/mariadb/pgsql")); retcd = -1; } - if (retcd == -1){ + if (retcd == -1) { MOTION_LOG(ERR, TYPE_DB, NO_ERRNO ,_("Database functionality disabled.")); cam_list[0]->conf->database_type = ""; @@ -81,7 +81,7 @@ void dbse_global_deinit(struct ctx_motapp *motapp) #endif /* HAVE_MYSQL */ indx = 0; - while (motapp->cam_list[indx] != NULL){ + while (motapp->cam_list[indx] != NULL) { if (motapp->cam_list[indx]->dbse != NULL) { free(motapp->cam_list[indx]->dbse); } @@ -102,7 +102,9 @@ void dbse_global_init(struct ctx_motapp *motapp) } if (motapp->cam_list[0]->conf->database_type != "") { - if (dbse_global_edits(motapp->cam_list) == -1) return; + if (dbse_global_edits(motapp->cam_list) == -1) { + return; + } MOTION_LOG(DBG, TYPE_DB, NO_ERRNO,_("Initializing database")); /* Initialize all the database items */ diff --git a/src/draw.cpp b/src/draw.cpp index da55080c..8f19c8ca 100644 --- a/src/draw.cpp +++ b/src/draw.cpp @@ -1087,13 +1087,17 @@ static int draw_textn(unsigned char *image, int startx, int starty, int width int pos, line_offset, next_char_offs; unsigned char *image_ptr, *char_ptr; - if (startx > width / 2) + if (startx > width / 2) { startx -= len * (6 * factor); + } - if (startx + len * 6 * factor >= width) + if (startx + len * 6 * factor >= width) { len = (width-startx-1)/(6*factor); + } - if ((startx < 1) || (starty < 1) || (len < 1)) return 0; + if ((startx < 1) || (starty < 1) || (len < 1)) { + return 0; + } line_offset = width - (7 * factor); next_char_offs = (width * 8 * factor) - (6 * factor); @@ -1147,24 +1151,32 @@ int draw_text(unsigned char *image, int width, int height, int startx, int start begin = end = text; txtlen = 0; while ((end = strstr(end, NEWLINE))) { - if ((end - begin)>txtlen) txtlen = (end - begin); + if ((end - begin)>txtlen) { + txtlen = (end - begin); + } num_nl++; end += sizeof(NEWLINE)-1; begin = end; } - if (txtlen == 0) txtlen = strlen(text); + if (txtlen == 0) { + txtlen = strlen(text); + } /* Adjust the factor if it is out of bounds * txtlen at this point is the approx length of longest line */ - if ((txtlen * 7 * factor) > width){ + if ((txtlen * 7 * factor) > width) { factor = (width / (txtlen * 7)); - if (factor <= 0) factor = 1; + if (factor <= 0) { + factor = 1; + } } - if (((num_nl+1) * 8 * factor) > height){ + if (((num_nl+1) * 8 * factor) > height) { factor = (height / ((num_nl+1) * 8)); - if (factor <= 0) factor = 1; + if (factor <= 0) { + factor = 1; + } } line_space = factor * 9; @@ -1216,18 +1228,24 @@ void draw_init_scale(struct ctx_cam *cam) */ cam->text_scale = cam->conf->text_scale; - if (cam->text_scale <= 0) cam->text_scale = 1; + if (cam->text_scale <= 0) { + cam->text_scale = 1; + } if ((cam->text_scale * 10 * 2) > (cam->imgs.width / 4)) { cam->text_scale = (cam->imgs.width / (4 * 10 * 2)); - if (cam->text_scale <= 0) cam->text_scale = 1; + if (cam->text_scale <= 0) { + cam->text_scale = 1; + } MOTION_LOG(WRN, TYPE_ALL, NO_ERRNO ,_("Invalid text scale. Adjusted to %d"), cam->text_scale); } if ((cam->text_scale * 10 * 2) > (cam->imgs.height / 4)) { cam->text_scale = (cam->imgs.height / (4 * 10 * 2)); - if (cam->text_scale <= 0) cam->text_scale = 1; + if (cam->text_scale <= 0) { + cam->text_scale = 1; + } MOTION_LOG(WRN, TYPE_ALL, NO_ERRNO ,_("Invalid text scale. Adjusted to %d"), cam->text_scale); } @@ -1485,8 +1503,9 @@ void draw_smartmask(struct ctx_cam *cam, unsigned char *out) out_y = out; /* Set colour intensity for smartmask. */ for (i = 0; i < imgs->motionsize; i++) { - if (smartmask[i] == 0) + if (smartmask[i] == 0) { *out_y = 0; + } out_y++; } } @@ -1523,8 +1542,9 @@ void draw_fixed_mask(struct ctx_cam *cam, unsigned char *out) out_y = out; /* Set colour intensity for mask. */ for (i = 0; i < imgs->motionsize; i++) { - if (mask[i] == 0) + if (mask[i] == 0) { *out_y = 0; + } out_y++; } } @@ -1561,8 +1581,9 @@ void draw_largest_label(struct ctx_cam *cam, unsigned char *out) out_y = out; /* Set intensity for coloured label to have better visibility. */ for (i = 0; i < imgs->motionsize; i++) { - if (*labels++ & 32768) + if (*labels++ & 32768) { *out_y = 0; + } out_y++; } } diff --git a/src/event.cpp b/src/event.cpp index bfb8a0ef..90ec21c7 100644 --- a/src/event.cpp +++ b/src/event.cpp @@ -101,11 +101,13 @@ static void on_picture_save_command(struct ctx_cam *cam, motion_event evnt (void)img_data; (void)ts1; - if ((filetype & FTYPE_IMAGE_ANY) != 0 && (cam->conf->on_picture_save != "")) + if ((filetype & FTYPE_IMAGE_ANY) != 0 && (cam->conf->on_picture_save != "")) { util_exec_command(cam, cam->conf->on_picture_save.c_str(), fname, filetype); + } - if ((filetype & FTYPE_MPEG_ANY) != 0 && (cam->conf->on_movie_start != "")) + if ((filetype & FTYPE_MPEG_ANY) != 0 && (cam->conf->on_movie_start != "")) { util_exec_command(cam, cam->conf->on_movie_start.c_str(), fname, filetype); + } } static void on_motion_detected_command(struct ctx_cam *cam, motion_event evnt @@ -118,8 +120,9 @@ static void on_motion_detected_command(struct ctx_cam *cam, motion_event evnt (void)ftype; (void)ts1; - if (cam->conf->on_motion_detected != "") + if (cam->conf->on_motion_detected != "") { util_exec_command(cam, cam->conf->on_motion_detected.c_str(), NULL, 0); + } } static void event_sqlfirstmotion(struct ctx_cam *cam, motion_event evnt @@ -149,7 +152,7 @@ static void event_sqlnewfile(struct ctx_cam *cam, motion_event evnt (void)img_data; /* Only log the file types we want */ - if ((cam->conf->database_type == "") || (sqltype & cam->dbse->sql_mask) == 0){ + if ((cam->conf->database_type == "") || (sqltype & cam->dbse->sql_mask) == 0) { return; } else { dbse_newfile(cam, fname, sqltype, ts1); @@ -167,7 +170,7 @@ static void event_sqlfileclose(struct ctx_cam *cam, motion_event evnt (void)img_data; /* Only log the file types we want */ - if ((cam->conf->database_type == "") || (sqltype & cam->dbse->sql_mask) == 0){ + if ((cam->conf->database_type == "") || (sqltype & cam->dbse->sql_mask) == 0) { return; } else { dbse_fileclose(cam, fname, sqltype, ts1); @@ -186,8 +189,9 @@ static void on_area_command(struct ctx_cam *cam, motion_event evnt (void)ftype; (void)ts1; - if (cam->conf->on_area_detected != "") + if (cam->conf->on_area_detected != "") { util_exec_command(cam, cam->conf->on_area_detected.c_str(), NULL, 0); + } } static void on_event_start_command(struct ctx_cam *cam, motion_event evnt @@ -200,8 +204,9 @@ static void on_event_start_command(struct ctx_cam *cam, motion_event evnt (void)ftype; (void)ts1; - if (cam->conf->on_event_start != "") + if (cam->conf->on_event_start != "") { util_exec_command(cam, cam->conf->on_event_start.c_str(), NULL, 0); + } } static void on_event_end_command(struct ctx_cam *cam, motion_event evnt @@ -214,8 +219,9 @@ static void on_event_end_command(struct ctx_cam *cam, motion_event evnt (void)ftype; (void)ts1; - if (cam->conf->on_event_end != "") + if (cam->conf->on_event_end != "") { util_exec_command(cam, cam->conf->on_event_end.c_str(), NULL, 0); + } } static void event_stream_put(struct ctx_cam *cam, motion_event evnt @@ -241,9 +247,10 @@ static void event_vlp_putpipe(struct ctx_cam *cam, motion_event evnt (void)ts1; if (*(int *)ftype >= 0) { - if (vlp_putpipe(*(int *)ftype, img_data->image_norm, cam->imgs.size_norm) == -1) + if (vlp_putpipe(*(int *)ftype, img_data->image_norm, cam->imgs.size_norm) == -1) { MOTION_LOG(ERR, TYPE_EVENTS, SHOW_ERRNO ,_("Failed to put image into video pipe")); + } } } @@ -270,7 +277,7 @@ static void event_image_detect(struct ctx_cam *cam, motion_event evnt mystrftime(cam, filename, sizeof(filename), cam->conf->picture_filename.c_str(), ts1, NULL, 0); retcd = snprintf(fullfilename, PATH_MAX, "%s/%s.%s" , cam->conf->target_dir.c_str(), filename, imageext(cam)); - if ((retcd < 0) || (retcd >= PATH_MAX)){ + if ((retcd < 0) || (retcd >= PATH_MAX)) { MOTION_LOG(ERR, TYPE_EVENTS, NO_ERRNO ,_("Error creating image file name")); return; @@ -302,7 +309,7 @@ static void event_imagem_detect(struct ctx_cam *cam, motion_event evnt mystrftime(cam, filename, sizeof(filename), cam->conf->picture_filename.c_str(), ts1, NULL, 0); retcd = snprintf(fullfilename, PATH_MAX, "%s/%sm.%s" , cam->conf->target_dir.c_str(), filename, imageext(cam)); - if ((retcd < 0) || (retcd >= PATH_MAX)){ + if ((retcd < 0) || (retcd >= PATH_MAX)) { MOTION_LOG(ERR, TYPE_EVENTS, NO_ERRNO ,_("Error creating image motion file name")); return; @@ -313,7 +320,7 @@ static void event_imagem_detect(struct ctx_cam *cam, motion_event evnt mystrftime(cam, filename, sizeof(filename), cam->conf->picture_filename.c_str(), ts1, NULL, 0); retcd = snprintf(fullfilename, PATH_MAX, "%s/%sr.%s" , cam->conf->target_dir.c_str(), filename, imageext(cam)); - if ((retcd < 0) || (retcd >= PATH_MAX)){ + if ((retcd < 0) || (retcd >= PATH_MAX)) { MOTION_LOG(ERR, TYPE_EVENTS, NO_ERRNO ,_("Error creating image motion roi file name")); return; @@ -338,15 +345,21 @@ static void event_image_snapshot(struct ctx_cam *cam, motion_event evnt (void)ftype; offset = cam->conf->snapshot_filename.length() - 8; - if (offset < 0) offset = 1; + if (offset < 0) { + offset = 1; + } if (cam->conf->snapshot_filename.compare(offset, 8, "lastsnap") != 0) { mystrftime(cam, filepath, sizeof(filepath), cam->conf->snapshot_filename.c_str(), ts1, NULL, 0); retcd = snprintf(filename, PATH_MAX, "%s.%s", filepath, imageext(cam)); - if (retcd <0) MOTION_LOG(INF, TYPE_STREAM, NO_ERRNO, _("Error option")); + if (retcd <0) { + MOTION_LOG(INF, TYPE_STREAM, NO_ERRNO, _("Error option")); + } retcd =snprintf(fullfilename, PATH_MAX, "%s/%s", cam->conf->target_dir.c_str(), filename); - if (retcd <0) MOTION_LOG(INF, TYPE_STREAM, NO_ERRNO, _("Error option")); + if (retcd <0) { + MOTION_LOG(INF, TYPE_STREAM, NO_ERRNO, _("Error option")); + } pic_save_norm(cam, fullfilename, img_data->image_norm, FTYPE_IMAGE_SNAPSHOT); event(cam, EVENT_FILECREATE, NULL, fullfilename, (void *)FTYPE_IMAGE_SNAPSHOT, ts1); @@ -362,10 +375,14 @@ static void event_image_snapshot(struct ctx_cam *cam, motion_event evnt } else { mystrftime(cam, filepath, sizeof(filepath), cam->conf->snapshot_filename.c_str(), ts1, NULL, 0); retcd = snprintf(filename, PATH_MAX, "%s.%s", filepath, imageext(cam)); - if (retcd <0) MOTION_LOG(INF, TYPE_STREAM, NO_ERRNO, _("Error option")); + if (retcd <0) { + MOTION_LOG(INF, TYPE_STREAM, NO_ERRNO, _("Error option")); + } retcd = snprintf(fullfilename, PATH_MAX, "%s/%s", cam->conf->target_dir.c_str(), filename); - if (retcd <0) MOTION_LOG(INF, TYPE_STREAM, NO_ERRNO, _("Error option")); + if (retcd <0) { + MOTION_LOG(INF, TYPE_STREAM, NO_ERRNO, _("Error option")); + } remove(fullfilename); pic_save_norm(cam, fullfilename, img_data->image_norm, FTYPE_IMAGE_SNAPSHOT); @@ -397,7 +414,7 @@ static void event_image_preview(struct ctx_cam *cam, motion_event evnt , &cam->imgs.image_preview.imgts, NULL, 0); retcd = snprintf(previewname, PATH_MAX, "%s/%s.%s" , cam->conf->target_dir.c_str(), filename, imageext(cam)); - if ((retcd < 0) || (retcd >= PATH_MAX)){ + if ((retcd < 0) || (retcd >= PATH_MAX)) { MOTION_LOG(ERR, TYPE_EVENTS, NO_ERRNO ,_("Error creating preview file name")); return; @@ -425,8 +442,9 @@ static void event_camera_lost(struct ctx_cam *cam, motion_event evnt (void)ftype; (void)ts1; - if (cam->conf->on_camera_lost != "") + if (cam->conf->on_camera_lost != "") { util_exec_command(cam, cam->conf->on_camera_lost.c_str(), NULL, 0); + } } static void event_secondary_detect(struct ctx_cam *cam, motion_event evnt @@ -441,8 +459,9 @@ static void event_secondary_detect(struct ctx_cam *cam, motion_event evnt MOTION_LOG(NTC, TYPE_EVENTS, NO_ERRNO,_("Event secondary detect")); - if (cam->conf->on_secondary_detect != "") + if (cam->conf->on_secondary_detect != "") { util_exec_command(cam, cam->conf->on_secondary_detect.c_str(), NULL, 0); + } } static void event_camera_found(struct ctx_cam *cam, motion_event evnt @@ -455,8 +474,9 @@ static void event_camera_found(struct ctx_cam *cam, motion_event evnt (void)ftype; (void)ts1; - if (cam->conf->on_camera_found != "") + if (cam->conf->on_camera_found != "") { util_exec_command(cam, cam->conf->on_camera_found.c_str(), NULL, 0); + } } static void on_movie_end_command(struct ctx_cam *cam, motion_event evnt @@ -469,8 +489,9 @@ static void on_movie_end_command(struct ctx_cam *cam, motion_event evnt (void)img_data; (void)ts1; - if ((filetype & FTYPE_MPEG_ANY) && (cam->conf->on_movie_end != "")) + if ((filetype & FTYPE_MPEG_ANY) && (cam->conf->on_movie_end != "")) { util_exec_command(cam, cam->conf->on_movie_end.c_str(), fname, filetype); + } } static void event_extpipe_end(struct ctx_cam *cam, motion_event evnt @@ -510,7 +531,9 @@ static void event_create_extpipe(struct ctx_cam *cam, motion_event evnt mystrftime(cam, stamp, sizeof(stamp), cam->conf->movie_filename.c_str(), ts1, NULL, 0); retcd = snprintf(cam->extpipefilename, PATH_MAX - 4, "%s/%s" , cam->conf->target_dir.c_str(), stamp); - if (retcd <0) MOTION_LOG(INF, TYPE_STREAM, NO_ERRNO, _("Error option")); + if (retcd <0) { + MOTION_LOG(INF, TYPE_STREAM, NO_ERRNO, _("Error option")); + } if (access(cam->conf->target_dir.c_str(), W_OK)!= 0) { /* Permission denied */ @@ -522,8 +545,9 @@ static void event_create_extpipe(struct ctx_cam *cam, motion_event evnt } else if (errno == ENOENT) { MOTION_LOG(ERR, TYPE_EVENTS, SHOW_ERRNO ,_("path not found, trying to create it %s ..."), cam->conf->target_dir.c_str()); - if (mycreate_path(cam->extpipefilename) == -1) + if (mycreate_path(cam->extpipefilename) == -1) { return ; + } } else { MOTION_LOG(ERR, TYPE_EVENTS, SHOW_ERRNO @@ -533,14 +557,15 @@ static void event_create_extpipe(struct ctx_cam *cam, motion_event evnt } /* Always create any path specified as file name */ - if (mycreate_path(cam->extpipefilename) == -1) + if (mycreate_path(cam->extpipefilename) == -1) { return ; + } mystrftime(cam, stamp, sizeof(stamp), cam->conf->movie_extpipe.c_str() , ts1, cam->extpipefilename, 0); retcd = snprintf(cam->extpipecmdline, PATH_MAX, "%s", stamp); - if ((retcd < 0 ) || (retcd >= PATH_MAX)){ + if ((retcd < 0 ) || (retcd >= PATH_MAX)) { MOTION_LOG(ERR, TYPE_EVENTS, NO_ERRNO , _("Error specifying command line: %s"), cam->extpipecmdline); return; @@ -579,14 +604,16 @@ static void event_extpipe_put(struct ctx_cam *cam, motion_event evnt passthrough = mycheck_passthrough(cam); /* Check that is open */ if ((cam->extpipe_open) && (fileno(cam->extpipe) > 0)) { - if ((cam->imgs.size_high > 0) && (!passthrough)){ - if (!fwrite(img_data->image_high, cam->imgs.size_high, 1, cam->extpipe)) + if ((cam->imgs.size_high > 0) && (!passthrough)) { + if (!fwrite(img_data->image_high, cam->imgs.size_high, 1, cam->extpipe)) { MOTION_LOG(ERR, TYPE_EVENTS, SHOW_ERRNO ,_("Error writing in pipe , state error %d"), ferror(cam->extpipe)); + } } else { - if (!fwrite(img_data->image_norm, cam->imgs.size_norm, 1, cam->extpipe)) + if (!fwrite(img_data->image_norm, cam->imgs.size_norm, 1, cam->extpipe)) { MOTION_LOG(ERR, TYPE_EVENTS, SHOW_ERRNO ,_("Error writing in pipe , state error %d"), ferror(cam->extpipe)); + } } } else { MOTION_LOG(ERR, TYPE_EVENTS, NO_ERRNO @@ -611,7 +638,9 @@ static void event_new_video(struct ctx_cam *cam, motion_event evnt MOTION_LOG(INF, TYPE_EVENTS, NO_ERRNO, _("Source FPS %d"), cam->movie_fps); - if (cam->movie_fps < 2) cam->movie_fps = 2; + if (cam->movie_fps < 2) { + cam->movie_fps = 2; + } } @@ -626,11 +655,13 @@ static void event_movie_newfile(struct ctx_cam *cam, motion_event evnt (void)fname; (void)ftype; - if (!cam->conf->movie_output && !cam->conf->movie_output_motion) return; + if (!cam->conf->movie_output && !cam->conf->movie_output_motion) { + return; + } if (cam->conf->movie_output) { retcd = movie_init_norm(cam, ts1); - if (retcd < 0){ + if (retcd < 0) { MOTION_LOG(ERR, TYPE_EVENTS, NO_ERRNO ,_("Error opening ctx_cam for movie output.")); free(cam->movie_norm); @@ -642,7 +673,7 @@ static void event_movie_newfile(struct ctx_cam *cam, motion_event evnt if (cam->conf->movie_output_motion) { retcd = movie_init_motion(cam, ts1); - if (retcd < 0){ + if (retcd < 0) { MOTION_LOG(ERR, TYPE_EVENTS, NO_ERRNO ,_("Error creating motion file [%s]"), cam->movie_motion->filename); free(cam->movie_motion); @@ -664,7 +695,7 @@ static void event_movie_timelapse(struct ctx_cam *cam, motion_event evnt if (!cam->movie_timelapse) { retcd = movie_init_timelapse(cam, ts1); - if (retcd < 0){ + if (retcd < 0) { MOTION_LOG(ERR, TYPE_EVENTS, NO_ERRNO ,_("Error creating timelapse file [%s]"), cam->movie_timelapse->filename); free(cam->movie_timelapse); @@ -690,7 +721,7 @@ static void event_movie_put(struct ctx_cam *cam, motion_event evnt (void)ftype; if (cam->movie_norm) { - if (movie_put_image(cam->movie_norm, img_data, ts1) == -1){ + if (movie_put_image(cam->movie_norm, img_data, ts1) == -1) { MOTION_LOG(ERR, TYPE_EVENTS, NO_ERRNO, _("Error encoding image")); } } @@ -895,7 +926,8 @@ void event(struct ctx_cam *cam, motion_event evnt int i=-1; while (event_handlers[++i].handler) { - if (evnt == event_handlers[i].type) + if (evnt == event_handlers[i].type) { event_handlers[i].handler(cam, evnt, img_data, fname, ftype, ts1); + } } } diff --git a/src/exif.cpp b/src/exif.cpp index 3564a8e8..1cdc33bf 100644 --- a/src/exif.cpp +++ b/src/exif.cpp @@ -287,11 +287,13 @@ unsigned exif_prepare(unsigned char **exif, const struct ctx_cam *cam, put_uint16(writing.buf, ifd0_tagcount); writing.buf += 2; - if (description) + if (description) { put_stringentry(&writing, TIFF_TAG_IMAGE_DESCRIPTION, description, 1); + } - if (datetime) + if (datetime) { put_stringentry(&writing, TIFF_TAG_DATETIME, datetime, 1); + } if (ifd1_tagcount > 0) { /* Offset of IFD1 - TIFF header + IFD0 size. */ @@ -318,14 +320,17 @@ unsigned exif_prepare(unsigned char **exif, const struct ctx_cam *cam, memcpy(writing.buf + 2, exif_version_tag, 12); /* tag 0x9000 */ writing.buf += 14; - if (datetime) + if (datetime) { put_stringentry(&writing, EXIF_TAG_ORIGINAL_DATETIME, datetime, 1); + } - if (box) + if (box) { put_subjectarea(&writing, box); + } - if (subtime) + if (subtime) { put_stringentry(&writing, EXIF_TAG_ORIGINAL_DATETIME_SS, subtime, 0); + } put_uint32(writing.buf, 0); /* Next IFD = 0 (no next IFD) */ writing.buf += 4; diff --git a/src/jpegutils.cpp b/src/jpegutils.cpp index d53d7276..b682d70f 100644 --- a/src/jpegutils.cpp +++ b/src/jpegutils.cpp @@ -70,8 +70,9 @@ static void add_huff_table(j_decompress_ptr dinfo, JHUFF_TBL **htblptr, const UI /* Define a Huffman table */ int nsymbols, len; - if (*htblptr == NULL) + if (*htblptr == NULL) { *htblptr = jpeg_alloc_huff_table((j_common_ptr) dinfo); + } /* Copy the number-of-symbols-of-each-code-length counts. */ memcpy((*htblptr)->bits, bits, sizeof((*htblptr)->bits)); @@ -86,8 +87,9 @@ static void add_huff_table(j_decompress_ptr dinfo, JHUFF_TBL **htblptr, const UI for (len = 1; len <= 16; len++) nsymbols += bits[len]; - if (nsymbols < 1 || nsymbols > 256) + if (nsymbols < 1 || nsymbols > 256) { MOTION_LOG(ERR, TYPE_ALL, NO_ERRNO, _("%s: Given jpeg buffer was too small")); + } memcpy((*htblptr)->huffval, val, nsymbols * sizeof(UINT8)); } @@ -209,8 +211,9 @@ static boolean jpgutl_fill_input_buffer(j_decompress_ptr cinfo) static void jpgutl_skip_data(j_decompress_ptr cinfo, long num_bytes) { if (num_bytes > 0) { - if (num_bytes > (long) cinfo->src->bytes_in_buffer) + if (num_bytes > (long) cinfo->src->bytes_in_buffer) { num_bytes = (long) cinfo->src->bytes_in_buffer; + } cinfo->src->next_input_byte += (size_t) num_bytes; cinfo->src->bytes_in_buffer -= (size_t) num_bytes; } @@ -510,7 +513,9 @@ int jpgutl_decode_jpeg (unsigned char *jpeg_data_in, int jpeg_data_len, * only a partial image could be returned which would * trigger many false positive motion detections */ - if (jerr.warning_seen > 2) return -1; + if (jerr.warning_seen > 2) { + return -1; + } return 0; diff --git a/src/logger.cpp b/src/logger.cpp index 298e9dfa..64af252c 100644 --- a/src/logger.cpp +++ b/src/logger.cpp @@ -51,7 +51,9 @@ static int log_get_type(const char *type) void log_set_type(const char *new_logtype) { - if ( mystreq(new_logtype, log_type_str[log_type]) ) return; + if ( mystreq(new_logtype, log_type_str[log_type]) ) { + return; + } pthread_mutex_lock(&log_motapp->mutex_parms); log_type = log_get_type(new_logtype); @@ -62,7 +64,9 @@ void log_set_type(const char *new_logtype) void log_set_level(int new_loglevel) { - if (new_loglevel == log_level) return; + if (new_loglevel == log_level) { + return; + } pthread_mutex_lock(&log_motapp->mutex_parms); log_level = new_loglevel; @@ -77,11 +81,11 @@ static void log_set_mode(int mode) log_mode = mode; - if (mode == LOGMODE_SYSLOG && prev_mode != LOGMODE_SYSLOG){ + if (mode == LOGMODE_SYSLOG && prev_mode != LOGMODE_SYSLOG) { openlog("motion", LOG_PID, LOG_USER); } - if (mode != LOGMODE_SYSLOG && prev_mode == LOGMODE_SYSLOG){ + if (mode != LOGMODE_SYSLOG && prev_mode == LOGMODE_SYSLOG) { closelog(); } } @@ -95,7 +99,7 @@ static void log_set_logfile(const char *logfile_name) logfile = myfopen(logfile_name, "a"); /* If logfile was opened correctly */ - if (logfile){ + if (logfile) { log_set_mode(LOGMODE_FILE); } @@ -139,8 +143,12 @@ void motion_log(int level, int type, int errno_flag,int fncname, const char *fmt pthread_mutex_unlock(&log_motapp->mutex_parms); /*Exit if not our level or type */ - if (level > applvl) return; - if ((apptyp != TYPE_ALL) && (apptyp != type)) return; + if (level > applvl) { + return; + } + if ((apptyp != TYPE_ALL) && (apptyp != type)) { + return; + } threadnr = (unsigned long)pthread_getspecific(tls_key_threadnr); @@ -161,7 +169,7 @@ void motion_log(int level, int type, int errno_flag,int fncname, const char *fmt } /* Prepend the format specifier for the function name */ - if (fncname){ + if (fncname) { snprintf(usrfmt, sizeof (usrfmt),"%s: %s", "%s", fmt); } else { snprintf(usrfmt, sizeof (usrfmt),"%s",fmt); @@ -200,10 +208,10 @@ void motion_log(int level, int type, int errno_flag,int fncname, const char *fmt #endif } - if ((mystreq(buf,flood_msg)) && (flood_cnt <= 5000)){ + if ((mystreq(buf,flood_msg)) && (flood_cnt <= 5000)) { flood_cnt++; } else { - if (flood_cnt > 1){ + if (flood_cnt > 1) { if (log_mode == LOGMODE_FILE) { snprintf(flood_repeats,1024,"%s [%s] [%s] [%02d:%s] Above message repeats %d times" , str_time(), log_level_str[level], log_type_str[type] diff --git a/src/mmalcam.cpp b/src/mmalcam.cpp index 814ef10d..07bc1ea2 100644 --- a/src/mmalcam.cpp +++ b/src/mmalcam.cpp @@ -109,7 +109,7 @@ static void set_video_port_format(ctx_mmalcam_ptr mmalcam, MMAL_ES_FORMAT_T *for set_port_format(mmalcam, format); format->es->video.frame_rate.num = mmalcam->framerate; format->es->video.frame_rate.den = VIDEO_FRAME_RATE_DEN; - if (mmalcam->framerate > 30){ + if (mmalcam->framerate > 30) { /* The pi noir camera could not determine autoexpose at high frame rates */ MOTION_LOG(WRN, TYPE_VIDEO, NO_ERRNO, _("A high frame rate can cause problems with exposure of images")); MOTION_LOG(WRN, TYPE_VIDEO, NO_ERRNO, _("If autoexposure is not working, try a lower frame rate.")); @@ -411,8 +411,9 @@ int mmalcam_next(struct ctx_cam *cam, struct ctx_image_data *img_data) #ifdef HAVE_MMAL ctx_mmalcam_ptr mmalcam; - if ((!cam) || (!cam->mmalcam)) + if ((!cam) || (!cam->mmalcam)) { return -1; + } mmalcam = cam->mmalcam; @@ -440,9 +441,10 @@ int mmalcam_next(struct ctx_cam *cam, struct ctx_image_data *img_data) status = mmal_port_send_buffer(mmalcam->camera_capture_port, new_buffer); } - if (!new_buffer || status != MMAL_SUCCESS) + if (!new_buffer || status != MMAL_SUCCESS) { MOTION_LOG(ERR, TYPE_VIDEO, NO_ERRNO ,_("Unable to return a buffer to the camera video port")); + } } rotate_map(cam,img_data); diff --git a/src/motion_loop.cpp b/src/motion_loop.cpp index 9f2edd12..c5f30519 100644 --- a/src/motion_loop.cpp +++ b/src/motion_loop.cpp @@ -49,7 +49,7 @@ static void mlp_ring_resize(struct ctx_cam *cam, int new_size) if (cam->event_nr != cam->prev_event) { - if (new_size < cam->imgs.ring_size){ + if (new_size < cam->imgs.ring_size) { smallest = new_size; } else { smallest = cam->imgs.ring_size; @@ -61,14 +61,14 @@ static void mlp_ring_resize(struct ctx_cam *cam, int new_size) tmp =(struct ctx_image_data*) mymalloc(new_size * sizeof(struct ctx_image_data)); - if (smallest > 0){ + if (smallest > 0) { memcpy(tmp, cam->imgs.image_ring, sizeof(struct ctx_image_data) * smallest); } for(i = smallest; i < new_size; i++) { tmp[i].image_norm =(unsigned char*) mymalloc(cam->imgs.size_norm); memset(tmp[i].image_norm, 0x80, cam->imgs.size_norm); /* initialize to grey */ - if (cam->imgs.size_high > 0){ + if (cam->imgs.size_high > 0) { tmp[i].image_high =(unsigned char*) mymalloc(cam->imgs.size_high); memset(tmp[i].image_high, 0x80, cam->imgs.size_high); } @@ -91,11 +91,15 @@ static void mlp_ring_destroy(struct ctx_cam *cam) { int i; - if (cam->imgs.image_ring == NULL) return; + if (cam->imgs.image_ring == NULL) { + return; + } - for (i = 0; i < cam->imgs.ring_size; i++){ + for (i = 0; i < cam->imgs.ring_size; i++) { free(cam->imgs.image_ring[i].image_norm); - if (cam->imgs.size_high >0 ) free(cam->imgs.image_ring[i].image_high); + if (cam->imgs.size_high >0 ) { + free(cam->imgs.image_ring[i].image_high); + } } free(cam->imgs.image_ring); @@ -109,13 +113,13 @@ static void mlp_ring_process_debug(struct ctx_cam *cam) char tmp[32]; const char *t; - if (cam->imgs.image_ring[cam->imgs.ring_out].flags & IMAGE_TRIGGER){ + if (cam->imgs.image_ring[cam->imgs.ring_out].flags & IMAGE_TRIGGER) { t = "Trigger"; - } else if (cam->imgs.image_ring[cam->imgs.ring_out].flags & IMAGE_MOTION){ + } else if (cam->imgs.image_ring[cam->imgs.ring_out].flags & IMAGE_MOTION) { t = "Motion"; - } else if (cam->imgs.image_ring[cam->imgs.ring_out].flags & IMAGE_PRECAP){ + } else if (cam->imgs.image_ring[cam->imgs.ring_out].flags & IMAGE_PRECAP) { t = "Precap"; - } else if (cam->imgs.image_ring[cam->imgs.ring_out].flags & IMAGE_POSTCAP){ + } else if (cam->imgs.image_ring[cam->imgs.ring_out].flags & IMAGE_POSTCAP) { t = "Postcap"; } else { t = "Other"; @@ -136,20 +140,22 @@ static void mlp_ring_process(struct ctx_cam *cam) struct ctx_image_data *saved_current_image = cam->current_image; do { - if ((cam->imgs.image_ring[cam->imgs.ring_out].flags & (IMAGE_SAVE | IMAGE_SAVED)) != IMAGE_SAVE){ + if ((cam->imgs.image_ring[cam->imgs.ring_out].flags & (IMAGE_SAVE | IMAGE_SAVED)) != IMAGE_SAVE) { break; } cam->current_image = &cam->imgs.image_ring[cam->imgs.ring_out]; if (cam->imgs.image_ring[cam->imgs.ring_out].shot < cam->conf->framerate) { - if (cam->motapp->log_level >= DBG) mlp_ring_process_debug(cam); + if (cam->motapp->log_level >= DBG) { + mlp_ring_process_debug(cam); + } event(cam, EVENT_IMAGE_DETECTED, &cam->imgs.image_ring[cam->imgs.ring_out], NULL, NULL, &cam->imgs.image_ring[cam->imgs.ring_out].imgts); - if (cam->movie_last_shot >= 0){ + if (cam->movie_last_shot >= 0) { cam->movie_last_shot = cam->imgs.image_ring[cam->imgs.ring_out].shot; } } @@ -196,7 +202,7 @@ static void mlp_detected_trigger(struct ctx_cam *cam, struct ctx_image_data *img MOTION_LOG(NTC, TYPE_ALL, NO_ERRNO, _("Motion detected - starting event %d"), cam->event_nr); - if (cam->new_img & (NEWIMG_FIRST | NEWIMG_BEST | NEWIMG_CENTER)){ + if (cam->new_img & (NEWIMG_FIRST | NEWIMG_BEST | NEWIMG_CENTER)) { pic_save_preview(cam, img); } @@ -247,10 +253,10 @@ static void mlp_detected(struct ctx_cam *cam, struct ctx_image_data *img) mlp_detected_trigger(cam, img); if (img->shot < conf->framerate) { - if (conf->stream_motion && !cam->motapp->setup_mode && img->shot != 1){ + if (conf->stream_motion && !cam->motapp->setup_mode && img->shot != 1) { event(cam, EVENT_STREAM, img, NULL, NULL, &img->imgts); } - if (conf->picture_output_motion != "off"){ + if (conf->picture_output_motion != "off") { event(cam, EVENT_IMAGEM_DETECTED, NULL, NULL, NULL, &img->imgts); } } @@ -262,7 +268,9 @@ static void mlp_detected(struct ctx_cam *cam, struct ctx_image_data *img) static void mlp_mask_privacy(struct ctx_cam *cam) { - if (cam->imgs.mask_privacy == NULL) return; + if (cam->imgs.mask_privacy == NULL) { + return; + } /* * This function uses long operations to process 4 (32 bit) or 8 (64 bit) @@ -280,11 +288,14 @@ static void mlp_mask_privacy(struct ctx_cam *cam) int indx_max; /* 1 if we are only doing norm, 2 if we are doing both norm and high */ indx_img = 1; - indx_max = 1; - if (cam->imgs.size_high > 0) indx_max = 2; + if (cam->imgs.size_high > 0) { + indx_max = 2; + } else { + indx_max = 1; + } increment = sizeof(unsigned long); - while (indx_img <= indx_max){ + while (indx_img <= indx_max) { if (indx_img == 1) { /* Normal Resolution */ index_y = cam->imgs.height * cam->imgs.width; @@ -328,7 +339,9 @@ static void mlp_mask_privacy(struct ctx_cam *cam) } while (--index_crcb >= 0) { - if (*(mask++) == 0x00) *image = 0x80; // Mask last remaining bytes. + if (*(mask++) == 0x00) { + *image = 0x80; // Mask last remaining bytes. + } image += 1; } @@ -423,9 +436,9 @@ int mlp_cam_next(struct ctx_cam *cam, struct ctx_image_data *img_data) } if (cam->camera_type == CAMERA_TYPE_NETCAM) { - if (cam->video_dev == -1) + if (cam->video_dev == -1) { return NETCAM_GENERAL_ERROR; - + } return netcam_next(cam, img_data); } @@ -478,12 +491,15 @@ static void mlp_init_firstimage(struct ctx_cam *cam) cam->current_image = &cam->imgs.image_ring[cam->imgs.ring_in]; if (cam->video_dev >= 0) { for (indx = 0; indx < 5; indx++) { - if (mlp_cam_next(cam, cam->current_image) == 0) break; + if (mlp_cam_next(cam, cam->current_image) == 0) { + break; + } SLEEP(2, 0); } if (indx >= 5) { - memset(cam->current_image->image_norm, 0x80, cam->imgs.size_norm); /* initialize to grey */ + memset(cam->current_image->image_norm, 0x80, cam->imgs.size_norm); + /* initialize to grey */ draw_text(cam->current_image->image_norm , cam->imgs.width, cam->imgs.height, 10, 20, "Error capturing first image", cam->text_scale); MOTION_LOG(ERR, TYPE_ALL, NO_ERRNO, _("Error capturing first image")); @@ -502,7 +518,7 @@ static int mlp_check_szimg(struct ctx_cam *cam) ,cam->imgs.width, cam->imgs.height); return -1; } - if ((cam->imgs.width < 64) || (cam->imgs.height < 64)){ + if ((cam->imgs.width < 64) || (cam->imgs.height < 64)) { MOTION_LOG(ERR, TYPE_ALL, NO_ERRNO ,_("Motion only supports width and height greater than or equal to 64 %dx%d") ,cam->imgs.width, cam->imgs.height); @@ -562,7 +578,7 @@ static void mlp_init_buffers(struct ctx_cam *cam) cam->imgs.image_preview.image_norm =(unsigned char*) mymalloc(cam->imgs.size_norm); cam->imgs.common_buffer =(unsigned char*) mymalloc(3 * cam->imgs.width * cam->imgs.height); cam->imgs.image_secondary =(unsigned char*) mymalloc(3 * cam->imgs.width * cam->imgs.height); - if (cam->imgs.size_high > 0){ + if (cam->imgs.size_high > 0) { cam->imgs.image_preview.image_high =(unsigned char*) mymalloc(cam->imgs.size_high); } @@ -584,7 +600,7 @@ static void mlp_init_values(struct ctx_cam *cam) cam->noise = cam->conf->noise_level; cam->threshold = cam->conf->threshold; - if (cam->conf->threshold_maximum > cam->conf->threshold ){ + if (cam->conf->threshold_maximum > cam->conf->threshold ) { cam->threshold_maximum = cam->conf->threshold_maximum; } else { cam->threshold_maximum = (cam->imgs.height * cam->imgs.width * 3) / 2; @@ -643,7 +659,7 @@ static void mlp_init_ref(struct ctx_cam *cam) memcpy(cam->imgs.image_vprvcy, cam->current_image->image_norm, cam->imgs.size_norm); - if (cam->conf->primary_method == 0){ + if (cam->conf->primary_method == 0) { alg_update_reference_frame(cam, RESET_REF_FRAME); } else if (cam->conf->primary_method == 1) { //alg_new_update_frame(cam); @@ -661,13 +677,19 @@ static int mlp_init(struct ctx_cam *cam) pthread_setspecific(tls_key_threadnr, (void *)((unsigned long)cam->threadnr)); - if (init_camera_type(cam) != 0 ) return -1; + if (init_camera_type(cam) != 0 ) { + return -1; + } mlp_init_values(cam); - if (mlp_init_cam_start(cam) != 0) return -1; + if (mlp_init_cam_start(cam) != 0) { + return -1; + } - if (mlp_check_szimg(cam) != 0) return -1; + if (mlp_check_szimg(cam) != 0) { + return -1; + } mlp_ring_resize(cam, 1); /* Create a initial precapture ring buffer with 1 frame */ @@ -717,7 +739,9 @@ void mlp_cleanup(struct ctx_cam *cam) algsec_deinit(cam); - if (cam->video_dev >= 0) mlp_cam_close(cam); + if (cam->video_dev >= 0) { + mlp_cam_close(cam); + } free(cam->imgs.image_motion.image_norm); cam->imgs.image_motion.image_norm = NULL; @@ -749,19 +773,29 @@ void mlp_cleanup(struct ctx_cam *cam) free(cam->imgs.smartmask_buffer); cam->imgs.smartmask_buffer = NULL; - if (cam->imgs.mask) free(cam->imgs.mask); + if (cam->imgs.mask) { + free(cam->imgs.mask); + } cam->imgs.mask = NULL; - if (cam->imgs.mask_privacy) free(cam->imgs.mask_privacy); + if (cam->imgs.mask_privacy) { + free(cam->imgs.mask_privacy); + } cam->imgs.mask_privacy = NULL; - if (cam->imgs.mask_privacy_uv) free(cam->imgs.mask_privacy_uv); + if (cam->imgs.mask_privacy_uv) { + free(cam->imgs.mask_privacy_uv); + } cam->imgs.mask_privacy_uv = NULL; - if (cam->imgs.mask_privacy_high) free(cam->imgs.mask_privacy_high); + if (cam->imgs.mask_privacy_high) { + free(cam->imgs.mask_privacy_high); + } cam->imgs.mask_privacy_high = NULL; - if (cam->imgs.mask_privacy_high_uv) free(cam->imgs.mask_privacy_high_uv); + if (cam->imgs.mask_privacy_high_uv) { + free(cam->imgs.mask_privacy_high_uv); + } cam->imgs.mask_privacy_high_uv = NULL; free(cam->imgs.common_buffer); @@ -773,7 +807,7 @@ void mlp_cleanup(struct ctx_cam *cam) free(cam->imgs.image_preview.image_norm); cam->imgs.image_preview.image_norm = NULL; - if (cam->imgs.size_high > 0){ + if (cam->imgs.size_high > 0) { free(cam->imgs.image_preview.image_high); cam->imgs.image_preview.image_high = NULL; } @@ -834,13 +868,15 @@ static void mlp_prepare(struct ctx_cam *cam) cam->frame_last_ts.tv_nsec = cam->frame_curr_ts.tv_nsec; clock_gettime(CLOCK_REALTIME, &cam->frame_curr_ts); - if (cam->conf->pre_capture < 0) + if (cam->conf->pre_capture < 0) { cam->conf->pre_capture = 0; + } frame_buffer_size = cam->conf->pre_capture + cam->conf->minimum_motion_frames; - if (cam->imgs.ring_size != frame_buffer_size) + if (cam->imgs.ring_size != frame_buffer_size) { mlp_ring_resize(cam, frame_buffer_size); + } if (cam->frame_last_ts.tv_sec != cam->frame_curr_ts.tv_sec) { cam->lastrate = cam->shots + 1; @@ -848,8 +884,9 @@ static void mlp_prepare(struct ctx_cam *cam) if (cam->conf->minimum_frame_time) { cam->minimum_frame_time_downcounter--; - if (cam->minimum_frame_time_downcounter == 0) + if (cam->minimum_frame_time_downcounter == 0) { cam->get_image = 1; + } } else { cam->get_image = 1; } @@ -857,8 +894,9 @@ static void mlp_prepare(struct ctx_cam *cam) cam->shots++; - if (cam->startup_frames > 0) + if (cam->startup_frames > 0) { cam->startup_frames--; + } } @@ -872,13 +910,15 @@ static void mlp_resetimages(struct ctx_cam *cam) } /* ring_buffer_in is pointing to current pos, update before put in a new image */ - if (++cam->imgs.ring_in >= cam->imgs.ring_size) + if (++cam->imgs.ring_in >= cam->imgs.ring_size) { cam->imgs.ring_in = 0; + } /* Check if we have filled the ring buffer, throw away last image */ if (cam->imgs.ring_in == cam->imgs.ring_out) { - if (++cam->imgs.ring_out >= cam->imgs.ring_size) + if (++cam->imgs.ring_out >= cam->imgs.ring_size) { cam->imgs.ring_out = 0; + } } cam->current_image = &cam->imgs.image_ring[cam->imgs.ring_in]; @@ -914,7 +954,9 @@ static int mlp_retry(struct ctx_cam *cam) return 1; } - if (mlp_check_szimg(cam) != 0) return 1; + if (mlp_check_szimg(cam) != 0) { + return 1; + } /* * If the netcam has different dimensions than in the config file @@ -940,7 +982,9 @@ static int mlp_retry(struct ctx_cam *cam) * and the mlp_cam_start ONLY re-populates the height/width so we can check the size here. */ size_high = (cam->imgs.width_high * cam->imgs.height_high * 3) / 2; - if (cam->imgs.size_high != size_high) return 1; + if (cam->imgs.size_high != size_high) { + return 1; + } } return 0; } @@ -953,10 +997,11 @@ static int mlp_capture(struct ctx_cam *cam) int vid_return_code = 0; /* Return code used when calling mlp_cam_next */ struct timespec ts1; - if (cam->video_dev >= 0) + if (cam->video_dev >= 0) { vid_return_code = mlp_cam_next(cam, cam->current_image); - else + } else { vid_return_code = 1; /* Non fatal error */ + } if (vid_return_code == 0) { cam->lost_connection = 0; @@ -986,7 +1031,7 @@ static int mlp_capture(struct ctx_cam *cam) return 1; } - if (cam->connectionlosttime == 0){ + if (cam->connectionlosttime == 0) { cam->connectionlosttime = cam->frame_curr_ts.tv_sec; } @@ -998,10 +1043,11 @@ static int mlp_capture(struct ctx_cam *cam) } else { cam->lost_connection = 1; - if (cam->video_dev >= 0) + if (cam->video_dev >= 0) { tmpin = "CONNECTION TO CAMERA LOST\\nSINCE %Y-%m-%d %T"; - else + } else { tmpin = "UNABLE TO OPEN VIDEO DEVICE\\nSINCE %Y-%m-%d %T"; + } ts1.tv_sec=cam->connectionlosttime; ts1.tv_nsec = 0; @@ -1039,7 +1085,7 @@ static void mlp_detection(struct ctx_cam *cam) } if ( !cam->pause ) { - if (cam->conf->primary_method == 0){ + if (cam->conf->primary_method == 0) { alg_diff(cam); alg_lightswitch(cam); alg_despeckle(cam); @@ -1061,12 +1107,12 @@ static void mlp_tuning(struct ctx_cam *cam) alg_noise_tune(cam, cam->imgs.image_vprvcy); } - if (cam->conf->threshold_tune){ + if (cam->conf->threshold_tune) { alg_threshold_tune(cam, cam->current_image->diffs, cam->detecting_motion); } if ((cam->current_image->diffs > cam->threshold) && - (cam->current_image->diffs < cam->threshold_maximum)){ + (cam->current_image->diffs < cam->threshold_maximum)) { alg_locate_center_size(&cam->imgs , cam->imgs.width , cam->imgs.height @@ -1090,35 +1136,38 @@ static void mlp_overlay(struct ctx_cam *cam) ((cam->conf->picture_output_motion != "off") || cam->conf->movie_output_motion || cam->motapp->setup_mode || - (cam->stream.motion.cnct_count > 0))) + (cam->stream.motion.cnct_count > 0))) { draw_smartmask(cam, cam->imgs.image_motion.image_norm); + } if (cam->imgs.largest_label && ((cam->conf->picture_output_motion != "off") || cam->conf->movie_output_motion || cam->motapp->setup_mode || - (cam->stream.motion.cnct_count > 0))) + (cam->stream.motion.cnct_count > 0))) { draw_largest_label(cam, cam->imgs.image_motion.image_norm); + } if (cam->imgs.mask && ((cam->conf->picture_output_motion != "off") || cam->conf->movie_output_motion || cam->motapp->setup_mode || - (cam->stream.motion.cnct_count > 0))) + (cam->stream.motion.cnct_count > 0))) { draw_fixed_mask(cam, cam->imgs.image_motion.image_norm); + } if (cam->conf->text_changes) { - if (!cam->pause) + if (!cam->pause) { sprintf(tmp, "%d", cam->current_image->diffs); - else + } else { sprintf(tmp, "-"); - + } draw_text(cam->current_image->image_norm, cam->imgs.width, cam->imgs.height, cam->imgs.width - 10, 10, tmp, cam->text_scale); } if (cam->motapp->setup_mode || (cam->stream.motion.cnct_count > 0)) { - if (cam->conf->primary_method == 0){ + if (cam->conf->primary_method == 0) { sprintf(tmp, "D:%5d L:%3d N:%3d", cam->current_image->diffs, cam->current_image->total_labels, cam->noise); draw_text(cam->imgs.image_motion.image_norm, cam->imgs.width, cam->imgs.height, @@ -1169,8 +1218,9 @@ static void mlp_actions_emulate(struct ctx_cam *cam) int indx; - if ( (cam->detecting_motion == FALSE) && (cam->movie_norm != NULL) ) + if ( (cam->detecting_motion == FALSE) && (cam->movie_norm != NULL) ) { movie_reset_start_time(cam->movie_norm, &cam->current_image->imgts); + } cam->detecting_motion = TRUE; if (cam->conf->post_capture > 0) { @@ -1179,7 +1229,7 @@ static void mlp_actions_emulate(struct ctx_cam *cam) cam->current_image->flags |= (IMAGE_TRIGGER | IMAGE_SAVE); /* Mark all images in image_ring to be saved */ - for (indx = 0; indx < cam->imgs.ring_size; indx++){ + for (indx = 0; indx < cam->imgs.ring_size; indx++) { cam->imgs.image_ring[indx].flags |= IMAGE_SAVE; } @@ -1193,8 +1243,10 @@ static void mlp_actions_motion(struct ctx_cam *cam) int pos = cam->imgs.ring_in; for (indx = 0; indx < cam->conf->minimum_motion_frames; indx++) { - if (cam->imgs.image_ring[pos].flags & IMAGE_MOTION) frame_count++; - if (pos == 0){ + if (cam->imgs.image_ring[pos].flags & IMAGE_MOTION) { + frame_count++; + } + if (pos == 0) { pos = cam->imgs.ring_size-1; } else { pos--; @@ -1205,13 +1257,13 @@ static void mlp_actions_motion(struct ctx_cam *cam) cam->current_image->flags |= (IMAGE_TRIGGER | IMAGE_SAVE); - if ( (cam->detecting_motion == FALSE) && (cam->movie_norm != NULL) ){ + if ( (cam->detecting_motion == FALSE) && (cam->movie_norm != NULL) ) { movie_reset_start_time(cam->movie_norm, &cam->current_image->imgts); } cam->detecting_motion = TRUE; cam->postcap = cam->conf->post_capture; - for (indx = 0; indx < cam->imgs.ring_size; indx++){ + for (indx = 0; indx < cam->imgs.ring_size; indx++) { cam->imgs.image_ring[indx].flags |= IMAGE_SAVE; } @@ -1249,8 +1301,8 @@ static void mlp_actions_event(struct ctx_cam *cam) mlp_track_center(cam); - if (cam->algsec_inuse){ - if (cam->algsec->isdetected){ + if (cam->algsec_inuse) { + if (cam->algsec->isdetected) { event(cam, EVENT_SECDETECT, NULL, NULL, NULL, &cam->current_image->imgts); } cam->algsec->isdetected = false; @@ -1284,15 +1336,19 @@ static void mlp_actions(struct ctx_cam *cam) cam->postcap--; } else { cam->current_image->flags |= IMAGE_PRECAP; - if ((cam->conf->event_gap == 0) && cam->detecting_motion) cam->event_stop = TRUE; + if ((cam->conf->event_gap == 0) && cam->detecting_motion) { + cam->event_stop = TRUE; + } cam->detecting_motion = FALSE; } - if (cam->current_image->flags & IMAGE_SAVE){ + if (cam->current_image->flags & IMAGE_SAVE) { cam->lasttime = cam->current_image->imgts.tv_sec; } - if (cam->detecting_motion) algsec_detect(cam); + if (cam->detecting_motion) { + algsec_detect(cam); + } mlp_areadetect(cam); @@ -1362,23 +1418,24 @@ static void mlp_timelapse(struct ctx_cam *cam) (cam->frame_curr_ts.tv_sec % 60 < cam->frame_last_ts.tv_sec % 60) && cam->shots == 0) { - if (cam->conf->timelapse_mode == "daily"){ - if (timestamp_tm.tm_hour == 0) + if (cam->conf->timelapse_mode == "daily") { + if (timestamp_tm.tm_hour == 0) { event(cam, EVENT_TIMELAPSEEND, NULL, NULL, NULL, &cam->current_image->imgts); - } else if (cam->conf->timelapse_mode == "hourly"){ + } + } else if (cam->conf->timelapse_mode == "hourly") { event(cam, EVENT_TIMELAPSEEND, NULL, NULL, NULL, &cam->current_image->imgts); - } else if (cam->conf->timelapse_mode == "weekly-sunday"){ - if (timestamp_tm.tm_wday == 0 && - timestamp_tm.tm_hour == 0) + } else if (cam->conf->timelapse_mode == "weekly-sunday") { + if (timestamp_tm.tm_wday == 0 && timestamp_tm.tm_hour == 0) { event(cam, EVENT_TIMELAPSEEND, NULL, NULL, NULL, &cam->current_image->imgts); - } else if (cam->conf->timelapse_mode == "weekly-monday"){ - if (timestamp_tm.tm_wday == 1 && - timestamp_tm.tm_hour == 0) + } + } else if (cam->conf->timelapse_mode == "weekly-monday") { + if (timestamp_tm.tm_wday == 1 && timestamp_tm.tm_hour == 0) { event(cam, EVENT_TIMELAPSEEND, NULL, NULL, NULL, &cam->current_image->imgts); - } else if (cam->conf->timelapse_mode == "monthly"){ - if (timestamp_tm.tm_mday == 1 && - timestamp_tm.tm_hour == 0) + } + } else if (cam->conf->timelapse_mode == "monthly") { + if (timestamp_tm.tm_mday == 1 && timestamp_tm.tm_hour == 0) { event(cam, EVENT_TIMELAPSEEND, NULL, NULL, NULL, &cam->current_image->imgts); + } } } @@ -1409,7 +1466,7 @@ static void mlp_loopback(struct ctx_cam *cam) } else { event(cam, EVENT_IMAGE, cam->current_image, NULL, &cam->pipe, &cam->current_image->imgts); - if (!cam->conf->stream_motion || cam->shots == 0){ + if (!cam->conf->stream_motion || cam->shots == 0) { event(cam, EVENT_STREAM, cam->current_image, NULL, NULL, &cam->current_image->imgts); } } @@ -1422,18 +1479,20 @@ static void mlp_parmsupdate(struct ctx_cam *cam) { /* Check for some config parameter changes but only every second */ - if (cam->shots != 0) return; + if (cam->shots != 0) { + return; + } if (cam->parms_changed ) { draw_init_scale(cam); /* Initialize and validate text_scale */ - if (cam->conf->picture_output == "on"){ + if (cam->conf->picture_output == "on") { cam->new_img = NEWIMG_ON; - } else if (cam->conf->picture_output == "first"){ + } else if (cam->conf->picture_output == "first") { cam->new_img = NEWIMG_FIRST; - } else if (cam->conf->picture_output == "best"){ + } else if (cam->conf->picture_output == "best") { cam->new_img = NEWIMG_BEST; - } else if (cam->conf->picture_output == "center"){ + } else if (cam->conf->picture_output == "center") { cam->new_img = NEWIMG_CENTER; } else { cam->new_img = NEWIMG_OFF; @@ -1441,19 +1500,19 @@ static void mlp_parmsupdate(struct ctx_cam *cam) if (cam->conf->locate_motion_mode == "on") { cam->locate_motion_mode = LOCATE_ON; - } else if (cam->conf->locate_motion_mode == "preview"){ + } else if (cam->conf->locate_motion_mode == "preview") { cam->locate_motion_mode = LOCATE_PREVIEW; } else { cam->locate_motion_mode = LOCATE_OFF; } - if (cam->conf->locate_motion_style == "box"){ + if (cam->conf->locate_motion_style == "box") { cam->locate_motion_style = LOCATE_BOX; - } else if (cam->conf->locate_motion_style == "redbox"){ + } else if (cam->conf->locate_motion_style == "redbox") { cam->locate_motion_style = LOCATE_REDBOX; - } else if (cam->conf->locate_motion_style == "cross"){ + } else if (cam->conf->locate_motion_style == "cross") { cam->locate_motion_style = LOCATE_CROSS; - } else if (cam->conf->locate_motion_style == "redcross"){ + } else if (cam->conf->locate_motion_style == "redcross") { cam->locate_motion_style = LOCATE_REDCROSS; } else { cam->locate_motion_style = LOCATE_BOX; @@ -1473,13 +1532,13 @@ static void mlp_parmsupdate(struct ctx_cam *cam) dbse_sqlmask_update(cam); cam->threshold = cam->conf->threshold; - if (cam->conf->threshold_maximum > cam->conf->threshold ){ + if (cam->conf->threshold_maximum > cam->conf->threshold ) { cam->threshold_maximum = cam->conf->threshold_maximum; } else { cam->threshold_maximum = (cam->imgs.height * cam->imgs.width * 3) / 2; } - if (!cam->conf->noise_tune){ + if (!cam->conf->noise_tune) { cam->noise = cam->conf->noise_level; } @@ -1502,7 +1561,7 @@ static void mlp_frametiming(struct ctx_cam *cam) int64_t avgtime; /* Shuffle the last wait times*/ - for (indx=0; indxframe_wait[indx]=cam->frame_wait[indx+1]; } @@ -1519,7 +1578,7 @@ static void mlp_frametiming(struct ctx_cam *cam) ((ts2.tv_nsec - cam->frame_curr_ts.tv_nsec)/1000); avgtime = 0; - for (indx=0; indxframe_wait[indx]; } avgtime = (avgtime/AVGCNT); @@ -1545,13 +1604,17 @@ void *motion_loop(void *arg) cam->watchdog = cam->conf->watchdog_tmo; cam->running_cam = TRUE; - if (mlp_init(cam) == 0){ + if (mlp_init(cam) == 0) { while (!cam->finish_cam || cam->event_stop) { mlp_prepare(cam); if (cam->get_image) { mlp_resetimages(cam); - if (mlp_retry(cam) == 1) break; - if (mlp_capture(cam) == 1) break; + if (mlp_retry(cam) == 1) { + break; + } + if (mlp_capture(cam) == 1) { + break; + } mlp_detection(cam); mlp_tuning(cam); mlp_overlay(cam); diff --git a/src/motionplus.cpp b/src/motionplus.cpp index 548bf86c..fe08203f 100644 --- a/src/motionplus.cpp +++ b/src/motionplus.cpp @@ -42,7 +42,7 @@ static void motion_signal_process(struct ctx_motapp *motapp) if (motapp->cam_list != NULL) { indx = 0; while (motapp->cam_list[indx] != NULL) { - if (motapp->cam_list[indx]->conf->snapshot_interval){ + if (motapp->cam_list[indx]->conf->snapshot_interval) { motapp->cam_list[indx]->snapshot = true; } indx++; @@ -167,7 +167,7 @@ static void motion_remove_pid(struct ctx_motapp *motapp) if ((motapp->daemon) && (motapp->pid_file != "") && (motapp->restart_all == false)) { - if (!unlink(motapp->pid_file.c_str())){ + if (!unlink(motapp->pid_file.c_str())) { MOTION_LOG(NTC, TYPE_ALL, NO_ERRNO, _("Removed process id file (pid file).")); } else{ MOTION_LOG(ERR, TYPE_ALL, SHOW_ERRNO, _("Error removing pid file")); @@ -222,7 +222,7 @@ static void motion_daemon(struct ctx_motapp *motapp) * Changing dir to root enables people to unmount a disk * without having to stop Motion */ - if (chdir("/")){ + if (chdir("/")) { MOTION_LOG(ERR, TYPE_ALL, SHOW_ERRNO, _("Could not change directory")); } @@ -253,7 +253,7 @@ static void motion_daemon(struct ctx_motapp *motapp) } /* Now it is safe to add the PID creation to the logs */ - if (pidf){ + if (pidf) { MOTION_LOG(NTC, TYPE_ALL, NO_ERRNO ,_("Created process id file %s. Process ID is %d") ,motapp->pid_file.c_str(), getpid()); @@ -287,7 +287,7 @@ static void motion_camera_ids(struct ctx_cam **cam_list) /* Set defaults */ indx = 0; while (cam_list[indx] != NULL){ - if (cam_list[indx]->conf->camera_id > 0){ + if (cam_list[indx]->conf->camera_id > 0) { cam_list[indx]->camera_id = cam_list[indx]->conf->camera_id; } else { cam_list[indx]->camera_id = indx; @@ -298,15 +298,19 @@ static void motion_camera_ids(struct ctx_cam **cam_list) invalid_ids = false; indx = 0; while (cam_list[indx] != NULL){ - if (cam_list[indx]->camera_id > 32000) invalid_ids = true; + if (cam_list[indx]->camera_id > 32000) { + invalid_ids = true; + } indx2 = indx + 1; while (cam_list[indx2] != NULL){ - if (cam_list[indx]->camera_id == cam_list[indx2]->camera_id) invalid_ids = true; + if (cam_list[indx]->camera_id == cam_list[indx2]->camera_id) { + invalid_ids = true; + } indx2++; } indx++; } - if (invalid_ids){ + if (invalid_ids) { MOTION_LOG(ERR, TYPE_ALL, NO_ERRNO ,_("Camara IDs are not unique or have values over 32,000. Falling back to thread numbers")); indx = 0; @@ -393,7 +397,7 @@ static void motion_startup(struct ctx_motapp *motapp, int daemonize, int argc, c } } - if (motapp->setup_mode){ + if (motapp->setup_mode) { MOTION_LOG(NTC, TYPE_ALL, NO_ERRNO,_("Motion running in setup mode.")); } @@ -469,7 +473,9 @@ static void motion_watchdog(struct ctx_motapp *motapp, int indx) * Best to just not get into a watchdog situation... */ - if (!motapp->cam_list[indx]->running_cam) return; + if (!motapp->cam_list[indx]->running_cam) { + return; + } motapp->cam_list[indx]->watchdog--; if (motapp->cam_list[indx]->watchdog == 0) { @@ -485,11 +491,11 @@ static void motion_watchdog(struct ctx_motapp *motapp, int indx) ,_("Thread %d - Watchdog timeout did NOT restart, killing it!") , motapp->cam_list[indx]->threadnr); if ((motapp->cam_list[indx]->camera_type == CAMERA_TYPE_NETCAM) && - (motapp->cam_list[indx]->netcam != NULL)){ + (motapp->cam_list[indx]->netcam != NULL)) { pthread_cancel(motapp->cam_list[indx]->netcam->thread_id); } if ((motapp->cam_list[indx]->camera_type == CAMERA_TYPE_NETCAM) && - (motapp->cam_list[indx]->netcam_high != NULL)){ + (motapp->cam_list[indx]->netcam_high != NULL)) { pthread_cancel(motapp->cam_list[indx]->netcam_high->thread_id); } pthread_cancel(motapp->cam_list[indx]->thread_id); @@ -501,7 +507,7 @@ static void motion_watchdog(struct ctx_motapp *motapp, int indx) , motapp->cam_list[indx]->threadnr); if ((motapp->cam_list[indx]->camera_type == CAMERA_TYPE_NETCAM) && - (motapp->cam_list[indx]->netcam != NULL)){ + (motapp->cam_list[indx]->netcam != NULL)) { if (!motapp->cam_list[indx]->netcam->handler_finished && pthread_kill(motapp->cam_list[indx]->netcam->thread_id, 0) == ESRCH) { motapp->cam_list[indx]->netcam->handler_finished = true; @@ -514,7 +520,7 @@ static void motion_watchdog(struct ctx_motapp *motapp, int indx) } } if ((motapp->cam_list[indx]->camera_type == CAMERA_TYPE_NETCAM) && - (motapp->cam_list[indx]->netcam_high != NULL)){ + (motapp->cam_list[indx]->netcam_high != NULL)) { if (!motapp->cam_list[indx]->netcam_high->handler_finished && pthread_kill(motapp->cam_list[indx]->netcam_high->thread_id, 0) == ESRCH) { motapp->cam_list[indx]->netcam_high->handler_finished = true; @@ -527,7 +533,7 @@ static void motion_watchdog(struct ctx_motapp *motapp, int indx) } } if (motapp->cam_list[indx]->running_cam && - pthread_kill(motapp->cam_list[indx]->thread_id, 0) == ESRCH){ + pthread_kill(motapp->cam_list[indx]->thread_id, 0) == ESRCH) { MOTION_LOG(DBG, TYPE_ALL, NO_ERRNO ,_("Thread %d - Cleaning thread.") , motapp->cam_list[indx]->threadnr); @@ -559,7 +565,7 @@ static int motion_check_threadcount(struct ctx_motapp *motapp) thrdcnt = 0; for (indx = (motapp->cam_list[1] != NULL ? 1 : 0); motapp->cam_list[indx]; indx++) { - if (motapp->cam_list[indx]->running_cam || motapp->cam_list[indx]->restart_cam){ + if (motapp->cam_list[indx]->running_cam || motapp->cam_list[indx]->restart_cam) { thrdcnt++; } } diff --git a/src/movie.cpp b/src/movie.cpp index 578ced48..705048e9 100644 --- a/src/movie.cpp +++ b/src/movie.cpp @@ -59,10 +59,11 @@ static void movie_encode_nal(struct ctx_movie *movie) movie_free_nal(movie); movie->nal_info_len = movie->pkt.size; movie->nal_info =(char*) malloc(movie->nal_info_len); - if (movie->nal_info) + if (movie->nal_info) { memcpy(movie->nal_info, &movie->pkt.data[0], movie->nal_info_len); - else + } else { movie->nal_info_len = 0; + } } else if (movie->nal_info) { int old_size = movie->pkt.size; av_grow_packet(&movie->pkt, movie->nal_info_len); @@ -76,8 +77,7 @@ static int movie_timelapse_exists(const char *fname) { FILE *file; file = fopen(fname, "r"); - if (file) - { + if (file) { fclose(file); return 1; } @@ -89,7 +89,9 @@ static int movie_timelapse_append(struct ctx_movie *movie, AVPacket pkt) FILE *file; file = fopen(movie->filename, "a"); - if (!file) return -1; + if (!file) { + return -1; + } fwrite(pkt.data,1,pkt.size,file); @@ -101,17 +103,17 @@ static int movie_timelapse_append(struct ctx_movie *movie, AVPacket pkt) static void movie_free_context(struct ctx_movie *movie) { - if (movie->picture != NULL){ + if (movie->picture != NULL) { myframe_free(movie->picture); movie->picture = NULL; } - if (movie->ctx_codec != NULL){ + if (movie->ctx_codec != NULL) { myavcodec_close(movie->ctx_codec); movie->ctx_codec = NULL; } - if (movie->oc != NULL){ + if (movie->oc != NULL) { avformat_free_context(movie->oc); movie->oc = NULL; } @@ -140,7 +142,7 @@ static int movie_get_oformat(struct ctx_movie *movie) codec_name[codec_name_len] = 0; retcd = snprintf(basename,PATH_MAX,"%s",movie->filename); - if ((retcd < 0) || (retcd >= PATH_MAX)){ + if ((retcd < 0) || (retcd >= PATH_MAX)) { MOTION_LOG(ERR, TYPE_ENCODER, NO_ERRNO ,_("Error setting base file name")); movie_free_context(movie); @@ -148,12 +150,14 @@ static int movie_get_oformat(struct ctx_movie *movie) return -1; } - if (movie->tlapse == TIMELAPSE_APPEND){ + if (movie->tlapse == TIMELAPSE_APPEND) { movie->oc->oformat = av_guess_format ("mpeg2video", NULL, NULL); - if (movie->oc->oformat) movie->oc->oformat->video_codec = MY_CODEC_ID_MPEG2VIDEO; + if (movie->oc->oformat) { + movie->oc->oformat->video_codec = MY_CODEC_ID_MPEG2VIDEO; + } retcd = snprintf(movie->filename,PATH_MAX,"%s.mpg",basename); if ((!movie->oc->oformat) || - (retcd < 0) || (retcd >= PATH_MAX)){ + (retcd < 0) || (retcd >= PATH_MAX)) { MOTION_LOG(ERR, TYPE_ENCODER, NO_ERRNO ,_("Error setting timelapse append for codec %s"), codec_name); movie_free_context(movie); @@ -167,41 +171,53 @@ static int movie_get_oformat(struct ctx_movie *movie) if (mystreq(codec_name, "flv")) { movie->oc->oformat = av_guess_format("flv", NULL, NULL); retcd = snprintf(movie->filename,PATH_MAX,"%s.flv",basename); - if (movie->oc->oformat) movie->oc->oformat->video_codec = MY_CODEC_ID_FLV1; + if (movie->oc->oformat) { + movie->oc->oformat->video_codec = MY_CODEC_ID_FLV1; + } } if (mystreq(codec_name, "ogg")) { movie->oc->oformat = av_guess_format("ogg", NULL, NULL); retcd = snprintf(movie->filename,PATH_MAX,"%s.ogg",basename); - if (movie->oc->oformat) movie->oc->oformat->video_codec = MY_CODEC_ID_THEORA; + if (movie->oc->oformat) { + movie->oc->oformat->video_codec = MY_CODEC_ID_THEORA; + } } if (mystreq(codec_name, "vp8")) { movie->oc->oformat = av_guess_format("webm", NULL, NULL); retcd = snprintf(movie->filename,PATH_MAX,"%s.webm",basename); - if (movie->oc->oformat) movie->oc->oformat->video_codec = MY_CODEC_ID_VP8; + if (movie->oc->oformat) { + movie->oc->oformat->video_codec = MY_CODEC_ID_VP8; + } } if (mystreq(codec_name, "mp4")) { movie->oc->oformat = av_guess_format("mp4", NULL, NULL); retcd = snprintf(movie->filename,PATH_MAX,"%s.mp4",basename); - if (movie->oc->oformat) movie->oc->oformat->video_codec = MY_CODEC_ID_H264; + if (movie->oc->oformat) { + movie->oc->oformat->video_codec = MY_CODEC_ID_H264; + } } if (mystreq(codec_name, "mkv")) { movie->oc->oformat = av_guess_format("matroska", NULL, NULL); retcd = snprintf(movie->filename,PATH_MAX,"%s.mkv",basename); - if (movie->oc->oformat) movie->oc->oformat->video_codec = MY_CODEC_ID_H264; + if (movie->oc->oformat) { + movie->oc->oformat->video_codec = MY_CODEC_ID_H264; + } } if (mystreq(codec_name, "hevc")) { movie->oc->oformat = av_guess_format("mp4", NULL, NULL); retcd = snprintf(movie->filename,PATH_MAX,"%s.mp4",basename); - if (movie->oc->oformat) movie->oc->oformat->video_codec = MY_CODEC_ID_HEVC; + if (movie->oc->oformat) { + movie->oc->oformat->video_codec = MY_CODEC_ID_HEVC; + } } //Check for valid results - if ((retcd < 0) || (retcd >= PATH_MAX)){ + if ((retcd < 0) || (retcd >= PATH_MAX)) { MOTION_LOG(ERR, TYPE_ENCODER, NO_ERRNO ,_("Error setting file name")); movie_free_context(movie); @@ -237,19 +253,19 @@ static int movie_encode_video(struct ctx_movie *movie) char errstr[128]; retcd = avcodec_send_frame(movie->ctx_codec, movie->picture); - if (retcd < 0 ){ + if (retcd < 0 ) { av_strerror(retcd, errstr, sizeof(errstr)); MOTION_LOG(ERR, TYPE_ENCODER, NO_ERRNO ,_("Error sending frame for encoding:%s"),errstr); return -1; } retcd = avcodec_receive_packet(movie->ctx_codec, &movie->pkt); - if (retcd == AVERROR(EAGAIN)){ + if (retcd == AVERROR(EAGAIN)) { //Buffered packet. Throw special return code mypacket_unref(movie->pkt); return -2; } - if (retcd < 0 ){ + if (retcd < 0 ) { av_strerror(retcd, errstr, sizeof(errstr)); MOTION_LOG(ERR, TYPE_ENCODER, NO_ERRNO ,_("Error receiving encoded packet video:%s"),errstr); @@ -257,7 +273,7 @@ static int movie_encode_video(struct ctx_movie *movie) return -1; } - if (movie->preferred_codec == USER_CODEC_V4L2M2M){ + if (movie->preferred_codec == USER_CODEC_V4L2M2M) { movie_encode_nal(movie); } @@ -270,20 +286,20 @@ static int movie_encode_video(struct ctx_movie *movie) int got_packet_ptr; retcd = avcodec_encode_video2(movie->ctx_codec, &movie->pkt, movie->picture, &got_packet_ptr); - if (retcd < 0 ){ + if (retcd < 0 ) { av_strerror(retcd, errstr, sizeof(errstr)); MOTION_LOG(ERR, TYPE_ENCODER, NO_ERRNO, _("Error encoding video:%s"),errstr); //Packet is freed upon failure of encoding return -1; } - if (got_packet_ptr == 0){ + if (got_packet_ptr == 0) { //Buffered packet. Throw special return code mypacket_unref(movie->pkt); return -2; } /* This kills compiler warnings. Nal setting is only for recent movie versions*/ - if (movie->preferred_codec == USER_CODEC_V4L2M2M){ + if (movie->preferred_codec == USER_CODEC_V4L2M2M) { movie_encode_nal(movie); } @@ -299,12 +315,12 @@ static int movie_encode_video(struct ctx_movie *movie) video_outbuf =(uint8_t *) mymalloc(video_outbuf_size); retcd = avcodec_encode_video(movie->strm_video->codec, video_outbuf, video_outbuf_size, movie->picture); - if (retcd < 0 ){ + if (retcd < 0 ) { MOTION_LOG(ERR, TYPE_ENCODER, NO_ERRNO, _("Error encoding video")); mypacket_unref(movie->pkt); return -1; } - if (retcd == 0 ){ + if (retcd == 0 ) { // No bytes encoded => buffered=>special handling mypacket_unref(movie->pkt); return -2; @@ -314,8 +330,9 @@ static int movie_encode_video(struct ctx_movie *movie) movie->pkt.size = retcd; movie->pkt.data = video_outbuf; - if (movie->picture->key_frame == 1) - movie->pkt.flags |= AV_PKT_FLAG_KEY; + if (movie->picture->key_frame == 1) { + movie->pkt.flags |= AV_PKT_FLAG_KEY; + } movie->pkt.pts = movie->picture->pts; movie->pkt.dts = movie->pkt.pts; @@ -323,7 +340,7 @@ static int movie_encode_video(struct ctx_movie *movie) free(video_outbuf); /* This kills compiler warnings. Nal setting is only for recent movie versions*/ - if (movie->preferred_codec == USER_CODEC_V4L2M2M){ + if (movie->preferred_codec == USER_CODEC_V4L2M2M) { movie_encode_nal(movie); } @@ -343,7 +360,7 @@ static int movie_set_pts(struct ctx_movie *movie, const struct timespec *ts1) movie->picture->pts = movie->last_pts; } else { pts_interval = ((1000000L * (ts1->tv_sec - movie->start_time.tv_sec)) + (ts1->tv_nsec/1000) - (movie->start_time.tv_nsec/1000)); - if (pts_interval < 0){ + if (pts_interval < 0) { /* This can occur when we have pre-capture frames. Reset start time of video. */ movie_reset_start_time(movie, ts1); pts_interval = 0; @@ -354,16 +371,16 @@ static int movie_set_pts(struct ctx_movie *movie, const struct timespec *ts1) } else movie->picture->pts = av_rescale_q(pts_interval,(AVRational){1, 1000000L},movie->strm_video->time_base) + movie->base_pts; - if (movie->test_mode == TRUE){ + if (movie->test_mode == TRUE) { MOTION_LOG(INF, TYPE_ENCODER, NO_ERRNO ,_("PTS %" PRId64 " Base PTS %" PRId64 " ms interval %" PRId64 " timebase %d-%d") ,movie->picture->pts,movie->base_pts,pts_interval ,movie->strm_video->time_base.num,movie->strm_video->time_base.den); } - if (movie->picture->pts <= movie->last_pts){ + if (movie->picture->pts <= movie->last_pts) { //We have a problem with our motion loop timing and sending frames or the rounding into the PTS. - if (movie->test_mode == TRUE){ + if (movie->test_mode == TRUE) { MOTION_LOG(INF, TYPE_ENCODER, NO_ERRNO, _("BAD TIMING!! Frame skipped.")); } return -1; @@ -377,11 +394,14 @@ static int movie_set_quality(struct ctx_movie *movie) { movie->opts = 0; - if (movie->quality > 100) movie->quality = 100; + if (movie->quality > 100) { + movie->quality = 100; + } if (movie->ctx_codec->codec_id == MY_CODEC_ID_H264 || - movie->ctx_codec->codec_id == MY_CODEC_ID_HEVC){ - if (movie->quality <= 0) + movie->ctx_codec->codec_id == MY_CODEC_ID_HEVC) { + if (movie->quality <= 0) { movie->quality = 45; // default to 45% quality + } /* This next if statement needs validation. Are mpeg4omx * and v4l2m2m even MY_CODEC_ID_H264 or MY_CODEC_ID_HEVC @@ -394,8 +414,10 @@ static int movie_set_quality(struct ctx_movie *movie) // bit_rate = movie->width * movie->height * movie->fps * quality_factor movie->quality = (int)(((int64_t)movie->width * movie->height * movie->fps * movie->quality) >> 7); // Clip bit rate to min - if (movie->quality < 4000) // magic number + if (movie->quality < 4000) { + // magic number movie->quality = 4000; + } movie->ctx_codec->profile = FF_PROFILE_H264_HIGH; movie->ctx_codec->bit_rate = movie->quality; av_dict_set(&movie->opts, "preset", "ultrafast", 0); @@ -418,7 +440,7 @@ static int movie_set_quality(struct ctx_movie *movie) } } else { /* The selection of 8000 is a subjective number based upon viewing output files */ - if (movie->quality > 0){ + if (movie->quality > 0) { movie->quality =(int)(((100-movie->quality)*(100-movie->quality)*(100-movie->quality) * 8000) / 1000000) + 1; movie->ctx_codec->flags |= MY_CODEC_FLAG_QSCALE; movie->ctx_codec->global_quality=movie->quality; @@ -460,8 +482,9 @@ static const char *movie_codec_is_blacklisted(const char *codec_name) i_mx = (size_t)(sizeof(blacklisted_codec)/sizeof(blacklisted_codec[0])); for (i = 0; i < i_mx; i++) { - if (mystreq(codec_name, blacklisted_codec[i].codec_name)) + if (mystreq(codec_name, blacklisted_codec[i].codec_name)) { return blacklisted_codec[i].reason; + } } return NULL; } @@ -488,8 +511,9 @@ static int movie_set_codec_preferred(struct ctx_movie *movie) } } } - if (!movie->codec) + if (!movie->codec) { movie->codec = avcodec_find_encoder(movie->oc->oformat->video_codec); + } if (!movie->codec) { MOTION_LOG(ERR, TYPE_ENCODER, NO_ERRNO ,_("Codec %s not found"), movie->codec_name); @@ -497,18 +521,19 @@ static int movie_set_codec_preferred(struct ctx_movie *movie) return -1; } - if (mystreq(movie->codec->name, "h264_v4l2m2m")){ + if (mystreq(movie->codec->name, "h264_v4l2m2m")) { movie->preferred_codec = USER_CODEC_V4L2M2M; - } else if (mystreq(movie->codec->name, "h264_omx")){ + } else if (mystreq(movie->codec->name, "h264_omx")) { movie->preferred_codec = USER_CODEC_H264OMX; - } else if (mystreq(movie->codec->name, "mpeg4_omx")){ + } else if (mystreq(movie->codec->name, "mpeg4_omx")) { movie->preferred_codec = USER_CODEC_MPEG4OMX; } else { movie->preferred_codec = USER_CODEC_DEFAULT; } - if (movie->codec_name[codec_name_len]) + if (movie->codec_name[codec_name_len]) { MOTION_LOG(NTC, TYPE_ENCODER, NO_ERRNO,_("Using codec %s"), movie->codec->name); + } return 0; @@ -522,7 +547,9 @@ static int movie_set_codec(struct ctx_movie *movie) int chkrate; retcd = movie_set_codec_preferred(movie); - if (retcd != 0) return retcd; + if (retcd != 0) { + return retcd; + } #if (MYFFVER >= 57041) //If we provide the codec to this, it results in a memory leak. ffmpeg ticket: 5714 @@ -552,9 +579,9 @@ static int movie_set_codec(struct ctx_movie *movie) if (movie->tlapse != TIMELAPSE_NONE) { movie->ctx_codec->gop_size = 1; } else { - if (movie->fps <= 5){ + if (movie->fps <= 5) { movie->ctx_codec->gop_size = 1; - } else if (movie->fps > 30){ + } else if (movie->fps > 30) { movie->ctx_codec->gop_size = 15; } else { movie->ctx_codec->gop_size = (movie->fps / 2); @@ -566,7 +593,7 @@ static int movie_set_codec(struct ctx_movie *movie) ** a very poor quality playback. We can set the FPS to a higher number and ** then let the PTS display the frames correctly. */ - if ((movie->tlapse == TIMELAPSE_NONE) && (movie->fps <= 5)){ + if ((movie->tlapse == TIMELAPSE_NONE) && (movie->fps <= 5)) { if (mystreq(movie->codec_name, "flv") || mystreq(movie->codec_name, "mp4") || mystreq(movie->codec_name, "hevc")) { @@ -582,13 +609,13 @@ static int movie_set_codec(struct ctx_movie *movie) movie->ctx_codec->height = movie->height; movie->ctx_codec->time_base.num = 1; movie->ctx_codec->time_base.den = movie->fps; - if (movie->preferred_codec == USER_CODEC_V4L2M2M){ + if (movie->preferred_codec == USER_CODEC_V4L2M2M) { movie->ctx_codec->pix_fmt = AV_PIX_FMT_NV21; } else { movie->ctx_codec->pix_fmt = MY_PIX_FMT_YUV420P; } movie->ctx_codec->max_b_frames = 0; - if (mystreq(movie->codec_name, "ffv1")){ + if (mystreq(movie->codec_name, "ffv1")) { movie->ctx_codec->strict_std_compliance = -2; movie->ctx_codec->level = 3; } @@ -604,7 +631,7 @@ static int movie_set_codec(struct ctx_movie *movie) } retcd = movie_set_quality(movie); - if (retcd < 0){ + if (retcd < 0) { MOTION_LOG(ERR, TYPE_ENCODER, NO_ERRNO, _("Unable to set quality")); return -1; } @@ -625,7 +652,7 @@ static int movie_set_codec(struct ctx_movie *movie) retcd = avcodec_open2(movie->ctx_codec, movie->codec, &movie->opts); chkrate++; } - if (retcd < 0){ + if (retcd < 0) { av_strerror(retcd, errstr, sizeof(errstr)); MOTION_LOG(ERR, TYPE_ENCODER, NO_ERRNO, _("Could not open codec %s"),errstr); av_dict_free(&movie->opts); @@ -669,23 +696,28 @@ static int movie_alloc_video_buffer(AVFrame *frame, int align) int ret, i, padded_height; int plane_padding = FFMAX(16 + 16/*STRIDE_ALIGN*/, align); - if (!desc) + if (!desc) { return AVERROR(EINVAL); + } - if ((ret = av_image_check_size(frame->width, frame->height, 0, NULL)) < 0) + if ((ret = av_image_check_size(frame->width, frame->height, 0, NULL)) < 0) { return ret; + } if (!frame->linesize[0]) { - if (align <= 0) + if (align <= 0) { align = 32; /* STRIDE_ALIGN. Should be av_cpu_max_align() */ + } for(i=1; i<=align; i+=i) { ret = av_image_fill_linesizes(frame->linesize,(enum AVPixelFormat) frame->format, FFALIGN(frame->width, i)); - if (ret < 0) + if (ret < 0) { return ret; - if (!(frame->linesize[0] & (align-1))) + } + if (!(frame->linesize[0] & (align-1))) { break; + } } for (i = 0; i < 4 && frame->linesize[i]; i++) @@ -693,9 +725,14 @@ static int movie_alloc_video_buffer(AVFrame *frame, int align) } padded_height = FFALIGN(frame->height, 32); - if ((ret = av_image_fill_pointers(frame->data,(enum AVPixelFormat) frame->format, padded_height, - NULL, frame->linesize)) < 0) + ret = av_image_fill_pointers(frame->data + ,(enum AVPixelFormat) frame->format + , padded_height + , NULL + , frame->linesize); + if (ret < 0) { return ret; + } frame->buf[0] = av_buffer_alloc(ret + 4*plane_padding); if (!frame->buf[0]) { @@ -734,8 +771,9 @@ static int movie_set_picture(struct ctx_movie *movie) } /* Take care of variable bitrate setting. */ - if (movie->quality) + if (movie->quality) { movie->picture->quality = movie->quality; + } movie->picture->linesize[0] = movie->ctx_codec->width; movie->picture->linesize[1] = movie->ctx_codec->width / 2; @@ -767,7 +805,7 @@ static int movie_set_outputfile(struct ctx_movie *movie) #if (MYFFVER < 58000) retcd = snprintf(movie->oc->filename, sizeof(movie->oc->filename), "%s", movie->filename); - if ((retcd < 0) || (retcd >= PATH_MAX)){ + if ((retcd < 0) || (retcd >= PATH_MAX)) { MOTION_LOG(ERR, TYPE_ENCODER, NO_ERRNO ,_("Error setting file name")); return -1; @@ -809,7 +847,7 @@ static int movie_set_outputfile(struct ctx_movie *movie) * items here */ retcd = avformat_write_header(movie->oc, NULL); - if (retcd < 0){ + if (retcd < 0) { av_strerror(retcd, errstr, sizeof(errstr)); MOTION_LOG(ERR, TYPE_ENCODER, NO_ERRNO ,_("Could not write movie header %s"),errstr); @@ -837,7 +875,7 @@ static int movie_flush_codec(struct ctx_movie *movie) int recv_cd = 0; char errstr[128]; - if (movie->passthrough){ + if (movie->passthrough) { return 0; } @@ -845,7 +883,7 @@ static int movie_flush_codec(struct ctx_movie *movie) recv_cd = 0; if (movie->tlapse == TIMELAPSE_NONE) { retcd = avcodec_send_frame(movie->ctx_codec, NULL); - if (retcd < 0 ){ + if (retcd < 0 ) { av_strerror(retcd, errstr, sizeof(errstr)); MOTION_LOG(ERR, TYPE_ENCODER, NO_ERRNO ,_("Error entering draining mode:%s"),errstr); @@ -856,8 +894,8 @@ static int movie_flush_codec(struct ctx_movie *movie) movie->pkt.data = NULL; movie->pkt.size = 0; recv_cd = avcodec_receive_packet(movie->ctx_codec, &movie->pkt); - if (recv_cd != AVERROR_EOF){ - if (recv_cd < 0){ + if (recv_cd != AVERROR_EOF) { + if (recv_cd < 0) { av_strerror(recv_cd, errstr, sizeof(errstr)); MOTION_LOG(ERR, TYPE_ENCODER, NO_ERRNO ,_("Error draining codec:%s"),errstr); @@ -908,8 +946,8 @@ static int movie_put_frame(struct ctx_movie *movie, const struct timespec *ts1) } retcd = movie_encode_video(movie); - if (retcd != 0){ - if (retcd != -2){ + if (retcd != 0) { + if (retcd != -2) { MOTION_LOG(ERR, TYPE_ENCODER, NO_ERRNO, _("Error while encoding picture")); } mypacket_unref(movie->pkt); @@ -1016,14 +1054,16 @@ static int movie_passthru_put(struct ctx_movie *movie, struct ctx_image_data *im int idnbr_image, idnbr_lastwritten, idnbr_stop, idnbr_firstkey; int indx, indx_lastwritten, indx_firstkey; - if (movie->netcam_data == NULL) return -1; + if (movie->netcam_data == NULL) { + return -1; + } if ((movie->netcam_data->status == NETCAM_NOTCONNECTED ) || - (movie->netcam_data->status == NETCAM_RECONNECTING ) ){ + (movie->netcam_data->status == NETCAM_RECONNECTING ) ) { return 0; } - if (movie->high_resolution){ + if (movie->high_resolution) { idnbr_image = img_data->idnbr_high; } else { idnbr_image = img_data->idnbr_norm; @@ -1038,27 +1078,27 @@ static int movie_passthru_put(struct ctx_movie *movie, struct ctx_image_data *im for(indx = 0; indx < movie->netcam_data->pktarray_size; indx++) { if ((movie->netcam_data->pktarray[indx].iswritten) && - (movie->netcam_data->pktarray[indx].idnbr > idnbr_lastwritten)){ + (movie->netcam_data->pktarray[indx].idnbr > idnbr_lastwritten)) { idnbr_lastwritten=movie->netcam_data->pktarray[indx].idnbr; indx_lastwritten = indx; } if ((movie->netcam_data->pktarray[indx].idnbr > idnbr_stop) && - (movie->netcam_data->pktarray[indx].idnbr <= idnbr_image)){ + (movie->netcam_data->pktarray[indx].idnbr <= idnbr_image)) { idnbr_stop=movie->netcam_data->pktarray[indx].idnbr; } if ((movie->netcam_data->pktarray[indx].iskey) && - (movie->netcam_data->pktarray[indx].idnbr <= idnbr_firstkey)){ + (movie->netcam_data->pktarray[indx].idnbr <= idnbr_firstkey)) { idnbr_firstkey=movie->netcam_data->pktarray[indx].idnbr; indx_firstkey = indx; } } - if (idnbr_stop == 0){ + if (idnbr_stop == 0) { pthread_mutex_unlock(&movie->netcam_data->mutex_pktarray); return 0; } - if (indx_lastwritten != -1){ + if (indx_lastwritten != -1) { indx = indx_lastwritten; } else if (indx_firstkey != -1) { indx = indx_firstkey; @@ -1073,9 +1113,13 @@ static int movie_passthru_put(struct ctx_movie *movie, struct ctx_image_data *im (movie->netcam_data->pktarray[indx].idnbr <= idnbr_image)) { movie_passthru_write(movie, indx); } - if (movie->netcam_data->pktarray[indx].idnbr == idnbr_stop) break; + if (movie->netcam_data->pktarray[indx].idnbr == idnbr_stop) { + break; + } indx++; - if (indx == movie->netcam_data->pktarray_size ) indx = 0; + if (indx == movie->netcam_data->pktarray_size ) { + indx = 0; + } } pthread_mutex_unlock(&movie->netcam_data->mutex_pktarray); return 0; @@ -1171,13 +1215,13 @@ static int movie_passthru_streams(struct ctx_movie *movie) static int movie_passthru_check(struct ctx_movie *movie) { if ((movie->netcam_data->status == NETCAM_NOTCONNECTED ) || - (movie->netcam_data->status == NETCAM_RECONNECTING ) ){ + (movie->netcam_data->status == NETCAM_RECONNECTING )) { MOTION_LOG(NTC, TYPE_ENCODER, NO_ERRNO ,_("rtsp camera not ready for pass-through.")); return -1; } - if (movie->netcam_data == NULL){ + if (movie->netcam_data == NULL) { MOTION_LOG(ERR, TYPE_ENCODER, NO_ERRNO, _("RTSP context not available.")); return -1; } @@ -1224,7 +1268,7 @@ static int movie_passthru_open(struct ctx_movie *movie) } retcd = movie_set_outputfile(movie); - if (retcd < 0){ + if (retcd < 0) { MOTION_LOG(ERR, TYPE_ENCODER, NO_ERRNO, _("Could not set the output file")); return -1; } @@ -1258,14 +1302,13 @@ void movie_avcodec_log(void *ignoreme, int errno_flag, const char *fmt, va_list * are not necessarily our errors. */ - if (errno_flag <= AV_LOG_WARNING){ + if (errno_flag <= AV_LOG_WARNING) { retcd = vsnprintf(buf, sizeof(buf), fmt, vl); - if (retcd >=1024){ + if (retcd >=1024) { MOTION_LOG(DBG, TYPE_ENCODER, NO_ERRNO, "av message truncated %d bytes",(retcd - 1024)); } end = buf + strlen(buf); - if (end > buf && end[-1] == '\n') - { + if (end > buf && end[-1] == '\n') { *--end = 0; } @@ -1279,7 +1322,7 @@ static void movie_put_pix_nv21(struct ctx_movie *movie, struct ctx_image_data *i unsigned char *image,*imagecr, *imagecb; int cr_len, x, y; - if (movie->high_resolution){ + if (movie->high_resolution) { image = img_data->image_high; } else { image = img_data->image_norm; @@ -1305,7 +1348,7 @@ static void movie_put_pix_yuv420(struct ctx_movie *movie, struct ctx_image_data { unsigned char *image; - if (movie->high_resolution){ + if (movie->high_resolution) { image = img_data->image_high; } else { image = img_data->image_norm; @@ -1344,8 +1387,7 @@ void movie_global_deinit(void) #if (MYFFVER < 58000) /* TODO Determine if this is even needed for old versions */ - if (av_lockmgr_register(NULL) < 0) - { + if (av_lockmgr_register(NULL) < 0) { MOTION_LOG(EMG, TYPE_ALL, SHOW_ERRNO ,_("av_lockmgr_register reset failed on cleanup")); } @@ -1389,19 +1431,19 @@ int movie_open(struct ctx_movie *movie) } retcd = movie_set_stream(movie); - if (retcd < 0){ + if (retcd < 0) { MOTION_LOG(ERR, TYPE_ENCODER, NO_ERRNO, _("Could not set the stream")); return -1; } retcd = movie_set_picture(movie); - if (retcd < 0){ + if (retcd < 0) { MOTION_LOG(ERR, TYPE_ENCODER, NO_ERRNO, _("Could not set the stream")); return -1; } retcd = movie_set_outputfile(movie); - if (retcd < 0){ + if (retcd < 0) { MOTION_LOG(ERR, TYPE_ENCODER, NO_ERRNO, _("Could not set the stream")); return -1; } @@ -1415,10 +1457,10 @@ void movie_close(struct ctx_movie *movie) if (movie != NULL) { - if (movie_flush_codec(movie) < 0){ + if (movie_flush_codec(movie) < 0) { MOTION_LOG(ERR, TYPE_ENCODER, NO_ERRNO, _("Error flushing codec")); } - if (movie->oc->pb != NULL){ + if (movie->oc->pb != NULL) { if (movie->tlapse != TIMELAPSE_APPEND) { av_write_trailer(movie->oc); } @@ -1456,7 +1498,7 @@ int movie_put_image(struct ctx_movie *movie, struct ctx_image_data *img_data, co } movie->gop_cnt ++; - if (movie->gop_cnt == movie->ctx_codec->gop_size ){ + if (movie->gop_cnt == movie->ctx_codec->gop_size ) { movie->picture->pict_type = AV_PICTURE_TYPE_I; movie->picture->key_frame = 1; movie->gop_cnt = 0; @@ -1474,14 +1516,14 @@ int movie_put_image(struct ctx_movie *movie, struct ctx_image_data *img_data, co while ((retcd == -2) && (movie->tlapse != TIMELAPSE_NONE)) { retcd = movie_put_frame(movie, ts1); cnt++; - if (cnt > 50){ + if (cnt > 50) { MOTION_LOG(ERR, TYPE_ENCODER, NO_ERRNO ,_("Excessive attempts to clear buffered packet")); retcd = -1; } } //non timelapse buffered is ok - if (retcd == -2){ + if (retcd == -2) { retcd = 0; MOTION_LOG(DBG, TYPE_ENCODER, NO_ERRNO, _("Buffered packet")); } @@ -1494,8 +1536,9 @@ int movie_put_image(struct ctx_movie *movie, struct ctx_image_data *img_data, co void movie_reset_start_time(struct ctx_movie *movie, const struct timespec *ts1) { int64_t one_frame_interval = av_rescale_q(1,(AVRational){1, movie->fps}, movie->strm_video->time_base); - if (one_frame_interval <= 0) + if (one_frame_interval <= 0) { one_frame_interval = 1; + } movie->base_pts = movie->last_pts + one_frame_interval; movie->start_time.tv_sec = ts1->tv_sec; @@ -1520,16 +1563,27 @@ static const char* movie_init_codec(struct ctx_cam *cam) if (cam->conf->movie_codec == "test") { MOTION_LOG(NTC, TYPE_ENCODER, NO_ERRNO, "Running test of the various output formats."); codenbr = cam->event_nr % 10; - if (codenbr == 1) return "flv"; - else if (codenbr == 2) return "ogg"; - else if (codenbr == 3) return "vp8"; - else if (codenbr == 4) return "mp4"; - else if (codenbr == 5) return "mkv"; - else if (codenbr == 6) return "hevc"; - else if (codenbr == 7) return "flv"; - else if (codenbr == 8) return "ogg"; - else if (codenbr == 9) return "vp8"; - else return "mkv"; + if (codenbr == 1) { + return "flv"; + } else if (codenbr == 2) { + return "ogg"; + } else if (codenbr == 3) { + return "vp8"; + } else if (codenbr == 4) { + return "mp4"; + } else if (codenbr == 5) { + return "mkv"; + } else if (codenbr == 6) { + return "hevc"; + } else if (codenbr == 7) { + return "flv"; + } else if (codenbr == 8) { + return "ogg"; + } else if (codenbr == 9) { + return "vp8"; + } else { + return "mkv"; + } } return cam->conf->movie_codec.c_str(); @@ -1554,12 +1608,12 @@ int movie_init_norm(struct ctx_cam *cam, struct timespec *ts1) retcd = snprintf(cam->movie_norm->filename, PATH_MAX, "%s/%s" , cam->conf->target_dir.c_str(), stamp); } - if ((retcd < 0) || (retcd >= PATH_MAX)){ + if ((retcd < 0) || (retcd >= PATH_MAX)) { MOTION_LOG(ERR, TYPE_ENCODER, NO_ERRNO ,_("Error setting file name")); return -1; } - if (cam->imgs.size_high > 0){ + if (cam->imgs.size_high > 0) { cam->movie_norm->width = cam->imgs.width_high; cam->movie_norm->height = cam->imgs.height_high; cam->movie_norm->high_resolution = TRUE; @@ -1611,7 +1665,7 @@ int movie_init_motion(struct ctx_cam *cam, struct timespec *ts1) retcd = snprintf(cam->movie_motion->filename, PATH_MAX, "%s/%sm" , cam->conf->target_dir.c_str(), stamp); } - if ((retcd < 0) || (retcd >= PATH_MAX)){ + if ((retcd < 0) || (retcd >= PATH_MAX)) { MOTION_LOG(ERR, TYPE_ENCODER, NO_ERRNO ,_("Error setting file name")); return -1; @@ -1663,7 +1717,7 @@ int movie_init_timelapse(struct ctx_cam *cam, struct timespec *ts1) , _("Error setting timelapse file name %s"), tmp); } - if ((cam->imgs.size_high > 0) && (!cam->movie_passthrough)){ + if ((cam->imgs.size_high > 0) && (!cam->movie_passthrough)) { cam->movie_timelapse->width = cam->imgs.width_high; cam->movie_timelapse->height = cam->imgs.height_high; cam->movie_timelapse->high_resolution = TRUE; diff --git a/src/netcam.cpp b/src/netcam.cpp index 8115c8c8..5ecbe239 100644 --- a/src/netcam.cpp +++ b/src/netcam.cpp @@ -46,14 +46,16 @@ static void netcam_check_buffsize(netcam_buff_ptr buff, size_t numbytes) int real_alloc; int new_size; - if ((buff->size - buff->used) >= numbytes) + if ((buff->size - buff->used) >= numbytes) { return; + } min_size_to_alloc = numbytes - (buff->size - buff->used); real_alloc = ((min_size_to_alloc / NETCAM_BUFFSIZE) * NETCAM_BUFFSIZE); - if ((min_size_to_alloc - real_alloc) > 0) + if ((min_size_to_alloc - real_alloc) > 0) { real_alloc += NETCAM_BUFFSIZE; + } new_size = buff->size + real_alloc; @@ -162,15 +164,15 @@ static void netcam_url_parse(struct url_t *parse_url, const char *text_url) regex_t pattbuf; regmatch_t matches[10]; - if (!strncmp(text_url, "file", 4)) + if (!strncmp(text_url, "file", 4)) { re = "(file)://(((.*):(.*))@)?([/:])?(:([0-9]+))?($|(/[^*]*))"; - - if (!strncmp(text_url, "jpeg", 4)) + } + if (!strncmp(text_url, "jpeg", 4)) { re = "(jpeg)://(((.*):(.*))@)?([/:])?(:([0-9]+))?($|(/[^*]*))"; - - if (!strncmp(text_url, "v4l2", 4)) + } + if (!strncmp(text_url, "v4l2", 4)) { re = "(v4l2)://(((.*):(.*))@)?([/:])?(:([0-9]+))?($|(/[^*]*))"; - + } /* Note that log messages are commented out to avoid leaking info related * to user/host/pass etc. Keeing them in the code for easier debugging if * it is needed @@ -223,14 +225,15 @@ static void netcam_url_parse(struct url_t *parse_url, const char *text_url) } if (((!parse_url->port) && (parse_url->service)) || ((parse_url->port > 65535) && (parse_url->service))) { - if (mystreq(parse_url->service, "http")) + if (mystreq(parse_url->service, "http")) { parse_url->port = 80; - else if (mystreq(parse_url->service, "ftp")) + } else if (mystreq(parse_url->service, "ftp")) { parse_url->port = 21; - else if (mystreq(parse_url->service, "rtmp")) + } else if (mystreq(parse_url->service, "rtmp")) { parse_url->port = 1935; - else if (mystreq(parse_url->service, "rtsp")) + } else if (mystreq(parse_url->service, "rtsp")) { parse_url->port = 554; + } MOTION_LOG(INF, TYPE_NETCAM, NO_ERRNO, _("Using port number %d"),parse_url->port); } @@ -271,7 +274,9 @@ static int netcam_check_pixfmt(struct ctx_netcam *netcam) retcd = -1; if (((enum AVPixelFormat)netcam->frame->format == MY_PIX_FMT_YUV420P) || - ((enum AVPixelFormat)netcam->frame->format == MY_PIX_FMT_YUVJ420P)) retcd = 0; + ((enum AVPixelFormat)netcam->frame->format == MY_PIX_FMT_YUVJ420P)) { + retcd = 0; + } return retcd; @@ -282,7 +287,7 @@ static void netcam_pktarray_free(struct ctx_netcam *netcam) int indx; pthread_mutex_lock(&netcam->mutex_pktarray); - if (netcam->pktarray_size > 0){ + if (netcam->pktarray_size > 0) { for(indx = 0; indx < netcam->pktarray_size; indx++) { if (netcam->pktarray[indx].packet.data != NULL) { mypacket_unref(netcam->pktarray[indx].packet); @@ -315,11 +320,11 @@ static void netcam_null_context(struct ctx_netcam *netcam) static void netcam_close_context(struct ctx_netcam *netcam) { - if (netcam->swsctx != NULL) sws_freeContext(netcam->swsctx); - if (netcam->swsframe_in != NULL) myframe_free(netcam->swsframe_in); - if (netcam->swsframe_out != NULL) myframe_free(netcam->swsframe_out); - if (netcam->frame != NULL) myframe_free(netcam->frame); - if (netcam->pktarray != NULL) netcam_pktarray_free(netcam); + if (netcam->swsctx != NULL) sws_freeContext(netcam->swsctx); + if (netcam->swsframe_in != NULL) myframe_free(netcam->swsframe_in); + if (netcam->swsframe_out != NULL) myframe_free(netcam->swsframe_out); + if (netcam->frame != NULL) myframe_free(netcam->frame); + if (netcam->pktarray != NULL) netcam_pktarray_free(netcam); if (netcam->codec_context != NULL) myavcodec_close(netcam->codec_context); if (netcam->format_context != NULL) avformat_close_input(&netcam->format_context); if (netcam->transfer_format != NULL) avformat_close_input(&netcam->transfer_format); @@ -353,7 +358,7 @@ static void netcam_pktarray_resize(struct ctx_cam *cam, int is_highres) struct packet_item *tmp; int newsize; - if (is_highres){ + if (is_highres) { idnbr_last = cam->imgs.image_ring[cam->imgs.ring_out].idnbr_high; idnbr_first = cam->imgs.image_ring[cam->imgs.ring_in].idnbr_high; netcam = cam->netcam_high; @@ -363,17 +368,21 @@ static void netcam_pktarray_resize(struct ctx_cam *cam, int is_highres) netcam = cam->netcam; } - if (!netcam->passthrough) return; + if (!netcam->passthrough) { + return; + } /* The 30 is arbitrary */ /* Double the size plus double last diff so we don't catch our tail */ newsize =((idnbr_first - idnbr_last) * 1 ) + ((netcam->idnbr - idnbr_last ) * 2); - if (newsize < 30) newsize = 30; + if (newsize < 30) { + newsize = 30; + } pthread_mutex_lock(&netcam->mutex_pktarray); - if ((netcam->pktarray_size < newsize) || (netcam->pktarray_size < 30)){ + if ((netcam->pktarray_size < newsize) || (netcam->pktarray_size < 30)) { tmp =(packet_item*) mymalloc(newsize * sizeof(struct packet_item)); - if (netcam->pktarray_size > 0 ){ + if (netcam->pktarray_size > 0 ) { memcpy(tmp, netcam->pktarray, sizeof(struct packet_item) * netcam->pktarray_size); } for(indx = netcam->pktarray_size; indx < newsize; indx++) { @@ -385,7 +394,9 @@ static void netcam_pktarray_resize(struct ctx_cam *cam, int is_highres) tmp[indx].iswritten = false; } - if (netcam->pktarray != NULL) free(netcam->pktarray); + if (netcam->pktarray != NULL) { + free(netcam->pktarray); + } netcam->pktarray = tmp; netcam->pktarray_size = newsize; @@ -405,13 +416,13 @@ static void netcam_pktarray_add(struct ctx_netcam *netcam) pthread_mutex_lock(&netcam->mutex_pktarray); - if (netcam->pktarray_size == 0){ + if (netcam->pktarray_size == 0) { pthread_mutex_unlock(&netcam->mutex_pktarray); return; } /* Recall pktarray_size is one based but pktarray is zero based */ - if (netcam->pktarray_index == (netcam->pktarray_size-1) ){ + if (netcam->pktarray_index == (netcam->pktarray_size-1)) { indx_next = 0; } else { indx_next = netcam->pktarray_index + 1; @@ -456,8 +467,8 @@ static int netcam_decode_sw(struct ctx_netcam *netcam) char errstr[128]; retcd = avcodec_receive_frame(netcam->codec_context, netcam->frame); - if ((netcam->interrupted) || (netcam->finish) || (retcd < 0) ){ - if (retcd == AVERROR(EAGAIN)){ + if ((netcam->interrupted) || (netcam->finish) || (retcd < 0)) { + if (retcd == AVERROR(EAGAIN)) { retcd = 0; } else if (retcd == AVERROR_INVALIDDATA) { MOTION_LOG(INF, TYPE_NETCAM, NO_ERRNO @@ -493,8 +504,8 @@ static int netcam_decode_vaapi(struct ctx_netcam *netcam) hw_frame = myframe_alloc(); retcd = avcodec_receive_frame(netcam->codec_context, hw_frame); - if ((netcam->interrupted) || (netcam->finish) || (retcd < 0) ){ - if (retcd == AVERROR(EAGAIN)){ + if ((netcam->interrupted) || (netcam->finish) || (retcd < 0)) { + if (retcd == AVERROR(EAGAIN)) { retcd = 0; } else if (retcd == AVERROR_INVALIDDATA) { MOTION_LOG(INF, TYPE_NETCAM, NO_ERRNO @@ -549,10 +560,12 @@ static int netcam_decode_video(struct ctx_netcam *netcam) * We should consider adding a maximum count of these errors and reset every time * we get a good image. */ - if (netcam->finish) return 0; /* This just speeds up the shutdown time */ + if (netcam->finish) { + return 0; /* This just speeds up the shutdown time */ + } retcd = avcodec_send_packet(netcam->codec_context, &netcam->packet_recv); - if ((netcam->interrupted) || (netcam->finish)){ + if ((netcam->interrupted) || (netcam->finish)) { MOTION_LOG(INF, TYPE_NETCAM, NO_ERRNO ,_("%s: Interrupted or finish on send") ,netcam->cameratype); @@ -564,7 +577,7 @@ static int netcam_decode_video(struct ctx_netcam *netcam) ,netcam->cameratype); return 0; } - if (retcd < 0 && retcd != AVERROR_EOF){ + if (retcd < 0 && retcd != AVERROR_EOF) { av_strerror(retcd, errstr, sizeof(errstr)); MOTION_LOG(INF, TYPE_NETCAM, NO_ERRNO ,_("%s: Error sending packet to codec: %s") @@ -572,7 +585,7 @@ static int netcam_decode_video(struct ctx_netcam *netcam) return -1; } - if (netcam->hw_type == AV_HWDEVICE_TYPE_VAAPI ){ + if (netcam->hw_type == AV_HWDEVICE_TYPE_VAAPI) { retcd = netcam_decode_vaapi(netcam); } else { retcd = netcam_decode_sw(netcam); @@ -589,11 +602,13 @@ static int netcam_decode_video(struct ctx_netcam *netcam) (void)netcam_decode_sw; (void)netcam_decode_vaapi; - if (netcam->finish) return 0; /* This just speeds up the shutdown time */ - + if (netcam->finish) { + return 0; /* This just speeds up the shutdown time */ + } retcd = avcodec_decode_video2(netcam->codec_context, netcam->frame, &check, &netcam->packet_recv); - if ((netcam->interrupted) || (netcam->finish)) return -1; - + if ((netcam->interrupted) || (netcam->finish)) { + return -1; + } if (retcd == AVERROR_INVALIDDATA) { MOTION_LOG(INF, TYPE_NETCAM, NO_ERRNO, _("Ignoring packet with invalid data")); return 0; @@ -605,8 +620,9 @@ static int netcam_decode_video(struct ctx_netcam *netcam) return -1; } - if (check == 0 || retcd == 0) return 0; - + if (check == 0 || retcd == 0) { + return 0; + } return 1; #endif @@ -618,7 +634,9 @@ static int netcam_decode_packet(struct ctx_netcam *netcam) int frame_size; int retcd; - if (netcam->finish) return -1; /* This just speeds up the shutdown time */ + if (netcam->finish) { + return -1; /* This just speeds up the shutdown time */ + } if (netcam->packet_recv.stream_index == netcam->audio_stream_index) { MOTION_LOG(ERR, TYPE_NETCAM, NO_ERRNO @@ -627,8 +645,9 @@ static int netcam_decode_packet(struct ctx_netcam *netcam) } retcd = netcam_decode_video(netcam); - if (retcd <= 0) return retcd; - + if (retcd <= 0) { + return retcd; + } frame_size = myimage_get_buffer_size((enum AVPixelFormat) netcam->frame->format ,netcam->frame->width ,netcam->frame->height); @@ -658,8 +677,9 @@ static void netcam_hwdecoders(struct ctx_netcam *netcam) { #if ( MYFFVER >= 57083) /* High Res pass through does not decode images into frames*/ - if (netcam->high_resolution && netcam->passthrough) return; - + if (netcam->high_resolution && netcam->passthrough) { + return; + } if ((netcam->hw_type == AV_HWDEVICE_TYPE_NONE) && (netcam->first_image)) { MOTION_LOG(INF, TYPE_NETCAM, NO_ERRNO ,_("%s: HW Devices: ") @@ -693,7 +713,9 @@ static enum AVPixelFormat netcam_getfmt_vaapi(AVCodecContext *avctx, const enum (void)avctx; for (p = pix_fmts; *p != -1; p++) { - if (*p == AV_PIX_FMT_VAAPI) return *p; + if (*p == AV_PIX_FMT_VAAPI) { + return *p; + } } MOTION_LOG(ERR, TYPE_NETCAM, NO_ERRNO,_("Failed to get vaapi pix format")); @@ -710,11 +732,11 @@ static void netcam_decoder_error(struct ctx_netcam *netcam, int retcd, const cha char errstr[128]; int indx; - if (netcam->interrupted){ + if (netcam->interrupted) { MOTION_LOG(ERR, TYPE_NETCAM, NO_ERRNO ,_("%s: Interrupted"),netcam->cameratype); } else { - if (retcd < 0){ + if (retcd < 0) { av_strerror(retcd, errstr, sizeof(errstr)); MOTION_LOG(ERR, TYPE_NETCAM, NO_ERRNO ,_("%s: %s: %s"),netcam->cameratype,fnc_nm, errstr); @@ -763,7 +785,7 @@ static int netcam_init_vaapi(struct ctx_netcam *netcam) ,_("%s: Initializing vaapi decoder"),netcam->cameratype); netcam->hw_type = av_hwdevice_find_type_by_name("vaapi"); - if (netcam->hw_type == AV_HWDEVICE_TYPE_NONE){ + if (netcam->hw_type == AV_HWDEVICE_TYPE_NONE) { MOTION_LOG(ERR, TYPE_NETCAM, NO_ERRNO,_("%s: Unable to find vaapi hw device") , netcam->cameratype); netcam_decoder_error(netcam, 0, "av_hwdevice"); @@ -771,7 +793,7 @@ static int netcam_init_vaapi(struct ctx_netcam *netcam) } netcam->codec_context = avcodec_alloc_context3(netcam->decoder); - if ((netcam->codec_context == NULL) || (netcam->interrupted)){ + if ((netcam->codec_context == NULL) || (netcam->interrupted)) { netcam_decoder_error(netcam, 0, "avcodec_alloc_context3"); return -1; } @@ -791,7 +813,7 @@ static int netcam_init_vaapi(struct ctx_netcam *netcam) AV_HWACCEL_FLAG_IGNORE_LEVEL; retcd = av_hwdevice_ctx_create(&netcam->hw_device_ctx, netcam->hw_type, NULL, NULL, 0); - if (retcd < 0){ + if (retcd < 0) { netcam_decoder_error(netcam, retcd, "hwctx"); return -1; } @@ -825,13 +847,13 @@ static int netcam_init_swdecoder(struct ctx_netcam *netcam) if (netcam->decoder == NULL) { netcam->decoder = avcodec_find_decoder(netcam->strm->codecpar->codec_id); } - if ((netcam->decoder == NULL) || (netcam->interrupted)){ + if ((netcam->decoder == NULL) || (netcam->interrupted)) { netcam_decoder_error(netcam, 0, "avcodec_find_decoder"); return -1; } netcam->codec_context = avcodec_alloc_context3(netcam->decoder); - if ((netcam->codec_context == NULL) || (netcam->interrupted)){ + if ((netcam->codec_context == NULL) || (netcam->interrupted)) { netcam_decoder_error(netcam, 0, "avcodec_alloc_context3"); return -1; } @@ -870,13 +892,15 @@ static int netcam_open_codec(struct ctx_netcam *netcam) int retcd; - if (netcam->finish) return -1; /* This just speeds up the shutdown time */ + if (netcam->finish) { + return -1; /* This just speeds up the shutdown time */ + } netcam_hwdecoders(netcam); retcd = av_find_best_stream(netcam->format_context , AVMEDIA_TYPE_AUDIO, -1, -1, NULL, 0); - if ((retcd < 0) || (netcam->interrupted)){ + if ((retcd < 0) || (netcam->interrupted)) { netcam->audio_stream_index = -1; } else { netcam->audio_stream_index = retcd; @@ -885,15 +909,15 @@ static int netcam_open_codec(struct ctx_netcam *netcam) netcam->decoder = NULL; retcd = av_find_best_stream(netcam->format_context , AVMEDIA_TYPE_VIDEO, -1, -1, &netcam->decoder, 0); - if ((retcd < 0) || (netcam->interrupted)){ + if ((retcd < 0) || (netcam->interrupted)) { netcam_decoder_error(netcam, retcd, "av_find_best_stream"); return -1; } netcam->video_stream_index = retcd; netcam->strm = netcam->format_context->streams[netcam->video_stream_index]; - if (mystrceq(netcam->decoder_nm,"vaapi")){ - if (netcam_init_vaapi(netcam) < 0){ + if (mystrceq(netcam->decoder_nm,"vaapi")) { + if (netcam_init_vaapi(netcam) < 0) { netcam_decoder_error(netcam, retcd, "hwvaapi_init"); return -1; } @@ -902,7 +926,7 @@ static int netcam_open_codec(struct ctx_netcam *netcam) } retcd = avcodec_open2(netcam->codec_context, netcam->decoder, NULL); - if ((retcd < 0) || (netcam->interrupted)){ + if ((retcd < 0) || (netcam->interrupted)) { netcam_decoder_error(netcam, retcd, "avcodec_open2"); return -1; } @@ -955,7 +979,7 @@ static int netcam_interrupt(void *ctx) { struct ctx_netcam *netcam = (struct ctx_netcam *)ctx; - if (netcam->finish){ + if (netcam->finish) { netcam->interrupted = true; return true; } @@ -998,11 +1022,13 @@ static int netcam_interrupt(void *ctx) static int netcam_open_sws(struct ctx_netcam *netcam) { - if (netcam->finish) return -1; /* This just speeds up the shutdown time */ + if (netcam->finish) { + return -1; /* This just speeds up the shutdown time */ + } netcam->swsframe_in = myframe_alloc(); if (netcam->swsframe_in == NULL) { - if (netcam->status == NETCAM_NOTCONNECTED){ + if (netcam->status == NETCAM_NOTCONNECTED) { MOTION_LOG(ERR, TYPE_NETCAM, NO_ERRNO , _("%s: Unable to allocate swsframe_in.") , netcam->cameratype); @@ -1013,7 +1039,7 @@ static int netcam_open_sws(struct ctx_netcam *netcam) netcam->swsframe_out = myframe_alloc(); if (netcam->swsframe_out == NULL) { - if (netcam->status == NETCAM_NOTCONNECTED){ + if (netcam->status == NETCAM_NOTCONNECTED) { MOTION_LOG(ERR, TYPE_NETCAM, NO_ERRNO , _("%s: Unable to allocate swsframe_out.") , netcam->cameratype); @@ -1026,7 +1052,7 @@ static int netcam_open_sws(struct ctx_netcam *netcam) * The scaling context is used to change dimensions to config file and * also if the format sent by the camera is not YUV420. */ - if (netcam_check_pixfmt(netcam) != 0){ + if (netcam_check_pixfmt(netcam) != 0) { MOTION_LOG(INF, TYPE_NETCAM, NO_ERRNO , _("%s: Pixel format %d will be converted.") , netcam->cameratype, netcam->frame->format); @@ -1041,7 +1067,7 @@ static int netcam_open_sws(struct ctx_netcam *netcam) ,MY_PIX_FMT_YUV420P ,SWS_BICUBIC,NULL,NULL,NULL); if (netcam->swsctx == NULL) { - if (netcam->status == NETCAM_NOTCONNECTED){ + if (netcam->status == NETCAM_NOTCONNECTED) { MOTION_LOG(ERR, TYPE_NETCAM, NO_ERRNO , _("%s: Unable to allocate scaling context.") , netcam->cameratype); @@ -1055,7 +1081,7 @@ static int netcam_open_sws(struct ctx_netcam *netcam) ,netcam->imgsize.width ,netcam->imgsize.height); if (netcam->swsframe_size <= 0) { - if (netcam->status == NETCAM_NOTCONNECTED){ + if (netcam->status == NETCAM_NOTCONNECTED) { MOTION_LOG(ERR, TYPE_NETCAM, NO_ERRNO , _("%s: Error determining size of frame out") , netcam->cameratype); @@ -1079,10 +1105,14 @@ static int netcam_resize(struct ctx_netcam *netcam) char errstr[128]; uint8_t *buffer_out; - if (netcam->finish) return -1; /* This just speeds up the shutdown time */ + if (netcam->finish) { + return -1; /* This just speeds up the shutdown time */ + } if (netcam->swsctx == NULL) { - if (netcam_open_sws(netcam) < 0) return -1; + if (netcam_open_sws(netcam) < 0) { + return -1; + } } retcd=myimage_fill_arrays( @@ -1092,7 +1122,7 @@ static int netcam_resize(struct ctx_netcam *netcam) ,netcam->frame->width ,netcam->frame->height); if (retcd < 0) { - if (netcam->status == NETCAM_NOTCONNECTED){ + if (netcam->status == NETCAM_NOTCONNECTED) { av_strerror(retcd, errstr, sizeof(errstr)); MOTION_LOG(ERR, TYPE_NETCAM, NO_ERRNO ,_("%s: Error allocating picture in: %s") @@ -1111,7 +1141,7 @@ static int netcam_resize(struct ctx_netcam *netcam) ,netcam->imgsize.width ,netcam->imgsize.height); if (retcd < 0) { - if (netcam->status == NETCAM_NOTCONNECTED){ + if (netcam->status == NETCAM_NOTCONNECTED) { av_strerror(retcd, errstr, sizeof(errstr)); MOTION_LOG(ERR, TYPE_NETCAM, NO_ERRNO ,_("%s: Error allocating picture out: %s") @@ -1130,7 +1160,7 @@ static int netcam_resize(struct ctx_netcam *netcam) ,netcam->swsframe_out->data ,netcam->swsframe_out->linesize); if (retcd < 0) { - if (netcam->status == NETCAM_NOTCONNECTED){ + if (netcam->status == NETCAM_NOTCONNECTED) { av_strerror(retcd, errstr, sizeof(errstr)); MOTION_LOG(ERR, TYPE_NETCAM, NO_ERRNO ,_("%s: Error resizing/reformatting: %s") @@ -1148,7 +1178,7 @@ static int netcam_resize(struct ctx_netcam *netcam) ,netcam->imgsize.height ,netcam->swsframe_size); if (retcd < 0) { - if (netcam->status == NETCAM_NOTCONNECTED){ + if (netcam->status == NETCAM_NOTCONNECTED) { av_strerror(retcd, errstr, sizeof(errstr)); MOTION_LOG(ERR, TYPE_NETCAM, NO_ERRNO ,_("%s: Error putting frame into output buffer: %s") @@ -1172,7 +1202,9 @@ static int netcam_read_image(struct ctx_netcam *netcam) char errstr[128]; netcam_buff *xchg; - if (netcam->finish) return -1; /* This just speeds up the shutdown time */ + if (netcam->finish) { + return -1; /* This just speeds up the shutdown time */ + } av_init_packet(&netcam->packet_recv); netcam->packet_recv.data = NULL; @@ -1190,7 +1222,9 @@ static int netcam_read_image(struct ctx_netcam *netcam) while ((!haveimage) && (!netcam->interrupted)) { retcd = av_read_frame(netcam->format_context, &netcam->packet_recv); - if (retcd < 0 ) errcnt++; + if (retcd < 0 ) { + errcnt++; + } if ((netcam->interrupted) || (errcnt > 1)) { if (netcam->interrupted) { MOTION_LOG(INF, TYPE_NETCAM, NO_ERRNO @@ -1219,9 +1253,9 @@ static int netcam_read_image(struct ctx_netcam *netcam) size_decoded = netcam_decode_packet(netcam); } } - if (size_decoded > 0 ){ + if (size_decoded > 0) { haveimage = true; - } else if (size_decoded == 0){ + } else if (size_decoded == 0) { /* Did not fail, just didn't get anything. Try again */ mypacket_unref(netcam->packet_recv); av_init_packet(&netcam->packet_recv); @@ -1247,7 +1281,7 @@ static int netcam_read_image(struct ctx_netcam *netcam) if ((netcam->imgsize.width != netcam->frame->width) || (netcam->imgsize.height != netcam->frame->height) || (netcam_check_pixfmt(netcam) != 0)) { - if (netcam_resize(netcam) < 0){ + if (netcam_resize(netcam) < 0) { mypacket_unref(netcam->packet_recv); netcam_close_context(netcam); return -1; @@ -1257,7 +1291,9 @@ static int netcam_read_image(struct ctx_netcam *netcam) pthread_mutex_lock(&netcam->mutex); netcam->idnbr++; - if (netcam->passthrough) netcam_pktarray_add(netcam); + if (netcam->passthrough) { + netcam_pktarray_add(netcam); + } if (!(netcam->high_resolution && netcam->passthrough) && (netcam->packet_recv.stream_index == netcam->video_stream_index)) { xchg = netcam->img_latest; @@ -1268,7 +1304,7 @@ static int netcam_read_image(struct ctx_netcam *netcam) mypacket_unref(netcam->packet_recv); - if (netcam->format_context->streams[netcam->video_stream_index]->avg_frame_rate.den > 0){ + if (netcam->format_context->streams[netcam->video_stream_index]->avg_frame_rate.den > 0) { netcam->src_fps = ( (netcam->format_context->streams[netcam->video_stream_index]->avg_frame_rate.num / netcam->format_context->streams[netcam->video_stream_index]->avg_frame_rate.den) + @@ -1294,13 +1330,17 @@ static int netcam_read_image(struct ctx_netcam *netcam) static int netcam_ntc(struct ctx_netcam *netcam) { - if ((netcam->finish) || (!netcam->first_image)) return 0; + if ((netcam->finish) || (!netcam->first_image)) { + return 0; + } /* High Res pass through does not decode images into frames*/ - if (netcam->high_resolution && netcam->passthrough) return 0; + if (netcam->high_resolution && netcam->passthrough) { + return 0; + } if ((netcam->imgsize.width != netcam->frame->width) || - (netcam->imgsize.height != netcam->frame->height) ){ + (netcam->imgsize.height != netcam->frame->height)) { MOTION_LOG(NTC, TYPE_NETCAM, NO_ERRNO, ""); MOTION_LOG(NTC, TYPE_NETCAM, NO_ERRNO, "******************************************************"); MOTION_LOG(NTC, TYPE_NETCAM, NO_ERRNO, _("The network camera is sending pictures at %dx%d") @@ -1401,7 +1441,7 @@ static void netcam_set_path (struct ctx_cam *cam, struct ctx_netcam *netcam ) memset(&url, 0, sizeof(url)); memset(userpass,0,PATH_MAX); - if (netcam->high_resolution){ + if (netcam->high_resolution) { netcam_url_parse(&url, cam->conf->netcam_high_url.c_str()); } else { netcam_url_parse(&url, cam->conf->netcam_url.c_str()); @@ -1411,7 +1451,7 @@ static void netcam_set_path (struct ctx_cam *cam, struct ctx_netcam *netcam ) cam->conf->netcam_userpass.copy(userpass, PATH_MAX); } else if (url.userpass != NULL) { retcd = snprintf(userpass,PATH_MAX,"%s",url.userpass); - if ((retcd <0) || (retcd>=PATH_MAX)){ + if ((retcd <0) || (retcd>=PATH_MAX)) { MOTION_LOG(INF, TYPE_NETCAM, NO_ERRNO,_("Error getting userpass")); } } @@ -1591,7 +1631,7 @@ static int netcam_copy_stream(struct ctx_netcam *netcam) transfer_stream = avformat_new_stream(netcam->transfer_format, NULL); stream_in = netcam->format_context->streams[indx]; retcd = avcodec_parameters_copy(transfer_stream->codecpar, stream_in->codecpar); - if (retcd < 0){ + if (retcd < 0) { MOTION_LOG(ERR, TYPE_NETCAM, NO_ERRNO ,_("%s: Unable to copy codec parameters") , netcam->cameratype); @@ -1607,7 +1647,9 @@ static int netcam_copy_stream(struct ctx_netcam *netcam) return 0; #else /* This is disabled in the mycheck_passthrough but we need it here for compiling */ - if (netcam != NULL) MOTION_LOG(INF, TYPE_ENCODER, NO_ERRNO, _("ffmpeg too old")); + if (netcam != NULL) { + MOTION_LOG(INF, TYPE_ENCODER, NO_ERRNO, _("ffmpeg too old")); + } return -1; #endif @@ -1619,10 +1661,12 @@ static int netcam_open_context(struct ctx_netcam *netcam) int retcd; char errstr[128]; - if (netcam->finish) return -1; + if (netcam->finish) { + return -1; + } if (netcam->path == NULL) { - if (netcam->status == NETCAM_NOTCONNECTED){ + if (netcam->status == NETCAM_NOTCONNECTED) { MOTION_LOG(ERR, TYPE_NETCAM, NO_ERRNO, _("Null path passed to connect")); } return -1; @@ -1641,15 +1685,17 @@ static int netcam_open_context(struct ctx_netcam *netcam) netcam_set_options(netcam); retcd = avformat_open_input(&netcam->format_context, netcam->path, NULL, &netcam->opts); - if ((retcd < 0) || (netcam->interrupted) || (netcam->finish) ){ - if (netcam->status == NETCAM_NOTCONNECTED){ + if ((retcd < 0) || (netcam->interrupted) || (netcam->finish) ) { + if (netcam->status == NETCAM_NOTCONNECTED) { av_strerror(retcd, errstr, sizeof(errstr)); MOTION_LOG(ERR, TYPE_NETCAM, NO_ERRNO ,_("%s: Unable to open camera(%s): %s") , netcam->cameratype, netcam->camera_name, errstr); } av_dict_free(&netcam->opts); - if (netcam->interrupted) netcam_close_context(netcam); + if (netcam->interrupted) { + netcam_close_context(netcam); + } return -1; } av_dict_free(&netcam->opts); @@ -1659,8 +1705,8 @@ static int netcam_open_context(struct ctx_netcam *netcam) /* fill out stream information */ retcd = avformat_find_stream_info(netcam->format_context, NULL); - if ((retcd < 0) || (netcam->interrupted) || (netcam->finish) ){ - if (netcam->status == NETCAM_NOTCONNECTED){ + if ((retcd < 0) || (netcam->interrupted) || (netcam->finish) ) { + if (netcam->status == NETCAM_NOTCONNECTED) { av_strerror(retcd, errstr, sizeof(errstr)); MOTION_LOG(ERR, TYPE_NETCAM, NO_ERRNO ,_("%s: Unable to find stream info: %s") @@ -1678,8 +1724,8 @@ static int netcam_open_context(struct ctx_netcam *netcam) mythreadname_set("av",netcam->threadnbr,netcam->camera_name); retcd = netcam_open_codec(netcam); mythreadname_set(NULL, 0, netcam->threadname); - if ((retcd < 0) || (netcam->interrupted) || (netcam->finish) ){ - if (netcam->status == NETCAM_NOTCONNECTED){ + if ((retcd < 0) || (netcam->interrupted) || (netcam->finish) ) { + if (netcam->status == NETCAM_NOTCONNECTED) { av_strerror(retcd, errstr, sizeof(errstr)); MOTION_LOG(ERR, TYPE_NETCAM, NO_ERRNO ,_("%s: Unable to open codec context: %s") @@ -1702,14 +1748,14 @@ static int netcam_open_context(struct ctx_netcam *netcam) return -1; } - if (netcam->high_resolution){ + if (netcam->high_resolution) { netcam->imgsize.width = netcam->codec_context->width; netcam->imgsize.height = netcam->codec_context->height; } netcam->frame = myframe_alloc(); if (netcam->frame == NULL) { - if (netcam->status == NETCAM_NOTCONNECTED){ + if (netcam->status == NETCAM_NOTCONNECTED) { MOTION_LOG(ERR, TYPE_NETCAM, NO_ERRNO ,_("%s: Unable to allocate frame."),netcam->cameratype); } @@ -1717,10 +1763,10 @@ static int netcam_open_context(struct ctx_netcam *netcam) return -1; } - if (netcam->passthrough){ + if (netcam->passthrough) { retcd = netcam_copy_stream(netcam); - if ((retcd < 0) || (netcam->interrupted)){ - if (netcam->status == NETCAM_NOTCONNECTED){ + if ((retcd < 0) || (netcam->interrupted)) { + if (netcam->status == NETCAM_NOTCONNECTED) { MOTION_LOG(ERR, TYPE_NETCAM, NO_ERRNO ,_("%s: Failed to copy stream for pass-through.") ,netcam->cameratype); @@ -1731,8 +1777,8 @@ static int netcam_open_context(struct ctx_netcam *netcam) /* Validate that the previous steps opened the camera */ retcd = netcam_read_image(netcam); - if ((retcd < 0) || (netcam->interrupted)){ - if (netcam->status == NETCAM_NOTCONNECTED){ + if ((retcd < 0) || (netcam->interrupted)) { + if (netcam->status == NETCAM_NOTCONNECTED) { MOTION_LOG(ERR, TYPE_NETCAM, NO_ERRNO ,_("%s: Failed to read first image"),netcam->cameratype); } @@ -1747,11 +1793,17 @@ static int netcam_open_context(struct ctx_netcam *netcam) static int netcam_connect(struct ctx_netcam *netcam) { - if (netcam_open_context(netcam) < 0) return -1; + if (netcam_open_context(netcam) < 0) { + return -1; + } - if (netcam_ntc(netcam) < 0 ) return -1; + if (netcam_ntc(netcam) < 0 ) { + return -1; + } - if (netcam_read_image(netcam) < 0) return -1; + if (netcam_read_image(netcam) < 0) { + return -1; + } /* We use the status for determining whether to grab a image from * the Motion loop(see "next" function). When we are initially starting, @@ -1759,7 +1811,7 @@ static int netcam_connect(struct ctx_netcam *netcam) * Motion loop to start quite yet on this first image so we do * not set the status to connected */ - if (!netcam->first_image){ + if (!netcam->first_image) { netcam->status = NETCAM_CONNECTED; MOTION_LOG(NTC, TYPE_NETCAM, NO_ERRNO @@ -1770,7 +1822,7 @@ static int netcam_connect(struct ctx_netcam *netcam) , _("%s: Netcam capture FPS is %d.") , netcam->cameratype, netcam->capture_rate); - if (netcam->src_fps > 0){ + if (netcam->src_fps > 0) { MOTION_LOG(NTC, TYPE_NETCAM, NO_ERRNO , _("%s: Camera source is %d FPS") , netcam->cameratype, netcam->src_fps); @@ -1780,7 +1832,7 @@ static int netcam_connect(struct ctx_netcam *netcam) , netcam->cameratype); } - if (netcam->capture_rate < netcam->src_fps){ + if (netcam->capture_rate < netcam->src_fps) { MOTION_LOG(WRN, TYPE_NETCAM, NO_ERRNO , _("%s: Capture FPS less than camera FPS. Decoding errors will occur.") , netcam->cameratype); @@ -1799,22 +1851,24 @@ static void netcam_shutdown(struct ctx_netcam *netcam) if (netcam) { netcam_close_context(netcam); - if (netcam->path != NULL) free(netcam->path); + if (netcam->path != NULL) { + free(netcam->path); + } netcam->path = NULL; - if (netcam->img_latest != NULL){ + if (netcam->img_latest != NULL) { free(netcam->img_latest->ptr); free(netcam->img_latest); } netcam->img_latest = NULL; - if (netcam->img_recv != NULL){ + if (netcam->img_recv != NULL) { free(netcam->img_recv->ptr); free(netcam->img_recv); } netcam->img_recv = NULL; - if (netcam->decoder_nm != NULL){ + if (netcam->decoder_nm != NULL) { free(netcam->decoder_nm); } netcam->decoder_nm = NULL; @@ -1832,7 +1886,9 @@ static void netcam_handler_wait(struct ctx_netcam *netcam) { long usec_maxrate, usec_delay; - if (netcam->capture_rate < 1) netcam->capture_rate = 1; + if (netcam->capture_rate < 1) { + netcam->capture_rate = 1; + } usec_maxrate = (1000000L / netcam->capture_rate); @@ -1842,7 +1898,7 @@ static void netcam_handler_wait(struct ctx_netcam *netcam) ((netcam->frame_curr_tm.tv_sec - netcam->frame_prev_tm.tv_sec) * 1000000L) - ((netcam->frame_curr_tm.tv_nsec - netcam->frame_prev_tm.tv_nsec)/1000); - if ((usec_delay > 0) && (usec_delay < 1000000L)){ + if ((usec_delay > 0) && (usec_delay < 1000000L)) { SLEEP(0, usec_delay * 1000); } @@ -1854,7 +1910,7 @@ static void netcam_handler_reconnect(struct ctx_netcam *netcam) int retcd; if ((netcam->status == NETCAM_CONNECTED) || - (netcam->status == NETCAM_READINGIMAGE)){ + (netcam->status == NETCAM_READINGIMAGE)) { MOTION_LOG(ERR, TYPE_NETCAM, NO_ERRNO ,_("%s: Reconnecting with camera...."),netcam->cameratype); } @@ -1866,10 +1922,10 @@ static void netcam_handler_reconnect(struct ctx_netcam *netcam) * before we go into the long wait phase */ retcd = netcam_connect(netcam); - if (retcd < 0){ - if (netcam->reconnect_count < 100){ + if (retcd < 0) { + if (netcam->reconnect_count < 100) { netcam->reconnect_count++; - } else if (netcam->reconnect_count == 100){ + } else if (netcam->reconnect_count == 100) { MOTION_LOG(NTC, TYPE_NETCAM, NO_ERRNO ,_("%s: Camera did not reconnect."), netcam->cameratype); MOTION_LOG(NTC, TYPE_NETCAM, NO_ERRNO @@ -1967,10 +2023,12 @@ static int netcam_start_handler(struct ctx_netcam *netcam) wait_counter = 60; while (wait_counter > 0) { pthread_mutex_lock(&netcam->mutex); - if (netcam->img_latest->ptr != NULL ) wait_counter = -1; + if (netcam->img_latest->ptr != NULL ) { + wait_counter = -1; + } pthread_mutex_unlock(&netcam->mutex); - if (wait_counter > 0 ){ + if (wait_counter > 0 ) { MOTION_LOG(INF, TYPE_NETCAM, NO_ERRNO ,_("%s: Waiting for first image from the handler."),netcam->cameratype); SLEEP(0,5000000); @@ -1992,14 +2050,19 @@ int netcam_setup(struct ctx_cam *cam) cam->netcam = NULL; cam->netcam_high = NULL; - if (netcam_set_dimensions(cam) < 0 ) return -1; + if (netcam_set_dimensions(cam) < 0 ) { + return -1; + } indx_cam = 1; - indx_max = 1; - if (cam->conf->netcam_high_url != "") indx_max = 2; + if (cam->conf->netcam_high_url != "") { + indx_max = 2; + } else { + indx_max = 1; + } while (indx_cam <= indx_max){ - if (indx_cam == 1){ + if (indx_cam == 1) { cam->netcam = netcam_new_context(); if (cam->netcam == NULL) { MOTION_LOG(ERR, TYPE_NETCAM, NO_ERRNO @@ -2023,10 +2086,12 @@ int netcam_setup(struct ctx_cam *cam) netcam_set_parms(cam, netcam); - if (netcam_connect(netcam) < 0) return -1; + if (netcam_connect(netcam) < 0) { + return -1; + } retcd = netcam_read_image(netcam); - if (retcd < 0){ + if (retcd < 0) { MOTION_LOG(CRT, TYPE_NETCAM, NO_ERRNO ,_("Failed trying to read first image - retval:%d"), retcd); netcam->status = NETCAM_NOTCONNECTED; @@ -2041,12 +2106,14 @@ int netcam_setup(struct ctx_cam *cam) * to set the dimension parameters here (it is done in the set_parms). For high res * we must get the dimensions from the first image captured */ - if (netcam->high_resolution){ + if (netcam->high_resolution) { cam->imgs.width_high = netcam->imgsize.width; cam->imgs.height_high = netcam->imgsize.height; } - if (netcam_start_handler(netcam) < 0 ) return -1; + if (netcam_start_handler(netcam) < 0 ) { + return -1; + } indx_cam++; } @@ -2061,7 +2128,7 @@ int netcam_next(struct ctx_cam *cam, struct ctx_image_data *img_data) /* This is called from the motion loop thread */ if ((cam->netcam->status == NETCAM_RECONNECTING) || - (cam->netcam->status == NETCAM_NOTCONNECTED)){ + (cam->netcam->status == NETCAM_NOTCONNECTED)) { return 1; } pthread_mutex_lock(&cam->netcam->mutex); @@ -2072,9 +2139,11 @@ int netcam_next(struct ctx_cam *cam, struct ctx_image_data *img_data) img_data->idnbr_norm = cam->netcam->idnbr; pthread_mutex_unlock(&cam->netcam->mutex); - if (cam->netcam_high){ + if (cam->netcam_high) { if ((cam->netcam_high->status == NETCAM_RECONNECTING) || - (cam->netcam_high->status == NETCAM_NOTCONNECTED)) return 1; + (cam->netcam_high->status == NETCAM_NOTCONNECTED)) { + return 1; + } pthread_mutex_lock(&cam->netcam_high->mutex); netcam_pktarray_resize(cam, true); @@ -2107,17 +2176,20 @@ void netcam_cleanup(struct ctx_cam *cam, int init_retry_flag) struct ctx_netcam *netcam; indx_cam = 1; - indx_max = 1; - if (cam->netcam_high) indx_max = 2; + if (cam->netcam_high) { + indx_max = 2; + } else { + indx_max = 1; + } while (indx_cam <= indx_max) { - if (indx_cam == 1){ + if (indx_cam == 1) { netcam = cam->netcam; } else { netcam = cam->netcam_high; } - if (netcam){ + if (netcam) { MOTION_LOG(INF, TYPE_NETCAM, NO_ERRNO ,_("%s: Shutting down network camera."),netcam->cameratype); @@ -2139,7 +2211,7 @@ void netcam_cleanup(struct ctx_cam *cam, int init_retry_flag) /* pthread_kill(netcam->thread_id); */ pthread_cancel(netcam->thread_id); pthread_kill(netcam->thread_id, SIGVTALRM); /* This allows the cancel to be processed */ - if (!init_retry_flag){ + if (!init_retry_flag) { pthread_mutex_lock(&netcam->motapp->global_lock); netcam->motapp->threads_running--; pthread_mutex_unlock(&netcam->motapp->global_lock); @@ -2154,7 +2226,7 @@ void netcam_cleanup(struct ctx_cam *cam, int init_retry_flag) free(netcam); netcam = NULL; - if (indx_cam == 1){ + if (indx_cam == 1) { MOTION_LOG(NTC, TYPE_NETCAM, NO_ERRNO ,_("Norm: Shut down complete.")); } else { diff --git a/src/picture.cpp b/src/picture.cpp index 96c1d8a3..b57e78eb 100644 --- a/src/picture.cpp +++ b/src/picture.cpp @@ -70,14 +70,14 @@ static void pic_save_webp(FILE *fp, unsigned char *image, int width, int height, #ifdef HAVE_WEBP /* Create a config present and check for compatible library version */ WebPConfig webp_config; - if (!WebPConfigPreset(&webp_config, WEBP_PRESET_DEFAULT, (float) quality)){ + if (!WebPConfigPreset(&webp_config, WEBP_PRESET_DEFAULT, (float) quality)) { MOTION_LOG(ERR, TYPE_CORE, NO_ERRNO, _("libwebp version error")); return; } /* Create the input data structure and check for compatible library version */ WebPPicture webp_image; - if (!WebPPictureInit(&webp_image)){ + if (!WebPPictureInit(&webp_image)) { MOTION_LOG(ERR, TYPE_CORE, NO_ERRNO,_("libwebp version error")); return; } @@ -85,7 +85,7 @@ static void pic_save_webp(FILE *fp, unsigned char *image, int width, int height, /* Allocate the image buffer based on image width and height */ webp_image.width = width; webp_image.height = height; - if (!WebPPictureAlloc(&webp_image)){ + if (!WebPPictureAlloc(&webp_image)) { MOTION_LOG(ERR, TYPE_CORE, NO_ERRNO,_("libwebp image buffer allocation error")); return; } @@ -102,9 +102,9 @@ static void pic_save_webp(FILE *fp, unsigned char *image, int width, int height, webp_image.custom_ptr = (void*) &webp_writer; /* Encode the YUV image as webp */ - if (!WebPEncode(&webp_config, &webp_image)) + if (!WebPEncode(&webp_config, &webp_image)) { MOTION_LOG(WRN, TYPE_CORE, NO_ERRNO,_("libwebp image compression error")); - + } /* A bitstream object is needed for the muxing proces */ WebPData webp_bitstream; webp_bitstream.bytes = webp_writer.mem; @@ -122,8 +122,9 @@ static void pic_save_webp(FILE *fp, unsigned char *image, int width, int height, } /* Write the webp final bitstream to the file */ - if (fwrite(webp_output.bytes, sizeof(uint8_t), webp_output.size, fp) != webp_output.size) + if (fwrite(webp_output.bytes, sizeof(uint8_t), webp_output.size, fp) != webp_output.size) { MOTION_LOG(ERR, TYPE_CORE, NO_ERRNO,_("unable to save webp image to file")); + } #if WEBP_ENCODER_ABI_VERSION > 0x0202 /* writer.mem must be freed by calling WebPMemoryWriterClear */ @@ -210,18 +211,24 @@ static void pic_save_ppm(FILE *picture, unsigned char *image, int width, int hei r = r >> 16; g = g >> 16; b = b >> 16; - if (r < 0) + + if (r < 0) { r = 0; - else if (r > 255) + } else if (r > 255) { r = 255; - if (g < 0) + } + + if (g < 0) { g = 0; - else if (g > 255) + } else if (g > 255) { g = 255; - if (b < 0) + } + + if (b < 0) { b = 0; - else if (b > 255) + } else if (b > 255) { b = 255; + } rgb[0] = b; rgb[1] = g; @@ -250,7 +257,7 @@ int pic_put_memory(struct ctx_cam *cam, unsigned char* dest_image, int image_siz struct timespec ts1; clock_gettime(CLOCK_REALTIME, &ts1); - if (!cam->conf->stream_grey){ + if (!cam->conf->stream_grey) { return jpgutl_put_yuv420p(dest_image, image_size, image, width, height, quality, cam ,&ts1, NULL); } else { @@ -328,7 +335,9 @@ void pic_save_roi(struct ctx_cam *cam, char *file, unsigned char *image) bx = &cam->current_image->location; - if ((bx->width <64) || (bx->height <64)) return; + if ((bx->width <64) || (bx->height <64)) { + return; + } picture = myfopen(file, "w"); if (!picture) { @@ -383,8 +392,9 @@ unsigned char *pic_load_pgm(FILE *picture, int width, int height) /* Skip comment */ line[0] = '#'; while (line[0] == '#') - if (!fgets(line, 255, picture)) + if (!fgets(line, 255, picture)) { return NULL; + } /* Read image size */ if (sscanf(line, "%d %d", &mask_width, &mask_height) != 2) { @@ -396,8 +406,9 @@ unsigned char *pic_load_pgm(FILE *picture, int width, int height) /* Maximum value */ line[0] = '#'; while (line[0] == '#') - if (!fgets(line, 255, picture)) + if (!fgets(line, 255, picture)) { return NULL; + } if (sscanf(line, "%d", &maxval) != 1) { MOTION_LOG(ERR, TYPE_ALL, SHOW_ERRNO @@ -413,11 +424,13 @@ unsigned char *pic_load_pgm(FILE *picture, int width, int height) image =(unsigned char*) mymalloc((mask_width * mask_height * 3) / 2); for (y = 0; y < mask_height; y++) { - if ((int)fread(&image[y * mask_width], 1, mask_width, picture) != mask_width) + if ((int)fread(&image[y * mask_width], 1, mask_width, picture) != mask_width) { MOTION_LOG(ERR, TYPE_ALL, SHOW_ERRNO, "Failed reading image data from pgm file"); + } - for (x = 0; x < mask_width; x++) + for (x = 0; x < mask_width; x++) { image[y * mask_width + x] = (int)image[y * mask_width + x] * 255 / maxval; + } } @@ -521,7 +534,7 @@ void pic_save_preview(struct ctx_cam *cam, struct ctx_image_data *img) /* Copy the actual images for norm and high */ memcpy(cam->imgs.image_preview.image_norm, img->image_norm, cam->imgs.size_norm); - if (cam->imgs.size_high > 0){ + if (cam->imgs.size_high > 0) { memcpy(cam->imgs.image_preview.image_high, img->image_high, cam->imgs.size_high); } @@ -529,8 +542,9 @@ void pic_save_preview(struct ctx_cam *cam, struct ctx_image_data *img) * If we set output_all to yes and during the event * there is no image with motion, diffs is 0, we are not going to save the preview event */ - if (cam->imgs.image_preview.diffs == 0) + if (cam->imgs.image_preview.diffs == 0) { cam->imgs.image_preview.diffs = 1; + } draw_locate_preview(cam, img); @@ -567,7 +581,7 @@ void pic_init_privacy(struct ctx_cam *cam) /* We only need the "or" mask for the U & V chrominance area. */ cam->imgs.mask_privacy_uv =(unsigned char*) mymalloc((cam->imgs.height * cam->imgs.width) / 2); - if (cam->imgs.size_high > 0){ + if (cam->imgs.size_high > 0) { MOTION_LOG(INF, TYPE_ALL, NO_ERRNO ,_("Opening high resolution privacy mask file")); rewind(picture); @@ -591,11 +605,14 @@ void pic_init_privacy(struct ctx_cam *cam) ,_("Mask privacy file \"%s\" loaded."), cam->conf->mask_privacy.c_str()); indx_img = 1; - indx_max = 1; - if (cam->imgs.size_high > 0) indx_max = 2; + if (cam->imgs.size_high > 0) { + indx_max = 2; + } else { + indx_max = 1; + } while (indx_img <= indx_max){ - if (indx_img == 1){ + if (indx_img == 1) { start_cr = (cam->imgs.height * cam->imgs.width); offset_cb = ((cam->imgs.height * cam->imgs.width)/4); start_cb = start_cr + offset_cb; @@ -617,7 +634,7 @@ void pic_init_privacy(struct ctx_cam *cam) for (indxcol = 0; indxcol < indx_width; indxcol++) { y_index = indxcol + (indxrow * indx_width); if (img_temp[y_index] == 0xff) { - if ((indxcol % 2 == 0) && (indxrow % 2 == 0) ){ + if ((indxcol % 2 == 0) && (indxrow % 2 == 0) ) { uv_index = (indxcol/2) + ((indxrow * indx_width)/4); img_temp[start_cr + uv_index] = 0xff; img_temp[start_cb + uv_index] = 0xff; @@ -626,7 +643,7 @@ void pic_init_privacy(struct ctx_cam *cam) } } else { img_temp[y_index] = 0x00; - if ((indxcol % 2 == 0) && (indxrow % 2 == 0) ){ + if ((indxcol % 2 == 0) && (indxrow % 2 == 0) ) { uv_index = (indxcol/2) + ((indxrow * indx_width)/4); img_temp[start_cr + uv_index] = 0x00; img_temp[start_cb + uv_index] = 0x00; diff --git a/src/rotate.cpp b/src/rotate.cpp index 50328325..c30add5f 100644 --- a/src/rotate.cpp +++ b/src/rotate.cpp @@ -244,15 +244,19 @@ void rotate_init(struct ctx_cam *cam) * If we're not rotating, let's exit once we have setup the capture dimensions * and output dimensions properly. */ - if (cam->rotate_data->degrees == 0) return; + if (cam->rotate_data->degrees == 0) { + return; + } /* * Allocate memory if rotating 90 or 270 degrees, because those rotations * cannot be performed in-place (they can, but it would be too slow). */ - if ((cam->rotate_data->degrees == 90) || (cam->rotate_data->degrees == 270)){ + if ((cam->rotate_data->degrees == 90) || (cam->rotate_data->degrees == 270)) { cam->rotate_data->buffer_norm =(unsigned char*) mymalloc(size_norm); - if (size_high > 0 ) cam->rotate_data->buffer_high =(unsigned char*) mymalloc(size_high); + if (size_high > 0 ) { + cam->rotate_data->buffer_high =(unsigned char*) mymalloc(size_high); + } } } @@ -271,13 +275,15 @@ void rotate_init(struct ctx_cam *cam) void rotate_deinit(struct ctx_cam *cam) { - if (cam->rotate_data->buffer_norm) + if (cam->rotate_data->buffer_norm) { free(cam->rotate_data->buffer_norm); + } - if (cam->rotate_data->buffer_high) + if (cam->rotate_data->buffer_high) { free(cam->rotate_data->buffer_high); + } - if (cam->rotate_data != NULL){ + if (cam->rotate_data != NULL) { free(cam->rotate_data); cam->rotate_data = NULL; } @@ -316,11 +322,16 @@ int rotate_map(struct ctx_cam *cam, struct ctx_image_data *img_data) unsigned char *img; unsigned char *temp_buff; - if (cam->rotate_data->degrees == 0 && cam->rotate_data->axis == FLIP_TYPE_NONE) return 0; + if (cam->rotate_data->degrees == 0 && cam->rotate_data->axis == FLIP_TYPE_NONE) { + return 0; + } indx = 0; - indx_max = 0; - if ((cam->rotate_data->capture_width_high != 0) && (cam->rotate_data->capture_height_high != 0)) indx_max = 1; + if ((cam->rotate_data->capture_width_high != 0) && (cam->rotate_data->capture_height_high != 0)) { + indx_max = 1; + } else { + indx_max = 0; + } while (indx <= indx_max) { deg = cam->rotate_data->degrees; @@ -328,7 +339,7 @@ int rotate_map(struct ctx_cam *cam, struct ctx_image_data *img_data) wh4 = 0; w2 = 0; h2 = 0; - if (indx == 0 ){ + if (indx == 0 ) { img = img_data->image_norm; width = cam->rotate_data->capture_width_norm; height = cam->rotate_data->capture_height_norm; diff --git a/src/util.cpp b/src/util.cpp index 4bd26edd..f0572198 100644 --- a/src/util.cpp +++ b/src/util.cpp @@ -410,11 +410,12 @@ size_t mystrftime(const struct ctx_cam *cam, char *s, size_t max, const char *us break; case 'C': // text_event - if (cam->text_event_string[0]) + if (cam->text_event_string[0]) { snprintf(tempstr, PATH_MAX, "%*s", width, cam->text_event_string); - else + } else { ++pos_userformat; + } break; case 'w': // picture width @@ -432,17 +433,19 @@ size_t mystrftime(const struct ctx_cam *cam, char *s, size_t max, const char *us break; } - if (filename) + if (filename) { snprintf(tempstr, PATH_MAX, "%*s", width, filename); - else + } else { ++pos_userformat; + } break; case 'n': // sqltype - if (sqltype) + if (sqltype) { sprintf(tempstr, "%*d", width, sqltype); - else + } else { ++pos_userformat; + } break; case '{': // long format specifier word. @@ -451,15 +454,18 @@ size_t mystrftime(const struct ctx_cam *cam, char *s, size_t max, const char *us while ((*pos_userformat != '}') && (*pos_userformat != 0)) ++pos_userformat; mystrftime_long (cam, width, word, (int)(pos_userformat-word), tempstr); - if (*pos_userformat == '\0') --pos_userformat; + if (*pos_userformat == '\0') { + --pos_userformat; + } } break; case '$': // thread name - if (cam->conf->camera_name != "") + if (cam->conf->camera_name != "") { cam->conf->camera_name.copy(tempstr, PATH_MAX); - else + } else { ++pos_userformat; + } break; default: // Any other code is copied with the %-sign @@ -561,7 +567,9 @@ static void mytranslate_locale_chg(const char *langcd) /* Invoke external function to change locale*/ ++_nl_msg_cat_cntr; #else - if (langcd != NULL) MOTION_LOG(NTC, TYPE_ALL, NO_ERRNO,"No native language support"); + if (langcd != NULL) { + MOTION_LOG(NTC, TYPE_ALL, NO_ERRNO,"No native language support"); + } #endif } @@ -593,7 +601,7 @@ char* mytranslate_text(const char *msgid, int setnls) { static int nls_enabled = TRUE; - if (setnls == 0){ + if (setnls == 0) { if (nls_enabled) { MOTION_LOG(NTC, TYPE_ALL, NO_ERRNO,_("Disabling native language support")); } @@ -796,7 +804,7 @@ int mycopy_packet(AVPacket *dest_pkt, AVPacket *src_pkt) * We therefore disable the pass through recording and * for this function, simply do not do anything */ - if (dest_pkt == src_pkt ){ + if (dest_pkt == src_pkt ) { return 0; } else { return 0; @@ -992,7 +1000,7 @@ void util_parms_parse_qte(struct ctx_params *params, std::string &parmline) if (indxcm == std::string::npos) { if (indxnm_st == std::string::npos) { indxvl_st = indxeq + 1; - if (indxvl_st >= parmline.length()){ + if (indxvl_st >= parmline.length()) { indxvl_st = parmline.length() - 1; } indxvl_en = parmline.length() - 1; @@ -1140,7 +1148,7 @@ void util_parms_update(struct ctx_params *params, std::string &confline) std::string parmline; for (indx = 0; indx < params->params_count; indx++) { - if (indx == 0){ + if (indx == 0) { parmline = " "; } else { parmline += ","; diff --git a/src/video_common.cpp b/src/video_common.cpp index 31d3eb16..1b70ae75 100644 --- a/src/video_common.cpp +++ b/src/video_common.cpp @@ -434,7 +434,7 @@ int vid_mjpegtoyuv420p(unsigned char *img_dst, unsigned char *img_src, int width ptr_buffer =(unsigned char*) memmem(img_src + soi_pos + 1, size - soi_pos - 1, "\xff\xd8", 2); } - if (soi_pos != 0){ + if (soi_pos != 0) { MOTION_LOG(INF, TYPE_VIDEO, NO_ERRNO,_("SOI position adjusted by %d bytes."), soi_pos); } diff --git a/src/video_loopback.cpp b/src/video_loopback.cpp index 6f72cd54..c0cb23a2 100644 --- a/src/video_loopback.cpp +++ b/src/video_loopback.cpp @@ -114,7 +114,9 @@ static int vlp_open_vidpipe(void) if ((tfd = open(buffer, O_RDWR|O_CLOEXEC)) >= 0) { strncpy(pipepath, buffer, sizeof(pipepath)); - if (pipe_fd >= 0) close(pipe_fd); + if (pipe_fd >= 0) { + close(pipe_fd); + } pipe_fd = tfd; break; } @@ -125,8 +127,9 @@ static int vlp_open_vidpipe(void) closedir(dir); - if (pipe_fd >= 0) + if (pipe_fd >= 0) { MOTION_LOG(NTC, TYPE_VIDEO, NO_ERRNO,_("Opened %s as pipe output"), pipepath); + } return pipe_fd; } @@ -143,9 +146,11 @@ static void vlp_show_vcap(struct v4l2_capability *cap) MOTION_LOG(INF, TYPE_VIDEO, NO_ERRNO, "cap.bus_info: %s",cap->bus_info); MOTION_LOG(INF, TYPE_VIDEO, NO_ERRNO, "cap.card: %u.%u.%u",(vers >> 16) & 0xFF,(vers >> 8) & 0xFF,vers & 0xFF); MOTION_LOG(INF, TYPE_VIDEO, NO_ERRNO, "Device capabilities"); - for (i=0;cap_list[i].code;i++) - if (c & cap_list[i].code) + for (i=0;cap_list[i].code;i++) { + if (c & cap_list[i].code) { MOTION_LOG(INF, TYPE_VIDEO, NO_ERRNO, "%s",cap_list[i].cap); + } + } MOTION_LOG(INF, TYPE_VIDEO, NO_ERRNO, "------------------------"); } diff --git a/src/webu_stream.cpp b/src/webu_stream.cpp index 9d568607..afa41c31 100644 --- a/src/webu_stream.cpp +++ b/src/webu_stream.cpp @@ -30,7 +30,7 @@ /* Allocate buffers if needed */ static void webu_stream_mjpeg_checkbuffers(struct webui_ctx *webui) { - if (webui->resp_size < (size_t)webui->cam->imgs.size_norm){ + if (webui->resp_size < (size_t)webui->cam->imgs.size_norm) { if (webui->resp_image != NULL) { free(webui->resp_image); webui->resp_image = NULL; @@ -57,12 +57,16 @@ static void webu_stream_mjpeg_delay(struct webui_ctx *webui) */ stream_delay = ((time_curr.tv_nsec - webui->time_last.tv_nsec)) + ((time_curr.tv_sec - webui->time_last.tv_sec)*1000000000); - if (stream_delay < 0) stream_delay = 0; - if (stream_delay > 1000000000 ) stream_delay = 1000000000; + if (stream_delay < 0) { + stream_delay = 0; + } + if (stream_delay > 1000000000 ) { + stream_delay = 1000000000; + } - if (webui->stream_fps >= 1){ + if (webui->stream_fps >= 1) { stream_rate = ( (1000000000 / webui->stream_fps) - stream_delay); - if ((stream_rate > 0) && (stream_rate < 1000000000)){ + if ((stream_rate > 0) && (stream_rate < 1000000000)) { SLEEP(0,stream_rate); } else if (stream_rate == 1000000000) { SLEEP(1,0); @@ -82,19 +86,19 @@ static void webu_stream_mjpeg_getimg(struct webui_ctx *webui) memset(webui->resp_image, '\0', webui->resp_size); /* Assign to a local pointer the stream we want */ - if (webui->cnct_type == WEBUI_CNCT_FULL){ + if (webui->cnct_type == WEBUI_CNCT_FULL) { local_stream = &webui->cam->stream.norm; - } else if (webui->cnct_type == WEBUI_CNCT_SUB){ + } else if (webui->cnct_type == WEBUI_CNCT_SUB) { local_stream = &webui->cam->stream.sub; - } else if (webui->cnct_type == WEBUI_CNCT_MOTION){ + } else if (webui->cnct_type == WEBUI_CNCT_MOTION) { local_stream = &webui->cam->stream.motion; - } else if (webui->cnct_type == WEBUI_CNCT_SOURCE){ + } else if (webui->cnct_type == WEBUI_CNCT_SOURCE) { local_stream = &webui->cam->stream.source; - } else if (webui->cnct_type == WEBUI_CNCT_SECONDARY){ + } else if (webui->cnct_type == WEBUI_CNCT_SECONDARY) { local_stream = &webui->cam->stream.secondary; } else { @@ -104,7 +108,7 @@ static void webu_stream_mjpeg_getimg(struct webui_ctx *webui) /* Copy jpg from the motion loop thread */ pthread_mutex_lock(&webui->cam->stream.mutex); if ((!webui->cam->detecting_motion) && - (webui->motapp->cam_list[webui->threadnbr]->conf->stream_motion)){ + (webui->motapp->cam_list[webui->threadnbr]->conf->stream_motion)) { webui->stream_fps = 1; } else { webui->stream_fps = webui->motapp->cam_list[webui->threadnbr]->conf->stream_maxrate; @@ -146,9 +150,11 @@ static ssize_t webu_stream_mjpeg_response (void *cls, uint64_t pos, char *buf, s (void)pos; /*Remove compiler warning */ - if (webui->cam->motapp->webcontrol_finish) return -1; + if (webui->cam->motapp->webcontrol_finish) { + return -1; + } - if ((webui->stream_pos == 0) || (webui->resp_used == 0)){ + if ((webui->stream_pos == 0) || (webui->resp_used == 0)) { webu_stream_mjpeg_delay(webui); @@ -157,7 +163,9 @@ static ssize_t webu_stream_mjpeg_response (void *cls, uint64_t pos, char *buf, s webu_stream_mjpeg_getimg(webui); - if (webui->resp_used == 0) return 0; + if (webui->resp_used == 0) { + return 0; + } } if ((webui->resp_used - webui->stream_pos) > max) { @@ -169,7 +177,7 @@ static ssize_t webu_stream_mjpeg_response (void *cls, uint64_t pos, char *buf, s memcpy(buf, webui->resp_image + webui->stream_pos, sent_bytes); webui->stream_pos = webui->stream_pos + sent_bytes; - if (webui->stream_pos >= webui->resp_used){ + if (webui->stream_pos >= webui->resp_used) { webui->stream_pos = 0; } @@ -187,19 +195,19 @@ static void webu_stream_static_getimg(struct webui_ctx *webui) memset(webui->resp_image, '\0', webui->resp_size); /* Assign to a local pointer the stream we want */ - if (webui->cnct_type == WEBUI_CNCT_FULL){ + if (webui->cnct_type == WEBUI_CNCT_FULL) { local_stream = &webui->cam->stream.norm; - } else if (webui->cnct_type == WEBUI_CNCT_SUB){ + } else if (webui->cnct_type == WEBUI_CNCT_SUB) { local_stream = &webui->cam->stream.sub; - } else if (webui->cnct_type == WEBUI_CNCT_MOTION){ + } else if (webui->cnct_type == WEBUI_CNCT_MOTION) { local_stream = &webui->cam->stream.motion; - } else if (webui->cnct_type == WEBUI_CNCT_SOURCE){ + } else if (webui->cnct_type == WEBUI_CNCT_SOURCE) { local_stream = &webui->cam->stream.source; - } else if (webui->cnct_type == WEBUI_CNCT_SECONDARY){ + } else if (webui->cnct_type == WEBUI_CNCT_SECONDARY) { local_stream = &webui->cam->stream.secondary; } else { @@ -207,7 +215,7 @@ static void webu_stream_static_getimg(struct webui_ctx *webui) } pthread_mutex_lock(&webui->cam->stream.mutex); - if (local_stream->jpeg_data == NULL){ + if (local_stream->jpeg_data == NULL) { pthread_mutex_unlock(&webui->cam->stream.mutex); return; } @@ -281,7 +289,7 @@ static void webu_stream_cnct_count(struct webui_ctx *webui) pthread_mutex_unlock(&webui->cam->stream.mutex); } - if (cnct_count == 1){ + if (cnct_count == 1) { /* This is the first connection so we need to wait half a sec * so that the motion loop on the other thread can update image */ @@ -327,7 +335,9 @@ static mhdrslt webu_stream_mjpeg(struct webui_ctx *webui) mhdrslt retcd; struct MHD_Response *response; - if (webu_stream_checks(webui) == -1) return MHD_NO; + if (webu_stream_checks(webui) == -1) { + return MHD_NO; + } webu_stream_cnct_count(webui); @@ -337,12 +347,12 @@ static mhdrslt webu_stream_mjpeg(struct webui_ctx *webui) response = MHD_create_response_from_callback (MHD_SIZE_UNKNOWN, 1024 ,&webu_stream_mjpeg_response, webui, NULL); - if (!response){ + if (!response) { MOTION_LOG(ERR, TYPE_STREAM, NO_ERRNO, _("Invalid response")); return MHD_NO; } - if (webui->motapp->cam_list[0]->conf->webcontrol_cors_header != ""){ + if (webui->motapp->cam_list[0]->conf->webcontrol_cors_header != "") { MHD_add_response_header(response, MHD_HTTP_HEADER_ACCESS_CONTROL_ALLOW_ORIGIN , webui->motapp->cam_list[0]->conf->webcontrol_cors_header.c_str()); } @@ -364,7 +374,9 @@ static mhdrslt webu_stream_static(struct webui_ctx *webui) struct MHD_Response *response; char resp_used[20]; - if (webu_stream_checks(webui) == -1) return MHD_NO; + if (webu_stream_checks(webui) == -1) { + return MHD_NO; + } webu_stream_cnct_count(webui); @@ -379,12 +391,12 @@ static mhdrslt webu_stream_static(struct webui_ctx *webui) response = MHD_create_response_from_buffer (webui->resp_size ,(void *)webui->resp_image, MHD_RESPMEM_MUST_COPY); - if (!response){ + if (!response) { MOTION_LOG(ERR, TYPE_STREAM, NO_ERRNO, _("Invalid response")); return MHD_NO; } - if (webui->motapp->cam_list[0]->conf->webcontrol_cors_header != ""){ + if (webui->motapp->cam_list[0]->conf->webcontrol_cors_header != "") { MHD_add_response_header (response, MHD_HTTP_HEADER_ACCESS_CONTROL_ALLOW_ORIGIN , webui->motapp->cam_list[0]->conf->webcontrol_cors_header.c_str()); } @@ -462,32 +474,32 @@ void webu_stream_deinit(struct ctx_cam *cam) pthread_mutex_destroy(&cam->stream.mutex); - if (cam->imgs.image_substream != NULL){ + if (cam->imgs.image_substream != NULL) { free(cam->imgs.image_substream); cam->imgs.image_substream = NULL; } - if (cam->stream.norm.jpeg_data != NULL){ + if (cam->stream.norm.jpeg_data != NULL) { free(cam->stream.norm.jpeg_data); cam->stream.norm.jpeg_data = NULL; } - if (cam->stream.sub.jpeg_data != NULL){ + if (cam->stream.sub.jpeg_data != NULL) { free(cam->stream.sub.jpeg_data); cam->stream.sub.jpeg_data = NULL; } - if (cam->stream.motion.jpeg_data != NULL){ + if (cam->stream.motion.jpeg_data != NULL) { free(cam->stream.motion.jpeg_data); cam->stream.motion.jpeg_data = NULL; } - if (cam->stream.source.jpeg_data != NULL){ + if (cam->stream.source.jpeg_data != NULL) { free(cam->stream.source.jpeg_data); cam->stream.source.jpeg_data = NULL; } - if (cam->stream.secondary.jpeg_data != NULL){ + if (cam->stream.secondary.jpeg_data != NULL) { free(cam->stream.secondary.jpeg_data); cam->stream.secondary.jpeg_data = NULL; } @@ -498,7 +510,7 @@ void webu_stream_deinit(struct ctx_cam *cam) static void webu_stream_getimg_norm(struct ctx_cam *cam, struct ctx_image_data *img_data) { /*This is on the motion_loop thread */ - if (cam->stream.norm.jpeg_data == NULL){ + if (cam->stream.norm.jpeg_data == NULL) { cam->stream.norm.jpeg_data =(unsigned char*)mymalloc(cam->imgs.size_norm); } if (img_data->image_norm != NULL && cam->stream.norm.consumed) { @@ -521,7 +533,7 @@ static void webu_stream_getimg_sub(struct ctx_cam *cam, struct ctx_image_data *i int subsize; - if (cam->stream.sub.jpeg_data == NULL){ + if (cam->stream.sub.jpeg_data == NULL) { cam->stream.sub.jpeg_data =(unsigned char*)mymalloc(cam->imgs.size_norm); } if (img_data->image_norm != NULL && cam->stream.sub.consumed) { @@ -530,7 +542,7 @@ static void webu_stream_getimg_sub(struct ctx_cam *cam, struct ctx_image_data *i ((cam->imgs.height % 16) == 0)) { subsize = ((cam->imgs.width / 2) * (cam->imgs.height / 2) * 3 / 2); - if (cam->imgs.image_substream == NULL){ + if (cam->imgs.image_substream == NULL) { cam->imgs.image_substream =(unsigned char*)mymalloc(subsize); } pic_scale_img(cam->imgs.width @@ -564,7 +576,7 @@ static void webu_stream_getimg_motion(struct ctx_cam *cam) { /*This is on the motion_loop thread */ - if (cam->stream.motion.jpeg_data == NULL){ + if (cam->stream.motion.jpeg_data == NULL) { cam->stream.motion.jpeg_data =(unsigned char*)mymalloc(cam->imgs.size_norm); } if (cam->imgs.image_motion.image_norm != NULL && cam->stream.motion.consumed) { @@ -585,7 +597,7 @@ static void webu_stream_getimg_source(struct ctx_cam *cam) { /*This is on the motion_loop thread */ - if (cam->stream.source.jpeg_data == NULL){ + if (cam->stream.source.jpeg_data == NULL) { cam->stream.source.jpeg_data =(unsigned char*)mymalloc(cam->imgs.size_norm); } if (cam->imgs.image_virgin != NULL && cam->stream.source.consumed) { @@ -608,14 +620,14 @@ static void webu_stream_getimg_secondary(struct ctx_cam *cam) if (cam->imgs.size_secondary>0) { pthread_mutex_lock(&cam->algsec->mutex); - if (cam->stream.secondary.jpeg_data == NULL){ + if (cam->stream.secondary.jpeg_data == NULL) { cam->stream.secondary.jpeg_data =(unsigned char*)mymalloc(cam->imgs.size_norm); } memcpy(cam->stream.secondary.jpeg_data,cam->imgs.image_secondary,cam->imgs.size_secondary); cam->stream.secondary.jpeg_size = cam->imgs.size_secondary; pthread_mutex_unlock(&cam->algsec->mutex); } else { - if (cam->stream.secondary.jpeg_data != NULL){ + if (cam->stream.secondary.jpeg_data != NULL) { free(cam->stream.secondary.jpeg_data); cam->stream.secondary.jpeg_data = NULL; }