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