Brace Usage Style

* Adjust brace usage style
This commit is contained in:
Mr-DaveDev
2020-11-04 17:38:37 -07:00
committed by GitHub
parent 905ea1646a
commit c2cef04645
28 changed files with 2529 additions and 1589 deletions

View File

@@ -120,9 +120,7 @@ GOOD EXAMPLE
if ((picture=fopen(cnt->conf.mask_file, "r"))) {
cnt->imgs.mask=get_pgm(cnt, picture, cnt->imgs.width, cnt->imgs.height);
fclose(picture);
} else {
put_fixed_mask(cnt, cnt->conf.mask_file);
printf("Hello world\n");
}
@@ -172,6 +170,8 @@ switch (expr) {
statement;
}
RULE 5A
if, while and for statements shall always use braces.
--------------------

225
src/alg.c
View File

@@ -78,16 +78,16 @@ void alg_locate_center_size(struct images *imgs, int width, int height, struct c
for (y = 0; y < height; y++) {
for (x = 0; x < width; x++) {
if (*(labels++) & 32768) {
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;
}
centc++;
}
}
@@ -97,16 +97,16 @@ void alg_locate_center_size(struct images *imgs, int width, int height, struct c
for (y = 0; y < height; y++) {
for (x = 0; x < width; x++) {
if (*(out++)) {
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;
}
centc++;
}
}
@@ -126,25 +126,28 @@ void alg_locate_center_size(struct images *imgs, int width, int height, struct c
cent->maxy = cent->y + ydist / centc * 2;
}
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;
}
/* Align for better locate box handling */
cent->minx += cent->minx % 2;
@@ -370,8 +373,9 @@ void alg_noise_tune(struct context *cnt, unsigned char *new)
for (; i > 0; i--) {
diff = ABS(*ref - *new);
if (mask)
if (mask) {
diff = ((diff * *mask++) / 255);
}
if (*smartmask) {
sum += diff + 1;
@@ -383,8 +387,10 @@ void alg_noise_tune(struct context *cnt, unsigned char *new)
smartmask++;
}
if (count > 3) /* Avoid divide by zero. */
if (count > 3) {
/* Avoid divide by zero. */
sum /= count / 3;
}
/* 5: safe, 4: regular, 3: more sensitive */
cnt->noise = 4 + (cnt->noise + sum) / 2;
@@ -399,22 +405,26 @@ void alg_threshold_tune(struct context *cnt, int diffs, int motion)
int i;
int sum = 0, top = diffs;
if (!diffs)
if (!diffs) {
return;
}
if (motion)
if (motion) {
diffs = cnt->threshold / 4;
}
for (i = 0; i < THRESHOLD_TUNE_LENGTH - 1; i++) {
sum += cnt->diffs_last[i];
if (cnt->diffs_last[i + 1] && !motion)
if (cnt->diffs_last[i + 1] && !motion) {
cnt->diffs_last[i] = cnt->diffs_last[i + 1];
else
} else {
cnt->diffs_last[i] = cnt->threshold / 4;
}
if (cnt->diffs_last[i] > top)
if (cnt->diffs_last[i] > top) {
top = cnt->diffs_last[i];
}
}
sum += cnt->diffs_last[i];
@@ -422,11 +432,13 @@ void alg_threshold_tune(struct context *cnt, int diffs, int motion)
sum /= THRESHOLD_TUNE_LENGTH / 4;
if (sum < top * 2)
if (sum < top * 2) {
sum = top * 2;
}
if (sum < cnt->conf.threshold)
if (sum < cnt->conf.threshold) {
cnt->threshold = (cnt->threshold + sum) / 2;
}
}
/*
@@ -463,8 +475,9 @@ static int iflood(int x, int y, int width, int height,
Segment stack[MAXS], *sp = stack; /* Stack of filled segments. */
int count = 0;
if (x < 0 || x >= width || y < 0 || y >= height)
if (x < 0 || x >= width || y < 0 || y >= height) {
return 0;
}
PUSH(y, x, x, 1); /* Needed in some cases. */
PUSH(y+1, x, x, -1); /* Seed segment (popped 1st). */
@@ -481,13 +494,15 @@ static int iflood(int x, int y, int width, int height,
count++;
}
if (x >= x1)
if (x >= x1) {
goto skip;
}
l = x + 1;
if (l < x1)
if (l < x1) {
PUSH(y, l, x1 - 1, -dy); /* Leak on left? */
}
x = x1 + 1;
@@ -499,12 +514,13 @@ static int iflood(int x, int y, int width, int height,
PUSH(y, l, x - 1, dy);
if (x > x2 + 1)
if (x > x2 + 1) {
PUSH(y, x2 + 1, x - 1, -dy); /* Leak on right? */
}
skip:
for (x++; x <= x2 && !(out[y * width + x] != 0 && labels[y * width + x] == oldvalue); x++);
for (x++; x <= x2 && !(out[y * width + x] != 0 && labels[y * width + x] == oldvalue); x++) {}
l = x;
} while (x <= x2);
@@ -548,8 +564,9 @@ static int alg_labeling(struct context *cnt)
}
/* Already visited by iflood */
if (labels[pixelpos] > 0)
if (labels[pixelpos] > 0) {
continue;
}
labelsize = iflood(ix, iy, width, height, out, labels, current_label, 0);
@@ -563,8 +580,9 @@ static int alg_labeling(struct context *cnt)
labelsize = iflood(ix, iy, width, height, out, labels, current_label + 32768, current_label);
imgs->labelgroup_max += labelsize;
imgs->labels_above++;
} else if(max_under < labelsize)
} else if(max_under < labelsize) {
max_under = labelsize;
}
if (imgs->labelsize_max < labelsize) {
imgs->labelsize_max = labelsize;
@@ -627,10 +645,11 @@ static int dilate9(unsigned char *img, int width, int height, void *buffer)
row3 = rowTemp;
/* If we're at the last row, fill with zeros, otherwise copy from img. */
if (y == height - 1)
if (y == height - 1) {
memset(row3, 0, width);
else
} else {
memcpy(row3, yp+width, width);
}
/* Init slots 0 and 1 in the moving window. */
window[0] = MAX3(row1[0], row2[0], row3[0]);
@@ -652,10 +671,11 @@ static int dilate9(unsigned char *img, int width, int height, void *buffer)
* If the value is larger than the current max, use it. Otherwise,
* calculate a new max (because the new value may not be the max.
*/
if (latest >= blob)
if (latest >= blob) {
blob = latest;
else
} else {
blob = MAX3(window[0], window[1], window[2]);
}
/* Write the max value (blob) to the image. */
if (blob != 0) {
@@ -664,8 +684,9 @@ static int dilate9(unsigned char *img, int width, int height, void *buffer)
}
/* Wrap around the window index if necessary. */
if (++widx == 3)
if (++widx == 3) {
widx = 0;
}
}
/* Store zeros in the vertical sides. */
@@ -710,10 +731,11 @@ static int dilate5(unsigned char *img, int width, int height, void *buffer)
row3 = rowTemp;
/* If we're at the last row, fill with zeros, otherwise copy from img. */
if (y == height - 1)
if (y == height - 1) {
memset(row3, 0, width);
else
} else {
memcpy(row3, yp + width, width);
}
/* Init mem and set blob to force an evaluation of the entire + shape. */
mem = MAX2(row2[0], row2[1]);
@@ -766,10 +788,11 @@ static int erode9(unsigned char *img, int width, int height, void *buffer, unsig
memcpy(Row1, Row2, width);
memcpy(Row2, Row3, width);
if (y == height-1)
if (y == height-1) {
memset(Row3, flag, width);
else
} else {
memcpy(Row3, img + (y+1) * width, width);
}
for (i = width - 2; i >= 1; i--) {
if (Row1[i - 1] == 0 ||
@@ -780,10 +803,11 @@ static int erode9(unsigned char *img, int width, int height, void *buffer, unsig
Row2[i + 1] == 0 ||
Row3[i - 1] == 0 ||
Row3[i] == 0 ||
Row3[i + 1] == 0)
Row3[i + 1] == 0) {
img[y * width + i] = 0;
else
} else {
sum++;
}
}
img[y * width] = img[y * width + width - 1] = flag;
@@ -810,20 +834,22 @@ static int erode5(unsigned char *img, int width, int height, void *buffer, unsig
memcpy(Row1, Row2, width);
memcpy(Row2, Row3, width);
if (y == height-1)
if (y == height-1) {
memset(Row3, flag, width);
else
} else {
memcpy(Row3, img + (y + 1) * width, width);
}
for (i = width - 2; i >= 1; i--) {
if (Row1[i] == 0 ||
Row2[i - 1] == 0 ||
Row2[i] == 0 ||
Row2[i + 1] == 0 ||
Row3[i] == 0)
Row3[i] == 0) {
img[y * width + i] = 0;
else
} else {
sum++;
}
}
img[y * width] = img[y * width + width - 1] = flag;
@@ -847,13 +873,15 @@ int alg_despeckle(struct context *cnt, int olddiffs)
for (i = 0; i < len; i++) {
switch (cnt->conf.despeckle_filter[i]) {
case 'E':
if ((diffs = erode9(out, width, height, common_buffer, 0)) == 0)
if ((diffs = erode9(out, width, height, common_buffer, 0)) == 0) {
i = len;
}
done = 1;
break;
case 'e':
if ((diffs = erode5(out, width, height, common_buffer, 0)) == 0)
if ((diffs = erode5(out, width, height, common_buffer, 0)) == 0) {
i = len;
}
done = 1;
break;
case 'D':
@@ -875,8 +903,9 @@ int alg_despeckle(struct context *cnt, int olddiffs)
/* If conf.despeckle_filter contains any valid action EeDdl */
if (done) {
if (done != 2)
if (done != 2) {
cnt->imgs.labelsize_max = 0; // Disable Labeling
}
return diffs;
} else {
cnt->imgs.labelsize_max = 0; // Disable Labeling
@@ -900,23 +929,26 @@ void alg_tune_smartmask(struct context *cnt)
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;
if (diff) {
if (smartmask[i] <= diff + 80)
if (smartmask[i] <= diff + 80) {
smartmask[i] += diff;
else
} else {
smartmask[i] = 80;
}
smartmask_buffer[i] %= sensitivity;
}
/* Transfer raw mask to the final stage when above trigger value. */
if (smartmask[i] > 20)
if (smartmask[i] > 20) {
smartmask_final[i] = 0;
else
} else {
smartmask_final[i] = 255;
}
}
/* Further expansion (here:erode due to inverted logic!) of the mask. */
diff = erode9(smartmask_final, cnt->imgs.width, cnt->imgs.height,
@@ -1096,15 +1128,32 @@ int alg_diff_standard(struct context *cnt, unsigned char *new)
movq_r2r(mm3, mm0); /* U */
/* Add to *smartmask_buffer. This is probably the fastest way to do it. */
/* TODO: Revise this to use a loop */
if (cnt->event_nr != cnt->prev_event) {
if (mmtemp.ub[0]) smartmask_buffer[0] += SMARTMASK_SENSITIVITY_INCR;
if (mmtemp.ub[1]) smartmask_buffer[1] += SMARTMASK_SENSITIVITY_INCR;
if (mmtemp.ub[2]) smartmask_buffer[2] += SMARTMASK_SENSITIVITY_INCR;
if (mmtemp.ub[3]) smartmask_buffer[3] += SMARTMASK_SENSITIVITY_INCR;
if (mmtemp.ub[4]) smartmask_buffer[4] += SMARTMASK_SENSITIVITY_INCR;
if (mmtemp.ub[5]) smartmask_buffer[5] += SMARTMASK_SENSITIVITY_INCR;
if (mmtemp.ub[6]) smartmask_buffer[6] += SMARTMASK_SENSITIVITY_INCR;
if (mmtemp.ub[7]) smartmask_buffer[7] += SMARTMASK_SENSITIVITY_INCR;
if (mmtemp.ub[0]) {
smartmask_buffer[0] += SMARTMASK_SENSITIVITY_INCR;
}
if (mmtemp.ub[1]) {
smartmask_buffer[1] += SMARTMASK_SENSITIVITY_INCR;
}
if (mmtemp.ub[2]) {
smartmask_buffer[2] += SMARTMASK_SENSITIVITY_INCR;
}
if (mmtemp.ub[3]) {
smartmask_buffer[3] += SMARTMASK_SENSITIVITY_INCR;
}
if (mmtemp.ub[4]) {
smartmask_buffer[4] += SMARTMASK_SENSITIVITY_INCR;
}
if (mmtemp.ub[5]) {
smartmask_buffer[5] += SMARTMASK_SENSITIVITY_INCR;
}
if (mmtemp.ub[6]) {
smartmask_buffer[6] += SMARTMASK_SENSITIVITY_INCR;
}
if (mmtemp.ub[7]) {
smartmask_buffer[7] += SMARTMASK_SENSITIVITY_INCR;
}
}
smartmask_buffer += 8;
@@ -1168,8 +1217,9 @@ int alg_diff_standard(struct context *cnt, unsigned char *new)
for (; i > 0; i--) {
register unsigned char curdiff = (int)(abs(*ref - *new)); /* Using a temp variable is 12% faster. */
/* Apply fixed mask */
if (mask)
if (mask) {
curdiff = ((int)(curdiff * *mask++) / 255);
}
if (smartmask_speed) {
if (curdiff > noise) {
@@ -1180,11 +1230,13 @@ int alg_diff_standard(struct context *cnt, unsigned char *new)
* speed=10) we add 5 here. NOT related to the 5 at ratio-
* calculation.
*/
if (cnt->event_nr != cnt->prev_event)
if (cnt->event_nr != cnt->prev_event) {
(*smartmask_buffer) += SMARTMASK_SENSITIVITY_INCR;
}
/* Apply smart_mask */
if (!*smartmask_final)
if (!*smartmask_final) {
curdiff = 0;
}
}
smartmask_final++;
smartmask_buffer++;
@@ -1212,8 +1264,9 @@ static char alg_diff_fast(struct context *cnt, int max_n_changes, unsigned char
int noise = cnt->noise;
unsigned char *ref = imgs->ref;
if (!step % 2)
if (!step % 2) {
step++;
}
/* We're checking only 1 of several pixels. */
max_n_changes /= step;
@@ -1223,8 +1276,9 @@ static char alg_diff_fast(struct context *cnt, int max_n_changes, unsigned char
register unsigned char curdiff = (int)(abs((char)(*ref - *new))); /* Using a temp variable is 12% faster. */
if (curdiff > noise) {
diffs++;
if (diffs > max_n_changes)
if (diffs > max_n_changes) {
return 1;
}
}
ref += step;
new += step;
@@ -1242,8 +1296,9 @@ int alg_diff(struct context *cnt, unsigned char *new)
{
int diffs = 0;
if (alg_diff_fast(cnt, cnt->conf.threshold / 2, new))
if (alg_diff_fast(cnt, cnt->conf.threshold / 2, new)) {
diffs = alg_diff_standard(cnt, new);
}
return diffs;
}
@@ -1258,14 +1313,17 @@ int alg_lightswitch(struct context *cnt, int diffs)
{
struct images *imgs = &cnt->imgs;
if (cnt->conf.lightswitch_percent < 0)
if (cnt->conf.lightswitch_percent < 0) {
cnt->conf.lightswitch_percent = 0;
if (cnt->conf.lightswitch_percent > 100)
}
if (cnt->conf.lightswitch_percent > 100) {
cnt->conf.lightswitch_percent = 100;
}
/* Is lightswitch percent of the image changed? */
if (diffs > (imgs->motionsize * cnt->conf.lightswitch_percent / 100))
if (diffs > (imgs->motionsize * cnt->conf.lightswitch_percent / 100)) {
return 1;
}
return 0;
}
@@ -1284,15 +1342,18 @@ int alg_switchfilter(struct context *cnt, int diffs, unsigned char *newimg)
for (y = 0; y < cnt->imgs.height; y++) {
line = 0;
for (x = 0; x < cnt->imgs.width; x++) {
if (*(out++))
if (*(out++)) {
line++;
}
}
if (line > cnt->imgs.width / 18)
if (line > cnt->imgs.width / 18) {
vertlines++;
}
if (line > linediff * 2)
if (line > linediff * 2) {
lines++;
}
}
if (vertlines > cnt->imgs.height / 10 && lines < vertlines / 3 &&
@@ -1332,8 +1393,10 @@ void alg_update_reference_frame(struct context *cnt, int action)
unsigned char *smartmask = cnt->imgs.smartmask_final;
unsigned char *out = cnt->imgs.img_motion.image_norm;
if (cnt->lastrate > 5) /* Match rate limit */
/* Match rate limit */
if (cnt->lastrate > 5) {
accept_timer /= (cnt->lastrate / 3);
}
if (action == UPDATE_REF_FRAME) { /* Black&white only for better performance. */
threshold_ref = cnt->noise * EXCLUDE_LEVEL_PERCENT / 100;

View File

@@ -2043,11 +2043,12 @@ static void conf_cmdline(struct context *cnt, int thread)
* if necessary. This is accomplished by calling mystrcpy();
* see this function for more information.
*/
while ((c = getopt(conf->argc, conf->argv, "bc:d:hmns?p:k:l:")) != EOF)
while ((c = getopt(conf->argc, conf->argv, "bc:d:hmns?p:k:l:")) != EOF) {
switch (c) {
case 'c':
if (thread == -1)
if (thread == -1) {
strcpy(cnt->conf_filename, optarg);
}
break;
case 'b':
cnt->daemon = 1;
@@ -2060,8 +2061,9 @@ static void conf_cmdline(struct context *cnt, int thread)
break;
case 'd':
/* No validation - just take what user gives. */
if (thread == -1)
if (thread == -1) {
cnt->log_level = (unsigned int)atoi(optarg);
}
break;
case 'k':
if (thread == -1) {
@@ -2090,6 +2092,7 @@ static void conf_cmdline(struct context *cnt, int thread)
usage();
exit(1);
}
}
optind = 1;
}
@@ -2109,7 +2112,9 @@ struct context **conf_cmdparse(struct context **cnt, const char *cmd, const char
{
unsigned int i = 0;
if (!cmd) return cnt;
if (!cmd) {
return cnt;
}
/*
* We search through config_params until we find a param_name that matches
@@ -2120,7 +2125,7 @@ struct context **conf_cmdparse(struct context **cnt, const char *cmd, const char
/* If config_param is string we don't want to check arg1. */
if (strcasecmp(config_type(&config_params[i]), "string")) {
if (config_params[i].conf_value && !arg1){
if (config_params[i].conf_value && !arg1) {
return cnt;
}
}
@@ -2154,7 +2159,7 @@ struct context **conf_cmdparse(struct context **cnt, const char *cmd, const char
MOTION_LOG(ALR, TYPE_ALL, NO_ERRNO, _("%s after version %s")
, dep_config_params[i].info, dep_config_params[i].last_version);
if (dep_config_params[i].copy != NULL){
if (dep_config_params[i].copy != NULL) {
/* If the depreciated option is a vid item, copy_video_params is called
* with the array index sent instead of the context structure member pointer.
*/
@@ -2167,8 +2172,7 @@ struct context **conf_cmdparse(struct context **cnt, const char *cmd, const char
!strcmp(dep_config_params[i].name,"input") ||
!strcmp(dep_config_params[i].name,"norm") ||
!strcmp(dep_config_params[i].name,"frequency") ||
!strcmp(dep_config_params[i].name,"vid_control_params") )
{
!strcmp(dep_config_params[i].name,"vid_control_params")) {
cnt = copy_video_params(cnt, arg1, i);
} else if (!strcmp(dep_config_params[i].name,"netcam_decoder") ||
@@ -2178,8 +2182,7 @@ struct context **conf_cmdparse(struct context **cnt, const char *cmd, const char
!strcmp(dep_config_params[i].name,"netcam_ratehigh") ||
!strcmp(dep_config_params[i].name,"netcam_proxy") ||
!strcmp(dep_config_params[i].name,"netcam_tolerant_check") ||
!strcmp(dep_config_params[i].name,"netcam_keepalive") )
{
!strcmp(dep_config_params[i].name,"netcam_keepalive")) {
cnt = copy_netcam_params(cnt, arg1, i);
} else {
@@ -2218,31 +2221,35 @@ static struct context **conf_process(struct context **cnt, FILE *fp)
char *beg = NULL, *end = NULL;
while (fgets(line, PATH_MAX-1, fp)) {
if (!(line[0] == '#' || line[0] == ';' || strlen(line) < 2)) {/* skipcomment */
if (!(line[0] == '#' || line[0] == ';' || strlen(line) < 2)) {
/* skipcomment */
arg1 = NULL;
/* 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 line is only whitespace we continue to the next line. */
if (strlen(line) == 0)
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. */
@@ -2250,8 +2257,9 @@ static struct context **conf_process(struct context **cnt, FILE *fp)
beg++;
if (strlen(beg) > 0) {
while (*beg == ' ' || *beg == '\t' || *beg == '=' || *beg == '\n' || *beg == '\r')
while (*beg == ' ' || *beg == '\t' || *beg == '=' || *beg == '\n' || *beg == '\r') {
beg++;
}
/*
@@ -2297,8 +2305,9 @@ void conf_print(struct context **cnt)
conffile = myfopen(cnt[thread]->conf_filename, "w");
if (!conffile)
if (!conffile) {
continue;
}
char timestamp[32];
time_t now = time(0);
@@ -2318,10 +2327,11 @@ void conf_print(struct context **cnt)
* If the option is a text_* and first char is a space put
* quotation marks around to allow leading spaces.
*/
if (strncmp(config_params[i].param_name, "text", 4) || strncmp(retval, " ", 1))
if (strncmp(config_params[i].param_name, "text", 4) || strncmp(retval, " ", 1)) {
fprintf(conffile, "%s %s\n\n", config_params[i].param_name, retval);
else
} else {
fprintf(conffile, "%s \"%s\"\n\n", config_params[i].param_name, retval);
}
} else {
val = NULL;
config_params[i].print(cnt, &val, i, thread);
@@ -2334,19 +2344,21 @@ void conf_print(struct context **cnt)
if (val) {
fprintf(conffile, "%s\n", config_params[i].param_help);
if (strlen(val) > 0)
if (strlen(val) > 0) {
fprintf(conffile, "%s\n", val);
else
} else {
fprintf(conffile, "; camera %s/camera1.conf\n", sysconfdir);
}
free(val);
} else if (thread == 0) {
char value[PATH_MAX];
/* The 'camera_dir' option should keep the installed default value */
if (!strncmp(config_params[i].param_name, "camera_dir", 10))
if (!strncmp(config_params[i].param_name, "camera_dir", 10)) {
sprintf(value, "%s", sysconfdir"/conf.d");
else
} else {
sprintf(value, "%s", "value");
}
fprintf(conffile, "%s\n", config_params[i].param_help);
fprintf(conffile, "; %s %s\n\n", config_params[i].param_name, value);
@@ -2427,19 +2439,21 @@ struct context **conf_load(struct context **cnt)
conf_cmdline(cnt[0], -1);
if (cnt[0]->conf_filename[0]) { /* User has supplied filename on Command-line. */
strncpy(filename, cnt[0]->conf_filename, PATH_MAX-1);
filename[PATH_MAX-1] = '\0';
fp = fopen (filename, "r");
if (cnt[0]->conf_filename[0]) {
/* User has supplied filename on Command-line. */
strncpy(filename, cnt[0]->conf_filename, PATH_MAX-1);
filename[PATH_MAX-1] = '\0';
fp = fopen (filename, "r");
}
if (!fp) { /* Command-line didn't work, try current dir. */
char path[PATH_MAX];
if (cnt[0]->conf_filename[0])
if (cnt[0]->conf_filename[0]) {
MOTION_LOG(ALR, TYPE_ALL, SHOW_ERRNO
,_("Configfile %s not found - trying defaults.")
,filename);
}
if (getcwd(path, sizeof(path)) == NULL) {
MOTION_LOG(ERR, TYPE_ALL, SHOW_ERRNO, _("Error getcwd"));
@@ -2460,10 +2474,11 @@ struct context **conf_load(struct context **cnt)
snprintf(filename, PATH_MAX, "%s/motion.conf", sysconfdir);
fp = fopen(filename, "r");
if (!fp) /* There is no config file.... use defaults. */
if (!fp) { /* There is no config file.... use defaults. */
MOTION_LOG(ALR, TYPE_ALL, SHOW_ERRNO
,_("could not open configfile %s")
,filename);
}
}
}
@@ -2472,7 +2487,7 @@ struct context **conf_load(struct context **cnt)
retcd = snprintf(cnt[0]->conf_filename
,sizeof(cnt[0]->conf_filename)
,"%s",filename);
if ((retcd < 0) || (retcd >= (int)sizeof(cnt[0]->conf_filename))){
if ((retcd < 0) || (retcd >= (int)sizeof(cnt[0]->conf_filename))) {
MOTION_LOG(NTC, TYPE_ALL, NO_ERRNO
,_("Invalid file name %s"), filename);
} else {
@@ -2498,24 +2513,29 @@ struct context **conf_load(struct context **cnt)
*/
i = -1;
while (cnt[++i])
while (cnt[++i]) {
conf_cmdline(cnt[i], i);
}
/* If pid file was passed from Command-line copy to main thread conf struct. */
if (cnt[0]->pid_file[0])
if (cnt[0]->pid_file[0]) {
cnt[0]->conf.pid_file = mystrcpy(cnt[0]->conf.pid_file, cnt[0]->pid_file);
}
/* If log file was passed from Command-line copy to main thread conf struct. */
if (cnt[0]->log_file[0])
if (cnt[0]->log_file[0]) {
cnt[0]->conf.log_file = mystrcpy(cnt[0]->conf.log_file, cnt[0]->log_file);
}
/* If log type string was passed from Command-line copy to main thread conf struct. */
if (cnt[0]->log_type_str[0])
if (cnt[0]->log_type_str[0]) {
cnt[0]->conf.log_type = mystrcpy(cnt[0]->conf.log_type, cnt[0]->log_type_str);
}
/* if log level was passed from Command-line copy to main thread conf struct. */
if (cnt[0]->log_level != -1)
if (cnt[0]->log_level != -1) {
cnt[0]->conf.log_level = cnt[0]->log_level;
}
config_parms_intl();
@@ -2536,7 +2556,9 @@ void conf_output_parms(struct context **cnt)
unsigned int i, t = 0;
const char *name, *value;
while(cnt[++t]);
while(cnt[++t]) {
continue;
}
MOTION_LOG(INF, TYPE_ALL, NO_ERRNO
,_("Writing configuration parameters from all files (%d):"), t);
@@ -2557,18 +2579,21 @@ void conf_output_parms(struct context **cnt)
!strncmp(name, "webcontrol_key", 14) ||
!strncmp(name, "webcontrol_cert", 15) ||
!strncmp(name, "database_user", 13) ||
!strncmp(name, "database_password", 17))
{
!strncmp(name, "database_password", 17)) {
motion_log(INF, TYPE_ALL, NO_ERRNO,0
,_("%-25s <redacted>"), name);
} else {
if (strncmp(name, "text", 4) || strncmp(value, " ", 1))
if (strncmp(name, "text", 4) || strncmp(value, " ", 1)) {
motion_log(INF, TYPE_ALL, NO_ERRNO,0, "%-25s %s", name, value);
else
} else {
motion_log(INF, TYPE_ALL, NO_ERRNO,0, "%-25s \"%s\"", name, value);
}
}
} else {
if (t == 0) motion_log(INF, TYPE_ALL, NO_ERRNO,0, "%-25s ", name);
if (t == 0) {
motion_log(INF, TYPE_ALL, NO_ERRNO,0, "%-25s ", name);
}
}
i++;
}
@@ -2593,7 +2618,8 @@ void malloc_strings(struct context *cnt)
char **val;
while (config_params[i].param_name != NULL) {
if (config_params[i].copy == copy_string ||
config_params[i].copy == copy_uri) { /* if member is a string */
config_params[i].copy == copy_uri) {
/* if member is a string */
/* val is made to point to a pointer to the current string. */
val = (char **)((char *)cnt+config_params[i].conf_value);
@@ -2656,8 +2682,9 @@ static struct context **copy_bool(struct context **cnt, const char *str, int val
*((int *)tmp) = 0;
}
if (cnt[0]->threadnr)
if (cnt[0]->threadnr) {
return cnt;
}
}
return cnt;
@@ -2686,8 +2713,9 @@ static struct context **copy_int(struct context **cnt, const char *str, int val_
} else {
*((int *)tmp) = atoi(str);
}
if (cnt[0]->threadnr)
if (cnt[0]->threadnr) {
return cnt;
}
}
return cnt;
@@ -2724,8 +2752,9 @@ struct context **copy_string(struct context **cnt, const char *str, int val_ptr)
* Set the option on all threads if setting the option
* for thread 0; otherwise just set that one thread's option.
*/
if (cnt[0]->threadnr)
if (cnt[0]->threadnr) {
return cnt;
}
}
return cnt;
@@ -2745,17 +2774,19 @@ static struct context **copy_video_params(struct context **cnt, const char *conf
indx_vid = 0;
while (config_params[indx_vid].param_name != NULL) {
if (!strcmp(config_params[indx_vid].param_name,"video_params")) break;
if (!strcmp(config_params[indx_vid].param_name,"video_params")) {
break;
}
indx_vid++;
}
if (strcmp(config_params[indx_vid].param_name,"video_params")){
if (strcmp(config_params[indx_vid].param_name,"video_params")) {
MOTION_LOG(ALR, TYPE_ALL, NO_ERRNO
,_("Unable to locate video_params"));
return cnt;
}
if (config_val == NULL){
if (config_val == NULL) {
MOTION_LOG(ALR, TYPE_ALL, NO_ERRNO
,_("No value provided to put into video_params"));
}
@@ -2763,9 +2794,14 @@ static struct context **copy_video_params(struct context **cnt, const char *conf
/* If the depreciated option is the default, then just return */
parmval = atoi(config_val);
if (!strcmp(dep_config_params[config_indx].name,"power_line_frequency") &&
(parmval == -1)) return cnt;
(parmval == -1)) {
return cnt;
}
if (strcmp(dep_config_params[config_indx].name,"power_line_frequency") &&
(parmval == 0)) return cnt;
(parmval == 0)) {
return cnt;
}
/* Remove underscore from parm name and add quotes*/
if (!strcmp(dep_config_params[config_indx].name,"power_line_frequency")) {
@@ -2828,17 +2864,19 @@ static struct context **copy_netcam_params(struct context **cnt, const char *con
indx = 0;
while (config_params[indx].param_name != NULL) {
if (!strcmp(config_params[indx].param_name,"netcam_params")) break;
if (!strcmp(config_params[indx].param_name,"netcam_params")) {
break;
}
indx++;
}
if (strcmp(config_params[indx].param_name,"netcam_params")){
if (strcmp(config_params[indx].param_name,"netcam_params")) {
MOTION_LOG(ALR, TYPE_ALL, NO_ERRNO
,_("Unable to locate netcam_params"));
return cnt;
}
if (config_val == NULL){
if (config_val == NULL) {
MOTION_LOG(ALR, TYPE_ALL, NO_ERRNO
,_("No value provided to put into netcam_params"));
return cnt;
@@ -2846,8 +2884,7 @@ static struct context **copy_netcam_params(struct context **cnt, const char *con
/* Remove underscore from parm name and add quotes*/
if (!strcmp(dep_config_params[config_indx].name,"netcam_use_tcp") ||
!strcmp(dep_config_params[config_indx].name,"rtsp_uses_tcp"))
{
!strcmp(dep_config_params[config_indx].name,"rtsp_uses_tcp")) {
parm_len = strlen("rtsp_transport = tcp") + 1;
parm_new = mymalloc(parm_len);
if ( !strcmp(config_val,"on")) {
@@ -2862,8 +2899,7 @@ static struct context **copy_netcam_params(struct context **cnt, const char *con
snprintf(parm_new, parm_len, "%s%s", "decoder = ", config_val);
} else if (!strcmp(dep_config_params[config_indx].name,"netcam_rate") ||
!strcmp(dep_config_params[config_indx].name,"netcam_ratehigh"))
{
!strcmp(dep_config_params[config_indx].name,"netcam_ratehigh")) {
parm_len = strlen("capture_rate = ") + strlen(config_val) + 1;
parm_new = mymalloc(parm_len);
snprintf(parm_new, parm_len, "%s%s", "capture_rate = ", config_val);
@@ -2890,7 +2926,7 @@ static struct context **copy_netcam_params(struct context **cnt, const char *con
/* Recall that the current parms have already been processed by time this is called */
i = -1;
while (cnt[++i]) {
if (!strcmp(dep_config_params[config_indx].name,"netcam_ratehigh")){
if (!strcmp(dep_config_params[config_indx].name,"netcam_ratehigh")) {
if (cnt[i]->conf.netcam_high_params != NULL) {
parm_len = strlen(cnt[i]->conf.netcam_high_params) + 1;
orig_parm = mymalloc(parm_len);
@@ -2955,8 +2991,9 @@ static struct context **copy_text_double(struct context **cnt, const char *str,
*((int *)tmp) = 1;
}
if (cnt[0]->threadnr)
if (cnt[0]->threadnr) {
return cnt;
}
}
return cnt;
@@ -2983,8 +3020,9 @@ static struct context **copy_html_output(struct context **cnt, const char *str,
*((int *)tmp) = 1;
}
if (cnt[0]->threadnr)
if (cnt[0]->threadnr) {
return cnt;
}
}
return cnt;
@@ -3043,8 +3081,9 @@ char *mystrcpy(char *to, const char *from)
* same value as from.
*/
if (to != NULL)
if (to != NULL) {
free(to);
}
return mystrdup(from);
}
@@ -3093,14 +3132,18 @@ char *mystrdup(const char *from)
*/
const char *config_type(config_param *configparam)
{
if (configparam->copy == copy_string)
if (configparam->copy == copy_string) {
return "string";
if (configparam->copy == copy_int)
}
if (configparam->copy == copy_int) {
return "int";
if (configparam->copy == copy_bool)
}
if (configparam->copy == copy_bool) {
return "bool";
if (configparam->copy == copy_uri)
}
if (configparam->copy == copy_uri) {
return "uri";
}
return "unknown";
}
@@ -3117,14 +3160,15 @@ static const char *print_bool(struct context **cnt, char **str ATTRIBUTE_UNUSED,
{
int val = config_params[parm].conf_value;
if (threadnr &&
*(int*)((char *)cnt[threadnr] + val) == *(int*)((char *)cnt[0] + val))
if (threadnr && *(int*)((char *)cnt[threadnr] + val) == *(int*)((char *)cnt[0] + val)) {
return NULL;
}
if (*(int*)((char *)cnt[threadnr] + val))
if (*(int*)((char *)cnt[threadnr] + val)) {
return "on";
else
} else {
return "off";
}
}
/**
@@ -3148,8 +3192,9 @@ static const char *print_string(struct context **cnt,
cptr0 = (const char **)((char *)cnt[0] + val);
cptr1 = (const char **)((char *)cnt[threadnr] + val);
if ((threadnr) && (*cptr0 != NULL) && (*cptr1 != NULL) && (!strcmp(*cptr0, *cptr1)))
if ((threadnr) && (*cptr0 != NULL) && (*cptr1 != NULL) && (!strcmp(*cptr0, *cptr1))) {
return NULL;
}
return *cptr1;
}
@@ -3170,9 +3215,9 @@ static const char *print_int(struct context **cnt, char **str ATTRIBUTE_UNUSED,
static char retval[20];
int val = config_params[parm].conf_value;
if (threadnr &&
*(int*)((char *)cnt[threadnr] + val) == *(int*)((char *)cnt[0] + val))
if (threadnr && *(int*)((char *)cnt[threadnr] + val) == *(int*)((char *)cnt[0] + val)) {
return NULL;
}
sprintf(retval, "%d", *(int*)((char *)cnt[threadnr] + val));
@@ -3192,16 +3237,18 @@ static const char *print_camera(struct context **cnt, char **str,
char *retval;
unsigned int i = 0;
if (!str || threadnr)
if (!str || threadnr) {
return NULL;
}
retval = mymalloc(1);
retval[0] = 0;
while (cnt[++i]) {
/* Skip config files loaded from conf directory */
if (cnt[i]->from_conf_dir)
if (cnt[i]->from_conf_dir) {
continue;
}
retval = myrealloc(retval, strlen(retval) + strlen(cnt[i]->conf_filename) + 10,
"print_camera");
@@ -3229,18 +3276,12 @@ struct context **read_camera_dir(struct context **cnt, const char *str, int val)
char conf_file[PATH_MAX];
dp = opendir(str);
if (dp != NULL)
{
while( (ep = readdir(dp)) )
{
if (dp != NULL) {
while( (ep = readdir(dp)) ) {
name_len = strlen(ep->d_name);
if (name_len > strlen(EXTENSION) &&
(strncmp(EXTENSION,
(ep->d_name + name_len - strlen(EXTENSION)),
strlen(EXTENSION)) == 0
)
)
{
(strncmp(EXTENSION,(ep->d_name + name_len - strlen(EXTENSION)),
strlen(EXTENSION)) == 0 )) {
memset(conf_file, '\0', sizeof(conf_file));
snprintf(conf_file, sizeof(conf_file) - 1, "%s/%s",
str, ep->d_name);
@@ -3251,14 +3292,14 @@ struct context **read_camera_dir(struct context **cnt, const char *str, int val)
* set it as created from conf directory.
*/
i = 0;
while (cnt[++i]);
while (cnt[++i]) {
continue;
}
cnt[i-1]->from_conf_dir = 1;
}
}
}
closedir(dp);
}
else
{
} else {
MOTION_LOG(ALR, TYPE_ALL, SHOW_ERRNO
,_("Camera directory config %s not found"), str);
return cnt;
@@ -3288,8 +3329,9 @@ static struct context **config_camera(struct context **cnt, const char *str,
int i;
FILE *fp;
if (cnt[0]->threadnr)
if (cnt[0]->threadnr) {
return cnt;
}
fp = fopen(str, "r");
@@ -3302,7 +3344,9 @@ static struct context **config_camera(struct context **cnt, const char *str,
/* Find the current number of threads defined. */
i = -1;
while (cnt[++i]);
while (cnt[++i]) {
continue;
}
/*
* Make space for the threads + the terminating NULL pointer
@@ -3379,7 +3423,7 @@ static void config_parms_intl()
* it will be printed when called from the conf_load.
*/
if (FALSE){
if (FALSE) {
MOTION_LOG(DBG, TYPE_ALL, NO_ERRNO,"%s:%s","daemon",_("daemon"));
MOTION_LOG(DBG, TYPE_ALL, NO_ERRNO,"%s:%s","setup_mode",_("setup_mode"));
MOTION_LOG(DBG, TYPE_ALL, NO_ERRNO,"%s:%s","pid_file",_("pid_file"));

View File

@@ -1076,13 +1076,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);
@@ -1092,7 +1096,9 @@ static int draw_textn(unsigned char *image, int startx, int starty, int width,
for (pos = 0; pos < len; pos++) {
int pos_check = (int)text[pos];
if ((pos_check <0) || (pos_check >127)) pos_check = 45; /* Use a - for non ascii characters*/
if ((pos_check <0) || (pos_check >127)) {
pos_check = 45; /* Use a - for non ascii characters*/
}
char_ptr = char_arr_ptr[pos_check];
@@ -1134,24 +1140,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;

View File

@@ -89,8 +89,9 @@ static void exec_command(struct context *cnt, char *command, char *filename, int
* Close any file descriptor except console because we will
* like to see error messages
*/
for (i = getdtablesize() - 1; i > 2; i--)
for (i = getdtablesize() - 1; i > 2; i--) {
close(i);
}
execl("/bin/sh", "sh", "-c", stamp, " &", NULL);
@@ -126,8 +127,9 @@ static void event_beep(struct context *cnt, motion_event type ATTRIBUTE_UNUSED,
void *ftype ATTRIBUTE_UNUSED,
struct timeval *tv1 ATTRIBUTE_UNUSED)
{
if (!cnt->conf.quiet)
if (!cnt->conf.quiet) {
printf("\a");
}
}
/**
@@ -145,11 +147,13 @@ static void on_picture_save_command(struct context *cnt,
{
int filetype = (unsigned long)arg;
if ((filetype & FTYPE_IMAGE_ANY) != 0 && cnt->conf.on_picture_save)
if ((filetype & FTYPE_IMAGE_ANY) != 0 && cnt->conf.on_picture_save) {
exec_command(cnt, cnt->conf.on_picture_save, filename, filetype);
}
if ((filetype & FTYPE_MPEG_ANY) != 0 && cnt->conf.on_movie_start)
if ((filetype & FTYPE_MPEG_ANY) != 0 && cnt->conf.on_movie_start) {
exec_command(cnt, cnt->conf.on_movie_start, filename, filetype);
}
}
static void on_motion_detected_command(struct context *cnt,
@@ -158,8 +162,9 @@ static void on_motion_detected_command(struct context *cnt,
char *dummy2 ATTRIBUTE_UNUSED, void *dummy3 ATTRIBUTE_UNUSED,
struct timeval *tv1 ATTRIBUTE_UNUSED)
{
if (cnt->conf.on_motion_detected)
if (cnt->conf.on_motion_detected) {
exec_command(cnt, cnt->conf.on_motion_detected, NULL, 0);
}
}
#if defined(HAVE_MYSQL) || defined(HAVE_PGSQL) || defined(HAVE_SQLITE3) || defined(HAVE_MARIADB)
@@ -309,8 +314,9 @@ static void event_sqlnewfile(struct context *cnt, motion_event type ATTRIBUTE_U
int sqltype = (unsigned long)arg;
/* Only log the file types we want */
if (!(cnt->conf.database_type) || (sqltype & cnt->sql_mask) == 0)
if (!(cnt->conf.database_type) || (sqltype & cnt->sql_mask) == 0) {
return;
}
/*
* We place the code in a block so we only spend time making space in memory
@@ -333,8 +339,9 @@ static void event_sqlfileclose(struct context *cnt, motion_event type ATTRIBUTE
int sqltype = (unsigned long)arg;
/* Only log the file types we want */
if (!(cnt->conf.database_type) || (sqltype & cnt->sql_mask) == 0)
if (!(cnt->conf.database_type) || (sqltype & cnt->sql_mask) == 0) {
return;
}
/*
* We place the code in a block so we only spend time making space in memory
@@ -358,8 +365,9 @@ static void on_area_command(struct context *cnt,
char *dummy2 ATTRIBUTE_UNUSED, void *dummy3 ATTRIBUTE_UNUSED,
struct timeval *tv1 ATTRIBUTE_UNUSED)
{
if (cnt->conf.on_area_detected)
if (cnt->conf.on_area_detected) {
exec_command(cnt, cnt->conf.on_area_detected, NULL, 0);
}
}
static void on_event_start_command(struct context *cnt,
@@ -368,8 +376,9 @@ static void on_event_start_command(struct context *cnt,
char *dummy2 ATTRIBUTE_UNUSED, void *dummy3 ATTRIBUTE_UNUSED,
struct timeval *tv1 ATTRIBUTE_UNUSED)
{
if (cnt->conf.on_event_start)
if (cnt->conf.on_event_start) {
exec_command(cnt, cnt->conf.on_event_start, NULL, 0);
}
}
static void on_event_end_command(struct context *cnt,
@@ -378,8 +387,9 @@ static void on_event_end_command(struct context *cnt,
char *dummy2 ATTRIBUTE_UNUSED, void *dummy3 ATTRIBUTE_UNUSED,
struct timeval *tv1 ATTRIBUTE_UNUSED)
{
if (cnt->conf.on_event_end)
if (cnt->conf.on_event_end) {
exec_command(cnt, cnt->conf.on_event_end, NULL, 0);
}
}
static void event_stream_put(struct context *cnt,
@@ -391,11 +401,11 @@ static void event_stream_put(struct context *cnt,
pthread_mutex_lock(&cnt->mutex_stream);
/* Normal stream processing */
if (cnt->stream_norm.cnct_count > 0){
if (cnt->stream_norm.jpeg_data == NULL){
if (cnt->stream_norm.cnct_count > 0) {
if (cnt->stream_norm.jpeg_data == NULL) {
cnt->stream_norm.jpeg_data = mymalloc(cnt->imgs.size_norm);
}
if (img_data->image_norm != NULL){
if (img_data->image_norm != NULL) {
cnt->stream_norm.jpeg_size = put_picture_memory(cnt
,cnt->stream_norm.jpeg_data
,cnt->imgs.size_norm
@@ -407,17 +417,16 @@ static void event_stream_put(struct context *cnt,
}
/* Substream processing */
if (cnt->stream_sub.cnct_count > 0){
if (cnt->stream_sub.jpeg_data == NULL){
if (cnt->stream_sub.cnct_count > 0) {
if (cnt->stream_sub.jpeg_data == NULL) {
cnt->stream_sub.jpeg_data = mymalloc(cnt->imgs.size_norm);
}
if (img_data->image_norm != NULL){
if (img_data->image_norm != NULL) {
/* Resulting substream image must be multiple of 8 */
if (((cnt->imgs.width % 16) == 0) &&
((cnt->imgs.height % 16) == 0)) {
subsize = ((cnt->imgs.width / 2) * (cnt->imgs.height / 2) * 3 / 2);
if (cnt->imgs.substream_image == NULL){
if (cnt->imgs.substream_image == NULL) {
cnt->imgs.substream_image = mymalloc(subsize);
}
pic_scale_img(cnt->imgs.width
@@ -445,11 +454,11 @@ static void event_stream_put(struct context *cnt,
}
/* Motion stream processing */
if (cnt->stream_motion.cnct_count > 0){
if (cnt->stream_motion.jpeg_data == NULL){
if (cnt->stream_motion.cnct_count > 0) {
if (cnt->stream_motion.jpeg_data == NULL) {
cnt->stream_motion.jpeg_data = mymalloc(cnt->imgs.size_norm);
}
if (cnt->imgs.img_motion.image_norm != NULL){
if (cnt->imgs.img_motion.image_norm != NULL) {
cnt->stream_motion.jpeg_size = put_picture_memory(cnt
,cnt->stream_motion.jpeg_data
,cnt->imgs.size_norm
@@ -461,11 +470,11 @@ static void event_stream_put(struct context *cnt,
}
/* Source stream processing */
if (cnt->stream_source.cnct_count > 0){
if (cnt->stream_source.jpeg_data == NULL){
if (cnt->stream_source.cnct_count > 0) {
if (cnt->stream_source.jpeg_data == NULL) {
cnt->stream_source.jpeg_data = mymalloc(cnt->imgs.size_norm);
}
if (cnt->imgs.image_virgin.image_norm != NULL){
if (cnt->imgs.image_virgin.image_norm != NULL) {
cnt->stream_source.jpeg_size = put_picture_memory(cnt
,cnt->stream_source.jpeg_data
,cnt->imgs.size_norm
@@ -487,20 +496,23 @@ static void event_vlp_putpipe(struct context *cnt,
struct timeval *tv1 ATTRIBUTE_UNUSED)
{
if (*(int *)devpipe >= 0) {
if (vlp_putpipe(*(int *)devpipe, img_data->image_norm, cnt->imgs.size_norm) == -1)
if (vlp_putpipe(*(int *)devpipe, img_data->image_norm, cnt->imgs.size_norm) == -1) {
MOTION_LOG(ERR, TYPE_EVENTS, SHOW_ERRNO
,_("Failed to put image into video pipe"));
}
}
}
#endif /* defined(HAVE_V4L2) && !defined(BSD) */
const char *imageext(struct context *cnt)
{
if (cnt->imgs.picture_type == IMAGE_TYPE_PPM)
if (cnt->imgs.picture_type == IMAGE_TYPE_PPM) {
return "ppm";
}
if (cnt->imgs.picture_type == IMAGE_TYPE_WEBP)
if (cnt->imgs.picture_type == IMAGE_TYPE_WEBP) {
return "webp";
}
return "jpg";
}
@@ -521,10 +533,11 @@ static void event_image_detect(struct context *cnt,
* conf.imagepath would normally be defined but if someone deleted it by control interface
* it is better to revert to the default than fail
*/
if (cnt->conf.picture_filename)
if (cnt->conf.picture_filename) {
imagepath = cnt->conf.picture_filename;
else
} else {
imagepath = DEF_IMAGEPATH;
}
mystrftime(cnt, filename, sizeof(filename), imagepath, currenttime_tv, NULL, 0);
snprintf(fullfilename, PATH_MAX, "%.*s/%.*s.%s"
@@ -560,10 +573,11 @@ static void event_imagem_detect(struct context *cnt,
* conf.picture_filename would normally be defined but if someone deleted it by control interface
* it is better to revert to the default than fail
*/
if (cnt->conf.picture_filename)
if (cnt->conf.picture_filename) {
imagepath = cnt->conf.picture_filename;
else
} else {
imagepath = DEF_IMAGEPATH;
}
mystrftime(cnt, filename, sizeof(filename), imagepath, currenttime_tv, NULL, 0);
@@ -592,8 +606,9 @@ static void event_image_snapshot(struct context *cnt,
int offset = 0;
int len = strlen(cnt->conf.snapshot_filename);
if (len >= 9)
if (len >= 9) {
offset = len - 8;
}
if (strcmp(cnt->conf.snapshot_filename+offset, "lastsnap")) {
char linkpath[PATH_MAX];
@@ -602,10 +617,11 @@ static void event_image_snapshot(struct context *cnt,
* conf.snapshot_filename would normally be defined but if someone deleted it by control interface
* it is better to revert to the default than fail
*/
if (cnt->conf.snapshot_filename)
if (cnt->conf.snapshot_filename) {
snappath = cnt->conf.snapshot_filename;
else
} else {
snappath = DEF_SNAPPATH;
}
mystrftime(cnt, filepath, sizeof(filepath), snappath, currenttime_tv, NULL, 0);
snprintf(filename, PATH_MAX, "%.*s.%s"
@@ -727,10 +743,11 @@ static void event_image_preview(struct context *cnt,
* conf.picture_filename would normally be defined but if someone deleted it by
* control interface it is better to revert to the default than fail.
*/
if (cnt->conf.picture_filename)
if (cnt->conf.picture_filename) {
imagepath = cnt->conf.picture_filename;
else
} else {
imagepath = (char *)DEF_IMAGEPATH;
}
mystrftime(cnt, filename, sizeof(filename), imagepath, &cnt->imgs.preview_image.timestamp_tv, NULL, 0);
snprintf(previewname, PATH_MAX, "%.*s/%.*s.%s"
@@ -759,8 +776,9 @@ static void event_camera_lost(struct context *cnt,
struct image_data *img_data ATTRIBUTE_UNUSED, char *dummy1 ATTRIBUTE_UNUSED,
void *dummy2 ATTRIBUTE_UNUSED, struct timeval *tv1 ATTRIBUTE_UNUSED)
{
if (cnt->conf.on_camera_lost)
if (cnt->conf.on_camera_lost) {
exec_command(cnt, cnt->conf.on_camera_lost, NULL, 0);
}
}
static void event_camera_found(struct context *cnt,
@@ -768,8 +786,9 @@ static void event_camera_found(struct context *cnt,
struct image_data *img_data ATTRIBUTE_UNUSED, char *dummy1 ATTRIBUTE_UNUSED,
void *dummy2 ATTRIBUTE_UNUSED, struct timeval *tv1 ATTRIBUTE_UNUSED)
{
if (cnt->conf.on_camera_found)
if (cnt->conf.on_camera_found) {
exec_command(cnt, cnt->conf.on_camera_found, NULL, 0);
}
}
static void on_movie_end_command(struct context *cnt,
@@ -779,8 +798,9 @@ static void on_movie_end_command(struct context *cnt,
{
int filetype = (unsigned long) arg;
if ((filetype & FTYPE_MPEG_ANY) && cnt->conf.on_movie_end)
if ((filetype & FTYPE_MPEG_ANY) && cnt->conf.on_movie_end) {
exec_command(cnt, cnt->conf.on_movie_end, filename, filetype);
}
}
static void event_extpipe_end(struct context *cnt,
@@ -839,10 +859,10 @@ static void event_create_extpipe(struct context *cnt,
} else if (errno == ENOENT) {
MOTION_LOG(ERR, TYPE_EVENTS, SHOW_ERRNO
,_("path not found, trying to create it %s ..."), cnt->conf.target_dir);
if (create_path(cnt->extpipefilename) == -1)
return ;
}
else {
if (create_path(cnt->extpipefilename) == -1) {
return;
}
} else {
MOTION_LOG(ERR, TYPE_EVENTS, SHOW_ERRNO
,_("error accesing path %s"), cnt->conf.target_dir);
return ;
@@ -850,13 +870,14 @@ static void event_create_extpipe(struct context *cnt,
}
/* Always create any path specified as file name */
if (create_path(cnt->extpipefilename) == -1)
return ;
if (create_path(cnt->extpipefilename) == -1) {
return;
}
mystrftime(cnt, stamp, sizeof(stamp), cnt->conf.movie_extpipe, currenttime_tv, cnt->extpipefilename, 0);
retcd = snprintf(cnt->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"), cnt->extpipecmdline);
return;
@@ -891,14 +912,16 @@ static void event_extpipe_put(struct context *cnt,
passthrough = util_check_passthrough(cnt);
/* Check that is open */
if ((cnt->extpipe_open) && (fileno(cnt->extpipe) > 0)) {
if ((cnt->imgs.size_high > 0) && (!passthrough)){
if (!fwrite(img_data->image_high, cnt->imgs.size_high, 1, cnt->extpipe))
if ((cnt->imgs.size_high > 0) && (!passthrough)) {
if (!fwrite(img_data->image_high, cnt->imgs.size_high, 1, cnt->extpipe)) {
MOTION_LOG(ERR, TYPE_EVENTS, SHOW_ERRNO
,_("Error writing in pipe , state error %d"), ferror(cnt->extpipe));
}
} else {
if (!fwrite(img_data->image_norm, cnt->imgs.size_norm, 1, cnt->extpipe))
if (!fwrite(img_data->image_norm, cnt->imgs.size_norm, 1, cnt->extpipe)) {
MOTION_LOG(ERR, TYPE_EVENTS, SHOW_ERRNO
,_("Error writing in pipe , state error %d"), ferror(cnt->extpipe));
}
}
} else {
MOTION_LOG(ERR, TYPE_EVENTS, NO_ERRNO
@@ -919,7 +942,9 @@ static void event_new_video(struct context *cnt,
MOTION_LOG(INF, TYPE_EVENTS, NO_ERRNO, _("Source FPS %d"), cnt->movie_fps);
if (cnt->movie_fps < 2) cnt->movie_fps = 2;
if (cnt->movie_fps < 2) {
cnt->movie_fps = 2;
}
}
@@ -937,17 +962,19 @@ static void event_ffmpeg_newfile(struct context *cnt,
long codenbr;
int retcd;
if (!cnt->conf.movie_output && !cnt->conf.movie_output_motion)
if (!cnt->conf.movie_output && !cnt->conf.movie_output_motion) {
return;
}
/*
* conf.mpegpath would normally be defined but if someone deleted it by control interface
* it is better to revert to the default than fail
*/
if (cnt->conf.movie_filename)
if (cnt->conf.movie_filename) {
moviepath = cnt->conf.movie_filename;
else
} else {
moviepath = DEF_MOVIEPATH;
}
mystrftime(cnt, stamp, sizeof(stamp), moviepath, currenttime_tv, NULL, 0);
@@ -1029,7 +1056,7 @@ static void event_ffmpeg_newfile(struct context *cnt,
}
if (cnt->conf.movie_output) {
cnt->ffmpeg_output = mymalloc(sizeof(struct ffmpeg));
if (cnt->imgs.size_high > 0){
if (cnt->imgs.size_high > 0) {
cnt->ffmpeg_output->width = cnt->imgs.width_high;
cnt->ffmpeg_output->height = cnt->imgs.height_high;
cnt->ffmpeg_output->high_resolution = TRUE;
@@ -1061,7 +1088,7 @@ static void event_ffmpeg_newfile(struct context *cnt,
retcd = ffmpeg_open(cnt->ffmpeg_output);
if (retcd < 0){
if (retcd < 0) {
MOTION_LOG(ERR, TYPE_EVENTS, NO_ERRNO
,_("Error opening context for movie output."));
free(cnt->ffmpeg_output);
@@ -1098,7 +1125,7 @@ static void event_ffmpeg_newfile(struct context *cnt,
cnt->ffmpeg_output_motion->rtsp_data = NULL;
retcd = ffmpeg_open(cnt->ffmpeg_output_motion);
if (retcd < 0){
if (retcd < 0) {
MOTION_LOG(ERR, TYPE_EVENTS, NO_ERRNO
,_("ffopen_open error creating (motion) file [%s]"), cnt->motionfilename);
free(cnt->ffmpeg_output_motion);
@@ -1126,10 +1153,11 @@ static void event_ffmpeg_timelapse(struct context *cnt,
* conf.timelapse_filename would normally be defined but if someone deleted it by control interface
* it is better to revert to the default than fail
*/
if (cnt->conf.timelapse_filename)
if (cnt->conf.timelapse_filename) {
timepath = cnt->conf.timelapse_filename;
else
} else {
timepath = DEF_TIMEPATH;
}
mystrftime(cnt, tmp, sizeof(tmp), timepath, currenttime_tv, NULL, 0);
@@ -1141,7 +1169,7 @@ static void event_ffmpeg_timelapse(struct context *cnt,
, tmp);
passthrough = util_check_passthrough(cnt);
cnt->ffmpeg_timelapse = mymalloc(sizeof(struct ffmpeg));
if ((cnt->imgs.size_high > 0) && (!passthrough)){
if ((cnt->imgs.size_high > 0) && (!passthrough)) {
cnt->ffmpeg_timelapse->width = cnt->imgs.width_high;
cnt->ffmpeg_timelapse->height = cnt->imgs.height_high;
cnt->ffmpeg_timelapse->high_resolution = TRUE;
@@ -1165,8 +1193,7 @@ static void event_ffmpeg_timelapse(struct context *cnt,
cnt->ffmpeg_timelapse->rtsp_data = NULL;
if ((strcmp(cnt->conf.timelapse_codec,"mpg") == 0) ||
(strcmp(cnt->conf.timelapse_codec,"swf") == 0) ){
(strcmp(cnt->conf.timelapse_codec,"swf") == 0)) {
if (strcmp(cnt->conf.timelapse_codec,"swf") == 0) {
MOTION_LOG(WRN, TYPE_EVENTS, NO_ERRNO
,_("The swf container for timelapse no longer supported. Using mpg container."));
@@ -1187,7 +1214,7 @@ static void event_ffmpeg_timelapse(struct context *cnt,
retcd = ffmpeg_open(cnt->ffmpeg_timelapse);
}
if (retcd < 0){
if (retcd < 0) {
MOTION_LOG(ERR, TYPE_EVENTS, NO_ERRNO
,_("ffopen_open error creating (timelapse) file [%s]"), cnt->timelapsefilename);
free(cnt->ffmpeg_timelapse);
@@ -1209,7 +1236,7 @@ static void event_ffmpeg_put(struct context *cnt,
void *dummy2 ATTRIBUTE_UNUSED, struct timeval *currenttime_tv)
{
if (cnt->ffmpeg_output) {
if (ffmpeg_put_image(cnt->ffmpeg_output, img_data, currenttime_tv) == -1){
if (ffmpeg_put_image(cnt->ffmpeg_output, img_data, currenttime_tv) == -1) {
MOTION_LOG(ERR, TYPE_EVENTS, NO_ERRNO, _("Error encoding image"));
}
}
@@ -1423,7 +1450,8 @@ void event(struct context *cnt, motion_event type, struct image_data *img_data,
int i=-1;
while (event_handlers[++i].handler) {
if (type == event_handlers[i].type)
if (type == event_handlers[i].type) {
event_handlers[i].handler(cnt, type, img_data, filename, eventdata, tv1);
}
}
}

View File

@@ -168,7 +168,7 @@ int my_copy_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;
@@ -217,8 +217,7 @@ static int ffmpeg_timelapse_exists(const char *fname)
{
FILE *file;
file = fopen(fname, "r");
if (file)
{
if (file) {
fclose(file);
return 1;
}
@@ -230,7 +229,9 @@ static int ffmpeg_timelapse_append(struct ffmpeg *ffmpeg, AVPacket pkt)
FILE *file;
file = fopen(ffmpeg->filename, "a");
if (!file) return -1;
if (!file) {
return -1;
}
fwrite(pkt.data,1,pkt.size,file);
@@ -251,8 +252,10 @@ static int ffmpeg_lockmgr_cb(void **arg, enum AVLockOp op)
switch (op) {
case AV_LOCK_CREATE:
mutex = malloc(sizeof(*mutex));
if (!mutex)
if (!mutex) {
return AVERROR(ENOMEM);
}
if ((err = pthread_mutex_init(mutex, NULL))) {
free(mutex);
return AVERROR(err);
@@ -260,18 +263,19 @@ static int ffmpeg_lockmgr_cb(void **arg, enum AVLockOp op)
*arg = mutex;
return 0;
case AV_LOCK_OBTAIN:
if ((err = pthread_mutex_lock(mutex)))
if ((err = pthread_mutex_lock(mutex))) {
return AVERROR(err);
}
return 0;
case AV_LOCK_RELEASE:
if ((err = pthread_mutex_unlock(mutex)))
if ((err = pthread_mutex_unlock(mutex))) {
return AVERROR(err);
}
return 0;
case AV_LOCK_DESTROY:
if (mutex)
if (mutex) {
pthread_mutex_destroy(mutex);
}
free(mutex);
*arg = NULL;
return 0;
@@ -283,17 +287,17 @@ static int ffmpeg_lockmgr_cb(void **arg, enum AVLockOp op)
static void ffmpeg_free_context(struct ffmpeg *ffmpeg)
{
if (ffmpeg->picture != NULL){
if (ffmpeg->picture != NULL) {
my_frame_free(ffmpeg->picture);
ffmpeg->picture = NULL;
}
if (ffmpeg->ctx_codec != NULL){
if (ffmpeg->ctx_codec != NULL) {
my_avcodec_close(ffmpeg->ctx_codec);
ffmpeg->ctx_codec = NULL;
}
if (ffmpeg->oc != NULL){
if (ffmpeg->oc != NULL) {
avformat_free_context(ffmpeg->oc);
ffmpeg->oc = NULL;
}
@@ -324,7 +328,7 @@ static int ffmpeg_get_oformat(struct ffmpeg *ffmpeg)
/* Only the newer codec and containers can handle the really fast FPS */
if (((strcmp(codec_name, "msmpeg4") == 0) ||
(strcmp(codec_name, "mpeg4") == 0) ||
(strcmp(codec_name, "swf") == 0) ) && (ffmpeg->fps >50)){
(strcmp(codec_name, "swf") == 0) ) && (ffmpeg->fps >50)) {
MOTION_LOG(ERR, TYPE_ENCODER, NO_ERRNO
,_("The frame rate specified is too high for the ffmpeg movie type specified. "
"Choose a different ffmpeg container or lower framerate."));
@@ -334,7 +338,7 @@ static int ffmpeg_get_oformat(struct ffmpeg *ffmpeg)
}
retcd = snprintf(basename,PATH_MAX,"%s",ffmpeg->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"));
ffmpeg_free_context(ffmpeg);
@@ -342,12 +346,14 @@ static int ffmpeg_get_oformat(struct ffmpeg *ffmpeg)
return -1;
}
if (ffmpeg->tlapse == TIMELAPSE_APPEND){
if (ffmpeg->tlapse == TIMELAPSE_APPEND) {
ffmpeg->oc->oformat = av_guess_format ("mpeg2video", NULL, NULL);
if (ffmpeg->oc->oformat) ffmpeg->oc->oformat->video_codec = MY_CODEC_ID_MPEG2VIDEO;
if (ffmpeg->oc->oformat) {
ffmpeg->oc->oformat->video_codec = MY_CODEC_ID_MPEG2VIDEO;
}
retcd = snprintf(ffmpeg->filename,PATH_MAX,"%s.mpg",basename);
if ((!ffmpeg->oc->oformat) ||
(retcd < 0) || (retcd >= PATH_MAX)){
if ((!ffmpeg->oc->oformat) || (retcd < 0) || (retcd >= PATH_MAX)) {
MOTION_LOG(ERR, TYPE_ENCODER, NO_ERRNO
,_("Error setting timelapse append for codec %s"), codec_name);
ffmpeg_free_context(ffmpeg);
@@ -366,7 +372,9 @@ static int ffmpeg_get_oformat(struct ffmpeg *ffmpeg)
if (strcmp(codec_name, "msmpeg4") == 0) {
ffmpeg->oc->oformat = av_guess_format("avi", NULL, NULL);
retcd = snprintf(ffmpeg->filename,PATH_MAX,"%s.avi",basename);
if (ffmpeg->oc->oformat) ffmpeg->oc->oformat->video_codec = MY_CODEC_ID_MSMPEG4V2;
if (ffmpeg->oc->oformat) {
ffmpeg->oc->oformat->video_codec = MY_CODEC_ID_MSMPEG4V2;
}
}
if (strcmp(codec_name, "swf") == 0) {
@@ -377,13 +385,17 @@ static int ffmpeg_get_oformat(struct ffmpeg *ffmpeg)
if (strcmp(codec_name, "flv") == 0) {
ffmpeg->oc->oformat = av_guess_format("flv", NULL, NULL);
retcd = snprintf(ffmpeg->filename,PATH_MAX,"%s.flv",basename);
if (ffmpeg->oc->oformat) ffmpeg->oc->oformat->video_codec = MY_CODEC_ID_FLV1;
if (ffmpeg->oc->oformat) {
ffmpeg->oc->oformat->video_codec = MY_CODEC_ID_FLV1;
}
}
if (strcmp(codec_name, "ffv1") == 0) {
ffmpeg->oc->oformat = av_guess_format("avi", NULL, NULL);
retcd = snprintf(ffmpeg->filename,PATH_MAX,"%s.avi",basename);
if (ffmpeg->oc->oformat) ffmpeg->oc->oformat->video_codec = MY_CODEC_ID_FFV1;
if (ffmpeg->oc->oformat) {
ffmpeg->oc->oformat->video_codec = MY_CODEC_ID_FFV1;
}
}
if (strcmp(codec_name, "mov") == 0) {
@@ -394,23 +406,29 @@ static int ffmpeg_get_oformat(struct ffmpeg *ffmpeg)
if (strcmp(codec_name, "mp4") == 0) {
ffmpeg->oc->oformat = av_guess_format("mp4", NULL, NULL);
retcd = snprintf(ffmpeg->filename,PATH_MAX,"%s.mp4",basename);
if (ffmpeg->oc->oformat) ffmpeg->oc->oformat->video_codec = MY_CODEC_ID_H264;
if (ffmpeg->oc->oformat) {
ffmpeg->oc->oformat->video_codec = MY_CODEC_ID_H264;
}
}
if (strcmp(codec_name, "mkv") == 0) {
ffmpeg->oc->oformat = av_guess_format("matroska", NULL, NULL);
retcd = snprintf(ffmpeg->filename,PATH_MAX,"%s.mkv",basename);
if (ffmpeg->oc->oformat) ffmpeg->oc->oformat->video_codec = MY_CODEC_ID_H264;
if (ffmpeg->oc->oformat) {
ffmpeg->oc->oformat->video_codec = MY_CODEC_ID_H264;
}
}
if (strcmp(codec_name, "hevc") == 0) {
ffmpeg->oc->oformat = av_guess_format("mp4", NULL, NULL);
retcd = snprintf(ffmpeg->filename,PATH_MAX,"%s.mp4",basename);
if (ffmpeg->oc->oformat) ffmpeg->oc->oformat->video_codec = MY_CODEC_ID_HEVC;
if (ffmpeg->oc->oformat) {
ffmpeg->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"));
ffmpeg_free_context(ffmpeg);
@@ -445,14 +463,14 @@ static int ffmpeg_encode_video(struct ffmpeg *ffmpeg)
char errstr[128];
retcd = avcodec_send_frame(ffmpeg->ctx_codec, ffmpeg->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(ffmpeg->ctx_codec, &ffmpeg->pkt);
if (retcd == AVERROR(EAGAIN)){
if (retcd == AVERROR(EAGAIN)) {
//Buffered packet. Throw special return code
av_strerror(retcd, errstr, sizeof(errstr));
MOTION_LOG(DBG, TYPE_ENCODER, NO_ERRNO
@@ -460,7 +478,7 @@ static int ffmpeg_encode_video(struct ffmpeg *ffmpeg)
my_packet_unref(ffmpeg->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);
@@ -468,7 +486,7 @@ static int ffmpeg_encode_video(struct ffmpeg *ffmpeg)
return -1;
}
if (ffmpeg->preferred_codec == USER_CODEC_V4L2M2M){
if (ffmpeg->preferred_codec == USER_CODEC_V4L2M2M) {
if (ffmpeg_encode_nal(ffmpeg)) {
// Throw special return code
return -2;
@@ -483,20 +501,20 @@ static int ffmpeg_encode_video(struct ffmpeg *ffmpeg)
int got_packet_ptr;
retcd = avcodec_encode_video2(ffmpeg->ctx_codec, &ffmpeg->pkt, ffmpeg->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
my_packet_unref(ffmpeg->pkt);
return -2;
}
/* This kills compiler warnings. Nal setting is only for recent ffmpeg versions*/
if (ffmpeg->preferred_codec == USER_CODEC_V4L2M2M){
if (ffmpeg->preferred_codec == USER_CODEC_V4L2M2M) {
if (ffmpeg_encode_nal(ffmpeg)) {
// Throw special return code
return -2;
@@ -515,12 +533,12 @@ static int ffmpeg_encode_video(struct ffmpeg *ffmpeg)
video_outbuf = mymalloc(video_outbuf_size);
retcd = avcodec_encode_video(ffmpeg->video_st->codec, video_outbuf, video_outbuf_size, ffmpeg->picture);
if (retcd < 0 ){
if (retcd < 0 ) {
MOTION_LOG(ERR, TYPE_ENCODER, NO_ERRNO, _("Error encoding video"));
my_packet_unref(ffmpeg->pkt);
return -1;
}
if (retcd == 0 ){
if (retcd == 0 ) {
// No bytes encoded => buffered=>special handling
my_packet_unref(ffmpeg->pkt);
return -2;
@@ -530,8 +548,9 @@ static int ffmpeg_encode_video(struct ffmpeg *ffmpeg)
ffmpeg->pkt.size = retcd;
ffmpeg->pkt.data = video_outbuf;
if (ffmpeg->picture->key_frame == 1)
ffmpeg->pkt.flags |= AV_PKT_FLAG_KEY;
if (ffmpeg->picture->key_frame == 1) {
ffmpeg->pkt.flags |= AV_PKT_FLAG_KEY;
}
ffmpeg->pkt.pts = ffmpeg->picture->pts;
ffmpeg->pkt.dts = ffmpeg->pkt.pts;
@@ -539,7 +558,7 @@ static int ffmpeg_encode_video(struct ffmpeg *ffmpeg)
free(video_outbuf);
/* This kills compiler warnings. Nal setting is only for recent ffmpeg versions*/
if (ffmpeg->preferred_codec == USER_CODEC_V4L2M2M){
if (ffmpeg->preferred_codec == USER_CODEC_V4L2M2M) {
if (ffmpeg_encode_nal(ffmpeg)) {
// Throw special return code
return -2;
@@ -561,7 +580,7 @@ static int ffmpeg_set_pts(struct ffmpeg *ffmpeg, const struct timeval *tv1)
ffmpeg->picture->pts = ffmpeg->last_pts;
} else {
pts_interval = ((1000000L * (tv1->tv_sec - ffmpeg->start_time.tv_sec)) + tv1->tv_usec - ffmpeg->start_time.tv_usec);
if (pts_interval < 0){
if (pts_interval < 0) {
/* This can occur when we have pre-capture frames. Reset start time of video. */
ffmpeg_reset_movie_start_time(ffmpeg, tv1);
pts_interval = 0;
@@ -572,16 +591,16 @@ static int ffmpeg_set_pts(struct ffmpeg *ffmpeg, const struct timeval *tv1)
} else
ffmpeg->picture->pts = av_rescale_q(pts_interval,(AVRational){1, 1000000L},ffmpeg->video_st->time_base) + ffmpeg->base_pts;
if (ffmpeg->test_mode == TRUE){
if (ffmpeg->test_mode == TRUE) {
MOTION_LOG(INF, TYPE_ENCODER, NO_ERRNO
,_("PTS %"PRId64" Base PTS %"PRId64" ms interval %"PRId64" timebase %d-%d")
,ffmpeg->picture->pts,ffmpeg->base_pts,pts_interval
,ffmpeg->video_st->time_base.num,ffmpeg->video_st->time_base.den);
}
if (ffmpeg->picture->pts <= ffmpeg->last_pts){
if (ffmpeg->picture->pts <= ffmpeg->last_pts) {
//We have a problem with our motion loop timing and sending frames or the rounding into the PTS.
if (ffmpeg->test_mode == TRUE){
if (ffmpeg->test_mode == TRUE) {
MOTION_LOG(INF, TYPE_ENCODER, NO_ERRNO, _("BAD TIMING!! Frame skipped."));
}
return -1;
@@ -601,14 +620,14 @@ static int ffmpeg_set_pktpts(struct ffmpeg *ffmpeg, const struct timeval *tv1)
ffmpeg->pkt.pts = ffmpeg->last_pts;
} else {
pts_interval = ((1000000L * (tv1->tv_sec - ffmpeg->start_time.tv_sec)) + tv1->tv_usec - ffmpeg->start_time.tv_usec);
if (pts_interval < 0){
if (pts_interval < 0) {
/* This can occur when we have pre-capture frames. Reset start time of video. */
ffmpeg_reset_movie_start_time(ffmpeg, tv1);
pts_interval = 0;
}
ffmpeg->pkt.pts = av_rescale_q(pts_interval,(AVRational){1, 1000000L},ffmpeg->video_st->time_base) + ffmpeg->base_pts;
if (ffmpeg->test_mode == TRUE){
if (ffmpeg->test_mode == TRUE) {
MOTION_LOG(INF, TYPE_ENCODER, NO_ERRNO
,_("PTS %"PRId64" Base PTS %"PRId64" ms interval %"PRId64" timebase %d-%d Change %d")
,ffmpeg->pkt.pts
@@ -618,9 +637,9 @@ static int ffmpeg_set_pktpts(struct ffmpeg *ffmpeg, const struct timeval *tv1)
,(ffmpeg->pkt.pts-ffmpeg->last_pts) );
}
if (ffmpeg->pkt.pts <= ffmpeg->last_pts){
if (ffmpeg->pkt.pts <= ffmpeg->last_pts) {
//We have a problem with our motion loop timing and sending frames or the rounding into the PTS.
if (ffmpeg->test_mode == TRUE){
if (ffmpeg->test_mode == TRUE) {
MOTION_LOG(INF, TYPE_ENCODER, NO_ERRNO, _("BAD TIMING!! Frame skipped."));
}
return -1;
@@ -635,11 +654,14 @@ static int ffmpeg_set_quality(struct ffmpeg *ffmpeg)
{
ffmpeg->opts = 0;
if (ffmpeg->quality > 100) ffmpeg->quality = 100;
if (ffmpeg->quality > 100) {
ffmpeg->quality = 100;
}
if (ffmpeg->ctx_codec->codec_id == MY_CODEC_ID_H264 ||
ffmpeg->ctx_codec->codec_id == MY_CODEC_ID_HEVC){
if (ffmpeg->quality <= 0)
ffmpeg->ctx_codec->codec_id == MY_CODEC_ID_HEVC) {
if (ffmpeg->quality <= 0) {
ffmpeg->quality = 45; // default to 45% quality
}
av_dict_set(&ffmpeg->opts, "preset", "ultrafast", 0);
av_dict_set(&ffmpeg->opts, "tune", "zerolatency", 0);
/* This next if statement needs validation. Are mpeg4omx
@@ -652,8 +674,10 @@ static int ffmpeg_set_quality(struct ffmpeg *ffmpeg)
// bit_rate = ffmpeg->width * ffmpeg->height * ffmpeg->fps * quality_factor
ffmpeg->quality = (int)(((int64_t)ffmpeg->width * ffmpeg->height * ffmpeg->fps * ffmpeg->quality) >> 7);
// Clip bit rate to min
if (ffmpeg->quality < 4000) // magic number
if (ffmpeg->quality < 4000) {
// magic number
ffmpeg->quality = 4000;
}
ffmpeg->ctx_codec->profile = FF_PROFILE_H264_HIGH;
ffmpeg->ctx_codec->bit_rate = ffmpeg->quality;
} else {
@@ -665,7 +689,7 @@ static int ffmpeg_set_quality(struct ffmpeg *ffmpeg)
}
} else {
/* The selection of 8000 is a subjective number based upon viewing output files */
if (ffmpeg->quality > 0){
if (ffmpeg->quality > 0) {
ffmpeg->quality =(int)(((100-ffmpeg->quality)*(100-ffmpeg->quality)*(100-ffmpeg->quality) * 8000) / 1000000) + 1;
ffmpeg->ctx_codec->flags |= MY_CODEC_FLAG_QSCALE;
ffmpeg->ctx_codec->global_quality=ffmpeg->quality;
@@ -708,8 +732,9 @@ static const char *ffmpeg_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 (strcmp(codec_name, blacklisted_codec[i].codec_name) == 0)
if (strcmp(codec_name, blacklisted_codec[i].codec_name) == 0) {
return blacklisted_codec[i].reason;
}
}
return NULL;
}
@@ -736,8 +761,9 @@ static int ffmpeg_set_codec_preferred(struct ffmpeg *ffmpeg)
}
}
}
if (!ffmpeg->codec)
if (!ffmpeg->codec) {
ffmpeg->codec = avcodec_find_encoder(ffmpeg->oc->oformat->video_codec);
}
if (!ffmpeg->codec) {
MOTION_LOG(ERR, TYPE_ENCODER, NO_ERRNO
,_("Codec %s not found"), ffmpeg->codec_name);
@@ -745,18 +771,19 @@ static int ffmpeg_set_codec_preferred(struct ffmpeg *ffmpeg)
return -1;
}
if (strcmp(ffmpeg->codec->name, "h264_v4l2m2m") == 0){
if (strcmp(ffmpeg->codec->name, "h264_v4l2m2m") == 0) {
ffmpeg->preferred_codec = USER_CODEC_V4L2M2M;
} else if (strcmp(ffmpeg->codec->name, "h264_omx") == 0){
} else if (strcmp(ffmpeg->codec->name, "h264_omx") == 0) {
ffmpeg->preferred_codec = USER_CODEC_H264OMX;
} else if (strcmp(ffmpeg->codec->name, "mpeg4_omx") == 0){
} else if (strcmp(ffmpeg->codec->name, "mpeg4_omx") == 0) {
ffmpeg->preferred_codec = USER_CODEC_MPEG4OMX;
} else {
ffmpeg->preferred_codec = USER_CODEC_DEFAULT;
}
if (ffmpeg->codec_name[codec_name_len])
if (ffmpeg->codec_name[codec_name_len]) {
MOTION_LOG(NTC, TYPE_ENCODER, NO_ERRNO,_("Using codec %s"), ffmpeg->codec->name);
}
return 0;
@@ -770,7 +797,9 @@ static int ffmpeg_set_codec(struct ffmpeg *ffmpeg)
int chkrate;
retcd = ffmpeg_set_codec_preferred(ffmpeg);
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
@@ -800,9 +829,9 @@ static int ffmpeg_set_codec(struct ffmpeg *ffmpeg)
if (ffmpeg->tlapse != TIMELAPSE_NONE) {
ffmpeg->ctx_codec->gop_size = 1;
} else {
if (ffmpeg->fps <= 5){
if (ffmpeg->fps <= 5) {
ffmpeg->ctx_codec->gop_size = 1;
} else if (ffmpeg->fps > 30){
} else if (ffmpeg->fps > 30) {
ffmpeg->ctx_codec->gop_size = 15;
} else {
ffmpeg->ctx_codec->gop_size = (ffmpeg->fps / 2);
@@ -814,7 +843,7 @@ static int ffmpeg_set_codec(struct ffmpeg *ffmpeg)
** a very poor quality playback. We can set the FPS to a higher number and
** then let the PTS display the frames correctly.
*/
if ((ffmpeg->tlapse == TIMELAPSE_NONE) && (ffmpeg->fps <= 5)){
if ((ffmpeg->tlapse == TIMELAPSE_NONE) && (ffmpeg->fps <= 5)) {
if ((strcmp(ffmpeg->codec_name, "msmpeg4") == 0) ||
(strcmp(ffmpeg->codec_name, "flv") == 0) ||
(strcmp(ffmpeg->codec_name, "mov") == 0) ||
@@ -833,13 +862,13 @@ static int ffmpeg_set_codec(struct ffmpeg *ffmpeg)
ffmpeg->ctx_codec->height = ffmpeg->height;
ffmpeg->ctx_codec->time_base.num = 1;
ffmpeg->ctx_codec->time_base.den = ffmpeg->fps;
if (ffmpeg->preferred_codec == USER_CODEC_V4L2M2M){
if (ffmpeg->preferred_codec == USER_CODEC_V4L2M2M) {
ffmpeg->ctx_codec->pix_fmt = AV_PIX_FMT_NV21;
} else {
ffmpeg->ctx_codec->pix_fmt = MY_PIX_FMT_YUV420P;
}
ffmpeg->ctx_codec->max_b_frames = 0;
if (strcmp(ffmpeg->codec_name, "ffv1") == 0){
if (strcmp(ffmpeg->codec_name, "ffv1") == 0) {
ffmpeg->ctx_codec->strict_std_compliance = -2;
ffmpeg->ctx_codec->level = 3;
}
@@ -855,7 +884,7 @@ static int ffmpeg_set_codec(struct ffmpeg *ffmpeg)
}
retcd = ffmpeg_set_quality(ffmpeg);
if (retcd < 0){
if (retcd < 0) {
MOTION_LOG(ERR, TYPE_ENCODER, NO_ERRNO, _("Unable to set quality"));
return -1;
}
@@ -876,7 +905,7 @@ static int ffmpeg_set_codec(struct ffmpeg *ffmpeg)
retcd = avcodec_open2(ffmpeg->ctx_codec, ffmpeg->codec, &ffmpeg->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(&ffmpeg->opts);
@@ -920,33 +949,40 @@ static int ffmpeg_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, 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++)
for (i = 0; i < 4 && frame->linesize[i]; i++) {
frame->linesize[i] = FFALIGN(frame->linesize[i], align);
}
}
padded_height = FFALIGN(frame->height, 32);
if ((ret = av_image_fill_pointers(frame->data, frame->format, padded_height,
NULL, frame->linesize)) < 0)
NULL, frame->linesize)) < 0) {
return ret;
}
frame->buf[0] = av_buffer_alloc(ret + 4*plane_padding);
if (!frame->buf[0]) {
@@ -984,8 +1020,9 @@ static int ffmpeg_set_picture(struct ffmpeg *ffmpeg)
}
/* Take care of variable bitrate setting. */
if (ffmpeg->quality)
if (ffmpeg->quality) {
ffmpeg->picture->quality = ffmpeg->quality;
}
ffmpeg->picture->linesize[0] = ffmpeg->ctx_codec->width;
ffmpeg->picture->linesize[1] = ffmpeg->ctx_codec->width / 2;
@@ -1054,7 +1091,7 @@ static int ffmpeg_set_outputfile(struct ffmpeg *ffmpeg)
* items here
*/
retcd = avformat_write_header(ffmpeg->oc, NULL);
if (retcd < 0){
if (retcd < 0) {
av_strerror(retcd, errstr, sizeof(errstr));
MOTION_LOG(ERR, TYPE_ENCODER, NO_ERRNO
,_("Could not write ffmpeg header %s"),errstr);
@@ -1082,7 +1119,7 @@ static int ffmpeg_flush_codec(struct ffmpeg *ffmpeg)
int recv_cd = 0;
char errstr[128];
if (ffmpeg->passthrough){
if (ffmpeg->passthrough) {
return 0;
}
@@ -1090,19 +1127,19 @@ static int ffmpeg_flush_codec(struct ffmpeg *ffmpeg)
recv_cd = 0;
if (ffmpeg->tlapse == TIMELAPSE_NONE) {
retcd = avcodec_send_frame(ffmpeg->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);
return -1;
}
while (recv_cd != AVERROR_EOF){
while (recv_cd != AVERROR_EOF) {
av_init_packet(&ffmpeg->pkt);
ffmpeg->pkt.data = NULL;
ffmpeg->pkt.size = 0;
recv_cd = avcodec_receive_packet(ffmpeg->ctx_codec, &ffmpeg->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);
@@ -1130,7 +1167,7 @@ static int ffmpeg_flush_codec(struct ffmpeg *ffmpeg)
/* Dummy to kill warnings. No draining in older ffmpeg versions */
if (ffmpeg) {
return 0;
} else{
} else {
return 0;
}
#endif
@@ -1153,8 +1190,8 @@ static int ffmpeg_put_frame(struct ffmpeg *ffmpeg, const struct timeval *tv1)
}
retcd = ffmpeg_encode_video(ffmpeg);
if (retcd != 0){
if (retcd != -2){
if (retcd != 0) {
if (retcd != -2) {
MOTION_LOG(ERR, TYPE_ENCODER, NO_ERRNO, _("Error while encoding picture"));
}
my_packet_unref(ffmpeg->pkt);
@@ -1235,14 +1272,16 @@ static int ffmpeg_passthru_put(struct ffmpeg *ffmpeg, struct image_data *img_dat
int idnbr_image, idnbr_lastwritten, idnbr_stop, idnbr_firstkey;
int indx, indx_lastwritten, indx_firstkey;
if (ffmpeg->rtsp_data == NULL) return -1;
if (ffmpeg->rtsp_data == NULL) {
return -1;
}
if ((ffmpeg->rtsp_data->status == RTSP_NOTCONNECTED ) ||
(ffmpeg->rtsp_data->status == RTSP_RECONNECTING ) ){
(ffmpeg->rtsp_data->status == RTSP_RECONNECTING )) {
return 0;
}
if (ffmpeg->high_resolution){
if (ffmpeg->high_resolution) {
idnbr_image = img_data->idnbr_high;
} else {
idnbr_image = img_data->idnbr_norm;
@@ -1257,27 +1296,27 @@ static int ffmpeg_passthru_put(struct ffmpeg *ffmpeg, struct image_data *img_dat
for(indx = 0; indx < ffmpeg->rtsp_data->pktarray_size; indx++) {
if ((ffmpeg->rtsp_data->pktarray[indx].iswritten) &&
(ffmpeg->rtsp_data->pktarray[indx].idnbr > idnbr_lastwritten)){
(ffmpeg->rtsp_data->pktarray[indx].idnbr > idnbr_lastwritten)) {
idnbr_lastwritten=ffmpeg->rtsp_data->pktarray[indx].idnbr;
indx_lastwritten = indx;
}
if ((ffmpeg->rtsp_data->pktarray[indx].idnbr > idnbr_stop) &&
(ffmpeg->rtsp_data->pktarray[indx].idnbr <= idnbr_image)){
(ffmpeg->rtsp_data->pktarray[indx].idnbr <= idnbr_image)) {
idnbr_stop=ffmpeg->rtsp_data->pktarray[indx].idnbr;
}
if ((ffmpeg->rtsp_data->pktarray[indx].iskey) &&
(ffmpeg->rtsp_data->pktarray[indx].idnbr <= idnbr_firstkey)){
(ffmpeg->rtsp_data->pktarray[indx].idnbr <= idnbr_firstkey)) {
idnbr_firstkey=ffmpeg->rtsp_data->pktarray[indx].idnbr;
indx_firstkey = indx;
}
}
if (idnbr_stop == 0){
if (idnbr_stop == 0) {
pthread_mutex_unlock(&ffmpeg->rtsp_data->mutex_pktarray);
return 0;
}
if (indx_lastwritten != -1){
if (indx_lastwritten != -1) {
indx = indx_lastwritten;
} else if (indx_firstkey != -1) {
indx = indx_firstkey;
@@ -1285,16 +1324,20 @@ static int ffmpeg_passthru_put(struct ffmpeg *ffmpeg, struct image_data *img_dat
indx = 0;
}
while (TRUE){
while (TRUE) {
if ((!ffmpeg->rtsp_data->pktarray[indx].iswritten) &&
(ffmpeg->rtsp_data->pktarray[indx].packet.size > 0) &&
(ffmpeg->rtsp_data->pktarray[indx].idnbr > idnbr_lastwritten) &&
(ffmpeg->rtsp_data->pktarray[indx].idnbr <= idnbr_image)) {
ffmpeg_passthru_write(ffmpeg, indx);
}
if (ffmpeg->rtsp_data->pktarray[indx].idnbr == idnbr_stop) break;
if (ffmpeg->rtsp_data->pktarray[indx].idnbr == idnbr_stop) {
break;
}
indx++;
if (indx == ffmpeg->rtsp_data->pktarray_size ) indx = 0;
if (indx == ffmpeg->rtsp_data->pktarray_size) {
indx = 0;
}
}
pthread_mutex_unlock(&ffmpeg->rtsp_data->mutex_pktarray);
return 0;
@@ -1306,7 +1349,7 @@ static int ffmpeg_passthru_codec(struct ffmpeg *ffmpeg)
int retcd;
AVStream *stream_in;
if (ffmpeg->rtsp_data == NULL){
if (ffmpeg->rtsp_data == NULL) {
MOTION_LOG(ERR, TYPE_ENCODER, NO_ERRNO, _("RTSP context not available."));
return -1;
}
@@ -1314,14 +1357,14 @@ static int ffmpeg_passthru_codec(struct ffmpeg *ffmpeg)
pthread_mutex_lock(&ffmpeg->rtsp_data->mutex_transfer);
if ((ffmpeg->rtsp_data->status == RTSP_NOTCONNECTED ) ||
(ffmpeg->rtsp_data->status == RTSP_RECONNECTING ) ){
(ffmpeg->rtsp_data->status == RTSP_RECONNECTING )) {
MOTION_LOG(NTC, TYPE_ENCODER, NO_ERRNO
,_("rtsp camera not ready for pass-through."));
pthread_mutex_unlock(&ffmpeg->rtsp_data->mutex_transfer);
return -1;
}
if (strcmp(ffmpeg->codec_name, "mp4") != 0){
if (strcmp(ffmpeg->codec_name, "mp4") != 0) {
MOTION_LOG(NTC, TYPE_ENCODER, NO_ERRNO
,_("pass-through mode enabled. Changing to MP4 container."));
ffmpeg->codec_name = "mp4";
@@ -1346,7 +1389,7 @@ static int ffmpeg_passthru_codec(struct ffmpeg *ffmpeg)
}
retcd = avcodec_parameters_copy(ffmpeg->video_st->codecpar, stream_in->codecpar);
if (retcd < 0){
if (retcd < 0) {
MOTION_LOG(ERR, TYPE_ENCODER, NO_ERRNO, _("Unable to copy codec parameters"));
pthread_mutex_unlock(&ffmpeg->rtsp_data->mutex_transfer);
return -1;
@@ -1364,7 +1407,7 @@ static int ffmpeg_passthru_codec(struct ffmpeg *ffmpeg)
}
retcd = avcodec_copy_context(ffmpeg->video_st->codec, stream_in->codec);
if (retcd < 0){
if (retcd < 0) {
MOTION_LOG(ERR, TYPE_ENCODER, NO_ERRNO, _("Unable to copy codec parameters"));
pthread_mutex_unlock(&ffmpeg->rtsp_data->mutex_transfer);
return -1;
@@ -1397,12 +1440,11 @@ void ffmpeg_avcodec_log(void *ignoreme ATTRIBUTE_UNUSED, int errno_flag ATTRIBUT
* the log level. Now we put the avcodec messages to INF level since their error
* are not necessarily our errors.
*/
if (errno_flag <= AV_LOG_WARNING){
if (errno_flag <= AV_LOG_WARNING) {
/* Flatten the message coming in from avcodec. */
vsnprintf(buf, sizeof(buf), fmt, vl);
end = buf + strlen(buf);
if (end > buf && end[-1] == '\n')
{
if (end > buf && end[-1] == '\n') {
*--end = 0;
}
@@ -1415,7 +1457,7 @@ static void ffmpeg_put_pix_nv21(struct ffmpeg *ffmpeg, struct image_data *img_da
unsigned char *image,*imagecr, *imagecb;
int cr_len, x, y;
if (ffmpeg->high_resolution){
if (ffmpeg->high_resolution) {
image = img_data->image_high;
} else {
image = img_data->image_norm;
@@ -1441,7 +1483,7 @@ static void ffmpeg_put_pix_yuv420(struct ffmpeg *ffmpeg, struct image_data *img_
{
unsigned char *image;
if (ffmpeg->high_resolution){
if (ffmpeg->high_resolution) {
image = img_data->image_high;
} else {
image = img_data->image_norm;
@@ -1484,8 +1526,7 @@ void ffmpeg_global_init(void)
/* TODO: Determine if this is even needed for older versions */
int ret;
ret = av_lockmgr_register(ffmpeg_lockmgr_cb);
if (ret < 0)
{
if (ret < 0) {
MOTION_LOG(EMG, TYPE_ALL, SHOW_ERRNO, _("av_lockmgr_register failed (%d)"), ret);
exit(1);
}
@@ -1501,8 +1542,7 @@ void ffmpeg_global_deinit(void)
avformat_network_deinit();
#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"));
}
@@ -1550,20 +1590,20 @@ int ffmpeg_open(struct ffmpeg *ffmpeg)
}
retcd = ffmpeg_set_stream(ffmpeg);
if (retcd < 0){
if (retcd < 0) {
MOTION_LOG(ERR, TYPE_ENCODER, NO_ERRNO, _("Could not set the stream"));
return -1;
}
retcd = ffmpeg_set_picture(ffmpeg);
if (retcd < 0){
if (retcd < 0) {
MOTION_LOG(ERR, TYPE_ENCODER, NO_ERRNO, _("Could not set the stream"));
return -1;
}
}
retcd = ffmpeg_set_outputfile(ffmpeg);
if (retcd < 0){
if (retcd < 0) {
MOTION_LOG(ERR, TYPE_ENCODER, NO_ERRNO, _("Could not set the stream"));
return -1;
}
@@ -1585,10 +1625,10 @@ void ffmpeg_close(struct ffmpeg *ffmpeg)
if (ffmpeg != NULL) {
if (ffmpeg_flush_codec(ffmpeg) < 0){
if (ffmpeg_flush_codec(ffmpeg) < 0) {
MOTION_LOG(ERR, TYPE_ENCODER, NO_ERRNO, _("Error flushing codec"));
}
if (ffmpeg->oc->pb != NULL){
if (ffmpeg->oc->pb != NULL) {
if (ffmpeg->tlapse != TIMELAPSE_APPEND) {
av_write_trailer(ffmpeg->oc);
}
@@ -1603,7 +1643,9 @@ void ffmpeg_close(struct ffmpeg *ffmpeg)
}
#else
if (ffmpeg != NULL) free(ffmpeg);
if (ffmpeg != NULL) {
free(ffmpeg);
}
#endif // HAVE_FFMPEG
}
@@ -1627,7 +1669,7 @@ int ffmpeg_put_image(struct ffmpeg *ffmpeg, struct image_data *img_data, const s
}
ffmpeg->gop_cnt ++;
if (ffmpeg->gop_cnt == ffmpeg->ctx_codec->gop_size ){
if (ffmpeg->gop_cnt == ffmpeg->ctx_codec->gop_size ) {
ffmpeg->picture->pict_type = AV_PICTURE_TYPE_I;
ffmpeg->picture->key_frame = 1;
ffmpeg->gop_cnt = 0;
@@ -1645,14 +1687,14 @@ int ffmpeg_put_image(struct ffmpeg *ffmpeg, struct image_data *img_data, const s
while ((retcd == -2) && (ffmpeg->tlapse != TIMELAPSE_NONE)) {
retcd = ffmpeg_put_frame(ffmpeg, tv1);
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"));
}
@@ -1672,8 +1714,9 @@ void ffmpeg_reset_movie_start_time(struct ffmpeg *ffmpeg, const struct timeval *
{
#ifdef HAVE_FFMPEG
int64_t one_frame_interval = av_rescale_q(1,(AVRational){1, ffmpeg->fps},ffmpeg->video_st->time_base);
if (one_frame_interval <= 0)
if (one_frame_interval <= 0) {
one_frame_interval = 1;
}
ffmpeg->base_pts = ffmpeg->last_pts + one_frame_interval;
ffmpeg->start_time.tv_sec = tv1->tv_sec;

View File

@@ -101,8 +101,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));
@@ -114,11 +115,13 @@ static void add_huff_table(j_decompress_ptr dinfo, JHUFF_TBL **htblptr, const UI
*/
nsymbols = 0;
for (len = 1; len <= 16; len++)
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));
}
@@ -240,8 +243,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;
}
@@ -542,7 +546,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;

View File

@@ -102,11 +102,13 @@ void set_log_mode(int mode)
log_mode = mode;
//printf("set log mode %d\n", 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();
}
}
/**
@@ -123,8 +125,9 @@ FILE * set_logfile(const char *logfile_name)
logfile = myfopen(logfile_name, "a");
/* If logfile was opened correctly */
if (logfile)
if (logfile) {
set_log_mode(LOGMODE_FILE);
}
return logfile;
}
@@ -186,12 +189,14 @@ void motion_log(int level, unsigned int type, int errno_flag,int fncname, const
/* Exit if level is greater than log_level */
if ((unsigned int)level > log_level)
if ((unsigned int)level > log_level) {
return;
}
/* Exit if type is not equal to log_type and not TYPE_ALL */
if ((log_type != TYPE_ALL) && (type != log_type))
if ((log_type != TYPE_ALL) && (type != log_type)) {
return;
}
//printf("log_type %d, type %d level %d\n", log_type, type, level);
@@ -226,7 +231,7 @@ void motion_log(int level, unsigned int type, int errno_flag,int fncname, const
}
/* 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);
@@ -264,10 +269,10 @@ void motion_log(int level, unsigned int type, int errno_flag,int fncname, const
#endif
}
if ((!strcmp(buf,flood_msg)) && (flood_cnt <= 5000)){
if ((!strcmp(buf,flood_msg)) && (flood_cnt <= 5000)) {
flood_cnt++;
} else {
if (flood_cnt > 1){
if (flood_cnt > 1) {
snprintf(flood_repeats,1024,"[%d:%s] [%s] [%s] Above message repeats %d times",
threadnr, threadname, get_log_level_str(level)
, get_log_type_str(type), flood_cnt-1);

View File

@@ -96,7 +96,7 @@ static void set_video_port_format(mmalcam_context_ptr mmalcam, MMAL_ES_FORMAT_T
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."));
@@ -386,8 +386,9 @@ int mmalcam_next(struct context *cnt, struct image_data *img_data)
{
mmalcam_context_ptr mmalcam;
if ((!cnt) || (!cnt->mmalcam))
if ((!cnt) || (!cnt->mmalcam)) {
return NETCAM_FATAL_ERROR;
}
mmalcam = cnt->mmalcam;
@@ -415,9 +416,10 @@ int mmalcam_next(struct context *cnt, struct 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(cnt,img_data);

View File

File diff suppressed because it is too large Load Diff

View File

@@ -109,14 +109,17 @@ 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
@@ -170,14 +173,15 @@ 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 (!strcmp(parse_url->service, "http"))
if (!strcmp(parse_url->service, "http")) {
parse_url->port = 80;
else if (!strcmp(parse_url->service, "ftp"))
} else if (!strcmp(parse_url->service, "ftp")) {
parse_url->port = 21;
else if (!strcmp(parse_url->service, "rtmp"))
} else if (!strcmp(parse_url->service, "rtmp")) {
parse_url->port = 1935;
else if (!strcmp(parse_url->service, "rtsp"))
} else if (!strcmp(parse_url->service, "rtsp")) {
parse_url->port = 554;
}
MOTION_LOG(INF, TYPE_NETCAM, NO_ERRNO, _("Using port number %d"),parse_url->port);
}
@@ -340,8 +344,9 @@ static void *netcam_handler_loop(void *arg)
/* If FTP connection, attempt to re-connect to server. */
if (netcam->ftp) {
close(netcam->ftp->control_file_desc);
if (ftp_connect(netcam) < 0)
if (ftp_connect(netcam) < 0) {
MOTION_LOG(ERR, TYPE_NETCAM, NO_ERRNO,_("Trying to re-connect"));
}
}
continue;
}
@@ -374,8 +379,9 @@ static void *netcam_handler_loop(void *arg)
* us, we just continue. In either event, we clear
* the start_capture flag set by the main loop.
*/
if (!netcam->start_capture)
if (!netcam->start_capture) {
pthread_cond_wait(&netcam->cap_cond, &netcam->mutex);
}
netcam->start_capture = 0;
@@ -430,7 +436,9 @@ void netcam_cleanup(netcam_context_ptr netcam, int init_retry_flag)
{
struct timespec waittime;
if (!netcam) return;
if (!netcam) {
return;
}
/*
* This 'lock' is just a bit of "defensive" programming. It should
@@ -440,8 +448,9 @@ void netcam_cleanup(netcam_context_ptr netcam, int init_retry_flag)
*/
pthread_mutex_lock(&netcam->mutex);
if (netcam->cnt->netcam == NULL)
if (netcam->cnt->netcam == NULL) {
return;
}
/*
* We set the netcam_context pointer in the motion main-loop context
@@ -462,8 +471,9 @@ void netcam_cleanup(netcam_context_ptr netcam, int init_retry_flag)
* netcam->mutex locked.
*/
if (netcam->caps.streaming == NCS_UNSUPPORTED)
if (netcam->caps.streaming == NCS_UNSUPPORTED) {
pthread_cond_signal(&netcam->cap_cond);
}
/*
@@ -562,8 +572,9 @@ int netcam_next(struct context *cnt, struct image_data *img_data)
* Here we have some more "defensive programming". This check should
* never be true, but if it is just return with a "fatal error".
*/
if ((!cnt) || (!cnt->netcam))
if ((!cnt) || (!cnt->netcam)) {
return NETCAM_FATAL_ERROR;
}
netcam = cnt->netcam;
@@ -591,8 +602,9 @@ int netcam_next(struct context *cnt, struct image_data *img_data)
* approach is to just return a NULL (failed) to the caller (an
* error message has already been produced by the libjpeg routines).
*/
if (setjmp(netcam->setjmp_buffer))
if (setjmp(netcam->setjmp_buffer)) {
return NETCAM_GENERAL_ERROR | NETCAM_JPEG_CONV_ERROR;
}
/* If there was no error, process the latest image buffer. */
return netcam_proc_jpeg(netcam, img_data);
@@ -659,11 +671,9 @@ int netcam_start(struct context *cnt)
util_parms_add_default(netcam->parameters,"keepalive","off");
util_parms_add_default(netcam->parameters,"tolerant_check","off"); /*false*/
for (indx = 0; indx < netcam->parameters->params_count; indx++)
{
for (indx = 0; indx < netcam->parameters->params_count; indx++) {
if ( !strcmp(netcam->parameters->params_array[indx].param_name,"proxy") &&
strcmp(netcam->parameters->params_array[indx].param_name,"NULL") )
{
strcmp(netcam->parameters->params_array[indx].param_name,"NULL")) {
netcam_url_parse(&url, netcam->parameters->params_array[indx].param_value);
if (!url.host) {
MOTION_LOG(CRT, TYPE_NETCAM, NO_ERRNO
@@ -706,8 +716,7 @@ int netcam_start(struct context *cnt)
return -1;
}
for (indx = 0; indx < netcam->parameters->params_count; indx++)
{
for (indx = 0; indx < netcam->parameters->params_count; indx++) {
if (!strcmp(netcam->parameters->params_array[indx].param_name,"proxy")) {
if (!strcmp(netcam->parameters->params_array[indx].param_name,"NULL")) {
netcam->connect_host = url.host;
@@ -773,7 +782,9 @@ int netcam_start(struct context *cnt)
}
netcam_url_free(&url);
if (retval < 0) return -1;
if (retval < 0) {
return -1;
}
/*
* We expect that, at this point, we should be positioned to read

View File

@@ -55,14 +55,16 @@ ftp_context_pointer ftp_new_context(void)
*/
void ftp_free_context(ftp_context_pointer ctxt)
{
if (ctxt == NULL)
if (ctxt == NULL) {
return;
}
free(ctxt->path);
free(ctxt->user);
free(ctxt->passwd);
if (ctxt->control_file_desc >= 0)
if (ctxt->control_file_desc >= 0) {
close(ctxt->control_file_desc);
}
free(ctxt);
}
@@ -86,32 +88,37 @@ static int ftp_parse_response(char *buf, int len)
{
int val = 0;
if (len < 3)
if (len < 3) {
return -1;
}
if ((*buf >= '0') && (*buf <= '9'))
if ((*buf >= '0') && (*buf <= '9')) {
val = val * 10 + (*buf - '0');
else
} else {
return 0;
}
buf++;
if ((*buf >= '0') && (*buf <= '9'))
if ((*buf >= '0') && (*buf <= '9')) {
val = val * 10 + (*buf - '0');
else
} else {
return 0;
}
buf++;
if ((*buf >= '0') && (*buf <= '9'))
if ((*buf >= '0') && (*buf <= '9')) {
val = val * 10 + (*buf - '0');
else
} else {
return 0;
}
buf++;
if (*buf == '-')
if (*buf == '-') {
return -val;
}
return val;
}
@@ -133,17 +140,21 @@ static int ftp_get_more(ftp_context_pointer ctxt)
int size;
/* Validate that our context structure is valid. */
if ((ctxt == NULL) || (ctxt->control_file_desc < 0))
if ((ctxt == NULL) || (ctxt->control_file_desc < 0)) {
return -1;
}
if ((ctxt->control_buffer_index < 0) || (ctxt->control_buffer_index > FTP_BUF_SIZE))
if ((ctxt->control_buffer_index < 0) || (ctxt->control_buffer_index > FTP_BUF_SIZE)) {
return -1;
}
if ((ctxt->control_buffer_used < 0) || (ctxt->control_buffer_used > FTP_BUF_SIZE))
if ((ctxt->control_buffer_used < 0) || (ctxt->control_buffer_used > FTP_BUF_SIZE)) {
return -1;
}
if (ctxt->control_buffer_index > ctxt->control_buffer_used)
if (ctxt->control_buffer_index > ctxt->control_buffer_used) {
return -1;
}
/* First pack the control buffer. */
if (ctxt->control_buffer_index > 0) {
@@ -156,8 +167,9 @@ static int ftp_get_more(ftp_context_pointer ctxt)
size = FTP_BUF_SIZE - ctxt->control_buffer_used;
if (size == 0)
if (size == 0) {
return 0;
}
/* Read the amount left on the control connection. */
if ((len = recv(ctxt->control_file_desc,
@@ -191,8 +203,9 @@ static int ftp_get_response(ftp_context_pointer ctxt)
int len;
int res = -1, cur = -1;
if ((ctxt == NULL) || (ctxt->control_file_desc < 0))
if ((ctxt == NULL) || (ctxt->control_file_desc < 0)) {
return -1;
}
get_more:
/*
@@ -201,12 +214,14 @@ static int ftp_get_response(ftp_context_pointer ctxt)
*/
len = ftp_get_more(ctxt);
if (len < 0)
if (len < 0) {
return -1;
}
if ((ctxt->control_buffer_used == 0) && (len == 0))
if ((ctxt->control_buffer_used == 0) && (len == 0)) {
return -1;
}
ptr = &ctxt->control_buffer[ctxt->control_buffer_index];
@@ -223,32 +238,38 @@ static int ftp_get_response(ftp_context_pointer ctxt)
res = cur;
ptr += 3;
ctxt->control_buffer_answer = ptr - ctxt->control_buffer;
while ((ptr < end) && (*ptr != '\n'))
while ((ptr < end) && (*ptr != '\n')) {
ptr++;
}
if (*ptr == '\n')
if (*ptr == '\n') {
ptr++;
}
if (*ptr == '\r')
if (*ptr == '\r') {
ptr++;
}
break;
}
while ((ptr < end) && (*ptr != '\n'))
while ((ptr < end) && (*ptr != '\n')) {
ptr++;
}
if (ptr >= end) {
ctxt->control_buffer_index = ctxt->control_buffer_used;
goto get_more;
}
if (*ptr != '\r')
if (*ptr != '\r') {
ptr++;
}
}
if (res < 0)
if (res < 0) {
goto get_more;
}
ctxt->control_buffer_index = ptr - ctxt->control_buffer;
@@ -267,10 +288,11 @@ static int ftp_send_user(ftp_context_pointer ctxt)
int len;
int res;
if (ctxt->user == NULL)
if (ctxt->user == NULL) {
snprintf(buf, sizeof(buf), "USER anonymous\r\n");
else
} else {
snprintf(buf, sizeof(buf), "USER %s\r\n", ctxt->user);
}
buf[sizeof(buf) - 1] = 0;
len = strlen(buf);
@@ -293,10 +315,11 @@ static int ftp_send_passwd(ftp_context_pointer ctxt)
int len;
int res;
if (ctxt->passwd == NULL)
if (ctxt->passwd == NULL) {
snprintf(buf, sizeof(buf), "PASS anonymous@\r\n");
else
} else {
snprintf(buf, sizeof(buf), "PASS %s\r\n", ctxt->passwd);
}
buf[sizeof(buf) - 1] = 0;
len = strlen(buf);
@@ -326,8 +349,9 @@ static int ftp_quit(ftp_context_pointer ctxt)
char buf[200];
int len, res;
if ((ctxt == NULL) || (ctxt->control_file_desc < 0))
if ((ctxt == NULL) || (ctxt->control_file_desc < 0)) {
return -1;
}
snprintf(buf, sizeof(buf), "QUIT\r\n");
len = strlen(buf);
@@ -360,22 +384,26 @@ int ftp_connect(netcam_context_ptr netcam)
int res;
int addrlen = sizeof (struct sockaddr_in);
if (netcam == NULL)
if (netcam == NULL) {
return -1;
}
ctxt = netcam->ftp;
if (ctxt == NULL)
if (ctxt == NULL) {
return -1;
}
if (netcam->connect_host == NULL)
if (netcam->connect_host == NULL) {
return -1;
}
/* Do the blocking DNS query. */
port = netcam->connect_port;
if (port == 0)
if (port == 0) {
port = 21;
}
memset (&ctxt->ftp_address, 0, sizeof(ctxt->ftp_address));
@@ -510,12 +538,14 @@ static int ftp_get_connection(ftp_context_pointer ctxt)
struct sockaddr_in data_address;
unsigned int data_address_length;
if (ctxt == NULL)
return -1;
if (ctxt == NULL) {
return -1;
}
/* Set up a socket for our data address. */
if (ctxt->data_file_desc != -1)
if (ctxt->data_file_desc != -1) {
close(ctxt->data_file_desc);
}
memset (&data_address, 0, sizeof(data_address));
ctxt->data_file_desc = socket (AF_INET, SOCK_STREAM, IPPROTO_TCP);
@@ -566,8 +596,9 @@ static int ftp_get_connection(ftp_context_pointer ctxt)
/* Parse the IP address and port supplied by the server. */
cur = &ctxt->control_buffer[ctxt->control_buffer_answer];
while (((*cur < '0') || (*cur > '9')) && *cur != '\0')
while (((*cur < '0') || (*cur > '9')) && *cur != '\0') {
cur++;
}
if (sscanf(cur, "%u,%u,%u,%u,%u,%u", &temp[0], &temp[1], &temp[2],
&temp[3], &temp[4], &temp[5]) != 6) {
@@ -579,15 +610,15 @@ static int ftp_get_connection(ftp_context_pointer ctxt)
return -1;
}
for (i = 0; i < 6; i++)
for (i = 0; i < 6; i++) {
ad[i] = (unsigned char) (temp[i] & 0xff) ;
}
memcpy (&((struct sockaddr_in *)&data_address)->sin_addr, &ad[0], 4);
memcpy (&((struct sockaddr_in *)&data_address)->sin_port, &ad[4], 2);
/* Now try to connect to the data port. */
if (connect(ctxt->data_file_desc, (struct sockaddr *) &data_address,
data_address_length) < 0) {
if (connect(ctxt->data_file_desc, (struct sockaddr *) &data_address, data_address_length) < 0) {
MOTION_LOG(ERR, TYPE_NETCAM, SHOW_ERRNO,_("Failed to create a data connection"));
close(ctxt->data_file_desc);
ctxt->data_file_desc = -1;
@@ -605,8 +636,7 @@ static int ftp_get_connection(ftp_context_pointer ctxt)
((struct sockaddr_in *)&data_address)->sin_port = 0;
/* Bind to the socket - should give us a unique port. */
if (bind(ctxt->data_file_desc, (struct sockaddr *) &data_address,
data_address_length) < 0) {
if (bind(ctxt->data_file_desc, (struct sockaddr *) &data_address, data_address_length) < 0) {
MOTION_LOG(ERR, TYPE_NETCAM, SHOW_ERRNO,_("bind failed"));
close(ctxt->data_file_desc);
ctxt->data_file_desc = -1;
@@ -674,8 +704,9 @@ static int ftp_close_connection(ftp_context_pointer ctxt)
fd_set rfd, efd;
struct timeval tv;
if ((ctxt == NULL) || (ctxt->control_file_desc < 0))
if ((ctxt == NULL) || (ctxt->control_file_desc < 0)) {
return -1;
}
close(ctxt->data_file_desc);
ctxt->data_file_desc = -1;
@@ -728,14 +759,16 @@ int ftp_get_socket(ftp_context_pointer ctxt)
int res, len;
int acfd;
if ((ctxt == NULL) || (ctxt->path == NULL))
if ((ctxt == NULL) || (ctxt->path == NULL)) {
return -1;
}
/* Set up the data connection. */
ctxt->data_file_desc = ftp_get_connection(ctxt);
if (ctxt->data_file_desc == -1)
if (ctxt->data_file_desc == -1) {
return -1;
}
/* Generate a "retrieve" command for the file. */
snprintf(buf, sizeof(buf), "RETR %s\r\n", ctxt->path);
@@ -842,23 +875,28 @@ int ftp_send_type(ftp_context_pointer ctxt, char type)
*/
int ftp_read(ftp_context_pointer ctxt, void *dest, int len)
{
if (ctxt == NULL)
if (ctxt == NULL) {
return -1;
}
if (ctxt->data_file_desc < 0)
if (ctxt->data_file_desc < 0) {
return 0;
}
if (dest == NULL)
if (dest == NULL) {
return -1;
}
if (len <= 0)
if (len <= 0) {
return 0;
}
len = recv(ctxt->data_file_desc, dest, len, 0);
if (len <= 0) {
if (len < 0)
if (len < 0) {
MOTION_LOG(ERR, TYPE_NETCAM, SHOW_ERRNO,_("recv failed in ftp_read"));
}
ftp_close_connection(ctxt);
}
@@ -878,8 +916,9 @@ int ftp_read(ftp_context_pointer ctxt, void *dest, int len)
*/
int ftp_close(ftp_context_pointer ctxt)
{
if (ctxt == NULL)
if (ctxt == NULL) {
return -1;
}
if (ctxt->data_file_desc >= 0) {
close(ctxt->data_file_desc);
@@ -925,8 +964,9 @@ static int netcam_read_ftp_jpeg(netcam_context_ptr netcam)
netcam_check_buffsize(buffer, FTP_BUF_SIZE);
/* Do the read */
if ((len = ftp_read(netcam->ftp, buffer->ptr + buffer->used, FTP_BUF_SIZE)) < 0)
if ((len = ftp_read(netcam->ftp, buffer->ptr + buffer->used, FTP_BUF_SIZE)) < 0) {
return -1;
}
buffer->used += len;
} while (len > 0);
@@ -942,15 +982,16 @@ int netcam_setup_ftp(netcam_context_ptr netcam, struct url_t *url)
const char *ptr;
if ((netcam->ftp = ftp_new_context()) == NULL)
if ((netcam->ftp = ftp_new_context()) == NULL) {
return -1;
}
/*
* We copy the strings out of the url structure into the ftp_context
* structure. By setting url->{string} to NULL we effectively "take
* ownership" of the string away from the URL (i.e. it won't be freed
* when we cleanup the url structure later).
*/
if (strcmp(url->path,"/")){
if (strcmp(url->path,"/")) {
netcam->ftp->path = mystrdup(url->path + 1);
} else {
netcam->ftp->path = mystrdup(url->path);

View File

@@ -96,9 +96,10 @@ static long netcam_check_content_length(char *header)
* we were able to recognize the header section and the
* number we might as well try to use it.
*/
if (length > 0)
if (length > 0) {
MOTION_LOG(WRN, TYPE_NETCAM, NO_ERRNO
,_("malformed token Content-Length but value %ld"), length);
}
}
MOTION_LOG(DBG, TYPE_NETCAM, NO_ERRNO,_("Content-Length %ld"), length);
@@ -124,8 +125,9 @@ static int netcam_check_keepalive(char *header)
{
char *content_type = NULL;
if (!header_process(header, "Keep-Alive", http_process_type, &content_type))
if (!header_process(header, "Keep-Alive", http_process_type, &content_type)) {
return -1;
}
/* We do not detect the second field or other case mixes at present. */
free(content_type);
@@ -152,11 +154,13 @@ static int netcam_check_close(char *header)
char *type = NULL;
int ret = -1;
if (!header_process(header, "Connection", http_process_type, &type))
if (!header_process(header, "Connection", http_process_type, &type)) {
return -1;
}
if (!strcmp(type, "close")) /* strcmp returns 0 for match. */
if (!strcmp(type, "close")) { /* strcmp returns 0 for match. */
ret = 1;
}
free(type);
@@ -185,8 +189,9 @@ static int netcam_check_content_type(char *header)
char *content_type = NULL;
int ret;
if (!header_process(header, "Content-type", http_process_type, &content_type))
if (!header_process(header, "Content-type", http_process_type, &content_type)) {
return -1;
}
MOTION_LOG(DBG, TYPE_NETCAM, NO_ERRNO,_("Content-type %s"), content_type);
@@ -224,8 +229,9 @@ int netcam_read_next_header(netcam_context_ptr netcam)
char *header;
/* Return if not connected */
if (netcam->sock == -1)
if (netcam->sock == -1) {
return -1;
}
/*
* We are expecting a header which *must* contain a mime-type of
* image/jpeg, and *might* contain a Content-Length.
@@ -263,8 +269,9 @@ int netcam_read_next_header(netcam_context_ptr netcam)
retval = (strstr(header, netcam->boundary) == NULL);
free(header);
if (!retval)
if (!retval) {
break;
}
}
}
@@ -277,8 +284,9 @@ int netcam_read_next_header(netcam_context_ptr netcam)
return -1;
}
if (*header == 0)
if (*header == 0) {
break;
}
if ((retval = netcam_check_content_type(header)) >= 0) {
if (retval != 1) {
@@ -407,8 +415,9 @@ int netcam_read_first_header(netcam_context_ptr netcam)
continue;
}
if (*header == 0) /* Blank line received */
if (*header == 0) { /* Blank line received */
break;
}
/* Check if this line is the content type. */
if ((ret = netcam_check_content_type(header)) >= 0) {
@@ -422,12 +431,13 @@ int netcam_read_first_header(netcam_context_ptr netcam)
*/
switch (ret) {
case 1: /* Not streaming */
if (netcam->connect_keepalive)
if (netcam->connect_keepalive) {
MOTION_LOG(NTC, TYPE_NETCAM, NO_ERRNO
,_("Non-streaming camera (keep-alive set)"));
else
} else {
MOTION_LOG(NTC, TYPE_NETCAM, NO_ERRNO
,_("Non-streaming camera (keep-alive not set)"));
}
netcam->caps.streaming = NCS_UNSUPPORTED;
break;
@@ -618,8 +628,9 @@ int netcam_read_first_header(netcam_context_ptr netcam)
void netcam_disconnect(netcam_context_ptr netcam)
{
if (netcam->sock > 0) {
if (close(netcam->sock) < 0)
if (close(netcam->sock) < 0) {
MOTION_LOG(ERR, TYPE_NETCAM, SHOW_ERRNO, _("disconnect"));
}
netcam->sock = -1;
}
@@ -659,10 +670,11 @@ int netcam_connect(netcam_context_ptr netcam, int err_flag)
/* Lookup the hostname given in the netcam URL. */
if ((ret = getaddrinfo(netcam->connect_host, port, NULL, &ai)) != 0) {
if (!err_flag)
if (!err_flag) {
MOTION_LOG(ERR, TYPE_NETCAM, NO_ERRNO
,_("getaddrinfo() failed (%s): %s")
,netcam->connect_host, gai_strerror(ret));
}
MOTION_LOG(INF, TYPE_NETCAM, NO_ERRNO,_("disconnecting netcam (1)"));
@@ -755,9 +767,10 @@ int netcam_connect(netcam_context_ptr netcam, int err_flag)
/* If the connect failed with anything except EINPROGRESS, error. */
if ((ret < 0) && (back_err != EINPROGRESS)) {
if (!err_flag)
if (!err_flag) {
MOTION_LOG(ERR, TYPE_NETCAM, SHOW_ERRNO
,_("connect() failed (%d)"), back_err);
}
MOTION_LOG(INF, TYPE_NETCAM, NO_ERRNO,_("disconnecting netcam (4)"));
@@ -773,8 +786,9 @@ int netcam_connect(netcam_context_ptr netcam, int err_flag)
ret = select(FD_SETSIZE, NULL, &fd_w, NULL, &selecttime);
if (ret == 0) { /* 0 means timeout. */
if (!err_flag)
if (!err_flag) {
MOTION_LOG(ERR, TYPE_NETCAM, NO_ERRNO, _("timeout on connect()"));
}
MOTION_LOG(INF, TYPE_NETCAM, NO_ERRNO,_("disconnecting netcam (2)"));
@@ -797,8 +811,9 @@ int netcam_connect(netcam_context_ptr netcam, int err_flag)
/* If the return code is anything except 0, error on connect. */
if (ret) {
if (!err_flag)
if (!err_flag) {
MOTION_LOG(ERR, TYPE_NETCAM, SHOW_ERRNO, _("connect returned error"));
}
MOTION_LOG(INF, TYPE_NETCAM, NO_ERRNO,_("disconnecting netcam (3)"));
@@ -818,14 +833,16 @@ 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;
@@ -849,8 +866,9 @@ void netcam_image_read_complete(netcam_context_ptr netcam)
struct timeval curtime;
netcam_buff *xchg;
if (gettimeofday(&curtime, NULL) < 0)
if (gettimeofday(&curtime, NULL) < 0) {
MOTION_LOG(WRN, TYPE_NETCAM, SHOW_ERRNO, "gettimeofday");
}
netcam->receiving->image_time = curtime;
/*
@@ -963,10 +981,11 @@ static int netcam_read_html_jpeg(netcam_context_ptr netcam)
/* Assure the target buffer is empty. */
buffer->used = 0;
/* Prepare for read loop. */
if (buffer->content_length != 0)
if (buffer->content_length != 0) {
remaining = buffer->content_length;
else
} else {
remaining = 9999999;
}
/* Now read in the data. */
while (remaining) {
@@ -974,8 +993,9 @@ static int netcam_read_html_jpeg(netcam_context_ptr netcam)
if (netcam->response->buffer_left <= 0) {
retval = rbuf_read_bufferful(netcam);
if (retval <= 0)
if (retval <= 0) {
break;
}
netcam->response->buffer_left = retval;
netcam->response->buffer_pos = netcam->response->buffer;
@@ -999,23 +1019,27 @@ static int netcam_read_html_jpeg(netcam_context_ptr netcam)
* First a quick check if the string *might*
* be in the current buffer.
*/
if (rlen > remaining)
if (rlen > remaining) {
rlen = remaining;
}
if (remaining < netcam->boundary_length)
if (remaining < netcam->boundary_length) {
break;
}
if ((ptr = memchr(rptr, *bptr, rlen)) == NULL)
if ((ptr = memchr(rptr, *bptr, rlen)) == NULL) {
/* Boundary not here (normal path) */
break;
}
/*
* At least the first char was found in the
* buffer - check for the rest.
*/
rem = rlen - (ptr - rptr);
for (ix = 1; (ix < rem) && (ix < netcam->boundary_length); ix++) {
if (ptr[ix] != bptr[ix])
if (ptr[ix] != bptr[ix]) {
break;
}
}
if ((ix != netcam->boundary_length) && (ix != rem)) {
@@ -1027,9 +1051,10 @@ static int netcam_read_html_jpeg(netcam_context_ptr netcam)
rptr += ix;
rlen -= ix;
if (rlen <= 0)
if (rlen <= 0) {
/* boundary not in buffer - go copy out */
break;
}
/*
* Not yet decided - continue
* through input.
@@ -1044,8 +1069,9 @@ static int netcam_read_html_jpeg(netcam_context_ptr netcam)
* exit the main loop.
*/
if (ix == netcam->boundary_length) {
if ((ptr - netcam->response->buffer) < (int) remaining)
if ((ptr - netcam->response->buffer) < (int) remaining) {
remaining = ptr - netcam->response->buffer;
}
/* Go copy everything up to boundary. */
break;
@@ -1118,8 +1144,9 @@ static int netcam_read_html_jpeg(netcam_context_ptr netcam)
} /* End of while(1) input buffer search. */
/* !bptr shows we're processing split boundary. */
if (!bptr)
if (!bptr) {
continue;
}
} /* end of if (bptr) */
/* boundary string not present, so just write out as much data as possible. */
@@ -1198,8 +1225,9 @@ static int netcam_http_request(netcam_context_ptr netcam)
break;;
}
if (netcam_read_first_header(netcam) >= 0)
if (netcam_read_first_header(netcam) >= 0) {
break;
}
MOTION_LOG(ERR, TYPE_NETCAM, NO_ERRNO,_("Error reading first header - re-trying"));
}
@@ -1254,10 +1282,11 @@ static int netcam_http_build_url(netcam_context_ptr netcam, struct url_t *url)
* for the camera. We assume the first of these has a higher
* relevance.
*/
if (cnt->conf.netcam_userpass)
if (cnt->conf.netcam_userpass) {
ptr = cnt->conf.netcam_userpass;
else
} else {
ptr = url->userpass;
}
/* motion_base64_encode needs up to 3 additional chars. */
if (ptr) {
@@ -1346,10 +1375,11 @@ static int netcam_http_build_url(netcam_context_ptr netcam, struct url_t *url)
* which is read-only.
*/
if (netcam->connect_keepalive)
if (netcam->connect_keepalive) {
ix += strlen(connect_req_keepalive);
else
} else {
ix += strlen(connect_req_close);
}
/*
@@ -1357,10 +1387,11 @@ static int netcam_http_build_url(netcam_context_ptr netcam, struct url_t *url)
* If the configuration is anything other than 1.1, use 1.0
* as a default. This avoids a chance of being left with none.
*/
if (netcam->connect_http_11 == TRUE)
if (netcam->connect_http_11 == TRUE) {
connect_req = connect_req_http11;
else
} else {
connect_req = connect_req_http10;
}
/*
* Now that we know how much space we need, we can allocate space
@@ -1373,10 +1404,11 @@ static int netcam_http_build_url(netcam_context_ptr netcam, struct url_t *url)
sprintf(netcam->connect_request, connect_req, ptr,
netcam->connect_host);
if (netcam->connect_keepalive)
if (netcam->connect_keepalive) {
strcat(netcam->connect_request, connect_req_keepalive);
else
} else {
strcat(netcam->connect_request, connect_req_close);
}
if (userpass) {
@@ -1424,14 +1456,16 @@ int netcam_setup_html(netcam_context_ptr netcam, struct url_t *url)
* This netcam is http-based, so build the required URL and
* structures, like the connection-string and so on.
*/
if (netcam_http_build_url(netcam, url) < 0)
if (netcam_http_build_url(netcam, url) < 0) {
return -1;
}
/*
* Then we will send our http request and get headers.
*/
if (netcam_http_request(netcam) < 0)
return -1;
if (netcam_http_request(netcam) < 0) {
return -1;
}
/*
* If this is a streaming camera, we need to position just
@@ -1469,8 +1503,9 @@ static int netcam_mjpg_buffer_refill(netcam_context_ptr netcam)
{
int retval;
if (netcam->response->buffer_left > 0)
if (netcam->response->buffer_left > 0) {
return netcam->response->buffer_left;
}
while (1) {
retval = rbuf_read_bufferful(netcam);
@@ -1485,8 +1520,9 @@ static int netcam_mjpg_buffer_refill(netcam_context_ptr netcam)
}
}
if (retval > 0)
if (retval > 0) {
break;
}
}
netcam->response->buffer_left = retval;
@@ -1546,8 +1582,9 @@ static int netcam_read_mjpg_jpeg(netcam_context_ptr netcam)
/* Assure the target buffer is empty. */
buffer->used = 0;
if (netcam_mjpg_buffer_refill(netcam) < 0)
if (netcam_mjpg_buffer_refill(netcam) < 0) {
return -1;
}
/* Loop until we have a complete JPG. */
while (1) {
@@ -1564,8 +1601,9 @@ static int netcam_read_mjpg_jpeg(netcam_context_ptr netcam)
/* If we don't have received a full header, refill our buffer. */
if (read_bytes < sizeof(mh)) {
if (netcam_mjpg_buffer_refill(netcam) < 0)
if (netcam_mjpg_buffer_refill(netcam) < 0) {
return -1;
}
}
}
@@ -1577,8 +1615,9 @@ static int netcam_read_mjpg_jpeg(netcam_context_ptr netcam)
* We shall reconnect to restart the stream, and get a chance
* to resync.
*/
if (netcam_http_request(netcam) < 0)
if (netcam_http_request(netcam) < 0) {
return -1; /* We lost the cam... bail out. */
}
/* Even there, we need to resync. */
buffer->used = 0;
continue ;
@@ -1599,8 +1638,9 @@ static int netcam_read_mjpg_jpeg(netcam_context_ptr netcam)
if (retval < (int) (mh.mh_chunksize - read_bytes)) {
/* MOTION_LOG(EMG, TYPE_NETCAM, NO_ERRNO, "Chunk incomplete, going to refill."); */
if (netcam_mjpg_buffer_refill(netcam) < 0)
if (netcam_mjpg_buffer_refill(netcam) < 0) {
return -1;
}
}
}
@@ -1648,12 +1688,14 @@ int netcam_setup_mjpg(netcam_context_ptr netcam, struct url_t *url)
* This netcam is http-based, so build the required URL and
* structures, like the connection-string and so on.
*/
if (netcam_http_build_url(netcam, url) != 0)
if (netcam_http_build_url(netcam, url) != 0) {
return -1;
}
/* Then we will send our http request and get headers. */
if (netcam_http_request(netcam) < 0)
if (netcam_http_request(netcam) < 0) {
return -1;
}
/* We have a special type of streaming camera. */
netcam->caps.streaming = NCS_BLOCK;
@@ -1728,8 +1770,9 @@ static int netcam_read_file_jpeg(netcam_context_ptr netcam)
,_("processing new file image - st_mtime %d"), netcam->file->last_st_mtime);
/* Assure there's enough room in the buffer. */
while (buffer->size < (size_t)statbuf.st_size)
while (buffer->size < (size_t)statbuf.st_size) {
netcam_check_buffsize(buffer, statbuf.st_size);
}
/* Do the read */
@@ -1765,8 +1808,9 @@ tfile_context *file_new_context(void)
void file_free_context(tfile_context* ctxt)
{
if (ctxt == NULL)
if (ctxt == NULL) {
return;
}
free(ctxt->path);
free(ctxt);
@@ -1775,8 +1819,9 @@ void file_free_context(tfile_context* ctxt)
int netcam_setup_file(netcam_context_ptr netcam, struct url_t *url)
{
if ((netcam->file = file_new_context()) == NULL)
if ((netcam->file = file_new_context()) == NULL) {
return -1;
}
/*
* We copy the strings out of the url structure into the ftp_context
@@ -1819,16 +1864,19 @@ ssize_t netcam_recv(netcam_context_ptr netcam, void *buffptr, size_t buffsize)
fd_set fd_r;
struct timeval selecttime;
if (netcam->sock < 0)
if (netcam->sock < 0) {
return -1; /* We are not connected, it's impossible to receive data. */
}
FD_ZERO(&fd_r);
FD_SET(netcam->sock, &fd_r);
selecttime = netcam->timeout;
retval = select(FD_SETSIZE, &fd_r, NULL, NULL, &selecttime);
if (retval == 0) /* 0 means timeout */
if (retval == 0) {
/* 0 means timeout */
return -1;
}
return recv(netcam->sock, buffptr, buffsize, 0);
}

View File

@@ -144,11 +144,12 @@ static void netcam_memory_src(j_decompress_ptr cinfo, char *data, int length)
{
netcam_src_ptr src;
if (cinfo->src == NULL)
if (cinfo->src == NULL) {
cinfo->src = (struct jpeg_source_mgr *)
(*cinfo->mem->alloc_small)
((j_common_ptr) cinfo, JPOOL_PERMANENT,
sizeof (netcam_source_mgr));
}
src = (netcam_src_ptr)cinfo->src;
@@ -228,8 +229,9 @@ static void netcam_output_message(j_common_ptr cinfo)
* care about.
*/
if ((cinfo->err->msg_code != JWRN_EXTRANEOUS_DATA) &&
(cinfo->err->msg_code == JWRN_NOT_SEQUENTIAL) && (!netcam->netcam_tolerant_check))
(cinfo->err->msg_code == JWRN_NOT_SEQUENTIAL) && (!netcam->netcam_tolerant_check)) {
netcam->jpeg_error |= 2; /* Set flag to show problem */
}
/*
* Format the message according to library standards.
@@ -340,8 +342,9 @@ static int netcam_init_jpeg(netcam_context_ptr netcam, j_decompress_ptr cinfo)
/* Start the decompressor. */
jpeg_start_decompress(cinfo);
if (netcam->jpeg_error)
if (netcam->jpeg_error) {
MOTION_LOG(DBG, TYPE_NETCAM, NO_ERRNO,_("jpeg_error %d"), netcam->jpeg_error);
}
return netcam->jpeg_error;
}
@@ -419,8 +422,9 @@ static int netcam_image_conv(netcam_context_ptr netcam,
rotate_map(netcam->cnt, img_data);
if (netcam->jpeg_error)
if (netcam->jpeg_error) {
MOTION_LOG(DBG, TYPE_NETCAM, NO_ERRNO,_("jpeg_error %d"), netcam->jpeg_error);
}
return netcam->jpeg_error;
}

View File

File diff suppressed because it is too large Load Diff

View File

@@ -75,8 +75,9 @@ int header_get(netcam_context_ptr netcam, char **hdr, enum header_get_flags flag
for (i = 0; 1; i++) {
int res;
/* #### Use DO_REALLOC? */
if (i > bufsize - 1)
if (i > bufsize - 1) {
*hdr = (char *)myrealloc(*hdr, (bufsize <<= 1), "");
}
res = RBUF_READCHAR (netcam, *hdr + i);
@@ -100,8 +101,9 @@ int header_get(netcam_context_ptr netcam, char **hdr, enum header_get_flags flag
return HG_ERROR;
}
/* If the next character is HT or SP, just continue. */
if (next == '\t' || next == ' ')
if (next == '\t' || next == ' ') {
continue;
}
}
/*
@@ -109,8 +111,9 @@ int header_get(netcam_context_ptr netcam, char **hdr, enum header_get_flags flag
* decrement I until it points to the last available
* whitespace.
*/
while (i > 0 && isspace((*hdr)[i - 1]))
while (i > 0 && isspace((*hdr)[i - 1])) {
--i;
}
(*hdr)[i] = '\0';
break;
@@ -141,8 +144,9 @@ int header_process(const char *header, const char *name,
while (*name && (tolower (*name) == tolower (*header)))
++name, ++header;
if (*name || *header++ != ':')
if (*name || *header++ != ':') {
return 0;
}
header += skip_lws (header);
return ((*procfun) (header, arg));
@@ -161,12 +165,14 @@ int header_extract_number(const char *header, void *closure)
const char *p = header;
long result;
for (result = 0; isdigit (*p); p++)
for (result = 0; isdigit (*p); p++) {
result = 10 * result + (*p - '0');
}
/* Failure if no number present. */
if (p == header)
if (p == header) {
return 0;
}
/* Skip trailing whitespace. */
p += skip_lws (p);
@@ -175,8 +181,9 @@ int header_extract_number(const char *header, void *closure)
*(long *)closure = result;
/* Indicate failure if trailing garbage is present. */
if (*p)
if (*p) {
return 0;
}
return 1;
}
@@ -202,8 +209,9 @@ int skip_lws(const char *string)
{
const char *p = string;
while (*p == ' ' || *p == '\t' || *p == '\r' || *p == '\n')
while (*p == ' ' || *p == '\t' || *p == '\r' || *p == '\n') {
++p;
}
return p - string;
}
@@ -243,10 +251,11 @@ void motion_base64_encode(const char *s, char *store, int length)
}
/* Pad the result if necessary... */
if (i == length + 1)
if (i == length + 1) {
*(p - 1) = '=';
else if (i == length + 2)
} else if (i == length + 2) {
*(p - 1) = *(p - 2) = '=';
}
/* ...and zero-terminate it. */
*p = '\0';
@@ -273,11 +282,13 @@ int http_process_type(const char *hdr, void *arg)
/* Locate P on `;' or the terminating zero, whichever comes first. */
const char *p = strchr (hdr, ';');
if (!p)
if (!p) {
p = hdr + strlen (hdr);
}
while (p > hdr && isspace (*(p - 1)))
while (p > hdr && isspace (*(p - 1))) {
--p;
}
*result = strdupdelim (hdr, p);
return 1;
@@ -339,8 +350,9 @@ int rbuf_flush(netcam_context_ptr netcam, char *where, int maxsize)
} else {
int howmuch = MINVAL ((int)netcam->response->buffer_left, maxsize);
if (where)
if (where) {
memcpy(where, netcam->response->buffer_pos, howmuch);
}
netcam->response->buffer_left -= howmuch;
netcam->response->buffer_pos += howmuch;
@@ -358,12 +370,14 @@ int http_result_code(const char *header)
char *cptr;
/* Assure the header starts out right. */
if (strncmp(header, "HTTP", 4))
if (strncmp(header, "HTTP", 4)) {
return -1;
}
/* Find the space following the HTTP/1.x */
if ((cptr = strchr(header+4, ' ')) == NULL)
if ((cptr = strchr(header+4, ' ')) == NULL) {
return -1;
}
return atoi(cptr + 1);
}

View File

@@ -284,11 +284,13 @@ unsigned prepare_exif(unsigned char **exif,
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. */
@@ -315,14 +317,17 @@ unsigned prepare_exif(unsigned char **exif,
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;
@@ -398,14 +403,14 @@ static void put_webp_yuv420p_file(FILE *fp,
{
/* 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;
}
@@ -413,7 +418,7 @@ static void put_webp_yuv420p_file(FILE *fp,
/* 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;
}
@@ -430,8 +435,9 @@ static void put_webp_yuv420p_file(FILE *fp,
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;
@@ -450,8 +456,9 @@ static void put_webp_yuv420p_file(FILE *fp,
}
/* 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 */
@@ -570,18 +577,21 @@ static void put_ppm_bgr24_file(FILE *picture, unsigned char *image, int width, i
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;
@@ -629,7 +639,6 @@ void overlay_smartmask(struct context *cnt, unsigned char *out)
if (smartmask[line + x] == 0 || smartmask[line + x + 1] == 0 ||
smartmask[line + width + x] == 0 ||
smartmask[line + width + x + 1] == 0) {
*out_v = 255;
*out_u = 128;
}
@@ -640,8 +649,9 @@ void overlay_smartmask(struct context *cnt, 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++;
}
}
@@ -673,7 +683,6 @@ void overlay_fixed_mask(struct context *cnt, unsigned char *out)
if (mask[line + x] == 0 || mask[line + x + 1] == 0 ||
mask[line + width + x] == 0 ||
mask[line + width + x + 1] == 0) {
*out_v = 0;
*out_u = 0;
}
@@ -684,8 +693,9 @@ void overlay_fixed_mask(struct context *cnt, 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++;
}
}
@@ -717,7 +727,6 @@ void overlay_largest_label(struct context *cnt, unsigned char *out)
if (labels[line + x] & 32768 || labels[line + x + 1] & 32768 ||
labels[line + width + x] & 32768 ||
labels[line + width + x + 1] & 32768) {
*out_u = 255;
*out_v = 128;
}
@@ -728,8 +737,9 @@ void overlay_largest_label(struct context *cnt, 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++;
}
}
@@ -761,7 +771,7 @@ int put_picture_memory(struct context *cnt, unsigned char* dest_image, int image
*/
gettimeofday(&tv1, NULL);
if (!cnt->conf.stream_grey){
if (!cnt->conf.stream_grey) {
return jpgutl_put_yuv420p(dest_image, image_size, image,
width, height, quality, cnt ,&tv1,NULL);
} else {
@@ -792,13 +802,17 @@ static void put_picture_fd(struct context *cnt, FILE *picture, unsigned char *im
if (cnt->imgs.picture_type == IMAGE_TYPE_PPM) {
put_ppm_bgr24_file(picture, image, width, height);
} else {
if (dummy == 1){
if (dummy == 1) {
#ifdef HAVE_WEBP
if (cnt->imgs.picture_type == IMAGE_TYPE_WEBP)
put_webp_yuv420p_file(picture, image, width, height, quality, cnt, &(cnt->current_image->timestamp_tv), &(cnt->current_image->location));
if (cnt->imgs.picture_type == IMAGE_TYPE_WEBP) {
put_webp_yuv420p_file(picture, image, width, height, quality, cnt
, &(cnt->current_image->timestamp_tv), &(cnt->current_image->location));
}
#endif /* HAVE_WEBP */
if (cnt->imgs.picture_type == IMAGE_TYPE_JPEG)
put_jpeg_yuv420p_file(picture, image, width, height, quality, cnt, &(cnt->current_image->timestamp_tv), &(cnt->current_image->location));
if (cnt->imgs.picture_type == IMAGE_TYPE_JPEG) {
put_jpeg_yuv420p_file(picture, image, width, height, quality, cnt
, &(cnt->current_image->timestamp_tv), &(cnt->current_image->location));
}
} else {
put_jpeg_grey_file(picture, image, width, height, quality, cnt, &(cnt->current_image->timestamp_tv), &(cnt->current_image->location));
}
@@ -859,9 +873,11 @@ unsigned char *get_pgm(FILE *picture, int width, int height)
/* Skip comment */
line[0] = '#';
while (line[0] == '#')
if (!fgets(line, 255, picture))
while (line[0] == '#') {
if (!fgets(line, 255, picture)) {
return NULL;
}
}
/* Read image size */
if (sscanf(line, "%d %d", &mask_width, &mask_height) != 2) {
@@ -872,9 +888,11 @@ unsigned char *get_pgm(FILE *picture, int width, int height)
/* Maximum value */
line[0] = '#';
while (line[0] == '#')
if (!fgets(line, 255, picture))
while (line[0] == '#') {
if (!fgets(line, 255, picture)) {
return NULL;
}
}
if (sscanf(line, "%d", &maxval) != 1) {
MOTION_LOG(ERR, TYPE_ALL, SHOW_ERRNO
@@ -890,11 +908,13 @@ unsigned char *get_pgm(FILE *picture, int width, int height)
image = 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;
}
}
@@ -974,16 +994,18 @@ void pic_scale_img(int width_src, int height_src, unsigned char *img_src, unsign
{
int i = 0, x, y;
for (y = 0; y < height_src; y+=2)
for (x = 0; x < width_src; x+=2)
for (y = 0; y < height_src; y+=2) {
for (x = 0; x < width_src; x+=2) {
img_dst[i++] = img_src[y * width_src + x];
}
}
for (y = 0; y < height_src / 2; y+=2)
for (x = 0; x < width_src; x += 4)
{
for (y = 0; y < height_src / 2; y+=2) {
for (x = 0; x < width_src; x += 4) {
img_dst[i++] = img_src[(width_src * height_src) + (y * width_src) + x];
img_dst[i++] = img_src[(width_src * height_src) + (y * width_src) + (x + 1)];
}
}
return;
}

View File

@@ -136,9 +136,9 @@ static void rot90cw(unsigned char *src, register unsigned char *dst, int size,
endp = src + size;
for (base = endp - width; base < endp; base++) {
src = base;
for (j = 0; j < height; j++, src -= width)
for (j = 0; j < height; j++, src -= width) {
*dst++ = *src;
}
}
}
@@ -170,9 +170,9 @@ static inline void rot90ccw(unsigned char *src, register unsigned char *dst,
dst = dst + size - 1;
for (base = endp - width; base < endp; base++) {
src = base;
for (j = 0; j < height; j++, src -= width)
for (j = 0; j < height; j++, src -= width) {
*dst-- = *src;
}
}
}
@@ -253,15 +253,19 @@ void rotate_init(struct context *cnt)
* If we're not rotating, let's exit once we have setup the capture dimensions
* and output dimensions properly.
*/
if (cnt->rotate_data.degrees == 0) return;
if (cnt->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 ((cnt->rotate_data.degrees == 90) || (cnt->rotate_data.degrees == 270)){
if ((cnt->rotate_data.degrees == 90) || (cnt->rotate_data.degrees == 270)) {
cnt->rotate_data.buffer_norm = mymalloc(size_norm);
if (size_high > 0 ) cnt->rotate_data.buffer_high = mymalloc(size_high);
if (size_high > 0) {
cnt->rotate_data.buffer_high = mymalloc(size_high);
}
}
}
@@ -280,11 +284,13 @@ void rotate_init(struct context *cnt)
void rotate_deinit(struct context *cnt)
{
if (cnt->rotate_data.buffer_norm)
if (cnt->rotate_data.buffer_norm) {
free(cnt->rotate_data.buffer_norm);
}
if (cnt->rotate_data.buffer_high)
if (cnt->rotate_data.buffer_high) {
free(cnt->rotate_data.buffer_high);
}
}
/**
@@ -320,11 +326,15 @@ int rotate_map(struct context *cnt, struct image_data *img_data)
unsigned char *img;
unsigned char *temp_buff;
if (cnt->rotate_data.degrees == 0 && cnt->rotate_data.axis == FLIP_TYPE_NONE) return 0;
if (cnt->rotate_data.degrees == 0 && cnt->rotate_data.axis == FLIP_TYPE_NONE) {
return 0;
}
indx = 0;
indx_max = 0;
if ((cnt->rotate_data.capture_width_high != 0) && (cnt->rotate_data.capture_height_high != 0)) indx_max = 1;
if ((cnt->rotate_data.capture_width_high != 0) && (cnt->rotate_data.capture_height_high != 0)) {
indx_max = 1;
}
while (indx <= indx_max) {
deg = cnt->rotate_data.degrees;
@@ -332,7 +342,7 @@ int rotate_map(struct context *cnt, struct image_data *img_data)
wh4 = 0;
w2 = 0;
h2 = 0;
if (indx == 0 ){
if (indx == 0) {
img = img_data->image_norm;
width = cnt->rotate_data.capture_width_norm;
height = cnt->rotate_data.capture_height_norm;

View File

@@ -75,8 +75,9 @@ unsigned int track_center(struct context *cnt, int dev ATTRIBUTE_UNUSED,
{
struct coord cent;
if (!manual && !cnt->track.active)
if (!manual && !cnt->track.active) {
return 0;
}
if (cnt->track.type == TRACK_TYPE_STEPPER) {
unsigned int ret;
@@ -84,21 +85,23 @@ unsigned int track_center(struct context *cnt, int dev ATTRIBUTE_UNUSED,
if (!ret) {
MOTION_LOG(ERR, TYPE_TRACK, SHOW_ERRNO,_("internal error"));
return 0;
} else {
return ret;
}
else return ret;
} else if (cnt->track.type == TRACK_TYPE_SERVO) {
return servo_center(cnt, xoff, yoff);
}
#ifdef HAVE_V4L2
else if (cnt->track.type == TRACK_TYPE_PWC)
#ifdef HAVE_V4L2 /*dreadful coding method imo */
} else if (cnt->track.type == TRACK_TYPE_PWC) {
return lqos_center(cnt, dev, xoff, yoff);
else if (cnt->track.type == TRACK_TYPE_UVC)
} else if (cnt->track.type == TRACK_TYPE_UVC) {
return uvc_center(cnt, dev, xoff, yoff);
#endif
else if (cnt->track.type == TRACK_TYPE_IOMOJO)
} else if (cnt->track.type == TRACK_TYPE_IOMOJO) {
return iomojo_center(cnt, xoff, yoff);
else if (cnt->track.type == TRACK_TYPE_GENERIC) {
if (cnt->track.generic_move){
} else if (cnt->track.type == TRACK_TYPE_GENERIC) {
if (cnt->track.generic_move) {
cent.x = -cnt->track_posx;
cent.y = -cnt->track_posy;
return generic_move(cnt, TRACK_CENTER, manual,0 ,0 ,&cent , NULL);
@@ -118,26 +121,30 @@ unsigned int track_move(struct context *cnt, int dev, struct coord *cent, struct
unsigned int manual)
{
if (!manual && !cnt->track.active)
if (!manual && !cnt->track.active) {
return 0;
}
if (cnt->track.type == TRACK_TYPE_STEPPER)
if (cnt->track.type == TRACK_TYPE_STEPPER) {
return stepper_move(cnt, cent, imgs);
else if (cnt->track.type == TRACK_TYPE_SERVO)
} else if (cnt->track.type == TRACK_TYPE_SERVO) {
return servo_move(cnt, cent, imgs, manual);
#ifdef HAVE_V4L2
else if (cnt->track.type == TRACK_TYPE_PWC)
} else if (cnt->track.type == TRACK_TYPE_PWC) {
return lqos_move(cnt, dev, cent, imgs, manual);
else if (cnt->track.type == TRACK_TYPE_UVC)
} else if (cnt->track.type == TRACK_TYPE_UVC) {
return uvc_move(cnt, dev, cent, imgs, manual);
#endif
else if (cnt->track.type == TRACK_TYPE_IOMOJO)
} else if (cnt->track.type == TRACK_TYPE_IOMOJO) {
return iomojo_move(cnt, dev, cent, imgs);
else if (cnt->track.type == TRACK_TYPE_GENERIC) {
if (cnt->track.generic_move)
} else if (cnt->track.type == TRACK_TYPE_GENERIC) {
if (cnt->track.generic_move) {
return generic_move(cnt, TRACK_MOVE, manual, 0, 0, cent, imgs);
else
} else {
return cnt->track.move_wait; // FIX ME. I chose to return something reasonable.
}
}
MOTION_LOG(WRN, TYPE_TRACK, SHOW_ERRNO
@@ -169,7 +176,9 @@ static unsigned int stepper_command(struct context *cnt, unsigned int motor,
return 0;
}
while (read(cnt->track.dev, buffer, 1) != 1 && time(NULL) < timeout + 1);
while (read(cnt->track.dev, buffer, 1) != 1 && time(NULL) < timeout + 1) {
continue;
}
if (time(NULL) >= timeout + 2) {
MOTION_LOG(ERR, TYPE_TRACK, SHOW_ERRNO,_("Status byte timeout!"));
@@ -225,24 +234,33 @@ static unsigned int stepper_center(struct context *cnt, int x_offset, int y_offs
stepper_command(cnt, cnt->track.motorx, STEPPER_COMMAND_SPEED, cnt->track.speed);
stepper_command(cnt, cnt->track.motorx, STEPPER_COMMAND_LEFT_N, cnt->track.maxx);
while (stepper_status(cnt, cnt->track.motorx) & STEPPER_STATUS_LEFT);
while (stepper_status(cnt, cnt->track.motorx) & STEPPER_STATUS_LEFT) {
continue;
}
stepper_command(cnt, cnt->track.motorx, STEPPER_COMMAND_RIGHT_N,
cnt->track.maxx / 2 + x_offset * cnt->track.stepsize);
while (stepper_status(cnt, cnt->track.motorx) & STEPPER_STATUS_RIGHT);
while (stepper_status(cnt, cnt->track.motorx) & STEPPER_STATUS_RIGHT) {
continue;
}
/* y-axis */
stepper_command(cnt, cnt->track.motory, STEPPER_COMMAND_SPEED, cnt->track.speed);
stepper_command(cnt, cnt->track.motory, STEPPER_COMMAND_UP_N, cnt->track.maxy);
while (stepper_status(cnt, cnt->track.motory) & STEPPER_STATUS_UP)
while (stepper_status(cnt, cnt->track.motory) & STEPPER_STATUS_UP) {
continue;
}
stepper_command(cnt, cnt->track.motory, STEPPER_COMMAND_DOWN_N,
cnt->track.maxy / 2 + y_offset * cnt->track.stepsize);
while (stepper_status(cnt, cnt->track.motory) & STEPPER_STATUS_DOWN);
while (stepper_status(cnt, cnt->track.motory) & STEPPER_STATUS_DOWN) {
continue;
}
return cnt->track.move_wait;
}
@@ -283,7 +301,9 @@ static unsigned int stepper_move(struct context *cnt,
data = data * cnt->track.stepsize / imgs->width;
if (data) stepper_command(cnt, cnt->track.motorx, command, data);
if (data) {
stepper_command(cnt, cnt->track.motorx, command, data);
}
/* y-axis */
@@ -299,8 +319,9 @@ static unsigned int stepper_move(struct context *cnt,
data = data * cnt->track.stepsize / imgs->height;
if (data)
if (data) {
stepper_command(cnt, cnt->track.motory, command, data);
}
return cnt->track.move_wait;
@@ -368,7 +389,9 @@ static unsigned int servo_command(struct context *cnt, unsigned int motor,
return 0;
}
while (read(cnt->track.dev, buffer, 1) != 1 && time(NULL) < timeout + 1);
while (read(cnt->track.dev, buffer, 1) != 1 && time(NULL) < timeout + 1) {
continue;
}
if (time(NULL) >= timeout + 2) {
MOTION_LOG(ERR, TYPE_TRACK, NO_ERRNO,_("Status byte timeout!"));
@@ -427,10 +450,11 @@ static unsigned int servo_move(struct context *cnt, struct coord *cent,
if ((cnt->track.motorx_reverse && (offset > 0)) ||
(!cnt->track.motorx_reverse && (offset < 0)))
(!cnt->track.motorx_reverse && (offset < 0))) {
command = SERVO_COMMAND_LEFT_N;
else
} else {
command = SERVO_COMMAND_RIGHT_N;
}
data = abs(offset);
@@ -453,10 +477,11 @@ static unsigned int servo_move(struct context *cnt, struct coord *cent,
offset = cent->y * cnt->track.stepsize;
if ((cnt->track.motory_reverse && (offset > 0)) ||
(!cnt->track.motory_reverse && (offset < 0)))
(!cnt->track.motory_reverse && (offset < 0))) {
command = SERVO_COMMAND_UP_N;
else
} else {
command = SERVO_COMMAND_DOWN_N;
}
data = abs(offset);
@@ -478,19 +503,21 @@ static unsigned int servo_move(struct context *cnt, struct coord *cent,
/* Move left */
if (cent->x < imgs->width / 2) {
if (cnt->track.motorx_reverse)
if (cnt->track.motorx_reverse) {
command = SERVO_COMMAND_RIGHT_N;
else
} else {
command = SERVO_COMMAND_LEFT_N;
}
data = imgs->width / 2 - cent->x;
}
/* Move right */
if (cent->x > imgs->width / 2) {
if (cnt->track.motorx_reverse)
if (cnt->track.motorx_reverse) {
command = SERVO_COMMAND_LEFT_N;
else
} else {
command = SERVO_COMMAND_RIGHT_N;
}
data = cent->x - imgs->width / 2;
}
@@ -528,19 +555,21 @@ static unsigned int servo_move(struct context *cnt, struct coord *cent,
/* Move down */
if (cent->y < imgs->height / 2) {
if (cnt->track.motory_reverse)
if (cnt->track.motory_reverse) {
command = SERVO_COMMAND_UP_N;
else
} else {
command = SERVO_COMMAND_DOWN_N;
}
data = imgs->height / 2 - cent->y;
}
/* Move up */
if (cent->y > imgs->height / 2) {
if (cnt->track.motory_reverse)
if (cnt->track.motory_reverse) {
command = SERVO_COMMAND_DOWN_N;
else
} else {
command = SERVO_COMMAND_UP_N;
}
data = cent->y - imgs->height / 2;
}
@@ -616,10 +645,11 @@ static unsigned int servo_center(struct context *cnt, int x_offset, int y_offset
,cnt->track.stepsize);
/* x-axis */
if (cnt->track.motorx_reverse)
if (cnt->track.motorx_reverse) {
x_offset_abs = (128 - cnt->track.homex) - (x_offset * cnt->track.stepsize) + 128;
else
} else {
x_offset_abs = cnt->track.homex + (x_offset * cnt->track.stepsize);
}
if (x_offset_abs <= cnt->track.maxx && x_offset_abs >= cnt->track.minx) {
/* Set Speed , TODO : it should be done only when speed changes */
@@ -628,10 +658,11 @@ static unsigned int servo_center(struct context *cnt, int x_offset, int y_offset
}
/* y-axis */
if (cnt->track.motory_reverse)
if (cnt->track.motory_reverse) {
y_offset_abs = (128 - cnt->track.homey) - (y_offset * cnt->track.stepsize) + 128;
else
} else {
y_offset_abs = cnt->track.homey + (y_offset * cnt->track.stepsize);
}
if (y_offset_abs <= cnt->track.maxy && y_offset_abs >= cnt->track.minx) {
/* Set Speed , TODO : it should be done only when speed changes */
@@ -654,11 +685,14 @@ static char iomojo_command(struct context *cnt, char *command, int len, unsigned
char buffer[1];
time_t timeout = time(NULL);
if (write(cnt->track.dev, command, len) != len)
if (write(cnt->track.dev, command, len) != len) {
return 0;
}
if (ret) {
while (read(cnt->track.dev, buffer, 1) != 1 && time(NULL) < timeout + 2);
while (read(cnt->track.dev, buffer, 1) != 1 && time(NULL) < timeout + 2) {
continue;
}
if (time(NULL) >= timeout + 2) {
MOTION_LOG(ERR, TYPE_TRACK, SHOW_ERRNO,_("Return byte timeout!"));
@@ -677,8 +711,9 @@ static void iomojo_setspeed(struct context *cnt, unsigned int speed)
command[1] = cnt->track.iomojo_id;
command[2] = speed;
if (iomojo_command(cnt, command, 3, 1) != IOMOJO_SETSPEED_RET)
if (iomojo_command(cnt, command, 3, 1) != IOMOJO_SETSPEED_RET) {
MOTION_LOG(ERR, TYPE_TRACK, SHOW_ERRNO,_("Unable to set camera speed"));
}
}
static void iomojo_movehome(struct context *cnt)
@@ -736,11 +771,13 @@ static unsigned int iomojo_center(struct context *cnt, int x_offset, int y_offse
y_offset *= -1;
}
if (x_offset > 180)
if (x_offset > 180) {
x_offset = 180;
}
if (y_offset > 60)
if (y_offset > 60) {
y_offset = 60;
}
command[0] = IOMOJO_MOVEOFFSET_CMD;
command[1] = cnt->track.iomojo_id;
@@ -763,9 +800,11 @@ static unsigned int iomojo_move(struct context *cnt, int dev, struct coord *cent
int nx = 0, ny = 0;
int i;
if (dev < 0)
if (!iomojo_center(cnt, 0, 0))
if (dev < 0) {
if (!iomojo_center(cnt, 0, 0)) {
return 0;
}
}
if (cent->x < imgs->width / 2) {
direction |= IOMOJO_DIRECTION_LEFT;
@@ -791,11 +830,13 @@ static unsigned int iomojo_move(struct context *cnt, int dev, struct coord *cent
ny = ny * 72 / imgs->height;
if (nx || ny) {
if (nx > 180)
if (nx > 180) {
nx = 180;
}
if (ny > 60)
if (ny > 60) {
ny = 60;
}
command[0] = IOMOJO_MOVEOFFSET_CMD;
command[1] = cnt->track.iomojo_id;
@@ -805,10 +846,11 @@ static unsigned int iomojo_move(struct context *cnt, int dev, struct coord *cent
iomojo_command(cnt, command, 5, 0);
/* Number of frames to skip while moving */
if (ny >= nx)
if (ny >= nx) {
i = 25 * ny / 90;
else
} else {
i = 25 * nx / 90;
}
return i;
}
@@ -851,17 +893,20 @@ static unsigned int lqos_center(struct context *cnt, int dev, int x_angle, int y
cnt->track.maxy = pmr.tilt_max;
}
if (ioctl(dev, VIDIOCPWCMPTGANGLE, &pma) == -1)
if (ioctl(dev, VIDIOCPWCMPTGANGLE, &pma) == -1) {
MOTION_LOG(ERR, TYPE_TRACK, SHOW_ERRNO
,_("ioctl VIDIOCPWCMPTGANGLE"));
}
pma.absolute = 1;
if (x_angle * 100 < cnt->track.maxx && x_angle * 100 > cnt->track.minx)
if (x_angle * 100 < cnt->track.maxx && x_angle * 100 > cnt->track.minx) {
pma.pan = x_angle * 100;
}
if (y_angle * 100 < cnt->track.maxy && y_angle * 100 > cnt->track.miny)
if (y_angle * 100 < cnt->track.maxy && y_angle * 100 > cnt->track.miny) {
pma.tilt = y_angle * 100;
}
if (ioctl(dev, VIDIOCPWCMPTSANGLE, &pma) == -1) {
MOTION_LOG(ERR, TYPE_TRACK, SHOW_ERRNO
@@ -885,11 +930,12 @@ static unsigned int lqos_move(struct context *cnt, int dev, struct coord *cent,
/* If we are on auto track we calculate delta, otherwise we use user input in degrees times 100 */
if (!manual) {
if (delta_x > imgs->width * 3/8 && delta_x < imgs->width * 5/8)
if (delta_x > imgs->width * 3/8 && delta_x < imgs->width * 5/8) {
return 0;
if (delta_y > imgs->height * 3/8 && delta_y < imgs->height * 5/8)
}
if (delta_y > imgs->height * 3/8 && delta_y < imgs->height * 5/8) {
return 0;
}
move_x_degrees = delta_x * cnt->track.step_angle_x * 100 / (imgs->width / 2);
move_y_degrees = -delta_y * cnt->track.step_angle_y * 100 / (imgs->height / 2);
} else {
@@ -912,26 +958,31 @@ static unsigned int lqos_move(struct context *cnt, int dev, struct coord *cent,
}
/* Get current camera position */
if (ioctl(dev, VIDIOCPWCMPTGANGLE, &pma) == -1)
if (ioctl(dev, VIDIOCPWCMPTGANGLE, &pma) == -1) {
MOTION_LOG(ERR, TYPE_TRACK, SHOW_ERRNO
,_("ioctl VIDIOCPWCMPTGANGLE"));
}
/*
* Check current position of camera and see if we need to adjust
* values down to what is left to move
*/
if (move_x_degrees < 0 && (cnt->track.minx - pma.pan) > move_x_degrees)
if (move_x_degrees < 0 && (cnt->track.minx - pma.pan) > move_x_degrees) {
move_x_degrees = (cnt->track.minx - pma.pan);
}
if (move_x_degrees > 0 && (cnt->track.maxx - pma.pan) < move_x_degrees)
if (move_x_degrees > 0 && (cnt->track.maxx - pma.pan) < move_x_degrees) {
move_x_degrees = (cnt->track.maxx - pma.pan);
}
if (move_y_degrees < 0 && (cnt->track.miny - pma.tilt) > move_y_degrees)
if (move_y_degrees < 0 && (cnt->track.miny - pma.tilt) > move_y_degrees) {
move_y_degrees = (cnt->track.miny - pma.tilt);
}
if (move_y_degrees > 0 && (cnt->track.maxy - pma.tilt) < move_y_degrees)
if (move_y_degrees > 0 && (cnt->track.maxy - pma.tilt) < move_y_degrees) {
move_y_degrees = (cnt->track.maxy - pma.tilt);
}
/* Move camera relative to current position */
pma.absolute = 0;
@@ -1040,11 +1091,13 @@ static unsigned int uvc_center(struct context *cnt, int dev, int x_angle, int y_
,_("INPUT_PARAM_ABS X_Angel %d, Y_Angel %d ")
,x_angle, y_angle);
if (x_angle <= cnt->track.maxx && x_angle >= cnt->track.minx)
if (x_angle <= cnt->track.maxx && x_angle >= cnt->track.minx) {
move_x_degrees = x_angle - (cnt->track.pan_angle);
}
if (y_angle <= cnt->track.maxy && y_angle >= cnt->track.miny)
if (y_angle <= cnt->track.maxy && y_angle >= cnt->track.miny) {
move_y_degrees = y_angle - (cnt->track.tilt_angle);
}
/*
@@ -1077,8 +1130,9 @@ static unsigned int uvc_center(struct context *cnt, int dev, int x_angle, int y_
}
/* DWe 30.03.07 We must wait a little,before we set the next CMD, otherwise PAN is mad ... */
if ((move_x_degrees != 0) && (move_y_degrees != 0))
if ((move_x_degrees != 0) && (move_y_degrees != 0)) {
SLEEP(1, 0);
}
if (move_y_degrees != 0) {
control_s.id = V4L2_CID_TILT_RELATIVE;
@@ -1179,11 +1233,12 @@ static unsigned int uvc_move(struct context *cnt, int dev, struct coord *cent,
/* If we are on auto track we calculate delta, otherwise we use user input in degrees */
if (!manual) {
if (delta_x > imgs->width * 3/8 && delta_x < imgs->width * 5/8)
if (delta_x > imgs->width * 3/8 && delta_x < imgs->width * 5/8) {
return 0;
if (delta_y > imgs->height * 3/8 && delta_y < imgs->height * 5/8)
}
if (delta_y > imgs->height * 3/8 && delta_y < imgs->height * 5/8) {
return 0;
}
move_x_degrees = delta_x * cnt->track.step_angle_x / (imgs->width / 2);
move_y_degrees = -delta_y * cnt->track.step_angle_y / (imgs->height / 2);
} else {
@@ -1207,17 +1262,21 @@ static unsigned int uvc_move(struct context *cnt, int dev, struct coord *cent,
* Check current position of camera and see if we need to adjust
* values down to what is left to move
*/
if (move_x_degrees < 0 && (cnt->track.minx - cnt->track.pan_angle) > move_x_degrees)
if (move_x_degrees < 0 && (cnt->track.minx - cnt->track.pan_angle) > move_x_degrees) {
move_x_degrees = cnt->track.minx - cnt->track.pan_angle;
}
if (move_x_degrees > 0 && (cnt->track.maxx - cnt->track.pan_angle) < move_x_degrees)
if (move_x_degrees > 0 && (cnt->track.maxx - cnt->track.pan_angle) < move_x_degrees) {
move_x_degrees = cnt->track.maxx - cnt->track.pan_angle;
}
if (move_y_degrees < 0 && (cnt->track.miny - cnt->track.tilt_angle) > move_y_degrees)
if (move_y_degrees < 0 && (cnt->track.miny - cnt->track.tilt_angle) > move_y_degrees) {
move_y_degrees = cnt->track.miny - cnt->track.tilt_angle;
}
if (move_y_degrees > 0 && (cnt->track.maxy - cnt->track.tilt_angle) < move_y_degrees)
if (move_y_degrees > 0 && (cnt->track.maxy - cnt->track.tilt_angle) < move_y_degrees) {
move_y_degrees = cnt->track.maxy - cnt->track.tilt_angle;
}
}
MOTION_LOG(DBG, TYPE_TRACK, NO_ERRNO
@@ -1261,8 +1320,9 @@ static unsigned int uvc_move(struct context *cnt, int dev, struct coord *cent,
}
/* DWe 30.03.07 We must wait a little,before we set the next CMD, otherwise PAN is mad ... */
if ((move_x_degrees != 0) && (move_y_degrees != 0))
if ((move_x_degrees != 0) && (move_y_degrees != 0)) {
SLEEP (1, 0);
}
if (move_y_degrees != 0) {
@@ -1289,11 +1349,13 @@ static unsigned int uvc_move(struct context *cnt, int dev, struct coord *cent,
,_("Before_REL_Y_Angel : x= %d , Y= %d")
,cnt->track.pan_angle, cnt->track.tilt_angle);
if (move_x_degrees != 0)
if (move_x_degrees != 0) {
cnt->track.pan_angle += -pan.s16.pan / INCPANTILT;
}
if (move_y_degrees != 0)
if (move_y_degrees != 0) {
cnt->track.tilt_angle += -pan.s16.tilt / INCPANTILT;
}
MOTION_LOG(DBG, TYPE_TRACK, NO_ERRNO
,_("After_REL_Y_Angel : x= %d , Y= %d")
@@ -1321,8 +1383,9 @@ static unsigned int generic_move(struct context *cnt, enum track_action action,
setsid();
/* Provides data as environment variables */
if (manual)
if (manual) {
setenv("TRACK_MANUAL", "manual", 1);
}
switch (action) {
case TRACK_CENTER:
setenv("TRACK_ACTION", "center", 1);
@@ -1352,8 +1415,9 @@ static unsigned int generic_move(struct context *cnt, enum track_action action,
* Close any file descriptor except console because we will
* like to see error messages
*/
for (i = getdtablesize() - 1; i > 2; i--)
for (i = getdtablesize() - 1; i > 2; i--) {
close(i);
}
execl("/bin/sh", "sh", "-c", fmtcmd, " &", NULL);

View File

@@ -25,7 +25,9 @@ void translate_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
}
@@ -58,7 +60,7 @@ void translate_init(void)
char* translate_text(const char *msgid)
{
#ifdef HAVE_GETTEXT
if (nls_enabled){
if (nls_enabled) {
return (char*)gettext(msgid);
} else {
return (char*)msgid;

View File

@@ -323,8 +323,9 @@ static int bktr_set_geometry(struct video_dev *viddev, int width, int height)
h_max = BKTR_PAL_HEIGHT;
}
if (height <= h_max / 2)
if (height <= h_max / 2) {
geom.oformat |= METEOR_GEO_EVEN_ONLY;
}
geom.frames = 1;
@@ -346,17 +347,29 @@ static void bktr_picture_controls(struct context *cnt, struct video_dev *viddev)
int indx_user, retcd;
struct vdev_usrctrl_ctx *usritem;
if (!cnt->vdev->update_parms) return;
if (!cnt->vdev->update_parms) {
return;
}
retcd = vid_parms_parse(cnt);
if (retcd < 0) return;
if (retcd < 0) {
return;
}
for (indx_user=0; indx_user<cnt->vdev->usrctrl_count; indx_user++){
for (indx_user=0; indx_user<cnt->vdev->usrctrl_count; indx_user++) {
usritem=&cnt->vdev->usrctrl_array[indx_user];
if (!strcasecmp(usritem->ctrl_name,"contrast")) bktr_set_contrast(dev,usritem->ctrl_value);
if (!strcasecmp(usritem->ctrl_name,"hue")) bktr_set_hue(dev,usritem->ctrl_value);
if (!strcasecmp(usritem->ctrl_name,"brightness")) bktr_set_brightness(dev,usritem->ctrl_value);
if (!strcasecmp(usritem->ctrl_name,"saturation")) bktr_set_saturation(dev,usritem->ctrl_value);
if (!strcasecmp(usritem->ctrl_name,"contrast")) {
bktr_set_contrast(dev,usritem->ctrl_value);
}
if (!strcasecmp(usritem->ctrl_name,"hue")) {
bktr_set_hue(dev,usritem->ctrl_value);
}
if (!strcasecmp(usritem->ctrl_name,"brightness")) {
bktr_set_brightness(dev,usritem->ctrl_value);
}
if (!strcasecmp(usritem->ctrl_name,"saturation")) {
bktr_set_saturation(dev,usritem->ctrl_value);
}
}
cnt->vdev->update_parms = FALSE;
@@ -510,10 +523,11 @@ static unsigned char *bktr_device_init(struct video_dev *viddev, int width, int
}
}
if (viddev->bktr_method == METEOR_CAP_CONTINOUS)
if (viddev->bktr_method == METEOR_CAP_CONTINOUS) {
MOTION_LOG(NTC, TYPE_VIDEO, NO_ERRNO, "METEORCAPTUR METEOR_CAP_CONTINOUS");
else
} else {
MOTION_LOG(NTC, TYPE_VIDEO, NO_ERRNO, "METEORCAPTUR METEOR_CAP_SINGLE");
}
SLEEP(1, 0);
@@ -567,14 +581,16 @@ static int bktr_capture(struct video_dev *viddev, unsigned char *map, int width,
cap_map = viddev->bktr_buffers[viddev->bktr_curbuffer];
viddev->bktr_curbuffer++;
if (viddev->bktr_curbuffer >= viddev->bktr_maxbuffer)
if (viddev->bktr_curbuffer >= viddev->bktr_maxbuffer) {
viddev->bktr_curbuffer = 0;
}
/* Capture */
if (viddev->bktr_method == METEOR_CAP_CONTINOUS) {
if (bktr_frame_waiting)
if (bktr_frame_waiting) {
bktr_frame_waiting = 0;
}
} else if (ioctl(dev_bktr, METEORCAPTUR, &single) < 0) {
MOTION_LOG(ERR, TYPE_VIDEO, SHOW_ERRNO
@@ -631,20 +647,24 @@ static void bktr_set_input(struct context *cnt, struct video_dev *viddev, unsign
int dummy;
long frequnits = freq;
if ((dummy = bktr_set_input_device(viddev, input)) == -1)
if ((dummy = bktr_set_input_device(viddev, input)) == -1) {
return;
}
viddev->input = dummy;
if ((dummy = bktr_set_input_format(viddev, norm)) == -1)
if ((dummy = bktr_set_input_format(viddev, norm)) == -1) {
return;
}
viddev->norm = dummy;
if ((viddev->bktr_tuner != NULL) && (viddev->input == BKTR_IN_TV) &&
if ((viddev->bktr_tuner != NULL) &&
(viddev->input == BKTR_IN_TV) &&
(frequnits > 0)) {
if (bktr_set_freq(viddev, freq) == -1)
if (bktr_set_freq(viddev, freq) == -1) {
return;
}
}
bktr_picture_controls(cnt, viddev);
@@ -652,8 +672,9 @@ static void bktr_set_input(struct context *cnt, struct video_dev *viddev, unsign
viddev->frequency = freq;
/* skip a few frames if needed */
for (dummy = 0; dummy < skip; dummy++)
for (dummy = 0; dummy < skip; dummy++) {
bktr_capture(viddev, map, width, height);
}
} else {
/* No round robin - we only adjust picture controls */
bktr_picture_controls(cnt, viddev);
@@ -693,8 +714,9 @@ void bktr_cleanup(struct context *cnt)
pthread_mutex_lock(&bktr_mutex);
while (dev) {
if (dev->fd_device == cnt->video_dev)
if (dev->fd_device == cnt->video_dev) {
break;
}
prev = dev;
dev = dev->next;
}
@@ -705,15 +727,15 @@ void bktr_cleanup(struct context *cnt)
cnt->video_dev = -1;
/* free the information we collected regarding the controls */
if (cnt->vdev != NULL){
if (cnt->vdev->usrctrl_count > 0){
for (indx=0;indx<cnt->vdev->usrctrl_count;indx++){
if (cnt->vdev != NULL) {
if (cnt->vdev->usrctrl_count > 0) {
for (indx=0;indx<cnt->vdev->usrctrl_count;indx++) {
free(cnt->vdev->usrctrl_array[indx].ctrl_name);
cnt->vdev->usrctrl_array[indx].ctrl_name=NULL;
}
}
cnt->vdev->usrctrl_count = 0;
if (cnt->vdev->usrctrl_array != NULL){
if (cnt->vdev->usrctrl_array != NULL) {
free(cnt->vdev->usrctrl_array);
cnt->vdev->usrctrl_array = NULL;
}
@@ -730,8 +752,9 @@ void bktr_cleanup(struct context *cnt)
MOTION_LOG(NTC, TYPE_VIDEO, NO_ERRNO
,_("Closing video device %s"), dev->video_device);
if (dev->bktr_fdtuner > 0)
if (dev->bktr_fdtuner > 0) {
close(dev->bktr_fdtuner);
}
if (dev->fd_device > 0) {
if (dev->bktr_method == METEOR_CAP_CONTINOUS) {
@@ -750,10 +773,11 @@ void bktr_cleanup(struct context *cnt)
pthread_mutex_lock(&bktr_mutex);
/* Remove from list */
if (prev == NULL)
if (prev == NULL) {
viddevs = dev->next;
else
} else {
prev->next = dev->next;
}
pthread_mutex_unlock(&bktr_mutex);
@@ -776,7 +800,9 @@ void bktr_cleanup(struct context *cnt)
}
#else
if (!cnt) MOTION_LOG(DBG, TYPE_VIDEO, NO_ERRNO,_("BKTR is not enabled."));
if (!cnt) {
MOTION_LOG(DBG, TYPE_VIDEO, NO_ERRNO,_("BKTR is not enabled."));
}
#endif
}
@@ -816,15 +842,14 @@ int bktr_start(struct context *cnt)
width = conf->width;
height = conf->height;
for (indx = 0; indx < cnt->vdev->params_count; indx++)
{
if ( !strcmp(cnt->vdev->params_array[indx].param_name, "input") ){
for (indx = 0; indx < cnt->vdev->params_count; indx++) {
if ( !strcmp(cnt->vdev->params_array[indx].param_name, "input")) {
input = atoi(cnt->vdev->params_array[indx].param_value);
}
if ( !strcmp(cnt->vdev->params_array[indx].param_name, "norm") ){
if ( !strcmp(cnt->vdev->params_array[indx].param_name, "norm")) {
norm = atoi(cnt->vdev->params_array[indx].param_value);
}
if ( !strcmp(cnt->vdev->params_array[indx].param_name, "frequency") ){
if ( !strcmp(cnt->vdev->params_array[indx].param_name, "frequency")) {
frequency = atol(cnt->vdev->params_array[indx].param_value);
}
}
@@ -957,7 +982,9 @@ int bktr_start(struct context *cnt)
return fd_device;
#else
if (!cnt) MOTION_LOG(DBG, TYPE_VIDEO, NO_ERRNO,_("BKTR is not enabled."));
if (!cnt) {
MOTION_LOG(DBG, TYPE_VIDEO, NO_ERRNO,_("BKTR is not enabled."));
}
return -1;
#endif
@@ -981,14 +1008,17 @@ int bktr_next(struct context *cnt, struct image_data *img_data)
dev = viddevs;
while (dev) {
if (dev->fd_device == dev_bktr)
if (dev->fd_device == dev_bktr) {
break;
}
dev = dev->next;
}
pthread_mutex_unlock(&bktr_mutex);
if (dev == NULL) return -1;
if (dev == NULL) {
return -1;
}
if (dev->owner != cnt->threadnr) {
pthread_mutex_lock(&dev->mutex);
@@ -1012,7 +1042,9 @@ int bktr_next(struct context *cnt, struct image_data *img_data)
return ret;
#else
if (!cnt || !img_data) MOTION_LOG(DBG, TYPE_VIDEO, NO_ERRNO,_("BKTR is not enabled."));
if (!cnt || !img_data) {
MOTION_LOG(DBG, TYPE_VIDEO, NO_ERRNO,_("BKTR is not enabled."));
}
return -1;
#endif

View File

@@ -425,12 +425,12 @@ int vid_mjpegtoyuv420p(unsigned char *map, unsigned char *cap_map, int width, in
Some cameras are sending multiple SOIs in the buffer.
Move the pointer to the last SOI in the buffer and proceed.
*/
while (ptr_buffer != NULL && ((size - soi_pos - 1) > 2) ){
while (ptr_buffer != NULL && ((size - soi_pos - 1) > 2)) {
soi_pos = ptr_buffer - cap_map;
ptr_buffer = memmem(cap_map + 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);
}
@@ -489,7 +489,9 @@ void vid_greytoyuv420p(unsigned char *map, unsigned char *cap_map, int width, in
int vid_parms_parse(struct context *cnt)
{
if (cnt->vdev->update_params == FALSE) return 0;
if (cnt->vdev->update_params == FALSE) {
return 0;
}
/* Put in the user specified parameters */
util_parms_parse(cnt->vdev, cnt->conf.video_params);
@@ -678,15 +680,17 @@ int vid_next(struct context *cnt, struct image_data *img_data)
#endif
if (cnt->camera_type == CAMERA_TYPE_NETCAM) {
if (cnt->video_dev == -1)
if (cnt->video_dev == -1) {
return NETCAM_GENERAL_ERROR;
}
return netcam_next(cnt, img_data);
}
if (cnt->camera_type == CAMERA_TYPE_RTSP) {
if (cnt->video_dev == -1)
if (cnt->video_dev == -1) {
return NETCAM_GENERAL_ERROR;
}
return netcam_rtsp_next(cnt, img_data);
}

View File

@@ -72,7 +72,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;
}
@@ -83,8 +85,9 @@ static int vlp_open_vidpipe(void)
closedir(dir);
if (pipe_fd >= 0)
MOTION_LOG(NTC, TYPE_VIDEO, NO_ERRNO,_("Opened %s as pipe output"), pipepath);
if (pipe_fd >= 0) {
MOTION_LOG(NTC, TYPE_VIDEO, NO_ERRNO,_("Opened %s as pipe output"), pipepath);
}
return pipe_fd;
}
@@ -132,9 +135,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, "------------------------");
}

View File

@@ -108,7 +108,7 @@ static void v4l2_palette_init(palette_item *palette_array)
palette_array[20].v4l2id = V4L2_PIX_FMT_GREY;
palette_array[21].v4l2id = V4L2_PIX_FMT_H264;
for (indx=0; indx <=V4L2_PALETTE_COUNT_MAX; indx++ ){
for (indx=0; indx <=V4L2_PALETTE_COUNT_MAX; indx++ ) {
sprintf(palette_array[indx].fourcc ,"%c%c%c%c"
,palette_array[indx].v4l2id >> 0
,palette_array[indx].v4l2id >> 8
@@ -137,7 +137,7 @@ static void v4l2_vdev_free(struct context *cnt)
{
/* free the information we collected regarding the controls */
if (cnt->vdev != NULL){
if (cnt->vdev != NULL) {
util_parms_free(cnt->vdev);
free(cnt->vdev);
@@ -173,17 +173,19 @@ static int v4l2_ctrls_count(struct video_dev *curdev)
memset(&vid_ctrl, 0, sizeof(struct v4l2_queryctrl));
vid_ctrl.id = V4L2_CTRL_FLAG_NEXT_CTRL;
while (xioctl (vid_source, VIDIOC_QUERYCTRL, &vid_ctrl) == 0) {
if (vid_ctrl.type == V4L2_CTRL_TYPE_CTRL_CLASS){
if (vid_ctrl.type == V4L2_CTRL_TYPE_CTRL_CLASS) {
vid_ctrl.id |= V4L2_CTRL_FLAG_NEXT_CTRL;
continue;
}
curdev->devctrl_count++;
if (vid_ctrl.type == V4L2_CTRL_TYPE_MENU) {
for (indx = vid_ctrl.minimum; indx<=vid_ctrl.maximum; indx++){
for (indx = vid_ctrl.minimum; indx<=vid_ctrl.maximum; indx++) {
memset(&vid_menu, 0, sizeof(struct v4l2_querymenu));
vid_menu.id = vid_ctrl.id;
vid_menu.index = indx;
if (xioctl(vid_source, VIDIOC_QUERYMENU, &vid_menu) == 0) curdev->devctrl_count++;
if (xioctl(vid_source, VIDIOC_QUERYMENU, &vid_menu) == 0) {
curdev->devctrl_count++;
}
}
}
vid_ctrl.id |= V4L2_CTRL_FLAG_NEXT_CTRL;
@@ -203,7 +205,7 @@ static int v4l2_ctrls_list(struct video_dev *curdev)
int indx, indx_ctrl;
curdev->devctrl_array = NULL;
if (curdev->devctrl_count == 0 ){
if (curdev->devctrl_count == 0 ) {
MOTION_LOG(INF, TYPE_VIDEO, NO_ERRNO, _("No Controls found for device"));
return 0;
}
@@ -214,7 +216,7 @@ static int v4l2_ctrls_list(struct video_dev *curdev)
vid_ctrl.id = V4L2_CTRL_FLAG_NEXT_CTRL;
indx_ctrl = 0;
while (xioctl (vid_source, VIDIOC_QUERYCTRL, &vid_ctrl) == 0) {
if (vid_ctrl.type == V4L2_CTRL_TYPE_CTRL_CLASS){
if (vid_ctrl.type == V4L2_CTRL_TYPE_CTRL_CLASS) {
vid_ctrl.id |= V4L2_CTRL_FLAG_NEXT_CTRL;
continue;
}
@@ -236,11 +238,11 @@ static int v4l2_ctrls_list(struct video_dev *curdev)
curdev->devctrl_array[indx_ctrl].ctrl_maximum = vid_ctrl.maximum;
if (vid_ctrl.type == V4L2_CTRL_TYPE_MENU) {
for (indx = vid_ctrl.minimum; indx<=vid_ctrl.maximum; indx++){
for (indx = vid_ctrl.minimum; indx<=vid_ctrl.maximum; indx++) {
memset(&vid_menu, 0, sizeof(struct v4l2_querymenu));
vid_menu.id = vid_ctrl.id;
vid_menu.index = indx;
if (xioctl(vid_source, VIDIOC_QUERYMENU, &vid_menu) == 0){
if (xioctl(vid_source, VIDIOC_QUERYMENU, &vid_menu) == 0) {
indx_ctrl++;
curdev->devctrl_array[indx_ctrl].ctrl_id = vid_ctrl.id;
@@ -262,11 +264,11 @@ static int v4l2_ctrls_list(struct video_dev *curdev)
vid_ctrl.id |= V4L2_CTRL_FLAG_NEXT_CTRL;
}
if (curdev->devctrl_count != 0 ){
if (curdev->devctrl_count != 0 ) {
MOTION_LOG(INF, TYPE_VIDEO, NO_ERRNO, _("---------Controls---------"));
MOTION_LOG(INF, TYPE_VIDEO, NO_ERRNO, _(" V4L2 ID Name and Range"));
for (indx=0; indx < curdev->devctrl_count; indx++){
if (curdev->devctrl_array[indx].ctrl_menuitem){
for (indx=0; indx < curdev->devctrl_count; indx++) {
if (curdev->devctrl_array[indx].ctrl_menuitem) {
MOTION_LOG(INF, TYPE_VIDEO, NO_ERRNO, " %s %s"
,curdev->devctrl_array[indx].ctrl_iddesc
,curdev->devctrl_array[indx].ctrl_name);
@@ -293,12 +295,12 @@ static int v4l2_ctrls_set(struct video_dev *curdev)
struct v4l2_control vid_ctrl;
int indx_dev, retcd;
if (vid_source == NULL){
if (vid_source == NULL) {
MOTION_LOG(WRN, TYPE_VIDEO, NO_ERRNO,_("Device not ready"));
return -1;
}
for (indx_dev= 0;indx_dev<curdev->devctrl_count;indx_dev++){
for (indx_dev= 0;indx_dev<curdev->devctrl_count;indx_dev++) {
devitem=&curdev->devctrl_array[indx_dev];
if (!devitem->ctrl_menuitem) {
if (devitem->ctrl_currval != devitem->ctrl_newval) {
@@ -312,10 +314,11 @@ static int v4l2_ctrls_set(struct video_dev *curdev)
,devitem->ctrl_iddesc, devitem->ctrl_name
,devitem->ctrl_newval,retcd);
} else {
if (curdev->starting)
if (curdev->starting) {
MOTION_LOG(INF, TYPE_VIDEO, NO_ERRNO
,_("Set control \"%s\" to value %d")
,devitem->ctrl_name, devitem->ctrl_newval);
}
devitem->ctrl_currval = devitem->ctrl_newval;
}
@@ -333,9 +336,11 @@ static int v4l2_parms_set(struct context *cnt, struct video_dev *curdev)
struct params_item_ctx *usritem;
int indx_dev, indx_user;
if (cnt->conf.roundrobin_skip < 0) cnt->conf.roundrobin_skip = 1;
if (cnt->conf.roundrobin_skip < 0) {
cnt->conf.roundrobin_skip = 1;
}
if (curdev->devctrl_count == 0){
if (curdev->devctrl_count == 0) {
cnt->vdev->update_params = FALSE;
return 0;
}
@@ -343,7 +348,7 @@ static int v4l2_parms_set(struct context *cnt, struct video_dev *curdev)
for (indx_dev=0; indx_dev<curdev->devctrl_count; indx_dev++ ) {
devitem=&curdev->devctrl_array[indx_dev];
devitem->ctrl_newval = devitem->ctrl_default;
for (indx_user=0; indx_user<cnt->vdev->params_count; indx_user++){
for (indx_user=0; indx_user<cnt->vdev->params_count; indx_user++) {
usritem=&cnt->vdev->params_array[indx_user];
if ((!strcasecmp(devitem->ctrl_iddesc,usritem->param_name)) ||
(!strcasecmp(devitem->ctrl_name ,usritem->param_name))) {
@@ -351,12 +356,12 @@ static int v4l2_parms_set(struct context *cnt, struct video_dev *curdev)
case V4L2_CTRL_TYPE_MENU:
/*FALLTHROUGH*/
case V4L2_CTRL_TYPE_INTEGER:
if (atoi(usritem->param_value) < devitem->ctrl_minimum){
if (atoi(usritem->param_value) < devitem->ctrl_minimum) {
MOTION_LOG(WRN, TYPE_VIDEO, NO_ERRNO
,_("%s control option value %s is below minimum. Using minimum %d")
,devitem->ctrl_name, usritem->param_value, devitem->ctrl_minimum);
devitem->ctrl_newval = devitem->ctrl_minimum;
} else if (atoi(usritem->param_value) > devitem->ctrl_maximum){
} else if (atoi(usritem->param_value) > devitem->ctrl_maximum) {
MOTION_LOG(WRN, TYPE_VIDEO, NO_ERRNO
,_("%s control option value %s is above maximum. Using maximum %d")
,devitem->ctrl_name, usritem->param_value, devitem->ctrl_maximum);
@@ -395,7 +400,9 @@ static int v4l2_autobright(struct context *cnt, struct video_dev *curdev, int me
char cid_exp[15],cid_expabs[15],cid_bright[15];
if ((method == 0) || (method > 3)) return 0;
if ((method == 0) || (method > 3)) {
return 0;
}
/* Set the values for the control variables */
parm_hysteresis = 20;
@@ -409,7 +416,7 @@ static int v4l2_autobright(struct context *cnt, struct video_dev *curdev, int me
sprintf(cid_exp,"ID%08d",V4L2_CID_EXPOSURE);
sprintf(cid_expabs,"ID%08d",V4L2_CID_EXPOSURE_ABSOLUTE);
for (indx = 0;indx < cnt->vdev->params_count; indx++){
for (indx = 0;indx < cnt->vdev->params_count; indx++) {
usritem=&cnt->vdev->params_array[indx];
if ((method == 1) &&
((!strcasecmp(usritem->param_name,"brightness")) ||
@@ -427,36 +434,35 @@ static int v4l2_autobright(struct context *cnt, struct video_dev *curdev, int me
}
device_value = -1;
for (indx = 0;indx < curdev->devctrl_count; indx++){
for (indx = 0;indx < curdev->devctrl_count; indx++) {
devitem=&curdev->devctrl_array[indx];
if ((method == 1) &&
(devitem->ctrl_id == V4L2_CID_BRIGHTNESS)) {
if ((method == 1) && (devitem->ctrl_id == V4L2_CID_BRIGHTNESS)) {
device_value = devitem->ctrl_currval;
parm_max = devitem->ctrl_maximum;
parm_min = devitem->ctrl_minimum;
if (target == -1){
if (target == -1) {
target = (int) ((devitem->ctrl_maximum - devitem->ctrl_minimum)/2);
}
} else if ((method == 2) &&
(devitem->ctrl_id == V4L2_CID_EXPOSURE)) {
} else if ((method == 2) && (devitem->ctrl_id == V4L2_CID_EXPOSURE)) {
device_value = devitem->ctrl_currval;
parm_max = devitem->ctrl_maximum;
parm_min = devitem->ctrl_minimum;
if (target == -1){
if (target == -1) {
target = (int) ((devitem->ctrl_maximum - devitem->ctrl_minimum)/2);
}
} else if ((method == 3) &&
(devitem->ctrl_id == V4L2_CID_EXPOSURE_ABSOLUTE)) {
} else if ((method == 3) && (devitem->ctrl_id == V4L2_CID_EXPOSURE_ABSOLUTE)) {
device_value = devitem->ctrl_currval;
parm_max = devitem->ctrl_maximum;
parm_min = devitem->ctrl_minimum;
if (target == -1){
if (target == -1) {
target = (int) ((devitem->ctrl_maximum - devitem->ctrl_minimum)/2);
}
}
}
/* If we can not find control just give up */
if (device_value == -1) return 0;
if (device_value == -1) {
return 0;
}
avg = 0;
pixel_count = 0;
@@ -500,17 +506,14 @@ static int v4l2_autobright(struct context *cnt, struct video_dev *curdev, int me
//MOTION_LOG(INF, TYPE_VIDEO, NO_ERRNO, "Up Avg %d step: %d device:%d",avg,step,device_value);
}
if (make_change){
for (indx = 0;indx < curdev->devctrl_count; indx++){
if (make_change) {
for (indx = 0;indx < curdev->devctrl_count; indx++) {
devitem=&curdev->devctrl_array[indx];
if ((method == 1) &&
(devitem->ctrl_id == V4L2_CID_BRIGHTNESS)) {
if ((method == 1) && (devitem->ctrl_id == V4L2_CID_BRIGHTNESS)) {
devitem->ctrl_newval = device_value;
} else if ((method == 2) &&
(devitem->ctrl_id == V4L2_CID_EXPOSURE)) {
} else if ((method == 2) && (devitem->ctrl_id == V4L2_CID_EXPOSURE)) {
devitem->ctrl_newval = device_value;
} else if ((method == 3) &&
(devitem->ctrl_id == V4L2_CID_EXPOSURE_ABSOLUTE)) {
} else if ((method == 3) && (devitem->ctrl_id == V4L2_CID_EXPOSURE_ABSOLUTE)) {
devitem->ctrl_newval = device_value;
}
}
@@ -528,14 +531,16 @@ static int v4l2_input_select(struct context *cnt, struct video_dev *curdev)
int indx, tmpinp;
tmpinp = -1;
for (indx = 0;indx < cnt->vdev->params_count; indx++){
if ( !strcmp(cnt->vdev->params_array[indx].param_name,"input")){
for (indx = 0;indx < cnt->vdev->params_count; indx++) {
if ( !strcmp(cnt->vdev->params_array[indx].param_name,"input")) {
tmpinp = atoi(cnt->vdev->params_array[indx].param_value);
break;
}
}
if ((tmpinp == curdev->input) && (!curdev->starting)) return 0;
if ((tmpinp == curdev->input) && (!curdev->starting)) {
return 0;
}
memset(&input, 0, sizeof (struct v4l2_input));
if (tmpinp == -1 ) {
@@ -552,18 +557,18 @@ static int v4l2_input_select(struct context *cnt, struct video_dev *curdev)
return -1;
}
if (curdev->starting){
if (curdev->starting) {
MOTION_LOG(DBG, TYPE_VIDEO, NO_ERRNO
,_("Name = \"%s\", type 0x%08X, status %08x")
,input.name, input.type, input.status);
}
if ((input.type & V4L2_INPUT_TYPE_TUNER) && (curdev->starting)){
if ((input.type & V4L2_INPUT_TYPE_TUNER) && (curdev->starting)) {
MOTION_LOG(NTC, TYPE_VIDEO, NO_ERRNO
,_("Name = \"%s\",- TUNER"),input.name);
}
if ((input.type & V4L2_INPUT_TYPE_CAMERA) && (curdev->starting)){
if ((input.type & V4L2_INPUT_TYPE_CAMERA) && (curdev->starting)) {
MOTION_LOG(NTC, TYPE_VIDEO, NO_ERRNO,_("Name = \"%s\"- CAMERA"),input.name);
}
@@ -590,17 +595,19 @@ static int v4l2_norm_select(struct context *cnt, struct video_dev *curdev)
int norm, indx;
norm = 0;
for (indx = 0;indx < cnt->vdev->params_count; indx++){
if ( !strcmp(cnt->vdev->params_array[indx].param_name,"norm")){
for (indx = 0;indx < cnt->vdev->params_count; indx++) {
if ( !strcmp(cnt->vdev->params_array[indx].param_name,"norm")) {
norm = atoi(cnt->vdev->params_array[indx].param_value);
break;
}
}
if ((norm == curdev->norm) && (!curdev->starting)) return 0;
if ((norm == curdev->norm) && (!curdev->starting)) {
return 0;
}
if (xioctl(vid_source, VIDIOC_G_STD, &std_id) == -1) {
if (curdev->starting){
if (curdev->starting) {
MOTION_LOG(NTC, TYPE_VIDEO, NO_ERRNO
,_("Device does not support specifying PAL/NTSC norm"));
}
@@ -612,9 +619,10 @@ static int v4l2_norm_select(struct context *cnt, struct video_dev *curdev)
standard.index = 0;
while (xioctl(vid_source, VIDIOC_ENUMSTD, &standard) == 0) {
if ((standard.id & std_id) && (curdev->starting))
if ((standard.id & std_id) && (curdev->starting)) {
MOTION_LOG(NTC, TYPE_VIDEO, NO_ERRNO
,_("- video standard %s"), standard.name);
}
standard.index++;
}
@@ -629,7 +637,7 @@ static int v4l2_norm_select(struct context *cnt, struct video_dev *curdev)
std_id = V4L2_STD_PAL;
}
if (xioctl(vid_source, VIDIOC_S_STD, &std_id) == -1){
if (xioctl(vid_source, VIDIOC_S_STD, &std_id) == -1) {
MOTION_LOG(ERR, TYPE_VIDEO, SHOW_ERRNO
,_("Error selecting standard method %d VIDIOC_S_STD")
,(int)std_id);
@@ -662,14 +670,16 @@ static int v4l2_frequency_select(struct context *cnt, struct video_dev *curdev)
long usrfreq;
usrfreq = 0;
for (indx = 0;indx < cnt->vdev->params_count; indx++){
if ( !strcmp(cnt->vdev->params_array[indx].param_name,"frequency")){
for (indx = 0;indx < cnt->vdev->params_count; indx++) {
if ( !strcmp(cnt->vdev->params_array[indx].param_name,"frequency")) {
usrfreq = atol(cnt->vdev->params_array[indx].param_value);
break;
}
}
if ((usrfreq == curdev->frequency) && (!curdev->starting)) return 0;
if ((usrfreq == curdev->frequency) && (!curdev->starting)) {
return 0;
}
/* If this input is attached to a tuner, set the frequency. */
if (curdev->device_type & V4L2_INPUT_TYPE_TUNER) {
@@ -683,7 +693,7 @@ static int v4l2_frequency_select(struct context *cnt, struct video_dev *curdev)
return 0;
}
if (curdev->starting){
if (curdev->starting) {
MOTION_LOG(NTC, TYPE_VIDEO, NO_ERRNO, _("Set tuner %d"), tuner.index);
}
@@ -699,7 +709,7 @@ static int v4l2_frequency_select(struct context *cnt, struct video_dev *curdev)
return 0;
}
if (curdev->starting){
if (curdev->starting) {
MOTION_LOG(NTC, TYPE_VIDEO, NO_ERRNO, _("Set Frequency to %ul"), freq.frequency);
}
}
@@ -812,14 +822,13 @@ static int v4l2_pixfmt_select(struct context *cnt, struct video_dev *curdev)
}
indx_palette = 17;
for (indx = 0; indx < cnt->vdev->params_count; indx++)
{
if ( !strcmp(cnt->vdev->params_array[indx].param_name, "palette") ){
for (indx = 0; indx < cnt->vdev->params_count; indx++) {
if ( !strcmp(cnt->vdev->params_array[indx].param_name, "palette")) {
indx_palette = atoi(cnt->vdev->params_array[indx].param_value);
};
}
if (indx_palette == 21 ) {
if (indx_palette == 21) {
MOTION_LOG(WRN, TYPE_VIDEO, NO_ERRNO
,_("H264(21) format not supported via videodevice. Changing to default palette"));
indx_palette = 17;
@@ -828,7 +837,7 @@ static int v4l2_pixfmt_select(struct context *cnt, struct video_dev *curdev)
/* First we try setting the config file value */
if ((indx_palette >= 0) && (indx_palette <= V4L2_PALETTE_COUNT_MAX)) {
retcd = v4l2_pixfmt_set(cnt, curdev,palette_array[indx_palette].v4l2id);
if (retcd >= 0){
if (retcd >= 0) {
free(palette_array);
return 0;
}
@@ -856,10 +865,12 @@ static int v4l2_pixfmt_select(struct context *cnt, struct video_dev *curdev)
}
/* Adjust indx_palette if larger value found */
/* Prevent the selection of H264 since this module does not support it */
for (indx = 0; indx <= V4L2_PALETTE_COUNT_MAX; indx++)
for (indx = 0; indx <= V4L2_PALETTE_COUNT_MAX; indx++) {
if ((palette_array[indx].v4l2id == fmtd.pixelformat) &&
(palette_array[indx].v4l2id != V4L2_PIX_FMT_H264))
(palette_array[indx].v4l2id != V4L2_PIX_FMT_H264)) {
indx_palette = indx;
}
}
memset(&fmtd, 0, sizeof(struct v4l2_fmtdesc));
fmtd.index = ++v4l2_pal;
@@ -868,7 +879,7 @@ static int v4l2_pixfmt_select(struct context *cnt, struct video_dev *curdev)
if (indx_palette >= 0) {
retcd = v4l2_pixfmt_set(cnt, curdev, palette_array[indx_palette].v4l2id);
if (retcd >= 0){
if (retcd >= 0) {
if (curdev->starting) {
MOTION_LOG(NTC, TYPE_VIDEO, NO_ERRNO
,_("Selected palette %s")
@@ -901,7 +912,9 @@ static int v4l2_mmap_set(struct video_dev *curdev)
int buffer_index;
/* Does the device support streaming? */
if (!(vid_source->cap.capabilities & V4L2_CAP_STREAMING)) return -1;
if (!(vid_source->cap.capabilities & V4L2_CAP_STREAMING)) {
return -1;
}
memset(&vid_source->req, 0, sizeof(struct v4l2_requestbuffers));
@@ -1055,8 +1068,9 @@ static int v4l2_capture(struct context *cnt, struct video_dev *curdev, unsigned
if (errno == EIO) {
vid_source->pframe++;
if ((u32)vid_source->pframe >= vid_source->req.count)
if ((u32)vid_source->pframe >= vid_source->req.count) {
vid_source->pframe = 0;
}
vid_source->buf.index = vid_source->pframe;
MOTION_LOG(ERR, TYPE_VIDEO, SHOW_ERRNO
@@ -1178,15 +1192,14 @@ static int v4l2_device_init(struct context *cnt, struct video_dev *curdev)
curdev->usage_count = 1;
for (indx = 0; indx < cnt->vdev->params_count; indx++)
{
if ( !strcmp(cnt->vdev->params_array[indx].param_name, "input") ){
for (indx = 0; indx < cnt->vdev->params_count; indx++) {
if ( !strcmp(cnt->vdev->params_array[indx].param_name, "input")) {
curdev->input = atoi(cnt->vdev->params_array[indx].param_value);
}
if ( !strcmp(cnt->vdev->params_array[indx].param_name, "norm") ){
if ( !strcmp(cnt->vdev->params_array[indx].param_name, "norm")) {
curdev->norm = atoi(cnt->vdev->params_array[indx].param_value);
}
if ( !strcmp(cnt->vdev->params_array[indx].param_name, "frequency") ){
if ( !strcmp(cnt->vdev->params_array[indx].param_name, "frequency")) {
curdev->frequency = atol(cnt->vdev->params_array[indx].param_value);
}
}
@@ -1215,60 +1228,74 @@ static void v4l2_device_select(struct context *cnt, struct video_dev *curdev, un
int indx, retcd, newvals;
if (curdev->v4l2_private == NULL){
if (curdev->v4l2_private == NULL) {
MOTION_LOG(WRN, TYPE_VIDEO, NO_ERRNO,_("Device not ready"));
return;
}
newvals = FALSE;
for (indx = 0; indx < cnt->vdev->params_count; indx++)
{
for (indx = 0; indx < cnt->vdev->params_count; indx++) {
if (!strcmp(cnt->vdev->params_array[indx].param_name, "input") &&
atoi(cnt->vdev->params_array[indx].param_value) != curdev->input)
{
atoi(cnt->vdev->params_array[indx].param_value) != curdev->input) {
newvals = TRUE;
}
if (!strcmp(cnt->vdev->params_array[indx].param_name, "norm") &&
atoi(cnt->vdev->params_array[indx].param_value) != curdev->norm)
{
atoi(cnt->vdev->params_array[indx].param_value) != curdev->norm) {
newvals = TRUE;
}
if (!strcmp(cnt->vdev->params_array[indx].param_name, "frequency") &&
atol(cnt->vdev->params_array[indx].param_value) != curdev->frequency)
{
atol(cnt->vdev->params_array[indx].param_value) != curdev->frequency) {
newvals = TRUE;
}
}
if (newvals) {
retcd = v4l2_input_select(cnt, curdev);
if (retcd == 0) retcd = v4l2_norm_select(cnt, curdev);
if (retcd == 0) retcd = v4l2_frequency_select(cnt, curdev);
if (retcd == 0) retcd = vid_parms_parse(cnt);
if (retcd == 0) retcd = v4l2_parms_set(cnt, curdev);
if (retcd == 0) retcd = v4l2_autobright(cnt, curdev, cnt->conf.auto_brightness);
if (retcd == 0) retcd = v4l2_ctrls_set(curdev);
if (retcd < 0 ){
if (retcd == 0) {
retcd = v4l2_norm_select(cnt, curdev);
}
if (retcd == 0) {
retcd = v4l2_frequency_select(cnt, curdev);
}
if (retcd == 0) {
retcd = vid_parms_parse(cnt);
}
if (retcd == 0) {
retcd = v4l2_parms_set(cnt, curdev);
}
if (retcd == 0) {
retcd = v4l2_autobright(cnt, curdev, cnt->conf.auto_brightness);
}
if (retcd == 0) {
retcd = v4l2_ctrls_set(curdev);
}
if (retcd < 0) {
MOTION_LOG(WRN, TYPE_VIDEO, NO_ERRNO
,_("Errors occurred during device select"));
}
/* Clear the buffers from previous "robin" pictures*/
for (indx =0; indx < curdev->buffer_count; indx++){
for (indx =0; indx < curdev->buffer_count; indx++) {
v4l2_capture(cnt, curdev, map);
}
/* Skip the requested round robin frame count */
for (indx = 1; indx < cnt->conf.roundrobin_skip; indx++){
for (indx = 1; indx < cnt->conf.roundrobin_skip; indx++) {
v4l2_capture(cnt, curdev, map);
}
} else {
/* No round robin - we only adjust picture controls */
retcd = vid_parms_parse(cnt);
if (retcd == 0) retcd = v4l2_parms_set(cnt, curdev);
if (retcd == 0) retcd = v4l2_autobright(cnt, curdev, cnt->conf.auto_brightness);
if (retcd == 0) retcd = v4l2_ctrls_set(curdev);
if (retcd == 0) {
retcd = v4l2_parms_set(cnt, curdev);
}
if (retcd == 0) {
retcd = v4l2_autobright(cnt, curdev, cnt->conf.auto_brightness);
}
if (retcd == 0) {
retcd = v4l2_ctrls_set(curdev);
}
if (retcd < 0 ) {
MOTION_LOG(WRN, TYPE_VIDEO, NO_ERRNO
,_("Errors occurred during device select"));
@@ -1283,9 +1310,8 @@ static int v4l2_device_open(struct context *cnt, struct video_dev *curdev)
/* Open the video device */
usrinp = -1;
for (indx = 0; indx < cnt->vdev->params_count; indx++)
{
if ( !strcmp(cnt->vdev->params_array[indx].param_name, "input") ){
for (indx = 0; indx < cnt->vdev->params_count; indx++) {
if ( !strcmp(cnt->vdev->params_array[indx].param_name, "input")) {
usrinp = atoi(cnt->vdev->params_array[indx].param_value);
}
}
@@ -1324,11 +1350,11 @@ static void v4l2_device_close(struct video_dev *curdev)
type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
if (vid_source != NULL){
if (vid_source != NULL) {
xioctl(vid_source, VIDIOC_STREAMOFF, &type);
}
if (vid_source->fd_device != -1){
if (vid_source->fd_device != -1) {
close(vid_source->fd_device);
vid_source->fd_device = -1;
}
@@ -1343,20 +1369,20 @@ static void v4l2_device_cleanup(struct video_dev *curdev)
int indx2;
if (vid_source->buffers != NULL) {
for (indx = 0; indx < vid_source->req.count; indx++){
for (indx = 0; indx < vid_source->req.count; indx++) {
munmap(vid_source->buffers[indx].ptr, vid_source->buffers[indx].size);
}
free(vid_source->buffers);
vid_source->buffers = NULL;
}
if (vid_source != NULL){
if (vid_source != NULL) {
free(vid_source);
curdev->v4l2_private = NULL;
}
if (curdev->devctrl_count != 0 ){
for (indx2=0; indx2 < curdev->devctrl_count; indx2++){
if (curdev->devctrl_count != 0) {
for (indx2=0; indx2 < curdev->devctrl_count; indx2++) {
free(curdev->devctrl_array[indx2].ctrl_iddesc);
free(curdev->devctrl_array[indx2].ctrl_name);
curdev->devctrl_array[indx2].ctrl_iddesc = NULL;
@@ -1386,30 +1412,42 @@ static int v4l2_device_capability(struct video_dev *curdev)
MOTION_LOG(DBG, TYPE_VIDEO, NO_ERRNO, "cap.capabilities=0x%08X",vid_source->cap.capabilities);
MOTION_LOG(DBG, TYPE_VIDEO, NO_ERRNO, "------------------------");
if (vid_source->cap.capabilities & V4L2_CAP_VIDEO_CAPTURE)
if (vid_source->cap.capabilities & V4L2_CAP_VIDEO_CAPTURE) {
MOTION_LOG(NTC, TYPE_VIDEO, NO_ERRNO, "- VIDEO_CAPTURE");
if (vid_source->cap.capabilities & V4L2_CAP_VIDEO_OUTPUT)
}
if (vid_source->cap.capabilities & V4L2_CAP_VIDEO_OUTPUT) {
MOTION_LOG(NTC, TYPE_VIDEO, NO_ERRNO, "- VIDEO_OUTPUT");
if (vid_source->cap.capabilities & V4L2_CAP_VIDEO_OVERLAY)
}
if (vid_source->cap.capabilities & V4L2_CAP_VIDEO_OVERLAY) {
MOTION_LOG(NTC, TYPE_VIDEO, NO_ERRNO, "- VIDEO_OVERLAY");
if (vid_source->cap.capabilities & V4L2_CAP_VBI_CAPTURE)
}
if (vid_source->cap.capabilities & V4L2_CAP_VBI_CAPTURE) {
MOTION_LOG(NTC, TYPE_VIDEO, NO_ERRNO, "- VBI_CAPTURE");
if (vid_source->cap.capabilities & V4L2_CAP_VBI_OUTPUT)
}
if (vid_source->cap.capabilities & V4L2_CAP_VBI_OUTPUT) {
MOTION_LOG(NTC, TYPE_VIDEO, NO_ERRNO, "- VBI_OUTPUT");
if (vid_source->cap.capabilities & V4L2_CAP_RDS_CAPTURE)
}
if (vid_source->cap.capabilities & V4L2_CAP_RDS_CAPTURE) {
MOTION_LOG(NTC, TYPE_VIDEO, NO_ERRNO, "- RDS_CAPTURE");
if (vid_source->cap.capabilities & V4L2_CAP_TUNER)
}
if (vid_source->cap.capabilities & V4L2_CAP_TUNER) {
MOTION_LOG(NTC, TYPE_VIDEO, NO_ERRNO, "- TUNER");
if (vid_source->cap.capabilities & V4L2_CAP_AUDIO)
}
if (vid_source->cap.capabilities & V4L2_CAP_AUDIO) {
MOTION_LOG(NTC, TYPE_VIDEO, NO_ERRNO, "- AUDIO");
if (vid_source->cap.capabilities & V4L2_CAP_READWRITE)
}
if (vid_source->cap.capabilities & V4L2_CAP_READWRITE) {
MOTION_LOG(NTC, TYPE_VIDEO, NO_ERRNO, "- READWRITE");
if (vid_source->cap.capabilities & V4L2_CAP_ASYNCIO)
}
if (vid_source->cap.capabilities & V4L2_CAP_ASYNCIO) {
MOTION_LOG(NTC, TYPE_VIDEO, NO_ERRNO, "- ASYNCIO");
if (vid_source->cap.capabilities & V4L2_CAP_STREAMING)
}
if (vid_source->cap.capabilities & V4L2_CAP_STREAMING) {
MOTION_LOG(NTC, TYPE_VIDEO, NO_ERRNO, "- STREAMING");
if (vid_source->cap.capabilities & V4L2_CAP_TIMEPERFRAME)
}
if (vid_source->cap.capabilities & V4L2_CAP_TIMEPERFRAME) {
MOTION_LOG(NTC, TYPE_VIDEO, NO_ERRNO, "- TIMEPERFRAME");
}
if (!(vid_source->cap.capabilities & V4L2_CAP_VIDEO_CAPTURE)) {
MOTION_LOG(ERR, TYPE_VIDEO, NO_ERRNO, _("Device does not support capturing."));
@@ -1481,8 +1519,12 @@ int v4l2_start(struct context *cnt)
while (curdev) {
if (!strcmp(cnt->conf.video_device, curdev->video_device)) {
retcd = v4l2_vdev_init(cnt);
if (retcd == 0) retcd = vid_parms_parse(cnt);
if (retcd == 0) retcd = v4l2_imgs_set(cnt, curdev);
if (retcd == 0) {
retcd = vid_parms_parse(cnt);
}
if (retcd == 0) {
retcd = v4l2_imgs_set(cnt, curdev);
}
if (retcd == 0) {
curdev->usage_count++;
retcd = curdev->fd_device;
@@ -1498,31 +1540,63 @@ int v4l2_start(struct context *cnt)
curdev->starting = TRUE;
retcd = v4l2_vdev_init(cnt);
if (retcd == 0) retcd = vid_parms_parse(cnt);
if (retcd == 0) retcd = v4l2_device_init(cnt, curdev);
if (retcd == 0) retcd = v4l2_device_open(cnt, curdev);
if (retcd == 0) retcd = v4l2_device_capability(curdev);
if (retcd == 0) retcd = v4l2_input_select(cnt, curdev);
if (retcd == 0) retcd = v4l2_norm_select(cnt, curdev);
if (retcd == 0) retcd = v4l2_frequency_select(cnt, curdev);
if (retcd == 0) retcd = v4l2_pixfmt_select(cnt, curdev);
if (retcd == 0) retcd = v4l2_fps_set(cnt, curdev);
if (retcd == 0) retcd = v4l2_ctrls_count(curdev);
if (retcd == 0) retcd = v4l2_ctrls_list(curdev);
if (retcd == 0) retcd = v4l2_parms_set(cnt, curdev);
if (retcd == 0) retcd = v4l2_ctrls_set(curdev);
if (retcd == 0) retcd = v4l2_mmap_set(curdev);
if (retcd == 0) retcd = v4l2_imgs_set(cnt, curdev);
if (retcd < 0){
if (retcd == 0) {
retcd = vid_parms_parse(cnt);
}
if (retcd == 0) {
retcd = v4l2_device_init(cnt, curdev);
}
if (retcd == 0) {
retcd = v4l2_device_open(cnt, curdev);
}
if (retcd == 0) {
retcd = v4l2_device_capability(curdev);
}
if (retcd == 0) {
retcd = v4l2_input_select(cnt, curdev);
}
if (retcd == 0) {
retcd = v4l2_norm_select(cnt, curdev);
}
if (retcd == 0) {
retcd = v4l2_frequency_select(cnt, curdev);
}
if (retcd == 0) {
retcd = v4l2_pixfmt_select(cnt, curdev);
}
if (retcd == 0) {
retcd = v4l2_fps_set(cnt, curdev);
}
if (retcd == 0) {
retcd = v4l2_ctrls_count(curdev);
}
if (retcd == 0) {
retcd = v4l2_ctrls_list(curdev);
}
if (retcd == 0) {
retcd = v4l2_parms_set(cnt, curdev);
}
if (retcd == 0) {
retcd = v4l2_ctrls_set(curdev);
}
if (retcd == 0) {
retcd = v4l2_mmap_set(curdev);
}
if (retcd == 0) {
retcd = v4l2_imgs_set(cnt, curdev);
}
if (retcd < 0) {
/* These may need more work to consider all the fail scenarios*/
if (curdev->v4l2_private != NULL){
if (curdev->v4l2_private != NULL) {
free(curdev->v4l2_private);
curdev->v4l2_private = NULL;
}
pthread_mutexattr_destroy(&curdev->attr);
pthread_mutex_destroy(&curdev->mutex);
v4l2_vdev_free(cnt);
if (curdev->fd_device != -1) close(curdev->fd_device);
if (curdev->fd_device != -1) {
close(curdev->fd_device);
}
free(curdev);
pthread_mutex_unlock(&v4l2_mutex);
return retcd;
@@ -1538,7 +1612,9 @@ int v4l2_start(struct context *cnt)
return curdev->fd_device;
#else
if (!cnt) MOTION_LOG(DBG, TYPE_VIDEO, NO_ERRNO, _("V4L2 is not enabled."));
if (!cnt) {
MOTION_LOG(DBG, TYPE_VIDEO, NO_ERRNO, _("V4L2 is not enabled."));
}
return -1;
#endif // HAVE_V4l2
}
@@ -1553,8 +1629,9 @@ void v4l2_cleanup(struct context *cnt)
/* Cleanup the v4l2 part */
pthread_mutex_lock(&v4l2_mutex);
while (dev) {
if (dev->fd_device == cnt->video_dev)
if (dev->fd_device == cnt->video_dev) {
break;
}
prev = dev;
dev = dev->next;
}
@@ -1580,10 +1657,11 @@ void v4l2_cleanup(struct context *cnt)
dev->fd_device = -1;
/* Remove from list */
if (prev == NULL)
if (prev == NULL) {
video_devices = dev->next;
else
} else {
prev->next = dev->next;
}
pthread_mutexattr_destroy(&dev->attr);
pthread_mutex_destroy(&dev->mutex);
@@ -1606,7 +1684,9 @@ void v4l2_cleanup(struct context *cnt)
#else
if (!cnt) MOTION_LOG(DBG, TYPE_VIDEO, NO_ERRNO, _("V4L2 is not enabled."));
if (!cnt) {
MOTION_LOG(DBG, TYPE_VIDEO, NO_ERRNO, _("V4L2 is not enabled."));
}
#endif // HAVE_V4L2
}
@@ -1620,13 +1700,14 @@ int v4l2_next(struct context *cnt, struct image_data *img_data)
pthread_mutex_lock(&v4l2_mutex);
dev = video_devices;
while (dev) {
if (dev->fd_device == cnt->video_dev)
if (dev->fd_device == cnt->video_dev) {
break;
}
dev = dev->next;
}
pthread_mutex_unlock(&v4l2_mutex);
if (dev == NULL){
if (dev == NULL) {
return -1;
}
@@ -1650,7 +1731,9 @@ int v4l2_next(struct context *cnt, struct image_data *img_data)
return ret;
#else
if (!cnt || !img_data) MOTION_LOG(DBG, TYPE_VIDEO, NO_ERRNO, _("V4L2 is not enabled."));
if (!cnt || !img_data) {
MOTION_LOG(DBG, TYPE_VIDEO, NO_ERRNO, _("V4L2 is not enabled."));
}
return -1;
#endif // HAVE_V4L2
}
@@ -1689,8 +1772,9 @@ int v4l2_palette_valid(char *video_device, int v4l2_palette)
fmtd.type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
retcd = 0;
while (xioctl(vid_source, VIDIOC_ENUM_FMT, &fmtd) != -1) {
if (palette_array[v4l2_palette].v4l2id == fmtd.pixelformat ) retcd = 1;
if (palette_array[v4l2_palette].v4l2id == fmtd.pixelformat) {
retcd = 1;
}
memset(&fmtd, 0, sizeof(struct v4l2_fmtdesc));
fmtd.index = ++device_palette;
fmtd.type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
@@ -1705,7 +1789,9 @@ int v4l2_palette_valid(char *video_device, int v4l2_palette)
return retcd;
#else
/* We do not have v4l2 so we can not determine whether it is valid or not */
if ((video_device) || (v4l2_palette)) return 0;
if ((video_device) || (v4l2_palette)) {
return 0;
}
return 0;
#endif // HAVE_V4L2
}
@@ -1725,7 +1811,7 @@ void v4l2_palette_fourcc(int v4l2_palette, char *fourcc)
v4l2_palette_init(palette_array);
if ((v4l2_palette > V4L2_PALETTE_COUNT_MAX) || (v4l2_palette < 0)){
if ((v4l2_palette > V4L2_PALETTE_COUNT_MAX) || (v4l2_palette < 0)) {
sprintf(fourcc,"%s","NULL");
} else {
sprintf(fourcc,"%s",palette_array[v4l2_palette].fourcc);
@@ -1736,7 +1822,9 @@ void v4l2_palette_fourcc(int v4l2_palette, char *fourcc)
return;
#else
sprintf(fourcc,"%s","NULL");
if (v4l2_palette) return;
if (v4l2_palette) {
return;
}
return;
#endif // HAVE_V4L2
}
@@ -1808,7 +1896,9 @@ int v4l2_parms_valid(char *video_device, int v4l2_palette, int v4l2_fps, int v4l
((int)dev_sizes.discrete.width == v4l2_width) &&
((int)dev_sizes.discrete.height == v4l2_height) &&
((int)dev_frameint.discrete.numerator == 1) &&
((int)dev_frameint.discrete.denominator == v4l2_fps)) retcd = 1;
((int)dev_frameint.discrete.denominator == v4l2_fps)) {
retcd = 1;
}
memset(&dev_frameint, 0, sizeof(struct v4l2_frmivalenum));
dev_frameint.index = ++indx_frameint;
dev_frameint.pixel_format = dev_format.pixelformat;
@@ -1834,7 +1924,9 @@ int v4l2_parms_valid(char *video_device, int v4l2_palette, int v4l2_fps, int v4l
#else
/* We do not have v4l2 so we can not determine whether it is valid or not */
if ((video_device) || (v4l2_fps) || (v4l2_palette) ||
(v4l2_width) || (v4l2_height) ) return 0;
(v4l2_width) || (v4l2_height)) {
return 0;
}
return 0;
#endif // HAVE_V4L2
}

View File

File diff suppressed because it is too large Load Diff

View File

@@ -256,9 +256,9 @@ static void webu_html_navbar_camera(struct webui_ctx *webui)
char response[WEBUI_LEN_RESP];
int indx;
if (webui->cam_threads == 1){
if (webui->cam_threads == 1) {
/* Only Motion.conf file */
if (webui->cntlst[0]->conf.camera_name == NULL){
if (webui->cntlst[0]->conf.camera_name == NULL) {
snprintf(response, sizeof (response),
" <div class=\"dropdown\">\n"
" <button onclick='display_cameras()' id=\"cam_drop\" class=\"dropbtn\">%s</button>\n"
@@ -279,7 +279,7 @@ static void webu_html_navbar_camera(struct webui_ctx *webui)
,webui->cntlst[0]->conf.camera_name);
webu_write(webui, response);
}
} else if (webui->cam_threads > 1){
} else if (webui->cam_threads > 1) {
/* Motion.conf + separate camera.conf file */
snprintf(response, sizeof (response),
" <div class=\"dropdown\">\n"
@@ -290,8 +290,8 @@ static void webu_html_navbar_camera(struct webui_ctx *webui)
,_("All"));
webu_write(webui, response);
for (indx=1;indx <= webui->cam_count;indx++){
if (webui->cntlst[indx]->conf.camera_name == NULL){
for (indx=1;indx <= webui->cam_count;indx++) {
if (webui->cntlst[indx]->conf.camera_name == NULL) {
snprintf(response, sizeof (response),
" <a onclick=\"camera_click('cam_%05d');\">%s %d</a>\n"
,webui->cntlst[indx]->camera_id
@@ -379,15 +379,15 @@ static void webu_html_config_notice(struct webui_ctx *webui)
*/
char response[WEBUI_LEN_RESP];
if (webui->cntlst[0]->conf.webcontrol_parms == 0){
if (webui->cntlst[0]->conf.webcontrol_parms == 0) {
snprintf(response, sizeof (response),
" <h4 id='h4_parm' class='header-center'>webcontrol_parms = 0 (%s)</h4>\n"
,_("No Configuration Options"));
} else if (webui->cntlst[0]->conf.webcontrol_parms == 1){
} else if (webui->cntlst[0]->conf.webcontrol_parms == 1) {
snprintf(response, sizeof (response),
" <h4 id='h4_parm' class='header-center'>webcontrol_parms = 1 (%s)</h4>\n"
,_("Limited Configuration Options"));
} else if (webui->cntlst[0]->conf.webcontrol_parms == 2){
} else if (webui->cntlst[0]->conf.webcontrol_parms == 2) {
snprintf(response, sizeof (response),
" <h4 id='h4_parm' class='header-center'>webcontrol_parms = 2 (%s)</h4>\n"
,_("Advanced Configuration Options"));
@@ -404,7 +404,7 @@ static void webu_html_h3desc(struct webui_ctx *webui)
/* Write out the status description for the camera */
char response[WEBUI_LEN_RESP];
if (webui->cam_threads == 1){
if (webui->cam_threads == 1) {
snprintf(response, sizeof (response),
" <div id=\"id_header\">\n"
" <h3 id='h3_cam' data-cam=\"cam_all00\" class='header-center'>%s (%s)</h3>\n"
@@ -461,10 +461,10 @@ static void webu_html_config(struct webui_ctx *webui)
*/
val_temp=malloc(PATH_MAX);
indx_parm = 0;
while (config_params[indx_parm].param_name != NULL){
while (config_params[indx_parm].param_name != NULL) {
if ((config_params[indx_parm].webui_level > webui->cntlst[0]->conf.webcontrol_parms) ||
(config_params[indx_parm].webui_level == WEBUI_LEVEL_NEVER)){
(config_params[indx_parm].webui_level == WEBUI_LEVEL_NEVER)) {
indx_parm++;
continue;
}
@@ -477,15 +477,15 @@ static void webu_html_config(struct webui_ctx *webui)
webu_write(webui, response);
memset(val_temp,'\0',PATH_MAX);
if (val_main != NULL){
if (val_main != NULL) {
snprintf(response, sizeof (response),"%s", val_main);
webu_write(webui, response);
snprintf(val_temp, PATH_MAX,"%s", val_main);
}
/* Loop through all the treads and see if any have a different value from motion.conf */
if (webui->cam_threads > 1){
for (indx=1;indx <= webui->cam_count;indx++){
if (webui->cam_threads > 1) {
for (indx=1;indx <= webui->cam_count;indx++) {
val_thread=config_params[indx_parm].print(webui->cntlst, NULL, indx_parm, indx);
diff_vals = FALSE;
if (((strlen(val_temp) == 0) && (val_thread == NULL)) ||
@@ -494,9 +494,11 @@ static void webu_html_config(struct webui_ctx *webui)
} else if (((strlen(val_temp) == 0) && (val_thread != NULL)) ) {
diff_vals = TRUE;
} else {
if (strcasecmp(val_temp, val_thread)) diff_vals = TRUE;
if (strcasecmp(val_temp, val_thread)) {
diff_vals = TRUE;
}
}
if (diff_vals){
if (diff_vals) {
snprintf(response, sizeof (response),"%s","\" \\ \n");
webu_write(webui, response);
@@ -504,7 +506,7 @@ static void webu_html_config(struct webui_ctx *webui)
" data-cam_%05d=\""
,webui->cntlst[indx]->camera_id);
webu_write(webui, response);
if (val_thread != NULL){
if (val_thread != NULL) {
snprintf(response, sizeof (response),"%s", val_thread);
webu_write(webui, response);
}
@@ -514,7 +516,7 @@ static void webu_html_config(struct webui_ctx *webui)
/* Terminate the open quote and option. For foreign language put hint in () */
if (!strcasecmp(webui->lang,"en") ||
!strcasecmp(config_params[indx_parm].param_name
,_(config_params[indx_parm].param_name))){
,_(config_params[indx_parm].param_name))) {
snprintf(response, sizeof (response),"\" >%s</option>\n",
config_params[indx_parm].param_name);
webu_write(webui, response);
@@ -603,20 +605,20 @@ static void webu_html_strminfo(struct strminfo_ctx *strm_info, int indx)
snprintf(strm_info->proto,WEBUI_LEN_LNK,"%s","http");
}
}
if (strm_info->motion_images){
if (strm_info->motion_images) {
snprintf(strm_info->lnk_ref,WEBUI_LEN_LNK,"%s","/motion");
snprintf(strm_info->lnk_src,WEBUI_LEN_LNK,"%s","/motion");
} else {
/* Assign what images and links we want */
if (strm_info->cntlst[indx]->conf.stream_preview_method == 1){
if (strm_info->cntlst[indx]->conf.stream_preview_method == 1) {
/* Substream for preview */
snprintf(strm_info->lnk_ref,WEBUI_LEN_LNK,"%s","/stream");
snprintf(strm_info->lnk_src,WEBUI_LEN_LNK,"%s","/substream");
} else if (strm_info->cntlst[indx]->conf.stream_preview_method == 2){
} else if (strm_info->cntlst[indx]->conf.stream_preview_method == 2) {
/* Static image for preview */
snprintf(strm_info->lnk_ref,WEBUI_LEN_LNK,"%s","/stream");
snprintf(strm_info->lnk_src,WEBUI_LEN_LNK,"%s","/current");
} else if (strm_info->cntlst[indx]->conf.stream_preview_method == 4){
} else if (strm_info->cntlst[indx]->conf.stream_preview_method == 4) {
/* Source image for preview */
snprintf(strm_info->lnk_ref,WEBUI_LEN_LNK,"%s","/source");
snprintf(strm_info->lnk_src,WEBUI_LEN_LNK,"%s","/source");
@@ -646,16 +648,19 @@ static void webu_html_preview(struct webui_ctx *webui)
" <p id=\"id_preview\">\n");
webu_write(webui, response);
indx_st = 1;
if (webui->cam_threads == 1) indx_st = 0;
if (webui->cam_threads == 1) {
indx_st = 0;
} else {
indx_st = 1;
}
for (indx = indx_st; indx<webui->cam_threads; indx++){
if (webui->cntlst[indx]->conf.stream_preview_newline){
for (indx = indx_st; indx<webui->cam_threads; indx++) {
if (webui->cntlst[indx]->conf.stream_preview_newline) {
snprintf(response, sizeof (response),"%s"," <br>\n");
webu_write(webui, response);
}
if (webui->cntlst[indx]->conf.stream_preview_method == 3){
if (webui->cntlst[indx]->conf.stream_preview_method == 3) {
preview_scale = 45;
} else {
preview_scale = webui->cntlst[indx]->conf.stream_preview_scale;
@@ -673,7 +678,7 @@ static void webu_html_preview(struct webui_ctx *webui)
,preview_scale);
webu_write(webui, response);
if (webui->cntlst[indx]->conf.stream_preview_method == 3){
if (webui->cntlst[indx]->conf.stream_preview_method == 3) {
strm_info.motion_images = TRUE;
webu_html_strminfo(&strm_info,indx);
snprintf(response, sizeof (response),
@@ -715,10 +720,10 @@ static void webu_html_script_action(struct webui_ctx *webui)
snprintf(response, sizeof (response),"%s",
" function action_click(actval) {\n"
" if (actval == \"config\"){\n"
" if (actval == \"config\") {\n"
" document.getElementById('trk_form').style.display=\"none\";\n"
" document.getElementById('cfg_form').style.display=\"inline\";\n"
" } else if (actval == \"track\"){\n"
" } else if (actval == \"track\") {\n"
" document.getElementById('cfg_form').style.display=\"none\";\n"
" document.getElementById('trk_form').style.display=\"inline\";\n"
" } else {\n"
@@ -740,7 +745,7 @@ static void webu_html_script_action(struct webui_ctx *webui)
webu_write(webui, response);
snprintf(response, sizeof (response),
" if (camnbr == \"all00\"){\n"
" if (camnbr == \"all00\") {\n"
" url = url + \"%05d\";\n"
" } else {\n"
" url = url + camnbr;\n"
@@ -771,18 +776,21 @@ static void webu_html_script_camera_thread(struct webui_ctx *webui)
int indx, indx_st, preview_scale;
struct strminfo_ctx strm_info;
indx_st = 1;
if (webui->cam_threads == 1) indx_st = 0;
if (webui->cam_threads == 1) {
indx_st = 0;
} else {
indx_st = 1;
}
strm_info.cntlst = webui->cntlst;
for (indx = indx_st; indx<webui->cam_threads; indx++){
for (indx = indx_st; indx<webui->cam_threads; indx++) {
snprintf(response, sizeof (response),
" if (camid == \"cam_%05d\"){\n"
" if (camid == \"cam_%05d\") {\n"
,webui->cntlst[indx]->camera_id);
webu_write(webui, response);
if (webui->cntlst[indx]->conf.stream_preview_method == 3){
if (webui->cntlst[indx]->conf.stream_preview_method == 3) {
preview_scale = 45;
} else {
preview_scale = 95;
@@ -799,7 +807,7 @@ static void webu_html_script_camera_thread(struct webui_ctx *webui)
,strm_info.lnk_camid, strm_info.lnk_src, preview_scale);
webu_write(webui, response);
if (webui->cntlst[indx]->conf.stream_preview_method == 3){
if (webui->cntlst[indx]->conf.stream_preview_method == 3) {
strm_info.motion_images = TRUE;
webu_html_strminfo(&strm_info, indx);
snprintf(response, sizeof (response),
@@ -812,7 +820,7 @@ static void webu_html_script_camera_thread(struct webui_ctx *webui)
webu_write(webui, response);
}
if (webui->cntlst[indx]->conf.camera_name == NULL){
if (webui->cntlst[indx]->conf.camera_name == NULL) {
snprintf(response, sizeof (response),
" header=\"<h3 id='h3_cam' data-cam='\" + camid + \"' "
" class='header-center' >%s %d (%s)</h3>\"\n"
@@ -848,27 +856,29 @@ static void webu_html_script_camera_all(struct webui_ctx *webui)
int indx, indx_st, preview_scale;
struct strminfo_ctx strm_info;
indx_st = 1;
if (webui->cam_threads == 1) indx_st = 0;
if (webui->cam_threads == 1) {
indx_st = 0;
} else {
indx_st = 1;
}
strm_info.cntlst = webui->cntlst;
snprintf(response, sizeof (response), " if (camid == \"cam_all00\"){\n");
snprintf(response, sizeof (response), " if (camid == \"cam_all00\") {\n");
webu_write(webui, response);
for (indx = indx_st; indx<webui->cam_threads; indx++){
if (indx == indx_st){
for (indx = indx_st; indx<webui->cam_threads; indx++) {
if (indx == indx_st) {
snprintf(response, sizeof (response),"%s"," preview = \"\";\n");
webu_write(webui, response);
}
if (webui->cntlst[indx]->conf.stream_preview_newline){
if (webui->cntlst[indx]->conf.stream_preview_newline) {
snprintf(response, sizeof (response),"%s"," preview = preview + \" <br>\";\n");
webu_write(webui, response);
}
if (webui->cntlst[indx]->conf.stream_preview_method == 3){
if (webui->cntlst[indx]->conf.stream_preview_method == 3) {
preview_scale = 45;
} else {
preview_scale = webui->cntlst[indx]->conf.stream_preview_scale;
@@ -886,7 +896,7 @@ static void webu_html_script_camera_all(struct webui_ctx *webui)
,preview_scale);
webu_write(webui, response);
if (webui->cntlst[indx]->conf.stream_preview_method == 3){
if (webui->cntlst[indx]->conf.stream_preview_method == 3) {
strm_info.motion_images = TRUE;
webu_html_strminfo(&strm_info, indx);
snprintf(response, sizeof (response),
@@ -947,7 +957,7 @@ static void webu_html_script_menucam(struct webui_ctx *webui)
snprintf(response, sizeof (response),"%s",
" function display_cameras() {\n"
" document.getElementById('act_btn').style.display = 'none';\n"
" if (document.getElementById('cam_btn').style.display == 'block'){\n"
" if (document.getElementById('cam_btn').style.display == 'block') {\n"
" document.getElementById('cam_btn').style.display = 'none';\n"
" } else {\n"
" document.getElementById('cam_btn').style.display = 'block';\n"
@@ -965,7 +975,7 @@ static void webu_html_script_menuact(struct webui_ctx *webui)
snprintf(response, sizeof (response),"%s",
" function display_actions() {\n"
" document.getElementById('cam_btn').style.display = 'none';\n"
" if (document.getElementById('act_btn').style.display == 'block'){\n"
" if (document.getElementById('act_btn').style.display == 'block') {\n"
" document.getElementById('act_btn').style.display = 'none';\n"
" } else {\n"
" document.getElementById('act_btn').style.display = 'block';\n"
@@ -1020,7 +1030,7 @@ static void webu_html_script_cfgclk(struct webui_ctx *webui)
snprintf(response, sizeof (response),
" var optval=encodeURI(baseval);\n"
" if (camnbr == \"all00\"){\n"
" if (camnbr == \"all00\") {\n"
" url = url + \"%05d\";\n"
" } else {\n"
" url = url + camnbr;\n"
@@ -1054,7 +1064,7 @@ static void webu_html_script_cfgchg(struct webui_ctx *webui)
" var camSel = 'data-'+ document.getElementById('h3_cam').getAttribute('data-cam');\n"
" var opts = document.getElementById('cfg_parms');\n"
" var optval = opts.options[opts.selectedIndex].getAttribute(camSel);\n"
" if (optval == null){\n"
" if (optval == null) {\n"
" optval = opts.options[opts.selectedIndex].getAttribute('data-cam_all00');\n"
" }\n"
" document.getElementById('cfg_value').value = optval;\n"
@@ -1070,7 +1080,7 @@ static void webu_html_script_trkchg(struct webui_ctx *webui)
" function track_change() {\n"
" var opts = document.getElementById('trk_option');\n"
" var optval = opts.options[opts.selectedIndex].getAttribute('data-trk');\n"
" if (optval == 'pan'){\n"
" if (optval == 'pan') {\n"
" document.getElementById('trk_panx').disabled=false;\n"
" document.getElementById('trk_tilty').disabled = false;\n"
" document.getElementById('trk_lblx').style.display='none';\n"
@@ -1080,7 +1090,7 @@ static void webu_html_script_trkchg(struct webui_ctx *webui)
webu_write(webui, response);
snprintf(response, sizeof (response),"%s",
" } else if (optval =='abs'){\n"
" } else if (optval =='abs') {\n"
" document.getElementById('trk_panx').disabled=false;\n"
" document.getElementById('trk_tilty').disabled = false;\n"
" document.getElementById('trk_lblx').value = 'X';\n"
@@ -1123,7 +1133,7 @@ static void webu_html_script_trkclk(struct webui_ctx *webui)
webu_write(webui, response);
snprintf(response, sizeof (response),
" if (camnbr == \"all00\"){\n"
" if (camnbr == \"all00\") {\n"
" url = url + \"%05d\";\n"
" } else {\n"
" url = url + camnbr;\n"
@@ -1133,7 +1143,7 @@ static void webu_html_script_trkclk(struct webui_ctx *webui)
snprintf(response, sizeof (response),"%s",
" if (optsel == 'pan'){\n"
" if (optsel == 'pan') {\n"
" url = url + '/track/set?pan=' + optval1 + '&tilt=' + optval2;\n"
" } else if (optsel == 'abs') {\n"
" url = url + '/track/set?x=' + optval1 + '&y=' + optval2;\n"
@@ -1267,13 +1277,13 @@ void webu_html_main(struct webui_ctx *webui)
} else if (!strcmp(webui->uri_cmd1,"config")) {
retcd = webu_process_config(webui);
} else if (!strcmp(webui->uri_cmd1,"action")){
} else if (!strcmp(webui->uri_cmd1,"action")) {
webu_process_action(webui);
} else if (!strcmp(webui->uri_cmd1,"detection")){
} else if (!strcmp(webui->uri_cmd1,"detection")) {
webu_process_action(webui);
} else if (!strcmp(webui->uri_cmd1,"track")){
} else if (!strcmp(webui->uri_cmd1,"track")) {
retcd = webu_process_track(webui);
} else{
@@ -1283,7 +1293,9 @@ void webu_html_main(struct webui_ctx *webui)
retcd = -1;
}
if (retcd < 0) webu_html_badreq(webui);
if (retcd < 0) {
webu_html_badreq(webui);
}
return;
}

View File

@@ -21,8 +21,10 @@
static void webu_stream_mjpeg_checkbuffers(struct webui_ctx *webui)
{
/* Allocate buffers if needed */
if (webui->resp_size < (size_t)webui->cnt->imgs.size_norm){
if (webui->resp_page != NULL) free(webui->resp_page);
if (webui->resp_size < (size_t)webui->cnt->imgs.size_norm) {
if (webui->resp_page != NULL) {
free(webui->resp_page);
}
webui->resp_page = mymalloc(webui->cnt->imgs.size_norm);
memset(webui->resp_page,'\0',webui->cnt->imgs.size_norm);
webui->resp_size = webui->cnt->imgs.size_norm;
@@ -48,12 +50,16 @@ static void webu_stream_mjpeg_delay(struct webui_ctx *webui)
*/
stream_delay = ((time_curr.tv_usec - webui->time_last.tv_usec)*1000) +
((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);
@@ -73,16 +79,16 @@ static void webu_stream_mjpeg_getimg(struct webui_ctx *webui)
memset(webui->resp_page, '\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->cnt->stream_norm;
} else if (webui->cnct_type == WEBUI_CNCT_SUB){
} else if (webui->cnct_type == WEBUI_CNCT_SUB) {
local_stream = &webui->cnt->stream_sub;
} else if (webui->cnct_type == WEBUI_CNCT_MOTION){
} else if (webui->cnct_type == WEBUI_CNCT_MOTION) {
local_stream = &webui->cnt->stream_motion;
} else if (webui->cnct_type == WEBUI_CNCT_SOURCE){
} else if (webui->cnct_type == WEBUI_CNCT_SOURCE) {
local_stream = &webui->cnt->stream_source;
} else {
@@ -91,7 +97,7 @@ static void webu_stream_mjpeg_getimg(struct webui_ctx *webui)
/* Copy jpg from the motion loop thread */
pthread_mutex_lock(&webui->cnt->mutex_stream);
if ((!webui->cnt->detecting_motion) && (webui->cnt->conf.stream_motion)){
if ((!webui->cnt->detecting_motion) && (webui->cnt->conf.stream_motion)) {
webui->stream_fps = 1;
} else {
webui->stream_fps = webui->cnt->conf.stream_maxrate;
@@ -131,9 +137,11 @@ static ssize_t webu_stream_mjpeg_response (void *cls, uint64_t pos, char *buf, s
(void)pos; /*Remove compiler warning */
if (webui->cnt->webcontrol_finish) return -1;
if (webui->cnt->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);
@@ -142,7 +150,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) {
@@ -154,7 +164,7 @@ static ssize_t webu_stream_mjpeg_response (void *cls, uint64_t pos, char *buf, s
memcpy(buf, webui->resp_page + 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;
}
@@ -172,7 +182,7 @@ static void webu_stream_static_getimg(struct webui_ctx *webui)
memset(webui->resp_page, '\0', webui->resp_size);
pthread_mutex_lock(&webui->cnt->mutex_stream);
if (webui->cnt->stream_norm.jpeg_data == NULL){
if (webui->cnt->stream_norm.jpeg_data == NULL) {
pthread_mutex_unlock(&webui->cnt->mutex_stream);
return;
}
@@ -189,13 +199,13 @@ static int webu_stream_checks(struct webui_ctx *webui)
/* Perform edits to determine whether the user specified a valid URL
* for the particular port
*/
if ((webui->cntlst != NULL) && (webui->thread_nbr >= webui->cam_threads)){
if ((webui->cntlst != NULL) && (webui->thread_nbr >= webui->cam_threads)) {
MOTION_LOG(ERR, TYPE_STREAM, NO_ERRNO
, _("Invalid thread specified: %s"),webui->url);
return -1;
}
if ((webui->cntlst != NULL) && (webui->thread_nbr < 0) && (webui->cam_threads > 1)){
if ((webui->cntlst != NULL) && (webui->thread_nbr < 0) && (webui->cam_threads > 1)) {
MOTION_LOG(ERR, TYPE_STREAM, NO_ERRNO
, _("Invalid thread specified: %s"),webui->url);
return -1;
@@ -258,7 +268,7 @@ static void webu_stream_cnct_count(struct webui_ctx *webui)
pthread_mutex_unlock(&webui->cnt->mutex_stream);
}
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
*/
@@ -273,7 +283,9 @@ int webu_stream_mjpeg(struct webui_ctx *webui)
int 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);
@@ -283,12 +295,12 @@ int 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->cnt->conf.stream_cors_header != NULL){
if (webui->cnt->conf.stream_cors_header != NULL) {
MHD_add_response_header (response, MHD_HTTP_HEADER_ACCESS_CONTROL_ALLOW_ORIGIN
, webui->cnt->conf.stream_cors_header);
}
@@ -309,7 +321,9 @@ int 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);
@@ -324,12 +338,12 @@ int webu_stream_static(struct webui_ctx *webui)
response = MHD_create_response_from_buffer (webui->resp_size
,(void *)webui->resp_page, MHD_RESPMEM_MUST_COPY);
if (!response){
if (!response) {
MOTION_LOG(ERR, TYPE_STREAM, NO_ERRNO, _("Invalid response"));
return MHD_NO;
}
if (webui->cnt->conf.stream_cors_header != NULL){
if (webui->cnt->conf.stream_cors_header != NULL) {
MHD_add_response_header (response, MHD_HTTP_HEADER_ACCESS_CONTROL_ALLOW_ORIGIN
, webui->cnt->conf.stream_cors_header);
}

View File

@@ -39,7 +39,7 @@ static void webu_text_camera_name(struct webui_ctx *webui)
{
char response[WEBUI_LEN_RESP];
if (webui->cntlst[webui->thread_nbr]->conf.camera_name == NULL){
if (webui->cntlst[webui->thread_nbr]->conf.camera_name == NULL) {
snprintf(response,sizeof(response),
"Camera %s %s\n"
,webui->uri_camid,webui->text_eol
@@ -126,7 +126,7 @@ static void webu_text_page_raw(struct webui_ctx *webui)
);
webu_write(webui, response);
if (webui->cam_threads > 1){
if (webui->cam_threads > 1) {
for (indx = 1; indx < webui->cam_threads; indx++) {
snprintf(response, sizeof (response),
"%d \n"
@@ -152,9 +152,9 @@ static void webu_text_page_basic(struct webui_ctx *webui)
,webui->cntlst[0]->camera_id);
webu_write(webui, response);
if (webui->cam_threads > 1){
if (webui->cam_threads > 1) {
for (indx = 1; indx < webui->cam_threads; indx++) {
if (webui->cntlst[indx]->conf.camera_name == NULL){
if (webui->cntlst[indx]->conf.camera_name == NULL) {
snprintf(response, sizeof (response),
"<a href='/%d/'>Camera %d</a><br>\n"
, webui->cntlst[indx]->camera_id
@@ -181,17 +181,17 @@ static void webu_text_list_raw(struct webui_ctx *webui)
const char *val_parm;
indx_parm = 0;
while (config_params[indx_parm].param_name != NULL){
while (config_params[indx_parm].param_name != NULL) {
if ((config_params[indx_parm].webui_level > webui->cntlst[0]->conf.webcontrol_parms) ||
(config_params[indx_parm].webui_level == WEBUI_LEVEL_NEVER) ||
((webui->thread_nbr != 0) && (config_params[indx_parm].main_thread != 0))){
((webui->thread_nbr != 0) && (config_params[indx_parm].main_thread != 0))) {
indx_parm++;
continue;
}
val_parm = config_params[indx_parm].print(webui->cntlst, NULL, indx_parm, webui->thread_nbr);
if (val_parm == NULL){
if (val_parm == NULL) {
val_parm = config_params[indx_parm].print(webui->cntlst, NULL, indx_parm, 0);
}
snprintf(response, sizeof (response),
@@ -227,17 +227,17 @@ static void webu_text_list_basic(struct webui_ctx *webui)
webu_write(webui, response);
indx_parm = 0;
while (config_params[indx_parm].param_name != NULL){
while (config_params[indx_parm].param_name != NULL) {
if ((config_params[indx_parm].webui_level > webui->cntlst[0]->conf.webcontrol_parms) ||
(config_params[indx_parm].webui_level == WEBUI_LEVEL_NEVER) ||
((webui->thread_nbr != 0) && (config_params[indx_parm].main_thread != 0))){
((webui->thread_nbr != 0) && (config_params[indx_parm].main_thread != 0))) {
indx_parm++;
continue;
}
val_parm = config_params[indx_parm].print(webui->cntlst, NULL, indx_parm, webui->thread_nbr);
if (val_parm == NULL){
if (val_parm == NULL) {
val_parm = config_params[indx_parm].print(webui->cntlst, NULL, indx_parm, 0);
}
snprintf(response, sizeof (response),
@@ -284,17 +284,17 @@ static void webu_text_set_menu(struct webui_ctx *webui)
webu_write(webui, response);
indx_parm = 0;
while (config_params[indx_parm].param_name != NULL){
while (config_params[indx_parm].param_name != NULL) {
if ((config_params[indx_parm].webui_level > webui->cntlst[0]->conf.webcontrol_parms) ||
(config_params[indx_parm].webui_level == WEBUI_LEVEL_NEVER) ||
((webui->thread_nbr != 0) && (config_params[indx_parm].main_thread != 0))){
((webui->thread_nbr != 0) && (config_params[indx_parm].main_thread != 0))) {
indx_parm++;
continue;
}
val_parm = config_params[indx_parm].print(webui->cntlst, NULL, indx_parm, webui->thread_nbr);
if (val_parm == NULL){
if (val_parm == NULL) {
val_parm = config_params[indx_parm].print(webui->cntlst, NULL, indx_parm, 0);
}
snprintf(response, sizeof(response),
@@ -337,7 +337,7 @@ static void webu_text_set_query(struct webui_ctx *webui)
webu_text_camera_name(webui);
indx_parm = 0;
while (config_params[indx_parm].param_name != NULL){
while (config_params[indx_parm].param_name != NULL) {
if ((config_params[indx_parm].webui_level > webui->cntlst[0]->conf.webcontrol_parms) ||
(config_params[indx_parm].webui_level == WEBUI_LEVEL_NEVER) ||
@@ -348,7 +348,7 @@ static void webu_text_set_query(struct webui_ctx *webui)
}
val_parm = config_params[indx_parm].print(webui->cntlst, NULL, indx_parm, webui->thread_nbr);
if (val_parm == NULL){
if (val_parm == NULL) {
val_parm = config_params[indx_parm].print(webui->cntlst, NULL, indx_parm, 0);
}
@@ -380,7 +380,7 @@ static void webu_text_set_assign(struct webui_ctx *webui)
retcd = webu_process_config(webui);
if (retcd == 0){
if (retcd == 0) {
webu_text_header(webui);
webu_text_back(webui,"/config");
@@ -419,11 +419,11 @@ static void webu_text_get_menu(struct webui_ctx *webui)
webu_write(webui, response);
indx_parm = 0;
while (config_params[indx_parm].param_name != NULL){
while (config_params[indx_parm].param_name != NULL) {
if ((config_params[indx_parm].webui_level > webui->cntlst[0]->conf.webcontrol_parms) ||
(config_params[indx_parm].webui_level == WEBUI_LEVEL_NEVER) ||
((webui->thread_nbr != 0) && (config_params[indx_parm].main_thread != 0))){
((webui->thread_nbr != 0) && (config_params[indx_parm].main_thread != 0))) {
indx_parm++;
continue;
}
@@ -655,33 +655,33 @@ static void webu_text_action(struct webui_ctx *webui)
{
/* Call the action functions */
if (!strcmp(webui->uri_cmd2,"makemovie")){
if (!strcmp(webui->uri_cmd2,"makemovie")) {
webu_text_action_makemovie(webui);
} else if (strcmp(webui->uri_cmd2,"eventstart") == 0){
} else if (strcmp(webui->uri_cmd2,"eventstart") == 0) {
webu_text_action_eventstart(webui);
} else if (!strcmp(webui->uri_cmd2,"eventend")){
} else if (!strcmp(webui->uri_cmd2,"eventend")) {
webu_text_action_eventend(webui);
} else if (!strcmp(webui->uri_cmd2,"snapshot")){
} else if (!strcmp(webui->uri_cmd2,"snapshot")) {
webu_text_action_snapshot(webui);
} else if (!strcmp(webui->uri_cmd2,"restart")){
} else if (!strcmp(webui->uri_cmd2,"restart")) {
webu_text_action_restart(webui);
} else if (!strcmp(webui->uri_cmd2,"start")){
} else if (!strcmp(webui->uri_cmd2,"start")) {
webu_text_action_start(webui);
} else if (!strcmp(webui->uri_cmd2,"pause")){
} else if (!strcmp(webui->uri_cmd2,"pause")) {
webu_text_action_pause(webui);
} else if ((!strcmp(webui->uri_cmd2,"quit")) ||
(!strcmp(webui->uri_cmd2,"end"))){
(!strcmp(webui->uri_cmd2,"end"))) {
webu_text_action_quit(webui);
} else if ((!strcmp(webui->uri_cmd2,"write")) ||
(!strcmp(webui->uri_cmd2,"writeyes"))){
(!strcmp(webui->uri_cmd2,"writeyes"))) {
webu_text_action_write(webui);
} else {
@@ -729,7 +729,7 @@ static void webu_text_track(struct webui_ctx *webui)
int retcd;
retcd = webu_process_track(webui);
if (retcd == 0){
if (retcd == 0) {
webu_text_header(webui);
webu_text_back(webui,"/track");
@@ -909,7 +909,7 @@ void webu_text_get_query(struct webui_ctx *webui)
snprintf(temp_name, WEBUI_LEN_PARM, "%s", webui->uri_value1);
indx_parm=0;
while (dep_config_params[indx_parm].name != NULL) {
if (strcmp(dep_config_params[indx_parm].name, webui->uri_value1) == 0){
if (strcmp(dep_config_params[indx_parm].name, webui->uri_value1) == 0) {
snprintf(temp_name, WEBUI_LEN_PARM, "%s", dep_config_params[indx_parm].newname);
break;
}
@@ -917,22 +917,22 @@ void webu_text_get_query(struct webui_ctx *webui)
}
indx_parm = 0;
while (config_params[indx_parm].param_name != NULL){
while (config_params[indx_parm].param_name != NULL) {
if ((config_params[indx_parm].webui_level > webui->cntlst[0]->conf.webcontrol_parms) ||
(config_params[indx_parm].webui_level == WEBUI_LEVEL_NEVER) ||
strcmp(webui->uri_parm1,"query") ||
strcmp(temp_name, config_params[indx_parm].param_name)){
strcmp(temp_name, config_params[indx_parm].param_name)) {
indx_parm++;
continue;
}
val_parm = config_params[indx_parm].print(webui->cntlst, NULL, indx_parm, webui->thread_nbr);
if (val_parm == NULL){
if (val_parm == NULL) {
val_parm = config_params[indx_parm].print(webui->cntlst, NULL, indx_parm, 0);
}
if (strcmp(webui->uri_value1, config_params[indx_parm].param_name) != 0){
if (strcmp(webui->uri_value1, config_params[indx_parm].param_name) != 0) {
MOTION_LOG(NTC, TYPE_STREAM, NO_ERRNO
, _("'%s' option is depreciated. New option name is '%s'")
,webui->uri_value1, config_params[indx_parm].param_name);
@@ -967,7 +967,7 @@ void webu_text_get_query(struct webui_ctx *webui)
break;
}
if (config_params[indx_parm].param_name == NULL){
if (config_params[indx_parm].param_name == NULL) {
webu_text_badreq(webui);
}
@@ -984,9 +984,12 @@ void webu_text_status(struct webui_ctx *webui)
webu_text_back(webui,"/detection");
if (webui->thread_nbr == 0){
indx_st = 1;
if (webui->cam_threads == 1) indx_st = 0;
if (webui->thread_nbr == 0) {
if (webui->cam_threads == 1) {
indx_st = 0;
} else {
indx_st = 1;
}
for (indx = indx_st; indx < webui->cam_threads; indx++) {
snprintf(response, sizeof(response),
@@ -1023,9 +1026,12 @@ void webu_text_connection(struct webui_ctx *webui)
webu_text_camera_name(webui);
if (webui->thread_nbr == 0){
indx_st = 1;
if (webui->cam_threads == 1) indx_st = 0;
if (webui->thread_nbr == 0) {
if (webui->cam_threads == 1) {
indx_st = 0;
} else {
indx_st = 1;
}
for (indx = indx_st; indx < webui->cam_threads; indx++) {
snprintf(response,sizeof(response)
@@ -1072,7 +1078,7 @@ void webu_text_main(struct webui_ctx *webui)
webu_text_seteol(webui);
if (strlen(webui->uri_camid) == 0){
if (strlen(webui->uri_camid) == 0) {
if (webui->cntlst[0]->conf.webcontrol_interface == 2) {
webu_text_page_basic(webui);
} else {
@@ -1134,11 +1140,11 @@ void webu_text_main(struct webui_ctx *webui)
webu_text_action(webui);
} else if ((strcmp(webui->uri_cmd1,"action") == 0) &&
(strcmp(webui->uri_cmd2,"quit") == 0)){
(strcmp(webui->uri_cmd2,"quit") == 0)) {
webu_text_action(webui);
} else if ((strcmp(webui->uri_cmd1,"action") == 0) &&
(strcmp(webui->uri_cmd2,"end") == 0)){
(strcmp(webui->uri_cmd2,"end") == 0)) {
webu_text_action(webui);
} else if (!strcmp(webui->uri_cmd1,"action")) {
@@ -1149,7 +1155,7 @@ void webu_text_main(struct webui_ctx *webui)
(strlen(webui->uri_parm1) == 0)) {
webu_text_track_pantilt(webui);
} else if ((strcmp(webui->uri_cmd1,"track") == 0)){
} else if ((strcmp(webui->uri_cmd1,"track") == 0)) {
webu_text_track(webui);
} else{