From f7469950d0d98ba8c48026c5ac2f206a34e9a33e Mon Sep 17 00:00:00 2001 From: AngelCarpintero Date: Sun, 4 Apr 2010 21:50:50 +0000 Subject: [PATCH] Added a macro MOTION_LOG , no need to add __FUNCTION__ anymore. --- CHANGELOG | 4 +- alg.c | 235 ++++++------ conf.c | 255 ++++++++----- configure | 84 +++-- configure.in | 66 ++-- draw.c | 8 +- event.c | 90 +++-- ffmpeg.c | 155 ++++---- jpegutils.c | 212 ++++++----- logger.c | 2 +- logger.h | 2 + motion.c | 273 +++++++------- netcam.c | 867 ++++++++++++++++++++++----------------------- netcam_ftp.c | 156 ++++---- netcam_jpeg.c | 143 ++++---- netcam_wget.c | 119 ++++--- picture.c | 228 +++++++----- rotate.c | 32 +- stream.c | 155 ++++---- track.c | 212 ++++++----- video.c | 116 +++--- video2.c | 199 +++++------ video_common.c | 115 +++--- video_freebsd.c | 284 +++++++-------- vloopback_motion.c | 49 ++- webhttpd.c | 115 +++--- 26 files changed, 2115 insertions(+), 2061 deletions(-) diff --git a/CHANGELOG b/CHANGELOG index 427173c..0f6125e 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -36,8 +36,8 @@ Features to the "Live Stream Server". (Michael Finsterbusch) http://www.lavrsen.dk/foswiki/bin/view/Motion/MotionStreamAuthPatch * Implemented new logging system - http://www.lavrsen.dk/foswiki/bin/view/Motion/MotionLog (Angel Carpintero) - + http://www.lavrsen.dk/foswiki/bin/view/Motion/MotionLog (Angel Carpintero) + * Added a macro MOTION_LOG , no need to add __FUNCTION__ anymore. (Angel Carpintero) Bugfixes * Avoid segfault detecting strerror_r() version GNU or SUSv3. (Angel Carpintero) diff --git a/alg.c b/alg.c index 8c7b501..f2e22bd 100644 --- a/alg.c +++ b/alg.c @@ -17,8 +17,9 @@ #define MAX2(x, y) ((x) > (y) ? (x) : (y)) #define MAX3(x, y, z) ((x) > (y) ? ((x) > (z) ? (x) : (z)) : ((y) > (z) ? (y) : (z))) -/* - * alg_locate_center_size locates the center and size of the movement. +/** + * alg_locate_center_size + * Locates the center and size of the movement. */ void alg_locate_center_size(struct images *imgs, int width, int height, struct coord *cent) { @@ -33,7 +34,7 @@ void alg_locate_center_size(struct images *imgs, int width, int height, struct c cent->minx = width; cent->miny = height; - /* If Labeling enabled - locate center of largest labelgroup */ + /* If Labeling enabled - locate center of largest labelgroup. */ if (imgs->labelsize_max) { /* Locate largest labelgroup */ for (y = 0; y < height; y++) { @@ -65,14 +66,14 @@ void alg_locate_center_size(struct images *imgs, int width, int height, struct c cent->y = cent->y / centc; } - /* Now we find the size of the Motion */ + /* Now we find the size of the Motion. */ - /* First reset pointers back to initial value */ + /* First reset pointers back to initial value. */ centc = 0; labels = imgs->labels; out = imgs->out; - /* If Labeling then we find the area around largest labelgroup instead */ + /* If Labeling then we find the area around largest labelgroup instead. */ if (imgs->labelsize_max) { for (y = 0; y < height; y++) { for (x = 0; x < width; x++) { @@ -119,7 +120,7 @@ void alg_locate_center_size(struct images *imgs, int width, int height, struct c /* * Make the box a little bigger in y direction to make sure the * heads fit in so we multiply by 3 instead of 2 which seems to - * to work well in practical + * to work well in practical. */ cent->miny = cent->y - ydist / centc * 3; cent->maxy = cent->y + ydist / centc * 2; @@ -157,15 +158,16 @@ void alg_locate_center_size(struct images *imgs, int width, int height, struct c /* * We want to center Y coordinate to be the center of the action. * The head of a person is important so we correct the cent.y coordinate - * to match the correction to include a persons head that we just did above + * to match the correction to include a persons head that we just did above. */ cent->y = (cent->miny + cent->maxy) / 2; } -/* - * alg_draw_location draws a box around the movement +/** + * alg_draw_location + * Draws a box around the movement. */ void alg_draw_location(struct coord *cent, struct images *imgs, int width, unsigned char *new, int style, int mode, int process_thisframe) @@ -175,7 +177,7 @@ void alg_draw_location(struct coord *cent, struct images *imgs, int width, unsig out = imgs->out; - /* debug image always gets a 'normal' box */ + /* Debug image always gets a 'normal' box. */ if ((mode == LOCATE_BOTH) && process_thisframe) { int width_miny = width * cent->miny; int width_maxy = width * cent->maxy; @@ -196,7 +198,7 @@ void alg_draw_location(struct coord *cent, struct images *imgs, int width, unsig out[width_maxx_y] =~out[width_maxx_y]; } } - if (style == LOCATE_BOX) { /* draw a box on normal images */ + if (style == LOCATE_BOX) { /* Draw a box on normal images. */ int width_miny = width * cent->miny; int width_maxy = width * cent->maxy; @@ -215,7 +217,7 @@ void alg_draw_location(struct coord *cent, struct images *imgs, int width, unsig new[width_minx_y] =~new[width_minx_y]; new[width_maxx_y] =~new[width_maxx_y]; } - } else if (style == LOCATE_CROSS) { /* draw a cross on normal images */ + } else if (style == LOCATE_CROSS) { /* Draw a cross on normal images. */ int centy = cent->y * width; for (x = cent->x - 10; x <= cent->x + 10; x++) { @@ -231,8 +233,9 @@ void alg_draw_location(struct coord *cent, struct images *imgs, int width, unsig } -/* - * alg_draw_red_location draws a RED box around the movement +/** + * alg_draw_red_location + * Draws a RED box around the movement. */ void alg_draw_red_location(struct coord *cent, struct images *imgs, int width, unsigned char *new, int style, int mode, int process_thisframe) @@ -249,7 +252,7 @@ void alg_draw_red_location(struct coord *cent, struct images *imgs, int width, u new_u = new + x; new_v = new + v; - /* debug image always gets a 'normal' box */ + /* Debug image always gets a 'normal' box. */ if ((mode == LOCATE_BOTH) && process_thisframe) { int width_miny = width * cent->miny; int width_maxy = width * cent->maxy; @@ -271,7 +274,7 @@ void alg_draw_red_location(struct coord *cent, struct images *imgs, int width, u } } - if (style == LOCATE_REDBOX) { /* draw a red box on normal images */ + if (style == LOCATE_REDBOX) { /* Draw a red box on normal images. */ int width_miny = width * cent->miny; int width_maxy = width * cent->maxy; int cwidth_miny = cwidth * (cent->miny / 2); @@ -324,7 +327,7 @@ void alg_draw_red_location(struct coord *cent, struct images *imgs, int width, u new[width_minx_y + width + 1] = 128; new[width_maxx_y + width + 1] = 128; } - } else if (style == LOCATE_REDCROSS) { /* draw a red cross on normal images */ + } else if (style == LOCATE_REDCROSS) { /* Draw a red cross on normal images. */ int cwidth_maxy = cwidth * (cent->y / 2); for (x = cent->x - 10; x <= cent->x + 10; x += 2) { @@ -349,7 +352,10 @@ void alg_draw_red_location(struct coord *cent, struct images *imgs, int width, u #define DIFF(x, y) (ABS((x)-(y))) #define NDIFF(x, y) (ABS(x) * NORM / (ABS(x) + 2 * DIFF(x, y))) - +/** + * alg_noise_tune + * + */ void alg_noise_tune(struct context *cnt, unsigned char *new) { struct images *imgs = &cnt->imgs; @@ -377,13 +383,17 @@ 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; } +/** + * alg_threshold_tune + * + */ void alg_threshold_tune(struct context *cnt, int diffs, int motion) { int i; @@ -425,8 +435,8 @@ void alg_threshold_tune(struct context *cnt, int diffs, int motion) * http://www.acm.org/pubs/tog/GraphicsGems/ * http://www.codeproject.com/gdi/QuickFill.asp - * Filled horizontal segment of scanline y for xl<=x<=xr. - * Parent segment was on line y-dy. dy=1 or -1 + * Filled horizontal segment of scanline y for xl <= x <= xr. + * Parent segment was on line y - dy. dy = 1 or -1 */ #define MAXS 10000 /* max depth of stack */ @@ -442,25 +452,28 @@ typedef struct { short y, xl, xr, dy; } Segment; - +/** + * iflood + * + */ static int iflood(int x, int y, int width, int height, unsigned char *out, int *labels, int newvalue, int oldvalue) { int l, x1, x2, dy; - Segment stack[MAXS], *sp = stack; /* stack of filled segments */ + Segment stack[MAXS], *sp = stack; /* Stack of filled segments. */ int count = 0; 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) */ + PUSH(y, x, x, 1); /* Needed in some cases. */ + PUSH(y+1, x, x, -1); /* Seed segment (popped 1st). */ while (sp > stack) { - /* pop segment off stack and fill a neighboring scan line */ + /* Pop segment off stack and fill a neighboring scan line. */ POP(y, x1, x2, dy); /* - * segment of scan line y-dy for x1<=x<=x2 was previously filled, + * Segment of scan line y-dy for x1<=x<=x2 was previously filled, * now explore adjacent pixels in scan line y */ for (x = x1; x >= 0 && out[y * width + x] != 0 && labels[y * width + x] == oldvalue; x--) { @@ -474,7 +487,7 @@ static int iflood(int x, int y, int width, int height, l = x + 1; if (l < x1) - PUSH(y, l, x1 - 1, -dy); /* leak on left? */ + PUSH(y, l, x1 - 1, -dy); /* Leak on left? */ x = x1 + 1; @@ -487,7 +500,7 @@ static int iflood(int x, int y, int width, int height, PUSH(y, l, x - 1, dy); if (x > x2 + 1) - PUSH(y, x2 + 1, x - 1, -dy); /* leak on right? */ + PUSH(y, x2 + 1, x - 1, -dy); /* Leak on right? */ skip: @@ -499,6 +512,10 @@ static int iflood(int x, int y, int width, int height, return count; } +/** + * alg_labeling + * + */ static int alg_labeling(struct context *cnt) { struct images *imgs = &cnt->imgs; @@ -512,34 +529,34 @@ static int alg_labeling(struct context *cnt) cnt->current_image->total_labels = 0; imgs->labelsize_max = 0; - /* ALL labels above threshold are counted as labelgroup */ + /* ALL labels above threshold are counted as labelgroup. */ imgs->labelgroup_max = 0; imgs->labels_above = 0; - /* init: 0 means no label set / not checked */ + /* Init: 0 means no label set / not checked. */ memset(labels, 0, width * height * sizeof(labels)); pixelpos = 0; for (iy = 0; iy < height - 1; iy++) { for (ix = 0; ix < width - 1; ix++, pixelpos++) { - /* no motion - no label */ + /* No motion - no label */ if (out[pixelpos] == 0) { labels[pixelpos] = 1; continue; } - /* already visited by iflood */ + /* Already visited by iflood */ if (labels[pixelpos] > 0) continue; labelsize = iflood(ix, iy, width, height, out, labels, current_label, 0); if (labelsize > 0) { - motion_log(DBG, TYPE_ALL, NO_ERRNO, "%s: Label: %i (%i) Size: %i (%i,%i)", - __FUNCTION__, current_label, cnt->current_image->total_labels, + MOTION_LOG(DBG, TYPE_ALL, NO_ERRNO, "%s: Label: %i (%i) Size: %i (%i,%i)", + current_label, cnt->current_image->total_labels, labelsize, ix, iy); - /* Label above threshold? Mark it again (add 32768 to labelnumber) */ + /* Label above threshold? Mark it again (add 32768 to labelnumber). */ if (labelsize > cnt->threshold) { labelsize = iflood(ix, iy, width, height, out, labels, current_label + 32768, current_label); imgs->labelgroup_max += labelsize; @@ -555,29 +572,30 @@ static int alg_labeling(struct context *cnt) current_label++; } } - pixelpos++; /* compensate for ixlargest_label, imgs->labelsize_max, + MOTION_LOG(DBG, TYPE_ALL, NO_ERRNO, "%s: %i Labels found. Largest connected Area: %i Pixel(s). " + "Largest Label: %i", imgs->largest_label, imgs->labelsize_max, cnt->current_image->total_labels); - /* return group of significant labels */ + /* Return group of significant labels. */ return imgs->labelgroup_max; } -/* - * dilate9 dilates a 3x3 box +/** + * dilate9 + * Dilates a 3x3 box. */ static int dilate9(unsigned char *img, int width, int height, void *buffer) { /* - * - row1, row2 and row3 represent lines in the temporary buffer - * - window is a sliding window containing max values of the columns - * in the 3x3 matrix - * - widx is an index into the sliding window (this is faster than - * doing modulo 3 on i) - * - blob keeps the current max value + * - row1, row2 and row3 represent lines in the temporary buffer. + * - Window is a sliding window containing max values of the columns + * in the 3x3 matrix. + * - width is an index into the sliding window (this is faster than + * doing modulo 3 on i). + * - blob keeps the current max value. */ int y, i, sum = 0, widx; unsigned char *row1, *row2, *row3, *rowTemp,*yp; @@ -652,14 +670,15 @@ static int dilate9(unsigned char *img, int width, int height, void *buffer) return sum; } -/* - * dilate5 dilates a + shape +/** + * dilate5 + * Dilates a + shape. */ static int dilate5(unsigned char *img, int width, int height, void *buffer) { /* - * - row1, row2 and row3 represent lines in the temporary buffer - * - mem holds the max value of the overlapping part of two + shapes + * - row1, row2 and row3 represent lines in the temporary buffer. + * - mem holds the max value of the overlapping part of two + shapes. */ int y, i, sum = 0; unsigned char *row1, *row2, *row3, *rowTemp, *yp; @@ -722,8 +741,9 @@ static int dilate5(unsigned char *img, int width, int height, void *buffer) return sum; } -/* - * erode9 erodes a 3x3 box +/** + * erode9 + * Erodes a 3x3 box. */ static int erode9(unsigned char *img, int width, int height, void *buffer, unsigned char flag) { @@ -765,8 +785,9 @@ static int erode9(unsigned char *img, int width, int height, void *buffer, unsig return sum; } -/* - * erode5 erodes in a + shape +/** + * erode5 + * Erodes in a + shape. */ static int erode5(unsigned char *img, int width, int height, void *buffer, unsigned char flag) { @@ -804,8 +825,9 @@ static int erode5(unsigned char *img, int width, int height, void *buffer, unsig return sum; } -/* - * alg_despeckle despeckling routine to remove noisy detections. +/** + * alg_despeckle + * Despeckling routine to remove noisy detections. */ int alg_despeckle(struct context *cnt, int olddiffs) { @@ -836,7 +858,7 @@ int alg_despeckle(struct context *cnt, int olddiffs) diffs = dilate5(out, width, height, common_buffer); done = 1; break; - /* no further despeckle after labeling! */ + /* No further despeckle after labeling! */ case 'l': diffs = alg_labeling(cnt); i = len; @@ -857,8 +879,9 @@ int alg_despeckle(struct context *cnt, int olddiffs) return olddiffs; } -/* - * alg_tune_smartmask generates actual smartmask. Calculate sensitivity based on motion +/** + * alg_tune_smartmask + * Generates actual smartmask. Calculate sensitivity based on motion. */ void alg_tune_smartmask(struct context *cnt) { @@ -870,10 +893,10 @@ void alg_tune_smartmask(struct context *cnt) int sensitivity = cnt->lastrate * (11 - cnt->smartmask_speed); for (i = 0; i < motionsize; i++) { - /* Decrease smart_mask sensitivity every 5*speed seconds only */ + /* Decrease smart_mask sensitivity every 5*speed seconds only. */ if (smartmask[i] > 0) smartmask[i]--; - /* Increase smart_mask sensitivity based on the buffered values */ + /* Increase smart_mask sensitivity based on the buffered values. */ diff = smartmask_buffer[i]/sensitivity; if (diff) { @@ -883,13 +906,13 @@ void alg_tune_smartmask(struct context *cnt) smartmask[i] = 80; smartmask_buffer[i] %= sensitivity; } - /* Transfer raw mask to the final stage when above trigger value */ + /* Transfer raw mask to the final stage when above trigger value. */ if (smartmask[i] > 20) smartmask_final[i] = 0; else smartmask_final[i] = 255; } - /* Further expansion (here:erode due to inverted logic!) of the mask */ + /* Further expansion (here:erode due to inverted logic!) of the mask. */ diff = erode9(smartmask_final, cnt->imgs.width, cnt->imgs.height, cnt->imgs.common_buffer, 255); diff = erode5(smartmask_final, cnt->imgs.width, cnt->imgs.height, @@ -899,7 +922,11 @@ void alg_tune_smartmask(struct context *cnt) /* Increment for *smartmask_buffer in alg_diff_standard. */ #define SMARTMASK_SENSITIVITY_INCR 5 -int alg_diff_standard (struct context *cnt, unsigned char *new) +/** + * alg_diff_standard + * + */ +int alg_diff_standard(struct context *cnt, unsigned char *new) { struct images *imgs = &cnt->imgs; int i, diffs = 0; @@ -911,12 +938,12 @@ int alg_diff_standard (struct context *cnt, unsigned char *new) unsigned char *smartmask_final = imgs->smartmask_final; int *smartmask_buffer = imgs->smartmask_buffer; #ifdef HAVE_MMX - mmx_t mmtemp; /* used for transferring to/from memory */ - int unload; /* counter for unloading diff counts */ + mmx_t mmtemp; /* Used for transferring to/from memory. */ + int unload; /* Counter for unloading diff counts. */ #endif i = imgs->motionsize; - memset(out + i, 128, i / 2); /* motion pictures are now b/w i.o. green */ + memset(out + i, 128, i / 2); /* Motion pictures are now b/w i.o. green */ /* * Keeping this memset in the MMX case when zeroes are necessarily * written anyway seems to be beneficial in terms of speed. Perhaps a @@ -942,7 +969,7 @@ int alg_diff_standard (struct context *cnt, unsigned char *new) /* * To avoid a div, we work with differences multiplied by 255 in the * default case and *mask otherwise. Thus, the limit to compare with is - * 255*(noise+1)-1). + * 255 * (noise + 1) - 1). */ mmtemp.uw[0] = mmtemp.uw[1] = mmtemp.uw[2] = mmtemp.uw[3] = (unsigned short)(noise * 255 + 254); @@ -1057,7 +1084,7 @@ int alg_diff_standard (struct context *cnt, unsigned char *new) movq_r2m(mm0, mmtemp); /* U */ pcmpeqb_r2r(mm4, mm3); /* V: mm3 = 0xff where sX==0 */ - /* ANDN negates the target before anding. */ + /* AND negates the target before anding. */ pandn_r2r(mm0, mm3); /* U: mm3 = 0xff where dX>noise && sX>0 */ movq_r2r(mm3, mm0); /* U */ @@ -1133,8 +1160,8 @@ 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 */ + register unsigned char curdiff = (int)(abs(*ref - *new)); /* Using a temp variable is 12% faster. */ + /* Apply fixed mask */ if (mask) curdiff = ((int)(curdiff * *mask++) / 255); @@ -1149,7 +1176,7 @@ int alg_diff_standard (struct context *cnt, unsigned char *new) */ if (cnt->event_nr != cnt->prev_event) (*smartmask_buffer) += SMARTMASK_SENSITIVITY_INCR; - /* apply smart_mask */ + /* Apply smart_mask */ if (!*smartmask_final) curdiff = 0; } @@ -1168,8 +1195,9 @@ int alg_diff_standard (struct context *cnt, unsigned char *new) return diffs; } -/* - * alg_diff_fast very fast diff function, does not apply mask overlaying. +/** + * alg_diff_fast + * Very fast diff function, does not apply mask overlaying. */ static char alg_diff_fast(struct context *cnt, int max_n_changes, unsigned char *new) { @@ -1180,13 +1208,13 @@ static char alg_diff_fast(struct context *cnt, int max_n_changes, unsigned char if (!step % 2) step++; - /* we're checking only 1 of several pixels */ + /* We're checking only 1 of several pixels. */ max_n_changes /= step; i = imgs->motionsize; for (; i > 0; i -= step) { - register unsigned char curdiff = (int)(abs((char)(*ref - *new))); /* using a temp variable is 12% faster */ + 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) @@ -1199,9 +1227,10 @@ static char alg_diff_fast(struct context *cnt, int max_n_changes, unsigned char return 0; } -/* - * alg_diff uses diff_fast to quickly decide if there is anything worth - * sending to diff_standard. +/** + * alg_diff + * Uses diff_fast to quickly decide if there is anything worth + * sending to diff_standard. */ int alg_diff(struct context *cnt, unsigned char *new) { @@ -1213,10 +1242,11 @@ int alg_diff(struct context *cnt, unsigned char *new) return diffs; } -/* - * alg_lightswitch detects a sudden massive change in the picture. - * It is assumed to be the light being switched on or a camera displacement. - * In any way the user doesn't think it is worth capturing. +/** + * alg_lightswitch + * Detects a sudden massive change in the picture. + * It is assumed to be the light being switched on or a camera displacement. + * In any way the user doesn't think it is worth capturing. */ int alg_lightswitch(struct context *cnt, int diffs) { @@ -1227,13 +1257,17 @@ int alg_lightswitch(struct context *cnt, int diffs) if (cnt->conf.lightswitch > 100) cnt->conf.lightswitch = 100; - /* is lightswitch percent of the image changed? */ + /* Is lightswitch percent of the image changed? */ if (diffs > (imgs->motionsize * cnt->conf.lightswitch / 100)) return 1; return 0; } +/** + * alg_switchfilter + * + */ int alg_switchfilter(struct context *cnt, int diffs, unsigned char *newimg) { int linediff = diffs / cnt->imgs.height; @@ -1280,8 +1314,7 @@ int alg_switchfilter(struct context *cnt, int diffs, unsigned char *newimg) * action - UPDATE_REF_FRAME or RESET_REF_FRAME * */ -/* Seconds */ -#define ACCEPT_STATIC_OBJECT_TIME 10 +#define ACCEPT_STATIC_OBJECT_TIME 10 /* Seconds */ #define EXCLUDE_LEVEL_PERCENT 20 void alg_update_reference_frame(struct context *cnt, int action) { @@ -1293,29 +1326,29 @@ void alg_update_reference_frame(struct context *cnt, int action) unsigned char *smartmask = cnt->imgs.smartmask_final; unsigned char *out = cnt->imgs.out; - if (cnt->lastrate > 5) /* match rate limit */ + if (cnt->lastrate > 5) /* Match rate limit */ accept_timer /= (cnt->lastrate / 3); - if (action == UPDATE_REF_FRAME) { /* black&white only for better performance */ + if (action == UPDATE_REF_FRAME) { /* Black&white only for better performance. */ threshold_ref = cnt->noise * EXCLUDE_LEVEL_PERCENT / 100; for (i = cnt->imgs.motionsize; i > 0; i--) { - /* exclude pixels from ref frame well below noise level */ + /* Exclude pixels from ref frame well below noise level. */ if (((int)(abs(*ref - *image_virgin)) > threshold_ref) && (*smartmask)) { - if (*ref_dyn == 0) { /* Always give new pixels a chance */ + if (*ref_dyn == 0) { /* Always give new pixels a chance. */ *ref_dyn = 1; - } else if (*ref_dyn > accept_timer) { /* Include static Object after some time */ + } else if (*ref_dyn > accept_timer) { /* Include static Object after some time. */ *ref_dyn = 0; *ref = *image_virgin; } else if (*out) { - (*ref_dyn)++; /* Motionpixel? Keep excluding from ref frame */ + (*ref_dyn)++; /* Motionpixel? Keep excluding from ref frame. */ } else { - *ref_dyn = 0; /* Nothing special - release pixel */ + *ref_dyn = 0; /* Nothing special - release pixel. */ *ref = (*ref + *image_virgin) / 2; } - } else { /* No motion: copy to ref frame */ - *ref_dyn = 0; /* reset pixel */ + } else { /* No motion: copy to ref frame. */ + *ref_dyn = 0; /* Reset pixel */ *ref = *image_virgin; } @@ -1326,10 +1359,10 @@ void alg_update_reference_frame(struct context *cnt, int action) out++; } /* end for i */ - } else { /* action == RESET_REF_FRAME - also used to initialize the frame at startup */ - /* copy fresh image */ + } else { /* action == RESET_REF_FRAME - also used to initialize the frame at startup. */ + /* Copy fresh image */ memcpy(cnt->imgs.ref, cnt->imgs.image_virgin, cnt->imgs.size); - /* reset static objects */ + /* Reset static objects */ memset(cnt->imgs.ref_dyn, 0, cnt->imgs.motionsize * sizeof(cnt->imgs.ref_dyn)); } } diff --git a/conf.c b/conf.c index 647312c..28862db 100644 --- a/conf.c +++ b/conf.c @@ -1493,15 +1493,20 @@ config_param config_params[] = { { NULL, NULL, 0, 0, NULL, NULL } }; -/* conf_cmdline sets the conf struct options as defined by the Command-line. - * Any option already set from a config file are overridden. +/** + * conf_cmdline + * Sets the conf struct options as defined by the Command-line. + * Any option already set from a config file are overridden. + * + * Returns nothing. */ static void conf_cmdline(struct context *cnt, int thread) { struct config *conf = &cnt->conf; int c; - /* For the string options, we free() if necessary and malloc() + /* + * For the string options, we free() if necessary and malloc() * if necessary. This is accomplished by calling mystrcpy(); * see this function for more information. */ @@ -1518,7 +1523,7 @@ static void conf_cmdline(struct context *cnt, int thread) conf->setup_mode = 1; break; case 'd': - /* no validation - just take what user gives */ + /* No validation - just take what user gives. */ if (thread == -1) debug_level = (unsigned int)atoi(optarg); break; @@ -1545,11 +1550,15 @@ static void conf_cmdline(struct context *cnt, int thread) } -/* conf_cmdparse sets a config option given by 'cmd' to the value given by 'arg1'. - * Based on the name of the option it searches through the struct 'config_params' - * for an option where the config_params[i].param_name matches the option. - * By calling the function pointed to by config_params[i].copy the option gets - * assigned. +/** + * conf_cmdparse + * Sets a config option given by 'cmd' to the value given by 'arg1'. + * Based on the name of the option it searches through the struct 'config_params' + * for an option where the config_params[i].param_name matches the option. + * By calling the function pointed to by config_params[i].copy the option gets + * assigned. + * + * Returns context struct. */ struct context **conf_cmdparse(struct context **cnt, const char *cmd, const char *arg1) { @@ -1558,28 +1567,30 @@ struct context **conf_cmdparse(struct context **cnt, const char *cmd, const char if (!cmd) return cnt; - /* We search through config_params until we find a param_name that matches - * our option given by cmd (or reach the end = NULL) + /* + * We search through config_params until we find a param_name that matches + * our option given by cmd (or reach the end = NULL). */ while (config_params[i].param_name != NULL) { if (!strncasecmp(cmd, config_params[i].param_name , 255 + 50)) { // Why +50? - /* if config_param is string we don't want to check arg1 */ + /* If config_param is string we don't want to check arg1. */ if (strcmp(config_type(&config_params[i]), "string")) { if (config_params[i].conf_value && !arg1) return cnt; } - /* We call the function given by the pointer config_params[i].copy + /* + * We call the function given by the pointer config_params[i].copy * If the option is a bool, copy_bool is called. * If the option is an int, copy_int is called. * If the option is a string, copy_string is called. * If the option is a thread, config_thread is called. * The arguments to the function are: - * cnt - a pointer to the context structure - * arg1 - a pointer to the new option value (represented as string) + * cnt - a pointer to the context structure. + * arg1 - a pointer to the new option value (represented as string). * config_params[i].conf_value - an integer value which is a pointer - * to the context structure member relative to the pointer cnt. + * to the context structure member relative to the pointer cnt. */ cnt = config_params[i].copy(cnt, arg1, config_params[i].conf_value); return cnt; @@ -1587,26 +1598,30 @@ struct context **conf_cmdparse(struct context **cnt, const char *cmd, const char i++; } - /* We reached the end of config_params without finding a matching option */ - motion_log(ERR, TYPE_ALL, NO_ERRNO, "%s: Unknown config option \"%s\"", - __FUNCTION__, cmd); + /* We reached the end of config_params without finding a matching option. */ + MOTION_LOG(ALR, TYPE_ALL, NO_ERRNO, "%s: Unknown config option \"%s\"", + cmd); return cnt; } -/* conf_process walks through an already open config file line by line - * Any line starting with '#' or ';' or empty lines are ignored as a comments. - * Any non empty line is process so that the first word is the name of an option 'cnd' - * and the rest of the line is the argument 'arg1' - * White space before the first word, between option and argument and end of the line - * is discarded. A '=' between option and first word in argument is also discarded. - * Quotation marks round the argument are also discarded. - * For each option/argument pair the function conf_cmdparse is called which takes - * care of assigning the value to the option in the config structures. +/** + * conf_process + * Walks through an already open config file line by line + * Any line starting with '#' or ';' or empty lines are ignored as a comments. + * Any non empty line is process so that the first word is the name of an option 'cnd' + * and the rest of the line is the argument 'arg1' + * White space before the first word, between option and argument and end of the line + * is discarded. A '=' between option and first word in argument is also discarded. + * Quotation marks round the argument are also discarded. + * For each option/argument pair the function conf_cmdparse is called which takes + * care of assigning the value to the option in the config structures. + * + * Returns context struct. */ static struct context **conf_process(struct context **cnt, FILE *fp) { - /* process each line from the config file */ + /* Process each line from the config file. */ char line[PATH_MAX], *cmd = NULL, *arg1 = NULL; char *beg = NULL, *end = NULL; @@ -1616,31 +1631,31 @@ static struct context **conf_process(struct context **cnt, FILE *fp) 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 */ + /* 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 == ' ' || *end == '\t' || *end == '\n' || *end == '\r') end--; *(end+1) = '\0'; - /* If line is only whitespace we continue to the next line */ + /* If line is only whitespace we continue to the next line. */ if (strlen(line) == 0) continue; - /* trim leading whitespace from the line and find command */ + /* Trim leading whitespace from the line and find command. */ beg = line; while (*beg == ' ' || *beg == '\t') beg++; - cmd = beg; /* command starts here */ + cmd = beg; /* Command starts here. */ while (*beg != ' ' && *beg != '\t' && *beg != '=' && *beg != '\0') beg++; - *beg = '\0'; /* command string terminates here */ + *beg = '\0'; /* Command string terminates here. */ - /* trim space between command and argument */ + /* Trim space between command and argument. */ beg++; if (strlen(beg) > 0) { @@ -1648,9 +1663,11 @@ static struct context **conf_process(struct context **cnt, FILE *fp) beg++; - /* If argument is in "" we will strip them off - It is important that we can use "" so that we can use - leading spaces in text_left and text_right */ + /* + * If argument is in "" we will strip them off + * It is important that we can use "" so that we can use + * leading spaces in text_left and text_right. + */ if ((beg[0] == '"' && beg[strlen(beg)-1] == '"') || (beg[0] == '\'' && beg[strlen(beg)-1] == '\'')) { beg[strlen(beg)-1] = '\0'; @@ -1659,7 +1676,7 @@ static struct context **conf_process(struct context **cnt, FILE *fp) arg1 = beg; /* Argument starts here */ } - /* else arg1 stays null pointer */ + /* Else arg1 stays null pointer */ cnt = conf_cmdparse(cnt, cmd, arg1); } @@ -1669,8 +1686,12 @@ static struct context **conf_process(struct context **cnt, FILE *fp) } -/* conf_print is used to write out the config file(s) motion.conf and any thread - * config files. The function is called when using http remote control. +/** + * conf_print + * Is used to write out the config file(s) motion.conf and any thread + * config files. The function is called when using http remote control. + * + * Returns nothing. */ void conf_print(struct context **cnt) { @@ -1680,8 +1701,8 @@ void conf_print(struct context **cnt) FILE *conffile; for (thread = 0; cnt[thread]; thread++) { - motion_log(ERR, TYPE_ALL, NO_ERRNO, "%s: Writing config file to %s", - __FUNCTION__, cnt[thread]->conf_filename); + MOTION_LOG(ERR, TYPE_ALL, NO_ERRNO, "%s: Writing config file to %s", + cnt[thread]->conf_filename); conffile = myfopen(cnt[thread]->conf_filename, "w", 0); @@ -1694,11 +1715,13 @@ void conf_print(struct context **cnt) for (i = 0; config_params[i].param_name; i++) { retval = config_params[i].print(cnt, NULL, i, thread); - /*If config parameter has a value (not NULL) print it to the config file*/ + /* If config parameter has a value (not NULL) print it to the config file. */ if (retval) { fprintf(conffile, "%s\n", config_params[i].param_help); - /* If the option is a text_* and first char is a space put - quotation marks around to allow leading spaces */ + /* + * 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)) fprintf(conffile, "%s %s\n\n", config_params[i].param_name, retval); else @@ -1706,10 +1729,12 @@ void conf_print(struct context **cnt) } else { val = NULL; config_params[i].print(cnt, &val, i, thread); - /* It can either be a thread file parameter or a disabled parameter - If it is a thread parameter write it out - Else write the disabled option to the config file but with a - comment mark in front of the parameter name */ + /* + * It can either be a thread file parameter or a disabled parameter. + * If it is a thread parameter write it out. + * Else write the disabled option to the config file but with a + * comment mark in front of the parameter name. + */ if (val) { fprintf(conffile, "%s\n", config_params[i].param_help); fprintf(conffile, "%s\n", val); @@ -1731,8 +1756,9 @@ void conf_print(struct context **cnt) } } -/************************************************************************** - * conf_load is the main function, called from motion.c +/** + * conf_load + * Is the main function, called from motion.c * The function sets the important context structure "cnt" including * loading the config parameters from config files and Command-line. * The following takes place in the function: @@ -1748,28 +1774,32 @@ void conf_print(struct context **cnt) * - Finally it process the options given in the Command-line. This is done * for each thread cnt[i] so that the Command-line options overrides any * option given by motion.conf or a thread config file. - **************************************************************************/ + * + * Returns context struct. + */ struct context **conf_load(struct context **cnt) { FILE *fp = NULL; char filename[PATH_MAX]; int i; - /* We preserve argc and argv because they get overwritten by the memcpy command */ + /* We preserve argc and argv because they get overwritten by the memcpy command. */ char **argv = cnt[0]->conf.argv; int argc = cnt[0]->conf.argc; - /* Copy the template config structure with all the default config values + /* + * Copy the template config structure with all the default config values * into cnt[0]->conf */ memcpy(&cnt[0]->conf, &conf_template, sizeof(struct config)); - /* For each member of cnt[0] which is a pointer to a string - * if the member points to a string in conf_template and is not NULL - * 1. Reserve (malloc) memory for the string - * 2. Copy the conf_template given string to the reserved memory - * 3. Change the cnt[0] member (char*) pointing to the string in reserved memory + /* + * For each member of cnt[0] which is a pointer to a string + * if the member points to a string in conf_template and is not NULL. + * 1. Reserve (malloc) memory for the string. + * 2. Copy the conf_template given string to the reserved memory. + * 3. Change the cnt[0] member (char*) pointing to the string in reserved memory. * This ensures that we can free and malloc the string when changed - * via http remote control or config file or Command-line options + * via http remote control or config file or Command-line options. */ malloc_strings(cnt[0]); @@ -1777,13 +1807,14 @@ struct context **conf_load(struct context **cnt) cnt[0]->conf.argv = argv; cnt[0]->conf.argc = argc; - /* Open the motion.conf file. We try in this sequence: + /* + * Open the motion.conf file. We try in this sequence: * 1. Command-line * 2. current working directory * 3. $HOME/.motion/motion.conf * 4. sysconfig/motion.conf */ - /* Get filename , pid file & log file from Command-line */ + /* Get filename , pid file & log file from Command-line. */ cnt[0]->log_type_str[0] = 0; cnt[0]->conf_filename[0] = 0; cnt[0]->pid_file[0] = 0; @@ -1791,20 +1822,20 @@ 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*/ + if (cnt[0]->conf_filename[0]) { /* User has supplied filename on Command-line. */ strcpy(filename, cnt[0]->conf_filename); fp = fopen (filename, "r"); } - if (!fp) { /* Command-line didn't work, try current dir */ + if (!fp) { /* Command-line didn't work, try current dir. */ char *path = NULL; if (cnt[0]->conf_filename[0]) - motion_log(EMG, TYPE_ALL, SHOW_ERRNO, "%s: Configfile %s not found - trying defaults.", - __FUNCTION__, filename); + MOTION_LOG(EMG, TYPE_ALL, SHOW_ERRNO, "%s: Configfile %s not found - trying defaults.", + filename); if ((path = get_current_dir_name()) == NULL) { - motion_log(ERR, TYPE_ALL, SHOW_ERRNO, "%s: Error get_current_dir_name", __FUNCTION__); + MOTION_LOG(ERR, TYPE_ALL, SHOW_ERRNO, "%s: Error get_current_dir_name"); exit(-1); } @@ -1813,7 +1844,7 @@ struct context **conf_load(struct context **cnt) free(path); } - if (!fp) { /* specified file does not exist... try default file */ + if (!fp) { /* Specified file does not exist... try default file. */ snprintf(filename, PATH_MAX, "%s/.motion/motion.conf", getenv("HOME")); fp = fopen(filename, "r"); @@ -1821,22 +1852,21 @@ 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 */ - motion_log(EMG, TYPE_ALL, SHOW_ERRNO, "%s: could not open configfile %s", - __FUNCTION__, filename); + if (!fp) /* There is no config file.... use defaults. */ + MOTION_LOG(EMG, TYPE_ALL, SHOW_ERRNO, "%s: could not open configfile %s", + filename); } } - /* Now we process the motion.conf config file and close it */ + /* Now we process the motion.conf config file and close it. */ if (fp) { strcpy(cnt[0]->conf_filename, filename); - motion_log(ERR, TYPE_ALL, NO_ERRNO, "%s: Processing thread 0 - config file %s", - __FUNCTION__, filename); + MOTION_LOG(ALR, TYPE_ALL, NO_ERRNO, "%s: Processing thread 0 - config file %s", + filename); cnt = conf_process(cnt, fp); myfclose(fp); } else { - motion_log(ERR, TYPE_ALL, NO_ERRNO, "%s: Not config file to process using default values", - __FUNCTION__); + MOTION_LOG(EMG, TYPE_ALL, NO_ERRNO, "%s: Not config file to process using default values"); } @@ -1847,14 +1877,14 @@ struct context **conf_load(struct context **cnt) * cnt[1], cnt[2], ... are context structures for each thread * Command line options always wins over config file options * so we go through each thread and overrides any set Command-line - * options + * options. */ i = -1; while (cnt[++i]) conf_cmdline(cnt[i], i); - /* if pid file was passed from Command-line copy to main thread conf struct */ + /* if pid file was passed from Command-line copy to main thread conf struct. */ if (cnt[0]->pid_file[0]) cnt[0]->conf.pid_file = mystrcpy(cnt[0]->conf.pid_file, cnt[0]->pid_file); @@ -1877,6 +1907,8 @@ struct context **conf_load(struct context **cnt) * 2. Copy the original string to the reserved memory * 3. Change the cnt member (char*) pointing to the string in reserved memory * This ensures that we can free and malloc the string if it is later changed + * + * Returns nothing. */ void malloc_strings(struct context *cnt) { @@ -1884,7 +1916,7 @@ void malloc_strings(struct context *cnt) char **val; while (config_params[i].param_name != NULL) { if (config_params[i].copy == copy_string) { /* if member is a string */ - /* val is made to point to a pointer to the current string */ + /* val is made to point to a pointer to the current string. */ val = (char **)((char *)cnt+config_params[i].conf_value); /* @@ -1928,6 +1960,8 @@ void malloc_strings(struct context *cnt) * The boolean is given as a string in str which is converted to 0 or 1 * by the function. Values 1, yes and on are converted to 1 ignoring case. * Any other value is converted to 0. + * + * Returns context struct. */ static struct context **copy_bool(struct context **cnt, const char *str, int val_ptr) { @@ -1956,6 +1990,8 @@ static struct context **copy_bool(struct context **cnt, const char *str, int val * Assigns a config option to a new integer value. * The integer is given as a string in str which is converted to integer * by the function. + * + * Returns context struct. */ static struct context **copy_int(struct context **cnt, const char *str, int val_ptr) { @@ -1981,7 +2017,9 @@ static struct context **copy_int(struct context **cnt, const char *str, int val_ * the char *conf->option that we are working on is free()'d * (if memory for it has already been malloc()'d), and set to * a freshly malloc()'d string with the value from str, - * or NULL if str is blank + * or NULL if str is blank. + * + * Returns context struct. */ struct context **copy_string(struct context **cnt, const char *str, int val_ptr) { @@ -2001,7 +2039,7 @@ 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 + * for thread 0; otherwise just set that one thread's option. */ if (cnt[0]->threadnr) return cnt; @@ -2031,7 +2069,8 @@ struct context **copy_string(struct context **cnt, const char *str, int val_ptr) */ char *mystrcpy(char *to, const char *from) { - /* free the memory used by the to string, if such memory exists, + /* + * Free the memory used by the to string, if such memory exists, * and return a pointer to a freshly malloc()'d string with the * same value as from. */ @@ -2069,7 +2108,7 @@ char *mystrdup(const char *from) /* * We must ensure the string always has a NULL terminator. * This necessary because strncpy will not append a NULL terminator - * if the original string is greater than stringlength. + * if the original string is greater than string length. */ tmp += stringlength; *tmp = '\0'; @@ -2079,6 +2118,12 @@ char *mystrdup(const char *from) return tmp; } +/** + * config_type + * Returns a pointer to string containing value the type of config parameter passed. + * + * Returns const char *. + */ const char *config_type(config_param *configparam) { if (configparam->copy == copy_string) @@ -2091,6 +2136,13 @@ const char *config_type(config_param *configparam) return "unknown"; } + +/** + * print_bool + * Returns a pointer to string containing boolean value 'on' / 'off' or NULL. + * + * Returns const char *. + */ static const char *print_bool(struct context **cnt, char **str ATTRIBUTE_UNUSED, int parm, unsigned int threadnr) { @@ -2108,7 +2160,7 @@ static const char *print_bool(struct context **cnt, char **str ATTRIBUTE_UNUSED, /** * print_string - * returns a pointer to a string containing the value of the config option, + * Returns a pointer to a string containing the value of the config option, * If the thread number is not 0 the string is compared with the value of the same * option in thread 0. * @@ -2123,7 +2175,7 @@ static const char *print_string(struct context **cnt, int val = config_params[parm].conf_value; const char **cptr0, **cptr1; - /* strcmp does not like NULL so we have to check for this also */ + /* strcmp does not like NULL so we have to check for this also. */ cptr0 = (const char **)((char *)cnt[0] + val); cptr1 = (const char **)((char *)cnt[threadnr] + val); @@ -2162,7 +2214,8 @@ static const char *print_thread(struct context **cnt, char **str, retval[0] = 0; while (cnt[++i]) { - retval = myrealloc(retval, strlen(retval) + strlen(cnt[i]->conf_filename)+10, "print_thread"); + retval = myrealloc(retval, strlen(retval) + strlen(cnt[i]->conf_filename) + 10, + "print_thread"); sprintf(retval + strlen(retval), "thread %s\n", cnt[i]->conf_filename); } @@ -2195,8 +2248,8 @@ static struct context **config_thread(struct context **cnt, const char *str, fp = fopen(str, "r"); if (!fp) { - motion_log(ERR, TYPE_ALL, SHOW_ERRNO, "%s: Thread config file %s not found", - __FUNCTION__, str); + MOTION_LOG(ALR, TYPE_ALL, SHOW_ERRNO, "%s: Thread config file %s not found", + str); return cnt; } @@ -2208,8 +2261,8 @@ static struct context **config_thread(struct context **cnt, const char *str, /* * Make space for the threads + the terminating NULL pointer * in the array of pointers to context structures - * First thread is 0 so the number of threads is i+1 - * plus an extra for the NULL pointer. This gives i+2 + * First thread is 0 so the number of threads is i + 1 + * plus an extra for the NULL pointer. This gives i + 2 */ cnt = myrealloc(cnt, sizeof(struct context *) * (i + 2), "config_thread"); @@ -2228,21 +2281,27 @@ static struct context **config_thread(struct context **cnt, const char *str, */ malloc_strings(cnt[i]); - /* Mark the end if the array of pointers to context structures */ + /* Mark the end if the array of pointers to context structures. */ cnt[i + 1] = NULL; - /* process the thread's config file and notify user on console */ + /* Process the thread's config file and notify user on console. */ strcpy(cnt[i]->conf_filename, str); - motion_log(ERR, TYPE_ALL, NO_ERRNO, "%s: Processing config file %s", - __FUNCTION__, str); - conf_process(cnt+i, fp); + MOTION_LOG(ALR, TYPE_ALL, NO_ERRNO, "%s: Processing config file %s", + str); + conf_process(cnt + i, fp); - /* Finally we close the thread config file */ + /* Finally we close the thread config file. */ myfclose(fp); return cnt; } +/** + * usage + * Prints usage and options allowed from Command-line. + * + * Returns nothing. + */ static void usage() { printf("motion Version "VERSION", Copyright 2000-2005 Jeroen Vreeken/Folkert van Heusden/Kenneth Lavrsen\n"); diff --git a/configure b/configure index 39c50e6..b48d305 100755 --- a/configure +++ b/configure @@ -1,6 +1,6 @@ #! /bin/sh # Guess values for system-dependent variables and create Makefiles. -# Generated by GNU Autoconf 2.64 for motion trunkREV501. +# Generated by GNU Autoconf 2.64 for motion trunkREV502. # # Copyright (C) 1992, 1993, 1994, 1995, 1996, 1998, 1999, 2000, 2001, # 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009 Free Software @@ -546,8 +546,8 @@ MAKEFLAGS= # Identity of this package. PACKAGE_NAME='motion' PACKAGE_TARNAME='motion' -PACKAGE_VERSION='trunkREV501' -PACKAGE_STRING='motion trunkREV501' +PACKAGE_VERSION='trunkREV502' +PACKAGE_STRING='motion trunkREV502' PACKAGE_BUGREPORT='' PACKAGE_URL='' @@ -1210,7 +1210,7 @@ if test "$ac_init_help" = "long"; then # Omit some internal or obsolete options to make the list less imposing. # This message is too long to be a string in the A/UX 3.1 sh. cat <<_ACEOF -\`configure' configures motion trunkREV501 to adapt to many kinds of systems. +\`configure' configures motion trunkREV502 to adapt to many kinds of systems. Usage: $0 [OPTION]... [VAR=VALUE]... @@ -1271,7 +1271,7 @@ fi if test -n "$ac_init_help"; then case $ac_init_help in - short | recursive ) echo "Configuration of motion trunkREV501:";; + short | recursive ) echo "Configuration of motion trunkREV502:";; esac cat <<\_ACEOF @@ -1412,7 +1412,7 @@ fi test -n "$ac_init_help" && exit $ac_status if $ac_init_version; then cat <<\_ACEOF -motion configure trunkREV501 +motion configure trunkREV502 generated by GNU Autoconf 2.64 Copyright (C) 2009 Free Software Foundation, Inc. @@ -2009,7 +2009,7 @@ cat >config.log <<_ACEOF This file contains any messages produced by compilers while running configure, to aid debugging if configure makes a mistake. -It was created by motion $as_me trunkREV501, which was +It was created by motion $as_me trunkREV502, which was generated by GNU Autoconf 2.64. Invocation command line was $ $0 $@ @@ -5254,7 +5254,7 @@ rm -f core conftest.err conftest.$ac_objext \ if test "${DEVELOPER_FLAGS}" = "yes"; then - TEMP_CFLAGS="${TEMP_CFLAGS} -W -Wshadow -Wpointer-arith -Wcast-align -Wwrite-strings -Waggregate-return -Wstrict-prototypes -Wmissing-prototypes -Wnested-externs -Winline -Wredundant-decls -Wno-long-long -ggdb -g3 " + TEMP_CFLAGS="${TEMP_CFLAGS} -W -Wshadow -Wpointer-arith -Wcast-align -Wwrite-strings -Waggregate-return -Wstrict-prototypes -Wmissing-prototypes -Wnested-externs -Winline -Wredundant-decls -Wno-long-long -ggdb -g3" fi CFLAGS="${TEMP_CFLAGS} $UNAME_DEFS $CPU_OPTIONS" @@ -5790,7 +5790,7 @@ cat >>$CONFIG_STATUS <<\_ACEOF || ac_write_fail=1 # report actual input values of CONFIG_FILES etc. instead of their # values after options handling. ac_log=" -This file was extended by motion $as_me trunkREV501, which was +This file was extended by motion $as_me trunkREV502, which was generated by GNU Autoconf 2.64. Invocation command line was CONFIG_FILES = $CONFIG_FILES @@ -5850,7 +5850,7 @@ Report bugs to the package provider." _ACEOF cat >>$CONFIG_STATUS <<_ACEOF || ac_write_fail=1 ac_cs_version="\\ -motion config.status trunkREV501 +motion config.status trunkREV502 configured by $0, generated by GNU Autoconf 2.64, with options \\"`$as_echo "$ac_configure_args" | sed 's/^ //; s/[\\""\`\$]/\\\\&/g'`\\" @@ -6554,91 +6554,87 @@ echo if test "${Darwin}" != ""; then - echo "OS : Darwin" + echo "OS : Darwin" elif test "${FreeBSD}" != ""; then - echo "OS : *BSD" + echo "OS : *BSD" else - echo "OS : Linux" + echo "OS : Linux" fi if test "${PTHREAD_SUPPORT}" = "yes"; then - echo "pthread support: Yes" + echo "pthread support: Yes" else - echo "pthread support: No" - echo "**********************************************" - echo "** Fatal Error YOU MUST HAVE pthread Support *" - echo "**********************************************" + echo "pthread support: No" + echo "**********************************************" + echo "** Fatal Error YOU MUST HAVE pthread Support *" + echo "**********************************************" fi if test "${JPEG_SUPPORT_MMX}" = "yes"; then - echo "jpeg-mmx support: Yes" + echo "jpeg-mmx support: Yes" elif test "${JPEG_SUPPORT}" = "yes"; then - echo "jpeg support: Yes" + echo "jpeg support: Yes" else - echo "jpeg support: No" - echo "**********************************************" - echo "** Fatal Error YOU MUST HAVE jpeg Support ***" - echo "**********************************************" + echo "jpeg support: No" + echo "**********************************************" + echo "** Fatal Error YOU MUST HAVE jpeg Support ***" + echo "**********************************************" fi if test "${FreeBSD}" != ""; then if test "${BKTR}" = "yes"; then - echo "BKTR included: Yes" + echo "BKTR included: Yes" else - echo "BKTR included: No" + echo "BKTR included: No" fi if test "${PWCBSD}" = "yes"; then - echo "PWCBSD include: Yes" + echo "PWCBSD include: Yes" else - echo "PWCBSD include: No" + echo "PWCBSD include: No" fi else if test "${V4L}" = "yes"; then - echo "V4L support: Yes" + echo "V4L support: Yes" else - echo "V4L support: No" + echo "V4L support: No" fi if test x$SUPPORTED_V4L2 = xtrue; then - echo "V4L2 support: Yes" + echo "V4L2 support: Yes" else - echo "V4L2 support: No" + echo "V4L2 support: No" fi fi if test "${FFMPEG_OK}" = "found"; then - echo "FFmpeg support: Yes" + echo "FFmpeg support: Yes" else - echo "FFmpeg support: No" + echo "FFmpeg support: No" fi if test "${SQLITE3_SUPPORT}" = "yes"; then - echo "SQLite3 support: Yes" + echo "SQLite3 support: Yes" else - echo "SQLite3 support: No" + echo "SQLite3 support: No" fi if test "${MYSQL_SUPPORT}" = "yes"; then - echo "MYSQL support: Yes" + echo "MYSQL support: Yes" else - echo "MYSQL support: No" + echo "MYSQL support: No" fi if test "${PGSQL_SUPPORT}" = "yes"; then - echo "PostgreSQL support: Yes" + echo "PostgreSQL support: Yes" else - echo "PostgreSQL support: No" + echo "PostgreSQL support: No" fi echo - - echo "CFLAGS: $CFLAGS" echo "LIBS: $LIBS" echo "LDFLAGS: $LDFLAGS" - - echo echo "Install prefix: $prefix" echo diff --git a/configure.in b/configure.in index 54b7275..b7c96df 100644 --- a/configure.in +++ b/configure.in @@ -1090,7 +1090,7 @@ AC_LINK_IFELSE([ if test "${DEVELOPER_FLAGS}" = "yes"; then - TEMP_CFLAGS="${TEMP_CFLAGS} -W -Wshadow -Wpointer-arith -Wcast-align -Wwrite-strings -Waggregate-return -Wstrict-prototypes -Wmissing-prototypes -Wnested-externs -Winline -Wredundant-decls -Wno-long-long -ggdb -g3 " + TEMP_CFLAGS="${TEMP_CFLAGS} -W -Wshadow -Wpointer-arith -Wcast-align -Wwrite-strings -Waggregate-return -Wstrict-prototypes -Wmissing-prototypes -Wnested-externs -Winline -Wredundant-decls -Wno-long-long -ggdb -g3" fi CFLAGS="${TEMP_CFLAGS} $UNAME_DEFS $CPU_OPTIONS" @@ -1142,91 +1142,87 @@ echo if test "${Darwin}" != ""; then - echo "OS : Darwin" + echo "OS : Darwin" elif test "${FreeBSD}" != ""; then - echo "OS : *BSD" + echo "OS : *BSD" else - echo "OS : Linux" + echo "OS : Linux" fi if test "${PTHREAD_SUPPORT}" = "yes"; then - echo "pthread support: Yes" + echo "pthread support: Yes" else - echo "pthread support: No" - echo "**********************************************" - echo "** Fatal Error YOU MUST HAVE pthread Support *" - echo "**********************************************" + echo "pthread support: No" + echo "**********************************************" + echo "** Fatal Error YOU MUST HAVE pthread Support *" + echo "**********************************************" fi if test "${JPEG_SUPPORT_MMX}" = "yes"; then - echo "jpeg-mmx support: Yes" + echo "jpeg-mmx support: Yes" elif test "${JPEG_SUPPORT}" = "yes"; then - echo "jpeg support: Yes" + echo "jpeg support: Yes" else - echo "jpeg support: No" - echo "**********************************************" - echo "** Fatal Error YOU MUST HAVE jpeg Support ***" - echo "**********************************************" + echo "jpeg support: No" + echo "**********************************************" + echo "** Fatal Error YOU MUST HAVE jpeg Support ***" + echo "**********************************************" fi if test "${FreeBSD}" != ""; then if test "${BKTR}" = "yes"; then - echo "BKTR included: Yes" + echo "BKTR included: Yes" else - echo "BKTR included: No" + echo "BKTR included: No" fi if test "${PWCBSD}" = "yes"; then - echo "PWCBSD include: Yes" + echo "PWCBSD include: Yes" else - echo "PWCBSD include: No" + echo "PWCBSD include: No" fi else if test "${V4L}" = "yes"; then - echo "V4L support: Yes" + echo "V4L support: Yes" else - echo "V4L support: No" + echo "V4L support: No" fi if test x$SUPPORTED_V4L2 = xtrue; then - echo "V4L2 support: Yes" + echo "V4L2 support: Yes" else - echo "V4L2 support: No" + echo "V4L2 support: No" fi fi if test "${FFMPEG_OK}" = "found"; then - echo "FFmpeg support: Yes" + echo "FFmpeg support: Yes" else - echo "FFmpeg support: No" + echo "FFmpeg support: No" fi if test "${SQLITE3_SUPPORT}" = "yes"; then - echo "SQLite3 support: Yes" + echo "SQLite3 support: Yes" else - echo "SQLite3 support: No" + echo "SQLite3 support: No" fi if test "${MYSQL_SUPPORT}" = "yes"; then - echo "MYSQL support: Yes" + echo "MYSQL support: Yes" else - echo "MYSQL support: No" + echo "MYSQL support: No" fi if test "${PGSQL_SUPPORT}" = "yes"; then - echo "PostgreSQL support: Yes" + echo "PostgreSQL support: Yes" else - echo "PostgreSQL support: No" + echo "PostgreSQL support: No" fi echo - - echo "CFLAGS: $CFLAGS" echo "LIBS: $LIBS" echo "LDFLAGS: $LDFLAGS" - - echo echo "Install prefix: $prefix" echo diff --git a/draw.c b/draw.c index 23c19bb..1be96ba 100644 --- a/draw.c +++ b/draw.c @@ -12,7 +12,7 @@ #include #include "motion.h" -/* highest ascii value is 126 (~) */ +/* Highest ascii value is 126 (~) */ #define ASCII_MAX 127 unsigned char *small_char_arr_ptr[ASCII_MAX]; @@ -1132,7 +1132,7 @@ int draw_text(unsigned char *image, unsigned int startx, unsigned int starty, un const char *end, *begin; const int line_space = (factor + 1) * 9; - /* Count the number of newlines in "text" so we scroll it up the image */ + /* Count the number of newlines in "text" so we scroll it up the image. */ end = text; while ((end = strstr(end, NEWLINE))) { @@ -1179,13 +1179,13 @@ int initialize_chars(void) } } - /* first init all char ptr's to a space character */ + /* First init all char ptr's to a space character. */ for (i = 0; i < ASCII_MAX; i++) { small_char_arr_ptr[i] = &draw_table[0].pix[0][0]; big_char_arr_ptr[i] = &big_table[0].pix[0][0]; } - /* build [big_]char_arr_ptr table to point to each available ascii */ + /* Build [big_]char_arr_ptr table to point to each available ascii. */ for (i = 0; i < draw_table_size; i++) { small_char_arr_ptr[(int)draw_table[i].ascii] = &draw_table[i].pix[0][0]; big_char_arr_ptr[(int)draw_table[i].ascii] = &big_table[i].pix[0][0]; diff --git a/event.c b/event.c index b0f3f12..d979f03 100644 --- a/event.c +++ b/event.c @@ -46,14 +46,14 @@ static void exec_command(struct context *cnt, char *command, char *filename, int execl("/bin/sh", "sh", "-c", stamp, " &", NULL); /* if above function succeeds the program never reach here */ - motion_log(ALR, TYPE_EVENTS, SHOW_ERRNO, "%s: Unable to start external command '%s'", - __FUNCTION__, stamp); + MOTION_LOG(ALR, TYPE_EVENTS, SHOW_ERRNO, "%s: Unable to start external command '%s'", + stamp); exit(1); } - motion_log(DBG, TYPE_EVENTS, NO_ERRNO, "%s: Executing external command '%s'", - __FUNCTION__, stamp); + MOTION_LOG(DBG, TYPE_EVENTS, NO_ERRNO, "%s: Executing external command '%s'", + stamp); } /* @@ -64,8 +64,8 @@ static void event_newfile(struct context *cnt ATTRIBUTE_UNUSED, int type ATTRIBUTE_UNUSED, unsigned char *dummy ATTRIBUTE_UNUSED, char *filename, void *ftype, struct tm *tm ATTRIBUTE_UNUSED) { - motion_log(EMG, TYPE_EVENTS, NO_ERRNO, "%s: File of type %ld saved to: %s", - __FUNCTION__, (unsigned long)ftype, filename); + MOTION_LOG(EMG, TYPE_EVENTS, NO_ERRNO, "%s: File of type %ld saved to: %s", + (unsigned long)ftype, filename); } @@ -136,8 +136,8 @@ static void event_sqlnewfile(struct context *cnt, int type ATTRIBUTE_UNUSED, if (mysql_query(cnt->database, sqlquery) != 0) { int error_code = mysql_errno(cnt->database); - motion_log(ERR, TYPE_DB, SHOW_ERRNO, "%s: Mysql query failed %s error code %d", - __FUNCTION__, mysql_error(cnt->database), error_code); + MOTION_LOG(ERR, TYPE_DB, SHOW_ERRNO, "%s: Mysql query failed %s error code %d", + mysql_error(cnt->database), error_code); /* Try to reconnect ONCE if fails continue and discard this sql query */ if (error_code >= 2000) { cnt->database = (MYSQL *) mymalloc(sizeof(MYSQL)); @@ -146,9 +146,9 @@ static void event_sqlnewfile(struct context *cnt, int type ATTRIBUTE_UNUSED, if (!mysql_real_connect(cnt->database, cnt->conf.database_host, cnt->conf.database_user, cnt->conf.database_password, cnt->conf.database_dbname, 0, NULL, 0)) { - motion_log(ALR, TYPE_DB, NO_ERRNO, "%s: Cannot reconnect to MySQL" + MOTION_LOG(ALR, TYPE_DB, NO_ERRNO, "%s: Cannot reconnect to MySQL" " database %s on host %s with user %s MySQL error was %s", - __FUNCTION__, cnt->conf.database_dbname, + cnt->conf.database_dbname, cnt->conf.database_host, cnt->conf.database_user, mysql_error(cnt->database)); } else { @@ -166,8 +166,7 @@ static void event_sqlnewfile(struct context *cnt, int type ATTRIBUTE_UNUSED, res = PQexec(cnt->database_pg, sqlquery); if (PQresultStatus(res) != PGRES_COMMAND_OK) { - motion_log(ERR, TYPE_DB, SHOW_ERRNO, "%s: PGSQL query failed", - __FUNCTION__); + MOTION_LOG(ERR, TYPE_DB, SHOW_ERRNO, "%s: PGSQL query failed"); PQclear(res); } } @@ -179,8 +178,8 @@ static void event_sqlnewfile(struct context *cnt, int type ATTRIBUTE_UNUSED, char *errmsg = 0; res = sqlite3_exec(cnt->database_sqlite3, sqlquery, NULL, 0, &errmsg); if (res != SQLITE_OK ) { - motion_log(ERR, TYPE_DB, NO_ERRNO, "%s: SQLite error was %s", - __FUNCTION__, errmsg); + MOTION_LOG(ERR, TYPE_DB, NO_ERRNO, "%s: SQLite error was %s", + errmsg); sqlite3_free(errmsg); } } @@ -241,8 +240,7 @@ static void event_vid_putpipe(struct context *cnt, int type ATTRIBUTE_UNUSED, { if (*(int *)devpipe >= 0) { if (vid_putpipe(*(int *)devpipe, img, cnt->imgs.size) == -1) - motion_log(ERR, TYPE_EVENTS, SHOW_ERRNO, "%s: Failed to put image into video pipe", - __FUNCTION__); + MOTION_LOG(ERR, TYPE_EVENTS, SHOW_ERRNO, "%s: Failed to put image into video pipe"); } } #endif /* !WITHOUT_V4L && !BSD */ @@ -344,8 +342,8 @@ static void event_image_snapshot(struct context *cnt, int type ATTRIBUTE_UNUSED, remove(linkpath); if (symlink(filename, linkpath)) { - motion_log(ERR, TYPE_EVENTS, SHOW_ERRNO, "%s: Could not create symbolic link [%s]", - __FUNCTION__, filename); + MOTION_LOG(ERR, TYPE_EVENTS, SHOW_ERRNO, "%s: Could not create symbolic link [%s]", + filename); return; } } else { @@ -382,10 +380,10 @@ static void event_extpipe_end(struct context *cnt, int type ATTRIBUTE_UNUSED, if (cnt->extpipe_open) { cnt->extpipe_open = 0; fflush(cnt->extpipe); - motion_log(ERR, TYPE_EVENTS, NO_ERRNO, "%s: CLOSING: extpipe file desc %d, error state %d", - __FUNCTION__, fileno(cnt->extpipe), ferror(cnt->extpipe)); - motion_log(ERR, TYPE_EVENTS, NO_ERRNO, "%s: pclose return: %d", - __FUNCTION__, pclose(cnt->extpipe)); + MOTION_LOG(ERR, TYPE_EVENTS, NO_ERRNO, "%s: CLOSING: extpipe file desc %d, error state %d", + fileno(cnt->extpipe), ferror(cnt->extpipe)); + MOTION_LOG(ERR, TYPE_EVENTS, NO_ERRNO, "%s: pclose return: %d", + pclose(cnt->extpipe)); event(cnt, EVENT_FILECLOSE, NULL, cnt->extpipefilename, (void *)FTYPE_MPEG, NULL); } } @@ -407,8 +405,8 @@ static void event_create_extpipe(struct context *cnt, int type ATTRIBUTE_UNUSED, moviepath = cnt->conf.moviepath; } else { moviepath = DEF_MOVIEPATH; - motion_log(NTC, TYPE_EVENTS, NO_ERRNO, "%s: moviepath: %s", - __FUNCTION__, moviepath); + MOTION_LOG(NTC, TYPE_EVENTS, NO_ERRNO, "%s: moviepath: %s", + moviepath); } mystrftime(cnt, stamp, sizeof(stamp), moviepath, currenttime_tm, NULL, 0); @@ -421,13 +419,13 @@ static void event_create_extpipe(struct context *cnt, int type ATTRIBUTE_UNUSED, if (fd_dummy == NULL) { /* Permission denied */ if (errno == EACCES) { - motion_log(ERR, TYPE_EVENTS, SHOW_ERRNO, "%s: error opening file %s ..." + MOTION_LOG(ERR, TYPE_EVENTS, SHOW_ERRNO, "%s: error opening file %s ..." "check access rights to target directory", - __FUNCTION__, cnt->extpipefilename); + cnt->extpipefilename); return ; } else { - motion_log(ERR, TYPE_EVENTS, SHOW_ERRNO, "%s: error opening file %s", - __FUNCTION__, cnt->extpipefilename); + MOTION_LOG(ERR, TYPE_EVENTS, SHOW_ERRNO, "%s: error opening file %s", + cnt->extpipefilename); return ; } @@ -438,16 +436,16 @@ static void event_create_extpipe(struct context *cnt, int type ATTRIBUTE_UNUSED, mystrftime(cnt, stamp, sizeof(stamp), cnt->conf.extpipe, currenttime_tm, cnt->extpipefilename, 0); - motion_log(NTC, TYPE_EVENTS, NO_ERRNO, "%s: pipe: %s", - __FUNCTION__, stamp); - motion_log(NTC, TYPE_EVENTS, NO_ERRNO, "%s: cnt->moviefps: %d", - __FUNCTION__, cnt->movie_fps); + MOTION_LOG(NTC, TYPE_EVENTS, NO_ERRNO, "%s: pipe: %s", + stamp); + MOTION_LOG(NTC, TYPE_EVENTS, NO_ERRNO, "%s: cnt->moviefps: %d", + cnt->movie_fps); event(cnt, EVENT_FILECREATE, NULL, cnt->extpipefilename, (void *)FTYPE_MPEG, NULL); cnt->extpipe = popen(stamp, "w"); if (cnt->extpipe == NULL) { - motion_log(ERR, TYPE_EVENTS, SHOW_ERRNO, "%s: popen failed", __FUNCTION__); + MOTION_LOG(ERR, TYPE_EVENTS, SHOW_ERRNO, "%s: popen failed"); return; } @@ -462,16 +460,16 @@ static void event_extpipe_put(struct context *cnt, int type ATTRIBUTE_UNUSED, { /* Check use_extpipe enabled and ext_pipe not NULL */ if ((cnt->conf.useextpipe) && (cnt->extpipe != NULL)) { - motion_log(DBG, TYPE_EVENTS, NO_ERRNO, "%s:", __FUNCTION__); + MOTION_LOG(DBG, TYPE_EVENTS, NO_ERRNO, "%s:"); /* Check that is open */ if ((cnt->extpipe_open) && (fileno(cnt->extpipe) > 0)) { if (!fwrite(img, cnt->imgs.size, 1, cnt->extpipe)) - motion_log(ERR, TYPE_EVENTS, SHOW_ERRNO, "%s: Error writting in pipe , state error %d", - __FUNCTION__, ferror(cnt->extpipe)); + MOTION_LOG(ERR, TYPE_EVENTS, SHOW_ERRNO, "%s: Error writting in pipe , state error %d", + ferror(cnt->extpipe)); } else { - motion_log(ERR, TYPE_EVENTS, NO_ERRNO, "%s: pipe %s not created or closed already ", - __FUNCTION__, cnt->extpipe); + MOTION_LOG(ERR, TYPE_EVENTS, NO_ERRNO, "%s: pipe %s not created or closed already ", + cnt->extpipe); } } } @@ -485,8 +483,8 @@ static void event_new_video(struct context *cnt, int type ATTRIBUTE_UNUSED, cnt->movie_fps = cnt->lastrate; - motion_log(NTC, TYPE_EVENTS, NO_ERRNO, "%s FPS %d", - __FUNCTION__, cnt->movie_fps); + MOTION_LOG(NTC, TYPE_EVENTS, NO_ERRNO, "%s FPS %d", + cnt->movie_fps); if (cnt->movie_fps > 30) cnt->movie_fps = 30; @@ -552,8 +550,8 @@ static void event_ffmpeg_newfile(struct context *cnt, int type ATTRIBUTE_UNUSED, ffmpeg_open((char *)cnt->conf.ffmpeg_video_codec, cnt->newfilename, y, u, v, cnt->imgs.width, cnt->imgs.height, cnt->movie_fps, cnt->conf.ffmpeg_bps, cnt->conf.ffmpeg_vbr)) == NULL) { - motion_log(ERR, TYPE_EVENTS, SHOW_ERRNO, "%s: ffopen_open error creating (new) file [%s]", - __FUNCTION__, cnt->newfilename); + MOTION_LOG(ERR, TYPE_EVENTS, SHOW_ERRNO, "%s: ffopen_open error creating (new) file [%s]", + cnt->newfilename); cnt->finish = 1; return; } @@ -580,8 +578,8 @@ static void event_ffmpeg_newfile(struct context *cnt, int type ATTRIBUTE_UNUSED, ffmpeg_open((char *)cnt->conf.ffmpeg_video_codec, cnt->motionfilename, y, u, v, cnt->imgs.width, cnt->imgs.height, cnt->movie_fps, cnt->conf.ffmpeg_bps, cnt->conf.ffmpeg_vbr)) == NULL) { - motion_log(ERR, TYPE_EVENTS, SHOW_ERRNO, "%s: ffopen_open error creating (motion) file [%s]", - __FUNCTION__, cnt->motionfilename); + MOTION_LOG(ERR, TYPE_EVENTS, SHOW_ERRNO, "%s: ffopen_open error creating (motion) file [%s]", + cnt->motionfilename); cnt->finish = 1; return; } @@ -635,8 +633,8 @@ static void event_ffmpeg_timelapse(struct context *cnt, ffmpeg_open((char *)TIMELAPSE_CODEC, cnt->timelapsefilename, y, u, v, cnt->imgs.width, cnt->imgs.height, 24, cnt->conf.ffmpeg_bps, cnt->conf.ffmpeg_vbr)) == NULL) { - motion_log(ERR, TYPE_EVENTS, SHOW_ERRNO, "%s: ffopen_open error creating " - "(timelapse) file [%s]", __FUNCTION__, cnt->timelapsefilename); + MOTION_LOG(ERR, TYPE_EVENTS, SHOW_ERRNO, "%s: ffopen_open error creating " + "(timelapse) file [%s]", cnt->timelapsefilename); cnt->finish = 1; return; } diff --git a/ffmpeg.c b/ffmpeg.c index 8ddfab4..72d1f5b 100644 --- a/ffmpeg.c +++ b/ffmpeg.c @@ -1,4 +1,4 @@ -/********************************************************************** +/* * * ffmpeg.c * @@ -8,7 +8,7 @@ * The contents of this file has been derived from output_example.c * and apiexample.c from the FFmpeg distribution. * - **********************************************************************/ + */ #ifdef HAVE_FFMPEG @@ -42,7 +42,7 @@ /* * The API for av_write_frame changed with FFmpeg version 0.4.9pre1. * It now uses an AVPacket struct instead of direct parameters to the - * function. The + * function. */ # define FFMPEG_AVWRITEFRAME_NEWAPI #endif /* LIBAVFORMAT_BUILD >= 4616 */ @@ -79,7 +79,7 @@ static unsigned char mpeg1_trailer[] = {0x00, 0x00, 0x01, 0xb7}; * an ordinary file. The original file open function truncates an existing * file, but this version appends to it instead. * - * Returns + * Returns 0 on success and AVERROR(ENOENT) on error. * */ static int file_open_append(URLContext *h, const char *filename, int flags) @@ -227,7 +227,7 @@ URLProtocol file_protocol = { * We set AVOutputFormat->write_trailer to this function for mpeg1. That way, * the mpeg1 video gets a proper trailer when it is closed. * - * Returns + * Returns 0 * */ static int mpeg1_write_trailer(AVFormatContext *s) @@ -252,8 +252,8 @@ static int mpeg1_write_trailer(AVFormatContext *s) */ void ffmpeg_init() { - motion_log(ERR, TYPE_ENCODER, NO_ERRNO, "%s: ffmpeg LIBAVCODEC_BUILD %d" - " LIBAVFORMAT_BUILD %d", __FUNCTION__, LIBAVCODEC_BUILD, LIBAVFORMAT_BUILD); + MOTION_LOG(ERR, TYPE_ENCODER, NO_ERRNO, "%s: ffmpeg LIBAVCODEC_BUILD %d" + " LIBAVFORMAT_BUILD %d", LIBAVCODEC_BUILD, LIBAVFORMAT_BUILD); av_register_all(); #if LIBAVCODEC_BUILD > 4680 @@ -315,8 +315,8 @@ static AVOutputFormat *get_oformat(const char *codec, char *filename) #ifdef FFMPEG_NO_NONSTD_MPEG1 } else if (strcmp(codec, "mpeg1") == 0) { - motion_log(ERR, TYPE_ENCODER, NO_ERRNO, "%s: *** mpeg1 support for normal" - " videos has been disabled ***", __FUNCTION__); + MOTION_LOG(ERR, TYPE_ENCODER, NO_ERRNO, "%s: *** mpeg1 support for normal" + " videos has been disabled ***"); return NULL; #endif } else if (strcmp(codec, "mpeg4") == 0) { @@ -351,18 +351,18 @@ static AVOutputFormat *get_oformat(const char *codec, char *filename) ext = ".mov"; of = guess_format("mov", NULL, NULL); } else { - motion_log(ERR, TYPE_ENCODER, NO_ERRNO, "%s: ffmpeg_video_codec option value" - " %s is not supported", __FUNCTION__, codec); + MOTION_LOG(ERR, TYPE_ENCODER, NO_ERRNO, "%s: ffmpeg_video_codec option value" + " %s is not supported", codec); return NULL; } if (!of) { - motion_log(ERR, TYPE_ENCODER, NO_ERRNO, "%s: Could not guess format for %s", - __FUNCTION__, codec); + MOTION_LOG(ERR, TYPE_ENCODER, NO_ERRNO, "%s: Could not guess format for %s", + codec); return NULL; } - /* The 4 allows for ".avi" or ".mpg" to be appended */ + /* The 4 allows for ".avi" or ".mpg" to be appended. */ strncat(filename, ext, 4); return of; @@ -398,14 +398,14 @@ struct ffmpeg *ffmpeg_open(char *ffmpeg_video_codec, char *filename, ffmpeg->vbr = vbr; - /* store codec name in ffmpeg->codec, with buffer overflow check */ + /* Store codec name in ffmpeg->codec, with buffer overflow check. */ snprintf(ffmpeg->codec, sizeof(ffmpeg->codec), "%s", ffmpeg_video_codec); - /* allocation the output media context */ + /* Allocation the output media context. */ ffmpeg->oc = av_mallocz(sizeof(AVFormatContext)); if (!ffmpeg->oc) { - motion_log(ERR, TYPE_ENCODER, SHOW_ERRNO, "%s: Memory error while allocating" - " output media context", __FUNCTION__); + MOTION_LOG(ERR, TYPE_ENCODER, SHOW_ERRNO, "%s: Memory error while allocating" + " output media context"); ffmpeg_cleanups(ffmpeg); return NULL; } @@ -419,21 +419,21 @@ struct ffmpeg *ffmpeg_open(char *ffmpeg_video_codec, char *filename, snprintf(ffmpeg->oc->filename, sizeof(ffmpeg->oc->filename), "%s", filename); - /* Create a new video stream and initialize the codecs */ + /* Create a new video stream and initialize the codecs. */ ffmpeg->video_st = NULL; if (ffmpeg->oc->oformat->video_codec != CODEC_ID_NONE) { ffmpeg->video_st = av_new_stream(ffmpeg->oc, 0); if (!ffmpeg->video_st) { - motion_log(ERR, TYPE_ENCODER, SHOW_ERRNO, "%s: av_new_stream - could" - " not alloc stream", __FUNCTION__); + MOTION_LOG(ERR, TYPE_ENCODER, SHOW_ERRNO, "%s: av_new_stream - could" + " not alloc stream"); ffmpeg_cleanups(ffmpeg); return NULL; } } else { /* We did not get a proper video codec. */ - motion_log(ERR, TYPE_ENCODER, NO_ERRNO, "%s: Failed to obtain a proper" - " video codec", __FUNCTION__); + MOTION_LOG(ERR, TYPE_ENCODER, NO_ERRNO, "%s: Failed to obtain a proper" + " video codec"); ffmpeg_cleanups(ffmpeg); return NULL; } @@ -454,7 +454,7 @@ struct ffmpeg *ffmpeg_open(char *ffmpeg_video_codec, char *filename, c->width = width; c->height = height; #if LIBAVCODEC_BUILD >= 4754 - /* frame rate = 1/time_base, so we set 1/rate, not rate/1 */ + /* Frame rate = 1/time_base, so we set 1/rate, not rate/1 */ c->time_base.num = 1; c->time_base.den = rate; #else @@ -462,45 +462,45 @@ struct ffmpeg *ffmpeg_open(char *ffmpeg_video_codec, char *filename, c->frame_rate_base = 1; #endif /* LIBAVCODEC_BUILD >= 4754 */ - motion_log(DBG, TYPE_ENCODER, NO_ERRNO, "%s FPS %d", - __FUNCTION__, rate); + MOTION_LOG(DBG, TYPE_ENCODER, NO_ERRNO, "%s FPS %d", + rate); if (vbr) c->flags |= CODEC_FLAG_QSCALE; /* * Set codec specific parameters. - * Set intra frame distance in frames depending on codec + * Set intra frame distance in frames depending on codec. */ c->gop_size = is_mpeg1 ? 10 : 12; - /* some formats want stream headers to be separate */ + /* Some formats want stream headers to be separate. */ if (!strcmp(ffmpeg->oc->oformat->name, "mp4") || !strcmp(ffmpeg->oc->oformat->name, "mov") || !strcmp(ffmpeg->oc->oformat->name, "3gp")) { c->flags |= CODEC_FLAG_GLOBAL_HEADER; } - /* set the output parameters (must be done even if no parameters). */ + /* Set the output parameters (must be done even if no parameters). */ if (av_set_parameters(ffmpeg->oc, NULL) < 0) { - motion_log(ERR, TYPE_ENCODER, NO_ERRNO, "%s: av_set_parameters error:" - " Invalid output format parameters", __FUNCTION__); + MOTION_LOG(ERR, TYPE_ENCODER, NO_ERRNO, "%s: av_set_parameters error:" + " Invalid output format parameters"); ffmpeg_cleanups(ffmpeg); return NULL; } - /* Dump the format settings. This shows how the various streams relate to each other */ + /* Dump the format settings. This shows how the various streams relate to each other. */ //dump_format(ffmpeg->oc, 0, filename, 1); /* * Now that all the parameters are set, we can open the video - * codec and allocate the necessary encode buffers + * codec and allocate the necessary encode buffers. */ codec = avcodec_find_encoder(c->codec_id); if (!codec) { - motion_log(ERR, TYPE_ENCODER, NO_ERRNO, "%s: Codec %s not found", - __FUNCTION__, ffmpeg_video_codec); + MOTION_LOG(ERR, TYPE_ENCODER, NO_ERRNO, "%s: Codec %s not found", + ffmpeg_video_codec); ffmpeg_cleanups(ffmpeg); return NULL; } @@ -511,12 +511,12 @@ struct ffmpeg *ffmpeg_open(char *ffmpeg_video_codec, char *filename, /* Get a mutex lock. */ pthread_mutex_lock(&global_lock); - /* open the codec */ + /* Open the codec */ if (avcodec_open(c, codec) < 0) { /* Release the lock. */ pthread_mutex_unlock(&global_lock); - motion_log(ERR, TYPE_ENCODER, NO_ERRNO, "%s: avcodec_open - could not open codec %s", - __FUNCTION__, ffmpeg_video_codec); + MOTION_LOG(ERR, TYPE_ENCODER, NO_ERRNO, "%s: avcodec_open - could not open codec %s", + ffmpeg_video_codec); ffmpeg_cleanups(ffmpeg); return NULL; } @@ -536,22 +536,22 @@ struct ffmpeg *ffmpeg_open(char *ffmpeg_video_codec, char *filename, ffmpeg->video_outbuf = mymalloc(ffmpeg->video_outbuf_size); } - /* allocate the encoded raw picture */ + /* Allocate the encoded raw picture. */ ffmpeg->picture = avcodec_alloc_frame(); if (!ffmpeg->picture) { - motion_log(ERR, TYPE_ENCODER, NO_ERRNO, "%s: avcodec_alloc_frame -" - " could not alloc frame", __FUNCTION__); + MOTION_LOG(ERR, TYPE_ENCODER, NO_ERRNO, "%s: avcodec_alloc_frame -" + " could not alloc frame"); ffmpeg_cleanups(ffmpeg); return NULL; } - /* set variable bitrate if requested */ + /* Set variable bitrate if requested. */ if (ffmpeg->vbr) ffmpeg->picture->quality = ffmpeg->vbr; - /* set the frame data */ + /* Set the frame data. */ ffmpeg->picture->data[0] = y; ffmpeg->picture->data[1] = u; ffmpeg->picture->data[2] = v; @@ -559,7 +559,7 @@ struct ffmpeg *ffmpeg_open(char *ffmpeg_video_codec, char *filename, ffmpeg->picture->linesize[1] = ffmpeg->c->width / 2; ffmpeg->picture->linesize[2] = ffmpeg->c->width / 2; - /* open the output file, if needed */ + /* Open the output file, if needed. */ if (!(ffmpeg->oc->oformat->flags & AVFMT_NOFILE)) { char file_proto[256]; @@ -573,39 +573,39 @@ struct ffmpeg *ffmpeg_open(char *ffmpeg_video_codec, char *filename, snprintf(file_proto, sizeof(file_proto), "%s", filename); if (url_fopen(&ffmpeg->oc->pb, file_proto, URL_WRONLY) < 0) { - /* path did not exist? */ + /* Path did not exist? */ if (errno == ENOENT) { - /* create path for file (don't use file_proto)... */ + /* Create path for file (don't use file_proto)... */ if (create_path(filename) == -1) { ffmpeg_cleanups(ffmpeg); return NULL; } - /* and retry opening the file (use file_proto) */ + /* And retry opening the file (use file_proto). */ if (url_fopen(&ffmpeg->oc->pb, file_proto, URL_WRONLY) < 0) { - motion_log(ERR, TYPE_ENCODER, SHOW_ERRNO, "%s: url_fopen -" - " error opening file %s", __FUNCTION__, filename); + MOTION_LOG(ERR, TYPE_ENCODER, SHOW_ERRNO, "%s: url_fopen -" + " error opening file %s", filename); ffmpeg_cleanups(ffmpeg); return NULL; } /* Permission denied */ } else if (errno == EACCES) { - motion_log(ERR, TYPE_ENCODER, SHOW_ERRNO, + MOTION_LOG(ERR, TYPE_ENCODER, SHOW_ERRNO, "%s: url_fopen - error opening file %s" " ... check access rights to target directory", - __FUNCTION__, filename); + filename); ffmpeg_cleanups(ffmpeg); return NULL; } else { - motion_log(ERR, TYPE_ENCODER, SHOW_ERRNO, "%s: Error opening file %s", - __FUNCTION__, filename); + MOTION_LOG(ERR, TYPE_ENCODER, SHOW_ERRNO, "%s: Error opening file %s", + filename); ffmpeg_cleanups(ffmpeg); return NULL; } } } - /* write the stream header, if any */ + /* Write the stream header, if any. */ av_write_header(ffmpeg->oc); return ffmpeg; @@ -622,7 +622,7 @@ void ffmpeg_cleanups(struct ffmpeg *ffmpeg) { unsigned int i; - /* close each codec */ + /* Close each codec */ if (ffmpeg->video_st) { pthread_mutex_lock(&global_lock); #if LIBAVCODEC_BUILD > 4680 @@ -634,7 +634,7 @@ void ffmpeg_cleanups(struct ffmpeg *ffmpeg) free(ffmpeg->video_outbuf); } - /* free the streams */ + /* Free the streams */ for (i = 0; i < ffmpeg->oc->nb_streams; i++) av_freep(&ffmpeg->oc->streams[i]); @@ -644,7 +644,7 @@ void ffmpeg_cleanups(struct ffmpeg *ffmpeg) if (ffmpeg->oc->pb) url_fclose(&ffmpeg->oc->pb); } */ - /* free the stream */ + /* Free the stream */ av_free(ffmpeg->oc); #if LIBAVFORMAT_BUILD >= 4629 av_free(ffmpeg->c); @@ -663,7 +663,7 @@ void ffmpeg_close(struct ffmpeg *ffmpeg) { unsigned int i; - /* close each codec */ + /* Close each codec */ if (ffmpeg->video_st) { pthread_mutex_lock(&global_lock); avcodec_close(AVSTREAM_CODEC_PTR(ffmpeg->video_st)); @@ -672,16 +672,16 @@ void ffmpeg_close(struct ffmpeg *ffmpeg) free(ffmpeg->video_outbuf); } - /* write the trailer, if any */ + /* Write the trailer, if any. */ av_write_trailer(ffmpeg->oc); - /* free the streams */ + /* Free the streams. */ for (i = 0; i < ffmpeg->oc->nb_streams; i++) av_freep(&ffmpeg->oc->streams[i]); if (!(ffmpeg->oc->oformat->flags & AVFMT_NOFILE)) { - /* close the output file */ + /* Close the output file. */ #if LIBAVFORMAT_BUILD >= (52<<16) url_fclose(ffmpeg->oc->pb); #else @@ -689,7 +689,7 @@ void ffmpeg_close(struct ffmpeg *ffmpeg) #endif /* LIBAVFORMAT_BUILD >= (52<<16) */ } - /* free the stream */ + /* Free the stream. */ av_free(ffmpeg->oc); #if LIBAVFORMAT_BUILD >= 4629 av_free(ffmpeg->c); @@ -724,7 +724,7 @@ int ffmpeg_put_other_image(struct ffmpeg *ffmpeg, unsigned char *y, AVFrame *picture; int ret = 0; - /* allocate the encoded raw picture */ + /* Allocate the encoded raw picture. */ picture = ffmpeg_prepare_frame(ffmpeg, y, u, v); if (picture) { @@ -750,12 +750,12 @@ int ffmpeg_put_frame(struct ffmpeg *ffmpeg, AVFrame *pic) #ifdef FFMPEG_AVWRITEFRAME_NEWAPI AVPacket pkt; - av_init_packet(&pkt); /* init static structure */ + av_init_packet(&pkt); /* Init static structure. */ pkt.stream_index = ffmpeg->video_st->index; #endif /* FFMPEG_AVWRITEFRAME_NEWAPI */ if (ffmpeg->oc->oformat->flags & AVFMT_RAWPICTURE) { - /* raw video case. The API will change slightly in the near future for that */ + /* Raw video case. The API will change slightly in the near future for that. */ #ifdef FFMPEG_AVWRITEFRAME_NEWAPI pkt.flags |= PKT_FLAG_KEY; pkt.data = (uint8_t *)pic; @@ -766,16 +766,16 @@ int ffmpeg_put_frame(struct ffmpeg *ffmpeg, AVFrame *pic) (uint8_t *)pic, sizeof(AVPicture)); #endif /* FFMPEG_AVWRITEFRAME_NEWAPI */ } else { - /* encode the image */ + /* Encodes the image. */ out_size = avcodec_encode_video(AVSTREAM_CODEC_PTR(ffmpeg->video_st), ffmpeg->video_outbuf, ffmpeg->video_outbuf_size, pic); - /* if zero size, it means the image was buffered */ + /* If zero size, it means the image was buffered. */ if (out_size != 0) { /* - * Writes the compressed frame in the media file - * XXX: in case of B frames, the pts is not yet valid + * Writes the compressed frame in the media file. + * XXX: in case of B frames, the pts is not yet valid. */ #ifdef FFMPEG_AVWRITEFRAME_NEWAPI pkt.pts = AVSTREAM_CODEC_PTR(ffmpeg->video_st)->coded_frame->pts; @@ -797,8 +797,8 @@ int ffmpeg_put_frame(struct ffmpeg *ffmpeg, AVFrame *pic) } if (ret != 0) { - motion_log(ERR, TYPE_ENCODER, SHOW_ERRNO, "%s: Error while writing" - " video frame", __FUNCTION__); + MOTION_LOG(ERR, TYPE_ENCODER, SHOW_ERRNO, "%s: Error while writing" + " video frame"); ffmpeg_cleanups(ffmpeg); return -1; } @@ -824,16 +824,15 @@ AVFrame *ffmpeg_prepare_frame(struct ffmpeg *ffmpeg, unsigned char *y, picture = avcodec_alloc_frame(); if (!picture) { - motion_log(ERR, TYPE_ENCODER, SHOW_ERRNO, "%s: Could not alloc frame", - __FUNCTION__); + MOTION_LOG(ERR, TYPE_ENCODER, SHOW_ERRNO, "%s: Could not alloc frame"); return NULL; } - /* take care of variable bitrate setting */ + /* Take care of variable bitrate setting. */ if (ffmpeg->vbr) picture->quality = ffmpeg->vbr; - /* setup pointers and line widths */ + /* Setup pointers and line widths. */ picture->data[0] = y; picture->data[1] = u; picture->data[2] = v; @@ -897,12 +896,12 @@ void ffmpeg_avcodec_log(void *ignoreme ATTRIBUTE_UNUSED, int errno_flag, const c { char buf[1024]; - /* Flatten the message coming in from avcodec */ + /* Flatten the message coming in from avcodec. */ vsnprintf(buf, sizeof(buf), fmt, vl); /* If the debug_level is correct then send the message to the motion logging routine. */ - motion_log(ERR, TYPE_ENCODER, NO_ERRNO, "%s: %s - flag %d", - __FUNCTION__, buf, errno_flag); + MOTION_LOG(NTC, TYPE_ENCODER, NO_ERRNO, "%s: %s - flag %d", + buf, errno_flag); } #endif /* HAVE_FFMPEG */ diff --git a/jpegutils.c b/jpegutils.c index 0b350b7..e458d5c 100644 --- a/jpegutils.c +++ b/jpegutils.c @@ -35,7 +35,7 @@ #include #include - /* +/* * jpeg_data: buffer with input / output jpeg * len: Length of jpeg buffer * itype: 0: Not interlaced @@ -49,8 +49,6 @@ * width width of Y channel (width of U/V is width/2) * height height of Y channel (height of U/V is height/2) */ - - static void jpeg_buffer_src(j_decompress_ptr cinfo, unsigned char *buffer, long num); static void jpeg_buffer_dest(j_compress_ptr cinfo, unsigned char *buffer, @@ -70,13 +68,11 @@ static void jpeg_skip_ff(j_decompress_ptr cinfo); * Initialize source --- called by jpeg_read_header * before any data is actually read. */ - static void init_source(j_decompress_ptr cinfo ATTRIBUTE_UNUSED) { - /* no work necessary here */ + /* No work necessary here */ } - /* * Fill the input buffer --- called whenever buffer is emptied. * @@ -85,7 +81,6 @@ static void init_source(j_decompress_ptr cinfo ATTRIBUTE_UNUSED) * which is the JPEG EOI marker; * */ - static uint8_t EOI_data[2] = { 0xFF, 0xD9 }; static boolean fill_input_buffer(j_decompress_ptr cinfo) @@ -101,7 +96,6 @@ static boolean fill_input_buffer(j_decompress_ptr cinfo) * uninteresting data (such as an APPn marker). * */ - static void skip_input_data(j_decompress_ptr cinfo, long num_bytes) { if (num_bytes > 0) { @@ -117,27 +111,25 @@ static void skip_input_data(j_decompress_ptr cinfo, long num_bytes) * Terminate source --- called by jpeg_finish_decompress * after all data has been read. Often a no-op. */ - static void term_source(j_decompress_ptr cinfo ATTRIBUTE_UNUSED) { - /* no work necessary here */ + /* No work necessary here */ } /* * Prepare for input from a data buffer. */ - static void jpeg_buffer_src(j_decompress_ptr cinfo, unsigned char *buffer, long num) { /* The source object and input buffer are made permanent so that a series -* of JPEG images can be read from the same buffer by calling jpeg_buffer_src -* only before the first one. (If we discarded the buffer at the end of -* one image, we'd likely lose the start of the next one.) -* This makes it unsafe to use this manager and a different source -* manager serially with the same JPEG object. Caveat programmer. -*/ - if (cinfo->src == NULL) { /* first time for this JPEG object? */ + * of JPEG images can be read from the same buffer by calling jpeg_buffer_src + * only before the first one. (If we discarded the buffer at the end of + * one image, we'd likely lose the start of the next one.) + * This makes it unsafe to use this manager and a different source + * manager serially with the same JPEG object. Caveat programmer. + */ + if (cinfo->src == NULL) { /* First time for this JPEG object? */ cinfo->src = (struct jpeg_source_mgr *) (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_PERMANENT, sizeof (struct jpeg_source_mgr)); @@ -146,7 +138,7 @@ static void jpeg_buffer_src(j_decompress_ptr cinfo, unsigned char *buffer, long cinfo->src->init_source = init_source; cinfo->src->fill_input_buffer = fill_input_buffer; cinfo->src->skip_input_data = skip_input_data; - cinfo->src->resync_to_restart = jpeg_resync_to_restart; /* use default method */ + cinfo->src->resync_to_restart = jpeg_resync_to_restart; /* Use default method */ cinfo->src->term_source = term_source; cinfo->src->bytes_in_buffer = num; cinfo->src->next_input_byte = (JOCTET *) buffer; @@ -158,7 +150,6 @@ static void jpeg_buffer_src(j_decompress_ptr cinfo, unsigned char *buffer, long * particularly useful when reading several images from the same buffer: * It should be called to skip padding 0xff bytes beetween images. */ - static void jpeg_skip_ff(j_decompress_ptr cinfo) { while (cinfo->src->bytes_in_buffer > 1 @@ -183,7 +174,6 @@ static void jpeg_skip_ff(j_decompress_ptr cinfo) * Initialize destination --- called by jpeg_start_compress * before any data is actually written. */ - static void init_destination(j_compress_ptr cinfo ATTRIBUTE_UNUSED) { /* No work necessary here */ @@ -197,13 +187,11 @@ static void init_destination(j_compress_ptr cinfo ATTRIBUTE_UNUSED) * If it gets called, the given jpeg buffer was too small. * */ - static boolean empty_output_buffer(j_compress_ptr cinfo) { /*FIXME: */ - motion_log(ERR, TYPE_ALL, NO_ERRNO, "%s: Given jpeg buffer was too small", - __FUNCTION__); - ERREXIT (cinfo, JERR_BUFFER_SIZE); /* shouldn't be FILE_WRITE but BUFFER_OVERRUN! */ + MOTION_LOG(ERR, TYPE_ALL, NO_ERRNO, "%s: Given jpeg buffer was too small"); + ERREXIT (cinfo, JERR_BUFFER_SIZE); /* Shouldn't be FILE_WRITE but BUFFER_OVERRUN! */ return TRUE; } @@ -216,10 +204,9 @@ static boolean empty_output_buffer(j_compress_ptr cinfo) * application must deal with any cleanup that should happen even * for error exit. */ - static void term_destination(j_compress_ptr cinfo ATTRIBUTE_UNUSED) { - /* no work necessary here */ + /* No work necessary here */ } @@ -232,13 +219,14 @@ static void term_destination(j_compress_ptr cinfo ATTRIBUTE_UNUSED) static void jpeg_buffer_dest(j_compress_ptr cinfo, unsigned char *buf, long len) { - /* The destination object is made permanent so that multiple JPEG images - * can be written to the same file without re-executing jpeg_stdio_dest. + /* + * The destination object is made permanent so that multiple JPEG images + * can be written to the same file without re-executing jpeg_stdio_dest. * This makes it dangerous to use this manager and a different destination * manager serially with the same JPEG object, because their private object * sizes may be different. Caveat programmer. */ - if (cinfo->dest == NULL) { /* first time for this JPEG object? */ + if (cinfo->dest == NULL) { /* First time for this JPEG object? */ cinfo->dest = (struct jpeg_destination_mgr *) (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_PERMANENT, sizeof (struct jpeg_destination_mgr)); @@ -265,39 +253,40 @@ static void jpeg_buffer_dest(j_compress_ptr cinfo, unsigned char *buf, long len) * The following kind of error handling is from the * example.c file in the Independent JPEG Group's JPEG software */ - struct my_error_mgr { struct jpeg_error_mgr pub; /* "public" fields */ - jmp_buf setjmp_buffer; /* for return to caller */ + jmp_buf setjmp_buffer; /* For return to caller */ - /* original emit_message method */ + /* Original emit_message method. */ JMETHOD(void, original_emit_message, (j_common_ptr cinfo, int msg_level)); - /* was a corrupt-data warning seen */ + /* Was a corrupt-data warning seen. */ int warning_seen; }; static void my_error_exit(j_common_ptr cinfo) { - /* cinfo->err really points to a my_error_mgr struct, so coerce pointer */ + /* cinfo->err really points to a my_error_mgr struct, so coerce pointer. */ struct my_error_mgr *myerr = (struct my_error_mgr *) cinfo->err; - /* Always display the message. */ - /* We could postpone this until after returning, if we chose. */ + /* + * Always display the message. + * We could postpone this until after returning, if we chose. + */ (*cinfo->err->output_message) (cinfo); - /* Return control to the setjmp point */ + /* Return control to the setjmp point. */ longjmp (myerr->setjmp_buffer, 1); } static void my_emit_message(j_common_ptr cinfo, int msg_level) { - /* cinfo->err really points to a my_error_mgr struct, so coerce pointer */ + /* cinfo->err really points to a my_error_mgr struct, so coerce pointer. */ struct my_error_mgr *myerr = (struct my_error_mgr *) cinfo->err; if (msg_level < 0) myerr->warning_seen = 1; - /* call original emit_message() */ + /* Call original emit_message() */ (myerr->original_emit_message)(cinfo, msg_level); } @@ -312,7 +301,7 @@ static unsigned char chr2[8][MAX_CHROMA_WIDTH]; -#if 1 /* generation of 'std' Huffman tables... */ +#if 1 /* Generation of 'std' Huffman tables... */ static void add_huff_table(j_decompress_ptr dinfo, JHUFF_TBL **htblptr, const UINT8 *bits, const UINT8 *val) @@ -323,23 +312,23 @@ static void add_huff_table(j_decompress_ptr dinfo, JHUFF_TBL **htblptr, 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)); + /* Copy the number-of-symbols-of-each-code-length counts. */ + memcpy((*htblptr)->bits, bits, sizeof((*htblptr)->bits)); - /* Validate the counts. We do this here mainly so we can copy the right - * number of symbols from the val[] array, without risking marching off - * the end of memory. jchuff.c will do a more thorough test later. - */ - nsymbols = 0; + /* + * Validate the counts. We do this here mainly so we can copy the right + * number of symbols from the val[] array, without risking marching off + * the end of memory. jchuff.c will do a more thorough test later. + */ + nsymbols = 0; - for (len = 1; len <= 16; len++) - nsymbols += bits[len]; + for (len = 1; len <= 16; len++) + nsymbols += bits[len]; - if (nsymbols < 1 || nsymbols > 256) - motion_log(ERR, TYPE_ALL, NO_ERRNO, "%s: Given jpeg buffer was too small", - __FUNCTION__); + 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)); + memcpy((*htblptr)->huffval, val, nsymbols * sizeof(UINT8)); } @@ -450,7 +439,6 @@ static void guarantee_huff_tables(j_decompress_ptr dinfo) * in this case, "a damaged output image is likely." * */ - int decode_jpeg_raw (unsigned char *jpeg_data, int len, int itype, int ctype, unsigned int width, unsigned int height, unsigned char *raw0, @@ -481,7 +469,7 @@ int decode_jpeg_raw (unsigned char *jpeg_data, int len, /* We set up the normal JPEG error routines, then override error_exit. */ dinfo.err = jpeg_std_error (&jerr.pub); jerr.pub.error_exit = my_error_exit; - /* also hook the emit_message routine to note corrupt-data warnings */ + /* Also hook the emit_message routine to note corrupt-data warnings. */ jerr.original_emit_message = jerr.pub.emit_message; jerr.pub.emit_message = my_emit_message; jerr.warning_seen = 0; @@ -497,9 +485,10 @@ int decode_jpeg_raw (unsigned char *jpeg_data, int len, jpeg_buffer_src (&dinfo, jpeg_data, len); - /* Read header, make some checks and try to figure out what the - user really wants */ - + /* + * Read header, make some checks and try to figure out what the + * user really wants. + */ jpeg_read_header (&dinfo, TRUE); dinfo.raw_data_out = TRUE; dinfo.out_color_space = JCS_YCbCr; @@ -508,8 +497,8 @@ int decode_jpeg_raw (unsigned char *jpeg_data, int len, jpeg_start_decompress (&dinfo); if (dinfo.output_components != 3) { - motion_log(ERR, TYPE_ALL, NO_ERRNO, "%s: Output components of JPEG image" - " = %d, must be 3", __FUNCTION__, dinfo.output_components); + MOTION_LOG(ERR, TYPE_ALL, NO_ERRNO, "%s: Output components of JPEG image" + " = %d, must be 3", dinfo.output_components); goto ERR_EXIT; } @@ -520,20 +509,20 @@ int decode_jpeg_raw (unsigned char *jpeg_data, int len, if ((hsf[0] != 2 && hsf[0] != 1) || hsf[1] != 1 || hsf[2] != 1 || (vsf[0] != 1 && vsf[0] != 2) || vsf[1] != 1 || vsf[2] != 1) { - motion_log(ERR, TYPE_ALL, NO_ERRNO, "%s: Unsupported sampling factors," - " hsf=(%d, %d, %d) vsf=(%d, %d, %d) !", __FUNCTION__, hsf[0], hsf[1], + MOTION_LOG(ERR, TYPE_ALL, NO_ERRNO, "%s: Unsupported sampling factors," + " hsf=(%d, %d, %d) vsf=(%d, %d, %d) !", hsf[0], hsf[1], hsf[2], vsf[0], vsf[1], vsf[2]); goto ERR_EXIT; } if (hsf[0] == 1) { if (height % 8 != 0) { - motion_log(ERR, TYPE_ALL, NO_ERRNO, "%s: YUV 4:4:4 sampling, but image" - " height %d not dividable by 8 !", __FUNCTION__, height); + MOTION_LOG(ERR, TYPE_ALL, NO_ERRNO, "%s: YUV 4:4:4 sampling, but image" + " height %d not dividable by 8 !", height); goto ERR_EXIT; } - for (y = 0; y < 16; y++) { // allocate a special buffer for the extra sampling depth + for (y = 0; y < 16; y++) { // Allocate a special buffer for the extra sampling depth. row1_444[y] = (unsigned char *)malloc(dinfo.output_width * sizeof(char)); row2_444[y] = (unsigned char *)malloc(dinfo.output_width * sizeof(char)); } @@ -541,23 +530,23 @@ int decode_jpeg_raw (unsigned char *jpeg_data, int len, scanarray[2] = row2_444; } - /* Height match image height or be exact twice the image height */ + /* Height match image height or be exact twice the image height. */ if (dinfo.output_height == height) { numfields = 1; } else if (2 * dinfo.output_height == height) { numfields = 2; } else { - motion_log(ERR, TYPE_ALL, NO_ERRNO, "%s: Read JPEG: requested height = %d, " - "height of image = %d", __FUNCTION__, height, dinfo.output_height); + MOTION_LOG(ERR, TYPE_ALL, NO_ERRNO, "%s: Read JPEG: requested height = %d, " + "height of image = %d", height, dinfo.output_height); goto ERR_EXIT; } /* Width is more flexible */ if (dinfo.output_width > MAX_LUMA_WIDTH) { - motion_log(ERR, TYPE_ALL, NO_ERRNO, "%s: Image width of %d exceeds max", - __FUNCTION__, dinfo.output_width); + MOTION_LOG(ERR, TYPE_ALL, NO_ERRNO, "%s: Image width of %d exceeds max", + dinfo.output_width); goto ERR_EXIT; } @@ -569,7 +558,7 @@ int decode_jpeg_raw (unsigned char *jpeg_data, int len, else xsl = 0; } else if (width == 2 * dinfo.output_width / 3) { - /* special case of 3:2 downsampling */ + /* Special case of 3:2 downsampling */ hdown = 2; xsl = 0; } else { @@ -606,8 +595,8 @@ int decode_jpeg_raw (unsigned char *jpeg_data, int len, yl = yc = (1 - field); break; default: - motion_log(ERR, TYPE_ALL, NO_ERRNO, "%s: Input is interlaced but" - " no interlacing set", __FUNCTION__); + MOTION_LOG(ERR, TYPE_ALL, NO_ERRNO, "%s: Input is interlaced but" + " no interlacing set"); goto ERR_EXIT; } } else { @@ -615,7 +604,7 @@ int decode_jpeg_raw (unsigned char *jpeg_data, int len, } while (dinfo.output_scanline < dinfo.output_height) { - /* read raw data */ + /* Read raw data */ jpeg_read_raw_data (&dinfo, scanarray, 8 * vsf[0]); for (y = 0; y < 8 * vsf[0]; yl += numfields, y++) { @@ -706,10 +695,10 @@ int decode_jpeg_raw (unsigned char *jpeg_data, int len, break; default: /* - * should be case Y4M_CHROMA_420JPEG: but use default: for compatibility. Some - * pass things like '420' in with the expectation that anything other than - * Y4M_CHROMA_422 will default to 420JPEG. - */ + * Should be case Y4M_CHROMA_420JPEG: but use default: for compatibility. Some + * pass things like '420' in with the expectation that anything other than + * Y4M_CHROMA_422 will default to 420JPEG. + */ if (vsf[0] == 1) { /* Really downsample */ for (y = 0; y < 8 /*&& yc < height/2*/; y += 2, yc += numfields) { @@ -724,7 +713,7 @@ int decode_jpeg_raw (unsigned char *jpeg_data, int len, } else { /* Just copy */ - for (y = 0; y < 8 /*&& yc < height/2 */; y++, yc += numfields) { + for (y = 0; y < 8 /* && yc < height / 2 */; y++, yc += numfields) { xd = yc * width / 2; for (x = 0; x < width / 2; x++, xd++) { @@ -743,7 +732,7 @@ int decode_jpeg_raw (unsigned char *jpeg_data, int len, } if (hsf[0] == 1) { - for (y = 0; y < 16; y++) { // allocate a special buffer for the extra sampling depth + for (y = 0; y < 16; y++) { // Allocate a special buffer for the extra sampling depth. free(row1_444[y]); free(row2_444[y]); } @@ -770,7 +759,6 @@ int decode_jpeg_raw (unsigned char *jpeg_data, int len, * ctype Chroma format for decompression. * Currently only Y4M_CHROMA_{420JPEG,422} are available */ - int decode_jpeg_gray_raw(unsigned char *jpeg_data, int len, int itype, int ctype, unsigned int width, unsigned int height, unsigned char *raw0, @@ -803,17 +791,18 @@ int decode_jpeg_gray_raw(unsigned char *jpeg_data, int len, jpeg_buffer_src (&dinfo, jpeg_data, len); - /* Read header, make some checks and try to figure out what the - user really wants */ - + /* + * Read header, make some checks and try to figure out what the + * user really wants. + */ jpeg_read_header (&dinfo, TRUE); dinfo.raw_data_out = TRUE; dinfo.out_color_space = JCS_GRAYSCALE; dinfo.dct_method = JDCT_IFAST; if (dinfo.jpeg_color_space != JCS_GRAYSCALE) { - motion_log(ERR, TYPE_ALL, NO_ERRNO, "%s: Expected grayscale colorspace" - " for JPEG raw decoding", __FUNCTION__); + MOTION_LOG(ERR, TYPE_ALL, NO_ERRNO, "%s: Expected grayscale colorspace" + " for JPEG raw decoding"); goto ERR_EXIT; } @@ -823,23 +812,23 @@ int decode_jpeg_gray_raw(unsigned char *jpeg_data, int len, hsf[0] = 1; hsf[1] = 1; hsf[2] = 1; vsf[0]= 1; vsf[1] = 1; vsf[2] = 1; - /* Height match image height or be exact twice the image height */ + /* Height match image height or be exact twice the image height. */ if (dinfo.output_height == height) { numfields = 1; } else if (2 * dinfo.output_height == height) { numfields = 2; } else { - motion_log(ERR, TYPE_ALL, NO_ERRNO, "%s: Read JPEG: requested height = %d, " - "height of image = %d", __FUNCTION__, height, dinfo.output_height); + MOTION_LOG(ERR, TYPE_ALL, NO_ERRNO, "%s: Read JPEG: requested height = %d, " + "height of image = %d", height, dinfo.output_height); goto ERR_EXIT; } /* Width is more flexible */ if (dinfo.output_width > MAX_LUMA_WIDTH) { - motion_log(ERR, TYPE_ALL, NO_ERRNO, "%s: Image width of %d exceeds max", - __FUNCTION__, dinfo.output_width); + MOTION_LOG(ERR, TYPE_ALL, NO_ERRNO, "%s: Image width of %d exceeds max", + dinfo.output_width); goto ERR_EXIT; } @@ -888,8 +877,8 @@ int decode_jpeg_gray_raw(unsigned char *jpeg_data, int len, yl = yc = (1 - field); break; default: - motion_log(ERR, TYPE_ALL, NO_ERRNO, "%s: Input is interlaced" - " but no interlacing set", __FUNCTION__); + MOTION_LOG(ERR, TYPE_ALL, NO_ERRNO, "%s: Input is interlaced" + " but no interlacing set"); goto ERR_EXIT; } } else { @@ -903,10 +892,10 @@ int decode_jpeg_gray_raw(unsigned char *jpeg_data, int len, xd = yl * width; xs = xsl; - if (hdown == 0) { // no horiz downsampling + if (hdown == 0) { // No horiz downsampling for (x = 0; x < width; x++) raw0[xd++] = row0[y][xs++]; - } else if (hdown == 1) { // half the res + } else if (hdown == 1) { // Half the res for (x = 0; x < width; x++, xs += 2) raw0[xd++] = (row0[y][xs] + row0[y][xs + 1]) >> 1; } else { // 2:3 downsampling @@ -947,7 +936,7 @@ int decode_jpeg_gray_raw(unsigned char *jpeg_data, int len, case Y4M_CHROMA_422: if (vsf[0] == 1) { /* Just copy */ - for (y = 0; y < 8 /*&& yc < height */; y++, yc += numfields) { + for (y = 0; y < 8 /* && yc < height */; y++, yc += numfields) { xd = yc * width / 2; for (x = 0; x < width / 2; x++, xd++) { @@ -957,7 +946,7 @@ int decode_jpeg_gray_raw(unsigned char *jpeg_data, int len, } } else { /* upsample */ - for (y = 0; y < 8 /*&& yc < height */; y++) { + for (y = 0; y < 8 /* && yc < height */; y++) { xd = yc * width / 2; for (x = 0; x < width / 2; x++, xd++) { @@ -1031,7 +1020,7 @@ int decode_jpeg_gray_raw(unsigned char *jpeg_data, int len, * * *******************************************************************/ - /* +/* * jpeg_data: Buffer to hold output jpeg * len: Length of buffer * itype: 0: Not interlaced @@ -1040,7 +1029,6 @@ int decode_jpeg_gray_raw(unsigned char *jpeg_data, int len, * ctype Chroma format for decompression. * Currently only Y4M_CHROMA_{420JPEG,422} are available */ - int encode_jpeg_raw(unsigned char *jpeg_data, int len, int quality, int itype, int ctype, unsigned int width, unsigned int height, unsigned char *raw0, @@ -1100,14 +1088,14 @@ int encode_jpeg_raw(unsigned char *jpeg_data, int len, int quality, if ((width > 4096) || (height > 4096)) { - motion_log(ERR, TYPE_ALL, NO_ERRNO, "%s: Image dimensions (%dx%d) exceed" - " lavtools' max (4096x4096)", __FUNCTION__, width, height); + MOTION_LOG(ERR, TYPE_ALL, NO_ERRNO, "%s: Image dimensions (%dx%d) exceed" + " lavtools' max (4096x4096)", width, height); goto ERR_EXIT; } if ((width % 16) || (height % 16)) { - motion_log(ERR, TYPE_ALL, NO_ERRNO, "%s: Image dimensions (%dx%d) not" - " multiples of 16", __FUNCTION__, width, height); + MOTION_LOG(ERR, TYPE_ALL, NO_ERRNO, "%s: Image dimensions (%dx%d) not" + " multiples of 16", width, height); goto ERR_EXIT; } @@ -1115,14 +1103,14 @@ int encode_jpeg_raw(unsigned char *jpeg_data, int len, int quality, switch (itype) { case Y4M_ILACE_TOP_FIRST: - case Y4M_ILACE_BOTTOM_FIRST: /* interlaced */ + case Y4M_ILACE_BOTTOM_FIRST: /* Interlaced */ numfields = 2; break; default: numfields = 1; if (height > 2048) { - motion_log(ERR, TYPE_ALL, NO_ERRNO, "%s: Image height (%d) exceeds" - " lavtools max for non-interlaced frames", __FUNCTION__, height); + MOTION_LOG(ERR, TYPE_ALL, NO_ERRNO, "%s: Image height (%d) exceeds" + " lavtools max for non-interlaced frames", height); goto ERR_EXIT; } } @@ -1141,15 +1129,15 @@ int encode_jpeg_raw(unsigned char *jpeg_data, int len, int quality, jpeg_write_marker(&cinfo, JPEG_APP0 + 1, marker0, 40); switch (itype) { - case Y4M_ILACE_TOP_FIRST: /* top field first */ + case Y4M_ILACE_TOP_FIRST: /* Top field first */ yl = yc = field; break; - case Y4M_ILACE_BOTTOM_FIRST: /* bottom field first */ + case Y4M_ILACE_BOTTOM_FIRST: /* Bottom field first */ yl = yc = (1 - field); break; default: - motion_log(ERR, TYPE_ALL, NO_ERRNO, "%s: Input is interlaced" - " but no interlacing set", __FUNCTION__); + MOTION_LOG(ERR, TYPE_ALL, NO_ERRNO, "%s: Input is interlaced" + " but no interlacing set"); goto ERR_EXIT; } @@ -1184,7 +1172,7 @@ int encode_jpeg_raw(unsigned char *jpeg_data, int len, int quality, i = len - cinfo.dest->free_in_buffer; jpeg_destroy_compress (&cinfo); - return i; /* size of jpeg */ + return i; /* Size of jpeg */ ERR_EXIT: jpeg_destroy_compress (&cinfo); diff --git a/logger.c b/logger.c index e2d927d..428dbed 100644 --- a/logger.c +++ b/logger.c @@ -133,7 +133,7 @@ static char *str_time(void) } /** - * motion_log + * MOTION_LOG * * This routine is used for printing all informational, debug or error * messages produced by any of the other motion functions. It always diff --git a/logger.h b/logger.h index a672b2d..bf689b9 100644 --- a/logger.h +++ b/logger.h @@ -50,6 +50,8 @@ #define TYPE_DEFAULT TYPE_ALL /* Default type */ #define TYPE_DEFAULT_STR "ALL" /* Default name logs */ +#define MOTION_LOG(x, y, z, format, args...) motion_log(x, y, z, format, __FUNCTION__, ##args) + int get_log_type(const char* type); const char* get_log_type_str(unsigned int type); void set_log_type(unsigned int type); diff --git a/motion.c b/motion.c index 822d83c..6198cb5 100644 --- a/motion.c +++ b/motion.c @@ -111,8 +111,8 @@ static void image_ring_resize(struct context *cnt, int new_size) smallest = cnt->imgs.image_ring_size; if (cnt->imgs.image_ring_in == smallest - 1 || smallest == 0) { - motion_log(ERR, TYPE_ALL, NO_ERRNO, "%s: Resizing pre_capture buffer to %d items", - __FUNCTION__, new_size); + MOTION_LOG(ERR, TYPE_ALL, NO_ERRNO, "%s: Resizing pre_capture buffer to %d items", + new_size); /* Create memory for new ring buffer */ struct image_data *tmp; @@ -388,13 +388,13 @@ static void motion_remove_pid(void) { if ((cnt_list[0]->daemon) && (cnt_list[0]->conf.pid_file) && (restart == 0)) { if (!unlink(cnt_list[0]->conf.pid_file)) - motion_log(ERR, TYPE_ALL, NO_ERRNO, "%s: Removed process id file (pid file).", __FUNCTION__); + MOTION_LOG(ERR, TYPE_ALL, NO_ERRNO, "%s: Removed process id file (pid file)."); else - motion_log(ERR, TYPE_ALL, SHOW_ERRNO, "%s: Error removing pid file", __FUNCTION__); + MOTION_LOG(ERR, TYPE_ALL, SHOW_ERRNO, "%s: Error removing pid file"); } if (ptr_logfile) { - motion_log(ERR, TYPE_ALL, NO_ERRNO, "%s: Closing logfile (%s).", __FUNCTION__, + MOTION_LOG(ERR, TYPE_ALL, NO_ERRNO, "%s: Closing logfile (%s).", cnt_list[0]->conf.log_file); set_log_mode(LOGMODE_SYSLOG); myfclose(ptr_logfile); @@ -471,8 +471,8 @@ static void motion_detected(struct context *cnt, int dev, struct image_data *img /* EVENT_FIRSTMOTION triggers on_event_start_command and event_ffmpeg_newfile */ event(cnt, EVENT_FIRSTMOTION, img->image, NULL, NULL, &img->timestamp_tm); - motion_log(WRN, TYPE_ALL, NO_ERRNO, "%s: Motion detected - starting event %d", - __FUNCTION__, cnt->event_nr); + MOTION_LOG(WRN, TYPE_ALL, NO_ERRNO, "%s: Motion detected - starting event %d", + cnt->event_nr); /* always save first motion frame as preview-shot, may be changed to an other one later */ if (cnt->new_img & (NEWIMG_FIRST | NEWIMG_BEST | NEWIMG_CENTER)) @@ -587,8 +587,8 @@ static void process_image_ring(struct context *cnt, unsigned int max_images) int frames = cnt->movie_fps - (cnt->movie_last_shot + 1); if (frames > 0) { char tmp[15]; - motion_log(DBG, TYPE_ALL, NO_ERRNO, "%s: Added %d fillerframes into movie", - __FUNCTION__, frames); + MOTION_LOG(DBG, TYPE_ALL, NO_ERRNO, "%s: Added %d fillerframes into movie", + frames); sprintf(tmp, "Fillerframes %d", frames); draw_text(cnt->imgs.image_ring[cnt->imgs.image_ring_out].image, 10, 40, cnt->imgs.width, tmp, cnt->conf.text_double); @@ -695,8 +695,8 @@ static int motion_init(struct context *cnt) cnt->detecting_motion = 0; cnt->makemovie = 0; - motion_log(DBG, TYPE_ALL, NO_ERRNO, "%s: Thread %d started", - __FUNCTION__, (unsigned long)pthread_getspecific(tls_key_threadnr)); + MOTION_LOG(DBG, TYPE_ALL, NO_ERRNO, "%s: Thread %d started", + (unsigned long)pthread_getspecific(tls_key_threadnr)); if (!cnt->conf.filepath) cnt->conf.filepath = mystrdup("."); @@ -710,18 +710,16 @@ static int motion_init(struct context *cnt) * file options. */ if (cnt->video_dev == -1) { - motion_log(ERR, TYPE_ALL, NO_ERRNO, "%s: Could not fetch initial image from camera " - "Motion continues using width and height from config file(s)", - __FUNCTION__); + MOTION_LOG(ERR, TYPE_ALL, NO_ERRNO, "%s: Could not fetch initial image from camera " + "Motion continues using width and height from config file(s)"); cnt->imgs.width = cnt->conf.width; cnt->imgs.height = cnt->conf.height; cnt->imgs.size = cnt->conf.width * cnt->conf.height * 3 / 2; cnt->imgs.motionsize = cnt->conf.width * cnt->conf.height; cnt->imgs.type = VIDEO_PALETTE_YUV420P; } else if (cnt->video_dev == -2) { - motion_log(ERR, TYPE_ALL, NO_ERRNO, "%s: Could not fetch initial image from camera " - "Motion only supports width and height modulo 16", - __FUNCTION__); + MOTION_LOG(ERR, TYPE_ALL, NO_ERRNO, "%s: Could not fetch initial image from camera " + "Motion only supports width and height modulo 16"); return -3; } @@ -780,7 +778,7 @@ static int motion_init(struct context *cnt) memset(cnt->imgs.image_virgin, 0x80, cnt->imgs.size); /* initialize to grey */ draw_text(cnt->imgs.image_virgin, 10, 20, cnt->imgs.width, "Error capturing first image", cnt->conf.text_double); - motion_log(ERR, TYPE_ALL, NO_ERRNO, "%s: Error capturing first image", __FUNCTION__); + MOTION_LOG(ERR, TYPE_ALL, NO_ERRNO, "%s: Error capturing first image"); } } @@ -790,29 +788,25 @@ static int motion_init(struct context *cnt) #if !defined(WITHOUT_V4L) && !defined(BSD) /* open video loopback devices if enabled */ if (cnt->conf.vidpipe) { - motion_log(DBG, TYPE_ALL, NO_ERRNO, "%s: Opening video loopback device for normal pictures", - __FUNCTION__); + MOTION_LOG(DBG, TYPE_ALL, NO_ERRNO, "%s: Opening video loopback device for normal pictures"); /* vid_startpipe should get the output dimensions */ cnt->pipe = vid_startpipe(cnt->conf.vidpipe, cnt->imgs.width, cnt->imgs.height, cnt->imgs.type); if (cnt->pipe < 0) { - motion_log(ERR, TYPE_ALL, NO_ERRNO, "%s: Failed to open video loopback for normal pictures", - __FUNCTION__); + MOTION_LOG(ERR, TYPE_ALL, NO_ERRNO, "%s: Failed to open video loopback for normal pictures"); return -1; } } if (cnt->conf.motionvidpipe) { - motion_log(DBG, TYPE_ALL, NO_ERRNO, "%s: Opening video loopback device for motion pictures", - __FUNCTION__); + MOTION_LOG(DBG, TYPE_ALL, NO_ERRNO, "%s: Opening video loopback device for motion pictures"); /* vid_startpipe should get the output dimensions */ cnt->mpipe = vid_startpipe(cnt->conf.motionvidpipe, cnt->imgs.width, cnt->imgs.height, cnt->imgs.type); if (cnt->mpipe < 0) { - motion_log(ERR, TYPE_ALL, NO_ERRNO, "%s: Failed to open video loopback for motion pictures", - __FUNCTION__); + MOTION_LOG(ERR, TYPE_ALL, NO_ERRNO, "%s: Failed to open video loopback for motion pictures"); return -1; } } @@ -820,16 +814,16 @@ static int motion_init(struct context *cnt) #if defined(HAVE_MYSQL) || defined(HAVE_PGSQL) || defined(HAVE_SQLITE3) if (cnt->conf.database_type) { - motion_log(ERR, TYPE_DB, NO_ERRNO, "%s: Database backend %s", __FUNCTION__, - cnt->conf.database_type); + MOTION_LOG(ERR, TYPE_DB, NO_ERRNO, "%s: Database backend %s", + cnt->conf.database_type); #ifdef HAVE_SQLITE3 if ((!strcmp(cnt->conf.database_type, "sqlite3")) && cnt->conf.sqlite3_db) { - motion_log(ERR, TYPE_DB, NO_ERRNO, "%s: DB %s", __FUNCTION__, + MOTION_LOG(ERR, TYPE_DB, NO_ERRNO, "%s: DB %s", cnt->conf.sqlite3_db); if (sqlite3_open(cnt->conf.sqlite3_db, &cnt->database_sqlite3) != SQLITE_OK) { - motion_log(EMG, TYPE_DB, NO_ERRNO, "%s: Can't open database %s : %s\n", __FUNCTION__, + MOTION_LOG(EMG, TYPE_DB, NO_ERRNO, "%s: Can't open database %s : %s\n", cnt->conf.sqlite3_db, sqlite3_errmsg(cnt->database_sqlite3)); sqlite3_close(cnt->database_sqlite3); exit(1); @@ -844,10 +838,10 @@ static int motion_init(struct context *cnt) if (!mysql_real_connect(cnt->database, cnt->conf.database_host, cnt->conf.database_user, cnt->conf.database_password, cnt->conf.database_dbname, 0, NULL, 0)) { - motion_log(ERR, TYPE_DB, NO_ERRNO, "%s: Cannot connect to MySQL database %s on host %s with user %s", - __FUNCTION__, cnt->conf.database_dbname, cnt->conf.database_host, - cnt->conf.database_user); - motion_log(ERR, TYPE_DB, NO_ERRNO, "%s: MySQL error was %s", __FUNCTION__, mysql_error(cnt->database)); + MOTION_LOG(ERR, TYPE_DB, NO_ERRNO, "%s: Cannot connect to MySQL database %s on host %s with user %s", + cnt->conf.database_dbname, cnt->conf.database_host, + cnt->conf.database_user); + MOTION_LOG(ERR, TYPE_DB, NO_ERRNO, "%s: MySQL error was %s", mysql_error(cnt->database)); return -2; } #if (defined(MYSQL_VERSION_ID)) && (MYSQL_VERSION_ID > 50012) @@ -876,8 +870,8 @@ static int motion_init(struct context *cnt) cnt->database_pg = PQconnectdb(connstring); if (PQstatus(cnt->database_pg) == CONNECTION_BAD) { - motion_log(ERR, TYPE_DB, NO_ERRNO, "%s: Connection to PostgreSQL database '%s' failed: %s", - __FUNCTION__, cnt->conf.database_dbname, PQerrorMessage(cnt->database_pg)); + MOTION_LOG(ERR, TYPE_DB, NO_ERRNO, "%s: Connection to PostgreSQL database '%s' failed: %s", + cnt->conf.database_dbname, PQerrorMessage(cnt->database_pg)); return -2; } } @@ -905,8 +899,8 @@ static int motion_init(struct context *cnt) cnt->imgs.mask = get_pgm(picture, cnt->imgs.width, cnt->imgs.height); myfclose(picture); } else { - motion_log(ERR, TYPE_ALL, SHOW_ERRNO, "%s: Error opening mask file %s", - __FUNCTION__, cnt->conf.mask_file); + MOTION_LOG(ERR, TYPE_ALL, SHOW_ERRNO, "%s: Error opening mask file %s", + cnt->conf.mask_file); /* * Try to write an empty mask file to make it easier * for the user to edit it @@ -915,11 +909,10 @@ static int motion_init(struct context *cnt) } if (!cnt->imgs.mask) { - motion_log(ERR, TYPE_ALL, NO_ERRNO, "%s: Failed to read mask image. Mask feature disabled.", - __FUNCTION__); + MOTION_LOG(ERR, TYPE_ALL, NO_ERRNO, "%s: Failed to read mask image. Mask feature disabled."); } else { - motion_log(DBG, TYPE_ALL, NO_ERRNO, "%s: Maskfile \"%s\" loaded.", - __FUNCTION__, cnt->conf.mask_file); + MOTION_LOG(DBG, TYPE_ALL, NO_ERRNO, "%s: Maskfile \"%s\" loaded.", + cnt->conf.mask_file); } } else { cnt->imgs.mask = NULL; @@ -939,12 +932,12 @@ static int motion_init(struct context *cnt) /* Initialize stream server if stream port is specified to not 0 */ if (cnt->conf.stream_port) { if (stream_init(cnt) == -1) { - motion_log(ERR, TYPE_ALL, SHOW_ERRNO, "%s: Problem enabling motion-stream server in port %d", - __FUNCTION__, cnt->conf.stream_port); + MOTION_LOG(ERR, TYPE_ALL, SHOW_ERRNO, "%s: Problem enabling motion-stream server in port %d", + cnt->conf.stream_port); cnt->finish = 1; } else { - motion_log(DBG, TYPE_ALL, NO_ERRNO, "%s: Started motion-stream server in port %d", - __FUNCTION__, cnt->conf.stream_port); + MOTION_LOG(DBG, TYPE_ALL, NO_ERRNO, "%s: Started motion-stream server in port %d", + cnt->conf.stream_port); } } @@ -974,7 +967,7 @@ static void motion_cleanup(struct context *cnt) event(cnt, EVENT_STOP, NULL, NULL, NULL, NULL); if (cnt->video_dev >= 0) { - motion_log(DBG, TYPE_ALL, NO_ERRNO, "%s: Calling vid_close() from motion_cleanup", __FUNCTION__); + MOTION_LOG(DBG, TYPE_ALL, NO_ERRNO, "%s: Calling vid_close() from motion_cleanup"); vid_close(cnt); } @@ -1300,8 +1293,8 @@ static void *motion_loop(void *arg) */ if (cnt->video_dev < 0 && cnt->currenttime % 10 == 0 && cnt->shots == 0) { - motion_log(ERR, TYPE_ALL, NO_ERRNO, - "%s: Retrying until successful connection with camera", __FUNCTION__); + MOTION_LOG(ERR, TYPE_ALL, NO_ERRNO, + "%s: Retrying until successful connection with camera"); cnt->video_dev = vid_start(cnt); /* @@ -1309,11 +1302,11 @@ static void *motion_loop(void *arg) * we need to restart Motion to re-allocate all the buffers */ if (cnt->imgs.width != cnt->conf.width || cnt->imgs.height != cnt->conf.height) { - motion_log(ERR, TYPE_ALL, NO_ERRNO, "%s: Camera has finally become available\n" + MOTION_LOG(ERR, TYPE_ALL, NO_ERRNO, "%s: Camera has finally become available\n" "Camera image has different width and height" "from what is in the config file. You should fix that\n" "Restarting Motion thread to reinitialize all " - "image buffers to new picture dimensions", __FUNCTION__); + "image buffers to new picture dimensions"); cnt->conf.width = cnt->imgs.width; cnt->conf.height = cnt->imgs.height; /* @@ -1348,7 +1341,7 @@ static void *motion_loop(void *arg) /* If all is well reset missing_frame_counter */ if (cnt->missing_frame_counter >= MISSING_FRAMES_TIMEOUT * cnt->conf.frame_limit) { /* If we previously logged starting a grey image, now log video re-start */ - motion_log(ERR, TYPE_ALL, NO_ERRNO, "%s: Video signal re-acquired", __FUNCTION__); + MOTION_LOG(ERR, TYPE_ALL, NO_ERRNO, "%s: Video signal re-acquired"); // event for re-acquired video signal can be called here } cnt->missing_frame_counter = 0; @@ -1378,8 +1371,7 @@ static void *motion_loop(void *arg) // FATAL ERROR - leave the thread by breaking out of the main loop } else if (vid_return_code < 0) { /* Fatal error - Close video device */ - motion_log(ERR, TYPE_ALL, NO_ERRNO, "%s: Video device fatal error - Closing video device", - __FUNCTION__); + MOTION_LOG(ERR, TYPE_ALL, NO_ERRNO, "%s: Video device fatal error - Closing video device"); vid_close(cnt); /* * Use virgin image, if we are not able to open it again next loop @@ -1397,8 +1389,8 @@ static void *motion_loop(void *arg) */ } else { - motion_log(DBG, TYPE_ALL, NO_ERRNO, "%s: vid_return_code %d", - __FUNCTION__, vid_return_code); + MOTION_LOG(DBG, TYPE_ALL, NO_ERRNO, "%s: vid_return_code %d", + vid_return_code); /* * Netcams that change dimensions while Motion is running will @@ -1407,8 +1399,8 @@ static void *motion_loop(void *arg) * other way */ if (vid_return_code == NETCAM_RESTART_ERROR) { - motion_log(ERR, TYPE_ALL, NO_ERRNO, "%s: Restarting Motion thread to reinitialize all " - "image buffers", __FUNCTION__); + MOTION_LOG(ERR, TYPE_ALL, NO_ERRNO, "%s: Restarting Motion thread to reinitialize all " + "image buffers"); /* * Break out of main loop terminating thread * watchdog will start us again @@ -1457,8 +1449,7 @@ static void *motion_loop(void *arg) /* Write error message only once */ if (cnt->missing_frame_counter == MISSING_FRAMES_TIMEOUT * cnt->conf.frame_limit) { - motion_log(ERR, TYPE_ALL, NO_ERRNO, "%s: Video signal lost - Adding grey image", - __FUNCTION__); + MOTION_LOG(ERR, TYPE_ALL, NO_ERRNO, "%s: Video signal lost - Adding grey image"); // Event for lost video signal can be called from here event(cnt, EVENT_CAMERA_LOST, NULL, NULL, NULL, cnt->currenttime_tm); @@ -1470,8 +1461,8 @@ static void *motion_loop(void *arg) */ if ((cnt->video_dev > 0) && (cnt->missing_frame_counter == (MISSING_FRAMES_TIMEOUT * 4) * cnt->conf.frame_limit)) { - motion_log(ERR, TYPE_ALL, NO_ERRNO, "%s: Video signal still lost - " - "Trying to close video device",__FUNCTION__); + MOTION_LOG(ERR, TYPE_ALL, NO_ERRNO, "%s: Video signal still lost - " + "Trying to close video device"); vid_close(cnt); } } @@ -1510,8 +1501,7 @@ static void *motion_loop(void *arg) */ if (cnt->conf.lightswitch && !cnt->lost_connection) { if (alg_lightswitch(cnt, cnt->current_image->diffs)) { - motion_log(DBG, TYPE_ALL, NO_ERRNO, "%s: Lightswitch detected", - __FUNCTION__); + MOTION_LOG(DBG, TYPE_ALL, NO_ERRNO, "%s: Lightswitch detected"); if (cnt->moved < 5) cnt->moved = 5; @@ -1537,8 +1527,7 @@ static void *motion_loop(void *arg) if (cnt->current_image->diffs <= cnt->threshold) { cnt->current_image->diffs = 0; - motion_log(DBG, TYPE_ALL, NO_ERRNO, "%s: Switchfilter detected", - __FUNCTION__); + MOTION_LOG(DBG, TYPE_ALL, NO_ERRNO, "%s: Switchfilter detected"); } } @@ -1640,8 +1629,7 @@ static void *motion_loop(void *arg) cnt->current_image->diffs = 0; cnt->lightswitch_framecounter = 0; - motion_log(DBG, TYPE_ALL, NO_ERRNO, "%s: micro-lightswitch!", - __FUNCTION__); + MOTION_LOG(DBG, TYPE_ALL, NO_ERRNO, "%s: micro-lightswitch!"); } else { alg_update_reference_frame(cnt, UPDATE_REF_FRAME); } @@ -1750,7 +1738,7 @@ static void *motion_loop(void *arg) */ if (cnt->conf.emulate_motion && (cnt->startup_frames == 0)) { cnt->detecting_motion = 1; - motion_log(DBG, TYPE_ALL, NO_ERRNO, "%s: Emulating motion %d", __FUNCTION__); + MOTION_LOG(DBG, TYPE_ALL, NO_ERRNO, "%s: Emulating motion"); #ifdef HAVE_FFMPEG if (cnt->ffmpeg_output || (cnt->conf.useextpipe && cnt->extpipe)) { #else @@ -1758,8 +1746,8 @@ static void *motion_loop(void *arg) #endif /* Setup the postcap counter */ cnt->postcap = cnt->conf.post_capture; - motion_log(DBG, TYPE_ALL, NO_ERRNO, "%s: (Em) Init post capture %d", - __FUNCTION__, cnt->postcap); + MOTION_LOG(DBG, TYPE_ALL, NO_ERRNO, "%s: (Em) Init post capture %d", + cnt->postcap); } cnt->current_image->flags |= (IMAGE_TRIGGER | IMAGE_SAVE); @@ -1795,8 +1783,8 @@ static void *motion_loop(void *arg) #endif /* Setup the postcap counter */ cnt->postcap = cnt->conf.post_capture; - motion_log(DBG, TYPE_ALL, NO_ERRNO, "%s: Setup post capture %d", - __FUNCTION__, cnt->postcap); + MOTION_LOG(DBG, TYPE_ALL, NO_ERRNO, "%s: Setup post capture %d", + cnt->postcap); } /* Mark all images in image_ring to be saved */ for (i = 0; i < cnt->imgs.image_ring_size; i++) @@ -1811,8 +1799,8 @@ static void *motion_loop(void *arg) /* we have motion in this frame, but not enought frames for trigger. Check postcap */ cnt->current_image->flags |= (IMAGE_POSTCAP | IMAGE_SAVE); cnt->postcap--; - motion_log(DBG, TYPE_ALL, NO_ERRNO, "%s: post capture %d", - __FUNCTION__, cnt->postcap); + MOTION_LOG(DBG, TYPE_ALL, NO_ERRNO, "%s: post capture %d", + cnt->postcap); } else { cnt->current_image->flags |= IMAGE_PRECAP; } @@ -1861,8 +1849,8 @@ static void *motion_loop(void *arg) NULL, cnt->currenttime_tm); area_once = cnt->event_nr; /* Fire script only once per event */ - motion_log(DBG, TYPE_ALL, NO_ERRNO, "%s: Motion in area %d detected.", - __FUNCTION__, z + 1); + MOTION_LOG(DBG, TYPE_ALL, NO_ERRNO, "%s: Motion in area %d detected.", + z + 1); break; } } @@ -1903,8 +1891,8 @@ static void *motion_loop(void *arg) if (cnt->track.type) cnt->moved = track_center(cnt, cnt->video_dev, 0, 0, 0); - motion_log(DBG, TYPE_ALL, NO_ERRNO, "%s: End of event %d", - __FUNCTION__, cnt->event_nr); + MOTION_LOG(DBG, TYPE_ALL, NO_ERRNO, "%s: End of event %d", + cnt->event_nr); cnt->makemovie = 0; /* Reset post capture */ @@ -1955,7 +1943,7 @@ static void *motion_loop(void *arg) strcat(msg, part); } - motion_log(EMG, TYPE_ALL, NO_ERRNO, "%s", msg); + MOTION_LOG(EMG, TYPE_ALL, NO_ERRNO, "%s: %s", msg); } } /* get_image end */ @@ -2029,10 +2017,9 @@ static void *motion_loop(void *arg) &cnt->current_image->timestamp_tm); /* If invalid we report in syslog once and continue in manual mode */ } else { - motion_log(ERR, TYPE_ALL, NO_ERRNO, "%s: Invalid timelapse_mode argument '%s'", - __FUNCTION__, cnt->conf.timelapse_mode); - motion_log(ERR, TYPE_ALL, NO_ERRNO, "%:s Defaulting to manual timelapse mode", - __FUNCTION__); + MOTION_LOG(ERR, TYPE_ALL, NO_ERRNO, "%s: Invalid timelapse_mode argument '%s'", + cnt->conf.timelapse_mode); + MOTION_LOG(ERR, TYPE_ALL, NO_ERRNO, "%:s Defaulting to manual timelapse mode"); conf_cmdparse(&cnt, (char *)"ffmpeg_timelapse_mode",(char *)"manual"); } } @@ -2219,7 +2206,7 @@ static void *motion_loop(void *arg) free(rolling_average_data); cnt->lost_connection = 1; - motion_log(EMG, TYPE_ALL, NO_ERRNO, "%s: Thread exiting", __FUNCTION__); + MOTION_LOG(EMG, TYPE_ALL, NO_ERRNO, "%s: Thread exiting"); motion_cleanup(cnt); @@ -2268,7 +2255,7 @@ static void become_daemon(void) /* fork */ if (fork()) { - motion_log(EMG, TYPE_ALL, NO_ERRNO, "%s: Motion going to daemon mode", __FUNCTION__); + MOTION_LOG(EMG, TYPE_ALL, NO_ERRNO, "%s: Motion going to daemon mode"); exit(0); } @@ -2285,8 +2272,8 @@ static void become_daemon(void) (void)fprintf(pidf, "%d\n", getpid()); myfclose(pidf); } else { - motion_log(EMG, TYPE_ALL, SHOW_ERRNO, "%s: Exit motion, cannot create process" - " id file (pid file) %s", __FUNCTION__, cnt_list[0]->conf.pid_file); + MOTION_LOG(EMG, TYPE_ALL, SHOW_ERRNO, "%s: Exit motion, cannot create process" + " id file (pid file) %s", cnt_list[0]->conf.pid_file); if (ptr_logfile) myfclose(ptr_logfile); exit(0); @@ -2298,7 +2285,7 @@ static void become_daemon(void) * without having to stop Motion */ if (chdir("/")) - motion_log(ERR, TYPE_ALL, SHOW_ERRNO, "%s: Could not change directory", __FUNCTION__); + MOTION_LOG(ERR, TYPE_ALL, SHOW_ERRNO, "%s: Could not change directory"); #if (defined(BSD)) @@ -2331,8 +2318,8 @@ static void become_daemon(void) /* Now it is safe to add the PID creation to the logs */ if (pidf) - motion_log(ERR, TYPE_ALL, NO_ERRNO, "%s: Created process id file %s. Process ID is %d", - __FUNCTION__, cnt_list[0]->conf.pid_file, getpid()); + MOTION_LOG(ERR, TYPE_ALL, NO_ERRNO, "%s: Created process id file %s. Process ID is %d", + cnt_list[0]->conf.pid_file, getpid()); sigaction(SIGTTOU, &sig_ign_action, NULL); sigaction(SIGTTIN, &sig_ign_action, NULL); @@ -2440,13 +2427,13 @@ static void motion_startup(int daemonize, int argc, char *argv[]) (cnt_list[0]->conf.log_level == 0)) { cnt_list[0]->conf.log_level = LEVEL_DEFAULT; debug_level = cnt_list[0]->conf.log_level; - motion_log(ERR, TYPE_ALL, NO_ERRNO, "%s: Using default log level (%s) (%d)", - __FUNCTION__, get_log_level_str(debug_level), SHOW_LEVEL_VALUE(debug_level)); + MOTION_LOG(ERR, TYPE_ALL, NO_ERRNO, "%s: Using default log level (%s) (%d)", + get_log_level_str(debug_level), SHOW_LEVEL_VALUE(debug_level)); } set_log_level(debug_level); - motion_log(EMG, TYPE_ALL, NO_ERRNO, "%s: Motion "VERSION" Started", __FUNCTION__); + MOTION_LOG(EMG, TYPE_ALL, NO_ERRNO, "%s: Motion "VERSION" Started"); if ((cnt_list[0]->conf.log_file) && (strncmp(cnt_list[0]->conf.log_file, "syslog", 6))) { set_log_mode(LOGMODE_FILE); @@ -2454,25 +2441,25 @@ static void motion_startup(int daemonize, int argc, char *argv[]) if (ptr_logfile) { set_log_mode(LOGMODE_SYSLOG); - motion_log(ERR, TYPE_ALL, NO_ERRNO, "%s: Logging to file (%s)", __FUNCTION__, + MOTION_LOG(ERR, TYPE_ALL, NO_ERRNO, "%s: Logging to file (%s)", cnt_list[0]->conf.log_file); set_log_mode(LOGMODE_FILE); } else { - motion_log(EMG, TYPE_ALL, SHOW_ERRNO, "%s: Exit motion, cannot create log file %s", - __FUNCTION__, cnt_list[0]->conf.log_file); + MOTION_LOG(EMG, TYPE_ALL, SHOW_ERRNO, "%s: Exit motion, cannot create log file %s", + cnt_list[0]->conf.log_file); exit(0); } } else { - motion_log(ERR, TYPE_ALL, NO_ERRNO, "%s: Logging to syslog", __FUNCTION__); + MOTION_LOG(ERR, TYPE_ALL, NO_ERRNO, "%s: Logging to syslog"); } if (!(debug_type = get_log_type(cnt_list[0]->conf.log_type_str))) { debug_type = TYPE_DEFAULT; - motion_log(ERR, TYPE_ALL, NO_ERRNO, "%s: Using default log type (%s)", __FUNCTION__, + MOTION_LOG(ERR, TYPE_ALL, NO_ERRNO, "%s: Using default log type (%s)", get_log_type_str(debug_type)); } - motion_log(ERR, TYPE_ALL, NO_ERRNO, "%s: Using log type (%s) log level (%s)", __FUNCTION__, + MOTION_LOG(ERR, TYPE_ALL, NO_ERRNO, "%s: Using log type (%s) log level (%s)", get_log_type_str(debug_type), get_log_level_str(debug_level)); set_log_type(debug_type); @@ -2486,7 +2473,7 @@ static void motion_startup(int daemonize, int argc, char *argv[]) */ if (cnt_list[0]->daemon && cnt_list[0]->conf.setup_mode == 0) { become_daemon(); - motion_log(EMG, TYPE_ALL, NO_ERRNO, "%s: Motion running as daemon process", __FUNCTION__); + MOTION_LOG(EMG, TYPE_ALL, NO_ERRNO, "%s: Motion running as daemon process"); } } @@ -2559,11 +2546,11 @@ static void start_motion_thread(struct context *cnt, pthread_attr_t *thread_attr if (cnt->conf.stream_port != 0) { /* Compare against the control port. */ if (cnt_list[0]->conf.webcontrol_port == cnt->conf.stream_port) { - motion_log(ERR, TYPE_ALL, NO_ERRNO, + MOTION_LOG(ERR, TYPE_ALL, NO_ERRNO, "%s: Stream port number %d for thread %d conflicts with the control port", - __FUNCTION__, cnt->conf.stream_port, cnt->threadnr); - motion_log(ERR, TYPE_ALL, NO_ERRNO, "%s: Stream feature for thread %d is disabled.", - __FUNCTION__, cnt->threadnr); + cnt->conf.stream_port, cnt->threadnr); + MOTION_LOG(ERR, TYPE_ALL, NO_ERRNO, "%s: Stream feature for thread %d is disabled.", + cnt->threadnr); cnt->conf.stream_port = 0; } @@ -2573,12 +2560,12 @@ static void start_motion_thread(struct context *cnt, pthread_attr_t *thread_attr continue; if (cnt_list[i]->conf.stream_port == cnt->conf.stream_port) { - motion_log(ERR, TYPE_ALL, NO_ERRNO, + MOTION_LOG(ERR, TYPE_ALL, NO_ERRNO, "%s: Stream port number %d for thread %d conflicts with thread %d", - __FUNCTION__, cnt->conf.stream_port, cnt->threadnr, cnt_list[i]->threadnr); - motion_log(ERR, TYPE_ALL, NO_ERRNO, + cnt->conf.stream_port, cnt->threadnr, cnt_list[i]->threadnr); + MOTION_LOG(ERR, TYPE_ALL, NO_ERRNO, "%s: Stream feature for thread %d is disabled.", - __FUNCTION__, cnt->threadnr); + cnt->threadnr); cnt->conf.stream_port = 0; } } @@ -2651,7 +2638,7 @@ int main (int argc, char **argv) * optimize motion detection and stuff. */ if (cnt_list[0]->conf.setup_mode) - motion_log(EMG, TYPE_ALL, NO_ERRNO, "%s: Motion running in setup mode.", __FUNCTION__); + MOTION_LOG(EMG, TYPE_ALL, NO_ERRNO, "%s: Motion running in setup mode."); /* * Create and a thread attribute for the threads we spawn later on. @@ -2671,14 +2658,14 @@ int main (int argc, char **argv) * cleanup everything, and then initialize everything again * (including re-reading the config file(s)). */ - motion_log(ERR, TYPE_ALL, NO_ERRNO, "%s: Restarting motion.", __FUNCTION__); + MOTION_LOG(ERR, TYPE_ALL, NO_ERRNO, "%s: Restarting motion."); motion_shutdown(); restart = 0; /* only one reset for now */ #ifndef WITHOUT_V4L SLEEP(5, 0); // maybe some cameras needs less time #endif motion_startup(0, argc, argv); /* 0 = skip daemon init */ - motion_log(ERR, TYPE_ALL, NO_ERRNO, "%s: Motion restarted", __FUNCTION__); + MOTION_LOG(ERR, TYPE_ALL, NO_ERRNO, "%s: Motion restarted"); } /* @@ -2690,16 +2677,16 @@ int main (int argc, char **argv) cnt_list[i]->threadnr = i ? i : 1; if (strcmp(cnt_list[i]->conf_filename, "")) - motion_log(ERR, TYPE_ALL, NO_ERRNO, "%s: Thread %d is from %s", - __FUNCTION__, cnt_list[i]->threadnr, cnt_list[i]->conf_filename); + MOTION_LOG(ERR, TYPE_ALL, NO_ERRNO, "%s: Thread %d is from %s", + cnt_list[i]->threadnr, cnt_list[i]->conf_filename); - motion_log(DBG, TYPE_ALL, NO_ERRNO, "%s: Thread %d is device: %s input %d", - __FUNCTION__, cnt_list[i]->threadnr, cnt_list[i]->conf.netcam_url ? + MOTION_LOG(DBG, TYPE_ALL, NO_ERRNO, "%s: Thread %d is device: %s input %d", + cnt_list[i]->threadnr, cnt_list[i]->conf.netcam_url ? cnt_list[i]->conf.netcam_url : cnt_list[i]->conf.video_device, cnt_list[i]->conf.netcam_url ? -1 : cnt_list[i]->conf.input); - motion_log(DBG, TYPE_ALL, NO_ERRNO, "%s: Stream port %d", - __FUNCTION__, cnt_list[i]->conf.stream_port); + MOTION_LOG(DBG, TYPE_ALL, NO_ERRNO, "%s: Stream port %d", + cnt_list[i]->conf.stream_port); start_motion_thread(cnt_list[i], &thread_attr); } @@ -2711,8 +2698,8 @@ int main (int argc, char **argv) if (cnt_list[0]->conf.webcontrol_port) pthread_create(&thread_id, &thread_attr, &motion_web_control, cnt_list); - motion_log(DBG, TYPE_ALL, NO_ERRNO, "%s: Waiting for threads to finish, pid: %d", - __FUNCTION__, getpid()); + MOTION_LOG(DBG, TYPE_ALL, NO_ERRNO, "%s: Waiting for threads to finish, pid: %d", + getpid()); /* * Crude way of waiting for all threads to finish - check the thread @@ -2734,16 +2721,16 @@ int main (int argc, char **argv) if (((motion_threads_running == 0) && finish) || ((motion_threads_running == 0) && (threads_running == 0))) { - motion_log(DBG, TYPE_ALL, NO_ERRNO, "%s: DEBUG-1 threads_running %d motion_threads_running %d " - ", finish %d", __FUNCTION__, threads_running, motion_threads_running, finish); + MOTION_LOG(DBG, TYPE_ALL, NO_ERRNO, "%s: DEBUG-1 threads_running %d motion_threads_running %d " + ", finish %d", threads_running, motion_threads_running, finish); break; } for (i = (cnt_list[1] != NULL ? 1 : 0); cnt_list[i]; i++) { /* Check if threads wants to be restarted */ if ((!cnt_list[i]->running) && (cnt_list[i]->restart)) { - motion_log(ERR, TYPE_ALL, NO_ERRNO, "%s: Motion thread %d restart", - __FUNCTION__, cnt_list[i]->threadnr); + MOTION_LOG(ERR, TYPE_ALL, NO_ERRNO, "%s: Motion thread %d restart", + cnt_list[i]->threadnr); start_motion_thread(cnt_list[i], &thread_attr); } @@ -2751,14 +2738,14 @@ int main (int argc, char **argv) cnt_list[i]->watchdog--; if (cnt_list[i]->watchdog == 0) { - motion_log(ERR, TYPE_ALL, NO_ERRNO, "%s: Thread %d - Watchdog timeout, trying to do " - "a graceful restart", __FUNCTION__, cnt_list[i]->threadnr); + MOTION_LOG(ERR, TYPE_ALL, NO_ERRNO, "%s: Thread %d - Watchdog timeout, trying to do " + "a graceful restart", cnt_list[i]->threadnr); cnt_list[i]->finish = 1; } if (cnt_list[i]->watchdog == -60) { - motion_log(ERR, TYPE_ALL, NO_ERRNO, "%s: Thread %d - Watchdog timeout, did NOT restart graceful," - "killing it!", __FUNCTION__, cnt_list[i]->threadnr); + MOTION_LOG(ERR, TYPE_ALL, NO_ERRNO, "%s: Thread %d - Watchdog timeout, did NOT restart graceful," + "killing it!", cnt_list[i]->threadnr); pthread_cancel(cnt_list[i]->thread_id); pthread_mutex_lock(&global_lock); threads_running--; @@ -2770,13 +2757,13 @@ int main (int argc, char **argv) } } - motion_log(DBG, TYPE_ALL, NO_ERRNO, "%s: DEBUG-2 threads_running %d motion_threads_running %d finish %d", - __FUNCTION__, threads_running, motion_threads_running, finish); + MOTION_LOG(DBG, TYPE_ALL, NO_ERRNO, "%s: DEBUG-2 threads_running %d motion_threads_running %d finish %d", + threads_running, motion_threads_running, finish); } /* Reset end main loop flag */ finish = 0; - motion_log(DBG, TYPE_ALL, NO_ERRNO, "%s: Threads finished", __FUNCTION__); + MOTION_LOG(DBG, TYPE_ALL, NO_ERRNO, "%s: Threads finished"); /* Rest for a while if we're supposed to restart. */ if (restart) @@ -2787,7 +2774,7 @@ int main (int argc, char **argv) // Be sure that http control exits fine cnt_list[0]->finish = 1; SLEEP(1, 0); - motion_log(EMG, TYPE_ALL, NO_ERRNO, "%s: Motion terminating", __FUNCTION__); + MOTION_LOG(EMG, TYPE_ALL, NO_ERRNO, "%s: Motion terminating"); /* Perform final cleanup. */ pthread_key_delete(tls_key_threadnr); @@ -2822,8 +2809,8 @@ void * mymalloc(size_t nbytes) void *dummy = malloc(nbytes); if (!dummy) { - motion_log(EMG, TYPE_ALL, SHOW_ERRNO, "%s: Could not allocate %llu bytes of memory!", - __FUNCTION__, (unsigned long long)nbytes); + MOTION_LOG(EMG, TYPE_ALL, SHOW_ERRNO, "%s: Could not allocate %llu bytes of memory!", + (unsigned long long)nbytes); motion_remove_pid(); exit(1); } @@ -2853,15 +2840,15 @@ void *myrealloc(void *ptr, size_t size, const char *desc) if (size == 0) { free(ptr); - motion_log(WRN, TYPE_ALL, NO_ERRNO, + MOTION_LOG(WRN, TYPE_ALL, NO_ERRNO, "%s: Warning! Function %s tries to resize memoryblock at %p to 0 bytes!", - __FUNCTION__, desc, ptr); + desc, ptr); } else { dummy = realloc(ptr, size); if (!dummy) { - motion_log(EMG, TYPE_ALL, NO_ERRNO, + MOTION_LOG(EMG, TYPE_ALL, NO_ERRNO, "%s: Could not resize memory-block at offset %p to %llu bytes (function %s)!", - __FUNCTION__, ptr, (unsigned long long)size, desc); + ptr, (unsigned long long)size, desc); motion_remove_pid(); exit(1); } @@ -2901,8 +2888,8 @@ int create_path(const char *path) buffer[start-path] = 0x00; if (mkdir(buffer, mode) == -1 && errno != EEXIST) { - motion_log(ERR, TYPE_ALL, SHOW_ERRNO, "%s: Problem creating directory %s", - __FUNCTION__, buffer); + MOTION_LOG(ERR, TYPE_ALL, SHOW_ERRNO, "%s: Problem creating directory %s", + buffer); free(buffer); return -1; } @@ -2910,7 +2897,7 @@ int create_path(const char *path) start = strchr(start + 1, '/'); if (!start) - motion_log(ERR, TYPE_ALL, NO_ERRNO, "%s: creating directory %s", __FUNCTION__, buffer); + MOTION_LOG(ERR, TYPE_ALL, NO_ERRNO, "%s: creating directory %s", buffer); free(buffer); } @@ -3025,8 +3012,8 @@ FILE * myfopen(const char *path, const char *mode, size_t bufsize) * first time * 2: could still not open the file after the path was created */ - motion_log(ERR, TYPE_ALL, SHOW_ERRNO, "%s: Error opening file %s with mode %s", - __FUNCTION__, path, mode); + MOTION_LOG(ERR, TYPE_ALL, SHOW_ERRNO, "%s: Error opening file %s with mode %s", + path, mode); } return dummy; diff --git a/netcam.c b/netcam.c index 057f3ff..5b2e880 100644 --- a/netcam.c +++ b/netcam.c @@ -46,17 +46,17 @@ #include "netcam_ftp.h" -#define CONNECT_TIMEOUT 10 /* timeout on remote connection attempt */ -#define READ_TIMEOUT 5 /* default timeout on recv requests */ -#define POLLING_TIMEOUT READ_TIMEOUT /* file polling timeout [s] */ -#define POLLING_TIME 500*1000*1000 /* file polling time quantum [ns] (500ms) */ +#define CONNECT_TIMEOUT 10 /* Timeout on remote connection attempt */ +#define READ_TIMEOUT 5 /* Default timeout on recv requests */ +#define POLLING_TIMEOUT READ_TIMEOUT /* File polling timeout [s] */ +#define POLLING_TIME 500*1000*1000 /* File polling time quantum [ns] (500ms) */ #define MAX_HEADER_RETRIES 5 /* Max tries to find a header record */ #define MINVAL(x, y) ((x) < (y) ? (x) : (y)) tfile_context *file_new_context(void); void file_free_context(tfile_context* ctxt); -/* These strings are used for the HTTP connection */ +/* These strings are used for the HTTP connection. */ static const char *connect_req; static const char *connect_req_http10 = "GET %s HTTP/1.0\r\n" @@ -155,8 +155,8 @@ static void netcam_url_parse(struct url_t *parse_url, const char *text_url) re = "(file)://(((.*):(.*))@)?" "([^/:]|[-.a-z0-9]*)(:([0-9]*))?($|(/[^:][/-_.a-z0-9]+))"; - motion_log(DBG, TYPE_NETCAM, NO_ERRNO, "%s: Entry netcam_url_parse data %s", - __FUNCTION__, text_url); + MOTION_LOG(DBG, TYPE_NETCAM, NO_ERRNO, "%s: Entry netcam_url_parse data %s", + text_url); memset(parse_url, 0, sizeof(struct url_t)); /* @@ -164,14 +164,14 @@ static void netcam_url_parse(struct url_t *parse_url, const char *text_url) * suitable for regexec searches * regexec matches the URL string against the regular expression * and returns an array of pointers to strings matching each match - * within (). The results that we need are finally placed in parse_url + * within (). The results that we need are finally placed in parse_url. */ if (!regcomp(&pattbuf, re, REG_EXTENDED | REG_ICASE)) { if (regexec(&pattbuf, text_url, 10, matches, 0) != REG_NOMATCH) { for (i = 0; i < 10; i++) { if ((s = netcam_url_match(matches[i], text_url)) != NULL) { - motion_log(DBG, TYPE_NETCAM, NO_ERRNO, "%s: Parse case %d" - " data %s", __FUNCTION__, i, s); + MOTION_LOG(DBG, TYPE_NETCAM, NO_ERRNO, "%s: Parse case %d" + " data %s", i, s); switch (i) { case 1: parse_url->service = s; @@ -189,7 +189,7 @@ static void netcam_url_parse(struct url_t *parse_url, const char *text_url) case 9: parse_url->path = s; break; - /* other components ignored */ + /* Other components ignored */ default: free(s); break; @@ -215,7 +215,7 @@ static void netcam_url_parse(struct url_t *parse_url, const char *text_url) * * Parameters: * - * parse_url Structure containing the parsed data + * parse_url Structure containing the parsed data. * * Returns: Nothing * @@ -251,9 +251,9 @@ static void netcam_url_free(struct url_t *parse_url) * * Parameters: * - * str Pointer to a string + * str Pointer to a string. * - * Returns: Nothing, but updates the target if necessary + * Returns: Nothing, but updates the target if necessary. * */ static void check_quote(char *str) @@ -275,20 +275,20 @@ static void check_quote(char *str) /** * netcam_check_content_length * - * Analyse an HTTP-header line to see if it is a Content-length + * Analyse an HTTP-header line to see if it is a Content-length. * * Parameters: * - * header Pointer to a string containing the header line + * header Pointer to a string containing the header line. * * Returns: - * -1 Not a Content-length line - * >=0 Value of Content-length field + * -1 Not a Content-length line. + * >=0 Value of Content-length field. * */ static long netcam_check_content_length(char *header) { - long length = -1; /* note this is a long, not an int */ + long length = -1; /* Note this is a long, not an int. */ if (!header_process(header, "Content-Length", header_extract_number, &length)) { /* @@ -297,12 +297,12 @@ static long netcam_check_content_length(char *header) * number we might as well try to use it. */ if (length > 0) - motion_log(INF, TYPE_NETCAM, NO_ERRNO, "%s: malformed token" - " Content-Length but value %ld", __FUNCTION__, length); + MOTION_LOG(WRN, TYPE_NETCAM, NO_ERRNO, "%s: malformed token" + " Content-Length but value %ld", length); } - motion_log(INF, TYPE_NETCAM, NO_ERRNO, "%s: Content-Length %ld", - __FUNCTION__, length); + MOTION_LOG(INF, TYPE_NETCAM, NO_ERRNO, "%s: Content-Length %ld", + length); return length; } @@ -314,11 +314,11 @@ static long netcam_check_content_length(char *header) * * Parameters: * - * header Pointer to a string containing the header line + * header Pointer to a string containing the header line. * * Returns: - * -1 Not a Keep-Alive line - * 1 Is a Keep-Alive line + * -1 Not a Keep-Alive line. + * 1 Is a Keep-Alive line. * */ static int netcam_check_keepalive(char *header) @@ -329,7 +329,6 @@ static int netcam_check_keepalive(char *header) return -1; /* We do not detect the second field or other case mixes at present. */ - if (content_type) free(content_type); @@ -339,15 +338,15 @@ static int netcam_check_keepalive(char *header) /** * netcam_check_close * - * Analyse an HTTP-header line to see if it is a Connection: close + * Analyse an HTTP-header line to see if it is a Connection: close. * * Parameters: * - * header Pointer to a string containing the header line + * header Pointer to a string containing the header line. * * Returns: - * -1 Not a Connection: close - * 1 Is a Connection: close + * -1 Not a Connection: close. + * 1 Is a Connection: close. * */ static int netcam_check_close(char *header) @@ -358,7 +357,7 @@ static int netcam_check_close(char *header) 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; if (type) @@ -370,11 +369,11 @@ static int netcam_check_close(char *header) /** * netcam_check_content_type * - * Analyse an HTTP-header line to see if it is a Content-type + * Analyse an HTTP-header line to see if it is a Content-type. * * Parameters: * - * header Pointer to a string containing the header line + * header Pointer to a string containing the header line. * * Returns: * -1 Not a Content-type line @@ -392,8 +391,8 @@ static int netcam_check_content_type(char *header) if (!header_process(header, "Content-type", http_process_type, &content_type)) return -1; - motion_log(INF, TYPE_NETCAM, NO_ERRNO, "%s: Content-type %s", - __FUNCTION__, content_type); + MOTION_LOG(INF, TYPE_NETCAM, NO_ERRNO, "%s: Content-type %s", + content_type); if (!strcmp(content_type, "image/jpeg")) { ret = 1; @@ -420,9 +419,9 @@ static int netcam_check_content_type(char *header) * * Parameters * - * netcam pointer to a netcam_context + * netcam pointer to a netcam_context. * - * Returns: 0 for success, -1 if any error + * Returns: 0 for success, -1 if any error. * */ static int netcam_read_next_header(netcam_context_ptr netcam) @@ -445,22 +444,22 @@ static int netcam_read_next_header(netcam_context_ptr netcam) /* * If this is a "streaming" camera, the stream header must be - * preceded by a "boundary" string + * preceded by a "boundary" string. */ if (netcam->caps.streaming == NCS_MULTIPART) { while (1) { retval = header_get(netcam, &header, HG_NONE); if (retval != HG_OK) { - /* Header reported as not-OK, check to see if it's null */ + /* Header reported as not-OK, check to see if it's null. */ if (strlen(header) == 0) { - motion_log(WRN, TYPE_NETCAM, NO_ERRNO, "%s: Error reading image header, " - "streaming mode (1). Null header.", __FUNCTION__); + MOTION_LOG(WRN, TYPE_NETCAM, NO_ERRNO, "%s: Error reading image header, " + "streaming mode (1). Null header."); } else { /* Header is not null. Output it in case it's a new camera with unknown headers. */ - motion_log(WRN, TYPE_NETCAM, NO_ERRNO, "%s: Error reading image header, " + MOTION_LOG(WRN, TYPE_NETCAM, NO_ERRNO, "%s: Error reading image header, " "streaming mode (1). Unknown header '%s'", - __FUNCTION__, header); + header); } free(header); @@ -479,8 +478,7 @@ static int netcam_read_next_header(netcam_context_ptr netcam) retval = header_get(netcam, &header, HG_NONE); if (retval != HG_OK) { - motion_log(ERR, TYPE_NETCAM, NO_ERRNO, "%s: Error reading image header (2)", - __FUNCTION__); + MOTION_LOG(ERR, TYPE_NETCAM, NO_ERRNO, "%s: Error reading image header (2)"); free(header); return -1; } @@ -490,8 +488,7 @@ static int netcam_read_next_header(netcam_context_ptr netcam) if ((retval = netcam_check_content_type(header)) >= 0) { if (retval != 1) { - motion_log(ERR, TYPE_NETCAM, NO_ERRNO, "%s: Header not JPEG", - __FUNCTION__); + MOTION_LOG(ERR, TYPE_NETCAM, NO_ERRNO, "%s: Header not JPEG"); free(header); return -1; } @@ -499,12 +496,11 @@ static int netcam_read_next_header(netcam_context_ptr netcam) if ((retval = (int) netcam_check_content_length(header)) >= 0) { if (retval > 0) { - netcam->caps.content_length = 1; /* set flag */ + netcam->caps.content_length = 1; /* Set flag */ netcam->receiving->content_length = retval; } else { netcam->receiving->content_length = 0; - motion_log(ERR, TYPE_NETCAM, NO_ERRNO, "%s: Content-Length 0", - __FUNCTION__); + MOTION_LOG(ERR, TYPE_NETCAM, NO_ERRNO, "%s: Content-Length 0"); free(header); return -1; } @@ -513,8 +509,7 @@ static int netcam_read_next_header(netcam_context_ptr netcam) free(header); } - motion_log(INF, TYPE_NETCAM, NO_ERRNO, "%s: Found image header record", - __FUNCTION__); + MOTION_LOG(INF, TYPE_NETCAM, NO_ERRNO, "%s: Found image header record"); free(header); return 0; @@ -537,26 +532,26 @@ static int netcam_read_next_header(netcam_context_ptr netcam) * After this processing, the routine returns to the caller. * * Parameters: - * netcam Pointer to the netcam_context structure + * netcam Pointer to the netcam_context structure. * * Returns: Content-type code if successful, -1 if not * -2 if Content-length = 0 */ static int netcam_read_first_header(netcam_context_ptr netcam) { - int retval = -3; /* "Unknown err" */ + int retval = -3; /* "Unknown err" */ int ret; int firstflag = 1; - int aliveflag = 0; /* If we have seen a Keep-Alive header from cam */ - int closeflag = 0; /* If we have seen a Connection: close header from cam */ + int aliveflag = 0; /* If we have seen a Keep-Alive header from cam. */ + int closeflag = 0; /* If we have seen a Connection: close header from cam. */ char *header; char *boundary; - /* Send the initial command to the camera */ + /* Send the initial command to the camera. */ if (send(netcam->sock, netcam->connect_request, strlen(netcam->connect_request), 0) < 0) { - motion_log(ERR, TYPE_NETCAM, SHOW_ERRNO, "%s: Error sending" - " 'connect' request", __FUNCTION__); + MOTION_LOG(ERR, TYPE_NETCAM, SHOW_ERRNO, "%s: Error sending" + " 'connect' request"); return -1; } @@ -585,20 +580,20 @@ static int netcam_read_first_header(netcam_context_ptr netcam) while (1) { /* 'Do forever' */ ret = header_get(netcam, &header, HG_NONE); - motion_log(INF, TYPE_NETCAM, NO_ERRNO, "%s: Received first header ('%s')", - __FUNCTION__, header); + MOTION_LOG(INF, TYPE_NETCAM, NO_ERRNO, "%s: Received first header ('%s')", + header); if (ret != HG_OK) { - motion_log(WRN, TYPE_NETCAM, NO_ERRNO, "%s: Error reading first header (%s)", - __FUNCTION__, header); + MOTION_LOG(WRN, TYPE_NETCAM, NO_ERRNO, "%s: Error reading first header (%s)", + header); free(header); return -1; } if (firstflag) { if ((ret = http_result_code(header)) != 200) { - motion_log(INF, TYPE_NETCAM, NO_ERRNO, "%s: HTTP Result code %d", - __FUNCTION__, ret); + MOTION_LOG(INF, TYPE_NETCAM, NO_ERRNO, "%s: HTTP Result code %d", + ret); free(header); if (netcam->connect_keepalive) { @@ -606,13 +601,13 @@ static int netcam_read_first_header(netcam_context_ptr netcam) * Cannot unset netcam->cnt->conf.netcam_keepalive as it is assigned const * But we do unset the netcam keepalive flag which was set in netcam_start * This message is logged as Information as it would be useful to know - * if your netcam often returns bad HTTP result codes + * if your netcam often returns bad HTTP result codes. */ netcam->connect_keepalive = FALSE; free((void *)netcam->cnt->conf.netcam_keepalive); netcam->cnt->conf.netcam_keepalive = strdup("off"); - motion_log(NTC, TYPE_NETCAM, NO_ERRNO, "%s: Removed netcam Keep-Alive flag" - "due to apparent closed HTTP connection.", __FUNCTION__); + MOTION_LOG(NTC, TYPE_NETCAM, NO_ERRNO, "%s: Removed netcam Keep-Alive flag" + "due to apparent closed HTTP connection."); } return ret; } @@ -621,10 +616,10 @@ static 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 */ + /* Check if this line is the content type. */ if ((ret = netcam_check_content_type(header)) >= 0) { retval = ret; /* @@ -635,25 +630,24 @@ static int netcam_read_first_header(netcam_context_ptr netcam) * camera which provides a single frame only. */ switch (ret) { - case 1: /* not streaming */ + case 1: /* Not streaming */ if (netcam->connect_keepalive) - motion_log(NTC, TYPE_NETCAM, NO_ERRNO, "%s: Non-streaming camera " - "(keep-alive set)", __FUNCTION__); + MOTION_LOG(NTC, TYPE_NETCAM, NO_ERRNO, "%s: Non-streaming camera " + "(keep-alive set)"); else - motion_log(NTC, TYPE_NETCAM, NO_ERRNO, "%s: Non-streaming camera " - "(keep-alive not set)", __FUNCTION__); + MOTION_LOG(NTC, TYPE_NETCAM, NO_ERRNO, "%s: Non-streaming camera " + "(keep-alive not set)"); netcam->caps.streaming = NCS_UNSUPPORTED; break; - case 2: /* streaming */ - motion_log(INF, TYPE_NETCAM, NO_ERRNO, "%s: Streaming camera", - __FUNCTION__); + case 2: /* Streaming */ + MOTION_LOG(INF, TYPE_NETCAM, NO_ERRNO, "%s: Streaming camera"); netcam->caps.streaming = NCS_MULTIPART; if ((boundary = strstr(header, "boundary="))) { - /* On error recovery this may already be set */ + /* On error recovery this may already be set. */ if (netcam->boundary) free(netcam->boundary); @@ -662,41 +656,41 @@ static int netcam_read_first_header(netcam_context_ptr netcam) * HTTP protocol apparently permits the boundary string * to be quoted (the Lumenera does this, which caused * trouble) so we need to get rid of any surrounding - * quotes + * quotes. */ check_quote(netcam->boundary); netcam->boundary_length = strlen(netcam->boundary); - motion_log(INF, TYPE_NETCAM, NO_ERRNO, "%s: Boundary string [%s]", - __FUNCTION__, netcam->boundary); + MOTION_LOG(INF, TYPE_NETCAM, NO_ERRNO, "%s: Boundary string [%s]", + netcam->boundary); } break; - case 3: /* MJPG-Block style streaming */ - motion_log(NTC, TYPE_NETCAM, NO_ERRNO, "%s: Streaming camera probably using MJPG-blocks," - " consider using mjpg:// netcam_url.", __FUNCTION__); + case 3: /* MJPG-Block style streaming. */ + MOTION_LOG(NTC, TYPE_NETCAM, NO_ERRNO, "%s: Streaming camera probably using MJPG-blocks," + " consider using mjpg:// netcam_url."); break; default: - /* error */ - motion_log(ERR, TYPE_NETCAM, NO_ERRNO, "%s: Unrecognized content type", __FUNCTION__); + /* Error */ + MOTION_LOG(ERR, TYPE_NETCAM, NO_ERRNO, "%s: Unrecognized content type"); free(header); return -1; } } else if ((ret = (int) netcam_check_content_length(header)) >= 0) { - motion_log(NTC, TYPE_NETCAM, NO_ERRNO, "%s: Content-length present", __FUNCTION__); + MOTION_LOG(NTC, TYPE_NETCAM, NO_ERRNO, "%s: Content-length present"); if (ret > 0) { - netcam->caps.content_length = 1; /* set flag */ + netcam->caps.content_length = 1; /* Set flag */ netcam->receiving->content_length = ret; } else { netcam->receiving->content_length = 0; - motion_log(ERR, TYPE_NETCAM, NO_ERRNO, "%s: Content-length 0", __FUNCTION__); + MOTION_LOG(ERR, TYPE_NETCAM, NO_ERRNO, "%s: Content-length 0"); retval = -2; } } else if (netcam_check_keepalive(header) == TRUE) { - /* Note that we have received a Keep-Alive header, and thus the socket can be left open */ + /* Note that we have received a Keep-Alive header, and thus the socket can be left open. */ aliveflag = TRUE; netcam->keepalive_thisconn = TRUE; /* @@ -704,14 +698,14 @@ static int netcam_read_first_header(netcam_context_ptr netcam) * does not matter as the test below looks at Streaming state also. */ } else if (netcam_check_close(header) == TRUE) { - /* Note that we have received a Connection: close header */ + /* Note that we have received a Connection: close header. */ closeflag = TRUE; /* - * This flag is acted upon below - * Changed criterion and moved up from below to catch headers that cause returns + * This flag is acted upon below. + * Changed criterion and moved up from below to catch headers that cause returns. */ - motion_log(NTC, TYPE_NETCAM, NO_ERRNO, "%s: Found Conn: close header ('%s')", - __FUNCTION__, header); + MOTION_LOG(NTC, TYPE_NETCAM, NO_ERRNO, "%s: Found Conn: close header ('%s')", + header); } free(header); } @@ -719,39 +713,38 @@ static int netcam_read_first_header(netcam_context_ptr netcam) if (netcam->caps.streaming == NCS_UNSUPPORTED && netcam->connect_keepalive) { - /* If we are a non-streaming (ie. Jpeg) netcam and keepalive is configured */ + /* If we are a non-streaming (ie. Jpeg) netcam and keepalive is configured. */ if (aliveflag) { if (closeflag) { netcam->warning_count++; if (netcam->warning_count > 3) { netcam->warning_count = 0; - motion_log(INF, TYPE_NETCAM, NO_ERRNO, "%s: Both 'Connection: Keep-Alive' and " - "'Connection: close' header received. Motion removes keepalive.", - __FUNCTION__); + MOTION_LOG(INF, TYPE_NETCAM, NO_ERRNO, "%s: Both 'Connection: Keep-Alive' and " + "'Connection: close' header received. Motion removes keepalive."); netcam->connect_keepalive = FALSE; free((void *)netcam->cnt->conf.netcam_keepalive); netcam->cnt->conf.netcam_keepalive = strdup("off"); - } else + } else { /* * If not a streaming cam, and keepalive is set, and the flag shows we * did not see a Keep-Alive field returned from netcam and a Close field. * Not quite sure what the correct course of action is here. In for testing. */ - motion_log(INF, TYPE_NETCAM, NO_ERRNO, "%s: Both 'Connection: Keep-Alive' and " - "'Connection: close' header received. Motion continues unchanged.", - __FUNCTION__); + MOTION_LOG(INF, TYPE_NETCAM, NO_ERRNO, "%s: Both 'Connection: Keep-Alive' and " + "'Connection: close' header received. Motion continues unchanged."); + } } else { - /* - * aliveflag && !closeflag - * - * If not a streaming cam, and keepalive is set, and the flag shows we - * just got a Keep-Alive field returned from netcam and no Close field. - * No action, as this is the normal case. In debug we print a notification. - */ + /* + * aliveflag && !closeflag + * + * If not a streaming cam, and keepalive is set, and the flag shows we + * just got a Keep-Alive field returned from netcam and no Close field. + * No action, as this is the normal case. In debug we print a notification. + */ - motion_log(INF, TYPE_NETCAM, NO_ERRNO, "%s: Received a Keep-Alive field in this" - "set of headers.", __FUNCTION__); + MOTION_LOG(INF, TYPE_NETCAM, NO_ERRNO, "%s: Received a Keep-Alive field in this" + "set of headers."); } } else { /* !aliveflag */ if (!closeflag) { @@ -759,19 +752,20 @@ static int netcam_read_first_header(netcam_context_ptr netcam) if (netcam->warning_count > 3) { netcam->warning_count = 0; - motion_log(INF, TYPE_NETCAM, NO_ERRNO, "%s: No 'Connection: Keep-Alive' nor 'Connection: close'" - " header received.\n Motion removes keepalive.", __FUNCTION__); + MOTION_LOG(INF, TYPE_NETCAM, NO_ERRNO, "%s: No 'Connection: Keep-Alive' nor 'Connection: close'" + " header received.\n Motion removes keepalive."); netcam->connect_keepalive = FALSE; free((void *)netcam->cnt->conf.netcam_keepalive); netcam->cnt->conf.netcam_keepalive = strdup("off"); - } else + } else { /* * If not a streaming cam, and keepalive is set, and the flag shows we * did not see a Keep-Alive field returned from netcam nor a Close field. * Not quite sure what the correct course of action is here. In for testing. */ - motion_log(INF, TYPE_NETCAM, NO_ERRNO, "%s: No 'Connection: Keep-Alive' nor 'Connection: close'" - " header received.\n Motion continues unchanged.", __FUNCTION__); + MOTION_LOG(INF, TYPE_NETCAM, NO_ERRNO, "%s: No 'Connection: Keep-Alive' nor 'Connection: close'" + " header received.\n Motion continues unchanged."); + } } else { /* * !aliveflag & closeflag @@ -799,14 +793,13 @@ static int netcam_read_first_header(netcam_context_ptr netcam) netcam->connect_keepalive = FALSE; /* No further attempts at keep-alive */ free((void *)netcam->cnt->conf.netcam_keepalive); netcam->cnt->conf.netcam_keepalive = strdup("off"); - motion_log(INF, TYPE_NETCAM, NO_ERRNO, "%s: Removed netcam Keep-Alive flag because" + MOTION_LOG(INF, TYPE_NETCAM, NO_ERRNO, "%s: Removed netcam Keep-Alive flag because" " 'Connection: close' header received.\n Netcam does not support " - "Keep-Alive. Motion continues in non-Keep-Alive.", __FUNCTION__); + "Keep-Alive. Motion continues in non-Keep-Alive."); } else { netcam->keepalive_timeup = TRUE; /* We will close and re-open keep-alive */ - motion_log(INF, TYPE_NETCAM, NO_ERRNO, "Keep-Alive has reached end of valid period.\n" - "Motion will close netcam, then resume Keep-Alive with a new socket.", - __FUNCTION__); + MOTION_LOG(INF, TYPE_NETCAM, NO_ERRNO, "Keep-Alive has reached end of valid period.\n" + "Motion will close netcam, then resume Keep-Alive with a new socket."); } } } @@ -831,7 +824,7 @@ static void netcam_disconnect(netcam_context_ptr netcam) { if (netcam->sock > 0) { if (close(netcam->sock) < 0) - motion_log(ERR, TYPE_NETCAM, SHOW_ERRNO, "%s: netcam_disconnect", __FUNCTION__); + MOTION_LOG(ERR, TYPE_NETCAM, SHOW_ERRNO, "%s: netcam_disconnect"); netcam->sock = -1; } @@ -856,8 +849,8 @@ static void netcam_disconnect(netcam_context_ptr netcam) */ static int netcam_connect(netcam_context_ptr netcam, int err_flag) { - struct sockaddr_in server; /* for connect */ - struct addrinfo *res; /* for getaddrinfo */ + struct sockaddr_in server; /* For connect */ + struct addrinfo *res; /* For getaddrinfo */ int ret; int saveflags; int back_err; @@ -867,72 +860,69 @@ static int netcam_connect(netcam_context_ptr netcam, int err_flag) fd_set fd_w; struct timeval selecttime; - /* Assure any previous connection has been closed - IF we are not in keepalive */ + /* Assure any previous connection has been closed - IF we are not in keepalive. */ if (!netcam->connect_keepalive) { - motion_log(INF, TYPE_NETCAM, NO_ERRNO, "%s: disconnecting netcam " - "since keep-alive not set.", __FUNCTION__); + MOTION_LOG(INF, TYPE_NETCAM, NO_ERRNO, "%s: disconnecting netcam " + "since keep-alive not set."); netcam_disconnect(netcam); - /* create a new socket */ + /* Create a new socket. */ if ((netcam->sock = socket(PF_INET, SOCK_STREAM, 0)) < 0) { - motion_log(WRN, TYPE_NETCAM, SHOW_ERRNO, "%s: with no keepalive, attempt " - "to create socket failed.", __FUNCTION__); + MOTION_LOG(WRN, TYPE_NETCAM, SHOW_ERRNO, "%s: with no keepalive, attempt " + "to create socket failed."); return -1; } - motion_log(INF, TYPE_NETCAM, NO_ERRNO, "%s: with no keepalive, " - "new socket created fd %d", __FUNCTION__, netcam->sock); + MOTION_LOG(INF, TYPE_NETCAM, NO_ERRNO, "%s: with no keepalive, " + "new socket created fd %d",netcam->sock); - } else if (netcam->sock == -1) { /* We are in keepalive mode, check for invalid socket */ - /* Must be first time, or closed, create a new socket */ + } else if (netcam->sock == -1) { /* We are in keepalive mode, check for invalid socket. */ + /* Must be first time, or closed, create a new socket. */ if ((netcam->sock = socket(PF_INET, SOCK_STREAM, 0)) < 0) { - motion_log(WRN, TYPE_NETCAM, SHOW_ERRNO, "%s: with keepalive set, invalid socket." - "This could be the first time. Creating a new one failed.", - __FUNCTION__); + MOTION_LOG(WRN, TYPE_NETCAM, SHOW_ERRNO, "%s: with keepalive set, invalid socket." + "This could be the first time. Creating a new one failed."); return -1; } - motion_log(INF, TYPE_NETCAM, NO_ERRNO, "%s: with keepalive set, invalid socket." + MOTION_LOG(INF, TYPE_NETCAM, NO_ERRNO, "%s: with keepalive set, invalid socket." "This could be first time, created a new one with fd %d", - __FUNCTION__, netcam->sock); + netcam->sock); - /* Record that this connection has not yet received a Keep-Alive header */ + /* Record that this connection has not yet received a Keep-Alive header. */ netcam->keepalive_thisconn = FALSE; - /* Check the socket status for the keepalive option */ + /* Check the socket status for the keepalive option. */ if (getsockopt(netcam->sock, SOL_SOCKET, SO_KEEPALIVE, &optval, &optlen) < 0) { - motion_log(ERR, TYPE_NETCAM, SHOW_ERRNO, "%s: getsockopt()", __FUNCTION__); + MOTION_LOG(ERR, TYPE_NETCAM, SHOW_ERRNO, "%s: getsockopt()"); return -1; } - motion_log(INF, TYPE_NETCAM, NO_ERRNO, "%s: SO_KEEPALIVE is %s", - __FUNCTION__, optval ? "ON":"OFF"); + MOTION_LOG(INF, TYPE_NETCAM, NO_ERRNO, "%s: SO_KEEPALIVE is %s", + optval ? "ON":"OFF"); - /* Set the option active */ + /* Set the option active. */ optval = 1; optlen = sizeof(optval); if (setsockopt(netcam->sock, SOL_SOCKET, SO_KEEPALIVE, &optval, optlen) < 0) { - motion_log(ERR, TYPE_NETCAM, SHOW_ERRNO, "%s: setsockopt()", __FUNCTION__); + MOTION_LOG(ERR, TYPE_NETCAM, SHOW_ERRNO, "%s: setsockopt()"); return -1; } - motion_log(INF, TYPE_NETCAM, NO_ERRNO, "%s: SO_KEEPALIVE set on socket.", - __FUNCTION__); + MOTION_LOG(INF, TYPE_NETCAM, NO_ERRNO, "%s: SO_KEEPALIVE set on socket."); } - motion_log(INF, TYPE_NETCAM, NO_ERRNO, "%s: re-using socket %d since keepalive is set.", - __FUNCTION__, netcam->sock); + MOTION_LOG(INF, TYPE_NETCAM, NO_ERRNO, "%s: re-using socket %d since keepalive is set.", + netcam->sock); - /* lookup the hostname given in the netcam URL */ + /* Lookup the hostname given in the netcam URL. */ if ((ret = getaddrinfo(netcam->connect_host, NULL, NULL, &res)) != 0) { if (!err_flag) - motion_log(ERR, TYPE_NETCAM, NO_ERRNO, "%s: getaddrinfo() failed (%s): %s", - __FUNCTION__, netcam->connect_host, gai_strerror(ret)); + MOTION_LOG(ERR, TYPE_NETCAM, NO_ERRNO, "%s: getaddrinfo() failed (%s): %s", + netcam->connect_host, gai_strerror(ret)); - motion_log(INF, TYPE_NETCAM, NO_ERRNO, "%s: disconnecting netcam (1)", - __FUNCTION__); + MOTION_LOG(INF, TYPE_NETCAM, NO_ERRNO, "%s: disconnecting netcam (1)"); netcam_disconnect(netcam); return -1; @@ -940,7 +930,7 @@ static int netcam_connect(netcam_context_ptr netcam, int err_flag) /* * Fill the hostname details into the 'server' structure and - * attempt to connect to the remote server + * attempt to connect to the remote server. */ memset(&server, 0, sizeof(server)); memcpy(&server, res->ai_addr, sizeof(server)); @@ -955,50 +945,47 @@ static int netcam_connect(netcam_context_ptr netcam, int err_flag) */ if ((saveflags = fcntl(netcam->sock, F_GETFL, 0)) < 0) { - motion_log(ERR, TYPE_NETCAM, SHOW_ERRNO, "%s: fcntl(1) on socket", __FUNCTION__); + MOTION_LOG(ERR, TYPE_NETCAM, SHOW_ERRNO, "%s: fcntl(1) on socket"); netcam_disconnect(netcam); return -1; } - /* Set the socket non-blocking */ + /* Set the socket non-blocking. */ if (fcntl(netcam->sock, F_SETFL, saveflags | O_NONBLOCK) < 0) { - motion_log(ERR, TYPE_NETCAM, SHOW_ERRNO, "%s: fcntl(2) on socket", __FUNCTION__); + MOTION_LOG(ERR, TYPE_NETCAM, SHOW_ERRNO, "%s: fcntl(2) on socket"); netcam_disconnect(netcam); return -1; } - /* Now the connect call will return immediately */ + /* Now the connect call will return immediately. */ ret = connect(netcam->sock, (struct sockaddr *) &server, sizeof(server)); - back_err = errno; /* save the errno from connect */ + back_err = errno; /* Save the errno from connect */ - /* If the connect failed with anything except EINPROGRESS, error */ + /* If the connect failed with anything except EINPROGRESS, error. */ if ((ret < 0) && (back_err != EINPROGRESS)) { if (!err_flag) - motion_log(ERR, TYPE_NETCAM, SHOW_ERRNO, "%s: connect() failed (%d)", - __FUNCTION__, back_err); + MOTION_LOG(ERR, TYPE_NETCAM, SHOW_ERRNO, "%s: connect() failed (%d)", + back_err); - motion_log(INF, TYPE_NETCAM, NO_ERRNO, "%s: disconnecting netcam (4)", - __FUNCTION__); + MOTION_LOG(INF, TYPE_NETCAM, NO_ERRNO, "%s: disconnecting netcam (4)"); netcam_disconnect(netcam); return -1; } - /* Now we do a 'select' with timeout to wait for the connect */ + /* Now we do a 'select' with timeout to wait for the connect. */ FD_ZERO(&fd_w); FD_SET(netcam->sock, &fd_w); selecttime.tv_sec = CONNECT_TIMEOUT; selecttime.tv_usec = 0; ret = select(FD_SETSIZE, NULL, &fd_w, NULL, &selecttime); - if (ret == 0) { /* 0 means timeout */ + if (ret == 0) { /* 0 means timeout. */ if (!err_flag) - motion_log(ERR, TYPE_NETCAM, NO_ERRNO, "%s: timeout on connect()", - __FUNCTION__); + MOTION_LOG(ERR, TYPE_NETCAM, NO_ERRNO, "%s: timeout on connect()"); - motion_log(INF, TYPE_NETCAM, NO_ERRNO, "%s: disconnecting netcam (2)", - __FUNCTION__); + MOTION_LOG(INF, TYPE_NETCAM, NO_ERRNO, "%s: disconnecting netcam (2)"); netcam_disconnect(netcam); return -1; @@ -1012,29 +999,26 @@ static int netcam_connect(netcam_context_ptr netcam, int err_flag) len = sizeof(ret); if (getsockopt(netcam->sock, SOL_SOCKET, SO_ERROR, &ret, &len) < 0) { - motion_log(ERR, TYPE_NETCAM, NO_ERRNO, "%s: getsockopt after connect", - __FUNCTION__); + MOTION_LOG(ERR, TYPE_NETCAM, NO_ERRNO, "%s: getsockopt after connect"); netcam_disconnect(netcam); return -1; } - /* If the return code is anything except 0, error on connect */ + /* If the return code is anything except 0, error on connect. */ if (ret) { if (!err_flag) - motion_log(ERR, TYPE_NETCAM, SHOW_ERRNO, "%s: connect returned error", - __FUNCTION__); + MOTION_LOG(ERR, TYPE_NETCAM, SHOW_ERRNO, "%s: connect returned error"); - motion_log(INF, TYPE_NETCAM, NO_ERRNO, "%s: disconnecting netcam (3)", - __FUNCTION__); + MOTION_LOG(INF, TYPE_NETCAM, NO_ERRNO, "%s: disconnecting netcam (3)"); netcam_disconnect(netcam); return -1; } - /* The socket info is stored in the rbuf structure of our context */ + /* The socket info is stored in the rbuf structure of our context. */ rbuf_initialize(netcam); - return 0; /* success */ + return 0; /* Success */ } @@ -1046,8 +1030,8 @@ static int netcam_connect(netcam_context_ptr netcam, int err_flag) * the buffer and adjust it's size. * * Parameters: - * buff Pointer to a netcam_image_buffer structure - * numbytes The number of bytes to be copied + * buff Pointer to a netcam_image_buffer structure. + * numbytes The number of bytes to be copied. * * Returns: Nothing */ @@ -1068,8 +1052,8 @@ static void netcam_check_buffsize(netcam_buff_ptr buff, size_t numbytes) new_size = buff->size + real_alloc; - motion_log(DBG, TYPE_NETCAM, NO_ERRNO, "%s: expanding buffer from [%d/%d] to [%d/%d] bytes.", - __FUNCTION__, (int) buff->used, (int) buff->size, + MOTION_LOG(DBG, TYPE_NETCAM, NO_ERRNO, "%s: expanding buffer from [%d/%d] to [%d/%d] bytes.", + (int) buff->used, (int) buff->size, (int) buff->used, new_size); buff->ptr = myrealloc(buff->ptr, new_size, @@ -1139,27 +1123,27 @@ static int netcam_read_html_jpeg(netcam_context_ptr netcam) netcam_buff_ptr buffer; size_t remaining; /* # characters to read */ size_t maxflush; /* # chars before boundary */ - size_t rem, rlen, ix; /* working vars */ + size_t rem, rlen, ix; /* Working vars */ int retval; char *ptr, *bptr, *rptr; netcam_buff *xchg; struct timeval curtime; /* * Initialisation - set our local pointers to the context - * information + * information. */ buffer = netcam->receiving; - /* Assure the target buffer is empty */ + /* Assure the target buffer is empty. */ buffer->used = 0; - /* Prepare for read loop */ + /* Prepare for read loop. */ if (buffer->content_length != 0) remaining = buffer->content_length; else remaining = 999999; - /* Now read in the data */ + /* Now read in the data. */ while (remaining) { - /* Assure data in input buffer */ + /* Assure data in input buffer. */ if (netcam->response->buffer_left <= 0) { retval = rbuf_read_bufferful(netcam); @@ -1170,14 +1154,14 @@ static int netcam_read_html_jpeg(netcam_context_ptr netcam) netcam->response->buffer_pos = netcam->response->buffer; } - /* If a boundary string is present, take it into account */ + /* If a boundary string is present, take it into account. */ bptr = netcam->boundary; if (bptr) { rptr = netcam->response->buffer_pos; rlen = netcam->response->buffer_left; - /* Loop through buffer looking for start of boundary */ + /* Loop through buffer looking for start of boundary. */ while (1) { /* * Logic gets a little complicated here. The @@ -1195,11 +1179,11 @@ static int netcam_read_html_jpeg(netcam_context_ptr netcam) break; if ((ptr = memchr(rptr, *bptr, rlen)) == NULL) - /* boundary not here (normal path) */ + /* Boundary not here (normal path) */ break; /* * At least the first char was found in the - * buffer - check for the rest + * buffer - check for the rest. */ rem = rlen - (ptr - rptr); for (ix = 1; (ix < rem) && (ix < netcam->boundary_length); ix++) { @@ -1210,7 +1194,7 @@ static int netcam_read_html_jpeg(netcam_context_ptr netcam) if ((ix != netcam->boundary_length) && (ix != rem)) { /* * Not pointing at a boundary string - - * step along input + * step along input. */ ix = ptr - rptr + 1; rptr += ix; @@ -1221,7 +1205,7 @@ static int netcam_read_html_jpeg(netcam_context_ptr netcam) break; /* * Not yet decided - continue - * through input + * through input. */ continue; } @@ -1236,7 +1220,7 @@ static int netcam_read_html_jpeg(netcam_context_ptr netcam) if ((ptr - netcam->response->buffer) < (int) remaining) remaining = ptr - netcam->response->buffer; - /* go copy everything up to boundary */ + /* Go copy everything up to boundary. */ break; } @@ -1247,7 +1231,7 @@ static int netcam_read_html_jpeg(netcam_context_ptr netcam) * problem mentioned above. * * Assure there is data before potential - * boundary string + * boundary string. */ if (ptr != netcam->response->buffer) { /* @@ -1259,7 +1243,7 @@ static int netcam_read_html_jpeg(netcam_context_ptr netcam) * beginning and get some more input * data. First we flush the input * buffer up to the beginning of the - * (potential) boundary string + * (potential) boundary string. */ ix = ptr - netcam->response->buffer_pos; netcam_check_buffsize(buffer, ix); @@ -1275,44 +1259,43 @@ static int netcam_read_html_jpeg(netcam_context_ptr netcam) * module netcam_wget.c to do this job! */ - motion_log(NTC, TYPE_NETCAM, NO_ERRNO, + MOTION_LOG(NTC, TYPE_NETCAM, NO_ERRNO, "%s: Potential split boundary - " "%d chars flushed, %d " - "re-positioned", __FUNCTION__, ix, + "re-positioned", ix, (int) netcam->response->buffer_left); memmove(netcam->response->buffer, ptr, netcam->response->buffer_left); - } /* end of boundary split over buffer */ + } /* End of boundary split over buffer. */ retval = netcam_recv(netcam, netcam->response->buffer + netcam->response->buffer_left, sizeof(netcam->response->buffer) - netcam->response->buffer_left); - if (retval <= 0) { /* this is a fatal error */ - motion_log(ERR, TYPE_NETCAM, SHOW_ERRNO, "%s: recv() fail after boundary string", - __FUNCTION__); + if (retval <= 0) { /* This is a fatal error. */ + MOTION_LOG(ERR, TYPE_NETCAM, SHOW_ERRNO, "%s: recv() fail after boundary string"); return -1; } - /* Reset the input buffer pointers */ + /* Reset the input buffer pointers. */ netcam->response->buffer_left = retval + netcam->response->buffer_left; netcam->response->buffer_pos = netcam->response->buffer; - /* This will cause a 'continue' of the main loop */ + /* This will cause a 'continue' of the main loop. */ bptr = NULL; - /* Return to do the boundary compare from the start */ + /* Return to do the boundary compare from the start. */ break; - } /* end of while(1) input buffer search */ + } /* End of while(1) input buffer search. */ - /* !bptr shows we're processing split boundary */ + /* !bptr shows we're processing split boundary. */ if (!bptr) continue; } /* end of if (bptr) */ - /* boundary string not present, so just write out as much data as possible */ + /* boundary string not present, so just write out as much data as possible. */ if (remaining) { maxflush = MINVAL(netcam->response->buffer_left, remaining); netcam_check_buffsize(buffer, maxflush); @@ -1325,12 +1308,11 @@ static int netcam_read_html_jpeg(netcam_context_ptr netcam) /* * Read is complete - set the current 'receiving' buffer atomically * as 'latest', and make the buffer previously in 'latest' become - * the new 'receiving' + * the new 'receiving'. */ if (gettimeofday(&curtime, NULL) < 0) - motion_log(WRN, TYPE_NETCAM, SHOW_ERRNO, "%s: gettimeofday", __FUNCTION__); + MOTION_LOG(WRN, TYPE_NETCAM, SHOW_ERRNO, "%s: gettimeofday"); - netcam->receiving->image_time = curtime; /* @@ -1343,8 +1325,8 @@ static int netcam_read_html_jpeg(netcam_context_ptr netcam) 1000000.0 * (curtime.tv_sec - netcam->last_image.tv_sec) + (curtime.tv_usec- netcam->last_image.tv_usec)) / 10.0; - motion_log(DBG, TYPE_NETCAM, NO_ERRNO, "%s: Calculated frame time %f", - __FUNCTION__, netcam->av_frame_time); + MOTION_LOG(DBG, TYPE_NETCAM, NO_ERRNO, "%s: Calculated frame time %f", + netcam->av_frame_time); } netcam->last_image = curtime; @@ -1365,13 +1347,12 @@ static int netcam_read_html_jpeg(netcam_context_ptr netcam) if (netcam->caps.streaming == NCS_UNSUPPORTED) { if (!netcam->connect_keepalive) { - motion_log(NTC, TYPE_NETCAM, NO_ERRNO, "%s: disconnecting " - "netcam since keep-alive not set.", __FUNCTION__); + MOTION_LOG(NTC, TYPE_NETCAM, NO_ERRNO, "%s: disconnecting " + "netcam since keep-alive not set."); netcam_disconnect(netcam); } - motion_log(NTC, TYPE_NETCAM, NO_ERRNO, "%s: leaving netcam connected.", - __FUNCTION__); + MOTION_LOG(NTC, TYPE_NETCAM, NO_ERRNO, "%s: leaving netcam connected."); } return 0; @@ -1409,14 +1390,14 @@ static int netcam_http_request(netcam_context_ptr netcam) /* * netcam_connect does an automatic netcam_close, so it's * safe to include it as part of this loop - * (Not always true now Keep-Alive is implemented) + * (Not always true now Keep-Alive is implemented). */ - motion_log(INF, TYPE_NETCAM, NO_ERRNO, "%s: about to try to connect, time #%d", - __FUNCTION__, ix); + MOTION_LOG(INF, TYPE_NETCAM, NO_ERRNO, "%s: about to try to connect, time #%d", + ix); if (netcam_connect(netcam, 0) != 0) { - motion_log(ERR, TYPE_NETCAM, NO_ERRNO, "Failed to open camera - check your config " - "and that netcamera is online", __FUNCTION__); + MOTION_LOG(ERR, TYPE_NETCAM, NO_ERRNO, "Failed to open camera - check your config " + "and that netcamera is online"); /* Fatal error on startup */ ix = MAX_HEADER_RETRIES; @@ -1426,12 +1407,12 @@ static int netcam_http_request(netcam_context_ptr netcam) if (netcam_read_first_header(netcam) >= 0) break; - motion_log(ERR, TYPE_NETCAM, NO_ERRNO, "%s: Error reading first header - re-trying", __FUNCTION__); + MOTION_LOG(ERR, TYPE_NETCAM, NO_ERRNO, "%s: Error reading first header - re-trying"); } if (ix == MAX_HEADER_RETRIES) { - motion_log(ERR, TYPE_NETCAM, NO_ERRNO, "%s: Failed to read first camera header " - "- giving up for now", __FUNCTION__); + MOTION_LOG(ERR, TYPE_NETCAM, NO_ERRNO, "%s: Failed to read first camera header " + "- giving up for now"); return -1; } @@ -1461,12 +1442,11 @@ static int netcam_mjpg_buffer_refill(netcam_context_ptr netcam) while (1) { retval = rbuf_read_bufferful(netcam); if (retval <= 0) { /* If we got 0, we timeoutted. */ - motion_log(EMG, TYPE_NETCAM, NO_ERRNO, "%s: Read error," - " trying to reconnect..", __FUNCTION__); + MOTION_LOG(ALR, TYPE_NETCAM, NO_ERRNO, "%s: Read error," + " trying to reconnect.."); /* We may have lost the connexion */ if (netcam_http_request(netcam) < 0) { - motion_log(EMG, TYPE_NETCAM, NO_ERRNO, "%s: lost the cam.", - __FUNCTION__); + MOTION_LOG(EMG, TYPE_NETCAM, NO_ERRNO, "%s: lost the cam."); return -1; /* We REALLY lost the cam... bail out for now. */ } } @@ -1478,8 +1458,8 @@ static int netcam_mjpg_buffer_refill(netcam_context_ptr netcam) netcam->response->buffer_left = retval; netcam->response->buffer_pos = netcam->response->buffer; - motion_log(INF, TYPE_NETCAM, NO_ERRNO, "%s: Refilled buffer with [%d]" - " bytes from the network.", __FUNCTION__, retval); + MOTION_LOG(INF, TYPE_NETCAM, NO_ERRNO, "%s: Refilled buffer with [%d]" + " bytes from the network.", retval); return retval; } @@ -1528,10 +1508,10 @@ static int netcam_read_mjpg_jpeg(netcam_context_ptr netcam) /* * Initialisation - set our local pointers to the context - * information + * information. */ buffer = netcam->receiving; - /* Assure the target buffer is empty */ + /* Assure the target buffer is empty. */ buffer->used = 0; if (netcam_mjpg_buffer_refill(netcam) < 0) @@ -1542,13 +1522,13 @@ static int netcam_read_mjpg_jpeg(netcam_context_ptr netcam) read_bytes = 0; while (read_bytes < sizeof(mh)) { - /* Transfer what we have in buffer in the header structure */ + /* Transfer what we have in buffer in the header structure. */ retval = rbuf_flush(netcam, ((char *)&mh) + read_bytes, sizeof(mh) - read_bytes); read_bytes += retval; - motion_log(INF, TYPE_NETCAM, NO_ERRNO, "%s: Read [%d/%d] header bytes.", - __FUNCTION__, read_bytes, sizeof(mh)); + MOTION_LOG(INF, TYPE_NETCAM, NO_ERRNO, "%s: Read [%d/%d] header bytes.", + read_bytes, sizeof(mh)); /* If we don't have received a full header, refill our buffer. */ if (read_bytes < sizeof(mh)) { @@ -1559,8 +1539,8 @@ static int netcam_read_mjpg_jpeg(netcam_context_ptr netcam) /* Now check the validity of our header. */ if (strncmp(mh.mh_magic, MJPG_MH_MAGIC, MJPG_MH_MAGIC_SIZE)) { - motion_log(WRN, TYPE_NETCAM, NO_ERRNO, "%s: Invalid header received," - " reconnecting", __FUNCTION__); + MOTION_LOG(WRN, TYPE_NETCAM, NO_ERRNO, "%s: Invalid header received," + " reconnecting"); /* * We shall reconnect to restart the stream, and get a chance * to resync. @@ -1580,12 +1560,12 @@ static int netcam_read_mjpg_jpeg(netcam_context_ptr netcam) retval = rbuf_flush(netcam, buffer->ptr + buffer->used + read_bytes, mh.mh_chunksize - read_bytes); read_bytes += retval; - motion_log(DBG, TYPE_NETCAM, NO_ERRNO, "%s: Read [%d/%d] chunk bytes," - " [%d/%d] total", __FUNCTION__, read_bytes, mh.mh_chunksize, + MOTION_LOG(DBG, TYPE_NETCAM, NO_ERRNO, "%s: Read [%d/%d] chunk bytes," + " [%d/%d] total", read_bytes, mh.mh_chunksize, buffer->used + read_bytes, mh.mh_framesize); if (retval < (int)(mh.mh_chunksize - read_bytes)) { - /* motion_log(EMG, TYPE_NETCAM, NO_ERRNO, "Chunk incomplete, going to refill."); */ + /* MOTION_LOG(EMG, TYPE_NETCAM, NO_ERRNO, "Chunk incomplete, going to refill."); */ if (netcam_mjpg_buffer_refill(netcam) < 0) return -1; @@ -1593,28 +1573,25 @@ static int netcam_read_mjpg_jpeg(netcam_context_ptr netcam) } buffer->used += read_bytes; - motion_log(DBG, TYPE_NETCAM, NO_ERRNO, "%s: Chunk complete," - " buffer used [%d] bytes.", __FUNCTION__, buffer->used); + MOTION_LOG(DBG, TYPE_NETCAM, NO_ERRNO, "%s: Chunk complete," + " buffer used [%d] bytes.", buffer->used); /* Is our JPG image complete ? */ if (mh.mh_framesize == buffer->used) { - - motion_log(DBG, TYPE_NETCAM, NO_ERRNO, "%s: Image complete," - " buffer used [%d] bytes.", __FUNCTION__, buffer->used); - + MOTION_LOG(DBG, TYPE_NETCAM, NO_ERRNO, "%s: Image complete," + " buffer used [%d] bytes.", buffer->used); break; } - /* motion_log(ERR, TYPE_NETCAM, NO_ERRNO, "%s: Rlen now at [%d] bytes", __FUNCTION__, rlen); */ + /* MOTION_LOG(ERR, TYPE_NETCAM, NO_ERRNO, "%s: Rlen now at [%d] bytes", rlen); */ } /* * read is complete - set the current 'receiving' buffer atomically * as 'latest', and make the buffer previously in 'latest' become - * the new 'receiving' + * the new 'receiving'. */ if (gettimeofday(&curtime, NULL) < 0) - motion_log(WRN, TYPE_NETCAM, SHOW_ERRNO, "%s: gettimeofday", - __FUNCTION__); + MOTION_LOG(WRN, TYPE_NETCAM, SHOW_ERRNO, "%s: gettimeofday"); netcam->receiving->image_time = curtime; @@ -1628,8 +1605,8 @@ static int netcam_read_mjpg_jpeg(netcam_context_ptr netcam) 1000000.0 * (curtime.tv_sec - netcam->last_image.tv_sec) + (curtime.tv_usec- netcam->last_image.tv_usec)) / 10.0; - motion_log(DBG, TYPE_NETCAM, NO_ERRNO, "%s: Calculated frame time %f", - __FUNCTION__, netcam->av_frame_time); + MOTION_LOG(DBG, TYPE_NETCAM, NO_ERRNO, "%s: Calculated frame time %f", + netcam->av_frame_time); } netcam->last_image = curtime; @@ -1666,20 +1643,19 @@ static int netcam_read_ftp_jpeg(netcam_context_ptr netcam) netcam_buff *xchg; struct timeval curtime; - /* Point to our working buffer */ + /* Point to our working buffer. */ buffer = netcam->receiving; buffer->used = 0; - /* Request the image from the remote server */ + /* Request the image from the remote server. */ if (ftp_get_socket(netcam->ftp) <= 0) { - motion_log(ERR, TYPE_NETCAM, NO_ERRNO, "%s: ftp_get_socket failed", - __FUNCTION__); + MOTION_LOG(ERR, TYPE_NETCAM, NO_ERRNO, "%s: ftp_get_socket failed"); return -1; } - /* Now fetch the image using ftp_read. Note this is a blocking call */ + /* Now fetch the image using ftp_read. Note this is a blocking call. */ do { - /* Assure there's enough room in the buffer */ + /* Assure there's enough room in the buffer. */ netcam_check_buffsize(buffer, FTP_BUF_SIZE); /* Do the read */ @@ -1690,8 +1666,7 @@ static int netcam_read_ftp_jpeg(netcam_context_ptr netcam) } while (len > 0); if (gettimeofday(&curtime, NULL) < 0) - motion_log(WRN, TYPE_NETCAM, SHOW_ERRNO, "%s: gettimeofday", - __FUNCTION__); + MOTION_LOG(WRN, TYPE_NETCAM, SHOW_ERRNO, "%s: gettimeofday"); netcam->receiving->image_time = curtime; /* @@ -1704,8 +1679,8 @@ static int netcam_read_ftp_jpeg(netcam_context_ptr netcam) (curtime.tv_sec - netcam->last_image.tv_sec) + (curtime.tv_usec- netcam->last_image.tv_usec)) / 10.0; - motion_log(DBG, TYPE_NETCAM, NO_ERRNO, "%s: Calculated frame time %f", - __FUNCTION__, netcam->av_frame_time); + MOTION_LOG(DBG, TYPE_NETCAM, NO_ERRNO, "%s: Calculated frame time %f", + netcam->av_frame_time); } netcam->last_image = curtime; @@ -1713,7 +1688,7 @@ static int netcam_read_ftp_jpeg(netcam_context_ptr netcam) /* * read is complete - set the current 'receiving' buffer atomically * as 'latest', and make the buffer previously in 'latest' become - * the new 'receiving' + * the new 'receiving'. */ pthread_mutex_lock(&netcam->mutex); @@ -1747,7 +1722,7 @@ static int netcam_read_file_jpeg(netcam_context_ptr netcam) { int loop_counter = 0; - motion_log(DBG, TYPE_NETCAM, NO_ERRNO, "%s: Begin", __FUNCTION__); + MOTION_LOG(DBG, TYPE_NETCAM, NO_ERRNO, "%s: Begin"); netcam_buff_ptr buffer; int len; @@ -1755,31 +1730,31 @@ static int netcam_read_file_jpeg(netcam_context_ptr netcam) struct timeval curtime; struct stat statbuf; - /* Point to our working buffer */ + /* Point to our working buffer. */ buffer = netcam->receiving; buffer->used = 0; /*int fstat(int filedes, struct stat *buf);*/ do { if (stat(netcam->file->path, &statbuf)) { - motion_log(EMG, TYPE_NETCAM, NO_ERRNO, "%s: stat(%s) error", - __FUNCTION__, netcam->file->path); + MOTION_LOG(CRT, TYPE_NETCAM, NO_ERRNO, "%s: stat(%s) error", + netcam->file->path); return -1; } - motion_log(DBG, TYPE_NETCAM, NO_ERRNO, "%s: statbuf.st_mtime[%d]" - " != last_st_mtime[%d]", __FUNCTION__, statbuf.st_mtime, + MOTION_LOG(DBG, TYPE_NETCAM, NO_ERRNO, "%s: statbuf.st_mtime[%d]" + " != last_st_mtime[%d]", statbuf.st_mtime, netcam->file->last_st_mtime); /* its waits POLLING_TIMEOUT */ if (loop_counter>((POLLING_TIMEOUT*1000*1000)/(POLLING_TIME/1000))) { - motion_log(EMG, TYPE_NETCAM, NO_ERRNO, "%s: waiting new file image" - " timeout", __FUNCTION__); + MOTION_LOG(EMG, TYPE_NETCAM, NO_ERRNO, "%s: waiting new file image" + " timeout"); return -1; } - motion_log(DBG, TYPE_NETCAM, NO_ERRNO, "%s: delay waiting new" - " file image ", __FUNCTION__); + MOTION_LOG(DBG, TYPE_NETCAM, NO_ERRNO, "%s: delay waiting new" + " file image "); //its waits 5seconds - READ_TIMEOUT //SLEEP(netcam->timeout.tv_sec, netcam->timeout.tv_usec*1000); @@ -1791,10 +1766,10 @@ static int netcam_read_file_jpeg(netcam_context_ptr netcam) netcam->file->last_st_mtime = statbuf.st_mtime; - motion_log(INF, TYPE_NETCAM, NO_ERRNO, "%s: processing new file image -" - " st_mtime %d", __FUNCTION__, netcam->file->last_st_mtime); + MOTION_LOG(INF, TYPE_NETCAM, NO_ERRNO, "%s: processing new file image -" + " st_mtime %d", netcam->file->last_st_mtime); - /* Assure there's enough room in the buffer */ + /* Assure there's enough room in the buffer. */ while (buffer->size < (size_t)statbuf.st_size) netcam_check_buffsize(buffer, statbuf.st_size); @@ -1802,15 +1777,15 @@ static int netcam_read_file_jpeg(netcam_context_ptr netcam) /* Do the read */ netcam->file->control_file_desc = open(netcam->file->path, O_RDONLY); if (netcam->file->control_file_desc < 0) { - motion_log(EMG, TYPE_NETCAM, NO_ERRNO, "%s: open(%s) error: %d", - __FUNCTION__, netcam->file->path, netcam->file->control_file_desc); + MOTION_LOG(CRT, TYPE_NETCAM, NO_ERRNO, "%s: open(%s) error: %d", + netcam->file->path, netcam->file->control_file_desc); return -1; } if ((len = read(netcam->file->control_file_desc, buffer->ptr + buffer->used, statbuf.st_size)) < 0) { - motion_log(EMG, TYPE_NETCAM, NO_ERRNO, "%s: read(%s) error: %d", - __FUNCTION__, netcam->file->control_file_desc, len); + MOTION_LOG(CRT, TYPE_NETCAM, NO_ERRNO, "%s: read(%s) error: %d", + netcam->file->control_file_desc, len); return -1; } @@ -1818,10 +1793,8 @@ static int netcam_read_file_jpeg(netcam_context_ptr netcam) close(netcam->file->control_file_desc); if (gettimeofday(&curtime, NULL) < 0) - motion_log(WRN, TYPE_NETCAM, SHOW_ERRNO, "%s: gettimeofday", - __FUNCTION__); + MOTION_LOG(WRN, TYPE_NETCAM, SHOW_ERRNO, "%s: gettimeofday"); - netcam->receiving->image_time = curtime; /* * Calculate our "running average" time for this netcam's @@ -1833,8 +1806,8 @@ static int netcam_read_file_jpeg(netcam_context_ptr netcam) (curtime.tv_sec - netcam->last_image.tv_sec) + (curtime.tv_usec- netcam->last_image.tv_usec)) / 10.0; - motion_log(DBG, TYPE_NETCAM, NO_ERRNO, "%s: Calculated frame time %f", - __FUNCTION__, netcam->av_frame_time); + MOTION_LOG(DBG, TYPE_NETCAM, NO_ERRNO, "%s: Calculated frame time %f", + netcam->av_frame_time); } netcam->last_image = curtime; @@ -1842,7 +1815,7 @@ static int netcam_read_file_jpeg(netcam_context_ptr netcam) /* * read is complete - set the current 'receiving' buffer atomically * as 'latest', and make the buffer previously in 'latest' become - * the new 'receiving' + * the new 'receiving'. */ pthread_mutex_lock(&netcam->mutex); @@ -1857,11 +1830,9 @@ static int netcam_read_file_jpeg(netcam_context_ptr netcam) * next frame to become available may proceed. */ pthread_cond_signal(&netcam->pic_ready); - pthread_mutex_unlock(&netcam->mutex); - motion_log(DBG, TYPE_NETCAM, NO_ERRNO, "%s: End", - __FUNCTION__); + MOTION_LOG(DBG, TYPE_NETCAM, NO_ERRNO, "%s: End"); return 0; } @@ -1871,7 +1842,7 @@ tfile_context *file_new_context(void) { tfile_context *ret; - /* note that mymalloc will exit on any problem */ + /* Note that mymalloc will exit on any problem. */ ret = mymalloc(sizeof(tfile_context)); if (!ret) return ret; @@ -1906,8 +1877,8 @@ static int netcam_setup_file(netcam_context_ptr netcam, struct url_t *url) netcam->file->path = url->path; url->path = NULL; - motion_log(INF, TYPE_NETCAM, NO_ERRNO, "%s: netcam->file->path %s", - __FUNCTION__, netcam->file->path); + MOTION_LOG(INF, TYPE_NETCAM, NO_ERRNO, "%s: netcam->file->path %s", + netcam->file->path); netcam_url_free(url); @@ -1923,7 +1894,7 @@ static int netcam_setup_file(netcam_context_ptr netcam, struct url_t *url) * * Parameters * - * arg Pointer to the motion context for this camera + * arg Pointer to the motion context for this camera. * * Returns: NULL pointer * @@ -1933,16 +1904,15 @@ static void *netcam_handler_loop(void *arg) int retval; int open_error = 0; netcam_context_ptr netcam = arg; - struct context *cnt = netcam->cnt; /* needed for the SETUP macro :-( */ + struct context *cnt = netcam->cnt; /* Needed for the SETUP macro :-( */ /* Store the corresponding motion thread number in TLS also for this - * thread (necessary for 'motion_log' to function properly). + * thread (necessary for 'MOTION_LOG' to function properly). */ pthread_setspecific(tls_key_threadnr, (void *)((unsigned long)cnt->threadnr)); - motion_log(WRN, TYPE_NETCAM, NO_ERRNO, "%s: Camera handler thread [%d]" - " started", __FUNCTION__, netcam->threadnr); - + MOTION_LOG(ALR, TYPE_NETCAM, NO_ERRNO, "%s: Camera handler thread [%d]" + " started", netcam->threadnr); /* * The logic of our loop is very simple. If this is a non- * streaming camera, we re-establish connection with the camera @@ -1955,57 +1925,56 @@ static void *netcam_handler_loop(void *arg) */ while (!netcam->finish) { - if (netcam->response) { /* if html input */ + if (netcam->response) { /* If html input */ if (netcam->caps.streaming == NCS_UNSUPPORTED) { /* Non-streaming ie. jpeg */ if (!netcam->connect_keepalive || (netcam->connect_keepalive && netcam->keepalive_timeup)) { - /* If keepalive flag set but time up, time to close this socket */ + /* If keepalive flag set but time up, time to close this socket. */ if (netcam->connect_keepalive && netcam->keepalive_timeup) { - motion_log(WRN, TYPE_NETCAM, NO_ERRNO, "%s: Closing netcam socket" + MOTION_LOG(WRN, TYPE_NETCAM, NO_ERRNO, "%s: Closing netcam socket" " as Keep-Alive time is up (camera sent Close field). A reconnect" - " should happen.", __FUNCTION__); + " should happen."); netcam_disconnect(netcam); netcam->keepalive_timeup = FALSE; } - /* And the netcam_connect call below will open a new one */ + /* And the netcam_connect call below will open a new one. */ if (netcam_connect(netcam, open_error) < 0) { - if (!open_error) { /* log first error */ - motion_log(WRN, TYPE_NETCAM, NO_ERRNO, - "%s: re-opening camera (non-streaming)", __FUNCTION__); + if (!open_error) { /* Log first error. */ + MOTION_LOG(WRN, TYPE_NETCAM, NO_ERRNO, + "%s: re-opening camera (non-streaming)"); open_error = 1; } - /* need to have a dynamic delay here */ + /* Need to have a dynamic delay here. */ SLEEP(5, 0); continue; } - if (open_error) { /* log re-connection */ - motion_log(WRN, TYPE_NETCAM, NO_ERRNO, - "%s: camera re-connected", __FUNCTION__); + if (open_error) { /* Log re-connection */ + MOTION_LOG(WRN, TYPE_NETCAM, NO_ERRNO, + "%s: camera re-connected"); open_error = 0; } } - /* Send our request and look at the response */ + /* Send our request and look at the response. */ if ((retval = netcam_read_first_header(netcam)) != 1) { if (retval > 0) { - motion_log(ERR, TYPE_NETCAM, NO_ERRNO, "%s: Unrecognized image" - " header (%d)", __FUNCTION__, retval); + MOTION_LOG(ERR, TYPE_NETCAM, NO_ERRNO, "%s: Unrecognized image" + " header (%d)", retval); } else if (retval != -1) { - motion_log(ERR, TYPE_NETCAM, NO_ERRNO, "%s: Error in header (%d)", - __FUNCTION__, retval); + MOTION_LOG(ERR, TYPE_NETCAM, NO_ERRNO, "%s: Error in header (%d)", + retval); } - /* need to have a dynamic delay here */ + /* Need to have a dynamic delay here. */ continue; } } else if (netcam->caps.streaming == NCS_MULTIPART) { /* Multipart Streaming */ if (netcam_read_next_header(netcam) < 0) { if (netcam_connect(netcam, open_error) < 0) { - if (!open_error) { /* log first error */ - motion_log(ERR, TYPE_NETCAM, NO_ERRNO, - "%s: re-opening camera (streaming)", - __FUNCTION__); + if (!open_error) { /* Log first error */ + MOTION_LOG(ERR, TYPE_NETCAM, NO_ERRNO, + "%s: re-opening camera (streaming)"); open_error = 1; } SLEEP(5, 0); @@ -2014,20 +1983,20 @@ static void *netcam_handler_loop(void *arg) if ((retval = netcam_read_first_header(netcam) != 2)) { if (retval > 0) { - motion_log(ERR, TYPE_NETCAM, NO_ERRNO, - "%s: Unrecognized image header (%d)", __FUNCTION__, + MOTION_LOG(ERR, TYPE_NETCAM, NO_ERRNO, + "%s: Unrecognized image header (%d)", retval); } else if (retval != -1) { - motion_log(ERR, TYPE_NETCAM, NO_ERRNO, - "%s: Error in header (%d)", __FUNCTION__, retval); + MOTION_LOG(ERR, TYPE_NETCAM, NO_ERRNO, + "%s: Error in header (%d)", retval); } - /* FIXME need some limit */ + /* FIXME need some limit. */ continue; } } - if (open_error) { /* log re-connection */ - motion_log(ERR, TYPE_NETCAM, NO_ERRNO, - "%s: camera re-connected", __FUNCTION__); + if (open_error) { /* Log re-connection */ + MOTION_LOG(ERR, TYPE_NETCAM, NO_ERRNO, + "%s: camera re-connected"); open_error = 0; } } else if (netcam->caps.streaming == NCS_BLOCK) { /* MJPG-Block streaming */ @@ -2038,14 +2007,12 @@ static void *netcam_handler_loop(void *arg) } } if (netcam->get_image(netcam) < 0) { - motion_log(ERR, TYPE_NETCAM, NO_ERRNO, "%s: Error getting jpeg image", - __FUNCTION__); - /* if FTP connection, attempt to re-connect to server */ + MOTION_LOG(ERR, TYPE_NETCAM, NO_ERRNO, "%s: Error getting jpeg image"); + /* If FTP connection, attempt to re-connect to server. */ if (netcam->ftp) { close(netcam->ftp->control_file_desc); if (ftp_connect(netcam) < 0) - motion_log(ERR, TYPE_NETCAM, NO_ERRNO, "%s: Trying to re-connect", - __FUNCTION__); + MOTION_LOG(ERR, TYPE_NETCAM, NO_ERRNO, "%s: Trying to re-connect"); } continue; @@ -2053,7 +2020,7 @@ static void *netcam_handler_loop(void *arg) /* * FIXME * Need to check whether the image was received / decoded - * satisfactorily + * satisfactorily. */ /* @@ -2063,7 +2030,7 @@ static void *netcam_handler_loop(void *arg) if (netcam->caps.streaming == NCS_UNSUPPORTED) { pthread_mutex_lock(&netcam->mutex); - /* before anything else, check for system shutdown */ + /* Before anything else, check for system shutdown. */ if (netcam->finish) { pthread_mutex_unlock(&netcam->mutex); break; @@ -2084,22 +2051,22 @@ static void *netcam_handler_loop(void *arg) pthread_mutex_unlock(&netcam->mutex); } - /* the loop continues forever, or until motion shutdown */ + /* The loop continues forever, or until motion shutdown. */ } - /* our thread is finished - decrement motion's thread count */ + /* Our thread is finished - decrement motion's thread count. */ pthread_mutex_lock(&global_lock); threads_running--; pthread_mutex_unlock(&global_lock); - /* log out a termination message */ - motion_log(ERR, TYPE_NETCAM, NO_ERRNO, "%s: netcam camera handler:" - " finish set, exiting", __FUNCTION__); + /* Log out a termination message. */ + MOTION_LOG(ALR, TYPE_NETCAM, NO_ERRNO, "%s: netcam camera handler:" + " finish set, exiting"); - /* setting netcam->thread_id to zero shows netcam_cleanup we're done */ + /* Setting netcam->thread_id to zero shows netcam_cleanup we're done. */ netcam->thread_id = 0; - /* signal netcam_cleanup that we're all done */ + /* Signal netcam_cleanup that we're all done. */ pthread_mutex_lock(&netcam->mutex); pthread_cond_signal(&netcam->exiting); pthread_mutex_unlock(&netcam->mutex); @@ -2126,18 +2093,18 @@ static void *netcam_handler_loop(void *arg) static int netcam_http_build_url(netcam_context_ptr netcam, struct url_t *url) { struct context *cnt = netcam->cnt; - const char *ptr; /* working var */ - char *userpass; /* temp pointer to config value */ - char *encuserpass; /* temp storage for encoded ver */ - char *request_pass = NULL; /* temp storage for base64 conv */ + const char *ptr; /* Working var */ + char *userpass; /* Temp pointer to config value */ + char *encuserpass; /* Temp storage for encoded ver */ + char *request_pass = NULL; /* Temp storage for base64 conv */ int ix; - /* First the http context structure */ + /* First the http context structure. */ netcam->response = (struct rbuf *) mymalloc(sizeof(struct rbuf)); memset(netcam->response, 0, sizeof(struct rbuf)); - motion_log(INF, TYPE_NETCAM, NO_ERRNO, "%s: Netcam has flags:" - " HTTP/1.0: %s HTTP/1.1: %s Keep-Alive %s.", __FUNCTION__, + MOTION_LOG(INF, TYPE_NETCAM, NO_ERRNO, "%s: Netcam has flags:" + " HTTP/1.0: %s HTTP/1.1: %s Keep-Alive %s.", netcam->connect_http_10 ? "1":"0", netcam->connect_http_11 ? "1":"0", netcam->connect_keepalive ? "ON":"OFF"); @@ -2154,7 +2121,7 @@ static int netcam_http_build_url(netcam_context_ptr netcam, struct url_t *url) else ptr = url->userpass; - /* base64_encode needs up to 3 additional chars */ + /* base64_encode needs up to 3 additional chars. */ if (ptr) { userpass = mymalloc(strlen(ptr) + 3); strcpy(userpass, ptr); @@ -2171,20 +2138,21 @@ static int netcam_http_build_url(netcam_context_ptr netcam, struct url_t *url) * concatenate it with the request. * */ - /* space for final \r\n plus string terminator */ + + /* Space for final \r\n plus string terminator. */ ix = 3; - /* See if username / password is required */ - if (userpass) { /* if either of the above are non-NULL */ - /* Allocate space for the base64-encoded string */ + /* See if username / password is required. */ + if (userpass) { /* If either of the above are non-NULL. */ + /* Allocate space for the base64-encoded string. */ encuserpass = mymalloc(BASE64_LENGTH(strlen(userpass)) + 1); - /* Fill in the value */ + /* Fill in the value. */ base64_encode(userpass, encuserpass, strlen(userpass)); - /* Now create the last part (authorization) of the request */ + /* Now create the last part (authorization) of the request. */ request_pass = mymalloc(strlen(connect_auth_req) + strlen(encuserpass) + 1); ix += sprintf(request_pass, connect_auth_req, encuserpass); - /* free the working variables */ + /* Free the working variables. */ free(encuserpass); } @@ -2215,14 +2183,14 @@ static int netcam_http_build_url(netcam_context_ptr netcam, struct url_t *url) free((void *)netcam->cnt->conf.netcam_keepalive); netcam->cnt->conf.netcam_keepalive = strdup("off"); - motion_log(NTC, TYPE_NETCAM, NO_ERRNO, "%s: " + MOTION_LOG(NTC, TYPE_NETCAM, NO_ERRNO, "%s: " "Removed netcam_keepalive flag due to proxy set." - "Proxy is incompatible with Keep-Alive.", __FUNCTION__); + "Proxy is incompatible with Keep-Alive."); } else { - /* if no proxy, set as netcam_url path */ + /* If no proxy, set as netcam_url path. */ ptr = url->path; /* - * after generating the connect message the string + * After generating the connect message the string * will be freed, so we don't want netcam_url_free * to free it as well. */ @@ -2231,7 +2199,8 @@ static int netcam_http_build_url(netcam_context_ptr netcam, struct url_t *url) ix += strlen(ptr); - /* Now add the required number of characters for the close header + /* + * Now add the required number of characters for the close header * or Keep-Alive header. We test the flag which can be unset if * there is a problem (rather than the flag in the conf structure * which is read-only. @@ -2243,9 +2212,10 @@ static int netcam_http_build_url(netcam_context_ptr netcam, struct url_t *url) ix += strlen(connect_req_close); - /* Point to either the HTTP 1.0 or 1.1 request header set + /* + * Point to either the HTTP 1.0 or 1.1 request header set * If the configuration is anything other than 1.1, use 1.0 - * as a default. This avoids a chance of being left with none + * as a default. This avoids a chance of being left with none. */ if (netcam->connect_http_11 == TRUE) connect_req = connect_req_http11; @@ -2259,7 +2229,7 @@ static int netcam_http_build_url(netcam_context_ptr netcam, struct url_t *url) netcam->connect_request = mymalloc(strlen(connect_req) + ix + strlen(netcam->connect_host)); - /* Now create the request string with an sprintf */ + /* Now create the request string with an sprintf. */ sprintf(netcam->connect_request, connect_req, ptr, netcam->connect_host); @@ -2275,14 +2245,14 @@ static int netcam_http_build_url(netcam_context_ptr netcam, struct url_t *url) free(userpass); } - /* put on the final CRLF onto the request */ + /* Put on the final CRLF onto the request. */ strcat(netcam->connect_request, "\r\n"); free((void *)ptr); - netcam_url_free(url); /* Cleanup the url data */ + netcam_url_free(url); /* Cleanup the url data. */ - motion_log(INF , TYPE_NETCAM, NO_ERRNO, "%s: Camera connect" + MOTION_LOG(INF , TYPE_NETCAM, NO_ERRNO, "%s: Camera connect" " string is ''%s'' End of camera connect string.", - __FUNCTION__, netcam->connect_request); + netcam->connect_request); return 0; } @@ -2318,19 +2288,19 @@ static int netcam_setup_html(netcam_context_ptr netcam, struct url_t *url) /* * If this is a streaming camera, we need to position just - * past the boundary string and read the image header + * past the boundary string and read the image header. */ if (netcam->caps.streaming == NCS_MULTIPART) { if (netcam_read_next_header(netcam) < 0) { - motion_log(ERR, TYPE_NETCAM, NO_ERRNO, "%s: Failed " + MOTION_LOG(ERR, TYPE_NETCAM, NO_ERRNO, "%s: Failed " "to read first stream header - " - "giving up for now", __FUNCTION__); + "giving up for now"); return -1; } } - motion_log(NTC, TYPE_NETCAM, NO_ERRNO, "%s: connected," - " going on to read image.", __FUNCTION__); + MOTION_LOG(NTC, TYPE_NETCAM, NO_ERRNO, "%s: connected," + " going on to read image."); netcam->get_image = netcam_read_html_jpeg; return 0; @@ -2358,23 +2328,19 @@ static int netcam_setup_mjpg(netcam_context_ptr netcam, struct url_t *url) if (netcam_http_build_url(netcam, url) != 0) return -1; - /* - * Then we will send our http request and get headers. - */ + /* Then we will send our http request and get headers. */ if (netcam_http_request(netcam) < 0) return -1; - /* - * We have a special type of streaming camera - */ + /* We have a special type of streaming camera. */ netcam->caps.streaming = NCS_BLOCK; /* * We are positionned right just at the start of the first MJPG * header, so don't move anymore, initialization complete. */ - motion_log(NTC, TYPE_NETCAM, NO_ERRNO, "%s: connected," - " going on to read and decode MJPG chunks.", __FUNCTION__); + MOTION_LOG(NTC, TYPE_NETCAM, NO_ERRNO, "%s: connected," + " going on to read and decode MJPG chunks."); netcam->get_image = netcam_read_mjpg_jpeg; @@ -2400,7 +2366,7 @@ static int netcam_setup_ftp(netcam_context_ptr netcam, struct url_t *url) if (cnt->conf.netcam_userpass != NULL) { ptr = cnt->conf.netcam_userpass; } else { - ptr = url->userpass; /* don't set this one NULL, gets freed */ + ptr = url->userpass; /* Don't set this one NULL, gets freed. */ } if (ptr != NULL) { @@ -2427,8 +2393,8 @@ static int netcam_setup_ftp(netcam_context_ptr netcam, struct url_t *url) } if (ftp_send_type(netcam->ftp, 'I') < 0) { - motion_log(ERR, TYPE_NETCAM, NO_ERRNO, "%s: Error sending" - " TYPE I to ftp server", __FUNCTION__); + MOTION_LOG(ERR, TYPE_NETCAM, NO_ERRNO, "%s: Error sending" + " TYPE I to ftp server"); return -1; } @@ -2516,7 +2482,7 @@ void netcam_cleanup(netcam_context_ptr netcam, int init_retry_flag) /* * We set the netcam_context pointer in the motion main-loop context - * to be NULL, so that this routine won't be called a second time + * to be NULL, so that this routine won't be called a second time. */ netcam->cnt->netcam = NULL; @@ -2562,20 +2528,19 @@ void netcam_cleanup(netcam_context_ptr netcam, int init_retry_flag) pthread_cond_timedwait(&netcam->exiting, &netcam->mutex, &waittime) != 0) { /* * Although this shouldn't happen, if it *does* happen we will - * log it (just for the programmer's information) + * log it (just for the programmer's information). */ - motion_log(EMG, TYPE_NETCAM, NO_ERRNO, "%s: No response from camera " - "handler - it must have already died", - __FUNCTION__); + MOTION_LOG(EMG, TYPE_NETCAM, NO_ERRNO, "%s: No response from camera " + "handler - it must have already died"); pthread_mutex_lock(&global_lock); threads_running--; pthread_mutex_unlock(&global_lock); } - /* we don't need any lock anymore, so release it */ + /* We don't need any lock anymore, so release it. */ pthread_mutex_unlock(&netcam->mutex); - /* and cleanup the rest of the netcam_context structure */ + /* and cleanup the rest of the netcam_context structure. */ if (netcam->connect_host != NULL) free(netcam->connect_host); @@ -2651,8 +2616,7 @@ int netcam_next(struct context *cnt, unsigned char *image) netcam = cnt->netcam; if (!netcam->latest->used) { - motion_log(WRN, TYPE_NETCAM, NO_ERRNO, "%s: called with no data in buffer", - __FUNCTION__); + MOTION_LOG(WRN, TYPE_NETCAM, NO_ERRNO, "%s: called with no data in buffer"); return NETCAM_NOTHING_NEW_ERROR; } @@ -2673,12 +2637,12 @@ int netcam_next(struct context *cnt, unsigned char *image) * If an error occurs in the JPEG decompression which follows this, * jpeglib will return to the code within this 'if'. Basically, our * approach is to just return a NULL (failed) to the caller (an - * error message has already been produced by the libjpeg routines) + * error message has already been produced by the libjpeg routines). */ if (setjmp(netcam->setjmp_buffer)) return NETCAM_GENERAL_ERROR | NETCAM_JPEG_CONV_ERROR; - /* If there was no error, process the latest image buffer */ + /* If there was no error, process the latest image buffer. */ return netcam_proc_jpeg(netcam, image); } @@ -2693,7 +2657,7 @@ int netcam_next(struct context *cnt, unsigned char *image) * * Parameters: * - * cnt Pointer to the motion context structure for this device + * cnt Pointer to the motion context structure for this device. * * Returns: 0 on success * -1 on any failure @@ -2702,15 +2666,15 @@ int netcam_next(struct context *cnt, unsigned char *image) int netcam_start(struct context *cnt) { - netcam_context_ptr netcam; /* local pointer to our context */ - pthread_attr_t handler_attribute; /* attributes of our handler thread */ - int retval; /* working var */ - struct url_t url; /* for parsing netcam URL */ + netcam_context_ptr netcam; /* Local pointer to our context. */ + pthread_attr_t handler_attribute; /* Attributes of our handler thread. */ + int retval; /* Working var. */ + struct url_t url; /* For parsing netcam URL. */ memset(&url, 0, sizeof(url)); - motion_log(ERR, TYPE_NETCAM, NO_ERRNO, "%s: Network Camera thread" - " starting... for url (%s)", __FUNCTION__, cnt->conf.netcam_url); + MOTION_LOG(ALR, TYPE_NETCAM, NO_ERRNO, "%s: Network Camera thread" + " starting... for url (%s)", cnt->conf.netcam_url); /* * Create a new netcam_context for this camera * and clear all the entries. @@ -2718,8 +2682,8 @@ int netcam_start(struct context *cnt) cnt->netcam = (struct netcam_context *) mymalloc(sizeof(struct netcam_context)); memset(cnt->netcam, 0, sizeof(struct netcam_context)); - netcam = cnt->netcam; /* Just for clarity in remaining code */ - netcam->cnt = cnt; /* Fill in the "parent" info */ + netcam = cnt->netcam; /* Just for clarity in remaining code. */ + netcam->cnt = cnt; /* Fill in the "parent" info. */ /* * Fill in our new netcam context with all known initial @@ -2746,25 +2710,23 @@ int netcam_start(struct context *cnt) pthread_cond_init(&netcam->pic_ready, NULL); pthread_cond_init(&netcam->exiting, NULL); - /* Initialise the average frame time to the user's value */ + /* Initialise the average frame time to the user's value. */ netcam->av_frame_time = 1000000.0 / cnt->conf.frame_limit; - /* - * If a proxy has been specified, parse that URL. - */ + /* If a proxy has been specified, parse that URL. */ if (cnt->conf.netcam_proxy) { netcam_url_parse(&url, cnt->conf.netcam_proxy); if (!url.host) { - motion_log(ERR, TYPE_NETCAM, NO_ERRNO, "%s: Invalid netcam_proxy (%s)", - __FUNCTION__, cnt->conf.netcam_proxy); + MOTION_LOG(CRT, TYPE_NETCAM, NO_ERRNO, "%s: Invalid netcam_proxy (%s)", + cnt->conf.netcam_proxy); netcam_url_free(&url); return -1; } if (url.userpass) { - motion_log(ERR, TYPE_NETCAM, NO_ERRNO, "%s: Username/password" - " not allowed on a proxy URL", __FUNCTION__); + MOTION_LOG(CRT, TYPE_NETCAM, NO_ERRNO, "%s: Username/password" + " not allowed on a proxy URL"); netcam_url_free(&url); return -1; } @@ -2780,14 +2742,12 @@ int netcam_start(struct context *cnt) netcam_url_free(&url); /* Finished with proxy */ } - /* - * Parse the URL from the configuration data - */ + /* Parse the URL from the configuration data */ netcam_url_parse(&url, cnt->conf.netcam_url); if (!url.host) { - motion_log(ERR, TYPE_NETCAM, NO_ERRNO, "%s: Invalid netcam_url (%s)", - __FUNCTION__, cnt->conf.netcam_url); + MOTION_LOG(CRT, TYPE_NETCAM, NO_ERRNO, "%s: Invalid netcam_url (%s)", + cnt->conf.netcam_url); netcam_url_free(&url); return -1; } @@ -2798,7 +2758,7 @@ int netcam_start(struct context *cnt) netcam->connect_port = url.port; } - /* Get HTTP Mode (1.0 default, 1.0 Keep-Alive, 1.1) flag from config + /* Get HTTP Mode (1.0 default, 1.0 Keep-Alive, 1.1) flag from config * and report its stata for debug reasons. * The flags in the conf structure is read only and cannot be * unset if the Keep-Alive needs to be switched off (ie. netcam does @@ -2817,42 +2777,42 @@ int netcam_start(struct context *cnt) } else if (!strcmp(cnt->conf.netcam_keepalive, "on")) { netcam->connect_http_10 = FALSE; netcam->connect_http_11 = TRUE; - netcam->connect_keepalive = TRUE; /* HTTP 1.1 has keepalive by default */ + netcam->connect_keepalive = TRUE; /* HTTP 1.1 has keepalive by default. */ } - motion_log(INF, TYPE_NETCAM, NO_ERRNO, "%s: Netcam_http parameter '%s'" + MOTION_LOG(INF, TYPE_NETCAM, NO_ERRNO, "%s: Netcam_http parameter '%s'" " converts to flags: HTTP/1.0: %s HTTP/1.1: %s Keep-Alive %s.", - __FUNCTION__, cnt->conf.netcam_keepalive, + cnt->conf.netcam_keepalive, netcam->connect_http_10 ? "1":"0", netcam->connect_http_11 ? "1":"0", netcam->connect_keepalive ? "ON":"OFF"); - /* Initialise the netcam socket to -1 to trigger a connection by the keep-alive logic */ + /* Initialise the netcam socket to -1 to trigger a connection by the keep-alive logic. */ netcam->sock = -1; if ((url.service) && (!strcmp(url.service, "http"))) { - motion_log(DBG, TYPE_NETCAM, NO_ERRNO, "%s: now calling" - " netcam_setup_html()", __FUNCTION__); + MOTION_LOG(INF, TYPE_NETCAM, NO_ERRNO, "%s: now calling" + " netcam_setup_html()"); retval = netcam_setup_html(netcam, &url); } else if ((url.service) && (!strcmp(url.service, "ftp"))) { - motion_log(DBG, TYPE_NETCAM, NO_ERRNO, "%s: now calling" - " netcam_setup_ftp", __FUNCTION__); + MOTION_LOG(INF, TYPE_NETCAM, NO_ERRNO, "%s: now calling" + " netcam_setup_ftp"); retval = netcam_setup_ftp(netcam, &url); } else if ((url.service) && (!strcmp(url.service, "file"))) { - motion_log(DBG, TYPE_NETCAM, NO_ERRNO, "%s: now calling" - " netcam_setup_file()", __FUNCTION__); + MOTION_LOG(INF, TYPE_NETCAM, NO_ERRNO, "%s: now calling" + " netcam_setup_file()"); retval = netcam_setup_file(netcam, &url); } else if ((url.service) && (!strcmp(url.service, "mjpg"))) { - motion_log(DBG, TYPE_NETCAM, NO_ERRNO, "%s: now calling" - " netcam_setup_mjpg()", __FUNCTION__); + MOTION_LOG(INF, TYPE_NETCAM, NO_ERRNO, "%s: now calling" + " netcam_setup_mjpg()"); strcpy(url.service, "http"); /* Put back a real URL service. */ retval = netcam_setup_mjpg(netcam, &url); } else { - motion_log(ERR, TYPE_NETCAM, NO_ERRNO, "%s: Invalid netcam service '%s' - " - "must be http, ftp, mjpg or file.", __FUNCTION__, url.service); + MOTION_LOG(CRT, TYPE_NETCAM, NO_ERRNO, "%s: Invalid netcam service '%s' - " + "must be http, ftp, mjpg or file.", url.service); netcam_url_free(&url); return -1; } @@ -2868,8 +2828,8 @@ int netcam_start(struct context *cnt) * these to set the required image buffer(s) in our netcam_struct. */ if ((retval = netcam->get_image(netcam)) != 0) { - motion_log(ERR, TYPE_NETCAM, NO_ERRNO, "%s: Failed trying to " - "read first image - retval:%d", __FUNCTION__, retval); + MOTION_LOG(CRT, TYPE_NETCAM, NO_ERRNO, "%s: Failed trying to " + "read first image - retval:%d", retval); return -1; } @@ -2879,8 +2839,8 @@ int netcam_start(struct context *cnt) * occurs during startup, we will just abandon this attempt. */ if (setjmp(netcam->setjmp_buffer)) { - motion_log(ERR, TYPE_NETCAM, NO_ERRNO, "%s: libjpeg decompression failure " - "on first frame - giving up!", __FUNCTION__); + MOTION_LOG(CRT, TYPE_NETCAM, NO_ERRNO, "%s: libjpeg decompression failure " + "on first frame - giving up!"); return -1; } @@ -2888,22 +2848,23 @@ int netcam_start(struct context *cnt) netcam->JFIF_marker = 0; netcam_get_dimensions(netcam); - /* Motion currently requires that image height and width is a + /* + * Motion currently requires that image height and width is a * multiple of 16. So we check for this. */ if (netcam->width % 16) { - motion_log(ERR, TYPE_NETCAM, NO_ERRNO, "%s: netcam image width (%d)" - " is not modulo 16", __FUNCTION__, netcam->width); + MOTION_LOG(CRT, TYPE_NETCAM, NO_ERRNO, "%s: netcam image width (%d)" + " is not modulo 16", netcam->width); return -3; } if (netcam->height % 16) { - motion_log(ERR, TYPE_NETCAM, NO_ERRNO, "%s: netcam image height (%d)" - " is not modulo 16", __FUNCTION__, netcam->height); + MOTION_LOG(CRT, TYPE_NETCAM, NO_ERRNO, "%s: netcam image height (%d)" + " is not modulo 16", netcam->height); return -3; } - /* Fill in camera details into context structure */ + /* Fill in camera details into context structure. */ cnt->imgs.width = netcam->width; cnt->imgs.height = netcam->height; cnt->imgs.size = (netcam->width * netcam->height * 3) / 2; @@ -2922,8 +2883,8 @@ int netcam_start(struct context *cnt) if ((retval = pthread_create(&netcam->thread_id, &handler_attribute, &netcam_handler_loop, netcam)) < 0) { - motion_log(ERR, TYPE_NETCAM, SHOW_ERRNO, "%s: Starting camera" - " handler thread [%d]", __FUNCTION__, netcam->threadnr); + MOTION_LOG(ALR, TYPE_NETCAM, SHOW_ERRNO, "%s: Starting camera" + " handler thread [%d]", netcam->threadnr); return -1; } diff --git a/netcam_ftp.c b/netcam_ftp.c index afe20a6..6846a89 100644 --- a/netcam_ftp.c +++ b/netcam_ftp.c @@ -8,7 +8,7 @@ * See also the file 'COPYING'. * */ -#include "motion.h" /* needs to come first, because _GNU_SOURCE_ set there */ +#include "motion.h" /* Needs to come first, because _GNU_SOURCE_ set there. */ #include #include @@ -18,36 +18,36 @@ /** * ftp_new_context * -* Create a new FTP context structure +* Create a new FTP context structure. * * Parameters * * None * -* Returns: Pointer to the newly-created structure, NULL if error +* Returns: Pointer to the newly-created structure, NULL if error. * */ ftp_context_pointer ftp_new_context(void) { ftp_context_pointer ret; - /* note that mymalloc will exit on any problem */ + /* Note that mymalloc will exit on any problem. */ ret = mymalloc(sizeof(ftp_context)); memset(ret, 0, sizeof(ftp_context)); - ret->control_file_desc = -1; /* no control connection yet */ - ret->data_file_desc = -1; /* no data connection yet */ + ret->control_file_desc = -1; /* No control connection yet. */ + ret->data_file_desc = -1; /* No data connection yet. */ return ret; } /** * ftp_free_context * -* Free the resources allocated for this context +* Free the resources allocated for this context. * * Parameters * -* ctxt Pointer to the ftp_context structure +* ctxt Pointer to the ftp_context structure. * * Returns: Nothing * @@ -79,8 +79,8 @@ void ftp_free_context(ftp_context_pointer ctxt) * * Parameters: * -* buf the buffer containing the response -* len the buffer length +* buf the buffer containing the response. +* len the buffer length. * * Returns: * 0 for errors @@ -124,11 +124,11 @@ static int ftp_parse_response(char *buf, int len) /** * ftp_get_more * -* Read more information from the FTP control connection +* Read more information from the FTP control connection. * * Parameters: * -* ctxt pointer to an FTP context +* ctxt pointer to an FTP context. * * Returns the number of bytes read, < 0 indicates an error */ @@ -137,7 +137,7 @@ static int ftp_get_more(ftp_context_pointer ctxt) int len; int size; - /* Validate that our context structure is valid */ + /* Validate that our context structure is valid. */ if ((ctxt == NULL) || (ctxt->control_file_desc < 0)) return -1; @@ -150,7 +150,7 @@ static int ftp_get_more(ftp_context_pointer ctxt) if (ctxt->control_buffer_index > ctxt->control_buffer_used) return -1; - /* First pack the control buffer */ + /* First pack the control buffer. */ if (ctxt->control_buffer_index > 0) { memmove(&ctxt->control_buffer[0], &ctxt->control_buffer[ctxt->control_buffer_index], @@ -164,10 +164,10 @@ static int ftp_get_more(ftp_context_pointer ctxt) if (size == 0) return 0; - /* Read the amount left on the control connection */ + /* Read the amount left on the control connection. */ if ((len = recv(ctxt->control_file_desc, - &ctxt->control_buffer[ctxt->control_buffer_index], size, 0)) < 0) { - motion_log(ERR, TYPE_NETCAM, SHOW_ERRNO, "%s: recv failed in ftp_get_more", __FUNCTION__); + &ctxt->control_buffer[ctxt->control_buffer_index], size, 0)) < 0) { + MOTION_LOG(ERR, TYPE_NETCAM, SHOW_ERRNO, "%s: recv failed in ftp_get_more"); close(ctxt->control_file_desc); ctxt->control_file_desc = -1; return -1; @@ -201,8 +201,8 @@ static int ftp_get_response(ftp_context_pointer ctxt) get_more: /* - * Assumes everything up to control_buffer[control_buffer_index] has been read - * and analyzed. + * Assumes everything up to control_buffer[control_buffer_index] + * has been read and analyzed. */ len = ftp_get_more(ctxt); @@ -262,7 +262,7 @@ static int ftp_get_response(ftp_context_pointer ctxt) /** * ftp_send_user -* Sends the user authentication +* Sends the user authentication. */ static int ftp_send_user(ftp_context_pointer ctxt) { @@ -280,7 +280,7 @@ static int ftp_send_user(ftp_context_pointer ctxt) res = send(ctxt->control_file_desc, buf, len, 0); if (res < 0) { - motion_log(ERR, TYPE_NETCAM, SHOW_ERRNO, "%s: send failed in ftp_send_user", __FUNCTION__); + MOTION_LOG(ERR, TYPE_NETCAM, SHOW_ERRNO, "%s: send failed in ftp_send_user"); return res; } return 0; @@ -288,7 +288,7 @@ static int ftp_send_user(ftp_context_pointer ctxt) /** * ftp_send_passwd -* Sends the password authentication +* Sends the password authentication. */ static int ftp_send_passwd(ftp_context_pointer ctxt) { @@ -306,7 +306,7 @@ static int ftp_send_passwd(ftp_context_pointer ctxt) res = send(ctxt->control_file_desc, buf, len, 0); if (res < 0) { - motion_log(ERR, TYPE_NETCAM, SHOW_ERRNO, "%s: send failed in ftp_send_passwd", __FUNCTION__); + MOTION_LOG(ERR, TYPE_NETCAM, SHOW_ERRNO, "%s: send failed in ftp_send_passwd"); return res; } @@ -337,7 +337,7 @@ static int ftp_quit(ftp_context_pointer ctxt) res = send(ctxt->control_file_desc, buf, len, 0); if (res < 0) { - motion_log(ERR, TYPE_NETCAM, SHOW_ERRNO, "%s: send failed in ftp_quit", __FUNCTION__); + MOTION_LOG(ERR, TYPE_NETCAM, SHOW_ERRNO, "%s: send failed in ftp_quit"); return res; } @@ -347,13 +347,13 @@ static int ftp_quit(ftp_context_pointer ctxt) /** * ftp_connect * -* Tries to open a control connection +* Tries to open a control connection. * * Parameters: * * ctxt an FTP context * -* Returns -1 in case of error, 0 otherwise +* Returns -1 in case of error, 0 otherwise. */ int ftp_connect(netcam_context_ptr netcam) { @@ -385,14 +385,14 @@ int ftp_connect(netcam_context_ptr netcam) hp = gethostbyname (netcam->connect_host); if (hp == NULL) { - motion_log(ERR, TYPE_NETCAM, SHOW_ERRNO, "%s: gethostbyname failed in ftp_connect", __FUNCTION__); + MOTION_LOG(ERR, TYPE_NETCAM, SHOW_ERRNO, "%s: gethostbyname failed in ftp_connect"); return -1; } if ((unsigned int) hp->h_length > sizeof(((struct sockaddr_in *)&ctxt->ftp_address)->sin_addr)) { - motion_log(ERR, TYPE_NETCAM, SHOW_ERRNO, "%s: gethostbyname address mismatch " - "in ftp_connect", __FUNCTION__); + MOTION_LOG(ERR, TYPE_NETCAM, SHOW_ERRNO, "%s: gethostbyname address mismatch " + "in ftp_connect"); return -1; } @@ -404,14 +404,14 @@ int ftp_connect(netcam_context_ptr netcam) addrlen = sizeof (struct sockaddr_in); if (ctxt->control_file_desc < 0) { - motion_log(ERR, TYPE_NETCAM, SHOW_ERRNO, "%s: socket failed", __FUNCTION__); + MOTION_LOG(ERR, TYPE_NETCAM, SHOW_ERRNO, "%s: socket failed"); return -1; } /* Do the connect. */ if (connect(ctxt->control_file_desc, (struct sockaddr *) &ctxt->ftp_address, addrlen) < 0) { - motion_log(ERR, TYPE_NETCAM, SHOW_ERRNO, "%s: Failed to create a connection", __FUNCTION__); + MOTION_LOG(ERR, TYPE_NETCAM, SHOW_ERRNO, "%s: Failed to create a connection"); close(ctxt->control_file_desc); ctxt->control_file_desc = -1; return -1; @@ -465,8 +465,7 @@ int ftp_connect(netcam_context_ptr netcam) case 2: break; case 3: - motion_log(ERR, TYPE_NETCAM, NO_ERRNO, "%s: FTP server asking for ACCT on anonymous", - __FUNCTION__); + MOTION_LOG(WRN, TYPE_NETCAM, NO_ERRNO, "%s: FTP server asking for ACCT on anonymous"); case 1: case 4: case 5: @@ -488,7 +487,7 @@ int ftp_connect(netcam_context_ptr netcam) * * Parameters: * -* ctxt pointer to an FTP context +* ctxt pointer to an FTP context. * * Returns -1 in case of error, 0 otherwise */ @@ -506,7 +505,7 @@ static int ftp_get_connection(ftp_context_pointer ctxt) if (ctxt == NULL) return -1; - /* set up a socket for our data address */ + /* Set up a socket for our data address. */ if (ctxt->data_file_desc != -1) close(ctxt->data_file_desc); @@ -514,7 +513,7 @@ static int ftp_get_connection(ftp_context_pointer ctxt) ctxt->data_file_desc = socket (AF_INET, SOCK_STREAM, IPPROTO_TCP); if (ctxt->data_file_desc < 0) { - motion_log(ERR, TYPE_NETCAM, SHOW_ERRNO, "%s: socket failed", __FUNCTION__); + MOTION_LOG(ERR, TYPE_NETCAM, SHOW_ERRNO, "%s: socket failed"); return -1; } @@ -522,8 +521,7 @@ static int ftp_get_connection(ftp_context_pointer ctxt) if (setsockopt(ctxt->data_file_desc, SOL_SOCKET, SO_REUSEADDR, (char *)&on, sizeof(on)) < 0) { - motion_log(ERR, TYPE_NETCAM, SHOW_ERRNO, "%s: setting socket option SO_REUSEADDR", - __FUNCTION__); + MOTION_LOG(ERR, TYPE_NETCAM, SHOW_ERRNO, "%s: setting socket option SO_REUSEADDR"); return -1; } @@ -531,19 +529,18 @@ static int ftp_get_connection(ftp_context_pointer ctxt) data_address_length = sizeof (struct sockaddr_in); if (ctxt->passive) { - /* send PASV command over control channel */ + /* Send PASV command over control channel. */ snprintf (buf, sizeof(buf), "PASV\r\n"); len = strlen (buf); res = send(ctxt->control_file_desc, buf, len, 0); if (res < 0) { - motion_log(ERR, TYPE_NETCAM, SHOW_ERRNO, "%s: send failed in ftp_get_connection", - __FUNCTION__); + MOTION_LOG(ERR, TYPE_NETCAM, SHOW_ERRNO, "%s: send failed in ftp_get_connection"); close(ctxt->data_file_desc); ctxt->data_file_desc = -1; return res; } - /* check server's answer */ + /* Check server's answer */ res = ftp_get_response(ctxt); if (res != 2) { @@ -552,15 +549,13 @@ static int ftp_get_connection(ftp_context_pointer ctxt) ctxt->data_file_desc = -1; return -1; } else { - /* - * retry with an active connection - */ + /* Retry with an active connection. */ close(ctxt->data_file_desc); ctxt->data_file_desc = -1; ctxt->passive = 0; } } - /* parse the IP address and port supplied by the server */ + /* 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') @@ -568,7 +563,7 @@ static int ftp_get_connection(ftp_context_pointer ctxt) if (sscanf(cur, "%u,%u,%u,%u,%u,%u", &temp[0], &temp[1], &temp[2], &temp[3], &temp[4], &temp[5]) != 6) { - motion_log(ERR, TYPE_NETCAM, NO_ERRNO, "%s: Invalid answer to PASV", __FUNCTION__); + MOTION_LOG(ERR, TYPE_NETCAM, NO_ERRNO, "%s: Invalid answer to PASV"); if (ctxt->data_file_desc != -1) { close (ctxt->data_file_desc); ctxt->data_file_desc = -1; @@ -582,11 +577,10 @@ static int ftp_get_connection(ftp_context_pointer ctxt) 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 */ + /* Now try to connect to the data port. */ if (connect(ctxt->data_file_desc, (struct sockaddr *) &data_address, data_address_length) < 0) { - motion_log(ERR, TYPE_NETCAM, SHOW_ERRNO, "%s: Failed to create a data connection", - __FUNCTION__); + MOTION_LOG(ERR, TYPE_NETCAM, SHOW_ERRNO, "%s: Failed to create a data connection"); close(ctxt->data_file_desc); ctxt->data_file_desc = -1; return -1; @@ -596,34 +590,34 @@ static int ftp_get_connection(ftp_context_pointer ctxt) * We want to bind to a port to receive the data. To do this, * we need the address of our host. One easy way to get it is * to get the info from the control connection that we have - * with the remote server + * with the remote server. */ getsockname(ctxt->control_file_desc, (struct sockaddr *)&data_address, &data_address_length); ((struct sockaddr_in *)&data_address)->sin_port = 0; - /* bind to the socket - should give us a unique port */ + /* Bind to the socket - should give us a unique port. */ if (bind(ctxt->data_file_desc, (struct sockaddr *) &data_address, data_address_length) < 0) { - motion_log(ERR, TYPE_NETCAM, SHOW_ERRNO, "%s: bind failed", __FUNCTION__); + MOTION_LOG(ERR, TYPE_NETCAM, SHOW_ERRNO, "%s: bind failed"); close(ctxt->data_file_desc); ctxt->data_file_desc = -1; return -1; } - /* we get the port number by reading back in the sockaddr */ + /* We get the port number by reading back in the sockaddr. */ getsockname(ctxt->data_file_desc, (struct sockaddr *)&data_address, &data_address_length); - /* set up a 'listen' on the port to get the server's connection */ + /* Set up a 'listen' on the port to get the server's connection. */ if (listen(ctxt->data_file_desc, 1) < 0) { - motion_log(ERR, TYPE_NETCAM, SHOW_ERRNO, "%s: listen failed", __FUNCTION__); + MOTION_LOG(ERR, TYPE_NETCAM, SHOW_ERRNO, "%s: listen failed"); close(ctxt->data_file_desc); ctxt->data_file_desc = -1; return -1; } - /* now generate the PORT command */ + /* Now generate the PORT command. */ adp = (unsigned char *) &((struct sockaddr_in *)&data_address)->sin_addr; portp = (unsigned char *) &((struct sockaddr_in *)&data_address)->sin_port; snprintf(buf, sizeof(buf), "PORT %d,%d,%d,%d,%d,%d\r\n", @@ -633,12 +627,11 @@ static int ftp_get_connection(ftp_context_pointer ctxt) buf[sizeof(buf) - 1] = 0; len = strlen(buf); - /* send the PORT command to the server */ + /* Send the PORT command to the server. */ res = send(ctxt->control_file_desc, buf, len, 0); if (res < 0) { - motion_log(ERR, TYPE_NETCAM, SHOW_ERRNO, "%s: send failed in ftp_get_connection", - __FUNCTION__); + MOTION_LOG(ERR, TYPE_NETCAM, SHOW_ERRNO, "%s: send failed in ftp_get_connection"); close(ctxt->data_file_desc); ctxt->data_file_desc = -1; return res; @@ -659,11 +652,11 @@ static int ftp_get_connection(ftp_context_pointer ctxt) /** * ftp_close_connection * -* Close the data connection from the server +* Close the data connection from the server. * * Parameters: * -* ctxt Pointer to an FTP context +* ctxt Pointer to an FTP context. * * Returns -1 in case of error, 0 otherwise */ @@ -679,7 +672,7 @@ static int ftp_close_connection(ftp_context_pointer ctxt) close(ctxt->data_file_desc); ctxt->data_file_desc = -1; - /* Check for data on the control channel */ + /* Check for data on the control channel. */ tv.tv_sec = 15; tv.tv_usec = 0; FD_ZERO(&rfd); @@ -694,13 +687,13 @@ static int ftp_close_connection(ftp_context_pointer ctxt) return -1; } - if (res == 0) { /* timeout */ + if (res == 0) { /* Timeout */ close(ctxt->control_file_desc); ctxt->control_file_desc = -1; - } else { /* read the response */ + } else { /* Read the response */ res = ftp_get_response(ctxt); - if (res != 2) { /* should be positive completion (2) */ + if (res != 2) { /* Should be positive completion (2) */ close(ctxt->control_file_desc); ctxt->control_file_desc = -1; return -1; @@ -730,29 +723,28 @@ int ftp_get_socket(ftp_context_pointer ctxt) if ((ctxt == NULL) || (ctxt->path == NULL)) return -1; - /* Set up the data connection */ + /* Set up the data connection. */ ctxt->data_file_desc = ftp_get_connection(ctxt); if (ctxt->data_file_desc == -1) return -1; - /* generate a "retrieve" command for the file */ + /* Generate a "retrieve" command for the file. */ snprintf(buf, sizeof(buf), "RETR %s\r\n", ctxt->path); buf[sizeof(buf) - 1] = 0; len = strlen(buf); - /* send it to the server */ + /* Send it to the server. */ res = send(ctxt->control_file_desc, buf, len, 0); if (res < 0) { - motion_log(ERR, TYPE_NETCAM, SHOW_ERRNO, "%s: send failed in ftp_get_socket", - __FUNCTION__); + MOTION_LOG(ERR, TYPE_NETCAM, SHOW_ERRNO, "%s: send failed in ftp_get_socket"); close(ctxt->data_file_desc); ctxt->data_file_desc = -1; return res; } - /* check the answer */ + /* Check the answer */ res = ftp_get_response(ctxt); if (res != 1) { @@ -763,7 +755,7 @@ int ftp_get_socket(ftp_context_pointer ctxt) /* * If not a passive connection, need to do an accept to get the - * connection from the server + * connection from the server. */ if (!ctxt->passive) { struct sockaddr_in data_address; @@ -771,7 +763,7 @@ int ftp_get_socket(ftp_context_pointer ctxt) if ((acfd = accept(ctxt->data_file_desc, (struct sockaddr *)&data_address, &data_address_length)) < 0) { - motion_log(ERR, TYPE_NETCAM, SHOW_ERRNO, "%s: accept in ftp_get_socket", __FUNCTION__); + MOTION_LOG(ERR, TYPE_NETCAM, SHOW_ERRNO, "%s: accept in ftp_get_socket"); close(ctxt->data_file_desc); ctxt->data_file_desc = -1; return -1; @@ -786,14 +778,14 @@ int ftp_get_socket(ftp_context_pointer ctxt) /** * ftp_send_type * -* Send a TYPE (either 'I' or 'A') command to the server +* Send a TYPE (either 'I' or 'A') command to the server. * * Parameters * * ctxt pointer to the ftp_context * type ascii character ('I' or 'A') * -* Returns 0 for success, negative error code for failure +* Returns 0 for success, negative error code for failure. * */ int ftp_send_type(ftp_context_pointer ctxt, char type) @@ -802,13 +794,13 @@ int ftp_send_type(ftp_context_pointer ctxt, char type) int len, res; utype = toupper(type); - /* Assure transfer will be in "image" mode */ + /* Assure transfer will be in "image" mode. */ snprintf(buf, sizeof(buf), "TYPE I\r\n"); len = strlen(buf); res = send(ctxt->control_file_desc, buf, len, 0); if (res < 0) { - motion_log(ERR, TYPE_NETCAM, SHOW_ERRNO, "%s: send failed in ftp_get_socket", __FUNCTION__); + MOTION_LOG(ERR, TYPE_NETCAM, SHOW_ERRNO, "%s: send failed in ftp_get_socket"); close(ctxt->data_file_desc); ctxt->data_file_desc = -1; return res; @@ -858,7 +850,7 @@ int ftp_read(ftp_context_pointer ctxt, void *dest, int len) if (len <= 0) { if (len < 0) - motion_log(ERR, TYPE_NETCAM, SHOW_ERRNO, "%s: recv failed in ftp_read", __FUNCTION__); + MOTION_LOG(ERR, TYPE_NETCAM, SHOW_ERRNO, "%s: recv failed in ftp_read"); ftp_close_connection(ctxt); } @@ -869,13 +861,13 @@ int ftp_read(ftp_context_pointer ctxt, void *dest, int len) /** * ftp_close * -* Close the connection and both control and transport +* Close the connection and both control and transport. * * Parameters: * -* ctxt Pointer to an FTP context +* ctxt Pointer to an FTP context. * -* Returns -1 in case of error, 0 otherwise +* Returns -1 in case of error, 0 otherwise. */ int ftp_close(ftp_context_pointer ctxt) { diff --git a/netcam_jpeg.c b/netcam_jpeg.c index 678f8e8..b07fcaa 100644 --- a/netcam_jpeg.c +++ b/netcam_jpeg.c @@ -19,7 +19,7 @@ /* * netcam_source_mgr is a locally-defined structure to contain elements * which are not present in the standard libjpeg (the element 'pub' is a - * pointer to the standard information) + * pointer to the standard information). */ typedef struct { struct jpeg_source_mgr pub; @@ -47,11 +47,11 @@ static void netcam_error_exit(j_common_ptr); static void netcam_init_source(j_decompress_ptr cinfo) { - /* Get our "private" structure from the libjpeg structure */ + /* Get our "private" structure from the libjpeg structure. */ netcam_src_ptr src = (netcam_src_ptr) cinfo->src; /* * Set the 'start_of_file' flag in our private structure - * (used by my_fill_input_buffer) + * (used by my_fill_input_buffer). */ src->start_of_file = TRUE; } @@ -81,8 +81,7 @@ static boolean netcam_fill_input_buffer(j_decompress_ptr cinfo) src->buffer = (JOCTET *) src->data; } else { /* Insert a fake EOI marker - as per jpeglib recommendation */ - motion_log(DBG, TYPE_NETCAM, NO_ERRNO, "%s: **fake EOI inserted**", - __FUNCTION__); + MOTION_LOG(NTC, TYPE_NETCAM, NO_ERRNO, "%s: **fake EOI inserted**"); src->buffer[0] = (JOCTET) 0xFF; src->buffer[1] = (JOCTET) JPEG_EOI; /* 0xD9 */ nbytes = 2; @@ -120,9 +119,9 @@ static void netcam_term_source(j_decompress_ptr cinfo ATTRIBUTE_UNUSED) * JPEG library decompression routine. * * Parameters: - * cinfo pointer to the jpeg decompression object - * data pointer to the image data received from a netcam - * length total size of the image + * cinfo pointer to the jpeg decompression object. + * data pointer to the image data received from a netcam. + * length total size of the image. * * Returns: Nothing * @@ -159,27 +158,27 @@ static void netcam_memory_src(j_decompress_ptr cinfo, char *data, int length) * * Parameters * - * cinfo pointer to the decompression control structure + * cinfo pointer to the decompression control structure. * * Returns: does an (ugly) longjmp to get back to netcam_jpeg - * code + * code. * */ static void netcam_error_exit(j_common_ptr cinfo) { - /* fetch our pre-stored pointer to the netcam context */ + /* Fetch our pre-stored pointer to the netcam context. */ netcam_context_ptr netcam = cinfo->client_data; - /* output the message associated with the error */ + /* Output the message associated with the error. */ (*cinfo->err->output_message)(cinfo); - /* set flag to show the decompression had errors */ + /* Set flag to show the decompression had errors. */ netcam->jpeg_error |= 1; - /* need to "cleanup" the aborted decompression */ + /* Need to "cleanup" the aborted decompression. */ jpeg_destroy (cinfo); - motion_log(DBG, TYPE_NETCAM, NO_ERRNO, "%s: netcam->jpeg_error %d", - __FUNCTION__, netcam->jpeg_error); + MOTION_LOG(INF, TYPE_NETCAM, NO_ERRNO, "%s: netcam->jpeg_error %d", + netcam->jpeg_error); - /* jump back to wherever we started */ + /* Jump back to wherever we started. */ longjmp(netcam->setjmp_buffer, 1); } @@ -192,7 +191,7 @@ static void netcam_error_exit(j_common_ptr cinfo) * * Parameters * - * cinfo pointer to the decompression control structure + * cinfo pointer to the decompression control structure. * * Returns Nothing * @@ -201,7 +200,7 @@ static void netcam_output_message(j_common_ptr cinfo) { char buffer[JMSG_LENGTH_MAX]; - /* fetch our pre-stored pointer to the netcam context */ + /* Fetch our pre-stored pointer to the netcam context. */ netcam_context_ptr netcam = cinfo->client_data; /* @@ -224,8 +223,7 @@ static void netcam_output_message(j_common_ptr cinfo) * Write it out to the motion log. */ (*cinfo->err->format_message)(cinfo, buffer); - motion_log(DBG, TYPE_NETCAM, NO_ERRNO, "%s: %s", - __FUNCTION__, buffer); + MOTION_LOG(DBG, TYPE_NETCAM, NO_ERRNO, "%s: %s", buffer); } @@ -236,10 +234,10 @@ static void netcam_output_message(j_common_ptr cinfo) * decompression. * * Parameters: - * netcam pointer to netcam_context - * cinfo pointer to JPEG decompression context + * netcam pointer to netcam_context. + * cinfo pointer to JPEG decompression context. * - * Returns: Error code + * Returns: Error code. */ static int netcam_init_jpeg(netcam_context_ptr netcam, j_decompress_ptr cinfo) { @@ -253,7 +251,7 @@ static int netcam_init_jpeg(netcam_context_ptr netcam, j_decompress_ptr cinfo) */ pthread_mutex_lock(&netcam->mutex); - if (netcam->imgcnt_last == netcam->imgcnt) { /* need to wait */ + if (netcam->imgcnt_last == netcam->imgcnt) { /* Need to wait */ struct timespec waittime; struct timeval curtime; int retcode; @@ -281,57 +279,57 @@ static int netcam_init_jpeg(netcam_context_ptr netcam, j_decompress_ptr cinfo) &netcam->mutex, &waittime); } while (retcode == EINTR); - if (retcode) { /* we assume a non-zero reply is ETIMEOUT */ + if (retcode) { /* We assume a non-zero reply is ETIMEOUT */ pthread_mutex_unlock(&netcam->mutex); - motion_log(WRN, TYPE_NETCAM, NO_ERRNO, - "%s: no new pic, no signal rcvd", __FUNCTION__); + MOTION_LOG(WRN, TYPE_NETCAM, NO_ERRNO, + "%s: no new pic, no signal rcvd"); return NETCAM_GENERAL_ERROR | NETCAM_NOTHING_NEW_ERROR; } - motion_log(DBG, TYPE_NETCAM, NO_ERRNO, - "%s: ***new pic delay successful***", __FUNCTION__); + MOTION_LOG(INF, TYPE_NETCAM, NO_ERRNO, + "%s: ***new pic delay successful***"); } netcam->imgcnt_last = netcam->imgcnt; - /* set latest buffer as "current" */ + /* Set latest buffer as "current". */ buff = netcam->latest; netcam->latest = netcam->jpegbuf; netcam->jpegbuf = buff; pthread_mutex_unlock(&netcam->mutex); - /* clear any error flag from previous work */ + /* Clear any error flag from previous work. */ netcam->jpeg_error = 0; buff = netcam->jpegbuf; /* - * Prepare for the decompression - * Initialize the JPEG decompression object + * Prepare for the decompression. + * Initialize the JPEG decompression object. */ jpeg_create_decompress(cinfo); - /* Set up own error exit routine */ + /* Set up own error exit routine. */ cinfo->err = jpeg_std_error(&netcam->jerr); cinfo->client_data = netcam; netcam->jerr.error_exit = netcam_error_exit; netcam->jerr.output_message = netcam_output_message; - /* Specify the data source as our own routine */ + /* Specify the data source as our own routine. */ netcam_memory_src(cinfo, buff->ptr, buff->used); - /* Read file parameters (rejecting tables-only) */ + /* Read file parameters (rejecting tables-only). */ jpeg_read_header(cinfo, TRUE); - /* Override the desired colour space */ + /* Override the desired colour space. */ cinfo->out_color_space = JCS_YCbCr; - /* Start the decompressor */ + /* Start the decompressor. */ jpeg_start_decompress(cinfo); - motion_log(DBG, TYPE_NETCAM, NO_ERRNO, "%s: jpeg_error %d", - __FUNCTION__, netcam->jpeg_error); + MOTION_LOG(INF, TYPE_NETCAM, NO_ERRNO, "%s: jpeg_error %d", + netcam->jpeg_error); return netcam->jpeg_error; } @@ -350,35 +348,35 @@ static int netcam_image_conv(netcam_context_ptr netcam, struct jpeg_decompress_struct *cinfo, unsigned char *image) { - JSAMPARRAY line; /* array of decomp data lines */ - unsigned char *wline; /* will point to line[0] */ + JSAMPARRAY line; /* Array of decomp data lines */ + unsigned char *wline; /* Will point to line[0] */ /* Working variables */ int linesize, i; unsigned char *upic, *vpic; unsigned char *pic = image; - unsigned char y; /* switch for decoding YUV data */ + unsigned char y; /* Switch for decoding YUV data */ unsigned int width, height; width = cinfo->output_width; height = cinfo->output_height; if (width && ((width != netcam->width) || (height != netcam->height))) { - motion_log(ERR, TYPE_NETCAM, NO_ERRNO, + MOTION_LOG(ERR, TYPE_NETCAM, NO_ERRNO, "%s: JPEG image size %dx%d, JPEG was %dx%d", - __FUNCTION__, netcam->width, netcam->height, width, height); + netcam->width, netcam->height, width, height); jpeg_destroy_decompress(cinfo); netcam->jpeg_error |= 4; return netcam->jpeg_error; } - /* Set the output pointers (these come from YUV411P definition */ + /* Set the output pointers (these come from YUV411P definition. */ upic = pic + width * height; vpic = upic + (width * height) / 4; - /* YCbCr format will give us one byte each for YUV */ + /* YCbCr format will give us one byte each for YUV. */ linesize = cinfo->output_width * 3; - /* Allocate space for one line */ + /* Allocate space for one line. */ line = (cinfo->mem->alloc_sarray)((j_common_ptr) cinfo, JPOOL_IMAGE, cinfo->output_width * cinfo->output_components, 1); @@ -408,10 +406,10 @@ static int netcam_image_conv(netcam_context_ptr netcam, jpeg_destroy_decompress(cinfo); if (netcam->cnt->rotate_data.degrees > 0) - /* rotate as specified */ + /* Rotate as specified */ rotate_map(netcam->cnt, image); - motion_log(DBG, TYPE_NETCAM, NO_ERRNO, "%s: jpeg_error %d", __FUNCTION__, + MOTION_LOG(INF, TYPE_NETCAM, NO_ERRNO, "%s: jpeg_error %d", netcam->jpeg_error); return netcam->jpeg_error; @@ -424,8 +422,8 @@ static int netcam_image_conv(netcam_context_ptr netcam, * suitable for processing by motion. * * Parameters: - * netcam pointer to the netcam_context structure - * image pointer to a buffer for the returned image + * netcam pointer to the netcam_context structure. + * image pointer to a buffer for the returned image. * * Returns: * @@ -436,24 +434,23 @@ static int netcam_image_conv(netcam_context_ptr netcam, */ int netcam_proc_jpeg(netcam_context_ptr netcam, unsigned char *image) { - struct jpeg_decompress_struct cinfo; /* decompression control struct */ - int retval = 0; /* value returned to caller */ - int ret; /* working var */ + struct jpeg_decompress_struct cinfo; /* Decompression control struct. */ + int retval = 0; /* Value returned to caller. */ + int ret; /* Working var. */ /* * This routine is only called from the main thread. * We need to "protect" the "latest" image while we * decompress it. netcam_init_jpeg uses - * netcam->mutex to do this; + * netcam->mutex to do this. */ - motion_log(INF, TYPE_NETCAM, NO_ERRNO, "%s: processing jpeg image" - " - content length %d", __FUNCTION__, netcam->latest->content_length); + MOTION_LOG(INF, TYPE_NETCAM, NO_ERRNO, "%s: processing jpeg image" + " - content length %d", netcam->latest->content_length); ret = netcam_init_jpeg(netcam, &cinfo); if (ret != 0) { - motion_log(INF, TYPE_NETCAM, NO_ERRNO, "%s: ret %d", - __FUNCTION__, ret); + MOTION_LOG(INF, TYPE_NETCAM, NO_ERRNO, "%s: ret %d", ret); return ret; } @@ -461,27 +458,27 @@ int netcam_proc_jpeg(netcam_context_ptr netcam, unsigned char *image) * Do a sanity check on dimensions * If dimensions have changed we throw an * error message that will cause - * restart of Motion + * restart of Motion. */ if (netcam->width) { /* 0 means not yet init'ed */ if ((cinfo.output_width != netcam->width) || (cinfo.output_height != netcam->height)) { retval = NETCAM_RESTART_ERROR; - motion_log(ERR, TYPE_NETCAM, NO_ERRNO, "%s: Camera width/height mismatch " + MOTION_LOG(ERR, TYPE_NETCAM, NO_ERRNO, "%s: Camera width/height mismatch " "with JPEG image - expected %dx%d, JPEG %dx%d", - " retval %d", __FUNCTION__, netcam->width, netcam->height, + " retval %d", netcam->width, netcam->height, cinfo.output_width, cinfo.output_height, retval); return retval; } } - /* do the conversion */ + /* Do the conversion */ ret = netcam_image_conv(netcam, &cinfo, image); if (ret != 0) { retval |= NETCAM_JPEG_CONV_ERROR; - motion_log(INF, TYPE_NETCAM, NO_ERRNO, "%s: ret %d retval %d", - __FUNCTION__, ret, retval); + MOTION_LOG(INF, TYPE_NETCAM, NO_ERRNO, "%s: ret %d retval %d", + ret, retval); } return retval; @@ -491,18 +488,18 @@ int netcam_proc_jpeg(netcam_context_ptr netcam, unsigned char *image) * netcam_get_dimensions * * This function gets the height and width of the JPEG image - * located in the supplied netcam_image_buffer + * located in the supplied netcam_image_buffer. * * Parameters * - * netcam pointer to the netcam context + * netcam pointer to the netcam context. * - * Returns: Nothing, but fills in width and height into context + * Returns: Nothing, but fills in width and height into context. * */ void netcam_get_dimensions(netcam_context_ptr netcam) { - struct jpeg_decompress_struct cinfo; /* decompression control struct */ + struct jpeg_decompress_struct cinfo; /* Decompression control struct. */ int ret; ret = netcam_init_jpeg(netcam, &cinfo); @@ -513,6 +510,6 @@ void netcam_get_dimensions(netcam_context_ptr netcam) jpeg_destroy_decompress(&cinfo); - motion_log(INF, TYPE_NETCAM, NO_ERRNO, "%s: JFIF_marker %s PRESENT ret %d", - __FUNCTION__, netcam->JFIF_marker ? "IS" : "NOT", ret); + MOTION_LOG(INF, TYPE_NETCAM, NO_ERRNO, "%s: JFIF_marker %s PRESENT ret %d", + netcam->JFIF_marker ? "IS" : "NOT", ret); } diff --git a/netcam_wget.c b/netcam_wget.c index daba00b..71daac6 100644 --- a/netcam_wget.c +++ b/netcam_wget.c @@ -63,8 +63,8 @@ Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ `:', thus you can use it to retrieve, say, HTTP status line. All trailing whitespace is stripped from the header, and it is - zero-terminated. */ - + zero-terminated. + */ int header_get(netcam_context_ptr netcam, char **hdr, enum header_get_flags flags) { int i; @@ -85,9 +85,11 @@ int header_get(netcam_context_ptr netcam, char **hdr, enum header_get_flags flag if (!((flags & HG_NO_CONTINUATIONS) || i == 0 || (i == 1 && (*hdr)[0] == '\r'))) { char next; - /* If the header is non-empty, we need to check if - it continues on to the other line. We do that by - peeking at the next character. */ + /* + * If the header is non-empty, we need to check if + * it continues on to the other line. We do that by + * peeking at the next character. + */ res = rbuf_peek(netcam, &next); if (res == 0) { @@ -97,15 +99,16 @@ int header_get(netcam_context_ptr netcam, char **hdr, enum header_get_flags flag (*hdr)[i] = '\0'; return HG_ERROR; } - /* If the next character is HT or SP, just continue. */ - + /* If the next character is HT or SP, just continue. */ if (next == '\t' || next == ' ') continue; } - /* Strip trailing whitespace. (*hdr)[i] is the newline; - decrement I until it points to the last available - whitespace. */ + /* + * Strip trailing whitespace. (*hdr)[i] is the newline; + * decrement I until it points to the last available + * whitespace. + */ while (i > 0 && isspace((*hdr)[i - 1])) --i; @@ -124,13 +127,17 @@ int header_get(netcam_context_ptr netcam, char **hdr, enum header_get_flags flag return HG_OK; } -/* Check whether HEADER begins with NAME and, if yes, skip the `:' and - the whitespace, and call PROCFUN with the arguments of HEADER's - contents (after the `:' and space) and ARG. Otherwise, return 0. */ -int header_process (const char *header, const char *name, +/** + * header_process + * + * Check whether HEADER begins with NAME and, if yes, skip the `:' and + * the whitespace, and call PROCFUN with the arguments of HEADER's + * contents (after the `:' and space) and ARG. Otherwise, return 0. + */ +int header_process(const char *header, const char *name, int (*procfun)(const char *, void *), void *arg) { - /* Check whether HEADER matches NAME. */ + /* Check whether HEADER matches NAME. */ while (*name && (tolower (*name) == tolower (*header))) ++name, ++header; @@ -141,10 +148,14 @@ int header_process (const char *header, const char *name, return ((*procfun) (header, arg)); } -/* Helper functions for use with header_process(). */ +/* Helper functions for use with header_process(). */ -/* Extract a long integer from HEADER and store it to CLOSURE. If an - error is encountered, return 0, else 1. */ +/** + * header_extract_number + * + * Extract a long integer from HEADER and store it to CLOSURE. If an + * error is encountered, return 0, else 1. + */ int header_extract_number(const char *header, void *closure) { const char *p = header; @@ -160,7 +171,7 @@ int header_extract_number(const char *header, void *closure) /* Skip trailing whitespace. */ p += skip_lws (p); - /* We return the value, even if a format error follows */ + /* We return the value, even if a format error follows. */ *(long *)closure = result; /* Indicate failure if trailing garbage is present. */ @@ -170,7 +181,11 @@ int header_extract_number(const char *header, void *closure) return 1; } -/* Strdup HEADER, and place the pointer to CLOSURE. */ +/** + * header_strdup + * + * Strdup HEADER, and place the pointer to CLOSURE. + */ int header_strdup(const char *header, void *closure) { *(char **)closure = mystrdup(header); @@ -178,8 +193,11 @@ int header_strdup(const char *header, void *closure) } -/* Skip LWS (linear white space), if present. Returns number of - characters to skip. */ +/** + * skip_lws + * Skip LWS (linear white space), if present. Returns number of + * characters to skip. + */ int skip_lws(const char *string) { const char *p = string; @@ -191,11 +209,13 @@ int skip_lws(const char *string) } -/* - Encode the string S of length LENGTH to base64 format and place it - to STORE. STORE will be 0-terminated, and must point to a writable - buffer of at least 1+BASE64_LENGTH(length) bytes. -*/ +/** + * base64_encode + * + * Encode the string S of length LENGTH to base64 format and place it + * to STORE. STORE will be 0-terminated, and must point to a writable + * buffer of at least 1+BASE64_LENGTH(length) bytes. + */ void base64_encode(const char *s, char *store, int length) { /* Conversion table. */ @@ -213,7 +233,7 @@ void base64_encode(const char *s, char *store, int length) int i; unsigned char *p = (unsigned char *)store; - /* Transform the 3x8 bits to 4x6 bits, as required by base64. */ + /* Transform the 3x8 bits to 4x6 bits, as required by base64. */ for (i = 0; i < length; i += 3) { *p++ = tbl[s[0] >> 2]; *p++ = tbl[((s[0] & 3) << 4) + (s[1] >> 4)]; @@ -222,7 +242,7 @@ void base64_encode(const char *s, char *store, int length) s += 3; } - /* Pad the result if necessary... */ + /* Pad the result if necessary... */ if (i == length + 1) *(p - 1) = '='; else if (i == length + 2) @@ -232,6 +252,9 @@ void base64_encode(const char *s, char *store, int length) *p = '\0'; } +/** + * strdupdelim + */ char *strdupdelim(const char *beg, const char *end) { char *res = (char *)mymalloc(end - beg + 1); @@ -241,6 +264,9 @@ char *strdupdelim(const char *beg, const char *end) return res; } +/** + * http_process_type + */ int http_process_type(const char *hdr, void *arg) { char **result = (char **)arg; @@ -257,8 +283,11 @@ int http_process_type(const char *hdr, void *arg) return 1; } -/* This is a simple implementation of buffering IO-read functions. */ - +/** + * rbuf_initialize + * + * This is a simple implementation of buffering IO-read functions. + */ void rbuf_initialize(netcam_context_ptr netcam) { netcam->response->buffer_pos = netcam->response->buffer; @@ -271,7 +300,11 @@ int rbuf_read_bufferful(netcam_context_ptr netcam) sizeof (netcam->response->buffer)); } -/* Like rbuf_readchar(), only don't move the buffer position. */ +/** + * rbuf_peek + * + * Like rbuf_readchar(), only don't move the buffer position. + */ int rbuf_peek(netcam_context_ptr netcam, char *store) { if (!netcam->response->buffer_left) { @@ -292,11 +325,13 @@ int rbuf_peek(netcam_context_ptr netcam, char *store) return 1; } -/* - Flush RBUF's buffer to WHERE. Flush MAXSIZE bytes at most. - Returns the number of bytes actually copied. If the buffer is - empty, 0 is returned. -*/ +/** + * rbuf_flush + * + * Flush RBUF's buffer to WHERE. Flush MAXSIZE bytes at most. + * Returns the number of bytes actually copied. If the buffer is + * empty, 0 is returned. + */ int rbuf_flush(netcam_context_ptr netcam, char *where, int maxsize) { if (!netcam->response->buffer_left) { @@ -313,16 +348,20 @@ int rbuf_flush(netcam_context_ptr netcam, char *where, int maxsize) } } -/* Get the HTTP result code */ +/** + * http_result_code + * + * Get the HTTP result code + */ int http_result_code(const char *header) { char *cptr; - /* assure the header starts out right */ + /* Assure the header starts out right. */ if (strncmp(header, "HTTP", 4)) return -1; - /* find the space following the HTTP/1.x */ + /* Find the space following the HTTP/1.x */ if ((cptr = strchr(header+4, ' ')) == NULL) return -1; diff --git a/picture.c b/picture.c index bb57b62..219a973 100644 --- a/picture.c +++ b/picture.c @@ -15,8 +15,9 @@ #include #include -/* The following declarations and 5 functions are jpeg related - * functions used by put_jpeg_grey_memory and put_jpeg_yuv420p_memory +/* + * The following declarations and 5 functions are jpeg related + * functions used by put_jpeg_grey_memory and put_jpeg_yuv420p_memory. */ typedef struct { struct jpeg_destination_mgr pub; @@ -80,15 +81,19 @@ static GLOBAL(int) _jpeg_mem_size(j_compress_ptr cinfo) } -/* put_jpeg_yuv420p_memory converts an input image in the YUV420P format into a jpeg image and puts - * it in a memory buffer. +/** + * put_jpeg_yuv420p_memory + * Converts an input image in the YUV420P format into a jpeg image and puts + * it in a memory buffer. * Inputs: * - image_size is the size of the input image buffer. * - input_image is the image in YUV420P format. * - width and height are the dimensions of the image * - quality is the jpeg encoding quality 0-100% + * * Output: * - dest_image is a pointer to the jpeg image buffer + * * Returns buffer size of jpeg image */ static int put_jpeg_yuv420p_memory(unsigned char *dest_image, int image_size, @@ -106,7 +111,7 @@ static int put_jpeg_yuv420p_memory(unsigned char *dest_image, int image_size, data[1] = cb; data[2] = cr; - cinfo.err = jpeg_std_error(&jerr); // errors get written to stderr + cinfo.err = jpeg_std_error(&jerr); // Errors get written to stderr jpeg_create_compress(&cinfo); cinfo.image_width = width; @@ -116,10 +121,10 @@ static int put_jpeg_yuv420p_memory(unsigned char *dest_image, int image_size, jpeg_set_colorspace(&cinfo, JCS_YCbCr); - cinfo.raw_data_in = TRUE; // supply downsampled data + cinfo.raw_data_in = TRUE; // Supply downsampled data #if JPEG_LIB_VERSION >= 70 #warning using JPEG_LIB_VERSION >= 70 - cinfo.do_fancy_downsampling = FALSE; // fix segfaulst with v7 + cinfo.do_fancy_downsampling = FALSE; // Fix segfault with v7 #endif cinfo.comp_info[0].h_samp_factor = 2; cinfo.comp_info[0].v_samp_factor = 2; @@ -131,7 +136,7 @@ static int put_jpeg_yuv420p_memory(unsigned char *dest_image, int image_size, jpeg_set_quality(&cinfo, quality, TRUE); cinfo.dct_method = JDCT_FASTEST; - _jpeg_mem_dest(&cinfo, dest_image, image_size); // data written to mem + _jpeg_mem_dest(&cinfo, dest_image, image_size); // Data written to mem jpeg_start_compress (&cinfo, TRUE); @@ -154,15 +159,20 @@ static int put_jpeg_yuv420p_memory(unsigned char *dest_image, int image_size, return jpeg_image_size; } -/* put_jpeg_grey_memory converts an input image in the grayscale format into a jpeg image +/** + * put_jpeg_grey_memory + * Converts an input image in the grayscale format into a jpeg image. + * * Inputs: * - image_size is the size of the input image buffer. * - input_image is the image in grayscale format. * - width and height are the dimensions of the image * - quality is the jpeg encoding quality 0-100% + * * Output: * - dest_image is a pointer to the jpeg image buffer - * Returns buffer size of jpeg image + * + * Returns buffer size of jpeg image. */ static int put_jpeg_grey_memory(unsigned char *dest_image, int image_size, unsigned char *input_image, int width, int height, int quality) { @@ -175,14 +185,14 @@ static int put_jpeg_grey_memory(unsigned char *dest_image, int image_size, unsig jpeg_create_compress(&cjpeg); cjpeg.image_width = width; cjpeg.image_height = height; - cjpeg.input_components = 1; /* one colour component */ + cjpeg.input_components = 1; /* One colour component */ cjpeg.in_color_space = JCS_GRAYSCALE; jpeg_set_defaults(&cjpeg); jpeg_set_quality(&cjpeg, quality, TRUE); cjpeg.dct_method = JDCT_FASTEST; - _jpeg_mem_dest(&cjpeg, dest_image, image_size); // data written to mem + _jpeg_mem_dest(&cjpeg, dest_image, image_size); // Data written to mem jpeg_start_compress (&cjpeg, TRUE); @@ -200,14 +210,19 @@ static int put_jpeg_grey_memory(unsigned char *dest_image, int image_size, unsig return dest_image_size; } -/* put_jpeg_yuv420p_file converts an YUV420P coded image to a jpeg image and writes - * it to an already open file. +/** + * put_jpeg_yuv420p_file + * Converts an YUV420P coded image to a jpeg image and writes + * it to an already open file. + * * Inputs: * - image is the image in YUV420P format. * - width and height are the dimensions of the image * - quality is the jpeg encoding quality 0-100% + * * Output: * - The jpeg is written directly to the file given by the file pointer fp + * * Returns nothing */ static void put_jpeg_yuv420p_file(FILE *fp, unsigned char *image, int width, int height, int quality) @@ -224,7 +239,7 @@ static void put_jpeg_yuv420p_file(FILE *fp, unsigned char *image, int width, int data[1] = cb; data[2] = cr; - cinfo.err = jpeg_std_error(&jerr); // errors get written to stderr + cinfo.err = jpeg_std_error(&jerr); // Errors get written to stderr jpeg_create_compress(&cinfo); cinfo.image_width = width; @@ -234,10 +249,10 @@ static void put_jpeg_yuv420p_file(FILE *fp, unsigned char *image, int width, int jpeg_set_colorspace(&cinfo, JCS_YCbCr); - cinfo.raw_data_in = TRUE; // supply downsampled data + cinfo.raw_data_in = TRUE; // Supply downsampled data #if JPEG_LIB_VERSION >= 70 #warning using JPEG_LIB_VERSION >= 70 - cinfo.do_fancy_downsampling = FALSE; // fix segfaulst with v7 + cinfo.do_fancy_downsampling = FALSE; // Fix segfault with v7 #endif cinfo.comp_info[0].h_samp_factor = 2; cinfo.comp_info[0].v_samp_factor = 2; @@ -249,7 +264,7 @@ static void put_jpeg_yuv420p_file(FILE *fp, unsigned char *image, int width, int jpeg_set_quality(&cinfo, quality, TRUE); cinfo.dct_method = JDCT_FASTEST; - jpeg_stdio_dest(&cinfo, fp); // data written to file + jpeg_stdio_dest(&cinfo, fp); // Data written to file jpeg_start_compress(&cinfo, TRUE); for (j = 0; j < height; j += 16) { @@ -268,14 +283,18 @@ static void put_jpeg_yuv420p_file(FILE *fp, unsigned char *image, int width, int } -/* put_jpeg_grey_file converts an greyscale image to a jpeg image and writes - * it to an already open file. +/** + * put_jpeg_grey_file + * Converts an greyscale image to a jpeg image and writes + * it to an already open file. + * * Inputs: * - image is the image in greyscale format. * - width and height are the dimensions of the image * - quality is the jpeg encoding quality 0-100% * Output: * - The jpeg is written directly to the file given by the file pointer fp + * * Returns nothing */ static void put_jpeg_grey_file(FILE *picture, unsigned char *image, int width, int height, int quality) @@ -289,7 +308,7 @@ static void put_jpeg_grey_file(FILE *picture, unsigned char *image, int width, i jpeg_create_compress(&cjpeg); cjpeg.image_width = width; cjpeg.image_height = height; - cjpeg.input_components = 1; /* one colour component */ + cjpeg.input_components = 1; /* One colour component */ cjpeg.in_color_space = JCS_GRAYSCALE; jpeg_set_defaults(&cjpeg); @@ -312,13 +331,17 @@ static void put_jpeg_grey_file(FILE *picture, unsigned char *image, int width, i } -/* put_ppm_bgr24_file converts an greyscale image to a PPM image and writes - * it to an already open file. +/** + * put_ppm_bgr24_file + * Converts an greyscale image to a PPM image and writes + * it to an already open file. * Inputs: * - image is the image in YUV420P format. * - width and height are the dimensions of the image + * * Output: * - The PPM is written directly to the file given by the file pointer fp + * * Returns nothing */ static void put_ppm_bgr24_file(FILE *picture, unsigned char *image, int width, int height) @@ -331,9 +354,10 @@ static void put_ppm_bgr24_file(FILE *picture, unsigned char *image, int width, i int warningkiller; unsigned char rgb[3]; - /* ppm header - * width height - * maxval + /* + * ppm header + * width height + * maxval */ fprintf(picture, "P6\n"); fprintf(picture, "%d %d\n", width, height); @@ -379,7 +403,12 @@ static void put_ppm_bgr24_file(FILE *picture, unsigned char *image, int width, i } } -/* copy smartmask as an overlay into motion images and movies */ +/** + * overlay_smartmask + * Copies smartmask as an overlay into motion images and movies. + * + * Returns nothing. + */ void overlay_smartmask(struct context *cnt, unsigned char *out) { int i, x, v, width, height, line; @@ -392,7 +421,7 @@ void overlay_smartmask(struct context *cnt, unsigned char *out) width = imgs->width; height = imgs->height; - /* set V to 255 to make smartmask appear red */ + /* Set V to 255 to make smartmask appear red. */ out_v = out + v; out_u = out + i; for (i = 0; i < height; i += 2) { @@ -410,7 +439,7 @@ void overlay_smartmask(struct context *cnt, unsigned char *out) } } out_y = out; - /* set colour intensity for smartmask */ + /* Set colour intensity for smartmask. */ for (i = 0; i < imgs->motionsize; i++) { if (smartmask[i] == 0) *out_y = 0; @@ -418,7 +447,12 @@ void overlay_smartmask(struct context *cnt, unsigned char *out) } } -/* copy fixed mask as green overlay into motion images and movies */ +/** + * overlay_fixed_mask + * Copies fixed mask as green overlay into motion images and movies. + * + * Returns nothing. + */ void overlay_fixed_mask(struct context *cnt, unsigned char *out) { int i, x, v, width, height, line; @@ -431,7 +465,7 @@ void overlay_fixed_mask(struct context *cnt, unsigned char *out) width = imgs->width; height = imgs->height; - /* set U and V to 0 to make fixed mask appear green */ + /* Set U and V to 0 to make fixed mask appear green. */ out_v = out + v; out_u = out + i; for (i = 0; i < height; i += 2) { @@ -449,7 +483,7 @@ void overlay_fixed_mask(struct context *cnt, unsigned char *out) } } out_y = out; - /* set colour intensity for mask */ + /* Set colour intensity for mask. */ for (i = 0; i < imgs->motionsize; i++) { if (mask[i] == 0) *out_y = 0; @@ -457,7 +491,12 @@ void overlay_fixed_mask(struct context *cnt, unsigned char *out) } } -/* copy largest label as an overlay into motion images and movies */ +/** + * overlay_largest_label + * Copies largest label as an overlay into motion images and movies. + * + * Returns nothing. + */ void overlay_largest_label(struct context *cnt, unsigned char *out) { int i, x, v, width, height, line; @@ -470,7 +509,7 @@ void overlay_largest_label(struct context *cnt, unsigned char *out) width = imgs->width; height = imgs->height; - /* set U to 255 to make label appear blue */ + /* Set U to 255 to make label appear blue. */ out_u = out + i; out_v = out + v; for (i = 0; i < height; i += 2) { @@ -488,7 +527,7 @@ void overlay_largest_label(struct context *cnt, unsigned char *out) } } out_y = out; - /* set intensity for coloured label to have better visibility */ + /* Set intensity for coloured label to have better visibility. */ for (i = 0; i < imgs->motionsize; i++) { if (*labels++ & 32768) *out_y = 0; @@ -496,17 +535,21 @@ void overlay_largest_label(struct context *cnt, unsigned char *out) } } -/* put_picture_mem is used for the webcam feature. Depending on the image type - * (colour YUV420P or greyscale) the corresponding put_jpeg_X_memory function is called. +/** + * put_picture_mem + * Is used for the webcam feature. Depending on the image type + * (colour YUV420P or greyscale) the corresponding put_jpeg_X_memory function is called. * Inputs: * - cnt is the global context struct and only cnt->imgs.type is used. * - image_size is the size of the input image buffer * - *image points to the image buffer that contains the YUV420P or Grayscale image about to be put * - quality is the jpeg quality setting from the config file. + * * Output: * - **dest_image is a pointer to a pointer that points to the destination buffer in which the * converted image it put - * Function returns the dest_image_size if successful. Otherwise 0. + * + * Returns the dest_image_size if successful. Otherwise 0. */ int put_picture_memory(struct context *cnt, unsigned char* dest_image, int image_size, unsigned char *image, int quality) @@ -519,7 +562,8 @@ int put_picture_memory(struct context *cnt, unsigned char* dest_image, int image return put_jpeg_grey_memory(dest_image, image_size, image, cnt->imgs.width, cnt->imgs.height, quality); default: - motion_log(ERR, TYPE_ALL, NO_ERRNO, "%s: Unknow image type %d", __FUNCTION__, cnt->imgs.type); + MOTION_LOG(ERR, TYPE_ALL, NO_ERRNO, "%s: Unknow image type %d", + cnt->imgs.type); } return 0; @@ -538,7 +582,8 @@ void put_picture_fd(struct context *cnt, FILE *picture, unsigned char *image, in put_jpeg_grey_file(picture, image, cnt->imgs.width, cnt->imgs.height, quality); break; default: - motion_log(ERR, TYPE_ALL, NO_ERRNO, "%s: Unknow image type %d", __FUNCTION__, cnt->imgs.type); + MOTION_LOG(ERR, TYPE_ALL, NO_ERRNO, "%s: Unknow image type %d", + cnt->imgs.type); } } } @@ -550,18 +595,19 @@ void put_picture(struct context *cnt, char *file, unsigned char *image, int ftyp picture = myfopen(file, "w", BUFSIZE_1MEG); if (!picture) { - /* Report to syslog - suggest solution if the problem is access rights to target dir */ + /* Report to syslog - suggest solution if the problem is access rights to target dir. */ if (errno == EACCES) { - motion_log(ERR, TYPE_ALL, SHOW_ERRNO, + MOTION_LOG(ERR, TYPE_ALL, SHOW_ERRNO, "%s: Can't write picture to file %s - check access rights to target directory\n" "Thread is going to finish due to this fatal error", - __FUNCTION__, file); + file); cnt->finish = 1; cnt->restart = 0; return; } else { - /* If target dir is temporarily unavailable we may survive */ - motion_log(ERR, TYPE_ALL, SHOW_ERRNO, "%s: Can't write picture to file %s", __FUNCTION__, file); + /* If target dir is temporarily unavailable we may survive. */ + MOTION_LOG(ERR, TYPE_ALL, SHOW_ERRNO, "%s: Can't write picture to file %s", + file); return; } } @@ -571,7 +617,11 @@ void put_picture(struct context *cnt, char *file, unsigned char *image, int ftyp event(cnt, EVENT_FILECREATE, NULL, file, (void *)(unsigned long)ftype, NULL); } -/* Get the pgm file used as fixed mask */ +/** + * get_pgm + * Get the pgm file used as fixed mask + * + */ unsigned char *get_pgm(FILE *picture, int width, int height) { int x = 0 , y = 0, maxval; @@ -581,31 +631,31 @@ unsigned char *get_pgm(FILE *picture, int width, int height) line[255] = 0; if (!fgets(line, 255, picture)) { - motion_log(ERR, TYPE_ALL, SHOW_ERRNO, "%s: Could not read from ppm file", __FUNCTION__); + MOTION_LOG(ERR, TYPE_ALL, SHOW_ERRNO, "%s: Could not read from ppm file"); return NULL; } if (strncmp(line, "P5", 2)) { - motion_log(ERR, TYPE_ALL, SHOW_ERRNO, "%s: This is not a ppm file, starts with '%s'", - __FUNCTION__, line); + MOTION_LOG(ERR, TYPE_ALL, SHOW_ERRNO, "%s: This is not a ppm file, starts with '%s'", + line); return NULL; } - /* skip comment */ + /* Skip comment */ line[0] = '#'; while (line[0] == '#') if (!fgets(line, 255, picture)) return NULL; - /* check size */ + /* Check size */ if (sscanf(line, "%d %d", &x, &y) != 2) { - motion_log(ERR, TYPE_ALL, SHOW_ERRNO, "%s: Failed reading size in pgm file", __FUNCTION__); + MOTION_LOG(ERR, TYPE_ALL, SHOW_ERRNO, "%s: Failed reading size in pgm file"); return NULL; } if (x != width || y != height) { - motion_log(ERR, TYPE_ALL, SHOW_ERRNO, "%s: Wrong image size %dx%d should be %dx%d", - __FUNCTION__, x, y, width, height); + MOTION_LOG(ERR, TYPE_ALL, SHOW_ERRNO, "%s: Wrong image size %dx%d should be %dx%d", + x, y, width, height); return NULL; } @@ -616,17 +666,17 @@ unsigned char *get_pgm(FILE *picture, int width, int height) return NULL; if (sscanf(line, "%d", &maxval) != 1) { - motion_log(ERR, TYPE_ALL, SHOW_ERRNO, "%s: Failed reading maximum value in pgm file", __FUNCTION__); + MOTION_LOG(ERR, TYPE_ALL, SHOW_ERRNO, "%s: Failed reading maximum value in pgm file"); return NULL; } - /* read data */ + /* Read data */ image = mymalloc(width * height); for (y = 0; y < height; y++) { if ((int)fread(&image[y * width], 1, width, picture) != width) - motion_log(ERR, TYPE_ALL, SHOW_ERRNO, "%s: Failed reading image data from pgm file", __FUNCTION__); + MOTION_LOG(ERR, TYPE_ALL, SHOW_ERRNO, "%s: Failed reading image data from pgm file"); for (x = 0; x < width; x++) image[y * width + x] = (int)image[y * width + x] * 255 / maxval; @@ -636,9 +686,13 @@ unsigned char *get_pgm(FILE *picture, int width, int height) return image; } -/* If a mask file is asked for but does not exist this function - * creates an empty mask file in the right binary pgm format and - * and the right size - easy to edit with Gimp or similar tool. +/** + * put_fixed_mask + * If a mask file is asked for but does not exist this function + * creates an empty mask file in the right binary pgm format and + * and the right size - easy to edit with Gimp or similar tool. + * + * Returns nothing. */ void put_fixed_mask(struct context *cnt, const char *file) { @@ -646,37 +700,42 @@ void put_fixed_mask(struct context *cnt, const char *file) picture = myfopen(file, "w", BUFSIZE_1MEG); if (!picture) { - /* Report to syslog - suggest solution if the problem is access rights to target dir */ + /* Report to syslog - suggest solution if the problem is access rights to target dir. */ if (errno == EACCES) { - motion_log(ERR, TYPE_ALL, SHOW_ERRNO, + MOTION_LOG(ERR, TYPE_ALL, SHOW_ERRNO, "%s: can't write mask file %s - check access rights to target directory", - __FUNCTION__, file); + file); } else { - /* If target dir is temporarily unavailable we may survive */ - motion_log(ERR, TYPE_ALL, SHOW_ERRNO, "%s: can't write mask file %s", __FUNCTION__, file); + /* If target dir is temporarily unavailable we may survive. */ + MOTION_LOG(ERR, TYPE_ALL, SHOW_ERRNO, "%s: can't write mask file %s", file); } return; } - memset(cnt->imgs.out, 255, cnt->imgs.motionsize); /* initialize to unset */ + memset(cnt->imgs.out, 255, cnt->imgs.motionsize); /* Initialize to unset */ - /* Write pgm-header */ + /* Write pgm-header. */ fprintf(picture, "P5\n"); fprintf(picture, "%d %d\n", cnt->conf.width, cnt->conf.height); fprintf(picture, "%d\n", 255); - /* write pgm image data at once */ + /* Write pgm image data at once. */ if ((int)fwrite(cnt->imgs.out, cnt->conf.width, cnt->conf.height, picture) != cnt->conf.height) { - motion_log(ERR, TYPE_ALL, SHOW_ERRNO, "%s: Failed writing default mask as pgm file", __FUNCTION__); + MOTION_LOG(ERR, TYPE_ALL, SHOW_ERRNO, "%s: Failed writing default mask as pgm file"); return; } myfclose(picture); - motion_log(ERR, TYPE_ALL, NO_ERRNO, "%s: Creating empty mask %s\nPlease edit this file and " - "re-run motion to enable mask feature", __FUNCTION__, cnt->conf.mask_file); + MOTION_LOG(ERR, TYPE_ALL, NO_ERRNO, "%s: Creating empty mask %s\nPlease edit this file and " + "re-run motion to enable mask feature", cnt->conf.mask_file); } -/* save preview_shot */ +/** + * preview_save + * save preview_shot + * + * Returns nothing. + */ void preview_save(struct context *cnt) { int use_imagepath; @@ -687,12 +746,12 @@ void preview_save(struct context *cnt) struct image_data *saved_current_image; if (cnt->imgs.preview_image.diffs) { - /* Save current global context */ + /* Save current global context. */ saved_current_image = cnt->current_image; - /* Set global context to the image we are processing */ + /* Set global context to the image we are processing. */ cnt->current_image = &cnt->imgs.preview_image; - /* Use filename of movie i.o. jpeg_filename when set to 'preview' */ + /* Use filename of movie i.o. jpeg_filename when set to 'preview'. */ use_imagepath = strcmp(cnt->conf.imagepath, "preview"); #ifdef HAVE_FFMPEG @@ -706,7 +765,7 @@ void preview_save(struct context *cnt) strncpy(previewname, cnt->extpipefilename, basename_len); previewname[basename_len - 1] = '.'; } else { - /* Replace avi/mpg with jpg/ppm and keep the rest of the filename */ + /* Replace avi/mpg with jpg/ppm and keep the rest of the filename. */ basename_len = strlen(cnt->newfilename) - 3; strncpy(previewname, cnt->newfilename, basename_len); } @@ -715,12 +774,15 @@ void preview_save(struct context *cnt) strcat(previewname, imageext(cnt)); put_picture(cnt, previewname, cnt->imgs.preview_image.image , FTYPE_IMAGE); } else { - /* Save best preview-shot also when no movies are recorded or imagepath - * is used. Filename has to be generated - nothing available to reuse! */ - //printf("preview_shot: different filename or picture only!\n"); - - /* conf.imagepath would normally be defined but if someone deleted it by control interface - * it is better to revert to the default than fail */ + /* + * Save best preview-shot also when no movies are recorded or imagepath + * is used. Filename has to be generated - nothing available to reuse! + */ + MOTION_LOG(NTC, TYPE_ALL, NO_ERRNO, "%s: different filename or picture only!"); + /* + * 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.imagepath) imagepath = cnt->conf.imagepath; else @@ -732,7 +794,7 @@ void preview_save(struct context *cnt) put_picture(cnt, previewname, cnt->imgs.preview_image.image, FTYPE_IMAGE); } - /* restore global context values */ + /* Restore global context values. */ cnt->current_image = saved_current_image; } } diff --git a/rotate.c b/rotate.c index 2f50cfd..c89b633 100644 --- a/rotate.c +++ b/rotate.c @@ -21,7 +21,7 @@ * - fix for __bswap_32 macro collision * - fixed bug where initialization would be * incomplete for invalid degrees of rotation - * - now uses motion_log for error reporting + * - now uses MOTION_LOG for error reporting * v4 (26-Oct-2004) - new fix for width/height from imgs/conf due to * earlier misinterpretation * v3 (11-Oct-2004) - cleanup of width/height from imgs/conf @@ -238,12 +238,12 @@ void rotate_init(struct context *cnt) * we have a value that is safe from changes caused by motion-control. */ if ((cnt->conf.rotate_deg % 90) > 0) { - motion_log(ERR, TYPE_ALL, NO_ERRNO, "%s: Config option \"rotate\" not a multiple of 90: %d", - __FUNCTION__, cnt->conf.rotate_deg); - cnt->conf.rotate_deg = 0; /* disable rotation */ - cnt->rotate_data.degrees = 0; /* force return below */ + MOTION_LOG(ERR, TYPE_ALL, NO_ERRNO, "%s: Config option \"rotate\" not a multiple of 90: %d", + cnt->conf.rotate_deg); + cnt->conf.rotate_deg = 0; /* Disable rotation. */ + cnt->rotate_data.degrees = 0; /* Force return below. */ } else { - cnt->rotate_data.degrees = cnt->conf.rotate_deg % 360; /* range: 0..359 */ + cnt->rotate_data.degrees = cnt->conf.rotate_deg % 360; /* Range: 0..359 */ } /* @@ -291,8 +291,8 @@ void rotate_init(struct context *cnt) break; default: cnt->rotate_data.degrees = 0; - motion_log(ERR, TYPE_ALL, NO_ERRNO, "%s: Unsupported palette (%d), rotation is disabled", - __FUNCTION__, cnt->imgs.type); + MOTION_LOG(ERR, TYPE_ALL, NO_ERRNO, "%s: Unsupported palette (%d), rotation is disabled", + cnt->imgs.type); return; } @@ -348,7 +348,7 @@ int rotate_map(struct context *cnt, unsigned char *map) * or, it is in greyscale, in which case the pixel data simply consists * of width x height bytes. */ - int wh, wh4 = 0, w2 = 0, h2 = 0; /* width*height, width*height/4 etc. */ + int wh, wh4 = 0, w2 = 0, h2 = 0; /* width * height, width * height / 4 etc. */ int size, deg; int width, height; @@ -376,16 +376,16 @@ int rotate_map(struct context *cnt, unsigned char *map) switch (deg) { case 90: - /* first do the Y part */ + /* First do the Y part */ rot90cw(map, cnt->rotate_data.temp_buf, wh, width, height); if (cnt->imgs.type == VIDEO_PALETTE_YUV420P) { - /* then do U and V */ + /* Then do U and V */ rot90cw(map + wh, cnt->rotate_data.temp_buf + wh, wh4, w2, h2); rot90cw(map + wh + wh4, cnt->rotate_data.temp_buf + wh + wh4, wh4, w2, h2); } - /* then copy back from the temp buffer to map */ + /* Then copy back from the temp buffer to map. */ memcpy(map, cnt->rotate_data.temp_buf, size); break; @@ -403,21 +403,21 @@ int rotate_map(struct context *cnt, unsigned char *map) case 270: - /* first do the Y part */ + /* First do the Y part */ rot90ccw(map, cnt->rotate_data.temp_buf, wh, width, height); if (cnt->imgs.type == VIDEO_PALETTE_YUV420P) { - /* then do U and V */ + /* Then do U and V */ rot90ccw(map + wh, cnt->rotate_data.temp_buf + wh, wh4, w2, h2); rot90ccw(map + wh + wh4, cnt->rotate_data.temp_buf + wh + wh4, wh4, w2, h2); } - /* then copy back from the temp buffer to map */ + /* Then copy back from the temp buffer to map. */ memcpy(map, cnt->rotate_data.temp_buf, size); break; default: - /* invalid */ + /* Invalid */ return -1; } diff --git a/stream.c b/stream.c index fe4fc15..581760a 100644 --- a/stream.c +++ b/stream.c @@ -54,7 +54,7 @@ static int set_sock_timeout(int sock, int sec) tv.tv_usec = 0; if (setsockopt(sock, SOL_SOCKET, SO_RCVTIMEO, (char*) &tv, sizeof(tv))) { - motion_log(ERR, TYPE_STREAM, SHOW_ERRNO, "%s: set socket timeout failed", __FUNCTION__); + MOTION_LOG(ALR, TYPE_STREAM, SHOW_ERRNO, "%s: set socket timeout failed"); return 1; } return 0; @@ -103,8 +103,8 @@ static int read_http_request(int sock, char* buffer, int buflen, char* uri, int nread += readb; if (nread > buflen) { - motion_log(ERR, TYPE_STREAM, SHOW_ERRNO, "%s: motion-stream End buffer reached" - " waiting for buffer ending", __FUNCTION__); + MOTION_LOG(ERR, TYPE_STREAM, SHOW_ERRNO, "%s: motion-stream End buffer reached" + " waiting for buffer ending"); break; } @@ -112,7 +112,7 @@ static int read_http_request(int sock, char* buffer, int buflen, char* uri, int } /* - * Make sure the last read didn't fail. If it did, there's a + * Make sure the last read didn't fail. If it did, there's a * problem with the connection, so give up. */ if (nread == -1) { @@ -121,7 +121,7 @@ static int read_http_request(int sock, char* buffer, int buflen, char* uri, int return 0; } - motion_log(ERR, TYPE_STREAM, SHOW_ERRNO, "%s: motion-stream READ give up!", __FUNCTION__); + MOTION_LOG(ERR, TYPE_STREAM, SHOW_ERRNO, "%s: motion-stream READ give up!"); return 0; } @@ -134,7 +134,7 @@ static int read_http_request(int sock, char* buffer, int buflen, char* uri, int /* Check Protocol */ if (strcmp(protocol, "HTTP/1.0") && strcmp (protocol, "HTTP/1.1")) { - /* We don't understand this protocol. Report a bad response. */ + /* We don't understand this protocol. Report a bad response. */ ret = write(sock, bad_request_response_raw, sizeof(bad_request_response_raw)); return 0; } @@ -208,7 +208,7 @@ static void* handle_basic_auth(void* param) authentication = (char *) mymalloc(BASE64_LENGTH(auth_size) + 1); userpass = mymalloc(auth_size + 4); - /* base64_encode can read 3 bytes after the end of the string, initialize it */ + /* base64_encode can read 3 bytes after the end of the string, initialize it. */ memset(userpass, 0, auth_size + 4); strcpy(userpass, p->conf->stream_authentication); base64_encode(userpass, authentication, auth_size); @@ -225,18 +225,18 @@ static void* handle_basic_auth(void* param) /* Set socket to non blocking */ if (fcntl(p->sock, F_SETFL, p->sock_flags) < 0) { - motion_log(ERR, TYPE_STREAM, SHOW_ERRNO, "%s: fcntl", __FUNCTION__); + MOTION_LOG(ERR, TYPE_STREAM, SHOW_ERRNO, "%s: fcntl"); goto Error; } - /* lock the mutex */ + /* Lock the mutex */ pthread_mutex_lock(&stream_auth_mutex); stream_add_client(&p->cnt->stream, p->sock); p->cnt->stream_count++; p->thread_count--; - /* unlock the mutex */ + /* Unlock the mutex */ pthread_mutex_unlock(&stream_auth_mutex); free(p); @@ -265,7 +265,7 @@ typedef char HASHHEX[HASHHEXLEN+1]; #define OUT /** * CvtHex - * calculates H(A1) as per HTTP Digest spec -- taken from RFC 2617 + * Calculates H(A1) as per HTTP Digest spec -- taken from RFC 2617. */ static void CvtHex(IN HASH Bin, OUT HASHHEX Hex) { @@ -289,7 +289,7 @@ static void CvtHex(IN HASH Bin, OUT HASHHEX Hex) /** * DigestCalcHA1 - * calculates H(A1) as per spec + * Calculates H(A1) as per spec. */ static void DigestCalcHA1( IN char * pszAlg, @@ -326,7 +326,7 @@ static void DigestCalcHA1( /** * DigestCalcResponse - * calculates request-digest/response-digest as per HTTP Digest spec + * Calculates request-digest/response-digest as per HTTP Digest spec. */ static void DigestCalcResponse( IN HASHHEX HA1, /* H(A1) */ @@ -345,7 +345,7 @@ static void DigestCalcResponse( HASH RespHash; HASHHEX HA2Hex; - // calculate H(A2) + // Calculate H(A2) MD5Init(&Md5Ctx); MD5Update(&Md5Ctx, (unsigned char *)pszMethod, strlen(pszMethod)); MD5Update(&Md5Ctx, (unsigned char *)":", 1); @@ -358,7 +358,7 @@ static void DigestCalcResponse( MD5Final((unsigned char *)HA2, &Md5Ctx); CvtHex(HA2, HA2Hex); - // calculate response + // Calculate response MD5Init(&Md5Ctx); MD5Update(&Md5Ctx, (unsigned char *)HA1, HASHHEXLEN); MD5Update(&Md5Ctx, (unsigned char *)":", 1); @@ -442,15 +442,13 @@ static void* handle_md5_digest(void* param) snprintf(server_nonce, SERVER_NONCE_LEN, "%08x%08x", rand1, rand2); if (!p->conf->stream_authentication) { - motion_log(ERR, TYPE_STREAM, SHOW_ERRNO, "%s: Error no authentication data", - __FUNCTION__); + MOTION_LOG(ERR, TYPE_STREAM, SHOW_ERRNO, "%s: Error no authentication data"); goto InternalError; } h = strstr(p->conf->stream_authentication, ":"); if (!h) { - motion_log(ERR, TYPE_STREAM, SHOW_ERRNO, "%s: Error no authentication data (no ':' found)", - __FUNCTION__); + MOTION_LOG(ERR, TYPE_STREAM, SHOW_ERRNO, "%s: Error no authentication data (no ':' found)"); goto InternalError; } @@ -458,7 +456,7 @@ static void* handle_md5_digest(void* param) server_pass = (char*)malloc(strlen(h) + 1); if (!server_user || !server_pass) { - motion_log(ERR, TYPE_STREAM, SHOW_ERRNO, "%s: Error malloc failed", __FUNCTION__); + MOTION_LOG(ERR, TYPE_STREAM, SHOW_ERRNO, "%s: Error malloc failed"); goto InternalError; } @@ -581,7 +579,7 @@ static void* handle_md5_digest(void* param) /* Set socket to non blocking */ if (fcntl(p->sock, F_SETFL, p->sock_flags) < 0) { - motion_log(ERR, TYPE_STREAM, SHOW_ERRNO, "%s: fcntl", __FUNCTION__); + MOTION_LOG(ERR, TYPE_STREAM, SHOW_ERRNO, "%s: fcntl"); goto Error; } @@ -591,14 +589,14 @@ static void* handle_md5_digest(void* param) if(server_pass) free(server_pass); - /* lock the mutex */ + /* Lock the mutex */ pthread_mutex_lock(&stream_auth_mutex); stream_add_client(&p->cnt->stream, p->sock); p->cnt->stream_count++; p->thread_count--; - /* unlock the mutex */ + /* Unlock the mutex */ pthread_mutex_unlock(&stream_auth_mutex); free(p); @@ -654,8 +652,7 @@ static void do_client_auth(struct context *cnt, int sc) handle_func = handle_md5_digest; break; default: - motion_log(ERR, TYPE_STREAM, SHOW_ERRNO, "%s: Error unknown stream authentication method", - __FUNCTION__); + MOTION_LOG(ERR, TYPE_STREAM, SHOW_ERRNO, "%s: Error unknown stream authentication method"); goto Error; break; } @@ -668,13 +665,13 @@ static void do_client_auth(struct context *cnt, int sc) /* Set socket to blocking */ if ((flags = fcntl(sc, F_GETFL, 0)) < 0) { - motion_log(ERR, TYPE_STREAM, SHOW_ERRNO, "%s: fcntl", __FUNCTION__); + MOTION_LOG(ERR, TYPE_STREAM, SHOW_ERRNO, "%s: fcntl"); goto Error; } handle_param->sock_flags = flags; if (fcntl(sc, F_SETFL, flags & (~O_NONBLOCK)) < 0) { - motion_log(ERR, TYPE_STREAM, SHOW_ERRNO, "%s: fcntl", __FUNCTION__); + MOTION_LOG(ERR, TYPE_STREAM, SHOW_ERRNO, "%s: fcntl"); goto Error; } @@ -682,18 +679,18 @@ static void do_client_auth(struct context *cnt, int sc) goto Error; if (pthread_attr_init(&attr)) { - motion_log(ERR, TYPE_STREAM, SHOW_ERRNO, "%s: Error pthread_attr_init", __FUNCTION__); + MOTION_LOG(ERR, TYPE_STREAM, SHOW_ERRNO, "%s: Error pthread_attr_init"); goto Error; } if (pthread_create(&thread_id, &attr, handle_func, handle_param)) { - motion_log(ERR, TYPE_STREAM, SHOW_ERRNO, "%s: Error pthread_create", __FUNCTION__); + MOTION_LOG(ERR, TYPE_STREAM, SHOW_ERRNO, "%s: Error pthread_create"); goto Error; } pthread_detach(thread_id); if (pthread_attr_destroy(&attr)) - motion_log(ERR, TYPE_STREAM, SHOW_ERRNO, "%s: Error pthread_attr_destroy", __FUNCTION__); + MOTION_LOG(ERR, TYPE_STREAM, SHOW_ERRNO, "%s: Error pthread_attr_destroy"); return; @@ -737,8 +734,8 @@ int http_bindsock(int port, int local, int ipv6_enabled) optval = getaddrinfo(local ? "localhost" : NULL, portnumber, &hints, &res); if (optval != 0) { - motion_log(ERR, TYPE_STREAM, SHOW_ERRNO, "%s: getaddrinfo() for motion-stream socket failed: %s", - __FUNCTION__, gai_strerror(optval)); + MOTION_LOG(ALR, TYPE_STREAM, SHOW_ERRNO, "%s: getaddrinfo() for motion-stream socket failed: %s", + gai_strerror(optval)); if (res != NULL) freeaddrinfo(res); @@ -748,7 +745,7 @@ int http_bindsock(int port, int local, int ipv6_enabled) ressave = res; while (res) { - /* create socket */ + /* Create socket */ sl = socket(res->ai_family, res->ai_socktype, res->ai_protocol); getnameinfo(res->ai_addr, res->ai_addrlen, hbuf, @@ -759,36 +756,33 @@ int http_bindsock(int port, int local, int ipv6_enabled) /* Reuse Address */ setsockopt(sl, SOL_SOCKET, SO_REUSEADDR, &optval, sizeof(int)); - motion_log(ERR, TYPE_STREAM, NO_ERRNO, "%s: motion-stream testing : %s addr: %s port: %s", - __FUNCTION__, res->ai_family == AF_INET ? "IPV4":"IPV6", hbuf, sbuf); + MOTION_LOG(EMG, TYPE_STREAM, NO_ERRNO, "%s: motion-stream testing : %s addr: %s port: %s", + res->ai_family == AF_INET ? "IPV4":"IPV6", hbuf, sbuf); if (bind(sl, res->ai_addr, res->ai_addrlen) == 0) { - motion_log(ERR, TYPE_STREAM, NO_ERRNO, "%s: motion-stream Bound : %s addr: %s port: %s", - __FUNCTION__, res->ai_family == AF_INET ? "IPV4":"IPV6", hbuf, sbuf); + MOTION_LOG(EMG, TYPE_STREAM, NO_ERRNO, "%s: motion-stream Bound : %s addr: %s port: %s", + res->ai_family == AF_INET ? "IPV4":"IPV6", hbuf, sbuf); break; } - motion_log(ERR, TYPE_STREAM, SHOW_ERRNO, "%s: motion-stream bind() failed, retrying", - __FUNCTION__); + MOTION_LOG(ALR, TYPE_STREAM, SHOW_ERRNO, "%s: motion-stream bind() failed, retrying"); close(sl); sl = -1; } - motion_log(ERR, TYPE_STREAM, SHOW_ERRNO, "%s: motion-stream socket failed, retrying", - __FUNCTION__); + MOTION_LOG(ALR, TYPE_STREAM, SHOW_ERRNO, "%s: motion-stream socket failed, retrying"); res = res->ai_next; } freeaddrinfo(ressave); if (sl < 0) { - motion_log(ERR, TYPE_STREAM, SHOW_ERRNO, "%s: motion-stream creating socket/bind ERROR", - __FUNCTION__); + MOTION_LOG(ALR, TYPE_STREAM, SHOW_ERRNO, "%s: motion-stream creating socket/bind ERROR"); return -1; } if (listen(sl, DEF_MAXWEBQUEUE) == -1) { - motion_log(ERR, TYPE_STREAM, SHOW_ERRNO, "%s: motion-stream listen() ERROR", __FUNCTION__); + MOTION_LOG(ALR, TYPE_STREAM, SHOW_ERRNO, "%s: motion-stream listen() ERROR"); close(sl); sl = -1; } @@ -815,7 +809,7 @@ static int http_acceptsock(int sl) return sc; } - motion_log(ERR, TYPE_STREAM, SHOW_ERRNO, "%s: motion-stream accept()", __FUNCTION__); + MOTION_LOG(ALR, TYPE_STREAM, SHOW_ERRNO, "%s: motion-stream accept()"); return -1; } @@ -830,16 +824,16 @@ static int http_acceptsock(int sl) */ static void stream_flush(struct stream *list, int *stream_count, int lim) { - int written; /* the number of bytes actually written */ - struct stream *client; /* pointer to the client being served */ - int workdone = 0; /* flag set any time data is successfully - written */ + int written; /* The number of bytes actually written. */ + struct stream *client; /* Pointer to the client being served. */ + int workdone = 0; /* Flag set any time data is successfully + written. */ client = list->next; while (client) { - /* If data waiting for client, try to send it */ + /* If data waiting for client, try to send it. */ if (client->tmpbuffer) { /* @@ -865,7 +859,7 @@ static void stream_flush(struct stream *list, int *stream_count, int lim) /* * If any data has been written, update the - * data pointer and set the workdone flag + * data pointer and set the workdone flag. */ if (written > 0) { client->filepos += written; @@ -882,13 +876,13 @@ static void stream_flush(struct stream *list, int *stream_count, int lim) */ if ((client->filepos >= client->tmpbuffer->size) || (written < 0 && errno != EAGAIN)) { - /* If no other clients need this buffer, free it */ + /* If no other clients need this buffer, free it. */ if (--client->tmpbuffer->ref <= 0) { free(client->tmpbuffer->ptr); free(client->tmpbuffer); } - /* Mark this client's buffer as empty */ + /* Mark this client's buffer as empty. */ client->tmpbuffer = NULL; client->nr++; } @@ -897,7 +891,7 @@ static void stream_flush(struct stream *list, int *stream_count, int lim) * If the client is no longer connected, or the total * number of frames already sent to this client is * greater than our configuration limit, disconnect - * the client and free the stream struct + * the client and free the stream struct. */ if ((written < 0 && errno != EAGAIN) || (lim && !client->tmpbuffer && client->nr > lim)) { @@ -914,13 +908,13 @@ static void stream_flush(struct stream *list, int *stream_count, int lim) free(tmp); (*stream_count)--; } - } /* end if (client->tmpbuffer) */ + } /* End if (client->tmpbuffer) */ /* * Step the the next client in the list. If we get to the * end of the list, check if anything was written during * that loop; (if so) reset the 'workdone' flag and go back - * to the beginning + * to the beginning. */ client = client->next; @@ -928,7 +922,7 @@ static void stream_flush(struct stream *list, int *stream_count, int lim) client = list->next; workdone = 0; } - } /* end while (client) */ + } /* End while (client) */ } /** @@ -969,8 +963,7 @@ static void stream_add_client(struct stream *list, int sc) new->socket = sc; if ((new->tmpbuffer = stream_tmpbuffer(sizeof(header))) == NULL) { - motion_log(ERR, TYPE_STREAM, SHOW_ERRNO, "%s: Error creating tmpbuffer in stream_add_client", - __FUNCTION__); + MOTION_LOG(ERR, TYPE_STREAM, SHOW_ERRNO, "%s: Error creating tmpbuffer in stream_add_client"); } else { memcpy(new->tmpbuffer->ptr, header, sizeof(header)-1); new->tmpbuffer->size = sizeof(header)-1; @@ -1047,7 +1040,8 @@ static int stream_check_write(struct stream *list) */ int stream_init(struct context *cnt) { - cnt->stream.socket = http_bindsock(cnt->conf.stream_port, cnt->conf.stream_localhost, cnt->conf.ipv6_enabled); + cnt->stream.socket = http_bindsock(cnt->conf.stream_port, cnt->conf.stream_localhost, + cnt->conf.ipv6_enabled); cnt->stream.next = NULL; cnt->stream.prev = NULL; return cnt->stream.socket; @@ -1063,8 +1057,8 @@ void stream_stop(struct context *cnt) struct stream *list; struct stream *next = cnt->stream.next; - motion_log(ERR, TYPE_STREAM, NO_ERRNO, "%s: Closing motion-stream listen socket" - " & active motion-stream sockets", __FUNCTION__); + MOTION_LOG(ALR, TYPE_STREAM, NO_ERRNO, "%s: Closing motion-stream listen socket" + " & active motion-stream sockets"); close(cnt->stream.socket); cnt->stream.socket = -1; @@ -1082,8 +1076,8 @@ void stream_stop(struct context *cnt) free(list); } - motion_log(ERR, TYPE_STREAM, NO_ERRNO, "%s: Closed motion-stream listen socket" - " & active motion-stream sockets", __FUNCTION__); + MOTION_LOG(ALR, TYPE_STREAM, NO_ERRNO, "%s: Closed motion-stream listen socket" + " & active motion-stream sockets"); } /* @@ -1109,16 +1103,16 @@ void stream_put(struct context *cnt, unsigned char *image) fd_set fdread; int sl = cnt->stream.socket; int sc; - /* the following string has an extra 16 chars at end for length */ + /* Tthe following string has an extra 16 chars at end for length. */ const char jpeghead[] = "--BoundaryString\r\n" "Content-type: image/jpeg\r\n" "Content-Length: "; - int headlength = sizeof(jpeghead) - 1; /* don't include terminator */ - char len[20]; /* will be used for sprintf, must be >= 16 */ + int headlength = sizeof(jpeghead) - 1; /* Don't include terminator. */ + char len[20]; /* Will be used for sprintf, must be >= 16 */ /* - * timeout struct used to timeout the time we wait for a client - * and we do not wait at all + * Timeout struct used to timeout the time we wait for a client + * and we do not wait at all. */ timeout.tv_sec = 0; timeout.tv_usec = 0; @@ -1143,25 +1137,25 @@ void stream_put(struct context *cnt, unsigned char *image) } } - /* lock the mutex */ + /* Lock the mutex */ if (cnt->conf.stream_auth_method != 0) pthread_mutex_lock(&stream_auth_mutex); - /* call flush to send any previous partial-sends which are waiting */ + /* Call flush to send any previous partial-sends which are waiting. */ stream_flush(&cnt->stream, &cnt->stream_count, cnt->conf.stream_limit); - /* Check if any clients have available buffers */ + /* Check if any clients have available buffers. */ if (stream_check_write(&cnt->stream)) { /* - * yes - create a new tmpbuffer for current image. + * Yes - create a new tmpbuffer for current image. * Note that this should create a buffer which is *much* larger * than necessary, but it is difficult to estimate the * minimum size actually required. */ tmpbuffer = stream_tmpbuffer(cnt->imgs.size); - /* check if allocation went ok */ + /* Check if allocation was ok. */ if (tmpbuffer) { int imgsize; @@ -1180,18 +1174,18 @@ void stream_put(struct context *cnt, unsigned char *image) */ memcpy(wptr, jpeghead, headlength); - /* update our working pointer to point past header */ + /* Update our working pointer to point past header. */ wptr += headlength; - /* create a jpeg image and place into tmpbuffer */ + /* Create a jpeg image and place into tmpbuffer. */ tmpbuffer->size = put_picture_memory(cnt, wptr, cnt->imgs.size, image, cnt->conf.stream_quality); - /* fill in the image length into the header */ + /* Fill in the image length into the header. */ imgsize = sprintf(len, "%9ld\r\n\r\n", tmpbuffer->size); memcpy(wptr - imgsize, len, imgsize); - /* append a CRLF for good measure */ + /* Append a CRLF for good measure. */ memcpy(wptr + tmpbuffer->size, "\r\n", 2); /* @@ -1207,8 +1201,7 @@ void stream_put(struct context *cnt, unsigned char *image) */ stream_add_write(&cnt->stream, tmpbuffer, cnt->conf.stream_maxrate); } else { - motion_log(ERR, TYPE_STREAM, SHOW_ERRNO, "%s: Error creating tmpbuffer", - __FUNCTION__); + MOTION_LOG(ERR, TYPE_STREAM, SHOW_ERRNO, "%s: Error creating tmpbuffer"); } } @@ -1218,7 +1211,7 @@ void stream_put(struct context *cnt, unsigned char *image) */ stream_flush(&cnt->stream, &cnt->stream_count, cnt->conf.stream_limit); - /* unlock the mutex */ + /* Unlock the mutex */ if (cnt->conf.stream_auth_method != 0) pthread_mutex_unlock(&stream_auth_mutex); diff --git a/track.c b/track.c index 1e6781b..438c110 100644 --- a/track.c +++ b/track.c @@ -74,7 +74,7 @@ unsigned int track_center(struct context *cnt, int dev ATTRIBUTE_UNUSED, unsigned int ret; ret = stepper_center(cnt, xoff, yoff); if (!ret) { - motion_log(ALR, TYPE_TRACK, SHOW_ERRNO, "%s: internal error", __FUNCTION__); + MOTION_LOG(ALR, TYPE_TRACK, SHOW_ERRNO, "%s: internal error"); return 0; } else return ret; @@ -94,8 +94,8 @@ unsigned int track_center(struct context *cnt, int dev ATTRIBUTE_UNUSED, else if (cnt->track.type == TRACK_TYPE_GENERIC) return 10; // FIX ME. I chose to return something reasonable. - motion_log(ALR, TYPE_TRACK, SHOW_ERRNO, "%s: internal error, %hu is not a known track-type", - __FUNCTION__, cnt->track.type); + MOTION_LOG(ALR, TYPE_TRACK, SHOW_ERRNO, "%s: internal error, %hu is not a known track-type", + cnt->track.type); return 0; } @@ -125,22 +125,20 @@ unsigned int track_move(struct context *cnt, int dev, struct coord *cent, struct else if (cnt->track.type == TRACK_TYPE_GENERIC) return cnt->track.move_wait; // FIX ME. I chose to return something reasonable. - motion_log(ALR, TYPE_TRACK, SHOW_ERRNO, "%s: internal error, %hu is not a known track-type", - __FUNCTION__, cnt->track.type); + MOTION_LOG(ALR, TYPE_TRACK, SHOW_ERRNO, "%s: internal error, %hu is not a known track-type", + cnt->track.type); return 0; } - /****************************************************************************** Stepper motor on serial port http://www.lavrsen.dk/twiki/bin/view/Motion/MotionTracking http://www.lavrsen.dk/twiki/bin/view/Motion/MotionTrackerAPI ******************************************************************************/ - static unsigned int stepper_command(struct context *cnt, unsigned int motor, - unsigned int command, unsigned int data) + unsigned int command, unsigned int data) { char buffer[3]; time_t timeout = time(NULL); @@ -150,15 +148,15 @@ static unsigned int stepper_command(struct context *cnt, unsigned int motor, buffer[2] = data; if (write(cnt->track.dev, buffer, 3) != 3) { - motion_log(ERR, TYPE_TRACK, SHOW_ERRNO, "%s: port %s dev fd %i, motor %hu command %hu data %hu", - __FUNCTION__, cnt->track.port, cnt->track.dev, motor, command, data); + MOTION_LOG(NTC, TYPE_TRACK, SHOW_ERRNO, "%s: port %s dev fd %i, motor %hu command %hu data %hu", + cnt->track.port, cnt->track.dev, motor, command, data); return 0; } while (read(cnt->track.dev, buffer, 1) != 1 && time(NULL) < timeout + 1); if (time(NULL) >= timeout + 2) { - motion_log(ERR, TYPE_TRACK, SHOW_ERRNO, "%s: Status byte timeout!", __FUNCTION__); + MOTION_LOG(ERR, TYPE_TRACK, SHOW_ERRNO, "%s: Status byte timeout!"); return 0; } @@ -177,11 +175,11 @@ static unsigned int stepper_center(struct context *cnt, int x_offset, int y_offs struct termios adtio; if (cnt->track.dev < 0) { - motion_log(ERR, TYPE_TRACK, NO_ERRNO, "%s: Try to open serial device %s", __FUNCTION__, cnt->track.port); + MOTION_LOG(NTC, TYPE_TRACK, NO_ERRNO, "%s: Try to open serial device %s", cnt->track.port); if ((cnt->track.dev = open(cnt->track.port, O_RDWR | O_NOCTTY)) < 0) { - motion_log(ALR, TYPE_TRACK, SHOW_ERRNO, "%s: Unable to open serial device %s", - __FUNCTION__, cnt->track.port); + MOTION_LOG(ALR, TYPE_TRACK, SHOW_ERRNO, "%s: Unable to open serial device %s", + cnt->track.port); return 0; } @@ -195,13 +193,13 @@ static unsigned int stepper_center(struct context *cnt, int x_offset, int y_offs tcflush (cnt->track.dev, TCIFLUSH); if (tcsetattr(cnt->track.dev, TCSANOW, &adtio) < 0) { - motion_log(ALR, TYPE_TRACK, SHOW_ERRNO, "%s: Unable to initialize serial device %s", - __FUNCTION__, cnt->track.port); + MOTION_LOG(ALR, TYPE_TRACK, SHOW_ERRNO, "%s: Unable to initialize serial device %s", + cnt->track.port); cnt->track.dev = -1; return 0; } - motion_log(ALR, TYPE_TRACK, NO_ERRNO, "%s: Opened serial device %s and initialize, fd %i", - __FUNCTION__, cnt->track.port, cnt->track.dev); + MOTION_LOG(NTC, TYPE_TRACK, NO_ERRNO, "%s: Opened serial device %s and initialize, fd %i", + cnt->track.port, cnt->track.dev); } /* x-axis */ @@ -237,17 +235,17 @@ static unsigned int stepper_move(struct context *cnt, unsigned int command = 0, data = 0; if (cnt->track.dev < 0) { - motion_log(ERR, TYPE_TRACK, NO_ERRNO, "%s: No device %s started yet , trying stepper_center()", - __FUNCTION__, cnt->track.port); + MOTION_LOG(WRN, TYPE_TRACK, NO_ERRNO, "%s: No device %s started yet , trying stepper_center()", + cnt->track.port); if (!stepper_center(cnt, 0, 0)) { - motion_log(ALR, TYPE_TRACK, SHOW_ERRNO, "%s: failed to initialize stepper device on %s , fd [%i].", - __FUNCTION__, cnt->track.port, cnt->track.dev); + MOTION_LOG(ALR, TYPE_TRACK, SHOW_ERRNO, "%s: failed to initialize stepper device on %s , fd [%i].", + cnt->track.port, cnt->track.dev); return 0; } - motion_log(ERR, TYPE_TRACK, NO_ERRNO, "%s: succeed , device started %s , fd [%i]", - __FUNCTION__, cnt->track.port, cnt->track.dev); + MOTION_LOG(NTC, TYPE_TRACK, NO_ERRNO, "%s: succeed , device started %s , fd [%i]", + cnt->track.port, cnt->track.dev); } /* x-axis */ @@ -287,7 +285,6 @@ static unsigned int stepper_move(struct context *cnt, return cnt->track.move_wait; } - /****************************************************************************** * Servo motor on serial port * http://www.lavrsen.dk/twiki/bin/view/Motion/MotionTracking @@ -299,8 +296,8 @@ static int servo_open(struct context *cnt) struct termios adtio; if ((cnt->track.dev = open(cnt->track.port, O_RDWR | O_NOCTTY)) < 0) { - motion_log(ALR, TYPE_TRACK, SHOW_ERRNO, "%s: Unable to open serial device %s", - __FUNCTION__, cnt->track.port); + MOTION_LOG(ALR, TYPE_TRACK, SHOW_ERRNO, "%s: Unable to open serial device %s", + cnt->track.port); return 0; } @@ -314,21 +311,21 @@ static int servo_open(struct context *cnt) tcflush (cnt->track.dev, TCIFLUSH); if (tcsetattr(cnt->track.dev, TCSANOW, &adtio) < 0) { - motion_log(ALR, TYPE_TRACK, NO_ERRNO, "%s: Unable to initialize serial device %s", - __FUNCTION__, cnt->track.port); + MOTION_LOG(ALR, TYPE_TRACK, NO_ERRNO, "%s: Unable to initialize serial device %s", + cnt->track.port); cnt->track.dev = -1; return 0; } - motion_log(ERR, TYPE_TRACK, NO_ERRNO, "%s: Opened serial device %s and initialize, fd %i", - __FUNCTION__, cnt->track.port, cnt->track.dev); + MOTION_LOG(NTC, TYPE_TRACK, NO_ERRNO, "%s: Opened serial device %s and initialize, fd %i", + cnt->track.port, cnt->track.dev); return 1; } static unsigned int servo_command(struct context *cnt, unsigned int motor, - unsigned int command, unsigned int data) + unsigned int command, unsigned int data) { unsigned char buffer[3]; time_t timeout = time(NULL); @@ -338,23 +335,23 @@ static unsigned int servo_command(struct context *cnt, unsigned int motor, buffer[2] = data; - motion_log(NTC, TYPE_TRACK, NO_ERRNO, "%s: SENDS port %s dev fd %i, motor %hu command %hu data %hu", - __FUNCTION__, cnt->track.port, cnt->track.dev, buffer[0], buffer[1], buffer[2]); + MOTION_LOG(NTC, TYPE_TRACK, NO_ERRNO, "%s: SENDS port %s dev fd %i, motor %hu command %hu data %hu", + cnt->track.port, cnt->track.dev, buffer[0], buffer[1], buffer[2]); if (write(cnt->track.dev, buffer, 3) != 3) { - motion_log(NTC, TYPE_TRACK, NO_ERRNO, "%s: port %s dev fd %i, motor %hu command %hu data %hu", - __FUNCTION__, cnt->track.port, cnt->track.dev, motor, command, data); + MOTION_LOG(NTC, TYPE_TRACK, NO_ERRNO, "%s: port %s dev fd %i, motor %hu command %hu data %hu", + cnt->track.port, cnt->track.dev, motor, command, data); return 0; } while (read(cnt->track.dev, buffer, 1) != 1 && time(NULL) < timeout + 1); if (time(NULL) >= timeout + 2) { - motion_log(ERR, TYPE_TRACK, NO_ERRNO, "%s: Status byte timeout!", __FUNCTION__); + MOTION_LOG(ERR, TYPE_TRACK, NO_ERRNO, "%s: Status byte timeout!"); return 0; } - motion_log(NTC, TYPE_TRACK, NO_ERRNO, "%s: Command return %d", __FUNCTION__, buffer[0]); + MOTION_LOG(NTC, TYPE_TRACK, NO_ERRNO, "%s: Command return %d", buffer[0]); return buffer[0]; @@ -371,7 +368,6 @@ static unsigned int servo_position(struct context *cnt, unsigned int motor) } - /** * servo_move * Does relative movements to current position. @@ -387,13 +383,13 @@ static unsigned int servo_move(struct context *cnt, struct coord *cent, /* If device is not open yet , open and center */ if (cnt->track.dev < 0) { if (!servo_center(cnt, 0, 0)) { - motion_log(ALR, TYPE_TRACK, NO_ERRNO, "%s: Problem opening servo!", __FUNCTION__); + MOTION_LOG(ALR, TYPE_TRACK, NO_ERRNO, "%s: Problem opening servo!"); return 0; } } - motion_log(NTC, TYPE_TRACK, NO_ERRNO, "%s: cent->x %d, cent->y %d, reversex %d," - "reversey %d manual %d", __FUNCTION__, cent->x , cent->y, + MOTION_LOG(NTC, TYPE_TRACK, NO_ERRNO, "%s: cent->x %d, cent->y %d, reversex %d," + "reversey %d manual %d", cent->x , cent->y, cnt->track.motorx_reverse, cnt->track.motory_reverse, manual); if (manual) { @@ -414,12 +410,11 @@ static unsigned int servo_move(struct context *cnt, struct coord *cent, if ((data + position > (unsigned)cnt->track.maxx) || (position - offset < (unsigned)cnt->track.minx)) { - motion_log(ALR, TYPE_TRACK, NO_ERRNO, "%s: x %d value out of range! (%d - %d)", - __FUNCTION__, data, cnt->track.minx, cnt->track.maxx); + MOTION_LOG(ALR, TYPE_TRACK, NO_ERRNO, "%s: x %d value out of range! (%d - %d)", + data, cnt->track.minx, cnt->track.maxx); return 0; } - /* Set Speed , TODO : it should be done only when speed changes */ servo_command(cnt, cnt->track.motorx, SERVO_COMMAND_SPEED, cnt->track.speed); servo_command(cnt, cnt->track.motorx, command, data); @@ -440,8 +435,8 @@ static unsigned int servo_move(struct context *cnt, struct coord *cent, if ((data + position > (unsigned)cnt->track.maxy) || (position - offset < (unsigned)cnt->track.miny)) { - motion_log(ALR, TYPE_TRACK, NO_ERRNO, "%s: y %d value out of range! (%d - %d)", - __FUNCTION__, data, cnt->track.miny, cnt->track.maxy); + MOTION_LOG(ALR, TYPE_TRACK, NO_ERRNO, "%s: y %d value out of range! (%d - %d)", + data, cnt->track.miny, cnt->track.maxy); return 0; } @@ -472,7 +467,7 @@ static unsigned int servo_move(struct context *cnt, struct coord *cent, } - motion_log(NTC, TYPE_TRACK, NO_ERRNO, "%s: X offset %d", __FUNCTION__, data); + MOTION_LOG(NTC, TYPE_TRACK, NO_ERRNO, "%s: X offset %d", data); data = data * cnt->track.stepsize / imgs->width; @@ -483,8 +478,8 @@ static unsigned int servo_move(struct context *cnt, struct coord *cent, if ((position + data > (unsigned)cnt->track.maxx) || (position - data < (unsigned)cnt->track.minx)) { - motion_log(ALR, TYPE_TRACK, NO_ERRNO, "%s: x %d value out of range! (%d - %d)", - __FUNCTION__, data, cnt->track.minx, cnt->track.maxx); + MOTION_LOG(ALR, TYPE_TRACK, NO_ERRNO, "%s: x %d value out of range! (%d - %d)", + data, cnt->track.minx, cnt->track.maxx); return 0; } @@ -493,8 +488,8 @@ static unsigned int servo_move(struct context *cnt, struct coord *cent, servo_command(cnt, cnt->track.motorx, SERVO_COMMAND_SPEED, cnt->track.speed); servo_command(cnt, cnt->track.motorx, command, data); - motion_log(NTC, TYPE_TRACK, NO_ERRNO, "%s: X cent->x %d, cent->y %d, reversex %d," - "reversey %d motorx %d data %d command %d", __FUNCTION__, + MOTION_LOG(NTC, TYPE_TRACK, NO_ERRNO, "%s: X cent->x %d, cent->y %d, reversex %d," + "reversey %d motorx %d data %d command %d", cent->x, cent->y, cnt->track.motorx_reverse, cnt->track.motory_reverse, cnt->track.motorx, data, command); } @@ -519,7 +514,7 @@ static unsigned int servo_move(struct context *cnt, struct coord *cent, data = cent->y - imgs->height / 2; } - motion_log(NTC, TYPE_TRACK, NO_ERRNO, "%s: Y offset %d", __FUNCTION__, data); + MOTION_LOG(NTC, TYPE_TRACK, NO_ERRNO, "%s: Y offset %d", data); data = data * cnt->track.stepsize / imgs->height; @@ -530,8 +525,8 @@ static unsigned int servo_move(struct context *cnt, struct coord *cent, if ((position + data > (unsigned)cnt->track.maxy) || (position - data < (unsigned)cnt->track.miny)) { - motion_log(ALR, TYPE_TRACK, NO_ERRNO, "%s: y %d value out of range! (%d - %d)", - __FUNCTION__, data, cnt->track.miny, cnt->track.maxy); + MOTION_LOG(ALR, TYPE_TRACK, NO_ERRNO, "%s: y %d value out of range! (%d - %d)", + data, cnt->track.miny, cnt->track.maxy); return 0; } @@ -539,8 +534,8 @@ static unsigned int servo_move(struct context *cnt, struct coord *cent, servo_command(cnt, cnt->track.motory, SERVO_COMMAND_SPEED, cnt->track.speed); servo_command(cnt, cnt->track.motory, command, data); - motion_log(NTC, TYPE_TRACK, NO_ERRNO, "%s: Y cent->x %d, cent->y %d, reversex %d," - "reversey %d motory %d data %d command %d", __FUNCTION__, + MOTION_LOG(NTC, TYPE_TRACK, NO_ERRNO, "%s: Y cent->x %d, cent->y %d, reversex %d," + "reversey %d motory %d data %d command %d", cent->x, cent->y, cnt->track.motorx_reverse, cnt->track.motory_reverse, cnt->track.motory, command); } @@ -575,13 +570,13 @@ static unsigned int servo_center(struct context *cnt, int x_offset, int y_offset /* If device is not open yet */ if (cnt->track.dev < 0) { if (!servo_open(cnt)) { - motion_log(ALR, TYPE_TRACK, NO_ERRNO, "%s: Problem opening servo!", __FUNCTION__); + MOTION_LOG(ALR, TYPE_TRACK, NO_ERRNO, "%s: Problem opening servo!"); return 0; } } - motion_log(NTC, TYPE_TRACK, NO_ERRNO, "%s: X-offset %d, Y-offset %d, x-position %d. y-position %d," - "reversex %d, reversey %d , stepsize %d", __FUNCTION__, x_offset, y_offset, + MOTION_LOG(NTC, TYPE_TRACK, NO_ERRNO, "%s: X-offset %d, Y-offset %d, x-position %d. y-position %d," + "reversex %d, reversey %d , stepsize %d", x_offset, y_offset, cnt->track.homex + (x_offset * cnt->track.stepsize), cnt->track.homey + (y_offset * cnt->track.stepsize), cnt->track.motorx_reverse, cnt->track.motory_reverse, @@ -633,7 +628,7 @@ static char iomojo_command(struct context *cnt, char *command, int len, unsigned while (read(cnt->track.dev, buffer, 1) != 1 && time(NULL) < timeout + 2); if (time(NULL) >= timeout + 2) { - motion_log(ALR, TYPE_TRACK, SHOW_ERRNO, "%s: Return byte timeout!", __FUNCTION__); + MOTION_LOG(ALR, TYPE_TRACK, SHOW_ERRNO, "%s: Return byte timeout!"); return 0; } } @@ -650,7 +645,7 @@ static void iomojo_setspeed(struct context *cnt, unsigned int speed) command[2] = speed; if (iomojo_command(cnt, command, 3, 1) != IOMOJO_SETSPEED_RET) - motion_log(ALR, TYPE_TRACK, SHOW_ERRNO, "%s: Unable to set camera speed", __FUNCTION__); + MOTION_LOG(ALR, TYPE_TRACK, SHOW_ERRNO, "%s: Unable to set camera speed"); } static void iomojo_movehome(struct context *cnt) @@ -670,8 +665,8 @@ static unsigned int iomojo_center(struct context *cnt, int x_offset, int y_offse if (cnt->track.dev < 0) { if ((cnt->track.dev = open(cnt->track.port, O_RDWR | O_NOCTTY)) < 0) { - motion_log(ALR, TYPE_TRACK, SHOW_ERRNO, "%s: Unable to open serial device %s", - __FUNCTION__, cnt->track.port); + MOTION_LOG(ALR, TYPE_TRACK, SHOW_ERRNO, "%s: Unable to open serial device %s", + cnt->track.port); return 0; } @@ -684,8 +679,8 @@ static unsigned int iomojo_center(struct context *cnt, int x_offset, int y_offse adtio.c_cc[VMIN] = 0; /* blocking read until 1 char */ tcflush(cnt->track.dev, TCIFLUSH); if (tcsetattr(cnt->track.dev, TCSANOW, &adtio) < 0) { - motion_log(ALR, TYPE_TRACK, SHOW_ERRNO, "%s: Unable to initialize serial device %s", - __FUNCTION__, cnt->track.port); + MOTION_LOG(ALR, TYPE_TRACK, SHOW_ERRNO, "%s: Unable to initialize serial device %s", + cnt->track.port); return 0; } } @@ -722,7 +717,7 @@ static unsigned int iomojo_center(struct context *cnt, int x_offset, int y_offse iomojo_command(cnt, command, 5, 0); } - motion_log(ERR, TYPE_TRACK, NO_ERRNO, "%s: succeed", __FUNCTION__); + MOTION_LOG(NTC, TYPE_TRACK, NO_ERRNO, "%s: succeed"); return cnt->track.move_wait; } @@ -802,15 +797,14 @@ static unsigned int lqos_center(struct context *cnt, int dev, int x_angle, int y if (cnt->track.dev == -1) { if (ioctl(dev, VIDIOCPWCMPTRESET, &reset) == -1) { - motion_log(ALR, TYPE_TRACK, SHOW_ERRNO, "%s: Failed to reset pwc camera to starting position! Reason", - __FUNCTION__); + MOTION_LOG(ALR, TYPE_TRACK, SHOW_ERRNO, "%s: Failed to reset pwc camera to starting position! Reason"); return 0; } SLEEP(6, 0); if (ioctl(dev, VIDIOCPWCMPTGRANGE, &pmr) == -1) { - motion_log(ALR, TYPE_TRACK, SHOW_ERRNO, "%s: failed VIDIOCPWCMPTGRANGE", __FUNCTION__); + MOTION_LOG(ALR, TYPE_TRACK, SHOW_ERRNO, "%s: failed VIDIOCPWCMPTGRANGE"); return 0; } @@ -823,7 +817,7 @@ static unsigned int lqos_center(struct context *cnt, int dev, int x_angle, int y } if (ioctl(dev, VIDIOCPWCMPTGANGLE, &pma) == -1) - motion_log(ERR, TYPE_TRACK, SHOW_ERRNO, "%s: ioctl VIDIOCPWCMPTGANGLE", __FUNCTION__); + MOTION_LOG(ERR, TYPE_TRACK, SHOW_ERRNO, "%s: ioctl VIDIOCPWCMPTGANGLE"); pma.absolute = 1; @@ -834,11 +828,11 @@ static unsigned int lqos_center(struct context *cnt, int dev, int x_angle, int y pma.tilt = y_angle * 100; if (ioctl(dev, VIDIOCPWCMPTSANGLE, &pma) == -1) { - motion_log(ERR, TYPE_TRACK, SHOW_ERRNO, "%s: Failed to pan/tilt pwc camera! Reason", __FUNCTION__); + MOTION_LOG(ERR, TYPE_TRACK, SHOW_ERRNO, "%s: Failed to pan/tilt pwc camera! Reason"); return 0; } - motion_log(ERR, TYPE_TRACK, NO_ERRNO, "%s: succeed", __FUNCTION__); + MOTION_LOG(NTC, TYPE_TRACK, NO_ERRNO, "%s: succeed"); return cnt->track.move_wait; } @@ -869,7 +863,7 @@ static unsigned int lqos_move(struct context *cnt, int dev, struct coord *cent, /* If we never checked for the min/max values for pan/tilt we do it now */ if (cnt->track.minmaxfound == 0) { if (ioctl(dev, VIDIOCPWCMPTGRANGE, &pmr) == -1) { - motion_log(ERR, TYPE_TRACK, SHOW_ERRNO, "%s: failed VIDIOCPWCMPTGRANGE", __FUNCTION__); + MOTION_LOG(ERR, TYPE_TRACK, SHOW_ERRNO, "%s: failed VIDIOCPWCMPTGRANGE"); return 0; } cnt->track.minmaxfound = 1; @@ -881,7 +875,7 @@ static unsigned int lqos_move(struct context *cnt, int dev, struct coord *cent, /* Get current camera position */ if (ioctl(dev, VIDIOCPWCMPTGANGLE, &pma) == -1) - motion_log(ERR, TYPE_TRACK, SHOW_ERRNO, "%s: ioctl VIDIOCPWCMPTGANGLE", __FUNCTION__); + MOTION_LOG(ERR, TYPE_TRACK, SHOW_ERRNO, "%s: ioctl VIDIOCPWCMPTGANGLE"); /* @@ -906,7 +900,7 @@ static unsigned int lqos_move(struct context *cnt, int dev, struct coord *cent, pma.tilt = move_y_degrees; if (ioctl(dev, VIDIOCPWCMPTSANGLE, &pma) == -1) { - motion_log(ERR, TYPE_TRACK, SHOW_ERRNO, "%s: Failed to pan/tilt pwc camera! Reason", __FUNCTION__); + MOTION_LOG(ERR, TYPE_TRACK, SHOW_ERRNO, "%s: Failed to pan/tilt pwc camera! Reason"); return 0; } @@ -945,13 +939,11 @@ static unsigned int uvc_center(struct context *cnt, int dev, int x_angle, int y_ control_s.value = (unsigned char) reset; if (ioctl(dev, VIDIOC_S_CTRL, &control_s) < 0) { - motion_log(ERR, TYPE_TRACK, SHOW_ERRNO, "%s: Failed to reset UVC camera to starting position! Reason", - __FUNCTION__); + MOTION_LOG(ERR, TYPE_TRACK, SHOW_ERRNO, "%s: Failed to reset UVC camera to starting position! Reason"); return 0; } - motion_log(NTC, TYPE_TRACK, NO_ERRNO, "%s: Reseting UVC camera to starting position", - __FUNCTION__); + MOTION_LOG(NTC, TYPE_TRACK, NO_ERRNO, "%s: Reseting UVC camera to starting position"); SLEEP(8, 0); @@ -960,13 +952,12 @@ static unsigned int uvc_center(struct context *cnt, int dev, int x_angle, int y_ queryctrl.id = V4L2_CID_PAN_RELATIVE; if (ioctl(dev, VIDIOC_QUERYCTRL, &queryctrl) < 0) { - motion_log(ERR, TYPE_TRACK, SHOW_ERRNO, "%s: ioctl querycontrol", __FUNCTION__); + MOTION_LOG(ERR, TYPE_TRACK, SHOW_ERRNO, "%s: ioctl querycontrol"); return 0; } - motion_log(NTC, TYPE_TRACK, NO_ERRNO, "%s: Getting camera range", __FUNCTION__); + MOTION_LOG(NTC, TYPE_TRACK, NO_ERRNO, "%s: Getting camera range"); - /* DWe 30.03.07 The orig request failed : * must be VIDIOC_G_CTRL separate for pan and tilt or via VIDIOC_G_EXT_CTRLS - now for 1st manual * Range X = -70 to +70 degrees @@ -992,10 +983,10 @@ static unsigned int uvc_center(struct context *cnt, int dev, int x_angle, int y_ struct v4l2_control control_s; - motion_log(NTC, TYPE_TRACK, NO_ERRNO, "%s: INPUT_PARAM_ABS pan_min %d,pan_max %d,tilt_min %d,tilt_max %d ", - __FUNCTION__, cnt->track.minx, cnt->track.maxx, cnt->track.miny, cnt->track.maxy); - motion_log(NTC, TYPE_TRACK, NO_ERRNO, "%s: INPUT_PARAM_ABS X_Angel %d, Y_Angel %d ", - __FUNCTION__, x_angle, y_angle); + MOTION_LOG(DBG, TYPE_TRACK, NO_ERRNO, "%s: INPUT_PARAM_ABS pan_min %d,pan_max %d,tilt_min %d,tilt_max %d ", + cnt->track.minx, cnt->track.maxx, cnt->track.miny, cnt->track.maxy); + MOTION_LOG(DBG, TYPE_TRACK, NO_ERRNO, "%s: INPUT_PARAM_ABS X_Angel %d, Y_Angel %d ", + x_angle, y_angle); if (x_angle <= cnt->track.maxx && x_angle >= cnt->track.minx) move_x_degrees = x_angle - (cnt->track.pan_angle); @@ -1013,8 +1004,8 @@ static unsigned int uvc_center(struct context *cnt, int dev, int x_angle, int y_ pan.s16.pan = -move_x_degrees * INCPANTILT; pan.s16.tilt = -move_y_degrees * INCPANTILT; - motion_log(NTC, TYPE_TRACK, NO_ERRNO, "%s: For_SET_ABS move_X %d,move_Y %d", - __FUNCTION__, move_x_degrees, move_y_degrees); + MOTION_LOG(DBG, TYPE_TRACK, NO_ERRNO, "%s: For_SET_ABS move_X %d,move_Y %d", + move_x_degrees, move_y_degrees); /* DWe 30.03.07 Must be broken in diff calls, because * one call for both is not accept via VIDIOC_S_CTRL -> maybe via VIDIOC_S_EXT_CTRLS @@ -1027,7 +1018,7 @@ static unsigned int uvc_center(struct context *cnt, int dev, int x_angle, int y_ control_s.value = pan.s16.pan; if (ioctl(dev, VIDIOC_S_CTRL, &control_s) < 0) { - motion_log(ERR, TYPE_TRACK, SHOW_ERRNO, "%s: Failed to move UVC camera!", __FUNCTION__); + MOTION_LOG(ERR, TYPE_TRACK, SHOW_ERRNO, "%s: Failed to move UVC camera!"); return 0; } } @@ -1042,17 +1033,17 @@ static unsigned int uvc_center(struct context *cnt, int dev, int x_angle, int y_ control_s.value = pan.s16.tilt; if (ioctl(dev, VIDIOC_S_CTRL, &control_s) < 0) { - motion_log(ERR, TYPE_TRACK, SHOW_ERRNO, "%s: Failed to move UVC camera!", __FUNCTION__); + MOTION_LOG(ERR, TYPE_TRACK, SHOW_ERRNO, "%s: Failed to move UVC camera!"); return 0; } } - motion_log(NTC, TYPE_TRACK, NO_ERRNO, "%s: Found MINMAX = %d", - __FUNCTION__, cnt->track.minmaxfound); + MOTION_LOG(NTC, TYPE_TRACK, NO_ERRNO, "%s: Found MINMAX = %d", + cnt->track.minmaxfound); if (cnt->track.dev != -1) { - motion_log(DBG, TYPE_TRACK, NO_ERRNO, "%s: Before_ABS_Y_Angel : x= %d , Y= %d, ", - __FUNCTION__, cnt->track.pan_angle, cnt->track.tilt_angle); + MOTION_LOG(DBG, TYPE_TRACK, NO_ERRNO, "%s: Before_ABS_Y_Angel : x= %d , Y= %d, ", + cnt->track.pan_angle, cnt->track.tilt_angle); if (move_x_degrees != -1) { cnt->track.pan_angle += move_x_degrees; @@ -1062,8 +1053,8 @@ static unsigned int uvc_center(struct context *cnt, int dev, int x_angle, int y_ cnt->track.tilt_angle += move_y_degrees; } - motion_log(NTC, TYPE_TRACK, NO_ERRNO, "%s: After_ABS_Y_Angel : x= %d , Y= %d", - __FUNCTION__, cnt->track.pan_angle, cnt->track.tilt_angle); + MOTION_LOG(NTC, TYPE_TRACK, NO_ERRNO, "%s: After_ABS_Y_Angel : x= %d , Y= %d", + cnt->track.pan_angle, cnt->track.tilt_angle); } return cnt->track.move_wait; @@ -1092,12 +1083,11 @@ static unsigned int uvc_move(struct context *cnt, int dev, struct coord *cent, control_s.value = (unsigned char) reset; if (ioctl(dev, VIDIOC_S_CTRL, &control_s) < 0) { - motion_log(ERR, TYPE_TRACK, SHOW_ERRNO, "%s: Failed to reset UVC camera to starting position! Reason", - __FUNCTION__); + MOTION_LOG(ERR, TYPE_TRACK, SHOW_ERRNO, "%s: Failed to reset UVC camera to starting position! Reason"); return 0; } - motion_log(NTC, TYPE_TRACK, NO_ERRNO, "%s: Reseting UVC camera to starting position", __FUNCTION__); + MOTION_LOG(NTC, TYPE_TRACK, NO_ERRNO, "%s: Reseting UVC camera to starting position"); /* set the "helpvalue" back to null because after reset CAM should be in x=0 and not 70 */ cent->x = 0; @@ -1164,11 +1154,11 @@ static unsigned int uvc_move(struct context *cnt, int dev, struct coord *cent, move_y_degrees = cnt->track.maxy - cnt->track.tilt_angle; } - motion_log(NTC, TYPE_TRACK, NO_ERRNO, "For_SET_REL pan_min %d,pan_max %d,tilt_min %d,tilt_max %d", + MOTION_LOG(DBG, TYPE_TRACK, NO_ERRNO, "For_SET_REL pan_min %d,pan_max %d,tilt_min %d,tilt_max %d", cnt->track.minx, cnt->track.maxx, cnt->track.miny, cnt->track.maxy); - motion_log(NTC, TYPE_TRACK, NO_ERRNO, "For_SET_REL track_pan_Angel %d, track_tilt_Angel %d", + MOTION_LOG(DBG, TYPE_TRACK, NO_ERRNO, "For_SET_REL track_pan_Angel %d, track_tilt_Angel %d", cnt->track.pan_angle, cnt->track.tilt_angle); - motion_log(NTC, TYPE_TRACK, NO_ERRNO, "For_SET_REL move_X %d,move_Y %d", move_x_degrees, move_y_degrees); + MOTION_LOG(DBG, TYPE_TRACK, NO_ERRNO, "For_SET_REL move_X %d,move_Y %d", move_x_degrees, move_y_degrees); /* * tilt up: - value @@ -1190,11 +1180,11 @@ static unsigned int uvc_move(struct context *cnt, int dev, struct coord *cent, control_s.id = V4L2_CID_PAN_RELATIVE; control_s.value = pan.s16.pan; - motion_log(NTC, TYPE_TRACK, NO_ERRNO, " dev %d, addr= %d, control_S= %d, Wert= %d", + MOTION_LOG(DBG, TYPE_TRACK, NO_ERRNO, " dev %d, addr= %d, control_S= %d, Wert= %d", dev, VIDIOC_S_CTRL, &control_s, pan.s16.pan); if (ioctl(dev, VIDIOC_S_CTRL, &control_s) < 0) { - motion_log(ERR, TYPE_TRACK, SHOW_ERRNO, "%s: Failed to move UVC camera!", __FUNCTION__); + MOTION_LOG(ERR, TYPE_TRACK, SHOW_ERRNO, "%s: Failed to move UVC camera!"); return 0; } } @@ -1209,20 +1199,20 @@ static unsigned int uvc_move(struct context *cnt, int dev, struct coord *cent, control_s.id = V4L2_CID_TILT_RELATIVE; control_s.value = pan.s16.tilt; - motion_log(NTC, TYPE_TRACK, NO_ERRNO, " dev %d,addr= %d, control_S= %d, Wert= %d", + MOTION_LOG(DBG, TYPE_TRACK, NO_ERRNO, " dev %d,addr= %d, control_S= %d, Wert= %d", dev, VIDIOC_S_CTRL, &control_s, pan.s16.tilt); if (ioctl(dev, VIDIOC_S_CTRL, &control_s) < 0) { - motion_log(ERR, TYPE_TRACK, SHOW_ERRNO, "%s: Failed to move UVC camera!", __FUNCTION__); + MOTION_LOG(ERR, TYPE_TRACK, SHOW_ERRNO, "%s: Failed to move UVC camera!"); return 0; } } - motion_log(NTC, TYPE_TRACK, NO_ERRNO, "%s: Found MINMAX = %d", - __FUNCTION__, cnt->track.minmaxfound); + MOTION_LOG(DBG, TYPE_TRACK, NO_ERRNO, "%s: Found MINMAX = %d", + cnt->track.minmaxfound); if (cnt->track.minmaxfound == 1) { - motion_log(NTC, TYPE_TRACK, NO_ERRNO, "Before_REL_Y_Angel : x= %d , Y= %d", + MOTION_LOG(DBG, TYPE_TRACK, NO_ERRNO, "Before_REL_Y_Angel : x= %d , Y= %d", cnt->track.pan_angle, cnt->track.tilt_angle); if (move_x_degrees != 0) @@ -1231,7 +1221,7 @@ static unsigned int uvc_move(struct context *cnt, int dev, struct coord *cent, if (move_y_degrees != 0) cnt->track.tilt_angle += -pan.s16.tilt / INCPANTILT; - motion_log(NTC, TYPE_TRACK, NO_ERRNO, "After_REL_Y_Angel : x= %d , Y= %d", + MOTION_LOG(DBG, TYPE_TRACK, NO_ERRNO, "After_REL_Y_Angel : x= %d , Y= %d", cnt->track.pan_angle, cnt->track.tilt_angle); } diff --git a/video.c b/video.c index d747894..2ac3a91 100644 --- a/video.c +++ b/video.c @@ -25,7 +25,7 @@ static void v4l_picture_controls(struct context *cnt, struct video_dev *viddev) if (cnt->conf.contrast && cnt->conf.contrast != viddev->contrast) { if (ioctl(dev, VIDIOCGPICT, &vid_pic) == -1) - motion_log(ERR, TYPE_VIDEO, SHOW_ERRNO, "%s: ioctl (VIDIOCGPICT)", __FUNCTION__); + MOTION_LOG(ERR, TYPE_VIDEO, SHOW_ERRNO, "%s: ioctl (VIDIOCGPICT)"); make_change = 1; vid_pic.contrast = cnt->conf.contrast * 256; @@ -36,7 +36,7 @@ static void v4l_picture_controls(struct context *cnt, struct video_dev *viddev) if (!make_change) { if (ioctl(dev, VIDIOCGPICT, &vid_pic)==-1) - motion_log(ERR, TYPE_VIDEO, SHOW_ERRNO, "%s: ioctl (VIDIOCGPICT)", __FUNCTION__); + MOTION_LOG(ERR, TYPE_VIDEO, SHOW_ERRNO, "%s: ioctl (VIDIOCGPICT)"); } make_change = 1; @@ -48,7 +48,7 @@ static void v4l_picture_controls(struct context *cnt, struct video_dev *viddev) if (!make_change) { if (ioctl(dev, VIDIOCGPICT, &vid_pic) == -1) - motion_log(ERR, TYPE_VIDEO, SHOW_ERRNO, "%s: ioctl (VIDIOCGPICT)", __FUNCTION__); + MOTION_LOG(ERR, TYPE_VIDEO, SHOW_ERRNO, "%s: ioctl (VIDIOCGPICT)"); } make_change = 1; @@ -63,23 +63,23 @@ static void v4l_picture_controls(struct context *cnt, struct video_dev *viddev) int fps; if (ioctl(dev, VIDIOCGWIN, &vw) == -1) { - motion_log(ERR, TYPE_VIDEO, SHOW_ERRNO, "%s: ioctl VIDIOCGWIN", __FUNCTION__); + MOTION_LOG(ERR, TYPE_VIDEO, SHOW_ERRNO, "%s: ioctl VIDIOCGWIN"); } else { fps = vw.flags >> PWC_FPS_SHIFT; - motion_log(DBG, TYPE_VIDEO, NO_ERRNO, "%s: Get Current framerate %d .. trying %d", - __FUNCTION__, fps, cnt->conf.frame_limit); + MOTION_LOG(DBG, TYPE_VIDEO, NO_ERRNO, "%s: Get Current framerate %d .. trying %d", + fps, cnt->conf.frame_limit); } fps = cnt->conf.frame_limit; vw.flags = fps << PWC_FPS_SHIFT; if (ioctl(dev, VIDIOCSWIN, &vw) == -1) { - motion_log(ERR, TYPE_VIDEO, SHOW_ERRNO, "%s: ioctl VIDIOCSWIN", __FUNCTION__); + MOTION_LOG(ERR, TYPE_VIDEO, SHOW_ERRNO, "%s: ioctl VIDIOCSWIN"); } else if (ioctl(dev, VIDIOCGWIN, &vw) == -1) { - motion_log(ERR, TYPE_VIDEO, SHOW_ERRNO, "%s: ioctl VIDIOCGWIN", __FUNCTION__); + MOTION_LOG(ERR, TYPE_VIDEO, SHOW_ERRNO, "%s: ioctl VIDIOCGWIN"); } else { fps = vw.flags >> PWC_FPS_SHIFT; - motion_log(DBG, TYPE_VIDEO, NO_ERRNO, "%s: Set new framerate %d", __FUNCTION__, fps); + MOTION_LOG(DBG, TYPE_VIDEO, NO_ERRNO, "%s: Set new framerate %d", fps); } viddev->fps = fps; @@ -89,10 +89,10 @@ static void v4l_picture_controls(struct context *cnt, struct video_dev *viddev) if (cnt->conf.autobright) { if (vid_do_autobright(cnt, viddev)) { - /* If we already read the VIDIOGPICT - we should not do it again */ + /* If we already read the VIDIOGPICT - we should not do it again. */ if (!make_change) { if (ioctl(dev, VIDIOCGPICT, &vid_pic) == -1) - motion_log(ERR, TYPE_VIDEO, SHOW_ERRNO, "%s: ioctl (VIDIOCGPICT)", __FUNCTION__); + MOTION_LOG(ERR, TYPE_VIDEO, SHOW_ERRNO, "%s: ioctl (VIDIOCGPICT)"); } vid_pic.brightness = viddev->brightness * 256; @@ -102,7 +102,7 @@ static void v4l_picture_controls(struct context *cnt, struct video_dev *viddev) } else if (cnt->conf.brightness && cnt->conf.brightness != viddev->brightness) { if ((!make_change) && (ioctl(dev, VIDIOCGPICT, &vid_pic) == -1)) - motion_log(ERR, TYPE_VIDEO, SHOW_ERRNO, "%s: ioctl (VIDIOCGPICT)", __FUNCTION__); + MOTION_LOG(ERR, TYPE_VIDEO, SHOW_ERRNO, "%s: ioctl (VIDIOCGPICT)"); make_change = 1; vid_pic.brightness = cnt->conf.brightness * 256; @@ -111,12 +111,10 @@ static void v4l_picture_controls(struct context *cnt, struct video_dev *viddev) if (make_change) { if (ioctl(dev, VIDIOCSPICT, &vid_pic) == -1) - motion_log(ERR, TYPE_VIDEO, SHOW_ERRNO, "%s: ioctl (VIDIOCSPICT)", __FUNCTION__); + MOTION_LOG(ERR, TYPE_VIDEO, SHOW_ERRNO, "%s: ioctl (VIDIOCSPICT)"); } } - - /******************************************************************************* Video4linux capture routines ********************************************************************************/ @@ -141,7 +139,7 @@ unsigned char *v4l_start(struct video_dev *viddev, int width, int height,int inp void *map; if (ioctl (dev, VIDIOCGCAP, &vid_caps) == -1) { - motion_log(ERR, TYPE_VIDEO, SHOW_ERRNO, "%s: ioctl (VIDIOCGCAP)", __FUNCTION__); + MOTION_LOG(ERR, TYPE_VIDEO, SHOW_ERRNO, "%s: ioctl (VIDIOCGCAP)"); return NULL; } @@ -153,14 +151,14 @@ unsigned char *v4l_start(struct video_dev *viddev, int width, int height,int inp vid_chnl.channel = input; if (ioctl (dev, VIDIOCGCHAN, &vid_chnl) == -1) { - motion_log(ERR, TYPE_VIDEO, SHOW_ERRNO, "%s: ioctl (VIDIOCGCHAN) Input %d", - __FUNCTION__, input); + MOTION_LOG(ERR, TYPE_VIDEO, SHOW_ERRNO, "%s: ioctl (VIDIOCGCHAN) Input %d", + input); } else { vid_chnl.channel = input; vid_chnl.norm = norm; if (ioctl (dev, VIDIOCSCHAN, &vid_chnl) == -1) { - motion_log(ERR, TYPE_VIDEO, SHOW_ERRNO, "%s: ioctl (VIDIOCSCHAN) Input %d Standard method %d", - __FUNCTION__, input, norm); + MOTION_LOG(ERR, TYPE_VIDEO, SHOW_ERRNO, "%s: ioctl (VIDIOCSCHAN) Input %d" + " Standard method %d", input, norm); return NULL; } } @@ -170,8 +168,8 @@ unsigned char *v4l_start(struct video_dev *viddev, int width, int height,int inp memset(&vid_tuner, 0, sizeof(struct video_tuner)); vid_tuner.tuner = tuner_number; if (ioctl (dev, VIDIOCGTUNER, &vid_tuner) == -1) { - motion_log(ERR, TYPE_VIDEO, SHOW_ERRNO, "%s: ioctl (VIDIOCGTUNER) tuner %d", - __FUNCTION__, tuner_number); + MOTION_LOG(ERR, TYPE_VIDEO, SHOW_ERRNO, "%s: ioctl (VIDIOCGTUNER) tuner %d", + tuner_number); } else { if (vid_tuner.flags & VIDEO_TUNER_LOW) freq = freq * 16; /* steps of 1/16 KHz */ @@ -179,20 +177,20 @@ unsigned char *v4l_start(struct video_dev *viddev, int width, int height,int inp freq = freq * 10 / 625; if (ioctl(dev, VIDIOCSFREQ, &freq) == -1) { - motion_log(ERR, TYPE_VIDEO, SHOW_ERRNO, "%s: ioctl (VIDIOCSFREQ) Frequency %ul", - __FUNCTION__, freq); + MOTION_LOG(ERR, TYPE_VIDEO, SHOW_ERRNO, "%s: ioctl (VIDIOCSFREQ)" + " Frequency %ul", freq); return NULL; } - motion_log(WRN, TYPE_VIDEO, NO_ERRNO, "%s: Set Tuner to %d Frequency set to %ul", - __FUNCTION__, tuner_number, freq); + MOTION_LOG(WRN, TYPE_VIDEO, NO_ERRNO, "%s: Set Tuner to %d Frequency set to %ul", + tuner_number, freq); } } if (ioctl (dev, VIDIOCGMBUF, &vid_buf) == -1) { - motion_log(ERR, TYPE_VIDEO, NO_ERRNO, "%s: ioctl(VIDIOCGMBUF) - Error device does not support memory map\n", - "V4L capturing using read is deprecated!\nMotion only supports mmap.", - __FUNCTION__); + MOTION_LOG(ALR, TYPE_VIDEO, NO_ERRNO, "%s: ioctl(VIDIOCGMBUF) - Error device" + " does not support memory map\n V4L capturing using read is deprecated!\n" + "Motion only supports mmap."); return NULL; } else { map = mmap(0, vid_buf.size, PROT_READ|PROT_WRITE, MAP_SHARED, dev, 0); @@ -208,7 +206,7 @@ unsigned char *v4l_start(struct video_dev *viddev, int width, int height,int inp } if (MAP_FAILED == map) { - motion_log(ERR, TYPE_VIDEO, SHOW_ERRNO, "%s: MAP_FAILED", __FUNCTION__); + MOTION_LOG(ALR, TYPE_VIDEO, SHOW_ERRNO, "%s: MAP_FAILED"); return NULL; } @@ -219,34 +217,33 @@ unsigned char *v4l_start(struct video_dev *viddev, int width, int height,int inp vid_mmap.height = height; if (ioctl(dev, VIDIOCMCAPTURE, &vid_mmap) == -1) { - motion_log(DBG, TYPE_VIDEO, SHOW_ERRNO, "%s: Failed with YUV420P, trying YUV422 palette", - __FUNCTION__); + MOTION_LOG(WRN, TYPE_VIDEO, SHOW_ERRNO, "%s: Failed with YUV420P, " + "trying YUV422 palette"); viddev->v4l_fmt = VIDEO_PALETTE_YUV422; vid_mmap.format = viddev->v4l_fmt; /* Try again... */ if (ioctl(dev, VIDIOCMCAPTURE, &vid_mmap) == -1) { - motion_log(DBG, TYPE_VIDEO, SHOW_ERRNO, "%s: Failed with YUV422, trying YUYV palette", - __FUNCTION__); + MOTION_LOG(WRN, TYPE_VIDEO, SHOW_ERRNO, "%s: Failed with YUV422," + " trying YUYV palette"); viddev->v4l_fmt = VIDEO_PALETTE_YUYV; vid_mmap.format = viddev->v4l_fmt; if (ioctl(dev, VIDIOCMCAPTURE, &vid_mmap) == -1) { - motion_log(DBG, TYPE_VIDEO, SHOW_ERRNO, "%s: Failed with YUYV, trying RGB24 palette", - __FUNCTION__); + MOTION_LOG(WRN, TYPE_VIDEO, SHOW_ERRNO, "%s: Failed with YUYV, trying RGB24 palette"); viddev->v4l_fmt = VIDEO_PALETTE_RGB24; vid_mmap.format = viddev->v4l_fmt; /* Try again... */ if (ioctl(dev, VIDIOCMCAPTURE, &vid_mmap) == -1) { - motion_log(DBG, TYPE_VIDEO, SHOW_ERRNO, "%s: Failed with RGB24, trying" - "GREYSCALE palette", __FUNCTION__); + MOTION_LOG(WRN, TYPE_VIDEO, SHOW_ERRNO, "%s: Failed with RGB24, trying" + "GREYSCALE palette"); viddev->v4l_fmt = VIDEO_PALETTE_GREY; vid_mmap.format = viddev->v4l_fmt; /* Try one last time... */ if (ioctl(dev, VIDIOCMCAPTURE, &vid_mmap) == -1) { - motion_log(ERR, TYPE_VIDEO, SHOW_ERRNO, "%s: Failed with all supported palettes " - "- giving up", __FUNCTION__); + MOTION_LOG(ALR, TYPE_VIDEO, SHOW_ERRNO, "%s: Failed with all supported palettes " + "- giving up"); return NULL; } } @@ -258,23 +255,23 @@ unsigned char *v4l_start(struct video_dev *viddev, int width, int height,int inp switch (viddev->v4l_fmt) { case VIDEO_PALETTE_YUV420P: viddev->v4l_bufsize = (width * height * 3) / 2; - motion_log(DBG, TYPE_VIDEO, NO_ERRNO, "%s: Using VIDEO_PALETTE_YUV420P palette", __FUNCTION__); + MOTION_LOG(CRT, TYPE_VIDEO, NO_ERRNO, "%s: Using VIDEO_PALETTE_YUV420P palette"); break; case VIDEO_PALETTE_YUV422: viddev->v4l_bufsize = (width * height * 2); - motion_log(DBG, TYPE_VIDEO, NO_ERRNO, "%s: Using VIDEO_PALETTE_YUV422 palette", __FUNCTION__); + MOTION_LOG(CRT, TYPE_VIDEO, NO_ERRNO, "%s: Using VIDEO_PALETTE_YUV422 palette"); break; case VIDEO_PALETTE_YUYV: viddev->v4l_bufsize = (width * height * 2); - motion_log(DBG, TYPE_VIDEO, NO_ERRNO, "%s: Using VIDEO_PALETTE_YUYV palette", __FUNCTION__); + MOTION_LOG(CRT, TYPE_VIDEO, NO_ERRNO, "%s: Using VIDEO_PALETTE_YUYV palette"); break; case VIDEO_PALETTE_RGB24: viddev->v4l_bufsize = (width * height * 3); - motion_log(DBG, TYPE_VIDEO, NO_ERRNO, "%s: Using VIDEO_PALETTE_RGB24 palette", __FUNCTION__); + MOTION_LOG(CRT, TYPE_VIDEO, NO_ERRNO, "%s: Using VIDEO_PALETTE_RGB24 palette"); break; case VIDEO_PALETTE_GREY: viddev->v4l_bufsize = width * height; - motion_log(DBG, TYPE_VIDEO, NO_ERRNO, "%s: Using VIDEO_PALETTE_GREY palette", __FUNCTION__); + MOTION_LOG(CRT, TYPE_VIDEO, NO_ERRNO, "%s: Using VIDEO_PALETTE_GREY palette"); break; } @@ -330,7 +327,8 @@ int v4l_next(struct video_dev *viddev, unsigned char *map, int width, int height vid_mmap.frame = viddev->v4l_curbuffer; if (ioctl(dev, VIDIOCMCAPTURE, &vid_mmap) == -1) { - motion_log(ERR, TYPE_VIDEO, SHOW_ERRNO, "%s: mcapture error in proc %d", __FUNCTION__, getpid()); + MOTION_LOG(ALR, TYPE_VIDEO, SHOW_ERRNO, "%s: mcapture error in proc %d", + getpid()); sigprocmask (SIG_UNBLOCK, &old, NULL); return V4L_FATAL_ERROR; } @@ -338,7 +336,8 @@ int v4l_next(struct video_dev *viddev, unsigned char *map, int width, int height vid_mmap.frame = frame; if (ioctl(dev, VIDIOCSYNC, &vid_mmap.frame) == -1) { - motion_log(ERR, TYPE_VIDEO, SHOW_ERRNO, "%s: sync error in proc %d", __FUNCTION__, getpid()); + MOTION_LOG(ALR, TYPE_VIDEO, SHOW_ERRNO, "%s: sync error in proc %d", + getpid()); sigprocmask (SIG_UNBLOCK, &old, NULL); } @@ -396,8 +395,8 @@ void v4l_set_input(struct context *cnt, struct video_dev *viddev, unsigned char vid_tuner.tuner = tuner_number; if (ioctl (dev, VIDIOCGTUNER, &vid_tuner) == -1) { - motion_log(ERR, TYPE_VIDEO, SHOW_ERRNO, "%s: ioctl (VIDIOCGTUNER) tuner number %d", - __FUNCTION__, tuner_number); + MOTION_LOG(ERR, TYPE_VIDEO, SHOW_ERRNO, "%s: ioctl (VIDIOCGTUNER) tuner number %d", + tuner_number); } else { if (vid_tuner.flags & VIDEO_TUNER_LOW) frequnits = freq * 16; /* steps of 1/16 KHz */ @@ -405,13 +404,13 @@ void v4l_set_input(struct context *cnt, struct video_dev *viddev, unsigned char frequnits = (freq * 10) / 625; if (ioctl(dev, VIDIOCSFREQ, &frequnits) == -1) { - motion_log(ERR, TYPE_VIDEO, SHOW_ERRNO, "%s: ioctl (VIDIOCSFREQ) Frequency %ul", - __FUNCTION__, frequnits); + MOTION_LOG(ERR, TYPE_VIDEO, SHOW_ERRNO, "%s: ioctl (VIDIOCSFREQ) Frequency %ul", + frequnits); return; } - motion_log(WRN, TYPE_VIDEO, NO_ERRNO, "%s: Set Tuner to %d Frequency to %ul", - __FUNCTION__, tuner_number, frequnits); + MOTION_LOG(ALR, TYPE_VIDEO, NO_ERRNO, "%s: Set Tuner to %d Frequency to %ul", + tuner_number, frequnits); } } @@ -419,19 +418,20 @@ void v4l_set_input(struct context *cnt, struct video_dev *viddev, unsigned char vid_chnl.channel = input; if (ioctl (dev, VIDIOCGCHAN, &vid_chnl) == -1) { - motion_log(ERR, TYPE_VIDEO, SHOW_ERRNO, "%s: ioctl (VIDIOCGCHAN) Input %d", __FUNCTION__, input); + MOTION_LOG(ERR, TYPE_VIDEO, SHOW_ERRNO, "%s: ioctl (VIDIOCGCHAN) Input %d", + input); } else { vid_chnl.channel = input; vid_chnl.norm = norm; if (ioctl (dev, VIDIOCSCHAN, &vid_chnl) == -1) { - motion_log(ERR, TYPE_VIDEO, SHOW_ERRNO, "%s: ioctl (VIDIOCSCHAN) Input %d Standard method %d", - __FUNCTION__, input, norm); + MOTION_LOG(ERR, TYPE_VIDEO, SHOW_ERRNO, "%s: ioctl (VIDIOCSCHAN) Input %d" + " Standard method %d", input, norm); return; } - motion_log(WRN, TYPE_VIDEO, NO_ERRNO, "%s: Set Input to %d Standard method to %d", - __FUNCTION__, input, norm); + MOTION_LOG(ALR, TYPE_VIDEO, NO_ERRNO, "%s: Set Input to %d Standard method to %d", + input, norm); } v4l_picture_controls(cnt, viddev); diff --git a/video2.c b/video2.c index 69540c8..e2b27aa 100644 --- a/video2.c +++ b/video2.c @@ -196,46 +196,45 @@ static int xioctl(int fd, int request, void *arg) static int v4l2_get_capability(src_v4l2_t * vid_source) { if (xioctl(vid_source->fd, VIDIOC_QUERYCAP, &vid_source->cap) < 0) { - motion_log(ERR, TYPE_VIDEO, NO_ERRNO, "%s: Not a V4L2 device?", __FUNCTION__); + MOTION_LOG(ERR, TYPE_VIDEO, NO_ERRNO, "%s: Not a V4L2 device?"); return -1; } - motion_log(ERR, TYPE_VIDEO, NO_ERRNO, "%s: \n------------------------\n" + MOTION_LOG(ERR, TYPE_VIDEO, NO_ERRNO, "%s: \n------------------------\n" "cap.driver: \"%s\"\n" "cap.card: \"%s\"\n" "cap.bus_info: \"%s\"\n" - "cap.capabilities=0x%08X\n------------------------", __FUNCTION__, + "cap.capabilities=0x%08X\n------------------------", vid_source->cap.driver, vid_source->cap.card, vid_source->cap.bus_info, vid_source->cap.capabilities); if (vid_source->cap.capabilities & V4L2_CAP_VIDEO_CAPTURE) - motion_log(ERR, TYPE_VIDEO, NO_ERRNO, "- VIDEO_CAPTURE"); + MOTION_LOG(ERR, TYPE_VIDEO, NO_ERRNO, "- VIDEO_CAPTURE"); if (vid_source->cap.capabilities & V4L2_CAP_VIDEO_OUTPUT) - motion_log(ERR, TYPE_VIDEO, NO_ERRNO, "- VIDEO_OUTPUT"); + MOTION_LOG(ERR, TYPE_VIDEO, NO_ERRNO, "- VIDEO_OUTPUT"); if (vid_source->cap.capabilities & V4L2_CAP_VIDEO_OVERLAY) - motion_log(ERR, TYPE_VIDEO, NO_ERRNO, "- VIDEO_OVERLAY"); + MOTION_LOG(ERR, TYPE_VIDEO, NO_ERRNO, "- VIDEO_OVERLAY"); if (vid_source->cap.capabilities & V4L2_CAP_VBI_CAPTURE) - motion_log(ERR, TYPE_VIDEO, NO_ERRNO, "- VBI_CAPTURE"); + MOTION_LOG(ERR, TYPE_VIDEO, NO_ERRNO, "- VBI_CAPTURE"); if (vid_source->cap.capabilities & V4L2_CAP_VBI_OUTPUT) - motion_log(ERR, TYPE_VIDEO, NO_ERRNO, "- VBI_OUTPUT"); + MOTION_LOG(ERR, TYPE_VIDEO, NO_ERRNO, "- VBI_OUTPUT"); if (vid_source->cap.capabilities & V4L2_CAP_RDS_CAPTURE) - motion_log(ERR, TYPE_VIDEO, NO_ERRNO, "- RDS_CAPTURE"); + MOTION_LOG(ERR, TYPE_VIDEO, NO_ERRNO, "- RDS_CAPTURE"); if (vid_source->cap.capabilities & V4L2_CAP_TUNER) - motion_log(ERR, TYPE_VIDEO, NO_ERRNO, "- TUNER"); + MOTION_LOG(ERR, TYPE_VIDEO, NO_ERRNO, "- TUNER"); if (vid_source->cap.capabilities & V4L2_CAP_AUDIO) - motion_log(ERR, TYPE_VIDEO, NO_ERRNO, "- AUDIO"); + MOTION_LOG(ERR, TYPE_VIDEO, NO_ERRNO, "- AUDIO"); if (vid_source->cap.capabilities & V4L2_CAP_READWRITE) - motion_log(ERR, TYPE_VIDEO, NO_ERRNO, "- READWRITE"); + MOTION_LOG(ERR, TYPE_VIDEO, NO_ERRNO, "- READWRITE"); if (vid_source->cap.capabilities & V4L2_CAP_ASYNCIO) - motion_log(ERR, TYPE_VIDEO, NO_ERRNO, "- ASYNCIO"); + MOTION_LOG(ERR, TYPE_VIDEO, NO_ERRNO, "- ASYNCIO"); if (vid_source->cap.capabilities & V4L2_CAP_STREAMING) - motion_log(ERR, TYPE_VIDEO, NO_ERRNO, "- STREAMING"); + MOTION_LOG(ERR, TYPE_VIDEO, NO_ERRNO, "- STREAMING"); if (vid_source->cap.capabilities & V4L2_CAP_TIMEPERFRAME) - motion_log(ERR, TYPE_VIDEO, NO_ERRNO, "- TIMEPERFRAME"); + MOTION_LOG(ERR, TYPE_VIDEO, NO_ERRNO, "- TIMEPERFRAME"); if (!(vid_source->cap.capabilities & V4L2_CAP_VIDEO_CAPTURE)) { - motion_log(ERR, TYPE_VIDEO, NO_ERRNO, "%s: Device does not support capturing.", - __FUNCTION__); + MOTION_LOG(ERR, TYPE_VIDEO, NO_ERRNO, "%s: Device does not support capturing."); return -1; } @@ -263,23 +262,23 @@ static int v4l2_select_input(struct config *conf, struct video_dev *viddev, src_ else input.index = in; if (xioctl(vid_source->fd, VIDIOC_ENUMINPUT, &input) == -1) { - motion_log(ERR, TYPE_VIDEO, SHOW_ERRNO, "%s: Unable to query input %d. VIDIOC_ENUMINPUT", - __FUNCTION__, input.index); + MOTION_LOG(ERR, TYPE_VIDEO, SHOW_ERRNO, "%s: Unable to query input %d. VIDIOC_ENUMINPUT", + input.index); return -1; } - motion_log(NTC, TYPE_VIDEO, NO_ERRNO, "%s: name = \"%s\", type 0x%08X, status %08x", - __FUNCTION__, input.name, input.type, input.status); + MOTION_LOG(NTC, TYPE_VIDEO, NO_ERRNO, "%s: name = \"%s\", type 0x%08X, status %08x", + input.name, input.type, input.status); if (input.type & V4L2_INPUT_TYPE_TUNER) - motion_log(NTC, TYPE_VIDEO, NO_ERRNO, "- TUNER"); + MOTION_LOG(NTC, TYPE_VIDEO, NO_ERRNO, "- TUNER"); if (input.type & V4L2_INPUT_TYPE_CAMERA) - motion_log(NTC, TYPE_VIDEO, NO_ERRNO, "- CAMERA"); + MOTION_LOG(NTC, TYPE_VIDEO, NO_ERRNO, "- CAMERA"); if (xioctl(vid_source->fd, VIDIOC_S_INPUT, &input.index) == -1) { - motion_log(ERR, TYPE_VIDEO, SHOW_ERRNO, "%s: Error selecting input %d VIDIOC_S_INPUT", - __FUNCTION__, input.index); + MOTION_LOG(ERR, TYPE_VIDEO, SHOW_ERRNO, "%s: Error selecting input %d VIDIOC_S_INPUT", + input.index); return -1; } @@ -287,8 +286,7 @@ static int v4l2_select_input(struct config *conf, struct video_dev *viddev, src_ /* Set video standard usually webcams doesn't support the ioctl or return V4L2_STD_UNKNOWN */ if (xioctl(vid_source->fd, VIDIOC_G_STD, &std_id) == -1) { - motion_log(NTC, TYPE_VIDEO, NO_ERRNO, "%s: Device doesn't support VIDIOC_G_STD", - __FUNCTION__); + MOTION_LOG(NTC, TYPE_VIDEO, NO_ERRNO, "%s: Device doesn't support VIDIOC_G_STD"); norm = std_id = 0; // V4L2_STD_UNKNOWN = 0 } @@ -298,8 +296,8 @@ static int v4l2_select_input(struct config *conf, struct video_dev *viddev, src_ while (xioctl(vid_source->fd, VIDIOC_ENUMSTD, &standard) == 0) { if (standard.id & std_id) - motion_log(NTC, TYPE_VIDEO, NO_ERRNO, "%s: - video standard %s", - __FUNCTION__, standard.name); + MOTION_LOG(NTC, TYPE_VIDEO, NO_ERRNO, "%s: - video standard %s", + standard.name); standard.index++; } @@ -316,12 +314,12 @@ static int v4l2_select_input(struct config *conf, struct video_dev *viddev, src_ } if (xioctl(vid_source->fd, VIDIOC_S_STD, &std_id) == -1) { - motion_log(ERR, TYPE_VIDEO, SHOW_ERRNO, "%s: Error selecting standard method %d VIDIOC_S_STD", - __FUNCTION__, (int)std_id); + MOTION_LOG(ERR, TYPE_VIDEO, SHOW_ERRNO, "%s: Error selecting standard method %d VIDIOC_S_STD", + (int)std_id); } - motion_log(NTC, TYPE_VIDEO, NO_ERRNO, "%s: Set standard method %d", - __FUNCTION__, (int)std_id); + MOTION_LOG(NTC, TYPE_VIDEO, NO_ERRNO, "%s: Set standard method %d", + (int)std_id); } viddev->norm = conf->norm = norm; @@ -337,13 +335,13 @@ static int v4l2_select_input(struct config *conf, struct video_dev *viddev, src_ tuner.index = input.tuner; if (xioctl(vid_source->fd, VIDIOC_G_TUNER, &tuner) == -1) { - motion_log(ERR, TYPE_VIDEO, SHOW_ERRNO, "%s: tuner %d VIDIOC_G_TUNER", - __FUNCTION__, tuner.index); + MOTION_LOG(ERR, TYPE_VIDEO, SHOW_ERRNO, "%s: tuner %d VIDIOC_G_TUNER", + tuner.index); return 0; } - motion_log(NTC, TYPE_VIDEO, NO_ERRNO, "%s: Set tuner %d", - __FUNCTION__, tuner.index); + MOTION_LOG(NTC, TYPE_VIDEO, NO_ERRNO, "%s: Set tuner %d", + tuner.index); /* Set the frequency. */ memset(&freq, 0, sizeof(struct v4l2_frequency)); @@ -352,15 +350,15 @@ static int v4l2_select_input(struct config *conf, struct video_dev *viddev, src_ freq.frequency = (freq_ / 1000) * 16; if (xioctl(vid_source->fd, VIDIOC_S_FREQUENCY, &freq) == -1) { - motion_log(ERR, TYPE_VIDEO, SHOW_ERRNO, "%s: freq %ul VIDIOC_S_FREQUENCY", - __FUNCTION__, freq.frequency); + MOTION_LOG(ERR, TYPE_VIDEO, SHOW_ERRNO, "%s: freq %ul VIDIOC_S_FREQUENCY", + freq.frequency); return 0; } viddev->freq = conf->frequency = freq_; - motion_log(NTC, TYPE_VIDEO, NO_ERRNO, "%s: Set Frequency to %ul", - __FUNCTION__, freq.frequency); + MOTION_LOG(NTC, TYPE_VIDEO, NO_ERRNO, "%s: Set Frequency to %ul", + freq.frequency); } else { viddev->freq = conf->frequency = 0; } @@ -403,23 +401,23 @@ static int v4l2_set_pix_format(struct context *cnt, src_v4l2_t * vid_source, int fmtd.index = v4l2_pal = 0; fmtd.type = V4L2_BUF_TYPE_VIDEO_CAPTURE; - motion_log(ERR, TYPE_VIDEO, NO_ERRNO, "%s: Supported palettes:", __FUNCTION__); + MOTION_LOG(ERR, TYPE_VIDEO, NO_ERRNO, "%s: Supported palettes:"); while (xioctl(vid_source->fd, VIDIOC_ENUM_FMT, &fmtd) != -1) { int i; - motion_log(ERR, TYPE_VIDEO, NO_ERRNO, "%i: %c%c%c%c (%s)", v4l2_pal, fmtd.pixelformat >> 0, + MOTION_LOG(ERR, TYPE_VIDEO, NO_ERRNO, "%i: %c%c%c%c (%s)", v4l2_pal, fmtd.pixelformat >> 0, fmtd.pixelformat >> 8, fmtd.pixelformat >> 16, fmtd.pixelformat >> 24, fmtd.description); - motion_log(ERR, TYPE_VIDEO, NO_ERRNO, "%s: %d - %s (compressed : %d) (%#x)", - __FUNCTION__, fmtd.index, fmtd.description, fmtd.flags, fmtd.pixelformat); + MOTION_LOG(ERR, TYPE_VIDEO, NO_ERRNO, "%s: %d - %s (compressed : %d) (%#x)", + fmtd.index, fmtd.description, fmtd.flags, fmtd.pixelformat); for (i = 0; supported_formats[i]; i++) if (supported_formats[i] == fmtd.pixelformat) { if (cnt->conf.v4l2_palette == i) { index_format = cnt->conf.v4l2_palette; - motion_log(ERR, TYPE_VIDEO, NO_ERRNO, "Selected palette %c%c%c%c", fmtd.pixelformat >> 0, + MOTION_LOG(ERR, TYPE_VIDEO, NO_ERRNO, "Selected palette %c%c%c%c", fmtd.pixelformat >> 0, fmtd.pixelformat >> 8, fmtd.pixelformat >> 16, fmtd.pixelformat >> 24); i = sizeof(supported_formats)/sizeof(u32); break; @@ -450,15 +448,15 @@ static int v4l2_set_pix_format(struct context *cnt, src_v4l2_t * vid_source, int if (xioctl(vid_source->fd, VIDIOC_TRY_FMT, &vid_source->dst_fmt) != -1 && vid_source->dst_fmt.fmt.pix.pixelformat == pixformat) { - motion_log(ERR, TYPE_VIDEO, NO_ERRNO, "%s: index_format %d Testing palette %c%c%c%c (%dx%d)", - __FUNCTION__, index_format, pixformat >> 0, pixformat >> 8, + MOTION_LOG(ERR, TYPE_VIDEO, NO_ERRNO, "%s: index_format %d Testing palette %c%c%c%c (%dx%d)", + index_format, pixformat >> 0, pixformat >> 8, pixformat >> 16, pixformat >> 24, *width, *height); if (vid_source->dst_fmt.fmt.pix.width != (unsigned int) *width || vid_source->dst_fmt.fmt.pix.height != (unsigned int) *height) { - motion_log(ERR, TYPE_VIDEO, NO_ERRNO, "%s: Adjusting resolution from %ix%i to %ix%i.", - __FUNCTION__, *width, *height, vid_source->dst_fmt.fmt.pix.width, + MOTION_LOG(ERR, TYPE_VIDEO, NO_ERRNO, "%s: Adjusting resolution from %ix%i to %ix%i.", + *width, *height, vid_source->dst_fmt.fmt.pix.width, vid_source->dst_fmt.fmt.pix.height); *width = vid_source->dst_fmt.fmt.pix.width; @@ -466,26 +464,25 @@ static int v4l2_set_pix_format(struct context *cnt, src_v4l2_t * vid_source, int } if (xioctl(vid_source->fd, VIDIOC_S_FMT, &vid_source->dst_fmt) == -1) { - motion_log(ERR, TYPE_VIDEO, SHOW_ERRNO, "%s: Error setting pixel format.\nVIDIOC_S_FMT: ", - __FUNCTION__); + MOTION_LOG(ERR, TYPE_VIDEO, SHOW_ERRNO, "%s: Error setting pixel format.\nVIDIOC_S_FMT: "); return -1; } - motion_log(ERR, TYPE_VIDEO, NO_ERRNO, "%s: Using palette %c%c%c%c (%dx%d) bytesperlines %d sizeimage " - "%d colorspace %08x", __FUNCTION__, pixformat >> 0, pixformat >> 8, pixformat >> 16, + MOTION_LOG(ERR, TYPE_VIDEO, NO_ERRNO, "%s: Using palette %c%c%c%c (%dx%d) bytesperlines %d sizeimage " + "%d colorspace %08x", pixformat >> 0, pixformat >> 8, pixformat >> 16, pixformat >> 24, *width, *height, vid_source->dst_fmt.fmt.pix.bytesperline, vid_source->dst_fmt.fmt.pix.sizeimage, vid_source->dst_fmt.fmt.pix.colorspace); return 0; } - motion_log(ERR, TYPE_VIDEO, SHOW_ERRNO, "%s: VIDIOC_TRY_FMT failed for format %c%c%c%c ", - __FUNCTION__, pixformat >> 0, pixformat >> 8, pixformat >> 16, pixformat >> 24); + MOTION_LOG(ERR, TYPE_VIDEO, SHOW_ERRNO, "%s: VIDIOC_TRY_FMT failed for format %c%c%c%c ", + pixformat >> 0, pixformat >> 8, pixformat >> 16, pixformat >> 24); return -1; } - motion_log(ERR, TYPE_VIDEO, NO_ERRNO, "%s: Unable to find a compatible palette format.", __FUNCTION__); + MOTION_LOG(ERR, TYPE_VIDEO, NO_ERRNO, "%s: Unable to find a compatible palette format."); return -1; } @@ -501,7 +498,7 @@ static void v4l2_set_fps(src_v4l2_t * vid_source) { setfpvid_source->parm.capture.timeperframe.denominator = vid_source->fps; if (xioctl(vid_source->fd, VIDIOC_S_PARM, setfps) == -1) - motion_log(ERR, 1, "%s: v4l2_set_fps VIDIOC_S_PARM", __FUNCTION__); + MOTION_LOG(ERR, 1, "%s: v4l2_set_fps VIDIOC_S_PARM"); } @@ -526,24 +523,24 @@ static int v4l2_set_mmap(src_v4l2_t * vid_source) vid_source->req.memory = V4L2_MEMORY_MMAP; if (xioctl(vid_source->fd, VIDIOC_REQBUFS, &vid_source->req) == -1) { - motion_log(ERR, TYPE_VIDEO, SHOW_ERRNO, "%s: Error requesting buffers %d for memory map. VIDIOC_REQBUFS", - __FUNCTION__, vid_source->req.count); + MOTION_LOG(ERR, TYPE_VIDEO, SHOW_ERRNO, "%s: Error requesting buffers %d for memory map. VIDIOC_REQBUFS", + vid_source->req.count); return -1; } - motion_log(DBG, TYPE_VIDEO, NO_ERRNO, "%s: mmap information: frames=%d", - __FUNCTION__, vid_source->req.count); + MOTION_LOG(DBG, TYPE_VIDEO, NO_ERRNO, "%s: mmap information: frames=%d", + vid_source->req.count); if (vid_source->req.count < MIN_MMAP_BUFFERS) { - motion_log(ERR, TYPE_VIDEO, SHOW_ERRNO, "%s: Insufficient buffer memory %d < MIN_MMAP_BUFFERS.", - __FUNCTION__, vid_source->req.count); + MOTION_LOG(ERR, TYPE_VIDEO, SHOW_ERRNO, "%s: Insufficient buffer memory %d < MIN_MMAP_BUFFERS.", + vid_source->req.count); return -1; } vid_source->buffers = calloc(vid_source->req.count, sizeof(video_buff)); if (!vid_source->buffers) { - motion_log(ERR, TYPE_VIDEO, SHOW_ERRNO, "%s: Out of memory.", __FUNCTION__); + MOTION_LOG(ERR, TYPE_VIDEO, SHOW_ERRNO, "%s: Out of memory."); return -1; } @@ -557,8 +554,8 @@ static int v4l2_set_mmap(src_v4l2_t * vid_source) buf.index = buffer_index; if (xioctl(vid_source->fd, VIDIOC_QUERYBUF, &buf) == -1) { - motion_log(ERR, TYPE_VIDEO, SHOW_ERRNO, "%s: Error querying buffer %i\nVIDIOC_QUERYBUF: ", - __FUNCTION__, buffer_index); + MOTION_LOG(ERR, TYPE_VIDEO, SHOW_ERRNO, "%s: Error querying buffer %i\nVIDIOC_QUERYBUF: ", + buffer_index); free(vid_source->buffers); return -1; } @@ -568,14 +565,14 @@ static int v4l2_set_mmap(src_v4l2_t * vid_source) MAP_SHARED, vid_source->fd, buf.m.offset); if (vid_source->buffers[buffer_index].ptr == MAP_FAILED) { - motion_log(ERR, TYPE_VIDEO, SHOW_ERRNO, "%s: Error mapping buffer %i mmap", - __FUNCTION__, buffer_index); + MOTION_LOG(ERR, TYPE_VIDEO, SHOW_ERRNO, "%s: Error mapping buffer %i mmap", + buffer_index); free(vid_source->buffers); return -1; } - motion_log(DBG, TYPE_VIDEO, NO_ERRNO, "%s: %i length=%d", - __FUNCTION__, buffer_index, buf.length); + MOTION_LOG(DBG, TYPE_VIDEO, NO_ERRNO, "%s: %i length=%d", + buffer_index, buf.length); } for (buffer_index = 0; buffer_index < vid_source->req.count; buffer_index++) { @@ -586,7 +583,7 @@ static int v4l2_set_mmap(src_v4l2_t * vid_source) vid_source->buf.index = buffer_index; if (xioctl(vid_source->fd, VIDIOC_QBUF, &vid_source->buf) == -1) { - motion_log(ERR, TYPE_VIDEO, SHOW_ERRNO, "%s: VIDIOC_QBUF", __FUNCTION__); + MOTION_LOG(ERR, TYPE_VIDEO, SHOW_ERRNO, "%s: VIDIOC_QBUF"); return -1; } } @@ -594,8 +591,7 @@ static int v4l2_set_mmap(src_v4l2_t * vid_source) type = V4L2_BUF_TYPE_VIDEO_CAPTURE; if (xioctl(vid_source->fd, VIDIOC_STREAMON, &type) == -1) { - motion_log(ERR, TYPE_VIDEO, SHOW_ERRNO, "%s: Error starting stream. VIDIOC_STREAMON", - __FUNCTION__); + MOTION_LOG(ERR, TYPE_VIDEO, SHOW_ERRNO, "%s: Error starting stream. VIDIOC_STREAMON"); return -1; } @@ -625,7 +621,7 @@ static int v4l2_scan_controls(src_v4l2_t * vid_source) struct v4l2_queryctrl *ctrl = vid_source->controls = calloc(count, sizeof(struct v4l2_queryctrl)); if (!ctrl) { - motion_log(ERR, TYPE_VIDEO, SHOW_ERRNO, "%s: Insufficient buffer memory.", __FUNCTION__); + MOTION_LOG(ERR, TYPE_VIDEO, SHOW_ERRNO, "%s: Insufficient buffer memory."); return -1; } @@ -639,14 +635,14 @@ static int v4l2_scan_controls(src_v4l2_t * vid_source) memcpy(ctrl, &queryctrl, sizeof(struct v4l2_queryctrl)); - motion_log(ERR, TYPE_VIDEO, NO_ERRNO, "%s: found control 0x%08x, \"%s\", range %d,%d %s", - __FUNCTION__,ctrl->id, ctrl->name, ctrl->minimum, ctrl->maximum, + MOTION_LOG(ERR, TYPE_VIDEO, NO_ERRNO, "%s: found control 0x%08x, \"%s\", range %d,%d %s", + ctrl->id, ctrl->name, ctrl->minimum, ctrl->maximum, ctrl->flags & V4L2_CTRL_FLAG_DISABLED ? "!DISABLED!" : ""); memset(&control, 0, sizeof (control)); control.id = queried_ctrls[i]; xioctl(vid_source->fd, VIDIOC_G_CTRL, &control); - motion_log(ERR, TYPE_VIDEO, NO_ERRNO, "%s: \t\"%s\", default %d, current %d", __FUNCTION__, + MOTION_LOG(ERR, TYPE_VIDEO, NO_ERRNO, "%s: \t\"%s\", default %d, current %d", ctrl->name, ctrl->default_value, control.value); ctrl++; @@ -690,13 +686,12 @@ static int v4l2_set_control(src_v4l2_t * vid_source, u32 cid, int value) break; default: - motion_log(ERR, TYPE_VIDEO, NO_ERRNO, "%s: control type not supported yet", - __FUNCTION__); + MOTION_LOG(ERR, TYPE_VIDEO, NO_ERRNO, "%s: control type not supported yet"); return -1; } - motion_log(NTC, TYPE_VIDEO, NO_ERRNO, "%s: setting control \"%s\" to %d (ret %d %s) %s", - __FUNCTION__, ctrl->name, value, ret, ret ? strerror(errno) : "", + MOTION_LOG(NTC, TYPE_VIDEO, NO_ERRNO, "%s: setting control \"%s\" to %d (ret %d %s) %s", + ctrl->name, value, ret, ret ? strerror(errno) : "", ctrl->flags & V4L2_CTRL_FLAG_DISABLED ? "Control is DISABLED!" : ""); return 0; @@ -756,7 +751,7 @@ unsigned char *v4l2_start(struct context *cnt, struct video_dev *viddev, int wid /* Allocate memory for the state structure. */ if (!(vid_source = calloc(sizeof(src_v4l2_t), 1))) { - motion_log(ERR, TYPE_VIDEO, SHOW_ERRNO, "%s: Out of memory.", __FUNCTION__); + MOTION_LOG(ERR, TYPE_VIDEO, SHOW_ERRNO, "%s: Out of memory."); goto err; } @@ -852,8 +847,8 @@ void v4l2_set_input(struct context *cnt, struct video_dev *viddev, unsigned char src_v4l2_t *vid_source = (src_v4l2_t *) viddev->v4l2_private; unsigned int counter = 0; - motion_log(NTC, TYPE_VIDEO, NO_ERRNO, "%s: set_input_skip_frame switch_time=%ld:%ld", - __FUNCTION__, switchTime.tv_sec, switchTime.tv_usec); + MOTION_LOG(NTC, TYPE_VIDEO, NO_ERRNO, "%s: set_input_skip_frame switch_time=%ld:%ld", + switchTime.tv_sec, switchTime.tv_usec); /* Avoid hang using the number of mmap buffers */ while(counter < vid_source->req.count) { @@ -866,9 +861,9 @@ void v4l2_set_input(struct context *cnt, struct video_dev *viddev, unsigned char vid_source->buf.timestamp.tv_usec > switchTime.tv_usec)) break; - motion_log(NTC, TYPE_VIDEO, NO_ERRNO, "%s: got frame before switch timestamp=%ld:%ld", - __FUNCTION__, vid_source->buf.timestamp.tv_sec, - vid_source->buf.timestamp.tv_usec); + MOTION_LOG(NTC, TYPE_VIDEO, NO_ERRNO, "%s: got frame before switch timestamp=%ld:%ld", + vid_source->buf.timestamp.tv_sec, + vid_source->buf.timestamp.tv_usec); } } @@ -901,12 +896,12 @@ int v4l2_next(struct context *cnt, struct video_dev *viddev, unsigned char *map, sigaddset(&set, SIGHUP); pthread_sigmask(SIG_BLOCK, &set, &old); - motion_log(NTC, TYPE_VIDEO, NO_ERRNO, "%s: 1) vid_source->pframe %i", - __FUNCTION__, vid_source->pframe); + MOTION_LOG(NTC, TYPE_VIDEO, NO_ERRNO, "%s: 1) vid_source->pframe %i", + vid_source->pframe); if (vid_source->pframe >= 0) { if (xioctl(vid_source->fd, VIDIOC_QBUF, &vid_source->buf) == -1) { - motion_log(ERR, TYPE_VIDEO, SHOW_ERRNO, "%s: VIDIOC_QBUF", __FUNCTION__); + MOTION_LOG(ERR, TYPE_VIDEO, SHOW_ERRNO, "%s: VIDIOC_QBUF"); pthread_sigmask(SIG_UNBLOCK, &old, NULL); return -1; } @@ -931,15 +926,15 @@ int v4l2_next(struct context *cnt, struct video_dev *viddev, unsigned char *map, vid_source->pframe = 0; vid_source->buf.index = vid_source->pframe; - motion_log(ERR, TYPE_VIDEO, SHOW_ERRNO, "%s: VIDIOC_DQBUF: EIO (vid_source->pframe %d)", - __FUNCTION__, vid_source->pframe); + MOTION_LOG(ERR, TYPE_VIDEO, SHOW_ERRNO, "%s: VIDIOC_DQBUF: EIO (vid_source->pframe %d)", + vid_source->pframe); ret = 1; } else if (errno == EAGAIN) { - motion_log(ERR, TYPE_VIDEO, SHOW_ERRNO, "%s: VIDIOC_DQBUF: EAGAIN (vid_source->pframe %d)", - __FUNCTION__, vid_source->pframe); + MOTION_LOG(ERR, TYPE_VIDEO, SHOW_ERRNO, "%s: VIDIOC_DQBUF: EAGAIN (vid_source->pframe %d)", + vid_source->pframe); ret = 1; } else { - motion_log(ERR, TYPE_VIDEO, SHOW_ERRNO, "%s: VIDIOC_DQBUF", __FUNCTION__); + MOTION_LOG(ERR, TYPE_VIDEO, SHOW_ERRNO, "%s: VIDIOC_DQBUF"); ret = -1; } @@ -947,17 +942,17 @@ int v4l2_next(struct context *cnt, struct video_dev *viddev, unsigned char *map, return ret; } - motion_log(NTC, TYPE_VIDEO, NO_ERRNO, "%s: 2) vid_source->pframe %i", - __FUNCTION__, vid_source->pframe); + MOTION_LOG(NTC, TYPE_VIDEO, NO_ERRNO, "%s: 2) vid_source->pframe %i", + vid_source->pframe); vid_source->pframe = vid_source->buf.index; vid_source->buffers[vid_source->buf.index].used = vid_source->buf.bytesused; vid_source->buffers[vid_source->buf.index].content_length = vid_source->buf.bytesused; - motion_log(NTC, TYPE_VIDEO, NO_ERRNO, "%s: 3) vid_source->pframe %i vid_source->buf.index %i", - __FUNCTION__, vid_source->pframe, vid_source->buf.index); - motion_log(NTC, TYPE_VIDEO, NO_ERRNO, "%s: vid_source->buf.bytesused %i", - __FUNCTION__, vid_source->buf.bytesused); + MOTION_LOG(NTC, TYPE_VIDEO, NO_ERRNO, "%s: 3) vid_source->pframe %i vid_source->buf.index %i", + vid_source->pframe, vid_source->buf.index); + MOTION_LOG(NTC, TYPE_VIDEO, NO_ERRNO, "%s: vid_source->buf.bytesused %i", + vid_source->buf.bytesused); pthread_sigmask(SIG_UNBLOCK, &old, NULL); /*undo the signal blocking */ diff --git a/video_common.c b/video_common.c index 90170b6..5144103 100644 --- a/video_common.c +++ b/video_common.c @@ -9,8 +9,8 @@ * */ -/* for rotation */ -#include "rotate.h" /* already includes motion.h */ +/* For rotation */ +#include "rotate.h" /* Already includes motion.h */ #include "video.h" #include "jpegutils.h" @@ -89,7 +89,7 @@ static void sonix_decompress_init(code_table_t * table) /** * sonix_decompress - * decompresses an image encoded by a SN9C101 camera controller chip. + * Decompresses an image encoded by a SN9C101 camera controller chip. * * IN width * height @@ -108,14 +108,14 @@ int sonix_decompress(unsigned char *outp, unsigned char *inp, int width, int hei unsigned char code; unsigned char *addr; - /* local storage */ + /* Local storage */ static code_table_t table[256]; static int init_done = 0; if (!init_done) { init_done = 1; sonix_decompress_init(table); - /* do sonix_decompress_init first! */ + /* Do sonix_decompress_init first! */ //return -1; // so it has been done and now fall through } @@ -124,7 +124,7 @@ int sonix_decompress(unsigned char *outp, unsigned char *inp, int width, int hei col = 0; - /* first two pixels in first two rows are stored as raw 8-bit */ + /* First two pixels in first two rows are stored as raw 8-bit. */ if (row < 2) { addr = inp + (bitpos >> 3); code = (addr[0] << (bitpos & 7)) | (addr[1] >> (8 - (bitpos & 7))); @@ -140,30 +140,30 @@ int sonix_decompress(unsigned char *outp, unsigned char *inp, int width, int hei } while (col < width) { - /* get bitcode from bitstream */ + /* Get bitcode from bitstream. */ addr = inp + (bitpos >> 3); code = (addr[0] << (bitpos & 7)) | (addr[1] >> (8 - (bitpos & 7))); - /* update bit position */ + /* Update bit position. */ bitpos += table[code].len; - /* calculate pixel value */ + /* Calculate pixel value. */ val = table[code].val; if (!table[code].is_abs) { - /* value is relative to top and left pixel */ + /* Value is relative to top and left pixel. */ if (col < 2) { - /* left column: relative to top pixel */ + /* Left column: relative to top pixel. */ val += outp[-2 * width]; } else if (row < 2) { - /* top row: relative to left pixel */ + /* Top row: relative to left pixel. */ val += outp[-2]; } else { - /* main area: average of left pixel and top pixel */ + /* Main area: average of left pixel and top pixel. */ val += (outp[-2] + outp[-2 * width]) / 2; } } - /* store pixel */ + /* Store pixel */ *outp++ = CLAMP(val); col++; } @@ -201,7 +201,7 @@ void bayer2rgb24(unsigned char *dst, unsigned char *src, long int width, long in *scanpt++ = (*(rawpt - width - 1) + *(rawpt - width + 1) + *(rawpt + width - 1) + *(rawpt + width + 1)) / 4; /* R */ } else { - /* first line or left column */ + /* First line or left column. */ *scanpt++ = *rawpt; /* B */ *scanpt++ = (*(rawpt + 1) + *(rawpt + width)) / 2; /* G */ *scanpt++ = *(rawpt + width + 1); /* R */ @@ -213,7 +213,7 @@ void bayer2rgb24(unsigned char *dst, unsigned char *src, long int width, long in *scanpt++ = *rawpt; /* G */ *scanpt++ = (*(rawpt + width) + *(rawpt - width)) / 2; /* R */ } else { - /* first line or right column */ + /* First line or right column. */ *scanpt++ = *(rawpt - 1); /* B */ *scanpt++ = *rawpt; /* G */ *scanpt++ = *(rawpt + width); /* R */ @@ -227,7 +227,7 @@ void bayer2rgb24(unsigned char *dst, unsigned char *src, long int width, long in *scanpt++ = *rawpt; /* G */ *scanpt++ = (*(rawpt - 1) + *(rawpt + 1)) / 2; /* R */ } else { - /* bottom line or left column */ + /* Bottom line or left column. */ *scanpt++ = *(rawpt - width); /* B */ *scanpt++ = *rawpt; /* G */ *scanpt++ = *(rawpt + 1); /* R */ @@ -241,7 +241,7 @@ void bayer2rgb24(unsigned char *dst, unsigned char *src, long int width, long in *(rawpt - width) + *(rawpt + width)) / 4; /* G */ *scanpt++ = *rawpt; /* R */ } else { - /* bottom line or right column */ + /* Bottom line or right column. */ *scanpt++ = *(rawpt - width - 1); /* B */ *scanpt++ = (*(rawpt - 1) + *(rawpt - width)) / 2; /* G */ *scanpt++ = *rawpt; /* R */ @@ -255,20 +255,22 @@ void bayer2rgb24(unsigned char *dst, unsigned char *src, long int width, long in /** * conv_yuv422to420p + * + * */ void conv_yuv422to420p(unsigned char *map, unsigned char *cap_map, int width, int height) { unsigned char *src, *dest, *src2, *dest2; int i, j; - /* Create the Y plane */ + /* Create the Y plane. */ src = cap_map; dest = map; for (i = width * height; i > 0; i--) { *dest++ = *src; src += 2; } - /* Create U and V planes */ + /* Create U and V planes. */ src = cap_map + 1; src2 = cap_map + width * 2 + 1; dest = map + width * height; @@ -291,6 +293,8 @@ void conv_yuv422to420p(unsigned char *map, unsigned char *cap_map, int width, in /** * conv_uyvyto420p + * + * */ void conv_uyvyto420p(unsigned char *map, unsigned char *cap_map, unsigned int width, unsigned int height) { @@ -329,6 +333,8 @@ void conv_uyvyto420p(unsigned char *map, unsigned char *cap_map, unsigned int wi /** * conv_rgb24toyuv420p + * + * */ void conv_rgb24toyuv420p(unsigned char *map, unsigned char *cap_map, int width, int height) { @@ -393,8 +399,7 @@ int mjpegtoyuv420p(unsigned char *map, unsigned char *cap_map, int width, int he ret = decode_jpeg_raw(cap_map, size, 0, 420, width, height, yuv[0], yuv[1], yuv[2]); if (ret == 1) { - motion_log(CRT, TYPE_VIDEO, NO_ERRNO, "%s: Corrupt image ... continue", - __FUNCTION__); + MOTION_LOG(CRT, TYPE_VIDEO, NO_ERRNO, "%s: Corrupt image ... continue"); ret = 2; } @@ -472,7 +477,7 @@ int vid_do_autobright(struct context *cnt, struct video_dev *viddev) } avg = avg / j; - /* average is above window - turn down brightness - go for the target */ + /* Average is above window - turn down brightness - go for the target. */ if (avg > brightness_window_high) { step = MIN2((avg - brightness_target) / AUTOBRIGHT_DAMPER + 1, viddev->brightness - AUTOBRIGHT_MIN); @@ -481,7 +486,7 @@ int vid_do_autobright(struct context *cnt, struct video_dev *viddev) make_change = 1; } } else if (avg < brightness_window_low) { - /* average is below window - turn up brightness - go for the target */ + /* Average is below window - turn up brightness - go for the target. */ step = MIN2((brightness_target - avg) / AUTOBRIGHT_DAMPER + 1, AUTOBRIGHT_MAX - viddev->brightness); if (viddev->brightness < AUTOBRIGHT_MAX - step) { @@ -500,7 +505,7 @@ int vid_do_autobright(struct context *cnt, struct video_dev *viddev) #ifndef WITHOUT_V4L /* * Big lock for vid_start to ensure exclusive access to viddevs while adding - * devices during initialization of each thread + * devices during initialization of each thread. */ static pthread_mutex_t vid_mutex; @@ -514,7 +519,7 @@ static struct video_dev *viddevs = NULL; * vid_init * * Called from motion.c at the very beginning before setting up the threads. - * Function prepares the vid_mutex + * Function prepares the vid_mutex. */ void vid_init(void) { @@ -524,7 +529,7 @@ void vid_init(void) /** * vid_cleanup * - * vid_cleanup is called from motion.c when Motion is stopped or restarted + * vid_cleanup is called from motion.c when Motion is stopped or restarted. */ void vid_cleanup(void) { @@ -536,7 +541,7 @@ void vid_cleanup(void) /** * vid_close * - * vid_close is called from motion.c when a Motion thread is stopped or restarted + * vid_close is called from motion.c when a Motion thread is stopped or restarted. */ void vid_close(struct context *cnt) { @@ -547,7 +552,7 @@ void vid_close(struct context *cnt) /* Cleanup the netcam part */ if (cnt->netcam) { - motion_log(DBG, TYPE_VIDEO, NO_ERRNO, "%s: calling netcam_cleanup", __FUNCTION__); + MOTION_LOG(INF, TYPE_VIDEO, NO_ERRNO, "%s: calling netcam_cleanup"); netcam_cleanup(cnt->netcam, 0); cnt->netcam = NULL; return; @@ -565,17 +570,17 @@ void vid_close(struct context *cnt) } pthread_mutex_unlock(&vid_mutex); - /* Set it as closed in thread context */ + /* Set it as closed in thread context. */ cnt->video_dev = -1; if (dev == NULL) { - motion_log(ERR, TYPE_VIDEO, NO_ERRNO, "%s: Unable to find video device", __FUNCTION__); + MOTION_LOG(EMG, TYPE_VIDEO, NO_ERRNO, "%s: Unable to find video device"); return; } if (--dev->usage_count == 0) { - motion_log(ERR, TYPE_VIDEO, NO_ERRNO, "%s: Closing video device %s", - __FUNCTION__, dev->video_device); + MOTION_LOG(ALR, TYPE_VIDEO, NO_ERRNO, "%s: Closing video device %s", + dev->video_device); #ifdef MOTION_V4L2 if (dev->v4l2) { v4l2_close(dev); @@ -600,11 +605,11 @@ void vid_close(struct context *cnt) pthread_mutex_destroy(&dev->mutex); free(dev); } else { - motion_log(ERR, TYPE_VIDEO, NO_ERRNO, "%s: Still %d users of video device %s, so we don't close it now", - __FUNCTION__, dev->usage_count, dev->video_device); + MOTION_LOG(ALR, TYPE_VIDEO, NO_ERRNO, "%s: Still %d users of video device %s, so we don't close it now", + dev->usage_count, dev->video_device); /* * There is still at least one thread using this device - * If we own it, release it + * If we own it, release it. */ if (dev->owner == cnt->threadnr) { dev->frames = 0; @@ -658,14 +663,14 @@ static int vid_v4lx_start(struct context *cnt) * for this first. */ if (conf->width % 16) { - motion_log(ERR, TYPE_VIDEO, NO_ERRNO, "%s: config image width (%d) is not modulo 16", - __FUNCTION__, conf->width); + MOTION_LOG(ALR, TYPE_VIDEO, NO_ERRNO, "%s: config image width (%d) is not modulo 16", + conf->width); return -3; } if (conf->height % 16) { - motion_log(ERR, TYPE_VIDEO, NO_ERRNO, "%s: config image height (%d) is not modulo 16", - __FUNCTION__, conf->height); + MOTION_LOG(ALR, TYPE_VIDEO, NO_ERRNO, "%s: config image height (%d) is not modulo 16", + conf->height); return -3; } @@ -690,7 +695,7 @@ static int vid_v4lx_start(struct context *cnt) * First we walk through the already discovered video devices to see * if we have already setup the same device before. If this is the case * the device is a Round Robin device and we set the basic settings - * and return the file descriptor + * and return the file descriptor. */ dev = viddevs; while (dev) { @@ -717,8 +722,8 @@ static int vid_v4lx_start(struct context *cnt) dev = dev->next; } - motion_log(ALR, TYPE_VIDEO, NO_ERRNO, "%s: Using videodevice %s and input %d", - __FUNCTION__, conf->video_device, conf->input); + MOTION_LOG(ALR, TYPE_VIDEO, NO_ERRNO, "%s: Using videodevice %s and input %d", + conf->video_device, conf->input); dev = mymalloc(sizeof(struct video_dev)); memset(dev, 0, sizeof(struct video_dev)); @@ -728,8 +733,8 @@ static int vid_v4lx_start(struct context *cnt) fd = open(dev->video_device, O_RDWR); if (fd < 0) { - motion_log(ERR, TYPE_VIDEO, SHOW_ERRNO, "%s: Failed to open video device %s", - __FUNCTION__, conf->video_device); + MOTION_LOG(ALR, TYPE_VIDEO, SHOW_ERRNO, "%s: Failed to open video device %s", + conf->video_device); free(dev); pthread_mutex_unlock(&vid_mutex); return -1; @@ -759,14 +764,14 @@ static int vid_v4lx_start(struct context *cnt) dev->v4l_fmt = VIDEO_PALETTE_YUV420P; dev->fps = 0; #ifdef MOTION_V4L2 - /* First lets try V4L2 and if it's not supported V4L1 */ + /* First lets try V4L2 and if it's not supported V4L1. */ dev->v4l2 = 1; if (!v4l2_start(cnt, dev, width, height, input, norm, frequency, tuner_number)) { /* * Restore width & height before test with v4l - * because could be changed in v4l2_start () + * because could be changed in v4l2_start(). */ dev->width = width; dev->height = height; @@ -786,10 +791,10 @@ static int vid_v4lx_start(struct context *cnt) } #endif if (dev->v4l2 == 0) { - motion_log(ALR, TYPE_VIDEO, NO_ERRNO, "%s: Using V4L1", __FUNCTION__); + MOTION_LOG(ALR, TYPE_VIDEO, NO_ERRNO, "%s: Using V4L1"); } else { - motion_log(ALR, TYPE_VIDEO, NO_ERRNO, "%s: Using V4L2", __FUNCTION__); - /* Update width & height because could be changed in v4l2_start () */ + MOTION_LOG(ALR, TYPE_VIDEO, NO_ERRNO, "%s: Using V4L2"); + /* Update width & height because could be changed in v4l2_start(). */ width = dev->width; height = dev->height; cnt->imgs.width = width; @@ -813,7 +818,7 @@ static int vid_v4lx_start(struct context *cnt) break; } - /* Insert into linked list */ + /* Insert into linked list. */ dev->next = viddevs; viddevs = dev; @@ -859,7 +864,7 @@ int vid_start(struct context *cnt) } #ifdef WITHOUT_V4L else - motion_log(ERR, TYPE_VIDEO, NO_ERRNO, "%s: You must setup netcam_url", __FUNCTION__); + MOTION_LOG(EMG, TYPE_VIDEO, NO_ERRNO, "%s: You must setup netcam_url"); #else else dev = vid_v4lx_start(cnt); @@ -902,7 +907,7 @@ int vid_next(struct context *cnt, unsigned char *map) #ifndef WITHOUT_V4L /* * We start a new block so we can make declarations without breaking - * gcc 2.95 or older + * gcc 2.95 or older. */ { struct video_dev *dev; @@ -946,11 +951,11 @@ int vid_next(struct context *cnt, unsigned char *map) pthread_mutex_unlock(&dev->mutex); } - /* rotate the image as specified */ + /* Rotate the image as specified. */ if (cnt->rotate_data.degrees > 0) rotate_map(cnt, map); } -#endif /*WITHOUT_V4L */ +#endif /*WITHOUT_V4L */ return ret; } diff --git a/video_freebsd.c b/video_freebsd.c index 43293b4..153cb35 100644 --- a/video_freebsd.c +++ b/video_freebsd.c @@ -7,13 +7,13 @@ * */ -/* for rotation */ -#include "rotate.h" /* already includes motion.h */ +/* For rotation */ +#include "rotate.h" /* Already includes motion.h */ #include "video_freebsd.h" #ifndef WITHOUT_V4L -/* for the v4l stuff: */ +/* For the v4l stuff: */ #include /* Hack from xawtv 4.x */ @@ -107,7 +107,10 @@ static void yuv422to420p(unsigned char *map, unsigned char *cap_map, int width, } -/* FIXME seems no work with METEOR_GEO_RGB24 , check BPP as well ? */ +/** + * rgb24toyuv420p + * FIXME seems no work with METEOR_GEO_RGB24 , check BPP as well ? + */ static void rgb24toyuv420p(unsigned char *map, unsigned char *cap_map, int width, int height) { unsigned char *y, *u, *v; @@ -175,12 +178,12 @@ static int set_hue(int viddev, int new_hue) signed char ioctlval = new_hue; if (ioctl(viddev, METEORSHUE, &ioctlval) < 0) { - motion_log(ERR, TYPE_VIDEO, SHOW_ERRNO, "%s: METEORSHUE Error setting hue [%d]", - __FUNCTION__, new_hue); + MOTION_LOG(ERR, TYPE_VIDEO, SHOW_ERRNO, "%s: METEORSHUE Error setting hue [%d]", + new_hue); return -1; } - motion_log(WRN, TYPE_VIDEO, NO_ERRNO, "%s: to [%d]", __FUNCTION__, ioctlval); + MOTION_LOG(NTC, TYPE_VIDEO, NO_ERRNO, "%s: to [%d]", ioctlval); return ioctlval; } @@ -190,12 +193,11 @@ static int get_hue(int viddev , int *hue) signed char ioctlval; if (ioctl(viddev, METEORGHUE, &ioctlval) < 0) { - motion_log(ERR, TYPE_VIDEO, SHOW_ERRNO, "%s: METEORGHUE Error getting hue", - __FUNCTION__); + MOTION_LOG(ERR, TYPE_VIDEO, SHOW_ERRNO, "%s: METEORGHUE Error getting hue"); return -1; } - motion_log(WRN, TYPE_VIDEO, NO_ERRNO, "%s: to [%d]", __FUNCTION__, ioctlval); + MOTION_LOG(NTC, TYPE_VIDEO, NO_ERRNO, "%s: to [%d]", ioctlval); *hue = ioctlval; return ioctlval; @@ -206,12 +208,12 @@ static int set_saturation(int viddev, int new_saturation) unsigned char ioctlval= new_saturation; if (ioctl(viddev, METEORSCSAT, &ioctlval) < 0) { - motion_log(ERR, TYPE_VIDEO, SHOW_ERRNO, "%s: METEORSCSAT Error setting saturation [%d]", - __FUNCTION__, new_saturation); + MOTION_LOG(ERR, TYPE_VIDEO, SHOW_ERRNO, "%s: METEORSCSAT Error setting saturation [%d]", + new_saturation); return -1; } - motion_log(WRN, TYPE_VIDEO, NO_ERRNO, "%s: to [%d]", __FUNCTION__, ioctlval); + MOTION_LOG(NTC, TYPE_VIDEO, NO_ERRNO, "%s: to [%d]", ioctlval); return ioctlval; } @@ -221,12 +223,11 @@ static int get_saturation(int viddev , int *saturation) unsigned char ioctlval; if (ioctl(viddev, METEORGCSAT, &ioctlval) < 0) { - motion_log(ERR, TYPE_VIDEO, SHOW_ERRNO, "%s: METEORGCSAT Error getting saturation", - __FUNCTION__); + MOTION_LOG(ERR, TYPE_VIDEO, SHOW_ERRNO, "%s: METEORGCSAT Error getting saturation"); return -1; } - motion_log(WRN, TYPE_VIDEO, NO_ERRNO, "%s: to [%d]", __FUNCTION__, ioctlval); + MOTION_LOG(NTC, TYPE_VIDEO, NO_ERRNO, "%s: to [%d]", ioctlval); *saturation = ioctlval; return ioctlval; @@ -237,12 +238,12 @@ static int set_contrast(int viddev, int new_contrast) unsigned char ioctlval = new_contrast; if (ioctl(viddev, METEORSCONT, &ioctlval) < 0) { - motion_log(ERR, TYPE_VIDEO, SHOW_ERRNO, "%s: METEORSCONT Error setting contrast [%d]", - __FUNCTION__, new_contrast); + MOTION_LOG(ERR, TYPE_VIDEO, SHOW_ERRNO, "%s: METEORSCONT Error setting contrast [%d]", + new_contrast); return 0; } - motion_log(WRN, TYPE_VIDEO, NO_ERRNO, "%s: to [%d]", __FUNCTION__, ioctlval); + MOTION_LOG(NTC, TYPE_VIDEO, NO_ERRNO, "%s: to [%d]", ioctlval); return ioctlval; } @@ -252,12 +253,11 @@ static int get_contrast(int viddev, int *contrast) unsigned char ioctlval; if (ioctl(viddev, METEORGCONT, &ioctlval) < 0) { - motion_log(ERR, TYPE_VIDEO, SHOW_ERRNO, "%s: METEORGCONT Error getting contrast", - __FUNCTION__); + MOTION_LOG(ERR, TYPE_VIDEO, SHOW_ERRNO, "%s: METEORGCONT Error getting contrast"); return -1; } - motion_log(WRN, TYPE_VIDEO, NO_ERRNO, "%s: to [%d]", __FUNCTION__, ioctlval); + MOTION_LOG(NTC, TYPE_VIDEO, NO_ERRNO, "%s: to [%d]", ioctlval); *contrast = ioctlval; return ioctlval; @@ -269,12 +269,12 @@ static int set_brightness(int viddev, int new_bright) unsigned char ioctlval = new_bright; if (ioctl(viddev, METEORSBRIG, &ioctlval) < 0) { - motion_log(ERR, TYPE_VIDEO, SHOW_ERRNO, "%s: METEORSBRIG brightness [%d]", - __FUNCTION__, new_bright); + MOTION_LOG(ERR, TYPE_VIDEO, SHOW_ERRNO, "%s: METEORSBRIG brightness [%d]", + new_bright); return -1; } - motion_log(WRN, TYPE_VIDEO, NO_ERRNO, "%s: to [%d]", __FUNCTION__, ioctlval); + MOTION_LOG(NTC, TYPE_VIDEO, NO_ERRNO, "%s: to [%d]", ioctlval); return ioctlval; } @@ -285,12 +285,11 @@ static int get_brightness(int viddev, int *brightness) unsigned char ioctlval; if (ioctl(viddev, METEORGBRIG, &ioctlval) < 0) { - motion_log(ERR, TYPE_VIDEO, SHOW_ERRNO, "%s: METEORGBRIG getting brightness", - __FUNCTION__); + MOTION_LOG(ERR, TYPE_VIDEO, SHOW_ERRNO, "%s: METEORGBRIG getting brightness"); return -1; } - motion_log(WRN, TYPE_VIDEO, NO_ERRNO, "%s: to [%d]", __FUNCTION__, ioctlval); + MOTION_LOG(NTC, TYPE_VIDEO, NO_ERRNO, "%s: to [%d]", ioctlval); *brightness = ioctlval; return ioctlval; @@ -304,10 +303,10 @@ static int set_channel(struct video_dev *viddev, int new_channel) ioctlval = new_channel; if (ioctl(viddev->fd_tuner, TVTUNER_SETCHNL, &ioctlval) < 0) { - motion_log(ERR, TYPE_VIDEO, SHOW_ERRNO, "Error channel %d", ioctlval); + MOTION_LOG(ERR, TYPE_VIDEO, SHOW_ERRNO, "%s: Error channel %d", ioctlval); return -1; } else { - motion_log(DBG, TYPE_VIDEO, NO_ERRNO, "channel set to %d", ioctlval); + MOTION_LOG(DBG, TYPE_VIDEO, NO_ERRNO, "%s: channel set to %d", ioctlval); } viddev->channel = new_channel; @@ -325,18 +324,18 @@ static int set_freq(struct video_dev *viddev, unsigned long freq) int tuner_fd = viddev->fd_tuner; int old_audio; - motion_log(DBG, TYPE_VIDEO, NO_ERRNO, "%s: Not implemented", __FUNCTION__); + MOTION_LOG(WRN, TYPE_VIDEO, NO_ERRNO, "%s: Not implemented"); return 0; /* HACK maybe not need it , but seems that is needed to mute before changing frequency */ if (ioctl(tuner_fd, BT848_GAUDIO, &old_audio) < 0) { - motion_log(ERR, TYPE_VIDEO, SHOW_ERRNO, "%s: BT848_GAUDIO", __FUNCTION__); + MOTION_LOG(ERR, TYPE_VIDEO, SHOW_ERRNO, "%s: BT848_GAUDIO"); return -1; } if (ioctl(tuner_fd, TVTUNER_SETFREQ, &freq) < 0) { - motion_log(ERR, TYPE_VIDEO, SHOW_ERRNO, "%s: Tuning (TVTUNER_SETFREQ) failed, ", - "freq [%lu]", __FUNCTION__, freq); + MOTION_LOG(ERR, TYPE_VIDEO, SHOW_ERRNO, "%s: Tuning (TVTUNER_SETFREQ) failed, ", + "freq [%lu]", freq); return -1; } @@ -344,7 +343,7 @@ static int set_freq(struct video_dev *viddev, unsigned long freq) if (old_audio) { old_audio = AUDIO_MUTE; if (ioctl(tuner_fd , BT848_SAUDIO, &old_audio) < 0) { - motion_log(ERR, TYPE_VIDEO, SHOW_ERRNO, "%s: BT848_SAUDIO %i", __FUNCTION__, + MOTION_LOG(ERR, TYPE_VIDEO, SHOW_ERRNO, "%s: BT848_SAUDIO %i", old_audio); return -1; } @@ -370,31 +369,31 @@ static int set_input(struct video_dev *viddev, unsigned input) METEOR_INPUT_DEV_SVIDEO }; if (input >= array_elem(portdata)) { - motion_log(ERR, TYPE_VIDEO, NO_ERRNO, "%s: Channel Port %d out of range (0-4)", - __FUNCTION__, input); + MOTION_LOG(ERR, TYPE_VIDEO, NO_ERRNO, "%s: Channel Port %d out of range (0-4)", + input); return -1; } actport = portdata[ input ]; if (ioctl(viddev->fd_bktr, METEORSINPUT, &actport) < 0) { if (input != IN_DEFAULT) { - motion_log(ERR, TYPE_VIDEO, SHOW_ERRNO, "%s: METEORSINPUT %d invalid -" - "Trying default %d", __FUNCTION__, input, IN_DEFAULT); + MOTION_LOG(ERR, TYPE_VIDEO, SHOW_ERRNO, "%s: METEORSINPUT %d invalid -" + "Trying default %d", input, IN_DEFAULT); input = IN_DEFAULT; actport = portdata[ input ]; if (ioctl(viddev->fd_bktr, METEORSINPUT, &actport) < 0) { - motion_log(ERR, TYPE_VIDEO, SHOW_ERRNO, "%s: METEORSINPUT %d init", - __FUNCTION__, input); + MOTION_LOG(ERR, TYPE_VIDEO, SHOW_ERRNO, "%s: METEORSINPUT %d init", + input); return -1; } } else { - motion_log(ERR, TYPE_VIDEO, SHOW_ERRNO, "%s: METEORSINPUT %d init", - __FUNCTION__, input); + MOTION_LOG(ERR, TYPE_VIDEO, SHOW_ERRNO, "%s: METEORSINPUT %d init", + input); return -1; } } - motion_log(WRN, TYPE_VIDEO, NO_ERRNO, "%s: to [%d]", __FUNCTION__, input); + MOTION_LOG(NTC, TYPE_VIDEO, NO_ERRNO, "%s: to [%d]", input); return input; } @@ -428,13 +427,12 @@ static int set_geometry(struct video_dev *viddev, int width, int height) geom.frames = 1; if (ioctl(viddev->fd_bktr, METEORSETGEO, &geom) < 0) { - motion_log(ERR, TYPE_VIDEO, SHOW_ERRNO, "%s: Couldn't set the geometry", - __FUNCTION__); + MOTION_LOG(ERR, TYPE_VIDEO, SHOW_ERRNO, "%s: Couldn't set the geometry"); return -1; } - motion_log(WRN, TYPE_VIDEO, NO_ERRNO, "%s: to [%d/%d] Norm %d", - __FUNCTION__, width, height, viddev->norm); + MOTION_LOG(NTC, TYPE_VIDEO, NO_ERRNO, "%s: to [%d/%d] Norm %d", + width, height, viddev->norm); return 0; } @@ -449,27 +447,27 @@ static int set_input_format(struct video_dev *viddev, unsigned newformat) int format; if (newformat >= array_elem(input_format)) { - motion_log(WRN, TYPE_VIDEO, NO_ERRNO, "%s: Input format %d out of range (0-2)", - __FUNCTION__, newformat); + MOTION_LOG(WRN, TYPE_VIDEO, NO_ERRNO, "%s: Input format %d out of range (0-2)", + newformat); return -1; } format = input_format[newformat]; if (ioctl(viddev->fd_bktr, BT848SFMT, &format) < 0) { - motion_log(ERR, TYPE_VIDEO, SHOW_ERRNO, "%s: BT848SFMT, Couldn't set the input format, " - "try again with default", __FUNCTION__); + MOTION_LOG(WRN, TYPE_VIDEO, SHOW_ERRNO, "%s: BT848SFMT, Couldn't set the input format, " + "try again with default"); format = NORM_DEFAULT_NEW; newformat = 3; if (ioctl(viddev->fd_bktr, BT848SFMT, &format) < 0) { - motion_log(ERR, TYPE_VIDEO, SHOW_ERRNO, "%s: BT848SFMT, Couldn't set the input format " - "either default", __FUNCTION__); + MOTION_LOG(WRN, TYPE_VIDEO, SHOW_ERRNO, "%s: BT848SFMT, Couldn't set the input format " + "either default"); return -1; } } - motion_log(WRN, TYPE_VIDEO, NO_ERRNO, "%s: to %d", __FUNCTION__, newformat); + MOTION_LOG(NTC, TYPE_VIDEO, NO_ERRNO, "%s: to %d", newformat); return newformat; } @@ -486,7 +484,7 @@ statict int setup_pixelformat(int bktr) if (ioctl(bktr, METEORGSUPPIXFMT, &p) < 0) { if (errno == EINVAL) break; - motion_log(ERR, TYPE_VIDEO, SHOW_ERRNO, "METEORGSUPPIXFMT getting pixformat %d", i); + MOTION_LOG(ERR, TYPE_VIDEO, SHOW_ERRNO, "%s: METEORGSUPPIXFMT getting pixformat %d", i); return -1; } @@ -495,40 +493,40 @@ statict int setup_pixelformat(int bktr) switch (p.type) { case METEOR_PIXTYPE_RGB: - motion_log(EMG, TYPE_VIDEO, NO_ERRNO, "setup_pixelformat METEOR_PIXTYPE_RGB"); + MOTION_LOG(EMG, TYPE_VIDEO, NO_ERRNO, "%s: setup_pixelformat METEOR_PIXTYPE_RGB"); switch (p.masks[0]) { case 31744: // 15 bpp format = p.swap_bytes ? VIDEO_RGB15_LE : VIDEO_RGB15_BE; - motion_log(EMG, TYPE_VIDEO, NO_ERRNO, "setup_pixelformat METEOR_PIXTYPE_RGB VIDEO_RGB15"); + MOTION_LOG(EMG, TYPE_VIDEO, NO_ERRNO, "%s: setup_pixelformat METEOR_PIXTYPE_RGB VIDEO_RGB15"); break; case 63488: // 16 bpp format = p.swap_bytes ? VIDEO_RGB16_LE : VIDEO_RGB16_BE; - motion_log(EMG, TYPE_VIDEO, NO_ERRNO, "setup_pixelformat METEOR_PIXTYPE_RGB VIDEO_RGB16"); + MOTION_LOG(EMG, TYPE_VIDEO, NO_ERRNO, "%s: setup_pixelformat METEOR_PIXTYPE_RGB VIDEO_RGB16"); break; case 16711680: // 24/32 bpp if (p.Bpp == 3 && p.swap_bytes == 1) { format = VIDEO_BGR24; - motion_log(EMG, TYPE_VIDEO, NO_ERRNO, "setup_pixelformat METEOR_PIXTYPE_RGB VIDEO_BGR24"); + MOTION_LOG(EMG, TYPE_VIDEO, NO_ERRNO, "%s: setup_pixelformat METEOR_PIXTYPE_RGB VIDEO_BGR24"); } else if (p.Bpp == 4 && p.swap_bytes == 1 && p.swap_shorts == 1) { format = VIDEO_BGR32; - motion_log(EMG, TYPE_VIDEO, NO_ERRNO, "setup_pixelformat METEOR_PIXTYPE_RGB VIDEO_BGR32"); + MOTION_LOG(EMG, TYPE_VIDEO, NO_ERRNO, "%s: setup_pixelformat METEOR_PIXTYPE_RGB VIDEO_BGR32"); } else if (p.Bpp == 4 && p.swap_bytes == 0 && p.swap_shorts == 0) { format = VIDEO_RGB32; - motion_log(EMG, TYPE_VIDEO, NO_ERRNO, "setup_pixelformat METEOR_PIXTYPE_RGB VIDEO_RGB32"); + MOTION_LOG(EMG, TYPE_VIDEO, NO_ERRNO, "%s: setup_pixelformat METEOR_PIXTYPE_RGB VIDEO_RGB32"); } } break; case METEOR_PIXTYPE_YUV: format = VIDEO_YUV422P; - motion_log(EMG, TYPE_VIDEO, NO_ERRNO, "setup_pixelformat METEOR_PIXTYPE_YUV"); + MOTION_LOG(EMG, TYPE_VIDEO, NO_ERRNO, "%s: setup_pixelformat METEOR_PIXTYPE_YUV"); break; case METEOR_PIXTYPE_YUV_12: format = VIDEO_YUV422P; - motion_log(EMG, TYPE_VIDEO, NO_ERRNO, "setup_pixelformat METEOR_PIXTYPE_YUV_12"); + MOTION_LOG(EMG, TYPE_VIDEO, NO_ERRNO, "%s: setup_pixelformat METEOR_PIXTYPE_YUV_12"); break; case METEOR_PIXTYPE_YUV_PACKED: format = VIDEO_YUV422P; - motion_log(EMG, TYPE_VIDEO, NO_ERRNO, "setup_pixelformat METEOR_PIXTYPE_YUV_PACKED"); + MOTION_LOG(EMG, TYPE_VIDEO, NO_ERRNO, "%s: setup_pixelformat METEOR_PIXTYPE_YUV_PACKED"); break; } @@ -536,20 +534,20 @@ statict int setup_pixelformat(int bktr) if (p.type == METEOR_PIXTYPE_RGB && p.Bpp == 3) { // Found a good pixeltype -- set it up if (ioctl(bktr, METEORSACTPIXFMT, &i) < 0) { - motion_log(WRN, TYPE_VIDEO, SHOW_ERRNO, "METEORSACTPIXFMT etting pixformat METEOR_PIXTYPE_RGB Bpp == 3"); + MOTION_LOG(WRN, TYPE_VIDEO, SHOW_ERRNO, "%s: METEORSACTPIXFMT etting pixformat METEOR_PIXTYPE_RGB Bpp == 3"); // Not immediately fatal } - motion_log(DBG, TYPE_VIDEO, NO_ERRNO, "input format METEOR_PIXTYPE_RGB %i", i); + MOTION_LOG(DBG, TYPE_VIDEO, NO_ERRNO, "%s: input format METEOR_PIXTYPE_RGB %i", i); format = i; } if (p.type == METEOR_PIXTYPE_YUV_PACKED) { // Found a good pixeltype -- set it up if (ioctl(bktr, METEORSACTPIXFMT, &i) < 0) { - motion_log(WRN, TYPE_VIDEO, SHOW_ERRNO, "METEORSACTPIXFMT setting pixformat METEOR_PIXTYPE_YUV_PACKED"); + MOTION_LOG(WRN, TYPE_VIDEO, SHOW_ERRNO, "%s: METEORSACTPIXFMT setting pixformat METEOR_PIXTYPE_YUV_PACKED"); // Not immediately fatal } - motion_log(DBG, TYPE_VIDEO, NO_ERRNO, "input format METEOR_PIXTYPE_YUV_PACKED %i", i); + MOTION_LOG(DBG, TYPE_VIDEO, NO_ERRNO, "%s: input format METEOR_PIXTYPE_YUV_PACKED %i", i); format = i; } @@ -617,44 +615,44 @@ static unsigned char *v4l_start(struct video_dev *viddev, int width, int height, void *map; - /* if we have choose the tuner is needed to setup the frequency */ + /* If we have choose the tuner is needed to setup the frequency. */ if ((viddev->tuner_device != NULL) && (input == IN_TV)) { if (!freq) { - motion_log(ERR, TYPE_VIDEO, NO_ERRNO, "%s: Not valid Frequency [%lu] for " - "Source input [%i]", __FUNCTION__, freq, input); + MOTION_LOG(ERR, TYPE_VIDEO, NO_ERRNO, "%s: Not valid Frequency [%lu] for " + "Source input [%i]", freq, input); return NULL; } else if (set_freq(viddev, freq) == -1) { - motion_log(ERR, TYPE_VIDEO, NO_ERRNO, "%s: Frequency [%lu] Source input [%i]", - __FUNCTION__, freq, input); + MOTION_LOG(ERR, TYPE_VIDEO, NO_ERRNO, "%s: Frequency [%lu] Source input [%i]", + freq, input); return NULL; } } /* FIXME if we set as input tuner , we need to set option for tuner not for bktr */ if ((dummy = set_input(viddev, input)) == -1) { - motion_log(ERR, TYPE_VIDEO, NO_ERRNO, "%s: set input [%d]", __FUNCTION__, input); + MOTION_LOG(ERR, TYPE_VIDEO, NO_ERRNO, "%s: set input [%d]", input); return NULL; } viddev->input = dummy; if ((dummy = set_input_format(viddev, norm)) == -1) { - motion_log(ERR, TYPE_VIDEO, NO_ERRNO, "%s: set input format [%d]", - __FUNCTION__, norm); + MOTION_LOG(ERR, TYPE_VIDEO, NO_ERRNO, "%s: set input format [%d]", + norm); return NULL; } viddev->norm = dummy; if (set_geometry(viddev, width, height) == -1) { - motion_log(ERR, TYPE_VIDEO, NO_ERRNO, "%s: set geometry [%d]x[%d]", - __FUNCTION__, width, height); + MOTION_LOG(ERR, TYPE_VIDEO, NO_ERRNO, "%s: set geometry [%d]x[%d]", + width, height); return NULL; } /* if (ioctl(dev_bktr, METEORSACTPIXFMT, &pixelformat) < 0) { - motion_log(ERR, TYPE_VIDEO, SHOW_ERRNO, "set encoding method BSD_VIDFMT_I420"); + MOTION_LOG(ERR, TYPE_VIDEO, SHOW_ERRNO, "%s: set encoding method BSD_VIDFMT_I420"); return NULL; } @@ -665,8 +663,7 @@ static unsigned char *v4l_start(struct video_dev *viddev, int width, int height, */ if (freq) { - motion_log(DBG, TYPE_VIDEO, NO_ERRNO, "%s: Frequency set (no implemented yet", - __FUNCTION__); + MOTION_LOG(WRN, TYPE_VIDEO, NO_ERRNO, "%s: Frequency set (no implemented yet"); /* TODO missing implementation set_channelset(viddev); @@ -690,7 +687,7 @@ static unsigned char *v4l_start(struct video_dev *viddev, int width, int height, dev_bktr, (off_t)0); if (map == MAP_FAILED) { - motion_log(ERR, TYPE_VIDEO, SHOW_ERRNO, "%s: mmap failed", __FUNCTION__); + MOTION_LOG(ALR, TYPE_VIDEO, SHOW_ERRNO, "%s: mmap failed"); return NULL; } @@ -709,11 +706,11 @@ static unsigned char *v4l_start(struct video_dev *viddev, int width, int height, /* Clear the buffer */ if (ioctl(dev_bktr, BT848SCBUF, &dummy) < 0) { - motion_log(ERR, TYPE_VIDEO, SHOW_ERRNO, "%s: BT848SCBUF", __FUNCTION__); + MOTION_LOG(ERR, TYPE_VIDEO, SHOW_ERRNO, "%s: BT848SCBUF"); return NULL; } - /* signal handler to know when data is ready to be read() */ + /* Signal handler to know when data is ready to be read() */ memset(&act, 0, sizeof(act)); sigemptyset(&act.sa_mask); act.sa_handler = catchsignal; @@ -726,37 +723,34 @@ static unsigned char *v4l_start(struct video_dev *viddev, int width, int height, if ((viddev->capture_method == METEOR_CAP_CONTINOUS) && (ioctl(dev_bktr, METEORSSIGNAL, &dummy) < 0)) { - motion_log(ERR, TYPE_VIDEO, SHOW_ERRNO, "%s: METEORSSIGNAL", __FUNCTION__); - motion_log(ERR, TYPE_VIDEO, TYPE_VIDEO, NO_ERRNO, "%s: METEORSSIGNAL", - __FUNCTION__); + MOTION_LOG(ERR, TYPE_VIDEO, SHOW_ERRNO, "%s: METEORSSIGNAL"); + MOTION_LOG(ERR, TYPE_VIDEO, TYPE_VIDEO, NO_ERRNO, "%s: METEORSSIGNAL"); viddev->capture_method = METEOR_CAP_SINGLE; if (ioctl(dev_bktr, METEORCAPTUR, &viddev->capture_method) < 0) { - motion_log(ERR, TYPE_VIDEO, SHOW_ERRNO, "%s: METEORCAPTUR using single method " - "Error capturing", __FUNCTION__); - motion_log(ERR, TYPE_VIDEO, NO_ERRNO, "%s: METEORCAPTUR using single method " - "Error capturing", __FUNCTION__); + MOTION_LOG(ERR, TYPE_VIDEO, SHOW_ERRNO, "%s: METEORCAPTUR using single method " + "Error capturing"); + MOTION_LOG(ERR, TYPE_VIDEO, NO_ERRNO, "%s: METEORCAPTUR using single method " + "Error capturing"); } } else { if (ioctl(dev_bktr, METEORCAPTUR, &viddev->capture_method) < 0) { viddev->capture_method = METEOR_CAP_SINGLE; if (ioctl(dev_bktr, METEORCAPTUR, &viddev->capture_method) < 0) { - motion_log(ERR, TYPE_VIDEO, SHOW_ERRNO, "%s: METEORCAPTUR using single method " - "Error capturing", __FUNCTION__); - motion_log(ERR, TYPE_VIDEO, NO_ERRNO, "%s: METEORCAPTUR using single method " - "Error capturing", __FUNCTION__); + MOTION_LOG(ERR, TYPE_VIDEO, SHOW_ERRNO, "%s: METEORCAPTUR using single method " + "Error capturing"); + MOTION_LOG(ERR, TYPE_VIDEO, NO_ERRNO, "%s: METEORCAPTUR using single method " + "Error capturing"); } } } if (viddev->capture_method == METEOR_CAP_CONTINOUS) - motion_log(ERR, TYPE_VIDEO, NO_ERRNO, "%s: METEORCAPTUR METEOR_CAP_CONTINOUS", - __FUNCTION__); + MOTION_LOG(ERR, TYPE_VIDEO, NO_ERRNO, "%s: METEORCAPTUR METEOR_CAP_CONTINOUS"); else - motion_log(ERR, TYPE_VIDEO, NO_ERRNO, "%s: METEORCAPTUR METEOR_CAP_SINGLE", - __FUNCTION__); + MOTION_LOG(ERR, TYPE_VIDEO, NO_ERRNO, "%s: METEORCAPTUR METEOR_CAP_SINGLE"); // settle , sleep(1) replaced SLEEP(1, 0); @@ -777,13 +771,13 @@ static unsigned char *v4l_start(struct video_dev *viddev, int width, int height, break; } - motion_log(ERR, TYPE_VIDEO, NO_ERRNO, "HUE [%d]", + MOTION_LOG(ERR, TYPE_VIDEO, NO_ERRNO, "HUE [%d]", get_hue(dev_bktr, &dummy)); - motion_log(ERR, TYPE_VIDEO, NO_ERRNO, "SATURATION [%d]", + MOTION_LOG(ERR, TYPE_VIDEO, NO_ERRNO, "SATURATION [%d]", get_saturation(dev_bktr, &dummy)); - motion_log(ERR, TYPE_VIDEO, NO_ERRNO, "BRIGHTNESS [%d]", + MOTION_LOG(ERR, TYPE_VIDEO, NO_ERRNO, "BRIGHTNESS [%d]", get_brightness(dev_bktr, &dummy)); - motion_log(ERR, TYPE_VIDEO, NO_ERRNO, "CONTRAST [%d]", + MOTION_LOG(ERR, TYPE_VIDEO, NO_ERRNO, "CONTRAST [%d]", get_contrast(dev_bktr, &dummy)); return map; @@ -830,15 +824,14 @@ static int v4l_next(struct video_dev *viddev, unsigned char *map, int width, int if (viddev->v4l_curbuffer >= viddev->v4l_maxbuffer) viddev->v4l_curbuffer = 0; - /* capture */ + /* Capture */ if (viddev->capture_method == METEOR_CAP_CONTINOUS) { if (bktr_frame_waiting) bktr_frame_waiting = 0; } else if (ioctl(dev_bktr, METEORCAPTUR, &single) < 0) { - motion_log(ERR, TYPE_VIDEO, SHOW_ERRNO, "%s: Error capturing using single method", - __FUNCTION__); + MOTION_LOG(ERR, TYPE_VIDEO, SHOW_ERRNO, "%s: Error capturing using single method"); sigprocmask(SIG_UNBLOCK, &old, NULL); return -1; } @@ -863,7 +856,7 @@ static int v4l_next(struct video_dev *viddev, unsigned char *map, int width, int /** * v4l_set_input - * Sets input & freq if needed FIXME not allowed use Tuner yet + * Sets input & freq if needed FIXME not allowed use Tuner yet. */ static void v4l_set_input(struct context *cnt, struct video_dev *viddev, unsigned char *map, int width, int height, unsigned input, unsigned norm, int skip, unsigned long freq) @@ -892,7 +885,7 @@ static void v4l_set_input(struct context *cnt, struct video_dev *viddev, unsigne // FIXME /* if (setup_pixelformat(viddev) == -1) { - motion_log(ERR, TYPE_VIDEO, SHOW_ERRNO, "ioctl (VIDIOCSFREQ)"); + MOTION_LOG(ERR, TYPE_VIDEO, SHOW_ERRNO, "%s: ioctl (VIDIOCSFREQ)"); return } @@ -927,12 +920,14 @@ vid_cleanup - Destroy vid_mutex. */ -/* big lock for vid_start to ensure exclusive access to viddevs while adding - * devices during initialization of each thread +/* + * Big lock for vid_start to ensure exclusive access to viddevs while adding + * devices during initialization of each thread. */ static pthread_mutex_t vid_mutex; -/* Here we setup the viddevs structure which is used globally in the vid_* +/* + * Here we setup the viddevs structure which is used globally in the vid_* * functions. */ static struct video_dev *viddevs = NULL; @@ -941,7 +936,7 @@ static struct video_dev *viddevs = NULL; * vid_init * * Called from motion.c at the very beginning before setting up the threads. - * Function prepares the vid_mutex + * Function prepares the vid_mutex. */ void vid_init(void) { @@ -951,7 +946,7 @@ void vid_init(void) /** * vid_cleanup * - * vid_cleanup is called from motion.c when Motion is stopped or restarted + * vid_cleanup is called from motion.c when Motion is stopped or restarted. */ void vid_cleanup(void) { @@ -963,7 +958,7 @@ void vid_cleanup(void) /** * vid_close * - * vid_close is called from motion.c when a Motion thread is stopped or restarted + * vid_close is called from motion.c when a Motion thread is stopped or restarted. */ void vid_close(struct context *cnt) { @@ -993,18 +988,17 @@ void vid_close(struct context *cnt) pthread_mutex_unlock(&vid_mutex); - /* Set it as closed in thread context */ + /* Set it as closed in thread context. */ cnt->video_dev = -1; if (dev == NULL) { - motion_log(ERR, TYPE_VIDEO, NO_ERRNO, "%s: Unable to find video device", - __FUNCTION__); + MOTION_LOG(ALR, TYPE_VIDEO, NO_ERRNO, "%s: Unable to find video device"); return; } if (--dev->usage_count == 0) { - motion_log(ERR, TYPE_VIDEO, NO_ERRNO, "%s: Closing video device %s", - __FUNCTION__, dev->video_device); + MOTION_LOG(CRT, TYPE_VIDEO, NO_ERRNO, "%s: Closing video device %s", + dev->video_device); if (dev->fd_tuner > 0) close(dev->fd_tuner); @@ -1037,8 +1031,8 @@ void vid_close(struct context *cnt) pthread_mutex_destroy(&dev->mutex); free(dev); } else { - motion_log(ERR, TYPE_VIDEO, NO_ERRNO, "%s: Still %d users of video device %s, " - "so we don't close it now", __FUNCTION__, dev->usage_count, + MOTION_LOG(CRT, TYPE_VIDEO, NO_ERRNO, "%s: Still %d users of video device %s, " + "so we don't close it now", dev->usage_count, dev->video_device); /* * There is still at least one thread using this device @@ -1072,8 +1066,7 @@ int vid_start(struct context *cnt) } #ifdef WITHOUT_V4L else - motion_log(ERR, TYPE_VIDEO, NO_ERRNO, "%s: You must setup netcam_url", - __FUNCTION__); + MOTION_LOG(EMG, TYPE_VIDEO, NO_ERRNO, "%s: You must setup netcam_url"); #else else { struct video_dev *dev; @@ -1083,26 +1076,26 @@ int vid_start(struct context *cnt) unsigned long frequency; - motion_log(EMG, TYPE_VIDEO, NO_ERRNO, "%s: [%s]", - __FUNCTION__, conf->video_device); + MOTION_LOG(EMG, TYPE_VIDEO, NO_ERRNO, "%s: [%s]", + conf->video_device); /* * We use width and height from conf in this function. They will be assigned * to width and height in imgs here, and cap_width and cap_height in * rotate_data won't be set until in rotate_init. - * Motion requires that width and height are multiples of 16 so we check for this + * Motion requires that width and height are multiples of 16 so we check for this. */ if (conf->width % 16) { - motion_log(ERR, TYPE_VIDEO, NO_ERRNO, + MOTION_LOG(CRT, TYPE_VIDEO, NO_ERRNO, "%s: config image width (%d) is not modulo 16", - __FUNCTION__, conf->width); + conf->width); return -1; } if (conf->height % 16) { - motion_log(ERR, TYPE_VIDEO, NO_ERRNO, + MOTION_LOG(CRT, TYPE_VIDEO, NO_ERRNO, "%s: config image height (%d) is not modulo 16", - __FUNCTION__, conf->height); + conf->height); return -1; } @@ -1137,13 +1130,12 @@ int vid_start(struct context *cnt) cnt->imgs.type = dev->v4l_fmt; if (ioctl(dev->fd_bktr, METEORCAPTUR, &dummy) < 0) { - motion_log(ERR, TYPE_VIDEO, SHOW_ERRNO, "%s Stopping capture", - __FUNCTION__); + MOTION_LOG(ALR, TYPE_VIDEO, SHOW_ERRNO, "%s Stopping capture"); return -1; } - motion_log(EMG, TYPE_VIDEO, NO_ERRNO, "%s Reusing [%s] inputs [%d,%d] Change " - "capture method METEOR_CAP_SINGLE", __FUNCTION__, dev->video_device, + MOTION_LOG(EMG, TYPE_VIDEO, NO_ERRNO, "%s Reusing [%s] inputs [%d,%d] Change " + "capture method METEOR_CAP_SINGLE", dev->video_device, dev->input, conf->input); dev->capture_method = METEOR_CAP_SINGLE; @@ -1157,8 +1149,8 @@ int vid_start(struct context *cnt) case VIDEO_PALETTE_YUV422: cnt->imgs.type = VIDEO_PALETTE_YUV420P; case VIDEO_PALETTE_YUV420P: - motion_log(EMG, TYPE_VIDEO, NO_ERRNO, "%s VIDEO_PALETTE_YUV420P setting" - " imgs.size and imgs.motionsize", __FUNCTION__); + MOTION_LOG(EMG, TYPE_VIDEO, NO_ERRNO, "%s VIDEO_PALETTE_YUV420P setting" + " imgs.size and imgs.motionsize"); cnt->imgs.motionsize = width * height; cnt->imgs.size = (width * height * 3) / 2; break; @@ -1177,20 +1169,20 @@ int vid_start(struct context *cnt) fd_bktr = open(conf->video_device, O_RDWR); if (fd_bktr < 0) { - motion_log(ERR, TYPE_VIDEO, SHOW_ERRNO, "%s: open video device %s", - __FUNCTION__, conf->video_device); + MOTION_LOG(ALR, TYPE_VIDEO, SHOW_ERRNO, "%s: open video device %s", + conf->video_device); free(dev); pthread_mutex_unlock(&vid_mutex); return -1; } - /* Only open tuner if conf->tuner_device has set , freq and input is 1 */ + /* Only open tuner if conf->tuner_device has set , freq and input is 1. */ if ((conf->tuner_device != NULL) && (frequency > 0) && (input == IN_TV)) { fd_tuner = open(conf->tuner_device, O_RDWR); if (fd_tuner < 0) { - motion_log(ERR, TYPE_VIDEO, SHOW_ERRNO, "%s: open tuner device %s", - __FUNCTION__, conf->tuner_device); + MOTION_LOG(ALR, TYPE_VIDEO, SHOW_ERRNO, "%s: open tuner device %s", + conf->tuner_device); free(dev); pthread_mutex_unlock(&vid_mutex); return -1; @@ -1223,7 +1215,7 @@ int vid_start(struct context *cnt) dev->hue = 0; dev->owner = -1; - /* default palette */ + /* Default palette */ dev->v4l_fmt = VIDEO_PALETTE_YUV420P; dev->v4l_curbuffer = 0; dev->v4l_maxbuffer = 1; @@ -1249,8 +1241,7 @@ int vid_start(struct context *cnt) case VIDEO_PALETTE_YUV422: cnt->imgs.type = VIDEO_PALETTE_YUV420P; case VIDEO_PALETTE_YUV420P: - motion_log(EMG, TYPE_VIDEO, NO_ERRNO, "%s: VIDEO_PALETTE_YUV420P imgs.type", - __FUNCTION__); + MOTION_LOG(EMG, TYPE_VIDEO, NO_ERRNO, "%s: VIDEO_PALETTE_YUV420P imgs.type"); cnt->imgs.size = (width * height * 3) / 2; cnt->imgs.motionsize = width * height; break; @@ -1318,7 +1309,6 @@ int vid_next(struct context *cnt, unsigned char *map) if (dev == NULL) return V4L_FATAL_ERROR; - //return -1; if (dev->owner != cnt->threadnr) { pthread_mutex_lock(&dev->mutex); @@ -1338,7 +1328,7 @@ int vid_next(struct context *cnt, unsigned char *map) pthread_mutex_unlock(&dev->mutex); } - /* rotate the image as specified */ + /* Rotate the image as specified */ if (cnt->rotate_data.degrees > 0) rotate_map(cnt, map); diff --git a/vloopback_motion.c b/vloopback_motion.c index ee4c877..d014017 100644 --- a/vloopback_motion.c +++ b/vloopback_motion.c @@ -27,8 +27,7 @@ static int v4l_open_vidpipe(void) struct utsname uts; if (uname(&uts) < 0) { - motion_log(ERR, TYPE_VIDEO, SHOW_ERRNO, "%s: Unable to execute uname", - __FUNCTION__); + MOTION_LOG(ALR, TYPE_VIDEO, SHOW_ERRNO, "%s: Unable to execute uname"); return -1; } @@ -36,8 +35,7 @@ static int v4l_open_vidpipe(void) minor = strtok(NULL, "."); if ((major == NULL) || (minor == NULL) || (strcmp(major, "2"))) { - motion_log(ERR, TYPE_VIDEO, SHOW_ERRNO, "%s: Unable to decipher OS version", - __FUNCTION__); + MOTION_LOG(EMG, TYPE_VIDEO, SHOW_ERRNO, "%s: Unable to decipher OS version"); return -1; } @@ -52,15 +50,14 @@ static int v4l_open_vidpipe(void) vloopbacks = fopen("/proc/video/vloopback/vloopbacks", "r"); if (!vloopbacks) { - motion_log(ERR, TYPE_VIDEO, SHOW_ERRNO, "%s: Failed to open " - "'/proc/video/vloopback/vloopbacks'", __FUNCTION__); + MOTION_LOG(EMG, TYPE_VIDEO, SHOW_ERRNO, "%s: Failed to open " + "'/proc/video/vloopback/vloopbacks'"); return -1; } /* Read vloopback version*/ if (!fgets(buffer, sizeof(buffer), vloopbacks)) { - motion_log(ERR, TYPE_VIDEO, SHOW_ERRNO, "%s: Unable to read vloopback version", - __FUNCTION__); + MOTION_LOG(EMG, TYPE_VIDEO, SHOW_ERRNO, "%s: Unable to read vloopback version"); return -1; } @@ -69,8 +66,8 @@ static int v4l_open_vidpipe(void) /* Read explanation line */ if (!fgets(buffer, sizeof(buffer), vloopbacks)) { - motion_log(ERR, TYPE_VIDEO, SHOW_ERRNO, "%s: Unable to read vloopback" - " explanation line", __FUNCTION__); + MOTION_LOG(EMG, TYPE_VIDEO, SHOW_ERRNO, "%s: Unable to read vloopback" + " explanation line"); return -1; } @@ -88,8 +85,8 @@ static int v4l_open_vidpipe(void) pipe_fd = open(pipepath, O_RDWR); if (pipe_fd >= 0) { - motion_log(EMG, TYPE_VIDEO, NO_ERRNO, "%s: \tInput: /dev/%s " - "\tOutput: /dev/%s", __FUNCTION__, input, output); + MOTION_LOG(ALR, TYPE_VIDEO, NO_ERRNO, "%s: \tInput: /dev/%s " + "\tOutput: /dev/%s", input, output); break; } } @@ -108,8 +105,8 @@ static int v4l_open_vidpipe(void) int tnum; if ((dir = opendir(prefix)) == NULL) { - motion_log(ERR, TYPE_VIDEO, SHOW_ERRNO, "%s: Failed to open '%s'", - __FUNCTION__, prefix); + MOTION_LOG(EMG, TYPE_VIDEO, SHOW_ERRNO, "%s: Failed to open '%s'", + prefix); return -1; } @@ -169,8 +166,8 @@ static int v4l_open_vidpipe(void) closedir(dir); if (pipe_fd >= 0) - motion_log(EMG, TYPE_VIDEO, NO_ERRNO, "%s: Opened %s as input", - __FUNCTION__, pipepath); + MOTION_LOG(ALR, TYPE_VIDEO, NO_ERRNO, "%s: Opened %s as input", + pipepath); } return pipe_fd; @@ -190,33 +187,30 @@ static int v4l_startpipe(const char *dev_name, int width, int height, int type) dev = v4l_open_vidpipe(); } else { dev = open(dev_name, O_RDWR); - motion_log(EMG, TYPE_VIDEO, NO_ERRNO, "%s: Opened %s as input", - __FUNCTION__, dev_name); + MOTION_LOG(ALR, TYPE_VIDEO, NO_ERRNO, "%s: Opened %s as input", + dev_name); } if (dev < 0) { - motion_log(ERR, TYPE_VIDEO, SHOW_ERRNO, "%s: Opening %s as input failed", - __FUNCTION__, dev_name); + MOTION_LOG(EMG, TYPE_VIDEO, SHOW_ERRNO, "%s: Opening %s as input failed", + dev_name); return -1; } if (ioctl(dev, VIDIOCGPICT, &vid_pic) == -1) { - motion_log(ERR, TYPE_VIDEO, SHOW_ERRNO, "%s: ioctl (VIDIOCGPICT)", - __FUNCTION__); + MOTION_LOG(EMG, TYPE_VIDEO, SHOW_ERRNO, "%s: ioctl (VIDIOCGPICT)"); return -1; } vid_pic.palette = type; if (ioctl(dev, VIDIOCSPICT, &vid_pic) == -1) { - motion_log(ERR, TYPE_VIDEO, SHOW_ERRNO, "%s: ioctl (VIDIOCSPICT)", - __FUNCTION__); + MOTION_LOG(EMG, TYPE_VIDEO, SHOW_ERRNO, "%s: ioctl (VIDIOCSPICT)"); return -1; } if (ioctl(dev, VIDIOCGWIN, &vid_win) == -1) { - motion_log(ERR, TYPE_VIDEO, SHOW_ERRNO, "%s: ioctl (VIDIOCGWIN)", - __FUNCTION__); + MOTION_LOG(EMG, TYPE_VIDEO, SHOW_ERRNO, "%s: ioctl (VIDIOCGWIN)"); return -1; } @@ -224,8 +218,7 @@ static int v4l_startpipe(const char *dev_name, int width, int height, int type) vid_win.width = width; if (ioctl(dev, VIDIOCSWIN, &vid_win) == -1) { - motion_log(ERR, TYPE_VIDEO, SHOW_ERRNO, "%s: ioctl (VIDIOCSWIN)", - __FUNCTION__); + MOTION_LOG(EMG, TYPE_VIDEO, SHOW_ERRNO, "%s: ioctl (VIDIOCSWIN)"); return -1; } diff --git a/webhttpd.c b/webhttpd.c index aa9af29..d5de4aa 100644 --- a/webhttpd.c +++ b/webhttpd.c @@ -249,8 +249,7 @@ static void send_template_ini_client(int client_socket, const char *template) nwrite = write_nonblock(client_socket, ok_response, strlen(ok_response)); nwrite += write_nonblock(client_socket, template, strlen(template)); if (nwrite != (ssize_t)(strlen(ok_response) + strlen(template))) - motion_log(ALR, TYPE_STREAM, SHOW_ERRNO, "%s: failure write", - __FUNCTION__); + MOTION_LOG(ALR, TYPE_STREAM, SHOW_ERRNO, "%s: failure write"); } /** @@ -261,8 +260,7 @@ static void send_template_ini_client_raw(int client_socket) ssize_t nwrite = 0; nwrite = write_nonblock(client_socket, ok_response_raw, strlen(ok_response_raw)); if (nwrite != (ssize_t)strlen(ok_response_raw)) - motion_log(ALR, TYPE_STREAM, SHOW_ERRNO, "%s: failure write", - __FUNCTION__); + MOTION_LOG(ALR, TYPE_STREAM, SHOW_ERRNO, "%s: failure write"); } /** @@ -273,8 +271,7 @@ static void send_template(int client_socket, char *res) ssize_t nwrite = 0; nwrite = write_nonblock(client_socket, res, strlen(res)); if (nwrite != (ssize_t)strlen(res)) - motion_log(ALR, TYPE_STREAM, SHOW_ERRNO, "%s: failure write", - __FUNCTION__); + MOTION_LOG(ALR, TYPE_STREAM, SHOW_ERRNO, "%s: failure write"); } /** @@ -1005,8 +1002,7 @@ static unsigned int action(char *pointer, char *res, unsigned int length_uri, /* call restart */ if (thread == 0) { - motion_log(ERR, TYPE_STREAM, NO_ERRNO, "%s: httpd restart", - __FUNCTION__); + MOTION_LOG(ERR, TYPE_STREAM, NO_ERRNO, "%s: httpd restart"); kill(getpid(),SIGHUP); if (cnt[0]->conf.webcontrol_html_output) { send_template_ini_client(client_socket, ini_template); @@ -1020,8 +1016,8 @@ static unsigned int action(char *pointer, char *res, unsigned int length_uri, } return 0; // to restart } else { - motion_log(ERR, TYPE_STREAM, NO_ERRNO, "%s: httpd restart thread %d", - __FUNCTION__, thread); + MOTION_LOG(ERR, TYPE_STREAM, NO_ERRNO, "%s: httpd restart thread %d", + thread); if (cnt[thread]->running) { cnt[thread]->makemovie = 1; cnt[thread]->finish = 1; @@ -1052,8 +1048,7 @@ static unsigned int action(char *pointer, char *res, unsigned int length_uri, /* call quit */ if (thread == 0) { - motion_log(ERR, TYPE_STREAM, NO_ERRNO, "%s: httpd quit", - __FUNCTION__); + MOTION_LOG(ERR, TYPE_STREAM, NO_ERRNO, "%s: httpd quit"); kill(getpid(),SIGQUIT); if (cnt[0]->conf.webcontrol_html_output) { send_template_ini_client(client_socket, ini_template); @@ -1067,8 +1062,8 @@ static unsigned int action(char *pointer, char *res, unsigned int length_uri, } return 0; // to quit } else { - motion_log(ERR, TYPE_STREAM, NO_ERRNO, "%s: httpd quit thread %d", - __FUNCTION__, thread); + MOTION_LOG(ERR, TYPE_STREAM, NO_ERRNO, "%s: httpd quit thread %d", + thread); cnt[thread]->restart = 0; cnt[thread]->makemovie = 1; cnt[thread]->finish = 1; @@ -1309,8 +1304,7 @@ static unsigned int track(char *pointer, char *res, unsigned int length_uri, if ((question != '=') || (command[0] == '\0')) { /* no valid syntax */ - motion_log(INF, TYPE_STREAM, NO_ERRNO, "%s: httpd debug race 1", - __FUNCTION__); + MOTION_LOG(INF, TYPE_STREAM, NO_ERRNO, "%s: httpd debug race 1"); if (cnt[0]->conf.webcontrol_html_output) response_client(client_socket, not_valid_syntax, NULL); else @@ -1360,8 +1354,7 @@ static unsigned int track(char *pointer, char *res, unsigned int length_uri, } } else { /* no valid syntax */ - motion_log(INF, TYPE_STREAM, NO_ERRNO, "%s: httpd debug race 2", - __FUNCTION__); + MOTION_LOG(INF, TYPE_STREAM, NO_ERRNO, "%s: httpd debug race 2"); if (cnt[0]->conf.webcontrol_html_output) response_client(client_socket, not_valid_syntax, NULL); else @@ -1372,8 +1365,7 @@ static unsigned int track(char *pointer, char *res, unsigned int length_uri, /* first value check for error */ if (!warningkill) { - motion_log(INF, TYPE_STREAM, NO_ERRNO, "%s: httpd debug race 3", - __FUNCTION__); + MOTION_LOG(INF, TYPE_STREAM, NO_ERRNO, "%s: httpd debug race 3"); /* error value */ if (cnt[0]->conf.webcontrol_html_output) response_client(client_socket, error_value, NULL); @@ -1525,8 +1517,7 @@ static unsigned int track(char *pointer, char *res, unsigned int length_uri, warningkill = sscanf(pointer, "%c%255[a-z]" , &question, command); if ((question != '&') || (command[0] == '\0')) { - motion_log(INF, TYPE_STREAM, NO_ERRNO, "%s: httpd debug race 4", - __FUNCTION__); + MOTION_LOG(INF, TYPE_STREAM, NO_ERRNO, "%s: httpd debug race 4"); if (strstr(pointer, "&")) { if (cnt[0]->conf.webcontrol_html_output) response_client(client_socket, error_value, NULL); @@ -1550,8 +1541,7 @@ static unsigned int track(char *pointer, char *res, unsigned int length_uri, pointer = pointer + 3; length_uri = length_uri - 3; if (pan || !tilt || X || Y) { - motion_log(INF, TYPE_STREAM, NO_ERRNO, "%s: httpd debug race 5", - __FUNCTION__); + MOTION_LOG(INF, TYPE_STREAM, NO_ERRNO, "%s: httpd debug race 5"); /* no valid syntax */ if (cnt[0]->conf.webcontrol_html_output) response_client(client_socket, not_valid_syntax, NULL); @@ -1567,8 +1557,7 @@ static unsigned int track(char *pointer, char *res, unsigned int length_uri, length_uri = length_uri - 4; if (tilt || !pan || X || Y) { /* no valid syntax */ - motion_log(INF, TYPE_STREAM, NO_ERRNO, "%s: httpd debug race 6", - __FUNCTION__); + MOTION_LOG(INF, TYPE_STREAM, NO_ERRNO, "%s: httpd debug race 6"); if (cnt[0]->conf.webcontrol_html_output) response_client(client_socket, not_valid_syntax, NULL); else @@ -1582,8 +1571,7 @@ static unsigned int track(char *pointer, char *res, unsigned int length_uri, pointer++; length_uri--; if (X || !Y || pan || tilt) { - motion_log(INF, TYPE_STREAM, NO_ERRNO, "%s: httpd debug race 7", - __FUNCTION__); + MOTION_LOG(INF, TYPE_STREAM, NO_ERRNO, "%s: httpd debug race 7"); /* no valid syntax */ if (cnt[0]->conf.webcontrol_html_output) @@ -1599,8 +1587,7 @@ static unsigned int track(char *pointer, char *res, unsigned int length_uri, pointer++; length_uri--; if (Y || !X || pan || tilt) { - motion_log(INF, TYPE_STREAM, NO_ERRNO, "%s: httpd debug race 8", - __FUNCTION__); + MOTION_LOG(INF, TYPE_STREAM, NO_ERRNO, "%s: httpd debug race 8"); /* no valid syntax */ if (cnt[0]->conf.webcontrol_html_output) response_client(client_socket, not_valid_syntax, NULL); @@ -1612,8 +1599,7 @@ static unsigned int track(char *pointer, char *res, unsigned int length_uri, warningkill = sscanf(pointer, "%c%10[-0-9]" , &question, y_value); } else { - motion_log(INF, TYPE_STREAM, NO_ERRNO, "%s: httpd debug race 9", - __FUNCTION__); + MOTION_LOG(INF, TYPE_STREAM, NO_ERRNO, "%s: httpd debug race 9"); /* no valid syntax */ if (cnt[0]->conf.webcontrol_html_output) response_client(client_socket, not_valid_syntax, NULL); @@ -1625,8 +1611,7 @@ static unsigned int track(char *pointer, char *res, unsigned int length_uri, /* Second value check */ if ((warningkill < 2) && (question != '=')) { - motion_log(INF, TYPE_STREAM, NO_ERRNO, "%s: httpd debug race 10", - __FUNCTION__); + MOTION_LOG(INF, TYPE_STREAM, NO_ERRNO, "%s: httpd debug race 10"); /* no valid syntax */ if (cnt[0]->conf.webcontrol_html_output) response_client(client_socket, not_valid_syntax, NULL); @@ -1634,8 +1619,7 @@ static unsigned int track(char *pointer, char *res, unsigned int length_uri, response_client(client_socket, not_valid_syntax_raw, NULL); return 1; } else if ((question == '=') && (warningkill == 1)) { - motion_log(INF, TYPE_STREAM, NO_ERRNO, "%s: httpd debug race 11", - __FUNCTION__); + MOTION_LOG(INF, TYPE_STREAM, NO_ERRNO, "%s: httpd debug race 11"); if (cnt[0]->conf.webcontrol_html_output) response_client(client_socket, error_value, NULL); else @@ -1660,8 +1644,7 @@ static unsigned int track(char *pointer, char *res, unsigned int length_uri, if (length_uri != 0) { - motion_log(INF, TYPE_STREAM, NO_ERRNO, "%s: httpd debug race 12", - __FUNCTION__); + MOTION_LOG(INF, TYPE_STREAM, NO_ERRNO, "%s: httpd debug race 12"); if (cnt[0]->conf.webcontrol_html_output) response_client(client_socket, error_value, NULL); else @@ -2238,8 +2221,7 @@ static unsigned int read_client(int client_socket, void *userdata, char *auth) nread = read_nonblock(client_socket, buffer, length); if (nread <= 0) { - motion_log(ERR, TYPE_STREAM, SHOW_ERRNO, "%s: motion-httpd First Read Error", - __FUNCTION__); + MOTION_LOG(ERR, TYPE_STREAM, SHOW_ERRNO, "%s: motion-httpd First Read Error"); pthread_mutex_unlock(&httpd_mutex); return 1; } else { @@ -2274,8 +2256,8 @@ static unsigned int read_client(int client_socket, void *userdata, char *auth) nread += readb; if (nread > length) { - motion_log(ERR, TYPE_STREAM, SHOW_ERRNO, "%s: motion-httpd End buffer" - " reached waiting for buffer ending", __FUNCTION__); + MOTION_LOG(ERR, TYPE_STREAM, SHOW_ERRNO, "%s: motion-httpd End buffer" + " reached waiting for buffer ending"); break; } buffer[nread] = '\0'; @@ -2286,8 +2268,7 @@ static unsigned int read_client(int client_socket, void *userdata, char *auth) * problem with the connection, so give up. */ if (nread == -1) { - motion_log(ERR, TYPE_STREAM, SHOW_ERRNO, "%s: motion-httpd READ give up!", - __FUNCTION__); + MOTION_LOG(ERR, TYPE_STREAM, SHOW_ERRNO, "%s: motion-httpd READ give up!"); pthread_mutex_unlock(&httpd_mutex); return 1; } @@ -2442,8 +2423,8 @@ void httpd_run(struct context **cnt) /* check != 0 to allow FreeBSD compatibility */ if (val != 0) { - motion_log(ERR, TYPE_STREAM, SHOW_ERRNO, "%s: getaddrinfo() for httpd socket failed: %s", - __FUNCTION__, gai_strerror(val)); + MOTION_LOG(EMG, TYPE_STREAM, SHOW_ERRNO, "%s: getaddrinfo() for httpd socket failed: %s", + gai_strerror(val)); if (res) freeaddrinfo(res); pthread_mutex_destroy(&httpd_mutex); @@ -2459,8 +2440,8 @@ void httpd_run(struct context **cnt) getnameinfo(res->ai_addr, res->ai_addrlen, hbuf, sizeof(hbuf), sbuf, sizeof(sbuf), NI_NUMERICHOST | NI_NUMERICSERV); - motion_log(ERR, TYPE_STREAM, NO_ERRNO, "%s: motion-httpd testing : %s addr: %s port: %s", - __FUNCTION__, res->ai_family == AF_INET ? "IPV4":"IPV6", hbuf, sbuf); + MOTION_LOG(ALR, TYPE_STREAM, NO_ERRNO, "%s: motion-httpd testing : %s addr: %s port: %s", + res->ai_family == AF_INET ? "IPV4":"IPV6", hbuf, sbuf); if (sd >= 0) { val = 1; @@ -2468,43 +2449,43 @@ void httpd_run(struct context **cnt) setsockopt(sd, SOL_SOCKET, SO_REUSEADDR, &val, sizeof(int)); if (bind(sd, res->ai_addr, res->ai_addrlen) == 0) { - motion_log(ERR, TYPE_STREAM, NO_ERRNO, "%s: motion-httpd Bound : %s addr: %s" - " port: %s", __FUNCTION__, res->ai_family == AF_INET ? "IPV4":"IPV6", + MOTION_LOG(ALR, TYPE_STREAM, NO_ERRNO, "%s: motion-httpd Bound : %s addr: %s" + " port: %s", res->ai_family == AF_INET ? "IPV4":"IPV6", hbuf, sbuf); break; } - motion_log(ERR, TYPE_STREAM, SHOW_ERRNO, "%s: motion-httpd failed bind() interface %s" - " / port %s, retrying", __FUNCTION__, hbuf, sbuf); + MOTION_LOG(ALR, TYPE_STREAM, SHOW_ERRNO, "%s: motion-httpd failed bind() interface %s" + " / port %s, retrying", hbuf, sbuf); close(sd); sd = -1; } - motion_log(ERR, TYPE_STREAM, SHOW_ERRNO, "%s: motion-httpd socket failed interface %s" - " / port %s, retrying", __FUNCTION__, hbuf, sbuf); + MOTION_LOG(ALR, TYPE_STREAM, SHOW_ERRNO, "%s: motion-httpd socket failed interface %s" + " / port %s, retrying", hbuf, sbuf); res = res->ai_next; } freeaddrinfo(ressave); if (sd < 0) { - motion_log(ERR, TYPE_STREAM, SHOW_ERRNO, "%s: motion-httpd ERROR bind()" - " [interface %s port %s]", __FUNCTION__, hbuf, sbuf); + MOTION_LOG(EMG, TYPE_STREAM, SHOW_ERRNO, "%s: motion-httpd ERROR bind()" + " [interface %s port %s]", hbuf, sbuf); pthread_mutex_destroy(&httpd_mutex); return; } if (listen(sd,5) == -1) { - motion_log(ERR, TYPE_STREAM, SHOW_ERRNO, "%s: motion-httpd ERROR listen()" - " [interface %s port %s]", __FUNCTION__, hbuf, sbuf); + MOTION_LOG(EMG, TYPE_STREAM, SHOW_ERRNO, "%s: motion-httpd ERROR listen()" + " [interface %s port %s]", hbuf, sbuf); close(sd); pthread_mutex_destroy(&httpd_mutex); return; } - motion_log(DBG, TYPE_STREAM, NO_ERRNO, "%s: motion-httpd/"VERSION" running," - " accepting connections", __FUNCTION__); - motion_log(DBG, TYPE_STREAM, NO_ERRNO, "%s: motion-httpd: waiting for data" - " on %s port TCP %s", __FUNCTION__, hbuf, sbuf); + MOTION_LOG(ALR, TYPE_STREAM, NO_ERRNO, "%s: motion-httpd/"VERSION" running," + " accepting connections"); + MOTION_LOG(ALR, TYPE_STREAM, NO_ERRNO, "%s: motion-httpd: waiting for data" + " on %s port TCP %s", hbuf, sbuf); if (cnt[0]->conf.webcontrol_authentication != NULL) { char *userpass = NULL; @@ -2525,15 +2506,13 @@ void httpd_run(struct context **cnt) if (client_socket_fd < 0) { if ((!cnt[0]) || (cnt[0]->finish)) { - motion_log(EMG, TYPE_STREAM, NO_ERRNO, "%s: motion-httpd - Finishing", - __FUNCTION__); + MOTION_LOG(EMG, TYPE_STREAM, NO_ERRNO, "%s: motion-httpd - Finishing"); closehttpd = 1; } } else { /* Get the Client request */ client_sent_quit_message = read_client(client_socket_fd, cnt, authentication); - motion_log(ERR, TYPE_STREAM, NO_ERRNO, "%s: motion-httpd - Read from client", - __FUNCTION__); + MOTION_LOG(ERR, TYPE_STREAM, NO_ERRNO, "%s: motion-httpd - Read from client"); /* Close Connection */ if (client_socket_fd) @@ -2545,7 +2524,7 @@ void httpd_run(struct context **cnt) if (authentication != NULL) free(authentication); close(sd); - motion_log(EMG, TYPE_STREAM, NO_ERRNO, "%s: motion-httpd Closing", __FUNCTION__); + MOTION_LOG(EMG, TYPE_STREAM, NO_ERRNO, "%s: motion-httpd Closing"); pthread_mutex_destroy(&httpd_mutex); } @@ -2557,6 +2536,6 @@ void *motion_web_control(void *arg) { struct context **cnt = arg; httpd_run(cnt); - motion_log(EMG, TYPE_STREAM, NO_ERRNO, "%s: motion-httpd thread exit", __FUNCTION__); + MOTION_LOG(EMG, TYPE_STREAM, NO_ERRNO, "%s: motion-httpd thread exit"); pthread_exit(NULL); }