105 lines
		
	
	
		
			2.3 KiB
		
	
	
	
		
			C
		
	
	
	
	
	
			
		
		
	
	
			105 lines
		
	
	
		
			2.3 KiB
		
	
	
	
		
			C
		
	
	
	
	
	
/*
 | 
						|
 *		tests pour capturer les webcams
 | 
						|
 */
 | 
						|
 | 
						|
#include  <stdio.h>
 | 
						|
#include  <stdlib.h>
 | 
						|
#include  <unistd.h>
 | 
						|
#include  <math.h>
 | 
						|
#include  <string.h>
 | 
						|
#include  <sys/ioctl.h>
 | 
						|
#include  <errno.h>
 | 
						|
#include  <inttypes.h>
 | 
						|
#include  <linux/videodev2.h>
 | 
						|
 | 
						|
#include  "../floatimg.h"
 | 
						|
 | 
						|
#include  "v4l2_pr_structs.h"
 | 
						|
#include  "funcs.h"
 | 
						|
 | 
						|
int		verbosity;
 | 
						|
 | 
						|
/* --------------------------------------------------------------------- */
 | 
						|
void help(int n)
 | 
						|
{
 | 
						|
 | 
						|
puts("camera controls");
 | 
						|
puts("\t-d bla\t\tselect video device");
 | 
						|
puts("\t-e nnn\t\tset 'etype'");
 | 
						|
puts("\t-K nnn\t\tinteger parameter");
 | 
						|
puts("\t-n bla\t\tset title");
 | 
						|
exit(0);
 | 
						|
}
 | 
						|
/* --------------------------------------------------------------------- */
 | 
						|
int init_screen(char *title)
 | 
						|
{
 | 
						|
fprintf(stderr, ">>> %s ( '%s' )\n", __func__, title);
 | 
						|
return -1;
 | 
						|
}
 | 
						|
/* --------------------------------------------------------------------- */
 | 
						|
int preparation(char *devname, int param)
 | 
						|
{
 | 
						|
int			fd, foo;
 | 
						|
struct v4l2_capability	cap;
 | 
						|
 | 
						|
fd = open_device(devname);
 | 
						|
if (fd < 0) {
 | 
						|
	fprintf(stderr, "err %d on %s opening\n", errno, devname);
 | 
						|
	return -2;
 | 
						|
	}
 | 
						|
 | 
						|
/* est-ce un device qui permet la capture video */
 | 
						|
foo = ioctl(fd, VIDIOC_QUERYCAP, &cap);
 | 
						|
if (-1 == foo) {
 | 
						|
	perror("VIDIOC_QUERYCAP");
 | 
						|
	return -2;
 | 
						|
	}
 | 
						|
if (!(cap.capabilities & V4L2_CAP_VIDEO_CAPTURE)) {
 | 
						|
	fprintf(stderr, "%s is not a video capture device\n", devname);
 | 
						|
	return -3;
 | 
						|
	}
 | 
						|
 | 
						|
return fd;
 | 
						|
}
 | 
						|
/* --------------------------------------------------------------------- */
 | 
						|
int interactive(int fd, int notused)
 | 
						|
{
 | 
						|
 | 
						|
init_screen("prototype");
 | 
						|
 | 
						|
fprintf(stderr, "file descriptor = %d\n", fd);
 | 
						|
 | 
						|
}
 | 
						|
/* --------------------------------------------------------------------- */
 | 
						|
int main(int argc, char *argv[])
 | 
						|
{
 | 
						|
int		foo, opt, devnum;
 | 
						|
int		etype = 0;
 | 
						|
char		*device = "/dev/video0";
 | 
						|
char		*title = NULL;
 | 
						|
int		K = 0;
 | 
						|
 | 
						|
while ((opt = getopt(argc, argv, "d:e:hK:lT:v")) != -1) {
 | 
						|
	switch(opt) {
 | 
						|
		case 'd':	device = optarg;	break;
 | 
						|
		case 'e':	etype = atol(optarg);	break;
 | 
						|
		case 'h':	help(0);		break;
 | 
						|
		case 'K':	K = atol(optarg);	break;
 | 
						|
		// case 'l':	liste_des_devices(0);	break;
 | 
						|
		case 't':	title = optarg;
 | 
						|
		case 'v':	verbosity++;		break;
 | 
						|
		}
 | 
						|
	}
 | 
						|
 | 
						|
devnum = preparation(device, K);
 | 
						|
if (devnum < 0) {
 | 
						|
	fprintf(stderr, "%s : erreur init video device\n", argv[0]);
 | 
						|
	exit(1);
 | 
						|
	}
 | 
						|
 | 
						|
foo = interactive(devnum, 0);
 | 
						|
 | 
						|
return 0;
 | 
						|
}
 | 
						|
/* --------------------------------------------------------------------- */
 |