62 lines · c
1/* SPDX-License-Identifier: GPL-2.0 */2/*3 * Copyright (C) 2019-2020 Pengutronix, Michael Tretter <kernel@pengutronix.de>4 */5 6#ifndef __NAL_RBSP_H__7#define __NAL_RBSP_H__8 9#include <linux/kernel.h>10#include <linux/types.h>11 12struct rbsp;13 14struct nal_rbsp_ops {15 int (*rbsp_bit)(struct rbsp *rbsp, int *val);16 int (*rbsp_bits)(struct rbsp *rbsp, int n, unsigned int *val);17 int (*rbsp_uev)(struct rbsp *rbsp, unsigned int *val);18 int (*rbsp_sev)(struct rbsp *rbsp, int *val);19};20 21/**22 * struct rbsp - State object for handling a raw byte sequence payload23 * @data: pointer to the data of the rbsp24 * @size: maximum size of the data of the rbsp25 * @pos: current bit position inside the rbsp26 * @num_consecutive_zeros: number of zeros before @pos27 * @ops: per datatype functions for interacting with the rbsp28 * @error: an error occurred while handling the rbsp29 *30 * This struct is passed around the various parsing functions and tracks the31 * current position within the raw byte sequence payload.32 *33 * The @ops field allows to separate the operation, i.e., reading/writing a34 * value from/to that rbsp, from the structure of the NAL unit. This allows to35 * have a single function for iterating the NAL unit, while @ops has function36 * pointers for handling each type in the rbsp.37 */38struct rbsp {39 u8 *data;40 size_t size;41 unsigned int pos;42 unsigned int num_consecutive_zeros;43 struct nal_rbsp_ops *ops;44 int error;45};46 47extern struct nal_rbsp_ops write;48extern struct nal_rbsp_ops read;49 50void rbsp_init(struct rbsp *rbsp, void *addr, size_t size,51 struct nal_rbsp_ops *ops);52void rbsp_unsupported(struct rbsp *rbsp);53 54void rbsp_bit(struct rbsp *rbsp, int *value);55void rbsp_bits(struct rbsp *rbsp, int n, int *value);56void rbsp_uev(struct rbsp *rbsp, unsigned int *value);57void rbsp_sev(struct rbsp *rbsp, int *value);58 59void rbsp_trailing_bits(struct rbsp *rbsp);60 61#endif /* __NAL_RBSP_H__ */62