1 /*--------------------------------------------------------------------------
2 Copyright (c) 2010-2012, 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 Code Aurora 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 "video_encoder_device.h"
31 #include <stdio.h>
32 #ifdef _ANDROID_ICS_
33 #include <media/hardware/HardwareAPI.h>
34 #endif
35 #ifdef _ANDROID_
36 #include <cutils/properties.h>
37 #endif
38 #ifndef _ANDROID_
39 #include <glib.h>
40 #define strlcpy g_strlcpy
41 #endif
42 /*----------------------------------------------------------------------------
43 * Preprocessor Definitions and Constants
44 * -------------------------------------------------------------------------*/
45
46 #define OMX_SPEC_VERSION 0x00000101
47 #define OMX_INIT_STRUCT(_s_, _name_) \
48 memset((_s_), 0x0, sizeof(_name_)); \
49 (_s_)->nSize = sizeof(_name_); \
50 (_s_)->nVersion.nVersion = OMX_SPEC_VERSION
51
52 extern int m_pipe;
53
54 // factory function executed by the core to create instances
get_omx_component_factory_fn(void)55 void *get_omx_component_factory_fn(void)
56 {
57 return(new omx_venc);
58 }
59
60 //constructor
61
omx_venc()62 omx_venc::omx_venc()
63 {
64 #ifdef _ANDROID_ICS_
65 meta_mode_enable = false;
66 memset(meta_buffer_hdr,0,sizeof(meta_buffer_hdr));
67 memset(meta_buffers,0,sizeof(meta_buffers));
68 memset(opaque_buffer_hdr,0,sizeof(opaque_buffer_hdr));
69 mUseProxyColorFormat = false;
70 #endif
71 }
72
~omx_venc()73 omx_venc::~omx_venc()
74 {
75 //nothing to do
76 }
77
78 /* ======================================================================
79 FUNCTION
80 omx_venc::ComponentInit
81
82 DESCRIPTION
83 Initialize the component.
84
85 PARAMETERS
86 ctxt -- Context information related to the self.
87 id -- Event identifier. This could be any of the following:
88 1. Command completion event
89 2. Buffer done callback event
90 3. Frame done callback event
91
92 RETURN VALUE
93 None.
94
95 ========================================================================== */
component_init(OMX_STRING role)96 OMX_ERRORTYPE omx_venc::component_init(OMX_STRING role)
97 {
98
99 OMX_ERRORTYPE eRet = OMX_ErrorNone;
100
101 int fds[2];
102 int r;
103
104 OMX_VIDEO_CODINGTYPE codec_type;
105
106 DEBUG_PRINT_HIGH("\n omx_venc(): Inside component_init()");
107 // Copy the role information which provides the decoder m_nkind
108 strlcpy((char *)m_nkind,role,OMX_MAX_STRINGNAME_SIZE);
109
110 if(!strncmp((char *)m_nkind,"OMX.qcom.video.encoder.mpeg4",\
111 OMX_MAX_STRINGNAME_SIZE))
112 {
113 strlcpy((char *)m_cRole, "video_encoder.mpeg4",\
114 OMX_MAX_STRINGNAME_SIZE);
115 codec_type = OMX_VIDEO_CodingMPEG4;
116 }
117 else if(!strncmp((char *)m_nkind, "OMX.qcom.video.encoder.h263",\
118 OMX_MAX_STRINGNAME_SIZE))
119 {
120 strlcpy((char *)m_cRole, "video_encoder.h263",OMX_MAX_STRINGNAME_SIZE);
121 codec_type = OMX_VIDEO_CodingH263;
122 }
123 else if(!strncmp((char *)m_nkind, "OMX.qcom.video.encoder.avc",\
124 OMX_MAX_STRINGNAME_SIZE))
125 {
126 strlcpy((char *)m_cRole, "video_encoder.avc",OMX_MAX_STRINGNAME_SIZE);
127 codec_type = OMX_VIDEO_CodingAVC;
128 }
129 else if(!strncmp((char *)m_nkind, "OMX.qcom.video.encoder.avc.secure",\
130 OMX_MAX_STRINGNAME_SIZE))
131 {
132 strlcpy((char *)m_cRole, "video_encoder.avc",OMX_MAX_STRINGNAME_SIZE);
133 codec_type = OMX_VIDEO_CodingAVC;
134 secure_session = true;
135 }
136 else
137 {
138 DEBUG_PRINT_ERROR("\nERROR: Unknown Component\n");
139 eRet = OMX_ErrorInvalidComponentName;
140 }
141
142
143 if(eRet != OMX_ErrorNone)
144 {
145 return eRet;
146 }
147
148 handle = new venc_dev(this);
149
150 if(handle == NULL)
151 {
152 DEBUG_PRINT_ERROR("\nERROR: handle is NULL");
153 return OMX_ErrorInsufficientResources;
154 }
155
156 if(handle->venc_open(codec_type) != true)
157 {
158 DEBUG_PRINT_ERROR("\nERROR: venc_open failed");
159 return OMX_ErrorInsufficientResources;
160 }
161
162 //Intialise the OMX layer variables
163 memset(&m_pCallbacks,0,sizeof(OMX_CALLBACKTYPE));
164
165 OMX_INIT_STRUCT(&m_sPortParam, OMX_PORT_PARAM_TYPE);
166 m_sPortParam.nPorts = 0x2;
167 m_sPortParam.nStartPortNumber = (OMX_U32) PORT_INDEX_IN;
168
169 OMX_INIT_STRUCT(&m_sPortParam_audio, OMX_PORT_PARAM_TYPE);
170 m_sPortParam_audio.nPorts = 0;
171 m_sPortParam_audio.nStartPortNumber = 0;
172
173 OMX_INIT_STRUCT(&m_sPortParam_img, OMX_PORT_PARAM_TYPE);
174 m_sPortParam_img.nPorts = 0;
175 m_sPortParam_img.nStartPortNumber = 0;
176
177 OMX_INIT_STRUCT(&m_sParamBitrate, OMX_VIDEO_PARAM_BITRATETYPE);
178 m_sParamBitrate.nPortIndex = (OMX_U32) PORT_INDEX_OUT;
179 m_sParamBitrate.eControlRate = OMX_Video_ControlRateVariableSkipFrames;
180 m_sParamBitrate.nTargetBitrate = 64000;
181
182 OMX_INIT_STRUCT(&m_sConfigBitrate, OMX_VIDEO_CONFIG_BITRATETYPE);
183 m_sConfigBitrate.nPortIndex = (OMX_U32) PORT_INDEX_OUT;
184 m_sConfigBitrate.nEncodeBitrate = 64000;
185
186 OMX_INIT_STRUCT(&m_sConfigFramerate, OMX_CONFIG_FRAMERATETYPE);
187 m_sConfigFramerate.nPortIndex = (OMX_U32) PORT_INDEX_OUT;
188 m_sConfigFramerate.xEncodeFramerate = 30 << 16;
189
190 OMX_INIT_STRUCT(&m_sConfigIntraRefreshVOP, OMX_CONFIG_INTRAREFRESHVOPTYPE);
191 m_sConfigIntraRefreshVOP.nPortIndex = (OMX_U32) PORT_INDEX_OUT;
192 m_sConfigIntraRefreshVOP.IntraRefreshVOP = OMX_FALSE;
193
194 OMX_INIT_STRUCT(&m_sConfigFrameRotation, OMX_CONFIG_ROTATIONTYPE);
195 m_sConfigFrameRotation.nPortIndex = (OMX_U32) PORT_INDEX_IN;
196 m_sConfigFrameRotation.nRotation = 0;
197
198 OMX_INIT_STRUCT(&m_sSessionQuantization, OMX_VIDEO_PARAM_QUANTIZATIONTYPE);
199 m_sSessionQuantization.nPortIndex = (OMX_U32) PORT_INDEX_OUT;
200 m_sSessionQuantization.nQpI = 9;
201 m_sSessionQuantization.nQpP = 6;
202 m_sSessionQuantization.nQpB = 2;
203
204 OMX_INIT_STRUCT(&m_sAVCSliceFMO, OMX_VIDEO_PARAM_AVCSLICEFMO);
205 m_sAVCSliceFMO.nPortIndex = (OMX_U32) PORT_INDEX_OUT;
206 m_sAVCSliceFMO.eSliceMode = OMX_VIDEO_SLICEMODE_AVCDefault;
207 m_sAVCSliceFMO.nNumSliceGroups = 0;
208 m_sAVCSliceFMO.nSliceGroupMapType = 0;
209 OMX_INIT_STRUCT(&m_sParamProfileLevel, OMX_VIDEO_PARAM_PROFILELEVELTYPE);
210 m_sParamProfileLevel.nPortIndex = (OMX_U32) PORT_INDEX_OUT;
211
212 OMX_INIT_STRUCT(&m_sIntraperiod, QOMX_VIDEO_INTRAPERIODTYPE);
213 m_sIntraperiod.nPortIndex = (OMX_U32) PORT_INDEX_OUT;
214 m_sIntraperiod.nPFrames = (m_sConfigFramerate.xEncodeFramerate * 2) - 1;
215
216 OMX_INIT_STRUCT(&m_sErrorCorrection, OMX_VIDEO_PARAM_ERRORCORRECTIONTYPE);
217 m_sErrorCorrection.nPortIndex = (OMX_U32) PORT_INDEX_OUT;
218 m_sErrorCorrection.bEnableDataPartitioning = OMX_FALSE;
219 m_sErrorCorrection.bEnableHEC = OMX_FALSE;
220 m_sErrorCorrection.bEnableResync = OMX_FALSE;
221 m_sErrorCorrection.bEnableRVLC = OMX_FALSE;
222 m_sErrorCorrection.nResynchMarkerSpacing = 0;
223
224 OMX_INIT_STRUCT(&m_sIntraRefresh, OMX_VIDEO_PARAM_INTRAREFRESHTYPE);
225 m_sIntraRefresh.nPortIndex = (OMX_U32) PORT_INDEX_OUT;
226 m_sIntraRefresh.eRefreshMode = OMX_VIDEO_IntraRefreshMax;
227
228 if(codec_type == OMX_VIDEO_CodingMPEG4)
229 {
230 m_sParamProfileLevel.eProfile = (OMX_U32) OMX_VIDEO_MPEG4ProfileSimple;
231 m_sParamProfileLevel.eLevel = (OMX_U32) OMX_VIDEO_MPEG4Level0;
232 }
233 else if(codec_type == OMX_VIDEO_CodingH263)
234 {
235 m_sParamProfileLevel.eProfile = (OMX_U32) OMX_VIDEO_H263ProfileBaseline;
236 m_sParamProfileLevel.eLevel = (OMX_U32) OMX_VIDEO_H263Level10;
237 }
238 else if(codec_type == OMX_VIDEO_CodingAVC)
239 {
240 m_sParamProfileLevel.eProfile = (OMX_U32) OMX_VIDEO_AVCProfileBaseline;
241 m_sParamProfileLevel.eLevel = (OMX_U32) OMX_VIDEO_AVCLevel1;
242 }
243
244 // Initialize the video parameters for input port
245 OMX_INIT_STRUCT(&m_sInPortDef, OMX_PARAM_PORTDEFINITIONTYPE);
246 m_sInPortDef.nPortIndex= (OMX_U32) PORT_INDEX_IN;
247 m_sInPortDef.bEnabled = OMX_TRUE;
248 m_sInPortDef.bPopulated = OMX_FALSE;
249 m_sInPortDef.eDomain = OMX_PortDomainVideo;
250 m_sInPortDef.eDir = OMX_DirInput;
251 m_sInPortDef.format.video.cMIMEType = "YUV420";
252 m_sInPortDef.format.video.nFrameWidth = OMX_CORE_QCIF_WIDTH;
253 m_sInPortDef.format.video.nFrameHeight = OMX_CORE_QCIF_HEIGHT;
254 m_sInPortDef.format.video.nStride = OMX_CORE_QCIF_WIDTH;
255 m_sInPortDef.format.video.nSliceHeight = OMX_CORE_QCIF_HEIGHT;
256 m_sInPortDef.format.video.nBitrate = 64000;
257 m_sInPortDef.format.video.xFramerate = 15 << 16;
258 m_sInPortDef.format.video.eColorFormat = OMX_COLOR_FormatYUV420SemiPlanar;
259 m_sInPortDef.format.video.eCompressionFormat = OMX_VIDEO_CodingUnused;
260
261 if(dev_get_buf_req(&m_sInPortDef.nBufferCountMin,
262 &m_sInPortDef.nBufferCountActual,
263 &m_sInPortDef.nBufferSize,
264 m_sInPortDef.nPortIndex) != true)
265 {
266 eRet = OMX_ErrorUndefined;
267
268 }
269
270 // Initialize the video parameters for output port
271 OMX_INIT_STRUCT(&m_sOutPortDef, OMX_PARAM_PORTDEFINITIONTYPE);
272 m_sOutPortDef.nPortIndex = (OMX_U32) PORT_INDEX_OUT;
273 m_sOutPortDef.bEnabled = OMX_TRUE;
274 m_sOutPortDef.bPopulated = OMX_FALSE;
275 m_sOutPortDef.eDomain = OMX_PortDomainVideo;
276 m_sOutPortDef.eDir = OMX_DirOutput;
277 m_sOutPortDef.format.video.nFrameWidth = OMX_CORE_QCIF_WIDTH;
278 m_sOutPortDef.format.video.nFrameHeight = OMX_CORE_QCIF_HEIGHT;
279 m_sOutPortDef.format.video.nBitrate = 64000;
280 m_sOutPortDef.format.video.xFramerate = 15 << 16;
281 m_sOutPortDef.format.video.eColorFormat = OMX_COLOR_FormatUnused;
282 if(codec_type == OMX_VIDEO_CodingMPEG4)
283 {
284 m_sOutPortDef.format.video.eCompressionFormat = OMX_VIDEO_CodingMPEG4;
285 }
286 else if(codec_type == OMX_VIDEO_CodingH263)
287 {
288 m_sOutPortDef.format.video.eCompressionFormat = OMX_VIDEO_CodingH263;
289 }
290 else
291 {
292 m_sOutPortDef.format.video.eCompressionFormat = OMX_VIDEO_CodingAVC;
293 }
294 if(dev_get_buf_req(&m_sOutPortDef.nBufferCountMin,
295 &m_sOutPortDef.nBufferCountActual,
296 &m_sOutPortDef.nBufferSize,
297 m_sOutPortDef.nPortIndex) != true)
298 {
299 eRet = OMX_ErrorUndefined;
300 }
301
302 // Initialize the video color format for input port
303 OMX_INIT_STRUCT(&m_sInPortFormat, OMX_VIDEO_PARAM_PORTFORMATTYPE);
304 m_sInPortFormat.nPortIndex = (OMX_U32) PORT_INDEX_IN;
305 m_sInPortFormat.nIndex = 0;
306 m_sInPortFormat.eColorFormat = OMX_COLOR_FormatYUV420SemiPlanar;
307 m_sInPortFormat.eCompressionFormat = OMX_VIDEO_CodingUnused;
308
309
310 // Initialize the compression format for output port
311 OMX_INIT_STRUCT(&m_sOutPortFormat, OMX_VIDEO_PARAM_PORTFORMATTYPE);
312 m_sOutPortFormat.nPortIndex = (OMX_U32) PORT_INDEX_OUT;
313 m_sOutPortFormat.nIndex = 0;
314 m_sOutPortFormat.eColorFormat = OMX_COLOR_FormatUnused;
315 if(codec_type == OMX_VIDEO_CodingMPEG4)
316 {
317 m_sOutPortFormat.eCompressionFormat = OMX_VIDEO_CodingMPEG4;
318 }
319 else if(codec_type == OMX_VIDEO_CodingH263)
320 {
321 m_sOutPortFormat.eCompressionFormat = OMX_VIDEO_CodingH263;
322 }
323 else
324 {
325 m_sOutPortFormat.eCompressionFormat = OMX_VIDEO_CodingAVC;
326 }
327
328 // mandatory Indices for kronos test suite
329 OMX_INIT_STRUCT(&m_sPriorityMgmt, OMX_PRIORITYMGMTTYPE);
330
331 OMX_INIT_STRUCT(&m_sInBufSupplier, OMX_PARAM_BUFFERSUPPLIERTYPE);
332 m_sInBufSupplier.nPortIndex = (OMX_U32) PORT_INDEX_IN;
333
334 OMX_INIT_STRUCT(&m_sOutBufSupplier, OMX_PARAM_BUFFERSUPPLIERTYPE);
335 m_sOutBufSupplier.nPortIndex = (OMX_U32) PORT_INDEX_OUT;
336
337
338 // mp4 specific init
339 OMX_INIT_STRUCT(&m_sParamMPEG4, OMX_VIDEO_PARAM_MPEG4TYPE);
340 m_sParamMPEG4.nPortIndex = (OMX_U32) PORT_INDEX_OUT;
341 m_sParamMPEG4.eProfile = OMX_VIDEO_MPEG4ProfileSimple;
342 m_sParamMPEG4.eLevel = OMX_VIDEO_MPEG4Level0;
343 m_sParamMPEG4.nSliceHeaderSpacing = 0;
344 m_sParamMPEG4.bSVH = OMX_FALSE;
345 m_sParamMPEG4.bGov = OMX_FALSE;
346 m_sParamMPEG4.nPFrames = (m_sOutPortFormat.xFramerate * 2 - 1); // 2 second intra period for default outport fps
347 m_sParamMPEG4.bACPred = OMX_TRUE;
348 m_sParamMPEG4.nTimeIncRes = 30; // delta = 2 @ 15 fps
349 m_sParamMPEG4.nAllowedPictureTypes = 2; // pframe and iframe
350 m_sParamMPEG4.nHeaderExtension = 1; // number of video packet headers per vop
351 m_sParamMPEG4.bReversibleVLC = OMX_FALSE;
352
353 // h263 specific init
354 OMX_INIT_STRUCT(&m_sParamH263, OMX_VIDEO_PARAM_H263TYPE);
355 m_sParamH263.nPortIndex = (OMX_U32) PORT_INDEX_OUT;
356 m_sParamH263.nPFrames = (m_sOutPortFormat.xFramerate * 2 - 1); // 2 second intra period for default outport fps
357 m_sParamH263.nBFrames = 0;
358 m_sParamH263.eProfile = OMX_VIDEO_H263ProfileBaseline;
359 m_sParamH263.eLevel = OMX_VIDEO_H263Level10;
360 m_sParamH263.bPLUSPTYPEAllowed = OMX_FALSE;
361 m_sParamH263.nAllowedPictureTypes = 2;
362 m_sParamH263.bForceRoundingTypeToZero = OMX_TRUE;
363 m_sParamH263.nPictureHeaderRepetition = 0;
364 m_sParamH263.nGOBHeaderInterval = 1;
365
366 // h264 specific init
367 OMX_INIT_STRUCT(&m_sParamAVC, OMX_VIDEO_PARAM_AVCTYPE);
368 m_sParamAVC.nPortIndex = (OMX_U32) PORT_INDEX_OUT;
369 m_sParamAVC.nSliceHeaderSpacing = 0;
370 m_sParamAVC.nPFrames = (m_sOutPortFormat.xFramerate * 2 - 1); // 2 second intra period for default outport fps
371 m_sParamAVC.nBFrames = 0;
372 m_sParamAVC.bUseHadamard = OMX_FALSE;
373 m_sParamAVC.nRefFrames = 1;
374 m_sParamAVC.nRefIdx10ActiveMinus1 = 1;
375 m_sParamAVC.nRefIdx11ActiveMinus1 = 0;
376 m_sParamAVC.bEnableUEP = OMX_FALSE;
377 m_sParamAVC.bEnableFMO = OMX_FALSE;
378 m_sParamAVC.bEnableASO = OMX_FALSE;
379 m_sParamAVC.bEnableRS = OMX_FALSE;
380 m_sParamAVC.eProfile = OMX_VIDEO_AVCProfileBaseline;
381 m_sParamAVC.eLevel = OMX_VIDEO_AVCLevel1;
382 m_sParamAVC.nAllowedPictureTypes = 2;
383 m_sParamAVC.bFrameMBsOnly = OMX_FALSE;
384 m_sParamAVC.bMBAFF = OMX_FALSE;
385 m_sParamAVC.bEntropyCodingCABAC = OMX_FALSE;
386 m_sParamAVC.bWeightedPPrediction = OMX_FALSE;
387 m_sParamAVC.nWeightedBipredicitonMode = 0;
388 m_sParamAVC.bconstIpred = OMX_FALSE;
389 m_sParamAVC.bDirect8x8Inference = OMX_FALSE;
390 m_sParamAVC.bDirectSpatialTemporal = OMX_FALSE;
391 m_sParamAVC.nCabacInitIdc = 0;
392 m_sParamAVC.eLoopFilterMode = OMX_VIDEO_AVCLoopFilterEnable;
393
394 m_state = OMX_StateLoaded;
395 m_sExtraData = 0;
396 m_sDebugSliceinfo = 0;
397 #ifdef _ANDROID_
398 char value[PROPERTY_VALUE_MAX] = {0};
399 property_get("vidc.venc.debug.sliceinfo", value, "0");
400 m_sDebugSliceinfo = (OMX_U32)atoi(value);
401 DEBUG_PRINT_HIGH("vidc.venc.debug.sliceinfo value is %d", m_sDebugSliceinfo);
402 #endif
403
404 if(eRet == OMX_ErrorNone)
405 {
406 if(pipe(fds))
407 {
408 DEBUG_PRINT_ERROR("ERROR: pipe creation failed\n");
409 eRet = OMX_ErrorInsufficientResources;
410 }
411 else
412 {
413 if(fds[0] == 0 || fds[1] == 0)
414 {
415 if(pipe(fds))
416 {
417 DEBUG_PRINT_ERROR("ERROR: pipe creation failed\n");
418 eRet = OMX_ErrorInsufficientResources;
419 }
420 }
421 if(eRet == OMX_ErrorNone)
422 {
423 m_pipe_in = fds[0];
424 m_pipe_out = fds[1];
425 }
426 }
427 r = pthread_create(&msg_thread_id,0,message_thread,this);
428
429 if(r < 0)
430 {
431 eRet = OMX_ErrorInsufficientResources;
432 }
433 else
434 {
435 r = pthread_create(&async_thread_id,0,async_venc_message_thread,this);
436 if(r < 0)
437 {
438 eRet = OMX_ErrorInsufficientResources;
439 }
440 }
441 }
442
443 DEBUG_PRINT_HIGH("\n Component_init return value = 0x%x", eRet);
444 return eRet;
445 }
446
447
448 /* ======================================================================
449 FUNCTION
450 omx_venc::Setparameter
451
452 DESCRIPTION
453 OMX Set Parameter method implementation.
454
455 PARAMETERS
456 <TBD>.
457
458 RETURN VALUE
459 OMX Error None if successful.
460
461 ========================================================================== */
set_parameter(OMX_IN OMX_HANDLETYPE hComp,OMX_IN OMX_INDEXTYPE paramIndex,OMX_IN OMX_PTR paramData)462 OMX_ERRORTYPE omx_venc::set_parameter(OMX_IN OMX_HANDLETYPE hComp,
463 OMX_IN OMX_INDEXTYPE paramIndex,
464 OMX_IN OMX_PTR paramData)
465 {
466 OMX_ERRORTYPE eRet = OMX_ErrorNone;
467
468
469 if(m_state == OMX_StateInvalid)
470 {
471 DEBUG_PRINT_ERROR("ERROR: Set Param in Invalid State\n");
472 return OMX_ErrorInvalidState;
473 }
474 if(paramData == NULL)
475 {
476 DEBUG_PRINT_ERROR("ERROR: Get Param in Invalid paramData \n");
477 return OMX_ErrorBadParameter;
478 }
479
480 /*set_parameter can be called in loaded state
481 or disabled port */
482 if(m_state == OMX_StateLoaded
483 || m_sInPortDef.bEnabled == OMX_FALSE
484 || m_sOutPortDef.bEnabled == OMX_FALSE)
485 {
486 DEBUG_PRINT_LOW("Set Parameter called in valid state");
487 }
488 else
489 {
490 DEBUG_PRINT_ERROR("ERROR: Set Parameter called in Invalid State\n");
491 return OMX_ErrorIncorrectStateOperation;
492 }
493
494 switch(paramIndex)
495 {
496 case OMX_IndexParamPortDefinition:
497 {
498 OMX_PARAM_PORTDEFINITIONTYPE *portDefn;
499 portDefn = (OMX_PARAM_PORTDEFINITIONTYPE *) paramData;
500 DEBUG_PRINT_LOW("set_parameter: OMX_IndexParamPortDefinition H= %d, W = %d\n",
501 (int)portDefn->format.video.nFrameHeight,
502 (int)portDefn->format.video.nFrameWidth);
503
504 if(PORT_INDEX_IN == portDefn->nPortIndex)
505 {
506 DEBUG_PRINT_LOW("\n i/p actual cnt requested = %d\n", portDefn->nBufferCountActual);
507 DEBUG_PRINT_LOW("\n i/p min cnt requested = %d\n", portDefn->nBufferCountMin);
508 DEBUG_PRINT_LOW("\n i/p buffersize requested = %d\n", portDefn->nBufferSize);
509 if(handle->venc_set_param(paramData,OMX_IndexParamPortDefinition) != true)
510 {
511 DEBUG_PRINT_ERROR("\nERROR: venc_set_param input failed");
512 return OMX_ErrorUnsupportedSetting;
513 }
514
515 DEBUG_PRINT_LOW("\n i/p previous actual cnt = %d\n", m_sInPortDef.nBufferCountActual);
516 DEBUG_PRINT_LOW("\n i/p previous min cnt = %d\n", m_sInPortDef.nBufferCountMin);
517 memcpy(&m_sInPortDef, portDefn,sizeof(OMX_PARAM_PORTDEFINITIONTYPE));
518
519 #ifdef _ANDROID_ICS_
520 if (portDefn->format.video.eColorFormat == (OMX_COLOR_FORMATTYPE)QOMX_COLOR_FormatAndroidOpaque) {
521 m_sInPortDef.format.video.eColorFormat =
522 OMX_COLOR_FormatYUV420SemiPlanar;
523 if(secure_session) {
524 secure_color_format = (int) QOMX_COLOR_FormatAndroidOpaque;
525 mUseProxyColorFormat = false;
526 m_input_msg_id = OMX_COMPONENT_GENERATE_ETB;
527 } else if(!mUseProxyColorFormat){
528 if (!c2d_conv.init()) {
529 DEBUG_PRINT_ERROR("\n C2D init failed");
530 return OMX_ErrorUnsupportedSetting;
531 }
532 DEBUG_PRINT_ERROR("\nC2D init is successful");
533 mUseProxyColorFormat = true;
534 m_input_msg_id = OMX_COMPONENT_GENERATE_ETB_OPQ;
535 }
536 } else
537 mUseProxyColorFormat = false;
538 #endif
539 /*Query Input Buffer Requirements*/
540 dev_get_buf_req (&m_sInPortDef.nBufferCountMin,
541 &m_sInPortDef.nBufferCountActual,
542 &m_sInPortDef.nBufferSize,
543 m_sInPortDef.nPortIndex);
544
545 /*Query ouput Buffer Requirements*/
546 dev_get_buf_req (&m_sOutPortDef.nBufferCountMin,
547 &m_sOutPortDef.nBufferCountActual,
548 &m_sOutPortDef.nBufferSize,
549 m_sOutPortDef.nPortIndex);
550 m_sInPortDef.nBufferCountActual = portDefn->nBufferCountActual;
551 }
552 else if(PORT_INDEX_OUT == portDefn->nPortIndex)
553 {
554 DEBUG_PRINT_LOW("\n o/p actual cnt requested = %d\n", portDefn->nBufferCountActual);
555 DEBUG_PRINT_LOW("\n o/p min cnt requested = %d\n", portDefn->nBufferCountMin);
556 DEBUG_PRINT_LOW("\n o/p buffersize requested = %d\n", portDefn->nBufferSize);
557 if(handle->venc_set_param(paramData,OMX_IndexParamPortDefinition) != true)
558 {
559 DEBUG_PRINT_ERROR("\nERROR: venc_set_param output failed");
560 return OMX_ErrorUnsupportedSetting;
561 }
562 memcpy(&m_sOutPortDef,portDefn,sizeof(struct OMX_PARAM_PORTDEFINITIONTYPE));
563 update_profile_level(); //framerate , bitrate
564
565 DEBUG_PRINT_LOW("\n o/p previous actual cnt = %d\n", m_sOutPortDef.nBufferCountActual);
566 DEBUG_PRINT_LOW("\n o/p previous min cnt = %d\n", m_sOutPortDef.nBufferCountMin);
567 m_sOutPortDef.nBufferCountActual = portDefn->nBufferCountActual;
568 }
569 else
570 {
571 DEBUG_PRINT_ERROR("ERROR: Set_parameter: Bad Port idx %d",
572 (int)portDefn->nPortIndex);
573 eRet = OMX_ErrorBadPortIndex;
574 }
575 m_sConfigFramerate.xEncodeFramerate = portDefn->format.video.xFramerate;
576 m_sConfigBitrate.nEncodeBitrate = portDefn->format.video.nBitrate;
577 m_sParamBitrate.nTargetBitrate = portDefn->format.video.nBitrate;
578 }
579 break;
580
581 case OMX_IndexParamVideoPortFormat:
582 {
583 OMX_VIDEO_PARAM_PORTFORMATTYPE *portFmt =
584 (OMX_VIDEO_PARAM_PORTFORMATTYPE *)paramData;
585 DEBUG_PRINT_LOW("set_parameter: OMX_IndexParamVideoPortFormat %d\n",
586 portFmt->eColorFormat);
587 //set the driver with the corresponding values
588 if(PORT_INDEX_IN == portFmt->nPortIndex)
589 {
590 if(handle->venc_set_param(paramData,OMX_IndexParamVideoPortFormat) != true)
591 {
592 return OMX_ErrorUnsupportedSetting;
593 }
594
595 DEBUG_PRINT_LOW("set_parameter: OMX_IndexParamVideoPortFormat %d\n",
596 portFmt->eColorFormat);
597 update_profile_level(); //framerate
598
599 #ifdef _ANDROID_ICS_
600 if (portFmt->eColorFormat ==
601 (OMX_COLOR_FORMATTYPE)QOMX_COLOR_FormatAndroidOpaque) {
602 m_sInPortFormat.eColorFormat = OMX_COLOR_FormatYUV420SemiPlanar;
603 if(secure_session) {
604 secure_color_format = (int) QOMX_COLOR_FormatAndroidOpaque;
605 mUseProxyColorFormat = false;
606 m_input_msg_id = OMX_COMPONENT_GENERATE_ETB;
607 } else if(!mUseProxyColorFormat){
608 if (!c2d_conv.init()) {
609 DEBUG_PRINT_ERROR("\n C2D init failed");
610 return OMX_ErrorUnsupportedSetting;
611 }
612 DEBUG_PRINT_ERROR("\nC2D init is successful");
613 mUseProxyColorFormat = true;
614 m_input_msg_id = OMX_COMPONENT_GENERATE_ETB_OPQ;
615 }
616 }
617 else
618 #endif
619 {
620 m_sInPortFormat.eColorFormat = portFmt->eColorFormat;
621 m_input_msg_id = OMX_COMPONENT_GENERATE_ETB;
622 mUseProxyColorFormat = false;
623 }
624 m_sInPortFormat.xFramerate = portFmt->xFramerate;
625 }
626 //TODO if no use case for O/P port,delet m_sOutPortFormat
627 }
628 break;
629 case OMX_IndexParamVideoInit:
630 { //TODO, do we need this index set param
631 OMX_PORT_PARAM_TYPE* pParam = (OMX_PORT_PARAM_TYPE*)(paramData);
632 DEBUG_PRINT_LOW("\n Set OMX_IndexParamVideoInit called");
633 break;
634 }
635
636 case OMX_IndexParamVideoBitrate:
637 {
638 OMX_VIDEO_PARAM_BITRATETYPE* pParam = (OMX_VIDEO_PARAM_BITRATETYPE*)paramData;
639 DEBUG_PRINT_LOW("set_parameter: OMX_IndexParamVideoBitrate");
640 if(handle->venc_set_param(paramData,OMX_IndexParamVideoBitrate) != true)
641 {
642 return OMX_ErrorUnsupportedSetting;
643 }
644 m_sParamBitrate.nTargetBitrate = pParam->nTargetBitrate;
645 m_sParamBitrate.eControlRate = pParam->eControlRate;
646 update_profile_level(); //bitrate
647 m_sConfigBitrate.nEncodeBitrate = pParam->nTargetBitrate;
648 m_sInPortDef.format.video.nBitrate = pParam->nTargetBitrate;
649 m_sOutPortDef.format.video.nBitrate = pParam->nTargetBitrate;
650 DEBUG_PRINT_LOW("\nbitrate = %u", m_sOutPortDef.format.video.nBitrate);
651 break;
652 }
653 case OMX_IndexParamVideoMpeg4:
654 {
655 OMX_VIDEO_PARAM_MPEG4TYPE* pParam = (OMX_VIDEO_PARAM_MPEG4TYPE*)paramData;
656 OMX_VIDEO_PARAM_MPEG4TYPE mp4_param;
657 memcpy(&mp4_param, pParam, sizeof(struct OMX_VIDEO_PARAM_MPEG4TYPE));
658 DEBUG_PRINT_LOW("set_parameter: OMX_IndexParamVideoMpeg4");
659 if(pParam->eProfile == OMX_VIDEO_MPEG4ProfileAdvancedSimple)
660 {
661 #ifdef MAX_RES_1080P
662 if(pParam->nBFrames)
663 {
664 DEBUG_PRINT_HIGH("INFO: Only 1 Bframe is supported");
665 mp4_param.nBFrames = 1;
666 }
667 #else
668 if(pParam->nBFrames)
669 {
670 DEBUG_PRINT_ERROR("Warning: B frames not supported\n");
671 mp4_param.nBFrames = 0;
672 }
673 #endif
674 }
675 else
676 {
677 if(pParam->nBFrames)
678 {
679 DEBUG_PRINT_ERROR("Warning: B frames not supported\n");
680 mp4_param.nBFrames = 0;
681 }
682 }
683 if(handle->venc_set_param(&mp4_param,OMX_IndexParamVideoMpeg4) != true)
684 {
685 return OMX_ErrorUnsupportedSetting;
686 }
687 memcpy(&m_sParamMPEG4,pParam, sizeof(struct OMX_VIDEO_PARAM_MPEG4TYPE));
688 break;
689 }
690 case OMX_IndexParamVideoH263:
691 {
692 OMX_VIDEO_PARAM_H263TYPE* pParam = (OMX_VIDEO_PARAM_H263TYPE*)paramData;
693 DEBUG_PRINT_LOW("set_parameter: OMX_IndexParamVideoH263");
694 if(handle->venc_set_param(paramData,OMX_IndexParamVideoH263) != true)
695 {
696 return OMX_ErrorUnsupportedSetting;
697 }
698 memcpy(&m_sParamH263,pParam, sizeof(struct OMX_VIDEO_PARAM_H263TYPE));
699 break;
700 }
701 case OMX_IndexParamVideoAvc:
702 {
703 OMX_VIDEO_PARAM_AVCTYPE* pParam = (OMX_VIDEO_PARAM_AVCTYPE*)paramData;
704 OMX_VIDEO_PARAM_AVCTYPE avc_param;
705 memcpy(&avc_param, pParam, sizeof( struct OMX_VIDEO_PARAM_AVCTYPE));
706 DEBUG_PRINT_LOW("set_parameter: OMX_IndexParamVideoAvc");
707
708 if((pParam->eProfile == OMX_VIDEO_AVCProfileHigh)||
709 (pParam->eProfile == OMX_VIDEO_AVCProfileMain))
710 {
711 #ifdef MAX_RES_1080P
712 if(pParam->nBFrames)
713 {
714 DEBUG_PRINT_HIGH("INFO: Only 1 Bframe is supported");
715 avc_param.nBFrames = 1;
716 }
717 if(pParam->nRefFrames != 2)
718 {
719 DEBUG_PRINT_ERROR("Warning: 2 RefFrames are needed, changing RefFrames from %d to 2", pParam->nRefFrames);
720 avc_param.nRefFrames = 2;
721 }
722 #else
723 if(pParam->nBFrames)
724 {
725 DEBUG_PRINT_ERROR("Warning: B frames not supported\n");
726 avc_param.nBFrames = 0;
727 }
728 if(pParam->nRefFrames != 1)
729 {
730 DEBUG_PRINT_ERROR("Warning: Only 1 RefFrame is supported, changing RefFrame from %d to 1)", pParam->nRefFrames);
731 avc_param.nRefFrames = 1;
732 }
733 #endif
734 }
735 else
736 {
737 if(pParam->nRefFrames != 1)
738 {
739 DEBUG_PRINT_ERROR("Warning: Only 1 RefFrame is supported, changing RefFrame from %d to 1)", pParam->nRefFrames);
740 avc_param.nRefFrames = 1;
741 }
742 if(pParam->nBFrames)
743 {
744 DEBUG_PRINT_ERROR("Warning: B frames not supported\n");
745 avc_param.nBFrames = 0;
746 }
747 }
748 if(handle->venc_set_param(&avc_param,OMX_IndexParamVideoAvc) != true)
749 {
750 return OMX_ErrorUnsupportedSetting;
751 }
752
753 memcpy(&m_sParamAVC,pParam, sizeof(struct OMX_VIDEO_PARAM_AVCTYPE));
754 break;
755 }
756 case OMX_IndexParamVideoProfileLevelCurrent:
757 {
758 OMX_VIDEO_PARAM_PROFILELEVELTYPE* pParam = (OMX_VIDEO_PARAM_PROFILELEVELTYPE*)paramData;
759 DEBUG_PRINT_LOW("set_parameter: OMX_IndexParamVideoProfileLevelCurrent");
760 if(handle->venc_set_param(pParam,OMX_IndexParamVideoProfileLevelCurrent) != true)
761 {
762 DEBUG_PRINT_ERROR("set_parameter: OMX_IndexParamVideoProfileLevelCurrent failed for Profile: %d "
763 "Level :%d", pParam->eProfile, pParam->eLevel);
764 return OMX_ErrorUnsupportedSetting;
765 }
766 m_sParamProfileLevel.eProfile = pParam->eProfile;
767 m_sParamProfileLevel.eLevel = pParam->eLevel;
768
769 if(!strncmp((char *)m_nkind, "OMX.qcom.video.encoder.mpeg4",\
770 OMX_MAX_STRINGNAME_SIZE))
771 {
772 m_sParamMPEG4.eProfile = (OMX_VIDEO_MPEG4PROFILETYPE)m_sParamProfileLevel.eProfile;
773 m_sParamMPEG4.eLevel = (OMX_VIDEO_MPEG4LEVELTYPE)m_sParamProfileLevel.eLevel;
774 DEBUG_PRINT_LOW("\n MPEG4 profile = %d, level = %d", m_sParamMPEG4.eProfile,
775 m_sParamMPEG4.eLevel);
776 }
777 else if(!strncmp((char *)m_nkind, "OMX.qcom.video.encoder.h263",\
778 OMX_MAX_STRINGNAME_SIZE))
779 {
780 m_sParamH263.eProfile = (OMX_VIDEO_H263PROFILETYPE)m_sParamProfileLevel.eProfile;
781 m_sParamH263.eLevel = (OMX_VIDEO_H263LEVELTYPE)m_sParamProfileLevel.eLevel;
782 DEBUG_PRINT_LOW("\n H263 profile = %d, level = %d", m_sParamH263.eProfile,
783 m_sParamH263.eLevel);
784 }
785 else if(!strncmp((char *)m_nkind, "OMX.qcom.video.encoder.avc",\
786 OMX_MAX_STRINGNAME_SIZE))
787 {
788 m_sParamAVC.eProfile = (OMX_VIDEO_AVCPROFILETYPE)m_sParamProfileLevel.eProfile;
789 m_sParamAVC.eLevel = (OMX_VIDEO_AVCLEVELTYPE)m_sParamProfileLevel.eLevel;
790 DEBUG_PRINT_LOW("\n AVC profile = %d, level = %d", m_sParamAVC.eProfile,
791 m_sParamAVC.eLevel);
792 }
793 break;
794 }
795 case OMX_IndexParamStandardComponentRole:
796 {
797 OMX_PARAM_COMPONENTROLETYPE *comp_role;
798 comp_role = (OMX_PARAM_COMPONENTROLETYPE *) paramData;
799 DEBUG_PRINT_LOW("set_parameter: OMX_IndexParamStandardComponentRole %s\n",
800 comp_role->cRole);
801
802 if((m_state == OMX_StateLoaded)&&
803 !BITMASK_PRESENT(&m_flags,OMX_COMPONENT_IDLE_PENDING))
804 {
805 DEBUG_PRINT_LOW("Set Parameter called in valid state");
806 }
807 else
808 {
809 DEBUG_PRINT_ERROR("Set Parameter called in Invalid State\n");
810 return OMX_ErrorIncorrectStateOperation;
811 }
812
813 if(!strncmp((char*)m_nkind, "OMX.qcom.video.encoder.avc",OMX_MAX_STRINGNAME_SIZE))
814 {
815 if(!strncmp((char*)comp_role->cRole,"video_encoder.avc",OMX_MAX_STRINGNAME_SIZE))
816 {
817 strlcpy((char*)m_cRole,"video_encoder.avc",OMX_MAX_STRINGNAME_SIZE);
818 }
819 else
820 {
821 DEBUG_PRINT_ERROR("ERROR: Setparameter: unknown Index %s\n", comp_role->cRole);
822 eRet =OMX_ErrorUnsupportedSetting;
823 }
824 }
825 else if(!strncmp((char*)m_nkind, "OMX.qcom.video.encoder.mpeg4",OMX_MAX_STRINGNAME_SIZE))
826 {
827 if(!strncmp((const char*)comp_role->cRole,"video_encoder.mpeg4",OMX_MAX_STRINGNAME_SIZE))
828 {
829 strlcpy((char*)m_cRole,"video_encoder.mpeg4",OMX_MAX_STRINGNAME_SIZE);
830 }
831 else
832 {
833 DEBUG_PRINT_ERROR("ERROR: Setparameter: unknown Index %s\n", comp_role->cRole);
834 eRet = OMX_ErrorUnsupportedSetting;
835 }
836 }
837 else if(!strncmp((char*)m_nkind, "OMX.qcom.video.encoder.h263",OMX_MAX_STRINGNAME_SIZE))
838 {
839 if(!strncmp((const char*)comp_role->cRole,"video_encoder.h263",OMX_MAX_STRINGNAME_SIZE))
840 {
841 strlcpy((char*)m_cRole,"video_encoder.h263",OMX_MAX_STRINGNAME_SIZE);
842 }
843 else
844 {
845 DEBUG_PRINT_ERROR("ERROR: Setparameter: unknown Index %s\n", comp_role->cRole);
846 eRet =OMX_ErrorUnsupportedSetting;
847 }
848 }
849 else
850 {
851 DEBUG_PRINT_ERROR("ERROR: Setparameter: unknown param %s\n", m_nkind);
852 eRet = OMX_ErrorInvalidComponentName;
853 }
854 break;
855 }
856
857 case OMX_IndexParamPriorityMgmt:
858 {
859 DEBUG_PRINT_LOW("set_parameter: OMX_IndexParamPriorityMgmt");
860 if(m_state != OMX_StateLoaded)
861 {
862 DEBUG_PRINT_ERROR("ERROR: Set Parameter called in Invalid State\n");
863 return OMX_ErrorIncorrectStateOperation;
864 }
865 OMX_PRIORITYMGMTTYPE *priorityMgmtype = (OMX_PRIORITYMGMTTYPE*) paramData;
866 DEBUG_PRINT_LOW("set_parameter: OMX_IndexParamPriorityMgmt %d\n",
867 priorityMgmtype->nGroupID);
868
869 DEBUG_PRINT_LOW("set_parameter: priorityMgmtype %d\n",
870 priorityMgmtype->nGroupPriority);
871
872 m_sPriorityMgmt.nGroupID = priorityMgmtype->nGroupID;
873 m_sPriorityMgmt.nGroupPriority = priorityMgmtype->nGroupPriority;
874
875 break;
876 }
877
878 case OMX_IndexParamCompBufferSupplier:
879 {
880 DEBUG_PRINT_LOW("set_parameter: OMX_IndexParamCompBufferSupplier");
881 OMX_PARAM_BUFFERSUPPLIERTYPE *bufferSupplierType = (OMX_PARAM_BUFFERSUPPLIERTYPE*) paramData;
882 DEBUG_PRINT_LOW("set_parameter: OMX_IndexParamCompBufferSupplier %d\n",
883 bufferSupplierType->eBufferSupplier);
884 if(bufferSupplierType->nPortIndex == 0 || bufferSupplierType->nPortIndex ==1)
885 m_sInBufSupplier.eBufferSupplier = bufferSupplierType->eBufferSupplier;
886
887 else
888
889 eRet = OMX_ErrorBadPortIndex;
890
891 break;
892
893 }
894 case OMX_IndexParamVideoQuantization:
895 {
896 DEBUG_PRINT_LOW("set_parameter: OMX_IndexParamVideoQuantization\n");
897 OMX_VIDEO_PARAM_QUANTIZATIONTYPE *session_qp = (OMX_VIDEO_PARAM_QUANTIZATIONTYPE*) paramData;
898 if(session_qp->nPortIndex == PORT_INDEX_OUT)
899 {
900 if(handle->venc_set_param(paramData, OMX_IndexParamVideoQuantization) != true)
901 {
902 return OMX_ErrorUnsupportedSetting;
903 }
904 m_sSessionQuantization.nQpI = session_qp->nQpI;
905 m_sSessionQuantization.nQpP = session_qp->nQpP;
906 }
907 else
908 {
909 DEBUG_PRINT_ERROR("\nERROR: Unsupported port Index for Session QP setting\n");
910 eRet = OMX_ErrorBadPortIndex;
911 }
912 break;
913 }
914
915 case OMX_QcomIndexPortDefn:
916 {
917 OMX_QCOM_PARAM_PORTDEFINITIONTYPE* pParam =
918 (OMX_QCOM_PARAM_PORTDEFINITIONTYPE*)paramData;
919 DEBUG_PRINT_LOW("set_parameter: OMX_QcomIndexPortDefn");
920 if(pParam->nPortIndex == (OMX_U32)PORT_INDEX_IN)
921 {
922 if(pParam->nMemRegion > OMX_QCOM_MemRegionInvalid &&
923 pParam->nMemRegion < OMX_QCOM_MemRegionMax)
924 {
925 m_use_input_pmem = OMX_TRUE;
926 }
927 else
928 {
929 m_use_input_pmem = OMX_FALSE;
930 }
931 }
932 else if (pParam->nPortIndex == (OMX_U32)PORT_INDEX_OUT)
933 {
934 if(pParam->nMemRegion > OMX_QCOM_MemRegionInvalid &&
935 pParam->nMemRegion < OMX_QCOM_MemRegionMax)
936 {
937 m_use_output_pmem = OMX_TRUE;
938 }
939 else
940 {
941 m_use_output_pmem = OMX_FALSE;
942 }
943 }
944 else
945 {
946 DEBUG_PRINT_ERROR("ERROR: SetParameter called on unsupported Port Index for QcomPortDefn");
947 return OMX_ErrorBadPortIndex;
948 }
949 break;
950 }
951
952 case OMX_IndexParamVideoErrorCorrection:
953 {
954 DEBUG_PRINT_LOW("OMX_IndexParamVideoErrorCorrection\n");
955 OMX_VIDEO_PARAM_ERRORCORRECTIONTYPE* pParam =
956 (OMX_VIDEO_PARAM_ERRORCORRECTIONTYPE*)paramData;
957 if(!handle->venc_set_param(paramData, OMX_IndexParamVideoErrorCorrection))
958 {
959 DEBUG_PRINT_ERROR("\nERROR: Request for setting Error Resilience failed");
960 return OMX_ErrorUnsupportedSetting;
961 }
962 memcpy(&m_sErrorCorrection,pParam, sizeof(m_sErrorCorrection));
963 break;
964 }
965 case OMX_IndexParamVideoIntraRefresh:
966 {
967 DEBUG_PRINT_LOW("set_param:OMX_IndexParamVideoIntraRefresh\n");
968 OMX_VIDEO_PARAM_INTRAREFRESHTYPE* pParam =
969 (OMX_VIDEO_PARAM_INTRAREFRESHTYPE*)paramData;
970 if(!handle->venc_set_param(paramData,OMX_IndexParamVideoIntraRefresh))
971 {
972 DEBUG_PRINT_ERROR("\nERROR: Request for setting intra refresh failed");
973 return OMX_ErrorUnsupportedSetting;
974 }
975 memcpy(&m_sIntraRefresh, pParam, sizeof(m_sIntraRefresh));
976 break;
977 }
978 #ifdef _ANDROID_ICS_
979 case OMX_QcomIndexParamVideoEncodeMetaBufferMode:
980 {
981 StoreMetaDataInBuffersParams *pParam =
982 (StoreMetaDataInBuffersParams*)paramData;
983 if(pParam->nPortIndex == PORT_INDEX_IN)
984 {
985 if(pParam->bStoreMetaData != meta_mode_enable)
986 {
987 if(!handle->venc_set_meta_mode(pParam->bStoreMetaData))
988 {
989 DEBUG_PRINT_ERROR("\nERROR: set Metabuffer mode %d fail",
990 pParam->bStoreMetaData);
991 return OMX_ErrorUnsupportedSetting;
992 }
993 meta_mode_enable = pParam->bStoreMetaData;
994 if(meta_mode_enable) {
995 m_sInPortDef.nBufferCountActual = 4;
996 if(handle->venc_set_param(&m_sInPortDef,OMX_IndexParamPortDefinition) != true)
997 {
998 DEBUG_PRINT_ERROR("\nERROR: venc_set_param input failed");
999 return OMX_ErrorUnsupportedSetting;
1000 }
1001 } else {
1002 /*TODO: reset encoder driver Meta mode*/
1003 dev_get_buf_req (&m_sOutPortDef.nBufferCountMin,
1004 &m_sOutPortDef.nBufferCountActual,
1005 &m_sOutPortDef.nBufferSize,
1006 m_sOutPortDef.nPortIndex);
1007 }
1008 }
1009 }
1010 break;
1011 }
1012 #endif
1013 #ifndef MAX_RES_720P
1014 case OMX_QcomIndexParamIndexExtraDataType:
1015 {
1016 DEBUG_PRINT_LOW("set_parameter: OMX_QcomIndexParamIndexExtraDataType");
1017 QOMX_INDEXEXTRADATATYPE *pParam = (QOMX_INDEXEXTRADATATYPE *)paramData;
1018 if (pParam->nIndex == (OMX_INDEXTYPE)OMX_ExtraDataVideoEncoderSliceInfo)
1019 {
1020 if (pParam->nPortIndex == PORT_INDEX_OUT)
1021 {
1022 if (pParam->bEnabled == OMX_TRUE)
1023 m_sExtraData |= VEN_EXTRADATA_SLICEINFO;
1024 else
1025 m_sExtraData &= ~VEN_EXTRADATA_SLICEINFO;
1026 DEBUG_PRINT_HIGH("set_param: m_sExtraData=%x", m_sExtraData);
1027 if(handle->venc_set_param(&m_sExtraData,
1028 (OMX_INDEXTYPE)OMX_ExtraDataVideoEncoderSliceInfo) != true)
1029 {
1030 DEBUG_PRINT_ERROR("ERROR: Setting "
1031 "OMX_QcomIndexParamIndexExtraDataType failed");
1032 return OMX_ErrorUnsupportedSetting;
1033 }
1034 else
1035 {
1036 m_sOutPortDef.nPortIndex = PORT_INDEX_OUT;
1037 dev_get_buf_req(&m_sOutPortDef.nBufferCountMin,
1038 &m_sOutPortDef.nBufferCountActual,
1039 &m_sOutPortDef.nBufferSize,
1040 m_sOutPortDef.nPortIndex);
1041 DEBUG_PRINT_HIGH("updated out_buf_req: buffer cnt=%d, "
1042 "count min=%d, buffer size=%d",
1043 m_sOutPortDef.nBufferCountActual,
1044 m_sOutPortDef.nBufferCountMin,
1045 m_sOutPortDef.nBufferSize);
1046 }
1047 }
1048 else
1049 {
1050 DEBUG_PRINT_ERROR("set_parameter: slice information is "
1051 "valid for output port only");
1052 eRet = OMX_ErrorUnsupportedIndex;
1053 }
1054 }
1055 else
1056 {
1057 DEBUG_PRINT_ERROR("set_parameter: unsupported index (%x), "
1058 "only slice information extradata is supported", pParam->nIndex);
1059 eRet = OMX_ErrorUnsupportedIndex;
1060 }
1061 break;
1062 }
1063 #endif
1064 case OMX_QcomIndexParamVideoMaxAllowedBitrateCheck:
1065 {
1066 QOMX_EXTNINDEX_PARAMTYPE* pParam =
1067 (QOMX_EXTNINDEX_PARAMTYPE*)paramData;
1068 if(pParam->nPortIndex == PORT_INDEX_OUT)
1069 {
1070 handle->m_max_allowed_bitrate_check =
1071 ((pParam->bEnable == OMX_TRUE) ? true : false);
1072 DEBUG_PRINT_HIGH("set_parameter: max allowed bitrate check %s",
1073 ((pParam->bEnable == OMX_TRUE) ? "enabled" : "disabled"));
1074 }
1075 else
1076 {
1077 DEBUG_PRINT_ERROR("ERROR: OMX_QcomIndexParamVideoMaxAllowedBitrateCheck "
1078 " called on wrong port(%d)", pParam->nPortIndex);
1079 return OMX_ErrorBadPortIndex;
1080 }
1081 break;
1082 }
1083 #ifdef MAX_RES_1080P
1084 case OMX_QcomIndexEnableSliceDeliveryMode:
1085 {
1086 QOMX_EXTNINDEX_PARAMTYPE* pParam =
1087 (QOMX_EXTNINDEX_PARAMTYPE*)paramData;
1088 if(pParam->nPortIndex == PORT_INDEX_OUT)
1089 {
1090 if(!handle->venc_set_param(paramData,
1091 (OMX_INDEXTYPE)OMX_QcomIndexEnableSliceDeliveryMode))
1092 {
1093 DEBUG_PRINT_ERROR("ERROR: Request for setting slice delivery mode failed");
1094 return OMX_ErrorUnsupportedSetting;
1095 }
1096 }
1097 else
1098 {
1099 DEBUG_PRINT_ERROR("ERROR: OMX_QcomIndexEnableSliceDeliveryMode "
1100 "called on wrong port(%d)", pParam->nPortIndex);
1101 return OMX_ErrorBadPortIndex;
1102 }
1103 break;
1104 }
1105 #endif
1106 case OMX_QcomIndexParamSequenceHeaderWithIDR:
1107 {
1108 if(!handle->venc_set_param(paramData,
1109 (OMX_INDEXTYPE)OMX_QcomIndexParamSequenceHeaderWithIDR))
1110 {
1111 DEBUG_PRINT_ERROR("ERROR: Request for setting inband sps/pps failed");
1112 return OMX_ErrorUnsupportedSetting;
1113 }
1114 break;
1115 }
1116 case OMX_IndexParamVideoSliceFMO:
1117 default:
1118 {
1119 DEBUG_PRINT_ERROR("ERROR: Setparameter: unknown param %d\n", paramIndex);
1120 eRet = OMX_ErrorUnsupportedIndex;
1121 break;
1122 }
1123 }
1124 return eRet;
1125 }
1126
update_profile_level()1127 bool omx_venc::update_profile_level()
1128 {
1129 OMX_U32 eProfile, eLevel;
1130
1131 if(!handle->venc_get_profile_level(&eProfile,&eLevel))
1132 {
1133 DEBUG_PRINT_ERROR("\nFailed to update the profile_level\n");
1134 return false;
1135 }
1136
1137 m_sParamProfileLevel.eProfile = (OMX_VIDEO_MPEG4PROFILETYPE)eProfile;
1138 m_sParamProfileLevel.eLevel = (OMX_VIDEO_MPEG4LEVELTYPE)eLevel;
1139
1140 if(!strncmp((char *)m_nkind, "OMX.qcom.video.encoder.mpeg4",\
1141 OMX_MAX_STRINGNAME_SIZE))
1142 {
1143 m_sParamMPEG4.eProfile = (OMX_VIDEO_MPEG4PROFILETYPE)eProfile;
1144 m_sParamMPEG4.eLevel = (OMX_VIDEO_MPEG4LEVELTYPE)eLevel;
1145 DEBUG_PRINT_LOW("\n MPEG4 profile = %d, level = %d", m_sParamMPEG4.eProfile,
1146 m_sParamMPEG4.eLevel);
1147 }
1148 else if(!strncmp((char *)m_nkind, "OMX.qcom.video.encoder.h263",\
1149 OMX_MAX_STRINGNAME_SIZE))
1150 {
1151 m_sParamH263.eProfile = (OMX_VIDEO_H263PROFILETYPE)eProfile;
1152 m_sParamH263.eLevel = (OMX_VIDEO_H263LEVELTYPE)eLevel;
1153 DEBUG_PRINT_LOW("\n H263 profile = %d, level = %d", m_sParamH263.eProfile,
1154 m_sParamH263.eLevel);
1155 }
1156 else if(!strncmp((char *)m_nkind, "OMX.qcom.video.encoder.avc",\
1157 OMX_MAX_STRINGNAME_SIZE))
1158 {
1159 m_sParamAVC.eProfile = (OMX_VIDEO_AVCPROFILETYPE)eProfile;
1160 m_sParamAVC.eLevel = (OMX_VIDEO_AVCLEVELTYPE)eLevel;
1161 DEBUG_PRINT_LOW("\n AVC profile = %d, level = %d", m_sParamAVC.eProfile,
1162 m_sParamAVC.eLevel);
1163 }
1164 return true;
1165 }
1166 /* ======================================================================
1167 FUNCTION
1168 omx_video::SetConfig
1169
1170 DESCRIPTION
1171 OMX Set Config method implementation
1172
1173 PARAMETERS
1174 <TBD>.
1175
1176 RETURN VALUE
1177 OMX Error None if successful.
1178 ========================================================================== */
set_config(OMX_IN OMX_HANDLETYPE hComp,OMX_IN OMX_INDEXTYPE configIndex,OMX_IN OMX_PTR configData)1179 OMX_ERRORTYPE omx_venc::set_config(OMX_IN OMX_HANDLETYPE hComp,
1180 OMX_IN OMX_INDEXTYPE configIndex,
1181 OMX_IN OMX_PTR configData)
1182 {
1183 if(configData == NULL)
1184 {
1185 DEBUG_PRINT_ERROR("ERROR: param is null");
1186 return OMX_ErrorBadParameter;
1187 }
1188
1189 if(m_state == OMX_StateInvalid)
1190 {
1191 DEBUG_PRINT_ERROR("ERROR: config called in Invalid state");
1192 return OMX_ErrorIncorrectStateOperation;
1193 }
1194
1195 // params will be validated prior to venc_init
1196 switch(configIndex)
1197 {
1198 case OMX_IndexConfigVideoBitrate:
1199 {
1200 OMX_VIDEO_CONFIG_BITRATETYPE* pParam =
1201 reinterpret_cast<OMX_VIDEO_CONFIG_BITRATETYPE*>(configData);
1202 DEBUG_PRINT_LOW("\n omx_venc:: set_config(): OMX_IndexConfigVideoBitrate");
1203
1204 if(pParam->nPortIndex == PORT_INDEX_OUT)
1205 {
1206 if(handle->venc_set_config(configData, OMX_IndexConfigVideoBitrate) != true)
1207 {
1208 DEBUG_PRINT_ERROR("ERROR: Setting OMX_IndexConfigVideoBitrate failed");
1209 return OMX_ErrorUnsupportedSetting;
1210 }
1211
1212 m_sConfigBitrate.nEncodeBitrate = pParam->nEncodeBitrate;
1213 m_sParamBitrate.nTargetBitrate = pParam->nEncodeBitrate;
1214 m_sOutPortDef.format.video.nBitrate = pParam->nEncodeBitrate;
1215 }
1216 else
1217 {
1218 DEBUG_PRINT_ERROR("ERROR: Unsupported port index: %u", pParam->nPortIndex);
1219 return OMX_ErrorBadPortIndex;
1220 }
1221 break;
1222 }
1223 case OMX_IndexConfigVideoFramerate:
1224 {
1225 OMX_CONFIG_FRAMERATETYPE* pParam =
1226 reinterpret_cast<OMX_CONFIG_FRAMERATETYPE*>(configData);
1227 DEBUG_PRINT_LOW("\n omx_venc:: set_config(): OMX_IndexConfigVideoFramerate");
1228
1229 if(pParam->nPortIndex == PORT_INDEX_OUT)
1230 {
1231 if(handle->venc_set_config(configData, OMX_IndexConfigVideoFramerate) != true)
1232 {
1233 DEBUG_PRINT_ERROR("ERROR: Setting OMX_IndexConfigVideoFramerate failed");
1234 return OMX_ErrorUnsupportedSetting;
1235 }
1236
1237 m_sConfigFramerate.xEncodeFramerate = pParam->xEncodeFramerate;
1238 m_sOutPortDef.format.video.xFramerate = pParam->xEncodeFramerate;
1239 m_sOutPortFormat.xFramerate = pParam->xEncodeFramerate;
1240 }
1241 else
1242 {
1243 DEBUG_PRINT_ERROR("ERROR: Unsupported port index: %u", pParam->nPortIndex);
1244 return OMX_ErrorBadPortIndex;
1245 }
1246
1247 break;
1248 }
1249 case QOMX_IndexConfigVideoIntraperiod:
1250 {
1251 QOMX_VIDEO_INTRAPERIODTYPE* pParam =
1252 reinterpret_cast<QOMX_VIDEO_INTRAPERIODTYPE*>(configData);
1253
1254 if(pParam->nPortIndex == PORT_INDEX_OUT)
1255 {
1256 #ifdef MAX_RES_720P
1257 if(pParam->nBFrames > 0)
1258 {
1259 DEBUG_PRINT_ERROR("B frames not supported\n");
1260 return OMX_ErrorUnsupportedSetting;
1261 }
1262 #endif
1263 if(handle->venc_set_config(configData, (OMX_INDEXTYPE) QOMX_IndexConfigVideoIntraperiod) != true)
1264 {
1265 DEBUG_PRINT_ERROR("ERROR: Setting QOMX_IndexConfigVideoIntraperiod failed");
1266 return OMX_ErrorUnsupportedSetting;
1267 }
1268 m_sIntraperiod.nPFrames = pParam->nPFrames;
1269 m_sIntraperiod.nBFrames = pParam->nBFrames;
1270 m_sIntraperiod.nIDRPeriod = pParam->nIDRPeriod;
1271
1272 if(m_sOutPortFormat.eCompressionFormat == OMX_VIDEO_CodingMPEG4)
1273 {
1274 m_sParamMPEG4.nPFrames = pParam->nPFrames;
1275 if(m_sParamMPEG4.eProfile != OMX_VIDEO_MPEG4ProfileSimple)
1276 m_sParamMPEG4.nBFrames = pParam->nBFrames;
1277 else
1278 m_sParamMPEG4.nBFrames = 0;
1279 }
1280 else if(m_sOutPortFormat.eCompressionFormat == OMX_VIDEO_CodingH263)
1281 {
1282 m_sParamH263.nPFrames = pParam->nPFrames;
1283 }
1284 else
1285 {
1286 m_sParamAVC.nPFrames = pParam->nPFrames;
1287 if(m_sParamAVC.eProfile != OMX_VIDEO_AVCProfileBaseline)
1288 m_sParamAVC.nBFrames = pParam->nBFrames;
1289 else
1290 m_sParamAVC.nBFrames = 0;
1291 }
1292 }
1293 else
1294 {
1295 DEBUG_PRINT_ERROR("ERROR: (QOMX_IndexConfigVideoIntraperiod) Unsupported port index: %u", pParam->nPortIndex);
1296 return OMX_ErrorBadPortIndex;
1297 }
1298
1299 break;
1300 }
1301
1302 case OMX_IndexConfigVideoIntraVOPRefresh:
1303 {
1304 OMX_CONFIG_INTRAREFRESHVOPTYPE* pParam =
1305 reinterpret_cast<OMX_CONFIG_INTRAREFRESHVOPTYPE*>(configData);
1306
1307 if(pParam->nPortIndex == PORT_INDEX_OUT)
1308 {
1309 if(handle->venc_set_config(configData,
1310 OMX_IndexConfigVideoIntraVOPRefresh) != true)
1311 {
1312 DEBUG_PRINT_ERROR("ERROR: Setting OMX_IndexConfigVideoIntraVOPRefresh failed");
1313 return OMX_ErrorUnsupportedSetting;
1314 }
1315
1316 m_sConfigIntraRefreshVOP.IntraRefreshVOP = pParam->IntraRefreshVOP;
1317 }
1318 else
1319 {
1320 DEBUG_PRINT_ERROR("ERROR: Unsupported port index: %u", pParam->nPortIndex);
1321 return OMX_ErrorBadPortIndex;
1322 }
1323
1324 break;
1325 }
1326 case OMX_IndexConfigCommonRotate:
1327 {
1328 OMX_CONFIG_ROTATIONTYPE *pParam =
1329 reinterpret_cast<OMX_CONFIG_ROTATIONTYPE*>(configData);
1330 OMX_S32 nRotation;
1331
1332 if(pParam->nPortIndex != PORT_INDEX_IN){
1333 DEBUG_PRINT_ERROR("ERROR: Unsupported port index: %u", pParam->nPortIndex);
1334 return OMX_ErrorBadPortIndex;
1335 }
1336 if( pParam->nRotation == 0 ||
1337 pParam->nRotation == 90 ||
1338 pParam->nRotation == 180 ||
1339 pParam->nRotation == 270 ) {
1340 DEBUG_PRINT_HIGH("\nset_config: Rotation Angle %u", pParam->nRotation);
1341 } else {
1342 DEBUG_PRINT_ERROR("ERROR: un supported Rotation %u", pParam->nRotation);
1343 return OMX_ErrorUnsupportedSetting;
1344 }
1345 nRotation = pParam->nRotation - m_sConfigFrameRotation.nRotation;
1346 if(nRotation < 0)
1347 nRotation = -nRotation;
1348 if(nRotation == 90 || nRotation == 270) {
1349 DEBUG_PRINT_HIGH("\nset_config: updating device Dims");
1350 if(handle->venc_set_config(configData,
1351 OMX_IndexConfigCommonRotate) != true) {
1352 DEBUG_PRINT_ERROR("ERROR: Set OMX_IndexConfigCommonRotate failed");
1353 return OMX_ErrorUnsupportedSetting;
1354 } else {
1355 OMX_U32 nFrameWidth;
1356
1357 DEBUG_PRINT_HIGH("\nset_config: updating port Dims");
1358
1359 nFrameWidth = m_sInPortDef.format.video.nFrameWidth;
1360 m_sInPortDef.format.video.nFrameWidth =
1361 m_sInPortDef.format.video.nFrameHeight;
1362 m_sInPortDef.format.video.nFrameHeight = nFrameWidth;
1363
1364 m_sOutPortDef.format.video.nFrameWidth =
1365 m_sInPortDef.format.video.nFrameWidth;
1366 m_sOutPortDef.format.video.nFrameHeight =
1367 m_sInPortDef.format.video.nFrameHeight;
1368 m_sConfigFrameRotation.nRotation = pParam->nRotation;
1369 }
1370 } else {
1371 m_sConfigFrameRotation.nRotation = pParam->nRotation;
1372 }
1373 break;
1374 }
1375 case OMX_QcomIndexConfigVideoFramePackingArrangement:
1376 {
1377 if(m_sOutPortFormat.eCompressionFormat == OMX_VIDEO_CodingAVC)
1378 {
1379 OMX_QCOM_FRAME_PACK_ARRANGEMENT *configFmt =
1380 (OMX_QCOM_FRAME_PACK_ARRANGEMENT *) configData;
1381 extra_data_handle.set_frame_pack_data(configFmt);
1382 }
1383 else
1384 {
1385 DEBUG_PRINT_ERROR("ERROR: FramePackingData not supported for non AVC compression");
1386 }
1387 break;
1388 }
1389 default:
1390 DEBUG_PRINT_ERROR("ERROR: unsupported index %d", (int) configIndex);
1391 break;
1392 }
1393
1394 return OMX_ErrorNone;
1395 }
1396
1397 /* ======================================================================
1398 FUNCTION
1399 omx_venc::ComponentDeInit
1400
1401 DESCRIPTION
1402 Destroys the component and release memory allocated to the heap.
1403
1404 PARAMETERS
1405 <TBD>.
1406
1407 RETURN VALUE
1408 OMX Error None if everything successful.
1409
1410 ========================================================================== */
component_deinit(OMX_IN OMX_HANDLETYPE hComp)1411 OMX_ERRORTYPE omx_venc::component_deinit(OMX_IN OMX_HANDLETYPE hComp)
1412 {
1413 OMX_U32 i = 0;
1414 DEBUG_PRINT_HIGH("\n omx_venc(): Inside component_deinit()");
1415 if(OMX_StateLoaded != m_state)
1416 {
1417 DEBUG_PRINT_ERROR("WARNING:Rxd DeInit,OMX not in LOADED state %d\n",\
1418 m_state);
1419 }
1420 if(m_out_mem_ptr)
1421 {
1422 DEBUG_PRINT_LOW("Freeing the Output Memory\n");
1423 for(i=0; i< m_sOutPortDef.nBufferCountActual; i++ )
1424 {
1425 free_output_buffer (&m_out_mem_ptr[i]);
1426 }
1427 free(m_out_mem_ptr);
1428 m_out_mem_ptr = NULL;
1429 }
1430
1431 /*Check if the input buffers have to be cleaned up*/
1432 if(m_inp_mem_ptr
1433 #ifdef _ANDROID_ICS_
1434 && !meta_mode_enable
1435 #endif
1436 )
1437 {
1438 DEBUG_PRINT_LOW("Freeing the Input Memory\n");
1439 for(i=0; i<m_sInPortDef.nBufferCountActual; i++ )
1440 {
1441 free_input_buffer (&m_inp_mem_ptr[i]);
1442 }
1443
1444
1445 free(m_inp_mem_ptr);
1446 m_inp_mem_ptr = NULL;
1447 }
1448
1449 // Reset counters in mesg queues
1450 m_ftb_q.m_size=0;
1451 m_cmd_q.m_size=0;
1452 m_etb_q.m_size=0;
1453 m_ftb_q.m_read = m_ftb_q.m_write =0;
1454 m_cmd_q.m_read = m_cmd_q.m_write =0;
1455 m_etb_q.m_read = m_etb_q.m_write =0;
1456
1457 #ifdef _ANDROID_
1458 // Clear the strong reference
1459 DEBUG_PRINT_HIGH("Calling m_heap_ptr.clear()\n");
1460 m_heap_ptr.clear();
1461 #endif // _ANDROID_
1462 DEBUG_PRINT_HIGH("Calling venc_close()\n");
1463 handle->venc_close();
1464 DEBUG_PRINT_HIGH("Deleting HANDLE[%p]\n", handle);
1465 delete (handle);
1466 DEBUG_PRINT_HIGH("OMX_Venc:Component Deinit\n");
1467 return OMX_ErrorNone;
1468 }
1469
1470
dev_stop(void)1471 OMX_U32 omx_venc::dev_stop( void)
1472 {
1473 return handle->venc_stop();
1474 }
1475
1476
dev_pause(void)1477 OMX_U32 omx_venc::dev_pause(void)
1478 {
1479 return handle->venc_pause();
1480 }
1481
dev_start(void)1482 OMX_U32 omx_venc::dev_start(void)
1483 {
1484 return handle->venc_start();
1485 }
1486
dev_flush(unsigned port)1487 OMX_U32 omx_venc::dev_flush(unsigned port)
1488 {
1489 return handle->venc_flush(port);
1490 }
dev_resume(void)1491 OMX_U32 omx_venc::dev_resume(void)
1492 {
1493 return handle->venc_resume();
1494 }
1495
dev_start_done(void)1496 OMX_U32 omx_venc::dev_start_done(void)
1497 {
1498 return handle->venc_start_done();
1499 }
1500
dev_stop_done(void)1501 OMX_U32 omx_venc::dev_stop_done(void)
1502 {
1503 return handle->venc_stop_done();
1504 }
1505
dev_use_buf(void * buf_addr,unsigned port,unsigned index)1506 bool omx_venc::dev_use_buf(void *buf_addr,unsigned port,unsigned index)
1507 {
1508 return handle->venc_use_buf(buf_addr,port,index);
1509 }
1510
dev_free_buf(void * buf_addr,unsigned port)1511 bool omx_venc::dev_free_buf(void *buf_addr,unsigned port)
1512 {
1513 return handle->venc_free_buf(buf_addr,port);
1514 }
1515
dev_empty_buf(void * buffer,void * pmem_data_buf,unsigned index,unsigned fd)1516 bool omx_venc::dev_empty_buf(void *buffer, void *pmem_data_buf,unsigned index,unsigned fd)
1517 {
1518 return handle->venc_empty_buf(buffer, pmem_data_buf,index,fd);
1519 }
1520
dev_fill_buf(void * buffer,void * pmem_data_buf,unsigned index,unsigned fd)1521 bool omx_venc::dev_fill_buf(void *buffer, void *pmem_data_buf,unsigned index,unsigned fd)
1522 {
1523 return handle->venc_fill_buf(buffer, pmem_data_buf,index,fd);
1524 }
1525
dev_get_seq_hdr(void * buffer,unsigned size,unsigned * hdrlen)1526 bool omx_venc::dev_get_seq_hdr(void *buffer, unsigned size, unsigned *hdrlen)
1527 {
1528 return handle->venc_get_seq_hdr(buffer, size, hdrlen);
1529 }
1530
dev_loaded_start()1531 bool omx_venc::dev_loaded_start()
1532 {
1533 return handle->venc_loaded_start();
1534 }
1535
dev_loaded_stop()1536 bool omx_venc::dev_loaded_stop()
1537 {
1538 return handle->venc_loaded_stop();
1539 }
1540
dev_loaded_start_done()1541 bool omx_venc::dev_loaded_start_done()
1542 {
1543 return handle->venc_loaded_start_done();
1544 }
1545
dev_loaded_stop_done()1546 bool omx_venc::dev_loaded_stop_done()
1547 {
1548 return handle->venc_loaded_stop_done();
1549 }
1550
dev_get_buf_req(OMX_U32 * min_buff_count,OMX_U32 * actual_buff_count,OMX_U32 * buff_size,OMX_U32 port)1551 bool omx_venc::dev_get_buf_req(OMX_U32 *min_buff_count,
1552 OMX_U32 *actual_buff_count,
1553 OMX_U32 *buff_size,
1554 OMX_U32 port)
1555 {
1556 return handle->venc_get_buf_req(min_buff_count,
1557 actual_buff_count,
1558 buff_size,
1559 port);
1560
1561 }
1562
dev_set_buf_req(OMX_U32 * min_buff_count,OMX_U32 * actual_buff_count,OMX_U32 * buff_size,OMX_U32 port)1563 bool omx_venc::dev_set_buf_req(OMX_U32 *min_buff_count,
1564 OMX_U32 *actual_buff_count,
1565 OMX_U32 *buff_size,
1566 OMX_U32 port)
1567 {
1568 return handle->venc_set_buf_req(min_buff_count,
1569 actual_buff_count,
1570 buff_size,
1571 port);
1572
1573 }
1574
async_message_process(void * context,void * message)1575 int omx_venc::async_message_process (void *context, void* message)
1576 {
1577 omx_video* omx = NULL;
1578 struct venc_msg *m_sVenc_msg = NULL;
1579 OMX_BUFFERHEADERTYPE* omxhdr = NULL;
1580 struct venc_buffer *temp_buff = NULL;
1581
1582 if(context == NULL || message == NULL)
1583 {
1584 DEBUG_PRINT_ERROR("\nERROR: omx_venc::async_message_process invalid i/p params");
1585 return -1;
1586 }
1587 m_sVenc_msg = (struct venc_msg *)message;
1588
1589 omx = reinterpret_cast<omx_video*>(context);
1590
1591 if(m_sVenc_msg->statuscode != VEN_S_SUCCESS)
1592 {
1593 DEBUG_PRINT_ERROR("\nERROR: async_msg_process() - Error statuscode = %d\n",
1594 m_sVenc_msg->statuscode);
1595 omx->omx_report_error();
1596 }
1597
1598 DEBUG_PRINT_LOW("\n omx_venc::async_message_process- msgcode = %d\n",
1599 m_sVenc_msg->msgcode);
1600 switch(m_sVenc_msg->msgcode)
1601 {
1602
1603 case VEN_MSG_START:
1604 omx->post_event (NULL,m_sVenc_msg->statuscode,\
1605 OMX_COMPONENT_GENERATE_START_DONE);
1606 break;
1607
1608 case VEN_MSG_STOP:
1609 omx->post_event (NULL,m_sVenc_msg->statuscode,\
1610 OMX_COMPONENT_GENERATE_STOP_DONE);
1611 break;
1612
1613 case VEN_MSG_RESUME:
1614 omx->post_event (NULL,m_sVenc_msg->statuscode,\
1615 OMX_COMPONENT_GENERATE_RESUME_DONE);
1616 break;
1617
1618 case VEN_MSG_PAUSE:
1619 omx->post_event (NULL,m_sVenc_msg->statuscode,\
1620 OMX_COMPONENT_GENERATE_PAUSE_DONE);
1621
1622 break;
1623
1624 case VEN_MSG_FLUSH_INPUT_DONE:
1625
1626 omx->post_event (NULL,m_sVenc_msg->statuscode,\
1627 OMX_COMPONENT_GENERATE_EVENT_INPUT_FLUSH);
1628 break;
1629 case VEN_MSG_FLUSH_OUPUT_DONE:
1630 omx->post_event (NULL,m_sVenc_msg->statuscode,\
1631 OMX_COMPONENT_GENERATE_EVENT_OUTPUT_FLUSH);
1632 break;
1633 case VEN_MSG_INPUT_BUFFER_DONE:
1634 omxhdr = (OMX_BUFFERHEADERTYPE* )\
1635 m_sVenc_msg->buf.clientdata;
1636
1637 if(omxhdr == NULL ||
1638 (((OMX_U32)(omxhdr - omx->m_inp_mem_ptr) > omx->m_sInPortDef.nBufferCountActual) &&
1639 ((OMX_U32)(omxhdr - omx->meta_buffer_hdr) > omx->m_sInPortDef.nBufferCountActual)))
1640 {
1641 omxhdr = NULL;
1642 m_sVenc_msg->statuscode = VEN_S_EFAIL;
1643 }
1644
1645 #ifdef _ANDROID_ICS_
1646 omx->omx_release_meta_buffer(omxhdr);
1647 #endif
1648 omx->post_event ((unsigned int)omxhdr,m_sVenc_msg->statuscode,
1649 OMX_COMPONENT_GENERATE_EBD);
1650 break;
1651 case VEN_MSG_OUTPUT_BUFFER_DONE:
1652
1653 omxhdr = (OMX_BUFFERHEADERTYPE*)m_sVenc_msg->buf.clientdata;
1654
1655 if( (omxhdr != NULL) &&
1656 ((OMX_U32)(omxhdr - omx->m_out_mem_ptr) < omx->m_sOutPortDef.nBufferCountActual))
1657 {
1658 if(m_sVenc_msg->buf.len <= omxhdr->nAllocLen)
1659 {
1660 omxhdr->nFilledLen = m_sVenc_msg->buf.len;
1661 omxhdr->nOffset = m_sVenc_msg->buf.offset;
1662 omxhdr->nTimeStamp = m_sVenc_msg->buf.timestamp;
1663 DEBUG_PRINT_LOW("\n o/p TS = %u", (OMX_U32)m_sVenc_msg->buf.timestamp);
1664 omxhdr->nFlags = m_sVenc_msg->buf.flags;
1665
1666 /*Use buffer case*/
1667 if(omx->output_use_buffer && !omx->m_use_output_pmem)
1668 {
1669 DEBUG_PRINT_LOW("\n memcpy() for o/p Heap UseBuffer");
1670 memcpy(omxhdr->pBuffer,
1671 (m_sVenc_msg->buf.ptrbuffer),
1672 m_sVenc_msg->buf.len);
1673 }
1674 }
1675 else
1676 {
1677 omxhdr->nFilledLen = 0;
1678 }
1679
1680 }
1681 else
1682 {
1683 omxhdr = NULL;
1684 m_sVenc_msg->statuscode = VEN_S_EFAIL;
1685 }
1686
1687 omx->post_event ((unsigned int)omxhdr,m_sVenc_msg->statuscode,
1688 OMX_COMPONENT_GENERATE_FBD);
1689 break;
1690 case VEN_MSG_NEED_OUTPUT_BUFFER:
1691 //TBD what action needs to be done here??
1692 break;
1693 default:
1694 break;
1695 }
1696 return 0;
1697 }
is_secure_session()1698 bool omx_venc::is_secure_session()
1699 {
1700 return secure_session;
1701 }
1702