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

📄 usbcam.h

📁 Windows CE下USB驱动(OV511)
💻 H
📖 第 1 页 / 共 2 页
字号:
	BOOL bStopped;              //是否停止
	int nPacketSize;            //包大小
    
    // USB support
	USB_HANDLE hDevice;
	LPCUSB_FUNCS lpUsbFuncs;

	DWORD dwDeviceContext;      //设备上下文指针
	
} DRVCONTEXT, *PDRVCONTEXT;

typedef struct
{
	int     framenum;		/* Index of this frame */
	BYTE    *data;	        /* Frame buffer */
	BYTE    *tempdata;      /* Temp buffer for multi-stage conversions */
	BYTE    *rawdata;	    /* Raw camera data buffer */
	BYTE    *compbuf;	    /* Temp buffer for decompressor */

	int depth;		        /* Bytes per pixel */
	int width;		        /* Width application is expecting */
	int height;		        /* Height application is expecting */

	int rawwidth;	    	/* Actual width of frame sent from camera */
	int rawheight;	    	/* Actual height of frame sent from camera */

	int sub_flag;		    /* Sub-capture mode for this frame? */
	unsigned int format;	/* Format for this frame */
	int compressed;	    	/* Is frame compressed? */

	//volatile int grabstate;/* State of grabbing */
	int scanstate;		    /* State of scanning */

	int bytes_recvd;	    /* Number of image bytes received from camera */

	DWORD bytes_read;	    /* Amount that has been read() */

	//wait_queue_head_t wq;	/* Processes waiting */

	BOOL snapshot;		    /* True if frame was a snapshot */
}OV511FRAME, POV511FRAME;

enum {
	BRG_UNKNOWN,
	BRG_OV511,
	BRG_OV511PLUS,
	BRG_OV518,
	BRG_OV518PLUS,
};

/* Bridge classes */
enum {
	BCL_UNKNOWN,
	BCL_OV511,
	BCL_OV518,
};

/* Sensor types */
enum {
	SEN_UNKNOWN,
	SEN_OV76BE,
	SEN_OV7610,
	SEN_OV7620,
	SEN_OV7620AE,
	SEN_OV6620,
	SEN_OV6630,
	SEN_OV6630AE,
	SEN_OV6630AF,
	SEN_OV8600,
	SEN_KS0127,
	SEN_KS0127B,
	SEN_SAA7111A,
};

typedef struct  
{

	int customid;
	char *desc;
	BYTE iface;
	char usb_path[OV511_USB_PATH_LEN];

	/* Determined by sensor type */
	int maxwidth;
	int maxheight;
	int minwidth;
	int minheight;

    int compress;		/* Should the next frame be compressed? */
	int compress_inited;	/* Are compression params uploaded? */

    int lightfreq;		/* Power (lighting) frequency */
	int bandfilt;		/* Banding filter enabled flag */

	int brightness;
	int colour;
	int contrast;
	int hue;
	int whiteness;
	int exposure;
	int auto_brt;		/* Auto brightness enabled flag */
	int auto_gain;		/* Auto gain control enabled flag */
	int auto_exp;		/* Auto exposure enabled flag */
	int backlight;		/* Backlight exposure algorithm flag */
	int mirror;		/* Image is reversed horizontally */
	int bridge;		/* Type of bridge (BRG_*) */
	int bclass;		/* Class of bridge (BCL_*) */
	int sensor;		/* Type of image sensor chip (SEN_*) */

	int packet_size;	/* Frame size per isoc desc */
	int packet_numbering;	/* Is ISO frame numbering enabled? */

    BYTE primary_i2c_slave;  /* I2C write id of sensor */

    int snap_enabled;	/* Snapshot mode enabled */

    /* Video decoder stuff */
	int input;		/* Composite, S-VIDEO, etc... */
	int num_inputs;		/* Number of inputs */
	int norm; 		/* NTSC / PAL / SECAM */
	int has_decoder;	/* Device has a video decoder */
	int pal;		/* Device is designed for PAL resolution */
	int led_policy;		/* LED: off|on|auto; OV511+ only */
}OV511STATUS, POV511STATUS;

enum {
	LED_OFF,
	LED_ON,
	LED_AUTO
};


#define OV511_DONE_BUS 0x01
#define OV511_REG_BUS 0x02
#define OV511_I2C_BUS 0x03

typedef struct{
    BYTE bus;
    BYTE reg;
    BYTE val;
}OV511REGVALS, POV511REGVALS;

#define OV511_QUANTABLESIZE	64
#define OV518_QUANTABLESIZE	32

#define OV511_YQUANTABLE { \
	0, 1, 1, 2, 2, 3, 3, 4, \
	1, 1, 1, 2, 2, 3, 4, 4, \
	1, 1, 2, 2, 3, 4, 4, 4, \
	2, 2, 2, 3, 4, 4, 4, 4, \
	2, 2, 3, 4, 4, 5, 5, 5, \
	3, 3, 4, 4, 5, 5, 5, 5, \
	3, 4, 4, 4, 5, 5, 5, 5, \
	4, 4, 4, 4, 5, 5, 5, 5  \
}

#define OV511_UVQUANTABLE { \
	0, 2, 2, 3, 4, 4, 4, 4, \
	2, 2, 2, 4, 4, 4, 4, 4, \
	2, 2, 3, 4, 4, 4, 4, 4, \
	3, 4, 4, 4, 4, 4, 4, 4, \
	4, 4, 4, 4, 4, 4, 4, 4, \
	4, 4, 4, 4, 4, 4, 4, 4, \
	4, 4, 4, 4, 4, 4, 4, 4, \
	4, 4, 4, 4, 4, 4, 4, 4  \
}

