1 /* 2 * Copyright (C) Texas Instruments - http://www.ti.com/ 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17 /** 18 * @file OMXZoom.cpp 19 * 20 * This file contains functionality for handling zoom configurations. 21 * 22 */ 23 24 #include "CameraHal.h" 25 #include "OMXCameraAdapter.h" 26 27 namespace Ti { 28 namespace Camera { 29 30 const int32_t OMXCameraAdapter::ZOOM_STEPS [ZOOM_STAGES] = { 31 65536, 68157, 70124, 72745, 32 75366, 77988, 80609, 83231, 33 86508, 89784, 92406, 95683, 34 99615, 102892, 106168, 110100, 35 114033, 117965, 122552, 126484, 36 131072, 135660, 140247, 145490, 37 150733, 155976, 161219, 167117, 38 173015, 178913, 185467, 192020, 39 198574, 205783, 212992, 220201, 40 228065, 236585, 244449, 252969, 41 262144, 271319, 281149, 290980, 42 300810, 311951, 322437, 334234, 43 346030, 357827, 370934, 384041, 44 397148, 411566, 425984, 441057, 45 456131, 472515, 488899, 506593, 46 524288 }; 47 48 49 status_t OMXCameraAdapter::setParametersZoom(const android::CameraParameters ¶ms, 50 BaseCameraAdapter::AdapterState state) 51 { 52 status_t ret = NO_ERROR; 53 android::AutoMutex lock(mZoomLock); 54 55 LOG_FUNCTION_NAME; 56 57 //Immediate zoom should not be avaialable while smooth zoom is running 58 if ( ( ZOOM_ACTIVE & state ) != ZOOM_ACTIVE ) 59 { 60 int zoom = params.getInt(android::CameraParameters::KEY_ZOOM); 61 if (( zoom >= 0 ) && ( zoom < mMaxZoomSupported )) { 62 mTargetZoomIdx = zoom; 63 64 //Immediate zoom should be applied instantly ( CTS requirement ) 65 mCurrentZoomIdx = mTargetZoomIdx; 66 if(!mZoomUpdating) { 67 doZoom(mCurrentZoomIdx); 68 mZoomUpdating = true; 69 } else { 70 mZoomUpdate = true; 71 } 72 73 CAMHAL_LOGDB("Zoom by App %d", zoom); 74 } 75 } 76 77 LOG_FUNCTION_NAME_EXIT; 78 79 return ret; 80 } 81 82 status_t OMXCameraAdapter::doZoom(int index) 83 { 84 status_t ret = NO_ERROR; 85 OMX_ERRORTYPE eError = OMX_ErrorNone; 86 OMX_CONFIG_SCALEFACTORTYPE zoomControl; 87 88 LOG_FUNCTION_NAME; 89 90 if ( OMX_StateInvalid == mComponentState ) 91 { 92 CAMHAL_LOGEA("OMX component is in invalid state"); 93 ret = -1; 94 } 95 96 if (( 0 > index) || ((mMaxZoomSupported - 1 ) < index )) { 97 CAMHAL_LOGEB("Zoom index %d out of range", index); 98 ret = -EINVAL; 99 } 100 101 if (mPreviousZoomIndx == index ) 102 { 103 return NO_ERROR; 104 } 105 106 if ( NO_ERROR == ret ) 107 { 108 OMX_INIT_STRUCT_PTR (&zoomControl, OMX_CONFIG_SCALEFACTORTYPE); 109 zoomControl.nPortIndex = OMX_ALL; 110 zoomControl.xHeight = ZOOM_STEPS[index]; 111 zoomControl.xWidth = ZOOM_STEPS[index]; 112 113 eError = OMX_SetConfig(mCameraAdapterParameters.mHandleComp, 114 OMX_IndexConfigCommonDigitalZoom, 115 &zoomControl); 116 if ( OMX_ErrorNone != eError ) 117 { 118 CAMHAL_LOGEB("Error while applying digital zoom 0x%x", eError); 119 ret = -1; 120 } 121 else 122 { 123 CAMHAL_LOGDA("Digital zoom applied successfully"); 124 mPreviousZoomIndx = index; 125 } 126 } 127 128 LOG_FUNCTION_NAME_EXIT; 129 130 return ret; 131 } 132 133 status_t OMXCameraAdapter::advanceZoom() 134 { 135 status_t ret = NO_ERROR; 136 AdapterState state; 137 android::AutoMutex lock(mZoomLock); 138 139 BaseCameraAdapter::getState(state); 140 141 if ( mReturnZoomStatus ) 142 { 143 mCurrentZoomIdx +=mZoomInc; 144 mTargetZoomIdx = mCurrentZoomIdx; 145 mReturnZoomStatus = false; 146 ret = doZoom(mCurrentZoomIdx); 147 notifyZoomSubscribers(mCurrentZoomIdx, true); 148 } 149 else if ( mCurrentZoomIdx != mTargetZoomIdx ) 150 { 151 if ( ZOOM_ACTIVE & state ) 152 { 153 if ( mCurrentZoomIdx < mTargetZoomIdx ) 154 { 155 mZoomInc = 1; 156 } 157 else 158 { 159 mZoomInc = -1; 160 } 161 162 mCurrentZoomIdx += mZoomInc; 163 } 164 else 165 { 166 mCurrentZoomIdx = mTargetZoomIdx; 167 } 168 169 ret = doZoom(mCurrentZoomIdx); 170 171 if ( ZOOM_ACTIVE & state ) 172 { 173 if ( mCurrentZoomIdx == mTargetZoomIdx ) 174 { 175 CAMHAL_LOGDB("[Goal Reached] Smooth Zoom notify currentIdx = %d, targetIdx = %d", 176 mCurrentZoomIdx, 177 mTargetZoomIdx); 178 179 if ( NO_ERROR == ret ) 180 { 181 182 ret = BaseCameraAdapter::setState(CAMERA_STOP_SMOOTH_ZOOM); 183 184 if ( NO_ERROR == ret ) 185 { 186 ret = BaseCameraAdapter::commitState(); 187 } 188 else 189 { 190 ret |= BaseCameraAdapter::rollbackState(); 191 } 192 193 } 194 mReturnZoomStatus = false; 195 notifyZoomSubscribers(mCurrentZoomIdx, true); 196 } 197 else 198 { 199 CAMHAL_LOGDB("[Advancing] Smooth Zoom notify currentIdx = %d, targetIdx = %d", 200 mCurrentZoomIdx, 201 mTargetZoomIdx); 202 notifyZoomSubscribers(mCurrentZoomIdx, false); 203 } 204 } 205 } 206 else if ( (mCurrentZoomIdx == mTargetZoomIdx ) && 207 ( ZOOM_ACTIVE & state ) ) 208 { 209 ret = BaseCameraAdapter::setState(CameraAdapter::CAMERA_STOP_SMOOTH_ZOOM); 210 211 if ( NO_ERROR == ret ) 212 { 213 ret = BaseCameraAdapter::commitState(); 214 } 215 else 216 { 217 ret |= BaseCameraAdapter::rollbackState(); 218 } 219 220 } 221 222 if(mZoomUpdate) { 223 doZoom(mTargetZoomIdx); 224 mZoomUpdate = false; 225 mZoomUpdating = true; 226 } else { 227 mZoomUpdating = false; 228 } 229 230 return ret; 231 } 232 233 status_t OMXCameraAdapter::startSmoothZoom(int targetIdx) 234 { 235 status_t ret = NO_ERROR; 236 237 LOG_FUNCTION_NAME; 238 239 android::AutoMutex lock(mZoomLock); 240 241 CAMHAL_LOGDB("Start smooth zoom target = %d, mCurrentIdx = %d", 242 targetIdx, 243 mCurrentZoomIdx); 244 245 if (( targetIdx >= 0 ) && ( targetIdx < mMaxZoomSupported )) { 246 mTargetZoomIdx = targetIdx; 247 mZoomParameterIdx = mCurrentZoomIdx; 248 mReturnZoomStatus = false; 249 } else { 250 CAMHAL_LOGEB("Smooth value out of range %d!", targetIdx); 251 ret = -EINVAL; 252 } 253 254 LOG_FUNCTION_NAME_EXIT; 255 256 return ret; 257 } 258 259 status_t OMXCameraAdapter::stopSmoothZoom() 260 { 261 status_t ret = NO_ERROR; 262 android::AutoMutex lock(mZoomLock); 263 264 LOG_FUNCTION_NAME; 265 266 if ( mTargetZoomIdx != mCurrentZoomIdx ) 267 { 268 if ( mCurrentZoomIdx < mTargetZoomIdx ) 269 { 270 mZoomInc = 1; 271 } 272 else 273 { 274 mZoomInc = -1; 275 } 276 mReturnZoomStatus = true; 277 mReturnZoomStatus = true; 278 CAMHAL_LOGDB("Stop smooth zoom mCurrentZoomIdx = %d, mTargetZoomIdx = %d", 279 mCurrentZoomIdx, 280 mTargetZoomIdx); 281 } 282 283 LOG_FUNCTION_NAME_EXIT; 284 285 return ret; 286 } 287 288 } // namespace Camera 289 } // namespace Ti 290