int changeSize (struct vdIn *vd) { int erreur; erreur = GetVideoPict (vd); vd->formatIn = vd->videopict.palette; vd->bppIn = vd->videopict.depth; /* To Compute the estimate frame size perhaps not need !!! */ if ((vd->bppIn = GetDepth (vd->formatIn)) < 0) { perror ("getdepth failed \n"); exit (1); } if (vd->grabMethod) { vd->vmmap.height = vd->hdrheight; vd->vmmap.width = vd->hdrwidth; vd->vmmap.format = vd->formatIn; } else { if (ioctl (vd->fd, VIDIOCGWIN, &vd->videowin) < 0) perror ("VIDIOCGWIN failed \n"); vd->videowin.height = vd->hdrheight; vd->videowin.width = vd->hdrwidth; if (ioctl (vd->fd, VIDIOCSWIN, &vd->videowin) < 0) perror ("VIDIOCSWIN failed \n"); printf ("VIDIOCGWIN height %d width %d \n", vd->videowin.height, vd->videowin.width); } vd->framesizeIn = ((vd->hdrwidth * vd->hdrheight * vd->bppIn) >> 3); // vd->pixTmp = // (unsigned char *) realloc (vd->pixTmp, (size_t) vd->framesizeIn); return 0; }
static int init_v4l (struct vdIn *vd) { int f; int erreur = 0; int err; if ((vd->fd = open (vd->videodevice, O_RDWR)) == -1) { //exit_fatal ("ERROR opening V4L interface"); printf("ERROR opening V4L interface\n"); return -1; } if (ioctl (vd->fd, VIDIOCGCAP, &(vd->videocap)) == -1) { //exit_fatal ("Couldn't get videodevice capability"); printf("Couldn't get videodevice capability"); return -1; } printf ("Camera found: %s \n", vd->videocap.name); snprintf (vd->cameraname, 32, "%s", vd->videocap.name); erreur = GetVideoPict (vd); if (ioctl (vd->fd, VIDIOCGCHAN, &vd->videochan) == -1) { printf ("Hmm did not support Video_channel\n"); vd->cameratype = UNOW; } else { if (vd->videochan.name){ printf ("Bridge found: %s \n", vd->videochan.name); snprintf (vd->bridge, 9, "%s", vd->videochan.name); vd->cameratype = GetStreamId (vd->videochan.name); spcaPrintParam (vd->fd,&vd->videoparam); } else { printf ("Bridge not found not a spca5xx Webcam Probing the hardware !!\n"); vd->cameratype = UNOW; } } printf ("StreamId: %d Camera\n", vd->cameratype); /* probe all available palette and size */ if (probePalette(vd ) < 0) { //exit_fatal ("could't probe video palette Abort !"); printf ("could't probe video palette Abort !\n"); return -1; } if (probeSize(vd ) < 0) { //exit_fatal ("could't probe video size Abort !"); printf ("could't probe video size Abort !\n"); return -1; } /* now check if the needed setting match the available if not find a new set and populate the change */ err = check_palettesize(vd); printf (" Format asked %d check %d\n",vd->formatIn, err); vd->videopict.palette = vd->formatIn; vd->videopict.depth = GetDepth (vd->formatIn); vd->bppIn = GetDepth (vd->formatIn); vd->framesizeIn = (vd->hdrwidth * vd->hdrheight * vd->bppIn) >> 3; erreur = SetVideoPict (vd); erreur = GetVideoPict (vd); if (vd->formatIn != vd->videopict.palette || vd->bppIn != vd->videopict.depth) { //exit_fatal ("could't set video palette Abort !"); printf ("could't set video palette Abort !\n"); return -1; } if (erreur < 0){ printf ("could't set video palette Abort !\n"); return -1; } if (vd->grabMethod) { printf (" grabbing method default MMAP asked \n"); // MMAP VIDEO acquisition memset (&(vd->videombuf), 0, sizeof (vd->videombuf)); if (ioctl (vd->fd, VIDIOCGMBUF, &(vd->videombuf)) < 0) { perror (" init VIDIOCGMBUF FAILED\n"); } printf ("VIDIOCGMBUF size %d frames %d offets[0]=%d offsets[1]=%d\n", vd->videombuf.size, vd->videombuf.frames, vd->videombuf.offsets[0], vd->videombuf.offsets[1]); vd->pFramebuffer = (unsigned char *) mmap (0, vd->videombuf.size, PROT_READ | PROT_WRITE, MAP_SHARED, vd->fd, 0); vd->mmapsize = vd->videombuf.size; vd->vmmap.height = vd->hdrheight; vd->vmmap.width = vd->hdrwidth; vd->vmmap.format = vd->formatIn; for (f = 0; f < vd->videombuf.frames; f++) { vd->vmmap.frame = f; if (ioctl (vd->fd, VIDIOCMCAPTURE, &(vd->vmmap))) { perror ("cmcapture"); } } vd->vmmap.frame = 0; } else { /* read method */ /* allocate the read buffer */ vd->pFramebuffer = (unsigned char *) realloc (vd->pFramebuffer, (size_t) vd->framesizeIn); printf (" grabbing method READ asked \n"); if (ioctl (vd->fd, VIDIOCGWIN, &(vd->videowin)) < 0) perror ("VIDIOCGWIN failed \n"); vd->videowin.height = vd->hdrheight; vd->videowin.width = vd->hdrwidth; if (ioctl (vd->fd, VIDIOCSWIN, &(vd->videowin)) < 0) perror ("VIDIOCSWIN failed \n"); printf ("VIDIOCSWIN height %d width %d \n", vd->videowin.height, vd->videowin.width); } vd->frame_cour = 0; return erreur; }