drivers/media/v4l2-core/v4l2-h264.c
Source file repositories/reference/linux-study-clean/drivers/media/v4l2-core/v4l2-h264.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/media/v4l2-core/v4l2-h264.c- Extension
.c- Size
- 13792 bytes
- Lines
- 454
- 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.
- 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/module.hlinux/sort.hmedia/v4l2-h264.h
Detected Declarations
function v4l2_h264_init_reflist_builderfunction v4l2_h264_get_pocfunction v4l2_h264_p_ref_list_cmpfunction v4l2_h264_b0_ref_list_cmpfunction v4l2_h264_b1_ref_list_cmpfunction reorder_field_reflistfunction ref_type_to_charfunction print_ref_list_pfunction print_ref_list_bfunction v4l2_h264_build_p_ref_listfunction v4l2_h264_build_b_ref_listsexport v4l2_h264_init_reflist_builderexport v4l2_h264_build_p_ref_listexport v4l2_h264_build_b_ref_lists
Annotated Snippet
if (b->cur_pic_fields == V4L2_H264_FRAME_REF) {
u8 fields = V4L2_H264_FRAME_REF;
b->unordered_reflist[b->num_valid].index = i;
b->unordered_reflist[b->num_valid].fields = fields;
b->num_valid++;
continue;
}
if (dpb[i].fields & V4L2_H264_TOP_FIELD_REF) {
u8 fields = V4L2_H264_TOP_FIELD_REF;
b->unordered_reflist[b->num_valid].index = i;
b->unordered_reflist[b->num_valid].fields = fields;
b->num_valid++;
}
if (dpb[i].fields & V4L2_H264_BOTTOM_FIELD_REF) {
u8 fields = V4L2_H264_BOTTOM_FIELD_REF;
b->unordered_reflist[b->num_valid].index = i;
b->unordered_reflist[b->num_valid].fields = fields;
b->num_valid++;
}
}
for (i = b->num_valid; i < ARRAY_SIZE(b->unordered_reflist); i++)
b->unordered_reflist[i].index = i;
}
EXPORT_SYMBOL_GPL(v4l2_h264_init_reflist_builder);
static s32 v4l2_h264_get_poc(const struct v4l2_h264_reflist_builder *b,
const struct v4l2_h264_reference *ref)
{
switch (ref->fields) {
case V4L2_H264_FRAME_REF:
return min(b->refs[ref->index].top_field_order_cnt,
b->refs[ref->index].bottom_field_order_cnt);
case V4L2_H264_TOP_FIELD_REF:
return b->refs[ref->index].top_field_order_cnt;
case V4L2_H264_BOTTOM_FIELD_REF:
return b->refs[ref->index].bottom_field_order_cnt;
}
/* not reached */
return 0;
}
static int v4l2_h264_p_ref_list_cmp(const void *ptra, const void *ptrb,
const void *data)
{
const struct v4l2_h264_reflist_builder *builder = data;
u8 idxa, idxb;
idxa = ((struct v4l2_h264_reference *)ptra)->index;
idxb = ((struct v4l2_h264_reference *)ptrb)->index;
if (WARN_ON(idxa >= V4L2_H264_NUM_DPB_ENTRIES ||
idxb >= V4L2_H264_NUM_DPB_ENTRIES))
return 1;
if (builder->refs[idxa].longterm != builder->refs[idxb].longterm) {
/* Short term pics first. */
if (!builder->refs[idxa].longterm)
return -1;
else
return 1;
}
/*
* For frames, short term pics are in descending pic num order and long
* term ones in ascending order. For fields, the same direction is used
* but with frame_num (wrapped). For frames, the value of pic_num and
* frame_num are the same (see formula (8-28) and (8-29)). For this
* reason we can use frame_num only and share this function between
* frames and fields reflist.
*/
if (!builder->refs[idxa].longterm)
return builder->refs[idxb].frame_num <
builder->refs[idxa].frame_num ?
-1 : 1;
return builder->refs[idxa].frame_num < builder->refs[idxb].frame_num ?
-1 : 1;
}
static int v4l2_h264_b0_ref_list_cmp(const void *ptra, const void *ptrb,
const void *data)
{
const struct v4l2_h264_reflist_builder *builder = data;
Annotation
- Immediate include surface: `linux/module.h`, `linux/sort.h`, `media/v4l2-h264.h`.
- Detected declarations: `function v4l2_h264_init_reflist_builder`, `function v4l2_h264_get_poc`, `function v4l2_h264_p_ref_list_cmp`, `function v4l2_h264_b0_ref_list_cmp`, `function v4l2_h264_b1_ref_list_cmp`, `function reorder_field_reflist`, `function ref_type_to_char`, `function print_ref_list_p`, `function print_ref_list_b`, `function v4l2_h264_build_p_ref_list`.
- 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.