Re: reading a capture from v4l1

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



Extremely helpful, particularly with mmap. When doing a read directly, I'm assuming the sequence of steps is:

ioctl(dev, VIDIOCSPICT, pict)
ioctl(dev, VIDIOCSWIN, win)
ioctl(dev, VIDIOCCAPTURE, 1)
while (whatever)
   read(dev, buf, count)
ioctl(dev, VIDIOCCAPTURE, 0)


Serguei Boldyrev wrote:

In general there are following main ways to make a capturing:

Each call to the read syscall returns the next available image from the device. It is up to the caller to set format and size (using the VIDIOCSPICT and VIDIOCSWIN ioctls) and then to pass a suitable size buffer and length to the function. Not all devices will support read operations. A second way to handle image capture is via the mmap interface if supported. To use the mmap interface a user first sets the desired image size and depth properties. Next the VIDIOCGMBUF ioctl is issued. This reports the size of buffer to mmap and the offset within the buffer for each frame. The number of frames supported is device dependent and may only be one.

Once the mmap has been made the VIDIOCMCAPTURE ioctl starts the capture to a frame using the format and image size specified in the video_mmap (which should match or be below the initial query size). When the VIDIOCMCAPTURE ioctl returns the frame is not captured yet, the driver just instructed the hardware to start the capture. The application has to use the VIDIOCSYNC ioctl to wait until the capture of a frame is finished. VIDIOCSYNC takes the frame number you want to wait for as argument.

It is allowed to call VIDIOCMCAPTURE multiple times (with different frame numbers in video_mmap->frame of course) and thus have multiple outstanding capture requests. A simple way do to double-buffering using this feature looks like this:

/* setup everything */
VIDIOCMCAPTURE(0)
while (whatever) {
  VIDIOCMCAPTURE(1)
  VIDIOCSYNC(0)
  /* process frame 0 while the hardware captures frame 1 */
  VIDIOCMCAPTURE(0)
  VIDIOCSYNC(1)
  /* process frame 1 while the hardware captures frame 0 */
}

Note that you are not limited to only two frames. The API allows up to 32 frames, the VIDIOCGMBUF ioctl returns the number of frames the driver granted. Thus it is possible to build deeper queues to avoid loosing frames on load peaks. While capturing to memory the driver will make a "best effort" attempt to capture to screen as well if requested. This normally means all frames that "miss" memory mapped capture will go to the display.

But I recommend you to read v4l docs...
regards,
Serguei.

Jeffrey Dever wrote:

I'm perplexed as to how to read captures from the video device. I can do quite a bit to control my webcam (probe, set window ...) but there seems to be several modes of reading captures. I'm just trying to do a simple capture, so I don't want to use mmap at this point as I want to keep it as simple as possible.

I expect to use VIDIOCCAPTURE. I can see that we call this ioctl to start capturing, but don't see how to read the data. Do we start capturing, do a read() and then stop capturing? What is the sequence of steps?







--
video4linux-list mailing list
Unsubscribe mailto:video4linux-list-request@xxxxxxxxxx?subject=unsubscribe
https://listman.redhat.com/mailman/listinfo/video4linux-list










[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