FloatImg4PythonBinding/v4l2/t.c
2019-08-02 03:33:59 +02:00

97 lines
2.0 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 <inttypes.h>
#include <linux/videodev2.h>
#include "funcs.h"
#include "../floatimg.h"
#include "v4l2_pr_structs.h"
int verbosity;
/* --------------------------------------------------------------------- */
int essai(char *dev, int k)
{
int vfd, foo;
struct v4l2_format fmt;
struct v4l2_requestbuffers reqbuf;
fprintf(stderr, ">>> %s ( '%s' %d )\n", __func__, dev, k);
vfd = open_device(dev);
if (verbosity) fprintf(stderr, "\topen %s -> %d\n", dev, vfd);
memset(&fmt, 0, sizeof(fmt));
fmt.type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
// pr_v4l2_format("before ioctl", &fmt);
foo = ioctl(vfd, VIDIOC_G_FMT, &fmt);
fprintf(stderr, "ioctl -> %d\n", foo);
if (0 != foo) {
perror("ioctl G_FMT");
exit(1);
}
pr_v4l2_format("after ioctl", &fmt);
return k;
}
/* --------------------------------------------------------------------- */
int liste_des_devices(int K)
{
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:v")) != -1) {
switch(opt) {
case 'd': device = optarg; break;
case 'h': help(0); break;
case 'K': K = atol(optarg); break;
case 'v': verbosity++; break;
}
}
if (verbosity) fimg_print_version(0);
foo = essai(device, K);
fprintf(stderr, "\tessai -> %d\n", foo);
return 0;
}
/* --------------------------------------------------------------------- */