00001
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027 #ifndef C_LIBWEBCAM_H
00028 #define C_LIBWEBCAM_H
00029
00030
00031 #include <assert.h>
00032
00033
00034
00035
00036
00037
00039 #define USE_UVCVIDEO
00040
00043 #define USE_LOGITECH_DYNCTRL
00044
00047 #undef DISABLE_UVCVIDEO_DYNCTRL
00048
00049 #ifndef USE_UVCVIDEO
00050 #define DISABLE_UVCVIDEO_DYNCTRL
00051 #endif
00052
00054 #define ENABLE_V4L2_ADVANCED_CONTROL_ENUMERATION
00055
00059 #define DYNCTRL_IGNORE_EEXIST_AFTER_PASS1
00060
00062 #define MAX_HANDLES 32
00063
00065 #define DISABLE_LOCKING 1
00067 #define DEBUG_LOCKING 1
00068
00070 #define UNKNOWN_CONTROL_NAME "Unknown control"
00073 #define CONTROL_IO_ERROR_RETRIES 2
00074
00075
00076
00077
00078
00079
00080
00082 #define GET_HANDLE(handle) (handle_list.handles[(handle)])
00084 #define HANDLE_OPEN(handle) ((handle) < MAX_HANDLES && GET_HANDLE(handle).open)
00086 #define HANDLE_VALID(handle) (HANDLE_OPEN(handle) && GET_HANDLE(handle).device)
00087
00090 #define V4L2_MENU_CTRL_MAX_NAME_SIZE sizeof(((struct v4l2_querymenu *)NULL)->name)
00091
00093 #define MAKE_FOURCC(c1,c2,c3,c4) \
00094 (unsigned int)((long)c1 | (long)c2 << 8 | (long)c3 << 16 | (long)c4 << 24)
00095
00096
00097
00098
00099
00100
00101
00105 typedef struct _Control {
00107 CControl control;
00109 int v4l2_control;
00111 struct _Control * next;
00112
00113 } Control;
00114
00118 typedef struct _ControlList {
00120 Control * first;
00122 pthread_mutex_t mutex;
00124 int count;
00125
00126 } ControlList;
00127
00131 typedef struct _Device {
00133 CDevice device;
00135 char v4l2_name[NAME_MAX];
00137 int handles;
00139 ControlList controls;
00142 int valid;
00144 struct _Device * next;
00145
00146 } Device;
00147
00151 typedef struct _DeviceList {
00153 Device * first;
00155 pthread_mutex_t mutex;
00157 int count;
00158
00159 } DeviceList;
00160
00172 typedef struct _Handle {
00174 Device * device;
00176 int open;
00178 int last_system_error;
00179
00180 } Handle;
00181
00185 typedef struct _HandleList {
00187 Handle handles[MAX_HANDLES];
00189 pthread_mutex_t mutex;
00192 int first_free;
00193
00194 } HandleList;
00195
00196
00197
00198
00199
00200
00201
00202 extern int initialized;
00203 extern HandleList handle_list;
00204
00205 extern int open_v4l2_device(char *device_name);
00206
00207
00208
00209
00210
00211
00212
00223 static inline CResult lock_mutex (pthread_mutex_t *mutex)
00224 {
00225 #ifndef DISABLE_LOCKING
00226 #ifdef DEBUG_LOCKING
00227 fprintf(stderr, "Acquiring mutex 0x%08x ...\n", (unsigned int)mutex);
00228 #endif
00229 int ret = pthread_mutex_lock(mutex);
00230 #ifdef DEBUG_LOCKING
00231 fprintf(stderr, "Acquisition of mutex 0x%08x %s.\n", (unsigned int)mutex,
00232 ret ? "failed" : "successful");
00233 #endif
00234 assert(ret == 0);
00235 return ret ? C_SYNC_ERROR : C_SUCCESS;
00236 #else
00237 return C_SUCCESS;
00238 #endif
00239 }
00240
00241
00252 static inline void unlock_mutex (pthread_mutex_t *mutex)
00253 {
00254 #ifndef DISABLE_LOCKING
00255 #ifdef DEBUG_LOCKING
00256 fprintf(stderr, "Releasing mutex 0x%08x ...\n", (unsigned int)mutex);
00257 #endif
00258 int ret = pthread_mutex_unlock(mutex);
00259 #ifdef DEBUG_LOCKING
00260 fprintf(stderr, "Release of mutex 0x%08x %s.\n", (unsigned int)mutex,
00261 ret ? "failed" : "successful");
00262 #endif
00263 assert(ret == 0);
00264 #endif
00265 }
00266
00267
00274 static inline void copy_string_to_buffer (char **target, char *source, void *buffer, unsigned int *offset)
00275 {
00276 unsigned int length = strlen(source);
00277 *target = (char *)buffer + *offset;
00278 memcpy(*target, source, length + 1);
00279 *offset += length + 1;
00280 }
00281
00282
00283 #endif