€•£®Œsphinx.addnodes”Œdocument”“”)”}”(Œ rawsource”Œ”Œchildren”]”(Œ translations”Œ LanguagesNode”“”)”}”(hhh]”(hŒ pending_xref”“”)”}”(hhh]”Œdocutils.nodes”ŒText”“”ŒChinese (Simplified)”…””}”Œparent”hsbaŒ attributes”}”(Œids”]”Œclasses”]”Œnames”]”Œdupnames”]”Œbackrefs”]”Œ refdomain”Œstd”Œreftype”Œdoc”Œ reftarget”Œ0/translations/zh_CN/userspace-api/media/v4l/mmap”Œmodname”NŒ classname”NŒ refexplicit”ˆuŒtagname”hhh ubh)”}”(hhh]”hŒChinese (Traditional)”…””}”hh2sbah}”(h]”h ]”h"]”h$]”h&]”Œ refdomain”h)Œreftype”h+Œ reftarget”Œ0/translations/zh_TW/userspace-api/media/v4l/mmap”Œmodname”NŒ classname”NŒ refexplicit”ˆuh1hhh ubh)”}”(hhh]”hŒItalian”…””}”hhFsbah}”(h]”h ]”h"]”h$]”h&]”Œ refdomain”h)Œreftype”h+Œ reftarget”Œ0/translations/it_IT/userspace-api/media/v4l/mmap”Œmodname”NŒ classname”NŒ refexplicit”ˆuh1hhh ubh)”}”(hhh]”hŒJapanese”…””}”hhZsbah}”(h]”h ]”h"]”h$]”h&]”Œ refdomain”h)Œreftype”h+Œ reftarget”Œ0/translations/ja_JP/userspace-api/media/v4l/mmap”Œmodname”NŒ classname”NŒ refexplicit”ˆuh1hhh ubh)”}”(hhh]”hŒKorean”…””}”hhnsbah}”(h]”h ]”h"]”h$]”h&]”Œ refdomain”h)Œreftype”h+Œ reftarget”Œ0/translations/ko_KR/userspace-api/media/v4l/mmap”Œmodname”NŒ classname”NŒ refexplicit”ˆuh1hhh ubh)”}”(hhh]”hŒPortuguese (Brazilian)”…””}”hh‚sbah}”(h]”h ]”h"]”h$]”h&]”Œ refdomain”h)Œreftype”h+Œ reftarget”Œ0/translations/pt_BR/userspace-api/media/v4l/mmap”Œmodname”NŒ classname”NŒ refexplicit”ˆuh1hhh ubh)”}”(hhh]”hŒSpanish”…””}”hh–sbah}”(h]”h ]”h"]”h$]”h&]”Œ refdomain”h)Œreftype”h+Œ reftarget”Œ0/translations/sp_SP/userspace-api/media/v4l/mmap”Œmodname”NŒ classname”NŒ refexplicit”ˆuh1hhh ubeh}”(h]”h ]”h"]”h$]”h&]”Œcurrent_language”ŒEnglish”uh1h hhŒ _document”hŒsource”NŒline”NubhŒcomment”“”)”}”(hŒ8SPDX-License-Identifier: GFDL-1.1-no-invariants-or-later”h]”hŒ8SPDX-License-Identifier: GFDL-1.1-no-invariants-or-later”…””}”hh·sbah}”(h]”h ]”h"]”h$]”h&]”Œ xml:space”Œpreserve”uh1hµhhh²hh³ŒJ/var/lib/git/docbuild/linux/Documentation/userspace-api/media/v4l/mmap.rst”h´KubhŒtarget”“”)”}”(hŒ .. _mmap:”h]”h}”(h]”h ]”h"]”h$]”h&]”Œrefid”Œmmap”uh1hÈh´Khhh²hh³hÇubhŒsection”“”)”}”(hhh]”(hŒtitle”“”)”}”(hŒStreaming I/O (Memory Mapping)”h]”hŒStreaming I/O (Memory Mapping)”…””}”(hhÝh²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hÛhhØh²hh³hÇh´KubhŒ paragraph”“”)”}”(hXInput and output devices support this I/O method when the ``V4L2_CAP_STREAMING`` flag in the ``capabilities`` field of struct :c:type:`v4l2_capability` returned by the :ref:`VIDIOC_QUERYCAP` ioctl is set. There are two streaming methods, to determine if the memory mapping flavor is supported applications must call the :ref:`VIDIOC_REQBUFS` ioctl with the memory type set to ``V4L2_MEMORY_MMAP``.”h]”(hŒ:Input and output devices support this I/O method when the ”…””}”(hhíh²hh³Nh´NubhŒliteral”“”)”}”(hŒ``V4L2_CAP_STREAMING``”h]”hŒV4L2_CAP_STREAMING”…””}”(hh÷h²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hõhhíubhŒ flag in the ”…””}”(hhíh²hh³Nh´Nubhö)”}”(hŒ``capabilities``”h]”hŒ capabilities”…””}”(hj h²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hõhhíubhŒ field of struct ”…””}”(hhíh²hh³Nh´Nubh)”}”(hŒ:c:type:`v4l2_capability`”h]”hö)”}”(hjh]”hŒv4l2_capability”…””}”(hjh²hh³Nh´Nubah}”(h]”h ]”(Œxref”Œc”Œc-type”eh"]”h$]”h&]”uh1hõhjubah}”(h]”h ]”h"]”h$]”h&]”Œrefdoc”Œuserspace-api/media/v4l/mmap”Œ refdomain”j*Œreftype”Œtype”Œ refexplicit”‰Œrefwarn”‰Œ c:parent_key”Œsphinx.domains.c”Œ LookupKey”“”)”}”Œdata”]”j=Œ ASTIdentifier”“”)”}”Œ identifier”ŒV4L”sbN†”asbŒ reftarget”Œv4l2_capability”uh1hh³hÇh´K hhíubhŒ returned by the ”…””}”(hhíh²hh³Nh´Nubh)”}”(hŒ:ref:`VIDIOC_QUERYCAP`”h]”hŒinline”“”)”}”(hjSh]”hŒVIDIOC_QUERYCAP”…””}”(hjWh²hh³Nh´Nubah}”(h]”h ]”(j)Œstd”Œstd-ref”eh"]”h$]”h&]”uh1jUhjQubah}”(h]”h ]”h"]”h$]”h&]”Œrefdoc”j6Œ refdomain”jaŒreftype”Œref”Œ refexplicit”‰Œrefwarn”ˆjKŒvidioc_querycap”uh1hh³hÇh´K hhíubhŒ‚ ioctl is set. There are two streaming methods, to determine if the memory mapping flavor is supported applications must call the ”…””}”(hhíh²hh³Nh´Nubh)”}”(hŒ:ref:`VIDIOC_REQBUFS`”h]”jV)”}”(hjyh]”hŒVIDIOC_REQBUFS”…””}”(hj{h²hh³Nh´Nubah}”(h]”h ]”(j)Œstd”Œstd-ref”eh"]”h$]”h&]”uh1jUhjwubah}”(h]”h ]”h"]”h$]”h&]”Œrefdoc”j6Œ refdomain”j…Œreftype”Œref”Œ refexplicit”‰Œrefwarn”ˆjKŒvidioc_reqbufs”uh1hh³hÇh´K hhíubhŒ# ioctl with the memory type set to ”…””}”(hhíh²hh³Nh´Nubhö)”}”(hŒ``V4L2_MEMORY_MMAP``”h]”hŒV4L2_MEMORY_MMAP”…””}”(hj›h²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hõhhíubhŒ.”…””}”(hhíh²hh³Nh´Nubeh}”(h]”h ]”h"]”h$]”h&]”uh1hëh³hÇh´K hhØh²hubhì)”}”(hXõStreaming is an I/O method where only pointers to buffers are exchanged between application and driver, the data itself is not copied. Memory mapping is primarily intended to map buffers in device memory into the application's address space. Device memory can be for example the video memory on a graphics card with a video capture add-on. However, being the most efficient I/O method available for a long time, many other drivers support streaming as well, allocating buffers in DMA-able main memory.”h]”hX÷Streaming is an I/O method where only pointers to buffers are exchanged between application and driver, the data itself is not copied. Memory mapping is primarily intended to map buffers in device memory into the application’s address space. Device memory can be for example the video memory on a graphics card with a video capture add-on. However, being the most efficient I/O method available for a long time, many other drivers support streaming as well, allocating buffers in DMA-able main memory.”…””}”(hj³h²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hëh³hÇh´KhhØh²hubhì)”}”(hXA driver can support many sets of buffers. Each set is identified by a unique buffer type value. The sets are independent and each set can hold a different type of data. To access different sets at the same time different file descriptors must be used. [#f1]_”h]”(hŒýA driver can support many sets of buffers. Each set is identified by a unique buffer type value. The sets are independent and each set can hold a different type of data. To access different sets at the same time different file descriptors must be used. ”…””}”(hjÁh²hh³Nh´NubhŒfootnote_reference”“”)”}”(hŒ[#f1]_”h]”hŒ1”…””}”(hjËh²hh³Nh´Nubah}”(h]”Œid1”ah ]”h"]”h$]”h&]”Œauto”KhÔŒf1”Œdocname”j6uh1jÉhjÁŒresolved”Kubeh}”(h]”h ]”h"]”h$]”h&]”uh1hëh³hÇh´KhhØh²hubhì)”}”(hX9To allocate device buffers applications call the :ref:`VIDIOC_REQBUFS` ioctl with the desired number of buffers and buffer type, for example ``V4L2_BUF_TYPE_VIDEO_CAPTURE``. This ioctl can also be used to change the number of buffers or to free the allocated memory, provided none of the buffers are still mapped.”h]”(hŒ1To allocate device buffers applications call the ”…””}”(hjäh²hh³Nh´Nubh)”}”(hŒ:ref:`VIDIOC_REQBUFS`”h]”jV)”}”(hjîh]”hŒVIDIOC_REQBUFS”…””}”(hjðh²hh³Nh´Nubah}”(h]”h ]”(j)Œstd”Œstd-ref”eh"]”h$]”h&]”uh1jUhjìubah}”(h]”h ]”h"]”h$]”h&]”Œrefdoc”j6Œ refdomain”júŒreftype”Œref”Œ refexplicit”‰Œrefwarn”ˆjKŒvidioc_reqbufs”uh1hh³hÇh´K hjäubhŒG ioctl with the desired number of buffers and buffer type, for example ”…””}”(hjäh²hh³Nh´Nubhö)”}”(hŒ``V4L2_BUF_TYPE_VIDEO_CAPTURE``”h]”hŒV4L2_BUF_TYPE_VIDEO_CAPTURE”…””}”(hjh²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hõhjäubhŒ. This ioctl can also be used to change the number of buffers or to free the allocated memory, provided none of the buffers are still mapped.”…””}”(hjäh²hh³Nh´Nubeh}”(h]”h ]”h"]”h$]”h&]”uh1hëh³hÇh´K hhØh²hubhì)”}”(hX Before applications can access the buffers they must map them into their address space with the :c:func:`mmap()` function. The location of the buffers in device memory can be determined with the :ref:`VIDIOC_QUERYBUF` ioctl. In the single-planar API case, the ``m.offset`` and ``length`` returned in a struct :c:type:`v4l2_buffer` are passed as sixth and second parameter to the :c:func:`mmap()` function. When using the multi-planar API, struct :c:type:`v4l2_buffer` contains an array of struct :c:type:`v4l2_plane` structures, each containing its own ``m.offset`` and ``length``. When using the multi-planar API, every plane of every buffer has to be mapped separately, so the number of calls to :c:func:`mmap()` should be equal to number of buffers times number of planes in each buffer. The offset and length values must not be modified. Remember, the buffers are allocated in physical memory, as opposed to virtual memory, which can be swapped out to disk. Applications should free the buffers as soon as possible with the :c:func:`munmap()` function.”h]”(hŒ`Before applications can access the buffers they must map them into their address space with the ”…””}”(hj(h²hh³Nh´Nubh)”}”(hŒ:c:func:`mmap()`”h]”hö)”}”(hj2h]”hŒmmap()”…””}”(hj4h²hh³Nh´Nubah}”(h]”h ]”(j)j*Œc-func”eh"]”h$]”h&]”uh1hõhj0ubah}”(h]”h ]”h"]”h$]”h&]”Œrefdoc”j6Œ refdomain”j*Œreftype”Œfunc”Œ refexplicit”‰Œrefwarn”‰j<j@jKŒmmap”uh1hh³hÇh´K&hj(ubhŒS function. The location of the buffers in device memory can be determined with the ”…””}”(hj(h²hh³Nh´Nubh)”}”(hŒ:ref:`VIDIOC_QUERYBUF`”h]”jV)”}”(hjUh]”hŒVIDIOC_QUERYBUF”…””}”(hjWh²hh³Nh´Nubah}”(h]”h ]”(j)Œstd”Œstd-ref”eh"]”h$]”h&]”uh1jUhjSubah}”(h]”h ]”h"]”h$]”h&]”Œrefdoc”j6Œ refdomain”jaŒreftype”Œref”Œ refexplicit”‰Œrefwarn”ˆjKŒvidioc_querybuf”uh1hh³hÇh´K&hj(ubhŒ+ ioctl. In the single-planar API case, the ”…””}”(hj(h²hh³Nh´Nubhö)”}”(hŒ ``m.offset``”h]”hŒm.offset”…””}”(hjwh²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hõhj(ubhŒ and ”…””}”(hj(h²hh³Nh´Nubhö)”}”(hŒ ``length``”h]”hŒlength”…””}”(hj‰h²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hõhj(ubhŒ returned in a struct ”…””}”(hj(h²hh³Nh´Nubh)”}”(hŒ:c:type:`v4l2_buffer`”h]”hö)”}”(hjh]”hŒ v4l2_buffer”…””}”(hjŸh²hh³Nh´Nubah}”(h]”h ]”(j)j*Œc-type”eh"]”h$]”h&]”uh1hõhj›ubah}”(h]”h ]”h"]”h$]”h&]”Œrefdoc”j6Œ refdomain”j*Œreftype”Œtype”Œ refexplicit”‰Œrefwarn”‰j<j@jKŒ v4l2_buffer”uh1hh³hÇh´K&hj(ubhŒ1 are passed as sixth and second parameter to the ”…””}”(hj(h²hh³Nh´Nubh)”}”(hŒ:c:func:`mmap()`”h]”hö)”}”(hjÀh]”hŒmmap()”…””}”(hjÂh²hh³Nh´Nubah}”(h]”h ]”(j)j*Œc-func”eh"]”h$]”h&]”uh1hõhj¾ubah}”(h]”h ]”h"]”h$]”h&]”Œrefdoc”j6Œ refdomain”j*Œreftype”Œfunc”Œ refexplicit”‰Œrefwarn”‰j<j@jKŒmmap”uh1hh³hÇh´K&hj(ubhŒ3 function. When using the multi-planar API, struct ”…””}”(hj(h²hh³Nh´Nubh)”}”(hŒ:c:type:`v4l2_buffer`”h]”hö)”}”(hjãh]”hŒ v4l2_buffer”…””}”(hjåh²hh³Nh´Nubah}”(h]”h ]”(j)j*Œc-type”eh"]”h$]”h&]”uh1hõhjáubah}”(h]”h ]”h"]”h$]”h&]”Œrefdoc”j6Œ refdomain”j*Œreftype”Œtype”Œ refexplicit”‰Œrefwarn”‰j<j@jKŒ v4l2_buffer”uh1hh³hÇh´K&hj(ubhŒ contains an array of struct ”…””}”(hj(h²hh³Nh´Nubh)”}”(hŒ:c:type:`v4l2_plane`”h]”hö)”}”(hjh]”hŒ v4l2_plane”…””}”(hjh²hh³Nh´Nubah}”(h]”h ]”(j)j*Œc-type”eh"]”h$]”h&]”uh1hõhjubah}”(h]”h ]”h"]”h$]”h&]”Œrefdoc”j6Œ refdomain”j*Œreftype”Œtype”Œ refexplicit”‰Œrefwarn”‰j<j@jKŒ v4l2_plane”uh1hh³hÇh´K&hj(ubhŒ% structures, each containing its own ”…””}”(hj(h²hh³Nh´Nubhö)”}”(hŒ ``m.offset``”h]”hŒm.offset”…””}”(hj'h²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hõhj(ubhŒ and ”…””}”hj(sbhö)”}”(hŒ ``length``”h]”hŒlength”…””}”(hj9h²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hõhj(ubhŒv. When using the multi-planar API, every plane of every buffer has to be mapped separately, so the number of calls to ”…””}”(hj(h²hh³Nh´Nubh)”}”(hŒ:c:func:`mmap()`”h]”hö)”}”(hjMh]”hŒmmap()”…””}”(hjOh²hh³Nh´Nubah}”(h]”h ]”(j)j*Œc-func”eh"]”h$]”h&]”uh1hõhjKubah}”(h]”h ]”h"]”h$]”h&]”Œrefdoc”j6Œ refdomain”j*Œreftype”Œfunc”Œ refexplicit”‰Œrefwarn”‰j<j@jKŒmmap”uh1hh³hÇh´K&hj(ubhX: should be equal to number of buffers times number of planes in each buffer. The offset and length values must not be modified. Remember, the buffers are allocated in physical memory, as opposed to virtual memory, which can be swapped out to disk. Applications should free the buffers as soon as possible with the ”…””}”(hj(h²hh³Nh´Nubh)”}”(hŒ:c:func:`munmap()`”h]”hö)”}”(hjph]”hŒmunmap()”…””}”(hjrh²hh³Nh´Nubah}”(h]”h ]”(j)j*Œc-func”eh"]”h$]”h&]”uh1hõhjnubah}”(h]”h ]”h"]”h$]”h&]”Œrefdoc”j6Œ refdomain”j*Œreftype”Œfunc”Œ refexplicit”‰Œrefwarn”‰j<j@jKŒmunmap”uh1hh³hÇh´K&hj(ubhŒ function.”…””}”(hj(h²hh³Nh´Nubeh}”(h]”h ]”h"]”h$]”h&]”uh1hëh³hÇh´K&hhØh²hubh×)”}”(hhh]”(hÜ)”}”(hŒ1Example: Mapping buffers in the single-planar API”h]”hŒ1Example: Mapping buffers in the single-planar API”…””}”(hjšh²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hÛhj—h²hh³hÇh´K9ubhŒ literal_block”“”)”}”(hXVstruct v4l2_requestbuffers reqbuf; struct { void *start; size_t length; } *buffers; unsigned int i; memset(&reqbuf, 0, sizeof(reqbuf)); reqbuf.type = V4L2_BUF_TYPE_VIDEO_CAPTURE; reqbuf.memory = V4L2_MEMORY_MMAP; reqbuf.count = 20; if (-1 == ioctl (fd, VIDIOC_REQBUFS, &reqbuf)) { if (errno == EINVAL) printf("Video capturing or mmap-streaming is not supported\\n"); else perror("VIDIOC_REQBUFS"); exit(EXIT_FAILURE); } /* We want at least five buffers. */ if (reqbuf.count < 5) { /* You may need to free the buffers here. */ printf("Not enough buffer memory\\n"); exit(EXIT_FAILURE); } buffers = calloc(reqbuf.count, sizeof(*buffers)); assert(buffers != NULL); for (i = 0; i < reqbuf.count; i++) { struct v4l2_buffer buffer; memset(&buffer, 0, sizeof(buffer)); buffer.type = reqbuf.type; buffer.memory = V4L2_MEMORY_MMAP; buffer.index = i; if (-1 == ioctl (fd, VIDIOC_QUERYBUF, &buffer)) { perror("VIDIOC_QUERYBUF"); exit(EXIT_FAILURE); } buffers[i].length = buffer.length; /* remember for munmap() */ buffers[i].start = mmap(NULL, buffer.length, PROT_READ | PROT_WRITE, /* recommended */ MAP_SHARED, /* recommended */ fd, buffer.m.offset); if (MAP_FAILED == buffers[i].start) { /* If you do not exit here you should unmap() and free() the buffers mapped so far. */ perror("mmap"); exit(EXIT_FAILURE); } } /* Cleanup. */ for (i = 0; i < reqbuf.count; i++) munmap(buffers[i].start, buffers[i].length);”h]”hXVstruct v4l2_requestbuffers reqbuf; struct { void *start; size_t length; } *buffers; unsigned int i; memset(&reqbuf, 0, sizeof(reqbuf)); reqbuf.type = V4L2_BUF_TYPE_VIDEO_CAPTURE; reqbuf.memory = V4L2_MEMORY_MMAP; reqbuf.count = 20; if (-1 == ioctl (fd, VIDIOC_REQBUFS, &reqbuf)) { if (errno == EINVAL) printf("Video capturing or mmap-streaming is not supported\\n"); else perror("VIDIOC_REQBUFS"); exit(EXIT_FAILURE); } /* We want at least five buffers. */ if (reqbuf.count < 5) { /* You may need to free the buffers here. */ printf("Not enough buffer memory\\n"); exit(EXIT_FAILURE); } buffers = calloc(reqbuf.count, sizeof(*buffers)); assert(buffers != NULL); for (i = 0; i < reqbuf.count; i++) { struct v4l2_buffer buffer; memset(&buffer, 0, sizeof(buffer)); buffer.type = reqbuf.type; buffer.memory = V4L2_MEMORY_MMAP; buffer.index = i; if (-1 == ioctl (fd, VIDIOC_QUERYBUF, &buffer)) { perror("VIDIOC_QUERYBUF"); exit(EXIT_FAILURE); } buffers[i].length = buffer.length; /* remember for munmap() */ buffers[i].start = mmap(NULL, buffer.length, PROT_READ | PROT_WRITE, /* recommended */ MAP_SHARED, /* recommended */ fd, buffer.m.offset); if (MAP_FAILED == buffers[i].start) { /* If you do not exit here you should unmap() and free() the buffers mapped so far. */ perror("mmap"); exit(EXIT_FAILURE); } } /* Cleanup. */ for (i = 0; i < reqbuf.count; i++) munmap(buffers[i].start, buffers[i].length);”…””}”hjªsbah}”(h]”h ]”h"]”h$]”h&]”hÅhÆŒforce”‰Œlanguage”j*Œhighlight_args”}”uh1j¨h³hÇh´K;hj—h²hubeh}”(h]”Œ0example-mapping-buffers-in-the-single-planar-api”ah ]”h"]”Œ1example: mapping buffers in the single-planar api”ah$]”h&]”uh1hÖhhØh²hh³hÇh´K9ubh×)”}”(hhh]”(hÜ)”}”(hŒ0Example: Mapping buffers in the multi-planar API”h]”hŒ0Example: Mapping buffers in the multi-planar API”…””}”(hjÇh²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hÛhjÄh²hh³hÇh´Kubj©)”}”(hXstruct v4l2_requestbuffers reqbuf; /* Our current format uses 3 planes per buffer */ #define FMT_NUM_PLANES = 3 struct { void *start[FMT_NUM_PLANES]; size_t length[FMT_NUM_PLANES]; } *buffers; unsigned int i, j; memset(&reqbuf, 0, sizeof(reqbuf)); reqbuf.type = V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE; reqbuf.memory = V4L2_MEMORY_MMAP; reqbuf.count = 20; if (ioctl(fd, VIDIOC_REQBUFS, &reqbuf) < 0) { if (errno == EINVAL) printf("Video capturing or mmap-streaming is not supported\\n"); else perror("VIDIOC_REQBUFS"); exit(EXIT_FAILURE); } /* We want at least five buffers. */ if (reqbuf.count < 5) { /* You may need to free the buffers here. */ printf("Not enough buffer memory\\n"); exit(EXIT_FAILURE); } buffers = calloc(reqbuf.count, sizeof(*buffers)); assert(buffers != NULL); for (i = 0; i < reqbuf.count; i++) { struct v4l2_buffer buffer; struct v4l2_plane planes[FMT_NUM_PLANES]; memset(&buffer, 0, sizeof(buffer)); buffer.type = reqbuf.type; buffer.memory = V4L2_MEMORY_MMAP; buffer.index = i; /* length in struct v4l2_buffer in multi-planar API stores the size * of planes array. */ buffer.length = FMT_NUM_PLANES; buffer.m.planes = planes; if (ioctl(fd, VIDIOC_QUERYBUF, &buffer) < 0) { perror("VIDIOC_QUERYBUF"); exit(EXIT_FAILURE); } /* Every plane has to be mapped separately */ for (j = 0; j < FMT_NUM_PLANES; j++) { buffers[i].length[j] = buffer.m.planes[j].length; /* remember for munmap() */ buffers[i].start[j] = mmap(NULL, buffer.m.planes[j].length, PROT_READ | PROT_WRITE, /* recommended */ MAP_SHARED, /* recommended */ fd, buffer.m.planes[j].m.mem_offset); if (MAP_FAILED == buffers[i].start[j]) { /* If you do not exit here you should unmap() and free() the buffers and planes mapped so far. */ perror("mmap"); exit(EXIT_FAILURE); } } } /* Cleanup. */ for (i = 0; i < reqbuf.count; i++) for (j = 0; j < FMT_NUM_PLANES; j++) munmap(buffers[i].start[j], buffers[i].length[j]);”h]”hXstruct v4l2_requestbuffers reqbuf; /* Our current format uses 3 planes per buffer */ #define FMT_NUM_PLANES = 3 struct { void *start[FMT_NUM_PLANES]; size_t length[FMT_NUM_PLANES]; } *buffers; unsigned int i, j; memset(&reqbuf, 0, sizeof(reqbuf)); reqbuf.type = V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE; reqbuf.memory = V4L2_MEMORY_MMAP; reqbuf.count = 20; if (ioctl(fd, VIDIOC_REQBUFS, &reqbuf) < 0) { if (errno == EINVAL) printf("Video capturing or mmap-streaming is not supported\\n"); else perror("VIDIOC_REQBUFS"); exit(EXIT_FAILURE); } /* We want at least five buffers. */ if (reqbuf.count < 5) { /* You may need to free the buffers here. */ printf("Not enough buffer memory\\n"); exit(EXIT_FAILURE); } buffers = calloc(reqbuf.count, sizeof(*buffers)); assert(buffers != NULL); for (i = 0; i < reqbuf.count; i++) { struct v4l2_buffer buffer; struct v4l2_plane planes[FMT_NUM_PLANES]; memset(&buffer, 0, sizeof(buffer)); buffer.type = reqbuf.type; buffer.memory = V4L2_MEMORY_MMAP; buffer.index = i; /* length in struct v4l2_buffer in multi-planar API stores the size * of planes array. */ buffer.length = FMT_NUM_PLANES; buffer.m.planes = planes; if (ioctl(fd, VIDIOC_QUERYBUF, &buffer) < 0) { perror("VIDIOC_QUERYBUF"); exit(EXIT_FAILURE); } /* Every plane has to be mapped separately */ for (j = 0; j < FMT_NUM_PLANES; j++) { buffers[i].length[j] = buffer.m.planes[j].length; /* remember for munmap() */ buffers[i].start[j] = mmap(NULL, buffer.m.planes[j].length, PROT_READ | PROT_WRITE, /* recommended */ MAP_SHARED, /* recommended */ fd, buffer.m.planes[j].m.mem_offset); if (MAP_FAILED == buffers[i].start[j]) { /* If you do not exit here you should unmap() and free() the buffers and planes mapped so far. */ perror("mmap"); exit(EXIT_FAILURE); } } } /* Cleanup. */ for (i = 0; i < reqbuf.count; i++) for (j = 0; j < FMT_NUM_PLANES; j++) munmap(buffers[i].start[j], buffers[i].length[j]);”…””}”hjÕsbah}”(h]”h ]”h"]”h$]”h&]”hÅhÆj¸‰j¹j*jº}”uh1j¨h³hÇh´KhjÄh²hubhì)”}”(hXîConceptually streaming drivers maintain two buffer queues, an incoming and an outgoing queue. They separate the synchronous capture or output operation locked to a video clock from the application which is subject to random disk or network delays and preemption by other processes, thereby reducing the probability of data loss. The queues are organized as FIFOs, buffers will be output in the order enqueued in the incoming FIFO, and were captured in the order dequeued from the outgoing FIFO.”h]”hXîConceptually streaming drivers maintain two buffer queues, an incoming and an outgoing queue. They separate the synchronous capture or output operation locked to a video clock from the application which is subject to random disk or network delays and preemption by other processes, thereby reducing the probability of data loss. The queues are organized as FIFOs, buffers will be output in the order enqueued in the incoming FIFO, and were captured in the order dequeued from the outgoing FIFO.”…””}”(hjäh²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hëh³hÇh´KÐhjÄh²hubhì)”}”(hX×The driver may require a minimum number of buffers enqueued at all times to function, apart of this no limit exists on the number of buffers applications can enqueue in advance, or dequeue and process. They can also enqueue in a different order than buffers have been dequeued, and the driver can *fill* enqueued *empty* buffers in any order. [#f2]_ The index number of a buffer (struct :c:type:`v4l2_buffer` ``index``) plays no role here, it only identifies the buffer.”h]”(hX)The driver may require a minimum number of buffers enqueued at all times to function, apart of this no limit exists on the number of buffers applications can enqueue in advance, or dequeue and process. They can also enqueue in a different order than buffers have been dequeued, and the driver can ”…””}”(hjòh²hh³Nh´NubhŒemphasis”“”)”}”(hŒ*fill*”h]”hŒfill”…””}”(hjüh²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1júhjòubhŒ enqueued ”…””}”(hjòh²hh³Nh´Nubjû)”}”(hŒ*empty*”h]”hŒempty”…””}”(hjh²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1júhjòubhŒ buffers in any order. ”…””}”(hjòh²hh³Nh´NubjÊ)”}”(hŒ[#f2]_”h]”hŒ2”…””}”(hj h²hh³Nh´Nubah}”(h]”Œid2”ah ]”h"]”h$]”h&]”jÚKhÔŒf2”jÜj6uh1jÉhjòjÝKubhŒ& The index number of a buffer (struct ”…””}”(hjòh²hh³Nh´Nubh)”}”(hŒ:c:type:`v4l2_buffer`”h]”hö)”}”(hj6h]”hŒ v4l2_buffer”…””}”(hj8h²hh³Nh´Nubah}”(h]”h ]”(j)j*Œc-type”eh"]”h$]”h&]”uh1hõhj4ubah}”(h]”h ]”h"]”h$]”h&]”Œrefdoc”j6Œ refdomain”j*Œreftype”Œtype”Œ refexplicit”‰Œrefwarn”‰j<j@jKŒ v4l2_buffer”uh1hh³hÇh´KØhjòubhŒ ”…””}”(hjòh²hh³Nh´Nubhö)”}”(hŒ ``index``”h]”hŒindex”…””}”(hjWh²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hõhjòubhŒ4) plays no role here, it only identifies the buffer.”…””}”(hjòh²hh³Nh´Nubeh}”(h]”h ]”h"]”h$]”h&]”uh1hëh³hÇh´KØhjÄh²hubhì)”}”(hXgInitially all mapped buffers are in dequeued state, inaccessible by the driver. For capturing applications it is customary to first enqueue all mapped buffers, then to start capturing and enter the read loop. Here the application waits until a filled buffer can be dequeued, and re-enqueues the buffer when the data is no longer needed. Output applications fill and enqueue buffers, when enough buffers are stacked up the output is started with :ref:`VIDIOC_STREAMON `. In the write loop, when the application runs out of free buffers, it must wait until an empty buffer can be dequeued and reused.”h]”(hX½Initially all mapped buffers are in dequeued state, inaccessible by the driver. For capturing applications it is customary to first enqueue all mapped buffers, then to start capturing and enter the read loop. Here the application waits until a filled buffer can be dequeued, and re-enqueues the buffer when the data is no longer needed. Output applications fill and enqueue buffers, when enough buffers are stacked up the output is started with ”…””}”(hjoh²hh³Nh´Nubh)”}”(hŒ(:ref:`VIDIOC_STREAMON `”h]”jV)”}”(hjyh]”hŒVIDIOC_STREAMON”…””}”(hj{h²hh³Nh´Nubah}”(h]”h ]”(j)Œstd”Œstd-ref”eh"]”h$]”h&]”uh1jUhjwubah}”(h]”h ]”h"]”h$]”h&]”Œrefdoc”j6Œ refdomain”j…Œreftype”Œref”Œ refexplicit”ˆŒrefwarn”ˆjKŒvidioc_streamon”uh1hh³hÇh´KàhjoubhŒ‚. In the write loop, when the application runs out of free buffers, it must wait until an empty buffer can be dequeued and reused.”…””}”(hjoh²hh³Nh´Nubeh}”(h]”h ]”h"]”h$]”h&]”uh1hëh³hÇh´KàhjÄh²hubhì)”}”(hXÍTo enqueue and dequeue a buffer applications use the :ref:`VIDIOC_QBUF ` and :ref:`VIDIOC_DQBUF ` ioctl. The status of a buffer being mapped, enqueued, full or empty can be determined at any time using the :ref:`VIDIOC_QUERYBUF` ioctl. Two methods exist to suspend execution of the application until one or more buffers can be dequeued. By default :ref:`VIDIOC_DQBUF ` blocks when no buffer is in the outgoing queue. When the ``O_NONBLOCK`` flag was given to the :c:func:`open()` function, :ref:`VIDIOC_DQBUF ` returns immediately with an ``EAGAIN`` error code when no buffer is available. The :c:func:`select()` or :c:func:`poll()` functions are always available.”h]”(hŒ5To enqueue and dequeue a buffer applications use the ”…””}”(hj¡h²hh³Nh´Nubh)”}”(hŒ :ref:`VIDIOC_QBUF `”h]”jV)”}”(hj«h]”hŒ VIDIOC_QBUF”…””}”(hj­h²hh³Nh´Nubah}”(h]”h ]”(j)Œstd”Œstd-ref”eh"]”h$]”h&]”uh1jUhj©ubah}”(h]”h ]”h"]”h$]”h&]”Œrefdoc”j6Œ refdomain”j·Œreftype”Œref”Œ refexplicit”ˆŒrefwarn”ˆjKŒ vidioc_qbuf”uh1hh³hÇh´Kêhj¡ubhŒ and ”…””}”(hj¡h²hh³Nh´Nubh)”}”(hŒ!:ref:`VIDIOC_DQBUF `”h]”jV)”}”(hjÏh]”hŒ VIDIOC_DQBUF”…””}”(hjÑh²hh³Nh´Nubah}”(h]”h ]”(j)Œstd”Œstd-ref”eh"]”h$]”h&]”uh1jUhjÍubah}”(h]”h ]”h"]”h$]”h&]”Œrefdoc”j6Œ refdomain”jÛŒreftype”Œref”Œ refexplicit”ˆŒrefwarn”ˆjKŒ vidioc_qbuf”uh1hh³hÇh´Kêhj¡ubhŒm ioctl. The status of a buffer being mapped, enqueued, full or empty can be determined at any time using the ”…””}”(hj¡h²hh³Nh´Nubh)”}”(hŒ:ref:`VIDIOC_QUERYBUF`”h]”jV)”}”(hjóh]”hŒVIDIOC_QUERYBUF”…””}”(hjõh²hh³Nh´Nubah}”(h]”h ]”(j)Œstd”Œstd-ref”eh"]”h$]”h&]”uh1jUhjñubah}”(h]”h ]”h"]”h$]”h&]”Œrefdoc”j6Œ refdomain”jÿŒreftype”Œref”Œ refexplicit”‰Œrefwarn”ˆjKŒvidioc_querybuf”uh1hh³hÇh´Kêhj¡ubhŒy ioctl. Two methods exist to suspend execution of the application until one or more buffers can be dequeued. By default ”…””}”(hj¡h²hh³Nh´Nubh)”}”(hŒ!:ref:`VIDIOC_DQBUF `”h]”jV)”}”(hjh]”hŒ VIDIOC_DQBUF”…””}”(hjh²hh³Nh´Nubah}”(h]”h ]”(j)Œstd”Œstd-ref”eh"]”h$]”h&]”uh1jUhjubah}”(h]”h ]”h"]”h$]”h&]”Œrefdoc”j6Œ refdomain”j#Œreftype”Œref”Œ refexplicit”ˆŒrefwarn”ˆjKŒ vidioc_qbuf”uh1hh³hÇh´Kêhj¡ubhŒ: blocks when no buffer is in the outgoing queue. When the ”…””}”(hj¡h²hh³Nh´Nubhö)”}”(hŒ``O_NONBLOCK``”h]”hŒ O_NONBLOCK”…””}”(hj9h²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hõhj¡ubhŒ flag was given to the ”…””}”(hj¡h²hh³Nh´Nubh)”}”(hŒ:c:func:`open()`”h]”hö)”}”(hjMh]”hŒopen()”…””}”(hjOh²hh³Nh´Nubah}”(h]”h ]”(j)j*Œc-func”eh"]”h$]”h&]”uh1hõhjKubah}”(h]”h ]”h"]”h$]”h&]”Œrefdoc”j6Œ refdomain”j*Œreftype”Œfunc”Œ refexplicit”‰Œrefwarn”‰j<j@jKŒopen”uh1hh³hÇh´Kêhj¡ubhŒ function, ”…””}”(hj¡h²hh³Nh´Nubh)”}”(hŒ!:ref:`VIDIOC_DQBUF `”h]”jV)”}”(hjph]”hŒ VIDIOC_DQBUF”…””}”(hjrh²hh³Nh´Nubah}”(h]”h ]”(j)Œstd”Œstd-ref”eh"]”h$]”h&]”uh1jUhjnubah}”(h]”h ]”h"]”h$]”h&]”Œrefdoc”j6Œ refdomain”j|Œreftype”Œref”Œ refexplicit”ˆŒrefwarn”ˆjKŒ vidioc_qbuf”uh1hh³hÇh´Kêhj¡ubhŒ returns immediately with an ”…””}”(hj¡h²hh³Nh´Nubhö)”}”(hŒ ``EAGAIN``”h]”hŒEAGAIN”…””}”(hj’h²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hõhj¡ubhŒ- error code when no buffer is available. The ”…””}”(hj¡h²hh³Nh´Nubh)”}”(hŒ:c:func:`select()`”h]”hö)”}”(hj¦h]”hŒselect()”…””}”(hj¨h²hh³Nh´Nubah}”(h]”h ]”(j)j*Œc-func”eh"]”h$]”h&]”uh1hõhj¤ubah}”(h]”h ]”h"]”h$]”h&]”Œrefdoc”j6Œ refdomain”j*Œreftype”Œfunc”Œ refexplicit”‰Œrefwarn”‰j<j@jKŒselect”uh1hh³hÇh´Kêhj¡ubhŒ or ”…””}”(hj¡h²hh³Nh´Nubh)”}”(hŒ:c:func:`poll()`”h]”hö)”}”(hjÉh]”hŒpoll()”…””}”(hjËh²hh³Nh´Nubah}”(h]”h ]”(j)j*Œc-func”eh"]”h$]”h&]”uh1hõhjÇubah}”(h]”h ]”h"]”h$]”h&]”Œrefdoc”j6Œ refdomain”j*Œreftype”Œfunc”Œ refexplicit”‰Œrefwarn”‰j<j@jKŒpoll”uh1hh³hÇh´Kêhj¡ubhŒ functions are always available.”…””}”(hj¡h²hh³Nh´Nubeh}”(h]”h ]”h"]”h$]”h&]”uh1hëh³hÇh´KêhjÄh²hubhì)”}”(hŒ™To start and stop capturing or output applications call the :ref:`VIDIOC_STREAMON ` and :ref:`VIDIOC_STREAMOFF ` ioctl.”h]”(hŒ`”h]”jV)”}”(hjúh]”hŒVIDIOC_STREAMON”…””}”(hjüh²hh³Nh´Nubah}”(h]”h ]”(j)Œstd”Œstd-ref”eh"]”h$]”h&]”uh1jUhjøubah}”(h]”h ]”h"]”h$]”h&]”Œrefdoc”j6Œ refdomain”jŒreftype”Œref”Œ refexplicit”ˆŒrefwarn”ˆjKŒvidioc_streamon”uh1hh³hÇh´KöhjðubhŒ and ”…””}”(hjðh²hh³Nh´Nubh)”}”(hŒ):ref:`VIDIOC_STREAMOFF `”h]”jV)”}”(hjh]”hŒVIDIOC_STREAMOFF”…””}”(hj h²hh³Nh´Nubah}”(h]”h ]”(j)Œstd”Œstd-ref”eh"]”h$]”h&]”uh1jUhjubah}”(h]”h ]”h"]”h$]”h&]”Œrefdoc”j6Œ refdomain”j*Œreftype”Œref”Œ refexplicit”ˆŒrefwarn”ˆjKŒvidioc_streamon”uh1hh³hÇh´KöhjðubhŒ ioctl.”…””}”(hjðh²hh³Nh´Nubeh}”(h]”h ]”h"]”h$]”h&]”uh1hëh³hÇh´KöhjÄh²hubh¶)”}”(hXOnote:::ref:`VIDIOC_STREAMOFF ` removes all buffers from both queues as a side effect. Since there is no notion of doing anything "now" on a multitasking system, if an application needs to synchronize with another event it should examine the struct ::c:type:`v4l2_buffer` ``timestamp`` of captured or outputted buffers.”h]”hXOnote:::ref:`VIDIOC_STREAMOFF ` removes all buffers from both queues as a side effect. Since there is no notion of doing anything "now" on a multitasking system, if an application needs to synchronize with another event it should examine the struct ::c:type:`v4l2_buffer` ``timestamp`` of captured or outputted buffers.”…””}”hjFsbah}”(h]”h ]”h"]”h$]”h&]”hÅhÆuh1hµhjÄh²hh³hÇh´Mubhì)”}”(hX¥Drivers implementing memory mapping I/O must support the :ref:`VIDIOC_REQBUFS `, :ref:`VIDIOC_QUERYBUF `, :ref:`VIDIOC_QBUF `, :ref:`VIDIOC_DQBUF `, :ref:`VIDIOC_STREAMON ` and :ref:`VIDIOC_STREAMOFF ` ioctls, the :ref:`mmap() `, :c:func:`munmap()`, :ref:`select() ` and :c:func:`poll()` function. [#f3]_”h]”(hŒ9Drivers implementing memory mapping I/O must support the ”…””}”(hjTh²hh³Nh´Nubh)”}”(hŒ&:ref:`VIDIOC_REQBUFS `”h]”jV)”}”(hj^h]”hŒVIDIOC_REQBUFS”…””}”(hj`h²hh³Nh´Nubah}”(h]”h ]”(j)Œstd”Œstd-ref”eh"]”h$]”h&]”uh1jUhj\ubah}”(h]”h ]”h"]”h$]”h&]”Œrefdoc”j6Œ refdomain”jjŒreftype”Œref”Œ refexplicit”ˆŒrefwarn”ˆjKŒvidioc_reqbufs”uh1hh³hÇh´MhjTubhŒ, ”…””}”(hjTh²hh³Nh´Nubh)”}”(hŒ(:ref:`VIDIOC_QUERYBUF `”h]”jV)”}”(hj‚h]”hŒVIDIOC_QUERYBUF”…””}”(hj„h²hh³Nh´Nubah}”(h]”h ]”(j)Œstd”Œstd-ref”eh"]”h$]”h&]”uh1jUhj€ubah}”(h]”h ]”h"]”h$]”h&]”Œrefdoc”j6Œ refdomain”jŽŒreftype”Œref”Œ refexplicit”ˆŒrefwarn”ˆjKŒvidioc_querybuf”uh1hh³hÇh´MhjTubhŒ, ”…””}”hjTsbh)”}”(hŒ :ref:`VIDIOC_QBUF `”h]”jV)”}”(hj¦h]”hŒ VIDIOC_QBUF”…””}”(hj¨h²hh³Nh´Nubah}”(h]”h ]”(j)Œstd”Œstd-ref”eh"]”h$]”h&]”uh1jUhj¤ubah}”(h]”h ]”h"]”h$]”h&]”Œrefdoc”j6Œ refdomain”j²Œreftype”Œref”Œ refexplicit”ˆŒrefwarn”ˆjKŒ vidioc_qbuf”uh1hh³hÇh´MhjTubhŒ, ”…””}”hjTsbh)”}”(hŒ!:ref:`VIDIOC_DQBUF `”h]”jV)”}”(hjÊh]”hŒ VIDIOC_DQBUF”…””}”(hjÌh²hh³Nh´Nubah}”(h]”h ]”(j)Œstd”Œstd-ref”eh"]”h$]”h&]”uh1jUhjÈubah}”(h]”h ]”h"]”h$]”h&]”Œrefdoc”j6Œ refdomain”jÖŒreftype”Œref”Œ refexplicit”ˆŒrefwarn”ˆjKŒ vidioc_qbuf”uh1hh³hÇh´MhjTubhŒ, ”…””}”hjTsbh)”}”(hŒ(:ref:`VIDIOC_STREAMON `”h]”jV)”}”(hjîh]”hŒVIDIOC_STREAMON”…””}”(hjðh²hh³Nh´Nubah}”(h]”h ]”(j)Œstd”Œstd-ref”eh"]”h$]”h&]”uh1jUhjìubah}”(h]”h ]”h"]”h$]”h&]”Œrefdoc”j6Œ refdomain”júŒreftype”Œref”Œ refexplicit”ˆŒrefwarn”ˆjKŒvidioc_streamon”uh1hh³hÇh´MhjTubhŒ and ”…””}”(hjTh²hh³Nh´Nubh)”}”(hŒ):ref:`VIDIOC_STREAMOFF `”h]”jV)”}”(hjh]”hŒVIDIOC_STREAMOFF”…””}”(hjh²hh³Nh´Nubah}”(h]”h ]”(j)Œstd”Œstd-ref”eh"]”h$]”h&]”uh1jUhjubah}”(h]”h ]”h"]”h$]”h&]”Œrefdoc”j6Œ refdomain”jŒreftype”Œref”Œ refexplicit”ˆŒrefwarn”ˆjKŒvidioc_streamon”uh1hh³hÇh´MhjTubhŒ ioctls, the ”…””}”(hjTh²hh³Nh´Nubh)”}”(hŒ:ref:`mmap() `”h]”jV)”}”(hj6h]”hŒmmap()”…””}”(hj8h²hh³Nh´Nubah}”(h]”h ]”(j)Œstd”Œstd-ref”eh"]”h$]”h&]”uh1jUhj4ubah}”(h]”h ]”h"]”h$]”h&]”Œrefdoc”j6Œ refdomain”jBŒreftype”Œref”Œ refexplicit”ˆŒrefwarn”ˆjKŒ func-mmap”uh1hh³hÇh´MhjTubhŒ, ”…””}”hjTsbh)”}”(hŒ:c:func:`munmap()`”h]”hö)”}”(hjZh]”hŒmunmap()”…””}”(hj\h²hh³Nh´Nubah}”(h]”h ]”(j)j*Œc-func”eh"]”h$]”h&]”uh1hõhjXubah}”(h]”h ]”h"]”h$]”h&]”Œrefdoc”j6Œ refdomain”j*Œreftype”Œfunc”Œ refexplicit”‰Œrefwarn”‰j<j@jKŒmunmap”uh1hh³hÇh´MhjTubhŒ, ”…””}”hjTsbh)”}”(hŒ:ref:`select() `”h]”jV)”}”(hj}h]”hŒselect()”…””}”(hjh²hh³Nh´Nubah}”(h]”h ]”(j)Œstd”Œstd-ref”eh"]”h$]”h&]”uh1jUhj{ubah}”(h]”h ]”h"]”h$]”h&]”Œrefdoc”j6Œ refdomain”j‰Œreftype”Œref”Œ refexplicit”ˆŒrefwarn”ˆjKŒ func-select”uh1hh³hÇh´MhjTubhŒ and ”…””}”(hjTh²hh³Nh´Nubh)”}”(hŒ:c:func:`poll()`”h]”hö)”}”(hj¡h]”hŒpoll()”…””}”(hj£h²hh³Nh´Nubah}”(h]”h ]”(j)j*Œc-func”eh"]”h$]”h&]”uh1hõhjŸubah}”(h]”h ]”h"]”h$]”h&]”Œrefdoc”j6Œ refdomain”j*Œreftype”Œfunc”Œ refexplicit”‰Œrefwarn”‰j<j@jKŒpoll”uh1hh³hÇh´MhjTubhŒ function. ”…””}”(hjTh²hh³Nh´NubjÊ)”}”(hŒ[#f3]_”h]”hŒ3”…””}”(hjÂh²hh³Nh´Nubah}”(h]”Œid3”ah ]”h"]”h$]”h&]”jÚKhÔŒf3”jÜj6uh1jÉhjTjÝKubeh}”(h]”h ]”h"]”h$]”h&]”uh1hëh³hÇh´MhjÄh²hubhì)”}”(hŒ[capture example]”h]”hŒ[capture example]”…””}”(hjØh²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hëh³hÇh´M hjÄh²hubhŒfootnote”“”)”}”(hXbOne could use one file descriptor and set the buffer type field accordingly when calling :ref:`VIDIOC_QBUF` etc., but it makes the :c:func:`select()` function ambiguous. We also like the clean approach of one file descriptor per logical stream. Video overlay for example is also a logical stream, although the CPU is not needed for continuous operation. ”h]”(hŒlabel”“”)”}”(hhh]”hŒ1”…””}”(hjîh²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1jìhjèh²hh³Nh´Nubhì)”}”(hXaOne could use one file descriptor and set the buffer type field accordingly when calling :ref:`VIDIOC_QBUF` etc., but it makes the :c:func:`select()` function ambiguous. We also like the clean approach of one file descriptor per logical stream. Video overlay for example is also a logical stream, although the CPU is not needed for continuous operation.”h]”(hŒYOne could use one file descriptor and set the buffer type field accordingly when calling ”…””}”(hjûh²hh³Nh´Nubh)”}”(hŒ:ref:`VIDIOC_QBUF`”h]”jV)”}”(hjh]”hŒ VIDIOC_QBUF”…””}”(hjh²hh³Nh´Nubah}”(h]”h ]”(j)Œstd”Œstd-ref”eh"]”h$]”h&]”uh1jUhjubah}”(h]”h ]”h"]”h$]”h&]”Œrefdoc”j6Œ refdomain”jŒreftype”Œref”Œ refexplicit”‰Œrefwarn”ˆjKŒ vidioc_qbuf”uh1hh³hÇh´M hjûubhŒ etc., but it makes the ”…””}”(hjûh²hh³Nh´Nubh)”}”(hŒ:c:func:`select()`”h]”hö)”}”(hj)h]”hŒselect()”…””}”(hj+h²hh³Nh´Nubah}”(h]”h ]”(j)j*Œc-func”eh"]”h$]”h&]”uh1hõhj'ubah}”(h]”h ]”h"]”h$]”h&]”Œrefdoc”j6Œ refdomain”j*Œreftype”Œfunc”Œ refexplicit”‰Œrefwarn”‰j<j@jKŒselect”uh1hh³hÇh´M hjûubhŒÌ function ambiguous. We also like the clean approach of one file descriptor per logical stream. Video overlay for example is also a logical stream, although the CPU is not needed for continuous operation.”…””}”(hjûh²hh³Nh´Nubeh}”(h]”h ]”h"]”h$]”h&]”uh1hëh³hÇh´M hjèubeh}”(h]”jÛah ]”h"]”Œf1”ah$]”h&]”jÕajÚKjÜj6uh1jæh³hÇh´M hjÄh²hubjç)”}”(hX+Random enqueue order permits applications processing images out of order (such as video codecs) to return buffers earlier, reducing the probability of data loss. Random fill order allows drivers to reuse buffers on a LIFO-basis, taking advantage of caches holding scatter-gather lists and the like. ”h]”(jí)”}”(hhh]”hŒ2”…””}”(hj[h²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1jìhjWh²hh³Nh´Nubhì)”}”(hX*Random enqueue order permits applications processing images out of order (such as video codecs) to return buffers earlier, reducing the probability of data loss. Random fill order allows drivers to reuse buffers on a LIFO-basis, taking advantage of caches holding scatter-gather lists and the like.”h]”hX*Random enqueue order permits applications processing images out of order (such as video codecs) to return buffers earlier, reducing the probability of data loss. Random fill order allows drivers to reuse buffers on a LIFO-basis, taking advantage of caches holding scatter-gather lists and the like.”…””}”(hjhh²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1hëh³hÇh´MhjWubeh}”(h]”j/ah ]”h"]”Œf2”ah$]”h&]”j*ajÚKjÜj6uh1jæh³hÇh´MhjÄh²hubjç)”}”(hŒAt the driver level :c:func:`select()` and :c:func:`poll()` are the same, and :c:func:`select()` is too important to be optional. The rest should be evident.”h]”(jí)”}”(hhh]”hŒ3”…””}”(hjh²hh³Nh´Nubah}”(h]”h ]”h"]”h$]”h&]”uh1jìhj}h²hh³Nh´Nubhì)”}”(hŒAt the driver level :c:func:`select()` and :c:func:`poll()` are the same, and :c:func:`select()` is too important to be optional. The rest should be evident.”h]”(hŒAt the driver level ”…””}”(hjŽh²hh³Nh´Nubh)”}”(hŒ:c:func:`select()`”h]”hö)”}”(hj˜h]”hŒselect()”…””}”(hjšh²hh³Nh´Nubah}”(h]”h ]”(j)j*Œc-func”eh"]”h$]”h&]”uh1hõhj–ubah}”(h]”h ]”h"]”h$]”h&]”Œrefdoc”j6Œ refdomain”j*Œreftype”Œfunc”Œ refexplicit”‰Œrefwarn”‰j<j@jKŒselect”uh1hh³hÇh´MhjŽubhŒ and ”…””}”(hjŽh²hh³Nh´Nubh)”}”(hŒ:c:func:`poll()`”h]”hö)”}”(hj»h]”hŒpoll()”…””}”(hj½h²hh³Nh´Nubah}”(h]”h ]”(j)j*Œc-func”eh"]”h$]”h&]”uh1hõhj¹ubah}”(h]”h ]”h"]”h$]”h&]”Œrefdoc”j6Œ refdomain”j*Œreftype”Œfunc”Œ refexplicit”‰Œrefwarn”‰j<j@jKŒpoll”uh1hh³hÇh´MhjŽubhŒ are the same, and ”…””}”(hjŽh²hh³Nh´Nubh)”}”(hŒ:c:func:`select()`”h]”hö)”}”(hjÞh]”hŒselect()”…””}”(hjàh²hh³Nh´Nubah}”(h]”h ]”(j)j*Œc-func”eh"]”h$]”h&]”uh1hõhjÜubah}”(h]”h ]”h"]”h$]”h&]”Œrefdoc”j6Œ refdomain”j*Œreftype”Œfunc”Œ refexplicit”‰Œrefwarn”‰j<j@jKŒselect”uh1hh³hÇh´MhjŽubhŒ= is too important to be optional. The rest should be evident.”…””}”(hjŽh²hh³Nh´Nubeh}”(h]”h ]”h"]”h$]”h&]”uh1hëh³hÇh´Mhj}ubeh}”(h]”jÑah ]”h"]”Œf3”ah$]”h&]”jÌajÚKjÜj6uh1jæh³hÇh´MhjÄh²hubeh}”(h]”Œ/example-mapping-buffers-in-the-multi-planar-api”ah ]”h"]”Œ0example: mapping buffers in the multi-planar api”ah$]”h&]”uh1hÖhhØh²hh³hÇh´Kubeh}”(h]”(Œstreaming-i-o-memory-mapping”hÕeh ]”h"]”(Œstreaming i/o (memory mapping)”Œmmap”eh$]”h&]”uh1hÖhhh²hh³hÇh´KŒexpect_referenced_by_name”}”j hÊsŒexpect_referenced_by_id”}”hÕhÊsubeh}”(h]”h ]”h"]”h$]”h&]”Œsource”hÇuh1hŒcurrent_source”NŒ current_line”NŒsettings”Œdocutils.frontend”ŒValues”“”)”}”(hÛNŒ generator”NŒ datestamp”NŒ source_link”NŒ source_url”NŒ toc_backlinks”Œentry”Œfootnote_backlinks”KŒ sectnum_xform”KŒstrip_comments”NŒstrip_elements_with_classes”NŒ strip_classes”NŒ report_level”KŒ halt_level”KŒexit_status_level”KŒdebug”NŒwarning_stream”NŒ traceback”ˆŒinput_encoding”Œ utf-8-sig”Œinput_encoding_error_handler”Œstrict”Œoutput_encoding”Œutf-8”Œoutput_encoding_error_handler”jD Œerror_encoding”Œutf-8”Œerror_encoding_error_handler”Œbackslashreplace”Œ language_code”Œen”Œrecord_dependencies”NŒconfig”NŒ id_prefix”hŒauto_id_prefix”Œid”Œ dump_settings”NŒdump_internals”NŒdump_transforms”NŒdump_pseudo_xml”NŒexpose_internals”NŒstrict_visitor”NŒ_disable_config”NŒ_source”hÇŒ _destination”NŒ _config_files”]”Œ7/var/lib/git/docbuild/linux/Documentation/docutils.conf”aŒfile_insertion_enabled”ˆŒ raw_enabled”KŒline_length_limit”M'Œpep_references”NŒ pep_base_url”Œhttps://peps.python.org/”Œpep_file_url_template”Œpep-%04d”Œrfc_references”NŒ rfc_base_url”Œ&https://datatracker.ietf.org/doc/html/”Œ tab_width”KŒtrim_footnote_reference_space”‰Œsyntax_highlight”Œlong”Œ smart_quotes”ˆŒsmartquotes_locales”]”Œcharacter_level_inline_markup”‰Œdoctitle_xform”‰Œ docinfo_xform”KŒsectsubtitle_xform”‰Œ image_loading”Œlink”Œembed_stylesheet”‰Œcloak_email_addresses”ˆŒsection_self_link”‰Œenv”NubŒreporter”NŒindirect_targets”]”Œsubstitution_defs”}”Œsubstitution_names”}”Œrefnames”}”(Œf1”]”jËaŒf2”]”j aŒf3”]”jÂauŒrefids”}”(hÕ]”hÊajÛ]”jËaj/]”j ajÑ]”jÂauŒnameids”}”(j hÕj j jÁj¾j j jTjÛjzj/j jÑuŒ nametypes”}”(j ˆj ‰jÁ‰j ‰jTˆjzˆj ˆuh}”(hÕhØj hØjÕjËj¾j—j jÄj*j jÌjÂjÛjèj/jWjÑj}uŒ footnote_refs”}”(j„ ]”jËaj† ]”j ajˆ ]”jÂauŒ citation_refs”}”Œ autofootnotes”]”(jèjWj}eŒautofootnote_refs”]”(jËj jÂeŒsymbol_footnotes”]”Œsymbol_footnote_refs”]”Œ footnotes”]”Œ citations”]”Œautofootnote_start”KŒsymbol_footnote_start”KŒ id_counter”Œ collections”ŒCounter”“”}”jR Ks…”R”Œparse_messages”]”Œtransform_messages”]”hŒsystem_message”“”)”}”(hhh]”hì)”}”(hhh]”hŒ*Hyperlink target "mmap" is not referenced.”…””}”hjº sbah}”(h]”h ]”h"]”h$]”h&]”uh1hëhj· ubah}”(h]”h ]”h"]”h$]”h&]”Œlevel”KŒtype”ŒINFO”Œsource”hÇŒline”Kuh1jµ ubaŒ transformer”NŒ include_log”]”Œ decoration”Nh²hub.