00001
00031 #include "omxvideocapnplay.h"
00032
00034 #define COMPONENT_NAME_BASE "OMX.st.video_src"
00035 #define BASE_ROLE "video_src"
00036 #define COMPONENT_NAME_BASE_LEN 20
00037
00038 OMX_CALLBACKTYPE videosrccallbacks = { .EventHandler = videosrcEventHandler,
00039 .EmptyBufferDone = NULL,
00040 .FillBufferDone = videosrcFillBufferDone
00041 };
00042
00043 OMX_CALLBACKTYPE colorconv_callbacks = { .EventHandler = colorconvEventHandler,
00044 .EmptyBufferDone = colorconvEmptyBufferDone,
00045 .FillBufferDone = colorconvFillBufferDone
00046 };
00047
00048 OMX_CALLBACKTYPE fbdev_sink_callbacks = { .EventHandler = fb_sinkEventHandler,
00049 .EmptyBufferDone = fb_sinkEmptyBufferDone,
00050 .FillBufferDone = NULL
00051 };
00052
00053
00055 appPrivateType* appPriv;
00056
00057 OMX_COLOR_FORMATTYPE COLOR_CONV_OUT_RGB_FORMAT = OMX_COLOR_Format24bitRGB888;
00058
00060 OMX_BUFFERHEADERTYPE *pOutBuffer1, *pOutBuffer2;
00062 OMX_BUFFERHEADERTYPE *pInBufferColorConv1, *pInBufferColorConv2,*pOutBufferColorConv1, *pOutBufferColorConv2;
00063 OMX_BUFFERHEADERTYPE *pInBufferSink1, *pInBufferSink2;
00064
00065 int buffer_in_size = BUFFER_IN_SIZE;
00066 OMX_U32 buffer_out_size;
00067 OMX_U32 outbuf_colorconv_size;
00068
00069 OMX_PARAM_PORTDEFINITIONTYPE paramPort;
00070 OMX_PARAM_PORTDEFINITIONTYPE omx_colorconvPortDefinition;
00071 OMX_PARAM_COMPONENTROLETYPE paramRole;
00072 OMX_VIDEO_PARAM_PORTFORMATTYPE omxVideoParam;
00073 OMX_U32 out_width = 176;
00074 OMX_U32 out_height = 144;
00075
00076 char *output_file;
00077 FILE *outfile;
00078
00079 int flagIsOutputExpected;
00080 int flagDecodedOutputReceived;
00081 int flagIsColorConvRequested;
00082 int flagIsSinkRequested;
00083 int flagIsFormatRequested;
00084 int flagSetupTunnel;
00085
00086 static OMX_BOOL bEOS = OMX_FALSE;
00087
00088 static void setHeader(OMX_PTR header, OMX_U32 size) {
00089 OMX_VERSIONTYPE* ver = (OMX_VERSIONTYPE*)(header + sizeof(OMX_U32));
00090 *((OMX_U32*)header) = size;
00091
00092 ver->s.nVersionMajor = VERSIONMAJOR;
00093 ver->s.nVersionMinor = VERSIONMINOR;
00094 ver->s.nRevision = VERSIONREVISION;
00095 ver->s.nStep = VERSIONSTEP;
00096 }
00097
00098
00102 int setPortParameters() {
00103 OMX_ERRORTYPE err = OMX_ErrorNone;
00104
00105 paramPort.nPortIndex = 0;
00106 setHeader(¶mPort, sizeof(OMX_PARAM_PORTDEFINITIONTYPE));
00107 err = OMX_GetParameter(appPriv->videosrchandle, OMX_IndexParamPortDefinition, ¶mPort);
00108 paramPort.format.video.nFrameWidth = out_width;
00109 paramPort.format.video.nFrameHeight = out_height;
00110 err = OMX_SetParameter(appPriv->videosrchandle, OMX_IndexParamPortDefinition, ¶mPort);
00111 if(err!=OMX_ErrorNone) {
00112 DEBUG(DEB_LEV_ERR, "In %s Setting Input Port Definition Error=%x\n",__func__,err);
00113 return err;
00114 }
00115 DEBUG(DEB_LEV_SIMPLE_SEQ, "input picture width : %d height : %d \n", (int)out_width, (int)out_height);
00116
00120 if(flagIsColorConvRequested == 1) {
00124 omx_colorconvPortDefinition.nPortIndex = 0;
00125 setHeader(&omx_colorconvPortDefinition, sizeof(OMX_PARAM_PORTDEFINITIONTYPE));
00126 err = OMX_GetParameter(appPriv->colorconv_handle, OMX_IndexParamPortDefinition, &omx_colorconvPortDefinition);
00127 omx_colorconvPortDefinition.format.video.nFrameWidth = out_width;
00128 omx_colorconvPortDefinition.format.video.nFrameHeight = out_height;
00129 omx_colorconvPortDefinition.format.video.eColorFormat = OMX_COLOR_FormatYUV420Planar;
00130 err = OMX_SetParameter(appPriv->colorconv_handle, OMX_IndexParamPortDefinition, &omx_colorconvPortDefinition);
00131 if(err!=OMX_ErrorNone) {
00132 DEBUG(DEB_LEV_ERR, "In %s Setting Input Port Definition Error=%x\n",__func__,err);
00133 return err;
00134 }
00135
00136 omx_colorconvPortDefinition.nPortIndex = 0;
00137 err = OMX_GetParameter(appPriv->colorconv_handle, OMX_IndexParamPortDefinition, &omx_colorconvPortDefinition);
00138 DEBUG(DEFAULT_MESSAGES, "Color Conv I/p Buffer Size=%d\n", (int)omx_colorconvPortDefinition.nBufferSize);
00142 omx_colorconvPortDefinition.nPortIndex = 1;
00143 err = OMX_GetParameter(appPriv->colorconv_handle, OMX_IndexParamPortDefinition, &omx_colorconvPortDefinition);
00144 omx_colorconvPortDefinition.format.video.nFrameWidth = out_width;
00145 omx_colorconvPortDefinition.format.video.nFrameHeight = out_height;
00146 omx_colorconvPortDefinition.format.video.eColorFormat = COLOR_CONV_OUT_RGB_FORMAT;
00147 err = OMX_SetParameter(appPriv->colorconv_handle, OMX_IndexParamPortDefinition, &omx_colorconvPortDefinition);
00148 if(err!=OMX_ErrorNone) {
00149 DEBUG(DEB_LEV_ERR, "In %s Setting Output Port Definition Error=%x\n",__func__,err);
00150 return err;
00151 }
00155 omxVideoParam.nPortIndex = 0;
00156 setHeader(&omxVideoParam, sizeof(OMX_VIDEO_PARAM_PORTFORMATTYPE));
00157 err = OMX_GetParameter(appPriv->colorconv_handle, OMX_IndexParamVideoPortFormat, &omxVideoParam);
00158 omxVideoParam.eColorFormat = OMX_COLOR_FormatYUV420Planar;
00159 err = OMX_SetParameter(appPriv->colorconv_handle, OMX_IndexParamVideoPortFormat, &omxVideoParam);
00160 if(err==OMX_ErrorBadParameter) {
00161 DEBUG(DEB_LEV_ERR,"\n bad parameter of input color format - exiting\n");
00162 exit(1);
00163 }
00165 omxVideoParam.nPortIndex = 1;
00166 err = OMX_GetParameter(appPriv->colorconv_handle, OMX_IndexParamVideoPortFormat, &omxVideoParam);
00167 omxVideoParam.eColorFormat = COLOR_CONV_OUT_RGB_FORMAT;
00168 err = OMX_SetParameter(appPriv->colorconv_handle, OMX_IndexParamVideoPortFormat, &omxVideoParam);
00169 if(err==OMX_ErrorBadParameter) {
00170 DEBUG(DEB_LEV_ERR,"\n bad parameter of output color format setting- exiting\n");
00171 exit(1);
00172 }
00176 if(flagIsSinkRequested == 1) {
00177 omx_colorconvPortDefinition.nPortIndex = 1;
00178 err = OMX_GetParameter(appPriv->colorconv_handle, OMX_IndexParamPortDefinition, &omx_colorconvPortDefinition);
00179 omx_colorconvPortDefinition.nPortIndex = 0;
00180 err = OMX_SetParameter(appPriv->fbdev_sink_handle, OMX_IndexParamPortDefinition, &omx_colorconvPortDefinition);
00181 if(err != OMX_ErrorNone) {
00182 DEBUG(DEB_LEV_ERR,"\n error in setting the inputport param of the sink component- exiting\n");
00183 exit(1);
00184 }
00185 omxVideoParam.nPortIndex = 1;
00186 err = OMX_GetParameter(appPriv->colorconv_handle, OMX_IndexParamVideoPortFormat, &omxVideoParam);
00187 omxVideoParam.nPortIndex = 0;
00188 err = OMX_SetParameter(appPriv->fbdev_sink_handle, OMX_IndexParamVideoPortFormat, &omxVideoParam);
00189 if(err != OMX_ErrorNone) {
00190 DEBUG(DEB_LEV_ERR,"\n error in setting the input video param of the sink component- exiting\n");
00191 exit(1);
00192 }
00193 }
00194 }
00195
00196 return err;
00197 }
00198
00200 void display_help() {
00201 printf("\n");
00202 printf("Usage: omxvideocapnplay -o outputfile [-t] [-c] [-h] [-f input_fmt] [-s]\n");
00203 printf("\n");
00204 printf(" -o outfile: If this option is specified, the output is written to user specified outfile\n");
00205 printf(" If the color conv option (-c) is specified then outfile will be .rgb file\n");
00206 printf(" Else outfile will be in .yuv format \n");
00207 printf(" N.B : This option is not needed if you use the sink component\n");
00208 printf("\n");
00209 printf(" -c : Color conv option - input file is decoded and color converted in outfile(.rgb file)\n");
00210 printf(" -h: Displays this help\n");
00211 printf("\n");
00212 printf(" -f : input format specification in case of color conv comp usage \n");
00213 printf(" The available input formats are - \n");
00214 printf(" - OMX_COLOR_Format24bitRGB888 (default format) \n");
00215 printf(" - OMX_COLOR_Format24bitBGR888 \n");
00216 printf(" - OMX_COLOR_Format32bitBGRA8888 \n");
00217 printf(" - OMX_COLOR_Format32bitARGB8888 \n");
00218 printf(" - OMX_COLOR_Format16bitARGB1555 \n");
00219 printf(" - OMX_COLOR_Format16bitRGB565 \n");
00220 printf(" - OMX_COLOR_Format16bitBGR565 \n");
00221 printf("\n");
00222 printf(" -W 176: Width of the frame [default 176]\n");
00223 printf(" -H 144: Height of the frame [default 144]\n");
00224 printf(" -s: Uses the video sink component to display the output of the color converter(.rgb file)\n");
00225 printf("\n");
00226 printf(" -t: Tunneling option - if this option is selected then by default the color converter and \n");
00227 printf(" video sink components are selected even if those two options are not specified - \n");
00228 printf(" the components are tunneled between themselves\n");
00229 printf("\n");
00230 exit(1);
00231 }
00232
00233
00234 OMX_ERRORTYPE test_OMX_ComponentNameEnum() {
00235 char * name;
00236 int index;
00237
00238 OMX_ERRORTYPE err = OMX_ErrorNone;
00239
00240 DEBUG(DEFAULT_MESSAGES, "GENERAL TEST %s\n", __func__);
00241 name = malloc(OMX_MAX_STRINGNAME_SIZE);
00242 index = 0;
00243 while(1) {
00244 err = OMX_ComponentNameEnum (name, OMX_MAX_STRINGNAME_SIZE, index);
00245 if ((name != NULL) && (err == OMX_ErrorNone)) {
00246 DEBUG(DEFAULT_MESSAGES, "component %i is %s\n", index, name);
00247 } else break;
00248 if (err != OMX_ErrorNone) break;
00249 index++;
00250 }
00251 free(name);
00252 name = NULL;
00253 DEBUG(DEFAULT_MESSAGES, "GENERAL TEST %s result %i\n", __func__, err);
00254 return err;
00255 }
00256
00257 OMX_ERRORTYPE test_OMX_RoleEnum(OMX_STRING component_name) {
00258 OMX_U32 no_of_roles;
00259 OMX_U8 **string_of_roles;
00260 OMX_ERRORTYPE err = OMX_ErrorNone;
00261 int index;
00262
00263 DEBUG(DEFAULT_MESSAGES, "GENERAL TEST %s\n", __func__);
00264 DEBUG(DEB_LEV_SIMPLE_SEQ, "Getting roles of %s. Passing Null first...\n", component_name);
00265 err = OMX_GetRolesOfComponent(component_name, &no_of_roles, NULL);
00266 if (err != OMX_ErrorNone) {
00267 DEBUG(DEB_LEV_ERR, "Not able to retrieve the number of roles of the given component\n");
00268 DEBUG(DEFAULT_MESSAGES, "GENERAL TEST %s result %i\n", __func__, err);
00269 return err;
00270 }
00271 DEBUG(DEFAULT_MESSAGES, "The number of roles for the component %s is: %i\n", component_name, (int)no_of_roles);
00272
00273 if(no_of_roles == 0) {
00274 DEBUG(DEB_LEV_ERR, "The Number or roles is 0.\nThe component selected is not correct for the purpose of this test.\nExiting...\n");
00275 err = OMX_ErrorInvalidComponentName;
00276 } else {
00277 string_of_roles = malloc(no_of_roles * sizeof(OMX_STRING));
00278 for (index = 0; index < no_of_roles; index++) {
00279 *(string_of_roles + index) = malloc(no_of_roles * OMX_MAX_STRINGNAME_SIZE);
00280 }
00281 DEBUG(DEB_LEV_SIMPLE_SEQ, "...then buffers\n");
00282
00283 err = OMX_GetRolesOfComponent(component_name, &no_of_roles, string_of_roles);
00284 if (err != OMX_ErrorNone) {
00285 DEBUG(DEB_LEV_ERR, "Not able to retrieve the roles of the given component\n");
00286 } else if(string_of_roles != NULL) {
00287 for (index = 0; index < no_of_roles; index++) {
00288 DEBUG(DEFAULT_MESSAGES, "The role %i for the component: %s \n", (index + 1), *(string_of_roles+index));
00289 }
00290 } else {
00291 DEBUG(DEB_LEV_ERR, "role string is NULL!!! Exiting...\n");
00292 err = OMX_ErrorInvalidComponentName;
00293 }
00294 }
00295 DEBUG(DEFAULT_MESSAGES, "GENERAL TEST %s result %i\n", __func__, err);
00296 return err;
00297 }
00298
00299 OMX_ERRORTYPE test_OMX_ComponentEnumByRole(OMX_STRING role_name) {
00300 OMX_U32 no_of_comp_per_role;
00301 OMX_U8 **string_of_comp_per_role;
00302 OMX_ERRORTYPE err;
00303 int index;
00304
00305 DEBUG(DEFAULT_MESSAGES, "GENERAL TEST %s\n", __func__);
00306 string_of_comp_per_role = malloc (10 * sizeof(OMX_STRING));
00307 for (index = 0; index < 10; index++) {
00308 string_of_comp_per_role[index] = malloc(OMX_MAX_STRINGNAME_SIZE);
00309 }
00310
00311 DEBUG(DEFAULT_MESSAGES, "Getting number of components per role for %s\n", role_name);
00312
00313 err = OMX_GetComponentsOfRole(role_name, &no_of_comp_per_role, NULL);
00314 if (err != OMX_ErrorNone) {
00315 DEBUG(DEB_LEV_ERR, "Not able to retrieve the number of components of a given role\n");
00316 DEBUG(DEFAULT_MESSAGES, "GENERAL TEST %s result %i\n", __func__, err);
00317 return err;
00318 }
00319 DEBUG(DEFAULT_MESSAGES, "Number of components per role for %s is %i\n", role_name, (int)no_of_comp_per_role);
00320
00321 err = OMX_GetComponentsOfRole(role_name, &no_of_comp_per_role, string_of_comp_per_role);
00322 if (err != OMX_ErrorNone) {
00323 DEBUG(DEB_LEV_ERR, "Not able to retrieve the components of a given role\n");
00324 DEBUG(DEFAULT_MESSAGES, "GENERAL TEST %s result %i\n",__func__, err);
00325 return err;
00326 }
00327
00328 DEBUG(DEFAULT_MESSAGES, " The components are:\n");
00329 for (index = 0; index < no_of_comp_per_role; index++) {
00330 DEBUG(DEFAULT_MESSAGES, "%s\n", string_of_comp_per_role[index]);
00331 }
00332 for (index = 0; index<10; index++) {
00333 if(string_of_comp_per_role[index]) {
00334 free(string_of_comp_per_role[index]);
00335 string_of_comp_per_role[index] = NULL;
00336 }
00337 }
00338
00339 if(string_of_comp_per_role) {
00340 free(string_of_comp_per_role);
00341 string_of_comp_per_role = NULL;
00342 }
00343 DEBUG(DEFAULT_MESSAGES, "GENERAL TEST %s result OMX_ErrorNone\n", __func__);
00344 return OMX_ErrorNone;
00345 }
00346
00347 OMX_ERRORTYPE test_OpenClose(OMX_STRING component_name) {
00348 OMX_ERRORTYPE err = OMX_ErrorNone;
00349
00350 DEBUG(DEFAULT_MESSAGES, "GENERAL TEST %s\n",__func__);
00351 err = OMX_GetHandle(&appPriv->videosrchandle, component_name, NULL, &videosrccallbacks);
00352 if(err != OMX_ErrorNone) {
00353 DEBUG(DEB_LEV_ERR, "No component found\n");
00354 } else {
00355 err = OMX_FreeHandle(appPriv->videosrchandle);
00356 }
00357 DEBUG(DEFAULT_MESSAGES, "GENERAL TEST %s result %i\n", __func__, err);
00358 return err;
00359 }
00360
00361
00362 int main(int argc, char** argv) {
00363
00364 OMX_ERRORTYPE err;
00365 int argn_dec;
00366 OMX_STRING full_component_name;
00367 int isWidth=0,isHeight=0;
00368
00369 if(argc < 2){
00370 display_help();
00371 } else {
00372 flagIsOutputExpected = 0;
00373 flagDecodedOutputReceived = 0;
00374 flagIsColorConvRequested = 0;
00375 flagSetupTunnel = 0;
00376 flagIsSinkRequested = 0;
00377 flagIsFormatRequested = 0;
00378
00379 argn_dec = 1;
00380 while (argn_dec < argc) {
00381 if (*(argv[argn_dec]) == '-') {
00382 if (flagIsOutputExpected) {
00383 display_help();
00384 }
00385 switch (*(argv[argn_dec] + 1)) {
00386 case 'h' :
00387 display_help();
00388 break;
00389 case 't' :
00390 flagSetupTunnel = 1;
00391 flagIsSinkRequested = 1;
00392 flagIsColorConvRequested = 1;
00393 break;
00394 case 's':
00395 flagIsSinkRequested = 1;
00396 break;
00397 case 'o':
00398 flagIsOutputExpected = 1;
00399 break;
00400 case 'c':
00401 flagIsColorConvRequested = 1;
00402 break;
00403 case 'f' :
00404 flagIsFormatRequested = 1;
00405 break;
00406 case 'W' :
00407 isWidth = 1;
00408 break;
00409 case 'H' :
00410 isHeight = 1;
00411 break;
00412 default:
00413 display_help();
00414 }
00415 } else {
00416 if (flagIsOutputExpected) {
00417 if(strstr(argv[argn_dec], ".yuv") == NULL && strstr(argv[argn_dec], ".rgb") == NULL) {
00418 output_file = malloc(strlen(argv[argn_dec]) + 5);
00419 strcpy(output_file,argv[argn_dec]);
00420 strcat(output_file, ".yuv");
00421 } else {
00422 output_file = malloc(strlen(argv[argn_dec]) + 1);
00423 strcpy(output_file,argv[argn_dec]);
00424 }
00425 flagIsOutputExpected = 0;
00426 flagDecodedOutputReceived = 1;
00427 } else if(flagIsFormatRequested) {
00428 if(strstr(argv[argn_dec], "OMX_COLOR_Format24bitRGB888") != NULL) {
00429 COLOR_CONV_OUT_RGB_FORMAT = OMX_COLOR_Format24bitRGB888;
00430 } else if(strstr(argv[argn_dec], "OMX_COLOR_Format24bitBGR888") != NULL) {
00431 COLOR_CONV_OUT_RGB_FORMAT = OMX_COLOR_Format24bitBGR888;
00432 } else if(strstr(argv[argn_dec], "OMX_COLOR_Format32bitBGRA8888") != NULL) {
00433 COLOR_CONV_OUT_RGB_FORMAT = OMX_COLOR_Format32bitBGRA8888;
00434 } else if(strstr(argv[argn_dec], "OMX_COLOR_Format32bitARGB8888") != NULL) {
00435 COLOR_CONV_OUT_RGB_FORMAT = OMX_COLOR_Format32bitARGB8888;
00436 } else if(strstr(argv[argn_dec], "OMX_COLOR_Format16bitARGB1555") != NULL) {
00437 COLOR_CONV_OUT_RGB_FORMAT = OMX_COLOR_Format16bitARGB1555;
00438 } else if(strstr(argv[argn_dec], "OMX_COLOR_Format16bitRGB565") != NULL) {
00439 COLOR_CONV_OUT_RGB_FORMAT = OMX_COLOR_Format16bitRGB565;
00440 } else if(strstr(argv[argn_dec], "OMX_COLOR_Format16bitBGR565") != NULL) {
00441 COLOR_CONV_OUT_RGB_FORMAT = OMX_COLOR_Format16bitBGR565;
00442 } else {
00443 DEBUG(DEB_LEV_ERR, "\n specified color converter format is unknown - keeping default format\n");
00444 }
00445 flagIsFormatRequested = 0;
00446 } else if(isWidth) {
00447 out_width=atoi(argv[argn_dec]);
00448 isWidth=0;
00449 } else if(isHeight) {
00450 out_height=atoi(argv[argn_dec]);
00451 }
00452 }
00453 argn_dec++;
00454 }
00455
00457 if(!flagIsColorConvRequested && flagIsSinkRequested) {
00458 DEBUG(DEB_LEV_ERR, "You requested for sink - not producing any output file\n");
00459 flagIsColorConvRequested = 1;
00460 flagDecodedOutputReceived = 0;
00461 }
00462
00464
00465 if(!flagIsOutputExpected && !flagDecodedOutputReceived && !flagIsSinkRequested) {
00466 DEBUG(DEB_LEV_ERR,"\n you did not enter any output file name");
00467 output_file = malloc(20);
00468 if(flagIsColorConvRequested) {
00469 strcpy(output_file,"output.rgb");
00470 } else {
00471 strcpy(output_file,"output.yuv");
00472 }
00473 DEBUG(DEB_LEV_ERR,"\n the decoded output file name will be %s \n", output_file);
00474 } else if(flagDecodedOutputReceived) {
00475 if(flagIsSinkRequested || flagSetupTunnel) {
00476 flagDecodedOutputReceived = 0;
00477 DEBUG(DEB_LEV_ERR, "Sink Requested or Components are tunneled. No FILE Output will be produced\n");
00478 } else {
00479
00480 if(flagIsColorConvRequested && strstr(output_file, ".rgb") == NULL) {
00481 output_file[strlen(output_file) - strlen(strstr(output_file, "."))] = '\0';
00482 strcat(output_file, ".rgb");
00483 DEBUG(DEB_LEV_ERR,"\n color conv option is selected - so the output file is %s \n", output_file);
00484 }else if(!flagIsColorConvRequested && strstr(output_file, ".yuv") == NULL) {
00485 output_file[strlen(output_file) - strlen(strstr(output_file, "."))] = '\0';
00486 strcat(output_file, ".yuv");
00487 DEBUG(DEB_LEV_ERR,"\n color conv option is not selected - so the output file is %s \n", output_file);
00488 }
00489 }
00490 }
00491
00492 if(flagIsSinkRequested) {
00493 DEBUG(DEFAULT_MESSAGES, "The color converter output will be displayed in the video sink\n");
00494 }
00495 if(flagSetupTunnel) {
00496 DEBUG(DEFAULT_MESSAGES,"The components are tunneled between themselves\n");
00497 }
00498 }
00499
00500 if(!flagIsSinkRequested) {
00501 outfile = fopen(output_file, "wb");
00502 if(outfile == NULL) {
00503 DEBUG(DEB_LEV_ERR, "Error in opening output file %s\n", output_file);
00504 exit(1);
00505 }
00506 }
00507
00508
00509 appPriv = malloc(sizeof(appPrivateType));
00510 appPriv->sourceEventSem = malloc(sizeof(tsem_t));
00511 if(flagIsColorConvRequested == 1) {
00512 if(flagIsSinkRequested == 1) {
00513 appPriv->fbdevSinkEventSem = malloc(sizeof(tsem_t));
00514 }
00515 appPriv->colorconvEventSem = malloc(sizeof(tsem_t));
00516 }
00517 appPriv->eofSem = malloc(sizeof(tsem_t));
00518 tsem_init(appPriv->sourceEventSem, 0);
00519 if(flagIsColorConvRequested == 1) {
00520 if(flagIsSinkRequested == 1) {
00521 tsem_init(appPriv->fbdevSinkEventSem, 0);
00522 }
00523 tsem_init(appPriv->colorconvEventSem, 0);
00524 }
00525 tsem_init(appPriv->eofSem, 0);
00526
00527 DEBUG(DEB_LEV_SIMPLE_SEQ, "Init the OMX core\n");
00528 err = OMX_Init();
00529 if (err != OMX_ErrorNone) {
00530 DEBUG(DEB_LEV_ERR, "The OpenMAX core can not be initialized. Exiting...\n");
00531 exit(1);
00532 } else {
00533 DEBUG(DEB_LEV_SIMPLE_SEQ, "OMX core is initialized \n");
00534 }
00535
00536 DEBUG(DEFAULT_MESSAGES, "------------------------------------\n");
00537 test_OMX_ComponentNameEnum();
00538 DEBUG(DEFAULT_MESSAGES, "------------------------------------\n");
00539 test_OMX_RoleEnum(COMPONENT_NAME_BASE);
00540 DEBUG(DEFAULT_MESSAGES, "------------------------------------\n");
00541 test_OMX_ComponentEnumByRole(BASE_ROLE);
00542 DEBUG(DEFAULT_MESSAGES, "------------------------------------\n");
00543 test_OpenClose(COMPONENT_NAME_BASE);
00544 DEBUG(DEFAULT_MESSAGES, "------------------------------------\n");
00545
00546
00547 full_component_name = malloc(OMX_MAX_STRINGNAME_SIZE);
00548 strcpy(full_component_name, "OMX.st.video_src");
00549
00550 DEBUG(DEFAULT_MESSAGES, "The component selected for decoding is %s\n", full_component_name);
00551
00553 err = OMX_GetHandle(&appPriv->videosrchandle, full_component_name, NULL, &videosrccallbacks);
00554 if(err != OMX_ErrorNone){
00555 DEBUG(DEB_LEV_ERR, "No video source component found. Exiting...\n");
00556 exit(1);
00557 } else {
00558 DEBUG(DEFAULT_MESSAGES, "Found The component for capturing is %s\n", full_component_name);
00559 }
00560
00562 if(flagIsColorConvRequested == 1) {
00563 err = OMX_GetHandle(&appPriv->colorconv_handle, "OMX.st.video_colorconv.ffmpeg", NULL, &colorconv_callbacks);
00564 if(err != OMX_ErrorNone){
00565 DEBUG(DEB_LEV_ERR, "No color converter component found. Exiting...\n");
00566 exit(1);
00567 } else {
00568 DEBUG(DEFAULT_MESSAGES, "Found The component for color converter \n");
00569 }
00570
00572 if(flagIsSinkRequested == 1) {
00573 err = OMX_GetHandle(&appPriv->fbdev_sink_handle, "OMX.st.fbdev.fbdev_sink", NULL, &fbdev_sink_callbacks);
00574 if(err != OMX_ErrorNone){
00575 DEBUG(DEB_LEV_ERR, "No video sink component component found. Exiting...\n");
00576 exit(1);
00577 } else {
00578 DEBUG(DEFAULT_MESSAGES, "Found The video sink component for color converter \n");
00579 }
00580 }
00581 }
00582
00584 buffer_out_size = out_width * out_height * 3/2;
00585 DEBUG(DEB_LEV_SIMPLE_SEQ, "\n buffer_out_size : %d \n", (int)buffer_out_size);
00586
00588 if (flagSetupTunnel) {
00589 DEBUG(DEB_LEV_SIMPLE_SEQ, "Setting up Tunnel\n");
00590 err = OMX_SetupTunnel(appPriv->videosrchandle, 0, appPriv->colorconv_handle, 0);
00591 if(err != OMX_ErrorNone) {
00592 DEBUG(DEB_LEV_ERR, "Set up Tunnel between video dec & color conv Failed\n");
00593 exit(1);
00594 }
00595 err = OMX_SetupTunnel(appPriv->colorconv_handle, 1, appPriv->fbdev_sink_handle, 0);
00596 if(err != OMX_ErrorNone) {
00597 DEBUG(DEB_LEV_ERR, "Set up Tunnel between color conv & video sink Failed\n");
00598 exit(1);
00599 }
00600 DEBUG(DEFAULT_MESSAGES, "Set up Tunnel Completed\n");
00601 }
00602
00603 setPortParameters();
00604
00606 err = OMX_SendCommand(appPriv->videosrchandle, OMX_CommandStateSet, OMX_StateIdle, NULL);
00607
00609 if(flagIsColorConvRequested && flagSetupTunnel) {
00610 err = OMX_SendCommand(appPriv->colorconv_handle, OMX_CommandStateSet, OMX_StateIdle, NULL);
00611 if(flagIsSinkRequested && flagSetupTunnel) {
00612 err = OMX_SendCommand(appPriv->fbdev_sink_handle, OMX_CommandStateSet, OMX_StateIdle, NULL);
00613 }
00614 }
00615
00616 if(flagSetupTunnel) {
00617 if(flagIsSinkRequested) {
00618 tsem_down(appPriv->fbdevSinkEventSem);
00619 }
00620 if(flagIsColorConvRequested) {
00621 tsem_down(appPriv->colorconvEventSem);
00622 }
00623 }
00624
00626 if (!flagSetupTunnel) {
00627 pOutBuffer1 = pOutBuffer2 = NULL;
00628 err = OMX_AllocateBuffer(appPriv->videosrchandle, &pOutBuffer1, 0, NULL, buffer_out_size);
00629 err = OMX_AllocateBuffer(appPriv->videosrchandle, &pOutBuffer2, 0, NULL, buffer_out_size);
00630 }
00631
00632 DEBUG(DEB_LEV_SIMPLE_SEQ, "Before locking on idle wait semaphore\n");
00633 tsem_down(appPriv->sourceEventSem);
00634 DEBUG(DEB_LEV_SIMPLE_SEQ, "source Sem free\n");
00635
00636 if(!flagSetupTunnel) {
00637 if(flagIsColorConvRequested == 1) {
00638 pOutBufferColorConv1 = pOutBufferColorConv2 = NULL;
00639 err = OMX_SendCommand(appPriv->colorconv_handle, OMX_CommandStateSet, OMX_StateIdle, NULL);
00640
00641 omx_colorconvPortDefinition.nPortIndex = 0;
00642 setHeader(&omx_colorconvPortDefinition, sizeof(OMX_PARAM_PORTDEFINITIONTYPE));
00643 err = OMX_GetParameter(appPriv->colorconv_handle, OMX_IndexParamPortDefinition, &omx_colorconvPortDefinition);
00644 outbuf_colorconv_size = omx_colorconvPortDefinition.nBufferSize;
00645
00647 err = OMX_UseBuffer(appPriv->colorconv_handle, &pInBufferColorConv1, 0, NULL, outbuf_colorconv_size, pOutBuffer1->pBuffer);
00648 if(err != OMX_ErrorNone) {
00649 DEBUG(DEB_LEV_ERR, "Unable to use the color conv comp allocate buffer\n");
00650 exit(1);
00651 }
00652 err = OMX_UseBuffer(appPriv->colorconv_handle, &pInBufferColorConv2, 0, NULL, outbuf_colorconv_size, pOutBuffer2->pBuffer);
00653 if(err != OMX_ErrorNone) {
00654 DEBUG(DEB_LEV_ERR, "Unable to use the color conv comp allocate buffer\n");
00655 exit(1);
00656 }
00657
00660 DEBUG(DEB_LEV_SIMPLE_SEQ, " outbuf_colorconv_size : %d \n", (int)outbuf_colorconv_size);
00661 omx_colorconvPortDefinition.nPortIndex = 1;
00662 setHeader(&omx_colorconvPortDefinition, sizeof(OMX_PARAM_PORTDEFINITIONTYPE));
00663 err = OMX_GetParameter(appPriv->colorconv_handle, OMX_IndexParamPortDefinition, &omx_colorconvPortDefinition);
00664 outbuf_colorconv_size = omx_colorconvPortDefinition.nBufferSize;
00665
00666 err = OMX_AllocateBuffer(appPriv->colorconv_handle, &pOutBufferColorConv1, 1, NULL, outbuf_colorconv_size);
00667 if(err != OMX_ErrorNone) {
00668 DEBUG(DEB_LEV_ERR, "Unable to allocate buffer in color conv\n");
00669 exit(1);
00670 }
00671 err = OMX_AllocateBuffer(appPriv->colorconv_handle, &pOutBufferColorConv2, 1, NULL, outbuf_colorconv_size);
00672 if(err != OMX_ErrorNone) {
00673 DEBUG(DEB_LEV_ERR, "Unable to allocate buffer in colro conv\n");
00674 exit(1);
00675 }
00676
00677 DEBUG(DEB_LEV_SIMPLE_SEQ, "Before locking on idle wait semaphore\n");
00678 tsem_down(appPriv->colorconvEventSem);
00679 DEBUG(DEB_LEV_SIMPLE_SEQ, "color conv Sem free\n");
00680
00681 if(flagIsSinkRequested == 1) {
00682 err = OMX_SendCommand(appPriv->fbdev_sink_handle, OMX_CommandStateSet, OMX_StateIdle, NULL);
00683 err = OMX_UseBuffer(appPriv->fbdev_sink_handle, &pInBufferSink1, 0, NULL, outbuf_colorconv_size, pOutBufferColorConv1->pBuffer);
00684 if(err != OMX_ErrorNone) {
00685 DEBUG(DEB_LEV_ERR, "Unable to use the color conv comp allocate buffer\n");
00686 exit(1);
00687 }
00688 err = OMX_UseBuffer(appPriv->fbdev_sink_handle, &pInBufferSink2, 0, NULL, outbuf_colorconv_size, pOutBufferColorConv2->pBuffer);
00689 if(err != OMX_ErrorNone) {
00690 DEBUG(DEB_LEV_ERR, "Unable to use the color conv comp allocate buffer\n");
00691 exit(1);
00692 }
00693
00694 DEBUG(DEB_LEV_SIMPLE_SEQ, "Before locking on idle wait semaphore\n");
00695 tsem_down(appPriv->fbdevSinkEventSem);
00696 DEBUG(DEB_LEV_SIMPLE_SEQ, "video sink comp Sem free\n");
00697 }
00698 }
00699
00700 if(flagIsColorConvRequested == 1) {
00701 err = OMX_SendCommand(appPriv->colorconv_handle, OMX_CommandStateSet, OMX_StateExecuting, NULL);
00702 tsem_down(appPriv->colorconvEventSem);
00703 if(flagIsSinkRequested == 1) {
00704 err = OMX_SendCommand(appPriv->fbdev_sink_handle, OMX_CommandStateSet, OMX_StateExecuting, NULL);
00705 tsem_down(appPriv->fbdevSinkEventSem);
00706 }
00707 }
00708 }
00709
00711 if(flagIsColorConvRequested == 1 && flagSetupTunnel) {
00712 err = OMX_SendCommand(appPriv->colorconv_handle, OMX_CommandStateSet, OMX_StateExecuting, NULL);
00713 tsem_down(appPriv->colorconvEventSem);
00714 if(flagIsSinkRequested == 1) {
00715 err = OMX_SendCommand(appPriv->fbdev_sink_handle, OMX_CommandStateSet, OMX_StateExecuting, NULL);
00716 tsem_down(appPriv->fbdevSinkEventSem);
00717 }
00718 }
00719
00721 err = OMX_SendCommand(appPriv->videosrchandle, OMX_CommandStateSet, OMX_StateExecuting, NULL);
00722 tsem_down(appPriv->sourceEventSem);
00723
00724 if(flagIsColorConvRequested == 1 && !flagSetupTunnel) {
00725 err = OMX_FillThisBuffer(appPriv->colorconv_handle, pOutBufferColorConv1);
00726 err = OMX_FillThisBuffer(appPriv->colorconv_handle, pOutBufferColorConv2);
00727 DEBUG(DEB_LEV_SIMPLE_SEQ, "---> After fill this buffer function calls to the color conv output buffers\n");
00728 }
00729 if (!flagSetupTunnel) {
00730 err = OMX_FillThisBuffer(appPriv->videosrchandle, pOutBuffer1);
00731 err = OMX_FillThisBuffer(appPriv->videosrchandle, pOutBuffer2);
00732 }
00733
00734 DEBUG(DEB_LEV_SIMPLE_SEQ, "---> Before locking on condition and sourceMutex\n");
00735
00736 DEBUG(DEFAULT_MESSAGES,"Enter 'q' or 'Q' to exit\n");
00737
00738 while(1) {
00739 if('Q' == toupper(getchar())) {
00740 DEBUG(DEFAULT_MESSAGES,"Stoping capture\n");
00741 bEOS = OMX_TRUE;
00742 break;
00743 }
00744 }
00745
00746 DEBUG(DEFAULT_MESSAGES, "The execution of the video decoding process is terminated\n");
00747
00749 err = OMX_SendCommand(appPriv->videosrchandle, OMX_CommandStateSet, OMX_StateIdle, NULL);
00750 if(flagIsColorConvRequested == 1) {
00751 err = OMX_SendCommand(appPriv->colorconv_handle, OMX_CommandStateSet, OMX_StateIdle, NULL);
00752 if(flagIsSinkRequested == 1) {
00753 err = OMX_SendCommand(appPriv->fbdev_sink_handle, OMX_CommandStateSet, OMX_StateIdle, NULL);
00754 }
00755 }
00756
00757 tsem_down(appPriv->sourceEventSem);
00758 if(flagIsColorConvRequested == 1) {
00759 tsem_down(appPriv->colorconvEventSem);
00760 if(flagIsSinkRequested == 1) {
00761 tsem_down(appPriv->fbdevSinkEventSem);
00762 }
00763 }
00764
00765 DEBUG(DEFAULT_MESSAGES, "All video components Transitioned to Idle\n");
00766
00768 err = OMX_SendCommand(appPriv->videosrchandle, OMX_CommandStateSet, OMX_StateLoaded, NULL);
00769 if(flagIsColorConvRequested == 1) {
00770 err = OMX_SendCommand(appPriv->colorconv_handle, OMX_CommandStateSet, OMX_StateLoaded, NULL);
00771 if(flagIsSinkRequested == 1) {
00772 err = OMX_SendCommand(appPriv->fbdev_sink_handle, OMX_CommandStateSet, OMX_StateLoaded, NULL);
00773 }
00774 }
00775
00777 if(flagIsColorConvRequested == 1 && !flagSetupTunnel) {
00778 if(flagIsSinkRequested == 1 && !flagSetupTunnel) {
00779 DEBUG(DEB_LEV_SIMPLE_SEQ, "Video sink to loaded\n");
00780 err = OMX_FreeBuffer(appPriv->fbdev_sink_handle, 0, pInBufferSink1);
00781 err = OMX_FreeBuffer(appPriv->fbdev_sink_handle, 0, pInBufferSink2);
00782 }
00783 DEBUG(DEB_LEV_SIMPLE_SEQ, "Color conv to loaded\n");
00784 err = OMX_FreeBuffer(appPriv->colorconv_handle, 0, pInBufferColorConv1);
00785 err = OMX_FreeBuffer(appPriv->colorconv_handle, 0, pInBufferColorConv2);
00786
00787 err = OMX_FreeBuffer(appPriv->colorconv_handle, 1, pOutBufferColorConv1);
00788 err = OMX_FreeBuffer(appPriv->colorconv_handle, 1, pOutBufferColorConv2);
00789 }
00790
00792 DEBUG(DEB_LEV_SIMPLE_SEQ, "Video dec to loaded\n");
00793 if(!flagSetupTunnel) {
00794 DEBUG(DEB_LEV_PARAMS, "Free Video dec output ports\n");
00795 err = OMX_FreeBuffer(appPriv->videosrchandle, 0, pOutBuffer1);
00796 err = OMX_FreeBuffer(appPriv->videosrchandle, 0, pOutBuffer2);
00797 }
00798
00799 if(flagIsColorConvRequested == 1) {
00800 if(flagIsSinkRequested == 1) {
00801 tsem_down(appPriv->fbdevSinkEventSem);
00802 }
00803 tsem_down(appPriv->colorconvEventSem);
00804 }
00805 tsem_down(appPriv->sourceEventSem);
00806 DEBUG(DEB_LEV_SIMPLE_SEQ, "All components released\n");
00807
00808 OMX_FreeHandle(appPriv->videosrchandle);
00809 if(flagIsColorConvRequested == 1) {
00810 if(flagIsSinkRequested == 1) {
00811 OMX_FreeHandle(appPriv->fbdev_sink_handle);
00812 }
00813 OMX_FreeHandle(appPriv->colorconv_handle);
00814 }
00815 DEBUG(DEB_LEV_SIMPLE_SEQ, "video dec freed\n");
00816
00817 OMX_Deinit();
00818
00819 DEBUG(DEFAULT_MESSAGES, "All components freed. Closing...\n");
00820 free(appPriv->sourceEventSem);
00821 if(flagIsColorConvRequested == 1) {
00822 if(flagIsSinkRequested == 1) {
00823 free(appPriv->fbdevSinkEventSem);
00824 }
00825 free(appPriv->colorconvEventSem);
00826 }
00827 free(appPriv->eofSem);
00828 free(appPriv);
00829
00830 free(full_component_name);
00831
00833 if(!flagIsSinkRequested) {
00834 fclose(outfile);
00835 }
00836 if(output_file) {
00837 free(output_file);
00838 }
00839
00840 return 0;
00841 }
00842
00843
00845 OMX_ERRORTYPE fb_sinkEventHandler(
00846 OMX_OUT OMX_HANDLETYPE hComponent,
00847 OMX_OUT OMX_PTR pAppData,
00848 OMX_OUT OMX_EVENTTYPE eEvent,
00849 OMX_OUT OMX_U32 Data1,
00850 OMX_OUT OMX_U32 Data2,
00851 OMX_OUT OMX_PTR pEventData) {
00852
00853 DEBUG(DEB_LEV_SIMPLE_SEQ, "Hi there, I am in the %s callback\n", __func__);
00854 if(eEvent == OMX_EventCmdComplete) {
00855 if (Data1 == OMX_CommandStateSet) {
00856 DEBUG(DEB_LEV_SIMPLE_SEQ, "State changed in ");
00857 switch ((int)Data2) {
00858 case OMX_StateInvalid:
00859 DEBUG(DEB_LEV_SIMPLE_SEQ, "OMX_StateInvalid\n");
00860 break;
00861 case OMX_StateLoaded:
00862 DEBUG(DEB_LEV_SIMPLE_SEQ, "OMX_StateLoaded\n");
00863 break;
00864 case OMX_StateIdle:
00865 DEBUG(DEB_LEV_SIMPLE_SEQ, "OMX_StateIdle ---- fbsink\n");
00866 break;
00867 case OMX_StateExecuting:
00868 DEBUG(DEB_LEV_SIMPLE_SEQ, "OMX_StateExecuting\n");
00869 break;
00870 case OMX_StatePause:
00871 DEBUG(DEB_LEV_SIMPLE_SEQ, "OMX_StatePause\n");
00872 break;
00873 case OMX_StateWaitForResources:
00874 DEBUG(DEB_LEV_SIMPLE_SEQ, "OMX_StateWaitForResources\n");
00875 break;
00876 }
00877 tsem_up(appPriv->fbdevSinkEventSem);
00878 }
00879 else if (OMX_CommandPortEnable || OMX_CommandPortDisable) {
00880 DEBUG(DEB_LEV_SIMPLE_SEQ, "In %s Received Port Enable/Disable Event\n",__func__);
00881 tsem_up(appPriv->fbdevSinkEventSem);
00882 }
00883 } else if(eEvent == OMX_EventBufferFlag) {
00884 DEBUG(DEB_LEV_ERR, "In %s OMX_BUFFERFLAG_EOS\n", __func__);
00885 if((int)Data2 == OMX_BUFFERFLAG_EOS) {
00886 tsem_up(appPriv->eofSem);
00887 }
00888 } else {
00889 DEBUG(DEB_LEV_SIMPLE_SEQ, "Param1 is %i\n", (int)Data1);
00890 DEBUG(DEB_LEV_SIMPLE_SEQ, "Param2 is %i\n", (int)Data2);
00891 }
00892 return OMX_ErrorNone;
00893 }
00894
00895
00896 OMX_ERRORTYPE fb_sinkEmptyBufferDone(
00897 OMX_OUT OMX_HANDLETYPE hComponent,
00898 OMX_OUT OMX_PTR pAppData,
00899 OMX_OUT OMX_BUFFERHEADERTYPE* pBuffer) {
00900
00901 OMX_ERRORTYPE err;
00902 static int inputBufferDropped = 0;
00903 if(pBuffer != NULL) {
00904 if(!bEOS) {
00905 if(pOutBufferColorConv1->pBuffer == pBuffer->pBuffer) {
00906 pOutBufferColorConv1->nFilledLen = pBuffer->nFilledLen;
00907 err = OMX_FillThisBuffer(appPriv->colorconv_handle, pOutBufferColorConv1);
00908 } else {
00909 pOutBufferColorConv2->nFilledLen = pBuffer->nFilledLen;
00910 err = OMX_FillThisBuffer(appPriv->colorconv_handle, pOutBufferColorConv2);
00911 }
00912 if(err != OMX_ErrorNone) {
00913 DEBUG(DEB_LEV_ERR, "In %s Error %08x Calling FillThisBuffer\n", __func__,err);
00914 }
00915 } else {
00916 DEBUG(DEB_LEV_ERR, "In %s: eos=%x Dropping Fill This Buffer\n", __func__,(int)pBuffer->nFlags);
00917 inputBufferDropped++;
00918 if(inputBufferDropped == 2) {
00919 tsem_up(appPriv->eofSem);
00920 }
00921 }
00922 } else {
00923 if(!bEOS) {
00924 tsem_up(appPriv->eofSem);
00925 }
00926 DEBUG(DEB_LEV_ERR, "Ouch! In %s: had NULL buffer to output...\n", __func__);
00927 }
00928 return OMX_ErrorNone;
00929 }
00930
00931
00932
00933 OMX_ERRORTYPE colorconvEventHandler(
00934 OMX_OUT OMX_HANDLETYPE hComponent,
00935 OMX_OUT OMX_PTR pAppData,
00936 OMX_OUT OMX_EVENTTYPE eEvent,
00937 OMX_OUT OMX_U32 Data1,
00938 OMX_OUT OMX_U32 Data2,
00939 OMX_OUT OMX_PTR pEventData) {
00940
00941 DEBUG(DEB_LEV_SIMPLE_SEQ, "\nHi there, I am in the %s callback\n", __func__);
00942 if(eEvent == OMX_EventCmdComplete) {
00943 if (Data1 == OMX_CommandStateSet) {
00944 DEBUG(DEB_LEV_SIMPLE_SEQ, "\nState changed in ");
00945 switch ((int)Data2) {
00946 case OMX_StateInvalid:
00947 DEBUG(DEB_LEV_SIMPLE_SEQ, "OMX_StateInvalid\n");
00948 break;
00949 case OMX_StateLoaded:
00950 DEBUG(DEB_LEV_SIMPLE_SEQ, "OMX_StateLoaded\n");
00951 break;
00952 case OMX_StateIdle:
00953 DEBUG(DEB_LEV_SIMPLE_SEQ, "OMX_StateIdle\n");
00954 break;
00955 case OMX_StateExecuting:
00956 DEBUG(DEB_LEV_SIMPLE_SEQ, "OMX_StateExecuting\n");
00957 break;
00958 case OMX_StatePause:
00959 DEBUG(DEB_LEV_SIMPLE_SEQ, "OMX_StatePause\n");
00960 break;
00961 case OMX_StateWaitForResources:
00962 DEBUG(DEB_LEV_SIMPLE_SEQ, "OMX_StateWaitForResources\n");
00963 break;
00964 }
00965 tsem_up(appPriv->colorconvEventSem);
00966 }
00967 else if (OMX_CommandPortEnable || OMX_CommandPortDisable) {
00968 DEBUG(DEB_LEV_SIMPLE_SEQ, "In %s Received Port Enable/Disable Event\n",__func__);
00969 tsem_up(appPriv->colorconvEventSem);
00970 }
00971 } else if(eEvent == OMX_EventBufferFlag) {
00972 DEBUG(DEB_LEV_ERR, "In %s OMX_BUFFERFLAG_EOS\n", __func__);
00973 if((int)Data2 == OMX_BUFFERFLAG_EOS) {
00974 tsem_up(appPriv->eofSem);
00975 }
00976 } else {
00977 DEBUG(DEB_LEV_SIMPLE_SEQ, "Param1 is %i\n", (int)Data1);
00978 DEBUG(DEB_LEV_SIMPLE_SEQ, "Param2 is %i\n", (int)Data2);
00979 }
00980 return OMX_ErrorNone;
00981 }
00982
00983
00984 OMX_ERRORTYPE colorconvEmptyBufferDone(
00985 OMX_OUT OMX_HANDLETYPE hComponent,
00986 OMX_OUT OMX_PTR pAppData,
00987 OMX_OUT OMX_BUFFERHEADERTYPE* pBuffer) {
00988
00989 OMX_ERRORTYPE err;
00990 static int iBufferDropped = 0;
00991
00992 if(pBuffer != NULL) {
00993 if(!bEOS) {
00994 if(pOutBuffer1->pBuffer == pBuffer->pBuffer) {
00995 pOutBuffer1->nFilledLen = pBuffer->nFilledLen;
00996 err = OMX_FillThisBuffer(appPriv->videosrchandle, pOutBuffer1);
00997 } else {
00998 pOutBuffer2->nFilledLen = pBuffer->nFilledLen;
00999 err = OMX_FillThisBuffer(appPriv->videosrchandle, pOutBuffer2);
01000 }
01001 if(err != OMX_ErrorNone) {
01002 DEBUG(DEB_LEV_ERR, "In %s Error %08x Calling FillThisBuffer\n", __func__,err);
01003 }
01004 } else {
01005 DEBUG(DEB_LEV_ERR, "In %s: eos=%x Dropping Fill This Buffer\n", __func__,(int)pBuffer->nFlags);
01006 iBufferDropped++;
01007 if(iBufferDropped == 2) {
01008 tsem_up(appPriv->eofSem);
01009 }
01010 }
01011 } else {
01012 if(!bEOS) {
01013 tsem_up(appPriv->eofSem);
01014 }
01015 DEBUG(DEB_LEV_ERR, "Ouch! In %s: had NULL buffer to output...\n", __func__);
01016 }
01017 return OMX_ErrorNone;
01018 }
01019
01020
01021 OMX_ERRORTYPE colorconvFillBufferDone(
01022 OMX_OUT OMX_HANDLETYPE hComponent,
01023 OMX_OUT OMX_PTR pAppData,
01024 OMX_OUT OMX_BUFFERHEADERTYPE* pBuffer) {
01025
01026 OMX_ERRORTYPE err;
01027 if(pBuffer != NULL) {
01028 if(!bEOS) {
01032 if(flagIsSinkRequested && (!flagSetupTunnel)) {
01033
01034 if(pInBufferSink1->pBuffer == pBuffer->pBuffer) {
01035 pInBufferSink1->nFilledLen = pBuffer->nFilledLen;
01036 err = OMX_EmptyThisBuffer(appPriv->fbdev_sink_handle, pInBufferSink1);
01037 } else {
01038 pInBufferSink2->nFilledLen = pBuffer->nFilledLen;
01039 err = OMX_EmptyThisBuffer(appPriv->fbdev_sink_handle, pInBufferSink2);
01040 }
01041 if(err != OMX_ErrorNone) {
01042 DEBUG(DEB_LEV_ERR, "In %s Error %08x Calling FillThisBuffer\n", __func__,err);
01043 }
01044 } else if((pBuffer->nFilledLen > 0) && (!flagSetupTunnel)) {
01045 fwrite(pBuffer->pBuffer, 1, pBuffer->nFilledLen, outfile);
01046 pBuffer->nFilledLen = 0;
01047 }
01048 if(pBuffer->nFlags == OMX_BUFFERFLAG_EOS) {
01049 DEBUG(DEB_LEV_ERR, "In %s: eos=%x Calling Empty This Buffer\n", __func__, (int)pBuffer->nFlags);
01050 bEOS = OMX_TRUE;
01051 }
01052 if(!bEOS && !flagIsSinkRequested && (!flagSetupTunnel)) {
01053 err = OMX_FillThisBuffer(hComponent, pBuffer);
01054 }
01055 } else {
01056 DEBUG(DEB_LEV_ERR, "In %s: eos=%x Dropping Empty This Buffer\n", __func__,(int)pBuffer->nFlags);
01057 }
01058 } else {
01059 DEBUG(DEB_LEV_ERR, "Ouch! In %s: had NULL buffer to output...\n", __func__);
01060 }
01061 return OMX_ErrorNone;
01062 }
01063
01065 OMX_ERRORTYPE videosrcEventHandler(
01066 OMX_OUT OMX_HANDLETYPE hComponent,
01067 OMX_OUT OMX_PTR pAppData,
01068 OMX_OUT OMX_EVENTTYPE eEvent,
01069 OMX_OUT OMX_U32 Data1,
01070 OMX_OUT OMX_U32 Data2,
01071 OMX_OUT OMX_PTR pEventData) {
01072
01073 OMX_ERRORTYPE err = OMX_ErrorNone;
01074
01075 DEBUG(DEB_LEV_SIMPLE_SEQ, "Hi there, I am in the %s callback\n", __func__);
01076 if(eEvent == OMX_EventCmdComplete) {
01077 if (Data1 == OMX_CommandStateSet) {
01078 DEBUG(DEB_LEV_SIMPLE_SEQ, "State changed in ");
01079 switch ((int)Data2) {
01080 case OMX_StateInvalid:
01081 DEBUG(DEB_LEV_SIMPLE_SEQ, "OMX_StateInvalid\n");
01082 break;
01083 case OMX_StateLoaded:
01084 DEBUG(DEB_LEV_SIMPLE_SEQ, "OMX_StateLoaded\n");
01085 break;
01086 case OMX_StateIdle:
01087 DEBUG(DEB_LEV_SIMPLE_SEQ, "OMX_StateIdle\n");
01088 break;
01089 case OMX_StateExecuting:
01090 DEBUG(DEB_LEV_SIMPLE_SEQ, "OMX_StateExecuting\n");
01091 break;
01092 case OMX_StatePause:
01093 DEBUG(DEB_LEV_SIMPLE_SEQ, "OMX_StatePause\n");
01094 break;
01095 case OMX_StateWaitForResources:
01096 DEBUG(DEB_LEV_SIMPLE_SEQ, "OMX_StateWaitForResources\n");
01097 break;
01098 }
01099 tsem_up(appPriv->sourceEventSem);
01100 }
01101 else if (OMX_CommandPortEnable || OMX_CommandPortDisable) {
01102 DEBUG(DEB_LEV_SIMPLE_SEQ, "In %s Received Port Enable/Disable Event\n",__func__);
01103 tsem_up(appPriv->sourceEventSem);
01104 }
01105 } else if(eEvent == OMX_EventPortSettingsChanged) {
01106 DEBUG(DEB_LEV_SIMPLE_SEQ, "\n port settings change event handler in %s \n", __func__);
01107 } else if(eEvent == OMX_EventBufferFlag) {
01108 DEBUG(DEB_LEV_ERR, "In %s OMX_BUFFERFLAG_EOS\n", __func__);
01109 if((int)Data2 == OMX_BUFFERFLAG_EOS) {
01110 tsem_up(appPriv->eofSem);
01111 }
01112 } else {
01113 DEBUG(DEB_LEV_SIMPLE_SEQ, "Param1 is %i\n", (int)Data1);
01114 DEBUG(DEB_LEV_SIMPLE_SEQ, "Param2 is %i\n", (int)Data2);
01115 }
01116 return err;
01117 }
01118
01119 OMX_ERRORTYPE videosrcFillBufferDone(
01120 OMX_OUT OMX_HANDLETYPE hComponent,
01121 OMX_OUT OMX_PTR pAppData,
01122 OMX_OUT OMX_BUFFERHEADERTYPE* pBuffer) {
01123
01124 OMX_ERRORTYPE err;
01125 OMX_STATETYPE eState;
01126
01127 if(pBuffer != NULL){
01128 if(!bEOS) {
01132 if(flagIsColorConvRequested && (!flagSetupTunnel)) {
01133 OMX_GetState(appPriv->colorconv_handle,&eState);
01134 if(eState == OMX_StateExecuting || eState == OMX_StatePause) {
01135 if(pInBufferColorConv1->pBuffer == pBuffer->pBuffer) {
01136 pInBufferColorConv1->nFilledLen = pBuffer->nFilledLen;
01137 err = OMX_EmptyThisBuffer(appPriv->colorconv_handle, pInBufferColorConv1);
01138 } else {
01139 pInBufferColorConv2->nFilledLen = pBuffer->nFilledLen;
01140 err = OMX_EmptyThisBuffer(appPriv->colorconv_handle, pInBufferColorConv2);
01141 }
01142 if(err != OMX_ErrorNone) {
01143 DEBUG(DEB_LEV_ERR, "In %s Error %08x Calling FillThisBuffer\n", __func__,err);
01144 }
01145 } else {
01146 err = OMX_FillThisBuffer(hComponent, pBuffer);
01147 }
01148 } else if((pBuffer->nFilledLen > 0) && (!flagSetupTunnel)) {
01149 fwrite(pBuffer->pBuffer, 1, pBuffer->nFilledLen, outfile);
01150 pBuffer->nFilledLen = 0;
01151 }
01152 if(pBuffer->nFlags == OMX_BUFFERFLAG_EOS) {
01153 DEBUG(DEB_LEV_ERR, "In %s: eos=%x Calling Empty This Buffer\n", __func__, (int)pBuffer->nFlags);
01154 bEOS = OMX_TRUE;
01155 }
01156 if(!bEOS && !flagIsColorConvRequested && (!flagSetupTunnel)) {
01157 err = OMX_FillThisBuffer(hComponent, pBuffer);
01158 }
01159 } else {
01160 DEBUG(DEB_LEV_ERR, "In %s: eos=%x Dropping Empty This Buffer\n", __func__,(int)pBuffer->nFlags);
01161 }
01162 } else {
01163 DEBUG(DEB_LEV_ERR, "Ouch! In %s: had NULL buffer to output...\n", __func__);
01164 }
01165 return OMX_ErrorNone;
01166 }
01167
01168