Problem using v4l2

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]



Hi:

I've developed an aplication on v4l2 but i've a doubt about how to sync with the capture of frames. Reading the draft of v4l2 i thought VIDIOC_DQBUF blocks aplication user until buffer wainting for was filled. When i tried to use DQBUF a buffer it rises an EINVAL with the perror "Resource temporarily unavailable"(i haven't opened fd with O_NONBLOCK and there is a buffer in queue). I've used select() to block the aplication until the buffer is filled and now it's work but i want to know if there is another way.

Another question is i've tried to change fmt.pix.field from V4L2_FIELD_ANY to V4L2_FIELD_ALTERNATE (i'm using the V4L2_MEMORY_MMAP and V4L2_BUF_TYPE_VIDEO_CAPTURE with GREYSCALE) to capture in half period time but it always rises an Segmentation fault in the second buffer (of 2) after VIDIOC_DQBUF call. Does anyone know some reason?

A little extract:

 video_format.fmt.pix.width=maxWidth;
 video_format.fmt.pix.height=maxHeight;
 video_format.fmt.pix.field=V4L2_FIELD_ALTERNATE;
 /*  video_format.fmt.pix.field=V4L2_FIELD_ANY;*/
 video_format.fmt.pix.pixelformat=V4L2_PIX_FMT_GREY;

if (ioctl(grab_fd, VIDIOC_S_FMT,&video_format)==-1)
   {
     perror("VIDIOC_S_FMT");
     return (-1);
   }
.......................

 reqbuf.type=V4L2_BUF_TYPE_VIDEO_CAPTURE;
 reqbuf.memory=V4L2_MEMORY_MMAP;
 reqbuf.count=numBuffers;

 if (ioctl(grab_fd, VIDIOC_REQBUFS,&reqbuf)==-1){
     perror("VIDIOC_REQBUFS\n");
     return(-1);
   }
...................
buffers[i].start=mmap(NULL, buffer.length, PROT_READ|PROT_WRITE /*requerido*/,
             MAP_SHARED, grab_fd, buffer.m.offset);
..............

   Here I put in the QBUF the alternate buffer without problems.
 phase=(phase ? 0:1);
 buffer.index=phase;
 buffer.type=V4L2_BUF_TYPE_VIDEO_CAPTURE;
 buffer.timestamp.tv_sec=0;
 buffer.timestamp.tv_usec=0;

 FD_ZERO(&rdset);
 FD_SET(grab_fd, &rdset);
 timeout.tv_sec = 1;
 timeout.tv_usec = 0;
 res = select(grab_fd + 1, &rdset, NULL, NULL, &timeout);

 if (ioctl(grab_fd,VIDIOC_DQBUF,&buffer)==-1){
   if (errno==EAGAIN)
     printf("Non-blocking I/O");
   else if (errno==EINVAL)
     printf("Einval");
   else if (errno==ENOMEM)
     printf("enomem");

   perror("ERROR VIDIOC_DQBUF");
   return NULL;
 }

With the first buffer i don't have problems but always i try to return the second buffer the aplication crash with a Segmentation fault at this point (phase=1). It works fine with
V4L2_FIELD_ANY but not with any of individual field formats.

 return buffers[phase].start;

Thanks and sorry for my english.





[Index of Archives]     [Linux DVB]     [Video Disk Recorder]     [Asterisk]     [Photo]     [DCCP]     [Netdev]     [Xorg]     [Util Linux NG]     [Xfree86]     [Free Photo Albums]     [Fedora Users]     [Fedora Women]     [ALSA Users]     [ALSA Devel]     [Linux USB]

Powered by Linux