setpwc-1.3/0000755000175000017500000000000011566013133012557 5ustar folkertfolkertsetpwc-1.3/Makefile0000644000175000017500000000233411566013133014221 0ustar folkertfolkert# The GPL applies to this program. # In addition, as a special exception, the copyright holders give # permission to link the code of portions of this program with the # OpenSSL library under certain conditions as described in each # individual source file, and distribute linked combinations # including the two. # You must obey the GNU General Public License in all respects # for all of the code used other than OpenSSL. If you modify # file(s) with this exception, you may extend this exception to your # version of the file(s), but you are not obligated to do so. If you # do not wish to do so, delete this exception statement from your # version. If you delete this exception statement from all source # files in the program, then also delete it here. VERSION=1.3 CFLAGS+=-Wall -O2 -DVERSION=\"$(VERSION)\" LDFLAGS= OBJS=setpwc.o all: setpwc setpwc: $(OBJS) $(CC) -Wall -W $(OBJS) $(LDFLAGS) -o setpwc # # Oh, blatant plug: http://keetweej.vanheusden.com/wishlist.html install: setpwc cp setpwc /usr/bin clean: rm -f $(OBJS) setpwc core package: clean mkdir setpwc-$(VERSION) cp *.c *.h setpwc.1 readme.txt Makefile license.txt setpwc-$(VERSION) tar czf setpwc-$(VERSION).tgz setpwc-$(VERSION) rm -rf setpwc-$(VERSION) setpwc-1.3/pwc-ioctl.h0000644000175000017500000002237311566013133014640 0ustar folkertfolkert#ifndef PWC_IOCTL_H #define PWC_IOCTL_H /* (C) 2001-2004 Nemosoft Unv. (C) 2004 Luc Saillard (luc@saillard.org) NOTE: this version of pwc is an unofficial (modified) release of pwc & pcwx driver and thus may have bugs that are not present in the original version. Please send bug reports and support requests to . The decompression routines have been implemented by reverse-engineering the Nemosoft binary pwcx module. Caveat emptor. This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ /* This is pwc-ioctl.h belonging to PWC 8.12.1 It contains structures and defines to communicate from user space directly to the driver. */ /* Changes 2001/08/03 Alvarado Added ioctl constants to access methods for changing white balance and red/blue gains 2002/12/15 G. H. Fernandez-Toribio VIDIOCGREALSIZE 2003/12/13 Nemosft Unv. Some modifications to make interfacing to PWCX easier */ /* These are private ioctl() commands, specific for the Philips webcams. They contain functions not found in other webcams, and settings not specified in the Video4Linux API. The #define names are built up like follows: VIDIOC VIDeo IOCtl prefix PWC Philps WebCam G optional: Get S optional: Set ... the function */ /* Enumeration of image sizes */ #define PSZ_SQCIF 0x00 #define PSZ_QSIF 0x01 #define PSZ_QCIF 0x02 #define PSZ_SIF 0x03 #define PSZ_CIF 0x04 #define PSZ_VGA 0x05 #define PSZ_MAX 6 /* The frame rate is encoded in the video_window.flags parameter using the upper 16 bits, since some flags are defined nowadays. The following defines provide a mask and shift to filter out this value. In 'Snapshot' mode the camera freezes its automatic exposure and colour balance controls. */ #define PWC_FPS_SHIFT 16 #define PWC_FPS_MASK 0x00FF0000 #define PWC_FPS_FRMASK 0x003F0000 #define PWC_FPS_SNAPSHOT 0x00400000 /* structure for transfering x & y coordinates */ struct pwc_coord { int x, y; /* guess what */ int size; /* size, or offset */ }; /* Used with VIDIOCPWCPROBE */ struct pwc_probe { char name[32]; int type; }; struct pwc_serial { char serial[30]; /* String with serial number. Contains terminating 0 */ }; /* pwc_whitebalance.mode values */ #define PWC_WB_INDOOR 0 #define PWC_WB_OUTDOOR 1 #define PWC_WB_FL 2 #define PWC_WB_MANUAL 3 #define PWC_WB_AUTO 4 /* Used with VIDIOCPWC[SG]AWB (Auto White Balance). Set mode to one of the PWC_WB_* values above. *red and *blue are the respective gains of these colour components inside the camera; range 0..65535 When 'mode' == PWC_WB_MANUAL, 'manual_red' and 'manual_blue' are set or read; otherwise undefined. 'read_red' and 'read_blue' are read-only. */ struct pwc_whitebalance { int mode; int manual_red, manual_blue; /* R/W */ int read_red, read_blue; /* R/O */ }; /* 'control_speed' and 'control_delay' are used in automatic whitebalance mode, and tell the camera how fast it should react to changes in lighting, and with how much delay. Valid values are 0..65535. */ struct pwc_wb_speed { int control_speed; int control_delay; }; /* Used with VIDIOCPWC[SG]LED */ struct pwc_leds { int led_on; /* Led on-time; range = 0..25000 */ int led_off; /* Led off-time; range = 0..25000 */ }; /* Image size (used with GREALSIZE) */ struct pwc_imagesize { int width; int height; }; /* Defines and structures for Motorized Pan & Tilt */ #define PWC_MPT_PAN 0x01 #define PWC_MPT_TILT 0x02 #define PWC_MPT_TIMEOUT 0x04 /* for status */ /* Set angles; when absolute != 0, the angle is absolute and the driver calculates the relative offset for you. This can only be used with VIDIOCPWCSANGLE; VIDIOCPWCGANGLE always returns absolute angles. */ struct pwc_mpt_angles { int absolute; /* write-only */ int pan; /* degrees * 100 */ int tilt; /* degress * 100 */ }; /* Range of angles of the camera, both horizontally and vertically. */ struct pwc_mpt_range { int pan_min, pan_max; /* degrees * 100 */ int tilt_min, tilt_max; }; struct pwc_mpt_status { int status; int time_pan; int time_tilt; }; /* This is used for out-of-kernel decompression. With it, you can get all the necessary information to initialize and use the decompressor routines in standalone applications. */ struct pwc_video_command { int type; /* camera type (645, 675, 730, etc.) */ int release; /* release number */ int size; /* one of PSZ_* */ int alternate; int command_len; /* length of USB video command */ unsigned char command_buf[13]; /* Actual USB video command */ int bandlength; /* >0 = compressed */ int frame_size; /* Size of one (un)compressed frame */ }; /* Flags for PWCX subroutines. Not all modules honour all flags. */ #define PWCX_FLAG_PLANAR 0x0001 #define PWCX_FLAG_BAYER 0x0008 /* IOCTL definitions */ /* Restore user settings */ #define VIDIOCPWCRUSER _IO('v', 192) /* Save user settings */ #define VIDIOCPWCSUSER _IO('v', 193) /* Restore factory settings */ #define VIDIOCPWCFACTORY _IO('v', 194) /* You can manipulate the compression factor. A compression preference of 0 means use uncompressed modes when available; 1 is low compression, 2 is medium and 3 is high compression preferred. Of course, the higher the compression, the lower the bandwidth used but more chance of artefacts in the image. The driver automatically chooses a higher compression when the preferred mode is not available. */ /* Set preferred compression quality (0 = uncompressed, 3 = highest compression) */ #define VIDIOCPWCSCQUAL _IOW('v', 195, int) /* Get preferred compression quality */ #define VIDIOCPWCGCQUAL _IOR('v', 195, int) /* Retrieve serial number of camera */ #define VIDIOCPWCGSERIAL _IOR('v', 198, struct pwc_serial) /* This is a probe function; since so many devices are supported, it becomes difficult to include all the names in programs that want to check for the enhanced Philips stuff. So in stead, try this PROBE; it returns a structure with the original name, and the corresponding Philips type. To use, fill the structure with zeroes, call PROBE and if that succeeds, compare the name with that returned from VIDIOCGCAP; they should be the same. If so, you can be assured it is a Philips (OEM) cam and the type is valid. */ #define VIDIOCPWCPROBE _IOR('v', 199, struct pwc_probe) /* Set AGC (Automatic Gain Control); int < 0 = auto, 0..65535 = fixed */ #define VIDIOCPWCSAGC _IOW('v', 200, int) /* Get AGC; int < 0 = auto; >= 0 = fixed, range 0..65535 */ #define VIDIOCPWCGAGC _IOR('v', 200, int) /* Set shutter speed; int < 0 = auto; >= 0 = fixed, range 0..65535 */ #define VIDIOCPWCSSHUTTER _IOW('v', 201, int) /* Color compensation (Auto White Balance) */ #define VIDIOCPWCSAWB _IOW('v', 202, struct pwc_whitebalance) #define VIDIOCPWCGAWB _IOR('v', 202, struct pwc_whitebalance) /* Auto WB speed */ #define VIDIOCPWCSAWBSPEED _IOW('v', 203, struct pwc_wb_speed) #define VIDIOCPWCGAWBSPEED _IOR('v', 203, struct pwc_wb_speed) /* LEDs on/off/blink; int range 0..65535 */ #define VIDIOCPWCSLED _IOW('v', 205, struct pwc_leds) #define VIDIOCPWCGLED _IOR('v', 205, struct pwc_leds) /* Contour (sharpness); int < 0 = auto, 0..65536 = fixed */ #define VIDIOCPWCSCONTOUR _IOW('v', 206, int) #define VIDIOCPWCGCONTOUR _IOR('v', 206, int) /* Backlight compensation; 0 = off, otherwise on */ #define VIDIOCPWCSBACKLIGHT _IOW('v', 207, int) #define VIDIOCPWCGBACKLIGHT _IOR('v', 207, int) /* Flickerless mode; = 0 off, otherwise on */ #define VIDIOCPWCSFLICKER _IOW('v', 208, int) #define VIDIOCPWCGFLICKER _IOR('v', 208, int) /* Dynamic noise reduction; 0 off, 3 = high noise reduction */ #define VIDIOCPWCSDYNNOISE _IOW('v', 209, int) #define VIDIOCPWCGDYNNOISE _IOR('v', 209, int) /* Real image size as used by the camera; tells you whether or not there's a gray border around the image */ #define VIDIOCPWCGREALSIZE _IOR('v', 210, struct pwc_imagesize) /* Motorized pan & tilt functions */ #define VIDIOCPWCMPTRESET _IOW('v', 211, int) #define VIDIOCPWCMPTGRANGE _IOR('v', 211, struct pwc_mpt_range) #define VIDIOCPWCMPTSANGLE _IOW('v', 212, struct pwc_mpt_angles) #define VIDIOCPWCMPTGANGLE _IOR('v', 212, struct pwc_mpt_angles) #define VIDIOCPWCMPTSTATUS _IOR('v', 213, struct pwc_mpt_status) /* Get the USB set-video command; needed for initializing libpwcx */ #define VIDIOCPWCGVIDCMD _IOR('v', 215, struct pwc_video_command) struct pwc_table_init_buffer { int len; char *buffer; }; #define VIDIOCPWCGVIDTABLE _IOR('v', 216, struct pwc_table_init_buffer) #endif setpwc-1.3/setpwc.10000644000175000017500000000327311566013133014153 0ustar folkertfolkert.TH SETPWC 1 "March 13, 2005" .SH NAME setpwc \- program to set settings specific to Philips (and compatibles like Logitech and Creative) WebCams. .SH SYNOPSIS .B setpwc .RI [ options ] .br .SH DESCRIPTION \fBsetpwc\fP is a program that can set and query settings of Philips (and compatibles like Logitech and Creative) WebCams. .SH OPTIONS .TP .B \-h Show summary of options. .TP .B \-p Dump current settings. .TP .B \-d dev Device to use, default /dev/video0. .TP .B \-f x Set framerate, 0-63. .TP .B \-b Store settings in nonvolatile RAM. .TP .B \-r Restore settings from nonvolatile RAM. .TP .B \-x Restore factory settings. .TP .B \-c x Set compression preference, 0-3. .TP .B \-g x Set automatic gain control, 0-65535. .TP .B \-s x Set shutter speed, 1-65535. .TP .B \-w setting Set automatic white balance mode, auto/manual/indoor/outdoor/fl. .TP .B \-a x Set red-balance (only if -w manual), 0-65535. .TP .B \-e x Set blue-balance (idem), 0-65535. .TP .B \-i x Set speed of automatic white balance, 1-65535. .TP .B \-j Set delay for automatic white balance, 1-65535. .TP .B \-k Set led on-time in ms, 0-2550. .TP .B \-l x Set led off-time. .TP .B \-m x Set electronic sharpness, 0-65535. .TP .B \-n x Set backligth compensation, 0=off, other=on. .TP .B \-o x Set antiflicker mode, 0=off, other=on. .TP .B \-q x Set noise reduction mode, 0=none...3=high. .TP .B \-t x Reset pan (bit 0) and/or tilt (bit 1). .TP .B \-u Query pan/tilt status. .TP .B \-y x Set pan position. .TP .B \-x x Set tilt position. .SH AUTHOR setpwc was written by Folkert van Heusden . .PP This manual page was written by Anders Lennartsson . for the Debian project (but may be used by others). setpwc-1.3/setpwc.c0000644000175000017500000005006211566013133014233 0ustar folkertfolkert/* The GPL applies to this program. In addition, as a special exception, the copyright holders give permission to link the code of portions of this program with the OpenSSL library under certain conditions as described in each individual source file, and distribute linked combinations including the two. You must obey the GNU General Public License in all respects for all of the code used other than OpenSSL. If you modify file(s) with this exception, you may extend this exception to your version of the file(s), but you are not obligated to do so. If you do not wish to do so, delete this exception statement from your version. If you delete this exception statement from all source files in the program, then also delete it here. */ #include #include #include #include #include #include #include #include #include #define _LINUX_TIME_H 1 /* to get things compile on kernel 2.6.x */ #include #include "pwc-ioctl.h" char *device = "/dev/video0"; #define SET_PAN 0 #define SET_TILT 1 void error_exit(char *what_ioctl) { fprintf(stderr, "Error while doing ioctl %s: %s\n", what_ioctl, strerror(errno)); /* commented out: some versions of the driver seem to return * unexpected errors */ /* exit(1); */ } void check_device(int *fd) { if (*fd == -1) { /* open device */ *fd = open(device, O_RDWR); if (*fd == -1) { fprintf(stderr, "Error while accessing device %s: %s\n", device, strerror(errno)); exit(1); } } } void not_supported(char *what) { printf("%s is not supported by the combination\n", what); printf("of your webcam and the driver.\n"); } void dump_current_settings_ctrl(int fd, const char *prefix, int id) { struct v4l2_control vctrl; struct v4l2_queryctrl qctrl; struct v4l2_querymenu qmenu; const char *flags[10]; int flags_cnt = 0; memset(&vctrl, 0, sizeof(vctrl)); memset(&qctrl, 0, sizeof(qctrl)); vctrl.id = id; qctrl.id = id; if (ioctl(fd, VIDIOC_G_CTRL, &vctrl) == -1) { printf("%s: VIDIOC_G_CTRL failed: %s\n", prefix, strerror(errno)); return; } if (ioctl(fd, VIDIOC_QUERYCTRL, &qctrl) == -1) { printf("%s: VIDIOC_QUERYCTRL failed: %s\n", prefix, strerror(errno)); return; } if (qctrl.flags & V4L2_CTRL_FLAG_DISABLED) flags[flags_cnt++] = "disabled"; if (qctrl.flags & V4L2_CTRL_FLAG_GRABBED) flags[flags_cnt++] = "grabbed"; if (qctrl.flags & V4L2_CTRL_FLAG_READ_ONLY) flags[flags_cnt++] = "read-only"; if (qctrl.flags & V4L2_CTRL_FLAG_UPDATE) flags[flags_cnt++] = "update"; if (qctrl.flags & V4L2_CTRL_FLAG_INACTIVE) flags[flags_cnt++] = "inactive"; if (qctrl.flags & V4L2_CTRL_FLAG_SLIDER) flags[flags_cnt++] = "slider"; flags[flags_cnt] = NULL; switch (qctrl.type) { case V4L2_CTRL_TYPE_INTEGER: printf("%s: %s\n", prefix, qctrl.name); printf(" Value: %d\n", vctrl.value); printf(" Minimum: %d\n", qctrl.minimum); printf(" Maximum: %d\n", qctrl.maximum); printf(" Step: %d\n", qctrl.step); printf(" Default: %d\n", qctrl.default_value); printf(" Flags: "); for (flags_cnt = 0; flags[flags_cnt]; flags_cnt++) printf("%s%s", flags_cnt ? "," : "", flags[flags_cnt]); printf("\n"); break; case V4L2_CTRL_TYPE_BOOLEAN: printf("%s: %s\n", prefix, qctrl.name); printf(" Value: %s\n", vctrl.value ? "enabled" : "disabled"); printf(" Default: %s\n", qctrl.default_value ? "enabled" : "disabled"); printf(" Flags: "); for (flags_cnt = 0; flags[flags_cnt]; flags_cnt++) printf("%s%s", flags_cnt ? "," : "", flags[flags_cnt]); printf("\n"); break; case V4L2_CTRL_TYPE_MENU: printf("%s: %s\n", prefix, qctrl.name); memset(&qmenu, 0, sizeof(qmenu)); qmenu.id = id; qmenu.index = vctrl.value; if (ioctl(fd, VIDIOC_QUERYMENU, &qmenu) == -1) printf(" Value: ??? (%d)\n", vctrl.value); else printf(" Value: %s (%d)\n", qmenu.name, vctrl.value); memset(&qmenu, 0, sizeof(qmenu)); qmenu.id = id; qmenu.index = qctrl.default_value; if (ioctl(fd, VIDIOC_QUERYMENU, &qmenu) == -1) printf(" Default: ??? (%d)\n", qctrl.default_value); else printf(" Default: %s (%d)\n", qmenu.name, qctrl.default_value); printf(" Flags: "); for (flags_cnt = 0; flags[flags_cnt]; flags_cnt++) printf("%s%s", flags_cnt ? "," : "", flags[flags_cnt]); printf("\n"); break; case V4L2_CTRL_TYPE_BUTTON: printf("%s: %s\n", prefix, qctrl.name); printf(" Unsupport type: button\n"); printf(" Flags: "); for (flags_cnt = 0; flags[flags_cnt]; flags_cnt++) printf("%s%s", flags_cnt ? "," : "", flags[flags_cnt]); printf("\n"); break; case V4L2_CTRL_TYPE_INTEGER64: printf("%s: %s\n", prefix, qctrl.name); printf(" Unsupport type: integer64\n"); printf(" Flags: "); for (flags_cnt = 0; flags[flags_cnt]; flags_cnt++) printf("%s%s", flags_cnt ? "," : "", flags[flags_cnt]); printf("\n"); break; case V4L2_CTRL_TYPE_CTRL_CLASS: printf("%s: %s\n", prefix, qctrl.name); printf(" Unsupport type: class\n"); printf(" Flags: "); for (flags_cnt = 0; flags[flags_cnt]; flags_cnt++) printf("%s%s", flags_cnt ? "," : "", flags[flags_cnt]); printf("\n"); break; case V4L2_CTRL_TYPE_STRING: printf("%s: %s\n", prefix, qctrl.name); printf(" Unsupport type: string\n"); printf(" Flags: "); for (flags_cnt = 0; flags[flags_cnt]; flags_cnt++) printf("%s%s", flags_cnt ? "," : "", flags[flags_cnt]); printf("\n"); break; } } void dump_current_settings(int fd) { struct v4l2_capability vcap; struct v4l2_format pixfmt; struct pwc_probe pwcp; int dummy; struct pwc_whitebalance pwcwb; struct pwc_leds pwcl; struct pwc_mpt_range pmr; struct pwc_mpt_angles pma; struct pwc_serial ps; /* get name */ if (ioctl(fd, VIDIOC_QUERYCAP, &vcap) == -1) error_exit("VIDIOC_QUERYCAP"); printf("Current device: %s (%s @ %s)\n", (const char *)vcap.card, (const char *)vcap.driver, (const char *)vcap.bus_info); /* verify that it IS a Philips Webcam */ if (ioctl(fd, VIDIOCPWCPROBE, &pwcp) == -1) error_exit("VIDIOCPWCPROBE"); if (strcmp((const char *)vcap.card, pwcp.name) != 0) printf("Warning: this might not be a Philips compatible webcam!\n"); printf("VIDIOCPWCPROBE returns: %s - %d\n", pwcp.name, pwcp.type); if (ioctl(fd, VIDIOCPWCGSERIAL, &ps) == -1) error_exit("VIDIOCPWCGSERIAL"); printf("Serial number: %s\n", ps.serial); /* get resolution/framerate */ memset(&pixfmt, 0, sizeof(pixfmt)); pixfmt.type = V4L2_BUF_TYPE_VIDEO_CAPTURE; if (ioctl(fd, VIDIOC_G_FMT, &pixfmt) == -1) error_exit("VIDIOC_G_FMT"); printf("Resolution (x, y): %d, %d\n", pixfmt.fmt.pix.width, pixfmt.fmt.pix.height); if (pixfmt.fmt.pix.priv & PWC_FPS_FRMASK) printf("Framerate: %d\n", (pixfmt.fmt.pix.priv & PWC_FPS_FRMASK) >> PWC_FPS_SHIFT); /* color (etc.) settings */ dump_current_settings_ctrl(fd, "Brightness", V4L2_CID_BRIGHTNESS); dump_current_settings_ctrl(fd, "Hue", V4L2_CID_HUE); dump_current_settings_ctrl(fd, "Colour", V4L2_CID_SATURATION); dump_current_settings_ctrl(fd, "Contrast", V4L2_CID_CONTRAST); dump_current_settings_ctrl(fd, "Whiteness", V4L2_CID_WHITENESS); printf("Palette: "); switch(pixfmt.fmt.pix.pixelformat) { case V4L2_PIX_FMT_GREY: printf("Linear intensity grey scale (255 is brightest).\n"); break; case V4L2_PIX_FMT_HI240: printf("The BT848 8bit colour cube.\n"); break; case V4L2_PIX_FMT_RGB565: printf("RGB565 packed into 16 bit words.\n"); break; case V4L2_PIX_FMT_RGB555: printf("RGV555 packed into 16 bit words, top bit undefined.\n"); break; case V4L2_PIX_FMT_BGR24: printf("RGB888 packed into 24bit words.\n"); break; case V4L2_PIX_FMT_BGR32: printf("RGB888 packed into the low 3 bytes of 32bit words. The top 8bits are undefined.\n"); break; case V4L2_PIX_FMT_YUYV: printf("Video style YUV422 - 8bits packed 4bits Y 2bits U 2bits V\n"); break; case V4L2_PIX_FMT_UYVY: printf("Describe me\n"); break; case V4L2_PIX_FMT_Y41P: printf("YUV411 capture\n"); break; case V4L2_PIX_FMT_YUV422P: printf("YUV 4:2:2 Planar\n"); break; case V4L2_PIX_FMT_YUV411P: printf("YUV 4:1:1 Planar\n"); break; case V4L2_PIX_FMT_YVU420: printf("YUV 4:2:0 Planar\n"); break; case V4L2_PIX_FMT_YVU410: printf("YUV 4:1:0 Planar\n"); break; default: printf("Unknown! (%d - %c%c%c%c)\n", pixfmt.fmt.pix.pixelformat, pixfmt.fmt.pix.pixelformat & 0xff, (pixfmt.fmt.pix.pixelformat >> 8) & 0xff, (pixfmt.fmt.pix.pixelformat >> 16) & 0xff, (pixfmt.fmt.pix.pixelformat >> 24) & 0xff); } if (ioctl(fd, VIDIOCPWCGCQUAL, &dummy) == -1) error_exit("VIDIOCPWCGCQUAL"); printf("Compression preference: %d\n", dummy); if (ioctl(fd, VIDIOCPWCGAGC, &dummy) == -1) error_exit("VIDIOCPWCGAGC"); printf("Automatic gain control: %d\n", dummy); if (ioctl(fd, VIDIOCPWCGAWB, &pwcwb) == -1) error_exit("VIDIOCPWCGAWB"); printf("Whitebalance mode: "); if (pwcwb.mode == PWC_WB_AUTO) printf("auto\n"); else if (pwcwb.mode == PWC_WB_MANUAL) printf("manual (red: %d, blue: %d)\n", pwcwb.manual_red, pwcwb.manual_blue); else if (pwcwb.mode == PWC_WB_INDOOR) printf("indoor\n"); else if (pwcwb.mode == PWC_WB_OUTDOOR) printf("outdoor\n"); else if (pwcwb.mode == PWC_WB_FL) printf("artificial lightning ('fl')\n"); else printf("unknown!\n"); if (ioctl(fd, VIDIOCPWCGLED, &pwcl) != -1) { printf("Led ON time: %d\n", pwcl.led_on); printf("Led OFF time: %d\n", pwcl.led_off); } else { not_supported("Blinking of LED"); } if (ioctl(fd, VIDIOCPWCGCONTOUR, &dummy) == -1) error_exit("VIDIOCPWCGCONTOUR"); printf("Sharpness: %d\n", dummy); if (ioctl(fd, VIDIOCPWCGBACKLIGHT, &dummy) == -1) error_exit("VIDIOCPWCGBACKLIGHT"); printf("Backlight compensation mode: "); if (dummy == 0) printf("off\n"); else printf("on\n"); if (ioctl(fd, VIDIOCPWCGFLICKER, &dummy) != -1) { printf("Anti-flicker mode: "); if (dummy == 0) printf("off\n"); else printf("on\n"); } else { not_supported("Anti-flicker mode"); } if (ioctl(fd, VIDIOCPWCGDYNNOISE, &dummy) != -1) { printf("Noise reduction mode: %d ", dummy); if (dummy == 0) printf("(none)"); else if (dummy == 3) printf("(high)"); printf("\n"); } else { not_supported("Noise reduction mode"); } if (ioctl(fd, VIDIOCPWCMPTGRANGE, &pmr) == -1) { not_supported("Pan/tilt range"); } else { printf("Pan min. : %d, max.: %d\n", pmr.pan_min, pmr.pan_max); printf("Tilt min.: %d, max.: %d\n", pmr.tilt_min, pmr.tilt_max); } pma.absolute=1; if (ioctl(fd, VIDIOCPWCMPTGANGLE, &pma) == -1) { not_supported("Get pan/tilt position"); } else { printf("Pan (degrees * 100): %d\n", pma.pan); printf("Tilt (degrees * 100): %d\n", pma.tilt); } } void query_pan_tilt_status(fd) { struct pwc_mpt_status pms; if (ioctl(fd, VIDIOCPWCMPTSTATUS, &pms) == -1) error_exit("VIDIOCPWCMPTSTATUS"); printf("Status: %d\n", pms.status); printf("Time pan: %d\n", pms.time_pan); printf("Time tilt: %d\n", pms.time_tilt); } void reset_pan_tilt(int fd, int what) { if (ioctl(fd, VIDIOCPWCMPTRESET, &what) == -1) error_exit("VIDIOCPWCMPTRESET"); } void set_pan_or_tilt(int fd, char what, int value) { struct pwc_mpt_angles pma; pma.absolute=1; if (ioctl(fd, VIDIOCPWCMPTGANGLE, &pma) == -1) error_exit("VIDIOCPWCMPTGANGLE"); if (what == SET_PAN) pma.pan = value; else if (what == SET_TILT) pma.tilt = value; if (ioctl(fd, VIDIOCPWCMPTSANGLE, &pma) == -1) error_exit("VIDIOCPWCMPTSANGLE"); } void set_dimensions_and_framerate(int fd, int w, int h, int framerate) { struct v4l2_format pixfmt; /* get resolution/framerate */ if (ioctl(fd, VIDIOC_G_FMT, &pixfmt) == -1) error_exit("VIDIOC_G_FMT"); if (w > 0 && h > 0) { pixfmt.fmt.pix.width = w; pixfmt.fmt.pix.height = h; } if (pixfmt.fmt.pix.priv & PWC_FPS_FRMASK) { /* set new framerate */ pixfmt.fmt.pix.priv &= ~PWC_FPS_FRMASK; pixfmt.fmt.pix.priv |= (framerate << PWC_FPS_SHIFT); if (ioctl(fd, VIDIOC_S_FMT, &pixfmt) == -1) error_exit("VIDIOC_S_FMT"); } else { fprintf(stderr, "This device doesn't support setting the framerate.\n"); exit(1); } } void flash_settings(int fd) { if (ioctl(fd, VIDIOCPWCSUSER) == -1) error_exit("VIDIOCPWCSUSER"); } void restore_settings(int fd) { if (ioctl(fd, VIDIOCPWCRUSER) == -1) error_exit("VIDIOCPWCRUSER"); } void restore_factory_settings(int fd) { if (ioctl(fd, VIDIOCPWCFACTORY) == -1) error_exit("VIDIOCPWCFACTORY"); } void set_compression_preference(int fd, int pref) { if (ioctl(fd, VIDIOCPWCSCQUAL, &pref) == -1) error_exit("VIDIOCPWCSCQUAL"); } void set_automatic_gain_control(int fd, int pref) { if (ioctl(fd, VIDIOCPWCSAGC, &pref) == -1) error_exit("VIDIOCPWCSAGC"); } void set_shutter_speed(int fd, int pref) { if (ioctl(fd, VIDIOCPWCSSHUTTER, &pref) == -1) error_exit("VIDIOCPWCSSHUTTER"); } void set_automatic_white_balance_mode(int fd, char *mode) { struct pwc_whitebalance pwcwb; if (ioctl(fd, VIDIOCPWCGAWB, &pwcwb) == -1) error_exit("VIDIOCPWCGAWB"); if (strcasecmp(mode, "auto") == 0) pwcwb.mode = PWC_WB_AUTO; else if (strcasecmp(mode, "manual") == 0) pwcwb.mode = PWC_WB_MANUAL; else if (strcasecmp(mode, "indoor") == 0) pwcwb.mode = PWC_WB_INDOOR; else if (strcasecmp(mode, "outdoor") == 0) pwcwb.mode = PWC_WB_OUTDOOR; else if (strcasecmp(mode, "fl") == 0) pwcwb.mode = PWC_WB_FL; else { fprintf(stderr, "'%s' is not a known white balance mode.\n", mode); exit(1); } if (ioctl(fd, VIDIOCPWCSAWB, &pwcwb) == -1) error_exit("VIDIOCPWCSAWB"); } void set_automatic_white_balance_mode_red(int fd, int val) { struct pwc_whitebalance pwcwb; if (ioctl(fd, VIDIOCPWCGAWB, &pwcwb) == -1) error_exit("VIDIOCPWCGAWB"); pwcwb.manual_red = val; if (ioctl(fd, VIDIOCPWCSAWB, &pwcwb) == -1) error_exit("VIDIOCPWCSAWB"); } void set_automatic_white_balance_mode_blue(int fd, int val) { struct pwc_whitebalance pwcwb; if (ioctl(fd, VIDIOCPWCGAWB, &pwcwb) == -1) error_exit("VIDIOCPWCGAWB"); pwcwb.manual_blue = val; if (ioctl(fd, VIDIOCPWCSAWB, &pwcwb) == -1) error_exit("VIDIOCPWCSAWB"); } void set_automatic_white_balance_speed(int fd, int val) { struct pwc_wb_speed pwcwbs; if (ioctl(fd, VIDIOCPWCGAWBSPEED, &pwcwbs) == -1) error_exit("VIDIOCPWCGAWBSPEED"); pwcwbs.control_speed = val; if (ioctl(fd, VIDIOCPWCSAWBSPEED, &pwcwbs) == -1) error_exit("VIDIOCPWCSAWBSPEED"); } void set_automatic_white_balance_delay(int fd, int val) { struct pwc_wb_speed pwcwbs; if (ioctl(fd, VIDIOCPWCGAWBSPEED, &pwcwbs) == -1) error_exit("VIDIOCPWCGAWBSPEED"); pwcwbs.control_delay = val; if (ioctl(fd, VIDIOCPWCSAWBSPEED, &pwcwbs) == -1) error_exit("VIDIOCPWCSAWBSPEED"); } void set_led_on_time(int fd, int val) { struct pwc_leds pwcl; if (ioctl(fd, VIDIOCPWCGLED, &pwcl) == -1) error_exit("VIDIOCPWCGLED"); pwcl.led_on = val; if (ioctl(fd, VIDIOCPWCSLED, &pwcl) == -1) error_exit("VIDIOCPWCSLED"); } void set_led_off_time(int fd, int val) { struct pwc_leds pwcl; if (ioctl(fd, VIDIOCPWCGLED, &pwcl) == -1) error_exit("VIDIOCPWCGLED"); pwcl.led_off = val; if (ioctl(fd, VIDIOCPWCSLED, &pwcl) == -1) error_exit("VIDIOCPWCSLED"); } void set_sharpness(int fd, int val) { if (ioctl(fd, VIDIOCPWCSCONTOUR, &val) == -1) error_exit("VIDIOCPWCSCONTOUR"); } void set_backlight_compensation(int fd, int val) { if (ioctl(fd, VIDIOCPWCSBACKLIGHT, &val) == -1) error_exit("VIDIOCPWCSBACKLIGHT"); } void set_antiflicker_mode(int fd, int val) { if (ioctl(fd, VIDIOCPWCSFLICKER, &val) == -1) error_exit("VIDIOCPWCSFLICKER"); } void set_noise_reduction(int fd, int val) { if (ioctl(fd, VIDIOCPWCSDYNNOISE, &val) == -1) error_exit("VIDIOCPWCSDYNNOISE"); } void usage(void) { fprintf(stderr, "-d device device to use (default: /dev/video0)\n"); fprintf(stderr, "-p dump current settings\n"); fprintf(stderr, "-f x set framerate (0...63)\n"); fprintf(stderr, "-S w,h,x set width/height/framerate\n"); fprintf(stderr, "-b store settings in nonvolatile RAM\n"); fprintf(stderr, "-r restore settings from nonvolatile RAM\n"); fprintf(stderr, "-x restore factory settings\n"); fprintf(stderr, "-c x set compression preference (0-3)\n"); fprintf(stderr, "-g x set automatic gain control (0...65535)\n"); fprintf(stderr, "-s x set shutter speed (1...65535)\n"); fprintf(stderr, "-w auto/manual/indoor/outdoor/fl\n"); fprintf(stderr, " set automatic white balance mode\n"); fprintf(stderr, "-a x red-balance (only if -w manual) (0...65535)\n"); fprintf(stderr, "-e x blue-balance (idem) (0...65535)\n"); fprintf(stderr, "-i x speed of automatic white balance (1...65535)\n"); fprintf(stderr, "-j x delay for automatic white balance (1...65535)\n"); fprintf(stderr, "-k x set led on-time (0...25500ms\n"); fprintf(stderr, "-l x set led off-time\n"); fprintf(stderr, "-m x set electronic sharpness (0...65535)\n"); fprintf(stderr, "-n x set backlight compensation (0=0ff, other=on)\n"); fprintf(stderr, "-o x set antiflicker mode (0=0ff, other=on)\n"); fprintf(stderr, "-q x set noise reduction mode (0=none...3=high)\n"); fprintf(stderr, "-t x reset pan(bit 0) and/or tilt(bit 1)\n"); fprintf(stderr, "-u query pan/tilt status\n"); fprintf(stderr, "-y x set pan position\n"); fprintf(stderr, "-z x set tilt position\n"); fprintf(stderr, "-h this help\n"); fprintf(stderr, "\n"); fprintf(stderr, "With this tool, you can only set settings specific to the Philips WebCams.\n"); fprintf(stderr, "For something more generic, see dov4l:\n"); fprintf(stderr, "http://www.vanheusden.com/dov4l/\n"); } int main(int argc, char *argv[]) { int fd = -1; int c; int loop; fprintf(stderr, "setpwc v" VERSION ", (C) 2003-2006 by folkert@vanheusden.com\n"); for(loop=1; loop