blob: 11d9de6087551f62274a458ef178a033d3eef93a [file] [log] [blame]
Jiyoung Shinc15a6b02012-06-05 01:08:14 -07001/*
2**
3** Copyright 2008, The Android Open Source Project
4** Copyright 2012, Samsung Electronics Co. LTD
5**
6** Licensed under the Apache License, Version 2.0 (the "License");
7** you may not use this file except in compliance with the License.
8** You may obtain a copy of the License at
9**
10** http://www.apache.org/licenses/LICENSE-2.0
11**
12** Unless required by applicable law or agreed to in writing, software
13** distributed under the License is distributed on an "AS IS" BASIS,
14** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15** See the License for the specific language governing permissions and
16** limitations under the License.
17*/
18
19/*!
20 * \file ExynosCameraHWInterface2.cpp
21 * \brief source file for Android Camera API 2.0 HAL
22 * \author Sungjoong Kang(sj3.kang@samsung.com)
Sungjoong Kang13d8c7b2012-07-14 10:20:39 +090023 * \date 2012/07/10
Jiyoung Shinc15a6b02012-06-05 01:08:14 -070024 *
25 * <b>Revision History: </b>
26 * - 2012/05/31 : Sungjoong Kang(sj3.kang@samsung.com) \n
27 * Initial Release
Sungjoong Kang13d8c7b2012-07-14 10:20:39 +090028 *
29 * - 2012/07/10 : Sungjoong Kang(sj3.kang@samsung.com) \n
30 * 2nd Release
31 *
Jiyoung Shinc15a6b02012-06-05 01:08:14 -070032 */
33
34//#define LOG_NDEBUG 0
Sungjoong Kang9dd63e12012-07-24 00:25:51 +090035#define LOG_TAG "ExynosCameraHAL2"
Jiyoung Shinc15a6b02012-06-05 01:08:14 -070036#include <utils/Log.h>
37
38#include "ExynosCameraHWInterface2.h"
39#include "exynos_format.h"
40
41
42
43namespace android {
44
45
Sungjoong Kang9dd63e12012-07-24 00:25:51 +090046void m_savePostView(const char *fname, uint8_t *buf, uint32_t size)
47{
48 int nw;
49 int cnt = 0;
50 uint32_t written = 0;
51
Sungjoong Kangad378612012-08-17 12:34:33 -070052 ALOGV("opening file [%s], address[%x], size(%d)", fname, (unsigned int)buf, size);
Sungjoong Kang9dd63e12012-07-24 00:25:51 +090053 int fd = open(fname, O_RDWR | O_CREAT, 0644);
54 if (fd < 0) {
55 ALOGE("failed to create file [%s]: %s", fname, strerror(errno));
56 return;
57 }
58
Sungjoong Kangad378612012-08-17 12:34:33 -070059 ALOGV("writing %d bytes to file [%s]", size, fname);
Sungjoong Kang9dd63e12012-07-24 00:25:51 +090060 while (written < size) {
61 nw = ::write(fd, buf + written, size - written);
62 if (nw < 0) {
63 ALOGE("failed to write to file %d [%s]: %s",written,fname, strerror(errno));
64 break;
65 }
66 written += nw;
67 cnt++;
68 }
Sungjoong Kangad378612012-08-17 12:34:33 -070069 ALOGV("done writing %d bytes to file [%s] in %d passes",size, fname, cnt);
Sungjoong Kang9dd63e12012-07-24 00:25:51 +090070 ::close(fd);
71}
72
Jiyoung Shinc15a6b02012-06-05 01:08:14 -070073int get_pixel_depth(uint32_t fmt)
74{
75 int depth = 0;
76
77 switch (fmt) {
78 case V4L2_PIX_FMT_JPEG:
79 depth = 8;
80 break;
81
82 case V4L2_PIX_FMT_NV12:
83 case V4L2_PIX_FMT_NV21:
84 case V4L2_PIX_FMT_YUV420:
85 case V4L2_PIX_FMT_YVU420M:
86 case V4L2_PIX_FMT_NV12M:
87 case V4L2_PIX_FMT_NV12MT:
88 depth = 12;
89 break;
90
91 case V4L2_PIX_FMT_RGB565:
92 case V4L2_PIX_FMT_YUYV:
93 case V4L2_PIX_FMT_YVYU:
94 case V4L2_PIX_FMT_UYVY:
95 case V4L2_PIX_FMT_VYUY:
96 case V4L2_PIX_FMT_NV16:
97 case V4L2_PIX_FMT_NV61:
98 case V4L2_PIX_FMT_YUV422P:
99 case V4L2_PIX_FMT_SBGGR10:
100 case V4L2_PIX_FMT_SBGGR12:
101 case V4L2_PIX_FMT_SBGGR16:
102 depth = 16;
103 break;
104
105 case V4L2_PIX_FMT_RGB32:
106 depth = 32;
107 break;
108 default:
109 ALOGE("Get depth failed(format : %d)", fmt);
110 break;
111 }
112
113 return depth;
Sungjoong Kang13d8c7b2012-07-14 10:20:39 +0900114}
Jiyoung Shinc15a6b02012-06-05 01:08:14 -0700115
116int cam_int_s_fmt(node_info_t *node)
117{
118 struct v4l2_format v4l2_fmt;
119 unsigned int framesize;
120 int ret;
121
122 memset(&v4l2_fmt, 0, sizeof(struct v4l2_format));
123
124 v4l2_fmt.type = node->type;
125 framesize = (node->width * node->height * get_pixel_depth(node->format)) / 8;
126
127 if (node->planes >= 1) {
128 v4l2_fmt.fmt.pix_mp.width = node->width;
129 v4l2_fmt.fmt.pix_mp.height = node->height;
130 v4l2_fmt.fmt.pix_mp.pixelformat = node->format;
131 v4l2_fmt.fmt.pix_mp.field = V4L2_FIELD_ANY;
132 } else {
Sungjoong Kang13d8c7b2012-07-14 10:20:39 +0900133 ALOGE("%s:S_FMT, Out of bound : Number of element plane",__FUNCTION__);
Jiyoung Shinc15a6b02012-06-05 01:08:14 -0700134 }
135
136 /* Set up for capture */
137 ret = exynos_v4l2_s_fmt(node->fd, &v4l2_fmt);
138
139 if (ret < 0)
Sungjoong Kang13d8c7b2012-07-14 10:20:39 +0900140 ALOGE("%s: exynos_v4l2_s_fmt fail (%d)",__FUNCTION__, ret);
Jiyoung Shinc15a6b02012-06-05 01:08:14 -0700141
Sungjoong Kangbe494d12012-08-04 15:36:56 -0700142
Jiyoung Shinc15a6b02012-06-05 01:08:14 -0700143 return ret;
144}
145
146int cam_int_reqbufs(node_info_t *node)
147{
148 struct v4l2_requestbuffers req;
149 int ret;
150
151 req.count = node->buffers;
152 req.type = node->type;
153 req.memory = node->memory;
154
155 ret = exynos_v4l2_reqbufs(node->fd, &req);
156
157 if (ret < 0)
Sungjoong Kang13d8c7b2012-07-14 10:20:39 +0900158 ALOGE("%s: VIDIOC_REQBUFS (fd:%d) failed (%d)",__FUNCTION__,node->fd, ret);
Jiyoung Shinc15a6b02012-06-05 01:08:14 -0700159
160 return req.count;
161}
162
163int cam_int_qbuf(node_info_t *node, int index)
164{
165 struct v4l2_buffer v4l2_buf;
166 struct v4l2_plane planes[VIDEO_MAX_PLANES];
167 int i;
168 int ret = 0;
169
170 v4l2_buf.m.planes = planes;
171 v4l2_buf.type = node->type;
172 v4l2_buf.memory = node->memory;
173 v4l2_buf.index = index;
174 v4l2_buf.length = node->planes;
175
176 for(i = 0; i < node->planes; i++){
Sungjoong Kang13d8c7b2012-07-14 10:20:39 +0900177 v4l2_buf.m.planes[i].m.fd = (int)(node->buffer[index].fd.extFd[i]);
178 v4l2_buf.m.planes[i].length = (unsigned long)(node->buffer[index].size.extS[i]);
Jiyoung Shinc15a6b02012-06-05 01:08:14 -0700179 }
180
181 ret = exynos_v4l2_qbuf(node->fd, &v4l2_buf);
182
183 if (ret < 0)
Sungjoong Kang13d8c7b2012-07-14 10:20:39 +0900184 ALOGE("%s: cam_int_qbuf failed (index:%d)(ret:%d)",__FUNCTION__, index, ret);
Jiyoung Shinc15a6b02012-06-05 01:08:14 -0700185
186 return ret;
187}
188
189int cam_int_streamon(node_info_t *node)
190{
191 enum v4l2_buf_type type = node->type;
192 int ret;
193
Sungjoong Kangbe494d12012-08-04 15:36:56 -0700194
Jiyoung Shinc15a6b02012-06-05 01:08:14 -0700195 ret = exynos_v4l2_streamon(node->fd, type);
196
197 if (ret < 0)
Sungjoong Kangad378612012-08-17 12:34:33 -0700198 ALOGE("%s: VIDIOC_STREAMON failed [%d] (%d)",__FUNCTION__, node->fd,ret);
Jiyoung Shinc15a6b02012-06-05 01:08:14 -0700199
200 ALOGV("On streaming I/O... ... fd(%d)", node->fd);
201
202 return ret;
203}
204
Sungjoong Kang13d8c7b2012-07-14 10:20:39 +0900205int cam_int_streamoff(node_info_t *node)
206{
Sungjoong Kangad378612012-08-17 12:34:33 -0700207 enum v4l2_buf_type type = V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE;
208 int ret;
Sungjoong Kang13d8c7b2012-07-14 10:20:39 +0900209
Sungjoong Kangbe494d12012-08-04 15:36:56 -0700210
Sungjoong Kangad378612012-08-17 12:34:33 -0700211 ALOGV("Off streaming I/O... fd(%d)", node->fd);
212 ret = exynos_v4l2_streamoff(node->fd, type);
Sungjoong Kang13d8c7b2012-07-14 10:20:39 +0900213
214 if (ret < 0)
215 ALOGE("%s: VIDIOC_STREAMOFF failed (%d)",__FUNCTION__, ret);
216
Sungjoong Kangad378612012-08-17 12:34:33 -0700217 return ret;
Sungjoong Kang13d8c7b2012-07-14 10:20:39 +0900218}
219
Sungjoong Kang9dd63e12012-07-24 00:25:51 +0900220int isp_int_streamoff(node_info_t *node)
221{
Sungjoong Kangad378612012-08-17 12:34:33 -0700222 enum v4l2_buf_type type = V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE;
223 int ret;
Sungjoong Kang9dd63e12012-07-24 00:25:51 +0900224
Sungjoong Kangad378612012-08-17 12:34:33 -0700225 ALOGV("Off streaming I/O... fd(%d)", node->fd);
226 ret = exynos_v4l2_streamoff(node->fd, type);
Sungjoong Kang9dd63e12012-07-24 00:25:51 +0900227
228 if (ret < 0)
229 ALOGE("%s: VIDIOC_STREAMOFF failed (%d)",__FUNCTION__, ret);
230
Sungjoong Kangad378612012-08-17 12:34:33 -0700231 return ret;
Sungjoong Kang9dd63e12012-07-24 00:25:51 +0900232}
233
Jiyoung Shinc15a6b02012-06-05 01:08:14 -0700234int cam_int_dqbuf(node_info_t *node)
235{
236 struct v4l2_buffer v4l2_buf;
237 struct v4l2_plane planes[VIDEO_MAX_PLANES];
238 int ret;
239
240 v4l2_buf.type = node->type;
241 v4l2_buf.memory = node->memory;
242 v4l2_buf.m.planes = planes;
243 v4l2_buf.length = node->planes;
244
245 ret = exynos_v4l2_dqbuf(node->fd, &v4l2_buf);
246 if (ret < 0)
Sungjoong Kang13d8c7b2012-07-14 10:20:39 +0900247 ALOGE("%s: VIDIOC_DQBUF failed (%d)",__FUNCTION__, ret);
Jiyoung Shinc15a6b02012-06-05 01:08:14 -0700248
249 return v4l2_buf.index;
250}
251
Sungjoong Kangfeb7df42012-08-28 23:35:43 +0900252int cam_int_dqbuf(node_info_t *node, int num_plane)
253{
254 struct v4l2_buffer v4l2_buf;
255 struct v4l2_plane planes[VIDEO_MAX_PLANES];
256 int ret;
257
258 v4l2_buf.type = node->type;
259 v4l2_buf.memory = node->memory;
260 v4l2_buf.m.planes = planes;
261 v4l2_buf.length = num_plane;
262
263 ret = exynos_v4l2_dqbuf(node->fd, &v4l2_buf);
264 if (ret < 0)
265 ALOGE("%s: VIDIOC_DQBUF failed (%d)",__FUNCTION__, ret);
266
267 return v4l2_buf.index;
268}
269
Jiyoung Shinc15a6b02012-06-05 01:08:14 -0700270int cam_int_s_input(node_info_t *node, int index)
271{
272 int ret;
Sungjoong Kang13d8c7b2012-07-14 10:20:39 +0900273
Jiyoung Shinc15a6b02012-06-05 01:08:14 -0700274 ret = exynos_v4l2_s_input(node->fd, index);
275 if (ret < 0)
Sungjoong Kang13d8c7b2012-07-14 10:20:39 +0900276 ALOGE("%s: VIDIOC_S_INPUT failed (%d)",__FUNCTION__, ret);
Jiyoung Shinc15a6b02012-06-05 01:08:14 -0700277
278 return ret;
279}
280
281
282gralloc_module_t const* ExynosCameraHWInterface2::m_grallocHal;
283
284RequestManager::RequestManager(SignalDrivenThread* main_thread):
285 m_numOfEntries(0),
Sungjoong Kangad378612012-08-17 12:34:33 -0700286 m_entryInsertionIndex(-1),
287 m_entryProcessingIndex(-1),
288 m_entryFrameOutputIndex(-1),
Sungjoong Kang2bdec062012-08-17 15:47:56 -0700289 m_lastAeMode(0),
290 m_lastAaMode(0),
291 m_lastAwbMode(0),
292 m_lastAeComp(0),
Sungjoong Kangad378612012-08-17 12:34:33 -0700293 m_frameIndex(-1)
Jiyoung Shinc15a6b02012-06-05 01:08:14 -0700294{
295 m_metadataConverter = new MetadataConverter;
296 m_mainThread = main_thread;
Sungjoong Kang13d8c7b2012-07-14 10:20:39 +0900297 for (int i=0 ; i<NUM_MAX_REQUEST_MGR_ENTRY; i++) {
Sungjoong Kang13d8c7b2012-07-14 10:20:39 +0900298 memset(&(entries[i]), 0x00, sizeof(request_manager_entry_t));
Sungjoong Kangbe494d12012-08-04 15:36:56 -0700299 entries[i].internal_shot.shot.ctl.request.frameCount = -1;
Sungjoong Kang13d8c7b2012-07-14 10:20:39 +0900300 }
Sungjoong Kangad378612012-08-17 12:34:33 -0700301 m_sensorPipelineSkipCnt = 0;
Jiyoung Shinc15a6b02012-06-05 01:08:14 -0700302 return;
303}
304
305RequestManager::~RequestManager()
306{
Sungjoong Kang15fd8232012-08-23 16:16:44 -0700307 ALOGV("%s", __FUNCTION__);
308 if (m_metadataConverter != NULL) {
309 delete m_metadataConverter;
310 m_metadataConverter = NULL;
311 }
312
Jiyoung Shinc15a6b02012-06-05 01:08:14 -0700313 return;
314}
315
316int RequestManager::GetNumEntries()
317{
318 return m_numOfEntries;
319}
320
Sungjoong Kang9dd63e12012-07-24 00:25:51 +0900321void RequestManager::SetDefaultParameters(int cropX)
322{
323 m_cropX = cropX;
324}
325
Jiyoung Shinc15a6b02012-06-05 01:08:14 -0700326bool RequestManager::IsRequestQueueFull()
327{
328 Mutex::Autolock lock(m_requestMutex);
329 if (m_numOfEntries>=NUM_MAX_REQUEST_MGR_ENTRY)
330 return true;
331 else
332 return false;
333}
334
335void RequestManager::RegisterRequest(camera_metadata_t * new_request)
336{
Sungjoong Kang13d8c7b2012-07-14 10:20:39 +0900337 ALOGV("DEBUG(%s):", __FUNCTION__);
338
Jiyoung Shinc15a6b02012-06-05 01:08:14 -0700339 Mutex::Autolock lock(m_requestMutex);
Sungjoong Kang13d8c7b2012-07-14 10:20:39 +0900340
Jiyoung Shinc15a6b02012-06-05 01:08:14 -0700341 request_manager_entry * newEntry = NULL;
Sungjoong Kang9dd63e12012-07-24 00:25:51 +0900342 int newInsertionIndex = GetNextIndex(m_entryInsertionIndex);
Sungjoong Kang13d8c7b2012-07-14 10:20:39 +0900343 ALOGV("DEBUG(%s): got lock, new insertIndex(%d), cnt before reg(%d)", __FUNCTION__,newInsertionIndex,m_numOfEntries );
Jiyoung Shinc15a6b02012-06-05 01:08:14 -0700344
Sungjoong Kang13d8c7b2012-07-14 10:20:39 +0900345
Jiyoung Shinc15a6b02012-06-05 01:08:14 -0700346 newEntry = &(entries[newInsertionIndex]);
347
348 if (newEntry->status!=EMPTY) {
Sungjoong Kang13d8c7b2012-07-14 10:20:39 +0900349 ALOGV("DEBUG(%s): Circular buffer abnormal ", __FUNCTION__);
350 return;
Jiyoung Shinc15a6b02012-06-05 01:08:14 -0700351 }
352 newEntry->status = REGISTERED;
353 newEntry->original_request = new_request;
Sungjoong Kangad378612012-08-17 12:34:33 -0700354 memset(&(newEntry->internal_shot), 0, sizeof(struct camera2_shot_ext));
Sungjoong Kang13d8c7b2012-07-14 10:20:39 +0900355 m_metadataConverter->ToInternalShot(new_request, &(newEntry->internal_shot));
Sungjoong Kangb56dcc02012-08-08 13:38:09 -0700356 newEntry->output_stream_count = newEntry->internal_shot.shot.ctl.request.outputStreams[15];
Jiyoung Shinc15a6b02012-06-05 01:08:14 -0700357
358 m_numOfEntries++;
359 m_entryInsertionIndex = newInsertionIndex;
360
Sungjoong Kang13d8c7b2012-07-14 10:20:39 +0900361
Jiyoung Shinc15a6b02012-06-05 01:08:14 -0700362 ALOGV("## RegisterReq DONE num(%d), insert(%d), processing(%d), frame(%d), (frameCnt(%d))",
Sungjoong Kangbe494d12012-08-04 15:36:56 -0700363 m_numOfEntries,m_entryInsertionIndex,m_entryProcessingIndex, m_entryFrameOutputIndex, newEntry->internal_shot.shot.ctl.request.frameCount);
Jiyoung Shinc15a6b02012-06-05 01:08:14 -0700364}
365
366void RequestManager::DeregisterRequest(camera_metadata_t ** deregistered_request)
367{
Sungjoong Kang13d8c7b2012-07-14 10:20:39 +0900368 ALOGV("DEBUG(%s):", __FUNCTION__);
Sungjoong Kangad378612012-08-17 12:34:33 -0700369 int frame_index;
370 request_manager_entry * currentEntry;
371
Jiyoung Shinc15a6b02012-06-05 01:08:14 -0700372 Mutex::Autolock lock(m_requestMutex);
373
Sungjoong Kangad378612012-08-17 12:34:33 -0700374 frame_index = GetFrameIndex();
375 currentEntry = &(entries[frame_index]);
Sungjoong Kangbe494d12012-08-04 15:36:56 -0700376 if (currentEntry->status != CAPTURED) {
Sungjoong Kangad378612012-08-17 12:34:33 -0700377 ALOGV("DBG(%s): Circular buffer abnormal. processing(%d), frame(%d), status(%d) ", __FUNCTION__
Jiyoung Shinc15a6b02012-06-05 01:08:14 -0700378 , m_entryProcessingIndex, m_entryFrameOutputIndex,(int)(currentEntry->status));
Sungjoong Kang13d8c7b2012-07-14 10:20:39 +0900379 return;
Jiyoung Shinc15a6b02012-06-05 01:08:14 -0700380 }
Sungjoong Kang13d8c7b2012-07-14 10:20:39 +0900381 if (deregistered_request) *deregistered_request = currentEntry->original_request;
382
Jiyoung Shinc15a6b02012-06-05 01:08:14 -0700383 currentEntry->status = EMPTY;
384 currentEntry->original_request = NULL;
Sungjoong Kangbe494d12012-08-04 15:36:56 -0700385 memset(&(currentEntry->internal_shot), 0, sizeof(struct camera2_shot_ext));
386 currentEntry->internal_shot.shot.ctl.request.frameCount = -1;
Jiyoung Shinc15a6b02012-06-05 01:08:14 -0700387 currentEntry->output_stream_count = 0;
Sungjoong Kang13d8c7b2012-07-14 10:20:39 +0900388 currentEntry->dynamic_meta_vaild = false;
Jiyoung Shinc15a6b02012-06-05 01:08:14 -0700389 m_numOfEntries--;
390 ALOGV("## DeRegistReq DONE num(%d), insert(%d), processing(%d), frame(%d)",
391 m_numOfEntries,m_entryInsertionIndex,m_entryProcessingIndex, m_entryFrameOutputIndex);
Sungjoong Kang13d8c7b2012-07-14 10:20:39 +0900392
Jiyoung Shinc15a6b02012-06-05 01:08:14 -0700393 return;
Jiyoung Shinc15a6b02012-06-05 01:08:14 -0700394}
395
Sungjoong Kang13d8c7b2012-07-14 10:20:39 +0900396bool RequestManager::PrepareFrame(size_t* num_entries, size_t* frame_size,
Sungjoong Kang0f26b202012-08-17 15:43:12 -0700397 camera_metadata_t ** prepared_frame, int afState)
Jiyoung Shinc15a6b02012-06-05 01:08:14 -0700398{
Sungjoong Kang13d8c7b2012-07-14 10:20:39 +0900399 ALOGV("DEBUG(%s):", __FUNCTION__);
Jiyoung Shinc15a6b02012-06-05 01:08:14 -0700400 Mutex::Autolock lock(m_requestMutex);
401 status_t res = NO_ERROR;
Sungjoong Kangad378612012-08-17 12:34:33 -0700402 int tempFrameOutputIndex = GetFrameIndex();
Sungjoong Kang13d8c7b2012-07-14 10:20:39 +0900403 request_manager_entry * currentEntry = &(entries[tempFrameOutputIndex]);
404 ALOGV("DEBUG(%s): processing(%d), frameOut(%d), insert(%d) recentlycompleted(%d)", __FUNCTION__,
405 m_entryProcessingIndex, m_entryFrameOutputIndex, m_entryInsertionIndex, m_completedIndex);
406
Sungjoong Kangbe494d12012-08-04 15:36:56 -0700407 if (currentEntry->status != CAPTURED) {
Sungjoong Kangad378612012-08-17 12:34:33 -0700408 ALOGV("DBG(%s): Circular buffer abnormal status(%d)", __FUNCTION__, (int)(currentEntry->status));
Sungjoong Kang13d8c7b2012-07-14 10:20:39 +0900409
410 return false;
411 }
412 m_entryFrameOutputIndex = tempFrameOutputIndex;
Sungjoong Kangfd2d78a2012-08-26 17:44:25 -0700413 m_tempFrameMetadata = place_camera_metadata(m_tempFrameMetadataBuf, 2000, 20, 500); //estimated
Sungjoong Kang0f26b202012-08-17 15:43:12 -0700414 add_camera_metadata_entry(m_tempFrameMetadata, ANDROID_CONTROL_AF_STATE, &afState, 1);
Sungjoong Kang13d8c7b2012-07-14 10:20:39 +0900415 res = m_metadataConverter->ToDynamicMetadata(&(currentEntry->internal_shot),
Jiyoung Shinc15a6b02012-06-05 01:08:14 -0700416 m_tempFrameMetadata);
417 if (res!=NO_ERROR) {
Sungjoong Kang13d8c7b2012-07-14 10:20:39 +0900418 ALOGE("ERROR(%s): ToDynamicMetadata (%d) ", __FUNCTION__, res);
419 return false;
Jiyoung Shinc15a6b02012-06-05 01:08:14 -0700420 }
421 *num_entries = get_camera_metadata_entry_count(m_tempFrameMetadata);
422 *frame_size = get_camera_metadata_size(m_tempFrameMetadata);
423 *prepared_frame = m_tempFrameMetadata;
Sungjoong Kang13d8c7b2012-07-14 10:20:39 +0900424 ALOGV("## PrepareFrame DONE: frameOut(%d) frameCnt-req(%d)", m_entryFrameOutputIndex,
Sungjoong Kangbe494d12012-08-04 15:36:56 -0700425 currentEntry->internal_shot.shot.ctl.request.frameCount);
Sungjoong Kang9dd63e12012-07-24 00:25:51 +0900426 // Dump();
Sungjoong Kang13d8c7b2012-07-14 10:20:39 +0900427 return true;
Jiyoung Shinc15a6b02012-06-05 01:08:14 -0700428}
429
Sungjoong Kang0f26b202012-08-17 15:43:12 -0700430int RequestManager::MarkProcessingRequest(ExynosBuffer* buf, int *afMode)
Jiyoung Shinc15a6b02012-06-05 01:08:14 -0700431{
Sungjoong Kangad378612012-08-17 12:34:33 -0700432
Jiyoung Shinc15a6b02012-06-05 01:08:14 -0700433 Mutex::Autolock lock(m_requestMutex);
Sungjoong Kang13d8c7b2012-07-14 10:20:39 +0900434 struct camera2_shot_ext * shot_ext;
Sungjoong Kangb56dcc02012-08-08 13:38:09 -0700435 struct camera2_shot_ext * request_shot;
Sungjoong Kang13d8c7b2012-07-14 10:20:39 +0900436 int targetStreamIndex = 0;
Sungjoong Kangad378612012-08-17 12:34:33 -0700437 request_manager_entry * newEntry = NULL;
Sungjoong Kang0f26b202012-08-17 15:43:12 -0700438 static int count = 0;
Sungjoong Kang13d8c7b2012-07-14 10:20:39 +0900439
Sungjoong Kang13d8c7b2012-07-14 10:20:39 +0900440 if (m_numOfEntries == 0) {
Sungjoong Kangad378612012-08-17 12:34:33 -0700441 ALOGD("DEBUG(%s): Request Manager Empty ", __FUNCTION__);
Sungjoong Kang13d8c7b2012-07-14 10:20:39 +0900442 return -1;
443 }
444
445 if ((m_entryProcessingIndex == m_entryInsertionIndex)
Sungjoong Kangbe494d12012-08-04 15:36:56 -0700446 && (entries[m_entryProcessingIndex].status == REQUESTED || entries[m_entryProcessingIndex].status == CAPTURED)) {
Younghwan Jooda7ca692012-09-03 20:47:21 -0700447 ALOGV("## MarkProcReq skipping(request underrun) - num(%d), insert(%d), processing(%d), frame(%d)",
Sungjoong Kang13d8c7b2012-07-14 10:20:39 +0900448 m_numOfEntries,m_entryInsertionIndex,m_entryProcessingIndex, m_entryFrameOutputIndex);
449 return -1;
450 }
Jiyoung Shinc15a6b02012-06-05 01:08:14 -0700451
Sungjoong Kang9dd63e12012-07-24 00:25:51 +0900452 int newProcessingIndex = GetNextIndex(m_entryProcessingIndex);
Sungjoong Kangad378612012-08-17 12:34:33 -0700453 ALOGV("DEBUG(%s): index(%d)", __FUNCTION__, newProcessingIndex);
Jiyoung Shinc15a6b02012-06-05 01:08:14 -0700454
Jiyoung Shinc15a6b02012-06-05 01:08:14 -0700455 newEntry = &(entries[newProcessingIndex]);
Sungjoong Kangad378612012-08-17 12:34:33 -0700456 request_shot = &(newEntry->internal_shot);
Sungjoong Kang0f26b202012-08-17 15:43:12 -0700457 *afMode = (int)(newEntry->internal_shot.shot.ctl.aa.afMode);
Sungjoong Kangbe494d12012-08-04 15:36:56 -0700458 if (newEntry->status != REGISTERED) {
Sungjoong Kangad378612012-08-17 12:34:33 -0700459 ALOGD("DEBUG(%s)(%d): Circular buffer abnormal ", __FUNCTION__, newProcessingIndex);
Sungjoong Kang13d8c7b2012-07-14 10:20:39 +0900460 return -1;
Jiyoung Shinc15a6b02012-06-05 01:08:14 -0700461 }
Sungjoong Kangad378612012-08-17 12:34:33 -0700462
Sungjoong Kangbe494d12012-08-04 15:36:56 -0700463 newEntry->status = REQUESTED;
Jiyoung Shinc15a6b02012-06-05 01:08:14 -0700464
Sungjoong Kangad378612012-08-17 12:34:33 -0700465 shot_ext = (struct camera2_shot_ext *)buf->virt.extP[1];
Sungjoong Kang13d8c7b2012-07-14 10:20:39 +0900466
Sungjoong Kangad378612012-08-17 12:34:33 -0700467 memset(shot_ext, 0x00, sizeof(struct camera2_shot_ext));
468 shot_ext->shot.ctl.request.frameCount = request_shot->shot.ctl.request.frameCount;
Sungjoong Kang13d8c7b2012-07-14 10:20:39 +0900469 shot_ext->request_sensor = 1;
Sungjoong Kang9dd63e12012-07-24 00:25:51 +0900470 shot_ext->dis_bypass = 1;
471 shot_ext->dnr_bypass = 1;
Sungjoong Kangad378612012-08-17 12:34:33 -0700472 shot_ext->fd_bypass = 1;
473 shot_ext->setfile = 0;
474
Sungjoong Kang13d8c7b2012-07-14 10:20:39 +0900475 for (int i = 0; i < newEntry->output_stream_count; i++) {
Sungjoong Kangbe494d12012-08-04 15:36:56 -0700476 targetStreamIndex = newEntry->internal_shot.shot.ctl.request.outputStreams[i];
Sungjoong Kang13d8c7b2012-07-14 10:20:39 +0900477
478 if (targetStreamIndex==0) {
479 ALOGV("DEBUG(%s): outputstreams(%d) is for scalerP", __FUNCTION__, i);
480 shot_ext->request_scp = 1;
Sungjoong Kangfd2d78a2012-08-26 17:44:25 -0700481 if (shot_ext->shot.ctl.stats.faceDetectMode != FACEDETECT_MODE_OFF)
482 shot_ext->fd_bypass = 0;
Sungjoong Kang13d8c7b2012-07-14 10:20:39 +0900483 }
Sungjoong Kang9dd63e12012-07-24 00:25:51 +0900484 else if (targetStreamIndex == 1) {
Sungjoong Kang13d8c7b2012-07-14 10:20:39 +0900485 ALOGV("DEBUG(%s): outputstreams(%d) is for scalerC", __FUNCTION__, i);
486 shot_ext->request_scc = 1;
Sungjoong Kang9dd63e12012-07-24 00:25:51 +0900487 }
488 else if (targetStreamIndex == 2) {
489 ALOGV("DEBUG(%s): outputstreams(%d) is for scalerP (record)", __FUNCTION__, i);
490 shot_ext->request_scp = 1;
491 shot_ext->shot.ctl.request.outputStreams[2] = 1;
Sungjoong Kangfd2d78a2012-08-26 17:44:25 -0700492 if (shot_ext->shot.ctl.stats.faceDetectMode != FACEDETECT_MODE_OFF)
493 shot_ext->fd_bypass = 0;
Sungjoong Kang13d8c7b2012-07-14 10:20:39 +0900494 }
Sungjoong Kang74d78eb2012-08-29 13:25:46 -0700495 else if (targetStreamIndex == 3) {
496 ALOGV("DEBUG(%s): outputstreams(%d) is for scalerP (previewCb)", __FUNCTION__, i);
497 shot_ext->request_scp = 1;
498 shot_ext->shot.ctl.request.outputStreams[3] = 1;
499 }
Sungjoong Kang13d8c7b2012-07-14 10:20:39 +0900500 else {
501 ALOGV("DEBUG(%s): outputstreams(%d) has abnormal value(%d)", __FUNCTION__, i, targetStreamIndex);
502 }
503 }
Sungjoong Kangad378612012-08-17 12:34:33 -0700504
Sungjoong Kang0f26b202012-08-17 15:43:12 -0700505 if (count == 0){
506 shot_ext->shot.ctl.aa.mode = AA_CONTROL_AUTO;
507 } else
508 shot_ext->shot.ctl.aa.mode = AA_CONTROL_NONE;
509
510 count++;
Sungjoong Kangad378612012-08-17 12:34:33 -0700511 shot_ext->shot.ctl.request.metadataMode = METADATA_MODE_FULL;
512 shot_ext->shot.ctl.stats.faceDetectMode = FACEDETECT_MODE_FULL;
513 shot_ext->shot.magicNumber = 0x23456789;
514 shot_ext->shot.ctl.sensor.exposureTime = 0;
515 shot_ext->shot.ctl.sensor.frameDuration = 33*1000*1000;
516 shot_ext->shot.ctl.sensor.sensitivity = 0;
517
Sungjoong Kange4657e32012-08-28 15:02:19 -0700518
519 shot_ext->shot.ctl.scaler.cropRegion[0] = newEntry->internal_shot.shot.ctl.scaler.cropRegion[0];
520 shot_ext->shot.ctl.scaler.cropRegion[1] = newEntry->internal_shot.shot.ctl.scaler.cropRegion[1];
521 shot_ext->shot.ctl.scaler.cropRegion[2] = newEntry->internal_shot.shot.ctl.scaler.cropRegion[2];
Sungjoong Kangad378612012-08-17 12:34:33 -0700522
Sungjoong Kang13d8c7b2012-07-14 10:20:39 +0900523 m_entryProcessingIndex = newProcessingIndex;
Sungjoong Kangad378612012-08-17 12:34:33 -0700524 return newProcessingIndex;
Jiyoung Shinc15a6b02012-06-05 01:08:14 -0700525}
526
Sungjoong Kang9dd63e12012-07-24 00:25:51 +0900527void RequestManager::NotifyStreamOutput(int frameCnt, int stream_id)
Jiyoung Shinc15a6b02012-06-05 01:08:14 -0700528{
Sungjoong Kang9dd63e12012-07-24 00:25:51 +0900529 int index;
530
531 ALOGV("DEBUG(%s): frameCnt(%d), stream_id(%d)", __FUNCTION__, frameCnt, stream_id);
532
533 index = FindEntryIndexByFrameCnt(frameCnt);
534 if (index == -1) {
535 ALOGE("ERR(%s): Cannot find entry for frameCnt(%d)", __FUNCTION__, frameCnt);
536 return;
537 }
538 ALOGV("DEBUG(%s): frameCnt(%d), stream_id(%d) last cnt (%d)", __FUNCTION__, frameCnt, stream_id, entries[index].output_stream_count);
539
Sungjoong Kangbe494d12012-08-04 15:36:56 -0700540 entries[index].output_stream_count--; //TODO : match stream id also
541 CheckCompleted(index);
Jiyoung Shinc15a6b02012-06-05 01:08:14 -0700542 return;
543}
544
Sungjoong Kang13d8c7b2012-07-14 10:20:39 +0900545void RequestManager::CheckCompleted(int index)
546{
Sungjoong Kang9dd63e12012-07-24 00:25:51 +0900547 ALOGV("DEBUG(%s): reqIndex(%d) current Count(%d)", __FUNCTION__, index, entries[index].output_stream_count);
Sungjoong Kangad378612012-08-17 12:34:33 -0700548 SetFrameIndex(index);
549 m_mainThread->SetSignal(SIGNAL_MAIN_STREAM_OUTPUT_DONE);
Sungjoong Kang13d8c7b2012-07-14 10:20:39 +0900550 return;
551}
Sungjoong Kang13d8c7b2012-07-14 10:20:39 +0900552
Sungjoong Kangad378612012-08-17 12:34:33 -0700553void RequestManager::SetFrameIndex(int index)
554{
555 Mutex::Autolock lock(m_requestMutex);
556 m_frameIndex = index;
557}
558
559int RequestManager::GetFrameIndex()
560{
561 return m_frameIndex;
562}
563
564void RequestManager::ApplyDynamicMetadata(struct camera2_shot_ext *shot_ext)
Sungjoong Kang13d8c7b2012-07-14 10:20:39 +0900565{
Sungjoong Kang9dd63e12012-07-24 00:25:51 +0900566 int index;
Sungjoong Kangb56dcc02012-08-08 13:38:09 -0700567 struct camera2_shot_ext * request_shot;
568 nsecs_t timeStamp;
Sungjoong Kangad378612012-08-17 12:34:33 -0700569 int i;
Sungjoong Kang9dd63e12012-07-24 00:25:51 +0900570
Sungjoong Kangad378612012-08-17 12:34:33 -0700571 ALOGV("DEBUG(%s): frameCnt(%d)", __FUNCTION__, shot_ext->shot.ctl.request.frameCount);
Sungjoong Kang9dd63e12012-07-24 00:25:51 +0900572
Sungjoong Kangad378612012-08-17 12:34:33 -0700573 for (i = 0 ; i < NUM_MAX_REQUEST_MGR_ENTRY ; i++) {
574 if((entries[i].internal_shot.shot.ctl.request.frameCount == shot_ext->shot.ctl.request.frameCount)
575 && (entries[i].status == CAPTURED))
576 break;
577 }
578
579 if (i == NUM_MAX_REQUEST_MGR_ENTRY){
580 ALOGE("[%s] no entry found(framecount:%d)", __FUNCTION__, shot_ext->shot.ctl.request.frameCount);
Sungjoong Kang9dd63e12012-07-24 00:25:51 +0900581 return;
582 }
583
Sungjoong Kangad378612012-08-17 12:34:33 -0700584 request_manager_entry * newEntry = &(entries[i]);
Sungjoong Kangb56dcc02012-08-08 13:38:09 -0700585 request_shot = &(newEntry->internal_shot);
Sungjoong Kang9dd63e12012-07-24 00:25:51 +0900586
Sungjoong Kangbe494d12012-08-04 15:36:56 -0700587 newEntry->dynamic_meta_vaild = true;
Sungjoong Kangb56dcc02012-08-08 13:38:09 -0700588 timeStamp = request_shot->shot.dm.sensor.timeStamp;
Sungjoong Kangad378612012-08-17 12:34:33 -0700589 memcpy(&(request_shot->shot.dm), &(shot_ext->shot.dm), sizeof(struct camera2_dm));
Sungjoong Kangb56dcc02012-08-08 13:38:09 -0700590 request_shot->shot.dm.sensor.timeStamp = timeStamp;
Sungjoong Kangad378612012-08-17 12:34:33 -0700591 CheckCompleted(i);
Sungjoong Kang13d8c7b2012-07-14 10:20:39 +0900592}
593
594void RequestManager::DumpInfoWithIndex(int index)
595{
Sungjoong Kangbe494d12012-08-04 15:36:56 -0700596 struct camera2_shot_ext * currMetadata = &(entries[index].internal_shot);
Sungjoong Kang13d8c7b2012-07-14 10:20:39 +0900597
598 ALOGV("#### frameCount(%d) exposureTime(%lld) ISO(%d)",
Sungjoong Kangbe494d12012-08-04 15:36:56 -0700599 currMetadata->shot.ctl.request.frameCount,
600 currMetadata->shot.ctl.sensor.exposureTime,
601 currMetadata->shot.ctl.sensor.sensitivity);
Sungjoong Kangb56dcc02012-08-08 13:38:09 -0700602 if (currMetadata->shot.ctl.request.outputStreams[15] == 0)
Sungjoong Kang13d8c7b2012-07-14 10:20:39 +0900603 ALOGV("#### No output stream selected");
Sungjoong Kangb56dcc02012-08-08 13:38:09 -0700604 else if (currMetadata->shot.ctl.request.outputStreams[15] == 1)
Sungjoong Kangbe494d12012-08-04 15:36:56 -0700605 ALOGV("#### OutputStreamId : %d", currMetadata->shot.ctl.request.outputStreams[0]);
Sungjoong Kangb56dcc02012-08-08 13:38:09 -0700606 else if (currMetadata->shot.ctl.request.outputStreams[15] == 2)
Sungjoong Kangbe494d12012-08-04 15:36:56 -0700607 ALOGV("#### OutputStreamId : %d, %d", currMetadata->shot.ctl.request.outputStreams[0],
608 currMetadata->shot.ctl.request.outputStreams[1]);
Sungjoong Kang13d8c7b2012-07-14 10:20:39 +0900609 else
Sungjoong Kangb56dcc02012-08-08 13:38:09 -0700610 ALOGV("#### OutputStream num (%d) abnormal ", currMetadata->shot.ctl.request.outputStreams[15]);
Sungjoong Kang13d8c7b2012-07-14 10:20:39 +0900611}
612
Sungjoong Kangef6f83c2012-08-28 22:59:48 +0900613void RequestManager::UpdateIspParameters(struct camera2_shot_ext *shot_ext, int frameCnt)
Sungjoong Kang13d8c7b2012-07-14 10:20:39 +0900614{
Sungjoong Kang9dd63e12012-07-24 00:25:51 +0900615 int index, targetStreamIndex;
Sungjoong Kangb56dcc02012-08-08 13:38:09 -0700616 struct camera2_shot_ext * request_shot;
Sungjoong Kang9dd63e12012-07-24 00:25:51 +0900617
618 ALOGV("DEBUG(%s): updating info with frameCnt(%d)", __FUNCTION__, frameCnt);
619 if (frameCnt < 0)
Sungjoong Kang13d8c7b2012-07-14 10:20:39 +0900620 return;
Sungjoong Kang9dd63e12012-07-24 00:25:51 +0900621
622 index = FindEntryIndexByFrameCnt(frameCnt);
623 if (index == -1) {
624 ALOGE("ERR(%s): Cannot find entry for frameCnt(%d)", __FUNCTION__, frameCnt);
625 return;
626 }
627
Sungjoong Kang13d8c7b2012-07-14 10:20:39 +0900628 request_manager_entry * newEntry = &(entries[index]);
Sungjoong Kangad378612012-08-17 12:34:33 -0700629 request_shot = &(newEntry->internal_shot);
Sungjoong Kang2bdec062012-08-17 15:47:56 -0700630 memcpy(&(shot_ext->shot.ctl), &(request_shot->shot.ctl), sizeof(struct camera2_ctl));
Sungjoong Kang13d8c7b2012-07-14 10:20:39 +0900631 shot_ext->request_sensor = 1;
Sungjoong Kangad378612012-08-17 12:34:33 -0700632 shot_ext->dis_bypass = 1;
633 shot_ext->dnr_bypass = 1;
634 shot_ext->fd_bypass = 1;
635 shot_ext->setfile = 0;
636
Sungjoong Kang13d8c7b2012-07-14 10:20:39 +0900637 shot_ext->request_scc = 0;
638 shot_ext->request_scp = 0;
Sungjoong Kangad378612012-08-17 12:34:33 -0700639
Sungjoong Kang9dd63e12012-07-24 00:25:51 +0900640 shot_ext->shot.ctl.request.outputStreams[0] = 0;
641 shot_ext->shot.ctl.request.outputStreams[1] = 0;
642 shot_ext->shot.ctl.request.outputStreams[2] = 0;
Sungjoong Kang74d78eb2012-08-29 13:25:46 -0700643 shot_ext->shot.ctl.request.outputStreams[3] = 0;
Sungjoong Kang9dd63e12012-07-24 00:25:51 +0900644
Sungjoong Kange4657e32012-08-28 15:02:19 -0700645 shot_ext->shot.ctl.scaler.cropRegion[0] = request_shot->shot.ctl.scaler.cropRegion[0];
646 shot_ext->shot.ctl.scaler.cropRegion[1] = request_shot->shot.ctl.scaler.cropRegion[1];
647 shot_ext->shot.ctl.scaler.cropRegion[2] = request_shot->shot.ctl.scaler.cropRegion[2];
648
Sungjoong Kang2bdec062012-08-17 15:47:56 -0700649 if (m_lastAaMode == request_shot->shot.ctl.aa.mode) {
650 shot_ext->shot.ctl.aa.mode = (enum aa_mode)(0);
651 }
652 else {
653 shot_ext->shot.ctl.aa.mode = request_shot->shot.ctl.aa.mode;
654 m_lastAaMode = (int)(shot_ext->shot.ctl.aa.mode);
655 }
656 if (m_lastAeMode == request_shot->shot.ctl.aa.aeMode) {
657 shot_ext->shot.ctl.aa.aeMode = (enum aa_aemode)(0);
658 }
659 else {
660 shot_ext->shot.ctl.aa.aeMode = request_shot->shot.ctl.aa.aeMode;
661 m_lastAeMode = (int)(shot_ext->shot.ctl.aa.aeMode);
662 }
663 if (m_lastAwbMode == request_shot->shot.ctl.aa.awbMode) {
664 shot_ext->shot.ctl.aa.awbMode = (enum aa_awbmode)(0);
665 }
666 else {
667 shot_ext->shot.ctl.aa.awbMode = request_shot->shot.ctl.aa.awbMode;
668 m_lastAwbMode = (int)(shot_ext->shot.ctl.aa.awbMode);
669 }
670 if (m_lastAeComp == request_shot->shot.ctl.aa.aeExpCompensation) {
671 shot_ext->shot.ctl.aa.aeExpCompensation = 0;
672 }
673 else {
674 shot_ext->shot.ctl.aa.aeExpCompensation = request_shot->shot.ctl.aa.aeExpCompensation;
675 m_lastAeComp = (int)(shot_ext->shot.ctl.aa.aeExpCompensation);
676 }
Sungjoong Kangef6f83c2012-08-28 22:59:48 +0900677
678 shot_ext->shot.ctl.aa.afTrigger = 0;
679
Sungjoong Kang13d8c7b2012-07-14 10:20:39 +0900680 for (int i = 0; i < newEntry->output_stream_count; i++) {
Sungjoong Kangad378612012-08-17 12:34:33 -0700681 targetStreamIndex = newEntry->internal_shot.shot.ctl.request.outputStreams[i];
Sungjoong Kang13d8c7b2012-07-14 10:20:39 +0900682
683 if (targetStreamIndex==0) {
Sungjoong Kangad378612012-08-17 12:34:33 -0700684 ALOGV("DEBUG(%s): outputstreams(%d) is for scalerP", __FUNCTION__, i);
Sungjoong Kang13d8c7b2012-07-14 10:20:39 +0900685 shot_ext->request_scp = 1;
Sungjoong Kangfd2d78a2012-08-26 17:44:25 -0700686 if (shot_ext->shot.ctl.stats.faceDetectMode != FACEDETECT_MODE_OFF)
687 shot_ext->fd_bypass = 0;
Sungjoong Kang13d8c7b2012-07-14 10:20:39 +0900688 }
Sungjoong Kang9dd63e12012-07-24 00:25:51 +0900689 else if (targetStreamIndex == 1) {
Sungjoong Kangad378612012-08-17 12:34:33 -0700690 ALOGV("DEBUG(%s): outputstreams(%d) is for scalerC", __FUNCTION__, i);
Sungjoong Kang13d8c7b2012-07-14 10:20:39 +0900691 shot_ext->request_scc = 1;
Sungjoong Kangfd2d78a2012-08-26 17:44:25 -0700692 if (shot_ext->shot.ctl.stats.faceDetectMode != FACEDETECT_MODE_OFF)
693 shot_ext->fd_bypass = 0;
Sungjoong Kang9dd63e12012-07-24 00:25:51 +0900694 }
695 else if (targetStreamIndex == 2) {
Sungjoong Kangad378612012-08-17 12:34:33 -0700696 ALOGV("DEBUG(%s): outputstreams(%d) is for scalerP (record)", __FUNCTION__, i);
Sungjoong Kang9dd63e12012-07-24 00:25:51 +0900697 shot_ext->request_scp = 1;
698 shot_ext->shot.ctl.request.outputStreams[2] = 1;
Sungjoong Kang2bdec062012-08-17 15:47:56 -0700699 shot_ext->shot.ctl.aa.aeTargetFpsRange[0] = 30;
700 shot_ext->shot.ctl.aa.aeTargetFpsRange[1] = 30;
Sungjoong Kangfd2d78a2012-08-26 17:44:25 -0700701 if (shot_ext->shot.ctl.stats.faceDetectMode != FACEDETECT_MODE_OFF)
702 shot_ext->fd_bypass = 0;
Sungjoong Kang13d8c7b2012-07-14 10:20:39 +0900703 }
Sungjoong Kang74d78eb2012-08-29 13:25:46 -0700704 else if (targetStreamIndex == 3) {
705 ALOGV("DEBUG(%s): outputstreams(%d) is for scalerP (previewCb)", __FUNCTION__, i);
706 shot_ext->request_scp = 1;
707 shot_ext->shot.ctl.request.outputStreams[3] = 1;
708 }
Sungjoong Kang13d8c7b2012-07-14 10:20:39 +0900709 else {
Sungjoong Kangad378612012-08-17 12:34:33 -0700710 ALOGV("DEBUG(%s): outputstreams(%d) has abnormal value(%d)", __FUNCTION__, i, targetStreamIndex);
Sungjoong Kang13d8c7b2012-07-14 10:20:39 +0900711 }
712 }
Sungjoong Kang2bdec062012-08-17 15:47:56 -0700713 ALOGV("(%s): applied aa(%d) aemode(%d) expComp(%d), awb(%d) afmode(%d), ", __FUNCTION__,
714 (int)(shot_ext->shot.ctl.aa.mode), (int)(shot_ext->shot.ctl.aa.aeMode),
715 (int)(shot_ext->shot.ctl.aa.aeExpCompensation), (int)(shot_ext->shot.ctl.aa.awbMode),
716 (int)(shot_ext->shot.ctl.aa.afMode));
Sungjoong Kang13d8c7b2012-07-14 10:20:39 +0900717}
718
Sungjoong Kang9dd63e12012-07-24 00:25:51 +0900719int RequestManager::FindEntryIndexByFrameCnt(int frameCnt)
Sungjoong Kang13d8c7b2012-07-14 10:20:39 +0900720{
Sungjoong Kang9dd63e12012-07-24 00:25:51 +0900721 for (int i = 0 ; i < NUM_MAX_REQUEST_MGR_ENTRY ; i++) {
Sungjoong Kangbe494d12012-08-04 15:36:56 -0700722 if (entries[i].internal_shot.shot.ctl.request.frameCount == frameCnt)
Sungjoong Kang9dd63e12012-07-24 00:25:51 +0900723 return i;
724 }
725 return -1;
Sungjoong Kang13d8c7b2012-07-14 10:20:39 +0900726}
727
Sungjoong Kang9dd63e12012-07-24 00:25:51 +0900728void RequestManager::RegisterTimestamp(int frameCnt, nsecs_t * frameTime)
Sungjoong Kang13d8c7b2012-07-14 10:20:39 +0900729{
Sungjoong Kang9dd63e12012-07-24 00:25:51 +0900730 int index = FindEntryIndexByFrameCnt(frameCnt);
731 if (index == -1) {
732 ALOGE("ERR(%s): Cannot find entry for frameCnt(%d)", __FUNCTION__, frameCnt);
733 return;
734 }
735
736 request_manager_entry * currentEntry = &(entries[index]);
Sungjoong Kangbe494d12012-08-04 15:36:56 -0700737 currentEntry->internal_shot.shot.dm.sensor.timeStamp = *((uint64_t*)frameTime);
Sungjoong Kang9dd63e12012-07-24 00:25:51 +0900738 ALOGV("DEBUG(%s): applied timestamp for reqIndex(%d) frameCnt(%d) (%lld)", __FUNCTION__,
Sungjoong Kangbe494d12012-08-04 15:36:56 -0700739 index, frameCnt, currentEntry->internal_shot.shot.dm.sensor.timeStamp);
Sungjoong Kang9dd63e12012-07-24 00:25:51 +0900740}
741
Sungjoong Kangad378612012-08-17 12:34:33 -0700742uint64_t RequestManager::GetTimestamp(int index)
Sungjoong Kang9dd63e12012-07-24 00:25:51 +0900743{
Sungjoong Kangeed7ed12012-08-23 16:35:08 -0700744 if (index < 0 || index >= NUM_MAX_REQUEST_MGR_ENTRY) {
745 ALOGE("ERR(%s): Request entry outside of bounds (%d)", __FUNCTION__, index);
Sungjoong Kang9dd63e12012-07-24 00:25:51 +0900746 return 0;
747 }
748
Sungjoong Kang13d8c7b2012-07-14 10:20:39 +0900749 request_manager_entry * currentEntry = &(entries[index]);
Sungjoong Kangbe494d12012-08-04 15:36:56 -0700750 uint64_t frameTime = currentEntry->internal_shot.shot.dm.sensor.timeStamp;
Sungjoong Kang9dd63e12012-07-24 00:25:51 +0900751 ALOGV("DEBUG(%s): Returning timestamp for reqIndex(%d) (%lld)", __FUNCTION__, index, frameTime);
Sungjoong Kang13d8c7b2012-07-14 10:20:39 +0900752 return frameTime;
753}
754
Sungjoong Kang9dd63e12012-07-24 00:25:51 +0900755int RequestManager::FindFrameCnt(struct camera2_shot_ext * shot_ext)
756{
Sungjoong Kangad378612012-08-17 12:34:33 -0700757 int i;
758
Sungjoong Kangbe494d12012-08-04 15:36:56 -0700759 if (m_numOfEntries == 0) {
Sungjoong Kangad378612012-08-17 12:34:33 -0700760 ALOGV("(%s): No Entry found", __FUNCTION__);
Sungjoong Kangbe494d12012-08-04 15:36:56 -0700761 return -1;
762 }
Sungjoong Kangad378612012-08-17 12:34:33 -0700763
Sungjoong Kangbe494d12012-08-04 15:36:56 -0700764 for (i = 0 ; i < NUM_MAX_REQUEST_MGR_ENTRY ; i++) {
Sungjoong Kangad378612012-08-17 12:34:33 -0700765 if(entries[i].internal_shot.shot.ctl.request.frameCount != shot_ext->shot.ctl.request.frameCount)
Sungjoong Kangbe494d12012-08-04 15:36:56 -0700766 continue;
Sungjoong Kangad378612012-08-17 12:34:33 -0700767
768 if (entries[i].status == REQUESTED) {
769 entries[i].status = CAPTURED;
770 return entries[i].internal_shot.shot.ctl.request.frameCount;
Sungjoong Kangbe494d12012-08-04 15:36:56 -0700771 }
Sungjoong Kangad378612012-08-17 12:34:33 -0700772
Sungjoong Kangbe494d12012-08-04 15:36:56 -0700773 }
Sungjoong Kangad378612012-08-17 12:34:33 -0700774
775 ALOGD("(%s): No Entry found", __FUNCTION__);
776
Sungjoong Kangbe494d12012-08-04 15:36:56 -0700777 return -1;
Sungjoong Kang9dd63e12012-07-24 00:25:51 +0900778}
Sungjoong Kang13d8c7b2012-07-14 10:20:39 +0900779
Sungjoong Kangb5237e62012-07-27 07:39:05 -0700780void RequestManager::SetInitialSkip(int count)
781{
782 ALOGV("(%s): Pipeline Restarting. setting cnt(%d) - current(%d)", __FUNCTION__, count, m_sensorPipelineSkipCnt);
783 if (count > m_sensorPipelineSkipCnt)
784 m_sensorPipelineSkipCnt = count;
785}
786
Sungjoong Kangad378612012-08-17 12:34:33 -0700787int RequestManager::GetSkipCnt()
788{
789 ALOGV("(%s): skip cnt(%d)", __FUNCTION__, m_sensorPipelineSkipCnt);
790 if (m_sensorPipelineSkipCnt == 0)
791 return m_sensorPipelineSkipCnt;
792 else
793 return --m_sensorPipelineSkipCnt;
794}
795
Sungjoong Kang13d8c7b2012-07-14 10:20:39 +0900796void RequestManager::Dump(void)
797{
Sungjoong Kang13d8c7b2012-07-14 10:20:39 +0900798 int i = 0;
799 request_manager_entry * currentEntry;
Sungjoong Kangad378612012-08-17 12:34:33 -0700800 ALOGD("## Dump totalentry(%d), insert(%d), processing(%d), frame(%d)",
Sungjoong Kang13d8c7b2012-07-14 10:20:39 +0900801 m_numOfEntries,m_entryInsertionIndex,m_entryProcessingIndex, m_entryFrameOutputIndex);
802
803 for (i = 0 ; i < NUM_MAX_REQUEST_MGR_ENTRY ; i++) {
804 currentEntry = &(entries[i]);
Sungjoong Kangad378612012-08-17 12:34:33 -0700805 ALOGD("[%2d] status[%d] frameCnt[%3d] numOutput[%d] outstream[0]-%d outstream[1]-%d", i,
Sungjoong Kangbe494d12012-08-04 15:36:56 -0700806 currentEntry->status, currentEntry->internal_shot.shot.ctl.request.frameCount,
Sungjoong Kangad378612012-08-17 12:34:33 -0700807 currentEntry->output_stream_count,
808 currentEntry->internal_shot.shot.ctl.request.outputStreams[0],
809 currentEntry->internal_shot.shot.ctl.request.outputStreams[1]);
Sungjoong Kang13d8c7b2012-07-14 10:20:39 +0900810 }
811}
812
Sungjoong Kang9dd63e12012-07-24 00:25:51 +0900813int RequestManager::GetNextIndex(int index)
814{
815 index++;
816 if (index >= NUM_MAX_REQUEST_MGR_ENTRY)
817 index = 0;
818
819 return index;
820}
821
Sungjoong Kang6044e502012-08-27 00:29:28 -0700822ExynosCameraHWInterface2::ExynosCameraHWInterface2(int cameraId, camera2_device_t *dev, ExynosCamera2 * camera, int *openInvalid):
Jiyoung Shinc15a6b02012-06-05 01:08:14 -0700823 m_requestQueueOps(NULL),
824 m_frameQueueOps(NULL),
825 m_callbackCookie(NULL),
826 m_numOfRemainingReqInSvc(0),
827 m_isRequestQueuePending(false),
Sungjoong Kang13d8c7b2012-07-14 10:20:39 +0900828 m_isRequestQueueNull(true),
Jiyoung Shinc15a6b02012-06-05 01:08:14 -0700829 m_isSensorThreadOn(false),
Sungjoong Kang13d8c7b2012-07-14 10:20:39 +0900830 m_isSensorStarted(false),
Sungjoong Kangad378612012-08-17 12:34:33 -0700831 m_isIspStarted(false),
Sungjoong Kang13d8c7b2012-07-14 10:20:39 +0900832 m_ionCameraClient(0),
833 m_initFlag1(false),
834 m_initFlag2(false),
Sungjoong Kang13d8c7b2012-07-14 10:20:39 +0900835 m_scp_flushing(false),
836 m_closing(false),
Sungjoong Kang9dd63e12012-07-24 00:25:51 +0900837 m_recordingEnabled(false),
838 m_needsRecordBufferInit(false),
Sungjoong Kang74d78eb2012-08-29 13:25:46 -0700839 m_needsPreviewCbBufferInit(false),
Sungjoong Kang9dd63e12012-07-24 00:25:51 +0900840 lastFrameCnt(-1),
hyeonmyeong Choi308291d2012-08-29 13:55:01 -0700841 m_zoomRatio(1),
Sungjoong Kang9dd63e12012-07-24 00:25:51 +0900842 m_scp_closing(false),
843 m_scp_closed(false),
Sungjoong Kang0f26b202012-08-17 15:43:12 -0700844 m_afState(HAL_AFSTATE_INACTIVE),
845 m_afMode(NO_CHANGE),
846 m_afMode2(NO_CHANGE),
847 m_IsAfModeUpdateRequired(false),
848 m_IsAfTriggerRequired(false),
849 m_IsAfLockRequired(false),
Sungjoong Kang15fd8232012-08-23 16:16:44 -0700850 m_wideAspect(false),
Sungjoong Kangb55ed662012-08-31 21:31:34 -0700851 m_aspectChanged(false),
852 m_scpOutputSignalCnt(0),
853 m_scpOutputImageCnt(0),
Sungjoong Kang0f26b202012-08-17 15:43:12 -0700854 m_afTriggerId(0),
Sungjoong Kang8e2c2fd2012-08-27 00:02:22 -0700855 m_afPendingTriggerId(0),
856 m_afModeWaitingCnt(0),
Sungjoong Kang9dd63e12012-07-24 00:25:51 +0900857 m_halDevice(dev),
Sungjoong Kangad378612012-08-17 12:34:33 -0700858 m_need_streamoff(0),
Sungjoong Kanga15b4e32012-08-28 12:55:39 -0700859 m_nightCaptureCnt(0),
Sungjoong Kang2d5e6ec2012-08-30 15:14:17 +0900860 m_cameraId(cameraId),
861 m_thumbNailW(160),
862 m_thumbNailH(120)
Jiyoung Shinc15a6b02012-06-05 01:08:14 -0700863{
Sungjoong Kang13d8c7b2012-07-14 10:20:39 +0900864 ALOGV("DEBUG(%s):", __FUNCTION__);
Jiyoung Shinc15a6b02012-06-05 01:08:14 -0700865 int ret = 0;
Sungjoong Kang6044e502012-08-27 00:29:28 -0700866 int res = 0;
Jiyoung Shinc15a6b02012-06-05 01:08:14 -0700867
Sungjoong Kang13d8c7b2012-07-14 10:20:39 +0900868 m_exynosPictureCSC = NULL;
Sungjoong Kang9dd63e12012-07-24 00:25:51 +0900869 m_exynosVideoCSC = NULL;
Sungjoong Kang13d8c7b2012-07-14 10:20:39 +0900870
Jiyoung Shinc15a6b02012-06-05 01:08:14 -0700871 if (!m_grallocHal) {
872 ret = hw_get_module(GRALLOC_HARDWARE_MODULE_ID, (const hw_module_t **)&m_grallocHal);
873 if (ret)
Sungjoong Kang13d8c7b2012-07-14 10:20:39 +0900874 ALOGE("ERR(%s):Fail on loading gralloc HAL", __FUNCTION__);
875 }
Jiyoung Shinc15a6b02012-06-05 01:08:14 -0700876
Sungjoong Kangdaa1fcd2012-08-08 11:49:43 -0700877 m_camera2 = camera;
Jiyoung Shinc15a6b02012-06-05 01:08:14 -0700878 m_ionCameraClient = createIonClient(m_ionCameraClient);
879 if(m_ionCameraClient == 0)
Sungjoong Kang13d8c7b2012-07-14 10:20:39 +0900880 ALOGE("ERR(%s):Fail on ion_client_create", __FUNCTION__);
Jiyoung Shinc15a6b02012-06-05 01:08:14 -0700881
Sungjoong Kang9dd63e12012-07-24 00:25:51 +0900882
883 m_BayerManager = new BayerBufManager();
Jiyoung Shinc15a6b02012-06-05 01:08:14 -0700884 m_mainThread = new MainThread(this);
Sungjoong Kang6044e502012-08-27 00:29:28 -0700885 *openInvalid = InitializeISPChain();
886 if (*openInvalid < 0) {
887 // clean process
888 // 1. close video nodes
889 // SCP
890 res = exynos_v4l2_close(m_fd_scp);
891 if (res != NO_ERROR ) {
892 ALOGE("ERR(%s): exynos_v4l2_close failed(%d)",__FUNCTION__ , res);
893 }
894 // SCC
895 res = exynos_v4l2_close(m_camera_info.capture.fd);
896 if (res != NO_ERROR ) {
897 ALOGE("ERR(%s): exynos_v4l2_close failed(%d)",__FUNCTION__ , res);
898 }
899 // Sensor
900 res = exynos_v4l2_close(m_camera_info.sensor.fd);
901 if (res != NO_ERROR ) {
902 ALOGE("ERR(%s): exynos_v4l2_close failed(%d)",__FUNCTION__ , res);
903 }
904 // ISP
905 res = exynos_v4l2_close(m_camera_info.isp.fd);
906 if (res != NO_ERROR ) {
907 ALOGE("ERR(%s): exynos_v4l2_close failed(%d)",__FUNCTION__ , res);
908 }
909 } else {
910 m_sensorThread = new SensorThread(this);
911 m_mainThread->Start("MainThread", PRIORITY_DEFAULT, 0);
912 ALOGV("DEBUG(%s): created sensorthread ################", __FUNCTION__);
913 m_requestManager = new RequestManager((SignalDrivenThread*)(m_mainThread.get()));
914 CSC_METHOD cscMethod = CSC_METHOD_HW;
915 m_exynosPictureCSC = csc_init(cscMethod);
916 if (m_exynosPictureCSC == NULL)
917 ALOGE("ERR(%s): csc_init() fail", __FUNCTION__);
918 csc_set_hw_property(m_exynosPictureCSC, CSC_HW_PROPERTY_FIXED_NODE, PICTURE_GSC_NODE_NUM);
Jiyoung Shinc15a6b02012-06-05 01:08:14 -0700919
Sungjoong Kang6044e502012-08-27 00:29:28 -0700920 m_exynosVideoCSC = csc_init(cscMethod);
921 if (m_exynosVideoCSC == NULL)
922 ALOGE("ERR(%s): csc_init() fail", __FUNCTION__);
923 csc_set_hw_property(m_exynosVideoCSC, CSC_HW_PROPERTY_FIXED_NODE, VIDEO_GSC_NODE_NUM);
Sungjoong Kang13d8c7b2012-07-14 10:20:39 +0900924
Sungjoong Kang6044e502012-08-27 00:29:28 -0700925 m_setExifFixedAttribute();
Younghwan Joo9a710a42012-09-05 17:52:08 -0700926
927 // contol information clear
928 // flash
929 m_ctlInfo.flash.i_flashMode = AA_AEMODE_ON;
930 m_ctlInfo.flash.m_afFlashDoneFlg= false;
931 m_ctlInfo.flash.m_afFlashEnableFlg = false;
932 m_ctlInfo.flash.m_afFlashCnt = 0;
933 m_ctlInfo.flash.m_flashEnableFlg = false;
934 m_ctlInfo.flash.m_flashCaptured = false;
935 m_ctlInfo.flash.m_flashFrameCount = 0;
936 m_ctlInfo.flash.m_flashCnt = 0;
937 m_ctlInfo.flash.m_flashTimeOut = 0;
938 m_ctlInfo.flash.m_flashWaitCnt = 0;
Younghwan Joocaea49e2012-09-07 13:34:20 -0700939 m_ctlInfo.flash.m_flashDecisionResult = false;
940 m_ctlInfo.flash.m_flashTorchMode = false;
Sungjoong Kang6044e502012-08-27 00:29:28 -0700941 }
Jiyoung Shinc15a6b02012-06-05 01:08:14 -0700942}
943
944ExynosCameraHWInterface2::~ExynosCameraHWInterface2()
945{
Sungjoong Kangad378612012-08-17 12:34:33 -0700946 ALOGV("%s: ENTER", __FUNCTION__);
Jiyoung Shinc15a6b02012-06-05 01:08:14 -0700947 this->release();
Sungjoong Kangad378612012-08-17 12:34:33 -0700948 ALOGV("%s: EXIT", __FUNCTION__);
Jiyoung Shinc15a6b02012-06-05 01:08:14 -0700949}
950
951void ExynosCameraHWInterface2::release()
952{
Sungjoong Kang13d8c7b2012-07-14 10:20:39 +0900953 int i, res;
Sungjoong Kang9dd63e12012-07-24 00:25:51 +0900954 ALOGD("%s: ENTER", __func__);
Sungjoong Kang13d8c7b2012-07-14 10:20:39 +0900955 m_closing = true;
Sungjoong Kang9dd63e12012-07-24 00:25:51 +0900956
Sungjoong Kangad378612012-08-17 12:34:33 -0700957 if (m_streamThreads[1] != NULL) {
958 m_streamThreads[1]->release();
959 m_streamThreads[1]->SetSignal(SIGNAL_THREAD_TERMINATE);
960 }
961
962 if (m_streamThreads[0] != NULL) {
963 m_streamThreads[0]->release();
964 m_streamThreads[0]->SetSignal(SIGNAL_THREAD_TERMINATE);
965 }
966
Sungjoong Kang13d8c7b2012-07-14 10:20:39 +0900967 if (m_ispThread != NULL) {
968 m_ispThread->release();
Sungjoong Kang13d8c7b2012-07-14 10:20:39 +0900969 }
970
971 if (m_sensorThread != NULL) {
972 m_sensorThread->release();
Sungjoong Kang13d8c7b2012-07-14 10:20:39 +0900973 }
Jiyoung Shinc15a6b02012-06-05 01:08:14 -0700974
975 if (m_mainThread != NULL) {
Sungjoong Kang13d8c7b2012-07-14 10:20:39 +0900976 m_mainThread->release();
Jiyoung Shinc15a6b02012-06-05 01:08:14 -0700977 }
Jiyoung Shinc15a6b02012-06-05 01:08:14 -0700978
Sungjoong Kang13d8c7b2012-07-14 10:20:39 +0900979 if (m_exynosPictureCSC)
980 csc_deinit(m_exynosPictureCSC);
981 m_exynosPictureCSC = NULL;
982
Sungjoong Kang9dd63e12012-07-24 00:25:51 +0900983 if (m_exynosVideoCSC)
984 csc_deinit(m_exynosVideoCSC);
985 m_exynosVideoCSC = NULL;
986
Sungjoong Kangad378612012-08-17 12:34:33 -0700987 if (m_streamThreads[1] != NULL) {
988 while (!m_streamThreads[1]->IsTerminated())
989 {
990 ALOGD("Waiting for ISP thread is tetminated");
991 usleep(100000);
992 }
993 m_streamThreads[1] = NULL;
994 }
995
996 if (m_streamThreads[0] != NULL) {
997 while (!m_streamThreads[0]->IsTerminated())
998 {
999 ALOGD("Waiting for sensor thread is tetminated");
1000 usleep(100000);
1001 }
1002 m_streamThreads[0] = NULL;
1003 }
1004
Sungjoong Kang9dd63e12012-07-24 00:25:51 +09001005 if (m_ispThread != NULL) {
1006 while (!m_ispThread->IsTerminated())
Sungjoong Kangad378612012-08-17 12:34:33 -07001007 {
1008 ALOGD("Waiting for isp thread is tetminated");
1009 usleep(100000);
1010 }
Sungjoong Kang9dd63e12012-07-24 00:25:51 +09001011 m_ispThread = NULL;
1012 }
1013
1014 if (m_sensorThread != NULL) {
1015 while (!m_sensorThread->IsTerminated())
Sungjoong Kangad378612012-08-17 12:34:33 -07001016 {
1017 ALOGD("Waiting for sensor thread is tetminated");
1018 usleep(100000);
1019 }
Sungjoong Kang9dd63e12012-07-24 00:25:51 +09001020 m_sensorThread = NULL;
1021 }
1022
Sungjoong Kangad378612012-08-17 12:34:33 -07001023 if (m_mainThread != NULL) {
Sungjoong Kang9dd63e12012-07-24 00:25:51 +09001024 while (!m_mainThread->IsTerminated())
Sungjoong Kangad378612012-08-17 12:34:33 -07001025 {
1026 ALOGD("Waiting for main thread is tetminated");
1027 usleep(100000);
1028 }
Sungjoong Kang9dd63e12012-07-24 00:25:51 +09001029 m_mainThread = NULL;
1030 }
1031
Sungjoong Kang15fd8232012-08-23 16:16:44 -07001032 if (m_requestManager != NULL) {
1033 delete m_requestManager;
1034 m_requestManager = NULL;
1035 }
1036
1037 if (m_BayerManager != NULL) {
1038 delete m_BayerManager;
1039 m_BayerManager = NULL;
1040 }
1041// for(i = 0; i < m_camera_info.sensor.buffers; i++)
1042 for (i = 0; i < NUM_BAYER_BUFFERS; i++)
Jiyoung Shinc15a6b02012-06-05 01:08:14 -07001043 freeCameraMemory(&m_camera_info.sensor.buffer[i], m_camera_info.sensor.planes);
1044
Jiyoung Shinc15a6b02012-06-05 01:08:14 -07001045 for(i = 0; i < m_camera_info.capture.buffers; i++)
1046 freeCameraMemory(&m_camera_info.capture.buffer[i], m_camera_info.capture.planes);
1047
Sungjoong Kang9dd63e12012-07-24 00:25:51 +09001048 ALOGV("DEBUG(%s): calling exynos_v4l2_close - sensor", __FUNCTION__);
Sungjoong Kang13d8c7b2012-07-14 10:20:39 +09001049 res = exynos_v4l2_close(m_camera_info.sensor.fd);
1050 if (res != NO_ERROR ) {
Sungjoong Kang9dd63e12012-07-24 00:25:51 +09001051 ALOGE("ERR(%s): exynos_v4l2_close failed(%d)",__FUNCTION__ , res);
Sungjoong Kang13d8c7b2012-07-14 10:20:39 +09001052 }
1053
Sungjoong Kang9dd63e12012-07-24 00:25:51 +09001054 ALOGV("DEBUG(%s): calling exynos_v4l2_close - isp", __FUNCTION__);
Sungjoong Kang13d8c7b2012-07-14 10:20:39 +09001055 res = exynos_v4l2_close(m_camera_info.isp.fd);
1056 if (res != NO_ERROR ) {
Sungjoong Kang9dd63e12012-07-24 00:25:51 +09001057 ALOGE("ERR(%s): exynos_v4l2_close failed(%d)",__FUNCTION__ , res);
Sungjoong Kang13d8c7b2012-07-14 10:20:39 +09001058 }
1059
Sungjoong Kang9dd63e12012-07-24 00:25:51 +09001060 ALOGV("DEBUG(%s): calling exynos_v4l2_close - capture", __FUNCTION__);
Sungjoong Kang13d8c7b2012-07-14 10:20:39 +09001061 res = exynos_v4l2_close(m_camera_info.capture.fd);
1062 if (res != NO_ERROR ) {
Sungjoong Kang9dd63e12012-07-24 00:25:51 +09001063 ALOGE("ERR(%s): exynos_v4l2_close failed(%d)",__FUNCTION__ , res);
Sungjoong Kang13d8c7b2012-07-14 10:20:39 +09001064 }
1065
Sungjoong Kang9dd63e12012-07-24 00:25:51 +09001066 ALOGV("DEBUG(%s): calling exynos_v4l2_close - scp", __FUNCTION__);
Sungjoong Kangad378612012-08-17 12:34:33 -07001067 res = exynos_v4l2_close(m_fd_scp);
Sungjoong Kang13d8c7b2012-07-14 10:20:39 +09001068 if (res != NO_ERROR ) {
Sungjoong Kang9dd63e12012-07-24 00:25:51 +09001069 ALOGE("ERR(%s): exynos_v4l2_close failed(%d)",__FUNCTION__ , res);
Sungjoong Kang13d8c7b2012-07-14 10:20:39 +09001070 }
Sungjoong Kang9dd63e12012-07-24 00:25:51 +09001071 ALOGV("DEBUG(%s): calling deleteIonClient", __FUNCTION__);
Jiyoung Shinc15a6b02012-06-05 01:08:14 -07001072 deleteIonClient(m_ionCameraClient);
Sungjoong Kangad378612012-08-17 12:34:33 -07001073
1074 ALOGV("%s: EXIT", __func__);
1075}
1076
Sungjoong Kang6044e502012-08-27 00:29:28 -07001077int ExynosCameraHWInterface2::InitializeISPChain()
Sungjoong Kangad378612012-08-17 12:34:33 -07001078{
1079 char node_name[30];
1080 int fd = 0;
1081 int i;
Sungjoong Kang6044e502012-08-27 00:29:28 -07001082 int ret = 0;
Sungjoong Kangad378612012-08-17 12:34:33 -07001083
1084 /* Open Sensor */
1085 memset(&node_name, 0x00, sizeof(char[30]));
1086 sprintf(node_name, "%s%d", NODE_PREFIX, 40);
1087 fd = exynos_v4l2_open(node_name, O_RDWR, 0);
1088
1089 if (fd < 0) {
1090 ALOGE("ERR(%s): failed to open sensor video node (%s) fd (%d)", __FUNCTION__,node_name, fd);
1091 }
1092 else {
1093 ALOGV("DEBUG(%s): sensor video node opened(%s) fd (%d)", __FUNCTION__,node_name, fd);
1094 }
1095 m_camera_info.sensor.fd = fd;
1096
1097 /* Open ISP */
1098 memset(&node_name, 0x00, sizeof(char[30]));
1099 sprintf(node_name, "%s%d", NODE_PREFIX, 41);
1100 fd = exynos_v4l2_open(node_name, O_RDWR, 0);
1101
1102 if (fd < 0) {
1103 ALOGE("ERR(%s): failed to open isp video node (%s) fd (%d)", __FUNCTION__,node_name, fd);
1104 }
1105 else {
1106 ALOGV("DEBUG(%s): isp video node opened(%s) fd (%d)", __FUNCTION__,node_name, fd);
1107 }
1108 m_camera_info.isp.fd = fd;
1109
1110 /* Open ScalerC */
1111 memset(&node_name, 0x00, sizeof(char[30]));
1112 sprintf(node_name, "%s%d", NODE_PREFIX, 42);
1113 fd = exynos_v4l2_open(node_name, O_RDWR, 0);
1114
1115 if (fd < 0) {
1116 ALOGE("ERR(%s): failed to open capture video node (%s) fd (%d)", __FUNCTION__,node_name, fd);
1117 }
1118 else {
1119 ALOGV("DEBUG(%s): capture video node opened(%s) fd (%d)", __FUNCTION__,node_name, fd);
1120 }
1121 m_camera_info.capture.fd = fd;
1122
1123 /* Open ScalerP */
1124 memset(&node_name, 0x00, sizeof(char[30]));
1125 sprintf(node_name, "%s%d", NODE_PREFIX, 44);
1126 fd = exynos_v4l2_open(node_name, O_RDWR, 0);
1127 if (fd < 0) {
1128 ALOGE("DEBUG(%s): failed to open preview video node (%s) fd (%d)", __FUNCTION__,node_name, fd);
1129 }
1130 else {
1131 ALOGV("DEBUG(%s): preview video node opened(%s) fd (%d)", __FUNCTION__,node_name, fd);
1132 }
1133 m_fd_scp = fd;
1134
1135 if(m_cameraId == 0)
1136 m_camera_info.sensor_id = SENSOR_NAME_S5K4E5;
1137 else
1138 m_camera_info.sensor_id = SENSOR_NAME_S5K6A3;
1139
1140 memset(&m_camera_info.dummy_shot, 0x00, sizeof(struct camera2_shot_ext));
1141 m_camera_info.dummy_shot.shot.ctl.request.metadataMode = METADATA_MODE_FULL;
1142 m_camera_info.dummy_shot.shot.magicNumber = 0x23456789;
1143
1144 m_camera_info.dummy_shot.dis_bypass = 1;
1145 m_camera_info.dummy_shot.dnr_bypass = 1;
1146 m_camera_info.dummy_shot.fd_bypass = 1;
1147
1148 /*sensor setting*/
1149 m_camera_info.dummy_shot.shot.ctl.sensor.exposureTime = 0;
1150 m_camera_info.dummy_shot.shot.ctl.sensor.frameDuration = 0;
1151 m_camera_info.dummy_shot.shot.ctl.sensor.sensitivity = 0;
1152
1153 m_camera_info.dummy_shot.shot.ctl.scaler.cropRegion[0] = 0;
1154 m_camera_info.dummy_shot.shot.ctl.scaler.cropRegion[1] = 0;
1155
1156 /*request setting*/
1157 m_camera_info.dummy_shot.request_sensor = 1;
1158 m_camera_info.dummy_shot.request_scc = 0;
1159 m_camera_info.dummy_shot.request_scp = 0;
1160 m_camera_info.dummy_shot.shot.ctl.request.outputStreams[0] = 0;
1161 m_camera_info.dummy_shot.shot.ctl.request.outputStreams[1] = 0;
1162 m_camera_info.dummy_shot.shot.ctl.request.outputStreams[2] = 0;
Sungjoong Kang74d78eb2012-08-29 13:25:46 -07001163 m_camera_info.dummy_shot.shot.ctl.request.outputStreams[3] = 0;
Sungjoong Kangad378612012-08-17 12:34:33 -07001164
1165 m_camera_info.sensor.width = m_camera2->getSensorRawW();
1166 m_camera_info.sensor.height = m_camera2->getSensorRawH();
1167
1168 m_camera_info.sensor.format = V4L2_PIX_FMT_SBGGR16;
1169 m_camera_info.sensor.planes = 2;
1170 m_camera_info.sensor.buffers = NUM_BAYER_BUFFERS;
1171 m_camera_info.sensor.type = V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE;
1172 m_camera_info.sensor.memory = V4L2_MEMORY_DMABUF;
1173 m_camera_info.sensor.ionClient = m_ionCameraClient;
1174
1175 for(i = 0; i < m_camera_info.sensor.buffers; i++){
1176 initCameraMemory(&m_camera_info.sensor.buffer[i], m_camera_info.sensor.planes);
1177 m_camera_info.sensor.buffer[i].size.extS[0] = m_camera_info.sensor.width*m_camera_info.sensor.height*2;
1178 m_camera_info.sensor.buffer[i].size.extS[1] = 8*1024; // HACK, driver use 8*1024, should be use predefined value
Sungjoong Kang181e4252012-08-29 02:11:07 -07001179 allocCameraMemory(m_camera_info.sensor.ionClient, &m_camera_info.sensor.buffer[i], m_camera_info.sensor.planes, 1<<1);
Sungjoong Kangad378612012-08-17 12:34:33 -07001180 }
1181
1182 m_camera_info.isp.width = m_camera_info.sensor.width;
1183 m_camera_info.isp.height = m_camera_info.sensor.height;
1184 m_camera_info.isp.format = m_camera_info.sensor.format;
1185 m_camera_info.isp.planes = m_camera_info.sensor.planes;
1186 m_camera_info.isp.buffers = m_camera_info.sensor.buffers;
1187 m_camera_info.isp.type = V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE;
1188 m_camera_info.isp.memory = V4L2_MEMORY_DMABUF;
1189 m_camera_info.isp.ionClient = m_ionCameraClient;
1190
1191 for(i = 0; i < m_camera_info.isp.buffers; i++){
1192 initCameraMemory(&m_camera_info.isp.buffer[i], m_camera_info.isp.planes);
1193 m_camera_info.isp.buffer[i].size.extS[0] = m_camera_info.sensor.buffer[i].size.extS[0];
1194 m_camera_info.isp.buffer[i].size.extS[1] = m_camera_info.sensor.buffer[i].size.extS[1];
1195 m_camera_info.isp.buffer[i].fd.extFd[0] = m_camera_info.sensor.buffer[i].fd.extFd[0];
1196 m_camera_info.isp.buffer[i].fd.extFd[1] = m_camera_info.sensor.buffer[i].fd.extFd[1];
1197 m_camera_info.isp.buffer[i].virt.extP[0] = m_camera_info.sensor.buffer[i].virt.extP[0];
1198 m_camera_info.isp.buffer[i].virt.extP[1] = m_camera_info.sensor.buffer[i].virt.extP[1];
1199 };
1200
1201 /* init ISP */
Sungjoong Kang6044e502012-08-27 00:29:28 -07001202 ret = cam_int_s_input(&(m_camera_info.isp), m_camera_info.sensor_id);
1203 if (ret < 0) {
1204 ALOGE("ERR(%s): cam_int_s_input(%d) failed!!!! ", __FUNCTION__, m_camera_info.sensor_id);
1205 return false;
1206 }
Sungjoong Kangad378612012-08-17 12:34:33 -07001207 cam_int_s_fmt(&(m_camera_info.isp));
1208 ALOGV("DEBUG(%s): isp calling reqbuf", __FUNCTION__);
1209 cam_int_reqbufs(&(m_camera_info.isp));
1210 ALOGV("DEBUG(%s): isp calling querybuf", __FUNCTION__);
1211 ALOGV("DEBUG(%s): isp mem alloc done", __FUNCTION__);
1212
1213 /* init Sensor */
1214 cam_int_s_input(&(m_camera_info.sensor), m_camera_info.sensor_id);
1215 ALOGV("DEBUG(%s): sensor s_input done", __FUNCTION__);
1216 if (cam_int_s_fmt(&(m_camera_info.sensor))< 0) {
1217 ALOGE("ERR(%s): sensor s_fmt fail", __FUNCTION__);
1218 }
1219 ALOGV("DEBUG(%s): sensor s_fmt done", __FUNCTION__);
1220 cam_int_reqbufs(&(m_camera_info.sensor));
1221 ALOGV("DEBUG(%s): sensor reqbuf done", __FUNCTION__);
1222 for (i = 0; i < m_camera_info.sensor.buffers; i++) {
1223 ALOGV("DEBUG(%s): sensor initial QBUF [%d]", __FUNCTION__, i);
1224 memcpy( m_camera_info.sensor.buffer[i].virt.extP[1], &(m_camera_info.dummy_shot),
1225 sizeof(struct camera2_shot_ext));
1226 m_camera_info.dummy_shot.shot.ctl.sensor.frameDuration = 33*1000*1000; // apply from frame #1
1227 m_camera_info.dummy_shot.shot.ctl.request.frameCount = -1;
1228 cam_int_qbuf(&(m_camera_info.sensor), i);
1229 }
1230 ALOGV("== stream_on :: .sensor");
1231 cam_int_streamon(&(m_camera_info.sensor));
1232
1233 /* init Capture */
1234 m_camera_info.capture.width = m_camera2->getSensorW();
1235 m_camera_info.capture.height = m_camera2->getSensorH();
1236 m_camera_info.capture.format = V4L2_PIX_FMT_YUYV;
Sungjoong Kangfeb7df42012-08-28 23:35:43 +09001237#ifdef ENABLE_FRAME_SYNC
1238 m_camera_info.capture.planes = 2;
1239#else
Sungjoong Kangad378612012-08-17 12:34:33 -07001240 m_camera_info.capture.planes = 1;
Sungjoong Kangfeb7df42012-08-28 23:35:43 +09001241#endif
Sungjoong Kangad378612012-08-17 12:34:33 -07001242 m_camera_info.capture.buffers = 8;
1243 m_camera_info.capture.type = V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE;
1244 m_camera_info.capture.memory = V4L2_MEMORY_DMABUF;
1245 m_camera_info.capture.ionClient = m_ionCameraClient;
1246
1247 for(i = 0; i < m_camera_info.capture.buffers; i++){
1248 initCameraMemory(&m_camera_info.capture.buffer[i], m_camera_info.capture.planes);
1249 m_camera_info.capture.buffer[i].size.extS[0] = m_camera_info.capture.width*m_camera_info.capture.height*2;
Sungjoong Kangfeb7df42012-08-28 23:35:43 +09001250#ifdef ENABLE_FRAME_SYNC
1251 m_camera_info.capture.buffer[i].size.extS[1] = 4*1024; // HACK, driver use 4*1024, should be use predefined value
1252#endif
Sungjoong Kangad378612012-08-17 12:34:33 -07001253 allocCameraMemory(m_camera_info.capture.ionClient, &m_camera_info.capture.buffer[i], m_camera_info.capture.planes);
1254 }
1255
1256 cam_int_s_input(&(m_camera_info.capture), m_camera_info.sensor_id);
1257 cam_int_s_fmt(&(m_camera_info.capture));
1258 ALOGV("DEBUG(%s): capture calling reqbuf", __FUNCTION__);
1259 cam_int_reqbufs(&(m_camera_info.capture));
1260 ALOGV("DEBUG(%s): capture calling querybuf", __FUNCTION__);
1261
1262 for (i = 0; i < m_camera_info.capture.buffers; i++) {
1263 ALOGV("DEBUG(%s): capture initial QBUF [%d]", __FUNCTION__, i);
1264 cam_int_qbuf(&(m_camera_info.capture), i);
1265 }
1266
1267 ALOGV("== stream_on :: capture");
Sungjoong Kang15fd8232012-08-23 16:16:44 -07001268 if (cam_int_streamon(&(m_camera_info.capture)) < 0) {
1269 ALOGE("ERR(%s): capture stream on fail", __FUNCTION__);
1270 } else {
1271 m_camera_info.capture.status = true;
1272 }
Sungjoong Kang6044e502012-08-27 00:29:28 -07001273
1274 return true;
Sungjoong Kangad378612012-08-17 12:34:33 -07001275}
1276
1277void ExynosCameraHWInterface2::StartISP()
1278{
Sungjoong Kangad378612012-08-17 12:34:33 -07001279 ALOGV("== stream_on :: isp");
1280 cam_int_streamon(&(m_camera_info.isp));
Sungjoong Kangad378612012-08-17 12:34:33 -07001281 exynos_v4l2_s_ctrl(m_camera_info.sensor.fd, V4L2_CID_IS_S_STREAM, IS_ENABLE_STREAM);
Sungjoong Kang13d8c7b2012-07-14 10:20:39 +09001282}
1283
Jiyoung Shinc15a6b02012-06-05 01:08:14 -07001284int ExynosCameraHWInterface2::getCameraId() const
1285{
Sungjoong Kang9dd63e12012-07-24 00:25:51 +09001286 return m_cameraId;
Jiyoung Shinc15a6b02012-06-05 01:08:14 -07001287}
Jiyoung Shinc15a6b02012-06-05 01:08:14 -07001288
1289int ExynosCameraHWInterface2::setRequestQueueSrcOps(const camera2_request_queue_src_ops_t *request_src_ops)
1290{
Sungjoong Kang13d8c7b2012-07-14 10:20:39 +09001291 ALOGV("DEBUG(%s):", __FUNCTION__);
Jiyoung Shinc15a6b02012-06-05 01:08:14 -07001292 if ((NULL != request_src_ops) && (NULL != request_src_ops->dequeue_request)
1293 && (NULL != request_src_ops->free_request) && (NULL != request_src_ops->request_count)) {
1294 m_requestQueueOps = (camera2_request_queue_src_ops_t*)request_src_ops;
1295 return 0;
1296 }
1297 else {
Sungjoong Kang13d8c7b2012-07-14 10:20:39 +09001298 ALOGE("DEBUG(%s):setRequestQueueSrcOps : NULL arguments", __FUNCTION__);
Jiyoung Shinc15a6b02012-06-05 01:08:14 -07001299 return 1;
1300 }
1301}
1302
1303int ExynosCameraHWInterface2::notifyRequestQueueNotEmpty()
1304{
Sungjoong Kangb5237e62012-07-27 07:39:05 -07001305 ALOGV("DEBUG(%s):setting [SIGNAL_MAIN_REQ_Q_NOT_EMPTY] current(%d)", __FUNCTION__, m_requestManager->GetNumEntries());
Jiyoung Shinc15a6b02012-06-05 01:08:14 -07001306 if ((NULL==m_frameQueueOps)|| (NULL==m_requestQueueOps)) {
Sungjoong Kang13d8c7b2012-07-14 10:20:39 +09001307 ALOGE("DEBUG(%s):queue ops NULL. ignoring request", __FUNCTION__);
Jiyoung Shinc15a6b02012-06-05 01:08:14 -07001308 return 0;
1309 }
Sungjoong Kang13d8c7b2012-07-14 10:20:39 +09001310 m_isRequestQueueNull = false;
Sungjoong Kang0f26b202012-08-17 15:43:12 -07001311 if (m_requestManager->GetNumEntries() == 0)
1312 m_requestManager->SetInitialSkip(5);
Jiyoung Shinc15a6b02012-06-05 01:08:14 -07001313 m_mainThread->SetSignal(SIGNAL_MAIN_REQ_Q_NOT_EMPTY);
1314 return 0;
1315}
1316
1317int ExynosCameraHWInterface2::setFrameQueueDstOps(const camera2_frame_queue_dst_ops_t *frame_dst_ops)
1318{
Sungjoong Kang13d8c7b2012-07-14 10:20:39 +09001319 ALOGV("DEBUG(%s):", __FUNCTION__);
Jiyoung Shinc15a6b02012-06-05 01:08:14 -07001320 if ((NULL != frame_dst_ops) && (NULL != frame_dst_ops->dequeue_frame)
1321 && (NULL != frame_dst_ops->cancel_frame) && (NULL !=frame_dst_ops->enqueue_frame)) {
1322 m_frameQueueOps = (camera2_frame_queue_dst_ops_t *)frame_dst_ops;
1323 return 0;
1324 }
1325 else {
Sungjoong Kang13d8c7b2012-07-14 10:20:39 +09001326 ALOGE("DEBUG(%s):setFrameQueueDstOps : NULL arguments", __FUNCTION__);
Jiyoung Shinc15a6b02012-06-05 01:08:14 -07001327 return 1;
1328 }
1329}
1330
1331int ExynosCameraHWInterface2::getInProgressCount()
1332{
1333 int inProgressCount = m_requestManager->GetNumEntries();
Sungjoong Kang13d8c7b2012-07-14 10:20:39 +09001334 ALOGV("DEBUG(%s): # of dequeued req (%d)", __FUNCTION__, inProgressCount);
Jiyoung Shinc15a6b02012-06-05 01:08:14 -07001335 return inProgressCount;
1336}
1337
1338int ExynosCameraHWInterface2::flushCapturesInProgress()
1339{
1340 return 0;
1341}
1342
Jiyoung Shinc15a6b02012-06-05 01:08:14 -07001343int ExynosCameraHWInterface2::constructDefaultRequest(int request_template, camera_metadata_t **request)
1344{
Sungjoong Kang13d8c7b2012-07-14 10:20:39 +09001345 ALOGV("DEBUG(%s): making template (%d) ", __FUNCTION__, request_template);
Jiyoung Shinc15a6b02012-06-05 01:08:14 -07001346
1347 if (request == NULL) return BAD_VALUE;
1348 if (request_template < 0 || request_template >= CAMERA2_TEMPLATE_COUNT) {
1349 return BAD_VALUE;
1350 }
1351 status_t res;
1352 // Pass 1, calculate size and allocate
Sungjoong Kangdaa1fcd2012-08-08 11:49:43 -07001353 res = m_camera2->constructDefaultRequest(request_template,
Jiyoung Shinc15a6b02012-06-05 01:08:14 -07001354 request,
1355 true);
1356 if (res != OK) {
1357 return res;
1358 }
1359 // Pass 2, build request
Sungjoong Kangdaa1fcd2012-08-08 11:49:43 -07001360 res = m_camera2->constructDefaultRequest(request_template,
Jiyoung Shinc15a6b02012-06-05 01:08:14 -07001361 request,
1362 false);
1363 if (res != OK) {
1364 ALOGE("Unable to populate new request for template %d",
1365 request_template);
1366 }
1367
1368 return res;
1369}
1370
1371int ExynosCameraHWInterface2::allocateStream(uint32_t width, uint32_t height, int format, const camera2_stream_ops_t *stream_ops,
1372 uint32_t *stream_id, uint32_t *format_actual, uint32_t *usage, uint32_t *max_buffers)
1373{
Sungjoong Kangad378612012-08-17 12:34:33 -07001374 ALOGV("DEBUG(%s): allocate stream width(%d) height(%d) format(%x)", __FUNCTION__, width, height, format);
Jiyoung Shinc15a6b02012-06-05 01:08:14 -07001375 char node_name[30];
Sungjoong Kang9dd63e12012-07-24 00:25:51 +09001376 int fd = 0, allocCase = 0;
Sungjoong Kang13d8c7b2012-07-14 10:20:39 +09001377 StreamThread *AllocatedStream;
1378 stream_parameters_t newParameters;
Jiyoung Shinc15a6b02012-06-05 01:08:14 -07001379
Sungjoong Kangdaa1fcd2012-08-08 11:49:43 -07001380 if (format == CAMERA2_HAL_PIXEL_FORMAT_OPAQUE &&
1381 m_camera2->isSupportedResolution(width, height)) {
Sungjoong Kang9dd63e12012-07-24 00:25:51 +09001382 if (!(m_streamThreads[0].get())) {
1383 ALOGV("DEBUG(%s): stream 0 not exist", __FUNCTION__);
1384 allocCase = 0;
Jiyoung Shinc15a6b02012-06-05 01:08:14 -07001385 }
Sungjoong Kang13d8c7b2012-07-14 10:20:39 +09001386 else {
Alex Ray6bbb5932012-07-27 17:19:48 -07001387 if ((m_streamThreads[0].get())->m_activated == true) {
Sungjoong Kang9dd63e12012-07-24 00:25:51 +09001388 ALOGV("DEBUG(%s): stream 0 exists and activated.", __FUNCTION__);
1389 allocCase = 1;
1390 }
1391 else {
1392 ALOGV("DEBUG(%s): stream 0 exists and deactivated.", __FUNCTION__);
1393 allocCase = 2;
1394 }
Sungjoong Kang13d8c7b2012-07-14 10:20:39 +09001395 }
hyeonmyeong Choia44c3362012-08-30 19:01:25 -07001396 if ((width == 1920 && height == 1080) || (width == 1280 && height == 720) || (width == 720 && height == 480)) {
Sungjoong Kang15fd8232012-08-23 16:16:44 -07001397 m_wideAspect = true;
1398 }
1399 else {
1400 m_wideAspect = false;
1401 }
Sungjoong Kangb55ed662012-08-31 21:31:34 -07001402 m_aspectChanged = true;
Sungjoong Kang15fd8232012-08-23 16:16:44 -07001403 ALOGV("DEBUG(%s): m_wideAspect (%d)", __FUNCTION__, m_wideAspect);
1404
Sungjoong Kang9dd63e12012-07-24 00:25:51 +09001405 if (allocCase == 0 || allocCase == 2) {
1406 *stream_id = 0;
Jiyoung Shinc15a6b02012-06-05 01:08:14 -07001407
Sungjoong Kang9dd63e12012-07-24 00:25:51 +09001408 if (allocCase == 0) {
1409 m_streamThreads[0] = new StreamThread(this, *stream_id);
Sungjoong Kang9dd63e12012-07-24 00:25:51 +09001410 }
1411 AllocatedStream = (StreamThread*)(m_streamThreads[0].get());
Sungjoong Kangb5237e62012-07-27 07:39:05 -07001412 m_scp_flushing = false;
1413 m_scp_closing = false;
1414 m_scp_closed = false;
Sungjoong Kang9dd63e12012-07-24 00:25:51 +09001415 usleep(100000); // TODO : guarantee the codes below will be run after readyToRunInternal()
Jiyoung Shinc15a6b02012-06-05 01:08:14 -07001416
Rebecca Schultz Zavinc853be72012-08-23 00:03:05 -07001417 *format_actual = HAL_PIXEL_FORMAT_EXYNOS_YV12;
Alex Ray6bbb5932012-07-27 17:19:48 -07001418 *usage = GRALLOC_USAGE_SW_WRITE_OFTEN;
Sungjoong Kangb55ed662012-08-31 21:31:34 -07001419 *max_buffers = 6;
Jiyoung Shinc15a6b02012-06-05 01:08:14 -07001420
Sungjoong Kang37e122d2012-08-08 11:13:48 -07001421 newParameters.streamType = STREAM_TYPE_DIRECT;
Sungjoong Kang9dd63e12012-07-24 00:25:51 +09001422 newParameters.outputWidth = width;
1423 newParameters.outputHeight = height;
1424 newParameters.nodeWidth = width;
1425 newParameters.nodeHeight = height;
1426 newParameters.outputFormat = *format_actual;
1427 newParameters.nodeFormat = HAL_PIXEL_FORMAT_2_V4L2_PIX(*format_actual);
1428 newParameters.streamOps = stream_ops;
1429 newParameters.usage = *usage;
Sungjoong Kangbe494d12012-08-04 15:36:56 -07001430 newParameters.numHwBuffers = 8;
1431 newParameters.numOwnSvcBuffers = *max_buffers;
Sungjoong Kang9dd63e12012-07-24 00:25:51 +09001432 newParameters.fd = m_fd_scp;
Sungjoong Kang74d78eb2012-08-29 13:25:46 -07001433 newParameters.nodePlanes = NUM_PLANES(*format_actual);
1434 newParameters.svcPlanes = NUM_PLANES(*format_actual);
Sungjoong Kangfeb7df42012-08-28 23:35:43 +09001435 newParameters.metaPlanes = 1;
Sungjoong Kang9dd63e12012-07-24 00:25:51 +09001436 newParameters.halBuftype = V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE;
1437 newParameters.memory = V4L2_MEMORY_DMABUF;
1438 newParameters.ionClient = m_ionCameraClient;
Sungjoong Kangbe494d12012-08-04 15:36:56 -07001439 newParameters.numSvcBufsInHal = 0;
Sungjoong Kang9dd63e12012-07-24 00:25:51 +09001440 AllocatedStream->m_index = *stream_id;
1441 AllocatedStream->setParameter(&newParameters);
1442 AllocatedStream->m_activated = true;
Sungjoong Kang13d8c7b2012-07-14 10:20:39 +09001443
Sungjoong Kang9dd63e12012-07-24 00:25:51 +09001444 m_scp_flushing = false;
1445 m_scp_closing = false;
1446 m_scp_closed = false;
Sungjoong Kangad378612012-08-17 12:34:33 -07001447 m_requestManager->SetDefaultParameters(m_camera2->getSensorW());
1448 m_camera_info.dummy_shot.shot.ctl.scaler.cropRegion[2] = m_camera2->getSensorW();
Sungjoong Kang9dd63e12012-07-24 00:25:51 +09001449 return 0;
1450 }
1451 else if (allocCase == 1) {
1452 record_parameters_t recordParameters;
1453 StreamThread *parentStream;
1454 parentStream = (StreamThread*)(m_streamThreads[0].get());
1455 if (!parentStream) {
1456 return 1;
1457 // TODO
1458 }
1459 *stream_id = 2;
1460 usleep(100000); // TODO : guarantee the codes below will be run after readyToRunInternal()
1461
Sungjoong Kang804236a2012-08-05 10:36:19 -07001462 *format_actual = HAL_PIXEL_FORMAT_YCbCr_420_SP; // NV12M
Alex Ray6bbb5932012-07-27 17:19:48 -07001463 *usage = GRALLOC_USAGE_SW_WRITE_OFTEN;
James Dong26306792012-08-24 14:42:26 -07001464 *max_buffers = 6;
Sungjoong Kang9dd63e12012-07-24 00:25:51 +09001465
1466 recordParameters.outputWidth = width;
1467 recordParameters.outputHeight = height;
1468 recordParameters.outputFormat = *format_actual;
Sungjoong Kang804236a2012-08-05 10:36:19 -07001469 recordParameters.svcPlanes = NUM_PLANES(*format_actual);
Sungjoong Kang9dd63e12012-07-24 00:25:51 +09001470 recordParameters.streamOps = stream_ops;
1471 recordParameters.usage = *usage;
Sungjoong Kangbe494d12012-08-04 15:36:56 -07001472 recordParameters.numOwnSvcBuffers = *max_buffers;
1473 recordParameters.numSvcBufsInHal = 0;
Sungjoong Kang9dd63e12012-07-24 00:25:51 +09001474
1475 parentStream->setRecordingParameter(&recordParameters);
1476 m_scp_flushing = false;
1477 m_scp_closing = false;
1478 m_scp_closed = false;
1479 m_recordingEnabled = true;
1480 return 0;
1481 }
Sungjoong Kang13d8c7b2012-07-14 10:20:39 +09001482 }
Sungjoong Kangad378612012-08-17 12:34:33 -07001483 else if (format == HAL_PIXEL_FORMAT_BLOB
Sungjoong Kangdaa1fcd2012-08-08 11:49:43 -07001484 && m_camera2->isSupportedJpegResolution(width, height)) {
Sungjoong Kang13d8c7b2012-07-14 10:20:39 +09001485
1486 *stream_id = 1;
1487
Sungjoong Kang15fd8232012-08-23 16:16:44 -07001488 if (!(m_streamThreads[*stream_id].get())) {
Sungjoong Kang8e2c2fd2012-08-27 00:02:22 -07001489 ALOGV("DEBUG(%s): stream 1 not exist", __FUNCTION__);
Sungjoong Kang15fd8232012-08-23 16:16:44 -07001490 m_streamThreads[1] = new StreamThread(this, *stream_id);
1491 allocCase = 0;
1492 }
1493 else {
1494 if ((m_streamThreads[*stream_id].get())->m_activated == true) {
Sungjoong Kang8e2c2fd2012-08-27 00:02:22 -07001495 ALOGV("DEBUG(%s): stream 1 exists and activated.", __FUNCTION__);
Sungjoong Kang15fd8232012-08-23 16:16:44 -07001496 allocCase = 1;
1497 }
1498 else {
Sungjoong Kang8e2c2fd2012-08-27 00:02:22 -07001499 ALOGV("DEBUG(%s): stream 1 exists and deactivated.", __FUNCTION__);
Sungjoong Kang15fd8232012-08-23 16:16:44 -07001500 allocCase = 2;
1501 }
1502 }
1503
1504 AllocatedStream = (StreamThread*)(m_streamThreads[*stream_id].get());
Sungjoong Kang9dd63e12012-07-24 00:25:51 +09001505
Sungjoong Kang13d8c7b2012-07-14 10:20:39 +09001506 fd = m_camera_info.capture.fd;
1507 usleep(100000); // TODO : guarantee the codes below will be run after readyToRunInternal()
1508
1509 *format_actual = HAL_PIXEL_FORMAT_BLOB;
1510
1511 *usage = GRALLOC_USAGE_SW_WRITE_OFTEN;
Sungjoong Kang37e122d2012-08-08 11:13:48 -07001512 *max_buffers = 4;
Sungjoong Kang13d8c7b2012-07-14 10:20:39 +09001513
Sungjoong Kang37e122d2012-08-08 11:13:48 -07001514 newParameters.streamType = STREAM_TYPE_INDIRECT;
Sungjoong Kang13d8c7b2012-07-14 10:20:39 +09001515 newParameters.outputWidth = width;
1516 newParameters.outputHeight = height;
Sungjoong Kang9dd63e12012-07-24 00:25:51 +09001517
Sungjoong Kangdaa1fcd2012-08-08 11:49:43 -07001518 newParameters.nodeWidth = m_camera2->getSensorW();
1519 newParameters.nodeHeight = m_camera2->getSensorH();
Sungjoong Kang9dd63e12012-07-24 00:25:51 +09001520
Sungjoong Kang13d8c7b2012-07-14 10:20:39 +09001521 newParameters.outputFormat = *format_actual;
1522 newParameters.nodeFormat = V4L2_PIX_FMT_YUYV;
1523 newParameters.streamOps = stream_ops;
1524 newParameters.usage = *usage;
Sungjoong Kangbe494d12012-08-04 15:36:56 -07001525 newParameters.numHwBuffers = 8;
1526 newParameters.numOwnSvcBuffers = *max_buffers;
Sungjoong Kang13d8c7b2012-07-14 10:20:39 +09001527 newParameters.fd = fd;
1528 newParameters.nodePlanes = 1;
1529 newParameters.svcPlanes = 1;
1530 newParameters.halBuftype = V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE;
1531 newParameters.memory = V4L2_MEMORY_DMABUF;
1532 newParameters.ionClient = m_ionCameraClient;
Sungjoong Kangbe494d12012-08-04 15:36:56 -07001533 newParameters.numSvcBufsInHal = 0;
Sungjoong Kang9dd63e12012-07-24 00:25:51 +09001534 AllocatedStream->m_index = *stream_id;
Sungjoong Kang13d8c7b2012-07-14 10:20:39 +09001535 AllocatedStream->setParameter(&newParameters);
1536 return 0;
1537 }
Sungjoong Kang74d78eb2012-08-29 13:25:46 -07001538 else if (format == HAL_PIXEL_FORMAT_YCrCb_420_SP || format == HAL_PIXEL_FORMAT_YV12) {
1539 StreamThread *parentStream;
1540 callback_parameters_t callbackParameters;
1541 parentStream = (StreamThread*)(m_streamThreads[0].get());
1542 if (!parentStream) {
1543 ALOGE("(%s): preview stream not exist", __FUNCTION__);
1544 return 1;
1545 }
1546 *stream_id = 3;
1547
1548 *format_actual = format;
1549 *usage = GRALLOC_USAGE_SW_WRITE_OFTEN;
1550 *max_buffers = 4;
1551 if (width == parentStream->m_parameters.outputWidth
1552 && height == parentStream->m_parameters.outputHeight) {
1553
1554 callbackParameters.outputWidth = width;
1555 callbackParameters.outputHeight = height;
1556 callbackParameters.outputFormat = *format_actual;
1557 callbackParameters.svcPlanes = NUM_PLANES(*format_actual);
1558 callbackParameters.streamOps = stream_ops;
1559 callbackParameters.usage = *usage;
1560 callbackParameters.numOwnSvcBuffers = *max_buffers;
1561 callbackParameters.numSvcBufsInHal = 0;
1562 if (format == HAL_PIXEL_FORMAT_YCrCb_420_SP) {
1563 callbackParameters.internalFormat = HAL_PIXEL_FORMAT_EXYNOS_YCrCb_420_SP;
1564 callbackParameters.internalPlanes = NUM_PLANES(HAL_PIXEL_FORMAT_EXYNOS_YCrCb_420_SP);
1565 }
1566 else {
1567 callbackParameters.internalFormat = HAL_PIXEL_FORMAT_EXYNOS_YV12;
1568 callbackParameters.internalPlanes = NUM_PLANES(HAL_PIXEL_FORMAT_EXYNOS_YV12);
1569 }
1570
1571 parentStream->setCallbackParameter(&callbackParameters);
1572 m_previewCbEnabled = true;
1573 ALOGV("(%s): Enabling Previewcb - planes(%d)", __FUNCTION__, callbackParameters.svcPlanes);
1574 }
1575 return 0;
1576 }
Sungjoong Kang13d8c7b2012-07-14 10:20:39 +09001577 ALOGE("DEBUG(%s): Unsupported Pixel Format", __FUNCTION__);
1578 return 1; // TODO : check proper error code
1579}
1580
1581int ExynosCameraHWInterface2::registerStreamBuffers(uint32_t stream_id,
1582 int num_buffers, buffer_handle_t *registeringBuffers)
1583{
1584 int i,j;
1585 void *virtAddr[3];
1586 uint32_t plane_index = 0;
1587 stream_parameters_t *targetStreamParms;
Sungjoong Kang9dd63e12012-07-24 00:25:51 +09001588 record_parameters_t *targetRecordParms;
Sungjoong Kang74d78eb2012-08-29 13:25:46 -07001589 callback_parameters_t *targetCallbackParms;
Sungjoong Kang13d8c7b2012-07-14 10:20:39 +09001590 node_info_t *currentNode;
1591
1592 struct v4l2_buffer v4l2_buf;
1593 struct v4l2_plane planes[VIDEO_MAX_PLANES];
1594
1595 ALOGV("DEBUG(%s): streamID (%d), num_buff(%d), handle(%x) ", __FUNCTION__,
1596 stream_id, num_buffers, (uint32_t)registeringBuffers);
1597
1598 if (stream_id == 0) {
1599 targetStreamParms = &(m_streamThreads[0]->m_parameters);
1600 }
1601 else if (stream_id == 1) {
1602 targetStreamParms = &(m_streamThreads[1]->m_parameters);
Sungjoong Kang15fd8232012-08-23 16:16:44 -07001603 // TODO : make clear stream off case
1604 m_need_streamoff = 0;
1605
1606 if (m_camera_info.capture.status == false) {
1607 /* capture */
1608 m_camera_info.capture.buffers = 8;
1609 cam_int_s_fmt(&(m_camera_info.capture));
1610 cam_int_reqbufs(&(m_camera_info.capture));
1611 for (i = 0; i < m_camera_info.capture.buffers; i++) {
1612 ALOGV("DEBUG(%s): capture initial QBUF [%d]", __FUNCTION__, i);
1613 cam_int_qbuf(&(m_camera_info.capture), i);
1614 }
1615
1616 if (cam_int_streamon(&(m_camera_info.capture)) < 0) {
1617 ALOGE("ERR(%s): capture stream on fail", __FUNCTION__);
1618 } else {
1619 m_camera_info.capture.status = true;
1620 }
1621 }
Sungjoong Kang13d8c7b2012-07-14 10:20:39 +09001622 }
Sungjoong Kang9dd63e12012-07-24 00:25:51 +09001623 else if (stream_id == 2) {
1624 targetRecordParms = &(m_streamThreads[0]->m_recordParameters);
1625
1626 targetRecordParms->numSvcBuffers = num_buffers;
1627
1628 for (i = 0 ; i<targetRecordParms->numSvcBuffers ; i++) {
1629 ALOGV("DEBUG(%s): registering Stream Buffers[%d] (%x) ", __FUNCTION__,
1630 i, (uint32_t)(registeringBuffers[i]));
1631 if (m_grallocHal) {
1632 if (m_grallocHal->lock(m_grallocHal, registeringBuffers[i],
1633 targetRecordParms->usage, 0, 0,
1634 targetRecordParms->outputWidth, targetRecordParms->outputHeight, virtAddr) != 0) {
1635 ALOGE("ERR(%s): could not obtain gralloc buffer", __FUNCTION__);
1636 }
1637 else {
1638 ExynosBuffer currentBuf;
1639 const private_handle_t *priv_handle = reinterpret_cast<const private_handle_t *>(registeringBuffers[i]);
Sungjoong Kang9dd63e12012-07-24 00:25:51 +09001640 currentBuf.fd.extFd[0] = priv_handle->fd;
Alex Ray6bbb5932012-07-27 17:19:48 -07001641 currentBuf.fd.extFd[1] = priv_handle->fd1;
1642 currentBuf.fd.extFd[2] = priv_handle->fd2;
Sungjoong Kang9dd63e12012-07-24 00:25:51 +09001643 for (plane_index=0 ; plane_index < targetRecordParms->svcPlanes ; plane_index++) {
1644 currentBuf.virt.extP[plane_index] = (char *)virtAddr[plane_index];
1645 ALOGV("DEBUG(%s): plane(%d): fd(%d) addr(%x)",
Sungjoong Kang804236a2012-08-05 10:36:19 -07001646 __FUNCTION__, plane_index, currentBuf.fd.extFd[plane_index],
Sungjoong Kang9dd63e12012-07-24 00:25:51 +09001647 (unsigned int)currentBuf.virt.extP[plane_index]);
1648 }
1649 targetRecordParms->svcBufStatus[i] = ON_SERVICE;
Sungjoong Kangb5237e62012-07-27 07:39:05 -07001650 targetRecordParms->svcBuffers[i] = currentBuf;
1651 targetRecordParms->svcBufHandle[i] = registeringBuffers[i];
Sungjoong Kang9dd63e12012-07-24 00:25:51 +09001652 }
1653 }
1654 }
1655 m_needsRecordBufferInit = true;
1656 return 0;
1657 }
Sungjoong Kang74d78eb2012-08-29 13:25:46 -07001658 else if (stream_id == 3) {
1659 targetCallbackParms = &(m_streamThreads[0]->m_previewCbParameters);
1660
1661 targetCallbackParms->numSvcBuffers = num_buffers;
1662
1663 for (i = 0 ; i < targetCallbackParms->numSvcBuffers ; i++) {
1664 ALOGE("%s: registering Stream Buffers[%d] (%x) ", __FUNCTION__,
1665 i, (uint32_t)(registeringBuffers[i]));
1666 if (m_grallocHal) {
1667 if (m_grallocHal->lock(m_grallocHal, registeringBuffers[i],
1668 targetCallbackParms->usage, 0, 0,
1669 targetCallbackParms->outputWidth, targetCallbackParms->outputHeight, virtAddr) != 0) {
1670 ALOGE("ERR(%s): could not obtain gralloc buffer", __FUNCTION__);
1671 }
1672 else {
1673 ExynosBuffer currentBuf;
1674 const private_handle_t *priv_handle = reinterpret_cast<const private_handle_t *>(registeringBuffers[i]);
1675 currentBuf.fd.extFd[0] = priv_handle->fd;
1676 currentBuf.fd.extFd[1] = priv_handle->fd1;
1677 currentBuf.fd.extFd[2] = priv_handle->fd2;
1678 for (plane_index = 0 ; plane_index < targetCallbackParms->svcPlanes ; plane_index++) {
1679 currentBuf.virt.extP[plane_index] = (char *)virtAddr[plane_index];
1680 }
1681 ALOGV("fd(%d) addr(%x) fd1(%d) fd2(%d)", priv_handle->fd, (unsigned int)currentBuf.virt.extP[plane_index],
1682 priv_handle->fd1, priv_handle->fd2);
1683 ALOGV("flags(%d) size(%d) offset(%d) stride(%d) vstride(%d)",
1684 priv_handle->flags, priv_handle->size, priv_handle->offset,
1685 priv_handle->stride, priv_handle->vstride);
1686 targetCallbackParms->svcBufStatus[i] = ON_SERVICE;
1687 targetCallbackParms->svcBuffers[i] = currentBuf;
1688 targetCallbackParms->svcBufHandle[i] = registeringBuffers[i];
1689 }
1690 }
1691 }
1692 m_needsPreviewCbBufferInit = true;
1693 return 0;
1694 }
Sungjoong Kang13d8c7b2012-07-14 10:20:39 +09001695 else {
1696 ALOGE("ERR(%s) unregisterd stream id (%d)", __FUNCTION__, stream_id);
Sungjoong Kangbe494d12012-08-04 15:36:56 -07001697 return 1;
Sungjoong Kang13d8c7b2012-07-14 10:20:39 +09001698 }
1699
Sungjoong Kang37e122d2012-08-08 11:13:48 -07001700 if (targetStreamParms->streamType == STREAM_TYPE_DIRECT) {
Sungjoong Kang13d8c7b2012-07-14 10:20:39 +09001701 if (num_buffers < targetStreamParms->numHwBuffers) {
1702 ALOGE("ERR(%s) registering insufficient num of buffers (%d) < (%d)",
1703 __FUNCTION__, num_buffers, targetStreamParms->numHwBuffers);
Sungjoong Kangbe494d12012-08-04 15:36:56 -07001704 return 1;
Sungjoong Kang13d8c7b2012-07-14 10:20:39 +09001705 }
1706 }
1707 ALOGV("DEBUG(%s): format(%x) width(%d), height(%d) svcPlanes(%d)",
1708 __FUNCTION__, targetStreamParms->outputFormat, targetStreamParms->outputWidth,
1709 targetStreamParms->outputHeight, targetStreamParms->svcPlanes);
1710
1711 targetStreamParms->numSvcBuffers = num_buffers;
1712 currentNode = &(targetStreamParms->node); // TO Remove
1713
1714 currentNode->fd = targetStreamParms->fd;
1715 currentNode->width = targetStreamParms->nodeWidth;
1716 currentNode->height = targetStreamParms->nodeHeight;
1717 currentNode->format = targetStreamParms->nodeFormat;
1718 currentNode->planes = targetStreamParms->nodePlanes;
1719 currentNode->buffers = targetStreamParms->numHwBuffers;
1720 currentNode->type = targetStreamParms->halBuftype;
1721 currentNode->memory = targetStreamParms->memory;
1722 currentNode->ionClient = targetStreamParms->ionClient;
1723
Sungjoong Kang37e122d2012-08-08 11:13:48 -07001724 if (targetStreamParms->streamType == STREAM_TYPE_DIRECT) {
Sungjoong Kangad378612012-08-17 12:34:33 -07001725 if(m_need_streamoff == 1) {
Sungjoong Kang15fd8232012-08-23 16:16:44 -07001726 if (m_sensorThread != NULL) {
1727 m_sensorThread->release();
1728 /* TODO */
1729 usleep(500000);
1730 } else {
1731 ALOGE("+++++++ sensor thread is NULL %d", __LINE__);
1732 }
1733
Sungjoong Kangad378612012-08-17 12:34:33 -07001734 ALOGV("(%s): calling capture streamoff", __FUNCTION__);
Sungjoong Kang15fd8232012-08-23 16:16:44 -07001735 if (cam_int_streamoff(&(m_camera_info.capture)) < 0) {
1736 ALOGE("ERR(%s): capture stream off fail", __FUNCTION__);
1737 } else {
1738 m_camera_info.capture.status = false;
1739 }
1740
Sungjoong Kangad378612012-08-17 12:34:33 -07001741 ALOGV("(%s): calling capture streamoff done", __FUNCTION__);
1742
1743 m_camera_info.capture.buffers = 0;
1744 ALOGV("DEBUG(%s): capture calling reqbuf 0 ", __FUNCTION__);
1745 cam_int_reqbufs(&(m_camera_info.capture));
1746 ALOGV("DEBUG(%s): capture calling reqbuf 0 done", __FUNCTION__);
1747
Sungjoong Kangad378612012-08-17 12:34:33 -07001748 m_isIspStarted = false;
1749 }
1750
Sungjoong Kangad378612012-08-17 12:34:33 -07001751 if (m_need_streamoff == 1) {
1752 m_camera_info.sensor.buffers = NUM_BAYER_BUFFERS;
1753 m_camera_info.isp.buffers = m_camera_info.sensor.buffers;
1754 m_camera_info.capture.buffers = 8;
Sungjoong Kang15fd8232012-08-23 16:16:44 -07001755 /* isp */
1756 cam_int_s_fmt(&(m_camera_info.isp));
Sungjoong Kangad378612012-08-17 12:34:33 -07001757 cam_int_reqbufs(&(m_camera_info.isp));
Sungjoong Kang15fd8232012-08-23 16:16:44 -07001758 /* sensor */
1759 cam_int_s_fmt(&(m_camera_info.sensor));
Sungjoong Kangad378612012-08-17 12:34:33 -07001760 cam_int_reqbufs(&(m_camera_info.sensor));
1761
1762 for (i = 0; i < 8; i++) {
1763 ALOGV("DEBUG(%s): sensor initial QBUF [%d]", __FUNCTION__, i);
1764 memcpy( m_camera_info.sensor.buffer[i].virt.extP[1], &(m_camera_info.dummy_shot),
1765 sizeof(struct camera2_shot_ext));
1766 m_camera_info.dummy_shot.shot.ctl.sensor.frameDuration = 33*1000*1000; // apply from frame #1
1767 m_camera_info.dummy_shot.shot.ctl.request.frameCount = -1;
1768 cam_int_qbuf(&(m_camera_info.sensor), i);
1769 }
1770
Sungjoong Kang15fd8232012-08-23 16:16:44 -07001771 /* capture */
1772 cam_int_s_fmt(&(m_camera_info.capture));
Sungjoong Kangad378612012-08-17 12:34:33 -07001773 cam_int_reqbufs(&(m_camera_info.capture));
Sungjoong Kang15fd8232012-08-23 16:16:44 -07001774 for (i = 0; i < m_camera_info.capture.buffers; i++) {
1775 ALOGV("DEBUG(%s): capture initial QBUF [%d]", __FUNCTION__, i);
1776 cam_int_qbuf(&(m_camera_info.capture), i);
1777 }
Sungjoong Kangad378612012-08-17 12:34:33 -07001778
Sungjoong Kang15fd8232012-08-23 16:16:44 -07001779 }
1780
1781 cam_int_s_input(currentNode, m_camera_info.sensor_id);
1782 cam_int_s_fmt(currentNode);
1783 cam_int_reqbufs(currentNode);
1784
Sungjoong Kang13d8c7b2012-07-14 10:20:39 +09001785 }
Sungjoong Kang37e122d2012-08-08 11:13:48 -07001786 else if (targetStreamParms->streamType == STREAM_TYPE_INDIRECT) {
Sungjoong Kang13d8c7b2012-07-14 10:20:39 +09001787 for(i = 0; i < currentNode->buffers; i++){
1788 memcpy(&(currentNode->buffer[i]), &(m_camera_info.capture.buffer[i]), sizeof(ExynosBuffer));
1789 }
1790 }
1791
1792 for (i = 0 ; i<targetStreamParms->numSvcBuffers ; i++) {
1793 ALOGV("DEBUG(%s): registering Stream Buffers[%d] (%x) ", __FUNCTION__,
1794 i, (uint32_t)(registeringBuffers[i]));
1795 if (m_grallocHal) {
1796 if (m_grallocHal->lock(m_grallocHal, registeringBuffers[i],
1797 targetStreamParms->usage, 0, 0,
1798 currentNode->width, currentNode->height, virtAddr) != 0) {
1799 ALOGE("ERR(%s): could not obtain gralloc buffer", __FUNCTION__);
1800 }
1801 else {
1802 v4l2_buf.m.planes = planes;
1803 v4l2_buf.type = currentNode->type;
1804 v4l2_buf.memory = currentNode->memory;
1805 v4l2_buf.index = i;
1806 v4l2_buf.length = currentNode->planes;
1807
1808 ExynosBuffer currentBuf;
Sungjoong Kangfeb7df42012-08-28 23:35:43 +09001809 ExynosBuffer metaBuf;
Sungjoong Kang13d8c7b2012-07-14 10:20:39 +09001810 const private_handle_t *priv_handle = reinterpret_cast<const private_handle_t *>(registeringBuffers[i]);
1811
1812 m_getAlignedYUVSize(currentNode->format,
1813 currentNode->width, currentNode->height, &currentBuf);
Alex Ray24231222012-06-27 15:18:15 -07001814
Sungjoong Kang37e122d2012-08-08 11:13:48 -07001815 ALOGV("DEBUG(%s): ion_size(%d), stride(%d), ", __FUNCTION__, priv_handle->size, priv_handle->stride);
1816 if (currentNode->planes == 1) {
Sungjoong Kang74d78eb2012-08-29 13:25:46 -07001817 v4l2_buf.m.planes[0].m.fd = priv_handle->fd;
1818 currentBuf.fd.extFd[0] = priv_handle->fd;
Sungjoong Kang37e122d2012-08-08 11:13:48 -07001819 currentBuf.size.extS[0] = priv_handle->size;
1820 currentBuf.size.extS[1] = 0;
1821 currentBuf.size.extS[2] = 0;
Sungjoong Kang74d78eb2012-08-29 13:25:46 -07001822 } else if (currentNode->planes == 2) {
1823 v4l2_buf.m.planes[0].m.fd = priv_handle->fd;
1824 v4l2_buf.m.planes[1].m.fd = priv_handle->fd1;
1825 currentBuf.fd.extFd[0] = priv_handle->fd;
1826 currentBuf.fd.extFd[1] = priv_handle->fd1;
1827
1828 } else if (currentNode->planes == 3) {
1829 v4l2_buf.m.planes[0].m.fd = priv_handle->fd;
1830 v4l2_buf.m.planes[2].m.fd = priv_handle->fd1;
1831 v4l2_buf.m.planes[1].m.fd = priv_handle->fd2;
1832 currentBuf.fd.extFd[0] = priv_handle->fd;
1833 currentBuf.fd.extFd[2] = priv_handle->fd1;
1834 currentBuf.fd.extFd[1] = priv_handle->fd2;
Sungjoong Kang37e122d2012-08-08 11:13:48 -07001835 }
Sungjoong Kangbe494d12012-08-04 15:36:56 -07001836 for (plane_index = 0 ; plane_index < v4l2_buf.length ; plane_index++) {
Sungjoong Kang13d8c7b2012-07-14 10:20:39 +09001837 currentBuf.virt.extP[plane_index] = (char *)virtAddr[plane_index];
1838 v4l2_buf.m.planes[plane_index].length = currentBuf.size.extS[plane_index];
1839 ALOGV("DEBUG(%s): plane(%d): fd(%d) addr(%x), length(%d)",
1840 __FUNCTION__, plane_index, v4l2_buf.m.planes[plane_index].m.fd,
1841 (unsigned int)currentBuf.virt.extP[plane_index],
1842 v4l2_buf.m.planes[plane_index].length);
Jiyoung Shinc15a6b02012-06-05 01:08:14 -07001843 }
Sungjoong Kang13d8c7b2012-07-14 10:20:39 +09001844
Sungjoong Kang37e122d2012-08-08 11:13:48 -07001845 if (targetStreamParms->streamType == STREAM_TYPE_DIRECT) {
Sungjoong Kang13d8c7b2012-07-14 10:20:39 +09001846 if (i < currentNode->buffers) {
Sungjoong Kangfeb7df42012-08-28 23:35:43 +09001847
1848
1849#ifdef ENABLE_FRAME_SYNC
1850 /* add plane for metadata*/
1851 metaBuf.size.extS[0] = 4*1024;
1852 allocCameraMemory(targetStreamParms->ionClient , &metaBuf, 1);
1853
1854 v4l2_buf.length += targetStreamParms->metaPlanes;
1855 v4l2_buf.m.planes[3].m.fd = metaBuf.fd.extFd[0];
1856 v4l2_buf.m.planes[3].length = metaBuf.size.extS[0];
1857
1858 ALOGV("Qbuf metaBuf: fd(%d), length(%d) plane(%d)", metaBuf.fd.extFd[0], metaBuf.size.extS[0], v4l2_buf.length);
1859#endif
Sungjoong Kang13d8c7b2012-07-14 10:20:39 +09001860 if (exynos_v4l2_qbuf(currentNode->fd, &v4l2_buf) < 0) {
Sungjoong Kang9dd63e12012-07-24 00:25:51 +09001861 ALOGE("ERR(%s): stream id(%d) exynos_v4l2_qbuf() fail fd(%d)",
1862 __FUNCTION__, stream_id, currentNode->fd);
1863 //return false;
Sungjoong Kang13d8c7b2012-07-14 10:20:39 +09001864 }
Sungjoong Kang9dd63e12012-07-24 00:25:51 +09001865 ALOGV("DEBUG(%s): stream id(%d) exynos_v4l2_qbuf() success fd(%d)",
1866 __FUNCTION__, stream_id, currentNode->fd);
Sungjoong Kang13d8c7b2012-07-14 10:20:39 +09001867 targetStreamParms->svcBufStatus[i] = REQUIRES_DQ_FROM_SVC;
1868 }
1869 else {
1870 targetStreamParms->svcBufStatus[i] = ON_SERVICE;
1871 }
1872 }
Sungjoong Kang37e122d2012-08-08 11:13:48 -07001873 else if (targetStreamParms->streamType == STREAM_TYPE_INDIRECT) {
Sungjoong Kang13d8c7b2012-07-14 10:20:39 +09001874 targetStreamParms->svcBufStatus[i] = ON_SERVICE;
1875 }
1876 targetStreamParms->svcBuffers[i] = currentBuf;
Sungjoong Kangfeb7df42012-08-28 23:35:43 +09001877 targetStreamParms->metaBuffers[i] = metaBuf;
Sungjoong Kang13d8c7b2012-07-14 10:20:39 +09001878 targetStreamParms->svcBufHandle[i] = registeringBuffers[i];
1879 }
Jiyoung Shinc15a6b02012-06-05 01:08:14 -07001880 }
Jiyoung Shinc15a6b02012-06-05 01:08:14 -07001881 }
Sungjoong Kangad378612012-08-17 12:34:33 -07001882
Sungjoong Kang9dd63e12012-07-24 00:25:51 +09001883 ALOGV("DEBUG(%s): calling streamon", __FUNCTION__);
Sungjoong Kang15fd8232012-08-23 16:16:44 -07001884 if (targetStreamParms->streamType == STREAM_TYPE_DIRECT) {
Sungjoong Kangad378612012-08-17 12:34:33 -07001885 ALOGD("%s(%d), stream id = %d", __FUNCTION__, __LINE__, stream_id);
1886 cam_int_streamon(&(targetStreamParms->node));
1887 }
1888
Sungjoong Kang15fd8232012-08-23 16:16:44 -07001889 if (m_need_streamoff == 1) {
1890 if (cam_int_streamon(&(m_camera_info.capture)) < 0) {
1891 ALOGE("ERR(%s): capture stream on fail", __FUNCTION__);
1892 } else {
1893 m_camera_info.capture.status = true;
1894 }
1895
1896 cam_int_streamon(&(m_camera_info.sensor));
1897 }
1898
Sungjoong Kangad378612012-08-17 12:34:33 -07001899 ALOGV("DEBUG(%s): calling streamon END", __FUNCTION__);
Sungjoong Kang13d8c7b2012-07-14 10:20:39 +09001900 ALOGV("DEBUG(%s): END registerStreamBuffers", __FUNCTION__);
Sungjoong Kangad378612012-08-17 12:34:33 -07001901
1902 if(!m_isIspStarted) {
1903 m_isIspStarted = true;
1904 StartISP();
Sungjoong Kangad378612012-08-17 12:34:33 -07001905 }
1906
Sungjoong Kang15fd8232012-08-23 16:16:44 -07001907 if (m_need_streamoff == 1) {
1908 m_requestManager->SetInitialSkip(8);
1909 m_sensorThread->Start("SensorThread", PRIORITY_DEFAULT, 0);
1910 m_mainThread->SetSignal(SIGNAL_MAIN_REQ_Q_NOT_EMPTY);
1911 }
1912 m_need_streamoff = 1;
1913
Jiyoung Shinc15a6b02012-06-05 01:08:14 -07001914 return 0;
1915}
1916
1917int ExynosCameraHWInterface2::releaseStream(uint32_t stream_id)
1918{
Sungjoong Kang13d8c7b2012-07-14 10:20:39 +09001919 StreamThread *targetStream;
hyeonmyeong Choi7d0efb52012-09-02 16:02:13 -07001920 ALOGV("DEBUG(%s):stream id %d", __FUNCTION__, stream_id);
Sungjoong Kang13d8c7b2012-07-14 10:20:39 +09001921
Sungjoong Kangb5237e62012-07-27 07:39:05 -07001922 if (stream_id == 0) {
Sungjoong Kang13d8c7b2012-07-14 10:20:39 +09001923 targetStream = (StreamThread*)(m_streamThreads[0].get());
Sungjoong Kang9dd63e12012-07-24 00:25:51 +09001924 m_scp_flushing = true;
Sungjoong Kang13d8c7b2012-07-14 10:20:39 +09001925 }
Sungjoong Kangb5237e62012-07-27 07:39:05 -07001926 else if (stream_id == 1) {
Sungjoong Kang13d8c7b2012-07-14 10:20:39 +09001927 targetStream = (StreamThread*)(m_streamThreads[1].get());
1928 }
Sungjoong Kangb5237e62012-07-27 07:39:05 -07001929 else if (stream_id == 2 && m_recordingEnabled) {
1930 m_recordingEnabled = false;
Sungjoong Kangad378612012-08-17 12:34:33 -07001931 m_needsRecordBufferInit = true;
Sungjoong Kangb5237e62012-07-27 07:39:05 -07001932 return 0;
1933 }
Sungjoong Kang74d78eb2012-08-29 13:25:46 -07001934 else if (stream_id == 3 && m_previewCbEnabled) {
1935 m_previewCbEnabled = false;
1936 m_needsPreviewCbBufferInit = true;
1937 return 0;
1938 }
Sungjoong Kang13d8c7b2012-07-14 10:20:39 +09001939 else {
1940 ALOGE("ERR:(%s): wrong stream id (%d)", __FUNCTION__, stream_id);
Sungjoong Kangbe494d12012-08-04 15:36:56 -07001941 return 1;
Sungjoong Kang13d8c7b2012-07-14 10:20:39 +09001942 }
1943
Sungjoong Kangb5237e62012-07-27 07:39:05 -07001944 targetStream->m_releasing = true;
Sungjoong Kang15fd8232012-08-23 16:16:44 -07001945 do {
1946 ALOGD("stream thread release %d", __LINE__);
1947 targetStream->release();
1948 usleep(33000);
1949 } while (targetStream->m_releasing);
Sungjoong Kang9dd63e12012-07-24 00:25:51 +09001950 targetStream->m_activated = false;
Sungjoong Kang13d8c7b2012-07-14 10:20:39 +09001951 ALOGV("DEBUG(%s): DONE", __FUNCTION__);
Jiyoung Shinc15a6b02012-06-05 01:08:14 -07001952 return 0;
1953}
1954
1955int ExynosCameraHWInterface2::allocateReprocessStream(
Sungjoong Kang13d8c7b2012-07-14 10:20:39 +09001956 uint32_t width, uint32_t height, uint32_t format,
1957 const camera2_stream_in_ops_t *reprocess_stream_ops,
Jiyoung Shinc15a6b02012-06-05 01:08:14 -07001958 uint32_t *stream_id, uint32_t *consumer_usage, uint32_t *max_buffers)
1959{
Sungjoong Kang13d8c7b2012-07-14 10:20:39 +09001960 ALOGV("DEBUG(%s):", __FUNCTION__);
Jiyoung Shinc15a6b02012-06-05 01:08:14 -07001961 return 0;
1962}
1963
1964int ExynosCameraHWInterface2::releaseReprocessStream(uint32_t stream_id)
1965{
Sungjoong Kang13d8c7b2012-07-14 10:20:39 +09001966 ALOGV("DEBUG(%s):", __FUNCTION__);
Jiyoung Shinc15a6b02012-06-05 01:08:14 -07001967 return 0;
1968}
1969
1970int ExynosCameraHWInterface2::triggerAction(uint32_t trigger_id, int ext1, int ext2)
1971{
Sungjoong Kang0f26b202012-08-17 15:43:12 -07001972 ALOGV("DEBUG(%s): id(%x), %d, %d", __FUNCTION__, trigger_id, ext1, ext2);
1973
1974 switch (trigger_id) {
1975 case CAMERA2_TRIGGER_AUTOFOCUS:
1976 ALOGV("DEBUG(%s):TRIGGER_AUTOFOCUS id(%d)", __FUNCTION__, ext1);
Sungjoong Kang8e2c2fd2012-08-27 00:02:22 -07001977 OnAfTriggerStart(ext1);
Sungjoong Kang0f26b202012-08-17 15:43:12 -07001978 break;
1979
1980 case CAMERA2_TRIGGER_CANCEL_AUTOFOCUS:
1981 ALOGV("DEBUG(%s):CANCEL_AUTOFOCUS id(%d)", __FUNCTION__, ext1);
1982 OnAfCancel(ext1);
1983 break;
1984 default:
1985 break;
1986 }
Jiyoung Shinc15a6b02012-06-05 01:08:14 -07001987 return 0;
1988}
1989
1990int ExynosCameraHWInterface2::setNotifyCallback(camera2_notify_callback notify_cb, void *user)
1991{
Sungjoong Kang0f26b202012-08-17 15:43:12 -07001992 ALOGV("DEBUG(%s): cb_addr(%x)", __FUNCTION__, (unsigned int)notify_cb);
Jiyoung Shinc15a6b02012-06-05 01:08:14 -07001993 m_notifyCb = notify_cb;
1994 m_callbackCookie = user;
1995 return 0;
1996}
1997
1998int ExynosCameraHWInterface2::getMetadataVendorTagOps(vendor_tag_query_ops_t **ops)
1999{
Sungjoong Kang13d8c7b2012-07-14 10:20:39 +09002000 ALOGV("DEBUG(%s):", __FUNCTION__);
Jiyoung Shinc15a6b02012-06-05 01:08:14 -07002001 return 0;
2002}
2003
2004int ExynosCameraHWInterface2::dump(int fd)
2005{
Sungjoong Kang13d8c7b2012-07-14 10:20:39 +09002006 ALOGV("DEBUG(%s):", __FUNCTION__);
Jiyoung Shinc15a6b02012-06-05 01:08:14 -07002007 return 0;
2008}
2009
Sungjoong Kang13d8c7b2012-07-14 10:20:39 +09002010void ExynosCameraHWInterface2::m_getAlignedYUVSize(int colorFormat, int w, int h, ExynosBuffer *buf)
2011{
2012 switch (colorFormat) {
2013 // 1p
2014 case V4L2_PIX_FMT_RGB565 :
2015 case V4L2_PIX_FMT_YUYV :
2016 case V4L2_PIX_FMT_UYVY :
2017 case V4L2_PIX_FMT_VYUY :
2018 case V4L2_PIX_FMT_YVYU :
2019 buf->size.extS[0] = FRAME_SIZE(V4L2_PIX_2_HAL_PIXEL_FORMAT(colorFormat), w, h);
2020 buf->size.extS[1] = 0;
2021 buf->size.extS[2] = 0;
2022 break;
2023 // 2p
2024 case V4L2_PIX_FMT_NV12 :
2025 case V4L2_PIX_FMT_NV12T :
2026 case V4L2_PIX_FMT_NV21 :
2027 buf->size.extS[0] = ALIGN(w, 16) * ALIGN(h, 16);
2028 buf->size.extS[1] = ALIGN(w/2, 16) * ALIGN(h/2, 16);
2029 buf->size.extS[2] = 0;
2030 break;
2031 case V4L2_PIX_FMT_NV12M :
2032 case V4L2_PIX_FMT_NV12MT_16X16 :
Sungjoong Kang9dd63e12012-07-24 00:25:51 +09002033 case V4L2_PIX_FMT_NV21M:
Sungjoong Kang13d8c7b2012-07-14 10:20:39 +09002034 buf->size.extS[0] = ALIGN(w, 16) * ALIGN(h, 16);
2035 buf->size.extS[1] = ALIGN(buf->size.extS[0] / 2, 256);
2036 buf->size.extS[2] = 0;
2037 break;
2038 case V4L2_PIX_FMT_NV16 :
2039 case V4L2_PIX_FMT_NV61 :
2040 buf->size.extS[0] = ALIGN(w, 16) * ALIGN(h, 16);
2041 buf->size.extS[1] = ALIGN(w, 16) * ALIGN(h, 16);
2042 buf->size.extS[2] = 0;
2043 break;
2044 // 3p
2045 case V4L2_PIX_FMT_YUV420 :
2046 case V4L2_PIX_FMT_YVU420 :
2047 buf->size.extS[0] = (w * h);
2048 buf->size.extS[1] = (w * h) >> 2;
2049 buf->size.extS[2] = (w * h) >> 2;
2050 break;
2051 case V4L2_PIX_FMT_YUV420M:
2052 case V4L2_PIX_FMT_YVU420M :
2053 case V4L2_PIX_FMT_YUV422P :
2054 buf->size.extS[0] = ALIGN(w, 32) * ALIGN(h, 16);
2055 buf->size.extS[1] = ALIGN(w/2, 16) * ALIGN(h/2, 8);
2056 buf->size.extS[2] = ALIGN(w/2, 16) * ALIGN(h/2, 8);
2057 break;
2058 default:
2059 ALOGE("ERR(%s):unmatched colorFormat(%d)", __FUNCTION__, colorFormat);
2060 return;
2061 break;
2062 }
2063}
2064
2065bool ExynosCameraHWInterface2::m_getRatioSize(int src_w, int src_h,
2066 int dst_w, int dst_h,
2067 int *crop_x, int *crop_y,
2068 int *crop_w, int *crop_h,
2069 int zoom)
2070{
2071 *crop_w = src_w;
2072 *crop_h = src_h;
2073
2074 if ( src_w != dst_w
2075 || src_h != dst_h) {
2076 float src_ratio = 1.0f;
2077 float dst_ratio = 1.0f;
2078
2079 // ex : 1024 / 768
2080 src_ratio = (float)src_w / (float)src_h;
2081
2082 // ex : 352 / 288
2083 dst_ratio = (float)dst_w / (float)dst_h;
2084
2085 if (dst_w * dst_h < src_w * src_h) {
2086 if (dst_ratio <= src_ratio) {
2087 // shrink w
2088 *crop_w = src_h * dst_ratio;
2089 *crop_h = src_h;
2090 } else {
2091 // shrink h
2092 *crop_w = src_w;
2093 *crop_h = src_w / dst_ratio;
2094 }
2095 } else {
2096 if (dst_ratio <= src_ratio) {
2097 // shrink w
2098 *crop_w = src_h * dst_ratio;
2099 *crop_h = src_h;
2100 } else {
2101 // shrink h
2102 *crop_w = src_w;
2103 *crop_h = src_w / dst_ratio;
2104 }
2105 }
2106 }
2107
2108 if (zoom != 0) {
2109 float zoomLevel = ((float)zoom + 10.0) / 10.0;
2110 *crop_w = (int)((float)*crop_w / zoomLevel);
2111 *crop_h = (int)((float)*crop_h / zoomLevel);
2112 }
2113
2114 #define CAMERA_CROP_WIDTH_RESTRAIN_NUM (0x2)
2115 unsigned int w_align = (*crop_w & (CAMERA_CROP_WIDTH_RESTRAIN_NUM - 1));
2116 if (w_align != 0) {
2117 if ( (CAMERA_CROP_WIDTH_RESTRAIN_NUM >> 1) <= w_align
2118 && *crop_w + (CAMERA_CROP_WIDTH_RESTRAIN_NUM - w_align) <= dst_w) {
2119 *crop_w += (CAMERA_CROP_WIDTH_RESTRAIN_NUM - w_align);
2120 }
2121 else
2122 *crop_w -= w_align;
2123 }
2124
2125 #define CAMERA_CROP_HEIGHT_RESTRAIN_NUM (0x2)
2126 unsigned int h_align = (*crop_h & (CAMERA_CROP_HEIGHT_RESTRAIN_NUM - 1));
2127 if (h_align != 0) {
2128 if ( (CAMERA_CROP_HEIGHT_RESTRAIN_NUM >> 1) <= h_align
2129 && *crop_h + (CAMERA_CROP_HEIGHT_RESTRAIN_NUM - h_align) <= dst_h) {
2130 *crop_h += (CAMERA_CROP_HEIGHT_RESTRAIN_NUM - h_align);
2131 }
2132 else
2133 *crop_h -= h_align;
2134 }
2135
2136 *crop_x = (src_w - *crop_w) >> 1;
2137 *crop_y = (src_h - *crop_h) >> 1;
2138
2139 if (*crop_x & (CAMERA_CROP_WIDTH_RESTRAIN_NUM >> 1))
2140 *crop_x -= 1;
2141
2142 if (*crop_y & (CAMERA_CROP_HEIGHT_RESTRAIN_NUM >> 1))
2143 *crop_y -= 1;
2144
2145 return true;
2146}
2147
Sungjoong Kang9dd63e12012-07-24 00:25:51 +09002148BayerBufManager::BayerBufManager()
Sungjoong Kang13d8c7b2012-07-14 10:20:39 +09002149{
Sungjoong Kang9dd63e12012-07-24 00:25:51 +09002150 ALOGV("DEBUG(%s): ", __FUNCTION__);
2151 for (int i = 0; i < NUM_BAYER_BUFFERS ; i++) {
2152 entries[i].status = BAYER_ON_HAL_EMPTY;
2153 entries[i].reqFrameCnt = 0;
Sungjoong Kang13d8c7b2012-07-14 10:20:39 +09002154 }
Sungjoong Kang9dd63e12012-07-24 00:25:51 +09002155 sensorEnqueueHead = 0;
2156 sensorDequeueHead = 0;
2157 ispEnqueueHead = 0;
2158 ispDequeueHead = 0;
2159 numOnSensor = 0;
2160 numOnIsp = 0;
2161 numOnHalFilled = 0;
2162 numOnHalEmpty = NUM_BAYER_BUFFERS;
Sungjoong Kang13d8c7b2012-07-14 10:20:39 +09002163}
2164
Sungjoong Kang15fd8232012-08-23 16:16:44 -07002165BayerBufManager::~BayerBufManager()
2166{
2167 ALOGV("%s", __FUNCTION__);
2168}
2169
Sungjoong Kang9dd63e12012-07-24 00:25:51 +09002170int BayerBufManager::GetIndexForSensorEnqueue()
Sungjoong Kang13d8c7b2012-07-14 10:20:39 +09002171{
Sungjoong Kang9dd63e12012-07-24 00:25:51 +09002172 int ret = 0;
2173 if (numOnHalEmpty == 0)
2174 ret = -1;
2175 else
2176 ret = sensorEnqueueHead;
2177 ALOGV("DEBUG(%s): returning (%d)", __FUNCTION__, ret);
Sungjoong Kang13d8c7b2012-07-14 10:20:39 +09002178 return ret;
2179}
2180
Sungjoong Kang9dd63e12012-07-24 00:25:51 +09002181int BayerBufManager::MarkSensorEnqueue(int index)
Sungjoong Kang13d8c7b2012-07-14 10:20:39 +09002182{
Sungjoong Kang9dd63e12012-07-24 00:25:51 +09002183 ALOGV("DEBUG(%s) : BayerIndex[%d] ", __FUNCTION__, index);
2184
2185 // sanity check
2186 if (index != sensorEnqueueHead) {
2187 ALOGV("DEBUG(%s) : Abnormal BayerIndex[%d] - expected[%d]", __FUNCTION__, index, sensorEnqueueHead);
2188 return -1;
2189 }
2190 if (entries[index].status != BAYER_ON_HAL_EMPTY) {
2191 ALOGV("DEBUG(%s) : Abnormal status in BayerIndex[%d] = (%d) expected (%d)", __FUNCTION__,
2192 index, entries[index].status, BAYER_ON_HAL_EMPTY);
Sungjoong Kang13d8c7b2012-07-14 10:20:39 +09002193 return -1;
2194 }
2195
Sungjoong Kang9dd63e12012-07-24 00:25:51 +09002196 entries[index].status = BAYER_ON_SENSOR;
2197 entries[index].reqFrameCnt = 0;
2198 numOnHalEmpty--;
2199 numOnSensor++;
2200 sensorEnqueueHead = GetNextIndex(index);
2201 ALOGV("DEBUG(%s) END: HAL-e(%d) HAL-f(%d) Sensor(%d) ISP(%d) ",
2202 __FUNCTION__, numOnHalEmpty, numOnHalFilled, numOnSensor, numOnIsp);
2203 return 0;
2204}
Sungjoong Kang13d8c7b2012-07-14 10:20:39 +09002205
Sungjoong Kang9dd63e12012-07-24 00:25:51 +09002206int BayerBufManager::MarkSensorDequeue(int index, int reqFrameCnt, nsecs_t *timeStamp)
2207{
2208 ALOGV("DEBUG(%s) : BayerIndex[%d] reqFrameCnt(%d)", __FUNCTION__, index, reqFrameCnt);
2209
Sungjoong Kang9dd63e12012-07-24 00:25:51 +09002210 if (entries[index].status != BAYER_ON_SENSOR) {
Sungjoong Kangad378612012-08-17 12:34:33 -07002211 ALOGE("DEBUG(%s) : Abnormal status in BayerIndex[%d] = (%d) expected (%d)", __FUNCTION__,
Sungjoong Kang9dd63e12012-07-24 00:25:51 +09002212 index, entries[index].status, BAYER_ON_SENSOR);
Sungjoong Kang13d8c7b2012-07-14 10:20:39 +09002213 return -1;
2214 }
2215
Sungjoong Kang9dd63e12012-07-24 00:25:51 +09002216 entries[index].status = BAYER_ON_HAL_FILLED;
Sungjoong Kang9dd63e12012-07-24 00:25:51 +09002217 numOnHalFilled++;
2218 numOnSensor--;
Sungjoong Kangad378612012-08-17 12:34:33 -07002219
Sungjoong Kang9dd63e12012-07-24 00:25:51 +09002220 return 0;
2221}
Sungjoong Kang13d8c7b2012-07-14 10:20:39 +09002222
Sungjoong Kang9dd63e12012-07-24 00:25:51 +09002223int BayerBufManager::GetIndexForIspEnqueue(int *reqFrameCnt)
2224{
2225 int ret = 0;
2226 if (numOnHalFilled == 0)
2227 ret = -1;
2228 else {
2229 *reqFrameCnt = entries[ispEnqueueHead].reqFrameCnt;
2230 ret = ispEnqueueHead;
2231 }
2232 ALOGV("DEBUG(%s): returning BayerIndex[%d]", __FUNCTION__, ret);
2233 return ret;
2234}
2235
2236int BayerBufManager::GetIndexForIspDequeue(int *reqFrameCnt)
2237{
2238 int ret = 0;
2239 if (numOnIsp == 0)
2240 ret = -1;
2241 else {
2242 *reqFrameCnt = entries[ispDequeueHead].reqFrameCnt;
2243 ret = ispDequeueHead;
2244 }
2245 ALOGV("DEBUG(%s): returning BayerIndex[%d]", __FUNCTION__, ret);
2246 return ret;
2247}
2248
2249int BayerBufManager::MarkIspEnqueue(int index)
2250{
2251 ALOGV("DEBUG(%s) : BayerIndex[%d] ", __FUNCTION__, index);
2252
2253 // sanity check
2254 if (index != ispEnqueueHead) {
2255 ALOGV("DEBUG(%s) : Abnormal BayerIndex[%d] - expected[%d]", __FUNCTION__, index, ispEnqueueHead);
2256 return -1;
2257 }
2258 if (entries[index].status != BAYER_ON_HAL_FILLED) {
2259 ALOGV("DEBUG(%s) : Abnormal status in BayerIndex[%d] = (%d) expected (%d)", __FUNCTION__,
2260 index, entries[index].status, BAYER_ON_HAL_FILLED);
2261 return -1;
2262 }
2263
2264 entries[index].status = BAYER_ON_ISP;
2265 numOnHalFilled--;
2266 numOnIsp++;
2267 ispEnqueueHead = GetNextIndex(index);
2268 ALOGV("DEBUG(%s) END: HAL-e(%d) HAL-f(%d) Sensor(%d) ISP(%d) ",
2269 __FUNCTION__, numOnHalEmpty, numOnHalFilled, numOnSensor, numOnIsp);
2270 return 0;
2271}
2272
2273int BayerBufManager::MarkIspDequeue(int index)
2274{
2275 ALOGV("DEBUG(%s) : BayerIndex[%d]", __FUNCTION__, index);
2276
2277 // sanity check
2278 if (index != ispDequeueHead) {
2279 ALOGV("DEBUG(%s) : Abnormal BayerIndex[%d] - expected[%d]", __FUNCTION__, index, ispDequeueHead);
2280 return -1;
2281 }
2282 if (entries[index].status != BAYER_ON_ISP) {
2283 ALOGV("DEBUG(%s) : Abnormal status in BayerIndex[%d] = (%d) expected (%d)", __FUNCTION__,
2284 index, entries[index].status, BAYER_ON_ISP);
2285 return -1;
2286 }
2287
2288 entries[index].status = BAYER_ON_HAL_EMPTY;
2289 entries[index].reqFrameCnt = 0;
2290 numOnHalEmpty++;
2291 numOnIsp--;
2292 ispDequeueHead = GetNextIndex(index);
2293 ALOGV("DEBUG(%s) END: HAL-e(%d) HAL-f(%d) Sensor(%d) ISP(%d) ",
2294 __FUNCTION__, numOnHalEmpty, numOnHalFilled, numOnSensor, numOnIsp);
2295 return 0;
2296}
2297
2298int BayerBufManager::GetNumOnSensor()
2299{
2300 return numOnSensor;
2301}
2302
2303int BayerBufManager::GetNumOnHalFilled()
2304{
2305 return numOnHalFilled;
2306}
2307
2308int BayerBufManager::GetNumOnIsp()
2309{
2310 return numOnIsp;
2311}
2312
2313int BayerBufManager::GetNextIndex(int index)
2314{
2315 index++;
2316 if (index >= NUM_BAYER_BUFFERS)
2317 index = 0;
2318
2319 return index;
Sungjoong Kang13d8c7b2012-07-14 10:20:39 +09002320}
Jiyoung Shinc15a6b02012-06-05 01:08:14 -07002321
2322void ExynosCameraHWInterface2::m_mainThreadFunc(SignalDrivenThread * self)
2323{
2324 camera_metadata_t *currentRequest = NULL;
2325 camera_metadata_t *currentFrame = NULL;
2326 size_t numEntries = 0;
Sungjoong Kang13d8c7b2012-07-14 10:20:39 +09002327 size_t frameSize = 0;
Jiyoung Shinc15a6b02012-06-05 01:08:14 -07002328 camera_metadata_t * preparedFrame = NULL;
2329 camera_metadata_t *deregisteredRequest = NULL;
2330 uint32_t currentSignal = self->GetProcessingSignal();
Sungjoong Kang13d8c7b2012-07-14 10:20:39 +09002331 MainThread * selfThread = ((MainThread*)self);
Jiyoung Shinc15a6b02012-06-05 01:08:14 -07002332 int res = 0;
Sungjoong Kang13d8c7b2012-07-14 10:20:39 +09002333
Sungjoong Kangad378612012-08-17 12:34:33 -07002334 int ret;
2335
Sungjoong Kang13d8c7b2012-07-14 10:20:39 +09002336 ALOGV("DEBUG(%s): m_mainThreadFunc (%x)", __FUNCTION__, currentSignal);
2337
2338 if (currentSignal & SIGNAL_THREAD_RELEASE) {
2339 ALOGV("DEBUG(%s): processing SIGNAL_THREAD_RELEASE", __FUNCTION__);
2340
2341 ALOGV("DEBUG(%s): processing SIGNAL_THREAD_RELEASE DONE", __FUNCTION__);
2342 selfThread->SetSignal(SIGNAL_THREAD_TERMINATE);
2343 return;
2344 }
2345
Jiyoung Shinc15a6b02012-06-05 01:08:14 -07002346 if (currentSignal & SIGNAL_MAIN_REQ_Q_NOT_EMPTY) {
Sungjoong Kang13d8c7b2012-07-14 10:20:39 +09002347 ALOGV("DEBUG(%s): MainThread processing SIGNAL_MAIN_REQ_Q_NOT_EMPTY", __FUNCTION__);
Sungjoong Kangad378612012-08-17 12:34:33 -07002348 if (m_requestManager->IsRequestQueueFull()==false) {
Jiyoung Shinc15a6b02012-06-05 01:08:14 -07002349 m_requestQueueOps->dequeue_request(m_requestQueueOps, &currentRequest);
2350 if (NULL == currentRequest) {
Sungjoong Kangad378612012-08-17 12:34:33 -07002351 ALOGE("DEBUG(%s)(0x%x): dequeue_request returned NULL ", __FUNCTION__, currentSignal);
Sungjoong Kang13d8c7b2012-07-14 10:20:39 +09002352 m_isRequestQueueNull = true;
Jiyoung Shinc15a6b02012-06-05 01:08:14 -07002353 }
2354 else {
2355 m_requestManager->RegisterRequest(currentRequest);
Sungjoong Kang13d8c7b2012-07-14 10:20:39 +09002356
Jiyoung Shinc15a6b02012-06-05 01:08:14 -07002357 m_numOfRemainingReqInSvc = m_requestQueueOps->request_count(m_requestQueueOps);
Sungjoong Kang13d8c7b2012-07-14 10:20:39 +09002358 ALOGV("DEBUG(%s): remaining req cnt (%d)", __FUNCTION__, m_numOfRemainingReqInSvc);
Sungjoong Kangad378612012-08-17 12:34:33 -07002359 if (m_requestManager->IsRequestQueueFull()==false)
Sungjoong Kang13d8c7b2012-07-14 10:20:39 +09002360 selfThread->SetSignal(SIGNAL_MAIN_REQ_Q_NOT_EMPTY); // dequeue repeatedly
Sungjoong Kang9dd63e12012-07-24 00:25:51 +09002361
Jiyoung Shinc15a6b02012-06-05 01:08:14 -07002362 m_sensorThread->SetSignal(SIGNAL_SENSOR_START_REQ_PROCESSING);
2363 }
2364 }
2365 else {
2366 m_isRequestQueuePending = true;
2367 }
2368 }
2369
2370 if (currentSignal & SIGNAL_MAIN_STREAM_OUTPUT_DONE) {
Sungjoong Kang13d8c7b2012-07-14 10:20:39 +09002371 ALOGV("DEBUG(%s): MainThread processing SIGNAL_MAIN_STREAM_OUTPUT_DONE", __FUNCTION__);
2372 /*while (1)*/ {
Sungjoong Kang0f26b202012-08-17 15:43:12 -07002373 ret = m_requestManager->PrepareFrame(&numEntries, &frameSize, &preparedFrame, GetAfStateForService());
Sungjoong Kangad378612012-08-17 12:34:33 -07002374 if (ret == false)
2375 ALOGD("++++++ PrepareFrame ret = %d", ret);
2376
Sungjoong Kang13d8c7b2012-07-14 10:20:39 +09002377 m_requestManager->DeregisterRequest(&deregisteredRequest);
Sungjoong Kangad378612012-08-17 12:34:33 -07002378
2379 ret = m_requestQueueOps->free_request(m_requestQueueOps, deregisteredRequest);
2380 if (ret < 0)
2381 ALOGD("++++++ free_request ret = %d", ret);
2382
2383 ret = m_frameQueueOps->dequeue_frame(m_frameQueueOps, numEntries, frameSize, &currentFrame);
2384 if (ret < 0)
2385 ALOGD("++++++ dequeue_frame ret = %d", ret);
2386
Sungjoong Kang13d8c7b2012-07-14 10:20:39 +09002387 if (currentFrame==NULL) {
Sungjoong Kangad378612012-08-17 12:34:33 -07002388 ALOGV("DBG(%s): frame dequeue returned NULL",__FUNCTION__ );
Sungjoong Kang13d8c7b2012-07-14 10:20:39 +09002389 }
2390 else {
Sungjoong Kangdaa1fcd2012-08-08 11:49:43 -07002391 ALOGV("DEBUG(%s): frame dequeue done. numEntries(%d) frameSize(%d)",__FUNCTION__ , numEntries, frameSize);
Sungjoong Kang13d8c7b2012-07-14 10:20:39 +09002392 }
2393 res = append_camera_metadata(currentFrame, preparedFrame);
2394 if (res==0) {
2395 ALOGV("DEBUG(%s): frame metadata append success",__FUNCTION__);
2396 m_frameQueueOps->enqueue_frame(m_frameQueueOps, currentFrame);
2397 }
2398 else {
2399 ALOGE("ERR(%s): frame metadata append fail (%d)",__FUNCTION__, res);
2400 }
Jiyoung Shinc15a6b02012-06-05 01:08:14 -07002401 }
Sungjoong Kang13d8c7b2012-07-14 10:20:39 +09002402 if (!m_isRequestQueueNull) {
2403 selfThread->SetSignal(SIGNAL_MAIN_REQ_Q_NOT_EMPTY);
Jiyoung Shinc15a6b02012-06-05 01:08:14 -07002404 }
Sungjoong Kang9dd63e12012-07-24 00:25:51 +09002405
Sungjoong Kang13d8c7b2012-07-14 10:20:39 +09002406 if (getInProgressCount()>0) {
2407 ALOGV("DEBUG(%s): STREAM_OUTPUT_DONE and signalling REQ_PROCESSING",__FUNCTION__);
2408 m_sensorThread->SetSignal(SIGNAL_SENSOR_START_REQ_PROCESSING);
Jiyoung Shinc15a6b02012-06-05 01:08:14 -07002409 }
Jiyoung Shinc15a6b02012-06-05 01:08:14 -07002410 }
Sungjoong Kang13d8c7b2012-07-14 10:20:39 +09002411 ALOGV("DEBUG(%s): MainThread Exit", __FUNCTION__);
Jiyoung Shinc15a6b02012-06-05 01:08:14 -07002412 return;
2413}
Sungjoong Kang13d8c7b2012-07-14 10:20:39 +09002414
Jiyoung Shinc15a6b02012-06-05 01:08:14 -07002415void ExynosCameraHWInterface2::m_sensorThreadInitialize(SignalDrivenThread * self)
2416{
Sungjoong Kang13d8c7b2012-07-14 10:20:39 +09002417 ALOGV("DEBUG(%s): ", __FUNCTION__ );
Sungjoong Kangad378612012-08-17 12:34:33 -07002418 /* will add */
Sungjoong Kang13d8c7b2012-07-14 10:20:39 +09002419 return;
2420}
2421
2422
Sungjoong Kang13d8c7b2012-07-14 10:20:39 +09002423void ExynosCameraHWInterface2::DumpInfoWithShot(struct camera2_shot_ext * shot_ext)
2424{
Sungjoong Kangad378612012-08-17 12:34:33 -07002425 ALOGD("#### common Section");
2426 ALOGD("#### magic(%x) ",
Sungjoong Kang13d8c7b2012-07-14 10:20:39 +09002427 shot_ext->shot.magicNumber);
Sungjoong Kangad378612012-08-17 12:34:33 -07002428 ALOGD("#### ctl Section");
2429 ALOGD("#### meta(%d) aper(%f) exp(%lld) duration(%lld) ISO(%d) AWB(%d)",
Sungjoong Kang13d8c7b2012-07-14 10:20:39 +09002430 shot_ext->shot.ctl.request.metadataMode,
Sungjoong Kangb56dcc02012-08-08 13:38:09 -07002431 shot_ext->shot.ctl.lens.aperture,
Sungjoong Kang13d8c7b2012-07-14 10:20:39 +09002432 shot_ext->shot.ctl.sensor.exposureTime,
2433 shot_ext->shot.ctl.sensor.frameDuration,
Sungjoong Kangb56dcc02012-08-08 13:38:09 -07002434 shot_ext->shot.ctl.sensor.sensitivity,
2435 shot_ext->shot.ctl.aa.awbMode);
Sungjoong Kang13d8c7b2012-07-14 10:20:39 +09002436
Sungjoong Kang74d78eb2012-08-29 13:25:46 -07002437 ALOGD("#### OutputStream Sensor(%d) SCP(%d) SCC(%d) pv(%d) rec(%d) previewCb(%d)",
Sungjoong Kang9dd63e12012-07-24 00:25:51 +09002438 shot_ext->request_sensor, shot_ext->request_scp, shot_ext->request_scc,
Sungjoong Kang74d78eb2012-08-29 13:25:46 -07002439 shot_ext->shot.ctl.request.outputStreams[0], shot_ext->shot.ctl.request.outputStreams[2],
2440 shot_ext->shot.ctl.request.outputStreams[3]);
Sungjoong Kang13d8c7b2012-07-14 10:20:39 +09002441
Sungjoong Kangad378612012-08-17 12:34:33 -07002442 ALOGD("#### DM Section");
2443 ALOGD("#### meta(%d) aper(%f) exp(%lld) duration(%lld) ISO(%d) timestamp(%lld) AWB(%d) cnt(%d)",
Sungjoong Kang13d8c7b2012-07-14 10:20:39 +09002444 shot_ext->shot.dm.request.metadataMode,
Sungjoong Kangb56dcc02012-08-08 13:38:09 -07002445 shot_ext->shot.dm.lens.aperture,
Sungjoong Kang13d8c7b2012-07-14 10:20:39 +09002446 shot_ext->shot.dm.sensor.exposureTime,
2447 shot_ext->shot.dm.sensor.frameDuration,
2448 shot_ext->shot.dm.sensor.sensitivity,
Sungjoong Kangb56dcc02012-08-08 13:38:09 -07002449 shot_ext->shot.dm.sensor.timeStamp,
2450 shot_ext->shot.dm.aa.awbMode,
2451 shot_ext->shot.dm.request.frameCount );
Sungjoong Kang13d8c7b2012-07-14 10:20:39 +09002452}
2453
Younghwan Joo6f19b6c2012-08-30 13:56:53 -07002454void ExynosCameraHWInterface2::flashSetter(struct camera2_shot_ext * shot_ext)
2455{
2456 // 1. AF Flash
Younghwan Joo9a710a42012-09-05 17:52:08 -07002457 if (m_ctlInfo.flash.m_afFlashEnableFlg) {
2458 switch (m_ctlInfo.flash.m_afFlashCnt) {
Younghwan Joo6f19b6c2012-08-30 13:56:53 -07002459 case IS_FLASH_AF_ON:
Younghwan Joo9257e292012-09-08 21:11:18 -07002460 ALOGV("(%s): [AF Flash] IS_FLASH_ON", __FUNCTION__);
Younghwan Joo9a710a42012-09-05 17:52:08 -07002461 if (m_ctlInfo.flash.i_flashMode == AA_AEMODE_ON_ALWAYS_FLASH) {
2462 shot_ext->shot.ctl.aa.aeflashMode = AA_FLASHMODE_ON_ALWAYS;
2463 m_ctlInfo.flash.m_flashWaitCnt = 0;
2464 } else
2465 shot_ext->shot.ctl.aa.aeflashMode = AA_FLASHMODE_ON;
2466 m_ctlInfo.flash.m_afFlashCnt = IS_FLASH_AF_ON_START;
2467 break;
2468 case IS_FLASH_AF_AUTO_AE_AWB_LOCK:
Younghwan Joo9257e292012-09-08 21:11:18 -07002469 ALOGV("(%s): [AF Flash] IS_FLASH_AF_AUTO_AE_AWB_LOCK", __FUNCTION__);
Younghwan Joo9a710a42012-09-05 17:52:08 -07002470 shot_ext->shot.ctl.aa.aeflashMode = AA_FLASHMODE_AUTO;
2471 shot_ext->shot.ctl.aa.awbMode = AA_AWBMODE_LOCKED;
2472 //shot_ext->shot.ctl.aa.aeMode = AA_AEMODE_LOCKED;
Younghwan Joocaea49e2012-09-07 13:34:20 -07002473 m_ctlInfo.flash.m_afFlashCnt = IS_FLASH_AF_AUTO_AE_AWB_LOCK_WAIT;
Younghwan Joo6f19b6c2012-08-30 13:56:53 -07002474 break;
2475 case IF_FLASH_AF_OFF:
Younghwan Joo9257e292012-09-08 21:11:18 -07002476 ALOGV("(%s): [AF Flash] IS_FLASH_OFF and status clear", __FUNCTION__);
Younghwan Joo6f19b6c2012-08-30 13:56:53 -07002477 shot_ext->shot.ctl.aa.aeflashMode = AA_FLASHMODE_OFF;
Younghwan Joo9a710a42012-09-05 17:52:08 -07002478 m_ctlInfo.flash.m_afFlashEnableFlg = false;
Younghwan Joo9257e292012-09-08 21:11:18 -07002479 m_ctlInfo.flash.m_afFlashDoneFlg = true;
Younghwan Joo9a710a42012-09-05 17:52:08 -07002480 m_ctlInfo.flash.m_afFlashCnt = 0;
Younghwan Joo6f19b6c2012-08-30 13:56:53 -07002481 break;
2482 }
2483 }
2484
2485 // 2. Flash
Younghwan Joo9a710a42012-09-05 17:52:08 -07002486 if (m_ctlInfo.flash.m_flashEnableFlg) {
2487 switch (m_ctlInfo.flash.m_flashCnt) {
Younghwan Joo6f19b6c2012-08-30 13:56:53 -07002488 case IS_FLASH_ON:
Younghwan Joo9257e292012-09-08 21:11:18 -07002489 ALOGV("(%s): [Flash] Flash ON for Capture", __FUNCTION__);
Younghwan Joo9a710a42012-09-05 17:52:08 -07002490 if (m_ctlInfo.flash.i_flashMode == AA_AEMODE_ON_ALWAYS_FLASH) {
2491 shot_ext->shot.ctl.aa.aeflashMode = AA_FLASHMODE_ON_ALWAYS;
2492 m_ctlInfo.flash.m_flashWaitCnt = 0;
2493 } else
2494 shot_ext->shot.ctl.aa.aeflashMode = AA_FLASHMODE_ON;
Younghwan Joo9a710a42012-09-05 17:52:08 -07002495 shot_ext->request_scc = 0;
2496 shot_ext->request_scp = 0;
Younghwan Joo6f19b6c2012-08-30 13:56:53 -07002497 break;
2498 case IS_FLASH_ON_DONE:
Younghwan Joo9a710a42012-09-05 17:52:08 -07002499 //shot_ext->shot.ctl.aa.aeMode = AA_AEMODE_LOCKED;
Younghwan Joo6f19b6c2012-08-30 13:56:53 -07002500 shot_ext->shot.ctl.aa.awbMode = AA_AWBMODE_LOCKED;
2501 shot_ext->shot.ctl.aa.aeflashMode = AA_FLASHMODE_AUTO;
Younghwan Joo9257e292012-09-08 21:11:18 -07002502 m_ctlInfo.flash.m_flashCnt = IS_FLASH_AE_AWB_LOCK_WAIT; // auto transition
Younghwan Joo6f19b6c2012-08-30 13:56:53 -07002503 shot_ext->request_scc = 0;
Younghwan Joo9a710a42012-09-05 17:52:08 -07002504 shot_ext->request_scp = 0;
Younghwan Joo6f19b6c2012-08-30 13:56:53 -07002505 break;
Younghwan Joo9257e292012-09-08 21:11:18 -07002506 case IS_FLASH_AE_AWB_LOCK_WAIT:
Younghwan Joo6f19b6c2012-08-30 13:56:53 -07002507 shot_ext->request_scc = 0;
Younghwan Joo9a710a42012-09-05 17:52:08 -07002508 shot_ext->request_scp = 0;
Younghwan Joo6f19b6c2012-08-30 13:56:53 -07002509 break;
2510 case IS_FLASH_CAPTURE:
Younghwan Joo9a710a42012-09-05 17:52:08 -07002511 m_ctlInfo.flash.m_flashCnt = IS_FLASH_CAPTURE_WAIT;
2512 shot_ext->shot.ctl.aa.aeflashMode = AA_FLASHMODE_CAPTURE;
Younghwan Joo6f19b6c2012-08-30 13:56:53 -07002513 shot_ext->request_scc = 0;
Younghwan Joo9a710a42012-09-05 17:52:08 -07002514 shot_ext->request_scp = 0;
Younghwan Joo9257e292012-09-08 21:11:18 -07002515 ALOGV("(%s): [Flash] IS_FLASH_CAPTURE - %d", __FUNCTION__, shot_ext->shot.ctl.aa.aeflashMode);
Younghwan Joo9a710a42012-09-05 17:52:08 -07002516 break;
2517 case IS_FLASH_CAPTURE_WAIT:
2518 shot_ext->request_scc = 0;
2519 shot_ext->request_scp = 0;
Younghwan Joo6f19b6c2012-08-30 13:56:53 -07002520 break;
2521 case IS_FLASH_CAPTURE_JPEG:
Younghwan Joo9257e292012-09-08 21:11:18 -07002522 ALOGV("(%s): [Flash] Flash Capture !!!!!", __FUNCTION__);
Younghwan Joo9a710a42012-09-05 17:52:08 -07002523 shot_ext->request_scc = 1;
2524 shot_ext->request_scp = 1;
2525 m_ctlInfo.flash.m_flashCnt = IS_FLASH_CAPTURE_END;
Younghwan Joo9a710a42012-09-05 17:52:08 -07002526 break;
2527 case IS_FLASH_CAPTURE_END:
Younghwan Joo9257e292012-09-08 21:11:18 -07002528 ALOGV("(%s): [Flash] Flash Capture END", __FUNCTION__);
Younghwan Joo6f19b6c2012-08-30 13:56:53 -07002529 shot_ext->request_scc = 0;
Younghwan Joo9a710a42012-09-05 17:52:08 -07002530 shot_ext->request_scp = 0;
2531 shot_ext->shot.ctl.aa.aeflashMode = AA_FLASHMODE_OFF;
Younghwan Joo9a710a42012-09-05 17:52:08 -07002532 m_ctlInfo.flash.m_flashEnableFlg = false;
2533 m_ctlInfo.flash.m_flashCnt = 0;
2534 m_ctlInfo.flash.m_afFlashDoneFlg= false;
Younghwan Joo6f19b6c2012-08-30 13:56:53 -07002535 break;
2536 }
2537 }
2538}
2539
Younghwan Joo9257e292012-09-08 21:11:18 -07002540void ExynosCameraHWInterface2::flashListenerSensor(struct camera2_shot_ext * shot_ext)
Younghwan Joo6f19b6c2012-08-30 13:56:53 -07002541{
Younghwan Joo6f19b6c2012-08-30 13:56:53 -07002542 // 1. AF Flash
Younghwan Joo9a710a42012-09-05 17:52:08 -07002543 if (m_ctlInfo.flash.m_afFlashEnableFlg) {
Younghwan Joo9a710a42012-09-05 17:52:08 -07002544 switch (m_ctlInfo.flash.m_afFlashCnt) {
Younghwan Joo9257e292012-09-08 21:11:18 -07002545 case IS_FLASH_AF_AUTO_OFF_WAIT:
2546 if (m_ctlInfo.flash.m_flashDecisionResult) {
2547 if (shot_ext->shot.dm.flash.flashMode == CAM2_FLASH_MODE_OFF) {
2548 m_ctlInfo.flash.m_afFlashCnt = IS_FLASH_AF_AUTO_END;
2549 ALOGV("(%s): [AF Flash] Lis : AUTO -> OFF (%d)", __FUNCTION__, shot_ext->shot.dm.flash.flashMode);
Younghwan Joo9a710a42012-09-05 17:52:08 -07002550 } else {
Younghwan Joo9257e292012-09-08 21:11:18 -07002551 ALOGV("(%s): [AF Flash] Waiting : AUTO -> OFF", __FUNCTION__);
Younghwan Joo9a710a42012-09-05 17:52:08 -07002552 }
Younghwan Joo6f19b6c2012-08-30 13:56:53 -07002553 } else {
Younghwan Joo9a710a42012-09-05 17:52:08 -07002554 m_ctlInfo.flash.m_afFlashCnt = IS_FLASH_AF_AUTO_END;
Younghwan Joo6f19b6c2012-08-30 13:56:53 -07002555 }
2556 break;
Younghwan Joo6f19b6c2012-08-30 13:56:53 -07002557 }
2558 }
2559
2560 // 2. Flash
Younghwan Joo9a710a42012-09-05 17:52:08 -07002561 if (m_ctlInfo.flash.m_flashEnableFlg) {
Younghwan Joo9a710a42012-09-05 17:52:08 -07002562 switch (m_ctlInfo.flash.m_flashCnt) {
Younghwan Joo9257e292012-09-08 21:11:18 -07002563 case IS_FLASH_AUTO_WAIT:
2564 if (m_ctlInfo.flash.m_flashDecisionResult) {
2565 if (shot_ext->shot.dm.flash.flashMode == CAM2_FLASH_MODE_OFF) {
2566 m_ctlInfo.flash.m_flashCnt = IS_FLASH_CAPTURE;
2567 m_ctlInfo.flash.m_flashTimeOut = 10;
2568 ALOGV("(%s): [Flash] Lis : AUTO -> OFF (%d)", __FUNCTION__, shot_ext->shot.dm.flash.flashMode);
2569 } else {
2570 ALOGV("(%s): [Flash] Waiting : AUTO -> OFF", __FUNCTION__);
2571 }
Younghwan Joo6f19b6c2012-08-30 13:56:53 -07002572 } else {
Younghwan Joo9a710a42012-09-05 17:52:08 -07002573 m_ctlInfo.flash.m_flashCnt = IS_FLASH_CAPTURE;
Younghwan Joo9257e292012-09-08 21:11:18 -07002574 m_ctlInfo.flash.m_flashTimeOut = 10;
2575 ALOGV("(%s): [Flash] Skip : FLASH_AUTO -> FLASH_MODE_OFF", __FUNCTION__);
Younghwan Joo6f19b6c2012-08-30 13:56:53 -07002576 }
2577 break;
Younghwan Joo9a710a42012-09-05 17:52:08 -07002578 }
2579 }
2580
2581}
2582
Younghwan Joo9257e292012-09-08 21:11:18 -07002583void ExynosCameraHWInterface2::flashListenerISP(struct camera2_shot_ext * shot_ext)
Younghwan Joo9a710a42012-09-05 17:52:08 -07002584{
Younghwan Joo9257e292012-09-08 21:11:18 -07002585 // 1. AF Flash
2586 if (m_ctlInfo.flash.m_afFlashEnableFlg) {
2587 switch (m_ctlInfo.flash.m_afFlashCnt) {
2588 case IS_FLASH_AF_ON_START:
2589 if (shot_ext->shot.dm.flash.decision > 0) {
2590 // store decision result to skip capture sequenece
2591 if (shot_ext->shot.dm.flash.decision == 2)
2592 m_ctlInfo.flash.m_flashDecisionResult = false;
2593 else
2594 m_ctlInfo.flash.m_flashDecisionResult = true;
2595 m_ctlInfo.flash.m_afFlashCnt = IS_FLASH_AF_ON_DONE;
2596 ALOGV("(%s): [AF Flash] IS_FLASH_ON, decision - %d", __FUNCTION__, shot_ext->shot.dm.flash.decision);
2597 m_IsAfTriggerRequired = true;
2598 } else {
2599 if (m_ctlInfo.flash.m_flashTimeOut == 0) {
2600 m_ctlInfo.flash.m_afFlashCnt = IS_FLASH_AF_ON_DONE;
2601 ALOGE("(%s): [AF Flash] Timeout IS_FLASH_ON, decision is false setting", __FUNCTION__);
2602 m_ctlInfo.flash.m_flashDecisionResult = false;
2603 m_IsAfTriggerRequired = true;
2604 } else {
2605 m_ctlInfo.flash.m_flashTimeOut--;
2606 }
2607 }
2608 break;
2609 case IS_FLASH_AF_AUTO_AE_AWB_LOCK_WAIT:
2610 if (shot_ext->shot.dm.aa.awbMode == AA_AWBMODE_LOCKED) {
2611 ALOGV("(%s): [AF Flash] AUTO_AE_AWB_LOCK_WAIT - %d", __FUNCTION__, shot_ext->shot.dm.aa.awbMode);
2612 m_ctlInfo.flash.m_afFlashCnt = IS_FLASH_AF_AUTO_OFF_WAIT;
2613 } else {
2614 ALOGV("(%s): [Flash] Waiting : AA_AWBMODE_LOCKED", __FUNCTION__);
2615 }
2616 break;
2617 }
2618 }
2619
2620 // 2. Flash
Younghwan Joo9a710a42012-09-05 17:52:08 -07002621 // firing stable field is valid at ISP meta output only.
2622 if (m_ctlInfo.flash.m_flashEnableFlg) {
2623 switch (m_ctlInfo.flash.m_flashCnt) {
Younghwan Joo9257e292012-09-08 21:11:18 -07002624 case IS_FLASH_ON:
2625 if (shot_ext->shot.dm.flash.decision > 0) {
2626 // store decision result to skip capture sequenece
2627 if (shot_ext->shot.dm.flash.decision == 2)
2628 m_ctlInfo.flash.m_flashDecisionResult = false;
2629 else
2630 m_ctlInfo.flash.m_flashDecisionResult = true;
2631 m_ctlInfo.flash.m_flashCnt = IS_FLASH_ON_DONE;
2632 ALOGV("(%s): [Flash] IS_FLASH_ON, decision - %d", __FUNCTION__, shot_ext->shot.dm.flash.decision);
2633 } else {
2634 if (m_ctlInfo.flash.m_flashTimeOut == 0) {
2635 m_ctlInfo.flash.m_flashCnt = IS_FLASH_ON_DONE;
2636 m_ctlInfo.flash.m_flashDecisionResult = false;
2637 ALOGE("(%s): [Flash] Timeout IS_FLASH_ON, decision is false setting", __FUNCTION__);
2638 } else {
2639 m_ctlInfo.flash.m_flashTimeOut--;
2640 }
2641 }
2642 break;
2643 case IS_FLASH_AE_AWB_LOCK_WAIT:
2644 if (shot_ext->shot.dm.aa.awbMode == AA_AWBMODE_LOCKED) {
2645 ALOGV("(%s): [Flash] FLASH_AUTO_AE_AWB_LOCK_WAIT - %d", __FUNCTION__, shot_ext->shot.dm.aa.awbMode);
2646 m_ctlInfo.flash.m_flashCnt = IS_FLASH_AUTO_WAIT;
2647 } else {
2648 ALOGV("(%s): [Flash] Waiting : AA_AWBMODE_LOCKED", __FUNCTION__);
2649 }
2650 break;
Younghwan Joo9a710a42012-09-05 17:52:08 -07002651 case IS_FLASH_CAPTURE_WAIT:
Younghwan Joocaea49e2012-09-07 13:34:20 -07002652 if (m_ctlInfo.flash.m_flashDecisionResult) {
2653 if (shot_ext->shot.dm.flash.firingStable) {
Younghwan Joo9a710a42012-09-05 17:52:08 -07002654 m_ctlInfo.flash.m_flashCnt = IS_FLASH_CAPTURE_JPEG;
2655 } else {
Younghwan Joocaea49e2012-09-07 13:34:20 -07002656 if (m_ctlInfo.flash.m_flashTimeOut == 0) {
2657 ALOGE("(%s): [Flash] Wait firingStable time-out!!", __FUNCTION__);
2658 m_ctlInfo.flash.m_flashCnt = IS_FLASH_CAPTURE_JPEG;
2659 } else {
2660 m_ctlInfo.flash.m_flashTimeOut--;
2661 }
Younghwan Joo9a710a42012-09-05 17:52:08 -07002662 }
Younghwan Joocaea49e2012-09-07 13:34:20 -07002663 } else {
2664 m_ctlInfo.flash.m_flashCnt = IS_FLASH_CAPTURE_JPEG;
Younghwan Joo6f19b6c2012-08-30 13:56:53 -07002665 }
2666 break;
2667 }
2668 }
Younghwan Joo6f19b6c2012-08-30 13:56:53 -07002669}
2670
Sungjoong Kang13d8c7b2012-07-14 10:20:39 +09002671void ExynosCameraHWInterface2::m_sensorThreadFunc(SignalDrivenThread * self)
2672{
2673 uint32_t currentSignal = self->GetProcessingSignal();
2674 SensorThread * selfThread = ((SensorThread*)self);
2675 int index;
Sungjoong Kangad378612012-08-17 12:34:33 -07002676 int index_isp;
Sungjoong Kang13d8c7b2012-07-14 10:20:39 +09002677 status_t res;
2678 nsecs_t frameTime;
2679 int bayersOnSensor = 0, bayersOnIsp = 0;
Sungjoong Kangad378612012-08-17 12:34:33 -07002680 int j = 0;
2681 bool isCapture = false;
Sungjoong Kang13d8c7b2012-07-14 10:20:39 +09002682 ALOGV("DEBUG(%s): m_sensorThreadFunc (%x)", __FUNCTION__, currentSignal);
2683
2684 if (currentSignal & SIGNAL_THREAD_RELEASE) {
Sungjoong Kangad378612012-08-17 12:34:33 -07002685 ALOGV("(%s): ENTER processing SIGNAL_THREAD_RELEASE", __FUNCTION__);
Sungjoong Kang13d8c7b2012-07-14 10:20:39 +09002686
Sungjoong Kang9dd63e12012-07-24 00:25:51 +09002687 ALOGV("(%s): calling sensor streamoff", __FUNCTION__);
Sungjoong Kang13d8c7b2012-07-14 10:20:39 +09002688 cam_int_streamoff(&(m_camera_info.sensor));
Sungjoong Kang9dd63e12012-07-24 00:25:51 +09002689 ALOGV("(%s): calling sensor streamoff done", __FUNCTION__);
Sungjoong Kangb5237e62012-07-27 07:39:05 -07002690
2691 m_camera_info.sensor.buffers = 0;
2692 ALOGV("DEBUG(%s): sensor calling reqbuf 0 ", __FUNCTION__);
2693 cam_int_reqbufs(&(m_camera_info.sensor));
2694 ALOGV("DEBUG(%s): sensor calling reqbuf 0 done", __FUNCTION__);
Sungjoong Kangad378612012-08-17 12:34:33 -07002695
Sungjoong Kang9dd63e12012-07-24 00:25:51 +09002696 ALOGV("(%s): calling ISP streamoff", __FUNCTION__);
2697 isp_int_streamoff(&(m_camera_info.isp));
2698 ALOGV("(%s): calling ISP streamoff done", __FUNCTION__);
Sungjoong Kangad378612012-08-17 12:34:33 -07002699
Sungjoong Kangb5237e62012-07-27 07:39:05 -07002700 m_camera_info.isp.buffers = 0;
2701 ALOGV("DEBUG(%s): isp calling reqbuf 0 ", __FUNCTION__);
2702 cam_int_reqbufs(&(m_camera_info.isp));
2703 ALOGV("DEBUG(%s): isp calling reqbuf 0 done", __FUNCTION__);
2704
Sungjoong Kang13d8c7b2012-07-14 10:20:39 +09002705 exynos_v4l2_s_ctrl(m_camera_info.sensor.fd, V4L2_CID_IS_S_STREAM, IS_DISABLE_STREAM);
Sungjoong Kang13d8c7b2012-07-14 10:20:39 +09002706
Sungjoong Kangad378612012-08-17 12:34:33 -07002707 ALOGV("(%s): EXIT processing SIGNAL_THREAD_RELEASE", __FUNCTION__);
Sungjoong Kang13d8c7b2012-07-14 10:20:39 +09002708 selfThread->SetSignal(SIGNAL_THREAD_TERMINATE);
2709 return;
2710 }
2711
2712 if (currentSignal & SIGNAL_SENSOR_START_REQ_PROCESSING)
2713 {
2714 ALOGV("DEBUG(%s): SensorThread processing SIGNAL_SENSOR_START_REQ_PROCESSING", __FUNCTION__);
Sungjoong Kang9dd63e12012-07-24 00:25:51 +09002715 int targetStreamIndex = 0, i=0;
Sungjoong Kangad378612012-08-17 12:34:33 -07002716 int matchedFrameCnt = -1, processingReqIndex;
Sungjoong Kang13d8c7b2012-07-14 10:20:39 +09002717 struct camera2_shot_ext *shot_ext;
Sungjoong Kangad378612012-08-17 12:34:33 -07002718 struct camera2_shot_ext *shot_ext_capture;
Sungjoong Kang0f26b202012-08-17 15:43:12 -07002719 bool triggered = false;
2720 int afMode;
Sungjoong Kang9dd63e12012-07-24 00:25:51 +09002721
Sungjoong Kangad378612012-08-17 12:34:33 -07002722 /* dqbuf from sensor */
2723 ALOGV("Sensor DQbuf start");
Sungjoong Kang13d8c7b2012-07-14 10:20:39 +09002724 index = cam_int_dqbuf(&(m_camera_info.sensor));
Sungjoong Kang9dd63e12012-07-24 00:25:51 +09002725 shot_ext = (struct camera2_shot_ext *)(m_camera_info.sensor.buffer[index].virt.extP[1]);
Sungjoong Kangad378612012-08-17 12:34:33 -07002726
2727 m_recordOutput = shot_ext->shot.ctl.request.outputStreams[2];
Sungjoong Kang74d78eb2012-08-29 13:25:46 -07002728 m_previewCbOutput = shot_ext->shot.ctl.request.outputStreams[3];
Sungjoong Kangad378612012-08-17 12:34:33 -07002729
Sungjoong Kanga15b4e32012-08-28 12:55:39 -07002730 if (m_nightCaptureCnt != 0) {
2731 matchedFrameCnt = m_nightCaptureFrameCnt;
Younghwan Joo9a710a42012-09-05 17:52:08 -07002732 } else if (m_ctlInfo.flash.m_flashCnt != 0) {
2733 matchedFrameCnt = m_ctlInfo.flash.m_flashFrameCount;
Younghwan Joocaea49e2012-09-07 13:34:20 -07002734 ALOGV("Skip frame, request is fixed at %d", matchedFrameCnt);
Younghwan Joo6f19b6c2012-08-30 13:56:53 -07002735 } else {
Sungjoong Kanga15b4e32012-08-28 12:55:39 -07002736 matchedFrameCnt = m_requestManager->FindFrameCnt(shot_ext);
2737 }
Sungjoong Kangad378612012-08-17 12:34:33 -07002738
Sungjoong Kanga07cbd92012-07-27 12:03:29 -07002739 if (matchedFrameCnt != -1) {
Sungjoong Kangef6f83c2012-08-28 22:59:48 +09002740 frameTime = systemTime();
2741 m_requestManager->RegisterTimestamp(matchedFrameCnt, &frameTime);
2742 m_requestManager->UpdateIspParameters(shot_ext, matchedFrameCnt);
Younghwan Joo9a710a42012-09-05 17:52:08 -07002743
Younghwan Joocaea49e2012-09-07 13:34:20 -07002744 // Mapping Flash UI mode from aeMode
2745 if (shot_ext->shot.ctl.aa.aeMode >= AA_AEMODE_ON) {
Younghwan Joo9a710a42012-09-05 17:52:08 -07002746 m_ctlInfo.flash.i_flashMode = shot_ext->shot.ctl.aa.aeMode;
Younghwan Joocaea49e2012-09-07 13:34:20 -07002747 shot_ext->shot.ctl.aa.aeMode = AA_AEMODE_ON;
2748 }
Younghwan Joo9a710a42012-09-05 17:52:08 -07002749
Sungjoong Kang8e2c2fd2012-08-27 00:02:22 -07002750 if (m_afModeWaitingCnt != 0) {
2751 ALOGV("### Af Trigger pulled, waiting for mode change cnt(%d) ", m_afModeWaitingCnt);
2752 m_afModeWaitingCnt --;
2753 if (m_afModeWaitingCnt == 1) {
Sungjoong Kangcd13bb72012-08-28 13:05:01 -07002754 m_afModeWaitingCnt = 0;
Sungjoong Kang8e2c2fd2012-08-27 00:02:22 -07002755 OnAfTrigger(m_afPendingTriggerId);
2756 }
2757 }
hyeonmyeong Choi308291d2012-08-29 13:55:01 -07002758 m_zoomRatio = (float)m_camera2->getSensorW() / (float)shot_ext->shot.ctl.scaler.cropRegion[2];
Sungjoong Kange4657e32012-08-28 15:02:19 -07002759 float zoomLeft, zoomTop, zoomWidth, zoomHeight;
2760 int crop_x = 0, crop_y = 0, crop_w = 0, crop_h = 0;
2761
2762 m_getRatioSize(m_camera2->getSensorW(), m_camera2->getSensorH(),
2763 m_streamThreads[0]->m_parameters.outputWidth, m_streamThreads[0]->m_parameters.outputHeight,
2764 &crop_x, &crop_y,
2765 &crop_w, &crop_h,
2766 0);
2767
2768 if (m_streamThreads[0]->m_parameters.outputWidth >= m_streamThreads[0]->m_parameters.outputHeight) {
hyeonmyeong Choi308291d2012-08-29 13:55:01 -07002769 zoomWidth = m_camera2->getSensorW() / m_zoomRatio;
Sungjoong Kange4657e32012-08-28 15:02:19 -07002770 zoomHeight = zoomWidth *
2771 m_streamThreads[0]->m_parameters.outputHeight / m_streamThreads[0]->m_parameters.outputWidth;
2772 } else {
hyeonmyeong Choi308291d2012-08-29 13:55:01 -07002773 zoomHeight = m_camera2->getSensorH() / m_zoomRatio;
Sungjoong Kange4657e32012-08-28 15:02:19 -07002774 zoomWidth = zoomHeight *
2775 m_streamThreads[0]->m_parameters.outputWidth / m_streamThreads[0]->m_parameters.outputHeight;
2776 }
2777 zoomLeft = (crop_w - zoomWidth) / 2;
2778 zoomTop = (crop_h - zoomHeight) / 2;
2779
2780 int32_t new_cropRegion[3] = { zoomLeft, zoomTop, zoomWidth };
2781
hyeonmyeong Choi308291d2012-08-29 13:55:01 -07002782 if (new_cropRegion[0] * 2 + new_cropRegion[2] > m_camera2->getSensorW())
2783 new_cropRegion[2]--;
2784 else if (new_cropRegion[0] * 2 + new_cropRegion[2] < m_camera2->getSensorW())
2785 new_cropRegion[2]++;
2786
Sungjoong Kange4657e32012-08-28 15:02:19 -07002787 shot_ext->shot.ctl.scaler.cropRegion[0] = new_cropRegion[0];
2788 shot_ext->shot.ctl.scaler.cropRegion[1] = new_cropRegion[1];
2789 shot_ext->shot.ctl.scaler.cropRegion[2] = new_cropRegion[2];
Sungjoong Kang0f26b202012-08-17 15:43:12 -07002790 if (m_IsAfModeUpdateRequired) {
2791 ALOGE("### AF Mode change(Mode %d) ", m_afMode);
2792 shot_ext->shot.ctl.aa.afMode = m_afMode;
2793 if (m_afMode == AA_AFMODE_CONTINUOUS_VIDEO || m_afMode == AA_AFMODE_CONTINUOUS_PICTURE) {
2794 ALOGE("### With Automatic triger for continuous modes");
2795 m_afState = HAL_AFSTATE_STARTED;
2796 shot_ext->shot.ctl.aa.afTrigger = 1;
2797 triggered = true;
2798 }
2799 m_IsAfModeUpdateRequired = false;
2800 if (m_afMode2 != NO_CHANGE) {
2801 enum aa_afmode tempAfMode = m_afMode2;
2802 m_afMode2 = NO_CHANGE;
2803 SetAfMode(tempAfMode);
2804 }
2805 }
2806 else {
2807 shot_ext->shot.ctl.aa.afMode = NO_CHANGE;
2808 }
2809 if (m_IsAfTriggerRequired) {
Younghwan Joo9a710a42012-09-05 17:52:08 -07002810 if (m_ctlInfo.flash.m_afFlashEnableFlg) {
2811 if (m_ctlInfo.flash.m_afFlashCnt == IS_FLASH_AF_ON_DONE) {
Younghwan Joo6f19b6c2012-08-30 13:56:53 -07002812 // Flash is enabled and start AF
2813 if (m_afState == HAL_AFSTATE_SCANNING) {
2814 ALOGE("(%s): restarting trigger ", __FUNCTION__);
2815 } else {
2816 if (m_afState != HAL_AFSTATE_NEEDS_COMMAND)
2817 ALOGE("(%s): wrong trigger state %d", __FUNCTION__, m_afState);
2818 else
2819 m_afState = HAL_AFSTATE_STARTED;
2820 }
Younghwan Joocaea49e2012-09-07 13:34:20 -07002821 ALOGE("### AF Triggering with mode (%d)", m_afMode);
Younghwan Joo6f19b6c2012-08-30 13:56:53 -07002822 shot_ext->shot.ctl.aa.afTrigger = 1;
2823 shot_ext->shot.ctl.aa.afMode = m_afMode;
2824 m_IsAfTriggerRequired = false;
2825 }
2826 } else {
Younghwan Joocaea49e2012-09-07 13:34:20 -07002827 ALOGE("### AF Triggering with mode (%d)", m_afMode);
Younghwan Joo6f19b6c2012-08-30 13:56:53 -07002828 if (m_afState == HAL_AFSTATE_SCANNING) {
2829 ALOGE("(%s): restarting trigger ", __FUNCTION__);
2830 } else {
2831 if (m_afState != HAL_AFSTATE_NEEDS_COMMAND)
2832 ALOGE("(%s): wrong trigger state %d", __FUNCTION__, m_afState);
2833 else
2834 m_afState = HAL_AFSTATE_STARTED;
2835 }
2836 shot_ext->shot.ctl.aa.afTrigger = 1;
2837 shot_ext->shot.ctl.aa.afMode = m_afMode;
2838 m_IsAfTriggerRequired = false;
Sungjoong Kang36c106c2012-08-23 17:38:20 -07002839 }
Sungjoong Kang0f26b202012-08-17 15:43:12 -07002840 }
2841 else {
Sungjoong Kang8e2c2fd2012-08-27 00:02:22 -07002842 shot_ext->shot.ctl.aa.afTrigger = 0;
Sungjoong Kang0f26b202012-08-17 15:43:12 -07002843 }
Sungjoong Kangb55ed662012-08-31 21:31:34 -07002844 if (m_aspectChanged) {
2845 shot_ext->shot.ctl.aa.aeTargetFpsRange[0] = 15;
Sungjoong Kang15fd8232012-08-23 16:16:44 -07002846 shot_ext->shot.ctl.aa.aeTargetFpsRange[1] = 30;
Sungjoong Kangb55ed662012-08-31 21:31:34 -07002847 m_aspectChanged = false;
Sungjoong Kang15fd8232012-08-23 16:16:44 -07002848 }
2849 else {
Sungjoong Kangb55ed662012-08-31 21:31:34 -07002850 if (m_wideAspect) {
2851 shot_ext->setfile = ISS_SUB_SCENARIO_VIDEO;
2852 shot_ext->shot.ctl.aa.aeTargetFpsRange[0] = 30;
2853 shot_ext->shot.ctl.aa.aeTargetFpsRange[1] = 30;
2854 }
2855 else {
2856 shot_ext->setfile = ISS_SUB_SCENARIO_STILL;
2857 }
Sungjoong Kang15fd8232012-08-23 16:16:44 -07002858 }
Sungjoong Kang0f26b202012-08-17 15:43:12 -07002859 if (triggered)
2860 shot_ext->shot.ctl.aa.afTrigger = 1;
2861
2862 // TODO : check collision with AFMode Update
2863 if (m_IsAfLockRequired) {
2864 shot_ext->shot.ctl.aa.afMode = AA_AFMODE_OFF;
2865 m_IsAfLockRequired = false;
2866 }
Rebecca Schultz Zavin4ed2f102012-08-22 00:55:29 -07002867 ALOGV("### Isp Qbuf start(%d) count (%d), SCP(%d) SCC(%d) DIS(%d) shot_size(%d)",
Sungjoong Kangad378612012-08-17 12:34:33 -07002868 index,
2869 shot_ext->shot.ctl.request.frameCount,
2870 shot_ext->request_scp,
2871 shot_ext->request_scc,
2872 shot_ext->dis_bypass, sizeof(camera2_shot));
Sungjoong Kanga15b4e32012-08-28 12:55:39 -07002873 ALOGV("### m_nightCaptureCnt (%d)", m_nightCaptureCnt);
Sungjoong Kang8e2c2fd2012-08-27 00:02:22 -07002874 if (0 == shot_ext->shot.ctl.aa.afRegions[0] && 0 == shot_ext->shot.ctl.aa.afRegions[1]
2875 && 0 == shot_ext->shot.ctl.aa.afRegions[2] && 0 == shot_ext->shot.ctl.aa.afRegions[3]) {
2876 ALOGV("(%s): AF region resetting", __FUNCTION__);
2877 lastAfRegion[0] = 0;
2878 lastAfRegion[1] = 0;
2879 lastAfRegion[2] = 0;
2880 lastAfRegion[3] = 0;
2881 }
2882 else {
2883 if (!(lastAfRegion[0] == shot_ext->shot.ctl.aa.afRegions[0] && lastAfRegion[1] == shot_ext->shot.ctl.aa.afRegions[1]
2884 && lastAfRegion[2] == shot_ext->shot.ctl.aa.afRegions[2] && lastAfRegion[3] == shot_ext->shot.ctl.aa.afRegions[3])) {
Younghwan Joocaea49e2012-09-07 13:34:20 -07002885 ALOGE("(%s): AF region changed : triggering", __FUNCTION__);
Sungjoong Kang8e2c2fd2012-08-27 00:02:22 -07002886 shot_ext->shot.ctl.aa.afTrigger = 1;
2887 shot_ext->shot.ctl.aa.afMode = m_afMode;
2888 m_afState = HAL_AFSTATE_STARTED;
2889 lastAfRegion[0] = shot_ext->shot.ctl.aa.afRegions[0];
2890 lastAfRegion[1] = shot_ext->shot.ctl.aa.afRegions[1];
2891 lastAfRegion[2] = shot_ext->shot.ctl.aa.afRegions[2];
2892 lastAfRegion[3] = shot_ext->shot.ctl.aa.afRegions[3];
2893 }
Younghwan Jooda7ca692012-09-03 20:47:21 -07002894 // clear region infos in case of CAF mode
2895 if (m_afMode == AA_AFMODE_CONTINUOUS_VIDEO || m_afMode == AA_AFMODE_CONTINUOUS_PICTURE) {
2896 shot_ext->shot.ctl.aa.afRegions[0] = lastAfRegion[0] = 0;
2897 shot_ext->shot.ctl.aa.afRegions[1] = lastAfRegion[1] = 0;
2898 shot_ext->shot.ctl.aa.afRegions[2] = lastAfRegion[2] = 0;
2899 shot_ext->shot.ctl.aa.afRegions[3] = lastAfRegion[3] = 0;
2900 }
Sungjoong Kang8e2c2fd2012-08-27 00:02:22 -07002901 }
Sungjoong Kanga15b4e32012-08-28 12:55:39 -07002902 if (m_nightCaptureCnt == 0) {
2903 if (shot_ext->shot.ctl.aa.captureIntent == ANDROID_CONTROL_INTENT_STILL_CAPTURE
2904 && shot_ext->shot.ctl.aa.sceneMode == AA_SCENE_MODE_NIGHT) {
2905 shot_ext->shot.ctl.aa.sceneMode = AA_SCENE_MODE_NIGHT_CAPTURE;
2906 shot_ext->shot.ctl.aa.aeTargetFpsRange[0] = 2;
2907 shot_ext->shot.ctl.aa.aeTargetFpsRange[1] = 30;
2908 m_nightCaptureCnt = 4;
2909 m_nightCaptureFrameCnt = matchedFrameCnt;
2910 shot_ext->request_scc = 0;
2911 }
2912 }
2913 else if (m_nightCaptureCnt == 1) {
2914 shot_ext->shot.ctl.aa.sceneMode = AA_SCENE_MODE_NIGHT_CAPTURE;
2915 shot_ext->shot.ctl.aa.aeTargetFpsRange[0] = 2;
2916 shot_ext->shot.ctl.aa.aeTargetFpsRange[1] = 30;
2917 m_nightCaptureCnt--;
2918 shot_ext->request_scc = 1;
2919 }
2920 else if (m_nightCaptureCnt == 2 || m_nightCaptureCnt == 3 || m_nightCaptureCnt == 4) {
2921 shot_ext->shot.ctl.aa.sceneMode = AA_SCENE_MODE_NIGHT_CAPTURE;
2922 shot_ext->shot.ctl.aa.aeTargetFpsRange[0] = 2;
2923 shot_ext->shot.ctl.aa.aeTargetFpsRange[1] = 30;
2924 m_nightCaptureCnt--;
2925 shot_ext->request_scc = 0;
2926 }
Younghwan Joo6f19b6c2012-08-30 13:56:53 -07002927
2928 // Flash mode
2929 // Keep and Skip request_scc = 1 at flash enable mode to operate flash sequence
Younghwan Joo9a710a42012-09-05 17:52:08 -07002930 if ((m_ctlInfo.flash.i_flashMode >= AA_AEMODE_ON_AUTO_FLASH) && (m_ctlInfo.flash.m_flashEnableFlg == false)
Younghwan Joo6f19b6c2012-08-30 13:56:53 -07002931 && (m_cameraId == 0)) {
2932 if (shot_ext->shot.ctl.aa.captureIntent == ANDROID_CONTROL_INTENT_STILL_CAPTURE) {
2933 ALOGE("(%s): [Flash] Flash capture start : skip request scc 1#####", __FUNCTION__);
2934 shot_ext->request_scc = 0;
Younghwan Joo9a710a42012-09-05 17:52:08 -07002935 m_ctlInfo.flash.m_flashFrameCount = matchedFrameCnt;
2936 m_ctlInfo.flash.m_flashEnableFlg = true;
2937 m_ctlInfo.flash.m_flashCaptured = false;
2938 if(m_ctlInfo.flash.m_afFlashDoneFlg) {
2939 ALOGD("(%s): [Flash] Flash capture start", __FUNCTION__);
2940 m_ctlInfo.flash.m_flashCnt = IS_FLASH_CAPTURE;
2941 } else {
2942 ALOGD("(%s): [Flash] Flash ON start", __FUNCTION__);
2943 m_ctlInfo.flash.m_flashCnt = IS_FLASH_ON;
2944 }
2945 m_ctlInfo.flash.m_flashTimeOut = 3;
Younghwan Joocaea49e2012-09-07 13:34:20 -07002946 }
2947 }
2948
2949 // TODO : set torch mode for video recording. need to find proper position.
2950 // m_wideAspect is will be changed to recording hint
2951 if ((shot_ext->shot.ctl.flash.flashMode == CAM2_FLASH_MODE_SINGLE) && m_wideAspect) {
2952 shot_ext->shot.ctl.flash.flashMode = CAM2_FLASH_MODE_TORCH;
2953 shot_ext->shot.ctl.flash.firingPower = 10;
2954 m_ctlInfo.flash.m_flashTorchMode = true;
2955 } else if (m_wideAspect){
2956 shot_ext->shot.ctl.flash.flashMode = CAM2_FLASH_MODE_OFF;
2957 shot_ext->shot.ctl.flash.firingPower = 0;
2958 m_ctlInfo.flash.m_flashTorchMode = false;
2959 } else {
2960 if (m_ctlInfo.flash.m_flashTorchMode) {
2961 shot_ext->shot.ctl.flash.flashMode = CAM2_FLASH_MODE_OFF;
2962 shot_ext->shot.ctl.flash.firingPower = 0;
2963 m_ctlInfo.flash.m_flashTorchMode = false;
2964 } else {
2965 shot_ext->shot.ctl.flash.flashMode = CAM2_FLASH_MODE_NOP;
Younghwan Joo6f19b6c2012-08-30 13:56:53 -07002966 }
2967 }
2968
Younghwan Joo9257e292012-09-08 21:11:18 -07002969 flashListenerSensor(shot_ext);
Younghwan Joo6f19b6c2012-08-30 13:56:53 -07002970 flashSetter(shot_ext);
Younghwan Joocaea49e2012-09-07 13:34:20 -07002971
Sungjoong Kang8e2c2fd2012-08-27 00:02:22 -07002972 ALOGV("(%s): queued aa(%d) aemode(%d) awb(%d) afmode(%d) trigger(%d)", __FUNCTION__,
2973 (int)(shot_ext->shot.ctl.aa.mode), (int)(shot_ext->shot.ctl.aa.aeMode),
2974 (int)(shot_ext->shot.ctl.aa.awbMode), (int)(shot_ext->shot.ctl.aa.afMode),
2975 (int)(shot_ext->shot.ctl.aa.afTrigger));
hyeonmyeong Choi7d0efb52012-09-02 16:02:13 -07002976
2977 int current_scp = shot_ext->request_scp;
2978
hyeonmyeong Choic0b6e172012-09-05 00:51:31 -07002979 if (shot_ext->shot.dm.request.frameCount == 0) {
hyeonmyeong Choi2bbbf0c2012-09-09 11:50:21 -07002980 ALOGE("ERR(%s): dm.request.frameCount = %d", __FUNCTION__, shot_ext->shot.dm.request.frameCount);
hyeonmyeong Choic0b6e172012-09-05 00:51:31 -07002981 }
2982
Sungjoong Kangad378612012-08-17 12:34:33 -07002983 cam_int_qbuf(&(m_camera_info.isp), index);
Sungjoong Kangad378612012-08-17 12:34:33 -07002984
2985 usleep(10000);
Sungjoong Kangad378612012-08-17 12:34:33 -07002986
2987 ALOGV("### isp DQBUF start");
2988 index_isp = cam_int_dqbuf(&(m_camera_info.isp));
Sungjoong Kangef6f83c2012-08-28 22:59:48 +09002989
Sungjoong Kangad378612012-08-17 12:34:33 -07002990 shot_ext = (struct camera2_shot_ext *)(m_camera_info.isp.buffer[index_isp].virt.extP[1]);
2991
Younghwan Joo9257e292012-09-08 21:11:18 -07002992 flashListenerISP(shot_ext);
Younghwan Joo9a710a42012-09-05 17:52:08 -07002993
Sungjoong Kangad378612012-08-17 12:34:33 -07002994 ALOGV("### Isp DQbuf done(%d) count (%d), SCP(%d) SCC(%d) shot_size(%d)",
2995 index,
2996 shot_ext->shot.ctl.request.frameCount,
2997 shot_ext->request_scp,
2998 shot_ext->request_scc,
2999 shot_ext->dis_bypass, sizeof(camera2_shot));
Sungjoong Kangef6f83c2012-08-28 22:59:48 +09003000 ALOGV("(%s): DM aa(%d) aemode(%d) awb(%d) afmode(%d)", __FUNCTION__,
Sungjoong Kang8e2c2fd2012-08-27 00:02:22 -07003001 (int)(shot_ext->shot.dm.aa.mode), (int)(shot_ext->shot.dm.aa.aeMode),
3002 (int)(shot_ext->shot.dm.aa.awbMode),
3003 (int)(shot_ext->shot.dm.aa.afMode));
Sungjoong Kangad378612012-08-17 12:34:33 -07003004
Sungjoong Kangef6f83c2012-08-28 22:59:48 +09003005 m_previewOutput = 0;
hyeonmyeong Choi7d0efb52012-09-02 16:02:13 -07003006 // HACK
3007 //if (shot_ext->request_scp && m_requestManager->GetNumEntries() > 1) {
3008 if (current_scp && m_requestManager->GetNumEntries() > 1) {
Sungjoong Kangad378612012-08-17 12:34:33 -07003009 m_previewOutput = 1;
Sungjoong Kangb55ed662012-08-31 21:31:34 -07003010 m_scpOutputSignalCnt++;
Sungjoong Kangad378612012-08-17 12:34:33 -07003011 m_streamThreads[0]->SetSignal(SIGNAL_STREAM_DATA_COMING);
3012 }
hyeonmyeong Choi7d0efb52012-09-02 16:02:13 -07003013
3014 if (current_scp != shot_ext->request_scp) {
3015 ALOGW("WARN(%s): scp frame drop1 request_scp(%d to %d)",
3016 __FUNCTION__, current_scp, shot_ext->request_scp);
3017 }
Sungjoong Kang15fd8232012-08-23 16:16:44 -07003018 if (shot_ext->request_scc) {
Sungjoong Kanga15b4e32012-08-28 12:55:39 -07003019 ALOGV("### m_nightCaptureCnt (%d) request_scc true", m_nightCaptureCnt);
3020 memcpy(&m_jpegMetadata, &shot_ext->shot, sizeof(struct camera2_shot));
3021 int shutterSpeed = (m_jpegMetadata.dm.sensor.exposureTime/1000);
3022
3023 if (shutterSpeed < 0) {
3024 shutterSpeed = 100;
3025 }
Sungjoong Kang15fd8232012-08-23 16:16:44 -07003026 m_streamThreads[1]->SetSignal(SIGNAL_STREAM_DATA_COMING);
3027 }
Sungjoong Kangad378612012-08-17 12:34:33 -07003028
3029 ALOGV("(%s): SCP_CLOSING check sensor(%d) scc(%d) scp(%d) ", __FUNCTION__,
3030 shot_ext->request_sensor, shot_ext->request_scc, shot_ext->request_scp);
3031 if (shot_ext->request_scc + shot_ext->request_scp + shot_ext->request_sensor == 0) {
3032 ALOGV("(%s): SCP_CLOSING check OK ", __FUNCTION__);
3033 m_scp_closed = true;
3034 }
3035 else
3036 m_scp_closed = false;
3037
Sungjoong Kangfd2d78a2012-08-26 17:44:25 -07003038 if (!shot_ext->fd_bypass) {
3039 /* FD orientation axis transformation */
3040 for (int i=0; i < CAMERA2_MAX_FACES; i++) {
3041 if (shot_ext->shot.dm.stats.faceRectangles[i][0] > 0)
3042 shot_ext->shot.dm.stats.faceRectangles[i][0] = (m_camera2->m_curCameraInfo->sensorW
Sungjoong Kangef6f83c2012-08-28 22:59:48 +09003043 * shot_ext->shot.dm.stats.faceRectangles[i][0])
3044 / m_streamThreads[0].get()->m_parameters.outputWidth;
Sungjoong Kangfd2d78a2012-08-26 17:44:25 -07003045 if (shot_ext->shot.dm.stats.faceRectangles[i][1] > 0)
3046 shot_ext->shot.dm.stats.faceRectangles[i][1] = (m_camera2->m_curCameraInfo->sensorH
Sungjoong Kangef6f83c2012-08-28 22:59:48 +09003047 * shot_ext->shot.dm.stats.faceRectangles[i][1])
3048 / m_streamThreads[0].get()->m_parameters.outputHeight;
Sungjoong Kangfd2d78a2012-08-26 17:44:25 -07003049 if (shot_ext->shot.dm.stats.faceRectangles[i][2] > 0)
3050 shot_ext->shot.dm.stats.faceRectangles[i][2] = (m_camera2->m_curCameraInfo->sensorW
Sungjoong Kangef6f83c2012-08-28 22:59:48 +09003051 * shot_ext->shot.dm.stats.faceRectangles[i][2])
3052 / m_streamThreads[0].get()->m_parameters.outputWidth;
Sungjoong Kangfd2d78a2012-08-26 17:44:25 -07003053 if (shot_ext->shot.dm.stats.faceRectangles[i][3] > 0)
3054 shot_ext->shot.dm.stats.faceRectangles[i][3] = (m_camera2->m_curCameraInfo->sensorH
Sungjoong Kangef6f83c2012-08-28 22:59:48 +09003055 * shot_ext->shot.dm.stats.faceRectangles[i][3])
3056 / m_streamThreads[0].get()->m_parameters.outputHeight;
Sungjoong Kangfd2d78a2012-08-26 17:44:25 -07003057 }
3058 }
Younghwan Joo9a710a42012-09-05 17:52:08 -07003059 if (m_nightCaptureCnt == 0 && m_ctlInfo.flash.m_flashCnt == 0) {
Sungjoong Kanga15b4e32012-08-28 12:55:39 -07003060 m_requestManager->ApplyDynamicMetadata(shot_ext);
3061 }
Sungjoong Kang0f26b202012-08-17 15:43:12 -07003062 OnAfNotification(shot_ext->shot.dm.aa.afState);
Sungjoong Kang13d8c7b2012-07-14 10:20:39 +09003063 }
Sungjoong Kangad378612012-08-17 12:34:33 -07003064
Sungjoong Kang0f26b202012-08-17 15:43:12 -07003065 processingReqIndex = m_requestManager->MarkProcessingRequest(&(m_camera_info.sensor.buffer[index]), &afMode);
Sungjoong Kangef6f83c2012-08-28 22:59:48 +09003066 if (processingReqIndex != -1)
Sungjoong Kang0f26b202012-08-17 15:43:12 -07003067 SetAfMode((enum aa_afmode)afMode);
Sungjoong Kangef6f83c2012-08-28 22:59:48 +09003068
Sungjoong Kangad378612012-08-17 12:34:33 -07003069
3070 shot_ext = (struct camera2_shot_ext *)(m_camera_info.sensor.buffer[index].virt.extP[1]);
3071 if (m_scp_closing || m_scp_closed) {
3072 ALOGD("(%s): SCP_CLOSING(%d) SCP_CLOSED(%d)", __FUNCTION__, m_scp_closing, m_scp_closed);
3073 shot_ext->request_scc = 0;
3074 shot_ext->request_scp = 0;
3075 shot_ext->request_sensor = 0;
3076 }
3077
Sungjoong Kangad378612012-08-17 12:34:33 -07003078 cam_int_qbuf(&(m_camera_info.sensor), index);
3079 ALOGV("### Sensor QBUF done");
3080
Sungjoong Kangef6f83c2012-08-28 22:59:48 +09003081 if (!m_scp_closing
3082 && ((matchedFrameCnt == -1) || (processingReqIndex == -1))){
Younghwan Jooda7ca692012-09-03 20:47:21 -07003083 ALOGV("make bubble shot: matchedFramcnt(%d) processingReqIndex(%d)",
Sungjoong Kangef6f83c2012-08-28 22:59:48 +09003084 matchedFrameCnt, processingReqIndex);
Sungjoong Kang13d8c7b2012-07-14 10:20:39 +09003085 selfThread->SetSignal(SIGNAL_SENSOR_START_REQ_PROCESSING);
Sungjoong Kang13d8c7b2012-07-14 10:20:39 +09003086 }
Sungjoong Kang9dd63e12012-07-24 00:25:51 +09003087 }
Sungjoong Kang13d8c7b2012-07-14 10:20:39 +09003088 return;
3089}
3090
Sungjoong Kang13d8c7b2012-07-14 10:20:39 +09003091void ExynosCameraHWInterface2::m_ispThreadInitialize(SignalDrivenThread * self)
3092{
3093 ALOGV("DEBUG(%s): ", __FUNCTION__ );
Sungjoong Kangad378612012-08-17 12:34:33 -07003094 /* will add */
Jiyoung Shinc15a6b02012-06-05 01:08:14 -07003095 return;
3096}
3097
Jiyoung Shinc15a6b02012-06-05 01:08:14 -07003098
Sungjoong Kang13d8c7b2012-07-14 10:20:39 +09003099void ExynosCameraHWInterface2::m_ispThreadFunc(SignalDrivenThread * self)
3100{
Sungjoong Kangad378612012-08-17 12:34:33 -07003101 ALOGV("DEBUG(%s): ", __FUNCTION__ );
3102 /* will add */
Jiyoung Shinc15a6b02012-06-05 01:08:14 -07003103 return;
3104}
3105
Sungjoong Kang86646da2012-08-28 17:29:11 +09003106void ExynosCameraHWInterface2::m_streamBufferInit(SignalDrivenThread *self)
3107{
3108 uint32_t currentSignal = self->GetProcessingSignal();
3109 StreamThread * selfThread = ((StreamThread*)self);
3110 stream_parameters_t *selfStreamParms = &(selfThread->m_parameters);
3111 record_parameters_t *selfRecordParms = &(selfThread->m_recordParameters);
Sungjoong Kang74d78eb2012-08-29 13:25:46 -07003112 callback_parameters_t *selfPreviewCbParms = &(selfThread->m_previewCbParameters);
Sungjoong Kang86646da2012-08-28 17:29:11 +09003113 node_info_t *currentNode = &(selfStreamParms->node);
3114
3115 buffer_handle_t * buf = NULL;
3116 status_t res;
3117 void *virtAddr[3];
3118 int i, j;
3119 int index;
3120 nsecs_t timestamp;
3121
3122 if (!(selfThread->m_isBufferInit))
3123 {
3124 for ( i=0 ; i < selfStreamParms->numSvcBuffers; i++) {
3125 res = selfStreamParms->streamOps->dequeue_buffer(selfStreamParms->streamOps, &buf);
3126 if (res != NO_ERROR || buf == NULL) {
3127 ALOGE("ERR(%s): Init: unable to dequeue buffer : %d",__FUNCTION__ , res);
3128 return;
3129 }
3130 ALOGV("DEBUG(%s): got buf(%x) version(%d), numFds(%d), numInts(%d)", __FUNCTION__, (uint32_t)(*buf),
3131 ((native_handle_t*)(*buf))->version, ((native_handle_t*)(*buf))->numFds, ((native_handle_t*)(*buf))->numInts);
3132
3133 if (m_grallocHal->lock(m_grallocHal, *buf,
3134 selfStreamParms->usage,
3135 0, 0, selfStreamParms->outputWidth, selfStreamParms->outputHeight, virtAddr) != 0) {
3136 ALOGE("ERR(%s): could not obtain gralloc buffer", __FUNCTION__);
3137 return;
3138 }
3139 ALOGV("DEBUG(%s): locked img buf plane0(%x) plane1(%x) plane2(%x)",
3140 __FUNCTION__, (unsigned int)virtAddr[0], (unsigned int)virtAddr[1], (unsigned int)virtAddr[2]);
3141
3142 index = selfThread->findBufferIndex(virtAddr[0]);
3143 if (index == -1) {
3144 ALOGE("ERR(%s): could not find buffer index", __FUNCTION__);
3145 }
3146 else {
3147 ALOGV("DEBUG(%s): found buffer index[%d] - status(%d)",
3148 __FUNCTION__, index, selfStreamParms->svcBufStatus[index]);
3149 if (selfStreamParms->svcBufStatus[index]== REQUIRES_DQ_FROM_SVC)
3150 selfStreamParms->svcBufStatus[index] = ON_DRIVER;
3151 else if (selfStreamParms->svcBufStatus[index]== ON_SERVICE)
3152 selfStreamParms->svcBufStatus[index] = ON_HAL;
3153 else {
3154 ALOGV("DBG(%s): buffer status abnormal (%d) "
3155 , __FUNCTION__, selfStreamParms->svcBufStatus[index]);
3156 }
3157 selfStreamParms->numSvcBufsInHal++;
3158 if (*buf != selfStreamParms->svcBufHandle[index])
3159 ALOGV("DBG(%s): different buf_handle index ", __FUNCTION__);
3160 else
3161 ALOGV("DEBUG(%s): same buf_handle index", __FUNCTION__);
3162 }
3163 selfStreamParms->svcBufIndex = 0;
3164 }
3165 selfThread->m_isBufferInit = true;
3166 }
3167
3168 if (m_recordingEnabled && m_needsRecordBufferInit) {
3169 ALOGV("DEBUG(%s): Recording Buffer Initialization numsvcbuf(%d)",
3170 __FUNCTION__, selfRecordParms->numSvcBuffers);
3171 int checkingIndex = 0;
3172 bool found = false;
3173 for ( i=0 ; i < selfRecordParms->numSvcBuffers; i++) {
3174 res = selfRecordParms->streamOps->dequeue_buffer(selfRecordParms->streamOps, &buf);
3175 if (res != NO_ERROR || buf == NULL) {
3176 ALOGE("ERR(%s): Init: unable to dequeue buffer : %d",__FUNCTION__ , res);
3177 return;
3178 }
3179 selfRecordParms->numSvcBufsInHal++;
3180 ALOGV("DEBUG(%s): [record] got buf(%x) bufInHal(%d) version(%d), numFds(%d), numInts(%d)", __FUNCTION__, (uint32_t)(*buf),
3181 selfRecordParms->numSvcBufsInHal, ((native_handle_t*)(*buf))->version, ((native_handle_t*)(*buf))->numFds, ((native_handle_t*)(*buf))->numInts);
3182
3183 if (m_grallocHal->lock(m_grallocHal, *buf,
3184 selfRecordParms->usage, 0, 0,
3185 selfRecordParms->outputWidth, selfRecordParms->outputHeight, virtAddr) != 0) {
3186 ALOGE("ERR(%s): could not obtain gralloc buffer", __FUNCTION__);
3187 }
3188 else {
3189 ALOGV("DEBUG(%s): [record] locked img buf plane0(%x) plane1(%x) plane2(%x)",
3190 __FUNCTION__, (unsigned int)virtAddr[0], (unsigned int)virtAddr[1], (unsigned int)virtAddr[2]);
3191 }
3192 found = false;
3193 for (checkingIndex = 0; checkingIndex < selfRecordParms->numSvcBuffers ; checkingIndex++) {
3194 if (selfRecordParms->svcBufHandle[checkingIndex] == *buf ) {
3195 found = true;
3196 break;
3197 }
3198 }
3199 ALOGV("DEBUG(%s): [record] found(%d) - index[%d]", __FUNCTION__, found, checkingIndex);
3200 if (!found) break;
3201
3202 index = checkingIndex;
3203
3204 if (index == -1) {
3205 ALOGV("ERR(%s): could not find buffer index", __FUNCTION__);
3206 }
3207 else {
3208 ALOGV("DEBUG(%s): found buffer index[%d] - status(%d)",
3209 __FUNCTION__, index, selfRecordParms->svcBufStatus[index]);
3210 if (selfRecordParms->svcBufStatus[index]== ON_SERVICE)
3211 selfRecordParms->svcBufStatus[index] = ON_HAL;
3212 else {
3213 ALOGV("DBG(%s): buffer status abnormal (%d) "
3214 , __FUNCTION__, selfRecordParms->svcBufStatus[index]);
3215 }
3216 if (*buf != selfRecordParms->svcBufHandle[index])
3217 ALOGV("DBG(%s): different buf_handle index ", __FUNCTION__);
3218 else
3219 ALOGV("DEBUG(%s): same buf_handle index", __FUNCTION__);
3220 }
3221 selfRecordParms->svcBufIndex = 0;
3222 }
3223 m_needsRecordBufferInit = false;
3224 }
Sungjoong Kang74d78eb2012-08-29 13:25:46 -07003225 if (m_previewCbEnabled && m_needsPreviewCbBufferInit) {
3226 ALOGV("DEBUG(%s): previewCb Buffer Initialization numsvcbuf(%d)",
3227 __FUNCTION__, selfPreviewCbParms->numSvcBuffers);
3228 int checkingIndex = 0;
3229 bool found = false;
3230
3231 m_getAlignedYUVSize(HAL_PIXEL_FORMAT_2_V4L2_PIX(selfPreviewCbParms->internalFormat), selfPreviewCbParms->outputWidth,
3232 selfPreviewCbParms->outputHeight, &m_previewCbBuf);
3233 ALOGV("(%s): PreviewCb tempbuf size : %d %d %d", __FUNCTION__, m_previewCbBuf.size.extS[0],
3234 m_previewCbBuf.size.extS[1], m_previewCbBuf.size.extS[2]);
3235
3236 if (allocCameraMemory(selfStreamParms->ionClient, &m_previewCbBuf, selfPreviewCbParms->internalPlanes) == -1) {
3237 ALOGE("ERR(%s): Failed to allocate previewcb buf", __FUNCTION__);
3238 }
3239
3240 for ( i=0 ; i < selfPreviewCbParms->numSvcBuffers; i++) {
3241 res = selfPreviewCbParms->streamOps->dequeue_buffer(selfPreviewCbParms->streamOps, &buf);
3242 if (res != NO_ERROR || buf == NULL) {
3243 ALOGE("ERR(%s): Init: unable to dequeue buffer : %d",__FUNCTION__ , res);
3244 return;
3245 }
3246 selfPreviewCbParms->numSvcBufsInHal++;
3247 ALOGV("DEBUG(%s): [previewCb] got buf(%x) bufInHal(%d) version(%d), numFds(%d), numInts(%d)", __FUNCTION__, (uint32_t)(*buf),
3248 selfPreviewCbParms->numSvcBufsInHal, ((native_handle_t*)(*buf))->version, ((native_handle_t*)(*buf))->numFds, ((native_handle_t*)(*buf))->numInts);
3249
3250 if (m_grallocHal->lock(m_grallocHal, *buf,
3251 selfPreviewCbParms->usage, 0, 0,
3252 selfPreviewCbParms->outputWidth, selfPreviewCbParms->outputHeight, virtAddr) != 0) {
3253 ALOGE("ERR(%s): could not obtain gralloc buffer", __FUNCTION__);
3254 }
3255 else {
3256 ALOGV("DEBUG(%s): [previewCb] locked img buf plane0(%x) plane1(%x) plane2(%x)",
3257 __FUNCTION__, (unsigned int)virtAddr[0], (unsigned int)virtAddr[1], (unsigned int)virtAddr[2]);
3258 }
3259 found = false;
3260 for (checkingIndex = 0; checkingIndex < selfPreviewCbParms->numSvcBuffers ; checkingIndex++) {
3261 if (selfPreviewCbParms->svcBufHandle[checkingIndex] == *buf ) {
3262 found = true;
3263 break;
3264 }
3265 }
3266 ALOGV("DEBUG(%s): [previewCb] found(%d) - index[%d]", __FUNCTION__, found, checkingIndex);
3267 if (!found) break;
3268
3269 index = checkingIndex;
3270
3271 if (index == -1) {
3272 ALOGV("ERR(%s): could not find buffer index", __FUNCTION__);
3273 }
3274 else {
3275 ALOGV("DEBUG(%s): found buffer index[%d] - status(%d)",
3276 __FUNCTION__, index, selfPreviewCbParms->svcBufStatus[index]);
3277 if (selfPreviewCbParms->svcBufStatus[index]== ON_SERVICE)
3278 selfPreviewCbParms->svcBufStatus[index] = ON_HAL;
3279 else {
3280 ALOGV("DBG(%s): buffer status abnormal (%d) "
3281 , __FUNCTION__, selfPreviewCbParms->svcBufStatus[index]);
3282 }
3283 if (*buf != selfPreviewCbParms->svcBufHandle[index])
3284 ALOGV("DBG(%s): different buf_handle index ", __FUNCTION__);
3285 else
3286 ALOGV("DEBUG(%s): same buf_handle index", __FUNCTION__);
3287 }
3288 selfPreviewCbParms->svcBufIndex = 0;
3289 }
3290 m_needsPreviewCbBufferInit = false;
3291 }
Sungjoong Kang86646da2012-08-28 17:29:11 +09003292
3293}
3294
Jiyoung Shinc15a6b02012-06-05 01:08:14 -07003295void ExynosCameraHWInterface2::m_streamThreadInitialize(SignalDrivenThread * self)
3296{
Sungjoong Kang13d8c7b2012-07-14 10:20:39 +09003297 StreamThread * selfThread = ((StreamThread*)self);
3298 ALOGV("DEBUG(%s): ", __FUNCTION__ );
3299 memset(&(selfThread->m_parameters), 0, sizeof(stream_parameters_t));
3300 selfThread->m_isBufferInit = false;
3301
Jiyoung Shinc15a6b02012-06-05 01:08:14 -07003302 return;
3303}
3304
Sungjoong Kang86646da2012-08-28 17:29:11 +09003305void ExynosCameraHWInterface2::m_streamFunc0(SignalDrivenThread *self)
Jiyoung Shinc15a6b02012-06-05 01:08:14 -07003306{
Sungjoong Kang13d8c7b2012-07-14 10:20:39 +09003307 uint32_t currentSignal = self->GetProcessingSignal();
3308 StreamThread * selfThread = ((StreamThread*)self);
3309 stream_parameters_t *selfStreamParms = &(selfThread->m_parameters);
Sungjoong Kang9dd63e12012-07-24 00:25:51 +09003310 record_parameters_t *selfRecordParms = &(selfThread->m_recordParameters);
Sungjoong Kang74d78eb2012-08-29 13:25:46 -07003311 callback_parameters_t *selfPreviewCbParms = &(selfThread->m_previewCbParameters);
Sungjoong Kang13d8c7b2012-07-14 10:20:39 +09003312 node_info_t *currentNode = &(selfStreamParms->node);
Jiyoung Shinc15a6b02012-06-05 01:08:14 -07003313
Sungjoong Kang13d8c7b2012-07-14 10:20:39 +09003314 if (currentSignal & SIGNAL_STREAM_CHANGE_PARAMETER) {
3315 ALOGV("DEBUG(%s): processing SIGNAL_STREAM_CHANGE_PARAMETER", __FUNCTION__);
Jiyoung Shinc15a6b02012-06-05 01:08:14 -07003316
Sungjoong Kang13d8c7b2012-07-14 10:20:39 +09003317 ALOGV("DEBUG(%s): processing SIGNAL_STREAM_CHANGE_PARAMETER DONE", __FUNCTION__);
Jiyoung Shinc15a6b02012-06-05 01:08:14 -07003318 }
Sungjoong Kang13d8c7b2012-07-14 10:20:39 +09003319
Sungjoong Kangb55ed662012-08-31 21:31:34 -07003320 if (currentSignal & SIGNAL_THREAD_RELEASE) {
3321 int i, index = -1, cnt_to_dq = 0;
3322 status_t res;
3323 ALOGV("DEBUG(%s): processing SIGNAL_THREAD_RELEASE", __FUNCTION__);
3324 ALOGD("(%s):(%d) SIGNAL_THREAD_RELEASE", __FUNCTION__, selfStreamParms->streamType);
3325
3326 if (selfThread->m_isBufferInit) {
3327 for ( i=0 ; i < selfStreamParms->numSvcBuffers; i++) {
3328 ALOGV("DEBUG(%s): checking buffer index[%d] - status(%d)",
3329 __FUNCTION__, i, selfStreamParms->svcBufStatus[i]);
3330 if (selfStreamParms->svcBufStatus[i] ==ON_DRIVER) cnt_to_dq++;
3331 }
3332
3333 ALOGV("DEBUG(%s): calling stream(%d) streamoff (fd:%d)", __FUNCTION__,
3334 selfThread->m_index, selfStreamParms->fd);
3335 if (cam_int_streamoff(&(selfStreamParms->node)) < 0 ){
3336 ALOGE("ERR(%s): stream off fail", __FUNCTION__);
3337 } else {
3338 m_scp_closing = true;
3339 }
3340 ALOGV("DEBUG(%s): calling stream(%d) streamoff done", __FUNCTION__, selfThread->m_index);
3341 ALOGV("DEBUG(%s): calling stream(%d) reqbuf 0 (fd:%d)", __FUNCTION__,
3342 selfThread->m_index, selfStreamParms->fd);
3343 currentNode->buffers = 0;
3344 cam_int_reqbufs(currentNode);
3345 ALOGV("DEBUG(%s): calling stream(%d) reqbuf 0 DONE(fd:%d)", __FUNCTION__,
3346 selfThread->m_index, selfStreamParms->fd);
3347 }
3348#ifdef ENABLE_FRAME_SYNC
3349 // free metabuffers
3350 for(i = 0; i < NUM_MAX_CAMERA_BUFFERS; i++)
3351 if(selfStreamParms->metaBuffers[i].fd.extFd[0] != 0){
3352 freeCameraMemory(&(selfStreamParms->metaBuffers[i]), 1);
3353 selfStreamParms->metaBuffers[i].fd.extFd[0] = 0;
3354 selfStreamParms->metaBuffers[i].size.extS[0] = 0;
3355 }
3356#endif
3357 selfThread->m_isBufferInit = false;
3358 selfThread->m_index = 255;
3359
3360 selfThread->m_releasing = false;
3361
3362 ALOGV("DEBUG(%s): processing SIGNAL_THREAD_RELEASE DONE", __FUNCTION__);
3363
3364 return;
3365 }
3366
Sungjoong Kang13d8c7b2012-07-14 10:20:39 +09003367 if (currentSignal & SIGNAL_STREAM_DATA_COMING) {
Jiyoung Shinc15a6b02012-06-05 01:08:14 -07003368 buffer_handle_t * buf = NULL;
3369 status_t res;
3370 void *virtAddr[3];
3371 int i, j;
3372 int index;
Sungjoong Kangad378612012-08-17 12:34:33 -07003373 nsecs_t timestamp;
Sungjoong Kangfeb7df42012-08-28 23:35:43 +09003374 camera2_stream *frame;
Sungjoong Kangad378612012-08-17 12:34:33 -07003375
hyeonmyeong Choic0b6e172012-09-05 00:51:31 -07003376 int numOfUndqbuf = 0;
3377 bool again = false;
3378
Sungjoong Kang13d8c7b2012-07-14 10:20:39 +09003379 ALOGV("DEBUG(%s): stream(%d) processing SIGNAL_STREAM_DATA_COMING",
3380 __FUNCTION__,selfThread->m_index);
Sungjoong Kangad378612012-08-17 12:34:33 -07003381
Sungjoong Kang86646da2012-08-28 17:29:11 +09003382 m_streamBufferInit(self);
Jiyoung Shinc15a6b02012-06-05 01:08:14 -07003383
Sungjoong Kangb5237e62012-07-27 07:39:05 -07003384 do {
Sungjoong Kang86646da2012-08-28 17:29:11 +09003385 ALOGV("DEBUG(%s): stream(%d) type(%d) DQBUF START ",__FUNCTION__,
3386 selfThread->m_index, selfStreamParms->streamType);
Jiyoung Shinc15a6b02012-06-05 01:08:14 -07003387
Sungjoong Kangfeb7df42012-08-28 23:35:43 +09003388#ifdef ENABLE_FRAME_SYNC
3389 index = cam_int_dqbuf(&(selfStreamParms->node), selfStreamParms->nodePlanes + selfStreamParms->metaPlanes);
3390 frame = (struct camera2_stream *)(selfStreamParms->metaBuffers[index].virt.extP[0]);
3391 ALOGD("frame count(SCP) : %d", frame->fcount);
3392#else
Sungjoong Kang86646da2012-08-28 17:29:11 +09003393 index = cam_int_dqbuf(&(selfStreamParms->node));
Sungjoong Kangfeb7df42012-08-28 23:35:43 +09003394#endif
Sungjoong Kangb55ed662012-08-31 21:31:34 -07003395 m_scpOutputImageCnt++;
3396 ALOGV("DEBUG(%s): stream(%d) DQBUF done index(%d) sigcnt(%d) imgcnt(%d)",__FUNCTION__,
3397 selfThread->m_index, index, m_scpOutputSignalCnt, m_scpOutputImageCnt);
Sungjoong Kang13d8c7b2012-07-14 10:20:39 +09003398
Sungjoong Kang86646da2012-08-28 17:29:11 +09003399 if (selfStreamParms->svcBufStatus[index] != ON_DRIVER)
3400 ALOGV("DBG(%s): DQed buffer status abnormal (%d) ",
3401 __FUNCTION__, selfStreamParms->svcBufStatus[index]);
3402 selfStreamParms->svcBufStatus[index] = ON_HAL;
Sungjoong Kang13d8c7b2012-07-14 10:20:39 +09003403
Sungjoong Kang86646da2012-08-28 17:29:11 +09003404 if (m_recordOutput && m_recordingEnabled) {
3405 ALOGV("DEBUG(%s): Entering record frame creator, index(%d)",__FUNCTION__, selfRecordParms->svcBufIndex);
Sungjoong Kang37e122d2012-08-08 11:13:48 -07003406 bool found = false;
Sungjoong Kang86646da2012-08-28 17:29:11 +09003407 for (int i = 0 ; selfRecordParms->numSvcBuffers ; i++) {
3408 if (selfRecordParms->svcBufStatus[selfRecordParms->svcBufIndex] == ON_HAL) {
Sungjoong Kang37e122d2012-08-08 11:13:48 -07003409 found = true;
3410 break;
3411 }
Sungjoong Kang86646da2012-08-28 17:29:11 +09003412 selfRecordParms->svcBufIndex++;
3413 if (selfRecordParms->svcBufIndex >= selfRecordParms->numSvcBuffers)
3414 selfRecordParms->svcBufIndex = 0;
Sungjoong Kang37e122d2012-08-08 11:13:48 -07003415 }
3416 if (!found) {
Sungjoong Kang86646da2012-08-28 17:29:11 +09003417 ALOGE("(%s): cannot find free recording buffer", __FUNCTION__);
3418 selfRecordParms->svcBufIndex++;
Sungjoong Kang37e122d2012-08-08 11:13:48 -07003419 break;
3420 }
Jiyoung Shinc15a6b02012-06-05 01:08:14 -07003421
Sungjoong Kang86646da2012-08-28 17:29:11 +09003422 if (m_exynosVideoCSC) {
3423 int videoW = selfRecordParms->outputWidth, videoH = selfRecordParms->outputHeight;
3424 int cropX, cropY, cropW, cropH = 0;
3425 int previewW = selfStreamParms->outputWidth, previewH = selfStreamParms->outputHeight;
3426 m_getRatioSize(previewW, previewH,
3427 videoW, videoH,
Sungjoong Kangb5237e62012-07-27 07:39:05 -07003428 &cropX, &cropY,
3429 &cropW, &cropH,
Sungjoong Kangad378612012-08-17 12:34:33 -07003430 0);
Sungjoong Kang13d8c7b2012-07-14 10:20:39 +09003431
Sungjoong Kangb5237e62012-07-27 07:39:05 -07003432 ALOGV("DEBUG(%s):cropX = %d, cropY = %d, cropW = %d, cropH = %d",
Sungjoong Kang86646da2012-08-28 17:29:11 +09003433 __FUNCTION__, cropX, cropY, cropW, cropH);
Sungjoong Kang13d8c7b2012-07-14 10:20:39 +09003434
Sungjoong Kang86646da2012-08-28 17:29:11 +09003435 csc_set_src_format(m_exynosVideoCSC,
3436 previewW, previewH,
Sungjoong Kangb5237e62012-07-27 07:39:05 -07003437 cropX, cropY, cropW, cropH,
Sungjoong Kang74d78eb2012-08-29 13:25:46 -07003438 selfStreamParms->outputFormat,
Sungjoong Kangb5237e62012-07-27 07:39:05 -07003439 0);
Sungjoong Kang13d8c7b2012-07-14 10:20:39 +09003440
Sungjoong Kang86646da2012-08-28 17:29:11 +09003441 csc_set_dst_format(m_exynosVideoCSC,
3442 videoW, videoH,
3443 0, 0, videoW, videoH,
3444 selfRecordParms->outputFormat,
3445 1);
Jiyoung Shinc15a6b02012-06-05 01:08:14 -07003446
Sungjoong Kang86646da2012-08-28 17:29:11 +09003447 csc_set_src_buffer(m_exynosVideoCSC,
3448 (void **)(&(selfStreamParms->svcBuffers[index].fd.fd)));
Sungjoong Kang13d8c7b2012-07-14 10:20:39 +09003449
Sungjoong Kang86646da2012-08-28 17:29:11 +09003450 csc_set_dst_buffer(m_exynosVideoCSC,
3451 (void **)(&(selfRecordParms->svcBuffers[selfRecordParms->svcBufIndex].fd.fd)));
Sungjoong Kang13d8c7b2012-07-14 10:20:39 +09003452
Sungjoong Kang86646da2012-08-28 17:29:11 +09003453 if (csc_convert(m_exynosVideoCSC) != 0) {
3454 ALOGE("ERR(%s):csc_convert() fail", __FUNCTION__);
3455 }
3456 else {
3457 ALOGV("(%s):csc_convert() SUCCESS", __FUNCTION__);
3458 }
Sungjoong Kang13d8c7b2012-07-14 10:20:39 +09003459 }
3460 else {
Sungjoong Kang86646da2012-08-28 17:29:11 +09003461 ALOGE("ERR(%s):m_exynosVideoCSC == NULL", __FUNCTION__);
Sungjoong Kang13d8c7b2012-07-14 10:20:39 +09003462 }
Sungjoong Kang13d8c7b2012-07-14 10:20:39 +09003463
Sungjoong Kang86646da2012-08-28 17:29:11 +09003464 res = selfRecordParms->streamOps->enqueue_buffer(selfRecordParms->streamOps,
3465 systemTime(),
3466 &(selfRecordParms->svcBufHandle[selfRecordParms->svcBufIndex]));
3467 ALOGV("DEBUG(%s): stream(%d) record enqueue_buffer to svc done res(%d)", __FUNCTION__,
3468 selfThread->m_index, res);
Sungjoong Kang37e122d2012-08-08 11:13:48 -07003469 if (res == 0) {
Sungjoong Kang86646da2012-08-28 17:29:11 +09003470 selfRecordParms->svcBufStatus[selfRecordParms->svcBufIndex] = ON_SERVICE;
3471 selfRecordParms->numSvcBufsInHal--;
Sungjoong Kangb5237e62012-07-27 07:39:05 -07003472 }
Sungjoong Kangb5237e62012-07-27 07:39:05 -07003473 }
hyeonmyeong Choic0b6e172012-09-05 00:51:31 -07003474
Sungjoong Kang74d78eb2012-08-29 13:25:46 -07003475 if (m_previewCbOutput && m_previewCbEnabled) {
3476 ALOGV("DEBUG(%s): Entering previewcb creator, index(%d)",__FUNCTION__, selfPreviewCbParms->svcBufIndex);
3477
3478 bool found = false;
3479 for (int i = 0 ; selfPreviewCbParms->numSvcBuffers ; i++) {
3480 if (selfPreviewCbParms->svcBufStatus[selfPreviewCbParms->svcBufIndex] == ON_HAL) {
3481 found = true;
3482 break;
3483 }
3484 selfPreviewCbParms->svcBufIndex++;
3485 if (selfPreviewCbParms->svcBufIndex >= selfPreviewCbParms->numSvcBuffers)
3486 selfPreviewCbParms->svcBufIndex = 0;
3487 }
3488 if (!found) {
3489 ALOGE("(%s): cannot find free previewcb buffer", __FUNCTION__);
3490 selfPreviewCbParms->svcBufIndex++;
3491 break;
3492 }
3493 if (selfPreviewCbParms->outputFormat == HAL_PIXEL_FORMAT_YCrCb_420_SP) {
3494 if (m_exynosVideoCSC) {
3495 int previewCbW = selfPreviewCbParms->outputWidth, previewCbH = selfPreviewCbParms->outputHeight;
3496 int cropX, cropY, cropW, cropH = 0;
3497 int previewW = selfStreamParms->outputWidth, previewH = selfStreamParms->outputHeight;
3498 m_getRatioSize(previewW, previewH,
3499 previewCbW, previewCbH,
3500 &cropX, &cropY,
3501 &cropW, &cropH,
3502 0);
3503
3504 ALOGV("DEBUG(%s):cropX = %d, cropY = %d, cropW = %d, cropH = %d",
3505 __FUNCTION__, cropX, cropY, cropW, cropH);
3506 csc_set_src_format(m_exynosVideoCSC,
3507 previewW, previewH,
3508 cropX, cropY, cropW, cropH,
3509 selfStreamParms->outputFormat,
3510 0);
3511
3512 csc_set_dst_format(m_exynosVideoCSC,
3513 previewCbW, previewCbH,
3514 0, 0, previewCbW, previewCbH,
3515 selfPreviewCbParms->internalFormat,
3516 1);
3517
3518 csc_set_src_buffer(m_exynosVideoCSC,
3519 (void **)(&(selfStreamParms->svcBuffers[index].fd.fd)));
3520
3521 csc_set_dst_buffer(m_exynosVideoCSC,
3522 (void **)(&(m_previewCbBuf.fd.fd)));
3523
3524 if (csc_convert(m_exynosVideoCSC) != 0) {
3525 ALOGE("ERR(%s):previewcb csc_convert() fail", __FUNCTION__);
3526 }
3527 else {
3528 ALOGV("(%s):previewcb csc_convert() SUCCESS", __FUNCTION__);
3529 }
3530 if (previewCbW == ALIGN(previewCbW, 16)) {
3531 ALOGV("(%s):previewcb %d = %d", __FUNCTION__, previewCbW, ALIGN(previewCbW, 16));
3532 memcpy(selfPreviewCbParms->svcBuffers[selfPreviewCbParms->svcBufIndex].virt.extP[0],
3533 m_previewCbBuf.virt.extP[0], previewCbW * previewCbH);
3534 memcpy(selfPreviewCbParms->svcBuffers[selfPreviewCbParms->svcBufIndex].virt.extP[0] + previewCbW * previewCbH,
3535 m_previewCbBuf.virt.extP[1], previewCbW * previewCbH / 2 );
3536 }
3537 else {
3538 // TODO : copy line by line ?
3539 }
3540 }
3541 else {
3542 ALOGE("ERR(%s):m_exynosVideoCSC == NULL", __FUNCTION__);
3543 }
3544 }
3545 else if (selfPreviewCbParms->outputFormat == HAL_PIXEL_FORMAT_YV12) {
3546 int previewCbW = selfPreviewCbParms->outputWidth, previewCbH = selfPreviewCbParms->outputHeight;
3547 int stride = ALIGN(previewCbW, 16);
3548 int c_stride = ALIGN(stride, 16);
3549 memcpy(selfPreviewCbParms->svcBuffers[selfPreviewCbParms->svcBufIndex].virt.extP[0],
3550 selfStreamParms->svcBuffers[index].virt.extP[0], stride * previewCbH);
3551 memcpy(selfPreviewCbParms->svcBuffers[selfPreviewCbParms->svcBufIndex].virt.extP[0] + stride * previewCbH,
3552 selfStreamParms->svcBuffers[index].virt.extP[1], c_stride * previewCbH / 2 );
3553 memcpy(selfPreviewCbParms->svcBuffers[selfPreviewCbParms->svcBufIndex].virt.extP[0] + (stride * previewCbH) + (c_stride * previewCbH / 2),
3554 selfStreamParms->svcBuffers[index].virt.extP[2], c_stride * previewCbH / 2 );
3555
3556 }
3557 res = selfPreviewCbParms->streamOps->enqueue_buffer(selfPreviewCbParms->streamOps,
3558 systemTime(),
3559 &(selfPreviewCbParms->svcBufHandle[selfPreviewCbParms->svcBufIndex]));
3560 ALOGV("DEBUG(%s): stream(%d) previewcb enqueue_buffer[%d] to svc done res(%d)", __FUNCTION__,
3561 selfThread->m_index, index, res);
3562 if (res == 0) {
3563 selfPreviewCbParms->svcBufStatus[selfPreviewCbParms->svcBufIndex] = ON_SERVICE;
3564 selfPreviewCbParms->numSvcBufsInHal--;
3565 }
3566 }
hyeonmyeong Choic0b6e172012-09-05 00:51:31 -07003567
Sungjoong Kang86646da2012-08-28 17:29:11 +09003568 if (m_previewOutput && m_requestManager->GetSkipCnt() <= 0) {
3569
3570 ALOGV("** Display Preview(frameCnt:%d)", m_requestManager->GetFrameIndex());
3571 res = selfStreamParms->streamOps->enqueue_buffer(selfStreamParms->streamOps,
3572 m_requestManager->GetTimestamp(m_requestManager->GetFrameIndex()),
3573 &(selfStreamParms->svcBufHandle[index]));
3574
3575 ALOGV("DEBUG(%s): stream(%d) enqueue_buffer to svc done res(%d)", __FUNCTION__, selfThread->m_index, res);
3576 }
3577 else {
3578 res = selfStreamParms->streamOps->cancel_buffer(selfStreamParms->streamOps,
3579 &(selfStreamParms->svcBufHandle[index]));
3580 ALOGV("DEBUG(%s): stream(%d) cancel_buffer to svc done res(%d)", __FUNCTION__, selfThread->m_index, res);
3581 }
3582 if (res == 0) {
3583 selfStreamParms->svcBufStatus[index] = ON_SERVICE;
3584 selfStreamParms->numSvcBufsInHal--;
3585 }
3586 else {
3587 selfStreamParms->svcBufStatus[index] = ON_HAL;
3588 }
3589
hyeonmyeong Choic0b6e172012-09-05 00:51:31 -07003590 // HACK
hyeonmyeong Choi2bbbf0c2012-09-09 11:50:21 -07003591 if (again == false && !(m_recordOutput && m_recordingEnabled)) {
hyeonmyeong Choic0b6e172012-09-05 00:51:31 -07003592 if (exynos_v4l2_g_ctrl(currentNode->fd, V4L2_CID_IS_G_COMPLETES, &numOfUndqbuf)) {
3593 ALOGW("WARN(%s): Fail to get SCP completes, val = %d", __FUNCTION__, numOfUndqbuf);
3594 } else {
3595 again = (numOfUndqbuf > 0)?true:false;
3596 if (again)
3597 ALOGW("WARN(%s): Drain SCP buf, num of undqbuf = %d", __FUNCTION__, numOfUndqbuf);
3598 }
3599 } else {
3600 again = false;
3601 }
Sungjoong Kang13d8c7b2012-07-14 10:20:39 +09003602 }
hyeonmyeong Choic0b6e172012-09-05 00:51:31 -07003603 while(again);
Sungjoong Kangb5237e62012-07-27 07:39:05 -07003604
Sungjoong Kang86646da2012-08-28 17:29:11 +09003605 if (m_recordOutput && m_recordingEnabled) {
Sungjoong Kang9dd63e12012-07-24 00:25:51 +09003606 do {
Sungjoong Kangbe494d12012-08-04 15:36:56 -07003607 ALOGV("DEBUG(%s): record currentBuf#(%d)", __FUNCTION__ , selfRecordParms->numSvcBufsInHal);
3608 if (selfRecordParms->numSvcBufsInHal >= 1)
Sungjoong Kang9dd63e12012-07-24 00:25:51 +09003609 {
3610 ALOGV("DEBUG(%s): breaking", __FUNCTION__);
3611 break;
3612 }
3613 res = selfRecordParms->streamOps->dequeue_buffer(selfRecordParms->streamOps, &buf);
3614 if (res != NO_ERROR || buf == NULL) {
3615 ALOGV("DEBUG(%s): record stream(%d) dequeue_buffer fail res(%d)",__FUNCTION__ , selfThread->m_index, res);
3616 break;
3617 }
Sungjoong Kangbe494d12012-08-04 15:36:56 -07003618 selfRecordParms->numSvcBufsInHal ++;
Sungjoong Kang9dd63e12012-07-24 00:25:51 +09003619 ALOGV("DEBUG(%s): record got buf(%x) numBufInHal(%d) version(%d), numFds(%d), numInts(%d)", __FUNCTION__, (uint32_t)(*buf),
Sungjoong Kangbe494d12012-08-04 15:36:56 -07003620 selfRecordParms->numSvcBufsInHal, ((native_handle_t*)(*buf))->version, ((native_handle_t*)(*buf))->numFds, ((native_handle_t*)(*buf))->numInts);
Sungjoong Kangad378612012-08-17 12:34:33 -07003621
Sungjoong Kang9dd63e12012-07-24 00:25:51 +09003622 const private_handle_t *priv_handle = reinterpret_cast<const private_handle_t *>(*buf);
Sungjoong Kang9dd63e12012-07-24 00:25:51 +09003623 bool found = false;
3624 int checkingIndex = 0;
3625 for (checkingIndex = 0; checkingIndex < selfRecordParms->numSvcBuffers ; checkingIndex++) {
3626 if (priv_handle->fd == selfRecordParms->svcBuffers[checkingIndex].fd.extFd[0] ) {
3627 found = true;
3628 break;
3629 }
3630 }
3631 ALOGV("DEBUG(%s): recording dequeueed_buffer found index(%d)", __FUNCTION__, found);
Sungjoong Kangad378612012-08-17 12:34:33 -07003632
3633 if (!found) {
3634 break;
3635 }
3636
Sungjoong Kang9dd63e12012-07-24 00:25:51 +09003637 index = checkingIndex;
3638 if (selfRecordParms->svcBufStatus[index] == ON_SERVICE) {
3639 selfRecordParms->svcBufStatus[index] = ON_HAL;
3640 }
3641 else {
3642 ALOGV("DEBUG(%s): record bufstatus abnormal [%d] status = %d", __FUNCTION__,
Sungjoong Kangad378612012-08-17 12:34:33 -07003643 index, selfRecordParms->svcBufStatus[index]);
Sungjoong Kang9dd63e12012-07-24 00:25:51 +09003644 }
3645 } while (0);
3646 }
Sungjoong Kang74d78eb2012-08-29 13:25:46 -07003647 if (m_previewCbOutput && m_previewCbEnabled) {
3648 do {
3649 ALOGV("DEBUG(%s): previewCb currentBuf#(%d)", __FUNCTION__ , selfPreviewCbParms->numSvcBufsInHal);
3650 if (selfPreviewCbParms->numSvcBufsInHal >= 1)
3651 {
3652 ALOGV("DEBUG(%s): breaking", __FUNCTION__);
3653 break;
3654 }
3655 res = selfPreviewCbParms->streamOps->dequeue_buffer(selfPreviewCbParms->streamOps, &buf);
3656 if (res != NO_ERROR || buf == NULL) {
3657 ALOGV("DEBUG(%s): previewcb stream(%d) dequeue_buffer fail res(%d)",__FUNCTION__ , selfThread->m_index, res);
3658 break;
3659 }
3660 selfPreviewCbParms->numSvcBufsInHal ++;
3661 ALOGV("DEBUG(%s): previewcb got buf(%x) numBufInHal(%d) version(%d), numFds(%d), numInts(%d)", __FUNCTION__, (uint32_t)(*buf),
3662 selfPreviewCbParms->numSvcBufsInHal, ((native_handle_t*)(*buf))->version, ((native_handle_t*)(*buf))->numFds, ((native_handle_t*)(*buf))->numInts);
3663
3664 const private_handle_t *priv_handle = reinterpret_cast<const private_handle_t *>(*buf);
3665 bool found = false;
3666 int checkingIndex = 0;
3667 for (checkingIndex = 0; checkingIndex < selfPreviewCbParms->numSvcBuffers ; checkingIndex++) {
3668 if (priv_handle->fd == selfPreviewCbParms->svcBuffers[checkingIndex].fd.extFd[0] ) {
3669 found = true;
3670 break;
3671 }
3672 }
3673 ALOGV("DEBUG(%s): previewcb dequeueed_buffer found index(%d)", __FUNCTION__, found);
3674
3675 if (!found) {
3676 break;
3677 }
3678
3679 index = checkingIndex;
3680 if (selfPreviewCbParms->svcBufStatus[index] == ON_SERVICE) {
3681 selfPreviewCbParms->svcBufStatus[index] = ON_HAL;
3682 }
3683 else {
3684 ALOGV("DEBUG(%s): previewcb bufstatus abnormal [%d] status = %d", __FUNCTION__,
3685 index, selfPreviewCbParms->svcBufStatus[index]);
3686 }
3687 } while (0);
3688 }
Sungjoong Kang86646da2012-08-28 17:29:11 +09003689
Sungjoong Kangb55ed662012-08-31 21:31:34 -07003690 while (selfStreamParms->numSvcBufsInHal < selfStreamParms->numOwnSvcBuffers - 1) {
Sungjoong Kang86646da2012-08-28 17:29:11 +09003691 res = selfStreamParms->streamOps->dequeue_buffer(selfStreamParms->streamOps, &buf);
3692 if (res != NO_ERROR || buf == NULL) {
3693 ALOGV("DEBUG(%s): stream(%d) dequeue_buffer fail res(%d)",__FUNCTION__ , selfThread->m_index, res);
3694 break;
3695 }
3696 selfStreamParms->numSvcBufsInHal++;
3697 ALOGV("DEBUG(%s): stream(%d) got buf(%x) numInHal(%d) version(%d), numFds(%d), numInts(%d)", __FUNCTION__,
3698 selfThread->m_index, (uint32_t)(*buf), selfStreamParms->numSvcBufsInHal,
3699 ((native_handle_t*)(*buf))->version, ((native_handle_t*)(*buf))->numFds, ((native_handle_t*)(*buf))->numInts);
3700 const private_handle_t *priv_handle = reinterpret_cast<const private_handle_t *>(*buf);
3701
3702 bool found = false;
3703 int checkingIndex = 0;
3704 for (checkingIndex = 0; checkingIndex < selfStreamParms->numSvcBuffers ; checkingIndex++) {
3705 if (priv_handle->fd == selfStreamParms->svcBuffers[checkingIndex].fd.extFd[0] ) {
3706 found = true;
Sungjoong Kang9dd63e12012-07-24 00:25:51 +09003707 break;
3708 }
Sungjoong Kang86646da2012-08-28 17:29:11 +09003709 }
hyeonmyeong Choic0b6e172012-09-05 00:51:31 -07003710
Sungjoong Kang86646da2012-08-28 17:29:11 +09003711 ALOGV("DEBUG(%s): post_dequeue_buffer found(%d)", __FUNCTION__, found);
3712 if (!found) break;
3713 ALOGV("DEBUG(%s): preparing to qbuf [%d]", __FUNCTION__, checkingIndex);
3714 index = checkingIndex;
3715 if (index < selfStreamParms->numHwBuffers) {
3716 uint32_t plane_index = 0;
3717 ExynosBuffer* currentBuf = &(selfStreamParms->svcBuffers[index]);
3718 struct v4l2_buffer v4l2_buf;
3719 struct v4l2_plane planes[VIDEO_MAX_PLANES];
Sungjoong Kang13d8c7b2012-07-14 10:20:39 +09003720
Sungjoong Kang86646da2012-08-28 17:29:11 +09003721 v4l2_buf.m.planes = planes;
3722 v4l2_buf.type = currentNode->type;
3723 v4l2_buf.memory = currentNode->memory;
3724 v4l2_buf.index = index;
3725 v4l2_buf.length = currentNode->planes;
3726
3727 v4l2_buf.m.planes[0].m.fd = priv_handle->fd;
3728 v4l2_buf.m.planes[2].m.fd = priv_handle->fd1;
3729 v4l2_buf.m.planes[1].m.fd = priv_handle->fd2;
3730 for (plane_index=0 ; plane_index < v4l2_buf.length ; plane_index++) {
3731 v4l2_buf.m.planes[plane_index].length = currentBuf->size.extS[plane_index];
3732 ALOGV("DEBUG(%s): plane(%d): fd(%d) length(%d)",
3733 __FUNCTION__, plane_index, v4l2_buf.m.planes[plane_index].m.fd,
3734 v4l2_buf.m.planes[plane_index].length);
Sungjoong Kang9dd63e12012-07-24 00:25:51 +09003735 }
Sungjoong Kangfeb7df42012-08-28 23:35:43 +09003736#ifdef ENABLE_FRAME_SYNC
3737 /* add plane for metadata*/
3738 v4l2_buf.length += selfStreamParms->metaPlanes;
3739 v4l2_buf.m.planes[3].m.fd = selfStreamParms->metaBuffers[index].fd.extFd[0];
3740 v4l2_buf.m.planes[3].length = selfStreamParms->metaBuffers[index].size.extS[0];
3741#endif
Sungjoong Kang86646da2012-08-28 17:29:11 +09003742 if (exynos_v4l2_qbuf(currentNode->fd, &v4l2_buf) < 0) {
3743 ALOGE("ERR(%s): stream id(%d) exynos_v4l2_qbuf() fail",
3744 __FUNCTION__, selfThread->m_index);
3745 return;
Sungjoong Kang9dd63e12012-07-24 00:25:51 +09003746 }
Sungjoong Kang86646da2012-08-28 17:29:11 +09003747 selfStreamParms->svcBufStatus[index] = ON_DRIVER;
3748 ALOGV("DEBUG(%s): stream id(%d) type0 QBUF done index(%d)",
3749 __FUNCTION__, selfThread->m_index, index);
Sungjoong Kang13d8c7b2012-07-14 10:20:39 +09003750 }
3751 }
Sungjoong Kangbe494d12012-08-04 15:36:56 -07003752
Sungjoong Kang13d8c7b2012-07-14 10:20:39 +09003753 ALOGV("DEBUG(%s): stream(%d) processing SIGNAL_STREAM_DATA_COMING DONE",
3754 __FUNCTION__,selfThread->m_index);
Jiyoung Shinc15a6b02012-06-05 01:08:14 -07003755 }
Sungjoong Kang86646da2012-08-28 17:29:11 +09003756 return;
3757}
3758
3759void ExynosCameraHWInterface2::m_streamFunc1(SignalDrivenThread *self)
3760{
3761 uint32_t currentSignal = self->GetProcessingSignal();
3762 StreamThread * selfThread = ((StreamThread*)self);
3763 stream_parameters_t *selfStreamParms = &(selfThread->m_parameters);
3764 record_parameters_t *selfRecordParms = &(selfThread->m_recordParameters);
3765 node_info_t *currentNode = &(selfStreamParms->node);
3766
3767 if (currentSignal & SIGNAL_STREAM_CHANGE_PARAMETER) {
3768 ALOGV("DEBUG(%s): processing SIGNAL_STREAM_CHANGE_PARAMETER", __FUNCTION__);
3769
3770 m_resizeBuf.size.extS[0] = ALIGN(selfStreamParms->outputWidth, 16) * ALIGN(selfStreamParms->outputHeight, 16) * 2;
3771 m_resizeBuf.size.extS[1] = 0;
3772 m_resizeBuf.size.extS[2] = 0;
3773
3774 if (allocCameraMemory(selfStreamParms->ionClient, &m_resizeBuf, 1) == -1) {
3775 ALOGE("ERR(%s): Failed to allocate resize buf", __FUNCTION__);
3776 }
3777
3778 ALOGV("DEBUG(%s): processing SIGNAL_STREAM_CHANGE_PARAMETER DONE", __FUNCTION__);
3779 }
3780
hyeonmyeong Choi7d0efb52012-09-02 16:02:13 -07003781 if (currentSignal & SIGNAL_THREAD_RELEASE) {
3782 int i, index = -1, cnt_to_dq = 0;
3783 status_t res;
3784 ALOGV("DEBUG(%s): processing SIGNAL_THREAD_RELEASE", __FUNCTION__);
3785 ALOGD("(%s):(%d) SIGNAL_THREAD_RELEASE", __FUNCTION__, selfStreamParms->streamType);
3786
3787 if (selfThread->m_isBufferInit) {
3788 for ( i=0 ; i < selfStreamParms->numSvcBuffers; i++) {
3789 ALOGV("DEBUG(%s): checking buffer index[%d] - status(%d)",
3790 __FUNCTION__, i, selfStreamParms->svcBufStatus[i]);
3791 if (selfStreamParms->svcBufStatus[i] ==ON_DRIVER) cnt_to_dq++;
3792 }
3793
3794 ALOGV("DEBUG(%s): calling stream(%d) streamoff (fd:%d)", __FUNCTION__,
3795 selfThread->m_index, selfStreamParms->fd);
3796 if (cam_int_streamoff(&(selfStreamParms->node)) < 0 ){
3797 ALOGE("ERR(%s): stream off fail", __FUNCTION__);
3798 } else {
3799 m_camera_info.capture.status = false;
3800 }
3801 ALOGV("DEBUG(%s): calling stream(%d) streamoff done", __FUNCTION__, selfThread->m_index);
3802 ALOGV("DEBUG(%s): calling stream(%d) reqbuf 0 (fd:%d)", __FUNCTION__,
3803 selfThread->m_index, selfStreamParms->fd);
3804 currentNode->buffers = 0;
3805 cam_int_reqbufs(currentNode);
3806 ALOGV("DEBUG(%s): calling stream(%d) reqbuf 0 DONE(fd:%d)", __FUNCTION__,
3807 selfThread->m_index, selfStreamParms->fd);
3808 }
3809 if (selfThread->m_index == 1 && m_resizeBuf.size.s != 0) {
3810 freeCameraMemory(&m_resizeBuf, 1);
3811 }
3812 selfThread->m_isBufferInit = false;
3813 selfThread->m_index = 255;
3814
3815 selfThread->m_releasing = false;
3816
3817 ALOGV("DEBUG(%s): processing SIGNAL_THREAD_RELEASE DONE", __FUNCTION__);
3818
3819 return;
3820 }
3821
Sungjoong Kang86646da2012-08-28 17:29:11 +09003822 if (currentSignal & SIGNAL_STREAM_DATA_COMING) {
3823 buffer_handle_t * buf = NULL;
3824 status_t res;
3825 void *virtAddr[3];
3826 int i, j;
3827 int index;
3828 nsecs_t timestamp;
3829
3830 ALOGV("DEBUG(%s): stream(%d) processing SIGNAL_STREAM_DATA_COMING",
3831 __FUNCTION__,selfThread->m_index);
3832
3833 m_streamBufferInit(self);
3834
3835 do {
3836 ExynosRect jpegRect;
3837 bool found = false;
3838 bool ret = false;
3839 int pictureW, pictureH, pictureFramesize = 0;
3840 int pictureFormat;
3841 int cropX, cropY, cropW, cropH = 0;
3842 ExynosBuffer resizeBufInfo;
3843 ExynosRect m_orgPictureRect;
Sungjoong Kangfeb7df42012-08-28 23:35:43 +09003844 camera2_stream *frame;
Sungjoong Kang86646da2012-08-28 17:29:11 +09003845
hyeonmyeong Choi7d0efb52012-09-02 16:02:13 -07003846 ALOGV("DEBUG(%s): stream(%d) type(%d) DQBUF START ",__FUNCTION__,
Sungjoong Kang86646da2012-08-28 17:29:11 +09003847 selfThread->m_index, selfStreamParms->streamType);
3848 index = cam_int_dqbuf(&(selfStreamParms->node));
hyeonmyeong Choi7d0efb52012-09-02 16:02:13 -07003849 ALOGV("DEBUG(%s): stream(%d) type(%d) DQBUF done index(%d)",__FUNCTION__,
Sungjoong Kang86646da2012-08-28 17:29:11 +09003850 selfThread->m_index, selfStreamParms->streamType, index);
3851
Sungjoong Kangfeb7df42012-08-28 23:35:43 +09003852#ifdef ENABLE_FRAME_SYNC
3853 frame = (struct camera2_stream *)(selfStreamParms->svcBuffers[index].virt.extP[selfStreamParms->nodePlanes -1]);
3854 ALOGD("frame count(SCC) : %d", frame->fcount);
3855#endif
Sungjoong Kang86646da2012-08-28 17:29:11 +09003856 for (int i = 0; i < selfStreamParms->numSvcBuffers ; i++) {
3857 if (selfStreamParms->svcBufStatus[selfStreamParms->svcBufIndex] == ON_HAL) {
3858 found = true;
3859 break;
3860 }
3861 selfStreamParms->svcBufIndex++;
3862 if (selfStreamParms->svcBufIndex >= selfStreamParms->numSvcBuffers)
3863 selfStreamParms->svcBufIndex = 0;
3864 }
3865 if (!found) {
3866 ALOGE("ERR(%s): NO free SVC buffer for JPEG", __FUNCTION__);
3867 break;
3868 }
3869
3870 m_orgPictureRect.w = selfStreamParms->outputWidth;
3871 m_orgPictureRect.h = selfStreamParms->outputHeight;
3872
3873 ExynosBuffer* m_pictureBuf = &(m_camera_info.capture.buffer[index]);
3874
Sungjoong Kange4657e32012-08-28 15:02:19 -07003875 m_getRatioSize(selfStreamParms->nodeWidth, selfStreamParms->nodeHeight,
3876 m_orgPictureRect.w, m_orgPictureRect.h,
3877 &cropX, &cropY,
3878 &pictureW, &pictureH,
3879 0);
Sungjoong Kang86646da2012-08-28 17:29:11 +09003880 pictureFormat = V4L2_PIX_FMT_YUYV;
3881 pictureFramesize = FRAME_SIZE(V4L2_PIX_2_HAL_PIXEL_FORMAT(pictureFormat), pictureW, pictureH);
3882
3883 if (m_exynosPictureCSC) {
hyeonmyeong Choi308291d2012-08-29 13:55:01 -07003884 float zoom_w = 0, zoom_h = 0;
3885 if (m_orgPictureRect.w >= m_orgPictureRect.h) {
3886 zoom_w = pictureW / m_zoomRatio;
3887 zoom_h = zoom_w * m_orgPictureRect.h / m_orgPictureRect.w;
3888 } else {
3889 zoom_h = pictureH / m_zoomRatio;
3890 zoom_w = zoom_h * m_orgPictureRect.w / m_orgPictureRect.h;
3891 }
3892 cropX = (pictureW - zoom_w) / 2;
3893 cropY = (pictureH - zoom_h) / 2;
3894 cropW = zoom_w;
3895 cropH = zoom_h;
Sungjoong Kang86646da2012-08-28 17:29:11 +09003896
3897 ALOGV("DEBUG(%s):cropX = %d, cropY = %d, cropW = %d, cropH = %d",
3898 __FUNCTION__, cropX, cropY, cropW, cropH);
3899
3900 csc_set_src_format(m_exynosPictureCSC,
3901 ALIGN(pictureW, 16), ALIGN(pictureH, 16),
3902 cropX, cropY, cropW, cropH,
3903 V4L2_PIX_2_HAL_PIXEL_FORMAT(pictureFormat),
3904 0);
3905
3906 csc_set_dst_format(m_exynosPictureCSC,
3907 m_orgPictureRect.w, m_orgPictureRect.h,
3908 0, 0, m_orgPictureRect.w, m_orgPictureRect.h,
3909 V4L2_PIX_2_HAL_PIXEL_FORMAT(V4L2_PIX_FMT_NV16),
3910 0);
3911 csc_set_src_buffer(m_exynosPictureCSC,
3912 (void **)&m_pictureBuf->fd.fd);
3913
3914 csc_set_dst_buffer(m_exynosPictureCSC,
3915 (void **)&m_resizeBuf.fd.fd);
3916 for (int i = 0 ; i < 3 ; i++)
3917 ALOGV("DEBUG(%s): m_resizeBuf.virt.extP[%d]=%d m_resizeBuf.size.extS[%d]=%d",
3918 __FUNCTION__, i, m_resizeBuf.fd.extFd[i], i, m_resizeBuf.size.extS[i]);
3919
3920 if (csc_convert(m_exynosPictureCSC) != 0)
3921 ALOGE("ERR(%s): csc_convert() fail", __FUNCTION__);
3922
3923
3924 }
3925 else {
3926 ALOGE("ERR(%s): m_exynosPictureCSC == NULL", __FUNCTION__);
3927 }
3928
3929 resizeBufInfo = m_resizeBuf;
3930
3931 m_getAlignedYUVSize(V4L2_PIX_FMT_NV16, m_orgPictureRect.w, m_orgPictureRect.h, &m_resizeBuf);
3932
3933 for (int i = 1; i < 3; i++) {
3934 if (m_resizeBuf.size.extS[i] != 0)
3935 m_resizeBuf.fd.extFd[i] = m_resizeBuf.fd.extFd[i-1] + m_resizeBuf.size.extS[i-1];
3936
3937 ALOGV("(%s): m_resizeBuf.size.extS[%d] = %d", __FUNCTION__, i, m_resizeBuf.size.extS[i]);
3938 }
3939
3940 jpegRect.w = m_orgPictureRect.w;
3941 jpegRect.h = m_orgPictureRect.h;
3942 jpegRect.colorFormat = V4L2_PIX_FMT_NV16;
3943
3944 if (yuv2Jpeg(&m_resizeBuf, &selfStreamParms->svcBuffers[selfStreamParms->svcBufIndex], &jpegRect) == false)
3945 ALOGE("ERR(%s):yuv2Jpeg() fail", __FUNCTION__);
3946 cam_int_qbuf(&(selfStreamParms->node), index);
3947 ALOGV("DEBUG(%s): stream(%d) type(%d) QBUF DONE ",__FUNCTION__,
3948 selfThread->m_index, selfStreamParms->streamType);
3949
3950 m_resizeBuf = resizeBufInfo;
3951
3952 res = selfStreamParms->streamOps->enqueue_buffer(selfStreamParms->streamOps, systemTime(), &(selfStreamParms->svcBufHandle[selfStreamParms->svcBufIndex]));
3953
3954 ALOGV("DEBUG(%s): stream(%d) enqueue_buffer index(%d) to svc done res(%d)",
3955 __FUNCTION__, selfThread->m_index, selfStreamParms->svcBufIndex, res);
3956 if (res == 0) {
3957 selfStreamParms->svcBufStatus[selfStreamParms->svcBufIndex] = ON_SERVICE;
3958 selfStreamParms->numSvcBufsInHal--;
3959 }
3960 else {
3961 selfStreamParms->svcBufStatus[selfStreamParms->svcBufIndex] = ON_HAL;
3962 }
3963 }
3964 while (0);
3965
3966 while (selfStreamParms->numSvcBufsInHal < selfStreamParms->numOwnSvcBuffers) {
3967 res = selfStreamParms->streamOps->dequeue_buffer(selfStreamParms->streamOps, &buf);
3968 if (res != NO_ERROR || buf == NULL) {
3969 ALOGV("DEBUG(%s): stream(%d) dequeue_buffer fail res(%d)",__FUNCTION__ , selfThread->m_index, res);
3970 break;
3971 }
3972
3973 ALOGV("DEBUG(%s): stream(%d) got buf(%x) numInHal(%d) version(%d), numFds(%d), numInts(%d)", __FUNCTION__,
3974 selfThread->m_index, (uint32_t)(*buf), selfStreamParms->numSvcBufsInHal,
3975 ((native_handle_t*)(*buf))->version, ((native_handle_t*)(*buf))->numFds, ((native_handle_t*)(*buf))->numInts);
3976
3977 const private_handle_t *priv_handle = reinterpret_cast<const private_handle_t *>(*buf);
3978
3979 bool found = false;
3980 int checkingIndex = 0;
3981 for (checkingIndex = 0; checkingIndex < selfStreamParms->numSvcBuffers ; checkingIndex++) {
3982 if (priv_handle->fd == selfStreamParms->svcBuffers[checkingIndex].fd.extFd[0] ) {
3983 found = true;
3984 break;
3985 }
3986 }
3987 if (!found) break;
3988 selfStreamParms->svcBufStatus[checkingIndex] = ON_HAL;
3989 selfStreamParms->numSvcBufsInHal++;
3990 }
3991
3992 ALOGV("DEBUG(%s): stream(%d) processing SIGNAL_STREAM_DATA_COMING DONE",
3993 __FUNCTION__,selfThread->m_index);
3994 }
3995
Sungjoong Kang86646da2012-08-28 17:29:11 +09003996 return;
3997}
3998
3999
4000void ExynosCameraHWInterface2::m_streamThreadFunc(SignalDrivenThread * self)
4001{
4002 uint32_t currentSignal = self->GetProcessingSignal();
4003 StreamThread * selfThread = ((StreamThread*)self);
4004 stream_parameters_t *selfStreamParms = &(selfThread->m_parameters);
4005 record_parameters_t *selfRecordParms = &(selfThread->m_recordParameters);
4006 node_info_t *currentNode = &(selfStreamParms->node);
4007
4008 ALOGV("DEBUG(%s): m_streamThreadFunc[%d] (%x)", __FUNCTION__, selfThread->m_index, currentSignal);
4009
4010 if (currentSignal & SIGNAL_STREAM_CHANGE_PARAMETER) {
4011 ALOGV("DEBUG(%s): processing SIGNAL_STREAM_CHANGE_PARAMETER", __FUNCTION__);
4012
4013 //Do something in Parent thread handler
4014 selfThread->applyChange();
4015
4016 ALOGV("DEBUG(%s): processing SIGNAL_STREAM_CHANGE_PARAMETER DONE", __FUNCTION__);
4017 }
4018
4019 // Do something in Child thread handler
4020 // Should change function to class that inherited StreamThread class to support dynamic stream allocation
4021 if (selfStreamParms->streamType == STREAM_TYPE_DIRECT)
4022 {
4023 m_streamFunc0(self);
4024 }
4025 else if (selfStreamParms->streamType == STREAM_TYPE_INDIRECT)
4026 {
4027 m_streamFunc1(self);
4028 }
4029
4030 if (currentSignal & SIGNAL_THREAD_RELEASE) {
4031 ALOGV("DEBUG(%s): processing SIGNAL_THREAD_RELEASE", __FUNCTION__);
4032 ALOGD("(%s):(%d) SIGNAL_THREAD_RELEASE", __FUNCTION__, selfStreamParms->streamType);
4033
4034 //Do something in Parent thread handler
4035
4036 ALOGV("DEBUG(%s): processing SIGNAL_THREAD_RELEASE DONE", __FUNCTION__);
4037
4038 return;
4039 }
4040
Jiyoung Shinc15a6b02012-06-05 01:08:14 -07004041 return;
4042}
4043
Sungjoong Kang2d5e6ec2012-08-30 15:14:17 +09004044bool ExynosCameraHWInterface2::m_checkThumbnailSize(int w, int h)
4045{
4046 int sizeOfSupportList;
4047
4048 //REAR Camera
4049 if(this->getCameraId() == 0) {
4050 sizeOfSupportList = sizeof(SUPPORT_THUMBNAIL_REAR_SIZE) / (sizeof(int)*2);
4051
4052 for(int i = 0; i < sizeOfSupportList; i++) {
4053 if((SUPPORT_THUMBNAIL_REAR_SIZE[i][0] == w) &&(SUPPORT_THUMBNAIL_REAR_SIZE[i][1] == h))
4054 return true;
4055 }
4056
4057 }
4058 else {
4059 sizeOfSupportList = sizeof(SUPPORT_THUMBNAIL_FRONT_SIZE) / (sizeof(int)*2);
4060
4061 for(int i = 0; i < sizeOfSupportList; i++) {
4062 if((SUPPORT_THUMBNAIL_FRONT_SIZE[i][0] == w) &&(SUPPORT_THUMBNAIL_FRONT_SIZE[i][1] == h))
4063 return true;
4064 }
4065 }
4066
4067 return false;
4068}
Sungjoong Kang13d8c7b2012-07-14 10:20:39 +09004069bool ExynosCameraHWInterface2::yuv2Jpeg(ExynosBuffer *yuvBuf,
4070 ExynosBuffer *jpegBuf,
4071 ExynosRect *rect)
Jiyoung Shinc15a6b02012-06-05 01:08:14 -07004072{
Sungjoong Kang13d8c7b2012-07-14 10:20:39 +09004073 unsigned char *addr;
4074
4075 ExynosJpegEncoderForCamera jpegEnc;
4076 bool ret = false;
4077 int res = 0;
4078
4079 unsigned int *yuvSize = yuvBuf->size.extS;
4080
4081 if (jpegEnc.create()) {
Sungjoong Kang9dd63e12012-07-24 00:25:51 +09004082 ALOGE("ERR(%s):jpegEnc.create() fail", __FUNCTION__);
Sungjoong Kang13d8c7b2012-07-14 10:20:39 +09004083 goto jpeg_encode_done;
4084 }
4085
4086 if (jpegEnc.setQuality(100)) {
Sungjoong Kang9dd63e12012-07-24 00:25:51 +09004087 ALOGE("ERR(%s):jpegEnc.setQuality() fail", __FUNCTION__);
Sungjoong Kang13d8c7b2012-07-14 10:20:39 +09004088 goto jpeg_encode_done;
4089 }
4090
4091 if (jpegEnc.setSize(rect->w, rect->h)) {
Sungjoong Kang9dd63e12012-07-24 00:25:51 +09004092 ALOGE("ERR(%s):jpegEnc.setSize() fail", __FUNCTION__);
Sungjoong Kang13d8c7b2012-07-14 10:20:39 +09004093 goto jpeg_encode_done;
4094 }
4095 ALOGV("%s : width = %d , height = %d\n", __FUNCTION__, rect->w, rect->h);
4096
4097 if (jpegEnc.setColorFormat(rect->colorFormat)) {
Sungjoong Kang9dd63e12012-07-24 00:25:51 +09004098 ALOGE("ERR(%s):jpegEnc.setColorFormat() fail", __FUNCTION__);
Sungjoong Kang13d8c7b2012-07-14 10:20:39 +09004099 goto jpeg_encode_done;
4100 }
Sungjoong Kang13d8c7b2012-07-14 10:20:39 +09004101
4102 if (jpegEnc.setJpegFormat(V4L2_PIX_FMT_JPEG_422)) {
Sungjoong Kang9dd63e12012-07-24 00:25:51 +09004103 ALOGE("ERR(%s):jpegEnc.setJpegFormat() fail", __FUNCTION__);
Sungjoong Kang13d8c7b2012-07-14 10:20:39 +09004104 goto jpeg_encode_done;
4105 }
Sungjoong Kang13d8c7b2012-07-14 10:20:39 +09004106
Sungjoong Kang2d5e6ec2012-08-30 15:14:17 +09004107 if((m_jpegMetadata.ctl.jpeg.thumbnailSize[0] != 0) && (m_jpegMetadata.ctl.jpeg.thumbnailSize[1] != 0)) {
4108 mExifInfo.enableThumb = true;
4109 if(!m_checkThumbnailSize(m_jpegMetadata.ctl.jpeg.thumbnailSize[0], m_jpegMetadata.ctl.jpeg.thumbnailSize[1])) {
4110 //default value
4111 m_thumbNailW = SUPPORT_THUMBNAIL_REAR_SIZE[0][0];
4112 m_thumbNailH = SUPPORT_THUMBNAIL_REAR_SIZE[0][1];
4113 } else {
4114 m_thumbNailW = m_jpegMetadata.ctl.jpeg.thumbnailSize[0];
4115 m_thumbNailH = m_jpegMetadata.ctl.jpeg.thumbnailSize[1];
4116 }
Sungjoong Kang13d8c7b2012-07-14 10:20:39 +09004117
Sungjoong Kang2d5e6ec2012-08-30 15:14:17 +09004118 ALOGV("(%s) m_thumbNailW = %d, m_thumbNailH = %d", __FUNCTION__, m_thumbNailW, m_thumbNailH);
4119
4120 } else {
4121 mExifInfo.enableThumb = false;
4122 }
4123
4124 if (jpegEnc.setThumbnailSize(m_thumbNailW, m_thumbNailH)) {
4125 ALOGE("ERR(%s):jpegEnc.setThumbnailSize(%d, %d) fail", __FUNCTION__, m_thumbNailH, m_thumbNailH);
Sungjoong Kangeed7ed12012-08-23 16:35:08 -07004126 goto jpeg_encode_done;
4127 }
4128
Sungjoong Kang2d5e6ec2012-08-30 15:14:17 +09004129 ALOGV("(%s):jpegEnc.setThumbnailSize(%d, %d) ", __FUNCTION__, m_thumbNailW, m_thumbNailW);
Sungjoong Kangeed7ed12012-08-23 16:35:08 -07004130 if (jpegEnc.setThumbnailQuality(50)) {
4131 ALOGE("ERR(%s):jpegEnc.setThumbnailQuality fail", __FUNCTION__);
4132 goto jpeg_encode_done;
4133 }
4134
4135 m_setExifChangedAttribute(&mExifInfo, rect, &m_jpegMetadata);
Sungjoong Kang9dd63e12012-07-24 00:25:51 +09004136 ALOGV("DEBUG(%s):calling jpegEnc.setInBuf() yuvSize(%d)", __FUNCTION__, *yuvSize);
Sungjoong Kangeed7ed12012-08-23 16:35:08 -07004137 if (jpegEnc.setInBuf((int *)&(yuvBuf->fd.fd), &(yuvBuf->virt.p), (int *)yuvSize)) {
Sungjoong Kang9dd63e12012-07-24 00:25:51 +09004138 ALOGE("ERR(%s):jpegEnc.setInBuf() fail", __FUNCTION__);
Sungjoong Kang13d8c7b2012-07-14 10:20:39 +09004139 goto jpeg_encode_done;
4140 }
Sungjoong Kangeed7ed12012-08-23 16:35:08 -07004141 if (jpegEnc.setOutBuf(jpegBuf->fd.fd, jpegBuf->virt.p, jpegBuf->size.extS[0] + jpegBuf->size.extS[1] + jpegBuf->size.extS[2])) {
Sungjoong Kang9dd63e12012-07-24 00:25:51 +09004142 ALOGE("ERR(%s):jpegEnc.setOutBuf() fail", __FUNCTION__);
Sungjoong Kang13d8c7b2012-07-14 10:20:39 +09004143 goto jpeg_encode_done;
4144 }
Sungjoong Kang13d8c7b2012-07-14 10:20:39 +09004145
4146 if (jpegEnc.updateConfig()) {
Sungjoong Kang9dd63e12012-07-24 00:25:51 +09004147 ALOGE("ERR(%s):jpegEnc.updateConfig() fail", __FUNCTION__);
Sungjoong Kang13d8c7b2012-07-14 10:20:39 +09004148 goto jpeg_encode_done;
4149 }
4150
Sungjoong Kangeed7ed12012-08-23 16:35:08 -07004151 if (res = jpegEnc.encode((int *)&jpegBuf->size.s, &mExifInfo)) {
Sungjoong Kang9dd63e12012-07-24 00:25:51 +09004152 ALOGE("ERR(%s):jpegEnc.encode() fail ret(%d)", __FUNCTION__, res);
Sungjoong Kang13d8c7b2012-07-14 10:20:39 +09004153 goto jpeg_encode_done;
4154 }
4155
4156 ret = true;
4157
4158jpeg_encode_done:
4159
4160 if (jpegEnc.flagCreate() == true)
4161 jpegEnc.destroy();
4162
4163 return ret;
Jiyoung Shinc15a6b02012-06-05 01:08:14 -07004164}
4165
Sungjoong Kang8e2c2fd2012-08-27 00:02:22 -07004166void ExynosCameraHWInterface2::OnAfTriggerStart(int id)
4167{
4168 m_afPendingTriggerId = id;
hyeonmyeong Choi7d0efb52012-09-02 16:02:13 -07004169 m_afModeWaitingCnt = 6;
Sungjoong Kang8e2c2fd2012-08-27 00:02:22 -07004170}
Sungjoong Kang13d8c7b2012-07-14 10:20:39 +09004171
Sungjoong Kang0f26b202012-08-17 15:43:12 -07004172void ExynosCameraHWInterface2::OnAfTrigger(int id)
4173{
Sungjoong Kang8e2c2fd2012-08-27 00:02:22 -07004174 m_afTriggerId = id;
Younghwan Joo6f19b6c2012-08-30 13:56:53 -07004175
Sungjoong Kang0f26b202012-08-17 15:43:12 -07004176 switch (m_afMode) {
4177 case AA_AFMODE_AUTO:
4178 case AA_AFMODE_MACRO:
Sungjoong Kang8e2c2fd2012-08-27 00:02:22 -07004179 case AA_AFMODE_OFF:
Younghwan Joocaea49e2012-09-07 13:34:20 -07004180 ALOGE("[AF] OnAfTrigger - AUTO,MACRO,OFF (Mode %d) ", m_afMode);
4181 // If flash is enable, Flash operation is executed before triggering AF
4182 if ((m_ctlInfo.flash.i_flashMode >= AA_AEMODE_ON_AUTO_FLASH)
4183 && (m_ctlInfo.flash.m_afFlashEnableFlg == false)
4184 && (m_cameraId == 0)) {
4185 ALOGE("[AF Flash] AF Flash start with Mode (%d)", m_afMode);
4186 m_ctlInfo.flash.m_afFlashEnableFlg = true;
4187 m_ctlInfo.flash.m_flashTimeOut = 3;
4188 m_ctlInfo.flash.m_afFlashCnt = IS_FLASH_AF_ON;
Younghwan Joocaea49e2012-09-07 13:34:20 -07004189 m_ctlInfo.flash.m_flashDecisionResult = false;
4190 }
Sungjoong Kang0f26b202012-08-17 15:43:12 -07004191 OnAfTriggerAutoMacro(id);
4192 break;
4193 case AA_AFMODE_CONTINUOUS_VIDEO:
Younghwan Joocaea49e2012-09-07 13:34:20 -07004194 ALOGE("[AF] OnAfTrigger - AA_AFMODE_CONTINUOUS_VIDEO (Mode %d) ", m_afMode);
Sungjoong Kang0f26b202012-08-17 15:43:12 -07004195 OnAfTriggerCAFVideo(id);
4196 break;
4197 case AA_AFMODE_CONTINUOUS_PICTURE:
Younghwan Joocaea49e2012-09-07 13:34:20 -07004198 ALOGE("[AF] OnAfTrigger - AA_AFMODE_CONTINUOUS_PICTURE (Mode %d) ", m_afMode);
Sungjoong Kang0f26b202012-08-17 15:43:12 -07004199 OnAfTriggerCAFPicture(id);
4200 break;
Sungjoong Kang8e2c2fd2012-08-27 00:02:22 -07004201
Sungjoong Kang0f26b202012-08-17 15:43:12 -07004202 default:
4203 break;
4204 }
4205}
4206
4207void ExynosCameraHWInterface2::OnAfTriggerAutoMacro(int id)
4208{
4209 int nextState = NO_TRANSITION;
Sungjoong Kang0f26b202012-08-17 15:43:12 -07004210
4211 switch (m_afState) {
4212 case HAL_AFSTATE_INACTIVE:
4213 nextState = HAL_AFSTATE_NEEDS_COMMAND;
4214 m_IsAfTriggerRequired = true;
4215 break;
4216 case HAL_AFSTATE_NEEDS_COMMAND:
4217 nextState = NO_TRANSITION;
4218 break;
4219 case HAL_AFSTATE_STARTED:
4220 nextState = NO_TRANSITION;
4221 break;
4222 case HAL_AFSTATE_SCANNING:
4223 nextState = NO_TRANSITION;
4224 break;
4225 case HAL_AFSTATE_LOCKED:
4226 nextState = HAL_AFSTATE_NEEDS_COMMAND;
4227 m_IsAfTriggerRequired = true;
4228 break;
4229 case HAL_AFSTATE_FAILED:
4230 nextState = HAL_AFSTATE_NEEDS_COMMAND;
4231 m_IsAfTriggerRequired = true;
4232 break;
4233 default:
4234 break;
4235 }
4236 ALOGV("(%s): State (%d) -> (%d)", __FUNCTION__, m_afState, nextState);
4237 if (nextState != NO_TRANSITION)
4238 m_afState = nextState;
4239}
4240
4241void ExynosCameraHWInterface2::OnAfTriggerCAFPicture(int id)
4242{
4243 int nextState = NO_TRANSITION;
Sungjoong Kang0f26b202012-08-17 15:43:12 -07004244
4245 switch (m_afState) {
4246 case HAL_AFSTATE_INACTIVE:
4247 nextState = HAL_AFSTATE_FAILED;
4248 SetAfStateForService(ANDROID_CONTROL_AF_STATE_NOT_FOCUSED_LOCKED);
4249 break;
4250 case HAL_AFSTATE_NEEDS_COMMAND:
4251 // not used
4252 break;
4253 case HAL_AFSTATE_STARTED:
4254 nextState = HAL_AFSTATE_NEEDS_DETERMINATION;
Sungjoong Kang36c106c2012-08-23 17:38:20 -07004255 m_AfHwStateFailed = false;
Younghwan Joocaea49e2012-09-07 13:34:20 -07004256 // If flash is enable, Flash operation is executed before triggering AF
4257 if ((m_ctlInfo.flash.i_flashMode >= AA_AEMODE_ON_AUTO_FLASH)
4258 && (m_ctlInfo.flash.m_afFlashEnableFlg == false)
4259 && (m_cameraId == 0)) {
4260 ALOGE("[AF Flash] AF Flash start with Mode (%d) state (%d) id (%d)", m_afMode, m_afState, id);
4261 m_ctlInfo.flash.m_afFlashEnableFlg = true;
4262 m_ctlInfo.flash.m_flashTimeOut = 3;
4263 m_ctlInfo.flash.m_afFlashCnt = IS_FLASH_AF_ON;
Younghwan Joocaea49e2012-09-07 13:34:20 -07004264 m_ctlInfo.flash.m_flashDecisionResult = false;
4265 }
Sungjoong Kang0f26b202012-08-17 15:43:12 -07004266 break;
4267 case HAL_AFSTATE_SCANNING:
4268 nextState = HAL_AFSTATE_NEEDS_DETERMINATION;
Sungjoong Kang36c106c2012-08-23 17:38:20 -07004269 m_AfHwStateFailed = false;
Younghwan Joocaea49e2012-09-07 13:34:20 -07004270 // If flash is enable, Flash operation is executed before triggering AF
4271 if ((m_ctlInfo.flash.i_flashMode >= AA_AEMODE_ON_AUTO_FLASH)
4272 && (m_ctlInfo.flash.m_afFlashEnableFlg == false)
4273 && (m_cameraId == 0)) {
4274 ALOGE("[AF Flash] AF Flash start with Mode (%d) state (%d) id (%d)", m_afMode, m_afState, id);
4275 m_ctlInfo.flash.m_afFlashEnableFlg = true;
4276 m_ctlInfo.flash.m_flashTimeOut = 3;
4277 m_ctlInfo.flash.m_afFlashCnt = IS_FLASH_AF_ON;
Younghwan Joocaea49e2012-09-07 13:34:20 -07004278 m_ctlInfo.flash.m_flashDecisionResult = false;
4279 }
Sungjoong Kang0f26b202012-08-17 15:43:12 -07004280 break;
4281 case HAL_AFSTATE_NEEDS_DETERMINATION:
4282 nextState = NO_TRANSITION;
4283 break;
4284 case HAL_AFSTATE_PASSIVE_FOCUSED:
4285 m_IsAfLockRequired = true;
Sungjoong Kang36c106c2012-08-23 17:38:20 -07004286 if (m_AfHwStateFailed) {
Younghwan Joocaea49e2012-09-07 13:34:20 -07004287 ALOGE("(%s): [CAF] LAST : fail", __FUNCTION__);
Sungjoong Kang36c106c2012-08-23 17:38:20 -07004288 SetAfStateForService(ANDROID_CONTROL_AF_STATE_NOT_FOCUSED_LOCKED);
4289 nextState = HAL_AFSTATE_FAILED;
4290 }
4291 else {
Younghwan Joocaea49e2012-09-07 13:34:20 -07004292 ALOGV("(%s): [CAF] LAST : success", __FUNCTION__);
Sungjoong Kang36c106c2012-08-23 17:38:20 -07004293 SetAfStateForService(ANDROID_CONTROL_AF_STATE_FOCUSED_LOCKED);
4294 nextState = HAL_AFSTATE_LOCKED;
4295 }
4296 m_AfHwStateFailed = false;
Sungjoong Kang0f26b202012-08-17 15:43:12 -07004297 break;
4298 case HAL_AFSTATE_LOCKED:
4299 nextState = NO_TRANSITION;
4300 break;
4301 case HAL_AFSTATE_FAILED:
4302 nextState = NO_TRANSITION;
4303 break;
4304 default:
4305 break;
4306 }
4307 ALOGV("(%s): State (%d) -> (%d)", __FUNCTION__, m_afState, nextState);
4308 if (nextState != NO_TRANSITION)
4309 m_afState = nextState;
4310}
4311
4312
4313void ExynosCameraHWInterface2::OnAfTriggerCAFVideo(int id)
4314{
4315 int nextState = NO_TRANSITION;
Sungjoong Kang0f26b202012-08-17 15:43:12 -07004316
4317 switch (m_afState) {
4318 case HAL_AFSTATE_INACTIVE:
4319 nextState = HAL_AFSTATE_FAILED;
4320 SetAfStateForService(ANDROID_CONTROL_AF_STATE_NOT_FOCUSED_LOCKED);
4321 break;
4322 case HAL_AFSTATE_NEEDS_COMMAND:
4323 // not used
4324 break;
4325 case HAL_AFSTATE_STARTED:
4326 m_IsAfLockRequired = true;
4327 nextState = HAL_AFSTATE_FAILED;
4328 SetAfStateForService(ANDROID_CONTROL_AF_STATE_NOT_FOCUSED_LOCKED);
4329 break;
4330 case HAL_AFSTATE_SCANNING:
4331 m_IsAfLockRequired = true;
4332 nextState = HAL_AFSTATE_FAILED;
4333 SetAfStateForService(ANDROID_CONTROL_AF_STATE_NOT_FOCUSED_LOCKED);
4334 break;
4335 case HAL_AFSTATE_NEEDS_DETERMINATION:
4336 // not used
4337 break;
4338 case HAL_AFSTATE_PASSIVE_FOCUSED:
4339 m_IsAfLockRequired = true;
4340 SetAfStateForService(ANDROID_CONTROL_AF_STATE_FOCUSED_LOCKED);
4341 nextState = HAL_AFSTATE_LOCKED;
4342 break;
4343 case HAL_AFSTATE_LOCKED:
4344 nextState = NO_TRANSITION;
4345 break;
4346 case HAL_AFSTATE_FAILED:
4347 nextState = NO_TRANSITION;
4348 break;
4349 default:
4350 break;
4351 }
4352 ALOGV("(%s): State (%d) -> (%d)", __FUNCTION__, m_afState, nextState);
4353 if (nextState != NO_TRANSITION)
4354 m_afState = nextState;
4355}
4356
4357void ExynosCameraHWInterface2::OnAfNotification(enum aa_afstate noti)
4358{
4359 switch (m_afMode) {
4360 case AA_AFMODE_AUTO:
4361 case AA_AFMODE_MACRO:
4362 OnAfNotificationAutoMacro(noti);
4363 break;
4364 case AA_AFMODE_CONTINUOUS_VIDEO:
4365 OnAfNotificationCAFVideo(noti);
4366 break;
4367 case AA_AFMODE_CONTINUOUS_PICTURE:
4368 OnAfNotificationCAFPicture(noti);
4369 break;
4370 case AA_AFMODE_OFF:
4371 default:
4372 break;
4373 }
4374}
4375
4376void ExynosCameraHWInterface2::OnAfNotificationAutoMacro(enum aa_afstate noti)
4377{
4378 int nextState = NO_TRANSITION;
4379 bool bWrongTransition = false;
4380
4381 if (m_afState == HAL_AFSTATE_INACTIVE || m_afState == HAL_AFSTATE_NEEDS_COMMAND) {
4382 switch (noti) {
4383 case AA_AFSTATE_INACTIVE:
4384 case AA_AFSTATE_ACTIVE_SCAN:
4385 case AA_AFSTATE_AF_ACQUIRED_FOCUS:
4386 case AA_AFSTATE_AF_FAILED_FOCUS:
4387 default:
4388 nextState = NO_TRANSITION;
4389 break;
4390 }
4391 }
4392 else if (m_afState == HAL_AFSTATE_STARTED) {
4393 switch (noti) {
4394 case AA_AFSTATE_INACTIVE:
4395 nextState = NO_TRANSITION;
4396 break;
4397 case AA_AFSTATE_ACTIVE_SCAN:
4398 nextState = HAL_AFSTATE_SCANNING;
4399 SetAfStateForService(ANDROID_CONTROL_AF_STATE_ACTIVE_SCAN);
4400 break;
4401 case AA_AFSTATE_AF_ACQUIRED_FOCUS:
4402 nextState = NO_TRANSITION;
4403 break;
4404 case AA_AFSTATE_AF_FAILED_FOCUS:
4405 nextState = NO_TRANSITION;
4406 break;
4407 default:
4408 bWrongTransition = true;
4409 break;
4410 }
4411 }
4412 else if (m_afState == HAL_AFSTATE_SCANNING) {
4413 switch (noti) {
4414 case AA_AFSTATE_INACTIVE:
4415 bWrongTransition = true;
4416 break;
4417 case AA_AFSTATE_ACTIVE_SCAN:
4418 nextState = NO_TRANSITION;
4419 break;
4420 case AA_AFSTATE_AF_ACQUIRED_FOCUS:
Younghwan Joo9a710a42012-09-05 17:52:08 -07004421 // If Flash mode is enable, after AF execute pre-capture metering
4422 if (m_ctlInfo.flash.m_afFlashEnableFlg) {
4423 if (m_ctlInfo.flash.m_afFlashCnt == IS_FLASH_AF_ON_DONE) {
4424 m_ctlInfo.flash.m_afFlashCnt = IS_FLASH_AF_AUTO_AE_AWB_LOCK;
4425 } else if (m_ctlInfo.flash.m_afFlashCnt == IS_FLASH_AF_AUTO_END) {
4426 nextState = HAL_AFSTATE_LOCKED;
4427 SetAfStateForService(ANDROID_CONTROL_AF_STATE_FOCUSED_LOCKED);
4428 } else {
4429 nextState = NO_TRANSITION;
4430 }
4431 } else {
4432 nextState = HAL_AFSTATE_LOCKED;
4433 SetAfStateForService(ANDROID_CONTROL_AF_STATE_FOCUSED_LOCKED);
4434 }
Sungjoong Kang0f26b202012-08-17 15:43:12 -07004435 break;
4436 case AA_AFSTATE_AF_FAILED_FOCUS:
Younghwan Joo9a710a42012-09-05 17:52:08 -07004437 // If Flash mode is enable, after AF execute pre-capture metering
4438 if (m_ctlInfo.flash.m_afFlashEnableFlg) {
4439 if (m_ctlInfo.flash.m_afFlashCnt == IS_FLASH_AF_ON_DONE) {
4440 m_ctlInfo.flash.m_afFlashCnt = IS_FLASH_AF_AUTO_AE_AWB_LOCK;
4441 } else if (m_ctlInfo.flash.m_afFlashCnt == IS_FLASH_AF_AUTO_END) {
4442 nextState = HAL_AFSTATE_FAILED;
4443 SetAfStateForService(ANDROID_CONTROL_AF_STATE_NOT_FOCUSED_LOCKED);
4444 } else {
4445 nextState = NO_TRANSITION;
4446 }
4447 } else {
4448 nextState = HAL_AFSTATE_FAILED;
4449 SetAfStateForService(ANDROID_CONTROL_AF_STATE_NOT_FOCUSED_LOCKED);
4450 }
Sungjoong Kang0f26b202012-08-17 15:43:12 -07004451 break;
4452 default:
4453 bWrongTransition = true;
4454 break;
4455 }
4456 }
4457 else if (m_afState == HAL_AFSTATE_LOCKED) {
4458 switch (noti) {
4459 case AA_AFSTATE_INACTIVE:
4460 case AA_AFSTATE_ACTIVE_SCAN:
4461 bWrongTransition = true;
4462 break;
4463 case AA_AFSTATE_AF_ACQUIRED_FOCUS:
Younghwan Joo6f19b6c2012-08-30 13:56:53 -07004464 // Flash off if flash mode is available.
Younghwan Joo9a710a42012-09-05 17:52:08 -07004465 if (m_ctlInfo.flash.m_afFlashEnableFlg)
4466 m_ctlInfo.flash.m_afFlashCnt = IF_FLASH_AF_OFF;
Sungjoong Kang0f26b202012-08-17 15:43:12 -07004467 nextState = NO_TRANSITION;
4468 break;
4469 case AA_AFSTATE_AF_FAILED_FOCUS:
4470 default:
4471 bWrongTransition = true;
4472 break;
4473 }
4474 }
4475 else if (m_afState == HAL_AFSTATE_FAILED) {
4476 switch (noti) {
4477 case AA_AFSTATE_INACTIVE:
4478 case AA_AFSTATE_ACTIVE_SCAN:
4479 case AA_AFSTATE_AF_ACQUIRED_FOCUS:
4480 bWrongTransition = true;
4481 break;
4482 case AA_AFSTATE_AF_FAILED_FOCUS:
Younghwan Joo6f19b6c2012-08-30 13:56:53 -07004483 // Flash off if flash mode is available.
Younghwan Joo9a710a42012-09-05 17:52:08 -07004484 if (m_ctlInfo.flash.m_afFlashEnableFlg)
4485 m_ctlInfo.flash.m_afFlashCnt = IF_FLASH_AF_OFF;
Sungjoong Kang0f26b202012-08-17 15:43:12 -07004486 nextState = NO_TRANSITION;
4487 break;
4488 default:
4489 bWrongTransition = true;
4490 break;
4491 }
4492 }
4493 if (bWrongTransition) {
4494 ALOGV("(%s): Wrong Transition state(%d) noti(%d)", __FUNCTION__, m_afState, noti);
4495 return;
4496 }
4497 ALOGV("(%s): State (%d) -> (%d) by (%d)", __FUNCTION__, m_afState, nextState, noti);
4498 if (nextState != NO_TRANSITION)
4499 m_afState = nextState;
4500}
4501
4502void ExynosCameraHWInterface2::OnAfNotificationCAFPicture(enum aa_afstate noti)
4503{
4504 int nextState = NO_TRANSITION;
4505 bool bWrongTransition = false;
4506
4507 if (m_afState == HAL_AFSTATE_INACTIVE) {
4508 switch (noti) {
4509 case AA_AFSTATE_INACTIVE:
4510 case AA_AFSTATE_ACTIVE_SCAN:
4511 case AA_AFSTATE_AF_ACQUIRED_FOCUS:
4512 case AA_AFSTATE_AF_FAILED_FOCUS:
4513 default:
4514 nextState = NO_TRANSITION;
4515 break;
4516 }
4517 }
4518 else if (m_afState == HAL_AFSTATE_STARTED) {
4519 switch (noti) {
4520 case AA_AFSTATE_INACTIVE:
4521 nextState = NO_TRANSITION;
4522 break;
4523 case AA_AFSTATE_ACTIVE_SCAN:
4524 nextState = HAL_AFSTATE_SCANNING;
4525 SetAfStateForService(ANDROID_CONTROL_AF_STATE_PASSIVE_SCAN);
4526 break;
4527 case AA_AFSTATE_AF_ACQUIRED_FOCUS:
4528 nextState = HAL_AFSTATE_PASSIVE_FOCUSED;
4529 SetAfStateForService(ANDROID_CONTROL_AF_STATE_PASSIVE_FOCUSED);
4530 break;
4531 case AA_AFSTATE_AF_FAILED_FOCUS:
Sungjoong Kangcd13bb72012-08-28 13:05:01 -07004532 //nextState = HAL_AFSTATE_FAILED;
4533 //SetAfStateForService(ANDROID_CONTROL_AF_STATE_NOT_FOCUSED_LOCKED);
4534 nextState = NO_TRANSITION;
Sungjoong Kang0f26b202012-08-17 15:43:12 -07004535 break;
4536 default:
4537 bWrongTransition = true;
4538 break;
4539 }
4540 }
4541 else if (m_afState == HAL_AFSTATE_SCANNING) {
4542 switch (noti) {
4543 case AA_AFSTATE_INACTIVE:
Sungjoong Kang36c106c2012-08-23 17:38:20 -07004544 nextState = NO_TRANSITION;
Sungjoong Kang0f26b202012-08-17 15:43:12 -07004545 break;
4546 case AA_AFSTATE_ACTIVE_SCAN:
4547 nextState = NO_TRANSITION;
Sungjoong Kang36c106c2012-08-23 17:38:20 -07004548 m_AfHwStateFailed = false;
Sungjoong Kang0f26b202012-08-17 15:43:12 -07004549 break;
4550 case AA_AFSTATE_AF_ACQUIRED_FOCUS:
4551 nextState = HAL_AFSTATE_PASSIVE_FOCUSED;
Sungjoong Kang36c106c2012-08-23 17:38:20 -07004552 m_AfHwStateFailed = false;
Sungjoong Kang0f26b202012-08-17 15:43:12 -07004553 SetAfStateForService(ANDROID_CONTROL_AF_STATE_PASSIVE_FOCUSED);
4554 break;
4555 case AA_AFSTATE_AF_FAILED_FOCUS:
Sungjoong Kang36c106c2012-08-23 17:38:20 -07004556 nextState = HAL_AFSTATE_PASSIVE_FOCUSED;
4557 m_AfHwStateFailed = true;
4558 SetAfStateForService(ANDROID_CONTROL_AF_STATE_PASSIVE_FOCUSED);
Sungjoong Kang0f26b202012-08-17 15:43:12 -07004559 break;
4560 default:
4561 bWrongTransition = true;
4562 break;
4563 }
4564 }
4565 else if (m_afState == HAL_AFSTATE_PASSIVE_FOCUSED) {
4566 switch (noti) {
4567 case AA_AFSTATE_INACTIVE:
Sungjoong Kang36c106c2012-08-23 17:38:20 -07004568 nextState = NO_TRANSITION;
Sungjoong Kang0f26b202012-08-17 15:43:12 -07004569 break;
4570 case AA_AFSTATE_ACTIVE_SCAN:
4571 nextState = HAL_AFSTATE_SCANNING;
Sungjoong Kang36c106c2012-08-23 17:38:20 -07004572 m_AfHwStateFailed = false;
Sungjoong Kang0f26b202012-08-17 15:43:12 -07004573 SetAfStateForService(ANDROID_CONTROL_AF_STATE_PASSIVE_SCAN);
4574 break;
4575 case AA_AFSTATE_AF_ACQUIRED_FOCUS:
4576 nextState = NO_TRANSITION;
Sungjoong Kang36c106c2012-08-23 17:38:20 -07004577 m_AfHwStateFailed = false;
Younghwan Joocaea49e2012-09-07 13:34:20 -07004578 // Flash off if flash mode is available.
4579 if (m_ctlInfo.flash.m_afFlashEnableFlg) {
4580 ALOGD("[AF Flash] Off with Mode (%d) state (%d) noti (%d)", m_afMode, m_afState, (int)noti);
4581 m_ctlInfo.flash.m_afFlashCnt = IF_FLASH_AF_OFF;
4582 }
Sungjoong Kang0f26b202012-08-17 15:43:12 -07004583 break;
4584 case AA_AFSTATE_AF_FAILED_FOCUS:
Sungjoong Kang36c106c2012-08-23 17:38:20 -07004585 nextState = NO_TRANSITION;
4586 m_AfHwStateFailed = true;
Younghwan Joocaea49e2012-09-07 13:34:20 -07004587 // Flash off if flash mode is available.
4588 if (m_ctlInfo.flash.m_afFlashEnableFlg) {
4589 ALOGD("[AF Flash] Off with Mode (%d) state (%d) noti (%d)", m_afMode, m_afState, (int)noti);
4590 m_ctlInfo.flash.m_afFlashCnt = IF_FLASH_AF_OFF;
4591 }
Sungjoong Kang0f26b202012-08-17 15:43:12 -07004592 break;
4593 default:
4594 bWrongTransition = true;
4595 break;
4596 }
4597 }
4598 else if (m_afState == HAL_AFSTATE_NEEDS_DETERMINATION) {
4599 switch (noti) {
4600 case AA_AFSTATE_INACTIVE:
Sungjoong Kang36c106c2012-08-23 17:38:20 -07004601 nextState = NO_TRANSITION;
Sungjoong Kang0f26b202012-08-17 15:43:12 -07004602 break;
4603 case AA_AFSTATE_ACTIVE_SCAN:
4604 nextState = NO_TRANSITION;
4605 break;
4606 case AA_AFSTATE_AF_ACQUIRED_FOCUS:
Younghwan Joocaea49e2012-09-07 13:34:20 -07004607 // If Flash mode is enable, after AF execute pre-capture metering
4608 if (m_ctlInfo.flash.m_afFlashEnableFlg) {
4609 ALOGD("[AF Flash] AUTO start with Mode (%d) state (%d) noti (%d)", m_afMode, m_afState, (int)noti);
4610 if (m_ctlInfo.flash.m_afFlashCnt == IS_FLASH_AF_ON_DONE) {
4611 m_ctlInfo.flash.m_afFlashCnt = IS_FLASH_AF_AUTO_AE_AWB_LOCK;
4612 } else if (m_ctlInfo.flash.m_afFlashCnt == IS_FLASH_AF_AUTO_END) {
4613 m_IsAfLockRequired = true;
4614 nextState = HAL_AFSTATE_LOCKED;
4615 SetAfStateForService(ANDROID_CONTROL_AF_STATE_FOCUSED_LOCKED);
4616 } else {
4617 nextState = NO_TRANSITION;
4618 }
4619 } else {
4620 m_IsAfLockRequired = true;
4621 nextState = HAL_AFSTATE_LOCKED;
4622 SetAfStateForService(ANDROID_CONTROL_AF_STATE_FOCUSED_LOCKED);
4623 }
Sungjoong Kang0f26b202012-08-17 15:43:12 -07004624 break;
4625 case AA_AFSTATE_AF_FAILED_FOCUS:
Younghwan Joocaea49e2012-09-07 13:34:20 -07004626 // If Flash mode is enable, after AF execute pre-capture metering
4627 if (m_ctlInfo.flash.m_afFlashEnableFlg) {
4628 ALOGD("[AF Flash] AUTO start with Mode (%d) state (%d) noti (%d)", m_afMode, m_afState, (int)noti);
4629 if (m_ctlInfo.flash.m_afFlashCnt == IS_FLASH_AF_ON_DONE) {
4630 m_ctlInfo.flash.m_afFlashCnt = IS_FLASH_AF_AUTO_AE_AWB_LOCK;
4631 } else if (m_ctlInfo.flash.m_afFlashCnt == IS_FLASH_AF_AUTO_END) {
4632 m_IsAfLockRequired = true;
4633 nextState = HAL_AFSTATE_FAILED;
4634 SetAfStateForService(ANDROID_CONTROL_AF_STATE_NOT_FOCUSED_LOCKED);
4635 } else {
4636 nextState = NO_TRANSITION;
4637 }
4638 } else {
4639 m_IsAfLockRequired = true;
4640 nextState = HAL_AFSTATE_FAILED;
4641 SetAfStateForService(ANDROID_CONTROL_AF_STATE_NOT_FOCUSED_LOCKED);
4642 }
Sungjoong Kang0f26b202012-08-17 15:43:12 -07004643 break;
4644 default:
4645 bWrongTransition = true;
4646 break;
4647 }
4648 }
4649 else if (m_afState == HAL_AFSTATE_LOCKED) {
4650 switch (noti) {
4651 case AA_AFSTATE_INACTIVE:
4652 nextState = NO_TRANSITION;
4653 break;
4654 case AA_AFSTATE_ACTIVE_SCAN:
4655 bWrongTransition = true;
4656 break;
4657 case AA_AFSTATE_AF_ACQUIRED_FOCUS:
4658 nextState = NO_TRANSITION;
Younghwan Joocaea49e2012-09-07 13:34:20 -07004659 // Flash off if flash mode is available.
4660 if (m_ctlInfo.flash.m_afFlashEnableFlg) {
4661 ALOGD("[AF Flash] Off with Mode (%d) state (%d) noti (%d)", m_afMode, m_afState, (int)noti);
4662 m_ctlInfo.flash.m_afFlashCnt = IF_FLASH_AF_OFF;
4663 }
Sungjoong Kang0f26b202012-08-17 15:43:12 -07004664 break;
4665 case AA_AFSTATE_AF_FAILED_FOCUS:
4666 default:
4667 bWrongTransition = true;
4668 break;
4669 }
4670 }
4671 else if (m_afState == HAL_AFSTATE_FAILED) {
4672 switch (noti) {
4673 case AA_AFSTATE_INACTIVE:
Sungjoong Kang36c106c2012-08-23 17:38:20 -07004674 bWrongTransition = true;
4675 break;
Sungjoong Kang0f26b202012-08-17 15:43:12 -07004676 case AA_AFSTATE_ACTIVE_SCAN:
Sungjoong Kang36c106c2012-08-23 17:38:20 -07004677 nextState = HAL_AFSTATE_SCANNING;
4678 break;
Sungjoong Kang0f26b202012-08-17 15:43:12 -07004679 case AA_AFSTATE_AF_ACQUIRED_FOCUS:
4680 bWrongTransition = true;
4681 break;
4682 case AA_AFSTATE_AF_FAILED_FOCUS:
Younghwan Joocaea49e2012-09-07 13:34:20 -07004683 // Flash off if flash mode is available.
4684 if (m_ctlInfo.flash.m_afFlashEnableFlg) {
4685 ALOGD("[AF Flash] Off with Mode (%d) state (%d) noti (%d)", m_afMode, m_afState, (int)noti);
4686 m_ctlInfo.flash.m_afFlashCnt = IF_FLASH_AF_OFF;
4687 }
Sungjoong Kang0f26b202012-08-17 15:43:12 -07004688 nextState = NO_TRANSITION;
4689 break;
4690 default:
4691 bWrongTransition = true;
4692 break;
4693 }
4694 }
4695 if (bWrongTransition) {
4696 ALOGV("(%s): Wrong Transition state(%d) noti(%d)", __FUNCTION__, m_afState, noti);
4697 return;
4698 }
4699 ALOGV("(%s): State (%d) -> (%d) by (%d)", __FUNCTION__, m_afState, nextState, noti);
4700 if (nextState != NO_TRANSITION)
4701 m_afState = nextState;
4702}
4703
4704void ExynosCameraHWInterface2::OnAfNotificationCAFVideo(enum aa_afstate noti)
4705{
4706 int nextState = NO_TRANSITION;
4707 bool bWrongTransition = false;
4708
4709 if (m_afState == HAL_AFSTATE_INACTIVE) {
4710 switch (noti) {
4711 case AA_AFSTATE_INACTIVE:
4712 case AA_AFSTATE_ACTIVE_SCAN:
4713 case AA_AFSTATE_AF_ACQUIRED_FOCUS:
4714 case AA_AFSTATE_AF_FAILED_FOCUS:
4715 default:
4716 nextState = NO_TRANSITION;
4717 break;
4718 }
4719 }
4720 else if (m_afState == HAL_AFSTATE_STARTED) {
4721 switch (noti) {
4722 case AA_AFSTATE_INACTIVE:
4723 nextState = NO_TRANSITION;
4724 break;
4725 case AA_AFSTATE_ACTIVE_SCAN:
4726 nextState = HAL_AFSTATE_SCANNING;
4727 SetAfStateForService(ANDROID_CONTROL_AF_STATE_PASSIVE_SCAN);
4728 break;
4729 case AA_AFSTATE_AF_ACQUIRED_FOCUS:
4730 nextState = HAL_AFSTATE_PASSIVE_FOCUSED;
4731 SetAfStateForService(ANDROID_CONTROL_AF_STATE_PASSIVE_FOCUSED);
4732 break;
4733 case AA_AFSTATE_AF_FAILED_FOCUS:
4734 nextState = HAL_AFSTATE_FAILED;
4735 SetAfStateForService(ANDROID_CONTROL_AF_STATE_NOT_FOCUSED_LOCKED);
4736 break;
4737 default:
4738 bWrongTransition = true;
4739 break;
4740 }
4741 }
4742 else if (m_afState == HAL_AFSTATE_SCANNING) {
4743 switch (noti) {
4744 case AA_AFSTATE_INACTIVE:
4745 bWrongTransition = true;
4746 break;
4747 case AA_AFSTATE_ACTIVE_SCAN:
4748 nextState = NO_TRANSITION;
4749 break;
4750 case AA_AFSTATE_AF_ACQUIRED_FOCUS:
4751 nextState = HAL_AFSTATE_PASSIVE_FOCUSED;
4752 SetAfStateForService(ANDROID_CONTROL_AF_STATE_PASSIVE_FOCUSED);
4753 break;
4754 case AA_AFSTATE_AF_FAILED_FOCUS:
4755 nextState = NO_TRANSITION;
Sungjoong Kang36c106c2012-08-23 17:38:20 -07004756 m_IsAfTriggerRequired = true;
Sungjoong Kang0f26b202012-08-17 15:43:12 -07004757 break;
4758 default:
4759 bWrongTransition = true;
4760 break;
4761 }
4762 }
4763 else if (m_afState == HAL_AFSTATE_PASSIVE_FOCUSED) {
4764 switch (noti) {
4765 case AA_AFSTATE_INACTIVE:
4766 bWrongTransition = true;
4767 break;
4768 case AA_AFSTATE_ACTIVE_SCAN:
4769 nextState = HAL_AFSTATE_SCANNING;
4770 SetAfStateForService(ANDROID_CONTROL_AF_STATE_PASSIVE_SCAN);
4771 break;
4772 case AA_AFSTATE_AF_ACQUIRED_FOCUS:
4773 nextState = NO_TRANSITION;
4774 break;
4775 case AA_AFSTATE_AF_FAILED_FOCUS:
4776 nextState = HAL_AFSTATE_FAILED;
4777 SetAfStateForService(ANDROID_CONTROL_AF_STATE_NOT_FOCUSED_LOCKED);
Sungjoong Kang8e2c2fd2012-08-27 00:02:22 -07004778 // TODO : needs NO_TRANSITION ?
Sungjoong Kang0f26b202012-08-17 15:43:12 -07004779 break;
4780 default:
4781 bWrongTransition = true;
4782 break;
4783 }
4784 }
4785 else if (m_afState == HAL_AFSTATE_NEEDS_DETERMINATION) {
4786 switch (noti) {
4787 case AA_AFSTATE_INACTIVE:
4788 bWrongTransition = true;
4789 break;
4790 case AA_AFSTATE_ACTIVE_SCAN:
4791 nextState = NO_TRANSITION;
4792 break;
4793 case AA_AFSTATE_AF_ACQUIRED_FOCUS:
4794 m_IsAfLockRequired = true;
4795 nextState = HAL_AFSTATE_LOCKED;
4796 SetAfStateForService(ANDROID_CONTROL_AF_STATE_FOCUSED_LOCKED);
4797 break;
4798 case AA_AFSTATE_AF_FAILED_FOCUS:
4799 nextState = HAL_AFSTATE_FAILED;
4800 SetAfStateForService(ANDROID_CONTROL_AF_STATE_NOT_FOCUSED_LOCKED);
4801 break;
4802 default:
4803 bWrongTransition = true;
4804 break;
4805 }
4806 }
4807 else if (m_afState == HAL_AFSTATE_LOCKED) {
4808 switch (noti) {
4809 case AA_AFSTATE_INACTIVE:
4810 nextState = NO_TRANSITION;
4811 break;
4812 case AA_AFSTATE_ACTIVE_SCAN:
4813 bWrongTransition = true;
4814 break;
4815 case AA_AFSTATE_AF_ACQUIRED_FOCUS:
4816 nextState = NO_TRANSITION;
4817 break;
4818 case AA_AFSTATE_AF_FAILED_FOCUS:
4819 default:
4820 bWrongTransition = true;
4821 break;
4822 }
4823 }
4824 else if (m_afState == HAL_AFSTATE_FAILED) {
4825 switch (noti) {
4826 case AA_AFSTATE_INACTIVE:
4827 case AA_AFSTATE_ACTIVE_SCAN:
4828 case AA_AFSTATE_AF_ACQUIRED_FOCUS:
4829 bWrongTransition = true;
4830 break;
4831 case AA_AFSTATE_AF_FAILED_FOCUS:
4832 nextState = NO_TRANSITION;
4833 break;
4834 default:
4835 bWrongTransition = true;
4836 break;
4837 }
4838 }
4839 if (bWrongTransition) {
4840 ALOGV("(%s): Wrong Transition state(%d) noti(%d)", __FUNCTION__, m_afState, noti);
4841 return;
4842 }
4843 ALOGV("(%s): State (%d) -> (%d) by (%d)", __FUNCTION__, m_afState, nextState, noti);
4844 if (nextState != NO_TRANSITION)
4845 m_afState = nextState;
4846}
4847
4848void ExynosCameraHWInterface2::OnAfCancel(int id)
4849{
Sungjoong Kang8e2c2fd2012-08-27 00:02:22 -07004850 m_afTriggerId = id;
4851
Sungjoong Kang0f26b202012-08-17 15:43:12 -07004852 switch (m_afMode) {
4853 case AA_AFMODE_AUTO:
4854 case AA_AFMODE_MACRO:
Sungjoong Kang8e2c2fd2012-08-27 00:02:22 -07004855 case AA_AFMODE_OFF:
Sungjoong Kang0f26b202012-08-17 15:43:12 -07004856 OnAfCancelAutoMacro(id);
4857 break;
4858 case AA_AFMODE_CONTINUOUS_VIDEO:
4859 OnAfCancelCAFVideo(id);
4860 break;
4861 case AA_AFMODE_CONTINUOUS_PICTURE:
4862 OnAfCancelCAFPicture(id);
4863 break;
Sungjoong Kang0f26b202012-08-17 15:43:12 -07004864 default:
4865 break;
4866 }
4867}
4868
4869void ExynosCameraHWInterface2::OnAfCancelAutoMacro(int id)
4870{
4871 int nextState = NO_TRANSITION;
4872 m_afTriggerId = id;
4873
Younghwan Joo9a710a42012-09-05 17:52:08 -07004874 if (m_ctlInfo.flash.m_afFlashEnableFlg) {
4875 m_ctlInfo.flash.m_afFlashCnt = IF_FLASH_AF_OFF;
Younghwan Joo6f19b6c2012-08-30 13:56:53 -07004876 }
Sungjoong Kang0f26b202012-08-17 15:43:12 -07004877 switch (m_afState) {
4878 case HAL_AFSTATE_INACTIVE:
4879 nextState = NO_TRANSITION;
Sungjoong Kangcd13bb72012-08-28 13:05:01 -07004880 SetAfStateForService(ANDROID_CONTROL_AF_STATE_INACTIVE);
Sungjoong Kang0f26b202012-08-17 15:43:12 -07004881 break;
4882 case HAL_AFSTATE_NEEDS_COMMAND:
4883 case HAL_AFSTATE_STARTED:
4884 case HAL_AFSTATE_SCANNING:
4885 case HAL_AFSTATE_LOCKED:
4886 case HAL_AFSTATE_FAILED:
4887 SetAfMode(AA_AFMODE_OFF);
4888 SetAfStateForService(ANDROID_CONTROL_AF_STATE_INACTIVE);
4889 nextState = HAL_AFSTATE_INACTIVE;
4890 break;
4891 default:
4892 break;
4893 }
4894 ALOGV("(%s): State (%d) -> (%d)", __FUNCTION__, m_afState, nextState);
4895 if (nextState != NO_TRANSITION)
4896 m_afState = nextState;
4897}
4898
4899void ExynosCameraHWInterface2::OnAfCancelCAFPicture(int id)
4900{
4901 int nextState = NO_TRANSITION;
4902 m_afTriggerId = id;
4903
4904 switch (m_afState) {
4905 case HAL_AFSTATE_INACTIVE:
4906 nextState = NO_TRANSITION;
4907 break;
4908 case HAL_AFSTATE_NEEDS_COMMAND:
4909 case HAL_AFSTATE_STARTED:
4910 case HAL_AFSTATE_SCANNING:
4911 case HAL_AFSTATE_LOCKED:
4912 case HAL_AFSTATE_FAILED:
4913 case HAL_AFSTATE_NEEDS_DETERMINATION:
4914 case HAL_AFSTATE_PASSIVE_FOCUSED:
4915 SetAfMode(AA_AFMODE_OFF);
4916 SetAfStateForService(ANDROID_CONTROL_AF_STATE_INACTIVE);
4917 SetAfMode(AA_AFMODE_CONTINUOUS_PICTURE);
4918 nextState = HAL_AFSTATE_INACTIVE;
4919 break;
4920 default:
4921 break;
4922 }
4923 ALOGV("(%s): State (%d) -> (%d)", __FUNCTION__, m_afState, nextState);
4924 if (nextState != NO_TRANSITION)
4925 m_afState = nextState;
4926}
4927
4928void ExynosCameraHWInterface2::OnAfCancelCAFVideo(int id)
4929{
4930 int nextState = NO_TRANSITION;
4931 m_afTriggerId = id;
4932
4933 switch (m_afState) {
4934 case HAL_AFSTATE_INACTIVE:
4935 nextState = NO_TRANSITION;
4936 break;
4937 case HAL_AFSTATE_NEEDS_COMMAND:
4938 case HAL_AFSTATE_STARTED:
4939 case HAL_AFSTATE_SCANNING:
4940 case HAL_AFSTATE_LOCKED:
4941 case HAL_AFSTATE_FAILED:
4942 case HAL_AFSTATE_NEEDS_DETERMINATION:
4943 case HAL_AFSTATE_PASSIVE_FOCUSED:
4944 SetAfMode(AA_AFMODE_OFF);
4945 SetAfStateForService(ANDROID_CONTROL_AF_STATE_INACTIVE);
4946 SetAfMode(AA_AFMODE_CONTINUOUS_VIDEO);
4947 nextState = HAL_AFSTATE_INACTIVE;
4948 break;
4949 default:
4950 break;
4951 }
4952 ALOGV("(%s): State (%d) -> (%d)", __FUNCTION__, m_afState, nextState);
4953 if (nextState != NO_TRANSITION)
4954 m_afState = nextState;
4955}
4956
4957void ExynosCameraHWInterface2::SetAfStateForService(int newState)
4958{
Sungjoong Kang8e2c2fd2012-08-27 00:02:22 -07004959 if (m_serviceAfState != newState || newState == 0)
4960 m_notifyCb(CAMERA2_MSG_AUTOFOCUS, newState, m_afTriggerId, 0, m_callbackCookie);
Sungjoong Kang0f26b202012-08-17 15:43:12 -07004961 m_serviceAfState = newState;
Sungjoong Kang0f26b202012-08-17 15:43:12 -07004962}
4963
4964int ExynosCameraHWInterface2::GetAfStateForService()
4965{
4966 return m_serviceAfState;
4967}
4968
4969void ExynosCameraHWInterface2::SetAfMode(enum aa_afmode afMode)
4970{
4971 if (m_afMode != afMode) {
4972 if (m_IsAfModeUpdateRequired) {
4973 m_afMode2 = afMode;
4974 ALOGV("(%s): pending(%d) and new(%d)", __FUNCTION__, m_afMode, afMode);
4975 }
4976 else {
4977 ALOGV("(%s): current(%d) new(%d)", __FUNCTION__, m_afMode, afMode);
4978 m_IsAfModeUpdateRequired = true;
4979 m_afMode = afMode;
Sungjoong Kangcd13bb72012-08-28 13:05:01 -07004980 if (m_afModeWaitingCnt != 0) {
4981 m_afModeWaitingCnt = 0;
hyeonmyeong Choi7d0efb52012-09-02 16:02:13 -07004982 m_afState = HAL_AFSTATE_INACTIVE;
Sungjoong Kangcd13bb72012-08-28 13:05:01 -07004983 OnAfTrigger(m_afPendingTriggerId);
4984 }
Sungjoong Kang8e2c2fd2012-08-27 00:02:22 -07004985 }
Sungjoong Kang0f26b202012-08-17 15:43:12 -07004986 }
4987}
4988
Sungjoong Kangeed7ed12012-08-23 16:35:08 -07004989void ExynosCameraHWInterface2::m_setExifFixedAttribute(void)
4990{
4991 char property[PROPERTY_VALUE_MAX];
4992
4993 //2 0th IFD TIFF Tags
Rebecca Schultz Zavin1b8ef182012-09-04 09:44:10 -07004994#if 0 // STOPSHIP TODO(aray): remove before launch, but for now don't leak product data
Sungjoong Kangeed7ed12012-08-23 16:35:08 -07004995 //3 Maker
4996 property_get("ro.product.brand", property, EXIF_DEF_MAKER);
4997 strncpy((char *)mExifInfo.maker, property,
4998 sizeof(mExifInfo.maker) - 1);
4999 mExifInfo.maker[sizeof(mExifInfo.maker) - 1] = '\0';
5000 //3 Model
5001 property_get("ro.product.model", property, EXIF_DEF_MODEL);
5002 strncpy((char *)mExifInfo.model, property,
5003 sizeof(mExifInfo.model) - 1);
5004 mExifInfo.model[sizeof(mExifInfo.model) - 1] = '\0';
5005 //3 Software
5006 property_get("ro.build.id", property, EXIF_DEF_SOFTWARE);
5007 strncpy((char *)mExifInfo.software, property,
5008 sizeof(mExifInfo.software) - 1);
5009 mExifInfo.software[sizeof(mExifInfo.software) - 1] = '\0';
Alex Ray5a92f772012-08-27 17:23:41 -07005010#endif
Sungjoong Kangeed7ed12012-08-23 16:35:08 -07005011
5012 //3 YCbCr Positioning
5013 mExifInfo.ycbcr_positioning = EXIF_DEF_YCBCR_POSITIONING;
5014
5015 //2 0th IFD Exif Private Tags
5016 //3 F Number
5017 mExifInfo.fnumber.num = EXIF_DEF_FNUMBER_NUM;
5018 mExifInfo.fnumber.den = EXIF_DEF_FNUMBER_DEN;
5019 //3 Exposure Program
5020 mExifInfo.exposure_program = EXIF_DEF_EXPOSURE_PROGRAM;
5021 //3 Exif Version
5022 memcpy(mExifInfo.exif_version, EXIF_DEF_EXIF_VERSION, sizeof(mExifInfo.exif_version));
5023 //3 Aperture
5024 uint32_t av = APEX_FNUM_TO_APERTURE((double)mExifInfo.fnumber.num/mExifInfo.fnumber.den);
5025 mExifInfo.aperture.num = av*EXIF_DEF_APEX_DEN;
5026 mExifInfo.aperture.den = EXIF_DEF_APEX_DEN;
5027 //3 Maximum lens aperture
5028 mExifInfo.max_aperture.num = mExifInfo.aperture.num;
5029 mExifInfo.max_aperture.den = mExifInfo.aperture.den;
5030 //3 Lens Focal Length
5031 mExifInfo.focal_length.num = EXIF_DEF_FOCAL_LEN_NUM;
5032 mExifInfo.focal_length.den = EXIF_DEF_FOCAL_LEN_DEN;
5033 //3 User Comments
5034 strcpy((char *)mExifInfo.user_comment, EXIF_DEF_USERCOMMENTS);
5035 //3 Color Space information
5036 mExifInfo.color_space = EXIF_DEF_COLOR_SPACE;
5037 //3 Exposure Mode
5038 mExifInfo.exposure_mode = EXIF_DEF_EXPOSURE_MODE;
5039
5040 //2 0th IFD GPS Info Tags
5041 unsigned char gps_version[4] = { 0x02, 0x02, 0x00, 0x00 };
5042 memcpy(mExifInfo.gps_version_id, gps_version, sizeof(gps_version));
5043
5044 //2 1th IFD TIFF Tags
5045 mExifInfo.compression_scheme = EXIF_DEF_COMPRESSION;
5046 mExifInfo.x_resolution.num = EXIF_DEF_RESOLUTION_NUM;
5047 mExifInfo.x_resolution.den = EXIF_DEF_RESOLUTION_DEN;
5048 mExifInfo.y_resolution.num = EXIF_DEF_RESOLUTION_NUM;
5049 mExifInfo.y_resolution.den = EXIF_DEF_RESOLUTION_DEN;
5050 mExifInfo.resolution_unit = EXIF_DEF_RESOLUTION_UNIT;
5051}
5052
5053void ExynosCameraHWInterface2::m_setExifChangedAttribute(exif_attribute_t *exifInfo, ExynosRect *rect,
5054 camera2_shot *currentEntry)
5055{
5056 camera2_dm *dm = &(currentEntry->dm);
5057 camera2_ctl *ctl = &(currentEntry->ctl);
5058
5059 ALOGV("(%s): framecnt(%d) exp(%lld) iso(%d)", __FUNCTION__, ctl->request.frameCount, dm->sensor.exposureTime,dm->aa.isoValue );
5060 if (!ctl->request.frameCount)
5061 return;
5062 //2 0th IFD TIFF Tags
5063 //3 Width
5064 exifInfo->width = rect->w;
5065 //3 Height
5066 exifInfo->height = rect->h;
5067 //3 Orientation
5068 switch (ctl->jpeg.orientation) {
5069 case 90:
5070 exifInfo->orientation = EXIF_ORIENTATION_90;
5071 break;
5072 case 180:
5073 exifInfo->orientation = EXIF_ORIENTATION_180;
5074 break;
5075 case 270:
5076 exifInfo->orientation = EXIF_ORIENTATION_270;
5077 break;
5078 case 0:
5079 default:
5080 exifInfo->orientation = EXIF_ORIENTATION_UP;
5081 break;
5082 }
5083
5084 //3 Date time
5085 time_t rawtime;
5086 struct tm *timeinfo;
5087 time(&rawtime);
5088 timeinfo = localtime(&rawtime);
5089 strftime((char *)exifInfo->date_time, 20, "%Y:%m:%d %H:%M:%S", timeinfo);
5090
5091 //2 0th IFD Exif Private Tags
5092 //3 Exposure Time
5093 int shutterSpeed = (dm->sensor.exposureTime/1000);
5094
5095 if (shutterSpeed < 0) {
5096 shutterSpeed = 100;
5097 }
5098
5099 exifInfo->exposure_time.num = 1;
5100 // x us -> 1/x s */
5101 //exifInfo->exposure_time.den = (uint32_t)(1000000 / shutterSpeed);
5102 exifInfo->exposure_time.den = (uint32_t)((double)1000000 / shutterSpeed);
5103
5104 //3 ISO Speed Rating
5105 exifInfo->iso_speed_rating = dm->aa.isoValue;
5106
5107 uint32_t av, tv, bv, sv, ev;
5108 av = APEX_FNUM_TO_APERTURE((double)exifInfo->fnumber.num / exifInfo->fnumber.den);
5109 tv = APEX_EXPOSURE_TO_SHUTTER((double)exifInfo->exposure_time.num / exifInfo->exposure_time.den);
5110 sv = APEX_ISO_TO_FILMSENSITIVITY(exifInfo->iso_speed_rating);
5111 bv = av + tv - sv;
5112 ev = av + tv;
5113 //ALOGD("Shutter speed=%d us, iso=%d", shutterSpeed, exifInfo->iso_speed_rating);
5114 ALOGD("AV=%d, TV=%d, SV=%d", av, tv, sv);
5115
5116 //3 Shutter Speed
5117 exifInfo->shutter_speed.num = tv * EXIF_DEF_APEX_DEN;
5118 exifInfo->shutter_speed.den = EXIF_DEF_APEX_DEN;
5119 //3 Brightness
5120 exifInfo->brightness.num = bv*EXIF_DEF_APEX_DEN;
5121 exifInfo->brightness.den = EXIF_DEF_APEX_DEN;
5122 //3 Exposure Bias
5123 if (ctl->aa.sceneMode== AA_SCENE_MODE_BEACH||
5124 ctl->aa.sceneMode== AA_SCENE_MODE_SNOW) {
5125 exifInfo->exposure_bias.num = EXIF_DEF_APEX_DEN;
5126 exifInfo->exposure_bias.den = EXIF_DEF_APEX_DEN;
5127 } else {
5128 exifInfo->exposure_bias.num = 0;
5129 exifInfo->exposure_bias.den = 0;
5130 }
5131 //3 Metering Mode
5132 /*switch (m_curCameraInfo->metering) {
5133 case METERING_MODE_CENTER:
5134 exifInfo->metering_mode = EXIF_METERING_CENTER;
5135 break;
5136 case METERING_MODE_MATRIX:
5137 exifInfo->metering_mode = EXIF_METERING_MULTISPOT;
5138 break;
5139 case METERING_MODE_SPOT:
5140 exifInfo->metering_mode = EXIF_METERING_SPOT;
5141 break;
5142 case METERING_MODE_AVERAGE:
5143 default:
5144 exifInfo->metering_mode = EXIF_METERING_AVERAGE;
5145 break;
5146 }*/
5147 exifInfo->metering_mode = EXIF_METERING_CENTER;
5148
5149 //3 Flash
Younghwan Joo9257e292012-09-08 21:11:18 -07005150 /*
Sungjoong Kangeed7ed12012-08-23 16:35:08 -07005151 int flash = dm->flash.flashMode;
5152 if (dm->flash.flashMode == FLASH_MODE_OFF || flash < 0)
5153 exifInfo->flash = EXIF_DEF_FLASH;
5154 else
5155 exifInfo->flash = flash;
Younghwan Joo9257e292012-09-08 21:11:18 -07005156 */
5157 if (m_ctlInfo.flash.m_flashDecisionResult)
5158 exifInfo->flash = 1;
5159 else
5160 exifInfo->flash = EXIF_DEF_FLASH;
Sungjoong Kangeed7ed12012-08-23 16:35:08 -07005161
5162 //3 White Balance
5163 if (dm->aa.awbMode == AA_AWBMODE_WB_AUTO)
5164 exifInfo->white_balance = EXIF_WB_AUTO;
5165 else
5166 exifInfo->white_balance = EXIF_WB_MANUAL;
5167
5168 //3 Scene Capture Type
5169 switch (ctl->aa.sceneMode) {
5170 case AA_SCENE_MODE_PORTRAIT:
5171 exifInfo->scene_capture_type = EXIF_SCENE_PORTRAIT;
5172 break;
5173 case AA_SCENE_MODE_LANDSCAPE:
5174 exifInfo->scene_capture_type = EXIF_SCENE_LANDSCAPE;
5175 break;
5176 case AA_SCENE_MODE_NIGHT_PORTRAIT:
5177 exifInfo->scene_capture_type = EXIF_SCENE_NIGHT;
5178 break;
5179 default:
5180 exifInfo->scene_capture_type = EXIF_SCENE_STANDARD;
5181 break;
5182 }
5183
5184 //2 0th IFD GPS Info Tags
5185 if (ctl->jpeg.gpsCoordinates[0] != 0 && ctl->jpeg.gpsCoordinates[1] != 0) {
5186
5187 if (ctl->jpeg.gpsCoordinates[0] > 0)
5188 strcpy((char *)exifInfo->gps_latitude_ref, "N");
5189 else
5190 strcpy((char *)exifInfo->gps_latitude_ref, "S");
5191
5192 if (ctl->jpeg.gpsCoordinates[1] > 0)
5193 strcpy((char *)exifInfo->gps_longitude_ref, "E");
5194 else
5195 strcpy((char *)exifInfo->gps_longitude_ref, "W");
5196
5197 if (ctl->jpeg.gpsCoordinates[2] > 0)
5198 exifInfo->gps_altitude_ref = 0;
5199 else
5200 exifInfo->gps_altitude_ref = 1;
5201
5202 double latitude = fabs(ctl->jpeg.gpsCoordinates[0] / 10000.0);
5203 double longitude = fabs(ctl->jpeg.gpsCoordinates[1] / 10000.0);
5204 double altitude = fabs(ctl->jpeg.gpsCoordinates[2] / 100.0);
5205
5206 exifInfo->gps_latitude[0].num = (uint32_t)latitude;
5207 exifInfo->gps_latitude[0].den = 1;
5208 exifInfo->gps_latitude[1].num = (uint32_t)((latitude - exifInfo->gps_latitude[0].num) * 60);
5209 exifInfo->gps_latitude[1].den = 1;
5210 exifInfo->gps_latitude[2].num = (uint32_t)((((latitude - exifInfo->gps_latitude[0].num) * 60)
5211 - exifInfo->gps_latitude[1].num) * 60);
5212 exifInfo->gps_latitude[2].den = 1;
5213
5214 exifInfo->gps_longitude[0].num = (uint32_t)longitude;
5215 exifInfo->gps_longitude[0].den = 1;
5216 exifInfo->gps_longitude[1].num = (uint32_t)((longitude - exifInfo->gps_longitude[0].num) * 60);
5217 exifInfo->gps_longitude[1].den = 1;
5218 exifInfo->gps_longitude[2].num = (uint32_t)((((longitude - exifInfo->gps_longitude[0].num) * 60)
5219 - exifInfo->gps_longitude[1].num) * 60);
5220 exifInfo->gps_longitude[2].den = 1;
5221
5222 exifInfo->gps_altitude.num = (uint32_t)altitude;
5223 exifInfo->gps_altitude.den = 1;
5224
5225 struct tm tm_data;
5226 long timestamp;
5227 timestamp = (long)ctl->jpeg.gpsTimestamp;
5228 gmtime_r(&timestamp, &tm_data);
5229 exifInfo->gps_timestamp[0].num = tm_data.tm_hour;
5230 exifInfo->gps_timestamp[0].den = 1;
5231 exifInfo->gps_timestamp[1].num = tm_data.tm_min;
5232 exifInfo->gps_timestamp[1].den = 1;
5233 exifInfo->gps_timestamp[2].num = tm_data.tm_sec;
5234 exifInfo->gps_timestamp[2].den = 1;
5235 snprintf((char*)exifInfo->gps_datestamp, sizeof(exifInfo->gps_datestamp),
5236 "%04d:%02d:%02d", tm_data.tm_year + 1900, tm_data.tm_mon + 1, tm_data.tm_mday);
5237
5238 exifInfo->enableGps = true;
5239 } else {
5240 exifInfo->enableGps = false;
5241 }
5242
5243 //2 1th IFD TIFF Tags
5244 exifInfo->widthThumb = ctl->jpeg.thumbnailSize[0];
5245 exifInfo->heightThumb = ctl->jpeg.thumbnailSize[1];
5246}
5247
Sungjoong Kang13d8c7b2012-07-14 10:20:39 +09005248ExynosCameraHWInterface2::MainThread::~MainThread()
Jiyoung Shinc15a6b02012-06-05 01:08:14 -07005249{
Sungjoong Kangad378612012-08-17 12:34:33 -07005250 ALOGV("(%s):", __FUNCTION__);
Sungjoong Kang13d8c7b2012-07-14 10:20:39 +09005251}
5252
5253void ExynosCameraHWInterface2::MainThread::release()
5254{
Sungjoong Kangad378612012-08-17 12:34:33 -07005255 ALOGV("(%s):", __func__);
Sungjoong Kang13d8c7b2012-07-14 10:20:39 +09005256 SetSignal(SIGNAL_THREAD_RELEASE);
Sungjoong Kang13d8c7b2012-07-14 10:20:39 +09005257}
5258
5259ExynosCameraHWInterface2::SensorThread::~SensorThread()
5260{
Sungjoong Kangad378612012-08-17 12:34:33 -07005261 ALOGV("(%s):", __FUNCTION__);
Sungjoong Kang13d8c7b2012-07-14 10:20:39 +09005262}
5263
5264void ExynosCameraHWInterface2::SensorThread::release()
5265{
Sungjoong Kangad378612012-08-17 12:34:33 -07005266 ALOGV("(%s):", __func__);
Sungjoong Kang13d8c7b2012-07-14 10:20:39 +09005267 SetSignal(SIGNAL_THREAD_RELEASE);
Sungjoong Kang13d8c7b2012-07-14 10:20:39 +09005268}
5269
5270ExynosCameraHWInterface2::IspThread::~IspThread()
5271{
Sungjoong Kangad378612012-08-17 12:34:33 -07005272 ALOGV("(%s):", __FUNCTION__);
Sungjoong Kang13d8c7b2012-07-14 10:20:39 +09005273}
5274
5275void ExynosCameraHWInterface2::IspThread::release()
5276{
Sungjoong Kangad378612012-08-17 12:34:33 -07005277 ALOGV("(%s):", __func__);
Sungjoong Kang13d8c7b2012-07-14 10:20:39 +09005278 SetSignal(SIGNAL_THREAD_RELEASE);
Sungjoong Kang13d8c7b2012-07-14 10:20:39 +09005279}
5280
5281ExynosCameraHWInterface2::StreamThread::~StreamThread()
5282{
Sungjoong Kangad378612012-08-17 12:34:33 -07005283 ALOGV("(%s):", __FUNCTION__);
Sungjoong Kang13d8c7b2012-07-14 10:20:39 +09005284}
5285
5286void ExynosCameraHWInterface2::StreamThread::setParameter(stream_parameters_t * new_parameters)
5287{
5288 ALOGV("DEBUG(%s):", __FUNCTION__);
5289
5290 m_tempParameters = new_parameters;
5291
5292 SetSignal(SIGNAL_STREAM_CHANGE_PARAMETER);
5293
5294 // TODO : return synchronously (after setting parameters asynchronously)
Sungjoong Kang9dd63e12012-07-24 00:25:51 +09005295 usleep(2000);
Sungjoong Kang13d8c7b2012-07-14 10:20:39 +09005296}
5297
5298void ExynosCameraHWInterface2::StreamThread::applyChange()
5299{
5300 memcpy(&m_parameters, m_tempParameters, sizeof(stream_parameters_t));
5301
Sungjoong Kang9dd63e12012-07-24 00:25:51 +09005302 ALOGV("DEBUG(%s): Applying Stream paremeters width(%d), height(%d)",
Sungjoong Kang13d8c7b2012-07-14 10:20:39 +09005303 __FUNCTION__, m_parameters.outputWidth, m_parameters.outputHeight);
5304}
5305
5306void ExynosCameraHWInterface2::StreamThread::release()
5307{
Sungjoong Kang9dd63e12012-07-24 00:25:51 +09005308 ALOGV("(%s):", __func__);
Sungjoong Kang13d8c7b2012-07-14 10:20:39 +09005309 SetSignal(SIGNAL_THREAD_RELEASE);
Sungjoong Kang13d8c7b2012-07-14 10:20:39 +09005310}
5311
5312int ExynosCameraHWInterface2::StreamThread::findBufferIndex(void * bufAddr)
5313{
5314 int index;
5315 for (index = 0 ; index < m_parameters.numSvcBuffers ; index++) {
5316 if (m_parameters.svcBuffers[index].virt.extP[0] == bufAddr)
5317 return index;
5318 }
5319 return -1;
Jiyoung Shinc15a6b02012-06-05 01:08:14 -07005320}
5321
Sungjoong Kang9dd63e12012-07-24 00:25:51 +09005322void ExynosCameraHWInterface2::StreamThread::setRecordingParameter(record_parameters_t * recordParm)
5323{
5324 memcpy(&m_recordParameters, recordParm, sizeof(record_parameters_t));
5325}
5326
Sungjoong Kang74d78eb2012-08-29 13:25:46 -07005327void ExynosCameraHWInterface2::StreamThread::setCallbackParameter(callback_parameters_t * callbackParm)
5328{
5329 memcpy(&m_previewCbParameters, callbackParm, sizeof(callback_parameters_t));
5330}
5331
Jiyoung Shinc15a6b02012-06-05 01:08:14 -07005332int ExynosCameraHWInterface2::createIonClient(ion_client ionClient)
5333{
5334 if (ionClient == 0) {
5335 ionClient = ion_client_create();
5336 if (ionClient < 0) {
Sungjoong Kang13d8c7b2012-07-14 10:20:39 +09005337 ALOGE("[%s]src ion client create failed, value = %d\n", __FUNCTION__, ionClient);
Jiyoung Shinc15a6b02012-06-05 01:08:14 -07005338 return 0;
5339 }
5340 }
5341
5342 return ionClient;
5343}
5344
5345int ExynosCameraHWInterface2::deleteIonClient(ion_client ionClient)
5346{
5347 if (ionClient != 0) {
5348 if (ionClient > 0) {
5349 ion_client_destroy(ionClient);
5350 }
5351 ionClient = 0;
5352 }
5353
5354 return ionClient;
5355}
5356
Sungjoong Kang13d8c7b2012-07-14 10:20:39 +09005357int ExynosCameraHWInterface2::allocCameraMemory(ion_client ionClient, ExynosBuffer *buf, int iMemoryNum)
Jiyoung Shinc15a6b02012-06-05 01:08:14 -07005358{
Sungjoong Kang181e4252012-08-29 02:11:07 -07005359 return allocCameraMemory(ionClient, buf, iMemoryNum, 0);
5360}
5361
5362int ExynosCameraHWInterface2::allocCameraMemory(ion_client ionClient, ExynosBuffer *buf, int iMemoryNum, int cacheFlag)
5363{
Jiyoung Shinc15a6b02012-06-05 01:08:14 -07005364 int ret = 0;
5365 int i = 0;
Sungjoong Kang181e4252012-08-29 02:11:07 -07005366 int flag = 0;
Jiyoung Shinc15a6b02012-06-05 01:08:14 -07005367
5368 if (ionClient == 0) {
Sungjoong Kang13d8c7b2012-07-14 10:20:39 +09005369 ALOGE("[%s] ionClient is zero (%d)\n", __FUNCTION__, ionClient);
Jiyoung Shinc15a6b02012-06-05 01:08:14 -07005370 return -1;
5371 }
5372
Sungjoong Kang181e4252012-08-29 02:11:07 -07005373 for (i = 0 ; i < iMemoryNum ; i++) {
Sungjoong Kang13d8c7b2012-07-14 10:20:39 +09005374 if (buf->size.extS[i] == 0) {
Jiyoung Shinc15a6b02012-06-05 01:08:14 -07005375 break;
5376 }
Sungjoong Kang181e4252012-08-29 02:11:07 -07005377 if (1 << i & cacheFlag)
5378 flag = ION_FLAG_CACHED;
5379 else
5380 flag = 0;
Sungjoong Kang13d8c7b2012-07-14 10:20:39 +09005381 buf->fd.extFd[i] = ion_alloc(ionClient, \
Sungjoong Kang181e4252012-08-29 02:11:07 -07005382 buf->size.extS[i], 0, ION_HEAP_EXYNOS_MASK, flag);
Sungjoong Kang13d8c7b2012-07-14 10:20:39 +09005383 if ((buf->fd.extFd[i] == -1) ||(buf->fd.extFd[i] == 0)) {
5384 ALOGE("[%s]ion_alloc(%d) failed\n", __FUNCTION__, buf->size.extS[i]);
5385 buf->fd.extFd[i] = -1;
Jiyoung Shinc15a6b02012-06-05 01:08:14 -07005386 freeCameraMemory(buf, iMemoryNum);
5387 return -1;
5388 }
5389
Sungjoong Kang13d8c7b2012-07-14 10:20:39 +09005390 buf->virt.extP[i] = (char *)ion_map(buf->fd.extFd[i], \
5391 buf->size.extS[i], 0);
5392 if ((buf->virt.extP[i] == (char *)MAP_FAILED) || (buf->virt.extP[i] == NULL)) {
5393 ALOGE("[%s]src ion map failed(%d)\n", __FUNCTION__, buf->size.extS[i]);
5394 buf->virt.extP[i] = (char *)MAP_FAILED;
Jiyoung Shinc15a6b02012-06-05 01:08:14 -07005395 freeCameraMemory(buf, iMemoryNum);
5396 return -1;
5397 }
Sungjoong Kang181e4252012-08-29 02:11:07 -07005398 ALOGV("allocCameraMem : [%d][0x%08x] size(%d) flag(%d)", i, (unsigned int)(buf->virt.extP[i]), buf->size.extS[i], flag);
Jiyoung Shinc15a6b02012-06-05 01:08:14 -07005399 }
5400
5401 return ret;
5402}
5403
Sungjoong Kang13d8c7b2012-07-14 10:20:39 +09005404void ExynosCameraHWInterface2::freeCameraMemory(ExynosBuffer *buf, int iMemoryNum)
Jiyoung Shinc15a6b02012-06-05 01:08:14 -07005405{
Sungjoong Kang13d8c7b2012-07-14 10:20:39 +09005406
Jiyoung Shinc15a6b02012-06-05 01:08:14 -07005407 int i =0 ;
Sungjoong Kang15fd8232012-08-23 16:16:44 -07005408 int ret = 0;
Jiyoung Shinc15a6b02012-06-05 01:08:14 -07005409
5410 for (i=0;i<iMemoryNum;i++) {
Sungjoong Kang13d8c7b2012-07-14 10:20:39 +09005411 if (buf->fd.extFd[i] != -1) {
5412 if (buf->virt.extP[i] != (char *)MAP_FAILED) {
Sungjoong Kang15fd8232012-08-23 16:16:44 -07005413 ret = ion_unmap(buf->virt.extP[i], buf->size.extS[i]);
5414 if (ret < 0)
5415 ALOGE("ERR(%s)", __FUNCTION__);
Jiyoung Shinc15a6b02012-06-05 01:08:14 -07005416 }
Sungjoong Kang13d8c7b2012-07-14 10:20:39 +09005417 ion_free(buf->fd.extFd[i]);
Jiyoung Shinc15a6b02012-06-05 01:08:14 -07005418 }
Sungjoong Kang13d8c7b2012-07-14 10:20:39 +09005419 buf->fd.extFd[i] = -1;
5420 buf->virt.extP[i] = (char *)MAP_FAILED;
5421 buf->size.extS[i] = 0;
Jiyoung Shinc15a6b02012-06-05 01:08:14 -07005422 }
5423}
5424
Sungjoong Kang13d8c7b2012-07-14 10:20:39 +09005425void ExynosCameraHWInterface2::initCameraMemory(ExynosBuffer *buf, int iMemoryNum)
Jiyoung Shinc15a6b02012-06-05 01:08:14 -07005426{
5427 int i =0 ;
5428 for (i=0;i<iMemoryNum;i++) {
Sungjoong Kang13d8c7b2012-07-14 10:20:39 +09005429 buf->virt.extP[i] = (char *)MAP_FAILED;
5430 buf->fd.extFd[i] = -1;
5431 buf->size.extS[i] = 0;
Jiyoung Shinc15a6b02012-06-05 01:08:14 -07005432 }
5433}
5434
5435
Sungjoong Kang13d8c7b2012-07-14 10:20:39 +09005436
5437
Sungjoong Kang9dd63e12012-07-24 00:25:51 +09005438static camera2_device_t *g_cam2_device = NULL;
Sungjoong Kangb5237e62012-07-27 07:39:05 -07005439static bool g_camera_vaild = false;
Sungjoong Kangdaa1fcd2012-08-08 11:49:43 -07005440ExynosCamera2 * g_camera2[2] = { NULL, NULL };
Jiyoung Shinc15a6b02012-06-05 01:08:14 -07005441
5442static int HAL2_camera_device_close(struct hw_device_t* device)
5443{
Sungjoong Kangad378612012-08-17 12:34:33 -07005444 ALOGV("%s: ENTER", __FUNCTION__);
Jiyoung Shinc15a6b02012-06-05 01:08:14 -07005445 if (device) {
Sungjoong Kang9dd63e12012-07-24 00:25:51 +09005446
Jiyoung Shinc15a6b02012-06-05 01:08:14 -07005447 camera2_device_t *cam_device = (camera2_device_t *)device;
Sungjoong Kangad378612012-08-17 12:34:33 -07005448 ALOGV("cam_device(0x%08x):", (unsigned int)cam_device);
5449 ALOGV("g_cam2_device(0x%08x):", (unsigned int)g_cam2_device);
Jiyoung Shinc15a6b02012-06-05 01:08:14 -07005450 delete static_cast<ExynosCameraHWInterface2 *>(cam_device->priv);
Sungjoong Kangad378612012-08-17 12:34:33 -07005451 g_cam2_device = NULL;
Jiyoung Shinc15a6b02012-06-05 01:08:14 -07005452 free(cam_device);
Sungjoong Kangb5237e62012-07-27 07:39:05 -07005453 g_camera_vaild = false;
Jiyoung Shinc15a6b02012-06-05 01:08:14 -07005454 }
Sungjoong Kang15fd8232012-08-23 16:16:44 -07005455
Sungjoong Kangad378612012-08-17 12:34:33 -07005456 ALOGV("%s: EXIT", __FUNCTION__);
Jiyoung Shinc15a6b02012-06-05 01:08:14 -07005457 return 0;
5458}
5459
5460static inline ExynosCameraHWInterface2 *obj(const struct camera2_device *dev)
5461{
5462 return reinterpret_cast<ExynosCameraHWInterface2 *>(dev->priv);
5463}
5464
5465static int HAL2_device_set_request_queue_src_ops(const struct camera2_device *dev,
5466 const camera2_request_queue_src_ops_t *request_src_ops)
5467{
Sungjoong Kang13d8c7b2012-07-14 10:20:39 +09005468 ALOGV("DEBUG(%s):", __FUNCTION__);
Jiyoung Shinc15a6b02012-06-05 01:08:14 -07005469 return obj(dev)->setRequestQueueSrcOps(request_src_ops);
5470}
5471
5472static int HAL2_device_notify_request_queue_not_empty(const struct camera2_device *dev)
5473{
Sungjoong Kang13d8c7b2012-07-14 10:20:39 +09005474 ALOGV("DEBUG(%s):", __FUNCTION__);
Jiyoung Shinc15a6b02012-06-05 01:08:14 -07005475 return obj(dev)->notifyRequestQueueNotEmpty();
5476}
5477
5478static int HAL2_device_set_frame_queue_dst_ops(const struct camera2_device *dev,
5479 const camera2_frame_queue_dst_ops_t *frame_dst_ops)
5480{
Sungjoong Kang13d8c7b2012-07-14 10:20:39 +09005481 ALOGV("DEBUG(%s):", __FUNCTION__);
Jiyoung Shinc15a6b02012-06-05 01:08:14 -07005482 return obj(dev)->setFrameQueueDstOps(frame_dst_ops);
5483}
5484
5485static int HAL2_device_get_in_progress_count(const struct camera2_device *dev)
5486{
Sungjoong Kang13d8c7b2012-07-14 10:20:39 +09005487 ALOGV("DEBUG(%s):", __FUNCTION__);
Jiyoung Shinc15a6b02012-06-05 01:08:14 -07005488 return obj(dev)->getInProgressCount();
5489}
5490
5491static int HAL2_device_flush_captures_in_progress(const struct camera2_device *dev)
5492{
Sungjoong Kang13d8c7b2012-07-14 10:20:39 +09005493 ALOGV("DEBUG(%s):", __FUNCTION__);
Jiyoung Shinc15a6b02012-06-05 01:08:14 -07005494 return obj(dev)->flushCapturesInProgress();
5495}
5496
5497static int HAL2_device_construct_default_request(const struct camera2_device *dev,
5498 int request_template, camera_metadata_t **request)
5499{
Sungjoong Kang13d8c7b2012-07-14 10:20:39 +09005500 ALOGV("DEBUG(%s):", __FUNCTION__);
Jiyoung Shinc15a6b02012-06-05 01:08:14 -07005501 return obj(dev)->constructDefaultRequest(request_template, request);
5502}
5503
5504static int HAL2_device_allocate_stream(
5505 const struct camera2_device *dev,
5506 // inputs
5507 uint32_t width,
5508 uint32_t height,
5509 int format,
5510 const camera2_stream_ops_t *stream_ops,
5511 // outputs
5512 uint32_t *stream_id,
5513 uint32_t *format_actual,
5514 uint32_t *usage,
5515 uint32_t *max_buffers)
5516{
Sungjoong Kang9dd63e12012-07-24 00:25:51 +09005517 ALOGV("(%s): ", __FUNCTION__);
Jiyoung Shinc15a6b02012-06-05 01:08:14 -07005518 return obj(dev)->allocateStream(width, height, format, stream_ops,
5519 stream_id, format_actual, usage, max_buffers);
5520}
5521
5522
5523static int HAL2_device_register_stream_buffers(const struct camera2_device *dev,
5524 uint32_t stream_id,
5525 int num_buffers,
5526 buffer_handle_t *buffers)
5527{
Sungjoong Kang13d8c7b2012-07-14 10:20:39 +09005528 ALOGV("DEBUG(%s):", __FUNCTION__);
Jiyoung Shinc15a6b02012-06-05 01:08:14 -07005529 return obj(dev)->registerStreamBuffers(stream_id, num_buffers, buffers);
5530}
5531
5532static int HAL2_device_release_stream(
5533 const struct camera2_device *dev,
5534 uint32_t stream_id)
5535{
Sungjoong Kangad378612012-08-17 12:34:33 -07005536 ALOGV("DEBUG(%s)(id: %d):", __FUNCTION__, stream_id);
Sungjoong Kangb5237e62012-07-27 07:39:05 -07005537 if (!g_camera_vaild)
5538 return 0;
Jiyoung Shinc15a6b02012-06-05 01:08:14 -07005539 return obj(dev)->releaseStream(stream_id);
5540}
5541
5542static int HAL2_device_allocate_reprocess_stream(
5543 const struct camera2_device *dev,
5544 uint32_t width,
5545 uint32_t height,
5546 uint32_t format,
5547 const camera2_stream_in_ops_t *reprocess_stream_ops,
5548 // outputs
5549 uint32_t *stream_id,
5550 uint32_t *consumer_usage,
5551 uint32_t *max_buffers)
5552{
Sungjoong Kang13d8c7b2012-07-14 10:20:39 +09005553 ALOGV("DEBUG(%s):", __FUNCTION__);
Jiyoung Shinc15a6b02012-06-05 01:08:14 -07005554 return obj(dev)->allocateReprocessStream(width, height, format, reprocess_stream_ops,
5555 stream_id, consumer_usage, max_buffers);
5556}
5557
Eino-Ville Talvala2b0421d2012-09-04 13:41:55 -07005558static int HAL2_device_allocate_reprocess_stream_from_stream(
5559 const struct camera2_device *dev,
5560 uint32_t output_stream_id,
5561 const camera2_stream_in_ops_t *reprocess_stream_ops,
5562 // outputs
5563 uint32_t *stream_id)
5564{
5565 ALOGV("DEBUG(%s):", __FUNCTION__);
5566 // Temporary stub
5567 return 0;
5568}
5569
Jiyoung Shinc15a6b02012-06-05 01:08:14 -07005570static int HAL2_device_release_reprocess_stream(
5571 const struct camera2_device *dev,
5572 uint32_t stream_id)
5573{
Sungjoong Kang13d8c7b2012-07-14 10:20:39 +09005574 ALOGV("DEBUG(%s):", __FUNCTION__);
Jiyoung Shinc15a6b02012-06-05 01:08:14 -07005575 return obj(dev)->releaseReprocessStream(stream_id);
5576}
5577
5578static int HAL2_device_trigger_action(const struct camera2_device *dev,
5579 uint32_t trigger_id,
5580 int ext1,
5581 int ext2)
5582{
Sungjoong Kang13d8c7b2012-07-14 10:20:39 +09005583 ALOGV("DEBUG(%s):", __FUNCTION__);
Jiyoung Shinc15a6b02012-06-05 01:08:14 -07005584 return obj(dev)->triggerAction(trigger_id, ext1, ext2);
5585}
5586
5587static int HAL2_device_set_notify_callback(const struct camera2_device *dev,
5588 camera2_notify_callback notify_cb,
5589 void *user)
5590{
Sungjoong Kang13d8c7b2012-07-14 10:20:39 +09005591 ALOGV("DEBUG(%s):", __FUNCTION__);
Jiyoung Shinc15a6b02012-06-05 01:08:14 -07005592 return obj(dev)->setNotifyCallback(notify_cb, user);
5593}
5594
5595static int HAL2_device_get_metadata_vendor_tag_ops(const struct camera2_device*dev,
5596 vendor_tag_query_ops_t **ops)
5597{
Sungjoong Kang13d8c7b2012-07-14 10:20:39 +09005598 ALOGV("DEBUG(%s):", __FUNCTION__);
Jiyoung Shinc15a6b02012-06-05 01:08:14 -07005599 return obj(dev)->getMetadataVendorTagOps(ops);
5600}
5601
5602static int HAL2_device_dump(const struct camera2_device *dev, int fd)
5603{
Sungjoong Kang13d8c7b2012-07-14 10:20:39 +09005604 ALOGV("DEBUG(%s):", __FUNCTION__);
Jiyoung Shinc15a6b02012-06-05 01:08:14 -07005605 return obj(dev)->dump(fd);
5606}
5607
5608
5609
5610
5611
5612static int HAL2_getNumberOfCameras()
5613{
Sungjoong Kang9dd63e12012-07-24 00:25:51 +09005614 ALOGV("(%s): returning 2", __FUNCTION__);
5615 return 2;
Jiyoung Shinc15a6b02012-06-05 01:08:14 -07005616}
5617
5618
Jiyoung Shinc15a6b02012-06-05 01:08:14 -07005619static int HAL2_getCameraInfo(int cameraId, struct camera_info *info)
5620{
Sungjoong Kangad378612012-08-17 12:34:33 -07005621 ALOGV("DEBUG(%s): cameraID: %d", __FUNCTION__, cameraId);
Sungjoong Kang9dd63e12012-07-24 00:25:51 +09005622 static camera_metadata_t * mCameraInfo[2] = {NULL, NULL};
Sungjoong Kangad378612012-08-17 12:34:33 -07005623
Jiyoung Shinc15a6b02012-06-05 01:08:14 -07005624 status_t res;
Sungjoong Kang13d8c7b2012-07-14 10:20:39 +09005625
Sungjoong Kangdaa1fcd2012-08-08 11:49:43 -07005626 if (cameraId == 0) {
Sungjoong Kang9dd63e12012-07-24 00:25:51 +09005627 info->facing = CAMERA_FACING_BACK;
Sungjoong Kangdaa1fcd2012-08-08 11:49:43 -07005628 if (!g_camera2[0])
5629 g_camera2[0] = new ExynosCamera2(0);
5630 }
5631 else if (cameraId == 1) {
Sungjoong Kang9dd63e12012-07-24 00:25:51 +09005632 info->facing = CAMERA_FACING_FRONT;
Sungjoong Kangdaa1fcd2012-08-08 11:49:43 -07005633 if (!g_camera2[1])
5634 g_camera2[1] = new ExynosCamera2(1);
5635 }
5636 else
5637 return BAD_VALUE;
5638
Jiyoung Shinc15a6b02012-06-05 01:08:14 -07005639 info->orientation = 0;
5640 info->device_version = HARDWARE_DEVICE_API_VERSION(2, 0);
Sungjoong Kang9dd63e12012-07-24 00:25:51 +09005641 if (mCameraInfo[cameraId] == NULL) {
Sungjoong Kangdaa1fcd2012-08-08 11:49:43 -07005642 res = g_camera2[cameraId]->constructStaticInfo(&(mCameraInfo[cameraId]), cameraId, true);
Jiyoung Shinc15a6b02012-06-05 01:08:14 -07005643 if (res != OK) {
5644 ALOGE("%s: Unable to allocate static info: %s (%d)",
Sungjoong Kang13d8c7b2012-07-14 10:20:39 +09005645 __FUNCTION__, strerror(-res), res);
Jiyoung Shinc15a6b02012-06-05 01:08:14 -07005646 return res;
5647 }
Sungjoong Kangdaa1fcd2012-08-08 11:49:43 -07005648 res = g_camera2[cameraId]->constructStaticInfo(&(mCameraInfo[cameraId]), cameraId, false);
Jiyoung Shinc15a6b02012-06-05 01:08:14 -07005649 if (res != OK) {
5650 ALOGE("%s: Unable to fill in static info: %s (%d)",
Sungjoong Kang13d8c7b2012-07-14 10:20:39 +09005651 __FUNCTION__, strerror(-res), res);
Jiyoung Shinc15a6b02012-06-05 01:08:14 -07005652 return res;
5653 }
5654 }
Sungjoong Kang9dd63e12012-07-24 00:25:51 +09005655 info->static_camera_characteristics = mCameraInfo[cameraId];
Sungjoong Kang13d8c7b2012-07-14 10:20:39 +09005656 return NO_ERROR;
Jiyoung Shinc15a6b02012-06-05 01:08:14 -07005657}
5658
5659#define SET_METHOD(m) m : HAL2_device_##m
5660
5661static camera2_device_ops_t camera2_device_ops = {
5662 SET_METHOD(set_request_queue_src_ops),
5663 SET_METHOD(notify_request_queue_not_empty),
5664 SET_METHOD(set_frame_queue_dst_ops),
5665 SET_METHOD(get_in_progress_count),
5666 SET_METHOD(flush_captures_in_progress),
5667 SET_METHOD(construct_default_request),
5668 SET_METHOD(allocate_stream),
5669 SET_METHOD(register_stream_buffers),
5670 SET_METHOD(release_stream),
5671 SET_METHOD(allocate_reprocess_stream),
Eino-Ville Talvala2b0421d2012-09-04 13:41:55 -07005672 SET_METHOD(allocate_reprocess_stream_from_stream),
Jiyoung Shinc15a6b02012-06-05 01:08:14 -07005673 SET_METHOD(release_reprocess_stream),
5674 SET_METHOD(trigger_action),
5675 SET_METHOD(set_notify_callback),
5676 SET_METHOD(get_metadata_vendor_tag_ops),
5677 SET_METHOD(dump),
5678};
5679
5680#undef SET_METHOD
5681
5682
5683static int HAL2_camera_device_open(const struct hw_module_t* module,
5684 const char *id,
5685 struct hw_device_t** device)
5686{
Sungjoong Kang9dd63e12012-07-24 00:25:51 +09005687
Jiyoung Shinc15a6b02012-06-05 01:08:14 -07005688
5689 int cameraId = atoi(id);
Sungjoong Kang6044e502012-08-27 00:29:28 -07005690 int openInvalid = 0;
Sungjoong Kang9dd63e12012-07-24 00:25:51 +09005691
Sungjoong Kangb5237e62012-07-27 07:39:05 -07005692 g_camera_vaild = false;
Sungjoong Kangad378612012-08-17 12:34:33 -07005693 ALOGV("\n\n>>> I'm Samsung's CameraHAL_2(ID:%d) <<<\n\n", cameraId);
Jiyoung Shinc15a6b02012-06-05 01:08:14 -07005694 if (cameraId < 0 || cameraId >= HAL2_getNumberOfCameras()) {
Sungjoong Kang13d8c7b2012-07-14 10:20:39 +09005695 ALOGE("ERR(%s):Invalid camera ID %s", __FUNCTION__, id);
Jiyoung Shinc15a6b02012-06-05 01:08:14 -07005696 return -EINVAL;
5697 }
5698
Sungjoong Kangad378612012-08-17 12:34:33 -07005699 ALOGV("g_cam2_device : 0x%08x", (unsigned int)g_cam2_device);
Jiyoung Shinc15a6b02012-06-05 01:08:14 -07005700 if (g_cam2_device) {
5701 if (obj(g_cam2_device)->getCameraId() == cameraId) {
Sungjoong Kang13d8c7b2012-07-14 10:20:39 +09005702 ALOGV("DEBUG(%s):returning existing camera ID %s", __FUNCTION__, id);
Jiyoung Shinc15a6b02012-06-05 01:08:14 -07005703 goto done;
5704 } else {
Sungjoong Kang9dd63e12012-07-24 00:25:51 +09005705
5706 while (g_cam2_device)
5707 usleep(10000);
Jiyoung Shinc15a6b02012-06-05 01:08:14 -07005708 }
5709 }
5710
5711 g_cam2_device = (camera2_device_t *)malloc(sizeof(camera2_device_t));
Sungjoong Kangad378612012-08-17 12:34:33 -07005712 ALOGV("g_cam2_device : 0x%08x", (unsigned int)g_cam2_device);
Sungjoong Kang9dd63e12012-07-24 00:25:51 +09005713
Jiyoung Shinc15a6b02012-06-05 01:08:14 -07005714 if (!g_cam2_device)
5715 return -ENOMEM;
5716
5717 g_cam2_device->common.tag = HARDWARE_DEVICE_TAG;
5718 g_cam2_device->common.version = CAMERA_DEVICE_API_VERSION_2_0;
5719 g_cam2_device->common.module = const_cast<hw_module_t *>(module);
5720 g_cam2_device->common.close = HAL2_camera_device_close;
5721
5722 g_cam2_device->ops = &camera2_device_ops;
5723
Sungjoong Kang13d8c7b2012-07-14 10:20:39 +09005724 ALOGV("DEBUG(%s):open camera2 %s", __FUNCTION__, id);
Jiyoung Shinc15a6b02012-06-05 01:08:14 -07005725
Sungjoong Kang6044e502012-08-27 00:29:28 -07005726 g_cam2_device->priv = new ExynosCameraHWInterface2(cameraId, g_cam2_device, g_camera2[cameraId], &openInvalid);
5727 if (!openInvalid) {
5728 ALOGE("DEBUG(%s): ExynosCameraHWInterface2 creation failed(%d)", __FUNCTION__);
Younghwan Joo6f19b6c2012-08-30 13:56:53 -07005729 return -ENODEV;
Sungjoong Kang6044e502012-08-27 00:29:28 -07005730 }
Jiyoung Shinc15a6b02012-06-05 01:08:14 -07005731done:
5732 *device = (hw_device_t *)g_cam2_device;
Sungjoong Kang13d8c7b2012-07-14 10:20:39 +09005733 ALOGV("DEBUG(%s):opened camera2 %s (%p)", __FUNCTION__, id, *device);
Sungjoong Kangb5237e62012-07-27 07:39:05 -07005734 g_camera_vaild = true;
Jiyoung Shinc15a6b02012-06-05 01:08:14 -07005735
5736 return 0;
5737}
5738
5739
5740static hw_module_methods_t camera_module_methods = {
5741 open : HAL2_camera_device_open
5742};
5743
5744extern "C" {
5745 struct camera_module HAL_MODULE_INFO_SYM = {
5746 common : {
5747 tag : HARDWARE_MODULE_TAG,
5748 module_api_version : CAMERA_MODULE_API_VERSION_2_0,
5749 hal_api_version : HARDWARE_HAL_API_VERSION,
5750 id : CAMERA_HARDWARE_MODULE_ID,
5751 name : "Exynos Camera HAL2",
5752 author : "Samsung Corporation",
5753 methods : &camera_module_methods,
5754 dso: NULL,
5755 reserved: {0},
5756 },
5757 get_number_of_cameras : HAL2_getNumberOfCameras,
5758 get_camera_info : HAL2_getCameraInfo
5759 };
5760}
5761
5762}; // namespace android