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