⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 usbvision.h

📁 这是一个Linux下的USB摄像头捕捉程序
💻 H
📖 第 1 页 / 共 2 页
字号:
#ifndef __LINUX_USBVISION_H#define __LINUX_USBVISION_H#include <linux/list.h>#ifndef VID_HARDWARE_USBVISION	#define VID_HARDWARE_USBVISION 34  /* USBVision Video Grabber */#endif#define USBVISION_PWR_REG		0x00	#define USBVISION_SSPND_EN		(1 << 1)	#define USBVISION_RES2			(1 << 2)	#define USBVISION_PWR_VID		(1 << 5)        #define USBVISION_E2_EN			(1 << 7)#define USBVISION_CONFIG_REG		0x01#define USBVISION_ADRS_REG		0x02#define USBVISION_ALTER_REG		0x03#define USBVISION_FORCE_ALTER_REG	0x04#define USBVISION_STATUS_REG		0x05#define USBVISION_IOPIN_REG		0x06	#define USBVISION_IO_1			(1 << 0)	#define USBVISION_IO_2			(1 << 1)	#define USBVISION_AUDIO_IN		0	#define USBVISION_AUDIO_TV		1	#define USBVISION_AUDIO_RADIO		2	#define USBVISION_AUDIO_MUTE		3#define USBVISION_SER_MODE		0x07#define USBVISION_SER_ADRS		0x08#define USBVISION_SER_CONT		0x09#define USBVISION_SER_DAT1		0x0A#define USBVISION_SER_DAT2		0x0B#define USBVISION_SER_DAT3		0x0C#define USBVISION_SER_DAT4		0x0D#define USBVISION_EE_DATA		0x0E#define USBVISION_EE_LSBAD		0x0F#define USBVISION_EE_CONT		0x10#define USBVISION_DRM_CONT			0x12	#define USBVISION_REF			(1 << 0)	#define USBVISION_RES_UR		(1 << 2)	#define USBVISION_RES_FDL		(1 << 3)	#define USBVISION_RES_VDW		(1 << 4)#define USBVISION_DRM_PRM1		0x13#define USBVISION_DRM_PRM2		0x14#define USBVISION_DRM_PRM3		0x15#define USBVISION_DRM_PRM4		0x16#define USBVISION_DRM_PRM5		0x17#define USBVISION_DRM_PRM6		0x18#define USBVISION_DRM_PRM7		0x19#define USBVISION_DRM_PRM8		0x1A#define USBVISION_VIN_REG1		0x1B	#define USBVISION_8_422_SYNC		0x01	#define USBVISION_16_422_SYNC		0x02	#define USBVISION_VSNC_POL		(1 << 3)	#define USBVISION_HSNC_POL		(1 << 4)	#define USBVISION_FID_POL		(1 << 5)	#define USBVISION_HVALID_PO		(1 << 6)	#define USBVISION_VCLK_POL		(1 << 7)#define USBVISION_VIN_REG2		0x1C	#define USBVISION_AUTO_FID		(1 << 0)	#define USBVISION_NONE_INTER		(1 << 1)	#define USBVISION_NOHVALID		(1 << 2)	#define USBVISION_UV_ID			(1 << 3)	#define USBVISION_FIX_2C		(1 << 4)	#define USBVISION_SEND_FID		(1 << 5)	#define USBVISION_KEEP_BLANK		(1 << 7)#define USBVISION_LXSIZE_I		0x1D#define USBVISION_MXSIZE_I		0x1E#define USBVISION_LYSIZE_I		0x1F#define USBVISION_MYSIZE_I		0x20#define USBVISION_LX_OFFST		0x21#define USBVISION_MX_OFFST		0x22#define USBVISION_LY_OFFST		0x23#define USBVISION_MY_OFFST		0x24#define USBVISION_FRM_RATE		0x25#define USBVISION_LXSIZE_O		0x26#define USBVISION_MXSIZE_O		0x27#define USBVISION_LYSIZE_O		0x28#define USBVISION_MYSIZE_O		0x29#define USBVISION_FILT_CONT		0x2A#define USBVISION_VO_MODE		0x2B#define USBVISION_INTRA_CYC		0x2C#define USBVISION_STRIP_SZ		0x2D#define USBVISION_FORCE_INTRA		0x2E#define USBVISION_FORCE_UP		0x2F#define USBVISION_BUF_THR		0x30#define USBVISION_DVI_YUV		0x31#define USBVISION_AUDIO_CONT		0x32#define USBVISION_AUD_PK_LEN		0x33#define USBVISION_BLK_PK_LEN		0x34#define USBVISION_PCM_THR1		0x38#define USBVISION_PCM_THR2		0x39#define USBVISION_DIST_THR_L		0x3A#define USBVISION_DIST_THR_H		0x3B#define USBVISION_MAX_DIST_L		0x3C#define USBVISION_MAX_DIST_H		0x3D#define USBVISION_OP_CODE		0x33#define MAX_BYTES_PER_PIXEL		4#define MIN_FRAME_WIDTH			64#define MAX_USB_WIDTH			320  //384#define MAX_FRAME_WIDTH			320  //384			/*streching sometimes causes crashes*/#define MIN_FRAME_HEIGHT		48#define MAX_USB_HEIGHT			240  //288#define MAX_FRAME_HEIGHT		240  //288			/*Streching sometimes causes crashes*/#define MAX_FRAME_SIZE     		(MAX_FRAME_WIDTH * MAX_FRAME_HEIGHT * MAX_BYTES_PER_PIXEL)#define USBVISION_CLIPMASK_SIZE		(MAX_FRAME_WIDTH * MAX_FRAME_HEIGHT / 8) //bytesize of clipmask#define USBVISION_URB_FRAMES		32#define USBVISION_MAX_ISOC_PACKET_SIZE 	959			// NT1003 Specs Document says 1023#define USBVISION_NUM_HEADERMARKER	20#define USBVISION_NUMFRAMES		2#define USBVISION_NUMSBUF		2#define USBVISION_POWEROFF_TIME		3 * (HZ)		// 3 seconds/* This macro restricts an int variable to an inclusive range */#define RESTRICT_TO_RANGE(v,mi,ma) { if ((v) < (mi)) (v) = (mi); else if ((v) > (ma)) (v) = (ma); }/* * We use macros to do YUV -> RGB conversion because this is * very important for speed and totally unimportant for size. * * YUV -> RGB Conversion * --------------------- * * B = 1.164*(Y-16)		    + 2.018*(V-128) * G = 1.164*(Y-16) - 0.813*(U-128) - 0.391*(V-128) * R = 1.164*(Y-16) + 1.596*(U-128) * * If you fancy integer arithmetics (as you should), hear this: * * 65536*B = 76284*(Y-16)		  + 132252*(V-128) * 65536*G = 76284*(Y-16) -  53281*(U-128) -  25625*(V-128) * 65536*R = 76284*(Y-16) + 104595*(U-128) * * Make sure the output values are within [0..255] range. */#define LIMIT_RGB(x) (((x) < 0) ? 0 : (((x) > 255) ? 255 : (x)))#define YUV_TO_RGB_BY_THE_BOOK(my,mu,mv,mr,mg,mb) { \    int mm_y, mm_yc, mm_u, mm_v, mm_r, mm_g, mm_b; \    mm_y = (my) - 16;  \    mm_u = (mu) - 128; \    mm_v = (mv) - 128; \    mm_yc= mm_y * 76284; \    mm_b = (mm_yc		+ 132252*mm_v	) >> 16; \    mm_g = (mm_yc -  53281*mm_u -  25625*mm_v	) >> 16; \    mm_r = (mm_yc + 104595*mm_u			) >> 16; \    mb = LIMIT_RGB(mm_b); \    mg = LIMIT_RGB(mm_g); \    mr = LIMIT_RGB(mm_r); \}#if 0/* * This macro performs bounds checking - use it when working with * new formats, or else you may get oopses all over the place. * If pixel falls out of bounds then it gets shoved back (as close * to place of offence as possible) and is painted bright red. */#define USBVISION_PUTPIXEL(fr, ix, iy, vr, vg, vb) { \	register unsigned char *pf; \	int limiter = 0, mx, my; \	mx = ix; \	my = iy; \	if (mx < 0) { \		mx=0; \		limiter++; \	} else if (mx >= 352) { \		mx=351; \		limiter++; \	} \	if (my < 0) { \		my = 0; \		limiter++; \	} else if (my >= V4L_FRAME_HEIGHT) { \		my = V4L_FRAME_HEIGHT - 1; \		limiter++; \	} \	pf = (fr)->data + V4L_BYTES_PER_PIXEL*((iy)*352 + (ix)); \	if (limiter) { \		*pf++ = 0; \		*pf++ = 0; \		*pf++ = 0xFF; \	} else { \		*pf++ = (vb); \		*pf++ = (vg); \		*pf++ = (vr); \	} \}#endif/* Debugging aid */#define USBVISION_SAY_AND_WAIT(what) { \	wait_queue_head_t wq; \	init_waitqueue_head(&wq); \	printk(KERN_INFO "Say: %s\n", what); \	interruptible_sleep_on_timeout (&wq, HZ*3); \}/* * This macro checks if usbvision is still operational. The 'usbvision' * pointer must be valid, usbvision->dev must be valid, we are not * removing the device and the device has not erred on us. */#define USBVISION_IS_OPERATIONAL(udevice) (\	(udevice != NULL) && \	((udevice)->dev != NULL) && \	((udevice)->last_error == 0) && \	(!(udevice)->remove_pending))enum ScanState {	ScanState_Scanning,	/* Scanning for header */	ScanState_Lines		/* Parsing lines */};/* Completion states of the data parser */enum ParseState {	ParseState_Continue,	/* Just parse next item */	ParseState_NextFrame,	/* Frame done, send it to V4L */	ParseState_Out,		/* Not enough data for frame */	ParseState_EndParse	/* End parsing */};enum FrameState {	FrameState_Unused,	/* Unused (no MCAPTURE) */	FrameState_Ready,	/* Ready to start grabbing */	FrameState_Grabbing,	/* In the process of being grabbed into */	FrameState_Done,	/* Finished grabbing, but not been synced yet */	FrameState_DoneHold,	/* Are syncing or reading */	FrameState_Error,	/* Something bad happened while processing */};enum IsocState {	IsocState_InFrame,	/* Isoc packet is member of frame */	IsocState_NoFrame,	/* Isoc packet is not member of any frame */};struct usb_device;struct usbvision_sbuf {	char *data;	struct urb *urb;};#define USBVISION_MAGIC_1      			0x55#define USBVISION_MAGIC_2      			0xAA#define USBVISION_HEADER_LENGTH			0x0c#define USBVISION_SAA7111_ADDR			0x48#define USBVISION_SAA7113_ADDR			0x4a#define USBVISION_BT819_ADDR			0x89#define USBVISION_IIC_LRACK			0x20#define USBVISION_IIC_LRNACK			0x30#define USBVISION_FRAME_FORMAT_PARAM_INTRA	(1<<7)struct usbvision_frame_header {	unsigned char magic_1;				/* 0 magic */	unsigned char magic_2;				/* 1  magic */	unsigned char headerLength;			/* 2 */	unsigned char frameNum;				/* 3 */	unsigned char framePhase;			/* 4 */	unsigned char frameLatency;			/* 5 */	unsigned char dataFormat;			/* 6 */	unsigned char formatParam;			/* 7 */	unsigned char frameWidthLo;			/* 8 */	unsigned char frameWidthHi;			/* 9 */	unsigned char frameHeightLo;			/* 10 */	unsigned char frameHeightHi;			/* 11 */	__u16 frameWidth;				/* 8 - 9 after endian correction*/	__u16 frameHeight;				/* 10 - 11 after endian correction*/};struct usbvision_frame {	char *data;					/* Frame buffer */	struct usbvision_frame_header isocHeader;	/* Header from stream */	int width;					/* Width application is expecting */	int height;					/* Height */	int frmwidth;					/* Width the frame actually is */	int frmheight;					/* Height */	volatile int grabstate;				/* State of grabbing */	int scanstate;					/* State of scanning */	int curline;					/* Line of frame we're working on */	long scanlength;				/* uncompressed, raw data length of frame */	long bytes_read;				/* amount of scanlength that has been read from data */	int v4l_format;					/* format the user needs*/	int v4l_linesize;				/* bytes for one videoline*/	wait_queue_head_t wq;				/* Processes waiting */

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -