CameraHalUtilClasses.cpp revision c322989ae6ff6769490828de1b5eda12b749cce9
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::parseFocusArea(const char *area, 140 size_t areaLength, 141 Vector< sp<CameraArea> > &areas) 142{ 143 status_t ret = NO_ERROR; 144 char *ctx; 145 char *pArea = NULL; 146 char *pStart = NULL; 147 char *pEnd = NULL; 148 const char *startToken = "("; 149 const char endToken = ')'; 150 const char sep = ','; 151 ssize_t top, left, bottom, right, weight; 152 char *tmpBuffer = NULL; 153 sp<CameraArea> currentArea; 154 155 LOG_FUNCTION_NAME 156 157 if ( ( NULL == area ) || 158 ( 0 >= areaLength ) ) 159 { 160 return -EINVAL; 161 } 162 163 tmpBuffer = ( char * ) malloc(areaLength); 164 if ( NULL == tmpBuffer ) 165 { 166 return -ENOMEM; 167 } 168 169 memcpy(tmpBuffer, area, areaLength); 170 171 pArea = strtok_r(tmpBuffer, startToken, &ctx); 172 173 do 174 { 175 176 pStart = pArea; 177 if ( NULL == pStart ) 178 { 179 CAMHAL_LOGEA("Parsing of the left area coordinate failed!"); 180 ret = -EINVAL; 181 break; 182 } 183 else 184 { 185 left = static_cast<ssize_t>(strtol(pStart, &pEnd, 10)); 186 } 187 188 if ( sep != *pEnd ) 189 { 190 CAMHAL_LOGEA("Parsing of the top area coordinate failed!"); 191 ret = -EINVAL; 192 break; 193 } 194 else 195 { 196 top = static_cast<ssize_t>(strtol(pEnd+1, &pEnd, 10)); 197 } 198 199 if ( sep != *pEnd ) 200 { 201 CAMHAL_LOGEA("Parsing of the right area coordinate failed!"); 202 ret = -EINVAL; 203 break; 204 } 205 else 206 { 207 right = static_cast<ssize_t>(strtol(pEnd+1, &pEnd, 10)); 208 } 209 210 if ( sep != *pEnd ) 211 { 212 CAMHAL_LOGEA("Parsing of the bottom area coordinate failed!"); 213 ret = -EINVAL; 214 break; 215 } 216 else 217 { 218 bottom = static_cast<ssize_t>(strtol(pEnd+1, &pEnd, 10)); 219 } 220 221 if ( sep != *pEnd ) 222 { 223 CAMHAL_LOGEA("Parsing of the weight area coordinate failed!"); 224 ret = -EINVAL; 225 break; 226 } 227 else 228 { 229 weight = static_cast<ssize_t>(strtol(pEnd+1, &pEnd, 10)); 230 } 231 232 if ( endToken != *pEnd ) 233 { 234 CAMHAL_LOGEA("Malformed area!"); 235 ret = -EINVAL; 236 break; 237 } 238 239 currentArea = new CameraArea(top, left, bottom, right, weight); 240 CAMHAL_LOGDB("Area parsed [%dx%d, %dx%d] %d", 241 ( int ) top, 242 ( int ) left, 243 ( int ) bottom, 244 ( int ) right, 245 ( int )weight); 246 if ( NULL != currentArea.get() ) 247 { 248 areas.add(currentArea); 249 } 250 else 251 { 252 ret = -ENOMEM; 253 break; 254 } 255 256 pArea = strtok_r(NULL, startToken, &ctx); 257 258 } 259 while ( NULL != pArea ); 260 261 if ( NULL != tmpBuffer ) 262 { 263 free(tmpBuffer); 264 } 265 266 LOG_FUNCTION_NAME_EXIT 267 268 return ret; 269} 270 271/*--------------------CameraArea Class ENDS here-----------------------------*/ 272 273}; 274