PageRenderTime 26ms CodeModel.GetById 19ms RepoModel.GetById 0ms app.codeStats 0ms

/interface/mmal/util/mmal_util.h

https://bitbucket.org/manaphassan/userland
C Header | 173 lines | 26 code | 22 blank | 125 comment | 0 complexity | 9d84a3fb012a6c6420bfbbd7e3facec3 MD5 | raw file
  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_UTIL_H
  26. #define MMAL_UTIL_H
  27. #include "interface/mmal/mmal.h"
  28. /** \defgroup MmalUtilities Utility functions
  29. * The utility functions provide helpers for common functionality that is not part
  30. * of the core MMAL API.
  31. * @{
  32. */
  33. /** Offset in bytes of FIELD in TYPE. */
  34. #define MMAL_OFFSET(TYPE, FIELD) ((size_t)((uint8_t *)&((TYPE*)0)->FIELD - (uint8_t *)0))
  35. #ifdef __cplusplus
  36. extern "C" {
  37. #endif
  38. /** Convert a status to a statically-allocated string.
  39. *
  40. * @param status The MMAL status code.
  41. * @return A C string describing the status code.
  42. */
  43. const char *mmal_status_to_string(MMAL_STATUS_T status);
  44. /** Convert stride to pixel width for a given pixel encoding.
  45. *
  46. * @param encoding The pixel encoding (such as one of the \ref MmalEncodings "pre-defined encodings")
  47. * @param stride The stride in bytes.
  48. * @return The width in pixels.
  49. */
  50. uint32_t mmal_encoding_stride_to_width(uint32_t encoding, uint32_t stride);
  51. /** Convert pixel width to stride for a given pixel encoding
  52. *
  53. * @param encoding The pixel encoding (such as one of the \ref MmalEncodings "pre-defined encodings")
  54. * @param width The width in pixels.
  55. * @return The stride in bytes.
  56. */
  57. uint32_t mmal_encoding_width_to_stride(uint32_t encoding, uint32_t width);
  58. /** Convert a port type to a string.
  59. *
  60. * @param type The MMAL port type.
  61. * @return A NULL-terminated string describing the port type.
  62. */
  63. const char* mmal_port_type_to_string(MMAL_PORT_TYPE_T type);
  64. /** Get a parameter from a port allocating the required amount of memory
  65. * for the parameter (i.e. for variable length parameters like URI or arrays).
  66. * The size field will be set on output to the actual size of the
  67. * parameter allocated and retrieved.
  68. *
  69. * The pointer returned must be released by a call to \ref mmal_port_parameter_free().
  70. *
  71. * @param port port to send request to
  72. * @param id parameter id
  73. * @param size initial size hint for allocation (can be 0)
  74. * @param status status of the parameter get operation (can be 0)
  75. * @return pointer to the header of the parameter or NULL on failure.
  76. */
  77. MMAL_PARAMETER_HEADER_T *mmal_port_parameter_alloc_get(MMAL_PORT_T *port,
  78. uint32_t id, uint32_t size, MMAL_STATUS_T *status);
  79. /** Free a parameter structure previously allocated via
  80. * \ref mmal_port_parameter_alloc_get().
  81. *
  82. * @param param pointer to header of the parameter
  83. */
  84. void mmal_port_parameter_free(MMAL_PARAMETER_HEADER_T *param);
  85. /** Copy buffer header metadata from source to destination.
  86. *
  87. * @param dest The destination buffer header.
  88. * @param src The source buffer header.
  89. */
  90. void mmal_buffer_header_copy_header(MMAL_BUFFER_HEADER_T *dest, const MMAL_BUFFER_HEADER_T *src);
  91. /** Create a pool of MMAL_BUFFER_HEADER_T associated with a specific port.
  92. * This allows a client to allocate memory for the payload buffers based on the preferences
  93. * of a port. This for instance will allow the port to allocate memory which can be shared
  94. * between the host processor and videocore.
  95. * After allocation, all allocated buffer headers will have been added to the queue.
  96. *
  97. * It is valid to create a pool with no buffer headers, or with zero size payload buffers.
  98. * The mmal_pool_resize() function can be used to increase or decrease the number of buffer
  99. * headers, or the size of the payload buffers, after creation of the pool.
  100. *
  101. * @param port Port responsible for creating the pool.
  102. * @param headers Number of buffers which will be allocated with the pool.
  103. * @param payload_size Size of the payload buffer which will be allocated in
  104. * each of the buffer headers.
  105. * @return Pointer to the newly created pool or NULL on failure.
  106. */
  107. MMAL_POOL_T *mmal_port_pool_create(MMAL_PORT_T *port,
  108. unsigned int headers, uint32_t payload_size);
  109. /** Destroy a pool of MMAL_BUFFER_HEADER_T associated with a specific port.
  110. * This will also deallocate all of the memory which was allocated when creating or
  111. * resizing the pool.
  112. *
  113. * @param port Pointer to the port responsible for creating the pool.
  114. * @param pool Pointer to the pool to be destroyed.
  115. */
  116. void mmal_port_pool_destroy(MMAL_PORT_T *port, MMAL_POOL_T *pool);
  117. /** Log the content of a \ref MMAL_PORT_T structure.
  118. *
  119. * @param port Pointer to the port to dump.
  120. */
  121. void mmal_log_dump_port(MMAL_PORT_T *port);
  122. /** Log the content of a \ref MMAL_ES_FORMAT_T structure.
  123. *
  124. * @param format Pointer to the format to dump.
  125. */
  126. void mmal_log_dump_format(MMAL_ES_FORMAT_T *format);
  127. /** Return the nth port.
  128. *
  129. * @param comp component to query
  130. * @param index port index
  131. * @param type port type
  132. *
  133. * @return port or NULL if not found
  134. */
  135. MMAL_PORT_T *mmal_util_get_port(MMAL_COMPONENT_T *comp, MMAL_PORT_TYPE_T type, unsigned index);
  136. /** Convert a 4cc into a string.
  137. *
  138. * @param buf Destination for result
  139. * @param len Size of result buffer
  140. * @param fourcc 4cc to be converted
  141. * @return converted string (buf)
  142. *
  143. */
  144. char *mmal_4cc_to_string(char *buf, size_t len, uint32_t fourcc);
  145. #ifdef __cplusplus
  146. }
  147. #endif
  148. /** @} */
  149. #endif