static inline int v4l1_probe_formats (zbar_video_t *vdo) { struct video_picture vpic; memset(&vpic, 0, sizeof(vpic)); if(v4l1_ioctl(vdo->fd, VIDIOCGPICT, &vpic) < 0) return(err_capture(vdo, SEV_ERROR, ZBAR_ERR_SYSTEM, __func__, "querying format (VIDIOCGPICT)")); vdo->format = 0; if(vpic.palette <= VIDEO_PALETTE_YUV410P) vdo->format = v4l1_formats[vpic.palette].format; zprintf(1, "current format: %.4s(%08x) depth=%d palette=%d\n", (char*)&vdo->format, vdo->format, vpic.depth, vpic.palette); vdo->formats = calloc(16, sizeof(uint32_t)); if(!vdo->formats) return(err_capture(vdo, SEV_FATAL, ZBAR_ERR_NOMEM, __func__, "allocating format list")); int num_formats = 0; zprintf(2, "probing supported formats:\n"); int i; for(i = 1; i <= VIDEO_PALETTE_YUV410P; i++) { if(!v4l1_formats[i].format) continue; vpic.depth = v4l1_formats[i].bpp; vpic.palette = i; if(v4l1_ioctl(vdo->fd, VIDIOCSPICT, &vpic) < 0) { zprintf(2, " [%02d] %.4s...no (set fails)\n", i, (char*)&v4l1_formats[i].format); continue; } if(v4l1_ioctl(vdo->fd, VIDIOCGPICT, &vpic) < 0 || vpic.palette != i) { zprintf(2, " [%02d] %.4s...no (set ignored)\n", i, (char*)&v4l1_formats[i].format); continue; } zprintf(2, " [%02d] %.4s...yes\n", i, (char*)&v4l1_formats[i].format); vdo->formats[num_formats++] = v4l1_formats[i].format; } vdo->formats = realloc(vdo->formats, (num_formats + 1) * sizeof(uint32_t)); assert(vdo->formats); return(v4l1_set_format(vdo, vdo->format)); }
SANE_Status sane_get_parameters (SANE_Handle handle, SANE_Parameters * params) { V4L_Scanner *s = handle; DBG (4, "sane_get_parameters\n"); update_parameters (s); if (params == 0) { DBG (1, "sane_get_parameters: params == 0\n"); return SANE_STATUS_INVAL; } if (-1 == v4l1_ioctl (s->fd, VIDIOCGWIN, &s->window)) { DBG (1, "sane_control_option: ioctl VIDIOCGWIN failed " "(can not get window geometry)\n"); return SANE_STATUS_INVAL; } parms.pixels_per_line = s->window.width; parms.bytes_per_line = s->window.width; if (parms.format == SANE_FRAME_RGB) parms.bytes_per_line = s->window.width * 3; parms.lines = s->window.height; *params = parms; return SANE_STATUS_GOOD; }
static inline int v4l1_init_window (zbar_video_t *vdo) { struct video_window vwin; memset(&vwin, 0, sizeof(vwin)); if(v4l1_ioctl(vdo->fd, VIDIOCGWIN, &vwin) < 0) return(err_capture(vdo, SEV_ERROR, ZBAR_ERR_SYSTEM, __func__, "querying video window settings (VIDIOCGWIN)")); zprintf(1, "current window: %d x %d @(%d, %d)%s\n", vwin.width, vwin.height, vwin.x, vwin.y, (vwin.flags & 1) ? " INTERLACE" : ""); if(vwin.width == vdo->width && vwin.height == vdo->height) /* max window already set */ return(0); struct video_window maxwin; memcpy(&maxwin, &vwin, sizeof(maxwin)); maxwin.width = vdo->width; maxwin.height = vdo->height; zprintf(1, "setting max win: %d x %d @(%d, %d)%s\n", maxwin.width, maxwin.height, maxwin.x, maxwin.y, (maxwin.flags & 1) ? " INTERLACE" : ""); if(v4l1_ioctl(vdo->fd, VIDIOCSWIN, &maxwin) < 0) { zprintf(1, "set FAILED...trying to recover original window\n"); /* ignore errors (driver broken anyway) */ v4l1_ioctl(vdo->fd, VIDIOCSWIN, &vwin); } /* re-query resulting parameters */ memset(&vwin, 0, sizeof(vwin)); if(v4l1_ioctl(vdo->fd, VIDIOCGWIN, &vwin) < 0) return(err_capture(vdo, SEV_ERROR, ZBAR_ERR_SYSTEM, __func__, "querying video window settings (VIDIOCGWIN)")); zprintf(1, " final window: %d x %d @(%d, %d)%s\n", vwin.width, vwin.height, vwin.x, vwin.y, (vwin.flags & 1) ? " INTERLACE" : ""); vdo->width = vwin.width; vdo->height = vwin.height; return(0); }
LIBV4L_PUBLIC int ioctl(int fd, unsigned long int request, ...) #endif { void *arg; va_list ap; va_start(ap, request); arg = va_arg(ap, void *); va_end(ap); return v4l1_ioctl(fd, request, arg); }
int my_ioctl(unsigned long int req, void* arg) { switch (camDriver) { case DRIVER_V4L: // printf("v4l driver is using..\n"); return ioctl(fd, req, arg); break; case DRIVER_V4L2: // printf("v4l2 driver is using..\n"); return v4l1_ioctl(fd, req, arg); break; default: printf("Neither v4l nor v4l2 is using..\n"); return -1; break; } return -1; }
static int v4l1_probe_iomode (zbar_video_t *vdo) { vdo->iomode = VIDEO_READWRITE; #ifdef HAVE_SYS_MMAN_H struct video_mbuf vbuf; memset(&vbuf, 0, sizeof(vbuf)); if(v4l1_ioctl(vdo->fd, VIDIOCGMBUF, &vbuf) < 0) { if(errno != EINVAL) return(err_capture(vdo, SEV_ERROR, ZBAR_ERR_SYSTEM, __func__, "querying video frame buffers (VIDIOCGMBUF)")); /* not supported */ return(0); } if(!vbuf.frames || !vbuf.size) return(0); vdo->iomode = VIDEO_MMAP; if(vdo->num_images > vbuf.frames) vdo->num_images = vbuf.frames; #endif zprintf(1, "using %d images in %s mode\n", vdo->num_images, (vdo->iomode == VIDEO_READWRITE) ? "READ" : "MMAP"); return(0); }
int _zbar_v4l1_probe (zbar_video_t *vdo) { /* check capabilities */ struct video_capability vcap; memset(&vcap, 0, sizeof(vcap)); if(v4l1_ioctl(vdo->fd, VIDIOCGCAP, &vcap) < 0) return(err_capture(vdo, SEV_ERROR, ZBAR_ERR_UNSUPPORTED, __func__, "video4linux version 1 not supported (VIDIOCGCAP)")); zprintf(1, "%s (%sCAPTURE) (%d x %d) - (%d x %d)\n", vcap.name, (vcap.type & VID_TYPE_CAPTURE) ? "" : "*NO* ", vcap.minwidth, vcap.minheight, vcap.maxwidth, vcap.maxheight); if(!(vcap.type & VID_TYPE_CAPTURE)) return(err_capture(vdo, SEV_ERROR, ZBAR_ERR_UNSUPPORTED, __func__, "v4l1 device does not support CAPTURE")); if(!vdo->width || !vdo->height) { vdo->width = vcap.maxwidth; vdo->height = vcap.maxheight; } if(v4l1_init_window(vdo) || v4l1_probe_formats(vdo) || v4l1_probe_iomode(vdo)) return(-1); vdo->intf = VIDEO_V4L1; vdo->init = v4l1_init; vdo->cleanup = v4l1_cleanup; vdo->start = v4l1_start; vdo->stop = v4l1_stop; vdo->nq = v4l1_nq; vdo->dq = v4l1_dq; return(0); }
SANE_Status sane_start (SANE_Handle handle) { int len, loop; V4L_Scanner *s; char data; DBG (2, "sane_start\n"); for (s = first_handle; s; s = s->next) { if (s == handle) break; } if (!s) { DBG (1, "sane_start: bad handle %p\n", handle); return SANE_STATUS_INVAL; /* oops, not a handle we know about */ } len = v4l1_ioctl (s->fd, VIDIOCGCAP, &s->capability); if (-1 == len) { DBG (1, "sane_start: can not get capabilities\n"); return SANE_STATUS_INVAL; } s->buffercount = 0; if (-1 == v4l1_ioctl (s->fd, VIDIOCGMBUF, &s->mbuf)) { s->is_mmap = SANE_FALSE; buffer = malloc (s->capability.maxwidth * s->capability.maxheight * s->pict.depth); if (0 == buffer) return SANE_STATUS_NO_MEM; DBG (3, "sane_start: V4L trying to read frame\n"); len = v4l1_read (s->fd, buffer, parms.bytes_per_line * parms.lines); DBG (3, "sane_start: %d bytes read\n", len); } else { s->is_mmap = SANE_TRUE; DBG (3, "sane_start: mmap frame, buffersize: %d bytes, buffers: %d, offset 0 %d\n", s->mbuf.size, s->mbuf.frames, s->mbuf.offsets[0]); buffer = v4l1_mmap (0, s->mbuf.size, PROT_READ | PROT_WRITE, MAP_SHARED, s->fd, 0); if (buffer == (void *)-1) { DBG (1, "sane_start: mmap failed: %s\n", strerror (errno)); buffer = NULL; return SANE_STATUS_IO_ERROR; } DBG (3, "sane_start: mmapped frame, capture 1 pict into %p\n", buffer); s->mmap.frame = 0; s->mmap.width = s->window.width; /* s->mmap.width = parms.pixels_per_line; ??? huh? */ s->mmap.height = s->window.height; /* s->mmap.height = parms.lines; ??? huh? */ s->mmap.format = s->pict.palette; DBG (2, "sane_start: mmapped frame %d x %d with palette %d\n", s->mmap.width, s->mmap.height, s->mmap.format); /* We need to loop here to empty the read buffers, so we don't get a stale image */ for (loop = 0; loop <= s->mbuf.frames; loop++) { len = v4l1_ioctl (s->fd, VIDIOCMCAPTURE, &s->mmap); if (len == -1) { DBG (1, "sane_start: ioctl VIDIOCMCAPTURE failed: %s\n", strerror (errno)); return SANE_STATUS_INVAL; } DBG (3, "sane_start: waiting for frame %x, loop %d\n", s->mmap.frame, loop); len = v4l1_ioctl (s->fd, VIDIOCSYNC, &(s->mmap.frame)); if (-1 == len) { DBG (1, "sane_start: call to ioctl(%d, VIDIOCSYNC, ..) failed\n", s->fd); return SANE_STATUS_INVAL; } } DBG (3, "sane_start: frame %x done\n", s->mmap.frame); } /* v4l1 actually returns BGR when we ask for RGB, so convert it */ if (s->pict.palette == VIDEO_PALETTE_RGB24) { DBG (3, "sane_start: converting from BGR to RGB\n"); for (loop = 0; loop < (s->window.width * s->window.height * 3); loop += 3) { data = *(buffer + loop); *(buffer + loop) = *(buffer + loop + 2); *(buffer + loop + 2) = data; } } DBG (3, "sane_start: done\n"); return SANE_STATUS_GOOD; }
SANE_Status sane_control_option (SANE_Handle handle, SANE_Int option, SANE_Action action, void *val, SANE_Int * info) { V4L_Scanner *s = handle; SANE_Status status; SANE_Word cap; if (info) *info = 0; if (option >= NUM_OPTIONS || option < 0) return SANE_STATUS_INVAL; DBG (4, "sane_control_option: %s option %d (%s)\n", action == SANE_ACTION_GET_VALUE ? "get" : action == SANE_ACTION_SET_VALUE ? "set" : action == SANE_ACTION_SET_AUTO ? "auto set" : "(unknow action with)", option, s->opt[option].name ? s->opt[option].name : s->opt[option].title); cap = s->opt[option].cap; if (!SANE_OPTION_IS_ACTIVE (cap)) { DBG (1, "sane_control option: option is inactive\n"); return SANE_STATUS_INVAL; } if (action == SANE_ACTION_GET_VALUE) { switch (option) { /* word options: */ case OPT_NUM_OPTS: case OPT_TL_X: case OPT_TL_Y: case OPT_BR_X: case OPT_BR_Y: case OPT_BRIGHTNESS: case OPT_HUE: case OPT_COLOR: case OPT_CONTRAST: case OPT_WHITE_LEVEL: *(SANE_Word *) val = s->val[option].w; return SANE_STATUS_GOOD; case OPT_CHANNEL: /* string list options */ case OPT_MODE: strcpy (val, s->val[option].s); return SANE_STATUS_GOOD; default: DBG (1, "sane_control_option: option %d unknown\n", option); } } else if (action == SANE_ACTION_SET_VALUE) { if (!SANE_OPTION_IS_SETTABLE (cap)) { DBG (1, "sane_control_option: option is not settable\n"); return SANE_STATUS_INVAL; } status = sanei_constrain_value (s->opt + option, val, info); if (status != SANE_STATUS_GOOD) { DBG (1, "sane_control_option: sanei_constarin_value failed: %s\n", sane_strstatus (status)); return status; } if (option >= OPT_TL_X && option <= OPT_BR_Y) { s->user_corner |= 1 << (option - OPT_TL_X); if (-1 == v4l1_ioctl (s->fd, VIDIOCGWIN, &s->window)) { DBG (1, "sane_control_option: ioctl VIDIOCGWIN failed " "(can not get window geometry)\n"); return SANE_STATUS_INVAL; } s->window.clipcount = 0; s->window.clips = 0; s->window.height = parms.lines; s->window.width = parms.pixels_per_line; } switch (option) { /* (mostly) side-effect-free word options: */ case OPT_TL_X: break; case OPT_TL_Y: break; case OPT_BR_X: s->window.width = *(SANE_Word *) val; parms.pixels_per_line = *(SANE_Word *) val; if (info) *info |= SANE_INFO_RELOAD_PARAMS; break; case OPT_BR_Y: s->window.height = *(SANE_Word *) val; parms.lines = *(SANE_Word *) val; if (info) *info |= SANE_INFO_RELOAD_PARAMS; break; case OPT_MODE: if (info) *info |= SANE_INFO_RELOAD_PARAMS | SANE_INFO_RELOAD_OPTIONS; s->val[option].s = strdup (val); if (!s->val[option].s) return SANE_STATUS_NO_MEM; if (strcmp (s->val[option].s, SANE_VALUE_SCAN_MODE_GRAY) == 0) s->pict.palette = VIDEO_PALETTE_GREY; else s->pict.palette = VIDEO_PALETTE_RGB24; update_parameters (s); break; case OPT_BRIGHTNESS: s->pict.brightness = *(SANE_Word *) val *256; s->val[option].w = *(SANE_Word *) val; break; case OPT_HUE: s->pict.hue = *(SANE_Word *) val *256; s->val[option].w = *(SANE_Word *) val; break; case OPT_COLOR: s->pict.colour = *(SANE_Word *) val *256; s->val[option].w = *(SANE_Word *) val; break; case OPT_CONTRAST: s->pict.contrast = *(SANE_Word *) val *256; s->val[option].w = *(SANE_Word *) val; break; case OPT_WHITE_LEVEL: s->pict.whiteness = *(SANE_Word *) val *256; s->val[option].w = *(SANE_Word *) val; break; case OPT_CHANNEL: { int i; struct video_channel channel; s->val[option].s = strdup (val); if (!s->val[option].s) return SANE_STATUS_NO_MEM; for (i = 0; i < MAX_CHANNELS; i++) { if (strcmp (s->channel[i], val) == 0) { channel.channel = i; if (-1 == v4l1_ioctl (s->fd, VIDIOCGCHAN, &channel)) { DBG (1, "sane_open: can't ioctl VIDIOCGCHAN %s: %s\n", s->devicename, strerror (errno)); return SANE_STATUS_INVAL; } if (-1 == v4l1_ioctl (s->fd, VIDIOCSCHAN, &channel)) { DBG (1, "sane_open: can't ioctl VIDIOCSCHAN %s: %s\n", s->devicename, strerror (errno)); return SANE_STATUS_INVAL; } break; } } return SANE_STATUS_GOOD; break; } default: DBG (1, "sane_control_option: option %d unknown\n", option); return SANE_STATUS_INVAL; } if (option >= OPT_TL_X && option <= OPT_BR_Y) { if (-1 == v4l1_ioctl (s->fd, VIDIOCSWIN, &s->window)) { DBG (1, "sane_control_option: ioctl VIDIOCSWIN failed (%s)\n", strerror (errno)); /* return SANE_STATUS_INVAL; */ } if (-1 == v4l1_ioctl (s->fd, VIDIOCGWIN, &s->window)) { DBG (1, "sane_control_option: ioctl VIDIOCGWIN failed (%s)\n", strerror (errno)); return SANE_STATUS_INVAL; } } if (option >= OPT_BRIGHTNESS && option <= OPT_WHITE_LEVEL) { if (-1 == v4l1_ioctl (s->fd, VIDIOCSPICT, &s->pict)) { DBG (1, "sane_control_option: ioctl VIDIOCSPICT failed (%s)\n", strerror (errno)); /* return SANE_STATUS_INVAL; */ } } return SANE_STATUS_GOOD; } else if (action == SANE_ACTION_SET_AUTO) { if (!(cap & SANE_CAP_AUTOMATIC)) { DBG (1, "sane_control_option: option can't be set automatically\n"); return SANE_STATUS_INVAL; } switch (option) { case OPT_BRIGHTNESS: /* not implemented yet */ return SANE_STATUS_GOOD; default: break; } } return SANE_STATUS_INVAL; }
SANE_Status sane_open (SANE_String_Const devname, SANE_Handle * handle) { V4L_Device *dev; V4L_Scanner *s; static int v4lfd; int i; struct video_channel channel; SANE_Status status; int max_channels = MAX_CHANNELS; if (!devname) { DBG (1, "sane_open: devname == 0\n"); return SANE_STATUS_INVAL; } for (dev = first_dev; dev; dev = dev->next) if (strcmp (dev->sane.name, devname) == 0) { DBG (5, "sane_open: device %s found in devlist\n", devname); break; } if (!devname[0]) dev = first_dev; if (!dev) { DBG (1, "sane_open: device %s doesn't seem to be a v4l " "device\n", devname); return SANE_STATUS_INVAL; } v4lfd = v4l1_open (devname, O_RDWR); if (v4lfd == -1) { DBG (1, "sane_open: can't open %s (%s)\n", devname, strerror (errno)); return SANE_STATUS_INVAL; } s = malloc (sizeof (*s)); if (!s) return SANE_STATUS_NO_MEM; memset (s, 0, sizeof (*s)); s->user_corner = 0; /* ??? */ s->devicename = devname; s->fd = v4lfd; if (v4l1_ioctl (s->fd, VIDIOCGCAP, &s->capability) == -1) { DBG (1, "sane_open: ioctl (%d, VIDIOCGCAP,..) failed on `%s': %s\n", s->fd, devname, strerror (errno)); v4l1_close (s->fd); return SANE_STATUS_INVAL; } DBG (5, "sane_open: %d channels, %d audio devices\n", s->capability.channels, s->capability.audios); DBG (5, "sane_open: minwidth=%d, minheight=%d, maxwidth=%d, " "maxheight=%d\n", s->capability.minwidth, s->capability.minheight, s->capability.maxwidth, s->capability.maxheight); if (VID_TYPE_CAPTURE & s->capability.type) DBG (5, "sane_open: V4L device can capture to memory\n"); if (VID_TYPE_TUNER & s->capability.type) DBG (5, "sane_open: V4L device has a tuner of some form\n"); if (VID_TYPE_TELETEXT & s->capability.type) DBG (5, "sane_open: V4L device supports teletext\n"); if (VID_TYPE_OVERLAY & s->capability.type) DBG (5, "sane_open: V4L device can overlay its image onto the frame " "buffer\n"); if (VID_TYPE_CHROMAKEY & s->capability.type) DBG (5, "sane_open: V4L device uses chromakey on overlay\n"); if (VID_TYPE_CLIPPING & s->capability.type) DBG (5, "sane_open: V4L device supports overlay clipping\n"); if (VID_TYPE_FRAMERAM & s->capability.type) DBG (5, "sane_open: V4L device overwrites frame buffer memory\n"); if (VID_TYPE_SCALES & s->capability.type) DBG (5, "sane_open: V4L device supports hardware scaling\n"); if (VID_TYPE_MONOCHROME & s->capability.type) DBG (5, "sane_open: V4L device is grey scale only\n"); if (VID_TYPE_SUBCAPTURE & s->capability.type) DBG (5, "sane_open: V4L device can capture parts of the image\n"); if (s->capability.channels < max_channels) max_channels = s->capability.channels; for (i = 0; i < max_channels; i++) { channel.channel = i; if (-1 == v4l1_ioctl (v4lfd, VIDIOCGCHAN, &channel)) { DBG (1, "sane_open: can't ioctl VIDIOCGCHAN %s: %s\n", devname, strerror (errno)); return SANE_STATUS_INVAL; } DBG (5, "sane_open: channel %d (%s), tuners=%d, flags=0x%x, " "type=%d, norm=%d\n", channel.channel, channel.name, channel.tuners, channel.flags, channel.type, channel.norm); if (VIDEO_VC_TUNER & channel.flags) DBG (5, "sane_open: channel has tuner(s)\n"); if (VIDEO_VC_AUDIO & channel.flags) DBG (5, "sane_open: channel has audio\n"); if (VIDEO_TYPE_TV == channel.type) DBG (5, "sane_open: input is TV input\n"); if (VIDEO_TYPE_CAMERA == channel.type) DBG (5, "sane_open: input is camera input\n"); s->channel[i] = strdup (channel.name); if (!s->channel[i]) return SANE_STATUS_NO_MEM; } s->channel[i] = 0; if (-1 == v4l1_ioctl (v4lfd, VIDIOCGPICT, &s->pict)) { DBG (1, "sane_open: can't ioctl VIDIOCGPICT %s: %s\n", devname, strerror (errno)); return SANE_STATUS_INVAL; } DBG (5, "sane_open: brightness=%d, hue=%d, colour=%d, contrast=%d\n", s->pict.brightness, s->pict.hue, s->pict.colour, s->pict.contrast); DBG (5, "sane_open: whiteness=%d, depth=%d, palette=%d\n", s->pict.whiteness, s->pict.depth, s->pict.palette); /* ??? */ s->pict.palette = VIDEO_PALETTE_GREY; if (-1 == v4l1_ioctl (s->fd, VIDIOCSPICT, &s->pict)) { DBG (1, "sane_open: ioctl VIDIOCSPICT failed (%s)\n", strerror (errno)); } if (-1 == v4l1_ioctl (s->fd, VIDIOCGWIN, &s->window)) { DBG (1, "sane_open: can't ioctl VIDIOCGWIN %s: %s\n", devname, strerror (errno)); return SANE_STATUS_INVAL; } DBG (5, "sane_open: x=%d, y=%d, width=%d, height=%d\n", s->window.x, s->window.y, s->window.width, s->window.height); /* already done in sane_start if (-1 == v4l1_ioctl (v4lfd, VIDIOCGMBUF, &mbuf)) DBG (1, "sane_open: can't ioctl VIDIOCGMBUF (no Fbuffer?)\n"); */ status = init_options (s); if (status != SANE_STATUS_GOOD) return status; update_parameters (s); /* insert newly opened handle into list of open handles: */ s->next = first_handle; first_handle = s; *handle = s; return SANE_STATUS_GOOD; }
static SANE_Status attach (const char *devname, V4L_Device ** devp) { V4L_Device *dev; static int v4lfd; static struct video_capability capability; errno = 0; for (dev = first_dev; dev; dev = dev->next) if (strcmp (dev->sane.name, devname) == 0) { if (devp) *devp = dev; DBG (5, "attach: device %s is already known\n", devname); return SANE_STATUS_GOOD; } DBG (3, "attach: trying to open %s\n", devname); v4lfd = v4l1_open (devname, O_RDWR); if (v4lfd != -1) { if (v4l1_ioctl (v4lfd, VIDIOCGCAP, &capability) == -1) { DBG (1, "attach: ioctl (%d, VIDIOCGCAP,..) failed on `%s': %s\n", v4lfd, devname, strerror (errno)); v4l1_close (v4lfd); return SANE_STATUS_INVAL; } if (!(VID_TYPE_CAPTURE & capability.type)) { DBG (1, "attach: device %s can't capture to memory -- exiting\n", devname); v4l1_close (v4lfd); return SANE_STATUS_UNSUPPORTED; } DBG (2, "attach: found videodev `%s' on `%s'\n", capability.name, devname); v4l1_close (v4lfd); } else { DBG (1, "attach: failed to open device `%s': %s\n", devname, strerror (errno)); return SANE_STATUS_INVAL; } dev = malloc (sizeof (*dev)); if (!dev) return SANE_STATUS_NO_MEM; memset (dev, 0, sizeof (*dev)); dev->sane.name = strdup (devname); if (!dev->sane.name) return SANE_STATUS_NO_MEM; dev->sane.vendor = "Noname"; dev->sane.model = strdup (capability.name); if (!dev->sane.model) return SANE_STATUS_NO_MEM; dev->sane.type = "virtual device"; ++num_devices; dev->next = first_dev; first_dev = dev; if (devp) *devp = dev; return SANE_STATUS_GOOD; }
int main(int argc, char** argv) { if(argc == 2) { strcpy(my_video_dev, argv[1]); } else { strcpy(my_video_dev, "/dev/video0"); } //if (-1 == (fd = open(my_video_dev, O_RDWR))) { if (-1 == (fd = v4l1_open(my_video_dev, O_RDWR))) { printf("Error opening device: %s\n", my_video_dev); goto error; } printf("\n -----[ VIDIOCGCAP returns ]-----\n"); printf(" name: %s\n", capability.name); printf(" type: %i\n", capability.type); printf(" channels: %i\n", capability.channels); printf(" audios: %i\n", capability.audios); printf(" maxwidth: %i\n", capability.maxwidth); printf(" maxheight: %i\n", capability.maxheight); printf(" minwidth: %i\n", capability.minwidth); printf(" minheight: %i\n", capability.minheight); if (-1 == v4l1_ioctl(fd, VIDIOCGPICT,&picture)) { printf("Error: ioctl(fd,VIDIOCGCPICT,&picture)\n"); goto error; } printf("\n -----[ VIDIOCGPICT returns ]-----\n"); printf(" brightness: %i\n", picture.brightness); printf(" hue: %i\n", picture.hue); printf(" colour: %i\n", picture.colour); printf(" contrast: %i\n", picture.contrast); printf(" whiteness: %i\n", picture.whiteness); printf(" depth: %i\n", picture.depth); char static palet_tipi_str[64]; palette_name(palet_tipi_str, picture.palette); printf(" palette: %s\n\n", palet_tipi_str); vch.channel = 0; // vch.norm = VIDEO_MODE_PAL; if(-1 == v4l1_ioctl(fd, VIDIOCSCHAN,&vch)) { perror("Setting channel\n"); goto error; } fcntl(fd,F_SETFD,FD_CLOEXEC); if (-1 == v4l1_ioctl(fd, VIDIOCGMBUF,&gb_buffers)) { printf("Error: Error getting buffers\n"); goto error; } map = v4l1_mmap(0,gb_buffers.size,PROT_READ|PROT_WRITE,MAP_SHARED,fd,0); if (map == NULL) { printf("Error: Mmap returned NULL\n"); goto error; } // Set up out capture to use the correct resolution my_buf.width = mywidth; my_buf.height = myheight; my_buf.format = VIDEO_PALETTE_RGB24; // Set up out video output SDL_Init(SDL_INIT_VIDEO); screen = SDL_SetVideoMode(mywidth, myheight, 24, SDL_SWSURFACE); if ( screen == NULL ) { fprintf(stderr, "Couldn't set video mode: %s\n", SDL_GetError()); exit(1); } SDL_WM_SetCaption("Oy oy oy teve pirogrami", NULL); // Tell the capture card to fill frame 0 my_buf.frame = 0; if (-1 == v4l1_ioctl(fd, VIDIOCMCAPTURE, &my_buf)) { printf(" ilk my_buf.frame=0 da hata olustu\n"); // printf("Error: Grabber chip can't sync (no station tuned in?)\n"); goto error; } // This is the infinate loop // We basically: // capture frame 1 // sync frame 0 // process frame 0 // capture frame 0 // sync frame 1 // process frame 1 // For more information, read the programming how-to that came with xawtv do { my_buf.frame = 1; if (-1 == v4l1_ioctl(fd, VIDIOCMCAPTURE, &my_buf)) { printf(" loop icinde frame=1 \n"); // printf("Error: Grabber chip can't sync (no station tuned in?)\n"); goto error; } my_buf.frame = 0; if (-1 == v4l1_ioctl(fd, VIDIOCSYNC, &my_buf.frame)) { printf("Error on sync!\n"); goto error; } copytoscreen(map); my_buf.frame = 0; if (-1 == v4l1_ioctl(fd, VIDIOCMCAPTURE, &my_buf)) { printf(" loop icinde frame=0 \n"); // printf("Error: Grabber chip can't sync (no station tuned in?)\n"); goto error; } my_buf.frame = 1; if (-1 == v4l1_ioctl(fd, VIDIOCSYNC, &my_buf.frame)) { printf("Error on sync!\n"); goto error; } copytoscreen(map + gb_buffers.offsets[1]); SDL_PollEvent(&event); } while (event.type != SDL_KEYDOWN); error: SDL_Quit(); return EXIT_SUCCESS; }