summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
Diffstat (limited to 'test')
-rw-r--r--test/Makefile2
-rw-r--r--test/ioctl-test.c4
-rw-r--r--test/sliced-vbi-detect.c142
-rw-r--r--test/sliced-vbi-test.c22
-rw-r--r--test/vbi-test.c90
5 files changed, 175 insertions, 85 deletions
diff --git a/test/Makefile b/test/Makefile
index 2bfdcb4dc..8623e4d98 100644
--- a/test/Makefile
+++ b/test/Makefile
@@ -1,4 +1,4 @@
-FILES = ioctl-test sliced-vbi-test sliced-vbi-detect
+FILES = ioctl-test sliced-vbi-test sliced-vbi-detect vbi-test
CC = gcc
LIBS =
CFLAGS = -O3 -Wall -fomit-frame-pointer -funroll-loops -g -I ../linux/include
diff --git a/test/ioctl-test.c b/test/ioctl-test.c
index 3f2fefc44..b7dd87e94 100644
--- a/test/ioctl-test.c
+++ b/test/ioctl-test.c
@@ -6,7 +6,7 @@
and v4l_decoder.h. These messages shouldn't be handled by video
driver itself, but for internal video and/or audio decoders.
- Copyright (C) 2005 Mauro Carvalho Chehab <mchehab@brturbo.com.br>
+ Copyright (C) 2005 Mauro Carvalho Chehab <mchehab@infradead.org>
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
@@ -200,7 +200,7 @@ int main (void)
char *device="/dev/video0";
union v4l_parms p;
- if ((fd = open(device, O_RDONLY)) < 0) {
+ if ((fd = open(device, O_RDONLY)) < 0) {
perror("Couldn't open video0");
return(-1);
}
diff --git a/test/sliced-vbi-detect.c b/test/sliced-vbi-detect.c
index 3fe33f6cc..9e2a3b2c5 100644
--- a/test/sliced-vbi-detect.c
+++ b/test/sliced-vbi-detect.c
@@ -47,45 +47,45 @@
static void detect(int fh, struct v4l2_sliced_vbi_format *fmt)
{
struct v4l2_sliced_vbi_data *buf = malloc(fmt->io_size);
- int cnt;
+ int cnt;
- for (cnt = 0; cnt < 5; cnt++) {
+ for (cnt = 0; cnt < 5; cnt++) {
int size = read(fh, buf, fmt->io_size);
int i;
if (size <= 0) {
- printf("size = %d\n", size);
+ printf("size = %d\n", size);
break;
- }
- if (cnt == 0)
- continue;
+ }
+ if (cnt == 0)
+ continue;
for (i = 0; i < size / sizeof(*buf); i++) {
- int field, line;
-
- line = buf[i].line;
- field = buf[i].field;
- if (buf[i].id == 0)
- continue;
- if (line < 0 || line >= 24) {
- printf("line %d out of range\n", line);
- free(buf);
- return;
- }
- fmt->service_lines[field][line] |= buf[i].id;
+ int field, line;
+
+ line = buf[i].line;
+ field = buf[i].field;
+ if (buf[i].id == 0)
+ continue;
+ if (line < 0 || line >= 24) {
+ printf("line %d out of range\n", line);
+ free(buf);
+ return;
+ }
+ fmt->service_lines[field][line] |= buf[i].id;
}
}
- free(buf);
+ free(buf);
}
void v2s(int id)
{
- switch (id) {
- case V4L2_SLICED_TELETEXT_B: printf(" TELETEXT"); break;
- case V4L2_SLICED_CAPTION_525: printf(" CC"); break;
- case V4L2_SLICED_WSS_625: printf(" WSS"); break;
- case V4L2_SLICED_VPS: printf(" VPS"); break;
- default: printf(" UNKNOWN %x", id); break;
- }
+ switch (id) {
+ case V4L2_SLICED_TELETEXT_B: printf(" TELETEXT"); break;
+ case V4L2_SLICED_CAPTION_525: printf(" CC"); break;
+ case V4L2_SLICED_WSS_625: printf(" WSS"); break;
+ case V4L2_SLICED_VPS: printf(" VPS"); break;
+ default: printf(" UNKNOWN %x", id); break;
+ }
}
int main(int argc, char **argv)
@@ -94,53 +94,53 @@ int main(int argc, char **argv)
struct v4l2_format vbifmt;
struct v4l2_sliced_vbi_format vbiresult;
int fh;
- int f, i, b;
+ int f, i, b;
if (argc == 2)
- device = argv[1];
- fh = open(device, O_RDONLY);
-
- if (fh == -1) {
- fprintf(stderr, "cannot open %s\n", device);
- return 1;
- }
- memset(&vbiresult, 0, sizeof(vbiresult));
- for (i = 0; i < 16; i++) {
- int l;
- int set = 0;
-
- memset(&vbifmt, 0, sizeof(vbifmt));
- vbifmt.type = V4L2_BUF_TYPE_SLICED_VBI_CAPTURE;
- for (l = 0; l < 24; l++) {
- vbifmt.fmt.sliced.service_lines[0][l] = 1 << i;
- vbifmt.fmt.sliced.service_lines[1][l] = 1 << i;
- }
- if (ioctl(fh, VIDIOC_S_FMT, &vbifmt) < 0) {
- if (errno == EINVAL)
- continue;
- perror("IVTV_IOC_S_VBI_FMT");
- exit(-1);
- }
- vbiresult.io_size = vbifmt.fmt.sliced.io_size;
- for (l = 0; l < 24; l++) {
- set |= vbifmt.fmt.sliced.service_lines[0][l] |
- vbifmt.fmt.sliced.service_lines[1][l];
- }
- detect(fh, &vbiresult);
- }
+ device = argv[1];
+ fh = open(device, O_RDONLY);
+
+ if (fh == -1) {
+ fprintf(stderr, "cannot open %s\n", device);
+ return 1;
+ }
+ memset(&vbiresult, 0, sizeof(vbiresult));
+ for (i = 0; i < 16; i++) {
+ int l;
+ int set = 0;
+
+ memset(&vbifmt, 0, sizeof(vbifmt));
+ vbifmt.type = V4L2_BUF_TYPE_SLICED_VBI_CAPTURE;
+ for (l = 0; l < 24; l++) {
+ vbifmt.fmt.sliced.service_lines[0][l] = 1 << i;
+ vbifmt.fmt.sliced.service_lines[1][l] = 1 << i;
+ }
+ if (ioctl(fh, VIDIOC_S_FMT, &vbifmt) < 0) {
+ if (errno == EINVAL)
+ continue;
+ perror("IVTV_IOC_S_VBI_FMT");
+ exit(-1);
+ }
+ vbiresult.io_size = vbifmt.fmt.sliced.io_size;
+ for (l = 0; l < 24; l++) {
+ set |= vbifmt.fmt.sliced.service_lines[0][l] |
+ vbifmt.fmt.sliced.service_lines[1][l];
+ }
+ detect(fh, &vbiresult);
+ }
close(fh);
- for (f = 0; f < 2; f++) {
- printf("Field %d:\n", f);
- for (i = 6; i < 24; i++) {
- unsigned set = vbiresult.service_lines[f][i];
-
- printf(" Line %2d:", i);
- for (b = 0; b < 16; b++) {
- if (set & (1 << b))
- v2s(1 << b);
- }
- printf("\n");
- }
- }
+ for (f = 0; f < 2; f++) {
+ printf("Field %d:\n", f);
+ for (i = 6; i < 24; i++) {
+ unsigned set = vbiresult.service_lines[f][i];
+
+ printf(" Line %2d:", i);
+ for (b = 0; b < 16; b++) {
+ if (set & (1 << b))
+ v2s(1 << b);
+ }
+ printf("\n");
+ }
+ }
return 0;
}
diff --git a/test/sliced-vbi-test.c b/test/sliced-vbi-test.c
index a44f75565..ae4e1b27d 100644
--- a/test/sliced-vbi-test.c
+++ b/test/sliced-vbi-test.c
@@ -397,24 +397,24 @@ void process(struct v4l2_sliced_vbi_data *s)
if (s->id == 0)
return;
- //printf("%04d: line %02u field %d type %x\n", frames, s->line, s->field, s->id);
+ //printf("%04d: line %02u field %d type %x\n", frames, s->line, s->field, s->id);
switch (s->id) {
case V4L2_SLICED_TELETEXT_B:
printf("teletext\n");
break;
case V4L2_SLICED_VPS:
- if (s->line != 16 || s->field)
- break;
+ if (s->line != 16 || s->field)
+ break;
decode_vps(s);
break;
case V4L2_SLICED_WSS_625:
- if (s->line != 23 || s->field)
- break;
+ if (s->line != 23 || s->field)
+ break;
decode_wss(s);
break;
case V4L2_SLICED_CAPTION_525:
- if (s->line != 21)
- break;
+ if (s->line != 21)
+ break;
decode_cc(s);
break;
default:
@@ -427,7 +427,7 @@ int main(int argc, char **argv)
{
char *device = "/dev/vbi0";
struct v4l2_format fmt;
- v4l2_std_id std;
+ v4l2_std_id std;
struct v4l2_sliced_vbi_data *buf;
int fh;
@@ -440,10 +440,10 @@ int main(int argc, char **argv)
return 1;
}
- setbuf(stdout, NULL);
+ setbuf(stdout, NULL);
ioctl(fh, VIDIOC_G_STD, &std);
- fmt.type = V4L2_BUF_TYPE_SLICED_VBI_CAPTURE;
+ fmt.type = V4L2_BUF_TYPE_SLICED_VBI_CAPTURE;
fmt.fmt.sliced.service_set = (std & V4L2_STD_NTSC) ? V4L2_SLICED_VBI_525 : V4L2_SLICED_VBI_625;
fmt.fmt.sliced.reserved[0] = 0;
fmt.fmt.sliced.reserved[1] = 0;
@@ -461,7 +461,7 @@ int main(int argc, char **argv)
if (size <= 0)
break;
- frames++;
+ frames++;
for (i = 0; i < size / sizeof(struct v4l2_sliced_vbi_data); i++) {
process(&buf[i]);
}
diff --git a/test/vbi-test.c b/test/vbi-test.c
new file mode 100644
index 000000000..27fd7a528
--- /dev/null
+++ b/test/vbi-test.c
@@ -0,0 +1,90 @@
+/*
+ v4l-ioctl-test - This small utility checks VBI format
+
+ Copyright (C) 2006 Mauro Carvalho Chehab <mchehab@infradead.org>
+
+ 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.
+
+ You should have received a copy of the GNU General Public License
+ along with this program; if not, write to the Free Software
+ Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+ */
+
+#include <stdio.h>
+#include <unistd.h>
+#include <string.h>
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <sys/ioctl.h>
+#include <fcntl.h>
+#define __user
+#include <linux/videodev.h>
+
+/* All possible parameters used on v4l ioctls */
+union v4l_parms {
+ /* V4L1 structs */
+ struct vbi_format v1;
+
+ /* V4L2 structs */
+ struct v4l2_format v2;
+};
+
+/* All defined ioctls */
+int ioctls[] = {
+ /* V4L ioctls */
+
+ VIDIOCGVBIFMT,/* struct vbi_format */
+
+ /* V4L2 ioctls */
+
+ VIDIOC_G_FMT,/* struct v4l2_format */
+};
+#define S_IOCTLS sizeof(ioctls)/sizeof(ioctls[0])
+
+/********************************************************************/
+int main (void)
+{
+ int fd=0, ret=0;
+ char *device="/dev/video0";
+ union v4l_parms p;
+
+ if ((fd = open(device, O_RDONLY)) < 0) {
+ perror("Couldn't open video0");
+ return(-1);
+ }
+
+
+ /* V4L1 call */
+ memset(&p,0,sizeof(p));
+ ret=ioctl(fd,VIDIOCGVBIFMT, (void *) &p);
+
+ printf ("V4L1 call: ret=%i: sampling_rate=%d, samples_per_line=%d, "
+ "sample_format=%d, start=%d/%d, count=%d/%d, flags=%d\n", ret,
+ p.v1.sampling_rate,p.v1.samples_per_line, p.v1.sample_format,
+ p.v1.start[0],p.v1.start[1],p.v1.count[0],p.v1.count[1],p.v1.flags);
+
+
+ /* V4L2 call */
+ memset(&p,0,sizeof(p));
+ p.v2.type=V4L2_BUF_TYPE_VBI_CAPTURE;
+ ret=ioctl(fd,VIDIOC_G_FMT, (void *) &p);
+
+ printf ("V4L2 call: ret=%i: sampling_rate=%d, samples_per_line=%d, "
+ "sample_format=%d, offset=%d, start=%d/%d, count=%d/%d\n", ret,
+ p.v2.fmt.vbi.sampling_rate,p.v2.fmt.vbi.samples_per_line,
+ p.v2.fmt.vbi.sample_format,p.v2.fmt.vbi.offset,
+ p.v2.fmt.vbi.start[0],p.v2.fmt.vbi.start[1],
+ p.v2.fmt.vbi.count[0],p.v2.fmt.vbi.count[1]);
+
+ close (fd);
+
+ return (0);
+}