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 err = OMX_SendCommand(appPriv->fbdev_sink_handle, OMX_CommandPortDisable, 1, NULL);
00583 if(err != OMX_ErrorNone) {
00584 DEBUG(DEB_LEV_ERR,"video sink clock port disable failed err=%x \n",err);
00585 exit(1);
00586 }
00587 tsem_down(appPriv->fbdevSinkEventSem);
00588 DEBUG(DEB_LEV_SIMPLE_SEQ, "In %s Video Sink Clock Port Disabled\n", __func__);
00589 }
00590 }
00591
00593 buffer_out_size = out_width * out_height * 3/2;
00594 DEBUG(DEB_LEV_SIMPLE_SEQ, "\n buffer_out_size : %d \n", (int)buffer_out_size);
00595
00597 if (flagSetupTunnel) {
00598 DEBUG(DEB_LEV_SIMPLE_SEQ, "Setting up Tunnel\n");
00599 err = OMX_SetupTunnel(appPriv->videosrchandle, 0, appPriv->colorconv_handle, 0);
00600 if(err != OMX_ErrorNone) {
00601 DEBUG(DEB_LEV_ERR, "Set up Tunnel between video dec & color conv Failed\n");
00602 exit(1);
00603 }
00604 err = OMX_SetupTunnel(appPriv->colorconv_handle, 1, appPriv->fbdev_sink_handle, 0);
00605 if(err != OMX_ErrorNone) {
00606 DEBUG(DEB_LEV_ERR, "Set up Tunnel between color conv & video sink Failed\n");
00607 exit(1);
00608 }
00609 DEBUG(DEFAULT_MESSAGES, "Set up Tunnel Completed\n");
00610 }
00611
00612 setPortParameters();
00613
00615 err = OMX_SendCommand(appPriv->videosrchandle, OMX_CommandStateSet, OMX_StateIdle, NULL);
00616
00618 if(flagIsColorConvRequested && flagSetupTunnel) {
00619 err = OMX_SendCommand(appPriv->colorconv_handle, OMX_CommandStateSet, OMX_StateIdle, NULL);
00620 if(flagIsSinkRequested && flagSetupTunnel) {
00621 err = OMX_SendCommand(appPriv->fbdev_sink_handle, OMX_CommandStateSet, OMX_StateIdle, NULL);
00622 }
00623 }
00624
00625 if(flagSetupTunnel) {
00626 if(flagIsSinkRequested) {
00627 tsem_down(appPriv->fbdevSinkEventSem);
00628 }
00629 if(flagIsColorConvRequested) {
00630 tsem_down(appPriv->colorconvEventSem);
00631 }
00632 }
00633
00635 if (!flagSetupTunnel) {
00636 pOutBuffer1 = pOutBuffer2 = NULL;
00637 err = OMX_AllocateBuffer(appPriv->videosrchandle, &pOutBuffer1, 0, NULL, buffer_out_size);
00638 err = OMX_AllocateBuffer(appPriv->videosrchandle, &pOutBuffer2, 0, NULL, buffer_out_size);
00639 }
00640
00641 DEBUG(DEB_LEV_SIMPLE_SEQ, "Before locking on idle wait semaphore\n");
00642 tsem_down(appPriv->sourceEventSem);
00643 DEBUG(DEB_LEV_SIMPLE_SEQ, "source Sem free\n");
00644
00645 if(!flagSetupTunnel) {
00646 if(flagIsColorConvRequested == 1) {
00647 pOutBufferColorConv1 = pOutBufferColorConv2 = NULL;
00648 err = OMX_SendCommand(appPriv->colorconv_handle, OMX_CommandStateSet, OMX_StateIdle, NULL);
00649
00650 omx_colorconvPortDefinition.nPortIndex = 0;
00651 setHeader(&omx_colorconvPortDefinition, sizeof(OMX_PARAM_PORTDEFINITIONTYPE));
00652 err = OMX_GetParameter(appPriv->colorconv_handle, OMX_IndexParamPortDefinition, &omx_colorconvPortDefinition);
00653 outbuf_colorconv_size = omx_colorconvPortDefinition.nBufferSize;
00654
00656 err = OMX_UseBuffer(appPriv->colorconv_handle, &pInBufferColorConv1, 0, NULL, outbuf_colorconv_size, pOutBuffer1->pBuffer);
00657 if(err != OMX_ErrorNone) {
00658 DEBUG(DEB_LEV_ERR, "Unable to use the color conv comp allocate buffer\n");
00659 exit(1);
00660 }
00661 err = OMX_UseBuffer(appPriv->colorconv_handle, &pInBufferColorConv2, 0, NULL, outbuf_colorconv_size, pOutBuffer2->pBuffer);
00662 if(err != OMX_ErrorNone) {
00663 DEBUG(DEB_LEV_ERR, "Unable to use the color conv comp allocate buffer\n");
00664 exit(1);
00665 }
00666
00669 DEBUG(DEB_LEV_SIMPLE_SEQ, " outbuf_colorconv_size : %d \n", (int)outbuf_colorconv_size);
00670 omx_colorconvPortDefinition.nPortIndex = 1;
00671 setHeader(&omx_colorconvPortDefinition, sizeof(OMX_PARAM_PORTDEFINITIONTYPE));
00672 err = OMX_GetParameter(appPriv->colorconv_handle, OMX_IndexParamPortDefinition, &omx_colorconvPortDefinition);
00673 outbuf_colorconv_size = omx_colorconvPortDefinition.nBufferSize;
00674
00675 err = OMX_AllocateBuffer(appPriv->colorconv_handle, &pOutBufferColorConv1, 1, NULL, outbuf_colorconv_size);
00676 if(err != OMX_ErrorNone) {
00677 DEBUG(DEB_LEV_ERR, "Unable to allocate buffer in color conv\n");
00678 exit(1);
00679 }
00680 err = OMX_AllocateBuffer(appPriv->colorconv_handle, &pOutBufferColorConv2, 1, NULL, outbuf_colorconv_size);
00681 if(err != OMX_ErrorNone) {
00682 DEBUG(DEB_LEV_ERR, "Unable to allocate buffer in colro conv\n");
00683 exit(1);
00684 }
00685
00686 DEBUG(DEB_LEV_SIMPLE_SEQ, "Before locking on idle wait semaphore\n");
00687 tsem_down(appPriv->colorconvEventSem);
00688 DEBUG(DEB_LEV_SIMPLE_SEQ, "color conv Sem free\n");
00689
00690 if(flagIsSinkRequested == 1) {
00691 err = OMX_SendCommand(appPriv->fbdev_sink_handle, OMX_CommandStateSet, OMX_StateIdle, NULL);
00692 err = OMX_UseBuffer(appPriv->fbdev_sink_handle, &pInBufferSink1, 0, NULL, outbuf_colorconv_size, pOutBufferColorConv1->pBuffer);
00693 if(err != OMX_ErrorNone) {
00694 DEBUG(DEB_LEV_ERR, "Unable to use the color conv comp allocate buffer\n");
00695 exit(1);
00696 }
00697 err = OMX_UseBuffer(appPriv->fbdev_sink_handle, &pInBufferSink2, 0, NULL, outbuf_colorconv_size, pOutBufferColorConv2->pBuffer);
00698 if(err != OMX_ErrorNone) {
00699 DEBUG(DEB_LEV_ERR, "Unable to use the color conv comp allocate buffer\n");
00700 exit(1);
00701 }
00702
00703 DEBUG(DEB_LEV_SIMPLE_SEQ, "Before locking on idle wait semaphore\n");
00704 tsem_down(appPriv->fbdevSinkEventSem);
00705 DEBUG(DEB_LEV_SIMPLE_SEQ, "video sink comp Sem free\n");
00706 }
00707 }
00708
00709 if(flagIsColorConvRequested == 1) {
00710 err = OMX_SendCommand(appPriv->colorconv_handle, OMX_CommandStateSet, OMX_StateExecuting, NULL);
00711 tsem_down(appPriv->colorconvEventSem);
00712 if(flagIsSinkRequested == 1) {
00713 err = OMX_SendCommand(appPriv->fbdev_sink_handle, OMX_CommandStateSet, OMX_StateExecuting, NULL);
00714 tsem_down(appPriv->fbdevSinkEventSem);
00715 }
00716 }
00717 }
00718
00720 if(flagIsColorConvRequested == 1 && flagSetupTunnel) {
00721 err = OMX_SendCommand(appPriv->colorconv_handle, OMX_CommandStateSet, OMX_StateExecuting, NULL);
00722 tsem_down(appPriv->colorconvEventSem);
00723 if(flagIsSinkRequested == 1) {
00724 err = OMX_SendCommand(appPriv->fbdev_sink_handle, OMX_CommandStateSet, OMX_StateExecuting, NULL);
00725 tsem_down(appPriv->fbdevSinkEventSem);
00726 }
00727 }
00728
00730 err = OMX_SendCommand(appPriv->videosrchandle, OMX_CommandStateSet, OMX_StateExecuting, NULL);
00731 tsem_down(appPriv->sourceEventSem);
00732
00733 if(flagIsColorConvRequested == 1 && !flagSetupTunnel) {
00734 err = OMX_FillThisBuffer(appPriv->colorconv_handle, pOutBufferColorConv1);
00735 err = OMX_FillThisBuffer(appPriv->colorconv_handle, pOutBufferColorConv2);
00736 DEBUG(DEB_LEV_SIMPLE_SEQ, "---> After fill this buffer function calls to the color conv output buffers\n");
00737 }
00738 if (!flagSetupTunnel) {
00739 err = OMX_FillThisBuffer(appPriv->videosrchandle, pOutBuffer1);
00740 err = OMX_FillThisBuffer(appPriv->videosrchandle, pOutBuffer2);
00741 }
00742
00743 DEBUG(DEB_LEV_SIMPLE_SEQ, "---> Before locking on condition and sourceMutex\n");
00744
00745 DEBUG(DEFAULT_MESSAGES,"Enter 'q' or 'Q' to exit\n");
00746
00747 while(1) {
00748 if('Q' == toupper(getchar())) {
00749 DEBUG(DEFAULT_MESSAGES,"Stoping capture\n");
00750 bEOS = OMX_TRUE;
00751 break;
00752 }
00753 }
00754
00755 DEBUG(DEFAULT_MESSAGES, "The execution of the video decoding process is terminated\n");
00756
00758 err = OMX_SendCommand(appPriv->videosrchandle, OMX_CommandStateSet, OMX_StateIdle, NULL);
00759 if(flagIsColorConvRequested == 1) {
00760 err = OMX_SendCommand(appPriv->colorconv_handle, OMX_CommandStateSet, OMX_StateIdle, NULL);
00761 if(flagIsSinkRequested == 1) {
00762 err = OMX_SendCommand(appPriv->fbdev_sink_handle, OMX_CommandStateSet, OMX_StateIdle, NULL);
00763 }
00764 }
00765
00766 tsem_down(appPriv->sourceEventSem);
00767 if(flagIsColorConvRequested == 1) {
00768 tsem_down(appPriv->colorconvEventSem);
00769 if(flagIsSinkRequested == 1) {
00770 tsem_down(appPriv->fbdevSinkEventSem);
00771 }
00772 }
00773
00774 DEBUG(DEFAULT_MESSAGES, "All video components Transitioned to Idle\n");
00775
00777 err = OMX_SendCommand(appPriv->videosrchandle, OMX_CommandStateSet, OMX_StateLoaded, NULL);
00778 if(flagIsColorConvRequested == 1) {
00779 err = OMX_SendCommand(appPriv->colorconv_handle, OMX_CommandStateSet, OMX_StateLoaded, NULL);
00780 if(flagIsSinkRequested == 1) {
00781 err = OMX_SendCommand(appPriv->fbdev_sink_handle, OMX_CommandStateSet, OMX_StateLoaded, NULL);
00782 }
00783 }
00784
00786 if(flagIsColorConvRequested == 1 && !flagSetupTunnel) {
00787 if(flagIsSinkRequested == 1 && !flagSetupTunnel) {
00788 DEBUG(DEB_LEV_SIMPLE_SEQ, "Video sink to loaded\n");
00789 err = OMX_FreeBuffer(appPriv->fbdev_sink_handle, 0, pInBufferSink1);
00790 err = OMX_FreeBuffer(appPriv->fbdev_sink_handle, 0, pInBufferSink2);
00791 }
00792 DEBUG(DEB_LEV_SIMPLE_SEQ, "Color conv to loaded\n");
00793 err = OMX_FreeBuffer(appPriv->colorconv_handle, 0, pInBufferColorConv1);
00794 err = OMX_FreeBuffer(appPriv->colorconv_handle, 0, pInBufferColorConv2);
00795
00796 err = OMX_FreeBuffer(appPriv->colorconv_handle, 1, pOutBufferColorConv1);
00797 err = OMX_FreeBuffer(appPriv->colorconv_handle, 1, pOutBufferColorConv2);
00798 }
00799
00801 DEBUG(DEB_LEV_SIMPLE_SEQ, "Video dec to loaded\n");
00802 if(!flagSetupTunnel) {
00803 DEBUG(DEB_LEV_PARAMS, "Free Video dec output ports\n");
00804 err = OMX_FreeBuffer(appPriv->videosrchandle, 0, pOutBuffer1);
00805 err = OMX_FreeBuffer(appPriv->videosrchandle, 0, pOutBuffer2);
00806 }
00807
00808 if(flagIsColorConvRequested == 1) {
00809 if(flagIsSinkRequested == 1) {
00810 tsem_down(appPriv->fbdevSinkEventSem);
00811 }
00812 tsem_down(appPriv->colorconvEventSem);
00813 }
00814 tsem_down(appPriv->sourceEventSem);
00815 DEBUG(DEB_LEV_SIMPLE_SEQ, "All components released\n");
00816
00817 OMX_FreeHandle(appPriv->videosrchandle);
00818 if(flagIsColorConvRequested == 1) {
00819 if(flagIsSinkRequested == 1) {
00820 OMX_FreeHandle(appPriv->fbdev_sink_handle);
00821 }
00822 OMX_FreeHandle(appPriv->colorconv_handle);
00823 }
00824 DEBUG(DEB_LEV_SIMPLE_SEQ, "video dec freed\n");
00825
00826 OMX_Deinit();
00827
00828 DEBUG(DEFAULT_MESSAGES, "All components freed. Closing...\n");
00829 free(appPriv->sourceEventSem);
00830 if(flagIsColorConvRequested == 1) {
00831 if(flagIsSinkRequested == 1) {
00832 free(appPriv->fbdevSinkEventSem);
00833 }
00834 free(appPriv->colorconvEventSem);
00835 }
00836 free(appPriv->eofSem);
00837 free(appPriv);
00838
00839 free(full_component_name);
00840
00842 if(!flagIsSinkRequested) {
00843 fclose(outfile);
00844 }
00845 if(output_file) {
00846 free(output_file);
00847 }
00848
00849 return 0;
00850 }
00851
00852
00854 OMX_ERRORTYPE fb_sinkEventHandler(
00855 OMX_OUT OMX_HANDLETYPE hComponent,
00856 OMX_OUT OMX_PTR pAppData,
00857 OMX_OUT OMX_EVENTTYPE eEvent,
00858 OMX_OUT OMX_U32 Data1,
00859 OMX_OUT OMX_U32 Data2,
00860 OMX_OUT OMX_PTR pEventData) {
00861
00862 DEBUG(DEB_LEV_SIMPLE_SEQ, "Hi there, I am in the %s callback\n", __func__);
00863 if(eEvent == OMX_EventCmdComplete) {
00864 if (Data1 == OMX_CommandStateSet) {
00865 DEBUG(DEB_LEV_SIMPLE_SEQ, "State changed in ");
00866 switch ((int)Data2) {
00867 case OMX_StateInvalid:
00868 DEBUG(DEB_LEV_SIMPLE_SEQ, "OMX_StateInvalid\n");
00869 break;
00870 case OMX_StateLoaded:
00871 DEBUG(DEB_LEV_SIMPLE_SEQ, "OMX_StateLoaded\n");
00872 break;
00873 case OMX_StateIdle:
00874 DEBUG(DEB_LEV_SIMPLE_SEQ, "OMX_StateIdle ---- fbsink\n");
00875 break;
00876 case OMX_StateExecuting:
00877 DEBUG(DEB_LEV_SIMPLE_SEQ, "OMX_StateExecuting\n");
00878 break;
00879 case OMX_StatePause:
00880 DEBUG(DEB_LEV_SIMPLE_SEQ, "OMX_StatePause\n");
00881 break;
00882 case OMX_StateWaitForResources:
00883 DEBUG(DEB_LEV_SIMPLE_SEQ, "OMX_StateWaitForResources\n");
00884 break;
00885 }
00886 tsem_up(appPriv->fbdevSinkEventSem);
00887 }
00888 else if (OMX_CommandPortEnable || OMX_CommandPortDisable) {
00889 DEBUG(DEB_LEV_SIMPLE_SEQ, "In %s Received Port Enable/Disable Event\n",__func__);
00890 tsem_up(appPriv->fbdevSinkEventSem);
00891 }
00892 } else if(eEvent == OMX_EventBufferFlag) {
00893 DEBUG(DEB_LEV_ERR, "In %s OMX_BUFFERFLAG_EOS\n", __func__);
00894 if((int)Data2 == OMX_BUFFERFLAG_EOS) {
00895 tsem_up(appPriv->eofSem);
00896 }
00897 } else {
00898 DEBUG(DEB_LEV_SIMPLE_SEQ, "Param1 is %i\n", (int)Data1);
00899 DEBUG(DEB_LEV_SIMPLE_SEQ, "Param2 is %i\n", (int)Data2);
00900 }
00901 return OMX_ErrorNone;
00902 }
00903
00904
00905 OMX_ERRORTYPE fb_sinkEmptyBufferDone(
00906 OMX_OUT OMX_HANDLETYPE hComponent,
00907 OMX_OUT OMX_PTR pAppData,
00908 OMX_OUT OMX_BUFFERHEADERTYPE* pBuffer) {
00909
00910 OMX_ERRORTYPE err;
00911 static int inputBufferDropped = 0;
00912 if(pBuffer != NULL) {
00913 if(!bEOS) {
00914 if(pOutBufferColorConv1->pBuffer == pBuffer->pBuffer) {
00915 pOutBufferColorConv1->nFilledLen = pBuffer->nFilledLen;
00916 err = OMX_FillThisBuffer(appPriv->colorconv_handle, pOutBufferColorConv1);
00917 } else {
00918 pOutBufferColorConv2->nFilledLen = pBuffer->nFilledLen;
00919 err = OMX_FillThisBuffer(appPriv->colorconv_handle, pOutBufferColorConv2);
00920 }
00921 if(err != OMX_ErrorNone) {
00922 DEBUG(DEB_LEV_ERR, "In %s Error %08x Calling FillThisBuffer\n", __func__,err);
00923 }
00924 } else {
00925 DEBUG(DEB_LEV_ERR, "In %s: eos=%x Dropping Fill This Buffer\n", __func__,(int)pBuffer->nFlags);
00926 inputBufferDropped++;
00927 if(inputBufferDropped == 2) {
00928 tsem_up(appPriv->eofSem);
00929 }
00930 }
00931 } else {
00932 if(!bEOS) {
00933 tsem_up(appPriv->eofSem);
00934 }
00935 DEBUG(DEB_LEV_ERR, "Ouch! In %s: had NULL buffer to output...\n", __func__);
00936 }
00937 return OMX_ErrorNone;
00938 }
00939
00940
00941
00942 OMX_ERRORTYPE colorconvEventHandler(
00943 OMX_OUT OMX_HANDLETYPE hComponent,
00944 OMX_OUT OMX_PTR pAppData,
00945 OMX_OUT OMX_EVENTTYPE eEvent,
00946 OMX_OUT OMX_U32 Data1,
00947 OMX_OUT OMX_U32 Data2,
00948 OMX_OUT OMX_PTR pEventData) {
00949
00950 DEBUG(DEB_LEV_SIMPLE_SEQ, "\nHi there, I am in the %s callback\n", __func__);
00951 if(eEvent == OMX_EventCmdComplete) {
00952 if (Data1 == OMX_CommandStateSet) {
00953 DEBUG(DEB_LEV_SIMPLE_SEQ, "\nState changed in ");
00954 switch ((int)Data2) {
00955 case OMX_StateInvalid:
00956 DEBUG(DEB_LEV_SIMPLE_SEQ, "OMX_StateInvalid\n");
00957 break;
00958 case OMX_StateLoaded:
00959 DEBUG(DEB_LEV_SIMPLE_SEQ, "OMX_StateLoaded\n");
00960 break;
00961 case OMX_StateIdle:
00962 DEBUG(DEB_LEV_SIMPLE_SEQ, "OMX_StateIdle\n");
00963 break;
00964 case OMX_StateExecuting:
00965 DEBUG(DEB_LEV_SIMPLE_SEQ, "OMX_StateExecuting\n");
00966 break;
00967 case OMX_StatePause:
00968 DEBUG(DEB_LEV_SIMPLE_SEQ, "OMX_StatePause\n");
00969 break;
00970 case OMX_StateWaitForResources:
00971 DEBUG(DEB_LEV_SIMPLE_SEQ, "OMX_StateWaitForResources\n");
00972 break;
00973 }
00974 tsem_up(appPriv->colorconvEventSem);
00975 }
00976 else if (OMX_CommandPortEnable || OMX_CommandPortDisable) {
00977 DEBUG(DEB_LEV_SIMPLE_SEQ, "In %s Received Port Enable/Disable Event\n",__func__);
00978 tsem_up(appPriv->colorconvEventSem);
00979 }
00980 } else if(eEvent == OMX_EventBufferFlag) {
00981 DEBUG(DEB_LEV_ERR, "In %s OMX_BUFFERFLAG_EOS\n", __func__);
00982 if((int)Data2 == OMX_BUFFERFLAG_EOS) {
00983 tsem_up(appPriv->eofSem);
00984 }
00985 } else {
00986 DEBUG(DEB_LEV_SIMPLE_SEQ, "Param1 is %i\n", (int)Data1);
00987 DEBUG(DEB_LEV_SIMPLE_SEQ, "Param2 is %i\n", (int)Data2);
00988 }
00989 return OMX_ErrorNone;
00990 }
00991
00992
00993 OMX_ERRORTYPE colorconvEmptyBufferDone(
00994 OMX_OUT OMX_HANDLETYPE hComponent,
00995 OMX_OUT OMX_PTR pAppData,
00996 OMX_OUT OMX_BUFFERHEADERTYPE* pBuffer) {
00997
00998 OMX_ERRORTYPE err;
00999 static int iBufferDropped = 0;
01000
01001 if(pBuffer != NULL) {
01002 if(!bEOS) {
01003 if(pOutBuffer1->pBuffer == pBuffer->pBuffer) {
01004 pOutBuffer1->nFilledLen = pBuffer->nFilledLen;
01005 err = OMX_FillThisBuffer(appPriv->videosrchandle, pOutBuffer1);
01006 } else {
01007 pOutBuffer2->nFilledLen = pBuffer->nFilledLen;
01008 err = OMX_FillThisBuffer(appPriv->videosrchandle, pOutBuffer2);
01009 }
01010 if(err != OMX_ErrorNone) {
01011 DEBUG(DEB_LEV_ERR, "In %s Error %08x Calling FillThisBuffer\n", __func__,err);
01012 }
01013 } else {
01014 DEBUG(DEB_LEV_ERR, "In %s: eos=%x Dropping Fill This Buffer\n", __func__,(int)pBuffer->nFlags);
01015 iBufferDropped++;
01016 if(iBufferDropped == 2) {
01017 tsem_up(appPriv->eofSem);
01018 }
01019 }
01020 } else {
01021 if(!bEOS) {
01022 tsem_up(appPriv->eofSem);
01023 }
01024 DEBUG(DEB_LEV_ERR, "Ouch! In %s: had NULL buffer to output...\n", __func__);
01025 }
01026 return OMX_ErrorNone;
01027 }
01028
01029
01030 OMX_ERRORTYPE colorconvFillBufferDone(
01031 OMX_OUT OMX_HANDLETYPE hComponent,
01032 OMX_OUT OMX_PTR pAppData,
01033 OMX_OUT OMX_BUFFERHEADERTYPE* pBuffer) {
01034
01035 OMX_ERRORTYPE err;
01036 if(pBuffer != NULL) {
01037 if(!bEOS) {
01041 if(flagIsSinkRequested && (!flagSetupTunnel)) {
01042
01043 if(pInBufferSink1->pBuffer == pBuffer->pBuffer) {
01044 pInBufferSink1->nFilledLen = pBuffer->nFilledLen;
01045 err = OMX_EmptyThisBuffer(appPriv->fbdev_sink_handle, pInBufferSink1);
01046 } else {
01047 pInBufferSink2->nFilledLen = pBuffer->nFilledLen;
01048 err = OMX_EmptyThisBuffer(appPriv->fbdev_sink_handle, pInBufferSink2);
01049 }
01050 if(err != OMX_ErrorNone) {
01051 DEBUG(DEB_LEV_ERR, "In %s Error %08x Calling FillThisBuffer\n", __func__,err);
01052 }
01053 } else if((pBuffer->nFilledLen > 0) && (!flagSetupTunnel)) {
01054 fwrite(pBuffer->pBuffer, 1, pBuffer->nFilledLen, outfile);
01055 pBuffer->nFilledLen = 0;
01056 }
01057 if(pBuffer->nFlags == OMX_BUFFERFLAG_EOS) {
01058 DEBUG(DEB_LEV_ERR, "In %s: eos=%x Calling Empty This Buffer\n", __func__, (int)pBuffer->nFlags);
01059 bEOS = OMX_TRUE;
01060 }
01061 if(!bEOS && !flagIsSinkRequested && (!flagSetupTunnel)) {
01062 err = OMX_FillThisBuffer(hComponent, pBuffer);
01063 }
01064 } else {
01065 DEBUG(DEB_LEV_ERR, "In %s: eos=%x Dropping Empty This Buffer\n", __func__,(int)pBuffer->nFlags);
01066 }
01067 } else {
01068 DEBUG(DEB_LEV_ERR, "Ouch! In %s: had NULL buffer to output...\n", __func__);
01069 }
01070 return OMX_ErrorNone;
01071 }
01072
01074 OMX_ERRORTYPE videosrcEventHandler(
01075 OMX_OUT OMX_HANDLETYPE hComponent,
01076 OMX_OUT OMX_PTR pAppData,
01077 OMX_OUT OMX_EVENTTYPE eEvent,
01078 OMX_OUT OMX_U32 Data1,
01079 OMX_OUT OMX_U32 Data2,
01080 OMX_OUT OMX_PTR pEventData) {
01081
01082 OMX_ERRORTYPE err = OMX_ErrorNone;
01083
01084 DEBUG(DEB_LEV_SIMPLE_SEQ, "Hi there, I am in the %s callback\n", __func__);
01085 if(eEvent == OMX_EventCmdComplete) {
01086 if (Data1 == OMX_CommandStateSet) {
01087 DEBUG(DEB_LEV_SIMPLE_SEQ, "State changed in ");
01088 switch ((int)Data2) {
01089 case OMX_StateInvalid:
01090 DEBUG(DEB_LEV_SIMPLE_SEQ, "OMX_StateInvalid\n");
01091 break;
01092 case OMX_StateLoaded:
01093 DEBUG(DEB_LEV_SIMPLE_SEQ, "OMX_StateLoaded\n");
01094 break;
01095 case OMX_StateIdle:
01096 DEBUG(DEB_LEV_SIMPLE_SEQ, "OMX_StateIdle\n");
01097 break;
01098 case OMX_StateExecuting:
01099 DEBUG(DEB_LEV_SIMPLE_SEQ, "OMX_StateExecuting\n");
01100 break;
01101 case OMX_StatePause:
01102 DEBUG(DEB_LEV_SIMPLE_SEQ, "OMX_StatePause\n");
01103 break;
01104 case OMX_StateWaitForResources:
01105 DEBUG(DEB_LEV_SIMPLE_SEQ, "OMX_StateWaitForResources\n");
01106 break;
01107 }
01108 tsem_up(appPriv->sourceEventSem);
01109 }
01110 else if (OMX_CommandPortEnable || OMX_CommandPortDisable) {
01111 DEBUG(DEB_LEV_SIMPLE_SEQ, "In %s Received Port Enable/Disable Event\n",__func__);
01112 tsem_up(appPriv->sourceEventSem);
01113 }
01114 } else if(eEvent == OMX_EventPortSettingsChanged) {
01115 DEBUG(DEB_LEV_SIMPLE_SEQ, "\n port settings change event handler in %s \n", __func__);
01116 } else if(eEvent == OMX_EventBufferFlag) {
01117 DEBUG(DEB_LEV_ERR, "In %s OMX_BUFFERFLAG_EOS\n", __func__);
01118 if((int)Data2 == OMX_BUFFERFLAG_EOS) {
01119 tsem_up(appPriv->eofSem);
01120 }
01121 } else {
01122 DEBUG(DEB_LEV_SIMPLE_SEQ, "Param1 is %i\n", (int)Data1);
01123 DEBUG(DEB_LEV_SIMPLE_SEQ, "Param2 is %i\n", (int)Data2);
01124 }
01125 return err;
01126 }
01127
01128 OMX_ERRORTYPE videosrcFillBufferDone(
01129 OMX_OUT OMX_HANDLETYPE hComponent,
01130 OMX_OUT OMX_PTR pAppData,
01131 OMX_OUT OMX_BUFFERHEADERTYPE* pBuffer) {
01132
01133 OMX_ERRORTYPE err;
01134 OMX_STATETYPE eState;
01135
01136 if(pBuffer != NULL){
01137 if(!bEOS) {
01141 if(flagIsColorConvRequested && (!flagSetupTunnel)) {
01142 OMX_GetState(appPriv->colorconv_handle,&eState);
01143 if(eState == OMX_StateExecuting || eState == OMX_StatePause) {
01144 if(pInBufferColorConv1->pBuffer == pBuffer->pBuffer) {
01145 pInBufferColorConv1->nFilledLen = pBuffer->nFilledLen;
01146 err = OMX_EmptyThisBuffer(appPriv->colorconv_handle, pInBufferColorConv1);
01147 } else {
01148 pInBufferColorConv2->nFilledLen = pBuffer->nFilledLen;
01149 err = OMX_EmptyThisBuffer(appPriv->colorconv_handle, pInBufferColorConv2);
01150 }
01151 if(err != OMX_ErrorNone) {
01152 DEBUG(DEB_LEV_ERR, "In %s Error %08x Calling FillThisBuffer\n", __func__,err);
01153 }
01154 } else {
01155 err = OMX_FillThisBuffer(hComponent, pBuffer);
01156 }
01157 } else if((pBuffer->nFilledLen > 0) && (!flagSetupTunnel)) {
01158 fwrite(pBuffer->pBuffer, 1, pBuffer->nFilledLen, outfile);
01159 pBuffer->nFilledLen = 0;
01160 }
01161 if(pBuffer->nFlags == OMX_BUFFERFLAG_EOS) {
01162 DEBUG(DEB_LEV_ERR, "In %s: eos=%x Calling Empty This Buffer\n", __func__, (int)pBuffer->nFlags);
01163 bEOS = OMX_TRUE;
01164 }
01165 if(!bEOS && !flagIsColorConvRequested && (!flagSetupTunnel)) {
01166 err = OMX_FillThisBuffer(hComponent, pBuffer);
01167 }
01168 } else {
01169 DEBUG(DEB_LEV_ERR, "In %s: eos=%x Dropping Empty This Buffer\n", __func__,(int)pBuffer->nFlags);
01170 }
01171 } else {
01172 DEBUG(DEB_LEV_ERR, "Ouch! In %s: had NULL buffer to output...\n", __func__);
01173 }
01174 return OMX_ErrorNone;
01175 }
01176
01177