~ubuntu-branches/ubuntu/precise/v4l-utils/precise

« back to all changes in this revision

Viewing changes to contrib/test/vbi-test.c

  • Committer: Bazaar Package Importer
  • Author(s): Gregor Jasny
  • Date: 2010-02-28 19:44:15 UTC
  • Revision ID: james.westby@ubuntu.com-20100228194415-067hdj8rvawj91zw
Tags: upstream-0.7.90
ImportĀ upstreamĀ versionĀ 0.7.90

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
   v4l-ioctl-test - This small utility checks VBI format
 
3
 
 
4
   Copyright (C) 2006 Mauro Carvalho Chehab <mchehab@infradead.org>
 
5
 
 
6
   This program is free software; you can redistribute it and/or modify
 
7
   it under the terms of the GNU General Public License as published by
 
8
   the Free Software Foundation; either version 2 of the License, or
 
9
   (at your option) any later version.
 
10
 
 
11
   This program is distributed in the hope that it will be useful,
 
12
   but WITHOUT ANY WARRANTY; without even the implied warranty of
 
13
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
14
   GNU General Public License for more details.
 
15
 
 
16
   You should have received a copy of the GNU General Public License
 
17
   along with this program; if not, write to the Free Software
 
18
   Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
 
19
 */
 
20
 
 
21
#include <stdio.h>
 
22
#include <unistd.h>
 
23
#include <string.h>
 
24
#include <sys/types.h>
 
25
#include <sys/stat.h>
 
26
#include <sys/ioctl.h>
 
27
#include <fcntl.h>
 
28
#include <linux/videodev.h>
 
29
 
 
30
/* All possible parameters used on v4l ioctls */
 
31
union v4l_parms {
 
32
#ifdef CONFIG_VIDEO_V4L1_COMPAT
 
33
        /* V4L1 structs */
 
34
        struct vbi_format v1;
 
35
#endif
 
36
 
 
37
        /* V4L2 structs */
 
38
        struct v4l2_format v2;
 
39
};
 
40
 
 
41
/* All defined ioctls */
 
42
int ioctls[] = {
 
43
#ifdef CONFIG_VIDEO_V4L1_COMPAT
 
44
        /* V4L ioctls */
 
45
 
 
46
        VIDIOCGVBIFMT,/* struct vbi_format */
 
47
#endif
 
48
 
 
49
        /* V4L2 ioctls */
 
50
 
 
51
        VIDIOC_G_FMT,/* struct v4l2_format */
 
52
};
 
53
#define S_IOCTLS sizeof(ioctls)/sizeof(ioctls[0])
 
54
 
 
55
/********************************************************************/
 
56
int main (void)
 
57
{
 
58
        int fd=0, ret=0;
 
59
        char *device="/dev/video0";
 
60
        union v4l_parms p;
 
61
 
 
62
        if ((fd = open(device, O_RDONLY)) < 0) {
 
63
                perror("Couldn't open video0");
 
64
                return(-1);
 
65
        }
 
66
 
 
67
 
 
68
#ifdef CONFIG_VIDEO_V4L1_COMPAT
 
69
        /* V4L1 call */
 
70
        memset(&p,0,sizeof(p));
 
71
        ret=ioctl(fd,VIDIOCGVBIFMT, (void *) &p);
 
72
 
 
73
        printf ("V4L1 call: ret=%i: sampling_rate=%d, samples_per_line=%d, "
 
74
                "sample_format=%d, start=%d/%d, count=%d/%d, flags=%d\n", ret,
 
75
                p.v1.sampling_rate,p.v1.samples_per_line, p.v1.sample_format,
 
76
                p.v1.start[0],p.v1.start[1],p.v1.count[0],p.v1.count[1],p.v1.flags);
 
77
#endif
 
78
 
 
79
 
 
80
        /* V4L2 call */
 
81
        memset(&p,0,sizeof(p));
 
82
        p.v2.type=V4L2_BUF_TYPE_VBI_CAPTURE;
 
83
        ret=ioctl(fd,VIDIOC_G_FMT, (void *) &p);
 
84
 
 
85
        printf ("V4L2 call: ret=%i: sampling_rate=%d, samples_per_line=%d, "
 
86
                "sample_format=%d, offset=%d, start=%d/%d, count=%d/%d\n", ret,
 
87
                p.v2.fmt.vbi.sampling_rate,p.v2.fmt.vbi.samples_per_line,
 
88
                p.v2.fmt.vbi.sample_format,p.v2.fmt.vbi.offset,
 
89
                p.v2.fmt.vbi.start[0],p.v2.fmt.vbi.start[1],
 
90
                p.v2.fmt.vbi.count[0],p.v2.fmt.vbi.count[1]);
 
91
 
 
92
        close (fd);
 
93
 
 
94
        return (0);
 
95
}