CameraHalUtilClasses.cpp revision 9e5cb561cc54d061fe9f3d05eae78f6efb70f2c2
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 CameraHalUtilClasses.cpp 19* 20* This file maps the CameraHardwareInterface to the Camera interfaces on OMAP4 (mainly OMX). 21* 22*/ 23 24#define LOG_TAG "CameraHAL" 25 26 27#include "CameraHal.h" 28 29namespace android { 30 31/*--------------------FrameProvider Class STARTS here-----------------------------*/ 32 33int FrameProvider::enableFrameNotification(int32_t frameTypes) 34{ 35 LOG_FUNCTION_NAME; 36 status_t ret = NO_ERROR; 37 38 ///Enable the frame notification to CameraAdapter (which implements FrameNotifier interface) 39 mFrameNotifier->enableMsgType(frameTypes<<MessageNotifier::FRAME_BIT_FIELD_POSITION 40 , mFrameCallback 41 , NULL 42 , mCookie 43 ); 44 45 LOG_FUNCTION_NAME_EXIT; 46 return ret; 47} 48 49int FrameProvider::disableFrameNotification(int32_t frameTypes) 50{ 51 LOG_FUNCTION_NAME; 52 status_t ret = NO_ERROR; 53 54 mFrameNotifier->disableMsgType(frameTypes<<MessageNotifier::FRAME_BIT_FIELD_POSITION 55 , mCookie 56 ); 57 58 LOG_FUNCTION_NAME_EXIT; 59 return ret; 60} 61 62int FrameProvider::returnFrame(void *frameBuf, CameraFrame::FrameType frameType) 63{ 64 status_t ret = NO_ERROR; 65 66 mFrameNotifier->returnFrame(frameBuf, frameType); 67 68 return ret; 69} 70 71 72/*--------------------FrameProvider Class ENDS here-----------------------------*/ 73 74/*--------------------EventProvider Class STARTS here-----------------------------*/ 75 76int EventProvider::enableEventNotification(int32_t frameTypes) 77{ 78 LOG_FUNCTION_NAME; 79 status_t ret = NO_ERROR; 80 81 ///Enable the frame notification to CameraAdapter (which implements FrameNotifier interface) 82 mEventNotifier->enableMsgType(frameTypes<<MessageNotifier::EVENT_BIT_FIELD_POSITION 83 , NULL 84 , mEventCallback 85 , mCookie 86 ); 87 88 LOG_FUNCTION_NAME_EXIT; 89 return ret; 90} 91 92int EventProvider::disableEventNotification(int32_t frameTypes) 93{ 94 LOG_FUNCTION_NAME; 95 status_t ret = NO_ERROR; 96 97 mEventNotifier->disableMsgType(frameTypes<<MessageNotifier::FRAME_BIT_FIELD_POSITION 98 , mCookie 99 ); 100 101 LOG_FUNCTION_NAME_EXIT; 102 return ret; 103} 104 105/*--------------------EventProvider Class ENDS here-----------------------------*/ 106 107/*--------------------CameraArea Class STARTS here-----------------------------*/ 108 109status_t CameraArea::transfrom(size_t width, 110 size_t height, 111 size_t &top, 112 size_t &left, 113 size_t &areaWidth, 114 size_t &areaHeight) 115{ 116 status_t ret = NO_ERROR; 117 size_t hRange, vRange; 118 double hScale, vScale; 119 120 LOG_FUNCTION_NAME 121 122 hRange = CameraArea::RIGHT - CameraArea::LEFT; 123 vRange = CameraArea::BOTTOM - CameraArea::TOP; 124 hScale = ( double ) width / ( double ) hRange; 125 vScale = ( double ) height / ( double ) vRange; 126 127 top = ( mTop + vRange / 2 ) * vScale; 128 left = ( mLeft + hRange / 2 ) * hScale; 129 areaHeight = ( mBottom + vRange / 2 ) * vScale; 130 areaHeight -= top; 131 areaWidth = ( mRight + hRange / 2) * hScale; 132 areaWidth -= left; 133 134 LOG_FUNCTION_NAME_EXIT 135 136 return ret; 137} 138 139status_t CameraArea::checkArea(ssize_t top, 140 ssize_t left, 141 ssize_t bottom, 142 ssize_t right, 143 ssize_t weight) 144{ 145 146 //Handles the invalid regin corner case. 147 if ( ( 0 == top ) && ( 0 == left ) && ( 0 == bottom ) && ( 0 == right ) && ( 0 == weight ) ) { 148 return NO_ERROR; 149 } 150 151 if ( ( CameraArea::WEIGHT_MIN > weight ) || ( CameraArea::WEIGHT_MAX < weight ) ) { 152 CAMHAL_LOGEB("Camera area weight is invalid %d", weight); 153 return -EINVAL; 154 } 155 156 if ( ( CameraArea::TOP > top ) || ( CameraArea::BOTTOM < top ) ) { 157 CAMHAL_LOGEB("Camera area top coordinate is invalid %d", top ); 158 return -EINVAL; 159 } 160 161 if ( ( CameraArea::TOP > bottom ) || ( CameraArea::BOTTOM < bottom ) ) { 162 CAMHAL_LOGEB("Camera area bottom coordinate is invalid %d", bottom ); 163 return -EINVAL; 164 } 165 166 if ( ( CameraArea::LEFT > left ) || ( CameraArea::RIGHT < left ) ) { 167 CAMHAL_LOGEB("Camera area left coordinate is invalid %d", left ); 168 return -EINVAL; 169 } 170 171 if ( ( CameraArea::LEFT > right ) || ( CameraArea::RIGHT < right ) ) { 172 CAMHAL_LOGEB("Camera area right coordinate is invalid %d", right ); 173 return -EINVAL; 174 } 175 176 if ( left >= right ) { 177 CAMHAL_LOGEA("Camera area left larger than right"); 178 return -EINVAL; 179 } 180 181 if ( top >= bottom ) { 182 CAMHAL_LOGEA("Camera area top larger than bottom"); 183 return -EINVAL; 184 } 185 186 return NO_ERROR; 187} 188 189status_t CameraArea::parseFocusArea(const char *area, 190 size_t areaLength, 191 Vector< sp<CameraArea> > &areas) 192{ 193 status_t ret = NO_ERROR; 194 char *ctx; 195 char *pArea = NULL; 196 char *pStart = NULL; 197 char *pEnd = NULL; 198 const char *startToken = "("; 199 const char endToken = ')'; 200 const char sep = ','; 201 ssize_t top, left, bottom, right, weight; 202 char *tmpBuffer = NULL; 203 sp<CameraArea> currentArea; 204 205 LOG_FUNCTION_NAME 206 207 if ( ( NULL == area ) || 208 ( 0 >= areaLength ) ) 209 { 210 return -EINVAL; 211 } 212 213 tmpBuffer = ( char * ) malloc(areaLength); 214 if ( NULL == tmpBuffer ) 215 { 216 return -ENOMEM; 217 } 218 219 memcpy(tmpBuffer, area, areaLength); 220 221 pArea = strtok_r(tmpBuffer, startToken, &ctx); 222 223 do 224 { 225 226 pStart = pArea; 227 if ( NULL == pStart ) 228 { 229 CAMHAL_LOGEA("Parsing of the left area coordinate failed!"); 230 ret = -EINVAL; 231 break; 232 } 233 else 234 { 235 left = static_cast<ssize_t>(strtol(pStart, &pEnd, 10)); 236 } 237 238 if ( sep != *pEnd ) 239 { 240 CAMHAL_LOGEA("Parsing of the top area coordinate failed!"); 241 ret = -EINVAL; 242 break; 243 } 244 else 245 { 246 top = static_cast<ssize_t>(strtol(pEnd+1, &pEnd, 10)); 247 } 248 249 if ( sep != *pEnd ) 250 { 251 CAMHAL_LOGEA("Parsing of the right area coordinate failed!"); 252 ret = -EINVAL; 253 break; 254 } 255 else 256 { 257 right = static_cast<ssize_t>(strtol(pEnd+1, &pEnd, 10)); 258 } 259 260 if ( sep != *pEnd ) 261 { 262 CAMHAL_LOGEA("Parsing of the bottom area coordinate failed!"); 263 ret = -EINVAL; 264 break; 265 } 266 else 267 { 268 bottom = static_cast<ssize_t>(strtol(pEnd+1, &pEnd, 10)); 269 } 270 271 if ( sep != *pEnd ) 272 { 273 CAMHAL_LOGEA("Parsing of the weight area coordinate failed!"); 274 ret = -EINVAL; 275 break; 276 } 277 else 278 { 279 weight = static_cast<ssize_t>(strtol(pEnd+1, &pEnd, 10)); 280 } 281 282 if ( endToken != *pEnd ) 283 { 284 CAMHAL_LOGEA("Malformed area!"); 285 ret = -EINVAL; 286 break; 287 } 288 289 ret = checkArea(top, left, bottom, right, weight); 290 if ( NO_ERROR != ret ) { 291 break; 292 } 293 294 currentArea = new CameraArea(top, left, bottom, right, weight); 295 CAMHAL_LOGDB("Area parsed [%dx%d, %dx%d] %d", 296 ( int ) top, 297 ( int ) left, 298 ( int ) bottom, 299 ( int ) right, 300 ( int ) weight); 301 if ( NULL != currentArea.get() ) 302 { 303 areas.add(currentArea); 304 } 305 else 306 { 307 ret = -ENOMEM; 308 break; 309 } 310 311 pArea = strtok_r(NULL, startToken, &ctx); 312 313 } 314 while ( NULL != pArea ); 315 316 if ( NULL != tmpBuffer ) 317 { 318 free(tmpBuffer); 319 } 320 321 LOG_FUNCTION_NAME_EXIT 322 323 return ret; 324} 325 326/*--------------------CameraArea Class ENDS here-----------------------------*/ 327 328}; 329