drivers/media/usb/uvc/uvc_video.c
Source file repositories/reference/linux-study-clean/drivers/media/usb/uvc/uvc_video.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/media/usb/uvc/uvc_video.c- Extension
.c- Size
- 70920 bytes
- Lines
- 2388
- Domain
- Driver Families
- Bucket
- drivers/media
- 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/dma-mapping.hlinux/highmem.hlinux/kernel.hlinux/list.hlinux/module.hlinux/slab.hlinux/usb.hlinux/usb/hcd.hlinux/videodev2.hlinux/vmalloc.hlinux/wait.hlinux/atomic.hlinux/unaligned.hmedia/jpeg.hmedia/v4l2-common.huvcvideo.h
Detected Declarations
function Copyrightfunction uvc_query_ctrlfunction uvc_fixup_video_ctrlfunction bFormatIndexfunction uvc_video_ctrl_sizefunction uvc_get_video_ctrlfunction uvc_set_video_ctrlfunction uvc_probe_videofunction uvc_commit_videofunction uvc_video_get_timefunction uvc_video_clock_add_samplefunction sof_difffunction uvc_video_clock_decodefunction uvc_video_clock_host_soffunction uvc_video_clock_resetfunction uvc_video_clock_initfunction uvc_video_clock_cleanupfunction usb_get_current_frame_numberfunction slopefunction uvc_video_stats_decodefunction uvc_video_stats_updatefunction uvc_video_stats_dumpfunction uvc_video_stats_startfunction uvc_video_stats_stopfunction uvc_video_decode_startfunction bitfunction uvc_stream_dirfunction uvc_video_copy_data_workfunction uvc_video_decode_datafunction uvc_video_decode_endfunction uvc_video_encode_headerfunction uvc_video_encode_datafunction uvc_video_decode_metafunction uvc_video_validate_bufferfunction uvc_video_next_buffersfunction uvc_video_decode_isocfunction uvc_video_decode_bulkfunction sizefunction uvc_video_encode_bulkfunction uvc_video_completefunction uvc_free_urb_buffersfunction for_each_uvc_urbfunction uvc_alloc_urb_bufferfunction uvc_alloc_urb_buffersfunction uvc_video_stop_transferfunction for_each_uvc_urbfunction uvc_init_video_isocfunction for_each_uvc_urb
Annotated Snippet
if (stream->formats[i].index == ctrl->bFormatIndex) {
format = &stream->formats[i];
break;
}
}
if (format == NULL)
return;
for (i = 0; i < format->nframes; ++i) {
if (format->frames[i].bFrameIndex == ctrl->bFrameIndex) {
frame = &format->frames[i];
break;
}
}
if (frame == NULL)
return;
if (!(format->flags & UVC_FMT_FLAG_COMPRESSED) ||
(ctrl->dwMaxVideoFrameSize == 0 &&
stream->dev->uvc_version < 0x0110))
ctrl->dwMaxVideoFrameSize =
frame->dwMaxVideoFrameBufferSize;
/*
* The "TOSHIBA Web Camera - 5M" Chicony device (04f2:b50b) seems to
* compute the bandwidth on 16 bits and erroneously sign-extend it to
* 32 bits, resulting in a huge bandwidth value. Detect and fix that
* condition by setting the 16 MSBs to 0 when they're all equal to 1.
*/
if ((ctrl->dwMaxPayloadTransferSize & 0xffff0000) == 0xffff0000)
ctrl->dwMaxPayloadTransferSize &= ~0xffff0000;
if (!(format->flags & UVC_FMT_FLAG_COMPRESSED) &&
stream->dev->quirks & UVC_QUIRK_FIX_BANDWIDTH &&
stream->intf->num_altsetting > 1) {
u32 interval;
u32 bandwidth;
interval = (ctrl->dwFrameInterval > 100000)
? ctrl->dwFrameInterval
: frame->dwFrameInterval[0];
/*
* Compute a bandwidth estimation by multiplying the frame
* size by the number of video frames per second, divide the
* result by the number of USB frames (or micro-frames for
* high- and super-speed devices) per second and add the UVC
* header size (assumed to be 12 bytes long).
*/
bandwidth = frame->wWidth * frame->wHeight / 8 * format->bpp;
bandwidth *= 10000000 / interval + 1;
bandwidth /= 1000;
if (stream->dev->udev->speed >= USB_SPEED_HIGH)
bandwidth /= 8;
bandwidth += 12;
/*
* The bandwidth estimate is too low for many cameras. Don't use
* maximum packet sizes lower than 1024 bytes to try and work
* around the problem. According to measurements done on two
* different camera models, the value is high enough to get most
* resolutions working while not preventing two simultaneous
* VGA streams at 15 fps.
*/
bandwidth = max_t(u32, bandwidth, 1024);
ctrl->dwMaxPayloadTransferSize = bandwidth;
}
if (stream->intf->num_altsetting > 1 &&
ctrl->dwMaxPayloadTransferSize > stream->maxpsize) {
dev_warn_ratelimited(&stream->intf->dev,
"UVC non compliance: Reducing max payload transfer size (%u) to fit endpoint limit (%u).\n",
ctrl->dwMaxPayloadTransferSize,
stream->maxpsize);
ctrl->dwMaxPayloadTransferSize = stream->maxpsize;
}
}
static size_t uvc_video_ctrl_size(struct uvc_streaming *stream)
{
/*
* Return the size of the video probe and commit controls, which depends
* on the protocol version.
*/
if (stream->dev->uvc_version < 0x0110)
return 26;
else if (stream->dev->uvc_version < 0x0150)
Annotation
- Immediate include surface: `linux/dma-mapping.h`, `linux/highmem.h`, `linux/kernel.h`, `linux/list.h`, `linux/module.h`, `linux/slab.h`, `linux/usb.h`, `linux/usb/hcd.h`.
- Detected declarations: `function Copyright`, `function uvc_query_ctrl`, `function uvc_fixup_video_ctrl`, `function bFormatIndex`, `function uvc_video_ctrl_size`, `function uvc_get_video_ctrl`, `function uvc_set_video_ctrl`, `function uvc_probe_video`, `function uvc_commit_video`, `function uvc_video_get_time`.
- Atlas domain: Driver Families / drivers/media.
- 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.