€•Ä­Œ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Œ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”…””}”(hhõ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â)”}”(hj h]”hŒv4l2_capability”…””}”(hj hž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”“”)”}”(hj?h]”hŒVIDIOC_QUERYCAP”…””}”(hjChžhhŸNh Nubah}”(h]”h ]”(jŒstd”Œstd-ref”eh"]”h$]”h&]”uh1jAhj=ubah}”(h]”h ]”h"]”h$]”h&]”Œrefdoc”j"Œ refdomain”jMŒreftype”Œref”Œ refexplicit”‰Œrefwarn”ˆj7Œ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]”jB)”}”(hjeh]”hŒVIDIOC_REQBUFS”…””}”(hjghžhhŸNh Nubah}”(h]”h ]”(jŒstd”Œstd-ref”eh"]”h$]”h&]”uh1jAhjcubah}”(h]”h ]”h"]”h$]”h&]”Œrefdoc”j"Œ refdomain”jqŒreftype”Œref”Œ refexplicit”‰Œrefwarn”ˆj7Œ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”j"uh1jµ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]”jB)”}”(hjÚh]”hŒVIDIOC_REQBUFS”…””}”(hjÜhžhhŸNh Nubah}”(h]”h ]”(jŒstd”Œstd-ref”eh"]”h$]”h&]”uh1jAhjØubah}”(h]”h ]”h"]”h$]”h&]”Œrefdoc”j"Œ refdomain”jæŒreftype”Œref”Œ refexplicit”‰Œrefwarn”ˆj7Œ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”…””}”(hjühž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 ”…””}”(hjhžhhŸNh Nubh)”}”(hŒ:c:func:`mmap()`”h]”hâ)”}”(hjh]”hŒmmap()”…””}”(hj hžhhŸNh Nubah}”(h]”h ]”(jjŒc-func”eh"]”h$]”h&]”uh1háhjubah}”(h]”h ]”h"]”h$]”h&]”Œrefdoc”j"Œ refdomain”jŒreftype”Œfunc”Œ refexplicit”‰Œrefwarn”‰j(j,j7Œmmap”uh1hhŸh³h K&hjubhŒS function. The location of the buffers in device memory can be determined with the ”…””}”(hjhžhhŸNh Nubh)”}”(hŒ:ref:`VIDIOC_QUERYBUF`”h]”jB)”}”(hjAh]”hŒVIDIOC_QUERYBUF”…””}”(hjChžhhŸNh Nubah}”(h]”h ]”(jŒstd”Œstd-ref”eh"]”h$]”h&]”uh1jAhj?ubah}”(h]”h ]”h"]”h$]”h&]”Œrefdoc”j"Œ refdomain”jMŒreftype”Œref”Œ refexplicit”‰Œrefwarn”ˆj7Œvidioc_querybuf”uh1hhŸh³h K&hjubhŒ+ ioctl. In the single-planar API case, the ”…””}”(hjhžhhŸNh Nubhâ)”}”(hŒ ``m.offset``”h]”hŒm.offset”…””}”(hjchžhhŸNh Nubah}”(h]”h ]”h"]”h$]”h&]”uh1háhjubhŒ and ”…””}”(hjhžhhŸNh Nubhâ)”}”(hŒ ``length``”h]”hŒlength”…””}”(hjuhžhhŸNh Nubah}”(h]”h ]”h"]”h$]”h&]”uh1háhjubhŒ returned in a struct ”…””}”(hjhžhhŸNh Nubh)”}”(hŒ:c:type:`v4l2_buffer`”h]”hâ)”}”(hj‰h]”hŒ v4l2_buffer”…””}”(hj‹hžhhŸNh Nubah}”(h]”h ]”(jjŒc-type”eh"]”h$]”h&]”uh1háhj‡ubah}”(h]”h ]”h"]”h$]”h&]”Œrefdoc”j"Œ refdomain”jŒreftype”Œtype”Œ refexplicit”‰Œrefwarn”‰j(j,j7Œ v4l2_buffer”uh1hhŸh³h K&hjubhŒ1 are passed as sixth and second parameter to the ”…””}”(hjhžhhŸNh Nubh)”}”(hŒ:c:func:`mmap()`”h]”hâ)”}”(hj¬h]”hŒmmap()”…””}”(hj®hžhhŸNh Nubah}”(h]”h ]”(jjŒc-func”eh"]”h$]”h&]”uh1háhjªubah}”(h]”h ]”h"]”h$]”h&]”Œrefdoc”j"Œ refdomain”jŒreftype”Œfunc”Œ refexplicit”‰Œrefwarn”‰j(j,j7Œmmap”uh1hhŸh³h K&hjubhŒ3 function. When using the multi-planar API, struct ”…””}”(hjhžhhŸNh Nubh)”}”(hŒ:c:type:`v4l2_buffer`”h]”hâ)”}”(hjÏh]”hŒ v4l2_buffer”…””}”(hjÑhžhhŸNh Nubah}”(h]”h ]”(jjŒc-type”eh"]”h$]”h&]”uh1háhjÍubah}”(h]”h ]”h"]”h$]”h&]”Œrefdoc”j"Œ refdomain”jŒreftype”Œtype”Œ refexplicit”‰Œrefwarn”‰j(j,j7Œ v4l2_buffer”uh1hhŸh³h K&hjubhŒ contains an array of struct ”…””}”(hjhžhhŸNh Nubh)”}”(hŒ:c:type:`v4l2_plane`”h]”hâ)”}”(hjòh]”hŒ v4l2_plane”…””}”(hjôhžhhŸNh Nubah}”(h]”h ]”(jjŒc-type”eh"]”h$]”h&]”uh1háhjðubah}”(h]”h ]”h"]”h$]”h&]”Œrefdoc”j"Œ refdomain”jŒreftype”Œtype”Œ refexplicit”‰Œrefwarn”‰j(j,j7Œ v4l2_plane”uh1hhŸh³h K&hjubhŒ% structures, each containing its own ”…””}”(hjhžhhŸNh Nubhâ)”}”(hŒ ``m.offset``”h]”hŒm.offset”…””}”(hjhžhhŸNh Nubah}”(h]”h ]”h"]”h$]”h&]”uh1háhjubhŒ and ”…””}”hjsbhâ)”}”(hŒ ``length``”h]”hŒlength”…””}”(hj%hžhhŸNh Nubah}”(h]”h ]”h"]”h$]”h&]”uh1háhjubhŒv. When using the multi-planar API, every plane of every buffer has to be mapped separately, so the number of calls to ”…””}”(hjhžhhŸNh Nubh)”}”(hŒ:c:func:`mmap()`”h]”hâ)”}”(hj9h]”hŒmmap()”…””}”(hj;hžhhŸNh Nubah}”(h]”h ]”(jjŒc-func”eh"]”h$]”h&]”uh1háhj7ubah}”(h]”h ]”h"]”h$]”h&]”Œrefdoc”j"Œ refdomain”jŒreftype”Œfunc”Œ refexplicit”‰Œrefwarn”‰j(j,j7Œmmap”uh1hhŸh³h K&hjubhX: 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 ”…””}”(hjhžhhŸNh Nubh)”}”(hŒ:c:func:`munmap()`”h]”hâ)”}”(hj\h]”hŒmunmap()”…””}”(hj^hžhhŸNh Nubah}”(h]”h ]”(jjŒc-func”eh"]”h$]”h&]”uh1háhjZubah}”(h]”h ]”h"]”h$]”h&]”Œrefdoc”j"Œ refdomain”jŒreftype”Œfunc”Œ refexplicit”‰Œrefwarn”‰j(j,j7Œmunmap”uh1hhŸh³h K&hjubhŒ function.”…””}”(hjhž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¥jj¦}”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”…””}”(hjúhž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Èj"uh1jµhjÞjÉKubhŒ& The index number of a buffer (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 ]”(jjŒc-type”eh"]”h$]”h&]”uh1háhj ubah}”(h]”h ]”h"]”h$]”h&]”Œrefdoc”j"Œ refdomain”jŒreftype”Œtype”Œ refexplicit”‰Œrefwarn”‰j(j,j7Œ v4l2_buffer”uh1hhŸh³h KØhjÞubhŒ ”…””}”(hjÞhžhhŸNh Nubhâ)”}”(hŒ ``index``”h]”hŒindex”…””}”(hjChž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 ”…””}”(hj[hžhhŸNh Nubh)”}”(hŒ(:ref:`VIDIOC_STREAMON `”h]”jB)”}”(hjeh]”hŒVIDIOC_STREAMON”…””}”(hjghžhhŸNh Nubah}”(h]”h ]”(jŒstd”Œstd-ref”eh"]”h$]”h&]”uh1jAhjcubah}”(h]”h ]”h"]”h$]”h&]”Œrefdoc”j"Œ refdomain”jqŒreftype”Œref”Œ refexplicit”ˆŒrefwarn”ˆj7Œvidioc_streamon”uh1hhŸh³h Kàhj[ubhŒ‚. In the write loop, when the application runs out of free buffers, it must wait until an empty buffer can be dequeued and reused.”…””}”(hj[hž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 ”…””}”(hjhžhhŸNh Nubh)”}”(hŒ :ref:`VIDIOC_QBUF `”h]”jB)”}”(hj—h]”hŒ VIDIOC_QBUF”…””}”(hj™hžhhŸNh Nubah}”(h]”h ]”(jŒstd”Œstd-ref”eh"]”h$]”h&]”uh1jAhj•ubah}”(h]”h ]”h"]”h$]”h&]”Œrefdoc”j"Œ refdomain”j£Œreftype”Œref”Œ refexplicit”ˆŒrefwarn”ˆj7Œ vidioc_qbuf”uh1hhŸh³h KêhjubhŒ and ”…””}”(hjhžhhŸNh Nubh)”}”(hŒ!:ref:`VIDIOC_DQBUF `”h]”jB)”}”(hj»h]”hŒ VIDIOC_DQBUF”…””}”(hj½hžhhŸNh Nubah}”(h]”h ]”(jŒstd”Œstd-ref”eh"]”h$]”h&]”uh1jAhj¹ubah}”(h]”h ]”h"]”h$]”h&]”Œrefdoc”j"Œ refdomain”jÇŒreftype”Œref”Œ refexplicit”ˆŒrefwarn”ˆj7Œ vidioc_qbuf”uh1hhŸh³h KêhjubhŒm ioctl. The status of a buffer being mapped, enqueued, full or empty can be determined at any time using the ”…””}”(hjhžhhŸNh Nubh)”}”(hŒ:ref:`VIDIOC_QUERYBUF`”h]”jB)”}”(hjßh]”hŒVIDIOC_QUERYBUF”…””}”(hjáhžhhŸNh Nubah}”(h]”h ]”(jŒstd”Œstd-ref”eh"]”h$]”h&]”uh1jAhjÝubah}”(h]”h ]”h"]”h$]”h&]”Œrefdoc”j"Œ refdomain”jëŒreftype”Œref”Œ refexplicit”‰Œrefwarn”ˆj7Œvidioc_querybuf”uh1hhŸh³h KêhjubhŒy ioctl. Two methods exist to suspend execution of the application until one or more buffers can be dequeued. By default ”…””}”(hjhžhhŸNh Nubh)”}”(hŒ!:ref:`VIDIOC_DQBUF `”h]”jB)”}”(hjh]”hŒ VIDIOC_DQBUF”…””}”(hjhžhhŸNh Nubah}”(h]”h ]”(jŒstd”Œstd-ref”eh"]”h$]”h&]”uh1jAhjubah}”(h]”h ]”h"]”h$]”h&]”Œrefdoc”j"Œ refdomain”jŒreftype”Œref”Œ refexplicit”ˆŒrefwarn”ˆj7Œ vidioc_qbuf”uh1hhŸh³h KêhjubhŒ: blocks when no buffer is in the outgoing queue. When the ”…””}”(hjhžhhŸNh Nubhâ)”}”(hŒ``O_NONBLOCK``”h]”hŒ O_NONBLOCK”…””}”(hj%hžhhŸNh Nubah}”(h]”h ]”h"]”h$]”h&]”uh1háhjubhŒ flag was given to the ”…””}”(hjhžhhŸNh Nubh)”}”(hŒ:c:func:`open()`”h]”hâ)”}”(hj9h]”hŒopen()”…””}”(hj;hžhhŸNh Nubah}”(h]”h ]”(jjŒc-func”eh"]”h$]”h&]”uh1háhj7ubah}”(h]”h ]”h"]”h$]”h&]”Œrefdoc”j"Œ refdomain”jŒreftype”Œfunc”Œ refexplicit”‰Œrefwarn”‰j(j,j7Œopen”uh1hhŸh³h KêhjubhŒ function, ”…””}”(hjhžhhŸNh Nubh)”}”(hŒ!:ref:`VIDIOC_DQBUF `”h]”jB)”}”(hj\h]”hŒ VIDIOC_DQBUF”…””}”(hj^hžhhŸNh Nubah}”(h]”h ]”(jŒstd”Œstd-ref”eh"]”h$]”h&]”uh1jAhjZubah}”(h]”h ]”h"]”h$]”h&]”Œrefdoc”j"Œ refdomain”jhŒreftype”Œref”Œ refexplicit”ˆŒrefwarn”ˆj7Œ vidioc_qbuf”uh1hhŸh³h KêhjubhŒ returns immediately with an ”…””}”(hjhžhhŸNh Nubhâ)”}”(hŒ ``EAGAIN``”h]”hŒEAGAIN”…””}”(hj~hžhhŸNh Nubah}”(h]”h ]”h"]”h$]”h&]”uh1háhjubhŒ- error code when no buffer is available. The ”…””}”(hjhžhhŸNh Nubh)”}”(hŒ:c:func:`select()`”h]”hâ)”}”(hj’h]”hŒselect()”…””}”(hj”hžhhŸNh Nubah}”(h]”h ]”(jjŒc-func”eh"]”h$]”h&]”uh1háhjubah}”(h]”h ]”h"]”h$]”h&]”Œrefdoc”j"Œ refdomain”jŒreftype”Œfunc”Œ refexplicit”‰Œrefwarn”‰j(j,j7Œselect”uh1hhŸh³h KêhjubhŒ or ”…””}”(hjhžhhŸNh Nubh)”}”(hŒ:c:func:`poll()`”h]”hâ)”}”(hjµh]”hŒpoll()”…””}”(hj·hžhhŸNh Nubah}”(h]”h ]”(jjŒc-func”eh"]”h$]”h&]”uh1háhj³ubah}”(h]”h ]”h"]”h$]”h&]”Œrefdoc”j"Œ refdomain”jŒreftype”Œfunc”Œ refexplicit”‰Œrefwarn”‰j(j,j7Œpoll”uh1hhŸh³h KêhjubhŒ functions are always available.”…””}”(hjhž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]”jB)”}”(hjæh]”hŒVIDIOC_STREAMON”…””}”(hjèhžhhŸNh Nubah}”(h]”h ]”(jŒstd”Œstd-ref”eh"]”h$]”h&]”uh1jAhjäubah}”(h]”h ]”h"]”h$]”h&]”Œrefdoc”j"Œ refdomain”jòŒreftype”Œref”Œ refexplicit”ˆŒrefwarn”ˆj7Œvidioc_streamon”uh1hhŸh³h KöhjÜubhŒ and ”…””}”(hjÜhžhhŸNh Nubh)”}”(hŒ):ref:`VIDIOC_STREAMOFF `”h]”jB)”}”(hj h]”hŒVIDIOC_STREAMOFF”…””}”(hj hžhhŸNh Nubah}”(h]”h ]”(jŒstd”Œstd-ref”eh"]”h$]”h&]”uh1jAhjubah}”(h]”h ]”h"]”h$]”h&]”Œrefdoc”j"Œ refdomain”jŒreftype”Œref”Œ refexplicit”ˆŒrefwarn”ˆj7Œ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.”…””}”hj2sbah}”(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 ”…””}”(hj@hžhhŸNh Nubh)”}”(hŒ&:ref:`VIDIOC_REQBUFS `”h]”jB)”}”(hjJh]”hŒVIDIOC_REQBUFS”…””}”(hjLhžhhŸNh Nubah}”(h]”h ]”(jŒstd”Œstd-ref”eh"]”h$]”h&]”uh1jAhjHubah}”(h]”h ]”h"]”h$]”h&]”Œrefdoc”j"Œ refdomain”jVŒreftype”Œref”Œ refexplicit”ˆŒrefwarn”ˆj7Œvidioc_reqbufs”uh1hhŸh³h Mhj@ubhŒ, ”…””}”(hj@hžhhŸNh Nubh)”}”(hŒ(:ref:`VIDIOC_QUERYBUF `”h]”jB)”}”(hjnh]”hŒVIDIOC_QUERYBUF”…””}”(hjphžhhŸNh Nubah}”(h]”h ]”(jŒstd”Œstd-ref”eh"]”h$]”h&]”uh1jAhjlubah}”(h]”h ]”h"]”h$]”h&]”Œrefdoc”j"Œ refdomain”jzŒreftype”Œref”Œ refexplicit”ˆŒrefwarn”ˆj7Œvidioc_querybuf”uh1hhŸh³h Mhj@ubhŒ, ”…””}”hj@sbh)”}”(hŒ :ref:`VIDIOC_QBUF `”h]”jB)”}”(hj’h]”hŒ VIDIOC_QBUF”…””}”(hj”hžhhŸNh Nubah}”(h]”h ]”(jŒstd”Œstd-ref”eh"]”h$]”h&]”uh1jAhjubah}”(h]”h ]”h"]”h$]”h&]”Œrefdoc”j"Œ refdomain”jžŒreftype”Œref”Œ refexplicit”ˆŒrefwarn”ˆj7Œ vidioc_qbuf”uh1hhŸh³h Mhj@ubhŒ, ”…””}”hj@sbh)”}”(hŒ!:ref:`VIDIOC_DQBUF `”h]”jB)”}”(hj¶h]”hŒ VIDIOC_DQBUF”…””}”(hj¸hžhhŸNh Nubah}”(h]”h ]”(jŒstd”Œstd-ref”eh"]”h$]”h&]”uh1jAhj´ubah}”(h]”h ]”h"]”h$]”h&]”Œrefdoc”j"Œ refdomain”jÂŒreftype”Œref”Œ refexplicit”ˆŒrefwarn”ˆj7Œ vidioc_qbuf”uh1hhŸh³h Mhj@ubhŒ, ”…””}”hj@sbh)”}”(hŒ(:ref:`VIDIOC_STREAMON `”h]”jB)”}”(hjÚh]”hŒVIDIOC_STREAMON”…””}”(hjÜhžhhŸNh Nubah}”(h]”h ]”(jŒstd”Œstd-ref”eh"]”h$]”h&]”uh1jAhjØubah}”(h]”h ]”h"]”h$]”h&]”Œrefdoc”j"Œ refdomain”jæŒreftype”Œref”Œ refexplicit”ˆŒrefwarn”ˆj7Œvidioc_streamon”uh1hhŸh³h Mhj@ubhŒ and ”…””}”(hj@hžhhŸNh Nubh)”}”(hŒ):ref:`VIDIOC_STREAMOFF `”h]”jB)”}”(hjþh]”hŒVIDIOC_STREAMOFF”…””}”(hjhžhhŸNh Nubah}”(h]”h ]”(jŒstd”Œstd-ref”eh"]”h$]”h&]”uh1jAhjüubah}”(h]”h ]”h"]”h$]”h&]”Œrefdoc”j"Œ refdomain”j Œreftype”Œref”Œ refexplicit”ˆŒrefwarn”ˆj7Œvidioc_streamon”uh1hhŸh³h Mhj@ubhŒ ioctls, the ”…””}”(hj@hžhhŸNh Nubh)”}”(hŒ:ref:`mmap() `”h]”jB)”}”(hj"h]”hŒmmap()”…””}”(hj$hžhhŸNh Nubah}”(h]”h ]”(jŒstd”Œstd-ref”eh"]”h$]”h&]”uh1jAhj ubah}”(h]”h ]”h"]”h$]”h&]”Œrefdoc”j"Œ refdomain”j.Œreftype”Œref”Œ refexplicit”ˆŒrefwarn”ˆj7Œ func-mmap”uh1hhŸh³h Mhj@ubhŒ, ”…””}”hj@sbh)”}”(hŒ:c:func:`munmap()`”h]”hâ)”}”(hjFh]”hŒmunmap()”…””}”(hjHhžhhŸNh Nubah}”(h]”h ]”(jjŒc-func”eh"]”h$]”h&]”uh1háhjDubah}”(h]”h ]”h"]”h$]”h&]”Œrefdoc”j"Œ refdomain”jŒreftype”Œfunc”Œ refexplicit”‰Œrefwarn”‰j(j,j7Œmunmap”uh1hhŸh³h Mhj@ubhŒ, ”…””}”hj@sbh)”}”(hŒ:ref:`select() `”h]”jB)”}”(hjih]”hŒselect()”…””}”(hjkhžhhŸNh Nubah}”(h]”h ]”(jŒstd”Œstd-ref”eh"]”h$]”h&]”uh1jAhjgubah}”(h]”h ]”h"]”h$]”h&]”Œrefdoc”j"Œ refdomain”juŒreftype”Œref”Œ refexplicit”ˆŒrefwarn”ˆj7Œ func-select”uh1hhŸh³h Mhj@ubhŒ and ”…””}”(hj@hžhhŸNh Nubh)”}”(hŒ:c:func:`poll()`”h]”hâ)”}”(hjh]”hŒpoll()”…””}”(hjhžhhŸNh Nubah}”(h]”h ]”(jjŒc-func”eh"]”h$]”h&]”uh1háhj‹ubah}”(h]”h ]”h"]”h$]”h&]”Œrefdoc”j"Œ refdomain”jŒreftype”Œfunc”Œ refexplicit”‰Œrefwarn”‰j(j,j7Œpoll”uh1hhŸh³h Mhj@ubhŒ function. ”…””}”(hj@hžhhŸNh Nubj¶)”}”(hŒ[#f3]_”h]”hŒ3”…””}”(hj®hžhhŸNh Nubah}”(h]”Œid3”ah ]”h"]”h$]”h&]”jÆKhÀŒf3”jÈj"uh1jµhj@jÉ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]”jB)”}”(hjñh]”hŒ VIDIOC_QBUF”…””}”(hjóhžhhŸNh Nubah}”(h]”h ]”(jŒstd”Œstd-ref”eh"]”h$]”h&]”uh1jAhjïubah}”(h]”h ]”h"]”h$]”h&]”Œrefdoc”j"Œ refdomain”jýŒreftype”Œref”Œ refexplicit”‰Œrefwarn”ˆj7Œ vidioc_qbuf”uh1hhŸh³h M hjçubhŒ etc., but it makes the ”…””}”(hjçhžhhŸNh Nubh)”}”(hŒ:c:func:`select()`”h]”hâ)”}”(hjh]”hŒselect()”…””}”(hjhžhhŸNh Nubah}”(h]”h ]”(jjŒc-func”eh"]”h$]”h&]”uh1háhjubah}”(h]”h ]”h"]”h$]”h&]”Œrefdoc”j"Œ refdomain”jŒreftype”Œfunc”Œ refexplicit”‰Œrefwarn”‰j(j,j7Œ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Èj"uh1jÒ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”…””}”(hjGhžhhŸNh Nubah}”(h]”h ]”h"]”h$]”h&]”uh1jØhjChž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.”…””}”(hjThžhhŸNh Nubah}”(h]”h ]”h"]”h$]”h&]”uh1h×hŸh³h MhjCubeh}”(h]”jah ]”h"]”Œf2”ah$]”h&]”jajÆKjÈj"uh1jÒ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”…””}”(hjmhžhhŸNh Nubah}”(h]”h ]”h"]”h$]”h&]”uh1jØhjihž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 ”…””}”(hjzhžhhŸNh Nubh)”}”(hŒ:c:func:`select()`”h]”hâ)”}”(hj„h]”hŒselect()”…””}”(hj†hžhhŸNh Nubah}”(h]”h ]”(jjŒc-func”eh"]”h$]”h&]”uh1háhj‚ubah}”(h]”h ]”h"]”h$]”h&]”Œrefdoc”j"Œ refdomain”jŒreftype”Œfunc”Œ refexplicit”‰Œrefwarn”‰j(j,j7Œselect”uh1hhŸh³h MhjzubhŒ and ”…””}”(hjzhžhhŸNh Nubh)”}”(hŒ:c:func:`poll()`”h]”hâ)”}”(hj§h]”hŒpoll()”…””}”(hj©hžhhŸNh Nubah}”(h]”h ]”(jjŒc-func”eh"]”h$]”h&]”uh1háhj¥ubah}”(h]”h ]”h"]”h$]”h&]”Œrefdoc”j"Œ refdomain”jŒreftype”Œfunc”Œ refexplicit”‰Œrefwarn”‰j(j,j7Œpoll”uh1hhŸh³h MhjzubhŒ are the same, and ”…””}”(hjzhžhhŸNh Nubh)”}”(hŒ:c:func:`select()`”h]”hâ)”}”(hjÊh]”hŒselect()”…””}”(hjÌhžhhŸNh Nubah}”(h]”h ]”(jjŒc-func”eh"]”h$]”h&]”uh1háhjÈubah}”(h]”h ]”h"]”h$]”h&]”Œrefdoc”j"Œ refdomain”jŒreftype”Œfunc”Œ refexplicit”‰Œrefwarn”‰j(j,j7Œselect”uh1hhŸh³h MhjzubhŒ= is too important to be optional. The rest should be evident.”…””}”(hjzhžhhŸNh Nubeh}”(h]”h ]”h"]”h$]”h&]”uh1h×hŸh³h Mhjiubeh}”(h]”j½ah ]”h"]”Œf3”ah$]”h&]”j¸ajÆKjÈj"uh1jÒ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”j0 Œ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új@jÇjfjjõj½uŒ nametypes”}”(j ˆj ‰j­‰jý‰j@ˆjfˆjõˆuh}”(hÁhÄj hÄjÁj·jªjƒjúj°jj j¸j®jÇjÔjjCj½jiuŒ footnote_refs”}”(jp ]”j·ajr ]”j ajt ]”j®auŒ citation_refs”}”Œ autofootnotes”]”(jÔjCjieŒautofootnote_refs”]”(j·j j®eŒsymbol_footnotes”]”Œsymbol_footnote_refs”]”Œ footnotes”]”Œ citations”]”Œautofootnote_start”KŒsymbol_footnote_start”KŒ id_counter”Œ collections”ŒCounter”“”}”j> 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.