summaryrefslogtreecommitdiffstats
path: root/camera
diff options
context:
space:
mode:
authorAkwasi Boateng <akwasi.boateng@ti.com>2011-11-01 10:43:52 -0500
committerIliyan Malchev <malchev@google.com>2011-12-01 10:40:03 -0800
commitc387abd774bbc0aa23314bb989c1dec23e588a22 (patch)
treef47d7722537da917942f1e3c933191b768df22c3 /camera
parent80a2eeb9c95c24e0dd69e61c3f58e6da36cf703d (diff)
downloadhardware_ti_omap4xxx-c387abd774bbc0aa23314bb989c1dec23e588a22.zip
hardware_ti_omap4xxx-c387abd774bbc0aa23314bb989c1dec23e588a22.tar.gz
hardware_ti_omap4xxx-c387abd774bbc0aa23314bb989c1dec23e588a22.tar.bz2
CameraHAL: Handling OMX initialization
Additional mOmxInitialized flag has been added to track whether OMX has been succesfully initialized to prevent duplicate OMX_DeInit() in OMXCameraAdapter destructor. Signed-off-by: Daniel Levin <x0155538@ti.com> Signed-off-by: Akwasi Boateng <akwasi.boateng@ti.com> Signed-off-by: Iliyan Malchev <malchev@google.com> Change-Id: I269c5ac9d5de3f3e9088a11a3bea7127c1bd79de
Diffstat (limited to 'camera')
-rwxr-xr-xcamera/OMXCameraAdapter/OMXCameraAdapter.cpp78
-rw-r--r--camera/inc/OMXCameraAdapter/OMXCameraAdapter.h1
2 files changed, 40 insertions, 39 deletions
diff --git a/camera/OMXCameraAdapter/OMXCameraAdapter.cpp b/camera/OMXCameraAdapter/OMXCameraAdapter.cpp
index edb97f8..a58ca45 100755
--- a/camera/OMXCameraAdapter/OMXCameraAdapter.cpp
+++ b/camera/OMXCameraAdapter/OMXCameraAdapter.cpp
@@ -78,12 +78,6 @@ status_t OMXCameraAdapter::initialize(CameraProperties::Properties* caps)
return NO_INIT;
}
- if (mComponentState != OMX_StateLoaded && mComponentState != OMX_StateInvalid) {
- CAMHAL_LOGEB("Error mComponentState %d is invalid!", mComponentState);
- LOG_FUNCTION_NAME_EXIT;
- return NO_INIT;
- }
-
///Update the preview and image capture port indexes
mCameraAdapterParameters.mPrevPortIndex = OMX_CAMERA_PORT_VIDEO_OUT_PREVIEW;
// temp changed in order to build OMX_CAMERA_PORT_VIDEO_OUT_IMAGE;
@@ -94,9 +88,10 @@ status_t OMXCameraAdapter::initialize(CameraProperties::Properties* caps)
eError = OMX_Init();
if (eError != OMX_ErrorNone) {
- CAMHAL_LOGEB("Error OMX_Init -0x%x", eError);
- return eError;
+ CAMHAL_LOGEB("OMX_Init() failed, error: 0x%x", eError);
+ return ErrorUtils::omxToAndroidError(eError);
}
+ mOmxInitialized = true;
///Get the handle to the OMX Component
eError = OMXCameraAdapter::OMXCameraGetHandle(&mCameraAdapterParameters.mHandleComp, (OMX_PTR)this);
@@ -105,6 +100,8 @@ status_t OMXCameraAdapter::initialize(CameraProperties::Properties* caps)
}
GOTO_EXIT_IF((eError != OMX_ErrorNone), eError);
+ mComponentState = OMX_StateLoaded;
+
CAMHAL_LOGVB("OMX_GetHandle -0x%x sensor_index = %lu", eError, mSensorIndex);
eError = OMX_SendCommand(mCameraAdapterParameters.mHandleComp,
OMX_CommandPortDisable,
@@ -176,7 +173,6 @@ status_t OMXCameraAdapter::initialize(CameraProperties::Properties* caps)
mRecording = false;
mWaitingForSnapshot = false;
mSnapshotCount = 0;
- mComponentState = OMX_StateLoaded;
mCapMode = HIGH_QUALITY;
mIPP = IPP_NULL;
@@ -3432,10 +3428,12 @@ OMX_OTHER_EXTRADATATYPE *OMXCameraAdapter::getExtradata(OMX_OTHER_EXTRADATATYPE
return NULL;
}
-OMXCameraAdapter::OMXCameraAdapter(size_t sensor_index): mComponentState (OMX_StateLoaded)
+OMXCameraAdapter::OMXCameraAdapter(size_t sensor_index)
{
LOG_FUNCTION_NAME;
+ mOmxInitialized = false;
+ mComponentState = OMX_StateInvalid;
mSensorIndex = sensor_index;
mPictureRotation = 0;
// Initial values
@@ -3475,22 +3473,22 @@ OMXCameraAdapter::~OMXCameraAdapter()
Mutex::Autolock lock(gAdapterLock);
- //Return to OMX Loaded state
- switchToLoaded();
+ if ( mOmxInitialized ) {
+ // return to OMX Loaded state
+ switchToLoaded();
- ///De-init the OMX
- if( (mComponentState==OMX_StateLoaded) || (mComponentState==OMX_StateInvalid))
- {
- ///Free the handle for the Camera component
- if(mCameraAdapterParameters.mHandleComp)
- {
- OMX_FreeHandle(mCameraAdapterParameters.mHandleComp);
- mCameraAdapterParameters.mHandleComp = NULL;
+ // deinit the OMX
+ if ( mComponentState == OMX_StateLoaded || mComponentState == OMX_StateInvalid ) {
+ // free the handle for the Camera component
+ if ( mCameraAdapterParameters.mHandleComp ) {
+ OMX_FreeHandle(mCameraAdapterParameters.mHandleComp);
+ mCameraAdapterParameters.mHandleComp = NULL;
}
-
- OMX_Deinit();
}
+ OMX_Deinit();
+ mOmxInitialized = false;
+ }
//Remove any unhandled events
if ( !mEventSignalQ.isEmpty() )
@@ -3560,28 +3558,30 @@ OMX_ERRORTYPE OMXCameraAdapter::OMXCameraGetHandle(OMX_HANDLETYPE *handle, OMX_P
{
OMX_ERRORTYPE eError = OMX_ErrorUndefined;
- int retries = 5;
- while(eError!=OMX_ErrorNone && --retries>=0) {
+ for ( int i = 0; i < 5; ++i ) {
+ if ( i > 0 ) {
+ // sleep for 100 ms before next attempt
+ usleep(100000);
+ }
- // Setup key parameters to send to Ducati during init
- OMX_CALLBACKTYPE oCallbacks;
+ // setup key parameters to send to Ducati during init
+ OMX_CALLBACKTYPE oCallbacks;
- // Initialize the callback handles
- oCallbacks.EventHandler = android::OMXCameraAdapterEventHandler;
- oCallbacks.EmptyBufferDone = android::OMXCameraAdapterEmptyBufferDone;
- oCallbacks.FillBufferDone = android::OMXCameraAdapterFillBufferDone;
+ // initialize the callback handles
+ oCallbacks.EventHandler = android::OMXCameraAdapterEventHandler;
+ oCallbacks.EmptyBufferDone = android::OMXCameraAdapterEmptyBufferDone;
+ oCallbacks.FillBufferDone = android::OMXCameraAdapterFillBufferDone;
- // Get Handle
- eError = OMX_GetHandle(handle, (OMX_STRING)"OMX.TI.DUCATI1.VIDEO.CAMERA", pAppData, &oCallbacks);
- if (eError != OMX_ErrorNone) {
- CAMHAL_LOGEB("OMX_GetHandle -0x%x", eError);
- //Sleep for 100 mS
- usleep(100000);
- } else {
- break;
- }
+ // get handle
+ eError = OMX_GetHandle(handle, (OMX_STRING)"OMX.TI.DUCATI1.VIDEO.CAMERA", pAppData, &oCallbacks);
+ if ( eError == OMX_ErrorNone ) {
+ return OMX_ErrorNone;
+ }
+
+ CAMHAL_LOGEB("OMX_GetHandle() failed, error: 0x%x", eError);
}
+ *handle = 0;
return eError;
}
diff --git a/camera/inc/OMXCameraAdapter/OMXCameraAdapter.h b/camera/inc/OMXCameraAdapter/OMXCameraAdapter.h
index 981e22d..4786f82 100644
--- a/camera/inc/OMXCameraAdapter/OMXCameraAdapter.h
+++ b/camera/inc/OMXCameraAdapter/OMXCameraAdapter.h
@@ -887,6 +887,7 @@ private:
int mBracketingRange;
CameraParameters mParameters;
+ bool mOmxInitialized;
OMXCameraAdapterComponentContext mCameraAdapterParameters;
bool mFirstTimeInit;