Projektarbeit Line Following Robot bei Prof. Chowanetz im WS22/23
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

mmal_pool.h 7.6KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167
  1. /*
  2. Copyright (c) 2012, Broadcom Europe Ltd
  3. All rights reserved.
  4. Redistribution and use in source and binary forms, with or without
  5. modification, are permitted provided that the following conditions are met:
  6. * Redistributions of source code must retain the above copyright
  7. notice, this list of conditions and the following disclaimer.
  8. * Redistributions in binary form must reproduce the above copyright
  9. notice, this list of conditions and the following disclaimer in the
  10. documentation and/or other materials provided with the distribution.
  11. * Neither the name of the copyright holder nor the
  12. names of its contributors may be used to endorse or promote products
  13. derived from this software without specific prior written permission.
  14. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
  15. ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
  16. WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  17. DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY
  18. DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
  19. (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
  20. LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
  21. ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  22. (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  23. SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  24. */
  25. #ifndef MMAL_POOL_H
  26. #define MMAL_POOL_H
  27. #ifdef __cplusplus
  28. extern "C" {
  29. #endif
  30. /** \defgroup MmalPool Pools of buffer headers
  31. * A pool of buffer headers is composed of a queue (\ref MMAL_QUEUE_T) and a user
  32. * specified number of buffer headers (\ref MMAL_BUFFER_HEADER_T). */
  33. /* @{ */
  34. #include "mmal_queue.h"
  35. /** Definition of a pool */
  36. typedef struct MMAL_POOL_T
  37. {
  38. MMAL_QUEUE_T *queue; /**< Queue used by the pool */
  39. uint32_t headers_num; /**< Number of buffer headers in the pool */
  40. MMAL_BUFFER_HEADER_T **header; /**< Array of buffer headers belonging to the pool */
  41. } MMAL_POOL_T;
  42. /** Allocator alloc prototype
  43. *
  44. * @param context The context pointer passed in on pool creation.
  45. * @param size The size of the allocation required, in bytes.
  46. * @return The pointer to the newly allocated memory, or NULL on failure.
  47. */
  48. typedef void *(*mmal_pool_allocator_alloc_t)(void *context, uint32_t size);
  49. /** Allocator free prototype
  50. *
  51. * @param context The context pointer passed in on pool creation.
  52. * @param mem The pointer to the memory to be released.
  53. */
  54. typedef void (*mmal_pool_allocator_free_t)(void *context, void *mem);
  55. /** Create a pool of MMAL_BUFFER_HEADER_T.
  56. * After allocation, all allocated buffer headers will have been added to the queue.
  57. *
  58. * It is valid to create a pool with no buffer headers, or with zero size payload buffers.
  59. * The mmal_pool_resize() function can be used to increase or decrease the number of buffer
  60. * headers, or the size of the payload buffers, after creation of the pool.
  61. *
  62. * The payload buffers may also be allocated independently by the client, and assigned
  63. * to the buffer headers, but it will be the responsibility of the client to deal with
  64. * resizing and releasing the memory. It is recommended that mmal_pool_create_with_allocator()
  65. * is used in this case, supplying allocator function pointers that will be used as
  66. * necessary by MMAL.
  67. *
  68. * @param headers Number of buffer headers to be allocated with the pool.
  69. * @param payload_size Size of the payload buffer that will be allocated in
  70. * each of the buffer headers.
  71. * @return Pointer to the newly created pool or NULL on failure.
  72. */
  73. MMAL_POOL_T *mmal_pool_create(unsigned int headers, uint32_t payload_size);
  74. /** Create a pool of MMAL_BUFFER_HEADER_T.
  75. * After allocation, all allocated buffer headers will have been added to the queue.
  76. *
  77. * It is valid to create a pool with no buffer headers, or with zero size payload buffers.
  78. * The mmal_pool_resize() function can be used to increase or decrease the number of buffer
  79. * headers, or the size of the payload buffers, after creation of the pool. The allocators
  80. * passed during creation shall be used when resizing the payload buffers.
  81. *
  82. * @param headers Number of buffer headers to be allocated with the pool.
  83. * @param payload_size Size of the payload buffer that will be allocated in
  84. * each of the buffer headers.
  85. * @param allocator_context Pointer to the context of the allocator.
  86. * @param allocator_alloc Function pointer for the alloc call of the allocator.
  87. * @param allocator_free Function pointer for the free call of the allocator.
  88. *
  89. * @return Pointer to the newly created pool or NULL on failure.
  90. */
  91. MMAL_POOL_T *mmal_pool_create_with_allocator(unsigned int headers, uint32_t payload_size,
  92. void *allocator_context, mmal_pool_allocator_alloc_t allocator_alloc,
  93. mmal_pool_allocator_free_t allocator_free);
  94. /** Destroy a pool of MMAL_BUFFER_HEADER_T.
  95. * This will also deallocate all of the memory which was allocated when creating or
  96. * resizing the pool.
  97. *
  98. * If payload buffers have been allocated independently by the client, they should be
  99. * released prior to calling this function. If the client provided allocator functions,
  100. * the allocator_free function shall be called for each payload buffer.
  101. *
  102. * @param pool Pointer to a pool
  103. */
  104. void mmal_pool_destroy(MMAL_POOL_T *pool);
  105. /** Resize a pool of MMAL_BUFFER_HEADER_T.
  106. * This allows modifying either the number of allocated buffers, the payload size or both at the
  107. * same time.
  108. *
  109. * @param pool Pointer to the pool
  110. * @param headers New number of buffer headers to be allocated in the pool.
  111. * It is not valid to pass zero for the number of buffers.
  112. * @param payload_size Size of the payload buffer that will be allocated in
  113. * each of the buffer headers.
  114. * If this is set to 0, all payload buffers shall be released.
  115. * @return MMAL_SUCCESS or an error on failure.
  116. */
  117. MMAL_STATUS_T mmal_pool_resize(MMAL_POOL_T *pool, unsigned int headers, uint32_t payload_size);
  118. /** Definition of the callback used by a pool to signal back to the user that a buffer header
  119. * has been released back to the pool.
  120. *
  121. * @param pool Pointer to the pool
  122. * @param buffer Buffer header just released
  123. * @param userdata User specific data passed in when setting the callback
  124. * @return True to have the buffer header put back in the pool's queue, false if the buffer
  125. * header has been taken within the callback.
  126. */
  127. typedef MMAL_BOOL_T (*MMAL_POOL_BH_CB_T)(MMAL_POOL_T *pool, MMAL_BUFFER_HEADER_T *buffer, void *userdata);
  128. /** Set a buffer header release callback to the pool.
  129. * Each time a buffer header is released to the pool, the callback will be triggered.
  130. *
  131. * @param pool Pointer to a pool
  132. * @param cb Callback function
  133. * @param userdata User specific data which will be passed with each callback
  134. */
  135. void mmal_pool_callback_set(MMAL_POOL_T *pool, MMAL_POOL_BH_CB_T cb, void *userdata);
  136. /** Set a pre-release callback for all buffer headers in the pool.
  137. * Each time a buffer header is about to be released to the pool, the callback
  138. * will be triggered.
  139. *
  140. * @param pool Pointer to the pool
  141. * @param cb Pre-release callback function
  142. * @param userdata User-specific data passed back with each callback
  143. */
  144. void mmal_pool_pre_release_callback_set(MMAL_POOL_T *pool, MMAL_BH_PRE_RELEASE_CB_T cb, void *userdata);
  145. /* @} */
  146. #ifdef __cplusplus
  147. }
  148. #endif
  149. #endif /* MMAL_POOL_H */