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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230
  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_CONNECTION_H
  26. #define MMAL_CONNECTION_H
  27. /** \defgroup MmalConnectionUtility Port connection utility
  28. * \ingroup MmalUtilities
  29. * The port connection utility functions can be used in place of common sequences
  30. * of calls to the MMAL API in order to process buffers being passed between two
  31. * ports.
  32. *
  33. * \section ProcessingConnectionBufferHeaders Processing connection buffer headers
  34. * Either in response to the client callback function being called, or simply on a
  35. * timer, the client will need to process the buffer headers of the connection
  36. * (unless tunneling is used).
  37. *
  38. * Buffer headers that are in the pool queue will need to be sent to the output port,
  39. * while buffer headers in the connection queue are sent to the input port. The
  40. * buffer headers in the connection queue may contain pixel data (the cmd field is
  41. * zero) or an event (the cmd field is non-zero). In general, pixel data buffer
  42. * headers need to be passed on, while event buffer headers are released. In the
  43. * case of the format changed event, mmal_connection_event_format_changed() can be
  44. * called before the event is released.
  45. *
  46. * Other, specialized use cases may also be implemented, such as getting and
  47. * immediately releasing buffer headers from the connection queue in order to
  48. * prevent their propagation. This could be used to drop out video, for example.
  49. *
  50. * \section TunnellingConnections Tunnelling connections
  51. * If the \ref MMAL_CONNECTION_FLAG_TUNNELLING flag is set when the connection is
  52. * created, MMAL tunneling will be used. This automates the passing of the buffer
  53. * headers between the output port and input port, and back again. It will also do
  54. * this as efficiently as possible, avoiding trips between the ARM and the VideoCore
  55. * if both components are implemented on the VideoCore. The consequence of this is
  56. * that there is no client callback made as buffer headers get transferred.
  57. *
  58. * The client can still monitor the control port of a component (usually a sink
  59. * component, such as video_render) for the end of stream, in order to know when to
  60. * dismantle the connection.
  61. *
  62. * \section ConnectionClientCallback Client callback
  63. * When not using tunnelling, the client callback function is called each time a
  64. * buffer arrives from a port (either input or output).
  65. *
  66. * \note The callback is made on a different thread from the one used by the
  67. * client to set up the connection, so care must be taken with thread safety.
  68. * One option is to raise a signal to the main client thread that queue processing
  69. * needs to be done, another is for the callback to perform the queue processing
  70. * itself.
  71. *
  72. * The client can also store an opaque pointer in the connection object, which is
  73. * never used by the MMAL code and is only meaningful to the client.
  74. *
  75. * @{
  76. */
  77. #ifdef __cplusplus
  78. extern "C" {
  79. #endif
  80. /** \name Connection flags
  81. * \anchor connectionflags
  82. * The following flags describe the properties of the connection. */
  83. /* @{ */
  84. /** The connection is tunnelled. Buffer headers do not transit via the client but
  85. * directly from the output port to the input port. */
  86. #define MMAL_CONNECTION_FLAG_TUNNELLING 0x1
  87. /** Force the pool of buffer headers used by the connection to be allocated on the input port. */
  88. #define MMAL_CONNECTION_FLAG_ALLOCATION_ON_INPUT 0x2
  89. /** Force the pool of buffer headers used by the connection to be allocated on the output port. */
  90. #define MMAL_CONNECTION_FLAG_ALLOCATION_ON_OUTPUT 0x4
  91. /** Specify that the connection should not modify the buffer requirements. */
  92. #define MMAL_CONNECTION_FLAG_KEEP_BUFFER_REQUIREMENTS 0x8
  93. /** The connection is flagged as direct. This doesn't change the behaviour of
  94. * the connection itself but is used by the the graph utility to specify that
  95. * the buffer should be sent to the input port from with the port callback. */
  96. #define MMAL_CONNECTION_FLAG_DIRECT 0x10
  97. /* @} */
  98. /** Forward type definition for a connection */
  99. typedef struct MMAL_CONNECTION_T MMAL_CONNECTION_T;
  100. /** Definition of the callback used by a connection to signal back to the client
  101. * that a buffer header is available either in the pool or in the output queue.
  102. *
  103. * @param connection Pointer to the connection
  104. */
  105. typedef void (*MMAL_CONNECTION_CALLBACK_T)(MMAL_CONNECTION_T *connection);
  106. /** Structure describing a connection between 2 ports (1 output and 1 input port) */
  107. struct MMAL_CONNECTION_T {
  108. void *user_data; /**< Field reserved for use by the client. */
  109. MMAL_CONNECTION_CALLBACK_T callback; /**< Callback set by the client. */
  110. uint32_t is_enabled; /**< Specifies whether the connection is enabled or not (Read Only). */
  111. uint32_t flags; /**< Flags passed during the create call (Read Only). A bitwise
  112. * combination of \ref connectionflags "Connection flags" values.
  113. */
  114. MMAL_PORT_T *in; /**< Input port used for the connection (Read Only). */
  115. MMAL_PORT_T *out; /**< Output port used for the connection (Read Only). */
  116. MMAL_POOL_T *pool; /**< Pool of buffer headers used by the output port (Read Only). */
  117. MMAL_QUEUE_T *queue; /**< Queue for the buffer headers produced by the output port (Read Only). */
  118. const char *name; /**< Connection name (Read Only). Used for debugging purposes. */
  119. /* Used for debug / statistics */
  120. int64_t time_setup; /**< Time in microseconds taken to setup the connection. */
  121. int64_t time_enable; /**< Time in microseconds taken to enable the connection. */
  122. int64_t time_disable; /**< Time in microseconds taken to disable the connection. */
  123. };
  124. /** Create a connection between two ports.
  125. * The connection shall include a pool of buffer headers suitable for the current format of
  126. * the output port. The format of the input port shall have been set to the same as that of
  127. * the input port.
  128. * Note that connections are reference counted and creating a connection automatically
  129. * acquires a reference to it (released when \ref mmal_connection_destroy is called).
  130. *
  131. * @param connection The address of a connection pointer that will be set to point to the created
  132. * connection.
  133. * @param out The output port to use for the connection.
  134. * @param in The input port to use for the connection.
  135. * @param flags The flags specifying which type of connection should be created.
  136. * A bitwise combination of \ref connectionflags "Connection flags" values.
  137. * @return MMAL_SUCCESS on success.
  138. */
  139. MMAL_STATUS_T mmal_connection_create(MMAL_CONNECTION_T **connection,
  140. MMAL_PORT_T *out, MMAL_PORT_T *in, uint32_t flags);
  141. /** Acquire a reference on a connection.
  142. * Acquiring a reference on a connection will prevent a connection from being destroyed until
  143. * the acquired reference is released (by a call to \ref mmal_connection_destroy).
  144. * References are internally counted so all acquired references need a matching call to
  145. * release them.
  146. *
  147. * @param connection connection to acquire
  148. */
  149. void mmal_connection_acquire(MMAL_CONNECTION_T *connection);
  150. /** Release a reference on a connection
  151. * Release an acquired reference on a connection. Triggers the destruction of the connection when
  152. * the last reference is being released.
  153. * \note This is in fact an alias of \ref mmal_connection_destroy which is added to make client
  154. * code clearer.
  155. *
  156. * @param connection connection to release
  157. * @return MMAL_SUCCESS on success
  158. */
  159. MMAL_STATUS_T mmal_connection_release(MMAL_CONNECTION_T *connection);
  160. /** Destroy a connection.
  161. * Release an acquired reference on a connection. Only actually destroys the connection when
  162. * the last reference is being released.
  163. * The actual destruction of the connection will start by disabling it, if necessary.
  164. * Any pool, queue, and so on owned by the connection shall then be destroyed.
  165. *
  166. * @param connection The connection to be destroyed.
  167. * @return MMAL_SUCCESS on success.
  168. */
  169. MMAL_STATUS_T mmal_connection_destroy(MMAL_CONNECTION_T *connection);
  170. /** Enable a connection.
  171. * The format of the two ports must have been committed before calling this function,
  172. * although note that on creation, the connection automatically copies and commits the
  173. * output port's format to the input port.
  174. *
  175. * The MMAL_CONNECTION_T::callback field must have been set if the \ref MMAL_CONNECTION_FLAG_TUNNELLING
  176. * flag was not specified on creation. The client may also set the MMAL_CONNECTION_T::user_data
  177. * in order to get a pointer passed, via the connection, to the callback.
  178. *
  179. * @param connection The connection to be enabled.
  180. * @return MMAL_SUCCESS on success.
  181. */
  182. MMAL_STATUS_T mmal_connection_enable(MMAL_CONNECTION_T *connection);
  183. /** Disable a connection.
  184. *
  185. * @param connection The connection to be disabled.
  186. * @return MMAL_SUCCESS on success.
  187. */
  188. MMAL_STATUS_T mmal_connection_disable(MMAL_CONNECTION_T *connection);
  189. /** Apply a format changed event to the connection.
  190. * This function can be used when the client is processing buffer headers and receives
  191. * a format changed event (\ref MMAL_EVENT_FORMAT_CHANGED). The connection is
  192. * reconfigured, changing the format of the ports, the number of buffer headers and
  193. * the size of the payload buffers as necessary.
  194. *
  195. * @param connection The connection to which the event shall be applied.
  196. * @param buffer The buffer containing a format changed event.
  197. * @return MMAL_SUCCESS on success.
  198. */
  199. MMAL_STATUS_T mmal_connection_event_format_changed(MMAL_CONNECTION_T *connection,
  200. MMAL_BUFFER_HEADER_T *buffer);
  201. #ifdef __cplusplus
  202. }
  203. #endif
  204. /** @} */
  205. #endif /* MMAL_CONNECTION_H */