00001
00030 #include <omxcore.h>
00031 #include <omx_base_video_port.h>
00032 #include <omx_videoenc_component.h>
00033 #include<OMX_Video.h>
00034
00036 #define MAX_COMPONENT_VIDEOENC 4
00037
00039 static OMX_U32 noVideoEncInstance = 0;
00040
00042 #define OUTPUT_ENCODED_COLOR_FMT OMX_COLOR_FormatYUV420Planar
00043
00047 OMX_ERRORTYPE omx_videoenc_component_Constructor(OMX_COMPONENTTYPE *openmaxStandComp,OMX_STRING cComponentName) {
00048
00049 OMX_ERRORTYPE eError = OMX_ErrorNone;
00050 omx_videoenc_component_PrivateType* omx_videoenc_component_Private;
00051 omx_base_video_PortType *inPort,*outPort;
00052 OMX_U32 i;
00053
00054 if (!openmaxStandComp->pComponentPrivate) {
00055 DEBUG(DEB_LEV_FUNCTION_NAME, "In %s, allocating component\n", __func__);
00056 openmaxStandComp->pComponentPrivate = calloc(1, sizeof(omx_videoenc_component_PrivateType));
00057 if(openmaxStandComp->pComponentPrivate == NULL) {
00058 return OMX_ErrorInsufficientResources;
00059 }
00060 } else {
00061 DEBUG(DEB_LEV_FUNCTION_NAME, "In %s, Error Component %x Already Allocated\n", __func__, (int)openmaxStandComp->pComponentPrivate);
00062 }
00063
00064 omx_videoenc_component_Private = openmaxStandComp->pComponentPrivate;
00065 omx_videoenc_component_Private->ports = NULL;
00066
00070 eError = omx_base_filter_Constructor(openmaxStandComp, cComponentName);
00071
00073 if (omx_videoenc_component_Private->sPortTypesParam.nPorts && !omx_videoenc_component_Private->ports) {
00074 omx_videoenc_component_Private->ports = calloc(omx_videoenc_component_Private->sPortTypesParam.nPorts, sizeof(omx_base_PortType *));
00075 if (!omx_videoenc_component_Private->ports) {
00076 return OMX_ErrorInsufficientResources;
00077 }
00078 for (i=0; i < omx_videoenc_component_Private->sPortTypesParam.nPorts; i++) {
00079 omx_videoenc_component_Private->ports[i] = calloc(1, sizeof(omx_base_video_PortType));
00080 if (!omx_videoenc_component_Private->ports[i]) {
00081 return OMX_ErrorInsufficientResources;
00082 }
00083 }
00084 }
00085
00086 base_video_port_Constructor(openmaxStandComp, &omx_videoenc_component_Private->ports[0], 0, OMX_TRUE);
00087 base_video_port_Constructor(openmaxStandComp, &omx_videoenc_component_Private->ports[1], 1, OMX_FALSE);
00088
00092
00093 inPort = (omx_base_video_PortType *)omx_videoenc_component_Private->ports[OMX_BASE_FILTER_INPUTPORT_INDEX];
00094 inPort->sPortParam.format.video.nFrameWidth = 176;
00095 inPort->sPortParam.format.video.nFrameHeight = 144;
00096 inPort->sPortParam.nBufferSize = inPort->sPortParam.format.video.nFrameWidth*
00097 inPort->sPortParam.format.video.nFrameHeight*3/2;
00098 inPort->sPortParam.format.video.xFramerate = 25;
00099 inPort->sPortParam.format.video.eColorFormat = OMX_COLOR_FormatYUV420Planar;
00100 inPort->sVideoParam.eColorFormat = OMX_COLOR_FormatYUV420Planar;
00101
00102
00103 outPort = (omx_base_video_PortType *)omx_videoenc_component_Private->ports[OMX_BASE_FILTER_OUTPUTPORT_INDEX];
00104 outPort->sPortParam.nBufferSize = FF_MIN_BUFFER_SIZE;
00105 outPort->sPortParam.format.video.xFramerate = 25;
00106 outPort->sPortParam.format.video.nFrameWidth = 176;
00107 outPort->sPortParam.format.video.nFrameHeight = 144;
00108
00110 if(!strcmp(cComponentName, VIDEO_ENC_MPEG4_NAME)) {
00111 omx_videoenc_component_Private->video_encoding_type = OMX_VIDEO_CodingMPEG4;
00112 } else if (!strcmp(cComponentName, VIDEO_ENC_BASE_NAME)) {
00113 omx_videoenc_component_Private->video_encoding_type = OMX_VIDEO_CodingUnused;
00114 } else {
00115
00116 DEBUG(DEB_LEV_ERR, "In valid component name\n");
00117 return OMX_ErrorInvalidComponentName;
00118 }
00119
00120 if(!omx_videoenc_component_Private->avCodecSyncSem) {
00121 omx_videoenc_component_Private->avCodecSyncSem = malloc(sizeof(tsem_t));
00122 if(omx_videoenc_component_Private->avCodecSyncSem == NULL) {
00123 return OMX_ErrorInsufficientResources;
00124 }
00125 tsem_init(omx_videoenc_component_Private->avCodecSyncSem, 0);
00126 }
00127
00128 SetInternalVideoEncParameters(openmaxStandComp);
00129
00130 omx_videoenc_component_Private->eOutFramePixFmt = PIX_FMT_YUV420P;
00131
00132 if(omx_videoenc_component_Private->video_encoding_type == OMX_VIDEO_CodingMPEG4) {
00133 omx_videoenc_component_Private->ports[OMX_BASE_FILTER_INPUTPORT_INDEX]->sPortParam.format.video.eCompressionFormat = OMX_VIDEO_CodingMPEG4;
00134 }
00135
00139 omx_videoenc_component_Private->avCodec = NULL;
00140 omx_videoenc_component_Private->avCodecContext= NULL;
00141 omx_videoenc_component_Private->avcodecReady = OMX_FALSE;
00142 omx_videoenc_component_Private->BufferMgmtCallback = omx_videoenc_component_BufferMgmtCallback;
00143
00145 omx_videoenc_component_Private->messageHandler = omx_videoenc_component_MessageHandler;
00146 omx_videoenc_component_Private->destructor = omx_videoenc_component_Destructor;
00147 openmaxStandComp->SetParameter = omx_videoenc_component_SetParameter;
00148 openmaxStandComp->GetParameter = omx_videoenc_component_GetParameter;
00149 openmaxStandComp->ComponentRoleEnum = omx_videoenc_component_ComponentRoleEnum;
00150
00151 noVideoEncInstance++;
00152
00153 if(noVideoEncInstance > MAX_COMPONENT_VIDEOENC) {
00154 return OMX_ErrorInsufficientResources;
00155 }
00156 return eError;
00157 }
00158
00159
00162 OMX_ERRORTYPE omx_videoenc_component_Destructor(OMX_COMPONENTTYPE *openmaxStandComp) {
00163 omx_videoenc_component_PrivateType* omx_videoenc_component_Private = openmaxStandComp->pComponentPrivate;
00164 OMX_U32 i;
00165
00166 if(omx_videoenc_component_Private->avCodecSyncSem) {
00167 free(omx_videoenc_component_Private->avCodecSyncSem);
00168 omx_videoenc_component_Private->avCodecSyncSem = NULL;
00169 }
00170
00171
00172 if (omx_videoenc_component_Private->ports) {
00173 for (i=0; i < omx_videoenc_component_Private->sPortTypesParam.nPorts; i++) {
00174 if(omx_videoenc_component_Private->ports[i])
00175 omx_videoenc_component_Private->ports[i]->PortDestructor(omx_videoenc_component_Private->ports[i]);
00176 }
00177 free(omx_videoenc_component_Private->ports);
00178 omx_videoenc_component_Private->ports=NULL;
00179 }
00180
00181 DEBUG(DEB_LEV_FUNCTION_NAME, "Destructor of video encoder component is called\n");
00182
00183 omx_base_filter_Destructor(openmaxStandComp);
00184 noVideoEncInstance--;
00185
00186 return OMX_ErrorNone;
00187 }
00188
00189
00192 OMX_ERRORTYPE omx_videoenc_component_ffmpegLibInit(omx_videoenc_component_PrivateType* omx_videoenc_component_Private) {
00193
00194 omx_base_video_PortType *inPort = (omx_base_video_PortType *)omx_videoenc_component_Private->ports[OMX_BASE_FILTER_INPUTPORT_INDEX];
00195 OMX_U32 target_coencID;
00196 avcodec_init();
00197 av_register_all();
00198
00199 DEBUG(DEB_LEV_SIMPLE_SEQ, "FFmpeg library/encoder initialized\n");
00200
00201 switch(omx_videoenc_component_Private->video_encoding_type) {
00202 case OMX_VIDEO_CodingMPEG4 :
00203 target_coencID = CODEC_ID_MPEG4;
00204 break;
00205 default :
00206 DEBUG(DEB_LEV_ERR, "\n encoders other than MPEG-4 are not supported -- encoder not found\n");
00207 return OMX_ErrorComponentNotFound;
00208 }
00209
00211 omx_videoenc_component_Private->avCodec = avcodec_find_encoder(target_coencID);
00212 if (omx_videoenc_component_Private->avCodec == NULL) {
00213 DEBUG(DEB_LEV_ERR, "Encoder Not found\n");
00214 return OMX_ErrorInsufficientResources;
00215 }
00216
00217 omx_videoenc_component_Private->avCodecContext = avcodec_alloc_context();
00218 omx_videoenc_component_Private->picture = avcodec_alloc_frame ();
00219
00220
00221 omx_videoenc_component_Private->avCodecContext->bit_rate = 400000;
00222 omx_videoenc_component_Private->avCodecContext->width = inPort->sPortParam.format.video.nFrameWidth;
00223 omx_videoenc_component_Private->avCodecContext->height = inPort->sPortParam.format.video.nFrameHeight;
00224
00225
00226 DEBUG(DEB_LEV_SIMPLE_SEQ, "Frame Rate=%d\n",(int)inPort->sPortParam.format.video.xFramerate);
00227 omx_videoenc_component_Private->avCodecContext->time_base= (AVRational){1,inPort->sPortParam.format.video.xFramerate};
00228 omx_videoenc_component_Private->avCodecContext->gop_size = 5;
00229 omx_videoenc_component_Private->avCodecContext->max_b_frames=1;
00230 omx_videoenc_component_Private->avCodecContext->pix_fmt = PIX_FMT_YUV420P;
00231
00232 if (avcodec_open(omx_videoenc_component_Private->avCodecContext, omx_videoenc_component_Private->avCodec) < 0) {
00233 DEBUG(DEB_LEV_ERR, "Could not open encoder\n");
00234 return OMX_ErrorInsufficientResources;
00235 }
00236 tsem_up(omx_videoenc_component_Private->avCodecSyncSem);
00237 DEBUG(DEB_LEV_SIMPLE_SEQ, "done\n");
00238
00239 return OMX_ErrorNone;
00240 }
00241
00244 void omx_videoenc_component_ffmpegLibDeInit(omx_videoenc_component_PrivateType* omx_videoenc_component_Private) {
00245
00246 avcodec_close(omx_videoenc_component_Private->avCodecContext);
00247 if (omx_videoenc_component_Private->avCodecContext->priv_data) {
00248 avcodec_close (omx_videoenc_component_Private->avCodecContext);
00249 }
00250 if (omx_videoenc_component_Private->avCodecContext->extradata) {
00251 av_free (omx_videoenc_component_Private->avCodecContext->extradata);
00252 omx_videoenc_component_Private->avCodecContext->extradata = NULL;
00253 }
00254 av_free (omx_videoenc_component_Private->avCodecContext);
00255
00256 av_free(omx_videoenc_component_Private->picture);
00257
00258 }
00259
00262 void SetInternalVideoEncParameters(OMX_COMPONENTTYPE *openmaxStandComp) {
00263
00264 omx_videoenc_component_PrivateType* omx_videoenc_component_Private = openmaxStandComp->pComponentPrivate;
00265 omx_base_video_PortType *outPort = (omx_base_video_PortType *)omx_videoenc_component_Private->ports[OMX_BASE_FILTER_OUTPUTPORT_INDEX];
00266
00267 if (omx_videoenc_component_Private->video_encoding_type == OMX_VIDEO_CodingMPEG4) {
00268 strcpy(outPort->sPortParam.format.video.cMIMEType,"video/mpeg4");
00269 outPort->sPortParam.format.video.eCompressionFormat = OMX_VIDEO_CodingMPEG4;
00270 outPort->sVideoParam.eCompressionFormat = OMX_VIDEO_CodingMPEG4;
00271
00272 setHeader(&omx_videoenc_component_Private->pVideoMpeg4, sizeof(OMX_VIDEO_PARAM_MPEG4TYPE));
00273 omx_videoenc_component_Private->pVideoMpeg4.nPortIndex = 1;
00274 omx_videoenc_component_Private->pVideoMpeg4.nSliceHeaderSpacing = 0;
00275 omx_videoenc_component_Private->pVideoMpeg4.bSVH = OMX_FALSE;
00276 omx_videoenc_component_Private->pVideoMpeg4.bGov = OMX_FALSE;
00277 omx_videoenc_component_Private->pVideoMpeg4.nPFrames = 0;
00278 omx_videoenc_component_Private->pVideoMpeg4.nBFrames = 0;
00279 omx_videoenc_component_Private->pVideoMpeg4.nIDCVLCThreshold = 0;
00280 omx_videoenc_component_Private->pVideoMpeg4.bACPred = OMX_FALSE;
00281 omx_videoenc_component_Private->pVideoMpeg4.nMaxPacketSize = 0;
00282 omx_videoenc_component_Private->pVideoMpeg4.nTimeIncRes = 0;
00283 omx_videoenc_component_Private->pVideoMpeg4.eProfile = OMX_VIDEO_MPEG4ProfileSimple;
00284 omx_videoenc_component_Private->pVideoMpeg4.eLevel = OMX_VIDEO_MPEG4Level0;
00285 omx_videoenc_component_Private->pVideoMpeg4.nAllowedPictureTypes = 0;
00286 omx_videoenc_component_Private->pVideoMpeg4.nHeaderExtension = 0;
00287 omx_videoenc_component_Private->pVideoMpeg4.bReversibleVLC = OMX_FALSE;
00288
00289 }
00290 }
00291
00292
00295 OMX_ERRORTYPE omx_videoenc_component_Init(OMX_COMPONENTTYPE *openmaxStandComp) {
00296
00297 omx_videoenc_component_PrivateType* omx_videoenc_component_Private = openmaxStandComp->pComponentPrivate;
00298 OMX_ERRORTYPE eError = OMX_ErrorNone;
00299
00301 omx_videoenc_component_Private->isFirstBuffer = 1;
00302 omx_videoenc_component_Private->isNewBuffer = 1;
00303
00304 return eError;
00305 }
00306
00309 OMX_ERRORTYPE omx_videoenc_component_Deinit(OMX_COMPONENTTYPE *openmaxStandComp) {
00310
00311 omx_videoenc_component_PrivateType* omx_videoenc_component_Private = openmaxStandComp->pComponentPrivate;
00312 OMX_ERRORTYPE eError = OMX_ErrorNone;
00313
00314 if (omx_videoenc_component_Private->avcodecReady) {
00315 omx_videoenc_component_ffmpegLibDeInit(omx_videoenc_component_Private);
00316 omx_videoenc_component_Private->avcodecReady = OMX_FALSE;
00317 }
00318
00319 return eError;
00320 }
00321
00324 static inline void UpdateFrameSize(OMX_COMPONENTTYPE *openmaxStandComp) {
00325 omx_videoenc_component_PrivateType* omx_videoenc_component_Private = openmaxStandComp->pComponentPrivate;
00326 omx_base_video_PortType *inPort = (omx_base_video_PortType *)omx_videoenc_component_Private->ports[OMX_BASE_FILTER_INPUTPORT_INDEX];
00327 switch(inPort->sPortParam.format.video.eColorFormat) {
00328 case OMX_COLOR_FormatYUV420Planar:
00329 inPort->sPortParam.nBufferSize = inPort->sPortParam.format.video.nFrameWidth * inPort->sPortParam.format.video.nFrameHeight * 3/2;
00330 break;
00331 default:
00332 inPort->sPortParam.nBufferSize = inPort->sPortParam.format.video.nFrameWidth * inPort->sPortParam.format.video.nFrameHeight * 3;
00333 break;
00334 }
00335 }
00336
00339 void omx_videoenc_component_BufferMgmtCallback(OMX_COMPONENTTYPE *openmaxStandComp, OMX_BUFFERHEADERTYPE* pInputBuffer, OMX_BUFFERHEADERTYPE* pOutputBuffer) {
00340
00341 omx_videoenc_component_PrivateType* omx_videoenc_component_Private = openmaxStandComp->pComponentPrivate;
00342 omx_base_video_PortType *inPort = (omx_base_video_PortType *)omx_videoenc_component_Private->ports[OMX_BASE_FILTER_INPUTPORT_INDEX];
00343
00344 OMX_S32 nOutputFilled = 0;
00345 OMX_U8* outputCurrBuffer;
00346 OMX_S32 nLen = 0;
00347 int size;
00348
00349 size= inPort->sPortParam.format.video.nFrameWidth*inPort->sPortParam.format.video.nFrameHeight;
00350
00351 DEBUG(DEB_LEV_FUNCTION_NAME, "In %s\n", __func__);
00353 if(omx_videoenc_component_Private->isNewBuffer) {
00354 omx_videoenc_component_Private->isNewBuffer = 0;
00355 DEBUG(DEB_LEV_FULL_SEQ, "New Buffer FilledLen = %d\n", (int)pInputBuffer->nFilledLen);
00356
00357 omx_videoenc_component_Private->picture->data[0] = pInputBuffer->pBuffer;
00358 omx_videoenc_component_Private->picture->data[1] = omx_videoenc_component_Private->picture->data[0] + size;
00359 omx_videoenc_component_Private->picture->data[2] = omx_videoenc_component_Private->picture->data[1] + size / 4;
00360 omx_videoenc_component_Private->picture->linesize[0] = inPort->sPortParam.format.video.nFrameWidth;
00361 omx_videoenc_component_Private->picture->linesize[1] = inPort->sPortParam.format.video.nFrameWidth / 2;
00362 omx_videoenc_component_Private->picture->linesize[2] = inPort->sPortParam.format.video.nFrameWidth / 2;
00363 }
00364
00365 outputCurrBuffer = pOutputBuffer->pBuffer;
00366 pOutputBuffer->nFilledLen = 0;
00367 pOutputBuffer->nOffset = 0;
00368
00369 while (!nOutputFilled) {
00370 if (omx_videoenc_component_Private->isFirstBuffer) {
00371 tsem_down(omx_videoenc_component_Private->avCodecSyncSem);
00372 omx_videoenc_component_Private->isFirstBuffer = 0;
00373 }
00374 omx_videoenc_component_Private->avCodecContext->frame_number++;
00375
00376 nLen = avcodec_encode_video(omx_videoenc_component_Private->avCodecContext,
00377 outputCurrBuffer,
00378 pOutputBuffer->nAllocLen,
00379 omx_videoenc_component_Private->picture);
00380
00381 if (nLen < 0) {
00382 DEBUG(DEB_LEV_ERR, "----> A general error or simply frame not encoded?\n");
00383 }
00384
00385 pInputBuffer->nFilledLen = 0;
00386 omx_videoenc_component_Private->isNewBuffer = 1;
00387 if ( nLen >= 0) {
00388 pOutputBuffer->nFilledLen = nLen;
00389 }
00390 nOutputFilled = 1;
00391 }
00392 DEBUG(DEB_LEV_FULL_SEQ, "One output buffer %x nLen=%d is full returning in video encoder\n",
00393 (int)pOutputBuffer->pBuffer, (int)pOutputBuffer->nFilledLen);
00394 }
00395
00396 OMX_ERRORTYPE omx_videoenc_component_SetParameter(
00397 OMX_IN OMX_HANDLETYPE hComponent,
00398 OMX_IN OMX_INDEXTYPE nParamIndex,
00399 OMX_IN OMX_PTR ComponentParameterStructure) {
00400
00401 OMX_ERRORTYPE eError = OMX_ErrorNone;
00402 OMX_U32 portIndex;
00403
00404
00405 OMX_COMPONENTTYPE *openmaxStandComp = hComponent;
00406 omx_videoenc_component_PrivateType* omx_videoenc_component_Private = openmaxStandComp->pComponentPrivate;
00407 omx_base_video_PortType *port;
00408 if (ComponentParameterStructure == NULL) {
00409 return OMX_ErrorBadParameter;
00410 }
00411
00412 DEBUG(DEB_LEV_SIMPLE_SEQ, " Setting parameter %i\n", nParamIndex);
00413 switch(nParamIndex) {
00414 case OMX_IndexParamPortDefinition:
00415 {
00416 OMX_PARAM_PORTDEFINITIONTYPE *pPortDef;
00417 pPortDef = ComponentParameterStructure;
00418 eError = omx_base_component_SetParameter(hComponent, nParamIndex, ComponentParameterStructure);
00419 if(eError != OMX_ErrorNone) {
00420 break;
00421 }
00422 UpdateFrameSize (openmaxStandComp);
00423 port = (omx_base_video_PortType *)omx_videoenc_component_Private->ports[pPortDef->nPortIndex];
00424 port->sVideoParam.eColorFormat = port->sPortParam.format.video.eColorFormat;
00425 port->sVideoParam.eCompressionFormat = port->sPortParam.format.video.eCompressionFormat;
00426 break;
00427 }
00428 case OMX_IndexParamVideoPortFormat:
00429 {
00430 OMX_VIDEO_PARAM_PORTFORMATTYPE *pVideoPortFormat;
00431 pVideoPortFormat = ComponentParameterStructure;
00432 portIndex = pVideoPortFormat->nPortIndex;
00433
00434 eError = omx_base_component_ParameterSanityCheck(hComponent, portIndex, pVideoPortFormat, sizeof(OMX_VIDEO_PARAM_PORTFORMATTYPE));
00435 if(eError!=OMX_ErrorNone) {
00436 DEBUG(DEB_LEV_ERR, "In %s Parameter Check Error=%x\n",__func__,eError);
00437 break;
00438 }
00439 if (portIndex <= 1) {
00440 port = (omx_base_video_PortType *)omx_videoenc_component_Private->ports[portIndex];
00441 memcpy(&port->sVideoParam, pVideoPortFormat, sizeof(OMX_VIDEO_PARAM_PORTFORMATTYPE));
00442 omx_videoenc_component_Private->ports[portIndex]->sPortParam.format.video.eColorFormat = port->sVideoParam.eColorFormat;
00443 omx_videoenc_component_Private->ports[portIndex]->sPortParam.format.video.eCompressionFormat = port->sVideoParam.eCompressionFormat;
00444
00445 if (portIndex == 1) {
00446 switch(port->sVideoParam.eColorFormat) {
00447 case OMX_COLOR_Format24bitRGB888 :
00448 omx_videoenc_component_Private->eOutFramePixFmt = PIX_FMT_RGB24;
00449 break;
00450 case OMX_COLOR_Format24bitBGR888 :
00451 omx_videoenc_component_Private->eOutFramePixFmt = PIX_FMT_BGR24;
00452 break;
00453 case OMX_COLOR_Format32bitBGRA8888 :
00454 omx_videoenc_component_Private->eOutFramePixFmt = PIX_FMT_BGR32;
00455 break;
00456 case OMX_COLOR_Format32bitARGB8888 :
00457 omx_videoenc_component_Private->eOutFramePixFmt = PIX_FMT_RGB32;
00458 break;
00459 case OMX_COLOR_Format16bitARGB1555 :
00460 omx_videoenc_component_Private->eOutFramePixFmt = PIX_FMT_RGB555;
00461 break;
00462 case OMX_COLOR_Format16bitRGB565 :
00463 omx_videoenc_component_Private->eOutFramePixFmt = PIX_FMT_RGB565;
00464 break;
00465 case OMX_COLOR_Format16bitBGR565 :
00466 omx_videoenc_component_Private->eOutFramePixFmt = PIX_FMT_BGR565;
00467 break;
00468 default:
00469 omx_videoenc_component_Private->eOutFramePixFmt = PIX_FMT_YUV420P;
00470 break;
00471 }
00472 UpdateFrameSize (openmaxStandComp);
00473 }
00474 } else {
00475 return OMX_ErrorBadPortIndex;
00476 }
00477 break;
00478 }
00479 case OMX_IndexParamStandardComponentRole:
00480 {
00481 OMX_PARAM_COMPONENTROLETYPE *pComponentRole;
00482 pComponentRole = ComponentParameterStructure;
00483 if (!strcmp((char *)pComponentRole->cRole, VIDEO_ENC_MPEG4_ROLE)) {
00484 omx_videoenc_component_Private->video_encoding_type = OMX_VIDEO_CodingMPEG4;
00485 } else {
00486 return OMX_ErrorBadParameter;
00487 }
00488 SetInternalVideoEncParameters(openmaxStandComp);
00489 break;
00490 }
00491 case OMX_IndexParamVideoMpeg4:
00492 {
00493 OMX_VIDEO_PARAM_MPEG4TYPE *pVideoMpeg4;
00494 pVideoMpeg4 = ComponentParameterStructure;
00495 portIndex = pVideoMpeg4->nPortIndex;
00496 eError = omx_base_component_ParameterSanityCheck(hComponent, portIndex, pVideoMpeg4, sizeof(OMX_VIDEO_PARAM_MPEG4TYPE));
00497 if(eError!=OMX_ErrorNone) {
00498 DEBUG(DEB_LEV_ERR, "In %s Parameter Check Error=%x\n",__func__,eError);
00499 break;
00500 }
00501 if (pVideoMpeg4->nPortIndex == 1) {
00502 memcpy(&omx_videoenc_component_Private->pVideoMpeg4, pVideoMpeg4, sizeof(OMX_VIDEO_PARAM_MPEG4TYPE));
00503 } else {
00504 return OMX_ErrorBadPortIndex;
00505 }
00506 break;
00507 }
00508 default:
00509 return omx_base_component_SetParameter(hComponent, nParamIndex, ComponentParameterStructure);
00510 }
00511 return eError;
00512 }
00513
00514 OMX_ERRORTYPE omx_videoenc_component_GetParameter(
00515 OMX_IN OMX_HANDLETYPE hComponent,
00516 OMX_IN OMX_INDEXTYPE nParamIndex,
00517 OMX_INOUT OMX_PTR ComponentParameterStructure) {
00518
00519 omx_base_video_PortType *port;
00520 OMX_ERRORTYPE eError = OMX_ErrorNone;
00521
00522 OMX_COMPONENTTYPE *openmaxStandComp = hComponent;
00523 omx_videoenc_component_PrivateType* omx_videoenc_component_Private = openmaxStandComp->pComponentPrivate;
00524 if (ComponentParameterStructure == NULL) {
00525 return OMX_ErrorBadParameter;
00526 }
00527 DEBUG(DEB_LEV_SIMPLE_SEQ, " Getting parameter %i\n", nParamIndex);
00528
00529 switch(nParamIndex) {
00530 case OMX_IndexParamVideoInit:
00531 if ((eError = checkHeader(ComponentParameterStructure, sizeof(OMX_PORT_PARAM_TYPE))) != OMX_ErrorNone) {
00532 break;
00533 }
00534 memcpy(ComponentParameterStructure, &omx_videoenc_component_Private->sPortTypesParam, sizeof(OMX_PORT_PARAM_TYPE));
00535 break;
00536 case OMX_IndexParamVideoPortFormat:
00537 {
00538 OMX_VIDEO_PARAM_PORTFORMATTYPE *pVideoPortFormat;
00539 pVideoPortFormat = ComponentParameterStructure;
00540 if ((eError = checkHeader(ComponentParameterStructure, sizeof(OMX_VIDEO_PARAM_PORTFORMATTYPE))) != OMX_ErrorNone) {
00541 break;
00542 }
00543 if (pVideoPortFormat->nPortIndex <= 1) {
00544 port = (omx_base_video_PortType *)omx_videoenc_component_Private->ports[pVideoPortFormat->nPortIndex];
00545 memcpy(pVideoPortFormat, &port->sVideoParam, sizeof(OMX_VIDEO_PARAM_PORTFORMATTYPE));
00546 } else {
00547 return OMX_ErrorBadPortIndex;
00548 }
00549 break;
00550 }
00551 case OMX_IndexParamVideoMpeg4:
00552 {
00553 OMX_VIDEO_PARAM_MPEG4TYPE *pVideoMpeg4;
00554 pVideoMpeg4 = ComponentParameterStructure;
00555 if (pVideoMpeg4->nPortIndex != 1) {
00556 return OMX_ErrorBadPortIndex;
00557 }
00558 if ((eError = checkHeader(ComponentParameterStructure, sizeof(OMX_VIDEO_PARAM_MPEG4TYPE))) != OMX_ErrorNone) {
00559 break;
00560 }
00561 memcpy(pVideoMpeg4, &omx_videoenc_component_Private->pVideoMpeg4, sizeof(OMX_VIDEO_PARAM_MPEG4TYPE));
00562 break;
00563 }
00564 case OMX_IndexParamStandardComponentRole:
00565 {
00566 OMX_PARAM_COMPONENTROLETYPE * pComponentRole;
00567 pComponentRole = ComponentParameterStructure;
00568 if ((eError = checkHeader(ComponentParameterStructure, sizeof(OMX_PARAM_COMPONENTROLETYPE))) != OMX_ErrorNone) {
00569 break;
00570 }
00571 if (omx_videoenc_component_Private->video_encoding_type == OMX_VIDEO_CodingMPEG4) {
00572 strcpy((char *)pComponentRole->cRole, VIDEO_ENC_MPEG4_ROLE);
00573 } else {
00574 strcpy((char *)pComponentRole->cRole,"\0");
00575 }
00576 break;
00577 }
00578 default:
00579 return omx_base_component_GetParameter(hComponent, nParamIndex, ComponentParameterStructure);
00580 }
00581 return OMX_ErrorNone;
00582 }
00583
00584 OMX_ERRORTYPE omx_videoenc_component_MessageHandler(OMX_COMPONENTTYPE* openmaxStandComp,internalRequestMessageType *message) {
00585
00586 omx_videoenc_component_PrivateType* omx_videoenc_component_Private = openmaxStandComp->pComponentPrivate;
00587 OMX_ERRORTYPE eError;
00588
00589 DEBUG(DEB_LEV_SIMPLE_SEQ, "In %s\n", __func__);
00590
00591 if (message->messageType == OMX_CommandStateSet){
00592 if ((message->messageParam == OMX_StateIdle ) && (omx_videoenc_component_Private->state == OMX_StateLoaded)) {
00593 if (!omx_videoenc_component_Private->avcodecReady) {
00594 eError = omx_videoenc_component_ffmpegLibInit(omx_videoenc_component_Private);
00595 if (eError != OMX_ErrorNone) {
00596 return OMX_ErrorNotReady;
00597 }
00598 omx_videoenc_component_Private->avcodecReady = OMX_TRUE;
00599 }
00600 eError = omx_videoenc_component_Init(openmaxStandComp);
00601 if(eError!=OMX_ErrorNone) {
00602 DEBUG(DEB_LEV_ERR, "In %s Video Encoder Init Failed Error=%x\n",__func__,eError);
00603 return eError;
00604 }
00605 } else if ((message->messageParam == OMX_StateLoaded) && (omx_videoenc_component_Private->state == OMX_StateIdle)) {
00606 eError = omx_videoenc_component_Deinit(openmaxStandComp);
00607 if(eError!=OMX_ErrorNone) {
00608 DEBUG(DEB_LEV_ERR, "In %s Video Encoder Deinit Failed Error=%x\n",__func__,eError);
00609 return eError;
00610 }
00611 }
00612 }
00613
00614 return omx_base_component_MessageHandler(openmaxStandComp,message);
00615 }
00616
00617 OMX_ERRORTYPE omx_videoenc_component_ComponentRoleEnum(
00618 OMX_IN OMX_HANDLETYPE hComponent,
00619 OMX_OUT OMX_U8 *cRole,
00620 OMX_IN OMX_U32 nIndex) {
00621
00622 if (nIndex == 0) {
00623 strcpy((char *)cRole, VIDEO_ENC_MPEG4_ROLE);
00624 } else {
00625 return OMX_ErrorUnsupportedIndex;
00626 }
00627 return OMX_ErrorNone;
00628 }