blob: 0e94cc28c1524379fb0653caefcb2074206d8df0 [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)) {
Sungjoong Kangad378612012-08-17 12:34:33 -0700447 ALOGD("## 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),
Younghwan Joo6f19b6c2012-08-30 13:56:53 -0700860 m_afFlashEnableFlg(false),
Sungjoong Kang2d5e6ec2012-08-30 15:14:17 +0900861 m_cameraId(cameraId),
862 m_thumbNailW(160),
863 m_thumbNailH(120)
Jiyoung Shinc15a6b02012-06-05 01:08:14 -0700864{
Sungjoong Kang13d8c7b2012-07-14 10:20:39 +0900865 ALOGV("DEBUG(%s):", __FUNCTION__);
Jiyoung Shinc15a6b02012-06-05 01:08:14 -0700866 int ret = 0;
Sungjoong Kang6044e502012-08-27 00:29:28 -0700867 int res = 0;
Jiyoung Shinc15a6b02012-06-05 01:08:14 -0700868
Sungjoong Kang13d8c7b2012-07-14 10:20:39 +0900869 m_exynosPictureCSC = NULL;
Sungjoong Kang9dd63e12012-07-24 00:25:51 +0900870 m_exynosVideoCSC = NULL;
Sungjoong Kang13d8c7b2012-07-14 10:20:39 +0900871
Jiyoung Shinc15a6b02012-06-05 01:08:14 -0700872 if (!m_grallocHal) {
873 ret = hw_get_module(GRALLOC_HARDWARE_MODULE_ID, (const hw_module_t **)&m_grallocHal);
874 if (ret)
Sungjoong Kang13d8c7b2012-07-14 10:20:39 +0900875 ALOGE("ERR(%s):Fail on loading gralloc HAL", __FUNCTION__);
876 }
Jiyoung Shinc15a6b02012-06-05 01:08:14 -0700877
Sungjoong Kangdaa1fcd2012-08-08 11:49:43 -0700878 m_camera2 = camera;
Jiyoung Shinc15a6b02012-06-05 01:08:14 -0700879 m_ionCameraClient = createIonClient(m_ionCameraClient);
880 if(m_ionCameraClient == 0)
Sungjoong Kang13d8c7b2012-07-14 10:20:39 +0900881 ALOGE("ERR(%s):Fail on ion_client_create", __FUNCTION__);
Jiyoung Shinc15a6b02012-06-05 01:08:14 -0700882
Sungjoong Kang9dd63e12012-07-24 00:25:51 +0900883
884 m_BayerManager = new BayerBufManager();
Jiyoung Shinc15a6b02012-06-05 01:08:14 -0700885 m_mainThread = new MainThread(this);
Sungjoong Kang6044e502012-08-27 00:29:28 -0700886 *openInvalid = InitializeISPChain();
887 if (*openInvalid < 0) {
888 // clean process
889 // 1. close video nodes
890 // SCP
891 res = exynos_v4l2_close(m_fd_scp);
892 if (res != NO_ERROR ) {
893 ALOGE("ERR(%s): exynos_v4l2_close failed(%d)",__FUNCTION__ , res);
894 }
895 // SCC
896 res = exynos_v4l2_close(m_camera_info.capture.fd);
897 if (res != NO_ERROR ) {
898 ALOGE("ERR(%s): exynos_v4l2_close failed(%d)",__FUNCTION__ , res);
899 }
900 // Sensor
901 res = exynos_v4l2_close(m_camera_info.sensor.fd);
902 if (res != NO_ERROR ) {
903 ALOGE("ERR(%s): exynos_v4l2_close failed(%d)",__FUNCTION__ , res);
904 }
905 // ISP
906 res = exynos_v4l2_close(m_camera_info.isp.fd);
907 if (res != NO_ERROR ) {
908 ALOGE("ERR(%s): exynos_v4l2_close failed(%d)",__FUNCTION__ , res);
909 }
910 } else {
911 m_sensorThread = new SensorThread(this);
912 m_mainThread->Start("MainThread", PRIORITY_DEFAULT, 0);
913 ALOGV("DEBUG(%s): created sensorthread ################", __FUNCTION__);
914 m_requestManager = new RequestManager((SignalDrivenThread*)(m_mainThread.get()));
915 CSC_METHOD cscMethod = CSC_METHOD_HW;
916 m_exynosPictureCSC = csc_init(cscMethod);
917 if (m_exynosPictureCSC == NULL)
918 ALOGE("ERR(%s): csc_init() fail", __FUNCTION__);
919 csc_set_hw_property(m_exynosPictureCSC, CSC_HW_PROPERTY_FIXED_NODE, PICTURE_GSC_NODE_NUM);
Jiyoung Shinc15a6b02012-06-05 01:08:14 -0700920
Sungjoong Kang6044e502012-08-27 00:29:28 -0700921 m_exynosVideoCSC = csc_init(cscMethod);
922 if (m_exynosVideoCSC == NULL)
923 ALOGE("ERR(%s): csc_init() fail", __FUNCTION__);
924 csc_set_hw_property(m_exynosVideoCSC, CSC_HW_PROPERTY_FIXED_NODE, VIDEO_GSC_NODE_NUM);
Sungjoong Kang13d8c7b2012-07-14 10:20:39 +0900925
Sungjoong Kang6044e502012-08-27 00:29:28 -0700926 m_setExifFixedAttribute();
927 }
Jiyoung Shinc15a6b02012-06-05 01:08:14 -0700928}
929
930ExynosCameraHWInterface2::~ExynosCameraHWInterface2()
931{
Sungjoong Kangad378612012-08-17 12:34:33 -0700932 ALOGV("%s: ENTER", __FUNCTION__);
Jiyoung Shinc15a6b02012-06-05 01:08:14 -0700933 this->release();
Sungjoong Kangad378612012-08-17 12:34:33 -0700934 ALOGV("%s: EXIT", __FUNCTION__);
Jiyoung Shinc15a6b02012-06-05 01:08:14 -0700935}
936
937void ExynosCameraHWInterface2::release()
938{
Sungjoong Kang13d8c7b2012-07-14 10:20:39 +0900939 int i, res;
Sungjoong Kang9dd63e12012-07-24 00:25:51 +0900940 ALOGD("%s: ENTER", __func__);
Sungjoong Kang13d8c7b2012-07-14 10:20:39 +0900941 m_closing = true;
Sungjoong Kang9dd63e12012-07-24 00:25:51 +0900942
Sungjoong Kangad378612012-08-17 12:34:33 -0700943 if (m_streamThreads[1] != NULL) {
944 m_streamThreads[1]->release();
945 m_streamThreads[1]->SetSignal(SIGNAL_THREAD_TERMINATE);
946 }
947
948 if (m_streamThreads[0] != NULL) {
949 m_streamThreads[0]->release();
950 m_streamThreads[0]->SetSignal(SIGNAL_THREAD_TERMINATE);
951 }
952
Sungjoong Kang13d8c7b2012-07-14 10:20:39 +0900953 if (m_ispThread != NULL) {
954 m_ispThread->release();
Sungjoong Kang13d8c7b2012-07-14 10:20:39 +0900955 }
956
957 if (m_sensorThread != NULL) {
958 m_sensorThread->release();
Sungjoong Kang13d8c7b2012-07-14 10:20:39 +0900959 }
Jiyoung Shinc15a6b02012-06-05 01:08:14 -0700960
961 if (m_mainThread != NULL) {
Sungjoong Kang13d8c7b2012-07-14 10:20:39 +0900962 m_mainThread->release();
Jiyoung Shinc15a6b02012-06-05 01:08:14 -0700963 }
Jiyoung Shinc15a6b02012-06-05 01:08:14 -0700964
Sungjoong Kang13d8c7b2012-07-14 10:20:39 +0900965 if (m_exynosPictureCSC)
966 csc_deinit(m_exynosPictureCSC);
967 m_exynosPictureCSC = NULL;
968
Sungjoong Kang9dd63e12012-07-24 00:25:51 +0900969 if (m_exynosVideoCSC)
970 csc_deinit(m_exynosVideoCSC);
971 m_exynosVideoCSC = NULL;
972
Sungjoong Kangad378612012-08-17 12:34:33 -0700973 if (m_streamThreads[1] != NULL) {
974 while (!m_streamThreads[1]->IsTerminated())
975 {
976 ALOGD("Waiting for ISP thread is tetminated");
977 usleep(100000);
978 }
979 m_streamThreads[1] = NULL;
980 }
981
982 if (m_streamThreads[0] != NULL) {
983 while (!m_streamThreads[0]->IsTerminated())
984 {
985 ALOGD("Waiting for sensor thread is tetminated");
986 usleep(100000);
987 }
988 m_streamThreads[0] = NULL;
989 }
990
Sungjoong Kang9dd63e12012-07-24 00:25:51 +0900991 if (m_ispThread != NULL) {
992 while (!m_ispThread->IsTerminated())
Sungjoong Kangad378612012-08-17 12:34:33 -0700993 {
994 ALOGD("Waiting for isp thread is tetminated");
995 usleep(100000);
996 }
Sungjoong Kang9dd63e12012-07-24 00:25:51 +0900997 m_ispThread = NULL;
998 }
999
1000 if (m_sensorThread != NULL) {
1001 while (!m_sensorThread->IsTerminated())
Sungjoong Kangad378612012-08-17 12:34:33 -07001002 {
1003 ALOGD("Waiting for sensor thread is tetminated");
1004 usleep(100000);
1005 }
Sungjoong Kang9dd63e12012-07-24 00:25:51 +09001006 m_sensorThread = NULL;
1007 }
1008
Sungjoong Kangad378612012-08-17 12:34:33 -07001009 if (m_mainThread != NULL) {
Sungjoong Kang9dd63e12012-07-24 00:25:51 +09001010 while (!m_mainThread->IsTerminated())
Sungjoong Kangad378612012-08-17 12:34:33 -07001011 {
1012 ALOGD("Waiting for main thread is tetminated");
1013 usleep(100000);
1014 }
Sungjoong Kang9dd63e12012-07-24 00:25:51 +09001015 m_mainThread = NULL;
1016 }
1017
Sungjoong Kang15fd8232012-08-23 16:16:44 -07001018 if (m_requestManager != NULL) {
1019 delete m_requestManager;
1020 m_requestManager = NULL;
1021 }
1022
1023 if (m_BayerManager != NULL) {
1024 delete m_BayerManager;
1025 m_BayerManager = NULL;
1026 }
1027// for(i = 0; i < m_camera_info.sensor.buffers; i++)
1028 for (i = 0; i < NUM_BAYER_BUFFERS; i++)
Jiyoung Shinc15a6b02012-06-05 01:08:14 -07001029 freeCameraMemory(&m_camera_info.sensor.buffer[i], m_camera_info.sensor.planes);
1030
Jiyoung Shinc15a6b02012-06-05 01:08:14 -07001031 for(i = 0; i < m_camera_info.capture.buffers; i++)
1032 freeCameraMemory(&m_camera_info.capture.buffer[i], m_camera_info.capture.planes);
1033
Sungjoong Kang9dd63e12012-07-24 00:25:51 +09001034 ALOGV("DEBUG(%s): calling exynos_v4l2_close - sensor", __FUNCTION__);
Sungjoong Kang13d8c7b2012-07-14 10:20:39 +09001035 res = exynos_v4l2_close(m_camera_info.sensor.fd);
1036 if (res != NO_ERROR ) {
Sungjoong Kang9dd63e12012-07-24 00:25:51 +09001037 ALOGE("ERR(%s): exynos_v4l2_close failed(%d)",__FUNCTION__ , res);
Sungjoong Kang13d8c7b2012-07-14 10:20:39 +09001038 }
1039
Sungjoong Kang9dd63e12012-07-24 00:25:51 +09001040 ALOGV("DEBUG(%s): calling exynos_v4l2_close - isp", __FUNCTION__);
Sungjoong Kang13d8c7b2012-07-14 10:20:39 +09001041 res = exynos_v4l2_close(m_camera_info.isp.fd);
1042 if (res != NO_ERROR ) {
Sungjoong Kang9dd63e12012-07-24 00:25:51 +09001043 ALOGE("ERR(%s): exynos_v4l2_close failed(%d)",__FUNCTION__ , res);
Sungjoong Kang13d8c7b2012-07-14 10:20:39 +09001044 }
1045
Sungjoong Kang9dd63e12012-07-24 00:25:51 +09001046 ALOGV("DEBUG(%s): calling exynos_v4l2_close - capture", __FUNCTION__);
Sungjoong Kang13d8c7b2012-07-14 10:20:39 +09001047 res = exynos_v4l2_close(m_camera_info.capture.fd);
1048 if (res != NO_ERROR ) {
Sungjoong Kang9dd63e12012-07-24 00:25:51 +09001049 ALOGE("ERR(%s): exynos_v4l2_close failed(%d)",__FUNCTION__ , res);
Sungjoong Kang13d8c7b2012-07-14 10:20:39 +09001050 }
1051
Sungjoong Kang9dd63e12012-07-24 00:25:51 +09001052 ALOGV("DEBUG(%s): calling exynos_v4l2_close - scp", __FUNCTION__);
Sungjoong Kangad378612012-08-17 12:34:33 -07001053 res = exynos_v4l2_close(m_fd_scp);
Sungjoong Kang13d8c7b2012-07-14 10:20:39 +09001054 if (res != NO_ERROR ) {
Sungjoong Kang9dd63e12012-07-24 00:25:51 +09001055 ALOGE("ERR(%s): exynos_v4l2_close failed(%d)",__FUNCTION__ , res);
Sungjoong Kang13d8c7b2012-07-14 10:20:39 +09001056 }
Sungjoong Kang9dd63e12012-07-24 00:25:51 +09001057 ALOGV("DEBUG(%s): calling deleteIonClient", __FUNCTION__);
Jiyoung Shinc15a6b02012-06-05 01:08:14 -07001058 deleteIonClient(m_ionCameraClient);
Sungjoong Kangad378612012-08-17 12:34:33 -07001059
1060 ALOGV("%s: EXIT", __func__);
1061}
1062
Sungjoong Kang6044e502012-08-27 00:29:28 -07001063int ExynosCameraHWInterface2::InitializeISPChain()
Sungjoong Kangad378612012-08-17 12:34:33 -07001064{
1065 char node_name[30];
1066 int fd = 0;
1067 int i;
Sungjoong Kang6044e502012-08-27 00:29:28 -07001068 int ret = 0;
Sungjoong Kangad378612012-08-17 12:34:33 -07001069
1070 /* Open Sensor */
1071 memset(&node_name, 0x00, sizeof(char[30]));
1072 sprintf(node_name, "%s%d", NODE_PREFIX, 40);
1073 fd = exynos_v4l2_open(node_name, O_RDWR, 0);
1074
1075 if (fd < 0) {
1076 ALOGE("ERR(%s): failed to open sensor video node (%s) fd (%d)", __FUNCTION__,node_name, fd);
1077 }
1078 else {
1079 ALOGV("DEBUG(%s): sensor video node opened(%s) fd (%d)", __FUNCTION__,node_name, fd);
1080 }
1081 m_camera_info.sensor.fd = fd;
1082
1083 /* Open ISP */
1084 memset(&node_name, 0x00, sizeof(char[30]));
1085 sprintf(node_name, "%s%d", NODE_PREFIX, 41);
1086 fd = exynos_v4l2_open(node_name, O_RDWR, 0);
1087
1088 if (fd < 0) {
1089 ALOGE("ERR(%s): failed to open isp video node (%s) fd (%d)", __FUNCTION__,node_name, fd);
1090 }
1091 else {
1092 ALOGV("DEBUG(%s): isp video node opened(%s) fd (%d)", __FUNCTION__,node_name, fd);
1093 }
1094 m_camera_info.isp.fd = fd;
1095
1096 /* Open ScalerC */
1097 memset(&node_name, 0x00, sizeof(char[30]));
1098 sprintf(node_name, "%s%d", NODE_PREFIX, 42);
1099 fd = exynos_v4l2_open(node_name, O_RDWR, 0);
1100
1101 if (fd < 0) {
1102 ALOGE("ERR(%s): failed to open capture video node (%s) fd (%d)", __FUNCTION__,node_name, fd);
1103 }
1104 else {
1105 ALOGV("DEBUG(%s): capture video node opened(%s) fd (%d)", __FUNCTION__,node_name, fd);
1106 }
1107 m_camera_info.capture.fd = fd;
1108
1109 /* Open ScalerP */
1110 memset(&node_name, 0x00, sizeof(char[30]));
1111 sprintf(node_name, "%s%d", NODE_PREFIX, 44);
1112 fd = exynos_v4l2_open(node_name, O_RDWR, 0);
1113 if (fd < 0) {
1114 ALOGE("DEBUG(%s): failed to open preview video node (%s) fd (%d)", __FUNCTION__,node_name, fd);
1115 }
1116 else {
1117 ALOGV("DEBUG(%s): preview video node opened(%s) fd (%d)", __FUNCTION__,node_name, fd);
1118 }
1119 m_fd_scp = fd;
1120
1121 if(m_cameraId == 0)
1122 m_camera_info.sensor_id = SENSOR_NAME_S5K4E5;
1123 else
1124 m_camera_info.sensor_id = SENSOR_NAME_S5K6A3;
1125
1126 memset(&m_camera_info.dummy_shot, 0x00, sizeof(struct camera2_shot_ext));
1127 m_camera_info.dummy_shot.shot.ctl.request.metadataMode = METADATA_MODE_FULL;
1128 m_camera_info.dummy_shot.shot.magicNumber = 0x23456789;
1129
1130 m_camera_info.dummy_shot.dis_bypass = 1;
1131 m_camera_info.dummy_shot.dnr_bypass = 1;
1132 m_camera_info.dummy_shot.fd_bypass = 1;
1133
1134 /*sensor setting*/
1135 m_camera_info.dummy_shot.shot.ctl.sensor.exposureTime = 0;
1136 m_camera_info.dummy_shot.shot.ctl.sensor.frameDuration = 0;
1137 m_camera_info.dummy_shot.shot.ctl.sensor.sensitivity = 0;
1138
1139 m_camera_info.dummy_shot.shot.ctl.scaler.cropRegion[0] = 0;
1140 m_camera_info.dummy_shot.shot.ctl.scaler.cropRegion[1] = 0;
1141
1142 /*request setting*/
1143 m_camera_info.dummy_shot.request_sensor = 1;
1144 m_camera_info.dummy_shot.request_scc = 0;
1145 m_camera_info.dummy_shot.request_scp = 0;
1146 m_camera_info.dummy_shot.shot.ctl.request.outputStreams[0] = 0;
1147 m_camera_info.dummy_shot.shot.ctl.request.outputStreams[1] = 0;
1148 m_camera_info.dummy_shot.shot.ctl.request.outputStreams[2] = 0;
Sungjoong Kang74d78eb2012-08-29 13:25:46 -07001149 m_camera_info.dummy_shot.shot.ctl.request.outputStreams[3] = 0;
Sungjoong Kangad378612012-08-17 12:34:33 -07001150
1151 m_camera_info.sensor.width = m_camera2->getSensorRawW();
1152 m_camera_info.sensor.height = m_camera2->getSensorRawH();
1153
1154 m_camera_info.sensor.format = V4L2_PIX_FMT_SBGGR16;
1155 m_camera_info.sensor.planes = 2;
1156 m_camera_info.sensor.buffers = NUM_BAYER_BUFFERS;
1157 m_camera_info.sensor.type = V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE;
1158 m_camera_info.sensor.memory = V4L2_MEMORY_DMABUF;
1159 m_camera_info.sensor.ionClient = m_ionCameraClient;
1160
1161 for(i = 0; i < m_camera_info.sensor.buffers; i++){
1162 initCameraMemory(&m_camera_info.sensor.buffer[i], m_camera_info.sensor.planes);
1163 m_camera_info.sensor.buffer[i].size.extS[0] = m_camera_info.sensor.width*m_camera_info.sensor.height*2;
1164 m_camera_info.sensor.buffer[i].size.extS[1] = 8*1024; // HACK, driver use 8*1024, should be use predefined value
1165 allocCameraMemory(m_camera_info.sensor.ionClient, &m_camera_info.sensor.buffer[i], m_camera_info.sensor.planes);
1166 }
1167
1168 m_camera_info.isp.width = m_camera_info.sensor.width;
1169 m_camera_info.isp.height = m_camera_info.sensor.height;
1170 m_camera_info.isp.format = m_camera_info.sensor.format;
1171 m_camera_info.isp.planes = m_camera_info.sensor.planes;
1172 m_camera_info.isp.buffers = m_camera_info.sensor.buffers;
1173 m_camera_info.isp.type = V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE;
1174 m_camera_info.isp.memory = V4L2_MEMORY_DMABUF;
1175 m_camera_info.isp.ionClient = m_ionCameraClient;
1176
1177 for(i = 0; i < m_camera_info.isp.buffers; i++){
1178 initCameraMemory(&m_camera_info.isp.buffer[i], m_camera_info.isp.planes);
1179 m_camera_info.isp.buffer[i].size.extS[0] = m_camera_info.sensor.buffer[i].size.extS[0];
1180 m_camera_info.isp.buffer[i].size.extS[1] = m_camera_info.sensor.buffer[i].size.extS[1];
1181 m_camera_info.isp.buffer[i].fd.extFd[0] = m_camera_info.sensor.buffer[i].fd.extFd[0];
1182 m_camera_info.isp.buffer[i].fd.extFd[1] = m_camera_info.sensor.buffer[i].fd.extFd[1];
1183 m_camera_info.isp.buffer[i].virt.extP[0] = m_camera_info.sensor.buffer[i].virt.extP[0];
1184 m_camera_info.isp.buffer[i].virt.extP[1] = m_camera_info.sensor.buffer[i].virt.extP[1];
1185 };
1186
1187 /* init ISP */
Sungjoong Kang6044e502012-08-27 00:29:28 -07001188 ret = cam_int_s_input(&(m_camera_info.isp), m_camera_info.sensor_id);
1189 if (ret < 0) {
1190 ALOGE("ERR(%s): cam_int_s_input(%d) failed!!!! ", __FUNCTION__, m_camera_info.sensor_id);
1191 return false;
1192 }
Sungjoong Kangad378612012-08-17 12:34:33 -07001193 cam_int_s_fmt(&(m_camera_info.isp));
1194 ALOGV("DEBUG(%s): isp calling reqbuf", __FUNCTION__);
1195 cam_int_reqbufs(&(m_camera_info.isp));
1196 ALOGV("DEBUG(%s): isp calling querybuf", __FUNCTION__);
1197 ALOGV("DEBUG(%s): isp mem alloc done", __FUNCTION__);
1198
1199 /* init Sensor */
1200 cam_int_s_input(&(m_camera_info.sensor), m_camera_info.sensor_id);
1201 ALOGV("DEBUG(%s): sensor s_input done", __FUNCTION__);
1202 if (cam_int_s_fmt(&(m_camera_info.sensor))< 0) {
1203 ALOGE("ERR(%s): sensor s_fmt fail", __FUNCTION__);
1204 }
1205 ALOGV("DEBUG(%s): sensor s_fmt done", __FUNCTION__);
1206 cam_int_reqbufs(&(m_camera_info.sensor));
1207 ALOGV("DEBUG(%s): sensor reqbuf done", __FUNCTION__);
1208 for (i = 0; i < m_camera_info.sensor.buffers; i++) {
1209 ALOGV("DEBUG(%s): sensor initial QBUF [%d]", __FUNCTION__, i);
1210 memcpy( m_camera_info.sensor.buffer[i].virt.extP[1], &(m_camera_info.dummy_shot),
1211 sizeof(struct camera2_shot_ext));
1212 m_camera_info.dummy_shot.shot.ctl.sensor.frameDuration = 33*1000*1000; // apply from frame #1
1213 m_camera_info.dummy_shot.shot.ctl.request.frameCount = -1;
1214 cam_int_qbuf(&(m_camera_info.sensor), i);
1215 }
1216 ALOGV("== stream_on :: .sensor");
1217 cam_int_streamon(&(m_camera_info.sensor));
1218
1219 /* init Capture */
1220 m_camera_info.capture.width = m_camera2->getSensorW();
1221 m_camera_info.capture.height = m_camera2->getSensorH();
1222 m_camera_info.capture.format = V4L2_PIX_FMT_YUYV;
Sungjoong Kangfeb7df42012-08-28 23:35:43 +09001223#ifdef ENABLE_FRAME_SYNC
1224 m_camera_info.capture.planes = 2;
1225#else
Sungjoong Kangad378612012-08-17 12:34:33 -07001226 m_camera_info.capture.planes = 1;
Sungjoong Kangfeb7df42012-08-28 23:35:43 +09001227#endif
Sungjoong Kangad378612012-08-17 12:34:33 -07001228 m_camera_info.capture.buffers = 8;
1229 m_camera_info.capture.type = V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE;
1230 m_camera_info.capture.memory = V4L2_MEMORY_DMABUF;
1231 m_camera_info.capture.ionClient = m_ionCameraClient;
1232
1233 for(i = 0; i < m_camera_info.capture.buffers; i++){
1234 initCameraMemory(&m_camera_info.capture.buffer[i], m_camera_info.capture.planes);
1235 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 +09001236#ifdef ENABLE_FRAME_SYNC
1237 m_camera_info.capture.buffer[i].size.extS[1] = 4*1024; // HACK, driver use 4*1024, should be use predefined value
1238#endif
Sungjoong Kangad378612012-08-17 12:34:33 -07001239 allocCameraMemory(m_camera_info.capture.ionClient, &m_camera_info.capture.buffer[i], m_camera_info.capture.planes);
1240 }
1241
1242 cam_int_s_input(&(m_camera_info.capture), m_camera_info.sensor_id);
1243 cam_int_s_fmt(&(m_camera_info.capture));
1244 ALOGV("DEBUG(%s): capture calling reqbuf", __FUNCTION__);
1245 cam_int_reqbufs(&(m_camera_info.capture));
1246 ALOGV("DEBUG(%s): capture calling querybuf", __FUNCTION__);
1247
1248 for (i = 0; i < m_camera_info.capture.buffers; i++) {
1249 ALOGV("DEBUG(%s): capture initial QBUF [%d]", __FUNCTION__, i);
1250 cam_int_qbuf(&(m_camera_info.capture), i);
1251 }
1252
1253 ALOGV("== stream_on :: capture");
Sungjoong Kang15fd8232012-08-23 16:16:44 -07001254 if (cam_int_streamon(&(m_camera_info.capture)) < 0) {
1255 ALOGE("ERR(%s): capture stream on fail", __FUNCTION__);
1256 } else {
1257 m_camera_info.capture.status = true;
1258 }
Sungjoong Kang6044e502012-08-27 00:29:28 -07001259
1260 return true;
Sungjoong Kangad378612012-08-17 12:34:33 -07001261}
1262
1263void ExynosCameraHWInterface2::StartISP()
1264{
Sungjoong Kangad378612012-08-17 12:34:33 -07001265 ALOGV("== stream_on :: isp");
1266 cam_int_streamon(&(m_camera_info.isp));
Sungjoong Kangad378612012-08-17 12:34:33 -07001267 exynos_v4l2_s_ctrl(m_camera_info.sensor.fd, V4L2_CID_IS_S_STREAM, IS_ENABLE_STREAM);
Sungjoong Kang13d8c7b2012-07-14 10:20:39 +09001268}
1269
Jiyoung Shinc15a6b02012-06-05 01:08:14 -07001270int ExynosCameraHWInterface2::getCameraId() const
1271{
Sungjoong Kang9dd63e12012-07-24 00:25:51 +09001272 return m_cameraId;
Jiyoung Shinc15a6b02012-06-05 01:08:14 -07001273}
Jiyoung Shinc15a6b02012-06-05 01:08:14 -07001274
1275int ExynosCameraHWInterface2::setRequestQueueSrcOps(const camera2_request_queue_src_ops_t *request_src_ops)
1276{
Sungjoong Kang13d8c7b2012-07-14 10:20:39 +09001277 ALOGV("DEBUG(%s):", __FUNCTION__);
Jiyoung Shinc15a6b02012-06-05 01:08:14 -07001278 if ((NULL != request_src_ops) && (NULL != request_src_ops->dequeue_request)
1279 && (NULL != request_src_ops->free_request) && (NULL != request_src_ops->request_count)) {
1280 m_requestQueueOps = (camera2_request_queue_src_ops_t*)request_src_ops;
1281 return 0;
1282 }
1283 else {
Sungjoong Kang13d8c7b2012-07-14 10:20:39 +09001284 ALOGE("DEBUG(%s):setRequestQueueSrcOps : NULL arguments", __FUNCTION__);
Jiyoung Shinc15a6b02012-06-05 01:08:14 -07001285 return 1;
1286 }
1287}
1288
1289int ExynosCameraHWInterface2::notifyRequestQueueNotEmpty()
1290{
Sungjoong Kangb5237e62012-07-27 07:39:05 -07001291 ALOGV("DEBUG(%s):setting [SIGNAL_MAIN_REQ_Q_NOT_EMPTY] current(%d)", __FUNCTION__, m_requestManager->GetNumEntries());
Jiyoung Shinc15a6b02012-06-05 01:08:14 -07001292 if ((NULL==m_frameQueueOps)|| (NULL==m_requestQueueOps)) {
Sungjoong Kang13d8c7b2012-07-14 10:20:39 +09001293 ALOGE("DEBUG(%s):queue ops NULL. ignoring request", __FUNCTION__);
Jiyoung Shinc15a6b02012-06-05 01:08:14 -07001294 return 0;
1295 }
Sungjoong Kang13d8c7b2012-07-14 10:20:39 +09001296 m_isRequestQueueNull = false;
Sungjoong Kang0f26b202012-08-17 15:43:12 -07001297 if (m_requestManager->GetNumEntries() == 0)
1298 m_requestManager->SetInitialSkip(5);
Jiyoung Shinc15a6b02012-06-05 01:08:14 -07001299 m_mainThread->SetSignal(SIGNAL_MAIN_REQ_Q_NOT_EMPTY);
1300 return 0;
1301}
1302
1303int ExynosCameraHWInterface2::setFrameQueueDstOps(const camera2_frame_queue_dst_ops_t *frame_dst_ops)
1304{
Sungjoong Kang13d8c7b2012-07-14 10:20:39 +09001305 ALOGV("DEBUG(%s):", __FUNCTION__);
Jiyoung Shinc15a6b02012-06-05 01:08:14 -07001306 if ((NULL != frame_dst_ops) && (NULL != frame_dst_ops->dequeue_frame)
1307 && (NULL != frame_dst_ops->cancel_frame) && (NULL !=frame_dst_ops->enqueue_frame)) {
1308 m_frameQueueOps = (camera2_frame_queue_dst_ops_t *)frame_dst_ops;
1309 return 0;
1310 }
1311 else {
Sungjoong Kang13d8c7b2012-07-14 10:20:39 +09001312 ALOGE("DEBUG(%s):setFrameQueueDstOps : NULL arguments", __FUNCTION__);
Jiyoung Shinc15a6b02012-06-05 01:08:14 -07001313 return 1;
1314 }
1315}
1316
1317int ExynosCameraHWInterface2::getInProgressCount()
1318{
1319 int inProgressCount = m_requestManager->GetNumEntries();
Sungjoong Kang13d8c7b2012-07-14 10:20:39 +09001320 ALOGV("DEBUG(%s): # of dequeued req (%d)", __FUNCTION__, inProgressCount);
Jiyoung Shinc15a6b02012-06-05 01:08:14 -07001321 return inProgressCount;
1322}
1323
1324int ExynosCameraHWInterface2::flushCapturesInProgress()
1325{
1326 return 0;
1327}
1328
Jiyoung Shinc15a6b02012-06-05 01:08:14 -07001329int ExynosCameraHWInterface2::constructDefaultRequest(int request_template, camera_metadata_t **request)
1330{
Sungjoong Kang13d8c7b2012-07-14 10:20:39 +09001331 ALOGV("DEBUG(%s): making template (%d) ", __FUNCTION__, request_template);
Jiyoung Shinc15a6b02012-06-05 01:08:14 -07001332
1333 if (request == NULL) return BAD_VALUE;
1334 if (request_template < 0 || request_template >= CAMERA2_TEMPLATE_COUNT) {
1335 return BAD_VALUE;
1336 }
1337 status_t res;
1338 // Pass 1, calculate size and allocate
Sungjoong Kangdaa1fcd2012-08-08 11:49:43 -07001339 res = m_camera2->constructDefaultRequest(request_template,
Jiyoung Shinc15a6b02012-06-05 01:08:14 -07001340 request,
1341 true);
1342 if (res != OK) {
1343 return res;
1344 }
1345 // Pass 2, build request
Sungjoong Kangdaa1fcd2012-08-08 11:49:43 -07001346 res = m_camera2->constructDefaultRequest(request_template,
Jiyoung Shinc15a6b02012-06-05 01:08:14 -07001347 request,
1348 false);
1349 if (res != OK) {
1350 ALOGE("Unable to populate new request for template %d",
1351 request_template);
1352 }
1353
1354 return res;
1355}
1356
1357int ExynosCameraHWInterface2::allocateStream(uint32_t width, uint32_t height, int format, const camera2_stream_ops_t *stream_ops,
1358 uint32_t *stream_id, uint32_t *format_actual, uint32_t *usage, uint32_t *max_buffers)
1359{
Sungjoong Kangad378612012-08-17 12:34:33 -07001360 ALOGV("DEBUG(%s): allocate stream width(%d) height(%d) format(%x)", __FUNCTION__, width, height, format);
Jiyoung Shinc15a6b02012-06-05 01:08:14 -07001361 char node_name[30];
Sungjoong Kang9dd63e12012-07-24 00:25:51 +09001362 int fd = 0, allocCase = 0;
Sungjoong Kang13d8c7b2012-07-14 10:20:39 +09001363 StreamThread *AllocatedStream;
1364 stream_parameters_t newParameters;
Jiyoung Shinc15a6b02012-06-05 01:08:14 -07001365
Sungjoong Kangdaa1fcd2012-08-08 11:49:43 -07001366 if (format == CAMERA2_HAL_PIXEL_FORMAT_OPAQUE &&
1367 m_camera2->isSupportedResolution(width, height)) {
Sungjoong Kang9dd63e12012-07-24 00:25:51 +09001368 if (!(m_streamThreads[0].get())) {
1369 ALOGV("DEBUG(%s): stream 0 not exist", __FUNCTION__);
1370 allocCase = 0;
Jiyoung Shinc15a6b02012-06-05 01:08:14 -07001371 }
Sungjoong Kang13d8c7b2012-07-14 10:20:39 +09001372 else {
Alex Ray6bbb5932012-07-27 17:19:48 -07001373 if ((m_streamThreads[0].get())->m_activated == true) {
Sungjoong Kang9dd63e12012-07-24 00:25:51 +09001374 ALOGV("DEBUG(%s): stream 0 exists and activated.", __FUNCTION__);
1375 allocCase = 1;
1376 }
1377 else {
1378 ALOGV("DEBUG(%s): stream 0 exists and deactivated.", __FUNCTION__);
1379 allocCase = 2;
1380 }
Sungjoong Kang13d8c7b2012-07-14 10:20:39 +09001381 }
Sungjoong Kang15fd8232012-08-23 16:16:44 -07001382 if ((width == 1920 && height == 1080) || (width == 1280 && height == 720)) {
1383 m_wideAspect = true;
1384 }
1385 else {
1386 m_wideAspect = false;
1387 }
Sungjoong Kangb55ed662012-08-31 21:31:34 -07001388 m_aspectChanged = true;
Sungjoong Kang15fd8232012-08-23 16:16:44 -07001389 ALOGV("DEBUG(%s): m_wideAspect (%d)", __FUNCTION__, m_wideAspect);
1390
Sungjoong Kang9dd63e12012-07-24 00:25:51 +09001391 if (allocCase == 0 || allocCase == 2) {
1392 *stream_id = 0;
Jiyoung Shinc15a6b02012-06-05 01:08:14 -07001393
Sungjoong Kang9dd63e12012-07-24 00:25:51 +09001394 if (allocCase == 0) {
1395 m_streamThreads[0] = new StreamThread(this, *stream_id);
Sungjoong Kang9dd63e12012-07-24 00:25:51 +09001396 }
1397 AllocatedStream = (StreamThread*)(m_streamThreads[0].get());
Sungjoong Kangb5237e62012-07-27 07:39:05 -07001398 m_scp_flushing = false;
1399 m_scp_closing = false;
1400 m_scp_closed = false;
Sungjoong Kang9dd63e12012-07-24 00:25:51 +09001401 usleep(100000); // TODO : guarantee the codes below will be run after readyToRunInternal()
Jiyoung Shinc15a6b02012-06-05 01:08:14 -07001402
Rebecca Schultz Zavinc853be72012-08-23 00:03:05 -07001403 *format_actual = HAL_PIXEL_FORMAT_EXYNOS_YV12;
Alex Ray6bbb5932012-07-27 17:19:48 -07001404 *usage = GRALLOC_USAGE_SW_WRITE_OFTEN;
Sungjoong Kangb55ed662012-08-31 21:31:34 -07001405 *max_buffers = 6;
Jiyoung Shinc15a6b02012-06-05 01:08:14 -07001406
Sungjoong Kang37e122d2012-08-08 11:13:48 -07001407 newParameters.streamType = STREAM_TYPE_DIRECT;
Sungjoong Kang9dd63e12012-07-24 00:25:51 +09001408 newParameters.outputWidth = width;
1409 newParameters.outputHeight = height;
1410 newParameters.nodeWidth = width;
1411 newParameters.nodeHeight = height;
1412 newParameters.outputFormat = *format_actual;
1413 newParameters.nodeFormat = HAL_PIXEL_FORMAT_2_V4L2_PIX(*format_actual);
1414 newParameters.streamOps = stream_ops;
1415 newParameters.usage = *usage;
Sungjoong Kangbe494d12012-08-04 15:36:56 -07001416 newParameters.numHwBuffers = 8;
1417 newParameters.numOwnSvcBuffers = *max_buffers;
Sungjoong Kang9dd63e12012-07-24 00:25:51 +09001418 newParameters.fd = m_fd_scp;
Sungjoong Kang74d78eb2012-08-29 13:25:46 -07001419 newParameters.nodePlanes = NUM_PLANES(*format_actual);
1420 newParameters.svcPlanes = NUM_PLANES(*format_actual);
Sungjoong Kangfeb7df42012-08-28 23:35:43 +09001421 newParameters.metaPlanes = 1;
Sungjoong Kang9dd63e12012-07-24 00:25:51 +09001422 newParameters.halBuftype = V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE;
1423 newParameters.memory = V4L2_MEMORY_DMABUF;
1424 newParameters.ionClient = m_ionCameraClient;
Sungjoong Kangbe494d12012-08-04 15:36:56 -07001425 newParameters.numSvcBufsInHal = 0;
Sungjoong Kang9dd63e12012-07-24 00:25:51 +09001426 AllocatedStream->m_index = *stream_id;
1427 AllocatedStream->setParameter(&newParameters);
1428 AllocatedStream->m_activated = true;
Sungjoong Kang13d8c7b2012-07-14 10:20:39 +09001429
Sungjoong Kang9dd63e12012-07-24 00:25:51 +09001430 m_scp_flushing = false;
1431 m_scp_closing = false;
1432 m_scp_closed = false;
Sungjoong Kangad378612012-08-17 12:34:33 -07001433 m_requestManager->SetDefaultParameters(m_camera2->getSensorW());
1434 m_camera_info.dummy_shot.shot.ctl.scaler.cropRegion[2] = m_camera2->getSensorW();
Sungjoong Kang9dd63e12012-07-24 00:25:51 +09001435 return 0;
1436 }
1437 else if (allocCase == 1) {
1438 record_parameters_t recordParameters;
1439 StreamThread *parentStream;
1440 parentStream = (StreamThread*)(m_streamThreads[0].get());
1441 if (!parentStream) {
1442 return 1;
1443 // TODO
1444 }
1445 *stream_id = 2;
1446 usleep(100000); // TODO : guarantee the codes below will be run after readyToRunInternal()
1447
Sungjoong Kang804236a2012-08-05 10:36:19 -07001448 *format_actual = HAL_PIXEL_FORMAT_YCbCr_420_SP; // NV12M
Alex Ray6bbb5932012-07-27 17:19:48 -07001449 *usage = GRALLOC_USAGE_SW_WRITE_OFTEN;
James Dong26306792012-08-24 14:42:26 -07001450 *max_buffers = 6;
Sungjoong Kang9dd63e12012-07-24 00:25:51 +09001451
1452 recordParameters.outputWidth = width;
1453 recordParameters.outputHeight = height;
1454 recordParameters.outputFormat = *format_actual;
Sungjoong Kang804236a2012-08-05 10:36:19 -07001455 recordParameters.svcPlanes = NUM_PLANES(*format_actual);
Sungjoong Kang9dd63e12012-07-24 00:25:51 +09001456 recordParameters.streamOps = stream_ops;
1457 recordParameters.usage = *usage;
Sungjoong Kangbe494d12012-08-04 15:36:56 -07001458 recordParameters.numOwnSvcBuffers = *max_buffers;
1459 recordParameters.numSvcBufsInHal = 0;
Sungjoong Kang9dd63e12012-07-24 00:25:51 +09001460
1461 parentStream->setRecordingParameter(&recordParameters);
1462 m_scp_flushing = false;
1463 m_scp_closing = false;
1464 m_scp_closed = false;
1465 m_recordingEnabled = true;
1466 return 0;
1467 }
Sungjoong Kang13d8c7b2012-07-14 10:20:39 +09001468 }
Sungjoong Kangad378612012-08-17 12:34:33 -07001469 else if (format == HAL_PIXEL_FORMAT_BLOB
Sungjoong Kangdaa1fcd2012-08-08 11:49:43 -07001470 && m_camera2->isSupportedJpegResolution(width, height)) {
Sungjoong Kang13d8c7b2012-07-14 10:20:39 +09001471
1472 *stream_id = 1;
1473
Sungjoong Kang15fd8232012-08-23 16:16:44 -07001474 if (!(m_streamThreads[*stream_id].get())) {
Sungjoong Kang8e2c2fd2012-08-27 00:02:22 -07001475 ALOGV("DEBUG(%s): stream 1 not exist", __FUNCTION__);
Sungjoong Kang15fd8232012-08-23 16:16:44 -07001476 m_streamThreads[1] = new StreamThread(this, *stream_id);
1477 allocCase = 0;
1478 }
1479 else {
1480 if ((m_streamThreads[*stream_id].get())->m_activated == true) {
Sungjoong Kang8e2c2fd2012-08-27 00:02:22 -07001481 ALOGV("DEBUG(%s): stream 1 exists and activated.", __FUNCTION__);
Sungjoong Kang15fd8232012-08-23 16:16:44 -07001482 allocCase = 1;
1483 }
1484 else {
Sungjoong Kang8e2c2fd2012-08-27 00:02:22 -07001485 ALOGV("DEBUG(%s): stream 1 exists and deactivated.", __FUNCTION__);
Sungjoong Kang15fd8232012-08-23 16:16:44 -07001486 allocCase = 2;
1487 }
1488 }
1489
1490 AllocatedStream = (StreamThread*)(m_streamThreads[*stream_id].get());
Sungjoong Kang9dd63e12012-07-24 00:25:51 +09001491
Sungjoong Kang13d8c7b2012-07-14 10:20:39 +09001492 fd = m_camera_info.capture.fd;
1493 usleep(100000); // TODO : guarantee the codes below will be run after readyToRunInternal()
1494
1495 *format_actual = HAL_PIXEL_FORMAT_BLOB;
1496
1497 *usage = GRALLOC_USAGE_SW_WRITE_OFTEN;
Sungjoong Kang37e122d2012-08-08 11:13:48 -07001498 *max_buffers = 4;
Sungjoong Kang13d8c7b2012-07-14 10:20:39 +09001499
Sungjoong Kang37e122d2012-08-08 11:13:48 -07001500 newParameters.streamType = STREAM_TYPE_INDIRECT;
Sungjoong Kang13d8c7b2012-07-14 10:20:39 +09001501 newParameters.outputWidth = width;
1502 newParameters.outputHeight = height;
Sungjoong Kang9dd63e12012-07-24 00:25:51 +09001503
Sungjoong Kangdaa1fcd2012-08-08 11:49:43 -07001504 newParameters.nodeWidth = m_camera2->getSensorW();
1505 newParameters.nodeHeight = m_camera2->getSensorH();
Sungjoong Kang9dd63e12012-07-24 00:25:51 +09001506
Sungjoong Kang13d8c7b2012-07-14 10:20:39 +09001507 newParameters.outputFormat = *format_actual;
1508 newParameters.nodeFormat = V4L2_PIX_FMT_YUYV;
1509 newParameters.streamOps = stream_ops;
1510 newParameters.usage = *usage;
Sungjoong Kangbe494d12012-08-04 15:36:56 -07001511 newParameters.numHwBuffers = 8;
1512 newParameters.numOwnSvcBuffers = *max_buffers;
Sungjoong Kang13d8c7b2012-07-14 10:20:39 +09001513 newParameters.fd = fd;
1514 newParameters.nodePlanes = 1;
1515 newParameters.svcPlanes = 1;
1516 newParameters.halBuftype = V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE;
1517 newParameters.memory = V4L2_MEMORY_DMABUF;
1518 newParameters.ionClient = m_ionCameraClient;
Sungjoong Kangbe494d12012-08-04 15:36:56 -07001519 newParameters.numSvcBufsInHal = 0;
Sungjoong Kang9dd63e12012-07-24 00:25:51 +09001520 AllocatedStream->m_index = *stream_id;
Sungjoong Kang13d8c7b2012-07-14 10:20:39 +09001521 AllocatedStream->setParameter(&newParameters);
1522 return 0;
1523 }
Sungjoong Kang74d78eb2012-08-29 13:25:46 -07001524 else if (format == HAL_PIXEL_FORMAT_YCrCb_420_SP || format == HAL_PIXEL_FORMAT_YV12) {
1525 StreamThread *parentStream;
1526 callback_parameters_t callbackParameters;
1527 parentStream = (StreamThread*)(m_streamThreads[0].get());
1528 if (!parentStream) {
1529 ALOGE("(%s): preview stream not exist", __FUNCTION__);
1530 return 1;
1531 }
1532 *stream_id = 3;
1533
1534 *format_actual = format;
1535 *usage = GRALLOC_USAGE_SW_WRITE_OFTEN;
1536 *max_buffers = 4;
1537 if (width == parentStream->m_parameters.outputWidth
1538 && height == parentStream->m_parameters.outputHeight) {
1539
1540 callbackParameters.outputWidth = width;
1541 callbackParameters.outputHeight = height;
1542 callbackParameters.outputFormat = *format_actual;
1543 callbackParameters.svcPlanes = NUM_PLANES(*format_actual);
1544 callbackParameters.streamOps = stream_ops;
1545 callbackParameters.usage = *usage;
1546 callbackParameters.numOwnSvcBuffers = *max_buffers;
1547 callbackParameters.numSvcBufsInHal = 0;
1548 if (format == HAL_PIXEL_FORMAT_YCrCb_420_SP) {
1549 callbackParameters.internalFormat = HAL_PIXEL_FORMAT_EXYNOS_YCrCb_420_SP;
1550 callbackParameters.internalPlanes = NUM_PLANES(HAL_PIXEL_FORMAT_EXYNOS_YCrCb_420_SP);
1551 }
1552 else {
1553 callbackParameters.internalFormat = HAL_PIXEL_FORMAT_EXYNOS_YV12;
1554 callbackParameters.internalPlanes = NUM_PLANES(HAL_PIXEL_FORMAT_EXYNOS_YV12);
1555 }
1556
1557 parentStream->setCallbackParameter(&callbackParameters);
1558 m_previewCbEnabled = true;
1559 ALOGV("(%s): Enabling Previewcb - planes(%d)", __FUNCTION__, callbackParameters.svcPlanes);
1560 }
1561 return 0;
1562 }
Sungjoong Kang13d8c7b2012-07-14 10:20:39 +09001563 ALOGE("DEBUG(%s): Unsupported Pixel Format", __FUNCTION__);
1564 return 1; // TODO : check proper error code
1565}
1566
1567int ExynosCameraHWInterface2::registerStreamBuffers(uint32_t stream_id,
1568 int num_buffers, buffer_handle_t *registeringBuffers)
1569{
1570 int i,j;
1571 void *virtAddr[3];
1572 uint32_t plane_index = 0;
1573 stream_parameters_t *targetStreamParms;
Sungjoong Kang9dd63e12012-07-24 00:25:51 +09001574 record_parameters_t *targetRecordParms;
Sungjoong Kang74d78eb2012-08-29 13:25:46 -07001575 callback_parameters_t *targetCallbackParms;
Sungjoong Kang13d8c7b2012-07-14 10:20:39 +09001576 node_info_t *currentNode;
1577
1578 struct v4l2_buffer v4l2_buf;
1579 struct v4l2_plane planes[VIDEO_MAX_PLANES];
1580
1581 ALOGV("DEBUG(%s): streamID (%d), num_buff(%d), handle(%x) ", __FUNCTION__,
1582 stream_id, num_buffers, (uint32_t)registeringBuffers);
1583
1584 if (stream_id == 0) {
1585 targetStreamParms = &(m_streamThreads[0]->m_parameters);
1586 }
1587 else if (stream_id == 1) {
1588 targetStreamParms = &(m_streamThreads[1]->m_parameters);
Sungjoong Kang15fd8232012-08-23 16:16:44 -07001589 // TODO : make clear stream off case
1590 m_need_streamoff = 0;
1591
1592 if (m_camera_info.capture.status == false) {
1593 /* capture */
1594 m_camera_info.capture.buffers = 8;
1595 cam_int_s_fmt(&(m_camera_info.capture));
1596 cam_int_reqbufs(&(m_camera_info.capture));
1597 for (i = 0; i < m_camera_info.capture.buffers; i++) {
1598 ALOGV("DEBUG(%s): capture initial QBUF [%d]", __FUNCTION__, i);
1599 cam_int_qbuf(&(m_camera_info.capture), i);
1600 }
1601
1602 if (cam_int_streamon(&(m_camera_info.capture)) < 0) {
1603 ALOGE("ERR(%s): capture stream on fail", __FUNCTION__);
1604 } else {
1605 m_camera_info.capture.status = true;
1606 }
1607 }
Sungjoong Kang13d8c7b2012-07-14 10:20:39 +09001608 }
Sungjoong Kang9dd63e12012-07-24 00:25:51 +09001609 else if (stream_id == 2) {
1610 targetRecordParms = &(m_streamThreads[0]->m_recordParameters);
1611
1612 targetRecordParms->numSvcBuffers = num_buffers;
1613
1614 for (i = 0 ; i<targetRecordParms->numSvcBuffers ; i++) {
1615 ALOGV("DEBUG(%s): registering Stream Buffers[%d] (%x) ", __FUNCTION__,
1616 i, (uint32_t)(registeringBuffers[i]));
1617 if (m_grallocHal) {
1618 if (m_grallocHal->lock(m_grallocHal, registeringBuffers[i],
1619 targetRecordParms->usage, 0, 0,
1620 targetRecordParms->outputWidth, targetRecordParms->outputHeight, virtAddr) != 0) {
1621 ALOGE("ERR(%s): could not obtain gralloc buffer", __FUNCTION__);
1622 }
1623 else {
1624 ExynosBuffer currentBuf;
1625 const private_handle_t *priv_handle = reinterpret_cast<const private_handle_t *>(registeringBuffers[i]);
Sungjoong Kang9dd63e12012-07-24 00:25:51 +09001626 currentBuf.fd.extFd[0] = priv_handle->fd;
Alex Ray6bbb5932012-07-27 17:19:48 -07001627 currentBuf.fd.extFd[1] = priv_handle->fd1;
1628 currentBuf.fd.extFd[2] = priv_handle->fd2;
Sungjoong Kang9dd63e12012-07-24 00:25:51 +09001629 for (plane_index=0 ; plane_index < targetRecordParms->svcPlanes ; plane_index++) {
1630 currentBuf.virt.extP[plane_index] = (char *)virtAddr[plane_index];
1631 ALOGV("DEBUG(%s): plane(%d): fd(%d) addr(%x)",
Sungjoong Kang804236a2012-08-05 10:36:19 -07001632 __FUNCTION__, plane_index, currentBuf.fd.extFd[plane_index],
Sungjoong Kang9dd63e12012-07-24 00:25:51 +09001633 (unsigned int)currentBuf.virt.extP[plane_index]);
1634 }
1635 targetRecordParms->svcBufStatus[i] = ON_SERVICE;
Sungjoong Kangb5237e62012-07-27 07:39:05 -07001636 targetRecordParms->svcBuffers[i] = currentBuf;
1637 targetRecordParms->svcBufHandle[i] = registeringBuffers[i];
Sungjoong Kang9dd63e12012-07-24 00:25:51 +09001638 }
1639 }
1640 }
1641 m_needsRecordBufferInit = true;
1642 return 0;
1643 }
Sungjoong Kang74d78eb2012-08-29 13:25:46 -07001644 else if (stream_id == 3) {
1645 targetCallbackParms = &(m_streamThreads[0]->m_previewCbParameters);
1646
1647 targetCallbackParms->numSvcBuffers = num_buffers;
1648
1649 for (i = 0 ; i < targetCallbackParms->numSvcBuffers ; i++) {
1650 ALOGE("%s: registering Stream Buffers[%d] (%x) ", __FUNCTION__,
1651 i, (uint32_t)(registeringBuffers[i]));
1652 if (m_grallocHal) {
1653 if (m_grallocHal->lock(m_grallocHal, registeringBuffers[i],
1654 targetCallbackParms->usage, 0, 0,
1655 targetCallbackParms->outputWidth, targetCallbackParms->outputHeight, virtAddr) != 0) {
1656 ALOGE("ERR(%s): could not obtain gralloc buffer", __FUNCTION__);
1657 }
1658 else {
1659 ExynosBuffer currentBuf;
1660 const private_handle_t *priv_handle = reinterpret_cast<const private_handle_t *>(registeringBuffers[i]);
1661 currentBuf.fd.extFd[0] = priv_handle->fd;
1662 currentBuf.fd.extFd[1] = priv_handle->fd1;
1663 currentBuf.fd.extFd[2] = priv_handle->fd2;
1664 for (plane_index = 0 ; plane_index < targetCallbackParms->svcPlanes ; plane_index++) {
1665 currentBuf.virt.extP[plane_index] = (char *)virtAddr[plane_index];
1666 }
1667 ALOGV("fd(%d) addr(%x) fd1(%d) fd2(%d)", priv_handle->fd, (unsigned int)currentBuf.virt.extP[plane_index],
1668 priv_handle->fd1, priv_handle->fd2);
1669 ALOGV("flags(%d) size(%d) offset(%d) stride(%d) vstride(%d)",
1670 priv_handle->flags, priv_handle->size, priv_handle->offset,
1671 priv_handle->stride, priv_handle->vstride);
1672 targetCallbackParms->svcBufStatus[i] = ON_SERVICE;
1673 targetCallbackParms->svcBuffers[i] = currentBuf;
1674 targetCallbackParms->svcBufHandle[i] = registeringBuffers[i];
1675 }
1676 }
1677 }
1678 m_needsPreviewCbBufferInit = true;
1679 return 0;
1680 }
Sungjoong Kang13d8c7b2012-07-14 10:20:39 +09001681 else {
1682 ALOGE("ERR(%s) unregisterd stream id (%d)", __FUNCTION__, stream_id);
Sungjoong Kangbe494d12012-08-04 15:36:56 -07001683 return 1;
Sungjoong Kang13d8c7b2012-07-14 10:20:39 +09001684 }
1685
Sungjoong Kang37e122d2012-08-08 11:13:48 -07001686 if (targetStreamParms->streamType == STREAM_TYPE_DIRECT) {
Sungjoong Kang13d8c7b2012-07-14 10:20:39 +09001687 if (num_buffers < targetStreamParms->numHwBuffers) {
1688 ALOGE("ERR(%s) registering insufficient num of buffers (%d) < (%d)",
1689 __FUNCTION__, num_buffers, targetStreamParms->numHwBuffers);
Sungjoong Kangbe494d12012-08-04 15:36:56 -07001690 return 1;
Sungjoong Kang13d8c7b2012-07-14 10:20:39 +09001691 }
1692 }
1693 ALOGV("DEBUG(%s): format(%x) width(%d), height(%d) svcPlanes(%d)",
1694 __FUNCTION__, targetStreamParms->outputFormat, targetStreamParms->outputWidth,
1695 targetStreamParms->outputHeight, targetStreamParms->svcPlanes);
1696
1697 targetStreamParms->numSvcBuffers = num_buffers;
1698 currentNode = &(targetStreamParms->node); // TO Remove
1699
1700 currentNode->fd = targetStreamParms->fd;
1701 currentNode->width = targetStreamParms->nodeWidth;
1702 currentNode->height = targetStreamParms->nodeHeight;
1703 currentNode->format = targetStreamParms->nodeFormat;
1704 currentNode->planes = targetStreamParms->nodePlanes;
1705 currentNode->buffers = targetStreamParms->numHwBuffers;
1706 currentNode->type = targetStreamParms->halBuftype;
1707 currentNode->memory = targetStreamParms->memory;
1708 currentNode->ionClient = targetStreamParms->ionClient;
1709
Sungjoong Kang37e122d2012-08-08 11:13:48 -07001710 if (targetStreamParms->streamType == STREAM_TYPE_DIRECT) {
Sungjoong Kangad378612012-08-17 12:34:33 -07001711 if(m_need_streamoff == 1) {
Sungjoong Kang15fd8232012-08-23 16:16:44 -07001712 if (m_sensorThread != NULL) {
1713 m_sensorThread->release();
1714 /* TODO */
1715 usleep(500000);
1716 } else {
1717 ALOGE("+++++++ sensor thread is NULL %d", __LINE__);
1718 }
1719
Sungjoong Kangad378612012-08-17 12:34:33 -07001720 ALOGV("(%s): calling capture streamoff", __FUNCTION__);
Sungjoong Kang15fd8232012-08-23 16:16:44 -07001721 if (cam_int_streamoff(&(m_camera_info.capture)) < 0) {
1722 ALOGE("ERR(%s): capture stream off fail", __FUNCTION__);
1723 } else {
1724 m_camera_info.capture.status = false;
1725 }
1726
Sungjoong Kangad378612012-08-17 12:34:33 -07001727 ALOGV("(%s): calling capture streamoff done", __FUNCTION__);
1728
1729 m_camera_info.capture.buffers = 0;
1730 ALOGV("DEBUG(%s): capture calling reqbuf 0 ", __FUNCTION__);
1731 cam_int_reqbufs(&(m_camera_info.capture));
1732 ALOGV("DEBUG(%s): capture calling reqbuf 0 done", __FUNCTION__);
1733
Sungjoong Kangad378612012-08-17 12:34:33 -07001734 m_isIspStarted = false;
1735 }
1736
Sungjoong Kangad378612012-08-17 12:34:33 -07001737 if (m_need_streamoff == 1) {
1738 m_camera_info.sensor.buffers = NUM_BAYER_BUFFERS;
1739 m_camera_info.isp.buffers = m_camera_info.sensor.buffers;
1740 m_camera_info.capture.buffers = 8;
Sungjoong Kang15fd8232012-08-23 16:16:44 -07001741 /* isp */
1742 cam_int_s_fmt(&(m_camera_info.isp));
Sungjoong Kangad378612012-08-17 12:34:33 -07001743 cam_int_reqbufs(&(m_camera_info.isp));
Sungjoong Kang15fd8232012-08-23 16:16:44 -07001744 /* sensor */
1745 cam_int_s_fmt(&(m_camera_info.sensor));
Sungjoong Kangad378612012-08-17 12:34:33 -07001746 cam_int_reqbufs(&(m_camera_info.sensor));
1747
1748 for (i = 0; i < 8; i++) {
1749 ALOGV("DEBUG(%s): sensor initial QBUF [%d]", __FUNCTION__, i);
1750 memcpy( m_camera_info.sensor.buffer[i].virt.extP[1], &(m_camera_info.dummy_shot),
1751 sizeof(struct camera2_shot_ext));
1752 m_camera_info.dummy_shot.shot.ctl.sensor.frameDuration = 33*1000*1000; // apply from frame #1
1753 m_camera_info.dummy_shot.shot.ctl.request.frameCount = -1;
1754 cam_int_qbuf(&(m_camera_info.sensor), i);
1755 }
1756
Sungjoong Kang15fd8232012-08-23 16:16:44 -07001757 /* capture */
1758 cam_int_s_fmt(&(m_camera_info.capture));
Sungjoong Kangad378612012-08-17 12:34:33 -07001759 cam_int_reqbufs(&(m_camera_info.capture));
Sungjoong Kang15fd8232012-08-23 16:16:44 -07001760 for (i = 0; i < m_camera_info.capture.buffers; i++) {
1761 ALOGV("DEBUG(%s): capture initial QBUF [%d]", __FUNCTION__, i);
1762 cam_int_qbuf(&(m_camera_info.capture), i);
1763 }
Sungjoong Kangad378612012-08-17 12:34:33 -07001764
Sungjoong Kang15fd8232012-08-23 16:16:44 -07001765 }
1766
1767 cam_int_s_input(currentNode, m_camera_info.sensor_id);
1768 cam_int_s_fmt(currentNode);
1769 cam_int_reqbufs(currentNode);
1770
Sungjoong Kang13d8c7b2012-07-14 10:20:39 +09001771 }
Sungjoong Kang37e122d2012-08-08 11:13:48 -07001772 else if (targetStreamParms->streamType == STREAM_TYPE_INDIRECT) {
Sungjoong Kang13d8c7b2012-07-14 10:20:39 +09001773 for(i = 0; i < currentNode->buffers; i++){
1774 memcpy(&(currentNode->buffer[i]), &(m_camera_info.capture.buffer[i]), sizeof(ExynosBuffer));
1775 }
1776 }
1777
1778 for (i = 0 ; i<targetStreamParms->numSvcBuffers ; i++) {
1779 ALOGV("DEBUG(%s): registering Stream Buffers[%d] (%x) ", __FUNCTION__,
1780 i, (uint32_t)(registeringBuffers[i]));
1781 if (m_grallocHal) {
1782 if (m_grallocHal->lock(m_grallocHal, registeringBuffers[i],
1783 targetStreamParms->usage, 0, 0,
1784 currentNode->width, currentNode->height, virtAddr) != 0) {
1785 ALOGE("ERR(%s): could not obtain gralloc buffer", __FUNCTION__);
1786 }
1787 else {
1788 v4l2_buf.m.planes = planes;
1789 v4l2_buf.type = currentNode->type;
1790 v4l2_buf.memory = currentNode->memory;
1791 v4l2_buf.index = i;
1792 v4l2_buf.length = currentNode->planes;
1793
1794 ExynosBuffer currentBuf;
Sungjoong Kangfeb7df42012-08-28 23:35:43 +09001795 ExynosBuffer metaBuf;
Sungjoong Kang13d8c7b2012-07-14 10:20:39 +09001796 const private_handle_t *priv_handle = reinterpret_cast<const private_handle_t *>(registeringBuffers[i]);
1797
1798 m_getAlignedYUVSize(currentNode->format,
1799 currentNode->width, currentNode->height, &currentBuf);
Alex Ray24231222012-06-27 15:18:15 -07001800
Sungjoong Kang37e122d2012-08-08 11:13:48 -07001801 ALOGV("DEBUG(%s): ion_size(%d), stride(%d), ", __FUNCTION__, priv_handle->size, priv_handle->stride);
1802 if (currentNode->planes == 1) {
Sungjoong Kang74d78eb2012-08-29 13:25:46 -07001803 v4l2_buf.m.planes[0].m.fd = priv_handle->fd;
1804 currentBuf.fd.extFd[0] = priv_handle->fd;
Sungjoong Kang37e122d2012-08-08 11:13:48 -07001805 currentBuf.size.extS[0] = priv_handle->size;
1806 currentBuf.size.extS[1] = 0;
1807 currentBuf.size.extS[2] = 0;
Sungjoong Kang74d78eb2012-08-29 13:25:46 -07001808 } else if (currentNode->planes == 2) {
1809 v4l2_buf.m.planes[0].m.fd = priv_handle->fd;
1810 v4l2_buf.m.planes[1].m.fd = priv_handle->fd1;
1811 currentBuf.fd.extFd[0] = priv_handle->fd;
1812 currentBuf.fd.extFd[1] = priv_handle->fd1;
1813
1814 } else if (currentNode->planes == 3) {
1815 v4l2_buf.m.planes[0].m.fd = priv_handle->fd;
1816 v4l2_buf.m.planes[2].m.fd = priv_handle->fd1;
1817 v4l2_buf.m.planes[1].m.fd = priv_handle->fd2;
1818 currentBuf.fd.extFd[0] = priv_handle->fd;
1819 currentBuf.fd.extFd[2] = priv_handle->fd1;
1820 currentBuf.fd.extFd[1] = priv_handle->fd2;
Sungjoong Kang37e122d2012-08-08 11:13:48 -07001821 }
Sungjoong Kangbe494d12012-08-04 15:36:56 -07001822 for (plane_index = 0 ; plane_index < v4l2_buf.length ; plane_index++) {
Sungjoong Kang13d8c7b2012-07-14 10:20:39 +09001823 currentBuf.virt.extP[plane_index] = (char *)virtAddr[plane_index];
1824 v4l2_buf.m.planes[plane_index].length = currentBuf.size.extS[plane_index];
1825 ALOGV("DEBUG(%s): plane(%d): fd(%d) addr(%x), length(%d)",
1826 __FUNCTION__, plane_index, v4l2_buf.m.planes[plane_index].m.fd,
1827 (unsigned int)currentBuf.virt.extP[plane_index],
1828 v4l2_buf.m.planes[plane_index].length);
Jiyoung Shinc15a6b02012-06-05 01:08:14 -07001829 }
Sungjoong Kang13d8c7b2012-07-14 10:20:39 +09001830
Sungjoong Kang37e122d2012-08-08 11:13:48 -07001831 if (targetStreamParms->streamType == STREAM_TYPE_DIRECT) {
Sungjoong Kang13d8c7b2012-07-14 10:20:39 +09001832 if (i < currentNode->buffers) {
Sungjoong Kangfeb7df42012-08-28 23:35:43 +09001833
1834
1835#ifdef ENABLE_FRAME_SYNC
1836 /* add plane for metadata*/
1837 metaBuf.size.extS[0] = 4*1024;
1838 allocCameraMemory(targetStreamParms->ionClient , &metaBuf, 1);
1839
1840 v4l2_buf.length += targetStreamParms->metaPlanes;
1841 v4l2_buf.m.planes[3].m.fd = metaBuf.fd.extFd[0];
1842 v4l2_buf.m.planes[3].length = metaBuf.size.extS[0];
1843
1844 ALOGV("Qbuf metaBuf: fd(%d), length(%d) plane(%d)", metaBuf.fd.extFd[0], metaBuf.size.extS[0], v4l2_buf.length);
1845#endif
Sungjoong Kang13d8c7b2012-07-14 10:20:39 +09001846 if (exynos_v4l2_qbuf(currentNode->fd, &v4l2_buf) < 0) {
Sungjoong Kang9dd63e12012-07-24 00:25:51 +09001847 ALOGE("ERR(%s): stream id(%d) exynos_v4l2_qbuf() fail fd(%d)",
1848 __FUNCTION__, stream_id, currentNode->fd);
1849 //return false;
Sungjoong Kang13d8c7b2012-07-14 10:20:39 +09001850 }
Sungjoong Kang9dd63e12012-07-24 00:25:51 +09001851 ALOGV("DEBUG(%s): stream id(%d) exynos_v4l2_qbuf() success fd(%d)",
1852 __FUNCTION__, stream_id, currentNode->fd);
Sungjoong Kang13d8c7b2012-07-14 10:20:39 +09001853 targetStreamParms->svcBufStatus[i] = REQUIRES_DQ_FROM_SVC;
1854 }
1855 else {
1856 targetStreamParms->svcBufStatus[i] = ON_SERVICE;
1857 }
1858 }
Sungjoong Kang37e122d2012-08-08 11:13:48 -07001859 else if (targetStreamParms->streamType == STREAM_TYPE_INDIRECT) {
Sungjoong Kang13d8c7b2012-07-14 10:20:39 +09001860 targetStreamParms->svcBufStatus[i] = ON_SERVICE;
1861 }
1862 targetStreamParms->svcBuffers[i] = currentBuf;
Sungjoong Kangfeb7df42012-08-28 23:35:43 +09001863 targetStreamParms->metaBuffers[i] = metaBuf;
Sungjoong Kang13d8c7b2012-07-14 10:20:39 +09001864 targetStreamParms->svcBufHandle[i] = registeringBuffers[i];
1865 }
Jiyoung Shinc15a6b02012-06-05 01:08:14 -07001866 }
Jiyoung Shinc15a6b02012-06-05 01:08:14 -07001867 }
Sungjoong Kangad378612012-08-17 12:34:33 -07001868
Sungjoong Kang9dd63e12012-07-24 00:25:51 +09001869 ALOGV("DEBUG(%s): calling streamon", __FUNCTION__);
Sungjoong Kang15fd8232012-08-23 16:16:44 -07001870 if (targetStreamParms->streamType == STREAM_TYPE_DIRECT) {
Sungjoong Kangad378612012-08-17 12:34:33 -07001871 ALOGD("%s(%d), stream id = %d", __FUNCTION__, __LINE__, stream_id);
1872 cam_int_streamon(&(targetStreamParms->node));
1873 }
1874
Sungjoong Kang15fd8232012-08-23 16:16:44 -07001875 if (m_need_streamoff == 1) {
1876 if (cam_int_streamon(&(m_camera_info.capture)) < 0) {
1877 ALOGE("ERR(%s): capture stream on fail", __FUNCTION__);
1878 } else {
1879 m_camera_info.capture.status = true;
1880 }
1881
1882 cam_int_streamon(&(m_camera_info.sensor));
1883 }
1884
Sungjoong Kangad378612012-08-17 12:34:33 -07001885 ALOGV("DEBUG(%s): calling streamon END", __FUNCTION__);
Sungjoong Kang13d8c7b2012-07-14 10:20:39 +09001886 ALOGV("DEBUG(%s): END registerStreamBuffers", __FUNCTION__);
Sungjoong Kangad378612012-08-17 12:34:33 -07001887
1888 if(!m_isIspStarted) {
1889 m_isIspStarted = true;
1890 StartISP();
Sungjoong Kangad378612012-08-17 12:34:33 -07001891 }
1892
Sungjoong Kang15fd8232012-08-23 16:16:44 -07001893 if (m_need_streamoff == 1) {
1894 m_requestManager->SetInitialSkip(8);
1895 m_sensorThread->Start("SensorThread", PRIORITY_DEFAULT, 0);
1896 m_mainThread->SetSignal(SIGNAL_MAIN_REQ_Q_NOT_EMPTY);
1897 }
1898 m_need_streamoff = 1;
1899
Jiyoung Shinc15a6b02012-06-05 01:08:14 -07001900 return 0;
1901}
1902
1903int ExynosCameraHWInterface2::releaseStream(uint32_t stream_id)
1904{
Sungjoong Kang13d8c7b2012-07-14 10:20:39 +09001905 StreamThread *targetStream;
1906 ALOGV("DEBUG(%s):", __FUNCTION__);
1907
Sungjoong Kangb5237e62012-07-27 07:39:05 -07001908 if (stream_id == 0) {
Sungjoong Kang13d8c7b2012-07-14 10:20:39 +09001909 targetStream = (StreamThread*)(m_streamThreads[0].get());
Sungjoong Kang9dd63e12012-07-24 00:25:51 +09001910 m_scp_flushing = true;
Sungjoong Kang13d8c7b2012-07-14 10:20:39 +09001911 }
Sungjoong Kangb5237e62012-07-27 07:39:05 -07001912 else if (stream_id == 1) {
Sungjoong Kang13d8c7b2012-07-14 10:20:39 +09001913 targetStream = (StreamThread*)(m_streamThreads[1].get());
1914 }
Sungjoong Kangb5237e62012-07-27 07:39:05 -07001915 else if (stream_id == 2 && m_recordingEnabled) {
1916 m_recordingEnabled = false;
Sungjoong Kangad378612012-08-17 12:34:33 -07001917 m_needsRecordBufferInit = true;
Sungjoong Kangb5237e62012-07-27 07:39:05 -07001918 return 0;
1919 }
Sungjoong Kang74d78eb2012-08-29 13:25:46 -07001920 else if (stream_id == 3 && m_previewCbEnabled) {
1921 m_previewCbEnabled = false;
1922 m_needsPreviewCbBufferInit = true;
1923 return 0;
1924 }
Sungjoong Kang13d8c7b2012-07-14 10:20:39 +09001925 else {
1926 ALOGE("ERR:(%s): wrong stream id (%d)", __FUNCTION__, stream_id);
Sungjoong Kangbe494d12012-08-04 15:36:56 -07001927 return 1;
Sungjoong Kang13d8c7b2012-07-14 10:20:39 +09001928 }
1929
Sungjoong Kangb5237e62012-07-27 07:39:05 -07001930 targetStream->m_releasing = true;
Sungjoong Kang15fd8232012-08-23 16:16:44 -07001931 do {
1932 ALOGD("stream thread release %d", __LINE__);
1933 targetStream->release();
1934 usleep(33000);
1935 } while (targetStream->m_releasing);
Sungjoong Kang9dd63e12012-07-24 00:25:51 +09001936 targetStream->m_activated = false;
Sungjoong Kang13d8c7b2012-07-14 10:20:39 +09001937 ALOGV("DEBUG(%s): DONE", __FUNCTION__);
Jiyoung Shinc15a6b02012-06-05 01:08:14 -07001938 return 0;
1939}
1940
1941int ExynosCameraHWInterface2::allocateReprocessStream(
Sungjoong Kang13d8c7b2012-07-14 10:20:39 +09001942 uint32_t width, uint32_t height, uint32_t format,
1943 const camera2_stream_in_ops_t *reprocess_stream_ops,
Jiyoung Shinc15a6b02012-06-05 01:08:14 -07001944 uint32_t *stream_id, uint32_t *consumer_usage, uint32_t *max_buffers)
1945{
Sungjoong Kang13d8c7b2012-07-14 10:20:39 +09001946 ALOGV("DEBUG(%s):", __FUNCTION__);
Jiyoung Shinc15a6b02012-06-05 01:08:14 -07001947 return 0;
1948}
1949
1950int ExynosCameraHWInterface2::releaseReprocessStream(uint32_t stream_id)
1951{
Sungjoong Kang13d8c7b2012-07-14 10:20:39 +09001952 ALOGV("DEBUG(%s):", __FUNCTION__);
Jiyoung Shinc15a6b02012-06-05 01:08:14 -07001953 return 0;
1954}
1955
1956int ExynosCameraHWInterface2::triggerAction(uint32_t trigger_id, int ext1, int ext2)
1957{
Sungjoong Kang0f26b202012-08-17 15:43:12 -07001958 ALOGV("DEBUG(%s): id(%x), %d, %d", __FUNCTION__, trigger_id, ext1, ext2);
1959
1960 switch (trigger_id) {
1961 case CAMERA2_TRIGGER_AUTOFOCUS:
1962 ALOGV("DEBUG(%s):TRIGGER_AUTOFOCUS id(%d)", __FUNCTION__, ext1);
Sungjoong Kang8e2c2fd2012-08-27 00:02:22 -07001963 OnAfTriggerStart(ext1);
Sungjoong Kang0f26b202012-08-17 15:43:12 -07001964 break;
1965
1966 case CAMERA2_TRIGGER_CANCEL_AUTOFOCUS:
1967 ALOGV("DEBUG(%s):CANCEL_AUTOFOCUS id(%d)", __FUNCTION__, ext1);
1968 OnAfCancel(ext1);
1969 break;
1970 default:
1971 break;
1972 }
Jiyoung Shinc15a6b02012-06-05 01:08:14 -07001973 return 0;
1974}
1975
1976int ExynosCameraHWInterface2::setNotifyCallback(camera2_notify_callback notify_cb, void *user)
1977{
Sungjoong Kang0f26b202012-08-17 15:43:12 -07001978 ALOGV("DEBUG(%s): cb_addr(%x)", __FUNCTION__, (unsigned int)notify_cb);
Jiyoung Shinc15a6b02012-06-05 01:08:14 -07001979 m_notifyCb = notify_cb;
1980 m_callbackCookie = user;
1981 return 0;
1982}
1983
1984int ExynosCameraHWInterface2::getMetadataVendorTagOps(vendor_tag_query_ops_t **ops)
1985{
Sungjoong Kang13d8c7b2012-07-14 10:20:39 +09001986 ALOGV("DEBUG(%s):", __FUNCTION__);
Jiyoung Shinc15a6b02012-06-05 01:08:14 -07001987 return 0;
1988}
1989
1990int ExynosCameraHWInterface2::dump(int fd)
1991{
Sungjoong Kang13d8c7b2012-07-14 10:20:39 +09001992 ALOGV("DEBUG(%s):", __FUNCTION__);
Jiyoung Shinc15a6b02012-06-05 01:08:14 -07001993 return 0;
1994}
1995
Sungjoong Kang13d8c7b2012-07-14 10:20:39 +09001996void ExynosCameraHWInterface2::m_getAlignedYUVSize(int colorFormat, int w, int h, ExynosBuffer *buf)
1997{
1998 switch (colorFormat) {
1999 // 1p
2000 case V4L2_PIX_FMT_RGB565 :
2001 case V4L2_PIX_FMT_YUYV :
2002 case V4L2_PIX_FMT_UYVY :
2003 case V4L2_PIX_FMT_VYUY :
2004 case V4L2_PIX_FMT_YVYU :
2005 buf->size.extS[0] = FRAME_SIZE(V4L2_PIX_2_HAL_PIXEL_FORMAT(colorFormat), w, h);
2006 buf->size.extS[1] = 0;
2007 buf->size.extS[2] = 0;
2008 break;
2009 // 2p
2010 case V4L2_PIX_FMT_NV12 :
2011 case V4L2_PIX_FMT_NV12T :
2012 case V4L2_PIX_FMT_NV21 :
2013 buf->size.extS[0] = ALIGN(w, 16) * ALIGN(h, 16);
2014 buf->size.extS[1] = ALIGN(w/2, 16) * ALIGN(h/2, 16);
2015 buf->size.extS[2] = 0;
2016 break;
2017 case V4L2_PIX_FMT_NV12M :
2018 case V4L2_PIX_FMT_NV12MT_16X16 :
Sungjoong Kang9dd63e12012-07-24 00:25:51 +09002019 case V4L2_PIX_FMT_NV21M:
Sungjoong Kang13d8c7b2012-07-14 10:20:39 +09002020 buf->size.extS[0] = ALIGN(w, 16) * ALIGN(h, 16);
2021 buf->size.extS[1] = ALIGN(buf->size.extS[0] / 2, 256);
2022 buf->size.extS[2] = 0;
2023 break;
2024 case V4L2_PIX_FMT_NV16 :
2025 case V4L2_PIX_FMT_NV61 :
2026 buf->size.extS[0] = ALIGN(w, 16) * ALIGN(h, 16);
2027 buf->size.extS[1] = ALIGN(w, 16) * ALIGN(h, 16);
2028 buf->size.extS[2] = 0;
2029 break;
2030 // 3p
2031 case V4L2_PIX_FMT_YUV420 :
2032 case V4L2_PIX_FMT_YVU420 :
2033 buf->size.extS[0] = (w * h);
2034 buf->size.extS[1] = (w * h) >> 2;
2035 buf->size.extS[2] = (w * h) >> 2;
2036 break;
2037 case V4L2_PIX_FMT_YUV420M:
2038 case V4L2_PIX_FMT_YVU420M :
2039 case V4L2_PIX_FMT_YUV422P :
2040 buf->size.extS[0] = ALIGN(w, 32) * ALIGN(h, 16);
2041 buf->size.extS[1] = ALIGN(w/2, 16) * ALIGN(h/2, 8);
2042 buf->size.extS[2] = ALIGN(w/2, 16) * ALIGN(h/2, 8);
2043 break;
2044 default:
2045 ALOGE("ERR(%s):unmatched colorFormat(%d)", __FUNCTION__, colorFormat);
2046 return;
2047 break;
2048 }
2049}
2050
2051bool ExynosCameraHWInterface2::m_getRatioSize(int src_w, int src_h,
2052 int dst_w, int dst_h,
2053 int *crop_x, int *crop_y,
2054 int *crop_w, int *crop_h,
2055 int zoom)
2056{
2057 *crop_w = src_w;
2058 *crop_h = src_h;
2059
2060 if ( src_w != dst_w
2061 || src_h != dst_h) {
2062 float src_ratio = 1.0f;
2063 float dst_ratio = 1.0f;
2064
2065 // ex : 1024 / 768
2066 src_ratio = (float)src_w / (float)src_h;
2067
2068 // ex : 352 / 288
2069 dst_ratio = (float)dst_w / (float)dst_h;
2070
2071 if (dst_w * dst_h < src_w * src_h) {
2072 if (dst_ratio <= src_ratio) {
2073 // shrink w
2074 *crop_w = src_h * dst_ratio;
2075 *crop_h = src_h;
2076 } else {
2077 // shrink h
2078 *crop_w = src_w;
2079 *crop_h = src_w / dst_ratio;
2080 }
2081 } else {
2082 if (dst_ratio <= src_ratio) {
2083 // shrink w
2084 *crop_w = src_h * dst_ratio;
2085 *crop_h = src_h;
2086 } else {
2087 // shrink h
2088 *crop_w = src_w;
2089 *crop_h = src_w / dst_ratio;
2090 }
2091 }
2092 }
2093
2094 if (zoom != 0) {
2095 float zoomLevel = ((float)zoom + 10.0) / 10.0;
2096 *crop_w = (int)((float)*crop_w / zoomLevel);
2097 *crop_h = (int)((float)*crop_h / zoomLevel);
2098 }
2099
2100 #define CAMERA_CROP_WIDTH_RESTRAIN_NUM (0x2)
2101 unsigned int w_align = (*crop_w & (CAMERA_CROP_WIDTH_RESTRAIN_NUM - 1));
2102 if (w_align != 0) {
2103 if ( (CAMERA_CROP_WIDTH_RESTRAIN_NUM >> 1) <= w_align
2104 && *crop_w + (CAMERA_CROP_WIDTH_RESTRAIN_NUM - w_align) <= dst_w) {
2105 *crop_w += (CAMERA_CROP_WIDTH_RESTRAIN_NUM - w_align);
2106 }
2107 else
2108 *crop_w -= w_align;
2109 }
2110
2111 #define CAMERA_CROP_HEIGHT_RESTRAIN_NUM (0x2)
2112 unsigned int h_align = (*crop_h & (CAMERA_CROP_HEIGHT_RESTRAIN_NUM - 1));
2113 if (h_align != 0) {
2114 if ( (CAMERA_CROP_HEIGHT_RESTRAIN_NUM >> 1) <= h_align
2115 && *crop_h + (CAMERA_CROP_HEIGHT_RESTRAIN_NUM - h_align) <= dst_h) {
2116 *crop_h += (CAMERA_CROP_HEIGHT_RESTRAIN_NUM - h_align);
2117 }
2118 else
2119 *crop_h -= h_align;
2120 }
2121
2122 *crop_x = (src_w - *crop_w) >> 1;
2123 *crop_y = (src_h - *crop_h) >> 1;
2124
2125 if (*crop_x & (CAMERA_CROP_WIDTH_RESTRAIN_NUM >> 1))
2126 *crop_x -= 1;
2127
2128 if (*crop_y & (CAMERA_CROP_HEIGHT_RESTRAIN_NUM >> 1))
2129 *crop_y -= 1;
2130
2131 return true;
2132}
2133
Sungjoong Kang9dd63e12012-07-24 00:25:51 +09002134BayerBufManager::BayerBufManager()
Sungjoong Kang13d8c7b2012-07-14 10:20:39 +09002135{
Sungjoong Kang9dd63e12012-07-24 00:25:51 +09002136 ALOGV("DEBUG(%s): ", __FUNCTION__);
2137 for (int i = 0; i < NUM_BAYER_BUFFERS ; i++) {
2138 entries[i].status = BAYER_ON_HAL_EMPTY;
2139 entries[i].reqFrameCnt = 0;
Sungjoong Kang13d8c7b2012-07-14 10:20:39 +09002140 }
Sungjoong Kang9dd63e12012-07-24 00:25:51 +09002141 sensorEnqueueHead = 0;
2142 sensorDequeueHead = 0;
2143 ispEnqueueHead = 0;
2144 ispDequeueHead = 0;
2145 numOnSensor = 0;
2146 numOnIsp = 0;
2147 numOnHalFilled = 0;
2148 numOnHalEmpty = NUM_BAYER_BUFFERS;
Sungjoong Kang13d8c7b2012-07-14 10:20:39 +09002149}
2150
Sungjoong Kang15fd8232012-08-23 16:16:44 -07002151BayerBufManager::~BayerBufManager()
2152{
2153 ALOGV("%s", __FUNCTION__);
2154}
2155
Sungjoong Kang9dd63e12012-07-24 00:25:51 +09002156int BayerBufManager::GetIndexForSensorEnqueue()
Sungjoong Kang13d8c7b2012-07-14 10:20:39 +09002157{
Sungjoong Kang9dd63e12012-07-24 00:25:51 +09002158 int ret = 0;
2159 if (numOnHalEmpty == 0)
2160 ret = -1;
2161 else
2162 ret = sensorEnqueueHead;
2163 ALOGV("DEBUG(%s): returning (%d)", __FUNCTION__, ret);
Sungjoong Kang13d8c7b2012-07-14 10:20:39 +09002164 return ret;
2165}
2166
Sungjoong Kang9dd63e12012-07-24 00:25:51 +09002167int BayerBufManager::MarkSensorEnqueue(int index)
Sungjoong Kang13d8c7b2012-07-14 10:20:39 +09002168{
Sungjoong Kang9dd63e12012-07-24 00:25:51 +09002169 ALOGV("DEBUG(%s) : BayerIndex[%d] ", __FUNCTION__, index);
2170
2171 // sanity check
2172 if (index != sensorEnqueueHead) {
2173 ALOGV("DEBUG(%s) : Abnormal BayerIndex[%d] - expected[%d]", __FUNCTION__, index, sensorEnqueueHead);
2174 return -1;
2175 }
2176 if (entries[index].status != BAYER_ON_HAL_EMPTY) {
2177 ALOGV("DEBUG(%s) : Abnormal status in BayerIndex[%d] = (%d) expected (%d)", __FUNCTION__,
2178 index, entries[index].status, BAYER_ON_HAL_EMPTY);
Sungjoong Kang13d8c7b2012-07-14 10:20:39 +09002179 return -1;
2180 }
2181
Sungjoong Kang9dd63e12012-07-24 00:25:51 +09002182 entries[index].status = BAYER_ON_SENSOR;
2183 entries[index].reqFrameCnt = 0;
2184 numOnHalEmpty--;
2185 numOnSensor++;
2186 sensorEnqueueHead = GetNextIndex(index);
2187 ALOGV("DEBUG(%s) END: HAL-e(%d) HAL-f(%d) Sensor(%d) ISP(%d) ",
2188 __FUNCTION__, numOnHalEmpty, numOnHalFilled, numOnSensor, numOnIsp);
2189 return 0;
2190}
Sungjoong Kang13d8c7b2012-07-14 10:20:39 +09002191
Sungjoong Kang9dd63e12012-07-24 00:25:51 +09002192int BayerBufManager::MarkSensorDequeue(int index, int reqFrameCnt, nsecs_t *timeStamp)
2193{
2194 ALOGV("DEBUG(%s) : BayerIndex[%d] reqFrameCnt(%d)", __FUNCTION__, index, reqFrameCnt);
2195
Sungjoong Kang9dd63e12012-07-24 00:25:51 +09002196 if (entries[index].status != BAYER_ON_SENSOR) {
Sungjoong Kangad378612012-08-17 12:34:33 -07002197 ALOGE("DEBUG(%s) : Abnormal status in BayerIndex[%d] = (%d) expected (%d)", __FUNCTION__,
Sungjoong Kang9dd63e12012-07-24 00:25:51 +09002198 index, entries[index].status, BAYER_ON_SENSOR);
Sungjoong Kang13d8c7b2012-07-14 10:20:39 +09002199 return -1;
2200 }
2201
Sungjoong Kang9dd63e12012-07-24 00:25:51 +09002202 entries[index].status = BAYER_ON_HAL_FILLED;
Sungjoong Kang9dd63e12012-07-24 00:25:51 +09002203 numOnHalFilled++;
2204 numOnSensor--;
Sungjoong Kangad378612012-08-17 12:34:33 -07002205
Sungjoong Kang9dd63e12012-07-24 00:25:51 +09002206 return 0;
2207}
Sungjoong Kang13d8c7b2012-07-14 10:20:39 +09002208
Sungjoong Kang9dd63e12012-07-24 00:25:51 +09002209int BayerBufManager::GetIndexForIspEnqueue(int *reqFrameCnt)
2210{
2211 int ret = 0;
2212 if (numOnHalFilled == 0)
2213 ret = -1;
2214 else {
2215 *reqFrameCnt = entries[ispEnqueueHead].reqFrameCnt;
2216 ret = ispEnqueueHead;
2217 }
2218 ALOGV("DEBUG(%s): returning BayerIndex[%d]", __FUNCTION__, ret);
2219 return ret;
2220}
2221
2222int BayerBufManager::GetIndexForIspDequeue(int *reqFrameCnt)
2223{
2224 int ret = 0;
2225 if (numOnIsp == 0)
2226 ret = -1;
2227 else {
2228 *reqFrameCnt = entries[ispDequeueHead].reqFrameCnt;
2229 ret = ispDequeueHead;
2230 }
2231 ALOGV("DEBUG(%s): returning BayerIndex[%d]", __FUNCTION__, ret);
2232 return ret;
2233}
2234
2235int BayerBufManager::MarkIspEnqueue(int index)
2236{
2237 ALOGV("DEBUG(%s) : BayerIndex[%d] ", __FUNCTION__, index);
2238
2239 // sanity check
2240 if (index != ispEnqueueHead) {
2241 ALOGV("DEBUG(%s) : Abnormal BayerIndex[%d] - expected[%d]", __FUNCTION__, index, ispEnqueueHead);
2242 return -1;
2243 }
2244 if (entries[index].status != BAYER_ON_HAL_FILLED) {
2245 ALOGV("DEBUG(%s) : Abnormal status in BayerIndex[%d] = (%d) expected (%d)", __FUNCTION__,
2246 index, entries[index].status, BAYER_ON_HAL_FILLED);
2247 return -1;
2248 }
2249
2250 entries[index].status = BAYER_ON_ISP;
2251 numOnHalFilled--;
2252 numOnIsp++;
2253 ispEnqueueHead = GetNextIndex(index);
2254 ALOGV("DEBUG(%s) END: HAL-e(%d) HAL-f(%d) Sensor(%d) ISP(%d) ",
2255 __FUNCTION__, numOnHalEmpty, numOnHalFilled, numOnSensor, numOnIsp);
2256 return 0;
2257}
2258
2259int BayerBufManager::MarkIspDequeue(int index)
2260{
2261 ALOGV("DEBUG(%s) : BayerIndex[%d]", __FUNCTION__, index);
2262
2263 // sanity check
2264 if (index != ispDequeueHead) {
2265 ALOGV("DEBUG(%s) : Abnormal BayerIndex[%d] - expected[%d]", __FUNCTION__, index, ispDequeueHead);
2266 return -1;
2267 }
2268 if (entries[index].status != BAYER_ON_ISP) {
2269 ALOGV("DEBUG(%s) : Abnormal status in BayerIndex[%d] = (%d) expected (%d)", __FUNCTION__,
2270 index, entries[index].status, BAYER_ON_ISP);
2271 return -1;
2272 }
2273
2274 entries[index].status = BAYER_ON_HAL_EMPTY;
2275 entries[index].reqFrameCnt = 0;
2276 numOnHalEmpty++;
2277 numOnIsp--;
2278 ispDequeueHead = GetNextIndex(index);
2279 ALOGV("DEBUG(%s) END: HAL-e(%d) HAL-f(%d) Sensor(%d) ISP(%d) ",
2280 __FUNCTION__, numOnHalEmpty, numOnHalFilled, numOnSensor, numOnIsp);
2281 return 0;
2282}
2283
2284int BayerBufManager::GetNumOnSensor()
2285{
2286 return numOnSensor;
2287}
2288
2289int BayerBufManager::GetNumOnHalFilled()
2290{
2291 return numOnHalFilled;
2292}
2293
2294int BayerBufManager::GetNumOnIsp()
2295{
2296 return numOnIsp;
2297}
2298
2299int BayerBufManager::GetNextIndex(int index)
2300{
2301 index++;
2302 if (index >= NUM_BAYER_BUFFERS)
2303 index = 0;
2304
2305 return index;
Sungjoong Kang13d8c7b2012-07-14 10:20:39 +09002306}
Jiyoung Shinc15a6b02012-06-05 01:08:14 -07002307
2308void ExynosCameraHWInterface2::m_mainThreadFunc(SignalDrivenThread * self)
2309{
2310 camera_metadata_t *currentRequest = NULL;
2311 camera_metadata_t *currentFrame = NULL;
2312 size_t numEntries = 0;
Sungjoong Kang13d8c7b2012-07-14 10:20:39 +09002313 size_t frameSize = 0;
Jiyoung Shinc15a6b02012-06-05 01:08:14 -07002314 camera_metadata_t * preparedFrame = NULL;
2315 camera_metadata_t *deregisteredRequest = NULL;
2316 uint32_t currentSignal = self->GetProcessingSignal();
Sungjoong Kang13d8c7b2012-07-14 10:20:39 +09002317 MainThread * selfThread = ((MainThread*)self);
Jiyoung Shinc15a6b02012-06-05 01:08:14 -07002318 int res = 0;
Sungjoong Kang13d8c7b2012-07-14 10:20:39 +09002319
Sungjoong Kangad378612012-08-17 12:34:33 -07002320 int ret;
2321
Sungjoong Kang13d8c7b2012-07-14 10:20:39 +09002322 ALOGV("DEBUG(%s): m_mainThreadFunc (%x)", __FUNCTION__, currentSignal);
2323
2324 if (currentSignal & SIGNAL_THREAD_RELEASE) {
2325 ALOGV("DEBUG(%s): processing SIGNAL_THREAD_RELEASE", __FUNCTION__);
2326
2327 ALOGV("DEBUG(%s): processing SIGNAL_THREAD_RELEASE DONE", __FUNCTION__);
2328 selfThread->SetSignal(SIGNAL_THREAD_TERMINATE);
2329 return;
2330 }
2331
Jiyoung Shinc15a6b02012-06-05 01:08:14 -07002332 if (currentSignal & SIGNAL_MAIN_REQ_Q_NOT_EMPTY) {
Sungjoong Kang13d8c7b2012-07-14 10:20:39 +09002333 ALOGV("DEBUG(%s): MainThread processing SIGNAL_MAIN_REQ_Q_NOT_EMPTY", __FUNCTION__);
Sungjoong Kangad378612012-08-17 12:34:33 -07002334 if (m_requestManager->IsRequestQueueFull()==false) {
Jiyoung Shinc15a6b02012-06-05 01:08:14 -07002335 m_requestQueueOps->dequeue_request(m_requestQueueOps, &currentRequest);
2336 if (NULL == currentRequest) {
Sungjoong Kangad378612012-08-17 12:34:33 -07002337 ALOGE("DEBUG(%s)(0x%x): dequeue_request returned NULL ", __FUNCTION__, currentSignal);
Sungjoong Kang13d8c7b2012-07-14 10:20:39 +09002338 m_isRequestQueueNull = true;
Jiyoung Shinc15a6b02012-06-05 01:08:14 -07002339 }
2340 else {
2341 m_requestManager->RegisterRequest(currentRequest);
Sungjoong Kang13d8c7b2012-07-14 10:20:39 +09002342
Jiyoung Shinc15a6b02012-06-05 01:08:14 -07002343 m_numOfRemainingReqInSvc = m_requestQueueOps->request_count(m_requestQueueOps);
Sungjoong Kang13d8c7b2012-07-14 10:20:39 +09002344 ALOGV("DEBUG(%s): remaining req cnt (%d)", __FUNCTION__, m_numOfRemainingReqInSvc);
Sungjoong Kangad378612012-08-17 12:34:33 -07002345 if (m_requestManager->IsRequestQueueFull()==false)
Sungjoong Kang13d8c7b2012-07-14 10:20:39 +09002346 selfThread->SetSignal(SIGNAL_MAIN_REQ_Q_NOT_EMPTY); // dequeue repeatedly
Sungjoong Kang9dd63e12012-07-24 00:25:51 +09002347
Jiyoung Shinc15a6b02012-06-05 01:08:14 -07002348 m_sensorThread->SetSignal(SIGNAL_SENSOR_START_REQ_PROCESSING);
2349 }
2350 }
2351 else {
2352 m_isRequestQueuePending = true;
2353 }
2354 }
2355
2356 if (currentSignal & SIGNAL_MAIN_STREAM_OUTPUT_DONE) {
Sungjoong Kang13d8c7b2012-07-14 10:20:39 +09002357 ALOGV("DEBUG(%s): MainThread processing SIGNAL_MAIN_STREAM_OUTPUT_DONE", __FUNCTION__);
2358 /*while (1)*/ {
Sungjoong Kang0f26b202012-08-17 15:43:12 -07002359 ret = m_requestManager->PrepareFrame(&numEntries, &frameSize, &preparedFrame, GetAfStateForService());
Sungjoong Kangad378612012-08-17 12:34:33 -07002360 if (ret == false)
2361 ALOGD("++++++ PrepareFrame ret = %d", ret);
2362
Sungjoong Kang13d8c7b2012-07-14 10:20:39 +09002363 m_requestManager->DeregisterRequest(&deregisteredRequest);
Sungjoong Kangad378612012-08-17 12:34:33 -07002364
2365 ret = m_requestQueueOps->free_request(m_requestQueueOps, deregisteredRequest);
2366 if (ret < 0)
2367 ALOGD("++++++ free_request ret = %d", ret);
2368
2369 ret = m_frameQueueOps->dequeue_frame(m_frameQueueOps, numEntries, frameSize, &currentFrame);
2370 if (ret < 0)
2371 ALOGD("++++++ dequeue_frame ret = %d", ret);
2372
Sungjoong Kang13d8c7b2012-07-14 10:20:39 +09002373 if (currentFrame==NULL) {
Sungjoong Kangad378612012-08-17 12:34:33 -07002374 ALOGV("DBG(%s): frame dequeue returned NULL",__FUNCTION__ );
Sungjoong Kang13d8c7b2012-07-14 10:20:39 +09002375 }
2376 else {
Sungjoong Kangdaa1fcd2012-08-08 11:49:43 -07002377 ALOGV("DEBUG(%s): frame dequeue done. numEntries(%d) frameSize(%d)",__FUNCTION__ , numEntries, frameSize);
Sungjoong Kang13d8c7b2012-07-14 10:20:39 +09002378 }
2379 res = append_camera_metadata(currentFrame, preparedFrame);
2380 if (res==0) {
2381 ALOGV("DEBUG(%s): frame metadata append success",__FUNCTION__);
2382 m_frameQueueOps->enqueue_frame(m_frameQueueOps, currentFrame);
2383 }
2384 else {
2385 ALOGE("ERR(%s): frame metadata append fail (%d)",__FUNCTION__, res);
2386 }
Jiyoung Shinc15a6b02012-06-05 01:08:14 -07002387 }
Sungjoong Kang13d8c7b2012-07-14 10:20:39 +09002388 if (!m_isRequestQueueNull) {
2389 selfThread->SetSignal(SIGNAL_MAIN_REQ_Q_NOT_EMPTY);
Jiyoung Shinc15a6b02012-06-05 01:08:14 -07002390 }
Sungjoong Kang9dd63e12012-07-24 00:25:51 +09002391
Sungjoong Kang13d8c7b2012-07-14 10:20:39 +09002392 if (getInProgressCount()>0) {
2393 ALOGV("DEBUG(%s): STREAM_OUTPUT_DONE and signalling REQ_PROCESSING",__FUNCTION__);
2394 m_sensorThread->SetSignal(SIGNAL_SENSOR_START_REQ_PROCESSING);
Jiyoung Shinc15a6b02012-06-05 01:08:14 -07002395 }
Jiyoung Shinc15a6b02012-06-05 01:08:14 -07002396 }
Sungjoong Kang13d8c7b2012-07-14 10:20:39 +09002397 ALOGV("DEBUG(%s): MainThread Exit", __FUNCTION__);
Jiyoung Shinc15a6b02012-06-05 01:08:14 -07002398 return;
2399}
Sungjoong Kang13d8c7b2012-07-14 10:20:39 +09002400
Jiyoung Shinc15a6b02012-06-05 01:08:14 -07002401void ExynosCameraHWInterface2::m_sensorThreadInitialize(SignalDrivenThread * self)
2402{
Sungjoong Kang13d8c7b2012-07-14 10:20:39 +09002403 ALOGV("DEBUG(%s): ", __FUNCTION__ );
Sungjoong Kangad378612012-08-17 12:34:33 -07002404 /* will add */
Sungjoong Kang13d8c7b2012-07-14 10:20:39 +09002405 return;
2406}
2407
2408
Sungjoong Kang13d8c7b2012-07-14 10:20:39 +09002409void ExynosCameraHWInterface2::DumpInfoWithShot(struct camera2_shot_ext * shot_ext)
2410{
Sungjoong Kangad378612012-08-17 12:34:33 -07002411 ALOGD("#### common Section");
2412 ALOGD("#### magic(%x) ",
Sungjoong Kang13d8c7b2012-07-14 10:20:39 +09002413 shot_ext->shot.magicNumber);
Sungjoong Kangad378612012-08-17 12:34:33 -07002414 ALOGD("#### ctl Section");
2415 ALOGD("#### meta(%d) aper(%f) exp(%lld) duration(%lld) ISO(%d) AWB(%d)",
Sungjoong Kang13d8c7b2012-07-14 10:20:39 +09002416 shot_ext->shot.ctl.request.metadataMode,
Sungjoong Kangb56dcc02012-08-08 13:38:09 -07002417 shot_ext->shot.ctl.lens.aperture,
Sungjoong Kang13d8c7b2012-07-14 10:20:39 +09002418 shot_ext->shot.ctl.sensor.exposureTime,
2419 shot_ext->shot.ctl.sensor.frameDuration,
Sungjoong Kangb56dcc02012-08-08 13:38:09 -07002420 shot_ext->shot.ctl.sensor.sensitivity,
2421 shot_ext->shot.ctl.aa.awbMode);
Sungjoong Kang13d8c7b2012-07-14 10:20:39 +09002422
Sungjoong Kang74d78eb2012-08-29 13:25:46 -07002423 ALOGD("#### OutputStream Sensor(%d) SCP(%d) SCC(%d) pv(%d) rec(%d) previewCb(%d)",
Sungjoong Kang9dd63e12012-07-24 00:25:51 +09002424 shot_ext->request_sensor, shot_ext->request_scp, shot_ext->request_scc,
Sungjoong Kang74d78eb2012-08-29 13:25:46 -07002425 shot_ext->shot.ctl.request.outputStreams[0], shot_ext->shot.ctl.request.outputStreams[2],
2426 shot_ext->shot.ctl.request.outputStreams[3]);
Sungjoong Kang13d8c7b2012-07-14 10:20:39 +09002427
Sungjoong Kangad378612012-08-17 12:34:33 -07002428 ALOGD("#### DM Section");
2429 ALOGD("#### meta(%d) aper(%f) exp(%lld) duration(%lld) ISO(%d) timestamp(%lld) AWB(%d) cnt(%d)",
Sungjoong Kang13d8c7b2012-07-14 10:20:39 +09002430 shot_ext->shot.dm.request.metadataMode,
Sungjoong Kangb56dcc02012-08-08 13:38:09 -07002431 shot_ext->shot.dm.lens.aperture,
Sungjoong Kang13d8c7b2012-07-14 10:20:39 +09002432 shot_ext->shot.dm.sensor.exposureTime,
2433 shot_ext->shot.dm.sensor.frameDuration,
2434 shot_ext->shot.dm.sensor.sensitivity,
Sungjoong Kangb56dcc02012-08-08 13:38:09 -07002435 shot_ext->shot.dm.sensor.timeStamp,
2436 shot_ext->shot.dm.aa.awbMode,
2437 shot_ext->shot.dm.request.frameCount );
Sungjoong Kang13d8c7b2012-07-14 10:20:39 +09002438}
2439
Younghwan Joo6f19b6c2012-08-30 13:56:53 -07002440void ExynosCameraHWInterface2::flashSetter(struct camera2_shot_ext * shot_ext)
2441{
2442 // 1. AF Flash
2443 if (m_afFlashEnableFlg) {
2444 switch (m_afFlashCnt) {
2445 case IS_FLASH_AF_ON:
2446 ALOGE("(%s): [AF Flash] IS_FLASH_ON", __FUNCTION__);
2447 shot_ext->shot.ctl.aa.aeflashMode = AA_FLASHMODE_ON;
2448 m_afFlashCnt = IS_FLASH_AF_ON_START;
2449 break;
2450 case IF_FLASH_AF_OFF:
2451 ALOGE("(%s): [AF Flash] IS_FLASH_OFF and status clear", __FUNCTION__);
2452 shot_ext->shot.ctl.aa.aeflashMode = AA_FLASHMODE_OFF;
2453 m_afFlashEnableFlg = false;
2454 m_afFlashCnt = 0;
2455 break;
2456 }
2457 }
2458
2459 // 2. Flash
2460 if (m_flashEnableFlg) {
2461 switch (m_flashCnt) {
2462 case IS_FLASH_ON:
2463 ALOGE("(%s): [Flash] Flash ON for Capture", __FUNCTION__);
2464 shot_ext->shot.ctl.aa.aeflashMode = AA_FLASHMODE_ON;
2465 shot_ext->shot.ctl.aa.awbMode = AA_AWBMODE_WB_AUTO;
2466 break;
2467 case IS_FLASH_ON_DONE:
2468 shot_ext->shot.ctl.aa.awbMode = AA_AWBMODE_LOCKED;
2469 shot_ext->shot.ctl.aa.aeflashMode = AA_FLASHMODE_AUTO;
2470 m_flashCnt = IS_FLASH_AUTO_AE_AWB_LOCK; // auto transition
2471 shot_ext->request_scc = 0;
2472 break;
2473 case IS_FLASH_AUTO_AE_AWB_LOCK:
2474 shot_ext->request_scc = 0;
2475 break;
2476 case IS_FLASH_AUTO_END:
2477 shot_ext->request_scc = 0;
2478 break;
2479 case IS_FLASH_AUTO_AE_AWB_LOCKED_AUTO_END:
2480 m_flashCnt = IS_FLASH_CAPTURE;
2481 shot_ext->shot.ctl.aa.aeflashMode = AA_FLASHMODE_CAPTURE;
2482 shot_ext->request_scc = 1;
2483 break;
2484 case IS_FLASH_CAPTURE:
2485 shot_ext->request_scc = 0;
2486 break;
2487 case IS_FLASH_CAPTURE_JPEG:
2488 shot_ext->request_scc = 0;
2489 m_flashCaptured = true;
2490 m_flashEnableFlg = false;
2491 m_flashCnt = 0;
2492 break;
2493 }
2494 }
2495}
2496
2497void ExynosCameraHWInterface2::flashListener(struct camera2_shot_ext * shot_ext)
2498{
2499 if (m_flashCaptured) {
2500 shot_ext->shot.ctl.aa.aeflashMode = AA_FLASHMODE_OFF;
2501 shot_ext->shot.ctl.aa.awbMode = AA_AWBMODE_WB_AUTO;
2502 ALOGE("(%s): [Flash] Flash off after Capture", __FUNCTION__);
2503 m_flashCaptured = false;
2504 }
2505
2506 // 1. AF Flash
2507 if (m_afFlashEnableFlg) {
2508 ALOGV("(%s), [AF Flash] aa.aeflashMode : (ctl,dm) - (%d , %d)", __FUNCTION__, shot_ext->shot.ctl.aa.aeflashMode, shot_ext->shot.dm.aa.aeflashMode);
2509 ALOGV("(%s), [AF Flash] flash.flashMode : (ctl,dm) - (%d , %d)", __FUNCTION__, shot_ext->shot.ctl.flash.flashMode, shot_ext->shot.dm.flash.flashMode);
2510
2511 switch (m_afFlashCnt) {
2512 case IS_FLASH_AF_ON_START:
2513 if (shot_ext->shot.dm.flash.flashMode == CAM2_FLASH_MODE_TORCH) {
2514 m_afFlashCnt = IS_FLASH_AF_ON_DONE;
2515 ALOGV("(%s): [AF Flash] Lis : dm.aa.aeflashMode == AA_FLASHMODE_ON", __FUNCTION__);
2516 m_IsAfTriggerRequired = true;
2517 } else {
2518 if (m_flashTimeOut == 0)
2519 m_afFlashCnt = IS_FLASH_AF_ON_DONE;
2520 else
2521 m_flashTimeOut--;
2522 }
2523 break;
2524 case IF_FLASH_AF_OFF:
2525 ALOGD("(%s): [AF Flash] Lis : IS_FLASH_OFF : status clear", __FUNCTION__);
2526 break;
2527 }
2528 }
2529
2530 // 2. Flash
2531 if (m_flashEnableFlg) {
2532 switch (m_flashCnt) {
2533 case IS_FLASH_ON:
2534 if (shot_ext->shot.dm.flash.flashMode == CAM2_FLASH_MODE_TORCH) {
2535 m_flashCnt = IS_FLASH_ON_DONE;
2536 } else {
2537 ALOGV("(%s): [Flash] Waiting : dm.flash.flashMode == ANDROID_FLASH_TORCH", __FUNCTION__);
2538 m_flashTimeOut--;
2539 if (m_flashTimeOut == 0)
2540 m_flashCnt = IS_FLASH_CAPTURE_JPEG;
2541 }
2542 break;
2543 case IS_FLASH_AUTO_AE_AWB_LOCK:
2544 if (shot_ext->shot.dm.flash.flashMode == CAM2_FLASH_MODE_TORCH) {
2545 m_flashCnt = IS_FLASH_AUTO_END;
2546 } else {
2547 ALOGV("(%s): [Flash] Waiting : dm.flash.flashMode== AA_FLASHMODE_AUTO", __FUNCTION__);
2548 }
2549 break;
2550 case IS_FLASH_AUTO_END:
2551 if (shot_ext->shot.dm.flash.flashMode == CAM2_FLASH_MODE_OFF) {
2552 m_flashCnt = IS_FLASH_AUTO_AE_AWB_LOCKED_AUTO_END;
2553 } else {
2554 ALOGV("(%s): [Flash] Waiting : dm.aa.awbMode == AA_AWBMODE_LOCKED and dm.flash.flashMode== CAM2_FLASH_MODE_OFF", __FUNCTION__);
2555 }
2556 break;
2557 case IS_FLASH_CAPTURE:
2558 if (shot_ext->shot.dm.flash.flashMode == CAM2_FLASH_MODE_SINGLE) {
2559 m_flashCnt = IS_FLASH_CAPTURE_JPEG;
2560 } else {
2561 ALOGV("(%s): [Flash] Waiting : ctl.aa.aeflashMode == AA_FLASHMODE_CAPTURE", __FUNCTION__);
2562 }
2563 break;
2564 }
2565 }
2566
2567}
2568
Sungjoong Kang13d8c7b2012-07-14 10:20:39 +09002569void ExynosCameraHWInterface2::m_sensorThreadFunc(SignalDrivenThread * self)
2570{
2571 uint32_t currentSignal = self->GetProcessingSignal();
2572 SensorThread * selfThread = ((SensorThread*)self);
2573 int index;
Sungjoong Kangad378612012-08-17 12:34:33 -07002574 int index_isp;
Sungjoong Kang13d8c7b2012-07-14 10:20:39 +09002575 status_t res;
2576 nsecs_t frameTime;
2577 int bayersOnSensor = 0, bayersOnIsp = 0;
Sungjoong Kangad378612012-08-17 12:34:33 -07002578 int j = 0;
2579 bool isCapture = false;
Sungjoong Kang13d8c7b2012-07-14 10:20:39 +09002580 ALOGV("DEBUG(%s): m_sensorThreadFunc (%x)", __FUNCTION__, currentSignal);
2581
2582 if (currentSignal & SIGNAL_THREAD_RELEASE) {
Sungjoong Kangad378612012-08-17 12:34:33 -07002583 ALOGV("(%s): ENTER processing SIGNAL_THREAD_RELEASE", __FUNCTION__);
Sungjoong Kang13d8c7b2012-07-14 10:20:39 +09002584
Sungjoong Kang9dd63e12012-07-24 00:25:51 +09002585 ALOGV("(%s): calling sensor streamoff", __FUNCTION__);
Sungjoong Kang13d8c7b2012-07-14 10:20:39 +09002586 cam_int_streamoff(&(m_camera_info.sensor));
Sungjoong Kang9dd63e12012-07-24 00:25:51 +09002587 ALOGV("(%s): calling sensor streamoff done", __FUNCTION__);
Sungjoong Kangb5237e62012-07-27 07:39:05 -07002588
2589 m_camera_info.sensor.buffers = 0;
2590 ALOGV("DEBUG(%s): sensor calling reqbuf 0 ", __FUNCTION__);
2591 cam_int_reqbufs(&(m_camera_info.sensor));
2592 ALOGV("DEBUG(%s): sensor calling reqbuf 0 done", __FUNCTION__);
Sungjoong Kangad378612012-08-17 12:34:33 -07002593
Sungjoong Kang9dd63e12012-07-24 00:25:51 +09002594 ALOGV("(%s): calling ISP streamoff", __FUNCTION__);
2595 isp_int_streamoff(&(m_camera_info.isp));
2596 ALOGV("(%s): calling ISP streamoff done", __FUNCTION__);
Sungjoong Kangad378612012-08-17 12:34:33 -07002597
Sungjoong Kangb5237e62012-07-27 07:39:05 -07002598 m_camera_info.isp.buffers = 0;
2599 ALOGV("DEBUG(%s): isp calling reqbuf 0 ", __FUNCTION__);
2600 cam_int_reqbufs(&(m_camera_info.isp));
2601 ALOGV("DEBUG(%s): isp calling reqbuf 0 done", __FUNCTION__);
2602
Sungjoong Kang13d8c7b2012-07-14 10:20:39 +09002603 exynos_v4l2_s_ctrl(m_camera_info.sensor.fd, V4L2_CID_IS_S_STREAM, IS_DISABLE_STREAM);
Sungjoong Kang13d8c7b2012-07-14 10:20:39 +09002604
Sungjoong Kangad378612012-08-17 12:34:33 -07002605 ALOGV("(%s): EXIT processing SIGNAL_THREAD_RELEASE", __FUNCTION__);
Sungjoong Kang13d8c7b2012-07-14 10:20:39 +09002606 selfThread->SetSignal(SIGNAL_THREAD_TERMINATE);
2607 return;
2608 }
2609
2610 if (currentSignal & SIGNAL_SENSOR_START_REQ_PROCESSING)
2611 {
2612 ALOGV("DEBUG(%s): SensorThread processing SIGNAL_SENSOR_START_REQ_PROCESSING", __FUNCTION__);
Sungjoong Kang9dd63e12012-07-24 00:25:51 +09002613 int targetStreamIndex = 0, i=0;
Sungjoong Kangad378612012-08-17 12:34:33 -07002614 int matchedFrameCnt = -1, processingReqIndex;
Sungjoong Kang13d8c7b2012-07-14 10:20:39 +09002615 struct camera2_shot_ext *shot_ext;
Sungjoong Kangad378612012-08-17 12:34:33 -07002616 struct camera2_shot_ext *shot_ext_capture;
Sungjoong Kang0f26b202012-08-17 15:43:12 -07002617 bool triggered = false;
2618 int afMode;
Sungjoong Kang9dd63e12012-07-24 00:25:51 +09002619
Sungjoong Kangad378612012-08-17 12:34:33 -07002620 /* dqbuf from sensor */
2621 ALOGV("Sensor DQbuf start");
Sungjoong Kang13d8c7b2012-07-14 10:20:39 +09002622 index = cam_int_dqbuf(&(m_camera_info.sensor));
Sungjoong Kang9dd63e12012-07-24 00:25:51 +09002623 shot_ext = (struct camera2_shot_ext *)(m_camera_info.sensor.buffer[index].virt.extP[1]);
Sungjoong Kangad378612012-08-17 12:34:33 -07002624
2625 m_recordOutput = shot_ext->shot.ctl.request.outputStreams[2];
Sungjoong Kang74d78eb2012-08-29 13:25:46 -07002626 m_previewCbOutput = shot_ext->shot.ctl.request.outputStreams[3];
Sungjoong Kangad378612012-08-17 12:34:33 -07002627
Sungjoong Kanga15b4e32012-08-28 12:55:39 -07002628 if (m_nightCaptureCnt != 0) {
2629 matchedFrameCnt = m_nightCaptureFrameCnt;
Younghwan Joo6f19b6c2012-08-30 13:56:53 -07002630 } else if (m_flashCnt != 0) {
2631 matchedFrameCnt = m_flashFrameCount;
2632 ALOGD("Skip frame, request is fixed at %d", matchedFrameCnt);
2633 } else {
Sungjoong Kanga15b4e32012-08-28 12:55:39 -07002634 matchedFrameCnt = m_requestManager->FindFrameCnt(shot_ext);
2635 }
Sungjoong Kangad378612012-08-17 12:34:33 -07002636
Sungjoong Kanga07cbd92012-07-27 12:03:29 -07002637 if (matchedFrameCnt != -1) {
Sungjoong Kangef6f83c2012-08-28 22:59:48 +09002638 frameTime = systemTime();
2639 m_requestManager->RegisterTimestamp(matchedFrameCnt, &frameTime);
2640 m_requestManager->UpdateIspParameters(shot_ext, matchedFrameCnt);
Sungjoong Kang8e2c2fd2012-08-27 00:02:22 -07002641 if (m_afModeWaitingCnt != 0) {
2642 ALOGV("### Af Trigger pulled, waiting for mode change cnt(%d) ", m_afModeWaitingCnt);
2643 m_afModeWaitingCnt --;
2644 if (m_afModeWaitingCnt == 1) {
Sungjoong Kangcd13bb72012-08-28 13:05:01 -07002645 m_afModeWaitingCnt = 0;
Sungjoong Kang8e2c2fd2012-08-27 00:02:22 -07002646 OnAfTrigger(m_afPendingTriggerId);
2647 }
2648 }
hyeonmyeong Choi308291d2012-08-29 13:55:01 -07002649 m_zoomRatio = (float)m_camera2->getSensorW() / (float)shot_ext->shot.ctl.scaler.cropRegion[2];
Sungjoong Kange4657e32012-08-28 15:02:19 -07002650 float zoomLeft, zoomTop, zoomWidth, zoomHeight;
2651 int crop_x = 0, crop_y = 0, crop_w = 0, crop_h = 0;
2652
2653 m_getRatioSize(m_camera2->getSensorW(), m_camera2->getSensorH(),
2654 m_streamThreads[0]->m_parameters.outputWidth, m_streamThreads[0]->m_parameters.outputHeight,
2655 &crop_x, &crop_y,
2656 &crop_w, &crop_h,
2657 0);
2658
2659 if (m_streamThreads[0]->m_parameters.outputWidth >= m_streamThreads[0]->m_parameters.outputHeight) {
hyeonmyeong Choi308291d2012-08-29 13:55:01 -07002660 zoomWidth = m_camera2->getSensorW() / m_zoomRatio;
Sungjoong Kange4657e32012-08-28 15:02:19 -07002661 zoomHeight = zoomWidth *
2662 m_streamThreads[0]->m_parameters.outputHeight / m_streamThreads[0]->m_parameters.outputWidth;
2663 } else {
hyeonmyeong Choi308291d2012-08-29 13:55:01 -07002664 zoomHeight = m_camera2->getSensorH() / m_zoomRatio;
Sungjoong Kange4657e32012-08-28 15:02:19 -07002665 zoomWidth = zoomHeight *
2666 m_streamThreads[0]->m_parameters.outputWidth / m_streamThreads[0]->m_parameters.outputHeight;
2667 }
2668 zoomLeft = (crop_w - zoomWidth) / 2;
2669 zoomTop = (crop_h - zoomHeight) / 2;
2670
2671 int32_t new_cropRegion[3] = { zoomLeft, zoomTop, zoomWidth };
2672
hyeonmyeong Choi308291d2012-08-29 13:55:01 -07002673 if (new_cropRegion[0] * 2 + new_cropRegion[2] > m_camera2->getSensorW())
2674 new_cropRegion[2]--;
2675 else if (new_cropRegion[0] * 2 + new_cropRegion[2] < m_camera2->getSensorW())
2676 new_cropRegion[2]++;
2677
Sungjoong Kange4657e32012-08-28 15:02:19 -07002678 shot_ext->shot.ctl.scaler.cropRegion[0] = new_cropRegion[0];
2679 shot_ext->shot.ctl.scaler.cropRegion[1] = new_cropRegion[1];
2680 shot_ext->shot.ctl.scaler.cropRegion[2] = new_cropRegion[2];
Sungjoong Kang0f26b202012-08-17 15:43:12 -07002681 if (m_IsAfModeUpdateRequired) {
2682 ALOGE("### AF Mode change(Mode %d) ", m_afMode);
2683 shot_ext->shot.ctl.aa.afMode = m_afMode;
2684 if (m_afMode == AA_AFMODE_CONTINUOUS_VIDEO || m_afMode == AA_AFMODE_CONTINUOUS_PICTURE) {
2685 ALOGE("### With Automatic triger for continuous modes");
2686 m_afState = HAL_AFSTATE_STARTED;
2687 shot_ext->shot.ctl.aa.afTrigger = 1;
2688 triggered = true;
2689 }
2690 m_IsAfModeUpdateRequired = false;
2691 if (m_afMode2 != NO_CHANGE) {
2692 enum aa_afmode tempAfMode = m_afMode2;
2693 m_afMode2 = NO_CHANGE;
2694 SetAfMode(tempAfMode);
2695 }
2696 }
2697 else {
2698 shot_ext->shot.ctl.aa.afMode = NO_CHANGE;
2699 }
2700 if (m_IsAfTriggerRequired) {
2701 ALOGE("### AF Triggering with mode (%d)", m_afMode);
Younghwan Joo6f19b6c2012-08-30 13:56:53 -07002702 // Flash triggering with AF
2703 if ((shot_ext->shot.ctl.aa.aeMode >= AA_AEMODE_ON_AUTO_FLASH) && (m_afFlashEnableFlg == false)
2704 && (m_cameraId == 0)) {
2705 m_afFlashEnableFlg = true;
2706 m_flashTimeOut = 3;
2707 m_afFlashCnt = IS_FLASH_AF_ON;
Sungjoong Kang36c106c2012-08-23 17:38:20 -07002708 }
Younghwan Joo6f19b6c2012-08-30 13:56:53 -07002709 if (m_afFlashEnableFlg) {
2710 if (m_afFlashCnt == IS_FLASH_AF_ON_DONE) {
2711 // Flash is enabled and start AF
2712 if (m_afState == HAL_AFSTATE_SCANNING) {
2713 ALOGE("(%s): restarting trigger ", __FUNCTION__);
2714 } else {
2715 if (m_afState != HAL_AFSTATE_NEEDS_COMMAND)
2716 ALOGE("(%s): wrong trigger state %d", __FUNCTION__, m_afState);
2717 else
2718 m_afState = HAL_AFSTATE_STARTED;
2719 }
2720 shot_ext->shot.ctl.aa.afTrigger = 1;
2721 shot_ext->shot.ctl.aa.afMode = m_afMode;
2722 m_IsAfTriggerRequired = false;
2723 }
2724 } else {
2725 if (m_afState == HAL_AFSTATE_SCANNING) {
2726 ALOGE("(%s): restarting trigger ", __FUNCTION__);
2727 } else {
2728 if (m_afState != HAL_AFSTATE_NEEDS_COMMAND)
2729 ALOGE("(%s): wrong trigger state %d", __FUNCTION__, m_afState);
2730 else
2731 m_afState = HAL_AFSTATE_STARTED;
2732 }
2733 shot_ext->shot.ctl.aa.afTrigger = 1;
2734 shot_ext->shot.ctl.aa.afMode = m_afMode;
2735 m_IsAfTriggerRequired = false;
Sungjoong Kang36c106c2012-08-23 17:38:20 -07002736 }
Sungjoong Kang0f26b202012-08-17 15:43:12 -07002737 }
2738 else {
Sungjoong Kang8e2c2fd2012-08-27 00:02:22 -07002739 shot_ext->shot.ctl.aa.afTrigger = 0;
Sungjoong Kang0f26b202012-08-17 15:43:12 -07002740 }
Sungjoong Kangb55ed662012-08-31 21:31:34 -07002741 if (m_aspectChanged) {
2742 shot_ext->shot.ctl.aa.aeTargetFpsRange[0] = 15;
Sungjoong Kang15fd8232012-08-23 16:16:44 -07002743 shot_ext->shot.ctl.aa.aeTargetFpsRange[1] = 30;
Sungjoong Kangb55ed662012-08-31 21:31:34 -07002744 m_aspectChanged = false;
Sungjoong Kang15fd8232012-08-23 16:16:44 -07002745 }
2746 else {
Sungjoong Kangb55ed662012-08-31 21:31:34 -07002747 if (m_wideAspect) {
2748 shot_ext->setfile = ISS_SUB_SCENARIO_VIDEO;
2749 shot_ext->shot.ctl.aa.aeTargetFpsRange[0] = 30;
2750 shot_ext->shot.ctl.aa.aeTargetFpsRange[1] = 30;
2751 }
2752 else {
2753 shot_ext->setfile = ISS_SUB_SCENARIO_STILL;
2754 }
Sungjoong Kang15fd8232012-08-23 16:16:44 -07002755 }
Sungjoong Kang0f26b202012-08-17 15:43:12 -07002756 if (triggered)
2757 shot_ext->shot.ctl.aa.afTrigger = 1;
2758
2759 // TODO : check collision with AFMode Update
2760 if (m_IsAfLockRequired) {
2761 shot_ext->shot.ctl.aa.afMode = AA_AFMODE_OFF;
2762 m_IsAfLockRequired = false;
2763 }
Rebecca Schultz Zavin4ed2f102012-08-22 00:55:29 -07002764 ALOGV("### Isp Qbuf start(%d) count (%d), SCP(%d) SCC(%d) DIS(%d) shot_size(%d)",
Sungjoong Kangad378612012-08-17 12:34:33 -07002765 index,
2766 shot_ext->shot.ctl.request.frameCount,
2767 shot_ext->request_scp,
2768 shot_ext->request_scc,
2769 shot_ext->dis_bypass, sizeof(camera2_shot));
Sungjoong Kanga15b4e32012-08-28 12:55:39 -07002770 ALOGV("### m_nightCaptureCnt (%d)", m_nightCaptureCnt);
Sungjoong Kang8e2c2fd2012-08-27 00:02:22 -07002771 if (0 == shot_ext->shot.ctl.aa.afRegions[0] && 0 == shot_ext->shot.ctl.aa.afRegions[1]
2772 && 0 == shot_ext->shot.ctl.aa.afRegions[2] && 0 == shot_ext->shot.ctl.aa.afRegions[3]) {
2773 ALOGV("(%s): AF region resetting", __FUNCTION__);
2774 lastAfRegion[0] = 0;
2775 lastAfRegion[1] = 0;
2776 lastAfRegion[2] = 0;
2777 lastAfRegion[3] = 0;
2778 }
2779 else {
2780 if (!(lastAfRegion[0] == shot_ext->shot.ctl.aa.afRegions[0] && lastAfRegion[1] == shot_ext->shot.ctl.aa.afRegions[1]
2781 && lastAfRegion[2] == shot_ext->shot.ctl.aa.afRegions[2] && lastAfRegion[3] == shot_ext->shot.ctl.aa.afRegions[3])) {
2782 ALOGV("(%s): AF region changed : triggering", __FUNCTION__);
2783 shot_ext->shot.ctl.aa.afTrigger = 1;
2784 shot_ext->shot.ctl.aa.afMode = m_afMode;
2785 m_afState = HAL_AFSTATE_STARTED;
2786 lastAfRegion[0] = shot_ext->shot.ctl.aa.afRegions[0];
2787 lastAfRegion[1] = shot_ext->shot.ctl.aa.afRegions[1];
2788 lastAfRegion[2] = shot_ext->shot.ctl.aa.afRegions[2];
2789 lastAfRegion[3] = shot_ext->shot.ctl.aa.afRegions[3];
2790 }
2791 }
Sungjoong Kanga15b4e32012-08-28 12:55:39 -07002792 if (m_nightCaptureCnt == 0) {
2793 if (shot_ext->shot.ctl.aa.captureIntent == ANDROID_CONTROL_INTENT_STILL_CAPTURE
2794 && shot_ext->shot.ctl.aa.sceneMode == AA_SCENE_MODE_NIGHT) {
2795 shot_ext->shot.ctl.aa.sceneMode = AA_SCENE_MODE_NIGHT_CAPTURE;
2796 shot_ext->shot.ctl.aa.aeTargetFpsRange[0] = 2;
2797 shot_ext->shot.ctl.aa.aeTargetFpsRange[1] = 30;
2798 m_nightCaptureCnt = 4;
2799 m_nightCaptureFrameCnt = matchedFrameCnt;
2800 shot_ext->request_scc = 0;
2801 }
2802 }
2803 else if (m_nightCaptureCnt == 1) {
2804 shot_ext->shot.ctl.aa.sceneMode = AA_SCENE_MODE_NIGHT_CAPTURE;
2805 shot_ext->shot.ctl.aa.aeTargetFpsRange[0] = 2;
2806 shot_ext->shot.ctl.aa.aeTargetFpsRange[1] = 30;
2807 m_nightCaptureCnt--;
2808 shot_ext->request_scc = 1;
2809 }
2810 else if (m_nightCaptureCnt == 2 || m_nightCaptureCnt == 3 || m_nightCaptureCnt == 4) {
2811 shot_ext->shot.ctl.aa.sceneMode = AA_SCENE_MODE_NIGHT_CAPTURE;
2812 shot_ext->shot.ctl.aa.aeTargetFpsRange[0] = 2;
2813 shot_ext->shot.ctl.aa.aeTargetFpsRange[1] = 30;
2814 m_nightCaptureCnt--;
2815 shot_ext->request_scc = 0;
2816 }
Younghwan Joo6f19b6c2012-08-30 13:56:53 -07002817
2818 // Flash mode
2819 // Keep and Skip request_scc = 1 at flash enable mode to operate flash sequence
2820 if ((shot_ext->shot.ctl.aa.aeMode >= AA_AEMODE_ON_AUTO_FLASH) && (m_flashEnableFlg == false)
2821 && (m_cameraId == 0)) {
2822 if (shot_ext->shot.ctl.aa.captureIntent == ANDROID_CONTROL_INTENT_STILL_CAPTURE) {
2823 ALOGE("(%s): [Flash] Flash capture start : skip request scc 1#####", __FUNCTION__);
2824 shot_ext->request_scc = 0;
2825 m_flashFrameCount = matchedFrameCnt;
2826 m_flashEnableFlg = true;
2827 m_flashCaptured = false;
2828 m_flashCnt = IS_FLASH_ON;
2829 m_flashTimeOut = 3;
2830 }
2831 }
2832
2833 flashListener(shot_ext);
2834 flashSetter(shot_ext);
Sungjoong Kang8e2c2fd2012-08-27 00:02:22 -07002835 ALOGV("(%s): queued aa(%d) aemode(%d) awb(%d) afmode(%d) trigger(%d)", __FUNCTION__,
2836 (int)(shot_ext->shot.ctl.aa.mode), (int)(shot_ext->shot.ctl.aa.aeMode),
2837 (int)(shot_ext->shot.ctl.aa.awbMode), (int)(shot_ext->shot.ctl.aa.afMode),
2838 (int)(shot_ext->shot.ctl.aa.afTrigger));
Sungjoong Kangad378612012-08-17 12:34:33 -07002839 cam_int_qbuf(&(m_camera_info.isp), index);
Sungjoong Kangad378612012-08-17 12:34:33 -07002840
2841 usleep(10000);
Sungjoong Kangad378612012-08-17 12:34:33 -07002842
2843 ALOGV("### isp DQBUF start");
2844 index_isp = cam_int_dqbuf(&(m_camera_info.isp));
Sungjoong Kangef6f83c2012-08-28 22:59:48 +09002845
Sungjoong Kangad378612012-08-17 12:34:33 -07002846
Sungjoong Kangad378612012-08-17 12:34:33 -07002847 shot_ext = (struct camera2_shot_ext *)(m_camera_info.isp.buffer[index_isp].virt.extP[1]);
2848
2849 ALOGV("### Isp DQbuf done(%d) count (%d), SCP(%d) SCC(%d) shot_size(%d)",
2850 index,
2851 shot_ext->shot.ctl.request.frameCount,
2852 shot_ext->request_scp,
2853 shot_ext->request_scc,
2854 shot_ext->dis_bypass, sizeof(camera2_shot));
Sungjoong Kangef6f83c2012-08-28 22:59:48 +09002855 ALOGV("(%s): DM aa(%d) aemode(%d) awb(%d) afmode(%d)", __FUNCTION__,
Sungjoong Kang8e2c2fd2012-08-27 00:02:22 -07002856 (int)(shot_ext->shot.dm.aa.mode), (int)(shot_ext->shot.dm.aa.aeMode),
2857 (int)(shot_ext->shot.dm.aa.awbMode),
2858 (int)(shot_ext->shot.dm.aa.afMode));
Sungjoong Kangad378612012-08-17 12:34:33 -07002859
Sungjoong Kangef6f83c2012-08-28 22:59:48 +09002860 m_previewOutput = 0;
Sungjoong Kangad378612012-08-17 12:34:33 -07002861 if (shot_ext->request_scp) {
2862 m_previewOutput = 1;
Sungjoong Kangb55ed662012-08-31 21:31:34 -07002863 m_scpOutputSignalCnt++;
Sungjoong Kangad378612012-08-17 12:34:33 -07002864 m_streamThreads[0]->SetSignal(SIGNAL_STREAM_DATA_COMING);
2865 }
Sungjoong Kang15fd8232012-08-23 16:16:44 -07002866 if (shot_ext->request_scc) {
Sungjoong Kanga15b4e32012-08-28 12:55:39 -07002867 ALOGV("### m_nightCaptureCnt (%d) request_scc true", m_nightCaptureCnt);
2868 memcpy(&m_jpegMetadata, &shot_ext->shot, sizeof(struct camera2_shot));
2869 int shutterSpeed = (m_jpegMetadata.dm.sensor.exposureTime/1000);
2870
2871 if (shutterSpeed < 0) {
2872 shutterSpeed = 100;
2873 }
Sungjoong Kang15fd8232012-08-23 16:16:44 -07002874 m_streamThreads[1]->SetSignal(SIGNAL_STREAM_DATA_COMING);
2875 }
Sungjoong Kangad378612012-08-17 12:34:33 -07002876
2877 ALOGV("(%s): SCP_CLOSING check sensor(%d) scc(%d) scp(%d) ", __FUNCTION__,
2878 shot_ext->request_sensor, shot_ext->request_scc, shot_ext->request_scp);
2879 if (shot_ext->request_scc + shot_ext->request_scp + shot_ext->request_sensor == 0) {
2880 ALOGV("(%s): SCP_CLOSING check OK ", __FUNCTION__);
2881 m_scp_closed = true;
2882 }
2883 else
2884 m_scp_closed = false;
2885
Sungjoong Kangfd2d78a2012-08-26 17:44:25 -07002886 if (!shot_ext->fd_bypass) {
2887 /* FD orientation axis transformation */
2888 for (int i=0; i < CAMERA2_MAX_FACES; i++) {
2889 if (shot_ext->shot.dm.stats.faceRectangles[i][0] > 0)
2890 shot_ext->shot.dm.stats.faceRectangles[i][0] = (m_camera2->m_curCameraInfo->sensorW
Sungjoong Kangef6f83c2012-08-28 22:59:48 +09002891 * shot_ext->shot.dm.stats.faceRectangles[i][0])
2892 / m_streamThreads[0].get()->m_parameters.outputWidth;
Sungjoong Kangfd2d78a2012-08-26 17:44:25 -07002893 if (shot_ext->shot.dm.stats.faceRectangles[i][1] > 0)
2894 shot_ext->shot.dm.stats.faceRectangles[i][1] = (m_camera2->m_curCameraInfo->sensorH
Sungjoong Kangef6f83c2012-08-28 22:59:48 +09002895 * shot_ext->shot.dm.stats.faceRectangles[i][1])
2896 / m_streamThreads[0].get()->m_parameters.outputHeight;
Sungjoong Kangfd2d78a2012-08-26 17:44:25 -07002897 if (shot_ext->shot.dm.stats.faceRectangles[i][2] > 0)
2898 shot_ext->shot.dm.stats.faceRectangles[i][2] = (m_camera2->m_curCameraInfo->sensorW
Sungjoong Kangef6f83c2012-08-28 22:59:48 +09002899 * shot_ext->shot.dm.stats.faceRectangles[i][2])
2900 / m_streamThreads[0].get()->m_parameters.outputWidth;
Sungjoong Kangfd2d78a2012-08-26 17:44:25 -07002901 if (shot_ext->shot.dm.stats.faceRectangles[i][3] > 0)
2902 shot_ext->shot.dm.stats.faceRectangles[i][3] = (m_camera2->m_curCameraInfo->sensorH
Sungjoong Kangef6f83c2012-08-28 22:59:48 +09002903 * shot_ext->shot.dm.stats.faceRectangles[i][3])
2904 / m_streamThreads[0].get()->m_parameters.outputHeight;
Sungjoong Kangfd2d78a2012-08-26 17:44:25 -07002905 }
2906 }
Younghwan Joo6f19b6c2012-08-30 13:56:53 -07002907 if (m_nightCaptureCnt == 0 && m_flashCnt == 0) {
Sungjoong Kanga15b4e32012-08-28 12:55:39 -07002908 m_requestManager->ApplyDynamicMetadata(shot_ext);
2909 }
Sungjoong Kang0f26b202012-08-17 15:43:12 -07002910 OnAfNotification(shot_ext->shot.dm.aa.afState);
Sungjoong Kang13d8c7b2012-07-14 10:20:39 +09002911 }
Sungjoong Kangad378612012-08-17 12:34:33 -07002912
Sungjoong Kang0f26b202012-08-17 15:43:12 -07002913 processingReqIndex = m_requestManager->MarkProcessingRequest(&(m_camera_info.sensor.buffer[index]), &afMode);
Sungjoong Kangef6f83c2012-08-28 22:59:48 +09002914 if (processingReqIndex != -1)
Sungjoong Kang0f26b202012-08-17 15:43:12 -07002915 SetAfMode((enum aa_afmode)afMode);
Sungjoong Kangef6f83c2012-08-28 22:59:48 +09002916
Sungjoong Kangad378612012-08-17 12:34:33 -07002917
2918 shot_ext = (struct camera2_shot_ext *)(m_camera_info.sensor.buffer[index].virt.extP[1]);
2919 if (m_scp_closing || m_scp_closed) {
2920 ALOGD("(%s): SCP_CLOSING(%d) SCP_CLOSED(%d)", __FUNCTION__, m_scp_closing, m_scp_closed);
2921 shot_ext->request_scc = 0;
2922 shot_ext->request_scp = 0;
2923 shot_ext->request_sensor = 0;
2924 }
2925
Sungjoong Kangad378612012-08-17 12:34:33 -07002926 cam_int_qbuf(&(m_camera_info.sensor), index);
2927 ALOGV("### Sensor QBUF done");
2928
Sungjoong Kangef6f83c2012-08-28 22:59:48 +09002929 if (!m_scp_closing
2930 && ((matchedFrameCnt == -1) || (processingReqIndex == -1))){
2931 ALOGD("make bubble shot: matchedFramcnt(%d) processingReqIndex(%d)",
2932 matchedFrameCnt, processingReqIndex);
Sungjoong Kang13d8c7b2012-07-14 10:20:39 +09002933 selfThread->SetSignal(SIGNAL_SENSOR_START_REQ_PROCESSING);
Sungjoong Kang13d8c7b2012-07-14 10:20:39 +09002934 }
Sungjoong Kang9dd63e12012-07-24 00:25:51 +09002935 }
Sungjoong Kang13d8c7b2012-07-14 10:20:39 +09002936 return;
2937}
2938
Sungjoong Kang13d8c7b2012-07-14 10:20:39 +09002939void ExynosCameraHWInterface2::m_ispThreadInitialize(SignalDrivenThread * self)
2940{
2941 ALOGV("DEBUG(%s): ", __FUNCTION__ );
Sungjoong Kangad378612012-08-17 12:34:33 -07002942 /* will add */
Jiyoung Shinc15a6b02012-06-05 01:08:14 -07002943 return;
2944}
2945
Jiyoung Shinc15a6b02012-06-05 01:08:14 -07002946
Sungjoong Kang13d8c7b2012-07-14 10:20:39 +09002947void ExynosCameraHWInterface2::m_ispThreadFunc(SignalDrivenThread * self)
2948{
Sungjoong Kangad378612012-08-17 12:34:33 -07002949 ALOGV("DEBUG(%s): ", __FUNCTION__ );
2950 /* will add */
Jiyoung Shinc15a6b02012-06-05 01:08:14 -07002951 return;
2952}
2953
Sungjoong Kang86646da2012-08-28 17:29:11 +09002954void ExynosCameraHWInterface2::m_streamBufferInit(SignalDrivenThread *self)
2955{
2956 uint32_t currentSignal = self->GetProcessingSignal();
2957 StreamThread * selfThread = ((StreamThread*)self);
2958 stream_parameters_t *selfStreamParms = &(selfThread->m_parameters);
2959 record_parameters_t *selfRecordParms = &(selfThread->m_recordParameters);
Sungjoong Kang74d78eb2012-08-29 13:25:46 -07002960 callback_parameters_t *selfPreviewCbParms = &(selfThread->m_previewCbParameters);
Sungjoong Kang86646da2012-08-28 17:29:11 +09002961 node_info_t *currentNode = &(selfStreamParms->node);
2962
2963 buffer_handle_t * buf = NULL;
2964 status_t res;
2965 void *virtAddr[3];
2966 int i, j;
2967 int index;
2968 nsecs_t timestamp;
2969
2970 if (!(selfThread->m_isBufferInit))
2971 {
2972 for ( i=0 ; i < selfStreamParms->numSvcBuffers; i++) {
2973 res = selfStreamParms->streamOps->dequeue_buffer(selfStreamParms->streamOps, &buf);
2974 if (res != NO_ERROR || buf == NULL) {
2975 ALOGE("ERR(%s): Init: unable to dequeue buffer : %d",__FUNCTION__ , res);
2976 return;
2977 }
2978 ALOGV("DEBUG(%s): got buf(%x) version(%d), numFds(%d), numInts(%d)", __FUNCTION__, (uint32_t)(*buf),
2979 ((native_handle_t*)(*buf))->version, ((native_handle_t*)(*buf))->numFds, ((native_handle_t*)(*buf))->numInts);
2980
2981 if (m_grallocHal->lock(m_grallocHal, *buf,
2982 selfStreamParms->usage,
2983 0, 0, selfStreamParms->outputWidth, selfStreamParms->outputHeight, virtAddr) != 0) {
2984 ALOGE("ERR(%s): could not obtain gralloc buffer", __FUNCTION__);
2985 return;
2986 }
2987 ALOGV("DEBUG(%s): locked img buf plane0(%x) plane1(%x) plane2(%x)",
2988 __FUNCTION__, (unsigned int)virtAddr[0], (unsigned int)virtAddr[1], (unsigned int)virtAddr[2]);
2989
2990 index = selfThread->findBufferIndex(virtAddr[0]);
2991 if (index == -1) {
2992 ALOGE("ERR(%s): could not find buffer index", __FUNCTION__);
2993 }
2994 else {
2995 ALOGV("DEBUG(%s): found buffer index[%d] - status(%d)",
2996 __FUNCTION__, index, selfStreamParms->svcBufStatus[index]);
2997 if (selfStreamParms->svcBufStatus[index]== REQUIRES_DQ_FROM_SVC)
2998 selfStreamParms->svcBufStatus[index] = ON_DRIVER;
2999 else if (selfStreamParms->svcBufStatus[index]== ON_SERVICE)
3000 selfStreamParms->svcBufStatus[index] = ON_HAL;
3001 else {
3002 ALOGV("DBG(%s): buffer status abnormal (%d) "
3003 , __FUNCTION__, selfStreamParms->svcBufStatus[index]);
3004 }
3005 selfStreamParms->numSvcBufsInHal++;
3006 if (*buf != selfStreamParms->svcBufHandle[index])
3007 ALOGV("DBG(%s): different buf_handle index ", __FUNCTION__);
3008 else
3009 ALOGV("DEBUG(%s): same buf_handle index", __FUNCTION__);
3010 }
3011 selfStreamParms->svcBufIndex = 0;
3012 }
3013 selfThread->m_isBufferInit = true;
3014 }
3015
3016 if (m_recordingEnabled && m_needsRecordBufferInit) {
3017 ALOGV("DEBUG(%s): Recording Buffer Initialization numsvcbuf(%d)",
3018 __FUNCTION__, selfRecordParms->numSvcBuffers);
3019 int checkingIndex = 0;
3020 bool found = false;
3021 for ( i=0 ; i < selfRecordParms->numSvcBuffers; i++) {
3022 res = selfRecordParms->streamOps->dequeue_buffer(selfRecordParms->streamOps, &buf);
3023 if (res != NO_ERROR || buf == NULL) {
3024 ALOGE("ERR(%s): Init: unable to dequeue buffer : %d",__FUNCTION__ , res);
3025 return;
3026 }
3027 selfRecordParms->numSvcBufsInHal++;
3028 ALOGV("DEBUG(%s): [record] got buf(%x) bufInHal(%d) version(%d), numFds(%d), numInts(%d)", __FUNCTION__, (uint32_t)(*buf),
3029 selfRecordParms->numSvcBufsInHal, ((native_handle_t*)(*buf))->version, ((native_handle_t*)(*buf))->numFds, ((native_handle_t*)(*buf))->numInts);
3030
3031 if (m_grallocHal->lock(m_grallocHal, *buf,
3032 selfRecordParms->usage, 0, 0,
3033 selfRecordParms->outputWidth, selfRecordParms->outputHeight, virtAddr) != 0) {
3034 ALOGE("ERR(%s): could not obtain gralloc buffer", __FUNCTION__);
3035 }
3036 else {
3037 ALOGV("DEBUG(%s): [record] locked img buf plane0(%x) plane1(%x) plane2(%x)",
3038 __FUNCTION__, (unsigned int)virtAddr[0], (unsigned int)virtAddr[1], (unsigned int)virtAddr[2]);
3039 }
3040 found = false;
3041 for (checkingIndex = 0; checkingIndex < selfRecordParms->numSvcBuffers ; checkingIndex++) {
3042 if (selfRecordParms->svcBufHandle[checkingIndex] == *buf ) {
3043 found = true;
3044 break;
3045 }
3046 }
3047 ALOGV("DEBUG(%s): [record] found(%d) - index[%d]", __FUNCTION__, found, checkingIndex);
3048 if (!found) break;
3049
3050 index = checkingIndex;
3051
3052 if (index == -1) {
3053 ALOGV("ERR(%s): could not find buffer index", __FUNCTION__);
3054 }
3055 else {
3056 ALOGV("DEBUG(%s): found buffer index[%d] - status(%d)",
3057 __FUNCTION__, index, selfRecordParms->svcBufStatus[index]);
3058 if (selfRecordParms->svcBufStatus[index]== ON_SERVICE)
3059 selfRecordParms->svcBufStatus[index] = ON_HAL;
3060 else {
3061 ALOGV("DBG(%s): buffer status abnormal (%d) "
3062 , __FUNCTION__, selfRecordParms->svcBufStatus[index]);
3063 }
3064 if (*buf != selfRecordParms->svcBufHandle[index])
3065 ALOGV("DBG(%s): different buf_handle index ", __FUNCTION__);
3066 else
3067 ALOGV("DEBUG(%s): same buf_handle index", __FUNCTION__);
3068 }
3069 selfRecordParms->svcBufIndex = 0;
3070 }
3071 m_needsRecordBufferInit = false;
3072 }
Sungjoong Kang74d78eb2012-08-29 13:25:46 -07003073 if (m_previewCbEnabled && m_needsPreviewCbBufferInit) {
3074 ALOGV("DEBUG(%s): previewCb Buffer Initialization numsvcbuf(%d)",
3075 __FUNCTION__, selfPreviewCbParms->numSvcBuffers);
3076 int checkingIndex = 0;
3077 bool found = false;
3078
3079 m_getAlignedYUVSize(HAL_PIXEL_FORMAT_2_V4L2_PIX(selfPreviewCbParms->internalFormat), selfPreviewCbParms->outputWidth,
3080 selfPreviewCbParms->outputHeight, &m_previewCbBuf);
3081 ALOGV("(%s): PreviewCb tempbuf size : %d %d %d", __FUNCTION__, m_previewCbBuf.size.extS[0],
3082 m_previewCbBuf.size.extS[1], m_previewCbBuf.size.extS[2]);
3083
3084 if (allocCameraMemory(selfStreamParms->ionClient, &m_previewCbBuf, selfPreviewCbParms->internalPlanes) == -1) {
3085 ALOGE("ERR(%s): Failed to allocate previewcb buf", __FUNCTION__);
3086 }
3087
3088 for ( i=0 ; i < selfPreviewCbParms->numSvcBuffers; i++) {
3089 res = selfPreviewCbParms->streamOps->dequeue_buffer(selfPreviewCbParms->streamOps, &buf);
3090 if (res != NO_ERROR || buf == NULL) {
3091 ALOGE("ERR(%s): Init: unable to dequeue buffer : %d",__FUNCTION__ , res);
3092 return;
3093 }
3094 selfPreviewCbParms->numSvcBufsInHal++;
3095 ALOGV("DEBUG(%s): [previewCb] got buf(%x) bufInHal(%d) version(%d), numFds(%d), numInts(%d)", __FUNCTION__, (uint32_t)(*buf),
3096 selfPreviewCbParms->numSvcBufsInHal, ((native_handle_t*)(*buf))->version, ((native_handle_t*)(*buf))->numFds, ((native_handle_t*)(*buf))->numInts);
3097
3098 if (m_grallocHal->lock(m_grallocHal, *buf,
3099 selfPreviewCbParms->usage, 0, 0,
3100 selfPreviewCbParms->outputWidth, selfPreviewCbParms->outputHeight, virtAddr) != 0) {
3101 ALOGE("ERR(%s): could not obtain gralloc buffer", __FUNCTION__);
3102 }
3103 else {
3104 ALOGV("DEBUG(%s): [previewCb] locked img buf plane0(%x) plane1(%x) plane2(%x)",
3105 __FUNCTION__, (unsigned int)virtAddr[0], (unsigned int)virtAddr[1], (unsigned int)virtAddr[2]);
3106 }
3107 found = false;
3108 for (checkingIndex = 0; checkingIndex < selfPreviewCbParms->numSvcBuffers ; checkingIndex++) {
3109 if (selfPreviewCbParms->svcBufHandle[checkingIndex] == *buf ) {
3110 found = true;
3111 break;
3112 }
3113 }
3114 ALOGV("DEBUG(%s): [previewCb] found(%d) - index[%d]", __FUNCTION__, found, checkingIndex);
3115 if (!found) break;
3116
3117 index = checkingIndex;
3118
3119 if (index == -1) {
3120 ALOGV("ERR(%s): could not find buffer index", __FUNCTION__);
3121 }
3122 else {
3123 ALOGV("DEBUG(%s): found buffer index[%d] - status(%d)",
3124 __FUNCTION__, index, selfPreviewCbParms->svcBufStatus[index]);
3125 if (selfPreviewCbParms->svcBufStatus[index]== ON_SERVICE)
3126 selfPreviewCbParms->svcBufStatus[index] = ON_HAL;
3127 else {
3128 ALOGV("DBG(%s): buffer status abnormal (%d) "
3129 , __FUNCTION__, selfPreviewCbParms->svcBufStatus[index]);
3130 }
3131 if (*buf != selfPreviewCbParms->svcBufHandle[index])
3132 ALOGV("DBG(%s): different buf_handle index ", __FUNCTION__);
3133 else
3134 ALOGV("DEBUG(%s): same buf_handle index", __FUNCTION__);
3135 }
3136 selfPreviewCbParms->svcBufIndex = 0;
3137 }
3138 m_needsPreviewCbBufferInit = false;
3139 }
Sungjoong Kang86646da2012-08-28 17:29:11 +09003140
3141}
3142
Jiyoung Shinc15a6b02012-06-05 01:08:14 -07003143void ExynosCameraHWInterface2::m_streamThreadInitialize(SignalDrivenThread * self)
3144{
Sungjoong Kang13d8c7b2012-07-14 10:20:39 +09003145 StreamThread * selfThread = ((StreamThread*)self);
3146 ALOGV("DEBUG(%s): ", __FUNCTION__ );
3147 memset(&(selfThread->m_parameters), 0, sizeof(stream_parameters_t));
3148 selfThread->m_isBufferInit = false;
3149
Jiyoung Shinc15a6b02012-06-05 01:08:14 -07003150 return;
3151}
3152
Sungjoong Kang86646da2012-08-28 17:29:11 +09003153void ExynosCameraHWInterface2::m_streamFunc0(SignalDrivenThread *self)
Jiyoung Shinc15a6b02012-06-05 01:08:14 -07003154{
Sungjoong Kang13d8c7b2012-07-14 10:20:39 +09003155 uint32_t currentSignal = self->GetProcessingSignal();
3156 StreamThread * selfThread = ((StreamThread*)self);
3157 stream_parameters_t *selfStreamParms = &(selfThread->m_parameters);
Sungjoong Kang9dd63e12012-07-24 00:25:51 +09003158 record_parameters_t *selfRecordParms = &(selfThread->m_recordParameters);
Sungjoong Kang74d78eb2012-08-29 13:25:46 -07003159 callback_parameters_t *selfPreviewCbParms = &(selfThread->m_previewCbParameters);
Sungjoong Kang13d8c7b2012-07-14 10:20:39 +09003160 node_info_t *currentNode = &(selfStreamParms->node);
Jiyoung Shinc15a6b02012-06-05 01:08:14 -07003161
Sungjoong Kang13d8c7b2012-07-14 10:20:39 +09003162 if (currentSignal & SIGNAL_STREAM_CHANGE_PARAMETER) {
3163 ALOGV("DEBUG(%s): processing SIGNAL_STREAM_CHANGE_PARAMETER", __FUNCTION__);
Jiyoung Shinc15a6b02012-06-05 01:08:14 -07003164
Sungjoong Kang13d8c7b2012-07-14 10:20:39 +09003165 ALOGV("DEBUG(%s): processing SIGNAL_STREAM_CHANGE_PARAMETER DONE", __FUNCTION__);
Jiyoung Shinc15a6b02012-06-05 01:08:14 -07003166 }
Sungjoong Kang13d8c7b2012-07-14 10:20:39 +09003167
Sungjoong Kangb55ed662012-08-31 21:31:34 -07003168 if (currentSignal & SIGNAL_THREAD_RELEASE) {
3169 int i, index = -1, cnt_to_dq = 0;
3170 status_t res;
3171 ALOGV("DEBUG(%s): processing SIGNAL_THREAD_RELEASE", __FUNCTION__);
3172 ALOGD("(%s):(%d) SIGNAL_THREAD_RELEASE", __FUNCTION__, selfStreamParms->streamType);
3173
3174 if (selfThread->m_isBufferInit) {
3175 for ( i=0 ; i < selfStreamParms->numSvcBuffers; i++) {
3176 ALOGV("DEBUG(%s): checking buffer index[%d] - status(%d)",
3177 __FUNCTION__, i, selfStreamParms->svcBufStatus[i]);
3178 if (selfStreamParms->svcBufStatus[i] ==ON_DRIVER) cnt_to_dq++;
3179 }
3180
3181 ALOGV("DEBUG(%s): calling stream(%d) streamoff (fd:%d)", __FUNCTION__,
3182 selfThread->m_index, selfStreamParms->fd);
3183 if (cam_int_streamoff(&(selfStreamParms->node)) < 0 ){
3184 ALOGE("ERR(%s): stream off fail", __FUNCTION__);
3185 } else {
3186 m_scp_closing = true;
3187 }
3188 ALOGV("DEBUG(%s): calling stream(%d) streamoff done", __FUNCTION__, selfThread->m_index);
3189 ALOGV("DEBUG(%s): calling stream(%d) reqbuf 0 (fd:%d)", __FUNCTION__,
3190 selfThread->m_index, selfStreamParms->fd);
3191 currentNode->buffers = 0;
3192 cam_int_reqbufs(currentNode);
3193 ALOGV("DEBUG(%s): calling stream(%d) reqbuf 0 DONE(fd:%d)", __FUNCTION__,
3194 selfThread->m_index, selfStreamParms->fd);
3195 }
3196#ifdef ENABLE_FRAME_SYNC
3197 // free metabuffers
3198 for(i = 0; i < NUM_MAX_CAMERA_BUFFERS; i++)
3199 if(selfStreamParms->metaBuffers[i].fd.extFd[0] != 0){
3200 freeCameraMemory(&(selfStreamParms->metaBuffers[i]), 1);
3201 selfStreamParms->metaBuffers[i].fd.extFd[0] = 0;
3202 selfStreamParms->metaBuffers[i].size.extS[0] = 0;
3203 }
3204#endif
3205 selfThread->m_isBufferInit = false;
3206 selfThread->m_index = 255;
3207
3208 selfThread->m_releasing = false;
3209
3210 ALOGV("DEBUG(%s): processing SIGNAL_THREAD_RELEASE DONE", __FUNCTION__);
3211
3212 return;
3213 }
3214
Sungjoong Kang13d8c7b2012-07-14 10:20:39 +09003215 if (currentSignal & SIGNAL_STREAM_DATA_COMING) {
Jiyoung Shinc15a6b02012-06-05 01:08:14 -07003216 buffer_handle_t * buf = NULL;
3217 status_t res;
3218 void *virtAddr[3];
3219 int i, j;
3220 int index;
Sungjoong Kangad378612012-08-17 12:34:33 -07003221 nsecs_t timestamp;
Sungjoong Kangfeb7df42012-08-28 23:35:43 +09003222 camera2_stream *frame;
Sungjoong Kangad378612012-08-17 12:34:33 -07003223
Sungjoong Kang13d8c7b2012-07-14 10:20:39 +09003224 ALOGV("DEBUG(%s): stream(%d) processing SIGNAL_STREAM_DATA_COMING",
3225 __FUNCTION__,selfThread->m_index);
Sungjoong Kangad378612012-08-17 12:34:33 -07003226
Sungjoong Kang86646da2012-08-28 17:29:11 +09003227 m_streamBufferInit(self);
Jiyoung Shinc15a6b02012-06-05 01:08:14 -07003228
Sungjoong Kangb5237e62012-07-27 07:39:05 -07003229 do {
Sungjoong Kang86646da2012-08-28 17:29:11 +09003230 ALOGV("DEBUG(%s): stream(%d) type(%d) DQBUF START ",__FUNCTION__,
3231 selfThread->m_index, selfStreamParms->streamType);
Jiyoung Shinc15a6b02012-06-05 01:08:14 -07003232
Sungjoong Kangfeb7df42012-08-28 23:35:43 +09003233#ifdef ENABLE_FRAME_SYNC
3234 index = cam_int_dqbuf(&(selfStreamParms->node), selfStreamParms->nodePlanes + selfStreamParms->metaPlanes);
3235 frame = (struct camera2_stream *)(selfStreamParms->metaBuffers[index].virt.extP[0]);
3236 ALOGD("frame count(SCP) : %d", frame->fcount);
3237#else
Sungjoong Kang86646da2012-08-28 17:29:11 +09003238 index = cam_int_dqbuf(&(selfStreamParms->node));
Sungjoong Kangfeb7df42012-08-28 23:35:43 +09003239#endif
Sungjoong Kangb55ed662012-08-31 21:31:34 -07003240 m_scpOutputImageCnt++;
3241 ALOGV("DEBUG(%s): stream(%d) DQBUF done index(%d) sigcnt(%d) imgcnt(%d)",__FUNCTION__,
3242 selfThread->m_index, index, m_scpOutputSignalCnt, m_scpOutputImageCnt);
Sungjoong Kang13d8c7b2012-07-14 10:20:39 +09003243
Sungjoong Kang86646da2012-08-28 17:29:11 +09003244 if (selfStreamParms->svcBufStatus[index] != ON_DRIVER)
3245 ALOGV("DBG(%s): DQed buffer status abnormal (%d) ",
3246 __FUNCTION__, selfStreamParms->svcBufStatus[index]);
3247 selfStreamParms->svcBufStatus[index] = ON_HAL;
Sungjoong Kang13d8c7b2012-07-14 10:20:39 +09003248
Sungjoong Kang86646da2012-08-28 17:29:11 +09003249 if (m_recordOutput && m_recordingEnabled) {
3250 ALOGV("DEBUG(%s): Entering record frame creator, index(%d)",__FUNCTION__, selfRecordParms->svcBufIndex);
Sungjoong Kang37e122d2012-08-08 11:13:48 -07003251 bool found = false;
Sungjoong Kang86646da2012-08-28 17:29:11 +09003252 for (int i = 0 ; selfRecordParms->numSvcBuffers ; i++) {
3253 if (selfRecordParms->svcBufStatus[selfRecordParms->svcBufIndex] == ON_HAL) {
Sungjoong Kang37e122d2012-08-08 11:13:48 -07003254 found = true;
3255 break;
3256 }
Sungjoong Kang86646da2012-08-28 17:29:11 +09003257 selfRecordParms->svcBufIndex++;
3258 if (selfRecordParms->svcBufIndex >= selfRecordParms->numSvcBuffers)
3259 selfRecordParms->svcBufIndex = 0;
Sungjoong Kang37e122d2012-08-08 11:13:48 -07003260 }
3261 if (!found) {
Sungjoong Kang86646da2012-08-28 17:29:11 +09003262 ALOGE("(%s): cannot find free recording buffer", __FUNCTION__);
3263 selfRecordParms->svcBufIndex++;
Sungjoong Kang37e122d2012-08-08 11:13:48 -07003264 break;
3265 }
Jiyoung Shinc15a6b02012-06-05 01:08:14 -07003266
Sungjoong Kang86646da2012-08-28 17:29:11 +09003267 if (m_exynosVideoCSC) {
3268 int videoW = selfRecordParms->outputWidth, videoH = selfRecordParms->outputHeight;
3269 int cropX, cropY, cropW, cropH = 0;
3270 int previewW = selfStreamParms->outputWidth, previewH = selfStreamParms->outputHeight;
3271 m_getRatioSize(previewW, previewH,
3272 videoW, videoH,
Sungjoong Kangb5237e62012-07-27 07:39:05 -07003273 &cropX, &cropY,
3274 &cropW, &cropH,
Sungjoong Kangad378612012-08-17 12:34:33 -07003275 0);
Sungjoong Kang13d8c7b2012-07-14 10:20:39 +09003276
Sungjoong Kangb5237e62012-07-27 07:39:05 -07003277 ALOGV("DEBUG(%s):cropX = %d, cropY = %d, cropW = %d, cropH = %d",
Sungjoong Kang86646da2012-08-28 17:29:11 +09003278 __FUNCTION__, cropX, cropY, cropW, cropH);
Sungjoong Kang13d8c7b2012-07-14 10:20:39 +09003279
Sungjoong Kang86646da2012-08-28 17:29:11 +09003280 csc_set_src_format(m_exynosVideoCSC,
3281 previewW, previewH,
Sungjoong Kangb5237e62012-07-27 07:39:05 -07003282 cropX, cropY, cropW, cropH,
Sungjoong Kang74d78eb2012-08-29 13:25:46 -07003283 selfStreamParms->outputFormat,
Sungjoong Kangb5237e62012-07-27 07:39:05 -07003284 0);
Sungjoong Kang13d8c7b2012-07-14 10:20:39 +09003285
Sungjoong Kang86646da2012-08-28 17:29:11 +09003286 csc_set_dst_format(m_exynosVideoCSC,
3287 videoW, videoH,
3288 0, 0, videoW, videoH,
3289 selfRecordParms->outputFormat,
3290 1);
Jiyoung Shinc15a6b02012-06-05 01:08:14 -07003291
Sungjoong Kang86646da2012-08-28 17:29:11 +09003292 csc_set_src_buffer(m_exynosVideoCSC,
3293 (void **)(&(selfStreamParms->svcBuffers[index].fd.fd)));
Sungjoong Kang13d8c7b2012-07-14 10:20:39 +09003294
Sungjoong Kang86646da2012-08-28 17:29:11 +09003295 csc_set_dst_buffer(m_exynosVideoCSC,
3296 (void **)(&(selfRecordParms->svcBuffers[selfRecordParms->svcBufIndex].fd.fd)));
Sungjoong Kang13d8c7b2012-07-14 10:20:39 +09003297
Sungjoong Kang86646da2012-08-28 17:29:11 +09003298 if (csc_convert(m_exynosVideoCSC) != 0) {
3299 ALOGE("ERR(%s):csc_convert() fail", __FUNCTION__);
3300 }
3301 else {
3302 ALOGV("(%s):csc_convert() SUCCESS", __FUNCTION__);
3303 }
Sungjoong Kang13d8c7b2012-07-14 10:20:39 +09003304 }
3305 else {
Sungjoong Kang86646da2012-08-28 17:29:11 +09003306 ALOGE("ERR(%s):m_exynosVideoCSC == NULL", __FUNCTION__);
Sungjoong Kang13d8c7b2012-07-14 10:20:39 +09003307 }
Sungjoong Kang13d8c7b2012-07-14 10:20:39 +09003308
Sungjoong Kang86646da2012-08-28 17:29:11 +09003309 res = selfRecordParms->streamOps->enqueue_buffer(selfRecordParms->streamOps,
3310 systemTime(),
3311 &(selfRecordParms->svcBufHandle[selfRecordParms->svcBufIndex]));
3312 ALOGV("DEBUG(%s): stream(%d) record enqueue_buffer to svc done res(%d)", __FUNCTION__,
3313 selfThread->m_index, res);
Sungjoong Kang37e122d2012-08-08 11:13:48 -07003314 if (res == 0) {
Sungjoong Kang86646da2012-08-28 17:29:11 +09003315 selfRecordParms->svcBufStatus[selfRecordParms->svcBufIndex] = ON_SERVICE;
3316 selfRecordParms->numSvcBufsInHal--;
Sungjoong Kangb5237e62012-07-27 07:39:05 -07003317 }
Sungjoong Kangb5237e62012-07-27 07:39:05 -07003318 }
Sungjoong Kang74d78eb2012-08-29 13:25:46 -07003319 if (m_previewCbOutput && m_previewCbEnabled) {
3320 ALOGV("DEBUG(%s): Entering previewcb creator, index(%d)",__FUNCTION__, selfPreviewCbParms->svcBufIndex);
3321
3322 bool found = false;
3323 for (int i = 0 ; selfPreviewCbParms->numSvcBuffers ; i++) {
3324 if (selfPreviewCbParms->svcBufStatus[selfPreviewCbParms->svcBufIndex] == ON_HAL) {
3325 found = true;
3326 break;
3327 }
3328 selfPreviewCbParms->svcBufIndex++;
3329 if (selfPreviewCbParms->svcBufIndex >= selfPreviewCbParms->numSvcBuffers)
3330 selfPreviewCbParms->svcBufIndex = 0;
3331 }
3332 if (!found) {
3333 ALOGE("(%s): cannot find free previewcb buffer", __FUNCTION__);
3334 selfPreviewCbParms->svcBufIndex++;
3335 break;
3336 }
3337 if (selfPreviewCbParms->outputFormat == HAL_PIXEL_FORMAT_YCrCb_420_SP) {
3338 if (m_exynosVideoCSC) {
3339 int previewCbW = selfPreviewCbParms->outputWidth, previewCbH = selfPreviewCbParms->outputHeight;
3340 int cropX, cropY, cropW, cropH = 0;
3341 int previewW = selfStreamParms->outputWidth, previewH = selfStreamParms->outputHeight;
3342 m_getRatioSize(previewW, previewH,
3343 previewCbW, previewCbH,
3344 &cropX, &cropY,
3345 &cropW, &cropH,
3346 0);
3347
3348 ALOGV("DEBUG(%s):cropX = %d, cropY = %d, cropW = %d, cropH = %d",
3349 __FUNCTION__, cropX, cropY, cropW, cropH);
3350 csc_set_src_format(m_exynosVideoCSC,
3351 previewW, previewH,
3352 cropX, cropY, cropW, cropH,
3353 selfStreamParms->outputFormat,
3354 0);
3355
3356 csc_set_dst_format(m_exynosVideoCSC,
3357 previewCbW, previewCbH,
3358 0, 0, previewCbW, previewCbH,
3359 selfPreviewCbParms->internalFormat,
3360 1);
3361
3362 csc_set_src_buffer(m_exynosVideoCSC,
3363 (void **)(&(selfStreamParms->svcBuffers[index].fd.fd)));
3364
3365 csc_set_dst_buffer(m_exynosVideoCSC,
3366 (void **)(&(m_previewCbBuf.fd.fd)));
3367
3368 if (csc_convert(m_exynosVideoCSC) != 0) {
3369 ALOGE("ERR(%s):previewcb csc_convert() fail", __FUNCTION__);
3370 }
3371 else {
3372 ALOGV("(%s):previewcb csc_convert() SUCCESS", __FUNCTION__);
3373 }
3374 if (previewCbW == ALIGN(previewCbW, 16)) {
3375 ALOGV("(%s):previewcb %d = %d", __FUNCTION__, previewCbW, ALIGN(previewCbW, 16));
3376 memcpy(selfPreviewCbParms->svcBuffers[selfPreviewCbParms->svcBufIndex].virt.extP[0],
3377 m_previewCbBuf.virt.extP[0], previewCbW * previewCbH);
3378 memcpy(selfPreviewCbParms->svcBuffers[selfPreviewCbParms->svcBufIndex].virt.extP[0] + previewCbW * previewCbH,
3379 m_previewCbBuf.virt.extP[1], previewCbW * previewCbH / 2 );
3380 }
3381 else {
3382 // TODO : copy line by line ?
3383 }
3384 }
3385 else {
3386 ALOGE("ERR(%s):m_exynosVideoCSC == NULL", __FUNCTION__);
3387 }
3388 }
3389 else if (selfPreviewCbParms->outputFormat == HAL_PIXEL_FORMAT_YV12) {
3390 int previewCbW = selfPreviewCbParms->outputWidth, previewCbH = selfPreviewCbParms->outputHeight;
3391 int stride = ALIGN(previewCbW, 16);
3392 int c_stride = ALIGN(stride, 16);
3393 memcpy(selfPreviewCbParms->svcBuffers[selfPreviewCbParms->svcBufIndex].virt.extP[0],
3394 selfStreamParms->svcBuffers[index].virt.extP[0], stride * previewCbH);
3395 memcpy(selfPreviewCbParms->svcBuffers[selfPreviewCbParms->svcBufIndex].virt.extP[0] + stride * previewCbH,
3396 selfStreamParms->svcBuffers[index].virt.extP[1], c_stride * previewCbH / 2 );
3397 memcpy(selfPreviewCbParms->svcBuffers[selfPreviewCbParms->svcBufIndex].virt.extP[0] + (stride * previewCbH) + (c_stride * previewCbH / 2),
3398 selfStreamParms->svcBuffers[index].virt.extP[2], c_stride * previewCbH / 2 );
3399
3400 }
3401 res = selfPreviewCbParms->streamOps->enqueue_buffer(selfPreviewCbParms->streamOps,
3402 systemTime(),
3403 &(selfPreviewCbParms->svcBufHandle[selfPreviewCbParms->svcBufIndex]));
3404 ALOGV("DEBUG(%s): stream(%d) previewcb enqueue_buffer[%d] to svc done res(%d)", __FUNCTION__,
3405 selfThread->m_index, index, res);
3406 if (res == 0) {
3407 selfPreviewCbParms->svcBufStatus[selfPreviewCbParms->svcBufIndex] = ON_SERVICE;
3408 selfPreviewCbParms->numSvcBufsInHal--;
3409 }
3410 }
Sungjoong Kang86646da2012-08-28 17:29:11 +09003411 if (m_previewOutput && m_requestManager->GetSkipCnt() <= 0) {
3412
3413 ALOGV("** Display Preview(frameCnt:%d)", m_requestManager->GetFrameIndex());
3414 res = selfStreamParms->streamOps->enqueue_buffer(selfStreamParms->streamOps,
3415 m_requestManager->GetTimestamp(m_requestManager->GetFrameIndex()),
3416 &(selfStreamParms->svcBufHandle[index]));
3417
3418 ALOGV("DEBUG(%s): stream(%d) enqueue_buffer to svc done res(%d)", __FUNCTION__, selfThread->m_index, res);
3419 }
3420 else {
3421 res = selfStreamParms->streamOps->cancel_buffer(selfStreamParms->streamOps,
3422 &(selfStreamParms->svcBufHandle[index]));
3423 ALOGV("DEBUG(%s): stream(%d) cancel_buffer to svc done res(%d)", __FUNCTION__, selfThread->m_index, res);
3424 }
3425 if (res == 0) {
3426 selfStreamParms->svcBufStatus[index] = ON_SERVICE;
3427 selfStreamParms->numSvcBufsInHal--;
3428 }
3429 else {
3430 selfStreamParms->svcBufStatus[index] = ON_HAL;
3431 }
3432
Sungjoong Kang13d8c7b2012-07-14 10:20:39 +09003433 }
Sungjoong Kangb5237e62012-07-27 07:39:05 -07003434 while (0);
3435
Sungjoong Kang86646da2012-08-28 17:29:11 +09003436 if (m_recordOutput && m_recordingEnabled) {
Sungjoong Kang9dd63e12012-07-24 00:25:51 +09003437 do {
Sungjoong Kangbe494d12012-08-04 15:36:56 -07003438 ALOGV("DEBUG(%s): record currentBuf#(%d)", __FUNCTION__ , selfRecordParms->numSvcBufsInHal);
3439 if (selfRecordParms->numSvcBufsInHal >= 1)
Sungjoong Kang9dd63e12012-07-24 00:25:51 +09003440 {
3441 ALOGV("DEBUG(%s): breaking", __FUNCTION__);
3442 break;
3443 }
3444 res = selfRecordParms->streamOps->dequeue_buffer(selfRecordParms->streamOps, &buf);
3445 if (res != NO_ERROR || buf == NULL) {
3446 ALOGV("DEBUG(%s): record stream(%d) dequeue_buffer fail res(%d)",__FUNCTION__ , selfThread->m_index, res);
3447 break;
3448 }
Sungjoong Kangbe494d12012-08-04 15:36:56 -07003449 selfRecordParms->numSvcBufsInHal ++;
Sungjoong Kang9dd63e12012-07-24 00:25:51 +09003450 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 -07003451 selfRecordParms->numSvcBufsInHal, ((native_handle_t*)(*buf))->version, ((native_handle_t*)(*buf))->numFds, ((native_handle_t*)(*buf))->numInts);
Sungjoong Kangad378612012-08-17 12:34:33 -07003452
Sungjoong Kang9dd63e12012-07-24 00:25:51 +09003453 const private_handle_t *priv_handle = reinterpret_cast<const private_handle_t *>(*buf);
Sungjoong Kang9dd63e12012-07-24 00:25:51 +09003454 bool found = false;
3455 int checkingIndex = 0;
3456 for (checkingIndex = 0; checkingIndex < selfRecordParms->numSvcBuffers ; checkingIndex++) {
3457 if (priv_handle->fd == selfRecordParms->svcBuffers[checkingIndex].fd.extFd[0] ) {
3458 found = true;
3459 break;
3460 }
3461 }
3462 ALOGV("DEBUG(%s): recording dequeueed_buffer found index(%d)", __FUNCTION__, found);
Sungjoong Kangad378612012-08-17 12:34:33 -07003463
3464 if (!found) {
3465 break;
3466 }
3467
Sungjoong Kang9dd63e12012-07-24 00:25:51 +09003468 index = checkingIndex;
3469 if (selfRecordParms->svcBufStatus[index] == ON_SERVICE) {
3470 selfRecordParms->svcBufStatus[index] = ON_HAL;
3471 }
3472 else {
3473 ALOGV("DEBUG(%s): record bufstatus abnormal [%d] status = %d", __FUNCTION__,
Sungjoong Kangad378612012-08-17 12:34:33 -07003474 index, selfRecordParms->svcBufStatus[index]);
Sungjoong Kang9dd63e12012-07-24 00:25:51 +09003475 }
3476 } while (0);
3477 }
Sungjoong Kang74d78eb2012-08-29 13:25:46 -07003478 if (m_previewCbOutput && m_previewCbEnabled) {
3479 do {
3480 ALOGV("DEBUG(%s): previewCb currentBuf#(%d)", __FUNCTION__ , selfPreviewCbParms->numSvcBufsInHal);
3481 if (selfPreviewCbParms->numSvcBufsInHal >= 1)
3482 {
3483 ALOGV("DEBUG(%s): breaking", __FUNCTION__);
3484 break;
3485 }
3486 res = selfPreviewCbParms->streamOps->dequeue_buffer(selfPreviewCbParms->streamOps, &buf);
3487 if (res != NO_ERROR || buf == NULL) {
3488 ALOGV("DEBUG(%s): previewcb stream(%d) dequeue_buffer fail res(%d)",__FUNCTION__ , selfThread->m_index, res);
3489 break;
3490 }
3491 selfPreviewCbParms->numSvcBufsInHal ++;
3492 ALOGV("DEBUG(%s): previewcb got buf(%x) numBufInHal(%d) version(%d), numFds(%d), numInts(%d)", __FUNCTION__, (uint32_t)(*buf),
3493 selfPreviewCbParms->numSvcBufsInHal, ((native_handle_t*)(*buf))->version, ((native_handle_t*)(*buf))->numFds, ((native_handle_t*)(*buf))->numInts);
3494
3495 const private_handle_t *priv_handle = reinterpret_cast<const private_handle_t *>(*buf);
3496 bool found = false;
3497 int checkingIndex = 0;
3498 for (checkingIndex = 0; checkingIndex < selfPreviewCbParms->numSvcBuffers ; checkingIndex++) {
3499 if (priv_handle->fd == selfPreviewCbParms->svcBuffers[checkingIndex].fd.extFd[0] ) {
3500 found = true;
3501 break;
3502 }
3503 }
3504 ALOGV("DEBUG(%s): previewcb dequeueed_buffer found index(%d)", __FUNCTION__, found);
3505
3506 if (!found) {
3507 break;
3508 }
3509
3510 index = checkingIndex;
3511 if (selfPreviewCbParms->svcBufStatus[index] == ON_SERVICE) {
3512 selfPreviewCbParms->svcBufStatus[index] = ON_HAL;
3513 }
3514 else {
3515 ALOGV("DEBUG(%s): previewcb bufstatus abnormal [%d] status = %d", __FUNCTION__,
3516 index, selfPreviewCbParms->svcBufStatus[index]);
3517 }
3518 } while (0);
3519 }
Sungjoong Kang86646da2012-08-28 17:29:11 +09003520
Sungjoong Kangb55ed662012-08-31 21:31:34 -07003521 while (selfStreamParms->numSvcBufsInHal < selfStreamParms->numOwnSvcBuffers - 1) {
Sungjoong Kang86646da2012-08-28 17:29:11 +09003522 res = selfStreamParms->streamOps->dequeue_buffer(selfStreamParms->streamOps, &buf);
3523 if (res != NO_ERROR || buf == NULL) {
3524 ALOGV("DEBUG(%s): stream(%d) dequeue_buffer fail res(%d)",__FUNCTION__ , selfThread->m_index, res);
3525 break;
3526 }
3527 selfStreamParms->numSvcBufsInHal++;
3528 ALOGV("DEBUG(%s): stream(%d) got buf(%x) numInHal(%d) version(%d), numFds(%d), numInts(%d)", __FUNCTION__,
3529 selfThread->m_index, (uint32_t)(*buf), selfStreamParms->numSvcBufsInHal,
3530 ((native_handle_t*)(*buf))->version, ((native_handle_t*)(*buf))->numFds, ((native_handle_t*)(*buf))->numInts);
3531 const private_handle_t *priv_handle = reinterpret_cast<const private_handle_t *>(*buf);
3532
3533 bool found = false;
3534 int checkingIndex = 0;
3535 for (checkingIndex = 0; checkingIndex < selfStreamParms->numSvcBuffers ; checkingIndex++) {
3536 if (priv_handle->fd == selfStreamParms->svcBuffers[checkingIndex].fd.extFd[0] ) {
3537 found = true;
Sungjoong Kang9dd63e12012-07-24 00:25:51 +09003538 break;
3539 }
Sungjoong Kang86646da2012-08-28 17:29:11 +09003540 }
3541 ALOGV("DEBUG(%s): post_dequeue_buffer found(%d)", __FUNCTION__, found);
3542 if (!found) break;
3543 ALOGV("DEBUG(%s): preparing to qbuf [%d]", __FUNCTION__, checkingIndex);
3544 index = checkingIndex;
3545 if (index < selfStreamParms->numHwBuffers) {
3546 uint32_t plane_index = 0;
3547 ExynosBuffer* currentBuf = &(selfStreamParms->svcBuffers[index]);
3548 struct v4l2_buffer v4l2_buf;
3549 struct v4l2_plane planes[VIDEO_MAX_PLANES];
Sungjoong Kang13d8c7b2012-07-14 10:20:39 +09003550
Sungjoong Kang86646da2012-08-28 17:29:11 +09003551 v4l2_buf.m.planes = planes;
3552 v4l2_buf.type = currentNode->type;
3553 v4l2_buf.memory = currentNode->memory;
3554 v4l2_buf.index = index;
3555 v4l2_buf.length = currentNode->planes;
3556
3557 v4l2_buf.m.planes[0].m.fd = priv_handle->fd;
3558 v4l2_buf.m.planes[2].m.fd = priv_handle->fd1;
3559 v4l2_buf.m.planes[1].m.fd = priv_handle->fd2;
3560 for (plane_index=0 ; plane_index < v4l2_buf.length ; plane_index++) {
3561 v4l2_buf.m.planes[plane_index].length = currentBuf->size.extS[plane_index];
3562 ALOGV("DEBUG(%s): plane(%d): fd(%d) length(%d)",
3563 __FUNCTION__, plane_index, v4l2_buf.m.planes[plane_index].m.fd,
3564 v4l2_buf.m.planes[plane_index].length);
Sungjoong Kang9dd63e12012-07-24 00:25:51 +09003565 }
Sungjoong Kangfeb7df42012-08-28 23:35:43 +09003566#ifdef ENABLE_FRAME_SYNC
3567 /* add plane for metadata*/
3568 v4l2_buf.length += selfStreamParms->metaPlanes;
3569 v4l2_buf.m.planes[3].m.fd = selfStreamParms->metaBuffers[index].fd.extFd[0];
3570 v4l2_buf.m.planes[3].length = selfStreamParms->metaBuffers[index].size.extS[0];
3571#endif
Sungjoong Kang86646da2012-08-28 17:29:11 +09003572 if (exynos_v4l2_qbuf(currentNode->fd, &v4l2_buf) < 0) {
3573 ALOGE("ERR(%s): stream id(%d) exynos_v4l2_qbuf() fail",
3574 __FUNCTION__, selfThread->m_index);
3575 return;
Sungjoong Kang9dd63e12012-07-24 00:25:51 +09003576 }
Sungjoong Kang86646da2012-08-28 17:29:11 +09003577 selfStreamParms->svcBufStatus[index] = ON_DRIVER;
3578 ALOGV("DEBUG(%s): stream id(%d) type0 QBUF done index(%d)",
3579 __FUNCTION__, selfThread->m_index, index);
Sungjoong Kang13d8c7b2012-07-14 10:20:39 +09003580 }
3581 }
Sungjoong Kangbe494d12012-08-04 15:36:56 -07003582
Sungjoong Kang13d8c7b2012-07-14 10:20:39 +09003583 ALOGV("DEBUG(%s): stream(%d) processing SIGNAL_STREAM_DATA_COMING DONE",
3584 __FUNCTION__,selfThread->m_index);
Jiyoung Shinc15a6b02012-06-05 01:08:14 -07003585 }
Sungjoong Kang86646da2012-08-28 17:29:11 +09003586 return;
3587}
3588
3589void ExynosCameraHWInterface2::m_streamFunc1(SignalDrivenThread *self)
3590{
3591 uint32_t currentSignal = self->GetProcessingSignal();
3592 StreamThread * selfThread = ((StreamThread*)self);
3593 stream_parameters_t *selfStreamParms = &(selfThread->m_parameters);
3594 record_parameters_t *selfRecordParms = &(selfThread->m_recordParameters);
3595 node_info_t *currentNode = &(selfStreamParms->node);
3596
3597 if (currentSignal & SIGNAL_STREAM_CHANGE_PARAMETER) {
3598 ALOGV("DEBUG(%s): processing SIGNAL_STREAM_CHANGE_PARAMETER", __FUNCTION__);
3599
3600 m_resizeBuf.size.extS[0] = ALIGN(selfStreamParms->outputWidth, 16) * ALIGN(selfStreamParms->outputHeight, 16) * 2;
3601 m_resizeBuf.size.extS[1] = 0;
3602 m_resizeBuf.size.extS[2] = 0;
3603
3604 if (allocCameraMemory(selfStreamParms->ionClient, &m_resizeBuf, 1) == -1) {
3605 ALOGE("ERR(%s): Failed to allocate resize buf", __FUNCTION__);
3606 }
3607
3608 ALOGV("DEBUG(%s): processing SIGNAL_STREAM_CHANGE_PARAMETER DONE", __FUNCTION__);
3609 }
3610
3611 if (currentSignal & SIGNAL_STREAM_DATA_COMING) {
3612 buffer_handle_t * buf = NULL;
3613 status_t res;
3614 void *virtAddr[3];
3615 int i, j;
3616 int index;
3617 nsecs_t timestamp;
3618
3619 ALOGV("DEBUG(%s): stream(%d) processing SIGNAL_STREAM_DATA_COMING",
3620 __FUNCTION__,selfThread->m_index);
3621
3622 m_streamBufferInit(self);
3623
3624 do {
3625 ExynosRect jpegRect;
3626 bool found = false;
3627 bool ret = false;
3628 int pictureW, pictureH, pictureFramesize = 0;
3629 int pictureFormat;
3630 int cropX, cropY, cropW, cropH = 0;
3631 ExynosBuffer resizeBufInfo;
3632 ExynosRect m_orgPictureRect;
Sungjoong Kangfeb7df42012-08-28 23:35:43 +09003633 camera2_stream *frame;
Sungjoong Kang86646da2012-08-28 17:29:11 +09003634
3635 ALOGD("DEBUG(%s): stream(%d) type(%d) DQBUF START ",__FUNCTION__,
3636 selfThread->m_index, selfStreamParms->streamType);
3637 index = cam_int_dqbuf(&(selfStreamParms->node));
3638 ALOGD("DEBUG(%s): stream(%d) type(%d) DQBUF done index(%d)",__FUNCTION__,
3639 selfThread->m_index, selfStreamParms->streamType, index);
3640
Sungjoong Kangfeb7df42012-08-28 23:35:43 +09003641#ifdef ENABLE_FRAME_SYNC
3642 frame = (struct camera2_stream *)(selfStreamParms->svcBuffers[index].virt.extP[selfStreamParms->nodePlanes -1]);
3643 ALOGD("frame count(SCC) : %d", frame->fcount);
3644#endif
Sungjoong Kang86646da2012-08-28 17:29:11 +09003645 for (int i = 0; i < selfStreamParms->numSvcBuffers ; i++) {
3646 if (selfStreamParms->svcBufStatus[selfStreamParms->svcBufIndex] == ON_HAL) {
3647 found = true;
3648 break;
3649 }
3650 selfStreamParms->svcBufIndex++;
3651 if (selfStreamParms->svcBufIndex >= selfStreamParms->numSvcBuffers)
3652 selfStreamParms->svcBufIndex = 0;
3653 }
3654 if (!found) {
3655 ALOGE("ERR(%s): NO free SVC buffer for JPEG", __FUNCTION__);
3656 break;
3657 }
3658
3659 m_orgPictureRect.w = selfStreamParms->outputWidth;
3660 m_orgPictureRect.h = selfStreamParms->outputHeight;
3661
3662 ExynosBuffer* m_pictureBuf = &(m_camera_info.capture.buffer[index]);
3663
Sungjoong Kange4657e32012-08-28 15:02:19 -07003664 m_getRatioSize(selfStreamParms->nodeWidth, selfStreamParms->nodeHeight,
3665 m_orgPictureRect.w, m_orgPictureRect.h,
3666 &cropX, &cropY,
3667 &pictureW, &pictureH,
3668 0);
Sungjoong Kang86646da2012-08-28 17:29:11 +09003669 pictureFormat = V4L2_PIX_FMT_YUYV;
3670 pictureFramesize = FRAME_SIZE(V4L2_PIX_2_HAL_PIXEL_FORMAT(pictureFormat), pictureW, pictureH);
3671
3672 if (m_exynosPictureCSC) {
hyeonmyeong Choi308291d2012-08-29 13:55:01 -07003673 float zoom_w = 0, zoom_h = 0;
3674 if (m_orgPictureRect.w >= m_orgPictureRect.h) {
3675 zoom_w = pictureW / m_zoomRatio;
3676 zoom_h = zoom_w * m_orgPictureRect.h / m_orgPictureRect.w;
3677 } else {
3678 zoom_h = pictureH / m_zoomRatio;
3679 zoom_w = zoom_h * m_orgPictureRect.w / m_orgPictureRect.h;
3680 }
3681 cropX = (pictureW - zoom_w) / 2;
3682 cropY = (pictureH - zoom_h) / 2;
3683 cropW = zoom_w;
3684 cropH = zoom_h;
Sungjoong Kang86646da2012-08-28 17:29:11 +09003685
3686 ALOGV("DEBUG(%s):cropX = %d, cropY = %d, cropW = %d, cropH = %d",
3687 __FUNCTION__, cropX, cropY, cropW, cropH);
3688
3689 csc_set_src_format(m_exynosPictureCSC,
3690 ALIGN(pictureW, 16), ALIGN(pictureH, 16),
3691 cropX, cropY, cropW, cropH,
3692 V4L2_PIX_2_HAL_PIXEL_FORMAT(pictureFormat),
3693 0);
3694
3695 csc_set_dst_format(m_exynosPictureCSC,
3696 m_orgPictureRect.w, m_orgPictureRect.h,
3697 0, 0, m_orgPictureRect.w, m_orgPictureRect.h,
3698 V4L2_PIX_2_HAL_PIXEL_FORMAT(V4L2_PIX_FMT_NV16),
3699 0);
3700 csc_set_src_buffer(m_exynosPictureCSC,
3701 (void **)&m_pictureBuf->fd.fd);
3702
3703 csc_set_dst_buffer(m_exynosPictureCSC,
3704 (void **)&m_resizeBuf.fd.fd);
3705 for (int i = 0 ; i < 3 ; i++)
3706 ALOGV("DEBUG(%s): m_resizeBuf.virt.extP[%d]=%d m_resizeBuf.size.extS[%d]=%d",
3707 __FUNCTION__, i, m_resizeBuf.fd.extFd[i], i, m_resizeBuf.size.extS[i]);
3708
3709 if (csc_convert(m_exynosPictureCSC) != 0)
3710 ALOGE("ERR(%s): csc_convert() fail", __FUNCTION__);
3711
3712
3713 }
3714 else {
3715 ALOGE("ERR(%s): m_exynosPictureCSC == NULL", __FUNCTION__);
3716 }
3717
3718 resizeBufInfo = m_resizeBuf;
3719
3720 m_getAlignedYUVSize(V4L2_PIX_FMT_NV16, m_orgPictureRect.w, m_orgPictureRect.h, &m_resizeBuf);
3721
3722 for (int i = 1; i < 3; i++) {
3723 if (m_resizeBuf.size.extS[i] != 0)
3724 m_resizeBuf.fd.extFd[i] = m_resizeBuf.fd.extFd[i-1] + m_resizeBuf.size.extS[i-1];
3725
3726 ALOGV("(%s): m_resizeBuf.size.extS[%d] = %d", __FUNCTION__, i, m_resizeBuf.size.extS[i]);
3727 }
3728
3729 jpegRect.w = m_orgPictureRect.w;
3730 jpegRect.h = m_orgPictureRect.h;
3731 jpegRect.colorFormat = V4L2_PIX_FMT_NV16;
3732
3733 if (yuv2Jpeg(&m_resizeBuf, &selfStreamParms->svcBuffers[selfStreamParms->svcBufIndex], &jpegRect) == false)
3734 ALOGE("ERR(%s):yuv2Jpeg() fail", __FUNCTION__);
3735 cam_int_qbuf(&(selfStreamParms->node), index);
3736 ALOGV("DEBUG(%s): stream(%d) type(%d) QBUF DONE ",__FUNCTION__,
3737 selfThread->m_index, selfStreamParms->streamType);
3738
3739 m_resizeBuf = resizeBufInfo;
3740
3741 res = selfStreamParms->streamOps->enqueue_buffer(selfStreamParms->streamOps, systemTime(), &(selfStreamParms->svcBufHandle[selfStreamParms->svcBufIndex]));
3742
3743 ALOGV("DEBUG(%s): stream(%d) enqueue_buffer index(%d) to svc done res(%d)",
3744 __FUNCTION__, selfThread->m_index, selfStreamParms->svcBufIndex, res);
3745 if (res == 0) {
3746 selfStreamParms->svcBufStatus[selfStreamParms->svcBufIndex] = ON_SERVICE;
3747 selfStreamParms->numSvcBufsInHal--;
3748 }
3749 else {
3750 selfStreamParms->svcBufStatus[selfStreamParms->svcBufIndex] = ON_HAL;
3751 }
3752 }
3753 while (0);
3754
3755 while (selfStreamParms->numSvcBufsInHal < selfStreamParms->numOwnSvcBuffers) {
3756 res = selfStreamParms->streamOps->dequeue_buffer(selfStreamParms->streamOps, &buf);
3757 if (res != NO_ERROR || buf == NULL) {
3758 ALOGV("DEBUG(%s): stream(%d) dequeue_buffer fail res(%d)",__FUNCTION__ , selfThread->m_index, res);
3759 break;
3760 }
3761
3762 ALOGV("DEBUG(%s): stream(%d) got buf(%x) numInHal(%d) version(%d), numFds(%d), numInts(%d)", __FUNCTION__,
3763 selfThread->m_index, (uint32_t)(*buf), selfStreamParms->numSvcBufsInHal,
3764 ((native_handle_t*)(*buf))->version, ((native_handle_t*)(*buf))->numFds, ((native_handle_t*)(*buf))->numInts);
3765
3766 const private_handle_t *priv_handle = reinterpret_cast<const private_handle_t *>(*buf);
3767
3768 bool found = false;
3769 int checkingIndex = 0;
3770 for (checkingIndex = 0; checkingIndex < selfStreamParms->numSvcBuffers ; checkingIndex++) {
3771 if (priv_handle->fd == selfStreamParms->svcBuffers[checkingIndex].fd.extFd[0] ) {
3772 found = true;
3773 break;
3774 }
3775 }
3776 if (!found) break;
3777 selfStreamParms->svcBufStatus[checkingIndex] = ON_HAL;
3778 selfStreamParms->numSvcBufsInHal++;
3779 }
3780
3781 ALOGV("DEBUG(%s): stream(%d) processing SIGNAL_STREAM_DATA_COMING DONE",
3782 __FUNCTION__,selfThread->m_index);
3783 }
3784
3785 if (currentSignal & SIGNAL_THREAD_RELEASE) {
3786 int i, index = -1, cnt_to_dq = 0;
3787 status_t res;
3788 ALOGV("DEBUG(%s): processing SIGNAL_THREAD_RELEASE", __FUNCTION__);
3789 ALOGD("(%s):(%d) SIGNAL_THREAD_RELEASE", __FUNCTION__, selfStreamParms->streamType);
3790
3791 if (selfThread->m_isBufferInit) {
3792 for ( i=0 ; i < selfStreamParms->numSvcBuffers; i++) {
3793 ALOGV("DEBUG(%s): checking buffer index[%d] - status(%d)",
3794 __FUNCTION__, i, selfStreamParms->svcBufStatus[i]);
3795 if (selfStreamParms->svcBufStatus[i] ==ON_DRIVER) cnt_to_dq++;
3796 }
3797
3798 ALOGV("DEBUG(%s): calling stream(%d) streamoff (fd:%d)", __FUNCTION__,
3799 selfThread->m_index, selfStreamParms->fd);
3800 if (cam_int_streamoff(&(selfStreamParms->node)) < 0 ){
3801 ALOGE("ERR(%s): stream off fail", __FUNCTION__);
3802 } else {
3803 m_camera_info.capture.status = false;
3804 }
3805 ALOGV("DEBUG(%s): calling stream(%d) streamoff done", __FUNCTION__, selfThread->m_index);
3806 ALOGV("DEBUG(%s): calling stream(%d) reqbuf 0 (fd:%d)", __FUNCTION__,
3807 selfThread->m_index, selfStreamParms->fd);
3808 currentNode->buffers = 0;
3809 cam_int_reqbufs(currentNode);
3810 ALOGV("DEBUG(%s): calling stream(%d) reqbuf 0 DONE(fd:%d)", __FUNCTION__,
3811 selfThread->m_index, selfStreamParms->fd);
3812 }
3813 if (selfThread->m_index == 1 && m_resizeBuf.size.s != 0) {
3814 freeCameraMemory(&m_resizeBuf, 1);
3815 }
3816 selfThread->m_isBufferInit = false;
3817 selfThread->m_index = 255;
3818
3819 selfThread->m_releasing = false;
3820
3821 ALOGV("DEBUG(%s): processing SIGNAL_THREAD_RELEASE DONE", __FUNCTION__);
3822
3823 return;
3824 }
3825
3826 return;
3827}
3828
3829
3830void ExynosCameraHWInterface2::m_streamThreadFunc(SignalDrivenThread * self)
3831{
3832 uint32_t currentSignal = self->GetProcessingSignal();
3833 StreamThread * selfThread = ((StreamThread*)self);
3834 stream_parameters_t *selfStreamParms = &(selfThread->m_parameters);
3835 record_parameters_t *selfRecordParms = &(selfThread->m_recordParameters);
3836 node_info_t *currentNode = &(selfStreamParms->node);
3837
3838 ALOGV("DEBUG(%s): m_streamThreadFunc[%d] (%x)", __FUNCTION__, selfThread->m_index, currentSignal);
3839
3840 if (currentSignal & SIGNAL_STREAM_CHANGE_PARAMETER) {
3841 ALOGV("DEBUG(%s): processing SIGNAL_STREAM_CHANGE_PARAMETER", __FUNCTION__);
3842
3843 //Do something in Parent thread handler
3844 selfThread->applyChange();
3845
3846 ALOGV("DEBUG(%s): processing SIGNAL_STREAM_CHANGE_PARAMETER DONE", __FUNCTION__);
3847 }
3848
3849 // Do something in Child thread handler
3850 // Should change function to class that inherited StreamThread class to support dynamic stream allocation
3851 if (selfStreamParms->streamType == STREAM_TYPE_DIRECT)
3852 {
3853 m_streamFunc0(self);
3854 }
3855 else if (selfStreamParms->streamType == STREAM_TYPE_INDIRECT)
3856 {
3857 m_streamFunc1(self);
3858 }
3859
3860 if (currentSignal & SIGNAL_THREAD_RELEASE) {
3861 ALOGV("DEBUG(%s): processing SIGNAL_THREAD_RELEASE", __FUNCTION__);
3862 ALOGD("(%s):(%d) SIGNAL_THREAD_RELEASE", __FUNCTION__, selfStreamParms->streamType);
3863
3864 //Do something in Parent thread handler
3865
3866 ALOGV("DEBUG(%s): processing SIGNAL_THREAD_RELEASE DONE", __FUNCTION__);
3867
3868 return;
3869 }
3870
Jiyoung Shinc15a6b02012-06-05 01:08:14 -07003871 return;
3872}
3873
Sungjoong Kang2d5e6ec2012-08-30 15:14:17 +09003874bool ExynosCameraHWInterface2::m_checkThumbnailSize(int w, int h)
3875{
3876 int sizeOfSupportList;
3877
3878 //REAR Camera
3879 if(this->getCameraId() == 0) {
3880 sizeOfSupportList = sizeof(SUPPORT_THUMBNAIL_REAR_SIZE) / (sizeof(int)*2);
3881
3882 for(int i = 0; i < sizeOfSupportList; i++) {
3883 if((SUPPORT_THUMBNAIL_REAR_SIZE[i][0] == w) &&(SUPPORT_THUMBNAIL_REAR_SIZE[i][1] == h))
3884 return true;
3885 }
3886
3887 }
3888 else {
3889 sizeOfSupportList = sizeof(SUPPORT_THUMBNAIL_FRONT_SIZE) / (sizeof(int)*2);
3890
3891 for(int i = 0; i < sizeOfSupportList; i++) {
3892 if((SUPPORT_THUMBNAIL_FRONT_SIZE[i][0] == w) &&(SUPPORT_THUMBNAIL_FRONT_SIZE[i][1] == h))
3893 return true;
3894 }
3895 }
3896
3897 return false;
3898}
Sungjoong Kang13d8c7b2012-07-14 10:20:39 +09003899bool ExynosCameraHWInterface2::yuv2Jpeg(ExynosBuffer *yuvBuf,
3900 ExynosBuffer *jpegBuf,
3901 ExynosRect *rect)
Jiyoung Shinc15a6b02012-06-05 01:08:14 -07003902{
Sungjoong Kang13d8c7b2012-07-14 10:20:39 +09003903 unsigned char *addr;
3904
3905 ExynosJpegEncoderForCamera jpegEnc;
3906 bool ret = false;
3907 int res = 0;
3908
3909 unsigned int *yuvSize = yuvBuf->size.extS;
3910
3911 if (jpegEnc.create()) {
Sungjoong Kang9dd63e12012-07-24 00:25:51 +09003912 ALOGE("ERR(%s):jpegEnc.create() fail", __FUNCTION__);
Sungjoong Kang13d8c7b2012-07-14 10:20:39 +09003913 goto jpeg_encode_done;
3914 }
3915
3916 if (jpegEnc.setQuality(100)) {
Sungjoong Kang9dd63e12012-07-24 00:25:51 +09003917 ALOGE("ERR(%s):jpegEnc.setQuality() fail", __FUNCTION__);
Sungjoong Kang13d8c7b2012-07-14 10:20:39 +09003918 goto jpeg_encode_done;
3919 }
3920
3921 if (jpegEnc.setSize(rect->w, rect->h)) {
Sungjoong Kang9dd63e12012-07-24 00:25:51 +09003922 ALOGE("ERR(%s):jpegEnc.setSize() fail", __FUNCTION__);
Sungjoong Kang13d8c7b2012-07-14 10:20:39 +09003923 goto jpeg_encode_done;
3924 }
3925 ALOGV("%s : width = %d , height = %d\n", __FUNCTION__, rect->w, rect->h);
3926
3927 if (jpegEnc.setColorFormat(rect->colorFormat)) {
Sungjoong Kang9dd63e12012-07-24 00:25:51 +09003928 ALOGE("ERR(%s):jpegEnc.setColorFormat() fail", __FUNCTION__);
Sungjoong Kang13d8c7b2012-07-14 10:20:39 +09003929 goto jpeg_encode_done;
3930 }
Sungjoong Kang13d8c7b2012-07-14 10:20:39 +09003931
3932 if (jpegEnc.setJpegFormat(V4L2_PIX_FMT_JPEG_422)) {
Sungjoong Kang9dd63e12012-07-24 00:25:51 +09003933 ALOGE("ERR(%s):jpegEnc.setJpegFormat() fail", __FUNCTION__);
Sungjoong Kang13d8c7b2012-07-14 10:20:39 +09003934 goto jpeg_encode_done;
3935 }
Sungjoong Kang13d8c7b2012-07-14 10:20:39 +09003936
Sungjoong Kang2d5e6ec2012-08-30 15:14:17 +09003937 if((m_jpegMetadata.ctl.jpeg.thumbnailSize[0] != 0) && (m_jpegMetadata.ctl.jpeg.thumbnailSize[1] != 0)) {
3938 mExifInfo.enableThumb = true;
3939 if(!m_checkThumbnailSize(m_jpegMetadata.ctl.jpeg.thumbnailSize[0], m_jpegMetadata.ctl.jpeg.thumbnailSize[1])) {
3940 //default value
3941 m_thumbNailW = SUPPORT_THUMBNAIL_REAR_SIZE[0][0];
3942 m_thumbNailH = SUPPORT_THUMBNAIL_REAR_SIZE[0][1];
3943 } else {
3944 m_thumbNailW = m_jpegMetadata.ctl.jpeg.thumbnailSize[0];
3945 m_thumbNailH = m_jpegMetadata.ctl.jpeg.thumbnailSize[1];
3946 }
Sungjoong Kang13d8c7b2012-07-14 10:20:39 +09003947
Sungjoong Kang2d5e6ec2012-08-30 15:14:17 +09003948 ALOGV("(%s) m_thumbNailW = %d, m_thumbNailH = %d", __FUNCTION__, m_thumbNailW, m_thumbNailH);
3949
3950 } else {
3951 mExifInfo.enableThumb = false;
3952 }
3953
3954 if (jpegEnc.setThumbnailSize(m_thumbNailW, m_thumbNailH)) {
3955 ALOGE("ERR(%s):jpegEnc.setThumbnailSize(%d, %d) fail", __FUNCTION__, m_thumbNailH, m_thumbNailH);
Sungjoong Kangeed7ed12012-08-23 16:35:08 -07003956 goto jpeg_encode_done;
3957 }
3958
Sungjoong Kang2d5e6ec2012-08-30 15:14:17 +09003959 ALOGV("(%s):jpegEnc.setThumbnailSize(%d, %d) ", __FUNCTION__, m_thumbNailW, m_thumbNailW);
Sungjoong Kangeed7ed12012-08-23 16:35:08 -07003960 if (jpegEnc.setThumbnailQuality(50)) {
3961 ALOGE("ERR(%s):jpegEnc.setThumbnailQuality fail", __FUNCTION__);
3962 goto jpeg_encode_done;
3963 }
3964
3965 m_setExifChangedAttribute(&mExifInfo, rect, &m_jpegMetadata);
Sungjoong Kang9dd63e12012-07-24 00:25:51 +09003966 ALOGV("DEBUG(%s):calling jpegEnc.setInBuf() yuvSize(%d)", __FUNCTION__, *yuvSize);
Sungjoong Kangeed7ed12012-08-23 16:35:08 -07003967 if (jpegEnc.setInBuf((int *)&(yuvBuf->fd.fd), &(yuvBuf->virt.p), (int *)yuvSize)) {
Sungjoong Kang9dd63e12012-07-24 00:25:51 +09003968 ALOGE("ERR(%s):jpegEnc.setInBuf() fail", __FUNCTION__);
Sungjoong Kang13d8c7b2012-07-14 10:20:39 +09003969 goto jpeg_encode_done;
3970 }
Sungjoong Kangeed7ed12012-08-23 16:35:08 -07003971 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 +09003972 ALOGE("ERR(%s):jpegEnc.setOutBuf() fail", __FUNCTION__);
Sungjoong Kang13d8c7b2012-07-14 10:20:39 +09003973 goto jpeg_encode_done;
3974 }
Sungjoong Kang13d8c7b2012-07-14 10:20:39 +09003975
3976 if (jpegEnc.updateConfig()) {
Sungjoong Kang9dd63e12012-07-24 00:25:51 +09003977 ALOGE("ERR(%s):jpegEnc.updateConfig() fail", __FUNCTION__);
Sungjoong Kang13d8c7b2012-07-14 10:20:39 +09003978 goto jpeg_encode_done;
3979 }
3980
Sungjoong Kangeed7ed12012-08-23 16:35:08 -07003981 if (res = jpegEnc.encode((int *)&jpegBuf->size.s, &mExifInfo)) {
Sungjoong Kang9dd63e12012-07-24 00:25:51 +09003982 ALOGE("ERR(%s):jpegEnc.encode() fail ret(%d)", __FUNCTION__, res);
Sungjoong Kang13d8c7b2012-07-14 10:20:39 +09003983 goto jpeg_encode_done;
3984 }
3985
3986 ret = true;
3987
3988jpeg_encode_done:
3989
3990 if (jpegEnc.flagCreate() == true)
3991 jpegEnc.destroy();
3992
3993 return ret;
Jiyoung Shinc15a6b02012-06-05 01:08:14 -07003994}
3995
Sungjoong Kang8e2c2fd2012-08-27 00:02:22 -07003996void ExynosCameraHWInterface2::OnAfTriggerStart(int id)
3997{
3998 m_afPendingTriggerId = id;
Sungjoong Kangcd13bb72012-08-28 13:05:01 -07003999 m_afModeWaitingCnt = 3;
Sungjoong Kang8e2c2fd2012-08-27 00:02:22 -07004000}
Sungjoong Kang13d8c7b2012-07-14 10:20:39 +09004001
Sungjoong Kang0f26b202012-08-17 15:43:12 -07004002void ExynosCameraHWInterface2::OnAfTrigger(int id)
4003{
Sungjoong Kang8e2c2fd2012-08-27 00:02:22 -07004004 m_afTriggerId = id;
Younghwan Joo6f19b6c2012-08-30 13:56:53 -07004005
Sungjoong Kang0f26b202012-08-17 15:43:12 -07004006 switch (m_afMode) {
4007 case AA_AFMODE_AUTO:
4008 case AA_AFMODE_MACRO:
Sungjoong Kang8e2c2fd2012-08-27 00:02:22 -07004009 case AA_AFMODE_OFF:
Sungjoong Kang0f26b202012-08-17 15:43:12 -07004010 OnAfTriggerAutoMacro(id);
4011 break;
4012 case AA_AFMODE_CONTINUOUS_VIDEO:
4013 OnAfTriggerCAFVideo(id);
4014 break;
4015 case AA_AFMODE_CONTINUOUS_PICTURE:
4016 OnAfTriggerCAFPicture(id);
4017 break;
Sungjoong Kang8e2c2fd2012-08-27 00:02:22 -07004018
Sungjoong Kang0f26b202012-08-17 15:43:12 -07004019 default:
4020 break;
4021 }
4022}
4023
4024void ExynosCameraHWInterface2::OnAfTriggerAutoMacro(int id)
4025{
4026 int nextState = NO_TRANSITION;
Sungjoong Kang0f26b202012-08-17 15:43:12 -07004027
4028 switch (m_afState) {
4029 case HAL_AFSTATE_INACTIVE:
4030 nextState = HAL_AFSTATE_NEEDS_COMMAND;
4031 m_IsAfTriggerRequired = true;
4032 break;
4033 case HAL_AFSTATE_NEEDS_COMMAND:
4034 nextState = NO_TRANSITION;
4035 break;
4036 case HAL_AFSTATE_STARTED:
4037 nextState = NO_TRANSITION;
4038 break;
4039 case HAL_AFSTATE_SCANNING:
4040 nextState = NO_TRANSITION;
4041 break;
4042 case HAL_AFSTATE_LOCKED:
4043 nextState = HAL_AFSTATE_NEEDS_COMMAND;
4044 m_IsAfTriggerRequired = true;
4045 break;
4046 case HAL_AFSTATE_FAILED:
4047 nextState = HAL_AFSTATE_NEEDS_COMMAND;
4048 m_IsAfTriggerRequired = true;
4049 break;
4050 default:
4051 break;
4052 }
4053 ALOGV("(%s): State (%d) -> (%d)", __FUNCTION__, m_afState, nextState);
4054 if (nextState != NO_TRANSITION)
4055 m_afState = nextState;
4056}
4057
4058void ExynosCameraHWInterface2::OnAfTriggerCAFPicture(int id)
4059{
4060 int nextState = NO_TRANSITION;
Sungjoong Kang0f26b202012-08-17 15:43:12 -07004061
4062 switch (m_afState) {
4063 case HAL_AFSTATE_INACTIVE:
4064 nextState = HAL_AFSTATE_FAILED;
4065 SetAfStateForService(ANDROID_CONTROL_AF_STATE_NOT_FOCUSED_LOCKED);
4066 break;
4067 case HAL_AFSTATE_NEEDS_COMMAND:
4068 // not used
4069 break;
4070 case HAL_AFSTATE_STARTED:
4071 nextState = HAL_AFSTATE_NEEDS_DETERMINATION;
Sungjoong Kang36c106c2012-08-23 17:38:20 -07004072 m_AfHwStateFailed = false;
Sungjoong Kang0f26b202012-08-17 15:43:12 -07004073 break;
4074 case HAL_AFSTATE_SCANNING:
4075 nextState = HAL_AFSTATE_NEEDS_DETERMINATION;
Sungjoong Kang36c106c2012-08-23 17:38:20 -07004076 m_AfHwStateFailed = false;
Sungjoong Kang0f26b202012-08-17 15:43:12 -07004077 break;
4078 case HAL_AFSTATE_NEEDS_DETERMINATION:
4079 nextState = NO_TRANSITION;
4080 break;
4081 case HAL_AFSTATE_PASSIVE_FOCUSED:
4082 m_IsAfLockRequired = true;
Sungjoong Kang36c106c2012-08-23 17:38:20 -07004083 if (m_AfHwStateFailed) {
4084 ALOGV("(%s): LAST : fail", __FUNCTION__);
4085 SetAfStateForService(ANDROID_CONTROL_AF_STATE_NOT_FOCUSED_LOCKED);
4086 nextState = HAL_AFSTATE_FAILED;
4087 }
4088 else {
4089 ALOGV("(%s): LAST : success", __FUNCTION__);
4090 SetAfStateForService(ANDROID_CONTROL_AF_STATE_FOCUSED_LOCKED);
4091 nextState = HAL_AFSTATE_LOCKED;
4092 }
4093 m_AfHwStateFailed = false;
Sungjoong Kang0f26b202012-08-17 15:43:12 -07004094 break;
4095 case HAL_AFSTATE_LOCKED:
4096 nextState = NO_TRANSITION;
4097 break;
4098 case HAL_AFSTATE_FAILED:
4099 nextState = NO_TRANSITION;
4100 break;
4101 default:
4102 break;
4103 }
4104 ALOGV("(%s): State (%d) -> (%d)", __FUNCTION__, m_afState, nextState);
4105 if (nextState != NO_TRANSITION)
4106 m_afState = nextState;
4107}
4108
4109
4110void ExynosCameraHWInterface2::OnAfTriggerCAFVideo(int id)
4111{
4112 int nextState = NO_TRANSITION;
Sungjoong Kang0f26b202012-08-17 15:43:12 -07004113
4114 switch (m_afState) {
4115 case HAL_AFSTATE_INACTIVE:
4116 nextState = HAL_AFSTATE_FAILED;
4117 SetAfStateForService(ANDROID_CONTROL_AF_STATE_NOT_FOCUSED_LOCKED);
4118 break;
4119 case HAL_AFSTATE_NEEDS_COMMAND:
4120 // not used
4121 break;
4122 case HAL_AFSTATE_STARTED:
4123 m_IsAfLockRequired = true;
4124 nextState = HAL_AFSTATE_FAILED;
4125 SetAfStateForService(ANDROID_CONTROL_AF_STATE_NOT_FOCUSED_LOCKED);
4126 break;
4127 case HAL_AFSTATE_SCANNING:
4128 m_IsAfLockRequired = true;
4129 nextState = HAL_AFSTATE_FAILED;
4130 SetAfStateForService(ANDROID_CONTROL_AF_STATE_NOT_FOCUSED_LOCKED);
4131 break;
4132 case HAL_AFSTATE_NEEDS_DETERMINATION:
4133 // not used
4134 break;
4135 case HAL_AFSTATE_PASSIVE_FOCUSED:
4136 m_IsAfLockRequired = true;
4137 SetAfStateForService(ANDROID_CONTROL_AF_STATE_FOCUSED_LOCKED);
4138 nextState = HAL_AFSTATE_LOCKED;
4139 break;
4140 case HAL_AFSTATE_LOCKED:
4141 nextState = NO_TRANSITION;
4142 break;
4143 case HAL_AFSTATE_FAILED:
4144 nextState = NO_TRANSITION;
4145 break;
4146 default:
4147 break;
4148 }
4149 ALOGV("(%s): State (%d) -> (%d)", __FUNCTION__, m_afState, nextState);
4150 if (nextState != NO_TRANSITION)
4151 m_afState = nextState;
4152}
4153
4154void ExynosCameraHWInterface2::OnAfNotification(enum aa_afstate noti)
4155{
4156 switch (m_afMode) {
4157 case AA_AFMODE_AUTO:
4158 case AA_AFMODE_MACRO:
4159 OnAfNotificationAutoMacro(noti);
4160 break;
4161 case AA_AFMODE_CONTINUOUS_VIDEO:
4162 OnAfNotificationCAFVideo(noti);
4163 break;
4164 case AA_AFMODE_CONTINUOUS_PICTURE:
4165 OnAfNotificationCAFPicture(noti);
4166 break;
4167 case AA_AFMODE_OFF:
4168 default:
4169 break;
4170 }
4171}
4172
4173void ExynosCameraHWInterface2::OnAfNotificationAutoMacro(enum aa_afstate noti)
4174{
4175 int nextState = NO_TRANSITION;
4176 bool bWrongTransition = false;
4177
4178 if (m_afState == HAL_AFSTATE_INACTIVE || m_afState == HAL_AFSTATE_NEEDS_COMMAND) {
4179 switch (noti) {
4180 case AA_AFSTATE_INACTIVE:
4181 case AA_AFSTATE_ACTIVE_SCAN:
4182 case AA_AFSTATE_AF_ACQUIRED_FOCUS:
4183 case AA_AFSTATE_AF_FAILED_FOCUS:
4184 default:
4185 nextState = NO_TRANSITION;
4186 break;
4187 }
4188 }
4189 else if (m_afState == HAL_AFSTATE_STARTED) {
4190 switch (noti) {
4191 case AA_AFSTATE_INACTIVE:
4192 nextState = NO_TRANSITION;
4193 break;
4194 case AA_AFSTATE_ACTIVE_SCAN:
4195 nextState = HAL_AFSTATE_SCANNING;
4196 SetAfStateForService(ANDROID_CONTROL_AF_STATE_ACTIVE_SCAN);
4197 break;
4198 case AA_AFSTATE_AF_ACQUIRED_FOCUS:
4199 nextState = NO_TRANSITION;
4200 break;
4201 case AA_AFSTATE_AF_FAILED_FOCUS:
4202 nextState = NO_TRANSITION;
4203 break;
4204 default:
4205 bWrongTransition = true;
4206 break;
4207 }
4208 }
4209 else if (m_afState == HAL_AFSTATE_SCANNING) {
4210 switch (noti) {
4211 case AA_AFSTATE_INACTIVE:
4212 bWrongTransition = true;
4213 break;
4214 case AA_AFSTATE_ACTIVE_SCAN:
4215 nextState = NO_TRANSITION;
4216 break;
4217 case AA_AFSTATE_AF_ACQUIRED_FOCUS:
4218 nextState = HAL_AFSTATE_LOCKED;
4219 SetAfStateForService(ANDROID_CONTROL_AF_STATE_FOCUSED_LOCKED);
4220 break;
4221 case AA_AFSTATE_AF_FAILED_FOCUS:
4222 nextState = HAL_AFSTATE_FAILED;
4223 SetAfStateForService(ANDROID_CONTROL_AF_STATE_NOT_FOCUSED_LOCKED);
4224 break;
4225 default:
4226 bWrongTransition = true;
4227 break;
4228 }
4229 }
4230 else if (m_afState == HAL_AFSTATE_LOCKED) {
4231 switch (noti) {
4232 case AA_AFSTATE_INACTIVE:
4233 case AA_AFSTATE_ACTIVE_SCAN:
4234 bWrongTransition = true;
4235 break;
4236 case AA_AFSTATE_AF_ACQUIRED_FOCUS:
Younghwan Joo6f19b6c2012-08-30 13:56:53 -07004237 // Flash off if flash mode is available.
4238 if (m_afFlashEnableFlg)
4239 m_afFlashCnt = IF_FLASH_AF_OFF;
Sungjoong Kang0f26b202012-08-17 15:43:12 -07004240 nextState = NO_TRANSITION;
4241 break;
4242 case AA_AFSTATE_AF_FAILED_FOCUS:
4243 default:
4244 bWrongTransition = true;
4245 break;
4246 }
4247 }
4248 else if (m_afState == HAL_AFSTATE_FAILED) {
4249 switch (noti) {
4250 case AA_AFSTATE_INACTIVE:
4251 case AA_AFSTATE_ACTIVE_SCAN:
4252 case AA_AFSTATE_AF_ACQUIRED_FOCUS:
4253 bWrongTransition = true;
4254 break;
4255 case AA_AFSTATE_AF_FAILED_FOCUS:
Younghwan Joo6f19b6c2012-08-30 13:56:53 -07004256 // Flash off if flash mode is available.
4257 if (m_afFlashEnableFlg)
4258 m_afFlashCnt = IF_FLASH_AF_OFF;
Sungjoong Kang0f26b202012-08-17 15:43:12 -07004259 nextState = NO_TRANSITION;
4260 break;
4261 default:
4262 bWrongTransition = true;
4263 break;
4264 }
4265 }
4266 if (bWrongTransition) {
4267 ALOGV("(%s): Wrong Transition state(%d) noti(%d)", __FUNCTION__, m_afState, noti);
4268 return;
4269 }
4270 ALOGV("(%s): State (%d) -> (%d) by (%d)", __FUNCTION__, m_afState, nextState, noti);
4271 if (nextState != NO_TRANSITION)
4272 m_afState = nextState;
4273}
4274
4275void ExynosCameraHWInterface2::OnAfNotificationCAFPicture(enum aa_afstate noti)
4276{
4277 int nextState = NO_TRANSITION;
4278 bool bWrongTransition = false;
4279
4280 if (m_afState == HAL_AFSTATE_INACTIVE) {
4281 switch (noti) {
4282 case AA_AFSTATE_INACTIVE:
4283 case AA_AFSTATE_ACTIVE_SCAN:
4284 case AA_AFSTATE_AF_ACQUIRED_FOCUS:
4285 case AA_AFSTATE_AF_FAILED_FOCUS:
4286 default:
4287 nextState = NO_TRANSITION;
4288 break;
4289 }
4290 }
4291 else if (m_afState == HAL_AFSTATE_STARTED) {
4292 switch (noti) {
4293 case AA_AFSTATE_INACTIVE:
4294 nextState = NO_TRANSITION;
4295 break;
4296 case AA_AFSTATE_ACTIVE_SCAN:
4297 nextState = HAL_AFSTATE_SCANNING;
4298 SetAfStateForService(ANDROID_CONTROL_AF_STATE_PASSIVE_SCAN);
4299 break;
4300 case AA_AFSTATE_AF_ACQUIRED_FOCUS:
4301 nextState = HAL_AFSTATE_PASSIVE_FOCUSED;
4302 SetAfStateForService(ANDROID_CONTROL_AF_STATE_PASSIVE_FOCUSED);
4303 break;
4304 case AA_AFSTATE_AF_FAILED_FOCUS:
Sungjoong Kangcd13bb72012-08-28 13:05:01 -07004305 //nextState = HAL_AFSTATE_FAILED;
4306 //SetAfStateForService(ANDROID_CONTROL_AF_STATE_NOT_FOCUSED_LOCKED);
4307 nextState = NO_TRANSITION;
Sungjoong Kang0f26b202012-08-17 15:43:12 -07004308 break;
4309 default:
4310 bWrongTransition = true;
4311 break;
4312 }
4313 }
4314 else if (m_afState == HAL_AFSTATE_SCANNING) {
4315 switch (noti) {
4316 case AA_AFSTATE_INACTIVE:
Sungjoong Kang36c106c2012-08-23 17:38:20 -07004317 nextState = NO_TRANSITION;
Sungjoong Kang0f26b202012-08-17 15:43:12 -07004318 break;
4319 case AA_AFSTATE_ACTIVE_SCAN:
4320 nextState = NO_TRANSITION;
Sungjoong Kang36c106c2012-08-23 17:38:20 -07004321 m_AfHwStateFailed = false;
Sungjoong Kang0f26b202012-08-17 15:43:12 -07004322 break;
4323 case AA_AFSTATE_AF_ACQUIRED_FOCUS:
4324 nextState = HAL_AFSTATE_PASSIVE_FOCUSED;
Sungjoong Kang36c106c2012-08-23 17:38:20 -07004325 m_AfHwStateFailed = false;
Sungjoong Kang0f26b202012-08-17 15:43:12 -07004326 SetAfStateForService(ANDROID_CONTROL_AF_STATE_PASSIVE_FOCUSED);
4327 break;
4328 case AA_AFSTATE_AF_FAILED_FOCUS:
Sungjoong Kang36c106c2012-08-23 17:38:20 -07004329 nextState = HAL_AFSTATE_PASSIVE_FOCUSED;
4330 m_AfHwStateFailed = true;
4331 SetAfStateForService(ANDROID_CONTROL_AF_STATE_PASSIVE_FOCUSED);
Sungjoong Kang0f26b202012-08-17 15:43:12 -07004332 break;
4333 default:
4334 bWrongTransition = true;
4335 break;
4336 }
4337 }
4338 else if (m_afState == HAL_AFSTATE_PASSIVE_FOCUSED) {
4339 switch (noti) {
4340 case AA_AFSTATE_INACTIVE:
Sungjoong Kang36c106c2012-08-23 17:38:20 -07004341 nextState = NO_TRANSITION;
Sungjoong Kang0f26b202012-08-17 15:43:12 -07004342 break;
4343 case AA_AFSTATE_ACTIVE_SCAN:
4344 nextState = HAL_AFSTATE_SCANNING;
Sungjoong Kang36c106c2012-08-23 17:38:20 -07004345 m_AfHwStateFailed = false;
Sungjoong Kang0f26b202012-08-17 15:43:12 -07004346 SetAfStateForService(ANDROID_CONTROL_AF_STATE_PASSIVE_SCAN);
4347 break;
4348 case AA_AFSTATE_AF_ACQUIRED_FOCUS:
4349 nextState = NO_TRANSITION;
Sungjoong Kang36c106c2012-08-23 17:38:20 -07004350 m_AfHwStateFailed = false;
Sungjoong Kang0f26b202012-08-17 15:43:12 -07004351 break;
4352 case AA_AFSTATE_AF_FAILED_FOCUS:
Sungjoong Kang36c106c2012-08-23 17:38:20 -07004353 nextState = NO_TRANSITION;
4354 m_AfHwStateFailed = true;
Sungjoong Kang0f26b202012-08-17 15:43:12 -07004355 break;
4356 default:
4357 bWrongTransition = true;
4358 break;
4359 }
4360 }
4361 else if (m_afState == HAL_AFSTATE_NEEDS_DETERMINATION) {
4362 switch (noti) {
4363 case AA_AFSTATE_INACTIVE:
Sungjoong Kang36c106c2012-08-23 17:38:20 -07004364 nextState = NO_TRANSITION;
Sungjoong Kang0f26b202012-08-17 15:43:12 -07004365 break;
4366 case AA_AFSTATE_ACTIVE_SCAN:
4367 nextState = NO_TRANSITION;
4368 break;
4369 case AA_AFSTATE_AF_ACQUIRED_FOCUS:
4370 m_IsAfLockRequired = true;
4371 nextState = HAL_AFSTATE_LOCKED;
4372 SetAfStateForService(ANDROID_CONTROL_AF_STATE_FOCUSED_LOCKED);
4373 break;
4374 case AA_AFSTATE_AF_FAILED_FOCUS:
4375 m_IsAfLockRequired = true;
4376 nextState = HAL_AFSTATE_FAILED;
4377 SetAfStateForService(ANDROID_CONTROL_AF_STATE_NOT_FOCUSED_LOCKED);
4378 break;
4379 default:
4380 bWrongTransition = true;
4381 break;
4382 }
4383 }
4384 else if (m_afState == HAL_AFSTATE_LOCKED) {
4385 switch (noti) {
4386 case AA_AFSTATE_INACTIVE:
4387 nextState = NO_TRANSITION;
4388 break;
4389 case AA_AFSTATE_ACTIVE_SCAN:
4390 bWrongTransition = true;
4391 break;
4392 case AA_AFSTATE_AF_ACQUIRED_FOCUS:
4393 nextState = NO_TRANSITION;
4394 break;
4395 case AA_AFSTATE_AF_FAILED_FOCUS:
4396 default:
4397 bWrongTransition = true;
4398 break;
4399 }
4400 }
4401 else if (m_afState == HAL_AFSTATE_FAILED) {
4402 switch (noti) {
4403 case AA_AFSTATE_INACTIVE:
Sungjoong Kang36c106c2012-08-23 17:38:20 -07004404 bWrongTransition = true;
4405 break;
Sungjoong Kang0f26b202012-08-17 15:43:12 -07004406 case AA_AFSTATE_ACTIVE_SCAN:
Sungjoong Kang36c106c2012-08-23 17:38:20 -07004407 nextState = HAL_AFSTATE_SCANNING;
4408 break;
Sungjoong Kang0f26b202012-08-17 15:43:12 -07004409 case AA_AFSTATE_AF_ACQUIRED_FOCUS:
4410 bWrongTransition = true;
4411 break;
4412 case AA_AFSTATE_AF_FAILED_FOCUS:
4413 nextState = NO_TRANSITION;
4414 break;
4415 default:
4416 bWrongTransition = true;
4417 break;
4418 }
4419 }
4420 if (bWrongTransition) {
4421 ALOGV("(%s): Wrong Transition state(%d) noti(%d)", __FUNCTION__, m_afState, noti);
4422 return;
4423 }
4424 ALOGV("(%s): State (%d) -> (%d) by (%d)", __FUNCTION__, m_afState, nextState, noti);
4425 if (nextState != NO_TRANSITION)
4426 m_afState = nextState;
4427}
4428
4429void ExynosCameraHWInterface2::OnAfNotificationCAFVideo(enum aa_afstate noti)
4430{
4431 int nextState = NO_TRANSITION;
4432 bool bWrongTransition = false;
4433
4434 if (m_afState == HAL_AFSTATE_INACTIVE) {
4435 switch (noti) {
4436 case AA_AFSTATE_INACTIVE:
4437 case AA_AFSTATE_ACTIVE_SCAN:
4438 case AA_AFSTATE_AF_ACQUIRED_FOCUS:
4439 case AA_AFSTATE_AF_FAILED_FOCUS:
4440 default:
4441 nextState = NO_TRANSITION;
4442 break;
4443 }
4444 }
4445 else if (m_afState == HAL_AFSTATE_STARTED) {
4446 switch (noti) {
4447 case AA_AFSTATE_INACTIVE:
4448 nextState = NO_TRANSITION;
4449 break;
4450 case AA_AFSTATE_ACTIVE_SCAN:
4451 nextState = HAL_AFSTATE_SCANNING;
4452 SetAfStateForService(ANDROID_CONTROL_AF_STATE_PASSIVE_SCAN);
4453 break;
4454 case AA_AFSTATE_AF_ACQUIRED_FOCUS:
4455 nextState = HAL_AFSTATE_PASSIVE_FOCUSED;
4456 SetAfStateForService(ANDROID_CONTROL_AF_STATE_PASSIVE_FOCUSED);
4457 break;
4458 case AA_AFSTATE_AF_FAILED_FOCUS:
4459 nextState = HAL_AFSTATE_FAILED;
4460 SetAfStateForService(ANDROID_CONTROL_AF_STATE_NOT_FOCUSED_LOCKED);
4461 break;
4462 default:
4463 bWrongTransition = true;
4464 break;
4465 }
4466 }
4467 else if (m_afState == HAL_AFSTATE_SCANNING) {
4468 switch (noti) {
4469 case AA_AFSTATE_INACTIVE:
4470 bWrongTransition = true;
4471 break;
4472 case AA_AFSTATE_ACTIVE_SCAN:
4473 nextState = NO_TRANSITION;
4474 break;
4475 case AA_AFSTATE_AF_ACQUIRED_FOCUS:
4476 nextState = HAL_AFSTATE_PASSIVE_FOCUSED;
4477 SetAfStateForService(ANDROID_CONTROL_AF_STATE_PASSIVE_FOCUSED);
4478 break;
4479 case AA_AFSTATE_AF_FAILED_FOCUS:
4480 nextState = NO_TRANSITION;
Sungjoong Kang36c106c2012-08-23 17:38:20 -07004481 m_IsAfTriggerRequired = true;
Sungjoong Kang0f26b202012-08-17 15:43:12 -07004482 break;
4483 default:
4484 bWrongTransition = true;
4485 break;
4486 }
4487 }
4488 else if (m_afState == HAL_AFSTATE_PASSIVE_FOCUSED) {
4489 switch (noti) {
4490 case AA_AFSTATE_INACTIVE:
4491 bWrongTransition = true;
4492 break;
4493 case AA_AFSTATE_ACTIVE_SCAN:
4494 nextState = HAL_AFSTATE_SCANNING;
4495 SetAfStateForService(ANDROID_CONTROL_AF_STATE_PASSIVE_SCAN);
4496 break;
4497 case AA_AFSTATE_AF_ACQUIRED_FOCUS:
4498 nextState = NO_TRANSITION;
4499 break;
4500 case AA_AFSTATE_AF_FAILED_FOCUS:
4501 nextState = HAL_AFSTATE_FAILED;
4502 SetAfStateForService(ANDROID_CONTROL_AF_STATE_NOT_FOCUSED_LOCKED);
Sungjoong Kang8e2c2fd2012-08-27 00:02:22 -07004503 // TODO : needs NO_TRANSITION ?
Sungjoong Kang0f26b202012-08-17 15:43:12 -07004504 break;
4505 default:
4506 bWrongTransition = true;
4507 break;
4508 }
4509 }
4510 else if (m_afState == HAL_AFSTATE_NEEDS_DETERMINATION) {
4511 switch (noti) {
4512 case AA_AFSTATE_INACTIVE:
4513 bWrongTransition = true;
4514 break;
4515 case AA_AFSTATE_ACTIVE_SCAN:
4516 nextState = NO_TRANSITION;
4517 break;
4518 case AA_AFSTATE_AF_ACQUIRED_FOCUS:
4519 m_IsAfLockRequired = true;
4520 nextState = HAL_AFSTATE_LOCKED;
4521 SetAfStateForService(ANDROID_CONTROL_AF_STATE_FOCUSED_LOCKED);
4522 break;
4523 case AA_AFSTATE_AF_FAILED_FOCUS:
4524 nextState = HAL_AFSTATE_FAILED;
4525 SetAfStateForService(ANDROID_CONTROL_AF_STATE_NOT_FOCUSED_LOCKED);
4526 break;
4527 default:
4528 bWrongTransition = true;
4529 break;
4530 }
4531 }
4532 else if (m_afState == HAL_AFSTATE_LOCKED) {
4533 switch (noti) {
4534 case AA_AFSTATE_INACTIVE:
4535 nextState = NO_TRANSITION;
4536 break;
4537 case AA_AFSTATE_ACTIVE_SCAN:
4538 bWrongTransition = true;
4539 break;
4540 case AA_AFSTATE_AF_ACQUIRED_FOCUS:
4541 nextState = NO_TRANSITION;
4542 break;
4543 case AA_AFSTATE_AF_FAILED_FOCUS:
4544 default:
4545 bWrongTransition = true;
4546 break;
4547 }
4548 }
4549 else if (m_afState == HAL_AFSTATE_FAILED) {
4550 switch (noti) {
4551 case AA_AFSTATE_INACTIVE:
4552 case AA_AFSTATE_ACTIVE_SCAN:
4553 case AA_AFSTATE_AF_ACQUIRED_FOCUS:
4554 bWrongTransition = true;
4555 break;
4556 case AA_AFSTATE_AF_FAILED_FOCUS:
4557 nextState = NO_TRANSITION;
4558 break;
4559 default:
4560 bWrongTransition = true;
4561 break;
4562 }
4563 }
4564 if (bWrongTransition) {
4565 ALOGV("(%s): Wrong Transition state(%d) noti(%d)", __FUNCTION__, m_afState, noti);
4566 return;
4567 }
4568 ALOGV("(%s): State (%d) -> (%d) by (%d)", __FUNCTION__, m_afState, nextState, noti);
4569 if (nextState != NO_TRANSITION)
4570 m_afState = nextState;
4571}
4572
4573void ExynosCameraHWInterface2::OnAfCancel(int id)
4574{
Sungjoong Kang8e2c2fd2012-08-27 00:02:22 -07004575 m_afTriggerId = id;
4576
Sungjoong Kang0f26b202012-08-17 15:43:12 -07004577 switch (m_afMode) {
4578 case AA_AFMODE_AUTO:
4579 case AA_AFMODE_MACRO:
Sungjoong Kang8e2c2fd2012-08-27 00:02:22 -07004580 case AA_AFMODE_OFF:
Sungjoong Kang0f26b202012-08-17 15:43:12 -07004581 OnAfCancelAutoMacro(id);
4582 break;
4583 case AA_AFMODE_CONTINUOUS_VIDEO:
4584 OnAfCancelCAFVideo(id);
4585 break;
4586 case AA_AFMODE_CONTINUOUS_PICTURE:
4587 OnAfCancelCAFPicture(id);
4588 break;
Sungjoong Kang0f26b202012-08-17 15:43:12 -07004589 default:
4590 break;
4591 }
4592}
4593
4594void ExynosCameraHWInterface2::OnAfCancelAutoMacro(int id)
4595{
4596 int nextState = NO_TRANSITION;
4597 m_afTriggerId = id;
4598
Younghwan Joo6f19b6c2012-08-30 13:56:53 -07004599 if (m_afFlashEnableFlg) {
4600 m_afFlashCnt = IF_FLASH_AF_OFF;
4601 }
Sungjoong Kang0f26b202012-08-17 15:43:12 -07004602 switch (m_afState) {
4603 case HAL_AFSTATE_INACTIVE:
4604 nextState = NO_TRANSITION;
Sungjoong Kangcd13bb72012-08-28 13:05:01 -07004605 SetAfStateForService(ANDROID_CONTROL_AF_STATE_INACTIVE);
Sungjoong Kang0f26b202012-08-17 15:43:12 -07004606 break;
4607 case HAL_AFSTATE_NEEDS_COMMAND:
4608 case HAL_AFSTATE_STARTED:
4609 case HAL_AFSTATE_SCANNING:
4610 case HAL_AFSTATE_LOCKED:
4611 case HAL_AFSTATE_FAILED:
4612 SetAfMode(AA_AFMODE_OFF);
4613 SetAfStateForService(ANDROID_CONTROL_AF_STATE_INACTIVE);
4614 nextState = HAL_AFSTATE_INACTIVE;
4615 break;
4616 default:
4617 break;
4618 }
4619 ALOGV("(%s): State (%d) -> (%d)", __FUNCTION__, m_afState, nextState);
4620 if (nextState != NO_TRANSITION)
4621 m_afState = nextState;
4622}
4623
4624void ExynosCameraHWInterface2::OnAfCancelCAFPicture(int id)
4625{
4626 int nextState = NO_TRANSITION;
4627 m_afTriggerId = id;
4628
4629 switch (m_afState) {
4630 case HAL_AFSTATE_INACTIVE:
4631 nextState = NO_TRANSITION;
4632 break;
4633 case HAL_AFSTATE_NEEDS_COMMAND:
4634 case HAL_AFSTATE_STARTED:
4635 case HAL_AFSTATE_SCANNING:
4636 case HAL_AFSTATE_LOCKED:
4637 case HAL_AFSTATE_FAILED:
4638 case HAL_AFSTATE_NEEDS_DETERMINATION:
4639 case HAL_AFSTATE_PASSIVE_FOCUSED:
4640 SetAfMode(AA_AFMODE_OFF);
4641 SetAfStateForService(ANDROID_CONTROL_AF_STATE_INACTIVE);
4642 SetAfMode(AA_AFMODE_CONTINUOUS_PICTURE);
4643 nextState = HAL_AFSTATE_INACTIVE;
4644 break;
4645 default:
4646 break;
4647 }
4648 ALOGV("(%s): State (%d) -> (%d)", __FUNCTION__, m_afState, nextState);
4649 if (nextState != NO_TRANSITION)
4650 m_afState = nextState;
4651}
4652
4653void ExynosCameraHWInterface2::OnAfCancelCAFVideo(int id)
4654{
4655 int nextState = NO_TRANSITION;
4656 m_afTriggerId = id;
4657
4658 switch (m_afState) {
4659 case HAL_AFSTATE_INACTIVE:
4660 nextState = NO_TRANSITION;
4661 break;
4662 case HAL_AFSTATE_NEEDS_COMMAND:
4663 case HAL_AFSTATE_STARTED:
4664 case HAL_AFSTATE_SCANNING:
4665 case HAL_AFSTATE_LOCKED:
4666 case HAL_AFSTATE_FAILED:
4667 case HAL_AFSTATE_NEEDS_DETERMINATION:
4668 case HAL_AFSTATE_PASSIVE_FOCUSED:
4669 SetAfMode(AA_AFMODE_OFF);
4670 SetAfStateForService(ANDROID_CONTROL_AF_STATE_INACTIVE);
4671 SetAfMode(AA_AFMODE_CONTINUOUS_VIDEO);
4672 nextState = HAL_AFSTATE_INACTIVE;
4673 break;
4674 default:
4675 break;
4676 }
4677 ALOGV("(%s): State (%d) -> (%d)", __FUNCTION__, m_afState, nextState);
4678 if (nextState != NO_TRANSITION)
4679 m_afState = nextState;
4680}
4681
4682void ExynosCameraHWInterface2::SetAfStateForService(int newState)
4683{
Sungjoong Kang8e2c2fd2012-08-27 00:02:22 -07004684 if (m_serviceAfState != newState || newState == 0)
4685 m_notifyCb(CAMERA2_MSG_AUTOFOCUS, newState, m_afTriggerId, 0, m_callbackCookie);
Sungjoong Kang0f26b202012-08-17 15:43:12 -07004686 m_serviceAfState = newState;
Sungjoong Kang0f26b202012-08-17 15:43:12 -07004687}
4688
4689int ExynosCameraHWInterface2::GetAfStateForService()
4690{
4691 return m_serviceAfState;
4692}
4693
4694void ExynosCameraHWInterface2::SetAfMode(enum aa_afmode afMode)
4695{
4696 if (m_afMode != afMode) {
4697 if (m_IsAfModeUpdateRequired) {
4698 m_afMode2 = afMode;
4699 ALOGV("(%s): pending(%d) and new(%d)", __FUNCTION__, m_afMode, afMode);
4700 }
4701 else {
4702 ALOGV("(%s): current(%d) new(%d)", __FUNCTION__, m_afMode, afMode);
4703 m_IsAfModeUpdateRequired = true;
4704 m_afMode = afMode;
Sungjoong Kangcd13bb72012-08-28 13:05:01 -07004705 if (m_afModeWaitingCnt != 0) {
4706 m_afModeWaitingCnt = 0;
4707 OnAfTrigger(m_afPendingTriggerId);
4708 }
Sungjoong Kang8e2c2fd2012-08-27 00:02:22 -07004709 }
Sungjoong Kang0f26b202012-08-17 15:43:12 -07004710 }
4711}
4712
Sungjoong Kangeed7ed12012-08-23 16:35:08 -07004713void ExynosCameraHWInterface2::m_setExifFixedAttribute(void)
4714{
4715 char property[PROPERTY_VALUE_MAX];
4716
4717 //2 0th IFD TIFF Tags
Rebecca Schultz Zavin1b8ef182012-09-04 09:44:10 -07004718#if 0 // STOPSHIP TODO(aray): remove before launch, but for now don't leak product data
Sungjoong Kangeed7ed12012-08-23 16:35:08 -07004719 //3 Maker
4720 property_get("ro.product.brand", property, EXIF_DEF_MAKER);
4721 strncpy((char *)mExifInfo.maker, property,
4722 sizeof(mExifInfo.maker) - 1);
4723 mExifInfo.maker[sizeof(mExifInfo.maker) - 1] = '\0';
4724 //3 Model
4725 property_get("ro.product.model", property, EXIF_DEF_MODEL);
4726 strncpy((char *)mExifInfo.model, property,
4727 sizeof(mExifInfo.model) - 1);
4728 mExifInfo.model[sizeof(mExifInfo.model) - 1] = '\0';
4729 //3 Software
4730 property_get("ro.build.id", property, EXIF_DEF_SOFTWARE);
4731 strncpy((char *)mExifInfo.software, property,
4732 sizeof(mExifInfo.software) - 1);
4733 mExifInfo.software[sizeof(mExifInfo.software) - 1] = '\0';
Alex Ray5a92f772012-08-27 17:23:41 -07004734#endif
Sungjoong Kangeed7ed12012-08-23 16:35:08 -07004735
4736 //3 YCbCr Positioning
4737 mExifInfo.ycbcr_positioning = EXIF_DEF_YCBCR_POSITIONING;
4738
4739 //2 0th IFD Exif Private Tags
4740 //3 F Number
4741 mExifInfo.fnumber.num = EXIF_DEF_FNUMBER_NUM;
4742 mExifInfo.fnumber.den = EXIF_DEF_FNUMBER_DEN;
4743 //3 Exposure Program
4744 mExifInfo.exposure_program = EXIF_DEF_EXPOSURE_PROGRAM;
4745 //3 Exif Version
4746 memcpy(mExifInfo.exif_version, EXIF_DEF_EXIF_VERSION, sizeof(mExifInfo.exif_version));
4747 //3 Aperture
4748 uint32_t av = APEX_FNUM_TO_APERTURE((double)mExifInfo.fnumber.num/mExifInfo.fnumber.den);
4749 mExifInfo.aperture.num = av*EXIF_DEF_APEX_DEN;
4750 mExifInfo.aperture.den = EXIF_DEF_APEX_DEN;
4751 //3 Maximum lens aperture
4752 mExifInfo.max_aperture.num = mExifInfo.aperture.num;
4753 mExifInfo.max_aperture.den = mExifInfo.aperture.den;
4754 //3 Lens Focal Length
4755 mExifInfo.focal_length.num = EXIF_DEF_FOCAL_LEN_NUM;
4756 mExifInfo.focal_length.den = EXIF_DEF_FOCAL_LEN_DEN;
4757 //3 User Comments
4758 strcpy((char *)mExifInfo.user_comment, EXIF_DEF_USERCOMMENTS);
4759 //3 Color Space information
4760 mExifInfo.color_space = EXIF_DEF_COLOR_SPACE;
4761 //3 Exposure Mode
4762 mExifInfo.exposure_mode = EXIF_DEF_EXPOSURE_MODE;
4763
4764 //2 0th IFD GPS Info Tags
4765 unsigned char gps_version[4] = { 0x02, 0x02, 0x00, 0x00 };
4766 memcpy(mExifInfo.gps_version_id, gps_version, sizeof(gps_version));
4767
4768 //2 1th IFD TIFF Tags
4769 mExifInfo.compression_scheme = EXIF_DEF_COMPRESSION;
4770 mExifInfo.x_resolution.num = EXIF_DEF_RESOLUTION_NUM;
4771 mExifInfo.x_resolution.den = EXIF_DEF_RESOLUTION_DEN;
4772 mExifInfo.y_resolution.num = EXIF_DEF_RESOLUTION_NUM;
4773 mExifInfo.y_resolution.den = EXIF_DEF_RESOLUTION_DEN;
4774 mExifInfo.resolution_unit = EXIF_DEF_RESOLUTION_UNIT;
4775}
4776
4777void ExynosCameraHWInterface2::m_setExifChangedAttribute(exif_attribute_t *exifInfo, ExynosRect *rect,
4778 camera2_shot *currentEntry)
4779{
4780 camera2_dm *dm = &(currentEntry->dm);
4781 camera2_ctl *ctl = &(currentEntry->ctl);
4782
4783 ALOGV("(%s): framecnt(%d) exp(%lld) iso(%d)", __FUNCTION__, ctl->request.frameCount, dm->sensor.exposureTime,dm->aa.isoValue );
4784 if (!ctl->request.frameCount)
4785 return;
4786 //2 0th IFD TIFF Tags
4787 //3 Width
4788 exifInfo->width = rect->w;
4789 //3 Height
4790 exifInfo->height = rect->h;
4791 //3 Orientation
4792 switch (ctl->jpeg.orientation) {
4793 case 90:
4794 exifInfo->orientation = EXIF_ORIENTATION_90;
4795 break;
4796 case 180:
4797 exifInfo->orientation = EXIF_ORIENTATION_180;
4798 break;
4799 case 270:
4800 exifInfo->orientation = EXIF_ORIENTATION_270;
4801 break;
4802 case 0:
4803 default:
4804 exifInfo->orientation = EXIF_ORIENTATION_UP;
4805 break;
4806 }
4807
4808 //3 Date time
4809 time_t rawtime;
4810 struct tm *timeinfo;
4811 time(&rawtime);
4812 timeinfo = localtime(&rawtime);
4813 strftime((char *)exifInfo->date_time, 20, "%Y:%m:%d %H:%M:%S", timeinfo);
4814
4815 //2 0th IFD Exif Private Tags
4816 //3 Exposure Time
4817 int shutterSpeed = (dm->sensor.exposureTime/1000);
4818
4819 if (shutterSpeed < 0) {
4820 shutterSpeed = 100;
4821 }
4822
4823 exifInfo->exposure_time.num = 1;
4824 // x us -> 1/x s */
4825 //exifInfo->exposure_time.den = (uint32_t)(1000000 / shutterSpeed);
4826 exifInfo->exposure_time.den = (uint32_t)((double)1000000 / shutterSpeed);
4827
4828 //3 ISO Speed Rating
4829 exifInfo->iso_speed_rating = dm->aa.isoValue;
4830
4831 uint32_t av, tv, bv, sv, ev;
4832 av = APEX_FNUM_TO_APERTURE((double)exifInfo->fnumber.num / exifInfo->fnumber.den);
4833 tv = APEX_EXPOSURE_TO_SHUTTER((double)exifInfo->exposure_time.num / exifInfo->exposure_time.den);
4834 sv = APEX_ISO_TO_FILMSENSITIVITY(exifInfo->iso_speed_rating);
4835 bv = av + tv - sv;
4836 ev = av + tv;
4837 //ALOGD("Shutter speed=%d us, iso=%d", shutterSpeed, exifInfo->iso_speed_rating);
4838 ALOGD("AV=%d, TV=%d, SV=%d", av, tv, sv);
4839
4840 //3 Shutter Speed
4841 exifInfo->shutter_speed.num = tv * EXIF_DEF_APEX_DEN;
4842 exifInfo->shutter_speed.den = EXIF_DEF_APEX_DEN;
4843 //3 Brightness
4844 exifInfo->brightness.num = bv*EXIF_DEF_APEX_DEN;
4845 exifInfo->brightness.den = EXIF_DEF_APEX_DEN;
4846 //3 Exposure Bias
4847 if (ctl->aa.sceneMode== AA_SCENE_MODE_BEACH||
4848 ctl->aa.sceneMode== AA_SCENE_MODE_SNOW) {
4849 exifInfo->exposure_bias.num = EXIF_DEF_APEX_DEN;
4850 exifInfo->exposure_bias.den = EXIF_DEF_APEX_DEN;
4851 } else {
4852 exifInfo->exposure_bias.num = 0;
4853 exifInfo->exposure_bias.den = 0;
4854 }
4855 //3 Metering Mode
4856 /*switch (m_curCameraInfo->metering) {
4857 case METERING_MODE_CENTER:
4858 exifInfo->metering_mode = EXIF_METERING_CENTER;
4859 break;
4860 case METERING_MODE_MATRIX:
4861 exifInfo->metering_mode = EXIF_METERING_MULTISPOT;
4862 break;
4863 case METERING_MODE_SPOT:
4864 exifInfo->metering_mode = EXIF_METERING_SPOT;
4865 break;
4866 case METERING_MODE_AVERAGE:
4867 default:
4868 exifInfo->metering_mode = EXIF_METERING_AVERAGE;
4869 break;
4870 }*/
4871 exifInfo->metering_mode = EXIF_METERING_CENTER;
4872
4873 //3 Flash
4874 int flash = dm->flash.flashMode;
4875 if (dm->flash.flashMode == FLASH_MODE_OFF || flash < 0)
4876 exifInfo->flash = EXIF_DEF_FLASH;
4877 else
4878 exifInfo->flash = flash;
4879
4880 //3 White Balance
4881 if (dm->aa.awbMode == AA_AWBMODE_WB_AUTO)
4882 exifInfo->white_balance = EXIF_WB_AUTO;
4883 else
4884 exifInfo->white_balance = EXIF_WB_MANUAL;
4885
4886 //3 Scene Capture Type
4887 switch (ctl->aa.sceneMode) {
4888 case AA_SCENE_MODE_PORTRAIT:
4889 exifInfo->scene_capture_type = EXIF_SCENE_PORTRAIT;
4890 break;
4891 case AA_SCENE_MODE_LANDSCAPE:
4892 exifInfo->scene_capture_type = EXIF_SCENE_LANDSCAPE;
4893 break;
4894 case AA_SCENE_MODE_NIGHT_PORTRAIT:
4895 exifInfo->scene_capture_type = EXIF_SCENE_NIGHT;
4896 break;
4897 default:
4898 exifInfo->scene_capture_type = EXIF_SCENE_STANDARD;
4899 break;
4900 }
4901
4902 //2 0th IFD GPS Info Tags
4903 if (ctl->jpeg.gpsCoordinates[0] != 0 && ctl->jpeg.gpsCoordinates[1] != 0) {
4904
4905 if (ctl->jpeg.gpsCoordinates[0] > 0)
4906 strcpy((char *)exifInfo->gps_latitude_ref, "N");
4907 else
4908 strcpy((char *)exifInfo->gps_latitude_ref, "S");
4909
4910 if (ctl->jpeg.gpsCoordinates[1] > 0)
4911 strcpy((char *)exifInfo->gps_longitude_ref, "E");
4912 else
4913 strcpy((char *)exifInfo->gps_longitude_ref, "W");
4914
4915 if (ctl->jpeg.gpsCoordinates[2] > 0)
4916 exifInfo->gps_altitude_ref = 0;
4917 else
4918 exifInfo->gps_altitude_ref = 1;
4919
4920 double latitude = fabs(ctl->jpeg.gpsCoordinates[0] / 10000.0);
4921 double longitude = fabs(ctl->jpeg.gpsCoordinates[1] / 10000.0);
4922 double altitude = fabs(ctl->jpeg.gpsCoordinates[2] / 100.0);
4923
4924 exifInfo->gps_latitude[0].num = (uint32_t)latitude;
4925 exifInfo->gps_latitude[0].den = 1;
4926 exifInfo->gps_latitude[1].num = (uint32_t)((latitude - exifInfo->gps_latitude[0].num) * 60);
4927 exifInfo->gps_latitude[1].den = 1;
4928 exifInfo->gps_latitude[2].num = (uint32_t)((((latitude - exifInfo->gps_latitude[0].num) * 60)
4929 - exifInfo->gps_latitude[1].num) * 60);
4930 exifInfo->gps_latitude[2].den = 1;
4931
4932 exifInfo->gps_longitude[0].num = (uint32_t)longitude;
4933 exifInfo->gps_longitude[0].den = 1;
4934 exifInfo->gps_longitude[1].num = (uint32_t)((longitude - exifInfo->gps_longitude[0].num) * 60);
4935 exifInfo->gps_longitude[1].den = 1;
4936 exifInfo->gps_longitude[2].num = (uint32_t)((((longitude - exifInfo->gps_longitude[0].num) * 60)
4937 - exifInfo->gps_longitude[1].num) * 60);
4938 exifInfo->gps_longitude[2].den = 1;
4939
4940 exifInfo->gps_altitude.num = (uint32_t)altitude;
4941 exifInfo->gps_altitude.den = 1;
4942
4943 struct tm tm_data;
4944 long timestamp;
4945 timestamp = (long)ctl->jpeg.gpsTimestamp;
4946 gmtime_r(&timestamp, &tm_data);
4947 exifInfo->gps_timestamp[0].num = tm_data.tm_hour;
4948 exifInfo->gps_timestamp[0].den = 1;
4949 exifInfo->gps_timestamp[1].num = tm_data.tm_min;
4950 exifInfo->gps_timestamp[1].den = 1;
4951 exifInfo->gps_timestamp[2].num = tm_data.tm_sec;
4952 exifInfo->gps_timestamp[2].den = 1;
4953 snprintf((char*)exifInfo->gps_datestamp, sizeof(exifInfo->gps_datestamp),
4954 "%04d:%02d:%02d", tm_data.tm_year + 1900, tm_data.tm_mon + 1, tm_data.tm_mday);
4955
4956 exifInfo->enableGps = true;
4957 } else {
4958 exifInfo->enableGps = false;
4959 }
4960
4961 //2 1th IFD TIFF Tags
4962 exifInfo->widthThumb = ctl->jpeg.thumbnailSize[0];
4963 exifInfo->heightThumb = ctl->jpeg.thumbnailSize[1];
4964}
4965
Sungjoong Kang13d8c7b2012-07-14 10:20:39 +09004966ExynosCameraHWInterface2::MainThread::~MainThread()
Jiyoung Shinc15a6b02012-06-05 01:08:14 -07004967{
Sungjoong Kangad378612012-08-17 12:34:33 -07004968 ALOGV("(%s):", __FUNCTION__);
Sungjoong Kang13d8c7b2012-07-14 10:20:39 +09004969}
4970
4971void ExynosCameraHWInterface2::MainThread::release()
4972{
Sungjoong Kangad378612012-08-17 12:34:33 -07004973 ALOGV("(%s):", __func__);
Sungjoong Kang13d8c7b2012-07-14 10:20:39 +09004974 SetSignal(SIGNAL_THREAD_RELEASE);
Sungjoong Kang13d8c7b2012-07-14 10:20:39 +09004975}
4976
4977ExynosCameraHWInterface2::SensorThread::~SensorThread()
4978{
Sungjoong Kangad378612012-08-17 12:34:33 -07004979 ALOGV("(%s):", __FUNCTION__);
Sungjoong Kang13d8c7b2012-07-14 10:20:39 +09004980}
4981
4982void ExynosCameraHWInterface2::SensorThread::release()
4983{
Sungjoong Kangad378612012-08-17 12:34:33 -07004984 ALOGV("(%s):", __func__);
Sungjoong Kang13d8c7b2012-07-14 10:20:39 +09004985 SetSignal(SIGNAL_THREAD_RELEASE);
Sungjoong Kang13d8c7b2012-07-14 10:20:39 +09004986}
4987
4988ExynosCameraHWInterface2::IspThread::~IspThread()
4989{
Sungjoong Kangad378612012-08-17 12:34:33 -07004990 ALOGV("(%s):", __FUNCTION__);
Sungjoong Kang13d8c7b2012-07-14 10:20:39 +09004991}
4992
4993void ExynosCameraHWInterface2::IspThread::release()
4994{
Sungjoong Kangad378612012-08-17 12:34:33 -07004995 ALOGV("(%s):", __func__);
Sungjoong Kang13d8c7b2012-07-14 10:20:39 +09004996 SetSignal(SIGNAL_THREAD_RELEASE);
Sungjoong Kang13d8c7b2012-07-14 10:20:39 +09004997}
4998
4999ExynosCameraHWInterface2::StreamThread::~StreamThread()
5000{
Sungjoong Kangad378612012-08-17 12:34:33 -07005001 ALOGV("(%s):", __FUNCTION__);
Sungjoong Kang13d8c7b2012-07-14 10:20:39 +09005002}
5003
5004void ExynosCameraHWInterface2::StreamThread::setParameter(stream_parameters_t * new_parameters)
5005{
5006 ALOGV("DEBUG(%s):", __FUNCTION__);
5007
5008 m_tempParameters = new_parameters;
5009
5010 SetSignal(SIGNAL_STREAM_CHANGE_PARAMETER);
5011
5012 // TODO : return synchronously (after setting parameters asynchronously)
Sungjoong Kang9dd63e12012-07-24 00:25:51 +09005013 usleep(2000);
Sungjoong Kang13d8c7b2012-07-14 10:20:39 +09005014}
5015
5016void ExynosCameraHWInterface2::StreamThread::applyChange()
5017{
5018 memcpy(&m_parameters, m_tempParameters, sizeof(stream_parameters_t));
5019
Sungjoong Kang9dd63e12012-07-24 00:25:51 +09005020 ALOGV("DEBUG(%s): Applying Stream paremeters width(%d), height(%d)",
Sungjoong Kang13d8c7b2012-07-14 10:20:39 +09005021 __FUNCTION__, m_parameters.outputWidth, m_parameters.outputHeight);
5022}
5023
5024void ExynosCameraHWInterface2::StreamThread::release()
5025{
Sungjoong Kang9dd63e12012-07-24 00:25:51 +09005026 ALOGV("(%s):", __func__);
Sungjoong Kang13d8c7b2012-07-14 10:20:39 +09005027 SetSignal(SIGNAL_THREAD_RELEASE);
Sungjoong Kang13d8c7b2012-07-14 10:20:39 +09005028}
5029
5030int ExynosCameraHWInterface2::StreamThread::findBufferIndex(void * bufAddr)
5031{
5032 int index;
5033 for (index = 0 ; index < m_parameters.numSvcBuffers ; index++) {
5034 if (m_parameters.svcBuffers[index].virt.extP[0] == bufAddr)
5035 return index;
5036 }
5037 return -1;
Jiyoung Shinc15a6b02012-06-05 01:08:14 -07005038}
5039
Sungjoong Kang9dd63e12012-07-24 00:25:51 +09005040void ExynosCameraHWInterface2::StreamThread::setRecordingParameter(record_parameters_t * recordParm)
5041{
5042 memcpy(&m_recordParameters, recordParm, sizeof(record_parameters_t));
5043}
5044
Sungjoong Kang74d78eb2012-08-29 13:25:46 -07005045void ExynosCameraHWInterface2::StreamThread::setCallbackParameter(callback_parameters_t * callbackParm)
5046{
5047 memcpy(&m_previewCbParameters, callbackParm, sizeof(callback_parameters_t));
5048}
5049
Jiyoung Shinc15a6b02012-06-05 01:08:14 -07005050int ExynosCameraHWInterface2::createIonClient(ion_client ionClient)
5051{
5052 if (ionClient == 0) {
5053 ionClient = ion_client_create();
5054 if (ionClient < 0) {
Sungjoong Kang13d8c7b2012-07-14 10:20:39 +09005055 ALOGE("[%s]src ion client create failed, value = %d\n", __FUNCTION__, ionClient);
Jiyoung Shinc15a6b02012-06-05 01:08:14 -07005056 return 0;
5057 }
5058 }
5059
5060 return ionClient;
5061}
5062
5063int ExynosCameraHWInterface2::deleteIonClient(ion_client ionClient)
5064{
5065 if (ionClient != 0) {
5066 if (ionClient > 0) {
5067 ion_client_destroy(ionClient);
5068 }
5069 ionClient = 0;
5070 }
5071
5072 return ionClient;
5073}
5074
Sungjoong Kang13d8c7b2012-07-14 10:20:39 +09005075int ExynosCameraHWInterface2::allocCameraMemory(ion_client ionClient, ExynosBuffer *buf, int iMemoryNum)
Jiyoung Shinc15a6b02012-06-05 01:08:14 -07005076{
5077 int ret = 0;
5078 int i = 0;
5079
5080 if (ionClient == 0) {
Sungjoong Kang13d8c7b2012-07-14 10:20:39 +09005081 ALOGE("[%s] ionClient is zero (%d)\n", __FUNCTION__, ionClient);
Jiyoung Shinc15a6b02012-06-05 01:08:14 -07005082 return -1;
5083 }
5084
5085 for (i=0;i<iMemoryNum;i++) {
Sungjoong Kang13d8c7b2012-07-14 10:20:39 +09005086 if (buf->size.extS[i] == 0) {
Jiyoung Shinc15a6b02012-06-05 01:08:14 -07005087 break;
5088 }
5089
Sungjoong Kang13d8c7b2012-07-14 10:20:39 +09005090 buf->fd.extFd[i] = ion_alloc(ionClient, \
5091 buf->size.extS[i], 0, ION_HEAP_EXYNOS_MASK,0);
5092 if ((buf->fd.extFd[i] == -1) ||(buf->fd.extFd[i] == 0)) {
5093 ALOGE("[%s]ion_alloc(%d) failed\n", __FUNCTION__, buf->size.extS[i]);
5094 buf->fd.extFd[i] = -1;
Jiyoung Shinc15a6b02012-06-05 01:08:14 -07005095 freeCameraMemory(buf, iMemoryNum);
5096 return -1;
5097 }
5098
Sungjoong Kang13d8c7b2012-07-14 10:20:39 +09005099 buf->virt.extP[i] = (char *)ion_map(buf->fd.extFd[i], \
5100 buf->size.extS[i], 0);
5101 if ((buf->virt.extP[i] == (char *)MAP_FAILED) || (buf->virt.extP[i] == NULL)) {
5102 ALOGE("[%s]src ion map failed(%d)\n", __FUNCTION__, buf->size.extS[i]);
5103 buf->virt.extP[i] = (char *)MAP_FAILED;
Jiyoung Shinc15a6b02012-06-05 01:08:14 -07005104 freeCameraMemory(buf, iMemoryNum);
5105 return -1;
5106 }
Sungjoong Kang13d8c7b2012-07-14 10:20:39 +09005107 ALOGV("allocCameraMem : [%d][0x%08x] size(%d)", i, (unsigned int)(buf->virt.extP[i]), buf->size.extS[i]);
Jiyoung Shinc15a6b02012-06-05 01:08:14 -07005108 }
5109
5110 return ret;
5111}
5112
Sungjoong Kang13d8c7b2012-07-14 10:20:39 +09005113void ExynosCameraHWInterface2::freeCameraMemory(ExynosBuffer *buf, int iMemoryNum)
Jiyoung Shinc15a6b02012-06-05 01:08:14 -07005114{
Sungjoong Kang13d8c7b2012-07-14 10:20:39 +09005115
Jiyoung Shinc15a6b02012-06-05 01:08:14 -07005116 int i =0 ;
Sungjoong Kang15fd8232012-08-23 16:16:44 -07005117 int ret = 0;
Jiyoung Shinc15a6b02012-06-05 01:08:14 -07005118
5119 for (i=0;i<iMemoryNum;i++) {
Sungjoong Kang13d8c7b2012-07-14 10:20:39 +09005120 if (buf->fd.extFd[i] != -1) {
5121 if (buf->virt.extP[i] != (char *)MAP_FAILED) {
Sungjoong Kang15fd8232012-08-23 16:16:44 -07005122 ret = ion_unmap(buf->virt.extP[i], buf->size.extS[i]);
5123 if (ret < 0)
5124 ALOGE("ERR(%s)", __FUNCTION__);
Jiyoung Shinc15a6b02012-06-05 01:08:14 -07005125 }
Sungjoong Kang13d8c7b2012-07-14 10:20:39 +09005126 ion_free(buf->fd.extFd[i]);
Jiyoung Shinc15a6b02012-06-05 01:08:14 -07005127 }
Sungjoong Kang13d8c7b2012-07-14 10:20:39 +09005128 buf->fd.extFd[i] = -1;
5129 buf->virt.extP[i] = (char *)MAP_FAILED;
5130 buf->size.extS[i] = 0;
Jiyoung Shinc15a6b02012-06-05 01:08:14 -07005131 }
5132}
5133
Sungjoong Kang13d8c7b2012-07-14 10:20:39 +09005134void ExynosCameraHWInterface2::initCameraMemory(ExynosBuffer *buf, int iMemoryNum)
Jiyoung Shinc15a6b02012-06-05 01:08:14 -07005135{
5136 int i =0 ;
5137 for (i=0;i<iMemoryNum;i++) {
Sungjoong Kang13d8c7b2012-07-14 10:20:39 +09005138 buf->virt.extP[i] = (char *)MAP_FAILED;
5139 buf->fd.extFd[i] = -1;
5140 buf->size.extS[i] = 0;
Jiyoung Shinc15a6b02012-06-05 01:08:14 -07005141 }
5142}
5143
5144
Sungjoong Kang13d8c7b2012-07-14 10:20:39 +09005145
5146
Sungjoong Kang9dd63e12012-07-24 00:25:51 +09005147static camera2_device_t *g_cam2_device = NULL;
Sungjoong Kangb5237e62012-07-27 07:39:05 -07005148static bool g_camera_vaild = false;
Sungjoong Kangdaa1fcd2012-08-08 11:49:43 -07005149ExynosCamera2 * g_camera2[2] = { NULL, NULL };
Jiyoung Shinc15a6b02012-06-05 01:08:14 -07005150
5151static int HAL2_camera_device_close(struct hw_device_t* device)
5152{
Sungjoong Kangad378612012-08-17 12:34:33 -07005153 ALOGV("%s: ENTER", __FUNCTION__);
Jiyoung Shinc15a6b02012-06-05 01:08:14 -07005154 if (device) {
Sungjoong Kang9dd63e12012-07-24 00:25:51 +09005155
Jiyoung Shinc15a6b02012-06-05 01:08:14 -07005156 camera2_device_t *cam_device = (camera2_device_t *)device;
Sungjoong Kangad378612012-08-17 12:34:33 -07005157 ALOGV("cam_device(0x%08x):", (unsigned int)cam_device);
5158 ALOGV("g_cam2_device(0x%08x):", (unsigned int)g_cam2_device);
Jiyoung Shinc15a6b02012-06-05 01:08:14 -07005159 delete static_cast<ExynosCameraHWInterface2 *>(cam_device->priv);
Sungjoong Kangad378612012-08-17 12:34:33 -07005160 g_cam2_device = NULL;
Jiyoung Shinc15a6b02012-06-05 01:08:14 -07005161 free(cam_device);
Sungjoong Kangb5237e62012-07-27 07:39:05 -07005162 g_camera_vaild = false;
Jiyoung Shinc15a6b02012-06-05 01:08:14 -07005163 }
Sungjoong Kang15fd8232012-08-23 16:16:44 -07005164
Sungjoong Kangad378612012-08-17 12:34:33 -07005165 ALOGV("%s: EXIT", __FUNCTION__);
Jiyoung Shinc15a6b02012-06-05 01:08:14 -07005166 return 0;
5167}
5168
5169static inline ExynosCameraHWInterface2 *obj(const struct camera2_device *dev)
5170{
5171 return reinterpret_cast<ExynosCameraHWInterface2 *>(dev->priv);
5172}
5173
5174static int HAL2_device_set_request_queue_src_ops(const struct camera2_device *dev,
5175 const camera2_request_queue_src_ops_t *request_src_ops)
5176{
Sungjoong Kang13d8c7b2012-07-14 10:20:39 +09005177 ALOGV("DEBUG(%s):", __FUNCTION__);
Jiyoung Shinc15a6b02012-06-05 01:08:14 -07005178 return obj(dev)->setRequestQueueSrcOps(request_src_ops);
5179}
5180
5181static int HAL2_device_notify_request_queue_not_empty(const struct camera2_device *dev)
5182{
Sungjoong Kang13d8c7b2012-07-14 10:20:39 +09005183 ALOGV("DEBUG(%s):", __FUNCTION__);
Jiyoung Shinc15a6b02012-06-05 01:08:14 -07005184 return obj(dev)->notifyRequestQueueNotEmpty();
5185}
5186
5187static int HAL2_device_set_frame_queue_dst_ops(const struct camera2_device *dev,
5188 const camera2_frame_queue_dst_ops_t *frame_dst_ops)
5189{
Sungjoong Kang13d8c7b2012-07-14 10:20:39 +09005190 ALOGV("DEBUG(%s):", __FUNCTION__);
Jiyoung Shinc15a6b02012-06-05 01:08:14 -07005191 return obj(dev)->setFrameQueueDstOps(frame_dst_ops);
5192}
5193
5194static int HAL2_device_get_in_progress_count(const struct camera2_device *dev)
5195{
Sungjoong Kang13d8c7b2012-07-14 10:20:39 +09005196 ALOGV("DEBUG(%s):", __FUNCTION__);
Jiyoung Shinc15a6b02012-06-05 01:08:14 -07005197 return obj(dev)->getInProgressCount();
5198}
5199
5200static int HAL2_device_flush_captures_in_progress(const struct camera2_device *dev)
5201{
Sungjoong Kang13d8c7b2012-07-14 10:20:39 +09005202 ALOGV("DEBUG(%s):", __FUNCTION__);
Jiyoung Shinc15a6b02012-06-05 01:08:14 -07005203 return obj(dev)->flushCapturesInProgress();
5204}
5205
5206static int HAL2_device_construct_default_request(const struct camera2_device *dev,
5207 int request_template, camera_metadata_t **request)
5208{
Sungjoong Kang13d8c7b2012-07-14 10:20:39 +09005209 ALOGV("DEBUG(%s):", __FUNCTION__);
Jiyoung Shinc15a6b02012-06-05 01:08:14 -07005210 return obj(dev)->constructDefaultRequest(request_template, request);
5211}
5212
5213static int HAL2_device_allocate_stream(
5214 const struct camera2_device *dev,
5215 // inputs
5216 uint32_t width,
5217 uint32_t height,
5218 int format,
5219 const camera2_stream_ops_t *stream_ops,
5220 // outputs
5221 uint32_t *stream_id,
5222 uint32_t *format_actual,
5223 uint32_t *usage,
5224 uint32_t *max_buffers)
5225{
Sungjoong Kang9dd63e12012-07-24 00:25:51 +09005226 ALOGV("(%s): ", __FUNCTION__);
Jiyoung Shinc15a6b02012-06-05 01:08:14 -07005227 return obj(dev)->allocateStream(width, height, format, stream_ops,
5228 stream_id, format_actual, usage, max_buffers);
5229}
5230
5231
5232static int HAL2_device_register_stream_buffers(const struct camera2_device *dev,
5233 uint32_t stream_id,
5234 int num_buffers,
5235 buffer_handle_t *buffers)
5236{
Sungjoong Kang13d8c7b2012-07-14 10:20:39 +09005237 ALOGV("DEBUG(%s):", __FUNCTION__);
Jiyoung Shinc15a6b02012-06-05 01:08:14 -07005238 return obj(dev)->registerStreamBuffers(stream_id, num_buffers, buffers);
5239}
5240
5241static int HAL2_device_release_stream(
5242 const struct camera2_device *dev,
5243 uint32_t stream_id)
5244{
Sungjoong Kangad378612012-08-17 12:34:33 -07005245 ALOGV("DEBUG(%s)(id: %d):", __FUNCTION__, stream_id);
Sungjoong Kangb5237e62012-07-27 07:39:05 -07005246 if (!g_camera_vaild)
5247 return 0;
Jiyoung Shinc15a6b02012-06-05 01:08:14 -07005248 return obj(dev)->releaseStream(stream_id);
5249}
5250
5251static int HAL2_device_allocate_reprocess_stream(
5252 const struct camera2_device *dev,
5253 uint32_t width,
5254 uint32_t height,
5255 uint32_t format,
5256 const camera2_stream_in_ops_t *reprocess_stream_ops,
5257 // outputs
5258 uint32_t *stream_id,
5259 uint32_t *consumer_usage,
5260 uint32_t *max_buffers)
5261{
Sungjoong Kang13d8c7b2012-07-14 10:20:39 +09005262 ALOGV("DEBUG(%s):", __FUNCTION__);
Jiyoung Shinc15a6b02012-06-05 01:08:14 -07005263 return obj(dev)->allocateReprocessStream(width, height, format, reprocess_stream_ops,
5264 stream_id, consumer_usage, max_buffers);
5265}
5266
Eino-Ville Talvala2b0421d2012-09-04 13:41:55 -07005267static int HAL2_device_allocate_reprocess_stream_from_stream(
5268 const struct camera2_device *dev,
5269 uint32_t output_stream_id,
5270 const camera2_stream_in_ops_t *reprocess_stream_ops,
5271 // outputs
5272 uint32_t *stream_id)
5273{
5274 ALOGV("DEBUG(%s):", __FUNCTION__);
5275 // Temporary stub
5276 return 0;
5277}
5278
Jiyoung Shinc15a6b02012-06-05 01:08:14 -07005279static int HAL2_device_release_reprocess_stream(
5280 const struct camera2_device *dev,
5281 uint32_t stream_id)
5282{
Sungjoong Kang13d8c7b2012-07-14 10:20:39 +09005283 ALOGV("DEBUG(%s):", __FUNCTION__);
Jiyoung Shinc15a6b02012-06-05 01:08:14 -07005284 return obj(dev)->releaseReprocessStream(stream_id);
5285}
5286
5287static int HAL2_device_trigger_action(const struct camera2_device *dev,
5288 uint32_t trigger_id,
5289 int ext1,
5290 int ext2)
5291{
Sungjoong Kang13d8c7b2012-07-14 10:20:39 +09005292 ALOGV("DEBUG(%s):", __FUNCTION__);
Jiyoung Shinc15a6b02012-06-05 01:08:14 -07005293 return obj(dev)->triggerAction(trigger_id, ext1, ext2);
5294}
5295
5296static int HAL2_device_set_notify_callback(const struct camera2_device *dev,
5297 camera2_notify_callback notify_cb,
5298 void *user)
5299{
Sungjoong Kang13d8c7b2012-07-14 10:20:39 +09005300 ALOGV("DEBUG(%s):", __FUNCTION__);
Jiyoung Shinc15a6b02012-06-05 01:08:14 -07005301 return obj(dev)->setNotifyCallback(notify_cb, user);
5302}
5303
5304static int HAL2_device_get_metadata_vendor_tag_ops(const struct camera2_device*dev,
5305 vendor_tag_query_ops_t **ops)
5306{
Sungjoong Kang13d8c7b2012-07-14 10:20:39 +09005307 ALOGV("DEBUG(%s):", __FUNCTION__);
Jiyoung Shinc15a6b02012-06-05 01:08:14 -07005308 return obj(dev)->getMetadataVendorTagOps(ops);
5309}
5310
5311static int HAL2_device_dump(const struct camera2_device *dev, int fd)
5312{
Sungjoong Kang13d8c7b2012-07-14 10:20:39 +09005313 ALOGV("DEBUG(%s):", __FUNCTION__);
Jiyoung Shinc15a6b02012-06-05 01:08:14 -07005314 return obj(dev)->dump(fd);
5315}
5316
5317
5318
5319
5320
5321static int HAL2_getNumberOfCameras()
5322{
Sungjoong Kang9dd63e12012-07-24 00:25:51 +09005323 ALOGV("(%s): returning 2", __FUNCTION__);
5324 return 2;
Jiyoung Shinc15a6b02012-06-05 01:08:14 -07005325}
5326
5327
Jiyoung Shinc15a6b02012-06-05 01:08:14 -07005328static int HAL2_getCameraInfo(int cameraId, struct camera_info *info)
5329{
Sungjoong Kangad378612012-08-17 12:34:33 -07005330 ALOGV("DEBUG(%s): cameraID: %d", __FUNCTION__, cameraId);
Sungjoong Kang9dd63e12012-07-24 00:25:51 +09005331 static camera_metadata_t * mCameraInfo[2] = {NULL, NULL};
Sungjoong Kangad378612012-08-17 12:34:33 -07005332
Jiyoung Shinc15a6b02012-06-05 01:08:14 -07005333 status_t res;
Sungjoong Kang13d8c7b2012-07-14 10:20:39 +09005334
Sungjoong Kangdaa1fcd2012-08-08 11:49:43 -07005335 if (cameraId == 0) {
Sungjoong Kang9dd63e12012-07-24 00:25:51 +09005336 info->facing = CAMERA_FACING_BACK;
Sungjoong Kangdaa1fcd2012-08-08 11:49:43 -07005337 if (!g_camera2[0])
5338 g_camera2[0] = new ExynosCamera2(0);
5339 }
5340 else if (cameraId == 1) {
Sungjoong Kang9dd63e12012-07-24 00:25:51 +09005341 info->facing = CAMERA_FACING_FRONT;
Sungjoong Kangdaa1fcd2012-08-08 11:49:43 -07005342 if (!g_camera2[1])
5343 g_camera2[1] = new ExynosCamera2(1);
5344 }
5345 else
5346 return BAD_VALUE;
5347
Jiyoung Shinc15a6b02012-06-05 01:08:14 -07005348 info->orientation = 0;
5349 info->device_version = HARDWARE_DEVICE_API_VERSION(2, 0);
Sungjoong Kang9dd63e12012-07-24 00:25:51 +09005350 if (mCameraInfo[cameraId] == NULL) {
Sungjoong Kangdaa1fcd2012-08-08 11:49:43 -07005351 res = g_camera2[cameraId]->constructStaticInfo(&(mCameraInfo[cameraId]), cameraId, true);
Jiyoung Shinc15a6b02012-06-05 01:08:14 -07005352 if (res != OK) {
5353 ALOGE("%s: Unable to allocate static info: %s (%d)",
Sungjoong Kang13d8c7b2012-07-14 10:20:39 +09005354 __FUNCTION__, strerror(-res), res);
Jiyoung Shinc15a6b02012-06-05 01:08:14 -07005355 return res;
5356 }
Sungjoong Kangdaa1fcd2012-08-08 11:49:43 -07005357 res = g_camera2[cameraId]->constructStaticInfo(&(mCameraInfo[cameraId]), cameraId, false);
Jiyoung Shinc15a6b02012-06-05 01:08:14 -07005358 if (res != OK) {
5359 ALOGE("%s: Unable to fill in static info: %s (%d)",
Sungjoong Kang13d8c7b2012-07-14 10:20:39 +09005360 __FUNCTION__, strerror(-res), res);
Jiyoung Shinc15a6b02012-06-05 01:08:14 -07005361 return res;
5362 }
5363 }
Sungjoong Kang9dd63e12012-07-24 00:25:51 +09005364 info->static_camera_characteristics = mCameraInfo[cameraId];
Sungjoong Kang13d8c7b2012-07-14 10:20:39 +09005365 return NO_ERROR;
Jiyoung Shinc15a6b02012-06-05 01:08:14 -07005366}
5367
5368#define SET_METHOD(m) m : HAL2_device_##m
5369
5370static camera2_device_ops_t camera2_device_ops = {
5371 SET_METHOD(set_request_queue_src_ops),
5372 SET_METHOD(notify_request_queue_not_empty),
5373 SET_METHOD(set_frame_queue_dst_ops),
5374 SET_METHOD(get_in_progress_count),
5375 SET_METHOD(flush_captures_in_progress),
5376 SET_METHOD(construct_default_request),
5377 SET_METHOD(allocate_stream),
5378 SET_METHOD(register_stream_buffers),
5379 SET_METHOD(release_stream),
5380 SET_METHOD(allocate_reprocess_stream),
Eino-Ville Talvala2b0421d2012-09-04 13:41:55 -07005381 SET_METHOD(allocate_reprocess_stream_from_stream),
Jiyoung Shinc15a6b02012-06-05 01:08:14 -07005382 SET_METHOD(release_reprocess_stream),
5383 SET_METHOD(trigger_action),
5384 SET_METHOD(set_notify_callback),
5385 SET_METHOD(get_metadata_vendor_tag_ops),
5386 SET_METHOD(dump),
5387};
5388
5389#undef SET_METHOD
5390
5391
5392static int HAL2_camera_device_open(const struct hw_module_t* module,
5393 const char *id,
5394 struct hw_device_t** device)
5395{
Sungjoong Kang9dd63e12012-07-24 00:25:51 +09005396
Jiyoung Shinc15a6b02012-06-05 01:08:14 -07005397
5398 int cameraId = atoi(id);
Sungjoong Kang6044e502012-08-27 00:29:28 -07005399 int openInvalid = 0;
Sungjoong Kang9dd63e12012-07-24 00:25:51 +09005400
Sungjoong Kangb5237e62012-07-27 07:39:05 -07005401 g_camera_vaild = false;
Sungjoong Kangad378612012-08-17 12:34:33 -07005402 ALOGV("\n\n>>> I'm Samsung's CameraHAL_2(ID:%d) <<<\n\n", cameraId);
Jiyoung Shinc15a6b02012-06-05 01:08:14 -07005403 if (cameraId < 0 || cameraId >= HAL2_getNumberOfCameras()) {
Sungjoong Kang13d8c7b2012-07-14 10:20:39 +09005404 ALOGE("ERR(%s):Invalid camera ID %s", __FUNCTION__, id);
Jiyoung Shinc15a6b02012-06-05 01:08:14 -07005405 return -EINVAL;
5406 }
5407
Sungjoong Kangad378612012-08-17 12:34:33 -07005408 ALOGV("g_cam2_device : 0x%08x", (unsigned int)g_cam2_device);
Jiyoung Shinc15a6b02012-06-05 01:08:14 -07005409 if (g_cam2_device) {
5410 if (obj(g_cam2_device)->getCameraId() == cameraId) {
Sungjoong Kang13d8c7b2012-07-14 10:20:39 +09005411 ALOGV("DEBUG(%s):returning existing camera ID %s", __FUNCTION__, id);
Jiyoung Shinc15a6b02012-06-05 01:08:14 -07005412 goto done;
5413 } else {
Sungjoong Kang9dd63e12012-07-24 00:25:51 +09005414
5415 while (g_cam2_device)
5416 usleep(10000);
Jiyoung Shinc15a6b02012-06-05 01:08:14 -07005417 }
5418 }
5419
5420 g_cam2_device = (camera2_device_t *)malloc(sizeof(camera2_device_t));
Sungjoong Kangad378612012-08-17 12:34:33 -07005421 ALOGV("g_cam2_device : 0x%08x", (unsigned int)g_cam2_device);
Sungjoong Kang9dd63e12012-07-24 00:25:51 +09005422
Jiyoung Shinc15a6b02012-06-05 01:08:14 -07005423 if (!g_cam2_device)
5424 return -ENOMEM;
5425
5426 g_cam2_device->common.tag = HARDWARE_DEVICE_TAG;
5427 g_cam2_device->common.version = CAMERA_DEVICE_API_VERSION_2_0;
5428 g_cam2_device->common.module = const_cast<hw_module_t *>(module);
5429 g_cam2_device->common.close = HAL2_camera_device_close;
5430
5431 g_cam2_device->ops = &camera2_device_ops;
5432
Sungjoong Kang13d8c7b2012-07-14 10:20:39 +09005433 ALOGV("DEBUG(%s):open camera2 %s", __FUNCTION__, id);
Jiyoung Shinc15a6b02012-06-05 01:08:14 -07005434
Sungjoong Kang6044e502012-08-27 00:29:28 -07005435 g_cam2_device->priv = new ExynosCameraHWInterface2(cameraId, g_cam2_device, g_camera2[cameraId], &openInvalid);
5436 if (!openInvalid) {
5437 ALOGE("DEBUG(%s): ExynosCameraHWInterface2 creation failed(%d)", __FUNCTION__);
Younghwan Joo6f19b6c2012-08-30 13:56:53 -07005438 return -ENODEV;
Sungjoong Kang6044e502012-08-27 00:29:28 -07005439 }
Jiyoung Shinc15a6b02012-06-05 01:08:14 -07005440done:
5441 *device = (hw_device_t *)g_cam2_device;
Sungjoong Kang13d8c7b2012-07-14 10:20:39 +09005442 ALOGV("DEBUG(%s):opened camera2 %s (%p)", __FUNCTION__, id, *device);
Sungjoong Kangb5237e62012-07-27 07:39:05 -07005443 g_camera_vaild = true;
Jiyoung Shinc15a6b02012-06-05 01:08:14 -07005444
5445 return 0;
5446}
5447
5448
5449static hw_module_methods_t camera_module_methods = {
5450 open : HAL2_camera_device_open
5451};
5452
5453extern "C" {
5454 struct camera_module HAL_MODULE_INFO_SYM = {
5455 common : {
5456 tag : HARDWARE_MODULE_TAG,
5457 module_api_version : CAMERA_MODULE_API_VERSION_2_0,
5458 hal_api_version : HARDWARE_HAL_API_VERSION,
5459 id : CAMERA_HARDWARE_MODULE_ID,
5460 name : "Exynos Camera HAL2",
5461 author : "Samsung Corporation",
5462 methods : &camera_module_methods,
5463 dso: NULL,
5464 reserved: {0},
5465 },
5466 get_number_of_cameras : HAL2_getNumberOfCameras,
5467 get_camera_info : HAL2_getCameraInfo
5468 };
5469}
5470
5471}; // namespace android