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_port.h 12KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286
  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_PORT_H
  26. #define MMAL_PORT_H
  27. #ifdef __cplusplus
  28. extern "C" {
  29. #endif
  30. /** \defgroup MmalPort Ports
  31. * Definition of a MMAL port and its associated API */
  32. /* @{ */
  33. #include "mmal_types.h"
  34. #include "mmal_format.h"
  35. #include "mmal_buffer.h"
  36. #include "mmal_parameters.h"
  37. /** List of port types */
  38. typedef enum
  39. {
  40. MMAL_PORT_TYPE_UNKNOWN = 0, /**< Unknown port type */
  41. MMAL_PORT_TYPE_CONTROL, /**< Control port */
  42. MMAL_PORT_TYPE_INPUT, /**< Input port */
  43. MMAL_PORT_TYPE_OUTPUT, /**< Output port */
  44. MMAL_PORT_TYPE_CLOCK, /**< Clock port */
  45. MMAL_PORT_TYPE_INVALID = 0xffffffff /**< Dummy value to force 32bit enum */
  46. } MMAL_PORT_TYPE_T;
  47. /** \name Port capabilities
  48. * \anchor portcapabilities
  49. * The following flags describe the capabilities advertised by a port */
  50. /* @{ */
  51. /** The port is pass-through and doesn't need buffer headers allocated */
  52. #define MMAL_PORT_CAPABILITY_PASSTHROUGH 0x01
  53. /** The port wants to allocate the buffer payloads. This signals a preference that
  54. * payload allocation should be done on this port for efficiency reasons. */
  55. #define MMAL_PORT_CAPABILITY_ALLOCATION 0x02
  56. /** The port supports format change events. This applies to input ports and is used
  57. * to let the client know whether the port supports being reconfigured via a format
  58. * change event (i.e. without having to disable the port). */
  59. #define MMAL_PORT_CAPABILITY_SUPPORTS_EVENT_FORMAT_CHANGE 0x04
  60. /* @} */
  61. /** Definition of a port.
  62. * A port is the entity that is exposed by components to receive or transmit
  63. * buffer headers (\ref MMAL_BUFFER_HEADER_T). A port is defined by its
  64. * \ref MMAL_ES_FORMAT_T.
  65. *
  66. * It may be possible to override the buffer requirements of a port by using
  67. * the MMAL_PARAMETER_BUFFER_REQUIREMENTS parameter.
  68. */
  69. typedef struct MMAL_PORT_T
  70. {
  71. struct MMAL_PORT_PRIVATE_T *priv; /**< Private member used by the framework */
  72. const char *name; /**< Port name. Used for debugging purposes (Read Only) */
  73. MMAL_PORT_TYPE_T type; /**< Type of the port (Read Only) */
  74. uint16_t index; /**< Index of the port in its type list (Read Only) */
  75. uint16_t index_all; /**< Index of the port in the list of all ports (Read Only) */
  76. uint32_t is_enabled; /**< Indicates whether the port is enabled or not (Read Only) */
  77. MMAL_ES_FORMAT_T *format; /**< Format of the elementary stream */
  78. uint32_t buffer_num_min; /**< Minimum number of buffers the port requires (Read Only).
  79. This is set by the component. */
  80. uint32_t buffer_size_min; /**< Minimum size of buffers the port requires (Read Only).
  81. This is set by the component. */
  82. uint32_t buffer_alignment_min; /**< Minimum alignment requirement for the buffers (Read Only).
  83. A value of zero means no special alignment requirements.
  84. This is set by the component. */
  85. uint32_t buffer_num_recommended; /**< Number of buffers the port recommends for optimal performance (Read Only).
  86. A value of zero means no special recommendation.
  87. This is set by the component. */
  88. uint32_t buffer_size_recommended; /**< Size of buffers the port recommends for optimal performance (Read Only).
  89. A value of zero means no special recommendation.
  90. This is set by the component. */
  91. uint32_t buffer_num; /**< Actual number of buffers the port will use.
  92. This is set by the client. */
  93. uint32_t buffer_size; /**< Actual maximum size of the buffers that will be sent
  94. to the port. This is set by the client. */
  95. struct MMAL_COMPONENT_T *component; /**< Component this port belongs to (Read Only) */
  96. struct MMAL_PORT_USERDATA_T *userdata; /**< Field reserved for use by the client */
  97. uint32_t capabilities; /**< Flags describing the capabilities of a port (Read Only).
  98. * Bitwise combination of \ref portcapabilities "Port capabilities"
  99. * values.
  100. */
  101. } MMAL_PORT_T;
  102. /** Commit format changes on a port.
  103. *
  104. * @param port The port for which format changes are to be committed.
  105. * @return MMAL_SUCCESS on success
  106. */
  107. MMAL_STATUS_T mmal_port_format_commit(MMAL_PORT_T *port);
  108. /** Definition of the callback used by a port to send a \ref MMAL_BUFFER_HEADER_T
  109. * back to the user.
  110. *
  111. * @param port The port sending the buffer header.
  112. * @param buffer The buffer header being sent.
  113. */
  114. typedef void (*MMAL_PORT_BH_CB_T)(MMAL_PORT_T *port, MMAL_BUFFER_HEADER_T *buffer);
  115. /** Enable processing on a port
  116. *
  117. * If this port is connected to another, the given callback must be NULL, while for a
  118. * disconnected port, the callback must be non-NULL.
  119. *
  120. * If this is a connected output port and is successfully enabled:
  121. * <ul>
  122. * <li>The port shall be populated with a pool of buffers, allocated as required, according
  123. * to the buffer_num and buffer_size values.
  124. * <li>The input port to which it is connected shall be set to the same buffer
  125. * configuration and then be enabled. Should that fail, the original port shall be
  126. * disabled.
  127. * </ul>
  128. *
  129. * @param port port to enable
  130. * @param cb callback use by the port to send a \ref MMAL_BUFFER_HEADER_T back
  131. * @return MMAL_SUCCESS on success
  132. */
  133. MMAL_STATUS_T mmal_port_enable(MMAL_PORT_T *port, MMAL_PORT_BH_CB_T cb);
  134. /** Disable processing on a port
  135. *
  136. * Disabling a port will stop all processing on this port and return all (non-processed)
  137. * buffer headers to the client.
  138. *
  139. * If this is a connected output port, the input port to which it is connected shall
  140. * also be disabled. Any buffer pool shall be released.
  141. *
  142. * @param port port to disable
  143. * @return MMAL_SUCCESS on success
  144. */
  145. MMAL_STATUS_T mmal_port_disable(MMAL_PORT_T *port);
  146. /** Ask a port to release all the buffer headers it currently has.
  147. *
  148. * Flushing a port will ask the port to send all the buffer headers it currently has
  149. * to the client. Flushing is an asynchronous request and the flush call will
  150. * return before all the buffer headers are returned to the client.
  151. * It is up to the client to keep a count on the buffer headers to know when the
  152. * flush operation has completed.
  153. * It is also important to note that flushing will also reset the state of the port
  154. * and any processing which was buffered by the port will be lost.
  155. *
  156. * \attention Flushing a connected port behaviour TBD.
  157. *
  158. * @param port The port to flush.
  159. * @return MMAL_SUCCESS on success
  160. */
  161. MMAL_STATUS_T mmal_port_flush(MMAL_PORT_T *port);
  162. /** Set a parameter on a port.
  163. *
  164. * @param port The port to which the request is sent.
  165. * @param param The pointer to the header of the parameter to set.
  166. * @return MMAL_SUCCESS on success
  167. */
  168. MMAL_STATUS_T mmal_port_parameter_set(MMAL_PORT_T *port,
  169. const MMAL_PARAMETER_HEADER_T *param);
  170. /** Get a parameter from a port.
  171. * The size field must be set on input to the maximum size of the parameter
  172. * (including the header) and will be set on output to the actual size of the
  173. * parameter retrieved.
  174. *
  175. * \note If MMAL_ENOSPC is returned, the parameter is larger than the size
  176. * given. The given parameter will have been filled up to its size and then
  177. * the size field set to the full parameter's size. This can be used to
  178. * resize the parameter buffer so that a second call should succeed.
  179. *
  180. * @param port The port to which the request is sent.
  181. * @param param The pointer to the header of the parameter to get.
  182. * @return MMAL_SUCCESS on success
  183. */
  184. MMAL_STATUS_T mmal_port_parameter_get(MMAL_PORT_T *port,
  185. MMAL_PARAMETER_HEADER_T *param);
  186. /** Send a buffer header to a port.
  187. *
  188. * @param port The port to which the buffer header is to be sent.
  189. * @param buffer The buffer header to send.
  190. * @return MMAL_SUCCESS on success
  191. */
  192. MMAL_STATUS_T mmal_port_send_buffer(MMAL_PORT_T *port,
  193. MMAL_BUFFER_HEADER_T *buffer);
  194. /** Connect an output port to an input port.
  195. *
  196. * When connected and enabled, buffers will automatically progress from the
  197. * output port to the input port when they become available, and released back
  198. * to the output port when no longer required by the input port.
  199. *
  200. * Ports can be given either way around, but one must be an output port and
  201. * the other must be an input port. Neither can be connected or enabled
  202. * already. The format of the output port will be applied to the input port
  203. * on connection.
  204. *
  205. * @param port One of the ports to connect.
  206. * @param other_port The other port to connect.
  207. * @return MMAL_SUCCESS on success.
  208. */
  209. MMAL_STATUS_T mmal_port_connect(MMAL_PORT_T *port, MMAL_PORT_T *other_port);
  210. /** Disconnect a connected port.
  211. *
  212. * If the port is not connected, an error will be returned. Otherwise, if the
  213. * ports are enabled, they will be disabled and any buffer pool created will be
  214. * freed.
  215. *
  216. * @param port The ports to disconnect.
  217. * @return MMAL_SUCCESS on success.
  218. */
  219. MMAL_STATUS_T mmal_port_disconnect(MMAL_PORT_T *port);
  220. /** Allocate a payload buffer.
  221. * This allows a client to allocate memory for a payload buffer based on the preferences
  222. * of a port. This for instance will allow the port to allocate memory which can be shared
  223. * between the host processor and videocore.
  224. *
  225. * See \ref mmal_pool_create_with_allocator().
  226. *
  227. * @param port Port responsible for allocating the memory.
  228. * @param payload_size Size of the payload buffer which will be allocated.
  229. *
  230. * @return Pointer to the allocated memory.
  231. */
  232. uint8_t *mmal_port_payload_alloc(MMAL_PORT_T *port, uint32_t payload_size);
  233. /** Free a payload buffer.
  234. * This allows a client to free memory allocated by a previous call to \ref mmal_port_payload_alloc.
  235. *
  236. * See \ref mmal_pool_create_with_allocator().
  237. *
  238. * @param port Port responsible for allocating the memory.
  239. * @param payload Pointer to the memory to free.
  240. */
  241. void mmal_port_payload_free(MMAL_PORT_T *port, uint8_t *payload);
  242. /** Get an empty event buffer header from a port
  243. *
  244. * @param port The port from which to get the event buffer header.
  245. * @param buffer The address of a buffer header pointer, which will be set on return.
  246. * @param event The specific event FourCC required. See the \ref MmalEvents "pre-defined events".
  247. * @return MMAL_SUCCESS on success
  248. */
  249. MMAL_STATUS_T mmal_port_event_get(MMAL_PORT_T *port, MMAL_BUFFER_HEADER_T **buffer, uint32_t event);
  250. /* @} */
  251. #ifdef __cplusplus
  252. }
  253. #endif
  254. #endif /* MMAL_PORT_H */