2019-05-25 02:40:13 +11:00
|
|
|
/*
|
|
|
|
* tests pour capturer les webcams
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <unistd.h>
|
|
|
|
#include <math.h>
|
|
|
|
#include <string.h>
|
2019-07-03 07:23:12 +11:00
|
|
|
#include <sys/ioctl.h>
|
2019-07-27 09:02:28 +11:00
|
|
|
#include <inttypes.h>
|
2019-07-03 07:23:12 +11:00
|
|
|
#include <linux/videodev2.h>
|
2019-07-03 04:35:08 +11:00
|
|
|
|
2019-05-26 01:16:24 +11:00
|
|
|
#include "funcs.h"
|
2019-06-05 19:57:39 +11:00
|
|
|
#include "../floatimg.h"
|
2019-05-25 02:40:13 +11:00
|
|
|
|
2019-07-03 04:35:08 +11:00
|
|
|
#include "v4l2_pr_structs.h"
|
|
|
|
|
|
|
|
|
2019-05-25 02:40:13 +11:00
|
|
|
int verbosity;
|
|
|
|
|
2019-05-26 01:16:24 +11:00
|
|
|
/* --------------------------------------------------------------------- */
|
|
|
|
int essai(char *dev, int k)
|
|
|
|
{
|
2019-07-04 00:29:24 +11:00
|
|
|
int vfd, foo;
|
|
|
|
struct v4l2_format fmt;
|
|
|
|
struct v4l2_requestbuffers reqbuf;
|
2019-05-26 01:16:24 +11:00
|
|
|
|
|
|
|
fprintf(stderr, ">>> %s ( '%s' %d )\n", __func__, dev, k);
|
|
|
|
|
|
|
|
vfd = open_device(dev);
|
|
|
|
fprintf(stderr, "\topen %s -> %d\n", dev, vfd);
|
|
|
|
|
2019-07-03 04:35:08 +11:00
|
|
|
memset(&fmt, 0, sizeof(fmt));
|
|
|
|
pr_v4l2_format("after 0", &fmt);
|
|
|
|
|
|
|
|
fmt.type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
|
|
|
|
fmt.fmt.pix.width = 640;
|
|
|
|
fmt.fmt.pix.height = 480;
|
|
|
|
fmt.fmt.pix.pixelformat = V4L2_PIX_FMT_RGB24;
|
|
|
|
fmt.fmt.pix.field = V4L2_FIELD_INTERLACED;
|
|
|
|
|
|
|
|
pr_v4l2_format("before ioctl", &fmt);
|
|
|
|
|
2019-07-03 07:23:12 +11:00
|
|
|
foo = ioctl(vfd, VIDIOC_S_FMT, &fmt);
|
|
|
|
fprintf(stderr, "ioctl -> %d\n", foo);
|
2019-07-04 00:29:24 +11:00
|
|
|
if (foo < 0) {
|
|
|
|
perror("ioctl S_FMT");
|
|
|
|
exit(1);
|
|
|
|
}
|
2019-07-03 07:23:12 +11:00
|
|
|
|
|
|
|
pr_v4l2_format("after ioctl", &fmt);
|
|
|
|
|
|
|
|
/* todo V4L2_BUF_TYPE_VIDEO_CAPTURE */
|
2019-07-04 00:29:24 +11:00
|
|
|
memset(&reqbuf, 0, sizeof(reqbuf));
|
|
|
|
pr_v4l2_requestbuffers("after 0", &reqbuf);
|
|
|
|
|
2019-05-26 01:16:24 +11:00
|
|
|
|
|
|
|
return k;
|
|
|
|
}
|
2019-05-25 02:40:13 +11:00
|
|
|
/* --------------------------------------------------------------------- */
|
2019-07-03 04:35:08 +11:00
|
|
|
int liste_des_devices(int K)
|
|
|
|
{
|
|
|
|
fprintf(stderr, "%s not implemented\n", __func__);
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
/* --------------------------------------------------------------------- */
|
|
|
|
|
2019-05-25 02:40:13 +11:00
|
|
|
void help(int k)
|
|
|
|
{
|
|
|
|
puts("Options :");
|
2019-05-25 20:56:56 +11:00
|
|
|
puts("\t-d\tselect the video device");
|
2019-05-25 03:34:07 +11:00
|
|
|
puts("\t-K\tset the K parameter");
|
2019-05-25 20:56:56 +11:00
|
|
|
puts("\t-l\tlist video devices");
|
2019-05-25 02:40:13 +11:00
|
|
|
puts("\t-v\tincrease verbosity");
|
2019-07-04 00:29:24 +11:00
|
|
|
|
|
|
|
if (verbosity) { puts(""); fimg_print_version(1); }
|
|
|
|
|
2019-05-25 02:40:13 +11:00
|
|
|
exit(0);
|
|
|
|
}
|
|
|
|
/* --------------------------------------------------------------------- */
|
|
|
|
int main(int argc, char *argv[])
|
|
|
|
{
|
|
|
|
int foo, opt;
|
2019-05-26 01:16:24 +11:00
|
|
|
|
|
|
|
char *device = "/dev/video0";
|
2019-05-25 02:40:13 +11:00
|
|
|
int K = 0;
|
|
|
|
|
2019-05-26 01:16:24 +11:00
|
|
|
while ((opt = getopt(argc, argv, "d:hK:v")) != -1) {
|
2019-05-25 02:40:13 +11:00
|
|
|
switch(opt) {
|
2019-05-26 01:16:24 +11:00
|
|
|
case 'd': device = optarg; break;
|
2019-05-25 02:40:13 +11:00
|
|
|
case 'h': help(0); break;
|
|
|
|
case 'K': K = atol(optarg); break;
|
|
|
|
case 'v': verbosity++; break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (verbosity) fimg_print_version(0);
|
|
|
|
|
2019-05-26 01:16:24 +11:00
|
|
|
foo = essai(device, K);
|
|
|
|
fprintf(stderr, "\tessai -> %d\n", foo);
|
|
|
|
|
2019-05-25 02:40:13 +11:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
/* --------------------------------------------------------------------- */
|
|
|
|
|
|
|
|
|