blob: 205807aa1d5445e998f1bff9f8ff5fb6e90cf112 [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
252int cam_int_s_input(node_info_t *node, int index)
253{
254 int ret;
Sungjoong Kang13d8c7b2012-07-14 10:20:39 +0900255
Jiyoung Shinc15a6b02012-06-05 01:08:14 -0700256 ret = exynos_v4l2_s_input(node->fd, index);
257 if (ret < 0)
Sungjoong Kang13d8c7b2012-07-14 10:20:39 +0900258 ALOGE("%s: VIDIOC_S_INPUT failed (%d)",__FUNCTION__, ret);
Jiyoung Shinc15a6b02012-06-05 01:08:14 -0700259
260 return ret;
261}
262
263
264gralloc_module_t const* ExynosCameraHWInterface2::m_grallocHal;
265
266RequestManager::RequestManager(SignalDrivenThread* main_thread):
267 m_numOfEntries(0),
Sungjoong Kangad378612012-08-17 12:34:33 -0700268 m_entryInsertionIndex(-1),
269 m_entryProcessingIndex(-1),
270 m_entryFrameOutputIndex(-1),
Sungjoong Kang2bdec062012-08-17 15:47:56 -0700271 m_lastAeMode(0),
272 m_lastAaMode(0),
273 m_lastAwbMode(0),
274 m_lastAeComp(0),
Sungjoong Kangad378612012-08-17 12:34:33 -0700275 m_frameIndex(-1)
Jiyoung Shinc15a6b02012-06-05 01:08:14 -0700276{
277 m_metadataConverter = new MetadataConverter;
278 m_mainThread = main_thread;
Sungjoong Kang13d8c7b2012-07-14 10:20:39 +0900279 for (int i=0 ; i<NUM_MAX_REQUEST_MGR_ENTRY; i++) {
Sungjoong Kang13d8c7b2012-07-14 10:20:39 +0900280 memset(&(entries[i]), 0x00, sizeof(request_manager_entry_t));
Sungjoong Kangbe494d12012-08-04 15:36:56 -0700281 entries[i].internal_shot.shot.ctl.request.frameCount = -1;
Sungjoong Kang13d8c7b2012-07-14 10:20:39 +0900282 }
Sungjoong Kangad378612012-08-17 12:34:33 -0700283 m_sensorPipelineSkipCnt = 0;
Jiyoung Shinc15a6b02012-06-05 01:08:14 -0700284 return;
285}
286
287RequestManager::~RequestManager()
288{
Sungjoong Kang15fd8232012-08-23 16:16:44 -0700289 ALOGV("%s", __FUNCTION__);
290 if (m_metadataConverter != NULL) {
291 delete m_metadataConverter;
292 m_metadataConverter = NULL;
293 }
294
Jiyoung Shinc15a6b02012-06-05 01:08:14 -0700295 return;
296}
297
298int RequestManager::GetNumEntries()
299{
300 return m_numOfEntries;
301}
302
Sungjoong Kang9dd63e12012-07-24 00:25:51 +0900303void RequestManager::SetDefaultParameters(int cropX)
304{
305 m_cropX = cropX;
306}
307
Jiyoung Shinc15a6b02012-06-05 01:08:14 -0700308bool RequestManager::IsRequestQueueFull()
309{
310 Mutex::Autolock lock(m_requestMutex);
311 if (m_numOfEntries>=NUM_MAX_REQUEST_MGR_ENTRY)
312 return true;
313 else
314 return false;
315}
316
317void RequestManager::RegisterRequest(camera_metadata_t * new_request)
318{
Sungjoong Kang13d8c7b2012-07-14 10:20:39 +0900319 ALOGV("DEBUG(%s):", __FUNCTION__);
320
Jiyoung Shinc15a6b02012-06-05 01:08:14 -0700321 Mutex::Autolock lock(m_requestMutex);
Sungjoong Kang13d8c7b2012-07-14 10:20:39 +0900322
Jiyoung Shinc15a6b02012-06-05 01:08:14 -0700323 request_manager_entry * newEntry = NULL;
Sungjoong Kang9dd63e12012-07-24 00:25:51 +0900324 int newInsertionIndex = GetNextIndex(m_entryInsertionIndex);
Sungjoong Kang13d8c7b2012-07-14 10:20:39 +0900325 ALOGV("DEBUG(%s): got lock, new insertIndex(%d), cnt before reg(%d)", __FUNCTION__,newInsertionIndex,m_numOfEntries );
Jiyoung Shinc15a6b02012-06-05 01:08:14 -0700326
Sungjoong Kang13d8c7b2012-07-14 10:20:39 +0900327
Jiyoung Shinc15a6b02012-06-05 01:08:14 -0700328 newEntry = &(entries[newInsertionIndex]);
329
330 if (newEntry->status!=EMPTY) {
Sungjoong Kang13d8c7b2012-07-14 10:20:39 +0900331 ALOGV("DEBUG(%s): Circular buffer abnormal ", __FUNCTION__);
332 return;
Jiyoung Shinc15a6b02012-06-05 01:08:14 -0700333 }
334 newEntry->status = REGISTERED;
335 newEntry->original_request = new_request;
Sungjoong Kangad378612012-08-17 12:34:33 -0700336 memset(&(newEntry->internal_shot), 0, sizeof(struct camera2_shot_ext));
Sungjoong Kang13d8c7b2012-07-14 10:20:39 +0900337 m_metadataConverter->ToInternalShot(new_request, &(newEntry->internal_shot));
Sungjoong Kangb56dcc02012-08-08 13:38:09 -0700338 newEntry->output_stream_count = newEntry->internal_shot.shot.ctl.request.outputStreams[15];
Jiyoung Shinc15a6b02012-06-05 01:08:14 -0700339
340 m_numOfEntries++;
341 m_entryInsertionIndex = newInsertionIndex;
342
Sungjoong Kang13d8c7b2012-07-14 10:20:39 +0900343
Jiyoung Shinc15a6b02012-06-05 01:08:14 -0700344 ALOGV("## RegisterReq DONE num(%d), insert(%d), processing(%d), frame(%d), (frameCnt(%d))",
Sungjoong Kangbe494d12012-08-04 15:36:56 -0700345 m_numOfEntries,m_entryInsertionIndex,m_entryProcessingIndex, m_entryFrameOutputIndex, newEntry->internal_shot.shot.ctl.request.frameCount);
Jiyoung Shinc15a6b02012-06-05 01:08:14 -0700346}
347
348void RequestManager::DeregisterRequest(camera_metadata_t ** deregistered_request)
349{
Sungjoong Kang13d8c7b2012-07-14 10:20:39 +0900350 ALOGV("DEBUG(%s):", __FUNCTION__);
Sungjoong Kangad378612012-08-17 12:34:33 -0700351 int frame_index;
352 request_manager_entry * currentEntry;
353
Jiyoung Shinc15a6b02012-06-05 01:08:14 -0700354 Mutex::Autolock lock(m_requestMutex);
355
Sungjoong Kangad378612012-08-17 12:34:33 -0700356 frame_index = GetFrameIndex();
357 currentEntry = &(entries[frame_index]);
Sungjoong Kangbe494d12012-08-04 15:36:56 -0700358 if (currentEntry->status != CAPTURED) {
Sungjoong Kangad378612012-08-17 12:34:33 -0700359 ALOGV("DBG(%s): Circular buffer abnormal. processing(%d), frame(%d), status(%d) ", __FUNCTION__
Jiyoung Shinc15a6b02012-06-05 01:08:14 -0700360 , m_entryProcessingIndex, m_entryFrameOutputIndex,(int)(currentEntry->status));
Sungjoong Kang13d8c7b2012-07-14 10:20:39 +0900361 return;
Jiyoung Shinc15a6b02012-06-05 01:08:14 -0700362 }
Sungjoong Kang13d8c7b2012-07-14 10:20:39 +0900363 if (deregistered_request) *deregistered_request = currentEntry->original_request;
364
Jiyoung Shinc15a6b02012-06-05 01:08:14 -0700365 currentEntry->status = EMPTY;
366 currentEntry->original_request = NULL;
Sungjoong Kangbe494d12012-08-04 15:36:56 -0700367 memset(&(currentEntry->internal_shot), 0, sizeof(struct camera2_shot_ext));
368 currentEntry->internal_shot.shot.ctl.request.frameCount = -1;
Jiyoung Shinc15a6b02012-06-05 01:08:14 -0700369 currentEntry->output_stream_count = 0;
Sungjoong Kang13d8c7b2012-07-14 10:20:39 +0900370 currentEntry->dynamic_meta_vaild = false;
Jiyoung Shinc15a6b02012-06-05 01:08:14 -0700371 m_numOfEntries--;
372 ALOGV("## DeRegistReq DONE num(%d), insert(%d), processing(%d), frame(%d)",
373 m_numOfEntries,m_entryInsertionIndex,m_entryProcessingIndex, m_entryFrameOutputIndex);
Sungjoong Kang13d8c7b2012-07-14 10:20:39 +0900374
Jiyoung Shinc15a6b02012-06-05 01:08:14 -0700375 return;
Jiyoung Shinc15a6b02012-06-05 01:08:14 -0700376}
377
Sungjoong Kang13d8c7b2012-07-14 10:20:39 +0900378bool RequestManager::PrepareFrame(size_t* num_entries, size_t* frame_size,
Sungjoong Kang0f26b202012-08-17 15:43:12 -0700379 camera_metadata_t ** prepared_frame, int afState)
Jiyoung Shinc15a6b02012-06-05 01:08:14 -0700380{
Sungjoong Kang13d8c7b2012-07-14 10:20:39 +0900381 ALOGV("DEBUG(%s):", __FUNCTION__);
Jiyoung Shinc15a6b02012-06-05 01:08:14 -0700382 Mutex::Autolock lock(m_requestMutex);
383 status_t res = NO_ERROR;
Sungjoong Kangad378612012-08-17 12:34:33 -0700384 int tempFrameOutputIndex = GetFrameIndex();
Sungjoong Kang13d8c7b2012-07-14 10:20:39 +0900385 request_manager_entry * currentEntry = &(entries[tempFrameOutputIndex]);
386 ALOGV("DEBUG(%s): processing(%d), frameOut(%d), insert(%d) recentlycompleted(%d)", __FUNCTION__,
387 m_entryProcessingIndex, m_entryFrameOutputIndex, m_entryInsertionIndex, m_completedIndex);
388
Sungjoong Kangbe494d12012-08-04 15:36:56 -0700389 if (currentEntry->status != CAPTURED) {
Sungjoong Kangad378612012-08-17 12:34:33 -0700390 ALOGV("DBG(%s): Circular buffer abnormal status(%d)", __FUNCTION__, (int)(currentEntry->status));
Sungjoong Kang13d8c7b2012-07-14 10:20:39 +0900391
392 return false;
393 }
394 m_entryFrameOutputIndex = tempFrameOutputIndex;
Sungjoong Kangfd2d78a2012-08-26 17:44:25 -0700395 m_tempFrameMetadata = place_camera_metadata(m_tempFrameMetadataBuf, 2000, 20, 500); //estimated
Sungjoong Kang0f26b202012-08-17 15:43:12 -0700396 add_camera_metadata_entry(m_tempFrameMetadata, ANDROID_CONTROL_AF_STATE, &afState, 1);
Sungjoong Kang13d8c7b2012-07-14 10:20:39 +0900397 res = m_metadataConverter->ToDynamicMetadata(&(currentEntry->internal_shot),
Jiyoung Shinc15a6b02012-06-05 01:08:14 -0700398 m_tempFrameMetadata);
399 if (res!=NO_ERROR) {
Sungjoong Kang13d8c7b2012-07-14 10:20:39 +0900400 ALOGE("ERROR(%s): ToDynamicMetadata (%d) ", __FUNCTION__, res);
401 return false;
Jiyoung Shinc15a6b02012-06-05 01:08:14 -0700402 }
403 *num_entries = get_camera_metadata_entry_count(m_tempFrameMetadata);
404 *frame_size = get_camera_metadata_size(m_tempFrameMetadata);
405 *prepared_frame = m_tempFrameMetadata;
Sungjoong Kang13d8c7b2012-07-14 10:20:39 +0900406 ALOGV("## PrepareFrame DONE: frameOut(%d) frameCnt-req(%d)", m_entryFrameOutputIndex,
Sungjoong Kangbe494d12012-08-04 15:36:56 -0700407 currentEntry->internal_shot.shot.ctl.request.frameCount);
Sungjoong Kang9dd63e12012-07-24 00:25:51 +0900408 // Dump();
Sungjoong Kang13d8c7b2012-07-14 10:20:39 +0900409 return true;
Jiyoung Shinc15a6b02012-06-05 01:08:14 -0700410}
411
Sungjoong Kang0f26b202012-08-17 15:43:12 -0700412int RequestManager::MarkProcessingRequest(ExynosBuffer* buf, int *afMode)
Jiyoung Shinc15a6b02012-06-05 01:08:14 -0700413{
Sungjoong Kangad378612012-08-17 12:34:33 -0700414
Jiyoung Shinc15a6b02012-06-05 01:08:14 -0700415 Mutex::Autolock lock(m_requestMutex);
Sungjoong Kang13d8c7b2012-07-14 10:20:39 +0900416 struct camera2_shot_ext * shot_ext;
Sungjoong Kangb56dcc02012-08-08 13:38:09 -0700417 struct camera2_shot_ext * request_shot;
Sungjoong Kang13d8c7b2012-07-14 10:20:39 +0900418 int targetStreamIndex = 0;
Sungjoong Kangad378612012-08-17 12:34:33 -0700419 request_manager_entry * newEntry = NULL;
Sungjoong Kang0f26b202012-08-17 15:43:12 -0700420 static int count = 0;
Sungjoong Kang13d8c7b2012-07-14 10:20:39 +0900421
Sungjoong Kang13d8c7b2012-07-14 10:20:39 +0900422 if (m_numOfEntries == 0) {
Sungjoong Kangad378612012-08-17 12:34:33 -0700423 ALOGD("DEBUG(%s): Request Manager Empty ", __FUNCTION__);
Sungjoong Kang13d8c7b2012-07-14 10:20:39 +0900424 return -1;
425 }
426
427 if ((m_entryProcessingIndex == m_entryInsertionIndex)
Sungjoong Kangbe494d12012-08-04 15:36:56 -0700428 && (entries[m_entryProcessingIndex].status == REQUESTED || entries[m_entryProcessingIndex].status == CAPTURED)) {
Sungjoong Kangad378612012-08-17 12:34:33 -0700429 ALOGD("## MarkProcReq skipping(request underrun) - num(%d), insert(%d), processing(%d), frame(%d)",
Sungjoong Kang13d8c7b2012-07-14 10:20:39 +0900430 m_numOfEntries,m_entryInsertionIndex,m_entryProcessingIndex, m_entryFrameOutputIndex);
431 return -1;
432 }
Jiyoung Shinc15a6b02012-06-05 01:08:14 -0700433
Sungjoong Kang9dd63e12012-07-24 00:25:51 +0900434 int newProcessingIndex = GetNextIndex(m_entryProcessingIndex);
Sungjoong Kangad378612012-08-17 12:34:33 -0700435 ALOGV("DEBUG(%s): index(%d)", __FUNCTION__, newProcessingIndex);
Jiyoung Shinc15a6b02012-06-05 01:08:14 -0700436
Jiyoung Shinc15a6b02012-06-05 01:08:14 -0700437 newEntry = &(entries[newProcessingIndex]);
Sungjoong Kangad378612012-08-17 12:34:33 -0700438 request_shot = &(newEntry->internal_shot);
Sungjoong Kang0f26b202012-08-17 15:43:12 -0700439 *afMode = (int)(newEntry->internal_shot.shot.ctl.aa.afMode);
Sungjoong Kangbe494d12012-08-04 15:36:56 -0700440 if (newEntry->status != REGISTERED) {
Sungjoong Kangad378612012-08-17 12:34:33 -0700441 ALOGD("DEBUG(%s)(%d): Circular buffer abnormal ", __FUNCTION__, newProcessingIndex);
Sungjoong Kang13d8c7b2012-07-14 10:20:39 +0900442 return -1;
Jiyoung Shinc15a6b02012-06-05 01:08:14 -0700443 }
Sungjoong Kangad378612012-08-17 12:34:33 -0700444
Sungjoong Kangbe494d12012-08-04 15:36:56 -0700445 newEntry->status = REQUESTED;
Jiyoung Shinc15a6b02012-06-05 01:08:14 -0700446
Sungjoong Kangad378612012-08-17 12:34:33 -0700447 shot_ext = (struct camera2_shot_ext *)buf->virt.extP[1];
Sungjoong Kang13d8c7b2012-07-14 10:20:39 +0900448
Sungjoong Kangad378612012-08-17 12:34:33 -0700449 memset(shot_ext, 0x00, sizeof(struct camera2_shot_ext));
450 shot_ext->shot.ctl.request.frameCount = request_shot->shot.ctl.request.frameCount;
Sungjoong Kang13d8c7b2012-07-14 10:20:39 +0900451 shot_ext->request_sensor = 1;
Sungjoong Kang9dd63e12012-07-24 00:25:51 +0900452 shot_ext->dis_bypass = 1;
453 shot_ext->dnr_bypass = 1;
Sungjoong Kangad378612012-08-17 12:34:33 -0700454 shot_ext->fd_bypass = 1;
455 shot_ext->setfile = 0;
456
Sungjoong Kang13d8c7b2012-07-14 10:20:39 +0900457 for (int i = 0; i < newEntry->output_stream_count; i++) {
Sungjoong Kangbe494d12012-08-04 15:36:56 -0700458 targetStreamIndex = newEntry->internal_shot.shot.ctl.request.outputStreams[i];
Sungjoong Kang13d8c7b2012-07-14 10:20:39 +0900459
460 if (targetStreamIndex==0) {
461 ALOGV("DEBUG(%s): outputstreams(%d) is for scalerP", __FUNCTION__, i);
462 shot_ext->request_scp = 1;
Sungjoong Kangfd2d78a2012-08-26 17:44:25 -0700463 if (shot_ext->shot.ctl.stats.faceDetectMode != FACEDETECT_MODE_OFF)
464 shot_ext->fd_bypass = 0;
Sungjoong Kang13d8c7b2012-07-14 10:20:39 +0900465 }
Sungjoong Kang9dd63e12012-07-24 00:25:51 +0900466 else if (targetStreamIndex == 1) {
Sungjoong Kang13d8c7b2012-07-14 10:20:39 +0900467 ALOGV("DEBUG(%s): outputstreams(%d) is for scalerC", __FUNCTION__, i);
468 shot_ext->request_scc = 1;
Sungjoong Kang9dd63e12012-07-24 00:25:51 +0900469 }
470 else if (targetStreamIndex == 2) {
471 ALOGV("DEBUG(%s): outputstreams(%d) is for scalerP (record)", __FUNCTION__, i);
472 shot_ext->request_scp = 1;
473 shot_ext->shot.ctl.request.outputStreams[2] = 1;
Sungjoong Kangfd2d78a2012-08-26 17:44:25 -0700474 if (shot_ext->shot.ctl.stats.faceDetectMode != FACEDETECT_MODE_OFF)
475 shot_ext->fd_bypass = 0;
Sungjoong Kang13d8c7b2012-07-14 10:20:39 +0900476 }
477 else {
478 ALOGV("DEBUG(%s): outputstreams(%d) has abnormal value(%d)", __FUNCTION__, i, targetStreamIndex);
479 }
480 }
Sungjoong Kangad378612012-08-17 12:34:33 -0700481
Sungjoong Kang0f26b202012-08-17 15:43:12 -0700482 if (count == 0){
483 shot_ext->shot.ctl.aa.mode = AA_CONTROL_AUTO;
484 } else
485 shot_ext->shot.ctl.aa.mode = AA_CONTROL_NONE;
486
487 count++;
Sungjoong Kangad378612012-08-17 12:34:33 -0700488 shot_ext->shot.ctl.request.metadataMode = METADATA_MODE_FULL;
489 shot_ext->shot.ctl.stats.faceDetectMode = FACEDETECT_MODE_FULL;
490 shot_ext->shot.magicNumber = 0x23456789;
491 shot_ext->shot.ctl.sensor.exposureTime = 0;
492 shot_ext->shot.ctl.sensor.frameDuration = 33*1000*1000;
493 shot_ext->shot.ctl.sensor.sensitivity = 0;
494
495 shot_ext->shot.ctl.scaler.cropRegion[0] = 0;
496 shot_ext->shot.ctl.scaler.cropRegion[1] = 0;
497 shot_ext->shot.ctl.scaler.cropRegion[2] = m_cropX;
498
Sungjoong Kang13d8c7b2012-07-14 10:20:39 +0900499 m_entryProcessingIndex = newProcessingIndex;
Sungjoong Kangad378612012-08-17 12:34:33 -0700500 return newProcessingIndex;
Jiyoung Shinc15a6b02012-06-05 01:08:14 -0700501}
502
Sungjoong Kang9dd63e12012-07-24 00:25:51 +0900503void RequestManager::NotifyStreamOutput(int frameCnt, int stream_id)
Jiyoung Shinc15a6b02012-06-05 01:08:14 -0700504{
Sungjoong Kang9dd63e12012-07-24 00:25:51 +0900505 int index;
506
507 ALOGV("DEBUG(%s): frameCnt(%d), stream_id(%d)", __FUNCTION__, frameCnt, stream_id);
508
509 index = FindEntryIndexByFrameCnt(frameCnt);
510 if (index == -1) {
511 ALOGE("ERR(%s): Cannot find entry for frameCnt(%d)", __FUNCTION__, frameCnt);
512 return;
513 }
514 ALOGV("DEBUG(%s): frameCnt(%d), stream_id(%d) last cnt (%d)", __FUNCTION__, frameCnt, stream_id, entries[index].output_stream_count);
515
Sungjoong Kangbe494d12012-08-04 15:36:56 -0700516 entries[index].output_stream_count--; //TODO : match stream id also
517 CheckCompleted(index);
Jiyoung Shinc15a6b02012-06-05 01:08:14 -0700518 return;
519}
520
Sungjoong Kang13d8c7b2012-07-14 10:20:39 +0900521void RequestManager::CheckCompleted(int index)
522{
Sungjoong Kang9dd63e12012-07-24 00:25:51 +0900523 ALOGV("DEBUG(%s): reqIndex(%d) current Count(%d)", __FUNCTION__, index, entries[index].output_stream_count);
Sungjoong Kangad378612012-08-17 12:34:33 -0700524 SetFrameIndex(index);
525 m_mainThread->SetSignal(SIGNAL_MAIN_STREAM_OUTPUT_DONE);
Sungjoong Kang13d8c7b2012-07-14 10:20:39 +0900526 return;
527}
Sungjoong Kang13d8c7b2012-07-14 10:20:39 +0900528
Sungjoong Kangad378612012-08-17 12:34:33 -0700529void RequestManager::SetFrameIndex(int index)
530{
531 Mutex::Autolock lock(m_requestMutex);
532 m_frameIndex = index;
533}
534
535int RequestManager::GetFrameIndex()
536{
537 return m_frameIndex;
538}
539
540void RequestManager::ApplyDynamicMetadata(struct camera2_shot_ext *shot_ext)
Sungjoong Kang13d8c7b2012-07-14 10:20:39 +0900541{
Sungjoong Kang9dd63e12012-07-24 00:25:51 +0900542 int index;
Sungjoong Kangb56dcc02012-08-08 13:38:09 -0700543 struct camera2_shot_ext * request_shot;
544 nsecs_t timeStamp;
Sungjoong Kangad378612012-08-17 12:34:33 -0700545 int i;
Sungjoong Kang9dd63e12012-07-24 00:25:51 +0900546
Sungjoong Kangad378612012-08-17 12:34:33 -0700547 ALOGV("DEBUG(%s): frameCnt(%d)", __FUNCTION__, shot_ext->shot.ctl.request.frameCount);
Sungjoong Kang9dd63e12012-07-24 00:25:51 +0900548
Sungjoong Kangad378612012-08-17 12:34:33 -0700549 for (i = 0 ; i < NUM_MAX_REQUEST_MGR_ENTRY ; i++) {
550 if((entries[i].internal_shot.shot.ctl.request.frameCount == shot_ext->shot.ctl.request.frameCount)
551 && (entries[i].status == CAPTURED))
552 break;
553 }
554
555 if (i == NUM_MAX_REQUEST_MGR_ENTRY){
556 ALOGE("[%s] no entry found(framecount:%d)", __FUNCTION__, shot_ext->shot.ctl.request.frameCount);
Sungjoong Kang9dd63e12012-07-24 00:25:51 +0900557 return;
558 }
559
Sungjoong Kangad378612012-08-17 12:34:33 -0700560 request_manager_entry * newEntry = &(entries[i]);
Sungjoong Kangb56dcc02012-08-08 13:38:09 -0700561 request_shot = &(newEntry->internal_shot);
Sungjoong Kang9dd63e12012-07-24 00:25:51 +0900562
Sungjoong Kangbe494d12012-08-04 15:36:56 -0700563 newEntry->dynamic_meta_vaild = true;
Sungjoong Kangb56dcc02012-08-08 13:38:09 -0700564 timeStamp = request_shot->shot.dm.sensor.timeStamp;
Sungjoong Kangad378612012-08-17 12:34:33 -0700565 memcpy(&(request_shot->shot.dm), &(shot_ext->shot.dm), sizeof(struct camera2_dm));
Sungjoong Kangb56dcc02012-08-08 13:38:09 -0700566 request_shot->shot.dm.sensor.timeStamp = timeStamp;
Sungjoong Kangad378612012-08-17 12:34:33 -0700567 CheckCompleted(i);
Sungjoong Kang13d8c7b2012-07-14 10:20:39 +0900568}
569
570void RequestManager::DumpInfoWithIndex(int index)
571{
Sungjoong Kangbe494d12012-08-04 15:36:56 -0700572 struct camera2_shot_ext * currMetadata = &(entries[index].internal_shot);
Sungjoong Kang13d8c7b2012-07-14 10:20:39 +0900573
574 ALOGV("#### frameCount(%d) exposureTime(%lld) ISO(%d)",
Sungjoong Kangbe494d12012-08-04 15:36:56 -0700575 currMetadata->shot.ctl.request.frameCount,
576 currMetadata->shot.ctl.sensor.exposureTime,
577 currMetadata->shot.ctl.sensor.sensitivity);
Sungjoong Kangb56dcc02012-08-08 13:38:09 -0700578 if (currMetadata->shot.ctl.request.outputStreams[15] == 0)
Sungjoong Kang13d8c7b2012-07-14 10:20:39 +0900579 ALOGV("#### No output stream selected");
Sungjoong Kangb56dcc02012-08-08 13:38:09 -0700580 else if (currMetadata->shot.ctl.request.outputStreams[15] == 1)
Sungjoong Kangbe494d12012-08-04 15:36:56 -0700581 ALOGV("#### OutputStreamId : %d", currMetadata->shot.ctl.request.outputStreams[0]);
Sungjoong Kangb56dcc02012-08-08 13:38:09 -0700582 else if (currMetadata->shot.ctl.request.outputStreams[15] == 2)
Sungjoong Kangbe494d12012-08-04 15:36:56 -0700583 ALOGV("#### OutputStreamId : %d, %d", currMetadata->shot.ctl.request.outputStreams[0],
584 currMetadata->shot.ctl.request.outputStreams[1]);
Sungjoong Kang13d8c7b2012-07-14 10:20:39 +0900585 else
Sungjoong Kangb56dcc02012-08-08 13:38:09 -0700586 ALOGV("#### OutputStream num (%d) abnormal ", currMetadata->shot.ctl.request.outputStreams[15]);
Sungjoong Kang13d8c7b2012-07-14 10:20:39 +0900587}
588
Sungjoong Kangef6f83c2012-08-28 22:59:48 +0900589void RequestManager::UpdateIspParameters(struct camera2_shot_ext *shot_ext, int frameCnt)
Sungjoong Kang13d8c7b2012-07-14 10:20:39 +0900590{
Sungjoong Kang9dd63e12012-07-24 00:25:51 +0900591 int index, targetStreamIndex;
Sungjoong Kangb56dcc02012-08-08 13:38:09 -0700592 struct camera2_shot_ext * request_shot;
Sungjoong Kang9dd63e12012-07-24 00:25:51 +0900593
594 ALOGV("DEBUG(%s): updating info with frameCnt(%d)", __FUNCTION__, frameCnt);
595 if (frameCnt < 0)
Sungjoong Kang13d8c7b2012-07-14 10:20:39 +0900596 return;
Sungjoong Kang9dd63e12012-07-24 00:25:51 +0900597
598 index = FindEntryIndexByFrameCnt(frameCnt);
599 if (index == -1) {
600 ALOGE("ERR(%s): Cannot find entry for frameCnt(%d)", __FUNCTION__, frameCnt);
601 return;
602 }
603
Sungjoong Kang13d8c7b2012-07-14 10:20:39 +0900604 request_manager_entry * newEntry = &(entries[index]);
Sungjoong Kangad378612012-08-17 12:34:33 -0700605 request_shot = &(newEntry->internal_shot);
Sungjoong Kang2bdec062012-08-17 15:47:56 -0700606 memcpy(&(shot_ext->shot.ctl), &(request_shot->shot.ctl), sizeof(struct camera2_ctl));
Sungjoong Kang13d8c7b2012-07-14 10:20:39 +0900607 shot_ext->request_sensor = 1;
Sungjoong Kangad378612012-08-17 12:34:33 -0700608 shot_ext->dis_bypass = 1;
609 shot_ext->dnr_bypass = 1;
610 shot_ext->fd_bypass = 1;
611 shot_ext->setfile = 0;
612
Sungjoong Kang13d8c7b2012-07-14 10:20:39 +0900613 shot_ext->request_scc = 0;
614 shot_ext->request_scp = 0;
Sungjoong Kangad378612012-08-17 12:34:33 -0700615
Sungjoong Kang9dd63e12012-07-24 00:25:51 +0900616 shot_ext->shot.ctl.request.outputStreams[0] = 0;
617 shot_ext->shot.ctl.request.outputStreams[1] = 0;
618 shot_ext->shot.ctl.request.outputStreams[2] = 0;
619
Sungjoong Kang2bdec062012-08-17 15:47:56 -0700620 if (m_lastAaMode == request_shot->shot.ctl.aa.mode) {
621 shot_ext->shot.ctl.aa.mode = (enum aa_mode)(0);
622 }
623 else {
624 shot_ext->shot.ctl.aa.mode = request_shot->shot.ctl.aa.mode;
625 m_lastAaMode = (int)(shot_ext->shot.ctl.aa.mode);
626 }
627 if (m_lastAeMode == request_shot->shot.ctl.aa.aeMode) {
628 shot_ext->shot.ctl.aa.aeMode = (enum aa_aemode)(0);
629 }
630 else {
631 shot_ext->shot.ctl.aa.aeMode = request_shot->shot.ctl.aa.aeMode;
632 m_lastAeMode = (int)(shot_ext->shot.ctl.aa.aeMode);
633 }
634 if (m_lastAwbMode == request_shot->shot.ctl.aa.awbMode) {
635 shot_ext->shot.ctl.aa.awbMode = (enum aa_awbmode)(0);
636 }
637 else {
638 shot_ext->shot.ctl.aa.awbMode = request_shot->shot.ctl.aa.awbMode;
639 m_lastAwbMode = (int)(shot_ext->shot.ctl.aa.awbMode);
640 }
641 if (m_lastAeComp == request_shot->shot.ctl.aa.aeExpCompensation) {
642 shot_ext->shot.ctl.aa.aeExpCompensation = 0;
643 }
644 else {
645 shot_ext->shot.ctl.aa.aeExpCompensation = request_shot->shot.ctl.aa.aeExpCompensation;
646 m_lastAeComp = (int)(shot_ext->shot.ctl.aa.aeExpCompensation);
647 }
Sungjoong Kangef6f83c2012-08-28 22:59:48 +0900648
649 shot_ext->shot.ctl.aa.afTrigger = 0;
650
Sungjoong Kang13d8c7b2012-07-14 10:20:39 +0900651 for (int i = 0; i < newEntry->output_stream_count; i++) {
Sungjoong Kangad378612012-08-17 12:34:33 -0700652 targetStreamIndex = newEntry->internal_shot.shot.ctl.request.outputStreams[i];
Sungjoong Kang13d8c7b2012-07-14 10:20:39 +0900653
654 if (targetStreamIndex==0) {
Sungjoong Kangad378612012-08-17 12:34:33 -0700655 ALOGV("DEBUG(%s): outputstreams(%d) is for scalerP", __FUNCTION__, i);
Sungjoong Kang13d8c7b2012-07-14 10:20:39 +0900656 shot_ext->request_scp = 1;
Sungjoong Kangfd2d78a2012-08-26 17:44:25 -0700657 if (shot_ext->shot.ctl.stats.faceDetectMode != FACEDETECT_MODE_OFF)
658 shot_ext->fd_bypass = 0;
Sungjoong Kang13d8c7b2012-07-14 10:20:39 +0900659 }
Sungjoong Kang9dd63e12012-07-24 00:25:51 +0900660 else if (targetStreamIndex == 1) {
Sungjoong Kangad378612012-08-17 12:34:33 -0700661 ALOGV("DEBUG(%s): outputstreams(%d) is for scalerC", __FUNCTION__, i);
Sungjoong Kang13d8c7b2012-07-14 10:20:39 +0900662 shot_ext->request_scc = 1;
Sungjoong Kangfd2d78a2012-08-26 17:44:25 -0700663 if (shot_ext->shot.ctl.stats.faceDetectMode != FACEDETECT_MODE_OFF)
664 shot_ext->fd_bypass = 0;
Sungjoong Kang9dd63e12012-07-24 00:25:51 +0900665 }
666 else if (targetStreamIndex == 2) {
Sungjoong Kangad378612012-08-17 12:34:33 -0700667 ALOGV("DEBUG(%s): outputstreams(%d) is for scalerP (record)", __FUNCTION__, i);
Sungjoong Kang9dd63e12012-07-24 00:25:51 +0900668 shot_ext->request_scp = 1;
669 shot_ext->shot.ctl.request.outputStreams[2] = 1;
Sungjoong Kang2bdec062012-08-17 15:47:56 -0700670 shot_ext->shot.ctl.aa.aeTargetFpsRange[0] = 30;
671 shot_ext->shot.ctl.aa.aeTargetFpsRange[1] = 30;
Sungjoong Kangfd2d78a2012-08-26 17:44:25 -0700672 if (shot_ext->shot.ctl.stats.faceDetectMode != FACEDETECT_MODE_OFF)
673 shot_ext->fd_bypass = 0;
Sungjoong Kang13d8c7b2012-07-14 10:20:39 +0900674 }
675 else {
Sungjoong Kangad378612012-08-17 12:34:33 -0700676 ALOGV("DEBUG(%s): outputstreams(%d) has abnormal value(%d)", __FUNCTION__, i, targetStreamIndex);
Sungjoong Kang13d8c7b2012-07-14 10:20:39 +0900677 }
678 }
Sungjoong Kang2bdec062012-08-17 15:47:56 -0700679 ALOGV("(%s): applied aa(%d) aemode(%d) expComp(%d), awb(%d) afmode(%d), ", __FUNCTION__,
680 (int)(shot_ext->shot.ctl.aa.mode), (int)(shot_ext->shot.ctl.aa.aeMode),
681 (int)(shot_ext->shot.ctl.aa.aeExpCompensation), (int)(shot_ext->shot.ctl.aa.awbMode),
682 (int)(shot_ext->shot.ctl.aa.afMode));
Sungjoong Kang13d8c7b2012-07-14 10:20:39 +0900683}
684
Sungjoong Kang9dd63e12012-07-24 00:25:51 +0900685int RequestManager::FindEntryIndexByFrameCnt(int frameCnt)
Sungjoong Kang13d8c7b2012-07-14 10:20:39 +0900686{
Sungjoong Kang9dd63e12012-07-24 00:25:51 +0900687 for (int i = 0 ; i < NUM_MAX_REQUEST_MGR_ENTRY ; i++) {
Sungjoong Kangbe494d12012-08-04 15:36:56 -0700688 if (entries[i].internal_shot.shot.ctl.request.frameCount == frameCnt)
Sungjoong Kang9dd63e12012-07-24 00:25:51 +0900689 return i;
690 }
691 return -1;
Sungjoong Kang13d8c7b2012-07-14 10:20:39 +0900692}
693
Sungjoong Kang9dd63e12012-07-24 00:25:51 +0900694void RequestManager::RegisterTimestamp(int frameCnt, nsecs_t * frameTime)
Sungjoong Kang13d8c7b2012-07-14 10:20:39 +0900695{
Sungjoong Kang9dd63e12012-07-24 00:25:51 +0900696 int index = FindEntryIndexByFrameCnt(frameCnt);
697 if (index == -1) {
698 ALOGE("ERR(%s): Cannot find entry for frameCnt(%d)", __FUNCTION__, frameCnt);
699 return;
700 }
701
702 request_manager_entry * currentEntry = &(entries[index]);
Sungjoong Kangbe494d12012-08-04 15:36:56 -0700703 currentEntry->internal_shot.shot.dm.sensor.timeStamp = *((uint64_t*)frameTime);
Sungjoong Kang9dd63e12012-07-24 00:25:51 +0900704 ALOGV("DEBUG(%s): applied timestamp for reqIndex(%d) frameCnt(%d) (%lld)", __FUNCTION__,
Sungjoong Kangbe494d12012-08-04 15:36:56 -0700705 index, frameCnt, currentEntry->internal_shot.shot.dm.sensor.timeStamp);
Sungjoong Kang9dd63e12012-07-24 00:25:51 +0900706}
707
Sungjoong Kangad378612012-08-17 12:34:33 -0700708uint64_t RequestManager::GetTimestamp(int index)
Sungjoong Kang9dd63e12012-07-24 00:25:51 +0900709{
Sungjoong Kangeed7ed12012-08-23 16:35:08 -0700710 if (index < 0 || index >= NUM_MAX_REQUEST_MGR_ENTRY) {
711 ALOGE("ERR(%s): Request entry outside of bounds (%d)", __FUNCTION__, index);
Sungjoong Kang9dd63e12012-07-24 00:25:51 +0900712 return 0;
713 }
714
Sungjoong Kang13d8c7b2012-07-14 10:20:39 +0900715 request_manager_entry * currentEntry = &(entries[index]);
Sungjoong Kangbe494d12012-08-04 15:36:56 -0700716 uint64_t frameTime = currentEntry->internal_shot.shot.dm.sensor.timeStamp;
Sungjoong Kang9dd63e12012-07-24 00:25:51 +0900717 ALOGV("DEBUG(%s): Returning timestamp for reqIndex(%d) (%lld)", __FUNCTION__, index, frameTime);
Sungjoong Kang13d8c7b2012-07-14 10:20:39 +0900718 return frameTime;
719}
720
Sungjoong Kang9dd63e12012-07-24 00:25:51 +0900721int RequestManager::FindFrameCnt(struct camera2_shot_ext * shot_ext)
722{
Sungjoong Kangad378612012-08-17 12:34:33 -0700723 int i;
724
Sungjoong Kangbe494d12012-08-04 15:36:56 -0700725 if (m_numOfEntries == 0) {
Sungjoong Kangad378612012-08-17 12:34:33 -0700726 ALOGV("(%s): No Entry found", __FUNCTION__);
Sungjoong Kangbe494d12012-08-04 15:36:56 -0700727 return -1;
728 }
Sungjoong Kangad378612012-08-17 12:34:33 -0700729
Sungjoong Kangbe494d12012-08-04 15:36:56 -0700730 for (i = 0 ; i < NUM_MAX_REQUEST_MGR_ENTRY ; i++) {
Sungjoong Kangad378612012-08-17 12:34:33 -0700731 if(entries[i].internal_shot.shot.ctl.request.frameCount != shot_ext->shot.ctl.request.frameCount)
Sungjoong Kangbe494d12012-08-04 15:36:56 -0700732 continue;
Sungjoong Kangad378612012-08-17 12:34:33 -0700733
734 if (entries[i].status == REQUESTED) {
735 entries[i].status = CAPTURED;
736 return entries[i].internal_shot.shot.ctl.request.frameCount;
Sungjoong Kangbe494d12012-08-04 15:36:56 -0700737 }
Sungjoong Kangad378612012-08-17 12:34:33 -0700738
Sungjoong Kangbe494d12012-08-04 15:36:56 -0700739 }
Sungjoong Kangad378612012-08-17 12:34:33 -0700740
741 ALOGD("(%s): No Entry found", __FUNCTION__);
742
Sungjoong Kangbe494d12012-08-04 15:36:56 -0700743 return -1;
Sungjoong Kang9dd63e12012-07-24 00:25:51 +0900744}
Sungjoong Kang13d8c7b2012-07-14 10:20:39 +0900745
Sungjoong Kangb5237e62012-07-27 07:39:05 -0700746void RequestManager::SetInitialSkip(int count)
747{
748 ALOGV("(%s): Pipeline Restarting. setting cnt(%d) - current(%d)", __FUNCTION__, count, m_sensorPipelineSkipCnt);
749 if (count > m_sensorPipelineSkipCnt)
750 m_sensorPipelineSkipCnt = count;
751}
752
Sungjoong Kangad378612012-08-17 12:34:33 -0700753int RequestManager::GetSkipCnt()
754{
755 ALOGV("(%s): skip cnt(%d)", __FUNCTION__, m_sensorPipelineSkipCnt);
756 if (m_sensorPipelineSkipCnt == 0)
757 return m_sensorPipelineSkipCnt;
758 else
759 return --m_sensorPipelineSkipCnt;
760}
761
Sungjoong Kang13d8c7b2012-07-14 10:20:39 +0900762void RequestManager::Dump(void)
763{
Sungjoong Kang13d8c7b2012-07-14 10:20:39 +0900764 int i = 0;
765 request_manager_entry * currentEntry;
Sungjoong Kangad378612012-08-17 12:34:33 -0700766 ALOGD("## Dump totalentry(%d), insert(%d), processing(%d), frame(%d)",
Sungjoong Kang13d8c7b2012-07-14 10:20:39 +0900767 m_numOfEntries,m_entryInsertionIndex,m_entryProcessingIndex, m_entryFrameOutputIndex);
768
769 for (i = 0 ; i < NUM_MAX_REQUEST_MGR_ENTRY ; i++) {
770 currentEntry = &(entries[i]);
Sungjoong Kangad378612012-08-17 12:34:33 -0700771 ALOGD("[%2d] status[%d] frameCnt[%3d] numOutput[%d] outstream[0]-%d outstream[1]-%d", i,
Sungjoong Kangbe494d12012-08-04 15:36:56 -0700772 currentEntry->status, currentEntry->internal_shot.shot.ctl.request.frameCount,
Sungjoong Kangad378612012-08-17 12:34:33 -0700773 currentEntry->output_stream_count,
774 currentEntry->internal_shot.shot.ctl.request.outputStreams[0],
775 currentEntry->internal_shot.shot.ctl.request.outputStreams[1]);
Sungjoong Kang13d8c7b2012-07-14 10:20:39 +0900776 }
777}
778
Sungjoong Kang9dd63e12012-07-24 00:25:51 +0900779int RequestManager::GetNextIndex(int index)
780{
781 index++;
782 if (index >= NUM_MAX_REQUEST_MGR_ENTRY)
783 index = 0;
784
785 return index;
786}
787
Sungjoong Kang6044e502012-08-27 00:29:28 -0700788ExynosCameraHWInterface2::ExynosCameraHWInterface2(int cameraId, camera2_device_t *dev, ExynosCamera2 * camera, int *openInvalid):
Jiyoung Shinc15a6b02012-06-05 01:08:14 -0700789 m_requestQueueOps(NULL),
790 m_frameQueueOps(NULL),
791 m_callbackCookie(NULL),
792 m_numOfRemainingReqInSvc(0),
793 m_isRequestQueuePending(false),
Sungjoong Kang13d8c7b2012-07-14 10:20:39 +0900794 m_isRequestQueueNull(true),
Jiyoung Shinc15a6b02012-06-05 01:08:14 -0700795 m_isSensorThreadOn(false),
Sungjoong Kang13d8c7b2012-07-14 10:20:39 +0900796 m_isSensorStarted(false),
Sungjoong Kangad378612012-08-17 12:34:33 -0700797 m_isIspStarted(false),
Sungjoong Kang13d8c7b2012-07-14 10:20:39 +0900798 m_ionCameraClient(0),
799 m_initFlag1(false),
800 m_initFlag2(false),
Sungjoong Kang13d8c7b2012-07-14 10:20:39 +0900801 m_scp_flushing(false),
802 m_closing(false),
Sungjoong Kang9dd63e12012-07-24 00:25:51 +0900803 m_recordingEnabled(false),
804 m_needsRecordBufferInit(false),
805 lastFrameCnt(-1),
806 m_scp_closing(false),
807 m_scp_closed(false),
Sungjoong Kang0f26b202012-08-17 15:43:12 -0700808 m_afState(HAL_AFSTATE_INACTIVE),
809 m_afMode(NO_CHANGE),
810 m_afMode2(NO_CHANGE),
811 m_IsAfModeUpdateRequired(false),
812 m_IsAfTriggerRequired(false),
813 m_IsAfLockRequired(false),
Sungjoong Kang15fd8232012-08-23 16:16:44 -0700814 m_wideAspect(false),
Sungjoong Kang0f26b202012-08-17 15:43:12 -0700815 m_afTriggerId(0),
Sungjoong Kang8e2c2fd2012-08-27 00:02:22 -0700816 m_afPendingTriggerId(0),
817 m_afModeWaitingCnt(0),
Sungjoong Kang9dd63e12012-07-24 00:25:51 +0900818 m_halDevice(dev),
Sungjoong Kangad378612012-08-17 12:34:33 -0700819 m_need_streamoff(0),
Sungjoong Kangbe494d12012-08-04 15:36:56 -0700820 m_cameraId(cameraId)
Jiyoung Shinc15a6b02012-06-05 01:08:14 -0700821{
Sungjoong Kang13d8c7b2012-07-14 10:20:39 +0900822 ALOGV("DEBUG(%s):", __FUNCTION__);
Jiyoung Shinc15a6b02012-06-05 01:08:14 -0700823 int ret = 0;
Sungjoong Kang6044e502012-08-27 00:29:28 -0700824 int res = 0;
Jiyoung Shinc15a6b02012-06-05 01:08:14 -0700825
Sungjoong Kang13d8c7b2012-07-14 10:20:39 +0900826 m_exynosPictureCSC = NULL;
Sungjoong Kang9dd63e12012-07-24 00:25:51 +0900827 m_exynosVideoCSC = NULL;
Sungjoong Kang13d8c7b2012-07-14 10:20:39 +0900828
Jiyoung Shinc15a6b02012-06-05 01:08:14 -0700829 if (!m_grallocHal) {
830 ret = hw_get_module(GRALLOC_HARDWARE_MODULE_ID, (const hw_module_t **)&m_grallocHal);
831 if (ret)
Sungjoong Kang13d8c7b2012-07-14 10:20:39 +0900832 ALOGE("ERR(%s):Fail on loading gralloc HAL", __FUNCTION__);
833 }
Jiyoung Shinc15a6b02012-06-05 01:08:14 -0700834
Sungjoong Kangdaa1fcd2012-08-08 11:49:43 -0700835 m_camera2 = camera;
Jiyoung Shinc15a6b02012-06-05 01:08:14 -0700836 m_ionCameraClient = createIonClient(m_ionCameraClient);
837 if(m_ionCameraClient == 0)
Sungjoong Kang13d8c7b2012-07-14 10:20:39 +0900838 ALOGE("ERR(%s):Fail on ion_client_create", __FUNCTION__);
Jiyoung Shinc15a6b02012-06-05 01:08:14 -0700839
Sungjoong Kang9dd63e12012-07-24 00:25:51 +0900840
841 m_BayerManager = new BayerBufManager();
Jiyoung Shinc15a6b02012-06-05 01:08:14 -0700842 m_mainThread = new MainThread(this);
Sungjoong Kang6044e502012-08-27 00:29:28 -0700843 *openInvalid = InitializeISPChain();
844 if (*openInvalid < 0) {
845 // clean process
846 // 1. close video nodes
847 // SCP
848 res = exynos_v4l2_close(m_fd_scp);
849 if (res != NO_ERROR ) {
850 ALOGE("ERR(%s): exynos_v4l2_close failed(%d)",__FUNCTION__ , res);
851 }
852 // SCC
853 res = exynos_v4l2_close(m_camera_info.capture.fd);
854 if (res != NO_ERROR ) {
855 ALOGE("ERR(%s): exynos_v4l2_close failed(%d)",__FUNCTION__ , res);
856 }
857 // Sensor
858 res = exynos_v4l2_close(m_camera_info.sensor.fd);
859 if (res != NO_ERROR ) {
860 ALOGE("ERR(%s): exynos_v4l2_close failed(%d)",__FUNCTION__ , res);
861 }
862 // ISP
863 res = exynos_v4l2_close(m_camera_info.isp.fd);
864 if (res != NO_ERROR ) {
865 ALOGE("ERR(%s): exynos_v4l2_close failed(%d)",__FUNCTION__ , res);
866 }
867 } else {
868 m_sensorThread = new SensorThread(this);
869 m_mainThread->Start("MainThread", PRIORITY_DEFAULT, 0);
870 ALOGV("DEBUG(%s): created sensorthread ################", __FUNCTION__);
871 m_requestManager = new RequestManager((SignalDrivenThread*)(m_mainThread.get()));
872 CSC_METHOD cscMethod = CSC_METHOD_HW;
873 m_exynosPictureCSC = csc_init(cscMethod);
874 if (m_exynosPictureCSC == NULL)
875 ALOGE("ERR(%s): csc_init() fail", __FUNCTION__);
876 csc_set_hw_property(m_exynosPictureCSC, CSC_HW_PROPERTY_FIXED_NODE, PICTURE_GSC_NODE_NUM);
Jiyoung Shinc15a6b02012-06-05 01:08:14 -0700877
Sungjoong Kang6044e502012-08-27 00:29:28 -0700878 m_exynosVideoCSC = csc_init(cscMethod);
879 if (m_exynosVideoCSC == NULL)
880 ALOGE("ERR(%s): csc_init() fail", __FUNCTION__);
881 csc_set_hw_property(m_exynosVideoCSC, CSC_HW_PROPERTY_FIXED_NODE, VIDEO_GSC_NODE_NUM);
Sungjoong Kang13d8c7b2012-07-14 10:20:39 +0900882
Sungjoong Kang6044e502012-08-27 00:29:28 -0700883 ALOGV("DEBUG(%s): END", __FUNCTION__);
884 m_setExifFixedAttribute();
885 }
Jiyoung Shinc15a6b02012-06-05 01:08:14 -0700886}
887
888ExynosCameraHWInterface2::~ExynosCameraHWInterface2()
889{
Sungjoong Kangad378612012-08-17 12:34:33 -0700890 ALOGV("%s: ENTER", __FUNCTION__);
Jiyoung Shinc15a6b02012-06-05 01:08:14 -0700891 this->release();
Sungjoong Kangad378612012-08-17 12:34:33 -0700892 ALOGV("%s: EXIT", __FUNCTION__);
Jiyoung Shinc15a6b02012-06-05 01:08:14 -0700893}
894
895void ExynosCameraHWInterface2::release()
896{
Sungjoong Kang13d8c7b2012-07-14 10:20:39 +0900897 int i, res;
Sungjoong Kang9dd63e12012-07-24 00:25:51 +0900898 ALOGD("%s: ENTER", __func__);
Sungjoong Kang13d8c7b2012-07-14 10:20:39 +0900899 m_closing = true;
Sungjoong Kang9dd63e12012-07-24 00:25:51 +0900900
Sungjoong Kangad378612012-08-17 12:34:33 -0700901 if (m_streamThreads[1] != NULL) {
902 m_streamThreads[1]->release();
903 m_streamThreads[1]->SetSignal(SIGNAL_THREAD_TERMINATE);
904 }
905
906 if (m_streamThreads[0] != NULL) {
907 m_streamThreads[0]->release();
908 m_streamThreads[0]->SetSignal(SIGNAL_THREAD_TERMINATE);
909 }
910
Sungjoong Kang13d8c7b2012-07-14 10:20:39 +0900911 if (m_ispThread != NULL) {
912 m_ispThread->release();
Sungjoong Kang13d8c7b2012-07-14 10:20:39 +0900913 }
914
915 if (m_sensorThread != NULL) {
916 m_sensorThread->release();
Sungjoong Kang13d8c7b2012-07-14 10:20:39 +0900917 }
Jiyoung Shinc15a6b02012-06-05 01:08:14 -0700918
919 if (m_mainThread != NULL) {
Sungjoong Kang13d8c7b2012-07-14 10:20:39 +0900920 m_mainThread->release();
Jiyoung Shinc15a6b02012-06-05 01:08:14 -0700921 }
Jiyoung Shinc15a6b02012-06-05 01:08:14 -0700922
Sungjoong Kang13d8c7b2012-07-14 10:20:39 +0900923 if (m_exynosPictureCSC)
924 csc_deinit(m_exynosPictureCSC);
925 m_exynosPictureCSC = NULL;
926
Sungjoong Kang9dd63e12012-07-24 00:25:51 +0900927 if (m_exynosVideoCSC)
928 csc_deinit(m_exynosVideoCSC);
929 m_exynosVideoCSC = NULL;
930
Sungjoong Kang15fd8232012-08-23 16:16:44 -0700931
Sungjoong Kangad378612012-08-17 12:34:33 -0700932 if (m_streamThreads[1] != NULL) {
933 while (!m_streamThreads[1]->IsTerminated())
934 {
935 ALOGD("Waiting for ISP thread is tetminated");
936 usleep(100000);
937 }
938 m_streamThreads[1] = NULL;
939 }
940
941 if (m_streamThreads[0] != NULL) {
942 while (!m_streamThreads[0]->IsTerminated())
943 {
944 ALOGD("Waiting for sensor thread is tetminated");
945 usleep(100000);
946 }
947 m_streamThreads[0] = NULL;
948 }
949
Sungjoong Kang9dd63e12012-07-24 00:25:51 +0900950 if (m_ispThread != NULL) {
951 while (!m_ispThread->IsTerminated())
Sungjoong Kangad378612012-08-17 12:34:33 -0700952 {
953 ALOGD("Waiting for isp thread is tetminated");
954 usleep(100000);
955 }
Sungjoong Kang9dd63e12012-07-24 00:25:51 +0900956 m_ispThread = NULL;
957 }
958
959 if (m_sensorThread != NULL) {
960 while (!m_sensorThread->IsTerminated())
Sungjoong Kangad378612012-08-17 12:34:33 -0700961 {
962 ALOGD("Waiting for sensor thread is tetminated");
963 usleep(100000);
964 }
Sungjoong Kang9dd63e12012-07-24 00:25:51 +0900965 m_sensorThread = NULL;
966 }
967
Sungjoong Kangad378612012-08-17 12:34:33 -0700968 if (m_mainThread != NULL) {
Sungjoong Kang9dd63e12012-07-24 00:25:51 +0900969 while (!m_mainThread->IsTerminated())
Sungjoong Kangad378612012-08-17 12:34:33 -0700970 {
971 ALOGD("Waiting for main thread is tetminated");
972 usleep(100000);
973 }
Sungjoong Kang9dd63e12012-07-24 00:25:51 +0900974 m_mainThread = NULL;
975 }
976
Sungjoong Kang15fd8232012-08-23 16:16:44 -0700977 if (m_requestManager != NULL) {
978 delete m_requestManager;
979 m_requestManager = NULL;
980 }
981
982 if (m_BayerManager != NULL) {
983 delete m_BayerManager;
984 m_BayerManager = NULL;
985 }
986// for(i = 0; i < m_camera_info.sensor.buffers; i++)
987 for (i = 0; i < NUM_BAYER_BUFFERS; i++)
Jiyoung Shinc15a6b02012-06-05 01:08:14 -0700988 freeCameraMemory(&m_camera_info.sensor.buffer[i], m_camera_info.sensor.planes);
989
Jiyoung Shinc15a6b02012-06-05 01:08:14 -0700990 for(i = 0; i < m_camera_info.capture.buffers; i++)
991 freeCameraMemory(&m_camera_info.capture.buffer[i], m_camera_info.capture.planes);
992
Sungjoong Kang9dd63e12012-07-24 00:25:51 +0900993 ALOGV("DEBUG(%s): calling exynos_v4l2_close - sensor", __FUNCTION__);
Sungjoong Kang13d8c7b2012-07-14 10:20:39 +0900994 res = exynos_v4l2_close(m_camera_info.sensor.fd);
995 if (res != NO_ERROR ) {
Sungjoong Kang9dd63e12012-07-24 00:25:51 +0900996 ALOGE("ERR(%s): exynos_v4l2_close failed(%d)",__FUNCTION__ , res);
Sungjoong Kang13d8c7b2012-07-14 10:20:39 +0900997 }
998
Sungjoong Kang9dd63e12012-07-24 00:25:51 +0900999 ALOGV("DEBUG(%s): calling exynos_v4l2_close - isp", __FUNCTION__);
Sungjoong Kang13d8c7b2012-07-14 10:20:39 +09001000 res = exynos_v4l2_close(m_camera_info.isp.fd);
1001 if (res != NO_ERROR ) {
Sungjoong Kang9dd63e12012-07-24 00:25:51 +09001002 ALOGE("ERR(%s): exynos_v4l2_close failed(%d)",__FUNCTION__ , res);
Sungjoong Kang13d8c7b2012-07-14 10:20:39 +09001003 }
1004
Sungjoong Kang9dd63e12012-07-24 00:25:51 +09001005 ALOGV("DEBUG(%s): calling exynos_v4l2_close - capture", __FUNCTION__);
Sungjoong Kang13d8c7b2012-07-14 10:20:39 +09001006 res = exynos_v4l2_close(m_camera_info.capture.fd);
1007 if (res != NO_ERROR ) {
Sungjoong Kang9dd63e12012-07-24 00:25:51 +09001008 ALOGE("ERR(%s): exynos_v4l2_close failed(%d)",__FUNCTION__ , res);
Sungjoong Kang13d8c7b2012-07-14 10:20:39 +09001009 }
1010
Sungjoong Kang9dd63e12012-07-24 00:25:51 +09001011 ALOGV("DEBUG(%s): calling exynos_v4l2_close - scp", __FUNCTION__);
Sungjoong Kangad378612012-08-17 12:34:33 -07001012 res = exynos_v4l2_close(m_fd_scp);
Sungjoong Kang13d8c7b2012-07-14 10:20:39 +09001013 if (res != NO_ERROR ) {
Sungjoong Kang9dd63e12012-07-24 00:25:51 +09001014 ALOGE("ERR(%s): exynos_v4l2_close failed(%d)",__FUNCTION__ , res);
Sungjoong Kang13d8c7b2012-07-14 10:20:39 +09001015 }
Sungjoong Kang9dd63e12012-07-24 00:25:51 +09001016 ALOGV("DEBUG(%s): calling deleteIonClient", __FUNCTION__);
Jiyoung Shinc15a6b02012-06-05 01:08:14 -07001017 deleteIonClient(m_ionCameraClient);
Sungjoong Kangad378612012-08-17 12:34:33 -07001018
1019 ALOGV("%s: EXIT", __func__);
1020}
1021
Sungjoong Kang6044e502012-08-27 00:29:28 -07001022int ExynosCameraHWInterface2::InitializeISPChain()
Sungjoong Kangad378612012-08-17 12:34:33 -07001023{
1024 char node_name[30];
1025 int fd = 0;
1026 int i;
Sungjoong Kang6044e502012-08-27 00:29:28 -07001027 int ret = 0;
Sungjoong Kangad378612012-08-17 12:34:33 -07001028
1029 /* Open Sensor */
1030 memset(&node_name, 0x00, sizeof(char[30]));
1031 sprintf(node_name, "%s%d", NODE_PREFIX, 40);
1032 fd = exynos_v4l2_open(node_name, O_RDWR, 0);
1033
1034 if (fd < 0) {
1035 ALOGE("ERR(%s): failed to open sensor video node (%s) fd (%d)", __FUNCTION__,node_name, fd);
1036 }
1037 else {
1038 ALOGV("DEBUG(%s): sensor video node opened(%s) fd (%d)", __FUNCTION__,node_name, fd);
1039 }
1040 m_camera_info.sensor.fd = fd;
1041
1042 /* Open ISP */
1043 memset(&node_name, 0x00, sizeof(char[30]));
1044 sprintf(node_name, "%s%d", NODE_PREFIX, 41);
1045 fd = exynos_v4l2_open(node_name, O_RDWR, 0);
1046
1047 if (fd < 0) {
1048 ALOGE("ERR(%s): failed to open isp video node (%s) fd (%d)", __FUNCTION__,node_name, fd);
1049 }
1050 else {
1051 ALOGV("DEBUG(%s): isp video node opened(%s) fd (%d)", __FUNCTION__,node_name, fd);
1052 }
1053 m_camera_info.isp.fd = fd;
1054
1055 /* Open ScalerC */
1056 memset(&node_name, 0x00, sizeof(char[30]));
1057 sprintf(node_name, "%s%d", NODE_PREFIX, 42);
1058 fd = exynos_v4l2_open(node_name, O_RDWR, 0);
1059
1060 if (fd < 0) {
1061 ALOGE("ERR(%s): failed to open capture video node (%s) fd (%d)", __FUNCTION__,node_name, fd);
1062 }
1063 else {
1064 ALOGV("DEBUG(%s): capture video node opened(%s) fd (%d)", __FUNCTION__,node_name, fd);
1065 }
1066 m_camera_info.capture.fd = fd;
1067
1068 /* Open ScalerP */
1069 memset(&node_name, 0x00, sizeof(char[30]));
1070 sprintf(node_name, "%s%d", NODE_PREFIX, 44);
1071 fd = exynos_v4l2_open(node_name, O_RDWR, 0);
1072 if (fd < 0) {
1073 ALOGE("DEBUG(%s): failed to open preview video node (%s) fd (%d)", __FUNCTION__,node_name, fd);
1074 }
1075 else {
1076 ALOGV("DEBUG(%s): preview video node opened(%s) fd (%d)", __FUNCTION__,node_name, fd);
1077 }
1078 m_fd_scp = fd;
1079
1080 if(m_cameraId == 0)
1081 m_camera_info.sensor_id = SENSOR_NAME_S5K4E5;
1082 else
1083 m_camera_info.sensor_id = SENSOR_NAME_S5K6A3;
1084
1085 memset(&m_camera_info.dummy_shot, 0x00, sizeof(struct camera2_shot_ext));
1086 m_camera_info.dummy_shot.shot.ctl.request.metadataMode = METADATA_MODE_FULL;
1087 m_camera_info.dummy_shot.shot.magicNumber = 0x23456789;
1088
1089 m_camera_info.dummy_shot.dis_bypass = 1;
1090 m_camera_info.dummy_shot.dnr_bypass = 1;
1091 m_camera_info.dummy_shot.fd_bypass = 1;
1092
1093 /*sensor setting*/
1094 m_camera_info.dummy_shot.shot.ctl.sensor.exposureTime = 0;
1095 m_camera_info.dummy_shot.shot.ctl.sensor.frameDuration = 0;
1096 m_camera_info.dummy_shot.shot.ctl.sensor.sensitivity = 0;
1097
1098 m_camera_info.dummy_shot.shot.ctl.scaler.cropRegion[0] = 0;
1099 m_camera_info.dummy_shot.shot.ctl.scaler.cropRegion[1] = 0;
1100
1101 /*request setting*/
1102 m_camera_info.dummy_shot.request_sensor = 1;
1103 m_camera_info.dummy_shot.request_scc = 0;
1104 m_camera_info.dummy_shot.request_scp = 0;
1105 m_camera_info.dummy_shot.shot.ctl.request.outputStreams[0] = 0;
1106 m_camera_info.dummy_shot.shot.ctl.request.outputStreams[1] = 0;
1107 m_camera_info.dummy_shot.shot.ctl.request.outputStreams[2] = 0;
1108
1109 m_camera_info.sensor.width = m_camera2->getSensorRawW();
1110 m_camera_info.sensor.height = m_camera2->getSensorRawH();
1111
1112 m_camera_info.sensor.format = V4L2_PIX_FMT_SBGGR16;
1113 m_camera_info.sensor.planes = 2;
1114 m_camera_info.sensor.buffers = NUM_BAYER_BUFFERS;
1115 m_camera_info.sensor.type = V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE;
1116 m_camera_info.sensor.memory = V4L2_MEMORY_DMABUF;
1117 m_camera_info.sensor.ionClient = m_ionCameraClient;
1118
1119 for(i = 0; i < m_camera_info.sensor.buffers; i++){
1120 initCameraMemory(&m_camera_info.sensor.buffer[i], m_camera_info.sensor.planes);
1121 m_camera_info.sensor.buffer[i].size.extS[0] = m_camera_info.sensor.width*m_camera_info.sensor.height*2;
1122 m_camera_info.sensor.buffer[i].size.extS[1] = 8*1024; // HACK, driver use 8*1024, should be use predefined value
1123 allocCameraMemory(m_camera_info.sensor.ionClient, &m_camera_info.sensor.buffer[i], m_camera_info.sensor.planes);
1124 }
1125
1126 m_camera_info.isp.width = m_camera_info.sensor.width;
1127 m_camera_info.isp.height = m_camera_info.sensor.height;
1128 m_camera_info.isp.format = m_camera_info.sensor.format;
1129 m_camera_info.isp.planes = m_camera_info.sensor.planes;
1130 m_camera_info.isp.buffers = m_camera_info.sensor.buffers;
1131 m_camera_info.isp.type = V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE;
1132 m_camera_info.isp.memory = V4L2_MEMORY_DMABUF;
1133 m_camera_info.isp.ionClient = m_ionCameraClient;
1134
1135 for(i = 0; i < m_camera_info.isp.buffers; i++){
1136 initCameraMemory(&m_camera_info.isp.buffer[i], m_camera_info.isp.planes);
1137 m_camera_info.isp.buffer[i].size.extS[0] = m_camera_info.sensor.buffer[i].size.extS[0];
1138 m_camera_info.isp.buffer[i].size.extS[1] = m_camera_info.sensor.buffer[i].size.extS[1];
1139 m_camera_info.isp.buffer[i].fd.extFd[0] = m_camera_info.sensor.buffer[i].fd.extFd[0];
1140 m_camera_info.isp.buffer[i].fd.extFd[1] = m_camera_info.sensor.buffer[i].fd.extFd[1];
1141 m_camera_info.isp.buffer[i].virt.extP[0] = m_camera_info.sensor.buffer[i].virt.extP[0];
1142 m_camera_info.isp.buffer[i].virt.extP[1] = m_camera_info.sensor.buffer[i].virt.extP[1];
1143 };
1144
1145 /* init ISP */
Sungjoong Kang6044e502012-08-27 00:29:28 -07001146 ret = cam_int_s_input(&(m_camera_info.isp), m_camera_info.sensor_id);
1147 if (ret < 0) {
1148 ALOGE("ERR(%s): cam_int_s_input(%d) failed!!!! ", __FUNCTION__, m_camera_info.sensor_id);
1149 return false;
1150 }
Sungjoong Kangad378612012-08-17 12:34:33 -07001151 cam_int_s_fmt(&(m_camera_info.isp));
1152 ALOGV("DEBUG(%s): isp calling reqbuf", __FUNCTION__);
1153 cam_int_reqbufs(&(m_camera_info.isp));
1154 ALOGV("DEBUG(%s): isp calling querybuf", __FUNCTION__);
1155 ALOGV("DEBUG(%s): isp mem alloc done", __FUNCTION__);
1156
1157 /* init Sensor */
1158 cam_int_s_input(&(m_camera_info.sensor), m_camera_info.sensor_id);
1159 ALOGV("DEBUG(%s): sensor s_input done", __FUNCTION__);
1160 if (cam_int_s_fmt(&(m_camera_info.sensor))< 0) {
1161 ALOGE("ERR(%s): sensor s_fmt fail", __FUNCTION__);
1162 }
1163 ALOGV("DEBUG(%s): sensor s_fmt done", __FUNCTION__);
1164 cam_int_reqbufs(&(m_camera_info.sensor));
1165 ALOGV("DEBUG(%s): sensor reqbuf done", __FUNCTION__);
1166 for (i = 0; i < m_camera_info.sensor.buffers; i++) {
1167 ALOGV("DEBUG(%s): sensor initial QBUF [%d]", __FUNCTION__, i);
1168 memcpy( m_camera_info.sensor.buffer[i].virt.extP[1], &(m_camera_info.dummy_shot),
1169 sizeof(struct camera2_shot_ext));
1170 m_camera_info.dummy_shot.shot.ctl.sensor.frameDuration = 33*1000*1000; // apply from frame #1
1171 m_camera_info.dummy_shot.shot.ctl.request.frameCount = -1;
1172 cam_int_qbuf(&(m_camera_info.sensor), i);
1173 }
1174 ALOGV("== stream_on :: .sensor");
1175 cam_int_streamon(&(m_camera_info.sensor));
1176
1177 /* init Capture */
1178 m_camera_info.capture.width = m_camera2->getSensorW();
1179 m_camera_info.capture.height = m_camera2->getSensorH();
1180 m_camera_info.capture.format = V4L2_PIX_FMT_YUYV;
1181 m_camera_info.capture.planes = 1;
1182 m_camera_info.capture.buffers = 8;
1183 m_camera_info.capture.type = V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE;
1184 m_camera_info.capture.memory = V4L2_MEMORY_DMABUF;
1185 m_camera_info.capture.ionClient = m_ionCameraClient;
1186
1187 for(i = 0; i < m_camera_info.capture.buffers; i++){
1188 initCameraMemory(&m_camera_info.capture.buffer[i], m_camera_info.capture.planes);
1189 m_camera_info.capture.buffer[i].size.extS[0] = m_camera_info.capture.width*m_camera_info.capture.height*2;
1190 allocCameraMemory(m_camera_info.capture.ionClient, &m_camera_info.capture.buffer[i], m_camera_info.capture.planes);
1191 }
1192
1193 cam_int_s_input(&(m_camera_info.capture), m_camera_info.sensor_id);
1194 cam_int_s_fmt(&(m_camera_info.capture));
1195 ALOGV("DEBUG(%s): capture calling reqbuf", __FUNCTION__);
1196 cam_int_reqbufs(&(m_camera_info.capture));
1197 ALOGV("DEBUG(%s): capture calling querybuf", __FUNCTION__);
1198
1199 for (i = 0; i < m_camera_info.capture.buffers; i++) {
1200 ALOGV("DEBUG(%s): capture initial QBUF [%d]", __FUNCTION__, i);
1201 cam_int_qbuf(&(m_camera_info.capture), i);
1202 }
1203
1204 ALOGV("== stream_on :: capture");
Sungjoong Kang15fd8232012-08-23 16:16:44 -07001205 if (cam_int_streamon(&(m_camera_info.capture)) < 0) {
1206 ALOGE("ERR(%s): capture stream on fail", __FUNCTION__);
1207 } else {
1208 m_camera_info.capture.status = true;
1209 }
Sungjoong Kang6044e502012-08-27 00:29:28 -07001210
1211 return true;
Sungjoong Kangad378612012-08-17 12:34:33 -07001212}
1213
1214void ExynosCameraHWInterface2::StartISP()
1215{
Sungjoong Kangad378612012-08-17 12:34:33 -07001216 ALOGV("== stream_on :: isp");
1217 cam_int_streamon(&(m_camera_info.isp));
Sungjoong Kangad378612012-08-17 12:34:33 -07001218 exynos_v4l2_s_ctrl(m_camera_info.sensor.fd, V4L2_CID_IS_S_STREAM, IS_ENABLE_STREAM);
Sungjoong Kang13d8c7b2012-07-14 10:20:39 +09001219}
1220
Jiyoung Shinc15a6b02012-06-05 01:08:14 -07001221int ExynosCameraHWInterface2::getCameraId() const
1222{
Sungjoong Kang9dd63e12012-07-24 00:25:51 +09001223 return m_cameraId;
Jiyoung Shinc15a6b02012-06-05 01:08:14 -07001224}
Jiyoung Shinc15a6b02012-06-05 01:08:14 -07001225
1226int ExynosCameraHWInterface2::setRequestQueueSrcOps(const camera2_request_queue_src_ops_t *request_src_ops)
1227{
Sungjoong Kang13d8c7b2012-07-14 10:20:39 +09001228 ALOGV("DEBUG(%s):", __FUNCTION__);
Jiyoung Shinc15a6b02012-06-05 01:08:14 -07001229 if ((NULL != request_src_ops) && (NULL != request_src_ops->dequeue_request)
1230 && (NULL != request_src_ops->free_request) && (NULL != request_src_ops->request_count)) {
1231 m_requestQueueOps = (camera2_request_queue_src_ops_t*)request_src_ops;
1232 return 0;
1233 }
1234 else {
Sungjoong Kang13d8c7b2012-07-14 10:20:39 +09001235 ALOGE("DEBUG(%s):setRequestQueueSrcOps : NULL arguments", __FUNCTION__);
Jiyoung Shinc15a6b02012-06-05 01:08:14 -07001236 return 1;
1237 }
1238}
1239
1240int ExynosCameraHWInterface2::notifyRequestQueueNotEmpty()
1241{
Sungjoong Kangb5237e62012-07-27 07:39:05 -07001242 ALOGV("DEBUG(%s):setting [SIGNAL_MAIN_REQ_Q_NOT_EMPTY] current(%d)", __FUNCTION__, m_requestManager->GetNumEntries());
Jiyoung Shinc15a6b02012-06-05 01:08:14 -07001243 if ((NULL==m_frameQueueOps)|| (NULL==m_requestQueueOps)) {
Sungjoong Kang13d8c7b2012-07-14 10:20:39 +09001244 ALOGE("DEBUG(%s):queue ops NULL. ignoring request", __FUNCTION__);
Jiyoung Shinc15a6b02012-06-05 01:08:14 -07001245 return 0;
1246 }
Sungjoong Kang13d8c7b2012-07-14 10:20:39 +09001247 m_isRequestQueueNull = false;
Sungjoong Kang0f26b202012-08-17 15:43:12 -07001248 if (m_requestManager->GetNumEntries() == 0)
1249 m_requestManager->SetInitialSkip(5);
Jiyoung Shinc15a6b02012-06-05 01:08:14 -07001250 m_mainThread->SetSignal(SIGNAL_MAIN_REQ_Q_NOT_EMPTY);
1251 return 0;
1252}
1253
1254int ExynosCameraHWInterface2::setFrameQueueDstOps(const camera2_frame_queue_dst_ops_t *frame_dst_ops)
1255{
Sungjoong Kang13d8c7b2012-07-14 10:20:39 +09001256 ALOGV("DEBUG(%s):", __FUNCTION__);
Jiyoung Shinc15a6b02012-06-05 01:08:14 -07001257 if ((NULL != frame_dst_ops) && (NULL != frame_dst_ops->dequeue_frame)
1258 && (NULL != frame_dst_ops->cancel_frame) && (NULL !=frame_dst_ops->enqueue_frame)) {
1259 m_frameQueueOps = (camera2_frame_queue_dst_ops_t *)frame_dst_ops;
1260 return 0;
1261 }
1262 else {
Sungjoong Kang13d8c7b2012-07-14 10:20:39 +09001263 ALOGE("DEBUG(%s):setFrameQueueDstOps : NULL arguments", __FUNCTION__);
Jiyoung Shinc15a6b02012-06-05 01:08:14 -07001264 return 1;
1265 }
1266}
1267
1268int ExynosCameraHWInterface2::getInProgressCount()
1269{
1270 int inProgressCount = m_requestManager->GetNumEntries();
Sungjoong Kang13d8c7b2012-07-14 10:20:39 +09001271 ALOGV("DEBUG(%s): # of dequeued req (%d)", __FUNCTION__, inProgressCount);
Jiyoung Shinc15a6b02012-06-05 01:08:14 -07001272 return inProgressCount;
1273}
1274
1275int ExynosCameraHWInterface2::flushCapturesInProgress()
1276{
1277 return 0;
1278}
1279
Jiyoung Shinc15a6b02012-06-05 01:08:14 -07001280int ExynosCameraHWInterface2::constructDefaultRequest(int request_template, camera_metadata_t **request)
1281{
Sungjoong Kang13d8c7b2012-07-14 10:20:39 +09001282 ALOGV("DEBUG(%s): making template (%d) ", __FUNCTION__, request_template);
Jiyoung Shinc15a6b02012-06-05 01:08:14 -07001283
1284 if (request == NULL) return BAD_VALUE;
1285 if (request_template < 0 || request_template >= CAMERA2_TEMPLATE_COUNT) {
1286 return BAD_VALUE;
1287 }
1288 status_t res;
1289 // Pass 1, calculate size and allocate
Sungjoong Kangdaa1fcd2012-08-08 11:49:43 -07001290 res = m_camera2->constructDefaultRequest(request_template,
Jiyoung Shinc15a6b02012-06-05 01:08:14 -07001291 request,
1292 true);
1293 if (res != OK) {
1294 return res;
1295 }
1296 // Pass 2, build request
Sungjoong Kangdaa1fcd2012-08-08 11:49:43 -07001297 res = m_camera2->constructDefaultRequest(request_template,
Jiyoung Shinc15a6b02012-06-05 01:08:14 -07001298 request,
1299 false);
1300 if (res != OK) {
1301 ALOGE("Unable to populate new request for template %d",
1302 request_template);
1303 }
1304
1305 return res;
1306}
1307
1308int ExynosCameraHWInterface2::allocateStream(uint32_t width, uint32_t height, int format, const camera2_stream_ops_t *stream_ops,
1309 uint32_t *stream_id, uint32_t *format_actual, uint32_t *usage, uint32_t *max_buffers)
1310{
Sungjoong Kangad378612012-08-17 12:34:33 -07001311 ALOGV("DEBUG(%s): allocate stream width(%d) height(%d) format(%x)", __FUNCTION__, width, height, format);
Jiyoung Shinc15a6b02012-06-05 01:08:14 -07001312 char node_name[30];
Sungjoong Kang9dd63e12012-07-24 00:25:51 +09001313 int fd = 0, allocCase = 0;
Sungjoong Kang13d8c7b2012-07-14 10:20:39 +09001314 StreamThread *AllocatedStream;
1315 stream_parameters_t newParameters;
Jiyoung Shinc15a6b02012-06-05 01:08:14 -07001316
Sungjoong Kangdaa1fcd2012-08-08 11:49:43 -07001317 if (format == CAMERA2_HAL_PIXEL_FORMAT_OPAQUE &&
1318 m_camera2->isSupportedResolution(width, height)) {
Sungjoong Kang9dd63e12012-07-24 00:25:51 +09001319 if (!(m_streamThreads[0].get())) {
1320 ALOGV("DEBUG(%s): stream 0 not exist", __FUNCTION__);
1321 allocCase = 0;
Jiyoung Shinc15a6b02012-06-05 01:08:14 -07001322 }
Sungjoong Kang13d8c7b2012-07-14 10:20:39 +09001323 else {
Alex Ray6bbb5932012-07-27 17:19:48 -07001324 if ((m_streamThreads[0].get())->m_activated == true) {
Sungjoong Kang9dd63e12012-07-24 00:25:51 +09001325 ALOGV("DEBUG(%s): stream 0 exists and activated.", __FUNCTION__);
1326 allocCase = 1;
1327 }
1328 else {
1329 ALOGV("DEBUG(%s): stream 0 exists and deactivated.", __FUNCTION__);
1330 allocCase = 2;
1331 }
Sungjoong Kang13d8c7b2012-07-14 10:20:39 +09001332 }
Sungjoong Kang15fd8232012-08-23 16:16:44 -07001333 if ((width == 1920 && height == 1080) || (width == 1280 && height == 720)) {
1334 m_wideAspect = true;
1335 }
1336 else {
1337 m_wideAspect = false;
1338 }
1339 ALOGV("DEBUG(%s): m_wideAspect (%d)", __FUNCTION__, m_wideAspect);
1340
Sungjoong Kang9dd63e12012-07-24 00:25:51 +09001341 if (allocCase == 0 || allocCase == 2) {
1342 *stream_id = 0;
Jiyoung Shinc15a6b02012-06-05 01:08:14 -07001343
Sungjoong Kang9dd63e12012-07-24 00:25:51 +09001344 if (allocCase == 0) {
1345 m_streamThreads[0] = new StreamThread(this, *stream_id);
Sungjoong Kang9dd63e12012-07-24 00:25:51 +09001346 }
1347 AllocatedStream = (StreamThread*)(m_streamThreads[0].get());
Sungjoong Kangb5237e62012-07-27 07:39:05 -07001348 m_scp_flushing = false;
1349 m_scp_closing = false;
1350 m_scp_closed = false;
Sungjoong Kang9dd63e12012-07-24 00:25:51 +09001351 usleep(100000); // TODO : guarantee the codes below will be run after readyToRunInternal()
Jiyoung Shinc15a6b02012-06-05 01:08:14 -07001352
Rebecca Schultz Zavinc853be72012-08-23 00:03:05 -07001353 *format_actual = HAL_PIXEL_FORMAT_EXYNOS_YV12;
Alex Ray6bbb5932012-07-27 17:19:48 -07001354 *usage = GRALLOC_USAGE_SW_WRITE_OFTEN;
Sungjoong Kang9dd63e12012-07-24 00:25:51 +09001355 *max_buffers = 8;
Jiyoung Shinc15a6b02012-06-05 01:08:14 -07001356
Sungjoong Kang37e122d2012-08-08 11:13:48 -07001357 newParameters.streamType = STREAM_TYPE_DIRECT;
Sungjoong Kang9dd63e12012-07-24 00:25:51 +09001358 newParameters.outputWidth = width;
1359 newParameters.outputHeight = height;
1360 newParameters.nodeWidth = width;
1361 newParameters.nodeHeight = height;
1362 newParameters.outputFormat = *format_actual;
1363 newParameters.nodeFormat = HAL_PIXEL_FORMAT_2_V4L2_PIX(*format_actual);
1364 newParameters.streamOps = stream_ops;
1365 newParameters.usage = *usage;
Sungjoong Kangbe494d12012-08-04 15:36:56 -07001366 newParameters.numHwBuffers = 8;
1367 newParameters.numOwnSvcBuffers = *max_buffers;
Sungjoong Kang9dd63e12012-07-24 00:25:51 +09001368 newParameters.fd = m_fd_scp;
1369 newParameters.nodePlanes = 3;
1370 newParameters.svcPlanes = 3;
1371 newParameters.halBuftype = V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE;
1372 newParameters.memory = V4L2_MEMORY_DMABUF;
1373 newParameters.ionClient = m_ionCameraClient;
Sungjoong Kangbe494d12012-08-04 15:36:56 -07001374 newParameters.numSvcBufsInHal = 0;
Sungjoong Kang9dd63e12012-07-24 00:25:51 +09001375 AllocatedStream->m_index = *stream_id;
1376 AllocatedStream->setParameter(&newParameters);
1377 AllocatedStream->m_activated = true;
Sungjoong Kang13d8c7b2012-07-14 10:20:39 +09001378
Sungjoong Kang9dd63e12012-07-24 00:25:51 +09001379 m_scp_flushing = false;
1380 m_scp_closing = false;
1381 m_scp_closed = false;
Sungjoong Kangad378612012-08-17 12:34:33 -07001382 m_requestManager->SetDefaultParameters(m_camera2->getSensorW());
1383 m_camera_info.dummy_shot.shot.ctl.scaler.cropRegion[2] = m_camera2->getSensorW();
Sungjoong Kang9dd63e12012-07-24 00:25:51 +09001384 return 0;
1385 }
1386 else if (allocCase == 1) {
1387 record_parameters_t recordParameters;
1388 StreamThread *parentStream;
1389 parentStream = (StreamThread*)(m_streamThreads[0].get());
1390 if (!parentStream) {
1391 return 1;
1392 // TODO
1393 }
1394 *stream_id = 2;
1395 usleep(100000); // TODO : guarantee the codes below will be run after readyToRunInternal()
1396
Sungjoong Kang804236a2012-08-05 10:36:19 -07001397 *format_actual = HAL_PIXEL_FORMAT_YCbCr_420_SP; // NV12M
Alex Ray6bbb5932012-07-27 17:19:48 -07001398 *usage = GRALLOC_USAGE_SW_WRITE_OFTEN;
James Dong26306792012-08-24 14:42:26 -07001399 *max_buffers = 6;
Sungjoong Kang9dd63e12012-07-24 00:25:51 +09001400
1401 recordParameters.outputWidth = width;
1402 recordParameters.outputHeight = height;
1403 recordParameters.outputFormat = *format_actual;
Sungjoong Kang804236a2012-08-05 10:36:19 -07001404 recordParameters.svcPlanes = NUM_PLANES(*format_actual);
Sungjoong Kang9dd63e12012-07-24 00:25:51 +09001405 recordParameters.streamOps = stream_ops;
1406 recordParameters.usage = *usage;
Sungjoong Kangbe494d12012-08-04 15:36:56 -07001407 recordParameters.numOwnSvcBuffers = *max_buffers;
1408 recordParameters.numSvcBufsInHal = 0;
Sungjoong Kang9dd63e12012-07-24 00:25:51 +09001409
1410 parentStream->setRecordingParameter(&recordParameters);
1411 m_scp_flushing = false;
1412 m_scp_closing = false;
1413 m_scp_closed = false;
1414 m_recordingEnabled = true;
1415 return 0;
1416 }
Sungjoong Kang13d8c7b2012-07-14 10:20:39 +09001417 }
Sungjoong Kangad378612012-08-17 12:34:33 -07001418 else if (format == HAL_PIXEL_FORMAT_BLOB
Sungjoong Kangdaa1fcd2012-08-08 11:49:43 -07001419 && m_camera2->isSupportedJpegResolution(width, height)) {
Sungjoong Kang13d8c7b2012-07-14 10:20:39 +09001420
1421 *stream_id = 1;
1422
Sungjoong Kang15fd8232012-08-23 16:16:44 -07001423 if (!(m_streamThreads[*stream_id].get())) {
Sungjoong Kang8e2c2fd2012-08-27 00:02:22 -07001424 ALOGV("DEBUG(%s): stream 1 not exist", __FUNCTION__);
Sungjoong Kang15fd8232012-08-23 16:16:44 -07001425 m_streamThreads[1] = new StreamThread(this, *stream_id);
1426 allocCase = 0;
1427 }
1428 else {
1429 if ((m_streamThreads[*stream_id].get())->m_activated == true) {
Sungjoong Kang8e2c2fd2012-08-27 00:02:22 -07001430 ALOGV("DEBUG(%s): stream 1 exists and activated.", __FUNCTION__);
Sungjoong Kang15fd8232012-08-23 16:16:44 -07001431 allocCase = 1;
1432 }
1433 else {
Sungjoong Kang8e2c2fd2012-08-27 00:02:22 -07001434 ALOGV("DEBUG(%s): stream 1 exists and deactivated.", __FUNCTION__);
Sungjoong Kang15fd8232012-08-23 16:16:44 -07001435 allocCase = 2;
1436 }
1437 }
1438
1439 AllocatedStream = (StreamThread*)(m_streamThreads[*stream_id].get());
Sungjoong Kang9dd63e12012-07-24 00:25:51 +09001440
Sungjoong Kang13d8c7b2012-07-14 10:20:39 +09001441 fd = m_camera_info.capture.fd;
1442 usleep(100000); // TODO : guarantee the codes below will be run after readyToRunInternal()
1443
1444 *format_actual = HAL_PIXEL_FORMAT_BLOB;
1445
1446 *usage = GRALLOC_USAGE_SW_WRITE_OFTEN;
Sungjoong Kang37e122d2012-08-08 11:13:48 -07001447 *max_buffers = 4;
Sungjoong Kang13d8c7b2012-07-14 10:20:39 +09001448
Sungjoong Kang37e122d2012-08-08 11:13:48 -07001449 newParameters.streamType = STREAM_TYPE_INDIRECT;
Sungjoong Kang13d8c7b2012-07-14 10:20:39 +09001450 newParameters.outputWidth = width;
1451 newParameters.outputHeight = height;
Sungjoong Kang9dd63e12012-07-24 00:25:51 +09001452
Sungjoong Kangdaa1fcd2012-08-08 11:49:43 -07001453 newParameters.nodeWidth = m_camera2->getSensorW();
1454 newParameters.nodeHeight = m_camera2->getSensorH();
Sungjoong Kang9dd63e12012-07-24 00:25:51 +09001455
Sungjoong Kang13d8c7b2012-07-14 10:20:39 +09001456 newParameters.outputFormat = *format_actual;
1457 newParameters.nodeFormat = V4L2_PIX_FMT_YUYV;
1458 newParameters.streamOps = stream_ops;
1459 newParameters.usage = *usage;
Sungjoong Kangbe494d12012-08-04 15:36:56 -07001460 newParameters.numHwBuffers = 8;
1461 newParameters.numOwnSvcBuffers = *max_buffers;
Sungjoong Kang13d8c7b2012-07-14 10:20:39 +09001462 newParameters.fd = fd;
1463 newParameters.nodePlanes = 1;
1464 newParameters.svcPlanes = 1;
1465 newParameters.halBuftype = V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE;
1466 newParameters.memory = V4L2_MEMORY_DMABUF;
1467 newParameters.ionClient = m_ionCameraClient;
Sungjoong Kangbe494d12012-08-04 15:36:56 -07001468 newParameters.numSvcBufsInHal = 0;
Sungjoong Kang9dd63e12012-07-24 00:25:51 +09001469 AllocatedStream->m_index = *stream_id;
Sungjoong Kang13d8c7b2012-07-14 10:20:39 +09001470 AllocatedStream->setParameter(&newParameters);
1471 return 0;
1472 }
1473 ALOGE("DEBUG(%s): Unsupported Pixel Format", __FUNCTION__);
1474 return 1; // TODO : check proper error code
1475}
1476
1477int ExynosCameraHWInterface2::registerStreamBuffers(uint32_t stream_id,
1478 int num_buffers, buffer_handle_t *registeringBuffers)
1479{
1480 int i,j;
1481 void *virtAddr[3];
1482 uint32_t plane_index = 0;
1483 stream_parameters_t *targetStreamParms;
Sungjoong Kang9dd63e12012-07-24 00:25:51 +09001484 record_parameters_t *targetRecordParms;
Sungjoong Kang13d8c7b2012-07-14 10:20:39 +09001485 node_info_t *currentNode;
1486
1487 struct v4l2_buffer v4l2_buf;
1488 struct v4l2_plane planes[VIDEO_MAX_PLANES];
1489
1490 ALOGV("DEBUG(%s): streamID (%d), num_buff(%d), handle(%x) ", __FUNCTION__,
1491 stream_id, num_buffers, (uint32_t)registeringBuffers);
1492
1493 if (stream_id == 0) {
1494 targetStreamParms = &(m_streamThreads[0]->m_parameters);
1495 }
1496 else if (stream_id == 1) {
1497 targetStreamParms = &(m_streamThreads[1]->m_parameters);
Sungjoong Kang15fd8232012-08-23 16:16:44 -07001498 // TODO : make clear stream off case
1499 m_need_streamoff = 0;
1500
1501 if (m_camera_info.capture.status == false) {
1502 /* capture */
1503 m_camera_info.capture.buffers = 8;
1504 cam_int_s_fmt(&(m_camera_info.capture));
1505 cam_int_reqbufs(&(m_camera_info.capture));
1506 for (i = 0; i < m_camera_info.capture.buffers; i++) {
1507 ALOGV("DEBUG(%s): capture initial QBUF [%d]", __FUNCTION__, i);
1508 cam_int_qbuf(&(m_camera_info.capture), i);
1509 }
1510
1511 if (cam_int_streamon(&(m_camera_info.capture)) < 0) {
1512 ALOGE("ERR(%s): capture stream on fail", __FUNCTION__);
1513 } else {
1514 m_camera_info.capture.status = true;
1515 }
1516 }
Sungjoong Kang13d8c7b2012-07-14 10:20:39 +09001517 }
Sungjoong Kang9dd63e12012-07-24 00:25:51 +09001518 else if (stream_id == 2) {
Sungjoong Kang15fd8232012-08-23 16:16:44 -07001519 m_need_streamoff = 0;
Sungjoong Kang9dd63e12012-07-24 00:25:51 +09001520 targetRecordParms = &(m_streamThreads[0]->m_recordParameters);
1521
1522 targetRecordParms->numSvcBuffers = num_buffers;
1523
1524 for (i = 0 ; i<targetRecordParms->numSvcBuffers ; i++) {
1525 ALOGV("DEBUG(%s): registering Stream Buffers[%d] (%x) ", __FUNCTION__,
1526 i, (uint32_t)(registeringBuffers[i]));
1527 if (m_grallocHal) {
1528 if (m_grallocHal->lock(m_grallocHal, registeringBuffers[i],
1529 targetRecordParms->usage, 0, 0,
1530 targetRecordParms->outputWidth, targetRecordParms->outputHeight, virtAddr) != 0) {
1531 ALOGE("ERR(%s): could not obtain gralloc buffer", __FUNCTION__);
1532 }
1533 else {
1534 ExynosBuffer currentBuf;
1535 const private_handle_t *priv_handle = reinterpret_cast<const private_handle_t *>(registeringBuffers[i]);
Sungjoong Kang9dd63e12012-07-24 00:25:51 +09001536 currentBuf.fd.extFd[0] = priv_handle->fd;
Alex Ray6bbb5932012-07-27 17:19:48 -07001537 currentBuf.fd.extFd[1] = priv_handle->fd1;
1538 currentBuf.fd.extFd[2] = priv_handle->fd2;
Sungjoong Kang9dd63e12012-07-24 00:25:51 +09001539 for (plane_index=0 ; plane_index < targetRecordParms->svcPlanes ; plane_index++) {
1540 currentBuf.virt.extP[plane_index] = (char *)virtAddr[plane_index];
1541 ALOGV("DEBUG(%s): plane(%d): fd(%d) addr(%x)",
Sungjoong Kang804236a2012-08-05 10:36:19 -07001542 __FUNCTION__, plane_index, currentBuf.fd.extFd[plane_index],
Sungjoong Kang9dd63e12012-07-24 00:25:51 +09001543 (unsigned int)currentBuf.virt.extP[plane_index]);
1544 }
1545 targetRecordParms->svcBufStatus[i] = ON_SERVICE;
Sungjoong Kangb5237e62012-07-27 07:39:05 -07001546 targetRecordParms->svcBuffers[i] = currentBuf;
1547 targetRecordParms->svcBufHandle[i] = registeringBuffers[i];
Sungjoong Kang9dd63e12012-07-24 00:25:51 +09001548 }
1549 }
1550 }
1551 m_needsRecordBufferInit = true;
1552 return 0;
1553 }
Sungjoong Kang13d8c7b2012-07-14 10:20:39 +09001554 else {
1555 ALOGE("ERR(%s) unregisterd stream id (%d)", __FUNCTION__, stream_id);
Sungjoong Kangbe494d12012-08-04 15:36:56 -07001556 return 1;
Sungjoong Kang13d8c7b2012-07-14 10:20:39 +09001557 }
1558
Sungjoong Kang37e122d2012-08-08 11:13:48 -07001559 if (targetStreamParms->streamType == STREAM_TYPE_DIRECT) {
Sungjoong Kang13d8c7b2012-07-14 10:20:39 +09001560 if (num_buffers < targetStreamParms->numHwBuffers) {
1561 ALOGE("ERR(%s) registering insufficient num of buffers (%d) < (%d)",
1562 __FUNCTION__, num_buffers, targetStreamParms->numHwBuffers);
Sungjoong Kangbe494d12012-08-04 15:36:56 -07001563 return 1;
Sungjoong Kang13d8c7b2012-07-14 10:20:39 +09001564 }
1565 }
1566 ALOGV("DEBUG(%s): format(%x) width(%d), height(%d) svcPlanes(%d)",
1567 __FUNCTION__, targetStreamParms->outputFormat, targetStreamParms->outputWidth,
1568 targetStreamParms->outputHeight, targetStreamParms->svcPlanes);
1569
1570 targetStreamParms->numSvcBuffers = num_buffers;
1571 currentNode = &(targetStreamParms->node); // TO Remove
1572
1573 currentNode->fd = targetStreamParms->fd;
1574 currentNode->width = targetStreamParms->nodeWidth;
1575 currentNode->height = targetStreamParms->nodeHeight;
1576 currentNode->format = targetStreamParms->nodeFormat;
1577 currentNode->planes = targetStreamParms->nodePlanes;
1578 currentNode->buffers = targetStreamParms->numHwBuffers;
1579 currentNode->type = targetStreamParms->halBuftype;
1580 currentNode->memory = targetStreamParms->memory;
1581 currentNode->ionClient = targetStreamParms->ionClient;
1582
Sungjoong Kang37e122d2012-08-08 11:13:48 -07001583 if (targetStreamParms->streamType == STREAM_TYPE_DIRECT) {
Sungjoong Kangad378612012-08-17 12:34:33 -07001584 if(m_need_streamoff == 1) {
Sungjoong Kang15fd8232012-08-23 16:16:44 -07001585 if (m_sensorThread != NULL) {
1586 m_sensorThread->release();
1587 /* TODO */
1588 usleep(500000);
1589 } else {
1590 ALOGE("+++++++ sensor thread is NULL %d", __LINE__);
1591 }
1592
Sungjoong Kangad378612012-08-17 12:34:33 -07001593 ALOGV("(%s): calling capture streamoff", __FUNCTION__);
Sungjoong Kang15fd8232012-08-23 16:16:44 -07001594 if (cam_int_streamoff(&(m_camera_info.capture)) < 0) {
1595 ALOGE("ERR(%s): capture stream off fail", __FUNCTION__);
1596 } else {
1597 m_camera_info.capture.status = false;
1598 }
1599
Sungjoong Kangad378612012-08-17 12:34:33 -07001600 ALOGV("(%s): calling capture streamoff done", __FUNCTION__);
1601
1602 m_camera_info.capture.buffers = 0;
1603 ALOGV("DEBUG(%s): capture calling reqbuf 0 ", __FUNCTION__);
1604 cam_int_reqbufs(&(m_camera_info.capture));
1605 ALOGV("DEBUG(%s): capture calling reqbuf 0 done", __FUNCTION__);
1606
Sungjoong Kangad378612012-08-17 12:34:33 -07001607 m_isIspStarted = false;
1608 }
1609
Sungjoong Kangad378612012-08-17 12:34:33 -07001610 if (m_need_streamoff == 1) {
1611 m_camera_info.sensor.buffers = NUM_BAYER_BUFFERS;
1612 m_camera_info.isp.buffers = m_camera_info.sensor.buffers;
1613 m_camera_info.capture.buffers = 8;
Sungjoong Kang15fd8232012-08-23 16:16:44 -07001614 /* isp */
1615 cam_int_s_fmt(&(m_camera_info.isp));
Sungjoong Kangad378612012-08-17 12:34:33 -07001616 cam_int_reqbufs(&(m_camera_info.isp));
Sungjoong Kang15fd8232012-08-23 16:16:44 -07001617 /* sensor */
1618 cam_int_s_fmt(&(m_camera_info.sensor));
Sungjoong Kangad378612012-08-17 12:34:33 -07001619 cam_int_reqbufs(&(m_camera_info.sensor));
1620
1621 for (i = 0; i < 8; i++) {
1622 ALOGV("DEBUG(%s): sensor initial QBUF [%d]", __FUNCTION__, i);
1623 memcpy( m_camera_info.sensor.buffer[i].virt.extP[1], &(m_camera_info.dummy_shot),
1624 sizeof(struct camera2_shot_ext));
1625 m_camera_info.dummy_shot.shot.ctl.sensor.frameDuration = 33*1000*1000; // apply from frame #1
1626 m_camera_info.dummy_shot.shot.ctl.request.frameCount = -1;
1627 cam_int_qbuf(&(m_camera_info.sensor), i);
1628 }
1629
Sungjoong Kang15fd8232012-08-23 16:16:44 -07001630 /* capture */
1631 cam_int_s_fmt(&(m_camera_info.capture));
Sungjoong Kangad378612012-08-17 12:34:33 -07001632 cam_int_reqbufs(&(m_camera_info.capture));
Sungjoong Kang15fd8232012-08-23 16:16:44 -07001633 for (i = 0; i < m_camera_info.capture.buffers; i++) {
1634 ALOGV("DEBUG(%s): capture initial QBUF [%d]", __FUNCTION__, i);
1635 cam_int_qbuf(&(m_camera_info.capture), i);
1636 }
Sungjoong Kangad378612012-08-17 12:34:33 -07001637
Sungjoong Kang15fd8232012-08-23 16:16:44 -07001638 }
1639
1640 cam_int_s_input(currentNode, m_camera_info.sensor_id);
1641 cam_int_s_fmt(currentNode);
1642 cam_int_reqbufs(currentNode);
1643
Sungjoong Kang13d8c7b2012-07-14 10:20:39 +09001644 }
Sungjoong Kang37e122d2012-08-08 11:13:48 -07001645 else if (targetStreamParms->streamType == STREAM_TYPE_INDIRECT) {
Sungjoong Kang13d8c7b2012-07-14 10:20:39 +09001646 for(i = 0; i < currentNode->buffers; i++){
1647 memcpy(&(currentNode->buffer[i]), &(m_camera_info.capture.buffer[i]), sizeof(ExynosBuffer));
1648 }
1649 }
1650
1651 for (i = 0 ; i<targetStreamParms->numSvcBuffers ; i++) {
1652 ALOGV("DEBUG(%s): registering Stream Buffers[%d] (%x) ", __FUNCTION__,
1653 i, (uint32_t)(registeringBuffers[i]));
1654 if (m_grallocHal) {
1655 if (m_grallocHal->lock(m_grallocHal, registeringBuffers[i],
1656 targetStreamParms->usage, 0, 0,
1657 currentNode->width, currentNode->height, virtAddr) != 0) {
1658 ALOGE("ERR(%s): could not obtain gralloc buffer", __FUNCTION__);
1659 }
1660 else {
1661 v4l2_buf.m.planes = planes;
1662 v4l2_buf.type = currentNode->type;
1663 v4l2_buf.memory = currentNode->memory;
1664 v4l2_buf.index = i;
1665 v4l2_buf.length = currentNode->planes;
1666
1667 ExynosBuffer currentBuf;
1668 const private_handle_t *priv_handle = reinterpret_cast<const private_handle_t *>(registeringBuffers[i]);
1669
1670 m_getAlignedYUVSize(currentNode->format,
1671 currentNode->width, currentNode->height, &currentBuf);
Alex Ray24231222012-06-27 15:18:15 -07001672
Sungjoong Kang9dd63e12012-07-24 00:25:51 +09001673 v4l2_buf.m.planes[0].m.fd = priv_handle->fd;
Alex Ray6bbb5932012-07-27 17:19:48 -07001674 v4l2_buf.m.planes[2].m.fd = priv_handle->fd1;
1675 v4l2_buf.m.planes[1].m.fd = priv_handle->fd2;
Sungjoong Kang9dd63e12012-07-24 00:25:51 +09001676 currentBuf.fd.extFd[0] = priv_handle->fd;
Alex Ray6bbb5932012-07-27 17:19:48 -07001677 currentBuf.fd.extFd[2] = priv_handle->fd1;
1678 currentBuf.fd.extFd[1] = priv_handle->fd2;
Sungjoong Kang37e122d2012-08-08 11:13:48 -07001679 ALOGV("DEBUG(%s): ion_size(%d), stride(%d), ", __FUNCTION__, priv_handle->size, priv_handle->stride);
1680 if (currentNode->planes == 1) {
1681 currentBuf.size.extS[0] = priv_handle->size;
1682 currentBuf.size.extS[1] = 0;
1683 currentBuf.size.extS[2] = 0;
1684 }
Sungjoong Kangbe494d12012-08-04 15:36:56 -07001685 for (plane_index = 0 ; plane_index < v4l2_buf.length ; plane_index++) {
Sungjoong Kang13d8c7b2012-07-14 10:20:39 +09001686 currentBuf.virt.extP[plane_index] = (char *)virtAddr[plane_index];
1687 v4l2_buf.m.planes[plane_index].length = currentBuf.size.extS[plane_index];
1688 ALOGV("DEBUG(%s): plane(%d): fd(%d) addr(%x), length(%d)",
1689 __FUNCTION__, plane_index, v4l2_buf.m.planes[plane_index].m.fd,
1690 (unsigned int)currentBuf.virt.extP[plane_index],
1691 v4l2_buf.m.planes[plane_index].length);
Jiyoung Shinc15a6b02012-06-05 01:08:14 -07001692 }
Sungjoong Kang13d8c7b2012-07-14 10:20:39 +09001693
Sungjoong Kang37e122d2012-08-08 11:13:48 -07001694 if (targetStreamParms->streamType == STREAM_TYPE_DIRECT) {
Sungjoong Kang13d8c7b2012-07-14 10:20:39 +09001695 if (i < currentNode->buffers) {
1696 if (exynos_v4l2_qbuf(currentNode->fd, &v4l2_buf) < 0) {
Sungjoong Kang9dd63e12012-07-24 00:25:51 +09001697 ALOGE("ERR(%s): stream id(%d) exynos_v4l2_qbuf() fail fd(%d)",
1698 __FUNCTION__, stream_id, currentNode->fd);
1699 //return false;
Sungjoong Kang13d8c7b2012-07-14 10:20:39 +09001700 }
Sungjoong Kang9dd63e12012-07-24 00:25:51 +09001701 ALOGV("DEBUG(%s): stream id(%d) exynos_v4l2_qbuf() success fd(%d)",
1702 __FUNCTION__, stream_id, currentNode->fd);
Sungjoong Kang13d8c7b2012-07-14 10:20:39 +09001703 targetStreamParms->svcBufStatus[i] = REQUIRES_DQ_FROM_SVC;
1704 }
1705 else {
1706 targetStreamParms->svcBufStatus[i] = ON_SERVICE;
1707 }
1708 }
Sungjoong Kang37e122d2012-08-08 11:13:48 -07001709 else if (targetStreamParms->streamType == STREAM_TYPE_INDIRECT) {
Sungjoong Kang13d8c7b2012-07-14 10:20:39 +09001710 targetStreamParms->svcBufStatus[i] = ON_SERVICE;
1711 }
1712 targetStreamParms->svcBuffers[i] = currentBuf;
1713 targetStreamParms->svcBufHandle[i] = registeringBuffers[i];
1714 }
Jiyoung Shinc15a6b02012-06-05 01:08:14 -07001715 }
Jiyoung Shinc15a6b02012-06-05 01:08:14 -07001716 }
Sungjoong Kangad378612012-08-17 12:34:33 -07001717
Sungjoong Kang9dd63e12012-07-24 00:25:51 +09001718 ALOGV("DEBUG(%s): calling streamon", __FUNCTION__);
Sungjoong Kang15fd8232012-08-23 16:16:44 -07001719 if (targetStreamParms->streamType == STREAM_TYPE_DIRECT) {
Sungjoong Kangad378612012-08-17 12:34:33 -07001720 ALOGD("%s(%d), stream id = %d", __FUNCTION__, __LINE__, stream_id);
1721 cam_int_streamon(&(targetStreamParms->node));
1722 }
1723
Sungjoong Kang15fd8232012-08-23 16:16:44 -07001724 if (m_need_streamoff == 1) {
1725 if (cam_int_streamon(&(m_camera_info.capture)) < 0) {
1726 ALOGE("ERR(%s): capture stream on fail", __FUNCTION__);
1727 } else {
1728 m_camera_info.capture.status = true;
1729 }
1730
1731 cam_int_streamon(&(m_camera_info.sensor));
1732 }
1733
Sungjoong Kangad378612012-08-17 12:34:33 -07001734 ALOGV("DEBUG(%s): calling streamon END", __FUNCTION__);
Sungjoong Kang13d8c7b2012-07-14 10:20:39 +09001735 ALOGV("DEBUG(%s): END registerStreamBuffers", __FUNCTION__);
Sungjoong Kangad378612012-08-17 12:34:33 -07001736
1737 if(!m_isIspStarted) {
1738 m_isIspStarted = true;
1739 StartISP();
Sungjoong Kangad378612012-08-17 12:34:33 -07001740 }
1741
Sungjoong Kang15fd8232012-08-23 16:16:44 -07001742 if (m_need_streamoff == 1) {
1743 m_requestManager->SetInitialSkip(8);
1744 m_sensorThread->Start("SensorThread", PRIORITY_DEFAULT, 0);
1745 m_mainThread->SetSignal(SIGNAL_MAIN_REQ_Q_NOT_EMPTY);
1746 }
1747 m_need_streamoff = 1;
1748
Jiyoung Shinc15a6b02012-06-05 01:08:14 -07001749 return 0;
1750}
1751
1752int ExynosCameraHWInterface2::releaseStream(uint32_t stream_id)
1753{
Sungjoong Kang13d8c7b2012-07-14 10:20:39 +09001754 StreamThread *targetStream;
1755 ALOGV("DEBUG(%s):", __FUNCTION__);
1756
Sungjoong Kangb5237e62012-07-27 07:39:05 -07001757 if (stream_id == 0) {
Sungjoong Kang13d8c7b2012-07-14 10:20:39 +09001758 targetStream = (StreamThread*)(m_streamThreads[0].get());
Sungjoong Kang9dd63e12012-07-24 00:25:51 +09001759 m_scp_flushing = true;
Sungjoong Kang13d8c7b2012-07-14 10:20:39 +09001760 }
Sungjoong Kangb5237e62012-07-27 07:39:05 -07001761 else if (stream_id == 1) {
Sungjoong Kang13d8c7b2012-07-14 10:20:39 +09001762 targetStream = (StreamThread*)(m_streamThreads[1].get());
1763 }
Sungjoong Kangb5237e62012-07-27 07:39:05 -07001764 else if (stream_id == 2 && m_recordingEnabled) {
1765 m_recordingEnabled = false;
Sungjoong Kangad378612012-08-17 12:34:33 -07001766 m_needsRecordBufferInit = true;
Sungjoong Kangb5237e62012-07-27 07:39:05 -07001767 return 0;
1768 }
Sungjoong Kang13d8c7b2012-07-14 10:20:39 +09001769 else {
1770 ALOGE("ERR:(%s): wrong stream id (%d)", __FUNCTION__, stream_id);
Sungjoong Kangbe494d12012-08-04 15:36:56 -07001771 return 1;
Sungjoong Kang13d8c7b2012-07-14 10:20:39 +09001772 }
1773
Sungjoong Kangb5237e62012-07-27 07:39:05 -07001774 targetStream->m_releasing = true;
Sungjoong Kang15fd8232012-08-23 16:16:44 -07001775 do {
1776 ALOGD("stream thread release %d", __LINE__);
1777 targetStream->release();
1778 usleep(33000);
1779 } while (targetStream->m_releasing);
Sungjoong Kang9dd63e12012-07-24 00:25:51 +09001780 targetStream->m_activated = false;
Sungjoong Kang13d8c7b2012-07-14 10:20:39 +09001781 ALOGV("DEBUG(%s): DONE", __FUNCTION__);
Jiyoung Shinc15a6b02012-06-05 01:08:14 -07001782 return 0;
1783}
1784
1785int ExynosCameraHWInterface2::allocateReprocessStream(
Sungjoong Kang13d8c7b2012-07-14 10:20:39 +09001786 uint32_t width, uint32_t height, uint32_t format,
1787 const camera2_stream_in_ops_t *reprocess_stream_ops,
Jiyoung Shinc15a6b02012-06-05 01:08:14 -07001788 uint32_t *stream_id, uint32_t *consumer_usage, uint32_t *max_buffers)
1789{
Sungjoong Kang13d8c7b2012-07-14 10:20:39 +09001790 ALOGV("DEBUG(%s):", __FUNCTION__);
Jiyoung Shinc15a6b02012-06-05 01:08:14 -07001791 return 0;
1792}
1793
1794int ExynosCameraHWInterface2::releaseReprocessStream(uint32_t stream_id)
1795{
Sungjoong Kang13d8c7b2012-07-14 10:20:39 +09001796 ALOGV("DEBUG(%s):", __FUNCTION__);
Jiyoung Shinc15a6b02012-06-05 01:08:14 -07001797 return 0;
1798}
1799
1800int ExynosCameraHWInterface2::triggerAction(uint32_t trigger_id, int ext1, int ext2)
1801{
Sungjoong Kang0f26b202012-08-17 15:43:12 -07001802 ALOGV("DEBUG(%s): id(%x), %d, %d", __FUNCTION__, trigger_id, ext1, ext2);
1803
1804 switch (trigger_id) {
1805 case CAMERA2_TRIGGER_AUTOFOCUS:
1806 ALOGV("DEBUG(%s):TRIGGER_AUTOFOCUS id(%d)", __FUNCTION__, ext1);
Sungjoong Kang8e2c2fd2012-08-27 00:02:22 -07001807 OnAfTriggerStart(ext1);
Sungjoong Kang0f26b202012-08-17 15:43:12 -07001808 break;
1809
1810 case CAMERA2_TRIGGER_CANCEL_AUTOFOCUS:
1811 ALOGV("DEBUG(%s):CANCEL_AUTOFOCUS id(%d)", __FUNCTION__, ext1);
1812 OnAfCancel(ext1);
1813 break;
1814 default:
1815 break;
1816 }
Jiyoung Shinc15a6b02012-06-05 01:08:14 -07001817 return 0;
1818}
1819
1820int ExynosCameraHWInterface2::setNotifyCallback(camera2_notify_callback notify_cb, void *user)
1821{
Sungjoong Kang0f26b202012-08-17 15:43:12 -07001822 ALOGV("DEBUG(%s): cb_addr(%x)", __FUNCTION__, (unsigned int)notify_cb);
Jiyoung Shinc15a6b02012-06-05 01:08:14 -07001823 m_notifyCb = notify_cb;
1824 m_callbackCookie = user;
1825 return 0;
1826}
1827
1828int ExynosCameraHWInterface2::getMetadataVendorTagOps(vendor_tag_query_ops_t **ops)
1829{
Sungjoong Kang13d8c7b2012-07-14 10:20:39 +09001830 ALOGV("DEBUG(%s):", __FUNCTION__);
Jiyoung Shinc15a6b02012-06-05 01:08:14 -07001831 return 0;
1832}
1833
1834int ExynosCameraHWInterface2::dump(int fd)
1835{
Sungjoong Kang13d8c7b2012-07-14 10:20:39 +09001836 ALOGV("DEBUG(%s):", __FUNCTION__);
Jiyoung Shinc15a6b02012-06-05 01:08:14 -07001837 return 0;
1838}
1839
Sungjoong Kang13d8c7b2012-07-14 10:20:39 +09001840void ExynosCameraHWInterface2::m_getAlignedYUVSize(int colorFormat, int w, int h, ExynosBuffer *buf)
1841{
1842 switch (colorFormat) {
1843 // 1p
1844 case V4L2_PIX_FMT_RGB565 :
1845 case V4L2_PIX_FMT_YUYV :
1846 case V4L2_PIX_FMT_UYVY :
1847 case V4L2_PIX_FMT_VYUY :
1848 case V4L2_PIX_FMT_YVYU :
1849 buf->size.extS[0] = FRAME_SIZE(V4L2_PIX_2_HAL_PIXEL_FORMAT(colorFormat), w, h);
1850 buf->size.extS[1] = 0;
1851 buf->size.extS[2] = 0;
1852 break;
1853 // 2p
1854 case V4L2_PIX_FMT_NV12 :
1855 case V4L2_PIX_FMT_NV12T :
1856 case V4L2_PIX_FMT_NV21 :
1857 buf->size.extS[0] = ALIGN(w, 16) * ALIGN(h, 16);
1858 buf->size.extS[1] = ALIGN(w/2, 16) * ALIGN(h/2, 16);
1859 buf->size.extS[2] = 0;
1860 break;
1861 case V4L2_PIX_FMT_NV12M :
1862 case V4L2_PIX_FMT_NV12MT_16X16 :
Sungjoong Kang9dd63e12012-07-24 00:25:51 +09001863 case V4L2_PIX_FMT_NV21M:
Sungjoong Kang13d8c7b2012-07-14 10:20:39 +09001864 buf->size.extS[0] = ALIGN(w, 16) * ALIGN(h, 16);
1865 buf->size.extS[1] = ALIGN(buf->size.extS[0] / 2, 256);
1866 buf->size.extS[2] = 0;
1867 break;
1868 case V4L2_PIX_FMT_NV16 :
1869 case V4L2_PIX_FMT_NV61 :
1870 buf->size.extS[0] = ALIGN(w, 16) * ALIGN(h, 16);
1871 buf->size.extS[1] = ALIGN(w, 16) * ALIGN(h, 16);
1872 buf->size.extS[2] = 0;
1873 break;
1874 // 3p
1875 case V4L2_PIX_FMT_YUV420 :
1876 case V4L2_PIX_FMT_YVU420 :
1877 buf->size.extS[0] = (w * h);
1878 buf->size.extS[1] = (w * h) >> 2;
1879 buf->size.extS[2] = (w * h) >> 2;
1880 break;
1881 case V4L2_PIX_FMT_YUV420M:
1882 case V4L2_PIX_FMT_YVU420M :
1883 case V4L2_PIX_FMT_YUV422P :
1884 buf->size.extS[0] = ALIGN(w, 32) * ALIGN(h, 16);
1885 buf->size.extS[1] = ALIGN(w/2, 16) * ALIGN(h/2, 8);
1886 buf->size.extS[2] = ALIGN(w/2, 16) * ALIGN(h/2, 8);
1887 break;
1888 default:
1889 ALOGE("ERR(%s):unmatched colorFormat(%d)", __FUNCTION__, colorFormat);
1890 return;
1891 break;
1892 }
1893}
1894
1895bool ExynosCameraHWInterface2::m_getRatioSize(int src_w, int src_h,
1896 int dst_w, int dst_h,
1897 int *crop_x, int *crop_y,
1898 int *crop_w, int *crop_h,
1899 int zoom)
1900{
1901 *crop_w = src_w;
1902 *crop_h = src_h;
1903
1904 if ( src_w != dst_w
1905 || src_h != dst_h) {
1906 float src_ratio = 1.0f;
1907 float dst_ratio = 1.0f;
1908
1909 // ex : 1024 / 768
1910 src_ratio = (float)src_w / (float)src_h;
1911
1912 // ex : 352 / 288
1913 dst_ratio = (float)dst_w / (float)dst_h;
1914
1915 if (dst_w * dst_h < src_w * src_h) {
1916 if (dst_ratio <= src_ratio) {
1917 // shrink w
1918 *crop_w = src_h * dst_ratio;
1919 *crop_h = src_h;
1920 } else {
1921 // shrink h
1922 *crop_w = src_w;
1923 *crop_h = src_w / dst_ratio;
1924 }
1925 } else {
1926 if (dst_ratio <= src_ratio) {
1927 // shrink w
1928 *crop_w = src_h * dst_ratio;
1929 *crop_h = src_h;
1930 } else {
1931 // shrink h
1932 *crop_w = src_w;
1933 *crop_h = src_w / dst_ratio;
1934 }
1935 }
1936 }
1937
1938 if (zoom != 0) {
1939 float zoomLevel = ((float)zoom + 10.0) / 10.0;
1940 *crop_w = (int)((float)*crop_w / zoomLevel);
1941 *crop_h = (int)((float)*crop_h / zoomLevel);
1942 }
1943
1944 #define CAMERA_CROP_WIDTH_RESTRAIN_NUM (0x2)
1945 unsigned int w_align = (*crop_w & (CAMERA_CROP_WIDTH_RESTRAIN_NUM - 1));
1946 if (w_align != 0) {
1947 if ( (CAMERA_CROP_WIDTH_RESTRAIN_NUM >> 1) <= w_align
1948 && *crop_w + (CAMERA_CROP_WIDTH_RESTRAIN_NUM - w_align) <= dst_w) {
1949 *crop_w += (CAMERA_CROP_WIDTH_RESTRAIN_NUM - w_align);
1950 }
1951 else
1952 *crop_w -= w_align;
1953 }
1954
1955 #define CAMERA_CROP_HEIGHT_RESTRAIN_NUM (0x2)
1956 unsigned int h_align = (*crop_h & (CAMERA_CROP_HEIGHT_RESTRAIN_NUM - 1));
1957 if (h_align != 0) {
1958 if ( (CAMERA_CROP_HEIGHT_RESTRAIN_NUM >> 1) <= h_align
1959 && *crop_h + (CAMERA_CROP_HEIGHT_RESTRAIN_NUM - h_align) <= dst_h) {
1960 *crop_h += (CAMERA_CROP_HEIGHT_RESTRAIN_NUM - h_align);
1961 }
1962 else
1963 *crop_h -= h_align;
1964 }
1965
1966 *crop_x = (src_w - *crop_w) >> 1;
1967 *crop_y = (src_h - *crop_h) >> 1;
1968
1969 if (*crop_x & (CAMERA_CROP_WIDTH_RESTRAIN_NUM >> 1))
1970 *crop_x -= 1;
1971
1972 if (*crop_y & (CAMERA_CROP_HEIGHT_RESTRAIN_NUM >> 1))
1973 *crop_y -= 1;
1974
1975 return true;
1976}
1977
Sungjoong Kang9dd63e12012-07-24 00:25:51 +09001978BayerBufManager::BayerBufManager()
Sungjoong Kang13d8c7b2012-07-14 10:20:39 +09001979{
Sungjoong Kang9dd63e12012-07-24 00:25:51 +09001980 ALOGV("DEBUG(%s): ", __FUNCTION__);
1981 for (int i = 0; i < NUM_BAYER_BUFFERS ; i++) {
1982 entries[i].status = BAYER_ON_HAL_EMPTY;
1983 entries[i].reqFrameCnt = 0;
Sungjoong Kang13d8c7b2012-07-14 10:20:39 +09001984 }
Sungjoong Kang9dd63e12012-07-24 00:25:51 +09001985 sensorEnqueueHead = 0;
1986 sensorDequeueHead = 0;
1987 ispEnqueueHead = 0;
1988 ispDequeueHead = 0;
1989 numOnSensor = 0;
1990 numOnIsp = 0;
1991 numOnHalFilled = 0;
1992 numOnHalEmpty = NUM_BAYER_BUFFERS;
Sungjoong Kang13d8c7b2012-07-14 10:20:39 +09001993}
1994
Sungjoong Kang15fd8232012-08-23 16:16:44 -07001995BayerBufManager::~BayerBufManager()
1996{
1997 ALOGV("%s", __FUNCTION__);
1998}
1999
Sungjoong Kang9dd63e12012-07-24 00:25:51 +09002000int BayerBufManager::GetIndexForSensorEnqueue()
Sungjoong Kang13d8c7b2012-07-14 10:20:39 +09002001{
Sungjoong Kang9dd63e12012-07-24 00:25:51 +09002002 int ret = 0;
2003 if (numOnHalEmpty == 0)
2004 ret = -1;
2005 else
2006 ret = sensorEnqueueHead;
2007 ALOGV("DEBUG(%s): returning (%d)", __FUNCTION__, ret);
Sungjoong Kang13d8c7b2012-07-14 10:20:39 +09002008 return ret;
2009}
2010
Sungjoong Kang9dd63e12012-07-24 00:25:51 +09002011int BayerBufManager::MarkSensorEnqueue(int index)
Sungjoong Kang13d8c7b2012-07-14 10:20:39 +09002012{
Sungjoong Kang9dd63e12012-07-24 00:25:51 +09002013 ALOGV("DEBUG(%s) : BayerIndex[%d] ", __FUNCTION__, index);
2014
2015 // sanity check
2016 if (index != sensorEnqueueHead) {
2017 ALOGV("DEBUG(%s) : Abnormal BayerIndex[%d] - expected[%d]", __FUNCTION__, index, sensorEnqueueHead);
2018 return -1;
2019 }
2020 if (entries[index].status != BAYER_ON_HAL_EMPTY) {
2021 ALOGV("DEBUG(%s) : Abnormal status in BayerIndex[%d] = (%d) expected (%d)", __FUNCTION__,
2022 index, entries[index].status, BAYER_ON_HAL_EMPTY);
Sungjoong Kang13d8c7b2012-07-14 10:20:39 +09002023 return -1;
2024 }
2025
Sungjoong Kang9dd63e12012-07-24 00:25:51 +09002026 entries[index].status = BAYER_ON_SENSOR;
2027 entries[index].reqFrameCnt = 0;
2028 numOnHalEmpty--;
2029 numOnSensor++;
2030 sensorEnqueueHead = GetNextIndex(index);
2031 ALOGV("DEBUG(%s) END: HAL-e(%d) HAL-f(%d) Sensor(%d) ISP(%d) ",
2032 __FUNCTION__, numOnHalEmpty, numOnHalFilled, numOnSensor, numOnIsp);
2033 return 0;
2034}
Sungjoong Kang13d8c7b2012-07-14 10:20:39 +09002035
Sungjoong Kang9dd63e12012-07-24 00:25:51 +09002036int BayerBufManager::MarkSensorDequeue(int index, int reqFrameCnt, nsecs_t *timeStamp)
2037{
2038 ALOGV("DEBUG(%s) : BayerIndex[%d] reqFrameCnt(%d)", __FUNCTION__, index, reqFrameCnt);
2039
Sungjoong Kang9dd63e12012-07-24 00:25:51 +09002040 if (entries[index].status != BAYER_ON_SENSOR) {
Sungjoong Kangad378612012-08-17 12:34:33 -07002041 ALOGE("DEBUG(%s) : Abnormal status in BayerIndex[%d] = (%d) expected (%d)", __FUNCTION__,
Sungjoong Kang9dd63e12012-07-24 00:25:51 +09002042 index, entries[index].status, BAYER_ON_SENSOR);
Sungjoong Kang13d8c7b2012-07-14 10:20:39 +09002043 return -1;
2044 }
2045
Sungjoong Kang9dd63e12012-07-24 00:25:51 +09002046 entries[index].status = BAYER_ON_HAL_FILLED;
Sungjoong Kang9dd63e12012-07-24 00:25:51 +09002047 numOnHalFilled++;
2048 numOnSensor--;
Sungjoong Kangad378612012-08-17 12:34:33 -07002049
Sungjoong Kang9dd63e12012-07-24 00:25:51 +09002050 return 0;
2051}
Sungjoong Kang13d8c7b2012-07-14 10:20:39 +09002052
Sungjoong Kang9dd63e12012-07-24 00:25:51 +09002053int BayerBufManager::GetIndexForIspEnqueue(int *reqFrameCnt)
2054{
2055 int ret = 0;
2056 if (numOnHalFilled == 0)
2057 ret = -1;
2058 else {
2059 *reqFrameCnt = entries[ispEnqueueHead].reqFrameCnt;
2060 ret = ispEnqueueHead;
2061 }
2062 ALOGV("DEBUG(%s): returning BayerIndex[%d]", __FUNCTION__, ret);
2063 return ret;
2064}
2065
2066int BayerBufManager::GetIndexForIspDequeue(int *reqFrameCnt)
2067{
2068 int ret = 0;
2069 if (numOnIsp == 0)
2070 ret = -1;
2071 else {
2072 *reqFrameCnt = entries[ispDequeueHead].reqFrameCnt;
2073 ret = ispDequeueHead;
2074 }
2075 ALOGV("DEBUG(%s): returning BayerIndex[%d]", __FUNCTION__, ret);
2076 return ret;
2077}
2078
2079int BayerBufManager::MarkIspEnqueue(int index)
2080{
2081 ALOGV("DEBUG(%s) : BayerIndex[%d] ", __FUNCTION__, index);
2082
2083 // sanity check
2084 if (index != ispEnqueueHead) {
2085 ALOGV("DEBUG(%s) : Abnormal BayerIndex[%d] - expected[%d]", __FUNCTION__, index, ispEnqueueHead);
2086 return -1;
2087 }
2088 if (entries[index].status != BAYER_ON_HAL_FILLED) {
2089 ALOGV("DEBUG(%s) : Abnormal status in BayerIndex[%d] = (%d) expected (%d)", __FUNCTION__,
2090 index, entries[index].status, BAYER_ON_HAL_FILLED);
2091 return -1;
2092 }
2093
2094 entries[index].status = BAYER_ON_ISP;
2095 numOnHalFilled--;
2096 numOnIsp++;
2097 ispEnqueueHead = GetNextIndex(index);
2098 ALOGV("DEBUG(%s) END: HAL-e(%d) HAL-f(%d) Sensor(%d) ISP(%d) ",
2099 __FUNCTION__, numOnHalEmpty, numOnHalFilled, numOnSensor, numOnIsp);
2100 return 0;
2101}
2102
2103int BayerBufManager::MarkIspDequeue(int index)
2104{
2105 ALOGV("DEBUG(%s) : BayerIndex[%d]", __FUNCTION__, index);
2106
2107 // sanity check
2108 if (index != ispDequeueHead) {
2109 ALOGV("DEBUG(%s) : Abnormal BayerIndex[%d] - expected[%d]", __FUNCTION__, index, ispDequeueHead);
2110 return -1;
2111 }
2112 if (entries[index].status != BAYER_ON_ISP) {
2113 ALOGV("DEBUG(%s) : Abnormal status in BayerIndex[%d] = (%d) expected (%d)", __FUNCTION__,
2114 index, entries[index].status, BAYER_ON_ISP);
2115 return -1;
2116 }
2117
2118 entries[index].status = BAYER_ON_HAL_EMPTY;
2119 entries[index].reqFrameCnt = 0;
2120 numOnHalEmpty++;
2121 numOnIsp--;
2122 ispDequeueHead = GetNextIndex(index);
2123 ALOGV("DEBUG(%s) END: HAL-e(%d) HAL-f(%d) Sensor(%d) ISP(%d) ",
2124 __FUNCTION__, numOnHalEmpty, numOnHalFilled, numOnSensor, numOnIsp);
2125 return 0;
2126}
2127
2128int BayerBufManager::GetNumOnSensor()
2129{
2130 return numOnSensor;
2131}
2132
2133int BayerBufManager::GetNumOnHalFilled()
2134{
2135 return numOnHalFilled;
2136}
2137
2138int BayerBufManager::GetNumOnIsp()
2139{
2140 return numOnIsp;
2141}
2142
2143int BayerBufManager::GetNextIndex(int index)
2144{
2145 index++;
2146 if (index >= NUM_BAYER_BUFFERS)
2147 index = 0;
2148
2149 return index;
Sungjoong Kang13d8c7b2012-07-14 10:20:39 +09002150}
Jiyoung Shinc15a6b02012-06-05 01:08:14 -07002151
2152void ExynosCameraHWInterface2::m_mainThreadFunc(SignalDrivenThread * self)
2153{
2154 camera_metadata_t *currentRequest = NULL;
2155 camera_metadata_t *currentFrame = NULL;
2156 size_t numEntries = 0;
Sungjoong Kang13d8c7b2012-07-14 10:20:39 +09002157 size_t frameSize = 0;
Jiyoung Shinc15a6b02012-06-05 01:08:14 -07002158 camera_metadata_t * preparedFrame = NULL;
2159 camera_metadata_t *deregisteredRequest = NULL;
2160 uint32_t currentSignal = self->GetProcessingSignal();
Sungjoong Kang13d8c7b2012-07-14 10:20:39 +09002161 MainThread * selfThread = ((MainThread*)self);
Jiyoung Shinc15a6b02012-06-05 01:08:14 -07002162 int res = 0;
Sungjoong Kang13d8c7b2012-07-14 10:20:39 +09002163
Sungjoong Kangad378612012-08-17 12:34:33 -07002164 int ret;
2165
Sungjoong Kang13d8c7b2012-07-14 10:20:39 +09002166 ALOGV("DEBUG(%s): m_mainThreadFunc (%x)", __FUNCTION__, currentSignal);
2167
2168 if (currentSignal & SIGNAL_THREAD_RELEASE) {
2169 ALOGV("DEBUG(%s): processing SIGNAL_THREAD_RELEASE", __FUNCTION__);
2170
2171 ALOGV("DEBUG(%s): processing SIGNAL_THREAD_RELEASE DONE", __FUNCTION__);
2172 selfThread->SetSignal(SIGNAL_THREAD_TERMINATE);
2173 return;
2174 }
2175
Jiyoung Shinc15a6b02012-06-05 01:08:14 -07002176 if (currentSignal & SIGNAL_MAIN_REQ_Q_NOT_EMPTY) {
Sungjoong Kang13d8c7b2012-07-14 10:20:39 +09002177 ALOGV("DEBUG(%s): MainThread processing SIGNAL_MAIN_REQ_Q_NOT_EMPTY", __FUNCTION__);
Sungjoong Kangad378612012-08-17 12:34:33 -07002178 if (m_requestManager->IsRequestQueueFull()==false) {
Jiyoung Shinc15a6b02012-06-05 01:08:14 -07002179 m_requestQueueOps->dequeue_request(m_requestQueueOps, &currentRequest);
2180 if (NULL == currentRequest) {
Sungjoong Kangad378612012-08-17 12:34:33 -07002181 ALOGE("DEBUG(%s)(0x%x): dequeue_request returned NULL ", __FUNCTION__, currentSignal);
Sungjoong Kang13d8c7b2012-07-14 10:20:39 +09002182 m_isRequestQueueNull = true;
Jiyoung Shinc15a6b02012-06-05 01:08:14 -07002183 }
2184 else {
2185 m_requestManager->RegisterRequest(currentRequest);
Sungjoong Kang13d8c7b2012-07-14 10:20:39 +09002186
Jiyoung Shinc15a6b02012-06-05 01:08:14 -07002187 m_numOfRemainingReqInSvc = m_requestQueueOps->request_count(m_requestQueueOps);
Sungjoong Kang13d8c7b2012-07-14 10:20:39 +09002188 ALOGV("DEBUG(%s): remaining req cnt (%d)", __FUNCTION__, m_numOfRemainingReqInSvc);
Sungjoong Kangad378612012-08-17 12:34:33 -07002189 if (m_requestManager->IsRequestQueueFull()==false)
Sungjoong Kang13d8c7b2012-07-14 10:20:39 +09002190 selfThread->SetSignal(SIGNAL_MAIN_REQ_Q_NOT_EMPTY); // dequeue repeatedly
Sungjoong Kang9dd63e12012-07-24 00:25:51 +09002191
Jiyoung Shinc15a6b02012-06-05 01:08:14 -07002192 m_sensorThread->SetSignal(SIGNAL_SENSOR_START_REQ_PROCESSING);
2193 }
2194 }
2195 else {
2196 m_isRequestQueuePending = true;
2197 }
2198 }
2199
2200 if (currentSignal & SIGNAL_MAIN_STREAM_OUTPUT_DONE) {
Sungjoong Kang13d8c7b2012-07-14 10:20:39 +09002201 ALOGV("DEBUG(%s): MainThread processing SIGNAL_MAIN_STREAM_OUTPUT_DONE", __FUNCTION__);
2202 /*while (1)*/ {
Sungjoong Kang0f26b202012-08-17 15:43:12 -07002203 ret = m_requestManager->PrepareFrame(&numEntries, &frameSize, &preparedFrame, GetAfStateForService());
Sungjoong Kangad378612012-08-17 12:34:33 -07002204 if (ret == false)
2205 ALOGD("++++++ PrepareFrame ret = %d", ret);
2206
Sungjoong Kang13d8c7b2012-07-14 10:20:39 +09002207 m_requestManager->DeregisterRequest(&deregisteredRequest);
Sungjoong Kangad378612012-08-17 12:34:33 -07002208
2209 ret = m_requestQueueOps->free_request(m_requestQueueOps, deregisteredRequest);
2210 if (ret < 0)
2211 ALOGD("++++++ free_request ret = %d", ret);
2212
2213 ret = m_frameQueueOps->dequeue_frame(m_frameQueueOps, numEntries, frameSize, &currentFrame);
2214 if (ret < 0)
2215 ALOGD("++++++ dequeue_frame ret = %d", ret);
2216
Sungjoong Kang13d8c7b2012-07-14 10:20:39 +09002217 if (currentFrame==NULL) {
Sungjoong Kangad378612012-08-17 12:34:33 -07002218 ALOGV("DBG(%s): frame dequeue returned NULL",__FUNCTION__ );
Sungjoong Kang13d8c7b2012-07-14 10:20:39 +09002219 }
2220 else {
Sungjoong Kangdaa1fcd2012-08-08 11:49:43 -07002221 ALOGV("DEBUG(%s): frame dequeue done. numEntries(%d) frameSize(%d)",__FUNCTION__ , numEntries, frameSize);
Sungjoong Kang13d8c7b2012-07-14 10:20:39 +09002222 }
2223 res = append_camera_metadata(currentFrame, preparedFrame);
2224 if (res==0) {
2225 ALOGV("DEBUG(%s): frame metadata append success",__FUNCTION__);
2226 m_frameQueueOps->enqueue_frame(m_frameQueueOps, currentFrame);
2227 }
2228 else {
2229 ALOGE("ERR(%s): frame metadata append fail (%d)",__FUNCTION__, res);
2230 }
Jiyoung Shinc15a6b02012-06-05 01:08:14 -07002231 }
Sungjoong Kang13d8c7b2012-07-14 10:20:39 +09002232 if (!m_isRequestQueueNull) {
2233 selfThread->SetSignal(SIGNAL_MAIN_REQ_Q_NOT_EMPTY);
Jiyoung Shinc15a6b02012-06-05 01:08:14 -07002234 }
Sungjoong Kang9dd63e12012-07-24 00:25:51 +09002235
Sungjoong Kang13d8c7b2012-07-14 10:20:39 +09002236 if (getInProgressCount()>0) {
2237 ALOGV("DEBUG(%s): STREAM_OUTPUT_DONE and signalling REQ_PROCESSING",__FUNCTION__);
2238 m_sensorThread->SetSignal(SIGNAL_SENSOR_START_REQ_PROCESSING);
Jiyoung Shinc15a6b02012-06-05 01:08:14 -07002239 }
Jiyoung Shinc15a6b02012-06-05 01:08:14 -07002240 }
Sungjoong Kang13d8c7b2012-07-14 10:20:39 +09002241 ALOGV("DEBUG(%s): MainThread Exit", __FUNCTION__);
Jiyoung Shinc15a6b02012-06-05 01:08:14 -07002242 return;
2243}
Sungjoong Kang13d8c7b2012-07-14 10:20:39 +09002244
Jiyoung Shinc15a6b02012-06-05 01:08:14 -07002245void ExynosCameraHWInterface2::m_sensorThreadInitialize(SignalDrivenThread * self)
2246{
Sungjoong Kang13d8c7b2012-07-14 10:20:39 +09002247 ALOGV("DEBUG(%s): ", __FUNCTION__ );
Sungjoong Kangad378612012-08-17 12:34:33 -07002248 /* will add */
Sungjoong Kang13d8c7b2012-07-14 10:20:39 +09002249 return;
2250}
2251
2252
Sungjoong Kang13d8c7b2012-07-14 10:20:39 +09002253void ExynosCameraHWInterface2::DumpInfoWithShot(struct camera2_shot_ext * shot_ext)
2254{
Sungjoong Kangad378612012-08-17 12:34:33 -07002255 ALOGD("#### common Section");
2256 ALOGD("#### magic(%x) ",
Sungjoong Kang13d8c7b2012-07-14 10:20:39 +09002257 shot_ext->shot.magicNumber);
Sungjoong Kangad378612012-08-17 12:34:33 -07002258 ALOGD("#### ctl Section");
2259 ALOGD("#### meta(%d) aper(%f) exp(%lld) duration(%lld) ISO(%d) AWB(%d)",
Sungjoong Kang13d8c7b2012-07-14 10:20:39 +09002260 shot_ext->shot.ctl.request.metadataMode,
Sungjoong Kangb56dcc02012-08-08 13:38:09 -07002261 shot_ext->shot.ctl.lens.aperture,
Sungjoong Kang13d8c7b2012-07-14 10:20:39 +09002262 shot_ext->shot.ctl.sensor.exposureTime,
2263 shot_ext->shot.ctl.sensor.frameDuration,
Sungjoong Kangb56dcc02012-08-08 13:38:09 -07002264 shot_ext->shot.ctl.sensor.sensitivity,
2265 shot_ext->shot.ctl.aa.awbMode);
Sungjoong Kang13d8c7b2012-07-14 10:20:39 +09002266
Sungjoong Kangad378612012-08-17 12:34:33 -07002267 ALOGD("#### OutputStream Sensor(%d) SCP(%d) SCC(%d) pv(%d) rec(%d)",
Sungjoong Kang9dd63e12012-07-24 00:25:51 +09002268 shot_ext->request_sensor, shot_ext->request_scp, shot_ext->request_scc,
2269 shot_ext->shot.ctl.request.outputStreams[0],
2270 shot_ext->shot.ctl.request.outputStreams[2]);
Sungjoong Kang13d8c7b2012-07-14 10:20:39 +09002271
Sungjoong Kangad378612012-08-17 12:34:33 -07002272 ALOGD("#### DM Section");
2273 ALOGD("#### meta(%d) aper(%f) exp(%lld) duration(%lld) ISO(%d) timestamp(%lld) AWB(%d) cnt(%d)",
Sungjoong Kang13d8c7b2012-07-14 10:20:39 +09002274 shot_ext->shot.dm.request.metadataMode,
Sungjoong Kangb56dcc02012-08-08 13:38:09 -07002275 shot_ext->shot.dm.lens.aperture,
Sungjoong Kang13d8c7b2012-07-14 10:20:39 +09002276 shot_ext->shot.dm.sensor.exposureTime,
2277 shot_ext->shot.dm.sensor.frameDuration,
2278 shot_ext->shot.dm.sensor.sensitivity,
Sungjoong Kangb56dcc02012-08-08 13:38:09 -07002279 shot_ext->shot.dm.sensor.timeStamp,
2280 shot_ext->shot.dm.aa.awbMode,
2281 shot_ext->shot.dm.request.frameCount );
Sungjoong Kang13d8c7b2012-07-14 10:20:39 +09002282}
2283
2284void ExynosCameraHWInterface2::m_sensorThreadFunc(SignalDrivenThread * self)
2285{
2286 uint32_t currentSignal = self->GetProcessingSignal();
2287 SensorThread * selfThread = ((SensorThread*)self);
2288 int index;
Sungjoong Kangad378612012-08-17 12:34:33 -07002289 int index_isp;
Sungjoong Kang13d8c7b2012-07-14 10:20:39 +09002290 status_t res;
2291 nsecs_t frameTime;
2292 int bayersOnSensor = 0, bayersOnIsp = 0;
Sungjoong Kangad378612012-08-17 12:34:33 -07002293 int j = 0;
2294 bool isCapture = false;
Sungjoong Kang13d8c7b2012-07-14 10:20:39 +09002295 ALOGV("DEBUG(%s): m_sensorThreadFunc (%x)", __FUNCTION__, currentSignal);
2296
2297 if (currentSignal & SIGNAL_THREAD_RELEASE) {
Sungjoong Kangad378612012-08-17 12:34:33 -07002298 ALOGV("(%s): ENTER processing SIGNAL_THREAD_RELEASE", __FUNCTION__);
Sungjoong Kang13d8c7b2012-07-14 10:20:39 +09002299
Sungjoong Kang9dd63e12012-07-24 00:25:51 +09002300 ALOGV("(%s): calling sensor streamoff", __FUNCTION__);
Sungjoong Kang13d8c7b2012-07-14 10:20:39 +09002301 cam_int_streamoff(&(m_camera_info.sensor));
Sungjoong Kang9dd63e12012-07-24 00:25:51 +09002302 ALOGV("(%s): calling sensor streamoff done", __FUNCTION__);
Sungjoong Kangb5237e62012-07-27 07:39:05 -07002303
2304 m_camera_info.sensor.buffers = 0;
2305 ALOGV("DEBUG(%s): sensor calling reqbuf 0 ", __FUNCTION__);
2306 cam_int_reqbufs(&(m_camera_info.sensor));
2307 ALOGV("DEBUG(%s): sensor calling reqbuf 0 done", __FUNCTION__);
Sungjoong Kangad378612012-08-17 12:34:33 -07002308
Sungjoong Kang9dd63e12012-07-24 00:25:51 +09002309 ALOGV("(%s): calling ISP streamoff", __FUNCTION__);
2310 isp_int_streamoff(&(m_camera_info.isp));
2311 ALOGV("(%s): calling ISP streamoff done", __FUNCTION__);
Sungjoong Kangad378612012-08-17 12:34:33 -07002312
Sungjoong Kangb5237e62012-07-27 07:39:05 -07002313 m_camera_info.isp.buffers = 0;
2314 ALOGV("DEBUG(%s): isp calling reqbuf 0 ", __FUNCTION__);
2315 cam_int_reqbufs(&(m_camera_info.isp));
2316 ALOGV("DEBUG(%s): isp calling reqbuf 0 done", __FUNCTION__);
2317
Sungjoong Kang13d8c7b2012-07-14 10:20:39 +09002318 exynos_v4l2_s_ctrl(m_camera_info.sensor.fd, V4L2_CID_IS_S_STREAM, IS_DISABLE_STREAM);
Sungjoong Kang13d8c7b2012-07-14 10:20:39 +09002319
Sungjoong Kangad378612012-08-17 12:34:33 -07002320 ALOGV("(%s): EXIT processing SIGNAL_THREAD_RELEASE", __FUNCTION__);
Sungjoong Kang13d8c7b2012-07-14 10:20:39 +09002321 selfThread->SetSignal(SIGNAL_THREAD_TERMINATE);
2322 return;
2323 }
2324
2325 if (currentSignal & SIGNAL_SENSOR_START_REQ_PROCESSING)
2326 {
2327 ALOGV("DEBUG(%s): SensorThread processing SIGNAL_SENSOR_START_REQ_PROCESSING", __FUNCTION__);
Sungjoong Kang9dd63e12012-07-24 00:25:51 +09002328 int targetStreamIndex = 0, i=0;
Sungjoong Kangad378612012-08-17 12:34:33 -07002329 int matchedFrameCnt = -1, processingReqIndex;
Sungjoong Kang13d8c7b2012-07-14 10:20:39 +09002330 struct camera2_shot_ext *shot_ext;
Sungjoong Kangad378612012-08-17 12:34:33 -07002331 struct camera2_shot_ext *shot_ext_capture;
Sungjoong Kang0f26b202012-08-17 15:43:12 -07002332 bool triggered = false;
2333 int afMode;
Sungjoong Kang9dd63e12012-07-24 00:25:51 +09002334
Sungjoong Kangad378612012-08-17 12:34:33 -07002335 /* dqbuf from sensor */
2336 ALOGV("Sensor DQbuf start");
Sungjoong Kang13d8c7b2012-07-14 10:20:39 +09002337 index = cam_int_dqbuf(&(m_camera_info.sensor));
Sungjoong Kang9dd63e12012-07-24 00:25:51 +09002338 shot_ext = (struct camera2_shot_ext *)(m_camera_info.sensor.buffer[index].virt.extP[1]);
Sungjoong Kangad378612012-08-17 12:34:33 -07002339
2340 m_recordOutput = shot_ext->shot.ctl.request.outputStreams[2];
2341
Sungjoong Kang9dd63e12012-07-24 00:25:51 +09002342 matchedFrameCnt = m_requestManager->FindFrameCnt(shot_ext);
Sungjoong Kangad378612012-08-17 12:34:33 -07002343
Sungjoong Kanga07cbd92012-07-27 12:03:29 -07002344 if (matchedFrameCnt != -1) {
Sungjoong Kangef6f83c2012-08-28 22:59:48 +09002345 frameTime = systemTime();
2346 m_requestManager->RegisterTimestamp(matchedFrameCnt, &frameTime);
2347 m_requestManager->UpdateIspParameters(shot_ext, matchedFrameCnt);
Sungjoong Kang8e2c2fd2012-08-27 00:02:22 -07002348 if (m_afModeWaitingCnt != 0) {
2349 ALOGV("### Af Trigger pulled, waiting for mode change cnt(%d) ", m_afModeWaitingCnt);
2350 m_afModeWaitingCnt --;
2351 if (m_afModeWaitingCnt == 1) {
2352 m_afModeWaitingCnt == 0;
2353 OnAfTrigger(m_afPendingTriggerId);
2354 }
2355 }
Sungjoong Kang0f26b202012-08-17 15:43:12 -07002356 if (m_IsAfModeUpdateRequired) {
2357 ALOGE("### AF Mode change(Mode %d) ", m_afMode);
2358 shot_ext->shot.ctl.aa.afMode = m_afMode;
2359 if (m_afMode == AA_AFMODE_CONTINUOUS_VIDEO || m_afMode == AA_AFMODE_CONTINUOUS_PICTURE) {
2360 ALOGE("### With Automatic triger for continuous modes");
2361 m_afState = HAL_AFSTATE_STARTED;
2362 shot_ext->shot.ctl.aa.afTrigger = 1;
2363 triggered = true;
2364 }
2365 m_IsAfModeUpdateRequired = false;
2366 if (m_afMode2 != NO_CHANGE) {
2367 enum aa_afmode tempAfMode = m_afMode2;
2368 m_afMode2 = NO_CHANGE;
2369 SetAfMode(tempAfMode);
2370 }
2371 }
2372 else {
2373 shot_ext->shot.ctl.aa.afMode = NO_CHANGE;
2374 }
2375 if (m_IsAfTriggerRequired) {
2376 ALOGE("### AF Triggering with mode (%d)", m_afMode);
Sungjoong Kang36c106c2012-08-23 17:38:20 -07002377 if (m_afState == HAL_AFSTATE_SCANNING) {
2378 ALOGE("(%s): restarting trigger ", __FUNCTION__);
2379 }
2380 else {
2381 if (m_afState != HAL_AFSTATE_NEEDS_COMMAND)
2382 ALOGE("(%s): wrong trigger state %d", __FUNCTION__, m_afState);
2383 else
2384 m_afState = HAL_AFSTATE_STARTED;
2385 }
Sungjoong Kang8e2c2fd2012-08-27 00:02:22 -07002386 shot_ext->shot.ctl.aa.afTrigger = 1;
Sungjoong Kang0f26b202012-08-17 15:43:12 -07002387 shot_ext->shot.ctl.aa.afMode = m_afMode;
2388 m_IsAfTriggerRequired = false;
2389 }
2390 else {
Sungjoong Kang8e2c2fd2012-08-27 00:02:22 -07002391 shot_ext->shot.ctl.aa.afTrigger = 0;
Sungjoong Kang0f26b202012-08-17 15:43:12 -07002392 }
Sungjoong Kang15fd8232012-08-23 16:16:44 -07002393 if (m_wideAspect) {
Sungjoong Kangef6f83c2012-08-28 22:59:48 +09002394 //shot_ext->setfile = ISS_SUB_SCENARIO_VIDEO;
Sungjoong Kang15fd8232012-08-23 16:16:44 -07002395 shot_ext->shot.ctl.aa.aeTargetFpsRange[0] = 30;
2396 shot_ext->shot.ctl.aa.aeTargetFpsRange[1] = 30;
2397 }
2398 else {
Sungjoong Kangef6f83c2012-08-28 22:59:48 +09002399 //shot_ext->setfile = ISS_SUB_SCENARIO_STILL;
Sungjoong Kang15fd8232012-08-23 16:16:44 -07002400 }
Sungjoong Kang0f26b202012-08-17 15:43:12 -07002401 if (triggered)
2402 shot_ext->shot.ctl.aa.afTrigger = 1;
2403
2404 // TODO : check collision with AFMode Update
2405 if (m_IsAfLockRequired) {
2406 shot_ext->shot.ctl.aa.afMode = AA_AFMODE_OFF;
2407 m_IsAfLockRequired = false;
2408 }
Rebecca Schultz Zavin4ed2f102012-08-22 00:55:29 -07002409 ALOGV("### Isp Qbuf start(%d) count (%d), SCP(%d) SCC(%d) DIS(%d) shot_size(%d)",
Sungjoong Kangad378612012-08-17 12:34:33 -07002410 index,
2411 shot_ext->shot.ctl.request.frameCount,
2412 shot_ext->request_scp,
2413 shot_ext->request_scc,
2414 shot_ext->dis_bypass, sizeof(camera2_shot));
Sungjoong Kang9dd63e12012-07-24 00:25:51 +09002415
Sungjoong Kang8e2c2fd2012-08-27 00:02:22 -07002416 if (0 == shot_ext->shot.ctl.aa.afRegions[0] && 0 == shot_ext->shot.ctl.aa.afRegions[1]
2417 && 0 == shot_ext->shot.ctl.aa.afRegions[2] && 0 == shot_ext->shot.ctl.aa.afRegions[3]) {
2418 ALOGV("(%s): AF region resetting", __FUNCTION__);
2419 lastAfRegion[0] = 0;
2420 lastAfRegion[1] = 0;
2421 lastAfRegion[2] = 0;
2422 lastAfRegion[3] = 0;
2423 }
2424 else {
2425 if (!(lastAfRegion[0] == shot_ext->shot.ctl.aa.afRegions[0] && lastAfRegion[1] == shot_ext->shot.ctl.aa.afRegions[1]
2426 && lastAfRegion[2] == shot_ext->shot.ctl.aa.afRegions[2] && lastAfRegion[3] == shot_ext->shot.ctl.aa.afRegions[3])) {
2427 ALOGV("(%s): AF region changed : triggering", __FUNCTION__);
2428 shot_ext->shot.ctl.aa.afTrigger = 1;
2429 shot_ext->shot.ctl.aa.afMode = m_afMode;
2430 m_afState = HAL_AFSTATE_STARTED;
2431 lastAfRegion[0] = shot_ext->shot.ctl.aa.afRegions[0];
2432 lastAfRegion[1] = shot_ext->shot.ctl.aa.afRegions[1];
2433 lastAfRegion[2] = shot_ext->shot.ctl.aa.afRegions[2];
2434 lastAfRegion[3] = shot_ext->shot.ctl.aa.afRegions[3];
2435 }
2436 }
2437 ALOGV("(%s): queued aa(%d) aemode(%d) awb(%d) afmode(%d) trigger(%d)", __FUNCTION__,
2438 (int)(shot_ext->shot.ctl.aa.mode), (int)(shot_ext->shot.ctl.aa.aeMode),
2439 (int)(shot_ext->shot.ctl.aa.awbMode), (int)(shot_ext->shot.ctl.aa.afMode),
2440 (int)(shot_ext->shot.ctl.aa.afTrigger));
Sungjoong Kangad378612012-08-17 12:34:33 -07002441 cam_int_qbuf(&(m_camera_info.isp), index);
Sungjoong Kangad378612012-08-17 12:34:33 -07002442
2443 usleep(10000);
Sungjoong Kangad378612012-08-17 12:34:33 -07002444
2445 ALOGV("### isp DQBUF start");
2446 index_isp = cam_int_dqbuf(&(m_camera_info.isp));
Sungjoong Kangef6f83c2012-08-28 22:59:48 +09002447
Sungjoong Kangad378612012-08-17 12:34:33 -07002448
Sungjoong Kangad378612012-08-17 12:34:33 -07002449 shot_ext = (struct camera2_shot_ext *)(m_camera_info.isp.buffer[index_isp].virt.extP[1]);
2450
2451 ALOGV("### Isp DQbuf done(%d) count (%d), SCP(%d) SCC(%d) shot_size(%d)",
2452 index,
2453 shot_ext->shot.ctl.request.frameCount,
2454 shot_ext->request_scp,
2455 shot_ext->request_scc,
2456 shot_ext->dis_bypass, sizeof(camera2_shot));
Sungjoong Kangef6f83c2012-08-28 22:59:48 +09002457 ALOGV("(%s): DM aa(%d) aemode(%d) awb(%d) afmode(%d)", __FUNCTION__,
Sungjoong Kang8e2c2fd2012-08-27 00:02:22 -07002458 (int)(shot_ext->shot.dm.aa.mode), (int)(shot_ext->shot.dm.aa.aeMode),
2459 (int)(shot_ext->shot.dm.aa.awbMode),
2460 (int)(shot_ext->shot.dm.aa.afMode));
Sungjoong Kangad378612012-08-17 12:34:33 -07002461
Sungjoong Kangef6f83c2012-08-28 22:59:48 +09002462 m_previewOutput = 0;
Sungjoong Kangad378612012-08-17 12:34:33 -07002463 if (shot_ext->request_scp) {
2464 m_previewOutput = 1;
2465 m_streamThreads[0]->SetSignal(SIGNAL_STREAM_DATA_COMING);
2466 }
2467
Sungjoong Kang15fd8232012-08-23 16:16:44 -07002468 if (shot_ext->request_scc) {
2469 m_streamThreads[1]->SetSignal(SIGNAL_STREAM_DATA_COMING);
2470 }
Sungjoong Kangad378612012-08-17 12:34:33 -07002471
2472 ALOGV("(%s): SCP_CLOSING check sensor(%d) scc(%d) scp(%d) ", __FUNCTION__,
2473 shot_ext->request_sensor, shot_ext->request_scc, shot_ext->request_scp);
2474 if (shot_ext->request_scc + shot_ext->request_scp + shot_ext->request_sensor == 0) {
2475 ALOGV("(%s): SCP_CLOSING check OK ", __FUNCTION__);
2476 m_scp_closed = true;
2477 }
2478 else
2479 m_scp_closed = false;
2480
Sungjoong Kangfd2d78a2012-08-26 17:44:25 -07002481 if (!shot_ext->fd_bypass) {
2482 /* FD orientation axis transformation */
2483 for (int i=0; i < CAMERA2_MAX_FACES; i++) {
2484 if (shot_ext->shot.dm.stats.faceRectangles[i][0] > 0)
2485 shot_ext->shot.dm.stats.faceRectangles[i][0] = (m_camera2->m_curCameraInfo->sensorW
Sungjoong Kangef6f83c2012-08-28 22:59:48 +09002486 * shot_ext->shot.dm.stats.faceRectangles[i][0])
2487 / m_streamThreads[0].get()->m_parameters.outputWidth;
Sungjoong Kangfd2d78a2012-08-26 17:44:25 -07002488 if (shot_ext->shot.dm.stats.faceRectangles[i][1] > 0)
2489 shot_ext->shot.dm.stats.faceRectangles[i][1] = (m_camera2->m_curCameraInfo->sensorH
Sungjoong Kangef6f83c2012-08-28 22:59:48 +09002490 * shot_ext->shot.dm.stats.faceRectangles[i][1])
2491 / m_streamThreads[0].get()->m_parameters.outputHeight;
Sungjoong Kangfd2d78a2012-08-26 17:44:25 -07002492 if (shot_ext->shot.dm.stats.faceRectangles[i][2] > 0)
2493 shot_ext->shot.dm.stats.faceRectangles[i][2] = (m_camera2->m_curCameraInfo->sensorW
Sungjoong Kangef6f83c2012-08-28 22:59:48 +09002494 * shot_ext->shot.dm.stats.faceRectangles[i][2])
2495 / m_streamThreads[0].get()->m_parameters.outputWidth;
Sungjoong Kangfd2d78a2012-08-26 17:44:25 -07002496 if (shot_ext->shot.dm.stats.faceRectangles[i][3] > 0)
2497 shot_ext->shot.dm.stats.faceRectangles[i][3] = (m_camera2->m_curCameraInfo->sensorH
Sungjoong Kangef6f83c2012-08-28 22:59:48 +09002498 * shot_ext->shot.dm.stats.faceRectangles[i][3])
2499 / m_streamThreads[0].get()->m_parameters.outputHeight;
Sungjoong Kangfd2d78a2012-08-26 17:44:25 -07002500 }
2501 }
2502
Sungjoong Kangad378612012-08-17 12:34:33 -07002503 m_requestManager->ApplyDynamicMetadata(shot_ext);
Sungjoong Kang0f26b202012-08-17 15:43:12 -07002504 OnAfNotification(shot_ext->shot.dm.aa.afState);
Sungjoong Kang13d8c7b2012-07-14 10:20:39 +09002505 }
Sungjoong Kangad378612012-08-17 12:34:33 -07002506
Sungjoong Kang0f26b202012-08-17 15:43:12 -07002507 processingReqIndex = m_requestManager->MarkProcessingRequest(&(m_camera_info.sensor.buffer[index]), &afMode);
Sungjoong Kangef6f83c2012-08-28 22:59:48 +09002508 if (processingReqIndex != -1)
Sungjoong Kang0f26b202012-08-17 15:43:12 -07002509 SetAfMode((enum aa_afmode)afMode);
Sungjoong Kangef6f83c2012-08-28 22:59:48 +09002510
Sungjoong Kangad378612012-08-17 12:34:33 -07002511
2512 shot_ext = (struct camera2_shot_ext *)(m_camera_info.sensor.buffer[index].virt.extP[1]);
2513 if (m_scp_closing || m_scp_closed) {
2514 ALOGD("(%s): SCP_CLOSING(%d) SCP_CLOSED(%d)", __FUNCTION__, m_scp_closing, m_scp_closed);
2515 shot_ext->request_scc = 0;
2516 shot_ext->request_scp = 0;
2517 shot_ext->request_sensor = 0;
2518 }
2519
Sungjoong Kangad378612012-08-17 12:34:33 -07002520 cam_int_qbuf(&(m_camera_info.sensor), index);
2521 ALOGV("### Sensor QBUF done");
2522
Sungjoong Kangef6f83c2012-08-28 22:59:48 +09002523 if (!m_scp_closing
2524 && ((matchedFrameCnt == -1) || (processingReqIndex == -1))){
2525 ALOGD("make bubble shot: matchedFramcnt(%d) processingReqIndex(%d)",
2526 matchedFrameCnt, processingReqIndex);
Sungjoong Kang13d8c7b2012-07-14 10:20:39 +09002527 selfThread->SetSignal(SIGNAL_SENSOR_START_REQ_PROCESSING);
Sungjoong Kang13d8c7b2012-07-14 10:20:39 +09002528 }
Sungjoong Kang9dd63e12012-07-24 00:25:51 +09002529 }
Sungjoong Kang13d8c7b2012-07-14 10:20:39 +09002530 return;
2531}
2532
Sungjoong Kang13d8c7b2012-07-14 10:20:39 +09002533void ExynosCameraHWInterface2::m_ispThreadInitialize(SignalDrivenThread * self)
2534{
2535 ALOGV("DEBUG(%s): ", __FUNCTION__ );
Sungjoong Kangad378612012-08-17 12:34:33 -07002536 /* will add */
Jiyoung Shinc15a6b02012-06-05 01:08:14 -07002537 return;
2538}
2539
Jiyoung Shinc15a6b02012-06-05 01:08:14 -07002540
Sungjoong Kang13d8c7b2012-07-14 10:20:39 +09002541void ExynosCameraHWInterface2::m_ispThreadFunc(SignalDrivenThread * self)
2542{
Sungjoong Kangad378612012-08-17 12:34:33 -07002543 ALOGV("DEBUG(%s): ", __FUNCTION__ );
2544 /* will add */
Jiyoung Shinc15a6b02012-06-05 01:08:14 -07002545 return;
2546}
2547
Sungjoong Kang86646da2012-08-28 17:29:11 +09002548void ExynosCameraHWInterface2::m_streamBufferInit(SignalDrivenThread *self)
2549{
2550 uint32_t currentSignal = self->GetProcessingSignal();
2551 StreamThread * selfThread = ((StreamThread*)self);
2552 stream_parameters_t *selfStreamParms = &(selfThread->m_parameters);
2553 record_parameters_t *selfRecordParms = &(selfThread->m_recordParameters);
2554 node_info_t *currentNode = &(selfStreamParms->node);
2555
2556 buffer_handle_t * buf = NULL;
2557 status_t res;
2558 void *virtAddr[3];
2559 int i, j;
2560 int index;
2561 nsecs_t timestamp;
2562
2563 if (!(selfThread->m_isBufferInit))
2564 {
2565 for ( i=0 ; i < selfStreamParms->numSvcBuffers; i++) {
2566 res = selfStreamParms->streamOps->dequeue_buffer(selfStreamParms->streamOps, &buf);
2567 if (res != NO_ERROR || buf == NULL) {
2568 ALOGE("ERR(%s): Init: unable to dequeue buffer : %d",__FUNCTION__ , res);
2569 return;
2570 }
2571 ALOGV("DEBUG(%s): got buf(%x) version(%d), numFds(%d), numInts(%d)", __FUNCTION__, (uint32_t)(*buf),
2572 ((native_handle_t*)(*buf))->version, ((native_handle_t*)(*buf))->numFds, ((native_handle_t*)(*buf))->numInts);
2573
2574 if (m_grallocHal->lock(m_grallocHal, *buf,
2575 selfStreamParms->usage,
2576 0, 0, selfStreamParms->outputWidth, selfStreamParms->outputHeight, virtAddr) != 0) {
2577 ALOGE("ERR(%s): could not obtain gralloc buffer", __FUNCTION__);
2578 return;
2579 }
2580 ALOGV("DEBUG(%s): locked img buf plane0(%x) plane1(%x) plane2(%x)",
2581 __FUNCTION__, (unsigned int)virtAddr[0], (unsigned int)virtAddr[1], (unsigned int)virtAddr[2]);
2582
2583 index = selfThread->findBufferIndex(virtAddr[0]);
2584 if (index == -1) {
2585 ALOGE("ERR(%s): could not find buffer index", __FUNCTION__);
2586 }
2587 else {
2588 ALOGV("DEBUG(%s): found buffer index[%d] - status(%d)",
2589 __FUNCTION__, index, selfStreamParms->svcBufStatus[index]);
2590 if (selfStreamParms->svcBufStatus[index]== REQUIRES_DQ_FROM_SVC)
2591 selfStreamParms->svcBufStatus[index] = ON_DRIVER;
2592 else if (selfStreamParms->svcBufStatus[index]== ON_SERVICE)
2593 selfStreamParms->svcBufStatus[index] = ON_HAL;
2594 else {
2595 ALOGV("DBG(%s): buffer status abnormal (%d) "
2596 , __FUNCTION__, selfStreamParms->svcBufStatus[index]);
2597 }
2598 selfStreamParms->numSvcBufsInHal++;
2599 if (*buf != selfStreamParms->svcBufHandle[index])
2600 ALOGV("DBG(%s): different buf_handle index ", __FUNCTION__);
2601 else
2602 ALOGV("DEBUG(%s): same buf_handle index", __FUNCTION__);
2603 }
2604 selfStreamParms->svcBufIndex = 0;
2605 }
2606 selfThread->m_isBufferInit = true;
2607 }
2608
2609 if (m_recordingEnabled && m_needsRecordBufferInit) {
2610 ALOGV("DEBUG(%s): Recording Buffer Initialization numsvcbuf(%d)",
2611 __FUNCTION__, selfRecordParms->numSvcBuffers);
2612 int checkingIndex = 0;
2613 bool found = false;
2614 for ( i=0 ; i < selfRecordParms->numSvcBuffers; i++) {
2615 res = selfRecordParms->streamOps->dequeue_buffer(selfRecordParms->streamOps, &buf);
2616 if (res != NO_ERROR || buf == NULL) {
2617 ALOGE("ERR(%s): Init: unable to dequeue buffer : %d",__FUNCTION__ , res);
2618 return;
2619 }
2620 selfRecordParms->numSvcBufsInHal++;
2621 ALOGV("DEBUG(%s): [record] got buf(%x) bufInHal(%d) version(%d), numFds(%d), numInts(%d)", __FUNCTION__, (uint32_t)(*buf),
2622 selfRecordParms->numSvcBufsInHal, ((native_handle_t*)(*buf))->version, ((native_handle_t*)(*buf))->numFds, ((native_handle_t*)(*buf))->numInts);
2623
2624 if (m_grallocHal->lock(m_grallocHal, *buf,
2625 selfRecordParms->usage, 0, 0,
2626 selfRecordParms->outputWidth, selfRecordParms->outputHeight, virtAddr) != 0) {
2627 ALOGE("ERR(%s): could not obtain gralloc buffer", __FUNCTION__);
2628 }
2629 else {
2630 ALOGV("DEBUG(%s): [record] locked img buf plane0(%x) plane1(%x) plane2(%x)",
2631 __FUNCTION__, (unsigned int)virtAddr[0], (unsigned int)virtAddr[1], (unsigned int)virtAddr[2]);
2632 }
2633 found = false;
2634 for (checkingIndex = 0; checkingIndex < selfRecordParms->numSvcBuffers ; checkingIndex++) {
2635 if (selfRecordParms->svcBufHandle[checkingIndex] == *buf ) {
2636 found = true;
2637 break;
2638 }
2639 }
2640 ALOGV("DEBUG(%s): [record] found(%d) - index[%d]", __FUNCTION__, found, checkingIndex);
2641 if (!found) break;
2642
2643 index = checkingIndex;
2644
2645 if (index == -1) {
2646 ALOGV("ERR(%s): could not find buffer index", __FUNCTION__);
2647 }
2648 else {
2649 ALOGV("DEBUG(%s): found buffer index[%d] - status(%d)",
2650 __FUNCTION__, index, selfRecordParms->svcBufStatus[index]);
2651 if (selfRecordParms->svcBufStatus[index]== ON_SERVICE)
2652 selfRecordParms->svcBufStatus[index] = ON_HAL;
2653 else {
2654 ALOGV("DBG(%s): buffer status abnormal (%d) "
2655 , __FUNCTION__, selfRecordParms->svcBufStatus[index]);
2656 }
2657 if (*buf != selfRecordParms->svcBufHandle[index])
2658 ALOGV("DBG(%s): different buf_handle index ", __FUNCTION__);
2659 else
2660 ALOGV("DEBUG(%s): same buf_handle index", __FUNCTION__);
2661 }
2662 selfRecordParms->svcBufIndex = 0;
2663 }
2664 m_needsRecordBufferInit = false;
2665 }
2666
2667}
2668
Jiyoung Shinc15a6b02012-06-05 01:08:14 -07002669void ExynosCameraHWInterface2::m_streamThreadInitialize(SignalDrivenThread * self)
2670{
Sungjoong Kang13d8c7b2012-07-14 10:20:39 +09002671 StreamThread * selfThread = ((StreamThread*)self);
2672 ALOGV("DEBUG(%s): ", __FUNCTION__ );
2673 memset(&(selfThread->m_parameters), 0, sizeof(stream_parameters_t));
2674 selfThread->m_isBufferInit = false;
2675
Jiyoung Shinc15a6b02012-06-05 01:08:14 -07002676 return;
2677}
2678
Sungjoong Kang86646da2012-08-28 17:29:11 +09002679void ExynosCameraHWInterface2::m_streamFunc0(SignalDrivenThread *self)
Jiyoung Shinc15a6b02012-06-05 01:08:14 -07002680{
Sungjoong Kang13d8c7b2012-07-14 10:20:39 +09002681 uint32_t currentSignal = self->GetProcessingSignal();
2682 StreamThread * selfThread = ((StreamThread*)self);
2683 stream_parameters_t *selfStreamParms = &(selfThread->m_parameters);
Sungjoong Kang9dd63e12012-07-24 00:25:51 +09002684 record_parameters_t *selfRecordParms = &(selfThread->m_recordParameters);
Sungjoong Kang13d8c7b2012-07-14 10:20:39 +09002685 node_info_t *currentNode = &(selfStreamParms->node);
Jiyoung Shinc15a6b02012-06-05 01:08:14 -07002686
Sungjoong Kang13d8c7b2012-07-14 10:20:39 +09002687 if (currentSignal & SIGNAL_STREAM_CHANGE_PARAMETER) {
2688 ALOGV("DEBUG(%s): processing SIGNAL_STREAM_CHANGE_PARAMETER", __FUNCTION__);
Jiyoung Shinc15a6b02012-06-05 01:08:14 -07002689
Sungjoong Kang13d8c7b2012-07-14 10:20:39 +09002690 ALOGV("DEBUG(%s): processing SIGNAL_STREAM_CHANGE_PARAMETER DONE", __FUNCTION__);
Jiyoung Shinc15a6b02012-06-05 01:08:14 -07002691 }
Sungjoong Kang13d8c7b2012-07-14 10:20:39 +09002692
Sungjoong Kang13d8c7b2012-07-14 10:20:39 +09002693 if (currentSignal & SIGNAL_STREAM_DATA_COMING) {
Jiyoung Shinc15a6b02012-06-05 01:08:14 -07002694 buffer_handle_t * buf = NULL;
2695 status_t res;
2696 void *virtAddr[3];
2697 int i, j;
2698 int index;
Sungjoong Kangad378612012-08-17 12:34:33 -07002699 nsecs_t timestamp;
2700
Sungjoong Kang13d8c7b2012-07-14 10:20:39 +09002701 ALOGV("DEBUG(%s): stream(%d) processing SIGNAL_STREAM_DATA_COMING",
2702 __FUNCTION__,selfThread->m_index);
Sungjoong Kangad378612012-08-17 12:34:33 -07002703
Sungjoong Kang86646da2012-08-28 17:29:11 +09002704 m_streamBufferInit(self);
Jiyoung Shinc15a6b02012-06-05 01:08:14 -07002705
Sungjoong Kangb5237e62012-07-27 07:39:05 -07002706 do {
Sungjoong Kang86646da2012-08-28 17:29:11 +09002707 ALOGV("DEBUG(%s): stream(%d) type(%d) DQBUF START ",__FUNCTION__,
2708 selfThread->m_index, selfStreamParms->streamType);
Jiyoung Shinc15a6b02012-06-05 01:08:14 -07002709
Sungjoong Kang86646da2012-08-28 17:29:11 +09002710 index = cam_int_dqbuf(&(selfStreamParms->node));
2711 ALOGV("DEBUG(%s): stream(%d) type(%d) DQBUF done index(%d)",__FUNCTION__,
2712 selfThread->m_index, selfStreamParms->streamType, index);
Sungjoong Kang13d8c7b2012-07-14 10:20:39 +09002713
Sungjoong Kang86646da2012-08-28 17:29:11 +09002714 if (selfStreamParms->svcBufStatus[index] != ON_DRIVER)
2715 ALOGV("DBG(%s): DQed buffer status abnormal (%d) ",
2716 __FUNCTION__, selfStreamParms->svcBufStatus[index]);
2717 selfStreamParms->svcBufStatus[index] = ON_HAL;
Sungjoong Kang13d8c7b2012-07-14 10:20:39 +09002718
Sungjoong Kang86646da2012-08-28 17:29:11 +09002719 if (m_recordOutput && m_recordingEnabled) {
2720 ALOGV("DEBUG(%s): Entering record frame creator, index(%d)",__FUNCTION__, selfRecordParms->svcBufIndex);
Sungjoong Kang37e122d2012-08-08 11:13:48 -07002721 bool found = false;
Sungjoong Kang86646da2012-08-28 17:29:11 +09002722 for (int i = 0 ; selfRecordParms->numSvcBuffers ; i++) {
2723 if (selfRecordParms->svcBufStatus[selfRecordParms->svcBufIndex] == ON_HAL) {
Sungjoong Kang37e122d2012-08-08 11:13:48 -07002724 found = true;
2725 break;
2726 }
Sungjoong Kang86646da2012-08-28 17:29:11 +09002727 selfRecordParms->svcBufIndex++;
2728 if (selfRecordParms->svcBufIndex >= selfRecordParms->numSvcBuffers)
2729 selfRecordParms->svcBufIndex = 0;
Sungjoong Kang37e122d2012-08-08 11:13:48 -07002730 }
2731 if (!found) {
Sungjoong Kang86646da2012-08-28 17:29:11 +09002732 ALOGE("(%s): cannot find free recording buffer", __FUNCTION__);
2733 selfRecordParms->svcBufIndex++;
Sungjoong Kang37e122d2012-08-08 11:13:48 -07002734 break;
2735 }
Jiyoung Shinc15a6b02012-06-05 01:08:14 -07002736
Sungjoong Kang86646da2012-08-28 17:29:11 +09002737 if (m_exynosVideoCSC) {
2738 int videoW = selfRecordParms->outputWidth, videoH = selfRecordParms->outputHeight;
2739 int cropX, cropY, cropW, cropH = 0;
2740 int previewW = selfStreamParms->outputWidth, previewH = selfStreamParms->outputHeight;
2741 m_getRatioSize(previewW, previewH,
2742 videoW, videoH,
Sungjoong Kangb5237e62012-07-27 07:39:05 -07002743 &cropX, &cropY,
2744 &cropW, &cropH,
Sungjoong Kangad378612012-08-17 12:34:33 -07002745 0);
Sungjoong Kang13d8c7b2012-07-14 10:20:39 +09002746
Sungjoong Kangb5237e62012-07-27 07:39:05 -07002747 ALOGV("DEBUG(%s):cropX = %d, cropY = %d, cropW = %d, cropH = %d",
Sungjoong Kang86646da2012-08-28 17:29:11 +09002748 __FUNCTION__, cropX, cropY, cropW, cropH);
Sungjoong Kang13d8c7b2012-07-14 10:20:39 +09002749
Sungjoong Kang86646da2012-08-28 17:29:11 +09002750 csc_set_src_format(m_exynosVideoCSC,
2751 previewW, previewH,
Sungjoong Kangb5237e62012-07-27 07:39:05 -07002752 cropX, cropY, cropW, cropH,
Sungjoong Kang86646da2012-08-28 17:29:11 +09002753 HAL_PIXEL_FORMAT_YV12,
Sungjoong Kangb5237e62012-07-27 07:39:05 -07002754 0);
Sungjoong Kang13d8c7b2012-07-14 10:20:39 +09002755
Sungjoong Kang86646da2012-08-28 17:29:11 +09002756 csc_set_dst_format(m_exynosVideoCSC,
2757 videoW, videoH,
2758 0, 0, videoW, videoH,
2759 selfRecordParms->outputFormat,
2760 1);
Jiyoung Shinc15a6b02012-06-05 01:08:14 -07002761
Sungjoong Kang86646da2012-08-28 17:29:11 +09002762 csc_set_src_buffer(m_exynosVideoCSC,
2763 (void **)(&(selfStreamParms->svcBuffers[index].fd.fd)));
Sungjoong Kang13d8c7b2012-07-14 10:20:39 +09002764
Sungjoong Kang86646da2012-08-28 17:29:11 +09002765 csc_set_dst_buffer(m_exynosVideoCSC,
2766 (void **)(&(selfRecordParms->svcBuffers[selfRecordParms->svcBufIndex].fd.fd)));
Sungjoong Kang13d8c7b2012-07-14 10:20:39 +09002767
Sungjoong Kang86646da2012-08-28 17:29:11 +09002768 if (csc_convert(m_exynosVideoCSC) != 0) {
2769 ALOGE("ERR(%s):csc_convert() fail", __FUNCTION__);
2770 }
2771 else {
2772 ALOGV("(%s):csc_convert() SUCCESS", __FUNCTION__);
2773 }
Sungjoong Kang13d8c7b2012-07-14 10:20:39 +09002774 }
2775 else {
Sungjoong Kang86646da2012-08-28 17:29:11 +09002776 ALOGE("ERR(%s):m_exynosVideoCSC == NULL", __FUNCTION__);
Sungjoong Kang13d8c7b2012-07-14 10:20:39 +09002777 }
Sungjoong Kang13d8c7b2012-07-14 10:20:39 +09002778
Sungjoong Kang86646da2012-08-28 17:29:11 +09002779 res = selfRecordParms->streamOps->enqueue_buffer(selfRecordParms->streamOps,
2780 systemTime(),
2781 &(selfRecordParms->svcBufHandle[selfRecordParms->svcBufIndex]));
2782 ALOGV("DEBUG(%s): stream(%d) record enqueue_buffer to svc done res(%d)", __FUNCTION__,
2783 selfThread->m_index, res);
Sungjoong Kang37e122d2012-08-08 11:13:48 -07002784 if (res == 0) {
Sungjoong Kang86646da2012-08-28 17:29:11 +09002785 selfRecordParms->svcBufStatus[selfRecordParms->svcBufIndex] = ON_SERVICE;
2786 selfRecordParms->numSvcBufsInHal--;
Sungjoong Kangb5237e62012-07-27 07:39:05 -07002787 }
Sungjoong Kangb5237e62012-07-27 07:39:05 -07002788 }
Sungjoong Kang86646da2012-08-28 17:29:11 +09002789 if (m_previewOutput && m_requestManager->GetSkipCnt() <= 0) {
2790
2791 ALOGV("** Display Preview(frameCnt:%d)", m_requestManager->GetFrameIndex());
2792 res = selfStreamParms->streamOps->enqueue_buffer(selfStreamParms->streamOps,
2793 m_requestManager->GetTimestamp(m_requestManager->GetFrameIndex()),
2794 &(selfStreamParms->svcBufHandle[index]));
2795
2796 ALOGV("DEBUG(%s): stream(%d) enqueue_buffer to svc done res(%d)", __FUNCTION__, selfThread->m_index, res);
2797 }
2798 else {
2799 res = selfStreamParms->streamOps->cancel_buffer(selfStreamParms->streamOps,
2800 &(selfStreamParms->svcBufHandle[index]));
2801 ALOGV("DEBUG(%s): stream(%d) cancel_buffer to svc done res(%d)", __FUNCTION__, selfThread->m_index, res);
2802 }
2803 if (res == 0) {
2804 selfStreamParms->svcBufStatus[index] = ON_SERVICE;
2805 selfStreamParms->numSvcBufsInHal--;
2806 }
2807 else {
2808 selfStreamParms->svcBufStatus[index] = ON_HAL;
2809 }
2810
Sungjoong Kang13d8c7b2012-07-14 10:20:39 +09002811 }
Sungjoong Kangb5237e62012-07-27 07:39:05 -07002812 while (0);
2813
Sungjoong Kang86646da2012-08-28 17:29:11 +09002814 if (m_recordOutput && m_recordingEnabled) {
Sungjoong Kang9dd63e12012-07-24 00:25:51 +09002815 do {
Sungjoong Kangbe494d12012-08-04 15:36:56 -07002816 ALOGV("DEBUG(%s): record currentBuf#(%d)", __FUNCTION__ , selfRecordParms->numSvcBufsInHal);
2817 if (selfRecordParms->numSvcBufsInHal >= 1)
Sungjoong Kang9dd63e12012-07-24 00:25:51 +09002818 {
2819 ALOGV("DEBUG(%s): breaking", __FUNCTION__);
2820 break;
2821 }
2822 res = selfRecordParms->streamOps->dequeue_buffer(selfRecordParms->streamOps, &buf);
2823 if (res != NO_ERROR || buf == NULL) {
2824 ALOGV("DEBUG(%s): record stream(%d) dequeue_buffer fail res(%d)",__FUNCTION__ , selfThread->m_index, res);
2825 break;
2826 }
Sungjoong Kangbe494d12012-08-04 15:36:56 -07002827 selfRecordParms->numSvcBufsInHal ++;
Sungjoong Kang9dd63e12012-07-24 00:25:51 +09002828 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 -07002829 selfRecordParms->numSvcBufsInHal, ((native_handle_t*)(*buf))->version, ((native_handle_t*)(*buf))->numFds, ((native_handle_t*)(*buf))->numInts);
Sungjoong Kangad378612012-08-17 12:34:33 -07002830
Sungjoong Kang9dd63e12012-07-24 00:25:51 +09002831 const private_handle_t *priv_handle = reinterpret_cast<const private_handle_t *>(*buf);
Sungjoong Kang9dd63e12012-07-24 00:25:51 +09002832 bool found = false;
2833 int checkingIndex = 0;
2834 for (checkingIndex = 0; checkingIndex < selfRecordParms->numSvcBuffers ; checkingIndex++) {
2835 if (priv_handle->fd == selfRecordParms->svcBuffers[checkingIndex].fd.extFd[0] ) {
2836 found = true;
2837 break;
2838 }
2839 }
2840 ALOGV("DEBUG(%s): recording dequeueed_buffer found index(%d)", __FUNCTION__, found);
Sungjoong Kangad378612012-08-17 12:34:33 -07002841
2842 if (!found) {
2843 break;
2844 }
2845
Sungjoong Kang9dd63e12012-07-24 00:25:51 +09002846 index = checkingIndex;
2847 if (selfRecordParms->svcBufStatus[index] == ON_SERVICE) {
2848 selfRecordParms->svcBufStatus[index] = ON_HAL;
2849 }
2850 else {
2851 ALOGV("DEBUG(%s): record bufstatus abnormal [%d] status = %d", __FUNCTION__,
Sungjoong Kangad378612012-08-17 12:34:33 -07002852 index, selfRecordParms->svcBufStatus[index]);
Sungjoong Kang9dd63e12012-07-24 00:25:51 +09002853 }
2854 } while (0);
2855 }
Sungjoong Kang86646da2012-08-28 17:29:11 +09002856
2857 while (selfStreamParms->numSvcBufsInHal < selfStreamParms->numOwnSvcBuffers) {
2858 res = selfStreamParms->streamOps->dequeue_buffer(selfStreamParms->streamOps, &buf);
2859 if (res != NO_ERROR || buf == NULL) {
2860 ALOGV("DEBUG(%s): stream(%d) dequeue_buffer fail res(%d)",__FUNCTION__ , selfThread->m_index, res);
2861 break;
2862 }
2863 selfStreamParms->numSvcBufsInHal++;
2864 ALOGV("DEBUG(%s): stream(%d) got buf(%x) numInHal(%d) version(%d), numFds(%d), numInts(%d)", __FUNCTION__,
2865 selfThread->m_index, (uint32_t)(*buf), selfStreamParms->numSvcBufsInHal,
2866 ((native_handle_t*)(*buf))->version, ((native_handle_t*)(*buf))->numFds, ((native_handle_t*)(*buf))->numInts);
2867 const private_handle_t *priv_handle = reinterpret_cast<const private_handle_t *>(*buf);
2868
2869 bool found = false;
2870 int checkingIndex = 0;
2871 for (checkingIndex = 0; checkingIndex < selfStreamParms->numSvcBuffers ; checkingIndex++) {
2872 if (priv_handle->fd == selfStreamParms->svcBuffers[checkingIndex].fd.extFd[0] ) {
2873 found = true;
Sungjoong Kang9dd63e12012-07-24 00:25:51 +09002874 break;
2875 }
Sungjoong Kang86646da2012-08-28 17:29:11 +09002876 }
2877 ALOGV("DEBUG(%s): post_dequeue_buffer found(%d)", __FUNCTION__, found);
2878 if (!found) break;
2879 ALOGV("DEBUG(%s): preparing to qbuf [%d]", __FUNCTION__, checkingIndex);
2880 index = checkingIndex;
2881 if (index < selfStreamParms->numHwBuffers) {
2882 uint32_t plane_index = 0;
2883 ExynosBuffer* currentBuf = &(selfStreamParms->svcBuffers[index]);
2884 struct v4l2_buffer v4l2_buf;
2885 struct v4l2_plane planes[VIDEO_MAX_PLANES];
Sungjoong Kang13d8c7b2012-07-14 10:20:39 +09002886
Sungjoong Kang86646da2012-08-28 17:29:11 +09002887 v4l2_buf.m.planes = planes;
2888 v4l2_buf.type = currentNode->type;
2889 v4l2_buf.memory = currentNode->memory;
2890 v4l2_buf.index = index;
2891 v4l2_buf.length = currentNode->planes;
2892
2893 v4l2_buf.m.planes[0].m.fd = priv_handle->fd;
2894 v4l2_buf.m.planes[2].m.fd = priv_handle->fd1;
2895 v4l2_buf.m.planes[1].m.fd = priv_handle->fd2;
2896 for (plane_index=0 ; plane_index < v4l2_buf.length ; plane_index++) {
2897 v4l2_buf.m.planes[plane_index].length = currentBuf->size.extS[plane_index];
2898 ALOGV("DEBUG(%s): plane(%d): fd(%d) length(%d)",
2899 __FUNCTION__, plane_index, v4l2_buf.m.planes[plane_index].m.fd,
2900 v4l2_buf.m.planes[plane_index].length);
Sungjoong Kang9dd63e12012-07-24 00:25:51 +09002901 }
Sungjoong Kang86646da2012-08-28 17:29:11 +09002902 if (exynos_v4l2_qbuf(currentNode->fd, &v4l2_buf) < 0) {
2903 ALOGE("ERR(%s): stream id(%d) exynos_v4l2_qbuf() fail",
2904 __FUNCTION__, selfThread->m_index);
2905 return;
Sungjoong Kang9dd63e12012-07-24 00:25:51 +09002906 }
Sungjoong Kang86646da2012-08-28 17:29:11 +09002907 selfStreamParms->svcBufStatus[index] = ON_DRIVER;
2908 ALOGV("DEBUG(%s): stream id(%d) type0 QBUF done index(%d)",
2909 __FUNCTION__, selfThread->m_index, index);
Sungjoong Kang13d8c7b2012-07-14 10:20:39 +09002910 }
2911 }
Sungjoong Kangbe494d12012-08-04 15:36:56 -07002912
Sungjoong Kang13d8c7b2012-07-14 10:20:39 +09002913 ALOGV("DEBUG(%s): stream(%d) processing SIGNAL_STREAM_DATA_COMING DONE",
2914 __FUNCTION__,selfThread->m_index);
Jiyoung Shinc15a6b02012-06-05 01:08:14 -07002915 }
Sungjoong Kang86646da2012-08-28 17:29:11 +09002916
2917
2918 if (currentSignal & SIGNAL_THREAD_RELEASE) {
2919 int i, index = -1, cnt_to_dq = 0;
2920 status_t res;
2921 ALOGV("DEBUG(%s): processing SIGNAL_THREAD_RELEASE", __FUNCTION__);
2922 ALOGD("(%s):(%d) SIGNAL_THREAD_RELEASE", __FUNCTION__, selfStreamParms->streamType);
2923
2924 if (selfThread->m_isBufferInit) {
2925 for ( i=0 ; i < selfStreamParms->numSvcBuffers; i++) {
2926 ALOGV("DEBUG(%s): checking buffer index[%d] - status(%d)",
2927 __FUNCTION__, i, selfStreamParms->svcBufStatus[i]);
2928 if (selfStreamParms->svcBufStatus[i] ==ON_DRIVER) cnt_to_dq++;
2929 }
2930
2931 ALOGV("DEBUG(%s): calling stream(%d) streamoff (fd:%d)", __FUNCTION__,
2932 selfThread->m_index, selfStreamParms->fd);
2933 if (cam_int_streamoff(&(selfStreamParms->node)) < 0 ){
2934 ALOGE("ERR(%s): stream off fail", __FUNCTION__);
2935 } else {
2936 m_scp_closing = true;
2937 }
2938 ALOGV("DEBUG(%s): calling stream(%d) streamoff done", __FUNCTION__, selfThread->m_index);
2939 ALOGV("DEBUG(%s): calling stream(%d) reqbuf 0 (fd:%d)", __FUNCTION__,
2940 selfThread->m_index, selfStreamParms->fd);
2941 currentNode->buffers = 0;
2942 cam_int_reqbufs(currentNode);
2943 ALOGV("DEBUG(%s): calling stream(%d) reqbuf 0 DONE(fd:%d)", __FUNCTION__,
2944 selfThread->m_index, selfStreamParms->fd);
2945 }
2946 if (selfThread->m_index == 1 && m_resizeBuf.size.s != 0) {
2947 freeCameraMemory(&m_resizeBuf, 1);
2948 }
2949 selfThread->m_isBufferInit = false;
2950 selfThread->m_index = 255;
2951
2952 selfThread->m_releasing = false;
2953
2954 ALOGV("DEBUG(%s): processing SIGNAL_THREAD_RELEASE DONE", __FUNCTION__);
2955
2956 return;
2957 }
2958
2959 return;
2960}
2961
2962void ExynosCameraHWInterface2::m_streamFunc1(SignalDrivenThread *self)
2963{
2964 uint32_t currentSignal = self->GetProcessingSignal();
2965 StreamThread * selfThread = ((StreamThread*)self);
2966 stream_parameters_t *selfStreamParms = &(selfThread->m_parameters);
2967 record_parameters_t *selfRecordParms = &(selfThread->m_recordParameters);
2968 node_info_t *currentNode = &(selfStreamParms->node);
2969
2970 if (currentSignal & SIGNAL_STREAM_CHANGE_PARAMETER) {
2971 ALOGV("DEBUG(%s): processing SIGNAL_STREAM_CHANGE_PARAMETER", __FUNCTION__);
2972
2973 m_resizeBuf.size.extS[0] = ALIGN(selfStreamParms->outputWidth, 16) * ALIGN(selfStreamParms->outputHeight, 16) * 2;
2974 m_resizeBuf.size.extS[1] = 0;
2975 m_resizeBuf.size.extS[2] = 0;
2976
2977 if (allocCameraMemory(selfStreamParms->ionClient, &m_resizeBuf, 1) == -1) {
2978 ALOGE("ERR(%s): Failed to allocate resize buf", __FUNCTION__);
2979 }
2980
2981 ALOGV("DEBUG(%s): processing SIGNAL_STREAM_CHANGE_PARAMETER DONE", __FUNCTION__);
2982 }
2983
2984 if (currentSignal & SIGNAL_STREAM_DATA_COMING) {
2985 buffer_handle_t * buf = NULL;
2986 status_t res;
2987 void *virtAddr[3];
2988 int i, j;
2989 int index;
2990 nsecs_t timestamp;
2991
2992 ALOGV("DEBUG(%s): stream(%d) processing SIGNAL_STREAM_DATA_COMING",
2993 __FUNCTION__,selfThread->m_index);
2994
2995 m_streamBufferInit(self);
2996
2997 do {
2998 ExynosRect jpegRect;
2999 bool found = false;
3000 bool ret = false;
3001 int pictureW, pictureH, pictureFramesize = 0;
3002 int pictureFormat;
3003 int cropX, cropY, cropW, cropH = 0;
3004 ExynosBuffer resizeBufInfo;
3005 ExynosRect m_orgPictureRect;
3006
3007 ALOGD("DEBUG(%s): stream(%d) type(%d) DQBUF START ",__FUNCTION__,
3008 selfThread->m_index, selfStreamParms->streamType);
3009 index = cam_int_dqbuf(&(selfStreamParms->node));
3010 ALOGD("DEBUG(%s): stream(%d) type(%d) DQBUF done index(%d)",__FUNCTION__,
3011 selfThread->m_index, selfStreamParms->streamType, index);
3012
3013
3014 for (int i = 0; i < selfStreamParms->numSvcBuffers ; i++) {
3015 if (selfStreamParms->svcBufStatus[selfStreamParms->svcBufIndex] == ON_HAL) {
3016 found = true;
3017 break;
3018 }
3019 selfStreamParms->svcBufIndex++;
3020 if (selfStreamParms->svcBufIndex >= selfStreamParms->numSvcBuffers)
3021 selfStreamParms->svcBufIndex = 0;
3022 }
3023 if (!found) {
3024 ALOGE("ERR(%s): NO free SVC buffer for JPEG", __FUNCTION__);
3025 break;
3026 }
3027
3028 m_orgPictureRect.w = selfStreamParms->outputWidth;
3029 m_orgPictureRect.h = selfStreamParms->outputHeight;
3030
3031 ExynosBuffer* m_pictureBuf = &(m_camera_info.capture.buffer[index]);
3032
3033 pictureW = selfStreamParms->nodeWidth;
3034 pictureH = selfStreamParms->nodeHeight;
3035 pictureFormat = V4L2_PIX_FMT_YUYV;
3036 pictureFramesize = FRAME_SIZE(V4L2_PIX_2_HAL_PIXEL_FORMAT(pictureFormat), pictureW, pictureH);
3037
3038 if (m_exynosPictureCSC) {
3039 m_getRatioSize(pictureW, pictureH,
3040 m_orgPictureRect.w, m_orgPictureRect.h,
3041 &cropX, &cropY,
3042 &cropW, &cropH,
3043 0);
3044
3045 ALOGV("DEBUG(%s):cropX = %d, cropY = %d, cropW = %d, cropH = %d",
3046 __FUNCTION__, cropX, cropY, cropW, cropH);
3047
3048 csc_set_src_format(m_exynosPictureCSC,
3049 ALIGN(pictureW, 16), ALIGN(pictureH, 16),
3050 cropX, cropY, cropW, cropH,
3051 V4L2_PIX_2_HAL_PIXEL_FORMAT(pictureFormat),
3052 0);
3053
3054 csc_set_dst_format(m_exynosPictureCSC,
3055 m_orgPictureRect.w, m_orgPictureRect.h,
3056 0, 0, m_orgPictureRect.w, m_orgPictureRect.h,
3057 V4L2_PIX_2_HAL_PIXEL_FORMAT(V4L2_PIX_FMT_NV16),
3058 0);
3059 csc_set_src_buffer(m_exynosPictureCSC,
3060 (void **)&m_pictureBuf->fd.fd);
3061
3062 csc_set_dst_buffer(m_exynosPictureCSC,
3063 (void **)&m_resizeBuf.fd.fd);
3064 for (int i = 0 ; i < 3 ; i++)
3065 ALOGV("DEBUG(%s): m_resizeBuf.virt.extP[%d]=%d m_resizeBuf.size.extS[%d]=%d",
3066 __FUNCTION__, i, m_resizeBuf.fd.extFd[i], i, m_resizeBuf.size.extS[i]);
3067
3068 if (csc_convert(m_exynosPictureCSC) != 0)
3069 ALOGE("ERR(%s): csc_convert() fail", __FUNCTION__);
3070
3071
3072 }
3073 else {
3074 ALOGE("ERR(%s): m_exynosPictureCSC == NULL", __FUNCTION__);
3075 }
3076
3077 resizeBufInfo = m_resizeBuf;
3078
3079 m_getAlignedYUVSize(V4L2_PIX_FMT_NV16, m_orgPictureRect.w, m_orgPictureRect.h, &m_resizeBuf);
3080
3081 for (int i = 1; i < 3; i++) {
3082 if (m_resizeBuf.size.extS[i] != 0)
3083 m_resizeBuf.fd.extFd[i] = m_resizeBuf.fd.extFd[i-1] + m_resizeBuf.size.extS[i-1];
3084
3085 ALOGV("(%s): m_resizeBuf.size.extS[%d] = %d", __FUNCTION__, i, m_resizeBuf.size.extS[i]);
3086 }
3087
3088 jpegRect.w = m_orgPictureRect.w;
3089 jpegRect.h = m_orgPictureRect.h;
3090 jpegRect.colorFormat = V4L2_PIX_FMT_NV16;
3091
3092 if (yuv2Jpeg(&m_resizeBuf, &selfStreamParms->svcBuffers[selfStreamParms->svcBufIndex], &jpegRect) == false)
3093 ALOGE("ERR(%s):yuv2Jpeg() fail", __FUNCTION__);
3094 cam_int_qbuf(&(selfStreamParms->node), index);
3095 ALOGV("DEBUG(%s): stream(%d) type(%d) QBUF DONE ",__FUNCTION__,
3096 selfThread->m_index, selfStreamParms->streamType);
3097
3098 m_resizeBuf = resizeBufInfo;
3099
3100 res = selfStreamParms->streamOps->enqueue_buffer(selfStreamParms->streamOps, systemTime(), &(selfStreamParms->svcBufHandle[selfStreamParms->svcBufIndex]));
3101
3102 ALOGV("DEBUG(%s): stream(%d) enqueue_buffer index(%d) to svc done res(%d)",
3103 __FUNCTION__, selfThread->m_index, selfStreamParms->svcBufIndex, res);
3104 if (res == 0) {
3105 selfStreamParms->svcBufStatus[selfStreamParms->svcBufIndex] = ON_SERVICE;
3106 selfStreamParms->numSvcBufsInHal--;
3107 }
3108 else {
3109 selfStreamParms->svcBufStatus[selfStreamParms->svcBufIndex] = ON_HAL;
3110 }
3111 }
3112 while (0);
3113
3114 while (selfStreamParms->numSvcBufsInHal < selfStreamParms->numOwnSvcBuffers) {
3115 res = selfStreamParms->streamOps->dequeue_buffer(selfStreamParms->streamOps, &buf);
3116 if (res != NO_ERROR || buf == NULL) {
3117 ALOGV("DEBUG(%s): stream(%d) dequeue_buffer fail res(%d)",__FUNCTION__ , selfThread->m_index, res);
3118 break;
3119 }
3120
3121 ALOGV("DEBUG(%s): stream(%d) got buf(%x) numInHal(%d) version(%d), numFds(%d), numInts(%d)", __FUNCTION__,
3122 selfThread->m_index, (uint32_t)(*buf), selfStreamParms->numSvcBufsInHal,
3123 ((native_handle_t*)(*buf))->version, ((native_handle_t*)(*buf))->numFds, ((native_handle_t*)(*buf))->numInts);
3124
3125 const private_handle_t *priv_handle = reinterpret_cast<const private_handle_t *>(*buf);
3126
3127 bool found = false;
3128 int checkingIndex = 0;
3129 for (checkingIndex = 0; checkingIndex < selfStreamParms->numSvcBuffers ; checkingIndex++) {
3130 if (priv_handle->fd == selfStreamParms->svcBuffers[checkingIndex].fd.extFd[0] ) {
3131 found = true;
3132 break;
3133 }
3134 }
3135 if (!found) break;
3136 selfStreamParms->svcBufStatus[checkingIndex] = ON_HAL;
3137 selfStreamParms->numSvcBufsInHal++;
3138 }
3139
3140 ALOGV("DEBUG(%s): stream(%d) processing SIGNAL_STREAM_DATA_COMING DONE",
3141 __FUNCTION__,selfThread->m_index);
3142 }
3143
3144 if (currentSignal & SIGNAL_THREAD_RELEASE) {
3145 int i, index = -1, cnt_to_dq = 0;
3146 status_t res;
3147 ALOGV("DEBUG(%s): processing SIGNAL_THREAD_RELEASE", __FUNCTION__);
3148 ALOGD("(%s):(%d) SIGNAL_THREAD_RELEASE", __FUNCTION__, selfStreamParms->streamType);
3149
3150 if (selfThread->m_isBufferInit) {
3151 for ( i=0 ; i < selfStreamParms->numSvcBuffers; i++) {
3152 ALOGV("DEBUG(%s): checking buffer index[%d] - status(%d)",
3153 __FUNCTION__, i, selfStreamParms->svcBufStatus[i]);
3154 if (selfStreamParms->svcBufStatus[i] ==ON_DRIVER) cnt_to_dq++;
3155 }
3156
3157 ALOGV("DEBUG(%s): calling stream(%d) streamoff (fd:%d)", __FUNCTION__,
3158 selfThread->m_index, selfStreamParms->fd);
3159 if (cam_int_streamoff(&(selfStreamParms->node)) < 0 ){
3160 ALOGE("ERR(%s): stream off fail", __FUNCTION__);
3161 } else {
3162 m_camera_info.capture.status = false;
3163 }
3164 ALOGV("DEBUG(%s): calling stream(%d) streamoff done", __FUNCTION__, selfThread->m_index);
3165 ALOGV("DEBUG(%s): calling stream(%d) reqbuf 0 (fd:%d)", __FUNCTION__,
3166 selfThread->m_index, selfStreamParms->fd);
3167 currentNode->buffers = 0;
3168 cam_int_reqbufs(currentNode);
3169 ALOGV("DEBUG(%s): calling stream(%d) reqbuf 0 DONE(fd:%d)", __FUNCTION__,
3170 selfThread->m_index, selfStreamParms->fd);
3171 }
3172 if (selfThread->m_index == 1 && m_resizeBuf.size.s != 0) {
3173 freeCameraMemory(&m_resizeBuf, 1);
3174 }
3175 selfThread->m_isBufferInit = false;
3176 selfThread->m_index = 255;
3177
3178 selfThread->m_releasing = false;
3179
3180 ALOGV("DEBUG(%s): processing SIGNAL_THREAD_RELEASE DONE", __FUNCTION__);
3181
3182 return;
3183 }
3184
3185 return;
3186}
3187
3188
3189void ExynosCameraHWInterface2::m_streamThreadFunc(SignalDrivenThread * self)
3190{
3191 uint32_t currentSignal = self->GetProcessingSignal();
3192 StreamThread * selfThread = ((StreamThread*)self);
3193 stream_parameters_t *selfStreamParms = &(selfThread->m_parameters);
3194 record_parameters_t *selfRecordParms = &(selfThread->m_recordParameters);
3195 node_info_t *currentNode = &(selfStreamParms->node);
3196
3197 ALOGV("DEBUG(%s): m_streamThreadFunc[%d] (%x)", __FUNCTION__, selfThread->m_index, currentSignal);
3198
3199 if (currentSignal & SIGNAL_STREAM_CHANGE_PARAMETER) {
3200 ALOGV("DEBUG(%s): processing SIGNAL_STREAM_CHANGE_PARAMETER", __FUNCTION__);
3201
3202 //Do something in Parent thread handler
3203 selfThread->applyChange();
3204
3205 ALOGV("DEBUG(%s): processing SIGNAL_STREAM_CHANGE_PARAMETER DONE", __FUNCTION__);
3206 }
3207
3208 // Do something in Child thread handler
3209 // Should change function to class that inherited StreamThread class to support dynamic stream allocation
3210 if (selfStreamParms->streamType == STREAM_TYPE_DIRECT)
3211 {
3212 m_streamFunc0(self);
3213 }
3214 else if (selfStreamParms->streamType == STREAM_TYPE_INDIRECT)
3215 {
3216 m_streamFunc1(self);
3217 }
3218
3219 if (currentSignal & SIGNAL_THREAD_RELEASE) {
3220 ALOGV("DEBUG(%s): processing SIGNAL_THREAD_RELEASE", __FUNCTION__);
3221 ALOGD("(%s):(%d) SIGNAL_THREAD_RELEASE", __FUNCTION__, selfStreamParms->streamType);
3222
3223 //Do something in Parent thread handler
3224
3225 ALOGV("DEBUG(%s): processing SIGNAL_THREAD_RELEASE DONE", __FUNCTION__);
3226
3227 return;
3228 }
3229
Jiyoung Shinc15a6b02012-06-05 01:08:14 -07003230 return;
3231}
3232
Sungjoong Kang13d8c7b2012-07-14 10:20:39 +09003233bool ExynosCameraHWInterface2::yuv2Jpeg(ExynosBuffer *yuvBuf,
3234 ExynosBuffer *jpegBuf,
3235 ExynosRect *rect)
Jiyoung Shinc15a6b02012-06-05 01:08:14 -07003236{
Sungjoong Kang13d8c7b2012-07-14 10:20:39 +09003237 unsigned char *addr;
3238
Sungjoong Kangeed7ed12012-08-23 16:35:08 -07003239 int thumbW = 320;
3240 int thumbH = 240;
3241
Sungjoong Kang13d8c7b2012-07-14 10:20:39 +09003242 ExynosJpegEncoderForCamera jpegEnc;
3243 bool ret = false;
3244 int res = 0;
3245
3246 unsigned int *yuvSize = yuvBuf->size.extS;
3247
3248 if (jpegEnc.create()) {
Sungjoong Kang9dd63e12012-07-24 00:25:51 +09003249 ALOGE("ERR(%s):jpegEnc.create() fail", __FUNCTION__);
Sungjoong Kang13d8c7b2012-07-14 10:20:39 +09003250 goto jpeg_encode_done;
3251 }
3252
3253 if (jpegEnc.setQuality(100)) {
Sungjoong Kang9dd63e12012-07-24 00:25:51 +09003254 ALOGE("ERR(%s):jpegEnc.setQuality() fail", __FUNCTION__);
Sungjoong Kang13d8c7b2012-07-14 10:20:39 +09003255 goto jpeg_encode_done;
3256 }
3257
3258 if (jpegEnc.setSize(rect->w, rect->h)) {
Sungjoong Kang9dd63e12012-07-24 00:25:51 +09003259 ALOGE("ERR(%s):jpegEnc.setSize() fail", __FUNCTION__);
Sungjoong Kang13d8c7b2012-07-14 10:20:39 +09003260 goto jpeg_encode_done;
3261 }
3262 ALOGV("%s : width = %d , height = %d\n", __FUNCTION__, rect->w, rect->h);
3263
3264 if (jpegEnc.setColorFormat(rect->colorFormat)) {
Sungjoong Kang9dd63e12012-07-24 00:25:51 +09003265 ALOGE("ERR(%s):jpegEnc.setColorFormat() fail", __FUNCTION__);
Sungjoong Kang13d8c7b2012-07-14 10:20:39 +09003266 goto jpeg_encode_done;
3267 }
Sungjoong Kang13d8c7b2012-07-14 10:20:39 +09003268
3269 if (jpegEnc.setJpegFormat(V4L2_PIX_FMT_JPEG_422)) {
Sungjoong Kang9dd63e12012-07-24 00:25:51 +09003270 ALOGE("ERR(%s):jpegEnc.setJpegFormat() fail", __FUNCTION__);
Sungjoong Kang13d8c7b2012-07-14 10:20:39 +09003271 goto jpeg_encode_done;
3272 }
Sungjoong Kang13d8c7b2012-07-14 10:20:39 +09003273
Sungjoong Kangeed7ed12012-08-23 16:35:08 -07003274 mExifInfo.enableThumb = true;
Sungjoong Kang13d8c7b2012-07-14 10:20:39 +09003275
Sungjoong Kangeed7ed12012-08-23 16:35:08 -07003276 if (jpegEnc.setThumbnailSize(thumbW, thumbH)) {
3277 ALOGE("ERR(%s):jpegEnc.setThumbnailSize(%d, %d) fail", __FUNCTION__, thumbW, thumbH);
3278 goto jpeg_encode_done;
3279 }
3280
3281 ALOGV("(%s):jpegEnc.setThumbnailSize(%d, %d) ", __FUNCTION__, thumbW, thumbH);
3282 if (jpegEnc.setThumbnailQuality(50)) {
3283 ALOGE("ERR(%s):jpegEnc.setThumbnailQuality fail", __FUNCTION__);
3284 goto jpeg_encode_done;
3285 }
3286
3287 m_setExifChangedAttribute(&mExifInfo, rect, &m_jpegMetadata);
Sungjoong Kang9dd63e12012-07-24 00:25:51 +09003288 ALOGV("DEBUG(%s):calling jpegEnc.setInBuf() yuvSize(%d)", __FUNCTION__, *yuvSize);
Sungjoong Kangeed7ed12012-08-23 16:35:08 -07003289 if (jpegEnc.setInBuf((int *)&(yuvBuf->fd.fd), &(yuvBuf->virt.p), (int *)yuvSize)) {
Sungjoong Kang9dd63e12012-07-24 00:25:51 +09003290 ALOGE("ERR(%s):jpegEnc.setInBuf() fail", __FUNCTION__);
Sungjoong Kang13d8c7b2012-07-14 10:20:39 +09003291 goto jpeg_encode_done;
3292 }
Sungjoong Kangeed7ed12012-08-23 16:35:08 -07003293 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 +09003294 ALOGE("ERR(%s):jpegEnc.setOutBuf() fail", __FUNCTION__);
Sungjoong Kang13d8c7b2012-07-14 10:20:39 +09003295 goto jpeg_encode_done;
3296 }
Sungjoong Kang13d8c7b2012-07-14 10:20:39 +09003297
3298 if (jpegEnc.updateConfig()) {
Sungjoong Kang9dd63e12012-07-24 00:25:51 +09003299 ALOGE("ERR(%s):jpegEnc.updateConfig() fail", __FUNCTION__);
Sungjoong Kang13d8c7b2012-07-14 10:20:39 +09003300 goto jpeg_encode_done;
3301 }
3302
Sungjoong Kangeed7ed12012-08-23 16:35:08 -07003303 if (res = jpegEnc.encode((int *)&jpegBuf->size.s, &mExifInfo)) {
Sungjoong Kang9dd63e12012-07-24 00:25:51 +09003304 ALOGE("ERR(%s):jpegEnc.encode() fail ret(%d)", __FUNCTION__, res);
Sungjoong Kang13d8c7b2012-07-14 10:20:39 +09003305 goto jpeg_encode_done;
3306 }
3307
3308 ret = true;
3309
3310jpeg_encode_done:
3311
3312 if (jpegEnc.flagCreate() == true)
3313 jpegEnc.destroy();
3314
3315 return ret;
Jiyoung Shinc15a6b02012-06-05 01:08:14 -07003316}
3317
Sungjoong Kang8e2c2fd2012-08-27 00:02:22 -07003318void ExynosCameraHWInterface2::OnAfTriggerStart(int id)
3319{
3320 m_afPendingTriggerId = id;
3321 m_afModeWaitingCnt = 4;
3322}
Sungjoong Kang13d8c7b2012-07-14 10:20:39 +09003323
Sungjoong Kang0f26b202012-08-17 15:43:12 -07003324void ExynosCameraHWInterface2::OnAfTrigger(int id)
3325{
Sungjoong Kang8e2c2fd2012-08-27 00:02:22 -07003326 m_afTriggerId = id;
Sungjoong Kang0f26b202012-08-17 15:43:12 -07003327 switch (m_afMode) {
3328 case AA_AFMODE_AUTO:
3329 case AA_AFMODE_MACRO:
Sungjoong Kang8e2c2fd2012-08-27 00:02:22 -07003330 case AA_AFMODE_OFF:
Sungjoong Kang0f26b202012-08-17 15:43:12 -07003331 OnAfTriggerAutoMacro(id);
3332 break;
3333 case AA_AFMODE_CONTINUOUS_VIDEO:
3334 OnAfTriggerCAFVideo(id);
3335 break;
3336 case AA_AFMODE_CONTINUOUS_PICTURE:
3337 OnAfTriggerCAFPicture(id);
3338 break;
Sungjoong Kang8e2c2fd2012-08-27 00:02:22 -07003339
Sungjoong Kang0f26b202012-08-17 15:43:12 -07003340 default:
3341 break;
3342 }
3343}
3344
3345void ExynosCameraHWInterface2::OnAfTriggerAutoMacro(int id)
3346{
3347 int nextState = NO_TRANSITION;
Sungjoong Kang0f26b202012-08-17 15:43:12 -07003348
3349 switch (m_afState) {
3350 case HAL_AFSTATE_INACTIVE:
3351 nextState = HAL_AFSTATE_NEEDS_COMMAND;
3352 m_IsAfTriggerRequired = true;
3353 break;
3354 case HAL_AFSTATE_NEEDS_COMMAND:
3355 nextState = NO_TRANSITION;
3356 break;
3357 case HAL_AFSTATE_STARTED:
3358 nextState = NO_TRANSITION;
3359 break;
3360 case HAL_AFSTATE_SCANNING:
3361 nextState = NO_TRANSITION;
3362 break;
3363 case HAL_AFSTATE_LOCKED:
3364 nextState = HAL_AFSTATE_NEEDS_COMMAND;
3365 m_IsAfTriggerRequired = true;
3366 break;
3367 case HAL_AFSTATE_FAILED:
3368 nextState = HAL_AFSTATE_NEEDS_COMMAND;
3369 m_IsAfTriggerRequired = true;
3370 break;
3371 default:
3372 break;
3373 }
3374 ALOGV("(%s): State (%d) -> (%d)", __FUNCTION__, m_afState, nextState);
3375 if (nextState != NO_TRANSITION)
3376 m_afState = nextState;
3377}
3378
3379void ExynosCameraHWInterface2::OnAfTriggerCAFPicture(int id)
3380{
3381 int nextState = NO_TRANSITION;
Sungjoong Kang0f26b202012-08-17 15:43:12 -07003382
3383 switch (m_afState) {
3384 case HAL_AFSTATE_INACTIVE:
3385 nextState = HAL_AFSTATE_FAILED;
3386 SetAfStateForService(ANDROID_CONTROL_AF_STATE_NOT_FOCUSED_LOCKED);
3387 break;
3388 case HAL_AFSTATE_NEEDS_COMMAND:
3389 // not used
3390 break;
3391 case HAL_AFSTATE_STARTED:
3392 nextState = HAL_AFSTATE_NEEDS_DETERMINATION;
Sungjoong Kang36c106c2012-08-23 17:38:20 -07003393 m_AfHwStateFailed = false;
Sungjoong Kang0f26b202012-08-17 15:43:12 -07003394 break;
3395 case HAL_AFSTATE_SCANNING:
3396 nextState = HAL_AFSTATE_NEEDS_DETERMINATION;
Sungjoong Kang36c106c2012-08-23 17:38:20 -07003397 m_AfHwStateFailed = false;
Sungjoong Kang0f26b202012-08-17 15:43:12 -07003398 break;
3399 case HAL_AFSTATE_NEEDS_DETERMINATION:
3400 nextState = NO_TRANSITION;
3401 break;
3402 case HAL_AFSTATE_PASSIVE_FOCUSED:
3403 m_IsAfLockRequired = true;
Sungjoong Kang36c106c2012-08-23 17:38:20 -07003404 if (m_AfHwStateFailed) {
3405 ALOGV("(%s): LAST : fail", __FUNCTION__);
3406 SetAfStateForService(ANDROID_CONTROL_AF_STATE_NOT_FOCUSED_LOCKED);
3407 nextState = HAL_AFSTATE_FAILED;
3408 }
3409 else {
3410 ALOGV("(%s): LAST : success", __FUNCTION__);
3411 SetAfStateForService(ANDROID_CONTROL_AF_STATE_FOCUSED_LOCKED);
3412 nextState = HAL_AFSTATE_LOCKED;
3413 }
3414 m_AfHwStateFailed = false;
Sungjoong Kang0f26b202012-08-17 15:43:12 -07003415 break;
3416 case HAL_AFSTATE_LOCKED:
3417 nextState = NO_TRANSITION;
3418 break;
3419 case HAL_AFSTATE_FAILED:
3420 nextState = NO_TRANSITION;
3421 break;
3422 default:
3423 break;
3424 }
3425 ALOGV("(%s): State (%d) -> (%d)", __FUNCTION__, m_afState, nextState);
3426 if (nextState != NO_TRANSITION)
3427 m_afState = nextState;
3428}
3429
3430
3431void ExynosCameraHWInterface2::OnAfTriggerCAFVideo(int id)
3432{
3433 int nextState = NO_TRANSITION;
Sungjoong Kang0f26b202012-08-17 15:43:12 -07003434
3435 switch (m_afState) {
3436 case HAL_AFSTATE_INACTIVE:
3437 nextState = HAL_AFSTATE_FAILED;
3438 SetAfStateForService(ANDROID_CONTROL_AF_STATE_NOT_FOCUSED_LOCKED);
3439 break;
3440 case HAL_AFSTATE_NEEDS_COMMAND:
3441 // not used
3442 break;
3443 case HAL_AFSTATE_STARTED:
3444 m_IsAfLockRequired = true;
3445 nextState = HAL_AFSTATE_FAILED;
3446 SetAfStateForService(ANDROID_CONTROL_AF_STATE_NOT_FOCUSED_LOCKED);
3447 break;
3448 case HAL_AFSTATE_SCANNING:
3449 m_IsAfLockRequired = true;
3450 nextState = HAL_AFSTATE_FAILED;
3451 SetAfStateForService(ANDROID_CONTROL_AF_STATE_NOT_FOCUSED_LOCKED);
3452 break;
3453 case HAL_AFSTATE_NEEDS_DETERMINATION:
3454 // not used
3455 break;
3456 case HAL_AFSTATE_PASSIVE_FOCUSED:
3457 m_IsAfLockRequired = true;
3458 SetAfStateForService(ANDROID_CONTROL_AF_STATE_FOCUSED_LOCKED);
3459 nextState = HAL_AFSTATE_LOCKED;
3460 break;
3461 case HAL_AFSTATE_LOCKED:
3462 nextState = NO_TRANSITION;
3463 break;
3464 case HAL_AFSTATE_FAILED:
3465 nextState = NO_TRANSITION;
3466 break;
3467 default:
3468 break;
3469 }
3470 ALOGV("(%s): State (%d) -> (%d)", __FUNCTION__, m_afState, nextState);
3471 if (nextState != NO_TRANSITION)
3472 m_afState = nextState;
3473}
3474
3475void ExynosCameraHWInterface2::OnAfNotification(enum aa_afstate noti)
3476{
3477 switch (m_afMode) {
3478 case AA_AFMODE_AUTO:
3479 case AA_AFMODE_MACRO:
3480 OnAfNotificationAutoMacro(noti);
3481 break;
3482 case AA_AFMODE_CONTINUOUS_VIDEO:
3483 OnAfNotificationCAFVideo(noti);
3484 break;
3485 case AA_AFMODE_CONTINUOUS_PICTURE:
3486 OnAfNotificationCAFPicture(noti);
3487 break;
3488 case AA_AFMODE_OFF:
3489 default:
3490 break;
3491 }
3492}
3493
3494void ExynosCameraHWInterface2::OnAfNotificationAutoMacro(enum aa_afstate noti)
3495{
3496 int nextState = NO_TRANSITION;
3497 bool bWrongTransition = false;
3498
3499 if (m_afState == HAL_AFSTATE_INACTIVE || m_afState == HAL_AFSTATE_NEEDS_COMMAND) {
3500 switch (noti) {
3501 case AA_AFSTATE_INACTIVE:
3502 case AA_AFSTATE_ACTIVE_SCAN:
3503 case AA_AFSTATE_AF_ACQUIRED_FOCUS:
3504 case AA_AFSTATE_AF_FAILED_FOCUS:
3505 default:
3506 nextState = NO_TRANSITION;
3507 break;
3508 }
3509 }
3510 else if (m_afState == HAL_AFSTATE_STARTED) {
3511 switch (noti) {
3512 case AA_AFSTATE_INACTIVE:
3513 nextState = NO_TRANSITION;
3514 break;
3515 case AA_AFSTATE_ACTIVE_SCAN:
3516 nextState = HAL_AFSTATE_SCANNING;
3517 SetAfStateForService(ANDROID_CONTROL_AF_STATE_ACTIVE_SCAN);
3518 break;
3519 case AA_AFSTATE_AF_ACQUIRED_FOCUS:
3520 nextState = NO_TRANSITION;
3521 break;
3522 case AA_AFSTATE_AF_FAILED_FOCUS:
3523 nextState = NO_TRANSITION;
3524 break;
3525 default:
3526 bWrongTransition = true;
3527 break;
3528 }
3529 }
3530 else if (m_afState == HAL_AFSTATE_SCANNING) {
3531 switch (noti) {
3532 case AA_AFSTATE_INACTIVE:
3533 bWrongTransition = true;
3534 break;
3535 case AA_AFSTATE_ACTIVE_SCAN:
3536 nextState = NO_TRANSITION;
3537 break;
3538 case AA_AFSTATE_AF_ACQUIRED_FOCUS:
3539 nextState = HAL_AFSTATE_LOCKED;
3540 SetAfStateForService(ANDROID_CONTROL_AF_STATE_FOCUSED_LOCKED);
3541 break;
3542 case AA_AFSTATE_AF_FAILED_FOCUS:
3543 nextState = HAL_AFSTATE_FAILED;
3544 SetAfStateForService(ANDROID_CONTROL_AF_STATE_NOT_FOCUSED_LOCKED);
3545 break;
3546 default:
3547 bWrongTransition = true;
3548 break;
3549 }
3550 }
3551 else if (m_afState == HAL_AFSTATE_LOCKED) {
3552 switch (noti) {
3553 case AA_AFSTATE_INACTIVE:
3554 case AA_AFSTATE_ACTIVE_SCAN:
3555 bWrongTransition = true;
3556 break;
3557 case AA_AFSTATE_AF_ACQUIRED_FOCUS:
3558 nextState = NO_TRANSITION;
3559 break;
3560 case AA_AFSTATE_AF_FAILED_FOCUS:
3561 default:
3562 bWrongTransition = true;
3563 break;
3564 }
3565 }
3566 else if (m_afState == HAL_AFSTATE_FAILED) {
3567 switch (noti) {
3568 case AA_AFSTATE_INACTIVE:
3569 case AA_AFSTATE_ACTIVE_SCAN:
3570 case AA_AFSTATE_AF_ACQUIRED_FOCUS:
3571 bWrongTransition = true;
3572 break;
3573 case AA_AFSTATE_AF_FAILED_FOCUS:
3574 nextState = NO_TRANSITION;
3575 break;
3576 default:
3577 bWrongTransition = true;
3578 break;
3579 }
3580 }
3581 if (bWrongTransition) {
3582 ALOGV("(%s): Wrong Transition state(%d) noti(%d)", __FUNCTION__, m_afState, noti);
3583 return;
3584 }
3585 ALOGV("(%s): State (%d) -> (%d) by (%d)", __FUNCTION__, m_afState, nextState, noti);
3586 if (nextState != NO_TRANSITION)
3587 m_afState = nextState;
3588}
3589
3590void ExynosCameraHWInterface2::OnAfNotificationCAFPicture(enum aa_afstate noti)
3591{
3592 int nextState = NO_TRANSITION;
3593 bool bWrongTransition = false;
3594
3595 if (m_afState == HAL_AFSTATE_INACTIVE) {
3596 switch (noti) {
3597 case AA_AFSTATE_INACTIVE:
3598 case AA_AFSTATE_ACTIVE_SCAN:
3599 case AA_AFSTATE_AF_ACQUIRED_FOCUS:
3600 case AA_AFSTATE_AF_FAILED_FOCUS:
3601 default:
3602 nextState = NO_TRANSITION;
3603 break;
3604 }
3605 }
3606 else if (m_afState == HAL_AFSTATE_STARTED) {
3607 switch (noti) {
3608 case AA_AFSTATE_INACTIVE:
3609 nextState = NO_TRANSITION;
3610 break;
3611 case AA_AFSTATE_ACTIVE_SCAN:
3612 nextState = HAL_AFSTATE_SCANNING;
3613 SetAfStateForService(ANDROID_CONTROL_AF_STATE_PASSIVE_SCAN);
3614 break;
3615 case AA_AFSTATE_AF_ACQUIRED_FOCUS:
3616 nextState = HAL_AFSTATE_PASSIVE_FOCUSED;
3617 SetAfStateForService(ANDROID_CONTROL_AF_STATE_PASSIVE_FOCUSED);
3618 break;
3619 case AA_AFSTATE_AF_FAILED_FOCUS:
3620 nextState = HAL_AFSTATE_FAILED;
3621 SetAfStateForService(ANDROID_CONTROL_AF_STATE_NOT_FOCUSED_LOCKED);
3622 break;
3623 default:
3624 bWrongTransition = true;
3625 break;
3626 }
3627 }
3628 else if (m_afState == HAL_AFSTATE_SCANNING) {
3629 switch (noti) {
3630 case AA_AFSTATE_INACTIVE:
Sungjoong Kang36c106c2012-08-23 17:38:20 -07003631 nextState = NO_TRANSITION;
Sungjoong Kang0f26b202012-08-17 15:43:12 -07003632 break;
3633 case AA_AFSTATE_ACTIVE_SCAN:
3634 nextState = NO_TRANSITION;
Sungjoong Kang36c106c2012-08-23 17:38:20 -07003635 m_AfHwStateFailed = false;
Sungjoong Kang0f26b202012-08-17 15:43:12 -07003636 break;
3637 case AA_AFSTATE_AF_ACQUIRED_FOCUS:
3638 nextState = HAL_AFSTATE_PASSIVE_FOCUSED;
Sungjoong Kang36c106c2012-08-23 17:38:20 -07003639 m_AfHwStateFailed = false;
Sungjoong Kang0f26b202012-08-17 15:43:12 -07003640 SetAfStateForService(ANDROID_CONTROL_AF_STATE_PASSIVE_FOCUSED);
3641 break;
3642 case AA_AFSTATE_AF_FAILED_FOCUS:
Sungjoong Kang36c106c2012-08-23 17:38:20 -07003643 nextState = HAL_AFSTATE_PASSIVE_FOCUSED;
3644 m_AfHwStateFailed = true;
3645 SetAfStateForService(ANDROID_CONTROL_AF_STATE_PASSIVE_FOCUSED);
Sungjoong Kang0f26b202012-08-17 15:43:12 -07003646 break;
3647 default:
3648 bWrongTransition = true;
3649 break;
3650 }
3651 }
3652 else if (m_afState == HAL_AFSTATE_PASSIVE_FOCUSED) {
3653 switch (noti) {
3654 case AA_AFSTATE_INACTIVE:
Sungjoong Kang36c106c2012-08-23 17:38:20 -07003655 nextState = NO_TRANSITION;
Sungjoong Kang0f26b202012-08-17 15:43:12 -07003656 break;
3657 case AA_AFSTATE_ACTIVE_SCAN:
3658 nextState = HAL_AFSTATE_SCANNING;
Sungjoong Kang36c106c2012-08-23 17:38:20 -07003659 m_AfHwStateFailed = false;
Sungjoong Kang0f26b202012-08-17 15:43:12 -07003660 SetAfStateForService(ANDROID_CONTROL_AF_STATE_PASSIVE_SCAN);
3661 break;
3662 case AA_AFSTATE_AF_ACQUIRED_FOCUS:
3663 nextState = NO_TRANSITION;
Sungjoong Kang36c106c2012-08-23 17:38:20 -07003664 m_AfHwStateFailed = false;
Sungjoong Kang0f26b202012-08-17 15:43:12 -07003665 break;
3666 case AA_AFSTATE_AF_FAILED_FOCUS:
Sungjoong Kang36c106c2012-08-23 17:38:20 -07003667 nextState = NO_TRANSITION;
3668 m_AfHwStateFailed = true;
Sungjoong Kang0f26b202012-08-17 15:43:12 -07003669 break;
3670 default:
3671 bWrongTransition = true;
3672 break;
3673 }
3674 }
3675 else if (m_afState == HAL_AFSTATE_NEEDS_DETERMINATION) {
3676 switch (noti) {
3677 case AA_AFSTATE_INACTIVE:
Sungjoong Kang36c106c2012-08-23 17:38:20 -07003678 nextState = NO_TRANSITION;
Sungjoong Kang0f26b202012-08-17 15:43:12 -07003679 break;
3680 case AA_AFSTATE_ACTIVE_SCAN:
3681 nextState = NO_TRANSITION;
3682 break;
3683 case AA_AFSTATE_AF_ACQUIRED_FOCUS:
3684 m_IsAfLockRequired = true;
3685 nextState = HAL_AFSTATE_LOCKED;
3686 SetAfStateForService(ANDROID_CONTROL_AF_STATE_FOCUSED_LOCKED);
3687 break;
3688 case AA_AFSTATE_AF_FAILED_FOCUS:
3689 m_IsAfLockRequired = true;
3690 nextState = HAL_AFSTATE_FAILED;
3691 SetAfStateForService(ANDROID_CONTROL_AF_STATE_NOT_FOCUSED_LOCKED);
3692 break;
3693 default:
3694 bWrongTransition = true;
3695 break;
3696 }
3697 }
3698 else if (m_afState == HAL_AFSTATE_LOCKED) {
3699 switch (noti) {
3700 case AA_AFSTATE_INACTIVE:
3701 nextState = NO_TRANSITION;
3702 break;
3703 case AA_AFSTATE_ACTIVE_SCAN:
3704 bWrongTransition = true;
3705 break;
3706 case AA_AFSTATE_AF_ACQUIRED_FOCUS:
3707 nextState = NO_TRANSITION;
3708 break;
3709 case AA_AFSTATE_AF_FAILED_FOCUS:
3710 default:
3711 bWrongTransition = true;
3712 break;
3713 }
3714 }
3715 else if (m_afState == HAL_AFSTATE_FAILED) {
3716 switch (noti) {
3717 case AA_AFSTATE_INACTIVE:
Sungjoong Kang36c106c2012-08-23 17:38:20 -07003718 bWrongTransition = true;
3719 break;
Sungjoong Kang0f26b202012-08-17 15:43:12 -07003720 case AA_AFSTATE_ACTIVE_SCAN:
Sungjoong Kang36c106c2012-08-23 17:38:20 -07003721 nextState = HAL_AFSTATE_SCANNING;
3722 break;
Sungjoong Kang0f26b202012-08-17 15:43:12 -07003723 case AA_AFSTATE_AF_ACQUIRED_FOCUS:
3724 bWrongTransition = true;
3725 break;
3726 case AA_AFSTATE_AF_FAILED_FOCUS:
3727 nextState = NO_TRANSITION;
3728 break;
3729 default:
3730 bWrongTransition = true;
3731 break;
3732 }
3733 }
3734 if (bWrongTransition) {
3735 ALOGV("(%s): Wrong Transition state(%d) noti(%d)", __FUNCTION__, m_afState, noti);
3736 return;
3737 }
3738 ALOGV("(%s): State (%d) -> (%d) by (%d)", __FUNCTION__, m_afState, nextState, noti);
3739 if (nextState != NO_TRANSITION)
3740 m_afState = nextState;
3741}
3742
3743void ExynosCameraHWInterface2::OnAfNotificationCAFVideo(enum aa_afstate noti)
3744{
3745 int nextState = NO_TRANSITION;
3746 bool bWrongTransition = false;
3747
3748 if (m_afState == HAL_AFSTATE_INACTIVE) {
3749 switch (noti) {
3750 case AA_AFSTATE_INACTIVE:
3751 case AA_AFSTATE_ACTIVE_SCAN:
3752 case AA_AFSTATE_AF_ACQUIRED_FOCUS:
3753 case AA_AFSTATE_AF_FAILED_FOCUS:
3754 default:
3755 nextState = NO_TRANSITION;
3756 break;
3757 }
3758 }
3759 else if (m_afState == HAL_AFSTATE_STARTED) {
3760 switch (noti) {
3761 case AA_AFSTATE_INACTIVE:
3762 nextState = NO_TRANSITION;
3763 break;
3764 case AA_AFSTATE_ACTIVE_SCAN:
3765 nextState = HAL_AFSTATE_SCANNING;
3766 SetAfStateForService(ANDROID_CONTROL_AF_STATE_PASSIVE_SCAN);
3767 break;
3768 case AA_AFSTATE_AF_ACQUIRED_FOCUS:
3769 nextState = HAL_AFSTATE_PASSIVE_FOCUSED;
3770 SetAfStateForService(ANDROID_CONTROL_AF_STATE_PASSIVE_FOCUSED);
3771 break;
3772 case AA_AFSTATE_AF_FAILED_FOCUS:
3773 nextState = HAL_AFSTATE_FAILED;
3774 SetAfStateForService(ANDROID_CONTROL_AF_STATE_NOT_FOCUSED_LOCKED);
3775 break;
3776 default:
3777 bWrongTransition = true;
3778 break;
3779 }
3780 }
3781 else if (m_afState == HAL_AFSTATE_SCANNING) {
3782 switch (noti) {
3783 case AA_AFSTATE_INACTIVE:
3784 bWrongTransition = true;
3785 break;
3786 case AA_AFSTATE_ACTIVE_SCAN:
3787 nextState = NO_TRANSITION;
3788 break;
3789 case AA_AFSTATE_AF_ACQUIRED_FOCUS:
3790 nextState = HAL_AFSTATE_PASSIVE_FOCUSED;
3791 SetAfStateForService(ANDROID_CONTROL_AF_STATE_PASSIVE_FOCUSED);
3792 break;
3793 case AA_AFSTATE_AF_FAILED_FOCUS:
3794 nextState = NO_TRANSITION;
Sungjoong Kang36c106c2012-08-23 17:38:20 -07003795 m_IsAfTriggerRequired = true;
Sungjoong Kang0f26b202012-08-17 15:43:12 -07003796 break;
3797 default:
3798 bWrongTransition = true;
3799 break;
3800 }
3801 }
3802 else if (m_afState == HAL_AFSTATE_PASSIVE_FOCUSED) {
3803 switch (noti) {
3804 case AA_AFSTATE_INACTIVE:
3805 bWrongTransition = true;
3806 break;
3807 case AA_AFSTATE_ACTIVE_SCAN:
3808 nextState = HAL_AFSTATE_SCANNING;
3809 SetAfStateForService(ANDROID_CONTROL_AF_STATE_PASSIVE_SCAN);
3810 break;
3811 case AA_AFSTATE_AF_ACQUIRED_FOCUS:
3812 nextState = NO_TRANSITION;
3813 break;
3814 case AA_AFSTATE_AF_FAILED_FOCUS:
3815 nextState = HAL_AFSTATE_FAILED;
3816 SetAfStateForService(ANDROID_CONTROL_AF_STATE_NOT_FOCUSED_LOCKED);
Sungjoong Kang8e2c2fd2012-08-27 00:02:22 -07003817 // TODO : needs NO_TRANSITION ?
Sungjoong Kang0f26b202012-08-17 15:43:12 -07003818 break;
3819 default:
3820 bWrongTransition = true;
3821 break;
3822 }
3823 }
3824 else if (m_afState == HAL_AFSTATE_NEEDS_DETERMINATION) {
3825 switch (noti) {
3826 case AA_AFSTATE_INACTIVE:
3827 bWrongTransition = true;
3828 break;
3829 case AA_AFSTATE_ACTIVE_SCAN:
3830 nextState = NO_TRANSITION;
3831 break;
3832 case AA_AFSTATE_AF_ACQUIRED_FOCUS:
3833 m_IsAfLockRequired = true;
3834 nextState = HAL_AFSTATE_LOCKED;
3835 SetAfStateForService(ANDROID_CONTROL_AF_STATE_FOCUSED_LOCKED);
3836 break;
3837 case AA_AFSTATE_AF_FAILED_FOCUS:
3838 nextState = HAL_AFSTATE_FAILED;
3839 SetAfStateForService(ANDROID_CONTROL_AF_STATE_NOT_FOCUSED_LOCKED);
3840 break;
3841 default:
3842 bWrongTransition = true;
3843 break;
3844 }
3845 }
3846 else if (m_afState == HAL_AFSTATE_LOCKED) {
3847 switch (noti) {
3848 case AA_AFSTATE_INACTIVE:
3849 nextState = NO_TRANSITION;
3850 break;
3851 case AA_AFSTATE_ACTIVE_SCAN:
3852 bWrongTransition = true;
3853 break;
3854 case AA_AFSTATE_AF_ACQUIRED_FOCUS:
3855 nextState = NO_TRANSITION;
3856 break;
3857 case AA_AFSTATE_AF_FAILED_FOCUS:
3858 default:
3859 bWrongTransition = true;
3860 break;
3861 }
3862 }
3863 else if (m_afState == HAL_AFSTATE_FAILED) {
3864 switch (noti) {
3865 case AA_AFSTATE_INACTIVE:
3866 case AA_AFSTATE_ACTIVE_SCAN:
3867 case AA_AFSTATE_AF_ACQUIRED_FOCUS:
3868 bWrongTransition = true;
3869 break;
3870 case AA_AFSTATE_AF_FAILED_FOCUS:
3871 nextState = NO_TRANSITION;
3872 break;
3873 default:
3874 bWrongTransition = true;
3875 break;
3876 }
3877 }
3878 if (bWrongTransition) {
3879 ALOGV("(%s): Wrong Transition state(%d) noti(%d)", __FUNCTION__, m_afState, noti);
3880 return;
3881 }
3882 ALOGV("(%s): State (%d) -> (%d) by (%d)", __FUNCTION__, m_afState, nextState, noti);
3883 if (nextState != NO_TRANSITION)
3884 m_afState = nextState;
3885}
3886
3887void ExynosCameraHWInterface2::OnAfCancel(int id)
3888{
Sungjoong Kang8e2c2fd2012-08-27 00:02:22 -07003889 m_afTriggerId = id;
3890
Sungjoong Kang0f26b202012-08-17 15:43:12 -07003891 switch (m_afMode) {
3892 case AA_AFMODE_AUTO:
3893 case AA_AFMODE_MACRO:
Sungjoong Kang8e2c2fd2012-08-27 00:02:22 -07003894 case AA_AFMODE_OFF:
Sungjoong Kang0f26b202012-08-17 15:43:12 -07003895 OnAfCancelAutoMacro(id);
3896 break;
3897 case AA_AFMODE_CONTINUOUS_VIDEO:
3898 OnAfCancelCAFVideo(id);
3899 break;
3900 case AA_AFMODE_CONTINUOUS_PICTURE:
3901 OnAfCancelCAFPicture(id);
3902 break;
Sungjoong Kang0f26b202012-08-17 15:43:12 -07003903 default:
3904 break;
3905 }
3906}
3907
3908void ExynosCameraHWInterface2::OnAfCancelAutoMacro(int id)
3909{
3910 int nextState = NO_TRANSITION;
3911 m_afTriggerId = id;
3912
3913 switch (m_afState) {
3914 case HAL_AFSTATE_INACTIVE:
3915 nextState = NO_TRANSITION;
3916 break;
3917 case HAL_AFSTATE_NEEDS_COMMAND:
3918 case HAL_AFSTATE_STARTED:
3919 case HAL_AFSTATE_SCANNING:
3920 case HAL_AFSTATE_LOCKED:
3921 case HAL_AFSTATE_FAILED:
3922 SetAfMode(AA_AFMODE_OFF);
3923 SetAfStateForService(ANDROID_CONTROL_AF_STATE_INACTIVE);
3924 nextState = HAL_AFSTATE_INACTIVE;
3925 break;
3926 default:
3927 break;
3928 }
3929 ALOGV("(%s): State (%d) -> (%d)", __FUNCTION__, m_afState, nextState);
3930 if (nextState != NO_TRANSITION)
3931 m_afState = nextState;
3932}
3933
3934void ExynosCameraHWInterface2::OnAfCancelCAFPicture(int id)
3935{
3936 int nextState = NO_TRANSITION;
3937 m_afTriggerId = id;
3938
3939 switch (m_afState) {
3940 case HAL_AFSTATE_INACTIVE:
3941 nextState = NO_TRANSITION;
3942 break;
3943 case HAL_AFSTATE_NEEDS_COMMAND:
3944 case HAL_AFSTATE_STARTED:
3945 case HAL_AFSTATE_SCANNING:
3946 case HAL_AFSTATE_LOCKED:
3947 case HAL_AFSTATE_FAILED:
3948 case HAL_AFSTATE_NEEDS_DETERMINATION:
3949 case HAL_AFSTATE_PASSIVE_FOCUSED:
3950 SetAfMode(AA_AFMODE_OFF);
3951 SetAfStateForService(ANDROID_CONTROL_AF_STATE_INACTIVE);
3952 SetAfMode(AA_AFMODE_CONTINUOUS_PICTURE);
3953 nextState = HAL_AFSTATE_INACTIVE;
3954 break;
3955 default:
3956 break;
3957 }
3958 ALOGV("(%s): State (%d) -> (%d)", __FUNCTION__, m_afState, nextState);
3959 if (nextState != NO_TRANSITION)
3960 m_afState = nextState;
3961}
3962
3963void ExynosCameraHWInterface2::OnAfCancelCAFVideo(int id)
3964{
3965 int nextState = NO_TRANSITION;
3966 m_afTriggerId = id;
3967
3968 switch (m_afState) {
3969 case HAL_AFSTATE_INACTIVE:
3970 nextState = NO_TRANSITION;
3971 break;
3972 case HAL_AFSTATE_NEEDS_COMMAND:
3973 case HAL_AFSTATE_STARTED:
3974 case HAL_AFSTATE_SCANNING:
3975 case HAL_AFSTATE_LOCKED:
3976 case HAL_AFSTATE_FAILED:
3977 case HAL_AFSTATE_NEEDS_DETERMINATION:
3978 case HAL_AFSTATE_PASSIVE_FOCUSED:
3979 SetAfMode(AA_AFMODE_OFF);
3980 SetAfStateForService(ANDROID_CONTROL_AF_STATE_INACTIVE);
3981 SetAfMode(AA_AFMODE_CONTINUOUS_VIDEO);
3982 nextState = HAL_AFSTATE_INACTIVE;
3983 break;
3984 default:
3985 break;
3986 }
3987 ALOGV("(%s): State (%d) -> (%d)", __FUNCTION__, m_afState, nextState);
3988 if (nextState != NO_TRANSITION)
3989 m_afState = nextState;
3990}
3991
3992void ExynosCameraHWInterface2::SetAfStateForService(int newState)
3993{
Sungjoong Kang8e2c2fd2012-08-27 00:02:22 -07003994 if (m_serviceAfState != newState || newState == 0)
3995 m_notifyCb(CAMERA2_MSG_AUTOFOCUS, newState, m_afTriggerId, 0, m_callbackCookie);
Sungjoong Kang0f26b202012-08-17 15:43:12 -07003996 m_serviceAfState = newState;
Sungjoong Kang0f26b202012-08-17 15:43:12 -07003997}
3998
3999int ExynosCameraHWInterface2::GetAfStateForService()
4000{
4001 return m_serviceAfState;
4002}
4003
4004void ExynosCameraHWInterface2::SetAfMode(enum aa_afmode afMode)
4005{
4006 if (m_afMode != afMode) {
4007 if (m_IsAfModeUpdateRequired) {
4008 m_afMode2 = afMode;
4009 ALOGV("(%s): pending(%d) and new(%d)", __FUNCTION__, m_afMode, afMode);
4010 }
4011 else {
4012 ALOGV("(%s): current(%d) new(%d)", __FUNCTION__, m_afMode, afMode);
4013 m_IsAfModeUpdateRequired = true;
4014 m_afMode = afMode;
4015 }
Sungjoong Kang8e2c2fd2012-08-27 00:02:22 -07004016 if (m_afModeWaitingCnt != 0) {
4017 m_afModeWaitingCnt = 0;
4018 OnAfTrigger(m_afPendingTriggerId);
4019 }
Sungjoong Kang0f26b202012-08-17 15:43:12 -07004020 }
4021}
4022
Sungjoong Kangeed7ed12012-08-23 16:35:08 -07004023void ExynosCameraHWInterface2::m_setExifFixedAttribute(void)
4024{
4025 char property[PROPERTY_VALUE_MAX];
4026
4027 //2 0th IFD TIFF Tags
Alex Ray5a92f772012-08-27 17:23:41 -07004028#if 0 // STOPSHIP TODO(aray): remove before launch, but for now don't leak product data
Sungjoong Kangeed7ed12012-08-23 16:35:08 -07004029 //3 Maker
4030 property_get("ro.product.brand", property, EXIF_DEF_MAKER);
4031 strncpy((char *)mExifInfo.maker, property,
4032 sizeof(mExifInfo.maker) - 1);
4033 mExifInfo.maker[sizeof(mExifInfo.maker) - 1] = '\0';
4034 //3 Model
4035 property_get("ro.product.model", property, EXIF_DEF_MODEL);
4036 strncpy((char *)mExifInfo.model, property,
4037 sizeof(mExifInfo.model) - 1);
4038 mExifInfo.model[sizeof(mExifInfo.model) - 1] = '\0';
4039 //3 Software
4040 property_get("ro.build.id", property, EXIF_DEF_SOFTWARE);
4041 strncpy((char *)mExifInfo.software, property,
4042 sizeof(mExifInfo.software) - 1);
4043 mExifInfo.software[sizeof(mExifInfo.software) - 1] = '\0';
Alex Ray5a92f772012-08-27 17:23:41 -07004044#endif
Sungjoong Kangeed7ed12012-08-23 16:35:08 -07004045
4046 //3 YCbCr Positioning
4047 mExifInfo.ycbcr_positioning = EXIF_DEF_YCBCR_POSITIONING;
4048
4049 //2 0th IFD Exif Private Tags
4050 //3 F Number
4051 mExifInfo.fnumber.num = EXIF_DEF_FNUMBER_NUM;
4052 mExifInfo.fnumber.den = EXIF_DEF_FNUMBER_DEN;
4053 //3 Exposure Program
4054 mExifInfo.exposure_program = EXIF_DEF_EXPOSURE_PROGRAM;
4055 //3 Exif Version
4056 memcpy(mExifInfo.exif_version, EXIF_DEF_EXIF_VERSION, sizeof(mExifInfo.exif_version));
4057 //3 Aperture
4058 uint32_t av = APEX_FNUM_TO_APERTURE((double)mExifInfo.fnumber.num/mExifInfo.fnumber.den);
4059 mExifInfo.aperture.num = av*EXIF_DEF_APEX_DEN;
4060 mExifInfo.aperture.den = EXIF_DEF_APEX_DEN;
4061 //3 Maximum lens aperture
4062 mExifInfo.max_aperture.num = mExifInfo.aperture.num;
4063 mExifInfo.max_aperture.den = mExifInfo.aperture.den;
4064 //3 Lens Focal Length
4065 mExifInfo.focal_length.num = EXIF_DEF_FOCAL_LEN_NUM;
4066 mExifInfo.focal_length.den = EXIF_DEF_FOCAL_LEN_DEN;
4067 //3 User Comments
4068 strcpy((char *)mExifInfo.user_comment, EXIF_DEF_USERCOMMENTS);
4069 //3 Color Space information
4070 mExifInfo.color_space = EXIF_DEF_COLOR_SPACE;
4071 //3 Exposure Mode
4072 mExifInfo.exposure_mode = EXIF_DEF_EXPOSURE_MODE;
4073
4074 //2 0th IFD GPS Info Tags
4075 unsigned char gps_version[4] = { 0x02, 0x02, 0x00, 0x00 };
4076 memcpy(mExifInfo.gps_version_id, gps_version, sizeof(gps_version));
4077
4078 //2 1th IFD TIFF Tags
4079 mExifInfo.compression_scheme = EXIF_DEF_COMPRESSION;
4080 mExifInfo.x_resolution.num = EXIF_DEF_RESOLUTION_NUM;
4081 mExifInfo.x_resolution.den = EXIF_DEF_RESOLUTION_DEN;
4082 mExifInfo.y_resolution.num = EXIF_DEF_RESOLUTION_NUM;
4083 mExifInfo.y_resolution.den = EXIF_DEF_RESOLUTION_DEN;
4084 mExifInfo.resolution_unit = EXIF_DEF_RESOLUTION_UNIT;
4085}
4086
4087void ExynosCameraHWInterface2::m_setExifChangedAttribute(exif_attribute_t *exifInfo, ExynosRect *rect,
4088 camera2_shot *currentEntry)
4089{
4090 camera2_dm *dm = &(currentEntry->dm);
4091 camera2_ctl *ctl = &(currentEntry->ctl);
4092
4093 ALOGV("(%s): framecnt(%d) exp(%lld) iso(%d)", __FUNCTION__, ctl->request.frameCount, dm->sensor.exposureTime,dm->aa.isoValue );
4094 if (!ctl->request.frameCount)
4095 return;
4096 //2 0th IFD TIFF Tags
4097 //3 Width
4098 exifInfo->width = rect->w;
4099 //3 Height
4100 exifInfo->height = rect->h;
4101 //3 Orientation
4102 switch (ctl->jpeg.orientation) {
4103 case 90:
4104 exifInfo->orientation = EXIF_ORIENTATION_90;
4105 break;
4106 case 180:
4107 exifInfo->orientation = EXIF_ORIENTATION_180;
4108 break;
4109 case 270:
4110 exifInfo->orientation = EXIF_ORIENTATION_270;
4111 break;
4112 case 0:
4113 default:
4114 exifInfo->orientation = EXIF_ORIENTATION_UP;
4115 break;
4116 }
4117
4118 //3 Date time
4119 time_t rawtime;
4120 struct tm *timeinfo;
4121 time(&rawtime);
4122 timeinfo = localtime(&rawtime);
4123 strftime((char *)exifInfo->date_time, 20, "%Y:%m:%d %H:%M:%S", timeinfo);
4124
4125 //2 0th IFD Exif Private Tags
4126 //3 Exposure Time
4127 int shutterSpeed = (dm->sensor.exposureTime/1000);
4128
4129 if (shutterSpeed < 0) {
4130 shutterSpeed = 100;
4131 }
4132
4133 exifInfo->exposure_time.num = 1;
4134 // x us -> 1/x s */
4135 //exifInfo->exposure_time.den = (uint32_t)(1000000 / shutterSpeed);
4136 exifInfo->exposure_time.den = (uint32_t)((double)1000000 / shutterSpeed);
4137
4138 //3 ISO Speed Rating
4139 exifInfo->iso_speed_rating = dm->aa.isoValue;
4140
4141 uint32_t av, tv, bv, sv, ev;
4142 av = APEX_FNUM_TO_APERTURE((double)exifInfo->fnumber.num / exifInfo->fnumber.den);
4143 tv = APEX_EXPOSURE_TO_SHUTTER((double)exifInfo->exposure_time.num / exifInfo->exposure_time.den);
4144 sv = APEX_ISO_TO_FILMSENSITIVITY(exifInfo->iso_speed_rating);
4145 bv = av + tv - sv;
4146 ev = av + tv;
4147 //ALOGD("Shutter speed=%d us, iso=%d", shutterSpeed, exifInfo->iso_speed_rating);
4148 ALOGD("AV=%d, TV=%d, SV=%d", av, tv, sv);
4149
4150 //3 Shutter Speed
4151 exifInfo->shutter_speed.num = tv * EXIF_DEF_APEX_DEN;
4152 exifInfo->shutter_speed.den = EXIF_DEF_APEX_DEN;
4153 //3 Brightness
4154 exifInfo->brightness.num = bv*EXIF_DEF_APEX_DEN;
4155 exifInfo->brightness.den = EXIF_DEF_APEX_DEN;
4156 //3 Exposure Bias
4157 if (ctl->aa.sceneMode== AA_SCENE_MODE_BEACH||
4158 ctl->aa.sceneMode== AA_SCENE_MODE_SNOW) {
4159 exifInfo->exposure_bias.num = EXIF_DEF_APEX_DEN;
4160 exifInfo->exposure_bias.den = EXIF_DEF_APEX_DEN;
4161 } else {
4162 exifInfo->exposure_bias.num = 0;
4163 exifInfo->exposure_bias.den = 0;
4164 }
4165 //3 Metering Mode
4166 /*switch (m_curCameraInfo->metering) {
4167 case METERING_MODE_CENTER:
4168 exifInfo->metering_mode = EXIF_METERING_CENTER;
4169 break;
4170 case METERING_MODE_MATRIX:
4171 exifInfo->metering_mode = EXIF_METERING_MULTISPOT;
4172 break;
4173 case METERING_MODE_SPOT:
4174 exifInfo->metering_mode = EXIF_METERING_SPOT;
4175 break;
4176 case METERING_MODE_AVERAGE:
4177 default:
4178 exifInfo->metering_mode = EXIF_METERING_AVERAGE;
4179 break;
4180 }*/
4181 exifInfo->metering_mode = EXIF_METERING_CENTER;
4182
4183 //3 Flash
4184 int flash = dm->flash.flashMode;
4185 if (dm->flash.flashMode == FLASH_MODE_OFF || flash < 0)
4186 exifInfo->flash = EXIF_DEF_FLASH;
4187 else
4188 exifInfo->flash = flash;
4189
4190 //3 White Balance
4191 if (dm->aa.awbMode == AA_AWBMODE_WB_AUTO)
4192 exifInfo->white_balance = EXIF_WB_AUTO;
4193 else
4194 exifInfo->white_balance = EXIF_WB_MANUAL;
4195
4196 //3 Scene Capture Type
4197 switch (ctl->aa.sceneMode) {
4198 case AA_SCENE_MODE_PORTRAIT:
4199 exifInfo->scene_capture_type = EXIF_SCENE_PORTRAIT;
4200 break;
4201 case AA_SCENE_MODE_LANDSCAPE:
4202 exifInfo->scene_capture_type = EXIF_SCENE_LANDSCAPE;
4203 break;
4204 case AA_SCENE_MODE_NIGHT_PORTRAIT:
4205 exifInfo->scene_capture_type = EXIF_SCENE_NIGHT;
4206 break;
4207 default:
4208 exifInfo->scene_capture_type = EXIF_SCENE_STANDARD;
4209 break;
4210 }
4211
4212 //2 0th IFD GPS Info Tags
4213 if (ctl->jpeg.gpsCoordinates[0] != 0 && ctl->jpeg.gpsCoordinates[1] != 0) {
4214
4215 if (ctl->jpeg.gpsCoordinates[0] > 0)
4216 strcpy((char *)exifInfo->gps_latitude_ref, "N");
4217 else
4218 strcpy((char *)exifInfo->gps_latitude_ref, "S");
4219
4220 if (ctl->jpeg.gpsCoordinates[1] > 0)
4221 strcpy((char *)exifInfo->gps_longitude_ref, "E");
4222 else
4223 strcpy((char *)exifInfo->gps_longitude_ref, "W");
4224
4225 if (ctl->jpeg.gpsCoordinates[2] > 0)
4226 exifInfo->gps_altitude_ref = 0;
4227 else
4228 exifInfo->gps_altitude_ref = 1;
4229
4230 double latitude = fabs(ctl->jpeg.gpsCoordinates[0] / 10000.0);
4231 double longitude = fabs(ctl->jpeg.gpsCoordinates[1] / 10000.0);
4232 double altitude = fabs(ctl->jpeg.gpsCoordinates[2] / 100.0);
4233
4234 exifInfo->gps_latitude[0].num = (uint32_t)latitude;
4235 exifInfo->gps_latitude[0].den = 1;
4236 exifInfo->gps_latitude[1].num = (uint32_t)((latitude - exifInfo->gps_latitude[0].num) * 60);
4237 exifInfo->gps_latitude[1].den = 1;
4238 exifInfo->gps_latitude[2].num = (uint32_t)((((latitude - exifInfo->gps_latitude[0].num) * 60)
4239 - exifInfo->gps_latitude[1].num) * 60);
4240 exifInfo->gps_latitude[2].den = 1;
4241
4242 exifInfo->gps_longitude[0].num = (uint32_t)longitude;
4243 exifInfo->gps_longitude[0].den = 1;
4244 exifInfo->gps_longitude[1].num = (uint32_t)((longitude - exifInfo->gps_longitude[0].num) * 60);
4245 exifInfo->gps_longitude[1].den = 1;
4246 exifInfo->gps_longitude[2].num = (uint32_t)((((longitude - exifInfo->gps_longitude[0].num) * 60)
4247 - exifInfo->gps_longitude[1].num) * 60);
4248 exifInfo->gps_longitude[2].den = 1;
4249
4250 exifInfo->gps_altitude.num = (uint32_t)altitude;
4251 exifInfo->gps_altitude.den = 1;
4252
4253 struct tm tm_data;
4254 long timestamp;
4255 timestamp = (long)ctl->jpeg.gpsTimestamp;
4256 gmtime_r(&timestamp, &tm_data);
4257 exifInfo->gps_timestamp[0].num = tm_data.tm_hour;
4258 exifInfo->gps_timestamp[0].den = 1;
4259 exifInfo->gps_timestamp[1].num = tm_data.tm_min;
4260 exifInfo->gps_timestamp[1].den = 1;
4261 exifInfo->gps_timestamp[2].num = tm_data.tm_sec;
4262 exifInfo->gps_timestamp[2].den = 1;
4263 snprintf((char*)exifInfo->gps_datestamp, sizeof(exifInfo->gps_datestamp),
4264 "%04d:%02d:%02d", tm_data.tm_year + 1900, tm_data.tm_mon + 1, tm_data.tm_mday);
4265
4266 exifInfo->enableGps = true;
4267 } else {
4268 exifInfo->enableGps = false;
4269 }
4270
4271 //2 1th IFD TIFF Tags
4272 exifInfo->widthThumb = ctl->jpeg.thumbnailSize[0];
4273 exifInfo->heightThumb = ctl->jpeg.thumbnailSize[1];
4274}
4275
Sungjoong Kang13d8c7b2012-07-14 10:20:39 +09004276ExynosCameraHWInterface2::MainThread::~MainThread()
Jiyoung Shinc15a6b02012-06-05 01:08:14 -07004277{
Sungjoong Kangad378612012-08-17 12:34:33 -07004278 ALOGV("(%s):", __FUNCTION__);
Sungjoong Kang13d8c7b2012-07-14 10:20:39 +09004279}
4280
4281void ExynosCameraHWInterface2::MainThread::release()
4282{
Sungjoong Kangad378612012-08-17 12:34:33 -07004283 ALOGV("(%s):", __func__);
Sungjoong Kang13d8c7b2012-07-14 10:20:39 +09004284 SetSignal(SIGNAL_THREAD_RELEASE);
Sungjoong Kang13d8c7b2012-07-14 10:20:39 +09004285}
4286
4287ExynosCameraHWInterface2::SensorThread::~SensorThread()
4288{
Sungjoong Kangad378612012-08-17 12:34:33 -07004289 ALOGV("(%s):", __FUNCTION__);
Sungjoong Kang13d8c7b2012-07-14 10:20:39 +09004290}
4291
4292void ExynosCameraHWInterface2::SensorThread::release()
4293{
Sungjoong Kangad378612012-08-17 12:34:33 -07004294 ALOGV("(%s):", __func__);
Sungjoong Kang13d8c7b2012-07-14 10:20:39 +09004295 SetSignal(SIGNAL_THREAD_RELEASE);
Sungjoong Kang13d8c7b2012-07-14 10:20:39 +09004296}
4297
4298ExynosCameraHWInterface2::IspThread::~IspThread()
4299{
Sungjoong Kangad378612012-08-17 12:34:33 -07004300 ALOGV("(%s):", __FUNCTION__);
Sungjoong Kang13d8c7b2012-07-14 10:20:39 +09004301}
4302
4303void ExynosCameraHWInterface2::IspThread::release()
4304{
Sungjoong Kangad378612012-08-17 12:34:33 -07004305 ALOGV("(%s):", __func__);
Sungjoong Kang13d8c7b2012-07-14 10:20:39 +09004306 SetSignal(SIGNAL_THREAD_RELEASE);
Sungjoong Kang13d8c7b2012-07-14 10:20:39 +09004307}
4308
4309ExynosCameraHWInterface2::StreamThread::~StreamThread()
4310{
Sungjoong Kangad378612012-08-17 12:34:33 -07004311 ALOGV("(%s):", __FUNCTION__);
Sungjoong Kang13d8c7b2012-07-14 10:20:39 +09004312}
4313
4314void ExynosCameraHWInterface2::StreamThread::setParameter(stream_parameters_t * new_parameters)
4315{
4316 ALOGV("DEBUG(%s):", __FUNCTION__);
4317
4318 m_tempParameters = new_parameters;
4319
4320 SetSignal(SIGNAL_STREAM_CHANGE_PARAMETER);
4321
4322 // TODO : return synchronously (after setting parameters asynchronously)
Sungjoong Kang9dd63e12012-07-24 00:25:51 +09004323 usleep(2000);
Sungjoong Kang13d8c7b2012-07-14 10:20:39 +09004324}
4325
4326void ExynosCameraHWInterface2::StreamThread::applyChange()
4327{
4328 memcpy(&m_parameters, m_tempParameters, sizeof(stream_parameters_t));
4329
Sungjoong Kang9dd63e12012-07-24 00:25:51 +09004330 ALOGV("DEBUG(%s): Applying Stream paremeters width(%d), height(%d)",
Sungjoong Kang13d8c7b2012-07-14 10:20:39 +09004331 __FUNCTION__, m_parameters.outputWidth, m_parameters.outputHeight);
4332}
4333
4334void ExynosCameraHWInterface2::StreamThread::release()
4335{
Sungjoong Kang9dd63e12012-07-24 00:25:51 +09004336 ALOGV("(%s):", __func__);
Sungjoong Kang13d8c7b2012-07-14 10:20:39 +09004337 SetSignal(SIGNAL_THREAD_RELEASE);
Sungjoong Kang13d8c7b2012-07-14 10:20:39 +09004338}
4339
4340int ExynosCameraHWInterface2::StreamThread::findBufferIndex(void * bufAddr)
4341{
4342 int index;
4343 for (index = 0 ; index < m_parameters.numSvcBuffers ; index++) {
4344 if (m_parameters.svcBuffers[index].virt.extP[0] == bufAddr)
4345 return index;
4346 }
4347 return -1;
Jiyoung Shinc15a6b02012-06-05 01:08:14 -07004348}
4349
Sungjoong Kang9dd63e12012-07-24 00:25:51 +09004350void ExynosCameraHWInterface2::StreamThread::setRecordingParameter(record_parameters_t * recordParm)
4351{
4352 memcpy(&m_recordParameters, recordParm, sizeof(record_parameters_t));
4353}
4354
Jiyoung Shinc15a6b02012-06-05 01:08:14 -07004355int ExynosCameraHWInterface2::createIonClient(ion_client ionClient)
4356{
4357 if (ionClient == 0) {
4358 ionClient = ion_client_create();
4359 if (ionClient < 0) {
Sungjoong Kang13d8c7b2012-07-14 10:20:39 +09004360 ALOGE("[%s]src ion client create failed, value = %d\n", __FUNCTION__, ionClient);
Jiyoung Shinc15a6b02012-06-05 01:08:14 -07004361 return 0;
4362 }
4363 }
4364
4365 return ionClient;
4366}
4367
4368int ExynosCameraHWInterface2::deleteIonClient(ion_client ionClient)
4369{
4370 if (ionClient != 0) {
4371 if (ionClient > 0) {
4372 ion_client_destroy(ionClient);
4373 }
4374 ionClient = 0;
4375 }
4376
4377 return ionClient;
4378}
4379
Sungjoong Kang13d8c7b2012-07-14 10:20:39 +09004380int ExynosCameraHWInterface2::allocCameraMemory(ion_client ionClient, ExynosBuffer *buf, int iMemoryNum)
Jiyoung Shinc15a6b02012-06-05 01:08:14 -07004381{
4382 int ret = 0;
4383 int i = 0;
4384
4385 if (ionClient == 0) {
Sungjoong Kang13d8c7b2012-07-14 10:20:39 +09004386 ALOGE("[%s] ionClient is zero (%d)\n", __FUNCTION__, ionClient);
Jiyoung Shinc15a6b02012-06-05 01:08:14 -07004387 return -1;
4388 }
4389
4390 for (i=0;i<iMemoryNum;i++) {
Sungjoong Kang13d8c7b2012-07-14 10:20:39 +09004391 if (buf->size.extS[i] == 0) {
Jiyoung Shinc15a6b02012-06-05 01:08:14 -07004392 break;
4393 }
4394
Sungjoong Kang13d8c7b2012-07-14 10:20:39 +09004395 buf->fd.extFd[i] = ion_alloc(ionClient, \
4396 buf->size.extS[i], 0, ION_HEAP_EXYNOS_MASK,0);
4397 if ((buf->fd.extFd[i] == -1) ||(buf->fd.extFd[i] == 0)) {
4398 ALOGE("[%s]ion_alloc(%d) failed\n", __FUNCTION__, buf->size.extS[i]);
4399 buf->fd.extFd[i] = -1;
Jiyoung Shinc15a6b02012-06-05 01:08:14 -07004400 freeCameraMemory(buf, iMemoryNum);
4401 return -1;
4402 }
4403
Sungjoong Kang13d8c7b2012-07-14 10:20:39 +09004404 buf->virt.extP[i] = (char *)ion_map(buf->fd.extFd[i], \
4405 buf->size.extS[i], 0);
4406 if ((buf->virt.extP[i] == (char *)MAP_FAILED) || (buf->virt.extP[i] == NULL)) {
4407 ALOGE("[%s]src ion map failed(%d)\n", __FUNCTION__, buf->size.extS[i]);
4408 buf->virt.extP[i] = (char *)MAP_FAILED;
Jiyoung Shinc15a6b02012-06-05 01:08:14 -07004409 freeCameraMemory(buf, iMemoryNum);
4410 return -1;
4411 }
Sungjoong Kang13d8c7b2012-07-14 10:20:39 +09004412 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 -07004413 }
4414
4415 return ret;
4416}
4417
Sungjoong Kang13d8c7b2012-07-14 10:20:39 +09004418void ExynosCameraHWInterface2::freeCameraMemory(ExynosBuffer *buf, int iMemoryNum)
Jiyoung Shinc15a6b02012-06-05 01:08:14 -07004419{
Sungjoong Kang13d8c7b2012-07-14 10:20:39 +09004420
Jiyoung Shinc15a6b02012-06-05 01:08:14 -07004421 int i =0 ;
Sungjoong Kang15fd8232012-08-23 16:16:44 -07004422 int ret = 0;
Jiyoung Shinc15a6b02012-06-05 01:08:14 -07004423
4424 for (i=0;i<iMemoryNum;i++) {
Sungjoong Kang13d8c7b2012-07-14 10:20:39 +09004425 if (buf->fd.extFd[i] != -1) {
4426 if (buf->virt.extP[i] != (char *)MAP_FAILED) {
Sungjoong Kang15fd8232012-08-23 16:16:44 -07004427 ret = ion_unmap(buf->virt.extP[i], buf->size.extS[i]);
4428 if (ret < 0)
4429 ALOGE("ERR(%s)", __FUNCTION__);
Jiyoung Shinc15a6b02012-06-05 01:08:14 -07004430 }
Sungjoong Kang13d8c7b2012-07-14 10:20:39 +09004431 ion_free(buf->fd.extFd[i]);
Jiyoung Shinc15a6b02012-06-05 01:08:14 -07004432 }
Sungjoong Kang13d8c7b2012-07-14 10:20:39 +09004433 buf->fd.extFd[i] = -1;
4434 buf->virt.extP[i] = (char *)MAP_FAILED;
4435 buf->size.extS[i] = 0;
Jiyoung Shinc15a6b02012-06-05 01:08:14 -07004436 }
4437}
4438
Sungjoong Kang13d8c7b2012-07-14 10:20:39 +09004439void ExynosCameraHWInterface2::initCameraMemory(ExynosBuffer *buf, int iMemoryNum)
Jiyoung Shinc15a6b02012-06-05 01:08:14 -07004440{
4441 int i =0 ;
4442 for (i=0;i<iMemoryNum;i++) {
Sungjoong Kang13d8c7b2012-07-14 10:20:39 +09004443 buf->virt.extP[i] = (char *)MAP_FAILED;
4444 buf->fd.extFd[i] = -1;
4445 buf->size.extS[i] = 0;
Jiyoung Shinc15a6b02012-06-05 01:08:14 -07004446 }
4447}
4448
4449
Sungjoong Kang13d8c7b2012-07-14 10:20:39 +09004450
4451
Sungjoong Kang9dd63e12012-07-24 00:25:51 +09004452static camera2_device_t *g_cam2_device = NULL;
Sungjoong Kangb5237e62012-07-27 07:39:05 -07004453static bool g_camera_vaild = false;
Sungjoong Kangdaa1fcd2012-08-08 11:49:43 -07004454ExynosCamera2 * g_camera2[2] = { NULL, NULL };
Jiyoung Shinc15a6b02012-06-05 01:08:14 -07004455
4456static int HAL2_camera_device_close(struct hw_device_t* device)
4457{
Sungjoong Kangad378612012-08-17 12:34:33 -07004458 ALOGV("%s: ENTER", __FUNCTION__);
Jiyoung Shinc15a6b02012-06-05 01:08:14 -07004459 if (device) {
Sungjoong Kang9dd63e12012-07-24 00:25:51 +09004460
Jiyoung Shinc15a6b02012-06-05 01:08:14 -07004461 camera2_device_t *cam_device = (camera2_device_t *)device;
Sungjoong Kangad378612012-08-17 12:34:33 -07004462 ALOGV("cam_device(0x%08x):", (unsigned int)cam_device);
4463 ALOGV("g_cam2_device(0x%08x):", (unsigned int)g_cam2_device);
Jiyoung Shinc15a6b02012-06-05 01:08:14 -07004464 delete static_cast<ExynosCameraHWInterface2 *>(cam_device->priv);
Sungjoong Kangad378612012-08-17 12:34:33 -07004465 g_cam2_device = NULL;
Jiyoung Shinc15a6b02012-06-05 01:08:14 -07004466 free(cam_device);
Sungjoong Kangb5237e62012-07-27 07:39:05 -07004467 g_camera_vaild = false;
Jiyoung Shinc15a6b02012-06-05 01:08:14 -07004468 }
Sungjoong Kang15fd8232012-08-23 16:16:44 -07004469
Sungjoong Kangad378612012-08-17 12:34:33 -07004470 ALOGV("%s: EXIT", __FUNCTION__);
Jiyoung Shinc15a6b02012-06-05 01:08:14 -07004471 return 0;
4472}
4473
4474static inline ExynosCameraHWInterface2 *obj(const struct camera2_device *dev)
4475{
4476 return reinterpret_cast<ExynosCameraHWInterface2 *>(dev->priv);
4477}
4478
4479static int HAL2_device_set_request_queue_src_ops(const struct camera2_device *dev,
4480 const camera2_request_queue_src_ops_t *request_src_ops)
4481{
Sungjoong Kang13d8c7b2012-07-14 10:20:39 +09004482 ALOGV("DEBUG(%s):", __FUNCTION__);
Jiyoung Shinc15a6b02012-06-05 01:08:14 -07004483 return obj(dev)->setRequestQueueSrcOps(request_src_ops);
4484}
4485
4486static int HAL2_device_notify_request_queue_not_empty(const struct camera2_device *dev)
4487{
Sungjoong Kang13d8c7b2012-07-14 10:20:39 +09004488 ALOGV("DEBUG(%s):", __FUNCTION__);
Jiyoung Shinc15a6b02012-06-05 01:08:14 -07004489 return obj(dev)->notifyRequestQueueNotEmpty();
4490}
4491
4492static int HAL2_device_set_frame_queue_dst_ops(const struct camera2_device *dev,
4493 const camera2_frame_queue_dst_ops_t *frame_dst_ops)
4494{
Sungjoong Kang13d8c7b2012-07-14 10:20:39 +09004495 ALOGV("DEBUG(%s):", __FUNCTION__);
Jiyoung Shinc15a6b02012-06-05 01:08:14 -07004496 return obj(dev)->setFrameQueueDstOps(frame_dst_ops);
4497}
4498
4499static int HAL2_device_get_in_progress_count(const struct camera2_device *dev)
4500{
Sungjoong Kang13d8c7b2012-07-14 10:20:39 +09004501 ALOGV("DEBUG(%s):", __FUNCTION__);
Jiyoung Shinc15a6b02012-06-05 01:08:14 -07004502 return obj(dev)->getInProgressCount();
4503}
4504
4505static int HAL2_device_flush_captures_in_progress(const struct camera2_device *dev)
4506{
Sungjoong Kang13d8c7b2012-07-14 10:20:39 +09004507 ALOGV("DEBUG(%s):", __FUNCTION__);
Jiyoung Shinc15a6b02012-06-05 01:08:14 -07004508 return obj(dev)->flushCapturesInProgress();
4509}
4510
4511static int HAL2_device_construct_default_request(const struct camera2_device *dev,
4512 int request_template, camera_metadata_t **request)
4513{
Sungjoong Kang13d8c7b2012-07-14 10:20:39 +09004514 ALOGV("DEBUG(%s):", __FUNCTION__);
Jiyoung Shinc15a6b02012-06-05 01:08:14 -07004515 return obj(dev)->constructDefaultRequest(request_template, request);
4516}
4517
4518static int HAL2_device_allocate_stream(
4519 const struct camera2_device *dev,
4520 // inputs
4521 uint32_t width,
4522 uint32_t height,
4523 int format,
4524 const camera2_stream_ops_t *stream_ops,
4525 // outputs
4526 uint32_t *stream_id,
4527 uint32_t *format_actual,
4528 uint32_t *usage,
4529 uint32_t *max_buffers)
4530{
Sungjoong Kang9dd63e12012-07-24 00:25:51 +09004531 ALOGV("(%s): ", __FUNCTION__);
Jiyoung Shinc15a6b02012-06-05 01:08:14 -07004532 return obj(dev)->allocateStream(width, height, format, stream_ops,
4533 stream_id, format_actual, usage, max_buffers);
4534}
4535
4536
4537static int HAL2_device_register_stream_buffers(const struct camera2_device *dev,
4538 uint32_t stream_id,
4539 int num_buffers,
4540 buffer_handle_t *buffers)
4541{
Sungjoong Kang13d8c7b2012-07-14 10:20:39 +09004542 ALOGV("DEBUG(%s):", __FUNCTION__);
Jiyoung Shinc15a6b02012-06-05 01:08:14 -07004543 return obj(dev)->registerStreamBuffers(stream_id, num_buffers, buffers);
4544}
4545
4546static int HAL2_device_release_stream(
4547 const struct camera2_device *dev,
4548 uint32_t stream_id)
4549{
Sungjoong Kangad378612012-08-17 12:34:33 -07004550 ALOGV("DEBUG(%s)(id: %d):", __FUNCTION__, stream_id);
Sungjoong Kangb5237e62012-07-27 07:39:05 -07004551 if (!g_camera_vaild)
4552 return 0;
Jiyoung Shinc15a6b02012-06-05 01:08:14 -07004553 return obj(dev)->releaseStream(stream_id);
4554}
4555
4556static int HAL2_device_allocate_reprocess_stream(
4557 const struct camera2_device *dev,
4558 uint32_t width,
4559 uint32_t height,
4560 uint32_t format,
4561 const camera2_stream_in_ops_t *reprocess_stream_ops,
4562 // outputs
4563 uint32_t *stream_id,
4564 uint32_t *consumer_usage,
4565 uint32_t *max_buffers)
4566{
Sungjoong Kang13d8c7b2012-07-14 10:20:39 +09004567 ALOGV("DEBUG(%s):", __FUNCTION__);
Jiyoung Shinc15a6b02012-06-05 01:08:14 -07004568 return obj(dev)->allocateReprocessStream(width, height, format, reprocess_stream_ops,
4569 stream_id, consumer_usage, max_buffers);
4570}
4571
4572static int HAL2_device_release_reprocess_stream(
4573 const struct camera2_device *dev,
4574 uint32_t stream_id)
4575{
Sungjoong Kang13d8c7b2012-07-14 10:20:39 +09004576 ALOGV("DEBUG(%s):", __FUNCTION__);
Jiyoung Shinc15a6b02012-06-05 01:08:14 -07004577 return obj(dev)->releaseReprocessStream(stream_id);
4578}
4579
4580static int HAL2_device_trigger_action(const struct camera2_device *dev,
4581 uint32_t trigger_id,
4582 int ext1,
4583 int ext2)
4584{
Sungjoong Kang13d8c7b2012-07-14 10:20:39 +09004585 ALOGV("DEBUG(%s):", __FUNCTION__);
Jiyoung Shinc15a6b02012-06-05 01:08:14 -07004586 return obj(dev)->triggerAction(trigger_id, ext1, ext2);
4587}
4588
4589static int HAL2_device_set_notify_callback(const struct camera2_device *dev,
4590 camera2_notify_callback notify_cb,
4591 void *user)
4592{
Sungjoong Kang13d8c7b2012-07-14 10:20:39 +09004593 ALOGV("DEBUG(%s):", __FUNCTION__);
Jiyoung Shinc15a6b02012-06-05 01:08:14 -07004594 return obj(dev)->setNotifyCallback(notify_cb, user);
4595}
4596
4597static int HAL2_device_get_metadata_vendor_tag_ops(const struct camera2_device*dev,
4598 vendor_tag_query_ops_t **ops)
4599{
Sungjoong Kang13d8c7b2012-07-14 10:20:39 +09004600 ALOGV("DEBUG(%s):", __FUNCTION__);
Jiyoung Shinc15a6b02012-06-05 01:08:14 -07004601 return obj(dev)->getMetadataVendorTagOps(ops);
4602}
4603
4604static int HAL2_device_dump(const struct camera2_device *dev, int fd)
4605{
Sungjoong Kang13d8c7b2012-07-14 10:20:39 +09004606 ALOGV("DEBUG(%s):", __FUNCTION__);
Jiyoung Shinc15a6b02012-06-05 01:08:14 -07004607 return obj(dev)->dump(fd);
4608}
4609
4610
4611
4612
4613
4614static int HAL2_getNumberOfCameras()
4615{
Sungjoong Kang9dd63e12012-07-24 00:25:51 +09004616 ALOGV("(%s): returning 2", __FUNCTION__);
4617 return 2;
Jiyoung Shinc15a6b02012-06-05 01:08:14 -07004618}
4619
4620
Jiyoung Shinc15a6b02012-06-05 01:08:14 -07004621static int HAL2_getCameraInfo(int cameraId, struct camera_info *info)
4622{
Sungjoong Kangad378612012-08-17 12:34:33 -07004623 ALOGV("DEBUG(%s): cameraID: %d", __FUNCTION__, cameraId);
Sungjoong Kang9dd63e12012-07-24 00:25:51 +09004624 static camera_metadata_t * mCameraInfo[2] = {NULL, NULL};
Sungjoong Kangad378612012-08-17 12:34:33 -07004625
Jiyoung Shinc15a6b02012-06-05 01:08:14 -07004626 status_t res;
Sungjoong Kang13d8c7b2012-07-14 10:20:39 +09004627
Sungjoong Kangdaa1fcd2012-08-08 11:49:43 -07004628 if (cameraId == 0) {
Sungjoong Kang9dd63e12012-07-24 00:25:51 +09004629 info->facing = CAMERA_FACING_BACK;
Sungjoong Kangdaa1fcd2012-08-08 11:49:43 -07004630 if (!g_camera2[0])
4631 g_camera2[0] = new ExynosCamera2(0);
4632 }
4633 else if (cameraId == 1) {
Sungjoong Kang9dd63e12012-07-24 00:25:51 +09004634 info->facing = CAMERA_FACING_FRONT;
Sungjoong Kangdaa1fcd2012-08-08 11:49:43 -07004635 if (!g_camera2[1])
4636 g_camera2[1] = new ExynosCamera2(1);
4637 }
4638 else
4639 return BAD_VALUE;
4640
Jiyoung Shinc15a6b02012-06-05 01:08:14 -07004641 info->orientation = 0;
4642 info->device_version = HARDWARE_DEVICE_API_VERSION(2, 0);
Sungjoong Kang9dd63e12012-07-24 00:25:51 +09004643 if (mCameraInfo[cameraId] == NULL) {
Sungjoong Kangdaa1fcd2012-08-08 11:49:43 -07004644 res = g_camera2[cameraId]->constructStaticInfo(&(mCameraInfo[cameraId]), cameraId, true);
Jiyoung Shinc15a6b02012-06-05 01:08:14 -07004645 if (res != OK) {
4646 ALOGE("%s: Unable to allocate static info: %s (%d)",
Sungjoong Kang13d8c7b2012-07-14 10:20:39 +09004647 __FUNCTION__, strerror(-res), res);
Jiyoung Shinc15a6b02012-06-05 01:08:14 -07004648 return res;
4649 }
Sungjoong Kangdaa1fcd2012-08-08 11:49:43 -07004650 res = g_camera2[cameraId]->constructStaticInfo(&(mCameraInfo[cameraId]), cameraId, false);
Jiyoung Shinc15a6b02012-06-05 01:08:14 -07004651 if (res != OK) {
4652 ALOGE("%s: Unable to fill in static info: %s (%d)",
Sungjoong Kang13d8c7b2012-07-14 10:20:39 +09004653 __FUNCTION__, strerror(-res), res);
Jiyoung Shinc15a6b02012-06-05 01:08:14 -07004654 return res;
4655 }
4656 }
Sungjoong Kang9dd63e12012-07-24 00:25:51 +09004657 info->static_camera_characteristics = mCameraInfo[cameraId];
Sungjoong Kang13d8c7b2012-07-14 10:20:39 +09004658 return NO_ERROR;
Jiyoung Shinc15a6b02012-06-05 01:08:14 -07004659}
4660
4661#define SET_METHOD(m) m : HAL2_device_##m
4662
4663static camera2_device_ops_t camera2_device_ops = {
4664 SET_METHOD(set_request_queue_src_ops),
4665 SET_METHOD(notify_request_queue_not_empty),
4666 SET_METHOD(set_frame_queue_dst_ops),
4667 SET_METHOD(get_in_progress_count),
4668 SET_METHOD(flush_captures_in_progress),
4669 SET_METHOD(construct_default_request),
4670 SET_METHOD(allocate_stream),
4671 SET_METHOD(register_stream_buffers),
4672 SET_METHOD(release_stream),
4673 SET_METHOD(allocate_reprocess_stream),
4674 SET_METHOD(release_reprocess_stream),
4675 SET_METHOD(trigger_action),
4676 SET_METHOD(set_notify_callback),
4677 SET_METHOD(get_metadata_vendor_tag_ops),
4678 SET_METHOD(dump),
4679};
4680
4681#undef SET_METHOD
4682
4683
4684static int HAL2_camera_device_open(const struct hw_module_t* module,
4685 const char *id,
4686 struct hw_device_t** device)
4687{
Sungjoong Kang9dd63e12012-07-24 00:25:51 +09004688
Jiyoung Shinc15a6b02012-06-05 01:08:14 -07004689
4690 int cameraId = atoi(id);
Sungjoong Kang6044e502012-08-27 00:29:28 -07004691 int openInvalid = 0;
Sungjoong Kang9dd63e12012-07-24 00:25:51 +09004692
Sungjoong Kangb5237e62012-07-27 07:39:05 -07004693 g_camera_vaild = false;
Sungjoong Kangad378612012-08-17 12:34:33 -07004694 ALOGV("\n\n>>> I'm Samsung's CameraHAL_2(ID:%d) <<<\n\n", cameraId);
Jiyoung Shinc15a6b02012-06-05 01:08:14 -07004695 if (cameraId < 0 || cameraId >= HAL2_getNumberOfCameras()) {
Sungjoong Kang13d8c7b2012-07-14 10:20:39 +09004696 ALOGE("ERR(%s):Invalid camera ID %s", __FUNCTION__, id);
Jiyoung Shinc15a6b02012-06-05 01:08:14 -07004697 return -EINVAL;
4698 }
4699
Sungjoong Kangad378612012-08-17 12:34:33 -07004700 ALOGV("g_cam2_device : 0x%08x", (unsigned int)g_cam2_device);
Jiyoung Shinc15a6b02012-06-05 01:08:14 -07004701 if (g_cam2_device) {
4702 if (obj(g_cam2_device)->getCameraId() == cameraId) {
Sungjoong Kang13d8c7b2012-07-14 10:20:39 +09004703 ALOGV("DEBUG(%s):returning existing camera ID %s", __FUNCTION__, id);
Jiyoung Shinc15a6b02012-06-05 01:08:14 -07004704 goto done;
4705 } else {
Sungjoong Kang9dd63e12012-07-24 00:25:51 +09004706
4707 while (g_cam2_device)
4708 usleep(10000);
Jiyoung Shinc15a6b02012-06-05 01:08:14 -07004709 }
4710 }
4711
4712 g_cam2_device = (camera2_device_t *)malloc(sizeof(camera2_device_t));
Sungjoong Kangad378612012-08-17 12:34:33 -07004713 ALOGV("g_cam2_device : 0x%08x", (unsigned int)g_cam2_device);
Sungjoong Kang9dd63e12012-07-24 00:25:51 +09004714
Jiyoung Shinc15a6b02012-06-05 01:08:14 -07004715 if (!g_cam2_device)
4716 return -ENOMEM;
4717
4718 g_cam2_device->common.tag = HARDWARE_DEVICE_TAG;
4719 g_cam2_device->common.version = CAMERA_DEVICE_API_VERSION_2_0;
4720 g_cam2_device->common.module = const_cast<hw_module_t *>(module);
4721 g_cam2_device->common.close = HAL2_camera_device_close;
4722
4723 g_cam2_device->ops = &camera2_device_ops;
4724
Sungjoong Kang13d8c7b2012-07-14 10:20:39 +09004725 ALOGV("DEBUG(%s):open camera2 %s", __FUNCTION__, id);
Jiyoung Shinc15a6b02012-06-05 01:08:14 -07004726
Sungjoong Kang6044e502012-08-27 00:29:28 -07004727 g_cam2_device->priv = new ExynosCameraHWInterface2(cameraId, g_cam2_device, g_camera2[cameraId], &openInvalid);
4728 if (!openInvalid) {
4729 ALOGE("DEBUG(%s): ExynosCameraHWInterface2 creation failed(%d)", __FUNCTION__);
4730 return -ENOMEM;
4731 }
Jiyoung Shinc15a6b02012-06-05 01:08:14 -07004732done:
4733 *device = (hw_device_t *)g_cam2_device;
Sungjoong Kang13d8c7b2012-07-14 10:20:39 +09004734 ALOGV("DEBUG(%s):opened camera2 %s (%p)", __FUNCTION__, id, *device);
Sungjoong Kangb5237e62012-07-27 07:39:05 -07004735 g_camera_vaild = true;
Jiyoung Shinc15a6b02012-06-05 01:08:14 -07004736
4737 return 0;
4738}
4739
4740
4741static hw_module_methods_t camera_module_methods = {
4742 open : HAL2_camera_device_open
4743};
4744
4745extern "C" {
4746 struct camera_module HAL_MODULE_INFO_SYM = {
4747 common : {
4748 tag : HARDWARE_MODULE_TAG,
4749 module_api_version : CAMERA_MODULE_API_VERSION_2_0,
4750 hal_api_version : HARDWARE_HAL_API_VERSION,
4751 id : CAMERA_HARDWARE_MODULE_ID,
4752 name : "Exynos Camera HAL2",
4753 author : "Samsung Corporation",
4754 methods : &camera_module_methods,
4755 dso: NULL,
4756 reserved: {0},
4757 },
4758 get_number_of_cameras : HAL2_getNumberOfCameras,
4759 get_camera_info : HAL2_getCameraInfo
4760 };
4761}
4762
4763}; // namespace android