From 7275da27eb5aa09ee9b599ace5e153848edd54a8 Mon Sep 17 00:00:00 2001 From: Mauro Carvalho Chehab Date: Sun, 12 Nov 2006 03:07:30 -0200 Subject: Improved ioctl-test From: Mauro Carvalho Chehab Now, it tests and diagnostics some api troubles. Still lacks several ioctls. Signed-off-by: Mauro Carvalho Chehab --- v4l2-apps/test/ioctl-test.c | 212 ++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 207 insertions(+), 5 deletions(-) (limited to 'v4l2-apps/test') diff --git a/v4l2-apps/test/ioctl-test.c b/v4l2-apps/test/ioctl-test.c index 6d78ad0f8..335ccf102 100644 --- a/v4l2-apps/test/ioctl-test.c +++ b/v4l2-apps/test/ioctl-test.c @@ -51,8 +51,9 @@ typedef u_int32_t u32; /* All possible parameters used on v4l ioctls */ union v4l_parms { int i; - unsigned long l; - u32 u_32; + unsigned long u64; + u32 u32; + v4l2_std_id id; #ifdef CONFIG_VIDEO_V4L1_COMPAT /* V4L1 structs */ @@ -148,10 +149,12 @@ int ioctls[] = { VIDIOC_ENUMAUDOUT,/* struct v4l2_audioout */ VIDIOC_ENUM_FMT,/* struct v4l2_fmtdesc */ VIDIOC_ENUMINPUT,/* struct v4l2_input */ + VIDIOC_G_INPUT,/* int */ + VIDIOC_S_INPUT,/* int */ VIDIOC_ENUMOUTPUT,/* struct v4l2_output */ VIDIOC_ENUMSTD,/* struct v4l2_standard */ -// VIDIOC_G_AUDIO_OLD,/* struct v4l2_audio */ -// VIDIOC_G_AUDOUT_OLD,/* struct v4l2_audioout */ + VIDIOC_G_STD, /*v4l2_std_id */ + VIDIOC_S_STD, /*v4l2_std_id */ VIDIOC_G_CROP,/* struct v4l2_crop */ VIDIOC_G_CTRL,/* struct v4l2_control */ VIDIOC_G_FMT,/* struct v4l2_format */ @@ -159,7 +162,6 @@ int ioctls[] = { VIDIOC_G_MODULATOR,/* struct v4l2_modulator */ VIDIOC_G_PARM,/* struct v4l2_streamparm */ VIDIOC_G_TUNER,/* struct v4l2_tuner */ -// VIDIOC_OVERLAY_OLD,/* int */ VIDIOC_QBUF,/* struct v4l2_buffer */ VIDIOC_QUERYBUF,/* struct v4l2_buffer */ VIDIOC_QUERYCTRL,/* struct v4l2_queryctrl */ @@ -172,6 +174,12 @@ int ioctls[] = { VIDIOC_S_PARM,/* struct v4l2_streamparm */ VIDIOC_TRY_FMT,/* struct v4l2_format */ +#if 0 + VIDIOC_G_AUDIO_OLD,/* struct v4l2_audio */ + VIDIOC_G_AUDOUT_OLD,/* struct v4l2_audioout */ + VIDIOC_OVERLAY_OLD,/* int */ +#endif + #ifdef INTERNAL /* V4L2 internal ioctls */ AUDC_SET_RADIO,/* no args */ @@ -201,6 +209,193 @@ int ioctls[] = { #define S_IOCTLS sizeof(ioctls)/sizeof(ioctls[0]) /********************************************************************/ + +int get_capabilities (int fd, union v4l_parms *p) +{ + int ret; + + ret=ioctl(fd,VIDIOC_QUERYCAP,(void *) &p); + if (ret>=0) { + struct v4l2_capability *pq= (struct v4l2_capability *)&p; + printf ("driver=%s, card=%s, bus=%s, version=0x%08x, " + "capabilities=0x%08x\n", + pq->driver,pq->card,pq->bus_info, + pq->version, + pq->capabilities); + } + return ret; +} + +#define ERR "*** ERROR " +#define WARN "* Warning " + +int get_set_stds (int fd, union v4l_parms *p) +{ + struct v4l2_standard *pq=(void *)p; + int ok=0,ret,i; + v4l2_std_id id; + + for (i=0; ok==0; i++) { + pq->index=i; + ok=ioctl(fd,VIDIOC_ENUMSTD,pq); + if (ok>=0) { + printf ("STANDARD: index=%d, id=%Ld, name=%s, fps=%.3f, " + "framelines=%d\n", pq->index, + (unsigned long long)pq->id, pq->name, + 1.*pq->frameperiod.denominator/pq->frameperiod.numerator, + pq->framelines); + } else + break; + id=pq->id; + p->id=id; + ret=ioctl(fd,VIDIOC_S_STD,p); + if (ret) { + printf (ERR "%i while trying to set STD to %08x\n",ret, + (unsigned int) id); + } + ret=ioctl(fd,VIDIOC_G_STD,p); + if (ret) { + printf (ERR "%i while trying to get STD id\n",ret); + } + if (id & p->id) { + if (id != p->id) { + printf (WARN "Received a std subset (%08x std) while trying to adjust to %08x\n", + (unsigned int) p->id,(unsigned int) id); + } + } else + printf (ERR "Received %08x std while trying to adjust to %08x\n", + (unsigned int) p->id,(unsigned int) id); + + } + return ok; +} + +int get_set_inputs (int fd, union v4l_parms *arg) +{ + struct v4l2_input *p=(void *)arg; + int ok=0,ret,i; + int input; + + for (i=0; ok==0; i++) { + p->index=i; + ok=ioctl(fd,VIDIOC_ENUMINPUT,p); + if (ok>=0) { + + printf ("INPUT: index=%d, name=%s, type=%d, audioset=%d, " + "tuner=%d, std=%08x, status=%d\n", + p->index,p->name,p->type,p->audioset, + p->tuner, + (unsigned int)p->std, + p->status); + + } else + break; + input=p->index; + arg->i=input; + ret=ioctl(fd,VIDIOC_S_INPUT,arg); + if (ret) { + printf (ERR "%i while trying to set INPUT to %d\n",ret, + input); + } + ret=ioctl(fd,VIDIOC_G_INPUT,arg); + if (ret) { + printf (ERR "%i while trying to get INPUT id\n",ret); + } + if (input != arg->i) { + printf ("Input is different than expected (received %i, set %i)\n", + input, p->index); + } + } + return ok; +} + +int get_set_formats (int fd, union v4l_parms *arg) +{ + struct v4l2_fmtdesc *p=(void *)arg; + int ok=0,ret,i; + struct v4l2_format fmt; + struct v4l2_streamparm parm; + struct v4l2_captureparm *c; + + + for (i=0; ok==0; i++) { + p->index=i; + p->type=V4L2_BUF_TYPE_VIDEO_CAPTURE; + + ok=ioctl(fd,VIDIOC_ENUM_FMT,p); + if (ok>=0) { + printf ("FORMAT: index=%d, type=%d, flags=%d, description=%s\n\t" + "pixelformat=0x%08x\n", + p->index, p->type, p->flags,p->description, + p->pixelformat); + } else + break; + + parm.type = V4L2_BUF_TYPE_VIDEO_CAPTURE; + if (ioctl(fd,VIDIOC_G_PARM,&parm)>=0) { + c=&parm.parm.capture; + printf ("PARM: capability=%d, capturemode=%d, frame time =%.3f ns " + "ext=%x, readbuf=%d\n", + c->capability, + c->capturemode, + 100.*c->timeperframe.numerator/c->timeperframe.denominator, + c->extendedmode, c->readbuffers); + } else + perror ("VIDIOC_G_PARM"); + +#if 0 + fmt.type=p->type; + fmt.pixelformat=p->pixelformat; + + ret=ioctl(fd,VIDIOC_G_FMT,arg); + if (ret < 0) { + printf("VIDIOC_G_FMT failed\n"); + continue; + } + + switch (f->type) { + case V4L2_BUF_TYPE_VIDEO_CAPTURE: + + err = cx8800_try_fmt(dev,fh,f); + if (0 != err) + return err; + + fmt.pixelformat=p->pixelformat; + fmt. + fh->fmt = format_by_fourcc(f->fmt.pix.pixelformat); + fh->width = f->fmt.pix.width; + fh->height = f->fmt.pix.height; + fh->vidq.field = f->fmt.pix.field; + return 0; + case V4L2_BUF_TYPE_VBI_CAPTURE: + cx8800_vbi_fmt(dev, f); + return 0; + default: + printf(WARN "format type not implemented\n"); + continue; + } + + + input=p->index; + arg->i=input; + ret=ioctl(fd,VIDIOC_S_INPUT,arg); + if (ret) { + printf (ERR "%i while trying to set INPUT to %d\n",ret, + input); + } + ret=ioctl(fd,VIDIOC_G_INPUT,arg); + if (ret) { + printf (ERR "%i while trying to get INPUT id\n",ret); + } + if (input != arg->i) { + printf ("Input is different than expected (received %i, set %i)\n", + input, p->index); + } +#endif + } + return ok; +} + int main (void) { int fd=0, ret=0; @@ -213,11 +408,18 @@ int main (void) return(-1); } + get_capabilities (fd, &p); + get_set_stds (fd, &p); + get_set_inputs (fd, &p); + get_set_formats (fd, &p); + +#if 0 for (i=0;i Date: Wed, 15 Nov 2006 15:42:04 -0200 Subject: Initiated v4l-apps/lib V4L2 functions From: Mauro Carvalho Chehab - Created v4l2_driver.c with some basic functions to: . Enum STD, INPUT and FORMAT . GET/SET STD and INPUT . GET PARAM - ioctl-test reverted back to a simple "brute-force" all ioctl call; - driver-test created to: . test V4L2 kernel drivers; . implement all functions provided by v4l2 library - driver-test should grow following the changes at v4l2-apps/lib Signed-off-by: Mauro Carvalho Chehab --- v4l2-apps/test/Makefile | 8 +- v4l2-apps/test/driver-test.c | 65 +++++++++++++++ v4l2-apps/test/ioctl-test.c | 193 ------------------------------------------- 3 files changed, 72 insertions(+), 194 deletions(-) create mode 100644 v4l2-apps/test/driver-test.c (limited to 'v4l2-apps/test') diff --git a/v4l2-apps/test/Makefile b/v4l2-apps/test/Makefile index b6a83b2b3..6c1edf6a5 100644 --- a/v4l2-apps/test/Makefile +++ b/v4l2-apps/test/Makefile @@ -6,7 +6,8 @@ binaries = ioctl-test \ sliced-vbi-test \ sliced-vbi-detect \ vbi-test \ - v4lgrab + v4lgrab \ + driver-test .PHONY: all clean install @@ -17,4 +18,9 @@ clean:: install: +../lib/libv4l2.a: ../lib/v4l2_driver.c ../lib/frequencies.c + make -C ../lib libv4l2.a + +driver-test: driver-test.o ../lib/libv4l2.a + include ../Make.rules diff --git a/v4l2-apps/test/driver-test.c b/v4l2-apps/test/driver-test.c new file mode 100644 index 000000000..cf3511fc4 --- /dev/null +++ b/v4l2-apps/test/driver-test.c @@ -0,0 +1,65 @@ +/* + driver-test.c - This program tests V4L2 kernel drivers + + Copyright (C) 2006 Mauro Carvalho Chehab + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + */ + +#include "../lib/v4l2_driver.h" +#include + +int main(void) +{ + struct v4l2_driver drv; + struct drv_list *cur; + + if (v4l2_open ("/dev/video0", 1,&drv)<0) { + perror("open"); + return -1; + } + if (v4l2_enum_stds (&drv)<0) { + perror("enum_stds"); + } + + /* Tries all video standards */ + for (cur=drv.stds;cur!=NULL;cur=cur->next) { + v4l2_std_id id=((struct v4l2_standard *)cur->curr)->id; + if (cur->curr) + if (v4l2_setget_std (&drv, V4L2_SET_GET, &id)) + perror("set_std"); + } + + if (v4l2_enum_input (&drv)<0) { + perror("enum_input"); + } + + /* Tries all video inputs */ + for (cur=drv.inputs;cur!=NULL;cur=cur->next) { + struct v4l2_input input; + input.index=((struct v4l2_input* )cur->curr)->index; + if (cur->curr) + if (v4l2_setget_input (&drv, V4L2_SET_GET, &input)) + perror("set_input"); + } + + if (v4l2_enum_fmt_cap (&drv)<0) { + perror("enum_fmt_cap"); + } + if (v4l2_get_parm (&drv)<0) { + perror("get_parm"); + } + if (v4l2_close (&drv)<0) { + perror("close"); + return -1; + } + return 0; +} diff --git a/v4l2-apps/test/ioctl-test.c b/v4l2-apps/test/ioctl-test.c index 335ccf102..f483338fb 100644 --- a/v4l2-apps/test/ioctl-test.c +++ b/v4l2-apps/test/ioctl-test.c @@ -210,192 +210,6 @@ int ioctls[] = { /********************************************************************/ -int get_capabilities (int fd, union v4l_parms *p) -{ - int ret; - - ret=ioctl(fd,VIDIOC_QUERYCAP,(void *) &p); - if (ret>=0) { - struct v4l2_capability *pq= (struct v4l2_capability *)&p; - printf ("driver=%s, card=%s, bus=%s, version=0x%08x, " - "capabilities=0x%08x\n", - pq->driver,pq->card,pq->bus_info, - pq->version, - pq->capabilities); - } - return ret; -} - -#define ERR "*** ERROR " -#define WARN "* Warning " - -int get_set_stds (int fd, union v4l_parms *p) -{ - struct v4l2_standard *pq=(void *)p; - int ok=0,ret,i; - v4l2_std_id id; - - for (i=0; ok==0; i++) { - pq->index=i; - ok=ioctl(fd,VIDIOC_ENUMSTD,pq); - if (ok>=0) { - printf ("STANDARD: index=%d, id=%Ld, name=%s, fps=%.3f, " - "framelines=%d\n", pq->index, - (unsigned long long)pq->id, pq->name, - 1.*pq->frameperiod.denominator/pq->frameperiod.numerator, - pq->framelines); - } else - break; - id=pq->id; - p->id=id; - ret=ioctl(fd,VIDIOC_S_STD,p); - if (ret) { - printf (ERR "%i while trying to set STD to %08x\n",ret, - (unsigned int) id); - } - ret=ioctl(fd,VIDIOC_G_STD,p); - if (ret) { - printf (ERR "%i while trying to get STD id\n",ret); - } - if (id & p->id) { - if (id != p->id) { - printf (WARN "Received a std subset (%08x std) while trying to adjust to %08x\n", - (unsigned int) p->id,(unsigned int) id); - } - } else - printf (ERR "Received %08x std while trying to adjust to %08x\n", - (unsigned int) p->id,(unsigned int) id); - - } - return ok; -} - -int get_set_inputs (int fd, union v4l_parms *arg) -{ - struct v4l2_input *p=(void *)arg; - int ok=0,ret,i; - int input; - - for (i=0; ok==0; i++) { - p->index=i; - ok=ioctl(fd,VIDIOC_ENUMINPUT,p); - if (ok>=0) { - - printf ("INPUT: index=%d, name=%s, type=%d, audioset=%d, " - "tuner=%d, std=%08x, status=%d\n", - p->index,p->name,p->type,p->audioset, - p->tuner, - (unsigned int)p->std, - p->status); - - } else - break; - input=p->index; - arg->i=input; - ret=ioctl(fd,VIDIOC_S_INPUT,arg); - if (ret) { - printf (ERR "%i while trying to set INPUT to %d\n",ret, - input); - } - ret=ioctl(fd,VIDIOC_G_INPUT,arg); - if (ret) { - printf (ERR "%i while trying to get INPUT id\n",ret); - } - if (input != arg->i) { - printf ("Input is different than expected (received %i, set %i)\n", - input, p->index); - } - } - return ok; -} - -int get_set_formats (int fd, union v4l_parms *arg) -{ - struct v4l2_fmtdesc *p=(void *)arg; - int ok=0,ret,i; - struct v4l2_format fmt; - struct v4l2_streamparm parm; - struct v4l2_captureparm *c; - - - for (i=0; ok==0; i++) { - p->index=i; - p->type=V4L2_BUF_TYPE_VIDEO_CAPTURE; - - ok=ioctl(fd,VIDIOC_ENUM_FMT,p); - if (ok>=0) { - printf ("FORMAT: index=%d, type=%d, flags=%d, description=%s\n\t" - "pixelformat=0x%08x\n", - p->index, p->type, p->flags,p->description, - p->pixelformat); - } else - break; - - parm.type = V4L2_BUF_TYPE_VIDEO_CAPTURE; - if (ioctl(fd,VIDIOC_G_PARM,&parm)>=0) { - c=&parm.parm.capture; - printf ("PARM: capability=%d, capturemode=%d, frame time =%.3f ns " - "ext=%x, readbuf=%d\n", - c->capability, - c->capturemode, - 100.*c->timeperframe.numerator/c->timeperframe.denominator, - c->extendedmode, c->readbuffers); - } else - perror ("VIDIOC_G_PARM"); - -#if 0 - fmt.type=p->type; - fmt.pixelformat=p->pixelformat; - - ret=ioctl(fd,VIDIOC_G_FMT,arg); - if (ret < 0) { - printf("VIDIOC_G_FMT failed\n"); - continue; - } - - switch (f->type) { - case V4L2_BUF_TYPE_VIDEO_CAPTURE: - - err = cx8800_try_fmt(dev,fh,f); - if (0 != err) - return err; - - fmt.pixelformat=p->pixelformat; - fmt. - fh->fmt = format_by_fourcc(f->fmt.pix.pixelformat); - fh->width = f->fmt.pix.width; - fh->height = f->fmt.pix.height; - fh->vidq.field = f->fmt.pix.field; - return 0; - case V4L2_BUF_TYPE_VBI_CAPTURE: - cx8800_vbi_fmt(dev, f); - return 0; - default: - printf(WARN "format type not implemented\n"); - continue; - } - - - input=p->index; - arg->i=input; - ret=ioctl(fd,VIDIOC_S_INPUT,arg); - if (ret) { - printf (ERR "%i while trying to set INPUT to %d\n",ret, - input); - } - ret=ioctl(fd,VIDIOC_G_INPUT,arg); - if (ret) { - printf (ERR "%i while trying to get INPUT id\n",ret); - } - if (input != arg->i) { - printf ("Input is different than expected (received %i, set %i)\n", - input, p->index); - } -#endif - } - return ok; -} - int main (void) { int fd=0, ret=0; @@ -408,18 +222,11 @@ int main (void) return(-1); } - get_capabilities (fd, &p); - get_set_stds (fd, &p); - get_set_inputs (fd, &p); - get_set_formats (fd, &p); - -#if 0 for (i=0;i Date: Wed, 15 Nov 2006 17:49:14 -0200 Subject: Improved v4l2_driver From: Mauro Carvalho Chehab - Better presentation of version - Make v4l2_enum_fmt generic for all types - Added v4l2_gettryset_fmt_cap to GET/TRY/SET fmt on capture - driver-test now sets a video format Signed-off-by: Mauro Carvalho Chehab --- v4l2-apps/test/driver-test.c | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) (limited to 'v4l2-apps/test') diff --git a/v4l2-apps/test/driver-test.c b/v4l2-apps/test/driver-test.c index cf3511fc4..53ce6b9d7 100644 --- a/v4l2-apps/test/driver-test.c +++ b/v4l2-apps/test/driver-test.c @@ -51,9 +51,21 @@ int main(void) perror("set_input"); } - if (v4l2_enum_fmt_cap (&drv)<0) { + if (v4l2_enum_fmt (&drv,V4L2_BUF_TYPE_VIDEO_CAPTURE)<0) { perror("enum_fmt_cap"); } + + /* Tries all formats */ + for (cur=drv.fmt_caps;cur!=NULL;cur=cur->next) { + struct v4l2_format fmt; + uint32_t pixelformat=((struct v4l2_fmtdesc *)cur->curr)->pixelformat; + if (cur->curr) { + if (v4l2_gettryset_fmt_cap (&drv,V4L2_SET,&fmt, 640, 480, + pixelformat,V4L2_FIELD_ANY)) + perror("set_input"); + } + } + if (v4l2_get_parm (&drv)<0) { perror("get_parm"); } -- cgit v1.2.3 From f90bff01fa3468160e9403fb488c1f319c30c6dd Mon Sep 17 00:00:00 2001 From: Mauro Carvalho Chehab Date: Thu, 16 Nov 2006 12:02:28 -0200 Subject: Start adding v4l2_mmap_bufs to prepare for stream From: Mauro Carvalho Chehab This method requests buffers and maps it into a mmaped memory. Still under testing. Still need other stuff to make stream to work. Signed-off-by: Mauro Carvalho Chehab --- v4l2-apps/test/driver-test.c | 3 +++ 1 file changed, 3 insertions(+) (limited to 'v4l2-apps/test') diff --git a/v4l2-apps/test/driver-test.c b/v4l2-apps/test/driver-test.c index 53ce6b9d7..809ee170c 100644 --- a/v4l2-apps/test/driver-test.c +++ b/v4l2-apps/test/driver-test.c @@ -69,6 +69,9 @@ int main(void) if (v4l2_get_parm (&drv)<0) { perror("get_parm"); } + + v4l2_mmap_bufs(&drv, 2); + if (v4l2_close (&drv)<0) { perror("close"); return -1; -- cgit v1.2.3