2
Sliced vbi autodetection demonstration utility
3
Copyright (C) 2004 Hans Verkuil <hverkuil@xs4all.nl>
5
This program is free software; you can redistribute it and/or modify
6
it under the terms of the GNU General Public License as published by
7
the Free Software Foundation; either version 2 of the License, or
8
(at your option) any later version.
10
This program is distributed in the hope that it will be useful,
11
but WITHOUT ANY WARRANTY; without even the implied warranty of
12
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13
GNU General Public License for more details.
15
You should have received a copy of the GNU General Public License
16
along with this program; if not, write to the Free Software
17
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20
/* This simple utility detects which VBI types are transmitted on
21
each field/line. It serves both as example source and as a tool to
22
test the sliced VBI implementation.
24
Usage: sliced-vbi-detect [device]
25
Without a device name as argument it will fallback to /dev/vbi0.
29
#include <features.h> /* Uses _GNU_SOURCE to define getsubopt in stdlib.h */
35
#include <sys/types.h>
39
#include <sys/ioctl.h>
43
#include <linux/videodev2.h>
45
static void detect(int fh, struct v4l2_sliced_vbi_format *fmt)
47
struct v4l2_sliced_vbi_data *buf = malloc(fmt->io_size);
50
for (cnt = 0; cnt < 5; cnt++) {
51
int size = read(fh, buf, fmt->io_size);
55
printf("size = %d\n", size);
60
for (i = 0; i < size / sizeof(*buf); i++) {
67
if (line < 0 || line >= 24) {
68
printf("line %d out of range\n", line);
72
fmt->service_lines[field][line] |= buf[i].id;
78
static void v2s(int id)
81
case V4L2_SLICED_TELETEXT_B: printf(" TELETEXT"); break;
82
case V4L2_SLICED_CAPTION_525: printf(" CC"); break;
83
case V4L2_SLICED_WSS_625: printf(" WSS"); break;
84
case V4L2_SLICED_VPS: printf(" VPS"); break;
85
default: printf(" UNKNOWN %x", id); break;
89
int main(int argc, char **argv)
91
char *device = "/dev/vbi0";
92
struct v4l2_format vbifmt;
93
struct v4l2_sliced_vbi_format vbiresult;
99
fh = open(device, O_RDONLY);
102
fprintf(stderr, "cannot open %s\n", device);
105
memset(&vbiresult, 0, sizeof(vbiresult));
106
for (i = 0; i < 16; i++) {
110
memset(&vbifmt, 0, sizeof(vbifmt));
111
vbifmt.type = V4L2_BUF_TYPE_SLICED_VBI_CAPTURE;
112
for (l = 0; l < 24; l++) {
113
vbifmt.fmt.sliced.service_lines[0][l] = 1 << i;
114
vbifmt.fmt.sliced.service_lines[1][l] = 1 << i;
116
if (ioctl(fh, VIDIOC_S_FMT, &vbifmt) < 0) {
119
perror("IVTV_IOC_S_VBI_FMT");
122
vbiresult.io_size = vbifmt.fmt.sliced.io_size;
123
for (l = 0; l < 24; l++) {
124
set |= vbifmt.fmt.sliced.service_lines[0][l] |
125
vbifmt.fmt.sliced.service_lines[1][l];
127
detect(fh, &vbiresult);
130
for (f = 0; f < 2; f++) {
131
printf("Field %d:\n", f);
132
for (i = 6; i < 24; i++) {
133
unsigned set = vbiresult.service_lines[f][i];
135
printf(" Line %2d:", i);
136
for (b = 0; b < 16; b++) {