#define OV518_YQUANTABLE { \
	5, 4, 5, 6, 6, 7, 7, 7, \
	5, 5, 5, 5, 6, 7, 7, 7, \
	6, 6, 6, 6, 7, 7, 7, 8, \
	7, 7, 6, 7, 7, 7, 8, 8  \
}

#define OV518_UVQUANTABLE { \
	6, 6, 6, 7, 7, 7, 7, 7, \
	6, 6, 6, 7, 7, 7, 7, 7, \
	6, 6, 6, 7, 7, 7, 7, 8, \
	7, 7, 7, 7, 7, 7, 8, 8  \
}


#define OV511IICREADETRIES 3
#define ENABLE_Y_QUANTABLE 1
#define ENABLE_UV_QUANTABLE 1

//视频相关处理函数

//分析视频接口
BOOL ParseStreamInterfaces( LPCUSB_DEVICE lpUsbDev, 
                            BYTE bIFStrm, 
                            BYTE bIFSubStrm, 
                            DWORD *pdwContext);

//进行OV511寄存器写操作
BOOL RegisterWrite(PDRVCONTEXT pDrv, 
                    BYTE reg, 
                    BYTE value);
//进行OV511寄存器读操作
BOOL RegisterRead(PDRVCONTEXT pDrv, 
                  BYTE reg, 
                  BYTE *value);

//给OV511寄存器赋初始值(在OV511初始化时调用)
BOOL WriteRegvals(PDRVCONTEXT pDrv);

//停止OV511视频采集
BOOL OV51xStop(PDRVCONTEXT pDrv);
//重新开始OV511采集
BOOL OV51xRestart(PDRVCONTEXT pDrv);
//重置OV511
BOOL OV51xReset(PDRVCONTEXT pDrv,
                BYTE reset_type);

//设置OV511传输包大小
//根据OV511 Datasheet
//视频接口有8种配置,每个的包大小分别为0,33,129,257,385,513,769,961
BOOL OV511SetPacketSize(PDRVCONTEXT pDrv,
                        DWORD size);

//设置视频接口
DWORD SetStreamInterface(PDRVCONTEXT pDrv,
                         BYTE nDWORDerFace);

//设置默认参数
BOOL OV51xSetDefaultParams(PDRVCONTEXT pDrv);
//初始化寄存器
BOOL OV511ModeInitRegs(PDRVCONTEXT pDrv,
                       int width, 
                       int height, 
                       int mode,
                       int sub_flag);

BOOL SensorSetAutoBrightness(PDRVCONTEXT pDrv);
BOOL SensorSetMirror(PDRVCONTEXT pDrv);
BOOL SensorSetAutoExposure(PDRVCONTEXT pDrv);
BOOL SensorSetLightFreq(PDRVCONTEXT pDrv);
BOOL SensorSetBandingFilter(PDRVCONTEXT pDrv);
BOOL SensorSetBacklight(PDRVCONTEXT pDrv);
BOOL SetOVSensorWindow( PDRVCONTEXT pDrv, 
                        int width,
                        int height,
                        int mode,
                        int sub_flag);

BOOL ModeInitOVSensorRegs(PDRVCONTEXT pDrv,
                          int width, 
                          int height,
                          int mode,
                          int sub_flag,
                          int qvga);


//进行实时传输,这个函数来源于微软例程,参照usnclient.cpp中的IssueVendorTransfer完成
DWORD IssueIsochTransfer (
   LPCUSB_FUNCS              pUsbFuncs,
   HANDLE                    hUsbDevice,
   LPTRANSFER_NOTIFY_ROUTINE NotifyRoutine,       // Transfer completion routine.
   PVOID                     NotifyContext,       // Single argument passed to the completion routine
   DWORD                     Flags,               // USB_XXX flags describing the transfer
   DWORD                     dwStartingFrame,     // Starting frame to read
   DWORD                     dwNumFrames,         // Number of frames to read
   PDWORD                    pdwFrameLengths,     // Array that receives the length of each frame
   LPVOID                    pBuffer,             // PoDWORDer to transfer buffer
   ULONG                     PhysAddr,            // Specifies the physical address, which may be NULL, of the data buffer
   LPDWORD                   pBytesTransferred,   // Number of bytes transferred by USB
   DWORD                     dwTimeout,           // Timeout in msec
   PUSB_ERROR                pUsbRc			      // Returns USB_ERROR or USB_TRANSFER
   );

//读取一帧画面
DWORD OV51xReadOneFrame(PDRVCONTEXT pDrv,
                        BYTE *pBuff,
                        DWORD startaddress);
OV511Reset(PDRVCONTEXT pDrv, 
           BYTE reset_type);
PDRVCONTEXT GetConfigData (DWORD dwContext);

//摄像头的PIV,VID
#define VID_OMINIVISION        0x05A9
#define PID_OV511    0x0511

typedef struct {
	LPTSTR lpszCamName;
	WORD wVendorID;
	WORD wProductID;
} USBCAMSTRUCT, *PUSBCAMSTRUCT;

void Make8x8(unsigned char *pIn, unsigned char *pOut, int w);
void YUV2RGB(int yy, int uu, int vv, int width, int height, int SegNum, PBYTE pBmpData);

#define mmax(a, b)        ((a) > (b) ? (a) : (b))
#define mmin(a, b)        ((a) < (b) ? (a) : (b))


//
// This structure contains the list of vendor specific cameras
// that closely follow the USB Vid Specification even though they
// don't say they do.  If your camera works with the driver, you
// can add your camera to this list.  
//

#endif //#endif usbcam.h

⌨️ 快捷键说明

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