forked from tTh/FloatImg
120 lines
2.4 KiB
C
120 lines
2.4 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 <linux/videodev2.h>
|
|
|
|
#include "../floatimg.h"
|
|
|
|
#include "v4l2_pr_structs.h"
|
|
#include "funcs.h"
|
|
|
|
int verbosity;
|
|
|
|
/* --------------------------------------------------------------------- */
|
|
static int enum_input(char *txt, int k)
|
|
{
|
|
|
|
return -1;
|
|
}
|
|
|
|
/* --------------------------------------------------------------------- */
|
|
int show_webcam_infos(char *devname, int k)
|
|
{
|
|
int vfd, foo;
|
|
|
|
struct v4l2_capability cap;
|
|
// struct v4l2_format fmt;
|
|
struct v4l2_input input;
|
|
// int index;
|
|
|
|
// struct v4l2_requestbuffers reqbuf;
|
|
|
|
#if DEBUG_LEVEL
|
|
fprintf(stderr, ">>> %s ( '%s' %d )\n", __func__, devname, k);
|
|
#endif
|
|
|
|
vfd = open_device(devname);
|
|
if (vfd < 0) {
|
|
perror(devname);
|
|
return -3;
|
|
}
|
|
|
|
fprintf(stderr, "\topen %s -> %d\n", devname, vfd);
|
|
|
|
memset(&cap, 0, sizeof(cap));
|
|
foo = ioctl(vfd, VIDIOC_QUERYCAP, &cap);
|
|
if (foo < 0) {
|
|
perror("ioctl QUERYCAP");
|
|
return -4;
|
|
}
|
|
pr_v4l2_capability(devname, &cap);
|
|
|
|
memset(&input, 0, sizeof(input));
|
|
if (-1 == ioctl(vfd, VIDIOC_ENUMINPUT, &input)) {
|
|
perror("VIDIOC_ENUMINPUT");
|
|
exit(EXIT_FAILURE);
|
|
}
|
|
pr_v4l2_input("input 0", &input);
|
|
|
|
|
|
close(vfd);
|
|
|
|
return 0;
|
|
}
|
|
/* --------------------------------------------------------------------- */
|
|
int liste_des_devices(int flag)
|
|
{
|
|
fprintf(stderr, "%s not implemented\n", __func__);
|
|
return -1;
|
|
}
|
|
/* --------------------------------------------------------------------- */
|
|
|
|
void help(int k)
|
|
{
|
|
puts("Options :");
|
|
puts("\t-d\tselect the video device");
|
|
puts("\t-K\tset the K parameter");
|
|
puts("\t-l\tlist video devices");
|
|
puts("\t-v\tincrease verbosity");
|
|
|
|
if (verbosity) { puts(""); fimg_print_version(1); }
|
|
|
|
exit(0);
|
|
}
|
|
/* --------------------------------------------------------------------- */
|
|
int main(int argc, char *argv[])
|
|
{
|
|
int foo, opt;
|
|
|
|
char *device = "/dev/video0";
|
|
int K = 0;
|
|
|
|
while ((opt = getopt(argc, argv, "d:hK:lv")) != -1) {
|
|
switch(opt) {
|
|
case 'd': device = optarg; break;
|
|
case 'h': help(0); break;
|
|
case 'K': K = atol(optarg); break;
|
|
case 'l': liste_des_devices(0); break;
|
|
case 'v': verbosity++; break;
|
|
}
|
|
}
|
|
|
|
if (verbosity) fimg_print_version(0);
|
|
|
|
foo = show_webcam_infos(device, K);
|
|
fprintf(stderr, "\n\tshow_webcam_infos -> %d\n", foo);
|
|
|
|
return 0;
|
|
}
|
|
/* --------------------------------------------------------------------- */
|
|
|
|
|