Webcam Library Reference Documentation  Logitech logo

Libs/libwebcam/libwebcam.h

Go to the documentation of this file.
00001 
00008 /*
00009  * Copyright (c) 2006-2008 Logitech.
00010  *
00011  * This file is part of libwebcam.
00012  * 
00013  * libwebcam is free software: you can redistribute it and/or modify
00014  * it under the terms of the GNU Lesser General Public License as published
00015  * by the Free Software Foundation, either version 3 of the License, or
00016  * (at your option) any later version.
00017  * 
00018  * libwebcam is distributed in the hope that it will be useful,
00019  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00020  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00021  * GNU Lesser General Public License for more details.
00022  * 
00023  * You should have received a copy of the GNU Lesser General Public License
00024  * along with libwebcam.  If not, see <http://www.gnu.org/licenses/>.
00025  */
00026 
00027 #ifndef C_LIBWEBCAM_H
00028 #define C_LIBWEBCAM_H
00029 
00030 
00031 #include <assert.h>
00032 
00033 
00034 /*
00035  * Constants
00036  */
00037 
00039 #define USE_UVCVIDEO
00040 
00043 #define USE_LOGITECH_DYNCTRL
00044 
00047 #undef  DISABLE_UVCVIDEO_DYNCTRL
00048 // There is no dynctrl support without uvcvideo support
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
00066 
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  * Macros
00079  */
00080 
00082 #define GET_HANDLE(handle)      (handle_list.handles[(handle)])
00083 
00084 #define HANDLE_OPEN(handle)     ((handle) < MAX_HANDLES && GET_HANDLE(handle).open)
00085 
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  * Structures
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  * Globals
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  * Helper functions
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 /* C_LIBWEBCAM_H */

Generated on Tue Nov 8 08:41:15 2011 for Webcam Library by Doxygen 1.4.6
Copyright © 2006-2008 Logitech.