reference-libobs-util-circlebuf.rst 4.2 KB

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