drivers/media/platform/allegro-dvt/nal-rbsp.c
Source file repositories/reference/linux-study-clean/drivers/media/platform/allegro-dvt/nal-rbsp.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/media/platform/allegro-dvt/nal-rbsp.c- Extension
.c- Size
- 5876 bytes
- Lines
- 311
- 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/kernel.hlinux/types.hlinux/string.hlinux/v4l2-controls.hlinux/device.hlinux/export.hlinux/log2.hnal-rbsp.h
Detected Declarations
function Copyrightfunction rbsp_unsupportedfunction add_emulation_prevention_three_bytefunction discard_emulation_prevention_three_bytefunction rbsp_read_bitfunction rbsp_write_bitfunction rbsp_read_bitsfunction rbsp_write_bitsfunction rbsp_read_uevfunction rbsp_write_uevfunction rbsp_read_sevfunction rbsp_write_sevfunction __rbsp_write_bitfunction __rbsp_write_bitsfunction __rbsp_read_bitfunction rbsp_bitfunction rbsp_bitsfunction rbsp_uevfunction rbsp_sevfunction rbsp_trailing_bits
Annotated Snippet
// SPDX-License-Identifier: GPL-2.0
/*
* Copyright (C) 2019-2020 Pengutronix, Michael Tretter <kernel@pengutronix.de>
*
* Helper functions to generate a raw byte sequence payload from values.
*/
#include <linux/kernel.h>
#include <linux/types.h>
#include <linux/string.h>
#include <linux/v4l2-controls.h>
#include <linux/device.h>
#include <linux/export.h>
#include <linux/log2.h>
#include "nal-rbsp.h"
void rbsp_init(struct rbsp *rbsp, void *addr, size_t size,
struct nal_rbsp_ops *ops)
{
if (!rbsp)
return;
rbsp->data = addr;
rbsp->size = size;
rbsp->pos = 0;
rbsp->ops = ops;
rbsp->error = 0;
}
void rbsp_unsupported(struct rbsp *rbsp)
{
rbsp->error = -EINVAL;
}
static int rbsp_read_bits(struct rbsp *rbsp, int n, unsigned int *value);
static int rbsp_write_bits(struct rbsp *rbsp, int n, unsigned int value);
/*
* When reading or writing, the emulation_prevention_three_byte is detected
* only when the 2 one bits need to be inserted. Therefore, we are not
* actually adding the 0x3 byte, but the 2 one bits and the six 0 bits of the
* next byte.
*/
#define EMULATION_PREVENTION_THREE_BYTE (0x3 << 6)
static int add_emulation_prevention_three_byte(struct rbsp *rbsp)
{
rbsp->num_consecutive_zeros = 0;
rbsp_write_bits(rbsp, 8, EMULATION_PREVENTION_THREE_BYTE);
return 0;
}
static int discard_emulation_prevention_three_byte(struct rbsp *rbsp)
{
unsigned int tmp = 0;
rbsp->num_consecutive_zeros = 0;
rbsp_read_bits(rbsp, 8, &tmp);
if (tmp != EMULATION_PREVENTION_THREE_BYTE)
return -EINVAL;
return 0;
}
static inline int rbsp_read_bit(struct rbsp *rbsp)
{
int shift;
int ofs;
int bit;
int err;
if (rbsp->num_consecutive_zeros == 22) {
err = discard_emulation_prevention_three_byte(rbsp);
if (err)
return err;
}
shift = 7 - (rbsp->pos % 8);
ofs = rbsp->pos / 8;
if (ofs >= rbsp->size)
return -EINVAL;
bit = (rbsp->data[ofs] >> shift) & 1;
rbsp->pos++;
if (bit == 1 ||
Annotation
- Immediate include surface: `linux/kernel.h`, `linux/types.h`, `linux/string.h`, `linux/v4l2-controls.h`, `linux/device.h`, `linux/export.h`, `linux/log2.h`, `nal-rbsp.h`.
- Detected declarations: `function Copyright`, `function rbsp_unsupported`, `function add_emulation_prevention_three_byte`, `function discard_emulation_prevention_three_byte`, `function rbsp_read_bit`, `function rbsp_write_bit`, `function rbsp_read_bits`, `function rbsp_write_bits`, `function rbsp_read_uev`, `function rbsp_write_uev`.
- 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.