OMX_ERRORTYPE IL_ClientSetEncodeParams (IL_Client *pAppData) { OMX_ERRORTYPE eError = OMX_ErrorUndefined; OMX_HANDLETYPE pHandle = NULL; OMX_VIDEO_PARAM_PROFILELEVELTYPE tProfileLevel; OMX_VIDEO_PARAM_ENCODER_PRESETTYPE tEncoderPreset; OMX_VIDEO_PARAM_BITRATETYPE tVidEncBitRate; OMX_VIDEO_PARAM_PORTFORMATTYPE tVideoParams; OMX_PARAM_PORTDEFINITIONTYPE tPortDef; OMX_VIDEO_CONFIG_DYNAMICPARAMS tDynParams; OMX_VIDEO_PARAM_STATICPARAMS tStaticParam; OMX_VIDEO_PARAM_AVCTYPE tAVCParams; pHandle = pAppData->pEncHandle; /* Number of frames to be encoded */ pAppData->encILComp->numFrames = pAppData->evmAppInParams->noFrames; OMX_INIT_PARAM (&tPortDef); /* Get the Number of Ports */ tPortDef.nPortIndex = OMX_VIDENC_INPUT_PORT; eError = OMX_GetParameter (pHandle, OMX_IndexParamPortDefinition, &tPortDef); /* set the actual number of buffers required */ tPortDef.nBufferCountActual = IL_CLIENT_ENC_INPUT_BUFFER_COUNT; /* set the video format settings */ tPortDef.format.video.nFrameWidth = pAppData->nWidth; tPortDef.format.video.nStride = pAppData->nWidth; tPortDef.format.video.nFrameHeight = pAppData->nHeight; if(pAppData->nScanFormat && !pAppData->evmAppInParams->deiEnable) { tPortDef.format.video.nFrameHeight = pAppData->nHeight >> 1; } tPortDef.format.video.eColorFormat = OMX_COLOR_FormatYUV420SemiPlanar; /* settings for OMX_IndexParamVideoPortFormat */ tPortDef.nBufferSize = (pAppData->nWidth * pAppData->nHeight * 3) >> 1; eError = OMX_SetParameter (pHandle, OMX_IndexParamPortDefinition, &tPortDef); if (eError != OMX_ErrorNone) { ERROR ("failed to set Encode OMX_IndexParamPortDefinition for input \n"); } OMX_INIT_PARAM (&tPortDef); tPortDef.nPortIndex = OMX_VIDENC_OUTPUT_PORT; eError = OMX_GetParameter (pHandle, OMX_IndexParamPortDefinition, &tPortDef); /* settings for OMX_IndexParamPortDefinition */ /* set the actual number of buffers required */ tPortDef.nBufferCountActual = IL_CLIENT_ENC_OUTPUT_BUFFER_COUNT; tPortDef.format.video.nFrameWidth = pAppData->nWidth; tPortDef.format.video.nFrameHeight = pAppData->nHeight; tPortDef.format.video.eCompressionFormat = OMX_VIDEO_CodingAVC; tPortDef.format.video.xFramerate = (pAppData->evmAppInParams->frameRate << 16); tVideoParams.xFramerate = (pAppData->evmAppInParams->frameRate << 16); tPortDef.format.video.nBitrate = pAppData->evmAppInParams->videoBitRate; /* settings for OMX_IndexParamVideoPortFormat */ eError = OMX_SetParameter (pHandle, OMX_IndexParamPortDefinition, &tPortDef); if (eError != OMX_ErrorNone) { ERROR ("failed to set Encode OMX_IndexParamPortDefinition for output \n"); } /* For changing bit rate following index can be used */ OMX_INIT_PARAM (&tVidEncBitRate); tVidEncBitRate.nPortIndex = OMX_VIDENC_OUTPUT_PORT; eError = OMX_GetParameter (pHandle, OMX_IndexParamVideoBitrate, &tVidEncBitRate); tVidEncBitRate.eControlRate = OMX_Video_ControlRateVariable; tVidEncBitRate.nTargetBitrate = pAppData->evmAppInParams->videoBitRate; eError = OMX_SetParameter (pHandle, OMX_IndexParamVideoBitrate, &tVidEncBitRate); if (eError != OMX_ErrorNone) { ERROR ("failed to set Encode bitrate \n"); } /* Set the profile and level for H264 */ OMX_INIT_PARAM (&tProfileLevel); tProfileLevel.nPortIndex = OMX_VIDENC_OUTPUT_PORT; eError = OMX_GetParameter (pHandle, OMX_IndexParamVideoProfileLevelCurrent, &tProfileLevel); /* set as high profile with 4.2 level */ tProfileLevel.eProfile = OMX_VIDEO_AVCProfileHigh; tProfileLevel.eLevel = OMX_VIDEO_AVCLevel42; eError = OMX_SetParameter (pHandle, OMX_IndexParamVideoProfileLevelCurrent, &tProfileLevel); if (eError != OMX_ErrorNone) ERROR ("failed to set encoder pfofile \n"); /* Encoder Preset settings */ OMX_INIT_PARAM (&tEncoderPreset); tEncoderPreset.nPortIndex = OMX_VIDENC_OUTPUT_PORT; eError = OMX_GetParameter (pHandle, OMX_TI_IndexParamVideoEncoderPreset, &tEncoderPreset); tEncoderPreset.eEncodingModePreset = OMX_Video_Enc_Default; tEncoderPreset.eRateControlPreset = OMX_Video_RC_None; eError = OMX_SetParameter (pHandle, OMX_TI_IndexParamVideoEncoderPreset, &tEncoderPreset); if (eError != OMX_ErrorNone) { ERROR ("failed to Encoder Preset \n"); } OMX_INIT_PARAM (&tDynParams); tDynParams.nPortIndex = OMX_VIDENC_OUTPUT_PORT; eError = OMX_GetParameter (pHandle, OMX_TI_IndexParamVideoDynamicParams, &tDynParams); /* setting I frame interval */ tDynParams.videoDynamicParams.h264EncDynamicParams.videnc2DynamicParams.targetFrameRate = pAppData->evmAppInParams->frameRate * 1000; tDynParams.videoDynamicParams.h264EncDynamicParams.videnc2DynamicParams.targetBitRate = pAppData->evmAppInParams->videoBitRate; /* EI: Rate-control settings done with Enocoder's Static parameters are not taking effect. So we set rate control parameters in Encoder's Dynamic parameters. */ tDynParams.videoDynamicParams.h264EncDynamicParams.rateControlParams.rateControlParamsPreset = pAppData->evmAppInParams->rateControlParamsPreset; tDynParams.videoDynamicParams.h264EncDynamicParams.rateControlParams.rcAlgo = pAppData->evmAppInParams->rcAlgo; tDynParams.videoDynamicParams.h264EncDynamicParams.rateControlParams.qpI = pAppData->evmAppInParams->qpI; tDynParams.videoDynamicParams.h264EncDynamicParams.rateControlParams.qpP = pAppData->evmAppInParams->qpP; tDynParams.videoDynamicParams.h264EncDynamicParams.rateControlParams.qpOffsetB = pAppData->evmAppInParams->qpOffsetB; tDynParams.videoDynamicParams.h264EncDynamicParams.rateControlParams.qpMaxI = pAppData->evmAppInParams->qpMaxI; tDynParams.videoDynamicParams.h264EncDynamicParams.rateControlParams.qpMaxP = pAppData->evmAppInParams->qpMaxP; tDynParams.videoDynamicParams.h264EncDynamicParams.rateControlParams.qpMaxB = pAppData->evmAppInParams->qpMaxB; tDynParams.videoDynamicParams.h264EncDynamicParams.rateControlParams.allowFrameSkip = pAppData->evmAppInParams->allowFrameSkip; tDynParams.videoDynamicParams.h264EncDynamicParams.rateControlParams.HRDBufferSize = pAppData->evmAppInParams->videoBitRate * 2; /* EI: As like rate-control, it may happened that changing inter-coding parameters may not effect with static parameter's structure, so we set these params as well with Dynamic structure. */ tDynParams.videoDynamicParams.h264EncDynamicParams.interCodingParams.interCodingPreset = pAppData->evmAppInParams->interCodingPreset; tDynParams.videoDynamicParams.h264EncDynamicParams.interCodingParams.searchRangeHorP = pAppData->evmAppInParams->searchRangeHorP; tDynParams.videoDynamicParams.h264EncDynamicParams.interCodingParams.searchRangeVerP = pAppData->evmAppInParams->searchRangeVerP; tDynParams.videoDynamicParams.h264EncDynamicParams.interCodingParams.searchRangeHorB = pAppData->evmAppInParams->searchRangeHorB; tDynParams.videoDynamicParams.h264EncDynamicParams.interCodingParams.searchRangeVerB = pAppData->evmAppInParams->searchRangeVerB; tDynParams.videoDynamicParams.h264EncDynamicParams.interCodingParams.minBlockSizeP = pAppData->evmAppInParams->minBlockSizeP; tDynParams.videoDynamicParams.h264EncDynamicParams.interCodingParams.minBlockSizeB = pAppData->evmAppInParams->minBlockSizeB; tDynParams.videoDynamicParams.h264EncDynamicParams.videnc2DynamicParams.intraFrameInterval = 90; eError = OMX_SetParameter (pHandle, OMX_TI_IndexParamVideoDynamicParams, &tDynParams); OMX_INIT_PARAM (&tStaticParam); tStaticParam.nPortIndex = OMX_VIDENC_OUTPUT_PORT; eError = OMX_GetParameter (pHandle, OMX_TI_IndexParamVideoStaticParams, &tStaticParam); /* To use extended parameters */ tStaticParam.videoStaticParams.h264EncStaticParams.rateControlParams.HRDBufferSize = pAppData->evmAppInParams->videoBitRate * 2; tStaticParam.videoStaticParams.h264EncStaticParams.videnc2Params.encodingPreset = XDM_USER_DEFINED; tStaticParam.videoStaticParams.h264EncStaticParams.videnc2Params.rateControlPreset = IVIDEO_USER_DEFINED; if(pAppData->nScanFormat && !pAppData->evmAppInParams->deiEnable) { /* for interlace, base profile can not be used */ tStaticParam.videoStaticParams.h264EncStaticParams.videnc2Params.profile = IH264_HIGH_PROFILE; tStaticParam.videoStaticParams.h264EncStaticParams.videnc2Params.level = IH264_LEVEL_22; /* setting Interlace mode */ tStaticParam.videoStaticParams.h264EncStaticParams.videnc2Params.inputContentType = IVIDEO_INTERLACED; tStaticParam.videoStaticParams.h264EncStaticParams.bottomFieldIntra = 0; tStaticParam.videoStaticParams.h264EncStaticParams.interlaceCodingType = IH264_INTERLACE_FIELDONLY; tStaticParam.videoStaticParams.h264EncStaticParams.videnc2Params.encodingPreset = XDM_USER_DEFINED; tStaticParam.videoStaticParams.h264EncStaticParams.videnc2Params.rateControlPreset = IVIDEO_USER_DEFINED; tStaticParam.videoStaticParams.h264EncStaticParams.intraCodingParams.lumaIntra4x4Enable = 309; tStaticParam.videoStaticParams.h264EncStaticParams.intraCodingParams.lumaIntra8x8Enable = 320; } /* To set user-defined NAL Unit */ tStaticParam.videoStaticParams.h264EncStaticParams.nalUnitControlParams.naluControlPreset = IH264_NALU_CONTROL_USERDEFINED; H264_SETNALU_MASK_SPS(tStaticParam.videoStaticParams.h264EncStaticParams.nalUnitControlParams.naluPresentMaskIntraPicture); H264_SETNALU_MASK_PPS(tStaticParam.videoStaticParams.h264EncStaticParams.nalUnitControlParams.naluPresentMaskIntraPicture); H264_SETNALU_MASK_SPS(tStaticParam.videoStaticParams.h264EncStaticParams.nalUnitControlParams.naluPresentMaskIDRPicture); H264_SETNALU_MASK_PPS(tStaticParam.videoStaticParams.h264EncStaticParams.nalUnitControlParams.naluPresentMaskIDRPicture); H264_SETNALU_MASK_SEI(tStaticParam.videoStaticParams.h264EncStaticParams.nalUnitControlParams.naluPresentMaskIDRPicture); H264_SETNALU_MASK_SPS(tStaticParam.videoStaticParams.h264EncStaticParams.nalUnitControlParams.naluPresentMaskStartOfSequence); H264_SETNALU_MASK_PPS(tStaticParam.videoStaticParams.h264EncStaticParams.nalUnitControlParams.naluPresentMaskStartOfSequence); H264_SETNALU_MASK_SEI(tStaticParam.videoStaticParams.h264EncStaticParams.nalUnitControlParams.naluPresentMaskStartOfSequence); /* To set VUI information */ tStaticParam.videoStaticParams.h264EncStaticParams.vuiCodingParams.vuiCodingPreset = IH264_VUICODING_USERDEFINED; tStaticParam.videoStaticParams.h264EncStaticParams.vuiCodingParams.hrdParamsPresentFlag = 1; tStaticParam.videoStaticParams.h264EncStaticParams.vuiCodingParams.timingInfoPresentFlag = 1; /* EI: To set maximum intra-frame interval of encoder, by default it was for 0x7FFF So encoder will not work for setting no of P-Frame more than that but with below setting user can set no of P-Frame at max 0xFFFF */ tStaticParam.videoStaticParams.h264EncStaticParams.maxIntraFrameInterval = 0xFFFF; /* EI: Rate-control settings done with Enocoder's Static parameters are not taking effect. So we set rate control parameters in Encoder's Dynamic parameters. */ /* EI: As like rate-control, it may happened that changing inter-coding parameters may not effect with static parameter's structure, so we set these params as well with Dynamic structure. During testing of this, while we change these params encoder return with bad param */ eError = OMX_SetParameter (pHandle, OMX_TI_IndexParamVideoStaticParams, &tStaticParam); /* Set AVC params */ OMX_INIT_PARAM (&tAVCParams); tAVCParams.nPortIndex = OMX_DirOutput; eError = OMX_GetParameter(pHandle, OMX_IndexParamVideoAvc, &tAVCParams); if(eError != OMX_ErrorNone) { printf("failed to Encoder OMX_IndexParamVideoAvc getparams\n"); } else { printf("success OMX_IndexParamVideoAvc getparams\n"); } tAVCParams.eLevel = OMX_VIDEO_AVCLevel42; tAVCParams.eProfile = OMX_VIDEO_AVCProfileHigh; tAVCParams.nBFrames = pAppData->evmAppInParams->noBFrame; tAVCParams.nPFrames = pAppData->evmAppInParams->noPFrame; eError = OMX_SetParameter(pHandle, OMX_IndexParamVideoAvc, &tAVCParams); if(eError != OMX_ErrorNone) { printf("failed to encoder OMX_IndexParamVideoAvc setparams\n"); } else { printf("success OMX_IndexParamVideoAvc setparams\n"); } return eError; }