drivers/media/v4l2-core/v4l2-jpeg.c
Source file repositories/reference/linux-study-clean/drivers/media/v4l2-core/v4l2-jpeg.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/media/v4l2-core/v4l2-jpeg.c- Extension
.c- Size
- 18979 bytes
- Lines
- 714
- 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.
- Defines or uses C structs; map object ownership, embedded links, reference counts, and lock ownership.
Dependency Surface
linux/unaligned.hlinux/errno.hlinux/kernel.hlinux/module.hlinux/types.hmedia/v4l2-jpeg.h
Detected Declarations
struct jpeg_streamfunction jpeg_get_bytefunction jpeg_get_word_befunction jpeg_skipfunction jpeg_next_markerfunction jpeg_reference_segmentfunction v4l2_jpeg_decode_subsamplingfunction jpeg_parse_frame_headerfunction jpeg_parse_scan_headerfunction jpeg_parse_quantization_tablesfunction jpeg_parse_huffman_tablesfunction jpeg_parse_restart_intervalfunction jpeg_skip_segmentfunction jpeg_parse_app14_datafunction v4l2_jpeg_parse_headerexport v4l2_jpeg_ref_table_luma_qtexport v4l2_jpeg_ref_table_chroma_qtexport v4l2_jpeg_zigzag_scan_indexexport v4l2_jpeg_ref_table_luma_dc_htexport v4l2_jpeg_ref_table_luma_ac_htexport v4l2_jpeg_ref_table_chroma_dc_htexport v4l2_jpeg_ref_table_chroma_ac_htexport v4l2_jpeg_parse_header
Annotated Snippet
struct jpeg_stream {
u8 *curr;
u8 *end;
};
/* returns a value that fits into u8, or negative error */
static int jpeg_get_byte(struct jpeg_stream *stream)
{
if (stream->curr >= stream->end)
return -EINVAL;
return *stream->curr++;
}
/* returns a value that fits into u16, or negative error */
static int jpeg_get_word_be(struct jpeg_stream *stream)
{
u16 word;
if (stream->curr + sizeof(__be16) > stream->end)
return -EINVAL;
word = get_unaligned_be16(stream->curr);
stream->curr += sizeof(__be16);
return word;
}
static int jpeg_skip(struct jpeg_stream *stream, size_t len)
{
if (stream->curr + len > stream->end)
return -EINVAL;
stream->curr += len;
return 0;
}
static int jpeg_next_marker(struct jpeg_stream *stream)
{
int byte;
u16 marker = 0;
while ((byte = jpeg_get_byte(stream)) >= 0) {
marker = (marker << 8) | byte;
/* skip stuffing bytes and REServed markers */
if (marker == TEM || (marker > 0xffbf && marker < 0xffff))
return marker;
}
return byte;
}
/* this does not advance the current position in the stream */
static int jpeg_reference_segment(struct jpeg_stream *stream,
struct v4l2_jpeg_reference *segment)
{
u16 len;
if (stream->curr + sizeof(__be16) > stream->end)
return -EINVAL;
len = get_unaligned_be16(stream->curr);
if (stream->curr + len > stream->end)
return -EINVAL;
segment->start = stream->curr;
segment->length = len;
return 0;
}
static int v4l2_jpeg_decode_subsampling(u8 nf, u8 h_v)
{
if (nf == 1)
return V4L2_JPEG_CHROMA_SUBSAMPLING_GRAY;
/* no chroma subsampling for 4-component images */
if (nf == 4 && h_v != 0x11)
return -EINVAL;
switch (h_v) {
case 0x11:
return V4L2_JPEG_CHROMA_SUBSAMPLING_444;
case 0x21:
return V4L2_JPEG_CHROMA_SUBSAMPLING_422;
case 0x22:
return V4L2_JPEG_CHROMA_SUBSAMPLING_420;
case 0x41:
return V4L2_JPEG_CHROMA_SUBSAMPLING_411;
Annotation
- Immediate include surface: `linux/unaligned.h`, `linux/errno.h`, `linux/kernel.h`, `linux/module.h`, `linux/types.h`, `media/v4l2-jpeg.h`.
- Detected declarations: `struct jpeg_stream`, `function jpeg_get_byte`, `function jpeg_get_word_be`, `function jpeg_skip`, `function jpeg_next_marker`, `function jpeg_reference_segment`, `function v4l2_jpeg_decode_subsampling`, `function jpeg_parse_frame_header`, `function jpeg_parse_scan_header`, `function jpeg_parse_quantization_tables`.
- Atlas domain: Driver Families / drivers/media.
- Implementation status: integration implementation candidate.
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.