1 | /* |
2 | Copyright (c) 2012, Broadcom Europe Ltd |
3 | All rights reserved. |
4 | |
5 | Redistribution and use in source and binary forms, with or without |
6 | modification, are permitted provided that the following conditions are met: |
7 | * Redistributions of source code must retain the above copyright |
8 | notice, this list of conditions and the following disclaimer. |
9 | * Redistributions in binary form must reproduce the above copyright |
10 | notice, this list of conditions and the following disclaimer in the |
11 | documentation and/or other materials provided with the distribution. |
12 | * Neither the name of the copyright holder nor the |
13 | names of its contributors may be used to endorse or promote products |
14 | derived from this software without specific prior written permission. |
15 | |
16 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND |
17 | ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED |
18 | WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE |
19 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY |
20 | DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES |
21 | (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; |
22 | LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND |
23 | ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
24 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS |
25 | SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
26 | */ |
27 | |
28 | #include "mmal.h" |
29 | #include "core/mmal_component_private.h" |
30 | #include "core/mmal_port_private.h" |
31 | #include "mmal_logging.h" |
32 | |
33 | #define NULLSINK_PORTS_NUM 1 |
34 | |
35 | /** Destroy a previously created component */ |
36 | static MMAL_STATUS_T null_sink_component_destroy(MMAL_COMPONENT_T *component) |
37 | { |
38 | if(component->input_num) |
39 | mmal_ports_free(component->input, component->input_num); |
40 | return MMAL_SUCCESS; |
41 | } |
42 | |
43 | /** Enable processing on a port */ |
44 | static MMAL_STATUS_T null_sink_port_enable(MMAL_PORT_T *port, MMAL_PORT_BH_CB_T cb) |
45 | { |
46 | MMAL_PARAM_UNUSED(port); |
47 | MMAL_PARAM_UNUSED(cb); |
48 | return MMAL_SUCCESS; |
49 | } |
50 | |
51 | /** Flush a port */ |
52 | static MMAL_STATUS_T null_sink_port_flush(MMAL_PORT_T *port) |
53 | { |
54 | MMAL_PARAM_UNUSED(port); |
55 | return MMAL_SUCCESS; |
56 | } |
57 | |
58 | /** Disable processing on a port */ |
59 | static MMAL_STATUS_T null_sink_port_disable(MMAL_PORT_T *port) |
60 | { |
61 | MMAL_PARAM_UNUSED(port); |
62 | return MMAL_SUCCESS; |
63 | } |
64 | |
65 | /** Send a buffer header to a port */ |
66 | static MMAL_STATUS_T null_sink_port_send(MMAL_PORT_T *port, MMAL_BUFFER_HEADER_T *buffer) |
67 | { |
68 | MMAL_BOOL_T eos = buffer->flags & MMAL_BUFFER_HEADER_FLAG_EOS; |
69 | |
70 | /* Send buffer back */ |
71 | buffer->length = 0; |
72 | mmal_port_buffer_header_callback(port, buffer); |
73 | |
74 | /* Generate EOS events */ |
75 | if(eos) |
76 | return mmal_event_eos_send(port); |
77 | |
78 | return MMAL_SUCCESS; |
79 | } |
80 | |
81 | /** Set format on a port */ |
82 | static MMAL_STATUS_T null_sink_port_format_commit(MMAL_PORT_T *port) |
83 | { |
84 | MMAL_PARAM_UNUSED(port); |
85 | return MMAL_SUCCESS; |
86 | } |
87 | |
88 | /** Create an instance of a component */ |
89 | static MMAL_STATUS_T mmal_component_create_null_sink(const char *name, MMAL_COMPONENT_T *component) |
90 | { |
91 | MMAL_STATUS_T status = MMAL_ENOMEM; |
92 | unsigned int i; |
93 | MMAL_PARAM_UNUSED(name); |
94 | |
95 | component->priv->pf_destroy = null_sink_component_destroy; |
96 | |
97 | /* Allocate all the ports for this component */ |
98 | component->input = mmal_ports_alloc(component, NULLSINK_PORTS_NUM, MMAL_PORT_TYPE_INPUT, 0); |
99 | if(!component->input) |
100 | goto error; |
101 | component->input_num = NULLSINK_PORTS_NUM; |
102 | |
103 | for(i = 0; i < component->input_num; i++) |
104 | { |
105 | component->input[i]->priv->pf_enable = null_sink_port_enable; |
106 | component->input[i]->priv->pf_disable = null_sink_port_disable; |
107 | component->input[i]->priv->pf_flush = null_sink_port_flush; |
108 | component->input[i]->priv->pf_send = null_sink_port_send; |
109 | component->input[i]->priv->pf_set_format = null_sink_port_format_commit; |
110 | component->input[i]->buffer_num_min = 1; |
111 | component->input[i]->buffer_num_recommended = 1; |
112 | } |
113 | |
114 | return MMAL_SUCCESS; |
115 | |
116 | error: |
117 | null_sink_component_destroy(component); |
118 | return status; |
119 | } |
120 | |
121 | MMAL_CONSTRUCTOR(mmal_register_component_null_sink); |
122 | void mmal_register_component_null_sink(void) |
123 | { |
124 | mmal_component_supplier_register("null_sink" , mmal_component_create_null_sink); |
125 | } |
126 | |