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