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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
|
/*
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>
#include <string.h>
#include <unistd.h>
#include <errno.h>
int recebe_buffer (struct v4l2_buffer *v4l2_buf, struct v4l2_t_buf *buf)
{
return 0;
}
int main(void)
{
struct v4l2_driver drv;
struct drv_list *cur;
unsigned int count = 10, i;
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;
memset (&fmt,0,sizeof(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");
}
v4l2_mmap_bufs(&drv, 2);
v4l2_start_streaming(&drv);
printf("Waiting for frames...\n");
for (i=0;i<count;i++) {
fd_set fds;
struct timeval tv;
int r;
FD_ZERO (&fds);
FD_SET (drv.fd, &fds);
/* Timeout. */
tv.tv_sec = 2;
tv.tv_usec = 0;
r = select (drv.fd + 1, &fds, NULL, NULL, &tv);
if (-1 == r) {
if (EINTR == errno)
continue;
perror ("select");
return errno;
}
if (0 == r) {
fprintf (stderr, "select timeout\n");
return errno;
}
if (v4l2_rcvbuf(&drv, recebe_buffer))
break;
}
printf("stopping streaming\n");
v4l2_stop_streaming(&drv);
if (v4l2_close (&drv)<0) {
perror("close");
return -1;
}
return 0;
}
|