• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * v4l-test: Test environment for Video For Linux Two API
3  *
4  *  5 Jul 2009  0.1  First release
5  *
6  * Written by M�rton N�meth <nm127@freemail.hu>
7  * Released under GPL
8  */
9 
10 #include <stdio.h>
11 #include <sys/types.h>
12 #include <sys/stat.h>
13 #include <fcntl.h>
14 #include <unistd.h>
15 #include <sys/ioctl.h>
16 #include <errno.h>
17 #include <string.h>
18 
19 #include <linux/videodev2.h>
20 #include <linux/errno.h>
21 
22 #include <CUnit/CUnit.h>
23 
24 #include "v4l2_test.h"
25 #include "dev_video.h"
26 #include "v4l2_show.h"
27 #include "v4l2_foreach.h"
28 
foreach_input(V4L2InputTestFunc pFunc)29 void foreach_input(V4L2InputTestFunc pFunc)
30 {
31 	__u32 input_index_orig;
32 	struct v4l2_input input;
33 	int ret_input_get, errno_input_get;
34 	int ret_input_enum, errno_input_enum;
35 	int ret_input_set, errno_input_set;
36 	__u32 i;
37 	int f;
38 	char not_yet_called = 1;
39 
40 	f = get_video_fd();
41 
42 	memset(&input_index_orig, 0xff, sizeof(input_index_orig));
43 	ret_input_get = ioctl(f, VIDIOC_G_INPUT, &input_index_orig);
44 	errno_input_get = errno;
45 	dprintf
46 	    ("\t%s:%u: VIDIOC_G_INPUT, ret_input_get=%i, errno_input_get=%i, input_index_orig=0x%X\n",
47 	     __FILE__, __LINE__, ret_input_get, errno_input_get,
48 	     input_index_orig);
49 
50 	i = 0;
51 	do {
52 		memset(&input, 0xff, sizeof(input));
53 		input.index = i;
54 		ret_input_enum = ioctl(f, VIDIOC_ENUMINPUT, &input);
55 		errno_input_enum = errno;
56 
57 		dprintf
58 		    ("\t%s:%u: VIDIOC_ENUMINPUT: i=%u, ret_input_enum=%i, errno_input_enum=%i\n",
59 		     __FILE__, __LINE__, i, ret_input_enum, errno_input_enum);
60 
61 		if (ret_input_enum == 0) {
62 			show_v4l2_input(&input);
63 			ret_input_set = ioctl(f, VIDIOC_S_INPUT, &input.index);
64 			errno_input_set = errno;
65 			dprintf
66 			    ("\t%s:%u: VIDIOC_S_INPUT: input.index=0x%X, ret_input_set=%i, errno_input_set=%i\n",
67 			     __FILE__, __LINE__, input.index, ret_input_set,
68 			     errno_input_set);
69 			CU_ASSERT_EQUAL(ret_input_set, 0);
70 		}
71 
72 		/* Ensure that pFunc() is called at least once even if
73 		 * everything else returned error before.
74 		 */
75 		if (not_yet_called || ret_input_enum == 0) {
76 			pFunc(ret_input_enum, errno_input_enum, &input);
77 			not_yet_called = 0;
78 		}
79 
80 		i++;
81 	} while (ret_input_enum == 0 && i != 0);
82 
83 	if (ret_input_get == 0) {
84 		/* Setting the original input_id should not fail */
85 		ret_input_set = ioctl(f, VIDIOC_S_INPUT, &input_index_orig);
86 		errno_input_set = errno;
87 		CU_ASSERT_EQUAL(ret_input_set, 0);
88 	}
89 }
90