reference-libobs-util-circlebuf.rst 4.3 KB

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