drivers/usb/gadget/function/uvc_video.c
Source file repositories/reference/linux-study-clean/drivers/usb/gadget/function/uvc_video.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/usb/gadget/function/uvc_video.c- Extension
.c- Size
- 22640 bytes
- Lines
- 844
- Domain
- Driver Families
- Bucket
- drivers/usb
- Inferred role
- Driver Families: implementation source
- Status
- source 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.
- Uses kernel synchronization; read lock ordering, sleepability, and interrupt context assumptions before translating.
- Allocates kernel memory; connect allocation flags and lifetime to context constraints.
- Defines or uses C structs; map object ownership, embedded links, reference counts, and lock ownership.
Dependency Surface
linux/kernel.hlinux/device.hlinux/errno.hlinux/usb/ch9.hlinux/usb/gadget.hlinux/usb/video.hlinux/unaligned.hmedia/v4l2-dev.huvc.huvc_queue.huvc_video.huvc_trace.h
Detected Declarations
function Copyrightfunction uvc_video_encode_datafunction uvc_video_encode_bulkfunction uvc_video_encode_isoc_sgfunction for_each_sgfunction uvc_video_encode_isocfunction uvc_video_free_requestfunction uvcg_video_ep_queuefunction uvcg_video_usb_req_queuefunction uvc_video_completefunction uvcg_video_hw_submitfunction uvc_video_free_requestsfunction uvc_video_prep_requestsfunction uvc_video_alloc_requestsfunction requestsfunction uvcg_video_disablefunction list_for_each_entry_safefunction list_for_each_entry_safefunction uvcg_video_enablefunction uvcg_video_init
Annotated Snippet
if (part == sg_left) {
buf->offset = 0;
buf->sg = sg_next(buf->sg);
} else {
buf->offset += part;
}
len -= part;
}
/* Assign the video data with header. */
req->buf = NULL;
req->sg = ureq->sgt.sgl;
req->num_sgs = i + 1;
req->length -= len;
video->queue.buf_used += req->length - header_len;
if (buf->bytesused == video->queue.buf_used || !buf->sg ||
video->queue.flags & UVC_QUEUE_DROP_INCOMPLETE) {
video->queue.buf_used = 0;
buf->state = UVC_BUF_STATE_DONE;
buf->offset = 0;
list_del(&buf->queue);
video->fid ^= UVC_STREAM_FID;
ureq->last_buf = buf;
}
}
static void
uvc_video_encode_isoc(struct usb_request *req, struct uvc_video *video,
struct uvc_buffer *buf)
{
void *mem = req->buf;
struct uvc_request *ureq = req->context;
int len = buf->req_payload_size;
int ret;
/* Add the header. */
ret = uvc_video_encode_header(video, buf, mem, len);
mem += ret;
len -= ret;
/* Process video data. */
ret = uvc_video_encode_data(video, buf, mem, len);
len -= ret;
req->length = buf->req_payload_size - len;
if (buf->bytesused == video->queue.buf_used ||
video->queue.flags & UVC_QUEUE_DROP_INCOMPLETE) {
video->queue.buf_used = 0;
buf->state = UVC_BUF_STATE_DONE;
list_del(&buf->queue);
video->fid ^= UVC_STREAM_FID;
ureq->last_buf = buf;
}
}
/* --------------------------------------------------------------------------
* Request handling
*/
/*
* Callers must take care to hold req_lock when this function may be called
* from multiple threads. For example, when frames are streaming to the host.
*/
static void
uvc_video_free_request(struct uvc_request *ureq, struct usb_ep *ep)
{
sg_free_table(&ureq->sgt);
if (ureq->req && ep) {
usb_ep_free_request(ep, ureq->req);
ureq->req = NULL;
}
kfree(ureq->req_buffer);
ureq->req_buffer = NULL;
if (!list_empty(&ureq->list))
list_del_init(&ureq->list);
kfree(ureq);
}
static int uvcg_video_ep_queue(struct uvc_video *video, struct usb_request *req)
{
int ret;
ret = usb_ep_queue(video->ep, req, GFP_ATOMIC);
if (ret < 0) {
Annotation
- Immediate include surface: `linux/kernel.h`, `linux/device.h`, `linux/errno.h`, `linux/usb/ch9.h`, `linux/usb/gadget.h`, `linux/usb/video.h`, `linux/unaligned.h`, `media/v4l2-dev.h`.
- Detected declarations: `function Copyright`, `function uvc_video_encode_data`, `function uvc_video_encode_bulk`, `function uvc_video_encode_isoc_sg`, `function for_each_sg`, `function uvc_video_encode_isoc`, `function uvc_video_free_request`, `function uvcg_video_ep_queue`, `function uvcg_video_usb_req_queue`, `function uvc_video_complete`.
- Atlas domain: Driver Families / drivers/usb.
- Implementation status: source 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.