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.

null_sink.c 4.2KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125
  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. #include "mmal.h"
  26. #include "core/mmal_component_private.h"
  27. #include "core/mmal_port_private.h"
  28. #include "mmal_logging.h"
  29. #define NULLSINK_PORTS_NUM 1
  30. /** Destroy a previously created component */
  31. static MMAL_STATUS_T null_sink_component_destroy(MMAL_COMPONENT_T *component)
  32. {
  33. if(component->input_num)
  34. mmal_ports_free(component->input, component->input_num);
  35. return MMAL_SUCCESS;
  36. }
  37. /** Enable processing on a port */
  38. static MMAL_STATUS_T null_sink_port_enable(MMAL_PORT_T *port, MMAL_PORT_BH_CB_T cb)
  39. {
  40. MMAL_PARAM_UNUSED(port);
  41. MMAL_PARAM_UNUSED(cb);
  42. return MMAL_SUCCESS;
  43. }
  44. /** Flush a port */
  45. static MMAL_STATUS_T null_sink_port_flush(MMAL_PORT_T *port)
  46. {
  47. MMAL_PARAM_UNUSED(port);
  48. return MMAL_SUCCESS;
  49. }
  50. /** Disable processing on a port */
  51. static MMAL_STATUS_T null_sink_port_disable(MMAL_PORT_T *port)
  52. {
  53. MMAL_PARAM_UNUSED(port);
  54. return MMAL_SUCCESS;
  55. }
  56. /** Send a buffer header to a port */
  57. static MMAL_STATUS_T null_sink_port_send(MMAL_PORT_T *port, MMAL_BUFFER_HEADER_T *buffer)
  58. {
  59. MMAL_BOOL_T eos = buffer->flags & MMAL_BUFFER_HEADER_FLAG_EOS;
  60. /* Send buffer back */
  61. buffer->length = 0;
  62. mmal_port_buffer_header_callback(port, buffer);
  63. /* Generate EOS events */
  64. if(eos)
  65. return mmal_event_eos_send(port);
  66. return MMAL_SUCCESS;
  67. }
  68. /** Set format on a port */
  69. static MMAL_STATUS_T null_sink_port_format_commit(MMAL_PORT_T *port)
  70. {
  71. MMAL_PARAM_UNUSED(port);
  72. return MMAL_SUCCESS;
  73. }
  74. /** Create an instance of a component */
  75. static MMAL_STATUS_T mmal_component_create_null_sink(const char *name, MMAL_COMPONENT_T *component)
  76. {
  77. MMAL_STATUS_T status = MMAL_ENOMEM;
  78. unsigned int i;
  79. MMAL_PARAM_UNUSED(name);
  80. component->priv->pf_destroy = null_sink_component_destroy;
  81. /* Allocate all the ports for this component */
  82. component->input = mmal_ports_alloc(component, NULLSINK_PORTS_NUM, MMAL_PORT_TYPE_INPUT, 0);
  83. if(!component->input)
  84. goto error;
  85. component->input_num = NULLSINK_PORTS_NUM;
  86. for(i = 0; i < component->input_num; i++)
  87. {
  88. component->input[i]->priv->pf_enable = null_sink_port_enable;
  89. component->input[i]->priv->pf_disable = null_sink_port_disable;
  90. component->input[i]->priv->pf_flush = null_sink_port_flush;
  91. component->input[i]->priv->pf_send = null_sink_port_send;
  92. component->input[i]->priv->pf_set_format = null_sink_port_format_commit;
  93. component->input[i]->buffer_num_min = 1;
  94. component->input[i]->buffer_num_recommended = 1;
  95. }
  96. return MMAL_SUCCESS;
  97. error:
  98. null_sink_component_destroy(component);
  99. return status;
  100. }
  101. MMAL_CONSTRUCTOR(mmal_register_component_null_sink);
  102. void mmal_register_component_null_sink(void)
  103. {
  104. mmal_component_supplier_register("null_sink", mmal_component_create_null_sink);
  105. }