not a good day...

This commit is contained in:
tth 2020-07-29 02:30:59 +02:00
parent 4fec59ec64
commit 14062a9586
2 changed files with 59 additions and 6 deletions

View File

@ -34,7 +34,8 @@ extern int verbosity;
size_t length; size_t length;
}; };
static char *dev_name; static char *dev_name;
static enum io_method io = IO_METHOD_MMAP; static enum io_method io = IO_METHOD_MMAP;
static int fd = -1; static int fd = -1;
struct buffer *buffers; struct buffer *buffers;
@ -48,10 +49,12 @@ static void errno_exit(const char *s)
fprintf(stderr, "%s error %d, %s\n", s, errno, strerror(errno)); fprintf(stderr, "%s error %d, %s\n", s, errno, strerror(errno));
exit(EXIT_FAILURE); exit(EXIT_FAILURE);
} }
static int xioctl(int fh, int request, void *arg) static int xioctl(int fh, int request, void *arg)
{ {
int r; int r;
/* PLEASE EXPLAIN THAT CODE */
do { do {
r = ioctl(fh, request, arg); r = ioctl(fh, request, arg);
} while (-1 == r && EINTR == errno); } while (-1 == r && EINTR == errno);
@ -225,7 +228,8 @@ if (-1 == xioctl(fd, VIDIOC_QUERYCAP, &cap)) {
if (EINVAL == errno) { if (EINVAL == errno) {
fprintf(stderr, "%s is not a V4L2 device\n", dev_name); fprintf(stderr, "%s is not a V4L2 device\n", dev_name);
exit(EXIT_FAILURE); exit(EXIT_FAILURE);
} else { }
else {
errno_exit("VIDIOC_QUERYCAP"); errno_exit("VIDIOC_QUERYCAP");
} }
} }

View File

@ -25,13 +25,55 @@ void help(int n)
puts("camera controls"); puts("camera controls");
puts("\t-d bla\t\tselect video device"); 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); 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 main(int argc, char *argv[])
{ {
int foo, opt; int foo, opt, devnum;
int etype = 0; int etype = 0;
char *device = "/dev/video0"; char *device = "/dev/video0";
char *title = NULL; char *title = NULL;
@ -44,11 +86,18 @@ while ((opt = getopt(argc, argv, "d:e:hK:lT:v")) != -1) {
case 'h': help(0); break; case 'h': help(0); break;
case 'K': K = atol(optarg); break; case 'K': K = atol(optarg); break;
// case 'l': liste_des_devices(0); break; // case 'l': liste_des_devices(0); break;
case 't': title = optarg;
case 'v': verbosity++; break; 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; return 0;
} }