blob: 9437a73f8890a8fc5948c40aa8b9df418b67221a [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{
289 return;
290}
291
292int RequestManager::GetNumEntries()
293{
294 return m_numOfEntries;
295}
296
Sungjoong Kang9dd63e12012-07-24 00:25:51 +0900297void RequestManager::SetDefaultParameters(int cropX)
298{
299 m_cropX = cropX;
300}
301
Jiyoung Shinc15a6b02012-06-05 01:08:14 -0700302bool RequestManager::IsRequestQueueFull()
303{
304 Mutex::Autolock lock(m_requestMutex);
305 if (m_numOfEntries>=NUM_MAX_REQUEST_MGR_ENTRY)
306 return true;
307 else
308 return false;
309}
310
311void RequestManager::RegisterRequest(camera_metadata_t * new_request)
312{
Sungjoong Kang13d8c7b2012-07-14 10:20:39 +0900313 ALOGV("DEBUG(%s):", __FUNCTION__);
314
Jiyoung Shinc15a6b02012-06-05 01:08:14 -0700315 Mutex::Autolock lock(m_requestMutex);
Sungjoong Kang13d8c7b2012-07-14 10:20:39 +0900316
Jiyoung Shinc15a6b02012-06-05 01:08:14 -0700317 request_manager_entry * newEntry = NULL;
Sungjoong Kang9dd63e12012-07-24 00:25:51 +0900318 int newInsertionIndex = GetNextIndex(m_entryInsertionIndex);
Sungjoong Kang13d8c7b2012-07-14 10:20:39 +0900319 ALOGV("DEBUG(%s): got lock, new insertIndex(%d), cnt before reg(%d)", __FUNCTION__,newInsertionIndex,m_numOfEntries );
Jiyoung Shinc15a6b02012-06-05 01:08:14 -0700320
Sungjoong Kang13d8c7b2012-07-14 10:20:39 +0900321
Jiyoung Shinc15a6b02012-06-05 01:08:14 -0700322 newEntry = &(entries[newInsertionIndex]);
323
324 if (newEntry->status!=EMPTY) {
Sungjoong Kang13d8c7b2012-07-14 10:20:39 +0900325 ALOGV("DEBUG(%s): Circular buffer abnormal ", __FUNCTION__);
326 return;
Jiyoung Shinc15a6b02012-06-05 01:08:14 -0700327 }
328 newEntry->status = REGISTERED;
329 newEntry->original_request = new_request;
Sungjoong Kangad378612012-08-17 12:34:33 -0700330 memset(&(newEntry->internal_shot), 0, sizeof(struct camera2_shot_ext));
Sungjoong Kang13d8c7b2012-07-14 10:20:39 +0900331 m_metadataConverter->ToInternalShot(new_request, &(newEntry->internal_shot));
Sungjoong Kangb56dcc02012-08-08 13:38:09 -0700332 newEntry->output_stream_count = newEntry->internal_shot.shot.ctl.request.outputStreams[15];
Jiyoung Shinc15a6b02012-06-05 01:08:14 -0700333
334 m_numOfEntries++;
335 m_entryInsertionIndex = newInsertionIndex;
336
Sungjoong Kang13d8c7b2012-07-14 10:20:39 +0900337
Jiyoung Shinc15a6b02012-06-05 01:08:14 -0700338 ALOGV("## RegisterReq DONE num(%d), insert(%d), processing(%d), frame(%d), (frameCnt(%d))",
Sungjoong Kangbe494d12012-08-04 15:36:56 -0700339 m_numOfEntries,m_entryInsertionIndex,m_entryProcessingIndex, m_entryFrameOutputIndex, newEntry->internal_shot.shot.ctl.request.frameCount);
Jiyoung Shinc15a6b02012-06-05 01:08:14 -0700340}
341
342void RequestManager::DeregisterRequest(camera_metadata_t ** deregistered_request)
343{
Sungjoong Kang13d8c7b2012-07-14 10:20:39 +0900344 ALOGV("DEBUG(%s):", __FUNCTION__);
Sungjoong Kangad378612012-08-17 12:34:33 -0700345 int frame_index;
346 request_manager_entry * currentEntry;
347
Jiyoung Shinc15a6b02012-06-05 01:08:14 -0700348 Mutex::Autolock lock(m_requestMutex);
349
Sungjoong Kangad378612012-08-17 12:34:33 -0700350 frame_index = GetFrameIndex();
351 currentEntry = &(entries[frame_index]);
Sungjoong Kangbe494d12012-08-04 15:36:56 -0700352 if (currentEntry->status != CAPTURED) {
Sungjoong Kangad378612012-08-17 12:34:33 -0700353 ALOGV("DBG(%s): Circular buffer abnormal. processing(%d), frame(%d), status(%d) ", __FUNCTION__
Jiyoung Shinc15a6b02012-06-05 01:08:14 -0700354 , m_entryProcessingIndex, m_entryFrameOutputIndex,(int)(currentEntry->status));
Sungjoong Kang13d8c7b2012-07-14 10:20:39 +0900355 return;
Jiyoung Shinc15a6b02012-06-05 01:08:14 -0700356 }
Sungjoong Kang13d8c7b2012-07-14 10:20:39 +0900357 if (deregistered_request) *deregistered_request = currentEntry->original_request;
358
Jiyoung Shinc15a6b02012-06-05 01:08:14 -0700359 currentEntry->status = EMPTY;
360 currentEntry->original_request = NULL;
Sungjoong Kangbe494d12012-08-04 15:36:56 -0700361 memset(&(currentEntry->internal_shot), 0, sizeof(struct camera2_shot_ext));
362 currentEntry->internal_shot.shot.ctl.request.frameCount = -1;
Jiyoung Shinc15a6b02012-06-05 01:08:14 -0700363 currentEntry->output_stream_count = 0;
Sungjoong Kang13d8c7b2012-07-14 10:20:39 +0900364 currentEntry->dynamic_meta_vaild = false;
Jiyoung Shinc15a6b02012-06-05 01:08:14 -0700365 m_numOfEntries--;
366 ALOGV("## DeRegistReq DONE num(%d), insert(%d), processing(%d), frame(%d)",
367 m_numOfEntries,m_entryInsertionIndex,m_entryProcessingIndex, m_entryFrameOutputIndex);
Sungjoong Kang13d8c7b2012-07-14 10:20:39 +0900368
Jiyoung Shinc15a6b02012-06-05 01:08:14 -0700369 return;
Jiyoung Shinc15a6b02012-06-05 01:08:14 -0700370}
371
Sungjoong Kang13d8c7b2012-07-14 10:20:39 +0900372bool RequestManager::PrepareFrame(size_t* num_entries, size_t* frame_size,
Sungjoong Kang0f26b202012-08-17 15:43:12 -0700373 camera_metadata_t ** prepared_frame, int afState)
Jiyoung Shinc15a6b02012-06-05 01:08:14 -0700374{
Sungjoong Kang13d8c7b2012-07-14 10:20:39 +0900375 ALOGV("DEBUG(%s):", __FUNCTION__);
Jiyoung Shinc15a6b02012-06-05 01:08:14 -0700376 Mutex::Autolock lock(m_requestMutex);
377 status_t res = NO_ERROR;
Sungjoong Kangad378612012-08-17 12:34:33 -0700378 int tempFrameOutputIndex = GetFrameIndex();
Sungjoong Kang13d8c7b2012-07-14 10:20:39 +0900379 request_manager_entry * currentEntry = &(entries[tempFrameOutputIndex]);
380 ALOGV("DEBUG(%s): processing(%d), frameOut(%d), insert(%d) recentlycompleted(%d)", __FUNCTION__,
381 m_entryProcessingIndex, m_entryFrameOutputIndex, m_entryInsertionIndex, m_completedIndex);
382
Sungjoong Kangbe494d12012-08-04 15:36:56 -0700383 if (currentEntry->status != CAPTURED) {
Sungjoong Kangad378612012-08-17 12:34:33 -0700384 ALOGV("DBG(%s): Circular buffer abnormal status(%d)", __FUNCTION__, (int)(currentEntry->status));
Sungjoong Kang13d8c7b2012-07-14 10:20:39 +0900385
386 return false;
387 }
388 m_entryFrameOutputIndex = tempFrameOutputIndex;
Sungjoong Kangb56dcc02012-08-08 13:38:09 -0700389 m_tempFrameMetadata = place_camera_metadata(m_tempFrameMetadataBuf, 2000, 15, 500); //estimated
Sungjoong Kang0f26b202012-08-17 15:43:12 -0700390 add_camera_metadata_entry(m_tempFrameMetadata, ANDROID_CONTROL_AF_STATE, &afState, 1);
Sungjoong Kang13d8c7b2012-07-14 10:20:39 +0900391 res = m_metadataConverter->ToDynamicMetadata(&(currentEntry->internal_shot),
Jiyoung Shinc15a6b02012-06-05 01:08:14 -0700392 m_tempFrameMetadata);
393 if (res!=NO_ERROR) {
Sungjoong Kang13d8c7b2012-07-14 10:20:39 +0900394 ALOGE("ERROR(%s): ToDynamicMetadata (%d) ", __FUNCTION__, res);
395 return false;
Jiyoung Shinc15a6b02012-06-05 01:08:14 -0700396 }
397 *num_entries = get_camera_metadata_entry_count(m_tempFrameMetadata);
398 *frame_size = get_camera_metadata_size(m_tempFrameMetadata);
399 *prepared_frame = m_tempFrameMetadata;
Sungjoong Kang13d8c7b2012-07-14 10:20:39 +0900400 ALOGV("## PrepareFrame DONE: frameOut(%d) frameCnt-req(%d)", m_entryFrameOutputIndex,
Sungjoong Kangbe494d12012-08-04 15:36:56 -0700401 currentEntry->internal_shot.shot.ctl.request.frameCount);
Sungjoong Kang9dd63e12012-07-24 00:25:51 +0900402 // Dump();
Sungjoong Kang13d8c7b2012-07-14 10:20:39 +0900403 return true;
Jiyoung Shinc15a6b02012-06-05 01:08:14 -0700404}
405
Sungjoong Kang0f26b202012-08-17 15:43:12 -0700406int RequestManager::MarkProcessingRequest(ExynosBuffer* buf, int *afMode)
Jiyoung Shinc15a6b02012-06-05 01:08:14 -0700407{
Sungjoong Kangad378612012-08-17 12:34:33 -0700408
Jiyoung Shinc15a6b02012-06-05 01:08:14 -0700409 Mutex::Autolock lock(m_requestMutex);
Sungjoong Kang13d8c7b2012-07-14 10:20:39 +0900410 struct camera2_shot_ext * shot_ext;
Sungjoong Kangb56dcc02012-08-08 13:38:09 -0700411 struct camera2_shot_ext * request_shot;
Sungjoong Kang13d8c7b2012-07-14 10:20:39 +0900412 int targetStreamIndex = 0;
Sungjoong Kangad378612012-08-17 12:34:33 -0700413 request_manager_entry * newEntry = NULL;
Sungjoong Kang0f26b202012-08-17 15:43:12 -0700414 static int count = 0;
Sungjoong Kang13d8c7b2012-07-14 10:20:39 +0900415
Sungjoong Kang13d8c7b2012-07-14 10:20:39 +0900416 if (m_numOfEntries == 0) {
Sungjoong Kangad378612012-08-17 12:34:33 -0700417 ALOGD("DEBUG(%s): Request Manager Empty ", __FUNCTION__);
Sungjoong Kang13d8c7b2012-07-14 10:20:39 +0900418 return -1;
419 }
420
421 if ((m_entryProcessingIndex == m_entryInsertionIndex)
Sungjoong Kangbe494d12012-08-04 15:36:56 -0700422 && (entries[m_entryProcessingIndex].status == REQUESTED || entries[m_entryProcessingIndex].status == CAPTURED)) {
Sungjoong Kangad378612012-08-17 12:34:33 -0700423 ALOGD("## MarkProcReq skipping(request underrun) - num(%d), insert(%d), processing(%d), frame(%d)",
Sungjoong Kang13d8c7b2012-07-14 10:20:39 +0900424 m_numOfEntries,m_entryInsertionIndex,m_entryProcessingIndex, m_entryFrameOutputIndex);
425 return -1;
426 }
Jiyoung Shinc15a6b02012-06-05 01:08:14 -0700427
Sungjoong Kang9dd63e12012-07-24 00:25:51 +0900428 int newProcessingIndex = GetNextIndex(m_entryProcessingIndex);
Sungjoong Kangad378612012-08-17 12:34:33 -0700429 ALOGV("DEBUG(%s): index(%d)", __FUNCTION__, newProcessingIndex);
Jiyoung Shinc15a6b02012-06-05 01:08:14 -0700430
Jiyoung Shinc15a6b02012-06-05 01:08:14 -0700431 newEntry = &(entries[newProcessingIndex]);
Sungjoong Kangad378612012-08-17 12:34:33 -0700432 request_shot = &(newEntry->internal_shot);
Sungjoong Kang0f26b202012-08-17 15:43:12 -0700433 *afMode = (int)(newEntry->internal_shot.shot.ctl.aa.afMode);
Sungjoong Kangbe494d12012-08-04 15:36:56 -0700434 if (newEntry->status != REGISTERED) {
Sungjoong Kangad378612012-08-17 12:34:33 -0700435 ALOGD("DEBUG(%s)(%d): Circular buffer abnormal ", __FUNCTION__, newProcessingIndex);
Sungjoong Kang13d8c7b2012-07-14 10:20:39 +0900436 return -1;
Jiyoung Shinc15a6b02012-06-05 01:08:14 -0700437 }
Sungjoong Kangad378612012-08-17 12:34:33 -0700438
Sungjoong Kangbe494d12012-08-04 15:36:56 -0700439 newEntry->status = REQUESTED;
Jiyoung Shinc15a6b02012-06-05 01:08:14 -0700440
Sungjoong Kangad378612012-08-17 12:34:33 -0700441 shot_ext = (struct camera2_shot_ext *)buf->virt.extP[1];
Sungjoong Kang13d8c7b2012-07-14 10:20:39 +0900442
Sungjoong Kangad378612012-08-17 12:34:33 -0700443 memset(shot_ext, 0x00, sizeof(struct camera2_shot_ext));
444 shot_ext->shot.ctl.request.frameCount = request_shot->shot.ctl.request.frameCount;
Sungjoong Kang13d8c7b2012-07-14 10:20:39 +0900445 shot_ext->request_sensor = 1;
Sungjoong Kang9dd63e12012-07-24 00:25:51 +0900446 shot_ext->dis_bypass = 1;
447 shot_ext->dnr_bypass = 1;
Sungjoong Kangad378612012-08-17 12:34:33 -0700448 shot_ext->fd_bypass = 1;
449 shot_ext->setfile = 0;
450
Sungjoong Kang13d8c7b2012-07-14 10:20:39 +0900451 for (int i = 0; i < newEntry->output_stream_count; i++) {
Sungjoong Kangbe494d12012-08-04 15:36:56 -0700452 targetStreamIndex = newEntry->internal_shot.shot.ctl.request.outputStreams[i];
Sungjoong Kang13d8c7b2012-07-14 10:20:39 +0900453
454 if (targetStreamIndex==0) {
455 ALOGV("DEBUG(%s): outputstreams(%d) is for scalerP", __FUNCTION__, i);
456 shot_ext->request_scp = 1;
457 }
Sungjoong Kang9dd63e12012-07-24 00:25:51 +0900458 else if (targetStreamIndex == 1) {
Sungjoong Kang13d8c7b2012-07-14 10:20:39 +0900459 ALOGV("DEBUG(%s): outputstreams(%d) is for scalerC", __FUNCTION__, i);
460 shot_ext->request_scc = 1;
Sungjoong Kang9dd63e12012-07-24 00:25:51 +0900461 }
462 else if (targetStreamIndex == 2) {
463 ALOGV("DEBUG(%s): outputstreams(%d) is for scalerP (record)", __FUNCTION__, i);
464 shot_ext->request_scp = 1;
465 shot_ext->shot.ctl.request.outputStreams[2] = 1;
Sungjoong Kang13d8c7b2012-07-14 10:20:39 +0900466 }
467 else {
468 ALOGV("DEBUG(%s): outputstreams(%d) has abnormal value(%d)", __FUNCTION__, i, targetStreamIndex);
469 }
470 }
Sungjoong Kangad378612012-08-17 12:34:33 -0700471
Sungjoong Kang0f26b202012-08-17 15:43:12 -0700472 if (count == 0){
473 shot_ext->shot.ctl.aa.mode = AA_CONTROL_AUTO;
474 } else
475 shot_ext->shot.ctl.aa.mode = AA_CONTROL_NONE;
476
477 count++;
Sungjoong Kangad378612012-08-17 12:34:33 -0700478 shot_ext->shot.ctl.request.metadataMode = METADATA_MODE_FULL;
479 shot_ext->shot.ctl.stats.faceDetectMode = FACEDETECT_MODE_FULL;
480 shot_ext->shot.magicNumber = 0x23456789;
481 shot_ext->shot.ctl.sensor.exposureTime = 0;
482 shot_ext->shot.ctl.sensor.frameDuration = 33*1000*1000;
483 shot_ext->shot.ctl.sensor.sensitivity = 0;
484
485 shot_ext->shot.ctl.scaler.cropRegion[0] = 0;
486 shot_ext->shot.ctl.scaler.cropRegion[1] = 0;
487 shot_ext->shot.ctl.scaler.cropRegion[2] = m_cropX;
488
Sungjoong Kang13d8c7b2012-07-14 10:20:39 +0900489 m_entryProcessingIndex = newProcessingIndex;
Sungjoong Kangad378612012-08-17 12:34:33 -0700490 return newProcessingIndex;
Jiyoung Shinc15a6b02012-06-05 01:08:14 -0700491}
492
Sungjoong Kang9dd63e12012-07-24 00:25:51 +0900493void RequestManager::NotifyStreamOutput(int frameCnt, int stream_id)
Jiyoung Shinc15a6b02012-06-05 01:08:14 -0700494{
Sungjoong Kang9dd63e12012-07-24 00:25:51 +0900495 int index;
496
497 ALOGV("DEBUG(%s): frameCnt(%d), stream_id(%d)", __FUNCTION__, frameCnt, stream_id);
498
499 index = FindEntryIndexByFrameCnt(frameCnt);
500 if (index == -1) {
501 ALOGE("ERR(%s): Cannot find entry for frameCnt(%d)", __FUNCTION__, frameCnt);
502 return;
503 }
504 ALOGV("DEBUG(%s): frameCnt(%d), stream_id(%d) last cnt (%d)", __FUNCTION__, frameCnt, stream_id, entries[index].output_stream_count);
505
Sungjoong Kangbe494d12012-08-04 15:36:56 -0700506 entries[index].output_stream_count--; //TODO : match stream id also
507 CheckCompleted(index);
Jiyoung Shinc15a6b02012-06-05 01:08:14 -0700508 return;
509}
510
Sungjoong Kang13d8c7b2012-07-14 10:20:39 +0900511void RequestManager::CheckCompleted(int index)
512{
Sungjoong Kang9dd63e12012-07-24 00:25:51 +0900513 ALOGV("DEBUG(%s): reqIndex(%d) current Count(%d)", __FUNCTION__, index, entries[index].output_stream_count);
Sungjoong Kangad378612012-08-17 12:34:33 -0700514 SetFrameIndex(index);
515 m_mainThread->SetSignal(SIGNAL_MAIN_STREAM_OUTPUT_DONE);
Sungjoong Kang13d8c7b2012-07-14 10:20:39 +0900516 return;
517}
Sungjoong Kang13d8c7b2012-07-14 10:20:39 +0900518
Sungjoong Kangad378612012-08-17 12:34:33 -0700519void RequestManager::SetFrameIndex(int index)
520{
521 Mutex::Autolock lock(m_requestMutex);
522 m_frameIndex = index;
523}
524
525int RequestManager::GetFrameIndex()
526{
527 return m_frameIndex;
528}
529
530void RequestManager::ApplyDynamicMetadata(struct camera2_shot_ext *shot_ext)
Sungjoong Kang13d8c7b2012-07-14 10:20:39 +0900531{
Sungjoong Kang9dd63e12012-07-24 00:25:51 +0900532 int index;
Sungjoong Kangb56dcc02012-08-08 13:38:09 -0700533 struct camera2_shot_ext * request_shot;
534 nsecs_t timeStamp;
Sungjoong Kangad378612012-08-17 12:34:33 -0700535 int i;
Sungjoong Kang9dd63e12012-07-24 00:25:51 +0900536
Sungjoong Kangad378612012-08-17 12:34:33 -0700537 ALOGV("DEBUG(%s): frameCnt(%d)", __FUNCTION__, shot_ext->shot.ctl.request.frameCount);
Sungjoong Kang9dd63e12012-07-24 00:25:51 +0900538
Sungjoong Kangad378612012-08-17 12:34:33 -0700539 for (i = 0 ; i < NUM_MAX_REQUEST_MGR_ENTRY ; i++) {
540 if((entries[i].internal_shot.shot.ctl.request.frameCount == shot_ext->shot.ctl.request.frameCount)
541 && (entries[i].status == CAPTURED))
542 break;
543 }
544
545 if (i == NUM_MAX_REQUEST_MGR_ENTRY){
546 ALOGE("[%s] no entry found(framecount:%d)", __FUNCTION__, shot_ext->shot.ctl.request.frameCount);
Sungjoong Kang9dd63e12012-07-24 00:25:51 +0900547 return;
548 }
549
Sungjoong Kangad378612012-08-17 12:34:33 -0700550 request_manager_entry * newEntry = &(entries[i]);
Sungjoong Kangb56dcc02012-08-08 13:38:09 -0700551 request_shot = &(newEntry->internal_shot);
Sungjoong Kang9dd63e12012-07-24 00:25:51 +0900552
Sungjoong Kangbe494d12012-08-04 15:36:56 -0700553 newEntry->dynamic_meta_vaild = true;
Sungjoong Kangb56dcc02012-08-08 13:38:09 -0700554 timeStamp = request_shot->shot.dm.sensor.timeStamp;
Sungjoong Kangad378612012-08-17 12:34:33 -0700555 memcpy(&(request_shot->shot.dm), &(shot_ext->shot.dm), sizeof(struct camera2_dm));
Sungjoong Kangb56dcc02012-08-08 13:38:09 -0700556 request_shot->shot.dm.sensor.timeStamp = timeStamp;
Sungjoong Kangad378612012-08-17 12:34:33 -0700557 CheckCompleted(i);
Sungjoong Kang13d8c7b2012-07-14 10:20:39 +0900558}
559
560void RequestManager::DumpInfoWithIndex(int index)
561{
Sungjoong Kangbe494d12012-08-04 15:36:56 -0700562 struct camera2_shot_ext * currMetadata = &(entries[index].internal_shot);
Sungjoong Kang13d8c7b2012-07-14 10:20:39 +0900563
564 ALOGV("#### frameCount(%d) exposureTime(%lld) ISO(%d)",
Sungjoong Kangbe494d12012-08-04 15:36:56 -0700565 currMetadata->shot.ctl.request.frameCount,
566 currMetadata->shot.ctl.sensor.exposureTime,
567 currMetadata->shot.ctl.sensor.sensitivity);
Sungjoong Kangb56dcc02012-08-08 13:38:09 -0700568 if (currMetadata->shot.ctl.request.outputStreams[15] == 0)
Sungjoong Kang13d8c7b2012-07-14 10:20:39 +0900569 ALOGV("#### No output stream selected");
Sungjoong Kangb56dcc02012-08-08 13:38:09 -0700570 else if (currMetadata->shot.ctl.request.outputStreams[15] == 1)
Sungjoong Kangbe494d12012-08-04 15:36:56 -0700571 ALOGV("#### OutputStreamId : %d", currMetadata->shot.ctl.request.outputStreams[0]);
Sungjoong Kangb56dcc02012-08-08 13:38:09 -0700572 else if (currMetadata->shot.ctl.request.outputStreams[15] == 2)
Sungjoong Kangbe494d12012-08-04 15:36:56 -0700573 ALOGV("#### OutputStreamId : %d, %d", currMetadata->shot.ctl.request.outputStreams[0],
574 currMetadata->shot.ctl.request.outputStreams[1]);
Sungjoong Kang13d8c7b2012-07-14 10:20:39 +0900575 else
Sungjoong Kangb56dcc02012-08-08 13:38:09 -0700576 ALOGV("#### OutputStream num (%d) abnormal ", currMetadata->shot.ctl.request.outputStreams[15]);
Sungjoong Kang13d8c7b2012-07-14 10:20:39 +0900577}
578
Sungjoong Kang0f26b202012-08-17 15:43:12 -0700579void RequestManager::UpdateIspParameters(struct camera2_shot_ext *shot_ext, int frameCnt, bool afTrigger)
Sungjoong Kang13d8c7b2012-07-14 10:20:39 +0900580{
Sungjoong Kang9dd63e12012-07-24 00:25:51 +0900581 int index, targetStreamIndex;
Sungjoong Kangb56dcc02012-08-08 13:38:09 -0700582 struct camera2_shot_ext * request_shot;
Sungjoong Kang9dd63e12012-07-24 00:25:51 +0900583
584 ALOGV("DEBUG(%s): updating info with frameCnt(%d)", __FUNCTION__, frameCnt);
585 if (frameCnt < 0)
Sungjoong Kang13d8c7b2012-07-14 10:20:39 +0900586 return;
Sungjoong Kang9dd63e12012-07-24 00:25:51 +0900587
588 index = FindEntryIndexByFrameCnt(frameCnt);
589 if (index == -1) {
590 ALOGE("ERR(%s): Cannot find entry for frameCnt(%d)", __FUNCTION__, frameCnt);
591 return;
592 }
593
Sungjoong Kang13d8c7b2012-07-14 10:20:39 +0900594 request_manager_entry * newEntry = &(entries[index]);
Sungjoong Kangad378612012-08-17 12:34:33 -0700595 request_shot = &(newEntry->internal_shot);
Sungjoong Kang2bdec062012-08-17 15:47:56 -0700596 memcpy(&(shot_ext->shot.ctl), &(request_shot->shot.ctl), sizeof(struct camera2_ctl));
Sungjoong Kang13d8c7b2012-07-14 10:20:39 +0900597 shot_ext->request_sensor = 1;
Sungjoong Kangad378612012-08-17 12:34:33 -0700598 shot_ext->dis_bypass = 1;
599 shot_ext->dnr_bypass = 1;
600 shot_ext->fd_bypass = 1;
601 shot_ext->setfile = 0;
602
Sungjoong Kang13d8c7b2012-07-14 10:20:39 +0900603 shot_ext->request_scc = 0;
604 shot_ext->request_scp = 0;
Sungjoong Kangad378612012-08-17 12:34:33 -0700605
Sungjoong Kang9dd63e12012-07-24 00:25:51 +0900606 shot_ext->shot.ctl.request.outputStreams[0] = 0;
607 shot_ext->shot.ctl.request.outputStreams[1] = 0;
608 shot_ext->shot.ctl.request.outputStreams[2] = 0;
609
Sungjoong Kang2bdec062012-08-17 15:47:56 -0700610 if (m_lastAaMode == request_shot->shot.ctl.aa.mode) {
611 shot_ext->shot.ctl.aa.mode = (enum aa_mode)(0);
612 }
613 else {
614 shot_ext->shot.ctl.aa.mode = request_shot->shot.ctl.aa.mode;
615 m_lastAaMode = (int)(shot_ext->shot.ctl.aa.mode);
616 }
617 if (m_lastAeMode == request_shot->shot.ctl.aa.aeMode) {
618 shot_ext->shot.ctl.aa.aeMode = (enum aa_aemode)(0);
619 }
620 else {
621 shot_ext->shot.ctl.aa.aeMode = request_shot->shot.ctl.aa.aeMode;
622 m_lastAeMode = (int)(shot_ext->shot.ctl.aa.aeMode);
623 }
624 if (m_lastAwbMode == request_shot->shot.ctl.aa.awbMode) {
625 shot_ext->shot.ctl.aa.awbMode = (enum aa_awbmode)(0);
626 }
627 else {
628 shot_ext->shot.ctl.aa.awbMode = request_shot->shot.ctl.aa.awbMode;
629 m_lastAwbMode = (int)(shot_ext->shot.ctl.aa.awbMode);
630 }
631 if (m_lastAeComp == request_shot->shot.ctl.aa.aeExpCompensation) {
632 shot_ext->shot.ctl.aa.aeExpCompensation = 0;
633 }
634 else {
635 shot_ext->shot.ctl.aa.aeExpCompensation = request_shot->shot.ctl.aa.aeExpCompensation;
636 m_lastAeComp = (int)(shot_ext->shot.ctl.aa.aeExpCompensation);
637 }
Sungjoong Kang0f26b202012-08-17 15:43:12 -0700638 if (afTrigger) {
639 ALOGE("### AF Trigger ");
640 shot_ext->shot.ctl.aa.afTrigger = 1;
641 shot_ext->shot.ctl.aa.afRegions[0] = 0;
642 shot_ext->shot.ctl.aa.afRegions[1] = 0;
643 shot_ext->shot.ctl.aa.afRegions[2] = 0;
644 shot_ext->shot.ctl.aa.afRegions[3] = 0;
645 shot_ext->shot.ctl.aa.afRegions[4] = 0;
646 }
647 else
648 shot_ext->shot.ctl.aa.afTrigger = 0;
Sungjoong Kang13d8c7b2012-07-14 10:20:39 +0900649 for (int i = 0; i < newEntry->output_stream_count; i++) {
Sungjoong Kangad378612012-08-17 12:34:33 -0700650 targetStreamIndex = newEntry->internal_shot.shot.ctl.request.outputStreams[i];
Sungjoong Kang13d8c7b2012-07-14 10:20:39 +0900651
652 if (targetStreamIndex==0) {
Sungjoong Kangad378612012-08-17 12:34:33 -0700653 ALOGV("DEBUG(%s): outputstreams(%d) is for scalerP", __FUNCTION__, i);
Sungjoong Kang13d8c7b2012-07-14 10:20:39 +0900654 shot_ext->request_scp = 1;
655 }
Sungjoong Kang9dd63e12012-07-24 00:25:51 +0900656 else if (targetStreamIndex == 1) {
Sungjoong Kangad378612012-08-17 12:34:33 -0700657 ALOGV("DEBUG(%s): outputstreams(%d) is for scalerC", __FUNCTION__, i);
Sungjoong Kang13d8c7b2012-07-14 10:20:39 +0900658 shot_ext->request_scc = 1;
Sungjoong Kang9dd63e12012-07-24 00:25:51 +0900659 }
660 else if (targetStreamIndex == 2) {
Sungjoong Kangad378612012-08-17 12:34:33 -0700661 ALOGV("DEBUG(%s): outputstreams(%d) is for scalerP (record)", __FUNCTION__, i);
Sungjoong Kang9dd63e12012-07-24 00:25:51 +0900662 shot_ext->request_scp = 1;
663 shot_ext->shot.ctl.request.outputStreams[2] = 1;
Sungjoong Kang2bdec062012-08-17 15:47:56 -0700664 shot_ext->shot.ctl.aa.aeTargetFpsRange[0] = 30;
665 shot_ext->shot.ctl.aa.aeTargetFpsRange[1] = 30;
Sungjoong Kang13d8c7b2012-07-14 10:20:39 +0900666 }
667 else {
Sungjoong Kangad378612012-08-17 12:34:33 -0700668 ALOGV("DEBUG(%s): outputstreams(%d) has abnormal value(%d)", __FUNCTION__, i, targetStreamIndex);
Sungjoong Kang13d8c7b2012-07-14 10:20:39 +0900669 }
670 }
Sungjoong Kang2bdec062012-08-17 15:47:56 -0700671 ALOGV("(%s): applied aa(%d) aemode(%d) expComp(%d), awb(%d) afmode(%d), ", __FUNCTION__,
672 (int)(shot_ext->shot.ctl.aa.mode), (int)(shot_ext->shot.ctl.aa.aeMode),
673 (int)(shot_ext->shot.ctl.aa.aeExpCompensation), (int)(shot_ext->shot.ctl.aa.awbMode),
674 (int)(shot_ext->shot.ctl.aa.afMode));
Sungjoong Kang13d8c7b2012-07-14 10:20:39 +0900675}
676
Sungjoong Kang9dd63e12012-07-24 00:25:51 +0900677int RequestManager::FindEntryIndexByFrameCnt(int frameCnt)
Sungjoong Kang13d8c7b2012-07-14 10:20:39 +0900678{
Sungjoong Kang9dd63e12012-07-24 00:25:51 +0900679 for (int i = 0 ; i < NUM_MAX_REQUEST_MGR_ENTRY ; i++) {
Sungjoong Kangbe494d12012-08-04 15:36:56 -0700680 if (entries[i].internal_shot.shot.ctl.request.frameCount == frameCnt)
Sungjoong Kang9dd63e12012-07-24 00:25:51 +0900681 return i;
682 }
683 return -1;
Sungjoong Kang13d8c7b2012-07-14 10:20:39 +0900684}
685
Sungjoong Kang9dd63e12012-07-24 00:25:51 +0900686void RequestManager::RegisterTimestamp(int frameCnt, nsecs_t * frameTime)
Sungjoong Kang13d8c7b2012-07-14 10:20:39 +0900687{
Sungjoong Kang9dd63e12012-07-24 00:25:51 +0900688 int index = FindEntryIndexByFrameCnt(frameCnt);
689 if (index == -1) {
690 ALOGE("ERR(%s): Cannot find entry for frameCnt(%d)", __FUNCTION__, frameCnt);
691 return;
692 }
693
694 request_manager_entry * currentEntry = &(entries[index]);
Sungjoong Kangbe494d12012-08-04 15:36:56 -0700695 currentEntry->internal_shot.shot.dm.sensor.timeStamp = *((uint64_t*)frameTime);
Sungjoong Kang9dd63e12012-07-24 00:25:51 +0900696 ALOGV("DEBUG(%s): applied timestamp for reqIndex(%d) frameCnt(%d) (%lld)", __FUNCTION__,
Sungjoong Kangbe494d12012-08-04 15:36:56 -0700697 index, frameCnt, currentEntry->internal_shot.shot.dm.sensor.timeStamp);
Sungjoong Kang9dd63e12012-07-24 00:25:51 +0900698}
699
Sungjoong Kangad378612012-08-17 12:34:33 -0700700uint64_t RequestManager::GetTimestamp(int index)
Sungjoong Kang9dd63e12012-07-24 00:25:51 +0900701{
Sungjoong Kangad378612012-08-17 12:34:33 -0700702
Sungjoong Kang9dd63e12012-07-24 00:25:51 +0900703 if (index == -1) {
Sungjoong Kangad378612012-08-17 12:34:33 -0700704 ALOGE("ERR(%s): Cannot find entry ", __FUNCTION__);
Sungjoong Kang9dd63e12012-07-24 00:25:51 +0900705 return 0;
706 }
707
Sungjoong Kang13d8c7b2012-07-14 10:20:39 +0900708 request_manager_entry * currentEntry = &(entries[index]);
Sungjoong Kangbe494d12012-08-04 15:36:56 -0700709 uint64_t frameTime = currentEntry->internal_shot.shot.dm.sensor.timeStamp;
Sungjoong Kang9dd63e12012-07-24 00:25:51 +0900710 ALOGV("DEBUG(%s): Returning timestamp for reqIndex(%d) (%lld)", __FUNCTION__, index, frameTime);
Sungjoong Kang13d8c7b2012-07-14 10:20:39 +0900711 return frameTime;
712}
713
Sungjoong Kang9dd63e12012-07-24 00:25:51 +0900714int RequestManager::FindFrameCnt(struct camera2_shot_ext * shot_ext)
715{
Sungjoong Kangad378612012-08-17 12:34:33 -0700716 int i;
717
Sungjoong Kangbe494d12012-08-04 15:36:56 -0700718 if (m_numOfEntries == 0) {
Sungjoong Kangad378612012-08-17 12:34:33 -0700719 ALOGV("(%s): No Entry found", __FUNCTION__);
Sungjoong Kangbe494d12012-08-04 15:36:56 -0700720 return -1;
721 }
Sungjoong Kangad378612012-08-17 12:34:33 -0700722
Sungjoong Kangbe494d12012-08-04 15:36:56 -0700723 for (i = 0 ; i < NUM_MAX_REQUEST_MGR_ENTRY ; i++) {
Sungjoong Kangad378612012-08-17 12:34:33 -0700724 if(entries[i].internal_shot.shot.ctl.request.frameCount != shot_ext->shot.ctl.request.frameCount)
Sungjoong Kangbe494d12012-08-04 15:36:56 -0700725 continue;
Sungjoong Kangad378612012-08-17 12:34:33 -0700726
727 if (entries[i].status == REQUESTED) {
728 entries[i].status = CAPTURED;
729 return entries[i].internal_shot.shot.ctl.request.frameCount;
Sungjoong Kangbe494d12012-08-04 15:36:56 -0700730 }
Sungjoong Kangad378612012-08-17 12:34:33 -0700731
Sungjoong Kangbe494d12012-08-04 15:36:56 -0700732 }
Sungjoong Kangad378612012-08-17 12:34:33 -0700733
734 ALOGD("(%s): No Entry found", __FUNCTION__);
735
Sungjoong Kangbe494d12012-08-04 15:36:56 -0700736 return -1;
Sungjoong Kang9dd63e12012-07-24 00:25:51 +0900737}
Sungjoong Kang13d8c7b2012-07-14 10:20:39 +0900738
Sungjoong Kangb5237e62012-07-27 07:39:05 -0700739void RequestManager::SetInitialSkip(int count)
740{
741 ALOGV("(%s): Pipeline Restarting. setting cnt(%d) - current(%d)", __FUNCTION__, count, m_sensorPipelineSkipCnt);
742 if (count > m_sensorPipelineSkipCnt)
743 m_sensorPipelineSkipCnt = count;
744}
745
Sungjoong Kangad378612012-08-17 12:34:33 -0700746int RequestManager::GetSkipCnt()
747{
748 ALOGV("(%s): skip cnt(%d)", __FUNCTION__, m_sensorPipelineSkipCnt);
749 if (m_sensorPipelineSkipCnt == 0)
750 return m_sensorPipelineSkipCnt;
751 else
752 return --m_sensorPipelineSkipCnt;
753}
754
Sungjoong Kang13d8c7b2012-07-14 10:20:39 +0900755void RequestManager::Dump(void)
756{
Sungjoong Kang13d8c7b2012-07-14 10:20:39 +0900757 int i = 0;
758 request_manager_entry * currentEntry;
Sungjoong Kangad378612012-08-17 12:34:33 -0700759 ALOGD("## Dump totalentry(%d), insert(%d), processing(%d), frame(%d)",
Sungjoong Kang13d8c7b2012-07-14 10:20:39 +0900760 m_numOfEntries,m_entryInsertionIndex,m_entryProcessingIndex, m_entryFrameOutputIndex);
761
762 for (i = 0 ; i < NUM_MAX_REQUEST_MGR_ENTRY ; i++) {
763 currentEntry = &(entries[i]);
Sungjoong Kangad378612012-08-17 12:34:33 -0700764 ALOGD("[%2d] status[%d] frameCnt[%3d] numOutput[%d] outstream[0]-%d outstream[1]-%d", i,
Sungjoong Kangbe494d12012-08-04 15:36:56 -0700765 currentEntry->status, currentEntry->internal_shot.shot.ctl.request.frameCount,
Sungjoong Kangad378612012-08-17 12:34:33 -0700766 currentEntry->output_stream_count,
767 currentEntry->internal_shot.shot.ctl.request.outputStreams[0],
768 currentEntry->internal_shot.shot.ctl.request.outputStreams[1]);
Sungjoong Kang13d8c7b2012-07-14 10:20:39 +0900769 }
770}
771
Sungjoong Kang9dd63e12012-07-24 00:25:51 +0900772int RequestManager::GetNextIndex(int index)
773{
774 index++;
775 if (index >= NUM_MAX_REQUEST_MGR_ENTRY)
776 index = 0;
777
778 return index;
779}
780
Sungjoong Kangdaa1fcd2012-08-08 11:49:43 -0700781ExynosCameraHWInterface2::ExynosCameraHWInterface2(int cameraId, camera2_device_t *dev, ExynosCamera2 * camera):
Jiyoung Shinc15a6b02012-06-05 01:08:14 -0700782 m_requestQueueOps(NULL),
783 m_frameQueueOps(NULL),
784 m_callbackCookie(NULL),
785 m_numOfRemainingReqInSvc(0),
786 m_isRequestQueuePending(false),
Sungjoong Kang13d8c7b2012-07-14 10:20:39 +0900787 m_isRequestQueueNull(true),
Jiyoung Shinc15a6b02012-06-05 01:08:14 -0700788 m_isSensorThreadOn(false),
Sungjoong Kang13d8c7b2012-07-14 10:20:39 +0900789 m_isSensorStarted(false),
Sungjoong Kangad378612012-08-17 12:34:33 -0700790 m_isIspStarted(false),
Sungjoong Kang13d8c7b2012-07-14 10:20:39 +0900791 m_ionCameraClient(0),
792 m_initFlag1(false),
793 m_initFlag2(false),
Sungjoong Kang13d8c7b2012-07-14 10:20:39 +0900794 m_scp_flushing(false),
795 m_closing(false),
Sungjoong Kang9dd63e12012-07-24 00:25:51 +0900796 m_recordingEnabled(false),
797 m_needsRecordBufferInit(false),
798 lastFrameCnt(-1),
799 m_scp_closing(false),
800 m_scp_closed(false),
Sungjoong Kang0f26b202012-08-17 15:43:12 -0700801 m_afState(HAL_AFSTATE_INACTIVE),
802 m_afMode(NO_CHANGE),
803 m_afMode2(NO_CHANGE),
804 m_IsAfModeUpdateRequired(false),
805 m_IsAfTriggerRequired(false),
806 m_IsAfLockRequired(false),
807 m_afTriggerId(0),
Sungjoong Kang9dd63e12012-07-24 00:25:51 +0900808 m_halDevice(dev),
Sungjoong Kangad378612012-08-17 12:34:33 -0700809 m_need_streamoff(0),
Sungjoong Kangbe494d12012-08-04 15:36:56 -0700810 m_cameraId(cameraId)
Jiyoung Shinc15a6b02012-06-05 01:08:14 -0700811{
Sungjoong Kang13d8c7b2012-07-14 10:20:39 +0900812 ALOGV("DEBUG(%s):", __FUNCTION__);
Jiyoung Shinc15a6b02012-06-05 01:08:14 -0700813 int ret = 0;
814
Sungjoong Kang13d8c7b2012-07-14 10:20:39 +0900815 m_exynosPictureCSC = NULL;
Sungjoong Kang9dd63e12012-07-24 00:25:51 +0900816 m_exynosVideoCSC = NULL;
Sungjoong Kang13d8c7b2012-07-14 10:20:39 +0900817
Jiyoung Shinc15a6b02012-06-05 01:08:14 -0700818 if (!m_grallocHal) {
819 ret = hw_get_module(GRALLOC_HARDWARE_MODULE_ID, (const hw_module_t **)&m_grallocHal);
820 if (ret)
Sungjoong Kang13d8c7b2012-07-14 10:20:39 +0900821 ALOGE("ERR(%s):Fail on loading gralloc HAL", __FUNCTION__);
822 }
Jiyoung Shinc15a6b02012-06-05 01:08:14 -0700823
Sungjoong Kangdaa1fcd2012-08-08 11:49:43 -0700824 m_camera2 = camera;
Jiyoung Shinc15a6b02012-06-05 01:08:14 -0700825 m_ionCameraClient = createIonClient(m_ionCameraClient);
826 if(m_ionCameraClient == 0)
Sungjoong Kang13d8c7b2012-07-14 10:20:39 +0900827 ALOGE("ERR(%s):Fail on ion_client_create", __FUNCTION__);
Jiyoung Shinc15a6b02012-06-05 01:08:14 -0700828
Sungjoong Kang9dd63e12012-07-24 00:25:51 +0900829
830 m_BayerManager = new BayerBufManager();
Jiyoung Shinc15a6b02012-06-05 01:08:14 -0700831 m_mainThread = new MainThread(this);
Sungjoong Kangad378612012-08-17 12:34:33 -0700832 InitializeISPChain();
Jiyoung Shinc15a6b02012-06-05 01:08:14 -0700833 m_sensorThread = new SensorThread(this);
Sungjoong Kang13d8c7b2012-07-14 10:20:39 +0900834 m_mainThread->Start("MainThread", PRIORITY_DEFAULT, 0);
835 ALOGV("DEBUG(%s): created sensorthread ################", __FUNCTION__);
Jiyoung Shinc15a6b02012-06-05 01:08:14 -0700836
Sungjoong Kang13d8c7b2012-07-14 10:20:39 +0900837 m_requestManager = new RequestManager((SignalDrivenThread*)(m_mainThread.get()));
838 CSC_METHOD cscMethod = CSC_METHOD_HW;
839 m_exynosPictureCSC = csc_init(cscMethod);
840 if (m_exynosPictureCSC == NULL)
841 ALOGE("ERR(%s): csc_init() fail", __FUNCTION__);
842 csc_set_hw_property(m_exynosPictureCSC, CSC_HW_PROPERTY_FIXED_NODE, PICTURE_GSC_NODE_NUM);
843
Sungjoong Kang9dd63e12012-07-24 00:25:51 +0900844 m_exynosVideoCSC = csc_init(cscMethod);
845 if (m_exynosVideoCSC == NULL)
846 ALOGE("ERR(%s): csc_init() fail", __FUNCTION__);
847 csc_set_hw_property(m_exynosVideoCSC, CSC_HW_PROPERTY_FIXED_NODE, PREVIEW_GSC_NODE_NUM);
848
Sungjoong Kang13d8c7b2012-07-14 10:20:39 +0900849 ALOGV("DEBUG(%s): END", __FUNCTION__);
Jiyoung Shinc15a6b02012-06-05 01:08:14 -0700850}
851
852ExynosCameraHWInterface2::~ExynosCameraHWInterface2()
853{
Sungjoong Kangad378612012-08-17 12:34:33 -0700854 ALOGV("%s: ENTER", __FUNCTION__);
Jiyoung Shinc15a6b02012-06-05 01:08:14 -0700855 this->release();
Sungjoong Kangad378612012-08-17 12:34:33 -0700856 ALOGV("%s: EXIT", __FUNCTION__);
Jiyoung Shinc15a6b02012-06-05 01:08:14 -0700857}
858
859void ExynosCameraHWInterface2::release()
860{
Sungjoong Kang13d8c7b2012-07-14 10:20:39 +0900861 int i, res;
Sungjoong Kang9dd63e12012-07-24 00:25:51 +0900862 ALOGD("%s: ENTER", __func__);
Sungjoong Kang13d8c7b2012-07-14 10:20:39 +0900863 m_closing = true;
Sungjoong Kang9dd63e12012-07-24 00:25:51 +0900864
Sungjoong Kangad378612012-08-17 12:34:33 -0700865 if (m_streamThreads[1] != NULL) {
866 m_streamThreads[1]->release();
867 m_streamThreads[1]->SetSignal(SIGNAL_THREAD_TERMINATE);
868 }
869
870 if (m_streamThreads[0] != NULL) {
871 m_streamThreads[0]->release();
872 m_streamThreads[0]->SetSignal(SIGNAL_THREAD_TERMINATE);
873 }
874
Sungjoong Kang13d8c7b2012-07-14 10:20:39 +0900875 if (m_ispThread != NULL) {
876 m_ispThread->release();
Sungjoong Kang13d8c7b2012-07-14 10:20:39 +0900877 }
878
879 if (m_sensorThread != NULL) {
880 m_sensorThread->release();
Sungjoong Kang13d8c7b2012-07-14 10:20:39 +0900881 }
Jiyoung Shinc15a6b02012-06-05 01:08:14 -0700882
883 if (m_mainThread != NULL) {
Sungjoong Kang13d8c7b2012-07-14 10:20:39 +0900884 m_mainThread->release();
Jiyoung Shinc15a6b02012-06-05 01:08:14 -0700885 }
Jiyoung Shinc15a6b02012-06-05 01:08:14 -0700886
Sungjoong Kang13d8c7b2012-07-14 10:20:39 +0900887 if (m_exynosPictureCSC)
888 csc_deinit(m_exynosPictureCSC);
889 m_exynosPictureCSC = NULL;
890
Sungjoong Kang9dd63e12012-07-24 00:25:51 +0900891 if (m_exynosVideoCSC)
892 csc_deinit(m_exynosVideoCSC);
893 m_exynosVideoCSC = NULL;
894
Sungjoong Kangad378612012-08-17 12:34:33 -0700895 if (m_streamThreads[1] != NULL) {
896 while (!m_streamThreads[1]->IsTerminated())
897 {
898 ALOGD("Waiting for ISP thread is tetminated");
899 usleep(100000);
900 }
901 m_streamThreads[1] = NULL;
902 }
903
904 if (m_streamThreads[0] != NULL) {
905 while (!m_streamThreads[0]->IsTerminated())
906 {
907 ALOGD("Waiting for sensor thread is tetminated");
908 usleep(100000);
909 }
910 m_streamThreads[0] = NULL;
911 }
912
Sungjoong Kang9dd63e12012-07-24 00:25:51 +0900913 if (m_ispThread != NULL) {
914 while (!m_ispThread->IsTerminated())
Sungjoong Kangad378612012-08-17 12:34:33 -0700915 {
916 ALOGD("Waiting for isp thread is tetminated");
917 usleep(100000);
918 }
Sungjoong Kang9dd63e12012-07-24 00:25:51 +0900919 m_ispThread = NULL;
920 }
921
922 if (m_sensorThread != NULL) {
923 while (!m_sensorThread->IsTerminated())
Sungjoong Kangad378612012-08-17 12:34:33 -0700924 {
925 ALOGD("Waiting for sensor thread is tetminated");
926 usleep(100000);
927 }
Sungjoong Kang9dd63e12012-07-24 00:25:51 +0900928 m_sensorThread = NULL;
929 }
930
Sungjoong Kangad378612012-08-17 12:34:33 -0700931 if (m_mainThread != NULL) {
Sungjoong Kang9dd63e12012-07-24 00:25:51 +0900932 while (!m_mainThread->IsTerminated())
Sungjoong Kangad378612012-08-17 12:34:33 -0700933 {
934 ALOGD("Waiting for main thread is tetminated");
935 usleep(100000);
936 }
Sungjoong Kang9dd63e12012-07-24 00:25:51 +0900937 m_mainThread = NULL;
938 }
939
Jiyoung Shinc15a6b02012-06-05 01:08:14 -0700940 for(i = 0; i < m_camera_info.sensor.buffers; i++)
941 freeCameraMemory(&m_camera_info.sensor.buffer[i], m_camera_info.sensor.planes);
942
Jiyoung Shinc15a6b02012-06-05 01:08:14 -0700943 for(i = 0; i < m_camera_info.capture.buffers; i++)
944 freeCameraMemory(&m_camera_info.capture.buffer[i], m_camera_info.capture.planes);
945
Sungjoong Kang9dd63e12012-07-24 00:25:51 +0900946 ALOGV("DEBUG(%s): calling exynos_v4l2_close - sensor", __FUNCTION__);
Sungjoong Kang13d8c7b2012-07-14 10:20:39 +0900947 res = exynos_v4l2_close(m_camera_info.sensor.fd);
948 if (res != NO_ERROR ) {
Sungjoong Kang9dd63e12012-07-24 00:25:51 +0900949 ALOGE("ERR(%s): exynos_v4l2_close failed(%d)",__FUNCTION__ , res);
Sungjoong Kang13d8c7b2012-07-14 10:20:39 +0900950 }
951
Sungjoong Kang9dd63e12012-07-24 00:25:51 +0900952 ALOGV("DEBUG(%s): calling exynos_v4l2_close - isp", __FUNCTION__);
Sungjoong Kang13d8c7b2012-07-14 10:20:39 +0900953 res = exynos_v4l2_close(m_camera_info.isp.fd);
954 if (res != NO_ERROR ) {
Sungjoong Kang9dd63e12012-07-24 00:25:51 +0900955 ALOGE("ERR(%s): exynos_v4l2_close failed(%d)",__FUNCTION__ , res);
Sungjoong Kang13d8c7b2012-07-14 10:20:39 +0900956 }
957
Sungjoong Kang9dd63e12012-07-24 00:25:51 +0900958 ALOGV("DEBUG(%s): calling exynos_v4l2_close - capture", __FUNCTION__);
Sungjoong Kang13d8c7b2012-07-14 10:20:39 +0900959 res = exynos_v4l2_close(m_camera_info.capture.fd);
960 if (res != NO_ERROR ) {
Sungjoong Kang9dd63e12012-07-24 00:25:51 +0900961 ALOGE("ERR(%s): exynos_v4l2_close failed(%d)",__FUNCTION__ , res);
Sungjoong Kang13d8c7b2012-07-14 10:20:39 +0900962 }
963
Sungjoong Kang9dd63e12012-07-24 00:25:51 +0900964 ALOGV("DEBUG(%s): calling exynos_v4l2_close - scp", __FUNCTION__);
Sungjoong Kangad378612012-08-17 12:34:33 -0700965 res = exynos_v4l2_close(m_fd_scp);
Sungjoong Kang13d8c7b2012-07-14 10:20:39 +0900966 if (res != NO_ERROR ) {
Sungjoong Kang9dd63e12012-07-24 00:25:51 +0900967 ALOGE("ERR(%s): exynos_v4l2_close failed(%d)",__FUNCTION__ , res);
Sungjoong Kang13d8c7b2012-07-14 10:20:39 +0900968 }
Sungjoong Kang9dd63e12012-07-24 00:25:51 +0900969 ALOGV("DEBUG(%s): calling deleteIonClient", __FUNCTION__);
Jiyoung Shinc15a6b02012-06-05 01:08:14 -0700970 deleteIonClient(m_ionCameraClient);
Sungjoong Kangad378612012-08-17 12:34:33 -0700971
972 ALOGV("%s: EXIT", __func__);
973}
974
975void ExynosCameraHWInterface2::InitializeISPChain()
976{
977 char node_name[30];
978 int fd = 0;
979 int i;
980
981 /* Open Sensor */
982 memset(&node_name, 0x00, sizeof(char[30]));
983 sprintf(node_name, "%s%d", NODE_PREFIX, 40);
984 fd = exynos_v4l2_open(node_name, O_RDWR, 0);
985
986 if (fd < 0) {
987 ALOGE("ERR(%s): failed to open sensor video node (%s) fd (%d)", __FUNCTION__,node_name, fd);
988 }
989 else {
990 ALOGV("DEBUG(%s): sensor video node opened(%s) fd (%d)", __FUNCTION__,node_name, fd);
991 }
992 m_camera_info.sensor.fd = fd;
993
994 /* Open ISP */
995 memset(&node_name, 0x00, sizeof(char[30]));
996 sprintf(node_name, "%s%d", NODE_PREFIX, 41);
997 fd = exynos_v4l2_open(node_name, O_RDWR, 0);
998
999 if (fd < 0) {
1000 ALOGE("ERR(%s): failed to open isp video node (%s) fd (%d)", __FUNCTION__,node_name, fd);
1001 }
1002 else {
1003 ALOGV("DEBUG(%s): isp video node opened(%s) fd (%d)", __FUNCTION__,node_name, fd);
1004 }
1005 m_camera_info.isp.fd = fd;
1006
1007 /* Open ScalerC */
1008 memset(&node_name, 0x00, sizeof(char[30]));
1009 sprintf(node_name, "%s%d", NODE_PREFIX, 42);
1010 fd = exynos_v4l2_open(node_name, O_RDWR, 0);
1011
1012 if (fd < 0) {
1013 ALOGE("ERR(%s): failed to open capture video node (%s) fd (%d)", __FUNCTION__,node_name, fd);
1014 }
1015 else {
1016 ALOGV("DEBUG(%s): capture video node opened(%s) fd (%d)", __FUNCTION__,node_name, fd);
1017 }
1018 m_camera_info.capture.fd = fd;
1019
1020 /* Open ScalerP */
1021 memset(&node_name, 0x00, sizeof(char[30]));
1022 sprintf(node_name, "%s%d", NODE_PREFIX, 44);
1023 fd = exynos_v4l2_open(node_name, O_RDWR, 0);
1024 if (fd < 0) {
1025 ALOGE("DEBUG(%s): failed to open preview video node (%s) fd (%d)", __FUNCTION__,node_name, fd);
1026 }
1027 else {
1028 ALOGV("DEBUG(%s): preview video node opened(%s) fd (%d)", __FUNCTION__,node_name, fd);
1029 }
1030 m_fd_scp = fd;
1031
1032 if(m_cameraId == 0)
1033 m_camera_info.sensor_id = SENSOR_NAME_S5K4E5;
1034 else
1035 m_camera_info.sensor_id = SENSOR_NAME_S5K6A3;
1036
1037 memset(&m_camera_info.dummy_shot, 0x00, sizeof(struct camera2_shot_ext));
1038 m_camera_info.dummy_shot.shot.ctl.request.metadataMode = METADATA_MODE_FULL;
1039 m_camera_info.dummy_shot.shot.magicNumber = 0x23456789;
1040
1041 m_camera_info.dummy_shot.dis_bypass = 1;
1042 m_camera_info.dummy_shot.dnr_bypass = 1;
1043 m_camera_info.dummy_shot.fd_bypass = 1;
1044
1045 /*sensor setting*/
1046 m_camera_info.dummy_shot.shot.ctl.sensor.exposureTime = 0;
1047 m_camera_info.dummy_shot.shot.ctl.sensor.frameDuration = 0;
1048 m_camera_info.dummy_shot.shot.ctl.sensor.sensitivity = 0;
1049
1050 m_camera_info.dummy_shot.shot.ctl.scaler.cropRegion[0] = 0;
1051 m_camera_info.dummy_shot.shot.ctl.scaler.cropRegion[1] = 0;
1052
1053 /*request setting*/
1054 m_camera_info.dummy_shot.request_sensor = 1;
1055 m_camera_info.dummy_shot.request_scc = 0;
1056 m_camera_info.dummy_shot.request_scp = 0;
1057 m_camera_info.dummy_shot.shot.ctl.request.outputStreams[0] = 0;
1058 m_camera_info.dummy_shot.shot.ctl.request.outputStreams[1] = 0;
1059 m_camera_info.dummy_shot.shot.ctl.request.outputStreams[2] = 0;
1060
1061 m_camera_info.sensor.width = m_camera2->getSensorRawW();
1062 m_camera_info.sensor.height = m_camera2->getSensorRawH();
1063
1064 m_camera_info.sensor.format = V4L2_PIX_FMT_SBGGR16;
1065 m_camera_info.sensor.planes = 2;
1066 m_camera_info.sensor.buffers = NUM_BAYER_BUFFERS;
1067 m_camera_info.sensor.type = V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE;
1068 m_camera_info.sensor.memory = V4L2_MEMORY_DMABUF;
1069 m_camera_info.sensor.ionClient = m_ionCameraClient;
1070
1071 for(i = 0; i < m_camera_info.sensor.buffers; i++){
1072 initCameraMemory(&m_camera_info.sensor.buffer[i], m_camera_info.sensor.planes);
1073 m_camera_info.sensor.buffer[i].size.extS[0] = m_camera_info.sensor.width*m_camera_info.sensor.height*2;
1074 m_camera_info.sensor.buffer[i].size.extS[1] = 8*1024; // HACK, driver use 8*1024, should be use predefined value
1075 allocCameraMemory(m_camera_info.sensor.ionClient, &m_camera_info.sensor.buffer[i], m_camera_info.sensor.planes);
1076 }
1077
1078 m_camera_info.isp.width = m_camera_info.sensor.width;
1079 m_camera_info.isp.height = m_camera_info.sensor.height;
1080 m_camera_info.isp.format = m_camera_info.sensor.format;
1081 m_camera_info.isp.planes = m_camera_info.sensor.planes;
1082 m_camera_info.isp.buffers = m_camera_info.sensor.buffers;
1083 m_camera_info.isp.type = V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE;
1084 m_camera_info.isp.memory = V4L2_MEMORY_DMABUF;
1085 m_camera_info.isp.ionClient = m_ionCameraClient;
1086
1087 for(i = 0; i < m_camera_info.isp.buffers; i++){
1088 initCameraMemory(&m_camera_info.isp.buffer[i], m_camera_info.isp.planes);
1089 m_camera_info.isp.buffer[i].size.extS[0] = m_camera_info.sensor.buffer[i].size.extS[0];
1090 m_camera_info.isp.buffer[i].size.extS[1] = m_camera_info.sensor.buffer[i].size.extS[1];
1091 m_camera_info.isp.buffer[i].fd.extFd[0] = m_camera_info.sensor.buffer[i].fd.extFd[0];
1092 m_camera_info.isp.buffer[i].fd.extFd[1] = m_camera_info.sensor.buffer[i].fd.extFd[1];
1093 m_camera_info.isp.buffer[i].virt.extP[0] = m_camera_info.sensor.buffer[i].virt.extP[0];
1094 m_camera_info.isp.buffer[i].virt.extP[1] = m_camera_info.sensor.buffer[i].virt.extP[1];
1095 };
1096
1097 /* init ISP */
1098 cam_int_s_input(&(m_camera_info.isp), m_camera_info.sensor_id);
1099 cam_int_s_fmt(&(m_camera_info.isp));
1100 ALOGV("DEBUG(%s): isp calling reqbuf", __FUNCTION__);
1101 cam_int_reqbufs(&(m_camera_info.isp));
1102 ALOGV("DEBUG(%s): isp calling querybuf", __FUNCTION__);
1103 ALOGV("DEBUG(%s): isp mem alloc done", __FUNCTION__);
1104
1105 /* init Sensor */
1106 cam_int_s_input(&(m_camera_info.sensor), m_camera_info.sensor_id);
1107 ALOGV("DEBUG(%s): sensor s_input done", __FUNCTION__);
1108 if (cam_int_s_fmt(&(m_camera_info.sensor))< 0) {
1109 ALOGE("ERR(%s): sensor s_fmt fail", __FUNCTION__);
1110 }
1111 ALOGV("DEBUG(%s): sensor s_fmt done", __FUNCTION__);
1112 cam_int_reqbufs(&(m_camera_info.sensor));
1113 ALOGV("DEBUG(%s): sensor reqbuf done", __FUNCTION__);
1114 for (i = 0; i < m_camera_info.sensor.buffers; i++) {
1115 ALOGV("DEBUG(%s): sensor initial QBUF [%d]", __FUNCTION__, i);
1116 memcpy( m_camera_info.sensor.buffer[i].virt.extP[1], &(m_camera_info.dummy_shot),
1117 sizeof(struct camera2_shot_ext));
1118 m_camera_info.dummy_shot.shot.ctl.sensor.frameDuration = 33*1000*1000; // apply from frame #1
1119 m_camera_info.dummy_shot.shot.ctl.request.frameCount = -1;
1120 cam_int_qbuf(&(m_camera_info.sensor), i);
1121 }
1122 ALOGV("== stream_on :: .sensor");
1123 cam_int_streamon(&(m_camera_info.sensor));
1124
1125 /* init Capture */
1126 m_camera_info.capture.width = m_camera2->getSensorW();
1127 m_camera_info.capture.height = m_camera2->getSensorH();
1128 m_camera_info.capture.format = V4L2_PIX_FMT_YUYV;
1129 m_camera_info.capture.planes = 1;
1130 m_camera_info.capture.buffers = 8;
1131 m_camera_info.capture.type = V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE;
1132 m_camera_info.capture.memory = V4L2_MEMORY_DMABUF;
1133 m_camera_info.capture.ionClient = m_ionCameraClient;
1134
1135 for(i = 0; i < m_camera_info.capture.buffers; i++){
1136 initCameraMemory(&m_camera_info.capture.buffer[i], m_camera_info.capture.planes);
1137 m_camera_info.capture.buffer[i].size.extS[0] = m_camera_info.capture.width*m_camera_info.capture.height*2;
1138 allocCameraMemory(m_camera_info.capture.ionClient, &m_camera_info.capture.buffer[i], m_camera_info.capture.planes);
1139 }
1140
1141 cam_int_s_input(&(m_camera_info.capture), m_camera_info.sensor_id);
1142 cam_int_s_fmt(&(m_camera_info.capture));
1143 ALOGV("DEBUG(%s): capture calling reqbuf", __FUNCTION__);
1144 cam_int_reqbufs(&(m_camera_info.capture));
1145 ALOGV("DEBUG(%s): capture calling querybuf", __FUNCTION__);
1146
1147 for (i = 0; i < m_camera_info.capture.buffers; i++) {
1148 ALOGV("DEBUG(%s): capture initial QBUF [%d]", __FUNCTION__, i);
1149 cam_int_qbuf(&(m_camera_info.capture), i);
1150 }
1151
1152 ALOGV("== stream_on :: capture");
1153 cam_int_streamon(&(m_camera_info.capture));
1154}
1155
1156void ExynosCameraHWInterface2::StartISP()
1157{
1158 int i;
1159
1160 for (i = 0; i < m_camera_info.isp.buffers; i++) {
1161 ALOGV("DEBUG(%s): isp initial QBUF [%d]", __FUNCTION__, i);
1162 cam_int_qbuf(&(m_camera_info.isp), i);
1163 }
1164
1165 ALOGV("== stream_on :: isp");
1166 cam_int_streamon(&(m_camera_info.isp));
1167
1168 for (i = 0; i < m_camera_info.isp.buffers; i++) {
1169 ALOGV("DEBUG(%s): isp initial DQBUF [%d]", __FUNCTION__, i);
1170 cam_int_dqbuf(&(m_camera_info.isp));
1171 }
1172 exynos_v4l2_s_ctrl(m_camera_info.sensor.fd, V4L2_CID_IS_S_STREAM, IS_ENABLE_STREAM);
Sungjoong Kang13d8c7b2012-07-14 10:20:39 +09001173}
1174
Jiyoung Shinc15a6b02012-06-05 01:08:14 -07001175int ExynosCameraHWInterface2::getCameraId() const
1176{
Sungjoong Kang9dd63e12012-07-24 00:25:51 +09001177 return m_cameraId;
Jiyoung Shinc15a6b02012-06-05 01:08:14 -07001178}
Jiyoung Shinc15a6b02012-06-05 01:08:14 -07001179
1180int ExynosCameraHWInterface2::setRequestQueueSrcOps(const camera2_request_queue_src_ops_t *request_src_ops)
1181{
Sungjoong Kang13d8c7b2012-07-14 10:20:39 +09001182 ALOGV("DEBUG(%s):", __FUNCTION__);
Jiyoung Shinc15a6b02012-06-05 01:08:14 -07001183 if ((NULL != request_src_ops) && (NULL != request_src_ops->dequeue_request)
1184 && (NULL != request_src_ops->free_request) && (NULL != request_src_ops->request_count)) {
1185 m_requestQueueOps = (camera2_request_queue_src_ops_t*)request_src_ops;
1186 return 0;
1187 }
1188 else {
Sungjoong Kang13d8c7b2012-07-14 10:20:39 +09001189 ALOGE("DEBUG(%s):setRequestQueueSrcOps : NULL arguments", __FUNCTION__);
Jiyoung Shinc15a6b02012-06-05 01:08:14 -07001190 return 1;
1191 }
1192}
1193
1194int ExynosCameraHWInterface2::notifyRequestQueueNotEmpty()
1195{
Sungjoong Kangb5237e62012-07-27 07:39:05 -07001196 ALOGV("DEBUG(%s):setting [SIGNAL_MAIN_REQ_Q_NOT_EMPTY] current(%d)", __FUNCTION__, m_requestManager->GetNumEntries());
Jiyoung Shinc15a6b02012-06-05 01:08:14 -07001197 if ((NULL==m_frameQueueOps)|| (NULL==m_requestQueueOps)) {
Sungjoong Kang13d8c7b2012-07-14 10:20:39 +09001198 ALOGE("DEBUG(%s):queue ops NULL. ignoring request", __FUNCTION__);
Jiyoung Shinc15a6b02012-06-05 01:08:14 -07001199 return 0;
1200 }
Sungjoong Kang13d8c7b2012-07-14 10:20:39 +09001201 m_isRequestQueueNull = false;
Sungjoong Kang0f26b202012-08-17 15:43:12 -07001202 if (m_requestManager->GetNumEntries() == 0)
1203 m_requestManager->SetInitialSkip(5);
Jiyoung Shinc15a6b02012-06-05 01:08:14 -07001204 m_mainThread->SetSignal(SIGNAL_MAIN_REQ_Q_NOT_EMPTY);
1205 return 0;
1206}
1207
1208int ExynosCameraHWInterface2::setFrameQueueDstOps(const camera2_frame_queue_dst_ops_t *frame_dst_ops)
1209{
Sungjoong Kang13d8c7b2012-07-14 10:20:39 +09001210 ALOGV("DEBUG(%s):", __FUNCTION__);
Jiyoung Shinc15a6b02012-06-05 01:08:14 -07001211 if ((NULL != frame_dst_ops) && (NULL != frame_dst_ops->dequeue_frame)
1212 && (NULL != frame_dst_ops->cancel_frame) && (NULL !=frame_dst_ops->enqueue_frame)) {
1213 m_frameQueueOps = (camera2_frame_queue_dst_ops_t *)frame_dst_ops;
1214 return 0;
1215 }
1216 else {
Sungjoong Kang13d8c7b2012-07-14 10:20:39 +09001217 ALOGE("DEBUG(%s):setFrameQueueDstOps : NULL arguments", __FUNCTION__);
Jiyoung Shinc15a6b02012-06-05 01:08:14 -07001218 return 1;
1219 }
1220}
1221
1222int ExynosCameraHWInterface2::getInProgressCount()
1223{
1224 int inProgressCount = m_requestManager->GetNumEntries();
Sungjoong Kang13d8c7b2012-07-14 10:20:39 +09001225 ALOGV("DEBUG(%s): # of dequeued req (%d)", __FUNCTION__, inProgressCount);
Jiyoung Shinc15a6b02012-06-05 01:08:14 -07001226 return inProgressCount;
1227}
1228
1229int ExynosCameraHWInterface2::flushCapturesInProgress()
1230{
1231 return 0;
1232}
1233
Jiyoung Shinc15a6b02012-06-05 01:08:14 -07001234int ExynosCameraHWInterface2::constructDefaultRequest(int request_template, camera_metadata_t **request)
1235{
Sungjoong Kang13d8c7b2012-07-14 10:20:39 +09001236 ALOGV("DEBUG(%s): making template (%d) ", __FUNCTION__, request_template);
Jiyoung Shinc15a6b02012-06-05 01:08:14 -07001237
1238 if (request == NULL) return BAD_VALUE;
1239 if (request_template < 0 || request_template >= CAMERA2_TEMPLATE_COUNT) {
1240 return BAD_VALUE;
1241 }
1242 status_t res;
1243 // Pass 1, calculate size and allocate
Sungjoong Kangdaa1fcd2012-08-08 11:49:43 -07001244 res = m_camera2->constructDefaultRequest(request_template,
Jiyoung Shinc15a6b02012-06-05 01:08:14 -07001245 request,
1246 true);
1247 if (res != OK) {
1248 return res;
1249 }
1250 // Pass 2, build request
Sungjoong Kangdaa1fcd2012-08-08 11:49:43 -07001251 res = m_camera2->constructDefaultRequest(request_template,
Jiyoung Shinc15a6b02012-06-05 01:08:14 -07001252 request,
1253 false);
1254 if (res != OK) {
1255 ALOGE("Unable to populate new request for template %d",
1256 request_template);
1257 }
1258
1259 return res;
1260}
1261
1262int ExynosCameraHWInterface2::allocateStream(uint32_t width, uint32_t height, int format, const camera2_stream_ops_t *stream_ops,
1263 uint32_t *stream_id, uint32_t *format_actual, uint32_t *usage, uint32_t *max_buffers)
1264{
Sungjoong Kangad378612012-08-17 12:34:33 -07001265 ALOGV("DEBUG(%s): allocate stream width(%d) height(%d) format(%x)", __FUNCTION__, width, height, format);
Jiyoung Shinc15a6b02012-06-05 01:08:14 -07001266 char node_name[30];
Sungjoong Kang9dd63e12012-07-24 00:25:51 +09001267 int fd = 0, allocCase = 0;
Sungjoong Kang13d8c7b2012-07-14 10:20:39 +09001268 StreamThread *AllocatedStream;
1269 stream_parameters_t newParameters;
Jiyoung Shinc15a6b02012-06-05 01:08:14 -07001270
Sungjoong Kangdaa1fcd2012-08-08 11:49:43 -07001271 if (format == CAMERA2_HAL_PIXEL_FORMAT_OPAQUE &&
1272 m_camera2->isSupportedResolution(width, height)) {
Sungjoong Kang9dd63e12012-07-24 00:25:51 +09001273 if (!(m_streamThreads[0].get())) {
1274 ALOGV("DEBUG(%s): stream 0 not exist", __FUNCTION__);
1275 allocCase = 0;
Jiyoung Shinc15a6b02012-06-05 01:08:14 -07001276 }
Sungjoong Kang13d8c7b2012-07-14 10:20:39 +09001277 else {
Alex Ray6bbb5932012-07-27 17:19:48 -07001278 if ((m_streamThreads[0].get())->m_activated == true) {
Sungjoong Kang9dd63e12012-07-24 00:25:51 +09001279 ALOGV("DEBUG(%s): stream 0 exists and activated.", __FUNCTION__);
1280 allocCase = 1;
1281 }
1282 else {
1283 ALOGV("DEBUG(%s): stream 0 exists and deactivated.", __FUNCTION__);
1284 allocCase = 2;
1285 }
Sungjoong Kang13d8c7b2012-07-14 10:20:39 +09001286 }
Sungjoong Kang9dd63e12012-07-24 00:25:51 +09001287 if (allocCase == 0 || allocCase == 2) {
1288 *stream_id = 0;
Jiyoung Shinc15a6b02012-06-05 01:08:14 -07001289
Sungjoong Kang9dd63e12012-07-24 00:25:51 +09001290 if (allocCase == 0) {
1291 m_streamThreads[0] = new StreamThread(this, *stream_id);
Sungjoong Kang9dd63e12012-07-24 00:25:51 +09001292 }
1293 AllocatedStream = (StreamThread*)(m_streamThreads[0].get());
Sungjoong Kangb5237e62012-07-27 07:39:05 -07001294 m_scp_flushing = false;
1295 m_scp_closing = false;
1296 m_scp_closed = false;
Sungjoong Kang9dd63e12012-07-24 00:25:51 +09001297 usleep(100000); // TODO : guarantee the codes below will be run after readyToRunInternal()
Jiyoung Shinc15a6b02012-06-05 01:08:14 -07001298
Rebecca Schultz Zavinc853be72012-08-23 00:03:05 -07001299 *format_actual = HAL_PIXEL_FORMAT_EXYNOS_YV12;
Alex Ray6bbb5932012-07-27 17:19:48 -07001300 *usage = GRALLOC_USAGE_SW_WRITE_OFTEN;
Sungjoong Kang9dd63e12012-07-24 00:25:51 +09001301 *max_buffers = 8;
Jiyoung Shinc15a6b02012-06-05 01:08:14 -07001302
Sungjoong Kang37e122d2012-08-08 11:13:48 -07001303 newParameters.streamType = STREAM_TYPE_DIRECT;
Sungjoong Kang9dd63e12012-07-24 00:25:51 +09001304 newParameters.outputWidth = width;
1305 newParameters.outputHeight = height;
1306 newParameters.nodeWidth = width;
1307 newParameters.nodeHeight = height;
1308 newParameters.outputFormat = *format_actual;
1309 newParameters.nodeFormat = HAL_PIXEL_FORMAT_2_V4L2_PIX(*format_actual);
1310 newParameters.streamOps = stream_ops;
1311 newParameters.usage = *usage;
Sungjoong Kangbe494d12012-08-04 15:36:56 -07001312 newParameters.numHwBuffers = 8;
1313 newParameters.numOwnSvcBuffers = *max_buffers;
Sungjoong Kang9dd63e12012-07-24 00:25:51 +09001314 newParameters.fd = m_fd_scp;
1315 newParameters.nodePlanes = 3;
1316 newParameters.svcPlanes = 3;
1317 newParameters.halBuftype = V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE;
1318 newParameters.memory = V4L2_MEMORY_DMABUF;
1319 newParameters.ionClient = m_ionCameraClient;
Sungjoong Kangbe494d12012-08-04 15:36:56 -07001320 newParameters.numSvcBufsInHal = 0;
Sungjoong Kang9dd63e12012-07-24 00:25:51 +09001321 AllocatedStream->m_index = *stream_id;
1322 AllocatedStream->setParameter(&newParameters);
1323 AllocatedStream->m_activated = true;
Sungjoong Kang13d8c7b2012-07-14 10:20:39 +09001324
Sungjoong Kang9dd63e12012-07-24 00:25:51 +09001325 m_scp_flushing = false;
1326 m_scp_closing = false;
1327 m_scp_closed = false;
Sungjoong Kangad378612012-08-17 12:34:33 -07001328 m_requestManager->SetDefaultParameters(m_camera2->getSensorW());
1329 m_camera_info.dummy_shot.shot.ctl.scaler.cropRegion[2] = m_camera2->getSensorW();
Sungjoong Kang9dd63e12012-07-24 00:25:51 +09001330 return 0;
1331 }
1332 else if (allocCase == 1) {
1333 record_parameters_t recordParameters;
1334 StreamThread *parentStream;
1335 parentStream = (StreamThread*)(m_streamThreads[0].get());
1336 if (!parentStream) {
1337 return 1;
1338 // TODO
1339 }
1340 *stream_id = 2;
1341 usleep(100000); // TODO : guarantee the codes below will be run after readyToRunInternal()
1342
Sungjoong Kang804236a2012-08-05 10:36:19 -07001343 *format_actual = HAL_PIXEL_FORMAT_YCbCr_420_SP; // NV12M
Alex Ray6bbb5932012-07-27 17:19:48 -07001344 *usage = GRALLOC_USAGE_SW_WRITE_OFTEN;
Sungjoong Kang9dd63e12012-07-24 00:25:51 +09001345 *max_buffers = 10;
1346
1347 recordParameters.outputWidth = width;
1348 recordParameters.outputHeight = height;
1349 recordParameters.outputFormat = *format_actual;
Sungjoong Kang804236a2012-08-05 10:36:19 -07001350 recordParameters.svcPlanes = NUM_PLANES(*format_actual);
Sungjoong Kang9dd63e12012-07-24 00:25:51 +09001351 recordParameters.streamOps = stream_ops;
1352 recordParameters.usage = *usage;
Sungjoong Kangbe494d12012-08-04 15:36:56 -07001353 recordParameters.numOwnSvcBuffers = *max_buffers;
1354 recordParameters.numSvcBufsInHal = 0;
Sungjoong Kang9dd63e12012-07-24 00:25:51 +09001355
1356 parentStream->setRecordingParameter(&recordParameters);
1357 m_scp_flushing = false;
1358 m_scp_closing = false;
1359 m_scp_closed = false;
1360 m_recordingEnabled = true;
1361 return 0;
1362 }
Sungjoong Kang13d8c7b2012-07-14 10:20:39 +09001363 }
Sungjoong Kangad378612012-08-17 12:34:33 -07001364 else if (format == HAL_PIXEL_FORMAT_BLOB
Sungjoong Kangdaa1fcd2012-08-08 11:49:43 -07001365 && m_camera2->isSupportedJpegResolution(width, height)) {
Sungjoong Kang13d8c7b2012-07-14 10:20:39 +09001366
1367 *stream_id = 1;
1368
1369 m_streamThreads[1] = new StreamThread(this, *stream_id);
1370 AllocatedStream = (StreamThread*)(m_streamThreads[1].get());
Sungjoong Kang9dd63e12012-07-24 00:25:51 +09001371
Sungjoong Kang13d8c7b2012-07-14 10:20:39 +09001372 fd = m_camera_info.capture.fd;
1373 usleep(100000); // TODO : guarantee the codes below will be run after readyToRunInternal()
1374
1375 *format_actual = HAL_PIXEL_FORMAT_BLOB;
1376
1377 *usage = GRALLOC_USAGE_SW_WRITE_OFTEN;
Sungjoong Kang37e122d2012-08-08 11:13:48 -07001378 *max_buffers = 4;
Sungjoong Kang13d8c7b2012-07-14 10:20:39 +09001379
Sungjoong Kang37e122d2012-08-08 11:13:48 -07001380 newParameters.streamType = STREAM_TYPE_INDIRECT;
Sungjoong Kang13d8c7b2012-07-14 10:20:39 +09001381 newParameters.outputWidth = width;
1382 newParameters.outputHeight = height;
Sungjoong Kang9dd63e12012-07-24 00:25:51 +09001383
Sungjoong Kangdaa1fcd2012-08-08 11:49:43 -07001384 newParameters.nodeWidth = m_camera2->getSensorW();
1385 newParameters.nodeHeight = m_camera2->getSensorH();
Sungjoong Kang9dd63e12012-07-24 00:25:51 +09001386
Sungjoong Kang13d8c7b2012-07-14 10:20:39 +09001387 newParameters.outputFormat = *format_actual;
1388 newParameters.nodeFormat = V4L2_PIX_FMT_YUYV;
1389 newParameters.streamOps = stream_ops;
1390 newParameters.usage = *usage;
Sungjoong Kangbe494d12012-08-04 15:36:56 -07001391 newParameters.numHwBuffers = 8;
1392 newParameters.numOwnSvcBuffers = *max_buffers;
Sungjoong Kang13d8c7b2012-07-14 10:20:39 +09001393 newParameters.fd = fd;
1394 newParameters.nodePlanes = 1;
1395 newParameters.svcPlanes = 1;
1396 newParameters.halBuftype = V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE;
1397 newParameters.memory = V4L2_MEMORY_DMABUF;
1398 newParameters.ionClient = m_ionCameraClient;
Sungjoong Kangbe494d12012-08-04 15:36:56 -07001399 newParameters.numSvcBufsInHal = 0;
Sungjoong Kang9dd63e12012-07-24 00:25:51 +09001400 AllocatedStream->m_index = *stream_id;
Sungjoong Kang13d8c7b2012-07-14 10:20:39 +09001401 AllocatedStream->setParameter(&newParameters);
1402 return 0;
1403 }
1404 ALOGE("DEBUG(%s): Unsupported Pixel Format", __FUNCTION__);
1405 return 1; // TODO : check proper error code
1406}
1407
1408int ExynosCameraHWInterface2::registerStreamBuffers(uint32_t stream_id,
1409 int num_buffers, buffer_handle_t *registeringBuffers)
1410{
1411 int i,j;
1412 void *virtAddr[3];
1413 uint32_t plane_index = 0;
1414 stream_parameters_t *targetStreamParms;
Sungjoong Kang9dd63e12012-07-24 00:25:51 +09001415 record_parameters_t *targetRecordParms;
Sungjoong Kang13d8c7b2012-07-14 10:20:39 +09001416 node_info_t *currentNode;
1417
1418 struct v4l2_buffer v4l2_buf;
1419 struct v4l2_plane planes[VIDEO_MAX_PLANES];
1420
1421 ALOGV("DEBUG(%s): streamID (%d), num_buff(%d), handle(%x) ", __FUNCTION__,
1422 stream_id, num_buffers, (uint32_t)registeringBuffers);
1423
1424 if (stream_id == 0) {
1425 targetStreamParms = &(m_streamThreads[0]->m_parameters);
1426 }
1427 else if (stream_id == 1) {
1428 targetStreamParms = &(m_streamThreads[1]->m_parameters);
1429 }
Sungjoong Kang9dd63e12012-07-24 00:25:51 +09001430 else if (stream_id == 2) {
1431 targetRecordParms = &(m_streamThreads[0]->m_recordParameters);
1432
1433 targetRecordParms->numSvcBuffers = num_buffers;
1434
1435 for (i = 0 ; i<targetRecordParms->numSvcBuffers ; i++) {
1436 ALOGV("DEBUG(%s): registering Stream Buffers[%d] (%x) ", __FUNCTION__,
1437 i, (uint32_t)(registeringBuffers[i]));
1438 if (m_grallocHal) {
1439 if (m_grallocHal->lock(m_grallocHal, registeringBuffers[i],
1440 targetRecordParms->usage, 0, 0,
1441 targetRecordParms->outputWidth, targetRecordParms->outputHeight, virtAddr) != 0) {
1442 ALOGE("ERR(%s): could not obtain gralloc buffer", __FUNCTION__);
1443 }
1444 else {
1445 ExynosBuffer currentBuf;
1446 const private_handle_t *priv_handle = reinterpret_cast<const private_handle_t *>(registeringBuffers[i]);
Sungjoong Kang9dd63e12012-07-24 00:25:51 +09001447 currentBuf.fd.extFd[0] = priv_handle->fd;
Alex Ray6bbb5932012-07-27 17:19:48 -07001448 currentBuf.fd.extFd[1] = priv_handle->fd1;
1449 currentBuf.fd.extFd[2] = priv_handle->fd2;
Sungjoong Kang9dd63e12012-07-24 00:25:51 +09001450 for (plane_index=0 ; plane_index < targetRecordParms->svcPlanes ; plane_index++) {
1451 currentBuf.virt.extP[plane_index] = (char *)virtAddr[plane_index];
1452 ALOGV("DEBUG(%s): plane(%d): fd(%d) addr(%x)",
Sungjoong Kang804236a2012-08-05 10:36:19 -07001453 __FUNCTION__, plane_index, currentBuf.fd.extFd[plane_index],
Sungjoong Kang9dd63e12012-07-24 00:25:51 +09001454 (unsigned int)currentBuf.virt.extP[plane_index]);
1455 }
1456 targetRecordParms->svcBufStatus[i] = ON_SERVICE;
Sungjoong Kangb5237e62012-07-27 07:39:05 -07001457 targetRecordParms->svcBuffers[i] = currentBuf;
1458 targetRecordParms->svcBufHandle[i] = registeringBuffers[i];
Sungjoong Kang9dd63e12012-07-24 00:25:51 +09001459 }
1460 }
1461 }
1462 m_needsRecordBufferInit = true;
1463 return 0;
1464 }
Sungjoong Kang13d8c7b2012-07-14 10:20:39 +09001465 else {
1466 ALOGE("ERR(%s) unregisterd stream id (%d)", __FUNCTION__, stream_id);
Sungjoong Kangbe494d12012-08-04 15:36:56 -07001467 return 1;
Sungjoong Kang13d8c7b2012-07-14 10:20:39 +09001468 }
1469
Sungjoong Kang37e122d2012-08-08 11:13:48 -07001470 if (targetStreamParms->streamType == STREAM_TYPE_DIRECT) {
Sungjoong Kang13d8c7b2012-07-14 10:20:39 +09001471 if (num_buffers < targetStreamParms->numHwBuffers) {
1472 ALOGE("ERR(%s) registering insufficient num of buffers (%d) < (%d)",
1473 __FUNCTION__, num_buffers, targetStreamParms->numHwBuffers);
Sungjoong Kangbe494d12012-08-04 15:36:56 -07001474 return 1;
Sungjoong Kang13d8c7b2012-07-14 10:20:39 +09001475 }
1476 }
1477 ALOGV("DEBUG(%s): format(%x) width(%d), height(%d) svcPlanes(%d)",
1478 __FUNCTION__, targetStreamParms->outputFormat, targetStreamParms->outputWidth,
1479 targetStreamParms->outputHeight, targetStreamParms->svcPlanes);
1480
1481 targetStreamParms->numSvcBuffers = num_buffers;
1482 currentNode = &(targetStreamParms->node); // TO Remove
1483
1484 currentNode->fd = targetStreamParms->fd;
1485 currentNode->width = targetStreamParms->nodeWidth;
1486 currentNode->height = targetStreamParms->nodeHeight;
1487 currentNode->format = targetStreamParms->nodeFormat;
1488 currentNode->planes = targetStreamParms->nodePlanes;
1489 currentNode->buffers = targetStreamParms->numHwBuffers;
1490 currentNode->type = targetStreamParms->halBuftype;
1491 currentNode->memory = targetStreamParms->memory;
1492 currentNode->ionClient = targetStreamParms->ionClient;
1493
Sungjoong Kang37e122d2012-08-08 11:13:48 -07001494 if (targetStreamParms->streamType == STREAM_TYPE_DIRECT) {
Sungjoong Kangad378612012-08-17 12:34:33 -07001495 if(m_need_streamoff == 1) {
1496 ALOGV("(%s): calling capture streamoff", __FUNCTION__);
1497 cam_int_streamoff(&(m_camera_info.capture));
1498 ALOGV("(%s): calling capture streamoff done", __FUNCTION__);
1499
1500 m_camera_info.capture.buffers = 0;
1501 ALOGV("DEBUG(%s): capture calling reqbuf 0 ", __FUNCTION__);
1502 cam_int_reqbufs(&(m_camera_info.capture));
1503 ALOGV("DEBUG(%s): capture calling reqbuf 0 done", __FUNCTION__);
1504
1505 if (m_sensorThread != NULL) {
1506 m_sensorThread->release();
1507 usleep(500000);
1508 } else {
1509 ALOGE("+++++++ sensor thread is NULL %d", __LINE__);
1510 }
1511 m_isIspStarted = false;
1512 }
1513
Sungjoong Kang13d8c7b2012-07-14 10:20:39 +09001514 cam_int_s_input(currentNode, m_camera_info.sensor_id);
1515 cam_int_s_fmt(currentNode);
1516 cam_int_reqbufs(currentNode);
Sungjoong Kangad378612012-08-17 12:34:33 -07001517
1518 if (m_need_streamoff == 1) {
1519 m_camera_info.sensor.buffers = NUM_BAYER_BUFFERS;
1520 m_camera_info.isp.buffers = m_camera_info.sensor.buffers;
1521 m_camera_info.capture.buffers = 8;
1522 cam_int_reqbufs(&(m_camera_info.isp));
1523 cam_int_reqbufs(&(m_camera_info.sensor));
1524
1525 for (i = 0; i < 8; i++) {
1526 ALOGV("DEBUG(%s): sensor initial QBUF [%d]", __FUNCTION__, i);
1527 memcpy( m_camera_info.sensor.buffer[i].virt.extP[1], &(m_camera_info.dummy_shot),
1528 sizeof(struct camera2_shot_ext));
1529 m_camera_info.dummy_shot.shot.ctl.sensor.frameDuration = 33*1000*1000; // apply from frame #1
1530 m_camera_info.dummy_shot.shot.ctl.request.frameCount = -1;
1531 cam_int_qbuf(&(m_camera_info.sensor), i);
1532 }
1533
1534 cam_int_reqbufs(&(m_camera_info.capture));
1535 cam_int_streamon(&(m_camera_info.capture));
1536 cam_int_streamon(&(m_camera_info.sensor));
1537
1538 m_need_streamoff = 0;
1539 m_requestManager->SetInitialSkip(2);
1540 m_sensorThread->Start("SensorThread", PRIORITY_DEFAULT, 0);
1541 m_mainThread->SetSignal(SIGNAL_MAIN_REQ_Q_NOT_EMPTY);
1542 }
Sungjoong Kang13d8c7b2012-07-14 10:20:39 +09001543 }
Sungjoong Kang37e122d2012-08-08 11:13:48 -07001544 else if (targetStreamParms->streamType == STREAM_TYPE_INDIRECT) {
Sungjoong Kang13d8c7b2012-07-14 10:20:39 +09001545 for(i = 0; i < currentNode->buffers; i++){
1546 memcpy(&(currentNode->buffer[i]), &(m_camera_info.capture.buffer[i]), sizeof(ExynosBuffer));
1547 }
1548 }
1549
1550 for (i = 0 ; i<targetStreamParms->numSvcBuffers ; i++) {
1551 ALOGV("DEBUG(%s): registering Stream Buffers[%d] (%x) ", __FUNCTION__,
1552 i, (uint32_t)(registeringBuffers[i]));
1553 if (m_grallocHal) {
1554 if (m_grallocHal->lock(m_grallocHal, registeringBuffers[i],
1555 targetStreamParms->usage, 0, 0,
1556 currentNode->width, currentNode->height, virtAddr) != 0) {
1557 ALOGE("ERR(%s): could not obtain gralloc buffer", __FUNCTION__);
1558 }
1559 else {
1560 v4l2_buf.m.planes = planes;
1561 v4l2_buf.type = currentNode->type;
1562 v4l2_buf.memory = currentNode->memory;
1563 v4l2_buf.index = i;
1564 v4l2_buf.length = currentNode->planes;
1565
1566 ExynosBuffer currentBuf;
1567 const private_handle_t *priv_handle = reinterpret_cast<const private_handle_t *>(registeringBuffers[i]);
1568
1569 m_getAlignedYUVSize(currentNode->format,
1570 currentNode->width, currentNode->height, &currentBuf);
Alex Ray24231222012-06-27 15:18:15 -07001571
Sungjoong Kang9dd63e12012-07-24 00:25:51 +09001572 v4l2_buf.m.planes[0].m.fd = priv_handle->fd;
Alex Ray6bbb5932012-07-27 17:19:48 -07001573 v4l2_buf.m.planes[2].m.fd = priv_handle->fd1;
1574 v4l2_buf.m.planes[1].m.fd = priv_handle->fd2;
Sungjoong Kang9dd63e12012-07-24 00:25:51 +09001575 currentBuf.fd.extFd[0] = priv_handle->fd;
Alex Ray6bbb5932012-07-27 17:19:48 -07001576 currentBuf.fd.extFd[2] = priv_handle->fd1;
1577 currentBuf.fd.extFd[1] = priv_handle->fd2;
Sungjoong Kang37e122d2012-08-08 11:13:48 -07001578 ALOGV("DEBUG(%s): ion_size(%d), stride(%d), ", __FUNCTION__, priv_handle->size, priv_handle->stride);
1579 if (currentNode->planes == 1) {
1580 currentBuf.size.extS[0] = priv_handle->size;
1581 currentBuf.size.extS[1] = 0;
1582 currentBuf.size.extS[2] = 0;
1583 }
Sungjoong Kangbe494d12012-08-04 15:36:56 -07001584 for (plane_index = 0 ; plane_index < v4l2_buf.length ; plane_index++) {
Sungjoong Kang13d8c7b2012-07-14 10:20:39 +09001585 currentBuf.virt.extP[plane_index] = (char *)virtAddr[plane_index];
1586 v4l2_buf.m.planes[plane_index].length = currentBuf.size.extS[plane_index];
1587 ALOGV("DEBUG(%s): plane(%d): fd(%d) addr(%x), length(%d)",
1588 __FUNCTION__, plane_index, v4l2_buf.m.planes[plane_index].m.fd,
1589 (unsigned int)currentBuf.virt.extP[plane_index],
1590 v4l2_buf.m.planes[plane_index].length);
Jiyoung Shinc15a6b02012-06-05 01:08:14 -07001591 }
Sungjoong Kang13d8c7b2012-07-14 10:20:39 +09001592
Sungjoong Kang37e122d2012-08-08 11:13:48 -07001593 if (targetStreamParms->streamType == STREAM_TYPE_DIRECT) {
Sungjoong Kang13d8c7b2012-07-14 10:20:39 +09001594 if (i < currentNode->buffers) {
1595 if (exynos_v4l2_qbuf(currentNode->fd, &v4l2_buf) < 0) {
Sungjoong Kang9dd63e12012-07-24 00:25:51 +09001596 ALOGE("ERR(%s): stream id(%d) exynos_v4l2_qbuf() fail fd(%d)",
1597 __FUNCTION__, stream_id, currentNode->fd);
1598 //return false;
Sungjoong Kang13d8c7b2012-07-14 10:20:39 +09001599 }
Sungjoong Kang9dd63e12012-07-24 00:25:51 +09001600 ALOGV("DEBUG(%s): stream id(%d) exynos_v4l2_qbuf() success fd(%d)",
1601 __FUNCTION__, stream_id, currentNode->fd);
Sungjoong Kang13d8c7b2012-07-14 10:20:39 +09001602 targetStreamParms->svcBufStatus[i] = REQUIRES_DQ_FROM_SVC;
1603 }
1604 else {
1605 targetStreamParms->svcBufStatus[i] = ON_SERVICE;
1606 }
1607 }
Sungjoong Kang37e122d2012-08-08 11:13:48 -07001608 else if (targetStreamParms->streamType == STREAM_TYPE_INDIRECT) {
Sungjoong Kang13d8c7b2012-07-14 10:20:39 +09001609 targetStreamParms->svcBufStatus[i] = ON_SERVICE;
1610 }
1611 targetStreamParms->svcBuffers[i] = currentBuf;
1612 targetStreamParms->svcBufHandle[i] = registeringBuffers[i];
1613 }
Jiyoung Shinc15a6b02012-06-05 01:08:14 -07001614 }
Jiyoung Shinc15a6b02012-06-05 01:08:14 -07001615 }
Sungjoong Kangad378612012-08-17 12:34:33 -07001616
Sungjoong Kang9dd63e12012-07-24 00:25:51 +09001617 ALOGV("DEBUG(%s): calling streamon", __FUNCTION__);
Sungjoong Kangad378612012-08-17 12:34:33 -07001618 if (targetStreamParms->streamType == 0) {
1619 ALOGD("%s(%d), stream id = %d", __FUNCTION__, __LINE__, stream_id);
1620 cam_int_streamon(&(targetStreamParms->node));
1621 }
1622
1623 ALOGV("DEBUG(%s): calling streamon END", __FUNCTION__);
Sungjoong Kang13d8c7b2012-07-14 10:20:39 +09001624 ALOGV("DEBUG(%s): END registerStreamBuffers", __FUNCTION__);
Sungjoong Kangad378612012-08-17 12:34:33 -07001625
1626 if(!m_isIspStarted) {
1627 m_isIspStarted = true;
1628 StartISP();
1629 m_need_streamoff = 1;
1630 }
1631
Jiyoung Shinc15a6b02012-06-05 01:08:14 -07001632 return 0;
1633}
1634
1635int ExynosCameraHWInterface2::releaseStream(uint32_t stream_id)
1636{
Sungjoong Kang13d8c7b2012-07-14 10:20:39 +09001637 StreamThread *targetStream;
1638 ALOGV("DEBUG(%s):", __FUNCTION__);
1639
Sungjoong Kangb5237e62012-07-27 07:39:05 -07001640 if (stream_id == 0) {
Sungjoong Kang13d8c7b2012-07-14 10:20:39 +09001641 targetStream = (StreamThread*)(m_streamThreads[0].get());
Sungjoong Kang9dd63e12012-07-24 00:25:51 +09001642 m_scp_flushing = true;
Sungjoong Kang13d8c7b2012-07-14 10:20:39 +09001643 }
Sungjoong Kangb5237e62012-07-27 07:39:05 -07001644 else if (stream_id == 1) {
Sungjoong Kang13d8c7b2012-07-14 10:20:39 +09001645 targetStream = (StreamThread*)(m_streamThreads[1].get());
1646 }
Sungjoong Kangb5237e62012-07-27 07:39:05 -07001647 else if (stream_id == 2 && m_recordingEnabled) {
1648 m_recordingEnabled = false;
Sungjoong Kangad378612012-08-17 12:34:33 -07001649 m_needsRecordBufferInit = true;
Sungjoong Kangb5237e62012-07-27 07:39:05 -07001650 return 0;
1651 }
Sungjoong Kang13d8c7b2012-07-14 10:20:39 +09001652 else {
1653 ALOGE("ERR:(%s): wrong stream id (%d)", __FUNCTION__, stream_id);
Sungjoong Kangbe494d12012-08-04 15:36:56 -07001654 return 1;
Sungjoong Kang13d8c7b2012-07-14 10:20:39 +09001655 }
1656
Sungjoong Kangb5237e62012-07-27 07:39:05 -07001657 targetStream->m_releasing = true;
Sungjoong Kang13d8c7b2012-07-14 10:20:39 +09001658 targetStream->release();
Sungjoong Kangb5237e62012-07-27 07:39:05 -07001659 while (targetStream->m_releasing)
Sungjoong Kangad378612012-08-17 12:34:33 -07001660 {
1661 ALOGD("stream thread release fail %d", __LINE__);
Sungjoong Kangb5237e62012-07-27 07:39:05 -07001662 usleep(2000);
Sungjoong Kangad378612012-08-17 12:34:33 -07001663 }
Sungjoong Kang9dd63e12012-07-24 00:25:51 +09001664 targetStream->m_activated = false;
Sungjoong Kang13d8c7b2012-07-14 10:20:39 +09001665 ALOGV("DEBUG(%s): DONE", __FUNCTION__);
Jiyoung Shinc15a6b02012-06-05 01:08:14 -07001666 return 0;
1667}
1668
1669int ExynosCameraHWInterface2::allocateReprocessStream(
Sungjoong Kang13d8c7b2012-07-14 10:20:39 +09001670 uint32_t width, uint32_t height, uint32_t format,
1671 const camera2_stream_in_ops_t *reprocess_stream_ops,
Jiyoung Shinc15a6b02012-06-05 01:08:14 -07001672 uint32_t *stream_id, uint32_t *consumer_usage, uint32_t *max_buffers)
1673{
Sungjoong Kang13d8c7b2012-07-14 10:20:39 +09001674 ALOGV("DEBUG(%s):", __FUNCTION__);
Jiyoung Shinc15a6b02012-06-05 01:08:14 -07001675 return 0;
1676}
1677
1678int ExynosCameraHWInterface2::releaseReprocessStream(uint32_t stream_id)
1679{
Sungjoong Kang13d8c7b2012-07-14 10:20:39 +09001680 ALOGV("DEBUG(%s):", __FUNCTION__);
Jiyoung Shinc15a6b02012-06-05 01:08:14 -07001681 return 0;
1682}
1683
1684int ExynosCameraHWInterface2::triggerAction(uint32_t trigger_id, int ext1, int ext2)
1685{
Sungjoong Kang0f26b202012-08-17 15:43:12 -07001686 ALOGV("DEBUG(%s): id(%x), %d, %d", __FUNCTION__, trigger_id, ext1, ext2);
1687
1688 switch (trigger_id) {
1689 case CAMERA2_TRIGGER_AUTOFOCUS:
1690 ALOGV("DEBUG(%s):TRIGGER_AUTOFOCUS id(%d)", __FUNCTION__, ext1);
1691 OnAfTrigger(ext1);
1692 break;
1693
1694 case CAMERA2_TRIGGER_CANCEL_AUTOFOCUS:
1695 ALOGV("DEBUG(%s):CANCEL_AUTOFOCUS id(%d)", __FUNCTION__, ext1);
1696 OnAfCancel(ext1);
1697 break;
1698 default:
1699 break;
1700 }
Jiyoung Shinc15a6b02012-06-05 01:08:14 -07001701 return 0;
1702}
1703
1704int ExynosCameraHWInterface2::setNotifyCallback(camera2_notify_callback notify_cb, void *user)
1705{
Sungjoong Kang0f26b202012-08-17 15:43:12 -07001706 ALOGV("DEBUG(%s): cb_addr(%x)", __FUNCTION__, (unsigned int)notify_cb);
Jiyoung Shinc15a6b02012-06-05 01:08:14 -07001707 m_notifyCb = notify_cb;
1708 m_callbackCookie = user;
1709 return 0;
1710}
1711
1712int ExynosCameraHWInterface2::getMetadataVendorTagOps(vendor_tag_query_ops_t **ops)
1713{
Sungjoong Kang13d8c7b2012-07-14 10:20:39 +09001714 ALOGV("DEBUG(%s):", __FUNCTION__);
Jiyoung Shinc15a6b02012-06-05 01:08:14 -07001715 return 0;
1716}
1717
1718int ExynosCameraHWInterface2::dump(int fd)
1719{
Sungjoong Kang13d8c7b2012-07-14 10:20:39 +09001720 ALOGV("DEBUG(%s):", __FUNCTION__);
Jiyoung Shinc15a6b02012-06-05 01:08:14 -07001721 return 0;
1722}
1723
Sungjoong Kang13d8c7b2012-07-14 10:20:39 +09001724void ExynosCameraHWInterface2::m_getAlignedYUVSize(int colorFormat, int w, int h, ExynosBuffer *buf)
1725{
1726 switch (colorFormat) {
1727 // 1p
1728 case V4L2_PIX_FMT_RGB565 :
1729 case V4L2_PIX_FMT_YUYV :
1730 case V4L2_PIX_FMT_UYVY :
1731 case V4L2_PIX_FMT_VYUY :
1732 case V4L2_PIX_FMT_YVYU :
1733 buf->size.extS[0] = FRAME_SIZE(V4L2_PIX_2_HAL_PIXEL_FORMAT(colorFormat), w, h);
1734 buf->size.extS[1] = 0;
1735 buf->size.extS[2] = 0;
1736 break;
1737 // 2p
1738 case V4L2_PIX_FMT_NV12 :
1739 case V4L2_PIX_FMT_NV12T :
1740 case V4L2_PIX_FMT_NV21 :
1741 buf->size.extS[0] = ALIGN(w, 16) * ALIGN(h, 16);
1742 buf->size.extS[1] = ALIGN(w/2, 16) * ALIGN(h/2, 16);
1743 buf->size.extS[2] = 0;
1744 break;
1745 case V4L2_PIX_FMT_NV12M :
1746 case V4L2_PIX_FMT_NV12MT_16X16 :
Sungjoong Kang9dd63e12012-07-24 00:25:51 +09001747 case V4L2_PIX_FMT_NV21M:
Sungjoong Kang13d8c7b2012-07-14 10:20:39 +09001748 buf->size.extS[0] = ALIGN(w, 16) * ALIGN(h, 16);
1749 buf->size.extS[1] = ALIGN(buf->size.extS[0] / 2, 256);
1750 buf->size.extS[2] = 0;
1751 break;
1752 case V4L2_PIX_FMT_NV16 :
1753 case V4L2_PIX_FMT_NV61 :
1754 buf->size.extS[0] = ALIGN(w, 16) * ALIGN(h, 16);
1755 buf->size.extS[1] = ALIGN(w, 16) * ALIGN(h, 16);
1756 buf->size.extS[2] = 0;
1757 break;
1758 // 3p
1759 case V4L2_PIX_FMT_YUV420 :
1760 case V4L2_PIX_FMT_YVU420 :
1761 buf->size.extS[0] = (w * h);
1762 buf->size.extS[1] = (w * h) >> 2;
1763 buf->size.extS[2] = (w * h) >> 2;
1764 break;
1765 case V4L2_PIX_FMT_YUV420M:
1766 case V4L2_PIX_FMT_YVU420M :
1767 case V4L2_PIX_FMT_YUV422P :
1768 buf->size.extS[0] = ALIGN(w, 32) * ALIGN(h, 16);
1769 buf->size.extS[1] = ALIGN(w/2, 16) * ALIGN(h/2, 8);
1770 buf->size.extS[2] = ALIGN(w/2, 16) * ALIGN(h/2, 8);
1771 break;
1772 default:
1773 ALOGE("ERR(%s):unmatched colorFormat(%d)", __FUNCTION__, colorFormat);
1774 return;
1775 break;
1776 }
1777}
1778
1779bool ExynosCameraHWInterface2::m_getRatioSize(int src_w, int src_h,
1780 int dst_w, int dst_h,
1781 int *crop_x, int *crop_y,
1782 int *crop_w, int *crop_h,
1783 int zoom)
1784{
1785 *crop_w = src_w;
1786 *crop_h = src_h;
1787
1788 if ( src_w != dst_w
1789 || src_h != dst_h) {
1790 float src_ratio = 1.0f;
1791 float dst_ratio = 1.0f;
1792
1793 // ex : 1024 / 768
1794 src_ratio = (float)src_w / (float)src_h;
1795
1796 // ex : 352 / 288
1797 dst_ratio = (float)dst_w / (float)dst_h;
1798
1799 if (dst_w * dst_h < src_w * src_h) {
1800 if (dst_ratio <= src_ratio) {
1801 // shrink w
1802 *crop_w = src_h * dst_ratio;
1803 *crop_h = src_h;
1804 } else {
1805 // shrink h
1806 *crop_w = src_w;
1807 *crop_h = src_w / dst_ratio;
1808 }
1809 } else {
1810 if (dst_ratio <= src_ratio) {
1811 // shrink w
1812 *crop_w = src_h * dst_ratio;
1813 *crop_h = src_h;
1814 } else {
1815 // shrink h
1816 *crop_w = src_w;
1817 *crop_h = src_w / dst_ratio;
1818 }
1819 }
1820 }
1821
1822 if (zoom != 0) {
1823 float zoomLevel = ((float)zoom + 10.0) / 10.0;
1824 *crop_w = (int)((float)*crop_w / zoomLevel);
1825 *crop_h = (int)((float)*crop_h / zoomLevel);
1826 }
1827
1828 #define CAMERA_CROP_WIDTH_RESTRAIN_NUM (0x2)
1829 unsigned int w_align = (*crop_w & (CAMERA_CROP_WIDTH_RESTRAIN_NUM - 1));
1830 if (w_align != 0) {
1831 if ( (CAMERA_CROP_WIDTH_RESTRAIN_NUM >> 1) <= w_align
1832 && *crop_w + (CAMERA_CROP_WIDTH_RESTRAIN_NUM - w_align) <= dst_w) {
1833 *crop_w += (CAMERA_CROP_WIDTH_RESTRAIN_NUM - w_align);
1834 }
1835 else
1836 *crop_w -= w_align;
1837 }
1838
1839 #define CAMERA_CROP_HEIGHT_RESTRAIN_NUM (0x2)
1840 unsigned int h_align = (*crop_h & (CAMERA_CROP_HEIGHT_RESTRAIN_NUM - 1));
1841 if (h_align != 0) {
1842 if ( (CAMERA_CROP_HEIGHT_RESTRAIN_NUM >> 1) <= h_align
1843 && *crop_h + (CAMERA_CROP_HEIGHT_RESTRAIN_NUM - h_align) <= dst_h) {
1844 *crop_h += (CAMERA_CROP_HEIGHT_RESTRAIN_NUM - h_align);
1845 }
1846 else
1847 *crop_h -= h_align;
1848 }
1849
1850 *crop_x = (src_w - *crop_w) >> 1;
1851 *crop_y = (src_h - *crop_h) >> 1;
1852
1853 if (*crop_x & (CAMERA_CROP_WIDTH_RESTRAIN_NUM >> 1))
1854 *crop_x -= 1;
1855
1856 if (*crop_y & (CAMERA_CROP_HEIGHT_RESTRAIN_NUM >> 1))
1857 *crop_y -= 1;
1858
1859 return true;
1860}
1861
Sungjoong Kang9dd63e12012-07-24 00:25:51 +09001862BayerBufManager::BayerBufManager()
Sungjoong Kang13d8c7b2012-07-14 10:20:39 +09001863{
Sungjoong Kang9dd63e12012-07-24 00:25:51 +09001864 ALOGV("DEBUG(%s): ", __FUNCTION__);
1865 for (int i = 0; i < NUM_BAYER_BUFFERS ; i++) {
1866 entries[i].status = BAYER_ON_HAL_EMPTY;
1867 entries[i].reqFrameCnt = 0;
Sungjoong Kang13d8c7b2012-07-14 10:20:39 +09001868 }
Sungjoong Kang9dd63e12012-07-24 00:25:51 +09001869 sensorEnqueueHead = 0;
1870 sensorDequeueHead = 0;
1871 ispEnqueueHead = 0;
1872 ispDequeueHead = 0;
1873 numOnSensor = 0;
1874 numOnIsp = 0;
1875 numOnHalFilled = 0;
1876 numOnHalEmpty = NUM_BAYER_BUFFERS;
Sungjoong Kang13d8c7b2012-07-14 10:20:39 +09001877}
1878
Sungjoong Kang9dd63e12012-07-24 00:25:51 +09001879int BayerBufManager::GetIndexForSensorEnqueue()
Sungjoong Kang13d8c7b2012-07-14 10:20:39 +09001880{
Sungjoong Kang9dd63e12012-07-24 00:25:51 +09001881 int ret = 0;
1882 if (numOnHalEmpty == 0)
1883 ret = -1;
1884 else
1885 ret = sensorEnqueueHead;
1886 ALOGV("DEBUG(%s): returning (%d)", __FUNCTION__, ret);
Sungjoong Kang13d8c7b2012-07-14 10:20:39 +09001887 return ret;
1888}
1889
Sungjoong Kang9dd63e12012-07-24 00:25:51 +09001890int BayerBufManager::MarkSensorEnqueue(int index)
Sungjoong Kang13d8c7b2012-07-14 10:20:39 +09001891{
Sungjoong Kang9dd63e12012-07-24 00:25:51 +09001892 ALOGV("DEBUG(%s) : BayerIndex[%d] ", __FUNCTION__, index);
1893
1894 // sanity check
1895 if (index != sensorEnqueueHead) {
1896 ALOGV("DEBUG(%s) : Abnormal BayerIndex[%d] - expected[%d]", __FUNCTION__, index, sensorEnqueueHead);
1897 return -1;
1898 }
1899 if (entries[index].status != BAYER_ON_HAL_EMPTY) {
1900 ALOGV("DEBUG(%s) : Abnormal status in BayerIndex[%d] = (%d) expected (%d)", __FUNCTION__,
1901 index, entries[index].status, BAYER_ON_HAL_EMPTY);
Sungjoong Kang13d8c7b2012-07-14 10:20:39 +09001902 return -1;
1903 }
1904
Sungjoong Kang9dd63e12012-07-24 00:25:51 +09001905 entries[index].status = BAYER_ON_SENSOR;
1906 entries[index].reqFrameCnt = 0;
1907 numOnHalEmpty--;
1908 numOnSensor++;
1909 sensorEnqueueHead = GetNextIndex(index);
1910 ALOGV("DEBUG(%s) END: HAL-e(%d) HAL-f(%d) Sensor(%d) ISP(%d) ",
1911 __FUNCTION__, numOnHalEmpty, numOnHalFilled, numOnSensor, numOnIsp);
1912 return 0;
1913}
Sungjoong Kang13d8c7b2012-07-14 10:20:39 +09001914
Sungjoong Kang9dd63e12012-07-24 00:25:51 +09001915int BayerBufManager::MarkSensorDequeue(int index, int reqFrameCnt, nsecs_t *timeStamp)
1916{
1917 ALOGV("DEBUG(%s) : BayerIndex[%d] reqFrameCnt(%d)", __FUNCTION__, index, reqFrameCnt);
1918
Sungjoong Kang9dd63e12012-07-24 00:25:51 +09001919 if (entries[index].status != BAYER_ON_SENSOR) {
Sungjoong Kangad378612012-08-17 12:34:33 -07001920 ALOGE("DEBUG(%s) : Abnormal status in BayerIndex[%d] = (%d) expected (%d)", __FUNCTION__,
Sungjoong Kang9dd63e12012-07-24 00:25:51 +09001921 index, entries[index].status, BAYER_ON_SENSOR);
Sungjoong Kang13d8c7b2012-07-14 10:20:39 +09001922 return -1;
1923 }
1924
Sungjoong Kang9dd63e12012-07-24 00:25:51 +09001925 entries[index].status = BAYER_ON_HAL_FILLED;
Sungjoong Kang9dd63e12012-07-24 00:25:51 +09001926 numOnHalFilled++;
1927 numOnSensor--;
Sungjoong Kangad378612012-08-17 12:34:33 -07001928
Sungjoong Kang9dd63e12012-07-24 00:25:51 +09001929 return 0;
1930}
Sungjoong Kang13d8c7b2012-07-14 10:20:39 +09001931
Sungjoong Kang9dd63e12012-07-24 00:25:51 +09001932int BayerBufManager::GetIndexForIspEnqueue(int *reqFrameCnt)
1933{
1934 int ret = 0;
1935 if (numOnHalFilled == 0)
1936 ret = -1;
1937 else {
1938 *reqFrameCnt = entries[ispEnqueueHead].reqFrameCnt;
1939 ret = ispEnqueueHead;
1940 }
1941 ALOGV("DEBUG(%s): returning BayerIndex[%d]", __FUNCTION__, ret);
1942 return ret;
1943}
1944
1945int BayerBufManager::GetIndexForIspDequeue(int *reqFrameCnt)
1946{
1947 int ret = 0;
1948 if (numOnIsp == 0)
1949 ret = -1;
1950 else {
1951 *reqFrameCnt = entries[ispDequeueHead].reqFrameCnt;
1952 ret = ispDequeueHead;
1953 }
1954 ALOGV("DEBUG(%s): returning BayerIndex[%d]", __FUNCTION__, ret);
1955 return ret;
1956}
1957
1958int BayerBufManager::MarkIspEnqueue(int index)
1959{
1960 ALOGV("DEBUG(%s) : BayerIndex[%d] ", __FUNCTION__, index);
1961
1962 // sanity check
1963 if (index != ispEnqueueHead) {
1964 ALOGV("DEBUG(%s) : Abnormal BayerIndex[%d] - expected[%d]", __FUNCTION__, index, ispEnqueueHead);
1965 return -1;
1966 }
1967 if (entries[index].status != BAYER_ON_HAL_FILLED) {
1968 ALOGV("DEBUG(%s) : Abnormal status in BayerIndex[%d] = (%d) expected (%d)", __FUNCTION__,
1969 index, entries[index].status, BAYER_ON_HAL_FILLED);
1970 return -1;
1971 }
1972
1973 entries[index].status = BAYER_ON_ISP;
1974 numOnHalFilled--;
1975 numOnIsp++;
1976 ispEnqueueHead = GetNextIndex(index);
1977 ALOGV("DEBUG(%s) END: HAL-e(%d) HAL-f(%d) Sensor(%d) ISP(%d) ",
1978 __FUNCTION__, numOnHalEmpty, numOnHalFilled, numOnSensor, numOnIsp);
1979 return 0;
1980}
1981
1982int BayerBufManager::MarkIspDequeue(int index)
1983{
1984 ALOGV("DEBUG(%s) : BayerIndex[%d]", __FUNCTION__, index);
1985
1986 // sanity check
1987 if (index != ispDequeueHead) {
1988 ALOGV("DEBUG(%s) : Abnormal BayerIndex[%d] - expected[%d]", __FUNCTION__, index, ispDequeueHead);
1989 return -1;
1990 }
1991 if (entries[index].status != BAYER_ON_ISP) {
1992 ALOGV("DEBUG(%s) : Abnormal status in BayerIndex[%d] = (%d) expected (%d)", __FUNCTION__,
1993 index, entries[index].status, BAYER_ON_ISP);
1994 return -1;
1995 }
1996
1997 entries[index].status = BAYER_ON_HAL_EMPTY;
1998 entries[index].reqFrameCnt = 0;
1999 numOnHalEmpty++;
2000 numOnIsp--;
2001 ispDequeueHead = GetNextIndex(index);
2002 ALOGV("DEBUG(%s) END: HAL-e(%d) HAL-f(%d) Sensor(%d) ISP(%d) ",
2003 __FUNCTION__, numOnHalEmpty, numOnHalFilled, numOnSensor, numOnIsp);
2004 return 0;
2005}
2006
2007int BayerBufManager::GetNumOnSensor()
2008{
2009 return numOnSensor;
2010}
2011
2012int BayerBufManager::GetNumOnHalFilled()
2013{
2014 return numOnHalFilled;
2015}
2016
2017int BayerBufManager::GetNumOnIsp()
2018{
2019 return numOnIsp;
2020}
2021
2022int BayerBufManager::GetNextIndex(int index)
2023{
2024 index++;
2025 if (index >= NUM_BAYER_BUFFERS)
2026 index = 0;
2027
2028 return index;
Sungjoong Kang13d8c7b2012-07-14 10:20:39 +09002029}
Jiyoung Shinc15a6b02012-06-05 01:08:14 -07002030
2031void ExynosCameraHWInterface2::m_mainThreadFunc(SignalDrivenThread * self)
2032{
2033 camera_metadata_t *currentRequest = NULL;
2034 camera_metadata_t *currentFrame = NULL;
2035 size_t numEntries = 0;
Sungjoong Kang13d8c7b2012-07-14 10:20:39 +09002036 size_t frameSize = 0;
Jiyoung Shinc15a6b02012-06-05 01:08:14 -07002037 camera_metadata_t * preparedFrame = NULL;
2038 camera_metadata_t *deregisteredRequest = NULL;
2039 uint32_t currentSignal = self->GetProcessingSignal();
Sungjoong Kang13d8c7b2012-07-14 10:20:39 +09002040 MainThread * selfThread = ((MainThread*)self);
Jiyoung Shinc15a6b02012-06-05 01:08:14 -07002041 int res = 0;
Sungjoong Kang13d8c7b2012-07-14 10:20:39 +09002042
Sungjoong Kangad378612012-08-17 12:34:33 -07002043 int ret;
2044
Sungjoong Kang13d8c7b2012-07-14 10:20:39 +09002045 ALOGV("DEBUG(%s): m_mainThreadFunc (%x)", __FUNCTION__, currentSignal);
2046
2047 if (currentSignal & SIGNAL_THREAD_RELEASE) {
2048 ALOGV("DEBUG(%s): processing SIGNAL_THREAD_RELEASE", __FUNCTION__);
2049
2050 ALOGV("DEBUG(%s): processing SIGNAL_THREAD_RELEASE DONE", __FUNCTION__);
2051 selfThread->SetSignal(SIGNAL_THREAD_TERMINATE);
2052 return;
2053 }
2054
Jiyoung Shinc15a6b02012-06-05 01:08:14 -07002055 if (currentSignal & SIGNAL_MAIN_REQ_Q_NOT_EMPTY) {
Sungjoong Kang13d8c7b2012-07-14 10:20:39 +09002056 ALOGV("DEBUG(%s): MainThread processing SIGNAL_MAIN_REQ_Q_NOT_EMPTY", __FUNCTION__);
Sungjoong Kangad378612012-08-17 12:34:33 -07002057 if (m_requestManager->IsRequestQueueFull()==false) {
Jiyoung Shinc15a6b02012-06-05 01:08:14 -07002058 m_requestQueueOps->dequeue_request(m_requestQueueOps, &currentRequest);
2059 if (NULL == currentRequest) {
Sungjoong Kangad378612012-08-17 12:34:33 -07002060 ALOGE("DEBUG(%s)(0x%x): dequeue_request returned NULL ", __FUNCTION__, currentSignal);
Sungjoong Kang13d8c7b2012-07-14 10:20:39 +09002061 m_isRequestQueueNull = true;
Jiyoung Shinc15a6b02012-06-05 01:08:14 -07002062 }
2063 else {
2064 m_requestManager->RegisterRequest(currentRequest);
Sungjoong Kang13d8c7b2012-07-14 10:20:39 +09002065
Jiyoung Shinc15a6b02012-06-05 01:08:14 -07002066 m_numOfRemainingReqInSvc = m_requestQueueOps->request_count(m_requestQueueOps);
Sungjoong Kang13d8c7b2012-07-14 10:20:39 +09002067 ALOGV("DEBUG(%s): remaining req cnt (%d)", __FUNCTION__, m_numOfRemainingReqInSvc);
Sungjoong Kangad378612012-08-17 12:34:33 -07002068 if (m_requestManager->IsRequestQueueFull()==false)
Sungjoong Kang13d8c7b2012-07-14 10:20:39 +09002069 selfThread->SetSignal(SIGNAL_MAIN_REQ_Q_NOT_EMPTY); // dequeue repeatedly
Sungjoong Kang9dd63e12012-07-24 00:25:51 +09002070
Jiyoung Shinc15a6b02012-06-05 01:08:14 -07002071 m_sensorThread->SetSignal(SIGNAL_SENSOR_START_REQ_PROCESSING);
2072 }
2073 }
2074 else {
2075 m_isRequestQueuePending = true;
2076 }
2077 }
2078
2079 if (currentSignal & SIGNAL_MAIN_STREAM_OUTPUT_DONE) {
Sungjoong Kang13d8c7b2012-07-14 10:20:39 +09002080 ALOGV("DEBUG(%s): MainThread processing SIGNAL_MAIN_STREAM_OUTPUT_DONE", __FUNCTION__);
2081 /*while (1)*/ {
Sungjoong Kang0f26b202012-08-17 15:43:12 -07002082 ret = m_requestManager->PrepareFrame(&numEntries, &frameSize, &preparedFrame, GetAfStateForService());
Sungjoong Kangad378612012-08-17 12:34:33 -07002083 if (ret == false)
2084 ALOGD("++++++ PrepareFrame ret = %d", ret);
2085
Sungjoong Kang13d8c7b2012-07-14 10:20:39 +09002086 m_requestManager->DeregisterRequest(&deregisteredRequest);
Sungjoong Kangad378612012-08-17 12:34:33 -07002087
2088 ret = m_requestQueueOps->free_request(m_requestQueueOps, deregisteredRequest);
2089 if (ret < 0)
2090 ALOGD("++++++ free_request ret = %d", ret);
2091
2092 ret = m_frameQueueOps->dequeue_frame(m_frameQueueOps, numEntries, frameSize, &currentFrame);
2093 if (ret < 0)
2094 ALOGD("++++++ dequeue_frame ret = %d", ret);
2095
Sungjoong Kang13d8c7b2012-07-14 10:20:39 +09002096 if (currentFrame==NULL) {
Sungjoong Kangad378612012-08-17 12:34:33 -07002097 ALOGV("DBG(%s): frame dequeue returned NULL",__FUNCTION__ );
Sungjoong Kang13d8c7b2012-07-14 10:20:39 +09002098 }
2099 else {
Sungjoong Kangdaa1fcd2012-08-08 11:49:43 -07002100 ALOGV("DEBUG(%s): frame dequeue done. numEntries(%d) frameSize(%d)",__FUNCTION__ , numEntries, frameSize);
Sungjoong Kang13d8c7b2012-07-14 10:20:39 +09002101 }
2102 res = append_camera_metadata(currentFrame, preparedFrame);
2103 if (res==0) {
2104 ALOGV("DEBUG(%s): frame metadata append success",__FUNCTION__);
2105 m_frameQueueOps->enqueue_frame(m_frameQueueOps, currentFrame);
2106 }
2107 else {
2108 ALOGE("ERR(%s): frame metadata append fail (%d)",__FUNCTION__, res);
2109 }
Jiyoung Shinc15a6b02012-06-05 01:08:14 -07002110 }
Sungjoong Kang13d8c7b2012-07-14 10:20:39 +09002111 if (!m_isRequestQueueNull) {
2112 selfThread->SetSignal(SIGNAL_MAIN_REQ_Q_NOT_EMPTY);
Jiyoung Shinc15a6b02012-06-05 01:08:14 -07002113 }
Sungjoong Kang9dd63e12012-07-24 00:25:51 +09002114
Sungjoong Kang13d8c7b2012-07-14 10:20:39 +09002115 if (getInProgressCount()>0) {
2116 ALOGV("DEBUG(%s): STREAM_OUTPUT_DONE and signalling REQ_PROCESSING",__FUNCTION__);
2117 m_sensorThread->SetSignal(SIGNAL_SENSOR_START_REQ_PROCESSING);
Jiyoung Shinc15a6b02012-06-05 01:08:14 -07002118 }
Jiyoung Shinc15a6b02012-06-05 01:08:14 -07002119 }
Sungjoong Kang13d8c7b2012-07-14 10:20:39 +09002120 ALOGV("DEBUG(%s): MainThread Exit", __FUNCTION__);
Jiyoung Shinc15a6b02012-06-05 01:08:14 -07002121 return;
2122}
Sungjoong Kang13d8c7b2012-07-14 10:20:39 +09002123
Jiyoung Shinc15a6b02012-06-05 01:08:14 -07002124void ExynosCameraHWInterface2::m_sensorThreadInitialize(SignalDrivenThread * self)
2125{
Sungjoong Kang13d8c7b2012-07-14 10:20:39 +09002126 ALOGV("DEBUG(%s): ", __FUNCTION__ );
Sungjoong Kangad378612012-08-17 12:34:33 -07002127 /* will add */
Sungjoong Kang13d8c7b2012-07-14 10:20:39 +09002128 return;
2129}
2130
2131
Sungjoong Kang13d8c7b2012-07-14 10:20:39 +09002132void ExynosCameraHWInterface2::DumpInfoWithShot(struct camera2_shot_ext * shot_ext)
2133{
Sungjoong Kangad378612012-08-17 12:34:33 -07002134 ALOGD("#### common Section");
2135 ALOGD("#### magic(%x) ",
Sungjoong Kang13d8c7b2012-07-14 10:20:39 +09002136 shot_ext->shot.magicNumber);
Sungjoong Kangad378612012-08-17 12:34:33 -07002137 ALOGD("#### ctl Section");
2138 ALOGD("#### meta(%d) aper(%f) exp(%lld) duration(%lld) ISO(%d) AWB(%d)",
Sungjoong Kang13d8c7b2012-07-14 10:20:39 +09002139 shot_ext->shot.ctl.request.metadataMode,
Sungjoong Kangb56dcc02012-08-08 13:38:09 -07002140 shot_ext->shot.ctl.lens.aperture,
Sungjoong Kang13d8c7b2012-07-14 10:20:39 +09002141 shot_ext->shot.ctl.sensor.exposureTime,
2142 shot_ext->shot.ctl.sensor.frameDuration,
Sungjoong Kangb56dcc02012-08-08 13:38:09 -07002143 shot_ext->shot.ctl.sensor.sensitivity,
2144 shot_ext->shot.ctl.aa.awbMode);
Sungjoong Kang13d8c7b2012-07-14 10:20:39 +09002145
Sungjoong Kangad378612012-08-17 12:34:33 -07002146 ALOGD("#### OutputStream Sensor(%d) SCP(%d) SCC(%d) pv(%d) rec(%d)",
Sungjoong Kang9dd63e12012-07-24 00:25:51 +09002147 shot_ext->request_sensor, shot_ext->request_scp, shot_ext->request_scc,
2148 shot_ext->shot.ctl.request.outputStreams[0],
2149 shot_ext->shot.ctl.request.outputStreams[2]);
Sungjoong Kang13d8c7b2012-07-14 10:20:39 +09002150
Sungjoong Kangad378612012-08-17 12:34:33 -07002151 ALOGD("#### DM Section");
2152 ALOGD("#### meta(%d) aper(%f) exp(%lld) duration(%lld) ISO(%d) timestamp(%lld) AWB(%d) cnt(%d)",
Sungjoong Kang13d8c7b2012-07-14 10:20:39 +09002153 shot_ext->shot.dm.request.metadataMode,
Sungjoong Kangb56dcc02012-08-08 13:38:09 -07002154 shot_ext->shot.dm.lens.aperture,
Sungjoong Kang13d8c7b2012-07-14 10:20:39 +09002155 shot_ext->shot.dm.sensor.exposureTime,
2156 shot_ext->shot.dm.sensor.frameDuration,
2157 shot_ext->shot.dm.sensor.sensitivity,
Sungjoong Kangb56dcc02012-08-08 13:38:09 -07002158 shot_ext->shot.dm.sensor.timeStamp,
2159 shot_ext->shot.dm.aa.awbMode,
2160 shot_ext->shot.dm.request.frameCount );
Sungjoong Kang13d8c7b2012-07-14 10:20:39 +09002161}
2162
2163void ExynosCameraHWInterface2::m_sensorThreadFunc(SignalDrivenThread * self)
2164{
2165 uint32_t currentSignal = self->GetProcessingSignal();
2166 SensorThread * selfThread = ((SensorThread*)self);
2167 int index;
Sungjoong Kangad378612012-08-17 12:34:33 -07002168 int index_isp;
Sungjoong Kang13d8c7b2012-07-14 10:20:39 +09002169 status_t res;
2170 nsecs_t frameTime;
2171 int bayersOnSensor = 0, bayersOnIsp = 0;
Sungjoong Kangad378612012-08-17 12:34:33 -07002172 int j = 0;
2173 bool isCapture = false;
Sungjoong Kang13d8c7b2012-07-14 10:20:39 +09002174 ALOGV("DEBUG(%s): m_sensorThreadFunc (%x)", __FUNCTION__, currentSignal);
2175
2176 if (currentSignal & SIGNAL_THREAD_RELEASE) {
Sungjoong Kangad378612012-08-17 12:34:33 -07002177 ALOGV("(%s): ENTER processing SIGNAL_THREAD_RELEASE", __FUNCTION__);
Sungjoong Kang13d8c7b2012-07-14 10:20:39 +09002178
Sungjoong Kang9dd63e12012-07-24 00:25:51 +09002179 ALOGV("(%s): calling sensor streamoff", __FUNCTION__);
Sungjoong Kang13d8c7b2012-07-14 10:20:39 +09002180 cam_int_streamoff(&(m_camera_info.sensor));
Sungjoong Kang9dd63e12012-07-24 00:25:51 +09002181 ALOGV("(%s): calling sensor streamoff done", __FUNCTION__);
Sungjoong Kangb5237e62012-07-27 07:39:05 -07002182
2183 m_camera_info.sensor.buffers = 0;
2184 ALOGV("DEBUG(%s): sensor calling reqbuf 0 ", __FUNCTION__);
2185 cam_int_reqbufs(&(m_camera_info.sensor));
2186 ALOGV("DEBUG(%s): sensor calling reqbuf 0 done", __FUNCTION__);
Sungjoong Kangad378612012-08-17 12:34:33 -07002187
Sungjoong Kang9dd63e12012-07-24 00:25:51 +09002188 ALOGV("(%s): calling ISP streamoff", __FUNCTION__);
2189 isp_int_streamoff(&(m_camera_info.isp));
2190 ALOGV("(%s): calling ISP streamoff done", __FUNCTION__);
Sungjoong Kangad378612012-08-17 12:34:33 -07002191
Sungjoong Kangb5237e62012-07-27 07:39:05 -07002192 m_camera_info.isp.buffers = 0;
2193 ALOGV("DEBUG(%s): isp calling reqbuf 0 ", __FUNCTION__);
2194 cam_int_reqbufs(&(m_camera_info.isp));
2195 ALOGV("DEBUG(%s): isp calling reqbuf 0 done", __FUNCTION__);
2196
Sungjoong Kang13d8c7b2012-07-14 10:20:39 +09002197 exynos_v4l2_s_ctrl(m_camera_info.sensor.fd, V4L2_CID_IS_S_STREAM, IS_DISABLE_STREAM);
Sungjoong Kang13d8c7b2012-07-14 10:20:39 +09002198
Sungjoong Kangad378612012-08-17 12:34:33 -07002199 ALOGV("(%s): EXIT processing SIGNAL_THREAD_RELEASE", __FUNCTION__);
Sungjoong Kang13d8c7b2012-07-14 10:20:39 +09002200 selfThread->SetSignal(SIGNAL_THREAD_TERMINATE);
2201 return;
2202 }
2203
2204 if (currentSignal & SIGNAL_SENSOR_START_REQ_PROCESSING)
2205 {
2206 ALOGV("DEBUG(%s): SensorThread processing SIGNAL_SENSOR_START_REQ_PROCESSING", __FUNCTION__);
Sungjoong Kang9dd63e12012-07-24 00:25:51 +09002207 int targetStreamIndex = 0, i=0;
Sungjoong Kangad378612012-08-17 12:34:33 -07002208 int matchedFrameCnt = -1, processingReqIndex;
Sungjoong Kang13d8c7b2012-07-14 10:20:39 +09002209 struct camera2_shot_ext *shot_ext;
Sungjoong Kangad378612012-08-17 12:34:33 -07002210 struct camera2_shot_ext *shot_ext_capture;
Sungjoong Kang0f26b202012-08-17 15:43:12 -07002211 bool triggered = false;
2212 int afMode;
Sungjoong Kang9dd63e12012-07-24 00:25:51 +09002213
Sungjoong Kangad378612012-08-17 12:34:33 -07002214 /* dqbuf from sensor */
2215 ALOGV("Sensor DQbuf start");
Sungjoong Kang13d8c7b2012-07-14 10:20:39 +09002216 index = cam_int_dqbuf(&(m_camera_info.sensor));
Sungjoong Kang9dd63e12012-07-24 00:25:51 +09002217 shot_ext = (struct camera2_shot_ext *)(m_camera_info.sensor.buffer[index].virt.extP[1]);
Sungjoong Kangad378612012-08-17 12:34:33 -07002218
2219 m_recordOutput = shot_ext->shot.ctl.request.outputStreams[2];
2220
Sungjoong Kang9dd63e12012-07-24 00:25:51 +09002221 matchedFrameCnt = m_requestManager->FindFrameCnt(shot_ext);
Sungjoong Kangad378612012-08-17 12:34:33 -07002222
Sungjoong Kanga07cbd92012-07-27 12:03:29 -07002223 if (matchedFrameCnt != -1) {
Sungjoong Kanga07cbd92012-07-27 12:03:29 -07002224 frameTime = systemTime();
Sungjoong Kang9dd63e12012-07-24 00:25:51 +09002225 m_requestManager->RegisterTimestamp(matchedFrameCnt, &frameTime);
Sungjoong Kang0f26b202012-08-17 15:43:12 -07002226 if (m_IsAfModeUpdateRequired) {
2227 ALOGE("### AF Mode change(Mode %d) ", m_afMode);
2228 shot_ext->shot.ctl.aa.afMode = m_afMode;
2229 if (m_afMode == AA_AFMODE_CONTINUOUS_VIDEO || m_afMode == AA_AFMODE_CONTINUOUS_PICTURE) {
2230 ALOGE("### With Automatic triger for continuous modes");
2231 m_afState = HAL_AFSTATE_STARTED;
2232 shot_ext->shot.ctl.aa.afTrigger = 1;
2233 triggered = true;
2234 }
2235 m_IsAfModeUpdateRequired = false;
2236 if (m_afMode2 != NO_CHANGE) {
2237 enum aa_afmode tempAfMode = m_afMode2;
2238 m_afMode2 = NO_CHANGE;
2239 SetAfMode(tempAfMode);
2240 }
2241 }
2242 else {
2243 shot_ext->shot.ctl.aa.afMode = NO_CHANGE;
2244 }
2245 if (m_IsAfTriggerRequired) {
2246 ALOGE("### AF Triggering with mode (%d)", m_afMode);
2247 if (m_afState != HAL_AFSTATE_NEEDS_COMMAND)
2248 ALOGE("(%s): wrong trigger state %d", __FUNCTION__, m_afState);
2249 else
2250 m_afState = HAL_AFSTATE_STARTED;
2251 m_requestManager->UpdateIspParameters(shot_ext, matchedFrameCnt, true);
2252 shot_ext->shot.ctl.aa.afMode = m_afMode;
2253 m_IsAfTriggerRequired = false;
2254 }
2255 else {
2256 m_requestManager->UpdateIspParameters(shot_ext, matchedFrameCnt, false);
2257 }
2258 if (triggered)
2259 shot_ext->shot.ctl.aa.afTrigger = 1;
2260
2261 // TODO : check collision with AFMode Update
2262 if (m_IsAfLockRequired) {
2263 shot_ext->shot.ctl.aa.afMode = AA_AFMODE_OFF;
2264 m_IsAfLockRequired = false;
2265 }
Rebecca Schultz Zavin4ed2f102012-08-22 00:55:29 -07002266 ALOGV("### Isp Qbuf start(%d) count (%d), SCP(%d) SCC(%d) DIS(%d) shot_size(%d)",
Sungjoong Kangad378612012-08-17 12:34:33 -07002267 index,
2268 shot_ext->shot.ctl.request.frameCount,
2269 shot_ext->request_scp,
2270 shot_ext->request_scc,
2271 shot_ext->dis_bypass, sizeof(camera2_shot));
Sungjoong Kang9dd63e12012-07-24 00:25:51 +09002272
Sungjoong Kangad378612012-08-17 12:34:33 -07002273 if(shot_ext->request_scc == 1) {
2274 isCapture = true;
Sungjoong Kang13d8c7b2012-07-14 10:20:39 +09002275 }
2276
Sungjoong Kangad378612012-08-17 12:34:33 -07002277 if(isCapture)
2278 {
2279 for(j = 0; j < m_camera_info.isp.buffers; j++)
2280 {
2281 shot_ext_capture = (struct camera2_shot_ext *)(m_camera_info.isp.buffer[j].virt.extP[1]);
2282 shot_ext_capture->request_scc = 1;
2283 }
Sungjoong Kang9dd63e12012-07-24 00:25:51 +09002284 }
Sungjoong Kangad378612012-08-17 12:34:33 -07002285
2286 cam_int_qbuf(&(m_camera_info.isp), index);
2287 //m_ispThread->SetSignal(SIGNAL_ISP_START_BAYER_DEQUEUE);
2288
2289 usleep(10000);
2290 if(isCapture)
2291 {
2292 for(j = 0; j < m_camera_info.isp.buffers; j++)
2293 {
2294 shot_ext_capture = (struct camera2_shot_ext *)(m_camera_info.isp.buffer[j].virt.extP[1]);
2295 ALOGD("shot_ext_capture[%d] scp = %d, scc = %d", j, shot_ext_capture->request_scp, shot_ext_capture->request_scc);
2296// DumpInfoWithShot(shot_ext_capture);
2297 }
2298 }
2299
2300
2301 ALOGV("### isp DQBUF start");
2302 index_isp = cam_int_dqbuf(&(m_camera_info.isp));
2303 //m_previewOutput = 0;
2304
2305 if(isCapture)
2306 {
2307 for(j = 0; j < m_camera_info.isp.buffers; j++)
2308 {
2309 shot_ext_capture = (struct camera2_shot_ext *)(m_camera_info.isp.buffer[j].virt.extP[1]);
2310 ALOGD("shot_ext_capture[%d] scp = %d, scc = %d", j, shot_ext_capture->request_scp, shot_ext_capture->request_scc);
2311// DumpInfoWithShot(shot_ext_capture);
2312 }
2313 }
2314 shot_ext = (struct camera2_shot_ext *)(m_camera_info.isp.buffer[index_isp].virt.extP[1]);
2315
2316 ALOGV("### Isp DQbuf done(%d) count (%d), SCP(%d) SCC(%d) shot_size(%d)",
2317 index,
2318 shot_ext->shot.ctl.request.frameCount,
2319 shot_ext->request_scp,
2320 shot_ext->request_scc,
2321 shot_ext->dis_bypass, sizeof(camera2_shot));
2322
2323 if(isCapture) {
2324 ALOGD("======= request_scc is 1");
2325 m_streamThreads[1]->SetSignal(SIGNAL_STREAM_DATA_COMING);
2326
2327 for(j = 0; j < m_camera_info.isp.buffers; j++)
2328 {
2329 shot_ext_capture = (struct camera2_shot_ext *)(m_camera_info.isp.buffer[j].virt.extP[1]);
2330 shot_ext_capture->request_scc = 0;
2331 }
2332
2333 isCapture = false;
2334 }
2335
2336 if (shot_ext->request_scp) {
2337 m_previewOutput = 1;
2338 m_streamThreads[0]->SetSignal(SIGNAL_STREAM_DATA_COMING);
2339 }
2340
2341
2342 ALOGV("(%s): SCP_CLOSING check sensor(%d) scc(%d) scp(%d) ", __FUNCTION__,
2343 shot_ext->request_sensor, shot_ext->request_scc, shot_ext->request_scp);
2344 if (shot_ext->request_scc + shot_ext->request_scp + shot_ext->request_sensor == 0) {
2345 ALOGV("(%s): SCP_CLOSING check OK ", __FUNCTION__);
2346 m_scp_closed = true;
2347 }
2348 else
2349 m_scp_closed = false;
2350
2351 m_requestManager->ApplyDynamicMetadata(shot_ext);
Sungjoong Kang0f26b202012-08-17 15:43:12 -07002352 OnAfNotification(shot_ext->shot.dm.aa.afState);
Sungjoong Kang13d8c7b2012-07-14 10:20:39 +09002353 }
Sungjoong Kangad378612012-08-17 12:34:33 -07002354
Sungjoong Kang0f26b202012-08-17 15:43:12 -07002355 processingReqIndex = m_requestManager->MarkProcessingRequest(&(m_camera_info.sensor.buffer[index]), &afMode);
Sungjoong Kangad378612012-08-17 12:34:33 -07002356 if (processingReqIndex == -1)
2357 {
2358 ALOGE("DEBUG(%s) req underrun => inserting bubble to BayerIndex(%d)", __FUNCTION__, index);
2359 }
Sungjoong Kang0f26b202012-08-17 15:43:12 -07002360 else {
2361 SetAfMode((enum aa_afmode)afMode);
2362 }
Sungjoong Kangad378612012-08-17 12:34:33 -07002363
2364 shot_ext = (struct camera2_shot_ext *)(m_camera_info.sensor.buffer[index].virt.extP[1]);
2365 if (m_scp_closing || m_scp_closed) {
2366 ALOGD("(%s): SCP_CLOSING(%d) SCP_CLOSED(%d)", __FUNCTION__, m_scp_closing, m_scp_closed);
2367 shot_ext->request_scc = 0;
2368 shot_ext->request_scp = 0;
2369 shot_ext->request_sensor = 0;
2370 }
2371
Rebecca Schultz Zavin4ed2f102012-08-22 00:55:29 -07002372 ALOGV("### Sensor Qbuf start(%d) SCP(%d) SCC(%d) DIS(%d)", index, shot_ext->request_scp, shot_ext->request_scc, shot_ext->dis_bypass);
Sungjoong Kangad378612012-08-17 12:34:33 -07002373
2374 cam_int_qbuf(&(m_camera_info.sensor), index);
2375 ALOGV("### Sensor QBUF done");
2376
Sungjoong Kang9dd63e12012-07-24 00:25:51 +09002377 if (!m_closing){
Sungjoong Kang13d8c7b2012-07-14 10:20:39 +09002378 selfThread->SetSignal(SIGNAL_SENSOR_START_REQ_PROCESSING);
Sungjoong Kang13d8c7b2012-07-14 10:20:39 +09002379 }
Sungjoong Kang9dd63e12012-07-24 00:25:51 +09002380 return;
2381 }
Sungjoong Kang13d8c7b2012-07-14 10:20:39 +09002382 return;
2383}
2384
Sungjoong Kang13d8c7b2012-07-14 10:20:39 +09002385void ExynosCameraHWInterface2::m_ispThreadInitialize(SignalDrivenThread * self)
2386{
2387 ALOGV("DEBUG(%s): ", __FUNCTION__ );
Sungjoong Kangad378612012-08-17 12:34:33 -07002388 /* will add */
Jiyoung Shinc15a6b02012-06-05 01:08:14 -07002389 return;
2390}
2391
Jiyoung Shinc15a6b02012-06-05 01:08:14 -07002392
Sungjoong Kang13d8c7b2012-07-14 10:20:39 +09002393void ExynosCameraHWInterface2::m_ispThreadFunc(SignalDrivenThread * self)
2394{
Sungjoong Kangad378612012-08-17 12:34:33 -07002395 ALOGV("DEBUG(%s): ", __FUNCTION__ );
2396 /* will add */
Jiyoung Shinc15a6b02012-06-05 01:08:14 -07002397 return;
2398}
2399
2400void ExynosCameraHWInterface2::m_streamThreadInitialize(SignalDrivenThread * self)
2401{
Sungjoong Kang13d8c7b2012-07-14 10:20:39 +09002402 StreamThread * selfThread = ((StreamThread*)self);
2403 ALOGV("DEBUG(%s): ", __FUNCTION__ );
2404 memset(&(selfThread->m_parameters), 0, sizeof(stream_parameters_t));
2405 selfThread->m_isBufferInit = false;
2406
Jiyoung Shinc15a6b02012-06-05 01:08:14 -07002407 return;
2408}
2409
Jiyoung Shinc15a6b02012-06-05 01:08:14 -07002410void ExynosCameraHWInterface2::m_streamThreadFunc(SignalDrivenThread * self)
2411{
Sungjoong Kang13d8c7b2012-07-14 10:20:39 +09002412 uint32_t currentSignal = self->GetProcessingSignal();
2413 StreamThread * selfThread = ((StreamThread*)self);
2414 stream_parameters_t *selfStreamParms = &(selfThread->m_parameters);
Sungjoong Kang9dd63e12012-07-24 00:25:51 +09002415 record_parameters_t *selfRecordParms = &(selfThread->m_recordParameters);
Sungjoong Kang13d8c7b2012-07-14 10:20:39 +09002416 node_info_t *currentNode = &(selfStreamParms->node);
Jiyoung Shinc15a6b02012-06-05 01:08:14 -07002417
Sungjoong Kang13d8c7b2012-07-14 10:20:39 +09002418 ALOGV("DEBUG(%s): m_streamThreadFunc[%d] (%x)", __FUNCTION__, selfThread->m_index, currentSignal);
Jiyoung Shinc15a6b02012-06-05 01:08:14 -07002419
Sungjoong Kang13d8c7b2012-07-14 10:20:39 +09002420 if (currentSignal & SIGNAL_STREAM_CHANGE_PARAMETER) {
2421 ALOGV("DEBUG(%s): processing SIGNAL_STREAM_CHANGE_PARAMETER", __FUNCTION__);
2422 selfThread->applyChange();
Sungjoong Kang37e122d2012-08-08 11:13:48 -07002423 if (selfStreamParms->streamType == STREAM_TYPE_INDIRECT) {
Sungjoong Kang13d8c7b2012-07-14 10:20:39 +09002424 m_resizeBuf.size.extS[0] = ALIGN(selfStreamParms->outputWidth, 16) * ALIGN(selfStreamParms->outputHeight, 16) * 2;
2425 m_resizeBuf.size.extS[1] = 0;
2426 m_resizeBuf.size.extS[2] = 0;
Jiyoung Shinc15a6b02012-06-05 01:08:14 -07002427
Sungjoong Kang13d8c7b2012-07-14 10:20:39 +09002428 if (allocCameraMemory(selfStreamParms->ionClient, &m_resizeBuf, 1) == -1) {
2429 ALOGE("ERR(%s): Failed to allocate resize buf", __FUNCTION__);
2430 }
2431 }
2432 ALOGV("DEBUG(%s): processing SIGNAL_STREAM_CHANGE_PARAMETER DONE", __FUNCTION__);
Jiyoung Shinc15a6b02012-06-05 01:08:14 -07002433 }
Sungjoong Kang13d8c7b2012-07-14 10:20:39 +09002434
2435 if (currentSignal & SIGNAL_THREAD_RELEASE) {
Sungjoong Kang9dd63e12012-07-24 00:25:51 +09002436 int i, index = -1, cnt_to_dq = 0;
Sungjoong Kang13d8c7b2012-07-14 10:20:39 +09002437 status_t res;
2438 ALOGV("DEBUG(%s): processing SIGNAL_THREAD_RELEASE", __FUNCTION__);
Sungjoong Kangad378612012-08-17 12:34:33 -07002439 ALOGD("(%s):(%d) SIGNAL_THREAD_RELEASE", __FUNCTION__, selfStreamParms->streamType);
Sungjoong Kang13d8c7b2012-07-14 10:20:39 +09002440
2441 if (selfThread->m_isBufferInit) {
2442 for ( i=0 ; i < selfStreamParms->numSvcBuffers; i++) {
2443 ALOGV("DEBUG(%s): checking buffer index[%d] - status(%d)",
2444 __FUNCTION__, i, selfStreamParms->svcBufStatus[i]);
2445 if (selfStreamParms->svcBufStatus[i] ==ON_DRIVER) cnt_to_dq++;
2446 }
Sungjoong Kangb5237e62012-07-27 07:39:05 -07002447
Sungjoong Kang9dd63e12012-07-24 00:25:51 +09002448 m_scp_closing = true;
Sungjoong Kang13d8c7b2012-07-14 10:20:39 +09002449 ALOGV("DEBUG(%s): calling stream(%d) streamoff (fd:%d)", __FUNCTION__,
2450 selfThread->m_index, selfStreamParms->fd);
2451 cam_int_streamoff(&(selfStreamParms->node));
2452 ALOGV("DEBUG(%s): calling stream(%d) streamoff done", __FUNCTION__, selfThread->m_index);
Sungjoong Kang37e122d2012-08-08 11:13:48 -07002453 if (selfStreamParms->streamType == STREAM_TYPE_DIRECT) {
Sungjoong Kangb5237e62012-07-27 07:39:05 -07002454 ALOGV("DEBUG(%s): calling stream(%d) reqbuf 0 (fd:%d)", __FUNCTION__,
2455 selfThread->m_index, selfStreamParms->fd);
2456 currentNode->buffers = 0;
2457 cam_int_reqbufs(currentNode);
2458 ALOGV("DEBUG(%s): calling stream(%d) reqbuf 0 DONE(fd:%d)", __FUNCTION__,
2459 selfThread->m_index, selfStreamParms->fd);
Sungjoong Kang13d8c7b2012-07-14 10:20:39 +09002460 }
2461 }
Sungjoong Kangad378612012-08-17 12:34:33 -07002462 selfThread->m_releasing = false;
2463 ALOGD("m_releasing set false");
Sungjoong Kangb5237e62012-07-27 07:39:05 -07002464 if (selfThread->m_index == 1 && m_resizeBuf.size.s != 0) {
Sungjoong Kang9dd63e12012-07-24 00:25:51 +09002465 freeCameraMemory(&m_resizeBuf, 1);
Sungjoong Kang13d8c7b2012-07-14 10:20:39 +09002466 }
Sungjoong Kang9dd63e12012-07-24 00:25:51 +09002467 selfThread->m_isBufferInit = false;
Sungjoong Kang13d8c7b2012-07-14 10:20:39 +09002468 selfThread->m_index = 255;
Sungjoong Kang9dd63e12012-07-24 00:25:51 +09002469
Sungjoong Kang13d8c7b2012-07-14 10:20:39 +09002470 ALOGV("DEBUG(%s): processing SIGNAL_THREAD_RELEASE DONE", __FUNCTION__);
Sungjoong Kang9dd63e12012-07-24 00:25:51 +09002471
Sungjoong Kang13d8c7b2012-07-14 10:20:39 +09002472 return;
2473 }
2474
2475 if (currentSignal & SIGNAL_STREAM_DATA_COMING) {
Jiyoung Shinc15a6b02012-06-05 01:08:14 -07002476 buffer_handle_t * buf = NULL;
2477 status_t res;
2478 void *virtAddr[3];
2479 int i, j;
2480 int index;
Sungjoong Kangad378612012-08-17 12:34:33 -07002481 nsecs_t timestamp;
2482
Sungjoong Kang13d8c7b2012-07-14 10:20:39 +09002483 ALOGV("DEBUG(%s): stream(%d) processing SIGNAL_STREAM_DATA_COMING",
2484 __FUNCTION__,selfThread->m_index);
Sungjoong Kangad378612012-08-17 12:34:33 -07002485
2486 if (selfStreamParms->streamType == STREAM_TYPE_INDIRECT)
2487 {
2488 ALOGD("stream(%s) processing SIGNAL_STREAM_DATA_COMING",
2489 __FUNCTION__,selfThread->m_index);
2490 }
2491
Sungjoong Kang13d8c7b2012-07-14 10:20:39 +09002492 if (!(selfThread->m_isBufferInit)) {
2493 for ( i=0 ; i < selfStreamParms->numSvcBuffers; i++) {
2494 res = selfStreamParms->streamOps->dequeue_buffer(selfStreamParms->streamOps, &buf);
Jiyoung Shinc15a6b02012-06-05 01:08:14 -07002495 if (res != NO_ERROR || buf == NULL) {
Sungjoong Kang13d8c7b2012-07-14 10:20:39 +09002496 ALOGE("ERR(%s): Init: unable to dequeue buffer : %d",__FUNCTION__ , res);
Jiyoung Shinc15a6b02012-06-05 01:08:14 -07002497 return;
2498 }
Sungjoong Kang13d8c7b2012-07-14 10:20:39 +09002499 ALOGV("DEBUG(%s): got buf(%x) version(%d), numFds(%d), numInts(%d)", __FUNCTION__, (uint32_t)(*buf),
Jiyoung Shinc15a6b02012-06-05 01:08:14 -07002500 ((native_handle_t*)(*buf))->version, ((native_handle_t*)(*buf))->numFds, ((native_handle_t*)(*buf))->numInts);
Sungjoong Kang13d8c7b2012-07-14 10:20:39 +09002501
Jiyoung Shinc15a6b02012-06-05 01:08:14 -07002502 if (m_grallocHal->lock(m_grallocHal, *buf,
Sungjoong Kang13d8c7b2012-07-14 10:20:39 +09002503 selfStreamParms->usage,
2504 0, 0, selfStreamParms->outputWidth, selfStreamParms->outputHeight, virtAddr) != 0) {
2505 ALOGE("ERR(%s): could not obtain gralloc buffer", __FUNCTION__);
2506 return;
Jiyoung Shinc15a6b02012-06-05 01:08:14 -07002507 }
Sungjoong Kang13d8c7b2012-07-14 10:20:39 +09002508 ALOGV("DEBUG(%s): locked img buf plane0(%x) plane1(%x) plane2(%x)",
2509 __FUNCTION__, (unsigned int)virtAddr[0], (unsigned int)virtAddr[1], (unsigned int)virtAddr[2]);
2510
2511 index = selfThread->findBufferIndex(virtAddr[0]);
2512 if (index == -1) {
2513 ALOGE("ERR(%s): could not find buffer index", __FUNCTION__);
Jiyoung Shinc15a6b02012-06-05 01:08:14 -07002514 }
2515 else {
Sungjoong Kang13d8c7b2012-07-14 10:20:39 +09002516 ALOGV("DEBUG(%s): found buffer index[%d] - status(%d)",
2517 __FUNCTION__, index, selfStreamParms->svcBufStatus[index]);
2518 if (selfStreamParms->svcBufStatus[index]== REQUIRES_DQ_FROM_SVC)
2519 selfStreamParms->svcBufStatus[index] = ON_DRIVER;
2520 else if (selfStreamParms->svcBufStatus[index]== ON_SERVICE)
2521 selfStreamParms->svcBufStatus[index] = ON_HAL;
2522 else {
Sungjoong Kang9dd63e12012-07-24 00:25:51 +09002523 ALOGV("DBG(%s): buffer status abnormal (%d) "
Sungjoong Kang13d8c7b2012-07-14 10:20:39 +09002524 , __FUNCTION__, selfStreamParms->svcBufStatus[index]);
2525 }
Sungjoong Kangbe494d12012-08-04 15:36:56 -07002526 selfStreamParms->numSvcBufsInHal++;
Sungjoong Kang13d8c7b2012-07-14 10:20:39 +09002527 if (*buf != selfStreamParms->svcBufHandle[index])
Sungjoong Kang9dd63e12012-07-24 00:25:51 +09002528 ALOGV("DBG(%s): different buf_handle index ", __FUNCTION__);
Sungjoong Kang13d8c7b2012-07-14 10:20:39 +09002529 else
2530 ALOGV("DEBUG(%s): same buf_handle index", __FUNCTION__);
Jiyoung Shinc15a6b02012-06-05 01:08:14 -07002531 }
Sungjoong Kangbe494d12012-08-04 15:36:56 -07002532 selfStreamParms->svcBufIndex = 0;
Jiyoung Shinc15a6b02012-06-05 01:08:14 -07002533 }
Sungjoong Kang13d8c7b2012-07-14 10:20:39 +09002534 selfThread->m_isBufferInit = true;
Jiyoung Shinc15a6b02012-06-05 01:08:14 -07002535 }
Sungjoong Kangad378612012-08-17 12:34:33 -07002536
Sungjoong Kang9dd63e12012-07-24 00:25:51 +09002537 if (m_recordingEnabled && m_needsRecordBufferInit) {
2538 ALOGV("DEBUG(%s): Recording Buffer Initialization numsvcbuf(%d)",
2539 __FUNCTION__, selfRecordParms->numSvcBuffers);
Sungjoong Kangad378612012-08-17 12:34:33 -07002540 int checkingIndex = 0;
2541 bool found = false;
Sungjoong Kang9dd63e12012-07-24 00:25:51 +09002542 for ( i=0 ; i < selfRecordParms->numSvcBuffers; i++) {
2543 res = selfRecordParms->streamOps->dequeue_buffer(selfRecordParms->streamOps, &buf);
2544 if (res != NO_ERROR || buf == NULL) {
2545 ALOGE("ERR(%s): Init: unable to dequeue buffer : %d",__FUNCTION__ , res);
2546 return;
2547 }
Sungjoong Kangbe494d12012-08-04 15:36:56 -07002548 selfRecordParms->numSvcBufsInHal++;
Sungjoong Kang9dd63e12012-07-24 00:25:51 +09002549 ALOGV("DEBUG(%s): [record] got buf(%x) bufInHal(%d) version(%d), numFds(%d), numInts(%d)", __FUNCTION__, (uint32_t)(*buf),
Sungjoong Kangbe494d12012-08-04 15:36:56 -07002550 selfRecordParms->numSvcBufsInHal, ((native_handle_t*)(*buf))->version, ((native_handle_t*)(*buf))->numFds, ((native_handle_t*)(*buf))->numInts);
Sungjoong Kang9dd63e12012-07-24 00:25:51 +09002551
2552 if (m_grallocHal->lock(m_grallocHal, *buf,
2553 selfRecordParms->usage, 0, 0,
2554 selfRecordParms->outputWidth, selfRecordParms->outputHeight, virtAddr) != 0) {
2555 ALOGE("ERR(%s): could not obtain gralloc buffer", __FUNCTION__);
2556 }
Sungjoong Kangad378612012-08-17 12:34:33 -07002557 else {
Sungjoong Kang9dd63e12012-07-24 00:25:51 +09002558 ALOGV("DEBUG(%s): [record] locked img buf plane0(%x) plane1(%x) plane2(%x)",
2559 __FUNCTION__, (unsigned int)virtAddr[0], (unsigned int)virtAddr[1], (unsigned int)virtAddr[2]);
Sungjoong Kang9dd63e12012-07-24 00:25:51 +09002560 }
2561 found = false;
2562 for (checkingIndex = 0; checkingIndex < selfRecordParms->numSvcBuffers ; checkingIndex++) {
Sungjoong Kang9dd63e12012-07-24 00:25:51 +09002563 if (selfRecordParms->svcBufHandle[checkingIndex] == *buf ) {
2564 found = true;
2565 break;
2566 }
2567 }
2568 ALOGV("DEBUG(%s): [record] found(%d) - index[%d]", __FUNCTION__, found, checkingIndex);
2569 if (!found) break;
Sungjoong Kangad378612012-08-17 12:34:33 -07002570
Sungjoong Kang9dd63e12012-07-24 00:25:51 +09002571 index = checkingIndex;
2572
Sungjoong Kang9dd63e12012-07-24 00:25:51 +09002573 if (index == -1) {
Sungjoong Kangad378612012-08-17 12:34:33 -07002574 ALOGV("ERR(%s): could not find buffer index", __FUNCTION__);
Sungjoong Kang9dd63e12012-07-24 00:25:51 +09002575 }
2576 else {
2577 ALOGV("DEBUG(%s): found buffer index[%d] - status(%d)",
2578 __FUNCTION__, index, selfRecordParms->svcBufStatus[index]);
2579 if (selfRecordParms->svcBufStatus[index]== ON_SERVICE)
2580 selfRecordParms->svcBufStatus[index] = ON_HAL;
2581 else {
2582 ALOGV("DBG(%s): buffer status abnormal (%d) "
2583 , __FUNCTION__, selfRecordParms->svcBufStatus[index]);
2584 }
2585 if (*buf != selfRecordParms->svcBufHandle[index])
2586 ALOGV("DBG(%s): different buf_handle index ", __FUNCTION__);
2587 else
2588 ALOGV("DEBUG(%s): same buf_handle index", __FUNCTION__);
2589 }
Sungjoong Kangbe494d12012-08-04 15:36:56 -07002590 selfRecordParms->svcBufIndex = 0;
Sungjoong Kang9dd63e12012-07-24 00:25:51 +09002591 }
2592 m_needsRecordBufferInit = false;
2593 }
Jiyoung Shinc15a6b02012-06-05 01:08:14 -07002594
Sungjoong Kangb5237e62012-07-27 07:39:05 -07002595 do {
Sungjoong Kang37e122d2012-08-08 11:13:48 -07002596 if (selfStreamParms->streamType == STREAM_TYPE_DIRECT) {
Sungjoong Kangb5237e62012-07-27 07:39:05 -07002597 ALOGV("DEBUG(%s): stream(%d) type(%d) DQBUF START ",__FUNCTION__,
2598 selfThread->m_index, selfStreamParms->streamType);
Jiyoung Shinc15a6b02012-06-05 01:08:14 -07002599
Sungjoong Kangb5237e62012-07-27 07:39:05 -07002600 index = cam_int_dqbuf(&(selfStreamParms->node));
2601 ALOGV("DEBUG(%s): stream(%d) type(%d) DQBUF done index(%d)",__FUNCTION__,
2602 selfThread->m_index, selfStreamParms->streamType, index);
Sungjoong Kang13d8c7b2012-07-14 10:20:39 +09002603
Sungjoong Kang13d8c7b2012-07-14 10:20:39 +09002604
Sungjoong Kangb5237e62012-07-27 07:39:05 -07002605 if (selfStreamParms->svcBufStatus[index] != ON_DRIVER)
Sungjoong Kangad378612012-08-17 12:34:33 -07002606 ALOGV("DBG(%s): DQed buffer status abnormal (%d) ",
Sungjoong Kangb5237e62012-07-27 07:39:05 -07002607 __FUNCTION__, selfStreamParms->svcBufStatus[index]);
2608 selfStreamParms->svcBufStatus[index] = ON_HAL;
Sungjoong Kang9dd63e12012-07-24 00:25:51 +09002609
Sungjoong Kangb5237e62012-07-27 07:39:05 -07002610 if (m_recordOutput && m_recordingEnabled) {
Sungjoong Kangbe494d12012-08-04 15:36:56 -07002611 ALOGV("DEBUG(%s): Entering record frame creator, index(%d)",__FUNCTION__, selfRecordParms->svcBufIndex);
Sungjoong Kangb5237e62012-07-27 07:39:05 -07002612 bool found = false;
2613 for (int i = 0 ; selfRecordParms->numSvcBuffers ; i++) {
Sungjoong Kangbe494d12012-08-04 15:36:56 -07002614 if (selfRecordParms->svcBufStatus[selfRecordParms->svcBufIndex] == ON_HAL) {
Sungjoong Kangb5237e62012-07-27 07:39:05 -07002615 found = true;
2616 break;
2617 }
Sungjoong Kangbe494d12012-08-04 15:36:56 -07002618 selfRecordParms->svcBufIndex++;
2619 if (selfRecordParms->svcBufIndex >= selfRecordParms->numSvcBuffers)
2620 selfRecordParms->svcBufIndex = 0;
Sungjoong Kangb5237e62012-07-27 07:39:05 -07002621 }
2622 if (!found) {
2623 ALOGE("(%s): cannot find free recording buffer", __FUNCTION__);
Sungjoong Kangbe494d12012-08-04 15:36:56 -07002624 selfRecordParms->svcBufIndex++;
Sungjoong Kangb5237e62012-07-27 07:39:05 -07002625 break;
2626 }
Sungjoong Kang9dd63e12012-07-24 00:25:51 +09002627
Sungjoong Kangb5237e62012-07-27 07:39:05 -07002628 if (m_exynosVideoCSC) {
2629 int videoW = selfRecordParms->outputWidth, videoH = selfRecordParms->outputHeight;
2630 int cropX, cropY, cropW, cropH = 0;
2631 int previewW = selfStreamParms->outputWidth, previewH = selfStreamParms->outputHeight;
Sungjoong Kangb5237e62012-07-27 07:39:05 -07002632 m_getRatioSize(previewW, previewH,
Sungjoong Kang804236a2012-08-05 10:36:19 -07002633 videoW, videoH,
Sungjoong Kangb5237e62012-07-27 07:39:05 -07002634 &cropX, &cropY,
2635 &cropW, &cropH,
Sungjoong Kang9dd63e12012-07-24 00:25:51 +09002636 0);
2637
Sungjoong Kangb5237e62012-07-27 07:39:05 -07002638 ALOGV("DEBUG(%s):cropX = %d, cropY = %d, cropW = %d, cropH = %d",
2639 __FUNCTION__, cropX, cropY, cropW, cropH);
Sungjoong Kang9dd63e12012-07-24 00:25:51 +09002640
Sungjoong Kangb5237e62012-07-27 07:39:05 -07002641 csc_set_src_format(m_exynosVideoCSC,
Sungjoong Kangb5237e62012-07-27 07:39:05 -07002642 previewW, previewH,
2643 cropX, cropY, cropW, cropH,
Rebecca Schultz Zavinc853be72012-08-23 00:03:05 -07002644 HAL_PIXEL_FORMAT_EXYNOS_YV12,
Sungjoong Kangb5237e62012-07-27 07:39:05 -07002645 0);
Sungjoong Kang9dd63e12012-07-24 00:25:51 +09002646
Sungjoong Kangb5237e62012-07-27 07:39:05 -07002647 csc_set_dst_format(m_exynosVideoCSC,
Sungjoong Kang804236a2012-08-05 10:36:19 -07002648 videoW, videoH,
Sungjoong Kangb5237e62012-07-27 07:39:05 -07002649 0, 0, videoW, videoH,
Sungjoong Kangbe494d12012-08-04 15:36:56 -07002650 selfRecordParms->outputFormat,
Sungjoong Kangb5237e62012-07-27 07:39:05 -07002651 1);
Sungjoong Kang9dd63e12012-07-24 00:25:51 +09002652
Sungjoong Kangb5237e62012-07-27 07:39:05 -07002653 csc_set_src_buffer(m_exynosVideoCSC,
2654 (void **)(&(selfStreamParms->svcBuffers[index].fd.fd)));
Sungjoong Kang804236a2012-08-05 10:36:19 -07002655
Sungjoong Kangb5237e62012-07-27 07:39:05 -07002656 csc_set_dst_buffer(m_exynosVideoCSC,
Sungjoong Kang804236a2012-08-05 10:36:19 -07002657 (void **)(&(selfRecordParms->svcBuffers[selfRecordParms->svcBufIndex].fd.fd)));
Sungjoong Kangb5237e62012-07-27 07:39:05 -07002658
2659 if (csc_convert(m_exynosVideoCSC) != 0) {
2660 ALOGE("ERR(%s):csc_convert() fail", __FUNCTION__);
2661 }
2662 else {
Sungjoong Kangbe494d12012-08-04 15:36:56 -07002663 ALOGV("(%s):csc_convert() SUCCESS", __FUNCTION__);
Sungjoong Kangb5237e62012-07-27 07:39:05 -07002664 }
Sungjoong Kang9dd63e12012-07-24 00:25:51 +09002665 }
2666 else {
Sungjoong Kangb5237e62012-07-27 07:39:05 -07002667 ALOGE("ERR(%s):m_exynosVideoCSC == NULL", __FUNCTION__);
Sungjoong Kang9dd63e12012-07-24 00:25:51 +09002668 }
Sungjoong Kangb5237e62012-07-27 07:39:05 -07002669
Sungjoong Kangb5237e62012-07-27 07:39:05 -07002670 res = selfRecordParms->streamOps->enqueue_buffer(selfRecordParms->streamOps,
Sungjoong Kangad378612012-08-17 12:34:33 -07002671 systemTime(),
Sungjoong Kangbe494d12012-08-04 15:36:56 -07002672 &(selfRecordParms->svcBufHandle[selfRecordParms->svcBufIndex]));
Sungjoong Kangb5237e62012-07-27 07:39:05 -07002673 ALOGV("DEBUG(%s): stream(%d) record enqueue_buffer to svc done res(%d)", __FUNCTION__,
2674 selfThread->m_index, res);
2675 if (res == 0) {
Sungjoong Kangbe494d12012-08-04 15:36:56 -07002676 selfRecordParms->svcBufStatus[selfRecordParms->svcBufIndex] = ON_SERVICE;
2677 selfRecordParms->numSvcBufsInHal--;
Sungjoong Kangb5237e62012-07-27 07:39:05 -07002678 }
Sungjoong Kangb5237e62012-07-27 07:39:05 -07002679 }
Sungjoong Kangad378612012-08-17 12:34:33 -07002680 if (m_previewOutput && m_requestManager->GetSkipCnt() <= 0) {
2681
2682 ALOGV("** Display Preview(frameCnt:%d)", m_requestManager->GetFrameIndex());
Sungjoong Kangb5237e62012-07-27 07:39:05 -07002683 res = selfStreamParms->streamOps->enqueue_buffer(selfStreamParms->streamOps,
Sungjoong Kangad378612012-08-17 12:34:33 -07002684 m_requestManager->GetTimestamp(m_requestManager->GetFrameIndex()),
2685 &(selfStreamParms->svcBufHandle[index]));
2686
Sungjoong Kangb5237e62012-07-27 07:39:05 -07002687 ALOGV("DEBUG(%s): stream(%d) enqueue_buffer to svc done res(%d)", __FUNCTION__, selfThread->m_index, res);
2688 }
Sungjoong Kang9dd63e12012-07-24 00:25:51 +09002689 else {
Sungjoong Kangb5237e62012-07-27 07:39:05 -07002690 res = selfStreamParms->streamOps->cancel_buffer(selfStreamParms->streamOps,
2691 &(selfStreamParms->svcBufHandle[index]));
2692 ALOGV("DEBUG(%s): stream(%d) cancel_buffer to svc done res(%d)", __FUNCTION__, selfThread->m_index, res);
Sungjoong Kang9dd63e12012-07-24 00:25:51 +09002693 }
Sungjoong Kang9dd63e12012-07-24 00:25:51 +09002694 if (res == 0) {
Sungjoong Kangb5237e62012-07-27 07:39:05 -07002695 selfStreamParms->svcBufStatus[index] = ON_SERVICE;
Sungjoong Kangbe494d12012-08-04 15:36:56 -07002696 selfStreamParms->numSvcBufsInHal--;
Sungjoong Kang9dd63e12012-07-24 00:25:51 +09002697 }
Sungjoong Kangb5237e62012-07-27 07:39:05 -07002698 else {
2699 selfStreamParms->svcBufStatus[index] = ON_HAL;
2700 }
Sungjoong Kang9dd63e12012-07-24 00:25:51 +09002701 }
Sungjoong Kang37e122d2012-08-08 11:13:48 -07002702 else if (selfStreamParms->streamType == STREAM_TYPE_INDIRECT) {
2703 ExynosRect jpegRect;
2704 bool found = false;
2705 bool ret = false;
2706 int pictureW, pictureH, pictureFramesize = 0;
2707 int pictureFormat;
2708 int cropX, cropY, cropW, cropH = 0;
2709 ExynosBuffer resizeBufInfo;
2710 ExynosRect m_orgPictureRect;
2711
Sungjoong Kangad378612012-08-17 12:34:33 -07002712 ALOGD("DEBUG(%s): stream(%d) type(%d) DQBUF START ",__FUNCTION__,
Sungjoong Kangb5237e62012-07-27 07:39:05 -07002713 selfThread->m_index, selfStreamParms->streamType);
2714 index = cam_int_dqbuf(&(selfStreamParms->node));
Sungjoong Kangad378612012-08-17 12:34:33 -07002715 ALOGD("DEBUG(%s): stream(%d) type(%d) DQBUF done index(%d)",__FUNCTION__,
Sungjoong Kangb5237e62012-07-27 07:39:05 -07002716 selfThread->m_index, selfStreamParms->streamType, index);
Sungjoong Kang13d8c7b2012-07-14 10:20:39 +09002717
Sungjoong Kangb5237e62012-07-27 07:39:05 -07002718 m_jpegEncodingFrameCnt = m_ispProcessingFrameCnt;
Sungjoong Kang13d8c7b2012-07-14 10:20:39 +09002719
Sungjoong Kang37e122d2012-08-08 11:13:48 -07002720 for (int i = 0; i < selfStreamParms->numSvcBuffers ; i++) {
2721 if (selfStreamParms->svcBufStatus[selfStreamParms->svcBufIndex] == ON_HAL) {
2722 found = true;
2723 break;
2724 }
2725 selfStreamParms->svcBufIndex++;
2726 if (selfStreamParms->svcBufIndex >= selfStreamParms->numSvcBuffers)
2727 selfStreamParms->svcBufIndex = 0;
2728 }
2729 if (!found) {
2730 ALOGE("ERR(%s): NO free SVC buffer for JPEG", __FUNCTION__);
2731 break;
2732 }
Jiyoung Shinc15a6b02012-06-05 01:08:14 -07002733
Sungjoong Kangb5237e62012-07-27 07:39:05 -07002734 m_orgPictureRect.w = selfStreamParms->outputWidth;
2735 m_orgPictureRect.h = selfStreamParms->outputHeight;
Jiyoung Shinc15a6b02012-06-05 01:08:14 -07002736
Sungjoong Kangb5237e62012-07-27 07:39:05 -07002737 ExynosBuffer* m_pictureBuf = &(m_camera_info.capture.buffer[index]);
Jiyoung Shinc15a6b02012-06-05 01:08:14 -07002738
Sungjoong Kangdaa1fcd2012-08-08 11:49:43 -07002739 pictureW = selfStreamParms->nodeWidth;
2740 pictureH = selfStreamParms->nodeHeight;
Sungjoong Kangb5237e62012-07-27 07:39:05 -07002741 pictureFormat = V4L2_PIX_FMT_YUYV;
2742 pictureFramesize = FRAME_SIZE(V4L2_PIX_2_HAL_PIXEL_FORMAT(pictureFormat), pictureW, pictureH);
Jiyoung Shinc15a6b02012-06-05 01:08:14 -07002743
Sungjoong Kangb5237e62012-07-27 07:39:05 -07002744 if (m_exynosPictureCSC) {
2745 m_getRatioSize(pictureW, pictureH,
Sungjoong Kang13d8c7b2012-07-14 10:20:39 +09002746 m_orgPictureRect.w, m_orgPictureRect.h,
Sungjoong Kangb5237e62012-07-27 07:39:05 -07002747 &cropX, &cropY,
2748 &cropW, &cropH,
Sungjoong Kangad378612012-08-17 12:34:33 -07002749 0);
Sungjoong Kang13d8c7b2012-07-14 10:20:39 +09002750
Sungjoong Kangb5237e62012-07-27 07:39:05 -07002751 ALOGV("DEBUG(%s):cropX = %d, cropY = %d, cropW = %d, cropH = %d",
2752 __FUNCTION__, cropX, cropY, cropW, cropH);
Sungjoong Kang13d8c7b2012-07-14 10:20:39 +09002753
Sungjoong Kangb5237e62012-07-27 07:39:05 -07002754 csc_set_src_format(m_exynosPictureCSC,
2755 ALIGN(pictureW, 16), ALIGN(pictureH, 16),
2756 cropX, cropY, cropW, cropH,
2757 V4L2_PIX_2_HAL_PIXEL_FORMAT(pictureFormat),
2758 0);
Sungjoong Kang13d8c7b2012-07-14 10:20:39 +09002759
Sungjoong Kangb5237e62012-07-27 07:39:05 -07002760 csc_set_dst_format(m_exynosPictureCSC,
2761 m_orgPictureRect.w, m_orgPictureRect.h,
2762 0, 0, m_orgPictureRect.w, m_orgPictureRect.h,
2763 V4L2_PIX_2_HAL_PIXEL_FORMAT(V4L2_PIX_FMT_NV16),
2764 0);
2765 csc_set_src_buffer(m_exynosPictureCSC,
2766 (void **)&m_pictureBuf->fd.fd);
Jiyoung Shinc15a6b02012-06-05 01:08:14 -07002767
Sungjoong Kangb5237e62012-07-27 07:39:05 -07002768 csc_set_dst_buffer(m_exynosPictureCSC,
2769 (void **)&m_resizeBuf.fd.fd);
Sungjoong Kang37e122d2012-08-08 11:13:48 -07002770 for (int i = 0 ; i < 3 ; i++)
Sungjoong Kangb5237e62012-07-27 07:39:05 -07002771 ALOGV("DEBUG(%s): m_resizeBuf.virt.extP[%d]=%d m_resizeBuf.size.extS[%d]=%d",
Sungjoong Kang13d8c7b2012-07-14 10:20:39 +09002772 __FUNCTION__, i, m_resizeBuf.fd.extFd[i], i, m_resizeBuf.size.extS[i]);
Sungjoong Kang13d8c7b2012-07-14 10:20:39 +09002773
Sungjoong Kangb5237e62012-07-27 07:39:05 -07002774 if (csc_convert(m_exynosPictureCSC) != 0)
2775 ALOGE("ERR(%s): csc_convert() fail", __FUNCTION__);
Sungjoong Kang13d8c7b2012-07-14 10:20:39 +09002776
2777
Sungjoong Kang13d8c7b2012-07-14 10:20:39 +09002778 }
2779 else {
Sungjoong Kangb5237e62012-07-27 07:39:05 -07002780 ALOGE("ERR(%s): m_exynosPictureCSC == NULL", __FUNCTION__);
Sungjoong Kang13d8c7b2012-07-14 10:20:39 +09002781 }
Sungjoong Kang13d8c7b2012-07-14 10:20:39 +09002782
Sungjoong Kangb5237e62012-07-27 07:39:05 -07002783 resizeBufInfo = m_resizeBuf;
2784
2785 m_getAlignedYUVSize(V4L2_PIX_FMT_NV16, m_orgPictureRect.w, m_orgPictureRect.h, &m_resizeBuf);
2786
2787 for (int i = 1; i < 3; i++) {
2788 if (m_resizeBuf.size.extS[i] != 0)
2789 m_resizeBuf.fd.extFd[i] = m_resizeBuf.fd.extFd[i-1] + m_resizeBuf.size.extS[i-1];
2790
2791 ALOGV("(%s): m_resizeBuf.size.extS[%d] = %d", __FUNCTION__, i, m_resizeBuf.size.extS[i]);
2792 }
2793
Sungjoong Kangb5237e62012-07-27 07:39:05 -07002794 jpegRect.w = m_orgPictureRect.w;
2795 jpegRect.h = m_orgPictureRect.h;
2796 jpegRect.colorFormat = V4L2_PIX_FMT_NV16;
2797
Sungjoong Kang37e122d2012-08-08 11:13:48 -07002798 if (yuv2Jpeg(&m_resizeBuf, &selfStreamParms->svcBuffers[selfStreamParms->svcBufIndex], &jpegRect) == false)
Sungjoong Kangb5237e62012-07-27 07:39:05 -07002799 ALOGE("ERR(%s):yuv2Jpeg() fail", __FUNCTION__);
2800 cam_int_qbuf(&(selfStreamParms->node), index);
2801 ALOGV("DEBUG(%s): stream(%d) type(%d) QBUF DONE ",__FUNCTION__,
2802 selfThread->m_index, selfStreamParms->streamType);
2803
2804 m_resizeBuf = resizeBufInfo;
2805
Sungjoong Kang37e122d2012-08-08 11:13:48 -07002806 res = selfStreamParms->streamOps->enqueue_buffer(selfStreamParms->streamOps,
2807 m_requestManager->GetTimestamp(m_jpegEncodingFrameCnt), &(selfStreamParms->svcBufHandle[selfStreamParms->svcBufIndex]));
2808
2809 ALOGV("DEBUG(%s): stream(%d) enqueue_buffer index(%d) to svc done res(%d)",
2810 __FUNCTION__, selfThread->m_index, selfStreamParms->svcBufIndex, res);
2811 if (res == 0) {
2812 selfStreamParms->svcBufStatus[selfStreamParms->svcBufIndex] = ON_SERVICE;
2813 selfStreamParms->numSvcBufsInHal--;
Sungjoong Kangb5237e62012-07-27 07:39:05 -07002814 }
2815 else {
Sungjoong Kang37e122d2012-08-08 11:13:48 -07002816 selfStreamParms->svcBufStatus[selfStreamParms->svcBufIndex] = ON_HAL;
Sungjoong Kangb5237e62012-07-27 07:39:05 -07002817 }
Sungjoong Kangb5237e62012-07-27 07:39:05 -07002818 }
Sungjoong Kang13d8c7b2012-07-14 10:20:39 +09002819 }
Sungjoong Kangb5237e62012-07-27 07:39:05 -07002820 while (0);
2821
Sungjoong Kang37e122d2012-08-08 11:13:48 -07002822 if (selfStreamParms->streamType == STREAM_TYPE_DIRECT && m_recordOutput && m_recordingEnabled) {
Sungjoong Kang9dd63e12012-07-24 00:25:51 +09002823 do {
Sungjoong Kangbe494d12012-08-04 15:36:56 -07002824 ALOGV("DEBUG(%s): record currentBuf#(%d)", __FUNCTION__ , selfRecordParms->numSvcBufsInHal);
2825 if (selfRecordParms->numSvcBufsInHal >= 1)
Sungjoong Kang9dd63e12012-07-24 00:25:51 +09002826 {
2827 ALOGV("DEBUG(%s): breaking", __FUNCTION__);
2828 break;
2829 }
2830 res = selfRecordParms->streamOps->dequeue_buffer(selfRecordParms->streamOps, &buf);
2831 if (res != NO_ERROR || buf == NULL) {
2832 ALOGV("DEBUG(%s): record stream(%d) dequeue_buffer fail res(%d)",__FUNCTION__ , selfThread->m_index, res);
2833 break;
2834 }
Sungjoong Kangbe494d12012-08-04 15:36:56 -07002835 selfRecordParms->numSvcBufsInHal ++;
Sungjoong Kang9dd63e12012-07-24 00:25:51 +09002836 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 -07002837 selfRecordParms->numSvcBufsInHal, ((native_handle_t*)(*buf))->version, ((native_handle_t*)(*buf))->numFds, ((native_handle_t*)(*buf))->numInts);
Sungjoong Kangad378612012-08-17 12:34:33 -07002838
Sungjoong Kang9dd63e12012-07-24 00:25:51 +09002839 const private_handle_t *priv_handle = reinterpret_cast<const private_handle_t *>(*buf);
Sungjoong Kang9dd63e12012-07-24 00:25:51 +09002840 bool found = false;
2841 int checkingIndex = 0;
2842 for (checkingIndex = 0; checkingIndex < selfRecordParms->numSvcBuffers ; checkingIndex++) {
2843 if (priv_handle->fd == selfRecordParms->svcBuffers[checkingIndex].fd.extFd[0] ) {
2844 found = true;
2845 break;
2846 }
2847 }
2848 ALOGV("DEBUG(%s): recording dequeueed_buffer found index(%d)", __FUNCTION__, found);
Sungjoong Kangad378612012-08-17 12:34:33 -07002849
2850 if (!found) {
2851 break;
2852 }
2853
Sungjoong Kang9dd63e12012-07-24 00:25:51 +09002854 index = checkingIndex;
2855 if (selfRecordParms->svcBufStatus[index] == ON_SERVICE) {
2856 selfRecordParms->svcBufStatus[index] = ON_HAL;
2857 }
2858 else {
2859 ALOGV("DEBUG(%s): record bufstatus abnormal [%d] status = %d", __FUNCTION__,
Sungjoong Kangad378612012-08-17 12:34:33 -07002860 index, selfRecordParms->svcBufStatus[index]);
Sungjoong Kang9dd63e12012-07-24 00:25:51 +09002861 }
2862 } while (0);
2863 }
Sungjoong Kang37e122d2012-08-08 11:13:48 -07002864 if (selfStreamParms->streamType == STREAM_TYPE_DIRECT) {
Sungjoong Kangbe494d12012-08-04 15:36:56 -07002865 while (selfStreamParms->numSvcBufsInHal < selfStreamParms->numOwnSvcBuffers) {
2866 res = selfStreamParms->streamOps->dequeue_buffer(selfStreamParms->streamOps, &buf);
2867 if (res != NO_ERROR || buf == NULL) {
2868 ALOGV("DEBUG(%s): stream(%d) dequeue_buffer fail res(%d)",__FUNCTION__ , selfThread->m_index, res);
Sungjoong Kang9dd63e12012-07-24 00:25:51 +09002869 break;
2870 }
Sungjoong Kangbe494d12012-08-04 15:36:56 -07002871 selfStreamParms->numSvcBufsInHal++;
2872 ALOGV("DEBUG(%s): stream(%d) got buf(%x) numInHal(%d) version(%d), numFds(%d), numInts(%d)", __FUNCTION__,
2873 selfThread->m_index, (uint32_t)(*buf), selfStreamParms->numSvcBufsInHal,
2874 ((native_handle_t*)(*buf))->version, ((native_handle_t*)(*buf))->numFds, ((native_handle_t*)(*buf))->numInts);
2875 const private_handle_t *priv_handle = reinterpret_cast<const private_handle_t *>(*buf);
Sungjoong Kang13d8c7b2012-07-14 10:20:39 +09002876
Sungjoong Kangbe494d12012-08-04 15:36:56 -07002877 bool found = false;
2878 int checkingIndex = 0;
2879 for (checkingIndex = 0; checkingIndex < selfStreamParms->numSvcBuffers ; checkingIndex++) {
2880 if (priv_handle->fd == selfStreamParms->svcBuffers[checkingIndex].fd.extFd[0] ) {
2881 found = true;
2882 break;
2883 }
Sungjoong Kang9dd63e12012-07-24 00:25:51 +09002884 }
Sungjoong Kangbe494d12012-08-04 15:36:56 -07002885 ALOGV("DEBUG(%s): post_dequeue_buffer found(%d)", __FUNCTION__, found);
2886 if (!found) break;
2887 ALOGV("DEBUG(%s): preparing to qbuf [%d]", __FUNCTION__, checkingIndex);
2888 index = checkingIndex;
2889 if (index < selfStreamParms->numHwBuffers) {
2890 uint32_t plane_index = 0;
2891 ExynosBuffer* currentBuf = &(selfStreamParms->svcBuffers[index]);
2892 struct v4l2_buffer v4l2_buf;
2893 struct v4l2_plane planes[VIDEO_MAX_PLANES];
Sungjoong Kang13d8c7b2012-07-14 10:20:39 +09002894
Sungjoong Kangbe494d12012-08-04 15:36:56 -07002895 v4l2_buf.m.planes = planes;
2896 v4l2_buf.type = currentNode->type;
2897 v4l2_buf.memory = currentNode->memory;
2898 v4l2_buf.index = index;
2899 v4l2_buf.length = currentNode->planes;
2900
2901 v4l2_buf.m.planes[0].m.fd = priv_handle->fd;
Sungjoong Kangad378612012-08-17 12:34:33 -07002902 v4l2_buf.m.planes[2].m.fd = priv_handle->fd1;
2903 v4l2_buf.m.planes[1].m.fd = priv_handle->fd2;
Sungjoong Kangbe494d12012-08-04 15:36:56 -07002904 for (plane_index=0 ; plane_index < v4l2_buf.length ; plane_index++) {
2905 v4l2_buf.m.planes[plane_index].length = currentBuf->size.extS[plane_index];
2906 ALOGV("DEBUG(%s): plane(%d): fd(%d) length(%d)",
2907 __FUNCTION__, plane_index, v4l2_buf.m.planes[plane_index].m.fd,
2908 v4l2_buf.m.planes[plane_index].length);
2909 }
Sungjoong Kang9dd63e12012-07-24 00:25:51 +09002910 if (exynos_v4l2_qbuf(currentNode->fd, &v4l2_buf) < 0) {
2911 ALOGE("ERR(%s): stream id(%d) exynos_v4l2_qbuf() fail",
2912 __FUNCTION__, selfThread->m_index);
2913 return;
Sungjoong Kang13d8c7b2012-07-14 10:20:39 +09002914 }
Sungjoong Kang9dd63e12012-07-24 00:25:51 +09002915 selfStreamParms->svcBufStatus[index] = ON_DRIVER;
2916 ALOGV("DEBUG(%s): stream id(%d) type0 QBUF done index(%d)",
2917 __FUNCTION__, selfThread->m_index, index);
2918 }
Sungjoong Kang13d8c7b2012-07-14 10:20:39 +09002919 }
2920 }
Sungjoong Kang37e122d2012-08-08 11:13:48 -07002921 else if (selfStreamParms->streamType == STREAM_TYPE_INDIRECT) {
Sungjoong Kangbe494d12012-08-04 15:36:56 -07002922 while (selfStreamParms->numSvcBufsInHal < selfStreamParms->numOwnSvcBuffers) {
2923 res = selfStreamParms->streamOps->dequeue_buffer(selfStreamParms->streamOps, &buf);
2924 if (res != NO_ERROR || buf == NULL) {
2925 ALOGV("DEBUG(%s): stream(%d) dequeue_buffer fail res(%d)",__FUNCTION__ , selfThread->m_index, res);
2926 break;
2927 }
2928
2929 ALOGV("DEBUG(%s): stream(%d) got buf(%x) numInHal(%d) version(%d), numFds(%d), numInts(%d)", __FUNCTION__,
2930 selfThread->m_index, (uint32_t)(*buf), selfStreamParms->numSvcBufsInHal,
2931 ((native_handle_t*)(*buf))->version, ((native_handle_t*)(*buf))->numFds, ((native_handle_t*)(*buf))->numInts);
2932
2933 const private_handle_t *priv_handle = reinterpret_cast<const private_handle_t *>(*buf);
2934
2935 bool found = false;
2936 int checkingIndex = 0;
2937 for (checkingIndex = 0; checkingIndex < selfStreamParms->numSvcBuffers ; checkingIndex++) {
2938 if (priv_handle->fd == selfStreamParms->svcBuffers[checkingIndex].fd.extFd[0] ) {
2939 found = true;
2940 break;
2941 }
2942 }
2943 if (!found) break;
2944 selfStreamParms->svcBufStatus[checkingIndex] = ON_HAL;
2945 selfStreamParms->numSvcBufsInHal++;
2946 }
2947
2948 }
Sungjoong Kang13d8c7b2012-07-14 10:20:39 +09002949 ALOGV("DEBUG(%s): stream(%d) processing SIGNAL_STREAM_DATA_COMING DONE",
2950 __FUNCTION__,selfThread->m_index);
Jiyoung Shinc15a6b02012-06-05 01:08:14 -07002951 }
Jiyoung Shinc15a6b02012-06-05 01:08:14 -07002952 return;
2953}
2954
Sungjoong Kang13d8c7b2012-07-14 10:20:39 +09002955bool ExynosCameraHWInterface2::yuv2Jpeg(ExynosBuffer *yuvBuf,
2956 ExynosBuffer *jpegBuf,
2957 ExynosRect *rect)
Jiyoung Shinc15a6b02012-06-05 01:08:14 -07002958{
Sungjoong Kang13d8c7b2012-07-14 10:20:39 +09002959 unsigned char *addr;
2960
2961 ExynosJpegEncoderForCamera jpegEnc;
2962 bool ret = false;
2963 int res = 0;
2964
2965 unsigned int *yuvSize = yuvBuf->size.extS;
2966
2967 if (jpegEnc.create()) {
Sungjoong Kang9dd63e12012-07-24 00:25:51 +09002968 ALOGE("ERR(%s):jpegEnc.create() fail", __FUNCTION__);
Sungjoong Kang13d8c7b2012-07-14 10:20:39 +09002969 goto jpeg_encode_done;
2970 }
2971
2972 if (jpegEnc.setQuality(100)) {
Sungjoong Kang9dd63e12012-07-24 00:25:51 +09002973 ALOGE("ERR(%s):jpegEnc.setQuality() fail", __FUNCTION__);
Sungjoong Kang13d8c7b2012-07-14 10:20:39 +09002974 goto jpeg_encode_done;
2975 }
2976
2977 if (jpegEnc.setSize(rect->w, rect->h)) {
Sungjoong Kang9dd63e12012-07-24 00:25:51 +09002978 ALOGE("ERR(%s):jpegEnc.setSize() fail", __FUNCTION__);
Sungjoong Kang13d8c7b2012-07-14 10:20:39 +09002979 goto jpeg_encode_done;
2980 }
2981 ALOGV("%s : width = %d , height = %d\n", __FUNCTION__, rect->w, rect->h);
2982
2983 if (jpegEnc.setColorFormat(rect->colorFormat)) {
Sungjoong Kang9dd63e12012-07-24 00:25:51 +09002984 ALOGE("ERR(%s):jpegEnc.setColorFormat() fail", __FUNCTION__);
Sungjoong Kang13d8c7b2012-07-14 10:20:39 +09002985 goto jpeg_encode_done;
2986 }
Sungjoong Kang13d8c7b2012-07-14 10:20:39 +09002987
2988 if (jpegEnc.setJpegFormat(V4L2_PIX_FMT_JPEG_422)) {
Sungjoong Kang9dd63e12012-07-24 00:25:51 +09002989 ALOGE("ERR(%s):jpegEnc.setJpegFormat() fail", __FUNCTION__);
Sungjoong Kang13d8c7b2012-07-14 10:20:39 +09002990 goto jpeg_encode_done;
2991 }
Sungjoong Kang13d8c7b2012-07-14 10:20:39 +09002992
Sungjoong Kangad378612012-08-17 12:34:33 -07002993 mExifInfo.enableThumb = false;
Sungjoong Kang13d8c7b2012-07-14 10:20:39 +09002994
Sungjoong Kang9dd63e12012-07-24 00:25:51 +09002995 ALOGV("DEBUG(%s):calling jpegEnc.setInBuf() yuvSize(%d)", __FUNCTION__, *yuvSize);
Sungjoong Kang13d8c7b2012-07-14 10:20:39 +09002996 if (jpegEnc.setInBuf((int *)&(yuvBuf->fd.fd), (int *)yuvSize)) {
Sungjoong Kang9dd63e12012-07-24 00:25:51 +09002997 ALOGE("ERR(%s):jpegEnc.setInBuf() fail", __FUNCTION__);
Sungjoong Kang13d8c7b2012-07-14 10:20:39 +09002998 goto jpeg_encode_done;
2999 }
3000
3001 if (jpegEnc.setOutBuf(jpegBuf->fd.fd, jpegBuf->size.extS[0] + jpegBuf->size.extS[1] + jpegBuf->size.extS[2])) {
Sungjoong Kang9dd63e12012-07-24 00:25:51 +09003002 ALOGE("ERR(%s):jpegEnc.setOutBuf() fail", __FUNCTION__);
Sungjoong Kang13d8c7b2012-07-14 10:20:39 +09003003 goto jpeg_encode_done;
3004 }
Sungjoong Kang37e122d2012-08-08 11:13:48 -07003005 memset(jpegBuf->virt.p, 0 ,jpegBuf->size.extS[0] + jpegBuf->size.extS[1] + jpegBuf->size.extS[2]);
Sungjoong Kang13d8c7b2012-07-14 10:20:39 +09003006
3007 if (jpegEnc.updateConfig()) {
Sungjoong Kang9dd63e12012-07-24 00:25:51 +09003008 ALOGE("ERR(%s):jpegEnc.updateConfig() fail", __FUNCTION__);
Sungjoong Kang13d8c7b2012-07-14 10:20:39 +09003009 goto jpeg_encode_done;
3010 }
3011
3012 if (res = jpegEnc.encode((int *)&jpegBuf->size.s, NULL)) {
Sungjoong Kang9dd63e12012-07-24 00:25:51 +09003013 ALOGE("ERR(%s):jpegEnc.encode() fail ret(%d)", __FUNCTION__, res);
Sungjoong Kang13d8c7b2012-07-14 10:20:39 +09003014 goto jpeg_encode_done;
3015 }
3016
3017 ret = true;
3018
3019jpeg_encode_done:
3020
3021 if (jpegEnc.flagCreate() == true)
3022 jpegEnc.destroy();
3023
3024 return ret;
Jiyoung Shinc15a6b02012-06-05 01:08:14 -07003025}
3026
Sungjoong Kang13d8c7b2012-07-14 10:20:39 +09003027
Sungjoong Kang0f26b202012-08-17 15:43:12 -07003028void ExynosCameraHWInterface2::OnAfTrigger(int id)
3029{
3030 switch (m_afMode) {
3031 case AA_AFMODE_AUTO:
3032 case AA_AFMODE_MACRO:
3033 OnAfTriggerAutoMacro(id);
3034 break;
3035 case AA_AFMODE_CONTINUOUS_VIDEO:
3036 OnAfTriggerCAFVideo(id);
3037 break;
3038 case AA_AFMODE_CONTINUOUS_PICTURE:
3039 OnAfTriggerCAFPicture(id);
3040 break;
3041 case AA_AFMODE_OFF:
3042 default:
3043 break;
3044 }
3045}
3046
3047void ExynosCameraHWInterface2::OnAfTriggerAutoMacro(int id)
3048{
3049 int nextState = NO_TRANSITION;
3050 m_afTriggerId = id;
3051
3052 switch (m_afState) {
3053 case HAL_AFSTATE_INACTIVE:
3054 nextState = HAL_AFSTATE_NEEDS_COMMAND;
3055 m_IsAfTriggerRequired = true;
3056 break;
3057 case HAL_AFSTATE_NEEDS_COMMAND:
3058 nextState = NO_TRANSITION;
3059 break;
3060 case HAL_AFSTATE_STARTED:
3061 nextState = NO_TRANSITION;
3062 break;
3063 case HAL_AFSTATE_SCANNING:
3064 nextState = NO_TRANSITION;
3065 break;
3066 case HAL_AFSTATE_LOCKED:
3067 nextState = HAL_AFSTATE_NEEDS_COMMAND;
3068 m_IsAfTriggerRequired = true;
3069 break;
3070 case HAL_AFSTATE_FAILED:
3071 nextState = HAL_AFSTATE_NEEDS_COMMAND;
3072 m_IsAfTriggerRequired = true;
3073 break;
3074 default:
3075 break;
3076 }
3077 ALOGV("(%s): State (%d) -> (%d)", __FUNCTION__, m_afState, nextState);
3078 if (nextState != NO_TRANSITION)
3079 m_afState = nextState;
3080}
3081
3082void ExynosCameraHWInterface2::OnAfTriggerCAFPicture(int id)
3083{
3084 int nextState = NO_TRANSITION;
3085 m_afTriggerId = id;
3086
3087 switch (m_afState) {
3088 case HAL_AFSTATE_INACTIVE:
3089 nextState = HAL_AFSTATE_FAILED;
3090 SetAfStateForService(ANDROID_CONTROL_AF_STATE_NOT_FOCUSED_LOCKED);
3091 break;
3092 case HAL_AFSTATE_NEEDS_COMMAND:
3093 // not used
3094 break;
3095 case HAL_AFSTATE_STARTED:
3096 nextState = HAL_AFSTATE_NEEDS_DETERMINATION;
3097 break;
3098 case HAL_AFSTATE_SCANNING:
3099 nextState = HAL_AFSTATE_NEEDS_DETERMINATION;
3100 break;
3101 case HAL_AFSTATE_NEEDS_DETERMINATION:
3102 nextState = NO_TRANSITION;
3103 break;
3104 case HAL_AFSTATE_PASSIVE_FOCUSED:
3105 m_IsAfLockRequired = true;
3106 SetAfStateForService(ANDROID_CONTROL_AF_STATE_FOCUSED_LOCKED);
3107 nextState = HAL_AFSTATE_LOCKED;
3108 break;
3109 case HAL_AFSTATE_LOCKED:
3110 nextState = NO_TRANSITION;
3111 break;
3112 case HAL_AFSTATE_FAILED:
3113 nextState = NO_TRANSITION;
3114 break;
3115 default:
3116 break;
3117 }
3118 ALOGV("(%s): State (%d) -> (%d)", __FUNCTION__, m_afState, nextState);
3119 if (nextState != NO_TRANSITION)
3120 m_afState = nextState;
3121}
3122
3123
3124void ExynosCameraHWInterface2::OnAfTriggerCAFVideo(int id)
3125{
3126 int nextState = NO_TRANSITION;
3127 m_afTriggerId = id;
3128
3129 switch (m_afState) {
3130 case HAL_AFSTATE_INACTIVE:
3131 nextState = HAL_AFSTATE_FAILED;
3132 SetAfStateForService(ANDROID_CONTROL_AF_STATE_NOT_FOCUSED_LOCKED);
3133 break;
3134 case HAL_AFSTATE_NEEDS_COMMAND:
3135 // not used
3136 break;
3137 case HAL_AFSTATE_STARTED:
3138 m_IsAfLockRequired = true;
3139 nextState = HAL_AFSTATE_FAILED;
3140 SetAfStateForService(ANDROID_CONTROL_AF_STATE_NOT_FOCUSED_LOCKED);
3141 break;
3142 case HAL_AFSTATE_SCANNING:
3143 m_IsAfLockRequired = true;
3144 nextState = HAL_AFSTATE_FAILED;
3145 SetAfStateForService(ANDROID_CONTROL_AF_STATE_NOT_FOCUSED_LOCKED);
3146 break;
3147 case HAL_AFSTATE_NEEDS_DETERMINATION:
3148 // not used
3149 break;
3150 case HAL_AFSTATE_PASSIVE_FOCUSED:
3151 m_IsAfLockRequired = true;
3152 SetAfStateForService(ANDROID_CONTROL_AF_STATE_FOCUSED_LOCKED);
3153 nextState = HAL_AFSTATE_LOCKED;
3154 break;
3155 case HAL_AFSTATE_LOCKED:
3156 nextState = NO_TRANSITION;
3157 break;
3158 case HAL_AFSTATE_FAILED:
3159 nextState = NO_TRANSITION;
3160 break;
3161 default:
3162 break;
3163 }
3164 ALOGV("(%s): State (%d) -> (%d)", __FUNCTION__, m_afState, nextState);
3165 if (nextState != NO_TRANSITION)
3166 m_afState = nextState;
3167}
3168
3169void ExynosCameraHWInterface2::OnAfNotification(enum aa_afstate noti)
3170{
3171 switch (m_afMode) {
3172 case AA_AFMODE_AUTO:
3173 case AA_AFMODE_MACRO:
3174 OnAfNotificationAutoMacro(noti);
3175 break;
3176 case AA_AFMODE_CONTINUOUS_VIDEO:
3177 OnAfNotificationCAFVideo(noti);
3178 break;
3179 case AA_AFMODE_CONTINUOUS_PICTURE:
3180 OnAfNotificationCAFPicture(noti);
3181 break;
3182 case AA_AFMODE_OFF:
3183 default:
3184 break;
3185 }
3186}
3187
3188void ExynosCameraHWInterface2::OnAfNotificationAutoMacro(enum aa_afstate noti)
3189{
3190 int nextState = NO_TRANSITION;
3191 bool bWrongTransition = false;
3192
3193 if (m_afState == HAL_AFSTATE_INACTIVE || m_afState == HAL_AFSTATE_NEEDS_COMMAND) {
3194 switch (noti) {
3195 case AA_AFSTATE_INACTIVE:
3196 case AA_AFSTATE_ACTIVE_SCAN:
3197 case AA_AFSTATE_AF_ACQUIRED_FOCUS:
3198 case AA_AFSTATE_AF_FAILED_FOCUS:
3199 default:
3200 nextState = NO_TRANSITION;
3201 break;
3202 }
3203 }
3204 else if (m_afState == HAL_AFSTATE_STARTED) {
3205 switch (noti) {
3206 case AA_AFSTATE_INACTIVE:
3207 nextState = NO_TRANSITION;
3208 break;
3209 case AA_AFSTATE_ACTIVE_SCAN:
3210 nextState = HAL_AFSTATE_SCANNING;
3211 SetAfStateForService(ANDROID_CONTROL_AF_STATE_ACTIVE_SCAN);
3212 break;
3213 case AA_AFSTATE_AF_ACQUIRED_FOCUS:
3214 nextState = NO_TRANSITION;
3215 break;
3216 case AA_AFSTATE_AF_FAILED_FOCUS:
3217 nextState = NO_TRANSITION;
3218 break;
3219 default:
3220 bWrongTransition = true;
3221 break;
3222 }
3223 }
3224 else if (m_afState == HAL_AFSTATE_SCANNING) {
3225 switch (noti) {
3226 case AA_AFSTATE_INACTIVE:
3227 bWrongTransition = true;
3228 break;
3229 case AA_AFSTATE_ACTIVE_SCAN:
3230 nextState = NO_TRANSITION;
3231 break;
3232 case AA_AFSTATE_AF_ACQUIRED_FOCUS:
3233 nextState = HAL_AFSTATE_LOCKED;
3234 SetAfStateForService(ANDROID_CONTROL_AF_STATE_FOCUSED_LOCKED);
3235 break;
3236 case AA_AFSTATE_AF_FAILED_FOCUS:
3237 nextState = HAL_AFSTATE_FAILED;
3238 SetAfStateForService(ANDROID_CONTROL_AF_STATE_NOT_FOCUSED_LOCKED);
3239 break;
3240 default:
3241 bWrongTransition = true;
3242 break;
3243 }
3244 }
3245 else if (m_afState == HAL_AFSTATE_LOCKED) {
3246 switch (noti) {
3247 case AA_AFSTATE_INACTIVE:
3248 case AA_AFSTATE_ACTIVE_SCAN:
3249 bWrongTransition = true;
3250 break;
3251 case AA_AFSTATE_AF_ACQUIRED_FOCUS:
3252 nextState = NO_TRANSITION;
3253 break;
3254 case AA_AFSTATE_AF_FAILED_FOCUS:
3255 default:
3256 bWrongTransition = true;
3257 break;
3258 }
3259 }
3260 else if (m_afState == HAL_AFSTATE_FAILED) {
3261 switch (noti) {
3262 case AA_AFSTATE_INACTIVE:
3263 case AA_AFSTATE_ACTIVE_SCAN:
3264 case AA_AFSTATE_AF_ACQUIRED_FOCUS:
3265 bWrongTransition = true;
3266 break;
3267 case AA_AFSTATE_AF_FAILED_FOCUS:
3268 nextState = NO_TRANSITION;
3269 break;
3270 default:
3271 bWrongTransition = true;
3272 break;
3273 }
3274 }
3275 if (bWrongTransition) {
3276 ALOGV("(%s): Wrong Transition state(%d) noti(%d)", __FUNCTION__, m_afState, noti);
3277 return;
3278 }
3279 ALOGV("(%s): State (%d) -> (%d) by (%d)", __FUNCTION__, m_afState, nextState, noti);
3280 if (nextState != NO_TRANSITION)
3281 m_afState = nextState;
3282}
3283
3284void ExynosCameraHWInterface2::OnAfNotificationCAFPicture(enum aa_afstate noti)
3285{
3286 int nextState = NO_TRANSITION;
3287 bool bWrongTransition = false;
3288
3289 if (m_afState == HAL_AFSTATE_INACTIVE) {
3290 switch (noti) {
3291 case AA_AFSTATE_INACTIVE:
3292 case AA_AFSTATE_ACTIVE_SCAN:
3293 case AA_AFSTATE_AF_ACQUIRED_FOCUS:
3294 case AA_AFSTATE_AF_FAILED_FOCUS:
3295 default:
3296 nextState = NO_TRANSITION;
3297 break;
3298 }
3299 }
3300 else if (m_afState == HAL_AFSTATE_STARTED) {
3301 switch (noti) {
3302 case AA_AFSTATE_INACTIVE:
3303 nextState = NO_TRANSITION;
3304 break;
3305 case AA_AFSTATE_ACTIVE_SCAN:
3306 nextState = HAL_AFSTATE_SCANNING;
3307 SetAfStateForService(ANDROID_CONTROL_AF_STATE_PASSIVE_SCAN);
3308 break;
3309 case AA_AFSTATE_AF_ACQUIRED_FOCUS:
3310 nextState = HAL_AFSTATE_PASSIVE_FOCUSED;
3311 SetAfStateForService(ANDROID_CONTROL_AF_STATE_PASSIVE_FOCUSED);
3312 break;
3313 case AA_AFSTATE_AF_FAILED_FOCUS:
3314 nextState = HAL_AFSTATE_FAILED;
3315 SetAfStateForService(ANDROID_CONTROL_AF_STATE_NOT_FOCUSED_LOCKED);
3316 break;
3317 default:
3318 bWrongTransition = true;
3319 break;
3320 }
3321 }
3322 else if (m_afState == HAL_AFSTATE_SCANNING) {
3323 switch (noti) {
3324 case AA_AFSTATE_INACTIVE:
3325 bWrongTransition = true;
3326 break;
3327 case AA_AFSTATE_ACTIVE_SCAN:
3328 nextState = NO_TRANSITION;
3329 break;
3330 case AA_AFSTATE_AF_ACQUIRED_FOCUS:
3331 nextState = HAL_AFSTATE_PASSIVE_FOCUSED;
3332 SetAfStateForService(ANDROID_CONTROL_AF_STATE_PASSIVE_FOCUSED);
3333 break;
3334 case AA_AFSTATE_AF_FAILED_FOCUS:
3335 nextState = NO_TRANSITION;
3336 break;
3337 default:
3338 bWrongTransition = true;
3339 break;
3340 }
3341 }
3342 else if (m_afState == HAL_AFSTATE_PASSIVE_FOCUSED) {
3343 switch (noti) {
3344 case AA_AFSTATE_INACTIVE:
3345 bWrongTransition = true;
3346 break;
3347 case AA_AFSTATE_ACTIVE_SCAN:
3348 nextState = HAL_AFSTATE_SCANNING;
3349 SetAfStateForService(ANDROID_CONTROL_AF_STATE_PASSIVE_SCAN);
3350 break;
3351 case AA_AFSTATE_AF_ACQUIRED_FOCUS:
3352 nextState = NO_TRANSITION;
3353 break;
3354 case AA_AFSTATE_AF_FAILED_FOCUS:
3355 nextState = HAL_AFSTATE_FAILED;
3356 SetAfStateForService(ANDROID_CONTROL_AF_STATE_NOT_FOCUSED_LOCKED);
3357 break;
3358 default:
3359 bWrongTransition = true;
3360 break;
3361 }
3362 }
3363 else if (m_afState == HAL_AFSTATE_NEEDS_DETERMINATION) {
3364 switch (noti) {
3365 case AA_AFSTATE_INACTIVE:
3366 bWrongTransition = true;
3367 break;
3368 case AA_AFSTATE_ACTIVE_SCAN:
3369 nextState = NO_TRANSITION;
3370 break;
3371 case AA_AFSTATE_AF_ACQUIRED_FOCUS:
3372 m_IsAfLockRequired = true;
3373 nextState = HAL_AFSTATE_LOCKED;
3374 SetAfStateForService(ANDROID_CONTROL_AF_STATE_FOCUSED_LOCKED);
3375 break;
3376 case AA_AFSTATE_AF_FAILED_FOCUS:
3377 m_IsAfLockRequired = true;
3378 nextState = HAL_AFSTATE_FAILED;
3379 SetAfStateForService(ANDROID_CONTROL_AF_STATE_NOT_FOCUSED_LOCKED);
3380 break;
3381 default:
3382 bWrongTransition = true;
3383 break;
3384 }
3385 }
3386 else if (m_afState == HAL_AFSTATE_LOCKED) {
3387 switch (noti) {
3388 case AA_AFSTATE_INACTIVE:
3389 nextState = NO_TRANSITION;
3390 break;
3391 case AA_AFSTATE_ACTIVE_SCAN:
3392 bWrongTransition = true;
3393 break;
3394 case AA_AFSTATE_AF_ACQUIRED_FOCUS:
3395 nextState = NO_TRANSITION;
3396 break;
3397 case AA_AFSTATE_AF_FAILED_FOCUS:
3398 default:
3399 bWrongTransition = true;
3400 break;
3401 }
3402 }
3403 else if (m_afState == HAL_AFSTATE_FAILED) {
3404 switch (noti) {
3405 case AA_AFSTATE_INACTIVE:
3406 case AA_AFSTATE_ACTIVE_SCAN:
3407 case AA_AFSTATE_AF_ACQUIRED_FOCUS:
3408 bWrongTransition = true;
3409 break;
3410 case AA_AFSTATE_AF_FAILED_FOCUS:
3411 nextState = NO_TRANSITION;
3412 break;
3413 default:
3414 bWrongTransition = true;
3415 break;
3416 }
3417 }
3418 if (bWrongTransition) {
3419 ALOGV("(%s): Wrong Transition state(%d) noti(%d)", __FUNCTION__, m_afState, noti);
3420 return;
3421 }
3422 ALOGV("(%s): State (%d) -> (%d) by (%d)", __FUNCTION__, m_afState, nextState, noti);
3423 if (nextState != NO_TRANSITION)
3424 m_afState = nextState;
3425}
3426
3427void ExynosCameraHWInterface2::OnAfNotificationCAFVideo(enum aa_afstate noti)
3428{
3429 int nextState = NO_TRANSITION;
3430 bool bWrongTransition = false;
3431
3432 if (m_afState == HAL_AFSTATE_INACTIVE) {
3433 switch (noti) {
3434 case AA_AFSTATE_INACTIVE:
3435 case AA_AFSTATE_ACTIVE_SCAN:
3436 case AA_AFSTATE_AF_ACQUIRED_FOCUS:
3437 case AA_AFSTATE_AF_FAILED_FOCUS:
3438 default:
3439 nextState = NO_TRANSITION;
3440 break;
3441 }
3442 }
3443 else if (m_afState == HAL_AFSTATE_STARTED) {
3444 switch (noti) {
3445 case AA_AFSTATE_INACTIVE:
3446 nextState = NO_TRANSITION;
3447 break;
3448 case AA_AFSTATE_ACTIVE_SCAN:
3449 nextState = HAL_AFSTATE_SCANNING;
3450 SetAfStateForService(ANDROID_CONTROL_AF_STATE_PASSIVE_SCAN);
3451 break;
3452 case AA_AFSTATE_AF_ACQUIRED_FOCUS:
3453 nextState = HAL_AFSTATE_PASSIVE_FOCUSED;
3454 SetAfStateForService(ANDROID_CONTROL_AF_STATE_PASSIVE_FOCUSED);
3455 break;
3456 case AA_AFSTATE_AF_FAILED_FOCUS:
3457 nextState = HAL_AFSTATE_FAILED;
3458 SetAfStateForService(ANDROID_CONTROL_AF_STATE_NOT_FOCUSED_LOCKED);
3459 break;
3460 default:
3461 bWrongTransition = true;
3462 break;
3463 }
3464 }
3465 else if (m_afState == HAL_AFSTATE_SCANNING) {
3466 switch (noti) {
3467 case AA_AFSTATE_INACTIVE:
3468 bWrongTransition = true;
3469 break;
3470 case AA_AFSTATE_ACTIVE_SCAN:
3471 nextState = NO_TRANSITION;
3472 break;
3473 case AA_AFSTATE_AF_ACQUIRED_FOCUS:
3474 nextState = HAL_AFSTATE_PASSIVE_FOCUSED;
3475 SetAfStateForService(ANDROID_CONTROL_AF_STATE_PASSIVE_FOCUSED);
3476 break;
3477 case AA_AFSTATE_AF_FAILED_FOCUS:
3478 nextState = NO_TRANSITION;
3479 break;
3480 default:
3481 bWrongTransition = true;
3482 break;
3483 }
3484 }
3485 else if (m_afState == HAL_AFSTATE_PASSIVE_FOCUSED) {
3486 switch (noti) {
3487 case AA_AFSTATE_INACTIVE:
3488 bWrongTransition = true;
3489 break;
3490 case AA_AFSTATE_ACTIVE_SCAN:
3491 nextState = HAL_AFSTATE_SCANNING;
3492 SetAfStateForService(ANDROID_CONTROL_AF_STATE_PASSIVE_SCAN);
3493 break;
3494 case AA_AFSTATE_AF_ACQUIRED_FOCUS:
3495 nextState = NO_TRANSITION;
3496 break;
3497 case AA_AFSTATE_AF_FAILED_FOCUS:
3498 nextState = HAL_AFSTATE_FAILED;
3499 SetAfStateForService(ANDROID_CONTROL_AF_STATE_NOT_FOCUSED_LOCKED);
3500 break;
3501 default:
3502 bWrongTransition = true;
3503 break;
3504 }
3505 }
3506 else if (m_afState == HAL_AFSTATE_NEEDS_DETERMINATION) {
3507 switch (noti) {
3508 case AA_AFSTATE_INACTIVE:
3509 bWrongTransition = true;
3510 break;
3511 case AA_AFSTATE_ACTIVE_SCAN:
3512 nextState = NO_TRANSITION;
3513 break;
3514 case AA_AFSTATE_AF_ACQUIRED_FOCUS:
3515 m_IsAfLockRequired = true;
3516 nextState = HAL_AFSTATE_LOCKED;
3517 SetAfStateForService(ANDROID_CONTROL_AF_STATE_FOCUSED_LOCKED);
3518 break;
3519 case AA_AFSTATE_AF_FAILED_FOCUS:
3520 nextState = HAL_AFSTATE_FAILED;
3521 SetAfStateForService(ANDROID_CONTROL_AF_STATE_NOT_FOCUSED_LOCKED);
3522 break;
3523 default:
3524 bWrongTransition = true;
3525 break;
3526 }
3527 }
3528 else if (m_afState == HAL_AFSTATE_LOCKED) {
3529 switch (noti) {
3530 case AA_AFSTATE_INACTIVE:
3531 nextState = NO_TRANSITION;
3532 break;
3533 case AA_AFSTATE_ACTIVE_SCAN:
3534 bWrongTransition = true;
3535 break;
3536 case AA_AFSTATE_AF_ACQUIRED_FOCUS:
3537 nextState = NO_TRANSITION;
3538 break;
3539 case AA_AFSTATE_AF_FAILED_FOCUS:
3540 default:
3541 bWrongTransition = true;
3542 break;
3543 }
3544 }
3545 else if (m_afState == HAL_AFSTATE_FAILED) {
3546 switch (noti) {
3547 case AA_AFSTATE_INACTIVE:
3548 case AA_AFSTATE_ACTIVE_SCAN:
3549 case AA_AFSTATE_AF_ACQUIRED_FOCUS:
3550 bWrongTransition = true;
3551 break;
3552 case AA_AFSTATE_AF_FAILED_FOCUS:
3553 nextState = NO_TRANSITION;
3554 break;
3555 default:
3556 bWrongTransition = true;
3557 break;
3558 }
3559 }
3560 if (bWrongTransition) {
3561 ALOGV("(%s): Wrong Transition state(%d) noti(%d)", __FUNCTION__, m_afState, noti);
3562 return;
3563 }
3564 ALOGV("(%s): State (%d) -> (%d) by (%d)", __FUNCTION__, m_afState, nextState, noti);
3565 if (nextState != NO_TRANSITION)
3566 m_afState = nextState;
3567}
3568
3569void ExynosCameraHWInterface2::OnAfCancel(int id)
3570{
3571 switch (m_afMode) {
3572 case AA_AFMODE_AUTO:
3573 case AA_AFMODE_MACRO:
3574 OnAfCancelAutoMacro(id);
3575 break;
3576 case AA_AFMODE_CONTINUOUS_VIDEO:
3577 OnAfCancelCAFVideo(id);
3578 break;
3579 case AA_AFMODE_CONTINUOUS_PICTURE:
3580 OnAfCancelCAFPicture(id);
3581 break;
3582 case AA_AFMODE_OFF:
3583 default:
3584 break;
3585 }
3586}
3587
3588void ExynosCameraHWInterface2::OnAfCancelAutoMacro(int id)
3589{
3590 int nextState = NO_TRANSITION;
3591 m_afTriggerId = id;
3592
3593 switch (m_afState) {
3594 case HAL_AFSTATE_INACTIVE:
3595 nextState = NO_TRANSITION;
3596 break;
3597 case HAL_AFSTATE_NEEDS_COMMAND:
3598 case HAL_AFSTATE_STARTED:
3599 case HAL_AFSTATE_SCANNING:
3600 case HAL_AFSTATE_LOCKED:
3601 case HAL_AFSTATE_FAILED:
3602 SetAfMode(AA_AFMODE_OFF);
3603 SetAfStateForService(ANDROID_CONTROL_AF_STATE_INACTIVE);
3604 nextState = HAL_AFSTATE_INACTIVE;
3605 break;
3606 default:
3607 break;
3608 }
3609 ALOGV("(%s): State (%d) -> (%d)", __FUNCTION__, m_afState, nextState);
3610 if (nextState != NO_TRANSITION)
3611 m_afState = nextState;
3612}
3613
3614void ExynosCameraHWInterface2::OnAfCancelCAFPicture(int id)
3615{
3616 int nextState = NO_TRANSITION;
3617 m_afTriggerId = id;
3618
3619 switch (m_afState) {
3620 case HAL_AFSTATE_INACTIVE:
3621 nextState = NO_TRANSITION;
3622 break;
3623 case HAL_AFSTATE_NEEDS_COMMAND:
3624 case HAL_AFSTATE_STARTED:
3625 case HAL_AFSTATE_SCANNING:
3626 case HAL_AFSTATE_LOCKED:
3627 case HAL_AFSTATE_FAILED:
3628 case HAL_AFSTATE_NEEDS_DETERMINATION:
3629 case HAL_AFSTATE_PASSIVE_FOCUSED:
3630 SetAfMode(AA_AFMODE_OFF);
3631 SetAfStateForService(ANDROID_CONTROL_AF_STATE_INACTIVE);
3632 SetAfMode(AA_AFMODE_CONTINUOUS_PICTURE);
3633 nextState = HAL_AFSTATE_INACTIVE;
3634 break;
3635 default:
3636 break;
3637 }
3638 ALOGV("(%s): State (%d) -> (%d)", __FUNCTION__, m_afState, nextState);
3639 if (nextState != NO_TRANSITION)
3640 m_afState = nextState;
3641}
3642
3643void ExynosCameraHWInterface2::OnAfCancelCAFVideo(int id)
3644{
3645 int nextState = NO_TRANSITION;
3646 m_afTriggerId = id;
3647
3648 switch (m_afState) {
3649 case HAL_AFSTATE_INACTIVE:
3650 nextState = NO_TRANSITION;
3651 break;
3652 case HAL_AFSTATE_NEEDS_COMMAND:
3653 case HAL_AFSTATE_STARTED:
3654 case HAL_AFSTATE_SCANNING:
3655 case HAL_AFSTATE_LOCKED:
3656 case HAL_AFSTATE_FAILED:
3657 case HAL_AFSTATE_NEEDS_DETERMINATION:
3658 case HAL_AFSTATE_PASSIVE_FOCUSED:
3659 SetAfMode(AA_AFMODE_OFF);
3660 SetAfStateForService(ANDROID_CONTROL_AF_STATE_INACTIVE);
3661 SetAfMode(AA_AFMODE_CONTINUOUS_VIDEO);
3662 nextState = HAL_AFSTATE_INACTIVE;
3663 break;
3664 default:
3665 break;
3666 }
3667 ALOGV("(%s): State (%d) -> (%d)", __FUNCTION__, m_afState, nextState);
3668 if (nextState != NO_TRANSITION)
3669 m_afState = nextState;
3670}
3671
3672void ExynosCameraHWInterface2::SetAfStateForService(int newState)
3673{
3674 m_serviceAfState = newState;
3675 m_notifyCb(CAMERA2_MSG_AUTOFOCUS, newState, m_afTriggerId, 0, m_callbackCookie);
3676}
3677
3678int ExynosCameraHWInterface2::GetAfStateForService()
3679{
3680 return m_serviceAfState;
3681}
3682
3683void ExynosCameraHWInterface2::SetAfMode(enum aa_afmode afMode)
3684{
3685 if (m_afMode != afMode) {
3686 if (m_IsAfModeUpdateRequired) {
3687 m_afMode2 = afMode;
3688 ALOGV("(%s): pending(%d) and new(%d)", __FUNCTION__, m_afMode, afMode);
3689 }
3690 else {
3691 ALOGV("(%s): current(%d) new(%d)", __FUNCTION__, m_afMode, afMode);
3692 m_IsAfModeUpdateRequired = true;
3693 m_afMode = afMode;
3694 }
3695 }
3696}
3697
Sungjoong Kang13d8c7b2012-07-14 10:20:39 +09003698ExynosCameraHWInterface2::MainThread::~MainThread()
Jiyoung Shinc15a6b02012-06-05 01:08:14 -07003699{
Sungjoong Kangad378612012-08-17 12:34:33 -07003700 ALOGV("(%s):", __FUNCTION__);
Sungjoong Kang13d8c7b2012-07-14 10:20:39 +09003701}
3702
3703void ExynosCameraHWInterface2::MainThread::release()
3704{
Sungjoong Kangad378612012-08-17 12:34:33 -07003705 ALOGV("(%s):", __func__);
Sungjoong Kang13d8c7b2012-07-14 10:20:39 +09003706 SetSignal(SIGNAL_THREAD_RELEASE);
Sungjoong Kang13d8c7b2012-07-14 10:20:39 +09003707}
3708
3709ExynosCameraHWInterface2::SensorThread::~SensorThread()
3710{
Sungjoong Kangad378612012-08-17 12:34:33 -07003711 ALOGV("(%s):", __FUNCTION__);
Sungjoong Kang13d8c7b2012-07-14 10:20:39 +09003712}
3713
3714void ExynosCameraHWInterface2::SensorThread::release()
3715{
Sungjoong Kangad378612012-08-17 12:34:33 -07003716 ALOGV("(%s):", __func__);
Sungjoong Kang13d8c7b2012-07-14 10:20:39 +09003717 SetSignal(SIGNAL_THREAD_RELEASE);
Sungjoong Kang13d8c7b2012-07-14 10:20:39 +09003718}
3719
3720ExynosCameraHWInterface2::IspThread::~IspThread()
3721{
Sungjoong Kangad378612012-08-17 12:34:33 -07003722 ALOGV("(%s):", __FUNCTION__);
Sungjoong Kang13d8c7b2012-07-14 10:20:39 +09003723}
3724
3725void ExynosCameraHWInterface2::IspThread::release()
3726{
Sungjoong Kangad378612012-08-17 12:34:33 -07003727 ALOGV("(%s):", __func__);
Sungjoong Kang13d8c7b2012-07-14 10:20:39 +09003728 SetSignal(SIGNAL_THREAD_RELEASE);
Sungjoong Kang13d8c7b2012-07-14 10:20:39 +09003729}
3730
3731ExynosCameraHWInterface2::StreamThread::~StreamThread()
3732{
Sungjoong Kangad378612012-08-17 12:34:33 -07003733 ALOGV("(%s):", __FUNCTION__);
Sungjoong Kang13d8c7b2012-07-14 10:20:39 +09003734}
3735
3736void ExynosCameraHWInterface2::StreamThread::setParameter(stream_parameters_t * new_parameters)
3737{
3738 ALOGV("DEBUG(%s):", __FUNCTION__);
3739
3740 m_tempParameters = new_parameters;
3741
3742 SetSignal(SIGNAL_STREAM_CHANGE_PARAMETER);
3743
3744 // TODO : return synchronously (after setting parameters asynchronously)
Sungjoong Kang9dd63e12012-07-24 00:25:51 +09003745 usleep(2000);
Sungjoong Kang13d8c7b2012-07-14 10:20:39 +09003746}
3747
3748void ExynosCameraHWInterface2::StreamThread::applyChange()
3749{
3750 memcpy(&m_parameters, m_tempParameters, sizeof(stream_parameters_t));
3751
Sungjoong Kang9dd63e12012-07-24 00:25:51 +09003752 ALOGV("DEBUG(%s): Applying Stream paremeters width(%d), height(%d)",
Sungjoong Kang13d8c7b2012-07-14 10:20:39 +09003753 __FUNCTION__, m_parameters.outputWidth, m_parameters.outputHeight);
3754}
3755
3756void ExynosCameraHWInterface2::StreamThread::release()
3757{
Sungjoong Kang9dd63e12012-07-24 00:25:51 +09003758 ALOGV("(%s):", __func__);
Sungjoong Kang13d8c7b2012-07-14 10:20:39 +09003759 SetSignal(SIGNAL_THREAD_RELEASE);
Sungjoong Kang13d8c7b2012-07-14 10:20:39 +09003760}
3761
3762int ExynosCameraHWInterface2::StreamThread::findBufferIndex(void * bufAddr)
3763{
3764 int index;
3765 for (index = 0 ; index < m_parameters.numSvcBuffers ; index++) {
3766 if (m_parameters.svcBuffers[index].virt.extP[0] == bufAddr)
3767 return index;
3768 }
3769 return -1;
Jiyoung Shinc15a6b02012-06-05 01:08:14 -07003770}
3771
Sungjoong Kang9dd63e12012-07-24 00:25:51 +09003772void ExynosCameraHWInterface2::StreamThread::setRecordingParameter(record_parameters_t * recordParm)
3773{
3774 memcpy(&m_recordParameters, recordParm, sizeof(record_parameters_t));
3775}
3776
Jiyoung Shinc15a6b02012-06-05 01:08:14 -07003777int ExynosCameraHWInterface2::createIonClient(ion_client ionClient)
3778{
3779 if (ionClient == 0) {
3780 ionClient = ion_client_create();
3781 if (ionClient < 0) {
Sungjoong Kang13d8c7b2012-07-14 10:20:39 +09003782 ALOGE("[%s]src ion client create failed, value = %d\n", __FUNCTION__, ionClient);
Jiyoung Shinc15a6b02012-06-05 01:08:14 -07003783 return 0;
3784 }
3785 }
3786
3787 return ionClient;
3788}
3789
3790int ExynosCameraHWInterface2::deleteIonClient(ion_client ionClient)
3791{
3792 if (ionClient != 0) {
3793 if (ionClient > 0) {
3794 ion_client_destroy(ionClient);
3795 }
3796 ionClient = 0;
3797 }
3798
3799 return ionClient;
3800}
3801
Sungjoong Kang13d8c7b2012-07-14 10:20:39 +09003802int ExynosCameraHWInterface2::allocCameraMemory(ion_client ionClient, ExynosBuffer *buf, int iMemoryNum)
Jiyoung Shinc15a6b02012-06-05 01:08:14 -07003803{
3804 int ret = 0;
3805 int i = 0;
3806
3807 if (ionClient == 0) {
Sungjoong Kang13d8c7b2012-07-14 10:20:39 +09003808 ALOGE("[%s] ionClient is zero (%d)\n", __FUNCTION__, ionClient);
Jiyoung Shinc15a6b02012-06-05 01:08:14 -07003809 return -1;
3810 }
3811
3812 for (i=0;i<iMemoryNum;i++) {
Sungjoong Kang13d8c7b2012-07-14 10:20:39 +09003813 if (buf->size.extS[i] == 0) {
Jiyoung Shinc15a6b02012-06-05 01:08:14 -07003814 break;
3815 }
3816
Sungjoong Kang13d8c7b2012-07-14 10:20:39 +09003817 buf->fd.extFd[i] = ion_alloc(ionClient, \
3818 buf->size.extS[i], 0, ION_HEAP_EXYNOS_MASK,0);
3819 if ((buf->fd.extFd[i] == -1) ||(buf->fd.extFd[i] == 0)) {
3820 ALOGE("[%s]ion_alloc(%d) failed\n", __FUNCTION__, buf->size.extS[i]);
3821 buf->fd.extFd[i] = -1;
Jiyoung Shinc15a6b02012-06-05 01:08:14 -07003822 freeCameraMemory(buf, iMemoryNum);
3823 return -1;
3824 }
3825
Sungjoong Kang13d8c7b2012-07-14 10:20:39 +09003826 buf->virt.extP[i] = (char *)ion_map(buf->fd.extFd[i], \
3827 buf->size.extS[i], 0);
3828 if ((buf->virt.extP[i] == (char *)MAP_FAILED) || (buf->virt.extP[i] == NULL)) {
3829 ALOGE("[%s]src ion map failed(%d)\n", __FUNCTION__, buf->size.extS[i]);
3830 buf->virt.extP[i] = (char *)MAP_FAILED;
Jiyoung Shinc15a6b02012-06-05 01:08:14 -07003831 freeCameraMemory(buf, iMemoryNum);
3832 return -1;
3833 }
Sungjoong Kang13d8c7b2012-07-14 10:20:39 +09003834 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 -07003835 }
3836
3837 return ret;
3838}
3839
Sungjoong Kang13d8c7b2012-07-14 10:20:39 +09003840void ExynosCameraHWInterface2::freeCameraMemory(ExynosBuffer *buf, int iMemoryNum)
Jiyoung Shinc15a6b02012-06-05 01:08:14 -07003841{
Sungjoong Kang13d8c7b2012-07-14 10:20:39 +09003842
Jiyoung Shinc15a6b02012-06-05 01:08:14 -07003843 int i =0 ;
3844
3845 for (i=0;i<iMemoryNum;i++) {
Sungjoong Kang13d8c7b2012-07-14 10:20:39 +09003846 if (buf->fd.extFd[i] != -1) {
3847 if (buf->virt.extP[i] != (char *)MAP_FAILED) {
3848 ion_unmap(buf->virt.extP[i], buf->size.extS[i]);
Jiyoung Shinc15a6b02012-06-05 01:08:14 -07003849 }
Sungjoong Kang13d8c7b2012-07-14 10:20:39 +09003850 ion_free(buf->fd.extFd[i]);
Jiyoung Shinc15a6b02012-06-05 01:08:14 -07003851 }
Sungjoong Kang13d8c7b2012-07-14 10:20:39 +09003852 buf->fd.extFd[i] = -1;
3853 buf->virt.extP[i] = (char *)MAP_FAILED;
3854 buf->size.extS[i] = 0;
Jiyoung Shinc15a6b02012-06-05 01:08:14 -07003855 }
3856}
3857
Sungjoong Kang13d8c7b2012-07-14 10:20:39 +09003858void ExynosCameraHWInterface2::initCameraMemory(ExynosBuffer *buf, int iMemoryNum)
Jiyoung Shinc15a6b02012-06-05 01:08:14 -07003859{
3860 int i =0 ;
3861 for (i=0;i<iMemoryNum;i++) {
Sungjoong Kang13d8c7b2012-07-14 10:20:39 +09003862 buf->virt.extP[i] = (char *)MAP_FAILED;
3863 buf->fd.extFd[i] = -1;
3864 buf->size.extS[i] = 0;
Jiyoung Shinc15a6b02012-06-05 01:08:14 -07003865 }
3866}
3867
3868
Sungjoong Kang13d8c7b2012-07-14 10:20:39 +09003869
3870
Sungjoong Kang9dd63e12012-07-24 00:25:51 +09003871static camera2_device_t *g_cam2_device = NULL;
Sungjoong Kangb5237e62012-07-27 07:39:05 -07003872static bool g_camera_vaild = false;
Sungjoong Kangdaa1fcd2012-08-08 11:49:43 -07003873ExynosCamera2 * g_camera2[2] = { NULL, NULL };
Jiyoung Shinc15a6b02012-06-05 01:08:14 -07003874
3875static int HAL2_camera_device_close(struct hw_device_t* device)
3876{
Sungjoong Kangad378612012-08-17 12:34:33 -07003877 ALOGV("%s: ENTER", __FUNCTION__);
Jiyoung Shinc15a6b02012-06-05 01:08:14 -07003878 if (device) {
Sungjoong Kang9dd63e12012-07-24 00:25:51 +09003879
Jiyoung Shinc15a6b02012-06-05 01:08:14 -07003880 camera2_device_t *cam_device = (camera2_device_t *)device;
Sungjoong Kangad378612012-08-17 12:34:33 -07003881 ALOGV("cam_device(0x%08x):", (unsigned int)cam_device);
3882 ALOGV("g_cam2_device(0x%08x):", (unsigned int)g_cam2_device);
Jiyoung Shinc15a6b02012-06-05 01:08:14 -07003883 delete static_cast<ExynosCameraHWInterface2 *>(cam_device->priv);
Sungjoong Kangad378612012-08-17 12:34:33 -07003884 g_cam2_device = NULL;
Jiyoung Shinc15a6b02012-06-05 01:08:14 -07003885 free(cam_device);
Sungjoong Kangb5237e62012-07-27 07:39:05 -07003886 g_camera_vaild = false;
Jiyoung Shinc15a6b02012-06-05 01:08:14 -07003887 }
Sungjoong Kangad378612012-08-17 12:34:33 -07003888 ALOGV("%s: EXIT", __FUNCTION__);
Jiyoung Shinc15a6b02012-06-05 01:08:14 -07003889 return 0;
3890}
3891
3892static inline ExynosCameraHWInterface2 *obj(const struct camera2_device *dev)
3893{
3894 return reinterpret_cast<ExynosCameraHWInterface2 *>(dev->priv);
3895}
3896
3897static int HAL2_device_set_request_queue_src_ops(const struct camera2_device *dev,
3898 const camera2_request_queue_src_ops_t *request_src_ops)
3899{
Sungjoong Kang13d8c7b2012-07-14 10:20:39 +09003900 ALOGV("DEBUG(%s):", __FUNCTION__);
Jiyoung Shinc15a6b02012-06-05 01:08:14 -07003901 return obj(dev)->setRequestQueueSrcOps(request_src_ops);
3902}
3903
3904static int HAL2_device_notify_request_queue_not_empty(const struct camera2_device *dev)
3905{
Sungjoong Kang13d8c7b2012-07-14 10:20:39 +09003906 ALOGV("DEBUG(%s):", __FUNCTION__);
Jiyoung Shinc15a6b02012-06-05 01:08:14 -07003907 return obj(dev)->notifyRequestQueueNotEmpty();
3908}
3909
3910static int HAL2_device_set_frame_queue_dst_ops(const struct camera2_device *dev,
3911 const camera2_frame_queue_dst_ops_t *frame_dst_ops)
3912{
Sungjoong Kang13d8c7b2012-07-14 10:20:39 +09003913 ALOGV("DEBUG(%s):", __FUNCTION__);
Jiyoung Shinc15a6b02012-06-05 01:08:14 -07003914 return obj(dev)->setFrameQueueDstOps(frame_dst_ops);
3915}
3916
3917static int HAL2_device_get_in_progress_count(const struct camera2_device *dev)
3918{
Sungjoong Kang13d8c7b2012-07-14 10:20:39 +09003919 ALOGV("DEBUG(%s):", __FUNCTION__);
Jiyoung Shinc15a6b02012-06-05 01:08:14 -07003920 return obj(dev)->getInProgressCount();
3921}
3922
3923static int HAL2_device_flush_captures_in_progress(const struct camera2_device *dev)
3924{
Sungjoong Kang13d8c7b2012-07-14 10:20:39 +09003925 ALOGV("DEBUG(%s):", __FUNCTION__);
Jiyoung Shinc15a6b02012-06-05 01:08:14 -07003926 return obj(dev)->flushCapturesInProgress();
3927}
3928
3929static int HAL2_device_construct_default_request(const struct camera2_device *dev,
3930 int request_template, camera_metadata_t **request)
3931{
Sungjoong Kang13d8c7b2012-07-14 10:20:39 +09003932 ALOGV("DEBUG(%s):", __FUNCTION__);
Jiyoung Shinc15a6b02012-06-05 01:08:14 -07003933 return obj(dev)->constructDefaultRequest(request_template, request);
3934}
3935
3936static int HAL2_device_allocate_stream(
3937 const struct camera2_device *dev,
3938 // inputs
3939 uint32_t width,
3940 uint32_t height,
3941 int format,
3942 const camera2_stream_ops_t *stream_ops,
3943 // outputs
3944 uint32_t *stream_id,
3945 uint32_t *format_actual,
3946 uint32_t *usage,
3947 uint32_t *max_buffers)
3948{
Sungjoong Kang9dd63e12012-07-24 00:25:51 +09003949 ALOGV("(%s): ", __FUNCTION__);
Jiyoung Shinc15a6b02012-06-05 01:08:14 -07003950 return obj(dev)->allocateStream(width, height, format, stream_ops,
3951 stream_id, format_actual, usage, max_buffers);
3952}
3953
3954
3955static int HAL2_device_register_stream_buffers(const struct camera2_device *dev,
3956 uint32_t stream_id,
3957 int num_buffers,
3958 buffer_handle_t *buffers)
3959{
Sungjoong Kang13d8c7b2012-07-14 10:20:39 +09003960 ALOGV("DEBUG(%s):", __FUNCTION__);
Jiyoung Shinc15a6b02012-06-05 01:08:14 -07003961 return obj(dev)->registerStreamBuffers(stream_id, num_buffers, buffers);
3962}
3963
3964static int HAL2_device_release_stream(
3965 const struct camera2_device *dev,
3966 uint32_t stream_id)
3967{
Sungjoong Kangad378612012-08-17 12:34:33 -07003968 ALOGV("DEBUG(%s)(id: %d):", __FUNCTION__, stream_id);
Sungjoong Kangb5237e62012-07-27 07:39:05 -07003969 if (!g_camera_vaild)
3970 return 0;
Jiyoung Shinc15a6b02012-06-05 01:08:14 -07003971 return obj(dev)->releaseStream(stream_id);
3972}
3973
3974static int HAL2_device_allocate_reprocess_stream(
3975 const struct camera2_device *dev,
3976 uint32_t width,
3977 uint32_t height,
3978 uint32_t format,
3979 const camera2_stream_in_ops_t *reprocess_stream_ops,
3980 // outputs
3981 uint32_t *stream_id,
3982 uint32_t *consumer_usage,
3983 uint32_t *max_buffers)
3984{
Sungjoong Kang13d8c7b2012-07-14 10:20:39 +09003985 ALOGV("DEBUG(%s):", __FUNCTION__);
Jiyoung Shinc15a6b02012-06-05 01:08:14 -07003986 return obj(dev)->allocateReprocessStream(width, height, format, reprocess_stream_ops,
3987 stream_id, consumer_usage, max_buffers);
3988}
3989
3990static int HAL2_device_release_reprocess_stream(
3991 const struct camera2_device *dev,
3992 uint32_t stream_id)
3993{
Sungjoong Kang13d8c7b2012-07-14 10:20:39 +09003994 ALOGV("DEBUG(%s):", __FUNCTION__);
Jiyoung Shinc15a6b02012-06-05 01:08:14 -07003995 return obj(dev)->releaseReprocessStream(stream_id);
3996}
3997
3998static int HAL2_device_trigger_action(const struct camera2_device *dev,
3999 uint32_t trigger_id,
4000 int ext1,
4001 int ext2)
4002{
Sungjoong Kang13d8c7b2012-07-14 10:20:39 +09004003 ALOGV("DEBUG(%s):", __FUNCTION__);
Jiyoung Shinc15a6b02012-06-05 01:08:14 -07004004 return obj(dev)->triggerAction(trigger_id, ext1, ext2);
4005}
4006
4007static int HAL2_device_set_notify_callback(const struct camera2_device *dev,
4008 camera2_notify_callback notify_cb,
4009 void *user)
4010{
Sungjoong Kang13d8c7b2012-07-14 10:20:39 +09004011 ALOGV("DEBUG(%s):", __FUNCTION__);
Jiyoung Shinc15a6b02012-06-05 01:08:14 -07004012 return obj(dev)->setNotifyCallback(notify_cb, user);
4013}
4014
4015static int HAL2_device_get_metadata_vendor_tag_ops(const struct camera2_device*dev,
4016 vendor_tag_query_ops_t **ops)
4017{
Sungjoong Kang13d8c7b2012-07-14 10:20:39 +09004018 ALOGV("DEBUG(%s):", __FUNCTION__);
Jiyoung Shinc15a6b02012-06-05 01:08:14 -07004019 return obj(dev)->getMetadataVendorTagOps(ops);
4020}
4021
4022static int HAL2_device_dump(const struct camera2_device *dev, int fd)
4023{
Sungjoong Kang13d8c7b2012-07-14 10:20:39 +09004024 ALOGV("DEBUG(%s):", __FUNCTION__);
Jiyoung Shinc15a6b02012-06-05 01:08:14 -07004025 return obj(dev)->dump(fd);
4026}
4027
4028
4029
4030
4031
4032static int HAL2_getNumberOfCameras()
4033{
Sungjoong Kang9dd63e12012-07-24 00:25:51 +09004034 ALOGV("(%s): returning 2", __FUNCTION__);
4035 return 2;
Jiyoung Shinc15a6b02012-06-05 01:08:14 -07004036}
4037
4038
Jiyoung Shinc15a6b02012-06-05 01:08:14 -07004039static int HAL2_getCameraInfo(int cameraId, struct camera_info *info)
4040{
Sungjoong Kangad378612012-08-17 12:34:33 -07004041 ALOGV("DEBUG(%s): cameraID: %d", __FUNCTION__, cameraId);
Sungjoong Kang9dd63e12012-07-24 00:25:51 +09004042 static camera_metadata_t * mCameraInfo[2] = {NULL, NULL};
Sungjoong Kangad378612012-08-17 12:34:33 -07004043
Jiyoung Shinc15a6b02012-06-05 01:08:14 -07004044 status_t res;
Sungjoong Kang13d8c7b2012-07-14 10:20:39 +09004045
Sungjoong Kangdaa1fcd2012-08-08 11:49:43 -07004046 if (cameraId == 0) {
Sungjoong Kang9dd63e12012-07-24 00:25:51 +09004047 info->facing = CAMERA_FACING_BACK;
Sungjoong Kangdaa1fcd2012-08-08 11:49:43 -07004048 if (!g_camera2[0])
4049 g_camera2[0] = new ExynosCamera2(0);
4050 }
4051 else if (cameraId == 1) {
Sungjoong Kang9dd63e12012-07-24 00:25:51 +09004052 info->facing = CAMERA_FACING_FRONT;
Sungjoong Kangdaa1fcd2012-08-08 11:49:43 -07004053 if (!g_camera2[1])
4054 g_camera2[1] = new ExynosCamera2(1);
4055 }
4056 else
4057 return BAD_VALUE;
4058
Jiyoung Shinc15a6b02012-06-05 01:08:14 -07004059 info->orientation = 0;
4060 info->device_version = HARDWARE_DEVICE_API_VERSION(2, 0);
Sungjoong Kang9dd63e12012-07-24 00:25:51 +09004061 if (mCameraInfo[cameraId] == NULL) {
Sungjoong Kangdaa1fcd2012-08-08 11:49:43 -07004062 res = g_camera2[cameraId]->constructStaticInfo(&(mCameraInfo[cameraId]), cameraId, true);
Jiyoung Shinc15a6b02012-06-05 01:08:14 -07004063 if (res != OK) {
4064 ALOGE("%s: Unable to allocate static info: %s (%d)",
Sungjoong Kang13d8c7b2012-07-14 10:20:39 +09004065 __FUNCTION__, strerror(-res), res);
Jiyoung Shinc15a6b02012-06-05 01:08:14 -07004066 return res;
4067 }
Sungjoong Kangdaa1fcd2012-08-08 11:49:43 -07004068 res = g_camera2[cameraId]->constructStaticInfo(&(mCameraInfo[cameraId]), cameraId, false);
Jiyoung Shinc15a6b02012-06-05 01:08:14 -07004069 if (res != OK) {
4070 ALOGE("%s: Unable to fill in static info: %s (%d)",
Sungjoong Kang13d8c7b2012-07-14 10:20:39 +09004071 __FUNCTION__, strerror(-res), res);
Jiyoung Shinc15a6b02012-06-05 01:08:14 -07004072 return res;
4073 }
4074 }
Sungjoong Kang9dd63e12012-07-24 00:25:51 +09004075 info->static_camera_characteristics = mCameraInfo[cameraId];
Sungjoong Kang13d8c7b2012-07-14 10:20:39 +09004076 return NO_ERROR;
Jiyoung Shinc15a6b02012-06-05 01:08:14 -07004077}
4078
4079#define SET_METHOD(m) m : HAL2_device_##m
4080
4081static camera2_device_ops_t camera2_device_ops = {
4082 SET_METHOD(set_request_queue_src_ops),
4083 SET_METHOD(notify_request_queue_not_empty),
4084 SET_METHOD(set_frame_queue_dst_ops),
4085 SET_METHOD(get_in_progress_count),
4086 SET_METHOD(flush_captures_in_progress),
4087 SET_METHOD(construct_default_request),
4088 SET_METHOD(allocate_stream),
4089 SET_METHOD(register_stream_buffers),
4090 SET_METHOD(release_stream),
4091 SET_METHOD(allocate_reprocess_stream),
4092 SET_METHOD(release_reprocess_stream),
4093 SET_METHOD(trigger_action),
4094 SET_METHOD(set_notify_callback),
4095 SET_METHOD(get_metadata_vendor_tag_ops),
4096 SET_METHOD(dump),
4097};
4098
4099#undef SET_METHOD
4100
4101
4102static int HAL2_camera_device_open(const struct hw_module_t* module,
4103 const char *id,
4104 struct hw_device_t** device)
4105{
Sungjoong Kang9dd63e12012-07-24 00:25:51 +09004106
Jiyoung Shinc15a6b02012-06-05 01:08:14 -07004107
4108 int cameraId = atoi(id);
Sungjoong Kang9dd63e12012-07-24 00:25:51 +09004109
Sungjoong Kangb5237e62012-07-27 07:39:05 -07004110 g_camera_vaild = false;
Sungjoong Kangad378612012-08-17 12:34:33 -07004111 ALOGV("\n\n>>> I'm Samsung's CameraHAL_2(ID:%d) <<<\n\n", cameraId);
Jiyoung Shinc15a6b02012-06-05 01:08:14 -07004112 if (cameraId < 0 || cameraId >= HAL2_getNumberOfCameras()) {
Sungjoong Kang13d8c7b2012-07-14 10:20:39 +09004113 ALOGE("ERR(%s):Invalid camera ID %s", __FUNCTION__, id);
Jiyoung Shinc15a6b02012-06-05 01:08:14 -07004114 return -EINVAL;
4115 }
4116
Sungjoong Kangad378612012-08-17 12:34:33 -07004117 ALOGV("g_cam2_device : 0x%08x", (unsigned int)g_cam2_device);
Jiyoung Shinc15a6b02012-06-05 01:08:14 -07004118 if (g_cam2_device) {
4119 if (obj(g_cam2_device)->getCameraId() == cameraId) {
Sungjoong Kang13d8c7b2012-07-14 10:20:39 +09004120 ALOGV("DEBUG(%s):returning existing camera ID %s", __FUNCTION__, id);
Jiyoung Shinc15a6b02012-06-05 01:08:14 -07004121 goto done;
4122 } else {
Sungjoong Kang9dd63e12012-07-24 00:25:51 +09004123
4124 while (g_cam2_device)
4125 usleep(10000);
Jiyoung Shinc15a6b02012-06-05 01:08:14 -07004126 }
4127 }
4128
4129 g_cam2_device = (camera2_device_t *)malloc(sizeof(camera2_device_t));
Sungjoong Kangad378612012-08-17 12:34:33 -07004130 ALOGV("g_cam2_device : 0x%08x", (unsigned int)g_cam2_device);
Sungjoong Kang9dd63e12012-07-24 00:25:51 +09004131
Jiyoung Shinc15a6b02012-06-05 01:08:14 -07004132 if (!g_cam2_device)
4133 return -ENOMEM;
4134
4135 g_cam2_device->common.tag = HARDWARE_DEVICE_TAG;
4136 g_cam2_device->common.version = CAMERA_DEVICE_API_VERSION_2_0;
4137 g_cam2_device->common.module = const_cast<hw_module_t *>(module);
4138 g_cam2_device->common.close = HAL2_camera_device_close;
4139
4140 g_cam2_device->ops = &camera2_device_ops;
4141
Sungjoong Kang13d8c7b2012-07-14 10:20:39 +09004142 ALOGV("DEBUG(%s):open camera2 %s", __FUNCTION__, id);
Jiyoung Shinc15a6b02012-06-05 01:08:14 -07004143
Sungjoong Kangdaa1fcd2012-08-08 11:49:43 -07004144 g_cam2_device->priv = new ExynosCameraHWInterface2(cameraId, g_cam2_device, g_camera2[cameraId]);
Jiyoung Shinc15a6b02012-06-05 01:08:14 -07004145
4146done:
4147 *device = (hw_device_t *)g_cam2_device;
Sungjoong Kang13d8c7b2012-07-14 10:20:39 +09004148 ALOGV("DEBUG(%s):opened camera2 %s (%p)", __FUNCTION__, id, *device);
Sungjoong Kangb5237e62012-07-27 07:39:05 -07004149 g_camera_vaild = true;
Jiyoung Shinc15a6b02012-06-05 01:08:14 -07004150
4151 return 0;
4152}
4153
4154
4155static hw_module_methods_t camera_module_methods = {
4156 open : HAL2_camera_device_open
4157};
4158
4159extern "C" {
4160 struct camera_module HAL_MODULE_INFO_SYM = {
4161 common : {
4162 tag : HARDWARE_MODULE_TAG,
4163 module_api_version : CAMERA_MODULE_API_VERSION_2_0,
4164 hal_api_version : HARDWARE_HAL_API_VERSION,
4165 id : CAMERA_HARDWARE_MODULE_ID,
4166 name : "Exynos Camera HAL2",
4167 author : "Samsung Corporation",
4168 methods : &camera_module_methods,
4169 dso: NULL,
4170 reserved: {0},
4171 },
4172 get_number_of_cameras : HAL2_getNumberOfCameras,
4173 get_camera_info : HAL2_getCameraInfo
4174 };
4175}
4176
4177}; // namespace android