• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * v4l-test: Test environment for Video For Linux Two API
3  *
4  * 17 Jul 2009  0.3  show_v4l2_frmsizeenum() added
5  *  5 Jul 2009  0.2  show_v4l2_input() introduced
6  *  7 May 2009  0.1  First release
7  *
8  * Written by M�rton N�meth <nm127@freemail.hu>
9  * Released under GPL
10  */
11 
12 #include <stdio.h>
13 #include <sys/types.h>
14 #include <sys/stat.h>
15 #include <fcntl.h>
16 #include <unistd.h>
17 #include <sys/ioctl.h>
18 #include <errno.h>
19 #include <string.h>
20 
21 #include <linux/videodev2.h>
22 #include <linux/errno.h>
23 
24 #include <CUnit/CUnit.h>
25 
26 #include "v4l2_test.h"
27 #include "dev_video.h"
28 #include "video_limits.h"
29 
30 #include "test_VIDIOC_REQBUFS.h"
31 
show_v4l2_requestbuffers(struct v4l2_requestbuffers * reqbuf)32 void show_v4l2_requestbuffers(struct v4l2_requestbuffers *reqbuf)
33 {
34 	dprintf("\treqbuf = { "
35 		".count=%u, "
36 		".type=%i, "
37 		".memory=%i, "
38 		".reserved = { 0x%X, 0x%X } "
39 		"}\n",
40 		reqbuf->count,
41 		reqbuf->type,
42 		reqbuf->memory, reqbuf->reserved[0], reqbuf->reserved[1]
43 	    );
44 }
45 
show_v4l2_buffer(struct v4l2_buffer * buf)46 void show_v4l2_buffer(struct v4l2_buffer *buf)
47 {
48 	unsigned int i;
49 
50 	dprintf("\tbuf = { "
51 		".index=%u, "
52 		".type=%i, "
53 		".bytesused=%u, "
54 		".flags=0x%x, "
55 		".field=%i, "
56 		".timestamp = { tv_sec=%lu, tv_usec=%lu }, "
57 		".timecode = { "
58 		".type=%u, "
59 		".flags=0x%x, "
60 		".frames=%u, "
61 		".seconds=%u, "
62 		".minutes=%u, "
63 		".hours=%u, "
64 		".userbits = { 0x%x, 0x%x, 0x%x, 0x%x } "
65 		" }, "
66 		".sequence=%u, "
67 		".memory=%i, ",
68 		buf->index,
69 		buf->type,
70 		buf->bytesused,
71 		buf->flags,
72 		buf->field,
73 		buf->timestamp.tv_sec,
74 		buf->timestamp.tv_usec,
75 		buf->timecode.type,
76 		buf->timecode.flags,
77 		buf->timecode.frames,
78 		buf->timecode.seconds,
79 		buf->timecode.minutes,
80 		buf->timecode.hours,
81 		buf->timecode.userbits[0],
82 		buf->timecode.userbits[1],
83 		buf->timecode.userbits[2],
84 		buf->timecode.userbits[3], buf->sequence, buf->memory);
85 
86 	switch (buf->memory) {
87 	case V4L2_MEMORY_USERPTR:
88 		dprintf(".m.userptr=0x%lx, ", buf->m.userptr);
89 		for (i = sizeof(buf->m.userptr); i < sizeof(buf->m); i++) {
90 			dprintf("((__u8*)&.m)[%u]=0x%x, ",
91 				i, ((__u8 *) & buf->m)[i]);
92 		}
93 		break;
94 	case V4L2_MEMORY_MMAP:
95 	case V4L2_MEMORY_OVERLAY:
96 	default:
97 		dprintf(".m.offset=%u, ", buf->m.offset);
98 		for (i = sizeof(buf->m.offset); i < sizeof(buf->m); i++) {
99 			dprintf("((__u8*)&.m)[%u]=0x%x, ",
100 				i, ((__u8 *) & buf->m)[i]);
101 		}
102 	}
103 
104 	dprintf(".length=%u, "
105 		".input=%u, "
106 		".reserved=0x%x "
107 		"}\n", buf->length, buf->input, buf->reserved);
108 
109 }
110 
show_v4l2_input(struct v4l2_input * input)111 void show_v4l2_input(struct v4l2_input *input)
112 {
113 	dprintf("\tinput = {.index=%u, .name=\"%s\", "
114 		".type=0x%X, .audioset=0x%X, .tuner=0x%X, "
115 		".std=%llX, "
116 		".status=0x%X, "
117 		".reserved[]={ 0x%X, 0x%X, 0x%X, 0x%X } }\n",
118 		input->index,
119 		input->name,
120 		input->type,
121 		input->audioset,
122 		input->tuner,
123 		input->std,
124 		input->status,
125 		input->reserved[0],
126 		input->reserved[1], input->reserved[2], input->reserved[3]
127 	    );
128 }
129 
show_v4l2_frmsizeenum(struct v4l2_frmsizeenum * framesize)130 void show_v4l2_frmsizeenum(struct v4l2_frmsizeenum *framesize)
131 {
132 	dprintf("\tframesize = { .index=%u, "
133 		".pixel_format=0x%x, "
134 		".type=%u, ",
135 		framesize->index, framesize->pixel_format, framesize->type);
136 
137 	switch (framesize->type) {
138 	case V4L2_FRMSIZE_TYPE_DISCRETE:
139 		dprintf(".discrete = { .width=%u, heigth=%u }, ",
140 			framesize->discrete.width, framesize->discrete.height);
141 		break;
142 	case V4L2_FRMSIZE_TYPE_CONTINUOUS:
143 	case V4L2_FRMSIZE_TYPE_STEPWISE:
144 		dprintf(".stepwise = { .min_width=%u, "
145 			".max_width=%u, "
146 			".step_width=%u, "
147 			".min_height=%u, "
148 			".max_height=%u, "
149 			".step_height=%u }, ",
150 			framesize->stepwise.min_width,
151 			framesize->stepwise.max_width,
152 			framesize->stepwise.step_width,
153 			framesize->stepwise.min_height,
154 			framesize->stepwise.max_height,
155 			framesize->stepwise.step_height);
156 		break;
157 	default:
158 		;
159 	}
160 
161 	dprintf(".reserved = { 0x%x, 0x%x } }\n",
162 		framesize->reserved[0], framesize->reserved[1]
163 	    );
164 
165 }
166