~ubuntu-branches/ubuntu/precise/v4l-utils/precise

« back to all changes in this revision

Viewing changes to lib/libv4l1/log.c

  • Committer: Bazaar Package Importer
  • Author(s): Gregor Jasny
  • Date: 2010-02-28 19:44:15 UTC
  • Revision ID: james.westby@ubuntu.com-20100228194415-067hdj8rvawj91zw
Tags: upstream-0.7.90
ImportĀ upstreamĀ versionĀ 0.7.90

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
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., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 
17
*/
 
18
 
 
19
#include <stdio.h>
 
20
#include <stdlib.h>
 
21
#include "../libv4lconvert/libv4lsyscall-priv.h"
 
22
#include <linux/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(VIDIOCKEY)]        = "VIDIOCKEY",
 
43
        [_IOC_NR(VIDIOCGFREQ)]      = "VIDIOCGFREQ",
 
44
        [_IOC_NR(VIDIOCSFREQ)]      = "VIDIOCSFREQ",
 
45
        [_IOC_NR(VIDIOCGAUDIO)]     = "VIDIOCGAUDIO",
 
46
        [_IOC_NR(VIDIOCSAUDIO)]     = "VIDIOCSAUDIO",
 
47
        [_IOC_NR(VIDIOCSYNC)]       = "VIDIOCSYNC",
 
48
        [_IOC_NR(VIDIOCMCAPTURE)]   = "VIDIOCMCAPTURE",
 
49
        [_IOC_NR(VIDIOCGMBUF)]      = "VIDIOCGMBUF",
 
50
        [_IOC_NR(VIDIOCGUNIT)]      = "VIDIOCGUNIT",
 
51
        [_IOC_NR(VIDIOCGCAPTURE)]   = "VIDIOCGCAPTURE",
 
52
        [_IOC_NR(VIDIOCSCAPTURE)]   = "VIDIOCSCAPTURE",
 
53
        [_IOC_NR(VIDIOCSPLAYMODE)]  = "VIDIOCSPLAYMODE",
 
54
        [_IOC_NR(VIDIOCSWRITEMODE)] = "VIDIOCSWRITEMODE",
 
55
        [_IOC_NR(VIDIOCGPLAYINFO)]  = "VIDIOCGPLAYINFO",
 
56
        [_IOC_NR(VIDIOCSMICROCODE)] = "VIDIOCSMICROCODE",
 
57
        [_IOC_NR(VIDIOCGVBIFMT)]    = "VIDIOCGVBIFMT",
 
58
        [_IOC_NR(VIDIOCSVBIFMT)]    = "VIDIOCSVBIFMT",
 
59
};
 
60
 
 
61
void v4l1_log_ioctl(unsigned long int request, void *arg, int result)
 
