• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2 #             (C) 2008 Hans de Goede <hdegoede@redhat.com>
3 
4 # This program is free software; you can redistribute it and/or modify
5 # it under the terms of the GNU Lesser General Public License as published by
6 # the Free Software Foundation; either version 2.1 of the License, or
7 # (at your option) any later version.
8 #
9 # This program is distributed in the hope that it will be useful,
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12 # GNU Lesser General Public License for more details.
13 #
14 # You should have received a copy of the GNU Lesser General Public License
15 # along with this program; if not, write to the Free Software
16 # Foundation, Inc., 51 Franklin Street, Suite 500, Boston, MA  02110-1335  USA
17  */
18 
19 #include <stdio.h>
20 #include <stdlib.h>
21 #include "../libv4lconvert/libv4lsyscall-priv.h"
22 #include "libv4l1-videodev.h"
23 #include "libv4l1-priv.h"
24 
25 #define ARRAY_SIZE(x) (sizeof(x) / sizeof((x)[0]))
26 
27 FILE *v4l1_log_file = NULL;
28 
29 static const char *v4l1_ioctls[] = {
30 	[_IOC_NR(VIDIOCGCAP)]       = "VIDIOCGCAP",
31 	[_IOC_NR(VIDIOCGCHAN)]      = "VIDIOCGCHAN",
32 	[_IOC_NR(VIDIOCSCHAN)]      = "VIDIOCSCHAN",
33 	[_IOC_NR(VIDIOCGTUNER)]     = "VIDIOCGTUNER",
34 	[_IOC_NR(VIDIOCSTUNER)]     = "VIDIOCSTUNER",
35 	[_IOC_NR(VIDIOCGPICT)]      = "VIDIOCGPICT",
36 	[_IOC_NR(VIDIOCSPICT)]      = "VIDIOCSPICT",
37 	[_IOC_NR(VIDIOCCAPTURE)]    = "VIDIOCCAPTURE",
38 	[_IOC_NR(VIDIOCGWIN)]       = "VIDIOCGWIN",
39 	[_IOC_NR(VIDIOCSWIN)]       = "VIDIOCSWIN",
40 	[_IOC_NR(VIDIOCGFBUF)]      = "VIDIOCGFBUF",
41 	[_IOC_NR(VIDIOCSFBUF)]      = "VIDIOCSFBUF",
42 	[_IOC_NR(VIDIOCGFREQ)]      = "VIDIOCGFREQ",
43 	[_IOC_NR(VIDIOCSFREQ)]      = "VIDIOCSFREQ",
44 	[_IOC_NR(VIDIOCGAUDIO)]     = "VIDIOCGAUDIO",
45 	[_IOC_NR(VIDIOCSAUDIO)]     = "VIDIOCSAUDIO",
46 	[_IOC_NR(VIDIOCSYNC)]       = "VIDIOCSYNC",
47 	[_IOC_NR(VIDIOCMCAPTURE)]   = "VIDIOCMCAPTURE",
48 	[_IOC_NR(VIDIOCGMBUF)]      = "VIDIOCGMBUF",
49 	[_IOC_NR(VIDIOCGVBIFMT)]    = "VIDIOCGVBIFMT",
50 	[_IOC_NR(VIDIOCSVBIFMT)]    = "VIDIOCSVBIFMT",
51 };
52 
v4l1_log_ioctl(unsigned long int request,void * arg,int result)53 void v4l1_log_ioctl(unsigned long int request, void *arg, int result)
54 {
55 	const char *ioctl_str = "unknown";
56 	char buf[40];
57 
58 	if (!v4l1_log_file)
59 		return;
60 
61 	/* Don't log v4l2 ioctl's as unknown we pass them to libv4l2 which will
62 	   log them for us */
63 	if (_IOC_TYPE(request) == 'V')
64 		return;
65 
66 	if (_IOC_TYPE(request) == 'v' && _IOC_NR(request) < ARRAY_SIZE(v4l1_ioctls))
67 		ioctl_str = v4l1_ioctls[_IOC_NR(request)];
68 	else {
69 		snprintf(buf, sizeof(buf), "unknown request: %c %d\n",
70 				(int)_IOC_TYPE(request), (int)_IOC_NR(request));
71 		ioctl_str = buf;
72 	}
73 
74 	fprintf(v4l1_log_file, "request == %s\n", ioctl_str);
75 
76 	switch (request) {
77 	case VIDIOCGCAP:
78 		fprintf(v4l1_log_file, "name      %s\n", ((struct video_capability *)arg)->name);
79 		fprintf(v4l1_log_file, "type      %d\n", ((struct video_capability *)arg)->type);
80 		fprintf(v4l1_log_file, "channels  %d\n", ((struct video_capability *)arg)->channels);
81 		fprintf(v4l1_log_file, "audios    %d\n", ((struct video_capability *)arg)->audios);
82 		fprintf(v4l1_log_file, "maxwidth  %d\n", ((struct video_capability *)arg)->maxwidth);
83 		fprintf(v4l1_log_file, "maxheight %d\n", ((struct video_capability *)arg)->maxheight);
84 		fprintf(v4l1_log_file, "minwidth  %d\n", ((struct video_capability *)arg)->minwidth);
85 		fprintf(v4l1_log_file, "minheight %d\n", ((struct video_capability *)arg)->minheight);
86 		break;
87 	case VIDIOCGWIN:
88 	case VIDIOCSWIN:
89 		fprintf(v4l1_log_file, "width     %u\n",
90 				((struct video_window *)arg)->width);
91 		fprintf(v4l1_log_file, "height    %u\n",
92 				((struct video_window *)arg)->height);
93 		break;
94 
95 	case VIDIOCGCHAN:
96 	case VIDIOCSCHAN:
97 		fprintf(v4l1_log_file, "channel   %d\n", ((struct video_channel *)arg)->channel);
98 		fprintf(v4l1_log_file, "name      %s\n", ((struct video_channel *)arg)->name);
99 		break;
100 
101 	case VIDIOCGPICT:
102 	case VIDIOCSPICT:
103 		fprintf(v4l1_log_file, "brightness %d\n", ((int)((struct video_picture *)arg)->brightness));
104 		fprintf(v4l1_log_file, "hue       %d\n", ((int)((struct video_picture *)arg)->hue));
105 		fprintf(v4l1_log_file, "colour    %d\n", ((int)((struct video_picture *)arg)->colour));
106 		fprintf(v4l1_log_file, "contrast  %d\n", ((int)((struct video_picture *)arg)->contrast));
107 		fprintf(v4l1_log_file, "whiteness %d\n", ((int)((struct video_picture *)arg)->whiteness));
108 		fprintf(v4l1_log_file, "depth     %d\n", ((int)((struct video_picture *)arg)->depth));
109 		fprintf(v4l1_log_file, "palette   %d\n", ((int)((struct video_picture *)arg)->palette));
110 		break;
111 
112 	case VIDIOCCAPTURE:
113 		fprintf(v4l1_log_file, "on/off?   %d\n", *((int *)arg));
114 		break;
115 
116 	case VIDIOCSYNC:
117 		fprintf(v4l1_log_file, "sync      %d\n", *((int *)arg));
118 		break;
119 
120 	case VIDIOCMCAPTURE:
121 		fprintf(v4l1_log_file, "frame     %u\n", ((struct video_mmap *)arg)->frame);
122 		fprintf(v4l1_log_file, "width     %d\n", ((struct video_mmap *)arg)->width);
123 		fprintf(v4l1_log_file, "height    %d\n", ((struct video_mmap *)arg)->height);
124 		fprintf(v4l1_log_file, "format    %u\n", ((struct video_mmap *)arg)->format);
125 		break;
126 
127 	case VIDIOCGMBUF:
128 		fprintf(v4l1_log_file, "size      %d\n", ((struct video_mbuf *)arg)->size);
129 		fprintf(v4l1_log_file, "frames    %d\n", ((struct video_mbuf *)arg)->frames);
130 		break;
131 	}
132 	fprintf(v4l1_log_file, "result == %d\n", result);
133 	fflush(v4l1_log_file);
134 }
135