drivers/media/common/videobuf2/videobuf2-v4l2.c
Source file repositories/reference/linux-study-clean/drivers/media/common/videobuf2/videobuf2-v4l2.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/media/common/videobuf2/videobuf2-v4l2.c- Extension
.c- Size
- 37345 bytes
- Lines
- 1359
- Domain
- Driver Families
- Bucket
- drivers/media
- Inferred role
- Driver Families: exported/initcall integration point
- Status
- integration implementation candidate
Why This File Exists
Repeatable hardware-adapter layer. Deep compatibility for every driver is out of scope; this atlas records patterns, probe lifecycles, bus glue, IRQ/DMA usage, and links back to core abstractions.
- Repeatable hardware-adapter layer. Deep compatibility for every driver is out of scope; this atlas records patterns, probe lifecycles, bus glue, IRQ/DMA usage, and links back to core abstractions.
- Exports symbols or registers init work; inspect boot/module ordering and who consumes the exported contract.
- Uses kernel synchronization; read lock ordering, sleepability, and interrupt context assumptions before translating.
- Defines or uses C structs; map object ownership, embedded links, reference counts, and lock ownership.
Dependency Surface
linux/device.hlinux/err.hlinux/freezer.hlinux/kernel.hlinux/kthread.hlinux/mm.hlinux/module.hlinux/poll.hlinux/sched.hlinux/slab.hmedia/v4l2-common.hmedia/v4l2-dev.hmedia/v4l2-device.hmedia/v4l2-event.hmedia/v4l2-fh.hmedia/videobuf2-v4l2.h
Detected Declarations
function __verify_planes_arrayfunction __verify_planes_array_corefunction __verify_lengthfunction __init_vb2_v4l2_bufferfunction __copy_timestampfunction vb2_warn_zero_bytesusedfunction vb2_fill_vb2_v4l2_bufferfunction set_buffer_cache_hintsfunction vb2_queue_or_prepare_buffunction vb2_core_qbuffunction __fill_v4l2_bufferfunction __fill_vb2_bufferfunction vb2_querybuffunction vb2_set_flags_and_capsfunction vb2_reqbufsfunction vb2_prepare_buffunction vb2_create_bufsfunction vb2_qbuffunction vb2_dqbuffunction vb2_streamonfunction vb2_streamofffunction vb2_expbuffunction vb2_queue_init_namefunction vb2_queue_initfunction vb2_queue_releasefunction vb2_queue_change_typefunction vb2_pollfunction vb2_ioctl_remove_bufsfunction vb2_ioctl_reqbufsfunction vb2_ioctl_create_bufsfunction vb2_ioctl_prepare_buffunction vb2_ioctl_querybuffunction vb2_ioctl_qbuffunction vb2_ioctl_dqbuffunction vb2_ioctl_streamonfunction vb2_ioctl_streamofffunction vb2_ioctl_expbuffunction vb2_fop_mmapfunction _vb2_fop_releasefunction vb2_fop_releasefunction vb2_fop_writefunction vb2_fop_readfunction vb2_fop_pollfunction vb2_fop_get_unmapped_areafunction vb2_video_unregister_devicefunction vb2_request_validatefunction list_for_each_entryfunction vb2_request_queue
Annotated Snippet
switch (b->memory) {
case VB2_MEMORY_USERPTR:
for (plane = 0; plane < vb->num_planes; ++plane) {
planes[plane].m.userptr =
b->m.planes[plane].m.userptr;
planes[plane].length =
b->m.planes[plane].length;
}
break;
case VB2_MEMORY_DMABUF:
for (plane = 0; plane < vb->num_planes; ++plane) {
planes[plane].m.fd =
b->m.planes[plane].m.fd;
planes[plane].length =
b->m.planes[plane].length;
}
break;
default:
for (plane = 0; plane < vb->num_planes; ++plane) {
planes[plane].m.offset =
vb->planes[plane].m.offset;
planes[plane].length =
vb->planes[plane].length;
}
break;
}
/* Fill in user-provided information for OUTPUT types */
if (V4L2_TYPE_IS_OUTPUT(b->type)) {
/*
* Will have to go up to b->length when API starts
* accepting variable number of planes.
*
* If bytesused == 0 for the output buffer, then fall
* back to the full buffer size. In that case
* userspace clearly never bothered to set it and
* it's a safe assumption that they really meant to
* use the full plane sizes.
*
* Some drivers, e.g. old codec drivers, use bytesused == 0
* as a way to indicate that streaming is finished.
* In that case, the driver should use the
* allow_zero_bytesused flag to keep old userspace
* applications working.
*/
for (plane = 0; plane < vb->num_planes; ++plane) {
struct vb2_plane *pdst = &planes[plane];
struct v4l2_plane *psrc = &b->m.planes[plane];
if (psrc->bytesused == 0)
vb2_warn_zero_bytesused(vb);
if (vb->vb2_queue->allow_zero_bytesused)
pdst->bytesused = psrc->bytesused;
else
pdst->bytesused = psrc->bytesused ?
psrc->bytesused : pdst->length;
pdst->data_offset = psrc->data_offset;
}
}
} else {
/*
* Single-planar buffers do not use planes array,
* so fill in relevant v4l2_buffer struct fields instead.
* In vb2 we use our internal V4l2_planes struct for
* single-planar buffers as well, for simplicity.
*
* If bytesused == 0 for the output buffer, then fall back
* to the full buffer size as that's a sensible default.
*
* Some drivers, e.g. old codec drivers, use bytesused == 0 as
* a way to indicate that streaming is finished. In that case,
* the driver should use the allow_zero_bytesused flag to keep
* old userspace applications working.
*/
switch (b->memory) {
case VB2_MEMORY_USERPTR:
planes[0].m.userptr = b->m.userptr;
planes[0].length = b->length;
break;
case VB2_MEMORY_DMABUF:
planes[0].m.fd = b->m.fd;
planes[0].length = b->length;
break;
default:
planes[0].m.offset = vb->planes[0].m.offset;
planes[0].length = vb->planes[0].length;
break;
}
Annotation
- Immediate include surface: `linux/device.h`, `linux/err.h`, `linux/freezer.h`, `linux/kernel.h`, `linux/kthread.h`, `linux/mm.h`, `linux/module.h`, `linux/poll.h`.
- Detected declarations: `function __verify_planes_array`, `function __verify_planes_array_core`, `function __verify_length`, `function __init_vb2_v4l2_buffer`, `function __copy_timestamp`, `function vb2_warn_zero_bytesused`, `function vb2_fill_vb2_v4l2_buffer`, `function set_buffer_cache_hints`, `function vb2_queue_or_prepare_buf`, `function vb2_core_qbuf`.
- Atlas domain: Driver Families / drivers/media.
- Implementation status: integration implementation candidate.
- Synchronization appears in or near this file; preserve lock ordering, sleepability, and interrupt-context constraints.
Implementation Notes
- This generated page is the file-by-file coverage layer; curated subsystem chapters should link here when they synthesize a multi-file control flow.
- Core OS pages should be promoted from atlas-only to deep-reviewed when they explain data structures, invariants, locking, lifecycle, and C implementation snippets.
- Driver-family pages are intentionally pattern-oriented unless they are part of the selected PCIe/NVMe representative device path.