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 "interface/vmcs_host/khronos/IL/OMX_Broadcom.h" |
29 | #include "mmalomx.h" |
30 | #include "mmalomx_util_params.h" |
31 | #include "mmalomx_util_params_common.h" |
32 | |
33 | static const MMALOMX_PARAM_TRANSLATION_T *mmalomx_param_list[] = { |
34 | mmalomx_param_xlator_audio, mmalomx_param_xlator_video, |
35 | mmalomx_param_xlator_camera, mmalomx_param_xlator_misc}; |
36 | |
37 | const MMALOMX_PARAM_TRANSLATION_T *mmalomx_find_parameter_enum(unsigned int index) |
38 | { |
39 | unsigned int i, j; |
40 | |
41 | for (i = 0; i < MMAL_COUNTOF(mmalomx_param_list); i++) |
42 | { |
43 | for (j = 0; mmalomx_param_list[i][j].mmal_id != MMAL_PARAMETER_UNUSED; j++) |
44 | { |
45 | if (!index--) |
46 | break; |
47 | } |
48 | if (mmalomx_param_list[i][j].mmal_id != MMAL_PARAMETER_UNUSED) |
49 | break; |
50 | } |
51 | |
52 | return i < MMAL_COUNTOF(mmalomx_param_list) ? &mmalomx_param_list[i][j] : NULL; |
53 | } |
54 | |
55 | const MMALOMX_PARAM_TRANSLATION_T *mmalomx_find_parameter_from_omx_id(uint32_t id) |
56 | { |
57 | unsigned int i, j; |
58 | |
59 | for (i = 0; i < MMAL_COUNTOF(mmalomx_param_list); i++) |
60 | { |
61 | for (j = 0; mmalomx_param_list[i][j].mmal_id != MMAL_PARAMETER_UNUSED; j++) |
62 | { |
63 | if (mmalomx_param_list[i][j].omx_id == id) |
64 | break; |
65 | } |
66 | if (mmalomx_param_list[i][j].mmal_id != MMAL_PARAMETER_UNUSED) |
67 | break; |
68 | } |
69 | |
70 | return i < MMAL_COUNTOF(mmalomx_param_list) ? &mmalomx_param_list[i][j] : NULL; |
71 | } |
72 | |
73 | const MMALOMX_PARAM_TRANSLATION_T *mmalomx_find_parameter_from_mmal_id(uint32_t id) |
74 | { |
75 | unsigned int i, j; |
76 | |
77 | for (i = 0; i < MMAL_COUNTOF(mmalomx_param_list); i++) |
78 | { |
79 | for (j = 0; mmalomx_param_list[i][j].mmal_id != MMAL_PARAMETER_UNUSED; j++) |
80 | { |
81 | if (mmalomx_param_list[i][j].mmal_id == id) |
82 | break; |
83 | } |
84 | if (mmalomx_param_list[i][j].mmal_id != MMAL_PARAMETER_UNUSED) |
85 | break; |
86 | } |
87 | |
88 | return i < MMAL_COUNTOF(mmalomx_param_list) ? &mmalomx_param_list[i][j] : NULL; |
89 | } |
90 | |
91 | const char *mmalomx_parameter_name_omx(uint32_t id) |
92 | { |
93 | const MMALOMX_PARAM_TRANSLATION_T *xlat = mmalomx_find_parameter_from_omx_id(id); |
94 | return xlat ? xlat->omx_name : 0; |
95 | } |
96 | |
97 | const char *mmalomx_parameter_name_mmal(uint32_t id) |
98 | { |
99 | const MMALOMX_PARAM_TRANSLATION_T *xlat = mmalomx_find_parameter_from_mmal_id(id); |
100 | return xlat ? xlat->mmal_name : 0; |
101 | } |
102 | |
103 | MMAL_STATUS_T mmalomx_param_mapping_generic(MMALOMX_PARAM_MAPPING_DIRECTION dir, |
104 | const MMALOMX_PARAM_TRANSLATION_T *xlat, |
105 | MMAL_PARAMETER_HEADER_T *mmal_param, OMX_PTR omx_param, MMAL_PORT_T *mmal_port) |
106 | { |
107 | MMALOMX_PARAM_OMX_HEADER_T * = (MMALOMX_PARAM_OMX_HEADER_T *)omx_param; |
108 | uint8_t *mmal_data = ((uint8_t *)mmal_param) + sizeof(MMAL_PARAMETER_HEADER_T); |
109 | uint8_t *omx_data = ((uint8_t *)omx_param) + sizeof(MMALOMX_PARAM_OMX_HEADER_T); |
110 | unsigned int size = mmal_param->size - sizeof(MMAL_PARAMETER_HEADER_T); |
111 | MMAL_PARAM_UNUSED(mmal_port); |
112 | |
113 | if (xlat->portless) |
114 | omx_data -= sizeof(OMX_U32); |
115 | |
116 | if (((uint8_t *)omx_param) + omx_header->nSize != |
117 | omx_data + size) |
118 | { |
119 | VCOS_ALERT("mmalomx_param_mapping_generic: mismatch between mmal and omx parameters for (%u)" , |
120 | (unsigned int)mmal_param->id); |
121 | return MMAL_EINVAL; |
122 | } |
123 | |
124 | if (dir == MMALOMX_PARAM_MAPPING_TO_MMAL) |
125 | memcpy(mmal_data, omx_data, size); |
126 | else |
127 | memcpy(omx_data, mmal_data, size); |
128 | |
129 | return MMAL_SUCCESS; |
130 | } |
131 | |
132 | MMAL_STATUS_T mmalomx_param_enum_generic(MMALOMX_PARAM_MAPPING_DIRECTION dir, |
133 | const MMALOMX_PARAM_TRANSLATION_T *xlat, |
134 | MMAL_PARAMETER_HEADER_T *mmal_param, OMX_PTR omx_param, MMAL_PORT_T *mmal_port) |
135 | { |
136 | uint32_t *mmal = (uint32_t *)(((uint8_t *)mmal_param) + sizeof(MMAL_PARAMETER_HEADER_T)); |
137 | uint32_t *omx = (uint32_t *)(((uint8_t *)omx_param) + sizeof(MMALOMX_PARAM_OMX_HEADER_T)); |
138 | unsigned int i = 0; |
139 | MMAL_PARAM_UNUSED(mmal_port); |
140 | |
141 | if (xlat->portless) |
142 | omx -= 1; |
143 | |
144 | /* Find translation entry in lookup table */ |
145 | if (dir == MMALOMX_PARAM_MAPPING_TO_MMAL) |
146 | for (i = 0; i < xlat->xlat_enum_num && xlat->xlat_enum->omx != *omx; i++); |
147 | else |
148 | for (i = 0; i < xlat->xlat_enum_num && xlat->xlat_enum->mmal != *mmal; i++); |
149 | |
150 | if (i == xlat->xlat_enum_num) |
151 | { |
152 | if (dir == MMALOMX_PARAM_MAPPING_TO_MMAL) |
153 | VCOS_ALERT("mmalomx_param_enum_generic: omx enum value %u not supported" , (unsigned int)*omx); |
154 | else |
155 | VCOS_ALERT("mmalomx_param_enum_generic: mmal enum value %u not supported" , (unsigned int)*mmal); |
156 | return MMAL_EINVAL; |
157 | } |
158 | |
159 | if (dir == MMALOMX_PARAM_MAPPING_TO_MMAL) |
160 | *mmal = xlat->xlat_enum[i].mmal; |
161 | else |
162 | *omx = xlat->xlat_enum[i].omx; |
163 | |
164 | return MMAL_SUCCESS; |
165 | } |
166 | |
167 | MMAL_STATUS_T mmalomx_param_rational_generic(MMALOMX_PARAM_MAPPING_DIRECTION dir, |
168 | const MMALOMX_PARAM_TRANSLATION_T *xlat, |
169 | MMAL_PARAMETER_HEADER_T *mmal_param, OMX_PTR omx_param, MMAL_PORT_T *mmal_port) |
170 | { |
171 | MMAL_RATIONAL_T *mmal = (MMAL_RATIONAL_T *)(((uint8_t *)mmal_param) + sizeof(MMAL_PARAMETER_HEADER_T)); |
172 | int32_t *omx = (int32_t *)(((uint8_t *)omx_param) + sizeof(MMALOMX_PARAM_OMX_HEADER_T)); |
173 | MMAL_PARAM_UNUSED(mmal_port); |
174 | |
175 | if (xlat->portless) |
176 | omx -= 1; |
177 | |
178 | if (dir == MMALOMX_PARAM_MAPPING_TO_MMAL) |
179 | { |
180 | mmal->num = *omx; |
181 | mmal->den = xlat->xlat_enum_num; |
182 | mmal_rational_simplify(mmal); |
183 | } |
184 | else |
185 | { |
186 | mmal_rational_simplify(mmal); |
187 | *omx = 0; |
188 | if (mmal->den) |
189 | *omx = mmal->num * xlat->xlat_enum_num / mmal->den; |
190 | } |
191 | |
192 | return MMAL_SUCCESS; |
193 | } |
194 | |