blob: 9c7bf9438403ca792f8dc20f8332a8a1e38b1c5e [file] [log] [blame]
codeworkx62f02ba2012-05-20 12:00:36 +02001/*
2 * Copyright 2008, The Android Open Source Project
3 * Copyright 2010, Samsung Electronics Co. LTD
4 *
5 * Licensed under the Apache License, Version 2.0 (the "License");
6 * you may not use this file except in compliance with the License.
7 * You may obtain a copy of the License at
8 *
9 * http://www.apache.org/licenses/LICENSE-2.0
10 *
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
16 */
17
18/*
19************************************
20* Filename: SecCamera.cpp
21* Author: Sachin P. Kamat
22* Purpose: This file interacts with the Camera and JPEG drivers.
23*************************************
24*/
25
26//#define LOG_NDEBUG 0
27#define LOG_TAG "SecCamera"
28
29#include <utils/Log.h>
30#include <string.h>
31#include <stdlib.h>
32#include <sys/poll.h>
33#include "SecCamera.h"
34#include "cutils/properties.h"
35
36using namespace android;
37
38#define CHECK(return_value) \
39 if (return_value < 0) { \
40 LOGE("%s::%d fail. errno: %s, m_camera_id = %d", \
41 __func__, __LINE__, strerror(errno), m_camera_id); \
42 return -1; \
43 }
44
45#define CHECK_PTR(return_value) \
46 if (return_value < 0) { \
47 LOGE("%s::%d fail, errno: %s, m_camera_id = %d", \
48 __func__,__LINE__, strerror(errno), m_camera_id); \
49 return NULL; \
50 }
51
52namespace android {
53
54static struct timeval time_start;
55static struct timeval time_stop;
56
57#if defined(LOG_NDEBUG) && LOG_NDEBUG == 0
58unsigned long measure_time_camera(struct timeval *start, struct timeval *stop)
59{
60 unsigned long sec, usec, time;
61
62 sec = stop->tv_sec - start->tv_sec;
63
64 if (stop->tv_usec >= start->tv_usec) {
65 usec = stop->tv_usec - start->tv_usec;
66 } else {
67 usec = stop->tv_usec + 1000000 - start->tv_usec;
68 sec--;
69 }
70
71 time = (sec * 1000000) + usec;
72
73 return time;
74}
75#endif
76
77static int close_buffers(struct SecBuffer *buffers, int num_of_buf)
78{
79 int ret;
80
81 for (int i = 0; i < num_of_buf; i++) {
82 for(int j = 0; j < MAX_PLANES; j++) {
83 if (buffers[i].virt.extP[j]) {
84#ifndef BOARD_USE_V4L2_ION
85 ret = munmap(buffers[i].virt.extP[j], buffers[i].size.extS[j]);
86 LOGV("munmap():buffers[%d].virt.extP[%d]: 0x%x size = %d",
87 i, j, (unsigned int) buffers[i].virt.extP[j],
88 buffers[i].size.extS[j]);
89#endif
90 buffers[i].virt.extP[j] = NULL;
91 }
92 }
93 }
94
95 return 0;
96}
97
98static int get_pixel_depth(unsigned int fmt)
99{
100 int depth = 0;
101
102 switch (fmt) {
103 case V4L2_PIX_FMT_NV12:
104 case V4L2_PIX_FMT_NV12T:
105 case V4L2_PIX_FMT_NV21:
106 case V4L2_PIX_FMT_YUV420:
107 case V4L2_PIX_FMT_YVU420:
108 case V4L2_PIX_FMT_YVU420M:
109 depth = 12;
110 break;
111
112 case V4L2_PIX_FMT_RGB565:
113 case V4L2_PIX_FMT_YUYV:
114 case V4L2_PIX_FMT_YVYU:
115 case V4L2_PIX_FMT_UYVY:
116 case V4L2_PIX_FMT_VYUY:
117 case V4L2_PIX_FMT_NV16:
118 case V4L2_PIX_FMT_NV61:
119 case V4L2_PIX_FMT_YUV422P:
120 depth = 16;
121 break;
122
123 case V4L2_PIX_FMT_RGB32:
124 depth = 32;
125 break;
126 }
127
128 return depth;
129}
130
131static int fimc_poll(struct pollfd *events)
132{
133 int ret;
134
135 /* 10 second delay is because sensor can take a long time
136 * to do auto focus and capture in dark settings
137 */
138 ret = poll(events, 1, 10000);
139 if (ret < 0) {
140 LOGE("ERR(%s):poll error", __func__);
141 return ret;
142 }
143
144 if (ret == 0) {
145 LOGE("ERR(%s):No data in 10 secs..", __func__);
146 return ret;
147 }
148
149 return ret;
150}
151
152static int fimc_v4l2_querycap(int fp)
153{
154 struct v4l2_capability cap;
155
156 if (ioctl(fp, VIDIOC_QUERYCAP, &cap) < 0) {
157 LOGE("ERR(%s):VIDIOC_QUERYCAP failed", __func__);
158 return -1;
159 }
160
161 if (!(cap.capabilities & V4L2_CAP_VIDEO_CAPTURE)) {
162 LOGE("ERR(%s):no capture devices", __func__);
163 return -1;
164 }
165
166 return 0;
167}
168
169static const __u8* fimc_v4l2_enuminput(int fp, int index)
170{
171 static struct v4l2_input input;
172
173 input.index = index;
174 if (ioctl(fp, VIDIOC_ENUMINPUT, &input) != 0) {
175 LOGE("ERR(%s):No matching index found", __func__);
176 return NULL;
177 }
178 LOGI("Name of input channel[%d] is %s", input.index, input.name);
179
180 return input.name;
181}
182
183static int fimc_v4l2_s_input(int fp, int index)
184{
185 struct v4l2_input input;
186
187 input.index = index;
188
189 if (ioctl(fp, VIDIOC_S_INPUT, &input) < 0) {
190 LOGE("ERR(%s):VIDIOC_S_INPUT failed", __func__);
191 return -1;
192 }
193
194 return 0;
195}
196
197static int fimc_v4l2_s_fmt(int fp, int width, int height, unsigned int fmt, enum v4l2_field field, unsigned int num_plane)
198{
199 struct v4l2_format v4l2_fmt;
200 struct v4l2_pix_format pixfmt;
201 unsigned int framesize;
202
203 memset(&v4l2_fmt, 0, sizeof(struct v4l2_format));
204 v4l2_fmt.type = V4L2_BUF_TYPE;
205
206#ifdef BOARD_USE_V4L2
207 framesize = (width * height * get_pixel_depth(fmt)) / 8;
208
209 v4l2_fmt.fmt.pix_mp.width = width;
210 v4l2_fmt.fmt.pix_mp.height = height;
211 v4l2_fmt.fmt.pix_mp.pixelformat = fmt;
212 v4l2_fmt.fmt.pix_mp.field = field;
213 if (num_plane == 1) {
214 v4l2_fmt.fmt.pix_mp.plane_fmt[0].sizeimage = framesize;
215 } else if (num_plane == 2) {
216 v4l2_fmt.fmt.pix_mp.plane_fmt[0].sizeimage = ALIGN(width * height, 2048);
217 v4l2_fmt.fmt.pix_mp.plane_fmt[1].sizeimage = ALIGN(width/2, 16) * ALIGN(height/2, 16) * 2;
218 } else if (num_plane == 3) {
219 v4l2_fmt.fmt.pix_mp.plane_fmt[0].sizeimage = ALIGN(width, 16) * ALIGN(height, 16);
220 v4l2_fmt.fmt.pix_mp.plane_fmt[1].sizeimage = ALIGN(width/2, 16) * ALIGN(height/2, 16);
221 v4l2_fmt.fmt.pix_mp.plane_fmt[2].sizeimage = ALIGN(width/2, 16) * ALIGN(height/2, 16);
222 } else {
223 LOGE("ERR(%s): Invalid plane number", __func__);
224 return -1;
225 }
226 v4l2_fmt.fmt.pix_mp.num_planes = num_plane;
227#else
228 memset(&pixfmt, 0, sizeof(pixfmt));
229
230 pixfmt.width = width;
231 pixfmt.height = height;
232 pixfmt.pixelformat = fmt;
233 pixfmt.field = V4L2_FIELD_NONE;
234
235 v4l2_fmt.fmt.pix = pixfmt;
236 LOGV("fimc_v4l2_s_fmt : width(%d) height(%d)", width, height);
237#endif
238
239 /* Set up for capture */
240 if (ioctl(fp, VIDIOC_S_FMT, &v4l2_fmt) < 0) {
241 LOGE("ERR(%s):VIDIOC_S_FMT failed", __func__);
242 return -1;
243 }
244
245 return 0;
246}
247
248static int fimc_v4l2_s_fmt_cap(int fp, int width, int height, unsigned int fmt)
249{
250 struct v4l2_format v4l2_fmt;
251 struct v4l2_pix_format pixfmt;
252
253 memset(&pixfmt, 0, sizeof(pixfmt));
254
255 v4l2_fmt.type = V4L2_BUF_TYPE;
256
257 pixfmt.width = width;
258 pixfmt.height = height;
259 pixfmt.pixelformat = fmt;
260 if (fmt == V4L2_PIX_FMT_JPEG)
261 pixfmt.colorspace = V4L2_COLORSPACE_JPEG;
262
263 v4l2_fmt.fmt.pix = pixfmt;
264 LOGV("fimc_v4l2_s_fmt_cap : width(%d) height(%d)", width, height);
265
266 /* Set up for capture */
267 if (ioctl(fp, VIDIOC_S_FMT, &v4l2_fmt) < 0) {
268 LOGE("ERR(%s):VIDIOC_S_FMT failed", __func__);
269 return -1;
270 }
271
272 return 0;
273}
274
275int fimc_v4l2_s_fmt_is(int fp, int width, int height, unsigned int fmt, enum v4l2_field field)
276{
277 struct v4l2_format v4l2_fmt;
278 struct v4l2_pix_format pixfmt;
279
280 memset(&pixfmt, 0, sizeof(pixfmt));
281
282 v4l2_fmt.type = V4L2_BUF_TYPE_PRIVATE;
283
284 pixfmt.width = width;
285 pixfmt.height = height;
286 pixfmt.pixelformat = fmt;
287 pixfmt.field = field;
288
289 v4l2_fmt.fmt.pix = pixfmt;
290 LOGV("fimc_v4l2_s_fmt_is : width(%d) height(%d)", width, height);
291
292 /* Set up for capture */
293 if (ioctl(fp, VIDIOC_S_FMT, &v4l2_fmt) < 0) {
294 LOGE("ERR(%s):VIDIOC_S_FMT failed", __func__);
295 return -1;
296 }
297
298 return 0;
299}
300
301static int fimc_v4l2_enum_fmt(int fp, unsigned int fmt)
302{
303 struct v4l2_fmtdesc fmtdesc;
304 int found = 0;
305
306 fmtdesc.type = V4L2_BUF_TYPE;
307 fmtdesc.index = 0;
308
309 while (ioctl(fp, VIDIOC_ENUM_FMT, &fmtdesc) == 0) {
310 if (fmtdesc.pixelformat == fmt) {
311 LOGV("passed fmt = %#x found pixel format[%d]: %s", fmt, fmtdesc.index, fmtdesc.description);
312 found = 1;
313 break;
314 }
315
316 fmtdesc.index++;
317 }
318
319 if (!found) {
320 LOGE("unsupported pixel format");
321 return -1;
322 }
323
324 return 0;
325}
326
327static int fimc_v4l2_reqbufs(int fp, enum v4l2_buf_type type, int nr_bufs)
328{
329 struct v4l2_requestbuffers req;
330
331 req.count = nr_bufs;
332 req.type = type;
333 req.memory = V4L2_MEMORY_TYPE;
334
335 if (ioctl(fp, VIDIOC_REQBUFS, &req) < 0) {
336 LOGE("ERR(%s):VIDIOC_REQBUFS failed", __func__);
337 return -1;
338 }
339
340 return req.count;
341}
342
343static int fimc_v4l2_querybuf(int fp, struct SecBuffer *buffers, enum v4l2_buf_type type, int nr_frames, int num_plane)
344{
345 struct v4l2_buffer v4l2_buf;
346#ifdef BOARD_USE_V4L2
347 struct v4l2_plane planes[VIDEO_MAX_PLANES];
348#endif
349 int i, ret, plane_index;
350
351 for (i = 0; i < nr_frames; i++) {
352 v4l2_buf.type = type;
353 v4l2_buf.memory = V4L2_MEMORY_TYPE;
354 v4l2_buf.index = i;
355#ifdef BOARD_USE_V4L2
356 v4l2_buf.m.planes = planes;
357 v4l2_buf.length = num_plane; // this is for multi-planar
358 LOGV("QUERYBUF(index=%d)", i);
359 LOGV("memory plane is %d", v4l2_buf.length);
360#endif
361
362 ret = ioctl(fp, VIDIOC_QUERYBUF, &v4l2_buf);
363 if (ret < 0) {
364 LOGE("ERR(%s):VIDIOC_QUERYBUF failed", __func__);
365 return -1;
366 }
367
368#ifdef BOARD_USE_V4L2
369 for (plane_index = 0; plane_index < num_plane; plane_index++) {
370 LOGV("Offset : 0x%x", v4l2_buf.m.planes[plane_index].m.mem_offset);
371 LOGV("Plane Length : 0x%x", v4l2_buf.m.planes[plane_index].length);
372
373 buffers[i].phys.extP[plane_index] = (unsigned int)v4l2_buf.m.planes[plane_index].cookie;
374
375 buffers[i].size.extS[plane_index] = v4l2_buf.m.planes[plane_index].length;
376 LOGV("length[%d] : 0x%x", i, buffers[i].size.extS[plane_index]);
377 if ((buffers[i].virt.extP[plane_index] = (char *)mmap(0, v4l2_buf.m.planes[plane_index].length,
378 PROT_READ | PROT_WRITE, MAP_SHARED, fp, v4l2_buf.m.planes[plane_index].m.mem_offset)) < 0) {
379 LOGE("mmap failed");
380 return -1;
381 }
382 LOGV("vaddr[%d][%d] : 0x%x", i, plane_index, (__u32) buffers[i].virt.extP[plane_index]);
383 }
384#else
385 buffers[i].size.s = v4l2_buf.length;
386
387 if ((buffers[i].virt.p = (char *)mmap(0, v4l2_buf.length, PROT_READ | PROT_WRITE, MAP_SHARED,
388 fp, v4l2_buf.m.offset)) < 0) {
389 LOGE("%s %d] mmap() failed",__func__, __LINE__);
390 return -1;
391 }
392 LOGV("buffers[%d].virt.p = %p v4l2_buf.length = %d", i, buffers[i].virt.p, v4l2_buf.length);
393#endif
394 }
395 return 0;
396}
397
398static int fimc_v4l2_streamon(int fp)
399{
400 enum v4l2_buf_type type = V4L2_BUF_TYPE;
401 int ret;
402
403 ret = ioctl(fp, VIDIOC_STREAMON, &type);
404 if (ret < 0) {
405 LOGE("ERR(%s):VIDIOC_STREAMON failed", __func__);
406 return ret;
407 }
408
409 return ret;
410}
411
412static int fimc_v4l2_streamoff(int fp)
413{
414 enum v4l2_buf_type type = V4L2_BUF_TYPE;
415 int ret;
416
417 LOGV("%s :", __func__);
418 ret = ioctl(fp, VIDIOC_STREAMOFF, &type);
419 if (ret < 0) {
420 LOGE("ERR(%s):VIDIOC_STREAMOFF failed", __func__);
421 return ret;
422 }
423
424 return ret;
425}
426
427static int fimc_v4l2_qbuf(int fp, int width, int height, struct SecBuffer *vaddr, int index, int num_plane, int mode)
428{
429 struct v4l2_buffer v4l2_buf;
430 int ret;
431
432#ifdef BOARD_USE_V4L2
433 struct v4l2_plane planes[VIDEO_MAX_PLANES];
434
435 v4l2_buf.m.planes = planes;
436 v4l2_buf.length = num_plane;
437#endif
438
439 v4l2_buf.type = V4L2_BUF_TYPE;
440 v4l2_buf.memory = V4L2_MEMORY_TYPE;
441 v4l2_buf.index = index;
442
443#ifdef BOARD_USE_V4L2_ION
444 if (mode == PREVIEW_MODE) {
445 if (num_plane == 1) {
446 v4l2_buf.m.planes[0].m.userptr = (long unsigned int)vaddr[index].virt.extP[0];
447 v4l2_buf.m.planes[0].length = width * height * 2;
448 } else if (num_plane == 2) {
449 v4l2_buf.m.planes[0].m.userptr = (long unsigned int)vaddr[index].virt.extP[0];
450 v4l2_buf.m.planes[0].length = ALIGN(width, 16) * ALIGN(height, 16);
451 v4l2_buf.m.planes[1].m.userptr = (long unsigned int)vaddr[index].virt.extP[1];
452 v4l2_buf.m.planes[1].length = ALIGN(width/2, 16) * ALIGN(height/2, 16);
453 } else if (num_plane == 3) {
454 v4l2_buf.m.planes[0].m.userptr = (long unsigned int)vaddr[index].virt.extP[0];
455 v4l2_buf.m.planes[0].length = ALIGN(width, 16) * ALIGN(height, 16);
456 v4l2_buf.m.planes[1].m.userptr = (long unsigned int)vaddr[index].virt.extP[1];
457 v4l2_buf.m.planes[1].length = ALIGN(width/2, 16) * ALIGN(height/2, 16);
458 v4l2_buf.m.planes[2].m.userptr = (long unsigned int)vaddr[index].virt.extP[2];
459 v4l2_buf.m.planes[2].length = ALIGN(width/2, 16) * ALIGN(height/2, 16);
460 } else {
461 LOGE("ERR(%s): Invalid plane number", __func__);
462 return -1;
463 }
464 } else if (mode == CAPTURE_MODE) {
465 v4l2_buf.m.planes[0].m.userptr = (long unsigned int)vaddr[index].virt.extP[0];
466 v4l2_buf.m.planes[0].length = width * height * 2;
467 } else if (mode == RECORD_MODE) {
468 v4l2_buf.m.planes[0].m.userptr = (long unsigned int)vaddr[index].virt.extP[0];
469 v4l2_buf.m.planes[0].length = ALIGN(ALIGN(width, 16) * ALIGN(height, 16), 2048);
470 v4l2_buf.m.planes[1].m.userptr = (long unsigned int)vaddr[index].virt.extP[1];
471 v4l2_buf.m.planes[1].length = ALIGN(ALIGN(width, 16) * ALIGN(height >> 1, 8), 2048);
472 } else {
473 LOGE("ERR(%s): Invalid mode", __func__);
474 return -1;
475 }
476#endif
477
478 ret = ioctl(fp, VIDIOC_QBUF, &v4l2_buf);
479 if (ret < 0) {
480 LOGE("ERR(%s):VIDIOC_QBUF failed", __func__);
481 return ret;
482 }
483
484 return 0;
485}
486
487static int fimc_v4l2_dqbuf(int fp, int num_plane)
488{
489 struct v4l2_buffer v4l2_buf;
490 int ret;
491
492#ifdef BOARD_USE_V4L2
493 struct v4l2_plane planes[VIDEO_MAX_PLANES];
494
495 v4l2_buf.m.planes = planes;
496 v4l2_buf.length = num_plane;
497#endif
498
499 v4l2_buf.type = V4L2_BUF_TYPE;
500 v4l2_buf.memory = V4L2_MEMORY_TYPE;
501
502 ret = ioctl(fp, VIDIOC_DQBUF, &v4l2_buf);
503 if (ret < 0) {
504 LOGE("ERR(%s):VIDIOC_DQBUF failed, dropped frame", __func__);
505 return ret;
506 }
507
508 return v4l2_buf.index;
509}
510
511static int fimc_v4l2_g_ctrl(int fp, unsigned int id)
512{
513 struct v4l2_control ctrl;
514 int ret;
515
516 ctrl.id = id;
517
518 ret = ioctl(fp, VIDIOC_G_CTRL, &ctrl);
519 if (ret < 0) {
520 LOGE("ERR(%s): VIDIOC_G_CTRL(id = 0x%x (%d)) failed, ret = %d",
521 __func__, id, id-V4L2_CID_PRIVATE_BASE, ret);
522 return ret;
523 }
524
525 return ctrl.value;
526}
527
528static int fimc_v4l2_s_ctrl(int fp, unsigned int id, unsigned int value)
529{
530 struct v4l2_control ctrl;
531 int ret;
532
533 ctrl.id = id;
534 ctrl.value = value;
535
536 ret = ioctl(fp, VIDIOC_S_CTRL, &ctrl);
537 if (ret < 0) {
538 LOGE("ERR(%s):VIDIOC_S_CTRL(id = %#x (%d), value = %d) failed ret = %d",
539 __func__, id, id-V4L2_CID_PRIVATE_BASE, value, ret);
540
541 return ret;
542 }
543
544 return ctrl.value;
545}
546
547static int fimc_v4l2_s_ext_ctrl(int fp, unsigned int id, void *value)
548{
549 struct v4l2_ext_controls ctrls;
550 struct v4l2_ext_control ctrl;
551 int ret;
552
553 ctrl.id = id;
554
555 ctrls.ctrl_class = V4L2_CTRL_CLASS_CAMERA;
556 ctrls.count = 1;
557 ctrls.controls = &ctrl;
558
559 ret = ioctl(fp, VIDIOC_S_EXT_CTRLS, &ctrls);
560 if (ret < 0)
561 LOGE("ERR(%s):VIDIOC_S_EXT_CTRLS failed", __func__);
562
563 return ret;
564}
565
566static int fimc_v4l2_s_ext_ctrl_face_detection(int fp, unsigned int id, void *value)
567{
568 struct v4l2_ext_control ext_ctrl_fd[111];
569 struct v4l2_ext_controls ext_ctrls_fd;
570 struct v4l2_ext_controls *ctrls;
571 camera_frame_metadata_t *facedata = (camera_frame_metadata_t *)value;
572 int i, ret;
573
574 ext_ctrl_fd[0].id = V4L2_CID_IS_FD_GET_FACE_COUNT;
575 for (i = 0; i < 5; i++) {
576 ext_ctrl_fd[22*i+1].id = V4L2_CID_IS_FD_GET_FACE_FRAME_NUMBER;
577 ext_ctrl_fd[22*i+2].id = V4L2_CID_IS_FD_GET_FACE_CONFIDENCE;
578 ext_ctrl_fd[22*i+3].id = V4L2_CID_IS_FD_GET_FACE_SMILE_LEVEL;
579 ext_ctrl_fd[22*i+4].id = V4L2_CID_IS_FD_GET_FACE_BLINK_LEVEL;
580 ext_ctrl_fd[22*i+5].id = V4L2_CID_IS_FD_GET_FACE_TOPLEFT_X;
581 ext_ctrl_fd[22*i+6].id = V4L2_CID_IS_FD_GET_FACE_TOPLEFT_Y;
582 ext_ctrl_fd[22*i+7].id = V4L2_CID_IS_FD_GET_FACE_BOTTOMRIGHT_X;
583 ext_ctrl_fd[22*i+8].id = V4L2_CID_IS_FD_GET_FACE_BOTTOMRIGHT_Y;
584 ext_ctrl_fd[22*i+9].id = V4L2_CID_IS_FD_GET_LEFT_EYE_TOPLEFT_X;
585 ext_ctrl_fd[22*i+10].id = V4L2_CID_IS_FD_GET_LEFT_EYE_TOPLEFT_Y;
586 ext_ctrl_fd[22*i+11].id = V4L2_CID_IS_FD_GET_LEFT_EYE_BOTTOMRIGHT_X;
587 ext_ctrl_fd[22*i+12].id = V4L2_CID_IS_FD_GET_LEFT_EYE_BOTTOMRIGHT_Y;
588 ext_ctrl_fd[22*i+13].id = V4L2_CID_IS_FD_GET_RIGHT_EYE_TOPLEFT_X;
589 ext_ctrl_fd[22*i+14].id = V4L2_CID_IS_FD_GET_RIGHT_EYE_TOPLEFT_Y;
590 ext_ctrl_fd[22*i+15].id = V4L2_CID_IS_FD_GET_RIGHT_EYE_BOTTOMRIGHT_X;
591 ext_ctrl_fd[22*i+16].id = V4L2_CID_IS_FD_GET_RIGHT_EYE_BOTTOMRIGHT_Y;
592 ext_ctrl_fd[22*i+17].id = V4L2_CID_IS_FD_GET_MOUTH_TOPLEFT_X;
593 ext_ctrl_fd[22*i+18].id = V4L2_CID_IS_FD_GET_MOUTH_TOPLEFT_Y;
594 ext_ctrl_fd[22*i+19].id = V4L2_CID_IS_FD_GET_MOUTH_BOTTOMRIGHT_X;
595 ext_ctrl_fd[22*i+20].id = V4L2_CID_IS_FD_GET_MOUTH_BOTTOMRIGHT_Y;
596 ext_ctrl_fd[22*i+21].id = V4L2_CID_IS_FD_GET_ANGLE;
597 ext_ctrl_fd[22*i+22].id = V4L2_CID_IS_FD_GET_NEXT;
598 }
599
600 ext_ctrls_fd.ctrl_class = V4L2_CTRL_CLASS_CAMERA;
601 ext_ctrls_fd.count = 111;
602 ext_ctrls_fd.controls = ext_ctrl_fd;
603 ctrls = &ext_ctrls_fd;
604
605 ret = ioctl(fp, VIDIOC_G_EXT_CTRLS, &ext_ctrls_fd);
606
607 facedata->number_of_faces = ext_ctrls_fd.controls[0].value;
608
609 for(i = 0; i < facedata->number_of_faces; i++) {
610 facedata->faces[i].rect[0] = ext_ctrl_fd[22*i+5].value;
611 facedata->faces[i].rect[1] = ext_ctrl_fd[22*i+6].value;
612 facedata->faces[i].rect[2] = ext_ctrl_fd[22*i+7].value;
613 facedata->faces[i].rect[3] = ext_ctrl_fd[22*i+8].value;
614 facedata->faces[i].score = ext_ctrl_fd[22*i+2].value;
615/* TODO : id is unique value for each face. We need to suppot this. */
616 facedata->faces[i].id = 0;
617 facedata->faces[i].left_eye[0] = (ext_ctrl_fd[22*i+9].value + ext_ctrl_fd[22*i+11].value) / 2;
618 facedata->faces[i].left_eye[1] = (ext_ctrl_fd[22*i+10].value + ext_ctrl_fd[22*i+12].value) / 2;
619 facedata->faces[i].right_eye[0] = (ext_ctrl_fd[22*i+13].value + ext_ctrl_fd[22*i+15].value) / 2;
620 facedata->faces[i].right_eye[1] = (ext_ctrl_fd[22*i+14].value + ext_ctrl_fd[22*i+16].value) / 2;
621 facedata->faces[i].mouth[0] = (ext_ctrl_fd[22*i+17].value + ext_ctrl_fd[22*i+19].value) / 2;
622 facedata->faces[i].mouth[1] = (ext_ctrl_fd[22*i+18].value + ext_ctrl_fd[22*i+20].value) / 2;
623 }
624
625 return ret;
626}
627
628static int fimc_v4l2_g_parm(int fp, struct v4l2_streamparm *streamparm)
629{
630 int ret;
631
632 streamparm->type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
633
634 ret = ioctl(fp, VIDIOC_G_PARM, streamparm);
635 if (ret < 0) {
636 LOGE("ERR(%s):VIDIOC_G_PARM failed", __func__);
637 return -1;
638 }
639
640 LOGV("%s : timeperframe: numerator %d, denominator %d", __func__,
641 streamparm->parm.capture.timeperframe.numerator,
642 streamparm->parm.capture.timeperframe.denominator);
643
644 return 0;
645}
646
647static int fimc_v4l2_s_parm(int fp, struct v4l2_streamparm *streamparm)
648{
649 int ret;
650
651 streamparm->type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
652
653 ret = ioctl(fp, VIDIOC_S_PARM, streamparm);
654 if (ret < 0) {
655 LOGE("ERR(%s):VIDIOC_S_PARM failed", __func__);
656 return ret;
657 }
658
659 return 0;
660}
661
662SecCamera::SecCamera() :
663 m_flagCreate(0),
664 m_preview_state(0),
665 m_snapshot_state(0),
666 m_camera_id(CAMERA_ID_BACK),
667 m_camera_use_ISP(0),
668 m_cam_fd(-1),
669 m_cam_fd2(-1),
670 m_cam_fd3(-1),
671 m_cap_fd(-1),
672 m_rec_fd(-1),
673 m_jpeg_fd(-1),
674 m_flag_record_start(0),
675 m_preview_v4lformat(V4L2_PIX_FMT_YVU420),
676 m_preview_width (0),
677 m_preview_height (0),
678 m_preview_max_width (MAX_BACK_CAMERA_PREVIEW_WIDTH),
679 m_preview_max_height (MAX_BACK_CAMERA_PREVIEW_HEIGHT),
680 m_snapshot_v4lformat(V4L2_PIX_FMT_YUYV),
681 m_snapshot_width (0),
682 m_snapshot_height (0),
683 m_num_capbuf (0),
684 m_videosnapshot_width (0),
685 m_videosnapshot_height(0),
686 m_snapshot_max_width (MAX_BACK_CAMERA_SNAPSHOT_WIDTH),
687 m_snapshot_max_height (MAX_BACK_CAMERA_SNAPSHOT_HEIGHT),
688 m_recording_en (0),
689 m_record_hint (0),
690 m_recording_width (0),
691 m_recording_height (0),
692 m_angle(-1),
693 m_anti_banding(0),
694 m_wdr(0),
695 m_anti_shake(0),
696 m_zoom_level(-1),
697 m_object_tracking(-1),
698 m_smart_auto(-1),
699 m_beauty_shot(-1),
700 m_vintage_mode(-1),
701 m_face_detect(0),
702 m_object_tracking_start_stop(-1),
703 m_gps_latitude(-1),
704 m_gps_longitude(-1),
705 m_gps_altitude(-1),
706 m_gps_timestamp(-1),
707 m_sensor_mode(-1),
708 m_shot_mode(-1),
709 m_exif_orientation(-1),
710 m_chk_dataline(-1),
711 m_video_gamma(0),
712 m_slow_ae(0),
713 m_camera_af_flag(-1),
714 m_flag_camera_create(0),
715 m_flag_camera_start(0),
716 m_jpeg_thumbnail_width (0),
717 m_jpeg_thumbnail_height(0),
718 m_jpeg_thumbnail_quality(100),
719 m_jpeg_quality(100),
720 m_touch_af_start_stop(-1),
721 m_postview_offset(0),
722 m_auto_focus_state(0)
723#ifdef ENABLE_ESD_PREVIEW_CHECK
724 ,
725 m_esd_check_count(0)
726#endif // ENABLE_ESD_PREVIEW_CHECK
727{
728 initParameters(0);
729 memset(&mExifInfo, 0, sizeof(mExifInfo));
730
731 memset(&m_events_c, 0, sizeof(m_events_c));
732 memset(&m_events_c2, 0, sizeof(m_events_c2));
733 memset(&m_events_c3, 0, sizeof(m_events_c3));
734}
735
736SecCamera::~SecCamera()
737{
738 LOGV("%s :", __func__);
739 DestroyCamera();
740}
741
742bool SecCamera::CreateCamera(int index)
743{
744 LOGV("%s :", __func__);
745 int ret = 0;
746
747 switch (index) {
748 case CAMERA_ID_FRONT:
749 m_preview_max_width = MAX_FRONT_CAMERA_PREVIEW_WIDTH;
750 m_preview_max_height = MAX_FRONT_CAMERA_PREVIEW_HEIGHT;
751 m_snapshot_max_width = MAX_FRONT_CAMERA_SNAPSHOT_WIDTH;
752 m_snapshot_max_height = MAX_FRONT_CAMERA_SNAPSHOT_HEIGHT;
753 break;
754
755 case CAMERA_ID_BACK:
756 default:
757 m_preview_max_width = MAX_BACK_CAMERA_PREVIEW_WIDTH;
758 m_preview_max_height = MAX_BACK_CAMERA_PREVIEW_HEIGHT;
759 m_snapshot_max_width = MAX_BACK_CAMERA_SNAPSHOT_WIDTH;
760 m_snapshot_max_height = MAX_BACK_CAMERA_SNAPSHOT_HEIGHT;
761 break;
762 }
763
764 if (!m_flagCreate) {
765 /* Arun C
766 * Reset the lense position only during camera starts; don't do
767 * reset between shot to shot
768 */
769 m_flagCreate = 1;
770 m_snapshot_state = 0;
771 m_camera_af_flag = -1;
772 m_camera_id = index;
773 m_recording_en = 0;
774
775 m_cam_fd = open(CAMERA_DEV_NAME, O_RDWR);
776 if (m_cam_fd < 0) {
777 LOGE("ERR(%s):Cannot open %s (error : %s)", __func__, CAMERA_DEV_NAME, strerror(errno));
778 return -1;
779 }
780 LOGV("%s: open(%s) --> m_cam_fd %d", __func__, CAMERA_DEV_NAME, m_cam_fd);
781
782 ret = fimc_v4l2_querycap(m_cam_fd);
783 CHECK(ret);
784 if (!fimc_v4l2_enuminput(m_cam_fd, index)) {
785 LOGE("m_cam_fd(%d) fimc_v4l2_enuminput fail", m_cam_fd);
786 return -1;
787 }
788 ret = fimc_v4l2_s_input(m_cam_fd, index);
789 CHECK(ret);
790
791 m_camera_use_ISP = getUseInternalISP();
792
793 if (m_camera_use_ISP) {
794 if (!m_recording_en)
795 fimc_v4l2_s_fmt_is(m_cam_fd, m_preview_max_width, m_preview_max_height,
796 m_preview_v4lformat, (enum v4l2_field) IS_MODE_PREVIEW_STILL);
797 else
798 fimc_v4l2_s_fmt_is(m_cam_fd, m_preview_max_width, m_preview_max_height,
799 m_preview_v4lformat, (enum v4l2_field) IS_MODE_PREVIEW_VIDEO);
800 }
801
802 ret = fimc_v4l2_s_fmt(m_cam_fd, m_preview_max_width, m_preview_max_height,
803 m_preview_v4lformat, V4L2_FIELD_ANY, PREVIEW_NUM_PLANE);
804 CHECK(ret);
805
806 initParameters(m_camera_use_ISP);
807
808#ifdef SAMSUNG_EXYNOS4x12
809#ifdef ZERO_SHUTTER_LAG
810 if (m_camera_use_ISP) {
811 m_cam_fd2 = open(CAMERA_DEV_NAME2, O_RDWR);
812 LOGV("%s: open(%s) --> m_cam_fd2 = %d", __func__, CAMERA_DEV_NAME2, m_cam_fd2);
813 if (m_cam_fd2 < 0) {
814 LOGE("ERR(%s):Cannot open %s (error : %s)", __func__, CAMERA_DEV_NAME2, strerror(errno));
815 return -1;
816 }
817
818 ret = fimc_v4l2_querycap(m_cam_fd2);
819 CHECK(ret);
820 if (!fimc_v4l2_enuminput(m_cam_fd2, index)) {
821 LOGE("m_cam_fd2(%d) fimc_v4l2_enuminput fail", m_cam_fd2);
822 return -1;
823 }
824 ret = fimc_v4l2_s_input(m_cam_fd2, index);
825 CHECK(ret);
826 }
827#endif
828#endif
829
830 m_cam_fd3 = open(CAMERA_DEV_NAME3, O_RDWR);
831 LOGV("%s: open(%s) --> m_cam_fd3 = %d", __func__, CAMERA_DEV_NAME3, m_cam_fd3);
832 if (m_cam_fd3 < 0) {
833 LOGE("ERR(%s):Cannot open %s (error : %s)", __func__, CAMERA_DEV_NAME3, strerror(errno));
834 return -1;
835 }
836
837 ret = fimc_v4l2_querycap(m_cam_fd3);
838 CHECK(ret);
839 if (!fimc_v4l2_enuminput(m_cam_fd3, index)) {
840 LOGE("m_cam_fd3(%d) fimc_v4l2_enuminput fail", m_cam_fd3);
841 return -1;
842 }
843 ret = fimc_v4l2_s_input(m_cam_fd3, index);
844 CHECK(ret);
845
846 setExifFixedAttribute();
847 }
848
849#ifdef ZERO_SHUTTER_LAG
850 if (m_camera_use_ISP)
851 m_cap_fd = m_cam_fd2;
852 else
853 m_cap_fd = m_cam_fd;
854#else
855 m_cap_fd = m_cam_fd;
856#endif
857
858 m_rec_fd = m_cam_fd3;
859
860 if (m_camera_use_ISP)
861 m_num_capbuf = CAP_BUFFERS;
862 else
863 m_num_capbuf = 1;
864
865 m_flag_camera_create = 1;
866
867 return 0;
868}
869
870void SecCamera::resetCamera()
871{
872 LOGV("%s :", __func__);
873 DestroyCamera();
874 CreateCamera(m_camera_id);
875}
876
877bool SecCamera::DestroyCamera()
878{
879 LOGV("%s :", __func__);
880
881 if (m_flagCreate) {
882
883 stopRecord();
884
885 /* close m_cam_fd after stopRecord() because stopRecord()
886 * uses m_cam_fd to change frame rate
887 */
888 LOGI("DestroyCamera: m_cam_fd(%d)", m_cam_fd);
889 if (m_cam_fd > -1) {
890 close(m_cam_fd);
891 m_cam_fd = -1;
892 }
893
894#ifdef ZERO_SHUTTER_LAG
895 if (m_camera_use_ISP) {
896 LOGI("DestroyCamera: m_cam_fd2(%d)", m_cam_fd2);
897 if (m_cam_fd2 > -1) {
898 close(m_cam_fd2);
899 m_cam_fd2 = -1;
900 }
901 }
902#endif
903
904 LOGI("DestroyCamera: m_cam_fd3(%d)", m_cam_fd3);
905 if (m_cam_fd3 > -1) {
906 close(m_cam_fd3);
907 m_cam_fd3 = -1;
908 }
909
910 m_flagCreate = 0;
911 } else
912 LOGI("%s : already deinitialized", __func__);
913
914 return 0;
915}
916
917void SecCamera::initParameters(int internalISP)
918{
919 memset(&m_streamparm, 0, sizeof(m_streamparm));
920 m_params = (struct sec_cam_parm*)&m_streamparm.parm.raw_data;
921 struct v4l2_captureparm capture;
922
923 m_params->capture.timeperframe.numerator = 1;
924 m_params->capture.timeperframe.denominator = FRAME_RATE_AUTO;
925 m_params->flash_mode = FLASH_MODE_AUTO;
926 m_params->iso = ISO_AUTO;
927 m_params->metering = METERING_CENTER;
928 m_params->saturation = SATURATION_DEFAULT;
929 m_params->scene_mode = SCENE_MODE_NONE;
930 m_params->sharpness = SHARPNESS_DEFAULT;
931 m_params->white_balance = WHITE_BALANCE_AUTO;
932 m_params->anti_banding = ANTI_BANDING_OFF;
933 m_params->effects = IMAGE_EFFECT_NONE;
934 m_params->focus_mode = FOCUS_MODE_AUTO;
935
936 if (internalISP) {
937 m_params->contrast = IS_CONTRAST_DEFAULT;
938 m_params->brightness = IS_BRIGHTNESS_DEFAULT;
939 m_params->exposure = IS_EXPOSURE_DEFAULT;
940 m_params->hue = IS_HUE_DEFAULT;
941 m_params->aeawb_mode = AE_UNLOCK_AWB_UNLOCK;
942 } else {
943 m_params->contrast = CONTRAST_DEFAULT;
944 m_params->brightness = EV_DEFAULT;
945 m_params->exposure = EV_DEFAULT;
946 m_params->hue = -1;
947 m_params->aeawb_mode = -1;
948 }
949}
950
951int SecCamera::setMode(int recording_en)
952{
953 LOGV("%s :", __func__);
954 int mode;
955
956 m_recording_en = recording_en;
957
958 if (m_camera_use_ISP) {
959 if (!recording_en)
960 mode = IS_MODE_PREVIEW_STILL;
961 else
962 mode = IS_MODE_PREVIEW_VIDEO;
963
964 if (fimc_v4l2_s_ctrl(m_cam_fd, V4L2_CID_IS_S_FORMAT_SCENARIO, mode) < 0) {
965 LOGE("ERR(%s):Fail on V4L2_CID_IS_S_FORMAT_SCENARIO", __func__);
966 return -1;
967 }
968 }
969
970 return 0;
971}
972
973int SecCamera::getCameraFd(enum CAM_MODE mode)
974{
975 int ret = -1;
976
977 switch (mode) {
978 case PREVIEW:
979 ret = m_cam_fd;
980 break;
981 case PICTURE:
982 ret = m_cap_fd;
983 break;
984 default:
985 ret = m_cam_fd;
986 break;
987 }
988
989 return ret;
990}
991
992int SecCamera::startPreview(void)
993{
994 v4l2_streamparm streamparm;
995 struct sec_cam_parm *parms;
996 parms = (struct sec_cam_parm*)&streamparm.parm.raw_data;
997 LOGV("%s :", __func__);
998
999 // aleady started
1000 if (m_flag_camera_start > 0) {
1001 LOGE("ERR(%s):Preview was already started", __func__);
1002 return 0;
1003 }
1004
1005 if (m_cam_fd <= 0) {
1006 LOGE("ERR(%s):Camera was closed", __func__);
1007 return -1;
1008 }
1009
1010 memset(&m_events_c, 0, sizeof(m_events_c));
1011 m_events_c.fd = m_cam_fd;
1012 m_events_c.events = POLLIN | POLLERR;
1013
1014 /* enum_fmt, s_fmt sample */
1015 int ret = fimc_v4l2_enum_fmt(m_cam_fd,m_preview_v4lformat);
1016 CHECK(ret);
1017
1018 LOGV("m_camera_use_ISP(%d), %s", m_camera_use_ISP, (const char*)getCameraSensorName());
1019
1020 if (m_camera_use_ISP) {
1021 if (!m_recording_en)
1022 fimc_v4l2_s_fmt_is(m_cam_fd, m_videosnapshot_width, m_videosnapshot_height,
1023 m_preview_v4lformat, (enum v4l2_field) IS_MODE_PREVIEW_STILL);
1024 else
1025 fimc_v4l2_s_fmt_is(m_cam_fd, m_videosnapshot_width, m_videosnapshot_height,
1026 m_preview_v4lformat, (enum v4l2_field) IS_MODE_PREVIEW_VIDEO);
1027 }
1028
1029 ret = fimc_v4l2_s_fmt(m_cam_fd, m_preview_width, m_preview_height, m_preview_v4lformat, V4L2_FIELD_ANY, PREVIEW_NUM_PLANE);
1030 CHECK(ret);
1031
1032#ifndef BOARD_USE_V4L2_ION
1033 if (!m_camera_use_ISP) {
1034 fimc_v4l2_s_fmt_is(m_cam_fd, m_preview_width, m_preview_height,
1035 m_preview_v4lformat, (enum v4l2_field) IS_MODE_PREVIEW_STILL);
1036 }
1037#endif
1038
1039 if (m_camera_use_ISP) {
1040 if (!m_recording_en)
1041 ret = fimc_v4l2_s_ctrl(m_cam_fd, V4L2_CID_IS_S_SCENARIO_MODE, IS_MODE_PREVIEW_STILL);
1042 else
1043 ret = fimc_v4l2_s_ctrl(m_cam_fd, V4L2_CID_IS_S_SCENARIO_MODE, IS_MODE_PREVIEW_VIDEO);
1044 }
1045 CHECK(ret);
1046
1047#ifndef BOARD_USE_V4L2_ION
1048 ret = fimc_v4l2_s_ctrl(m_cam_fd, V4L2_CID_CACHEABLE, 1);
1049 CHECK(ret);
1050#endif
1051
1052 ret = fimc_v4l2_reqbufs(m_cam_fd, V4L2_BUF_TYPE, MAX_BUFFERS);
1053 CHECK(ret);
1054
1055#ifndef BOARD_USE_V4L2_ION
1056 ret = fimc_v4l2_querybuf(m_cam_fd, m_buffers_preview, V4L2_BUF_TYPE, MAX_BUFFERS, PREVIEW_NUM_PLANE);
1057 CHECK(ret);
1058#endif
1059
1060 LOGV("%s : m_preview_width: %d m_preview_height: %d m_angle: %d",
1061 __func__, m_preview_width, m_preview_height, m_angle);
1062
1063 LOGV("m_camera_id : %d", m_camera_id);
1064
1065 /* start with all buffers in queue */
1066 for (int i = 0; i < MAX_BUFFERS; i++) {
1067 ret = fimc_v4l2_qbuf(m_cam_fd, m_preview_width, m_preview_height, m_buffers_preview, i, PREVIEW_NUM_PLANE, PREVIEW_MODE);
1068 CHECK(ret);
1069 }
1070
1071 ret = fimc_v4l2_streamon(m_cam_fd);
1072 CHECK(ret);
1073
1074#ifdef USE_FACE_DETECTION
1075 if (m_camera_use_ISP) {
1076 ret = fimc_v4l2_s_ctrl(m_cam_fd, V4L2_CID_IS_CMD_FD, IS_FD_COMMAND_START);
1077 CHECK(ret);
1078 }
1079#endif
1080
1081#ifdef ZERO_SHUTTER_LAG
1082 if (m_camera_use_ISP && !m_recording_en) {
1083 stopSnapshot();
1084 startSnapshot(NULL);
1085 }
1086#endif
1087
1088 m_flag_camera_start = 1;
1089
1090 LOGV("%s: got the first frame of the preview", __func__);
1091
1092 return 0;
1093}
1094
1095int SecCamera::stopPreview(void)
1096{
1097 int ret;
1098
1099 LOGV("%s :", __func__);
1100
1101 if (m_flag_camera_start == 0) {
1102 LOGW("%s: doing nothing because m_flag_camera_start is zero", __func__);
1103 return 0;
1104 }
1105
1106#ifdef ZERO_SHUTTER_LAG
1107 if (m_camera_use_ISP && !m_recording_en)
1108 stopSnapshot();
1109#endif
1110
1111 if (m_params->flash_mode == FLASH_MODE_TORCH)
1112 setFlashMode(FLASH_MODE_OFF);
1113
1114 if (m_cam_fd <= 0) {
1115 LOGE("ERR(%s):Camera was closed", __func__);
1116 return -1;
1117 }
1118#ifdef USE_FACE_DETECTION
1119 if (m_camera_use_ISP) {
1120 ret = fimc_v4l2_s_ctrl(m_cam_fd, V4L2_CID_IS_CMD_FD, IS_FD_COMMAND_STOP);
1121 CHECK(ret);
1122 }
1123#endif
1124 /* TODO : This code is temporary implementation. */
1125 /* Because streamoff is failed when ae lock or awb lock state */
1126 if (m_camera_use_ISP && m_params->aeawb_mode) {
1127 if (m_params->aeawb_mode & 0x1) {
1128 if (setAutoExposureLock(0) < 0) {
1129 LOGE("ERR(%s): Fail on setAutoExposureLock()");
1130 return -1;
1131 }
1132 }
1133 if (m_params->aeawb_mode & (0x1 << 1)) {
1134 if (setAutoWhiteBalanceLock(0) < 0) {
1135 LOGE("ERR(%s): Fail on setAutoWhiteBalnaceLock()");
1136 return -1;
1137 }
1138 }
1139 m_params->aeawb_mode = 0;
1140 }
1141
1142 ret = fimc_v4l2_streamoff(m_cam_fd);
1143 CHECK(ret);
1144
1145 close_buffers(m_buffers_preview, MAX_BUFFERS);
1146
1147 fimc_v4l2_reqbufs(m_cam_fd, V4L2_BUF_TYPE, 0);
1148
1149 m_flag_camera_start = 0;
1150
1151 return ret;
1152}
1153
1154int SecCamera::startSnapshot(SecBuffer *yuv_buf)
1155{
1156 LOGV("%s :", __func__);
1157
1158 // already started
1159 if (m_snapshot_state) {
1160 LOGI("%s: Doing nothing because snapshot is already started!", __func__);
1161 return 0;
1162 }
1163
1164 if (m_cap_fd <= 0) {
1165 LOGE("ERR(%s):Camera was closed", __func__);
1166 return -1;
1167 }
1168
1169 m_snapshot_state = 1;
1170
1171 memset(&m_events_c2, 0, sizeof(m_events_c2));
1172 m_events_c2.fd = m_cap_fd;
1173 m_events_c2.events = POLLIN | POLLERR;
1174
1175#if defined(LOG_NDEBUG) && LOG_NDEBUG == 0
1176 if (m_snapshot_v4lformat == V4L2_PIX_FMT_YUV420)
1177 LOGV("SnapshotFormat:V4L2_PIX_FMT_YUV420");
1178 else if (m_snapshot_v4lformat == V4L2_PIX_FMT_NV12)
1179 LOGV("SnapshotFormat:V4L2_PIX_FMT_NV12");
1180 else if (m_snapshot_v4lformat == V4L2_PIX_FMT_NV12T)
1181 LOGV("SnapshotFormat:V4L2_PIX_FMT_NV12T");
1182 else if (m_snapshot_v4lformat == V4L2_PIX_FMT_NV21)
1183 LOGV("SnapshotFormat:V4L2_PIX_FMT_NV21");
1184 else if (m_snapshot_v4lformat == V4L2_PIX_FMT_YUV422P)
1185 LOGV("SnapshotFormat:V4L2_PIX_FMT_YUV422P");
1186 else if (m_snapshot_v4lformat == V4L2_PIX_FMT_YUYV)
1187 LOGV("SnapshotFormat:V4L2_PIX_FMT_YUYV");
1188 else if (m_snapshot_v4lformat == V4L2_PIX_FMT_UYVY)
1189 LOGV("SnapshotFormat:V4L2_PIX_FMT_UYVY");
1190 else if (m_snapshot_v4lformat == V4L2_PIX_FMT_RGB565)
1191 LOGV("SnapshotFormat:V4L2_PIX_FMT_RGB565");
1192 else
1193 LOGV("SnapshotFormat:UnknownFormat");
1194#endif
1195
1196 int ret = fimc_v4l2_enum_fmt(m_cap_fd, m_snapshot_v4lformat);
1197 CHECK(ret);
1198
1199 if (m_camera_use_ISP) {
1200 fimc_v4l2_s_fmt_is(m_cap_fd, m_videosnapshot_width, m_videosnapshot_height,
1201 m_preview_v4lformat, (enum v4l2_field) IS_MODE_PREVIEW_STILL);
1202 }
1203
1204 if (!m_recording_en)
1205 ret = fimc_v4l2_s_fmt_cap(m_cap_fd, m_snapshot_width, m_snapshot_height, m_snapshot_v4lformat);
1206 else
1207 ret = fimc_v4l2_s_fmt_cap(m_cap_fd, m_videosnapshot_width, m_videosnapshot_height, m_snapshot_v4lformat);
1208 CHECK(ret);
1209
1210#ifndef BOARD_USE_V4L2_ION
1211 if (!m_camera_use_ISP)
1212 if (!m_recording_en)
1213 fimc_v4l2_s_fmt_is(m_cap_fd, m_snapshot_width, m_snapshot_height,
1214 m_preview_v4lformat, (enum v4l2_field) IS_MODE_PREVIEW_STILL);
1215 else
1216 fimc_v4l2_s_fmt_is(m_cap_fd, m_videosnapshot_width, m_videosnapshot_height,
1217 m_preview_v4lformat, (enum v4l2_field) IS_MODE_PREVIEW_VIDEO);
1218#endif
1219
1220#ifndef ZERO_SHUTTER_LAG
1221 if (m_camera_use_ISP)
1222 ret = fimc_v4l2_s_ctrl(m_cap_fd, V4L2_CID_IS_S_SCENARIO_MODE, IS_MODE_PREVIEW_STILL);
1223 CHECK(ret);
1224#endif
1225
1226#ifndef BOARD_USE_V4L2_ION
1227 ret = fimc_v4l2_s_ctrl(m_cap_fd, V4L2_CID_CACHEABLE, 1);
1228 CHECK(ret);
1229#endif
1230
1231 ret = fimc_v4l2_reqbufs(m_cap_fd, V4L2_BUF_TYPE, m_num_capbuf);
1232 CHECK(ret);
1233
1234#ifdef BOARD_USE_V4L2_ION
1235#ifndef ZERO_SHUTTER_LAG
1236 m_capture_buf[0].virt.p = (char *)yuv_buf->virt.p;
1237#endif
1238#else
1239 ret = fimc_v4l2_querybuf(m_cap_fd, m_capture_buf, V4L2_BUF_TYPE, m_num_capbuf, 1);
1240 CHECK(ret);
1241#endif
1242
1243 /* start with all buffers in queue */
1244 for (int i = 0; i < m_num_capbuf; i++) {
1245 ret = fimc_v4l2_qbuf(m_cap_fd, m_snapshot_width, m_snapshot_height, m_capture_buf, i, 1, CAPTURE_MODE);
1246 CHECK(ret);
1247 }
1248
1249 ret = fimc_v4l2_streamon(m_cap_fd);
1250 CHECK(ret);
1251
1252 return 0;
1253}
1254
1255int SecCamera::stopSnapshot(void)
1256{
1257 int ret;
1258
1259 LOGV("%s :", __func__);
1260
1261 if (!m_snapshot_state) {
1262 LOGI("%s: Doing nothing because snapshot is not started!", __func__);
1263 return 0;
1264 }
1265
1266 if (m_cap_fd <= 0) {
1267 LOGE("ERR(%s):Camera was closed", __func__);
1268 return -1;
1269 }
1270
1271 ret = fimc_v4l2_streamoff(m_cap_fd);
1272 CHECK(ret);
1273
1274 endSnapshot();
1275
1276 m_snapshot_state = 0;
1277
1278 return ret;
1279}
1280
1281//Recording
1282int SecCamera::startRecord(bool recordHint)
1283{
1284 int ret, i;
1285
1286 LOGV("%s :", __func__);
1287
1288 // aleady started
1289 if (m_flag_record_start > 0) {
1290 LOGE("ERR(%s):Preview was already started", __func__);
1291 return 0;
1292 }
1293
1294 if (m_rec_fd <= 0) {
1295 LOGE("ERR(%s):Camera was closed", __func__);
1296 return -1;
1297 }
1298
1299 /* enum_fmt, s_fmt sample */
1300 ret = fimc_v4l2_enum_fmt(m_rec_fd, RECORD_PIX_FMT);
1301 CHECK(ret);
1302
1303 LOGI("%s: m_recording_width = %d, m_recording_height = %d",
1304 __func__, m_recording_width, m_recording_height);
1305
1306 LOGV("m_camera_use_ISP(%d), %s", m_camera_use_ISP, (const char*)getCameraSensorName());
1307
1308 if (m_camera_use_ISP) {
1309 fimc_v4l2_s_fmt_is(m_rec_fd, m_videosnapshot_width, m_videosnapshot_height,
1310 m_preview_v4lformat, (enum v4l2_field) IS_MODE_CAPTURE_VIDEO);
1311
1312 ret = fimc_v4l2_s_fmt(m_rec_fd, m_recording_width,
1313 m_recording_height, RECORD_PIX_FMT, V4L2_FIELD_ANY, RECORD_NUM_PLANE);
1314 CHECK(ret);
1315 } else {
1316 ret = fimc_v4l2_s_fmt(m_rec_fd, m_preview_width,
1317 m_preview_height, RECORD_PIX_FMT, V4L2_FIELD_ANY, RECORD_NUM_PLANE);
1318 CHECK(ret);
1319#ifndef BOARD_USE_V4L2_ION
1320 fimc_v4l2_s_fmt_is(m_rec_fd, m_preview_width, m_preview_height,
1321 m_preview_v4lformat, (enum v4l2_field) IS_MODE_CAPTURE_VIDEO);
1322#endif
1323 }
1324
1325 if (!m_camera_use_ISP) {
1326 ret = fimc_v4l2_s_ctrl(m_rec_fd, V4L2_CID_CAMERA_BUSFREQ_LOCK, 267160);
1327 CHECK(ret);
1328 }
1329
1330 ret = fimc_v4l2_reqbufs(m_rec_fd, V4L2_BUF_TYPE, MAX_BUFFERS);
1331 CHECK(ret);
1332
1333#ifndef BOARD_USE_V4L2_ION
1334 ret = fimc_v4l2_querybuf(m_rec_fd, m_buffers_record, V4L2_BUF_TYPE, MAX_BUFFERS, RECORD_NUM_PLANE);
1335 CHECK(ret);
1336#endif
1337
1338 /* start with all buffers in queue */
1339 for (i = 0; i < MAX_BUFFERS; i++) {
1340 ret = fimc_v4l2_qbuf(m_rec_fd, m_recording_width, m_recording_height, m_buffers_record, i, RECORD_NUM_PLANE, RECORD_MODE);
1341 CHECK(ret);
1342 }
1343
1344 // Get and throw away the first frame since it is often garbled.
1345 memset(&m_events_c3, 0, sizeof(m_events_c3));
1346 m_events_c3.fd = m_rec_fd;
1347 m_events_c3.events = POLLIN | POLLERR;
1348
1349 m_record_hint = recordHint;
1350#ifdef VIDEO_SNAPSHOT
1351 if (m_camera_use_ISP && m_record_hint) {
1352 stopSnapshot();
1353 startSnapshot(NULL);
1354 }
1355#endif
1356
1357 ret = fimc_v4l2_streamon(m_rec_fd);
1358 CHECK(ret);
1359
1360 m_flag_record_start = 1;
1361
1362 return 0;
1363}
1364
1365int SecCamera::stopRecord(void)
1366{
1367 int ret;
1368
1369 LOGV("%s :", __func__);
1370
1371 if (m_flag_record_start == 0) {
1372 LOGW("%s: doing nothing because m_flag_record_start is zero", __func__);
1373 return 0;
1374 }
1375
1376#ifdef VIDEO_SNAPSHOT
1377 if (m_camera_use_ISP && m_record_hint)
1378 stopSnapshot();
1379#endif
1380
1381 if (m_rec_fd <= 0) {
1382 LOGE("ERR(%s):Camera was closed", __func__);
1383 return -1;
1384 }
1385
1386 m_flag_record_start = 0;
1387
1388 if (!m_camera_use_ISP) {
1389 ret = fimc_v4l2_s_ctrl(m_rec_fd, V4L2_CID_CAMERA_BUSFREQ_UNLOCK, 0);
1390 CHECK(ret);
1391 }
1392
1393 ret = fimc_v4l2_streamoff(m_rec_fd);
1394 CHECK(ret);
1395
1396 close_buffers(m_buffers_record, MAX_BUFFERS);
1397
1398 fimc_v4l2_reqbufs(m_rec_fd, V4L2_BUF_TYPE, 0);
1399
1400 return 0;
1401}
1402
1403int SecCamera::getRecordAddr(int index, SecBuffer *buffer)
1404{
1405#ifdef BOARD_USE_V4L2
1406 buffer->phys.extP[0] = (unsigned int)m_buffers_record[index].phys.extP[0];
1407 buffer->phys.extP[1] = (unsigned int)(m_buffers_record[index].phys.extP[0] + (m_recording_width * m_recording_height));
1408#else
1409 buffer->phys.extP[0] = fimc_v4l2_s_ctrl(m_rec_fd, V4L2_CID_PADDR_Y, index);
1410 CHECK((int)buffer->phys.extP[0]);
1411 buffer->phys.extP[1] = fimc_v4l2_s_ctrl(m_rec_fd, V4L2_CID_PADDR_CBCR, index);
1412 CHECK((int)buffer->phys.extP[1]);
1413#endif
1414 return 0;
1415}
1416
1417int SecCamera::getPreviewAddr(int index, SecBuffer *buffer)
1418{
1419#ifdef BOARD_USE_V4L2
1420 buffer->phys.extP[0] = (unsigned int)m_buffers_preview[index].phys.extP[0];
1421 buffer->phys.extP[1] = (unsigned int)m_buffers_preview[index].phys.extP[1];
1422 buffer->virt.extP[0] = m_buffers_preview[index].virt.extP[0];
1423#else
1424 buffer->phys.extP[0] = fimc_v4l2_s_ctrl(m_cam_fd, V4L2_CID_PADDR_Y, index);
1425 CHECK((int)buffer->phys.extP[0]);
1426 buffer->phys.extP[1] = fimc_v4l2_s_ctrl(m_cam_fd, V4L2_CID_PADDR_CBCR, index);
1427 CHECK((int)buffer->phys.extP[1]);
1428#endif
1429 return 0;
1430}
1431
1432int SecCamera::getCaptureAddr(int index, SecBuffer *buffer)
1433{
1434 buffer->virt.extP[0] = m_capture_buf[index].virt.extP[0];
1435 CHECK((int)buffer->virt.extP[0]);
1436 return 0;
1437}
1438
1439#ifdef BOARD_USE_V4L2_ION
1440void SecCamera::setUserBufferAddr(void *ptr, int index, int mode)
1441{
1442 if (mode == PREVIEW_MODE) {
1443 m_buffers_preview[index].virt.extP[0] = (char *)((unsigned int *)ptr)[0];
1444 m_buffers_preview[index].virt.extP[1] = (char *)((unsigned int *)ptr)[1];
1445 m_buffers_preview[index].virt.extP[2] = (char *)((unsigned int *)ptr)[2];
1446 } else if (mode == CAPTURE_MODE) {
1447 m_capture_buf[index].virt.extP[0] = (char *)ptr;
1448 } else if (mode == RECORD_MODE) {
1449 m_buffers_record[index].virt.extP[0] = (char *)ptr;
1450 m_buffers_record[index].virt.extP[1] = (char *)ptr + (ALIGN((ALIGN(m_recording_width, 16) * ALIGN(m_recording_height, 16)), 2048));
1451 } else
1452 LOGE("%s: Invalid fd!!!", __func__);
1453}
1454#endif
1455
1456int SecCamera::getPreview(camera_frame_metadata_t *facedata)
1457{
1458 int index;
1459 int ret;
1460
1461 if (m_flag_camera_start == 0 || fimc_poll(&m_events_c) == 0) {
1462 LOGE("ERR(%s):Start Camera Device Reset", __func__);
1463 /*
1464 * When there is no data for more than 1 second from the camera we inform
1465 * the FIMC driver by calling fimc_v4l2_s_input() with a special value = 1000
1466 * FIMC driver identify that there is something wrong with the camera
1467 * and it restarts the sensor.
1468 */
1469 stopPreview();
1470 /* Reset Only Camera Device */
1471 ret = fimc_v4l2_querycap(m_cam_fd);
1472 CHECK(ret);
1473 if (fimc_v4l2_enuminput(m_cam_fd, m_camera_id))
1474 return -1;
1475 ret = fimc_v4l2_s_input(m_cam_fd, 1000);
1476 CHECK(ret);
1477#ifdef BOARD_USE_V4L2_ION
1478 m_preview_state = 0;
1479 return -1;
1480#endif
1481 ret = startPreview();
1482 if (ret < 0) {
1483 LOGE("ERR(%s): startPreview() return %d", __func__, ret);
1484 return 0;
1485 }
1486 }
1487
1488 index = fimc_v4l2_dqbuf(m_cam_fd, PREVIEW_NUM_PLANE);
1489 if (!(0 <= index && index < MAX_BUFFERS)) {
1490 LOGE("ERR(%s):wrong index = %d", __func__, index);
1491 return -1;
1492 }
1493
1494#ifdef USE_FACE_DETECTION
1495 if (m_camera_use_ISP) {
1496 fimc_v4l2_s_ext_ctrl_face_detection(m_cam_fd, 0, facedata);
1497 }
1498#endif
1499
1500 return index;
1501}
1502
1503int SecCamera::setPreviewFrame(int index)
1504{
1505 int ret;
1506 ret = fimc_v4l2_qbuf(m_cam_fd, m_preview_width, m_preview_height, m_buffers_preview, index, PREVIEW_NUM_PLANE, PREVIEW_MODE);
1507 CHECK(ret);
1508
1509 return ret;
1510}
1511
1512int SecCamera::getSnapshot()
1513{
1514 int index;
1515 int ret;
1516
1517 if (m_snapshot_state) {
1518 fimc_poll(&m_events_c2);
1519
1520 index = fimc_v4l2_dqbuf(m_cap_fd, 1);
1521 if (!(0 <= index && index < m_num_capbuf)) {
1522 LOGE("ERR(%s):wrong index = %d", __func__, index);
1523 return -1;
1524 }
1525 return index;
1526 }
1527
1528 return -1;
1529}
1530
1531int SecCamera::setSnapshotFrame(int index)
1532{
1533 int ret;
1534 ret = fimc_v4l2_qbuf(m_cap_fd, m_snapshot_width, m_snapshot_height, m_capture_buf, index, PREVIEW_NUM_PLANE, CAPTURE_MODE);
1535 CHECK(ret);
1536
1537 return ret;
1538}
1539
1540int SecCamera::getRecordFrame()
1541{
1542 if (m_flag_record_start == 0) {
1543 LOGE("%s: m_flag_record_start is 0", __func__);
1544 return -1;
1545 }
1546
1547 fimc_poll(&m_events_c3);
1548 int index = fimc_v4l2_dqbuf(m_rec_fd, RECORD_NUM_PLANE);
1549 if (!(0 <= index && index < MAX_BUFFERS)) {
1550 LOGE("ERR(%s):wrong index = %d", __func__, index);
1551 return -1;
1552 }
1553
1554 return index;
1555}
1556
1557int SecCamera::releaseRecordFrame(int index)
1558{
1559 if (!m_flag_record_start) {
1560 /* this can happen when recording frames are returned after
1561 * the recording is stopped at the driver level. we don't
1562 * need to return the buffers in this case and we've seen
1563 * cases where fimc could crash if we called qbuf and it
1564 * wasn't expecting it.
1565 */
1566 LOGI("%s: recording not in progress, ignoring", __func__);
1567 return 0;
1568 }
1569
1570 return fimc_v4l2_qbuf(m_rec_fd, m_recording_width, m_recording_height, m_buffers_record, index, RECORD_NUM_PLANE, RECORD_MODE);
1571}
1572
1573int SecCamera::setPreviewSize(int width, int height, int pixel_format)
1574{
1575 LOGV("%s(width(%d), height(%d), format(%d))", __func__, width, height, pixel_format);
1576
1577 int v4lpixelformat = pixel_format;
1578
1579#if defined(LOG_NDEBUG) && LOG_NDEBUG == 0
1580 if (v4lpixelformat == V4L2_PIX_FMT_YUV420)
1581 LOGV("PreviewFormat:V4L2_PIX_FMT_YUV420");
1582 else if (v4lpixelformat == V4L2_PIX_FMT_YVU420)
1583 LOGV("PreviewFormat:V4L2_PIX_FMT_YVU420");
1584 else if (v4lpixelformat == V4L2_PIX_FMT_YVU420M)
1585 LOGV("PreviewFormat:V4L2_PIX_FMT_YVU420M");
1586 else if (v4lpixelformat == V4L2_PIX_FMT_NV12)
1587 LOGV("PreviewFormat:V4L2_PIX_FMT_NV12");
1588 else if (v4lpixelformat == V4L2_PIX_FMT_NV12T)
1589 LOGV("PreviewFormat:V4L2_PIX_FMT_NV12T");
1590 else if (v4lpixelformat == V4L2_PIX_FMT_NV21)
1591 LOGV("PreviewFormat:V4L2_PIX_FMT_NV21");
1592 else if (v4lpixelformat == V4L2_PIX_FMT_YUV422P)
1593 LOGV("PreviewFormat:V4L2_PIX_FMT_YUV422P");
1594 else if (v4lpixelformat == V4L2_PIX_FMT_YUYV)
1595 LOGV("PreviewFormat:V4L2_PIX_FMT_YUYV");
1596 else if (v4lpixelformat == V4L2_PIX_FMT_RGB565)
1597 LOGV("PreviewFormat:V4L2_PIX_FMT_RGB565");
1598 else
1599 LOGV("PreviewFormat:UnknownFormat");
1600#endif
1601 m_preview_width = width;
1602 m_preview_height = height;
1603 m_preview_v4lformat = v4lpixelformat;
1604
1605 return 0;
1606}
1607
1608int SecCamera::getPreviewSize(int *width, int *height, int *frame_size)
1609{
1610 *width = m_preview_width;
1611 *height = m_preview_height;
1612 *frame_size = FRAME_SIZE(V4L2_PIX_2_HAL_PIXEL_FORMAT(m_preview_v4lformat), *width, *height);
1613 return 0;
1614}
1615
1616int SecCamera::getPreviewMaxSize(int *width, int *height)
1617{
1618 *width = m_preview_max_width;
1619 *height = m_preview_max_height;
1620
1621 return 0;
1622}
1623
1624int SecCamera::getPreviewPixelFormat(void)
1625{
1626 return m_preview_v4lformat;
1627}
1628
1629/*
1630 * Devide getJpeg() as two funcs, setSnapshotCmd() & getJpeg() because of the shutter sound timing.
1631 * Here, just send the capture cmd to camera ISP to start JPEG capture.
1632 */
1633int SecCamera::setSnapshotCmd(void)
1634{
1635 LOGV("%s :", __func__);
1636
1637 int ret = 0;
1638
1639 if (m_cam_fd <= 0) {
1640 LOGE("ERR(%s):Camera was closed", __func__);
1641 return 0;
1642 }
1643
1644 if (m_flag_camera_start > 0) {
1645 LOGW("WARN(%s):Camera was in preview, should have been stopped", __func__);
1646 stopPreview();
1647 }
1648
1649 memset(&m_events_c, 0, sizeof(m_events_c));
1650 m_events_c.fd = m_cam_fd;
1651 m_events_c.events = POLLIN | POLLERR;
1652
1653 int nframe = 1;
1654
1655 ret = fimc_v4l2_enum_fmt(m_cam_fd,m_snapshot_v4lformat);
1656 CHECK(ret);
1657 ret = fimc_v4l2_s_fmt_cap(m_cam_fd, m_snapshot_width, m_snapshot_height, V4L2_PIX_FMT_JPEG);
1658 CHECK(ret);
1659
1660#ifndef BOARD_USE_V4L2_ION
1661 if (!m_camera_use_ISP)
1662 if (!m_recording_en)
1663 fimc_v4l2_s_fmt_is(m_cap_fd, m_snapshot_width, m_snapshot_height,
1664 V4L2_PIX_FMT_JPEG, (enum v4l2_field) IS_MODE_PREVIEW_STILL);
1665 else
1666 fimc_v4l2_s_fmt_is(m_cap_fd, m_videosnapshot_width, m_videosnapshot_height,
1667 V4L2_PIX_FMT_JPEG, (enum v4l2_field) IS_MODE_PREVIEW_VIDEO);
1668#endif
1669
1670 ret = fimc_v4l2_reqbufs(m_cam_fd, V4L2_BUF_TYPE, nframe);
1671 CHECK(ret);
1672
1673#ifndef BOARD_USE_V4L2_ION
1674 ret = fimc_v4l2_querybuf(m_cam_fd, m_capture_buf, V4L2_BUF_TYPE, 1, 1);
1675 CHECK(ret);
1676#endif
1677
1678 ret = fimc_v4l2_qbuf(m_cam_fd, m_snapshot_width, m_snapshot_height, m_capture_buf, 0, 1, CAPTURE_MODE);
1679 CHECK(ret);
1680
1681 ret = fimc_v4l2_streamon(m_cam_fd);
1682 CHECK(ret);
1683
1684 return 0;
1685}
1686
1687int SecCamera::endSnapshot(void)
1688{
1689 close_buffers(m_capture_buf, m_num_capbuf);
1690
1691 fimc_v4l2_reqbufs(m_cap_fd, V4L2_BUF_TYPE, 0);
1692
1693 return 0;
1694}
1695
1696/*
1697 * Set Jpeg quality & exif info and get JPEG data from camera ISP
1698 */
1699unsigned char* SecCamera::getJpeg(int *jpeg_size,
1700 int *thumb_size,
1701 unsigned int *thumb_addr,
1702 unsigned int *phyaddr)
1703{
1704 int index, ret = 0;
1705 unsigned char *addr;
1706 SecBuffer jpegAddr;
1707
1708 // capture
1709 ret = fimc_v4l2_s_ctrl(m_cam_fd, V4L2_CID_CAMERA_CAPTURE, 0);
1710 CHECK_PTR(ret);
1711 ret = fimc_poll(&m_events_c);
1712 CHECK_PTR(ret);
1713 index = fimc_v4l2_dqbuf(m_cam_fd, 1);
1714
1715 if (index != 0) {
1716 LOGE("ERR(%s):wrong index = %d", __func__, index);
1717 return NULL;
1718 }
1719
1720 *jpeg_size = fimc_v4l2_g_ctrl(m_cam_fd, V4L2_CID_CAM_JPEG_MAIN_SIZE);
1721 CHECK_PTR(*jpeg_size);
1722
1723 int main_offset = fimc_v4l2_g_ctrl(m_cam_fd, V4L2_CID_CAM_JPEG_MAIN_OFFSET);
1724 CHECK_PTR(main_offset);
1725
1726 *thumb_size = fimc_v4l2_g_ctrl(m_cam_fd, V4L2_CID_CAM_JPEG_THUMB_SIZE);
1727 CHECK_PTR(*thumb_size);
1728
1729 int thumb_offset = fimc_v4l2_g_ctrl(m_cam_fd, V4L2_CID_CAM_JPEG_THUMB_OFFSET);
1730 CHECK_PTR(thumb_offset);
1731
1732 m_postview_offset = fimc_v4l2_g_ctrl(m_cam_fd, V4L2_CID_CAM_JPEG_POSTVIEW_OFFSET);
1733 CHECK_PTR(m_postview_offset);
1734
1735 ret = fimc_v4l2_s_ctrl(m_cam_fd, V4L2_CID_STREAM_PAUSE, 0);
1736 CHECK_PTR(ret);
1737
1738 LOGV("\nsnapshot dqueued buffer = %d snapshot_width = %d snapshot_height = %d, size = %d",
1739 index, m_snapshot_width, m_snapshot_height, *jpeg_size);
1740
1741 addr = (unsigned char*)(m_capture_buf[0].virt.extP[0]) + main_offset;
1742
1743 *thumb_addr = (unsigned int)(addr + thumb_offset);
1744
1745 getPreviewAddr(index, &jpegAddr);
1746 *phyaddr = jpegAddr.phys.extP[0] + m_postview_offset;
1747
1748 ret = fimc_v4l2_streamoff(m_cam_fd);
1749 CHECK_PTR(ret);
1750
1751 return addr;
1752}
1753
1754int SecCamera::getExif(unsigned char *pExifDst, unsigned char *pThumbSrc, int thumbSize)
1755{
1756#ifdef SAMSUNG_EXYNOS4210
1757 /* JPEG encode for smdkv310 */
1758 if (m_jpeg_fd > 0) {
1759 if (api_jpeg_encode_deinit(m_jpeg_fd) != JPEG_OK)
1760 LOGE("ERR(%s):Fail on api_jpeg_encode_deinit", __func__);
1761 m_jpeg_fd = 0;
1762 }
1763
1764 m_jpeg_fd = api_jpeg_encode_init();
1765 LOGV("(%s):JPEG device open ID = %d", __func__, m_jpeg_fd);
1766
1767 if (m_jpeg_fd <= 0) {
1768 if (m_jpeg_fd < 0) {
1769 m_jpeg_fd = 0;
1770 LOGE("ERR(%s):Cannot open a jpeg device file", __func__);
1771 return -1;
1772 }
1773 LOGE("ERR(%s):JPEG device was closed", __func__);
1774 return -1;
1775 }
1776
1777 if (m_snapshot_v4lformat == V4L2_PIX_FMT_RGB565) {
1778 LOGE("ERR(%s):It doesn't support V4L2_PIX_FMT_RGB565", __func__);
1779 return -1;
1780 }
1781
1782 struct jpeg_enc_param enc_param;
1783 enum jpeg_frame_format inFormat = YUV_422;
1784 enum jpeg_stream_format outFormat = JPEG_422;
1785
1786 switch (m_snapshot_v4lformat) {
1787 case V4L2_PIX_FMT_NV12:
1788 case V4L2_PIX_FMT_NV21:
1789 case V4L2_PIX_FMT_NV12T:
1790 case V4L2_PIX_FMT_YUV420:
1791 inFormat = YUV_420;
1792 outFormat = JPEG_420;
1793 break;
1794 case V4L2_PIX_FMT_YUYV:
1795 case V4L2_PIX_FMT_UYVY:
1796 case V4L2_PIX_FMT_YUV422P:
1797 default:
1798 inFormat = YUV_422;
1799 outFormat = JPEG_422;
1800 break;
1801 }
1802
1803 // set encode parameters //
1804 enc_param.width = m_jpeg_thumbnail_width;
1805 enc_param.height = m_jpeg_thumbnail_width;
1806 enc_param.in_fmt = inFormat; // YCBCR Only
1807 enc_param.out_fmt = outFormat;
1808
1809 if (m_jpeg_thumbnail_quality >= 90)
1810 enc_param.quality = QUALITY_LEVEL_1;
1811 else if (m_jpeg_thumbnail_quality >= 80)
1812 enc_param.quality = QUALITY_LEVEL_2;
1813 else if (m_jpeg_thumbnail_quality >= 70)
1814 enc_param.quality = QUALITY_LEVEL_3;
1815 else
1816 enc_param.quality = QUALITY_LEVEL_4;
1817
1818 api_jpeg_set_encode_param(&enc_param);
1819
1820 unsigned int thumbnail_size = m_jpeg_thumbnail_width * m_jpeg_thumbnail_height * 2;
1821 unsigned char *pInBuf = (unsigned char *)api_jpeg_get_encode_in_buf(m_jpeg_fd, thumbnail_size);
1822 if (pInBuf == NULL) {
1823 LOGE("ERR(%s):JPEG input buffer is NULL!!", __func__);
1824 return -1;
1825 }
1826
1827 unsigned char *pOutBuf = (unsigned char *)api_jpeg_get_encode_out_buf(m_jpeg_fd);
1828 if (pOutBuf == NULL) {
1829 LOGE("ERR(%s):JPEG output buffer is NULL!!", __func__);
1830 return -1;
1831 }
1832
1833 memcpy(pInBuf, pThumbSrc, thumbnail_size);
1834
1835 enum jpeg_ret_type result = api_jpeg_encode_exe(m_jpeg_fd, &enc_param);
1836 if (result != JPEG_ENCODE_OK) {
1837 LOGE("ERR(%s):encode failed", __func__);
1838 return -1;
1839 }
1840
1841 unsigned int outbuf_size = enc_param.size;
1842 unsigned int exifSize;
1843
1844 setExifChangedAttribute();
1845
1846 LOGV("%s: calling jpgEnc.makeExif, mExifInfo.width set to %d, height to %d",
1847 __func__, mExifInfo.width, mExifInfo.height);
1848
1849 LOGV("%s : enableThumb set to true", __func__);
1850 mExifInfo.enableThumb = true;
1851
1852 makeExif(pExifDst, pOutBuf, outbuf_size, &mExifInfo, &exifSize, true);
1853#endif
1854
1855#ifdef SAMSUNG_EXYNOS4x12
1856 /* JPEG encode for smdk4x12 */
1857 unsigned int exifSize;
1858
1859 if (m_camera_use_ISP) {
1860 LOGV("%s : m_jpeg_thumbnail_width = %d, height = %d",
1861 __func__, m_jpeg_thumbnail_width, m_jpeg_thumbnail_height);
1862 m_jpeg_fd = jpeghal_enc_init();
1863 LOGV("(%s):JPEG device open ID = %d", __func__, m_jpeg_fd);
1864
1865 if (m_jpeg_fd <= 0) {
1866 if (m_jpeg_fd < 0) {
1867 m_jpeg_fd = 0;
1868 LOGE("ERR(%s):Cannot open a jpeg device file", __func__);
1869 return -1;
1870 }
1871 LOGE("ERR(%s):JPEG device was closed", __func__);
1872 return -1;
1873 }
1874
1875 if (m_snapshot_v4lformat == V4L2_PIX_FMT_RGB565) {
1876 LOGE("ERR(%s):It doesn't support V4L2_PIX_FMT_RGB565", __func__);
1877 return -1;
1878 }
1879
1880 struct jpeg_config enc_config;
1881 int outFormat;
1882
1883 switch (m_snapshot_v4lformat) {
1884 case V4L2_PIX_FMT_NV12:
1885 case V4L2_PIX_FMT_NV21:
1886 case V4L2_PIX_FMT_NV12T:
1887 case V4L2_PIX_FMT_YUV420:
1888 outFormat = V4L2_PIX_FMT_JPEG_420;
1889 break;
1890 case V4L2_PIX_FMT_YUYV:
1891 case V4L2_PIX_FMT_UYVY:
1892 case V4L2_PIX_FMT_YUV422P:
1893 default:
1894 outFormat = V4L2_PIX_FMT_JPEG_422;
1895 break;
1896 }
1897
1898 // set encode parameters //
1899 enc_config.mode = JPEG_ENCODE;
1900
1901 if (m_jpeg_thumbnail_quality >= 90)
1902 enc_config.enc_qual = QUALITY_LEVEL_1;
1903 else if (m_jpeg_thumbnail_quality >= 80)
1904 enc_config.enc_qual = QUALITY_LEVEL_2;
1905 else if (m_jpeg_thumbnail_quality >= 70)
1906 enc_config.enc_qual = QUALITY_LEVEL_3;
1907 else
1908 enc_config.enc_qual = QUALITY_LEVEL_4;
1909
1910 enc_config.width = m_jpeg_thumbnail_width;
1911 enc_config.height = m_jpeg_thumbnail_height;
1912 enc_config.pix.enc_fmt.in_fmt = m_snapshot_v4lformat;
1913 enc_config.pix.enc_fmt.out_fmt = outFormat;
1914
1915 jpeghal_enc_setconfig(m_jpeg_fd, &enc_config);
1916
1917 jpeghal_s_ctrl(m_jpeg_fd, V4L2_CID_CACHEABLE, 1);
1918
1919 struct jpeg_buf m_jpeg_inbuf;
1920 m_jpeg_inbuf.memory = V4L2_MEMORY_MMAP;
1921 m_jpeg_inbuf.num_planes = 1;
1922
1923 if (jpeghal_set_inbuf(m_jpeg_fd, &m_jpeg_inbuf) < 0) {
1924 LOGE("ERR(%s):Fail to JPEG input buffer!!", __func__);
1925 return -1;
1926 }
1927
1928 struct jpeg_buf m_jpeg_outbuf;
1929 m_jpeg_outbuf.memory = V4L2_MEMORY_MMAP;
1930 m_jpeg_outbuf.num_planes = 1;
1931
1932 if (jpeghal_set_outbuf(m_jpeg_fd, &m_jpeg_outbuf) < 0) {
1933 LOGE("ERR(%s):Fail to JPEG output buffer!!", __func__);
1934 return -1;
1935 }
1936
1937 memcpy(m_jpeg_inbuf.start[0], pThumbSrc, m_jpeg_inbuf.length[0]);
1938
1939 if (jpeghal_enc_exe(m_jpeg_fd, &m_jpeg_inbuf, &m_jpeg_outbuf) < 0) {
1940 LOGE("ERR(%s):encode failed", __func__);
1941 return -1;
1942 }
1943
1944 int outbuf_size = jpeghal_g_ctrl(m_jpeg_fd, V4L2_CID_CAM_JPEG_ENCODEDSIZE);
1945 if (outbuf_size < 0) {
1946 LOGE("ERR(%s): jpeghal_g_ctrl fail on V4L2_CID_CAM_JPEG_ENCODEDSIZE", __func__);
1947 return -1;
1948 }
1949
1950 setExifChangedAttribute();
1951
1952 LOGV("%s: calling jpgEnc.makeExif, mExifInfo.width set to %d, height to %d",
1953 __func__, mExifInfo.width, mExifInfo.height);
1954
1955 LOGV("%s : enableThumb set to true", __func__);
1956 mExifInfo.enableThumb = true;
1957
1958 makeExif(pExifDst, (unsigned char *)m_jpeg_outbuf.start[0], (unsigned int)outbuf_size, &mExifInfo, &exifSize, true);
1959
1960 if (m_jpeg_fd > 0) {
1961 if (jpeghal_deinit(m_jpeg_fd, &m_jpeg_inbuf, &m_jpeg_outbuf) < 0)
1962 LOGE("ERR(%s):Fail on api_jpeg_encode_deinit", __func__);
1963 m_jpeg_fd = 0;
1964 }
1965 } else {
1966 setExifChangedAttribute();
1967 mExifInfo.enableThumb = true;
1968 makeExif(pExifDst, pThumbSrc, (unsigned int)thumbSize, &mExifInfo, &exifSize, true);
1969 }
1970#endif
1971
1972 return exifSize;
1973}
1974
1975void SecCamera::getPostViewConfig(int *width, int *height, int *size)
1976{
1977 *width = m_snapshot_width;
1978 *height = m_snapshot_height;
1979 *size = FRAME_SIZE(V4L2_PIX_2_HAL_PIXEL_FORMAT(m_snapshot_v4lformat), *width, *height);
1980 LOGV("[5B] m_preview_width : %d, mPostViewWidth = %d mPostViewHeight = %d mPostViewSize = %d",
1981 m_preview_width, *width, *height, *size);
1982}
1983
1984void SecCamera::getThumbnailConfig(int *width, int *height, int *size)
1985{
1986 *width = m_jpeg_thumbnail_width;
1987 *height = m_jpeg_thumbnail_height;
1988 *size = FRAME_SIZE(V4L2_PIX_2_HAL_PIXEL_FORMAT(m_snapshot_v4lformat), *width, *height);
1989}
1990
1991int SecCamera::getPostViewOffset(void)
1992{
1993 return m_postview_offset;
1994}
1995
1996int SecCamera::getSnapshotAndJpeg(SecBuffer *yuv_buf, int index, unsigned char *jpeg_buf,
1997 int *output_size)
1998{
1999 LOGV("%s :", __func__);
2000
2001 int ret = 0;
2002 int i;
2003
2004#ifdef ZERO_SHUTTER_LAG
2005 if (!m_camera_use_ISP){
2006 startSnapshot(yuv_buf);
2007
2008 index = getSnapshot();
2009 if (index < 0) {
2010 LOGE("ERR(%s): Invalid index!", __func__);
2011 return -1;
2012 }
2013
2014#ifndef BOARD_USE_V4L2_ION
2015 ret = fimc_v4l2_s_ctrl(m_cap_fd, V4L2_CID_STREAM_PAUSE, 0);
2016 CHECK_PTR(ret);
2017 LOGV("snapshot dequeued buffer = %d snapshot_width = %d snapshot_height = %d",
2018 index, m_snapshot_width, m_snapshot_height);
2019
2020 getCaptureAddr(index, yuv_buf);
2021#endif
2022
2023 if (yuv_buf->virt.extP[0] == NULL) {
2024 LOGE("ERR(%s):Fail on SecCamera getCaptureAddr = %0x ",
2025 __func__, yuv_buf->virt.extP[0]);
2026 return UNKNOWN_ERROR;
2027 }
2028 }
2029#else
2030 startSnapshot(yuv_buf);
2031
2032 index = getSnapshot();
2033 if (index < 0) {
2034 LOGE("ERR(%s): Invalid index!", __func__);
2035 return -1;
2036 }
2037
2038#ifndef BOARD_USE_V4L2_ION
2039 ret = fimc_v4l2_s_ctrl(m_cap_fd, V4L2_CID_STREAM_PAUSE, 0);
2040 CHECK_PTR(ret);
2041 LOGV("snapshot dequeued buffer = %d snapshot_width = %d snapshot_height = %d",
2042 index, m_snapshot_width, m_snapshot_height);
2043
2044 getCaptureAddr(index, yuv_buf);
2045#endif
2046
2047 if (yuv_buf->virt.extP[0] == NULL) {
2048 LOGE("ERR(%s):Fail on SecCamera getCaptureAddr = %0x ",
2049 __func__, yuv_buf->virt.extP[0]);
2050 return UNKNOWN_ERROR;
2051 }
2052#endif
2053
2054#ifdef SAMSUNG_EXYNOS4210
2055 /* JPEG encode for smdkv310 */
2056 if (m_jpeg_fd > 0) {
2057 if (api_jpeg_encode_deinit(m_jpeg_fd) != JPEG_OK)
2058 LOGE("ERR(%s):Fail on api_jpeg_encode_deinit", __func__);
2059 m_jpeg_fd = 0;
2060 }
2061
2062 m_jpeg_fd = api_jpeg_encode_init();
2063 LOGV("(%s):JPEG device open ID = %d", __func__, m_jpeg_fd);
2064
2065 if (m_jpeg_fd <= 0) {
2066 if (m_jpeg_fd < 0) {
2067 m_jpeg_fd = 0;
2068 LOGE("ERR(%s):Cannot open a jpeg device file", __func__);
2069 return -1;
2070 }
2071 LOGE("ERR(%s):JPEG device was closed", __func__);
2072 return -1;
2073 }
2074
2075 if (m_snapshot_v4lformat == V4L2_PIX_FMT_RGB565) {
2076 LOGE("ERR(%s):It doesn't support V4L2_PIX_FMT_RGB565", __func__);
2077 return -1;
2078 }
2079
2080 struct jpeg_enc_param enc_param;
2081 enum jpeg_frame_format inFormat = YUV_422;
2082 enum jpeg_stream_format outFormat = JPEG_422;
2083
2084 switch (m_snapshot_v4lformat) {
2085 case V4L2_PIX_FMT_NV12:
2086 case V4L2_PIX_FMT_NV21:
2087 case V4L2_PIX_FMT_NV12T:
2088 case V4L2_PIX_FMT_YUV420:
2089 inFormat = YUV_420;
2090 outFormat = JPEG_420;
2091 break;
2092 case V4L2_PIX_FMT_YUYV:
2093 case V4L2_PIX_FMT_UYVY:
2094 case V4L2_PIX_FMT_YUV422P:
2095 default:
2096 inFormat = YUV_422;
2097 outFormat = JPEG_422;
2098 break;
2099 }
2100
2101 // set encode parameters //
2102 enc_param.width = m_snapshot_width;
2103 enc_param.height = m_snapshot_height;
2104 enc_param.in_fmt = inFormat; // YCBCR Only
2105 enc_param.out_fmt = outFormat;
2106
2107 if (m_jpeg_quality >= 90)
2108 enc_param.quality = QUALITY_LEVEL_1;
2109 else if (m_jpeg_quality >= 80)
2110 enc_param.quality = QUALITY_LEVEL_2;
2111 else if (m_jpeg_quality >= 70)
2112 enc_param.quality = QUALITY_LEVEL_3;
2113 else
2114 enc_param.quality = QUALITY_LEVEL_4;
2115
2116 api_jpeg_set_encode_param(&enc_param);
2117
2118 unsigned int snapshot_size = m_snapshot_width * m_snapshot_height * 2;
2119 unsigned char *pInBuf = (unsigned char *)api_jpeg_get_encode_in_buf(m_jpeg_fd, snapshot_size);
2120 if (pInBuf == NULL) {
2121 LOGE("ERR(%s):JPEG input buffer is NULL!!", __func__);
2122 return -1;
2123 }
2124
2125 unsigned char *pOutBuf = (unsigned char *)api_jpeg_get_encode_out_buf(m_jpeg_fd);
2126 if (pOutBuf == NULL) {
2127 LOGE("ERR(%s):JPEG output buffer is NULL!!", __func__);
2128 return -1;
2129 }
2130
2131 memcpy(pInBuf, yuv_buf->virt.extP[0], snapshot_size);
2132
2133 enum jpeg_ret_type result = api_jpeg_encode_exe(m_jpeg_fd, &enc_param);
2134 if (result != JPEG_ENCODE_OK) {
2135 LOGE("ERR(%s):encode failed", __func__);
2136 return -1;
2137 }
2138
2139 *output_size = enc_param.size;
2140 memcpy(jpeg_buf, pOutBuf, *output_size);
2141#endif
2142
2143#ifdef SAMSUNG_EXYNOS4x12
2144 /* JPEG encode for smdk4x12 */
2145 m_jpeg_fd = jpeghal_enc_init();
2146 LOGV("(%s):JPEG device open ID = %d", __func__, m_jpeg_fd);
2147
2148 if (m_jpeg_fd <= 0) {
2149 if (m_jpeg_fd < 0) {
2150 m_jpeg_fd = 0;
2151 LOGE("ERR(%s):Cannot open a jpeg device file", __func__);
2152 return -1;
2153 }
2154 LOGE("ERR(%s):JPEG device was closed", __func__);
2155 return -1;
2156 }
2157
2158 if (m_snapshot_v4lformat == V4L2_PIX_FMT_RGB565) {
2159 LOGE("ERR(%s):It doesn't support V4L2_PIX_FMT_RGB565", __func__);
2160 return -1;
2161 }
2162
2163 struct jpeg_config enc_config;
2164 int outFormat;
2165
2166 switch (m_snapshot_v4lformat) {
2167 case V4L2_PIX_FMT_NV12:
2168 case V4L2_PIX_FMT_NV21:
2169 case V4L2_PIX_FMT_NV12T:
2170 case V4L2_PIX_FMT_YUV420:
2171 outFormat = V4L2_PIX_FMT_JPEG_420;
2172 break;
2173 case V4L2_PIX_FMT_YUYV:
2174 case V4L2_PIX_FMT_UYVY:
2175 case V4L2_PIX_FMT_YUV422P:
2176 default:
2177 outFormat = V4L2_PIX_FMT_JPEG_422;
2178 break;
2179 }
2180
2181 // set encode parameters //
2182 enc_config.mode = JPEG_ENCODE;
2183
2184 if (m_jpeg_quality >= 90)
2185 enc_config.enc_qual = QUALITY_LEVEL_1;
2186 else if (m_jpeg_quality >= 80)
2187 enc_config.enc_qual = QUALITY_LEVEL_2;
2188 else if (m_jpeg_quality >= 70)
2189 enc_config.enc_qual = QUALITY_LEVEL_3;
2190 else
2191 enc_config.enc_qual = QUALITY_LEVEL_4;
2192
2193 if (!m_recording_en) {
2194 enc_config.width = m_snapshot_width;
2195 enc_config.height = m_snapshot_height;
2196 } else {
2197 enc_config.width = m_videosnapshot_width;
2198 enc_config.height = m_videosnapshot_height;
2199 }
2200 enc_config.pix.enc_fmt.in_fmt = m_snapshot_v4lformat;
2201 enc_config.pix.enc_fmt.out_fmt = outFormat;
2202
2203 jpeghal_enc_setconfig(m_jpeg_fd, &enc_config);
2204
2205 ret = jpeghal_s_ctrl(m_jpeg_fd, V4L2_CID_CACHEABLE, 3);
2206 CHECK(ret);
2207
2208 struct jpeg_buf m_jpeg_inbuf;
2209#ifdef BOARD_USE_V4L2_ION
2210 m_jpeg_inbuf.memory = V4L2_MEMORY_MMAP;
2211 m_jpeg_inbuf.num_planes = 1;
2212#else
2213 m_jpeg_inbuf.start[0] = (void *)fimc_v4l2_s_ctrl(m_cap_fd, V4L2_CID_PADDR_Y, index);
2214 m_jpeg_inbuf.length[0] = m_capture_buf[index].size.extS[0];
2215 m_jpeg_inbuf.memory = V4L2_MEMORY_USERPTR;
2216 m_jpeg_inbuf.num_planes = 1;
2217#endif
2218
2219 if (jpeghal_set_inbuf(m_jpeg_fd, &m_jpeg_inbuf) < 0) {
2220 LOGE("ERR(%s):Fail to JPEG input buffer!!", __func__);
2221 return -1;
2222 }
2223
2224 for (i = 0; i < m_jpeg_inbuf.num_planes; i++) {
2225 if ((unsigned int)m_jpeg_inbuf.start[i] & (SIZE_4K - 1)) {
2226 LOGE("ERR(%s): JPEG start address should be aligned to 4 Kbytes", __func__);
2227 return -1;
2228 } else if ((unsigned int)enc_config.width & (16 - 1)) {
2229 LOGE("ERR(%s): Image width should be multiple of 16", __func__);
2230 return -1;
2231 }
2232 }
2233
2234 struct jpeg_buf m_jpeg_outbuf;
2235 m_jpeg_outbuf.memory = V4L2_MEMORY_MMAP;
2236 m_jpeg_outbuf.num_planes = 1;
2237
2238 if (jpeghal_set_outbuf(m_jpeg_fd, &m_jpeg_outbuf) < 0) {
2239 LOGE("ERR(%s):Fail to JPEG output buffer!!", __func__);
2240 return -1;
2241 }
2242
2243#ifdef BOARD_USE_V4L2_ION
2244 memcpy(m_jpeg_inbuf.start[0], yuv_buf->virt.extP[0], m_jpeg_inbuf.length[0]);
2245#endif
2246
2247 if (jpeghal_enc_exe(m_jpeg_fd, &m_jpeg_inbuf, &m_jpeg_outbuf) < 0) {
2248 LOGE("ERR(%s):encode failed", __func__);
2249 return -1;
2250 }
2251
2252 ret = jpeghal_g_ctrl(m_jpeg_fd, V4L2_CID_CAM_JPEG_ENCODEDSIZE);
2253 if (ret < 0) {
2254 LOGE("ERR(%s): jpeghal_g_ctrl fail on V4L2_CID_CAM_JPEG_ENCODEDSIZE", __func__);
2255 return -1;
2256 } else {
2257 *output_size = (unsigned int)ret;
2258 }
2259
2260 memcpy(jpeg_buf, m_jpeg_outbuf.start[0], *output_size);
2261
2262 if (m_jpeg_fd > 0) {
2263 if (jpeghal_deinit(m_jpeg_fd, &m_jpeg_inbuf, &m_jpeg_outbuf) < 0)
2264 LOGE("ERR(%s):Fail on api_jpeg_encode_deinit", __func__);
2265 m_jpeg_fd = 0;
2266 }
2267#endif
2268
2269 return 0;
2270}
2271
2272int SecCamera::setVideosnapshotSize(int width, int height)
2273{
2274 LOGV("%s(width(%d), height(%d))", __func__, width, height);
2275
2276 m_videosnapshot_width = width;
2277 m_videosnapshot_height = height;
2278
2279 return 0;
2280}
2281
2282int SecCamera::getVideosnapshotSize(int *width, int *height, int *frame_size)
2283{
2284 *width = m_videosnapshot_width;
2285 *height = m_videosnapshot_height;
2286
2287 int frame = 0;
2288
2289 frame = FRAME_SIZE(V4L2_PIX_2_HAL_PIXEL_FORMAT(m_snapshot_v4lformat), *width, *height);
2290
2291 // set it big.
2292 if (frame == 0)
2293 frame = m_videosnapshot_width * m_videosnapshot_height * BPP;
2294
2295 *frame_size = frame;
2296
2297 return 0;
2298}
2299
2300int SecCamera::setSnapshotSize(int width, int height)
2301{
2302 LOGV("%s(width(%d), height(%d))", __func__, width, height);
2303
2304 m_snapshot_width = width;
2305 m_snapshot_height = height;
2306
2307 return 0;
2308}
2309
2310int SecCamera::getSnapshotSize(int *width, int *height, int *frame_size)
2311{
2312 *width = m_snapshot_width;
2313 *height = m_snapshot_height;
2314
2315 int frame = 0;
2316
2317 frame = FRAME_SIZE(V4L2_PIX_2_HAL_PIXEL_FORMAT(m_snapshot_v4lformat), *width, *height);
2318
2319 // set it big.
2320 if (frame == 0)
2321 frame = m_snapshot_width * m_snapshot_height * BPP;
2322
2323 *frame_size = frame;
2324
2325 return 0;
2326}
2327
2328int SecCamera::getSnapshotMaxSize(int *width, int *height)
2329{
2330 *width = m_snapshot_max_width;
2331 *height = m_snapshot_max_height;
2332
2333 return 0;
2334}
2335
2336int SecCamera::setSnapshotPixelFormat(int pixel_format)
2337{
2338 int v4lpixelformat = pixel_format;
2339
2340 if (m_snapshot_v4lformat != v4lpixelformat) {
2341 m_snapshot_v4lformat = v4lpixelformat;
2342 }
2343
2344#if defined(LOG_NDEBUG) && LOG_NDEBUG == 0
2345 if (m_snapshot_v4lformat == V4L2_PIX_FMT_YUV420)
2346 LOGE("%s : SnapshotFormat:V4L2_PIX_FMT_YUV420", __func__);
2347 else if (m_snapshot_v4lformat == V4L2_PIX_FMT_NV12)
2348 LOGD("%s : SnapshotFormat:V4L2_PIX_FMT_NV12", __func__);
2349 else if (m_snapshot_v4lformat == V4L2_PIX_FMT_NV12T)
2350 LOGD("%s : SnapshotFormat:V4L2_PIX_FMT_NV12T", __func__);
2351 else if (m_snapshot_v4lformat == V4L2_PIX_FMT_NV21)
2352 LOGD("%s : SnapshotFormat:V4L2_PIX_FMT_NV21", __func__);
2353 else if (m_snapshot_v4lformat == V4L2_PIX_FMT_YUV422P)
2354 LOGD("%s : SnapshotFormat:V4L2_PIX_FMT_YUV422P", __func__);
2355 else if (m_snapshot_v4lformat == V4L2_PIX_FMT_YUYV)
2356 LOGD("%s : SnapshotFormat:V4L2_PIX_FMT_YUYV", __func__);
2357 else if (m_snapshot_v4lformat == V4L2_PIX_FMT_UYVY)
2358 LOGD("%s : SnapshotFormat:V4L2_PIX_FMT_UYVY", __func__);
2359 else if (m_snapshot_v4lformat == V4L2_PIX_FMT_RGB565)
2360 LOGD("%s : SnapshotFormat:V4L2_PIX_FMT_RGB565", __func__);
2361 else
2362 LOGD("SnapshotFormat:UnknownFormat");
2363#endif
2364 return 0;
2365}
2366
2367int SecCamera::getSnapshotPixelFormat(void)
2368{
2369 return m_snapshot_v4lformat;
2370}
2371
2372int SecCamera::getCameraId(void)
2373{
2374 return m_camera_id;
2375}
2376
2377int SecCamera::initSetParams(void)
2378{
2379 LOGV("%s :", __func__);
2380
2381 if (m_cam_fd <= 0) {
2382 LOGE("ERR(%s):Camera was closed", __func__);
2383 return -1;
2384 }
2385
2386 if (fimc_v4l2_s_ctrl(m_cam_fd, V4L2_CID_CAMERA_ISO, ISO_AUTO) < 0) {
2387 LOGE("ERR(%s):Fail on V4L2_CID_CAMERA_ISO", __func__);
2388 return -1;
2389 }
2390 if (fimc_v4l2_s_ctrl(m_cam_fd, V4L2_CID_CAMERA_METERING, METERING_CENTER) < 0) {
2391 LOGE("ERR(%s):Fail on V4L2_CID_CAMERA_METERING", __func__);
2392 return -1;
2393 }
2394 if (fimc_v4l2_s_ctrl(m_cam_fd, V4L2_CID_CAMERA_SATURATION, SATURATION_DEFAULT) < 0) {
2395 LOGE("ERR(%s):Fail on V4L2_CID_CAMERA_SATURATION", __func__);
2396 return -1;
2397 }
2398 if (fimc_v4l2_s_ctrl(m_cam_fd, V4L2_CID_CAMERA_SCENE_MODE, SCENE_MODE_NONE) < 0) {
2399 LOGE("ERR(%s):Fail on V4L2_CID_CAMERA_SCENE_MODE", __func__);
2400 return -1;
2401 }
2402 if (fimc_v4l2_s_ctrl(m_cam_fd, V4L2_CID_CAMERA_SHARPNESS, SHARPNESS_DEFAULT) < 0) {
2403 LOGE("ERR(%s):Fail on V4L2_CID_CAMERA_SHARPNESS", __func__);
2404 return -1;
2405 }
2406 if (fimc_v4l2_s_ctrl(m_cam_fd, V4L2_CID_CAMERA_WHITE_BALANCE, WHITE_BALANCE_AUTO) < 0) {
2407 LOGE("ERR(%s):Fail on V4L2_CID_CAMERA_WHITE_BALANCE", __func__);
2408 return -1;
2409 }
2410 if (fimc_v4l2_s_ctrl(m_cam_fd, V4L2_CID_CAMERA_ANTI_BANDING, ANTI_BANDING_OFF) < 0) {
2411 LOGE("ERR(%s):Fail on V4L2_CID_CAMERA_ANTI_BANDING", __func__);
2412 return -1;
2413 }
2414 if (fimc_v4l2_s_ctrl(m_cam_fd, V4L2_CID_IS_CAMERA_CONTRAST, IS_CONTRAST_DEFAULT) < 0) {
2415 LOGE("ERR(%s):Fail on V4L2_CID_IS_CAMERA_CONTRAST", __func__);
2416 return -1;
2417 }
2418 if (fimc_v4l2_s_ctrl(m_cam_fd, V4L2_CID_CAMERA_EFFECT, IMAGE_EFFECT_NONE) < 0) {
2419 LOGE("ERR(%s):Fail on V4L2_CID_CAMERA_EFFECT", __func__);
2420 return -1;
2421 }
2422 if (fimc_v4l2_s_ctrl(m_cam_fd, V4L2_CID_IS_CAMERA_BRIGHTNESS, IS_BRIGHTNESS_DEFAULT) < 0) {
2423 LOGE("ERR(%s):Fail on V4L2_CID_IS_CAMERA_BRIGHTNESS", __func__);
2424 return -1;
2425 }
2426 if (fimc_v4l2_s_ctrl(m_cam_fd, V4L2_CID_IS_CAMERA_EXPOSURE, IS_EXPOSURE_DEFAULT) < 0) {
2427 LOGE("ERR(%s):Fail on V4L2_CID_IS_CAMERA_EXPOSURE", __func__);
2428 return -1;
2429 }
2430/* TODO */
2431/* This code is temporary implementation because *
2432 * hue value tuning was not complete */
2433#ifdef USE_HUE
2434 if (fimc_v4l2_s_ctrl(m_cam_fd, V4L2_CID_IS_CAMERA_HUE, IS_HUE_DEFAULT) < 0) {
2435 LOGE("ERR(%s):Fail on V4L2_CID_IS_CAMERA_HUE", __func__);
2436 return -1;
2437 }
2438#endif
2439
2440 initParameters(m_camera_use_ISP);
2441
2442 return 0;
2443}
2444
2445int SecCamera::setAutofocus(void)
2446{
2447 LOGV("%s :", __func__);
2448
2449 if (m_cam_fd <= 0) {
2450 LOGE("ERR(%s):Camera was closed", __func__);
2451 return -1;
2452 }
2453
2454 if (fimc_v4l2_s_ctrl(m_cam_fd, V4L2_CID_CAMERA_SET_AUTO_FOCUS, AUTO_FOCUS_ON) < 0) {
2455 LOGE("ERR(%s):Fail on V4L2_CID_CAMERA_SET_AUTO_FOCUS", __func__);
2456 return -1;
2457 }
2458
2459 m_auto_focus_state = 1;
2460
2461 return 0;
2462}
2463
2464int SecCamera::setTouchAF(void)
2465{
2466 LOGV("%s :", __func__);
2467
2468 if (m_cam_fd <= 0) {
2469 LOGE("ERR(%s):Camera was closed", __func__);
2470 return -1;
2471 }
2472
2473 if (fimc_v4l2_s_ctrl(m_cam_fd, V4L2_CID_CAMERA_FOCUS_MODE, FOCUS_MODE_TOUCH) < 0) {
2474 LOGE("ERR(%s):Fail on V4L2_CID_CAMERA_FOCUS_MODE", __func__);
2475 return -1;
2476 }
2477
2478 return 0;
2479}
2480
2481int SecCamera::getAutoFocusResult(void)
2482{
2483 int af_result;
2484
2485 af_result = fimc_v4l2_g_ctrl(m_cam_fd, V4L2_CID_CAMERA_AUTO_FOCUS_RESULT);
2486
2487 LOGV("%s : returning %d", __func__, af_result);
2488
2489 return af_result;
2490}
2491
2492int SecCamera::cancelAutofocus(void)
2493{
2494 LOGV("%s :", __func__);
2495
2496 if (m_cam_fd <= 0) {
2497 LOGE("ERR(%s):Camera was closed", __func__);
2498 return -1;
2499 }
2500
2501#ifndef BOARD_USE_V4L2
2502 if (m_flag_camera_start && m_auto_focus_state) {
2503 if (m_params->focus_mode == FOCUS_MODE_AUTO || m_params->focus_mode == FOCUS_MODE_MACRO) {
2504 if (fimc_v4l2_s_ctrl(m_cam_fd, V4L2_CID_CAMERA_SET_AUTO_FOCUS, AUTO_FOCUS_OFF) < 0) {
2505 LOGE("ERR(%s):Fail on V4L2_CID_CAMERA_SET_AUTO_FOCUS", __func__);
2506 return -1;
2507 }
2508 }
2509 m_auto_focus_state = 0;
2510 }
2511#endif
2512
2513 return 0;
2514}
2515
2516int SecCamera::SetRotate(int angle)
2517{
2518 LOGE("%s(angle(%d))", __func__, angle);
2519
2520 if (m_angle != angle) {
2521 switch (angle) {
2522 case -360:
2523 case 0:
2524 case 360:
2525 m_angle = 0;
2526 break;
2527
2528 case -270:
2529 case 90:
2530 m_angle = 90;
2531 break;
2532
2533 case -180:
2534 case 180:
2535 m_angle = 180;
2536 break;
2537
2538 case -90:
2539 case 270:
2540 m_angle = 270;
2541 break;
2542
2543 default:
2544 LOGE("ERR(%s):Invalid angle(%d)", __func__, angle);
2545 return -1;
2546 }
2547
2548 if (m_flag_camera_create) {
2549 if (fimc_v4l2_s_ctrl(m_cam_fd, V4L2_CID_ROTATION, angle) < 0) {
2550 LOGE("ERR(%s):Fail on V4L2_CID_ROTATION", __func__);
2551 return -1;
2552 }
2553 m_angle = angle;
2554 }
2555 }
2556
2557 return 0;
2558}
2559
2560int SecCamera::getRotate(void)
2561{
2562 LOGV("%s : angle(%d)", __func__, m_angle);
2563 return m_angle;
2564}
2565
2566int SecCamera::setFrameRate(int frame_rate)
2567{
2568 LOGV("%s(FrameRate(%d))", __func__, frame_rate);
2569
2570 if (frame_rate < FRAME_RATE_AUTO || FRAME_RATE_MAX < frame_rate ) {
2571 LOGE("ERR(%s):Invalid frame_rate(%d)", __func__, frame_rate);
2572 return -1;
2573 }
2574
2575 if (m_params->capture.timeperframe.denominator != frame_rate) {
2576 if (m_flag_camera_create) {
2577 if (fimc_v4l2_s_ctrl(m_cam_fd, V4L2_CID_CAMERA_FRAME_RATE, frame_rate) < 0) {
2578 LOGE("ERR(%s):Fail on V4L2_CID_CAMERA_FRAME_RATE", __func__);
2579 return -1;
2580 }
2581 m_params->capture.timeperframe.denominator = frame_rate;
2582 }
2583 }
2584
2585 return 0;
2586}
2587
2588int SecCamera::setVerticalMirror(void)
2589{
2590 LOGV("%s :", __func__);
2591
2592 if (m_cam_fd <= 0) {
2593 LOGE("ERR(%s):Camera was closed", __func__);
2594 return -1;
2595 }
2596
2597 if (fimc_v4l2_s_ctrl(m_cam_fd, V4L2_CID_VFLIP, 0) < 0) {
2598 LOGE("ERR(%s):Fail on V4L2_CID_VFLIP", __func__);
2599 return -1;
2600 }
2601
2602 return 0;
2603}
2604
2605int SecCamera::setHorizontalMirror(void)
2606{
2607 LOGV("%s :", __func__);
2608
2609 if (m_cam_fd <= 0) {
2610 LOGE("ERR(%s):Camera was closed", __func__);
2611 return -1;
2612 }
2613
2614 if (fimc_v4l2_s_ctrl(m_cam_fd, V4L2_CID_HFLIP, 0) < 0) {
2615 LOGE("ERR(%s):Fail on V4L2_CID_HFLIP", __func__);
2616 return -1;
2617 }
2618
2619 return 0;
2620}
2621
2622int SecCamera::setWhiteBalance(int white_balance)
2623{
2624 LOGV("%s(white_balance(%d))", __func__, white_balance);
2625
2626 if (white_balance <= WHITE_BALANCE_BASE || WHITE_BALANCE_MAX <= white_balance) {
2627 LOGE("ERR(%s):Invalid white_balance(%d)", __func__, white_balance);
2628 return -1;
2629 }
2630
2631 if (m_params->white_balance != white_balance) {
2632 if (m_flag_camera_create) {
2633 LOGE("%s(white_balance(%d))", __func__, white_balance);
2634 if (fimc_v4l2_s_ctrl(m_cam_fd, V4L2_CID_CAMERA_WHITE_BALANCE, white_balance) < 0) {
2635 LOGE("ERR(%s):Fail on V4L2_CID_CAMERA_WHITE_BALANCE", __func__);
2636 return -1;
2637 }
2638 m_params->white_balance = white_balance;
2639 }
2640 }
2641
2642 return 0;
2643}
2644
2645int SecCamera::getWhiteBalance(void)
2646{
2647 LOGV("%s : white_balance(%d)", __func__, m_params->white_balance);
2648 return m_params->white_balance;
2649}
2650
2651int SecCamera::setBrightness(int brightness)
2652{
2653 LOGV("%s(brightness(%d))", __func__, brightness);
2654
2655 if (m_camera_use_ISP) {
2656 brightness += IS_BRIGHTNESS_DEFAULT;
2657 if (brightness < IS_BRIGHTNESS_MINUS_2 || IS_BRIGHTNESS_PLUS_2 < brightness) {
2658 LOGE("ERR(%s):Invalid brightness(%d)", __func__, brightness);
2659 return -1;
2660 }
2661 } else {
2662 LOGW("WARN(%s):Not supported brightness setting", __func__);
2663 return 0;
2664 }
2665
2666 if (m_params->brightness != brightness) {
2667 if (m_flag_camera_create) {
2668 if (fimc_v4l2_s_ctrl(m_cam_fd, V4L2_CID_IS_CAMERA_BRIGHTNESS, brightness) < EV_MINUS_4) {
2669 LOGE("ERR(%s):Fail on V4L2_CID_IS_CAMERA_BRIGHTNESS", __func__);
2670 return -1;
2671 }
2672 m_params->brightness = brightness;
2673 }
2674 }
2675
2676 return 0;
2677}
2678
2679int SecCamera::getBrightness(void)
2680{
2681 LOGV("%s : brightness(%d)", __func__, m_params->brightness);
2682 return m_params->brightness;
2683}
2684
2685int SecCamera::setExposure(int exposure)
2686{
2687 LOGV("%s(exposure(%d))", __func__, exposure);
2688
2689 if (m_camera_use_ISP) {
2690 exposure += IS_EXPOSURE_DEFAULT;
2691 if (exposure < IS_EXPOSURE_MINUS_4 || IS_EXPOSURE_PLUS_4 < exposure) {
2692 LOGE("ERR(%s):Invalid exposure(%d)", __func__, exposure);
2693 return -1;
2694 }
2695 } else {
2696 exposure += EV_DEFAULT;
2697 if (exposure < EV_MINUS_4 || EV_PLUS_4 < exposure) {
2698 LOGE("ERR(%s):Invalid exposure(%d)", __func__, exposure);
2699 return -1;
2700 }
2701 }
2702
2703 if (m_params->exposure != exposure) {
2704 if (m_flag_camera_create) {
2705 if (m_camera_use_ISP) {
2706 if (fimc_v4l2_s_ctrl(m_cam_fd, V4L2_CID_IS_CAMERA_EXPOSURE, exposure) < 0) {
2707 LOGE("ERR(%s):Fail on V4L2_CID_IS_CAMERA_EXPOSURE", __func__);
2708 return -1;
2709 }
2710 } else {
2711 if (fimc_v4l2_s_ctrl(m_cam_fd, V4L2_CID_CAMERA_BRIGHTNESS, exposure) < EV_MINUS_4) {
2712 LOGE("ERR(%s):Fail on V4L2_CID_CAMERA_BRIGHTNESS", __func__);
2713 return -1;
2714 }
2715 }
2716 m_params->exposure = exposure;
2717 }
2718 }
2719
2720 return 0;
2721}
2722
2723int SecCamera::getExposure(void)
2724{
2725 LOGV("%s : exposure(%d)", __func__, m_params->exposure);
2726 return m_params->exposure;
2727}
2728
2729int SecCamera::setImageEffect(int image_effect)
2730{
2731 LOGV("%s(image_effect(%d))", __func__, image_effect);
2732
2733 if (image_effect <= IMAGE_EFFECT_BASE || IMAGE_EFFECT_MAX <= image_effect) {
2734 LOGE("ERR(%s):Invalid image_effect(%d)", __func__, image_effect);
2735 return -1;
2736 }
2737
2738 if (m_params->effects != image_effect) {
2739 if (m_flag_camera_create) {
2740 if (fimc_v4l2_s_ctrl(m_cam_fd, V4L2_CID_CAMERA_EFFECT, image_effect) < 0) {
2741 LOGE("ERR(%s):Fail on V4L2_CID_CAMERA_EFFECT", __func__);
2742 return -1;
2743 }
2744 m_params->effects = image_effect;
2745 }
2746 }
2747
2748 return 0;
2749}
2750
2751int SecCamera::getImageEffect(void)
2752{
2753 LOGV("%s : image_effect(%d)", __func__, m_params->effects);
2754 return m_params->effects;
2755}
2756
2757int SecCamera::setAntiBanding(int anti_banding)
2758{
2759 LOGV("%s(anti_banding(%d))", __func__, anti_banding);
2760
2761 if (anti_banding < ANTI_BANDING_AUTO || ANTI_BANDING_OFF < anti_banding) {
2762 LOGE("ERR(%s):Invalid anti_banding (%d)", __func__, anti_banding);
2763 return -1;
2764 }
2765
2766 if (m_params->anti_banding != anti_banding) {
2767 if (m_flag_camera_create) {
2768 if (fimc_v4l2_s_ctrl(m_cam_fd, V4L2_CID_CAMERA_ANTI_BANDING, anti_banding) < 0) {
2769 LOGE("ERR(%s):Fail on V4L2_CID_CAMERA_ANTI_BANDING", __func__);
2770 return -1;
2771 }
2772 m_params->anti_banding = anti_banding;
2773 }
2774 }
2775
2776 return 0;
2777}
2778
2779int SecCamera::setSceneMode(int scene_mode)
2780{
2781 LOGV("%s(scene_mode(%d))", __func__, scene_mode);
2782
2783 if (scene_mode <= SCENE_MODE_BASE || SCENE_MODE_MAX <= scene_mode) {
2784 LOGE("ERR(%s):Invalid scene_mode (%d)", __func__, scene_mode);
2785 return -1;
2786 }
2787
2788 if (m_params->scene_mode != scene_mode) {
2789 if (m_flag_camera_create) {
2790 LOGE("%s(scene_mode(%d))", __func__, scene_mode);
2791 if (fimc_v4l2_s_ctrl(m_cam_fd, V4L2_CID_CAMERA_SCENE_MODE, scene_mode) < 0) {
2792 LOGE("ERR(%s):Fail on V4L2_CID_CAMERA_SCENE_MODE", __func__);
2793 return -1;
2794 }
2795 m_params->scene_mode = scene_mode;
2796 }
2797 }
2798
2799 return 0;
2800}
2801
2802int SecCamera::getSceneMode(void)
2803{
2804 return m_params->scene_mode;
2805}
2806
2807int SecCamera::setFlashMode(int flash_mode)
2808{
2809 LOGV("%s(flash_mode(%d))", __func__, flash_mode);
2810
2811 if (flash_mode <= FLASH_MODE_BASE || FLASH_MODE_MAX <= flash_mode) {
2812 LOGE("ERR(%s):Invalid flash_mode (%d)", __func__, flash_mode);
2813 return -1;
2814 }
2815
2816 if (m_params->flash_mode != flash_mode) {
2817 if (m_flag_camera_create) {
2818 if (fimc_v4l2_s_ctrl(m_cam_fd, V4L2_CID_CAMERA_FLASH_MODE, flash_mode) < 0) {
2819 LOGE("ERR(%s):Fail on V4L2_CID_CAMERA_FLASH_MODE", __func__);
2820 return -1;
2821 }
2822 m_params->flash_mode = flash_mode;
2823 }
2824 }
2825
2826 return 0;
2827}
2828
2829int SecCamera::getFlashMode(void)
2830{
2831 return m_params->flash_mode;
2832}
2833
2834int SecCamera::setAutoExposureLock(int toggle)
2835{
2836 LOGV("%s(toggle value(%d))", __func__, toggle);
2837
2838 int aeawb_mode = m_params->aeawb_mode;
2839
2840 if (m_flag_camera_create) {
2841 if (toggle ^ aeawb_mode) {
2842 aeawb_mode = aeawb_mode ^ 0x1;
2843 m_params->aeawb_mode = aeawb_mode;
2844 if (fimc_v4l2_s_ctrl(m_cam_fd, V4L2_CID_CAMERA_AEAWB_LOCK_UNLOCK, aeawb_mode) < 0) {
2845 LOGE("ERR(%s):Fail on V4L2_CID_CAMERA_AEAWB_LOCK_UNLOCK", __func__);
2846 return -1;
2847 }
2848 }
2849 }
2850 return 0;
2851}
2852
2853int SecCamera::setAutoWhiteBalanceLock(int toggle)
2854{
2855 LOGV("%s(toggle value(%d))", __func__, toggle);
2856
2857 int aeawb_mode = m_params->aeawb_mode;
2858
2859 if (m_flag_camera_create) {
2860 if (toggle ^ (aeawb_mode >> 1)) {
2861 aeawb_mode = aeawb_mode ^ (0x1 << 1);
2862 m_params->aeawb_mode = aeawb_mode;
2863 if (fimc_v4l2_s_ctrl(m_cam_fd, V4L2_CID_CAMERA_AEAWB_LOCK_UNLOCK, aeawb_mode) < 0) {
2864 LOGE("ERR(%s):Fail on V4L2_CID_CAMERA_AEAWB_LOCK_UNLOCK", __func__);
2865 return -1;
2866 }
2867 }
2868 }
2869 return 0;
2870}
2871
2872int SecCamera::setISO(int iso_value)
2873{
2874 LOGV("%s(iso_value(%d))", __func__, iso_value);
2875
2876 if (iso_value < ISO_AUTO || ISO_MAX <= iso_value) {
2877 LOGE("ERR(%s):Invalid iso_value (%d)", __func__, iso_value);
2878 return -1;
2879 }
2880
2881 if (m_params->iso != iso_value) {
2882 if (m_flag_camera_create) {
2883 if (fimc_v4l2_s_ctrl(m_cam_fd, V4L2_CID_CAMERA_ISO, iso_value) < 0) {
2884 LOGE("ERR(%s):Fail on V4L2_CID_CAMERA_ISO", __func__);
2885 return -1;
2886 }
2887 m_params->iso = iso_value;
2888 }
2889 }
2890
2891 return 0;
2892}
2893
2894int SecCamera::getISO(void)
2895{
2896 return m_params->iso;
2897}
2898
2899int SecCamera::setContrast(int contrast_value)
2900{
2901 LOGV("%s(contrast_value(%d))", __func__, contrast_value);
2902
2903 if (m_camera_use_ISP) {
2904 if (contrast_value < IS_CONTRAST_AUTO || IS_CONTRAST_MAX <= contrast_value) {
2905 LOGE("ERR(%s):Invalid contrast_value (%d)", __func__, contrast_value);
2906 return -1;
2907 }
2908 } else {
2909 if (contrast_value < CONTRAST_MINUS_2 || CONTRAST_MAX <= contrast_value) {
2910 LOGE("ERR(%s):Invalid contrast_value (%d)", __func__, contrast_value);
2911 return -1;
2912 }
2913 }
2914
2915 if (m_params->contrast != contrast_value) {
2916 if (m_flag_camera_create) {
2917 if (m_camera_use_ISP) {
2918 if (fimc_v4l2_s_ctrl(m_cam_fd, V4L2_CID_IS_CAMERA_CONTRAST, contrast_value) < 0) {
2919 LOGE("ERR(%s):Fail on V4L2_CID_IS_CAMERA_CONTRAST", __func__);
2920 return -1;
2921 }
2922 } else {
2923 if (fimc_v4l2_s_ctrl(m_cam_fd, V4L2_CID_CAMERA_CONTRAST, contrast_value) < 0) {
2924 LOGE("ERR(%s):Fail on V4L2_CID_CAMERA_CONTRAST", __func__);
2925 return -1;
2926 }
2927 }
2928 m_params->contrast = contrast_value;
2929 }
2930 }
2931
2932 return 0;
2933}
2934
2935int SecCamera::getContrast(void)
2936{
2937 return m_params->contrast;
2938}
2939
2940int SecCamera::setSaturation(int saturation_value)
2941{
2942 LOGV("%s(saturation_value(%d))", __func__, saturation_value);
2943
2944 saturation_value += SATURATION_DEFAULT;
2945 if (saturation_value < SATURATION_MINUS_2 || SATURATION_MAX <= saturation_value) {
2946 LOGE("ERR(%s):Invalid saturation_value (%d)", __func__, saturation_value);
2947 return -1;
2948 }
2949
2950 if (m_params->saturation != saturation_value) {
2951 if (m_flag_camera_create) {
2952 if (fimc_v4l2_s_ctrl(m_cam_fd, V4L2_CID_CAMERA_SATURATION, saturation_value) < 0) {
2953 LOGE("ERR(%s):Fail on V4L2_CID_CAMERA_SATURATION", __func__);
2954 return -1;
2955 }
2956 m_params->saturation = saturation_value;
2957 }
2958 }
2959
2960 return 0;
2961}
2962
2963int SecCamera::getSaturation(void)
2964{
2965 return m_params->saturation;
2966}
2967
2968int SecCamera::setSharpness(int sharpness_value)
2969{
2970 LOGV("%s(sharpness_value(%d))", __func__, sharpness_value);
2971
2972 sharpness_value += SHARPNESS_DEFAULT;
2973 if (sharpness_value < SHARPNESS_MINUS_2 || SHARPNESS_MAX <= sharpness_value) {
2974 LOGE("ERR(%s):Invalid sharpness_value (%d)", __func__, sharpness_value);
2975 return -1;
2976 }
2977
2978 if (m_params->sharpness != sharpness_value) {
2979 if (m_flag_camera_create) {
2980 if (fimc_v4l2_s_ctrl(m_cam_fd, V4L2_CID_CAMERA_SHARPNESS, sharpness_value) < 0) {
2981 LOGE("ERR(%s):Fail on V4L2_CID_CAMERA_SHARPNESS", __func__);
2982 return -1;
2983 }
2984 m_params->sharpness = sharpness_value;
2985 }
2986 }
2987
2988 return 0;
2989}
2990
2991int SecCamera::getSharpness(void)
2992{
2993 return m_params->sharpness;
2994}
2995
2996int SecCamera::setHue(int hue_value)
2997{
2998 LOGV("%s(hue_value(%d))", __func__, hue_value);
2999
3000/* TODO */
3001/* This code is temporary implementation because *
3002 * hue value tuning was not complete */
3003#ifdef USE_HUE
3004 if (m_camera_use_ISP) {
3005 hue_value += IS_HUE_DEFAULT;
3006 if (hue_value < IS_HUE_MINUS_2 || IS_HUE_MAX <= hue_value) {
3007 LOGE("ERR(%s):Invalid hue_value (%d)", __func__, hue_value);
3008 return -1;
3009 }
3010 } else {
3011 LOGW("WARN(%s):Not supported hue setting", __func__);
3012 return 0;
3013 }
3014
3015 if (m_params->hue != hue_value) {
3016 if (m_flag_camera_create) {
3017 if (fimc_v4l2_s_ctrl(m_cam_fd, V4L2_CID_IS_CAMERA_HUE, hue_value) < 0) {
3018 LOGE("ERR(%s):Fail on V4L2_CID_CAMERA_HUE", __func__);
3019 return -1;
3020 }
3021 m_params->hue = hue_value;
3022 }
3023 }
3024#endif
3025
3026 return 0;
3027}
3028
3029int SecCamera::getHue(void)
3030{
3031 return m_params->hue;
3032}
3033
3034int SecCamera::setWDR(int wdr_value)
3035{
3036 LOGV("%s(wdr_value(%d))", __func__, wdr_value);
3037
3038 if (m_camera_use_ISP) {
3039 if (wdr_value < IS_DRC_BYPASS_DISABLE || IS_DRC_BYPASS_MAX <= wdr_value) {
3040 LOGE("ERR(%s):Invalid drc_value (%d)", __func__, wdr_value);
3041 return -1;
3042 }
3043 } else {
3044 if (wdr_value < WDR_OFF || WDR_MAX <= wdr_value) {
3045 LOGE("ERR(%s):Invalid wdr_value (%d)", __func__, wdr_value);
3046 return -1;
3047 }
3048 }
3049
3050 if (m_wdr != wdr_value) {
3051 if (m_flag_camera_create) {
3052 if (m_camera_use_ISP) {
3053 if (fimc_v4l2_s_ctrl(m_cam_fd, V4L2_CID_IS_SET_DRC, wdr_value) < 0) {
3054 LOGE("ERR(%s):Fail on V4L2_CID_IS_SET_DRC", __func__);
3055 return -1;
3056 }
3057 } else {
3058 if (fimc_v4l2_s_ctrl(m_cam_fd, V4L2_CID_CAMERA_WDR, wdr_value) < 0) {
3059 LOGE("ERR(%s):Fail on V4L2_CID_CAMERA_WDR", __func__);
3060 return -1;
3061 }
3062 }
3063 m_wdr = wdr_value;
3064 }
3065 }
3066
3067 return 0;
3068}
3069
3070int SecCamera::getWDR(void)
3071{
3072 return m_wdr;
3073}
3074
3075int SecCamera::setAntiShake(int anti_shake)
3076{
3077 LOGV("%s(anti_shake(%d))", __func__, anti_shake);
3078
3079 if (anti_shake < ANTI_SHAKE_OFF || ANTI_SHAKE_MAX <= anti_shake) {
3080 LOGE("ERR(%s):Invalid anti_shake (%d)", __func__, anti_shake);
3081 return -1;
3082 }
3083
3084 if (m_anti_shake != anti_shake) {
3085 if (m_flag_camera_create) {
3086 if (fimc_v4l2_s_ctrl(m_cam_fd, V4L2_CID_CAMERA_ANTI_SHAKE, anti_shake) < 0) {
3087 LOGE("ERR(%s):Fail on V4L2_CID_CAMERA_ANTI_SHAKE", __func__);
3088 return -1;
3089 }
3090 m_anti_shake = anti_shake;
3091 }
3092 }
3093
3094 return 0;
3095}
3096
3097int SecCamera::getAntiShake(void)
3098{
3099 return m_anti_shake;
3100}
3101
3102int SecCamera::setMetering(int metering_value)
3103{
3104 LOGV("%s(metering (%d))", __func__, metering_value);
3105
3106 if (metering_value <= METERING_BASE || METERING_MAX <= metering_value) {
3107 LOGE("ERR(%s):Invalid metering_value (%d)", __func__, metering_value);
3108 return -1;
3109 }
3110
3111 if (m_params->metering != metering_value) {
3112 if (m_flag_camera_create) {
3113 if (fimc_v4l2_s_ctrl(m_cam_fd, V4L2_CID_CAMERA_METERING, metering_value) < 0) {
3114 LOGE("ERR(%s):Fail on V4L2_CID_CAMERA_METERING", __func__);
3115 return -1;
3116 }
3117 m_params->metering = metering_value;
3118 }
3119 }
3120
3121 return 0;
3122}
3123
3124int SecCamera::getMetering(void)
3125{
3126 return m_params->metering;
3127}
3128
3129int SecCamera::setJpegQuality(int jpeg_quality)
3130{
3131 LOGV("%s(jpeg_quality (%d))", __func__, jpeg_quality);
3132
3133 if (jpeg_quality < JPEG_QUALITY_ECONOMY || JPEG_QUALITY_MAX <= jpeg_quality) {
3134 LOGE("ERR(%s):Invalid jpeg_quality (%d)", __func__, jpeg_quality);
3135 return -1;
3136 }
3137
3138 if (m_jpeg_quality != jpeg_quality) {
3139 m_jpeg_quality = jpeg_quality;
3140 if (m_flag_camera_create && !m_camera_use_ISP) {
3141 jpeg_quality -= 5;
3142 if (fimc_v4l2_s_ctrl(m_cam_fd, V4L2_CID_CAM_JPEG_QUALITY, jpeg_quality) < 0) {
3143 LOGE("ERR(%s):Fail on V4L2_CID_CAM_JPEG_QUALITY", __func__);
3144 return -1;
3145 }
3146 }
3147 }
3148
3149 return 0;
3150}
3151
3152int SecCamera::getJpegQuality(void)
3153{
3154 return m_jpeg_quality;
3155}
3156
3157int SecCamera::setZoom(int zoom_level)
3158{
3159 LOGV("%s(zoom_level (%d))", __func__, zoom_level);
3160
3161 if (zoom_level < ZOOM_LEVEL_0 || ZOOM_LEVEL_MAX <= zoom_level) {
3162 LOGE("ERR(%s):Invalid zoom_level (%d)", __func__, zoom_level);
3163 return -1;
3164 }
3165
3166 if (m_zoom_level != zoom_level) {
3167 if (m_flag_camera_create) {
3168 if (fimc_v4l2_s_ctrl(m_cam_fd, V4L2_CID_CAMERA_ZOOM, zoom_level) < 0) {
3169 LOGE("ERR(%s):Fail on V4L2_CID_CAMERA_ZOOM", __func__);
3170 return -1;
3171 }
3172 m_zoom_level = zoom_level;
3173 }
3174 }
3175
3176 return 0;
3177}
3178
3179int SecCamera::getZoom(void)
3180{
3181 return m_zoom_level;
3182}
3183
3184int SecCamera::setObjectTracking(int object_tracking)
3185{
3186 LOGV("%s(object_tracking (%d))", __func__, object_tracking);
3187
3188 if (object_tracking < OBJECT_TRACKING_OFF || OBJECT_TRACKING_MAX <= object_tracking) {
3189 LOGE("ERR(%s):Invalid object_tracking (%d)", __func__, object_tracking);
3190 return -1;
3191 }
3192
3193 if (m_object_tracking != object_tracking)
3194 m_object_tracking = object_tracking;
3195
3196 return 0;
3197}
3198
3199int SecCamera::getObjectTracking(void)
3200{
3201 return m_object_tracking;
3202}
3203
3204int SecCamera::getObjectTrackingStatus(void)
3205{
3206 int obj_status = 0;
3207 obj_status = fimc_v4l2_g_ctrl(m_cam_fd, V4L2_CID_CAMERA_OBJ_TRACKING_STATUS);
3208 return obj_status;
3209}
3210
3211int SecCamera::setObjectTrackingStartStop(int start_stop)
3212{
3213 LOGV("%s(object_tracking_start_stop (%d))", __func__, start_stop);
3214
3215 if (m_object_tracking_start_stop != start_stop) {
3216 m_object_tracking_start_stop = start_stop;
3217 if (fimc_v4l2_s_ctrl(m_cam_fd, V4L2_CID_CAMERA_OBJ_TRACKING_START_STOP, start_stop) < 0) {
3218 LOGE("ERR(%s):Fail on V4L2_CID_CAMERA_OBJ_TRACKING_START_STOP", __func__);
3219 return -1;
3220 }
3221 }
3222
3223 return 0;
3224}
3225
3226int SecCamera::setTouchAFStartStop(int start_stop)
3227{
3228 LOGV("%s(touch_af_start_stop (%d))", __func__, start_stop);
3229
3230 if (m_touch_af_start_stop != start_stop) {
3231 m_touch_af_start_stop = start_stop;
3232 if (fimc_v4l2_s_ctrl(m_cam_fd, V4L2_CID_CAMERA_TOUCH_AF_START_STOP, start_stop) < 0) {
3233 LOGE("ERR(%s):Fail on V4L2_CID_CAMERA_TOUCH_AF_START_STOP", __func__);
3234 return -1;
3235 }
3236 }
3237
3238 return 0;
3239}
3240
3241int SecCamera::setSmartAuto(int smart_auto)
3242{
3243 LOGV("%s(smart_auto (%d))", __func__, smart_auto);
3244
3245 if (smart_auto < SMART_AUTO_OFF || SMART_AUTO_MAX <= smart_auto) {
3246 LOGE("ERR(%s):Invalid smart_auto (%d)", __func__, smart_auto);
3247 return -1;
3248 }
3249
3250 if (m_smart_auto != smart_auto) {
3251 if (m_flag_camera_create) {
3252 if (fimc_v4l2_s_ctrl(m_cam_fd, V4L2_CID_CAMERA_SMART_AUTO, smart_auto) < 0) {
3253 LOGE("ERR(%s):Fail on V4L2_CID_CAMERA_SMART_AUTO", __func__);
3254 return -1;
3255 }
3256 m_smart_auto = smart_auto;
3257 }
3258 }
3259
3260 return 0;
3261}
3262
3263int SecCamera::getSmartAuto(void)
3264{
3265 return m_smart_auto;
3266}
3267
3268int SecCamera::getAutosceneStatus(void)
3269{
3270 int autoscene_status = -1;
3271
3272 if (getSmartAuto() == SMART_AUTO_ON) {
3273 autoscene_status = fimc_v4l2_g_ctrl(m_cam_fd, V4L2_CID_CAMERA_SMART_AUTO_STATUS);
3274
3275 if ((autoscene_status < SMART_AUTO_STATUS_AUTO) || (autoscene_status > SMART_AUTO_STATUS_MAX)) {
3276 LOGE("ERR(%s):Invalid getAutosceneStatus (%d)", __func__, autoscene_status);
3277 return -1;
3278 }
3279 }
3280 return autoscene_status;
3281}
3282
3283int SecCamera::setBeautyShot(int beauty_shot)
3284{
3285 LOGV("%s(beauty_shot (%d))", __func__, beauty_shot);
3286
3287 if (beauty_shot < BEAUTY_SHOT_OFF || BEAUTY_SHOT_MAX <= beauty_shot) {
3288 LOGE("ERR(%s):Invalid beauty_shot (%d)", __func__, beauty_shot);
3289 return -1;
3290 }
3291
3292 if (m_beauty_shot != beauty_shot) {
3293 if (m_flag_camera_create) {
3294 if (fimc_v4l2_s_ctrl(m_cam_fd, V4L2_CID_CAMERA_BEAUTY_SHOT, beauty_shot) < 0) {
3295 LOGE("ERR(%s):Fail on V4L2_CID_CAMERA_BEAUTY_SHOT", __func__);
3296 return -1;
3297 }
3298 m_beauty_shot = beauty_shot;
3299 }
3300
3301 setFaceDetect(FACE_DETECTION_ON_BEAUTY);
3302 }
3303
3304 return 0;
3305}
3306
3307int SecCamera::getBeautyShot(void)
3308{
3309 return m_beauty_shot;
3310}
3311
3312int SecCamera::setVintageMode(int vintage_mode)
3313{
3314 LOGV("%s(vintage_mode(%d))", __func__, vintage_mode);
3315
3316 if (vintage_mode <= VINTAGE_MODE_BASE || VINTAGE_MODE_MAX <= vintage_mode) {
3317 LOGE("ERR(%s):Invalid vintage_mode (%d)", __func__, vintage_mode);
3318 return -1;
3319 }
3320
3321 if (m_vintage_mode != vintage_mode) {
3322 if (m_flag_camera_create) {
3323 if (fimc_v4l2_s_ctrl(m_cam_fd, V4L2_CID_CAMERA_VINTAGE_MODE, vintage_mode) < 0) {
3324 LOGE("ERR(%s):Fail on V4L2_CID_CAMERA_VINTAGE_MODE", __func__);
3325 return -1;
3326 }
3327 m_vintage_mode = vintage_mode;
3328 }
3329 }
3330
3331 return 0;
3332}
3333
3334int SecCamera::getVintageMode(void)
3335{
3336 return m_vintage_mode;
3337}
3338
3339int SecCamera::setFocusMode(int focus_mode)
3340{
3341 LOGV("%s(focus_mode(%d))", __func__, focus_mode);
3342
3343 if (FOCUS_MODE_MAX <= focus_mode) {
3344 LOGE("ERR(%s):Invalid focus_mode (%d)", __func__, focus_mode);
3345 return -1;
3346 }
3347
3348 if (m_params->focus_mode != focus_mode) {
3349 if (m_flag_camera_create) {
3350 if (m_params->focus_mode == FOCUS_MODE_AUTO || m_params->focus_mode == FOCUS_MODE_MACRO) {
3351 if (fimc_v4l2_s_ctrl(m_cam_fd, V4L2_CID_CAMERA_SET_AUTO_FOCUS, AUTO_FOCUS_OFF) < 0) {
3352 LOGE("ERR(%s):Fail on V4L2_CID_CAMERA_SET_AUTO_FOCUS", __func__);
3353 return -1;
3354 }
3355 }
3356 if (fimc_v4l2_s_ctrl(m_cam_fd, V4L2_CID_CAMERA_FOCUS_MODE, focus_mode) < 0) {
3357 LOGE("ERR(%s):Fail on V4L2_CID_CAMERA_FOCUS_MODE", __func__);
3358 return -1;
3359 }
3360 if (!m_camera_use_ISP) {
3361 if (fimc_v4l2_s_ctrl(m_cam_fd, V4L2_CID_CAMERA_SET_AUTO_FOCUS, AUTO_FOCUS_ON) < 0) {
3362 LOGE("ERR(%s):Fail on V4L2_CID_CAMERA_SET_AUTO_FOCUS", __func__);
3363 return -1;
3364 }
3365 }
3366 m_params->focus_mode = focus_mode;
3367 }
3368 }
3369
3370 return 0;
3371}
3372
3373int SecCamera::getFocusMode(void)
3374{
3375 return m_params->focus_mode;
3376}
3377
3378int SecCamera::setFaceDetect(int face_detect)
3379{
3380 LOGV("%s(face_detect(%d))", __func__, face_detect);
3381 if (m_camera_use_ISP) {
3382 if (face_detect < IS_FD_COMMAND_STOP || IS_FD_COMMAND_MAX <= face_detect) {
3383 LOGE("ERR(%s):Invalid face_detect value (%d)", __func__, face_detect);
3384 return -1;
3385 }
3386 } else {
3387 if (face_detect < FACE_DETECTION_OFF || FACE_DETECTION_MAX <= face_detect) {
3388 LOGE("ERR(%s):Invalid face_detect value (%d)", __func__, face_detect);
3389 return -1;
3390 }
3391 }
3392
3393 if (m_face_detect != face_detect) {
3394 if (m_flag_camera_create) {
3395 if (m_camera_use_ISP) {
3396 if (fimc_v4l2_s_ctrl(m_cam_fd, V4L2_CID_IS_CMD_FD, face_detect) < 0) {
3397 LOGE("ERR(%s):Fail on V4L2_CID_IS_CMD_FD", __func__);
3398 return -1;
3399 }
3400 } else {
3401 if (fimc_v4l2_s_ctrl(m_cam_fd, V4L2_CID_CAMERA_FACE_DETECTION, face_detect) < 0) {
3402 LOGE("ERR(%s):Fail on V4L2_CID_CAMERA_FACE_DETECTION", __func__);
3403 return -1;
3404 }
3405 }
3406 m_face_detect = face_detect;
3407 }
3408 }
3409
3410 return 0;
3411}
3412
3413int SecCamera::getFaceDetect(void)
3414{
3415 return m_face_detect;
3416}
3417
3418int SecCamera::setGPSLatitude(const char *gps_latitude)
3419{
3420 double conveted_latitude = 0;
3421 LOGV("%s(gps_latitude(%s))", __func__, gps_latitude);
3422 if (gps_latitude == NULL)
3423 m_gps_latitude = 0;
3424 else {
3425 conveted_latitude = atof(gps_latitude);
3426 m_gps_latitude = (long)(conveted_latitude * 10000 / 1);
3427 }
3428
3429 LOGV("%s(m_gps_latitude(%ld))", __func__, m_gps_latitude);
3430 return 0;
3431}
3432
3433int SecCamera::setGPSLongitude(const char *gps_longitude)
3434{
3435 double conveted_longitude = 0;
3436 LOGV("%s(gps_longitude(%s))", __func__, gps_longitude);
3437 if (gps_longitude == NULL)
3438 m_gps_longitude = 0;
3439 else {
3440 conveted_longitude = atof(gps_longitude);
3441 m_gps_longitude = (long)(conveted_longitude * 10000 / 1);
3442 }
3443
3444 LOGV("%s(m_gps_longitude(%ld))", __func__, m_gps_longitude);
3445 return 0;
3446}
3447
3448int SecCamera::setGPSAltitude(const char *gps_altitude)
3449{
3450 double conveted_altitude = 0;
3451 LOGV("%s(gps_altitude(%s))", __func__, gps_altitude);
3452 if (gps_altitude == NULL)
3453 m_gps_altitude = 0;
3454 else {
3455 conveted_altitude = atof(gps_altitude);
3456 m_gps_altitude = (long)(conveted_altitude * 100 / 1);
3457 }
3458
3459 LOGV("%s(m_gps_altitude(%ld))", __func__, m_gps_altitude);
3460 return 0;
3461}
3462
3463int SecCamera::setGPSTimeStamp(const char *gps_timestamp)
3464{
3465 LOGV("%s(gps_timestamp(%s))", __func__, gps_timestamp);
3466 if (gps_timestamp == NULL)
3467 m_gps_timestamp = 0;
3468 else
3469 m_gps_timestamp = atol(gps_timestamp);
3470
3471 LOGV("%s(m_gps_timestamp(%ld))", __func__, m_gps_timestamp);
3472 return 0;
3473}
3474
3475int SecCamera::setGPSProcessingMethod(const char *gps_processing_method)
3476{
3477 LOGV("%s(gps_processing_method(%s))", __func__, gps_processing_method);
3478 memset(mExifInfo.gps_processing_method, 0, sizeof(mExifInfo.gps_processing_method));
3479 if (gps_processing_method != NULL) {
3480 size_t len = strlen(gps_processing_method);
3481 if (len > sizeof(mExifInfo.gps_processing_method)) {
3482 len = sizeof(mExifInfo.gps_processing_method);
3483 }
3484 memcpy(mExifInfo.gps_processing_method, gps_processing_method, len);
3485 }
3486 return 0;
3487}
3488
3489int SecCamera::setFaceDetectLockUnlock(int facedetect_lockunlock)
3490{
3491 LOGV("%s(facedetect_lockunlock(%d))", __func__, facedetect_lockunlock);
3492
3493 if (fimc_v4l2_s_ctrl(m_cam_fd, V4L2_CID_CAMERA_FACEDETECT_LOCKUNLOCK, facedetect_lockunlock) < 0) {
3494 LOGE("ERR(%s):Fail on V4L2_CID_CAMERA_FACEDETECT_LOCKUNLOCK", __func__);
3495 return -1;
3496 }
3497
3498 return 0;
3499}
3500
3501int SecCamera::setObjectPosition(int x, int y)
3502{
3503 LOGV("%s(setObjectPosition(x=%d, y=%d))", __func__, x, y);
3504
3505 if (m_flag_camera_start) {
3506 if (fimc_v4l2_s_ctrl(m_cam_fd, V4L2_CID_CAMERA_OBJECT_POSITION_X, x) < 0) {
3507 LOGE("ERR(%s):Fail on V4L2_CID_CAMERA_OBJECT_POSITION_X", __func__);
3508 return -1;
3509 }
3510 if (fimc_v4l2_s_ctrl(m_cam_fd, V4L2_CID_CAMERA_OBJECT_POSITION_Y, y) < 0) {
3511 LOGE("ERR(%s):Fail on V4L2_CID_CAMERA_OBJECT_POSITION_Y", __func__);
3512 return -1;
3513 }
3514 }
3515
3516 return 0;
3517}
3518
3519int SecCamera::setGamma(int gamma)
3520{
3521 LOGV("%s(gamma(%d))", __func__, gamma);
3522
3523 if (gamma < GAMMA_OFF || GAMMA_MAX <= gamma) {
3524 LOGE("ERR(%s):Invalid gamma (%d)", __func__, gamma);
3525 return -1;
3526 }
3527
3528 if (m_video_gamma != gamma) {
3529 if (m_flag_camera_create) {
3530 if (fimc_v4l2_s_ctrl(m_cam_fd, V4L2_CID_CAMERA_SET_GAMMA, gamma) < 0) {
3531 LOGE("ERR(%s):Fail on V4L2_CID_CAMERA_SET_GAMMA", __func__);
3532 return -1;
3533 }
3534 m_video_gamma = gamma;
3535 }
3536 }
3537
3538 return 0;
3539}
3540
3541int SecCamera::setSlowAE(int slow_ae)
3542{
3543 LOGV("%s(slow_ae(%d))", __func__, slow_ae);
3544
3545 if (slow_ae < GAMMA_OFF || GAMMA_MAX <= slow_ae) {
3546 LOGE("ERR(%s):Invalid slow_ae (%d)", __func__, slow_ae);
3547 return -1;
3548 }
3549
3550 if (m_slow_ae!= slow_ae) {
3551 if (m_flag_camera_create) {
3552 if (fimc_v4l2_s_ctrl(m_cam_fd, V4L2_CID_CAMERA_SET_SLOW_AE, slow_ae) < 0) {
3553 LOGE("ERR(%s):Fail on V4L2_CID_CAMERA_SET_SLOW_AE", __func__);
3554 return -1;
3555 }
3556 m_slow_ae = slow_ae;
3557 }
3558 }
3559
3560 return 0;
3561}
3562
3563int SecCamera::setRecordingSize(int width, int height)
3564{
3565 LOGV("%s(width(%d), height(%d))", __func__, width, height);
3566
3567 m_recording_width = width;
3568 m_recording_height = height;
3569
3570 return 0;
3571}
3572
3573int SecCamera::getRecordingSize(int *width, int *height)
3574{
3575 *width = m_recording_width;
3576 *height = m_recording_height;
3577
3578 return 0;
3579}
3580
3581int SecCamera::setExifOrientationInfo(int orientationInfo)
3582{
3583 LOGV("%s(orientationInfo(%d))", __func__, orientationInfo);
3584
3585 if (orientationInfo < 0) {
3586 LOGE("ERR(%s):Invalid orientationInfo (%d)", __func__, orientationInfo);
3587 return -1;
3588 }
3589 m_exif_orientation = orientationInfo;
3590
3591 return 0;
3592}
3593
3594int SecCamera::setBatchReflection()
3595{
3596 if (m_flag_camera_create) {
3597 if (fimc_v4l2_s_ctrl(m_cam_fd, V4L2_CID_CAMERA_BATCH_REFLECTION, 1) < 0) {
3598 LOGE("ERR(%s):Fail on V4L2_CID_CAMERA_BATCH_REFLECTION", __func__);
3599 return -1;
3600 }
3601 }
3602
3603 return 0;
3604}
3605
3606/* Camcorder fix fps */
3607int SecCamera::setSensorMode(int sensor_mode)
3608{
3609 LOGV("%s(sensor_mode (%d))", __func__, sensor_mode);
3610
3611 if (sensor_mode < SENSOR_MODE_CAMERA || SENSOR_MODE_MOVIE < sensor_mode) {
3612 LOGE("ERR(%s):Invalid sensor mode (%d)", __func__, sensor_mode);
3613 return -1;
3614 }
3615
3616 if (m_sensor_mode != sensor_mode)
3617 m_sensor_mode = sensor_mode;
3618
3619 return 0;
3620}
3621
3622/* Shot mode */
3623/* SINGLE = 0
3624* CONTINUOUS = 1
3625* PANORAMA = 2
3626* SMILE = 3
3627* SELF = 6
3628*/
3629int SecCamera::setShotMode(int shot_mode)
3630{
3631 LOGV("%s(shot_mode (%d))", __func__, shot_mode);
3632 if (shot_mode < SHOT_MODE_SINGLE || SHOT_MODE_SELF < shot_mode) {
3633 LOGE("ERR(%s):Invalid shot_mode (%d)", __func__, shot_mode);
3634 return -1;
3635 }
3636 m_shot_mode = shot_mode;
3637
3638 return 0;
3639}
3640
3641int SecCamera::setDataLineCheck(int chk_dataline)
3642{
3643 LOGV("%s(chk_dataline (%d))", __func__, chk_dataline);
3644
3645 if (chk_dataline < CHK_DATALINE_OFF || CHK_DATALINE_MAX <= chk_dataline) {
3646 LOGE("ERR(%s):Invalid chk_dataline (%d)", __func__, chk_dataline);
3647 return -1;
3648 }
3649
3650 m_chk_dataline = chk_dataline;
3651
3652 return 0;
3653}
3654
3655int SecCamera::getDataLineCheck(void)
3656{
3657 return m_chk_dataline;
3658}
3659
3660int SecCamera::setDataLineCheckStop(void)
3661{
3662 LOGV("%s", __func__);
3663
3664 if (m_flag_camera_create) {
3665 if (fimc_v4l2_s_ctrl(m_cam_fd, V4L2_CID_CAMERA_CHECK_DATALINE_STOP, 1) < 0) {
3666 LOGE("ERR(%s):Fail on V4L2_CID_CAMERA_CHECK_DATALINE_STOP", __func__);
3667 return -1;
3668 }
3669 }
3670 return 0;
3671}
3672
3673const __u8* SecCamera::getCameraSensorName(void)
3674{
3675 LOGV("%s", __func__);
3676
3677 return fimc_v4l2_enuminput(m_cam_fd, getCameraId());
3678}
3679
3680bool SecCamera::getUseInternalISP(void)
3681{
3682 LOGV("%s", __func__);
3683 int ret = 0;
3684
3685/*TODO*/
3686 if (!strncmp((const char*)getCameraSensorName(), "ISP Camera", 10))
3687 return true;
3688 else if(!strncmp((const char*)getCameraSensorName(), "S5K3H2", 10))
3689 return true;
3690 else if(!strncmp((const char*)getCameraSensorName(), "S5K3H7", 10))
3691 return true;
3692 else if(!strncmp((const char*)getCameraSensorName(), "S5K4E5", 10))
3693 return true;
3694 else if(!strncmp((const char*)getCameraSensorName(), "S5K6A3", 10))
3695 return true;
3696 else
3697 return false;
3698}
3699
3700#ifdef ENABLE_ESD_PREVIEW_CHECK
3701int SecCamera::getCameraSensorESDStatus(void)
3702{
3703 LOGV("%s", __func__);
3704
3705 // 0 : normal operation, 1 : abnormal operation
3706 int status = fimc_v4l2_g_ctrl(m_cam_fd, V4L2_CID_ESD_INT);
3707
3708 return status;
3709}
3710#endif // ENABLE_ESD_PREVIEW_CHECK
3711
3712int SecCamera::setJpegThumbnailSize(int width, int height)
3713{
3714 LOGV("%s(width(%d), height(%d))", __func__, width, height);
3715
3716 m_jpeg_thumbnail_width = width;
3717 m_jpeg_thumbnail_height = height;
3718
3719 return 0;
3720}
3721
3722int SecCamera::getJpegThumbnailSize(int *width, int *height)
3723{
3724 if (width)
3725 *width = m_jpeg_thumbnail_width;
3726 if (height)
3727 *height = m_jpeg_thumbnail_height;
3728
3729 return 0;
3730}
3731
3732int SecCamera::setJpegThumbnailQuality(int jpeg_thumbnail_quality)
3733{
3734 LOGV("%s(jpeg_thumbnail_quality (%d))", __func__, jpeg_thumbnail_quality);
3735
3736 if (jpeg_thumbnail_quality < JPEG_QUALITY_ECONOMY || JPEG_QUALITY_MAX <= jpeg_thumbnail_quality) {
3737 LOGE("ERR(%s):Invalid jpeg_thumbnail_quality (%d)", __func__, jpeg_thumbnail_quality);
3738 return -1;
3739 }
3740
3741 if (m_jpeg_thumbnail_quality != jpeg_thumbnail_quality) {
3742 m_jpeg_thumbnail_quality = jpeg_thumbnail_quality;
3743 }
3744
3745 return 0;
3746}
3747
3748int SecCamera::getJpegThumbnailQuality(void)
3749{
3750 return m_jpeg_thumbnail_quality;
3751}
3752
3753void SecCamera::setExifFixedAttribute()
3754{
3755 char property[PROPERTY_VALUE_MAX];
3756
3757 //2 0th IFD TIFF Tags
3758 //3 Maker
3759 property_get("ro.product.brand", property, EXIF_DEF_MAKER);
3760 strncpy((char *)mExifInfo.maker, property,
3761 sizeof(mExifInfo.maker) - 1);
3762 mExifInfo.maker[sizeof(mExifInfo.maker) - 1] = '\0';
3763 //3 Model
3764 property_get("ro.product.model", property, EXIF_DEF_MODEL);
3765 strncpy((char *)mExifInfo.model, property,
3766 sizeof(mExifInfo.model) - 1);
3767 mExifInfo.model[sizeof(mExifInfo.model) - 1] = '\0';
3768 //3 Software
3769 property_get("ro.build.id", property, EXIF_DEF_SOFTWARE);
3770 strncpy((char *)mExifInfo.software, property,
3771 sizeof(mExifInfo.software) - 1);
3772 mExifInfo.software[sizeof(mExifInfo.software) - 1] = '\0';
3773
3774 //3 YCbCr Positioning
3775 mExifInfo.ycbcr_positioning = EXIF_DEF_YCBCR_POSITIONING;
3776
3777 //2 0th IFD Exif Private Tags
3778 //3 F Number
3779 mExifInfo.fnumber.num = EXIF_DEF_FNUMBER_NUM;
3780 mExifInfo.fnumber.den = EXIF_DEF_FNUMBER_DEN;
3781 //3 Exposure Program
3782 mExifInfo.exposure_program = EXIF_DEF_EXPOSURE_PROGRAM;
3783 //3 Exif Version
3784 memcpy(mExifInfo.exif_version, EXIF_DEF_EXIF_VERSION, sizeof(mExifInfo.exif_version));
3785 //3 Aperture
3786 uint32_t av = APEX_FNUM_TO_APERTURE((double)mExifInfo.fnumber.num/mExifInfo.fnumber.den);
3787 mExifInfo.aperture.num = av*EXIF_DEF_APEX_DEN;
3788 mExifInfo.aperture.den = EXIF_DEF_APEX_DEN;
3789 //3 Maximum lens aperture
3790 mExifInfo.max_aperture.num = mExifInfo.aperture.num;
3791 mExifInfo.max_aperture.den = mExifInfo.aperture.den;
3792 //3 Lens Focal Length
3793 if (m_camera_id == CAMERA_ID_BACK)
3794 mExifInfo.focal_length.num = BACK_CAMERA_FOCAL_LENGTH;
3795 else
3796 mExifInfo.focal_length.num = FRONT_CAMERA_FOCAL_LENGTH;
3797
3798 mExifInfo.focal_length.den = EXIF_DEF_FOCAL_LEN_DEN;
3799 //3 User Comments
3800 strcpy((char *)mExifInfo.user_comment, EXIF_DEF_USERCOMMENTS);
3801 //3 Color Space information
3802 mExifInfo.color_space = EXIF_DEF_COLOR_SPACE;
3803 //3 Exposure Mode
3804 mExifInfo.exposure_mode = EXIF_DEF_EXPOSURE_MODE;
3805
3806 //2 0th IFD GPS Info Tags
3807 unsigned char gps_version[4] = { 0x02, 0x02, 0x00, 0x00 };
3808 memcpy(mExifInfo.gps_version_id, gps_version, sizeof(gps_version));
3809
3810 //2 1th IFD TIFF Tags
3811 mExifInfo.compression_scheme = EXIF_DEF_COMPRESSION;
3812 mExifInfo.x_resolution.num = EXIF_DEF_RESOLUTION_NUM;
3813 mExifInfo.x_resolution.den = EXIF_DEF_RESOLUTION_DEN;
3814 mExifInfo.y_resolution.num = EXIF_DEF_RESOLUTION_NUM;
3815 mExifInfo.y_resolution.den = EXIF_DEF_RESOLUTION_DEN;
3816 mExifInfo.resolution_unit = EXIF_DEF_RESOLUTION_UNIT;
3817}
3818
3819void SecCamera::setExifChangedAttribute()
3820{
3821 //2 0th IFD TIFF Tags
3822 //3 Width
3823 mExifInfo.width = m_snapshot_width;
3824 //3 Height
3825 mExifInfo.height = m_snapshot_height;
3826 //3 Orientation
3827 switch (m_exif_orientation) {
3828 case 90:
3829 mExifInfo.orientation = EXIF_ORIENTATION_90;
3830 break;
3831 case 180:
3832 mExifInfo.orientation = EXIF_ORIENTATION_180;
3833 break;
3834 case 270:
3835 mExifInfo.orientation = EXIF_ORIENTATION_270;
3836 break;
3837 case 0:
3838 default:
3839 mExifInfo.orientation = EXIF_ORIENTATION_UP;
3840 break;
3841 }
3842 //3 Date time
3843 time_t rawtime;
3844 struct tm *timeinfo;
3845 time(&rawtime);
3846 timeinfo = localtime(&rawtime);
3847 strftime((char *)mExifInfo.date_time, 20, "%Y:%m:%d %H:%M:%S", timeinfo);
3848
3849 //2 0th IFD Exif Private Tags
3850 //3 Exposure Time
3851 int shutterSpeed = 100;
3852 if (m_camera_use_ISP) {
3853 shutterSpeed = fimc_v4l2_g_ctrl(m_cam_fd, V4L2_CID_IS_CAMERA_EXIF_SHUTTERSPEED);
3854 if (shutterSpeed <= 0) {
3855 LOGE("%s: error %d getting shutterSpeed, camera_id = %d, using 100",
3856 __func__, shutterSpeed, m_camera_id);
3857 shutterSpeed = 100;
3858 }
3859 } else {
3860 shutterSpeed = fimc_v4l2_g_ctrl(m_cam_fd, V4L2_CID_CAMERA_EXIF_TV);
3861 if (shutterSpeed <= 0) {
3862 LOGE("%s: error %d getting shutterSpeed, camera_id = %d, using 100",
3863 __func__, shutterSpeed, m_camera_id);
3864 shutterSpeed = 100;
3865 }
3866 }
3867
3868 /* TODO : external isp is not shuppoting exptime now. */
3869 int exptime = 100;
3870 if (m_camera_use_ISP) {
3871 exptime = fimc_v4l2_g_ctrl(m_cam_fd, V4L2_CID_CAMERA_EXIF_EXPTIME);
3872 if (exptime <= 0) {
3873 LOGE("%s: error %d getting exposure time, camera_id = %d, using 100",
3874 __func__, exptime, m_camera_id);
3875 exptime = 100;
3876 }
3877 }
3878 mExifInfo.exposure_time.num = 1;
3879 mExifInfo.exposure_time.den = (uint32_t)exptime;
3880
3881 /* TODO : Normaly exposure time and shutter speed is same. But we need to */
3882 /* calculate exactly value. */
3883 shutterSpeed = exptime;
3884
3885 //3 ISO Speed Rating
3886 int iso;
3887 if (m_camera_use_ISP)
3888 iso = fimc_v4l2_g_ctrl(m_cam_fd, V4L2_CID_IS_CAMERA_EXIF_ISO);
3889 else
3890 iso = fimc_v4l2_g_ctrl(m_cam_fd, V4L2_CID_CAMERA_EXIF_ISO);
3891 if (iso < 0) {
3892 LOGE("%s: error %d getting iso, camera_id = %d, using 100",
3893 __func__, iso, m_camera_id);
3894 iso = 0;
3895 }
3896 mExifInfo.iso_speed_rating = iso;
3897
3898 uint32_t av, tv, bv, sv, ev;
3899 if (m_camera_use_ISP) {
3900 av = APEX_FNUM_TO_APERTURE((double)mExifInfo.fnumber.num / mExifInfo.fnumber.den);
3901 tv = APEX_EXPOSURE_TO_SHUTTER((double)mExifInfo.exposure_time.num / mExifInfo.exposure_time.den);
3902 sv = APEX_ISO_TO_FILMSENSITIVITY(mExifInfo.iso_speed_rating);
3903 bv = av + tv - sv;
3904 ev = m_params->exposure - IS_EXPOSURE_DEFAULT;
3905 } else {
3906 av = APEX_FNUM_TO_APERTURE((double)mExifInfo.fnumber.num / mExifInfo.fnumber.den);
3907 tv = shutterSpeed;
3908 sv = APEX_ISO_TO_FILMSENSITIVITY(mExifInfo.iso_speed_rating);
3909 bv = fimc_v4l2_g_ctrl(m_cam_fd, V4L2_CID_CAMERA_EXIF_BV);
3910 ev = fimc_v4l2_g_ctrl(m_cam_fd, V4L2_CID_CAMERA_EXIF_EBV);
3911 }
3912 LOGD("Shutter speed=1/%d s, iso=%d", shutterSpeed, mExifInfo.iso_speed_rating);
3913 LOGD("AV=%d, TV=%d, SV=%d, BV=%d, EV=%d", av, tv, sv, bv, ev);
3914
3915 //3 Shutter Speed
3916 mExifInfo.shutter_speed.num = 1;
3917 mExifInfo.shutter_speed.den = shutterSpeed;
3918 //3 Brightness
3919 mExifInfo.brightness.num = bv*EXIF_DEF_APEX_DEN;
3920 mExifInfo.brightness.den = EXIF_DEF_APEX_DEN;
3921 //3 Exposure Bias
3922 if (m_params->scene_mode == SCENE_MODE_BEACH_SNOW) {
3923 mExifInfo.exposure_bias.num = EXIF_DEF_APEX_DEN;
3924 mExifInfo.exposure_bias.den = EXIF_DEF_APEX_DEN;
3925 } else {
3926 mExifInfo.exposure_bias.num = ev*EXIF_DEF_APEX_DEN;
3927 mExifInfo.exposure_bias.den = EXIF_DEF_APEX_DEN;
3928 }
3929 //3 Metering Mode
3930 switch (m_params->metering) {
3931 case METERING_SPOT:
3932 mExifInfo.metering_mode = EXIF_METERING_SPOT;
3933 break;
3934 case METERING_MATRIX:
3935 mExifInfo.metering_mode = EXIF_METERING_AVERAGE;
3936 break;
3937 case METERING_CENTER:
3938 mExifInfo.metering_mode = EXIF_METERING_CENTER;
3939 break;
3940 default :
3941 mExifInfo.metering_mode = EXIF_METERING_AVERAGE;
3942 break;
3943 }
3944
3945 //3 Flash
3946 int flash = m_params->flash_mode;
3947 //int flash = fimc_v4l2_g_ctrl(m_cam_fd, V4L2_CID_CAMERA_GET_FLASH_ONOFF);
3948 if (flash < 0)
3949 mExifInfo.flash = EXIF_DEF_FLASH;
3950 else
3951 mExifInfo.flash = flash;
3952
3953 //3 White Balance
3954 if (m_params->white_balance == WHITE_BALANCE_AUTO || m_params->white_balance == IS_AWB_AUTO)
3955 mExifInfo.white_balance = EXIF_WB_AUTO;
3956 else
3957 mExifInfo.white_balance = EXIF_WB_MANUAL;
3958 //3 Scene Capture Type
3959 switch (m_params->scene_mode) {
3960 case SCENE_MODE_PORTRAIT:
3961 mExifInfo.scene_capture_type = EXIF_SCENE_PORTRAIT;
3962 break;
3963 case SCENE_MODE_LANDSCAPE:
3964 mExifInfo.scene_capture_type = EXIF_SCENE_LANDSCAPE;
3965 break;
3966 case SCENE_MODE_NIGHTSHOT:
3967 mExifInfo.scene_capture_type = EXIF_SCENE_NIGHT;
3968 break;
3969 default:
3970 mExifInfo.scene_capture_type = EXIF_SCENE_STANDARD;
3971 break;
3972 }
3973
3974 //2 0th IFD GPS Info Tags
3975 if (m_gps_latitude != 0 && m_gps_longitude != 0) {
3976 if (m_gps_latitude > 0)
3977 strcpy((char *)mExifInfo.gps_latitude_ref, "N");
3978 else
3979 strcpy((char *)mExifInfo.gps_latitude_ref, "S");
3980
3981 if (m_gps_longitude > 0)
3982 strcpy((char *)mExifInfo.gps_longitude_ref, "E");
3983 else
3984 strcpy((char *)mExifInfo.gps_longitude_ref, "W");
3985
3986 if (m_gps_altitude > 0)
3987 mExifInfo.gps_altitude_ref = 0;
3988 else
3989 mExifInfo.gps_altitude_ref = 1;
3990
3991 double latitude = fabs(m_gps_latitude / 10000.0);
3992 double longitude = fabs(m_gps_longitude / 10000.0);
3993 double altitude = fabs(m_gps_altitude / 100.0);
3994
3995 mExifInfo.gps_latitude[0].num = (uint32_t)latitude;
3996 mExifInfo.gps_latitude[0].den = 1;
3997 mExifInfo.gps_latitude[1].num = (uint32_t)((latitude - mExifInfo.gps_latitude[0].num) * 60);
3998 mExifInfo.gps_latitude[1].den = 1;
3999 mExifInfo.gps_latitude[2].num = (uint32_t)((((latitude - mExifInfo.gps_latitude[0].num) * 60)
4000 - mExifInfo.gps_latitude[1].num) * 60);
4001 mExifInfo.gps_latitude[2].den = 1;
4002
4003 mExifInfo.gps_longitude[0].num = (uint32_t)longitude;
4004 mExifInfo.gps_longitude[0].den = 1;
4005 mExifInfo.gps_longitude[1].num = (uint32_t)((longitude - mExifInfo.gps_longitude[0].num) * 60);
4006 mExifInfo.gps_longitude[1].den = 1;
4007 mExifInfo.gps_longitude[2].num = (uint32_t)((((longitude - mExifInfo.gps_longitude[0].num) * 60)
4008 - mExifInfo.gps_longitude[1].num) * 60);
4009 mExifInfo.gps_longitude[2].den = 1;
4010
4011 mExifInfo.gps_altitude.num = (uint32_t)altitude;
4012 mExifInfo.gps_altitude.den = 1;
4013
4014 struct tm tm_data;
4015 gmtime_r(&m_gps_timestamp, &tm_data);
4016 mExifInfo.gps_timestamp[0].num = tm_data.tm_hour;
4017 mExifInfo.gps_timestamp[0].den = 1;
4018 mExifInfo.gps_timestamp[1].num = tm_data.tm_min;
4019 mExifInfo.gps_timestamp[1].den = 1;
4020 mExifInfo.gps_timestamp[2].num = tm_data.tm_sec;
4021 mExifInfo.gps_timestamp[2].den = 1;
4022 snprintf((char*)mExifInfo.gps_datestamp, sizeof(mExifInfo.gps_datestamp),
4023 "%04d:%02d:%02d", tm_data.tm_year + 1900, tm_data.tm_mon + 1, tm_data.tm_mday);
4024
4025 mExifInfo.enableGps = true;
4026 } else {
4027 mExifInfo.enableGps = false;
4028 }
4029
4030 //2 1th IFD TIFF Tags
4031 mExifInfo.widthThumb = m_jpeg_thumbnail_width;
4032 mExifInfo.heightThumb = m_jpeg_thumbnail_height;
4033}
4034
4035int SecCamera::makeExif (unsigned char *exifOut,
4036 unsigned char *thumb_buf,
4037 unsigned int thumb_size,
4038 exif_attribute_t *exifInfo,
4039 unsigned int *size,
4040 bool useMainbufForThumb)
4041{
4042 unsigned char *pCur, *pApp1Start, *pIfdStart, *pGpsIfdPtr, *pNextIfdOffset;
4043 unsigned int tmp, LongerTagOffest = 0;
4044 pApp1Start = pCur = exifOut;
4045
4046 //2 Exif Identifier Code & TIFF Header
4047 pCur += 4; // Skip 4 Byte for APP1 marker and length
4048 unsigned char ExifIdentifierCode[6] = { 0x45, 0x78, 0x69, 0x66, 0x00, 0x00 };
4049 memcpy(pCur, ExifIdentifierCode, 6);
4050 pCur += 6;
4051
4052 /* Byte Order - little endian, Offset of IFD - 0x00000008.H */
4053 unsigned char TiffHeader[8] = { 0x49, 0x49, 0x2A, 0x00, 0x08, 0x00, 0x00, 0x00 };
4054 memcpy(pCur, TiffHeader, 8);
4055 pIfdStart = pCur;
4056 pCur += 8;
4057
4058 //2 0th IFD TIFF Tags
4059 if (exifInfo->enableGps)
4060 tmp = NUM_0TH_IFD_TIFF;
4061 else
4062 tmp = NUM_0TH_IFD_TIFF - 1;
4063
4064 memcpy(pCur, &tmp, NUM_SIZE);
4065 pCur += NUM_SIZE;
4066
4067 LongerTagOffest += 8 + NUM_SIZE + tmp*IFD_SIZE + OFFSET_SIZE;
4068
4069 writeExifIfd(&pCur, EXIF_TAG_IMAGE_WIDTH, EXIF_TYPE_LONG,
4070 1, exifInfo->width);
4071 writeExifIfd(&pCur, EXIF_TAG_IMAGE_HEIGHT, EXIF_TYPE_LONG,
4072 1, exifInfo->height);
4073 writeExifIfd(&pCur, EXIF_TAG_MAKE, EXIF_TYPE_ASCII,
4074 strlen((char *)exifInfo->maker) + 1, exifInfo->maker, &LongerTagOffest, pIfdStart);
4075 writeExifIfd(&pCur, EXIF_TAG_MODEL, EXIF_TYPE_ASCII,
4076 strlen((char *)exifInfo->model) + 1, exifInfo->model, &LongerTagOffest, pIfdStart);
4077 writeExifIfd(&pCur, EXIF_TAG_ORIENTATION, EXIF_TYPE_SHORT,
4078 1, exifInfo->orientation);
4079 writeExifIfd(&pCur, EXIF_TAG_SOFTWARE, EXIF_TYPE_ASCII,
4080 strlen((char *)exifInfo->software) + 1, exifInfo->software, &LongerTagOffest, pIfdStart);
4081 writeExifIfd(&pCur, EXIF_TAG_DATE_TIME, EXIF_TYPE_ASCII,
4082 20, exifInfo->date_time, &LongerTagOffest, pIfdStart);
4083 writeExifIfd(&pCur, EXIF_TAG_YCBCR_POSITIONING, EXIF_TYPE_SHORT,
4084 1, exifInfo->ycbcr_positioning);
4085 writeExifIfd(&pCur, EXIF_TAG_EXIF_IFD_POINTER, EXIF_TYPE_LONG,
4086 1, LongerTagOffest);
4087 if (exifInfo->enableGps) {
4088 pGpsIfdPtr = pCur;
4089 pCur += IFD_SIZE; // Skip a ifd size for gps IFD pointer
4090 }
4091
4092 pNextIfdOffset = pCur; // Skip a offset size for next IFD offset
4093 pCur += OFFSET_SIZE;
4094
4095 //2 0th IFD Exif Private Tags
4096 pCur = pIfdStart + LongerTagOffest;
4097
4098 tmp = NUM_0TH_IFD_EXIF;
4099 memcpy(pCur, &tmp , NUM_SIZE);
4100 pCur += NUM_SIZE;
4101
4102 LongerTagOffest += NUM_SIZE + NUM_0TH_IFD_EXIF*IFD_SIZE + OFFSET_SIZE;
4103
4104 writeExifIfd(&pCur, EXIF_TAG_EXPOSURE_TIME, EXIF_TYPE_RATIONAL,
4105 1, &exifInfo->exposure_time, &LongerTagOffest, pIfdStart);
4106 writeExifIfd(&pCur, EXIF_TAG_FNUMBER, EXIF_TYPE_RATIONAL,
4107 1, &exifInfo->fnumber, &LongerTagOffest, pIfdStart);
4108 writeExifIfd(&pCur, EXIF_TAG_EXPOSURE_PROGRAM, EXIF_TYPE_SHORT,
4109 1, exifInfo->exposure_program);
4110 writeExifIfd(&pCur, EXIF_TAG_ISO_SPEED_RATING, EXIF_TYPE_SHORT,
4111 1, exifInfo->iso_speed_rating);
4112 writeExifIfd(&pCur, EXIF_TAG_EXIF_VERSION, EXIF_TYPE_UNDEFINED,
4113 4, exifInfo->exif_version);
4114 writeExifIfd(&pCur, EXIF_TAG_DATE_TIME_ORG, EXIF_TYPE_ASCII,
4115 20, exifInfo->date_time, &LongerTagOffest, pIfdStart);
4116 writeExifIfd(&pCur, EXIF_TAG_DATE_TIME_DIGITIZE, EXIF_TYPE_ASCII,
4117 20, exifInfo->date_time, &LongerTagOffest, pIfdStart);
4118 writeExifIfd(&pCur, EXIF_TAG_SHUTTER_SPEED, EXIF_TYPE_SRATIONAL,
4119 1, (rational_t *)&exifInfo->shutter_speed, &LongerTagOffest, pIfdStart);
4120 writeExifIfd(&pCur, EXIF_TAG_APERTURE, EXIF_TYPE_RATIONAL,
4121 1, &exifInfo->aperture, &LongerTagOffest, pIfdStart);
4122 writeExifIfd(&pCur, EXIF_TAG_BRIGHTNESS, EXIF_TYPE_SRATIONAL,
4123 1, (rational_t *)&exifInfo->brightness, &LongerTagOffest, pIfdStart);
4124 writeExifIfd(&pCur, EXIF_TAG_EXPOSURE_BIAS, EXIF_TYPE_SRATIONAL,
4125 1, (rational_t *)&exifInfo->exposure_bias, &LongerTagOffest, pIfdStart);
4126 writeExifIfd(&pCur, EXIF_TAG_MAX_APERTURE, EXIF_TYPE_RATIONAL,
4127 1, &exifInfo->max_aperture, &LongerTagOffest, pIfdStart);
4128 writeExifIfd(&pCur, EXIF_TAG_METERING_MODE, EXIF_TYPE_SHORT,
4129 1, exifInfo->metering_mode);
4130 writeExifIfd(&pCur, EXIF_TAG_FLASH, EXIF_TYPE_SHORT,
4131 1, exifInfo->flash);
4132 writeExifIfd(&pCur, EXIF_TAG_FOCAL_LENGTH, EXIF_TYPE_RATIONAL,
4133 1, &exifInfo->focal_length, &LongerTagOffest, pIfdStart);
4134 char code[8] = { 0x00, 0x00, 0x00, 0x49, 0x49, 0x43, 0x53, 0x41 };
4135 int commentsLen = strlen((char *)exifInfo->user_comment) + 1;
4136 memmove(exifInfo->user_comment + sizeof(code), exifInfo->user_comment, commentsLen);
4137 memcpy(exifInfo->user_comment, code, sizeof(code));
4138 writeExifIfd(&pCur, EXIF_TAG_USER_COMMENT, EXIF_TYPE_UNDEFINED,
4139 commentsLen + sizeof(code), exifInfo->user_comment, &LongerTagOffest, pIfdStart);
4140 writeExifIfd(&pCur, EXIF_TAG_COLOR_SPACE, EXIF_TYPE_SHORT,
4141 1, exifInfo->color_space);
4142 writeExifIfd(&pCur, EXIF_TAG_PIXEL_X_DIMENSION, EXIF_TYPE_LONG,
4143 1, exifInfo->width);
4144 writeExifIfd(&pCur, EXIF_TAG_PIXEL_Y_DIMENSION, EXIF_TYPE_LONG,
4145 1, exifInfo->height);
4146 writeExifIfd(&pCur, EXIF_TAG_EXPOSURE_MODE, EXIF_TYPE_LONG,
4147 1, exifInfo->exposure_mode);
4148 writeExifIfd(&pCur, EXIF_TAG_WHITE_BALANCE, EXIF_TYPE_LONG,
4149 1, exifInfo->white_balance);
4150 writeExifIfd(&pCur, EXIF_TAG_SCENCE_CAPTURE_TYPE, EXIF_TYPE_LONG,
4151 1, exifInfo->scene_capture_type);
4152 tmp = 0;
4153 memcpy(pCur, &tmp, OFFSET_SIZE); // next IFD offset
4154 pCur += OFFSET_SIZE;
4155
4156 //2 0th IFD GPS Info Tags
4157 if (exifInfo->enableGps) {
4158 writeExifIfd(&pGpsIfdPtr, EXIF_TAG_GPS_IFD_POINTER, EXIF_TYPE_LONG,
4159 1, LongerTagOffest); // GPS IFD pointer skipped on 0th IFD
4160
4161 pCur = pIfdStart + LongerTagOffest;
4162
4163 if (exifInfo->gps_processing_method[0] == 0) {
4164 // don't create GPS_PROCESSING_METHOD tag if there isn't any
4165 tmp = NUM_0TH_IFD_GPS - 1;
4166 } else {
4167 tmp = NUM_0TH_IFD_GPS;
4168 }
4169 memcpy(pCur, &tmp, NUM_SIZE);
4170 pCur += NUM_SIZE;
4171
4172 LongerTagOffest += NUM_SIZE + tmp*IFD_SIZE + OFFSET_SIZE;
4173
4174 writeExifIfd(&pCur, EXIF_TAG_GPS_VERSION_ID, EXIF_TYPE_BYTE,
4175 4, exifInfo->gps_version_id);
4176 writeExifIfd(&pCur, EXIF_TAG_GPS_LATITUDE_REF, EXIF_TYPE_ASCII,
4177 2, exifInfo->gps_latitude_ref);
4178 writeExifIfd(&pCur, EXIF_TAG_GPS_LATITUDE, EXIF_TYPE_RATIONAL,
4179 3, exifInfo->gps_latitude, &LongerTagOffest, pIfdStart);
4180 writeExifIfd(&pCur, EXIF_TAG_GPS_LONGITUDE_REF, EXIF_TYPE_ASCII,
4181 2, exifInfo->gps_longitude_ref);
4182 writeExifIfd(&pCur, EXIF_TAG_GPS_LONGITUDE, EXIF_TYPE_RATIONAL,
4183 3, exifInfo->gps_longitude, &LongerTagOffest, pIfdStart);
4184 writeExifIfd(&pCur, EXIF_TAG_GPS_ALTITUDE_REF, EXIF_TYPE_BYTE,
4185 1, exifInfo->gps_altitude_ref);
4186 writeExifIfd(&pCur, EXIF_TAG_GPS_ALTITUDE, EXIF_TYPE_RATIONAL,
4187 1, &exifInfo->gps_altitude, &LongerTagOffest, pIfdStart);
4188 writeExifIfd(&pCur, EXIF_TAG_GPS_TIMESTAMP, EXIF_TYPE_RATIONAL,
4189 3, exifInfo->gps_timestamp, &LongerTagOffest, pIfdStart);
4190 tmp = strlen((char*)exifInfo->gps_processing_method);
4191 if (tmp > 0) {
4192 if (tmp > 100) {
4193 tmp = 100;
4194 }
4195 static const char ExifAsciiPrefix[] = { 0x41, 0x53, 0x43, 0x49, 0x49, 0x0, 0x0, 0x0 };
4196 unsigned char tmp_buf[100+sizeof(ExifAsciiPrefix)];
4197 memcpy(tmp_buf, ExifAsciiPrefix, sizeof(ExifAsciiPrefix));
4198 memcpy(&tmp_buf[sizeof(ExifAsciiPrefix)], exifInfo->gps_processing_method, tmp);
4199 writeExifIfd(&pCur, EXIF_TAG_GPS_PROCESSING_METHOD, EXIF_TYPE_UNDEFINED,
4200 tmp+sizeof(ExifAsciiPrefix), tmp_buf, &LongerTagOffest, pIfdStart);
4201 }
4202 writeExifIfd(&pCur, EXIF_TAG_GPS_DATESTAMP, EXIF_TYPE_ASCII,
4203 11, exifInfo->gps_datestamp, &LongerTagOffest, pIfdStart);
4204 tmp = 0;
4205 memcpy(pCur, &tmp, OFFSET_SIZE); // next IFD offset
4206 pCur += OFFSET_SIZE;
4207 }
4208
4209 //2 1th IFD TIFF Tags
4210
4211 unsigned char *thumbBuf = thumb_buf;
4212 unsigned int thumbSize = thumb_size;
4213
4214 if (exifInfo->enableThumb && (thumbBuf != NULL) && (thumbSize > 0)) {
4215 tmp = LongerTagOffest;
4216 memcpy(pNextIfdOffset, &tmp, OFFSET_SIZE); // NEXT IFD offset skipped on 0th IFD
4217
4218 pCur = pIfdStart + LongerTagOffest;
4219
4220 tmp = NUM_1TH_IFD_TIFF;
4221 memcpy(pCur, &tmp, NUM_SIZE);
4222 pCur += NUM_SIZE;
4223
4224 LongerTagOffest += NUM_SIZE + NUM_1TH_IFD_TIFF*IFD_SIZE + OFFSET_SIZE;
4225
4226 writeExifIfd(&pCur, EXIF_TAG_IMAGE_WIDTH, EXIF_TYPE_LONG,
4227 1, exifInfo->widthThumb);
4228 writeExifIfd(&pCur, EXIF_TAG_IMAGE_HEIGHT, EXIF_TYPE_LONG,
4229 1, exifInfo->heightThumb);
4230 writeExifIfd(&pCur, EXIF_TAG_COMPRESSION_SCHEME, EXIF_TYPE_SHORT,
4231 1, exifInfo->compression_scheme);
4232 writeExifIfd(&pCur, EXIF_TAG_ORIENTATION, EXIF_TYPE_SHORT,
4233 1, exifInfo->orientation);
4234 writeExifIfd(&pCur, EXIF_TAG_X_RESOLUTION, EXIF_TYPE_RATIONAL,
4235 1, &exifInfo->x_resolution, &LongerTagOffest, pIfdStart);
4236 writeExifIfd(&pCur, EXIF_TAG_Y_RESOLUTION, EXIF_TYPE_RATIONAL,
4237 1, &exifInfo->y_resolution, &LongerTagOffest, pIfdStart);
4238 writeExifIfd(&pCur, EXIF_TAG_RESOLUTION_UNIT, EXIF_TYPE_SHORT,
4239 1, exifInfo->resolution_unit);
4240 writeExifIfd(&pCur, EXIF_TAG_JPEG_INTERCHANGE_FORMAT, EXIF_TYPE_LONG,
4241 1, LongerTagOffest);
4242 writeExifIfd(&pCur, EXIF_TAG_JPEG_INTERCHANGE_FORMAT_LEN, EXIF_TYPE_LONG,
4243 1, thumbSize);
4244
4245 tmp = 0;
4246 memcpy(pCur, &tmp, OFFSET_SIZE); // next IFD offset
4247 pCur += OFFSET_SIZE;
4248
4249 memcpy(pIfdStart + LongerTagOffest, thumbBuf, thumbSize);
4250 LongerTagOffest += thumbSize;
4251 } else {
4252 tmp = 0;
4253 memcpy(pNextIfdOffset, &tmp, OFFSET_SIZE); // NEXT IFD offset skipped on 0th IFD
4254 }
4255
4256 unsigned char App1Marker[2] = { 0xff, 0xe1 };
4257 memcpy(pApp1Start, App1Marker, 2);
4258 pApp1Start += 2;
4259
4260 *size = 10 + LongerTagOffest;
4261 tmp = *size - 2; // APP1 Maker isn't counted
4262 unsigned char size_mm[2] = {(tmp >> 8) & 0xFF, tmp & 0xFF};
4263 memcpy(pApp1Start, size_mm, 2);
4264
4265 LOGD("makeExif X");
4266
4267 return 0;
4268}
4269
4270inline void SecCamera::writeExifIfd(unsigned char **pCur,
4271 unsigned short tag,
4272 unsigned short type,
4273 unsigned int count,
4274 uint32_t value)
4275{
4276 memcpy(*pCur, &tag, 2);
4277 *pCur += 2;
4278 memcpy(*pCur, &type, 2);
4279 *pCur += 2;
4280 memcpy(*pCur, &count, 4);
4281 *pCur += 4;
4282 memcpy(*pCur, &value, 4);
4283 *pCur += 4;
4284}
4285
4286inline void SecCamera::writeExifIfd(unsigned char **pCur,
4287 unsigned short tag,
4288 unsigned short type,
4289 unsigned int count,
4290 unsigned char *pValue)
4291{
4292 char buf[4] = { 0,};
4293
4294 memcpy(buf, pValue, count);
4295 memcpy(*pCur, &tag, 2);
4296 *pCur += 2;
4297 memcpy(*pCur, &type, 2);
4298 *pCur += 2;
4299 memcpy(*pCur, &count, 4);
4300 *pCur += 4;
4301 memcpy(*pCur, buf, 4);
4302 *pCur += 4;
4303}
4304
4305inline void SecCamera::writeExifIfd(unsigned char **pCur,
4306 unsigned short tag,
4307 unsigned short type,
4308 unsigned int count,
4309 unsigned char *pValue,
4310 unsigned int *offset,
4311 unsigned char *start)
4312{
4313 memcpy(*pCur, &tag, 2);
4314 *pCur += 2;
4315 memcpy(*pCur, &type, 2);
4316 *pCur += 2;
4317 memcpy(*pCur, &count, 4);
4318 *pCur += 4;
4319 memcpy(*pCur, offset, 4);
4320 *pCur += 4;
4321 memcpy(start + *offset, pValue, count);
4322 *offset += count;
4323}
4324
4325inline void SecCamera::writeExifIfd(unsigned char **pCur,
4326 unsigned short tag,
4327 unsigned short type,
4328 unsigned int count,
4329 rational_t *pValue,
4330 unsigned int *offset,
4331 unsigned char *start)
4332{
4333 memcpy(*pCur, &tag, 2);
4334 *pCur += 2;
4335 memcpy(*pCur, &type, 2);
4336 *pCur += 2;
4337 memcpy(*pCur, &count, 4);
4338 *pCur += 4;
4339 memcpy(*pCur, offset, 4);
4340 *pCur += 4;
4341 memcpy(start + *offset, pValue, 8 * count);
4342 *offset += 8 * count;
4343}
4344
4345status_t SecCamera::dump(int fd)
4346{
4347 const size_t SIZE = 256;
4348 char buffer[SIZE];
4349 String8 result;
4350 snprintf(buffer, 255, "dump(%d)\n", fd);
4351 result.append(buffer);
4352 ::write(fd, result.string(), result.size());
4353 return NO_ERROR;
4354}
4355
4356double SecCamera::jpeg_ratio = 0.7;
4357int SecCamera::interleaveDataSize = 5242880;
4358int SecCamera::jpegLineLength = 636;
4359
4360}; // namespace android