drivers/media/pci/tw5864/tw5864-h264.c
Source file repositories/reference/linux-study-clean/drivers/media/pci/tw5864/tw5864-h264.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/media/pci/tw5864/tw5864-h264.c- Extension
.c- Size
- 6424 bytes
- Lines
- 251
- 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.
- Defines or uses C structs; map object ownership, embedded links, reference counts, and lock ownership.
Dependency Surface
linux/log2.htw5864.h
Detected Declarations
struct bsfunction bs_initfunction bs_lenfunction bs_writefunction bs_write1function bs_write_uefunction bs_write_sefunction bs_rbsp_trailingfunction tw5864_h264_gen_sps_rbspfunction tw5864_h264_gen_pps_rbspfunction tw5864_h264_gen_slice_headfunction tw5864_h264_put_stream_headerfunction tw5864_h264_put_slice_header
Annotated Snippet
struct bs {
u8 *buf; /* pointer to buffer beginning */
u8 *buf_end; /* pointer to buffer end */
u8 *ptr; /* pointer to current byte in buffer */
unsigned int bits_left; /* number of available bits in current byte */
};
static void bs_init(struct bs *s, void *buf, int size)
{
s->buf = buf;
s->ptr = buf;
s->buf_end = s->ptr + size;
s->bits_left = 8;
}
static int bs_len(struct bs *s)
{
return s->ptr - s->buf;
}
static void bs_write(struct bs *s, int count, u32 bits)
{
if (s->ptr >= s->buf_end - 4)
return;
while (count > 0) {
if (count < 32)
bits &= (1 << count) - 1;
if (count < s->bits_left) {
*s->ptr = (*s->ptr << count) | bits;
s->bits_left -= count;
break;
}
*s->ptr = (*s->ptr << s->bits_left) |
(bits >> (count - s->bits_left));
count -= s->bits_left;
s->ptr++;
s->bits_left = 8;
}
}
static void bs_write1(struct bs *s, u32 bit)
{
if (s->ptr < s->buf_end) {
*s->ptr <<= 1;
*s->ptr |= bit;
s->bits_left--;
if (s->bits_left == 0) {
s->ptr++;
s->bits_left = 8;
}
}
}
static void bs_write_ue(struct bs *s, u32 val)
{
if (val == 0) {
bs_write1(s, 1);
} else {
val++;
bs_write(s, 2 * fls(val) - 1, val);
}
}
static void bs_write_se(struct bs *s, int val)
{
bs_write_ue(s, val <= 0 ? -val * 2 : val * 2 - 1);
}
static void bs_rbsp_trailing(struct bs *s)
{
bs_write1(s, 1);
if (s->bits_left != 8)
bs_write(s, s->bits_left, 0x00);
}
/* H.264 headers generation functions */
static int tw5864_h264_gen_sps_rbsp(u8 *buf, size_t size, int width, int height)
{
struct bs bs, *s;
s = &bs;
bs_init(s, buf, size);
bs_write(s, 8, 0x42); /* profile_idc, baseline */
bs_write(s, 1, 1); /* constraint_set0_flag */
bs_write(s, 1, 1); /* constraint_set1_flag */
bs_write(s, 1, 0); /* constraint_set2_flag */
bs_write(s, 5, 0); /* reserved_zero_5bits */
bs_write(s, 8, 0x1e); /* level_idc */
bs_write_ue(s, 0); /* seq_parameter_set_id */
Annotation
- Immediate include surface: `linux/log2.h`, `tw5864.h`.
- Detected declarations: `struct bs`, `function bs_init`, `function bs_len`, `function bs_write`, `function bs_write1`, `function bs_write_ue`, `function bs_write_se`, `function bs_rbsp_trailing`, `function tw5864_h264_gen_sps_rbsp`, `function tw5864_h264_gen_pps_rbsp`.
- Atlas domain: Driver Families / drivers/media.
- Implementation status: source 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.