1/*--------------------------------------------------------------------------
2Copyright (c) 2010-2016, 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) QOMX_VIDEO_AVCProfileConstrainedBaseline))
1868                            m_sParamAVC.nBFrames = pParam->nBFrames;
1869                        else
1870                            m_sParamAVC.nBFrames = 0;
1871                    }
1872                } else {
1873                    DEBUG_PRINT_ERROR("ERROR: (QOMX_IndexConfigVideoIntraperiod) Unsupported port index: %u", (unsigned int)pParam->nPortIndex);
1874                    return OMX_ErrorBadPortIndex;
1875                }
1876
1877                break;
1878            }
1879
1880        case OMX_IndexConfigVideoIntraVOPRefresh:
1881            {
1882                VALIDATE_OMX_PARAM_DATA(configData, OMX_CONFIG_INTRAREFRESHVOPTYPE);
1883                OMX_CONFIG_INTRAREFRESHVOPTYPE* pParam =
1884                    reinterpret_cast<OMX_CONFIG_INTRAREFRESHVOPTYPE*>(configData);
1885
1886                DEBUG_PRINT_HIGH("set_config(): OMX_IndexConfigVideoIntraVOPRefresh");
1887                if (pParam->nPortIndex == PORT_INDEX_OUT) {
1888                    if (handle->venc_set_config(configData,
1889                                OMX_IndexConfigVideoIntraVOPRefresh) != true) {
1890                        DEBUG_PRINT_ERROR("ERROR: Setting OMX_IndexConfigVideoIntraVOPRefresh failed");
1891                        return OMX_ErrorUnsupportedSetting;
1892                    }
1893
1894                    m_sConfigIntraRefreshVOP.IntraRefreshVOP = pParam->IntraRefreshVOP;
1895                } else {
1896                    DEBUG_PRINT_ERROR("ERROR: Unsupported port index: %u", (unsigned int)pParam->nPortIndex);
1897                    return OMX_ErrorBadPortIndex;
1898                }
1899
1900                break;
1901            }
1902        case OMX_IndexConfigCommonRotate:
1903            {
1904                VALIDATE_OMX_PARAM_DATA(configData, OMX_CONFIG_ROTATIONTYPE);
1905                OMX_CONFIG_ROTATIONTYPE *pParam =
1906                    reinterpret_cast<OMX_CONFIG_ROTATIONTYPE*>(configData);
1907                OMX_S32 nRotation;
1908
1909                if (pParam->nPortIndex != PORT_INDEX_OUT) {
1910                    DEBUG_PRINT_ERROR("ERROR: Unsupported port index: %u", (unsigned int)pParam->nPortIndex);
1911                    return OMX_ErrorBadPortIndex;
1912                }
1913                if ( pParam->nRotation == 0   ||
1914                        pParam->nRotation == 90  ||
1915                        pParam->nRotation == 180 ||
1916                        pParam->nRotation == 270 ) {
1917                    DEBUG_PRINT_HIGH("set_config: Rotation Angle %u", (unsigned int)pParam->nRotation);
1918                } else {
1919                    DEBUG_PRINT_ERROR("ERROR: un supported Rotation %u", (unsigned int)pParam->nRotation);
1920                    return OMX_ErrorUnsupportedSetting;
1921                }
1922                nRotation = pParam->nRotation - m_sConfigFrameRotation.nRotation;
1923                if (nRotation < 0)
1924                    nRotation = -nRotation;
1925                if (nRotation == 90 || nRotation == 270) {
1926                    DEBUG_PRINT_HIGH("set_config: updating device Dims");
1927                    if (handle->venc_set_config(configData,
1928                                OMX_IndexConfigCommonRotate) != true) {
1929                        DEBUG_PRINT_ERROR("ERROR: Set OMX_IndexConfigCommonRotate failed");
1930                        return OMX_ErrorUnsupportedSetting;
1931                    } else {
1932                        OMX_U32 nFrameWidth;
1933                        OMX_U32 nFrameHeight;
1934
1935                        DEBUG_PRINT_HIGH("set_config: updating port Dims");
1936
1937                        nFrameWidth = m_sOutPortDef.format.video.nFrameWidth;
1938                        nFrameHeight = m_sOutPortDef.format.video.nFrameHeight;
1939                        m_sOutPortDef.format.video.nFrameWidth  = nFrameHeight;
1940                        m_sOutPortDef.format.video.nFrameHeight = nFrameWidth;
1941                        m_sConfigFrameRotation.nRotation = pParam->nRotation;
1942                    }
1943                } else {
1944                    m_sConfigFrameRotation.nRotation = pParam->nRotation;
1945                }
1946
1947                // Update output-port resolution (since it might have been flipped by rotation)
1948                if (handle->venc_get_dimensions(PORT_INDEX_OUT,
1949                        &m_sOutPortDef.format.video.nFrameWidth,
1950                        &m_sOutPortDef.format.video.nFrameHeight)) {
1951                    DEBUG_PRINT_HIGH("set Rotation: updated dimensions = %u x %u",
1952                            m_sOutPortDef.format.video.nFrameWidth,
1953                            m_sOutPortDef.format.video.nFrameHeight);
1954                }
1955                break;
1956            }
1957        case OMX_QcomIndexConfigVideoFramePackingArrangement:
1958            {
1959                DEBUG_PRINT_HIGH("set_config(): OMX_QcomIndexConfigVideoFramePackingArrangement");
1960                if (m_sOutPortFormat.eCompressionFormat == OMX_VIDEO_CodingAVC) {
1961                    VALIDATE_OMX_PARAM_DATA(configData, OMX_QCOM_FRAME_PACK_ARRANGEMENT);
1962                    OMX_QCOM_FRAME_PACK_ARRANGEMENT *configFmt =
1963                        (OMX_QCOM_FRAME_PACK_ARRANGEMENT *) configData;
1964                    extra_data_handle.set_frame_pack_data(configFmt);
1965                } else {
1966                    DEBUG_PRINT_ERROR("ERROR: FramePackingData not supported for non AVC compression");
1967                }
1968                break;
1969            }
1970        case QOMX_IndexConfigVideoLTRPeriod:
1971            {
1972                VALIDATE_OMX_PARAM_DATA(configData, QOMX_VIDEO_CONFIG_LTRPERIOD_TYPE);
1973                QOMX_VIDEO_CONFIG_LTRPERIOD_TYPE* pParam = (QOMX_VIDEO_CONFIG_LTRPERIOD_TYPE*)configData;
1974                if (!handle->venc_set_config(configData, (OMX_INDEXTYPE)QOMX_IndexConfigVideoLTRPeriod)) {
1975                    DEBUG_PRINT_ERROR("ERROR: Setting LTR period failed");
1976                    return OMX_ErrorUnsupportedSetting;
1977                }
1978                memcpy(&m_sConfigLTRPeriod, pParam, sizeof(m_sConfigLTRPeriod));
1979                break;
1980            }
1981
1982       case OMX_IndexConfigVideoVp8ReferenceFrame:
1983           {
1984                VALIDATE_OMX_PARAM_DATA(configData, OMX_VIDEO_VP8REFERENCEFRAMETYPE);
1985               OMX_VIDEO_VP8REFERENCEFRAMETYPE* pParam = (OMX_VIDEO_VP8REFERENCEFRAMETYPE*) configData;
1986               if (!handle->venc_set_config(pParam, (OMX_INDEXTYPE) OMX_IndexConfigVideoVp8ReferenceFrame)) {
1987                   DEBUG_PRINT_ERROR("ERROR: Setting VP8 reference frame");
1988                   return OMX_ErrorUnsupportedSetting;
1989               }
1990               memcpy(&m_sConfigVp8ReferenceFrame, pParam, sizeof(m_sConfigVp8ReferenceFrame));
1991               break;
1992           }
1993
1994       case QOMX_IndexConfigVideoLTRUse:
1995            {
1996                VALIDATE_OMX_PARAM_DATA(configData, QOMX_VIDEO_CONFIG_LTRUSE_TYPE);
1997                QOMX_VIDEO_CONFIG_LTRUSE_TYPE* pParam = (QOMX_VIDEO_CONFIG_LTRUSE_TYPE*)configData;
1998                if (!handle->venc_set_config(pParam, (OMX_INDEXTYPE)QOMX_IndexConfigVideoLTRUse)) {
1999                    DEBUG_PRINT_ERROR("ERROR: Setting LTR use failed");
2000                    return OMX_ErrorUnsupportedSetting;
2001                }
2002                memcpy(&m_sConfigLTRUse, pParam, sizeof(m_sConfigLTRUse));
2003                break;
2004            }
2005        case QOMX_IndexConfigVideoLTRMark:
2006            {
2007                VALIDATE_OMX_PARAM_DATA(configData, QOMX_VIDEO_CONFIG_LTRMARK_TYPE);
2008                QOMX_VIDEO_CONFIG_LTRMARK_TYPE* pParam = (QOMX_VIDEO_CONFIG_LTRMARK_TYPE*)configData;
2009                if (!handle->venc_set_config(pParam, (OMX_INDEXTYPE)QOMX_IndexConfigVideoLTRMark)) {
2010                    DEBUG_PRINT_ERROR("ERROR: Setting LTR mark failed");
2011                    return OMX_ErrorUnsupportedSetting;
2012                }
2013                break;
2014            }
2015        case OMX_IndexConfigVideoAVCIntraPeriod:
2016            {
2017                VALIDATE_OMX_PARAM_DATA(configData, OMX_VIDEO_CONFIG_AVCINTRAPERIOD);
2018                OMX_VIDEO_CONFIG_AVCINTRAPERIOD *pParam = (OMX_VIDEO_CONFIG_AVCINTRAPERIOD*) configData;
2019                DEBUG_PRINT_LOW("set_config: OMX_IndexConfigVideoAVCIntraPeriod");
2020                if (!handle->venc_set_config(pParam, (OMX_INDEXTYPE)OMX_IndexConfigVideoAVCIntraPeriod)) {
2021                    DEBUG_PRINT_ERROR("ERROR: Setting OMX_IndexConfigVideoAVCIntraPeriod failed");
2022                    return OMX_ErrorUnsupportedSetting;
2023                }
2024                memcpy(&m_sConfigAVCIDRPeriod, pParam, sizeof(m_sConfigAVCIDRPeriod));
2025                break;
2026            }
2027        case OMX_IndexConfigCommonDeinterlace:
2028            {
2029                VALIDATE_OMX_PARAM_DATA(configData, OMX_VIDEO_CONFIG_DEINTERLACE);
2030                OMX_VIDEO_CONFIG_DEINTERLACE *pParam = (OMX_VIDEO_CONFIG_DEINTERLACE*) configData;
2031                DEBUG_PRINT_LOW("set_config: OMX_IndexConfigCommonDeinterlace");
2032                if (!handle->venc_set_config(pParam, (OMX_INDEXTYPE)OMX_IndexConfigCommonDeinterlace)) {
2033                    DEBUG_PRINT_ERROR("ERROR: Setting OMX_IndexConfigCommonDeinterlace failed");
2034                    return OMX_ErrorUnsupportedSetting;
2035                }
2036                memcpy(&m_sConfigDeinterlace, pParam, sizeof(m_sConfigDeinterlace));
2037                break;
2038            }
2039        case OMX_QcomIndexConfigVideoVencPerfMode:
2040            {
2041                VALIDATE_OMX_PARAM_DATA(configData, QOMX_EXTNINDEX_VIDEO_PERFMODE);
2042                QOMX_EXTNINDEX_VIDEO_PERFMODE* pParam = (QOMX_EXTNINDEX_VIDEO_PERFMODE*)configData;
2043                if (!handle->venc_set_config(pParam, (OMX_INDEXTYPE)OMX_QcomIndexConfigVideoVencPerfMode)) {
2044                    DEBUG_PRINT_ERROR("ERROR: Setting OMX_QcomIndexConfigVideoVencPerfMode failed");
2045                    return OMX_ErrorUnsupportedSetting;
2046                }
2047                break;
2048            }
2049        case OMX_QcomIndexConfigNumHierPLayers:
2050        {
2051            VALIDATE_OMX_PARAM_DATA(configData, QOMX_EXTNINDEX_VIDEO_HIER_P_LAYERS);
2052            QOMX_EXTNINDEX_VIDEO_HIER_P_LAYERS* pParam =
2053                (QOMX_EXTNINDEX_VIDEO_HIER_P_LAYERS*)configData;
2054            if (!handle->venc_set_config(pParam, (OMX_INDEXTYPE)OMX_QcomIndexConfigNumHierPLayers)) {
2055                DEBUG_PRINT_ERROR("ERROR: Setting OMX_QcomIndexConfigNumHierPLayers failed");
2056                return OMX_ErrorUnsupportedSetting;
2057            }
2058            memcpy(&m_sHPlayers, pParam, sizeof(m_sHPlayers));
2059            break;
2060        }
2061        case OMX_QcomIndexConfigBaseLayerId:
2062        {
2063            VALIDATE_OMX_PARAM_DATA(configData, OMX_SKYPE_VIDEO_CONFIG_BASELAYERPID);
2064            OMX_SKYPE_VIDEO_CONFIG_BASELAYERPID* pParam =
2065                (OMX_SKYPE_VIDEO_CONFIG_BASELAYERPID*) configData;
2066            if (!handle->venc_set_config(pParam, (OMX_INDEXTYPE)OMX_QcomIndexConfigBaseLayerId)) {
2067                DEBUG_PRINT_ERROR("ERROR: Setting OMX_QcomIndexConfigBaseLayerId failed");
2068                return OMX_ErrorUnsupportedSetting;
2069            }
2070            memcpy(&m_sBaseLayerID, pParam, sizeof(m_sBaseLayerID));
2071            break;
2072        }
2073        case OMX_QcomIndexConfigQp:
2074        {
2075            VALIDATE_OMX_PARAM_DATA(configData, OMX_SKYPE_VIDEO_CONFIG_QP);
2076            OMX_SKYPE_VIDEO_CONFIG_QP* pParam =
2077                (OMX_SKYPE_VIDEO_CONFIG_QP*) configData;
2078            if (!handle->venc_set_config(pParam, (OMX_INDEXTYPE)OMX_QcomIndexConfigQp)) {
2079                DEBUG_PRINT_ERROR("ERROR: Setting OMX_QcomIndexConfigQp failed");
2080                return OMX_ErrorUnsupportedSetting;
2081            }
2082            memcpy(&m_sConfigQP, pParam, sizeof(m_sConfigQP));
2083            break;
2084        }
2085        case OMX_IndexConfigPriority:
2086            {
2087                VALIDATE_OMX_PARAM_DATA(configData, OMX_PARAM_U32TYPE);
2088                if (!handle->venc_set_config(configData, (OMX_INDEXTYPE)OMX_IndexConfigPriority)) {
2089                    DEBUG_PRINT_ERROR("Failed to set OMX_IndexConfigPriority");
2090                    return OMX_ErrorUnsupportedSetting;
2091                }
2092                break;
2093            }
2094        case OMX_IndexConfigOperatingRate:
2095            {
2096                VALIDATE_OMX_PARAM_DATA(configData, OMX_PARAM_U32TYPE);
2097                if (!handle->venc_set_config(configData, (OMX_INDEXTYPE)OMX_IndexConfigOperatingRate)) {
2098                    DEBUG_PRINT_ERROR("Failed to set OMX_IndexConfigOperatingRate");
2099                    return handle->hw_overload ? OMX_ErrorInsufficientResources :
2100                            OMX_ErrorUnsupportedSetting;
2101                }
2102                break;
2103            }
2104        case OMX_QTIIndexConfigVideoRoiInfo:
2105            {
2106                VALIDATE_OMX_PARAM_DATA(configData, OMX_QTI_VIDEO_CONFIG_ROIINFO);
2107                if (!handle->venc_set_config(configData, (OMX_INDEXTYPE)OMX_QTIIndexConfigVideoRoiInfo)) {
2108                    DEBUG_PRINT_ERROR("Failed to set OMX_QTIIndexConfigVideoRoiInfo");
2109                    return OMX_ErrorUnsupportedSetting;
2110                }
2111                break;
2112            }
2113       case OMX_IndexConfigAndroidIntraRefresh:
2114           {
2115                VALIDATE_OMX_PARAM_DATA(configData, OMX_VIDEO_CONFIG_ANDROID_INTRAREFRESHTYPE);
2116                OMX_VIDEO_CONFIG_ANDROID_INTRAREFRESHTYPE* pParam =
2117                (OMX_VIDEO_CONFIG_ANDROID_INTRAREFRESHTYPE*) configData;
2118                if (m_state == OMX_StateLoaded
2119                        || m_sInPortDef.bEnabled == OMX_FALSE
2120                        || m_sOutPortDef.bEnabled == OMX_FALSE) {
2121                    if (!handle->venc_set_config(configData, (OMX_INDEXTYPE)OMX_IndexConfigAndroidIntraRefresh)) {
2122                        DEBUG_PRINT_ERROR("Failed to set OMX_IndexConfigVideoIntraRefreshType");
2123                        return OMX_ErrorUnsupportedSetting;
2124                    }
2125                    m_sConfigIntraRefresh.nRefreshPeriod = pParam->nRefreshPeriod;
2126               } else {
2127                    DEBUG_PRINT_ERROR("ERROR: Setting OMX_IndexConfigAndroidIntraRefresh supported only at start of session");
2128                    return OMX_ErrorUnsupportedSetting;
2129                }
2130               break;
2131           }
2132        case OMX_IndexConfigAndroidVideoTemporalLayering:
2133            {
2134                VALIDATE_OMX_PARAM_DATA(configData, OMX_VIDEO_CONFIG_ANDROID_TEMPORALLAYERINGTYPE);
2135                DEBUG_PRINT_ERROR("Setting/modifying Temporal layers at run-time is not supported !");
2136                return OMX_ErrorUnsupportedSetting;
2137            }
2138        case OMX_QTIIndexConfigDescribeColorAspects:
2139           {
2140               VALIDATE_OMX_PARAM_DATA(configData, DescribeColorAspectsParams);
2141               DescribeColorAspectsParams *params = (DescribeColorAspectsParams *)configData;
2142               print_debug_color_aspects(&(params->sAspects), "set_config");
2143               if (!handle->venc_set_config(configData, (OMX_INDEXTYPE)OMX_QTIIndexConfigDescribeColorAspects)) {
2144                   DEBUG_PRINT_ERROR("Failed to set OMX_QTIIndexConfigDescribeColorAspects");
2145                   return OMX_ErrorUnsupportedSetting;
2146               }
2147               memcpy(&m_sConfigColorAspects, configData, sizeof(m_sConfigColorAspects));
2148               break;
2149           }
2150        case OMX_IndexConfigAndroidVendorExtension:
2151            {
2152                VALIDATE_OMX_PARAM_DATA(configData, OMX_CONFIG_ANDROID_VENDOR_EXTENSIONTYPE);
2153
2154                OMX_CONFIG_ANDROID_VENDOR_EXTENSIONTYPE *ext =
2155                    reinterpret_cast<OMX_CONFIG_ANDROID_VENDOR_EXTENSIONTYPE *>(configData);
2156                VALIDATE_OMX_VENDOR_EXTENSION_PARAM_DATA(ext);
2157
2158                return set_vendor_extension_config(ext);
2159            }
2160
2161        default:
2162            DEBUG_PRINT_ERROR("ERROR: unsupported index %d", (int) configIndex);
2163            break;
2164    }
2165
2166    return OMX_ErrorNone;
2167}
2168
2169/* ======================================================================
2170   FUNCTION
2171   omx_venc::ComponentDeInit
2172
2173   DESCRIPTION
2174   Destroys the component and release memory allocated to the heap.
2175
2176   PARAMETERS
2177   <TBD>.
2178
2179   RETURN VALUE
2180   OMX Error None if everything successful.
2181
2182   ========================================================================== */
2183OMX_ERRORTYPE  omx_venc::component_deinit(OMX_IN OMX_HANDLETYPE hComp)
2184{
2185    (void) hComp;
2186    OMX_U32 i = 0;
2187    DEBUG_PRINT_HIGH("omx_venc(): Inside component_deinit()");
2188    if (OMX_StateLoaded != m_state) {
2189        DEBUG_PRINT_ERROR("WARNING:Rxd DeInit,OMX not in LOADED state %d",\
2190                m_state);
2191    }
2192    if (m_out_mem_ptr) {
2193        DEBUG_PRINT_LOW("Freeing the Output Memory");
2194        for (i=0; i< m_sOutPortDef.nBufferCountActual; i++ ) {
2195            if (BITMASK_PRESENT(&m_out_bm_count, i)) {
2196                BITMASK_CLEAR(&m_out_bm_count, i);
2197                free_output_buffer (&m_out_mem_ptr[i]);
2198            }
2199
2200            if (release_output_done()) {
2201                break;
2202            }
2203        }
2204        free(m_out_mem_ptr);
2205        m_out_mem_ptr = NULL;
2206    }
2207
2208    /*Check if the input buffers have to be cleaned up*/
2209    if (m_inp_mem_ptr
2210#ifdef _ANDROID_ICS_
2211            && !meta_mode_enable
2212#endif
2213       ) {
2214        DEBUG_PRINT_LOW("Freeing the Input Memory");
2215        for (i=0; i<m_sInPortDef.nBufferCountActual; i++ ) {
2216            if (BITMASK_PRESENT(&m_inp_bm_count, i)) {
2217                BITMASK_CLEAR(&m_inp_bm_count, i);
2218                free_input_buffer (&m_inp_mem_ptr[i]);
2219            }
2220
2221            if (release_input_done()) {
2222                break;
2223            }
2224        }
2225
2226
2227        free(m_inp_mem_ptr);
2228        m_inp_mem_ptr = NULL;
2229    }
2230
2231    // Reset counters in mesg queues
2232    m_ftb_q.m_size=0;
2233    m_cmd_q.m_size=0;
2234    m_etb_q.m_size=0;
2235    m_ftb_q.m_read = m_ftb_q.m_write =0;
2236    m_cmd_q.m_read = m_cmd_q.m_write =0;
2237    m_etb_q.m_read = m_etb_q.m_write =0;
2238
2239#ifdef _ANDROID_
2240    // Clear the strong reference
2241    DEBUG_PRINT_HIGH("Calling m_heap_ptr.clear()");
2242    m_heap_ptr.clear();
2243#endif // _ANDROID_
2244    DEBUG_PRINT_HIGH("Calling venc_close()");
2245    if (handle) {
2246        handle->venc_close();
2247        DEBUG_PRINT_HIGH("Deleting HANDLE[%p]", handle);
2248        delete (handle);
2249        handle = NULL;
2250    }
2251    DEBUG_PRINT_INFO("Component Deinit");
2252    return OMX_ErrorNone;
2253}
2254
2255
2256OMX_U32 omx_venc::dev_stop( void)
2257{
2258    return handle->venc_stop();
2259}
2260
2261
2262OMX_U32 omx_venc::dev_pause(void)
2263{
2264    return handle->venc_pause();
2265}
2266
2267OMX_U32 omx_venc::dev_start(void)
2268{
2269    return handle->venc_start();
2270}
2271
2272OMX_U32 omx_venc::dev_flush(unsigned port)
2273{
2274    return handle->venc_flush(port);
2275}
2276OMX_U32 omx_venc::dev_resume(void)
2277{
2278    return handle->venc_resume();
2279}
2280
2281OMX_U32 omx_venc::dev_start_done(void)
2282{
2283    return handle->venc_start_done();
2284}
2285
2286OMX_U32 omx_venc::dev_set_message_thread_id(pthread_t tid)
2287{
2288    return handle->venc_set_message_thread_id(tid);
2289}
2290
2291bool omx_venc::dev_use_buf(void *buf_addr,unsigned port,unsigned index)
2292{
2293    return handle->venc_use_buf(buf_addr,port,index);
2294}
2295
2296bool omx_venc::dev_free_buf(void *buf_addr,unsigned port)
2297{
2298    return handle->venc_free_buf(buf_addr,port);
2299}
2300
2301bool omx_venc::dev_empty_buf(void *buffer, void *pmem_data_buf,unsigned index,unsigned fd)
2302{
2303    bool bret = false;
2304    bret = handle->venc_empty_buf(buffer, pmem_data_buf,index,fd);
2305    hw_overload = handle->hw_overload;
2306    return bret;
2307}
2308
2309bool omx_venc::dev_fill_buf(void *buffer, void *pmem_data_buf,unsigned index,unsigned fd)
2310{
2311    return handle->venc_fill_buf(buffer, pmem_data_buf,index,fd);
2312}
2313
2314bool omx_venc::dev_get_seq_hdr(void *buffer, unsigned size, unsigned *hdrlen)
2315{
2316    return handle->venc_get_seq_hdr(buffer, size, hdrlen);
2317}
2318
2319bool omx_venc::dev_get_capability_ltrcount(OMX_U32 *min, OMX_U32 *max, OMX_U32 *step_size)
2320{
2321#ifdef _MSM8974_
2322    (void) min;
2323    (void) max;
2324    (void) step_size;
2325    DEBUG_PRINT_ERROR("Get Capability LTR Count is not supported");
2326    return false;
2327#else
2328    return handle->venc_get_capability_ltrcount(min, max, step_size);
2329#endif
2330}
2331
2332bool omx_venc::dev_get_performance_level(OMX_U32 *perflevel)
2333{
2334#ifdef _MSM8974_
2335    return handle->venc_get_performance_level(perflevel);
2336#else
2337    DEBUG_PRINT_ERROR("Get performance level is not supported");
2338    return false;
2339#endif
2340}
2341
2342bool omx_venc::dev_get_vui_timing_info(OMX_U32 *enabled)
2343{
2344#ifdef _MSM8974_
2345    return handle->venc_get_vui_timing_info(enabled);
2346#else
2347    DEBUG_PRINT_ERROR("Get vui timing information is not supported");
2348    return false;
2349#endif
2350}
2351
2352bool omx_venc::dev_get_vqzip_sei_info(OMX_U32 *enabled)
2353{
2354    return handle->venc_get_vqzip_sei_info(enabled);
2355}
2356
2357bool omx_venc::dev_get_peak_bitrate(OMX_U32 *peakbitrate)
2358{
2359#ifdef _MSM8974_
2360    return handle->venc_get_peak_bitrate(peakbitrate);
2361#else
2362    DEBUG_PRINT_ERROR("Get peak bitrate is not supported");
2363    return false;
2364#endif
2365}
2366
2367bool omx_venc::dev_get_batch_size(OMX_U32 *size)
2368{
2369#ifdef _MSM8974_
2370    return handle->venc_get_batch_size(size);
2371#else
2372    DEBUG_PRINT_ERROR("Get batch size is not supported");
2373    return false;
2374#endif
2375}
2376
2377bool omx_venc::dev_get_temporal_layer_caps(OMX_U32 *nMaxLayers,
2378        OMX_U32 *nMaxBLayers) {
2379    return handle->venc_get_temporal_layer_caps(nMaxLayers, nMaxBLayers);
2380}
2381
2382bool omx_venc::dev_loaded_start()
2383{
2384    return handle->venc_loaded_start();
2385}
2386
2387bool omx_venc::dev_loaded_stop()
2388{
2389    return handle->venc_loaded_stop();
2390}
2391
2392bool omx_venc::dev_loaded_start_done()
2393{
2394    return handle->venc_loaded_start_done();
2395}
2396
2397bool omx_venc::dev_loaded_stop_done()
2398{
2399    return handle->venc_loaded_stop_done();
2400}
2401
2402bool omx_venc::dev_get_buf_req(OMX_U32 *min_buff_count,
2403        OMX_U32 *actual_buff_count,
2404        OMX_U32 *buff_size,
2405        OMX_U32 port)
2406{
2407    return handle->venc_get_buf_req(min_buff_count,
2408            actual_buff_count,
2409            buff_size,
2410            port);
2411
2412}
2413
2414bool omx_venc::dev_set_buf_req(OMX_U32 *min_buff_count,
2415        OMX_U32 *actual_buff_count,
2416        OMX_U32 *buff_size,
2417        OMX_U32 port)
2418{
2419    return handle->venc_set_buf_req(min_buff_count,
2420            actual_buff_count,
2421            buff_size,
2422            port);
2423
2424}
2425
2426bool omx_venc::dev_is_video_session_supported(OMX_U32 width, OMX_U32 height)
2427{
2428#ifdef _MSM8974_
2429    return handle->venc_is_video_session_supported(width,height);
2430#else
2431    DEBUG_PRINT_LOW("Check against video capability not supported");
2432    return true;
2433#endif
2434}
2435
2436int omx_venc::dev_handle_output_extradata(void *buffer)
2437{
2438    return handle->handle_output_extradata(buffer);
2439}
2440
2441int omx_venc::dev_handle_input_extradata(void *buffer, int fd)
2442{
2443    return handle->handle_input_extradata(buffer, fd);
2444}
2445
2446void omx_venc::dev_set_extradata_cookie(void *cookie)
2447{
2448    handle->mInputExtradata.setCookieForConfig(cookie);
2449}
2450
2451int omx_venc::dev_set_format(int color)
2452{
2453    return handle->venc_set_format(color);
2454}
2455
2456int omx_venc::async_message_process (void *context, void* message)
2457{
2458    omx_video* omx = NULL;
2459    struct venc_msg *m_sVenc_msg = NULL;
2460    OMX_BUFFERHEADERTYPE* omxhdr = NULL;
2461    struct venc_buffer *temp_buff = NULL;
2462
2463    if (context == NULL || message == NULL) {
2464        DEBUG_PRINT_ERROR("ERROR: omx_venc::async_message_process invalid i/p params");
2465        return -1;
2466    }
2467    m_sVenc_msg = (struct venc_msg *)message;
2468
2469    omx = reinterpret_cast<omx_video*>(context);
2470
2471    if (m_sVenc_msg->statuscode != VEN_S_SUCCESS) {
2472        DEBUG_PRINT_ERROR("ERROR: async_msg_process() - Error statuscode = %lu",
2473                m_sVenc_msg->statuscode);
2474        if(m_sVenc_msg->msgcode == VEN_MSG_HW_OVERLOAD) {
2475            omx->post_event (0, m_sVenc_msg->statuscode,\
2476                    OMX_COMPONENT_GENERATE_HARDWARE_OVERLOAD);
2477        } else {
2478            omx->post_event (0, m_sVenc_msg->statuscode,\
2479                    OMX_COMPONENT_GENERATE_HARDWARE_ERROR);
2480        }
2481    }
2482
2483    DEBUG_PRINT_LOW("omx_venc::async_message_process- msgcode = %lu",
2484            m_sVenc_msg->msgcode);
2485    switch (m_sVenc_msg->msgcode) {
2486        case VEN_MSG_START:
2487            omx->post_event (0,m_sVenc_msg->statuscode,\
2488                    OMX_COMPONENT_GENERATE_START_DONE);
2489            break;
2490        case VEN_MSG_STOP:
2491            omx->post_event (0,m_sVenc_msg->statuscode,\
2492                    OMX_COMPONENT_GENERATE_STOP_DONE);
2493            break;
2494        case VEN_MSG_RESUME:
2495            omx->post_event (0,m_sVenc_msg->statuscode,\
2496                    OMX_COMPONENT_GENERATE_RESUME_DONE);
2497            break;
2498        case VEN_MSG_PAUSE:
2499            omx->post_event (0,m_sVenc_msg->statuscode,\
2500                    OMX_COMPONENT_GENERATE_PAUSE_DONE);
2501            break;
2502        case VEN_MSG_FLUSH_INPUT_DONE:
2503
2504            omx->post_event (0,m_sVenc_msg->statuscode,\
2505                    OMX_COMPONENT_GENERATE_EVENT_INPUT_FLUSH);
2506            break;
2507        case VEN_MSG_FLUSH_OUPUT_DONE:
2508            omx->post_event (0,m_sVenc_msg->statuscode,\
2509                    OMX_COMPONENT_GENERATE_EVENT_OUTPUT_FLUSH);
2510            break;
2511        case VEN_MSG_INPUT_BUFFER_DONE:
2512            omxhdr = (OMX_BUFFERHEADERTYPE* )\
2513                     m_sVenc_msg->buf.clientdata;
2514
2515            if (omxhdr == NULL ||
2516                    (((OMX_U32)(omxhdr - omx->m_inp_mem_ptr) > omx->m_sInPortDef.nBufferCountActual) &&
2517                     ((OMX_U32)(omxhdr - omx->meta_buffer_hdr) > omx->m_sInPortDef.nBufferCountActual))) {
2518                omxhdr = NULL;
2519                m_sVenc_msg->statuscode = VEN_S_EFAIL;
2520            }
2521
2522#ifdef _ANDROID_ICS_
2523            omx->omx_release_meta_buffer(omxhdr);
2524#endif
2525            omx->post_event ((unsigned long)omxhdr,m_sVenc_msg->statuscode,
2526                    OMX_COMPONENT_GENERATE_EBD);
2527            break;
2528        case VEN_MSG_OUTPUT_BUFFER_DONE:
2529            omxhdr = (OMX_BUFFERHEADERTYPE*)m_sVenc_msg->buf.clientdata;
2530
2531            if ( (omxhdr != NULL) &&
2532                    ((OMX_U32)(omxhdr - omx->m_out_mem_ptr)  < omx->m_sOutPortDef.nBufferCountActual)) {
2533                if (m_sVenc_msg->buf.len <=  omxhdr->nAllocLen) {
2534                    omxhdr->nFilledLen = m_sVenc_msg->buf.len;
2535                    omxhdr->nOffset = m_sVenc_msg->buf.offset;
2536                    omxhdr->nTimeStamp = m_sVenc_msg->buf.timestamp;
2537                    DEBUG_PRINT_LOW("o/p TS = %u", (unsigned int)m_sVenc_msg->buf.timestamp);
2538                    omxhdr->nFlags = m_sVenc_msg->buf.flags;
2539
2540                    /*Use buffer case*/
2541                    if (omx->output_use_buffer && !omx->m_use_output_pmem && !omx->is_secure_session()) {
2542                        DEBUG_PRINT_LOW("memcpy() for o/p Heap UseBuffer");
2543                        memcpy(omxhdr->pBuffer,
2544                                (m_sVenc_msg->buf.ptrbuffer),
2545                                m_sVenc_msg->buf.len);
2546                    }
2547                } else {
2548                    omxhdr->nFilledLen = 0;
2549                }
2550
2551            } else {
2552                omxhdr = NULL;
2553                m_sVenc_msg->statuscode = VEN_S_EFAIL;
2554            }
2555            omx->post_event ((unsigned long)omxhdr,m_sVenc_msg->statuscode,
2556                    OMX_COMPONENT_GENERATE_FBD);
2557            break;
2558        case VEN_MSG_NEED_OUTPUT_BUFFER:
2559            //TBD what action needs to be done here??
2560            break;
2561#ifndef _MSM8974_
2562        case VEN_MSG_LTRUSE_FAILED:
2563            DEBUG_PRINT_ERROR("LTRUSE Failed!");
2564            omx->post_event (NULL,m_sVenc_msg->statuscode,
2565                    OMX_COMPONENT_GENERATE_LTRUSE_FAILED);
2566            break;
2567#endif
2568        default:
2569            DEBUG_PRINT_HIGH("Unknown msg received : %lu", m_sVenc_msg->msgcode);
2570            break;
2571    }
2572    return 0;
2573}
2574
2575bool omx_venc::dev_color_align(OMX_BUFFERHEADERTYPE *buffer,
2576                OMX_U32 width, OMX_U32 height)
2577{
2578    if(secure_session) {
2579        DEBUG_PRINT_ERROR("Cannot align colors in secure session.");
2580        return OMX_FALSE;
2581    }
2582    return handle->venc_color_align(buffer, width,height);
2583}
2584
2585bool omx_venc::is_secure_session()
2586{
2587    return secure_session;
2588}
2589
2590bool omx_venc::dev_get_output_log_flag()
2591{
2592    return handle->venc_get_output_log_flag();
2593}
2594
2595int omx_venc::dev_output_log_buffers(const char *buffer, int bufferlen)
2596{
2597    return handle->venc_output_log_buffers(buffer, bufferlen);
2598}
2599
2600int omx_venc::dev_extradata_log_buffers(char *buffer)
2601{
2602    return handle->venc_extradata_log_buffers(buffer);
2603}
2604