diff options
author | Sundar Raman <a0393242@ti.com> | 2012-10-02 09:17:26 -0500 |
---|---|---|
committer | Daniel Levin <dendy@ti.com> | 2012-10-10 18:55:51 +0300 |
commit | 230af436bfb220922006a6f9e0acb274800ca498 (patch) | |
tree | 1399a8e8a81b4c93a286673aa756e7f24a36016a /camera | |
parent | c2671dfd2ff330bf4da6563a50a70b0bc5d57ee8 (diff) | |
parent | e65834d4109ef3a831c38bfa98003b8e6e2de98c (diff) | |
download | hardware_ti_omap4-230af436bfb220922006a6f9e0acb274800ca498.zip hardware_ti_omap4-230af436bfb220922006a6f9e0acb274800ca498.tar.gz hardware_ti_omap4-230af436bfb220922006a6f9e0acb274800ca498.tar.bz2 |
Merge CameraHal: Camera Capabilities query update into p-jb-release
Change-Id: Ie8a95e38ecb9f9a6b59de6f1df962df071cc55ab
Diffstat (limited to 'camera')
-rw-r--r-- | camera/Android.mk | 3 | ||||
-rw-r--r-- | camera/OMXCameraAdapter/OMXCameraAdapter.cpp | 251 | ||||
-rw-r--r-- | camera/OMXCameraAdapter/OMXDCC.cpp | 223 | ||||
-rw-r--r-- | camera/inc/OMXCameraAdapter/OMXDCC.h | 44 |
4 files changed, 294 insertions, 227 deletions
diff --git a/camera/Android.mk b/camera/Android.mk index a3c6bd7..7b64ae2 100644 --- a/camera/Android.mk +++ b/camera/Android.mk @@ -93,7 +93,8 @@ TI_CAMERAHAL_OMX_SRC := \ OMXCameraAdapter/OMXFocus.cpp \ OMXCameraAdapter/OMXMetadata.cpp \ OMXCameraAdapter/OMXZoom.cpp \ - OMXCameraAdapter/OMXDccDataSave.cpp + OMXCameraAdapter/OMXDccDataSave.cpp \ + OMXCameraAdapter/OMXDCC.cpp TI_CAMERAHAL_USB_SRC := \ V4LCameraAdapter/V4LCameraAdapter.cpp \ diff --git a/camera/OMXCameraAdapter/OMXCameraAdapter.cpp b/camera/OMXCameraAdapter/OMXCameraAdapter.cpp index d4ec707..c142fa5 100644 --- a/camera/OMXCameraAdapter/OMXCameraAdapter.cpp +++ b/camera/OMXCameraAdapter/OMXCameraAdapter.cpp @@ -23,6 +23,7 @@ #include "CameraHal.h" #include "OMXCameraAdapter.h" +#include "OMXDCC.h" #include "ErrorUtils.h" #include "TICameraParameters.h" #include <signal.h> @@ -4279,7 +4280,6 @@ public: CapabilitiesHandler() { mComponent = 0; - mIsAborted = true; } const OMX_HANDLETYPE & component() const @@ -4292,94 +4292,6 @@ public: return mComponent; } - status_t disableAllPorts() - { - android::AutoMutex locker(mLock); - CAMHAL_UNUSED(locker); - - mPortsLeftToDisable = OMX_CAMERA_NUM_PORTS; - mIsOk = false; - mIsAborted = false; - - CAMHAL_LOGD("Disabling ports..."); - const OMX_ERRORTYPE sendCommandError = OMX_SendCommand(component(), - OMX_CommandPortDisable, OMX_ALL, 0); - CAMHAL_LOGD("Disabling ports... DONE"); - - if ( sendCommandError != OMX_ErrorNone ) - { - CAMHAL_LOGE("Failed disabling all ports, error: 0x%x", sendCommandError); - return Utils::ErrorUtils::omxToAndroidError(sendCommandError); - } - - CAMHAL_LOGD("Waiting for disabling all ports will be finished..."); - const status_t waitStatus = mCondition.waitRelative(mLock, seconds_to_nanoseconds(3)); - CAMHAL_LOGD("Waiting for disabling all ports will be finished... DONE"); - - if ( waitStatus != NO_ERROR ) - { - CAMHAL_LOGE("Timeout triggered while waiting for all ports to be disabled"); - return TIMED_OUT; - } - - if ( !mIsOk ) - { - CAMHAL_LOGE("Failed to disable all ports"); - return UNKNOWN_ERROR; - } - - // all ports have been disabled - mIsAborted = true; - - return NO_ERROR; - } - - status_t switchToState(OMX_STATETYPE state) - { - CAMHAL_LOGD("."); - android::AutoMutex locker(mLock); - CAMHAL_UNUSED(locker); - CAMHAL_LOGD("."); - - mState = state; - mIsOk = false; - mIsAborted = false; - - CAMHAL_LOGD("Switching to state 0x%x...", mState); - const OMX_ERRORTYPE switchError = OMX_SendCommand(mComponent, - OMX_CommandStateSet, mState, 0); - CAMHAL_LOGD("Switching to state 0x%x... DONE", mState); - - if ( switchError != OMX_ErrorNone ) - { - CAMHAL_LOGE("Failed switching to state 0x%x, error: 0x%x", mState, switchError); - return Utils::ErrorUtils::omxToAndroidError(switchError); - } - - // wait for the event for 3 seconds - CAMHAL_LOGD("Waiting..."); - const status_t waitStatus = mCondition.waitRelative(mLock, seconds_to_nanoseconds(3)); - CAMHAL_LOGD("Waiting... DONE"); - - // disable following events - mIsAborted = true; - - if ( waitStatus != NO_ERROR ) - { - CAMHAL_LOGE("Timeout triggered while switching to state 0x%x", mState); - return TIMED_OUT; - } - - // state has been switched, check whether is was Idle - if ( !mIsOk ) - { - CAMHAL_LOGE("Switching to state 0x%x has failed", mState); - return UNKNOWN_ERROR; - } - - return NO_ERROR; - } - status_t fetchCapabiltiesForMode(OMX_CAMOPERATINGMODETYPE mode, int sensorId, CameraProperties::Properties * properties) @@ -4398,37 +4310,15 @@ public: return BAD_VALUE; } - const status_t idleSwitchError = switchToState(OMX_StateIdle); - if ( idleSwitchError != NO_ERROR ) { - CAMHAL_LOGE("Failed to switch to Idle state, error: %d", idleSwitchError); - return UNKNOWN_ERROR; - } - // get and fill capabilities OMXCameraAdapter::getCaps(sensorId, properties, component()); - const status_t loadedSwitchError = switchToState(OMX_StateLoaded); - if ( loadedSwitchError != NO_ERROR ) { - CAMHAL_LOGE("Failed to switch to Loaded state, error: %d", loadedSwitchError); - return UNKNOWN_ERROR; - } - return NO_ERROR; } status_t fetchCapabilitiesForSensor(int sensorId, CameraProperties::Properties * properties) { - CAMHAL_LOGD("Disabling all ports..."); - const status_t disableAllPortsError = disableAllPorts(); - CAMHAL_LOGD("Disabling all ports... DONE"); - - if ( disableAllPortsError != NO_ERROR ) { - CAMHAL_LOGE("Failed to disable all ports, error: %d", - disableAllPortsError); - return UNKNOWN_ERROR; - } - // sensor select OMX_CONFIG_SENSORSELECTTYPE sensorSelect; OMX_INIT_STRUCT_PTR (&sensorSelect, OMX_CONFIG_SENSORSELECTTYPE); @@ -4504,102 +4394,9 @@ public: return err; } -public: - static OMX_ERRORTYPE eventCallback(const OMX_HANDLETYPE component, - const OMX_PTR cookie, const OMX_EVENTTYPE event, const OMX_U32 data1, const OMX_U32 data2, - const OMX_PTR pEventData) - { - LOG_FUNCTION_NAME; - - CAMHAL_UNUSED(pEventData); - - CAMHAL_LOGD("event = 0x%x", event); - CAMHAL_LOGD("data1 = 0x%x", data1); - CAMHAL_LOGD("data2 = 0x%x", data2); - - CapabilitiesHandler * handler = reinterpret_cast<CapabilitiesHandler*>(cookie); - - // ensure this is out component - if ( handler->component() != component ) - { - CAMHAL_LOGE("Wrong component handle received: %p, expecting: %p", - component, handler->component()); - return OMX_ErrorBadParameter; - } - - return handler->processEvent(event, data1, data2); - } - - OMX_ERRORTYPE processEvent(const OMX_EVENTTYPE event, const OMX_U32 data1, const OMX_U32 data2) - { - android::AutoMutex locker(mLock); - CAMHAL_UNUSED(locker); - - if ( mIsAborted ) - { - CAMHAL_LOGE("Waiting for state switch has been aborted"); - return OMX_ErrorNone; - } - - switch ( event ) - { - case OMX_EventCmdComplete: - switch ( data1 ) - { - case OMX_CommandStateSet: - // this is our state switch command we are waiting for - mIsOk = static_cast<OMX_STATETYPE>(data2) == mState; - - // wake up the caller - CAMHAL_LOGD("Waking the condition..."); - mCondition.signal(); - CAMHAL_LOGD("Waking the condition... DONE"); - break; - - case OMX_CommandPortDisable: - CAMHAL_LOGD("Decreasing disabled port count: %d", mPortsLeftToDisable); - mPortsLeftToDisable--; - if ( mPortsLeftToDisable == 0 ) - { - CAMHAL_LOGD("All ports have been disabled, waking the caller..."); - mIsOk = true; - mCondition.signal(); - CAMHAL_LOGD("All ports have been disabled, waking the caller... DONE"); - } - break; - - default: - // ignore rest of the commands - break; - } - break; - - case OMX_EventError: - CAMHAL_LOGE("Error event received, data1 = 0x%8x, data2 = 0x%8x", data1, data2); - - // keep mIsOk in false state, indicating that request has failed - - CAMHAL_LOGD("Waking the condition..."); - mCondition.signal(); - CAMHAL_LOGD("Waking the condition... DONE"); - break; - - default: - // ignore rest of the event types - break; - } - - return OMX_ErrorNone; - } - private: - android::Mutex mLock; - android::Condition mCondition; OMX_HANDLETYPE mComponent; OMX_STATETYPE mState; - bool mIsAborted; - bool mIsOk; - int mPortsLeftToDisable; }; extern "C" status_t OMXCameraAdapter_Capabilities( @@ -4627,43 +4424,45 @@ extern "C" status_t OMXCameraAdapter_Capabilities( return Utils::ErrorUtils::omxToAndroidError(eError); } + CapabilitiesHandler handler; + OMX_CALLBACKTYPE callbacks; + callbacks.EventHandler = 0; + callbacks.EmptyBufferDone = 0; + callbacks.FillBufferDone = 0; + + eError = OMXCameraAdapter::OMXCameraGetHandle(&handler.componentRef(), &handler, callbacks); + if (eError != OMX_ErrorNone) { + CAMHAL_LOGEB("OMX_GetHandle -0x%x", eError); + goto EXIT; + } + + DCCHandler dcc_handler; + dcc_handler.loadDCC(handler.componentRef()); + // Continue selecting sensor and then querying OMX Camera for it's capabilities // When sensor select returns an error, we know to break and stop while (eError == OMX_ErrorNone && (starting_camera + num_cameras_supported) < max_camera) { - CapabilitiesHandler handler; - - OMX_CALLBACKTYPE callbacks; - callbacks.EventHandler = CapabilitiesHandler::eventCallback; - callbacks.EmptyBufferDone = 0; - callbacks.FillBufferDone = 0; - - eError = OMXCameraAdapter::OMXCameraGetHandle(&handler.componentRef(), &handler, callbacks); - if (eError != OMX_ErrorNone) { - CAMHAL_LOGEB("OMX_GetHandle -0x%x", eError); - goto EXIT; - } - const int sensorId = num_cameras_supported; CameraProperties::Properties * properties = properties_array + starting_camera + sensorId; const status_t err = handler.fetchCapabilitiesForSensor(sensorId, properties); - // clean up - if(handler.component()) { - CAMHAL_LOGD("Freeing the component..."); - OMX_FreeHandle(handler.component()); - CAMHAL_LOGD("Freeing the component... DONE"); - handler.componentRef() = NULL; - } - if ( err != NO_ERROR ) break; num_cameras_supported++; - CAMHAL_LOGDB("Number of OMX Cameras detected = %d \n",num_cameras_supported); + CAMHAL_LOGEB("Number of OMX Cameras detected = %d \n",num_cameras_supported); } + // clean up + if(handler.component()) { + CAMHAL_LOGD("Freeing the component..."); + OMX_FreeHandle(handler.component()); + CAMHAL_LOGD("Freeing the component... DONE"); + handler.componentRef() = NULL; + } + EXIT: CAMHAL_LOGD("Deinit..."); OMX_Deinit(); diff --git a/camera/OMXCameraAdapter/OMXDCC.cpp b/camera/OMXCameraAdapter/OMXDCC.cpp new file mode 100644 index 0000000..914a53e --- /dev/null +++ b/camera/OMXCameraAdapter/OMXDCC.cpp @@ -0,0 +1,223 @@ +/* + * Copyright (C) Texas Instruments - http://www.ti.com/ + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/** +* @file OMXDCC.cpp +* +* This file contains functionality for loading the DCC binaries. +* +*/ + +#include "CameraHal.h" +#include "OMXCameraAdapter.h" +#include "ErrorUtils.h" +#include "OMXDCC.h" +#include <utils/String8.h> +#include <utils/Vector.h> + +namespace Ti { +namespace Camera { + +android::String8 DCCHandler::DCCPath("/data/misc/camera/"); +bool DCCHandler::mDCCLoaded = false; + +status_t DCCHandler::loadDCC(OMX_HANDLETYPE hComponent) +{ + OMX_ERRORTYPE dccError = OMX_ErrorNone; + + if (!mDCCLoaded) { + dccError = initDCC(hComponent); + if (dccError != OMX_ErrorNone) { + CAMHAL_LOGE(" Error in DCC Init"); + } + + mDCCLoaded = true; + } + + return Utils::ErrorUtils::omxToAndroidError(dccError); +} + +OMX_ERRORTYPE DCCHandler::initDCC(OMX_HANDLETYPE hComponent) +{ + OMX_TI_PARAM_DCCURIINFO param; + OMX_PTR ptempbuf; + OMX_U16 nIndex = 0; + OMX_ERRORTYPE eError = OMX_ErrorNone; + int ret; + OMX_S32 status = 0; + android::Vector<android::String8 *> dccDirs; + OMX_U16 i; + MemoryManager memMgr; + CameraBuffer *dccBuffer = NULL; + int dccbuf_size = 0; + OMX_INIT_STRUCT_PTR(¶m, OMX_TI_PARAM_DCCURIINFO); + + // Read the the DCC URI info + for (nIndex = 0; eError != OMX_ErrorNoMore; nIndex++) { + param.nIndex = nIndex; + eError = OMX_GetParameter(hComponent, + ( OMX_INDEXTYPE )OMX_TI_IndexParamDccUriInfo, + ¶m); + + if (eError == OMX_ErrorNone) { + CAMHAL_LOGD("DCC URI's %s ", param.sDCCURI); + android::String8 *dccDir = new android::String8(); + if ( NULL != dccDir ) { + dccDir->clear(); + dccDir->append(DCCPath); + dccDir->append((const char *) param.sDCCURI); + dccDir->append("/"); + dccDirs.add(dccDir); + } else { + CAMHAL_LOGE("DCC URI not allocated"); + eError = OMX_ErrorInsufficientResources; + goto EXIT; + } + } + } + + // setting back errortype OMX_ErrorNone + if (eError == OMX_ErrorNoMore) { + eError = OMX_ErrorNone; + } + + dccbuf_size = readDCCdir(NULL, dccDirs); + if(dccbuf_size <= 0) { + CAMHAL_LOGE("No DCC files found, switching back to default DCC"); + eError = OMX_ErrorInsufficientResources; + goto EXIT; + } + dccbuf_size = ((dccbuf_size + 4095 )/4096)*4096; + + if ( memMgr.initialize() != NO_ERROR ) { + CAMHAL_LOGE("DCC memory manager initialization failed!!!"); + eError = OMX_ErrorInsufficientResources; + goto EXIT; + } + + dccBuffer = memMgr.allocateBufferList(0, 0, NULL, dccbuf_size, 1); + if ( NULL == dccBuffer ) { + CAMHAL_LOGE("DCC buffer allocation failed!!!"); + eError = OMX_ErrorInsufficientResources; + goto EXIT; + } + + dccbuf_size = readDCCdir(dccBuffer[0].mapped, dccDirs); + CAMHAL_ASSERT_X(dccbuf_size > 0,"ERROR in copy DCC files into buffer"); + + eError = sendDCCBufPtr(hComponent, dccBuffer); + +EXIT: + + for (i = 0; i < dccDirs.size(); i++) { + android::String8 *dccDir = dccDirs.itemAt(0); + dccDirs.removeAt(0); + delete dccDir; + } + + if ( NULL != dccBuffer ) { + memMgr.freeBufferList(dccBuffer); + } + + return eError; +} + +OMX_ERRORTYPE DCCHandler::sendDCCBufPtr(OMX_HANDLETYPE hComponent, + CameraBuffer *dccBuffer) +{ + OMX_TI_CONFIG_SHAREDBUFFER uribufparam; + OMX_ERRORTYPE eError = OMX_ErrorNone; + OMX_INIT_STRUCT_PTR(&uribufparam, OMX_TI_CONFIG_SHAREDBUFFER); + + CAMHAL_ASSERT_X(dccBuffer != NULL,"ERROR invalid DCC buffer"); + + uribufparam.nPortIndex = OMX_ALL; + uribufparam.nSharedBuffSize = dccBuffer->size; + uribufparam.pSharedBuff = (OMX_U8 *) camera_buffer_get_omx_ptr(dccBuffer); + + eError = OMX_SetParameter(hComponent, + ( OMX_INDEXTYPE )OMX_TI_IndexParamDccUriBuffer, + &uribufparam); + if (eError != OMX_ErrorNone) { + CAMHAL_LOGEB(" Error in SetParam for DCC Uri Buffer 0x%x", eError); + } + + return eError; +} + +size_t DCCHandler::readDCCdir(OMX_PTR buffer, + const android::Vector<android::String8 *> &dirPaths) +{ + FILE *pFile; + OMX_S32 lSize; + OMX_S32 dcc_buf_size = 0; + size_t result; + OMX_STRING filename; + android::String8 temp; + const char *dotdot = ".."; + DIR *d; + struct dirent *dir; + OMX_U16 i = 0; + status_t stat = NO_ERROR; + size_t ret = 0; + + for (i = 0; i < dirPaths.size(); i++) { + d = opendir(dirPaths.itemAt(i)->string()); + if (d) { + // read each filename + while ((dir = readdir(d)) != NULL) { + filename = dir->d_name; + temp.clear(); + temp.append(dirPaths.itemAt(i)->string()); + temp.append(filename); + if ((*filename != *dotdot)) { + pFile = fopen(temp.string(), "rb"); + if (pFile == NULL) { + stat = -errno; + } else { + fseek(pFile, 0, SEEK_END); + lSize = ftell(pFile); + rewind(pFile); + // buffer is not NULL then copy all the DCC profiles into buffer + // else return the size of the DCC directory. + if (buffer) { + // copy file into the buffer: + result = fread(buffer, 1, lSize, pFile); + if (result != (size_t) lSize) { + stat = INVALID_OPERATION; + } + buffer = buffer + lSize; + } + // getting the size of the total dcc files available in FS */ + dcc_buf_size = dcc_buf_size + lSize; + // terminate + fclose(pFile); + } + } + } + closedir(d); + } + } + + if (stat == NO_ERROR) { + ret = dcc_buf_size; + } + + return ret; +} + +} // namespace Camera +} // namespace Ti diff --git a/camera/inc/OMXCameraAdapter/OMXDCC.h b/camera/inc/OMXCameraAdapter/OMXDCC.h new file mode 100644 index 0000000..c75a24d --- /dev/null +++ b/camera/inc/OMXCameraAdapter/OMXDCC.h @@ -0,0 +1,44 @@ +/* + * Copyright (C) Texas Instruments - http://www.ti.com/ + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef OMX_DCC_H +#define OMX_DCC_H + +namespace Ti { +namespace Camera { + +class DCCHandler +{ +public: + + status_t loadDCC(OMX_HANDLETYPE hComponent); + +private: + + OMX_ERRORTYPE initDCC(OMX_HANDLETYPE hComponent); + OMX_ERRORTYPE sendDCCBufPtr(OMX_HANDLETYPE hComponent, CameraBuffer *dccBuffer); + size_t readDCCdir(OMX_PTR buffer, const android::Vector<android::String8 *> &dirPaths); + +private: + + static android::String8 DCCPath; + static bool mDCCLoaded; +}; + +} // namespace Camera +} // namespace Ti + +#endif // OMX_DCC_H |