nal-rbsp.h 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. /* SPDX-License-Identifier: GPL-2.0 */
  2. /*
  3. * Copyright (C) 2019-2020 Pengutronix, Michael Tretter <[email protected]>
  4. */
  5. #ifndef __NAL_RBSP_H__
  6. #define __NAL_RBSP_H__
  7. #include <linux/kernel.h>
  8. #include <linux/types.h>
  9. struct rbsp;
  10. struct nal_rbsp_ops {
  11. int (*rbsp_bit)(struct rbsp *rbsp, int *val);
  12. int (*rbsp_bits)(struct rbsp *rbsp, int n, unsigned int *val);
  13. int (*rbsp_uev)(struct rbsp *rbsp, unsigned int *val);
  14. int (*rbsp_sev)(struct rbsp *rbsp, int *val);
  15. };
  16. /**
  17. * struct rbsp - State object for handling a raw byte sequence payload
  18. * @data: pointer to the data of the rbsp
  19. * @size: maximum size of the data of the rbsp
  20. * @pos: current bit position inside the rbsp
  21. * @num_consecutive_zeros: number of zeros before @pos
  22. * @ops: per datatype functions for interacting with the rbsp
  23. * @error: an error occurred while handling the rbsp
  24. *
  25. * This struct is passed around the various parsing functions and tracks the
  26. * current position within the raw byte sequence payload.
  27. *
  28. * The @ops field allows to separate the operation, i.e., reading/writing a
  29. * value from/to that rbsp, from the structure of the NAL unit. This allows to
  30. * have a single function for iterating the NAL unit, while @ops has function
  31. * pointers for handling each type in the rbsp.
  32. */
  33. struct rbsp {
  34. u8 *data;
  35. size_t size;
  36. unsigned int pos;
  37. unsigned int num_consecutive_zeros;
  38. struct nal_rbsp_ops *ops;
  39. int error;
  40. };
  41. extern struct nal_rbsp_ops write;
  42. extern struct nal_rbsp_ops read;
  43. void rbsp_init(struct rbsp *rbsp, void *addr, size_t size,
  44. struct nal_rbsp_ops *ops);
  45. void rbsp_unsupported(struct rbsp *rbsp);
  46. void rbsp_bit(struct rbsp *rbsp, int *value);
  47. void rbsp_bits(struct rbsp *rbsp, int n, int *value);
  48. void rbsp_uev(struct rbsp *rbsp, unsigned int *value);
  49. void rbsp_sev(struct rbsp *rbsp, int *value);
  50. void rbsp_trailing_bits(struct rbsp *rbsp);
  51. #endif /* __NAL_RBSP_H__ */