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>
|
2020-08-06 22:30:40 +02:00
|
|
|
// #include <string.h>
|
2020-03-07 15:24:31 +01:00
|
|
|
#include <sys/ioctl.h>
|
|
|
|
#include <errno.h>
|
|
|
|
#include <inttypes.h>
|
2020-08-06 22:30:40 +02:00
|
|
|
#include <curses.h>
|
2020-03-07 15:24:31 +01:00
|
|
|
#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)
|
|
|
|
{
|
2020-08-06 22:30:40 +02:00
|
|
|
int foo;
|
|
|
|
|
|
|
|
#if DEBUG_LEVEL
|
2020-07-29 02:30:59 +02:00
|
|
|
fprintf(stderr, ">>> %s ( '%s' )\n", __func__, title);
|
2020-08-06 22:30:40 +02:00
|
|
|
#endif
|
|
|
|
|
|
|
|
initscr();
|
|
|
|
|
|
|
|
standout(); mvaddstr(1, 5, title); standend(); refresh();
|
|
|
|
|
|
|
|
|
2020-07-29 02:30:59 +02:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
/* --------------------------------------------------------------------- */
|
2020-08-06 22:30:40 +02:00
|
|
|
int end_screen(void)
|
|
|
|
{
|
|
|
|
endwin();
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
/* --------------------------------------------------------------------- */
|
|
|
|
int preparation_v4l2(char *devname, int param)
|
2020-07-29 02:30:59 +02:00
|
|
|
{
|
|
|
|
int fd, foo;
|
|
|
|
struct v4l2_capability cap;
|
|
|
|
|
2020-08-06 22:30:40 +02:00
|
|
|
#if DEBUG_LEVEL
|
|
|
|
fprintf(stderr, ">>> %s ( '%s' %d )\n", __func__, devname, param);
|
|
|
|
#endif
|
|
|
|
|
2020-07-29 02:30:59 +02:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
/* --------------------------------------------------------------------- */
|
2020-08-06 22:30:40 +02:00
|
|
|
int interactive(int fd, char *text, int notused)
|
2020-07-29 02:30:59 +02:00
|
|
|
{
|
|
|
|
|
2020-08-06 22:30:40 +02:00
|
|
|
fprintf(stderr, "file descriptor = %d\n", fd);
|
|
|
|
|
2020-07-29 02:30:59 +02:00
|
|
|
init_screen("prototype");
|
|
|
|
|
2020-08-06 22:30:40 +02:00
|
|
|
sleep(2);
|
|
|
|
|
|
|
|
end_screen();
|
2020-07-29 02:30:59 +02:00
|
|
|
|
2020-08-06 22:30:40 +02:00
|
|
|
return 0;
|
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-08-06 22:30:40 +02:00
|
|
|
devnum = preparation_v4l2(device, K);
|
2020-07-29 02:30:59 +02:00
|
|
|
if (devnum < 0) {
|
|
|
|
fprintf(stderr, "%s : erreur init video device\n", argv[0]);
|
|
|
|
exit(1);
|
|
|
|
}
|
2020-03-07 15:24:31 +01:00
|
|
|
|
2020-08-06 22:30:40 +02:00
|
|
|
foo = interactive(devnum, title, 0);
|
2020-03-07 15:24:31 +01:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
/* --------------------------------------------------------------------- */
|