From 991308f5b216bf06177dfd7bc93fb4ca3228ae80 Mon Sep 17 00:00:00 2001 From: tth Date: Sun, 21 Jul 2019 13:36:14 +0200 Subject: [PATCH] adding a new tool : video-infos --- .gitignore | 1 + v4l2/Makefile | 9 +++- v4l2/v4l2_pr_structs.c | 21 +++++++-- v4l2/v4l2_pr_structs.h | 4 ++ v4l2/video-infos.c | 104 +++++++++++++++++++++++++++++++++++++++++ 5 files changed, 134 insertions(+), 5 deletions(-) create mode 100644 v4l2/video-infos.c diff --git a/.gitignore b/.gitignore index add1a91..0a0f7e4 100644 --- a/.gitignore +++ b/.gitignore @@ -17,6 +17,7 @@ v4l2/capture v4l2/grabvidseq v4l2/*.o v4l2/*.ppm +v4l2/video-infos tools/fimg2png tools/fimg2pnm diff --git a/v4l2/Makefile b/v4l2/Makefile index 57c8ea5..2c4224f 100644 --- a/v4l2/Makefile +++ b/v4l2/Makefile @@ -14,13 +14,18 @@ funcs.o: funcs.c funcs.h Makefile v4l2_pr_structs.o: v4l2_pr_structs.c v4l2_pr_structs.h Makefile gcc ${COPT} -c $< +grabvidseq: grabvidseq.c Makefile + gcc -Wall -g $< ../libfloatimg.a -lv4l2 -o $@ + +video-infos: video-infos.c Makefile funcs.o v4l2_pr_structs.o + gcc -Wall -g $< ../libfloatimg.a funcs.o v4l2_pr_structs.o -o $@ + + # --------------- # external things capture: capture.c Makefile gcc -Wall -g $< -o $@ -grabvidseq: grabvidseq.c Makefile - gcc -Wall -g $< ../libfloatimg.a -lv4l2 -o $@ diff --git a/v4l2/v4l2_pr_structs.c b/v4l2/v4l2_pr_structs.c index 15affac..417eb70 100644 --- a/v4l2/v4l2_pr_structs.c +++ b/v4l2/v4l2_pr_structs.c @@ -27,11 +27,26 @@ switch(type) { return "???"; } /* --------------------------------------------------------------------- */ +int pr_v4l2_capability(char *txt, struct v4l2_capability *ptr) +{ +fprintf(FP, "-- v4l2_capability, %-15s %p\n", txt, ptr); + +fprintf(FP, " driver %s\n", ptr->driver); +fprintf(FP, " card %s\n", ptr->card); +fprintf(FP, " bus info %s\n", ptr->bus_info); + +fprintf(FP, " version %X\n", ptr->version); +fprintf(FP, " capabilities %X\n", ptr->capabilities); +fprintf(FP, " device caps %X\n", ptr->device_caps); + +return -1; +} +/* --------------------------------------------------------------------- */ int pr_v4l2_format(char *txt, struct v4l2_format *ptr) { fprintf(FP, "-- v4l2_format, %-15s %p\n", txt, ptr); fprintf(FP, " type %d %s\n", ptr->type,/* enum v4l2_buf_type */ - fmttype2str(ptr->type)); + fmttype2str(ptr->type)); switch(ptr->type) { @@ -39,10 +54,10 @@ switch(ptr->type) { fprintf(FP, " dims %dx%d\n", ptr->fmt.pix.width, ptr->fmt.pix.height); - break; - default: fputs(" ???\n", FP); break; + default: fprintf(FP, "type is %d\n", ptr->type); + break; } diff --git a/v4l2/v4l2_pr_structs.h b/v4l2/v4l2_pr_structs.h index fd36a0d..350fea8 100644 --- a/v4l2/v4l2_pr_structs.h +++ b/v4l2/v4l2_pr_structs.h @@ -1,8 +1,12 @@ /* * fonctions pour afficher les structures de V4L2 + * + * WARNING : this is a work in progress ! */ /* --------------------------------------------------------------------- */ +int pr_v4l2_capability(char *txt, struct v4l2_capability *ptr); + int pr_v4l2_format(char *txt, struct v4l2_format *ptr); int pr_v4l2_requestbuffers(char *txt, struct v4l2_requestbuffers *ptr); /* --------------------------------------------------------------------- */ diff --git a/v4l2/video-infos.c b/v4l2/video-infos.c new file mode 100644 index 0000000..6ed242d --- /dev/null +++ b/v4l2/video-infos.c @@ -0,0 +1,104 @@ +/* + * tests pour capturer les webcams + */ + +#include +#include +#include +#include +#include +#include + +#include + +#include "../floatimg.h" + +#include "v4l2_pr_structs.h" +#include "funcs.h" + +int verbosity; + +/* --------------------------------------------------------------------- */ +int show_webcam_infos(char *devname, int k) +{ +int vfd, foo; + +struct v4l2_capability cap; +struct v4l2_format fmt; + +// 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); + +foo = ioctl(vfd, VIDIOC_QUERYCAP, &cap); +if (foo < 0) { + perror("ioctl QUERYCAP"); + return -4; + } +pr_v4l2_capability(devname, &cap); +if ( ! (cap.capabilities & V4L2_CAP_VIDEO_CAPTURE)) { + fprintf("%s : no video capture\n", devname); + } + +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, "\tshow_webcam_infos -> %d\n", foo); + +return 0; +} +/* --------------------------------------------------------------------- */ + +