mirror of
https://github.com/Motion-Project/motion.git
synced 2026-01-26 07:38:29 -05:00
Major clean up code , apply CODE_STANDARD rules, add partially IPV6 http://www.lavrsen.dk/twiki/bin/view/Motion/IPv6 ( webcam and http-control , not netcam yet )
This commit is contained in:
@@ -2,6 +2,8 @@ SVN trunk Summary of Changes
|
||||
|
||||
Features
|
||||
* Insert Blanking frames http://www.lavrsen.dk/twiki/bin/view/Motion/FeatureRequest2007x12x16x132522 (Dag Erlandsson)
|
||||
* IPV6 for http-control and webcam stream not netcam yet http://www.lavrsen.dk/twiki/bin/view/Motion/IPv6
|
||||
(Jeroen Massar & Angel Carpintero)
|
||||
|
||||
Bugfixes
|
||||
|
||||
|
||||
6
CREDITS
6
CREDITS
@@ -395,6 +395,8 @@ Angel Carpintero
|
||||
http://www.lavrsen.dk/twiki/bin/view/Motion/BugReport2008x02x25x025134
|
||||
* Fixed stepper when is used track_auto on.
|
||||
* Added to configure.in --with-pwcbsd to allow compile motion in freebsd with webcam support instead of bktr.
|
||||
* IPV6 for http-control and webcam stream not netcam yet http://www.lavrsen.dk/twiki/bin/view/Motion/IPv6
|
||||
(Jeroen Massar & Angel Carpintero)
|
||||
|
||||
Jared D
|
||||
* Change bayer2rgb24() to fix a problem with sn9c102 driver
|
||||
@@ -1022,6 +1024,10 @@ Bill Maidment
|
||||
Philip Marien
|
||||
* Fixed a problem when compiling with --without-v4l configuration.
|
||||
|
||||
Jeroen Massar
|
||||
* IPV6 for http-control and webcam stream not netcam yet http://www.lavrsen.dk/twiki/bin/view/Motion/IPv6
|
||||
(Jeroen Massar & Angel Carpintero)
|
||||
|
||||
Lionnel Maugis
|
||||
* ffmpeg code
|
||||
|
||||
|
||||
350
alg.c
350
alg.c
@@ -20,23 +20,23 @@
|
||||
/* locate the center and size of the movement. */
|
||||
void alg_locate_center_size(struct images *imgs, int width, int height, struct coord *cent)
|
||||
{
|
||||
unsigned char *out=imgs->out;
|
||||
int *labels=imgs->labels;
|
||||
int x, y, centc=0, xdist=0, ydist=0;
|
||||
unsigned char *out = imgs->out;
|
||||
int *labels = imgs->labels;
|
||||
int x, y, centc = 0, xdist = 0, ydist = 0;
|
||||
|
||||
cent->x=0;
|
||||
cent->y=0;
|
||||
cent->maxx=0;
|
||||
cent->maxy=0;
|
||||
cent->minx=width;
|
||||
cent->miny=height;
|
||||
cent->x = 0;
|
||||
cent->y = 0;
|
||||
cent->maxx = 0;
|
||||
cent->maxy = 0;
|
||||
cent->minx = width;
|
||||
cent->miny = height;
|
||||
|
||||
/* If Labeling enabled - locate center of largest labelgroup */
|
||||
if (imgs->labelsize_max) {
|
||||
/* Locate largest labelgroup */
|
||||
for (y=0; y<height; y++) {
|
||||
for (x=0; x<width; x++) {
|
||||
if (*(labels++)&32768) {
|
||||
for (y = 0; y < height; y++) {
|
||||
for (x = 0; x < width; x++) {
|
||||
if (*(labels++) & 32768) {
|
||||
cent->x += x;
|
||||
cent->y += y;
|
||||
centc++;
|
||||
@@ -45,8 +45,8 @@ void alg_locate_center_size(struct images *imgs, int width, int height, struct c
|
||||
}
|
||||
} else {
|
||||
/* Locate movement */
|
||||
for (y=0; y<height; y++) {
|
||||
for (x=0; x<width; x++) {
|
||||
for (y = 0; y < height; y++) {
|
||||
for (x = 0; x < width; x++) {
|
||||
if (*(out++)) {
|
||||
cent->x += x;
|
||||
cent->y += y;
|
||||
@@ -56,22 +56,22 @@ void alg_locate_center_size(struct images *imgs, int width, int height, struct c
|
||||
}
|
||||
}
|
||||
if (centc) {
|
||||
cent->x=cent->x/centc;
|
||||
cent->y=cent->y/centc;
|
||||
cent->x = cent->x / centc;
|
||||
cent->y = cent->y / centc;
|
||||
}
|
||||
|
||||
/* Now we find the size of the Motion */
|
||||
|
||||
/* First reset pointers back to initial value */
|
||||
centc=0;
|
||||
labels=imgs->labels;
|
||||
out=imgs->out;
|
||||
centc = 0;
|
||||
labels = imgs->labels;
|
||||
out = imgs->out;
|
||||
|
||||
/* 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++) {
|
||||
if (*(labels++)&32768) {
|
||||
for (y = 0; y < height; y++) {
|
||||
for (x = 0; x < width; x++) {
|
||||
if (*(labels++) & 32768) {
|
||||
if (x > cent->x)
|
||||
xdist += x - cent->x;
|
||||
else if (x < cent->x)
|
||||
@@ -85,8 +85,8 @@ void alg_locate_center_size(struct images *imgs, int width, int height, struct c
|
||||
}
|
||||
}
|
||||
} else {
|
||||
for (y=0; y<height; y++) {
|
||||
for (x=0; x<width; x++) {
|
||||
for (y = 0; y < height; y++) {
|
||||
for (x = 0; x < width; x++) {
|
||||
if (*(out++)) {
|
||||
if (x > cent->x)
|
||||
xdist += x - cent->x;
|
||||
@@ -103,13 +103,13 @@ void alg_locate_center_size(struct images *imgs, int width, int height, struct c
|
||||
}
|
||||
|
||||
if (centc) {
|
||||
cent->minx = cent->x - xdist/centc*2;
|
||||
cent->maxx = cent->x + xdist/centc*2;
|
||||
cent->minx = cent->x - xdist / centc * 2;
|
||||
cent->maxx = cent->x + xdist / centc * 2;
|
||||
/* 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 */
|
||||
cent->miny = cent->y - ydist/centc*3;
|
||||
cent->maxy = cent->y + ydist/centc*2;
|
||||
cent->miny = cent->y - ydist / centc * 3;
|
||||
cent->maxy = cent->y + ydist / centc * 2;
|
||||
}
|
||||
if (cent->maxx > width - 1)
|
||||
cent->maxx = width - 1;
|
||||
@@ -134,7 +134,7 @@ 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 */
|
||||
cent->y = (cent->miny + cent->maxy)/2;
|
||||
cent->y = (cent->miny + cent->maxy) / 2;
|
||||
|
||||
}
|
||||
|
||||
@@ -142,46 +142,46 @@ void alg_locate_center_size(struct images *imgs, int width, int height, struct c
|
||||
/* draw a box around the movement */
|
||||
void alg_draw_location(struct coord *cent, struct images *imgs, int width, unsigned char *new, int mode)
|
||||
{
|
||||
unsigned char *out=imgs->out;
|
||||
unsigned char *out = imgs->out;
|
||||
int x, y;
|
||||
|
||||
out=imgs->out;
|
||||
out = imgs->out;
|
||||
|
||||
/* Draw a box around the movement */
|
||||
if (mode == LOCATE_BOTH){ /* both normal and motion image gets a box */
|
||||
int width_miny = width*cent->miny;
|
||||
int width_maxy = width*cent->maxy;
|
||||
for (x=cent->minx; x<=cent->maxx; x++) {
|
||||
for (x = cent->minx; x <= cent->maxx; x++) {
|
||||
int width_miny_x = x+width_miny;
|
||||
int width_maxy_x = x+width_maxy;
|
||||
new[width_miny_x]=~new[width_miny_x];
|
||||
new[width_maxy_x]=~new[width_maxy_x];
|
||||
out[width_miny_x]=~out[width_miny_x];
|
||||
out[width_maxy_x]=~out[width_maxy_x];
|
||||
new[width_miny_x] =~new[width_miny_x];
|
||||
new[width_maxy_x] =~new[width_maxy_x];
|
||||
out[width_miny_x] =~out[width_miny_x];
|
||||
out[width_maxy_x] =~out[width_maxy_x];
|
||||
}
|
||||
for (y=cent->miny; y<=cent->maxy; y++) {
|
||||
int width_minx_y = cent->minx+y*width;
|
||||
int width_maxx_y = cent->maxx+y*width;
|
||||
new[width_minx_y]=~new[width_minx_y];
|
||||
new[width_maxx_y]=~new[width_maxx_y];
|
||||
out[width_minx_y]=~out[width_minx_y];
|
||||
out[width_maxx_y]=~out[width_maxx_y];
|
||||
for (y = cent->miny; y <= cent->maxy; y++) {
|
||||
int width_minx_y = cent->minx + y * width;
|
||||
int width_maxx_y = cent->maxx + y * width;
|
||||
new[width_minx_y] =~new[width_minx_y];
|
||||
new[width_maxx_y] =~new[width_maxx_y];
|
||||
out[width_minx_y] =~out[width_minx_y];
|
||||
out[width_maxx_y] =~out[width_maxx_y];
|
||||
}
|
||||
}
|
||||
else{ /* normal image only (e.g. preview shot) */
|
||||
int width_miny = width*cent->miny;
|
||||
int width_maxy = width*cent->maxy;
|
||||
for (x=cent->minx; x<=cent->maxx; x++) {
|
||||
int width_miny = width * cent->miny;
|
||||
int width_maxy = width * cent->maxy;
|
||||
for (x = cent->minx; x <= cent->maxx; x++) {
|
||||
int width_miny_x = width_miny+x;
|
||||
int width_maxy_x = width_maxy+x;
|
||||
new[width_miny_x]=~new[width_miny_x];
|
||||
new[width_maxy_x]=~new[width_maxy_x];
|
||||
new[width_miny_x] =~new[width_miny_x];
|
||||
new[width_maxy_x] =~new[width_maxy_x];
|
||||
}
|
||||
for (y=cent->miny; y<=cent->maxy; y++) {
|
||||
for (y = cent->miny; y <= cent->maxy; y++) {
|
||||
int minx_y = cent->minx+y*width;
|
||||
int maxx_y = cent->maxx+y*width;
|
||||
new[minx_y]=~new[minx_y];
|
||||
new[maxx_y]=~new[maxx_y];
|
||||
new[minx_y] =~new[minx_y];
|
||||
new[maxx_y] =~new[maxx_y];
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -189,26 +189,26 @@ void alg_draw_location(struct coord *cent, struct images *imgs, int width, unsig
|
||||
|
||||
|
||||
#define NORM 100
|
||||
#define ABS(x) ((x)<0 ? -(x) : (x))
|
||||
#define ABS(x) ((x) < 0 ? -(x) : (x))
|
||||
#define DIFF(x, y) (ABS((x)-(y)))
|
||||
#define NDIFF(x, y) (ABS(x)*NORM/(ABS(x)+2*DIFF(x,y)))
|
||||
#define NDIFF(x, y) (ABS(x) * NORM / (ABS(x) + 2 * DIFF(x, y)))
|
||||
|
||||
|
||||
void alg_noise_tune(struct context *cnt, unsigned char *new)
|
||||
{
|
||||
struct images *imgs=&cnt->imgs;
|
||||
struct images *imgs = &cnt->imgs;
|
||||
int i;
|
||||
unsigned char *ref=imgs->ref;
|
||||
int diff, sum=0, count=0;
|
||||
unsigned char *mask=imgs->mask;
|
||||
unsigned char *smartmask=imgs->smartmask_final;
|
||||
unsigned char *ref = imgs->ref;
|
||||
int diff, sum = 0, count = 0;
|
||||
unsigned char *mask = imgs->mask;
|
||||
unsigned char *smartmask = imgs->smartmask_final;
|
||||
|
||||
i=imgs->motionsize;
|
||||
i = imgs->motionsize;
|
||||
|
||||
for (; i>0; i--) {
|
||||
for (; i > 0; i--) {
|
||||
diff = ABS(*ref - *new);
|
||||
if (mask)
|
||||
diff = ((diff * *mask++)/255);
|
||||
diff = ((diff * *mask++) / 255);
|
||||
if (*smartmask){
|
||||
sum += diff + 1;
|
||||
count++;
|
||||
@@ -298,8 +298,8 @@ static int iflood(int x, int y,
|
||||
* 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--) {
|
||||
labels[y*width+x] = newvalue;
|
||||
for (x = x1; x >= 0 && out[y * width + x] != 0 && labels[y * width + x] == oldvalue; x--) {
|
||||
labels[y * width + x] = newvalue;
|
||||
count++;
|
||||
}
|
||||
|
||||
@@ -314,8 +314,8 @@ static int iflood(int x, int y,
|
||||
x = x1 + 1;
|
||||
|
||||
do {
|
||||
for (; x < width && out[y*width+x] != 0 && labels[y*width+x]==oldvalue; x++) {
|
||||
labels[y*width+x] = newvalue;
|
||||
for (; x < width && out[y * width + x] != 0 && labels[y * width + x] == oldvalue; x++) {
|
||||
labels[y * width + x] = newvalue;
|
||||
count++;
|
||||
}
|
||||
|
||||
@@ -326,7 +326,7 @@ static int iflood(int x, int y,
|
||||
|
||||
skip:
|
||||
|
||||
for (x++; x <= x2 && !(out[y*width+x] != 0 && labels[y*width+x]==oldvalue); x++);
|
||||
for (x++; x <= x2 && !(out[y * width + x] != 0 && labels[y * width + x] == oldvalue); x++);
|
||||
|
||||
l = x;
|
||||
} while (x <= x2);
|
||||
@@ -336,48 +336,48 @@ static int iflood(int x, int y,
|
||||
|
||||
static int alg_labeling(struct context *cnt)
|
||||
{
|
||||
struct images *imgs=&cnt->imgs;
|
||||
unsigned char *out=imgs->out;
|
||||
int *labels=imgs->labels;
|
||||
struct images *imgs = &cnt->imgs;
|
||||
unsigned char *out = imgs->out;
|
||||
int *labels = imgs->labels;
|
||||
int ix, iy, pixelpos;
|
||||
int width=imgs->width;
|
||||
int height=imgs->height;
|
||||
int labelsize=0;
|
||||
int current_label=2;
|
||||
cnt->current_image->total_labels=0;
|
||||
imgs->labelsize_max=0;
|
||||
int width = imgs->width;
|
||||
int height = imgs->height;
|
||||
int labelsize = 0;
|
||||
int current_label = 2;
|
||||
cnt->current_image->total_labels = 0;
|
||||
imgs->labelsize_max = 0;
|
||||
/* ALL labels above threshold are counted as labelgroup */
|
||||
imgs->labelgroup_max=0;
|
||||
imgs->labels_above=0;
|
||||
imgs->labelgroup_max = 0;
|
||||
imgs->labels_above = 0;
|
||||
|
||||
/* 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++ ) {
|
||||
for (iy = 0; iy < height-1; iy++) {
|
||||
for (ix = 0; ix < width-1; ix++, pixelpos++) {
|
||||
/* no motion - no label */
|
||||
if( out[pixelpos] == 0 ) {
|
||||
labels[pixelpos]=1;
|
||||
labels[pixelpos] = 1;
|
||||
continue;
|
||||
}
|
||||
|
||||
/* already visited by iflood */
|
||||
if (labels[pixelpos] > 0)
|
||||
continue;
|
||||
labelsize=iflood(ix, iy, width, height, out, labels, current_label, 0);
|
||||
labelsize = iflood(ix, iy, width, height, out, labels, current_label, 0);
|
||||
|
||||
if( labelsize > 0 ) {
|
||||
if (labelsize > 0) {
|
||||
//printf( "Label: %i (%i) Size: %i (%i,%i)\n", current_label, cnt->current_image->total_labels, labelsize, ix, iy );
|
||||
/* 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;
|
||||
if (labelsize > cnt->threshold) {
|
||||
labelsize = iflood(ix, iy, width, height, out, labels, current_label + 32768, current_label);
|
||||
imgs->labelgroup_max += labelsize;
|
||||
imgs->labels_above++;
|
||||
}
|
||||
|
||||
if( imgs->labelsize_max < labelsize ){
|
||||
imgs->labelsize_max=labelsize;
|
||||
imgs->largest_label=current_label;
|
||||
if (imgs->labelsize_max < labelsize) {
|
||||
imgs->labelsize_max = labelsize;
|
||||
imgs->largest_label = current_label;
|
||||
}
|
||||
|
||||
cnt->current_image->total_labels++;
|
||||
@@ -546,7 +546,7 @@ static int erode9(unsigned char *img, int width, int height, void *buffer, unsig
|
||||
char *Row1,*Row2,*Row3;
|
||||
Row1 = buffer;
|
||||
Row2 = Row1 + width;
|
||||
Row3 = Row1 + 2*width;
|
||||
Row3 = Row1 + 2 * width;
|
||||
memset(Row2, flag, width);
|
||||
memcpy(Row3, img, width);
|
||||
for (y = 0; y < height; y++) {
|
||||
@@ -555,7 +555,7 @@ static int erode9(unsigned char *img, int width, int height, void *buffer, unsig
|
||||
if (y == height-1)
|
||||
memset(Row3, flag, width);
|
||||
else
|
||||
memcpy(Row3, img+(y+1)*width, width);
|
||||
memcpy(Row3, img + (y+1) * width, width);
|
||||
|
||||
for (i = width-2; i >= 1; i--) {
|
||||
if (Row1[i-1] == 0 ||
|
||||
@@ -571,7 +571,7 @@ static int erode9(unsigned char *img, int width, int height, void *buffer, unsig
|
||||
else
|
||||
sum++;
|
||||
}
|
||||
img[y*width] = img[y*width+width-1] = flag;
|
||||
img[y * width] = img[y * width + width - 1] = flag;
|
||||
}
|
||||
return sum;
|
||||
}
|
||||
@@ -583,7 +583,7 @@ static int erode5(unsigned char *img, int width, int height, void *buffer, unsig
|
||||
char *Row1,*Row2,*Row3;
|
||||
Row1 = buffer;
|
||||
Row2 = Row1 + width;
|
||||
Row3 = Row1 + 2*width;
|
||||
Row3 = Row1 + 2 * width;
|
||||
memset(Row2, flag, width);
|
||||
memcpy(Row3, img, width);
|
||||
for (y = 0; y < height; y++) {
|
||||
@@ -592,19 +592,19 @@ static int erode5(unsigned char *img, int width, int height, void *buffer, unsig
|
||||
if (y == height-1)
|
||||
memset(Row3, flag, width);
|
||||
else
|
||||
memcpy(Row3, img+(y+1)*width, width);
|
||||
memcpy(Row3, img + (y + 1) * width, width);
|
||||
|
||||
for (i = width-2; i >= 1; i--) {
|
||||
for (i = width - 2; i >= 1; i--) {
|
||||
if (Row1[i] == 0 ||
|
||||
Row2[i-1] == 0 ||
|
||||
Row2[i] == 0 ||
|
||||
Row2[i+1] == 0 ||
|
||||
Row3[i] == 0)
|
||||
img[y*width+i] = 0;
|
||||
img[y * width + i] = 0;
|
||||
else
|
||||
sum++;
|
||||
}
|
||||
img[y*width] = img[y*width+width-1] = flag;
|
||||
img[y * width] = img[y * width + width - 1] = flag;
|
||||
}
|
||||
return sum;
|
||||
}
|
||||
@@ -617,33 +617,33 @@ int alg_despeckle(struct context *cnt, int olddiffs)
|
||||
int diffs = 0;
|
||||
unsigned char *out = cnt->imgs.out;
|
||||
int width = cnt->imgs.width;
|
||||
int height= cnt->imgs.height;
|
||||
int height = cnt->imgs.height;
|
||||
int done = 0, i, len = strlen(cnt->conf.despeckle);
|
||||
unsigned char *common_buffer = cnt->imgs.common_buffer;
|
||||
|
||||
for (i = 0; i < len; i++) {
|
||||
switch (cnt->conf.despeckle[i]) {
|
||||
case 'E':
|
||||
if ((diffs = erode9(out, width, height, common_buffer, 0)) == 0) i=len;
|
||||
done=1;
|
||||
if ((diffs = erode9(out, width, height, common_buffer, 0)) == 0) i = len;
|
||||
done = 1;
|
||||
break;
|
||||
case 'e':
|
||||
if ((diffs = erode5(out, width, height, common_buffer, 0)) == 0) i=len;
|
||||
done=1;
|
||||
if ((diffs = erode5(out, width, height, common_buffer, 0)) == 0) i = len;
|
||||
done = 1;
|
||||
break;
|
||||
case 'D':
|
||||
diffs = dilate9(out, width, height, common_buffer);
|
||||
done=1;
|
||||
done = 1;
|
||||
break;
|
||||
case 'd':
|
||||
diffs = dilate5(out, width, height, common_buffer);
|
||||
done=1;
|
||||
done = 1;
|
||||
break;
|
||||
/* no further despeckle after labeling! */
|
||||
case 'l':
|
||||
diffs = alg_labeling(cnt);
|
||||
i=len;
|
||||
done=2;
|
||||
i = len;
|
||||
done = 2;
|
||||
break;
|
||||
}
|
||||
}
|
||||
@@ -668,10 +668,9 @@ void alg_tune_smartmask(struct context *cnt)
|
||||
unsigned char *smartmask = cnt->imgs.smartmask;
|
||||
unsigned char *smartmask_final = cnt->imgs.smartmask_final;
|
||||
int *smartmask_buffer = cnt->imgs.smartmask_buffer;
|
||||
int sensitivity=cnt->lastrate*(11-cnt->smartmask_speed);
|
||||
int sensitivity = cnt->lastrate * (11 - cnt->smartmask_speed);
|
||||
|
||||
for (i=0; i<motionsize; i++)
|
||||
{
|
||||
for (i = 0; i < motionsize; i++) {
|
||||
/* Decrease smart_mask sensitivity every 5*speed seconds only */
|
||||
if (smartmask[i] > 0)
|
||||
smartmask[i]--;
|
||||
@@ -679,16 +678,16 @@ void alg_tune_smartmask(struct context *cnt)
|
||||
diff = smartmask_buffer[i]/sensitivity;
|
||||
if (diff){
|
||||
if (smartmask[i] <= diff+80)
|
||||
smartmask[i]+=diff;
|
||||
smartmask[i] += diff;
|
||||
else
|
||||
smartmask[i]=80;
|
||||
smartmask_buffer[i]%=sensitivity;
|
||||
smartmask[i] = 80;
|
||||
smartmask_buffer[i] %= sensitivity;
|
||||
}
|
||||
/* Transfer raw mask to the final stage when above trigger value */
|
||||
if (smartmask[i]>20)
|
||||
smartmask_final[i]=0;
|
||||
if (smartmask[i] > 20)
|
||||
smartmask_final[i] = 0;
|
||||
else
|
||||
smartmask_final[i]=255;
|
||||
smartmask_final[i] = 255;
|
||||
}
|
||||
/* Further expansion (here:erode due to inverted logic!) of the mask */
|
||||
diff = erode9(smartmask_final, cnt->imgs.width, cnt->imgs.height, cnt->imgs.common_buffer, 255);
|
||||
@@ -700,21 +699,21 @@ void alg_tune_smartmask(struct context *cnt)
|
||||
|
||||
int alg_diff_standard (struct context *cnt, unsigned char *new)
|
||||
{
|
||||
struct images *imgs=&cnt->imgs;
|
||||
int i, diffs=0;
|
||||
int noise=cnt->noise;
|
||||
int smartmask_speed=cnt->smartmask_speed;
|
||||
unsigned char *ref=imgs->ref;
|
||||
unsigned char *out=imgs->out;
|
||||
unsigned char *mask=imgs->mask;
|
||||
unsigned char *smartmask_final=imgs->smartmask_final;
|
||||
int *smartmask_buffer=imgs->smartmask_buffer;
|
||||
struct images *imgs = &cnt->imgs;
|
||||
int i, diffs = 0;
|
||||
int noise = cnt->noise;
|
||||
int smartmask_speed = cnt->smartmask_speed;
|
||||
unsigned char *ref = imgs->ref;
|
||||
unsigned char *out = imgs->out;
|
||||
unsigned char *mask = imgs->mask;
|
||||
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 */
|
||||
#endif
|
||||
|
||||
i=imgs->motionsize;
|
||||
i = imgs->motionsize;
|
||||
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
|
||||
@@ -741,7 +740,7 @@ int alg_diff_standard (struct context *cnt, unsigned char *new)
|
||||
* 255*(noise+1)-1).
|
||||
*/
|
||||
mmtemp.uw[0] = mmtemp.uw[1] = mmtemp.uw[2] = mmtemp.uw[3] =
|
||||
(unsigned short)(noise * 255 + 254);
|
||||
(unsigned short)(noise * 255 + 254);
|
||||
|
||||
/* Reset mm5 to zero, set the mm6 mask, and store the multiplied noise
|
||||
* level as four words in mm7.
|
||||
@@ -756,9 +755,9 @@ int alg_diff_standard (struct context *cnt, unsigned char *new)
|
||||
* in each packed byte, which can hold at most 255 diffs before it
|
||||
* gets saturated.
|
||||
*/
|
||||
unload=255;
|
||||
unload = 255;
|
||||
|
||||
for (; i>7; i-=8) {
|
||||
for (; i > 7; i -= 8) {
|
||||
/* Calculate abs(*ref-*new) for 8 pixels in parallel. */
|
||||
movq_m2r(*ref, mm0); /* U: mm0 = r7 r6 r5 r4 r3 r2 r1 r0 */
|
||||
pxor_r2r(mm4, mm4); /* V: mm4 = 0 */
|
||||
@@ -793,9 +792,8 @@ int alg_diff_standard (struct context *cnt, unsigned char *new)
|
||||
|
||||
pmullw_r2r(mm3, mm1); /* U: mm1 = (d7*m7) ... (d4*m4) */
|
||||
|
||||
mask+=8;
|
||||
}
|
||||
else {
|
||||
mask += 8;
|
||||
} else {
|
||||
/* Not using mask - multiply the absolute differences by 255. We
|
||||
* do this by left-shifting 8 places and then subtracting dX.
|
||||
*/
|
||||
@@ -854,18 +852,18 @@ int alg_diff_standard (struct context *cnt, unsigned char *new)
|
||||
|
||||
/* Add to *smartmask_buffer. This is probably the fastest way to do it. */
|
||||
if (cnt->event_nr != cnt->prev_event) {
|
||||
if (mmtemp.ub[0]) smartmask_buffer[0]+=SMARTMASK_SENSITIVITY_INCR;
|
||||
if (mmtemp.ub[1]) smartmask_buffer[1]+=SMARTMASK_SENSITIVITY_INCR;
|
||||
if (mmtemp.ub[2]) smartmask_buffer[2]+=SMARTMASK_SENSITIVITY_INCR;
|
||||
if (mmtemp.ub[3]) smartmask_buffer[3]+=SMARTMASK_SENSITIVITY_INCR;
|
||||
if (mmtemp.ub[4]) smartmask_buffer[4]+=SMARTMASK_SENSITIVITY_INCR;
|
||||
if (mmtemp.ub[5]) smartmask_buffer[5]+=SMARTMASK_SENSITIVITY_INCR;
|
||||
if (mmtemp.ub[6]) smartmask_buffer[6]+=SMARTMASK_SENSITIVITY_INCR;
|
||||
if (mmtemp.ub[7]) smartmask_buffer[7]+=SMARTMASK_SENSITIVITY_INCR;
|
||||
if (mmtemp.ub[0]) smartmask_buffer[0] += SMARTMASK_SENSITIVITY_INCR;
|
||||
if (mmtemp.ub[1]) smartmask_buffer[1] += SMARTMASK_SENSITIVITY_INCR;
|
||||
if (mmtemp.ub[2]) smartmask_buffer[2] += SMARTMASK_SENSITIVITY_INCR;
|
||||
if (mmtemp.ub[3]) smartmask_buffer[3] += SMARTMASK_SENSITIVITY_INCR;
|
||||
if (mmtemp.ub[4]) smartmask_buffer[4] += SMARTMASK_SENSITIVITY_INCR;
|
||||
if (mmtemp.ub[5]) smartmask_buffer[5] += SMARTMASK_SENSITIVITY_INCR;
|
||||
if (mmtemp.ub[6]) smartmask_buffer[6] += SMARTMASK_SENSITIVITY_INCR;
|
||||
if (mmtemp.ub[7]) smartmask_buffer[7] += SMARTMASK_SENSITIVITY_INCR;
|
||||
}
|
||||
|
||||
smartmask_buffer+=8;
|
||||
smartmask_final+=8;
|
||||
smartmask_buffer += 8;
|
||||
smartmask_final += 8;
|
||||
}
|
||||
|
||||
movq_m2r(*new, mm2); /* U: mm1 = n7 n6 n5 n4 n3 n2 n1 n0 */
|
||||
@@ -885,28 +883,28 @@ int alg_diff_standard (struct context *cnt, unsigned char *new)
|
||||
/* Every 255th turn, we need to unload mm5 into the diffs variable,
|
||||
* because otherwise the packed bytes will get saturated.
|
||||
*/
|
||||
if (--unload==0) {
|
||||
if (--unload == 0) {
|
||||
/* Unload mm5 to memory and reset it. */
|
||||
movq_r2m(mm5, mmtemp); /* U */
|
||||
pxor_r2r(mm5, mm5); /* V: mm5 = 0 */
|
||||
|
||||
diffs += mmtemp.ub[0] + mmtemp.ub[1] + mmtemp.ub[2] + mmtemp.ub[3] +
|
||||
mmtemp.ub[4] + mmtemp.ub[5] + mmtemp.ub[6] + mmtemp.ub[7];
|
||||
unload=255;
|
||||
mmtemp.ub[4] + mmtemp.ub[5] + mmtemp.ub[6] + mmtemp.ub[7];
|
||||
unload = 255;
|
||||
}
|
||||
|
||||
out+=8;
|
||||
ref+=8;
|
||||
new+=8;
|
||||
out += 8;
|
||||
ref += 8;
|
||||
new += 8;
|
||||
}
|
||||
|
||||
/* Check if there are diffs left in mm5 that need to be copied to the
|
||||
* diffs variable.
|
||||
*/
|
||||
if (unload<255) {
|
||||
if (unload < 255) {
|
||||
movq_r2m(mm5, mmtemp);
|
||||
diffs += mmtemp.ub[0] + mmtemp.ub[1] + mmtemp.ub[2] + mmtemp.ub[3] +
|
||||
mmtemp.ub[4] + mmtemp.ub[5] + mmtemp.ub[6] + mmtemp.ub[7];
|
||||
mmtemp.ub[4] + mmtemp.ub[5] + mmtemp.ub[6] + mmtemp.ub[7];
|
||||
}
|
||||
|
||||
emms();
|
||||
@@ -917,11 +915,11 @@ int alg_diff_standard (struct context *cnt, unsigned char *new)
|
||||
* case the non-MMX code needs to take care of the remaining pixels.
|
||||
*/
|
||||
|
||||
for (; i>0; i--) {
|
||||
register unsigned char curdiff=(int)(abs(*ref - *new)); /* using a temp variable is 12% faster */
|
||||
for (; i > 0; i--) {
|
||||
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);
|
||||
curdiff = ((int)(curdiff * *mask++) / 255);
|
||||
|
||||
if (smartmask_speed) {
|
||||
if (curdiff > noise) {
|
||||
@@ -934,14 +932,14 @@ int alg_diff_standard (struct context *cnt, unsigned char *new)
|
||||
(*smartmask_buffer) += SMARTMASK_SENSITIVITY_INCR;
|
||||
/* apply smart_mask */
|
||||
if (!*smartmask_final)
|
||||
curdiff=0;
|
||||
curdiff = 0;
|
||||
}
|
||||
smartmask_final++;
|
||||
smartmask_buffer++;
|
||||
}
|
||||
/* Pixel still in motion after all the masks? */
|
||||
if (curdiff > noise) {
|
||||
*out=*new;
|
||||
*out = *new;
|
||||
diffs++;
|
||||
}
|
||||
out++;
|
||||
@@ -956,26 +954,26 @@ int alg_diff_standard (struct context *cnt, unsigned char *new)
|
||||
*/
|
||||
static char alg_diff_fast(struct context *cnt, int max_n_changes, unsigned char *new)
|
||||
{
|
||||
struct images *imgs=&cnt->imgs;
|
||||
int i, diffs=0, step=imgs->motionsize/10000;
|
||||
int noise=cnt->noise;
|
||||
unsigned char *ref=imgs->ref;
|
||||
struct images *imgs = &cnt->imgs;
|
||||
int i, diffs = 0, step = imgs->motionsize/10000;
|
||||
int noise = cnt->noise;
|
||||
unsigned char *ref = imgs->ref;
|
||||
|
||||
if (!step%2)
|
||||
if (!step % 2)
|
||||
step++;
|
||||
/* we're checking only 1 of several pixels */
|
||||
max_n_changes /= step;
|
||||
|
||||
i=imgs->motionsize;
|
||||
for (; i>0; i-=step) {
|
||||
register unsigned char curdiff=(int)(abs((char)(*ref-*new))); /* using a temp variable is 12% faster */
|
||||
i = imgs->motionsize;
|
||||
for (; i > 0; i -= step) {
|
||||
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)
|
||||
return 1;
|
||||
}
|
||||
ref+=step;
|
||||
new+=step;
|
||||
ref += step;
|
||||
new += step;
|
||||
}
|
||||
|
||||
return 0;
|
||||
@@ -986,10 +984,10 @@ static char alg_diff_fast(struct context *cnt, int max_n_changes, unsigned char
|
||||
*/
|
||||
int alg_diff(struct context *cnt, unsigned char *new)
|
||||
{
|
||||
int diffs=0;
|
||||
int diffs = 0;
|
||||
|
||||
if (alg_diff_fast(cnt, cnt->conf.max_changes/2, new))
|
||||
diffs=alg_diff_standard(cnt, new);
|
||||
if (alg_diff_fast(cnt, cnt->conf.max_changes / 2, new))
|
||||
diffs = alg_diff_standard(cnt, new);
|
||||
|
||||
return diffs;
|
||||
}
|
||||
@@ -1000,7 +998,7 @@ int alg_diff(struct context *cnt, unsigned char *new)
|
||||
*/
|
||||
int alg_lightswitch(struct context *cnt, int diffs)
|
||||
{
|
||||
struct images *imgs=&cnt->imgs;
|
||||
struct images *imgs = &cnt->imgs;
|
||||
|
||||
if (cnt->conf.lightswitch < 0)
|
||||
cnt->conf.lightswitch = 0;
|
||||
@@ -1019,29 +1017,29 @@ int alg_switchfilter(struct context *cnt, int diffs, unsigned char *newimg)
|
||||
int linediff = diffs / cnt->imgs.height;
|
||||
unsigned char *out = cnt->imgs.out;
|
||||
int y, x, line;
|
||||
int lines=0, vertlines=0;
|
||||
int lines = 0, vertlines = 0;
|
||||
|
||||
for (y=0; y < cnt->imgs.height; y++) {
|
||||
line=0;
|
||||
for (x=0; x < cnt->imgs.width; x++) {
|
||||
for (y = 0; y < cnt->imgs.height; y++) {
|
||||
line = 0;
|
||||
for (x = 0; x < cnt->imgs.width; x++) {
|
||||
if (*(out++)) {
|
||||
line++;
|
||||
}
|
||||
}
|
||||
if (line > cnt->imgs.width/18) {
|
||||
if (line > cnt->imgs.width / 18) {
|
||||
vertlines++;
|
||||
}
|
||||
if (line > linediff*2) {
|
||||
if (line > linediff * 2) {
|
||||
lines++;
|
||||
}
|
||||
}
|
||||
|
||||
if (vertlines > cnt->imgs.height/10 && lines < vertlines/3 &&
|
||||
(vertlines > cnt->imgs.height/4 || lines - vertlines > lines/2)) {
|
||||
if (vertlines > cnt->imgs.height / 10 && lines < vertlines / 3 &&
|
||||
(vertlines > cnt->imgs.height / 4 || lines - vertlines > lines / 2)) {
|
||||
if (cnt->conf.text_changes) {
|
||||
char tmp[80];
|
||||
sprintf(tmp, "%d %d", lines, vertlines);
|
||||
draw_text(newimg, cnt->imgs.width-10, 20, cnt->imgs.width, tmp, cnt->conf.text_double);
|
||||
draw_text(newimg, cnt->imgs.width - 10, 20, cnt->imgs.width, tmp, cnt->conf.text_double);
|
||||
}
|
||||
return diffs;
|
||||
}
|
||||
|
||||
76
conf.c
76
conf.c
@@ -1351,30 +1351,30 @@ config_param config_params[] = {
|
||||
*/
|
||||
static void conf_cmdline (struct context *cnt, short int thread)
|
||||
{
|
||||
struct config *conf=&cnt->conf;
|
||||
struct config *conf = &cnt->conf;
|
||||
int c;
|
||||
|
||||
/* For the string options, we free() if necessary and malloc()
|
||||
* if necessary. This is accomplished by calling mystrcpy();
|
||||
* see this function for more information.
|
||||
*/
|
||||
while ((c=getopt(conf->argc, conf->argv, "c:d:hns?p:"))!=EOF)
|
||||
while ((c = getopt(conf->argc, conf->argv, "c:d:hns?p:")) != EOF)
|
||||
switch (c) {
|
||||
case 'c':
|
||||
if (thread==-1) strcpy(cnt->conf_filename, optarg);
|
||||
if (thread == -1) strcpy(cnt->conf_filename, optarg);
|
||||
break;
|
||||
case 'n':
|
||||
cnt->daemon=0;
|
||||
cnt->daemon = 0;
|
||||
break;
|
||||
case 's':
|
||||
conf->setup_mode=1;
|
||||
conf->setup_mode = 1;
|
||||
break;
|
||||
case 'd':
|
||||
/* no validation - just take what user gives */
|
||||
debug_level = (unsigned short int)atoi(optarg);
|
||||
break;
|
||||
case 'p':
|
||||
if (thread==-1) strcpy(cnt->pid_file, optarg);
|
||||
if (thread == -1) strcpy(cnt->pid_file, optarg);
|
||||
break;
|
||||
case 'h':
|
||||
case '?':
|
||||
@@ -1382,7 +1382,7 @@ static void conf_cmdline (struct context *cnt, short int thread)
|
||||
usage();
|
||||
exit(1);
|
||||
}
|
||||
optind=1;
|
||||
optind = 1;
|
||||
}
|
||||
|
||||
|
||||
@@ -1406,7 +1406,7 @@ struct context **conf_cmdparse(struct context **cnt, const char *cmd, const char
|
||||
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 (strcmp(config_type(&config_params[i]),"string")) {
|
||||
if (strcmp(config_type(&config_params[i]), "string")) {
|
||||
if(config_params[i].conf_value && !arg1)
|
||||
return cnt;
|
||||
}
|
||||
@@ -1423,14 +1423,14 @@ struct context **conf_cmdparse(struct context **cnt, const char *cmd, const char
|
||||
* config_params[i].conf_value - an integer value which is a pointer
|
||||
* to the context structure member relative to the pointer cnt.
|
||||
*/
|
||||
cnt=config_params[i].copy( cnt, arg1, config_params[i].conf_value );
|
||||
cnt = config_params[i].copy( cnt, arg1, config_params[i].conf_value);
|
||||
return cnt;
|
||||
}
|
||||
i++;
|
||||
}
|
||||
|
||||
/* We reached the end of config_params without finding a matching option */
|
||||
motion_log(LOG_ERR, 0, "Unknown config option \"%s\"",cmd);
|
||||
motion_log(LOG_ERR, 0, "Unknown config option \"%s\"", cmd);
|
||||
|
||||
return cnt;
|
||||
}
|
||||
@@ -1484,7 +1484,7 @@ static struct context **conf_process(struct context **cnt, FILE *fp)
|
||||
/* trim space between command and argument */
|
||||
beg++;
|
||||
|
||||
if (strlen(beg) > 0){
|
||||
if (strlen(beg) > 0) {
|
||||
while (*beg == ' ' || *beg == '\t' || *beg == '=' || *beg == '\n' || *beg == '\r') {
|
||||
beg++;
|
||||
}
|
||||
@@ -1520,16 +1520,16 @@ void conf_print(struct context **cnt)
|
||||
unsigned short int i, thread;
|
||||
FILE *conffile;
|
||||
|
||||
for (thread=0; cnt[thread]; thread++) {
|
||||
motion_log(LOG_INFO, 0, "Writing config file to %s",cnt[thread]->conf_filename);
|
||||
conffile=myfopen(cnt[thread]->conf_filename, "w");
|
||||
for (thread = 0; cnt[thread]; thread++) {
|
||||
motion_log(LOG_INFO, 0, "Writing config file to %s", cnt[thread]->conf_filename);
|
||||
conffile = myfopen(cnt[thread]->conf_filename, "w");
|
||||
if (!conffile)
|
||||
continue;
|
||||
fprintf(conffile, "# %s\n", cnt[thread]->conf_filename);
|
||||
fprintf(conffile, "#\n# This config file was generated by motion " VERSION "\n");
|
||||
fprintf(conffile, "\n\n");
|
||||
for (i=0; config_params[i].param_name; i++) {
|
||||
retval=config_params[i].print(cnt, NULL, i, thread);
|
||||
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 (retval) {
|
||||
fprintf(conffile, "%s\n", config_params[i].param_help);
|
||||
@@ -1547,21 +1547,21 @@ void conf_print(struct context **cnt)
|
||||
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", config_params[i].param_help);
|
||||
fprintf(conffile, "%s\n", val);
|
||||
if (strlen(val)==0)
|
||||
fprintf(conffile,"; thread /usr/local/etc/thread1.conf\n");
|
||||
if (strlen(val) == 0)
|
||||
fprintf(conffile, "; thread /usr/local/etc/thread1.conf\n");
|
||||
free(val);
|
||||
} else if (thread==0) {
|
||||
fprintf(conffile,"%s\n", config_params[i].param_help);
|
||||
fprintf(conffile,"; %s value\n\n", config_params[i].param_name);
|
||||
} else if (thread == 0) {
|
||||
fprintf(conffile, "%s\n", config_params[i].param_help);
|
||||
fprintf(conffile, "; %s value\n\n", config_params[i].param_name);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fprintf(conffile, "\n");
|
||||
fclose(conffile);
|
||||
conffile=NULL;
|
||||
conffile = NULL;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1585,7 +1585,7 @@ void conf_print(struct context **cnt)
|
||||
**************************************************************************/
|
||||
struct context ** conf_load (struct context **cnt)
|
||||
{
|
||||
FILE *fp=NULL;
|
||||
FILE *fp = NULL;
|
||||
char filename[PATH_MAX];
|
||||
int i;
|
||||
/* We preserve argc and argv because they get overwritten by the memcpy command */
|
||||
@@ -1622,15 +1622,15 @@ struct context ** conf_load (struct context **cnt)
|
||||
cnt[0]->pid_file[0] = 0;
|
||||
|
||||
conf_cmdline(cnt[0], -1);
|
||||
if (cnt[0]->conf_filename[0]){ /* User has supplied filename on commandline*/
|
||||
if (cnt[0]->conf_filename[0]) { /* User has supplied filename on commandline*/
|
||||
strcpy(filename, cnt[0]->conf_filename);
|
||||
fp = fopen (filename, "r");
|
||||
}
|
||||
if (!fp){ /* Commandline didn't work, try current dir */
|
||||
if (!fp) { /* Commandline didn't work, try current dir */
|
||||
char *path = NULL;
|
||||
if (cnt[0]->conf_filename[0])
|
||||
motion_log(-1, 1, "Configfile %s not found - trying defaults.", filename);
|
||||
if ( (path = get_current_dir_name()) == NULL){
|
||||
if ( (path = get_current_dir_name()) == NULL) {
|
||||
motion_log(LOG_ERR, 1, "Error get_current_dir_name");
|
||||
exit(-1);
|
||||
}
|
||||
@@ -1645,17 +1645,17 @@ 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(-1, 1, "could not open configfile %s",filename);
|
||||
motion_log(-1, 1, "could not open configfile %s", filename);
|
||||
}
|
||||
}
|
||||
|
||||
/* Now we process the motion.conf config file and close it*/
|
||||
if (fp) {
|
||||
strcpy(cnt[0]->conf_filename, filename);
|
||||
motion_log(LOG_INFO, 0, "Processing thread 0 - config file %s",filename);
|
||||
cnt=conf_process(cnt, fp);
|
||||
motion_log(LOG_INFO, 0, "Processing thread 0 - config file %s", filename);
|
||||
cnt = conf_process(cnt, fp);
|
||||
fclose(fp);
|
||||
}else{
|
||||
} else {
|
||||
motion_log(LOG_INFO, 0, "Not config file to process using default values");
|
||||
}
|
||||
|
||||
@@ -1668,7 +1668,7 @@ struct context ** conf_load (struct context **cnt)
|
||||
* so we go through each thread and overrides any set command line
|
||||
* options
|
||||
*/
|
||||
i=-1;
|
||||
i = -1;
|
||||
while(cnt[++i])
|
||||
conf_cmdline(cnt[i], i);
|
||||
|
||||
@@ -1744,7 +1744,7 @@ static struct context **copy_bool (struct context **cnt, const char *str, int va
|
||||
i=-1;
|
||||
while(cnt[++i]) {
|
||||
tmp = (char *)cnt[i]+(int)val_ptr;
|
||||
if ( !strcmp(str, "1") || !strcasecmp(str, "yes") || !strcasecmp(str,"on")) {
|
||||
if ( !strcmp(str, "1") || !strcasecmp(str, "yes") || !strcasecmp(str, "on")) {
|
||||
*((int *)tmp) = 1;
|
||||
} else {
|
||||
*((int *)tmp) = 0;
|
||||
@@ -1898,7 +1898,7 @@ const char *config_type(config_param *configparam)
|
||||
static const char *print_bool(struct context **cnt, char **str ATTRIBUTE_UNUSED,
|
||||
int parm, unsigned short int threadnr)
|
||||
{
|
||||
int val=config_params[parm].conf_value;
|
||||
int val = config_params[parm].conf_value;
|
||||
|
||||
if (threadnr &&
|
||||
*(int*)((char *)cnt[threadnr] + val) == *(int*)((char *)cnt[0] + val))
|
||||
@@ -1920,7 +1920,7 @@ static const char *print_string(struct context **cnt,
|
||||
char **str ATTRIBUTE_UNUSED, int parm,
|
||||
unsigned short int threadnr)
|
||||
{
|
||||
int val=config_params[parm].conf_value;
|
||||
int val = config_params[parm].conf_value;
|
||||
const char **cptr0, **cptr1;
|
||||
|
||||
/* strcmp does not like NULL so we have to check for this also */
|
||||
@@ -1966,7 +1966,7 @@ static const char *print_thread(struct context **cnt, char **str,
|
||||
int parm ATTRIBUTE_UNUSED, unsigned short int threadnr)
|
||||
{
|
||||
char *retval;
|
||||
unsigned short int i=0;
|
||||
unsigned short int i = 0;
|
||||
|
||||
if (!str || threadnr)
|
||||
return NULL;
|
||||
@@ -2001,9 +2001,9 @@ static struct context **config_thread(struct context **cnt, const char *str,
|
||||
if (cnt[0]->threadnr)
|
||||
return cnt;
|
||||
|
||||
fp=fopen(str, "r");
|
||||
fp = fopen(str, "r");
|
||||
if (!fp) {
|
||||
motion_log(LOG_ERR, 1, "Thread config file %s not found",str);
|
||||
motion_log(LOG_ERR, 1, "Thread config file %s not found", str);
|
||||
return cnt;
|
||||
}
|
||||
|
||||
|
||||
12
conf.h
12
conf.h
@@ -135,12 +135,12 @@ typedef const char *(* conf_print_func)(struct context **, char **, int, unsigne
|
||||
* description for parameters in the config file
|
||||
*/
|
||||
typedef struct {
|
||||
const char * param_name; /* name for this parameter */
|
||||
const char * param_help; /* short explanation for parameter */
|
||||
unsigned short int main_thread; /* belong only to main thread when value>0 */
|
||||
int conf_value; /* pointer to a field in struct context */
|
||||
conf_copy_func copy; /* a function to set the value in 'config' */
|
||||
conf_print_func print; /* a function to output the value to a file */
|
||||
const char *param_name; /* name for this parameter */
|
||||
const char *param_help; /* short explanation for parameter */
|
||||
unsigned short int main_thread; /* belong only to main thread when value>0 */
|
||||
int conf_value; /* pointer to a field in struct context */
|
||||
conf_copy_func copy; /* a function to set the value in 'config' */
|
||||
conf_print_func print; /* a function to output the value to a file */
|
||||
} config_param;
|
||||
|
||||
|
||||
|
||||
20
configure
vendored
20
configure
vendored
@@ -1,6 +1,6 @@
|
||||
#! /bin/sh
|
||||
# Guess values for system-dependent variables and create Makefiles.
|
||||
# Generated by GNU Autoconf 2.61 for motion trunk-r339.
|
||||
# Generated by GNU Autoconf 2.61 for motion trunk-r343.
|
||||
#
|
||||
# Copyright (C) 1992, 1993, 1994, 1995, 1996, 1998, 1999, 2000, 2001,
|
||||
# 2002, 2003, 2004, 2005, 2006 Free Software Foundation, Inc.
|
||||
@@ -572,8 +572,8 @@ SHELL=${CONFIG_SHELL-/bin/sh}
|
||||
# Identity of this package.
|
||||
PACKAGE_NAME='motion'
|
||||
PACKAGE_TARNAME='motion'
|
||||
PACKAGE_VERSION='trunk-r339'
|
||||
PACKAGE_STRING='motion trunk-r339'
|
||||
PACKAGE_VERSION='trunk-r343'
|
||||
PACKAGE_STRING='motion trunk-r343'
|
||||
PACKAGE_BUGREPORT=''
|
||||
|
||||
ac_unique_file="motion.c"
|
||||
@@ -1178,7 +1178,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 trunk-r339 to adapt to many kinds of systems.
|
||||
\`configure' configures motion trunk-r343 to adapt to many kinds of systems.
|
||||
|
||||
Usage: $0 [OPTION]... [VAR=VALUE]...
|
||||
|
||||
@@ -1239,7 +1239,7 @@ fi
|
||||
|
||||
if test -n "$ac_init_help"; then
|
||||
case $ac_init_help in
|
||||
short | recursive ) echo "Configuration of motion trunk-r339:";;
|
||||
short | recursive ) echo "Configuration of motion trunk-r343:";;
|
||||
esac
|
||||
cat <<\_ACEOF
|
||||
|
||||
@@ -1375,7 +1375,7 @@ fi
|
||||
test -n "$ac_init_help" && exit $ac_status
|
||||
if $ac_init_version; then
|
||||
cat <<\_ACEOF
|
||||
motion configure trunk-r339
|
||||
motion configure trunk-r343
|
||||
generated by GNU Autoconf 2.61
|
||||
|
||||
Copyright (C) 1992, 1993, 1994, 1995, 1996, 1998, 1999, 2000, 2001,
|
||||
@@ -1389,7 +1389,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 trunk-r339, which was
|
||||
It was created by motion $as_me trunk-r343, which was
|
||||
generated by GNU Autoconf 2.61. Invocation command line was
|
||||
|
||||
$ $0 $@
|
||||
@@ -7108,7 +7108,7 @@ rm -f core conftest.err conftest.$ac_objext conftest_ipa8_conftest.oo \
|
||||
|
||||
|
||||
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"
|
||||
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 -gdwarf-2 -g3"
|
||||
fi
|
||||
|
||||
CFLAGS="${TEMP_CFLAGS} $UNAME_DEFS $CPU_OPTIONS"
|
||||
@@ -7538,7 +7538,7 @@ exec 6>&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 trunk-r339, which was
|
||||
This file was extended by motion $as_me trunk-r343, which was
|
||||
generated by GNU Autoconf 2.61. Invocation command line was
|
||||
|
||||
CONFIG_FILES = $CONFIG_FILES
|
||||
@@ -7587,7 +7587,7 @@ Report bugs to <bug-autoconf@gnu.org>."
|
||||
_ACEOF
|
||||
cat >>$CONFIG_STATUS <<_ACEOF
|
||||
ac_cs_version="\\
|
||||
motion config.status trunk-r339
|
||||
motion config.status trunk-r343
|
||||
configured by $0, generated by GNU Autoconf 2.61,
|
||||
with options \\"`echo "$ac_configure_args" | sed 's/^ //; s/[\\""\`\$]/\\\\&/g'`\\"
|
||||
|
||||
|
||||
@@ -1085,7 +1085,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"
|
||||
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 -gdwarf-2 -g3"
|
||||
fi
|
||||
|
||||
CFLAGS="${TEMP_CFLAGS} $UNAME_DEFS $CPU_OPTIONS"
|
||||
|
||||
34
draw.c
34
draw.c
@@ -1081,26 +1081,26 @@ static int draw_textn (unsigned char *image, int startx, int starty, int width,
|
||||
int pos, x, y, line_offset, next_char_offs;
|
||||
unsigned char *image_ptr, *char_ptr, **char_arr_ptr;
|
||||
|
||||
if (startx>width/2)
|
||||
startx -= len*(6*(factor+1));
|
||||
if (startx > width / 2)
|
||||
startx -= len * (6 * (factor + 1));
|
||||
|
||||
if (startx < 0)
|
||||
startx = 0;
|
||||
|
||||
if (startx+len*6*(factor+1) >= width)
|
||||
if (startx + len * 6 * (factor + 1) >= width)
|
||||
len = (width-startx-1)/(6*(factor+1));
|
||||
|
||||
line_offset = width - 7*(factor+1);
|
||||
next_char_offs = width*8*(factor+1) - 6*(factor+1);
|
||||
line_offset = width - 7 * (factor + 1);
|
||||
next_char_offs = width * 8 * (factor + 1) - 6 * (factor + 1);
|
||||
|
||||
image_ptr = image + startx + starty*width;
|
||||
image_ptr = image + startx + starty * width;
|
||||
|
||||
char_arr_ptr = factor ? big_char_arr_ptr : small_char_arr_ptr;
|
||||
|
||||
for (pos = 0; pos < len; pos++) {
|
||||
char_ptr = char_arr_ptr[(int)text[pos]];
|
||||
for (y=8*(factor+1); y--;) {
|
||||
for (x=7*(factor+1); x--;) {
|
||||
for (y = 8 * (factor + 1); y--; ) {
|
||||
for (x = 7 * (factor + 1); x--; ) {
|
||||
switch(*char_ptr) {
|
||||
case 1:
|
||||
*image_ptr = 0;
|
||||
@@ -1149,13 +1149,13 @@ int draw_text (unsigned char *image, int startx, int starty, int width, const ch
|
||||
|
||||
int initialize_chars(void)
|
||||
{
|
||||
unsigned int i=0, x, y;
|
||||
unsigned int i = 0, x, y;
|
||||
|
||||
/* Fill the structure 'big_table' with double sized characters. */
|
||||
while(draw_table[i].ascii) {
|
||||
big_table[i].ascii = draw_table[i].ascii;
|
||||
for(x=0; x < 14; x++) {
|
||||
for(y=0; y < 16; y++) {
|
||||
for(x = 0; x < 14; x++) {
|
||||
for(y = 0; y < 16; y++) {
|
||||
big_table[i].pix[y][x] = draw_table[i].pix[y/2][x/2];
|
||||
}
|
||||
}
|
||||
@@ -1163,15 +1163,15 @@ int initialize_chars(void)
|
||||
}
|
||||
|
||||
/* 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];
|
||||
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 */
|
||||
for (i=0; i < sizeof(draw_table) / sizeof(struct draw_char); 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];
|
||||
for (i = 0; i < sizeof(draw_table) / sizeof(struct draw_char); 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];
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
73
event.c
73
event.c
@@ -10,7 +10,6 @@
|
||||
*/
|
||||
|
||||
#include "ffmpeg.h" /* must be first to avoid 'shadow' warning */
|
||||
//#include "motion.h"
|
||||
#include "picture.h" /* already includes motion.h */
|
||||
#include "event.h"
|
||||
#if (!defined(BSD))
|
||||
@@ -340,8 +339,8 @@ static void event_camera_lost(struct context *cnt, int type ATTRIBUTE_UNUSED,
|
||||
#ifdef HAVE_FFMPEG
|
||||
static void grey2yuv420p(unsigned char *u, unsigned char *v, int width, int height)
|
||||
{
|
||||
memset(u, 128, width*height/4);
|
||||
memset(v, 128, width*height/4);
|
||||
memset(u, 128, width * height / 4);
|
||||
memset(v, 128, width * height / 4);
|
||||
}
|
||||
|
||||
static void on_movie_end_command(struct context *cnt, int type ATTRIBUTE_UNUSED,
|
||||
@@ -358,8 +357,8 @@ static void event_ffmpeg_newfile(struct context *cnt, int type ATTRIBUTE_UNUSED,
|
||||
unsigned char *img, char *dummy1 ATTRIBUTE_UNUSED,
|
||||
void *dummy2 ATTRIBUTE_UNUSED, struct tm *currenttime_tm)
|
||||
{
|
||||
int width=cnt->imgs.width;
|
||||
int height=cnt->imgs.height;
|
||||
int width = cnt->imgs.width;
|
||||
int height = cnt->imgs.height;
|
||||
unsigned char *convbuf, *y, *u, *v;
|
||||
char stamp[PATH_MAX];
|
||||
const char *mpegpath;
|
||||
@@ -371,7 +370,7 @@ static void event_ffmpeg_newfile(struct context *cnt, int type ATTRIBUTE_UNUSED,
|
||||
cnt->movie_fps = cnt->lastrate;
|
||||
|
||||
if (debug_level >= CAMERA_DEBUG)
|
||||
motion_log(LOG_DEBUG, 0, "%s FPS %d",__FUNCTION__,cnt->movie_fps);
|
||||
motion_log(LOG_DEBUG, 0, "%s FPS %d", __FUNCTION__, cnt->movie_fps);
|
||||
|
||||
if (cnt->movie_fps > 30)
|
||||
cnt->movie_fps = 30;
|
||||
@@ -393,41 +392,41 @@ static void event_ffmpeg_newfile(struct context *cnt, int type ATTRIBUTE_UNUSED,
|
||||
snprintf(cnt->newfilename, PATH_MAX - 4, "%s/%s", cnt->conf.filepath, stamp);
|
||||
|
||||
if (cnt->conf.ffmpeg_cap_new) {
|
||||
if (cnt->imgs.type==VIDEO_PALETTE_GREY) {
|
||||
convbuf=mymalloc((width*height)/2);
|
||||
y=img;
|
||||
u=convbuf;
|
||||
v=convbuf+(width*height)/4;
|
||||
if (cnt->imgs.type == VIDEO_PALETTE_GREY) {
|
||||
convbuf = mymalloc((width * height) / 2);
|
||||
y = img;
|
||||
u = convbuf;
|
||||
v = convbuf + (width * height) / 4;
|
||||
grey2yuv420p(u, v, width, height);
|
||||
} else {
|
||||
convbuf=NULL;
|
||||
y=img;
|
||||
u=img+width*height;
|
||||
v=u+(width*height)/4;
|
||||
convbuf = NULL;
|
||||
y = img;
|
||||
u = img + width * height;
|
||||
v = u + (width * height) / 4;
|
||||
}
|
||||
if ( (cnt->ffmpeg_new =
|
||||
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(LOG_ERR, 1, "ffopen_open error creating (new) file [%s]",cnt->newfilename);
|
||||
cnt->finish=1;
|
||||
motion_log(LOG_ERR, 1, "ffopen_open error creating (new) file [%s]", cnt->newfilename);
|
||||
cnt->finish = 1;
|
||||
return;
|
||||
}
|
||||
((struct ffmpeg *)cnt->ffmpeg_new)->udata=convbuf;
|
||||
((struct ffmpeg *)cnt->ffmpeg_new)->udata = convbuf;
|
||||
event(cnt, EVENT_FILECREATE, NULL, cnt->newfilename, (void *)FTYPE_MPEG, NULL);
|
||||
}
|
||||
if (cnt->conf.ffmpeg_cap_motion) {
|
||||
if (cnt->imgs.type==VIDEO_PALETTE_GREY) {
|
||||
convbuf=mymalloc((width*height)/2);
|
||||
y=cnt->imgs.out;
|
||||
u=convbuf;
|
||||
v=convbuf+(width*height)/4;
|
||||
if (cnt->imgs.type == VIDEO_PALETTE_GREY) {
|
||||
convbuf = mymalloc((width * height) / 2);
|
||||
y = cnt->imgs.out;
|
||||
u = convbuf;
|
||||
v = convbuf + (width * height) / 4;
|
||||
grey2yuv420p(u, v, width, height);
|
||||
} else {
|
||||
y=cnt->imgs.out;
|
||||
u=cnt->imgs.out+width*height;
|
||||
v=u+(width*height)/4;
|
||||
convbuf=NULL;
|
||||
y = cnt->imgs.out;
|
||||
u = cnt->imgs.out + width *height;
|
||||
v = u + (width * height) / 4;
|
||||
convbuf = NULL;
|
||||
}
|
||||
|
||||
if ( (cnt->ffmpeg_motion =
|
||||
@@ -435,10 +434,10 @@ static void event_ffmpeg_newfile(struct context *cnt, int type ATTRIBUTE_UNUSED,
|
||||
cnt->imgs.width, cnt->imgs.height, cnt->movie_fps, cnt->conf.ffmpeg_bps,
|
||||
cnt->conf.ffmpeg_vbr)) == NULL){
|
||||
motion_log(LOG_ERR, 1, "ffopen_open error creating (motion) file [%s]", cnt->motionfilename);
|
||||
cnt->finish=1;
|
||||
cnt->finish = 1;
|
||||
return;
|
||||
}
|
||||
cnt->ffmpeg_motion->udata=convbuf;
|
||||
cnt->ffmpeg_motion->udata = convbuf;
|
||||
event(cnt, EVENT_FILECREATE, NULL, cnt->motionfilename, (void *)FTYPE_MPEG_MOTION, NULL);
|
||||
}
|
||||
}
|
||||
@@ -469,16 +468,16 @@ static void event_ffmpeg_timelapse(struct context *cnt,
|
||||
snprintf(cnt->timelapsefilename, PATH_MAX - 4, "%s/%s", cnt->conf.filepath, tmp);
|
||||
|
||||
if (cnt->imgs.type == VIDEO_PALETTE_GREY) {
|
||||
convbuf = mymalloc((width*height)/2);
|
||||
convbuf = mymalloc((width * height) / 2);
|
||||
y = img;
|
||||
u = convbuf;
|
||||
v = convbuf+(width*height)/4;
|
||||
v = convbuf + (width * height) / 4;
|
||||
grey2yuv420p(u, v, width, height);
|
||||
} else {
|
||||
convbuf = NULL;
|
||||
y = img;
|
||||
u = img+width*height;
|
||||
v = u+(width*height)/4;
|
||||
u = img + width * height;
|
||||
v = u + (width * height) / 4;
|
||||
}
|
||||
|
||||
if ( (cnt->ffmpeg_timelapse =
|
||||
@@ -486,7 +485,7 @@ static void event_ffmpeg_timelapse(struct context *cnt,
|
||||
cnt->imgs.width, cnt->imgs.height, 24, cnt->conf.ffmpeg_bps,
|
||||
cnt->conf.ffmpeg_vbr)) == NULL) {
|
||||
motion_log(LOG_ERR, 1, "ffopen_open error creating (timelapse) file [%s]", cnt->timelapsefilename);
|
||||
cnt->finish=1;
|
||||
cnt->finish = 1;
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -499,7 +498,7 @@ static void event_ffmpeg_timelapse(struct context *cnt,
|
||||
if (cnt->imgs.type == VIDEO_PALETTE_GREY)
|
||||
u = cnt->ffmpeg_timelapse->udata;
|
||||
else
|
||||
u = img+width*height;
|
||||
u = img + width * height;
|
||||
|
||||
v = u+(width*height)/4;
|
||||
if (ffmpeg_put_other_image(cnt->ffmpeg_timelapse, y, u, v) == -1){
|
||||
@@ -515,8 +514,8 @@ static void event_ffmpeg_put(struct context *cnt, int type ATTRIBUTE_UNUSED,
|
||||
{
|
||||
if (cnt->ffmpeg_new)
|
||||
{
|
||||
int width=cnt->imgs.width;
|
||||
int height=cnt->imgs.height;
|
||||
int width = cnt->imgs.width;
|
||||
int height = cnt->imgs.height;
|
||||
unsigned char *y = img;
|
||||
unsigned char *u, *v;
|
||||
|
||||
|
||||
8
ffmpeg.c
8
ffmpeg.c
@@ -382,7 +382,7 @@ struct ffmpeg *ffmpeg_open(char *ffmpeg_video_codec, char *filename,
|
||||
#endif /* LIBAVCODEC_BUILD >= 4754 */
|
||||
|
||||
if (debug_level >= CAMERA_DEBUG)
|
||||
motion_log(LOG_DEBUG, 0, "%s FPS %d",__FUNCTION__,rate);
|
||||
motion_log(LOG_DEBUG, 0, "%s FPS %d", __FUNCTION__, rate);
|
||||
|
||||
if (vbr)
|
||||
c->flags |= CODEC_FLAG_QSCALE;
|
||||
@@ -489,7 +489,7 @@ struct ffmpeg *ffmpeg_open(char *ffmpeg_video_codec, char *filename,
|
||||
|
||||
/* and retry opening the file (use file_proto) */
|
||||
if (url_fopen(&ffmpeg->oc->pb, file_proto, URL_WRONLY) < 0) {
|
||||
motion_log(LOG_ERR, 1, "url_fopen - error opening file %s",filename);
|
||||
motion_log(LOG_ERR, 1, "url_fopen - error opening file %s", filename);
|
||||
ffmpeg_cleanups(ffmpeg);
|
||||
return (NULL);
|
||||
}
|
||||
@@ -735,8 +735,8 @@ void ffmpeg_deinterlace(unsigned char *img, int width, int height)
|
||||
}
|
||||
|
||||
picture->data[0] = img;
|
||||
picture->data[1] = img+width*height;
|
||||
picture->data[2] = picture->data[1]+(width*height)/4;
|
||||
picture->data[1] = img + width * height;
|
||||
picture->data[2] = picture->data[1] + (width * height) / 4;
|
||||
picture->linesize[0] = width;
|
||||
picture->linesize[1] = width2;
|
||||
picture->linesize[2] = width2;
|
||||
|
||||
44
motion.c
44
motion.c
@@ -48,7 +48,7 @@ pthread_mutex_t global_lock;
|
||||
*
|
||||
* List of context structures, one for each main Motion thread.
|
||||
*/
|
||||
struct context **cnt_list=NULL;
|
||||
struct context **cnt_list = NULL;
|
||||
|
||||
/**
|
||||
* threads_running
|
||||
@@ -56,7 +56,7 @@ struct context **cnt_list=NULL;
|
||||
* Keeps track of number of Motion threads currently running. Also used
|
||||
* by 'main' to know when all threads have exited.
|
||||
*/
|
||||
volatile int threads_running=0;
|
||||
volatile int threads_running = 0;
|
||||
|
||||
/*
|
||||
* debug_level is for developers, normally used to control which
|
||||
@@ -66,7 +66,7 @@ unsigned short int debug_level;
|
||||
|
||||
/* Set this when we want main to end or restart
|
||||
*/
|
||||
volatile unsigned short int finish=0;
|
||||
volatile unsigned short int finish = 0;
|
||||
|
||||
/**
|
||||
* restart
|
||||
@@ -75,7 +75,7 @@ volatile unsigned short int finish=0;
|
||||
* finished running, 'main' checks if 'restart' is true and if so starts
|
||||
* up again (instead of just quitting).
|
||||
*/
|
||||
unsigned short int restart=0;
|
||||
unsigned short int restart = 0;
|
||||
|
||||
/**
|
||||
* image_ring_resize
|
||||
@@ -288,7 +288,7 @@ static void sig_handler(int signo)
|
||||
i = -1;
|
||||
while (cnt_list[++i]) {
|
||||
if (cnt_list[i]->conf.snapshot_interval) {
|
||||
cnt_list[i]->snapshot=1;
|
||||
cnt_list[i]->snapshot = 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -299,7 +299,7 @@ static void sig_handler(int signo)
|
||||
if (cnt_list) {
|
||||
i = -1;
|
||||
while (cnt_list[++i])
|
||||
cnt_list[i]->makemovie=1;
|
||||
cnt_list[i]->makemovie = 1;
|
||||
}
|
||||
break;
|
||||
case SIGHUP:
|
||||
@@ -315,12 +315,12 @@ static void sig_handler(int signo)
|
||||
if (cnt_list) {
|
||||
i = -1;
|
||||
while (cnt_list[++i]) {
|
||||
cnt_list[i]->makemovie=1;
|
||||
cnt_list[i]->finish=1;
|
||||
cnt_list[i]->makemovie = 1;
|
||||
cnt_list[i]->finish = 1;
|
||||
/* don't restart thread when it ends,
|
||||
* all threads restarts if global restart is set
|
||||
*/
|
||||
cnt_list[i]->restart=0;
|
||||
cnt_list[i]->restart = 0;
|
||||
}
|
||||
}
|
||||
/* Set flag we want to quit main check threads loop
|
||||
@@ -676,7 +676,7 @@ static int motion_init(struct context *cnt)
|
||||
for (i = 0; i < 5; i++) {
|
||||
if (vid_next(cnt, cnt->imgs.image_virgin) == 0)
|
||||
break;
|
||||
SLEEP(2,0);
|
||||
SLEEP(2, 0);
|
||||
}
|
||||
if (i >= 5) {
|
||||
memset(cnt->imgs.image_virgin, 0x80, cnt->imgs.size); /* initialize to grey */
|
||||
@@ -795,7 +795,7 @@ static int motion_init(struct context *cnt)
|
||||
motion_log(LOG_INFO, 0, "Maskfile \"%s\" loaded.",cnt->conf.mask_file);
|
||||
}
|
||||
} else
|
||||
cnt->imgs.mask=NULL;
|
||||
cnt->imgs.mask = NULL;
|
||||
|
||||
/* Always initialize smart_mask - someone could turn it on later... */
|
||||
memset(cnt->imgs.smartmask, 0, cnt->imgs.motionsize);
|
||||
@@ -950,10 +950,10 @@ static void *motion_loop(void *arg)
|
||||
unsigned short int get_image = 1; /* Flag used to signal that we capture new image when we run the loop */
|
||||
|
||||
/* Next two variables are used for snapshot and timelapse feature
|
||||
* time_last_frame is set to 1 so that first coming timelapse or second=0
|
||||
* time_last_frame is set to 1 so that first coming timelapse or second = 0
|
||||
* is acted upon.
|
||||
*/
|
||||
unsigned long int time_last_frame=1, time_current_frame;
|
||||
unsigned long int time_last_frame = 1, time_current_frame;
|
||||
|
||||
cnt->running = 1;
|
||||
|
||||
@@ -991,8 +991,8 @@ static void *motion_loop(void *arg)
|
||||
rolling_average_data = mymalloc(sizeof(rolling_average_data) * rolling_average_limit);
|
||||
|
||||
/* Preset history buffer with expected frame rate */
|
||||
for (j=0; j< rolling_average_limit; j++)
|
||||
rolling_average_data[j]=required_frame_time;
|
||||
for (j = 0; j < rolling_average_limit; j++)
|
||||
rolling_average_data[j] = required_frame_time;
|
||||
|
||||
|
||||
/* MAIN MOTION LOOP BEGINS HERE */
|
||||
@@ -1868,7 +1868,7 @@ static void *motion_loop(void *arg)
|
||||
/* Calculate 10 second average and use deviation in delay calculation */
|
||||
rolling_average = 0L;
|
||||
|
||||
for (j=0; j < rolling_average_limit; j++)
|
||||
for (j = 0; j < rolling_average_limit; j++)
|
||||
rolling_average += rolling_average_data[j];
|
||||
|
||||
rolling_average /= rolling_average_limit;
|
||||
@@ -1907,7 +1907,7 @@ err:
|
||||
pthread_mutex_unlock(&global_lock);
|
||||
|
||||
if (!cnt->restart)
|
||||
cnt->watchdog=WATCHDOG_OFF;
|
||||
cnt->watchdog = WATCHDOG_OFF;
|
||||
cnt->running = 0;
|
||||
cnt->finish = 0;
|
||||
|
||||
@@ -2179,7 +2179,7 @@ static void start_motion_thread(struct context *cnt, pthread_attr_t *thread_attr
|
||||
/* Check the webcam port number for conflicts.
|
||||
* First we check for conflict with the control port.
|
||||
* Second we check for that two threads does not use the same port number
|
||||
* for the webcam. If a duplicate port is found the webcam feature gets disabled (port =0)
|
||||
* for the webcam. If a duplicate port is found the webcam feature gets disabled (port = 0)
|
||||
* for this thread and a warning is written to console and syslog.
|
||||
*/
|
||||
|
||||
@@ -2292,7 +2292,7 @@ int main (int argc, char **argv)
|
||||
restart = 0; /* only one reset for now */
|
||||
motion_log(LOG_INFO,0,"motion restarted");
|
||||
#ifndef WITHOUT_V4L
|
||||
SLEEP(5,0); // maybe some cameras needs less time
|
||||
SLEEP(5, 0); // maybe some cameras needs less time
|
||||
#endif
|
||||
motion_startup(0, argc, argv); /* 0 = skip daemon init */
|
||||
}
|
||||
@@ -2334,7 +2334,7 @@ int main (int argc, char **argv)
|
||||
* counter (because we cannot do join on the detached threads).
|
||||
*/
|
||||
while (1) {
|
||||
SLEEP(1,0);
|
||||
SLEEP(1, 0);
|
||||
|
||||
/* Calculate how many threads runnig or wants to run
|
||||
* if zero and we want to finish, break out
|
||||
@@ -2390,13 +2390,13 @@ int main (int argc, char **argv)
|
||||
|
||||
/* Rest for a while if we're supposed to restart. */
|
||||
if (restart)
|
||||
SLEEP(2,0);
|
||||
SLEEP(2, 0);
|
||||
|
||||
} while (restart); /* loop if we're supposed to restart */
|
||||
|
||||
// Be sure that http control exits fine
|
||||
cnt_list[0]->finish = 1;
|
||||
SLEEP(1,0);
|
||||
SLEEP(1, 0);
|
||||
motion_log(LOG_INFO, 0, "Motion terminating");
|
||||
|
||||
/* Perform final cleanup. */
|
||||
|
||||
28
motion.h
28
motion.h
@@ -134,14 +134,14 @@
|
||||
* and then we show a grey image instead
|
||||
*/
|
||||
|
||||
#define WATCHDOG_TMO 30 /* 10 sec max motion_loop interval */
|
||||
#define WATCHDOG_OFF -127 /* Turn off watchdog, used when we wants to quit a thread */
|
||||
#define WATCHDOG_TMO 30 /* 10 sec max motion_loop interval */
|
||||
#define WATCHDOG_OFF -127 /* Turn off watchdog, used when we wants to quit a thread */
|
||||
|
||||
#define CONNECTION_KO "Lost connection"
|
||||
#define CONNECTION_OK "Connection OK"
|
||||
|
||||
#define DEF_MAXSTREAMS 10 /* Maximum number of webcam clients per camera */
|
||||
#define DEF_MAXWEBQUEUE 10 /* Maximum number of webcam client in queue */
|
||||
#define DEF_MAXSTREAMS 10 /* Maximum number of webcam clients per camera */
|
||||
#define DEF_MAXWEBQUEUE 10 /* Maximum number of webcam client in queue */
|
||||
|
||||
#define DEF_TIMESTAMP "%Y-%m-%d\\n%T"
|
||||
#define DEF_EVENTSTAMP "%Y%m%d%H%M%S"
|
||||
@@ -207,15 +207,15 @@ struct images;
|
||||
struct image_data {
|
||||
unsigned char *image;
|
||||
int diffs;
|
||||
time_t timestamp; /* Timestamp when image was captured */
|
||||
time_t timestamp; /* Timestamp when image was captured */
|
||||
struct tm timestamp_tm;
|
||||
int shot; /* Sub second timestamp count */
|
||||
int shot; /* Sub second timestamp count */
|
||||
|
||||
/* movement center to img center distance
|
||||
* Note Dist is calculated distX*distX + distY*distY */
|
||||
unsigned long cent_dist;
|
||||
|
||||
unsigned int flags; /* Se IMAGE_* defines */
|
||||
unsigned int flags; /* Se IMAGE_* defines */
|
||||
|
||||
struct coord location; /* coordinates for center and size of last motion detection*/
|
||||
|
||||
@@ -310,11 +310,11 @@ struct context {
|
||||
struct images imgs;
|
||||
struct trackoptions track;
|
||||
struct netcam_context *netcam;
|
||||
struct image_data *current_image; /* Pointer to a structure where the image, diffs etc is stored */
|
||||
struct image_data *current_image; /* Pointer to a structure where the image, diffs etc is stored */
|
||||
unsigned short int new_img;
|
||||
|
||||
int locate;
|
||||
struct rotdata rotate_data; /* rotation data is thread-specific */
|
||||
struct rotdata rotate_data; /* rotation data is thread-specific */
|
||||
|
||||
int noise;
|
||||
int threshold;
|
||||
@@ -335,9 +335,9 @@ struct context {
|
||||
int event_nr;
|
||||
int prev_event;
|
||||
int lightswitch_framecounter;
|
||||
char text_event_string[PATH_MAX]; /* The text for conv. spec. %C -
|
||||
we assume PATH_MAX normally 4096 characters is fine */
|
||||
int postcap; /* downcounter, frames left to to send post event */
|
||||
char text_event_string[PATH_MAX]; /* The text for conv. spec. %C -
|
||||
we assume PATH_MAX normally 4096 characters is fine */
|
||||
int postcap; /* downcounter, frames left to to send post event */
|
||||
|
||||
short int shots;
|
||||
unsigned short int detecting_motion;
|
||||
@@ -347,13 +347,13 @@ struct context {
|
||||
time_t currenttime;
|
||||
time_t lasttime;
|
||||
time_t eventtime;
|
||||
time_t connectionlosttime; /* timestamp from connection lost */
|
||||
time_t connectionlosttime; /* timestamp from connection lost */
|
||||
|
||||
int lastrate;
|
||||
unsigned short int startup_frames;
|
||||
unsigned short int moved;
|
||||
unsigned short int pause;
|
||||
int missing_frame_counter; /* counts failed attempts to fetch picture frame from camera */
|
||||
int missing_frame_counter; /* counts failed attempts to fetch picture frame from camera */
|
||||
unsigned short int lost_connection;
|
||||
|
||||
#if (defined(BSD))
|
||||
|
||||
76
netcam.c
76
netcam.c
@@ -42,11 +42,7 @@
|
||||
#include <netdb.h>
|
||||
#include <netinet/in.h>
|
||||
#include <regex.h> /* For parsing of the URL */
|
||||
//#include <stdio.h>
|
||||
//#include <stdlib.h>
|
||||
//#include <string.h>
|
||||
#include <sys/socket.h>
|
||||
//#include <sys/types.h>
|
||||
|
||||
#include "netcam_ftp.h"
|
||||
|
||||
@@ -211,7 +207,7 @@ static void netcam_url_parse(struct url_t *parse_url, const char *text_url)
|
||||
}
|
||||
}
|
||||
}
|
||||
if ((!parse_url->port) && (parse_url->service)){
|
||||
if ((!parse_url->port) && (parse_url->service)) {
|
||||
if (!strcmp(parse_url->service, "http"))
|
||||
parse_url->port = 80;
|
||||
else if (!strcmp(parse_url->service, "ftp"))
|
||||
@@ -363,13 +359,13 @@ static int netcam_check_keepalive(char *header)
|
||||
static int netcam_check_close(char *header)
|
||||
{
|
||||
char *type = NULL;
|
||||
int ret=-1;
|
||||
int ret = -1;
|
||||
|
||||
if (!header_process(header, "Connection", http_process_type, &type))
|
||||
return -1;
|
||||
|
||||
if (!strcmp(type, "close")) /* strcmp returns 0 for match */
|
||||
ret=1;
|
||||
ret = 1;
|
||||
|
||||
if (type)
|
||||
free(type);
|
||||
@@ -697,7 +693,7 @@ static int netcam_read_first_header(netcam_context_ptr netcam)
|
||||
* If we are a non-streaming (ie. Jpeg) netcam and keepalive is configured
|
||||
*/
|
||||
|
||||
if (aliveflag){
|
||||
if (aliveflag) {
|
||||
if (closeflag) {
|
||||
/*
|
||||
* If not a streaming cam, and keepalive is set, and the flag shows we
|
||||
@@ -706,7 +702,7 @@ static int netcam_read_first_header(netcam_context_ptr netcam)
|
||||
*/
|
||||
motion_log(LOG_INFO, 0, "Info: Both 'Connection: Keep-Alive' and 'Connection: close' "
|
||||
"header received. Motion continues unchanged.");
|
||||
}else{
|
||||
} else {
|
||||
/* aliveflag && !closeflag
|
||||
*
|
||||
* If not a streaming cam, and keepalive is set, and the flag shows we
|
||||
@@ -717,7 +713,7 @@ static int netcam_read_first_header(netcam_context_ptr netcam)
|
||||
if (debug_level > CAMERA_INFO)
|
||||
motion_log(LOG_INFO, 0, "Info: Received a Keep-Alive field in this set of headers.");
|
||||
}
|
||||
}else{ /* !aliveflag */
|
||||
} else { /* !aliveflag */
|
||||
if (!closeflag) {
|
||||
/*
|
||||
* If not a streaming cam, and keepalive is set, and the flag shows we
|
||||
@@ -812,7 +808,7 @@ static int netcam_connect(netcam_context_ptr netcam, int err_flag)
|
||||
int saveflags;
|
||||
int back_err;
|
||||
int optval;
|
||||
socklen_t optlen=sizeof(optval);
|
||||
socklen_t optlen = sizeof(optval);
|
||||
socklen_t len;
|
||||
fd_set fd_w;
|
||||
struct timeval selecttime;
|
||||
@@ -820,16 +816,16 @@ static int netcam_connect(netcam_context_ptr netcam, int err_flag)
|
||||
/* Assure any previous connection has been closed - IF we are not in keepalive */
|
||||
if (!netcam->connect_keepalive) {
|
||||
if (debug_level > CAMERA_INFO )
|
||||
motion_log(LOG_DEBUG, 0, "netcam_connect, disconnecting netcam since keep-alive not set." );
|
||||
netcam_disconnect(netcam);
|
||||
motion_log(LOG_DEBUG, 0, "netcam_connect, disconnecting netcam since keep-alive not set." );
|
||||
netcam_disconnect(netcam);
|
||||
|
||||
/* create a new socket */
|
||||
if ((netcam->sock = socket(PF_INET, SOCK_STREAM, 0)) < 0) {
|
||||
motion_log(LOG_ERR, 1, "netcam_connect with no keepalive, attempt to create socket failed.");
|
||||
return -1;
|
||||
}
|
||||
if (debug_level > CAMERA_INFO )
|
||||
motion_log(LOG_DEBUG, 0, "netcam_connect with no keepalive, new socket created fd %d", netcam->sock);
|
||||
if ((netcam->sock = socket(PF_INET, SOCK_STREAM, 0)) < 0) {
|
||||
motion_log(LOG_ERR, 1, "netcam_connect with no keepalive, attempt to create socket failed.");
|
||||
return -1;
|
||||
}
|
||||
if (debug_level > CAMERA_INFO )
|
||||
motion_log(LOG_DEBUG, 0, "netcam_connect with no keepalive, new socket created fd %d", netcam->sock);
|
||||
} else { /* We are in keepalive mode, check for invalid socket */
|
||||
if (netcam->sock == -1) {
|
||||
/* Must be first time, or closed, create a new socket */
|
||||
@@ -851,11 +847,11 @@ static int netcam_connect(netcam_context_ptr netcam, int err_flag)
|
||||
return -1;
|
||||
}
|
||||
if (debug_level > CAMERA_INFO) {
|
||||
if (optval==1)
|
||||
if (optval == 1)
|
||||
motion_log(LOG_DEBUG, 0, "netcam_connect: SO_KEEPALIVE is ON");
|
||||
else
|
||||
motion_log(LOG_DEBUG, 0, "netcam_connect: SO_KEEPALIVE is OFF");
|
||||
}
|
||||
}
|
||||
|
||||
/* Set the option active */
|
||||
optval = 1;
|
||||
@@ -1393,9 +1389,9 @@ static int netcam_read_ftp_jpeg(netcam_context_ptr netcam)
|
||||
*/
|
||||
static int netcam_read_file_jpeg(netcam_context_ptr netcam)
|
||||
{
|
||||
int loop_counter=0;
|
||||
int loop_counter = 0;
|
||||
if (debug_level > CAMERA_VERBOSE) {
|
||||
motion_log(-1,0,"Begin %s", __FUNCTION__);
|
||||
motion_log(-1, 0, "Begin %s", __FUNCTION__);
|
||||
}
|
||||
netcam_buff_ptr buffer;
|
||||
int len;
|
||||
@@ -1433,7 +1429,7 @@ static int netcam_read_file_jpeg(netcam_context_ptr netcam)
|
||||
/*return -1;*/
|
||||
loop_counter++;
|
||||
|
||||
} while(statbuf.st_mtime==netcam->file->last_st_mtime);
|
||||
} while(statbuf.st_mtime == netcam->file->last_st_mtime);
|
||||
|
||||
netcam->file->last_st_mtime = statbuf.st_mtime;
|
||||
if (debug_level > CAMERA_INFO) {
|
||||
@@ -1507,7 +1503,7 @@ static int netcam_read_file_jpeg(netcam_context_ptr netcam)
|
||||
pthread_mutex_unlock(&netcam->mutex);
|
||||
|
||||
if (debug_level > CAMERA_VERBOSE) {
|
||||
motion_log(-1,0,"End %s", __FUNCTION__);
|
||||
motion_log(-1, 0, "End %s", __FUNCTION__);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
@@ -1550,7 +1546,7 @@ static int netcam_setup_file(netcam_context_ptr netcam, struct url_t *url) {
|
||||
url->path = NULL;
|
||||
|
||||
if (debug_level > CAMERA_INFO)
|
||||
motion_log(LOG_INFO, 0, "netcam_setup_file: netcam->file->path %s",netcam->file->path);
|
||||
motion_log(LOG_INFO, 0, "netcam_setup_file: netcam->file->path %s", netcam->file->path);
|
||||
|
||||
netcam_url_free(url);
|
||||
|
||||
@@ -1617,7 +1613,7 @@ static void *netcam_handler_loop(void *arg)
|
||||
open_error = 1;
|
||||
}
|
||||
/* need to have a dynamic delay here */
|
||||
SLEEP(5,0);
|
||||
SLEEP(5, 0);
|
||||
continue;
|
||||
}
|
||||
if (open_error) { /* log re-connection */
|
||||
@@ -1629,11 +1625,9 @@ static void *netcam_handler_loop(void *arg)
|
||||
/* Send our request and look at the response */
|
||||
if ((retval = netcam_read_first_header(netcam)) != 1) {
|
||||
if (retval > 0) {
|
||||
motion_log(LOG_ERR, 0,
|
||||
"Unrecognized image header (%d)", retval);
|
||||
motion_log(LOG_ERR, 0, "Unrecognized image header (%d)", retval);
|
||||
} else if (retval != -1) {
|
||||
motion_log(LOG_ERR, 0,
|
||||
"Error in header (%d)", retval);
|
||||
motion_log(LOG_ERR, 0, "Error in header (%d)", retval);
|
||||
}
|
||||
/* need to have a dynamic delay here */
|
||||
continue;
|
||||
@@ -1646,7 +1640,7 @@ static void *netcam_handler_loop(void *arg)
|
||||
"re-opening camera (streaming)");
|
||||
open_error = 1;
|
||||
}
|
||||
SLEEP(5,0);
|
||||
SLEEP(5, 0);
|
||||
continue;
|
||||
}
|
||||
|
||||
@@ -1823,7 +1817,7 @@ static int netcam_setup_html(netcam_context_ptr netcam, struct url_t *url) {
|
||||
ptr = mymalloc(strlen(url->service) + strlen(url->host)
|
||||
+ strlen(url->path) + 4);
|
||||
sprintf((char *)ptr, "http://%s%s", url->host, url->path);
|
||||
netcam->connect_keepalive=0; /* Disable Keepalive if proxy */
|
||||
netcam->connect_keepalive = 0; /* Disable Keepalive if proxy */
|
||||
if (debug_level > CAMERA_INFO)
|
||||
motion_log(LOG_DEBUG, 0, "Removed netcam_keepalive flag due to proxy set."
|
||||
"Proxy is incompatible with Keep-Alive.");
|
||||
@@ -1911,7 +1905,7 @@ static int netcam_setup_html(netcam_context_ptr netcam, struct url_t *url) {
|
||||
if (debug_level > CAMERA_INFO)
|
||||
motion_log(-1, 0, "netcam_setup_html: about to try to connect, time #%d", ix );
|
||||
if (netcam_connect(netcam, 0) != 0) {
|
||||
motion_log(LOG_ERR, 0,"Failed to open camera - check your config and that netcamera is online");
|
||||
motion_log(LOG_ERR, 0, "Failed to open camera - check your config and that netcamera is online");
|
||||
|
||||
/* Fatal error on startup */
|
||||
ix = MAX_HEADER_RETRIES;
|
||||
@@ -1975,7 +1969,7 @@ static int netcam_setup_ftp(netcam_context_ptr netcam, struct url_t *url) {
|
||||
netcam->ftp->user = strdup(ptr);
|
||||
else {
|
||||
netcam->ftp->user = mymalloc((cptr - ptr));
|
||||
memcpy(netcam->ftp->user,ptr,(cptr - ptr));
|
||||
memcpy(netcam->ftp->user, ptr,(cptr - ptr));
|
||||
netcam->ftp->passwd = strdup(cptr + 1);
|
||||
}
|
||||
}
|
||||
@@ -2368,15 +2362,15 @@ int netcam_start(struct context *cnt)
|
||||
* in the context structures (cnt->...) only.
|
||||
*/
|
||||
|
||||
if (!strcmp(cnt->conf.netcam_http,"keep_alive")) {
|
||||
if (!strcmp(cnt->conf.netcam_http, "keep_alive")) {
|
||||
netcam->connect_http_10 = TRUE;
|
||||
netcam->connect_http_11 = FALSE;
|
||||
netcam->connect_keepalive = TRUE;
|
||||
} else if (!strcmp(cnt->conf.netcam_http,"1.0") || !strcmp(cnt->conf.netcam_http,"1.0")) {
|
||||
} else if (!strcmp(cnt->conf.netcam_http, "1.0") || !strcmp(cnt->conf.netcam_http, "1.0")) {
|
||||
netcam->connect_http_10 = TRUE;
|
||||
netcam->connect_http_11 = FALSE;
|
||||
netcam->connect_keepalive = FALSE;
|
||||
} else if (!strcmp(cnt->conf.netcam_http,"1.1")) {
|
||||
} else if (!strcmp(cnt->conf.netcam_http, "1.1")) {
|
||||
netcam->connect_http_10 = FALSE;
|
||||
netcam->connect_http_11 = TRUE;
|
||||
netcam->connect_keepalive = TRUE; /* HTTP 1.1 has keepalive by default */
|
||||
@@ -2390,15 +2384,15 @@ int netcam_start(struct context *cnt)
|
||||
/* 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")) ){
|
||||
if ((url.service) && (!strcmp(url.service, "http")) ) {
|
||||
if (debug_level > CAMERA_INFO)
|
||||
motion_log(-1, 0, "netcam_start: now calling netcam_setup_html()");
|
||||
retval = netcam_setup_html(netcam, &url);
|
||||
} else if ((url.service) && (!strcmp(url.service, "ftp")) ){
|
||||
} else if ((url.service) && (!strcmp(url.service, "ftp")) ) {
|
||||
if (debug_level > CAMERA_INFO)
|
||||
motion_log(-1, 0, "netcam_start: now calling netcam_setup_ftp");
|
||||
retval = netcam_setup_ftp(netcam, &url);
|
||||
} else if ((url.service) && (!strcmp(url.service, "file")) ){
|
||||
} else if ((url.service) && (!strcmp(url.service, "file")) ) {
|
||||
if (debug_level > CAMERA_INFO)
|
||||
motion_log(-1, 0, "netcam_start: now calling netcam_setup_file()");
|
||||
retval = netcam_setup_file(netcam, &url);
|
||||
|
||||
62
netcam_ftp.c
62
netcam_ftp.c
@@ -11,19 +11,9 @@
|
||||
#include "motion.h" /* needs to come first, because _GNU_SOURCE_ set there */
|
||||
|
||||
#include <ctype.h>
|
||||
//#include <errno.h>
|
||||
//#include <fcntl.h>
|
||||
#include <netdb.h>
|
||||
#include <regex.h>
|
||||
//#include <stdarg.h>
|
||||
//#include <stdlib.h>
|
||||
//#include <stdio.h>
|
||||
//#include <string.h>
|
||||
//#include <syslog.h>
|
||||
//#include <unistd.h>
|
||||
#include <sys/socket.h>
|
||||
//#include <sys/stat.h>
|
||||
//#include <sys/types.h>
|
||||
//#include <regex.h>
|
||||
//#include <sys/socket.h>
|
||||
#include <netinet/in.h>
|
||||
|
||||
#include "netcam_ftp.h"
|
||||
@@ -210,7 +200,7 @@ static int ftp_get_response(ftp_context_pointer ctxt) {
|
||||
int res = -1, cur = -1;
|
||||
|
||||
if ((ctxt == NULL) || (ctxt->control_file_desc < 0))
|
||||
return(-1);
|
||||
return(-1);
|
||||
|
||||
get_more:
|
||||
/*
|
||||
@@ -244,7 +234,7 @@ static int ftp_get_response(ftp_context_pointer ctxt) {
|
||||
break;
|
||||
}
|
||||
while ((ptr < end) && (*ptr != '\n'))
|
||||
ptr++;
|
||||
ptr++;
|
||||
if (ptr >= end) {
|
||||
ctxt->control_buffer_index = ctxt->control_buffer_used;
|
||||
goto get_more;
|
||||
@@ -268,9 +258,9 @@ static int ftp_send_user(ftp_context_pointer ctxt) {
|
||||
int res;
|
||||
|
||||
if (ctxt->user == NULL)
|
||||
snprintf(buf, sizeof(buf), "USER anonymous\r\n");
|
||||
snprintf(buf, sizeof(buf), "USER anonymous\r\n");
|
||||
else
|
||||
snprintf(buf, sizeof(buf), "USER %s\r\n", ctxt->user);
|
||||
snprintf(buf, sizeof(buf), "USER %s\r\n", ctxt->user);
|
||||
buf[sizeof(buf) - 1] = 0;
|
||||
len = strlen(buf);
|
||||
res = send(ctxt->control_file_desc, buf, len, 0);
|
||||
@@ -291,9 +281,9 @@ static int ftp_send_passwd(ftp_context_pointer ctxt) {
|
||||
int res;
|
||||
|
||||
if (ctxt->passwd == NULL)
|
||||
snprintf(buf, sizeof(buf), "PASS anonymous@\r\n");
|
||||
snprintf(buf, sizeof(buf), "PASS anonymous@\r\n");
|
||||
else
|
||||
snprintf(buf, sizeof(buf), "PASS %s\r\n", ctxt->passwd);
|
||||
snprintf(buf, sizeof(buf), "PASS %s\r\n", ctxt->passwd);
|
||||
buf[sizeof(buf) - 1] = 0;
|
||||
len = strlen(buf);
|
||||
res = send(ctxt->control_file_desc, buf, len, 0);
|
||||
@@ -322,7 +312,7 @@ static int ftp_quit(ftp_context_pointer ctxt) {
|
||||
int len, res;
|
||||
|
||||
if ((ctxt == NULL) || (ctxt->control_file_desc < 0))
|
||||
return(-1);
|
||||
return(-1);
|
||||
|
||||
snprintf(buf, sizeof(buf), "QUIT\r\n");
|
||||
len = strlen(buf);
|
||||
@@ -354,19 +344,19 @@ int ftp_connect(netcam_context_ptr netcam) {
|
||||
int addrlen = sizeof (struct sockaddr_in);
|
||||
|
||||
if (netcam == NULL)
|
||||
return -1;
|
||||
return -1;
|
||||
ctxt = netcam->ftp;
|
||||
if (ctxt == NULL)
|
||||
return(-1);
|
||||
return(-1);
|
||||
if (netcam->connect_host == NULL)
|
||||
return(-1);
|
||||
return(-1);
|
||||
|
||||
/*
|
||||
* do the blocking DNS query.
|
||||
*/
|
||||
port = netcam->connect_port;
|
||||
if (port == 0)
|
||||
port = 21;
|
||||
port = 21;
|
||||
|
||||
memset (&ctxt->ftp_address, 0, sizeof(ctxt->ftp_address));
|
||||
|
||||
@@ -386,10 +376,8 @@ int ftp_connect(netcam_context_ptr netcam) {
|
||||
* Prepare the socket
|
||||
*/
|
||||
((struct sockaddr_in *)&ctxt->ftp_address)->sin_family = AF_INET;
|
||||
memcpy (&((struct sockaddr_in *)&ctxt->ftp_address)->sin_addr,
|
||||
hp->h_addr_list[0], hp->h_length);
|
||||
((struct sockaddr_in *)&ctxt->ftp_address)->sin_port =
|
||||
(u_short)htons ((unsigned short)port);
|
||||
memcpy (&((struct sockaddr_in *)&ctxt->ftp_address)->sin_addr, hp->h_addr_list[0], hp->h_length);
|
||||
((struct sockaddr_in *)&ctxt->ftp_address)->sin_port = (u_short)htons ((unsigned short)port);
|
||||
ctxt->control_file_desc = socket (AF_INET, SOCK_STREAM, 0);
|
||||
addrlen = sizeof (struct sockaddr_in);
|
||||
|
||||
@@ -431,7 +419,7 @@ int ftp_connect(netcam_context_ptr netcam) {
|
||||
res = ftp_get_response(ctxt);
|
||||
switch (res) {
|
||||
case 2:
|
||||
return(0);
|
||||
return(0);
|
||||
case 3:
|
||||
break;
|
||||
case 1:
|
||||
@@ -439,9 +427,9 @@ int ftp_connect(netcam_context_ptr netcam) {
|
||||
case 5:
|
||||
case -1:
|
||||
default:
|
||||
close(ctxt->control_file_desc);
|
||||
ctxt->control_file_desc = -1;
|
||||
return(-1);
|
||||
close(ctxt->control_file_desc);
|
||||
ctxt->control_file_desc = -1;
|
||||
return(-1);
|
||||
}
|
||||
res = ftp_send_passwd(ctxt);
|
||||
if (res < 0) {
|
||||
@@ -454,15 +442,15 @@ int ftp_connect(netcam_context_ptr netcam) {
|
||||
case 2:
|
||||
break;
|
||||
case 3:
|
||||
motion_log(LOG_ERR, 0, "FTP server asking for ACCT on anonymous");
|
||||
motion_log(LOG_ERR, 0, "FTP server asking for ACCT on anonymous");
|
||||
case 1:
|
||||
case 4:
|
||||
case 5:
|
||||
case -1:
|
||||
default:
|
||||
close(ctxt->control_file_desc); ctxt->control_file_desc = -1;
|
||||
ctxt->control_file_desc = -1;
|
||||
return(-1);
|
||||
close(ctxt->control_file_desc); ctxt->control_file_desc = -1;
|
||||
ctxt->control_file_desc = -1;
|
||||
return(-1);
|
||||
}
|
||||
|
||||
return(0);
|
||||
@@ -552,7 +540,7 @@ static int ftp_get_connection(ftp_context_pointer ctxt) {
|
||||
}
|
||||
return (-1);
|
||||
}
|
||||
for (i=0; i<6; i++)
|
||||
for (i = 0; i < 6; i++)
|
||||
ad[i] = (unsigned char) (temp[i] & 0xff) ;
|
||||
memcpy (&((struct sockaddr_in *)&data_address)->sin_addr, &ad[0], 4);
|
||||
memcpy (&((struct sockaddr_in *)&data_address)->sin_port, &ad[4], 2);
|
||||
@@ -600,7 +588,7 @@ static int ftp_get_connection(ftp_context_pointer ctxt) {
|
||||
/* 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",
|
||||
snprintf (buf, sizeof(buf), "PORT %d,%d,%d,%d,%d,%d\r\n",
|
||||
adp[0] & 0xff, adp[1] & 0xff, adp[2] & 0xff, adp[3] & 0xff,
|
||||
portp[0] & 0xff, portp[1] & 0xff);
|
||||
|
||||
|
||||
@@ -12,17 +12,10 @@
|
||||
* This program is published under the GNU Public license
|
||||
*/
|
||||
|
||||
//#include "motion.h"
|
||||
#include "rotate.h" /* already includes motion.h */
|
||||
|
||||
//#include <stdlib.h>
|
||||
//#include <stdio.h>
|
||||
//#include <string.h>
|
||||
#include <jpeglib.h>
|
||||
#include <jerror.h>
|
||||
|
||||
//#include "rotate.h"
|
||||
|
||||
/*
|
||||
* netcam_source_mgr is a locally-defined structure to contain elements
|
||||
* which are not present in the standard libjpeg (the element 'pub' is a
|
||||
@@ -295,7 +288,7 @@ static int netcam_init_jpeg(netcam_context_ptr netcam, j_decompress_ptr cinfo)
|
||||
pthread_mutex_unlock(&netcam->mutex);
|
||||
|
||||
if (debug_level > CAMERA_WARNINGS)
|
||||
motion_log(-1,0,"no new pic, no signal rcvd");
|
||||
motion_log(-1, 0, "no new pic, no signal rcvd");
|
||||
|
||||
return NETCAM_GENERAL_ERROR | NETCAM_NOTHING_NEW_ERROR;
|
||||
}
|
||||
|
||||
@@ -291,7 +291,7 @@ static void put_jpeg_grey_file(FILE *picture, unsigned char *image, int width, i
|
||||
|
||||
jpeg_start_compress(&cjpeg, TRUE);
|
||||
|
||||
row_ptr[0]=image;
|
||||
row_ptr[0] = image;
|
||||
for (y = 0; y < height; y++) {
|
||||
jpeg_write_scanlines(&cjpeg, row_ptr, 1);
|
||||
row_ptr[0] += width;
|
||||
@@ -539,11 +539,11 @@ void put_picture(struct context *cnt, char *file, unsigned char *image, int ftyp
|
||||
/* Get the pgm file used as fixed mask */
|
||||
unsigned char *get_pgm(FILE *picture, int width, int height)
|
||||
{
|
||||
int x = 0 ,y = 0, maxval;
|
||||
int x = 0 , y = 0, maxval;
|
||||
char line[256];
|
||||
unsigned char *image;
|
||||
|
||||
line[255]=0;
|
||||
line[255] = 0;
|
||||
|
||||
if (!fgets(line, 255, picture)) {
|
||||
motion_log(LOG_ERR, 1, "Could not read from ppm file");
|
||||
|
||||
53
track.c
53
track.c
@@ -115,18 +115,19 @@ static unsigned short int stepper_command(struct context *cnt, unsigned short in
|
||||
unsigned short int data)
|
||||
{
|
||||
char buffer[3];
|
||||
time_t timeout=time(NULL);
|
||||
time_t timeout = time(NULL);
|
||||
|
||||
buffer[0]=motor;
|
||||
buffer[1]=command;
|
||||
buffer[2]=data;
|
||||
if (write(cnt->track.dev, buffer, 3)!=3){
|
||||
buffer[0] = motor;
|
||||
buffer[1] = command;
|
||||
buffer[2] = data;
|
||||
|
||||
if (write(cnt->track.dev, buffer, 3) != 3){
|
||||
motion_log(LOG_ERR, 1, "stepper_command 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);
|
||||
while (read(cnt->track.dev, buffer, 1) != 1 && time(NULL) < timeout+1);
|
||||
if (time(NULL) >= timeout+2) {
|
||||
motion_log(LOG_ERR, 1, "Status byte timeout!");
|
||||
return 0;
|
||||
@@ -149,7 +150,7 @@ static unsigned short int stepper_center(struct context *cnt, int x_offset, int
|
||||
if (cnt->track.dev<0) {
|
||||
motion_log(LOG_INFO, 0, "Try to open serial device %s", cnt->track.port);
|
||||
|
||||
if ((cnt->track.dev=open(cnt->track.port, O_RDWR | O_NOCTTY)) < 0) {
|
||||
if ((cnt->track.dev = open(cnt->track.port, O_RDWR | O_NOCTTY)) < 0) {
|
||||
motion_log(LOG_ERR, 1, "Unable to open serial device %s", cnt->track.port);
|
||||
return 0;
|
||||
}
|
||||
@@ -159,8 +160,8 @@ static unsigned short int stepper_center(struct context *cnt, int x_offset, int
|
||||
adtio.c_iflag= IGNPAR;
|
||||
adtio.c_oflag= 0;
|
||||
adtio.c_lflag= 0; /* non-canon, no echo */
|
||||
adtio.c_cc[VTIME]=0; /* timer unused */
|
||||
adtio.c_cc[VMIN]=0; /* blocking read until 1 char */
|
||||
adtio.c_cc[VTIME] = 0; /* timer unused */
|
||||
adtio.c_cc[VMIN] = 0; /* blocking read until 1 char */
|
||||
tcflush (cnt->track.dev, TCIFLUSH);
|
||||
|
||||
if (tcsetattr(cnt->track.dev, TCSANOW, &adtio) < 0) {
|
||||
@@ -281,7 +282,7 @@ static void iomojo_setspeed(struct context *cnt, unsigned short int speed)
|
||||
command[1] = cnt->track.iomojo_id;
|
||||
command[2] = speed;
|
||||
|
||||
if (iomojo_command(cnt, command, 3, 1)!=IOMOJO_SETSPEED_RET)
|
||||
if (iomojo_command(cnt, command, 3, 1) != IOMOJO_SETSPEED_RET)
|
||||
motion_log(LOG_ERR, 1, "Unable to set camera speed");
|
||||
}
|
||||
|
||||
@@ -298,10 +299,10 @@ static void iomojo_movehome(struct context *cnt)
|
||||
static unsigned short int iomojo_center(struct context *cnt, int x_offset, int y_offset)
|
||||
{
|
||||
struct termios adtio;
|
||||
char command[5], direction=0;
|
||||
char command[5], direction = 0;
|
||||
|
||||
if (cnt->track.dev<0) {
|
||||
if ((cnt->track.dev=open(cnt->track.port, O_RDWR | O_NOCTTY)) < 0) {
|
||||
if ((cnt->track.dev = open(cnt->track.port, O_RDWR | O_NOCTTY)) < 0) {
|
||||
motion_log(LOG_ERR, 1, "Unable to open serial device %s", cnt->track.port);
|
||||
return 0;
|
||||
}
|
||||
@@ -427,14 +428,14 @@ static unsigned short int lqos_center(struct context *cnt, int dev, int x_angle,
|
||||
struct pwc_mpt_angles pma;
|
||||
struct pwc_mpt_range pmr;
|
||||
|
||||
if (cnt->track.dev==-1) {
|
||||
if (cnt->track.dev == -1) {
|
||||
|
||||
if (ioctl(dev, VIDIOCPWCMPTRESET, &reset) == -1) {
|
||||
motion_log(LOG_ERR, 1, "Failed to reset pwc camera to starting position! Reason");
|
||||
return 0;
|
||||
}
|
||||
|
||||
SLEEP(6,0)
|
||||
SLEEP(6, 0);
|
||||
|
||||
if (ioctl(dev, VIDIOCPWCMPTGRANGE, &pmr) == -1) {
|
||||
motion_log(LOG_ERR, 1, "failed VIDIOCPWCMPTGRANGE");
|
||||
@@ -574,7 +575,7 @@ static unsigned short int uvc_center(struct context *cnt, int dev, int x_angle,
|
||||
}
|
||||
motion_log(LOG_DEBUG, 0, "Reseting UVC camera to starting position");
|
||||
|
||||
SLEEP(8,0)
|
||||
SLEEP(8, 0);
|
||||
|
||||
/* Get camera range */
|
||||
struct v4l2_queryctrl queryctrl;
|
||||
@@ -650,7 +651,7 @@ static unsigned short int uvc_center(struct context *cnt, int dev, int x_angle,
|
||||
|
||||
/* DWe 30.03.07 We must wait a little,before we set the next CMD, otherwise PAN is mad ... */
|
||||
if ((move_x_degrees != 0) && (move_y_degrees != 0)) {
|
||||
SLEEP (1,0);
|
||||
SLEEP (1, 0);
|
||||
}
|
||||
|
||||
if (move_y_degrees != 0 ) {
|
||||
@@ -664,17 +665,17 @@ static unsigned short int uvc_center(struct context *cnt, int dev, int x_angle,
|
||||
|
||||
}
|
||||
|
||||
motion_log(LOG_DEBUG, 0,"Found MINMAX = %d", cnt->track.minmaxfound);
|
||||
motion_log(LOG_DEBUG, 0, "Found MINMAX = %d", cnt->track.minmaxfound);
|
||||
|
||||
if (cnt->track.dev!=-1) {
|
||||
motion_log(LOG_DEBUG, 0," Before_ABS_Y_Angel : x= %d , Y= %d , ", cnt->track.pan_angle, cnt->track.tilt_angle );
|
||||
motion_log(LOG_DEBUG, 0, " 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;
|
||||
}
|
||||
if (move_x_degrees != -1) {
|
||||
cnt->track.tilt_angle += move_y_degrees;
|
||||
}
|
||||
motion_log(LOG_DEBUG, 0," After_ABS_Y_Angel : x= %d , Y= %d , ", cnt->track.pan_angle, cnt->track.tilt_angle );
|
||||
motion_log(LOG_DEBUG, 0, " After_ABS_Y_Angel : x= %d , Y= %d , ", cnt->track.pan_angle, cnt->track.tilt_angle );
|
||||
}
|
||||
|
||||
return cnt->track.move_wait;
|
||||
@@ -707,7 +708,7 @@ static unsigned short int uvc_move(struct context *cnt, int dev, struct coord *c
|
||||
|
||||
/* set the "helpvalue" back to null because after reset CAM should be in x=0 and not 70 */
|
||||
cent->x = 0;
|
||||
SLEEP(8,0);
|
||||
SLEEP(8, 0);
|
||||
|
||||
/* 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
|
||||
@@ -792,7 +793,7 @@ static unsigned short int uvc_move(struct context *cnt, int dev, struct coord *c
|
||||
|
||||
// control_s.value = pan.value;
|
||||
control_s.value = pan.s16.pan;
|
||||
motion_log(LOG_DEBUG, 0," dev %d,addr= %d, control_S= %d,Wert= %d,", dev,VIDIOC_S_CTRL, &control_s, pan.s16.pan );
|
||||
motion_log(LOG_DEBUG, 0, " 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(LOG_ERR, 1, "Failed to move UVC camera!");
|
||||
return 0;
|
||||
@@ -801,7 +802,7 @@ static unsigned short int uvc_move(struct context *cnt, int dev, struct coord *c
|
||||
|
||||
/* DWe 30.03.07 We must wait a little,before we set the next CMD, otherwise PAN is mad ... */
|
||||
if ((move_x_degrees != 0) && (move_y_degrees != 0)) {
|
||||
SLEEP (1,0);
|
||||
SLEEP (1, 0);
|
||||
}
|
||||
|
||||
|
||||
@@ -811,7 +812,7 @@ static unsigned short int uvc_move(struct context *cnt, int dev, struct coord *c
|
||||
|
||||
// control_s.value = pan.value;
|
||||
control_s.value = pan.s16.tilt;
|
||||
motion_log(LOG_DEBUG, 0," dev %d,addr= %d, control_S= %d, Wert= %d, ", dev,VIDIOC_S_CTRL, &control_s, pan.s16.tilt );
|
||||
motion_log(LOG_DEBUG, 0, " 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(LOG_ERR, 1, "Failed to move UVC camera!");
|
||||
return 0;
|
||||
@@ -819,9 +820,9 @@ static unsigned short int uvc_move(struct context *cnt, int dev, struct coord *c
|
||||
}
|
||||
|
||||
|
||||
motion_log(LOG_DEBUG, 0,"Found MINMAX = %d", cnt->track.minmaxfound);
|
||||
motion_log(LOG_DEBUG, 0, "Found MINMAX = %d", cnt->track.minmaxfound);
|
||||
if (cnt->track.minmaxfound == 1) {
|
||||
motion_log(LOG_DEBUG, 0," Before_REL_Y_Angel : x= %d , Y= %d", cnt->track.pan_angle, cnt->track.tilt_angle );
|
||||
motion_log(LOG_DEBUG, 0, " Before_REL_Y_Angel : x= %d , Y= %d", cnt->track.pan_angle, cnt->track.tilt_angle );
|
||||
|
||||
if (move_x_degrees != 0){
|
||||
cnt->track.pan_angle += -pan.s16.pan / INCPANTILT;
|
||||
@@ -829,7 +830,7 @@ static unsigned short int uvc_move(struct context *cnt, int dev, struct coord *c
|
||||
if (move_y_degrees != 0){
|
||||
cnt->track.tilt_angle += -pan.s16.tilt / INCPANTILT;
|
||||
}
|
||||
motion_log(LOG_DEBUG, 0," After_REL_Y_Angel : x= %d , Y= %d", cnt->track.pan_angle, cnt->track.tilt_angle );
|
||||
motion_log(LOG_DEBUG, 0, " After_REL_Y_Angel : x= %d , Y= %d", cnt->track.pan_angle, cnt->track.tilt_angle );
|
||||
}
|
||||
|
||||
return cnt->track.move_wait;
|
||||
|
||||
14
track.h
14
track.h
@@ -32,7 +32,7 @@ struct trackoptions {
|
||||
unsigned short int step_angle_x;
|
||||
unsigned short int step_angle_y;
|
||||
unsigned short int move_wait;
|
||||
// UVC
|
||||
/* UVC */
|
||||
int pan_angle; // degrees
|
||||
int tilt_angle; // degrees
|
||||
};
|
||||
@@ -43,7 +43,7 @@ unsigned short int track_center(struct context *, int, unsigned short int, int,
|
||||
unsigned short int track_move(struct context *, int, struct coord *, struct images *, unsigned short int);
|
||||
|
||||
/*
|
||||
Some default values:
|
||||
* Some default values:
|
||||
*/
|
||||
#define TRACK_SPEED 255
|
||||
#define TRACK_STEPSIZE 40
|
||||
@@ -55,7 +55,7 @@ unsigned short int track_move(struct context *, int, struct coord *, struct imag
|
||||
#define TRACK_TYPE_UVC 5
|
||||
|
||||
/*
|
||||
Some defines for the Serial stepper motor:
|
||||
* Some defines for the Serial stepper motor:
|
||||
*/
|
||||
|
||||
#define STEPPER_BAUDRATE B9600
|
||||
@@ -88,7 +88,7 @@ unsigned short int track_move(struct context *, int, struct coord *, struct imag
|
||||
|
||||
|
||||
/*
|
||||
Some defines for the Iomojo Smilecam:
|
||||
* Some defines for the Iomojo Smilecam:
|
||||
*/
|
||||
|
||||
#define IOMOJO_BAUDRATE B19200
|
||||
@@ -109,14 +109,14 @@ unsigned short int track_move(struct context *, int, struct coord *, struct imag
|
||||
#ifndef WITHOUT_V4L
|
||||
|
||||
/*
|
||||
Defines for the Logitech QuickCam Orbit/Sphere USB webcam
|
||||
*/
|
||||
* Defines for the Logitech QuickCam Orbit/Sphere USB webcam
|
||||
*/
|
||||
|
||||
#define LQOS_VERTICAL_DEGREES 180
|
||||
#define LQOS_HORIZONAL_DEGREES 120
|
||||
|
||||
/*
|
||||
* UVC
|
||||
* UVC
|
||||
*/
|
||||
|
||||
#ifdef MOTION_V4L2
|
||||
|
||||
57
video2.c
57
video2.c
@@ -315,20 +315,22 @@ static int v4l2_set_pix_format(struct context *cnt, src_v4l2_t * s, int *width,
|
||||
fmt.type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
|
||||
|
||||
motion_log(LOG_INFO, 0, "Supported palettes:");
|
||||
|
||||
while (xioctl(s->fd, VIDIOC_ENUM_FMT, &fmt) != -1) {
|
||||
short int i;
|
||||
|
||||
motion_log(LOG_INFO, 0, "%i: %c%c%c%c (%s)", v4l2_pal,
|
||||
fmt.pixelformat >> 0, fmt.pixelformat >> 8,
|
||||
fmt.pixelformat >> 16, fmt.pixelformat >> 24, fmt.description);
|
||||
motion_log(LOG_INFO, 0, "%i: %c%c%c%c (%s)", v4l2_pal, fmt.pixelformat >> 0,
|
||||
fmt.pixelformat >> 8, fmt.pixelformat >> 16,
|
||||
fmt.pixelformat >> 24, fmt.description);
|
||||
|
||||
for (i = 0; supported_formats[i]; i++)
|
||||
if (supported_formats[i] == fmt.pixelformat && i > index_format) {
|
||||
if (cnt->conf.v4l2_palette == i) {
|
||||
index_format = cnt->conf.v4l2_palette;
|
||||
motion_log(LOG_INFO, 0, "Selected palette %c%c%c%c", fmt.pixelformat >> 0,
|
||||
fmt.pixelformat >> 8, fmt.pixelformat >> 16, fmt.pixelformat >> 24);
|
||||
i=10;
|
||||
fmt.pixelformat >> 8, fmt.pixelformat >> 16,
|
||||
fmt.pixelformat >> 24);
|
||||
i = 10;
|
||||
break;
|
||||
}
|
||||
index_format = i;
|
||||
@@ -355,12 +357,14 @@ static int v4l2_set_pix_format(struct context *cnt, src_v4l2_t * s, int *width,
|
||||
s->fmt.fmt.pix.field = V4L2_FIELD_ANY;
|
||||
|
||||
if (xioctl(s->fd, VIDIOC_TRY_FMT, &s->fmt) != -1 && s->fmt.fmt.pix.pixelformat == pixformat) {
|
||||
motion_log(LOG_INFO, 0, "index_format %d Test palette %c%c%c%c (%dx%d)", index_format, pixformat >> 0, pixformat >> 8, pixformat >> 16, pixformat >> 24, *width, *height);
|
||||
motion_log(LOG_INFO, 0, "index_format %d Test palette %c%c%c%c (%dx%d)",
|
||||
index_format, pixformat >> 0, pixformat >> 8,
|
||||
pixformat >> 16, pixformat >> 24, *width, *height);
|
||||
|
||||
if (s->fmt.fmt.pix.width != (unsigned int) *width
|
||||
|| s->fmt.fmt.pix.height != (unsigned int) *height) {
|
||||
motion_log(LOG_INFO, 0, "Adjusting resolution from %ix%i to %ix%i.", *width, *height,
|
||||
s->fmt.fmt.pix.width, s->fmt.fmt.pix.height);
|
||||
s->fmt.fmt.pix.width, s->fmt.fmt.pix.height);
|
||||
*width = s->fmt.fmt.pix.width;
|
||||
*height = s->fmt.fmt.pix.height;
|
||||
}
|
||||
@@ -371,7 +375,9 @@ static int v4l2_set_pix_format(struct context *cnt, src_v4l2_t * s, int *width,
|
||||
return (-1);
|
||||
}
|
||||
|
||||
motion_log(LOG_INFO, 0, "Using palette %c%c%c%c (%dx%d) bytesperlines %d sizeimage %d colorspace %08x", pixformat >> 0, pixformat >> 8, pixformat >> 16, pixformat >> 24, *width, *height, s->fmt.fmt.pix.bytesperline, s->fmt.fmt.pix.sizeimage, s->fmt.fmt. pix.colorspace);
|
||||
motion_log(LOG_INFO, 0, "Using palette %c%c%c%c (%dx%d) bytesperlines %d sizeimage %d colorspace %08x",
|
||||
pixformat >> 0, pixformat >> 8, pixformat >> 16, pixformat >> 24, *width, *height,
|
||||
s->fmt.fmt.pix.bytesperline, s->fmt.fmt.pix.sizeimage, s->fmt.fmt. pix.colorspace);
|
||||
|
||||
/* TODO: Review when it has been tested */
|
||||
if (pixformat == V4L2_PIX_FMT_MJPEG) {
|
||||
@@ -390,7 +396,7 @@ static int v4l2_set_pix_format(struct context *cnt, src_v4l2_t * s, int *width,
|
||||
}
|
||||
|
||||
motion_log(LOG_ERR, 0, "VIDIOC_TRY_FMT failed for format %c%c%c%c (%s).", pixformat >> 0,
|
||||
pixformat >> 8, pixformat >> 16, pixformat >> 24, strerror(errno));
|
||||
pixformat >> 8, pixformat >> 16, pixformat >> 24, strerror(errno));
|
||||
|
||||
return -1;
|
||||
}
|
||||
@@ -403,13 +409,13 @@ static int v4l2_set_pix_format(struct context *cnt, src_v4l2_t * s, int *width,
|
||||
static void v4l2_set_fps(src_v4l2_t * s){
|
||||
struct v4l2_streamparm* setfps;
|
||||
|
||||
setfps=(struct v4l2_streamparm *) calloc(1, sizeof(struct v4l2_streamparm));
|
||||
setfps = (struct v4l2_streamparm *) calloc(1, sizeof(struct v4l2_streamparm));
|
||||
memset(setfps, 0, sizeof(struct v4l2_streamparm));
|
||||
setfps->type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
|
||||
setfps->parm.capture.timeperframe.numerator=1;
|
||||
setfps->parm.capture.timeperframe.denominator=s->fps;
|
||||
if (xioctl(s->fd, VIDIOC_S_PARM, setfps) == -1){
|
||||
motion_log(LOG_ERR, 0, "v4l2_set_fps VIDIOC_S_PARM %s",strerror(errno));
|
||||
setfps->parm.capture.timeperframe.numerator = 1;
|
||||
setfps->parm.capture.timeperframe.denominator = s->fps;
|
||||
if (xioctl(s->fd, VIDIOC_S_PARM, setfps) == -1) {
|
||||
motion_log(LOG_ERR, 0, "v4l2_set_fps VIDIOC_S_PARM %s", strerror(errno));
|
||||
}
|
||||
|
||||
}
|
||||
@@ -540,14 +546,14 @@ static int v4l2_scan_controls(src_v4l2_t * s)
|
||||
memcpy(ctrl, &queryctrl, sizeof(struct v4l2_queryctrl));
|
||||
|
||||
motion_log(LOG_INFO, 0, "found control 0x%08x, \"%s\", range %d,%d %s", ctrl->id,
|
||||
ctrl->name, ctrl->minimum, ctrl->maximum,
|
||||
ctrl->flags & V4L2_CTRL_FLAG_DISABLED ? "!DISABLED!" : "");
|
||||
ctrl->name, ctrl->minimum, ctrl->maximum,
|
||||
ctrl->flags & V4L2_CTRL_FLAG_DISABLED ? "!DISABLED!" : "");
|
||||
|
||||
memset (&control, 0, sizeof (control));
|
||||
control.id = queried_ctrls[i];
|
||||
xioctl(s->fd, VIDIOC_G_CTRL, &control);
|
||||
motion_log(LOG_INFO, 0, "\t\"%s\", default %d, current %d", ctrl->name,
|
||||
ctrl->default_value, control.value);
|
||||
ctrl->default_value, control.value);
|
||||
|
||||
ctrl++;
|
||||
}
|
||||
@@ -592,8 +598,9 @@ static int v4l2_set_control(src_v4l2_t * s, u32 cid, int value)
|
||||
}
|
||||
if (debug_level > 5)
|
||||
motion_log(LOG_INFO, 0, "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!" : "");
|
||||
value, ret, ret ? strerror(errno) : "",
|
||||
ctrl->flags & V4L2_CTRL_FLAG_DISABLED ?
|
||||
"Control is DISABLED!" : "");
|
||||
|
||||
return 0;
|
||||
}
|
||||
@@ -664,7 +671,7 @@ unsigned char *v4l2_start(struct context *cnt, struct video_dev *viddev, int wid
|
||||
goto err;
|
||||
}
|
||||
|
||||
if (v4l2_set_pix_format(cnt ,s, &width, &height)) {
|
||||
if (v4l2_set_pix_format(cnt, s, &width, &height)) {
|
||||
goto err;
|
||||
}
|
||||
|
||||
@@ -736,7 +743,7 @@ void v4l2_set_input(struct context *cnt, struct video_dev *viddev, unsigned char
|
||||
unsigned int counter = 0;
|
||||
if (debug_level > 5)
|
||||
motion_log(LOG_DEBUG, 0, "set_input_skip_frame switch_time=%ld:%ld",
|
||||
switchTime.tv_sec, switchTime.tv_usec);
|
||||
switchTime.tv_sec, switchTime.tv_usec);
|
||||
|
||||
/* Avoid hang using the number of mmap buffers */
|
||||
while(counter < s->req.count)
|
||||
@@ -749,7 +756,7 @@ void v4l2_set_input(struct context *cnt, struct video_dev *viddev, unsigned char
|
||||
break;
|
||||
if (debug_level > 5)
|
||||
motion_log(LOG_DEBUG, 0, "got frame before switch timestamp=%ld:%ld",
|
||||
s->buf.timestamp.tv_sec, s->buf.timestamp.tv_usec);
|
||||
s->buf.timestamp.tv_sec, s->buf.timestamp.tv_usec);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -798,12 +805,12 @@ int v4l2_next(struct context *cnt, struct video_dev *viddev, unsigned char *map,
|
||||
driver might dequeue an (empty) buffer despite
|
||||
returning an error, or even stop capturing.
|
||||
*/
|
||||
if ( errno == EIO ){
|
||||
if ( errno == EIO ) {
|
||||
s->pframe++;
|
||||
if ((u32)s->pframe >= s->req.count) s->pframe=0;
|
||||
if ((u32)s->pframe >= s->req.count) s->pframe = 0;
|
||||
s->buf.index = s->pframe;
|
||||
|
||||
motion_log(LOG_ERR, 0, "%s: VIDIOC_DQBUF: EIO (s->pframe %d)", __FUNCTION__,s->pframe);
|
||||
motion_log(LOG_ERR, 0, "%s: VIDIOC_DQBUF: EIO (s->pframe %d)", __FUNCTION__, s->pframe);
|
||||
|
||||
return (1);
|
||||
}
|
||||
|
||||
@@ -9,12 +9,9 @@
|
||||
*
|
||||
*/
|
||||
|
||||
//#include "motion.h"
|
||||
/* for rotation */
|
||||
#include "rotate.h" /* already includes motion.h */
|
||||
#include "video.h"
|
||||
/* for rotation */
|
||||
//#include "rotate.h"
|
||||
|
||||
#ifdef MJPEGT
|
||||
#include <mjpegtools/jpegutils.h>
|
||||
@@ -296,7 +293,7 @@ void conv_uyvyto420p(unsigned char *map, unsigned char *cap_map, unsigned int wi
|
||||
{
|
||||
uint8_t *pY = map;
|
||||
uint8_t *pU = pY + (width * height);
|
||||
uint8_t *pV = pU + (width * height)/4;
|
||||
uint8_t *pV = pU + (width * height) / 4;
|
||||
uint32_t uv_offset = width * 4 * sizeof(uint8_t);
|
||||
uint32_t ix, jx;
|
||||
|
||||
@@ -363,7 +360,7 @@ void conv_rgb24toyuv420p(unsigned char *map, unsigned char *cap_map, int width,
|
||||
}
|
||||
}
|
||||
|
||||
int conv_jpeg2yuv420(struct context *cnt, unsigned char *dst, netcam_buff * buff, int width, int height)
|
||||
int conv_jpeg2yuv420(struct context *cnt, unsigned char *dst, netcam_buff *buff, int width, int height)
|
||||
{
|
||||
netcam_context netcam;
|
||||
|
||||
@@ -406,23 +403,23 @@ void mjpegtoyuv420p(unsigned char *map, unsigned char *cap_map, int width, int h
|
||||
|
||||
decode_jpeg_raw(cap_map, size, 0, 420, width, height, yuv[0], yuv[1], yuv[2]);
|
||||
|
||||
y=map;
|
||||
u=y+width*height;
|
||||
v=u+(width*height)/4;
|
||||
memset(y, 0, width*height);
|
||||
memset(u, 0, width*height/4);
|
||||
memset(v, 0, width*height/4);
|
||||
y = map;
|
||||
u = y + width * height;
|
||||
v = u + (width * height) / 4;
|
||||
memset(y, 0, width * height);
|
||||
memset(u, 0, width * height / 4);
|
||||
memset(v, 0, width * height / 4);
|
||||
|
||||
for(loop=0; loop<width*height; loop++) {
|
||||
*map++=yuv[0][loop];
|
||||
for(loop = 0; loop < width * height; loop++) {
|
||||
*map++ = yuv[0][loop];
|
||||
}
|
||||
|
||||
for(loop=0; loop<width*height/4; loop++) {
|
||||
*map++=yuv[1][loop];
|
||||
for(loop = 0; loop < width * height / 4; loop++) {
|
||||
*map++ = yuv[1][loop];
|
||||
}
|
||||
|
||||
for(loop=0; loop<width*height/4; loop++) {
|
||||
*map++=yuv[2][loop];
|
||||
for(loop = 0; loop < width * height / 4; loop++) {
|
||||
*map++ = yuv[2][loop];
|
||||
}
|
||||
|
||||
free(yuv[0]);
|
||||
@@ -853,7 +850,7 @@ int vid_start(struct context *cnt)
|
||||
}
|
||||
#ifdef WITHOUT_V4L
|
||||
else
|
||||
motion_log(LOG_ERR, 0,"You must setup netcam_url");
|
||||
motion_log(LOG_ERR, 0, "You must setup netcam_url");
|
||||
#else
|
||||
else
|
||||
dev = vid_v4lx_start(cnt);
|
||||
|
||||
164
video_freebsd.c
164
video_freebsd.c
@@ -7,13 +7,9 @@
|
||||
*
|
||||
*/
|
||||
|
||||
/* Common stuff: */
|
||||
//#include "motion.h"
|
||||
/* for rotation */
|
||||
#include "rotate.h" /* already includes motion.h */
|
||||
#include "video_freebsd.h"
|
||||
/* for rotation */
|
||||
//#include "rotate.h"
|
||||
|
||||
#ifndef WITHOUT_V4L
|
||||
|
||||
@@ -87,9 +83,9 @@ static void yuv422to420p(unsigned char *map, unsigned char *cap_map, int width,
|
||||
int i, j;
|
||||
|
||||
/* Create the Y plane */
|
||||
src=cap_map;
|
||||
dest=map;
|
||||
for (i= width * height; i; i--) {
|
||||
src = cap_map;
|
||||
dest = map;
|
||||
for (i = width * height; i; i--) {
|
||||
*dest++ = *src;
|
||||
src += 2;
|
||||
}
|
||||
@@ -132,28 +128,28 @@ static void rgb24toyuv420p(unsigned char *map, unsigned char *cap_map, int width
|
||||
memset(u, 0, width * height / 4);
|
||||
memset(v, 0, width * height / 4);
|
||||
|
||||
for(loop=0; loop<height; loop++) {
|
||||
for(i=0; i<width; i+=2) {
|
||||
*y++=(9796**r+19235**g+3736**b)>>15;
|
||||
*u+=((-4784**r-9437**g+14221**b)>>17)+32;
|
||||
*v+=((20218**r-16941**g-3277**b)>>17)+32;
|
||||
r+=3;
|
||||
g+=3;
|
||||
b+=3;
|
||||
*y++=(9796**r+19235**g+3736**b)>>15;
|
||||
*u+=((-4784**r-9437**g+14221**b)>>17)+32;
|
||||
*v+=((20218**r-16941**g-3277**b)>>17)+32;
|
||||
r+=3;
|
||||
g+=3;
|
||||
b+=3;
|
||||
for(loop = 0; loop < height; loop++) {
|
||||
for(i = 0; i < width; i += 2) {
|
||||
*y++ = (9796 ** r + 19235 ** g + 3736 ** b) >> 15;
|
||||
*u += ((-4784 ** r - 9437 ** g + 14221 ** b) >> 17) + 32;
|
||||
*v += ((20218 ** r - 16941**g-3277 ** b) >> 17) + 32;
|
||||
r += 3;
|
||||
g += 3;
|
||||
b += 3;
|
||||
*y++ = (9796 ** r + 19235 ** g + 3736 ** b) >> 15;
|
||||
*u += ((-4784 ** r - 9437 ** g + 14221 ** b) >> 17) + 32;
|
||||
*v += ((20218 ** r - 16941 ** g - 3277 ** b) >> 17) + 32;
|
||||
r += 3;
|
||||
g += 3;
|
||||
b += 3;
|
||||
u++;
|
||||
v++;
|
||||
}
|
||||
|
||||
if ((loop & 1) == 0)
|
||||
{
|
||||
u-=width/2;
|
||||
v-=width/2;
|
||||
u -= width / 2;
|
||||
v -= width / 2;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -174,7 +170,7 @@ static int camparam_normalize( int param, int cfg_value, int *ioctl_val )
|
||||
val = (cfg_value - CamParams[ param ].min ) /
|
||||
(CamParams[ param ].range + 0.01) * CamParams[param].drv_range + CamParams[param].drv_min;
|
||||
val = MAX( CamParams[ param ].min,
|
||||
MIN( CamParams[ param ].drv_min + CamParams[ param ].drv_range-1,val ));
|
||||
MIN( CamParams[ param ].drv_min + CamParams[ param ].drv_range-1, val ));
|
||||
*ioctl_val = val;
|
||||
return cfg_value;
|
||||
}
|
||||
@@ -185,11 +181,11 @@ static int set_hue( int viddev, int new_hue )
|
||||
signed char ioctlval = new_hue;
|
||||
|
||||
if( ioctl( viddev, METEORSHUE, &ioctlval ) < 0 ) {
|
||||
motion_log(LOG_ERR, 1, "METEORSHUE Error setting hue [%d]",new_hue);
|
||||
motion_log(LOG_ERR, 1, "METEORSHUE Error setting hue [%d]", new_hue);
|
||||
return -1;
|
||||
}
|
||||
|
||||
motion_log(-1, 0, "set hue to [%d]",ioctlval);
|
||||
motion_log(-1, 0, "set hue to [%d]", ioctlval);
|
||||
|
||||
return ioctlval;
|
||||
}
|
||||
@@ -212,11 +208,11 @@ static int set_saturation( int viddev, int new_saturation )
|
||||
unsigned char ioctlval= new_saturation;
|
||||
|
||||
if( ioctl( viddev, METEORSCSAT, &ioctlval ) < 0 ) {
|
||||
motion_log(LOG_ERR, 1, "METEORSCSAT Error setting saturation [%d]",new_saturation);
|
||||
motion_log(LOG_ERR, 1, "METEORSCSAT Error setting saturation [%d]", new_saturation);
|
||||
return -1;
|
||||
}
|
||||
|
||||
motion_log(-1, 0, "set saturation to [%d]",ioctlval);
|
||||
motion_log(-1, 0, "set saturation to [%d]", ioctlval);
|
||||
|
||||
return ioctlval;
|
||||
}
|
||||
@@ -244,7 +240,7 @@ static int set_contrast( int viddev, int new_contrast )
|
||||
return 0;
|
||||
}
|
||||
|
||||
motion_log(-1, 0, "set contrast to [%d]",ioctlval);
|
||||
motion_log(-1, 0, "set contrast to [%d]", ioctlval);
|
||||
|
||||
return ioctlval;
|
||||
}
|
||||
@@ -268,11 +264,11 @@ static int set_brightness( int viddev, int new_bright )
|
||||
unsigned char ioctlval = new_bright;
|
||||
|
||||
if( ioctl( viddev, METEORSBRIG, &ioctlval ) < 0 ) {
|
||||
motion_log(LOG_ERR, 1, "METEORSBRIG brightness [%d]",new_bright);
|
||||
motion_log(LOG_ERR, 1, "METEORSBRIG brightness [%d]", new_bright);
|
||||
return -1;
|
||||
}
|
||||
|
||||
motion_log(-1, 0, "set brightness to [%d]",ioctlval);
|
||||
motion_log(-1, 0, "set brightness to [%d]", ioctlval);
|
||||
|
||||
return ioctlval;
|
||||
}
|
||||
@@ -299,10 +295,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(LOG_ERR, 1, "Error channel %d",ioctlval);
|
||||
motion_log(LOG_ERR, 1, "Error channel %d", ioctlval);
|
||||
return -1;
|
||||
} else {
|
||||
motion_log(LOG_DEBUG, 0, "channel set to %d",ioctlval);
|
||||
motion_log(LOG_DEBUG, 0, "channel set to %d", ioctlval);
|
||||
}
|
||||
|
||||
viddev->channel = new_channel;
|
||||
@@ -328,7 +324,7 @@ static int set_freq(struct video_dev *viddev, unsigned long freq)
|
||||
}
|
||||
|
||||
if (ioctl(tuner_fd, TVTUNER_SETFREQ, &freq) < 0){
|
||||
motion_log(LOG_ERR, 1, "Tuning (TVTUNER_SETFREQ) failed , freq [%lu]",freq);
|
||||
motion_log(LOG_ERR, 1, "Tuning (TVTUNER_SETFREQ) failed , freq [%lu]", freq);
|
||||
return -1;
|
||||
}
|
||||
|
||||
@@ -336,7 +332,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(LOG_ERR, 1, "BT848_SAUDIO %i",old_audio);
|
||||
motion_log(LOG_ERR, 1, "BT848_SAUDIO %i", old_audio);
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
@@ -361,7 +357,7 @@ static int set_input(struct video_dev *viddev, unsigned short input)
|
||||
METEOR_INPUT_DEV_SVIDEO };
|
||||
|
||||
if( input >= array_elem( portdata ) ) {
|
||||
motion_log(LOG_WARNING, 0, "Channel Port %d out of range (0-4)",input);
|
||||
motion_log(LOG_WARNING, 0, "Channel Port %d out of range (0-4)", input);
|
||||
input = IN_DEFAULT;
|
||||
}
|
||||
|
||||
@@ -377,7 +373,7 @@ static int set_input(struct video_dev *viddev, unsigned short input)
|
||||
return -1;
|
||||
}
|
||||
} else {
|
||||
motion_log(LOG_ERR, 1, "METEORSINPUT %d init",input);
|
||||
motion_log(LOG_ERR, 1, "METEORSINPUT %d init", input);
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
@@ -427,7 +423,7 @@ static int set_input_format(struct video_dev *viddev, unsigned short newformat)
|
||||
int format;
|
||||
|
||||
if( newformat >= array_elem( input_format ) ) {
|
||||
motion_log(LOG_WARNING, 0, "Input format %d out of range (0-2)",newformat );
|
||||
motion_log(LOG_WARNING, 0, "Input format %d out of range (0-2)", newformat );
|
||||
format = NORM_DEFAULT_NEW;
|
||||
newformat = 3;
|
||||
} else
|
||||
@@ -454,12 +450,12 @@ statict int setup_pixelformat( int bktr )
|
||||
struct meteor_pixfmt p;
|
||||
int format=-1;
|
||||
|
||||
for( i=0; ; i++ ){
|
||||
for( i = 0; ; i++ ){
|
||||
p.index = i;
|
||||
if( ioctl( bktr, METEORGSUPPIXFMT, &p ) < 0 ){
|
||||
if( errno == EINVAL )
|
||||
break;
|
||||
motion_log(LOG_ERR, 1, "METEORGSUPPIXFMT getting pixformat %d",i);
|
||||
motion_log(LOG_ERR, 1, "METEORGSUPPIXFMT getting pixformat %d", i);
|
||||
return -1;
|
||||
}
|
||||
|
||||
@@ -512,8 +508,8 @@ statict int setup_pixelformat( int bktr )
|
||||
motion_log(LOG_WARNING, 1, "METEORSACTPIXFMT etting pixformat METEOR_PIXTYPE_RGB Bpp == 3");
|
||||
// Not immediately fatal
|
||||
}
|
||||
motion_log(LOG_DEBUG, 0, "input format METEOR_PIXTYPE_RGB %i",i);
|
||||
format=i;
|
||||
motion_log(LOG_DEBUG, 0, "input format METEOR_PIXTYPE_RGB %i", i);
|
||||
format = i;
|
||||
}
|
||||
|
||||
if( p.type == METEOR_PIXTYPE_YUV_PACKED ){
|
||||
@@ -522,8 +518,8 @@ statict int setup_pixelformat( int bktr )
|
||||
motion_log(LOG_WARNING, 1, "METEORSACTPIXFMT setting pixformat METEOR_PIXTYPE_YUV_PACKED");
|
||||
// Not immediately fatal
|
||||
}
|
||||
motion_log(LOG_DEBUG, 0, "input format METEOR_PIXTYPE_YUV_PACKED %i",i);
|
||||
format=i;
|
||||
motion_log(LOG_DEBUG, 0, "input format METEOR_PIXTYPE_YUV_PACKED %i", i);
|
||||
format = i;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -538,7 +534,7 @@ static void v4l_picture_controls(struct context *cnt, struct video_dev *viddev)
|
||||
int dev = viddev->fd_bktr;
|
||||
|
||||
if ( (cnt->conf.contrast) && (cnt->conf.contrast != viddev->contrast) ){
|
||||
set_contrast(dev,cnt->conf.contrast);
|
||||
set_contrast(dev, cnt->conf.contrast);
|
||||
viddev->contrast = cnt->conf.contrast;
|
||||
}
|
||||
|
||||
@@ -580,7 +576,7 @@ static unsigned char *v4l_start(struct context *cnt, struct video_dev *viddev, i
|
||||
{
|
||||
int dev_bktr = viddev->fd_bktr;
|
||||
struct sigaction act, old;
|
||||
//int dev_tunner=viddev->fd_tuner;
|
||||
//int dev_tunner = viddev->fd_tuner;
|
||||
/* to ensure that all device will be support the capture mode
|
||||
_TODO_ : Autodected the best capture mode .
|
||||
*/
|
||||
@@ -603,14 +599,14 @@ static unsigned char *v4l_start(struct context *cnt, struct video_dev *viddev, i
|
||||
/* FIXME if we set as input tuner , we need to set option for tuner not for bktr */
|
||||
|
||||
if ( set_input_format(viddev, norm) == -1 ) {
|
||||
motion_log(LOG_ERR, 1, "set input format [%d]",norm);
|
||||
motion_log(LOG_ERR, 1, "set input format [%d]", norm);
|
||||
return (NULL);
|
||||
}
|
||||
|
||||
viddev->norm = norm;
|
||||
|
||||
if (set_geometry(viddev, width, height) == -1) {
|
||||
motion_log(LOG_ERR, 1, "set geometry [%d]x[%d]",width, height);
|
||||
motion_log(LOG_ERR, 1, "set geometry [%d]x[%d]", width, height);
|
||||
return (NULL);
|
||||
}
|
||||
/*
|
||||
@@ -646,11 +642,11 @@ static unsigned char *v4l_start(struct context *cnt, struct video_dev *viddev, i
|
||||
/* That is the buffer size for capture images ,
|
||||
so is dependent of color space of input format / FIXME */
|
||||
|
||||
viddev->v4l_bufsize = (((width*height*3/2)) * sizeof(unsigned char *));
|
||||
viddev->v4l_bufsize = (((width * height * 3 / 2)) * sizeof(unsigned char *));
|
||||
viddev->v4l_fmt = VIDEO_PALETTE_YUV420P;
|
||||
|
||||
|
||||
map = mmap((caddr_t)0,viddev->v4l_bufsize,PROT_READ|PROT_WRITE,MAP_SHARED, dev_bktr, (off_t)0);
|
||||
map = mmap((caddr_t)0, viddev->v4l_bufsize, PROT_READ|PROT_WRITE, MAP_SHARED, dev_bktr, (off_t)0);
|
||||
|
||||
if (map == MAP_FAILED){
|
||||
motion_log(LOG_ERR, 1, "mmap failed");
|
||||
@@ -661,14 +657,14 @@ static unsigned char *v4l_start(struct context *cnt, struct video_dev *viddev, i
|
||||
if (0) {
|
||||
viddev->v4l_maxbuffer = 2;
|
||||
viddev->v4l_buffers[0] = map;
|
||||
viddev->v4l_buffers[1] = (unsigned char *)map+0; /* 0 is not valid just a test */
|
||||
//viddev->v4l_buffers[1]=map+vid_buf.offsets[1];
|
||||
viddev->v4l_buffers[1] = (unsigned char *)map + 0; /* 0 is not valid just a test */
|
||||
//viddev->v4l_buffers[1] = map+vid_buf.offsets[1];
|
||||
} else {
|
||||
viddev->v4l_buffers[0] = map;
|
||||
viddev->v4l_maxbuffer = 1;
|
||||
}
|
||||
|
||||
viddev->v4l_curbuffer=0;
|
||||
viddev->v4l_curbuffer = 0;
|
||||
|
||||
/* Clear the buffer */
|
||||
|
||||
@@ -701,7 +697,7 @@ static unsigned char *v4l_start(struct context *cnt, struct video_dev *viddev, i
|
||||
viddev->capture_method = METEOR_CAP_SINGLE;
|
||||
if (ioctl(dev_bktr, METEORCAPTUR, &viddev->capture_method) < 0){
|
||||
motion_log(LOG_ERR, 1, "METEORCAPTUR using single method Error capturing");
|
||||
motion_log(LOG_INFO,0, "METEORCAPTUR using single method Error capturing");
|
||||
motion_log(LOG_INFO, 0, "METEORCAPTUR using single method Error capturing");
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -712,28 +708,28 @@ static unsigned char *v4l_start(struct context *cnt, struct video_dev *viddev, i
|
||||
motion_log(LOG_INFO, 0, "METEORCAPTUR METEOR_CAP_SINGLE");
|
||||
|
||||
// settle , sleep(1) replaced
|
||||
SLEEP(1,0)
|
||||
SLEEP(1, 0);
|
||||
|
||||
/* FIXME*/
|
||||
switch (viddev->v4l_fmt) {
|
||||
case VIDEO_PALETTE_YUV420P:
|
||||
viddev->v4l_bufsize=(width*height*3)/2;
|
||||
viddev->v4l_bufsize = (width * height * 3) / 2;
|
||||
break;
|
||||
case VIDEO_PALETTE_YUV422:
|
||||
viddev->v4l_bufsize=(width*height*2);
|
||||
viddev->v4l_bufsize = (width * height * 2);
|
||||
break;
|
||||
case VIDEO_PALETTE_RGB24:
|
||||
viddev->v4l_bufsize=(width*height*3);
|
||||
viddev->v4l_bufsize = (width * height * 3);
|
||||
break;
|
||||
case VIDEO_PALETTE_GREY:
|
||||
viddev->v4l_bufsize=width*height;
|
||||
viddev->v4l_bufsize = width * height;
|
||||
break;
|
||||
}
|
||||
|
||||
motion_log(LOG_INFO,0,"HUE [%d]",get_hue(dev_bktr,&dummy));
|
||||
motion_log(LOG_INFO,0,"SATURATION [%d]",get_saturation(dev_bktr,&dummy));
|
||||
motion_log(LOG_INFO,0,"BRIGHTNESS [%d]",get_brightness(dev_bktr,&dummy));
|
||||
motion_log(LOG_INFO,0,"CONTRAST [%d]",get_contrast(dev_bktr,&dummy));
|
||||
motion_log(LOG_INFO, 0, "HUE [%d]", get_hue(dev_bktr, &dummy));
|
||||
motion_log(LOG_INFO, 0, "SATURATION [%d]", get_saturation(dev_bktr, &dummy));
|
||||
motion_log(LOG_INFO, 0, "BRIGHTNESS [%d]", get_brightness(dev_bktr, &dummy));
|
||||
motion_log(LOG_INFO, 0, "CONTRAST [%d]", get_contrast(dev_bktr, &dummy));
|
||||
|
||||
return map;
|
||||
}
|
||||
@@ -752,12 +748,12 @@ static unsigned char *v4l_start(struct context *cnt, struct video_dev *viddev, i
|
||||
* -1 Fatal error
|
||||
* 1 Non fatal error (not implemented)
|
||||
*/
|
||||
static int v4l_next(struct video_dev *viddev,unsigned char *map, int width, int height)
|
||||
static int v4l_next(struct video_dev *viddev, unsigned char *map, int width, int height)
|
||||
{
|
||||
int dev_bktr=viddev->fd_bktr;
|
||||
unsigned char *cap_map=NULL;
|
||||
int single = METEOR_CAP_SINGLE;
|
||||
sigset_t set, old;
|
||||
int dev_bktr = viddev->fd_bktr;
|
||||
unsigned char *cap_map = NULL;
|
||||
int single = METEOR_CAP_SINGLE;
|
||||
sigset_t set, old;
|
||||
|
||||
|
||||
/* ONLY MMAP method is used to Capture */
|
||||
@@ -770,12 +766,12 @@ static int v4l_next(struct video_dev *viddev,unsigned char *map, int width, int
|
||||
sigaddset (&set, SIGUSR1);
|
||||
sigaddset (&set, SIGTERM);
|
||||
sigaddset (&set, SIGHUP);
|
||||
pthread_sigmask (SIG_BLOCK, &set, &old);
|
||||
cap_map=viddev->v4l_buffers[viddev->v4l_curbuffer];
|
||||
pthread_sigmask(SIG_BLOCK, &set, &old);
|
||||
cap_map = viddev->v4l_buffers[viddev->v4l_curbuffer];
|
||||
|
||||
viddev->v4l_curbuffer++;
|
||||
if (viddev->v4l_curbuffer >= viddev->v4l_maxbuffer)
|
||||
viddev->v4l_curbuffer=0;
|
||||
viddev->v4l_curbuffer = 0;
|
||||
|
||||
/* capture */
|
||||
|
||||
@@ -792,7 +788,6 @@ static int v4l_next(struct video_dev *viddev,unsigned char *map, int width, int
|
||||
/*undo the signal blocking*/
|
||||
pthread_sigmask (SIG_UNBLOCK, &old, NULL);
|
||||
|
||||
|
||||
switch (viddev->v4l_fmt){
|
||||
case VIDEO_PALETTE_RGB24:
|
||||
rgb24toyuv420p(map, cap_map, width, height);
|
||||
@@ -803,7 +798,6 @@ static int v4l_next(struct video_dev *viddev,unsigned char *map, int width, int
|
||||
default:
|
||||
memcpy(map, cap_map, viddev->v4l_bufsize);
|
||||
}
|
||||
|
||||
|
||||
return 0;
|
||||
}
|
||||
@@ -817,7 +811,7 @@ static void v4l_set_input(struct context *cnt, struct video_dev *viddev, unsigne
|
||||
int i;
|
||||
unsigned long frequnits = freq;
|
||||
|
||||
if (input != viddev->input || width != viddev->width || height!=viddev->height || freq!=viddev->freq){
|
||||
if (input != viddev->input || width != viddev->width || height != viddev->height || freq != viddev->freq){
|
||||
if (set_input(viddev, input) == -1)
|
||||
return;
|
||||
|
||||
@@ -837,7 +831,7 @@ static void v4l_set_input(struct context *cnt, struct video_dev *viddev, unsigne
|
||||
}
|
||||
*/
|
||||
|
||||
viddev->norm=norm;
|
||||
viddev->norm = norm;
|
||||
|
||||
if (set_geometry(viddev, width, height) == -1)
|
||||
return;
|
||||
@@ -850,7 +844,7 @@ static void v4l_set_input(struct context *cnt, struct video_dev *viddev, unsigne
|
||||
viddev->freq = freq;
|
||||
|
||||
/* skip a few frames if needed */
|
||||
for (i=0; i<skip; i++)
|
||||
for (i = 0; i < skip; i++)
|
||||
v4l_next(viddev, map, width, height);
|
||||
}else{
|
||||
/* No round robin - we only adjust picture controls */
|
||||
@@ -960,7 +954,7 @@ void vid_close(struct context *cnt)
|
||||
}
|
||||
|
||||
|
||||
munmap(viddevs->v4l_buffers[0],viddevs->v4l_bufsize);
|
||||
munmap(viddevs->v4l_buffers[0], viddevs->v4l_bufsize);
|
||||
viddevs->v4l_buffers[0] = MAP_FAILED;
|
||||
|
||||
dev->fd_bktr = -1;
|
||||
@@ -1005,7 +999,7 @@ int vid_start(struct context *cnt)
|
||||
}
|
||||
#ifdef WITHOUT_V4L
|
||||
else
|
||||
motion_log(LOG_ERR, 0,"You must setup netcam_url");
|
||||
motion_log(LOG_ERR, 0, "You must setup netcam_url");
|
||||
#else
|
||||
else{
|
||||
struct video_dev *dev;
|
||||
@@ -1085,10 +1079,10 @@ int vid_start(struct context *cnt)
|
||||
dev = mymalloc(sizeof(struct video_dev));
|
||||
memset(dev, 0, sizeof(struct video_dev));
|
||||
|
||||
fd_bktr=open(conf->video_device, O_RDWR);
|
||||
fd_bktr = open(conf->video_device, O_RDWR);
|
||||
|
||||
if (fd_bktr < 0) {
|
||||
motion_log(LOG_ERR, 1, "open video device %s",conf->video_device);
|
||||
motion_log(LOG_ERR, 1, "open video device %s", conf->video_device);
|
||||
free(dev);
|
||||
pthread_mutex_unlock(&vid_mutex);
|
||||
return -1;
|
||||
@@ -1097,9 +1091,9 @@ int vid_start(struct context *cnt)
|
||||
|
||||
/* 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);
|
||||
fd_tuner = open(conf->tuner_device, O_RDWR);
|
||||
if (fd_tuner < 0) {
|
||||
motion_log(LOG_ERR, 1, "open tuner device %s",conf->tuner_device);
|
||||
motion_log(LOG_ERR, 1, "open tuner device %s", conf->tuner_device);
|
||||
free(dev);
|
||||
pthread_mutex_unlock(&vid_mutex);
|
||||
return -1;
|
||||
@@ -1145,7 +1139,7 @@ int vid_start(struct context *cnt)
|
||||
return -1;
|
||||
}
|
||||
|
||||
cnt->imgs.type=dev->v4l_fmt;
|
||||
cnt->imgs.type = dev->v4l_fmt;
|
||||
|
||||
switch (cnt->imgs.type) {
|
||||
case VIDEO_PALETTE_GREY:
|
||||
@@ -1214,7 +1208,7 @@ int vid_next(struct context *cnt, unsigned char *map)
|
||||
pthread_mutex_lock(&vid_mutex);
|
||||
dev = viddevs;
|
||||
while (dev){
|
||||
if (dev->fd_bktr==dev_bktr)
|
||||
if (dev->fd_bktr == dev_bktr)
|
||||
break;
|
||||
dev = dev->next;
|
||||
}
|
||||
@@ -1224,7 +1218,7 @@ int vid_next(struct context *cnt, unsigned char *map)
|
||||
return V4L_FATAL_ERROR;
|
||||
//return -1;
|
||||
|
||||
if (dev->owner!=cnt->threadnr) {
|
||||
if (dev->owner != cnt->threadnr) {
|
||||
pthread_mutex_lock(&dev->mutex);
|
||||
dev->owner = cnt->threadnr;
|
||||
dev->frames = conf->roundrobin_frames;
|
||||
|
||||
@@ -122,8 +122,8 @@ struct video_dev {
|
||||
|
||||
/* video functions, video_freebsd.c */
|
||||
int vid_start(struct context *);
|
||||
int vid_next(struct context *, unsigned char *map);
|
||||
void vid_close(struct context *cnt);
|
||||
int vid_next(struct context *, unsigned char *);
|
||||
void vid_close(struct context *);
|
||||
|
||||
#ifndef WITHOUT_V4L
|
||||
void vid_init(void);
|
||||
|
||||
168
webcam.c
168
webcam.c
@@ -19,15 +19,12 @@
|
||||
*/
|
||||
|
||||
#include "picture.h"
|
||||
//#include <sys/time.h>
|
||||
#include <sys/socket.h>
|
||||
#include <netinet/in.h>
|
||||
#include <arpa/inet.h>
|
||||
#include <netdb.h>
|
||||
#include <ctype.h>
|
||||
#include <sys/fcntl.h>
|
||||
//#include <sys/stat.h>
|
||||
|
||||
|
||||
|
||||
|
||||
/* This function sets up a TCP/IP socket for incoming requests. It is called only during
|
||||
@@ -38,35 +35,70 @@
|
||||
*/
|
||||
int http_bindsock(int port, int local)
|
||||
{
|
||||
int sl, optval=1;
|
||||
struct sockaddr_in sin;
|
||||
int sl = -1, optval;
|
||||
struct addrinfo hints, *res, *ressave;
|
||||
char portnumber[10], hbuf[NI_MAXHOST], sbuf[NI_MAXSERV];
|
||||
|
||||
if ((sl=socket(PF_INET, SOCK_STREAM, 0))<0) {
|
||||
motion_log(LOG_ERR, 1, "socket()");
|
||||
|
||||
snprintf(portnumber, sizeof(portnumber), "%u", port);
|
||||
|
||||
memset(&hints, 0, sizeof(struct addrinfo));
|
||||
/* Use the AI_PASSIVE flag, which indicates we are using this address for a listen() */
|
||||
hints.ai_flags = AI_PASSIVE;
|
||||
hints.ai_family = AF_UNSPEC;
|
||||
hints.ai_socktype = SOCK_STREAM;
|
||||
|
||||
optval = getaddrinfo(local ? "localhost" : NULL, portnumber, &hints, &res);
|
||||
|
||||
if (optval != 0) {
|
||||
motion_log(LOG_ERR, 1, "getaddrinfo() for webcam socket failed: %s", gai_strerror(optval));
|
||||
freeaddrinfo(res);
|
||||
return -1;
|
||||
}
|
||||
|
||||
memset(&sin, 0, sizeof(struct sockaddr_in));
|
||||
sin.sin_family=AF_INET;
|
||||
sin.sin_port=htons(port);
|
||||
ressave = res;
|
||||
|
||||
while (res) {
|
||||
/* create socket */
|
||||
sl = socket(res->ai_family, res->ai_socktype, res->ai_protocol);
|
||||
|
||||
getnameinfo(res->ai_addr, res->ai_addrlen, hbuf,
|
||||
sizeof(hbuf), sbuf, sizeof(sbuf), NI_NUMERICHOST | NI_NUMERICSERV);
|
||||
|
||||
if (sl >= 0) {
|
||||
optval = 1;
|
||||
/* Reuse Address */
|
||||
setsockopt(sl, SOL_SOCKET, SO_REUSEADDR, &optval, sizeof( int ) );
|
||||
|
||||
motion_log(LOG_INFO, 0, "webcam 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(LOG_INFO, 0, "webcam Binded : %s addr: %s port: %s",
|
||||
res->ai_family == AF_INET ? "IPV4":"IPV6", hbuf, sbuf);
|
||||
break;
|
||||
}
|
||||
|
||||
motion_log(LOG_ERR, 1, "webcam bind() failed, retrying ");
|
||||
close(sl);
|
||||
sl = -1;
|
||||
}
|
||||
motion_log(LOG_ERR, 1, "webcam socket failed, retrying");
|
||||
res = res->ai_next;
|
||||
}
|
||||
|
||||
freeaddrinfo(ressave);
|
||||
|
||||
if (sl < 0) {
|
||||
motion_log(LOG_ERR, 1, "webcam creating socket/bind ERROR");
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (local)
|
||||
sin.sin_addr.s_addr=htonl(INADDR_LOOPBACK);
|
||||
else
|
||||
sin.sin_addr.s_addr=htonl(INADDR_ANY);
|
||||
|
||||
setsockopt(sl, SOL_SOCKET, SO_REUSEADDR, &optval, sizeof(optval));
|
||||
|
||||
if (bind(sl, (struct sockaddr *)&sin, sizeof(struct sockaddr_in))==-1) {
|
||||
motion_log(LOG_ERR, 1, "bind()");
|
||||
if (listen(sl, DEF_MAXWEBQUEUE) == -1) {
|
||||
motion_log(LOG_ERR, 1, "webcam listen() ERROR");
|
||||
close(sl);
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (listen(sl, DEF_MAXWEBQUEUE)==-1) {
|
||||
motion_log(LOG_ERR, 1, "listen()");
|
||||
close(sl);
|
||||
return -1;
|
||||
sl = -1;
|
||||
}
|
||||
|
||||
return sl;
|
||||
@@ -77,16 +109,16 @@ static int http_acceptsock(int sl)
|
||||
{
|
||||
int sc;
|
||||
unsigned long i;
|
||||
struct sockaddr_in sin;
|
||||
socklen_t addrlen=sizeof(struct sockaddr_in);
|
||||
struct sockaddr_storage sin;
|
||||
socklen_t addrlen = sizeof(sin);
|
||||
|
||||
if ((sc=accept(sl, (struct sockaddr *)&sin, &addrlen))>=0) {
|
||||
i=1;
|
||||
if ((sc = accept(sl, (struct sockaddr *)&sin, &addrlen)) >= 0) {
|
||||
i = 1;
|
||||
ioctl(sc, FIONBIO, &i);
|
||||
return sc;
|
||||
}
|
||||
|
||||
motion_log(LOG_ERR, 1, "accept()");
|
||||
motion_log(LOG_ERR, 1, "motion-stream accept()");
|
||||
|
||||
return -1;
|
||||
}
|
||||
@@ -126,15 +158,15 @@ static void webcam_flush(struct webcam *list, int *stream_count, int lim)
|
||||
* 'filepos' contains how much of the buffer
|
||||
* has already been written.
|
||||
*/
|
||||
written=write(client->socket,
|
||||
written = write(client->socket,
|
||||
client->tmpbuffer->ptr + client->filepos,
|
||||
client->tmpbuffer->size - client->filepos);
|
||||
|
||||
/* If any data has been written, update the
|
||||
* data pointer and set the workdone flag
|
||||
*/
|
||||
if (written>0) {
|
||||
client->filepos+=written;
|
||||
if (written > 0) {
|
||||
client->filepos += written;
|
||||
workdone = 1;
|
||||
}
|
||||
} else
|
||||
@@ -146,7 +178,7 @@ static void webcam_flush(struct webcam *list, int *stream_count, int lim)
|
||||
* finished.
|
||||
*/
|
||||
if ( (client->filepos >= client->tmpbuffer->size) ||
|
||||
(written < 0 && errno!=EAGAIN)) {
|
||||
(written < 0 && errno != EAGAIN)) {
|
||||
/* If no other clients need this buffer, free it */
|
||||
if (--client->tmpbuffer->ref <= 0) {
|
||||
free(client->tmpbuffer->ptr);
|
||||
@@ -154,7 +186,7 @@ static void webcam_flush(struct webcam *list, int *stream_count, int lim)
|
||||
}
|
||||
|
||||
/* Mark this client's buffer as empty */
|
||||
client->tmpbuffer=NULL;
|
||||
client->tmpbuffer = NULL;
|
||||
client->nr++;
|
||||
}
|
||||
|
||||
@@ -163,18 +195,18 @@ static void webcam_flush(struct webcam *list, int *stream_count, int lim)
|
||||
* greater than our configuration limit, disconnect
|
||||
* the client and free the webcam struct
|
||||
*/
|
||||
if ( (written<0 && errno!=EAGAIN) ||
|
||||
(lim && !client->tmpbuffer && client->nr>lim) ) {
|
||||
if ( (written < 0 && errno != EAGAIN) ||
|
||||
(lim && !client->tmpbuffer && client->nr > lim) ) {
|
||||
void *tmp;
|
||||
|
||||
close(client->socket);
|
||||
|
||||
if (client->next)
|
||||
client->next->prev=client->prev;
|
||||
client->next->prev = client->prev;
|
||||
|
||||
client->prev->next=client->next;
|
||||
tmp=client;
|
||||
client=client->prev;
|
||||
client->prev->next = client->next;
|
||||
tmp = client;
|
||||
client = client->prev;
|
||||
free(tmp);
|
||||
(*stream_count)--;
|
||||
}
|
||||
@@ -198,9 +230,9 @@ static void webcam_flush(struct webcam *list, int *stream_count, int lim)
|
||||
*/
|
||||
static struct webcam_buffer *webcam_tmpbuffer(int size)
|
||||
{
|
||||
struct webcam_buffer *tmpbuffer=mymalloc(sizeof(struct webcam_buffer));
|
||||
tmpbuffer->ref=0;
|
||||
tmpbuffer->ptr=mymalloc(size);
|
||||
struct webcam_buffer *tmpbuffer = mymalloc(sizeof(struct webcam_buffer));
|
||||
tmpbuffer->ref = 0;
|
||||
tmpbuffer->ptr = mymalloc(size);
|
||||
|
||||
return tmpbuffer;
|
||||
}
|
||||
@@ -219,7 +251,7 @@ static void webcam_add_client(struct webcam *list, int sc)
|
||||
"Content-Type: multipart/x-mixed-replace; boundary=--BoundaryString\r\n\r\n";
|
||||
|
||||
memset(new, 0, sizeof(struct webcam));
|
||||
new->socket=sc;
|
||||
new->socket = sc;
|
||||
|
||||
if ((new->tmpbuffer = webcam_tmpbuffer(sizeof(header))) == NULL) {
|
||||
motion_log(LOG_ERR, 1, "Error creating tmpbuffer in webcam_add_client");
|
||||
@@ -228,13 +260,13 @@ static void webcam_add_client(struct webcam *list, int sc)
|
||||
new->tmpbuffer->size = sizeof(header)-1;
|
||||
}
|
||||
|
||||
new->prev=list;
|
||||
new->next=list->next;
|
||||
new->prev = list;
|
||||
new->next = list->next;
|
||||
|
||||
if (new->next)
|
||||
new->next->prev=new;
|
||||
new->next->prev = new;
|
||||
|
||||
list->next=new;
|
||||
list->next = new;
|
||||
}
|
||||
|
||||
|
||||
@@ -244,20 +276,20 @@ static void webcam_add_write(struct webcam *list, struct webcam_buffer *tmpbuffe
|
||||
unsigned long int curtime;
|
||||
|
||||
gettimeofday(&curtimeval, NULL);
|
||||
curtime=curtimeval.tv_usec+1000000L*curtimeval.tv_sec;
|
||||
curtime = curtimeval.tv_usec + 1000000L * curtimeval.tv_sec;
|
||||
|
||||
while (list->next) {
|
||||
list=list->next;
|
||||
list = list->next;
|
||||
|
||||
if (list->tmpbuffer==NULL && ((curtime-list->last) >= 1000000L/fps)) {
|
||||
list->last=curtime;
|
||||
list->tmpbuffer=tmpbuffer;
|
||||
if (list->tmpbuffer == NULL && ((curtime - list->last) >= 1000000L / fps)) {
|
||||
list->last = curtime;
|
||||
list->tmpbuffer = tmpbuffer;
|
||||
tmpbuffer->ref++;
|
||||
list->filepos=0;
|
||||
list->filepos = 0;
|
||||
}
|
||||
}
|
||||
|
||||
if (tmpbuffer->ref<=0) {
|
||||
if (tmpbuffer->ref <= 0) {
|
||||
free(tmpbuffer->ptr);
|
||||
free(tmpbuffer);
|
||||
}
|
||||
@@ -272,9 +304,9 @@ static void webcam_add_write(struct webcam *list, struct webcam_buffer *tmpbuffe
|
||||
static int webcam_check_write(struct webcam *list)
|
||||
{
|
||||
while (list->next) {
|
||||
list=list->next;
|
||||
list = list->next;
|
||||
|
||||
if (list->tmpbuffer==NULL)
|
||||
if (list->tmpbuffer == NULL)
|
||||
return 1;
|
||||
}
|
||||
return 0;
|
||||
@@ -287,9 +319,9 @@ static int webcam_check_write(struct webcam *list)
|
||||
*/
|
||||
int webcam_init(struct context *cnt)
|
||||
{
|
||||
cnt->webcam.socket=http_bindsock(cnt->conf.webcam_port, cnt->conf.webcam_localhost);
|
||||
cnt->webcam.next=NULL;
|
||||
cnt->webcam.prev=NULL;
|
||||
cnt->webcam.socket = http_bindsock(cnt->conf.webcam_port, cnt->conf.webcam_localhost);
|
||||
cnt->webcam.next = NULL;
|
||||
cnt->webcam.prev = NULL;
|
||||
return cnt->webcam.socket;
|
||||
}
|
||||
|
||||
@@ -310,8 +342,8 @@ void webcam_stop(struct context *cnt)
|
||||
cnt->webcam.socket = -1;
|
||||
|
||||
while (next) {
|
||||
list=next;
|
||||
next=list->next;
|
||||
list = next;
|
||||
next = list->next;
|
||||
|
||||
if (list->tmpbuffer) {
|
||||
free(list->tmpbuffer->ptr);
|
||||
@@ -347,7 +379,7 @@ void webcam_put(struct context *cnt, unsigned char *image)
|
||||
struct timeval timeout;
|
||||
struct webcam_buffer *tmpbuffer;
|
||||
fd_set fdread;
|
||||
int sl=cnt->webcam.socket;
|
||||
int sl = cnt->webcam.socket;
|
||||
int sc;
|
||||
/* the following string has an extra 16 chars at end for length */
|
||||
const char jpeghead[] = "--BoundaryString\r\n"
|
||||
@@ -359,8 +391,8 @@ void webcam_put(struct context *cnt, unsigned char *image)
|
||||
/* 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;
|
||||
timeout.tv_sec = 0;
|
||||
timeout.tv_usec = 0;
|
||||
FD_ZERO(&fdread);
|
||||
FD_SET(cnt->webcam.socket, &fdread);
|
||||
|
||||
@@ -372,7 +404,7 @@ void webcam_put(struct context *cnt, unsigned char *image)
|
||||
*/
|
||||
if ((cnt->stream_count < DEF_MAXSTREAMS) &&
|
||||
(select(sl+1, &fdread, NULL, NULL, &timeout)>0)) {
|
||||
sc=http_acceptsock(sl);
|
||||
sc = http_acceptsock(sl);
|
||||
webcam_add_client(&cnt->webcam, sc);
|
||||
cnt->stream_count++;
|
||||
}
|
||||
|
||||
477
webhttpd.c
477
webhttpd.c
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user