Consistently use for loops for camera

This commit is contained in:
Mr-Dave
2023-01-22 14:39:53 -07:00
parent 18b450dfd6
commit 74496fa04e
4 changed files with 23 additions and 66 deletions

View File

@@ -41,21 +41,17 @@ static void motion_signal_process(ctx_motapp *motapp)
switch(motsignal){
case MOTION_SIGNAL_ALARM: /* Trigger snapshot */
if (motapp->cam_list != NULL) {
indx = 0;
while (motapp->cam_list[indx] != NULL) {
for (indx=0; indx<motapp->cam_cnt; indx++) {
if (motapp->cam_list[indx]->conf->snapshot_interval) {
motapp->cam_list[indx]->snapshot = true;
}
indx++;
}
}
break;
case MOTION_SIGNAL_USR1: /* Trigger the end of a event */
if (motapp->cam_list != NULL) {
indx = 0;
while (motapp->cam_list[indx] != NULL){
for (indx=0; indx<motapp->cam_cnt; indx++) {
motapp->cam_list[indx]->event_stop = true;
indx++;
}
}
break;
@@ -507,8 +503,7 @@ static void motion_watchdog(ctx_motapp *motapp, int camindx)
, motapp->cam_list[camindx]->device_id);
/* Shut down all the cameras */
indx = 0;
while (motapp->cam_list[indx] != NULL) {
for (indx=0; indx<motapp->cam_cnt; indx++) {
pthread_mutex_unlock(&motapp->mutex_camlst);
pthread_mutex_unlock(&motapp->mutex_parms);
pthread_mutex_unlock(&motapp->mutex_camlst);
@@ -536,7 +531,6 @@ static void motion_watchdog(ctx_motapp *motapp, int camindx)
}
motapp->cam_list[indx]->event_stop = true;
motapp->cam_list[indx]->finish_dev = true;
indx++;
}
SLEEP(motapp->cam_list[camindx]->conf->watchdog_kill, 0);
@@ -545,8 +539,7 @@ static void motion_watchdog(ctx_motapp *motapp, int camindx)
* we WILL have to leak memory because the freeing/deinit
* processes could lock this thread which would stop everything.
*/
indx = 0;
while (motapp->cam_list[indx] != NULL) {
for (indx=0; indx<motapp->cam_cnt; indx++) {
if (motapp->cam_list[indx]->netcam != NULL) {
if (motapp->cam_list[indx]->netcam->handler_finished == false) {
MOTION_LOG(ERR, TYPE_ALL, NO_ERRNO
@@ -571,7 +564,6 @@ static void motion_watchdog(ctx_motapp *motapp, int camindx)
};
motapp->cam_list[indx]->running_dev = false;
motapp->cam_list[indx]->restart_dev = false;
indx++;
}
motapp->restart_all = true;
motapp->finish_all = true;
@@ -666,20 +658,17 @@ static void motion_cam_add(ctx_motapp *motapp)
conf_camera_add(motapp);
pthread_mutex_unlock(&motapp->mutex_camlst);
indx_cam = 0;
indx = 1;
while (motapp->cam_list[indx_cam] != NULL) {
for (indx_cam=0; indx_cam<motapp->cam_cnt; indx_cam++) {
if (indx < motapp->cam_list[indx_cam]->device_id) {
indx = motapp->cam_list[indx_cam]->device_id;
}
indx_cam++;
}
indx++;
indx_cam--;
motapp->cam_list[indx_cam]->device_id = indx;
motapp->cam_list[indx_cam]->conf->device_id = indx;
motapp->cam_list[indx_cam]->conf->webcontrol_port = 0;
motapp->cam_list[motapp->cam_cnt-1]->device_id = indx;
motapp->cam_list[motapp->cam_cnt-1]->conf->device_id = indx;
motapp->cam_list[motapp->cam_cnt-1]->conf->webcontrol_port = 0;
motapp->cam_add = false;

View File

@@ -1960,13 +1960,11 @@ static void netcam_handler_reconnect(ctx_netcam *netcam)
* and find the pointer that matches our passed in netcam.
*/
if (netcam->passthrough == true) {
indx = 1;
while (netcam->motapp->cam_list[indx] != NULL) {
for (indx=0; indx<netcam->motapp->cam_cnt; indx++) {
if ((netcam->motapp->cam_list[indx]->netcam == netcam) ||
(netcam->motapp->cam_list[indx]->netcam_high == netcam)) {
netcam->motapp->cam_list[indx]->event_stop = true;
}
indx++;
}
}

View File

@@ -164,12 +164,10 @@ static void webu_json_config_cam_parms(ctx_webui *webui)
webui->resp_page += "\"default\": ";
webu_json_config_parms(webui, webui->motapp->conf);
indx_cam = 0;
while (webui->motapp->cam_list[indx_cam] != NULL) {
for (indx_cam=0; indx_cam<webui->motapp->cam_cnt; indx_cam++) {
webui->resp_page += ",\"cam" +
std::to_string(webui->motapp->cam_list[indx_cam]->device_id) + "\": ";
webu_json_config_parms(webui, webui->motapp->cam_list[indx_cam]->conf);
indx_cam++;
}
webui->resp_page += "}";
@@ -186,8 +184,7 @@ static void webu_json_config_cam_list(ctx_webui *webui)
webui->resp_page += "{\"count\" : " + std::to_string(webui->motapp->cam_cnt);
indx_cam = 0;
while (webui->motapp->cam_list[indx_cam] != NULL) {
for (indx_cam=0; indx_cam<webui->motapp->cam_cnt; indx_cam++) {
cam = webui->motapp->cam_list[indx_cam];
strid =std::to_string(cam->device_id);
webui->resp_page += ",\"" + std::to_string(indx_cam) + "\":";
@@ -198,7 +195,6 @@ static void webu_json_config_cam_list(ctx_webui *webui)
}
webui->resp_page += ",\"id\": " + strid;
webui->resp_page += ",\"url\": \"" + webui->hostfull + "/" + strid + "/\"} ";
indx_cam++;
}
webui->resp_page += "}";
@@ -263,13 +259,11 @@ static void webu_json_movies_list(ctx_webui *webui)
ctx_params *wact;
/* Get the indx we want */
indx_cam = 0;
indx_req = -1;
while (webui->motapp->cam_list[indx_cam] != NULL) {
for (indx_cam=0; indx_cam<webui->motapp->cam_cnt; indx_cam++) {
if (webui->cam->device_id == webui->motapp->cam_list[indx_cam]->device_id){
indx_req = indx_cam;
}
indx_cam++;
}
webui->resp_page += "{\"count\" : 1";
@@ -429,17 +423,11 @@ void webu_json_status(ctx_webui *webui)
webui->resp_page += "{\"version\" : \"" VERSION "\"";
webui->resp_page += ",\"status\" : ";
indx_cam = 0;
while (webui->motapp->cam_list[indx_cam] != NULL) {
indx_cam++;
}
webui->resp_page += "{\"count\" : " + std::to_string(indx_cam - 1);
indx_cam = 0;
while (webui->motapp->cam_list[indx_cam] != NULL) {
webui->resp_page += "{\"count\" : " + std::to_string(webui->motapp->cam_cnt);
for (indx_cam=0; indx_cam<webui->motapp->cam_cnt; indx_cam++) {
webui->resp_page += ",\"cam" +
std::to_string(webui->motapp->cam_list[indx_cam]->device_id) + "\": ";
webu_json_status_vars(webui, indx_cam);
indx_cam++;
}
webui->resp_page += "}";

View File

@@ -137,13 +137,11 @@ void webu_post_cmdthrd(ctx_webui *webui)
return;
}
indx = 0;
while (webui->motapp->cam_list[indx] != NULL) {
for (indx=0; indx<webui->motapp->cam_cnt; indx++) {
if (webui->motapp->cam_list[indx]->device_id == camid) {
webui->threadnbr = indx;
break;
}
indx++;
}
}
@@ -167,10 +165,8 @@ void webu_post_action_eventend(ctx_webui *webui)
}
if (webui->threadnbr == -1) {
indx = 0;
while (webui->motapp->cam_list[indx]) {
for (indx=0; indx<webui->motapp->cam_cnt; indx++) {
webui->motapp->cam_list[indx]->event_stop = true;
indx++;
}
} else {
webui->motapp->cam_list[webui->threadnbr]->event_stop = true;
@@ -197,10 +193,8 @@ void webu_post_action_eventstart(ctx_webui *webui)
}
if (webui->threadnbr == -1) {
indx = 0;
while (webui->motapp->cam_list[indx]) {
for (indx=0; indx<webui->motapp->cam_cnt; indx++) {
webui->motapp->cam_list[indx]->event_user = true;
indx++;
}
} else {
webui->motapp->cam_list[webui->threadnbr]->event_user = true;
@@ -227,10 +221,8 @@ void webu_post_action_snapshot(ctx_webui *webui)
}
if (webui->threadnbr == -1) {
indx = 0;
while (webui->motapp->cam_list[indx]) {
for (indx=0; indx<webui->motapp->cam_cnt; indx++) {
webui->motapp->cam_list[indx]->snapshot = true;
indx++;
}
} else {
webui->motapp->cam_list[webui->threadnbr]->snapshot = true;
@@ -257,10 +249,8 @@ void webu_post_action_pause(ctx_webui *webui)
}
if (webui->threadnbr == -1) {
indx = 0;
while (webui->motapp->cam_list[indx]) {
for (indx=0; indx<webui->motapp->cam_cnt; indx++) {
webui->motapp->cam_list[indx]->pause = true;
indx++;
};
} else {
webui->motapp->cam_list[webui->threadnbr]->pause = true;
@@ -287,10 +277,8 @@ void webu_post_action_unpause(ctx_webui *webui)
}
if (webui->threadnbr == -1) {
indx = 0;
while (webui->motapp->cam_list[indx]) {
for (indx=0; indx<webui->motapp->cam_cnt; indx++) {
webui->motapp->cam_list[indx]->pause = false;
indx++;
};
} else {
webui->motapp->cam_list[webui->threadnbr]->pause = false;
@@ -317,11 +305,9 @@ void webu_post_action_restart(ctx_webui *webui)
}
if (webui->threadnbr == -1) {
MOTION_LOG(NTC, TYPE_STREAM, NO_ERRNO, _("Restarting all cameras"));
indx = 0;
while (webui->motapp->cam_list[indx]) {
for (indx=0; indx<webui->motapp->cam_cnt; indx++) {
webui->motapp->cam_list[indx]->restart_dev = true;
webui->motapp->cam_list[indx]->finish_dev = true;
indx++;
}
} else {
MOTION_LOG(NTC, TYPE_STREAM, NO_ERRNO
@@ -350,8 +336,7 @@ void webu_post_action_stop(ctx_webui *webui)
}
}
if (webui->threadnbr == -1) {
indx = 0;
while (webui->motapp->cam_list[indx]) {
for (indx=0; indx<webui->motapp->cam_cnt; indx++) {
MOTION_LOG(NTC, TYPE_STREAM, NO_ERRNO
, _("Stopping cam %d")
, webui->motapp->cam_list[indx]->device_id);
@@ -359,7 +344,6 @@ void webu_post_action_stop(ctx_webui *webui)
webui->motapp->cam_list[indx]->event_stop = true;
webui->motapp->cam_list[indx]->event_user = false;
webui->motapp->cam_list[indx]->finish_dev = true;
indx++;
}
} else {
MOTION_LOG(NTC, TYPE_STREAM, NO_ERRNO
@@ -394,8 +378,7 @@ void webu_post_action_user(ctx_webui *webui)
}
if (webui->threadnbr == -1) {
indx = 0;
while (webui->motapp->cam_list[indx]) {
for (indx=0; indx<webui->motapp->cam_cnt; indx++) {
cam = webui->motapp->cam_list[indx];
cam->action_user[0] = '\0';
for (indx2 = 0; indx2 < webui->post_sz; indx2++) {
@@ -416,7 +399,6 @@ void webu_post_action_user(ctx_webui *webui)
, _("Executing user action on cam %d")
, cam->device_id);
util_exec_command(cam, cam->conf->on_action_user.c_str(), NULL, 0);
indx++;
}
} else {
cam = webui->motapp->cam_list[webui->threadnbr];