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 10KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224
  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. /* @} */
  92. /** Forward type definition for a connection */
  93. typedef struct MMAL_CONNECTION_T MMAL_CONNECTION_T;
  94. /** Definition of the callback used by a connection to signal back to the client
  95. * that a buffer header is available either in the pool or in the output queue.
  96. *
  97. * @param connection Pointer to the connection
  98. */
  99. typedef void (*MMAL_CONNECTION_CALLBACK_T)(MMAL_CONNECTION_T *connection);
  100. /** Structure describing a connection between 2 ports (1 output and 1 input port) */
  101. struct MMAL_CONNECTION_T {
  102. void *user_data; /**< Field reserved for use by the client. */
  103. MMAL_CONNECTION_CALLBACK_T callback; /**< Callback set by the client. */
  104. uint32_t is_enabled; /**< Specifies whether the connection is enabled or not (Read Only). */
  105. uint32_t flags; /**< Flags passed during the create call (Read Only). A bitwise
  106. * combination of \ref connectionflags "Connection flags" values.
  107. */
  108. MMAL_PORT_T *in; /**< Input port used for the connection (Read Only). */
  109. MMAL_PORT_T *out; /**< Output port used for the connection (Read Only). */
  110. MMAL_POOL_T *pool; /**< Pool of buffer headers used by the output port (Read Only). */
  111. MMAL_QUEUE_T *queue; /**< Queue for the buffer headers produced by the output port (Read Only). */
  112. const char *name; /**< Connection name (Read Only). Used for debugging purposes. */
  113. /* Used for debug / statistics */
  114. int64_t time_setup; /**< Time in microseconds taken to setup the connection. */
  115. int64_t time_enable; /**< Time in microseconds taken to enable the connection. */
  116. int64_t time_disable; /**< Time in microseconds taken to disable the connection. */
  117. };
  118. /** Create a connection between two ports.
  119. * The connection shall include a pool of buffer headers suitable for the current format of
  120. * the output port. The format of the input port shall have been set to the same as that of
  121. * the input port.
  122. * Note that connections are reference counted and creating a connection automatically
  123. * acquires a reference to it (released when \ref mmal_connection_destroy is called).
  124. *
  125. * @param connection The address of a connection pointer that will be set to point to the created
  126. * connection.
  127. * @param out The output port to use for the connection.
  128. * @param in The input port to use for the connection.
  129. * @param flags The flags specifying which type of connection should be created.
  130. * A bitwise combination of \ref connectionflags "Connection flags" values.
  131. * @return MMAL_SUCCESS on success.
  132. */
  133. MMAL_STATUS_T mmal_connection_create(MMAL_CONNECTION_T **connection,
  134. MMAL_PORT_T *out, MMAL_PORT_T *in, uint32_t flags);
  135. /** Acquire a reference on a connection.
  136. * Acquiring a reference on a connection will prevent a connection from being destroyed until
  137. * the acquired reference is released (by a call to \ref mmal_connection_destroy).
  138. * References are internally counted so all acquired references need a matching call to
  139. * release them.
  140. *
  141. * @param connection connection to acquire
  142. */
  143. void mmal_connection_acquire(MMAL_CONNECTION_T *connection);
  144. /** Release a reference on a connection
  145. * Release an acquired reference on a connection. Triggers the destruction of the connection when
  146. * the last reference is being released.
  147. * \note This is in fact an alias of \ref mmal_connection_destroy which is added to make client
  148. * code clearer.
  149. *
  150. * @param connection connection to release
  151. * @return MMAL_SUCCESS on success
  152. */
  153. MMAL_STATUS_T mmal_connection_release(MMAL_CONNECTION_T *connection);
  154. /** Destroy a connection.
  155. * Release an acquired reference on a connection. Only actually destroys the connection when
  156. * the last reference is being released.
  157. * The actual destruction of the connection will start by disabling it, if necessary.
  158. * Any pool, queue, and so on owned by the connection shall then be destroyed.
  159. *
  160. * @param connection The connection to be destroyed.
  161. * @return MMAL_SUCCESS on success.
  162. */
  163. MMAL_STATUS_T mmal_connection_destroy(MMAL_CONNECTION_T *connection);
  164. /** Enable a connection.
  165. * The format of the two ports must have been committed before calling this function,
  166. * although note that on creation, the connection automatically copies and commits the
  167. * output port's format to the input port.
  168. *
  169. * The MMAL_CONNECTION_T::callback field must have been set if the \ref MMAL_CONNECTION_FLAG_TUNNELLING
  170. * flag was not specified on creation. The client may also set the MMAL_CONNECTION_T::user_data
  171. * in order to get a pointer passed, via the connection, to the callback.
  172. *
  173. * @param connection The connection to be enabled.
  174. * @return MMAL_SUCCESS on success.
  175. */
  176. MMAL_STATUS_T mmal_connection_enable(MMAL_CONNECTION_T *connection);
  177. /** Disable a connection.
  178. *
  179. * @param connection The connection to be disabled.
  180. * @return MMAL_SUCCESS on success.
  181. */
  182. MMAL_STATUS_T mmal_connection_disable(MMAL_CONNECTION_T *connection);
  183. /** Apply a format changed event to the connection.
  184. * This function can be used when the client is processing buffer headers and receives
  185. * a format changed event (\ref MMAL_EVENT_FORMAT_CHANGED). The connection is
  186. * reconfigured, changing the format of the ports, the number of buffer headers and
  187. * the size of the payload buffers as necessary.
  188. *
  189. * @param connection The connection to which the event shall be applied.
  190. * @param buffer The buffer containing a format changed event.
  191. * @return MMAL_SUCCESS on success.
  192. */
  193. MMAL_STATUS_T mmal_connection_event_format_changed(MMAL_CONNECTION_T *connection,
  194. MMAL_BUFFER_HEADER_T *buffer);
  195. #ifdef __cplusplus
  196. }
  197. #endif
  198. /** @} */
  199. #endif /* MMAL_CONNECTION_H */