0
s->buf.type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
s->buf.memory = V4L2_MEMORY_MMAP;

I must confess that I'm rather unfamiliar with V4L2 APIs. I fathom in the above two lines, the first one is to establish a buffer type, the second line is to pass the pointer of the video device dedicated memory to the buffer.

Problem is, I don't know if I'm making the right guess and I need someone to explain in detail how the second line works.

Tron Volta
  • 103
  • 5

1 Answers1

0

The second line establishes how the buffer will be used. The legal values are:

Table 3.5. enum v4l2_memory

V4L2_MEMORY_MMAP    1   The buffer is used for memory mapping I/O.  
V4L2_MEMORY_USERPTR 2   The buffer is used for user pointer I/O.  
V4L2_MEMORY_OVERLAY 3   [Not Yet Implemented]  
V4L2_MEMORY_DMABUF  4   The buffer is used for DMA shared buffer I/O. 

The code you included does not actually allocate the buffers. Here is a somewhat more complete code fragment showing the mmaping of buffers:

    CLEAR(req);
    req.count = 2;
    req.type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
    req.memory = V4L2_MEMORY_MMAP;
    xioctl(fd, VIDIOC_REQBUFS, &req);

    buffers = calloc(req.count, sizeof(*buffers));
    for (n_buffers = 0; n_buffers < req.count; ++n_buffers) {
            CLEAR(buf);

            buf.type        = V4L2_BUF_TYPE_VIDEO_CAPTURE;
            buf.memory      = V4L2_MEMORY_MMAP;
            buf.index       = n_buffers;

            xioctl(fd, VIDIOC_QUERYBUF, &buf);

            buffers[n_buffers].length = buf.length;
            buffers[n_buffers].start = v4l2_mmap(NULL, buf.length,
                          PROT_READ | PROT_WRITE, MAP_SHARED,
                          fd, buf.m.offset);

            if (MAP_FAILED == buffers[n_buffers].start) {
                    perror("mmap");
                    exit(EXIT_FAILURE);
            }
    }
John Hascall
  • 9,176
  • 6
  • 48
  • 72