FloatImg/v4l2/nc-camcontrol.c

105 lines
2.3 KiB
C
Raw Normal View History

2020-03-07 15:24:31 +01:00
/*
* 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");
2020-07-29 02:30:59 +02:00
puts("\t-e nnn\t\tset 'etype'");
puts("\t-K nnn\t\tinteger parameter");
puts("\t-n bla\t\tset title");
2020-03-07 15:24:31 +01:00
exit(0);
2020-07-29 02:30:59 +02:00
}
/* --------------------------------------------------------------------- */
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);
2020-03-07 15:24:31 +01:00
}
/* --------------------------------------------------------------------- */
int main(int argc, char *argv[])
{
2020-07-29 02:30:59 +02:00
int foo, opt, devnum;
2020-03-07 15:24:31 +01:00
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;
2020-07-29 02:30:59 +02:00
case 't': title = optarg;
2020-03-07 15:24:31 +01:00
case 'v': verbosity++; break;
}
}
2020-07-29 02:30:59 +02:00
devnum = preparation(device, K);
if (devnum < 0) {
fprintf(stderr, "%s : erreur init video device\n", argv[0]);
exit(1);
}
2020-03-07 15:24:31 +01:00
2020-07-29 02:30:59 +02:00
foo = interactive(devnum, 0);
2020-03-07 15:24:31 +01:00
return 0;
}
/* --------------------------------------------------------------------- */