Ejemplo n.º 1
0
void
sane_close (SANE_Handle handle)
{
  V4L_Scanner *prev, *s;

  DBG (2, "sane_close: trying to close handle %p\n", (void *) handle);
  /* remove handle from list of open handles: */
  prev = 0;
  for (s = first_handle; s; s = s->next)
    {
      if (s == handle)
	break;
      prev = s;
    }
  if (!s)
    {
      DBG (1, "sane_close: bad handle %p\n", handle);
      return;			/* oops, not a handle we know about */
    }
  if (prev)
    prev->next = s->next;
  else
    first_handle = s->next;

  if (s->scanning)
    sane_cancel (handle);
  v4l1_close (s->fd);
  free (s);
}
Ejemplo n.º 2
0
void copytoscreen(char* tmap) {
	int loop=0;
	do{
		SDL_PollEvent(&event);
		if (event.type == SDL_KEYDOWN) {
			v4l1_close(fd);
			SDL_Quit();
			exit(0);
		}
		// usleep(20);
	} while(loop++<20);
	offscreen = SDL_CreateRGBSurfaceFrom((void *) tmap, mywidth, myheight, 24, mywidth*3, 0xFF0000, 0x00FF00, 0x0000FF, 0x000000);
	SDL_BlitSurface(offscreen, NULL, screen, NULL);
	SDL_UpdateRect(screen, 0, 0, 0, 0);
	SDL_FreeSurface(offscreen);
}
Ejemplo n.º 3
0
Archivo: v4l1.c Proyecto: Jeija/ZBar
static int v4l1_cleanup (zbar_video_t *vdo)
{
#ifdef HAVE_SYS_MMAN_H
    /* FIXME should avoid holding onto mmap'd buffers so long? */
    if(vdo->iomode == VIDEO_MMAP && vdo->buf) {
        if(v4l1_munmap(vdo->buf, vdo->buflen))
            return(err_capture(vdo, SEV_ERROR, ZBAR_ERR_SYSTEM, __func__,
                               "unmapping video frame buffers"));
        vdo->buf = NULL;
        /* FIXME reset image */
    }
#endif

    /* close open device */
    if(vdo->fd >= 0) {
        v4l1_close(vdo->fd);
        vdo->fd = -1;
    }
    return(0);
}
Ejemplo n.º 4
0
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;
   }





    //if( -1 == ioctl(fd, VIDIOC_QUERYCAP, &v4l2_capability) ) {
    if( ioctl(fd, VIDIOC_QUERYCAP, &v4l2_capability) < 0 ) {
        printf("asd  1\n");
        if( -1 == ioctl(fd, VIDIOCGCAP, &capability) ) {
        printf("asd  2\n");
            printf("Error1: ioctl(fd,VIDIOCGCAP,&capability)\n");
            camDriver = DRIVER_NONE;
            goto error;
        } else {
        printf("asd  3\n");
            camDriver = DRIVER_V4L;
        }
    } else {
        printf("asd  4\n");
        camDriver = DRIVER_V4L2;

        v4l1_close(fd);
        fd = v4l1_open(my_video_dev, O_RDWR);

        if( -1 == my_ioctl(VIDIOCGCAP, &capability)) {
        printf("asd  5\n");
            printf("Error2: ioctl(fd,VIDIOCGCAP,&capability)\n");
            goto error;
        }
    }


//    if( DRIVER_V4L == camDriver ) {

        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 == my_ioctl(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 == my_ioctl(VIDIOCSCHAN,&vch)) {
        perror("Setting channel\n");
	goto error;
   }
   
   fcntl(fd,F_SETFD,FD_CLOEXEC);
   if (-1 == my_ioctl(VIDIOCGMBUF,&gb_buffers)) {
	printf("Error: Error getting buffers\n");
	goto error;
   }

   map = my_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 == my_ioctl(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 == my_ioctl(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 == my_ioctl(VIDIOCSYNC, &my_buf.frame)) {
		 printf("Error on sync!\n"); 
		goto error;
	}

	copytoscreen(map);

	my_buf.frame = 0;
	if (-1 == my_ioctl(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 == my_ioctl(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;

}
Ejemplo n.º 5
0
LIBV4L_PUBLIC int close(int fd)
{
	return v4l1_close(fd);
}
Ejemplo n.º 6
0
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;
}
Ejemplo n.º 7
0
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;
}