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_clock.h 7.3KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202
  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_CLOCK_H
  26. #define MMAL_CLOCK_H
  27. #include "vcos/vcos.h"
  28. #include "mmal_types.h"
  29. #include "mmal_common.h"
  30. #include <cassert>
  31. /** \defgroup MmalClock Clock Framework
  32. * The MMAL clock framework provides scheduling facilities to the rest of
  33. * MMAL.
  34. *
  35. * The framework consists mainly of clock ports and a clock module. Client
  36. * applications and components interact directly with clock ports, while
  37. * the clock module is only used internally by clock ports.
  38. *
  39. * Clock ports ensure that the local media-time for each component is
  40. * synchronised across all components. This is done by passing buffers between
  41. * clock ports which contain clock-specific data.
  42. *
  43. * One clock port will normally act as the reference clock for the rest of the
  44. * system. This is usually chosen to be the clock port of the audio render
  45. * component, but is configurable by the client and could potentially be any
  46. * other clock port (or even the client application itself).
  47. *
  48. * Components that are responsible for timed delivery of frames, do so by
  49. * registering callback requests for a particular time-stamp with the clock
  50. * port. These requests are scheduled using the clock module which maintains
  51. * an internal media-time.
  52. *
  53. * The clock framework also provides the ability to perform playback at different
  54. * speeds. This is achieved with a clock scale factor which determines the speed
  55. * at which the media-time advances relative to real-time, with:
  56. * scale = 1.0 -> normal playback speed
  57. * scale = 0 -> playback paused
  58. * scale > 1.0 -> fast-forward
  59. * scale < 1.0 -> slow motion
  60. */
  61. /** Clock event magic */
  62. #define MMAL_CLOCK_EVENT_MAGIC MMAL_FOURCC('C','K','L','M')
  63. /** Clock reference update */
  64. #define MMAL_CLOCK_EVENT_REFERENCE MMAL_FOURCC('C','R','E','F')
  65. /** Clock state update */
  66. #define MMAL_CLOCK_EVENT_ACTIVE MMAL_FOURCC('C','A','C','T')
  67. /** Clock scale update */
  68. #define MMAL_CLOCK_EVENT_SCALE MMAL_FOURCC('C','S','C','A')
  69. /** Clock media-time update */
  70. #define MMAL_CLOCK_EVENT_TIME MMAL_FOURCC('C','T','I','M')
  71. /** Clock update threshold */
  72. #define MMAL_CLOCK_EVENT_UPDATE_THRESHOLD MMAL_FOURCC('C','U','T','H')
  73. /** Clock discontinuity threshold */
  74. #define MMAL_CLOCK_EVENT_DISCONT_THRESHOLD MMAL_FOURCC('C','D','T','H')
  75. /** Clock request threshold */
  76. #define MMAL_CLOCK_EVENT_REQUEST_THRESHOLD MMAL_FOURCC('C','R','T','H')
  77. /** Buffer statistics */
  78. #define MMAL_CLOCK_EVENT_INPUT_BUFFER_INFO MMAL_FOURCC('C','I','B','I')
  79. #define MMAL_CLOCK_EVENT_OUTPUT_BUFFER_INFO MMAL_FOURCC('C','O','B','I')
  80. /** Clock latency setting */
  81. #define MMAL_CLOCK_EVENT_LATENCY MMAL_FOURCC('C','L','A','T')
  82. /** Clock event not valid */
  83. #define MMAL_CLOCK_EVENT_INVALID 0
  84. /** Thresholds used when updating a clock's media-time */
  85. typedef struct MMAL_CLOCK_UPDATE_THRESHOLD_T
  86. {
  87. /** Time differences below this threshold are ignored (microseconds) */
  88. int64_t threshold_lower;
  89. /** Time differences above this threshold reset media-time (microseconds) */
  90. int64_t threshold_upper;
  91. } MMAL_CLOCK_UPDATE_THRESHOLD_T;
  92. /** Threshold for detecting a discontinuity in media-time */
  93. typedef struct MMAL_CLOCK_DISCONT_THRESHOLD_T
  94. {
  95. /** Threshold after which backward jumps in media-time are treated as a
  96. * discontinuity (microseconds) */
  97. int64_t threshold;
  98. /** Duration in microseconds for which a discontinuity applies (wall-time) */
  99. int64_t duration;
  100. } MMAL_CLOCK_DISCONT_THRESHOLD_T;
  101. /** Threshold applied to client callback requests */
  102. typedef struct MMAL_CLOCK_REQUEST_THRESHOLD_T
  103. {
  104. /** Frames with a media-time difference (compared to current media-time)
  105. * above this threshold are dropped (microseconds) */
  106. int64_t threshold;
  107. /** Enable/disable the request threshold */
  108. MMAL_BOOL_T threshold_enable;
  109. } MMAL_CLOCK_REQUEST_THRESHOLD_T;
  110. /** Structure for passing buffer information to a clock port */
  111. typedef struct MMAL_CLOCK_BUFFER_INFO_T
  112. {
  113. int64_t time_stamp;
  114. uint32_t arrival_time;
  115. } MMAL_CLOCK_BUFFER_INFO_T;
  116. /** Clock latency settings used by the clock component */
  117. typedef struct MMAL_CLOCK_LATENCY_T
  118. {
  119. int64_t target; /**< target latency (microseconds) */
  120. int64_t attack_period; /**< duration of one attack period (microseconds) */
  121. int64_t attack_rate; /**< amount by which media-time will be adjusted
  122. every attack_period (microseconds) */
  123. } MMAL_CLOCK_LATENCY_T;
  124. /** Clock event used to pass data between clock ports and a client. */
  125. typedef struct MMAL_CLOCK_EVENT_T
  126. {
  127. /** 4cc event id */
  128. uint32_t id;
  129. /** 4cc event magic */
  130. uint32_t magic;
  131. /** buffer associated with this event (can be NULL) */
  132. struct MMAL_BUFFER_HEADER_T *buffer;
  133. /** pad to 64-bit boundary */
  134. uint32_t padding0;
  135. /** additional event data (type-specific) */
  136. union
  137. {
  138. /** used either for clock reference or clock state */
  139. MMAL_BOOL_T enable;
  140. /** new clock scale */
  141. MMAL_RATIONAL_T scale;
  142. /** new media-time */
  143. int64_t media_time;
  144. /** media-time update threshold */
  145. MMAL_CLOCK_UPDATE_THRESHOLD_T update_threshold;
  146. /** media-time discontinuity threshold */
  147. MMAL_CLOCK_DISCONT_THRESHOLD_T discont_threshold;
  148. /** client callback request threshold */
  149. MMAL_CLOCK_REQUEST_THRESHOLD_T request_threshold;
  150. /** input/output buffer information */
  151. MMAL_CLOCK_BUFFER_INFO_T buffer;
  152. /** clock latency setting */
  153. MMAL_CLOCK_LATENCY_T latency;
  154. } data;
  155. /** pad to 64-bit boundary */
  156. uint64_t padding1;
  157. } MMAL_CLOCK_EVENT_T;
  158. /* Make sure MMAL_CLOCK_EVENT_T will preserve 64-bit alignment */
  159. static_assert(!(sizeof(MMAL_CLOCK_EVENT_T) & 0x7),"mmal error");
  160. #define MMAL_CLOCK_EVENT_INIT(id) { id, MMAL_CLOCK_EVENT_MAGIC, NULL, 0, {0}, 0 }
  161. #endif /* MMAL_CLOCK_H */