Webcam Library Reference Documentation  Logitech logo
libwebcam.h
Go to the documentation of this file.
1 
8 /*
9  * Copyright (c) 2006-2008 Logitech.
10  *
11  * This file is part of libwebcam.
12  *
13  * libwebcam is free software: you can redistribute it and/or modify
14  * it under the terms of the GNU Lesser General Public License as published
15  * by the Free Software Foundation, either version 3 of the License, or
16  * (at your option) any later version.
17  *
18  * libwebcam is distributed in the hope that it will be useful,
19  * but WITHOUT ANY WARRANTY; without even the implied warranty of
20  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21  * GNU Lesser General Public License for more details.
22  *
23  * You should have received a copy of the GNU Lesser General Public License
24  * along with libwebcam. If not, see <http://www.gnu.org/licenses/>.
25  */
26 
27 #ifndef C_LIBWEBCAM_H
28 #define C_LIBWEBCAM_H
29 
30 
31 #include <assert.h>
32 
33 
34 /*
35  * Features
36  */
37 
39 #define USE_UVCVIDEO
40 #ifdef USE_UVCVIDEO
41 
44  #define ENABLE_UVCVIDEO_DYNCTRL
45  #ifdef ENABLE_UVCVIDEO_DYNCTRL
46 
49  #define USE_LOGITECH_DYNCTRL
50 
54  //#define ENABLE_RAW_CONTROLS
55 
56  #endif
57 
58 #endif
59 
60 
61 /*
62  * Constants
63  */
64 
66 #define ENABLE_V4L2_ADVANCED_CONTROL_ENUMERATION
67 
71 #define DYNCTRL_IGNORE_EEXIST_AFTER_PASS1
72 
74 #define MAX_HANDLES 32
75 
77 #define DISABLE_LOCKING 1
78 
79 #define DEBUG_LOCKING 1
80 
82 #define UNKNOWN_CONTROL_NAME "Unknown control"
83 
84 
85 #define CONTROL_IO_ERROR_RETRIES 2
86 
88 #define GUID_SIZE 16
89 
90 
91 
92 /*
93  * Macros
94  */
95 
97 #define GET_HANDLE(handle) (handle_list.handles[(handle)])
98 
99 #define HANDLE_OPEN(handle) ((handle) < MAX_HANDLES && GET_HANDLE(handle).open)
100 
101 #define HANDLE_VALID(handle) (HANDLE_OPEN(handle) && GET_HANDLE(handle).device)
102 
105 #define V4L2_MENU_CTRL_MAX_NAME_SIZE sizeof(((struct v4l2_querymenu *)NULL)->name)
106 
108 #define MAKE_FOURCC(c1,c2,c3,c4) \
109  (unsigned int)((long)c1 | (long)c2 << 8 | (long)c3 << 16 | (long)c4 << 24)
110 
112 #define GUID_FORMAT "%02x%02x%02x%02x-%02x%02x-%02x%02x-%02x%02x-%02x%02x%02x%02x%02x%02x"
113 
114 #define GUID_ARGS(guid) \
115  (guid)[3], (guid)[2], (guid)[1], (guid)[0], \
116  (guid)[5], (guid)[4], \
117  (guid)[7], (guid)[6], \
118  (guid)[8], (guid)[9], \
119  (guid)[10], (guid)[11], (guid)[12], \
120  (guid)[13], (guid)[14], (guid)[15]
121 
122 
123 
124 /*
125  * Structures
126  */
127 
131 typedef struct _Control {
137  struct _Control * next;
138 
139 } Control;
140 
144 typedef struct _ControlList {
148  pthread_mutex_t mutex;
150  int count;
151 
152 } ControlList;
153 
157 typedef struct _Device {
161  char v4l2_name[NAME_MAX];
163  int handles;
168  int valid;
170  struct _Device * next;
171 
172 } Device;
173 
177 typedef struct _DeviceList {
181  pthread_mutex_t mutex;
183  int count;
184 
185 } DeviceList;
186 
198 typedef struct _Handle {
202  int open;
205 
206 } Handle;
207 
211 typedef struct _HandleList {
215  pthread_mutex_t mutex;
219 
220 } HandleList;
221 
222 
223 
224 /*
225  * Globals
226  */
227 
228 extern int initialized;
229 extern HandleList handle_list;
230 
231 extern void print_error (char *format, ...);
232 extern int open_v4l2_device(char *device_name);
233 
234 
235 
236 /*
237  * Helper functions
238  */
239 
250 static inline CResult lock_mutex (pthread_mutex_t *mutex)
251 {
252 #ifndef DISABLE_LOCKING
253 #ifdef DEBUG_LOCKING
254  fprintf(stderr, "Acquiring mutex 0x%08x ...\n", (unsigned int)mutex);
255 #endif
256  int ret = pthread_mutex_lock(mutex);
257 #ifdef DEBUG_LOCKING
258  fprintf(stderr, "Acquisition of mutex 0x%08x %s.\n", (unsigned int)mutex,
259  ret ? "failed" : "successful");
260 #endif
261  assert(ret == 0);
262  return ret ? C_SYNC_ERROR : C_SUCCESS;
263 #else
264  return C_SUCCESS;
265 #endif
266 }
267 
268 
279 static inline void unlock_mutex (pthread_mutex_t *mutex)
280 {
281 #ifndef DISABLE_LOCKING
282 #ifdef DEBUG_LOCKING
283  fprintf(stderr, "Releasing mutex 0x%08x ...\n", (unsigned int)mutex);
284 #endif
285  int ret = pthread_mutex_unlock(mutex);
286 #ifdef DEBUG_LOCKING
287  fprintf(stderr, "Release of mutex 0x%08x %s.\n", (unsigned int)mutex,
288  ret ? "failed" : "successful");
289 #endif
290  assert(ret == 0);
291 #endif
292 }
293 
294 
301 static inline void copy_string_to_buffer (char **target, char *source, void *buffer, unsigned int *offset)
302 {
303  unsigned int length = strlen(source);
304  *target = (char *)buffer + *offset;
305  memcpy(*target, source, length + 1);
306  *offset += length + 1;
307 }
308 
309 
310 #endif /* C_LIBWEBCAM_H */

Generated on Sun Apr 28 2013 23:41:32 for Webcam Library by Doxygen 1.8.3.1
Copyright © 2006-2008 Logitech.