2
driver-test.c - This program tests V4L2 kernel drivers
4
Copyright (C) 2006 Mauro Carvalho Chehab <mchehab@infradead.org>
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.
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.
17
#include "../../utils/libv4l2util/v4l2_driver.h"
23
static int recebe_buffer (struct v4l2_buffer *v4l2_buf, struct v4l2_t_buf *buf)
31
struct v4l2_driver drv;
33
unsigned int count = 10, i;
36
if (v4l2_open ("/dev/video0", 1,&drv)<0) {
37
perror("open /dev/video0");
40
if (v4l2_enum_stds (&drv)<0) {
42
printf("Error! Driver is not reporting supported STD, frames/sec and number of lines!\n Trying to continue anyway...\n");
44
/* Tries all video standards */
45
for (cur=drv.stds;cur!=NULL;cur=cur->next) {
46
v4l2_std_id id=((struct v4l2_standard *)cur->curr)->id;
48
if (v4l2_setget_std (&drv, V4L2_SET_GET, &id))
53
if (v4l2_enum_input (&drv)<0) {
57
/* Tries all video inputs */
58
for (cur=drv.inputs;cur!=NULL;cur=cur->next) {
59
struct v4l2_input input;
60
input.index=((struct v4l2_input* )cur->curr)->index;
62
if (v4l2_setget_input (&drv, V4L2_SET_GET, &input))
66
if (v4l2_enum_fmt (&drv,V4L2_BUF_TYPE_VIDEO_CAPTURE)<0) {
67
perror("enum_fmt_cap");
70
/* Tries all formats */
71
for (cur=drv.fmt_caps;cur!=NULL;cur=cur->next) {
72
struct v4l2_format fmt;
73
memset (&fmt,0,sizeof(fmt));
75
uint32_t pixelformat=((struct v4l2_fmtdesc *)cur->curr)->pixelformat;
77
if (v4l2_gettryset_fmt_cap (&drv,V4L2_SET,&fmt, 640, 480,
78
pixelformat,V4L2_FIELD_ANY))
83
if (v4l2_get_parm (&drv)<0) {
88
v4l2_getset_freq (&drv,V4L2_GET, &freq);
91
v4l2_getset_freq (&drv,V4L2_SET, &freq);
93
freq=121250000; /* 121.250 MHz */
94
v4l2_getset_freq (&drv,V4L2_SET, &freq);
96
printf("Preparing for frames...\n");
100
v4l2_mmap_bufs(&drv, 2);
102
v4l2_start_streaming(&drv);
104
printf("Waiting for frames...\n");
106
for (i=0;i<count;i++) {
112
FD_SET (drv.fd, &fds);
118
r = select (drv.fd + 1, &fds, NULL, NULL, &tv);
128
fprintf (stderr, "select timeout\n");
132
if (v4l2_rcvbuf(&drv, recebe_buffer))
136
printf("stopping streaming\n");
137
v4l2_stop_streaming(&drv);
139
if (v4l2_close (&drv)<0) {