1 /*--------------------------------------------------------------------------
2 Copyright (c) 2010-2019, The Linux Foundation. All rights reserved.
3
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 Linux Foundation nor
12 the names of its contributors may be used to endorse or promote
13 products derived from this software without specific prior written
14 permission.
15
16 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
17 AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18 IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19 NON-INFRINGEMENT ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
20 CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
21 EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
22 PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
23 OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
24 WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
25 OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
26 ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27 --------------------------------------------------------------------------*/
28 #include "omx_video_encoder.h"
29 #include <string.h>
30 #include <stdio.h>
31 #include <fcntl.h>
32 #include <dlfcn.h>
33 #ifdef _ANDROID_ICS_
34 #include <media/hardware/HardwareAPI.h>
35 #endif
36 #ifdef _ANDROID_
37 #include <cutils/properties.h>
38 #endif
39 #ifdef _USE_GLIB_
40 #include <glib.h>
41 #define strlcpy g_strlcpy
42 #endif
43 #include "PlatformConfig.h"
44
45 /* defined in mp-ctl.h */
46 #define MPCTLV3_VIDEO_ENCODE_PB_HINT 0x41C00000
47
48 // factory function executed by the core to create instances
get_omx_component_factory_fn(void)49 void *get_omx_component_factory_fn(void)
50 {
51 return(new omx_venc);
52 }
53
perf_control()54 omx_venc::perf_control::perf_control()
55 {
56 m_perf_control_enable = 0;
57 m_perf_lib = NULL;
58 m_perf_lock_acquire = NULL;
59 m_perf_lock_release = NULL;
60 m_perf_handle = 0;
61 }
62
~perf_control()63 omx_venc::perf_control::~perf_control()
64 {
65 if (!m_perf_control_enable)
66 return;
67 if (m_perf_handle && m_perf_lock_release) {
68 m_perf_lock_release(m_perf_handle);
69 DEBUG_PRINT_HIGH("perflock released");
70 }
71 if (m_perf_lib) {
72 dlclose(m_perf_lib);
73 }
74 }
75
perf_lock_acquire()76 int omx_venc::perf_control::perf_lock_acquire()
77 {
78 int arg[2];
79 if (!m_perf_control_enable)
80 return 0;
81 if (!m_perf_lock_acquire) {
82 DEBUG_PRINT_ERROR("NULL perflock acquire");
83 return -1;
84 }
85 if (m_perf_handle) {
86 DEBUG_PRINT_LOW("perflock already acquired");
87 return 0;
88 }
89
90 DEBUG_PRINT_HIGH("perflock acquire");
91 arg[0] = MPCTLV3_VIDEO_ENCODE_PB_HINT;
92 arg[1] = 1;
93 m_perf_handle = m_perf_lock_acquire(0, 0, arg, sizeof(arg) / sizeof(int));
94 if (m_perf_handle < 0) {
95 DEBUG_PRINT_INFO("perflock acquire failed with error %d", m_perf_handle);
96 m_perf_handle = 0;
97 return -1;
98 }
99 return 0;
100 }
101
perf_lock_release()102 void omx_venc::perf_control::perf_lock_release()
103 {
104 if (!m_perf_control_enable)
105 return;
106 if (!m_perf_lib)
107 return;
108 if (!m_perf_lock_release) {
109 DEBUG_PRINT_ERROR("NULL perflock release");
110 return;
111 }
112 if (!m_perf_handle) {
113 DEBUG_PRINT_LOW("perflock already released");
114 return;
115 }
116 DEBUG_PRINT_HIGH("perflock release");
117 m_perf_lock_release(m_perf_handle);
118 m_perf_handle = 0;
119 }
120
load_perf_library()121 bool omx_venc::perf_control::load_perf_library()
122 {
123 char perf_lib_path[PROPERTY_VALUE_MAX] = {0};
124
125 if (!m_perf_control_enable) {
126 DEBUG_PRINT_HIGH("perf cotrol not enabled");
127 return false;
128 }
129
130 if (m_perf_lib) {
131 DEBUG_PRINT_HIGH("perf cotrol library already opened");
132 return true;
133 }
134
135 if ((property_get("ro.vendor.extension_library", perf_lib_path, NULL) <= 0)) {
136 DEBUG_PRINT_ERROR("vendor library not set in ro.vendor.extension_library");
137 goto handle_err;
138 }
139 if ((m_perf_lib = dlopen(perf_lib_path, RTLD_NOW)) == NULL) {
140 DEBUG_PRINT_ERROR("Failed to open %s : %s",perf_lib_path, dlerror());
141 goto handle_err;
142 } else {
143 m_perf_lock_acquire = (perf_lock_acquire_t)dlsym(m_perf_lib, "perf_lock_acq");
144 if (m_perf_lock_acquire == NULL) {
145 DEBUG_PRINT_ERROR("Failed to load symbol: perf_lock_acq");
146 goto handle_err;
147 }
148 m_perf_lock_release = (perf_lock_release_t)dlsym(m_perf_lib, "perf_lock_rel");
149 if (m_perf_lock_release == NULL) {
150 DEBUG_PRINT_ERROR("Failed to load symbol: perf_lock_rel");
151 goto handle_err;
152 }
153 }
154 return true;
155
156 handle_err:
157 if(m_perf_lib)
158 dlclose(m_perf_lib);
159 m_perf_lib = NULL;
160 m_perf_lock_acquire = NULL;
161 m_perf_lock_release = NULL;
162 return false;
163 }
164
165 //constructor
166
omx_venc()167 omx_venc::omx_venc()
168 {
169 #ifdef _ANDROID_ICS_
170 meta_mode_enable = false;
171 memset(meta_buffer_hdr,0,sizeof(meta_buffer_hdr));
172 memset(meta_buffers,0,sizeof(meta_buffers));
173 memset(opaque_buffer_hdr,0,sizeof(opaque_buffer_hdr));
174 mUseProxyColorFormat = false;
175 get_syntaxhdr_enable = false;
176 #endif
177 char property_value[PROPERTY_VALUE_MAX] = {0};
178 property_get("vendor.vidc.debug.level", property_value, "1");
179 debug_level = strtoul(property_value, NULL, 16);
180 property_value[0] = '\0';
181 handle = NULL;
182 Platform::Config::getInt32(Platform::vidc_perf_control_enable,
183 (int32_t *)&m_perf_control.m_perf_control_enable, 0);
184 if (m_perf_control.m_perf_control_enable) {
185 DEBUG_PRINT_HIGH("perf cotrol enabled");
186 m_perf_control.load_perf_library();
187 }
188 m_perf_control.perf_lock_acquire();
189 }
190
~omx_venc()191 omx_venc::~omx_venc()
192 {
193 get_syntaxhdr_enable = false;
194 m_perf_control.perf_lock_release();
195 }
196
197 /* ======================================================================
198 FUNCTION
199 omx_venc::ComponentInit
200
201 DESCRIPTION
202 Initialize the component.
203
204 PARAMETERS
205 ctxt -- Context information related to the self.
206 id -- Event identifier. This could be any of the following:
207 1. Command completion event
208 2. Buffer done callback event
209 3. Frame done callback event
210
211 RETURN VALUE
212 None.
213
214 ========================================================================== */
component_init(OMX_STRING role)215 OMX_ERRORTYPE omx_venc::component_init(OMX_STRING role)
216 {
217
218 OMX_ERRORTYPE eRet = OMX_ErrorNone;
219
220 int fds[2];
221 int r;
222
223 OMX_VIDEO_CODINGTYPE codec_type;
224
225 DEBUG_PRINT_HIGH("omx_venc(): Inside component_init()");
226 // Copy the role information which provides the decoder m_nkind
227 strlcpy((char *)m_nkind,role,OMX_MAX_STRINGNAME_SIZE);
228 secure_session = false;
229
230 if (!strncmp((char *)m_nkind, "OMX.qcom.video.encoder.avc",\
231 OMX_MAX_STRINGNAME_SIZE)) {
232 strlcpy((char *)m_cRole, "video_encoder.avc",OMX_MAX_STRINGNAME_SIZE);
233 codec_type = OMX_VIDEO_CodingAVC;
234 } else if(!strncmp((char *)m_nkind, "OMX.qcom.video.encoder.avc.secure",\
235 OMX_MAX_STRINGNAME_SIZE)) {
236 strlcpy((char *)m_cRole, "video_encoder.avc",OMX_MAX_STRINGNAME_SIZE);
237 codec_type = OMX_VIDEO_CodingAVC;
238 secure_session = true;
239 } else if (!strncmp((char *)m_nkind, "OMX.qcom.video.encoder.vp8", \
240 OMX_MAX_STRINGNAME_SIZE)) {
241 strlcpy((char *)m_cRole, "video_encoder.vp8",OMX_MAX_STRINGNAME_SIZE);
242 codec_type = OMX_VIDEO_CodingVP8;
243 } else if (!strncmp((char *)m_nkind, "OMX.qcom.video.encoder.hevc", \
244 OMX_MAX_STRINGNAME_SIZE) ||
245 !strncmp((char *)m_nkind, "OMX.qcom.video.encoder.hevc.cq", \
246 OMX_MAX_STRINGNAME_SIZE)) {
247 strlcpy((char *)m_cRole, "video_encoder.hevc", OMX_MAX_STRINGNAME_SIZE);
248 codec_type = OMX_VIDEO_CodingHEVC;
249 } else if (!strncmp((char *)m_nkind, "OMX.qcom.video.encoder.heic", \
250 OMX_MAX_STRINGNAME_SIZE)) {
251 char platform_name[PROP_VALUE_MAX] = {0};
252 char version[PROP_VALUE_MAX] = {0};
253 property_get("ro.board.platform", platform_name, "0"); //HW ID
254 if (!strcmp(platform_name, "sm6150"))
255 {
256 if (property_get("vendor.media.target.version", version, "0") &&
257 (atoi(version) == 0))
258 {
259 //Sku version, HEIC is disabled on this target
260 DEBUG_PRINT_ERROR("heic encoder not supported on this target");
261 eRet = OMX_ErrorInvalidComponentName;
262 } else {
263 strlcpy((char *)m_cRole, "video_encoder.hevc", OMX_MAX_STRINGNAME_SIZE);
264 codec_type = OMX_VIDEO_CodingImageHEIC;
265 }
266 } else {
267 strlcpy((char *)m_cRole, "video_encoder.hevc", OMX_MAX_STRINGNAME_SIZE);
268 codec_type = OMX_VIDEO_CodingImageHEIC;
269 }
270 } else if (!strncmp((char *)m_nkind, "OMX.qcom.video.encoder.hevc.secure", \
271 OMX_MAX_STRINGNAME_SIZE)) {
272 strlcpy((char *)m_cRole, "video_encoder.hevc", OMX_MAX_STRINGNAME_SIZE);
273 codec_type = OMX_VIDEO_CodingHEVC;
274 secure_session = true;
275 } else if (!strncmp((char *)m_nkind, "OMX.qcom.video.encoder.tme", \
276 OMX_MAX_STRINGNAME_SIZE)) {
277 char platform_name[PROP_VALUE_MAX] = {0};
278 char version[PROP_VALUE_MAX] = {0};
279 property_get("ro.board.platform", platform_name, "0"); //HW ID
280 if (!strcmp(platform_name, "sm6150")) {
281 if (property_get("vendor.media.target.version", version, "0") &&
282 (atoi(version) == 0)){
283 //Sku version, TME is enabled on this target
284 strlcpy((char *)m_cRole, "video_encoder.tme", OMX_MAX_STRINGNAME_SIZE);
285 codec_type = (OMX_VIDEO_CODINGTYPE)QOMX_VIDEO_CodingTME;
286 }
287 else {
288 //TME is disabled for Moorea
289 DEBUG_PRINT_LOW("TME is not supported");
290 eRet = OMX_ErrorInvalidComponentName;
291 }
292 }
293 else if (!strcmp(platform_name, "atoll")) {
294 //TME is enabled on ATOLL
295 strlcpy((char *)m_cRole, "video_encoder.tme", OMX_MAX_STRINGNAME_SIZE);
296 codec_type = (OMX_VIDEO_CODINGTYPE)QOMX_VIDEO_CodingTME;
297 }
298 else {
299 DEBUG_PRINT_LOW("TME is not supported");
300 eRet = OMX_ErrorInvalidComponentName;
301 }
302 } else {
303 DEBUG_PRINT_ERROR("ERROR: Unknown Component");
304 eRet = OMX_ErrorInvalidComponentName;
305 }
306
307 if (eRet != OMX_ErrorNone) {
308 return eRet;
309 }
310 #ifdef ENABLE_GET_SYNTAX_HDR
311 get_syntaxhdr_enable = true;
312 DEBUG_PRINT_HIGH("Get syntax header enabled");
313 #endif
314
315 handle = new venc_dev(this);
316
317 if (handle == NULL) {
318 DEBUG_PRINT_ERROR("ERROR: handle is NULL");
319 return OMX_ErrorInsufficientResources;
320 }
321
322 if (handle->venc_open(codec_type) != true) {
323 DEBUG_PRINT_ERROR("ERROR: venc_open failed");
324 eRet = OMX_ErrorInsufficientResources;
325 goto init_error;
326 }
327
328 //Intialise the OMX layer variables
329 memset(&m_pCallbacks,0,sizeof(OMX_CALLBACKTYPE));
330
331 OMX_INIT_STRUCT(&m_sPortParam, OMX_PORT_PARAM_TYPE);
332 m_sPortParam.nPorts = 0x2;
333 m_sPortParam.nStartPortNumber = (OMX_U32) PORT_INDEX_IN;
334
335 OMX_INIT_STRUCT(&m_sPortParam_audio, OMX_PORT_PARAM_TYPE);
336 m_sPortParam_audio.nPorts = 0;
337 m_sPortParam_audio.nStartPortNumber = 0;
338
339 OMX_INIT_STRUCT(&m_sPortParam_img, OMX_PORT_PARAM_TYPE);
340 m_sPortParam_img.nPorts = 0;
341 m_sPortParam_img.nStartPortNumber = 0;
342
343 OMX_INIT_STRUCT(&m_sParamBitrate, OMX_VIDEO_PARAM_BITRATETYPE);
344 m_sParamBitrate.nPortIndex = (OMX_U32) PORT_INDEX_OUT;
345 m_sParamBitrate.eControlRate = OMX_Video_ControlRateVariableSkipFrames;
346 m_sParamBitrate.nTargetBitrate = 64000;
347
348 OMX_INIT_STRUCT(&m_sConfigBitrate, OMX_VIDEO_CONFIG_BITRATETYPE);
349 m_sConfigBitrate.nPortIndex = (OMX_U32) PORT_INDEX_OUT;
350 m_sConfigBitrate.nEncodeBitrate = 64000;
351
352 OMX_INIT_STRUCT(&m_sConfigFramerate, OMX_CONFIG_FRAMERATETYPE);
353 m_sConfigFramerate.nPortIndex = (OMX_U32) PORT_INDEX_OUT;
354 m_sConfigFramerate.xEncodeFramerate = 30 << 16;
355
356 OMX_INIT_STRUCT(&m_sConfigIntraRefreshVOP, OMX_CONFIG_INTRAREFRESHVOPTYPE);
357 m_sConfigIntraRefreshVOP.nPortIndex = (OMX_U32) PORT_INDEX_OUT;
358 m_sConfigIntraRefreshVOP.IntraRefreshVOP = OMX_FALSE;
359
360 OMX_INIT_STRUCT(&m_sConfigFrameRotation, OMX_CONFIG_ROTATIONTYPE);
361 m_sConfigFrameRotation.nPortIndex = (OMX_U32) PORT_INDEX_OUT;
362 m_sConfigFrameRotation.nRotation = 0;
363
364 OMX_INIT_STRUCT(&m_sConfigFrameMirror, OMX_CONFIG_MIRRORTYPE);
365 m_sConfigFrameMirror.nPortIndex = (OMX_U32) PORT_INDEX_OUT;
366 m_sConfigFrameMirror.eMirror = OMX_MirrorNone;
367
368 OMX_INIT_STRUCT(&m_sConfigAVCIDRPeriod, OMX_VIDEO_CONFIG_AVCINTRAPERIOD);
369 m_sConfigAVCIDRPeriod.nPortIndex = (OMX_U32) PORT_INDEX_OUT;
370
371 OMX_INIT_STRUCT(&m_sPrependSPSPPS, PrependSPSPPSToIDRFramesParams);
372 m_sPrependSPSPPS.bEnable = OMX_FALSE;
373
374 OMX_INIT_STRUCT(&m_sSessionQuantization, OMX_VIDEO_PARAM_QUANTIZATIONTYPE);
375 m_sSessionQuantization.nPortIndex = (OMX_U32) PORT_INDEX_OUT;
376
377 OMX_INIT_STRUCT(&m_sSessionQPRange, OMX_QCOM_VIDEO_PARAM_IPB_QPRANGETYPE);
378 m_sSessionQPRange.nPortIndex = (OMX_U32) PORT_INDEX_OUT;
379
380 OMX_INIT_STRUCT(&m_sAVCSliceFMO, OMX_VIDEO_PARAM_AVCSLICEFMO);
381 m_sAVCSliceFMO.nPortIndex = (OMX_U32) PORT_INDEX_OUT;
382 m_sAVCSliceFMO.eSliceMode = OMX_VIDEO_SLICEMODE_AVCDefault;
383 m_sAVCSliceFMO.nNumSliceGroups = 0;
384 m_sAVCSliceFMO.nSliceGroupMapType = 0;
385 OMX_INIT_STRUCT(&m_sParamProfileLevel, OMX_VIDEO_PARAM_PROFILELEVELTYPE);
386 m_sParamProfileLevel.nPortIndex = (OMX_U32) PORT_INDEX_OUT;
387
388 OMX_INIT_STRUCT(&m_sIntraperiod, QOMX_VIDEO_INTRAPERIODTYPE);
389 m_sIntraperiod.nPortIndex = (OMX_U32) PORT_INDEX_OUT;
390 m_sIntraperiod.nPFrames = (m_sConfigFramerate.xEncodeFramerate * 2) - 1;
391 /* Consider a scenario where client does get of this and does not modify this
392 and does a set. Then if by default if this is 0 we assume that client is explicitly
393 requesting disabling of B-Frames and our logic to automatically enable bFrames will
394 fail(We do not enable bframes if there is a set of this param with 0 value). We do
395 not want this to happen(also all our default values support auto enabling of B-Frames).
396 We always take care of scenarios where bframes need to be disabled */
397 m_sIntraperiod.nBFrames = 1;
398
399
400 OMX_INIT_STRUCT(&m_sErrorCorrection, OMX_VIDEO_PARAM_ERRORCORRECTIONTYPE);
401 m_sErrorCorrection.nPortIndex = (OMX_U32) PORT_INDEX_OUT;
402 m_sErrorCorrection.bEnableDataPartitioning = OMX_FALSE;
403 m_sErrorCorrection.bEnableHEC = OMX_FALSE;
404 m_sErrorCorrection.bEnableResync = OMX_FALSE;
405 m_sErrorCorrection.bEnableRVLC = OMX_FALSE;
406 m_sErrorCorrection.nResynchMarkerSpacing = 0;
407
408 OMX_INIT_STRUCT(&m_sSliceSpacing, QOMX_VIDEO_PARAM_SLICE_SPACING_TYPE);
409 m_sSliceSpacing.nPortIndex = (OMX_U32) PORT_INDEX_OUT;
410 m_sSliceSpacing.eSliceMode = QOMX_SLICEMODE_MB_COUNT;
411
412 OMX_INIT_STRUCT(&m_sIntraRefresh, OMX_VIDEO_PARAM_INTRAREFRESHTYPE);
413 m_sIntraRefresh.nPortIndex = (OMX_U32) PORT_INDEX_OUT;
414 m_sIntraRefresh.eRefreshMode = OMX_VIDEO_IntraRefreshMax;
415
416 OMX_INIT_STRUCT(&m_sConfigIntraRefresh, OMX_VIDEO_CONFIG_ANDROID_INTRAREFRESHTYPE);
417 m_sConfigIntraRefresh.nPortIndex = (OMX_U32) PORT_INDEX_OUT;
418 m_sConfigIntraRefresh.nRefreshPeriod = 0;
419
420 OMX_INIT_STRUCT(&m_sConfigColorAspects, DescribeColorAspectsParams);
421 m_sConfigColorAspects.nPortIndex = (OMX_U32) PORT_INDEX_OUT;
422 m_sConfigColorAspects.sAspects.mRange = ColorAspects::RangeUnspecified;
423 m_sConfigColorAspects.sAspects.mPrimaries = ColorAspects::PrimariesUnspecified;
424 m_sConfigColorAspects.sAspects.mMatrixCoeffs = ColorAspects::MatrixUnspecified;
425 m_sConfigColorAspects.sAspects.mTransfer = ColorAspects::TransferUnspecified;
426
427 OMX_INIT_STRUCT(&m_sParamDownScalar, QOMX_INDEXDOWNSCALAR);
428 m_sParamDownScalar.bEnable = OMX_FALSE;
429 m_sParamDownScalar.nOutputWidth = 0;
430 m_sParamDownScalar.nOutputHeight = 0;
431
432 if (codec_type == OMX_VIDEO_CodingAVC) {
433 m_sParamProfileLevel.eProfile = (OMX_U32) OMX_VIDEO_AVCProfileBaseline;
434 m_sParamProfileLevel.eLevel = (OMX_U32) OMX_VIDEO_AVCLevel1;
435 } else if (codec_type == OMX_VIDEO_CodingVP8) {
436 m_sParamProfileLevel.eProfile = (OMX_U32) OMX_VIDEO_VP8ProfileMain;
437 m_sParamProfileLevel.eLevel = (OMX_U32) OMX_VIDEO_VP8Level_Version0;
438 } else if (codec_type == OMX_VIDEO_CodingHEVC) {
439 m_sParamProfileLevel.eProfile = (OMX_U32) OMX_VIDEO_HEVCProfileMain;
440 m_sParamProfileLevel.eLevel = (OMX_U32) OMX_VIDEO_HEVCMainTierLevel1;
441 } else if (codec_type == OMX_VIDEO_CodingImageHEIC) {
442 m_sParamProfileLevel.eProfile = (OMX_U32) OMX_VIDEO_HEVCProfileMainStill;
443 m_sParamProfileLevel.eLevel = (OMX_U32) OMX_VIDEO_HEVCMainTierLevel1;
444 }
445
446 OMX_INIT_STRUCT(&m_sParamEntropy, QOMX_VIDEO_H264ENTROPYCODINGTYPE);
447 m_sParamEntropy.bCabac = OMX_FALSE;
448
449 // Initialize the video parameters for input port
450 OMX_INIT_STRUCT(&m_sInPortDef, OMX_PARAM_PORTDEFINITIONTYPE);
451 m_sInPortDef.nPortIndex= (OMX_U32) PORT_INDEX_IN;
452 m_sInPortDef.bEnabled = OMX_TRUE;
453 m_sInPortDef.bPopulated = OMX_FALSE;
454 m_sInPortDef.eDomain = OMX_PortDomainVideo;
455 m_sInPortDef.eDir = OMX_DirInput;
456 m_sInPortDef.format.video.cMIMEType = (char *)"YUV420";
457 m_sInPortDef.format.video.nFrameWidth = OMX_CORE_QCIF_WIDTH;
458 m_sInPortDef.format.video.nFrameHeight = OMX_CORE_QCIF_HEIGHT;
459 m_sInPortDef.format.video.nStride = OMX_CORE_QCIF_WIDTH;
460 m_sInPortDef.format.video.nSliceHeight = OMX_CORE_QCIF_HEIGHT;
461 m_sInPortDef.format.video.nBitrate = 64000;
462 m_sInPortDef.format.video.xFramerate = 15 << 16;
463 m_sInPortDef.format.video.eColorFormat = (OMX_COLOR_FORMATTYPE)
464 QOMX_DEFAULT_COLOR_FMT;
465 m_sInPortDef.format.video.eCompressionFormat = OMX_VIDEO_CodingUnused;
466
467 if (dev_get_buf_req(&m_sInPortDef.nBufferCountMin,
468 &m_sInPortDef.nBufferCountActual,
469 &m_sInPortDef.nBufferSize,
470 m_sInPortDef.nPortIndex) != true) {
471 eRet = OMX_ErrorUndefined;
472 goto init_error;
473 }
474
475 // Initialize the video parameters for output port
476 OMX_INIT_STRUCT(&m_sOutPortDef, OMX_PARAM_PORTDEFINITIONTYPE);
477 m_sOutPortDef.nPortIndex = (OMX_U32) PORT_INDEX_OUT;
478 m_sOutPortDef.bEnabled = OMX_TRUE;
479 m_sOutPortDef.bPopulated = OMX_FALSE;
480 m_sOutPortDef.eDomain = OMX_PortDomainVideo;
481 m_sOutPortDef.eDir = OMX_DirOutput;
482 m_sOutPortDef.format.video.nFrameWidth = OMX_CORE_QCIF_WIDTH;
483 m_sOutPortDef.format.video.nFrameHeight = OMX_CORE_QCIF_HEIGHT;
484 m_sOutPortDef.format.video.nBitrate = 64000;
485 m_sOutPortDef.format.video.xFramerate = 15 << 16;
486 m_sOutPortDef.format.video.eColorFormat = OMX_COLOR_FormatUnused;
487 if (codec_type == OMX_VIDEO_CodingAVC) {
488 m_sOutPortDef.format.video.eCompressionFormat = OMX_VIDEO_CodingAVC;
489 } else if (codec_type == OMX_VIDEO_CodingVP8) {
490 m_sOutPortDef.format.video.eCompressionFormat = OMX_VIDEO_CodingVP8;
491 } else if (codec_type == OMX_VIDEO_CodingHEVC) {
492 m_sOutPortDef.format.video.eCompressionFormat = OMX_VIDEO_CodingHEVC;
493 } else if (codec_type == OMX_VIDEO_CodingImageHEIC) {
494 m_sOutPortDef.format.video.eCompressionFormat = OMX_VIDEO_CodingImageHEIC;
495 } else if (codec_type == (OMX_VIDEO_CODINGTYPE)QOMX_VIDEO_CodingTME) {
496 m_sOutPortDef.format.video.eCompressionFormat = (OMX_VIDEO_CODINGTYPE)QOMX_VIDEO_CodingTME;
497 }
498
499 if (dev_get_buf_req(&m_sOutPortDef.nBufferCountMin,
500 &m_sOutPortDef.nBufferCountActual,
501 &m_sOutPortDef.nBufferSize,
502 m_sOutPortDef.nPortIndex) != true) {
503 eRet = OMX_ErrorUndefined;
504 goto init_error;
505 }
506
507 // Initialize the video color format for input port
508 OMX_INIT_STRUCT(&m_sInPortFormat, OMX_VIDEO_PARAM_PORTFORMATTYPE);
509 m_sInPortFormat.nPortIndex = (OMX_U32) PORT_INDEX_IN;
510 m_sInPortFormat.nIndex = 0;
511 m_sInPortFormat.eColorFormat = (OMX_COLOR_FORMATTYPE)
512 QOMX_DEFAULT_COLOR_FMT;
513 m_sInPortFormat.eCompressionFormat = OMX_VIDEO_CodingUnused;
514
515
516 // Initialize the compression format for output port
517 OMX_INIT_STRUCT(&m_sOutPortFormat, OMX_VIDEO_PARAM_PORTFORMATTYPE);
518 m_sOutPortFormat.nPortIndex = (OMX_U32) PORT_INDEX_OUT;
519 m_sOutPortFormat.nIndex = 0;
520 m_sOutPortFormat.eColorFormat = OMX_COLOR_FormatUnused;
521 if (codec_type == OMX_VIDEO_CodingAVC) {
522 m_sOutPortFormat.eCompressionFormat = OMX_VIDEO_CodingAVC;
523 } else if (codec_type == OMX_VIDEO_CodingVP8) {
524 m_sOutPortFormat.eCompressionFormat = OMX_VIDEO_CodingVP8;
525 } else if (codec_type == OMX_VIDEO_CodingHEVC) {
526 m_sOutPortFormat.eCompressionFormat = OMX_VIDEO_CodingHEVC;
527 } else if (codec_type == OMX_VIDEO_CodingImageHEIC) {
528 m_sOutPortFormat.eCompressionFormat = OMX_VIDEO_CodingImageHEIC;
529 } else if (codec_type == (OMX_VIDEO_CODINGTYPE)QOMX_VIDEO_CodingTME) {
530 m_sOutPortFormat.eCompressionFormat = (OMX_VIDEO_CODINGTYPE)QOMX_VIDEO_CodingTME;
531 }
532
533 // mandatory Indices for kronos test suite
534 OMX_INIT_STRUCT(&m_sPriorityMgmt, OMX_PRIORITYMGMTTYPE);
535
536 OMX_INIT_STRUCT(&m_sInBufSupplier, OMX_PARAM_BUFFERSUPPLIERTYPE);
537 m_sInBufSupplier.nPortIndex = (OMX_U32) PORT_INDEX_IN;
538
539 OMX_INIT_STRUCT(&m_sOutBufSupplier, OMX_PARAM_BUFFERSUPPLIERTYPE);
540 m_sOutBufSupplier.nPortIndex = (OMX_U32) PORT_INDEX_OUT;
541
542 // h264 specific init
543 OMX_INIT_STRUCT(&m_sParamAVC, OMX_VIDEO_PARAM_AVCTYPE);
544 m_sParamAVC.nPortIndex = (OMX_U32) PORT_INDEX_OUT;
545 m_sParamAVC.nSliceHeaderSpacing = 0;
546 m_sParamAVC.nPFrames = (m_sOutPortFormat.xFramerate * 2 - 1); // 2 second intra period for default outport fps
547 m_sParamAVC.nBFrames = 0;
548 m_sParamAVC.bUseHadamard = OMX_FALSE;
549 m_sParamAVC.nRefIdx10ActiveMinus1 = 1;
550 m_sParamAVC.nRefIdx11ActiveMinus1 = 0;
551 m_sParamAVC.bEnableUEP = OMX_FALSE;
552 m_sParamAVC.bEnableFMO = OMX_FALSE;
553 m_sParamAVC.bEnableASO = OMX_FALSE;
554 m_sParamAVC.bEnableRS = OMX_FALSE;
555 /* Since nBFrames = 1 by default, we need a profile which supports B-Frames */
556 m_sParamAVC.eProfile = OMX_VIDEO_AVCProfileHigh;
557 m_sParamAVC.eLevel = OMX_VIDEO_AVCLevel4;
558 m_sParamAVC.nAllowedPictureTypes = 2;
559 m_sParamAVC.bFrameMBsOnly = OMX_FALSE;
560 m_sParamAVC.bMBAFF = OMX_FALSE;
561 m_sParamAVC.bEntropyCodingCABAC = OMX_FALSE;
562 m_sParamAVC.bWeightedPPrediction = OMX_FALSE;
563 m_sParamAVC.nWeightedBipredicitonMode = 0;
564 m_sParamAVC.bconstIpred = OMX_FALSE;
565 m_sParamAVC.bDirect8x8Inference = OMX_FALSE;
566 m_sParamAVC.bDirectSpatialTemporal = OMX_FALSE;
567 m_sParamAVC.nCabacInitIdc = 0;
568 m_sParamAVC.eLoopFilterMode = OMX_VIDEO_AVCLoopFilterEnable;
569
570 // VP8 specific init
571 OMX_INIT_STRUCT(&m_sParamVP8, OMX_VIDEO_PARAM_VP8TYPE);
572 m_sParamVP8.nPortIndex = (OMX_U32) PORT_INDEX_OUT;
573 m_sParamVP8.eProfile = OMX_VIDEO_VP8ProfileMain;
574 m_sParamVP8.eLevel = OMX_VIDEO_VP8Level_Version0;
575 m_sParamVP8.nDCTPartitions = 0;
576 m_sParamVP8.bErrorResilientMode = OMX_FALSE;
577
578 OMX_INIT_STRUCT(&m_sParamVP8Encoder,OMX_VIDEO_PARAM_ANDROID_VP8ENCODERTYPE);
579 m_sParamVP8Encoder.nPortIndex = (OMX_U32) PORT_INDEX_OUT;
580 m_sParamVP8Encoder.nKeyFrameInterval = 30;
581
582 // HEVC specific init
583 OMX_INIT_STRUCT(&m_sParamHEVC, OMX_VIDEO_PARAM_HEVCTYPE);
584 m_sParamHEVC.nPortIndex = (OMX_U32) PORT_INDEX_OUT;
585 m_sParamHEVC.eProfile = OMX_VIDEO_HEVCProfileMain;
586 m_sParamHEVC.eLevel = OMX_VIDEO_HEVCMainTierLevel1;
587
588 // TME specific init
589 OMX_INIT_STRUCT(&m_sParamTME, QOMX_VIDEO_PARAM_TMETYPE);
590 m_sParamTME.nPortIndex = (OMX_U32) PORT_INDEX_OUT;
591 m_sParamTME.eProfile = QOMX_VIDEO_TMEProfile0;
592 m_sParamTME.eLevel = QOMX_VIDEO_TMELevelInteger;
593 m_sParamTME.ePayloadVersion = tme_payload_version;
594
595 // HEIC specific init
596 OMX_INIT_STRUCT(&m_sParamAndroidImageGrid, OMX_VIDEO_PARAM_ANDROID_IMAGEGRIDTYPE);
597 m_sParamAndroidImageGrid.nPortIndex = (OMX_U32) PORT_INDEX_OUT;
598 m_sParamAndroidImageGrid.bEnabled = OMX_FALSE;
599 m_sParamAndroidImageGrid.nTileWidth = DEFAULT_TILE_DIMENSION;
600 m_sParamAndroidImageGrid.nTileHeight = DEFAULT_TILE_DIMENSION;
601 m_sParamAndroidImageGrid.nGridRows = DEFAULT_TILE_ROWS;
602 m_sParamAndroidImageGrid.nGridCols = DEFAULT_TILE_COLS;
603
604 OMX_INIT_STRUCT(&m_sParamLTRCount, QOMX_VIDEO_PARAM_LTRCOUNT_TYPE);
605 m_sParamLTRCount.nPortIndex = (OMX_U32) PORT_INDEX_OUT;
606 m_sParamLTRCount.nCount = 0;
607
608 OMX_INIT_STRUCT(&m_sConfigLTRUse, QOMX_VIDEO_CONFIG_LTRUSE_TYPE);
609 m_sConfigLTRUse.nPortIndex = (OMX_U32) PORT_INDEX_IN;
610 m_sConfigLTRUse.nID = 0;
611
612 OMX_INIT_STRUCT(&m_sConfigLTRMark, QOMX_VIDEO_CONFIG_LTRMARK_TYPE);
613 m_sConfigLTRMark.nPortIndex = (OMX_U32) PORT_INDEX_IN;
614 m_sConfigLTRMark.nID = 0;
615
616 OMX_INIT_STRUCT(&m_sConfigDeinterlace, OMX_VIDEO_CONFIG_DEINTERLACE);
617 m_sConfigDeinterlace.nPortIndex = (OMX_U32) PORT_INDEX_OUT;
618 m_sConfigDeinterlace.nEnable = OMX_FALSE;
619
620 OMX_INIT_STRUCT(&m_sHierLayers, QOMX_VIDEO_HIERARCHICALLAYERS);
621 m_sHierLayers.nPortIndex = (OMX_U32) PORT_INDEX_OUT;
622 m_sHierLayers.nNumLayers = 0;
623 m_sHierLayers.eHierarchicalCodingType = QOMX_HIERARCHICALCODING_P;
624
625 OMX_INIT_STRUCT(&m_sParamTemporalLayers, OMX_VIDEO_PARAM_ANDROID_TEMPORALLAYERINGTYPE);
626 m_sParamTemporalLayers.eSupportedPatterns = OMX_VIDEO_AndroidTemporalLayeringPatternAndroid;
627
628 OMX_INIT_STRUCT(&m_sConfigTemporalLayers, OMX_VIDEO_CONFIG_ANDROID_TEMPORALLAYERINGTYPE);
629
630 OMX_INIT_STRUCT(&m_sParamAVTimerTimestampMode, QOMX_ENABLETYPE);
631 m_sParamAVTimerTimestampMode.bEnable = OMX_FALSE;
632
633 OMX_INIT_STRUCT(&m_sConfigQP, OMX_QCOM_VIDEO_CONFIG_QP);
634 m_sConfigQP.nPortIndex = (OMX_U32) PORT_INDEX_OUT;
635 m_sConfigQP.nQP = 30;
636
637 OMX_INIT_STRUCT(&m_sParamControlInputQueue , QOMX_ENABLETYPE);
638 m_sParamControlInputQueue.bEnable = OMX_FALSE;
639
640 OMX_INIT_STRUCT(&m_sConfigInputTrigTS, OMX_TIME_CONFIG_TIMESTAMPTYPE);
641
642 OMX_INIT_STRUCT(&m_sParamLowLatency, QOMX_EXTNINDEX_VIDEO_LOW_LATENCY_MODE);
643 m_sParamLowLatency.nNumFrames = 0;
644
645 OMX_INIT_STRUCT(&m_sParamColorSpaceConversion , QOMX_ENABLETYPE);
646 m_sParamColorSpaceConversion.bEnable = OMX_FALSE;
647
648 OMX_INIT_STRUCT(&m_sBaseLayerID, OMX_SKYPE_VIDEO_CONFIG_BASELAYERPID);
649
650 OMX_INIT_STRUCT(&m_sParamLinearColorFormat, QOMX_ENABLETYPE);
651 m_sParamLinearColorFormat.bEnable = OMX_FALSE;
652
653 OMX_INIT_STRUCT(&m_sParamNativeRecorder, QOMX_ENABLETYPE);
654 m_sParamNativeRecorder.bEnable = OMX_FALSE;
655
656 m_state = OMX_StateLoaded;
657 m_sExtraData = 0;
658
659 if (eRet == OMX_ErrorNone) {
660 msg_thread_created = true;
661 r = pthread_create(&msg_thread_id,0, message_thread_enc, this);
662 if (r < 0) {
663 DEBUG_PRINT_ERROR("ERROR: message_thread_enc thread creation failed");
664 eRet = OMX_ErrorInsufficientResources;
665 msg_thread_created = false;
666 goto init_error;
667 } else {
668 async_thread_created = true;
669 r = pthread_create(&async_thread_id,0, venc_dev::async_venc_message_thread, this);
670 if (r < 0) {
671 DEBUG_PRINT_ERROR("ERROR: venc_dev::async_venc_message_thread thread creation failed");
672 eRet = OMX_ErrorInsufficientResources;
673 async_thread_created = false;
674 msg_thread_stop = true;
675 pthread_join(msg_thread_id,NULL);
676 msg_thread_created = false;
677 goto init_error;
678 } else
679 dev_set_message_thread_id(async_thread_id);
680 }
681 }
682
683 DEBUG_PRINT_INFO("Component_init : %s : return = 0x%x", m_nkind, eRet);
684
685 {
686 VendorExtensionStore *extStore = const_cast<VendorExtensionStore *>(&mVendorExtensionStore);
687 init_vendor_extensions(*extStore);
688 mVendorExtensionStore.dumpExtensions((const char *)m_nkind);
689 }
690
691 return eRet;
692 init_error:
693 handle->venc_close();
694 delete handle;
695 handle = NULL;
696 return eRet;
697 }
698
699
700 /* ======================================================================
701 FUNCTION
702 omx_venc::Setparameter
703
704 DESCRIPTION
705 OMX Set Parameter method implementation.
706
707 PARAMETERS
708 <TBD>.
709
710 RETURN VALUE
711 OMX Error None if successful.
712
713 ========================================================================== */
set_parameter(OMX_IN OMX_HANDLETYPE hComp,OMX_IN OMX_INDEXTYPE paramIndex,OMX_IN OMX_PTR paramData)714 OMX_ERRORTYPE omx_venc::set_parameter(OMX_IN OMX_HANDLETYPE hComp,
715 OMX_IN OMX_INDEXTYPE paramIndex,
716 OMX_IN OMX_PTR paramData)
717 {
718 (void)hComp;
719 OMX_ERRORTYPE eRet = OMX_ErrorNone;
720
721
722 if (m_state == OMX_StateInvalid) {
723 DEBUG_PRINT_ERROR("ERROR: Set Param in Invalid State");
724 return OMX_ErrorInvalidState;
725 }
726 if (paramData == NULL) {
727 DEBUG_PRINT_ERROR("ERROR: Get Param in Invalid paramData");
728 return OMX_ErrorBadParameter;
729 }
730
731 /*set_parameter can be called in loaded state
732 or disabled port */
733 if (m_state == OMX_StateLoaded
734 || m_sInPortDef.bEnabled == OMX_FALSE
735 || m_sOutPortDef.bEnabled == OMX_FALSE) {
736 DEBUG_PRINT_LOW("Set Parameter called in valid state");
737 } else {
738 DEBUG_PRINT_ERROR("ERROR: Set Parameter called in Invalid State");
739 return OMX_ErrorIncorrectStateOperation;
740 }
741
742 if (reject_param_for_TME_mode(paramIndex)) {
743 DEBUG_PRINT_ERROR("ERROR: Set Parameter 0x%x rejected in TME mode", (int)paramIndex);
744 return OMX_ErrorNone;
745 }
746
747 switch ((int)paramIndex) {
748 case OMX_IndexParamPortDefinition:
749 {
750 VALIDATE_OMX_PARAM_DATA(paramData, OMX_PARAM_PORTDEFINITIONTYPE);
751 OMX_PARAM_PORTDEFINITIONTYPE *portDefn;
752 portDefn = (OMX_PARAM_PORTDEFINITIONTYPE *) paramData;
753 char colorFormatStr[200];
754 dev_get_color_format_as_string(colorFormatStr, sizeof(colorFormatStr), portDefn->format.video.eColorFormat);
755 DEBUG_PRINT_HIGH("set_parameter: OMX_IndexParamPortDefinition: port %d, wxh %dx%d, min %d, actual %d, size %d, colorformat %#x (%s), compression format %#x",
756 portDefn->nPortIndex, portDefn->format.video.nFrameWidth, portDefn->format.video.nFrameHeight,
757 portDefn->nBufferCountMin, portDefn->nBufferCountActual, portDefn->nBufferSize,
758 portDefn->format.video.eColorFormat, colorFormatStr, portDefn->format.video.eCompressionFormat);
759
760 if (PORT_INDEX_IN == portDefn->nPortIndex) {
761 if (portDefn->nBufferCountActual > MAX_NUM_INPUT_BUFFERS) {
762 DEBUG_PRINT_ERROR("ERROR: (In_PORT) actual count (%u) exceeds max(%u)",
763 (unsigned int)portDefn->nBufferCountActual, (unsigned int)MAX_NUM_INPUT_BUFFERS);
764 return OMX_ErrorUnsupportedSetting;
765 }
766 if (m_inp_mem_ptr &&
767 (portDefn->nBufferCountActual != m_sInPortDef.nBufferCountActual ||
768 portDefn->nBufferSize != m_sInPortDef.nBufferSize)) {
769 DEBUG_PRINT_ERROR("ERROR: (In_PORT) buffer count/size can change only if port is unallocated !");
770 return OMX_ErrorInvalidState;
771 }
772 if (m_inp_mem_ptr &&
773 (portDefn->nBufferCountActual != m_sInPortDef.nBufferCountActual ||
774 portDefn->nBufferSize != m_sInPortDef.nBufferSize)) {
775 DEBUG_PRINT_ERROR("ERROR: (In_PORT) buffer count/size can change only if port is unallocated !");
776 return OMX_ErrorInvalidState;
777 }
778 if (portDefn->nBufferCountMin > portDefn->nBufferCountActual) {
779 DEBUG_PRINT_ERROR("ERROR: (In_PORT) Min buffers (%u) > actual count (%u)",
780 (unsigned int)portDefn->nBufferCountMin, (unsigned int)portDefn->nBufferCountActual);
781 return OMX_ErrorUnsupportedSetting;
782 }
783 if (handle->venc_set_param(paramData,OMX_IndexParamPortDefinition) != true) {
784 DEBUG_PRINT_ERROR("ERROR: venc_set_param input failed");
785 return handle->hw_overload ? OMX_ErrorInsufficientResources :
786 OMX_ErrorUnsupportedSetting;
787 }
788
789 memcpy(&m_sInPortDef, portDefn,sizeof(OMX_PARAM_PORTDEFINITIONTYPE));
790
791 #ifdef _ANDROID_ICS_
792 if (portDefn->format.video.eColorFormat ==
793 (OMX_COLOR_FORMATTYPE)QOMX_COLOR_FormatAndroidOpaque) {
794 m_sInPortDef.format.video.eColorFormat = (OMX_COLOR_FORMATTYPE)
795 QOMX_DEFAULT_COLOR_FMT;
796 mUseProxyColorFormat = true;
797 m_input_msg_id = OMX_COMPONENT_GENERATE_ETB_OPQ;
798 } else
799 mUseProxyColorFormat = false;
800 #endif
801 /*Query Input Buffer Requirements*/
802 dev_get_buf_req (&m_sInPortDef.nBufferCountMin,
803 &m_sInPortDef.nBufferCountActual,
804 &m_sInPortDef.nBufferSize,
805 m_sInPortDef.nPortIndex);
806
807 /*Query ouput Buffer Requirements*/
808 dev_get_buf_req (&m_sOutPortDef.nBufferCountMin,
809 &m_sOutPortDef.nBufferCountActual,
810 &m_sOutPortDef.nBufferSize,
811 m_sOutPortDef.nPortIndex);
812 m_sInPortDef.nBufferCountActual = portDefn->nBufferCountActual;
813 } else if (PORT_INDEX_EXTRADATA_OUT == portDefn->nPortIndex) {
814 DEBUG_PRINT_LOW("extradata actual cnt =%u , min cnt =%u ,buffersize requested = %u",
815 (unsigned int)portDefn->nBufferCountActual,(unsigned int)portDefn->nBufferCountMin,
816 (unsigned int)portDefn->nBufferSize);
817 if (portDefn->nBufferCountActual != m_client_out_extradata_info.getBufferCount() ||
818 portDefn->nBufferSize != m_client_out_extradata_info.getSize()) {
819 DEBUG_PRINT_HIGH("ERROR: Bad parameeters request for extradata limit %d size - %d",
820 portDefn->nBufferCountActual, portDefn->nBufferSize);
821 eRet = OMX_ErrorNone;
822 break;
823 }
824 } else if (PORT_INDEX_EXTRADATA_IN == portDefn->nPortIndex) {
825 DEBUG_PRINT_LOW("extradata actual cnt =%u , min cnt =%u ,buffersize requested = %u",
826 (unsigned int)portDefn->nBufferCountActual,(unsigned int)portDefn->nBufferCountMin,
827 (unsigned int)portDefn->nBufferSize);
828 if (portDefn->nBufferCountActual != m_client_in_extradata_info.getBufferCount() ||
829 portDefn->nBufferSize != m_client_in_extradata_info.getSize()) {
830 DEBUG_PRINT_ERROR("ERROR: Bad parameeters request for extradata limit %d size - %d",
831 portDefn->nBufferCountActual, portDefn->nBufferSize);
832 eRet = OMX_ErrorBadParameter;
833 break;
834 }
835 } else if (PORT_INDEX_OUT == portDefn->nPortIndex) {
836
837 if (portDefn->nBufferCountActual > MAX_NUM_OUTPUT_BUFFERS) {
838 DEBUG_PRINT_ERROR("ERROR: (Out_PORT) actual count (%u) exceeds max(%u)",
839 (unsigned int)portDefn->nBufferCountActual, (unsigned int)MAX_NUM_OUTPUT_BUFFERS);
840 return OMX_ErrorUnsupportedSetting;
841 }
842 if (m_out_mem_ptr &&
843 (portDefn->nBufferCountActual != m_sOutPortDef.nBufferCountActual ||
844 portDefn->nBufferSize != m_sOutPortDef.nBufferSize)) {
845 DEBUG_PRINT_ERROR("ERROR: (Out_PORT) buffer count/size can change only if port is unallocated !");
846 return OMX_ErrorInvalidState;
847 }
848
849 if (portDefn->nBufferCountMin > portDefn->nBufferCountActual) {
850 DEBUG_PRINT_ERROR("ERROR: (Out_PORT) Min buffers (%u) > actual count (%u)",
851 (unsigned int)portDefn->nBufferCountMin, (unsigned int)portDefn->nBufferCountActual);
852 return OMX_ErrorUnsupportedSetting;
853 }
854 if (handle->venc_set_param(paramData,OMX_IndexParamPortDefinition) != true) {
855 DEBUG_PRINT_ERROR("ERROR: venc_set_param output failed");
856 return OMX_ErrorUnsupportedSetting;
857 }
858 memcpy(&m_sOutPortDef,portDefn,sizeof(struct OMX_PARAM_PORTDEFINITIONTYPE));
859 /*Query ouput Buffer Requirements*/
860 dev_get_buf_req(&m_sOutPortDef.nBufferCountMin,
861 &m_sOutPortDef.nBufferCountActual,
862 &m_sOutPortDef.nBufferSize,
863 m_sOutPortDef.nPortIndex);
864 update_profile_level(); //framerate , bitrate
865
866 m_sOutPortDef.nBufferCountActual = portDefn->nBufferCountActual;
867 } else {
868 DEBUG_PRINT_ERROR("ERROR: Set_parameter: Bad Port idx %d",
869 (int)portDefn->nPortIndex);
870 eRet = OMX_ErrorBadPortIndex;
871 }
872 m_sConfigFramerate.xEncodeFramerate = portDefn->format.video.xFramerate;
873 m_sConfigBitrate.nEncodeBitrate = portDefn->format.video.nBitrate;
874 m_sParamBitrate.nTargetBitrate = portDefn->format.video.nBitrate;
875 }
876 break;
877
878 case OMX_IndexParamVideoPortFormat:
879 {
880 VALIDATE_OMX_PARAM_DATA(paramData, OMX_VIDEO_PARAM_PORTFORMATTYPE);
881 OMX_VIDEO_PARAM_PORTFORMATTYPE *portFmt =
882 (OMX_VIDEO_PARAM_PORTFORMATTYPE *)paramData;
883 char colorFormatStr[200];
884 dev_get_color_format_as_string(colorFormatStr, sizeof(colorFormatStr), portFmt->eColorFormat);
885 DEBUG_PRINT_LOW("set_parameter: OMX_IndexParamVideoPortFormat %x (%s)",
886 portFmt->eColorFormat, colorFormatStr);
887 //set the driver with the corresponding values
888 if (PORT_INDEX_IN == portFmt->nPortIndex) {
889 if (handle->venc_set_param(paramData,OMX_IndexParamVideoPortFormat) != true) {
890 return OMX_ErrorUnsupportedSetting;
891 }
892
893 DEBUG_PRINT_LOW("set_parameter: OMX_IndexParamVideoPortFormat %x (%s)",
894 portFmt->eColorFormat, colorFormatStr);
895 update_profile_level(); //framerate
896
897 #ifdef _ANDROID_ICS_
898 if (portFmt->eColorFormat ==
899 (OMX_COLOR_FORMATTYPE)QOMX_COLOR_FormatAndroidOpaque) {
900 m_sInPortFormat.eColorFormat = (OMX_COLOR_FORMATTYPE)
901 QOMX_DEFAULT_COLOR_FMT;
902 mUseProxyColorFormat = true;
903 m_input_msg_id = OMX_COMPONENT_GENERATE_ETB_OPQ;
904 } else
905 #endif
906 {
907 m_sInPortFormat.eColorFormat = portFmt->eColorFormat;
908 m_sInPortDef.format.video.eColorFormat = portFmt->eColorFormat;
909 m_input_msg_id = OMX_COMPONENT_GENERATE_ETB;
910 mUseProxyColorFormat = false;
911 }
912 m_sInPortFormat.xFramerate = portFmt->xFramerate;
913 }
914 //TODO if no use case for O/P port,delet m_sOutPortFormat
915 }
916 break;
917 case OMX_IndexParamVideoInit:
918 { //TODO, do we need this index set param
919 VALIDATE_OMX_PARAM_DATA(paramData, OMX_PORT_PARAM_TYPE);
920 OMX_PORT_PARAM_TYPE* pParam = (OMX_PORT_PARAM_TYPE*)(paramData);
921 DEBUG_PRINT_LOW("Set OMX_IndexParamVideoInit called");
922 break;
923 }
924
925 case OMX_IndexParamVideoBitrate:
926 {
927 VALIDATE_OMX_PARAM_DATA(paramData, OMX_VIDEO_PARAM_BITRATETYPE);
928 OMX_VIDEO_PARAM_BITRATETYPE* pParam = (OMX_VIDEO_PARAM_BITRATETYPE*)paramData;
929 DEBUG_PRINT_LOW("set_parameter: OMX_IndexParamVideoBitrate");
930 if (handle->venc_set_param(paramData,OMX_IndexParamVideoBitrate) != true) {
931 return OMX_ErrorUnsupportedSetting;
932 }
933 m_sParamBitrate.nTargetBitrate = pParam->nTargetBitrate;
934 m_sParamBitrate.eControlRate = pParam->eControlRate;
935 update_profile_level(); //bitrate
936 m_sConfigBitrate.nEncodeBitrate = pParam->nTargetBitrate;
937 m_sInPortDef.format.video.nBitrate = pParam->nTargetBitrate;
938 m_sOutPortDef.format.video.nBitrate = pParam->nTargetBitrate;
939 /* RC mode chan chage buffer requirements on Input port */
940 dev_get_buf_req(&m_sInPortDef.nBufferCountMin,
941 &m_sInPortDef.nBufferCountActual,
942 &m_sInPortDef.nBufferSize,
943 m_sInPortDef.nPortIndex);
944 DEBUG_PRINT_LOW("bitrate = %u", (unsigned int)m_sOutPortDef.format.video.nBitrate);
945 break;
946 }
947 case OMX_IndexParamVideoAvc:
948 {
949 VALIDATE_OMX_PARAM_DATA(paramData, OMX_VIDEO_PARAM_AVCTYPE);
950 OMX_VIDEO_PARAM_AVCTYPE* pParam = (OMX_VIDEO_PARAM_AVCTYPE*)paramData;
951 OMX_VIDEO_PARAM_AVCTYPE avc_param;
952 memcpy(&avc_param, pParam, sizeof( struct OMX_VIDEO_PARAM_AVCTYPE));
953 DEBUG_PRINT_LOW("set_parameter: OMX_IndexParamVideoAvc");
954
955 avc_param.nBFrames = 0;
956 avc_param.bEntropyCodingCABAC = (OMX_BOOL)(0);
957 avc_param.nCabacInitIdc = 0;
958 if ((pParam->eProfile == OMX_VIDEO_AVCProfileHigh)||
959 (pParam->eProfile == OMX_VIDEO_AVCProfileMain)||
960 (pParam->eProfile == (OMX_VIDEO_AVCPROFILETYPE)OMX_VIDEO_AVCProfileConstrainedHigh)) {
961
962 if (pParam->nBFrames) {
963 avc_param.nBFrames = pParam->nBFrames;
964 DEBUG_PRINT_LOW("B frames set using Client setparam to %d",
965 avc_param.nBFrames);
966 }
967
968 DEBUG_PRINT_HIGH("AVC: BFrames: %u", (unsigned int)avc_param.nBFrames);
969 avc_param.bEntropyCodingCABAC = (OMX_BOOL)(1);
970 avc_param.nCabacInitIdc = 0;
971 } else {
972 if (pParam->nBFrames) {
973 DEBUG_PRINT_HIGH("B frames not supported with profile %x", pParam->eProfile);
974 }
975 }
976
977 if (handle->venc_set_param(&avc_param,OMX_IndexParamVideoAvc) != true) {
978 return OMX_ErrorUnsupportedSetting;
979 }
980 memcpy(&m_sParamAVC,pParam, sizeof(struct OMX_VIDEO_PARAM_AVCTYPE));
981 /* nBFrames is only supported through QOMX_IndexConfigVideoIntraperiod. Don't set here */
982 break;
983 }
984 case (OMX_INDEXTYPE)OMX_IndexParamVideoVp8:
985 {
986 VALIDATE_OMX_PARAM_DATA(paramData, OMX_VIDEO_PARAM_VP8TYPE);
987 OMX_VIDEO_PARAM_VP8TYPE* pParam = (OMX_VIDEO_PARAM_VP8TYPE*)paramData;
988 OMX_VIDEO_PARAM_VP8TYPE vp8_param;
989 DEBUG_PRINT_LOW("set_parameter: OMX_IndexParamVideoVp8");
990 if (pParam->nDCTPartitions != m_sParamVP8.nDCTPartitions ||
991 pParam->bErrorResilientMode != m_sParamVP8.bErrorResilientMode) {
992 DEBUG_PRINT_ERROR("VP8 doesn't support nDCTPartitions or bErrorResilientMode");
993 }
994 memcpy(&vp8_param, pParam, sizeof( struct OMX_VIDEO_PARAM_VP8TYPE));
995 if (handle->venc_set_param(&vp8_param, (OMX_INDEXTYPE)OMX_IndexParamVideoVp8) != true) {
996 return OMX_ErrorUnsupportedSetting;
997 }
998 memcpy(&m_sParamVP8,pParam, sizeof(struct OMX_VIDEO_PARAM_VP8TYPE));
999 break;
1000 }
1001 case (OMX_INDEXTYPE)OMX_IndexParamVideoAndroidVp8Encoder:
1002 {
1003 VALIDATE_OMX_PARAM_DATA(paramData, OMX_VIDEO_PARAM_ANDROID_VP8ENCODERTYPE);
1004 OMX_VIDEO_PARAM_ANDROID_VP8ENCODERTYPE* pParam = (OMX_VIDEO_PARAM_ANDROID_VP8ENCODERTYPE*)paramData;
1005 OMX_VIDEO_PARAM_ANDROID_VP8ENCODERTYPE vp8_param;
1006 DEBUG_PRINT_LOW("set_parameter: OMX_IndexParamVideoAndroidVp8Encoder");
1007
1008 memcpy(&vp8_param, pParam, sizeof( struct OMX_VIDEO_PARAM_ANDROID_VP8ENCODERTYPE));
1009 if (handle->venc_set_param(&vp8_param, (OMX_INDEXTYPE)OMX_IndexParamVideoAndroidVp8Encoder) != true) {
1010 return OMX_ErrorUnsupportedSetting;
1011 }
1012 memcpy(&m_sParamVP8Encoder, &vp8_param, sizeof(struct OMX_VIDEO_PARAM_ANDROID_VP8ENCODERTYPE));
1013 break;
1014 }
1015 case (OMX_INDEXTYPE)OMX_IndexParamVideoHevc:
1016 {
1017 VALIDATE_OMX_PARAM_DATA(paramData, OMX_VIDEO_PARAM_HEVCTYPE);
1018 OMX_VIDEO_PARAM_HEVCTYPE* pParam = (OMX_VIDEO_PARAM_HEVCTYPE*)paramData;
1019 OMX_VIDEO_PARAM_HEVCTYPE hevc_param;
1020 DEBUG_PRINT_LOW("set_parameter: OMX_IndexParamVideoHevc");
1021 memcpy(&hevc_param, pParam, sizeof( struct OMX_VIDEO_PARAM_HEVCTYPE));
1022 if (handle->venc_set_param(&hevc_param, (OMX_INDEXTYPE)OMX_IndexParamVideoHevc) != true) {
1023 DEBUG_PRINT_ERROR("Failed : set_parameter: OMX_IndexParamVideoHevc");
1024 return OMX_ErrorUnsupportedSetting;
1025 }
1026 memcpy(&m_sParamHEVC, pParam, sizeof(struct OMX_VIDEO_PARAM_HEVCTYPE));
1027 break;
1028 }
1029 case (OMX_INDEXTYPE)OMX_IndexParamVideoTme:
1030 {
1031 VALIDATE_OMX_PARAM_DATA(paramData, QOMX_VIDEO_PARAM_TMETYPE);
1032 QOMX_VIDEO_PARAM_TMETYPE* pParam = (QOMX_VIDEO_PARAM_TMETYPE*)paramData;
1033 QOMX_VIDEO_PARAM_TMETYPE tme_param;
1034 DEBUG_PRINT_LOW("set_parameter: OMX_IndexParamVideoTME");
1035 memcpy(&tme_param, pParam, sizeof( struct QOMX_VIDEO_PARAM_TMETYPE));
1036 if (handle->venc_set_param(&tme_param, (OMX_INDEXTYPE)OMX_IndexParamVideoTme) != true) {
1037 DEBUG_PRINT_ERROR("Failed : set_parameter: OMX_IndexParamVideoTme");
1038 return OMX_ErrorUnsupportedSetting;
1039 }
1040 memcpy(&m_sParamTME, pParam, sizeof(struct QOMX_VIDEO_PARAM_TMETYPE));
1041 m_sParamTME.ePayloadVersion = tme_payload_version;
1042 break;
1043 }
1044 case OMX_IndexParamVideoAndroidImageGrid:
1045 {
1046 DEBUG_PRINT_LOW("set_parameter: OMX_IndexParamVideoAndroidImageGrid. Ignore!");
1047 break;
1048 }
1049 case OMX_IndexParamVideoProfileLevelCurrent:
1050 {
1051 VALIDATE_OMX_PARAM_DATA(paramData, OMX_VIDEO_PARAM_PROFILELEVELTYPE);
1052 OMX_VIDEO_PARAM_PROFILELEVELTYPE* pParam = (OMX_VIDEO_PARAM_PROFILELEVELTYPE*)paramData;
1053 DEBUG_PRINT_LOW("set_parameter: OMX_IndexParamVideoProfileLevelCurrent");
1054 if (handle->venc_set_param(pParam,OMX_IndexParamVideoProfileLevelCurrent) != true) {
1055 DEBUG_PRINT_ERROR("set_parameter: OMX_IndexParamVideoProfileLevelCurrent failed for Profile: %u "
1056 "Level :%u", (unsigned int)pParam->eProfile, (unsigned int)pParam->eLevel);
1057 return OMX_ErrorUnsupportedSetting;
1058 }
1059 m_sParamProfileLevel.eProfile = pParam->eProfile;
1060 m_sParamProfileLevel.eLevel = pParam->eLevel;
1061
1062 if (!strncmp((char *)m_nkind, "OMX.qcom.video.encoder.avc",\
1063 OMX_MAX_STRINGNAME_SIZE)) {
1064 m_sParamAVC.eProfile = (OMX_VIDEO_AVCPROFILETYPE)m_sParamProfileLevel.eProfile;
1065 m_sParamAVC.eLevel = (OMX_VIDEO_AVCLEVELTYPE)m_sParamProfileLevel.eLevel;
1066 DEBUG_PRINT_LOW("AVC profile = %d, level = %d", m_sParamAVC.eProfile,
1067 m_sParamAVC.eLevel);
1068 } else if (!strncmp((char *)m_nkind, "OMX.qcom.video.encoder.avc.secure",\
1069 OMX_MAX_STRINGNAME_SIZE)) {
1070 m_sParamAVC.eProfile = (OMX_VIDEO_AVCPROFILETYPE)m_sParamProfileLevel.eProfile;
1071 m_sParamAVC.eLevel = (OMX_VIDEO_AVCLEVELTYPE)m_sParamProfileLevel.eLevel;
1072 DEBUG_PRINT_LOW("\n AVC profile = %d, level = %d", m_sParamAVC.eProfile,
1073 m_sParamAVC.eLevel);
1074 }
1075 else if (!strncmp((char*)m_nkind, "OMX.qcom.video.encoder.vp8",\
1076 OMX_MAX_STRINGNAME_SIZE)) {
1077 m_sParamVP8.eProfile = (OMX_VIDEO_VP8PROFILETYPE)m_sParamProfileLevel.eProfile;
1078 m_sParamVP8.eLevel = (OMX_VIDEO_VP8LEVELTYPE)m_sParamProfileLevel.eLevel;
1079 DEBUG_PRINT_LOW("VP8 profile = %d, level = %d", m_sParamVP8.eProfile,
1080 m_sParamVP8.eLevel);
1081 }
1082 else if (!strncmp((char*)m_nkind, "OMX.qcom.video.encoder.hevc",\
1083 OMX_MAX_STRINGNAME_SIZE) ||
1084 !strncmp((char*)m_nkind, "OMX.qcom.video.encoder.hevc.cq",\
1085 OMX_MAX_STRINGNAME_SIZE) ||
1086 !strncmp((char*)m_nkind, "OMX.qcom.video.encoder.heic",\
1087 OMX_MAX_STRINGNAME_SIZE)) {
1088 m_sParamHEVC.eProfile = (OMX_VIDEO_HEVCPROFILETYPE)m_sParamProfileLevel.eProfile;
1089 m_sParamHEVC.eLevel = (OMX_VIDEO_HEVCLEVELTYPE)m_sParamProfileLevel.eLevel;
1090 DEBUG_PRINT_LOW("HEVC profile = %d, level = %d", m_sParamHEVC.eProfile,
1091 m_sParamHEVC.eLevel);
1092 }
1093
1094 break;
1095 }
1096 case OMX_IndexParamStandardComponentRole:
1097 {
1098 VALIDATE_OMX_PARAM_DATA(paramData, OMX_PARAM_COMPONENTROLETYPE);
1099 OMX_PARAM_COMPONENTROLETYPE *comp_role;
1100 comp_role = (OMX_PARAM_COMPONENTROLETYPE *) paramData;
1101 DEBUG_PRINT_LOW("set_parameter: OMX_IndexParamStandardComponentRole %s",
1102 comp_role->cRole);
1103
1104 if ((m_state == OMX_StateLoaded)&&
1105 !BITMASK_PRESENT(&m_flags,OMX_COMPONENT_IDLE_PENDING)) {
1106 DEBUG_PRINT_LOW("Set Parameter called in valid state");
1107 } else {
1108 DEBUG_PRINT_ERROR("Set Parameter called in Invalid State");
1109 return OMX_ErrorIncorrectStateOperation;
1110 }
1111
1112 if (!strncmp((char*)m_nkind, "OMX.qcom.video.encoder.avc",OMX_MAX_STRINGNAME_SIZE)) {
1113 if (!strncmp((char*)comp_role->cRole,"video_encoder.avc",OMX_MAX_STRINGNAME_SIZE)) {
1114 strlcpy((char*)m_cRole,"video_encoder.avc",OMX_MAX_STRINGNAME_SIZE);
1115 } else {
1116 DEBUG_PRINT_ERROR("ERROR: Setparameter: unknown Index %s", comp_role->cRole);
1117 eRet =OMX_ErrorUnsupportedSetting;
1118 }
1119 } else if (!strncmp((char*)m_nkind, "OMX.qcom.video.encoder.avc.secure",OMX_MAX_STRINGNAME_SIZE)) {
1120 if (!strncmp((char*)comp_role->cRole,"video_encoder.avc",OMX_MAX_STRINGNAME_SIZE)) {
1121 strlcpy((char*)m_cRole,"video_encoder.avc",OMX_MAX_STRINGNAME_SIZE);
1122 } else {
1123 DEBUG_PRINT_ERROR("ERROR: Setparameter: unknown Index %s\n", comp_role->cRole);
1124 eRet =OMX_ErrorUnsupportedSetting;
1125 }
1126 } else if (!strncmp((char*)m_nkind, "OMX.qcom.video.encoder.vp8",OMX_MAX_STRINGNAME_SIZE)) {
1127 if (!strncmp((const char*)comp_role->cRole,"video_encoder.vp8",OMX_MAX_STRINGNAME_SIZE)) {
1128 strlcpy((char*)m_cRole,"video_encoder.vp8",OMX_MAX_STRINGNAME_SIZE);
1129 } else {
1130 DEBUG_PRINT_ERROR("ERROR: Setparameter: unknown Index %s", comp_role->cRole);
1131 eRet =OMX_ErrorUnsupportedSetting;
1132 }
1133 } else if (!strncmp((char*)m_nkind, "OMX.qcom.video.encoder.hevc",OMX_MAX_STRINGNAME_SIZE) ||
1134 !strncmp((char*)m_nkind, "OMX.qcom.video.encoder.hevc.cq",OMX_MAX_STRINGNAME_SIZE)) {
1135 if (!strncmp((const char*)comp_role->cRole,"video_encoder.hevc",OMX_MAX_STRINGNAME_SIZE)) {
1136 strlcpy((char*)m_cRole,"video_encoder.hevc",OMX_MAX_STRINGNAME_SIZE);
1137 } else {
1138 DEBUG_PRINT_ERROR("ERROR: Setparameter: unknown Index %s", comp_role->cRole);
1139 eRet = OMX_ErrorUnsupportedSetting;
1140 }
1141 } else if (!strncmp((char*)m_nkind, "OMX.qcom.video.encoder.hevc.secure",OMX_MAX_STRINGNAME_SIZE)) {
1142 if (!strncmp((const char*)comp_role->cRole,"video_encoder.hevc",OMX_MAX_STRINGNAME_SIZE)) {
1143 strlcpy((char*)m_cRole,"video_encoder.hevc",OMX_MAX_STRINGNAME_SIZE);
1144 } else {
1145 DEBUG_PRINT_ERROR("ERROR: Setparameter: unknown Index %s", comp_role->cRole);
1146 eRet = OMX_ErrorUnsupportedSetting;
1147 }
1148 } else if (!strncmp((char*)m_nkind, "OMX.qcom.video.encoder.heic",OMX_MAX_STRINGNAME_SIZE)) {
1149 if (!strncmp((const char*)comp_role->cRole,"image_encoder.heic",OMX_MAX_STRINGNAME_SIZE)) {
1150 strlcpy((char*)m_cRole,"video_encoder.hevc",OMX_MAX_STRINGNAME_SIZE);
1151 } else {
1152 DEBUG_PRINT_ERROR("ERROR: Setparameter: unknown Index %s", comp_role->cRole);
1153 eRet = OMX_ErrorUnsupportedSetting;
1154 }
1155 } else if (!strncmp((char*)m_nkind, "OMX.qcom.video.encoder.tme", OMX_MAX_STRINGNAME_SIZE)) {
1156 if (!strncmp((const char*)comp_role->cRole,"video_encoder.tme",OMX_MAX_STRINGNAME_SIZE)) {
1157 strlcpy((char*)m_cRole,"video_encoder.tme",OMX_MAX_STRINGNAME_SIZE);
1158 } else {
1159 DEBUG_PRINT_ERROR("ERROR: Setparameter: unknown Index %s", comp_role->cRole);
1160 eRet = OMX_ErrorUnsupportedSetting;
1161 }
1162 }
1163 else {
1164 DEBUG_PRINT_ERROR("ERROR: Setparameter: unknown param %s", m_nkind);
1165 eRet = OMX_ErrorInvalidComponentName;
1166 }
1167 break;
1168 }
1169
1170 case OMX_IndexParamPriorityMgmt:
1171 {
1172 VALIDATE_OMX_PARAM_DATA(paramData, OMX_PRIORITYMGMTTYPE);
1173 DEBUG_PRINT_LOW("set_parameter: OMX_IndexParamPriorityMgmt");
1174 if (m_state != OMX_StateLoaded) {
1175 DEBUG_PRINT_ERROR("ERROR: Set Parameter called in Invalid State");
1176 return OMX_ErrorIncorrectStateOperation;
1177 }
1178 OMX_PRIORITYMGMTTYPE *priorityMgmtype = (OMX_PRIORITYMGMTTYPE*) paramData;
1179 DEBUG_PRINT_LOW("set_parameter: OMX_IndexParamPriorityMgmt %u",
1180 (unsigned int)priorityMgmtype->nGroupID);
1181
1182 DEBUG_PRINT_LOW("set_parameter: priorityMgmtype %u",
1183 (unsigned int)priorityMgmtype->nGroupPriority);
1184
1185 m_sPriorityMgmt.nGroupID = priorityMgmtype->nGroupID;
1186 m_sPriorityMgmt.nGroupPriority = priorityMgmtype->nGroupPriority;
1187
1188 break;
1189 }
1190
1191 case OMX_IndexParamCompBufferSupplier:
1192 {
1193 VALIDATE_OMX_PARAM_DATA(paramData, OMX_PARAM_BUFFERSUPPLIERTYPE);
1194 DEBUG_PRINT_LOW("set_parameter: OMX_IndexParamCompBufferSupplier");
1195 OMX_PARAM_BUFFERSUPPLIERTYPE *bufferSupplierType = (OMX_PARAM_BUFFERSUPPLIERTYPE*) paramData;
1196 DEBUG_PRINT_LOW("set_parameter: OMX_IndexParamCompBufferSupplier %d",
1197 bufferSupplierType->eBufferSupplier);
1198 if (bufferSupplierType->nPortIndex == 0 || bufferSupplierType->nPortIndex ==1)
1199 m_sInBufSupplier.eBufferSupplier = bufferSupplierType->eBufferSupplier;
1200
1201 else
1202
1203 eRet = OMX_ErrorBadPortIndex;
1204
1205 break;
1206
1207 }
1208 case OMX_GoogleAndroidIndexAllocateNativeHandle:
1209 {
1210 VALIDATE_OMX_PARAM_DATA(paramData, AllocateNativeHandleParams);
1211
1212 AllocateNativeHandleParams* allocateNativeHandleParams = (AllocateNativeHandleParams *) paramData;
1213
1214 if (!secure_session) {
1215 DEBUG_PRINT_INFO("WARN: Enable/Disable allocate-native-handle allowed only in secure session");
1216 eRet = OMX_ErrorUnsupportedSetting;
1217 break;
1218 } else if (allocateNativeHandleParams->nPortIndex != PORT_INDEX_OUT) {
1219 DEBUG_PRINT_INFO("WARN: Enable/Disable allocate-native-handle allowed only on Output port!");
1220 eRet = OMX_ErrorUnsupportedSetting;
1221 break;
1222 } else if (m_out_mem_ptr) {
1223 DEBUG_PRINT_INFO("WARN: Enable/Disable allocate-native-handle is not allowed since Output port is not free !");
1224 eRet = OMX_ErrorInvalidState;
1225 break;
1226 }
1227
1228 if (allocateNativeHandleParams != NULL) {
1229 allocate_native_handle = allocateNativeHandleParams->enable;
1230 }
1231 break;
1232 }
1233 case OMX_IndexParamVideoQuantization:
1234 {
1235 VALIDATE_OMX_PARAM_DATA(paramData, OMX_VIDEO_PARAM_QUANTIZATIONTYPE);
1236 DEBUG_PRINT_LOW("set_parameter: OMX_IndexParamVideoQuantization");
1237 OMX_VIDEO_PARAM_QUANTIZATIONTYPE *session_qp = (OMX_VIDEO_PARAM_QUANTIZATIONTYPE*) paramData;
1238 if (session_qp->nPortIndex == PORT_INDEX_OUT) {
1239 if (handle->venc_set_param(paramData, OMX_IndexParamVideoQuantization) != true) {
1240 return OMX_ErrorUnsupportedSetting;
1241 }
1242 m_sSessionQuantization.nQpI = session_qp->nQpI;
1243 m_sSessionQuantization.nQpP = session_qp->nQpP;
1244 m_sSessionQuantization.nQpB = session_qp->nQpB;
1245 m_QPSet = ENABLE_I_QP | ENABLE_P_QP | ENABLE_B_QP;
1246 } else {
1247 DEBUG_PRINT_ERROR("ERROR: Unsupported port Index for Session QP setting");
1248 eRet = OMX_ErrorBadPortIndex;
1249 }
1250 break;
1251 }
1252 case OMX_QcomIndexParamVideoIPBQPRange:
1253 {
1254 VALIDATE_OMX_PARAM_DATA(paramData, OMX_QCOM_VIDEO_PARAM_IPB_QPRANGETYPE);
1255 DEBUG_PRINT_LOW("set_parameter: OMX_QcomIndexParamVideoIPBQPRange");
1256 OMX_QCOM_VIDEO_PARAM_IPB_QPRANGETYPE *session_qp_range = (OMX_QCOM_VIDEO_PARAM_IPB_QPRANGETYPE*) paramData;
1257 if (session_qp_range->nPortIndex == PORT_INDEX_OUT) {
1258 if (handle->venc_set_param(paramData, (OMX_INDEXTYPE)OMX_QcomIndexParamVideoIPBQPRange) != true) {
1259 return OMX_ErrorUnsupportedSetting;
1260 }
1261 m_sSessionQPRange.minIQP = session_qp_range->minIQP;
1262 m_sSessionQPRange.maxIQP = session_qp_range->maxIQP;
1263 m_sSessionQPRange.minPQP = session_qp_range->minPQP;
1264 m_sSessionQPRange.maxPQP = session_qp_range->maxPQP;
1265 m_sSessionQPRange.minBQP = session_qp_range->minBQP;
1266 m_sSessionQPRange.maxBQP = session_qp_range->maxBQP;
1267 } else {
1268 DEBUG_PRINT_ERROR("ERROR: Unsupported port Index for QP range setting");
1269 eRet = OMX_ErrorBadPortIndex;
1270 }
1271 break;
1272 }
1273 case QOMX_IndexParamVideoInitialQp:
1274 {
1275 VALIDATE_OMX_PARAM_DATA(paramData, QOMX_EXTNINDEX_VIDEO_INITIALQP);
1276 DEBUG_PRINT_LOW("set_parameter: QOMX_IndexParamVideoInitialQp");
1277 QOMX_EXTNINDEX_VIDEO_INITIALQP *initial_qp = (QOMX_EXTNINDEX_VIDEO_INITIALQP*) paramData;
1278 if (initial_qp->nPortIndex == PORT_INDEX_OUT) {
1279 if (handle->venc_set_param(paramData, (OMX_INDEXTYPE)QOMX_IndexParamVideoInitialQp) != true) {
1280 return OMX_ErrorUnsupportedSetting;
1281 }
1282 m_sSessionQuantization.nQpI = initial_qp->nQpI;
1283 m_sSessionQuantization.nQpP = initial_qp->nQpP;
1284 m_sSessionQuantization.nQpB = initial_qp->nQpB;
1285 m_QPSet = initial_qp->bEnableInitQp;
1286 } else {
1287 DEBUG_PRINT_ERROR("ERROR: Unsupported port Index for initial QP setting");
1288 eRet = OMX_ErrorBadPortIndex;
1289 }
1290 break;
1291 }
1292 case OMX_QcomIndexPortDefn:
1293 {
1294 VALIDATE_OMX_PARAM_DATA(paramData, OMX_QCOM_PARAM_PORTDEFINITIONTYPE);
1295 OMX_QCOM_PARAM_PORTDEFINITIONTYPE* pParam =
1296 (OMX_QCOM_PARAM_PORTDEFINITIONTYPE*)paramData;
1297 DEBUG_PRINT_LOW("set_parameter: OMX_QcomIndexPortDefn");
1298 if (pParam->nPortIndex == (OMX_U32)PORT_INDEX_IN) {
1299 if (pParam->nMemRegion > OMX_QCOM_MemRegionInvalid &&
1300 pParam->nMemRegion < OMX_QCOM_MemRegionMax) {
1301 m_use_input_pmem = OMX_TRUE;
1302 } else {
1303 m_use_input_pmem = OMX_FALSE;
1304 }
1305 } else if (pParam->nPortIndex == (OMX_U32)PORT_INDEX_OUT) {
1306 if (pParam->nMemRegion > OMX_QCOM_MemRegionInvalid &&
1307 pParam->nMemRegion < OMX_QCOM_MemRegionMax) {
1308 m_use_output_pmem = OMX_TRUE;
1309 } else {
1310 m_use_output_pmem = OMX_FALSE;
1311 }
1312 } else {
1313 DEBUG_PRINT_ERROR("ERROR: SetParameter called on unsupported Port Index for QcomPortDefn");
1314 return OMX_ErrorBadPortIndex;
1315 }
1316 break;
1317 }
1318
1319 case OMX_IndexParamVideoErrorCorrection:
1320 {
1321 VALIDATE_OMX_PARAM_DATA(paramData, OMX_VIDEO_PARAM_ERRORCORRECTIONTYPE);
1322 DEBUG_PRINT_LOW("OMX_IndexParamVideoErrorCorrection");
1323 OMX_VIDEO_PARAM_ERRORCORRECTIONTYPE* pParam =
1324 (OMX_VIDEO_PARAM_ERRORCORRECTIONTYPE*)paramData;
1325 if (!handle->venc_set_param(paramData, OMX_IndexParamVideoErrorCorrection)) {
1326 DEBUG_PRINT_ERROR("ERROR: Request for setting Error Resilience failed");
1327 return OMX_ErrorUnsupportedSetting;
1328 }
1329 memcpy(&m_sErrorCorrection,pParam, sizeof(m_sErrorCorrection));
1330 break;
1331 }
1332 case OMX_QcomIndexParamVideoSliceSpacing:
1333 {
1334 VALIDATE_OMX_PARAM_DATA(paramData, QOMX_VIDEO_PARAM_SLICE_SPACING_TYPE);
1335 DEBUG_PRINT_LOW("OMX_QcomIndexParamVideoSliceSpacing");
1336 QOMX_VIDEO_PARAM_SLICE_SPACING_TYPE* pParam =
1337 (QOMX_VIDEO_PARAM_SLICE_SPACING_TYPE*)paramData;
1338 if (!handle->venc_set_param(paramData, (OMX_INDEXTYPE)OMX_QcomIndexParamVideoSliceSpacing)) {
1339 DEBUG_PRINT_ERROR("ERROR: Request for setting slice spacing failed");
1340 return OMX_ErrorUnsupportedSetting;
1341 }
1342 memcpy(&m_sSliceSpacing, pParam, sizeof(m_sSliceSpacing));
1343 break;
1344 }
1345 case OMX_IndexParamVideoIntraRefresh:
1346 {
1347 VALIDATE_OMX_PARAM_DATA(paramData, OMX_VIDEO_PARAM_INTRAREFRESHTYPE);
1348 DEBUG_PRINT_LOW("set_param:OMX_IndexParamVideoIntraRefresh");
1349 OMX_VIDEO_PARAM_INTRAREFRESHTYPE* pParam =
1350 (OMX_VIDEO_PARAM_INTRAREFRESHTYPE*)paramData;
1351 if (!handle->venc_set_param(paramData,OMX_IndexParamVideoIntraRefresh)) {
1352 DEBUG_PRINT_ERROR("ERROR: Request for setting intra refresh failed");
1353 return OMX_ErrorUnsupportedSetting;
1354 }
1355 memcpy(&m_sIntraRefresh, pParam, sizeof(m_sIntraRefresh));
1356 break;
1357 }
1358 #ifdef _ANDROID_ICS_
1359 case OMX_QcomIndexParamVideoMetaBufferMode:
1360 {
1361 VALIDATE_OMX_PARAM_DATA(paramData, StoreMetaDataInBuffersParams);
1362 StoreMetaDataInBuffersParams *pParam =
1363 (StoreMetaDataInBuffersParams*)paramData;
1364 DEBUG_PRINT_HIGH("set_parameter:OMX_QcomIndexParamVideoMetaBufferMode: "
1365 "port_index = %u, meta_mode = %d", (unsigned int)pParam->nPortIndex, pParam->bStoreMetaData);
1366 if (pParam->nPortIndex == PORT_INDEX_IN) {
1367 if (pParam->bStoreMetaData != meta_mode_enable) {
1368 if (!handle->venc_set_meta_mode(pParam->bStoreMetaData)) {
1369 DEBUG_PRINT_ERROR("ERROR: set Metabuffer mode %d fail",
1370 pParam->bStoreMetaData);
1371 return OMX_ErrorUnsupportedSetting;
1372 }
1373 meta_mode_enable = pParam->bStoreMetaData;
1374 if (meta_mode_enable) {
1375 m_sInPortDef.nBufferCountActual = m_sInPortDef.nBufferCountMin;
1376 if (handle->venc_set_param(&m_sInPortDef,OMX_IndexParamPortDefinition) != true) {
1377 DEBUG_PRINT_ERROR("ERROR: venc_set_param input failed");
1378 return OMX_ErrorUnsupportedSetting;
1379 }
1380 } else {
1381 /*TODO: reset encoder driver Meta mode*/
1382 dev_get_buf_req (&m_sOutPortDef.nBufferCountMin,
1383 &m_sOutPortDef.nBufferCountActual,
1384 &m_sOutPortDef.nBufferSize,
1385 m_sOutPortDef.nPortIndex);
1386 }
1387 }
1388 } else if (pParam->nPortIndex == PORT_INDEX_OUT && secure_session) {
1389 DEBUG_PRINT_INFO("WARN: set_parameter: metamode is "
1390 "valid for input port only in secure session");
1391 return OMX_ErrorUnsupportedSetting;
1392 } else {
1393 DEBUG_PRINT_INFO("WARN: set_parameter: metamode is "
1394 "valid for input port only");
1395 eRet = OMX_ErrorUnsupportedIndex;
1396 }
1397 }
1398 break;
1399 #endif
1400 case OMX_QcomIndexParamIndexExtraDataType:
1401 {
1402 VALIDATE_OMX_PARAM_DATA(paramData, QOMX_INDEXEXTRADATATYPE);
1403 DEBUG_PRINT_HIGH("set_parameter: OMX_QcomIndexParamIndexExtraDataType");
1404 QOMX_INDEXEXTRADATATYPE *pParam = (QOMX_INDEXEXTRADATATYPE *)paramData;
1405 bool enable = false;
1406 OMX_U32 mask = 0;
1407
1408 if (pParam->nIndex == (OMX_INDEXTYPE)OMX_ExtraDataVideoEncoderSliceInfo) {
1409 if (pParam->nPortIndex == PORT_INDEX_OUT) {
1410 mask = VENC_EXTRADATA_SLICEINFO;
1411
1412 DEBUG_PRINT_HIGH("SliceInfo extradata %s",
1413 ((pParam->bEnabled == OMX_TRUE) ? "enabled" : "disabled"));
1414 } else {
1415 DEBUG_PRINT_ERROR("set_parameter: Slice information is "
1416 "valid for output port only");
1417 eRet = OMX_ErrorUnsupportedIndex;
1418 break;
1419 }
1420 } else if (pParam->nIndex == (OMX_INDEXTYPE)OMX_ExtraDataVideoEncoderMBInfo) {
1421 if (pParam->nPortIndex == PORT_INDEX_OUT) {
1422 mask = VENC_EXTRADATA_MBINFO;
1423
1424 DEBUG_PRINT_HIGH("MBInfo extradata %s",
1425 ((pParam->bEnabled == OMX_TRUE) ? "enabled" : "disabled"));
1426 } else {
1427 DEBUG_PRINT_ERROR("set_parameter: MB information is "
1428 "valid for output port only");
1429 eRet = OMX_ErrorUnsupportedIndex;
1430 break;
1431 }
1432 } else if (pParam->nIndex == (OMX_INDEXTYPE)OMX_ExtraDataFrameDimension) {
1433 if (pParam->nPortIndex == PORT_INDEX_IN) {
1434 mask = VENC_EXTRADATA_FRAMEDIMENSION;
1435 DEBUG_PRINT_HIGH("Frame dimension extradata %s",
1436 ((pParam->bEnabled == OMX_TRUE) ? "enabled" : "disabled"));
1437 } else {
1438 DEBUG_PRINT_ERROR("set_parameter: Frame Dimension is "
1439 "valid for input port only");
1440 eRet = OMX_ErrorUnsupportedIndex;
1441 break;
1442 }
1443 } else if (pParam->nIndex == (OMX_INDEXTYPE)OMX_QTIIndexParamVQZipSEIExtraData) {
1444 if (pParam->nPortIndex == PORT_INDEX_IN) {
1445 mask = VENC_EXTRADATA_VQZIP;
1446 DEBUG_PRINT_HIGH("VQZIP extradata %s",
1447 ((pParam->bEnabled == OMX_TRUE) ? "enabled" : "disabled"));
1448 } else {
1449 DEBUG_PRINT_ERROR("set_parameter: VQZIP is "
1450 "valid for input port only");
1451 eRet = OMX_ErrorUnsupportedIndex;
1452 break;
1453 }
1454 } else if (pParam->nIndex == (OMX_INDEXTYPE)OMX_ExtraDataVideoLTRInfo) {
1455 if (pParam->nPortIndex == PORT_INDEX_OUT) {
1456 if (pParam->bEnabled == OMX_TRUE)
1457 mask = VENC_EXTRADATA_LTRINFO;
1458
1459 DEBUG_PRINT_HIGH("LTRInfo extradata %s",
1460 ((pParam->bEnabled == OMX_TRUE) ? "enabled" : "disabled"));
1461 } else {
1462 DEBUG_PRINT_ERROR("set_parameter: LTR information is "
1463 "valid for output port only");
1464 eRet = OMX_ErrorUnsupportedIndex;
1465 break;
1466 }
1467 } else if (pParam->nIndex == (OMX_INDEXTYPE)OMX_QTIIndexParamVideoEnableRoiInfo) {
1468 if (pParam->nPortIndex == PORT_INDEX_IN) {
1469 if (pParam->bEnabled == OMX_TRUE)
1470 mask = VENC_EXTRADATA_ROI;
1471
1472 DEBUG_PRINT_HIGH("ROIInfo extradata %s",
1473 ((pParam->bEnabled == OMX_TRUE) ? "enabled" : "disabled"));
1474 } else {
1475 DEBUG_PRINT_ERROR("set_parameter: ROI information is "
1476 "valid for input port only");
1477 eRet = OMX_ErrorUnsupportedIndex;
1478 break;
1479 }
1480 } else {
1481 DEBUG_PRINT_ERROR("set_parameter: unsupported extrdata index (%x)",
1482 pParam->nIndex);
1483 eRet = OMX_ErrorUnsupportedIndex;
1484 break;
1485 }
1486
1487
1488 if (pParam->bEnabled == OMX_TRUE)
1489 m_sExtraData |= mask;
1490 else
1491 m_sExtraData &= ~mask;
1492
1493 enable = !!(m_sExtraData & mask);
1494 if (handle->venc_set_param(&enable,
1495 (OMX_INDEXTYPE)pParam->nIndex) != true) {
1496 DEBUG_PRINT_ERROR("ERROR: Setting Extradata (%x) failed", pParam->nIndex);
1497 return OMX_ErrorUnsupportedSetting;
1498 }
1499
1500 if (pParam->nPortIndex == PORT_INDEX_IN) {
1501 m_sInPortDef.nPortIndex = PORT_INDEX_IN;
1502 dev_get_buf_req(&m_sInPortDef.nBufferCountMin,
1503 &m_sInPortDef.nBufferCountActual,
1504 &m_sInPortDef.nBufferSize,
1505 m_sInPortDef.nPortIndex);
1506 DEBUG_PRINT_HIGH("updated in_buf_req: buffer cnt=%u, "
1507 "count min=%u, buffer size=%u",
1508 (unsigned int)m_sInPortDef.nBufferCountActual,
1509 (unsigned int)m_sInPortDef.nBufferCountMin,
1510 (unsigned int)m_sInPortDef.nBufferSize);
1511
1512 } else {
1513 m_sOutPortDef.nPortIndex = PORT_INDEX_OUT;
1514 dev_get_buf_req(&m_sOutPortDef.nBufferCountMin,
1515 &m_sOutPortDef.nBufferCountActual,
1516 &m_sOutPortDef.nBufferSize,
1517 m_sOutPortDef.nPortIndex);
1518 DEBUG_PRINT_HIGH("updated out_buf_req: buffer cnt=%u, "
1519 "count min=%u, buffer size=%u",
1520 (unsigned int)m_sOutPortDef.nBufferCountActual,
1521 (unsigned int)m_sOutPortDef.nBufferCountMin,
1522 (unsigned int)m_sOutPortDef.nBufferSize);
1523 }
1524 break;
1525 }
1526 case OMX_QTIIndexParamVideoClientExtradata:
1527 {
1528 VALIDATE_OMX_PARAM_DATA(paramData, QOMX_EXTRADATA_ENABLE);
1529 DEBUG_PRINT_LOW("set_parameter: OMX_QTIIndexParamVideoClientExtradata");
1530 QOMX_EXTRADATA_ENABLE *pParam = (QOMX_EXTRADATA_ENABLE *)paramData;
1531
1532 if (m_state != OMX_StateLoaded) {
1533 DEBUG_PRINT_ERROR("Set Parameter called in Invalid state");
1534 return OMX_ErrorIncorrectStateOperation;
1535 }
1536
1537 if (pParam->nPortIndex == PORT_INDEX_EXTRADATA_OUT) {
1538 m_client_out_extradata_info.enable_client_extradata(pParam->bEnable);
1539 } else if (pParam->nPortIndex == PORT_INDEX_EXTRADATA_IN) {
1540 m_client_in_extradata_info.enable_client_extradata(pParam->bEnable);
1541 } else {
1542 DEBUG_PRINT_ERROR("Incorrect portIndex - %d", pParam->nPortIndex);
1543 eRet = OMX_ErrorUnsupportedIndex;
1544 }
1545 break;
1546 }
1547 case QOMX_IndexParamVideoLTRCount:
1548 {
1549 VALIDATE_OMX_PARAM_DATA(paramData, QOMX_VIDEO_PARAM_LTRCOUNT_TYPE);
1550 QOMX_VIDEO_PARAM_LTRCOUNT_TYPE* pParam =
1551 (QOMX_VIDEO_PARAM_LTRCOUNT_TYPE*)paramData;
1552 if (!handle->venc_set_param(paramData, (OMX_INDEXTYPE)QOMX_IndexParamVideoLTRCount)) {
1553 DEBUG_PRINT_ERROR("ERROR: Setting LTR count failed");
1554 return OMX_ErrorUnsupportedSetting;
1555 }
1556 memcpy(&m_sParamLTRCount, pParam, sizeof(m_sParamLTRCount));
1557 break;
1558 }
1559 case OMX_QcomIndexParamVideoMaxAllowedBitrateCheck:
1560 {
1561 VALIDATE_OMX_PARAM_DATA(paramData, QOMX_EXTNINDEX_PARAMTYPE);
1562 QOMX_EXTNINDEX_PARAMTYPE* pParam =
1563 (QOMX_EXTNINDEX_PARAMTYPE*)paramData;
1564 if (pParam->nPortIndex == PORT_INDEX_OUT) {
1565 handle->m_max_allowed_bitrate_check =
1566 ((pParam->bEnable == OMX_TRUE) ? true : false);
1567 DEBUG_PRINT_HIGH("set_parameter: max allowed bitrate check %s",
1568 ((pParam->bEnable == OMX_TRUE) ? "enabled" : "disabled"));
1569 } else {
1570 DEBUG_PRINT_ERROR("ERROR: OMX_QcomIndexParamVideoMaxAllowedBitrateCheck "
1571 " called on wrong port(%u)", (unsigned int)pParam->nPortIndex);
1572 return OMX_ErrorBadPortIndex;
1573 }
1574 break;
1575 }
1576 case OMX_QcomIndexEnableSliceDeliveryMode:
1577 {
1578 VALIDATE_OMX_PARAM_DATA(paramData, QOMX_EXTNINDEX_PARAMTYPE);
1579 QOMX_EXTNINDEX_PARAMTYPE* pParam =
1580 (QOMX_EXTNINDEX_PARAMTYPE*)paramData;
1581 if (pParam->nPortIndex == PORT_INDEX_OUT) {
1582 if (!handle->venc_set_param(paramData,
1583 (OMX_INDEXTYPE)OMX_QcomIndexEnableSliceDeliveryMode)) {
1584 DEBUG_PRINT_ERROR("ERROR: Request for setting slice delivery mode failed");
1585 return OMX_ErrorUnsupportedSetting;
1586 }
1587 } else {
1588 DEBUG_PRINT_ERROR("ERROR: OMX_QcomIndexEnableSliceDeliveryMode "
1589 "called on wrong port(%u)", (unsigned int)pParam->nPortIndex);
1590 return OMX_ErrorBadPortIndex;
1591 }
1592 break;
1593 }
1594 case OMX_QcomIndexParamSequenceHeaderWithIDR:
1595 {
1596 VALIDATE_OMX_PARAM_DATA(paramData, PrependSPSPPSToIDRFramesParams);
1597 if(!handle->venc_set_param(paramData,
1598 (OMX_INDEXTYPE)OMX_QcomIndexParamSequenceHeaderWithIDR)) {
1599 DEBUG_PRINT_ERROR("%s: %s",
1600 "OMX_QComIndexParamSequenceHeaderWithIDR:",
1601 "request for inband sps/pps failed.");
1602 return OMX_ErrorUnsupportedSetting;
1603 }
1604 memcpy(&m_sPrependSPSPPS, paramData, sizeof(m_sPrependSPSPPS));
1605 break;
1606 }
1607 case OMX_QcomIndexParamAUDelimiter:
1608 {
1609 VALIDATE_OMX_PARAM_DATA(paramData, OMX_QCOM_VIDEO_CONFIG_AUD);
1610 if(!handle->venc_set_param(paramData,
1611 (OMX_INDEXTYPE)OMX_QcomIndexParamAUDelimiter)) {
1612 DEBUG_PRINT_ERROR("%s: %s",
1613 "OMX_QComIndexParamAUDelimiter:",
1614 "request for AU Delimiters failed.");
1615 return OMX_ErrorUnsupportedSetting;
1616 }
1617 break;
1618 }
1619 case OMX_QcomIndexHierarchicalStructure:
1620 {
1621 VALIDATE_OMX_PARAM_DATA(paramData, QOMX_VIDEO_HIERARCHICALLAYERS);
1622 QOMX_VIDEO_HIERARCHICALLAYERS* pParam =
1623 (QOMX_VIDEO_HIERARCHICALLAYERS*)paramData;
1624 DEBUG_PRINT_LOW("OMX_QcomIndexHierarchicalStructure");
1625 if (pParam->nPortIndex == PORT_INDEX_OUT) {
1626 if (!handle->venc_set_param(paramData,
1627 (OMX_INDEXTYPE)OMX_QcomIndexHierarchicalStructure)) {
1628 DEBUG_PRINT_ERROR("ERROR: Request for setting PlusPType failed");
1629 return OMX_ErrorUnsupportedSetting;
1630 }
1631 if((pParam->eHierarchicalCodingType == QOMX_HIERARCHICALCODING_B) && pParam->nNumLayers)
1632 hier_b_enabled = true;
1633 m_sHierLayers.nNumLayers = pParam->nNumLayers;
1634 m_sHierLayers.eHierarchicalCodingType = pParam->eHierarchicalCodingType;
1635 } else {
1636 DEBUG_PRINT_ERROR("ERROR: OMX_QcomIndexHierarchicalStructure called on wrong port(%u)",
1637 (unsigned int)pParam->nPortIndex);
1638 return OMX_ErrorBadPortIndex;
1639 }
1640 break;
1641
1642 }
1643 case OMX_QcomIndexParamH264VUITimingInfo:
1644 {
1645 VALIDATE_OMX_PARAM_DATA(paramData, OMX_QCOM_VIDEO_PARAM_VUI_TIMING_INFO);
1646 if (!handle->venc_set_param(paramData,
1647 (OMX_INDEXTYPE) OMX_QcomIndexParamH264VUITimingInfo)) {
1648 DEBUG_PRINT_ERROR("ERROR: Setting VUI timing info");
1649 return OMX_ErrorUnsupportedSetting;
1650 }
1651 break;
1652 }
1653 case OMX_QcomIndexParamPeakBitrate:
1654 {
1655 VALIDATE_OMX_PARAM_DATA(paramData, OMX_QCOM_VIDEO_PARAM_PEAK_BITRATE);
1656 if (!handle->venc_set_param(paramData,
1657 (OMX_INDEXTYPE) OMX_QcomIndexParamPeakBitrate)) {
1658 DEBUG_PRINT_ERROR("ERROR: Setting peak bitrate");
1659 return OMX_ErrorUnsupportedSetting;
1660 }
1661 break;
1662 }
1663 case OMX_QcomIndexParamSetMVSearchrange:
1664 {
1665 if (!handle->venc_set_param(paramData,
1666 (OMX_INDEXTYPE) OMX_QcomIndexParamSetMVSearchrange)) {
1667 DEBUG_PRINT_ERROR("ERROR: Setting Searchrange");
1668 return OMX_ErrorUnsupportedSetting;
1669 }
1670 break;
1671 }
1672 case OMX_QcomIndexParamBatchSize:
1673 {
1674 VALIDATE_OMX_PARAM_DATA(paramData, OMX_PARAM_U32TYPE);
1675 if(!handle->venc_set_param(paramData,
1676 (OMX_INDEXTYPE)OMX_QcomIndexParamBatchSize)) {
1677 DEBUG_PRINT_ERROR("Attempting to set batch size failed");
1678 return OMX_ErrorUnsupportedSetting;
1679 }
1680 break;
1681 }
1682 case OMX_QcomIndexConfigH264EntropyCodingCabac:
1683 {
1684 VALIDATE_OMX_PARAM_DATA(paramData, QOMX_VIDEO_H264ENTROPYCODINGTYPE);
1685 if(!handle->venc_set_param(paramData,
1686 (OMX_INDEXTYPE)OMX_QcomIndexConfigH264EntropyCodingCabac)) {
1687 DEBUG_PRINT_ERROR("Attempting to set Entropy failed");
1688 return OMX_ErrorUnsupportedSetting;
1689 }
1690 break;
1691 }
1692 case OMX_QTIIndexParamVQZIPSEIType:
1693 {
1694 VALIDATE_OMX_PARAM_DATA(paramData, OMX_QTI_VIDEO_PARAM_VQZIP_SEI_TYPE);
1695 if (!handle->venc_set_param(paramData,
1696 (OMX_INDEXTYPE) OMX_QTIIndexParamVQZIPSEIType)) {
1697 DEBUG_PRINT_ERROR("ERROR: Setting VQZIP SEI type");
1698 return OMX_ErrorUnsupportedSetting;
1699 }
1700 m_sExtraData |= VENC_EXTRADATA_VQZIP;
1701 break;
1702 }
1703 case OMX_QcomIndexParamVencAspectRatio:
1704 {
1705 VALIDATE_OMX_PARAM_DATA(paramData, QOMX_EXTNINDEX_VIDEO_VENC_SAR);
1706 if (!handle->venc_set_param(paramData,
1707 (OMX_INDEXTYPE)OMX_QcomIndexParamVencAspectRatio)) {
1708 DEBUG_PRINT_ERROR("ERROR: Setting OMX_QcomIndexParamVencAspectRatio failed");
1709 return OMX_ErrorUnsupportedSetting;
1710 }
1711 memcpy(&m_sSar, paramData, sizeof(m_sSar));
1712 break;
1713 }
1714 case OMX_QTIIndexParamVideoEnableRoiInfo:
1715 {
1716 if (!handle->venc_set_param(paramData,
1717 (OMX_INDEXTYPE)OMX_QTIIndexParamVideoEnableRoiInfo)) {
1718 DEBUG_PRINT_ERROR("ERROR: Setting OMX_QTIIndexParamVideoEnableRoiInfo failed");
1719 return OMX_ErrorUnsupportedSetting;
1720 }
1721 m_sExtraData |= VENC_EXTRADATA_ROI;
1722 break;
1723 }
1724 case OMX_IndexParamAndroidVideoTemporalLayering:
1725 {
1726 VALIDATE_OMX_PARAM_DATA(paramData, OMX_VIDEO_PARAM_ANDROID_TEMPORALLAYERINGTYPE);
1727 if (!handle->venc_set_param(paramData,
1728 (OMX_INDEXTYPE)OMX_IndexParamAndroidVideoTemporalLayering)) {
1729 DEBUG_PRINT_ERROR("Failed to configure temporal layers");
1730 return OMX_ErrorUnsupportedSetting;
1731 }
1732 // save the actual configuration applied
1733 memcpy(&m_sParamTemporalLayers, paramData, sizeof(m_sParamTemporalLayers));
1734 // keep the config data in sync
1735 m_sConfigTemporalLayers.ePattern = m_sParamTemporalLayers.ePattern;
1736 m_sConfigTemporalLayers.nBLayerCountActual = m_sParamTemporalLayers.nBLayerCountActual;
1737 m_sConfigTemporalLayers.nPLayerCountActual = m_sParamTemporalLayers.nPLayerCountActual;
1738 m_sConfigTemporalLayers.bBitrateRatiosSpecified = m_sParamTemporalLayers.bBitrateRatiosSpecified;
1739 memcpy(&m_sConfigTemporalLayers.nBitrateRatios[0],
1740 &m_sParamTemporalLayers.nBitrateRatios[0],
1741 OMX_VIDEO_ANDROID_MAXTEMPORALLAYERS * sizeof(OMX_U32));
1742 break;
1743 }
1744 case OMX_QTIIndexParamDisablePQ:
1745 {
1746 VALIDATE_OMX_PARAM_DATA(paramData, QOMX_DISABLETYPE);
1747 handle->venc_set_param(paramData,
1748 (OMX_INDEXTYPE)OMX_QTIIndexParamDisablePQ);
1749 break;
1750 }
1751 case OMX_QTIIndexParamIframeSizeType:
1752 {
1753 VALIDATE_OMX_PARAM_DATA(paramData, QOMX_VIDEO_IFRAMESIZE);
1754 if (!handle->venc_set_param(paramData,
1755 (OMX_INDEXTYPE)OMX_QTIIndexParamIframeSizeType)) {
1756 DEBUG_PRINT_ERROR("ERROR: Setting OMX_QTIIndexParamIframeSizeType failed");
1757 return OMX_ErrorUnsupportedSetting;
1758 }
1759 break;
1760 }
1761 case OMX_QTIIndexParamEnableAVTimerTimestamps:
1762 {
1763 VALIDATE_OMX_PARAM_DATA(paramData, QOMX_ENABLETYPE);
1764 if (!handle->venc_set_param(paramData,
1765 (OMX_INDEXTYPE)OMX_QTIIndexParamEnableAVTimerTimestamps)) {
1766 DEBUG_PRINT_ERROR("ERROR: Setting OMX_QTIIndexParamEnableAVTimerTimestamps failed");
1767 return OMX_ErrorUnsupportedSetting;
1768 }
1769 memcpy(&m_sParamAVTimerTimestampMode, paramData, sizeof(QOMX_ENABLETYPE));
1770 break;
1771 }
1772 case OMX_QcomIndexParamVideoDownScalar:
1773 {
1774 VALIDATE_OMX_PARAM_DATA(paramData, QOMX_INDEXDOWNSCALAR);
1775 if(!handle->venc_set_param(paramData,
1776 (OMX_INDEXTYPE)OMX_QcomIndexParamVideoDownScalar)) {
1777 DEBUG_PRINT_ERROR("ERROR: Setting OMX_QcomIndexParamVideodownscalar failed");
1778 return OMX_ErrorUnsupportedSetting;
1779 }
1780 memcpy(&m_sParamDownScalar, paramData, sizeof(QOMX_INDEXDOWNSCALAR));
1781 break;
1782 }
1783 case OMX_QcomIndexParamVencControlInputQueue:
1784 {
1785 VALIDATE_OMX_PARAM_DATA(paramData, QOMX_ENABLETYPE);
1786 memcpy(&m_sParamControlInputQueue, paramData, sizeof(QOMX_ENABLETYPE));
1787 break;
1788 }
1789 case OMX_QTIIndexParamLowLatencyMode:
1790 {
1791 VALIDATE_OMX_PARAM_DATA(paramData, QOMX_EXTNINDEX_VIDEO_LOW_LATENCY_MODE);
1792 if (!handle->venc_set_param(paramData,
1793 (OMX_INDEXTYPE)OMX_QTIIndexParamLowLatencyMode)) {
1794 DEBUG_PRINT_ERROR("ERROR: Setting OMX_QTIIndexParamLowLatencyMode failed");
1795 return OMX_ErrorUnsupportedSetting;
1796 }
1797 memcpy(&m_sParamLowLatency, paramData, sizeof(QOMX_EXTNINDEX_VIDEO_LOW_LATENCY_MODE));
1798 break;
1799 }
1800 case OMX_QTIIndexParamColorSpaceConversion:
1801 {
1802 VALIDATE_OMX_PARAM_DATA(paramData, QOMX_ENABLETYPE);
1803 if (!handle->venc_set_param(paramData,
1804 (OMX_INDEXTYPE)OMX_QTIIndexParamColorSpaceConversion)) {
1805 DEBUG_PRINT_ERROR("ERROR: Setting OMX_QTIIndexParamColorSpaceConversion failed");
1806 return OMX_ErrorUnsupportedSetting;
1807 }
1808 memcpy(&m_sParamColorSpaceConversion, paramData, sizeof(QOMX_ENABLETYPE));
1809 break;
1810 }
1811 case OMX_QTIIndexParamEnableLinearColorFormat:
1812 {
1813 VALIDATE_OMX_PARAM_DATA(paramData, QOMX_ENABLETYPE);
1814 if (!handle->venc_set_param(paramData,
1815 (OMX_INDEXTYPE)OMX_QTIIndexParamEnableLinearColorFormat)) {
1816 DEBUG_PRINT_ERROR("ERROR: Setting OMX_QTIIndexParamEnableLinearColorFormat failed");
1817 return OMX_ErrorUnsupportedSetting;
1818 }
1819 memcpy(&m_sParamLinearColorFormat, paramData, sizeof(QOMX_ENABLETYPE));
1820 break;
1821 }
1822 case OMX_QTIIndexParamVideoEnableBlur:
1823 {
1824 VALIDATE_OMX_PARAM_DATA(paramData, OMX_QTI_VIDEO_CONFIG_BLURINFO);
1825 if (!handle->venc_set_param(paramData,
1826 (OMX_INDEXTYPE)OMX_QTIIndexParamVideoEnableBlur)) {
1827 DEBUG_PRINT_ERROR("ERROR: Setting OMX_QTIIndexParamVideoEnableBlur failed");
1828 return OMX_ErrorUnsupportedSetting;
1829 }
1830 memcpy(&m_blurInfo, paramData, sizeof(OMX_QTI_VIDEO_CONFIG_BLURINFO));
1831 break;
1832 }
1833 case OMX_QTIIndexParamNativeRecorder:
1834 {
1835 VALIDATE_OMX_PARAM_DATA(paramData, QOMX_ENABLETYPE);
1836 if (!handle->venc_set_param(paramData,
1837 (OMX_INDEXTYPE)OMX_QTIIndexParamNativeRecorder)) {
1838 DEBUG_PRINT_ERROR("ERROR: Setting OMX_QTIIndexParamNativeRecorder failed");
1839 return OMX_ErrorUnsupportedSetting;
1840 }
1841 memcpy(&m_sParamNativeRecorder, paramData, sizeof(QOMX_ENABLETYPE));
1842 break;
1843 }
1844 case OMX_IndexParamVideoSliceFMO:
1845 default:
1846 {
1847 DEBUG_PRINT_ERROR("ERROR: Setparameter: unknown param %d", paramIndex);
1848 eRet = OMX_ErrorUnsupportedIndex;
1849 break;
1850 }
1851 }
1852 return eRet;
1853 }
1854
update_profile_level()1855 bool omx_venc::update_profile_level()
1856 {
1857 OMX_U32 eProfile, eLevel;
1858
1859 if (!handle->venc_get_profile_level(&eProfile,&eLevel)) {
1860 DEBUG_PRINT_INFO("WARN: Failed to update the profile_level");
1861 return false;
1862 }
1863
1864 m_sParamProfileLevel.eProfile = (OMX_VIDEO_AVCPROFILETYPE)eProfile;
1865 m_sParamProfileLevel.eLevel = (OMX_VIDEO_AVCLEVELTYPE)eLevel;
1866
1867 if (!strncmp((char *)m_nkind, "OMX.qcom.video.encoder.avc",\
1868 OMX_MAX_STRINGNAME_SIZE)) {
1869 m_sParamAVC.eProfile = (OMX_VIDEO_AVCPROFILETYPE)eProfile;
1870 m_sParamAVC.eLevel = (OMX_VIDEO_AVCLEVELTYPE)eLevel;
1871 DEBUG_PRINT_LOW("AVC profile = %d, level = %d", m_sParamAVC.eProfile,
1872 m_sParamAVC.eLevel);
1873 } else if (!strncmp((char *)m_nkind, "OMX.qcom.video.encoder.avc.secure",\
1874 OMX_MAX_STRINGNAME_SIZE)) {
1875 m_sParamAVC.eProfile = (OMX_VIDEO_AVCPROFILETYPE)eProfile;
1876 m_sParamAVC.eLevel = (OMX_VIDEO_AVCLEVELTYPE)eLevel;
1877 DEBUG_PRINT_LOW("\n AVC profile = %d, level = %d", m_sParamAVC.eProfile,
1878 m_sParamAVC.eLevel);
1879 }
1880 else if (!strncmp((char *)m_nkind, "OMX.qcom.video.encoder.vp8",\
1881 OMX_MAX_STRINGNAME_SIZE)) {
1882 m_sParamVP8.eProfile = (OMX_VIDEO_VP8PROFILETYPE)eProfile;
1883 m_sParamVP8.eLevel = (OMX_VIDEO_VP8LEVELTYPE)eLevel;
1884 DEBUG_PRINT_LOW("VP8 profile = %d, level = %d", m_sParamVP8.eProfile,
1885 m_sParamVP8.eLevel);
1886 }
1887 else if (!strncmp((char *)m_nkind, "OMX.qcom.video.encoder.hevc",\
1888 OMX_MAX_STRINGNAME_SIZE) ||
1889 !strncmp((char *)m_nkind, "OMX.qcom.video.encoder.heic",\
1890 OMX_MAX_STRINGNAME_SIZE)) {
1891 m_sParamHEVC.eProfile = (OMX_VIDEO_HEVCPROFILETYPE)eProfile;
1892 m_sParamHEVC.eLevel = (OMX_VIDEO_HEVCLEVELTYPE)eLevel;
1893 DEBUG_PRINT_LOW("HEVC profile = %d, level = %d", m_sParamHEVC.eProfile,
1894 m_sParamHEVC.eLevel);
1895 }
1896
1897 return true;
1898 }
1899 /* ======================================================================
1900 FUNCTION
1901 omx_video::SetConfig
1902
1903 DESCRIPTION
1904 OMX Set Config method implementation
1905
1906 PARAMETERS
1907 <TBD>.
1908
1909 RETURN VALUE
1910 OMX Error None if successful.
1911 ========================================================================== */
set_config(OMX_IN OMX_HANDLETYPE hComp,OMX_IN OMX_INDEXTYPE configIndex,OMX_IN OMX_PTR configData)1912 OMX_ERRORTYPE omx_venc::set_config(OMX_IN OMX_HANDLETYPE hComp,
1913 OMX_IN OMX_INDEXTYPE configIndex,
1914 OMX_IN OMX_PTR configData)
1915 {
1916 (void)hComp;
1917 if (configData == NULL) {
1918 DEBUG_PRINT_ERROR("ERROR: param is null");
1919 return OMX_ErrorBadParameter;
1920 }
1921
1922 if (m_state == OMX_StateInvalid) {
1923 DEBUG_PRINT_ERROR("ERROR: config called in Invalid state");
1924 return OMX_ErrorIncorrectStateOperation;
1925 }
1926
1927 if (reject_config_for_TME_mode(configIndex)) {
1928 DEBUG_PRINT_ERROR("ERROR: config 0x%x rejected in TME mode", configIndex);
1929 return OMX_ErrorNone;
1930 }
1931
1932 // params will be validated prior to venc_init
1933 switch ((int)configIndex) {
1934 case OMX_IndexConfigVideoBitrate:
1935 {
1936 VALIDATE_OMX_PARAM_DATA(configData, OMX_VIDEO_CONFIG_BITRATETYPE);
1937 OMX_VIDEO_CONFIG_BITRATETYPE* pParam =
1938 reinterpret_cast<OMX_VIDEO_CONFIG_BITRATETYPE*>(configData);
1939 DEBUG_PRINT_HIGH("set_config(): OMX_IndexConfigVideoBitrate (%u)", (unsigned int)pParam->nEncodeBitrate);
1940
1941 if (pParam->nPortIndex == PORT_INDEX_OUT) {
1942 if (handle->venc_set_config(configData, OMX_IndexConfigVideoBitrate) != true) {
1943 DEBUG_PRINT_ERROR("ERROR: Setting OMX_IndexConfigVideoBitrate failed");
1944 return OMX_ErrorUnsupportedSetting;
1945 }
1946
1947 m_sConfigBitrate.nEncodeBitrate = pParam->nEncodeBitrate;
1948 m_sParamBitrate.nTargetBitrate = pParam->nEncodeBitrate;
1949 m_sOutPortDef.format.video.nBitrate = pParam->nEncodeBitrate;
1950 } else {
1951 DEBUG_PRINT_ERROR("ERROR: Unsupported port index: %u", (unsigned int)pParam->nPortIndex);
1952 return OMX_ErrorBadPortIndex;
1953 }
1954 break;
1955 }
1956 case OMX_IndexConfigVideoFramerate:
1957 {
1958 VALIDATE_OMX_PARAM_DATA(configData, OMX_CONFIG_FRAMERATETYPE);
1959 OMX_CONFIG_FRAMERATETYPE* pParam =
1960 reinterpret_cast<OMX_CONFIG_FRAMERATETYPE*>(configData);
1961 DEBUG_PRINT_HIGH("set_config(): OMX_IndexConfigVideoFramerate (0x%x)", (unsigned int)pParam->xEncodeFramerate);
1962
1963 if (pParam->nPortIndex == PORT_INDEX_OUT) {
1964 if (handle->venc_set_config(configData, OMX_IndexConfigVideoFramerate) != true) {
1965 DEBUG_PRINT_ERROR("ERROR: Setting OMX_IndexConfigVideoFramerate failed");
1966 return OMX_ErrorUnsupportedSetting;
1967 }
1968
1969 m_sConfigFramerate.xEncodeFramerate = pParam->xEncodeFramerate;
1970 m_sOutPortDef.format.video.xFramerate = pParam->xEncodeFramerate;
1971 m_sOutPortFormat.xFramerate = pParam->xEncodeFramerate;
1972 /*
1973 * Frame rate can change buffer requirements. If query is not allowed,
1974 * failure is not FATAL here.
1975 */
1976 dev_get_buf_req(&m_sInPortDef.nBufferCountMin,
1977 &m_sInPortDef.nBufferCountActual,
1978 &m_sInPortDef.nBufferSize,
1979 m_sInPortDef.nPortIndex);
1980 } else {
1981 DEBUG_PRINT_ERROR("ERROR: Unsupported port index: %u", (unsigned int)pParam->nPortIndex);
1982 return OMX_ErrorBadPortIndex;
1983 }
1984
1985 break;
1986 }
1987 case QOMX_IndexConfigVideoIntraperiod:
1988 {
1989 VALIDATE_OMX_PARAM_DATA(configData, QOMX_VIDEO_INTRAPERIODTYPE);
1990 QOMX_VIDEO_INTRAPERIODTYPE* pParam =
1991 reinterpret_cast<QOMX_VIDEO_INTRAPERIODTYPE*>(configData);
1992
1993 DEBUG_PRINT_HIGH("set_config(): QOMX_IndexConfigVideoIntraperiod");
1994 if (pParam->nPortIndex == PORT_INDEX_OUT) {
1995 DEBUG_PRINT_HIGH("Old: P/B frames = %u/%u, New: P/B frames = %u/%u",
1996 (unsigned int)m_sIntraperiod.nPFrames, (unsigned int)m_sIntraperiod.nBFrames,
1997 (unsigned int)pParam->nPFrames, (unsigned int)pParam->nBFrames);
1998 if (m_sIntraperiod.nBFrames != pParam->nBFrames) {
1999 if(hier_b_enabled && m_state == OMX_StateLoaded) {
2000 DEBUG_PRINT_INFO("B-frames setting is supported if HierB is enabled");
2001 }
2002 }
2003 if (handle->venc_set_config(configData, (OMX_INDEXTYPE) QOMX_IndexConfigVideoIntraperiod) != true) {
2004 DEBUG_PRINT_ERROR("ERROR: Setting QOMX_IndexConfigVideoIntraperiod failed");
2005 return OMX_ErrorUnsupportedSetting;
2006 }
2007 m_sIntraperiod.nPFrames = pParam->nPFrames;
2008 m_sIntraperiod.nBFrames = pParam->nBFrames;
2009 m_sIntraperiod.nIDRPeriod = pParam->nIDRPeriod;
2010
2011 m_sParamAVC.nPFrames = pParam->nPFrames;
2012 if ((m_sParamAVC.eProfile != OMX_VIDEO_AVCProfileBaseline) &&
2013 (m_sParamAVC.eProfile != (OMX_VIDEO_AVCPROFILETYPE) QOMX_VIDEO_AVCProfileConstrainedBaseline))
2014 m_sParamAVC.nBFrames = pParam->nBFrames;
2015 else
2016 m_sParamAVC.nBFrames = 0;
2017 } else {
2018 DEBUG_PRINT_ERROR("ERROR: (QOMX_IndexConfigVideoIntraperiod) Unsupported port index: %u", (unsigned int)pParam->nPortIndex);
2019 return OMX_ErrorBadPortIndex;
2020 }
2021
2022 break;
2023 }
2024
2025 case OMX_IndexConfigVideoIntraVOPRefresh:
2026 {
2027 VALIDATE_OMX_PARAM_DATA(configData, OMX_CONFIG_INTRAREFRESHVOPTYPE);
2028 OMX_CONFIG_INTRAREFRESHVOPTYPE* pParam =
2029 reinterpret_cast<OMX_CONFIG_INTRAREFRESHVOPTYPE*>(configData);
2030
2031 DEBUG_PRINT_HIGH("set_config(): OMX_IndexConfigVideoIntraVOPRefresh");
2032 if (pParam->nPortIndex == PORT_INDEX_OUT) {
2033 if (handle->venc_set_config(configData,
2034 OMX_IndexConfigVideoIntraVOPRefresh) != true) {
2035 DEBUG_PRINT_ERROR("ERROR: Setting OMX_IndexConfigVideoIntraVOPRefresh failed");
2036 return OMX_ErrorUnsupportedSetting;
2037 }
2038
2039 m_sConfigIntraRefreshVOP.IntraRefreshVOP = pParam->IntraRefreshVOP;
2040 } else {
2041 DEBUG_PRINT_ERROR("ERROR: Unsupported port index: %u", (unsigned int)pParam->nPortIndex);
2042 return OMX_ErrorBadPortIndex;
2043 }
2044
2045 break;
2046 }
2047 case OMX_IndexConfigCommonMirror:
2048 {
2049 VALIDATE_OMX_PARAM_DATA(configData, OMX_CONFIG_MIRRORTYPE);
2050 OMX_CONFIG_MIRRORTYPE *pParam = reinterpret_cast<OMX_CONFIG_MIRRORTYPE*>(configData);
2051
2052 if (pParam->nPortIndex != PORT_INDEX_OUT) {
2053 DEBUG_PRINT_ERROR("ERROR: Unsupported port index: %u", (unsigned int)pParam->nPortIndex);
2054 return OMX_ErrorBadPortIndex;
2055 }
2056 if (handle->venc_set_config(configData,OMX_IndexConfigCommonMirror) != true) {
2057 DEBUG_PRINT_ERROR("ERROR: Set OMX_IndexConfigCommonMirror failed");
2058 return OMX_ErrorUnsupportedSetting;
2059 }
2060 m_sConfigFrameMirror.eMirror = pParam->eMirror;
2061 break;
2062 }
2063 case OMX_IndexConfigCommonRotate:
2064 {
2065 VALIDATE_OMX_PARAM_DATA(configData, OMX_CONFIG_ROTATIONTYPE);
2066 OMX_CONFIG_ROTATIONTYPE *pParam =
2067 reinterpret_cast<OMX_CONFIG_ROTATIONTYPE*>(configData);
2068
2069 if (pParam->nPortIndex != PORT_INDEX_OUT) {
2070 DEBUG_PRINT_ERROR("ERROR: Unsupported port index: %u", (unsigned int)pParam->nPortIndex);
2071 return OMX_ErrorBadPortIndex;
2072 }
2073 if ( pParam->nRotation == 0 ||
2074 pParam->nRotation == 90 ||
2075 pParam->nRotation == 180 ||
2076 pParam->nRotation == 270 ) {
2077 DEBUG_PRINT_HIGH("set_config: Rotation Angle %u", (unsigned int)pParam->nRotation);
2078 } else {
2079 DEBUG_PRINT_ERROR("ERROR: un supported Rotation %u", (unsigned int)pParam->nRotation);
2080 return OMX_ErrorUnsupportedSetting;
2081 }
2082
2083 if (handle->venc_set_config(configData,
2084 OMX_IndexConfigCommonRotate) != true) {
2085 DEBUG_PRINT_ERROR("ERROR: Set OMX_IndexConfigCommonRotate failed");
2086 return OMX_ErrorUnsupportedSetting;
2087 }
2088 m_sConfigFrameRotation.nRotation = pParam->nRotation;
2089 break;
2090 }
2091 case OMX_QcomIndexConfigVideoFramePackingArrangement:
2092 {
2093 DEBUG_PRINT_HIGH("set_config(): OMX_QcomIndexConfigVideoFramePackingArrangement");
2094 if (m_sOutPortFormat.eCompressionFormat == OMX_VIDEO_CodingAVC) {
2095 VALIDATE_OMX_PARAM_DATA(configData, OMX_QCOM_FRAME_PACK_ARRANGEMENT);
2096 OMX_QCOM_FRAME_PACK_ARRANGEMENT *configFmt =
2097 (OMX_QCOM_FRAME_PACK_ARRANGEMENT *) configData;
2098 } else {
2099 DEBUG_PRINT_ERROR("ERROR: FramePackingData not supported for non AVC compression");
2100 }
2101 break;
2102 }
2103 case OMX_IndexConfigVideoVp8ReferenceFrame:
2104 {
2105 VALIDATE_OMX_PARAM_DATA(configData, OMX_VIDEO_VP8REFERENCEFRAMETYPE);
2106 OMX_VIDEO_VP8REFERENCEFRAMETYPE* pParam = (OMX_VIDEO_VP8REFERENCEFRAMETYPE*) configData;
2107 if (!handle->venc_set_config(pParam, (OMX_INDEXTYPE) OMX_IndexConfigVideoVp8ReferenceFrame)) {
2108 DEBUG_PRINT_ERROR("ERROR: Setting VP8 reference frame");
2109 return OMX_ErrorUnsupportedSetting;
2110 }
2111 memcpy(&m_sConfigVp8ReferenceFrame, pParam, sizeof(m_sConfigVp8ReferenceFrame));
2112 break;
2113 }
2114
2115 case QOMX_IndexConfigVideoLTRUse:
2116 {
2117 VALIDATE_OMX_PARAM_DATA(configData, QOMX_VIDEO_CONFIG_LTRUSE_TYPE);
2118 QOMX_VIDEO_CONFIG_LTRUSE_TYPE* pParam = (QOMX_VIDEO_CONFIG_LTRUSE_TYPE*)configData;
2119 if (!handle->venc_set_config(pParam, (OMX_INDEXTYPE)QOMX_IndexConfigVideoLTRUse)) {
2120 DEBUG_PRINT_ERROR("ERROR: Setting LTR use failed");
2121 return OMX_ErrorUnsupportedSetting;
2122 }
2123 memcpy(&m_sConfigLTRUse, pParam, sizeof(m_sConfigLTRUse));
2124 break;
2125 }
2126 case QOMX_IndexConfigVideoLTRMark:
2127 {
2128 VALIDATE_OMX_PARAM_DATA(configData, QOMX_VIDEO_CONFIG_LTRMARK_TYPE);
2129 QOMX_VIDEO_CONFIG_LTRMARK_TYPE* pParam = (QOMX_VIDEO_CONFIG_LTRMARK_TYPE*)configData;
2130 if (!handle->venc_set_config(pParam, (OMX_INDEXTYPE)QOMX_IndexConfigVideoLTRMark)) {
2131 DEBUG_PRINT_ERROR("ERROR: Setting LTR mark failed");
2132 return OMX_ErrorUnsupportedSetting;
2133 }
2134 break;
2135 }
2136 case OMX_IndexConfigVideoAVCIntraPeriod:
2137 {
2138 VALIDATE_OMX_PARAM_DATA(configData, OMX_VIDEO_CONFIG_AVCINTRAPERIOD);
2139 OMX_VIDEO_CONFIG_AVCINTRAPERIOD *pParam = (OMX_VIDEO_CONFIG_AVCINTRAPERIOD*) configData;
2140 DEBUG_PRINT_LOW("set_config: OMX_IndexConfigVideoAVCIntraPeriod");
2141 if (!handle->venc_set_config(pParam, (OMX_INDEXTYPE)OMX_IndexConfigVideoAVCIntraPeriod)) {
2142 DEBUG_PRINT_ERROR("ERROR: Setting OMX_IndexConfigVideoAVCIntraPeriod failed");
2143 return OMX_ErrorUnsupportedSetting;
2144 }
2145 memcpy(&m_sConfigAVCIDRPeriod, pParam, sizeof(m_sConfigAVCIDRPeriod));
2146 break;
2147 }
2148 case OMX_IndexConfigCommonDeinterlace:
2149 {
2150 VALIDATE_OMX_PARAM_DATA(configData, OMX_VIDEO_CONFIG_DEINTERLACE);
2151 OMX_VIDEO_CONFIG_DEINTERLACE *pParam = (OMX_VIDEO_CONFIG_DEINTERLACE*) configData;
2152 DEBUG_PRINT_LOW("set_config: OMX_IndexConfigCommonDeinterlace");
2153 if (!handle->venc_set_config(pParam, (OMX_INDEXTYPE)OMX_IndexConfigCommonDeinterlace)) {
2154 DEBUG_PRINT_ERROR("ERROR: Setting OMX_IndexConfigCommonDeinterlace failed");
2155 return OMX_ErrorUnsupportedSetting;
2156 }
2157 memcpy(&m_sConfigDeinterlace, pParam, sizeof(m_sConfigDeinterlace));
2158 break;
2159 }
2160 case OMX_QcomIndexConfigNumHierPLayers:
2161 {
2162 VALIDATE_OMX_PARAM_DATA(configData, QOMX_EXTNINDEX_VIDEO_HIER_P_LAYERS);
2163 QOMX_EXTNINDEX_VIDEO_HIER_P_LAYERS* pParam =
2164 (QOMX_EXTNINDEX_VIDEO_HIER_P_LAYERS*)configData;
2165 if (!handle->venc_set_config(pParam, (OMX_INDEXTYPE)OMX_QcomIndexConfigNumHierPLayers)) {
2166 DEBUG_PRINT_ERROR("ERROR: Setting OMX_QcomIndexConfigNumHierPLayers failed");
2167 return OMX_ErrorUnsupportedSetting;
2168 }
2169 memcpy(&m_sHPlayers, pParam, sizeof(m_sHPlayers));
2170 break;
2171 }
2172 case OMX_QcomIndexConfigBaseLayerId:
2173 {
2174 VALIDATE_OMX_PARAM_DATA(configData, OMX_SKYPE_VIDEO_CONFIG_BASELAYERPID);
2175 OMX_SKYPE_VIDEO_CONFIG_BASELAYERPID* pParam =
2176 (OMX_SKYPE_VIDEO_CONFIG_BASELAYERPID*) configData;
2177 if (!handle->venc_set_config(pParam, (OMX_INDEXTYPE)OMX_QcomIndexConfigBaseLayerId)) {
2178 DEBUG_PRINT_ERROR("ERROR: Setting OMX_QcomIndexConfigBaseLayerId failed");
2179 return OMX_ErrorUnsupportedSetting;
2180 }
2181 memcpy(&m_sBaseLayerID, pParam, sizeof(m_sBaseLayerID));
2182 break;
2183 }
2184 case OMX_QcomIndexConfigQp:
2185 {
2186 VALIDATE_OMX_PARAM_DATA(configData, OMX_SKYPE_VIDEO_CONFIG_QP);
2187 OMX_SKYPE_VIDEO_CONFIG_QP* pParam =
2188 (OMX_SKYPE_VIDEO_CONFIG_QP*) configData;
2189 if (!handle->venc_set_config(pParam, (OMX_INDEXTYPE)OMX_QcomIndexConfigQp)) {
2190 DEBUG_PRINT_ERROR("ERROR: Setting OMX_QcomIndexConfigQp failed");
2191 return OMX_ErrorUnsupportedSetting;
2192 }
2193 memcpy(&m_sConfigQP, pParam, sizeof(m_sConfigQP));
2194 break;
2195 }
2196 case OMX_IndexConfigPriority:
2197 {
2198 VALIDATE_OMX_PARAM_DATA(configData, OMX_PARAM_U32TYPE);
2199 if (!handle->venc_set_config(configData, (OMX_INDEXTYPE)OMX_IndexConfigPriority)) {
2200 DEBUG_PRINT_ERROR("Failed to set OMX_IndexConfigPriority");
2201 return OMX_ErrorUnsupportedSetting;
2202 }
2203 break;
2204 }
2205 case OMX_IndexConfigOperatingRate:
2206 {
2207 VALIDATE_OMX_PARAM_DATA(configData, OMX_PARAM_U32TYPE);
2208 OMX_PARAM_U32TYPE* pParam = (OMX_PARAM_U32TYPE*) configData;
2209 if (!handle->venc_set_config(configData, (OMX_INDEXTYPE)OMX_IndexConfigOperatingRate)) {
2210 DEBUG_PRINT_ERROR("Failed to set OMX_IndexConfigOperatingRate %u", pParam->nU32 >> 16);
2211 return handle->hw_overload ? OMX_ErrorInsufficientResources :
2212 OMX_ErrorUnsupportedSetting;
2213 }
2214 m_nOperatingRate = pParam->nU32;
2215 break;
2216 }
2217 case OMX_QTIIndexConfigVideoRoiInfo:
2218 {
2219 VALIDATE_OMX_PARAM_DATA(configData, OMX_QTI_VIDEO_CONFIG_ROIINFO);
2220 if (!handle->venc_set_config(configData, (OMX_INDEXTYPE)OMX_QTIIndexConfigVideoRoiInfo)) {
2221 DEBUG_PRINT_ERROR("Failed to set OMX_QTIIndexConfigVideoRoiInfo");
2222 return OMX_ErrorUnsupportedSetting;
2223 }
2224 break;
2225 }
2226 case OMX_IndexConfigTimePosition:
2227 {
2228 OMX_TIME_CONFIG_TIMESTAMPTYPE* pParam =
2229 (OMX_TIME_CONFIG_TIMESTAMPTYPE*) configData;
2230 unsigned long buf;
2231 unsigned long p2;
2232 unsigned long bufTime;
2233
2234 pthread_mutex_lock(&m_TimeStampInfo.m_lock);
2235 m_TimeStampInfo.ts = (OMX_S64)pParam->nTimestamp;
2236 while (m_TimeStampInfo.deferred_inbufq.m_size &&
2237 !(m_TimeStampInfo.deferred_inbufq.get_q_msg_type() > m_TimeStampInfo.ts)) {
2238 m_TimeStampInfo.deferred_inbufq.pop_entry(&buf,&p2,&bufTime);
2239 DEBUG_PRINT_INFO("Queueing back pending buffer %lu timestamp %lu", buf, bufTime);
2240 this->post_event((unsigned long)hComp, (unsigned long)buf, m_input_msg_id);
2241 }
2242 pthread_mutex_unlock(&m_TimeStampInfo.m_lock);
2243
2244 memcpy(&m_sConfigInputTrigTS, pParam, sizeof(m_sConfigInputTrigTS));
2245 break;
2246 }
2247 case OMX_IndexConfigAndroidIntraRefresh:
2248 {
2249 VALIDATE_OMX_PARAM_DATA(configData, OMX_VIDEO_CONFIG_ANDROID_INTRAREFRESHTYPE);
2250 OMX_VIDEO_CONFIG_ANDROID_INTRAREFRESHTYPE* pParam =
2251 (OMX_VIDEO_CONFIG_ANDROID_INTRAREFRESHTYPE*) configData;
2252 if (m_state == OMX_StateLoaded
2253 || m_sInPortDef.bEnabled == OMX_FALSE
2254 || m_sOutPortDef.bEnabled == OMX_FALSE) {
2255 if (!handle->venc_set_config(configData, (OMX_INDEXTYPE)OMX_IndexConfigAndroidIntraRefresh)) {
2256 DEBUG_PRINT_ERROR("Failed to set OMX_IndexConfigVideoIntraRefreshType");
2257 return OMX_ErrorUnsupportedSetting;
2258 }
2259 m_sConfigIntraRefresh.nRefreshPeriod = pParam->nRefreshPeriod;
2260 } else {
2261 DEBUG_PRINT_ERROR("ERROR: Setting OMX_IndexConfigAndroidIntraRefresh supported only at start of session");
2262 return OMX_ErrorUnsupportedSetting;
2263 }
2264 break;
2265 }
2266 case OMX_QTIIndexConfigVideoBlurResolution:
2267 {
2268 VALIDATE_OMX_PARAM_DATA(configData, OMX_QTI_VIDEO_CONFIG_BLURINFO);
2269 OMX_QTI_VIDEO_CONFIG_BLURINFO* pParam =
2270 (OMX_QTI_VIDEO_CONFIG_BLURINFO*) configData;
2271 if (!handle->venc_set_config(configData, (OMX_INDEXTYPE)OMX_QTIIndexConfigVideoBlurResolution)) {
2272 DEBUG_PRINT_ERROR("Failed to set OMX_QTIIndexConfigVideoBlurResolution");
2273 return OMX_ErrorUnsupportedSetting;
2274 }
2275 memcpy(&m_blurInfo, pParam, sizeof(OMX_QTI_VIDEO_CONFIG_BLURINFO));
2276 break;
2277 }
2278 case OMX_QcomIndexConfigH264Transform8x8:
2279 {
2280 if (!handle->venc_set_config(configData, (OMX_INDEXTYPE)OMX_QcomIndexConfigH264Transform8x8)) {
2281 DEBUG_PRINT_ERROR("ERROR: Setting OMX_QcomIndexConfigH264Transform8x8 failed");
2282 return OMX_ErrorUnsupportedSetting;
2283 }
2284 break;
2285 }
2286 case OMX_QTIIndexConfigDescribeColorAspects:
2287 {
2288 VALIDATE_OMX_PARAM_DATA(configData, DescribeColorAspectsParams);
2289 DescribeColorAspectsParams *params = (DescribeColorAspectsParams *)configData;
2290 print_debug_color_aspects(&(params->sAspects), "set_config");
2291
2292 // WA: Android client does not set the correct color-aspects (from dataspace).
2293 // Such a dataspace change is detected and set while in executing. This leads to
2294 // a race condition where client is trying to set (wrong) color and component trying
2295 // to set (right) color from ETB.
2296 // Hence ignore this config in Executing state till the framework starts setting right color.
2297 if (m_state == OMX_StateExecuting) {
2298 DEBUG_PRINT_HIGH("Ignoring ColorSpace setting in Executing state");
2299 return OMX_ErrorUnsupportedSetting;
2300 }
2301
2302 if (!handle->venc_set_config(configData, (OMX_INDEXTYPE)OMX_QTIIndexConfigDescribeColorAspects)) {
2303 DEBUG_PRINT_ERROR("Failed to set OMX_QTIIndexConfigDescribeColorAspects");
2304 return OMX_ErrorUnsupportedSetting;
2305 }
2306 memcpy(&m_sConfigColorAspects, configData, sizeof(m_sConfigColorAspects));
2307 break;
2308 }
2309 case OMX_IndexConfigAndroidVideoTemporalLayering:
2310 {
2311 VALIDATE_OMX_PARAM_DATA(configData, OMX_VIDEO_CONFIG_ANDROID_TEMPORALLAYERINGTYPE);
2312 OMX_VIDEO_CONFIG_ANDROID_TEMPORALLAYERINGTYPE* pParam =
2313 (OMX_VIDEO_CONFIG_ANDROID_TEMPORALLAYERINGTYPE*) configData;
2314 if (!handle->venc_set_config(configData, (OMX_INDEXTYPE)OMX_IndexConfigAndroidVideoTemporalLayering)) {
2315 DEBUG_PRINT_ERROR("Failed to set OMX_VIDEO_CONFIG_ANDROID_TEMPORALLAYERINGTYPE");
2316 return OMX_ErrorUnsupportedSetting;
2317 }
2318 memcpy(&m_sConfigTemporalLayers, pParam, sizeof(m_sConfigTemporalLayers));
2319 break;
2320 }
2321 case OMX_IndexConfigAndroidVendorExtension:
2322 {
2323 VALIDATE_OMX_PARAM_DATA(configData, OMX_CONFIG_ANDROID_VENDOR_EXTENSIONTYPE);
2324
2325 OMX_CONFIG_ANDROID_VENDOR_EXTENSIONTYPE *ext =
2326 reinterpret_cast<OMX_CONFIG_ANDROID_VENDOR_EXTENSIONTYPE *>(configData);
2327 VALIDATE_OMX_VENDOR_EXTENSION_PARAM_DATA(ext);
2328
2329 return set_vendor_extension_config(ext);
2330 }
2331 case OMX_IndexConfigVideoNalSize:
2332 {
2333 VALIDATE_OMX_PARAM_DATA(configData, OMX_VIDEO_CONFIG_NALSIZE);
2334
2335 OMX_VIDEO_CONFIG_NALSIZE* pParam =
2336 reinterpret_cast<OMX_VIDEO_CONFIG_NALSIZE*>(configData);
2337 DEBUG_PRINT_HIGH("set_config(): OMX_IndexConfigVideoNalSize (%u)", (unsigned int)pParam->nNaluBytes);
2338
2339 if (pParam->nPortIndex == PORT_INDEX_OUT) {
2340 if (handle->venc_set_config(configData, OMX_IndexConfigVideoNalSize) != true) {
2341 DEBUG_PRINT_LOW("Setting OMX_IndexConfigVideoBitrate failed");
2342 return OMX_ErrorUnsupportedSetting;
2343 }
2344 } else {
2345 DEBUG_PRINT_ERROR("ERROR: Unsupported port index: %u", (unsigned int)pParam->nPortIndex);
2346 return OMX_ErrorBadPortIndex;
2347 }
2348 break;
2349 }
2350 case OMX_QTIIndexConfigVideoRoiRectRegionInfo:
2351 {
2352 VALIDATE_OMX_PARAM_DATA(configData, OMX_QTI_VIDEO_CONFIG_ROI_RECT_REGION_INFO);
2353 if (!handle->venc_set_config(configData, (OMX_INDEXTYPE)OMX_QTIIndexConfigVideoRoiRectRegionInfo)) {
2354 DEBUG_PRINT_ERROR("Failed to set OMX_QTIIndexConfigVideoRoiRegionInfo");
2355 return OMX_ErrorUnsupportedSetting;
2356 }
2357 break;
2358
2359 }
2360 default:
2361 DEBUG_PRINT_ERROR("ERROR: unsupported index %d", (int) configIndex);
2362 break;
2363 }
2364
2365 return OMX_ErrorNone;
2366 }
2367
2368 /* ======================================================================
2369 FUNCTION
2370 omx_venc::ComponentDeInit
2371
2372 DESCRIPTION
2373 Destroys the component and release memory allocated to the heap.
2374
2375 PARAMETERS
2376 <TBD>.
2377
2378 RETURN VALUE
2379 OMX Error None if everything successful.
2380
2381 ========================================================================== */
component_deinit(OMX_IN OMX_HANDLETYPE hComp)2382 OMX_ERRORTYPE omx_venc::component_deinit(OMX_IN OMX_HANDLETYPE hComp)
2383 {
2384 (void) hComp;
2385 OMX_U32 i = 0;
2386 DEBUG_PRINT_HIGH("omx_venc(): Inside component_deinit()");
2387 if (OMX_StateLoaded != m_state) {
2388 DEBUG_PRINT_ERROR("WARNING:Rxd DeInit,OMX not in LOADED state %d",\
2389 m_state);
2390 }
2391
2392 auto_lock l(m_buf_lock);
2393 if (m_out_mem_ptr) {
2394 DEBUG_PRINT_LOW("Freeing the Output Memory");
2395 for (i=0; i< m_sOutPortDef.nBufferCountActual; i++ ) {
2396 if (BITMASK_PRESENT(&m_out_bm_count, i)) {
2397 BITMASK_CLEAR(&m_out_bm_count, i);
2398 if (BITMASK_PRESENT(&m_client_out_bm_count, i))
2399 BITMASK_CLEAR(&m_client_out_bm_count, i);
2400 free_output_buffer (&m_out_mem_ptr[i]);
2401 }
2402
2403 if (release_output_done()) {
2404 break;
2405 }
2406 }
2407 free(m_out_mem_ptr);
2408 m_out_mem_ptr = NULL;
2409 }
2410
2411 /*Check if the input buffers have to be cleaned up*/
2412 OMX_BUFFERHEADERTYPE* ptr = m_inp_mem_ptr;
2413 #ifdef _ANDROID_ICS_
2414 if (meta_mode_enable) {
2415 ptr = meta_buffer_hdr;
2416 }
2417 #endif
2418 if (ptr) {
2419 DEBUG_PRINT_LOW("Freeing the Input Memory");
2420 for (i=0; i<m_sInPortDef.nBufferCountActual; i++ ) {
2421 if (BITMASK_PRESENT(&m_inp_bm_count, i)) {
2422 BITMASK_CLEAR(&m_inp_bm_count, i);
2423 if (BITMASK_PRESENT(&m_client_in_bm_count, i))
2424 BITMASK_CLEAR(&m_client_in_bm_count, i);
2425 free_input_buffer(ptr + i);
2426 }
2427
2428 if (release_input_done()) {
2429 break;
2430 }
2431 }
2432
2433 if (m_inp_mem_ptr != meta_buffer_hdr)
2434 free(m_inp_mem_ptr);
2435 m_inp_mem_ptr = NULL;
2436 }
2437
2438 // Reset counters in mesg queues
2439 m_ftb_q.m_size=0;
2440 m_cmd_q.m_size=0;
2441 m_etb_q.m_size=0;
2442 m_ftb_q.m_read = m_ftb_q.m_write =0;
2443 m_cmd_q.m_read = m_cmd_q.m_write =0;
2444 m_etb_q.m_read = m_etb_q.m_write =0;
2445
2446 DEBUG_PRINT_HIGH("Calling venc_close()");
2447 if (handle) {
2448 handle->venc_close();
2449 DEBUG_PRINT_HIGH("Deleting HANDLE[%p]", handle);
2450 delete (handle);
2451 handle = NULL;
2452 }
2453 DEBUG_PRINT_INFO("Component Deinit");
2454 return OMX_ErrorNone;
2455 }
2456
2457
dev_stop(void)2458 OMX_U32 omx_venc::dev_stop( void)
2459 {
2460 return handle->venc_stop();
2461 }
2462
2463
dev_pause(void)2464 OMX_U32 omx_venc::dev_pause(void)
2465 {
2466 return handle->venc_pause();
2467 }
2468
dev_start(void)2469 OMX_U32 omx_venc::dev_start(void)
2470 {
2471 return handle->venc_start();
2472 }
2473
dev_flush(unsigned port)2474 OMX_U32 omx_venc::dev_flush(unsigned port)
2475 {
2476 return handle->venc_flush(port);
2477 }
2478
dev_resume(void)2479 OMX_U32 omx_venc::dev_resume(void)
2480 {
2481 return handle->venc_resume();
2482 }
2483
dev_start_done(void)2484 OMX_U32 omx_venc::dev_start_done(void)
2485 {
2486 return handle->venc_start_done();
2487 }
2488
dev_set_message_thread_id(pthread_t tid)2489 OMX_U32 omx_venc::dev_set_message_thread_id(pthread_t tid)
2490 {
2491 return handle->venc_set_message_thread_id(tid);
2492 }
2493
dev_handle_empty_eos_buffer(void)2494 bool omx_venc::dev_handle_empty_eos_buffer(void)
2495 {
2496 return handle->venc_handle_empty_eos_buffer();
2497 }
2498
dev_use_buf(unsigned port)2499 bool omx_venc::dev_use_buf(unsigned port)
2500 {
2501 return handle->allocate_extradata(port);
2502 }
2503
dev_buffer_ready_to_queue(OMX_BUFFERHEADERTYPE * buffer)2504 bool omx_venc::dev_buffer_ready_to_queue(OMX_BUFFERHEADERTYPE *buffer)
2505 {
2506 bool bRet = true;
2507
2508 /* do not defer the buffer if m_TimeStamp is not initialized */
2509 if (!m_sParamControlInputQueue.bEnable)
2510 return true;
2511
2512 pthread_mutex_lock(&m_TimeStampInfo.m_lock);
2513
2514 if ((!m_sParamControlInputQueue.bEnable) ||
2515 (OMX_S64)buffer->nTimeStamp <= (OMX_S64)m_TimeStampInfo.ts) {
2516 DEBUG_PRINT_LOW("ETB is ready to be queued");
2517 } else {
2518 DEBUG_PRINT_INFO(
2519 "ETB is deferred due to timeStamp mismatch buf_ts %lld m_TimeStampInfo.ts %lld",
2520 (OMX_S64)buffer->nTimeStamp, (OMX_S64)m_TimeStampInfo.ts);
2521 m_TimeStampInfo.deferred_inbufq.insert_entry((unsigned long)buffer, 0, buffer->nTimeStamp);
2522 bRet = false;
2523 }
2524 pthread_mutex_unlock(&m_TimeStampInfo.m_lock);
2525 return bRet;
2526 }
2527
dev_free_buf(void * buf_addr,unsigned port)2528 bool omx_venc::dev_free_buf(void *buf_addr,unsigned port)
2529 {
2530 return handle->venc_free_buf(buf_addr,port);
2531 }
2532
dev_empty_buf(void * buffer,void * pmem_data_buf,unsigned index,unsigned fd)2533 bool omx_venc::dev_empty_buf(void *buffer, void *pmem_data_buf,unsigned index,unsigned fd)
2534 {
2535 bool bret = false;
2536 bret = handle->venc_empty_buf(buffer, pmem_data_buf,index,fd);
2537 hw_overload = handle->hw_overload;
2538 return bret;
2539 }
2540
dev_fill_buf(void * buffer,void * pmem_data_buf,unsigned index,unsigned fd)2541 bool omx_venc::dev_fill_buf(void *buffer, void *pmem_data_buf,unsigned index,unsigned fd)
2542 {
2543 return handle->venc_fill_buf(buffer, pmem_data_buf,index,fd);
2544 }
2545
dev_get_seq_hdr(void * buffer,unsigned size,unsigned * hdrlen)2546 bool omx_venc::dev_get_seq_hdr(void *buffer, unsigned size, unsigned *hdrlen)
2547 {
2548 return handle->venc_get_seq_hdr(buffer, size, hdrlen);
2549 }
2550
dev_get_capability_ltrcount(OMX_U32 * min,OMX_U32 * max,OMX_U32 * step_size)2551 bool omx_venc::dev_get_capability_ltrcount(OMX_U32 *min, OMX_U32 *max, OMX_U32 *step_size)
2552 {
2553 (void) min;
2554 (void) max;
2555 (void) step_size;
2556 DEBUG_PRINT_ERROR("Get Capability LTR Count is not supported");
2557 return false;
2558 }
2559
dev_get_vui_timing_info(OMX_U32 * enabled)2560 bool omx_venc::dev_get_vui_timing_info(OMX_U32 *enabled)
2561 {
2562 return handle->venc_get_vui_timing_info(enabled);
2563 }
2564
dev_get_vqzip_sei_info(OMX_U32 * enabled)2565 bool omx_venc::dev_get_vqzip_sei_info(OMX_U32 *enabled)
2566 {
2567 return handle->venc_get_vqzip_sei_info(enabled);
2568 }
2569
dev_get_peak_bitrate(OMX_U32 * peakbitrate)2570 bool omx_venc::dev_get_peak_bitrate(OMX_U32 *peakbitrate)
2571 {
2572 return handle->venc_get_peak_bitrate(peakbitrate);
2573 }
2574
dev_get_batch_size(OMX_U32 * size)2575 bool omx_venc::dev_get_batch_size(OMX_U32 *size)
2576 {
2577 return handle->venc_get_batch_size(size);
2578 }
2579
dev_get_temporal_layer_caps(OMX_U32 * nMaxLayers,OMX_U32 * nMaxBLayers,OMX_VIDEO_ANDROID_TEMPORALLAYERINGPATTERNTYPE * eSupportedPattern)2580 bool omx_venc::dev_get_temporal_layer_caps(OMX_U32 *nMaxLayers,
2581 OMX_U32 *nMaxBLayers, OMX_VIDEO_ANDROID_TEMPORALLAYERINGPATTERNTYPE *eSupportedPattern) {
2582 return handle->venc_get_temporal_layer_caps(nMaxLayers, nMaxBLayers, eSupportedPattern);
2583 }
2584
dev_get_supported_profile_level(OMX_VIDEO_PARAM_PROFILELEVELTYPE * profileLevelType)2585 OMX_ERRORTYPE omx_venc::dev_get_supported_profile_level(OMX_VIDEO_PARAM_PROFILELEVELTYPE *profileLevelType)
2586 {
2587 return handle->venc_get_supported_profile_level(profileLevelType);
2588 }
2589
dev_get_supported_color_format(unsigned index,OMX_U32 * colorFormat)2590 bool omx_venc::dev_get_supported_color_format(unsigned index, OMX_U32 *colorFormat) {
2591 return handle->venc_get_supported_color_format(index, colorFormat);
2592 }
2593
dev_get_color_format_as_string(char * buf,int buf_len,unsigned colorformat)2594 void omx_venc::dev_get_color_format_as_string(char * buf, int buf_len, unsigned colorformat) {
2595 // Try to match with OMX_QCOM_COLOR_FORMATTYPE
2596 switch (colorformat) {
2597 case QOMX_COLOR_FormatYVU420SemiPlanar:
2598 snprintf(buf, buf_len, "QOMX_COLOR_FormatYVU420SemiPlanar");
2599 break;
2600 case QOMX_COLOR_FormatYVU420PackedSemiPlanar32m4ka:
2601 snprintf(buf, buf_len, "QOMX_COLOR_FormatYVU420PackedSemiPlanar32m4ka");
2602 break;
2603 case QOMX_COLOR_FormatYUV420PackedSemiPlanar16m2ka:
2604 snprintf(buf, buf_len, "QOMX_COLOR_FormatYUV420PackedSemiPlanar16m2ka");
2605 break;
2606 case QOMX_COLOR_FormatYUV420PackedSemiPlanar64x32Tile2m8ka:
2607 snprintf(buf, buf_len, "QOMX_COLOR_FormatYUV420PackedSemiPlanar64x32Tile2m8ka");
2608 break;
2609 case QOMX_COLOR_FORMATYUV420PackedSemiPlanar32m:
2610 snprintf(buf, buf_len, "QOMX_COLOR_FORMATYUV420PackedSemiPlanar32m");
2611 break;
2612 case QOMX_COLOR_FORMATYUV420PackedSemiPlanar32mMultiView:
2613 snprintf(buf, buf_len, "QOMX_COLOR_FORMATYUV420PackedSemiPlanar32mMultiView");
2614 break;
2615 case QOMX_COLOR_FORMATYUV420PackedSemiPlanar32mCompressed:
2616 snprintf(buf, buf_len, "QOMX_COLOR_FORMATYUV420PackedSemiPlanar32mCompressed");
2617 break;
2618 case QOMX_COLOR_Format32bitRGBA8888:
2619 snprintf(buf, buf_len, "QOMX_COLOR_Format32bitRGBA8888");
2620 break;
2621 case QOMX_COLOR_Format32bitRGBA8888Compressed:
2622 snprintf(buf, buf_len, "QOMX_COLOR_Format32bitRGBA8888Compressed");
2623 break;
2624 case QOMX_COLOR_FORMATYUV420PackedSemiPlanar32m10bitCompressed:
2625 snprintf(buf, buf_len, "QOMX_COLOR_FORMATYUV420PackedSemiPlanar32m10bitCompressed");
2626 break;
2627 case QOMX_COLOR_FORMATYUV420SemiPlanarP010Venus:
2628 snprintf(buf, buf_len, "QOMX_COLOR_FORMATYUV420SemiPlanarP010Venus");
2629 break;
2630 case QOMX_COLOR_FormatAndroidOpaque:
2631 snprintf(buf, buf_len, "QOMX_COLOR_FormatAndroidOpaque");
2632 break;
2633 default:
2634 snprintf(buf, buf_len, "no match found in OMX_QCOM_COLOR_FORMATTYPE");
2635 return;
2636 }
2637 }
2638
dev_loaded_start()2639 bool omx_venc::dev_loaded_start()
2640 {
2641 return handle->venc_loaded_start();
2642 }
2643
dev_loaded_stop()2644 bool omx_venc::dev_loaded_stop()
2645 {
2646 return handle->venc_loaded_stop();
2647 }
2648
dev_loaded_start_done()2649 bool omx_venc::dev_loaded_start_done()
2650 {
2651 return handle->venc_loaded_start_done();
2652 }
2653
dev_loaded_stop_done()2654 bool omx_venc::dev_loaded_stop_done()
2655 {
2656 return handle->venc_loaded_stop_done();
2657 }
2658
dev_get_buf_req(OMX_U32 * min_buff_count,OMX_U32 * actual_buff_count,OMX_U32 * buff_size,OMX_U32 port)2659 bool omx_venc::dev_get_buf_req(OMX_U32 *min_buff_count,
2660 OMX_U32 *actual_buff_count,
2661 OMX_U32 *buff_size,
2662 OMX_U32 port)
2663 {
2664 return handle->venc_get_buf_req(min_buff_count,
2665 actual_buff_count,
2666 buff_size,
2667 port);
2668
2669 }
2670
dev_get_dimensions(OMX_U32 port,OMX_U32 * width,OMX_U32 * height)2671 bool omx_venc::dev_get_dimensions(OMX_U32 port,
2672 OMX_U32 *width,
2673 OMX_U32 *height)
2674 {
2675 return handle->venc_get_dimensions(port,
2676 width,
2677 height);
2678 }
2679
is_streamon_done(OMX_U32 port)2680 bool omx_venc::is_streamon_done(OMX_U32 port)
2681 {
2682 return handle->is_streamon_done(port);
2683 }
2684
dev_set_buf_req(OMX_U32 * min_buff_count,OMX_U32 * actual_buff_count,OMX_U32 * buff_size,OMX_U32 port)2685 bool omx_venc::dev_set_buf_req(OMX_U32 *min_buff_count,
2686 OMX_U32 *actual_buff_count,
2687 OMX_U32 *buff_size,
2688 OMX_U32 port)
2689 {
2690 return handle->venc_set_buf_req(min_buff_count,
2691 actual_buff_count,
2692 buff_size,
2693 port);
2694
2695 }
2696
dev_is_video_session_supported(OMX_U32 width,OMX_U32 height)2697 bool omx_venc::dev_is_video_session_supported(OMX_U32 width, OMX_U32 height)
2698 {
2699 return handle->venc_is_video_session_supported(width,height);
2700 }
2701
dev_handle_output_extradata(void * buffer,int index)2702 int omx_venc::dev_handle_output_extradata(void *buffer, int index)
2703 {
2704 return handle->handle_output_extradata(buffer, index);
2705 }
2706
dev_set_format(int color)2707 int omx_venc::dev_set_format(int color)
2708 {
2709 return handle->venc_set_format(color);
2710 }
2711
dev_query_cap(struct v4l2_queryctrl & cap)2712 bool omx_venc::dev_query_cap(struct v4l2_queryctrl &cap)
2713
2714 {
2715 return handle->venc_query_cap(cap);
2716 }
2717
async_message_process(void * context,void * message)2718 int omx_venc::async_message_process (void *context, void* message)
2719 {
2720 omx_video* omx = NULL;
2721 struct venc_msg *m_sVenc_msg = NULL;
2722 OMX_BUFFERHEADERTYPE* omxhdr = NULL;
2723 struct venc_buffer *temp_buff = NULL;
2724 native_handle_t *nh = NULL;
2725
2726 if (context == NULL || message == NULL) {
2727 DEBUG_PRINT_ERROR("ERROR: omx_venc::async_message_process invalid i/p params");
2728 return -1;
2729 }
2730 m_sVenc_msg = (struct venc_msg *)message;
2731
2732 omx = reinterpret_cast<omx_video*>(context);
2733
2734 if (m_sVenc_msg->statuscode != VEN_S_SUCCESS) {
2735 DEBUG_PRINT_ERROR("ERROR: async_msg_process() - Error statuscode = %lu",
2736 m_sVenc_msg->statuscode);
2737 if(m_sVenc_msg->msgcode == VEN_MSG_HW_OVERLOAD) {
2738 omx->post_event (0, m_sVenc_msg->statuscode,\
2739 OMX_COMPONENT_GENERATE_HARDWARE_OVERLOAD);
2740 } else {
2741 omx->post_event (0, m_sVenc_msg->statuscode,\
2742 OMX_COMPONENT_GENERATE_HARDWARE_ERROR);
2743 }
2744 }
2745
2746 DEBUG_PRINT_LOW("omx_venc::async_message_process- msgcode = %lu",
2747 m_sVenc_msg->msgcode);
2748 switch (m_sVenc_msg->msgcode) {
2749 case VEN_MSG_START:
2750 omx->post_event (0,m_sVenc_msg->statuscode,\
2751 OMX_COMPONENT_GENERATE_START_DONE);
2752 break;
2753 case VEN_MSG_STOP:
2754 omx->post_event (0,m_sVenc_msg->statuscode,\
2755 OMX_COMPONENT_GENERATE_STOP_DONE);
2756 break;
2757 case VEN_MSG_RESUME:
2758 omx->post_event (0,m_sVenc_msg->statuscode,\
2759 OMX_COMPONENT_GENERATE_RESUME_DONE);
2760 break;
2761 case VEN_MSG_PAUSE:
2762 omx->post_event (0,m_sVenc_msg->statuscode,\
2763 OMX_COMPONENT_GENERATE_PAUSE_DONE);
2764 break;
2765 case VEN_MSG_FLUSH_INPUT_DONE:
2766
2767 omx->post_event (0,m_sVenc_msg->statuscode,\
2768 OMX_COMPONENT_GENERATE_EVENT_INPUT_FLUSH);
2769 break;
2770 case VEN_MSG_FLUSH_OUPUT_DONE:
2771 omx->post_event (0,m_sVenc_msg->statuscode,\
2772 OMX_COMPONENT_GENERATE_EVENT_OUTPUT_FLUSH);
2773 break;
2774 case VEN_MSG_INPUT_BUFFER_DONE:
2775 omxhdr = (OMX_BUFFERHEADERTYPE* )\
2776 m_sVenc_msg->buf.clientdata;
2777
2778 if (omxhdr == NULL ||
2779 (((OMX_U32)(omxhdr - omx->m_inp_mem_ptr) > omx->m_sInPortDef.nBufferCountActual) &&
2780 ((OMX_U32)(omxhdr - omx->meta_buffer_hdr) > omx->m_sInPortDef.nBufferCountActual))) {
2781 omxhdr = NULL;
2782 m_sVenc_msg->statuscode = VEN_S_EFAIL;
2783 }
2784
2785 #ifdef _ANDROID_ICS_
2786 omx->omx_release_meta_buffer(omxhdr);
2787 #endif
2788 omx->post_event ((unsigned long)omxhdr,m_sVenc_msg->statuscode,
2789 OMX_COMPONENT_GENERATE_EBD);
2790 break;
2791 case VEN_MSG_OUTPUT_BUFFER_DONE:
2792 {
2793 omxhdr = (OMX_BUFFERHEADERTYPE*)m_sVenc_msg->buf.clientdata;
2794 OMX_U32 bufIndex = (OMX_U32)(omxhdr - omx->m_out_mem_ptr);
2795
2796 if ( (omxhdr != NULL) &&
2797 (bufIndex < omx->m_sOutPortDef.nBufferCountActual)) {
2798 auto_lock l(omx->m_buf_lock);
2799 if (BITMASK_ABSENT(&(omx->m_out_bm_count), bufIndex)) {
2800 DEBUG_PRINT_ERROR("Recieved FBD for buffer that is already freed !");
2801 break;
2802 }
2803 if (!omx->is_secure_session() && (m_sVenc_msg->buf.len <= omxhdr->nAllocLen)) {
2804 omxhdr->nFilledLen = m_sVenc_msg->buf.len;
2805 omxhdr->nOffset = m_sVenc_msg->buf.offset;
2806 omxhdr->nTimeStamp = m_sVenc_msg->buf.timestamp;
2807 DEBUG_PRINT_LOW("o/p TS = %u", (unsigned int)m_sVenc_msg->buf.timestamp);
2808 omxhdr->nFlags = m_sVenc_msg->buf.flags;
2809
2810 /*Use buffer case*/
2811 if (BITMASK_PRESENT(&(omx->m_client_out_bm_count), bufIndex) &&
2812 omx->output_use_buffer && !omx->m_use_output_pmem && !omx->is_secure_session()) {
2813 DEBUG_PRINT_LOW("memcpy() for o/p Heap UseBuffer");
2814 memcpy(omxhdr->pBuffer,
2815 (m_sVenc_msg->buf.ptrbuffer),
2816 m_sVenc_msg->buf.len);
2817 }
2818 } else if (omx->is_secure_session()) {
2819 if (omx->allocate_native_handle) {
2820 native_handle_t *nh = (native_handle_t *)(omxhdr->pBuffer);
2821 nh->data[1] = m_sVenc_msg->buf.offset;
2822 nh->data[2] = m_sVenc_msg->buf.len;
2823 omxhdr->nFilledLen = m_sVenc_msg->buf.len;
2824 omxhdr->nTimeStamp = m_sVenc_msg->buf.timestamp;
2825 omxhdr->nFlags = m_sVenc_msg->buf.flags;
2826 } else {
2827 output_metabuffer *meta_buf = (output_metabuffer *)(omxhdr->pBuffer);
2828 native_handle_t *nh = meta_buf->nh;
2829 nh->data[1] = m_sVenc_msg->buf.offset;
2830 nh->data[2] = m_sVenc_msg->buf.len;
2831 omxhdr->nFilledLen = sizeof(output_metabuffer);
2832 omxhdr->nTimeStamp = m_sVenc_msg->buf.timestamp;
2833 omxhdr->nFlags = m_sVenc_msg->buf.flags;
2834 }
2835 } else {
2836 omxhdr->nFilledLen = 0;
2837 }
2838
2839 } else {
2840 omxhdr = NULL;
2841 m_sVenc_msg->statuscode = VEN_S_EFAIL;
2842 }
2843 omx->post_event ((unsigned long)omxhdr,m_sVenc_msg->statuscode,
2844 OMX_COMPONENT_GENERATE_FBD);
2845 break;
2846 }
2847 case VEN_MSG_NEED_OUTPUT_BUFFER:
2848 //TBD what action needs to be done here??
2849 break;
2850 default:
2851 DEBUG_PRINT_HIGH("Unknown msg received : %lu", m_sVenc_msg->msgcode);
2852 break;
2853 }
2854 return 0;
2855 }
2856
dev_color_align(OMX_BUFFERHEADERTYPE * buffer,OMX_U32 width,OMX_U32 height)2857 bool omx_venc::dev_color_align(OMX_BUFFERHEADERTYPE *buffer,
2858 OMX_U32 width, OMX_U32 height)
2859 {
2860 if(secure_session) {
2861 DEBUG_PRINT_ERROR("Cannot align colors in secure session.");
2862 return OMX_FALSE;
2863 }
2864 return handle->venc_color_align(buffer, width,height);
2865 }
2866
is_secure_session()2867 bool omx_venc::is_secure_session()
2868 {
2869 return secure_session;
2870 }
2871
dev_get_output_log_flag()2872 bool omx_venc::dev_get_output_log_flag()
2873 {
2874 return handle->venc_get_output_log_flag();
2875 }
2876
dev_output_log_buffers(const char * buffer,int bufferlen,uint64_t timestamp)2877 int omx_venc::dev_output_log_buffers(const char *buffer,
2878 int bufferlen, uint64_t timestamp)
2879 {
2880 return handle->venc_output_log_buffers(buffer, bufferlen, timestamp);
2881 }
2882
dev_extradata_log_buffers(char * buffer,bool input)2883 int omx_venc::dev_extradata_log_buffers(char *buffer, bool input)
2884 {
2885 return handle->venc_extradata_log_buffers(buffer, input);
2886 }
2887
dev_get_hevc_profile(OMX_U32 * profile)2888 bool omx_venc::dev_get_hevc_profile(OMX_U32* profile)
2889 {
2890 return handle->venc_get_hevc_profile(profile);
2891 }
2892
dev_handle_client_input_extradata(void * buffer)2893 bool omx_venc::dev_handle_client_input_extradata(void *buffer)
2894 {
2895 return handle->venc_handle_client_input_extradata(buffer);
2896 }
2897
dev_get_consumer_usage(OMX_U32 * usage)2898 void omx_venc::dev_get_consumer_usage(OMX_U32* usage)
2899 {
2900 return handle->venc_get_consumer_usage(usage);
2901 }
2902