62
{
 
63
  const char *ioctl_str = "unknown";
 
64
  char buf[40];
 
65
 
 
66
  if (!v4l1_log_file)
 
67
    return;
 
68
 
 
69
  /* Don't log v4l2 ioctl's as unknown we pass them to libv4l2 which will
 
70
     log them for us */
 
71
  if (_IOC_TYPE(request) == 'V')
 
72
    return;
 
73
 
 
74
  if (_IOC_TYPE(request) == 'v' && _IOC_NR(request) < ARRAY_SIZE(v4l1_ioctls))
 
75
    ioctl_str = v4l1_ioctls[_IOC_NR(request)];
 
76
  else {
 
77
    snprintf(buf, sizeof(buf), "unknown request: %c %d\n",
 
78
      (int)_IOC_TYPE(request), (int)_IOC_NR(request));
 
79
    ioctl_str = buf;
 
80
  }
 
81
 
 
82
  fprintf(v4l1_log_file, "request == %s\n", ioctl_str);
 
83
 
 
84
  switch(request)
 
85
  {
 
86
          case VIDIOCGCAP:fprintf(v4l1_log_file,"name   %s\n",( (struct video_capability*)arg)->name            );
 
87
                          fprintf(v4l1_log_file,"type   %d\n",( (struct video_capability*)arg)->type            );
 
88
                          fprintf(v4l1_log_file,"channels       %d\n",( (struct video_capability*)arg)->channels        );
 
89
                          fprintf(v4l1_log_file,"audios         %d\n",( (struct video_capability*)arg)->audios          );
 
90
                          fprintf(v4l1_log_file,"maxwidth       %d\n",( (struct video_capability*)arg)->maxwidth        );
 
91
                          fprintf(v4l1_log_file,"maxheight      %d\n",( (struct video_capability*)arg)->maxheight       );
 
92
                          fprintf(v4l1_log_file,"minwidth       %d\n",( (struct video_capability*)arg)->minwidth        );
 
93
                          fprintf(v4l1_log_file,"minheight      %d\n",( (struct video_capability*)arg)->minheight       );
 
94
                          break;
 
95
    case VIDIOCGWIN:
 
96
    case VIDIOCSWIN:
 
97
      fprintf(v4l1_log_file,"width\t%u\n",
 
98
        ((struct video_window *)arg)->width);
 
99
      fprintf(v4l1_log_file,"height\t%u\n",
 
100
        ((struct video_window *)arg)->height);
 
101
      break;
 
102
 
 
103
          case VIDIOCGCHAN:
 
104
          case VIDIOCSCHAN:
 
105
                          fprintf(v4l1_log_file,"channel        %d\n",( (struct video_channel*)arg)->channel            );
 
106
                          fprintf(v4l1_log_file,"name   %s\n",( (struct video_channel*)arg)->name               );
 
107
                          break;
 
108
 
 
109
          case VIDIOCGPICT:
 
110
          case VIDIOCSPICT:
 
111
                          fprintf(v4l1_log_file,"brightness     %d\n",( (int)((struct video_picture*)arg)->brightness)  );
 
112
                          fprintf(v4l1_log_file,"hue    %d\n",( (int)((struct video_picture*)arg)->hue)         );
 
113
                          fprintf(v4l1_log_file,"colour         %d\n",( (int)((struct video_picture*)arg)->colour)      );
 
114
                          fprintf(v4l1_log_file,"contrast       %d\n",( (int)((struct video_picture*)arg)->contrast)    );
 
115
                          fprintf(v4l1_log_file,"whiteness      %d\n",( (int)((struct video_picture*)arg)->whiteness)   );
 
116
                          fprintf(v4l1_log_file,"depth  %d\n",( (int)((struct video_picture*)arg)->depth)       );
 
117
                          fprintf(v4l1_log_file,"palette        %d\n",( (int)((struct video_picture*)arg)->palette)     );
 
118
                          break;
 
119
 
 
120
          case VIDIOCCAPTURE: fprintf(v4l1_log_file,"on/off?    %d\n",  *((int *)arg)                                   );
 
121
                          break;
 
122
 
 
123
          case VIDIOCSYNC: fprintf(v4l1_log_file,"sync  %d\n",  *((int *)arg)                                   );
 
124
                          break;
 
125
 
 
126
          case VIDIOCMCAPTURE:
 
127
                          fprintf(v4l1_log_file,"frame  %u\n",( (struct video_mmap*)arg)->frame                 );
 
128
                          fprintf(v4l1_log_file,"width  %d\n",( (struct video_mmap*)arg)->width                 );
 
129
                          fprintf(v4l1_log_file,"height         %d\n",( (struct video_mmap*)arg)->height                );
 
130
                          fprintf(v4l1_log_file,"format         %u\n",( (struct video_mmap*)arg)->format                );
 
131
                          break;
 
132
 
 
133
          case VIDIOCGMBUF:
 
134
                          fprintf(v4l1_log_file,"size   %d\n",( (struct video_mbuf*)arg)->size                  );
 
135
                          fprintf(v4l1_log_file,"frames         %d\n",( (struct video_mbuf*)arg)->frames                );
 
136
                          break;
 
137
  }
 
138
  fprintf(v4l1_log_file, "result == %d\n", result);
 
139
  fflush(v4l1_log_file);
 
140
}