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_graph.h 11KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243
  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_GRAPH_H
  26. #define MMAL_GRAPH_H
  27. #include "util/mmal_connection.h"
  28. /** \defgroup MmalGraphUtility Graph Utility
  29. * \ingroup MmalUtilities
  30. * The graph utility functions allows one to easily create graphs of MMAL components.
  31. *
  32. * @{
  33. */
  34. #ifdef __cplusplus
  35. extern "C" {
  36. #endif
  37. /** List of topology types */
  38. typedef enum
  39. {
  40. MMAL_GRAPH_TOPOLOGY_ALL = 0, /**< All input ports and output ports are linked */
  41. MMAL_GRAPH_TOPOLOGY_STRAIGHT, /**< Input ports and output ports of the same index are linked */
  42. MMAL_GRAPH_TOPOLOGY_CUSTOM, /**< Custom defined topology */
  43. MMAL_GRAPH_TOPOLOGY_MAX
  44. } MMAL_GRAPH_TOPOLOGY_T;
  45. /** Structure describing a graph */
  46. typedef struct MMAL_GRAPH_T
  47. {
  48. /** Pointer to private data of the client */
  49. struct MMAL_GRAPH_USERDATA_T *userdata;
  50. /** Optional callback that the client can set to get notified when the graph is going to be destroyed */
  51. void (*pf_destroy)(struct MMAL_GRAPH_T *);
  52. /** Optional callback that the client can set to intercept parameter requests on ports exposed by the graph */
  53. MMAL_STATUS_T (*pf_parameter_set)(struct MMAL_GRAPH_T *, MMAL_PORT_T *port, const MMAL_PARAMETER_HEADER_T *param);
  54. /** Optional callback that the client can set to intercept parameter requests on ports exposed by the graph */
  55. MMAL_STATUS_T (*pf_parameter_get)(struct MMAL_GRAPH_T *, MMAL_PORT_T *port, MMAL_PARAMETER_HEADER_T *param);
  56. /** Optional callback that the client can set to intercept format commit calls on ports exposed by the graph */
  57. MMAL_STATUS_T (*pf_format_commit)(struct MMAL_GRAPH_T *, MMAL_PORT_T *port);
  58. /** Optional callback that the client can set to intercept send buffer calls on ports exposed by the graph */
  59. MMAL_STATUS_T (*pf_send_buffer)(struct MMAL_GRAPH_T *, MMAL_PORT_T *port, MMAL_BUFFER_HEADER_T *buffer);
  60. /** Optional callback that the client can set to intercept buffer callbacks on ports exposed by the graph */
  61. MMAL_STATUS_T (*pf_return_buffer)(struct MMAL_GRAPH_T *, MMAL_PORT_T *port, MMAL_BUFFER_HEADER_T *buffer);
  62. /** Optional callback that the client can set to intercept payload alloc calls on ports exposed by the graph */
  63. MMAL_STATUS_T (*pf_payload_alloc)(struct MMAL_GRAPH_T *, MMAL_PORT_T *port, uint32_t payload_size, uint8_t **);
  64. /** Optional callback that the client can set to intercept payload free calls on ports exposed by the graph */
  65. MMAL_STATUS_T (*pf_payload_free)(struct MMAL_GRAPH_T *, MMAL_PORT_T *port, uint8_t *payload);
  66. /** Optional callback that the client can set to intercept flush calls on ports exposed by the graph */
  67. MMAL_STATUS_T (*pf_flush)(struct MMAL_GRAPH_T *, MMAL_PORT_T *port);
  68. /** Optional callback that the client can set to control callbacks from the internal components of the graph */
  69. /** Optional callback that the client can set to intercept enable calls on ports exposed by the graph */
  70. MMAL_STATUS_T (*pf_enable)(struct MMAL_GRAPH_T *, MMAL_PORT_T *port);
  71. /** Optional callback that the client can set to intercept disable calls on ports exposed by the graph */
  72. MMAL_STATUS_T (*pf_disable)(struct MMAL_GRAPH_T *, MMAL_PORT_T *port);
  73. /** Optional callback that the client can set to control callbacks from the internal components of the graph */
  74. MMAL_STATUS_T (*pf_control_callback)(struct MMAL_GRAPH_T *, MMAL_PORT_T *port, MMAL_BUFFER_HEADER_T *buffer);
  75. /** Optional callback that the client can set to intercept component_enable/disable calls made to the graph */
  76. MMAL_STATUS_T (*pf_graph_enable)(struct MMAL_GRAPH_T *, MMAL_BOOL_T enable);
  77. /** Optional callback that the client can set to intercept buffers going through internal connections.
  78. * This will only be triggered if the connection is not tunnelled */
  79. MMAL_STATUS_T (*pf_connection_buffer)(struct MMAL_GRAPH_T *, MMAL_CONNECTION_T *connection, MMAL_BUFFER_HEADER_T *buffer);
  80. } MMAL_GRAPH_T;
  81. /** Create an instance of a graph.
  82. * The newly created graph will need to be populated by the client.
  83. *
  84. * @param graph returned graph
  85. * @param userdata_size size to be allocated for the userdata field
  86. * @return MMAL_SUCCESS on success
  87. */
  88. MMAL_STATUS_T mmal_graph_create(MMAL_GRAPH_T **graph, unsigned int userdata_size);
  89. /** Add a component to a graph.
  90. * Allows the client to add a component to the graph.
  91. *
  92. * @param graph instance of the graph
  93. * @param component component to add to a graph
  94. * @return MMAL_SUCCESS on success
  95. */
  96. MMAL_STATUS_T mmal_graph_add_component(MMAL_GRAPH_T *graph, MMAL_COMPONENT_T *component);
  97. /** Describe the topology of the ports of a component.
  98. * Allows the client to describe the topology of a component. This information
  99. * is used by the graph to choose which action to perform when
  100. * enabling / disabling / committing / flushing a port exposed by the graph.
  101. * Note that by default the topology of a component is set to MMAL_GRAPH_TOPOLOGY_ALL.
  102. *
  103. * @param graph instance of the graph
  104. * @param component component to describe
  105. * @param topology type of topology used by this component
  106. * @param input output index (or -1 if sink) linked to each input port
  107. * @param input_num number of indexes in the input list
  108. * @param output input index (or -1 if source) linked to each output port
  109. * @param output_num number of indexes in the output list
  110. * @return MMAL_SUCCESS on success
  111. */
  112. MMAL_STATUS_T mmal_graph_component_topology(MMAL_GRAPH_T *graph, MMAL_COMPONENT_T *component,
  113. MMAL_GRAPH_TOPOLOGY_T topology, int8_t *input, unsigned int input_num,
  114. int8_t *output, unsigned int output_num);
  115. /** Add a port to a graph.
  116. * Allows the client to add an input or output port to a graph. The given port
  117. * will effectively become an end point for the graph.
  118. *
  119. * @param graph instance of the graph
  120. * @param port port to add to the graph
  121. * @return MMAL_SUCCESS on success
  122. */
  123. MMAL_STATUS_T mmal_graph_add_port(MMAL_GRAPH_T *graph, MMAL_PORT_T *port);
  124. /** Add a connection to a graph.
  125. * Allows the client to add an internal connection to a graph.
  126. *
  127. * @param graph instance of the graph
  128. * @param connection connection to add to the graph
  129. * @return MMAL_SUCCESS on success
  130. */
  131. MMAL_STATUS_T mmal_graph_add_connection(MMAL_GRAPH_T *graph, MMAL_CONNECTION_T *connection);
  132. /** Create a new component and add it to a graph.
  133. * Allows the client to create and add a component to the graph.
  134. *
  135. * @param graph instance of the graph
  136. * @param name name of the component to create
  137. * @param component if not NULL, will contain a pointer to the created component
  138. * @return MMAL_SUCCESS on success
  139. */
  140. MMAL_STATUS_T mmal_graph_new_component(MMAL_GRAPH_T *graph, const char *name,
  141. MMAL_COMPONENT_T **component);
  142. /** Create and add a connection to a graph.
  143. * Allows the client to create and add an internal connection to a graph.
  144. *
  145. * @param graph instance of the graph
  146. * @param out the output port to use for the connection
  147. * @param in the input port to use for the connection
  148. * @param flags the flags specifying which type of connection should be created
  149. * @param connection if not NULL, will contain a pointer to the created connection
  150. * @return MMAL_SUCCESS on success
  151. */
  152. MMAL_STATUS_T mmal_graph_new_connection(MMAL_GRAPH_T *graph, MMAL_PORT_T *out, MMAL_PORT_T *in,
  153. uint32_t flags, MMAL_CONNECTION_T **connection);
  154. /** Definition of the callback used by a graph to send events to the client.
  155. *
  156. * @param graph the graph sending the event
  157. * @param port the port which generated the event
  158. * @param buffer the buffer header containing the event data
  159. * @param cb_data data passed back to the client when the callback is invoked
  160. */
  161. typedef void (*MMAL_GRAPH_EVENT_CB)(MMAL_GRAPH_T *graph, MMAL_PORT_T *port, MMAL_BUFFER_HEADER_T *buffer,
  162. void *cb_data);
  163. /** Enable the graph and start processing.
  164. *
  165. * @param graph the graph to enable
  166. * @param cb the callback to invoke when an event occurs on any of the internal control ports
  167. * @param cb_data data passed back to the client when the callback is invoked
  168. *
  169. * @return MMAL_SUCCESS on success
  170. */
  171. MMAL_STATUS_T mmal_graph_enable(MMAL_GRAPH_T *graph, MMAL_GRAPH_EVENT_CB cb, void *cb_data);
  172. MMAL_STATUS_T mmal_graph_disable(MMAL_GRAPH_T *graph);
  173. /** Find a port in the graph.
  174. *
  175. * @param graph graph instance
  176. * @param name name of the component of interest
  177. * @param type type of port (in/out)
  178. * @param index which port index within the component
  179. *
  180. * @return port, or NULL if not found
  181. */
  182. MMAL_PORT_T *mmal_graph_find_port(MMAL_GRAPH_T *graph,
  183. const char *name,
  184. MMAL_PORT_TYPE_T type,
  185. unsigned index);
  186. /** Create an instance of a component from a graph.
  187. * The newly created component will expose input and output ports to the client.
  188. * Not that all the exposed ports will be in a disabled state by default.
  189. *
  190. * @param graph graph to create the component from
  191. * @param name name of the component to create
  192. * @param component returned component
  193. * @return MMAL_SUCCESS on success
  194. */
  195. MMAL_STATUS_T mmal_graph_build(MMAL_GRAPH_T *ctx,
  196. const char *name, MMAL_COMPONENT_T **component);
  197. /** Component constructor for a graph.
  198. * FIXME: private function
  199. *
  200. * @param name name of the component to create
  201. * @param component component
  202. * @return MMAL_SUCCESS on success
  203. */
  204. MMAL_STATUS_T mmal_graph_component_constructor(const char *name, MMAL_COMPONENT_T *component);
  205. /** Destroy a previously created graph
  206. * @param graph graph to destroy
  207. * @return MMAL_SUCCESS on success
  208. */
  209. MMAL_STATUS_T mmal_graph_destroy(MMAL_GRAPH_T *ctx);
  210. #ifdef __cplusplus
  211. }
  212. #endif
  213. /** @} */
  214. #endif /* MMAL_GRAPH_H */