162306a36Sopenharmony_ci/* SPDX-License-Identifier: GPL-2.0 */ 262306a36Sopenharmony_ci/* 362306a36Sopenharmony_ci * Copyright (C) 2019-2020 Pengutronix, Michael Tretter <kernel@pengutronix.de> 462306a36Sopenharmony_ci */ 562306a36Sopenharmony_ci 662306a36Sopenharmony_ci#ifndef __NAL_RBSP_H__ 762306a36Sopenharmony_ci#define __NAL_RBSP_H__ 862306a36Sopenharmony_ci 962306a36Sopenharmony_ci#include <linux/kernel.h> 1062306a36Sopenharmony_ci#include <linux/types.h> 1162306a36Sopenharmony_ci 1262306a36Sopenharmony_cistruct rbsp; 1362306a36Sopenharmony_ci 1462306a36Sopenharmony_cistruct nal_rbsp_ops { 1562306a36Sopenharmony_ci int (*rbsp_bit)(struct rbsp *rbsp, int *val); 1662306a36Sopenharmony_ci int (*rbsp_bits)(struct rbsp *rbsp, int n, unsigned int *val); 1762306a36Sopenharmony_ci int (*rbsp_uev)(struct rbsp *rbsp, unsigned int *val); 1862306a36Sopenharmony_ci int (*rbsp_sev)(struct rbsp *rbsp, int *val); 1962306a36Sopenharmony_ci}; 2062306a36Sopenharmony_ci 2162306a36Sopenharmony_ci/** 2262306a36Sopenharmony_ci * struct rbsp - State object for handling a raw byte sequence payload 2362306a36Sopenharmony_ci * @data: pointer to the data of the rbsp 2462306a36Sopenharmony_ci * @size: maximum size of the data of the rbsp 2562306a36Sopenharmony_ci * @pos: current bit position inside the rbsp 2662306a36Sopenharmony_ci * @num_consecutive_zeros: number of zeros before @pos 2762306a36Sopenharmony_ci * @ops: per datatype functions for interacting with the rbsp 2862306a36Sopenharmony_ci * @error: an error occurred while handling the rbsp 2962306a36Sopenharmony_ci * 3062306a36Sopenharmony_ci * This struct is passed around the various parsing functions and tracks the 3162306a36Sopenharmony_ci * current position within the raw byte sequence payload. 3262306a36Sopenharmony_ci * 3362306a36Sopenharmony_ci * The @ops field allows to separate the operation, i.e., reading/writing a 3462306a36Sopenharmony_ci * value from/to that rbsp, from the structure of the NAL unit. This allows to 3562306a36Sopenharmony_ci * have a single function for iterating the NAL unit, while @ops has function 3662306a36Sopenharmony_ci * pointers for handling each type in the rbsp. 3762306a36Sopenharmony_ci */ 3862306a36Sopenharmony_cistruct rbsp { 3962306a36Sopenharmony_ci u8 *data; 4062306a36Sopenharmony_ci size_t size; 4162306a36Sopenharmony_ci unsigned int pos; 4262306a36Sopenharmony_ci unsigned int num_consecutive_zeros; 4362306a36Sopenharmony_ci struct nal_rbsp_ops *ops; 4462306a36Sopenharmony_ci int error; 4562306a36Sopenharmony_ci}; 4662306a36Sopenharmony_ci 4762306a36Sopenharmony_ciextern struct nal_rbsp_ops write; 4862306a36Sopenharmony_ciextern struct nal_rbsp_ops read; 4962306a36Sopenharmony_ci 5062306a36Sopenharmony_civoid rbsp_init(struct rbsp *rbsp, void *addr, size_t size, 5162306a36Sopenharmony_ci struct nal_rbsp_ops *ops); 5262306a36Sopenharmony_civoid rbsp_unsupported(struct rbsp *rbsp); 5362306a36Sopenharmony_ci 5462306a36Sopenharmony_civoid rbsp_bit(struct rbsp *rbsp, int *value); 5562306a36Sopenharmony_civoid rbsp_bits(struct rbsp *rbsp, int n, int *value); 5662306a36Sopenharmony_civoid rbsp_uev(struct rbsp *rbsp, unsigned int *value); 5762306a36Sopenharmony_civoid rbsp_sev(struct rbsp *rbsp, int *value); 5862306a36Sopenharmony_ci 5962306a36Sopenharmony_civoid rbsp_trailing_bits(struct rbsp *rbsp); 6062306a36Sopenharmony_ci 6162306a36Sopenharmony_ci#endif /* __NAL_RBSP_H__ */ 62