FloatImg4PythonBinding/v4l2/t.c

94 lines
1.9 KiB
C
Raw Normal View History

2019-05-24 17:40:13 +02:00
/*
* tests pour capturer les webcams
*/
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <math.h>
#include <string.h>
2019-07-02 22:23:12 +02:00
#include <sys/ioctl.h>
2019-07-27 00:02:28 +02:00
#include <inttypes.h>
2019-07-02 22:23:12 +02:00
#include <linux/videodev2.h>
2019-07-02 19:35:08 +02:00
2019-06-05 10:57:39 +02:00
#include "../floatimg.h"
2019-08-10 18:37:52 +02:00
#include "funcs.h"
2019-05-24 17:40:13 +02:00
2019-07-02 19:35:08 +02:00
#include "v4l2_pr_structs.h"
2019-05-24 17:40:13 +02:00
int verbosity;
2019-05-25 16:16:24 +02:00
/* --------------------------------------------------------------------- */
2020-01-28 22:11:20 +01:00
int essai_get_fmt(char *dev, int k)
2019-05-25 16:16:24 +02:00
{
2020-07-24 14:04:54 +02:00
int vfd, foo;
struct v4l2_format fmt;
2020-07-24 14:04:54 +02:00
// struct v4l2_requestbuffers reqbuf;
2019-05-25 16:16:24 +02:00
2023-02-13 14:27:01 +01:00
#if DEBUG_LEVEL
2019-05-25 16:16:24 +02:00
fprintf(stderr, ">>> %s ( '%s' %d )\n", __func__, dev, k);
2023-02-13 14:27:01 +01:00
#endif
2019-05-25 16:16:24 +02:00
vfd = open_device(dev);
2019-07-29 02:53:28 +02:00
if (verbosity) fprintf(stderr, "\topen %s -> %d\n", dev, vfd);
2019-05-25 16:16:24 +02:00
2020-01-28 22:11:20 +01:00
memset(&fmt, 0, sizeof(fmt));
fmt.type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
foo = ioctl(vfd, VIDIOC_G_FMT, &fmt);
2023-02-13 14:27:01 +01:00
if (verbosity) fprintf(stderr, "%s: ioctl -> %d\n", __func__, foo);
2020-01-28 22:11:20 +01:00
if (0 != foo) {
perror("ioctl G_FMT");
return -1;
}
2019-07-02 22:23:12 +02:00
2019-08-23 23:56:36 +02:00
pr_v4l2_format("after ioctl VIDIOC_G_FMT", &fmt);
2019-07-02 22:23:12 +02:00
2020-01-22 18:53:55 +01:00
/* this function is bugged */
2019-05-25 16:16:24 +02:00
2020-01-28 22:11:20 +01:00
close(vfd);
2019-05-25 16:16:24 +02:00
return k;
}
2019-05-24 17:40:13 +02:00
/* --------------------------------------------------------------------- */
2019-07-02 19:35:08 +02:00
2019-05-24 17:40:13 +02:00
void help(int k)
{
puts("Options :");
2019-05-25 11:56:56 +02:00
puts("\t-d\tselect the video device");
2019-05-24 18:34:07 +02:00
puts("\t-K\tset the K parameter");
2019-05-24 17:40:13 +02:00
puts("\t-v\tincrease verbosity");
if (verbosity) { puts(""); fimg_print_version(1); }
2019-05-24 17:40:13 +02:00
exit(0);
}
/* --------------------------------------------------------------------- */
int main(int argc, char *argv[])
{
int foo, opt;
2019-05-25 16:16:24 +02:00
char *device = "/dev/video0";
2019-05-24 17:40:13 +02:00
int K = 0;
2019-05-25 16:16:24 +02:00
while ((opt = getopt(argc, argv, "d:hK:v")) != -1) {
2019-05-24 17:40:13 +02:00
switch(opt) {
2019-05-25 16:16:24 +02:00
case 'd': device = optarg; break;
2019-05-24 17:40:13 +02:00
case 'h': help(0); break;
case 'K': K = atol(optarg); break;
case 'v': verbosity++; break;
}
}
if (verbosity) fimg_print_version(0);
2020-01-28 22:11:20 +01:00
foo = essai_get_fmt(device, K);
2023-02-13 14:27:01 +01:00
if (verbosity || foo) fprintf(stderr, "%s: essai -> %d\n", __func__, foo);
2019-05-25 16:16:24 +02:00
2019-05-24 17:40:13 +02:00
return 0;
}
/* --------------------------------------------------------------------- */