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 12 struct rbsp; 13 14 struct 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 payload 23 * @data: pointer to the data of the rbsp 24 * @size: maximum size of the data of the rbsp 25 * @pos: current bit position inside the rbsp 26 * @num_consecutive_zeros: number of zeros before @pos 27 * @ops: per datatype functions for interacting with the rbsp 28 * @error: an error occurred while handling the rbsp 29 * 30 * This struct is passed around the various parsing functions and tracks the 31 * current position within the raw byte sequence payload. 32 * 33 * The @ops field allows to separate the operation, i.e., reading/writing a 34 * value from/to that rbsp, from the structure of the NAL unit. This allows to 35 * have a single function for iterating the NAL unit, while @ops has function 36 * pointers for handling each type in the rbsp. 37 */ 38 struct 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 47 extern struct nal_rbsp_ops write; 48 extern struct nal_rbsp_ops read; 49 50 void rbsp_init(struct rbsp *rbsp, void *addr, size_t size, 51 struct nal_rbsp_ops *ops); 52 void rbsp_unsupported(struct rbsp *rbsp); 53 54 void rbsp_bit(struct rbsp *rbsp, int *value); 55 void rbsp_bits(struct rbsp *rbsp, int n, int *value); 56 void rbsp_uev(struct rbsp *rbsp, unsigned int *value); 57 void rbsp_sev(struct rbsp *rbsp, int *value); 58 59 void rbsp_trailing_bits(struct rbsp *rbsp); 60 61 #endif /* __NAL_RBSP_H__ */ 62