1/* 2 * Copyright 2008, The Android Open Source Project 3 * Copyright 2010, Samsung Electronics Co. LTD 4 * 5 * Licensed under the Apache License, Version 2.0 (the "License"); 6 * you may not use this file except in compliance with the License. 7 * You may obtain a copy of the License at 8 * 9 * http://www.apache.org/licenses/LICENSE-2.0 10 * 11 * Unless required by applicable law or agreed to in writing, software 12 * distributed under the License is distributed on an "AS IS" BASIS, 13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 * See the License for the specific language governing permissions and 15 * limitations under the License. 16 */ 17 18/* 19************************************ 20* Filename: SecCamera.cpp 21* Author: Sachin P. Kamat 22* Purpose: This file interacts with the Camera and JPEG drivers. 23************************************* 24*/ 25 26//#define LOG_NDEBUG 0 27#define LOG_TAG "SecCamera" 28 29#include <utils/Log.h> 30 31#include <math.h> 32#include <string.h> 33#include <stdlib.h> 34#include <sys/poll.h> 35#include "SecCamera.h" 36#include "cutils/properties.h" 37 38using namespace android; 39 40#define CHECK(return_value) \ 41 if (return_value < 0) { \ 42 ALOGE("%s::%d fail. errno: %s, m_camera_id = %d\n", \ 43 __func__, __LINE__, strerror(errno), m_camera_id); \ 44 return -1; \ 45 } 46 47 48#define CHECK_PTR(return_value) \ 49 if (return_value < 0) { \ 50 ALOGE("%s::%d fail, errno: %s, m_camera_id = %d\n", \ 51 __func__,__LINE__, strerror(errno), m_camera_id); \ 52 return NULL; \ 53 } 54 55#define ALIGN_TO_32B(x) ((((x) + (1 << 5) - 1) >> 5) << 5) 56#define ALIGN_TO_128B(x) ((((x) + (1 << 7) - 1) >> 7) << 7) 57#define ALIGN_TO_8KB(x) ((((x) + (1 << 13) - 1) >> 13) << 13) 58 59namespace android { 60 61// ====================================================================== 62// Camera controls 63 64static struct timeval time_start; 65static struct timeval time_stop; 66 67unsigned long measure_time(struct timeval *start, struct timeval *stop) 68{ 69 unsigned long sec, usec, time; 70 71 sec = stop->tv_sec - start->tv_sec; 72 73 if (stop->tv_usec >= start->tv_usec) { 74 usec = stop->tv_usec - start->tv_usec; 75 } else { 76 usec = stop->tv_usec + 1000000 - start->tv_usec; 77 sec--; 78 } 79 80 time = (sec * 1000000) + usec; 81 82 return time; 83} 84 85static int get_pixel_depth(unsigned int fmt) 86{ 87 int depth = 0; 88 89 switch (fmt) { 90 case V4L2_PIX_FMT_NV12: 91 depth = 12; 92 break; 93 case V4L2_PIX_FMT_NV12T: 94 depth = 12; 95 break; 96 case V4L2_PIX_FMT_NV21: 97 depth = 12; 98 break; 99 case V4L2_PIX_FMT_YUV420: 100 depth = 12; 101 break; 102 103 case V4L2_PIX_FMT_RGB565: 104 case V4L2_PIX_FMT_YUYV: 105 case V4L2_PIX_FMT_YVYU: 106 case V4L2_PIX_FMT_UYVY: 107 case V4L2_PIX_FMT_VYUY: 108 case V4L2_PIX_FMT_NV16: 109 case V4L2_PIX_FMT_NV61: 110 case V4L2_PIX_FMT_YUV422P: 111 depth = 16; 112 break; 113 114 case V4L2_PIX_FMT_RGB32: 115 depth = 32; 116 break; 117 } 118 119 return depth; 120} 121 122#define ALIGN_W(x) (((x) + 0x7F) & (~0x7F)) // Set as multiple of 128 123#define ALIGN_H(x) (((x) + 0x1F) & (~0x1F)) // Set as multiple of 32 124#define ALIGN_BUF(x) (((x) + 0x1FFF)& (~0x1FFF)) // Set as multiple of 8K 125 126static int fimc_poll(struct pollfd *events) 127{ 128 int ret; 129 130 /* 10 second delay is because sensor can take a long time 131 * to do auto focus and capture in dark settings 132 */ 133 ret = poll(events, 1, 10000); 134 if (ret < 0) { 135 ALOGE("ERR(%s):poll error\n", __func__); 136 return ret; 137 } 138 139 if (ret == 0) { 140 ALOGE("ERR(%s):No data in 10 secs..\n", __func__); 141 return ret; 142 } 143 144 return ret; 145} 146 147int SecCamera::previewPoll(bool preview) 148{ 149 int ret; 150 151 if (preview) { 152#ifdef ENABLE_ESD_PREVIEW_CHECK 153 int status = 0; 154 155 if (!(++m_esd_check_count % 60)) { 156 status = getCameraSensorESDStatus(); 157 m_esd_check_count = 0; 158 if (status) { 159 ALOGE("ERR(%s) ESD status(%d)", __func__, status); 160 return status; 161 } 162 } 163#endif 164 165 ret = poll(&m_events_c, 1, 1000); 166 } else { 167 ret = poll(&m_events_c2, 1, 1000); 168 } 169 170 if (ret < 0) { 171 ALOGE("ERR(%s):poll error\n", __func__); 172 return ret; 173 } 174 175 if (ret == 0) { 176 ALOGE("ERR(%s):No data in 1 secs.. Camera Device Reset \n", __func__); 177 return ret; 178 } 179 180 return ret; 181} 182 183static int fimc_v4l2_querycap(int fp) 184{ 185 struct v4l2_capability cap; 186 int ret = 0; 187 188 ret = ioctl(fp, VIDIOC_QUERYCAP, &cap); 189 190 if (ret < 0) { 191 ALOGE("ERR(%s):VIDIOC_QUERYCAP failed\n", __func__); 192 return -1; 193 } 194 195 if (!(cap.capabilities & V4L2_CAP_VIDEO_CAPTURE)) { 196 ALOGE("ERR(%s):no capture devices\n", __func__); 197 return -1; 198 } 199 200 return ret; 201} 202 203static const __u8* fimc_v4l2_enuminput(int fp, int index) 204{ 205 static struct v4l2_input input; 206 207 input.index = index; 208 if (ioctl(fp, VIDIOC_ENUMINPUT, &input) != 0) { 209 ALOGE("ERR(%s):No matching index found\n", __func__); 210 return NULL; 211 } 212 ALOGI("Name of input channel[%d] is %s\n", input.index, input.name); 213 214 return input.name; 215} 216 217 218static int fimc_v4l2_s_input(int fp, int index) 219{ 220 struct v4l2_input input; 221 int ret; 222 223 input.index = index; 224 225 ret = ioctl(fp, VIDIOC_S_INPUT, &input); 226 if (ret < 0) { 227 ALOGE("ERR(%s):VIDIOC_S_INPUT failed\n", __func__); 228 return ret; 229 } 230 231 return ret; 232} 233 234static int fimc_v4l2_s_fmt(int fp, int width, int height, unsigned int fmt, int flag_capture) 235{ 236 struct v4l2_format v4l2_fmt; 237 struct v4l2_pix_format pixfmt; 238 int ret; 239 240 v4l2_fmt.type = V4L2_BUF_TYPE_VIDEO_CAPTURE; 241 242 memset(&pixfmt, 0, sizeof(pixfmt)); 243 244 pixfmt.width = width; 245 pixfmt.height = height; 246 pixfmt.pixelformat = fmt; 247 248 pixfmt.sizeimage = (width * height * get_pixel_depth(fmt)) / 8; 249 250 pixfmt.field = V4L2_FIELD_NONE; 251 252 v4l2_fmt.fmt.pix = pixfmt; 253 254 /* Set up for capture */ 255 ret = ioctl(fp, VIDIOC_S_FMT, &v4l2_fmt); 256 if (ret < 0) { 257 ALOGE("ERR(%s):VIDIOC_S_FMT failed\n", __func__); 258 return -1; 259 } 260 261 return 0; 262} 263 264static int fimc_v4l2_s_fmt_cap(int fp, int width, int height, unsigned int fmt) 265{ 266 struct v4l2_format v4l2_fmt; 267 struct v4l2_pix_format pixfmt; 268 int ret; 269 270 memset(&pixfmt, 0, sizeof(pixfmt)); 271 272 v4l2_fmt.type = V4L2_BUF_TYPE_VIDEO_CAPTURE; 273 274 pixfmt.width = width; 275 pixfmt.height = height; 276 pixfmt.pixelformat = fmt; 277 if (fmt == V4L2_PIX_FMT_JPEG) { 278 pixfmt.colorspace = V4L2_COLORSPACE_JPEG; 279 } 280 281 pixfmt.sizeimage = (width * height * get_pixel_depth(fmt)) / 8; 282 283 v4l2_fmt.fmt.pix = pixfmt; 284 285 //ALOGE("ori_w %d, ori_h %d, w %d, h %d\n", width, height, v4l2_fmt.fmt.pix.width, v4l2_fmt.fmt.pix.height); 286 287 /* Set up for capture */ 288 ret = ioctl(fp, VIDIOC_S_FMT, &v4l2_fmt); 289 if (ret < 0) { 290 ALOGE("ERR(%s):VIDIOC_S_FMT failed\n", __func__); 291 return ret; 292 } 293 294 return ret; 295} 296 297static int fimc_v4l2_enum_fmt(int fp, unsigned int fmt) 298{ 299 struct v4l2_fmtdesc fmtdesc; 300 int found = 0; 301 302 fmtdesc.type = V4L2_BUF_TYPE_VIDEO_CAPTURE; 303 fmtdesc.index = 0; 304 305 while (ioctl(fp, VIDIOC_ENUM_FMT, &fmtdesc) == 0) { 306 if (fmtdesc.pixelformat == fmt) { 307 ALOGV("passed fmt = %#x found pixel format[%d]: %s\n", fmt, fmtdesc.index, fmtdesc.description); 308 found = 1; 309 break; 310 } 311 312 fmtdesc.index++; 313 } 314 315 if (!found) { 316 ALOGE("unsupported pixel format\n"); 317 return -1; 318 } 319 320 return 0; 321} 322 323static int fimc_v4l2_reqbufs(int fp, enum v4l2_buf_type type, int nr_bufs) 324{ 325 struct v4l2_requestbuffers req; 326 int ret; 327 328 req.count = nr_bufs; 329 req.type = type; 330 req.memory = V4L2_MEMORY_MMAP; 331 332 ret = ioctl(fp, VIDIOC_REQBUFS, &req); 333 if (ret < 0) { 334 ALOGE("ERR(%s):VIDIOC_REQBUFS failed\n", __func__); 335 return -1; 336 } 337 338 return req.count; 339} 340 341static int fimc_v4l2_querybuf(int fp, struct fimc_buffer *buffer, enum v4l2_buf_type type) 342{ 343 struct v4l2_buffer v4l2_buf; 344 int ret; 345 346 ALOGI("%s :", __func__); 347 348 v4l2_buf.type = type; 349 v4l2_buf.memory = V4L2_MEMORY_MMAP; 350 v4l2_buf.index = 0; 351 352 ret = ioctl(fp , VIDIOC_QUERYBUF, &v4l2_buf); 353 if (ret < 0) { 354 ALOGE("ERR(%s):VIDIOC_QUERYBUF failed\n", __func__); 355 return -1; 356 } 357 358 buffer->length = v4l2_buf.length; 359 if ((buffer->start = (char *)mmap(0, v4l2_buf.length, 360 PROT_READ | PROT_WRITE, MAP_SHARED, 361 fp, v4l2_buf.m.offset)) < 0) { 362 ALOGE("%s %d] mmap() failed\n",__func__, __LINE__); 363 return -1; 364 } 365 366 ALOGI("%s: buffer->start = %p v4l2_buf.length = %d", 367 __func__, buffer->start, v4l2_buf.length); 368 369 return 0; 370} 371 372static int fimc_v4l2_streamon(int fp) 373{ 374 enum v4l2_buf_type type = V4L2_BUF_TYPE_VIDEO_CAPTURE; 375 int ret; 376 377 ret = ioctl(fp, VIDIOC_STREAMON, &type); 378 if (ret < 0) { 379 ALOGE("ERR(%s):VIDIOC_STREAMON failed\n", __func__); 380 return ret; 381 } 382 383 return ret; 384} 385 386static int fimc_v4l2_streamoff(int fp) 387{ 388 enum v4l2_buf_type type = V4L2_BUF_TYPE_VIDEO_CAPTURE; 389 int ret; 390 391 ALOGV("%s :", __func__); 392 ret = ioctl(fp, VIDIOC_STREAMOFF, &type); 393 if (ret < 0) { 394 ALOGE("ERR(%s):VIDIOC_STREAMOFF failed\n", __func__); 395 return ret; 396 } 397 398 return ret; 399} 400 401static int fimc_v4l2_qbuf(int fp, int index) 402{ 403 struct v4l2_buffer v4l2_buf; 404 int ret; 405 406 v4l2_buf.type = V4L2_BUF_TYPE_VIDEO_CAPTURE; 407 v4l2_buf.memory = V4L2_MEMORY_MMAP; 408 v4l2_buf.index = index; 409 410 ret = ioctl(fp, VIDIOC_QBUF, &v4l2_buf); 411 if (ret < 0) { 412 ALOGE("ERR(%s):VIDIOC_QBUF failed\n", __func__); 413 return ret; 414 } 415 416 return 0; 417} 418 419static int fimc_v4l2_dqbuf(int fp) 420{ 421 struct v4l2_buffer v4l2_buf; 422 int ret; 423 424 v4l2_buf.type = V4L2_BUF_TYPE_VIDEO_CAPTURE; 425 v4l2_buf.memory = V4L2_MEMORY_MMAP; 426 427 ret = ioctl(fp, VIDIOC_DQBUF, &v4l2_buf); 428 if (ret < 0) { 429 ALOGE("ERR(%s):VIDIOC_DQBUF failed, dropped frame\n", __func__); 430 return ret; 431 } 432 433 return v4l2_buf.index; 434} 435 436static int fimc_v4l2_g_ctrl(int fp, unsigned int id) 437{ 438 struct v4l2_control ctrl; 439 int ret; 440 441 ctrl.id = id; 442 443 ret = ioctl(fp, VIDIOC_G_CTRL, &ctrl); 444 if (ret < 0) { 445 ALOGE("ERR(%s): VIDIOC_G_CTRL(id = 0x%x (%d)) failed, ret = %d\n", 446 __func__, id, id-V4L2_CID_PRIVATE_BASE, ret); 447 return ret; 448 } 449 450 return ctrl.value; 451} 452 453static int fimc_v4l2_s_ctrl(int fp, unsigned int id, unsigned int value) 454{ 455 struct v4l2_control ctrl; 456 int ret; 457 458 ctrl.id = id; 459 ctrl.value = value; 460 461 ret = ioctl(fp, VIDIOC_S_CTRL, &ctrl); 462 if (ret < 0) { 463 ALOGE("ERR(%s):VIDIOC_S_CTRL(id = %#x (%d), value = %d) failed ret = %d\n", 464 __func__, id, id-V4L2_CID_PRIVATE_BASE, value, ret); 465 466 return ret; 467 } 468 469 return ctrl.value; 470} 471 472static int fimc_v4l2_g_parm(int fp, struct v4l2_streamparm *streamparm) 473{ 474 int ret; 475 476 streamparm->type = V4L2_BUF_TYPE_VIDEO_CAPTURE; 477 478 ret = ioctl(fp, VIDIOC_G_PARM, streamparm); 479 if (ret < 0) { 480 ALOGE("ERR(%s):VIDIOC_G_PARM failed\n", __func__); 481 return -1; 482 } 483 484 ALOGV("%s : timeperframe: numerator %d, denominator %d\n", __func__, 485 streamparm->parm.capture.timeperframe.numerator, 486 streamparm->parm.capture.timeperframe.denominator); 487 488 return 0; 489} 490 491static int fimc_v4l2_s_parm(int fp, struct v4l2_streamparm *streamparm) 492{ 493 int ret; 494 495 streamparm->type = V4L2_BUF_TYPE_VIDEO_CAPTURE; 496 497 ret = ioctl(fp, VIDIOC_S_PARM, streamparm); 498 if (ret < 0) { 499 ALOGE("ERR(%s):VIDIOC_S_PARM failed\n", __func__); 500 return ret; 501 } 502 503 return 0; 504} 505 506// ====================================================================== 507// Constructor & Destructor 508 509SecCamera::SecCamera() : 510 m_flag_init(0), 511 m_camera_id(CAMERA_ID_BACK), 512 m_cam_fd(-1), 513 m_cam_fd2(-1), 514 m_preview_v4lformat(V4L2_PIX_FMT_NV21), 515 m_preview_width (0), 516 m_preview_height (0), 517 m_preview_max_width (MAX_BACK_CAMERA_PREVIEW_WIDTH), 518 m_preview_max_height (MAX_BACK_CAMERA_PREVIEW_HEIGHT), 519 m_snapshot_v4lformat(-1), 520 m_snapshot_width (0), 521 m_snapshot_height (0), 522 m_snapshot_max_width (MAX_BACK_CAMERA_SNAPSHOT_WIDTH), 523 m_snapshot_max_height (MAX_BACK_CAMERA_SNAPSHOT_HEIGHT), 524 m_angle(-1), 525 m_anti_banding(-1), 526 m_wdr(-1), 527 m_anti_shake(-1), 528 m_zoom_level(-1), 529 m_object_tracking(-1), 530 m_smart_auto(-1), 531 m_beauty_shot(-1), 532 m_vintage_mode(-1), 533 m_face_detect(-1), 534 m_gps_enabled(false), 535 m_gps_latitude(-1), 536 m_gps_longitude(-1), 537 m_gps_altitude(-1), 538 m_gps_timestamp(-1), 539 m_vtmode(0), 540 m_sensor_mode(-1), 541 m_shot_mode(-1), 542 m_exif_orientation(-1), 543 m_blur_level(-1), 544 m_chk_dataline(-1), 545 m_video_gamma(-1), 546 m_slow_ae(-1), 547 m_camera_af_flag(-1), 548 m_flag_camera_start(0), 549 m_jpeg_thumbnail_width (0), 550 m_jpeg_thumbnail_height(0), 551 m_jpeg_quality(100) 552#ifdef ENABLE_ESD_PREVIEW_CHECK 553 , 554 m_esd_check_count(0) 555#endif // ENABLE_ESD_PREVIEW_CHECK 556{ 557 m_params = (struct sec_cam_parm*)&m_streamparm.parm.raw_data; 558 struct v4l2_captureparm capture; 559 m_params->capture.timeperframe.numerator = 1; 560 m_params->capture.timeperframe.denominator = 0; 561 m_params->contrast = -1; 562 m_params->effects = -1; 563 m_params->brightness = -1; 564 m_params->flash_mode = -1; 565 m_params->focus_mode = -1; 566 m_params->iso = -1; 567 m_params->metering = -1; 568 m_params->saturation = -1; 569 m_params->scene_mode = -1; 570 m_params->sharpness = -1; 571 m_params->white_balance = -1; 572 573 memset(&m_capture_buf, 0, sizeof(m_capture_buf)); 574 575 ALOGV("%s :", __func__); 576} 577 578SecCamera::~SecCamera() 579{ 580 ALOGV("%s :", __func__); 581} 582 583int SecCamera::initCamera(int index) 584{ 585 ALOGV("%s :", __func__); 586 int ret = 0; 587 588 if (!m_flag_init) { 589 /* Arun C 590 * Reset the lense position only during camera starts; don't do 591 * reset between shot to shot 592 */ 593 m_camera_af_flag = -1; 594 595 m_cam_fd = open(CAMERA_DEV_NAME, O_RDWR); 596 if (m_cam_fd < 0) { 597 ALOGE("ERR(%s):Cannot open %s (error : %s)\n", __func__, CAMERA_DEV_NAME, strerror(errno)); 598 return -1; 599 } 600 ALOGV("%s: open(%s) --> m_cam_fd %d", __FUNCTION__, CAMERA_DEV_NAME, m_cam_fd); 601 602 ALOGE("initCamera: m_cam_fd(%d), m_jpeg_fd(%d)", m_cam_fd, m_jpeg_fd); 603 604 ret = fimc_v4l2_querycap(m_cam_fd); 605 CHECK(ret); 606 if (!fimc_v4l2_enuminput(m_cam_fd, index)) 607 return -1; 608 ret = fimc_v4l2_s_input(m_cam_fd, index); 609 CHECK(ret); 610 611 m_cam_fd2 = open(CAMERA_DEV_NAME2, O_RDWR); 612 ALOGV("%s: open(%s) --> m_cam_fd2 = %d", __FUNCTION__, CAMERA_DEV_NAME2, m_cam_fd2); 613 if (m_cam_fd2 < 0) { 614 ALOGE("ERR(%s):Cannot open %s (error : %s)\n", __func__, CAMERA_DEV_NAME2, strerror(errno)); 615 return -1; 616 } 617 618 ALOGE("initCamera: m_cam_fd2(%d)", m_cam_fd2); 619 620 ret = fimc_v4l2_querycap(m_cam_fd2); 621 CHECK(ret); 622 if (!fimc_v4l2_enuminput(m_cam_fd2, index)) 623 return -1; 624 ret = fimc_v4l2_s_input(m_cam_fd2, index); 625 CHECK(ret); 626 627 m_camera_id = index; 628 629 switch (m_camera_id) { 630 case CAMERA_ID_FRONT: 631 m_preview_max_width = MAX_FRONT_CAMERA_PREVIEW_WIDTH; 632 m_preview_max_height = MAX_FRONT_CAMERA_PREVIEW_HEIGHT; 633 m_snapshot_max_width = MAX_FRONT_CAMERA_SNAPSHOT_WIDTH; 634 m_snapshot_max_height = MAX_FRONT_CAMERA_SNAPSHOT_HEIGHT; 635 break; 636 637 case CAMERA_ID_BACK: 638 m_preview_max_width = MAX_BACK_CAMERA_PREVIEW_WIDTH; 639 m_preview_max_height = MAX_BACK_CAMERA_PREVIEW_HEIGHT; 640 m_snapshot_max_width = MAX_BACK_CAMERA_SNAPSHOT_WIDTH; 641 m_snapshot_max_height = MAX_BACK_CAMERA_SNAPSHOT_HEIGHT; 642 break; 643 } 644 645 setExifFixedAttribute(); 646 647 m_flag_init = 1; 648 ALOGI("%s : initialized", __FUNCTION__); 649 } 650 return 0; 651} 652 653void SecCamera::resetCamera() 654{ 655 ALOGV("%s :", __func__); 656 DeinitCamera(); 657 initCamera(m_camera_id); 658} 659 660void SecCamera::DeinitCamera() 661{ 662 ALOGV("%s :", __func__); 663 664 if (m_flag_init) { 665 666 stopRecord(); 667 668 /* close m_cam_fd after stopRecord() because stopRecord() 669 * uses m_cam_fd to change frame rate 670 */ 671 ALOGI("DeinitCamera: m_cam_fd(%d)", m_cam_fd); 672 if (m_cam_fd > -1) { 673 close(m_cam_fd); 674 m_cam_fd = -1; 675 } 676 677 ALOGI("DeinitCamera: m_cam_fd2(%d)", m_cam_fd2); 678 if (m_cam_fd2 > -1) { 679 close(m_cam_fd2); 680 m_cam_fd2 = -1; 681 } 682 683 m_flag_init = 0; 684 } 685 else ALOGI("%s : already deinitialized", __FUNCTION__); 686} 687 688 689int SecCamera::getCameraFd(void) 690{ 691 return m_cam_fd; 692} 693 694// ====================================================================== 695// Preview 696 697int SecCamera::startPreview(void) 698{ 699 v4l2_streamparm streamparm; 700 struct sec_cam_parm *parms; 701 parms = (struct sec_cam_parm*)&streamparm.parm.raw_data; 702 ALOGV("%s :", __func__); 703 704 // aleady started 705 if (m_flag_camera_start > 0) { 706 ALOGE("ERR(%s):Preview was already started\n", __func__); 707 return 0; 708 } 709 710 if (m_cam_fd <= 0) { 711 ALOGE("ERR(%s):Camera was closed\n", __func__); 712 return -1; 713 } 714 715 memset(&m_events_c, 0, sizeof(m_events_c)); 716 m_events_c.fd = m_cam_fd; 717 m_events_c.events = POLLIN | POLLERR; 718 719 /* enum_fmt, s_fmt sample */ 720 int ret = fimc_v4l2_enum_fmt(m_cam_fd,m_preview_v4lformat); 721 CHECK(ret); 722 ret = fimc_v4l2_s_fmt(m_cam_fd, m_preview_width,m_preview_height,m_preview_v4lformat, 0); 723 CHECK(ret); 724 725 ret = fimc_v4l2_reqbufs(m_cam_fd, V4L2_BUF_TYPE_VIDEO_CAPTURE, MAX_BUFFERS); 726 CHECK(ret); 727 728 ALOGV("%s : m_preview_width: %d m_preview_height: %d m_angle: %d\n", 729 __func__, m_preview_width, m_preview_height, m_angle); 730 731 ret = fimc_v4l2_s_ctrl(m_cam_fd, 732 V4L2_CID_CAMERA_CHECK_DATALINE, m_chk_dataline); 733 CHECK(ret); 734 735 if (m_camera_id == CAMERA_ID_FRONT) { 736 /* VT mode setting */ 737 ret = fimc_v4l2_s_ctrl(m_cam_fd, V4L2_CID_CAMERA_VT_MODE, m_vtmode); 738 CHECK(ret); 739 } 740 741 /* start with all buffers in queue */ 742 for (int i = 0; i < MAX_BUFFERS; i++) { 743 ret = fimc_v4l2_qbuf(m_cam_fd, i); 744 CHECK(ret); 745 } 746 747 ret = fimc_v4l2_streamon(m_cam_fd); 748 CHECK(ret); 749 750 m_flag_camera_start = 1; 751 752 ret = fimc_v4l2_s_parm(m_cam_fd, &m_streamparm); 753 CHECK(ret); 754 755 if (m_camera_id == CAMERA_ID_FRONT) { 756 /* Blur setting */ 757 ALOGV("m_blur_level = %d", m_blur_level); 758 ret = fimc_v4l2_s_ctrl(m_cam_fd, V4L2_CID_CAMERA_VGA_BLUR, 759 m_blur_level); 760 CHECK(ret); 761 } 762 763 // It is a delay for a new frame, not to show the previous bigger ugly picture frame. 764 ret = fimc_poll(&m_events_c); 765 CHECK(ret); 766 ret = fimc_v4l2_s_ctrl(m_cam_fd, V4L2_CID_CAMERA_RETURN_FOCUS, 0); 767 CHECK(ret); 768 769 ALOGV("%s: got the first frame of the preview\n", __func__); 770 771 return 0; 772} 773 774int SecCamera::stopPreview(void) 775{ 776 int ret; 777 778 ALOGV("%s :", __func__); 779 780 if (m_flag_camera_start == 0) { 781 ALOGW("%s: doing nothing because m_flag_camera_start is zero", __func__); 782 return 0; 783 } 784 785 if (m_params->flash_mode == FLASH_MODE_TORCH) 786 setFlashMode(FLASH_MODE_OFF); 787 788 if (m_cam_fd <= 0) { 789 ALOGE("ERR(%s):Camera was closed\n", __func__); 790 return -1; 791 } 792 793 ret = fimc_v4l2_streamoff(m_cam_fd); 794 CHECK(ret); 795 796 m_flag_camera_start = 0; 797 798 return ret; 799} 800 801//Recording 802int SecCamera::startRecord(void) 803{ 804 int ret, i; 805 806 ALOGV("%s :", __func__); 807 808 // aleady started 809 if (m_flag_record_start > 0) { 810 ALOGE("ERR(%s):Preview was already started\n", __func__); 811 return 0; 812 } 813 814 if (m_cam_fd2 <= 0) { 815 ALOGE("ERR(%s):Camera was closed\n", __func__); 816 return -1; 817 } 818 819 /* enum_fmt, s_fmt sample */ 820 ret = fimc_v4l2_enum_fmt(m_cam_fd2, V4L2_PIX_FMT_NV12T); 821 CHECK(ret); 822 823 ALOGI("%s: m_recording_width = %d, m_recording_height = %d\n", 824 __func__, m_recording_width, m_recording_height); 825 826 ret = fimc_v4l2_s_fmt(m_cam_fd2, m_recording_width, 827 m_recording_height, V4L2_PIX_FMT_NV12T, 0); 828 CHECK(ret); 829 830 ret = fimc_v4l2_s_ctrl(m_cam_fd, V4L2_CID_CAMERA_FRAME_RATE, 831 m_params->capture.timeperframe.denominator); 832 CHECK(ret); 833 834 ret = fimc_v4l2_reqbufs(m_cam_fd2, V4L2_BUF_TYPE_VIDEO_CAPTURE, MAX_BUFFERS); 835 CHECK(ret); 836 837 /* start with all buffers in queue */ 838 for (i = 0; i < MAX_BUFFERS; i++) { 839 ret = fimc_v4l2_qbuf(m_cam_fd2, i); 840 CHECK(ret); 841 } 842 843 ret = fimc_v4l2_streamon(m_cam_fd2); 844 CHECK(ret); 845 846 // Get and throw away the first frame since it is often garbled. 847 memset(&m_events_c2, 0, sizeof(m_events_c2)); 848 m_events_c2.fd = m_cam_fd2; 849 m_events_c2.events = POLLIN | POLLERR; 850 ret = fimc_poll(&m_events_c2); 851 CHECK(ret); 852 853 m_flag_record_start = 1; 854 855 return 0; 856} 857 858int SecCamera::stopRecord(void) 859{ 860 int ret; 861 862 ALOGV("%s :", __func__); 863 864 if (m_flag_record_start == 0) { 865 ALOGW("%s: doing nothing because m_flag_record_start is zero", __func__); 866 return 0; 867 } 868 869 if (m_cam_fd2 <= 0) { 870 ALOGE("ERR(%s):Camera was closed\n", __func__); 871 return -1; 872 } 873 874 m_flag_record_start = 0; 875 876 ret = fimc_v4l2_streamoff(m_cam_fd2); 877 CHECK(ret); 878 879 ret = fimc_v4l2_s_ctrl(m_cam_fd, V4L2_CID_CAMERA_FRAME_RATE, 880 FRAME_RATE_AUTO); 881 CHECK(ret); 882 883 return 0; 884} 885 886unsigned int SecCamera::getRecPhyAddrY(int index) 887{ 888 unsigned int addr_y; 889 890 addr_y = fimc_v4l2_s_ctrl(m_cam_fd2, V4L2_CID_PADDR_Y, index); 891 CHECK((int)addr_y); 892 return addr_y; 893} 894 895unsigned int SecCamera::getRecPhyAddrC(int index) 896{ 897 unsigned int addr_c; 898 899 addr_c = fimc_v4l2_s_ctrl(m_cam_fd2, V4L2_CID_PADDR_CBCR, index); 900 CHECK((int)addr_c); 901 return addr_c; 902} 903 904unsigned int SecCamera::getPhyAddrY(int index) 905{ 906 unsigned int addr_y; 907 908 addr_y = fimc_v4l2_s_ctrl(m_cam_fd, V4L2_CID_PADDR_Y, index); 909 CHECK((int)addr_y); 910 return addr_y; 911} 912 913unsigned int SecCamera::getPhyAddrC(int index) 914{ 915 unsigned int addr_c; 916 917 addr_c = fimc_v4l2_s_ctrl(m_cam_fd, V4L2_CID_PADDR_CBCR, index); 918 CHECK((int)addr_c); 919 return addr_c; 920} 921 922void SecCamera::pausePreview() 923{ 924 fimc_v4l2_s_ctrl(m_cam_fd, V4L2_CID_STREAM_PAUSE, 0); 925} 926 927int SecCamera::getPreview() 928{ 929 int index; 930 int ret; 931 932 if (m_flag_camera_start == 0 || previewPoll(true) == 0) { 933 ALOGE("ERR(%s):Start Camera Device Reset \n", __func__); 934 /* GAUDI Project([arun.c@samsung.com]) 2010.05.20. [Implemented ESD code] */ 935 /* 936 * When there is no data for more than 1 second from the camera we inform 937 * the FIMC driver by calling fimc_v4l2_s_input() with a special value = 1000 938 * FIMC driver identify that there is something wrong with the camera 939 * and it restarts the sensor. 940 */ 941 stopPreview(); 942 /* Reset Only Camera Device */ 943 ret = fimc_v4l2_querycap(m_cam_fd); 944 CHECK(ret); 945 if (fimc_v4l2_enuminput(m_cam_fd, m_camera_id)) 946 return -1; 947 ret = fimc_v4l2_s_input(m_cam_fd, 1000); 948 CHECK(ret); 949 ret = startPreview(); 950 if (ret < 0) { 951 ALOGE("ERR(%s): startPreview() return %d\n", __func__, ret); 952 return 0; 953 } 954 } 955 956 index = fimc_v4l2_dqbuf(m_cam_fd); 957 if (!(0 <= index && index < MAX_BUFFERS)) { 958 ALOGE("ERR(%s):wrong index = %d\n", __func__, index); 959 return -1; 960 } 961 962 ret = fimc_v4l2_qbuf(m_cam_fd, index); 963 CHECK(ret); 964 965 return index; 966} 967 968int SecCamera::getRecordFrame() 969{ 970 if (m_flag_record_start == 0) { 971 ALOGE("%s: m_flag_record_start is 0", __func__); 972 return -1; 973 } 974 975 previewPoll(false); 976 return fimc_v4l2_dqbuf(m_cam_fd2); 977} 978 979int SecCamera::releaseRecordFrame(int index) 980{ 981 if (!m_flag_record_start) { 982 /* this can happen when recording frames are returned after 983 * the recording is stopped at the driver level. we don't 984 * need to return the buffers in this case and we've seen 985 * cases where fimc could crash if we called qbuf and it 986 * wasn't expecting it. 987 */ 988 ALOGI("%s: recording not in progress, ignoring", __func__); 989 return 0; 990 } 991 992 return fimc_v4l2_qbuf(m_cam_fd2, index); 993} 994 995int SecCamera::setPreviewSize(int width, int height, int pixel_format) 996{ 997 ALOGV("%s(width(%d), height(%d), format(%d))", __func__, width, height, pixel_format); 998 999 int v4lpixelformat = pixel_format; 1000 1001#if defined(LOG_NDEBUG) && LOG_NDEBUG == 0 1002 if (v4lpixelformat == V4L2_PIX_FMT_YUV420) 1003 ALOGV("PreviewFormat:V4L2_PIX_FMT_YUV420"); 1004 else if (v4lpixelformat == V4L2_PIX_FMT_NV12) 1005 ALOGV("PreviewFormat:V4L2_PIX_FMT_NV12"); 1006 else if (v4lpixelformat == V4L2_PIX_FMT_NV12T) 1007 ALOGV("PreviewFormat:V4L2_PIX_FMT_NV12T"); 1008 else if (v4lpixelformat == V4L2_PIX_FMT_NV21) 1009 ALOGV("PreviewFormat:V4L2_PIX_FMT_NV21"); 1010 else if (v4lpixelformat == V4L2_PIX_FMT_YUV422P) 1011 ALOGV("PreviewFormat:V4L2_PIX_FMT_YUV422P"); 1012 else if (v4lpixelformat == V4L2_PIX_FMT_YUYV) 1013 ALOGV("PreviewFormat:V4L2_PIX_FMT_YUYV"); 1014 else if (v4lpixelformat == V4L2_PIX_FMT_RGB565) 1015 ALOGV("PreviewFormat:V4L2_PIX_FMT_RGB565"); 1016 else 1017 ALOGV("PreviewFormat:UnknownFormat"); 1018#endif 1019 m_preview_width = width; 1020 m_preview_height = height; 1021 m_preview_v4lformat = v4lpixelformat; 1022 1023 return 0; 1024} 1025 1026int SecCamera::getPreviewSize(int *width, int *height, int *frame_size) 1027{ 1028 *width = m_preview_width; 1029 *height = m_preview_height; 1030 *frame_size = m_frameSize(m_preview_v4lformat, m_preview_width, m_preview_height); 1031 1032 return 0; 1033} 1034 1035int SecCamera::getPreviewMaxSize(int *width, int *height) 1036{ 1037 *width = m_preview_max_width; 1038 *height = m_preview_max_height; 1039 1040 return 0; 1041} 1042 1043int SecCamera::getPreviewPixelFormat(void) 1044{ 1045 return m_preview_v4lformat; 1046} 1047 1048 1049// ====================================================================== 1050// Snapshot 1051/* 1052 * Devide getJpeg() as two funcs, setSnapshotCmd() & getJpeg() because of the shutter sound timing. 1053 * Here, just send the capture cmd to camera ISP to start JPEG capture. 1054 */ 1055int SecCamera::setSnapshotCmd(void) 1056{ 1057 ALOGV("%s :", __func__); 1058 1059 int ret = 0; 1060 1061 LOG_TIME_DEFINE(0) 1062 LOG_TIME_DEFINE(1) 1063 1064 if (m_cam_fd <= 0) { 1065 ALOGE("ERR(%s):Camera was closed\n", __func__); 1066 return 0; 1067 } 1068 1069 if (m_flag_camera_start > 0) { 1070 LOG_TIME_START(0) 1071 ALOGW("WARN(%s):Camera was in preview, should have been stopped\n", __func__); 1072 stopPreview(); 1073 LOG_TIME_END(0) 1074 } 1075 1076 memset(&m_events_c, 0, sizeof(m_events_c)); 1077 m_events_c.fd = m_cam_fd; 1078 m_events_c.events = POLLIN | POLLERR; 1079 1080 LOG_TIME_START(1) // prepare 1081 int nframe = 1; 1082 1083 ret = fimc_v4l2_enum_fmt(m_cam_fd,m_snapshot_v4lformat); 1084 CHECK(ret); 1085 ret = fimc_v4l2_s_fmt_cap(m_cam_fd, m_snapshot_width, m_snapshot_height, V4L2_PIX_FMT_JPEG); 1086 CHECK(ret); 1087 ret = fimc_v4l2_reqbufs(m_cam_fd, V4L2_BUF_TYPE_VIDEO_CAPTURE, nframe); 1088 CHECK(ret); 1089 ret = fimc_v4l2_querybuf(m_cam_fd, &m_capture_buf, V4L2_BUF_TYPE_VIDEO_CAPTURE); 1090 CHECK(ret); 1091 1092 ret = fimc_v4l2_qbuf(m_cam_fd, 0); 1093 CHECK(ret); 1094 1095 ret = fimc_v4l2_streamon(m_cam_fd); 1096 CHECK(ret); 1097 LOG_TIME_END(1) 1098 1099 return 0; 1100} 1101 1102int SecCamera::endSnapshot(void) 1103{ 1104 int ret; 1105 1106 ALOGI("%s :", __func__); 1107 if (m_capture_buf.start) { 1108 munmap(m_capture_buf.start, m_capture_buf.length); 1109 ALOGI("munmap():virt. addr %p size = %d\n", 1110 m_capture_buf.start, m_capture_buf.length); 1111 m_capture_buf.start = NULL; 1112 m_capture_buf.length = 0; 1113 } 1114 return 0; 1115} 1116 1117/* 1118 * Set Jpeg quality & exif info and get JPEG data from camera ISP 1119 */ 1120unsigned char* SecCamera::getJpeg(int *jpeg_size, unsigned int *phyaddr) 1121{ 1122 ALOGV("%s :", __func__); 1123 1124 int index, ret = 0; 1125 unsigned char *addr; 1126 1127 LOG_TIME_DEFINE(2) 1128 1129 // capture 1130 ret = fimc_poll(&m_events_c); 1131 CHECK_PTR(ret); 1132 index = fimc_v4l2_dqbuf(m_cam_fd); 1133 if (index != 0) { 1134 ALOGE("ERR(%s):wrong index = %d\n", __func__, index); 1135 return NULL; 1136 } 1137 1138 *jpeg_size = fimc_v4l2_g_ctrl(m_cam_fd, V4L2_CID_CAM_JPEG_MAIN_SIZE); 1139 CHECK_PTR(*jpeg_size); 1140 1141 int main_offset = fimc_v4l2_g_ctrl(m_cam_fd, V4L2_CID_CAM_JPEG_MAIN_OFFSET); 1142 CHECK_PTR(main_offset); 1143 m_postview_offset = fimc_v4l2_g_ctrl(m_cam_fd, V4L2_CID_CAM_JPEG_POSTVIEW_OFFSET); 1144 CHECK_PTR(m_postview_offset); 1145 1146 ret = fimc_v4l2_s_ctrl(m_cam_fd, V4L2_CID_STREAM_PAUSE, 0); 1147 CHECK_PTR(ret); 1148 ALOGV("\nsnapshot dqueued buffer = %d snapshot_width = %d snapshot_height = %d, size = %d\n\n", 1149 index, m_snapshot_width, m_snapshot_height, *jpeg_size); 1150 1151 addr = (unsigned char*)(m_capture_buf.start) + main_offset; 1152 *phyaddr = getPhyAddrY(index) + m_postview_offset; 1153 1154 LOG_TIME_START(2) // post 1155 ret = fimc_v4l2_streamoff(m_cam_fd); 1156 CHECK_PTR(ret); 1157 LOG_TIME_END(2) 1158 1159 return addr; 1160} 1161 1162int SecCamera::getExif(unsigned char *pExifDst, unsigned char *pThumbSrc) 1163{ 1164 JpegEncoder jpgEnc; 1165 1166 ALOGV("%s : m_jpeg_thumbnail_width = %d, height = %d", 1167 __func__, m_jpeg_thumbnail_width, m_jpeg_thumbnail_height); 1168 if ((m_jpeg_thumbnail_width > 0) && (m_jpeg_thumbnail_height > 0)) { 1169 int inFormat = JPG_MODESEL_YCBCR; 1170 int outFormat = JPG_422; 1171 switch (m_snapshot_v4lformat) { 1172 case V4L2_PIX_FMT_NV12: 1173 case V4L2_PIX_FMT_NV21: 1174 case V4L2_PIX_FMT_NV12T: 1175 case V4L2_PIX_FMT_YUV420: 1176 outFormat = JPG_420; 1177 break; 1178 case V4L2_PIX_FMT_YUYV: 1179 case V4L2_PIX_FMT_UYVY: 1180 case V4L2_PIX_FMT_YUV422P: 1181 outFormat = JPG_422; 1182 break; 1183 } 1184 1185 if (jpgEnc.setConfig(JPEG_SET_ENCODE_IN_FORMAT, inFormat) != JPG_SUCCESS) 1186 return -1; 1187 1188 if (jpgEnc.setConfig(JPEG_SET_SAMPING_MODE, outFormat) != JPG_SUCCESS) 1189 return -1; 1190 1191 if (jpgEnc.setConfig(JPEG_SET_ENCODE_QUALITY, JPG_QUALITY_LEVEL_2) != JPG_SUCCESS) 1192 return -1; 1193 1194 int thumbWidth, thumbHeight, thumbSrcSize; 1195 getThumbnailConfig(&thumbWidth, &thumbHeight, &thumbSrcSize); 1196 if (jpgEnc.setConfig(JPEG_SET_ENCODE_WIDTH, thumbWidth) != JPG_SUCCESS) 1197 return -1; 1198 1199 if (jpgEnc.setConfig(JPEG_SET_ENCODE_HEIGHT, thumbHeight) != JPG_SUCCESS) 1200 return -1; 1201 1202 char *pInBuf = (char *)jpgEnc.getInBuf(thumbSrcSize); 1203 if (pInBuf == NULL) 1204 return -1; 1205 memcpy(pInBuf, pThumbSrc, thumbSrcSize); 1206 1207 unsigned int thumbSize; 1208 1209 jpgEnc.encode(&thumbSize, NULL); 1210 1211 ALOGV("%s : enableThumb set to true", __func__); 1212 mExifInfo.enableThumb = true; 1213 } else { 1214 ALOGV("%s : enableThumb set to false", __func__); 1215 mExifInfo.enableThumb = false; 1216 } 1217 1218 unsigned int exifSize; 1219 1220 setExifChangedAttribute(); 1221 1222 ALOGV("%s: calling jpgEnc.makeExif, mExifInfo.width set to %d, height to %d\n", 1223 __func__, mExifInfo.width, mExifInfo.height); 1224 1225 jpgEnc.makeExif(pExifDst, &mExifInfo, &exifSize, true); 1226 1227 return exifSize; 1228} 1229 1230void SecCamera::getPostViewConfig(int *width, int *height, int *size) 1231{ 1232 if (m_preview_width == 1024) { 1233 *width = BACK_CAMERA_POSTVIEW_WIDE_WIDTH; 1234 *height = BACK_CAMERA_POSTVIEW_HEIGHT; 1235 *size = BACK_CAMERA_POSTVIEW_WIDE_WIDTH * BACK_CAMERA_POSTVIEW_HEIGHT * BACK_CAMERA_POSTVIEW_BPP / 8; 1236 } else { 1237 *width = BACK_CAMERA_POSTVIEW_WIDTH; 1238 *height = BACK_CAMERA_POSTVIEW_HEIGHT; 1239 *size = BACK_CAMERA_POSTVIEW_WIDTH * BACK_CAMERA_POSTVIEW_HEIGHT * BACK_CAMERA_POSTVIEW_BPP / 8; 1240 } 1241 ALOGV("[5B] m_preview_width : %d, mPostViewWidth = %d mPostViewHeight = %d mPostViewSize = %d", 1242 m_preview_width, *width, *height, *size); 1243} 1244 1245void SecCamera::getThumbnailConfig(int *width, int *height, int *size) 1246{ 1247 if (m_camera_id == CAMERA_ID_BACK) { 1248 *width = BACK_CAMERA_THUMBNAIL_WIDTH; 1249 *height = BACK_CAMERA_THUMBNAIL_HEIGHT; 1250 *size = BACK_CAMERA_THUMBNAIL_WIDTH * BACK_CAMERA_THUMBNAIL_HEIGHT 1251 * BACK_CAMERA_THUMBNAIL_BPP / 8; 1252 } else { 1253 *width = FRONT_CAMERA_THUMBNAIL_WIDTH; 1254 *height = FRONT_CAMERA_THUMBNAIL_HEIGHT; 1255 *size = FRONT_CAMERA_THUMBNAIL_WIDTH * FRONT_CAMERA_THUMBNAIL_HEIGHT 1256 * FRONT_CAMERA_THUMBNAIL_BPP / 8; 1257 } 1258} 1259 1260int SecCamera::getPostViewOffset(void) 1261{ 1262 return m_postview_offset; 1263} 1264 1265int SecCamera::getSnapshotAndJpeg(unsigned char *yuv_buf, unsigned char *jpeg_buf, 1266 unsigned int *output_size) 1267{ 1268 ALOGV("%s :", __func__); 1269 1270 int index; 1271 //unsigned int addr; 1272 unsigned char *addr; 1273 int ret = 0; 1274 1275 LOG_TIME_DEFINE(0) 1276 LOG_TIME_DEFINE(1) 1277 LOG_TIME_DEFINE(2) 1278 LOG_TIME_DEFINE(3) 1279 LOG_TIME_DEFINE(4) 1280 LOG_TIME_DEFINE(5) 1281 1282 //fimc_v4l2_streamoff(m_cam_fd); [zzangdol] remove - it is separate in HWInterface with camera_id 1283 1284 if (m_cam_fd <= 0) { 1285 ALOGE("ERR(%s):Camera was closed\n", __func__); 1286 return -1; 1287 } 1288 1289 if (m_flag_camera_start > 0) { 1290 LOG_TIME_START(0) 1291 ALOGW("WARN(%s):Camera was in preview, should have been stopped\n", __func__); 1292 stopPreview(); 1293 LOG_TIME_END(0) 1294 } 1295 1296 memset(&m_events_c, 0, sizeof(m_events_c)); 1297 m_events_c.fd = m_cam_fd; 1298 m_events_c.events = POLLIN | POLLERR; 1299 1300#if defined(LOG_NDEBUG) && LOG_NDEBUG == 0 1301 if (m_snapshot_v4lformat == V4L2_PIX_FMT_YUV420) 1302 ALOGV("SnapshotFormat:V4L2_PIX_FMT_YUV420"); 1303 else if (m_snapshot_v4lformat == V4L2_PIX_FMT_NV12) 1304 ALOGV("SnapshotFormat:V4L2_PIX_FMT_NV12"); 1305 else if (m_snapshot_v4lformat == V4L2_PIX_FMT_NV12T) 1306 ALOGV("SnapshotFormat:V4L2_PIX_FMT_NV12T"); 1307 else if (m_snapshot_v4lformat == V4L2_PIX_FMT_NV21) 1308 ALOGV("SnapshotFormat:V4L2_PIX_FMT_NV21"); 1309 else if (m_snapshot_v4lformat == V4L2_PIX_FMT_YUV422P) 1310 ALOGV("SnapshotFormat:V4L2_PIX_FMT_YUV422P"); 1311 else if (m_snapshot_v4lformat == V4L2_PIX_FMT_YUYV) 1312 ALOGV("SnapshotFormat:V4L2_PIX_FMT_YUYV"); 1313 else if (m_snapshot_v4lformat == V4L2_PIX_FMT_UYVY) 1314 ALOGV("SnapshotFormat:V4L2_PIX_FMT_UYVY"); 1315 else if (m_snapshot_v4lformat == V4L2_PIX_FMT_RGB565) 1316 ALOGV("SnapshotFormat:V4L2_PIX_FMT_RGB565"); 1317 else 1318 ALOGV("SnapshotFormat:UnknownFormat"); 1319#endif 1320 1321 LOG_TIME_START(1) // prepare 1322 int nframe = 1; 1323 1324 ret = fimc_v4l2_enum_fmt(m_cam_fd,m_snapshot_v4lformat); 1325 CHECK(ret); 1326 ret = fimc_v4l2_s_fmt_cap(m_cam_fd, m_snapshot_width, m_snapshot_height, m_snapshot_v4lformat); 1327 CHECK(ret); 1328 ret = fimc_v4l2_reqbufs(m_cam_fd, V4L2_BUF_TYPE_VIDEO_CAPTURE, nframe); 1329 CHECK(ret); 1330 ret = fimc_v4l2_querybuf(m_cam_fd, &m_capture_buf, V4L2_BUF_TYPE_VIDEO_CAPTURE); 1331 CHECK(ret); 1332 1333 ret = fimc_v4l2_qbuf(m_cam_fd, 0); 1334 CHECK(ret); 1335 1336 ret = fimc_v4l2_streamon(m_cam_fd); 1337 CHECK(ret); 1338 LOG_TIME_END(1) 1339 1340 LOG_TIME_START(2) // capture 1341 fimc_poll(&m_events_c); 1342 index = fimc_v4l2_dqbuf(m_cam_fd); 1343 fimc_v4l2_s_ctrl(m_cam_fd, V4L2_CID_STREAM_PAUSE, 0); 1344 ALOGV("\nsnapshot dequeued buffer = %d snapshot_width = %d snapshot_height = %d\n\n", 1345 index, m_snapshot_width, m_snapshot_height); 1346 1347 LOG_TIME_END(2) 1348 1349 ALOGI("%s : calling memcpy from m_capture_buf", __func__); 1350 memcpy(yuv_buf, (unsigned char*)m_capture_buf.start, m_snapshot_width * m_snapshot_height * 2); 1351 LOG_TIME_START(5) // post 1352 fimc_v4l2_streamoff(m_cam_fd); 1353 LOG_TIME_END(5) 1354 1355 LOG_CAMERA("getSnapshotAndJpeg intervals : stopPreview(%lu), prepare(%lu)," 1356 " capture(%lu), memcpy(%lu), yuv2Jpeg(%lu), post(%lu) us", 1357 LOG_TIME(0), LOG_TIME(1), LOG_TIME(2), LOG_TIME(3), LOG_TIME(4), LOG_TIME(5)); 1358 /* JPEG encoding */ 1359 JpegEncoder jpgEnc; 1360 int inFormat = JPG_MODESEL_YCBCR; 1361 int outFormat = JPG_422; 1362 1363 switch (m_snapshot_v4lformat) { 1364 case V4L2_PIX_FMT_NV12: 1365 case V4L2_PIX_FMT_NV21: 1366 case V4L2_PIX_FMT_NV12T: 1367 case V4L2_PIX_FMT_YUV420: 1368 outFormat = JPG_420; 1369 break; 1370 case V4L2_PIX_FMT_YUYV: 1371 case V4L2_PIX_FMT_UYVY: 1372 case V4L2_PIX_FMT_YUV422P: 1373 default: 1374 outFormat = JPG_422; 1375 break; 1376 } 1377 1378 if (jpgEnc.setConfig(JPEG_SET_ENCODE_IN_FORMAT, inFormat) != JPG_SUCCESS) 1379 ALOGE("[JPEG_SET_ENCODE_IN_FORMAT] Error\n"); 1380 1381 if (jpgEnc.setConfig(JPEG_SET_SAMPING_MODE, outFormat) != JPG_SUCCESS) 1382 ALOGE("[JPEG_SET_SAMPING_MODE] Error\n"); 1383 1384 image_quality_type_t jpegQuality; 1385 if (m_jpeg_quality >= 90) 1386 jpegQuality = JPG_QUALITY_LEVEL_1; 1387 else if (m_jpeg_quality >= 80) 1388 jpegQuality = JPG_QUALITY_LEVEL_2; 1389 else if (m_jpeg_quality >= 70) 1390 jpegQuality = JPG_QUALITY_LEVEL_3; 1391 else 1392 jpegQuality = JPG_QUALITY_LEVEL_4; 1393 1394 if (jpgEnc.setConfig(JPEG_SET_ENCODE_QUALITY, jpegQuality) != JPG_SUCCESS) 1395 ALOGE("[JPEG_SET_ENCODE_QUALITY] Error\n"); 1396 if (jpgEnc.setConfig(JPEG_SET_ENCODE_WIDTH, m_snapshot_width) != JPG_SUCCESS) 1397 ALOGE("[JPEG_SET_ENCODE_WIDTH] Error\n"); 1398 1399 if (jpgEnc.setConfig(JPEG_SET_ENCODE_HEIGHT, m_snapshot_height) != JPG_SUCCESS) 1400 ALOGE("[JPEG_SET_ENCODE_HEIGHT] Error\n"); 1401 1402 unsigned int snapshot_size = m_snapshot_width * m_snapshot_height * 2; 1403 unsigned char *pInBuf = (unsigned char *)jpgEnc.getInBuf(snapshot_size); 1404 1405 if (pInBuf == NULL) { 1406 ALOGE("JPEG input buffer is NULL!!\n"); 1407 return -1; 1408 } 1409 memcpy(pInBuf, yuv_buf, snapshot_size); 1410 1411 setExifChangedAttribute(); 1412 jpgEnc.encode(output_size, NULL); 1413 1414 uint64_t outbuf_size; 1415 unsigned char *pOutBuf = (unsigned char *)jpgEnc.getOutBuf(&outbuf_size); 1416 1417 if (pOutBuf == NULL) { 1418 ALOGE("JPEG output buffer is NULL!!\n"); 1419 return -1; 1420 } 1421 1422 memcpy(jpeg_buf, pOutBuf, outbuf_size); 1423 1424 return 0; 1425} 1426 1427 1428int SecCamera::setSnapshotSize(int width, int height) 1429{ 1430 ALOGV("%s(width(%d), height(%d))", __func__, width, height); 1431 1432 m_snapshot_width = width; 1433 m_snapshot_height = height; 1434 1435 return 0; 1436} 1437 1438int SecCamera::getSnapshotSize(int *width, int *height, int *frame_size) 1439{ 1440 *width = m_snapshot_width; 1441 *height = m_snapshot_height; 1442 1443 int frame = 0; 1444 1445 frame = m_frameSize(m_snapshot_v4lformat, m_snapshot_width, m_snapshot_height); 1446 1447 // set it big. 1448 if (frame == 0) 1449 frame = m_snapshot_width * m_snapshot_height * BPP; 1450 1451 *frame_size = frame; 1452 1453 return 0; 1454} 1455 1456int SecCamera::getSnapshotMaxSize(int *width, int *height) 1457{ 1458 switch (m_camera_id) { 1459 case CAMERA_ID_FRONT: 1460 m_snapshot_max_width = MAX_FRONT_CAMERA_SNAPSHOT_WIDTH; 1461 m_snapshot_max_height = MAX_FRONT_CAMERA_SNAPSHOT_HEIGHT; 1462 break; 1463 1464 default: 1465 case CAMERA_ID_BACK: 1466 m_snapshot_max_width = MAX_BACK_CAMERA_SNAPSHOT_WIDTH; 1467 m_snapshot_max_height = MAX_BACK_CAMERA_SNAPSHOT_HEIGHT; 1468 break; 1469 } 1470 1471 *width = m_snapshot_max_width; 1472 *height = m_snapshot_max_height; 1473 1474 return 0; 1475} 1476 1477int SecCamera::setSnapshotPixelFormat(int pixel_format) 1478{ 1479 int v4lpixelformat= pixel_format; 1480 1481 if (m_snapshot_v4lformat != v4lpixelformat) { 1482 m_snapshot_v4lformat = v4lpixelformat; 1483 } 1484 1485#if defined(LOG_NDEBUG) && LOG_NDEBUG == 0 1486 if (m_snapshot_v4lformat == V4L2_PIX_FMT_YUV420) 1487 ALOGE("%s : SnapshotFormat:V4L2_PIX_FMT_YUV420", __func__); 1488 else if (m_snapshot_v4lformat == V4L2_PIX_FMT_NV12) 1489 ALOGD("%s : SnapshotFormat:V4L2_PIX_FMT_NV12", __func__); 1490 else if (m_snapshot_v4lformat == V4L2_PIX_FMT_NV12T) 1491 ALOGD("%s : SnapshotFormat:V4L2_PIX_FMT_NV12T", __func__); 1492 else if (m_snapshot_v4lformat == V4L2_PIX_FMT_NV21) 1493 ALOGD("%s : SnapshotFormat:V4L2_PIX_FMT_NV21", __func__); 1494 else if (m_snapshot_v4lformat == V4L2_PIX_FMT_YUV422P) 1495 ALOGD("%s : SnapshotFormat:V4L2_PIX_FMT_YUV422P", __func__); 1496 else if (m_snapshot_v4lformat == V4L2_PIX_FMT_YUYV) 1497 ALOGD("%s : SnapshotFormat:V4L2_PIX_FMT_YUYV", __func__); 1498 else if (m_snapshot_v4lformat == V4L2_PIX_FMT_UYVY) 1499 ALOGD("%s : SnapshotFormat:V4L2_PIX_FMT_UYVY", __func__); 1500 else if (m_snapshot_v4lformat == V4L2_PIX_FMT_RGB565) 1501 ALOGD("%s : SnapshotFormat:V4L2_PIX_FMT_RGB565", __func__); 1502 else 1503 ALOGD("SnapshotFormat:UnknownFormat"); 1504#endif 1505 return 0; 1506} 1507 1508int SecCamera::getSnapshotPixelFormat(void) 1509{ 1510 return m_snapshot_v4lformat; 1511} 1512 1513// ====================================================================== 1514// Settings 1515 1516int SecCamera::getCameraId(void) 1517{ 1518 return m_camera_id; 1519} 1520 1521// ----------------------------------- 1522 1523int SecCamera::setAutofocus(void) 1524{ 1525 ALOGV("%s :", __func__); 1526 1527 if (m_cam_fd <= 0) { 1528 ALOGE("ERR(%s):Camera was closed\n", __func__); 1529 return -1; 1530 } 1531 1532 if (fimc_v4l2_s_ctrl(m_cam_fd, V4L2_CID_CAMERA_SET_AUTO_FOCUS, AUTO_FOCUS_ON) < 0) { 1533 ALOGE("ERR(%s):Fail on V4L2_CID_CAMERA_SET_AUTO_FOCUS", __func__); 1534 return -1; 1535 } 1536 1537 return 0; 1538} 1539 1540int SecCamera::getAutoFocusResult(void) 1541{ 1542 int af_result, count, ret; 1543 1544 for (count = 0; count < FIRST_AF_SEARCH_COUNT; count++) { 1545 ret = fimc_v4l2_g_ctrl(m_cam_fd, V4L2_CID_CAMERA_AUTO_FOCUS_RESULT_FIRST); 1546 if (ret != AF_PROGRESS) 1547 break; 1548 usleep(AF_DELAY); 1549 } 1550 if ((count >= FIRST_AF_SEARCH_COUNT) || (ret != AF_SUCCESS)) { 1551 ALOGV("%s : 1st AF timed out, failed, or was canceled", __func__); 1552 af_result = 0; 1553 goto finish_auto_focus; 1554 } 1555 1556 for (count = 0; count < SECOND_AF_SEARCH_COUNT; count++) { 1557 ret = fimc_v4l2_g_ctrl(m_cam_fd, V4L2_CID_CAMERA_AUTO_FOCUS_RESULT_SECOND); 1558 /* low byte is garbage. done when high byte is 0x0 */ 1559 if (!(ret & 0xff00)) 1560 break; 1561 usleep(AF_DELAY); 1562 } 1563 if (count >= SECOND_AF_SEARCH_COUNT) { 1564 ALOGV("%s : 2nd AF timed out, failed, or was canceled", __func__); 1565 af_result = 0; 1566 goto finish_auto_focus; 1567 } 1568 1569 af_result = 1; 1570 ALOGV("%s : AF was successful, returning %d", __func__, af_result); 1571 1572finish_auto_focus: 1573 if (fimc_v4l2_s_ctrl(m_cam_fd, V4L2_CID_CAMERA_FINISH_AUTO_FOCUS, 0) < 0) { 1574 ALOGE("ERR(%s):Fail on V4L2_CID_CAMERA_SET_PRE_FLASH", __func__); 1575 return -1; 1576 } 1577 return af_result; 1578} 1579 1580int SecCamera::cancelAutofocus(void) 1581{ 1582 ALOGV("%s :", __func__); 1583 1584 if (m_cam_fd <= 0) { 1585 ALOGE("ERR(%s):Camera was closed\n", __func__); 1586 return -1; 1587 } 1588 1589 if (fimc_v4l2_s_ctrl(m_cam_fd, V4L2_CID_CAMERA_SET_AUTO_FOCUS, AUTO_FOCUS_OFF) < 0) { 1590 ALOGE("ERR(%s):Fail on V4L2_CID_CAMERA_SET_AUTO_FOCUS", __func__); 1591 return -1; 1592 } 1593 1594 return 0; 1595} 1596 1597// ----------------------------------- 1598 1599int SecCamera::zoomIn(void) 1600{ 1601 ALOGV("%s :", __func__); 1602 return 0; 1603} 1604 1605int SecCamera::zoomOut(void) 1606{ 1607 ALOGV("%s :", __func__); 1608 return 0; 1609} 1610 1611// ----------------------------------- 1612 1613int SecCamera::SetRotate(int angle) 1614{ 1615 ALOGE("%s(angle(%d))", __func__, angle); 1616 1617 if (m_angle != angle) { 1618 switch (angle) { 1619 case -360: 1620 case 0: 1621 case 360: 1622 m_angle = 0; 1623 break; 1624 1625 case -270: 1626 case 90: 1627 m_angle = 90; 1628 break; 1629 1630 case -180: 1631 case 180: 1632 m_angle = 180; 1633 break; 1634 1635 case -90: 1636 case 270: 1637 m_angle = 270; 1638 break; 1639 1640 default: 1641 ALOGE("ERR(%s):Invalid angle(%d)", __func__, angle); 1642 return -1; 1643 } 1644 1645 if (m_flag_camera_start) { 1646 if (fimc_v4l2_s_ctrl(m_cam_fd, V4L2_CID_ROTATION, angle) < 0) { 1647 ALOGE("ERR(%s):Fail on V4L2_CID_ROTATION", __func__); 1648 return -1; 1649 } 1650 } 1651 } 1652 1653 return 0; 1654} 1655 1656int SecCamera::getRotate(void) 1657{ 1658 ALOGV("%s : angle(%d)", __func__, m_angle); 1659 return m_angle; 1660} 1661 1662int SecCamera::setFrameRate(int frame_rate) 1663{ 1664 ALOGV("%s(FrameRate(%d))", __func__, frame_rate); 1665 1666 if (frame_rate < FRAME_RATE_AUTO || FRAME_RATE_MAX < frame_rate ) 1667 ALOGE("ERR(%s):Invalid frame_rate(%d)", __func__, frame_rate); 1668 1669 if (m_params->capture.timeperframe.denominator != (unsigned)frame_rate) { 1670 m_params->capture.timeperframe.denominator = frame_rate; 1671 if (m_flag_camera_start) { 1672 if (fimc_v4l2_s_ctrl(m_cam_fd, V4L2_CID_CAMERA_FRAME_RATE, frame_rate) < 0) { 1673 ALOGE("ERR(%s):Fail on V4L2_CID_CAMERA_FRAME_RATE", __func__); 1674 return -1; 1675 } 1676 } 1677 } 1678 1679 return 0; 1680} 1681 1682// ----------------------------------- 1683 1684int SecCamera::setVerticalMirror(void) 1685{ 1686 ALOGV("%s :", __func__); 1687 1688 if (m_cam_fd <= 0) { 1689 ALOGE("ERR(%s):Camera was closed\n", __func__); 1690 return -1; 1691 } 1692 1693 if (fimc_v4l2_s_ctrl(m_cam_fd, V4L2_CID_VFLIP, 0) < 0) { 1694 ALOGE("ERR(%s):Fail on V4L2_CID_VFLIP", __func__); 1695 return -1; 1696 } 1697 1698 return 0; 1699} 1700 1701int SecCamera::setHorizontalMirror(void) 1702{ 1703 ALOGV("%s :", __func__); 1704 1705 if (m_cam_fd <= 0) { 1706 ALOGE("ERR(%s):Camera was closed\n", __func__); 1707 return -1; 1708 } 1709 1710 if (fimc_v4l2_s_ctrl(m_cam_fd, V4L2_CID_HFLIP, 0) < 0) { 1711 ALOGE("ERR(%s):Fail on V4L2_CID_HFLIP", __func__); 1712 return -1; 1713 } 1714 1715 return 0; 1716} 1717 1718// ----------------------------------- 1719 1720int SecCamera::setWhiteBalance(int white_balance) 1721{ 1722 ALOGV("%s(white_balance(%d))", __func__, white_balance); 1723 1724 if (white_balance <= WHITE_BALANCE_BASE || WHITE_BALANCE_MAX <= white_balance) { 1725 ALOGE("ERR(%s):Invalid white_balance(%d)", __func__, white_balance); 1726 return -1; 1727 } 1728 1729 if (m_params->white_balance != white_balance) { 1730 m_params->white_balance = white_balance; 1731 if (m_flag_camera_start) { 1732 if (fimc_v4l2_s_ctrl(m_cam_fd, V4L2_CID_CAMERA_WHITE_BALANCE, white_balance) < 0) { 1733 ALOGE("ERR(%s):Fail on V4L2_CID_CAMERA_WHITE_BALANCE", __func__); 1734 return -1; 1735 } 1736 } 1737 } 1738 1739 return 0; 1740} 1741 1742int SecCamera::getWhiteBalance(void) 1743{ 1744 ALOGV("%s : white_balance(%d)", __func__, m_params->white_balance); 1745 return m_params->white_balance; 1746} 1747 1748// ----------------------------------- 1749 1750int SecCamera::setBrightness(int brightness) 1751{ 1752 ALOGV("%s(brightness(%d))", __func__, brightness); 1753 1754 brightness += EV_DEFAULT; 1755 1756 if (brightness < EV_MINUS_4 || EV_PLUS_4 < brightness) { 1757 ALOGE("ERR(%s):Invalid brightness(%d)", __func__, brightness); 1758 return -1; 1759 } 1760 1761 if (m_params->brightness != brightness) { 1762 m_params->brightness = brightness; 1763 if (m_flag_camera_start) { 1764 if (fimc_v4l2_s_ctrl(m_cam_fd, V4L2_CID_CAMERA_BRIGHTNESS, brightness) < 0) { 1765 ALOGE("ERR(%s):Fail on V4L2_CID_CAMERA_BRIGHTNESS", __func__); 1766 return -1; 1767 } 1768 } 1769 } 1770 1771 return 0; 1772} 1773 1774int SecCamera::getBrightness(void) 1775{ 1776 ALOGV("%s : brightness(%d)", __func__, m_params->brightness); 1777 return m_params->brightness; 1778} 1779 1780// ----------------------------------- 1781 1782int SecCamera::setImageEffect(int image_effect) 1783{ 1784 ALOGV("%s(image_effect(%d))", __func__, image_effect); 1785 1786 if (image_effect <= IMAGE_EFFECT_BASE || IMAGE_EFFECT_MAX <= image_effect) { 1787 ALOGE("ERR(%s):Invalid image_effect(%d)", __func__, image_effect); 1788 return -1; 1789 } 1790 1791 if (m_params->effects != image_effect) { 1792 m_params->effects = image_effect; 1793 if (m_flag_camera_start) { 1794 if (fimc_v4l2_s_ctrl(m_cam_fd, V4L2_CID_CAMERA_EFFECT, image_effect) < 0) { 1795 ALOGE("ERR(%s):Fail on V4L2_CID_CAMERA_EFFECT", __func__); 1796 return -1; 1797 } 1798 } 1799 } 1800 1801 return 0; 1802} 1803 1804int SecCamera::getImageEffect(void) 1805{ 1806 ALOGV("%s : image_effect(%d)", __func__, m_params->effects); 1807 return m_params->effects; 1808} 1809 1810// ====================================================================== 1811int SecCamera::setAntiBanding(int anti_banding) 1812{ 1813 ALOGV("%s(anti_banding(%d))", __func__, anti_banding); 1814 1815 if (anti_banding < ANTI_BANDING_AUTO || ANTI_BANDING_OFF < anti_banding) { 1816 ALOGE("ERR(%s):Invalid anti_banding (%d)", __func__, anti_banding); 1817 return -1; 1818 } 1819 1820 if (m_anti_banding != anti_banding) { 1821 m_anti_banding = anti_banding; 1822 if (m_flag_camera_start) { 1823 if (fimc_v4l2_s_ctrl(m_cam_fd, V4L2_CID_CAMERA_ANTI_BANDING, anti_banding) < 0) { 1824 ALOGE("ERR(%s):Fail on V4L2_CID_CAMERA_ANTI_BANDING", __func__); 1825 return -1; 1826 } 1827 } 1828 } 1829 1830 return 0; 1831} 1832 1833//====================================================================== 1834int SecCamera::setSceneMode(int scene_mode) 1835{ 1836 ALOGV("%s(scene_mode(%d))", __func__, scene_mode); 1837 1838 if (scene_mode <= SCENE_MODE_BASE || SCENE_MODE_MAX <= scene_mode) { 1839 ALOGE("ERR(%s):Invalid scene_mode (%d)", __func__, scene_mode); 1840 return -1; 1841 } 1842 1843 if (m_params->scene_mode != scene_mode) { 1844 m_params->scene_mode = scene_mode; 1845 if (m_flag_camera_start) { 1846 if (fimc_v4l2_s_ctrl(m_cam_fd, V4L2_CID_CAMERA_SCENE_MODE, scene_mode) < 0) { 1847 ALOGE("ERR(%s):Fail on V4L2_CID_CAMERA_SCENE_MODE", __func__); 1848 return -1; 1849 } 1850 } 1851 } 1852 1853 return 0; 1854} 1855 1856int SecCamera::getSceneMode(void) 1857{ 1858 return m_params->scene_mode; 1859} 1860 1861//====================================================================== 1862 1863int SecCamera::setFlashMode(int flash_mode) 1864{ 1865 ALOGV("%s(flash_mode(%d))", __func__, flash_mode); 1866 1867 if (flash_mode <= FLASH_MODE_BASE || FLASH_MODE_MAX <= flash_mode) { 1868 ALOGE("ERR(%s):Invalid flash_mode (%d)", __func__, flash_mode); 1869 return -1; 1870 } 1871 1872 if (m_params->flash_mode != flash_mode) { 1873 m_params->flash_mode = flash_mode; 1874 if (m_flag_camera_start) { 1875 if (fimc_v4l2_s_ctrl(m_cam_fd, V4L2_CID_CAMERA_FLASH_MODE, flash_mode) < 0) { 1876 ALOGE("ERR(%s):Fail on V4L2_CID_CAMERA_FLASH_MODE", __func__); 1877 return -1; 1878 } 1879 } 1880 } 1881 1882 return 0; 1883} 1884 1885int SecCamera::getFlashMode(void) 1886{ 1887 return m_params->flash_mode; 1888} 1889 1890//====================================================================== 1891 1892int SecCamera::setISO(int iso_value) 1893{ 1894 ALOGV("%s(iso_value(%d))", __func__, iso_value); 1895 if (iso_value < ISO_AUTO || ISO_MAX <= iso_value) { 1896 ALOGE("ERR(%s):Invalid iso_value (%d)", __func__, iso_value); 1897 return -1; 1898 } 1899 1900 if (m_params->iso != iso_value) { 1901 m_params->iso = iso_value; 1902 if (m_flag_camera_start) { 1903 if (fimc_v4l2_s_ctrl(m_cam_fd, V4L2_CID_CAMERA_ISO, iso_value) < 0) { 1904 ALOGE("ERR(%s):Fail on V4L2_CID_CAMERA_ISO", __func__); 1905 return -1; 1906 } 1907 } 1908 } 1909 1910 return 0; 1911} 1912 1913int SecCamera::getISO(void) 1914{ 1915 return m_params->iso; 1916} 1917 1918//====================================================================== 1919 1920int SecCamera::setContrast(int contrast_value) 1921{ 1922 ALOGV("%s(contrast_value(%d))", __func__, contrast_value); 1923 1924 if (contrast_value < CONTRAST_MINUS_2 || CONTRAST_MAX <= contrast_value) { 1925 ALOGE("ERR(%s):Invalid contrast_value (%d)", __func__, contrast_value); 1926 return -1; 1927 } 1928 1929 if (m_params->contrast != contrast_value) { 1930 m_params->contrast = contrast_value; 1931 if (m_flag_camera_start) { 1932 if (fimc_v4l2_s_ctrl(m_cam_fd, V4L2_CID_CAMERA_CONTRAST, contrast_value) < 0) { 1933 ALOGE("ERR(%s):Fail on V4L2_CID_CAMERA_CONTRAST", __func__); 1934 return -1; 1935 } 1936 } 1937 } 1938 1939 return 0; 1940} 1941 1942int SecCamera::getContrast(void) 1943{ 1944 return m_params->contrast; 1945} 1946 1947//====================================================================== 1948 1949int SecCamera::setSaturation(int saturation_value) 1950{ 1951 ALOGV("%s(saturation_value(%d))", __func__, saturation_value); 1952 1953 if (saturation_value <SATURATION_MINUS_2 || SATURATION_MAX<= saturation_value) { 1954 ALOGE("ERR(%s):Invalid saturation_value (%d)", __func__, saturation_value); 1955 return -1; 1956 } 1957 1958 if (m_params->saturation != saturation_value) { 1959 m_params->saturation = saturation_value; 1960 if (m_flag_camera_start) { 1961 if (fimc_v4l2_s_ctrl(m_cam_fd, V4L2_CID_CAMERA_SATURATION, saturation_value) < 0) { 1962 ALOGE("ERR(%s):Fail on V4L2_CID_CAMERA_SATURATION", __func__); 1963 return -1; 1964 } 1965 } 1966 } 1967 1968 return 0; 1969} 1970 1971int SecCamera::getSaturation(void) 1972{ 1973 return m_params->saturation; 1974} 1975 1976//====================================================================== 1977 1978int SecCamera::setSharpness(int sharpness_value) 1979{ 1980 ALOGV("%s(sharpness_value(%d))", __func__, sharpness_value); 1981 1982 if (sharpness_value < SHARPNESS_MINUS_2 || SHARPNESS_MAX <= sharpness_value) { 1983 ALOGE("ERR(%s):Invalid sharpness_value (%d)", __func__, sharpness_value); 1984 return -1; 1985 } 1986 1987 if (m_params->sharpness != sharpness_value) { 1988 m_params->sharpness = sharpness_value; 1989 if (m_flag_camera_start) { 1990 if (fimc_v4l2_s_ctrl(m_cam_fd, V4L2_CID_CAMERA_SHARPNESS, sharpness_value) < 0) { 1991 ALOGE("ERR(%s):Fail on V4L2_CID_CAMERA_SHARPNESS", __func__); 1992 return -1; 1993 } 1994 } 1995 } 1996 1997 return 0; 1998} 1999 2000int SecCamera::getSharpness(void) 2001{ 2002 return m_params->sharpness; 2003} 2004 2005//====================================================================== 2006 2007int SecCamera::setWDR(int wdr_value) 2008{ 2009 ALOGV("%s(wdr_value(%d))", __func__, wdr_value); 2010 2011 if (wdr_value < WDR_OFF || WDR_MAX <= wdr_value) { 2012 ALOGE("ERR(%s):Invalid wdr_value (%d)", __func__, wdr_value); 2013 return -1; 2014 } 2015 2016 if (m_wdr != wdr_value) { 2017 m_wdr = wdr_value; 2018 if (m_flag_camera_start) { 2019 if (fimc_v4l2_s_ctrl(m_cam_fd, V4L2_CID_CAMERA_WDR, wdr_value) < 0) { 2020 ALOGE("ERR(%s):Fail on V4L2_CID_CAMERA_WDR", __func__); 2021 return -1; 2022 } 2023 } 2024 } 2025 2026 return 0; 2027} 2028 2029int SecCamera::getWDR(void) 2030{ 2031 return m_wdr; 2032} 2033 2034//====================================================================== 2035 2036int SecCamera::setAntiShake(int anti_shake) 2037{ 2038 ALOGV("%s(anti_shake(%d))", __func__, anti_shake); 2039 2040 if (anti_shake < ANTI_SHAKE_OFF || ANTI_SHAKE_MAX <= anti_shake) { 2041 ALOGE("ERR(%s):Invalid anti_shake (%d)", __func__, anti_shake); 2042 return -1; 2043 } 2044 2045 if (m_anti_shake != anti_shake) { 2046 m_anti_shake = anti_shake; 2047 if (m_flag_camera_start) { 2048 if (fimc_v4l2_s_ctrl(m_cam_fd, V4L2_CID_CAMERA_ANTI_SHAKE, anti_shake) < 0) { 2049 ALOGE("ERR(%s):Fail on V4L2_CID_CAMERA_ANTI_SHAKE", __func__); 2050 return -1; 2051 } 2052 } 2053 } 2054 2055 return 0; 2056} 2057 2058int SecCamera::getAntiShake(void) 2059{ 2060 return m_anti_shake; 2061} 2062 2063//====================================================================== 2064 2065 2066int SecCamera::setMetering(int metering_value) 2067{ 2068 ALOGV("%s(metering (%d))", __func__, metering_value); 2069 2070 if (metering_value <= METERING_BASE || METERING_MAX <= metering_value) { 2071 ALOGE("ERR(%s):Invalid metering_value (%d)", __func__, metering_value); 2072 return -1; 2073 } 2074 2075 if (m_params->metering != metering_value) { 2076 m_params->metering = metering_value; 2077 if (m_flag_camera_start) { 2078 if (fimc_v4l2_s_ctrl(m_cam_fd, V4L2_CID_CAMERA_METERING, metering_value) < 0) { 2079 ALOGE("ERR(%s):Fail on V4L2_CID_CAMERA_METERING", __func__); 2080 return -1; 2081 } 2082 } 2083 } 2084 2085 return 0; 2086} 2087 2088int SecCamera::getMetering(void) 2089{ 2090 return m_params->metering; 2091} 2092 2093//====================================================================== 2094 2095int SecCamera::setJpegQuality(int jpeg_quality) 2096{ 2097 ALOGV("%s(jpeg_quality (%d))", __func__, jpeg_quality); 2098 2099 if (jpeg_quality < JPEG_QUALITY_ECONOMY || JPEG_QUALITY_MAX <= jpeg_quality) { 2100 ALOGE("ERR(%s):Invalid jpeg_quality (%d)", __func__, jpeg_quality); 2101 return -1; 2102 } 2103 2104 if (m_jpeg_quality != jpeg_quality) { 2105 m_jpeg_quality = jpeg_quality; 2106 if (m_flag_camera_start && (m_camera_id == CAMERA_ID_BACK)) { 2107 if (fimc_v4l2_s_ctrl(m_cam_fd, V4L2_CID_CAM_JPEG_QUALITY, jpeg_quality) < 0) { 2108 ALOGE("ERR(%s):Fail on V4L2_CID_CAM_JPEG_QUALITY", __func__); 2109 return -1; 2110 } 2111 } 2112 } 2113 2114 return 0; 2115} 2116 2117int SecCamera::getJpegQuality(void) 2118{ 2119 return m_jpeg_quality; 2120} 2121 2122//====================================================================== 2123 2124int SecCamera::setZoom(int zoom_level) 2125{ 2126 ALOGV("%s(zoom_level (%d))", __func__, zoom_level); 2127 2128 if (zoom_level < ZOOM_LEVEL_0 || ZOOM_LEVEL_MAX <= zoom_level) { 2129 ALOGE("ERR(%s):Invalid zoom_level (%d)", __func__, zoom_level); 2130 return -1; 2131 } 2132 2133 if (m_zoom_level != zoom_level) { 2134 m_zoom_level = zoom_level; 2135 if (m_flag_camera_start) { 2136 if (fimc_v4l2_s_ctrl(m_cam_fd, V4L2_CID_CAMERA_ZOOM, zoom_level) < 0) { 2137 ALOGE("ERR(%s):Fail on V4L2_CID_CAMERA_ZOOM", __func__); 2138 return -1; 2139 } 2140 } 2141 } 2142 2143 return 0; 2144} 2145 2146int SecCamera::getZoom(void) 2147{ 2148 return m_zoom_level; 2149} 2150 2151//====================================================================== 2152 2153int SecCamera::setObjectTracking(int object_tracking) 2154{ 2155 ALOGV("%s(object_tracking (%d))", __func__, object_tracking); 2156 2157 if (object_tracking < OBJECT_TRACKING_OFF || OBJECT_TRACKING_MAX <= object_tracking) { 2158 ALOGE("ERR(%s):Invalid object_tracking (%d)", __func__, object_tracking); 2159 return -1; 2160 } 2161 2162 if (m_object_tracking != object_tracking) { 2163 m_object_tracking = object_tracking; 2164 } 2165 2166 return 0; 2167} 2168 2169int SecCamera::getObjectTracking(void) 2170{ 2171 return m_object_tracking; 2172} 2173 2174int SecCamera::getObjectTrackingStatus(void) 2175{ 2176 int obj_status = 0; 2177 obj_status = fimc_v4l2_g_ctrl(m_cam_fd, V4L2_CID_CAMERA_OBJ_TRACKING_STATUS); 2178 return obj_status; 2179} 2180 2181int SecCamera::setObjectTrackingStartStop(int start_stop) 2182{ 2183 ALOGV("%s(object_tracking_start_stop (%d))", __func__, start_stop); 2184 2185 if (m_object_tracking_start_stop != start_stop) { 2186 m_object_tracking_start_stop = start_stop; 2187 if (fimc_v4l2_s_ctrl(m_cam_fd, V4L2_CID_CAMERA_OBJ_TRACKING_START_STOP, start_stop) < 0) { 2188 ALOGE("ERR(%s):Fail on V4L2_CID_CAMERA_OBJ_TRACKING_START_STOP", __func__); 2189 return -1; 2190 } 2191 } 2192 2193 return 0; 2194} 2195 2196int SecCamera::setTouchAFStartStop(int start_stop) 2197{ 2198 ALOGV("%s(touch_af_start_stop (%d))", __func__, start_stop); 2199 2200 if (m_touch_af_start_stop != start_stop) { 2201 m_touch_af_start_stop = start_stop; 2202 if (fimc_v4l2_s_ctrl(m_cam_fd, V4L2_CID_CAMERA_TOUCH_AF_START_STOP, start_stop) < 0) { 2203 ALOGE("ERR(%s):Fail on V4L2_CID_CAMERA_TOUCH_AF_START_STOP", __func__); 2204 return -1; 2205 } 2206 } 2207 2208 return 0; 2209} 2210 2211//====================================================================== 2212 2213int SecCamera::setSmartAuto(int smart_auto) 2214{ 2215 ALOGV("%s(smart_auto (%d))", __func__, smart_auto); 2216 2217 if (smart_auto < SMART_AUTO_OFF || SMART_AUTO_MAX <= smart_auto) { 2218 ALOGE("ERR(%s):Invalid smart_auto (%d)", __func__, smart_auto); 2219 return -1; 2220 } 2221 2222 if (m_smart_auto != smart_auto) { 2223 m_smart_auto = smart_auto; 2224 if (m_flag_camera_start) { 2225 if (fimc_v4l2_s_ctrl(m_cam_fd, V4L2_CID_CAMERA_SMART_AUTO, smart_auto) < 0) { 2226 ALOGE("ERR(%s):Fail on V4L2_CID_CAMERA_SMART_AUTO", __func__); 2227 return -1; 2228 } 2229 } 2230 } 2231 2232 return 0; 2233} 2234 2235int SecCamera::getSmartAuto(void) 2236{ 2237 return m_smart_auto; 2238} 2239 2240int SecCamera::getAutosceneStatus(void) 2241{ 2242 int autoscene_status = -1; 2243 2244 if (getSmartAuto() == SMART_AUTO_ON) { 2245 autoscene_status = fimc_v4l2_g_ctrl(m_cam_fd, V4L2_CID_CAMERA_SMART_AUTO_STATUS); 2246 2247 if ((autoscene_status < SMART_AUTO_STATUS_AUTO) || (autoscene_status > SMART_AUTO_STATUS_MAX)) { 2248 ALOGE("ERR(%s):Invalid getAutosceneStatus (%d)", __func__, autoscene_status); 2249 return -1; 2250 } 2251 } 2252 //ALOGV("%s : autoscene_status (%d)", __func__, autoscene_status); 2253 return autoscene_status; 2254} 2255//====================================================================== 2256 2257int SecCamera::setBeautyShot(int beauty_shot) 2258{ 2259 ALOGV("%s(beauty_shot (%d))", __func__, beauty_shot); 2260 2261 if (beauty_shot < BEAUTY_SHOT_OFF || BEAUTY_SHOT_MAX <= beauty_shot) { 2262 ALOGE("ERR(%s):Invalid beauty_shot (%d)", __func__, beauty_shot); 2263 return -1; 2264 } 2265 2266 if (m_beauty_shot != beauty_shot) { 2267 m_beauty_shot = beauty_shot; 2268 if (m_flag_camera_start) { 2269 if (fimc_v4l2_s_ctrl(m_cam_fd, V4L2_CID_CAMERA_BEAUTY_SHOT, beauty_shot) < 0) { 2270 ALOGE("ERR(%s):Fail on V4L2_CID_CAMERA_BEAUTY_SHOT", __func__); 2271 return -1; 2272 } 2273 } 2274 2275 setFaceDetect(FACE_DETECTION_ON_BEAUTY); 2276 } 2277 2278 return 0; 2279} 2280 2281int SecCamera::getBeautyShot(void) 2282{ 2283 return m_beauty_shot; 2284} 2285 2286//====================================================================== 2287 2288int SecCamera::setVintageMode(int vintage_mode) 2289{ 2290 ALOGV("%s(vintage_mode(%d))", __func__, vintage_mode); 2291 2292 if (vintage_mode <= VINTAGE_MODE_BASE || VINTAGE_MODE_MAX <= vintage_mode) { 2293 ALOGE("ERR(%s):Invalid vintage_mode (%d)", __func__, vintage_mode); 2294 return -1; 2295 } 2296 2297 if (m_vintage_mode != vintage_mode) { 2298 m_vintage_mode = vintage_mode; 2299 if (m_flag_camera_start) { 2300 if (fimc_v4l2_s_ctrl(m_cam_fd, V4L2_CID_CAMERA_VINTAGE_MODE, vintage_mode) < 0) { 2301 ALOGE("ERR(%s):Fail on V4L2_CID_CAMERA_VINTAGE_MODE", __func__); 2302 return -1; 2303 } 2304 } 2305 } 2306 2307 return 0; 2308} 2309 2310int SecCamera::getVintageMode(void) 2311{ 2312 return m_vintage_mode; 2313} 2314 2315//====================================================================== 2316 2317int SecCamera::setFocusMode(int focus_mode) 2318{ 2319 ALOGV("%s(focus_mode(%d))", __func__, focus_mode); 2320 2321 if (FOCUS_MODE_MAX <= focus_mode) { 2322 ALOGE("ERR(%s):Invalid focus_mode (%d)", __func__, focus_mode); 2323 return -1; 2324 } 2325 2326 if (m_params->focus_mode != focus_mode) { 2327 m_params->focus_mode = focus_mode; 2328 2329 if (m_flag_camera_start) { 2330 if (fimc_v4l2_s_ctrl(m_cam_fd, V4L2_CID_CAMERA_FOCUS_MODE, focus_mode) < 0) { 2331 ALOGE("ERR(%s):Fail on V4L2_CID_CAMERA_FOCUS_MODE", __func__); 2332 return -1; 2333 } 2334 } 2335 } 2336 2337 return 0; 2338} 2339 2340int SecCamera::getFocusMode(void) 2341{ 2342 return m_params->focus_mode; 2343} 2344 2345//====================================================================== 2346 2347int SecCamera::setFaceDetect(int face_detect) 2348{ 2349 ALOGV("%s(face_detect(%d))", __func__, face_detect); 2350 2351 if (m_face_detect != face_detect) { 2352 m_face_detect = face_detect; 2353 if (m_flag_camera_start) { 2354 if (m_face_detect != FACE_DETECTION_OFF) { 2355 if (fimc_v4l2_s_ctrl(m_cam_fd, V4L2_CID_CAMERA_FOCUS_MODE, FOCUS_MODE_AUTO) < 0) { 2356 ALOGE("ERR(%s):Fail on V4L2_CID_CAMERA_FOCUS_MODin face detecion", __func__); 2357 return -1; 2358 } 2359 } 2360 if (fimc_v4l2_s_ctrl(m_cam_fd, V4L2_CID_CAMERA_FACE_DETECTION, face_detect) < 0) { 2361 ALOGE("ERR(%s):Fail on V4L2_CID_CAMERA_FACE_DETECTION", __func__); 2362 return -1; 2363 } 2364 } 2365 } 2366 2367 return 0; 2368} 2369 2370int SecCamera::getFaceDetect(void) 2371{ 2372 return m_face_detect; 2373} 2374 2375//====================================================================== 2376 2377int SecCamera::setGPSLatitude(const char *gps_latitude) 2378{ 2379 ALOGV("%s(gps_latitude(%s))", __func__, gps_latitude); 2380 if (gps_latitude == NULL) 2381 m_gps_enabled = false; 2382 else { 2383 m_gps_enabled = true; 2384 m_gps_latitude = lround(strtod(gps_latitude, NULL) * 10000000); 2385 } 2386 2387 ALOGV("%s(m_gps_latitude(%ld))", __func__, m_gps_latitude); 2388 return 0; 2389} 2390 2391int SecCamera::setGPSLongitude(const char *gps_longitude) 2392{ 2393 ALOGV("%s(gps_longitude(%s))", __func__, gps_longitude); 2394 if (gps_longitude == NULL) 2395 m_gps_enabled = false; 2396 else { 2397 m_gps_enabled = true; 2398 m_gps_longitude = lround(strtod(gps_longitude, NULL) * 10000000); 2399 } 2400 2401 ALOGV("%s(m_gps_longitude(%ld))", __func__, m_gps_longitude); 2402 return 0; 2403} 2404 2405int SecCamera::setGPSAltitude(const char *gps_altitude) 2406{ 2407 ALOGV("%s(gps_altitude(%s))", __func__, gps_altitude); 2408 if (gps_altitude == NULL) 2409 m_gps_altitude = 0; 2410 else { 2411 m_gps_altitude = lround(strtod(gps_altitude, NULL) * 100); 2412 } 2413 2414 ALOGV("%s(m_gps_altitude(%ld))", __func__, m_gps_altitude); 2415 return 0; 2416} 2417 2418int SecCamera::setGPSTimeStamp(const char *gps_timestamp) 2419{ 2420 ALOGV("%s(gps_timestamp(%s))", __func__, gps_timestamp); 2421 if (gps_timestamp == NULL) 2422 m_gps_timestamp = 0; 2423 else 2424 m_gps_timestamp = atol(gps_timestamp); 2425 2426 ALOGV("%s(m_gps_timestamp(%ld))", __func__, m_gps_timestamp); 2427 return 0; 2428} 2429 2430int SecCamera::setGPSProcessingMethod(const char *gps_processing_method) 2431{ 2432 ALOGV("%s(gps_processing_method(%s))", __func__, gps_processing_method); 2433 memset(mExifInfo.gps_processing_method, 0, sizeof(mExifInfo.gps_processing_method)); 2434 if (gps_processing_method != NULL) { 2435 size_t len = strlen(gps_processing_method); 2436 if (len > sizeof(mExifInfo.gps_processing_method)) { 2437 len = sizeof(mExifInfo.gps_processing_method); 2438 } 2439 memcpy(mExifInfo.gps_processing_method, gps_processing_method, len); 2440 } 2441 return 0; 2442} 2443 2444int SecCamera::setFaceDetectLockUnlock(int facedetect_lockunlock) 2445{ 2446 ALOGV("%s(facedetect_lockunlock(%d))", __func__, facedetect_lockunlock); 2447 2448 if (fimc_v4l2_s_ctrl(m_cam_fd, V4L2_CID_CAMERA_FACEDETECT_LOCKUNLOCK, facedetect_lockunlock) < 0) { 2449 ALOGE("ERR(%s):Fail on V4L2_CID_CAMERA_FACEDETECT_LOCKUNLOCK", __func__); 2450 return -1; 2451 } 2452 2453 return 0; 2454} 2455 2456int SecCamera::setObjectPosition(int x, int y) 2457{ 2458 ALOGV("%s(setObjectPosition(x=%d, y=%d))", __func__, x, y); 2459 2460 if (m_preview_width ==640) 2461 x = x - 80; 2462 2463 if (fimc_v4l2_s_ctrl(m_cam_fd, V4L2_CID_CAMERA_OBJECT_POSITION_X, x) < 0) { 2464 ALOGE("ERR(%s):Fail on V4L2_CID_CAMERA_OBJECT_POSITION_X", __func__); 2465 return -1; 2466 } 2467 2468 if (fimc_v4l2_s_ctrl(m_cam_fd, V4L2_CID_CAMERA_OBJECT_POSITION_Y, y) < 0) { 2469 ALOGE("ERR(%s):Fail on V4L2_CID_CAMERA_OBJECT_POSITION_Y", __func__); 2470 return -1; 2471 } 2472 2473 return 0; 2474} 2475 2476//====================================================================== 2477 2478int SecCamera::setGamma(int gamma) 2479{ 2480 ALOGV("%s(gamma(%d))", __func__, gamma); 2481 2482 if (gamma < GAMMA_OFF || GAMMA_MAX <= gamma) { 2483 ALOGE("ERR(%s):Invalid gamma (%d)", __func__, gamma); 2484 return -1; 2485 } 2486 2487 if (m_video_gamma != gamma) { 2488 m_video_gamma = gamma; 2489 if (m_flag_camera_start) { 2490 if (fimc_v4l2_s_ctrl(m_cam_fd, V4L2_CID_CAMERA_SET_GAMMA, gamma) < 0) { 2491 ALOGE("ERR(%s):Fail on V4L2_CID_CAMERA_SET_GAMMA", __func__); 2492 return -1; 2493 } 2494 } 2495 } 2496 2497 return 0; 2498} 2499 2500//====================================================================== 2501 2502int SecCamera::setSlowAE(int slow_ae) 2503{ 2504 ALOGV("%s(slow_ae(%d))", __func__, slow_ae); 2505 2506 if (slow_ae < GAMMA_OFF || GAMMA_MAX <= slow_ae) { 2507 ALOGE("ERR(%s):Invalid slow_ae (%d)", __func__, slow_ae); 2508 return -1; 2509 } 2510 2511 if (m_slow_ae!= slow_ae) { 2512 m_slow_ae = slow_ae; 2513 if (m_flag_camera_start) { 2514 if (fimc_v4l2_s_ctrl(m_cam_fd, V4L2_CID_CAMERA_SET_SLOW_AE, slow_ae) < 0) { 2515 ALOGE("ERR(%s):Fail on V4L2_CID_CAMERA_SET_SLOW_AE", __func__); 2516 return -1; 2517 } 2518 } 2519 } 2520 2521 return 0; 2522} 2523 2524//====================================================================== 2525int SecCamera::setRecordingSize(int width, int height) 2526{ 2527 ALOGV("%s(width(%d), height(%d))", __func__, width, height); 2528 2529 m_recording_width = width; 2530 m_recording_height = height; 2531 2532 return 0; 2533} 2534 2535//====================================================================== 2536 2537int SecCamera::setExifOrientationInfo(int orientationInfo) 2538{ 2539 ALOGV("%s(orientationInfo(%d))", __func__, orientationInfo); 2540 2541 if (orientationInfo < 0) { 2542 ALOGE("ERR(%s):Invalid orientationInfo (%d)", __func__, orientationInfo); 2543 return -1; 2544 } 2545 m_exif_orientation = orientationInfo; 2546 2547 return 0; 2548} 2549 2550//====================================================================== 2551int SecCamera::setBatchReflection() 2552{ 2553 if (m_flag_camera_start) { 2554 if (fimc_v4l2_s_ctrl(m_cam_fd, V4L2_CID_CAMERA_BATCH_REFLECTION, 1) < 0) { 2555 ALOGE("ERR(%s):Fail on V4L2_CID_CAMERA_BATCH_REFLECTION", __func__); 2556 return -1; 2557 } 2558 } 2559 2560 return 0; 2561} 2562 2563/*Video call*/ 2564int SecCamera::setVTmode(int vtmode) 2565{ 2566 ALOGV("%s(vtmode (%d))", __func__, vtmode); 2567 2568 if (vtmode < VT_MODE_OFF || VT_MODE_MAX <= vtmode) { 2569 ALOGE("ERR(%s):Invalid vtmode (%d)", __func__, vtmode); 2570 return -1; 2571 } 2572 2573 if (m_vtmode != vtmode) { 2574 m_vtmode = vtmode; 2575 } 2576 2577 return 0; 2578} 2579 2580/* Camcorder fix fps */ 2581int SecCamera::setSensorMode(int sensor_mode) 2582{ 2583 ALOGV("%s(sensor_mode (%d))", __func__, sensor_mode); 2584 2585 if (sensor_mode < SENSOR_MODE_CAMERA || SENSOR_MODE_MOVIE < sensor_mode) { 2586 ALOGE("ERR(%s):Invalid sensor mode (%d)", __func__, sensor_mode); 2587 return -1; 2588 } 2589 2590 if (m_sensor_mode != sensor_mode) { 2591 m_sensor_mode = sensor_mode; 2592 } 2593 2594 return 0; 2595} 2596 2597/* Shot mode */ 2598/* SINGLE = 0 2599* CONTINUOUS = 1 2600* PANORAMA = 2 2601* SMILE = 3 2602* SELF = 6 2603*/ 2604int SecCamera::setShotMode(int shot_mode) 2605{ 2606 ALOGV("%s(shot_mode (%d))", __func__, shot_mode); 2607 if (shot_mode < SHOT_MODE_SINGLE || SHOT_MODE_SELF < shot_mode) { 2608 ALOGE("ERR(%s):Invalid shot_mode (%d)", __func__, shot_mode); 2609 return -1; 2610 } 2611 m_shot_mode = shot_mode; 2612 2613 return 0; 2614} 2615 2616int SecCamera::getVTmode(void) 2617{ 2618 return m_vtmode; 2619} 2620 2621int SecCamera::setBlur(int blur_level) 2622{ 2623 ALOGV("%s(level (%d))", __func__, blur_level); 2624 2625 if (blur_level < BLUR_LEVEL_0 || BLUR_LEVEL_MAX <= blur_level) { 2626 ALOGE("ERR(%s):Invalid level (%d)", __func__, blur_level); 2627 return -1; 2628 } 2629 2630 if (m_blur_level != blur_level) { 2631 m_blur_level = blur_level; 2632 if (m_flag_camera_start) { 2633 if (fimc_v4l2_s_ctrl(m_cam_fd, V4L2_CID_CAMERA_VGA_BLUR, blur_level) < 0) { 2634 ALOGE("ERR(%s):Fail on V4L2_CID_CAMERA_VGA_BLUR", __func__); 2635 return -1; 2636 } 2637 } 2638 } 2639 return 0; 2640} 2641 2642int SecCamera::getBlur(void) 2643{ 2644 return m_blur_level; 2645} 2646 2647int SecCamera::setDataLineCheck(int chk_dataline) 2648{ 2649 ALOGV("%s(chk_dataline (%d))", __func__, chk_dataline); 2650 2651 if (chk_dataline < CHK_DATALINE_OFF || CHK_DATALINE_MAX <= chk_dataline) { 2652 ALOGE("ERR(%s):Invalid chk_dataline (%d)", __func__, chk_dataline); 2653 return -1; 2654 } 2655 2656 m_chk_dataline = chk_dataline; 2657 2658 return 0; 2659} 2660 2661int SecCamera::getDataLineCheck(void) 2662{ 2663 return m_chk_dataline; 2664} 2665 2666int SecCamera::setDataLineCheckStop(void) 2667{ 2668 ALOGV("%s", __func__); 2669 2670 if (m_flag_camera_start) { 2671 if (fimc_v4l2_s_ctrl(m_cam_fd, V4L2_CID_CAMERA_CHECK_DATALINE_STOP, 1) < 0) { 2672 ALOGE("ERR(%s):Fail on V4L2_CID_CAMERA_CHECK_DATALINE_STOP", __func__); 2673 return -1; 2674 } 2675 } 2676 return 0; 2677} 2678 2679const __u8* SecCamera::getCameraSensorName(void) 2680{ 2681 ALOGV("%s", __func__); 2682 2683 return fimc_v4l2_enuminput(m_cam_fd, getCameraId()); 2684} 2685 2686#ifdef ENABLE_ESD_PREVIEW_CHECK 2687int SecCamera::getCameraSensorESDStatus(void) 2688{ 2689 ALOGV("%s", __func__); 2690 2691 // 0 : normal operation, 1 : abnormal operation 2692 int status = fimc_v4l2_g_ctrl(m_cam_fd, V4L2_CID_ESD_INT); 2693 2694 return status; 2695} 2696#endif // ENABLE_ESD_PREVIEW_CHECK 2697 2698// ====================================================================== 2699// Jpeg 2700 2701int SecCamera::setJpegThumbnailSize(int width, int height) 2702{ 2703 ALOGV("%s(width(%d), height(%d))", __func__, width, height); 2704 2705 m_jpeg_thumbnail_width = width; 2706 m_jpeg_thumbnail_height = height; 2707 2708 return 0; 2709} 2710 2711int SecCamera::getJpegThumbnailSize(int *width, int *height) 2712{ 2713 if (width) 2714 *width = m_jpeg_thumbnail_width; 2715 if (height) 2716 *height = m_jpeg_thumbnail_height; 2717 2718 return 0; 2719} 2720 2721void SecCamera::setExifFixedAttribute() 2722{ 2723 char property[PROPERTY_VALUE_MAX]; 2724 2725 //2 0th IFD TIFF Tags 2726 //3 Maker 2727 property_get("ro.product.brand", property, EXIF_DEF_MAKER); 2728 strncpy((char *)mExifInfo.maker, property, 2729 sizeof(mExifInfo.maker) - 1); 2730 mExifInfo.maker[sizeof(mExifInfo.maker) - 1] = '\0'; 2731 //3 Model 2732 property_get("ro.product.model", property, EXIF_DEF_MODEL); 2733 strncpy((char *)mExifInfo.model, property, 2734 sizeof(mExifInfo.model) - 1); 2735 mExifInfo.model[sizeof(mExifInfo.model) - 1] = '\0'; 2736 //3 Software 2737 property_get("ro.build.id", property, EXIF_DEF_SOFTWARE); 2738 strncpy((char *)mExifInfo.software, property, 2739 sizeof(mExifInfo.software) - 1); 2740 mExifInfo.software[sizeof(mExifInfo.software) - 1] = '\0'; 2741 2742 //3 YCbCr Positioning 2743 mExifInfo.ycbcr_positioning = EXIF_DEF_YCBCR_POSITIONING; 2744 2745 //2 0th IFD Exif Private Tags 2746 //3 F Number 2747 mExifInfo.fnumber.num = EXIF_DEF_FNUMBER_NUM; 2748 mExifInfo.fnumber.den = EXIF_DEF_FNUMBER_DEN; 2749 //3 Exposure Program 2750 mExifInfo.exposure_program = EXIF_DEF_EXPOSURE_PROGRAM; 2751 //3 Exif Version 2752 memcpy(mExifInfo.exif_version, EXIF_DEF_EXIF_VERSION, sizeof(mExifInfo.exif_version)); 2753 //3 Aperture 2754 uint32_t av = APEX_FNUM_TO_APERTURE((double)mExifInfo.fnumber.num/mExifInfo.fnumber.den); 2755 mExifInfo.aperture.num = av*EXIF_DEF_APEX_DEN; 2756 mExifInfo.aperture.den = EXIF_DEF_APEX_DEN; 2757 //3 Maximum lens aperture 2758 mExifInfo.max_aperture.num = mExifInfo.aperture.num; 2759 mExifInfo.max_aperture.den = mExifInfo.aperture.den; 2760 //3 Lens Focal Length 2761 if (m_camera_id == CAMERA_ID_BACK) 2762 mExifInfo.focal_length.num = BACK_CAMERA_FOCAL_LENGTH; 2763 else 2764 mExifInfo.focal_length.num = FRONT_CAMERA_FOCAL_LENGTH; 2765 2766 mExifInfo.focal_length.den = EXIF_DEF_FOCAL_LEN_DEN; 2767 //3 User Comments 2768 strcpy((char *)mExifInfo.user_comment, EXIF_DEF_USERCOMMENTS); 2769 //3 Color Space information 2770 mExifInfo.color_space = EXIF_DEF_COLOR_SPACE; 2771 //3 Exposure Mode 2772 mExifInfo.exposure_mode = EXIF_DEF_EXPOSURE_MODE; 2773 2774 //2 0th IFD GPS Info Tags 2775 unsigned char gps_version[4] = { 0x02, 0x02, 0x00, 0x00 }; 2776 memcpy(mExifInfo.gps_version_id, gps_version, sizeof(gps_version)); 2777 2778 //2 1th IFD TIFF Tags 2779 mExifInfo.compression_scheme = EXIF_DEF_COMPRESSION; 2780 mExifInfo.x_resolution.num = EXIF_DEF_RESOLUTION_NUM; 2781 mExifInfo.x_resolution.den = EXIF_DEF_RESOLUTION_DEN; 2782 mExifInfo.y_resolution.num = EXIF_DEF_RESOLUTION_NUM; 2783 mExifInfo.y_resolution.den = EXIF_DEF_RESOLUTION_DEN; 2784 mExifInfo.resolution_unit = EXIF_DEF_RESOLUTION_UNIT; 2785} 2786 2787void SecCamera::setExifChangedAttribute() 2788{ 2789 //2 0th IFD TIFF Tags 2790 //3 Width 2791 mExifInfo.width = m_snapshot_width; 2792 //3 Height 2793 mExifInfo.height = m_snapshot_height; 2794 //3 Orientation 2795 switch (m_exif_orientation) { 2796 case 0: 2797 mExifInfo.orientation = EXIF_ORIENTATION_UP; 2798 break; 2799 case 90: 2800 mExifInfo.orientation = EXIF_ORIENTATION_90; 2801 break; 2802 case 180: 2803 mExifInfo.orientation = EXIF_ORIENTATION_180; 2804 break; 2805 case 270: 2806 mExifInfo.orientation = EXIF_ORIENTATION_270; 2807 break; 2808 default: 2809 mExifInfo.orientation = EXIF_ORIENTATION_UP; 2810 break; 2811 } 2812 //3 Date time 2813 time_t rawtime; 2814 struct tm *timeinfo; 2815 time(&rawtime); 2816 timeinfo = localtime(&rawtime); 2817 strftime((char *)mExifInfo.date_time, 20, "%Y:%m:%d %H:%M:%S", timeinfo); 2818 2819 //2 0th IFD Exif Private Tags 2820 //3 Exposure Time 2821 int shutterSpeed = fimc_v4l2_g_ctrl(m_cam_fd, 2822 V4L2_CID_CAMERA_GET_SHT_TIME); 2823 /* TBD - front camera needs to be fixed to support this g_ctrl, 2824 it current returns a negative err value, so avoid putting 2825 odd value into exif for now */ 2826 if (shutterSpeed < 0) { 2827 ALOGE("%s: error %d getting shutterSpeed, camera_id = %d, using 100", 2828 __func__, shutterSpeed, m_camera_id); 2829 shutterSpeed = 100; 2830 } 2831 mExifInfo.exposure_time.num = 1; 2832 // x us -> 1/x s */ 2833 mExifInfo.exposure_time.den = (uint32_t)(1000000 / shutterSpeed); 2834 2835 //3 ISO Speed Rating 2836 int iso = fimc_v4l2_g_ctrl(m_cam_fd, V4L2_CID_CAMERA_GET_ISO); 2837 /* TBD - front camera needs to be fixed to support this g_ctrl, 2838 it current returns a negative err value, so avoid putting 2839 odd value into exif for now */ 2840 if (iso < 0) { 2841 ALOGE("%s: error %d getting iso, camera_id = %d, using 100", 2842 __func__, iso, m_camera_id); 2843 iso = ISO_100; 2844 } 2845 switch(iso) { 2846 case ISO_50: 2847 mExifInfo.iso_speed_rating = 50; 2848 break; 2849 case ISO_100: 2850 mExifInfo.iso_speed_rating = 100; 2851 break; 2852 case ISO_200: 2853 mExifInfo.iso_speed_rating = 200; 2854 break; 2855 case ISO_400: 2856 mExifInfo.iso_speed_rating = 400; 2857 break; 2858 case ISO_800: 2859 mExifInfo.iso_speed_rating = 800; 2860 break; 2861 case ISO_1600: 2862 mExifInfo.iso_speed_rating = 1600; 2863 break; 2864 default: 2865 mExifInfo.iso_speed_rating = 100; 2866 break; 2867 } 2868 2869 uint32_t av, tv, bv, sv, ev; 2870 av = APEX_FNUM_TO_APERTURE((double)mExifInfo.fnumber.num / mExifInfo.fnumber.den); 2871 tv = APEX_EXPOSURE_TO_SHUTTER((double)mExifInfo.exposure_time.num / mExifInfo.exposure_time.den); 2872 sv = APEX_ISO_TO_FILMSENSITIVITY(mExifInfo.iso_speed_rating); 2873 bv = av + tv - sv; 2874 ev = av + tv; 2875 ALOGD("Shutter speed=%d us, iso=%d\n", shutterSpeed, mExifInfo.iso_speed_rating); 2876 ALOGD("AV=%d, TV=%d, SV=%d\n", av, tv, sv); 2877 2878 //3 Shutter Speed 2879 mExifInfo.shutter_speed.num = tv*EXIF_DEF_APEX_DEN; 2880 mExifInfo.shutter_speed.den = EXIF_DEF_APEX_DEN; 2881 //3 Brightness 2882 mExifInfo.brightness.num = bv*EXIF_DEF_APEX_DEN; 2883 mExifInfo.brightness.den = EXIF_DEF_APEX_DEN; 2884 //3 Exposure Bias 2885 if (m_params->scene_mode == SCENE_MODE_BEACH_SNOW) { 2886 mExifInfo.exposure_bias.num = EXIF_DEF_APEX_DEN; 2887 mExifInfo.exposure_bias.den = EXIF_DEF_APEX_DEN; 2888 } else { 2889 mExifInfo.exposure_bias.num = 0; 2890 mExifInfo.exposure_bias.den = 0; 2891 } 2892 //3 Metering Mode 2893 switch (m_params->metering) { 2894 case METERING_SPOT: 2895 mExifInfo.metering_mode = EXIF_METERING_SPOT; 2896 break; 2897 case METERING_MATRIX: 2898 mExifInfo.metering_mode = EXIF_METERING_AVERAGE; 2899 break; 2900 case METERING_CENTER: 2901 mExifInfo.metering_mode = EXIF_METERING_CENTER; 2902 break; 2903 default : 2904 mExifInfo.metering_mode = EXIF_METERING_AVERAGE; 2905 break; 2906 } 2907 2908 //3 Flash 2909 int flash = fimc_v4l2_g_ctrl(m_cam_fd, V4L2_CID_CAMERA_GET_FLASH_ONOFF); 2910 if (flash < 0) 2911 mExifInfo.flash = EXIF_DEF_FLASH; 2912 else 2913 mExifInfo.flash = flash; 2914 2915 //3 White Balance 2916 if (m_params->white_balance == WHITE_BALANCE_AUTO) 2917 mExifInfo.white_balance = EXIF_WB_AUTO; 2918 else 2919 mExifInfo.white_balance = EXIF_WB_MANUAL; 2920 //3 Scene Capture Type 2921 switch (m_params->scene_mode) { 2922 case SCENE_MODE_PORTRAIT: 2923 mExifInfo.scene_capture_type = EXIF_SCENE_PORTRAIT; 2924 break; 2925 case SCENE_MODE_LANDSCAPE: 2926 mExifInfo.scene_capture_type = EXIF_SCENE_LANDSCAPE; 2927 break; 2928 case SCENE_MODE_NIGHTSHOT: 2929 mExifInfo.scene_capture_type = EXIF_SCENE_NIGHT; 2930 break; 2931 default: 2932 mExifInfo.scene_capture_type = EXIF_SCENE_STANDARD; 2933 break; 2934 } 2935 2936 //2 0th IFD GPS Info Tags 2937 if (m_gps_enabled) { 2938 if (m_gps_latitude >= 0) 2939 strcpy((char *)mExifInfo.gps_latitude_ref, "N"); 2940 else 2941 strcpy((char *)mExifInfo.gps_latitude_ref, "S"); 2942 2943 if (m_gps_longitude >= 0) 2944 strcpy((char *)mExifInfo.gps_longitude_ref, "E"); 2945 else 2946 strcpy((char *)mExifInfo.gps_longitude_ref, "W"); 2947 2948 if (m_gps_altitude >= 0) 2949 mExifInfo.gps_altitude_ref = 0; 2950 else 2951 mExifInfo.gps_altitude_ref = 1; 2952 2953 mExifInfo.gps_latitude[0].num = (uint32_t)labs(m_gps_latitude); 2954 mExifInfo.gps_latitude[0].den = 10000000; 2955 mExifInfo.gps_latitude[1].num = 0; 2956 mExifInfo.gps_latitude[1].den = 1; 2957 mExifInfo.gps_latitude[2].num = 0; 2958 mExifInfo.gps_latitude[2].den = 1; 2959 2960 mExifInfo.gps_longitude[0].num = (uint32_t)labs(m_gps_longitude); 2961 mExifInfo.gps_longitude[0].den = 10000000; 2962 mExifInfo.gps_longitude[1].num = 0; 2963 mExifInfo.gps_longitude[1].den = 1; 2964 mExifInfo.gps_longitude[2].num = 0; 2965 mExifInfo.gps_longitude[2].den = 1; 2966 2967 mExifInfo.gps_altitude.num = (uint32_t)labs(m_gps_altitude); 2968 mExifInfo.gps_altitude.den = 100; 2969 2970 struct tm tm_data; 2971 gmtime_r(&m_gps_timestamp, &tm_data); 2972 mExifInfo.gps_timestamp[0].num = tm_data.tm_hour; 2973 mExifInfo.gps_timestamp[0].den = 1; 2974 mExifInfo.gps_timestamp[1].num = tm_data.tm_min; 2975 mExifInfo.gps_timestamp[1].den = 1; 2976 mExifInfo.gps_timestamp[2].num = tm_data.tm_sec; 2977 mExifInfo.gps_timestamp[2].den = 1; 2978 snprintf((char*)mExifInfo.gps_datestamp, sizeof(mExifInfo.gps_datestamp), 2979 "%04d:%02d:%02d", tm_data.tm_year + 1900, tm_data.tm_mon + 1, tm_data.tm_mday); 2980 2981 mExifInfo.enableGps = true; 2982 } else { 2983 mExifInfo.enableGps = false; 2984 } 2985 2986 //2 1th IFD TIFF Tags 2987 mExifInfo.widthThumb = m_jpeg_thumbnail_width; 2988 mExifInfo.heightThumb = m_jpeg_thumbnail_height; 2989} 2990 2991// ====================================================================== 2992// Conversions 2993 2994inline int SecCamera::m_frameSize(int format, int width, int height) 2995{ 2996 int size = 0; 2997 2998 switch (format) { 2999 case V4L2_PIX_FMT_YUV420: 3000 case V4L2_PIX_FMT_NV12: 3001 case V4L2_PIX_FMT_NV21: 3002 size = (width * height * 3 / 2); 3003 break; 3004 3005 case V4L2_PIX_FMT_NV12T: 3006 size = ALIGN_TO_8KB(ALIGN_TO_128B(width) * ALIGN_TO_32B(height)) + 3007 ALIGN_TO_8KB(ALIGN_TO_128B(width) * ALIGN_TO_32B(height / 2)); 3008 break; 3009 3010 case V4L2_PIX_FMT_YUV422P: 3011 case V4L2_PIX_FMT_YUYV: 3012 case V4L2_PIX_FMT_UYVY: 3013 size = (width * height * 2); 3014 break; 3015 3016 default : 3017 ALOGE("ERR(%s):Invalid V4L2 pixel format(%d)\n", __func__, format); 3018 case V4L2_PIX_FMT_RGB565: 3019 size = (width * height * BPP); 3020 break; 3021 } 3022 3023 return size; 3024} 3025 3026status_t SecCamera::dump(int fd) 3027{ 3028 const size_t SIZE = 256; 3029 char buffer[SIZE]; 3030 String8 result; 3031 snprintf(buffer, 255, "dump(%d)\n", fd); 3032 result.append(buffer); 3033 ::write(fd, result.string(), result.size()); 3034 return NO_ERROR; 3035} 3036 3037double SecCamera::jpeg_ratio = 0.7; 3038int SecCamera::interleaveDataSize = 5242880; 3039int SecCamera::jpegLineLength = 636; 3040 3041}; // namespace android 3042