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 "mmalomx.h" |
29 | #include "mmalomx_util_params_common.h" |
30 | #include "mmalomx_logging.h" |
31 | |
32 | static void rect_to_omx(OMX_DISPLAYRECTTYPE *dst, const MMAL_RECT_T *src) |
33 | { |
34 | dst->x_offset = src->x; |
35 | dst->y_offset = src->y; |
36 | dst->width = src->width; |
37 | dst->height = src->height; |
38 | } |
39 | |
40 | static void rect_to_mmal(MMAL_RECT_T *dst, const OMX_DISPLAYRECTTYPE *src) |
41 | { |
42 | dst->x = src->x_offset; |
43 | dst->y = src->y_offset; |
44 | dst->width = src->width; |
45 | dst->height = src->height; |
46 | } |
47 | |
48 | static MMAL_STATUS_T mmalomx_param_mapping_displayregion(MMALOMX_PARAM_MAPPING_DIRECTION dir, |
49 | MMAL_PARAMETER_HEADER_T *mmal_param, OMX_PTR omx_param) |
50 | { |
51 | OMX_CONFIG_DISPLAYREGIONTYPE *omx = (OMX_CONFIG_DISPLAYREGIONTYPE *)omx_param; |
52 | MMAL_DISPLAYREGION_T *mmal = (MMAL_DISPLAYREGION_T *)mmal_param; |
53 | |
54 | if (dir == MMALOMX_PARAM_MAPPING_TO_MMAL) |
55 | { |
56 | mmal->set = omx->set; |
57 | mmal->display_num = omx->num; |
58 | mmal->fullscreen = omx->fullscreen; |
59 | mmal->transform = (MMAL_DISPLAYTRANSFORM_T)omx->transform; |
60 | rect_to_mmal(&mmal->dest_rect, &omx->dest_rect); |
61 | rect_to_mmal(&mmal->src_rect, &omx->src_rect); |
62 | mmal->noaspect = omx->noaspect; |
63 | mmal->mode = (MMAL_DISPLAYMODE_T)omx->mode; |
64 | mmal->pixel_x = omx->pixel_x; |
65 | mmal->pixel_y = omx->pixel_y; |
66 | mmal->layer = omx->layer; |
67 | mmal->copyprotect_required = omx->copyprotect_required; |
68 | mmal->alpha = omx->alpha; |
69 | } |
70 | else |
71 | { |
72 | omx->set = mmal->set; |
73 | omx->num = mmal->display_num; |
74 | omx->fullscreen = mmal->fullscreen; |
75 | omx->transform = (OMX_DISPLAYTRANSFORMTYPE)mmal->transform; |
76 | rect_to_omx(&omx->dest_rect, &mmal->dest_rect); |
77 | rect_to_omx(&omx->src_rect, &mmal->src_rect); |
78 | omx->noaspect = mmal->noaspect; |
79 | omx->mode = (OMX_DISPLAYMODETYPE)mmal->mode; |
80 | omx->pixel_x = mmal->pixel_x; |
81 | omx->pixel_y = mmal->pixel_y; |
82 | omx->layer = mmal->layer; |
83 | omx->copyprotect_required = mmal->copyprotect_required; |
84 | omx->alpha = mmal->alpha; |
85 | } |
86 | |
87 | return MMAL_SUCCESS; |
88 | } |
89 | |
90 | static MMAL_STATUS_T mmalomx_param_list_supported_profiles(MMALOMX_PARAM_MAPPING_DIRECTION dir, |
91 | const MMALOMX_PARAM_TRANSLATION_T *xlat, unsigned int index, |
92 | MMAL_PARAMETER_HEADER_T *mmal_param, OMX_PTR omx_param, MMAL_PORT_T *mmal_port) |
93 | { |
94 | OMX_VIDEO_PARAM_PROFILELEVELTYPE *omx = (OMX_VIDEO_PARAM_PROFILELEVELTYPE *)omx_param; |
95 | MMAL_PARAMETER_VIDEO_PROFILE_T *mmal = (MMAL_PARAMETER_VIDEO_PROFILE_T *)mmal_param; |
96 | MMAL_PARAM_UNUSED(xlat); |
97 | |
98 | if (dir == MMALOMX_PARAM_MAPPING_TO_MMAL) |
99 | { |
100 | OMX_VIDEO_CODINGTYPE coding = mmalil_encoding_to_omx_video_coding(mmal_port->format->encoding); |
101 | mmal->profile[index].profile = mmalil_omx_video_profile_to_mmal(omx->eProfile, coding); |
102 | mmal->profile[index].level = mmalil_omx_video_level_to_mmal(omx->eLevel, coding); |
103 | } |
104 | else |
105 | { |
106 | omx->eProfile = mmalil_video_profile_to_omx(mmal->profile[index].profile); |
107 | omx->eLevel = mmalil_video_level_to_omx(mmal->profile[index].level); |
108 | } |
109 | |
110 | return MMAL_SUCCESS; |
111 | } |
112 | |
113 | static MMAL_STATUS_T mmalomx_param_custom_profile(MMALOMX_PARAM_MAPPING_DIRECTION dir, |
114 | const MMALOMX_PARAM_TRANSLATION_T *xlat, |
115 | MMAL_PARAMETER_HEADER_T *mmal_param, OMX_PTR omx_param, MMAL_PORT_T *mmal_port) |
116 | { |
117 | OMX_VIDEO_PARAM_PROFILELEVELTYPE *omx = (OMX_VIDEO_PARAM_PROFILELEVELTYPE *)omx_param; |
118 | MMAL_PARAMETER_VIDEO_PROFILE_T *mmal = (MMAL_PARAMETER_VIDEO_PROFILE_T *)mmal_param; |
119 | MMAL_PARAM_UNUSED(xlat); |
120 | |
121 | if (dir == MMALOMX_PARAM_MAPPING_TO_MMAL) |
122 | { |
123 | OMX_VIDEO_CODINGTYPE coding = mmalil_encoding_to_omx_video_coding(mmal_port->format->encoding); |
124 | mmal->profile[0].profile = mmalil_omx_video_profile_to_mmal(omx->eProfile, coding); |
125 | mmal->profile[0].level = mmalil_omx_video_level_to_mmal(omx->eLevel, coding); |
126 | } |
127 | else |
128 | { |
129 | omx->eProfile = mmalil_video_profile_to_omx(mmal->profile[0].profile); |
130 | omx->eLevel = mmalil_video_level_to_omx(mmal->profile[0].level); |
131 | } |
132 | |
133 | return MMAL_SUCCESS; |
134 | } |
135 | |
136 | static MMAL_STATUS_T mmalomx_param_custom_ratecontrol(MMALOMX_PARAM_MAPPING_DIRECTION dir, |
137 | const MMALOMX_PARAM_TRANSLATION_T *xlat, |
138 | MMAL_PARAMETER_HEADER_T *mmal_param, OMX_PTR omx_param, MMAL_PORT_T *mmal_port) |
139 | { |
140 | OMX_VIDEO_PARAM_BITRATETYPE *omx = (OMX_VIDEO_PARAM_BITRATETYPE *)omx_param; |
141 | MMAL_PARAMETER_VIDEO_RATECONTROL_T *mmal = (MMAL_PARAMETER_VIDEO_RATECONTROL_T *)mmal_param; |
142 | MMAL_PARAM_UNUSED(xlat); |
143 | |
144 | if (dir == MMALOMX_PARAM_MAPPING_TO_MMAL) |
145 | { |
146 | mmal->control = mmalil_omx_video_ratecontrol_to_mmal(omx->eControlRate); |
147 | /* This does not apply nTargetBitrate but should not be necessary */ |
148 | } |
149 | else |
150 | { |
151 | omx->eControlRate = mmalil_video_ratecontrol_to_omx(mmal->control); |
152 | omx->nTargetBitrate = mmal_port->format->bitrate; /* Should not really be necessary */ |
153 | } |
154 | |
155 | return MMAL_SUCCESS; |
156 | } |
157 | |
158 | static const MMALOMX_PARAM_ENUM_TRANSLATE_T mmalomx_param_enum_nalunitformat[] = { |
159 | {MMAL_VIDEO_NALUNITFORMAT_STARTCODES, OMX_NaluFormatStartCodes}, |
160 | {MMAL_VIDEO_NALUNITFORMAT_NALUNITPERBUFFER, OMX_NaluFormatOneNaluPerBuffer}, |
161 | {MMAL_VIDEO_NALUNITFORMAT_ONEBYTEINTERLEAVELENGTH, OMX_NaluFormatOneByteInterleaveLength}, |
162 | {MMAL_VIDEO_NALUNITFORMAT_TWOBYTEINTERLEAVELENGTH, OMX_NaluFormatTwoByteInterleaveLength}, |
163 | {MMAL_VIDEO_NALUNITFORMAT_FOURBYTEINTERLEAVELENGTH, OMX_NaluFormatFourByteInterleaveLength}, |
164 | }; |
165 | |
166 | static MMAL_STATUS_T mmalomx_param_mapping_frame_rate(MMALOMX_PARAM_MAPPING_DIRECTION dir, |
167 | MMAL_PARAMETER_HEADER_T *mmal_param, OMX_PTR omx_param) |
168 | { |
169 | OMX_CONFIG_FRAMERATETYPE *omx = (OMX_CONFIG_FRAMERATETYPE *)omx_param; |
170 | MMAL_PARAMETER_FRAME_RATE_T *mmal = (MMAL_PARAMETER_FRAME_RATE_T *)mmal_param; |
171 | |
172 | if (dir == MMALOMX_PARAM_MAPPING_TO_MMAL) |
173 | { |
174 | mmal->frame_rate.num = omx->xEncodeFramerate; |
175 | mmal->frame_rate.den = (1<<16); |
176 | } |
177 | else |
178 | { |
179 | omx->xEncodeFramerate = 0; |
180 | if (mmal->frame_rate.den) |
181 | omx->xEncodeFramerate = (((int64_t)mmal->frame_rate.num)<<16)/mmal->frame_rate.den; |
182 | } |
183 | |
184 | return MMAL_SUCCESS; |
185 | } |
186 | |
187 | const MMALOMX_PARAM_TRANSLATION_T mmalomx_param_xlator_video[] = { |
188 | MMALOMX_PARAM_STRAIGHT_MAPPING(MMAL_PARAMETER_DISPLAYREGION, MMAL_DISPLAYREGION_T, |
189 | OMX_IndexConfigDisplayRegion, OMX_CONFIG_DISPLAYREGIONTYPE, |
190 | mmalomx_param_mapping_displayregion), |
191 | MMALOMX_PARAM_LIST(MMAL_PARAMETER_SUPPORTED_PROFILES, MMAL_PARAMETER_VIDEO_PROFILE_T, |
192 | OMX_IndexParamVideoProfileLevelQuerySupported, OMX_VIDEO_PARAM_PROFILELEVELTYPE, |
193 | nProfileIndex, mmalomx_param_list_supported_profiles), |
194 | MMALOMX_PARAM_CUSTOM(MMAL_PARAMETER_PROFILE, MMAL_PARAMETER_VIDEO_PROFILE_T, |
195 | OMX_IndexParamVideoProfileLevelCurrent, OMX_VIDEO_PARAM_PROFILELEVELTYPE, |
196 | mmalomx_param_custom_profile), |
197 | MMALOMX_PARAM_PASSTHROUGH(MMAL_PARAMETER_INTRAPERIOD, MMAL_PARAMETER_UINT32_T, |
198 | OMX_IndexConfigBrcmVideoIntraPeriod, OMX_PARAM_U32TYPE), |
199 | MMALOMX_PARAM_CUSTOM(MMAL_PARAMETER_RATECONTROL, MMAL_PARAMETER_VIDEO_RATECONTROL_T, |
200 | OMX_IndexParamVideoBitrate, OMX_VIDEO_PARAM_BITRATETYPE, |
201 | mmalomx_param_custom_ratecontrol), |
202 | MMALOMX_PARAM_ENUM(MMAL_PARAMETER_NALUNITFORMAT, MMAL_PARAMETER_VIDEO_NALUNITFORMAT_T, |
203 | OMX_IndexParamNalStreamFormatSelect, OMX_NALSTREAMFORMATTYPE, mmalomx_param_enum_nalunitformat), |
204 | MMALOMX_PARAM_BOOLEAN_PORTLESS(MMAL_PARAMETER_MINIMISE_FRAGMENTATION, |
205 | OMX_IndexConfigMinimiseFragmentation), |
206 | MMALOMX_PARAM_PASSTHROUGH(MMAL_PARAMETER_MB_ROWS_PER_SLICE, MMAL_PARAMETER_UINT32_T, |
207 | OMX_IndexConfigBrcmVideoEncoderMBRowsPerSlice, OMX_PARAM_U32TYPE), |
208 | MMALOMX_PARAM_PASSTHROUGH(MMAL_PARAMETER_VIDEO_LEVEL_EXTENSION, MMAL_PARAMETER_VIDEO_LEVEL_EXTENSION_T, |
209 | OMX_IndexConfigEncLevelExtension, OMX_VIDEO_CONFIG_LEVEL_EXTEND), |
210 | MMALOMX_PARAM_PASSTHROUGH(MMAL_PARAMETER_VIDEO_INTRA_REFRESH, MMAL_PARAMETER_VIDEO_INTRA_REFRESH_T, |
211 | OMX_IndexConfigBrcmVideoIntraRefresh, OMX_VIDEO_PARAM_INTRAREFRESHTYPE), |
212 | MMALOMX_PARAM_PASSTHROUGH(MMAL_PARAMETER_VIDEO_INTRA_REFRESH, MMAL_PARAMETER_VIDEO_INTRA_REFRESH_T, |
213 | OMX_IndexParamVideoIntraRefresh, OMX_VIDEO_PARAM_INTRAREFRESHTYPE), |
214 | MMALOMX_PARAM_PASSTHROUGH(MMAL_PARAMETER_VIDEO_EEDE_ENABLE, MMAL_PARAMETER_VIDEO_EEDE_ENABLE_T, |
215 | OMX_IndexParamBrcmEEDEEnable, OMX_VIDEO_EEDE_ENABLE), |
216 | MMALOMX_PARAM_PASSTHROUGH(MMAL_PARAMETER_VIDEO_EEDE_LOSSRATE, MMAL_PARAMETER_VIDEO_EEDE_LOSSRATE_T, |
217 | OMX_IndexParamBrcmEEDELossRate, OMX_VIDEO_EEDE_LOSSRATE), |
218 | MMALOMX_PARAM_BOOLEAN_PORTLESS(MMAL_PARAMETER_VIDEO_REQUEST_I_FRAME, |
219 | OMX_IndexConfigBrcmVideoRequestIFrame), |
220 | MMALOMX_PARAM_BOOLEAN_PORTLESS(MMAL_PARAMETER_VIDEO_IMMUTABLE_INPUT, |
221 | OMX_IndexParamBrcmImmutableInput), |
222 | MMALOMX_PARAM_PASSTHROUGH(MMAL_PARAMETER_VIDEO_BIT_RATE, MMAL_PARAMETER_UINT32_T, |
223 | OMX_IndexConfigVideoBitrate, OMX_VIDEO_CONFIG_BITRATETYPE), |
224 | MMALOMX_PARAM_STRAIGHT_MAPPING(MMAL_PARAMETER_VIDEO_FRAME_RATE, MMAL_PARAMETER_FRAME_RATE_T, |
225 | OMX_IndexConfigVideoFramerate, OMX_CONFIG_FRAMERATETYPE, mmalomx_param_mapping_frame_rate), |
226 | MMALOMX_PARAM_STRAIGHT_MAPPING(MMAL_PARAMETER_FRAME_RATE, MMAL_PARAMETER_FRAME_RATE_T, |
227 | OMX_IndexConfigVideoFramerate, OMX_CONFIG_FRAMERATETYPE, mmalomx_param_mapping_frame_rate), |
228 | MMALOMX_PARAM_PASSTHROUGH(MMAL_PARAMETER_VIDEO_ENCODE_MIN_QUANT, MMAL_PARAMETER_UINT32_T, |
229 | OMX_IndexParamBrcmVideoEncodeMinQuant, OMX_PARAM_U32TYPE), |
230 | MMALOMX_PARAM_PASSTHROUGH(MMAL_PARAMETER_VIDEO_ENCODE_MAX_QUANT, MMAL_PARAMETER_UINT32_T, |
231 | OMX_IndexParamBrcmVideoEncodeMaxQuant, OMX_PARAM_U32TYPE), |
232 | MMALOMX_PARAM_PASSTHROUGH(MMAL_PARAMETER_VIDEO_ENCODE_RC_MODEL, MMAL_PARAMETER_VIDEO_ENCODE_RC_MODEL_T, |
233 | OMX_IndexParamRateControlModel, OMX_PARAM_U32TYPE), |
234 | MMALOMX_PARAM_PASSTHROUGH(MMAL_PARAMETER_EXTRA_BUFFERS, MMAL_PARAMETER_UINT32_T, |
235 | OMX_IndexParamBrcmExtraBuffers, OMX_PARAM_U32TYPE), |
236 | MMALOMX_PARAM_PASSTHROUGH(MMAL_PARAMETER_VIDEO_ALIGN_HORIZ, MMAL_PARAMETER_UINT32_T, |
237 | OMX_IndexParamBrcmAlignHoriz, OMX_PARAM_U32TYPE), |
238 | MMALOMX_PARAM_PASSTHROUGH(MMAL_PARAMETER_VIDEO_ALIGN_VERT, MMAL_PARAMETER_UINT32_T, |
239 | OMX_IndexParamBrcmAlignVert, OMX_PARAM_U32TYPE), |
240 | MMALOMX_PARAM_BOOLEAN_PORTLESS(MMAL_PARAMETER_VIDEO_DROPPABLE_PFRAMES, |
241 | OMX_IndexParamBrcmDroppablePFrames), |
242 | MMALOMX_PARAM_PASSTHROUGH(MMAL_PARAMETER_VIDEO_ENCODE_INITIAL_QUANT, MMAL_PARAMETER_UINT32_T, |
243 | OMX_IndexParamBrcmVideoInitialQuant, OMX_PARAM_U32TYPE), |
244 | MMALOMX_PARAM_PASSTHROUGH(MMAL_PARAMETER_VIDEO_ENCODE_QP_P, MMAL_PARAMETER_UINT32_T, |
245 | OMX_IndexParamBrcmVideoInitialQuant, OMX_PARAM_U32TYPE), |
246 | MMALOMX_PARAM_PASSTHROUGH(MMAL_PARAMETER_VIDEO_ENCODE_RC_SLICE_DQUANT, MMAL_PARAMETER_UINT32_T, |
247 | OMX_IndexParamBrcmVideoRCSliceDQuant, OMX_PARAM_U32TYPE), |
248 | MMALOMX_PARAM_PASSTHROUGH(MMAL_PARAMETER_VIDEO_ENCODE_FRAME_LIMIT_BITS, MMAL_PARAMETER_UINT32_T, |
249 | OMX_IndexParamBrcmVideoFrameLimitBits, OMX_PARAM_U32TYPE), |
250 | MMALOMX_PARAM_PASSTHROUGH(MMAL_PARAMETER_VIDEO_ENCODE_PEAK_RATE, MMAL_PARAMETER_UINT32_T, |
251 | OMX_IndexParamBrcmVideoPeakRate, OMX_PARAM_U32TYPE), |
252 | MMALOMX_PARAM_BOOLEAN_PORTLESS(MMAL_PARAMETER_VIDEO_ENCODE_H264_DISABLE_CABAC, |
253 | OMX_IndexConfigBrcmVideoH264DisableCABAC), |
254 | MMALOMX_PARAM_BOOLEAN_PORTLESS(MMAL_PARAMETER_VIDEO_ENCODE_H264_LOW_LATENCY, |
255 | OMX_IndexConfigBrcmVideoH264LowLatency), |
256 | MMALOMX_PARAM_BOOLEAN_PORTLESS(MMAL_PARAMETER_VIDEO_ENCODE_H264_AU_DELIMITERS, |
257 | OMX_IndexConfigBrcmVideoH264AUDelimiters), |
258 | MMALOMX_PARAM_PASSTHROUGH(MMAL_PARAMETER_VIDEO_ENCODE_H264_DEBLOCK_IDC, MMAL_PARAMETER_UINT32_T, |
259 | OMX_IndexConfigBrcmVideoH264DeblockIDC, OMX_PARAM_U32TYPE), |
260 | MMALOMX_PARAM_PASSTHROUGH(MMAL_PARAMETER_VIDEO_ENCODE_H264_MB_INTRA_MODE, MMAL_PARAMETER_VIDEO_ENCODER_H264_MB_INTRA_MODES_T, |
261 | OMX_IndexConfigBrcmVideoH264IntraMBMode, OMX_PARAM_U32TYPE), |
262 | MMALOMX_PARAM_BOOLEAN_PORTLESS(MMAL_PARAMETER_VIDEO_ENCODE_HEADER_ON_OPEN, |
263 | OMX_IndexParamBrcmHeaderOnOpen), |
264 | MMALOMX_PARAM_BOOLEAN_PORTLESS(MMAL_PARAMETER_VIDEO_ENCODE_PRECODE_FOR_QP, |
265 | OMX_IndexParamBrcmVideoPrecodeForQP), |
266 | MMALOMX_PARAM_BOOLEAN_PORTLESS(MMAL_PARAMETER_VIDEO_TIMESTAMP_FIFO, |
267 | OMX_IndexParamBrcmVideoTimestampFifo), |
268 | MMALOMX_PARAM_BOOLEAN_PORTLESS(MMAL_PARAMETER_VIDEO_DECODE_ERROR_CONCEALMENT, |
269 | OMX_IndexParamBrcmVideoDecodeErrorConcealment), |
270 | MMALOMX_PARAM_PASSTHROUGH_PORTLESS_DOUBLE_TRANSLATION(MMAL_PARAMETER_VIDEO_DRM_PROTECT_BUFFER, MMAL_PARAMETER_VIDEO_DRM_PROTECT_BUFFER_T, |
271 | OMX_IndexParamBrcmVideoDrmProtectBuffer, OMX_PARAM_BRCMVIDEODRMPROTECTBUFFERTYPE), |
272 | MMALOMX_PARAM_PASSTHROUGH_PORTLESS(MMAL_PARAMETER_VIDEO_DECODE_CONFIG_VD3, MMAL_PARAMETER_BYTES_T, |
273 | OMX_IndexParamBrcmVideoDecodeConfigVD3, OMX_PARAM_BRCMVIDEODECODECONFIGVD3TYPE), |
274 | MMALOMX_PARAM_BOOLEAN(MMAL_PARAMETER_VIDEO_ENCODE_INLINE_HEADER, |
275 | OMX_IndexParamBrcmVideoAVCInlineHeaderEnable), |
276 | MMALOMX_PARAM_TERMINATE() |
277 | }; |
278 | |