1
0

reference-libobs-util-circlebuf.rst 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158
  1. Circular Buffers
  2. ================
  3. A circular buffer that will automatically increase in size as necessary
  4. as data is pushed to the front or back.
  5. .. code:: cpp
  6. #include <util/circlebuf.h>
  7. Circular Buffer Structure (struct circlebuf)
  8. --------------------------------------------
  9. .. struct:: circlebuf
  10. .. member:: void *circlebuf.data
  11. .. member:: size_t circlebuf.size
  12. .. member:: size_t circlebuf.start_pos
  13. .. member:: size_t circlebuf.end_pos
  14. .. member:: size_t circlebuf.capacity
  15. Circular Buffer Inline Functions
  16. --------------------------------
  17. .. function:: void circlebuf_init(struct circlebuf *cb)
  18. Initializes a circular buffer (just zeroes out the entire structure).
  19. :param cb: The circular buffer
  20. ---------------------
  21. .. function:: void circlebuf_free(struct circlebuf *cb)
  22. Frees a circular buffer.
  23. :param cb: The circular buffer
  24. ---------------------
  25. .. function:: void circlebuf_reserve(struct circlebuf *cb, size_t capacity)
  26. Reserves a specific amount of buffer space to ensure minimum
  27. upsizing.
  28. :param cb: The circular buffer
  29. :param capacity: The new capacity, in bytes
  30. ---------------------
  31. .. function:: void circlebuf_upsize(struct circlebuf *cb, size_t size)
  32. Sets the current active (not just reserved) size. Any new data is
  33. zeroed.
  34. :param cb: The circular buffer
  35. :param size: The new size, in bytes
  36. ---------------------
  37. .. function:: void circlebuf_place(struct circlebuf *cb, size_t position, const void *data, size_t size)
  38. Places data at a specific positional index (relative to the starting
  39. point) within the circular buffer.
  40. :param cb: The circular buffer
  41. :param position: Positional index relative to starting point
  42. :param data: Data to insert
  43. :param size: Size of data to insert
  44. ---------------------
  45. .. function:: void circlebuf_push_back(struct circlebuf *cb, const void *data, size_t size)
  46. Pushes data to the end of the circular buffer.
  47. :param cb: The circular buffer
  48. :param data: Data
  49. :param size: Size of data
  50. ---------------------
  51. .. function:: void circlebuf_push_front(struct circlebuf *cb, const void *data, size_t size)
  52. Pushes data to the front of the circular buffer.
  53. :param cb: The circular buffer
  54. :param data: Data
  55. :param size: Size of data
  56. ---------------------
  57. .. function:: void circlebuf_push_back_zero(struct circlebuf *cb, size_t size)
  58. Pushes zeroed data to the end of the circular buffer.
  59. :param cb: The circular buffer
  60. :param size: Size
  61. ---------------------
  62. .. function:: void circlebuf_push_front_zero(struct circlebuf *cb, size_t size)
  63. Pushes zeroed data to the front of the circular buffer.
  64. :param cb: The circular buffer
  65. :param size: Size
  66. ---------------------
  67. .. function:: void circlebuf_peek_front(struct circlebuf *cb, void *data, size_t size)
  68. Peeks data at the front of the circular buffer.
  69. :param cb: The circular buffer
  70. :param data: Buffer to store data in
  71. :param size: Size of data to retrieve
  72. ---------------------
  73. .. function:: void circlebuf_peek_back(struct circlebuf *cb, void *data, size_t size)
  74. Peeks data at the back of the circular buffer.
  75. :param cb: The circular buffer
  76. :param data: Buffer to store data in
  77. :param size: Size of data to retrieve
  78. ---------------------
  79. .. function:: void circlebuf_pop_front(struct circlebuf *cb, void *data, size_t size)
  80. Pops data from the front of the circular buffer.
  81. :param cb: The circular buffer
  82. :param data: Buffer to store data in, or *NULL*
  83. :param size: Size of data to retrieve
  84. ---------------------
  85. .. function:: void circlebuf_pop_back(struct circlebuf *cb, void *data, size_t size)
  86. Pops data from the back of the circular buffer.
  87. :param cb: The circular buffer
  88. :param data: Buffer to store data in, or *NULL*
  89. :param size: Size of data to retrieve
  90. ---------------------
  91. .. function:: void *circlebuf_data(struct circlebuf *cb, size_t idx)
  92. Gets a direct pointer to data at a specific positional index within
  93. the circular buffer, relative to the starting point.
  94. :param cb: The circular buffer
  95. :param idx: Byte index relative to the starting point