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