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 | /** \file |
29 | * OpenMAX IL adaptation layer for MMAL - Marking related functions |
30 | * |
31 | * Note that we do not support buffer marks properly other than for conformance |
32 | * testing. For input ports, we just move the mark over to the output port. |
33 | */ |
34 | |
35 | #include "mmalomx.h" |
36 | #include "mmalomx_buffer.h" |
37 | #include "mmalomx_marks.h" |
38 | #include "mmalomx_commands.h" |
39 | #include "mmalomx_logging.h" |
40 | |
41 | #define MMALOMX_GET_MARK(port, mark) \ |
42 | mark = &port->marks[port->marks_first]; \ |
43 | port->marks_num--; \ |
44 | port->marks_first = ++port->marks_first == MAX_MARKS_NUM ? 0 : port->marks_first |
45 | #define MMALOMX_PUT_MARK(port, mark) \ |
46 | port->marks[(port->marks_first + port->marks_num) % MAX_MARKS_NUM] = *mark; \ |
47 | port->marks_num++; |
48 | |
49 | void mmalomx_mark_process_incoming(MMALOMX_COMPONENT_T *component, |
50 | MMALOMX_PORT_T *port, OMX_BUFFERHEADERTYPE *omx_buffer) |
51 | { |
52 | /* Tag buffers with OMX marks */ |
53 | if (!omx_buffer->hMarkTargetComponent && port->marks_num > 0 && |
54 | port->direction == OMX_DirInput) |
55 | { |
56 | OMX_MARKTYPE *mark; |
57 | MMALOMX_GET_MARK(port, mark); |
58 | omx_buffer->hMarkTargetComponent = mark->hMarkTargetComponent; |
59 | omx_buffer->pMarkData = mark->pMarkData; |
60 | |
61 | mmalomx_callback_event_handler(component, OMX_EventCmdComplete, |
62 | OMX_CommandMarkBuffer, port->index, NULL); |
63 | } |
64 | /* We do not support buffer marks properly other than for conformance testing. |
65 | * For input ports, we just move the mark over to the output port. */ |
66 | if (port->direction == OMX_DirInput && omx_buffer->hMarkTargetComponent) |
67 | { |
68 | OMX_MARKTYPE mark = {omx_buffer->hMarkTargetComponent, omx_buffer->pMarkData}; |
69 | unsigned int i; |
70 | for (i = 0; i < component->ports_num; i++) |
71 | { |
72 | if (component->ports[i].direction != OMX_DirOutput || |
73 | component->ports[i].marks_num >= MAX_MARKS_NUM) |
74 | continue; |
75 | |
76 | MMALOMX_PUT_MARK((&component->ports[i]), (&mark)); |
77 | } |
78 | } |
79 | } |
80 | |
81 | void mmalomx_mark_process_outgoing(MMALOMX_COMPONENT_T *component, |
82 | MMALOMX_PORT_T *port, OMX_BUFFERHEADERTYPE *omx_buffer) |
83 | { |
84 | /* Tag buffers with OMX marks */ |
85 | if (port->direction == OMX_DirOutput && |
86 | !omx_buffer->hMarkTargetComponent && port->marks_num) |
87 | { |
88 | OMX_MARKTYPE *mark; |
89 | MMALOMX_GET_MARK(port, mark); |
90 | omx_buffer->hMarkTargetComponent = mark->hMarkTargetComponent; |
91 | omx_buffer->pMarkData = mark->pMarkData; |
92 | } |
93 | /* Check if we need to trigger a Mark event */ |
94 | if (omx_buffer->hMarkTargetComponent && |
95 | omx_buffer->hMarkTargetComponent == (OMX_HANDLETYPE)&component->omx) |
96 | { |
97 | mmalomx_callback_event_handler(component, OMX_EventMark, 0, 0, omx_buffer->pMarkData); |
98 | omx_buffer->hMarkTargetComponent = NULL; |
99 | omx_buffer->pMarkData = NULL; |
100 | } |
101 | } |
102 | |