📄 usbvideo.h
字号:
/* * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2, or (at your option) * any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */#ifndef usbvideo_h#define usbvideo_h#include <linux/config.h>#include <linux/proc_fs.h>#include <linux/videodev.h>#include <linux/usb.h>/* Most helpful debugging aid */#define assert(expr) ((void) ((expr) ? 0 : (err("assert failed at line %d",__LINE__))))#define USES_PROC_FS (defined(CONFIG_PROC_FS) && defined(CONFIG_VIDEO_PROC_FS))#define USBVIDEO_REPORT_STATS 1 /* Set to 0 to block statistics on close *//* Bit flags (options) */#define FLAGS_RETRY_VIDIOCSYNC (1 << 0)#define FLAGS_MONOCHROME (1 << 1)#define FLAGS_DISPLAY_HINTS (1 << 2)#define FLAGS_OVERLAY_STATS (1 << 3)#define FLAGS_FORCE_TESTPATTERN (1 << 4)#define FLAGS_SEPARATE_FRAMES (1 << 5)#define FLAGS_CLEAN_FRAMES (1 << 6)#define FLAGS_NO_DECODING (1 << 7)/* Bit flags for frames (apply to the frame where they are specified) */#define USBVIDEO_FRAME_FLAG_SOFTWARE_CONTRAST (1 << 0)/* Camera capabilities (maximum) */#define CAMERA_URB_FRAMES 32#define CAMERA_MAX_ISO_PACKET 1023 /* 1022 actually sent by camera */#define FRAMES_PER_DESC (CAMERA_URB_FRAMES)#define FRAME_SIZE_PER_DESC (CAMERA_MAX_ISO_PACKET)/* 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); }#define V4L_BYTES_PER_PIXEL 3 /* Because we produce RGB24 *//* * Use this macro to construct constants for different video sizes. * We have to deal with different video sizes that have to be * configured in the device or compared against when we receive * a data. Normally one would define a bunch of VIDEOSIZE_x_by_y * #defines and that's the end of story. However this solution * does not allow to convert between real pixel sizes and the * constant (integer) value that may be used to tag a frame or * whatever. The set of macros below constructs videosize constants * from the pixel size and allows to reconstruct the pixel size * from the combined value later. */#define VIDEOSIZE(x,y) (((x) & 0xFFFFL) | (((y) & 0xFFFFL) << 16))#define VIDEOSIZE_X(vs) ((vs) & 0xFFFFL)#define VIDEOSIZE_Y(vs) (((vs) >> 16) & 0xFFFFL)typedef unsigned long videosize_t;/* * This macro checks if the camera is still operational. The 'uvd' * pointer must be valid, uvd->dev must be valid, we are not * removing the device and the device has not erred on us. */#define CAMERA_IS_OPERATIONAL(uvd) (\ (uvd != NULL) && \ ((uvd)->dev != NULL) && \ ((uvd)->last_error == 0) && \ (!(uvd)->remove_pending))/* * 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); \}#define RING_QUEUE_SIZE (128*1024) /* Must be a power of 2 */#define RING_QUEUE_ADVANCE_INDEX(rq,ind,n) (rq)->ind = ((rq)->ind + (n)) & ((rq)->length-1)#define RING_QUEUE_DEQUEUE_BYTES(rq,n) RING_QUEUE_ADVANCE_INDEX(rq,ri,n)#define RING_QUEUE_PEEK(rq,ofs) ((rq)->queue[((ofs) + (rq)->ri) & ((rq)->length-1)])struct RingQueue { unsigned char *queue; /* Data from the Isoc data pump */ int length; /* How many bytes allocated for the queue */ int wi; /* That's where we write */ int ri; /* Read from here until you hit write index */ wait_queue_head_t wqh; /* Processes waiting */};enum ScanState { ScanState_Scanning, /* Scanning for header */ ScanState_Lines /* Parsing lines */};/* Completion states of the data parser */enum ParseState { scan_Continue, /* Just parse next item */ scan_NextFrame, /* Frame done, send it to V4L */ scan_Out, /* Not enough data for frame */ scan_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_Done_Hold, /* Are syncing or reading */ FrameState_Error, /* Something bad happened while processing */};/* * Some frames may contain only even or odd lines. This type * specifies what type of deinterlacing is required. */enum Deinterlace { Deinterlace_None=0, Deinterlace_FillOddLines, Deinterlace_FillEvenLines};#define USBVIDEO_NUMFRAMES 2 /* How many frames we work with */#define USBVIDEO_NUMSBUF 2 /* How many URBs linked in a ring *//* This structure represents one Isoc request - URB and buffer */struct usbvideo_sbuf { char *data; struct urb *urb;};struct usbvideo_frame { char *data; /* Frame buffer */ unsigned long header; /* Significant bits from the header */ videosize_t canvas; /* The canvas (max. image) allocated */ videosize_t request; /* That's what the application asked for */ unsigned short palette; /* The desired format */ enum FrameState frameState;/* State of grabbing */ enum ScanState scanstate; /* State of scanning */ enum Deinterlace deinterlace; int flags; /* USBVIDEO_FRAME_FLAG_xxx bit flags */ int curline; /* Line of frame we're working on */ long seqRead_Length; /* Raw data length of frame */ long seqRead_Index; /* Amount of data that has been already read */ void *user; /* Additional data that user may need */};/* Statistics that can be overlaid on screen */struct usbvideo_statistics { unsigned long frame_num; /* Sequential number of the frame */ unsigned long urb_count; /* How many URBs we received so far */ unsigned long urb_length; /* Length of last URB */ unsigned long data_count; /* How many bytes we received */ unsigned long header_count; /* How many frame headers we found */ unsigned long iso_skip_count; /* How many empty ISO packets received */ unsigned long iso_err_count; /* How many bad ISO packets received */};struct usbvideo;struct uvd { struct video_device vdev; /* Must be the first field! */ struct usb_device *dev; struct usbvideo *handle; /* Points back to the struct usbvideo */ void *user_data; /* Camera-dependent data */ int user_size; /* Size of that camera-dependent data */ int debug; /* Debug level for usbvideo */ unsigned char iface; /* Video interface number */ unsigned char video_endp; unsigned char ifaceAltActive;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -