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