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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250
  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_BUFFER_H
  26. #define MMAL_BUFFER_H
  27. #ifdef __cplusplus
  28. extern "C" {
  29. #endif
  30. /** \defgroup MmalBufferHeader Buffer headers
  31. * Definition of a buffer header and its associated API.
  32. * Buffer headers are the basic element used to pass data and information between different
  33. * parts of the system. They are passed to components via ports and sent back to the client
  34. * using a callback mechanism.
  35. */
  36. /* @{ */
  37. /** Specific data associated with video frames */
  38. typedef struct {
  39. uint32_t planes; /**< Number of planes composing the video frame */
  40. uint32_t offset[4]; /**< Offsets to the different planes. These must point within the
  41. payload buffer */
  42. uint32_t pitch[4]; /**< Pitch (size in bytes of a line of a plane) of the different
  43. planes */
  44. uint32_t flags; /**< Flags describing video specific properties of a buffer header
  45. (see \ref videobufferheaderflags "Video buffer header flags") */
  46. /* TBD stereoscopic support */
  47. } MMAL_BUFFER_HEADER_VIDEO_SPECIFIC_T;
  48. /** Type specific data that's associated with a payload buffer */
  49. typedef union
  50. {
  51. /** Specific data associated with video frames */
  52. MMAL_BUFFER_HEADER_VIDEO_SPECIFIC_T video;
  53. } MMAL_BUFFER_HEADER_TYPE_SPECIFIC_T;
  54. /** Definition of the buffer header structure.
  55. * A buffer header does not directly carry the data to be passed to a component but instead
  56. * it references the actual data using a pointer (and an associated length).
  57. * It also contains an internal area which can be used to store command or metadata to be
  58. * associated with the external data.
  59. */
  60. typedef struct MMAL_BUFFER_HEADER_T
  61. {
  62. struct MMAL_BUFFER_HEADER_T *next; /**< Used to link several buffer headers together */
  63. struct MMAL_BUFFER_HEADER_PRIVATE_T *priv; /**< Data private to the framework */
  64. uint32_t cmd; /**< Defines what the buffer header contains. This is a FourCC
  65. with 0 as a special value meaning stream data */
  66. uint8_t *data; /**< Pointer to the start of the payload buffer (should not be
  67. changed by component) */
  68. uint32_t alloc_size; /**< Allocated size in bytes of payload buffer */
  69. uint32_t length; /**< Number of bytes currently used in the payload buffer (starting
  70. from offset) */
  71. uint32_t offset; /**< Offset in bytes to the start of valid data in the payload buffer */
  72. uint32_t flags; /**< Flags describing properties of a buffer header (see
  73. \ref bufferheaderflags "Buffer header flags") */
  74. int64_t pts; /**< Presentation timestamp in microseconds. \ref MMAL_TIME_UNKNOWN
  75. is used when the pts is unknown. */
  76. int64_t dts; /**< Decode timestamp in microseconds (dts = pts, except in the case
  77. of video streams with B frames). \ref MMAL_TIME_UNKNOWN
  78. is used when the dts is unknown. */
  79. /** Type specific data that's associated with a payload buffer */
  80. MMAL_BUFFER_HEADER_TYPE_SPECIFIC_T *type;
  81. void *user_data; /**< Field reserved for use by the client */
  82. } MMAL_BUFFER_HEADER_T;
  83. /** \name Buffer header flags
  84. * \anchor bufferheaderflags
  85. * The following flags describe properties of a buffer header */
  86. /* @{ */
  87. /** Signals that the current payload is the end of the stream of data */
  88. #define MMAL_BUFFER_HEADER_FLAG_EOS (1<<0)
  89. /** Signals that the start of the current payload starts a frame */
  90. #define MMAL_BUFFER_HEADER_FLAG_FRAME_START (1<<1)
  91. /** Signals that the end of the current payload ends a frame */
  92. #define MMAL_BUFFER_HEADER_FLAG_FRAME_END (1<<2)
  93. /** Signals that the current payload contains only complete frames (1 or more) */
  94. #define MMAL_BUFFER_HEADER_FLAG_FRAME (MMAL_BUFFER_HEADER_FLAG_FRAME_START|MMAL_BUFFER_HEADER_FLAG_FRAME_END)
  95. /** Signals that the current payload is a keyframe (i.e. self decodable) */
  96. #define MMAL_BUFFER_HEADER_FLAG_KEYFRAME (1<<3)
  97. /** Signals a discontinuity in the stream of data (e.g. after a seek).
  98. * Can be used for instance by a decoder to reset its state */
  99. #define MMAL_BUFFER_HEADER_FLAG_DISCONTINUITY (1<<4)
  100. /** Signals a buffer containing some kind of config data for the component
  101. * (e.g. codec config data) */
  102. #define MMAL_BUFFER_HEADER_FLAG_CONFIG (1<<5)
  103. /** Signals an encrypted payload */
  104. #define MMAL_BUFFER_HEADER_FLAG_ENCRYPTED (1<<6)
  105. /** Signals a buffer containing side information */
  106. #define MMAL_BUFFER_HEADER_FLAG_CODECSIDEINFO (1<<7)
  107. /** Signals a buffer which is the snapshot/postview image from a stills capture */
  108. #define MMAL_BUFFER_HEADER_FLAGS_SNAPSHOT (1<<8)
  109. /** Signals a buffer which contains data known to be corrupted */
  110. #define MMAL_BUFFER_HEADER_FLAG_CORRUPTED (1<<9)
  111. /** Signals that a buffer failed to be transmitted */
  112. #define MMAL_BUFFER_HEADER_FLAG_TRANSMISSION_FAILED (1<<10)
  113. /** Signals the output buffer won't be used, just update reference frames */
  114. #define MMAL_BUFFER_HEADER_FLAG_DECODEONLY (1<<11)
  115. /** User flags - can be passed in and will get returned */
  116. #define MMAL_BUFFER_HEADER_FLAG_USER0 (1<<28)
  117. #define MMAL_BUFFER_HEADER_FLAG_USER1 (1<<29)
  118. #define MMAL_BUFFER_HEADER_FLAG_USER2 (1<<30)
  119. #define MMAL_BUFFER_HEADER_FLAG_USER3 (1<<31)
  120. /* @} */
  121. /** \name Video buffer header flags
  122. * \anchor videobufferheaderflags
  123. * The following flags describe properties of a video buffer header */
  124. /* @{ */
  125. /** Signals an interlaced video frame */
  126. #define MMAL_BUFFER_HEADER_VIDEO_FLAG_INTERLACED (1<<0)
  127. /** Signals that the top field of the current interlaced frame should be displayed first */
  128. #define MMAL_BUFFER_HEADER_VIDEO_FLAG_TOP_FIELD_FIRST (1<<2)
  129. /** Signals that the buffer should be displayed on external display if attached. */
  130. #define MMAL_BUFFER_HEADER_VIDEO_FLAG_DISPLAY_EXTERNAL (1<<3)
  131. /** Signals that contents of the buffer requires copy protection. */
  132. #define MMAL_BUFFER_HEADER_VIDEO_FLAG_PROTECTED (1<<4)
  133. /* @} */
  134. /** Acquire a buffer header.
  135. * Acquiring a buffer header increases a reference counter on it and makes sure that the
  136. * buffer header won't be recycled until all the references to it are gone.
  137. * This is useful for instance if a component needs to return a buffer header but still needs
  138. * access to it for some internal processing (e.g. reference frames in video codecs).
  139. *
  140. * @param header buffer header to acquire
  141. */
  142. void mmal_buffer_header_acquire(MMAL_BUFFER_HEADER_T *header);
  143. /** Reset a buffer header.
  144. * Resets all header variables to default values.
  145. *
  146. * @param header buffer header to reset
  147. */
  148. void mmal_buffer_header_reset(MMAL_BUFFER_HEADER_T *header);
  149. /** Release a buffer header.
  150. * Releasing a buffer header will decrease its reference counter and when no more references
  151. * are left, the buffer header will be recycled by calling its 'release' callback function.
  152. *
  153. * If a pre-release callback is set (\ref MMAL_BH_PRE_RELEASE_CB_T), this will be invoked
  154. * before calling the buffer's release callback and potentially postpone buffer recycling.
  155. * Once pre-release is complete the buffer header is recycled with
  156. * \ref mmal_buffer_header_release_continue.
  157. *
  158. * @param header buffer header to release
  159. */
  160. void mmal_buffer_header_release(MMAL_BUFFER_HEADER_T *header);
  161. /** Continue the buffer header release process.
  162. * This should be called to complete buffer header recycling once all pre-release activity
  163. * has been completed.
  164. *
  165. * @param header buffer header to release
  166. */
  167. void mmal_buffer_header_release_continue(MMAL_BUFFER_HEADER_T *header);
  168. /** Buffer header pre-release callback.
  169. * The callback is invoked just before a buffer is released back into a
  170. * pool. This is used by clients who need to trigger additional actions
  171. * before the buffer can finally be released (e.g. wait for a bulk transfer
  172. * to complete).
  173. *
  174. * The callback should return TRUE if the buffer release need to be post-poned.
  175. *
  176. * @param header buffer header about to be released
  177. * @param userdata user-specific data
  178. *
  179. * @return TRUE if the buffer should not be released
  180. */
  181. typedef MMAL_BOOL_T (*MMAL_BH_PRE_RELEASE_CB_T)(MMAL_BUFFER_HEADER_T *header, void *userdata);
  182. /** Set a buffer header pre-release callback.
  183. * If the callback is NULL, the buffer will be released back into the pool
  184. * immediately as usual.
  185. *
  186. * @param header buffer header to associate callback with
  187. * @param cb pre-release callback to invoke
  188. * @param userdata user-specific data
  189. */
  190. void mmal_buffer_header_pre_release_cb_set(MMAL_BUFFER_HEADER_T *header, MMAL_BH_PRE_RELEASE_CB_T cb, void *userdata);
  191. /** Replicate a buffer header into another one.
  192. * Replicating a buffer header will not only do an exact copy of all the public fields of the
  193. * buffer header (including data and alloc_size), but it will also acquire a reference to the
  194. * source buffer header which will only be released once the replicate has been released.
  195. *
  196. * @param dest buffer header into which to replicate
  197. * @param src buffer header to use as the source for the replication
  198. * @return MMAL_SUCCESS on success
  199. */
  200. MMAL_STATUS_T mmal_buffer_header_replicate(MMAL_BUFFER_HEADER_T *dest, MMAL_BUFFER_HEADER_T *src);
  201. /** Lock the data buffer contained in the buffer header in memory.
  202. * This call does nothing on all platforms except VideoCore where it is needed to pin a
  203. * buffer in memory before any access to it.
  204. *
  205. * @param header buffer header to lock
  206. */
  207. MMAL_STATUS_T mmal_buffer_header_mem_lock(MMAL_BUFFER_HEADER_T *header);
  208. /** Unlock the data buffer contained in the buffer header.
  209. * This call does nothing on all platforms except VideoCore where it is needed to un-pin a
  210. * buffer in memory after any access to it.
  211. *
  212. * @param header buffer header to unlock
  213. */
  214. void mmal_buffer_header_mem_unlock(MMAL_BUFFER_HEADER_T *header);
  215. /* @} */
  216. #ifdef __cplusplus
  217. }
  218. #endif
  219. #endif /* MMAL_BUFFER_H */