1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
|
/*
driver-test.c - This program tests V4L2 kernel drivers
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.
*/
#include "../lib/v4l2_driver.h"
#include <stdio.h>
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 (&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");
}
if (v4l2_close (&drv)<0) {
perror("close");
return -1;
}
return 0;
}
|