~ubuntu-branches/ubuntu/utopic/lebiniou/utopic

« back to all changes in this revision

Viewing changes to src/webcam_controls.c

  • Committer: Package Import Robot
  • Author(s): Olivier Girondel
  • Date: 2012-04-22 22:07:40 UTC
  • mfrom: (6.1.7 sid)
  • Revision ID: package-import@ubuntu.com-20120422220740-xncgwhc3g71nopnu
Tags: 3.18-1
* New upstream release 3.18.
* Support older libswscale.
* Add missing Build-Depends: libfreetype6-dev, libasound2-dev,
  libpulse-dev. (Closes: #669437)

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 *  Copyright 1994-2012 Olivier Girondel
 
3
 *
 
4
 *  This file is part of lebiniou.
 
5
 *
 
6
 *  lebiniou is free software: you can redistribute it and/or modify
 
7
 *  it under the terms of the GNU General Public License as published by
 
8
 *  the Free Software Foundation, either version 2 of the License, or
 
9
 *  (at your option) any later version.
 
10
 *
 
11
 *  lebiniou is distributed in the hope that it will be useful,
 
12
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 
13
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
14
 *  GNU General Public License for more details.
 
15
 *
 
16
 *  You should have received a copy of the GNU General Public License
 
17
 *  along with lebiniou. If not, see <http://www.gnu.org/licenses/>.
 
18
 */
 
19
 
 
20
#include "webcam.h"
 
21
 
 
22
static struct v4l2_queryctrl queryctrl;
 
23
static struct v4l2_querymenu querymenu;
 
24
 
 
25
 
 
26
static void
 
27
enumerate_menu(const webcam_t *cam)
 
28
{
 
29
  memset(&querymenu, 0, sizeof(querymenu));
 
30
  querymenu.id = queryctrl.id;
 
31
  
 
32
  for (querymenu.index = queryctrl.minimum;
 
33
       querymenu.index <= (unsigned)queryctrl.maximum;
 
34
       querymenu.index++)
 
35
    if (0 == ioctl(cam->fd, VIDIOC_QUERYMENU, &querymenu))
 
36
      printf ("[i]   - %s\n", querymenu.name);
 
37
    else
 
38
      xperror("VIDIOC_QUERYMENU");
 
39
}
 
40
 
 
41
 
 
42
static void
 
43
enumerate_base_cids(const webcam_t *cam)
 
44
{
 
45
  memset(&queryctrl, 0, sizeof(queryctrl));
 
46
  
 
47
  for (queryctrl.id = V4L2_CID_BASE;
 
48
       queryctrl.id < V4L2_CID_LASTP1;
 
49
       queryctrl.id++) {
 
50
    if (0 == ioctl(cam->fd, VIDIOC_QUERYCTRL, &queryctrl)) {
 
51
      if (queryctrl.flags & V4L2_CTRL_FLAG_DISABLED)
 
52
        continue;
 
53
      
 
54
      printf("[i] * %s\n", queryctrl.name);
 
55
      
 
56
      if (queryctrl.type == V4L2_CTRL_TYPE_MENU)
 
57
        enumerate_menu(cam);
 
58
    } else {
 
59
      if (errno == EINVAL)
 
60
        continue;
 
61
      else
 
62
        xperror("VIDIOC_QUERYCTRL");
 
63
    }
 
64
  }
 
65
}
 
66
 
 
67
 
 
68
static void
 
69
enumerate_private_cids(webcam_t *cam)
 
70
{
 
71
  memset(&queryctrl, 0, sizeof (queryctrl));
 
72
  
 
73
  for (queryctrl.id = V4L2_CID_PRIVATE_BASE;
 
74
       ;
 
75
       queryctrl.id++) {
 
76
    if (0 == ioctl(cam->fd, VIDIOC_QUERYCTRL, &queryctrl)) {
 
77
      if (queryctrl.flags & V4L2_CTRL_FLAG_DISABLED)
 
78
        continue;
 
79
      
 
80
      printf ("[i] * %s\n", queryctrl.name);
 
81
      
 
82
      if (queryctrl.type == V4L2_CTRL_TYPE_MENU)
 
83
        enumerate_menu(cam);
 
84
    } else {
 
85
      if (errno == EINVAL)
 
86
        break;
 
87
      else
 
88
        xperror("VIDIOC_QUERYCTRL");
 
89
    }
 
90
  }
 
91
}
 
92
 
 
93
 
 
94
void
 
95
enumerate_cids(webcam_t *cam)
 
96
{
 
97
  printf("[i] Webcam %d: base controls\n", cam->cam_no);
 
98
  enumerate_base_cids(cam);
 
99
  printf("[i] Webcam %d: private controls\n", cam->cam_no);
 
100
  enumerate_private_cids(cam);
 
101
}
 
102
 
 
103
 
 
104
static void
 
105
set_ctrl(int fd, const int ctrl, const int value)
 
106
{
 
107
  struct v4l2_queryctrl queryctrl;
 
108
  struct v4l2_control control;
 
109
 
 
110
  memset(&queryctrl, 0, sizeof(queryctrl));
 
111
  queryctrl.id = ctrl;
 
112
 
 
113
  if (-1 == xioctl(fd, VIDIOC_QUERYCTRL, &queryctrl)) {
 
114
    if (errno != EINVAL) {
 
115
      xerror("VIDIOC_QUERYCTRL\n");
 
116
    } else {
 
117
      printf("V4L2_CID_BRIGHTNESS is not supported\n");
 
118
    }
 
119
  } else if (queryctrl.flags & V4L2_CTRL_FLAG_DISABLED) {
 
120
    printf("%s is not supported\n",
 
121
           (ctrl == V4L2_CID_VFLIP) ? "V4L2_CID_VFLIP" : "V4L2_CID_HFLIP");
 
122
  } else {
 
123
    memset(&control, 0, sizeof(control));
 
124
    control.id = ctrl;
 
125
    control.value = queryctrl.default_value;
 
126
 
 
127
    if (-1 == xioctl(fd, VIDIOC_S_CTRL, &control)) {
 
128
      xerror("VIDIOC_S_CTRL\n");
 
129
    }
 
130
  }
 
131
 
 
132
  printf("[i] %s: default= %d",
 
133
         ((ctrl == V4L2_CID_VFLIP) ? "V4L2_CID_VFLIP" : "V4L2_CID_HFLIP"),
 
134
         control.value);;
 
135
 
 
136
  memset(&control, 0, sizeof (control));
 
137
  control.id = ctrl;
 
138
 
 
139
  if (0 == xioctl(fd, VIDIOC_G_CTRL, &control)) {
 
140
    control.value = value;
 
141
 
 
142
    if (-1 == xioctl(fd, VIDIOC_S_CTRL, &control)
 
143
        && errno != ERANGE) {
 
144
      xerror("VIDIOC_S_CTRL\n");
 
145
    } else
 
146
      printf(" set: %d\n", value);
 
147
    /* Ignore if V4L2_CID_CONTRAST is unsupported */
 
148
  } else if (errno != EINVAL) {
 
149
    xerror("VIDIOC_G_CTRL\n");
 
150
  }
 
151
}
 
152
 
 
153
 
 
154
void
 
155
cam_hflip(int fd, const int value)
 
156
{
 
157
  set_ctrl(fd, V4L2_CID_HFLIP, value);
 
158
}
 
159
 
 
160
 
 
161
void
 
162
cam_vflip(int fd, const int value)
 
163
{
 
164
  set_ctrl(fd, V4L2_CID_VFLIP, value);
 
165
}
 
166
 
 
167
 
 
168
int
 
169
list_inputs(const webcam_t *cam)
 
170
{
 
171
  struct v4l2_input inputs;
 
172
  int index = 0;
 
173
  int fd = cam->fd;
 
174
 
 
175
  inputs.index = 0;
 
176
  while (ioctl(fd, VIDIOC_ENUMINPUT, &inputs) == 0) {
 
177
    printf("[i] Webcam %d: input #%d\n", cam->cam_no, index);
 
178
    printf("[i] * Name: %s\n", inputs.name);
 
179
 
 
180
    printf("[i] * Type: ");
 
181
    if (inputs.type == V4L2_INPUT_TYPE_CAMERA)
 
182
      printf("camera\n");
 
183
    else if (inputs.type == V4L2_INPUT_TYPE_TUNER)
 
184
      printf("tuner\n");
 
185
    else
 
186
      assert(0);
 
187
 
 
188
    printf("[i] * Video standard: %d\n", (int)inputs.std);
 
189
    index++;
 
190
    inputs.index = index;
 
191
  }
 
192
 
 
193
  return index;
 
194
}