codeworkx | 62f02ba | 2012-05-20 12:00:36 +0200 | [diff] [blame] | 1 | /* |
| 2 | ** |
| 3 | ** Copyright 2008, The Android Open Source Project |
| 4 | ** Copyright 2010, Samsung Electronics Co. LTD |
| 5 | ** |
| 6 | ** Licensed under the Apache License, Version 2.0 (the "License"); |
| 7 | ** you may not use this file except in compliance with the License. |
| 8 | ** You may obtain a copy of the License at |
| 9 | ** |
| 10 | ** http://www.apache.org/licenses/LICENSE-2.0 |
| 11 | ** |
| 12 | ** Unless required by applicable law or agreed to in writing, software |
| 13 | ** distributed under the License is distributed on an "AS IS" BASIS, |
| 14 | ** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 15 | ** See the License for the specific language governing permissions and |
| 16 | ** limitations under the License. |
| 17 | */ |
| 18 | //#define LOG_NDEBUG 0 |
| 19 | #define LOG_TAG "CameraHardwareSec" |
| 20 | #include <utils/Log.h> |
| 21 | |
| 22 | #include "SecCameraHWInterface.h" |
| 23 | #include <utils/threads.h> |
| 24 | #include <fcntl.h> |
| 25 | #include <sys/mman.h> |
| 26 | #include <camera/Camera.h> |
| 27 | #include <media/stagefright/MetadataBufferType.h> |
| 28 | |
| 29 | #define VIDEO_COMMENT_MARKER_H 0xFFBE |
| 30 | #define VIDEO_COMMENT_MARKER_L 0xFFBF |
| 31 | #define VIDEO_COMMENT_MARKER_LENGTH 4 |
| 32 | #define JPEG_EOI_MARKER 0xFFD9 |
| 33 | #define HIBYTE(x) (((x) >> 8) & 0xFF) |
| 34 | #define LOBYTE(x) ((x) & 0xFF) |
| 35 | #define ALIGN(x, a) (((x) + (a) - 1) & ~((a) - 1)) |
| 36 | |
| 37 | #define BACK_CAMERA_AUTO_FOCUS_DISTANCES_STR "0.10,1.20,Infinity" |
| 38 | #define BACK_CAMERA_MACRO_FOCUS_DISTANCES_STR "0.10,0.20,Infinity" |
| 39 | #define BACK_CAMERA_INFINITY_FOCUS_DISTANCES_STR "0.10,1.20,Infinity" |
| 40 | #define FRONT_CAMERA_FOCUS_DISTANCES_STR "0.20,0.25,Infinity" |
| 41 | //#define USE_EGL |
| 42 | |
| 43 | // This hack does two things: |
| 44 | // -- it sets preview to NV21 (YUV420SP) |
| 45 | // -- it sets gralloc to YV12 |
| 46 | // |
| 47 | // The reason being: the samsung encoder understands only yuv420sp, and gralloc |
| 48 | // does yv12 and rgb565. So what we do is we break up the interleaved UV in |
| 49 | // separate V and U planes, which makes preview look good, and enabled the |
| 50 | // encoder as well. |
| 51 | // |
| 52 | // FIXME: Samsung needs to enable support for proper yv12 coming out of the |
| 53 | // camera, and to fix their video encoder to work with yv12. |
| 54 | // FIXME: It also seems like either Samsung's YUV420SP (NV21) or img's YV12 has |
| 55 | // the color planes switched. We need to figure which side is doing it |
| 56 | // wrong and have the respective party fix it. |
| 57 | |
| 58 | namespace android { |
| 59 | |
| 60 | struct addrs { |
| 61 | uint32_t type; // make sure that this is 4 byte. |
| 62 | unsigned int addr_y; |
| 63 | unsigned int addr_cbcr; |
| 64 | unsigned int buf_index; |
| 65 | unsigned int reserved; |
| 66 | }; |
| 67 | |
| 68 | struct addrs_cap { |
| 69 | unsigned int addr_y; |
| 70 | unsigned int width; |
| 71 | unsigned int height; |
| 72 | }; |
| 73 | |
| 74 | static const int INITIAL_SKIP_FRAME = 3; |
| 75 | static const int EFFECT_SKIP_FRAME = 1; |
| 76 | |
| 77 | gralloc_module_t const* CameraHardwareSec::mGrallocHal; |
| 78 | |
| 79 | CameraHardwareSec::CameraHardwareSec(int cameraId, camera_device_t *dev) |
| 80 | : |
| 81 | mCaptureInProgress(false), |
| 82 | mParameters(), |
| 83 | mFrameSizeDelta(0), |
| 84 | mCameraSensorName(NULL), |
| 85 | mSkipFrame(0), |
| 86 | mNotifyCb(0), |
| 87 | mDataCb(0), |
| 88 | mDataCbTimestamp(0), |
| 89 | mCallbackCookie(0), |
| 90 | mMsgEnabled(CAMERA_MSG_RAW_IMAGE), |
| 91 | mRecordRunning(false), |
| 92 | mPostViewWidth(0), |
| 93 | mPostViewHeight(0), |
| 94 | mPostViewSize(0), |
| 95 | mHalDevice(dev) |
| 96 | { |
| 97 | LOGV("%s :", __func__); |
| 98 | int ret = 0; |
| 99 | |
| 100 | mPreviewWindow = NULL; |
| 101 | mSecCamera = SecCamera::createInstance(); |
| 102 | |
| 103 | mRawHeap = NULL; |
| 104 | mPreviewHeap = NULL; |
| 105 | for(int i = 0; i < BUFFER_COUNT_FOR_ARRAY; i++) |
| 106 | mRecordHeap[i] = NULL; |
| 107 | |
| 108 | if (!mGrallocHal) { |
| 109 | ret = hw_get_module(GRALLOC_HARDWARE_MODULE_ID, (const hw_module_t **)&mGrallocHal); |
| 110 | if (ret) |
| 111 | LOGE("ERR(%s):Fail on loading gralloc HAL", __func__); |
| 112 | } |
| 113 | |
| 114 | ret = mSecCamera->CreateCamera(cameraId); |
| 115 | if (ret < 0) { |
| 116 | LOGE("ERR(%s):Fail on mSecCamera init", __func__); |
| 117 | mSecCamera->DestroyCamera(); |
| 118 | } |
| 119 | |
| 120 | initDefaultParameters(cameraId); |
| 121 | |
| 122 | mExitAutoFocusThread = false; |
| 123 | mExitPreviewThread = false; |
| 124 | /* whether the PreviewThread is active in preview or stopped. we |
| 125 | * create the thread but it is initially in stopped state. |
| 126 | */ |
| 127 | mPreviewRunning = false; |
| 128 | mPreviewStartDeferred = false; |
| 129 | mPreviewThread = new PreviewThread(this); |
| 130 | mAutoFocusThread = new AutoFocusThread(this); |
| 131 | mPictureThread = new PictureThread(this); |
| 132 | } |
| 133 | |
| 134 | int CameraHardwareSec::getCameraId() const |
| 135 | { |
| 136 | return mSecCamera->getCameraId(); |
| 137 | } |
| 138 | |
| 139 | void CameraHardwareSec::initDefaultParameters(int cameraId) |
| 140 | { |
| 141 | if (mSecCamera == NULL) { |
| 142 | LOGE("ERR(%s):mSecCamera object is NULL", __func__); |
| 143 | return; |
| 144 | } |
| 145 | |
| 146 | CameraParameters p; |
| 147 | CameraParameters ip; |
| 148 | |
| 149 | #ifndef GAIA_FW_BETA |
| 150 | mCameraSensorName = mSecCamera->getCameraSensorName(); |
| 151 | if (mCameraSensorName == NULL) { |
| 152 | LOGE("ERR(%s):mCameraSensorName is NULL", __func__); |
| 153 | return; |
| 154 | } |
| 155 | LOGV("CameraSensorName: %s", mCameraSensorName); |
| 156 | int Internal_is = !strncmp((const char*)mCameraSensorName, "ISP Camera", 10); |
| 157 | #else |
| 158 | int Internal_is = 0; |
| 159 | //sprintf((char *)mCameraSensorName, "%s", "temp name"); |
| 160 | #endif |
| 161 | int preview_max_width = 0; |
| 162 | int preview_max_height = 0; |
| 163 | int snapshot_max_width = 0; |
| 164 | int snapshot_max_height = 0; |
| 165 | |
| 166 | if (cameraId == SecCamera::CAMERA_ID_BACK) { |
| 167 | p.set(CameraParameters::KEY_SUPPORTED_PREVIEW_SIZES, |
| 168 | "3264x2448,2576x1948,1920x1080,1280x720,800x480,720x480,640x480,320x240,528x432,176x144"); |
| 169 | p.set(CameraParameters::KEY_SUPPORTED_PICTURE_SIZES, |
| 170 | "3264x2448,1920x1080,1280x720,800x480,720x480,640x480"); |
| 171 | if (Internal_is) |
| 172 | p.set(CameraParameters::KEY_SUPPORTED_VIDEO_SIZES, |
| 173 | "1920x1080,1280x720,640x480,176x144"); |
| 174 | } else { |
| 175 | p.set(CameraParameters::KEY_SUPPORTED_PREVIEW_SIZES, |
| 176 | "1392x1392,1280x720,640x480,352x288,320x240,176x144"); |
| 177 | p.set(CameraParameters::KEY_SUPPORTED_PICTURE_SIZES, |
| 178 | "1392x1392,1280x960,640x480"); |
| 179 | if (Internal_is) |
| 180 | p.set(CameraParameters::KEY_SUPPORTED_VIDEO_SIZES, |
| 181 | "1280x720,640x480,176x144"); |
| 182 | } |
| 183 | |
| 184 | p.getSupportedPreviewSizes(mSupportedPreviewSizes); |
| 185 | |
| 186 | // If these fail, then we are using an invalid cameraId and we'll leave the |
| 187 | // sizes at zero to catch the error. |
| 188 | if (mSecCamera->getPreviewMaxSize(&preview_max_width, |
| 189 | &preview_max_height) < 0) |
| 190 | LOGE("getPreviewMaxSize fail (%d / %d)", |
| 191 | preview_max_width, preview_max_height); |
| 192 | if (mSecCamera->getSnapshotMaxSize(&snapshot_max_width, |
| 193 | &snapshot_max_height) < 0) |
| 194 | LOGE("getSnapshotMaxSize fail (%d / %d)", |
| 195 | snapshot_max_width, snapshot_max_height); |
| 196 | |
| 197 | p.setPreviewFormat(CameraParameters::PIXEL_FORMAT_YUV420P); mFrameSizeDelta = 16; |
| 198 | p.set(CameraParameters::KEY_SUPPORTED_PREVIEW_FORMATS, CameraParameters::PIXEL_FORMAT_YUV420P); |
| 199 | p.set(CameraParameters::KEY_VIDEO_FRAME_FORMAT, CameraParameters::PIXEL_FORMAT_YUV420SP); |
| 200 | p.setPreviewSize(preview_max_width, preview_max_height); |
| 201 | |
| 202 | p.setPictureFormat(CameraParameters::PIXEL_FORMAT_JPEG); |
| 203 | p.setPictureSize(snapshot_max_width, snapshot_max_height); |
| 204 | p.set(CameraParameters::KEY_JPEG_QUALITY, "100"); // maximum quality |
| 205 | p.set(CameraParameters::KEY_SUPPORTED_PICTURE_FORMATS, |
| 206 | CameraParameters::PIXEL_FORMAT_JPEG); |
| 207 | |
| 208 | p.set(CameraParameters::KEY_PREFERRED_PREVIEW_SIZE_FOR_VIDEO, "1280x720"); |
| 209 | |
| 210 | String8 parameterString; |
| 211 | |
| 212 | if (cameraId == SecCamera::CAMERA_ID_BACK) { |
| 213 | parameterString = CameraParameters::FOCUS_MODE_AUTO; |
| 214 | parameterString.append(","); |
| 215 | parameterString.append(CameraParameters::FOCUS_MODE_INFINITY); |
| 216 | parameterString.append(","); |
| 217 | parameterString.append(CameraParameters::FOCUS_MODE_MACRO); |
| 218 | p.set(CameraParameters::KEY_SUPPORTED_FOCUS_MODES, |
| 219 | parameterString.string()); |
| 220 | p.set(CameraParameters::KEY_FOCUS_MODE, |
| 221 | CameraParameters::FOCUS_MODE_AUTO); |
| 222 | p.set(CameraParameters::KEY_FOCUS_DISTANCES, |
| 223 | BACK_CAMERA_AUTO_FOCUS_DISTANCES_STR); |
| 224 | p.set(CameraParameters::KEY_SUPPORTED_JPEG_THUMBNAIL_SIZES, |
| 225 | "320x240,0x0"); |
| 226 | p.set(CameraParameters::KEY_JPEG_THUMBNAIL_WIDTH, "320"); |
| 227 | p.set(CameraParameters::KEY_JPEG_THUMBNAIL_HEIGHT, "240"); |
| 228 | p.set(CameraParameters::KEY_SUPPORTED_PREVIEW_FRAME_RATES, "7,15,30"); |
| 229 | p.setPreviewFrameRate(30); |
| 230 | } else { |
| 231 | parameterString = CameraParameters::FOCUS_MODE_FIXED; |
| 232 | p.set(CameraParameters::KEY_SUPPORTED_FOCUS_MODES, |
| 233 | parameterString.string()); |
| 234 | p.set(CameraParameters::KEY_FOCUS_MODE, |
| 235 | CameraParameters::FOCUS_MODE_FIXED); |
| 236 | p.set(CameraParameters::KEY_FOCUS_DISTANCES, |
| 237 | FRONT_CAMERA_FOCUS_DISTANCES_STR); |
| 238 | p.set(CameraParameters::KEY_SUPPORTED_JPEG_THUMBNAIL_SIZES, |
| 239 | "160x120,0x0"); |
| 240 | p.set(CameraParameters::KEY_JPEG_THUMBNAIL_WIDTH, "160"); |
| 241 | p.set(CameraParameters::KEY_JPEG_THUMBNAIL_HEIGHT, "120"); |
| 242 | p.set(CameraParameters::KEY_SUPPORTED_PREVIEW_FRAME_RATES, "7,15,30"); |
| 243 | p.setPreviewFrameRate(30); |
| 244 | } |
| 245 | |
| 246 | parameterString = CameraParameters::EFFECT_NONE; |
| 247 | parameterString.append(","); |
| 248 | parameterString.append(CameraParameters::EFFECT_MONO); |
| 249 | parameterString.append(","); |
| 250 | parameterString.append(CameraParameters::EFFECT_NEGATIVE); |
| 251 | parameterString.append(","); |
| 252 | parameterString.append(CameraParameters::EFFECT_SEPIA); |
| 253 | p.set(CameraParameters::KEY_SUPPORTED_EFFECTS, parameterString.string()); |
| 254 | |
| 255 | if (cameraId == SecCamera::CAMERA_ID_BACK) { |
| 256 | parameterString = CameraParameters::FLASH_MODE_ON; |
| 257 | parameterString.append(","); |
| 258 | parameterString.append(CameraParameters::FLASH_MODE_OFF); |
| 259 | parameterString.append(","); |
| 260 | parameterString.append(CameraParameters::FLASH_MODE_AUTO); |
| 261 | parameterString.append(","); |
| 262 | parameterString.append(CameraParameters::FLASH_MODE_TORCH); |
| 263 | p.set(CameraParameters::KEY_SUPPORTED_FLASH_MODES, |
| 264 | parameterString.string()); |
| 265 | p.set(CameraParameters::KEY_FLASH_MODE, |
| 266 | CameraParameters::FLASH_MODE_OFF); |
| 267 | |
| 268 | parameterString = CameraParameters::SCENE_MODE_AUTO; |
| 269 | parameterString.append(","); |
| 270 | parameterString.append(CameraParameters::SCENE_MODE_PORTRAIT); |
| 271 | parameterString.append(","); |
| 272 | parameterString.append(CameraParameters::SCENE_MODE_LANDSCAPE); |
| 273 | parameterString.append(","); |
| 274 | parameterString.append(CameraParameters::SCENE_MODE_BEACH); |
| 275 | parameterString.append(","); |
| 276 | parameterString.append(CameraParameters::SCENE_MODE_SNOW); |
| 277 | parameterString.append(","); |
| 278 | parameterString.append(CameraParameters::SCENE_MODE_FIREWORKS); |
| 279 | parameterString.append(","); |
| 280 | parameterString.append(CameraParameters::SCENE_MODE_SPORTS); |
| 281 | parameterString.append(","); |
| 282 | parameterString.append(CameraParameters::SCENE_MODE_PARTY); |
| 283 | parameterString.append(","); |
| 284 | parameterString.append(CameraParameters::SCENE_MODE_CANDLELIGHT); |
| 285 | p.set(CameraParameters::KEY_SUPPORTED_SCENE_MODES, |
| 286 | parameterString.string()); |
| 287 | p.set(CameraParameters::KEY_SCENE_MODE, |
| 288 | CameraParameters::SCENE_MODE_AUTO); |
| 289 | |
| 290 | /* we have two ranges, 4-30fps for night mode and |
| 291 | * 15-30fps for all others |
| 292 | */ |
| 293 | p.set(CameraParameters::KEY_SUPPORTED_PREVIEW_FPS_RANGE, "(15000,30000)"); |
| 294 | p.set(CameraParameters::KEY_PREVIEW_FPS_RANGE, "15000,30000"); |
| 295 | |
| 296 | p.set(CameraParameters::KEY_FOCAL_LENGTH, "3.43"); |
| 297 | } else { |
| 298 | p.set(CameraParameters::KEY_SUPPORTED_PREVIEW_FPS_RANGE, "(7500,30000)"); |
| 299 | p.set(CameraParameters::KEY_PREVIEW_FPS_RANGE, "7500,30000"); |
| 300 | |
| 301 | p.set(CameraParameters::KEY_FOCAL_LENGTH, "0.9"); |
| 302 | } |
| 303 | |
| 304 | parameterString = CameraParameters::WHITE_BALANCE_AUTO; |
| 305 | parameterString.append(","); |
| 306 | parameterString.append(CameraParameters::WHITE_BALANCE_INCANDESCENT); |
| 307 | parameterString.append(","); |
| 308 | parameterString.append(CameraParameters::WHITE_BALANCE_FLUORESCENT); |
| 309 | parameterString.append(","); |
| 310 | parameterString.append(CameraParameters::WHITE_BALANCE_DAYLIGHT); |
| 311 | parameterString.append(","); |
| 312 | parameterString.append(CameraParameters::WHITE_BALANCE_CLOUDY_DAYLIGHT); |
| 313 | p.set(CameraParameters::KEY_SUPPORTED_WHITE_BALANCE, |
| 314 | parameterString.string()); |
| 315 | |
| 316 | p.set(CameraParameters::KEY_JPEG_THUMBNAIL_QUALITY, "100"); |
| 317 | |
| 318 | p.set(CameraParameters::KEY_ROTATION, 0); |
| 319 | p.set(CameraParameters::KEY_WHITE_BALANCE, CameraParameters::WHITE_BALANCE_AUTO); |
| 320 | |
| 321 | p.set(CameraParameters::KEY_EFFECT, CameraParameters::EFFECT_NONE); |
| 322 | |
| 323 | p.set("contrast", "auto"); |
| 324 | p.set("iso", "auto"); |
| 325 | p.set("metering", "center"); |
| 326 | p.set("wdr", 0); |
| 327 | |
| 328 | ip.set("chk_dataline", 0); |
| 329 | if (cameraId == SecCamera::CAMERA_ID_FRONT) { |
| 330 | ip.set("vtmode", 0); |
| 331 | ip.set("blur", 0); |
| 332 | } |
| 333 | |
| 334 | p.set(CameraParameters::KEY_HORIZONTAL_VIEW_ANGLE, "51.2"); |
| 335 | p.set(CameraParameters::KEY_VERTICAL_VIEW_ANGLE, "39.4"); |
| 336 | |
| 337 | p.set(CameraParameters::KEY_EXPOSURE_COMPENSATION, "0"); |
| 338 | p.set(CameraParameters::KEY_MAX_EXPOSURE_COMPENSATION, "2"); |
| 339 | p.set(CameraParameters::KEY_MIN_EXPOSURE_COMPENSATION, "-2"); |
| 340 | p.set(CameraParameters::KEY_EXPOSURE_COMPENSATION_STEP, "1"); |
| 341 | |
| 342 | p.set("brightness", 0); |
| 343 | p.set("brightness-max", 2); |
| 344 | p.set("brightness-min", -2); |
| 345 | |
| 346 | p.set("saturation", 0); |
| 347 | p.set("saturation-max", 2); |
| 348 | p.set("saturation-min", -2); |
| 349 | |
| 350 | p.set("sharpness", 0); |
| 351 | p.set("sharpness-max", 2); |
| 352 | p.set("sharpness-min", -2); |
| 353 | |
| 354 | p.set("hue", 0); |
| 355 | p.set("hue-max", 2); |
| 356 | p.set("hue-min", -2); |
| 357 | |
| 358 | parameterString = CameraParameters::ANTIBANDING_AUTO; |
| 359 | parameterString.append(","); |
| 360 | parameterString.append(CameraParameters::ANTIBANDING_50HZ); |
| 361 | parameterString.append(","); |
| 362 | parameterString.append(CameraParameters::ANTIBANDING_60HZ); |
| 363 | parameterString.append(","); |
| 364 | parameterString.append(CameraParameters::ANTIBANDING_OFF); |
| 365 | p.set(CameraParameters::KEY_SUPPORTED_ANTIBANDING, |
| 366 | parameterString.string()); |
| 367 | |
| 368 | p.set(CameraParameters::KEY_ANTIBANDING, CameraParameters::ANTIBANDING_OFF); |
| 369 | |
| 370 | mParameters = p; |
| 371 | mInternalParameters = ip; |
| 372 | |
| 373 | /* make sure mSecCamera has all the settings we do. applications |
| 374 | * aren't required to call setParameters themselves (only if they |
| 375 | * want to change something. |
| 376 | */ |
| 377 | setParameters(p); |
| 378 | if (cameraId == SecCamera::CAMERA_ID_BACK) |
| 379 | mSecCamera->setFrameRate(BACK_CAMERA_FPS); |
| 380 | else |
| 381 | mSecCamera->setFrameRate(FRONT_CAMERA_FPS); |
| 382 | } |
| 383 | |
| 384 | CameraHardwareSec::~CameraHardwareSec() |
| 385 | { |
| 386 | LOGV("%s", __func__); |
| 387 | mSecCamera->DestroyCamera(); |
| 388 | } |
| 389 | |
| 390 | status_t CameraHardwareSec::setPreviewWindow(preview_stream_ops *w) |
| 391 | { |
| 392 | int min_bufs; |
| 393 | |
| 394 | mPreviewWindow = w; |
| 395 | LOGV("%s: mPreviewWindow %p", __func__, mPreviewWindow); |
| 396 | |
| 397 | if (!w) { |
| 398 | LOGE("preview window is NULL!"); |
| 399 | return OK; |
| 400 | } |
| 401 | |
| 402 | mPreviewLock.lock(); |
| 403 | |
| 404 | if (mPreviewRunning && !mPreviewStartDeferred) { |
| 405 | LOGI("stop preview (window change)"); |
| 406 | stopPreviewInternal(); |
| 407 | } |
| 408 | |
| 409 | if (w->get_min_undequeued_buffer_count(w, &min_bufs)) { |
| 410 | LOGE("%s: could not retrieve min undequeued buffer count", __func__); |
| 411 | return INVALID_OPERATION; |
| 412 | } |
| 413 | |
| 414 | if (min_bufs >= BUFFER_COUNT_FOR_GRALLOC) { |
| 415 | LOGE("%s: min undequeued buffer count %d is too high (expecting at most %d)", __func__, |
| 416 | min_bufs, BUFFER_COUNT_FOR_GRALLOC - 1); |
| 417 | } |
| 418 | |
| 419 | LOGV("%s: setting buffer count to %d", __func__, BUFFER_COUNT_FOR_GRALLOC); |
| 420 | if (w->set_buffer_count(w, BUFFER_COUNT_FOR_GRALLOC)) { |
| 421 | LOGE("%s: could not set buffer count", __func__); |
| 422 | return INVALID_OPERATION; |
| 423 | } |
| 424 | |
| 425 | int preview_width; |
| 426 | int preview_height; |
| 427 | mParameters.getPreviewSize(&preview_width, &preview_height); |
| 428 | |
| 429 | int hal_pixel_format; |
| 430 | |
| 431 | const char *str_preview_format = mParameters.getPreviewFormat(); |
| 432 | LOGV("%s: str preview format %s width : %d height : %d ", __func__, str_preview_format, preview_width, preview_height); |
| 433 | mFrameSizeDelta = 16; |
| 434 | |
| 435 | hal_pixel_format = HAL_PIXEL_FORMAT_YV12; |
| 436 | |
| 437 | if (!strcmp(str_preview_format, |
| 438 | CameraParameters::PIXEL_FORMAT_RGB565)) { |
| 439 | hal_pixel_format = HAL_PIXEL_FORMAT_RGB_565; |
| 440 | mFrameSizeDelta = 0; |
| 441 | } else if (!strcmp(str_preview_format, |
| 442 | CameraParameters::PIXEL_FORMAT_RGBA8888)) { |
| 443 | hal_pixel_format = HAL_PIXEL_FORMAT_RGBA_8888; |
| 444 | mFrameSizeDelta = 0; |
| 445 | } else if (!strcmp(str_preview_format, |
| 446 | CameraParameters::PIXEL_FORMAT_YUV420SP)) { |
| 447 | hal_pixel_format = HAL_PIXEL_FORMAT_YCrCb_420_SP; |
| 448 | } else if (!strcmp(str_preview_format, |
| 449 | CameraParameters::PIXEL_FORMAT_YUV420P)) |
| 450 | hal_pixel_format = HAL_PIXEL_FORMAT_YV12; |
| 451 | |
| 452 | #ifdef USE_EGL |
| 453 | if (w->set_usage(w, GRALLOC_USAGE_SW_WRITE_OFTEN | GRALLOC_USAGE_HW_ION)) { |
| 454 | LOGE("%s: could not set usage on gralloc buffer", __func__); |
| 455 | return INVALID_OPERATION; |
| 456 | } |
| 457 | #else |
| 458 | if (w->set_usage(w, GRALLOC_USAGE_SW_WRITE_OFTEN |
| 459 | | GRALLOC_USAGE_HWC_HWOVERLAY | GRALLOC_USAGE_HW_ION)) { |
| 460 | LOGE("%s: could not set usage on gralloc buffer", __func__); |
| 461 | return INVALID_OPERATION; |
| 462 | } |
| 463 | #endif |
| 464 | |
| 465 | if (w->set_buffers_geometry(w, |
| 466 | preview_width, preview_height, |
| 467 | hal_pixel_format)) { |
| 468 | LOGE("%s: could not set buffers geometry to %s", |
| 469 | __func__, str_preview_format); |
| 470 | return INVALID_OPERATION; |
| 471 | } |
| 472 | |
| 473 | for(int i = 0; i < BUFFER_COUNT_FOR_ARRAY; i++) |
| 474 | if (0 != mPreviewWindow->dequeue_buffer(mPreviewWindow, &mBufferHandle[i], &mStride[i])) { |
| 475 | LOGE("%s: Could not dequeue gralloc buffer[%d]!!", __func__, i); |
| 476 | return INVALID_OPERATION; |
| 477 | } |
| 478 | |
| 479 | if (mPreviewRunning && mPreviewStartDeferred) { |
| 480 | LOGV("start/resume preview"); |
| 481 | status_t ret = startPreviewInternal(); |
| 482 | if (ret == OK) { |
| 483 | mPreviewStartDeferred = false; |
| 484 | mPreviewCondition.signal(); |
| 485 | } |
| 486 | } |
| 487 | mPreviewLock.unlock(); |
| 488 | |
| 489 | return OK; |
| 490 | } |
| 491 | |
| 492 | void CameraHardwareSec::setCallbacks(camera_notify_callback notify_cb, |
| 493 | camera_data_callback data_cb, |
| 494 | camera_data_timestamp_callback data_cb_timestamp, |
| 495 | camera_request_memory get_memory, |
| 496 | void *user) |
| 497 | { |
| 498 | mNotifyCb = notify_cb; |
| 499 | mDataCb = data_cb; |
| 500 | mDataCbTimestamp = data_cb_timestamp; |
| 501 | mGetMemoryCb = get_memory; |
| 502 | mCallbackCookie = user; |
| 503 | } |
| 504 | |
| 505 | void CameraHardwareSec::enableMsgType(int32_t msgType) |
| 506 | { |
| 507 | LOGV("%s : msgType = 0x%x, mMsgEnabled before = 0x%x", |
| 508 | __func__, msgType, mMsgEnabled); |
| 509 | mMsgEnabled |= msgType; |
| 510 | |
| 511 | mPreviewLock.lock(); |
| 512 | if ((msgType & (CAMERA_MSG_PREVIEW_FRAME | CAMERA_MSG_VIDEO_FRAME)) && |
| 513 | mPreviewRunning && mPreviewStartDeferred) { |
| 514 | LOGV("%s: starting deferred preview", __func__); |
| 515 | if (startPreviewInternal() == OK) { |
| 516 | mPreviewStartDeferred = false; |
| 517 | mPreviewCondition.signal(); |
| 518 | } |
| 519 | } |
| 520 | mPreviewLock.unlock(); |
| 521 | |
| 522 | LOGV("%s : mMsgEnabled = 0x%x", __func__, mMsgEnabled); |
| 523 | } |
| 524 | |
| 525 | void CameraHardwareSec::disableMsgType(int32_t msgType) |
| 526 | { |
| 527 | LOGV("%s : msgType = 0x%x, mMsgEnabled before = 0x%x", |
| 528 | __func__, msgType, mMsgEnabled); |
| 529 | mMsgEnabled &= ~msgType; |
| 530 | LOGV("%s : mMsgEnabled = 0x%x", __func__, mMsgEnabled); |
| 531 | } |
| 532 | |
| 533 | bool CameraHardwareSec::msgTypeEnabled(int32_t msgType) |
| 534 | { |
| 535 | return (mMsgEnabled & msgType); |
| 536 | } |
| 537 | |
| 538 | void CameraHardwareSec::setSkipFrame(int frame) |
| 539 | { |
| 540 | Mutex::Autolock lock(mSkipFrameLock); |
| 541 | if (frame < mSkipFrame) |
| 542 | return; |
| 543 | |
| 544 | mSkipFrame = frame; |
| 545 | } |
| 546 | |
| 547 | int CameraHardwareSec::previewThreadWrapper() |
| 548 | { |
| 549 | LOGI("%s: starting", __func__); |
| 550 | while (1) { |
| 551 | mPreviewLock.lock(); |
| 552 | while (!mPreviewRunning) { |
| 553 | LOGI("%s: calling mSecCamera->stopPreview() and waiting", __func__); |
| 554 | mSecCamera->stopPreview(); |
| 555 | /* signal that we're stopping */ |
| 556 | mPreviewStoppedCondition.signal(); |
| 557 | mPreviewCondition.wait(mPreviewLock); |
| 558 | LOGI("%s: return from wait", __func__); |
| 559 | } |
| 560 | mPreviewLock.unlock(); |
| 561 | |
| 562 | if (mExitPreviewThread) { |
| 563 | LOGI("%s: exiting", __func__); |
| 564 | mSecCamera->stopPreview(); |
| 565 | return 0; |
| 566 | } |
| 567 | previewThread(); |
| 568 | } |
| 569 | } |
| 570 | |
| 571 | int CameraHardwareSec::previewThread() |
| 572 | { |
| 573 | int index; |
| 574 | nsecs_t timestamp; |
| 575 | SecBuffer previewAddr, recordAddr; |
| 576 | static int numArray = 0; |
| 577 | void *virAddr[3]; |
| 578 | private_handle_t *hnd = NULL; |
| 579 | |
| 580 | index = mSecCamera->getPreview(); |
| 581 | |
| 582 | if (index < 0) { |
| 583 | LOGE("ERR(%s):Fail on SecCamera->getPreview()", __func__); |
| 584 | if (mSecCamera->getPreviewState()) { |
| 585 | stopPreview(); |
| 586 | startPreview(); |
| 587 | mSecCamera->clearPreviewState(); |
| 588 | } |
| 589 | return UNKNOWN_ERROR; |
| 590 | } |
| 591 | |
| 592 | mSkipFrameLock.lock(); |
| 593 | if (mSkipFrame > 0) { |
| 594 | mSkipFrame--; |
| 595 | mSkipFrameLock.unlock(); |
| 596 | LOGV("%s: index %d skipping frame", __func__, index); |
| 597 | if (mSecCamera->setPreviewFrame(index) < 0) { |
| 598 | LOGE("%s: Could not qbuff[%d]!!", __func__, index); |
| 599 | return UNKNOWN_ERROR; |
| 600 | } |
| 601 | return NO_ERROR; |
| 602 | } |
| 603 | mSkipFrameLock.unlock(); |
| 604 | |
| 605 | timestamp = systemTime(SYSTEM_TIME_MONOTONIC); |
| 606 | |
| 607 | int width, height, frame_size, offset; |
| 608 | |
| 609 | mSecCamera->getPreviewSize(&width, &height, &frame_size); |
| 610 | |
| 611 | offset = frame_size * index; |
| 612 | |
| 613 | if (mPreviewWindow && mGrallocHal && mPreviewRunning) { |
| 614 | hnd = (private_handle_t*)*mBufferHandle[index]; |
| 615 | |
| 616 | if (mPreviewHeap) { |
| 617 | mPreviewHeap->release(mPreviewHeap); |
| 618 | mPreviewHeap = 0; |
| 619 | } |
| 620 | |
| 621 | mPreviewHeap = mGetMemoryCb(hnd->fd, frame_size, 1, 0); |
| 622 | |
| 623 | hnd = NULL; |
| 624 | |
| 625 | mGrallocHal->unlock(mGrallocHal, *mBufferHandle[index]); |
| 626 | if (0 != mPreviewWindow->enqueue_buffer(mPreviewWindow, mBufferHandle[index])) { |
| 627 | LOGE("%s: Could not enqueue gralloc buffer[%d]!!", __func__, index); |
| 628 | goto callbacks; |
| 629 | } |
| 630 | |
| 631 | numArray = index; |
| 632 | |
| 633 | if (0 != mPreviewWindow->dequeue_buffer(mPreviewWindow, &mBufferHandle[numArray], &mStride[numArray])) { |
| 634 | LOGE("%s: Could not dequeue gralloc buffer[%d]!!", __func__, numArray); |
| 635 | goto callbacks; |
| 636 | } |
| 637 | |
| 638 | if (!mGrallocHal->lock(mGrallocHal, |
| 639 | *mBufferHandle[numArray], |
| 640 | GRALLOC_USAGE_SW_WRITE_OFTEN | GRALLOC_USAGE_YUV_ADDR, |
| 641 | 0, 0, width, height, virAddr)) { |
| 642 | mSecCamera->getPreviewAddr(index, &previewAddr); |
| 643 | char *frame = (char *)previewAddr.virt.extP[0]; |
| 644 | |
| 645 | #ifdef USE_EGL |
| 646 | int m_Ywidth = ALIGN(width, 16); |
| 647 | int m_Yheight = ALIGN(height, 16); |
| 648 | int m_UVwidth = ALIGN(width/2, 8); |
| 649 | int m_UVheight = ALIGN(height/2, 8); |
| 650 | virAddr[1] = virAddr[0] + (m_Ywidth * m_Yheight); |
| 651 | virAddr[2] = virAddr[1] + (m_UVwidth * m_UVheight); |
| 652 | #endif |
| 653 | |
| 654 | mSecCamera->setUserBufferAddr(virAddr, index, PREVIEW_MODE); |
| 655 | } |
| 656 | else |
| 657 | LOGE("%s: could not obtain gralloc buffer", __func__); |
| 658 | |
| 659 | if (mSecCamera->setPreviewFrame(index) < 0) { |
| 660 | LOGE("%s: Fail qbuf, index(%d)", __func__, index); |
| 661 | goto callbacks; |
| 662 | } |
| 663 | index = 0; |
| 664 | } |
| 665 | |
| 666 | callbacks: |
| 667 | // Notify the client of a new frame. |
| 668 | if (mMsgEnabled & CAMERA_MSG_PREVIEW_FRAME) |
| 669 | mDataCb(CAMERA_MSG_PREVIEW_FRAME, mPreviewHeap, index, NULL, mCallbackCookie); |
| 670 | |
| 671 | Mutex::Autolock lock(mRecordLock); |
| 672 | if (mRecordRunning == true) { |
| 673 | int recordingIndex = 0; |
| 674 | |
| 675 | index = mSecCamera->getRecordFrame(); |
| 676 | if (index < 0) { |
| 677 | LOGE("ERR(%s):Fail on SecCamera->getRecordFrame()", __func__); |
| 678 | return UNKNOWN_ERROR; |
| 679 | } |
| 680 | |
| 681 | numArray = index; |
| 682 | |
| 683 | // Notify the client of a new frame. |
| 684 | if (mMsgEnabled & CAMERA_MSG_VIDEO_FRAME) |
| 685 | mDataCbTimestamp(timestamp, CAMERA_MSG_VIDEO_FRAME, |
| 686 | mRecordHeap[numArray], recordingIndex, mCallbackCookie); |
| 687 | else |
| 688 | mSecCamera->releaseRecordFrame(index); |
| 689 | } |
| 690 | |
| 691 | return NO_ERROR; |
| 692 | } |
| 693 | |
| 694 | status_t CameraHardwareSec::startPreview() |
| 695 | { |
| 696 | int ret = 0; |
| 697 | |
| 698 | LOGV("%s :", __func__); |
| 699 | |
| 700 | Mutex::Autolock lock(mStateLock); |
| 701 | if (mCaptureInProgress) { |
| 702 | LOGE("%s : capture in progress, not allowed", __func__); |
| 703 | return INVALID_OPERATION; |
| 704 | } |
| 705 | |
| 706 | mPreviewLock.lock(); |
| 707 | if (mPreviewRunning) { |
| 708 | // already running |
| 709 | LOGE("%s : preview thread already running", __func__); |
| 710 | mPreviewLock.unlock(); |
| 711 | return INVALID_OPERATION; |
| 712 | } |
| 713 | |
| 714 | mPreviewRunning = true; |
| 715 | mPreviewStartDeferred = false; |
| 716 | |
| 717 | if (!mPreviewWindow && |
| 718 | !(mMsgEnabled & CAMERA_MSG_PREVIEW_FRAME) && |
| 719 | !(mMsgEnabled & CAMERA_MSG_VIDEO_FRAME)) { |
| 720 | LOGI("%s : deferring", __func__); |
| 721 | mPreviewStartDeferred = true; |
| 722 | mPreviewLock.unlock(); |
| 723 | return NO_ERROR; |
| 724 | } |
| 725 | |
| 726 | ret = startPreviewInternal(); |
| 727 | if (ret == OK) |
| 728 | mPreviewCondition.signal(); |
| 729 | |
| 730 | mPreviewLock.unlock(); |
| 731 | return ret; |
| 732 | } |
| 733 | |
| 734 | status_t CameraHardwareSec::startPreviewInternal() |
| 735 | { |
| 736 | LOGV("%s", __func__); |
| 737 | int width, height, frame_size; |
| 738 | |
| 739 | mSecCamera->getPreviewSize(&width, &height, &frame_size); |
| 740 | LOGD("mPreviewHeap(fd(%d), size(%d), width(%d), height(%d))", |
| 741 | mSecCamera->getCameraFd(), frame_size + mFrameSizeDelta, width, height); |
| 742 | |
| 743 | void *vaddr[3]; |
| 744 | |
| 745 | for (int i = 0; i < MAX_BUFFERS; i++) { |
| 746 | !mGrallocHal->lock(mGrallocHal, |
| 747 | *mBufferHandle[i], |
| 748 | GRALLOC_USAGE_SW_WRITE_OFTEN | GRALLOC_USAGE_YUV_ADDR, |
| 749 | 0, 0, width, height, vaddr); |
| 750 | memset(vaddr[0], 0, width*height*2); |
| 751 | int m_Ywidth = ALIGN(width, 16); |
| 752 | int m_Yheight = ALIGN(height, 16); |
| 753 | int m_UVwidth = ALIGN(width/2, 8); |
| 754 | int m_UVheight = ALIGN(height/2, 8); |
| 755 | vaddr[1] = vaddr[0] + (m_Ywidth * m_Yheight); |
| 756 | vaddr[2] = vaddr[1] + (m_UVwidth * m_UVheight); |
| 757 | mSecCamera->setUserBufferAddr(vaddr, i, PREVIEW_MODE); |
| 758 | } |
| 759 | |
| 760 | int ret = mSecCamera->startPreview(); |
| 761 | LOGV("%s : mSecCamera->startPreview() returned %d", __func__, ret); |
| 762 | |
| 763 | if (ret < 0) { |
| 764 | LOGE("ERR(%s):Fail on mSecCamera->startPreview()", __func__); |
| 765 | return UNKNOWN_ERROR; |
| 766 | } |
| 767 | |
| 768 | setSkipFrame(INITIAL_SKIP_FRAME); |
| 769 | |
| 770 | if (mPreviewHeap) { |
| 771 | mPreviewHeap->release(mPreviewHeap); |
| 772 | mPreviewHeap = 0; |
| 773 | } |
| 774 | |
| 775 | mSecCamera->getPostViewConfig(&mPostViewWidth, &mPostViewHeight, &mPostViewSize); |
| 776 | LOGV("CameraHardwareSec: mPostViewWidth = %d mPostViewHeight = %d mPostViewSize = %d", |
| 777 | mPostViewWidth,mPostViewHeight,mPostViewSize); |
| 778 | |
| 779 | return NO_ERROR; |
| 780 | } |
| 781 | |
| 782 | void CameraHardwareSec::stopPreviewInternal() |
| 783 | { |
| 784 | LOGV("%s :", __func__); |
| 785 | |
| 786 | /* request that the preview thread stop. */ |
| 787 | if (mPreviewRunning) { |
| 788 | mPreviewRunning = false; |
| 789 | if (!mPreviewStartDeferred) { |
| 790 | mPreviewCondition.signal(); |
| 791 | /* wait until preview thread is stopped */ |
| 792 | mPreviewStoppedCondition.wait(mPreviewLock); |
| 793 | |
| 794 | for (int i = 0; i < MAX_BUFFERS; i++) { |
| 795 | if (0 != mPreviewWindow->enqueue_buffer(mPreviewWindow, mBufferHandle[i])) |
| 796 | LOGE("%s: Fail to enqueue buffer[%d]", __func__, i); |
| 797 | } |
| 798 | } |
| 799 | else |
| 800 | LOGV("%s : preview running but deferred, doing nothing", __func__); |
| 801 | } else |
| 802 | LOGI("%s : preview not running, doing nothing", __func__); |
| 803 | } |
| 804 | |
| 805 | void CameraHardwareSec::stopPreview() |
| 806 | { |
| 807 | LOGV("%s :", __func__); |
| 808 | |
| 809 | /* request that the preview thread stop. */ |
| 810 | mPreviewLock.lock(); |
| 811 | stopPreviewInternal(); |
| 812 | mPreviewLock.unlock(); |
| 813 | } |
| 814 | |
| 815 | bool CameraHardwareSec::previewEnabled() |
| 816 | { |
| 817 | Mutex::Autolock lock(mPreviewLock); |
| 818 | LOGV("%s : %d", __func__, mPreviewRunning); |
| 819 | return mPreviewRunning; |
| 820 | } |
| 821 | |
| 822 | status_t CameraHardwareSec::startRecording() |
| 823 | { |
| 824 | LOGV("%s :", __func__); |
| 825 | |
| 826 | Mutex::Autolock lock(mRecordLock); |
| 827 | |
| 828 | for(int i = 0; i<BUFFER_COUNT_FOR_ARRAY; i++){ |
| 829 | if (mRecordHeap[i] != NULL) { |
| 830 | mRecordHeap[i]->release(mRecordHeap[i]); |
| 831 | mRecordHeap[i] = 0; |
| 832 | } |
| 833 | |
| 834 | int width, height; |
| 835 | |
| 836 | mSecCamera->getRecordingSize(&width, &height); |
| 837 | mRecordHeap[i] = mGetMemoryCb(-1, (ALIGN((ALIGN(width, 16) * ALIGN(height, 16)), 2048) |
| 838 | + ALIGN((ALIGN(width, 16) * ALIGN(height >> 1, 8)), 2048)), 1, NULL); |
| 839 | mSecCamera->setUserBufferAddr((void *)(mRecordHeap[i]->data), i, RECORD_MODE); |
| 840 | if (!mRecordHeap[i]) { |
| 841 | LOGE("ERR(%s): Record heap[%d] creation fail", __func__, i); |
| 842 | return UNKNOWN_ERROR; |
| 843 | } |
| 844 | } |
| 845 | |
| 846 | LOGV("mRecordHeaps alloc done"); |
| 847 | |
| 848 | if (mRecordRunning == false) { |
| 849 | if (mSecCamera->startRecord() < 0) { |
| 850 | LOGE("ERR(%s):Fail on mSecCamera->startRecord()", __func__); |
| 851 | return UNKNOWN_ERROR; |
| 852 | } |
| 853 | mRecordRunning = true; |
| 854 | } |
| 855 | return NO_ERROR; |
| 856 | } |
| 857 | |
| 858 | void CameraHardwareSec::stopRecording() |
| 859 | { |
| 860 | LOGV("%s :", __func__); |
| 861 | |
| 862 | Mutex::Autolock lock(mRecordLock); |
| 863 | |
| 864 | if (mRecordRunning == true) { |
| 865 | if (mSecCamera->stopRecord() < 0) { |
| 866 | LOGE("ERR(%s):Fail on mSecCamera->stopRecord()", __func__); |
| 867 | return; |
| 868 | } |
| 869 | mRecordRunning = false; |
| 870 | } |
| 871 | } |
| 872 | |
| 873 | bool CameraHardwareSec::recordingEnabled() |
| 874 | { |
| 875 | LOGV("%s :", __func__); |
| 876 | LOGV("%s : %d", __func__, mPreviewRunning); |
| 877 | |
| 878 | return mRecordRunning; |
| 879 | } |
| 880 | |
| 881 | void CameraHardwareSec::releaseRecordingFrame(const void *opaque) |
| 882 | { |
| 883 | int i; |
| 884 | for (i = 0; i < MAX_BUFFERS; i++) |
| 885 | if ((char *)mRecordHeap[i]->data == (char *)opaque) |
| 886 | break; |
| 887 | |
| 888 | mSecCamera->releaseRecordFrame(i); |
| 889 | } |
| 890 | |
| 891 | int CameraHardwareSec::autoFocusThread() |
| 892 | { |
| 893 | int count =0; |
| 894 | int af_status =0 ; |
| 895 | |
| 896 | LOGV("%s : starting", __func__); |
| 897 | |
| 898 | |
| 899 | /* block until we're told to start. we don't want to use |
| 900 | * a restartable thread and requestExitAndWait() in cancelAutoFocus() |
| 901 | * because it would cause deadlock between our callbacks and the |
| 902 | * caller of cancelAutoFocus() which both want to grab the same lock |
| 903 | * in CameraServices layer. |
| 904 | */ |
| 905 | mFocusLock.lock(); |
| 906 | /* check early exit request */ |
| 907 | if (mExitAutoFocusThread) { |
| 908 | mFocusLock.unlock(); |
| 909 | LOGV("%s : exiting on request0", __func__); |
| 910 | return NO_ERROR; |
| 911 | } |
| 912 | mFocusCondition.wait(mFocusLock); |
| 913 | /* check early exit request */ |
| 914 | if (mExitAutoFocusThread) { |
| 915 | mFocusLock.unlock(); |
| 916 | LOGV("%s : exiting on request1", __func__); |
| 917 | return NO_ERROR; |
| 918 | } |
| 919 | mFocusLock.unlock(); |
| 920 | |
| 921 | #ifdef GAIA_FW_BETA |
| 922 | if (mMsgEnabled & CAMERA_MSG_FOCUS) |
| 923 | mNotifyCb(CAMERA_MSG_FOCUS, false, 0, mCallbackCookie); |
| 924 | |
| 925 | //LOGV("%s : exiting with no error", __func__); |
| 926 | return NO_ERROR; |
| 927 | #else |
| 928 | |
| 929 | #ifdef AF_SUPPORT |
| 930 | LOGV("%s : calling setAutoFocus", __func__); |
| 931 | if (mSecCamera->setAutofocus() < 0) { |
| 932 | LOGE("ERR(%s):Fail on mSecCamera->setAutofocus()", __func__); |
| 933 | return UNKNOWN_ERROR; |
| 934 | } |
| 935 | |
| 936 | af_status = mSecCamera->getAutoFocusResult(); |
| 937 | #else |
| 938 | sleep(1); |
| 939 | af_status = 0x02; |
| 940 | #endif |
| 941 | |
| 942 | if (af_status == 0x01) { |
| 943 | LOGV("%s : AF Success!!", __func__); |
| 944 | if (mMsgEnabled & CAMERA_MSG_FOCUS) |
| 945 | mNotifyCb(CAMERA_MSG_FOCUS, true, 0, mCallbackCookie); |
| 946 | } else if (af_status == 0x02) { |
| 947 | LOGV("%s : AF Cancelled !!", __func__); |
| 948 | if (mMsgEnabled & CAMERA_MSG_FOCUS) { |
| 949 | /* CAMERA_MSG_FOCUS only takes a bool. true for |
| 950 | * finished and false for failure. cancel is still |
| 951 | * considered a true result. |
| 952 | */ |
| 953 | mNotifyCb(CAMERA_MSG_FOCUS, true, 0, mCallbackCookie); |
| 954 | } |
| 955 | } else { |
| 956 | LOGV("%s : AF Fail !!", __func__); |
| 957 | LOGV("%s : mMsgEnabled = 0x%x", __func__, mMsgEnabled); |
| 958 | if (mMsgEnabled & CAMERA_MSG_FOCUS) |
| 959 | mNotifyCb(CAMERA_MSG_FOCUS, false, 0, mCallbackCookie); |
| 960 | } |
| 961 | |
| 962 | LOGV("%s : exiting with no error", __func__); |
| 963 | return NO_ERROR; |
| 964 | #endif |
| 965 | } |
| 966 | |
| 967 | status_t CameraHardwareSec::autoFocus() |
| 968 | { |
| 969 | LOGV("%s :", __func__); |
| 970 | /* signal autoFocusThread to run once */ |
| 971 | mFocusCondition.signal(); |
| 972 | return NO_ERROR; |
| 973 | } |
| 974 | |
| 975 | status_t CameraHardwareSec::cancelAutoFocus() |
| 976 | { |
| 977 | LOGV("%s :", __func__); |
| 978 | #ifndef GAIA_FW_BETA |
| 979 | |
| 980 | if (mSecCamera->cancelAutofocus() < 0) { |
| 981 | LOGE("ERR(%s):Fail on mSecCamera->cancelAutofocus()", __func__); |
| 982 | return UNKNOWN_ERROR; |
| 983 | } |
| 984 | #endif |
| 985 | return NO_ERROR; |
| 986 | } |
| 987 | |
| 988 | int CameraHardwareSec::save_jpeg( unsigned char *real_jpeg, int jpeg_size) |
| 989 | { |
| 990 | FILE *yuv_fp = NULL; |
| 991 | char filename[100], *buffer = NULL; |
| 992 | |
| 993 | /* file create/open, note to "wb" */ |
| 994 | yuv_fp = fopen("/data/camera_dump.jpeg", "wb"); |
| 995 | if (yuv_fp == NULL) { |
| 996 | LOGE("Save jpeg file open error"); |
| 997 | return -1; |
| 998 | } |
| 999 | |
| 1000 | LOGV("[BestIQ] real_jpeg size ========> %d", jpeg_size); |
| 1001 | buffer = (char *) malloc(jpeg_size); |
| 1002 | if (buffer == NULL) { |
| 1003 | LOGE("Save YUV] buffer alloc failed"); |
| 1004 | if (yuv_fp) |
| 1005 | fclose(yuv_fp); |
| 1006 | |
| 1007 | return -1; |
| 1008 | } |
| 1009 | |
| 1010 | memcpy(buffer, real_jpeg, jpeg_size); |
| 1011 | |
| 1012 | fflush(stdout); |
| 1013 | |
| 1014 | fwrite(buffer, 1, jpeg_size, yuv_fp); |
| 1015 | |
| 1016 | fflush(yuv_fp); |
| 1017 | |
| 1018 | if (yuv_fp) |
| 1019 | fclose(yuv_fp); |
| 1020 | if (buffer) |
| 1021 | free(buffer); |
| 1022 | |
| 1023 | return 0; |
| 1024 | } |
| 1025 | |
| 1026 | void CameraHardwareSec::save_postview(const char *fname, uint8_t *buf, uint32_t size) |
| 1027 | { |
| 1028 | int nw; |
| 1029 | int cnt = 0; |
| 1030 | uint32_t written = 0; |
| 1031 | |
| 1032 | LOGD("opening file [%s]", fname); |
| 1033 | int fd = open(fname, O_RDWR | O_CREAT); |
| 1034 | if (fd < 0) { |
| 1035 | LOGE("failed to create file [%s]: %s", fname, strerror(errno)); |
| 1036 | return; |
| 1037 | } |
| 1038 | |
| 1039 | LOGD("writing %d bytes to file [%s]", size, fname); |
| 1040 | while (written < size) { |
| 1041 | nw = ::write(fd, buf + written, size - written); |
| 1042 | if (nw < 0) { |
| 1043 | LOGE("failed to write to file %d [%s]: %s",written,fname, strerror(errno)); |
| 1044 | break; |
| 1045 | } |
| 1046 | written += nw; |
| 1047 | cnt++; |
| 1048 | } |
| 1049 | LOGD("done writing %d bytes to file [%s] in %d passes",size, fname, cnt); |
| 1050 | ::close(fd); |
| 1051 | } |
| 1052 | |
| 1053 | bool CameraHardwareSec::scaleDownYuv422(char *srcBuf, uint32_t srcWidth, uint32_t srcHeight, |
| 1054 | char *dstBuf, uint32_t dstWidth, uint32_t dstHeight) |
| 1055 | { |
| 1056 | int32_t step_x, step_y; |
| 1057 | int32_t iXsrc, iXdst; |
| 1058 | int32_t x, y, src_y_start_pos, dst_pos, src_pos; |
| 1059 | |
| 1060 | if (dstWidth % 2 != 0 || dstHeight % 2 != 0) { |
| 1061 | LOGE("scale_down_yuv422: invalid width, height for scaling"); |
| 1062 | return false; |
| 1063 | } |
| 1064 | |
| 1065 | step_x = srcWidth / dstWidth; |
| 1066 | step_y = srcHeight / dstHeight; |
| 1067 | |
| 1068 | dst_pos = 0; |
| 1069 | for (uint32_t y = 0; y < dstHeight; y++) { |
| 1070 | src_y_start_pos = (y * step_y * (srcWidth * 2)); |
| 1071 | |
| 1072 | for (uint32_t x = 0; x < dstWidth; x += 2) { |
| 1073 | src_pos = src_y_start_pos + (x * (step_x * 2)); |
| 1074 | |
| 1075 | dstBuf[dst_pos++] = srcBuf[src_pos ]; |
| 1076 | dstBuf[dst_pos++] = srcBuf[src_pos + 1]; |
| 1077 | dstBuf[dst_pos++] = srcBuf[src_pos + 2]; |
| 1078 | dstBuf[dst_pos++] = srcBuf[src_pos + 3]; |
| 1079 | } |
| 1080 | } |
| 1081 | |
| 1082 | return true; |
| 1083 | } |
| 1084 | |
| 1085 | bool CameraHardwareSec::YUY2toNV21(void *srcBuf, void *dstBuf, uint32_t srcWidth, uint32_t srcHeight) |
| 1086 | { |
| 1087 | int32_t x, y, src_y_start_pos, dst_cbcr_pos, dst_pos, src_pos; |
| 1088 | unsigned char *srcBufPointer = (unsigned char *)srcBuf; |
| 1089 | unsigned char *dstBufPointer = (unsigned char *)dstBuf; |
| 1090 | |
| 1091 | dst_pos = 0; |
| 1092 | dst_cbcr_pos = srcWidth*srcHeight; |
| 1093 | for (uint32_t y = 0; y < srcHeight; y++) { |
| 1094 | src_y_start_pos = (y * (srcWidth * 2)); |
| 1095 | |
| 1096 | for (uint32_t x = 0; x < (srcWidth * 2); x += 2) { |
| 1097 | src_pos = src_y_start_pos + x; |
| 1098 | |
| 1099 | dstBufPointer[dst_pos++] = srcBufPointer[src_pos]; |
| 1100 | } |
| 1101 | } |
| 1102 | for (uint32_t y = 0; y < srcHeight; y += 2) { |
| 1103 | src_y_start_pos = (y * (srcWidth * 2)); |
| 1104 | |
| 1105 | for (uint32_t x = 0; x < (srcWidth * 2); x += 4) { |
| 1106 | src_pos = src_y_start_pos + x; |
| 1107 | |
| 1108 | dstBufPointer[dst_cbcr_pos++] = srcBufPointer[src_pos + 3]; |
| 1109 | dstBufPointer[dst_cbcr_pos++] = srcBufPointer[src_pos + 1]; |
| 1110 | } |
| 1111 | } |
| 1112 | |
| 1113 | return true; |
| 1114 | } |
| 1115 | |
| 1116 | int CameraHardwareSec::pictureThread() |
| 1117 | { |
| 1118 | LOGV("%s :", __func__); |
| 1119 | |
| 1120 | int jpeg_size = 0; |
| 1121 | int ret = NO_ERROR; |
| 1122 | unsigned char *jpeg_data = NULL; |
| 1123 | int postview_offset = 0; |
| 1124 | unsigned char *postview_data = NULL; |
| 1125 | |
| 1126 | unsigned char *addr = NULL; |
| 1127 | int mPostViewWidth, mPostViewHeight, mPostViewSize; |
| 1128 | int mThumbWidth, mThumbHeight, mThumbSize; |
| 1129 | int cap_width, cap_height, cap_frame_size; |
| 1130 | |
| 1131 | unsigned int output_size = 0; |
| 1132 | |
| 1133 | mSecCamera->getPostViewConfig(&mPostViewWidth, &mPostViewHeight, &mPostViewSize); |
| 1134 | mSecCamera->getThumbnailConfig(&mThumbWidth, &mThumbHeight, &mThumbSize); |
| 1135 | int postviewHeapSize = mPostViewSize; |
| 1136 | mSecCamera->getSnapshotSize(&cap_width, &cap_height, &cap_frame_size); |
| 1137 | int mJpegHeapSize; |
| 1138 | #ifdef JPEG_FROM_SENSOR |
| 1139 | if (mSecCamera->getCameraId() == SecCamera::CAMERA_ID_BACK) |
| 1140 | mJpegHeapSize = cap_frame_size * SecCamera::getJpegRatio(); |
| 1141 | else |
| 1142 | #endif |
| 1143 | mJpegHeapSize = cap_frame_size; |
| 1144 | |
| 1145 | //sp<MemoryBase> buffer = new MemoryBase(mRawHeap, 0, mPostViewSize + 8); |
| 1146 | |
| 1147 | LOGV("[5B] mPostViewWidth = %d mPostViewHeight = %d\n",mPostViewWidth,mPostViewHeight); |
| 1148 | |
| 1149 | camera_memory_t *JpegHeap = mGetMemoryCb(-1, mJpegHeapSize, 1, 0); |
| 1150 | #ifndef GAIA_FW_BETA |
| 1151 | sp<MemoryHeapBase> PostviewHeap = new MemoryHeapBaseIon(mPostViewSize); |
| 1152 | sp<MemoryHeapBase> ThumbnailHeap = new MemoryHeapBaseIon(mThumbSize); |
| 1153 | #else |
| 1154 | sp<MemoryHeapBase> PostviewHeap = new MemoryHeapBase(mPostViewSize); |
| 1155 | sp<MemoryHeapBase> ThumbnailHeap = new MemoryHeapBase(mThumbSize); |
| 1156 | #endif |
| 1157 | |
| 1158 | if (mMsgEnabled & CAMERA_MSG_RAW_IMAGE) { |
| 1159 | int picture_size, picture_width, picture_height; |
| 1160 | mSecCamera->getSnapshotSize(&picture_width, &picture_height, &picture_size); |
| 1161 | int picture_format = mSecCamera->getSnapshotPixelFormat(); |
| 1162 | |
| 1163 | unsigned int phyAddr; |
| 1164 | |
| 1165 | // Modified the shutter sound timing for Jpeg capture |
| 1166 | #ifdef JPEG_FROM_SENSOR |
| 1167 | if (mSecCamera->getCameraId() == SecCamera::CAMERA_ID_BACK) |
| 1168 | mSecCamera->setSnapshotCmd(); |
| 1169 | if (mMsgEnabled & CAMERA_MSG_SHUTTER) |
| 1170 | mNotifyCb(CAMERA_MSG_SHUTTER, 0, 0, mCallbackCookie); |
| 1171 | if (mSecCamera->getCameraId() == SecCamera::CAMERA_ID_BACK){ |
| 1172 | jpeg_data = mSecCamera->getJpeg(&jpeg_size, &phyAddr); |
| 1173 | if (jpeg_data == NULL) { |
| 1174 | LOGE("ERR(%s):Fail on SecCamera->getSnapshot()", __func__); |
| 1175 | ret = UNKNOWN_ERROR; |
| 1176 | } |
| 1177 | } else { |
| 1178 | #endif |
| 1179 | if (mMsgEnabled & CAMERA_MSG_SHUTTER) |
| 1180 | mNotifyCb(CAMERA_MSG_SHUTTER, 0, 0, mCallbackCookie); |
| 1181 | if (mSecCamera->getSnapshotAndJpeg((unsigned char*)PostviewHeap->base(), |
| 1182 | (unsigned char*)JpegHeap->data, &output_size) < 0) { |
| 1183 | mStateLock.lock(); |
| 1184 | mCaptureInProgress = false; |
| 1185 | mStateLock.unlock(); |
| 1186 | JpegHeap->release(JpegHeap); |
| 1187 | return UNKNOWN_ERROR; |
| 1188 | } |
| 1189 | LOGI("snapshotandjpeg done"); |
| 1190 | #ifdef JPEG_FROM_SENSOR |
| 1191 | } |
| 1192 | #endif |
| 1193 | } |
| 1194 | |
| 1195 | int JpegImageSize, JpegExifSize; |
| 1196 | bool isLSISensor = false; |
| 1197 | |
| 1198 | #ifdef JPEG_FROM_SENSOR |
| 1199 | if (mSecCamera->getCameraId() == SecCamera::CAMERA_ID_BACK) { |
| 1200 | LOGV("%s, %s", __func__, (const char*)mCameraSensorName); //to check sensor name |
| 1201 | isLSISensor = !strncmp((const char*)mCameraSensorName, "S5K4ECGX", 8); |
| 1202 | if (isLSISensor) { |
| 1203 | LOGI("== Camera Sensor Detect %s - Samsung LSI SOC 5M ==", mCameraSensorName); |
| 1204 | // LSI 5M SOC |
| 1205 | if (!SplitFrame(jpeg_data, SecCamera::getInterleaveDataSize(), |
| 1206 | SecCamera::getJpegLineLength(), |
| 1207 | mPostViewWidth * 2, mPostViewWidth, |
| 1208 | JpegHeap->data, &JpegImageSize, |
| 1209 | PostviewHeap->base(), &mPostViewSize)) { |
| 1210 | JpegHeap->release(JpegHeap); |
| 1211 | return UNKNOWN_ERROR; |
| 1212 | } |
| 1213 | } else { |
| 1214 | LOGI("== Camera Sensor Detect %s Sony SOC 5M ==", mCameraSensorName); |
| 1215 | decodeInterleaveData(jpeg_data, |
| 1216 | SecCamera::getInterleaveDataSize(), |
| 1217 | mPostViewWidth, mPostViewHeight, |
| 1218 | &JpegImageSize, JpegHeap->data, PostviewHeap->base()); |
| 1219 | } |
| 1220 | } else |
| 1221 | #endif |
| 1222 | JpegImageSize = static_cast<int>(output_size); |
| 1223 | |
| 1224 | scaleDownYuv422((char *)mSecCamera->getPictureVaddr(), mPostViewWidth, mPostViewHeight, |
| 1225 | (char *)ThumbnailHeap->base(), mThumbWidth, mThumbHeight); |
| 1226 | |
| 1227 | #ifdef GAIA_FW_BETA |
| 1228 | int rawHeapSize = mPostViewSize; |
| 1229 | LOGV("mRawHeap : MemoryHeapBase(previewHeapSize(%d))", rawHeapSize); |
| 1230 | mRawHeap = mGetMemoryCb((int)mSecCamera->getCameraFd(), rawHeapSize, 1, 0); |
| 1231 | if (!mRawHeap) |
| 1232 | LOGE("ERR(%s): Raw heap creation fail", __func__); |
| 1233 | |
| 1234 | if (mMsgEnabled & CAMERA_MSG_RAW_IMAGE) |
| 1235 | mDataCb(CAMERA_MSG_RAW_IMAGE, mRawHeap, 0, NULL, mCallbackCookie); |
| 1236 | #endif |
| 1237 | |
| 1238 | mStateLock.lock(); |
| 1239 | mCaptureInProgress = false; |
| 1240 | mStateLock.unlock(); |
| 1241 | |
| 1242 | if (mMsgEnabled & CAMERA_MSG_COMPRESSED_IMAGE) { |
| 1243 | camera_memory_t *ExifHeap = |
| 1244 | mGetMemoryCb(-1, EXIF_FILE_SIZE + mThumbSize, 1, 0); |
| 1245 | |
| 1246 | JpegExifSize = mSecCamera->getExif((unsigned char *)ExifHeap->data, |
| 1247 | (unsigned char *)ThumbnailHeap->base()); |
| 1248 | LOGV("JpegExifSize=%d", JpegExifSize); |
| 1249 | |
| 1250 | if (JpegExifSize < 0) { |
| 1251 | ret = UNKNOWN_ERROR; |
| 1252 | goto out; |
| 1253 | } |
| 1254 | |
| 1255 | int mJpegHeapSize_out = JpegImageSize + JpegExifSize; |
| 1256 | camera_memory_t *JpegHeap_out = mGetMemoryCb(-1, mJpegHeapSize_out, 1, 0); |
| 1257 | |
| 1258 | unsigned char *ExifStart = (unsigned char *)JpegHeap_out->data + 2; |
| 1259 | unsigned char *ImageStart = ExifStart + JpegExifSize; |
| 1260 | |
| 1261 | memcpy(JpegHeap_out->data, JpegHeap->data, 2); |
| 1262 | memcpy(ExifStart, ExifHeap->data, JpegExifSize); |
| 1263 | memcpy(ImageStart, JpegHeap->data + 2, JpegImageSize - 2); |
| 1264 | |
| 1265 | mDataCb(CAMERA_MSG_COMPRESSED_IMAGE, JpegHeap_out, 0, NULL, mCallbackCookie); |
| 1266 | |
| 1267 | if (ExifHeap) { |
| 1268 | ExifHeap->release(ExifHeap); |
| 1269 | ExifHeap = 0; |
| 1270 | } |
| 1271 | |
| 1272 | if (JpegHeap_out) { |
| 1273 | JpegHeap_out->release(JpegHeap_out); |
| 1274 | JpegHeap_out = 0; |
| 1275 | } |
| 1276 | } |
| 1277 | |
| 1278 | LOGV("%s : pictureThread end", __func__); |
| 1279 | |
| 1280 | out: |
| 1281 | if (JpegHeap) { |
| 1282 | JpegHeap->release(JpegHeap); |
| 1283 | JpegHeap = 0; |
| 1284 | } |
| 1285 | |
| 1286 | if (mRawHeap) { |
| 1287 | mRawHeap->release(mRawHeap); |
| 1288 | mRawHeap = 0; |
| 1289 | } |
| 1290 | |
| 1291 | return ret; |
| 1292 | } |
| 1293 | |
| 1294 | status_t CameraHardwareSec::takePicture() |
| 1295 | { |
| 1296 | LOGV("%s :", __func__); |
| 1297 | |
| 1298 | stopPreview(); |
| 1299 | |
| 1300 | Mutex::Autolock lock(mStateLock); |
| 1301 | if (mCaptureInProgress) { |
| 1302 | LOGE("%s : capture already in progress", __func__); |
| 1303 | return INVALID_OPERATION; |
| 1304 | } |
| 1305 | |
| 1306 | if (mPictureThread->run("CameraPictureThread", PRIORITY_DEFAULT) != NO_ERROR) { |
| 1307 | LOGE("%s : couldn't run picture thread", __func__); |
| 1308 | return INVALID_OPERATION; |
| 1309 | } |
| 1310 | mCaptureInProgress = true; |
| 1311 | |
| 1312 | return NO_ERROR; |
| 1313 | } |
| 1314 | |
| 1315 | status_t CameraHardwareSec::cancelPicture() |
| 1316 | { |
| 1317 | LOGV("%s", __func__); |
| 1318 | |
| 1319 | if (mPictureThread.get()) { |
| 1320 | LOGV("%s: waiting for picture thread to exit", __func__); |
| 1321 | mPictureThread->requestExitAndWait(); |
| 1322 | LOGV("%s: picture thread has exited", __func__); |
| 1323 | } |
| 1324 | |
| 1325 | return NO_ERROR; |
| 1326 | } |
| 1327 | |
| 1328 | bool CameraHardwareSec::CheckVideoStartMarker(unsigned char *pBuf) |
| 1329 | { |
| 1330 | if (!pBuf) { |
| 1331 | LOGE("CheckVideoStartMarker() => pBuf is NULL"); |
| 1332 | return false; |
| 1333 | } |
| 1334 | |
| 1335 | if (HIBYTE(VIDEO_COMMENT_MARKER_H) == * pBuf && LOBYTE(VIDEO_COMMENT_MARKER_H) == *(pBuf + 1) && |
| 1336 | HIBYTE(VIDEO_COMMENT_MARKER_L) == *(pBuf + 2) && LOBYTE(VIDEO_COMMENT_MARKER_L) == *(pBuf + 3)) |
| 1337 | return true; |
| 1338 | |
| 1339 | return false; |
| 1340 | } |
| 1341 | |
| 1342 | bool CameraHardwareSec::CheckEOIMarker(unsigned char *pBuf) |
| 1343 | { |
| 1344 | if (!pBuf) { |
| 1345 | LOGE("CheckEOIMarker() => pBuf is NULL"); |
| 1346 | return false; |
| 1347 | } |
| 1348 | |
| 1349 | // EOI marker [FF D9] |
| 1350 | if (HIBYTE(JPEG_EOI_MARKER) == *pBuf && LOBYTE(JPEG_EOI_MARKER) == *(pBuf + 1)) |
| 1351 | return true; |
| 1352 | |
| 1353 | return false; |
| 1354 | } |
| 1355 | |
| 1356 | bool CameraHardwareSec::FindEOIMarkerInJPEG(unsigned char *pBuf, int dwBufSize, int *pnJPEGsize) |
| 1357 | { |
| 1358 | if (NULL == pBuf || 0 >= dwBufSize) { |
| 1359 | LOGE("FindEOIMarkerInJPEG() => There is no contents."); |
| 1360 | return false; |
| 1361 | } |
| 1362 | |
| 1363 | unsigned char *pBufEnd = pBuf + dwBufSize; |
| 1364 | |
| 1365 | while (pBuf < pBufEnd) { |
| 1366 | if (CheckEOIMarker(pBuf++)) |
| 1367 | return true; |
| 1368 | |
| 1369 | (*pnJPEGsize)++; |
| 1370 | } |
| 1371 | |
| 1372 | return false; |
| 1373 | } |
| 1374 | |
| 1375 | bool CameraHardwareSec::SplitFrame(unsigned char *pFrame, int dwSize, |
| 1376 | int dwJPEGLineLength, int dwVideoLineLength, int dwVideoHeight, |
| 1377 | void *pJPEG, int *pdwJPEGSize, |
| 1378 | void *pVideo, int *pdwVideoSize) |
| 1379 | { |
| 1380 | LOGV("===========SplitFrame Start=============="); |
| 1381 | |
| 1382 | if (NULL == pFrame || 0 >= dwSize) { |
| 1383 | LOGE("There is no contents (pFrame=%p, dwSize=%d", pFrame, dwSize); |
| 1384 | return false; |
| 1385 | } |
| 1386 | |
| 1387 | if (0 == dwJPEGLineLength || 0 == dwVideoLineLength) { |
| 1388 | LOGE("There in no input information for decoding interleaved jpeg"); |
| 1389 | return false; |
| 1390 | } |
| 1391 | |
| 1392 | unsigned char *pSrc = pFrame; |
| 1393 | unsigned char *pSrcEnd = pFrame + dwSize; |
| 1394 | |
| 1395 | unsigned char *pJ = (unsigned char *)pJPEG; |
| 1396 | int dwJSize = 0; |
| 1397 | unsigned char *pV = (unsigned char *)pVideo; |
| 1398 | int dwVSize = 0; |
| 1399 | |
| 1400 | bool bRet = false; |
| 1401 | bool isFinishJpeg = false; |
| 1402 | |
| 1403 | while (pSrc < pSrcEnd) { |
| 1404 | // Check video start marker |
| 1405 | if (CheckVideoStartMarker(pSrc)) { |
| 1406 | int copyLength; |
| 1407 | |
| 1408 | if (pSrc + dwVideoLineLength <= pSrcEnd) |
| 1409 | copyLength = dwVideoLineLength; |
| 1410 | else |
| 1411 | copyLength = pSrcEnd - pSrc - VIDEO_COMMENT_MARKER_LENGTH; |
| 1412 | |
| 1413 | // Copy video data |
| 1414 | if (pV) { |
| 1415 | memcpy(pV, pSrc + VIDEO_COMMENT_MARKER_LENGTH, copyLength); |
| 1416 | pV += copyLength; |
| 1417 | dwVSize += copyLength; |
| 1418 | } |
| 1419 | |
| 1420 | pSrc += copyLength + VIDEO_COMMENT_MARKER_LENGTH; |
| 1421 | } else { |
| 1422 | // Copy pure JPEG data |
| 1423 | int size = 0; |
| 1424 | int dwCopyBufLen = dwJPEGLineLength <= pSrcEnd-pSrc ? dwJPEGLineLength : pSrcEnd - pSrc; |
| 1425 | |
| 1426 | if (FindEOIMarkerInJPEG((unsigned char *)pSrc, dwCopyBufLen, &size)) { |
| 1427 | isFinishJpeg = true; |
| 1428 | size += 2; // to count EOF marker size |
| 1429 | } else { |
| 1430 | if ((dwCopyBufLen == 1) && (pJPEG < pJ)) { |
| 1431 | unsigned char checkBuf[2] = { *(pJ - 1), *pSrc }; |
| 1432 | |
| 1433 | if (CheckEOIMarker(checkBuf)) |
| 1434 | isFinishJpeg = true; |
| 1435 | } |
| 1436 | size = dwCopyBufLen; |
| 1437 | } |
| 1438 | |
| 1439 | memcpy(pJ, pSrc, size); |
| 1440 | |
| 1441 | dwJSize += size; |
| 1442 | |
| 1443 | pJ += dwCopyBufLen; |
| 1444 | pSrc += dwCopyBufLen; |
| 1445 | } |
| 1446 | if (isFinishJpeg) |
| 1447 | break; |
| 1448 | } |
| 1449 | |
| 1450 | if (isFinishJpeg) { |
| 1451 | bRet = true; |
| 1452 | if (pdwJPEGSize) |
| 1453 | *pdwJPEGSize = dwJSize; |
| 1454 | if (pdwVideoSize) |
| 1455 | *pdwVideoSize = dwVSize; |
| 1456 | } else { |
| 1457 | LOGE("DecodeInterleaveJPEG_WithOutDT() => Can not find EOI"); |
| 1458 | bRet = false; |
| 1459 | if (pdwJPEGSize) |
| 1460 | *pdwJPEGSize = 0; |
| 1461 | if (pdwVideoSize) |
| 1462 | *pdwVideoSize = 0; |
| 1463 | } |
| 1464 | LOGV("===========SplitFrame end=============="); |
| 1465 | |
| 1466 | return bRet; |
| 1467 | } |
| 1468 | |
| 1469 | int CameraHardwareSec::decodeInterleaveData(unsigned char *pInterleaveData, |
| 1470 | int interleaveDataSize, |
| 1471 | int yuvWidth, |
| 1472 | int yuvHeight, |
| 1473 | int *pJpegSize, |
| 1474 | void *pJpegData, |
| 1475 | void *pYuvData) |
| 1476 | { |
| 1477 | if (pInterleaveData == NULL) |
| 1478 | return false; |
| 1479 | |
| 1480 | bool ret = true; |
| 1481 | unsigned int *interleave_ptr = (unsigned int *)pInterleaveData; |
| 1482 | unsigned char *jpeg_ptr = (unsigned char *)pJpegData; |
| 1483 | unsigned char *yuv_ptr = (unsigned char *)pYuvData; |
| 1484 | unsigned char *p; |
| 1485 | int jpeg_size = 0; |
| 1486 | int yuv_size = 0; |
| 1487 | |
| 1488 | int i = 0; |
| 1489 | |
| 1490 | LOGV("decodeInterleaveData Start~~~"); |
| 1491 | while (i < interleaveDataSize) { |
| 1492 | if ((*interleave_ptr == 0xFFFFFFFF) || (*interleave_ptr == 0x02FFFFFF) || |
| 1493 | (*interleave_ptr == 0xFF02FFFF)) { |
| 1494 | // Padding Data |
| 1495 | interleave_ptr++; |
| 1496 | i += 4; |
| 1497 | } else if ((*interleave_ptr & 0xFFFF) == 0x05FF) { |
| 1498 | // Start-code of YUV Data |
| 1499 | p = (unsigned char *)interleave_ptr; |
| 1500 | p += 2; |
| 1501 | i += 2; |
| 1502 | |
| 1503 | // Extract YUV Data |
| 1504 | if (pYuvData != NULL) { |
| 1505 | memcpy(yuv_ptr, p, yuvWidth * 2); |
| 1506 | yuv_ptr += yuvWidth * 2; |
| 1507 | yuv_size += yuvWidth * 2; |
| 1508 | } |
| 1509 | p += yuvWidth * 2; |
| 1510 | i += yuvWidth * 2; |
| 1511 | |
| 1512 | // Check End-code of YUV Data |
| 1513 | if ((*p == 0xFF) && (*(p + 1) == 0x06)) { |
| 1514 | interleave_ptr = (unsigned int *)(p + 2); |
| 1515 | i += 2; |
| 1516 | } else { |
| 1517 | ret = false; |
| 1518 | break; |
| 1519 | } |
| 1520 | } else { |
| 1521 | // Extract JPEG Data |
| 1522 | if (pJpegData != NULL) { |
| 1523 | memcpy(jpeg_ptr, interleave_ptr, 4); |
| 1524 | jpeg_ptr += 4; |
| 1525 | jpeg_size += 4; |
| 1526 | } |
| 1527 | interleave_ptr++; |
| 1528 | i += 4; |
| 1529 | } |
| 1530 | } |
| 1531 | if (ret) { |
| 1532 | if (pJpegData != NULL) { |
| 1533 | // Remove Padding after EOI |
| 1534 | for (i = 0; i < 3; i++) { |
| 1535 | if (*(--jpeg_ptr) != 0xFF) { |
| 1536 | break; |
| 1537 | } |
| 1538 | jpeg_size--; |
| 1539 | } |
| 1540 | *pJpegSize = jpeg_size; |
| 1541 | |
| 1542 | } |
| 1543 | // Check YUV Data Size |
| 1544 | if (pYuvData != NULL) { |
| 1545 | if (yuv_size != (yuvWidth * yuvHeight * 2)) { |
| 1546 | ret = false; |
| 1547 | } |
| 1548 | } |
| 1549 | } |
| 1550 | LOGV("decodeInterleaveData End~~~"); |
| 1551 | return ret; |
| 1552 | } |
| 1553 | |
| 1554 | status_t CameraHardwareSec::dump(int fd) const |
| 1555 | { |
| 1556 | const size_t SIZE = 256; |
| 1557 | char buffer[SIZE]; |
| 1558 | String8 result; |
| 1559 | const Vector<String16> args; |
| 1560 | |
| 1561 | if (mSecCamera != 0) { |
| 1562 | mSecCamera->dump(fd); |
| 1563 | mParameters.dump(fd, args); |
| 1564 | mInternalParameters.dump(fd, args); |
| 1565 | snprintf(buffer, 255, " preview running(%s)\n", mPreviewRunning?"true": "false"); |
| 1566 | result.append(buffer); |
| 1567 | } else |
| 1568 | result.append("No camera client yet.\n"); |
| 1569 | write(fd, result.string(), result.size()); |
| 1570 | return NO_ERROR; |
| 1571 | } |
| 1572 | |
| 1573 | bool CameraHardwareSec::isSupportedPreviewSize(const int width, |
| 1574 | const int height) const |
| 1575 | { |
| 1576 | unsigned int i; |
| 1577 | |
| 1578 | for (i = 0; i < mSupportedPreviewSizes.size(); i++) { |
| 1579 | if (mSupportedPreviewSizes[i].width == width && |
| 1580 | mSupportedPreviewSizes[i].height == height) |
| 1581 | return true; |
| 1582 | } |
| 1583 | |
| 1584 | return false; |
| 1585 | } |
| 1586 | |
| 1587 | status_t CameraHardwareSec::setParameters(const CameraParameters& params) |
| 1588 | { |
| 1589 | LOGV("%s :", __func__); |
| 1590 | #ifndef GAIA_FW_BETA |
| 1591 | int Internal_is = !strncmp((const char*)mSecCamera->getCameraSensorName(), "ISP Camera", 10); |
| 1592 | #else |
| 1593 | int Internal_is = 0; |
| 1594 | #endif |
| 1595 | status_t ret = NO_ERROR; |
| 1596 | |
| 1597 | /* if someone calls us while picture thread is running, it could screw |
| 1598 | * up the sensor quite a bit so return error. we can't wait because |
| 1599 | * that would cause deadlock with the callbacks |
| 1600 | */ |
| 1601 | mStateLock.lock(); |
| 1602 | if (mCaptureInProgress) { |
| 1603 | mStateLock.unlock(); |
| 1604 | LOGE("%s : capture in progress, not allowed", __func__); |
| 1605 | return UNKNOWN_ERROR; |
| 1606 | } |
| 1607 | mStateLock.unlock(); |
| 1608 | |
| 1609 | // preview size |
| 1610 | #ifdef GAIA_FW_BETA |
| 1611 | int new_preview_width = 1920; |
| 1612 | int new_preview_height = 1080; |
| 1613 | #else |
| 1614 | int new_preview_width = 0; |
| 1615 | int new_preview_height = 0; |
| 1616 | params.getPreviewSize(&new_preview_width, &new_preview_height); |
| 1617 | #endif |
| 1618 | const char *new_str_preview_format = params.getPreviewFormat(); |
| 1619 | LOGV("%s : new_preview_width x new_preview_height = %dx%d, format = %s", |
| 1620 | __func__, new_preview_width, new_preview_height, new_str_preview_format); |
| 1621 | |
| 1622 | if (0 < new_preview_width && 0 < new_preview_height && |
| 1623 | new_str_preview_format != NULL && |
| 1624 | isSupportedPreviewSize(new_preview_width, new_preview_height)) { |
| 1625 | int new_preview_format = 0; |
| 1626 | |
| 1627 | mFrameSizeDelta = 16; |
| 1628 | if (!strcmp(new_str_preview_format, |
| 1629 | CameraParameters::PIXEL_FORMAT_RGB565)) { |
| 1630 | new_preview_format = V4L2_PIX_FMT_RGB565; |
| 1631 | mFrameSizeDelta = 0; |
| 1632 | } |
| 1633 | else if (!strcmp(new_str_preview_format, |
| 1634 | CameraParameters::PIXEL_FORMAT_RGBA8888)) { |
| 1635 | new_preview_format = V4L2_PIX_FMT_RGB32; |
| 1636 | mFrameSizeDelta = 0; |
| 1637 | } |
| 1638 | else if (!strcmp(new_str_preview_format, |
| 1639 | CameraParameters::PIXEL_FORMAT_YUV420SP)) |
| 1640 | new_preview_format = V4L2_PIX_FMT_NV21; |
| 1641 | else if (!strcmp(new_str_preview_format, |
| 1642 | CameraParameters::PIXEL_FORMAT_YUV420P)) |
| 1643 | new_preview_format = V4L2_PIX_FMT_YVU420M; |
| 1644 | |
| 1645 | else if (!strcmp(new_str_preview_format, "yuv420sp_custom")) |
| 1646 | new_preview_format = V4L2_PIX_FMT_NV12T; |
| 1647 | else if (!strcmp(new_str_preview_format, "yuv422i")) |
| 1648 | new_preview_format = V4L2_PIX_FMT_YUYV; |
| 1649 | else if (!strcmp(new_str_preview_format, "yuv422p")) |
| 1650 | new_preview_format = V4L2_PIX_FMT_YUV422P; |
| 1651 | else |
| 1652 | new_preview_format = V4L2_PIX_FMT_NV21; //for 3rd party |
| 1653 | |
| 1654 | int current_preview_width, current_preview_height, current_frame_size; |
| 1655 | mSecCamera->getPreviewSize(¤t_preview_width, |
| 1656 | ¤t_preview_height, |
| 1657 | ¤t_frame_size); |
| 1658 | int current_pixel_format = mSecCamera->getPreviewPixelFormat(); |
| 1659 | |
| 1660 | if (current_preview_width != new_preview_width || |
| 1661 | current_preview_height != new_preview_height || |
| 1662 | current_pixel_format != new_preview_format) { |
| 1663 | if (mSecCamera->setPreviewSize(new_preview_width, new_preview_height, |
| 1664 | new_preview_format) < 0) { |
| 1665 | LOGE("ERR(%s):Fail on mSecCamera->setPreviewSize(width(%d), height(%d), format(%d))", |
| 1666 | __func__, new_preview_width, new_preview_height, new_preview_format); |
| 1667 | ret = UNKNOWN_ERROR; |
| 1668 | } else { |
| 1669 | if (mPreviewWindow) { |
| 1670 | if (mPreviewRunning && !mPreviewStartDeferred) { |
| 1671 | LOGE("ERR(%s): preview is running, cannot change size and format!", |
| 1672 | __func__); |
| 1673 | ret = INVALID_OPERATION; |
| 1674 | } |
| 1675 | |
| 1676 | LOGV("%s: mPreviewWindow (%p) set_buffers_geometry", __func__, mPreviewWindow); |
| 1677 | LOGV("%s: mPreviewWindow->set_buffers_geometry (%p)", __func__, |
| 1678 | mPreviewWindow->set_buffers_geometry); |
| 1679 | mPreviewWindow->set_buffers_geometry(mPreviewWindow, |
| 1680 | new_preview_width, new_preview_height, |
| 1681 | new_preview_format); |
| 1682 | LOGV("%s: DONE mPreviewWindow (%p) set_buffers_geometry", __func__, mPreviewWindow); |
| 1683 | } |
| 1684 | mParameters.setPreviewSize(new_preview_width, new_preview_height); |
| 1685 | mParameters.setPreviewFormat(new_str_preview_format); |
| 1686 | } |
| 1687 | } |
| 1688 | else LOGV("%s: preview size and format has not changed", __func__); |
| 1689 | } else { |
| 1690 | LOGE("%s: Invalid preview size(%dx%d)", |
| 1691 | __func__, new_preview_width, new_preview_height); |
| 1692 | |
| 1693 | ret = INVALID_OPERATION; |
| 1694 | } |
| 1695 | |
| 1696 | #ifndef GAIA_FW_BETA |
| 1697 | int new_picture_width = 0; |
| 1698 | int new_picture_height = 0; |
| 1699 | |
| 1700 | params.getPictureSize(&new_picture_width, &new_picture_height); |
| 1701 | LOGV("%s : new_picture_width x new_picture_height = %dx%d", __func__, new_picture_width, new_picture_height); |
| 1702 | if (0 < new_picture_width && 0 < new_picture_height) { |
| 1703 | LOGV("%s: setSnapshotSize", __func__); |
| 1704 | if (mSecCamera->setSnapshotSize(new_picture_width, new_picture_height) < 0) { |
| 1705 | LOGE("ERR(%s):Fail on mSecCamera->setSnapshotSize(width(%d), height(%d))", |
| 1706 | __func__, new_picture_width, new_picture_height); |
| 1707 | ret = UNKNOWN_ERROR; |
| 1708 | } else |
| 1709 | mParameters.setPictureSize(new_picture_width, new_picture_height); |
| 1710 | } |
| 1711 | |
| 1712 | // picture format |
| 1713 | const char *new_str_picture_format = params.getPictureFormat(); |
| 1714 | LOGV("%s : new_str_picture_format %s", __func__, new_str_picture_format); |
| 1715 | if (new_str_picture_format != NULL) { |
| 1716 | int new_picture_format = 0; |
| 1717 | |
| 1718 | if (!strcmp(new_str_picture_format, CameraParameters::PIXEL_FORMAT_RGB565)) |
| 1719 | new_picture_format = V4L2_PIX_FMT_RGB565; |
| 1720 | else if (!strcmp(new_str_picture_format, CameraParameters::PIXEL_FORMAT_RGBA8888)) |
| 1721 | new_picture_format = V4L2_PIX_FMT_RGB32; |
| 1722 | else if (!strcmp(new_str_picture_format, CameraParameters::PIXEL_FORMAT_YUV420SP)) |
| 1723 | new_picture_format = V4L2_PIX_FMT_NV21; |
| 1724 | else if (!strcmp(new_str_picture_format, "yuv420sp_custom")) |
| 1725 | new_picture_format = V4L2_PIX_FMT_NV12T; |
| 1726 | else if (!strcmp(new_str_picture_format, "yuv420p")) |
| 1727 | new_picture_format = V4L2_PIX_FMT_YUV420; |
| 1728 | else if (!strcmp(new_str_picture_format, "yuv422i")) |
| 1729 | new_picture_format = V4L2_PIX_FMT_YUYV; |
| 1730 | else if (!strcmp(new_str_picture_format, "uyv422i_custom")) //Zero copy UYVY format |
| 1731 | new_picture_format = V4L2_PIX_FMT_UYVY; |
| 1732 | else if (!strcmp(new_str_picture_format, "uyv422i")) //Non-zero copy UYVY format |
| 1733 | new_picture_format = V4L2_PIX_FMT_UYVY; |
| 1734 | else if (!strcmp(new_str_picture_format, CameraParameters::PIXEL_FORMAT_JPEG)) |
| 1735 | new_picture_format = V4L2_PIX_FMT_YUYV; |
| 1736 | else if (!strcmp(new_str_picture_format, "yuv422p")) |
| 1737 | new_picture_format = V4L2_PIX_FMT_YUV422P; |
| 1738 | else |
| 1739 | new_picture_format = V4L2_PIX_FMT_NV21; //for 3rd party |
| 1740 | |
| 1741 | if (mSecCamera->setSnapshotPixelFormat(new_picture_format) < 0) { |
| 1742 | LOGE("ERR(%s):Fail on mSecCamera->setSnapshotPixelFormat(format(%d))", __func__, new_picture_format); |
| 1743 | ret = UNKNOWN_ERROR; |
| 1744 | } else |
| 1745 | mParameters.setPictureFormat(new_str_picture_format); |
| 1746 | } |
| 1747 | |
| 1748 | // JPEG image quality |
| 1749 | int new_jpeg_quality = params.getInt(CameraParameters::KEY_JPEG_QUALITY); |
| 1750 | LOGV("%s : new_jpeg_quality %d", __func__, new_jpeg_quality); |
| 1751 | /* we ignore bad values */ |
| 1752 | if (new_jpeg_quality >=1 && new_jpeg_quality <= 100) { |
| 1753 | if (mSecCamera->setJpegQuality(new_jpeg_quality) < 0) { |
| 1754 | LOGE("ERR(%s):Fail on mSecCamera->setJpegQuality(quality(%d))", __func__, new_jpeg_quality); |
| 1755 | ret = UNKNOWN_ERROR; |
| 1756 | } else |
| 1757 | mParameters.set(CameraParameters::KEY_JPEG_QUALITY, new_jpeg_quality); |
| 1758 | } |
| 1759 | |
| 1760 | // JPEG thumbnail size |
| 1761 | int new_jpeg_thumbnail_width = params.getInt(CameraParameters::KEY_JPEG_THUMBNAIL_WIDTH); |
| 1762 | int new_jpeg_thumbnail_height= params.getInt(CameraParameters::KEY_JPEG_THUMBNAIL_HEIGHT); |
| 1763 | if (0 <= new_jpeg_thumbnail_width && 0 <= new_jpeg_thumbnail_height) { |
| 1764 | if (mSecCamera->setJpegThumbnailSize(new_jpeg_thumbnail_width, new_jpeg_thumbnail_height) < 0) { |
| 1765 | LOGE("ERR(%s):Fail on mSecCamera->setJpegThumbnailSize(width(%d), height(%d))", __func__, new_jpeg_thumbnail_width, new_jpeg_thumbnail_height); |
| 1766 | ret = UNKNOWN_ERROR; |
| 1767 | } else { |
| 1768 | mParameters.set(CameraParameters::KEY_JPEG_THUMBNAIL_WIDTH, new_jpeg_thumbnail_width); |
| 1769 | mParameters.set(CameraParameters::KEY_JPEG_THUMBNAIL_HEIGHT, new_jpeg_thumbnail_height); |
| 1770 | } |
| 1771 | } |
| 1772 | |
| 1773 | // JPEG thumbnail quality |
| 1774 | int new_jpeg_thumbnail_quality = params.getInt(CameraParameters::KEY_JPEG_THUMBNAIL_QUALITY); |
| 1775 | LOGV("%s : new_jpeg_thumbnail_quality %d", __func__, new_jpeg_thumbnail_quality); |
| 1776 | /* we ignore bad values */ |
| 1777 | if (new_jpeg_thumbnail_quality >=1 && new_jpeg_thumbnail_quality <= 100) { |
| 1778 | if (mSecCamera->setJpegThumbnailQuality(new_jpeg_thumbnail_quality) < 0) { |
| 1779 | LOGE("ERR(%s):Fail on mSecCamera->setJpegThumbnailQuality(quality(%d))", |
| 1780 | __func__, new_jpeg_thumbnail_quality); |
| 1781 | ret = UNKNOWN_ERROR; |
| 1782 | } else |
| 1783 | mParameters.set(CameraParameters::KEY_JPEG_THUMBNAIL_QUALITY, new_jpeg_thumbnail_quality); |
| 1784 | } |
| 1785 | |
| 1786 | // frame rate |
| 1787 | int new_frame_rate = params.getPreviewFrameRate(); |
| 1788 | /* ignore any fps request, we're determine fps automatically based |
| 1789 | * on scene mode. don't return an error because it causes CTS failure. |
| 1790 | */ |
| 1791 | if (new_frame_rate != mParameters.getPreviewFrameRate()) { |
| 1792 | if (mSecCamera->setFrameRate(new_frame_rate) < 0){ |
| 1793 | LOGE("ERR(%s):Fail on mSecCamera->setFrameRate(%d)", __func__, new_frame_rate); |
| 1794 | ret = UNKNOWN_ERROR; |
| 1795 | } else { |
| 1796 | mParameters.setPreviewFrameRate(new_frame_rate); |
| 1797 | } |
| 1798 | } |
| 1799 | |
| 1800 | // rotation |
| 1801 | int new_rotation = params.getInt(CameraParameters::KEY_ROTATION); |
| 1802 | LOGV("%s : new_rotation %d", __func__, new_rotation); |
| 1803 | if (0 <= new_rotation) { |
| 1804 | LOGV("%s : set orientation:%d", __func__, new_rotation); |
| 1805 | if (mSecCamera->setExifOrientationInfo(new_rotation) < 0) { |
| 1806 | LOGE("ERR(%s):Fail on mSecCamera->setExifOrientationInfo(%d)", __func__, new_rotation); |
| 1807 | ret = UNKNOWN_ERROR; |
| 1808 | } else |
| 1809 | mParameters.set(CameraParameters::KEY_ROTATION, new_rotation); |
| 1810 | } |
| 1811 | |
| 1812 | // brightness |
| 1813 | int new_brightness = params.getInt("brightness"); |
| 1814 | int max_brightness = params.getInt("brightness-max"); |
| 1815 | int min_brightness = params.getInt("brightness-min"); |
| 1816 | LOGV("%s : new_brightness %d", __func__, new_brightness); |
| 1817 | if ((min_brightness <= new_brightness) && |
| 1818 | (max_brightness >= new_brightness)) { |
| 1819 | if (mSecCamera->setBrightness(new_brightness) < 0) { |
| 1820 | LOGE("ERR(%s):Fail on mSecCamera->setBrightness(brightness(%d))", __func__, new_brightness); |
| 1821 | ret = UNKNOWN_ERROR; |
| 1822 | } else { |
| 1823 | mParameters.set("brightness", new_brightness); |
| 1824 | } |
| 1825 | } |
| 1826 | |
| 1827 | // saturation |
| 1828 | int new_saturation = params.getInt("saturation"); |
| 1829 | int max_saturation = params.getInt("saturation-max"); |
| 1830 | int min_saturation = params.getInt("saturation-min"); |
| 1831 | LOGV("%s : new_saturation %d", __func__, new_saturation); |
| 1832 | if ((min_saturation <= new_saturation) && |
| 1833 | (max_saturation >= new_saturation)) { |
| 1834 | if (mSecCamera->setSaturation(new_saturation) < 0) { |
| 1835 | LOGE("ERR(%s):Fail on mSecCamera->setSaturation(saturation(%d))", __func__, new_saturation); |
| 1836 | ret = UNKNOWN_ERROR; |
| 1837 | } else { |
| 1838 | mParameters.set("saturation", new_saturation); |
| 1839 | } |
| 1840 | } |
| 1841 | |
| 1842 | // sharpness |
| 1843 | int new_sharpness = params.getInt("sharpness"); |
| 1844 | int max_sharpness = params.getInt("sharpness-max"); |
| 1845 | int min_sharpness = params.getInt("sharpness-min"); |
| 1846 | LOGV("%s : new_sharpness %d", __func__, new_sharpness); |
| 1847 | if ((min_sharpness <= new_sharpness) && |
| 1848 | (max_sharpness >= new_sharpness)) { |
| 1849 | if (mSecCamera->setSharpness(new_sharpness) < 0) { |
| 1850 | LOGE("ERR(%s):Fail on mSecCamera->setSharpness(sharpness(%d))", __func__, new_sharpness); |
| 1851 | ret = UNKNOWN_ERROR; |
| 1852 | } else { |
| 1853 | mParameters.set("sharpness", new_sharpness); |
| 1854 | } |
| 1855 | } |
| 1856 | |
| 1857 | // hue |
| 1858 | int new_hue = params.getInt("hue"); |
| 1859 | int max_hue = params.getInt("hue-max"); |
| 1860 | int min_hue = params.getInt("hue-min"); |
| 1861 | LOGV("%s : new_hue %d", __func__, new_hue); |
| 1862 | if ((min_hue <= new_hue) && |
| 1863 | (max_hue >= new_hue)) { |
| 1864 | if (mSecCamera->setHue(new_hue) < 0) { |
| 1865 | LOGE("ERR(%s):Fail on mSecCamera->setHue(hue(%d))", __func__, new_hue); |
| 1866 | ret = UNKNOWN_ERROR; |
| 1867 | } else { |
| 1868 | mParameters.set("hue", new_hue); |
| 1869 | } |
| 1870 | } |
| 1871 | |
| 1872 | // exposure |
| 1873 | int new_exposure_compensation = params.getInt(CameraParameters::KEY_EXPOSURE_COMPENSATION); |
| 1874 | int max_exposure_compensation = params.getInt(CameraParameters::KEY_MAX_EXPOSURE_COMPENSATION); |
| 1875 | int min_exposure_compensation = params.getInt(CameraParameters::KEY_MIN_EXPOSURE_COMPENSATION); |
| 1876 | LOGV("%s : new_exposure_compensation %d", __func__, new_exposure_compensation); |
| 1877 | if ((min_exposure_compensation <= new_exposure_compensation) && |
| 1878 | (max_exposure_compensation >= new_exposure_compensation)) { |
| 1879 | if (mSecCamera->setExposure(new_exposure_compensation) < 0) { |
| 1880 | LOGE("ERR(%s):Fail on mSecCamera->setExposure(exposure(%d))", __func__, new_exposure_compensation); |
| 1881 | ret = UNKNOWN_ERROR; |
| 1882 | } else { |
| 1883 | mParameters.set(CameraParameters::KEY_EXPOSURE_COMPENSATION, new_exposure_compensation); |
| 1884 | } |
| 1885 | } |
| 1886 | |
| 1887 | // ISO |
| 1888 | const char *new_iso_str = params.get("iso"); |
| 1889 | LOGV("%s : new_iso_str %s", __func__, new_iso_str); |
| 1890 | if (new_iso_str != NULL) { |
| 1891 | int new_iso = -1; |
| 1892 | |
| 1893 | if (!strcmp(new_iso_str, "auto")) { |
| 1894 | if (Internal_is) |
| 1895 | new_iso = IS_ISO_AUTO; |
| 1896 | else |
| 1897 | new_iso = ISO_AUTO; |
| 1898 | } else if (!strcmp(new_iso_str, "50")) { |
| 1899 | if (Internal_is) |
| 1900 | new_iso = IS_ISO_50; |
| 1901 | else |
| 1902 | new_iso = ISO_50; |
| 1903 | } else if (!strcmp(new_iso_str, "100")) { |
| 1904 | if (Internal_is) |
| 1905 | new_iso = IS_ISO_100; |
| 1906 | else |
| 1907 | new_iso = ISO_100; |
| 1908 | } else if (!strcmp(new_iso_str, "200")) { |
| 1909 | if (Internal_is) |
| 1910 | new_iso = IS_ISO_200; |
| 1911 | else |
| 1912 | new_iso = ISO_200; |
| 1913 | } else if (!strcmp(new_iso_str, "400")) { |
| 1914 | if (Internal_is) |
| 1915 | new_iso = IS_ISO_400; |
| 1916 | else |
| 1917 | new_iso = ISO_400; |
| 1918 | } else if (!strcmp(new_iso_str, "800")) { |
| 1919 | if (Internal_is) |
| 1920 | new_iso = IS_ISO_800; |
| 1921 | else |
| 1922 | new_iso = ISO_800; |
| 1923 | } else if (!strcmp(new_iso_str, "1600")) { |
| 1924 | if (Internal_is) |
| 1925 | new_iso = IS_ISO_1600; |
| 1926 | else |
| 1927 | new_iso = ISO_1600; |
| 1928 | } else { |
| 1929 | LOGE("ERR(%s):Invalid iso value(%s)", __func__, new_iso_str); |
| 1930 | ret = UNKNOWN_ERROR; |
| 1931 | } |
| 1932 | |
| 1933 | if (0 <= new_iso) { |
| 1934 | if (mSecCamera->setISO(new_iso) < 0) { |
| 1935 | LOGE("ERR(%s):Fail on mSecCamera->setISO(iso(%d))", __func__, new_iso); |
| 1936 | ret = UNKNOWN_ERROR; |
| 1937 | } else { |
| 1938 | mParameters.set("iso", new_iso_str); |
| 1939 | } |
| 1940 | } |
| 1941 | } |
| 1942 | |
| 1943 | // whitebalance |
| 1944 | const char *new_white_str = params.get(CameraParameters::KEY_WHITE_BALANCE); |
| 1945 | LOGV("%s : new_white_str %s", __func__, new_white_str); |
| 1946 | if (new_white_str != NULL) { |
| 1947 | int new_white = -1; |
| 1948 | |
| 1949 | if (!strcmp(new_white_str, CameraParameters::WHITE_BALANCE_AUTO)) { |
| 1950 | if (Internal_is) |
| 1951 | new_white = IS_AWB_AUTO; |
| 1952 | else |
| 1953 | new_white = WHITE_BALANCE_AUTO; |
| 1954 | } else if (!strcmp(new_white_str, |
| 1955 | CameraParameters::WHITE_BALANCE_DAYLIGHT)) { |
| 1956 | if (Internal_is) |
| 1957 | new_white = IS_AWB_DAYLIGHT; |
| 1958 | else |
| 1959 | new_white = WHITE_BALANCE_SUNNY; |
| 1960 | } else if (!strcmp(new_white_str, |
| 1961 | CameraParameters::WHITE_BALANCE_CLOUDY_DAYLIGHT)) { |
| 1962 | if (Internal_is) |
| 1963 | new_white = IS_AWB_CLOUDY; |
| 1964 | else |
| 1965 | new_white = WHITE_BALANCE_CLOUDY; |
| 1966 | } else if (!strcmp(new_white_str, |
| 1967 | CameraParameters::WHITE_BALANCE_FLUORESCENT)) { |
| 1968 | if (Internal_is) |
| 1969 | new_white = IS_AWB_FLUORESCENT; |
| 1970 | else |
| 1971 | new_white = WHITE_BALANCE_FLUORESCENT; |
| 1972 | } else if (!strcmp(new_white_str, |
| 1973 | CameraParameters::WHITE_BALANCE_INCANDESCENT)) { |
| 1974 | if (Internal_is) |
| 1975 | new_white = IS_AWB_TUNGSTEN; |
| 1976 | else |
| 1977 | new_white = WHITE_BALANCE_TUNGSTEN; |
| 1978 | } else { |
| 1979 | LOGE("ERR(%s):Invalid white balance(%s)", __func__, new_white_str); //twilight, shade, warm_flourescent |
| 1980 | ret = UNKNOWN_ERROR; |
| 1981 | } |
| 1982 | |
| 1983 | if (0 <= new_white) { |
| 1984 | if (mSecCamera->setWhiteBalance(new_white) < 0) { |
| 1985 | LOGE("ERR(%s):Fail on mSecCamera->setWhiteBalance(white(%d))", __func__, new_white); |
| 1986 | ret = UNKNOWN_ERROR; |
| 1987 | } else { |
| 1988 | mParameters.set(CameraParameters::KEY_WHITE_BALANCE, new_white_str); |
| 1989 | } |
| 1990 | } |
| 1991 | } |
| 1992 | |
| 1993 | // Metering |
| 1994 | const char *new_metering_str = params.get("metering"); |
| 1995 | LOGV("%s : new_metering_str %s", __func__, new_metering_str); |
| 1996 | if (new_metering_str != NULL) { |
| 1997 | int new_metering = -1; |
| 1998 | |
| 1999 | if (!strcmp(new_metering_str, "center")) { |
| 2000 | if (Internal_is) |
| 2001 | new_metering = IS_METERING_AVERAGE; |
| 2002 | else |
| 2003 | new_metering = METERING_CENTER; |
| 2004 | } else if (!strcmp(new_metering_str, "spot")) { |
| 2005 | if (Internal_is) |
| 2006 | new_metering = IS_METERING_SPOT; |
| 2007 | else |
| 2008 | new_metering = METERING_SPOT; |
| 2009 | } else if (!strcmp(new_metering_str, "matrix")) { |
| 2010 | if (Internal_is) |
| 2011 | new_metering = IS_METERING_MATRIX; |
| 2012 | else |
| 2013 | new_metering = METERING_MATRIX; |
| 2014 | } else { |
| 2015 | LOGE("ERR(%s):Invalid metering value(%s)", __func__, new_metering_str); |
| 2016 | ret = UNKNOWN_ERROR; |
| 2017 | } |
| 2018 | |
| 2019 | if (0 <= new_metering) { |
| 2020 | if (mSecCamera->setMetering(new_metering) < 0) { |
| 2021 | LOGE("ERR(%s):Fail on mSecCamera->setMetering(metering(%d))", __func__, new_metering); |
| 2022 | ret = UNKNOWN_ERROR; |
| 2023 | } else { |
| 2024 | mParameters.set("metering", new_metering_str); |
| 2025 | } |
| 2026 | } |
| 2027 | } |
| 2028 | |
| 2029 | // AFC |
| 2030 | const char *new_antibanding_str = params.get(CameraParameters::KEY_ANTIBANDING); |
| 2031 | LOGV("%s : new_antibanding_str %s", __func__, new_antibanding_str); |
| 2032 | if (new_antibanding_str != NULL) { |
| 2033 | int new_antibanding = -1; |
| 2034 | |
| 2035 | if (!strcmp(new_antibanding_str, CameraParameters::ANTIBANDING_AUTO)) { |
| 2036 | if (Internal_is) |
| 2037 | new_antibanding = IS_AFC_AUTO; |
| 2038 | else |
| 2039 | new_antibanding = ANTI_BANDING_AUTO; |
| 2040 | } else if (!strcmp(new_antibanding_str, CameraParameters::ANTIBANDING_50HZ)) { |
| 2041 | if (Internal_is) |
| 2042 | new_antibanding = IS_AFC_MANUAL_50HZ; |
| 2043 | else |
| 2044 | new_antibanding = ANTI_BANDING_50HZ; |
| 2045 | } else if (!strcmp(new_antibanding_str, CameraParameters::ANTIBANDING_60HZ)) { |
| 2046 | if (Internal_is) |
| 2047 | new_antibanding = IS_AFC_MANUAL_60HZ; |
| 2048 | else |
| 2049 | new_antibanding = ANTI_BANDING_60HZ; |
| 2050 | } else if (!strcmp(new_antibanding_str, CameraParameters::ANTIBANDING_OFF)) { |
| 2051 | if (Internal_is) |
| 2052 | new_antibanding = IS_AFC_DISABLE; |
| 2053 | else |
| 2054 | new_antibanding = ANTI_BANDING_OFF; |
| 2055 | } else { |
| 2056 | LOGE("ERR(%s):Invalid antibanding value(%s)", __func__, new_antibanding_str); |
| 2057 | ret = UNKNOWN_ERROR; |
| 2058 | } |
| 2059 | |
| 2060 | if (0 <= new_antibanding) { |
| 2061 | if (mSecCamera->setAntiBanding(new_antibanding) < 0) { |
| 2062 | LOGE("ERR(%s):Fail on mSecCamera->setAntiBanding(antibanding(%d))", __func__, new_antibanding); |
| 2063 | ret = UNKNOWN_ERROR; |
| 2064 | } else { |
| 2065 | mParameters.set(CameraParameters::KEY_ANTIBANDING, new_antibanding_str); |
| 2066 | } |
| 2067 | } |
| 2068 | } |
| 2069 | |
| 2070 | // scene mode |
| 2071 | const char *new_scene_mode_str = params.get(CameraParameters::KEY_SCENE_MODE); |
| 2072 | const char *current_scene_mode_str = mParameters.get(CameraParameters::KEY_SCENE_MODE); |
| 2073 | |
| 2074 | // fps range |
| 2075 | int new_min_fps = 0; |
| 2076 | int new_max_fps = 0; |
| 2077 | int current_min_fps, current_max_fps; |
| 2078 | params.getPreviewFpsRange(&new_min_fps, &new_max_fps); |
| 2079 | mParameters.getPreviewFpsRange(¤t_min_fps, ¤t_max_fps); |
| 2080 | /* our fps range is determined by the sensor, reject any request |
| 2081 | * that isn't exactly what we're already at. |
| 2082 | * but the check is performed when requesting only changing fps range |
| 2083 | */ |
| 2084 | if (new_scene_mode_str && current_scene_mode_str) { |
| 2085 | if (!strcmp(new_scene_mode_str, current_scene_mode_str)) { |
| 2086 | if ((new_min_fps != current_min_fps) || (new_max_fps != current_max_fps)) { |
| 2087 | LOGW("%s : requested new_min_fps = %d, new_max_fps = %d not allowed", |
| 2088 | __func__, new_min_fps, new_max_fps); |
| 2089 | LOGE("%s : current_min_fps = %d, current_max_fps = %d", |
| 2090 | __func__, current_min_fps, current_max_fps); |
| 2091 | ret = UNKNOWN_ERROR; |
| 2092 | } |
| 2093 | } |
| 2094 | } else { |
| 2095 | /* Check basic validation if scene mode is different */ |
| 2096 | if ((new_min_fps > new_max_fps) || |
| 2097 | (new_min_fps < 0) || (new_max_fps < 0)) |
| 2098 | ret = UNKNOWN_ERROR; |
| 2099 | } |
| 2100 | |
| 2101 | if (new_scene_mode_str != NULL) { |
| 2102 | int new_scene_mode = -1; |
| 2103 | |
| 2104 | const char *new_flash_mode_str = params.get(CameraParameters::KEY_FLASH_MODE); |
| 2105 | const char *new_focus_mode_str; |
| 2106 | |
| 2107 | new_focus_mode_str = params.get(CameraParameters::KEY_FOCUS_MODE); |
| 2108 | // fps range is (15000,30000) by default. |
| 2109 | mParameters.set(CameraParameters::KEY_SUPPORTED_PREVIEW_FPS_RANGE, "(15000,30000)"); |
| 2110 | mParameters.set(CameraParameters::KEY_PREVIEW_FPS_RANGE, |
| 2111 | "15000,30000"); |
| 2112 | |
| 2113 | if (!strcmp(new_scene_mode_str, CameraParameters::SCENE_MODE_AUTO)) { |
| 2114 | new_scene_mode = SCENE_MODE_NONE; |
| 2115 | } else { |
| 2116 | // defaults for non-auto scene modes |
| 2117 | if (mSecCamera->getCameraId() == SecCamera::CAMERA_ID_BACK) { |
| 2118 | new_focus_mode_str = CameraParameters::FOCUS_MODE_AUTO; |
| 2119 | } |
| 2120 | new_flash_mode_str = CameraParameters::FLASH_MODE_OFF; |
| 2121 | |
| 2122 | if (!strcmp(new_scene_mode_str, |
| 2123 | CameraParameters::SCENE_MODE_PORTRAIT)) { |
| 2124 | new_scene_mode = SCENE_MODE_PORTRAIT; |
| 2125 | new_flash_mode_str = CameraParameters::FLASH_MODE_AUTO; |
| 2126 | } else if (!strcmp(new_scene_mode_str, |
| 2127 | CameraParameters::SCENE_MODE_LANDSCAPE)) { |
| 2128 | new_scene_mode = SCENE_MODE_LANDSCAPE; |
| 2129 | } else if (!strcmp(new_scene_mode_str, |
| 2130 | CameraParameters::SCENE_MODE_SPORTS)) { |
| 2131 | new_scene_mode = SCENE_MODE_SPORTS; |
| 2132 | } else if (!strcmp(new_scene_mode_str, |
| 2133 | CameraParameters::SCENE_MODE_PARTY)) { |
| 2134 | new_scene_mode = SCENE_MODE_PARTY_INDOOR; |
| 2135 | new_flash_mode_str = CameraParameters::FLASH_MODE_AUTO; |
| 2136 | } else if ((!strcmp(new_scene_mode_str, |
| 2137 | CameraParameters::SCENE_MODE_BEACH)) || |
| 2138 | (!strcmp(new_scene_mode_str, |
| 2139 | CameraParameters::SCENE_MODE_SNOW))) { |
| 2140 | new_scene_mode = SCENE_MODE_BEACH_SNOW; |
| 2141 | } else if (!strcmp(new_scene_mode_str, |
| 2142 | CameraParameters::SCENE_MODE_SUNSET)) { |
| 2143 | new_scene_mode = SCENE_MODE_SUNSET; |
| 2144 | } else if (!strcmp(new_scene_mode_str, |
| 2145 | CameraParameters::SCENE_MODE_NIGHT)) { |
| 2146 | new_scene_mode = SCENE_MODE_NIGHTSHOT; |
| 2147 | mParameters.set(CameraParameters::KEY_SUPPORTED_PREVIEW_FPS_RANGE, "(4000,30000)"); |
| 2148 | mParameters.set(CameraParameters::KEY_PREVIEW_FPS_RANGE, |
| 2149 | "4000,30000"); |
| 2150 | } else if (!strcmp(new_scene_mode_str, |
| 2151 | CameraParameters::SCENE_MODE_FIREWORKS)) { |
| 2152 | new_scene_mode = SCENE_MODE_FIREWORKS; |
| 2153 | } else if (!strcmp(new_scene_mode_str, |
| 2154 | CameraParameters::SCENE_MODE_CANDLELIGHT)) { |
| 2155 | new_scene_mode = SCENE_MODE_CANDLE_LIGHT; |
| 2156 | } else { |
| 2157 | LOGE("%s::unmatched scene_mode(%s)", |
| 2158 | __func__, new_scene_mode_str); //action, night-portrait, theatre, steadyphoto |
| 2159 | ret = UNKNOWN_ERROR; |
| 2160 | } |
| 2161 | } |
| 2162 | |
| 2163 | // focus mode |
| 2164 | if (new_focus_mode_str != NULL) { |
| 2165 | int new_focus_mode = -1; |
| 2166 | |
| 2167 | if (!strcmp(new_focus_mode_str, |
| 2168 | CameraParameters::FOCUS_MODE_AUTO)) { |
| 2169 | new_focus_mode = FOCUS_MODE_AUTO; |
| 2170 | mParameters.set(CameraParameters::KEY_FOCUS_DISTANCES, |
| 2171 | BACK_CAMERA_AUTO_FOCUS_DISTANCES_STR); |
| 2172 | } else if (!strcmp(new_focus_mode_str, |
| 2173 | CameraParameters::FOCUS_MODE_MACRO)) { |
| 2174 | new_focus_mode = FOCUS_MODE_MACRO; |
| 2175 | mParameters.set(CameraParameters::KEY_FOCUS_DISTANCES, |
| 2176 | BACK_CAMERA_MACRO_FOCUS_DISTANCES_STR); |
| 2177 | } else if (!strcmp(new_focus_mode_str, |
| 2178 | CameraParameters::FOCUS_MODE_INFINITY)) { |
| 2179 | new_focus_mode = FOCUS_MODE_INFINITY; |
| 2180 | mParameters.set(CameraParameters::KEY_FOCUS_DISTANCES, |
| 2181 | BACK_CAMERA_INFINITY_FOCUS_DISTANCES_STR); |
| 2182 | } else { |
| 2183 | LOGE("%s::unmatched focus_mode(%s)", __func__, new_focus_mode_str); |
| 2184 | ret = UNKNOWN_ERROR; |
| 2185 | } |
| 2186 | |
| 2187 | if (0 <= new_focus_mode) { |
| 2188 | if (mSecCamera->setFocusMode(new_focus_mode) < 0) { |
| 2189 | LOGE("%s::mSecCamera->setFocusMode(%d) fail", __func__, new_focus_mode); |
| 2190 | ret = UNKNOWN_ERROR; |
| 2191 | } else { |
| 2192 | mParameters.set(CameraParameters::KEY_FOCUS_MODE, new_focus_mode_str); |
| 2193 | } |
| 2194 | } |
| 2195 | } |
| 2196 | |
| 2197 | // flash.. |
| 2198 | if (new_flash_mode_str != NULL) { |
| 2199 | int new_flash_mode = -1; |
| 2200 | |
| 2201 | if (!strcmp(new_flash_mode_str, CameraParameters::FLASH_MODE_OFF)) |
| 2202 | new_flash_mode = FLASH_MODE_OFF; |
| 2203 | else if (!strcmp(new_flash_mode_str, CameraParameters::FLASH_MODE_AUTO)) |
| 2204 | new_flash_mode = FLASH_MODE_AUTO; |
| 2205 | else if (!strcmp(new_flash_mode_str, CameraParameters::FLASH_MODE_ON)) |
| 2206 | new_flash_mode = FLASH_MODE_ON; |
| 2207 | else if (!strcmp(new_flash_mode_str, CameraParameters::FLASH_MODE_TORCH)) |
| 2208 | new_flash_mode = FLASH_MODE_TORCH; |
| 2209 | else { |
| 2210 | LOGE("%s::unmatched flash_mode(%s)", __func__, new_flash_mode_str); //red-eye |
| 2211 | ret = UNKNOWN_ERROR; |
| 2212 | } |
| 2213 | if (0 <= new_flash_mode) { |
| 2214 | if (mSecCamera->setFlashMode(new_flash_mode) < 0) { |
| 2215 | LOGE("%s::mSecCamera->setFlashMode(%d) fail", __func__, new_flash_mode); |
| 2216 | ret = UNKNOWN_ERROR; |
| 2217 | } else { |
| 2218 | mParameters.set(CameraParameters::KEY_FLASH_MODE, new_flash_mode_str); |
| 2219 | } |
| 2220 | } |
| 2221 | } |
| 2222 | |
| 2223 | // scene.. |
| 2224 | if (0 <= new_scene_mode) { |
| 2225 | if (mSecCamera->setSceneMode(new_scene_mode) < 0) { |
| 2226 | LOGE("%s::mSecCamera->setSceneMode(%d) fail", __func__, new_scene_mode); |
| 2227 | ret = UNKNOWN_ERROR; |
| 2228 | } else { |
| 2229 | mParameters.set(CameraParameters::KEY_SCENE_MODE, new_scene_mode_str); |
| 2230 | } |
| 2231 | } |
| 2232 | } |
| 2233 | |
| 2234 | // image effect |
| 2235 | const char *new_image_effect_str = params.get(CameraParameters::KEY_EFFECT); |
| 2236 | if (new_image_effect_str != NULL) { |
| 2237 | |
| 2238 | int new_image_effect = -1; |
| 2239 | |
| 2240 | if (!strcmp(new_image_effect_str, CameraParameters::EFFECT_NONE)) { |
| 2241 | if (Internal_is) |
| 2242 | new_image_effect = IS_IMAGE_EFFECT_DISABLE; |
| 2243 | else |
| 2244 | new_image_effect = IMAGE_EFFECT_NONE; |
| 2245 | } else if (!strcmp(new_image_effect_str, CameraParameters::EFFECT_MONO)) { |
| 2246 | if (Internal_is) |
| 2247 | new_image_effect = IS_IMAGE_EFFECT_MONOCHROME; |
| 2248 | else |
| 2249 | new_image_effect = IMAGE_EFFECT_BNW; |
| 2250 | } else if (!strcmp(new_image_effect_str, CameraParameters::EFFECT_SEPIA)) { |
| 2251 | if (Internal_is) |
| 2252 | new_image_effect = IS_IMAGE_EFFECT_SEPIA; |
| 2253 | else |
| 2254 | new_image_effect = IMAGE_EFFECT_SEPIA; |
| 2255 | } else if (!strcmp(new_image_effect_str, CameraParameters::EFFECT_AQUA)) |
| 2256 | new_image_effect = IMAGE_EFFECT_AQUA; |
| 2257 | else if (!strcmp(new_image_effect_str, CameraParameters::EFFECT_NEGATIVE)) { |
| 2258 | if (Internal_is) |
| 2259 | new_image_effect = IS_IMAGE_EFFECT_NEGATIVE_MONO; |
| 2260 | else |
| 2261 | LOGW("WARN(%s):Invalid effect value (%s)", __func__, new_image_effect_str); |
| 2262 | } else { |
| 2263 | //posterize, whiteboard, blackboard, solarize |
| 2264 | LOGE("ERR(%s):Invalid effect(%s)", __func__, new_image_effect_str); |
| 2265 | ret = UNKNOWN_ERROR; |
| 2266 | } |
| 2267 | |
| 2268 | if (new_image_effect >= 0) { |
| 2269 | if (mSecCamera->setImageEffect(new_image_effect) < 0) { |
| 2270 | LOGE("ERR(%s):Fail on mSecCamera->setImageEffect(effect(%d))", __func__, new_image_effect); |
| 2271 | ret = UNKNOWN_ERROR; |
| 2272 | } else { |
| 2273 | const char *old_image_effect_str = mParameters.get(CameraParameters::KEY_EFFECT); |
| 2274 | |
| 2275 | if (old_image_effect_str) { |
| 2276 | if (strcmp(old_image_effect_str, new_image_effect_str)) { |
| 2277 | setSkipFrame(EFFECT_SKIP_FRAME); |
| 2278 | } |
| 2279 | } |
| 2280 | |
| 2281 | mParameters.set(CameraParameters::KEY_EFFECT, new_image_effect_str); |
| 2282 | } |
| 2283 | } |
| 2284 | } |
| 2285 | |
| 2286 | //contrast |
| 2287 | const char *new_contrast_str = params.get("contrast"); |
| 2288 | LOGV("%s : new_contrast_str %s", __func__, new_contrast_str); |
| 2289 | if (new_contrast_str != NULL) { |
| 2290 | int new_contrast = -1; |
| 2291 | |
| 2292 | if (!strcmp(new_contrast_str, "auto")) { |
| 2293 | if (Internal_is) |
| 2294 | new_contrast = IS_CONTRAST_AUTO; |
| 2295 | else |
| 2296 | LOGW("WARN(%s):Invalid contrast value (%s)", __func__, new_contrast_str); |
| 2297 | } else if (!strcmp(new_contrast_str, "-2")) { |
| 2298 | if (Internal_is) |
| 2299 | new_contrast = IS_CONTRAST_MINUS_2; |
| 2300 | else |
| 2301 | new_contrast = CONTRAST_MINUS_2; |
| 2302 | } else if (!strcmp(new_contrast_str, "-1")) { |
| 2303 | if (Internal_is) |
| 2304 | new_contrast = IS_CONTRAST_MINUS_1; |
| 2305 | else |
| 2306 | new_contrast = CONTRAST_MINUS_1; |
| 2307 | } else if (!strcmp(new_contrast_str, "0")) { |
| 2308 | if (Internal_is) |
| 2309 | new_contrast = IS_CONTRAST_DEFAULT; |
| 2310 | else |
| 2311 | new_contrast = CONTRAST_DEFAULT; |
| 2312 | } else if (!strcmp(new_contrast_str, "1")) { |
| 2313 | if (Internal_is) |
| 2314 | new_contrast = IS_CONTRAST_PLUS_1; |
| 2315 | else |
| 2316 | new_contrast = CONTRAST_PLUS_1; |
| 2317 | } else if (!strcmp(new_contrast_str, "2")) { |
| 2318 | if (Internal_is) |
| 2319 | new_contrast = IS_CONTRAST_PLUS_2; |
| 2320 | else |
| 2321 | new_contrast = CONTRAST_PLUS_2; |
| 2322 | } else { |
| 2323 | LOGE("ERR(%s):Invalid contrast value(%s)", __func__, new_contrast_str); |
| 2324 | ret = UNKNOWN_ERROR; |
| 2325 | } |
| 2326 | |
| 2327 | if (0 <= new_contrast) { |
| 2328 | if (mSecCamera->setContrast(new_contrast) < 0) { |
| 2329 | LOGE("ERR(%s):Fail on mSecCamera->setContrast(contrast(%d))", __func__, new_contrast); |
| 2330 | ret = UNKNOWN_ERROR; |
| 2331 | } else { |
| 2332 | mParameters.set("contrast", new_contrast_str); |
| 2333 | } |
| 2334 | } |
| 2335 | } |
| 2336 | |
| 2337 | //WDR |
| 2338 | int new_wdr = params.getInt("wdr"); |
| 2339 | LOGV("%s : new_wdr %d", __func__, new_wdr); |
| 2340 | |
| 2341 | if (0 <= new_wdr) { |
| 2342 | if (mSecCamera->setWDR(new_wdr) < 0) { |
| 2343 | LOGE("ERR(%s):Fail on mSecCamera->setWDR(%d)", __func__, new_wdr); |
| 2344 | ret = UNKNOWN_ERROR; |
| 2345 | } |
| 2346 | } |
| 2347 | |
| 2348 | //anti shake |
| 2349 | int new_anti_shake = mInternalParameters.getInt("anti-shake"); |
| 2350 | |
| 2351 | if (0 <= new_anti_shake) { |
| 2352 | if (mSecCamera->setAntiShake(new_anti_shake) < 0) { |
| 2353 | LOGE("ERR(%s):Fail on mSecCamera->setWDR(%d)", __func__, new_anti_shake); |
| 2354 | ret = UNKNOWN_ERROR; |
| 2355 | } |
| 2356 | } |
| 2357 | |
| 2358 | // gps latitude |
| 2359 | const char *new_gps_latitude_str = params.get(CameraParameters::KEY_GPS_LATITUDE); |
| 2360 | if (mSecCamera->setGPSLatitude(new_gps_latitude_str) < 0) { |
| 2361 | LOGE("%s::mSecCamera->setGPSLatitude(%s) fail", __func__, new_gps_latitude_str); |
| 2362 | ret = UNKNOWN_ERROR; |
| 2363 | } else { |
| 2364 | if (new_gps_latitude_str) { |
| 2365 | mParameters.set(CameraParameters::KEY_GPS_LATITUDE, new_gps_latitude_str); |
| 2366 | } else { |
| 2367 | mParameters.remove(CameraParameters::KEY_GPS_LATITUDE); |
| 2368 | } |
| 2369 | } |
| 2370 | |
| 2371 | // gps longitude |
| 2372 | const char *new_gps_longitude_str = params.get(CameraParameters::KEY_GPS_LONGITUDE); |
| 2373 | |
| 2374 | if (mSecCamera->setGPSLongitude(new_gps_longitude_str) < 0) { |
| 2375 | LOGE("%s::mSecCamera->setGPSLongitude(%s) fail", __func__, new_gps_longitude_str); |
| 2376 | ret = UNKNOWN_ERROR; |
| 2377 | } else { |
| 2378 | if (new_gps_longitude_str) { |
| 2379 | mParameters.set(CameraParameters::KEY_GPS_LONGITUDE, new_gps_longitude_str); |
| 2380 | } else { |
| 2381 | mParameters.remove(CameraParameters::KEY_GPS_LONGITUDE); |
| 2382 | } |
| 2383 | } |
| 2384 | |
| 2385 | // gps altitude |
| 2386 | const char *new_gps_altitude_str = params.get(CameraParameters::KEY_GPS_ALTITUDE); |
| 2387 | |
| 2388 | if (mSecCamera->setGPSAltitude(new_gps_altitude_str) < 0) { |
| 2389 | LOGE("%s::mSecCamera->setGPSAltitude(%s) fail", __func__, new_gps_altitude_str); |
| 2390 | ret = UNKNOWN_ERROR; |
| 2391 | } else { |
| 2392 | if (new_gps_altitude_str) { |
| 2393 | mParameters.set(CameraParameters::KEY_GPS_ALTITUDE, new_gps_altitude_str); |
| 2394 | } else { |
| 2395 | mParameters.remove(CameraParameters::KEY_GPS_ALTITUDE); |
| 2396 | } |
| 2397 | } |
| 2398 | |
| 2399 | // gps timestamp |
| 2400 | const char *new_gps_timestamp_str = params.get(CameraParameters::KEY_GPS_TIMESTAMP); |
| 2401 | |
| 2402 | if (mSecCamera->setGPSTimeStamp(new_gps_timestamp_str) < 0) { |
| 2403 | LOGE("%s::mSecCamera->setGPSTimeStamp(%s) fail", __func__, new_gps_timestamp_str); |
| 2404 | ret = UNKNOWN_ERROR; |
| 2405 | } else { |
| 2406 | if (new_gps_timestamp_str) { |
| 2407 | mParameters.set(CameraParameters::KEY_GPS_TIMESTAMP, new_gps_timestamp_str); |
| 2408 | } else { |
| 2409 | mParameters.remove(CameraParameters::KEY_GPS_TIMESTAMP); |
| 2410 | } |
| 2411 | } |
| 2412 | |
| 2413 | // gps processing method |
| 2414 | const char *new_gps_processing_method_str = params.get(CameraParameters::KEY_GPS_PROCESSING_METHOD); |
| 2415 | |
| 2416 | if (mSecCamera->setGPSProcessingMethod(new_gps_processing_method_str) < 0) { |
| 2417 | LOGE("%s::mSecCamera->setGPSProcessingMethod(%s) fail", __func__, new_gps_processing_method_str); |
| 2418 | ret = UNKNOWN_ERROR; |
| 2419 | } else { |
| 2420 | if (new_gps_processing_method_str) { |
| 2421 | mParameters.set(CameraParameters::KEY_GPS_PROCESSING_METHOD, new_gps_processing_method_str); |
| 2422 | } else { |
| 2423 | mParameters.remove(CameraParameters::KEY_GPS_PROCESSING_METHOD); |
| 2424 | } |
| 2425 | } |
| 2426 | |
| 2427 | // Recording size |
| 2428 | int new_recording_width = 0; |
| 2429 | int new_recording_height = 0; |
| 2430 | params.getVideoSize(&new_recording_width, &new_recording_height); |
| 2431 | LOGV("new_recording_width (%d) new_recording_height (%d)", |
| 2432 | new_recording_width, new_recording_height); |
| 2433 | |
| 2434 | int current_recording_width, current_recording_height; |
| 2435 | mSecCamera->getRecordingSize(¤t_recording_width, ¤t_recording_height); |
| 2436 | LOGV("current_recording_width (%d) current_recording_height (%d)", |
| 2437 | current_recording_width, current_recording_height); |
| 2438 | |
| 2439 | if (0 < new_recording_width && 0 < new_recording_height) { |
| 2440 | if (current_recording_width != new_recording_width || |
| 2441 | current_recording_height != new_recording_height) { |
| 2442 | if (mSecCamera->setRecordingSize(new_recording_width, new_recording_height) < 0) { |
| 2443 | LOGE("ERR(%s):Fail on mSecCamera->setRecordingSize(width(%d), height(%d))", |
| 2444 | __func__, new_recording_width, new_recording_height); |
| 2445 | ret = UNKNOWN_ERROR; |
| 2446 | } else { |
| 2447 | if (Internal_is && mPreviewWindow && mPreviewRunning) { |
| 2448 | mSecCamera->setRecording(1); |
| 2449 | stopPreview(); |
| 2450 | startPreview(); |
| 2451 | mSecCamera->setRecording(0); |
| 2452 | } |
| 2453 | } |
| 2454 | } |
| 2455 | mParameters.setVideoSize(new_recording_width, new_recording_height); |
| 2456 | } else { |
| 2457 | if (mSecCamera->setRecordingSize(new_preview_width, new_preview_height) < 0) { |
| 2458 | LOGE("ERR(%s):Fail on mSecCamera->setRecordingSize(width(%d), height(%d))", |
| 2459 | __func__, new_preview_width, new_preview_height); |
| 2460 | ret = UNKNOWN_ERROR; |
| 2461 | } |
| 2462 | } |
| 2463 | |
| 2464 | //gamma |
| 2465 | const char *new_gamma_str = mInternalParameters.get("video_recording_gamma"); |
| 2466 | |
| 2467 | if (new_gamma_str != NULL) { |
| 2468 | int new_gamma = -1; |
| 2469 | if (!strcmp(new_gamma_str, "off")) |
| 2470 | new_gamma = GAMMA_OFF; |
| 2471 | else if (!strcmp(new_gamma_str, "on")) |
| 2472 | new_gamma = GAMMA_ON; |
| 2473 | else { |
| 2474 | LOGE("%s::unmatched gamma(%s)", __func__, new_gamma_str); |
| 2475 | ret = UNKNOWN_ERROR; |
| 2476 | } |
| 2477 | |
| 2478 | if (0 <= new_gamma) { |
| 2479 | if (mSecCamera->setGamma(new_gamma) < 0) { |
| 2480 | LOGE("%s::mSecCamera->setGamma(%d) fail", __func__, new_gamma); |
| 2481 | ret = UNKNOWN_ERROR; |
| 2482 | } |
| 2483 | } |
| 2484 | } |
| 2485 | |
| 2486 | //slow ae |
| 2487 | const char *new_slow_ae_str = mInternalParameters.get("slow_ae"); |
| 2488 | |
| 2489 | if (new_slow_ae_str != NULL) { |
| 2490 | int new_slow_ae = -1; |
| 2491 | |
| 2492 | if (!strcmp(new_slow_ae_str, "off")) |
| 2493 | new_slow_ae = SLOW_AE_OFF; |
| 2494 | else if (!strcmp(new_slow_ae_str, "on")) |
| 2495 | new_slow_ae = SLOW_AE_ON; |
| 2496 | else { |
| 2497 | LOGE("%s::unmatched slow_ae(%s)", __func__, new_slow_ae_str); |
| 2498 | ret = UNKNOWN_ERROR; |
| 2499 | } |
| 2500 | |
| 2501 | if (0 <= new_slow_ae) { |
| 2502 | if (mSecCamera->setSlowAE(new_slow_ae) < 0) { |
| 2503 | LOGE("%s::mSecCamera->setSlowAE(%d) fail", __func__, new_slow_ae); |
| 2504 | ret = UNKNOWN_ERROR; |
| 2505 | } |
| 2506 | } |
| 2507 | } |
| 2508 | |
| 2509 | /*Camcorder fix fps*/ |
| 2510 | int new_sensor_mode = mInternalParameters.getInt("cam_mode"); |
| 2511 | |
| 2512 | if (0 <= new_sensor_mode) { |
| 2513 | if (mSecCamera->setSensorMode(new_sensor_mode) < 0) { |
| 2514 | LOGE("ERR(%s):Fail on mSecCamera->setSensorMode(%d)", __func__, new_sensor_mode); |
| 2515 | ret = UNKNOWN_ERROR; |
| 2516 | } |
| 2517 | } else { |
| 2518 | new_sensor_mode=0; |
| 2519 | } |
| 2520 | |
| 2521 | /*Shot mode*/ |
| 2522 | int new_shot_mode = mInternalParameters.getInt("shot_mode"); |
| 2523 | |
| 2524 | if (0 <= new_shot_mode) { |
| 2525 | if (mSecCamera->setShotMode(new_shot_mode) < 0) { |
| 2526 | LOGE("ERR(%s):Fail on mSecCamera->setShotMode(%d)", __func__, new_shot_mode); |
| 2527 | ret = UNKNOWN_ERROR; |
| 2528 | } |
| 2529 | } else { |
| 2530 | new_shot_mode=0; |
| 2531 | } |
| 2532 | |
| 2533 | // chk_dataline |
| 2534 | int new_dataline = mInternalParameters.getInt("chk_dataline"); |
| 2535 | |
| 2536 | if (0 <= new_dataline) { |
| 2537 | if (mSecCamera->setDataLineCheck(new_dataline) < 0) { |
| 2538 | LOGE("ERR(%s):Fail on mSecCamera->setDataLineCheck(%d)", __func__, new_dataline); |
| 2539 | ret = UNKNOWN_ERROR; |
| 2540 | } |
| 2541 | } |
| 2542 | LOGV("%s return ret = %d", __func__, ret); |
| 2543 | #endif |
| 2544 | |
| 2545 | return ret; |
| 2546 | } |
| 2547 | |
| 2548 | CameraParameters CameraHardwareSec::getParameters() const |
| 2549 | { |
| 2550 | LOGV("%s :", __func__); |
| 2551 | return mParameters; |
| 2552 | } |
| 2553 | |
| 2554 | status_t CameraHardwareSec::sendCommand(int32_t command, int32_t arg1, int32_t arg2) |
| 2555 | { |
| 2556 | return BAD_VALUE; |
| 2557 | } |
| 2558 | |
| 2559 | void CameraHardwareSec::release() |
| 2560 | { |
| 2561 | LOGV("%s", __func__); |
| 2562 | |
| 2563 | /* shut down any threads we have that might be running. do it here |
| 2564 | * instead of the destructor. we're guaranteed to be on another thread |
| 2565 | * than the ones below. if we used the destructor, since the threads |
| 2566 | * have a reference to this object, we could wind up trying to wait |
| 2567 | * for ourself to exit, which is a deadlock. |
| 2568 | */ |
| 2569 | if (mPreviewThread != NULL) { |
| 2570 | /* this thread is normally already in it's threadLoop but blocked |
| 2571 | * on the condition variable or running. signal it so it wakes |
| 2572 | * up and can exit. |
| 2573 | */ |
| 2574 | mPreviewThread->requestExit(); |
| 2575 | mExitPreviewThread = true; |
| 2576 | mPreviewRunning = true; /* let it run so it can exit */ |
| 2577 | mPreviewCondition.signal(); |
| 2578 | mPreviewThread->requestExitAndWait(); |
| 2579 | mPreviewThread.clear(); |
| 2580 | } |
| 2581 | if (mAutoFocusThread != NULL) { |
| 2582 | /* this thread is normally already in it's threadLoop but blocked |
| 2583 | * on the condition variable. signal it so it wakes up and can exit. |
| 2584 | */ |
| 2585 | mFocusLock.lock(); |
| 2586 | mAutoFocusThread->requestExit(); |
| 2587 | mExitAutoFocusThread = true; |
| 2588 | mFocusCondition.signal(); |
| 2589 | mFocusLock.unlock(); |
| 2590 | mAutoFocusThread->requestExitAndWait(); |
| 2591 | mAutoFocusThread.clear(); |
| 2592 | } |
| 2593 | if (mPictureThread != NULL) { |
| 2594 | mPictureThread->requestExitAndWait(); |
| 2595 | mPictureThread.clear(); |
| 2596 | } |
| 2597 | |
| 2598 | if (mRawHeap) { |
| 2599 | mRawHeap->release(mRawHeap); |
| 2600 | mRawHeap = 0; |
| 2601 | } |
| 2602 | if (mPreviewHeap) { |
| 2603 | mPreviewHeap->release(mPreviewHeap); |
| 2604 | mPreviewHeap = 0; |
| 2605 | } |
| 2606 | for(int i = 0; i < BUFFER_COUNT_FOR_ARRAY; i++) { |
| 2607 | if (mRecordHeap[i]) { |
| 2608 | mRecordHeap[i]->release(mRecordHeap[i]); |
| 2609 | mRecordHeap[i] = 0; |
| 2610 | } |
| 2611 | } |
| 2612 | |
| 2613 | /* close after all the heaps are cleared since those |
| 2614 | * could have dup'd our file descriptor. |
| 2615 | */ |
| 2616 | mSecCamera->DestroyCamera(); |
| 2617 | } |
| 2618 | |
| 2619 | static CameraInfo sCameraInfo[] = { |
| 2620 | { |
| 2621 | CAMERA_FACING_BACK, |
| 2622 | 0, /* orientation */ |
| 2623 | }, |
| 2624 | { |
| 2625 | CAMERA_FACING_FRONT, |
| 2626 | 0, /* orientation */ |
| 2627 | } |
| 2628 | }; |
| 2629 | |
| 2630 | status_t CameraHardwareSec::storeMetaDataInBuffers(bool enable) |
| 2631 | { |
| 2632 | if (!enable) { |
| 2633 | LOGE("Non-metadata buffer mode is not supported!"); |
| 2634 | return INVALID_OPERATION; |
| 2635 | } |
| 2636 | return OK; |
| 2637 | } |
| 2638 | |
| 2639 | /** Close this device */ |
| 2640 | |
| 2641 | static camera_device_t *g_cam_device; |
| 2642 | |
| 2643 | static int HAL_camera_device_close(struct hw_device_t* device) |
| 2644 | { |
| 2645 | LOGI("%s", __func__); |
| 2646 | if (device) { |
| 2647 | camera_device_t *cam_device = (camera_device_t *)device; |
| 2648 | delete static_cast<CameraHardwareSec *>(cam_device->priv); |
| 2649 | free(cam_device); |
| 2650 | g_cam_device = 0; |
| 2651 | } |
| 2652 | return 0; |
| 2653 | } |
| 2654 | |
| 2655 | static inline CameraHardwareSec *obj(struct camera_device *dev) |
| 2656 | { |
| 2657 | return reinterpret_cast<CameraHardwareSec *>(dev->priv); |
| 2658 | } |
| 2659 | |
| 2660 | /** Set the preview_stream_ops to which preview frames are sent */ |
| 2661 | static int HAL_camera_device_set_preview_window(struct camera_device *dev, |
| 2662 | struct preview_stream_ops *buf) |
| 2663 | { |
| 2664 | LOGV("%s", __func__); |
| 2665 | return obj(dev)->setPreviewWindow(buf); |
| 2666 | } |
| 2667 | |
| 2668 | /** Set the notification and data callbacks */ |
| 2669 | static void HAL_camera_device_set_callbacks(struct camera_device *dev, |
| 2670 | camera_notify_callback notify_cb, |
| 2671 | camera_data_callback data_cb, |
| 2672 | camera_data_timestamp_callback data_cb_timestamp, |
| 2673 | camera_request_memory get_memory, |
| 2674 | void* user) |
| 2675 | { |
| 2676 | LOGV("%s", __func__); |
| 2677 | obj(dev)->setCallbacks(notify_cb, data_cb, data_cb_timestamp, |
| 2678 | get_memory, |
| 2679 | user); |
| 2680 | } |
| 2681 | |
| 2682 | /** |
| 2683 | * The following three functions all take a msg_type, which is a bitmask of |
| 2684 | * the messages defined in include/ui/Camera.h |
| 2685 | */ |
| 2686 | |
| 2687 | /** |
| 2688 | * Enable a message, or set of messages. |
| 2689 | */ |
| 2690 | static void HAL_camera_device_enable_msg_type(struct camera_device *dev, int32_t msg_type) |
| 2691 | { |
| 2692 | LOGV("%s", __func__); |
| 2693 | obj(dev)->enableMsgType(msg_type); |
| 2694 | } |
| 2695 | |
| 2696 | /** |
| 2697 | * Disable a message, or a set of messages. |
| 2698 | * |
| 2699 | * Once received a call to disableMsgType(CAMERA_MSG_VIDEO_FRAME), camera |
| 2700 | * HAL should not rely on its client to call releaseRecordingFrame() to |
| 2701 | * release video recording frames sent out by the cameral HAL before and |
| 2702 | * after the disableMsgType(CAMERA_MSG_VIDEO_FRAME) call. Camera HAL |
| 2703 | * clients must not modify/access any video recording frame after calling |
| 2704 | * disableMsgType(CAMERA_MSG_VIDEO_FRAME). |
| 2705 | */ |
| 2706 | static void HAL_camera_device_disable_msg_type(struct camera_device *dev, int32_t msg_type) |
| 2707 | { |
| 2708 | LOGV("%s", __func__); |
| 2709 | obj(dev)->disableMsgType(msg_type); |
| 2710 | } |
| 2711 | |
| 2712 | /** |
| 2713 | * Query whether a message, or a set of messages, is enabled. Note that |
| 2714 | * this is operates as an AND, if any of the messages queried are off, this |
| 2715 | * will return false. |
| 2716 | */ |
| 2717 | static int HAL_camera_device_msg_type_enabled(struct camera_device *dev, int32_t msg_type) |
| 2718 | { |
| 2719 | LOGV("%s", __func__); |
| 2720 | return obj(dev)->msgTypeEnabled(msg_type); |
| 2721 | } |
| 2722 | |
| 2723 | /** |
| 2724 | * Start preview mode. |
| 2725 | */ |
| 2726 | static int HAL_camera_device_start_preview(struct camera_device *dev) |
| 2727 | { |
| 2728 | LOGV("%s", __func__); |
| 2729 | return obj(dev)->startPreview(); |
| 2730 | } |
| 2731 | |
| 2732 | /** |
| 2733 | * Stop a previously started preview. |
| 2734 | */ |
| 2735 | static void HAL_camera_device_stop_preview(struct camera_device *dev) |
| 2736 | { |
| 2737 | LOGV("%s", __func__); |
| 2738 | obj(dev)->stopPreview(); |
| 2739 | } |
| 2740 | |
| 2741 | /** |
| 2742 | * Returns true if preview is enabled. |
| 2743 | */ |
| 2744 | static int HAL_camera_device_preview_enabled(struct camera_device *dev) |
| 2745 | { |
| 2746 | LOGV("%s", __func__); |
| 2747 | return obj(dev)->previewEnabled(); |
| 2748 | } |
| 2749 | |
| 2750 | /** |
| 2751 | * Request the camera HAL to store meta data or real YUV data in the video |
| 2752 | * buffers sent out via CAMERA_MSG_VIDEO_FRAME for a recording session. If |
| 2753 | * it is not called, the default camera HAL behavior is to store real YUV |
| 2754 | * data in the video buffers. |
| 2755 | * |
| 2756 | * This method should be called before startRecording() in order to be |
| 2757 | * effective. |
| 2758 | * |
| 2759 | * If meta data is stored in the video buffers, it is up to the receiver of |
| 2760 | * the video buffers to interpret the contents and to find the actual frame |
| 2761 | * data with the help of the meta data in the buffer. How this is done is |
| 2762 | * outside of the scope of this method. |
| 2763 | * |
| 2764 | * Some camera HALs may not support storing meta data in the video buffers, |
| 2765 | * but all camera HALs should support storing real YUV data in the video |
| 2766 | * buffers. If the camera HAL does not support storing the meta data in the |
| 2767 | * video buffers when it is requested to do do, INVALID_OPERATION must be |
| 2768 | * returned. It is very useful for the camera HAL to pass meta data rather |
| 2769 | * than the actual frame data directly to the video encoder, since the |
| 2770 | * amount of the uncompressed frame data can be very large if video size is |
| 2771 | * large. |
| 2772 | * |
| 2773 | * @param enable if true to instruct the camera HAL to store |
| 2774 | * meta data in the video buffers; false to instruct |
| 2775 | * the camera HAL to store real YUV data in the video |
| 2776 | * buffers. |
| 2777 | * |
| 2778 | * @return OK on success. |
| 2779 | */ |
| 2780 | static int HAL_camera_device_store_meta_data_in_buffers(struct camera_device *dev, int enable) |
| 2781 | { |
| 2782 | LOGV("%s", __func__); |
| 2783 | return obj(dev)->storeMetaDataInBuffers(enable); |
| 2784 | } |
| 2785 | |
| 2786 | /** |
| 2787 | * Start record mode. When a record image is available, a |
| 2788 | * CAMERA_MSG_VIDEO_FRAME message is sent with the corresponding |
| 2789 | * frame. Every record frame must be released by a camera HAL client via |
| 2790 | * releaseRecordingFrame() before the client calls |
| 2791 | * disableMsgType(CAMERA_MSG_VIDEO_FRAME). After the client calls |
| 2792 | * disableMsgType(CAMERA_MSG_VIDEO_FRAME), it is the camera HAL's |
| 2793 | * responsibility to manage the life-cycle of the video recording frames, |
| 2794 | * and the client must not modify/access any video recording frames. |
| 2795 | */ |
| 2796 | static int HAL_camera_device_start_recording(struct camera_device *dev) |
| 2797 | { |
| 2798 | LOGV("%s", __func__); |
| 2799 | return obj(dev)->startRecording(); |
| 2800 | } |
| 2801 | |
| 2802 | /** |
| 2803 | * Stop a previously started recording. |
| 2804 | */ |
| 2805 | static void HAL_camera_device_stop_recording(struct camera_device *dev) |
| 2806 | { |
| 2807 | LOGV("%s", __func__); |
| 2808 | obj(dev)->stopRecording(); |
| 2809 | } |
| 2810 | |
| 2811 | /** |
| 2812 | * Returns true if recording is enabled. |
| 2813 | */ |
| 2814 | static int HAL_camera_device_recording_enabled(struct camera_device *dev) |
| 2815 | { |
| 2816 | LOGV("%s", __func__); |
| 2817 | return obj(dev)->recordingEnabled(); |
| 2818 | } |
| 2819 | |
| 2820 | /** |
| 2821 | * Release a record frame previously returned by CAMERA_MSG_VIDEO_FRAME. |
| 2822 | * |
| 2823 | * It is camera HAL client's responsibility to release video recording |
| 2824 | * frames sent out by the camera HAL before the camera HAL receives a call |
| 2825 | * to disableMsgType(CAMERA_MSG_VIDEO_FRAME). After it receives the call to |
| 2826 | * disableMsgType(CAMERA_MSG_VIDEO_FRAME), it is the camera HAL's |
| 2827 | * responsibility to manage the life-cycle of the video recording frames. |
| 2828 | */ |
| 2829 | static void HAL_camera_device_release_recording_frame(struct camera_device *dev, |
| 2830 | const void *opaque) |
| 2831 | { |
| 2832 | LOGV("%s", __func__); |
| 2833 | obj(dev)->releaseRecordingFrame(opaque); |
| 2834 | } |
| 2835 | |
| 2836 | /** |
| 2837 | * Start auto focus, the notification callback routine is called with |
| 2838 | * CAMERA_MSG_FOCUS once when focusing is complete. autoFocus() will be |
| 2839 | * called again if another auto focus is needed. |
| 2840 | */ |
| 2841 | static int HAL_camera_device_auto_focus(struct camera_device *dev) |
| 2842 | { |
| 2843 | LOGV("%s", __func__); |
| 2844 | return obj(dev)->autoFocus(); |
| 2845 | } |
| 2846 | |
| 2847 | /** |
| 2848 | * Cancels auto-focus function. If the auto-focus is still in progress, |
| 2849 | * this function will cancel it. Whether the auto-focus is in progress or |
| 2850 | * not, this function will return the focus position to the default. If |
| 2851 | * the camera does not support auto-focus, this is a no-op. |
| 2852 | */ |
| 2853 | static int HAL_camera_device_cancel_auto_focus(struct camera_device *dev) |
| 2854 | { |
| 2855 | LOGV("%s", __func__); |
| 2856 | return obj(dev)->cancelAutoFocus(); |
| 2857 | } |
| 2858 | |
| 2859 | /** |
| 2860 | * Take a picture. |
| 2861 | */ |
| 2862 | static int HAL_camera_device_take_picture(struct camera_device *dev) |
| 2863 | { |
| 2864 | LOGV("%s", __func__); |
| 2865 | return obj(dev)->takePicture(); |
| 2866 | } |
| 2867 | |
| 2868 | /** |
| 2869 | * Cancel a picture that was started with takePicture. Calling this method |
| 2870 | * when no picture is being taken is a no-op. |
| 2871 | */ |
| 2872 | static int HAL_camera_device_cancel_picture(struct camera_device *dev) |
| 2873 | { |
| 2874 | LOGV("%s", __func__); |
| 2875 | return obj(dev)->cancelPicture(); |
| 2876 | } |
| 2877 | |
| 2878 | /** |
| 2879 | * Set the camera parameters. This returns BAD_VALUE if any parameter is |
| 2880 | * invalid or not supported. |
| 2881 | */ |
| 2882 | static int HAL_camera_device_set_parameters(struct camera_device *dev, |
| 2883 | const char *parms) |
| 2884 | { |
| 2885 | LOGV("%s", __func__); |
| 2886 | String8 str(parms); |
| 2887 | CameraParameters p(str); |
| 2888 | return obj(dev)->setParameters(p); |
| 2889 | } |
| 2890 | |
| 2891 | /** Return the camera parameters. */ |
| 2892 | char *HAL_camera_device_get_parameters(struct camera_device *dev) |
| 2893 | { |
| 2894 | LOGV("%s", __func__); |
| 2895 | String8 str; |
| 2896 | CameraParameters parms = obj(dev)->getParameters(); |
| 2897 | str = parms.flatten(); |
| 2898 | return strdup(str.string()); |
| 2899 | } |
| 2900 | |
| 2901 | static void HAL_camera_device_put_parameters(struct camera_device *dev, char *parms) |
| 2902 | { |
| 2903 | LOGV("%s", __func__); |
| 2904 | free(parms); |
| 2905 | } |
| 2906 | |
| 2907 | /** |
| 2908 | * Send command to camera driver. |
| 2909 | */ |
| 2910 | static int HAL_camera_device_send_command(struct camera_device *dev, |
| 2911 | int32_t cmd, int32_t arg1, int32_t arg2) |
| 2912 | { |
| 2913 | LOGV("%s", __func__); |
| 2914 | return obj(dev)->sendCommand(cmd, arg1, arg2); |
| 2915 | } |
| 2916 | |
| 2917 | /** |
| 2918 | * Release the hardware resources owned by this object. Note that this is |
| 2919 | * *not* done in the destructor. |
| 2920 | */ |
| 2921 | static void HAL_camera_device_release(struct camera_device *dev) |
| 2922 | { |
| 2923 | LOGV("%s", __func__); |
| 2924 | obj(dev)->release(); |
| 2925 | } |
| 2926 | |
| 2927 | /** |
| 2928 | * Dump state of the camera hardware |
| 2929 | */ |
| 2930 | static int HAL_camera_device_dump(struct camera_device *dev, int fd) |
| 2931 | { |
| 2932 | LOGV("%s", __func__); |
| 2933 | return obj(dev)->dump(fd); |
| 2934 | } |
| 2935 | |
| 2936 | static int HAL_getNumberOfCameras() |
| 2937 | { |
| 2938 | LOGV("%s", __func__); |
| 2939 | return sizeof(sCameraInfo) / sizeof(sCameraInfo[0]); |
| 2940 | } |
| 2941 | |
| 2942 | static int HAL_getCameraInfo(int cameraId, struct camera_info *cameraInfo) |
| 2943 | { |
| 2944 | LOGV("%s", __func__); |
| 2945 | memcpy(cameraInfo, &sCameraInfo[cameraId], sizeof(CameraInfo)); |
| 2946 | return 0; |
| 2947 | } |
| 2948 | |
| 2949 | #define SET_METHOD(m) m : HAL_camera_device_##m |
| 2950 | |
| 2951 | static camera_device_ops_t camera_device_ops = { |
| 2952 | SET_METHOD(set_preview_window), |
| 2953 | SET_METHOD(set_callbacks), |
| 2954 | SET_METHOD(enable_msg_type), |
| 2955 | SET_METHOD(disable_msg_type), |
| 2956 | SET_METHOD(msg_type_enabled), |
| 2957 | SET_METHOD(start_preview), |
| 2958 | SET_METHOD(stop_preview), |
| 2959 | SET_METHOD(preview_enabled), |
| 2960 | SET_METHOD(store_meta_data_in_buffers), |
| 2961 | SET_METHOD(start_recording), |
| 2962 | SET_METHOD(stop_recording), |
| 2963 | SET_METHOD(recording_enabled), |
| 2964 | SET_METHOD(release_recording_frame), |
| 2965 | SET_METHOD(auto_focus), |
| 2966 | SET_METHOD(cancel_auto_focus), |
| 2967 | SET_METHOD(take_picture), |
| 2968 | SET_METHOD(cancel_picture), |
| 2969 | SET_METHOD(set_parameters), |
| 2970 | SET_METHOD(get_parameters), |
| 2971 | SET_METHOD(put_parameters), |
| 2972 | SET_METHOD(send_command), |
| 2973 | SET_METHOD(release), |
| 2974 | SET_METHOD(dump), |
| 2975 | }; |
| 2976 | |
| 2977 | #undef SET_METHOD |
| 2978 | |
| 2979 | static int HAL_camera_device_open(const struct hw_module_t* module, |
| 2980 | const char *id, |
| 2981 | struct hw_device_t** device) |
| 2982 | { |
| 2983 | LOGV("%s", __func__); |
| 2984 | |
| 2985 | int cameraId = atoi(id); |
| 2986 | if (cameraId < 0 || cameraId >= HAL_getNumberOfCameras()) { |
| 2987 | LOGE("Invalid camera ID %s", id); |
| 2988 | return -EINVAL; |
| 2989 | } |
| 2990 | |
| 2991 | if (g_cam_device) { |
| 2992 | if (obj(g_cam_device)->getCameraId() == cameraId) { |
| 2993 | LOGV("returning existing camera ID %s", id); |
| 2994 | goto done; |
| 2995 | } else { |
| 2996 | LOGE("Cannot open camera %d. camera %d is already running!", |
| 2997 | cameraId, obj(g_cam_device)->getCameraId()); |
| 2998 | return -ENOSYS; |
| 2999 | } |
| 3000 | } |
| 3001 | |
| 3002 | g_cam_device = (camera_device_t *)malloc(sizeof(camera_device_t)); |
| 3003 | if (!g_cam_device) |
| 3004 | return -ENOMEM; |
| 3005 | |
| 3006 | g_cam_device->common.tag = HARDWARE_DEVICE_TAG; |
| 3007 | g_cam_device->common.version = 1; |
| 3008 | g_cam_device->common.module = const_cast<hw_module_t *>(module); |
| 3009 | g_cam_device->common.close = HAL_camera_device_close; |
| 3010 | |
| 3011 | g_cam_device->ops = &camera_device_ops; |
| 3012 | |
| 3013 | LOGI("%s: open camera %s", __func__, id); |
| 3014 | |
| 3015 | g_cam_device->priv = new CameraHardwareSec(cameraId, g_cam_device); |
| 3016 | |
| 3017 | done: |
| 3018 | *device = (hw_device_t *)g_cam_device; |
| 3019 | LOGI("%s: opened camera %s (%p)", __func__, id, *device); |
| 3020 | return 0; |
| 3021 | } |
| 3022 | |
| 3023 | static hw_module_methods_t camera_module_methods = { |
| 3024 | open : HAL_camera_device_open |
| 3025 | }; |
| 3026 | |
| 3027 | extern "C" { |
| 3028 | struct camera_module HAL_MODULE_INFO_SYM = { |
| 3029 | common : { |
| 3030 | tag : HARDWARE_MODULE_TAG, |
| 3031 | version_major : 1, |
| 3032 | version_minor : 0, |
| 3033 | id : CAMERA_HARDWARE_MODULE_ID, |
| 3034 | name : "orion camera HAL", |
| 3035 | author : "Samsung Corporation", |
| 3036 | methods : &camera_module_methods, |
| 3037 | }, |
| 3038 | get_number_of_cameras : HAL_getNumberOfCameras, |
| 3039 | get_camera_info : HAL_getCameraInfo |
| 3040 | }; |
| 3041 | } |
| 3042 | |
| 3043 | }; // namespace android |