📄 quickcam.h
字号:
#define TEST_BUGR_MSG(cond, fmt, args...) \ do { \ if ((cond)!=0) { \ PDEBUG(fmt, ## args); \ PDEBUG("Badness in %s at %s:%d", __FUNCTION__, __FILE__, __LINE__); \ return -EFAULT; \ } \ } while (0)#define POISON(obj) do { memset(&(obj),POISON_VAL,sizeof(obj)); } while(0)#else#define PDEBUG(fmt, args...)#define IDEBUG_VAR#define IDEBUG_INIT(x)#define IDEBUG_TEST(x)#define IDEBUG_EXIT(x)#define IDEBUG_EXIT_NOPOISON(x)#define TEST_BUG(x)#define TEST_BUGR(x)#define TEST_BUG_MSG(cond, fmt, args...)#define TEST_BUGR_MSG(cond, fmt, args...)#define POISON(obj)#endif /* DEBUG *///gcc is buggy? This doesn't work//#define PRINTK(lvl, fmt, args...) printk(lvl "quickcam: " fmt "\n", ## args)#define PRINTK(lvl, fmt, args...) do { printk(lvl "quickcam: " fmt, ## args); printk("\n"); } while (0)/* }}} *//* {{{ [fold] SECTION: hardware related stuff */#define QUICKCAM_ISOPIPE 0x81/* Control register of the STV0600 ASIC */#define STV_ISO_ENABLE 0x1440#define STV_SCAN_RATE 0x1443#define STV_ISO_SIZE 0x15C1#define STV_Y_CTRL 0x15C3#define STV_X_CTRL 0x1680#define STV_REG00 0x1500#define STV_REG01 0x1501#define STV_REG02 0x1502#define STV_REG03 0x1503#define STV_REG04 0x1504#define STV_REG23 0x0423/* Maximum frame size that any sensor can deliver */#define MAX_FRAME_WIDTH 360#define MAX_FRAME_HEIGHT 296/* }}} *//* {{{ [fold] SECTION: struct quickcam datatype and related values *//* {{{ [fold] qc_sensor_data: Sensor related data (unique to each camera) */struct qc_sensor_data { const struct qc_sensor *sensor; /* Autodetected when camera is plugged in */ int maxwidth; /* Maximum size the sensor can deliver */ int maxheight; int width; /* Size delivered by the sensor (-1=unknown) */ int height; int exposure; /* Current exposure in effect (sensor-specific value, -1=unknown) */ int rgain, ggain, bgain; /* Current gains in effect (sensor-specific values, -1=unknown) */ unsigned int subsample : 1; /* Set into subsampling mode? */ unsigned int compress : 1; /* Set into compressed mode? */};/* }}} *//* {{{ [fold] qc_i2c_data: I2C command queue for writing commands to camera */#define I2C_MAXCOMMANDS 16 /* Should be about 1-2 times the size of transfer buffer (=16) for maximum performance */#define I2C_FLAG_WORD BIT(0) /* Set if a 16-bit value is sent, otherwise 8-bit value */#define I2C_FLAG_BREAK BIT(1) /* Set if this is the last command in a packet */struct qc_i2c_data { struct urb *urb; struct { u8 loval; u8 hival; u8 regnum; u8 flags; } commands[I2C_MAXCOMMANDS]; /* 2=URB scheduled, need to schedule extra packet for QuickCam Web at completion */ volatile int packets; /* 0=no URBs scheduled, 1=URB scheduled */ volatile unsigned int newhead; /* Points to first free buffer position */ volatile unsigned int head; /* Points to oldest command which was not yet flushed */ volatile unsigned int tail; /* Points to next position which needs to be send, modified from interrupt */ wait_queue_head_t wq; /* Woken up when all pending data is sent */ IDEBUG_VAR};/* }}} *//* {{{ [fold] qc_isoc_data: Isochronous transfer queue control data for reading from camera */#define ISOC_URBS 2 /* Number of URBs to use */#define ISOC_PACKETS 10 /* How many isochronous data packets per URB */#define ISOC_PACKET_SIZE 1023 /* Max size of one packet (shouldn't be hardcoded JFC was 960) */struct qc_isoc_data { struct urb *urbs[ISOC_URBS]; unsigned char *buffer; /* Isochronous data transfer buffers */ int errorcount; Bool streaming; /* TRUE if URBs are allocated and submitted */ IDEBUG_VAR};/* }}} *//* {{{ [fold] qc_stream_data: Camera data stream control data */struct qc_stream_data { Bool capturing; /* Are we capturing data for a frame? */ int frameskip; /* How frequently to capture frames? 0=each frame, 1=every other */ IDEBUG_VAR};/* }}} *//* {{{ [fold] qc_frame_data: Raw frame (bayer/mjpeg) buffers */#define FRAME_BUFFERS 2 /* We are double buffering */#define FRAME_DATASIZE (MAX_FRAME_WIDTH*MAX_FRAME_HEIGHT) /* About 101 kilobytes (assume that compressed frame is always smaller) */struct qc_frame_data { struct { int rawdatalen; /* Number of used bytes of this frame buffer */ } buffers[FRAME_BUFFERS]; unsigned char *rawdatabuf; /* vmalloc'd chunk containing the all raw frame data buffers concatenated */ int maxrawdatalen; /* Maximum amount of data we are willing to accept in bytes, */ /* zero indicates that we are not grabbing current frame (but just throwing data away) */ volatile unsigned int head; /* The buffer to be captured next (empty or grabbing, if full, then whole buffer is full) */ volatile unsigned int tail; /* The buffer to be consumed next (full, unless equals head, then it is empty/grabbing) */ spinlock_t tail_lock; /* Protects tail changes */ volatile Bool tail_in_use; /* TRUE, when consumer is processing the frame pointed to by tail */ wait_queue_head_t wq; /* Processes waiting for more data in the buffer */ volatile int waiting; /* Number of processes waiting in the wait queues */ volatile Bool exiting; /* Set to TRUE when we want to quit */ volatile int lost_frames; /* Increased by one for every lost (non-captured by applications) frame, reset when a frame is captured */ IDEBUG_VAR};/* }}} *//* {{{ [fold] qc_mjpeg_data: MJPEG decoding data */struct qc_mjpeg_data { int depth; /* Bits per pixel in the final RGB image: 16 or 24 */ u8 *encV; /* Temporary buffers for holding YUV image data */ u8 *encU; u8 *encY; /* yuv2rgb private data */ void *table; void *table_rV[256]; void *table_gU[256]; int table_gV[256]; void *table_bU[256]; void (*yuv2rgb_func)(struct qc_mjpeg_data *, u8 *, u8 *, u8 *, u8 *, void *, void *, int); IDEBUG_VAR};/* }}} *//* {{{ [fold] qc_fmt_data: Format conversion routines private data */struct qc_fmt_data { unsigned char userlut[QC_LUT_SIZE]; /* User specified fixed look-up table, initialized when camera is plugged in */ unsigned char lut[QC_LUT_SIZE]; /* Dynamically calculated LUT, for which userlut is applied to */#if COMPRESS struct qc_mjpeg_data mjpeg_data; Bool compress; /* Was compression subsystem initialized? */#endif IDEBUG_VAR};/* }}} *//* {{{ [fold] qc_capt_data: Formatted image capturing control data *//* qc_capt_data: Formatted image capturing control data. */#define MAX_FRAME_SIZE (MAX_FRAME_WIDTH*MAX_FRAME_HEIGHT*4) /* Video Size 356x292x4 bytes for 0RGB 32 bpp mode */struct qc_capt_data { unsigned char *frame; /* Final image data buffer given to application, size MAX_FRAME_SIZE (mmappable) */ Bool settled; /* Has the picture settled after last open? */ IDEBUG_VAR};/* }}} *//* {{{ [fold] qc_adapt_data: Automatic exposure control data *//* There are three different exposure control algorithms for different cases */struct qc_adapt_data { int olddelta; int oldmidvalue, midvaluesum; int oldexposure, exposure; int gain; int framecounter; enum { EXPCONTROL_SATURATED, /* Picture is over/undersaturated, halve/double brightness */ EXPCONTROL_NEWTON, /* Using Newton linear estimation */ EXPCONTROL_FLOAT, /* Very near correct brightness, float exposure slightly */ } controlalg; IDEBUG_VAR};/* }}} *//* {{{ [fold] qc_settings_data: User settings given by qcset or module parameters, initialized when camera is plugged in */struct qc_settings_data { unsigned int keepsettings : 1; /* Keep all settings at each camera open (or reset most of them) */ unsigned int subsample : 1; /* Normal or sub-sample (sub-sample to increase the speed) */ unsigned int compress : 1; /* Enable compressed mode if available (higher framerate) */ unsigned int frameskip : 4; /* How many frames to skip (higher=lower framerate) */ unsigned int quality : 3; /* Quality of format conversion (higher=better but slower) */ unsigned int adaptive : 1; /* Use automatic exposure control */ unsigned int equalize : 1; /* Equalize images */ unsigned int userlut : 1; /* Apply user-specified lookup-table */ unsigned int retryerrors : 1; /* If errors happen when capturing an image, retry a few times? */ unsigned int compat_16x : 1; /* Compatibility: force image size to multiple of 16 */ unsigned int compat_dblbuf : 1; /* Compatibility: fake doublebuffering for applications */ unsigned int compat_torgb : 1; /* Compatibility: use RGB data order, not BGR */ unsigned int settle : 8; /* Maximum number of frames to wait image brightness to settle */ /* Total: 25 bits */};/* }}} *//* Main per-camera data structure, most important thing in whole driver */struct quickcam { /* The following entries are initialized in qc_usb_init() when camera is plugged in */ struct semaphore lock; /* Allow only one process to access quickcam at a time */ struct list_head list; /* All cameras are in a doubly linked list */ int users; /* User count (simultaneous open count) */ struct usb_device *dev; /* USB device, set to NULL when camera disconnected and interrupts disabled */ unsigned char iface; /* The interface number in the camera device we are bound to */ Bool connected; /* Set to FALSE immediately when the camera is disconnected (even before interrupts are disabled) */ struct video_device vdev; /* Used for registering the camera driver for Video4Linux */ struct qc_settings_data settings; /* General user settings set with e.g. qcset */#if HAVE_PROCFS struct proc_dir_entry *proc_entry;#endif /* The following entries are initialized in qc_v4l_init() when the camera device is opened */ struct video_picture vpic; /* Contains the last values set by user (which is reported to user) */ Bool vpic_pending; /* Settings in vpic were changed but are not yet in effect */ struct video_window vwin; /* Contains the image size and position the user is expecting */ /* Private structures for each module, initialized in corresponding init-function */ struct qc_i2c_data i2c_data; /* Filled when the camera is plugged in or driver loaded */ struct qc_adapt_data adapt_data; /* Filled when the camera is plugged in or driver loaded */ struct qc_sensor_data sensor_data; /* Mostly filled when the device is opened */ struct qc_stream_data stream_data; /* Filled when the device is opened */ struct qc_frame_data frame_data; /* Filled when the device is opened */ struct qc_capt_data capt_data; /* Filled when the device is opened */ struct qc_isoc_data isoc_data; /* Filled when the device is opened */ struct qc_fmt_data fmt_data; /* Mostly filled when the device is opened, except for userlut */ u8 dmabuf[35]; /* Temporary buffer which may be used for DMA transfer */};/* }}} *//* {{{ [fold] SECTION: miscelleneous *//* Constant information related to a sensor type */struct qc_sensor { char *name; char *manufacturer; int (*init)(struct quickcam *qc); /* Initialize sensor */ int (*start)(struct quickcam *qc); /* Start sending image data */ int (*stop)(struct quickcam *qc); /* Stop sending image data */ int (*set_size)(struct quickcam *qc, unsigned int w, unsigned int h); /* Request camera to send the given image size */ /* Set primary brightness value exp (usually exposure time) and HSV 0-65535 (usually gains) */ int (*set_levels)(struct quickcam *qc, unsigned int exp, unsigned int gain, unsigned int hue, unsigned int sat); int (*set_target)(struct quickcam *qc, unsigned int val); /* Set target brightness for sensor autoexposure 0-65535 */ /* Exposure and gain control information */ Bool autoexposure; /* Sensor has automatic exposure control */ int adapt_gainlow; /* (0-65535) How eagerly to decrease gain when necessary */ int adapt_gainhigh; /* (0-65535) How eagerly to increase gain when necessary */ /* Information needed to access the sensor via I2C */ int reg23; unsigned char i2c_addr; /* Identification information used for auto-detection */ int id_reg; unsigned char id; int length_id; int flag; /* May be used by sensor driver for private purposes */};/* }}} *//* {{{ [fold] SECTION: function prototypes *//* USB interface chip control */int qc_i2c_break(struct quickcam *qc);int qc_i2c_wait(struct quickcam *qc);int qc_i2c_set(struct quickcam *qc, unsigned char reg, unsigned char val);int qc_i2c_setw(struct quickcam *qc, unsigned char reg, unsigned short val);int qc_stv_set(struct quickcam *qc, unsigned short reg, unsigned char val);int qc_stv_setw(struct quickcam *qc, unsigned short reg, unsigned short val);int qc_stv_get(struct quickcam *qc, unsigned short reg);/* Image format conversion routines */int qc_fmt_convert(struct quickcam *qc, unsigned char *src, unsigned int src_len, unsigned char *dst, unsigned int dst_len, int *midvalue);int qc_fmt_issupported(int format);const char *qc_fmt_getname(int format);int qc_fmt_getdepth(int format);int qc_fmt_init(struct quickcam *qc);void qc_fmt_exit(struct quickcam *qc);int qc_mjpeg_decode(struct qc_mjpeg_data *md, unsigned char *src, int src_len, unsigned char *dst);int qc_mjpeg_init(struct qc_mjpeg_data *md, int depth, Bool tobgr);void qc_mjpeg_exit(struct qc_mjpeg_data *md);void qc_hsv2rgb(s16 hue, u16 sat, u16 val, int *red, int *green, int *blue);int qc_get_i2c(struct quickcam *qc, const struct qc_sensor *sensor, int reg);void qc_frame_flush(struct quickcam *qc);void qc_usleep(unsigned long usec);extern int qcdebug; /* Driver debuglevel *//* }}} */#endif /* __KERNEL__ */#endif /* __LINUX_QUICKCAM_H */
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -