diff -ur xawtv-3.94.orig/console/Subdir.mk xawtv-3.94/console/Subdir.mk --- xawtv-3.94.orig/console/Subdir.mk 2005-01-16 02:24:06.000000000 +0900 +++ xawtv-3.94/console/Subdir.mk 2005-01-16 18:02:14.000000000 +0900 @@ -6,7 +6,8 @@ console/showriff \ console/showqt \ console/streamer \ - console/webcam + console/webcam \ + console/webcam.cgi TARGETS-v4l-conf := ifeq ($(FOUND_ZVBI),yes) @@ -58,6 +59,10 @@ common/parseconfig.o \ libng/libng.a +console/webcam.cgi: \ + console/webcam.cgi.o \ + libng/libng.a + console/v4l-info: \ console/v4l-info.o \ structs/struct-dump.o \ @@ -79,6 +84,7 @@ console/scantv : LDLIBS += $(THREAD_LIBS) $(VBI_LIBS) -ljpeg console/streamer : LDLIBS += $(THREAD_LIBS) -ljpeg -lm console/webcam : LDLIBS += $(THREAD_LIBS) -ljpeg -lm +console/webcam.cgi : LDLIBS += $(THREAD_LIBS) -ljpeg -lm console/radio : LDLIBS += $(CURSES_LIBS) console/record : LDLIBS += $(CURSES_LIBS) console/v4l-conf : LDLIBS += $(ATHENA_LIBS) @@ -89,6 +95,7 @@ console/scantv : LDFLAGS := $(DLFLAGS) console/streamer : LDFLAGS := $(DLFLAGS) console/webcam : LDFLAGS := $(DLFLAGS) +console/webcam.cgi : LDFLAGS := $(DLFLAGS) # global targets all:: $(TARGETS-console) $(TARGETS-v4l-conf) diff -ur xawtv-3.94.orig/console/webcam.c xawtv-3.94/console/webcam.c --- xawtv-3.94.orig/console/webcam.c 2005-01-16 02:24:06.000000000 +0900 +++ xawtv-3.94/console/webcam.c 2005-01-16 21:20:00.000000000 +0900 @@ -6,6 +6,10 @@ * */ +/* + * Modified for CGI(webcam.cgi) by Suzuki Hironobu. 15 Jan 2005. + */ + #include #include #include @@ -22,17 +26,23 @@ #include "grab-ng.h" #include "jpeglib.h" + +#ifndef _CGI #include "ftp.h" #include "parseconfig.h" #include "list.h" - +#endif /* ---------------------------------------------------------------------- */ /* configuration */ +#ifndef _CGI int daemonize = 0; +#endif char *archive = NULL; +#ifndef _CGI char *tmpdir; +#endif struct list_head connections; char *grab_text = "webcam %Y-%m-%d %H:%M:%S"; /* strftime */ @@ -61,6 +71,37 @@ /* ---------------------------------------------------------------------- */ /* jpeg stuff */ +#ifdef _CGI +static int +write_data(char *data, int width, int height) +{ + struct jpeg_compress_struct cinfo; + struct jpeg_error_mgr jerr; + int i; + unsigned char *line; + + cinfo.err = jpeg_std_error(&jerr); + jpeg_create_compress(&cinfo); + jpeg_stdio_dest(&cinfo, stdout); + cinfo.image_width = width; + cinfo.image_height = height; + cinfo.input_components = 3; + cinfo.in_color_space = JCS_RGB; + jpeg_set_defaults(&cinfo); + jpeg_set_quality(&cinfo, grab_quality, TRUE); + jpeg_start_compress(&cinfo, TRUE); + + for (i = 0, line = data; i < height; i++, line += width*3) + jpeg_write_scanlines(&cinfo, &line, 1); + + jpeg_finish_compress(&(cinfo)); + jpeg_destroy_compress(&(cinfo)); + + return 0; +} + +#else + static int write_file(int fd, char *data, int width, int height) { @@ -282,6 +323,8 @@ close: local_close, }; +#endif + /* ---------------------------------------------------------------------- */ /* capture stuff */ @@ -514,6 +557,8 @@ /* ---------------------------------------------------------------------- */ +#ifndef _CGI + static unsigned int compare_images(unsigned char *last, unsigned char *current, int width, int height) @@ -534,6 +579,7 @@ return max; } +#endif static unsigned char * rotate_image(unsigned char * in, int *wp, int *hp, int rot, @@ -609,7 +655,7 @@ return rotimg; } - +#ifndef _CGI /* ---------------------------------------------------------------------- */ static int make_dirs(char *filename) @@ -635,6 +681,10 @@ return retval; } +#endif + +#ifndef _CGI + int main(int argc, char *argv[]) { @@ -905,3 +955,145 @@ } return 0; } + +#else + +static void +set_param (char *query) +{ + int i; + char *ptrptr; + char *name = NULL; + char *value = NULL; + + name = strtok_r (query, "=", &ptrptr); + value = strtok_r (NULL, "", &ptrptr); + + if (strcmp(name, "device") == 0) ng_dev.video = value; + else if (strcmp(name, "text") == 0) grab_text = value; + else if (strcmp(name, "input") == 0) grab_input = value; + else if (strcmp(name, "norm") == 0) grab_norm = value; + else if (strcmp(name, "width") == 0) grab_width = atoi(value); + else if (strcmp(name, "height") == 0) grab_height = atoi(value); + else if (strcmp(name, "rotate") == 0) grab_rotate = atoi(value); + else if (strcmp(name, "top") == 0) grab_top = atoi(value); + else if (strcmp(name, "left") == 0) grab_left = atoi(value); + else if (strcmp(name, "bottom") == 0) grab_bottom = atoi(value); + else if (strcmp(name, "right") == 0) grab_right = atoi(value); + else if (strcmp(name, "quality") == 0) grab_quality = atoi(value); + else if (strcmp(name, "fg_red") == 0) { + i = atoi(value); + if (i >= 0 && i <= 255) grab_fg_r = i; + } + else if (strcmp(name, "fg_green") == 0) { + i = atoi(value); + if (i >= 0 && i <= 255) grab_fg_g = i; + } + else if (strcmp(name, "fg_blue") == 0) { + i = atoi(value); + if (i >= 0 && i <= 255) grab_fg_b = i; + } + else if (strcmp(name, "bg_red") == 0) { + i = atoi(value); + if (i >= 0 && i <= 255) grab_bg_r = i; + } + else if (strcmp(name, "bg_green") == 0) { + i = atoi(value); + if (i >= 0 && i <= 255) grab_bg_g = i; + } + else if (strcmp(name, "bg_blue") == 0) { + i = atoi(value); + if (i >= 0 && i <= 255) grab_bg_b = i; + } + else if (strcmp(name, "distor") == 0) grab_dist_on = atoi(value); + else if (strcmp(name, "distor_k") == 0) grab_dist_k = atoi(value); + else if (strcmp(name, "distor_cx") == 0) grab_dist_cx = atoi(value); + else if (strcmp(name, "distor_cy") == 0) grab_dist_cy = atoi(value); + else if (strcmp(name, "distor_zoom") == 0) grab_dist_zoom = atoi(value); + else if (strcmp(name, "distor_sensorw") == 0) grab_dist_sensorw = atoi(value); + else if (strcmp(name, "distor_sensorh") == 0) grab_dist_sensorh = atoi(value); +} + +static void +parse_query (unsigned char *query_string) +{ + char *ptr = NULL; + char *ptrptr; + + ptr = strtok_r (query_string, "&", &ptrptr); + + if (ptr != NULL) { + set_param (ptr); + while ((ptr = strtok_r (NULL, "&", &ptrptr)) != NULL) { + set_param (ptr); + } + } +} + + +int +main(int argc, char *argv[]) +{ + unsigned char *image,*gimg = NULL; + unsigned char query[512] = "\0"; + int debug_flag = 0; + int width, height; + + ng_init(); + + if (NULL != getenv("QUERY_STRING")) { + sprintf(query, "%s", getenv("QUERY_STRING")); + parse_query(query); + } + + /* defaults */ + if (grab_top < 0) grab_top = 0; + if (grab_left < 0) grab_left = 0; + if (grab_bottom < 0) grab_bottom = grab_height; + if (grab_right < 0) grab_right = grab_width; + if (grab_bottom > grab_height) grab_bottom = grab_height; + if (grab_right > grab_width) grab_right = grab_width; + if (grab_top >= grab_bottom) { + fprintf(stderr, "config error: top must be smaller than bottom\n"); + exit(1); + } + if (grab_left >= grab_right) { + fprintf(stderr, "config error: left must be smaller than right\n"); + exit(1); + } + + if (grab_dist_k < 1 || grab_dist_k > 10000) grab_dist_k = 700; + if (grab_dist_cx < 0 || grab_dist_cx > grab_width) grab_dist_cx = grab_width / 2; + if (grab_dist_cy < 0 || grab_dist_cy > grab_height) grab_dist_cy = grab_height / 2; + if (grab_dist_zoom < 1 || grab_dist_zoom > 1000) grab_dist_zoom = 100; + if (grab_dist_sensorw < 1 || grab_dist_sensorw >9999) grab_dist_sensorw = 640; + if (grab_dist_sensorh < 1 || grab_dist_sensorh >9999) grab_dist_sensorh = 480; + + INIT_LIST_HEAD(&connections); + + /* init everything */ + grab_init(); + + /* grab a new one */ + gimg = grab_one(&width,&height); + + if (grab_dist_on) + gimg = correct_distor(gimg, width, height, + grab_dist_zoom, grab_dist_k, + grab_dist_cx, grab_dist_cy, + grab_dist_sensorw, grab_dist_sensorh); + + image = rotate_image(gimg, &width, &height, grab_rotate, + grab_top, grab_left, grab_bottom, grab_right); + + add_text(image,width,height); + + if (debug_flag == 0) + printf ("Content-type: image/jpg\n\n"); + + write_data(image, width, height); + + return 0; +} + +#endif diff -ur xawtv-3.94.orig/mk/Compile.mk xawtv-3.94/mk/Compile.mk --- xawtv-3.94.orig/mk/Compile.mk 2005-01-16 02:24:34.000000000 +0900 +++ xawtv-3.94/mk/Compile.mk 2005-01-16 18:02:14.000000000 +0900 @@ -21,6 +21,7 @@ depfiles = mk/*.dep compile_c = $(CC) $(CFLAGS) -Wp,-MD,$(tmpdep) -c -o $@ $< +compile_c_d = $(CC) -D_CGI $(CFLAGS) -Wp,-MD,$(tmpdep) -c -o $@ $< compile_cc = $(CXX) $(CXXFLAGS) -Wp,-MD,$(tmpdep) -c -o $@ $< fixup_deps = sed -e "s|.*\.o:|$@:|" < $(tmpdep) > $(depfile) && rm -f $(tmpdep) @@ -50,6 +51,11 @@ echo_msgfmt_po = echo $(msgfmt_po) endif +%.cgi.o: %.c + @$(echo_compile_c) + @$(compile_c_d) + @$(fixup_deps) + %.o: %.c @$(echo_compile_c) @$(compile_c)