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