📄 spca5xx.c
字号:
out += sprintf(out, "driver : SPCA5XX USB Camera\n"); out += sprintf(out, "driver_version : %s\n", version); out += sprintf(out, "model : %s\n", (spca50x->desc) ? clist[spca50x->desc].description : "unknown"); out += sprintf(out, "streaming : %s\n", YES_NO(spca50x->streaming)); out += sprintf(out, "grabbing : %s\n", YES_NO(spca50x->grabbing)); out += sprintf(out, "compress : %s\n", YES_NO(spca50x->compress)); out += sprintf(out, "data_format : %s\n", spca50x->force_rgb ? "RGB" : "BGR"); out += sprintf(out, "brightness : %d\n", spca50x->brightness >> 8); out += sprintf(out, "colour : %d\n", spca50x->colour >> 8); out += sprintf(out, "hue : %d\n", spca50x->hue >> 8); out += sprintf(out, "contrast : %d\n", spca50x->contrast); out += sprintf(out, "num_frames : %d\n", SPCA50X_NUMFRAMES); out += sprintf(out, "curframe : %d\n", spca50x->curframe); out += sprintf(out, "lastFrameRead : %d\n", spca50x->lastFrameRead); spca50x->avg_lum = get_avg_lum(spca50x); out += sprintf(out, "Avg. luminance : 0x%X %d\n", spca50x->avg_lum, spca50x->avg_lum); for (i = 0; i < SPCA50X_NUMFRAMES; i++) { out += sprintf(out, "frame : %d\n", i); out += sprintf(out, " sequence : %d\n", spca50x->frame[i].seq); out += sprintf(out, " grabstate : %d\n", spca50x->frame[i].grabstate); out += sprintf(out, " depth : %d\n", spca50x->frame[i].depth); out += sprintf(out, " size : %d %d\n", spca50x->frame[i].width, spca50x->frame[i].height); out += sprintf(out, " format : "); for (j = 0; plist[j].num >= 0; j++) { if (plist[j].num == spca50x->frame[i].format) { out += sprintf(out, "%s\n", plist[j].name); break; } } if (plist[j].num < 0) out += sprintf(out, "unknown\n"); out += sprintf(out, " data_buffer : 0x%p\n", spca50x->frame[i].data); } out += sprintf(out, "packet_size : %d\n", spca50x->packet_size); out += sprintf(out, "framebuffer : 0x%p\n", spca50x->fbuf);#ifdef SPCA50X_ENABLE_EXPERIMENTAL out += sprintf(out, "stable : %d\n", spca50x->nstable); out += sprintf(out, "unstable : %d\n", spca50x->nunstable); out += sprintf(out, "whiteness : %d\n", spca50x->whiteness >> 12); spca50x->avg_rg = get_avg_RG(spca50x); spca50x->avg_bg = get_avg_BG(spca50x); out += sprintf(out, "Avg. R-G/B-G : 0x%X/0x%X %d/%d\n", spca50x->avg_rg, spca50x->avg_bg, (char) spca50x->avg_rg, (char) spca50x->avg_bg);#endif /* SPCA50X_ENABLE_EXPERIMENTAL */ len = out - page; len -= off; if (len < count) { *eof = 1; if (len <= 0) return 0; } else len = count; *start = page + off; return len;}static intspca50x_write_proc(struct file *file, const char *buffer, unsigned long count, void *data){ return -EINVAL;}/* * Function services read requests to control proc entry * and prints all the static variables */static intspca50x_ctlread_proc(char *page, char **start, off_t off, int count, int *eof, void *data){ char *out = page; int len = 0; struct usb_spca50x *spca50x = data; out += sprintf(out, "force_rgb = %d\n", spca50x->force_rgb); out += sprintf(out, "min_bpp = %d\n", spca50x->min_bpp); out += sprintf(out, "lum_level = %d\n", spca50x->lum_level); out += sprintf(out, "debug = %d\n", debug); len = out - page; len -= off; if (len < count) { *eof = 1; if (len <= 0) return 0; } else len = count; *start = page + off; return len;}/* * Function compares two strings. * Return offset in pussy where prick ends if "prick" may penetrate * int "pussy" like prick into pussy, -1 otherwise. */static inline int match(const char *prick, const char *pussy, int len2){ int len1 = strlen(prick); //length of male string int i; //just an index variable const char *tmp; //temporary pointer for my own pleasure // We skip all spaces and tabs for (i = 0; i < len2 && (pussy[i] == ' ' || pussy[i] == '\t'); i++) { } tmp = pussy + i; // pointer to pussy with skipped shit (spaces and tabs) len2 = strlen(tmp); //calculate length again if (len1 > len2) return -1; //Fuck off, no fucking if (!strncmp(prick, tmp, len1)) return i + len1; return -1;}/* * Try to calculate value from string (atoi). Converts * decimal integer */static inline int atoi(const char *str){ int result = 0; //result of the function int i; //just an index variable for (i = 0; str[i] >= '0' && str[i] <= '9'; i++) { result *= 10; result += str[i] - '0'; } return result;}static intspca50x_ctlwrite_proc(struct file *file, const char *buffer, unsigned long count, void *data){ int off; //where look for a value struct usb_spca50x *spca50x = data; if ((off = match("lum_level=", buffer, count)) >= 0) spca50x->lum_level = atoi(buffer + off); if ((off = match("min_bpp=", buffer, count)) >= 0) spca50x->min_bpp = atoi(buffer + off); if ((off = match("force_rgb=", buffer, count)) >= 0) spca50x->force_rgb = atoi(buffer + off); if ((off = match("debug=", buffer, count)) >= 0) debug = atoi(buffer + off); return count;}static void create_proc_spca50x_cam(struct usb_spca50x *spca50x){ char name[PROC_NAME_LEN]; struct proc_dir_entry *ent; if (!spca50x_proc_entry || !spca50x) return;//Create videoxx proc entry sprintf(name, "video%d", spca50x->vdev->minor); PDEBUG(4, "creating /proc/video/spca50x/%s", name); ent = create_proc_entry(name, S_IFREG | S_IRUGO | S_IWUSR, spca50x_proc_entry); if (!ent) return; ent->data = spca50x; ent->read_proc = spca50x_read_proc; ent->write_proc = spca50x_write_proc; spca50x->proc_entry = ent;// Create the controlxx proc entry sprintf(name, "control%d", spca50x->vdev->minor); PDEBUG(4, "creating /proc/video/spca50x/%s", name); ent = create_proc_entry(name, S_IFREG | S_IRUGO | S_IWUSR, spca50x_proc_entry); if (!ent) return; ent->data = spca50x; ent->read_proc = spca50x_ctlread_proc; ent->write_proc = spca50x_ctlwrite_proc; spca50x->ctl_proc_entry = ent;}static void destroy_proc_spca50x_cam(struct usb_spca50x *spca50x){ char name[PROC_NAME_LEN]; if (!spca50x || !spca50x_proc_entry) return; /* destroy videoxx proc entry */ if (spca50x->proc_entry != NULL) { sprintf(name, "video%d", spca50x->vdev->minor); PDEBUG(4, "destroying %s", name); remove_proc_entry(name, spca50x_proc_entry); spca50x->proc_entry = NULL; } /* destroy controlxx proc entry */ if (spca50x->ctl_proc_entry != NULL) { sprintf(name, "control%d", spca50x->vdev->minor); PDEBUG(4, "destroying %s", name); remove_proc_entry(name, spca50x_proc_entry); spca50x->ctl_proc_entry = NULL; }}static void proc_spca50x_create(void){ /* No current standard here. Alan prefers /proc/video/ as it keeps * /proc "less cluttered than /proc/randomcardifoundintheshed/" * -claudio */#ifdef CONFIG_VIDEO_PROC_FS if (video_proc_entry == NULL) { err("Unable to initialise /proc/video/spca50x"); return; } spca50x_proc_entry = create_proc_entry("spca50x", S_IFDIR, video_proc_entry);#else /* CONFIG_VIDEO_PROC_FS */ spca50x_proc_entry = create_proc_entry("spca50x", S_IFDIR, 0);#endif /* CONFIG_VIDEO_PROC_FS */#if LINUX_VERSION_CODE > KERNEL_VERSION(2,3,0) if (spca50x_proc_entry) spca50x_proc_entry->owner = THIS_MODULE; else#ifdef CONFIG_VIDEO_PROC_FS err("Unable to initialise /proc/video/spca50x");#else /* CONFIG_VIDEO_PROC_FS */ err("Unable to initialise /proc/spca50x");#endif /* CONFIG_VIDEO_PROC_FS */#endif /* LINUX_VERSION_CODE > KERNEL_VERSION(2,3,0) */}static void proc_spca50x_destroy(void){#ifdef CONFIG_VIDEO_PROC_FS PDEBUG(3, "removing /proc/video/spca50x");#else /* CONFIG_VIDEO_PROC_FS */ PDEBUG(3, "removing /proc/spca50x");#endif /* CONFIG_VIDEO_PROC_FS */ if (spca50x_proc_entry == NULL) return;#ifdef CONFIG_VIDEO_PROC_FS remove_proc_entry("spca50x", video_proc_entry);#else /* CONFIG_VIDEO_PROC_FS */ remove_proc_entry("spca50x", 0);#endif /* CONFIG_VIDEO_PROC_FS */}#endif /* CONFIG_PROC_FS */static int spca50x_set_packet_size(struct usb_spca50x *spca50x, int size){ int alt; /**********************************************************************/ /******** Try to find real Packet size from usb struct ****************/ struct usb_device *dev = spca50x->dev;#if LINUX_VERSION_CODE < KERNEL_VERSION(2,5,0) struct usb_interface_descriptor *interface = NULL; struct usb_config_descriptor *config = dev->actconfig;#else struct usb_host_interface *interface = NULL; struct usb_interface *intf;#endif int mysize = 0; int ep = 0; /**********************************************************************/ if (size == 0) alt = SPCA50X_ALT_SIZE_0; else if (size == 128) alt = SPCA50X_ALT_SIZE_128; else if (size == 256) alt = SPCA50X_ALT_SIZE_256; else if (size == 384) alt = SPCA50X_ALT_SIZE_384; else if (size == 512) alt = SPCA50X_ALT_SIZE_512; else if (size == 640) alt = SPCA50X_ALT_SIZE_640; else if (size == 768) alt = SPCA50X_ALT_SIZE_768; else if (size == 896) alt = SPCA50X_ALT_SIZE_896; else if (size == 1000) alt = ETOMS_ALT_SIZE_1000; else if (size == 1023) if (spca50x->bridge == BRIDGE_SONIX || spca50x->bridge == BRIDGE_SN9CXXX || spca50x->bridge == BRIDGE_MR97311 || spca50x->bridge == BRIDGE_PAC207) { alt = 8; } else { alt = SPCA50X_ALT_SIZE_1023; } else { /* if an unrecognised size, default to the minimum */ PDEBUG(5, "Set packet size: invalid size (%d), defaulting to %d", size, SPCA50X_ALT_SIZE_128); alt = SPCA50X_ALT_SIZE_128; } PDEBUG(5, "iface alt size: %d %d %d", spca50x->iface, alt, size); if (usb_set_interface(spca50x->dev, spca50x->iface, alt) < 0) { err("Set packet size: set interface error"); return -EBUSY; } /* check endpoint */ if (spca50x->bridge == BRIDGE_PAC207) { ep = PAC207_ENDPOINT_ADDRESS - 1; } else { ep = SPCA50X_ENDPOINT_ADDRESS - 1; }#if LINUX_VERSION_CODE > KERNEL_VERSION(2,6,3) intf = usb_ifnum_to_if(dev, spca50x->iface); if (intf) { interface = usb_altnum_to_altsetting(intf, alt); } else { PDEBUG(0, "intf not found"); return -ENXIO; }#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,11) mysize = le16_to_cpu(interface->endpoint[ep].desc.wMaxPacketSize);#else mysize = (interface->endpoint[ep].desc.wMaxPacketSize);#endif#else interface = &config->interface[spca50x->iface].altsetting[alt];#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,11) mysize = le16_to_cpu(interface->endpoint[ep].wMaxPacketSize);#else mysize = (interface->endpoint[ep].wMaxPacketSize);#endif#endif spca50x->packet_size = mysize & 0x03ff; spca50x->alt = alt; PDEBUG(1, "set real packet size: %d, alt=%d", mysize, alt); return 0;}/* Returns number of bits per pixel (regardless of where they are located; planar or * not), or zero for unsupported format. */static int spca5xx_get_depth(struct usb_spca50x *spca50x, int palette){ switch (palette) {// case VIDEO_PALETTE_GREY: return 8; case VIDEO_PALETTE_RGB565: return 16; case VIDEO_PALETTE_RGB24: return 24;// case VIDEO_PALETTE_YUV422: return 16; // case VIDEO_PALETTE_YUYV:// return 16;// case VIDEO_PALETTE_YUV420: return 24; case VIDEO_PALETTE_YUV420P: return 12; /* strange need 12 this break the read method for this planar mode (6*8/4) */// case VIDEO_PALETTE_YUV422P: return 24; /* Planar */ case VIDEO_PALETTE_RGB32: return 32; case VIDEO_PALETTE_RAW_JPEG: return 24; /* raw jpeg. what should we return ?? */ case VIDEO_PALETTE_JPEG: if (spca50x->cameratype == JPEG || spca50x->cameratype == JPGH || spca50x->cameratype == JPGC || spca50x->cameratype == JPGS || spca50x->cameratype == JPGM) { return 8;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -