00001
00036 #include <stdio.h>
00037 #include <unistd.h>
00038 #include <stdlib.h>
00039 #include <string.h>
00040
00041 #include <OMX_Core.h>
00042 #include <OMX_Component.h>
00043 #include <OMX_Types.h>
00044
00045 #include "omxcameratest.h"
00046
00047
00048
00049
00050 OMX_CALLBACKTYPE camera_source_callbacks = {
00051 .EventHandler = camera_sourceEventHandler,
00052 .EmptyBufferDone = NULL,
00053 .FillBufferDone = camera_sourceFillBufferDone
00054 };
00055
00056
00057 OMX_CALLBACKTYPE colorconv_callbacks = {
00058 .EventHandler = colorconvEventHandler,
00059 .EmptyBufferDone = colorconvEmptyBufferDone,
00060 .FillBufferDone = colorconvFillBufferDone
00061 };
00062
00063
00064 OMX_CALLBACKTYPE fbsink_callbacks = {
00065 .EventHandler = fbsinkEventHandler,
00066 .EmptyBufferDone = fbsinkEmptyBufferDone,
00067 .FillBufferDone = NULL
00068 };
00069
00070 appPrivateType* appPriv = NULL;
00071
00072 OMX_PORTBUFFERCTXT sCameraPortBufferList[NUM_CAMERAPORTS];
00073
00074 FILE* fCapture = NULL;
00075 char g_DefaultCaptureFileName[] = "capture.yuv";
00076 FILE* fThumbnail = NULL;
00077 char g_DefaultThumbnailFileName[] = "thumbnail.yuv";
00078
00079
00081 OMX_ERRORTYPE camera_sourceEventHandler(
00082 OMX_OUT OMX_HANDLETYPE hComponent,
00083 OMX_OUT OMX_PTR pAppData,
00084 OMX_OUT OMX_EVENTTYPE eEvent,
00085 OMX_OUT OMX_U32 Data1,
00086 OMX_OUT OMX_U32 Data2,
00087 OMX_OUT OMX_PTR pEventData) {
00088
00089 DEBUG(DEB_LEV_FUNCTION_NAME, "In %s for camera component\n",__func__);
00090
00091 DEBUG(DEB_LEV_SIMPLE_SEQ, "Hi there, I am in the %s callback\n", __func__);
00092 DEBUG(DEB_LEV_SIMPLE_SEQ, "%s: event type code (eEvent)=%d\n", __func__, eEvent);
00093 if(eEvent == OMX_EventCmdComplete) {
00094 if (Data1 == OMX_CommandStateSet) {
00095 DEBUG(DEB_LEV_SIMPLE_SEQ, "Set state to ");
00096 switch ((int)Data2) {
00097 case OMX_StateInvalid:
00098 DEBUG(DEB_LEV_SIMPLE_SEQ, "OMX_StateInvalid\n");
00099 break;
00100 case OMX_StateLoaded:
00101 DEBUG(DEB_LEV_SIMPLE_SEQ, "OMX_StateLoaded\n");
00102 break;
00103 case OMX_StateIdle:
00104 DEBUG(DEB_LEV_SIMPLE_SEQ, "OMX_StateIdle\n");
00105 break;
00106 case OMX_StateExecuting:
00107 DEBUG(DEB_LEV_SIMPLE_SEQ, "OMX_StateExecuting\n");
00108 break;
00109 case OMX_StatePause:
00110 DEBUG(DEB_LEV_SIMPLE_SEQ, "OMX_StatePause\n");
00111 break;
00112 case OMX_StateWaitForResources:
00113 DEBUG(DEB_LEV_SIMPLE_SEQ, "OMX_StateWaitForResources\n");
00114 break;
00115 }
00116 tsem_up(appPriv->cameraSourceEventSem);
00117 }
00118 }
00119
00120 DEBUG(DEB_LEV_FUNCTION_NAME, "Out of %s for camera component, return code: 0x%X\n",__func__, OMX_ErrorNone);
00121 return OMX_ErrorNone;
00122 }
00123
00124
00125 OMX_ERRORTYPE camera_sourceFillBufferDone(
00126 OMX_OUT OMX_HANDLETYPE hComponent,
00127 OMX_OUT OMX_PTR pAppData,
00128 OMX_OUT OMX_BUFFERHEADERTYPE* pBuffer) {
00129
00130 DEBUG(DEB_LEV_FUNCTION_NAME, "In %s for camera component\n",__func__);
00131
00132 DEBUG(DEB_LEV_FULL_SEQ, "%s: Get returned buffer (0x%lX) from port[%ld], nFilledLen=%ld\n", __func__, (OMX_U32)pBuffer, pBuffer->nOutputPortIndex, pBuffer->nFilledLen);
00133
00134 if (pBuffer->nOutputPortIndex == OMX_CAMPORT_INDEX_CP) {
00135 if ((pBuffer->nFlags & OMX_BUFFERFLAG_STARTTIME) != 0) {
00136 DEBUG(DEB_LEV_FULL_SEQ, "%s: Get buffer flag OMX_BUFFERFLAG_STARTTIME!\n", __func__);
00137 pBuffer->nFlags = 0;
00138 }
00139
00140 #ifndef OMX_SKIP64BIT
00141 DEBUG(DEB_LEV_FULL_SEQ, "%s: buffer[0x%lX] time stamp: 0x%016llX\n", __func__, (OMX_U32)pBuffer, pBuffer->nTimeStamp);
00142 #else
00143 DEBUG(DEB_LEV_FULL_SEQ, "%s: buffer[0x%lX] time stamp: 0x%08lX%08lX\n", __func__, (OMX_U32)pBuffer, pBuffer->nTimeStamp.nHighPart, pBuffer->nTimeStamp.nLowPart);
00144 #endif
00145 }
00146
00147 if (pBuffer->nOutputPortIndex == OMX_CAMPORT_INDEX_CP && fCapture != NULL) {
00148 DEBUG(DEB_LEV_FULL_SEQ, "%s: writing to file",__func__);
00149 fwrite(pBuffer->pBuffer + pBuffer->nOffset, 1, pBuffer->nFilledLen, fCapture);
00150 pBuffer->nFilledLen = 0;
00151 pBuffer->nOffset = 0;
00152 OMX_FillThisBuffer(appPriv->camerahandle, pBuffer);
00153 }
00154 else if (pBuffer->nOutputPortIndex == OMX_CAMPORT_INDEX_CP_T && fThumbnail != NULL) {
00155 fwrite(pBuffer->pBuffer + pBuffer->nOffset, 1, pBuffer->nFilledLen, fThumbnail);
00156 pBuffer->nFilledLen = 0;
00157 pBuffer->nOffset = 0;
00158 OMX_FillThisBuffer(appPriv->camerahandle, pBuffer);
00159 }
00160
00161 DEBUG(DEB_LEV_FUNCTION_NAME, "Out of %s for camera component, return code: 0x%X\n",__func__, OMX_ErrorNone);
00162 return OMX_ErrorNone;
00163 }
00164
00166 OMX_ERRORTYPE colorconvEventHandler(
00167 OMX_OUT OMX_HANDLETYPE hComponent,
00168 OMX_OUT OMX_PTR pAppData,
00169 OMX_OUT OMX_EVENTTYPE eEvent,
00170 OMX_OUT OMX_U32 Data1,
00171 OMX_OUT OMX_U32 Data2,
00172 OMX_OUT OMX_PTR pEventData) {
00173
00174 DEBUG(DEB_LEV_FUNCTION_NAME, "In %s\n",__func__);
00175
00176 DEBUG(DEB_LEV_SIMPLE_SEQ, "Hi there, I am in the %s callback\n", __func__);
00177 DEBUG(DEB_LEV_SIMPLE_SEQ, "%s: event type code (eEvent)=%d\n", __func__, eEvent);
00178 if(eEvent == OMX_EventCmdComplete) {
00179 if (Data1 == OMX_CommandStateSet) {
00180 DEBUG(DEB_LEV_SIMPLE_SEQ, "Set state to ");
00181 switch ((int)Data2) {
00182 case OMX_StateInvalid:
00183 DEBUG(DEB_LEV_SIMPLE_SEQ, "OMX_StateInvalid\n");
00184 break;
00185 case OMX_StateLoaded:
00186 DEBUG(DEB_LEV_SIMPLE_SEQ, "OMX_StateLoaded\n");
00187 break;
00188 case OMX_StateIdle:
00189 DEBUG(DEB_LEV_SIMPLE_SEQ, "OMX_StateIdle\n");
00190 break;
00191 case OMX_StateExecuting:
00192 DEBUG(DEB_LEV_SIMPLE_SEQ, "OMX_StateExecuting\n");
00193 break;
00194 case OMX_StatePause:
00195 DEBUG(DEB_LEV_SIMPLE_SEQ, "OMX_StatePause\n");
00196 break;
00197 case OMX_StateWaitForResources:
00198 DEBUG(DEB_LEV_SIMPLE_SEQ, "OMX_StateWaitForResources\n");
00199 break;
00200 }
00201 tsem_up(appPriv->colorconvEventSem);
00202 }
00203 }
00204
00205 DEBUG(DEB_LEV_FUNCTION_NAME, "Out of %s, return code: 0x%X\n",__func__, OMX_ErrorNone);
00206 return OMX_ErrorNone;
00207 }
00208
00209
00210 OMX_ERRORTYPE colorconvEmptyBufferDone(
00211 OMX_OUT OMX_HANDLETYPE hComponent,
00212 OMX_OUT OMX_PTR pAppData,
00213 OMX_OUT OMX_BUFFERHEADERTYPE* pBuffer) {
00214
00215 DEBUG(DEB_LEV_FUNCTION_NAME, "In %s\n",__func__);
00216
00217 DEBUG(DEB_LEV_SIMPLE_SEQ, "%s: Get returned buffer (0x%lX) from colorconv input port, nFilledLen=%ld\n", __func__, (OMX_U32)pBuffer, pBuffer->nFilledLen);
00218
00219
00220 DEBUG(DEB_LEV_FUNCTION_NAME, "Out of %s, return code: 0x%X\n",__func__, OMX_ErrorNone);
00221 return OMX_ErrorNone;
00222 }
00223
00224 OMX_ERRORTYPE colorconvFillBufferDone(
00225 OMX_OUT OMX_HANDLETYPE hComponent,
00226 OMX_OUT OMX_PTR pAppData,
00227 OMX_OUT OMX_BUFFERHEADERTYPE* pBuffer) {
00228
00229 DEBUG(DEB_LEV_FUNCTION_NAME, "In %s\n",__func__);
00230
00231 DEBUG(DEB_LEV_SIMPLE_SEQ, "%s: Get returned buffer (0x%lX) from colorconv output port, nFilledLen=%ld\n", __func__, (OMX_U32)pBuffer, pBuffer->nFilledLen);
00232
00233
00234 DEBUG(DEB_LEV_FUNCTION_NAME, "Out of %s, return code: 0x%X\n",__func__, OMX_ErrorNone);
00235 return OMX_ErrorNone;
00236 }
00237
00239 OMX_ERRORTYPE fbsinkEventHandler(
00240 OMX_OUT OMX_HANDLETYPE hComponent,
00241 OMX_OUT OMX_PTR pAppData,
00242 OMX_OUT OMX_EVENTTYPE eEvent,
00243 OMX_OUT OMX_U32 Data1,
00244 OMX_OUT OMX_U32 Data2,
00245 OMX_OUT OMX_PTR pEventData) {
00246
00247 DEBUG(DEB_LEV_FUNCTION_NAME, "In %s\n",__func__);
00248
00249 DEBUG(DEB_LEV_SIMPLE_SEQ, "Hi there, I am in the %s callback\n", __func__);
00250 DEBUG(DEB_LEV_SIMPLE_SEQ, "%s: event type code (eEvent)=%d\n", __func__, eEvent);
00251 if(eEvent == OMX_EventCmdComplete) {
00252 if (Data1 == OMX_CommandStateSet) {
00253 DEBUG(DEB_LEV_SIMPLE_SEQ, "Set state to ");
00254 switch ((int)Data2) {
00255 case OMX_StateInvalid:
00256 DEBUG(DEB_LEV_SIMPLE_SEQ, "OMX_StateInvalid\n");
00257 break;
00258 case OMX_StateLoaded:
00259 DEBUG(DEB_LEV_SIMPLE_SEQ, "OMX_StateLoaded\n");
00260 break;
00261 case OMX_StateIdle:
00262 DEBUG(DEB_LEV_SIMPLE_SEQ, "OMX_StateIdle\n");
00263 break;
00264 case OMX_StateExecuting:
00265 DEBUG(DEB_LEV_SIMPLE_SEQ, "OMX_StateExecuting\n");
00266 break;
00267 case OMX_StatePause:
00268 DEBUG(DEB_LEV_SIMPLE_SEQ, "OMX_StatePause\n");
00269 break;
00270 case OMX_StateWaitForResources:
00271 DEBUG(DEB_LEV_SIMPLE_SEQ, "OMX_StateWaitForResources\n");
00272 break;
00273 }
00274 tsem_up(appPriv->fbsinkEventSem);
00275 }
00276 }
00277
00278 DEBUG(DEB_LEV_FUNCTION_NAME, "Out of %s, return code: 0x%X\n",__func__, OMX_ErrorNone);
00279 return OMX_ErrorNone;
00280 }
00281
00282
00283 OMX_ERRORTYPE fbsinkEmptyBufferDone(
00284 OMX_OUT OMX_HANDLETYPE hComponent,
00285 OMX_OUT OMX_PTR pAppData,
00286 OMX_OUT OMX_BUFFERHEADERTYPE* pBuffer) {
00287
00288 DEBUG(DEB_LEV_FUNCTION_NAME, "In %s\n",__func__);
00289
00290 DEBUG(DEB_LEV_SIMPLE_SEQ, "%s: Get returned buffer (0x%lX) from fbsink input port, nFilledLen=%ld\n", __func__, (OMX_U32)pBuffer, pBuffer->nFilledLen);
00291
00292
00293 DEBUG(DEB_LEV_FUNCTION_NAME, "Out of %s, return code: 0x%X\n",__func__, OMX_ErrorNone);
00294 return OMX_ErrorNone;
00295 }
00296
00297
00298 OMX_ERRORTYPE setHeader(OMX_PTR header, OMX_U32 size) {
00299 OMX_VERSIONTYPE* ver = (OMX_VERSIONTYPE*)(header + sizeof(OMX_U32));
00300 *((OMX_U32*)header) = size;
00301
00302 ver->s.nVersionMajor = VERSIONMAJOR;
00303 ver->s.nVersionMinor = VERSIONMINOR;
00304 ver->s.nRevision = VERSIONREVISION;
00305 ver->s.nStep = VERSIONSTEP;
00306
00307 return OMX_ErrorNone;
00308 }
00309
00310
00311 OMX_ERRORTYPE setCameraParameters(OMX_BOOL bCameraStillImageMode) {
00312 OMX_ERRORTYPE errRet = OMX_ErrorNone;
00313 OMX_ERRORTYPE err = OMX_ErrorNone;
00314 OMX_PARAM_SENSORMODETYPE sOmxSensorMode;
00315 OMX_PARAM_PORTDEFINITIONTYPE sOmxPortDefinition;
00316
00317
00318 setHeader(&sOmxSensorMode, sizeof(OMX_PARAM_SENSORMODETYPE));
00319 sOmxSensorMode.nPortIndex = 0;
00320 setHeader(&sOmxSensorMode.sFrameSize, sizeof(OMX_FRAMESIZETYPE));
00321 sOmxSensorMode.sFrameSize.nPortIndex = 0;
00322 if ((err = OMX_GetParameter(appPriv->camerahandle, OMX_IndexParamCommonSensorMode, &sOmxSensorMode)) != OMX_ErrorNone) {
00323 errRet = err;
00324 }
00325 else {
00326 sOmxSensorMode.nFrameRate = DEFAULT_FRAME_RATE;
00327 sOmxSensorMode.bOneShot = bCameraStillImageMode;
00328 sOmxSensorMode.sFrameSize.nWidth = DEFAULT_FRAME_WIDTH;
00329 sOmxSensorMode.sFrameSize.nHeight = DEFAULT_FRAME_HEIGHT;
00330 if ((err = OMX_SetParameter(appPriv->camerahandle, OMX_IndexParamCommonSensorMode, &sOmxSensorMode)) != OMX_ErrorNone) {
00331 errRet = err;
00332 }
00333 }
00334
00335
00336 setHeader(&sOmxPortDefinition, sizeof(OMX_PARAM_PORTDEFINITIONTYPE));
00337 sOmxPortDefinition.nPortIndex = OMX_CAMPORT_INDEX_VF;
00338 if ((err = OMX_GetParameter(appPriv->camerahandle, OMX_IndexParamPortDefinition, &sOmxPortDefinition)) != OMX_ErrorNone) {
00339 errRet = err;
00340 }
00341 else {
00342 sOmxPortDefinition.format.video.nFrameWidth = DEFAULT_FRAME_WIDTH;
00343 sOmxPortDefinition.format.video.nFrameHeight = DEFAULT_FRAME_HEIGHT;
00344 sOmxPortDefinition.format.video.nStride = DEFAULT_FRAME_WIDTH;
00345 sOmxPortDefinition.format.video.nSliceHeight = DEFAULT_FRAME_HEIGHT;
00346 sOmxPortDefinition.format.video.eCompressionFormat = OMX_VIDEO_CodingUnused;
00347 sOmxPortDefinition.format.video.eColorFormat = DEFAULT_CAMERA_COLOR_FORMAT;
00348 sOmxPortDefinition.nBufferSize = sOmxPortDefinition.format.video.nStride * sOmxPortDefinition.format.video.nFrameHeight * 3;
00349 if ((err = OMX_SetParameter(appPriv->camerahandle, OMX_IndexParamPortDefinition, &sOmxPortDefinition)) != OMX_ErrorNone) {
00350 errRet = err;
00351 }
00352 }
00353
00354
00355 setHeader(&sOmxPortDefinition, sizeof(OMX_PARAM_PORTDEFINITIONTYPE));
00356 sOmxPortDefinition.nPortIndex = OMX_CAMPORT_INDEX_CP;
00357 if ((err = OMX_GetParameter(appPriv->camerahandle, OMX_IndexParamPortDefinition, &sOmxPortDefinition)) != OMX_ErrorNone) {
00358 errRet = err;
00359 }
00360 else {
00361 sOmxPortDefinition.format.video.nFrameWidth = DEFAULT_FRAME_WIDTH;
00362 sOmxPortDefinition.format.video.nFrameHeight = DEFAULT_FRAME_HEIGHT;
00363 sOmxPortDefinition.format.video.nStride = DEFAULT_FRAME_WIDTH;
00364 sOmxPortDefinition.format.video.nSliceHeight = DEFAULT_FRAME_HEIGHT;
00365 sOmxPortDefinition.format.video.eCompressionFormat = OMX_VIDEO_CodingUnused;
00366 sOmxPortDefinition.format.video.eColorFormat = DEFAULT_CAMERA_COLOR_FORMAT;
00367 sOmxPortDefinition.nBufferSize = sOmxPortDefinition.format.video.nStride * sOmxPortDefinition.format.video.nFrameHeight * 3;
00368 if ((err = OMX_SetParameter(appPriv->camerahandle, OMX_IndexParamPortDefinition, &sOmxPortDefinition)) != OMX_ErrorNone) {
00369 errRet = err;
00370 }
00371 }
00372
00373
00374 setHeader(&sOmxPortDefinition, sizeof(OMX_PARAM_PORTDEFINITIONTYPE));
00375 sOmxPortDefinition.nPortIndex = OMX_CAMPORT_INDEX_CP_T;
00376 if ((err = OMX_GetParameter(appPriv->camerahandle, OMX_IndexParamPortDefinition, &sOmxPortDefinition)) != OMX_ErrorNone) {
00377 errRet = err;
00378 }
00379 else {
00380 sOmxPortDefinition.format.video.nFrameWidth = DEFAULT_FRAME_WIDTH;
00381 sOmxPortDefinition.format.video.nFrameHeight = DEFAULT_FRAME_HEIGHT;
00382 sOmxPortDefinition.format.video.nStride = DEFAULT_FRAME_WIDTH;
00383 sOmxPortDefinition.format.video.nSliceHeight = DEFAULT_FRAME_HEIGHT;
00384 sOmxPortDefinition.format.video.eCompressionFormat = OMX_VIDEO_CodingUnused;
00385 sOmxPortDefinition.format.video.eColorFormat = DEFAULT_CAMERA_COLOR_FORMAT;
00386 sOmxPortDefinition.nBufferSize = sOmxPortDefinition.format.video.nStride * sOmxPortDefinition.format.video.nFrameHeight * 3;
00387 if ((err = OMX_SetParameter(appPriv->camerahandle, OMX_IndexParamPortDefinition, &sOmxPortDefinition)) != OMX_ErrorNone) {
00388 errRet = err;
00389 }
00390 }
00391
00392
00393 return errRet;
00394 }
00395
00396 OMX_ERRORTYPE setColorConvParameters() {
00397 OMX_ERRORTYPE errRet = OMX_ErrorNone;
00398 OMX_ERRORTYPE err = OMX_ErrorNone;
00399 OMX_VIDEO_PARAM_PORTFORMATTYPE sVideoPortFormat;
00400 OMX_PARAM_PORTDEFINITIONTYPE sOmxPortDefinition;
00401
00402
00403 setHeader(&sVideoPortFormat, sizeof(OMX_VIDEO_PARAM_PORTFORMATTYPE));
00404 sVideoPortFormat.nPortIndex = 0;
00405 sVideoPortFormat.nIndex = 0;
00406 if ((err = OMX_GetParameter(appPriv->colorconvhandle, OMX_IndexParamVideoPortFormat, &sVideoPortFormat)) != OMX_ErrorNone) {
00407 DEBUG(DEB_LEV_ERR, "Getting colorconv input port video format failed!\n");
00408 errRet = err;
00409 }
00410 else {
00411 sVideoPortFormat.eCompressionFormat = OMX_VIDEO_CodingUnused;
00412 sVideoPortFormat.eColorFormat = DEFAULT_CAMERA_COLOR_FORMAT;
00413 sVideoPortFormat.xFramerate = 0;
00414 if ((err = OMX_SetParameter(appPriv->colorconvhandle, OMX_IndexParamVideoPortFormat, &sVideoPortFormat)) != OMX_ErrorNone) {
00415 DEBUG(DEB_LEV_ERR, "Setting colorconv input port video format failed!\n");
00416 errRet = err;
00417 }
00418 }
00419
00420 setHeader(&sOmxPortDefinition, sizeof(OMX_PARAM_PORTDEFINITIONTYPE));
00421 sOmxPortDefinition.nPortIndex = 0;
00422 if ((err = OMX_GetParameter(appPriv->colorconvhandle, OMX_IndexParamPortDefinition, &sOmxPortDefinition)) != OMX_ErrorNone) {
00423 DEBUG(DEB_LEV_ERR, "Getting colorconv input port parameters failed!\n");
00424 errRet = err;
00425 }
00426 else {
00427 sOmxPortDefinition.format.video.nFrameWidth = DEFAULT_FRAME_WIDTH;
00428 sOmxPortDefinition.format.video.nFrameHeight = DEFAULT_FRAME_HEIGHT;
00429 sOmxPortDefinition.format.video.nStride = DEFAULT_FRAME_WIDTH;
00430 sOmxPortDefinition.format.video.nSliceHeight = DEFAULT_FRAME_HEIGHT;
00431 sOmxPortDefinition.format.video.eCompressionFormat = OMX_VIDEO_CodingUnused;
00432 sOmxPortDefinition.format.video.eColorFormat = DEFAULT_CAMERA_COLOR_FORMAT;
00433 sOmxPortDefinition.nBufferSize = sOmxPortDefinition.format.video.nStride * sOmxPortDefinition.format.video.nFrameHeight * 3;
00434 if ((err = OMX_SetParameter(appPriv->colorconvhandle, OMX_IndexParamPortDefinition, &sOmxPortDefinition)) != OMX_ErrorNone) {
00435 DEBUG(DEB_LEV_ERR, "Setting colorconv input port parameters failed!\n");
00436 errRet = err;
00437 }
00438 }
00439
00440
00441 setHeader(&sVideoPortFormat, sizeof(OMX_VIDEO_PARAM_PORTFORMATTYPE));
00442 sVideoPortFormat.nPortIndex = 1;
00443 sVideoPortFormat.nIndex = 0;
00444 if ((err = OMX_GetParameter(appPriv->colorconvhandle, OMX_IndexParamVideoPortFormat, &sVideoPortFormat)) != OMX_ErrorNone) {
00445 DEBUG(DEB_LEV_ERR, "Getting colorconv input port video format failed!\n");
00446 errRet = err;
00447 }
00448 else {
00449 sVideoPortFormat.eCompressionFormat = OMX_VIDEO_CodingUnused;
00450 sVideoPortFormat.eColorFormat = DEFAULT_FBSINK_COLOR_FORMAT;
00451 sVideoPortFormat.xFramerate = 0;
00452 if ((err = OMX_SetParameter(appPriv->colorconvhandle, OMX_IndexParamVideoPortFormat, &sVideoPortFormat)) != OMX_ErrorNone) {
00453 DEBUG(DEB_LEV_ERR, "Setting colorconv input port video format failed!\n");
00454 errRet = err;
00455 }
00456 }
00457
00458 setHeader(&sOmxPortDefinition, sizeof(OMX_PARAM_PORTDEFINITIONTYPE));
00459 sOmxPortDefinition.nPortIndex = 1;
00460 if ((err = OMX_GetParameter(appPriv->colorconvhandle, OMX_IndexParamPortDefinition, &sOmxPortDefinition)) != OMX_ErrorNone) {
00461 DEBUG(DEB_LEV_ERR, "Getting colorconv input port parameters failed!\n");
00462 errRet = err;
00463 }
00464 else {
00465 sOmxPortDefinition.format.video.nFrameWidth = DEFAULT_FRAME_WIDTH;
00466 sOmxPortDefinition.format.video.nFrameHeight = DEFAULT_FRAME_HEIGHT;
00467 sOmxPortDefinition.format.video.nStride = DEFAULT_FRAME_WIDTH;
00468 sOmxPortDefinition.format.video.nSliceHeight = DEFAULT_FRAME_HEIGHT;
00469 sOmxPortDefinition.format.video.eCompressionFormat = OMX_VIDEO_CodingUnused;
00470 sOmxPortDefinition.format.video.eColorFormat = DEFAULT_FBSINK_COLOR_FORMAT;
00471 sOmxPortDefinition.nBufferSize = sOmxPortDefinition.format.video.nStride * sOmxPortDefinition.format.video.nFrameHeight * 3;
00472 if ((err = OMX_SetParameter(appPriv->colorconvhandle, OMX_IndexParamPortDefinition, &sOmxPortDefinition)) != OMX_ErrorNone) {
00473 DEBUG(DEB_LEV_ERR, "Setting colorconv input port parameters failed!\n");
00474 errRet = err;
00475 }
00476 }
00477
00478
00479
00480 return errRet;
00481 }
00482
00483
00484
00485 OMX_ERRORTYPE setFbsinkParameters() {
00486 OMX_ERRORTYPE errRet = OMX_ErrorNone;
00487 OMX_ERRORTYPE err = OMX_ErrorNone;
00488 OMX_VIDEO_PARAM_PORTFORMATTYPE sVideoPortFormat;
00489 OMX_PARAM_PORTDEFINITIONTYPE sOmxPortDefinition;
00490 OMX_CONFIG_RECTTYPE sConfigCrop;
00491 OMX_CONFIG_POINTTYPE sConfigOutputPosition;
00492
00493
00494 setHeader(&sVideoPortFormat, sizeof(OMX_VIDEO_PARAM_PORTFORMATTYPE));
00495 sVideoPortFormat.nPortIndex = 0;
00496 sVideoPortFormat.nIndex = 0;
00497 if ((err = OMX_GetParameter(appPriv->fbsinkhandle, OMX_IndexParamVideoPortFormat, &sVideoPortFormat)) != OMX_ErrorNone) {
00498 DEBUG(DEB_LEV_ERR, "Getting fbsink input port video format failed!\n");
00499 errRet = err;
00500 }
00501 else {
00502 sVideoPortFormat.eCompressionFormat = OMX_VIDEO_CodingUnused;
00503 sVideoPortFormat.eColorFormat = DEFAULT_FBSINK_COLOR_FORMAT;
00504 sVideoPortFormat.xFramerate = 0;
00505 if ((err = OMX_SetParameter(appPriv->fbsinkhandle, OMX_IndexParamVideoPortFormat, &sVideoPortFormat)) != OMX_ErrorNone) {
00506 DEBUG(DEB_LEV_ERR, "Setting fbsink input port video format failed!\n");
00507 errRet = err;
00508 }
00509 }
00510
00511 setHeader(&sOmxPortDefinition, sizeof(OMX_PARAM_PORTDEFINITIONTYPE));
00512 sOmxPortDefinition.nPortIndex = 0;
00513 if ((err = OMX_GetParameter(appPriv->fbsinkhandle, OMX_IndexParamPortDefinition, &sOmxPortDefinition)) != OMX_ErrorNone) {
00514 DEBUG(DEB_LEV_ERR, "Getting fbsink input port parameters failed!\n");
00515 errRet = err;
00516 }
00517 else {
00518 sOmxPortDefinition.format.video.nFrameWidth = DEFAULT_FRAME_WIDTH;
00519 sOmxPortDefinition.format.video.nFrameHeight = DEFAULT_FRAME_HEIGHT;
00520 sOmxPortDefinition.format.video.nStride = DEFAULT_FRAME_WIDTH;
00521 sOmxPortDefinition.format.video.nSliceHeight = DEFAULT_FRAME_HEIGHT;
00522 sOmxPortDefinition.format.video.eCompressionFormat = OMX_VIDEO_CodingUnused;
00523 sOmxPortDefinition.format.video.eColorFormat = DEFAULT_FBSINK_COLOR_FORMAT;
00524 sOmxPortDefinition.nBufferSize = sOmxPortDefinition.format.video.nStride * sOmxPortDefinition.format.video.nFrameHeight * 3;
00525 if ((err = OMX_SetParameter(appPriv->fbsinkhandle, OMX_IndexParamPortDefinition, &sOmxPortDefinition)) != OMX_ErrorNone) {
00526 DEBUG(DEB_LEV_ERR, "Setting fbsink input port parameters failed!\n");
00527 errRet = err;
00528 }
00529 }
00530
00531
00532 setHeader(&sConfigCrop, sizeof(OMX_CONFIG_RECTTYPE));
00533 sConfigCrop.nPortIndex = 0;
00534 if ((err = OMX_GetConfig(appPriv->fbsinkhandle, OMX_IndexConfigCommonInputCrop, &sConfigCrop)) != OMX_ErrorNone) {
00535 DEBUG(DEB_LEV_ERR, "Getting fbsink input port Crop config failed!\n");
00536 errRet = err;
00537 }
00538 else {
00539 sConfigCrop.nLeft = 0;
00540 sConfigCrop.nTop = 0;
00541 sConfigCrop.nWidth = DEFAULT_FRAME_WIDTH;
00542 sConfigCrop.nHeight = DEFAULT_FRAME_HEIGHT;
00543 if ((err = OMX_SetConfig(appPriv->fbsinkhandle, OMX_IndexConfigCommonInputCrop, &sConfigCrop)) != OMX_ErrorNone) {
00544 DEBUG(DEB_LEV_ERR, "Setting fbsink input port Crop config failed!\n");
00545 errRet = err;
00546 }
00547 }
00548
00549
00550
00551 setHeader(&sConfigOutputPosition, sizeof(OMX_CONFIG_POINTTYPE));
00552 sConfigOutputPosition.nPortIndex = 0;
00553 if ((err = OMX_GetConfig(appPriv->fbsinkhandle, OMX_IndexConfigCommonOutputPosition, &sConfigOutputPosition)) != OMX_ErrorNone) {
00554 DEBUG(DEB_LEV_ERR, "Getting fbsink output port Position config failed!\n");
00555 errRet = err;
00556 }
00557 else {
00558 sConfigOutputPosition.nX = 0;
00559 sConfigOutputPosition.nY = 0;
00560 if ((err = OMX_SetConfig(appPriv->fbsinkhandle, OMX_IndexConfigCommonOutputPosition, &sConfigOutputPosition)) != OMX_ErrorNone) {
00561 DEBUG(DEB_LEV_ERR, "Setting fbsink output port Position config failed!\n");
00562 errRet = err;
00563 }
00564 }
00565
00566
00567 return errRet;
00568 }
00569
00570
00571 void display_help(char* cSelfName) {
00572 fprintf(stdout, "\n");
00573 fprintf(stdout, "Usage: %s [-h] [-i] [-p] [-t preview_time] [-s capture_time] [-c capture_file] [-m thumbnail_file] [-n run_count]\n", cSelfName);
00574 fprintf(stdout, "\n");
00575 fprintf(stdout, " -i: If this option is specified, the camera will be running in still image capture mode\n");
00576 fprintf(stdout, " Else, the camera will be running in video capture mode by default\n");
00577 fprintf(stdout, "\n");
00578 fprintf(stdout, " -p: If this option is specified, the camera will be running in autopause mode\n");
00579 fprintf(stdout, " Else, the camera will not be in autopause mode by default\n");
00580 fprintf(stdout, "\n");
00581 fprintf(stdout, " -t preview_time: If this option is specified, the camera will stay in preview state for \"preview_time\" seconds\n");
00582 fprintf(stdout, " Else, the camera will preview for 5 seconds by default\n");
00583 fprintf(stdout, "\n");
00584 fprintf(stdout, " -s capture_time: After preview, the camera will start capturing videos\n");
00585 fprintf(stdout, " If this option is specified, the camera will stay in video-capture state for \"capture_time\" seconds\n");
00586 fprintf(stdout, " Else, the camera will capture videos for 5 seconds by default\n");
00587 fprintf(stdout, "\n");
00588 fprintf(stdout, " -c capture_file: If this option is specified, the camera captured videos will be saved in file \"capture_file\"\n");
00589 fprintf(stdout, " Else, captured videos will be saved in file \"%s\" by default\n", g_DefaultCaptureFileName);
00590 fprintf(stdout, "\n");
00591 fprintf(stdout, " -m thumbnail_file: If this option is specified, the camera thumbnail/snapshot image will be saved in file \"thumbnail_file\"\n");
00592 fprintf(stdout, " Else, thumbnail image will be saved in file \"%s\" by default\n", g_DefaultThumbnailFileName);
00593 fprintf(stdout, "\n");
00594 fprintf(stdout, " -n run_count: If this option is specified, this test app will run for \"run_count\" times\n");
00595 fprintf(stdout, " Else, run only once by default\n");
00596 fprintf(stdout, "\n");
00597 fprintf(stdout, " -h: Displays this help\n");
00598 fprintf(stdout, "\n");
00599 }
00600
00601
00602 int main(int argc, char** argv) {
00603 OMX_ERRORTYPE err = OMX_ErrorNone;
00604 OMX_BOOL bOmxInitialized = OMX_FALSE;
00605 OMX_PARAM_PORTDEFINITIONTYPE sOmxPortDefinition;
00606 OMX_CONFIG_BOOLEANTYPE sOmxCapturing;
00607 OMX_CONFIG_BOOLEANTYPE sOmxAutoPause;
00608 OMX_STATETYPE sOmxState;
00609 OMX_U32 nBufferCount;
00610 OMX_U32 nBufferSize;
00611 OMX_U32 nPortIndex;
00612 OMX_U32 i;
00613 unsigned int nPreviewTime = 5;
00614 unsigned int nCaptureTime = 5;
00615 char *cCaptureFileName = g_DefaultCaptureFileName;
00616 char *cThumbnailFileName = g_DefaultThumbnailFileName;
00617 OMX_BOOL bCameraStillImageMode = OMX_FALSE;
00618 OMX_BOOL bCameraAutoPause = OMX_FALSE;
00619 unsigned int nMaxRunCount = 1;
00620 unsigned int nRunCount = 0;
00621
00622
00623 for ( i = 1; i < argc && argv[i][0] == '-'; i++) {
00624 switch (argv[i][1]) {
00625 case 'i':
00626 bCameraStillImageMode = OMX_TRUE;
00627 break;
00628
00629 case 'p':
00630 bCameraAutoPause = OMX_TRUE;
00631 break;
00632
00633 case 't':
00634 i++;
00635 if (i>=argc ||argv[i][0] == '-') {
00636 DEBUG(DEB_LEV_ERR, "preview_time expected!\n");
00637 display_help(argv[0]);
00638 exit(-1);
00639 }
00640 nPreviewTime = (unsigned int)atoi(argv[i]);
00641 break;
00642
00643 case 's':
00644 i++;
00645 if (i>=argc ||argv[i][0] == '-') {
00646 DEBUG(DEB_LEV_ERR, "capture_time expected!\n");
00647 display_help(argv[0]);
00648 exit(-1);
00649 }
00650 nCaptureTime = (unsigned int)atoi(argv[i]);
00651 break;
00652
00653 case 'c':
00654 i++;
00655 if (i>=argc ||argv[i][0] == '-') {
00656 DEBUG(DEB_LEV_ERR, "capture_file expected!\n");
00657 display_help(argv[0]);
00658 exit(-1);
00659 }
00660 cCaptureFileName = argv[i];
00661 break;
00662
00663 case 'm':
00664 i++;
00665 if (i>=argc ||argv[i][0] == '-') {
00666 DEBUG(DEB_LEV_ERR, "thumbnail_file expected!\n");
00667 display_help(argv[0]);
00668 exit(-1);
00669 }
00670 cThumbnailFileName = argv[i];
00671 break;
00672
00673 case 'n':
00674 i++;
00675 if (i>=argc ||argv[i][0] == '-') {
00676 DEBUG(DEB_LEV_ERR, "run_count expected!\n");
00677 display_help(argv[0]);
00678 exit(-1);
00679 }
00680 nMaxRunCount = (unsigned int)atoi(argv[i]);
00681 break;
00682
00683 case 'h':
00684 display_help(argv[0]);
00685 exit(0);
00686 break;
00687
00688 default:
00689 DEBUG(DEB_LEV_ERR, "Unrecognized option -%c!\n", argv[i][1]);
00690 display_help(argv[0]);
00691 exit(-1);
00692 }
00693 }
00694
00695
00696
00697 DEBUG(DEB_LEV_SIMPLE_SEQ, "Init the OMX core\n");
00698 if ((err = OMX_Init()) != OMX_ErrorNone) {
00699 DEBUG(DEB_LEV_ERR, "The OpenMAX core can not be initialized. Exiting...\n");
00700 goto EXIT;
00701 }
00702 bOmxInitialized = OMX_TRUE;
00703
00704
00705 appPriv = (appPrivateType *)malloc(sizeof(appPrivateType));
00706 if (appPriv == NULL) {
00707 DEBUG(DEB_LEV_ERR, "Allocate app private data failed!Exiting...\n");
00708 err = OMX_ErrorInsufficientResources;
00709 goto EXIT;
00710 }
00711 memset(appPriv, 0, sizeof(appPrivateType));
00712
00713 memset(&sCameraPortBufferList, 0, NUM_CAMERAPORTS*sizeof(OMX_PORTBUFFERCTXT));
00714
00715
00716 fCapture=fopen(cCaptureFileName, "wb");
00717 fThumbnail=fopen(cThumbnailFileName, "wb");
00718
00719
00720
00721 if ((err = OMX_GetHandle(&appPriv->camerahandle, "OMX.st.v4l.camera_source", appPriv, &camera_source_callbacks)) != OMX_ErrorNone) {
00722 DEBUG(DEB_LEV_ERR, "Getting camera component handle failed!Exiting...\n");
00723 goto EXIT;
00724 }
00725
00726
00727 if ((err = OMX_GetHandle(&appPriv->colorconvhandle, "OMX.st.video_colorconv.ffmpeg", appPriv, &colorconv_callbacks)) != OMX_ErrorNone) {
00728 DEBUG(DEB_LEV_ERR, "Getting color conv component handle failed!Exiting...\n");
00729 goto EXIT;
00730 }
00731
00732
00733 if ((err = OMX_GetHandle(&appPriv->fbsinkhandle, "OMX.st.fbdev.fbdev_sink", appPriv, &fbsink_callbacks)) != OMX_ErrorNone) {
00734 DEBUG(DEB_LEV_ERR, "Getting fbsink component handle failed!Exiting...\n");
00735 goto EXIT;
00736 }
00737
00738
00739 if ((err = setCameraParameters(bCameraStillImageMode)) != OMX_ErrorNone) {
00740 DEBUG(DEB_LEV_ERR, "Set camera parameters failed! Use default settings...\n");
00741
00742 }
00743
00744
00745 if ((err = setColorConvParameters()) != OMX_ErrorNone) {
00746 DEBUG(DEB_LEV_ERR, "Set fbsink parameters failed! Use default settings...\n");
00747
00748 }
00749
00750
00751
00752 if ((err = setFbsinkParameters()) != OMX_ErrorNone) {
00753 DEBUG(DEB_LEV_ERR, "Set fbsink parameters failed! Use default settings...\n");
00754
00755 }
00756
00757
00758 appPriv->cameraSourceEventSem = (tsem_t *)malloc(sizeof(tsem_t));
00759 if (appPriv->cameraSourceEventSem == NULL) {
00760 DEBUG(DEB_LEV_ERR, "Allocate camera event semaphore failed!Exiting...\n");
00761 err = OMX_ErrorInsufficientResources;
00762 goto EXIT;
00763 }
00764 tsem_init(appPriv->cameraSourceEventSem, 0);
00765
00766 appPriv->fbsinkEventSem = (tsem_t *)malloc(sizeof(tsem_t));
00767 if (appPriv->fbsinkEventSem == NULL) {
00768 DEBUG(DEB_LEV_ERR, "Allocate fbsink event semaphore failed!Exiting...\n");
00769 err = OMX_ErrorInsufficientResources;
00770 goto EXIT;
00771 }
00772 tsem_init(appPriv->fbsinkEventSem, 0);
00773
00774 appPriv->colorconvEventSem = (tsem_t *)malloc(sizeof(tsem_t));
00775 if (appPriv->colorconvEventSem == NULL) {
00776 DEBUG(DEB_LEV_ERR, "Allocate colorconv event semaphore failed!Exiting...\n");
00777 err = OMX_ErrorInsufficientResources;
00778 goto EXIT;
00779 }
00780 tsem_init(appPriv->colorconvEventSem, 0);
00781
00782
00783 if ((err = OMX_SetupTunnel(appPriv->camerahandle, OMX_CAMPORT_INDEX_VF, appPriv->colorconvhandle, 0)) != OMX_ErrorNone) {
00784 DEBUG(DEB_LEV_ERR, "Setup tunnel between camera preview port and color converter failed!Exiting...\n");
00785 goto EXIT;
00786 }
00787 if ((err = OMX_SetupTunnel(appPriv->colorconvhandle, 1, appPriv->fbsinkhandle, 0)) != OMX_ErrorNone) {
00788 DEBUG(DEB_LEV_ERR, "Setup tunnel between color conv port and fbsink failed!Exiting...\n");
00789 goto EXIT;
00790 }
00791
00792 RUN_AGAIN:
00793
00794
00795 if ((err = OMX_SendCommand(appPriv->camerahandle, OMX_CommandStateSet, OMX_StateIdle, NULL)) != OMX_ErrorNone) {
00796 DEBUG(DEB_LEV_ERR, "Camera Loaded-->Idle failed!Exiting...\n");
00797 goto EXIT;
00798 }
00799
00800
00801 if ((err = OMX_SendCommand(appPriv->colorconvhandle, OMX_CommandStateSet, OMX_StateIdle, NULL)) != OMX_ErrorNone) {
00802 DEBUG(DEB_LEV_ERR, "Color Conv Loaded-->Idle failed!Exiting...\n");
00803 goto EXIT;
00804 }
00805
00806
00807 if ((err = OMX_SendCommand(appPriv->fbsinkhandle, OMX_CommandStateSet, OMX_StateIdle, NULL)) != OMX_ErrorNone) {
00808 DEBUG(DEB_LEV_ERR, "Fbsink Loaded-->Idle failed!Exiting...\n");
00809 goto EXIT;
00810 }
00811
00812
00813 for (nPortIndex = OMX_CAMPORT_INDEX_CP; nPortIndex <= OMX_CAMPORT_INDEX_CP_T; nPortIndex++) {
00814 setHeader(&sOmxPortDefinition, sizeof(OMX_PARAM_PORTDEFINITIONTYPE));
00815 sOmxPortDefinition.nPortIndex = nPortIndex;
00816 if ((err = OMX_GetParameter(appPriv->camerahandle, OMX_IndexParamPortDefinition, &sOmxPortDefinition)) != OMX_ErrorNone) {
00817 DEBUG(DEB_LEV_ERR, "OMX_GetParameter for camera on OMX_IndexParamPortDefinition index failed!Exiting...\n");
00818 goto EXIT;
00819 }
00820 nBufferCount = sOmxPortDefinition.nBufferCountActual;
00821 nBufferSize = sOmxPortDefinition.nBufferSize;
00822 DEBUG(DEB_LEV_SIMPLE_SEQ, "Camera port[%ld] needs %ld buffers each of which is %ld bytes\n", nPortIndex, nBufferCount, nBufferSize);
00823
00824 for (i = 0; i < nBufferCount; i++) {
00825 if ((err = OMX_AllocateBuffer(appPriv->camerahandle, &sCameraPortBufferList[nPortIndex].pBufHeaderList[i], nPortIndex, NULL, nBufferSize)) != OMX_ErrorNone) {
00826 DEBUG(DEB_LEV_ERR, "Allocate port buffer for camera failed!Exiting...\n");
00827 goto EXIT;
00828 }
00829 sCameraPortBufferList[nPortIndex].nBufferCountActual++;
00830 }
00831 }
00832
00833
00834 tsem_down(appPriv->cameraSourceEventSem);
00835
00836 tsem_down(appPriv->colorconvEventSem);
00837
00838 tsem_down(appPriv->fbsinkEventSem);
00839
00840
00841
00842
00843 if ((err = OMX_SendCommand(appPriv->camerahandle, OMX_CommandStateSet, OMX_StateExecuting, NULL)) != OMX_ErrorNone) {
00844 DEBUG(DEB_LEV_ERR, "Camera Idle-->Exec failed!Exiting...\n");
00845 goto EXIT;
00846 }
00847
00848
00849 if ((err = OMX_SendCommand(appPriv->colorconvhandle, OMX_CommandStateSet, OMX_StateExecuting, NULL)) != OMX_ErrorNone) {
00850 DEBUG(DEB_LEV_ERR, "Colorconv Idle-->Exec failed!Exiting...\n");
00851 goto EXIT;
00852 }
00853
00854
00855 if ((err = OMX_SendCommand(appPriv->fbsinkhandle, OMX_CommandStateSet, OMX_StateExecuting, NULL)) != OMX_ErrorNone) {
00856 DEBUG(DEB_LEV_ERR, "Fbsink Idle-->Exec failed!Exiting...\n");
00857 goto EXIT;
00858 }
00859
00860
00861 tsem_down(appPriv->cameraSourceEventSem);
00862
00863 tsem_down(appPriv->colorconvEventSem);
00864
00865 tsem_down(appPriv->fbsinkEventSem);
00866
00867
00868 fprintf(stdout, "Start preview, for %d sec...\n", nPreviewTime);
00869 sleep(nPreviewTime);
00870
00871
00872 for (i = 0; i < sCameraPortBufferList[OMX_CAMPORT_INDEX_CP].nBufferCountActual; i++) {
00873 sCameraPortBufferList[OMX_CAMPORT_INDEX_CP].pBufHeaderList[i]->nFilledLen = 0;
00874 sCameraPortBufferList[OMX_CAMPORT_INDEX_CP].pBufHeaderList[i]->nOffset = 0;
00875 if ((err = OMX_FillThisBuffer(appPriv->camerahandle, sCameraPortBufferList[OMX_CAMPORT_INDEX_CP].pBufHeaderList[i])) != OMX_ErrorNone) {
00876 DEBUG(DEB_LEV_ERR, "Fill buffer to camera capture port failed!Exiting...\n");
00877 goto EXIT;
00878 }
00879 DEBUG(DEB_LEV_SIMPLE_SEQ, "%s: Fill buffer[%ld] (0x%lX) to camera capture port\n", __func__, i, (OMX_U32)sCameraPortBufferList[OMX_CAMPORT_INDEX_CP].pBufHeaderList[i]);
00880 }
00881
00882
00883 for (i = 0; i < sCameraPortBufferList[OMX_CAMPORT_INDEX_CP_T].nBufferCountActual; i++) {
00884 sCameraPortBufferList[OMX_CAMPORT_INDEX_CP_T].pBufHeaderList[i]->nFilledLen = 0;
00885 sCameraPortBufferList[OMX_CAMPORT_INDEX_CP_T].pBufHeaderList[i]->nOffset = 0;
00886 if ((err = OMX_FillThisBuffer(appPriv->camerahandle, sCameraPortBufferList[OMX_CAMPORT_INDEX_CP_T].pBufHeaderList[i])) != OMX_ErrorNone) {
00887 DEBUG(DEB_LEV_ERR, "Fill buffer to camera capture port failed!Exiting...\n");
00888 goto EXIT;
00889 }
00890 DEBUG(DEB_LEV_SIMPLE_SEQ, "%s: Fill buffer[%ld] (0x%lX) to camera capture port\n", __func__, i, (OMX_U32)sCameraPortBufferList[OMX_CAMPORT_INDEX_CP_T].pBufHeaderList[i]);
00891 }
00892
00893
00894 setHeader(&sOmxAutoPause, sizeof(OMX_CONFIG_BOOLEANTYPE));
00895 sOmxAutoPause.bEnabled = bCameraAutoPause;
00896 if ((err = OMX_SetConfig(appPriv->camerahandle, OMX_IndexAutoPauseAfterCapture, &sOmxAutoPause)) != OMX_ErrorNone) {
00897 DEBUG(DEB_LEV_ERR, "Set autopause mode failed!Use default settings...\n");
00898
00899 }
00900
00901
00902 setHeader(&sOmxCapturing, sizeof(OMX_CONFIG_BOOLEANTYPE));
00903 sOmxCapturing.bEnabled = OMX_TRUE;
00904 if ((err = OMX_SetConfig(appPriv->camerahandle, OMX_IndexConfigCapturing, &sOmxCapturing)) != OMX_ErrorNone) {
00905 DEBUG(DEB_LEV_ERR, "Start capturing failed!Exiting...\n");
00906 goto EXIT;
00907 }
00908
00909 fprintf(stdout, "Start capturing, for %d sec...\n", nCaptureTime);
00910 sleep(nCaptureTime);
00911
00912
00913 if (!bCameraStillImageMode) {
00914 setHeader(&sOmxCapturing, sizeof(OMX_CONFIG_BOOLEANTYPE));
00915 sOmxCapturing.bEnabled = OMX_FALSE;
00916 if ((err = OMX_SetConfig(appPriv->camerahandle, OMX_IndexConfigCapturing, &sOmxCapturing)) != OMX_ErrorNone) {
00917 DEBUG(DEB_LEV_ERR, "Stop capturing failed!Exiting...\n");
00918 goto EXIT;
00919 }
00920 fprintf(stdout, "Stop capturing...\n");
00921 }
00922
00923
00924 if (bCameraAutoPause) {
00925 fprintf(stdout, "Now the camera is in autopause mode, wait for %d sec before out of this mode...\n", 5);
00926 sleep(5);
00927
00928 if ((err = OMX_GetState(appPriv->camerahandle,&sOmxState)) != OMX_ErrorNone) {
00929 DEBUG(DEB_LEV_ERR, "Get camera state failed!Exiting...\n");
00930 goto EXIT;
00931 }
00932 if (sOmxState == OMX_StatePause) {
00933 if ((err = OMX_SendCommand(appPriv->camerahandle, OMX_CommandStateSet,
00934 OMX_StateExecuting, 0 )) != OMX_ErrorNone ) {
00935 DEBUG(DEB_LEV_ERR, "Pause-->Exec failed!Exiting...\n");
00936 goto EXIT;
00937 }
00938
00939 tsem_down(appPriv->cameraSourceEventSem);
00940 fprintf(stdout, "Now the camera is out of autopause mode, wait for %d sec before exit...\n", 5);
00941 sleep(5);
00942 }
00943 else {
00944 DEBUG(DEB_LEV_ERR, "The camera is not in Pause state in autopause mode, ignore...\n");
00945 }
00946 }
00947
00948
00949 if ((err = OMX_SendCommand(appPriv->camerahandle, OMX_CommandStateSet, OMX_StateIdle, NULL)) != OMX_ErrorNone) {
00950 DEBUG(DEB_LEV_ERR, "Camera Exec-->Idle failed!Exiting...\n");
00951 goto EXIT;
00952 }
00953
00954
00955 if ((err = OMX_SendCommand(appPriv->colorconvhandle, OMX_CommandStateSet, OMX_StateIdle, NULL)) != OMX_ErrorNone) {
00956 DEBUG(DEB_LEV_ERR, "Color conv Exec-->Idle failed!Exiting...\n");
00957 goto EXIT;
00958 }
00959
00960
00961 if ((err = OMX_SendCommand(appPriv->fbsinkhandle, OMX_CommandStateSet, OMX_StateIdle, NULL)) != OMX_ErrorNone) {
00962 DEBUG(DEB_LEV_ERR, "Fbsink Exec-->Idle failed!Exiting...\n");
00963 goto EXIT;
00964 }
00965
00966
00967 tsem_down(appPriv->cameraSourceEventSem);
00968
00969 tsem_down(appPriv->colorconvEventSem);
00970
00971 tsem_down(appPriv->fbsinkEventSem);
00972
00973
00974
00975 if ((err = OMX_SendCommand(appPriv->camerahandle, OMX_CommandStateSet, OMX_StateExecuting, NULL)) != OMX_ErrorNone) {
00976 DEBUG(DEB_LEV_ERR, "Camera Idle-->Exec failed!Exiting...\n");
00977 goto EXIT;
00978 }
00979
00980
00981 if ((err = OMX_SendCommand(appPriv->colorconvhandle, OMX_CommandStateSet, OMX_StateExecuting, NULL)) != OMX_ErrorNone) {
00982 DEBUG(DEB_LEV_ERR, "Colorconv Idle-->Exec failed!Exiting...\n");
00983 goto EXIT;
00984 }
00985
00986
00987 if ((err = OMX_SendCommand(appPriv->fbsinkhandle, OMX_CommandStateSet, OMX_StateExecuting, NULL)) != OMX_ErrorNone) {
00988 DEBUG(DEB_LEV_ERR, "Fbsink Idle-->Exec failed!Exiting...\n");
00989 goto EXIT;
00990 }
00991
00992
00993 tsem_down(appPriv->cameraSourceEventSem);
00994
00995 tsem_down(appPriv->colorconvEventSem);
00996
00997 tsem_down(appPriv->fbsinkEventSem);
00998
00999 fprintf(stdout, "Continue to preview, for %d sec...\n", nPreviewTime);
01000 sleep(nPreviewTime);
01001
01002
01003 if ((err = OMX_SendCommand(appPriv->camerahandle, OMX_CommandStateSet, OMX_StateIdle, NULL)) != OMX_ErrorNone) {
01004 DEBUG(DEB_LEV_ERR, "Camera Exec-->Idle failed!Exiting...\n");
01005 goto EXIT;
01006 }
01007
01008
01009 if ((err = OMX_SendCommand(appPriv->colorconvhandle, OMX_CommandStateSet, OMX_StateIdle, NULL)) != OMX_ErrorNone) {
01010 DEBUG(DEB_LEV_ERR, "Color conv Exec-->Idle failed!Exiting...\n");
01011 goto EXIT;
01012 }
01013
01014
01015 if ((err = OMX_SendCommand(appPriv->fbsinkhandle, OMX_CommandStateSet, OMX_StateIdle, NULL)) != OMX_ErrorNone) {
01016 DEBUG(DEB_LEV_ERR, "Fbsink Exec-->Idle failed!Exiting...\n");
01017 goto EXIT;
01018 }
01019
01020
01021
01022 tsem_down(appPriv->cameraSourceEventSem);
01023
01024 tsem_down(appPriv->colorconvEventSem);
01025
01026 tsem_down(appPriv->fbsinkEventSem);
01027
01028
01029
01030 if ((err = OMX_SendCommand(appPriv->camerahandle, OMX_CommandStateSet, OMX_StateLoaded, NULL)) != OMX_ErrorNone) {
01031 DEBUG(DEB_LEV_ERR, "Camera Idle-->Loaded failed!Exiting...\n");
01032 goto EXIT;
01033 }
01034
01035
01036 if ((err = OMX_SendCommand(appPriv->colorconvhandle, OMX_CommandStateSet, OMX_StateLoaded, NULL)) != OMX_ErrorNone) {
01037 DEBUG(DEB_LEV_ERR, "Color conv Exec-->Idle failed!Exiting...\n");
01038 goto EXIT;
01039 }
01040
01041
01042 if ((err = OMX_SendCommand(appPriv->fbsinkhandle, OMX_CommandStateSet, OMX_StateLoaded, NULL)) != OMX_ErrorNone) {
01043 DEBUG(DEB_LEV_ERR, "Fbsink Idle-->Loaded failed!Exiting...\n");
01044 goto EXIT;
01045 }
01046
01047
01048 for (nPortIndex = OMX_CAMPORT_INDEX_CP; nPortIndex <= OMX_CAMPORT_INDEX_CP_T; nPortIndex++) {
01049 for (i = 0; i < sCameraPortBufferList[nPortIndex].nBufferCountActual; i++) {
01050 if (sCameraPortBufferList[nPortIndex].pBufHeaderList[i] != NULL) {
01051 OMX_FreeBuffer(appPriv->camerahandle, nPortIndex, sCameraPortBufferList[nPortIndex].pBufHeaderList[i]);
01052 }
01053 }
01054 sCameraPortBufferList[nPortIndex].nBufferCountActual = 0;
01055 }
01056
01057
01058 tsem_down(appPriv->cameraSourceEventSem);
01059
01060 tsem_down(appPriv->colorconvEventSem);
01061
01062 tsem_down(appPriv->fbsinkEventSem);
01063
01064 nRunCount++;
01065 if (nRunCount < nMaxRunCount) {
01066 goto RUN_AGAIN;
01067 }
01068
01069 fprintf(stdout, "The captured videos are saved in file \"%s\"\n", cCaptureFileName);
01070 fprintf(stdout, "The thumbnail image is saved in file \"%s\"\n", cThumbnailFileName);
01071
01072 EXIT:
01073 if (fCapture != NULL) {
01074 fclose(fCapture);
01075 }
01076 if (fThumbnail != NULL) {
01077 fclose(fThumbnail);
01078 }
01079
01080
01081 if (appPriv != NULL) {
01082
01083 if (appPriv->cameraSourceEventSem != NULL) {
01084 tsem_deinit(appPriv->cameraSourceEventSem);
01085 free(appPriv->cameraSourceEventSem);
01086 }
01087
01088 if (appPriv->colorconvEventSem != NULL) {
01089 tsem_deinit(appPriv->colorconvEventSem);
01090 free(appPriv->colorconvEventSem);
01091 }
01092
01093 if (appPriv->fbsinkEventSem != NULL) {
01094 tsem_deinit(appPriv->fbsinkEventSem);
01095 free(appPriv->fbsinkEventSem);
01096 }
01097
01098
01099 if (appPriv->camerahandle != NULL) {
01100 OMX_FreeHandle(appPriv->camerahandle);
01101 }
01102
01103 if (appPriv->colorconvhandle != NULL) {
01104 OMX_FreeHandle(appPriv->colorconvhandle);
01105 }
01106
01107
01108 if (appPriv->fbsinkhandle != NULL) {
01109 OMX_FreeHandle(appPriv->fbsinkhandle);
01110 }
01111
01112 free(appPriv);
01113 }
01114
01115
01116 if (bOmxInitialized) {
01117 OMX_Deinit();
01118 }
01119
01120 return (int) err;
01121 }