OMXZoom.cpp revision 226b496d5cce18e5898383bf479fdd42f2b5abdb
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#undef LOG_TAG 25 26#define LOG_TAG "CameraHAL" 27 28#include "CameraHal.h" 29#include "OMXCameraAdapter.h" 30 31namespace android { 32 33const int32_t OMXCameraAdapter::ZOOM_STEPS [ZOOM_STAGES] = { 34 65536, 68157, 70124, 72745, 35 75366, 77988, 80609, 83231, 36 86508, 89784, 92406, 95683, 37 99615, 102892, 106168, 110100, 38 114033, 117965, 122552, 126484, 39 131072, 135660, 140247, 145490, 40 150733, 155976, 161219, 167117, 41 173015, 178913, 185467, 192020, 42 198574, 205783, 212992, 220201, 43 228065, 236585, 244449, 252969, 44 262144, 271319, 281149, 290980, 45 300810, 311951, 322437, 334234, 46 346030, 357827, 370934, 384041, 47 397148, 411566, 425984, 441057, 48 456131, 472515, 488899, 506593, 49 524288 }; 50 51 52status_t OMXCameraAdapter::setParametersZoom(const CameraParameters ¶ms, 53 BaseCameraAdapter::AdapterState state) 54{ 55 status_t ret = NO_ERROR; 56 Mutex::Autolock lock(mZoomLock); 57 58 LOG_FUNCTION_NAME; 59 60 //Immediate zoom should not be avaialable while smooth zoom is running 61 if ( ( ZOOM_ACTIVE & state ) != ZOOM_ACTIVE ) 62 { 63 int zoom = params.getInt(CameraParameters::KEY_ZOOM); 64 if( ( zoom >= 0 ) && ( zoom < ZOOM_STAGES ) ) 65 { 66 mTargetZoomIdx = zoom; 67 68 //Immediate zoom should be applied instantly ( CTS requirement ) 69 mCurrentZoomIdx = mTargetZoomIdx; 70 doZoom(mCurrentZoomIdx); 71 72 CAMHAL_LOGDB("Zoom by App %d", zoom); 73 } 74 } 75 76 LOG_FUNCTION_NAME_EXIT; 77 78 return ret; 79} 80 81status_t OMXCameraAdapter::doZoom(int index) 82{ 83 status_t ret = NO_ERROR; 84 OMX_ERRORTYPE eError = OMX_ErrorNone; 85 OMX_CONFIG_SCALEFACTORTYPE zoomControl; 86 static int prevIndex = 0; 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) || ( ( ZOOM_STAGES - 1 ) < index ) ) 97 { 98 CAMHAL_LOGEB("Zoom index %d out of range", index); 99 ret = -EINVAL; 100 } 101 102 if ( prevIndex == index ) 103 { 104 return NO_ERROR; 105 } 106 107 if ( NO_ERROR == ret ) 108 { 109 OMX_INIT_STRUCT_PTR (&zoomControl, OMX_CONFIG_SCALEFACTORTYPE); 110 zoomControl.nPortIndex = OMX_ALL; 111 zoomControl.xHeight = ZOOM_STEPS[index]; 112 zoomControl.xWidth = ZOOM_STEPS[index]; 113 114 eError = OMX_SetConfig(mCameraAdapterParameters.mHandleComp, 115 OMX_IndexConfigCommonDigitalZoom, 116 &zoomControl); 117 if ( OMX_ErrorNone != eError ) 118 { 119 CAMHAL_LOGEB("Error while applying digital zoom 0x%x", eError); 120 ret = -1; 121 } 122 else 123 { 124 CAMHAL_LOGDA("Digital zoom applied successfully"); 125 prevIndex = index; 126 } 127 } 128 129 LOG_FUNCTION_NAME_EXIT; 130 131 return ret; 132} 133 134status_t OMXCameraAdapter::advanceZoom() 135{ 136 status_t ret = NO_ERROR; 137 AdapterState state; 138 BaseCameraAdapter::getState(state); 139 140 if ( mReturnZoomStatus ) 141 { 142 mTargetZoomIdx = mCurrentZoomIdx; 143 mReturnZoomStatus = false; 144 ret = doZoom(mCurrentZoomIdx); 145 notifyZoomSubscribers(mCurrentZoomIdx, true); 146 } 147 else if ( mCurrentZoomIdx != mTargetZoomIdx ) 148 { 149 if ( ZOOM_ACTIVE & state ) 150 { 151 if ( mCurrentZoomIdx < mTargetZoomIdx ) 152 { 153 mZoomInc = 1; 154 } 155 else 156 { 157 mZoomInc = -1; 158 } 159 160 mCurrentZoomIdx += mZoomInc; 161 } 162 else 163 { 164 mCurrentZoomIdx = mTargetZoomIdx; 165 } 166 167 ret = doZoom(mCurrentZoomIdx); 168 169 if ( ZOOM_ACTIVE & state ) 170 { 171 if ( mCurrentZoomIdx == mTargetZoomIdx ) 172 { 173 CAMHAL_LOGDB("[Goal Reached] Smooth Zoom notify currentIdx = %d, targetIdx = %d", 174 mCurrentZoomIdx, 175 mTargetZoomIdx); 176 177 if ( NO_ERROR == ret ) 178 { 179 180 ret = BaseCameraAdapter::setState(CAMERA_STOP_SMOOTH_ZOOM); 181 182 if ( NO_ERROR == ret ) 183 { 184 ret = BaseCameraAdapter::commitState(); 185 } 186 else 187 { 188 ret |= BaseCameraAdapter::rollbackState(); 189 } 190 191 } 192 mReturnZoomStatus = false; 193 notifyZoomSubscribers(mCurrentZoomIdx, true); 194 } 195 else 196 { 197 CAMHAL_LOGDB("[Advancing] Smooth Zoom notify currentIdx = %d, targetIdx = %d", 198 mCurrentZoomIdx, 199 mTargetZoomIdx); 200 notifyZoomSubscribers(mCurrentZoomIdx, false); 201 } 202 } 203 } 204 else if ( (mCurrentZoomIdx == mTargetZoomIdx ) && 205 ( ZOOM_ACTIVE & state ) ) 206 { 207 ret = BaseCameraAdapter::setState(CameraAdapter::CAMERA_STOP_SMOOTH_ZOOM); 208 209 if ( NO_ERROR == ret ) 210 { 211 ret = BaseCameraAdapter::commitState(); 212 } 213 else 214 { 215 ret |= BaseCameraAdapter::rollbackState(); 216 } 217 } 218 219 return ret; 220} 221 222status_t OMXCameraAdapter::startSmoothZoom(int targetIdx) 223{ 224 status_t ret = NO_ERROR; 225 226 LOG_FUNCTION_NAME; 227 228 Mutex::Autolock lock(mZoomLock); 229 230 CAMHAL_LOGDB("Start smooth zoom target = %d, mCurrentIdx = %d", 231 targetIdx, 232 mCurrentZoomIdx); 233 234 if ( ( targetIdx >= 0 ) && ( targetIdx < ZOOM_STAGES ) ) 235 { 236 mTargetZoomIdx = targetIdx; 237 mZoomParameterIdx = mCurrentZoomIdx; 238 mReturnZoomStatus = false; 239 } 240 else 241 { 242 CAMHAL_LOGEB("Smooth value out of range %d!", targetIdx); 243 ret = -EINVAL; 244 } 245 246 LOG_FUNCTION_NAME_EXIT; 247 248 return ret; 249} 250 251status_t OMXCameraAdapter::stopSmoothZoom() 252{ 253 status_t ret = NO_ERROR; 254 Mutex::Autolock lock(mZoomLock); 255 256 LOG_FUNCTION_NAME; 257 258 if ( mTargetZoomIdx != mCurrentZoomIdx ) 259 { 260 mTargetZoomIdx = mCurrentZoomIdx; 261 mReturnZoomStatus = true; 262 CAMHAL_LOGDB("Stop smooth zoom mCurrentZoomIdx = %d, mTargetZoomIdx = %d", 263 mCurrentZoomIdx, 264 mTargetZoomIdx); 265 } 266 267 LOG_FUNCTION_NAME_EXIT; 268 269 return ret; 270} 271 272}; 273