videodog patch

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]



here's a patch for videodog-0.06.c that i did while trying to get my
WinTV card to work. it was defaulting to PAL mode and i need NTSC. it
allows user to select input mode: PAL/NTSC/SECAM and also fixes a couple
small bugs.

douglas


--- videodog-0.06.c	Sun Apr 22 21:57:06 2001
+++ videodog-0.06-1.c	Sun Apr 22 21:56:56 2001
@@ -10,6 +10,11 @@
  *		added: -i option to change input ( note that not all devices aloow
this
  *		corrected bgr -> rgb issue ( depth 3 )
  *
+ *		22.april.2001 douglas repetto changes:
+ *			-m option to change mode (PAL/NTSC/SECAM)
+ *			fixed problem with device name loosing a letter
+ *			added update_cap() routine so that Max Width and Height are
reported correctly when changing mode
+ *
  * Just grabs a frame from v4l device or set its picture defaults.
Useful for scripts, webcam scripts. 
  * Output: a raw frame ( RGB ) or pnm frame ( -p option )
  * 
@@ -31,6 +36,8 @@
  *
  * Optional:
  *
+ * i - Input
+ * m - Mode
  * u - Hue
  * c - Contrast
  * b - Brightness
@@ -42,7 +49,9 @@
  *	./videodog -s -d /dev/video0 
  *			- query the device about settings.
  *	./videodog -x 320 -y 240 -w 3 -d /dev/video0 -p | cjpeg > lelel.jpg
- *			- produces a lelel.jpg image with 320x240x24bpp ( 3 * 8)
+ *			- produces a lelel.jpg image with 320x240x24bpp ( 3 * 8) *
./videodog -x 320 -y 240 -w 3 -d /dev/video0 -p | cjpeg > lelel.jpg
+ *	./videodog -x 640 -y 480 -w 3 -i 1 -m NTSC -d /dev/video -p >
out.pnm
+ *			- uses input 1 and NTSC mode to grab image
  *	./videodog -s -d /dev/video0 -u 200 
  *			- set Hue == 200 and query the device
  *
@@ -64,7 +73,7 @@
 
 
 #define VERSION "0.06"
-#define OPTSTR "hx:y:w:d:pu:c:b:l:sni:"
+#define OPTSTR "hx:y:w:d:pu:c:b:l:m:sni:"
 #define DOT fprintf(stderr,".");
 
 void showhelp(void) {
@@ -79,6 +88,7 @@
 	fprintf (stderr, "Other options :\n");
 	fprintf (stderr,"-h just show this lines, doesn't help you ok ?\n");
 	fprintf (stderr,"-i input number (0 is the default) \n");
+	fprintf (stderr,"-m input mode (PAL/NTSC/SECAM) \n");
 	fprintf (stderr,"-u image Hue\n");
 	fprintf (stderr,"-c image Contrast\n");
 	fprintf (stderr,"-b image Brightness \n");
@@ -93,21 +103,23 @@
 unsigned short int pnm=0;
 int x=0, y=0, w=0;
 unsigned char *v_device; /* device */
+unsigned char *v_mode; /* mode */
+unsigned char *default_mode = "NTSC";
 
 static struct video_picture	 grab_pic;
 static struct video_capability   grab_cap;
-static struct video_channel      grab_vid; /* escolher canal e NTSC */
+static struct video_channel      grab_vid; /* escolher canal*/
+static struct video_tuner	 grab_tun; /* choose PAL/NTSC/SECAM */
 static struct video_mmap         grab_buf;
 static int                       grab_fd, grab_size;
 static unsigned char            *grab_data;
 int hue=-1, contrast=-1, brightness=-1, colour=-1, nograb=0, showc=0i,
channel=0;
-
 /* prototype */
 
 void swap_rgb24(unsigned char *, int );
 unsigned char* grab_one(int *, int *);
 int grab_init();
-
+int update_cap();
 
 /* signal handler */
 void _sighandler (int sig) {
@@ -115,6 +127,7 @@
 			
 		case SIGINT: /* ctrl+x */
 			free (v_device);
+			free (v_mode);
 			close (grab_fd);
 			munmap(grab_data, grab_size);
 			fprintf (stderr, "Caught SIGINT - Cleaning \n");
@@ -136,7 +149,34 @@
 	if (ioctl(grab_fd, VIDIOCGCHAN, &grab_vid) == -1) return;
 	grab_vid.channel=channel;
 	if (ioctl(grab_fd, VIDIOCSCHAN, &grab_vid) == -1) return;
+}
+
+void set_mode() {
+        if (ioctl(grab_fd, VIDIOCGTUNER, &grab_tun) == -1) return;
+
+	if (strcmp(v_mode, "PAL") == 0)
+	{
+	        grab_tun.flags = VIDEO_TUNER_PAL;
+        	grab_tun.mode = VIDEO_MODE_PAL;
+        }
+	else if (strcmp(v_mode, "NTSC") == 0)
+	{
+	        grab_tun.flags = VIDEO_TUNER_NTSC;
+        	grab_tun.mode = VIDEO_MODE_NTSC;
+        }
+	else if (strcmp(v_mode, "SECAM") == 0)
+	{
+	        grab_tun.flags = VIDEO_TUNER_SECAM;
+        	grab_tun.mode = VIDEO_MODE_SECAM;
+	}
+	else
+	{
+		fprintf(stderr, 
+			"%s is not a valid mode.\n", v_mode);
+		return;
+	}
 	
+	if (ioctl(grab_fd, VIDIOCSTUNER, &grab_tun) == -1) return;
 }
 
 void show_cap()	{ 	/* mostra settings atuais */ 
@@ -147,6 +187,7 @@
 	fprintf (stderr, "Max Height : %d\n", grab_cap.maxheight);
 	fprintf (stderr, "Current Settings :\n\n");
 	fprintf (stderr, "\tInput : %i\n", grab_vid.channel);
+	fprintf (stderr, "\tMode: %s\n", v_mode);
 	fprintf (stderr, "\tBrightness : %i\n", grab_pic.brightness);
 	fprintf (stderr, "\tHue        : %i\n", grab_pic.hue);
 	fprintf (stderr, "\tColour     : %i\n", grab_pic.colour);
@@ -176,12 +217,16 @@
 			case 'd':
 				v_device= (char *)malloc ((strlen(optarg) * sizeof(char))+1);
 				memset(v_device, 0, strlen(optarg));
-				strncpy(v_device, optarg, strlen(optarg) -1 );
-				
+				strcpy(v_device, optarg);
 				break;
 			case 'i':
 				channel=atoi(optarg);
 				break;
+			case 'm':
+				v_mode= (char *)malloc ((strlen(optarg) * sizeof(char))+1);
+				memset(v_mode, 0, strlen(optarg));
+				strcpy(v_mode, optarg);
+				break;
 			case 'u':
 				hue=atoi(optarg);
 				break;
@@ -209,6 +254,12 @@
 			
 			}
 		if (!x || !y || !w ) nograb=1;
+		if (!v_mode)
+		{
+			v_mode= (char *)malloc ((strlen(default_mode) * sizeof(char)) + 1);
+			memset(v_mode, 0, strlen(default_mode));
+			strcpy(v_mode, default_mode);
+		}			
 		if (!v_device) {
 			fprintf (stderr, " I NEED A DEVICE NAME \n");
 			showhelp();
@@ -217,6 +268,8 @@
 		grab_init();
 		set_picture();
 		set_channel();
+		set_mode();
+		update_cap();
 		if (showc) show_cap();
 		
 		if (pnm) {
@@ -230,6 +283,7 @@
 		if (!nograb) fwrite ((unsigned char*)grab_one( &x, &y), x * y * w, 1,
stdout);
 		
 		free (v_device);
+		free (v_mode);
 		close (grab_fd);
 		munmap(grab_data, grab_size);
 	
@@ -282,7 +336,15 @@
 	grab_data =
mmap(0,grab_size,PROT_READ|PROT_WRITE,MAP_SHARED,grab_fd,0);
 	return(1);
 	}
-	
+
+int update_cap() {
+	if (ioctl(grab_fd,VIDIOCGCAP,&grab_cap) == -1) {
+	        fprintf(stderr,"couldn't update capabilities.\n");
+		exit(1);
+		}
+	return(1);
+	}
+
 unsigned char* grab_one(int *width, int *height) {
 	for (;;) {
 		if (-1 == ioctl(grab_fd,VIDIOCMCAPTURE,&grab_buf)) {



-- 
                        douglas irving repetto 
                  http://music.columbia.edu/~douglas 
                  http://shoko.calarts.edu/musicdsp
               http://music.columbia.edu/cmc/dorkbotnyc
--- videodog-0.06.c	Sun Apr 22 21:57:06 2001
+++ videodog-0.06-1.c	Sun Apr 22 21:56:56 2001
@@ -10,6 +10,11 @@
  *		added: -i option to change input ( note that not all devices aloow this
  *		corrected bgr -> rgb issue ( depth 3 )
  *
+ *		22.april.2001 douglas repetto changes:
+ *			-m option to change mode (PAL/NTSC/SECAM)
+ *			fixed problem with device name loosing a letter
+ *			added update_cap() routine so that Max Width and Height are reported correctly when changing mode
+ *
  * Just grabs a frame from v4l device or set its picture defaults. Useful for scripts, webcam scripts. 
  * Output: a raw frame ( RGB ) or pnm frame ( -p option )
  * 
@@ -31,6 +36,8 @@
  *
  * Optional:
  *
+ * i - Input
+ * m - Mode
  * u - Hue
  * c - Contrast
  * b - Brightness
@@ -42,7 +49,9 @@
  *	./videodog -s -d /dev/video0 
  *			- query the device about settings.
  *	./videodog -x 320 -y 240 -w 3 -d /dev/video0 -p | cjpeg > lelel.jpg
- *			- produces a lelel.jpg image with 320x240x24bpp ( 3 * 8)
+ *			- produces a lelel.jpg image with 320x240x24bpp ( 3 * 8) *	./videodog -x 320 -y 240 -w 3 -d /dev/video0 -p | cjpeg > lelel.jpg
+ *	./videodog -x 640 -y 480 -w 3 -i 1 -m NTSC -d /dev/video -p > out.pnm
+ *			- uses input 1 and NTSC mode to grab image
  *	./videodog -s -d /dev/video0 -u 200 
  *			- set Hue == 200 and query the device
  *
@@ -64,7 +73,7 @@
 
 
 #define VERSION "0.06"
-#define OPTSTR "hx:y:w:d:pu:c:b:l:sni:"
+#define OPTSTR "hx:y:w:d:pu:c:b:l:m:sni:"
 #define DOT fprintf(stderr,".");
 
 void showhelp(void) {
@@ -79,6 +88,7 @@
 	fprintf (stderr, "Other options :\n");
 	fprintf (stderr,"-h just show this lines, doesn't help you ok ?\n");
 	fprintf (stderr,"-i input number (0 is the default) \n");
+	fprintf (stderr,"-m input mode (PAL/NTSC/SECAM) \n");
 	fprintf (stderr,"-u image Hue\n");
 	fprintf (stderr,"-c image Contrast\n");
 	fprintf (stderr,"-b image Brightness \n");
@@ -93,21 +103,23 @@
 unsigned short int pnm=0;
 int x=0, y=0, w=0;
 unsigned char *v_device; /* device */
+unsigned char *v_mode; /* mode */
+unsigned char *default_mode = "NTSC";
 
 static struct video_picture	 grab_pic;
 static struct video_capability   grab_cap;
-static struct video_channel      grab_vid; /* escolher canal e NTSC */
+static struct video_channel      grab_vid; /* escolher canal*/
+static struct video_tuner	 grab_tun; /* choose PAL/NTSC/SECAM */
 static struct video_mmap         grab_buf;
 static int                       grab_fd, grab_size;
 static unsigned char            *grab_data;
 int hue=-1, contrast=-1, brightness=-1, colour=-1, nograb=0, showc=0i, channel=0;
-
 /* prototype */
 
 void swap_rgb24(unsigned char *, int );
 unsigned char* grab_one(int *, int *);
 int grab_init();
-
+int update_cap();
 
 /* signal handler */
 void _sighandler (int sig) {
@@ -115,6 +127,7 @@
 			
 		case SIGINT: /* ctrl+x */
 			free (v_device);
+			free (v_mode);
 			close (grab_fd);
 			munmap(grab_data, grab_size);
 			fprintf (stderr, "Caught SIGINT - Cleaning \n");
@@ -136,7 +149,34 @@
 	if (ioctl(grab_fd, VIDIOCGCHAN, &grab_vid) == -1) return;
 	grab_vid.channel=channel;
 	if (ioctl(grab_fd, VIDIOCSCHAN, &grab_vid) == -1) return;
+}
+
+void set_mode() {
+        if (ioctl(grab_fd, VIDIOCGTUNER, &grab_tun) == -1) return;
+
+	if (strcmp(v_mode, "PAL") == 0)
+	{
+	        grab_tun.flags = VIDEO_TUNER_PAL;
+        	grab_tun.mode = VIDEO_MODE_PAL;
+        }
+	else if (strcmp(v_mode, "NTSC") == 0)
+	{
+	        grab_tun.flags = VIDEO_TUNER_NTSC;
+        	grab_tun.mode = VIDEO_MODE_NTSC;
+        }
+	else if (strcmp(v_mode, "SECAM") == 0)
+	{
+	        grab_tun.flags = VIDEO_TUNER_SECAM;
+        	grab_tun.mode = VIDEO_MODE_SECAM;
+	}
+	else
+	{
+		fprintf(stderr, 
+			"%s is not a valid mode.\n", v_mode);
+		return;
+	}
 	
+	if (ioctl(grab_fd, VIDIOCSTUNER, &grab_tun) == -1) return;
 }
 
 void show_cap()	{ 	/* mostra settings atuais */ 
@@ -147,6 +187,7 @@
 	fprintf (stderr, "Max Height : %d\n", grab_cap.maxheight);
 	fprintf (stderr, "Current Settings :\n\n");
 	fprintf (stderr, "\tInput : %i\n", grab_vid.channel);
+	fprintf (stderr, "\tMode: %s\n", v_mode);
 	fprintf (stderr, "\tBrightness : %i\n", grab_pic.brightness);
 	fprintf (stderr, "\tHue        : %i\n", grab_pic.hue);
 	fprintf (stderr, "\tColour     : %i\n", grab_pic.colour);
@@ -176,12 +217,16 @@
 			case 'd':
 				v_device= (char *)malloc ((strlen(optarg) * sizeof(char))+1);
 				memset(v_device, 0, strlen(optarg));
-				strncpy(v_device, optarg, strlen(optarg) -1 );
-				
+				strcpy(v_device, optarg);
 				break;
 			case 'i':
 				channel=atoi(optarg);
 				break;
+			case 'm':
+				v_mode= (char *)malloc ((strlen(optarg) * sizeof(char))+1);
+				memset(v_mode, 0, strlen(optarg));
+				strcpy(v_mode, optarg);
+				break;
 			case 'u':
 				hue=atoi(optarg);
 				break;
@@ -209,6 +254,12 @@
 			
 			}
 		if (!x || !y || !w ) nograb=1;
+		if (!v_mode)
+		{
+			v_mode= (char *)malloc ((strlen(default_mode) * sizeof(char)) + 1);
+			memset(v_mode, 0, strlen(default_mode));
+			strcpy(v_mode, default_mode);
+		}			
 		if (!v_device) {
 			fprintf (stderr, " I NEED A DEVICE NAME \n");
 			showhelp();
@@ -217,6 +268,8 @@
 		grab_init();
 		set_picture();
 		set_channel();
+		set_mode();
+		update_cap();
 		if (showc) show_cap();
 		
 		if (pnm) {
@@ -230,6 +283,7 @@
 		if (!nograb) fwrite ((unsigned char*)grab_one( &x, &y), x * y * w, 1, stdout);
 		
 		free (v_device);
+		free (v_mode);
 		close (grab_fd);
 		munmap(grab_data, grab_size);
 	
@@ -282,7 +336,15 @@
 	grab_data = mmap(0,grab_size,PROT_READ|PROT_WRITE,MAP_SHARED,grab_fd,0);
 	return(1);
 	}
-	
+
+int update_cap() {
+	if (ioctl(grab_fd,VIDIOCGCAP,&grab_cap) == -1) {
+	        fprintf(stderr,"couldn't update capabilities.\n");
+		exit(1);
+		}
+	return(1);
+	}
+
 unsigned char* grab_one(int *width, int *height) {
 	for (;;) {
 		if (-1 == ioctl(grab_fd,VIDIOCMCAPTURE,&grab_buf)) {

[Index of Archives]     [Linux DVB]     [Video Disk Recorder]     [Asterisk]     [Photo]     [DCCP]     [Netdev]     [Xorg]     [Util Linux NG]     [Xfree86]     [Free Photo Albums]     [Fedora Users]     [Fedora Women]     [ALSA Users]     [ALSA Devel]     [Linux USB]

Powered by Linux