Commit | Line | Data |
---|---|---|
c15a6b00 JS |
1 | /* |
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) | |
13d8c7b4 | 23 | * \date 2012/07/10 |
c15a6b00 JS |
24 | * |
25 | * <b>Revision History: </b> | |
26 | * - 2012/05/31 : Sungjoong Kang(sj3.kang@samsung.com) \n | |
27 | * Initial Release | |
13d8c7b4 SK |
28 | * |
29 | * - 2012/07/10 : Sungjoong Kang(sj3.kang@samsung.com) \n | |
30 | * 2nd Release | |
31 | * | |
c15a6b00 JS |
32 | */ |
33 | ||
34 | //#define LOG_NDEBUG 0 | |
9dd63e1f | 35 | #define LOG_TAG "ExynosCameraHAL2" |
c15a6b00 JS |
36 | #include <utils/Log.h> |
37 | ||
38 | #include "ExynosCameraHWInterface2.h" | |
39 | #include "exynos_format.h" | |
40 | ||
41 | ||
42 | ||
43 | namespace android { | |
44 | ||
45 | ||
13d8c7b4 SK |
46 | // temporarily copied from EmulatedFakeCamera2 |
47 | // TODO : implement our own codes | |
48 | status_t constructDefaultRequestInternal( | |
49 | int request_template, | |
50 | camera_metadata_t **request, | |
51 | bool sizeRequest); | |
52 | ||
53 | status_t constructStaticInfo( | |
54 | camera_metadata_t **info, | |
9dd63e1f | 55 | int cameraId, |
13d8c7b4 | 56 | bool sizeRequest); |
c15a6b00 | 57 | |
9dd63e1f SK |
58 | bool isSupportedPreviewSize(int m_cameraId, int width, int height); |
59 | bool isSupportedJpegSize(int m_cameraId, int width, int height); | |
60 | int getSccOutputSizeX(int cameraId); | |
61 | int getSccOutputSizeY(int cameraId); | |
62 | int getSensorOutputSizeX(int cameraId); | |
63 | int getSensorOutputSizeY(int cameraId); | |
64 | int getJpegOutputSizeX(int cameraId); | |
65 | int getJpegOutputSizeY(int cameraId); | |
66 | ||
67 | void m_savePostView(const char *fname, uint8_t *buf, uint32_t size) | |
68 | { | |
69 | int nw; | |
70 | int cnt = 0; | |
71 | uint32_t written = 0; | |
72 | ||
73 | ALOGD("opening file [%s], address[%x], size(%d)", fname, (unsigned int)buf, size); | |
74 | int fd = open(fname, O_RDWR | O_CREAT, 0644); | |
75 | if (fd < 0) { | |
76 | ALOGE("failed to create file [%s]: %s", fname, strerror(errno)); | |
77 | return; | |
78 | } | |
79 | ||
80 | ALOGD("writing %d bytes to file [%s]", size, fname); | |
81 | while (written < size) { | |
82 | nw = ::write(fd, buf + written, size - written); | |
83 | if (nw < 0) { | |
84 | ALOGE("failed to write to file %d [%s]: %s",written,fname, strerror(errno)); | |
85 | break; | |
86 | } | |
87 | written += nw; | |
88 | cnt++; | |
89 | } | |
90 | ALOGD("done writing %d bytes to file [%s] in %d passes",size, fname, cnt); | |
91 | ::close(fd); | |
92 | } | |
93 | ||
c15a6b00 JS |
94 | int get_pixel_depth(uint32_t fmt) |
95 | { | |
96 | int depth = 0; | |
97 | ||
98 | switch (fmt) { | |
99 | case V4L2_PIX_FMT_JPEG: | |
100 | depth = 8; | |
101 | break; | |
102 | ||
103 | case V4L2_PIX_FMT_NV12: | |
104 | case V4L2_PIX_FMT_NV21: | |
105 | case V4L2_PIX_FMT_YUV420: | |
106 | case V4L2_PIX_FMT_YVU420M: | |
107 | case V4L2_PIX_FMT_NV12M: | |
108 | case V4L2_PIX_FMT_NV12MT: | |
109 | depth = 12; | |
110 | break; | |
111 | ||
112 | case V4L2_PIX_FMT_RGB565: | |
113 | case V4L2_PIX_FMT_YUYV: | |
114 | case V4L2_PIX_FMT_YVYU: | |
115 | case V4L2_PIX_FMT_UYVY: | |
116 | case V4L2_PIX_FMT_VYUY: | |
117 | case V4L2_PIX_FMT_NV16: | |
118 | case V4L2_PIX_FMT_NV61: | |
119 | case V4L2_PIX_FMT_YUV422P: | |
120 | case V4L2_PIX_FMT_SBGGR10: | |
121 | case V4L2_PIX_FMT_SBGGR12: | |
122 | case V4L2_PIX_FMT_SBGGR16: | |
123 | depth = 16; | |
124 | break; | |
125 | ||
126 | case V4L2_PIX_FMT_RGB32: | |
127 | depth = 32; | |
128 | break; | |
129 | default: | |
130 | ALOGE("Get depth failed(format : %d)", fmt); | |
131 | break; | |
132 | } | |
133 | ||
134 | return depth; | |
13d8c7b4 | 135 | } |
c15a6b00 JS |
136 | |
137 | int cam_int_s_fmt(node_info_t *node) | |
138 | { | |
139 | struct v4l2_format v4l2_fmt; | |
140 | unsigned int framesize; | |
141 | int ret; | |
142 | ||
143 | memset(&v4l2_fmt, 0, sizeof(struct v4l2_format)); | |
144 | ||
145 | v4l2_fmt.type = node->type; | |
146 | framesize = (node->width * node->height * get_pixel_depth(node->format)) / 8; | |
147 | ||
148 | if (node->planes >= 1) { | |
149 | v4l2_fmt.fmt.pix_mp.width = node->width; | |
150 | v4l2_fmt.fmt.pix_mp.height = node->height; | |
151 | v4l2_fmt.fmt.pix_mp.pixelformat = node->format; | |
152 | v4l2_fmt.fmt.pix_mp.field = V4L2_FIELD_ANY; | |
153 | } else { | |
13d8c7b4 | 154 | ALOGE("%s:S_FMT, Out of bound : Number of element plane",__FUNCTION__); |
c15a6b00 JS |
155 | } |
156 | ||
157 | /* Set up for capture */ | |
158 | ret = exynos_v4l2_s_fmt(node->fd, &v4l2_fmt); | |
159 | ||
160 | if (ret < 0) | |
13d8c7b4 | 161 | ALOGE("%s: exynos_v4l2_s_fmt fail (%d)",__FUNCTION__, ret); |
c15a6b00 JS |
162 | |
163 | return ret; | |
164 | } | |
165 | ||
166 | int cam_int_reqbufs(node_info_t *node) | |
167 | { | |
168 | struct v4l2_requestbuffers req; | |
169 | int ret; | |
170 | ||
171 | req.count = node->buffers; | |
172 | req.type = node->type; | |
173 | req.memory = node->memory; | |
174 | ||
175 | ret = exynos_v4l2_reqbufs(node->fd, &req); | |
176 | ||
177 | if (ret < 0) | |
13d8c7b4 | 178 | ALOGE("%s: VIDIOC_REQBUFS (fd:%d) failed (%d)",__FUNCTION__,node->fd, ret); |
c15a6b00 JS |
179 | |
180 | return req.count; | |
181 | } | |
182 | ||
183 | int cam_int_qbuf(node_info_t *node, int index) | |
184 | { | |
185 | struct v4l2_buffer v4l2_buf; | |
186 | struct v4l2_plane planes[VIDEO_MAX_PLANES]; | |
187 | int i; | |
188 | int ret = 0; | |
189 | ||
190 | v4l2_buf.m.planes = planes; | |
191 | v4l2_buf.type = node->type; | |
192 | v4l2_buf.memory = node->memory; | |
193 | v4l2_buf.index = index; | |
194 | v4l2_buf.length = node->planes; | |
195 | ||
196 | for(i = 0; i < node->planes; i++){ | |
13d8c7b4 SK |
197 | v4l2_buf.m.planes[i].m.fd = (int)(node->buffer[index].fd.extFd[i]); |
198 | v4l2_buf.m.planes[i].length = (unsigned long)(node->buffer[index].size.extS[i]); | |
c15a6b00 JS |
199 | } |
200 | ||
201 | ret = exynos_v4l2_qbuf(node->fd, &v4l2_buf); | |
202 | ||
203 | if (ret < 0) | |
13d8c7b4 | 204 | ALOGE("%s: cam_int_qbuf failed (index:%d)(ret:%d)",__FUNCTION__, index, ret); |
c15a6b00 JS |
205 | |
206 | return ret; | |
207 | } | |
208 | ||
209 | int cam_int_streamon(node_info_t *node) | |
210 | { | |
211 | enum v4l2_buf_type type = node->type; | |
212 | int ret; | |
213 | ||
214 | ret = exynos_v4l2_streamon(node->fd, type); | |
215 | ||
216 | if (ret < 0) | |
13d8c7b4 | 217 | ALOGE("%s: VIDIOC_STREAMON failed (%d)",__FUNCTION__, ret); |
c15a6b00 JS |
218 | |
219 | ALOGV("On streaming I/O... ... fd(%d)", node->fd); | |
220 | ||
221 | return ret; | |
222 | } | |
223 | ||
13d8c7b4 SK |
224 | int cam_int_streamoff(node_info_t *node) |
225 | { | |
226 | enum v4l2_buf_type type = V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE; | |
227 | int ret; | |
228 | ||
229 | ALOGV("Off streaming I/O... fd(%d)", node->fd); | |
230 | ret = exynos_v4l2_streamoff(node->fd, type); | |
231 | ||
232 | if (ret < 0) | |
233 | ALOGE("%s: VIDIOC_STREAMOFF failed (%d)",__FUNCTION__, ret); | |
234 | ||
235 | return ret; | |
236 | } | |
237 | ||
9dd63e1f SK |
238 | int isp_int_streamoff(node_info_t *node) |
239 | { | |
240 | enum v4l2_buf_type type = V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE; | |
241 | int ret; | |
242 | ||
243 | ALOGV("Off streaming I/O... fd(%d)", node->fd); | |
244 | ret = exynos_v4l2_streamoff(node->fd, type); | |
245 | ||
246 | if (ret < 0) | |
247 | ALOGE("%s: VIDIOC_STREAMOFF failed (%d)",__FUNCTION__, ret); | |
248 | ||
249 | return ret; | |
250 | } | |
251 | ||
c15a6b00 JS |
252 | int cam_int_dqbuf(node_info_t *node) |
253 | { | |
254 | struct v4l2_buffer v4l2_buf; | |
255 | struct v4l2_plane planes[VIDEO_MAX_PLANES]; | |
256 | int ret; | |
257 | ||
258 | v4l2_buf.type = node->type; | |
259 | v4l2_buf.memory = node->memory; | |
260 | v4l2_buf.m.planes = planes; | |
261 | v4l2_buf.length = node->planes; | |
262 | ||
263 | ret = exynos_v4l2_dqbuf(node->fd, &v4l2_buf); | |
264 | if (ret < 0) | |
13d8c7b4 | 265 | ALOGE("%s: VIDIOC_DQBUF failed (%d)",__FUNCTION__, ret); |
c15a6b00 JS |
266 | |
267 | return v4l2_buf.index; | |
268 | } | |
269 | ||
270 | int cam_int_s_input(node_info_t *node, int index) | |
271 | { | |
272 | int ret; | |
13d8c7b4 | 273 | |
c15a6b00 JS |
274 | ret = exynos_v4l2_s_input(node->fd, index); |
275 | if (ret < 0) | |
13d8c7b4 | 276 | ALOGE("%s: VIDIOC_S_INPUT failed (%d)",__FUNCTION__, ret); |
c15a6b00 JS |
277 | |
278 | return ret; | |
279 | } | |
280 | ||
281 | ||
282 | gralloc_module_t const* ExynosCameraHWInterface2::m_grallocHal; | |
283 | ||
284 | RequestManager::RequestManager(SignalDrivenThread* main_thread): | |
285 | m_numOfEntries(0), | |
286 | m_entryInsertionIndex(0), | |
287 | m_entryProcessingIndex(0), | |
288 | m_entryFrameOutputIndex(0) | |
289 | { | |
290 | m_metadataConverter = new MetadataConverter; | |
291 | m_mainThread = main_thread; | |
13d8c7b4 | 292 | for (int i=0 ; i<NUM_MAX_REQUEST_MGR_ENTRY; i++) { |
13d8c7b4 SK |
293 | memset(&(entries[i]), 0x00, sizeof(request_manager_entry_t)); |
294 | entries[i].internal_shot.ctl.request.frameCount = -1; | |
295 | } | |
b5237e6b | 296 | m_sensorPipelineSkipCnt = 8; |
c15a6b00 JS |
297 | return; |
298 | } | |
299 | ||
300 | RequestManager::~RequestManager() | |
301 | { | |
302 | return; | |
303 | } | |
304 | ||
305 | int RequestManager::GetNumEntries() | |
306 | { | |
307 | return m_numOfEntries; | |
308 | } | |
309 | ||
9dd63e1f SK |
310 | void RequestManager::SetDefaultParameters(int cropX) |
311 | { | |
312 | m_cropX = cropX; | |
313 | } | |
314 | ||
c15a6b00 JS |
315 | bool RequestManager::IsRequestQueueFull() |
316 | { | |
317 | Mutex::Autolock lock(m_requestMutex); | |
318 | if (m_numOfEntries>=NUM_MAX_REQUEST_MGR_ENTRY) | |
319 | return true; | |
320 | else | |
321 | return false; | |
322 | } | |
323 | ||
324 | void RequestManager::RegisterRequest(camera_metadata_t * new_request) | |
325 | { | |
13d8c7b4 SK |
326 | ALOGV("DEBUG(%s):", __FUNCTION__); |
327 | ||
c15a6b00 | 328 | Mutex::Autolock lock(m_requestMutex); |
13d8c7b4 | 329 | |
c15a6b00 | 330 | request_manager_entry * newEntry = NULL; |
9dd63e1f | 331 | int newInsertionIndex = GetNextIndex(m_entryInsertionIndex); |
13d8c7b4 SK |
332 | ALOGV("DEBUG(%s): got lock, new insertIndex(%d), cnt before reg(%d)", __FUNCTION__,newInsertionIndex,m_numOfEntries ); |
333 | ||
c15a6b00 | 334 | |
c15a6b00 JS |
335 | newEntry = &(entries[newInsertionIndex]); |
336 | ||
337 | if (newEntry->status!=EMPTY) { | |
13d8c7b4 SK |
338 | ALOGV("DEBUG(%s): Circular buffer abnormal ", __FUNCTION__); |
339 | return; | |
c15a6b00 JS |
340 | } |
341 | newEntry->status = REGISTERED; | |
342 | newEntry->original_request = new_request; | |
343 | // TODO : allocate internal_request dynamically | |
13d8c7b4 SK |
344 | m_metadataConverter->ToInternalShot(new_request, &(newEntry->internal_shot)); |
345 | newEntry->output_stream_count = newEntry->internal_shot.ctl.request.numOutputStream; | |
c15a6b00 JS |
346 | |
347 | m_numOfEntries++; | |
348 | m_entryInsertionIndex = newInsertionIndex; | |
349 | ||
13d8c7b4 | 350 | |
9dd63e1f | 351 | // Dump(); |
c15a6b00 | 352 | ALOGV("## RegisterReq DONE num(%d), insert(%d), processing(%d), frame(%d), (frameCnt(%d))", |
9dd63e1f | 353 | m_numOfEntries,m_entryInsertionIndex,m_entryProcessingIndex, m_entryFrameOutputIndex, newEntry->internal_shot.ctl.request.frameCount); |
c15a6b00 JS |
354 | } |
355 | ||
356 | void RequestManager::DeregisterRequest(camera_metadata_t ** deregistered_request) | |
357 | { | |
13d8c7b4 | 358 | ALOGV("DEBUG(%s):", __FUNCTION__); |
c15a6b00 JS |
359 | Mutex::Autolock lock(m_requestMutex); |
360 | ||
361 | request_manager_entry * currentEntry = &(entries[m_entryFrameOutputIndex]); | |
13d8c7b4 | 362 | |
c15a6b00 | 363 | if (currentEntry->status!=PROCESSING) { |
13d8c7b4 | 364 | ALOGD("DBG(%s): Circular buffer abnormal. processing(%d), frame(%d), status(%d) ", __FUNCTION__ |
c15a6b00 | 365 | , m_entryProcessingIndex, m_entryFrameOutputIndex,(int)(currentEntry->status)); |
13d8c7b4 | 366 | return; |
c15a6b00 | 367 | } |
13d8c7b4 SK |
368 | if (deregistered_request) *deregistered_request = currentEntry->original_request; |
369 | ||
c15a6b00 JS |
370 | currentEntry->status = EMPTY; |
371 | currentEntry->original_request = NULL; | |
13d8c7b4 SK |
372 | memset(&(currentEntry->internal_shot), 0, sizeof(camera2_ctl_metadata_NEW_t)); |
373 | currentEntry->internal_shot.ctl.request.frameCount = -1; | |
c15a6b00 | 374 | currentEntry->output_stream_count = 0; |
13d8c7b4 | 375 | currentEntry->dynamic_meta_vaild = false; |
c15a6b00 | 376 | m_numOfEntries--; |
9dd63e1f | 377 | // Dump(); |
c15a6b00 JS |
378 | ALOGV("## DeRegistReq DONE num(%d), insert(%d), processing(%d), frame(%d)", |
379 | m_numOfEntries,m_entryInsertionIndex,m_entryProcessingIndex, m_entryFrameOutputIndex); | |
13d8c7b4 | 380 | |
c15a6b00 | 381 | return; |
c15a6b00 JS |
382 | } |
383 | ||
13d8c7b4 | 384 | bool RequestManager::PrepareFrame(size_t* num_entries, size_t* frame_size, |
c15a6b00 JS |
385 | camera_metadata_t ** prepared_frame) |
386 | { | |
13d8c7b4 | 387 | ALOGV("DEBUG(%s):", __FUNCTION__); |
c15a6b00 JS |
388 | Mutex::Autolock lock(m_requestMutex); |
389 | status_t res = NO_ERROR; | |
9dd63e1f | 390 | int tempFrameOutputIndex = GetNextIndex(m_entryFrameOutputIndex); |
13d8c7b4 SK |
391 | request_manager_entry * currentEntry = &(entries[tempFrameOutputIndex]); |
392 | ALOGV("DEBUG(%s): processing(%d), frameOut(%d), insert(%d) recentlycompleted(%d)", __FUNCTION__, | |
393 | m_entryProcessingIndex, m_entryFrameOutputIndex, m_entryInsertionIndex, m_completedIndex); | |
394 | ||
395 | if (m_completedIndex != tempFrameOutputIndex) { | |
396 | ALOGV("DEBUG(%s): frame left behind : completed(%d), preparing(%d)", __FUNCTION__, m_completedIndex,tempFrameOutputIndex); | |
397 | ||
398 | request_manager_entry * currentEntry2 = &(entries[tempFrameOutputIndex]); | |
399 | currentEntry2->status = EMPTY; | |
400 | currentEntry2->original_request = NULL; | |
401 | memset(&(currentEntry2->internal_shot), 0, sizeof(camera2_ctl_metadata_NEW_t)); | |
402 | currentEntry2->internal_shot.ctl.request.frameCount = -1; | |
403 | currentEntry2->output_stream_count = 0; | |
404 | currentEntry2->dynamic_meta_vaild = false; | |
405 | m_numOfEntries--; | |
9dd63e1f | 406 | // Dump(); |
13d8c7b4 SK |
407 | tempFrameOutputIndex = m_completedIndex; |
408 | currentEntry = &(entries[tempFrameOutputIndex]); | |
409 | } | |
410 | ||
411 | if (currentEntry->output_stream_count!=0) { | |
412 | ALOGD("DBG(%s): Circular buffer has remaining output : stream_count(%d)", __FUNCTION__, currentEntry->output_stream_count); | |
413 | return false; | |
c15a6b00 JS |
414 | } |
415 | ||
13d8c7b4 SK |
416 | if (currentEntry->status!=PROCESSING) { |
417 | ALOGD("DBG(%s): Circular buffer abnormal status(%d)", __FUNCTION__, (int)(currentEntry->status)); | |
418 | ||
419 | return false; | |
420 | } | |
421 | m_entryFrameOutputIndex = tempFrameOutputIndex; | |
c15a6b00 | 422 | m_tempFrameMetadata = place_camera_metadata(m_tempFrameMetadataBuf, 2000, 10, 500); //estimated |
13d8c7b4 | 423 | res = m_metadataConverter->ToDynamicMetadata(&(currentEntry->internal_shot), |
c15a6b00 JS |
424 | m_tempFrameMetadata); |
425 | if (res!=NO_ERROR) { | |
13d8c7b4 SK |
426 | ALOGE("ERROR(%s): ToDynamicMetadata (%d) ", __FUNCTION__, res); |
427 | return false; | |
c15a6b00 JS |
428 | } |
429 | *num_entries = get_camera_metadata_entry_count(m_tempFrameMetadata); | |
430 | *frame_size = get_camera_metadata_size(m_tempFrameMetadata); | |
431 | *prepared_frame = m_tempFrameMetadata; | |
13d8c7b4 SK |
432 | ALOGV("## PrepareFrame DONE: frameOut(%d) frameCnt-req(%d)", m_entryFrameOutputIndex, |
433 | currentEntry->internal_shot.ctl.request.frameCount); | |
9dd63e1f | 434 | // Dump(); |
13d8c7b4 | 435 | return true; |
c15a6b00 JS |
436 | } |
437 | ||
13d8c7b4 | 438 | int RequestManager::MarkProcessingRequest(ExynosBuffer* buf) |
c15a6b00 | 439 | { |
13d8c7b4 | 440 | ALOGV("DEBUG(%s):", __FUNCTION__); |
c15a6b00 | 441 | Mutex::Autolock lock(m_requestMutex); |
13d8c7b4 SK |
442 | struct camera2_shot_ext * shot_ext; |
443 | int targetStreamIndex = 0; | |
444 | ||
13d8c7b4 SK |
445 | if (m_numOfEntries == 0) { |
446 | ALOGV("DEBUG(%s): Request Manager Empty ", __FUNCTION__); | |
447 | return -1; | |
448 | } | |
449 | ||
450 | if ((m_entryProcessingIndex == m_entryInsertionIndex) | |
451 | && (entries[m_entryProcessingIndex].status == PROCESSING)) { | |
452 | ALOGV("## MarkProcReq skipping(request underrun) - num(%d), insert(%d), processing(%d), frame(%d)", | |
453 | m_numOfEntries,m_entryInsertionIndex,m_entryProcessingIndex, m_entryFrameOutputIndex); | |
454 | return -1; | |
455 | } | |
c15a6b00 JS |
456 | |
457 | request_manager_entry * newEntry = NULL; | |
9dd63e1f | 458 | int newProcessingIndex = GetNextIndex(m_entryProcessingIndex); |
c15a6b00 | 459 | |
c15a6b00 JS |
460 | newEntry = &(entries[newProcessingIndex]); |
461 | ||
462 | if (newEntry->status!=REGISTERED) { | |
13d8c7b4 | 463 | ALOGV("DEBUG(%s): Circular buffer abnormal ", __FUNCTION__); |
9dd63e1f | 464 | // Dump(); |
13d8c7b4 | 465 | return -1; |
c15a6b00 JS |
466 | } |
467 | newEntry->status = PROCESSING; | |
13d8c7b4 | 468 | // TODO : replace the codes below with a single memcpy of pre-converted 'shot' |
c15a6b00 | 469 | |
13d8c7b4 SK |
470 | shot_ext = (struct camera2_shot_ext *)(buf->virt.extP[1]); |
471 | memset(shot_ext, 0x00, sizeof(struct camera2_shot_ext)); | |
472 | ||
473 | shot_ext->request_sensor = 1; | |
9dd63e1f SK |
474 | shot_ext->dis_bypass = 1; |
475 | shot_ext->dnr_bypass = 1; | |
13d8c7b4 SK |
476 | for (int i = 0; i < newEntry->output_stream_count; i++) { |
477 | // TODO : match with actual stream index; | |
478 | targetStreamIndex = newEntry->internal_shot.ctl.request.outputStreams[i]; | |
479 | ||
480 | if (targetStreamIndex==0) { | |
481 | ALOGV("DEBUG(%s): outputstreams(%d) is for scalerP", __FUNCTION__, i); | |
482 | shot_ext->request_scp = 1; | |
9dd63e1f | 483 | shot_ext->shot.ctl.request.outputStreams[0] = 1; |
13d8c7b4 | 484 | } |
9dd63e1f | 485 | else if (targetStreamIndex == 1) { |
13d8c7b4 SK |
486 | ALOGV("DEBUG(%s): outputstreams(%d) is for scalerC", __FUNCTION__, i); |
487 | shot_ext->request_scc = 1; | |
9dd63e1f SK |
488 | shot_ext->shot.ctl.request.outputStreams[1] = 1; |
489 | } | |
490 | else if (targetStreamIndex == 2) { | |
491 | ALOGV("DEBUG(%s): outputstreams(%d) is for scalerP (record)", __FUNCTION__, i); | |
492 | shot_ext->request_scp = 1; | |
493 | shot_ext->shot.ctl.request.outputStreams[2] = 1; | |
13d8c7b4 SK |
494 | } |
495 | else { | |
496 | ALOGV("DEBUG(%s): outputstreams(%d) has abnormal value(%d)", __FUNCTION__, i, targetStreamIndex); | |
497 | } | |
498 | } | |
9dd63e1f SK |
499 | shot_ext->shot.ctl.request.metadataMode = METADATA_MODE_FULL; |
500 | shot_ext->shot.magicNumber = 0x23456789; | |
501 | shot_ext->shot.ctl.sensor.exposureTime = 0; | |
502 | shot_ext->shot.ctl.sensor.frameDuration = 33*1000*1000; | |
503 | shot_ext->shot.ctl.sensor.sensitivity = 0; | |
13d8c7b4 SK |
504 | |
505 | shot_ext->shot.ctl.scaler.cropRegion[0] = 0; | |
506 | shot_ext->shot.ctl.scaler.cropRegion[1] = 0; | |
9dd63e1f | 507 | shot_ext->shot.ctl.scaler.cropRegion[2] = m_cropX; |
13d8c7b4 SK |
508 | |
509 | m_entryProcessingIndex = newProcessingIndex; | |
510 | ||
9dd63e1f | 511 | // Dump(); |
13d8c7b4 SK |
512 | ALOGV("## MarkProcReq DONE totalentry(%d), insert(%d), processing(%d), frame(%d) frameCnt(%d)", |
513 | m_numOfEntries,m_entryInsertionIndex,m_entryProcessingIndex, m_entryFrameOutputIndex, newEntry->internal_shot.ctl.request.frameCount); | |
514 | ||
515 | return m_entryProcessingIndex; | |
c15a6b00 JS |
516 | } |
517 | ||
9dd63e1f | 518 | void RequestManager::NotifyStreamOutput(int frameCnt, int stream_id) |
c15a6b00 | 519 | { |
9dd63e1f SK |
520 | int index; |
521 | ||
522 | ALOGV("DEBUG(%s): frameCnt(%d), stream_id(%d)", __FUNCTION__, frameCnt, stream_id); | |
523 | ||
524 | index = FindEntryIndexByFrameCnt(frameCnt); | |
525 | if (index == -1) { | |
526 | ALOGE("ERR(%s): Cannot find entry for frameCnt(%d)", __FUNCTION__, frameCnt); | |
527 | return; | |
528 | } | |
529 | ALOGV("DEBUG(%s): frameCnt(%d), stream_id(%d) last cnt (%d)", __FUNCTION__, frameCnt, stream_id, entries[index].output_stream_count); | |
530 | ||
b5237e6b SK |
531 | if (entries[index].output_stream_count == 0) { |
532 | ALOGV("(%s): applying to next frame", __FUNCTION__); | |
533 | entries[GetNextIndex(index)].output_stream_count--; | |
534 | } | |
535 | else { | |
536 | entries[index].output_stream_count--; //TODO : match stream id also | |
537 | CheckCompleted(index); | |
538 | } | |
13d8c7b4 SK |
539 | return; |
540 | } | |
541 | ||
542 | void RequestManager::CheckCompleted(int index) | |
543 | { | |
9dd63e1f | 544 | ALOGV("DEBUG(%s): reqIndex(%d) current Count(%d)", __FUNCTION__, index, entries[index].output_stream_count); |
b5237e6b | 545 | if (entries[index].output_stream_count == 0 && entries[index].dynamic_meta_vaild) { |
13d8c7b4 | 546 | ALOGV("DEBUG(%s): index[%d] completed and sending SIGNAL_MAIN_STREAM_OUTPUT_DONE", __FUNCTION__, index); |
b5237e6b | 547 | // Dump(); |
13d8c7b4 SK |
548 | m_completedIndex = index; |
549 | m_mainThread->SetSignal(SIGNAL_MAIN_STREAM_OUTPUT_DONE); | |
550 | } | |
c15a6b00 JS |
551 | return; |
552 | } | |
9dd63e1f SK |
553 | |
554 | void RequestManager::ApplyDynamicMetadata(struct camera2_shot_ext *shot_ext, int frameCnt) | |
13d8c7b4 | 555 | { |
9dd63e1f | 556 | int index; |
13d8c7b4 | 557 | |
9dd63e1f SK |
558 | ALOGV("DEBUG(%s): frameCnt(%d)", __FUNCTION__, frameCnt); |
559 | ||
560 | index = FindEntryIndexByFrameCnt(frameCnt); | |
561 | if (index == -1) { | |
562 | ALOGE("ERR(%s): Cannot find entry for frameCnt(%d)", __FUNCTION__, frameCnt); | |
563 | return; | |
13d8c7b4 | 564 | } |
9dd63e1f SK |
565 | |
566 | request_manager_entry * newEntry = &(entries[index]); | |
567 | ||
b5237e6b SK |
568 | if (newEntry->dynamic_meta_vaild) { |
569 | ALOGV("(%s): applying to next frame", __FUNCTION__); | |
570 | newEntry = &(entries[GetNextIndex(index)]); | |
571 | newEntry->dynamic_meta_vaild = true; | |
572 | } | |
573 | else { | |
574 | newEntry->dynamic_meta_vaild = true; | |
575 | // TODO : move some code of PrepareFrame here | |
576 | CheckCompleted(index); | |
577 | } | |
13d8c7b4 SK |
578 | } |
579 | ||
580 | void RequestManager::DumpInfoWithIndex(int index) | |
581 | { | |
582 | camera2_ctl_metadata_NEW_t * currMetadata = &(entries[index].internal_shot); | |
583 | ||
584 | ALOGV("#### frameCount(%d) exposureTime(%lld) ISO(%d)", | |
585 | currMetadata->ctl.request.frameCount, | |
586 | currMetadata->ctl.sensor.exposureTime, | |
587 | currMetadata->ctl.sensor.sensitivity); | |
588 | if (currMetadata->ctl.request.numOutputStream==0) | |
589 | ALOGV("#### No output stream selected"); | |
590 | else if (currMetadata->ctl.request.numOutputStream==1) | |
591 | ALOGV("#### OutputStreamId : %d", currMetadata->ctl.request.outputStreams[0]); | |
592 | else if (currMetadata->ctl.request.numOutputStream==2) | |
593 | ALOGV("#### OutputStreamId : %d, %d", currMetadata->ctl.request.outputStreams[0], | |
594 | currMetadata->ctl.request.outputStreams[1]); | |
595 | else | |
596 | ALOGV("#### OutputStream num (%d) abnormal ", currMetadata->ctl.request.numOutputStream); | |
597 | } | |
598 | ||
9dd63e1f | 599 | void RequestManager::UpdateOutputStreamInfo(struct camera2_shot_ext *shot_ext, int frameCnt) |
13d8c7b4 | 600 | { |
9dd63e1f SK |
601 | int index, targetStreamIndex; |
602 | ||
603 | ALOGV("DEBUG(%s): updating info with frameCnt(%d)", __FUNCTION__, frameCnt); | |
604 | if (frameCnt < 0) | |
13d8c7b4 | 605 | return; |
9dd63e1f SK |
606 | |
607 | index = FindEntryIndexByFrameCnt(frameCnt); | |
608 | if (index == -1) { | |
609 | ALOGE("ERR(%s): Cannot find entry for frameCnt(%d)", __FUNCTION__, frameCnt); | |
610 | return; | |
611 | } | |
612 | ||
13d8c7b4 SK |
613 | request_manager_entry * newEntry = &(entries[index]); |
614 | shot_ext->request_sensor = 1; | |
615 | shot_ext->request_scc = 0; | |
616 | shot_ext->request_scp = 0; | |
9dd63e1f SK |
617 | shot_ext->shot.ctl.request.outputStreams[0] = 0; |
618 | shot_ext->shot.ctl.request.outputStreams[1] = 0; | |
619 | shot_ext->shot.ctl.request.outputStreams[2] = 0; | |
620 | ||
13d8c7b4 SK |
621 | for (int i = 0; i < newEntry->output_stream_count; i++) { |
622 | // TODO : match with actual stream index; | |
623 | targetStreamIndex = newEntry->internal_shot.ctl.request.outputStreams[i]; | |
624 | ||
625 | if (targetStreamIndex==0) { | |
9dd63e1f | 626 | ALOGV("DEBUG(%s): outputstreams item[%d] is for scalerP", __FUNCTION__, i); |
13d8c7b4 | 627 | shot_ext->request_scp = 1; |
9dd63e1f | 628 | shot_ext->shot.ctl.request.outputStreams[0] = 1; |
13d8c7b4 | 629 | } |
9dd63e1f SK |
630 | else if (targetStreamIndex == 1) { |
631 | ALOGV("DEBUG(%s): outputstreams item[%d] is for scalerC", __FUNCTION__, i); | |
13d8c7b4 | 632 | shot_ext->request_scc = 1; |
9dd63e1f SK |
633 | shot_ext->shot.ctl.request.outputStreams[1] = 1; |
634 | } | |
635 | else if (targetStreamIndex == 2) { | |
636 | ALOGV("DEBUG(%s): outputstreams item[%d] is for scalerP (record)", __FUNCTION__, i); | |
637 | shot_ext->request_scp = 1; | |
638 | shot_ext->shot.ctl.request.outputStreams[2] = 1; | |
13d8c7b4 SK |
639 | } |
640 | else { | |
9dd63e1f | 641 | ALOGV("DEBUG(%s): outputstreams item[%d] has abnormal value(%d)", __FUNCTION__, i, targetStreamIndex); |
13d8c7b4 SK |
642 | } |
643 | } | |
644 | } | |
645 | ||
9dd63e1f SK |
646 | int RequestManager::FindEntryIndexByFrameCnt(int frameCnt) |
647 | { | |
648 | for (int i = 0 ; i < NUM_MAX_REQUEST_MGR_ENTRY ; i++) { | |
649 | if (entries[i].internal_shot.ctl.request.frameCount == frameCnt) | |
650 | return i; | |
651 | } | |
652 | return -1; | |
653 | } | |
654 | ||
655 | void RequestManager::RegisterTimestamp(int frameCnt, nsecs_t * frameTime) | |
13d8c7b4 | 656 | { |
9dd63e1f SK |
657 | int index = FindEntryIndexByFrameCnt(frameCnt); |
658 | if (index == -1) { | |
659 | ALOGE("ERR(%s): Cannot find entry for frameCnt(%d)", __FUNCTION__, frameCnt); | |
660 | return; | |
661 | } | |
662 | ||
13d8c7b4 SK |
663 | request_manager_entry * currentEntry = &(entries[index]); |
664 | currentEntry->internal_shot.dm.sensor.timeStamp = *((uint64_t*)frameTime); | |
9dd63e1f SK |
665 | ALOGV("DEBUG(%s): applied timestamp for reqIndex(%d) frameCnt(%d) (%lld)", __FUNCTION__, |
666 | index, frameCnt, currentEntry->internal_shot.dm.sensor.timeStamp); | |
13d8c7b4 SK |
667 | } |
668 | ||
9dd63e1f | 669 | uint64_t RequestManager::GetTimestamp(int frameCnt) |
13d8c7b4 | 670 | { |
9dd63e1f SK |
671 | int index = FindEntryIndexByFrameCnt(frameCnt); |
672 | if (index == -1) { | |
673 | ALOGE("ERR(%s): Cannot find entry for frameCnt(%d)", __FUNCTION__, frameCnt); | |
674 | return 0; | |
675 | } | |
676 | ||
13d8c7b4 SK |
677 | request_manager_entry * currentEntry = &(entries[index]); |
678 | uint64_t frameTime = currentEntry->internal_shot.dm.sensor.timeStamp; | |
9dd63e1f | 679 | ALOGV("DEBUG(%s): Returning timestamp for reqIndex(%d) (%lld)", __FUNCTION__, index, frameTime); |
13d8c7b4 SK |
680 | return frameTime; |
681 | } | |
682 | ||
9dd63e1f SK |
683 | int RequestManager::FindFrameCnt(struct camera2_shot_ext * shot_ext) |
684 | { | |
685 | int tempIndex; | |
b5237e6b SK |
686 | if (m_sensorPipelineSkipCnt > 0) { |
687 | m_sensorPipelineSkipCnt--; | |
9dd63e1f SK |
688 | return -1; |
689 | } | |
690 | /* | |
691 | * tempIndex = GetNextIndex(tempIndex); | |
692 | * return entries[tempIndex].internal_shot.ctl.request.frameCount; | |
693 | * */ | |
694 | tempIndex = GetNextIndex(m_entryFrameOutputIndex); | |
695 | return entries[tempIndex].internal_shot.ctl.request.frameCount; | |
696 | } | |
13d8c7b4 | 697 | |
b5237e6b SK |
698 | void RequestManager::SetInitialSkip(int count) |
699 | { | |
700 | ALOGV("(%s): Pipeline Restarting. setting cnt(%d) - current(%d)", __FUNCTION__, count, m_sensorPipelineSkipCnt); | |
701 | if (count > m_sensorPipelineSkipCnt) | |
702 | m_sensorPipelineSkipCnt = count; | |
703 | } | |
704 | ||
13d8c7b4 SK |
705 | void RequestManager::Dump(void) |
706 | { | |
13d8c7b4 SK |
707 | int i = 0; |
708 | request_manager_entry * currentEntry; | |
709 | ALOGV("## Dump totalentry(%d), insert(%d), processing(%d), frame(%d)", | |
710 | m_numOfEntries,m_entryInsertionIndex,m_entryProcessingIndex, m_entryFrameOutputIndex); | |
711 | ||
712 | for (i = 0 ; i < NUM_MAX_REQUEST_MGR_ENTRY ; i++) { | |
713 | currentEntry = &(entries[i]); | |
714 | ALOGV("[%2d] status[%d] frameCnt[%3d] numOutput[%d]", i, | |
715 | currentEntry->status, currentEntry->internal_shot.ctl.request.frameCount, | |
716 | currentEntry->output_stream_count); | |
717 | } | |
718 | } | |
c15a6b00 | 719 | |
9dd63e1f SK |
720 | int RequestManager::GetNextIndex(int index) |
721 | { | |
722 | index++; | |
723 | if (index >= NUM_MAX_REQUEST_MGR_ENTRY) | |
724 | index = 0; | |
725 | ||
726 | return index; | |
727 | } | |
728 | ||
c15a6b00 JS |
729 | ExynosCameraHWInterface2::ExynosCameraHWInterface2(int cameraId, camera2_device_t *dev): |
730 | m_requestQueueOps(NULL), | |
731 | m_frameQueueOps(NULL), | |
732 | m_callbackCookie(NULL), | |
733 | m_numOfRemainingReqInSvc(0), | |
734 | m_isRequestQueuePending(false), | |
13d8c7b4 | 735 | m_isRequestQueueNull(true), |
c15a6b00 | 736 | m_isSensorThreadOn(false), |
13d8c7b4 SK |
737 | m_isSensorStarted(false), |
738 | m_ionCameraClient(0), | |
739 | m_initFlag1(false), | |
740 | m_initFlag2(false), | |
13d8c7b4 SK |
741 | m_scp_flushing(false), |
742 | m_closing(false), | |
9dd63e1f SK |
743 | m_recordingEnabled(false), |
744 | m_needsRecordBufferInit(false), | |
745 | lastFrameCnt(-1), | |
746 | m_scp_closing(false), | |
747 | m_scp_closed(false), | |
9dd63e1f | 748 | m_halDevice(dev), |
b5237e6b | 749 | m_sensor_drop(false), |
9dd63e1f | 750 | m_cameraId(0) |
13d8c7b4 SK |
751 | { |
752 | ALOGV("DEBUG(%s):", __FUNCTION__); | |
c15a6b00 JS |
753 | int ret = 0; |
754 | ||
13d8c7b4 | 755 | m_exynosPictureCSC = NULL; |
9dd63e1f | 756 | m_exynosVideoCSC = NULL; |
13d8c7b4 | 757 | |
c15a6b00 JS |
758 | if (!m_grallocHal) { |
759 | ret = hw_get_module(GRALLOC_HARDWARE_MODULE_ID, (const hw_module_t **)&m_grallocHal); | |
760 | if (ret) | |
13d8c7b4 SK |
761 | ALOGE("ERR(%s):Fail on loading gralloc HAL", __FUNCTION__); |
762 | } | |
c15a6b00 JS |
763 | |
764 | m_ionCameraClient = createIonClient(m_ionCameraClient); | |
765 | if(m_ionCameraClient == 0) | |
13d8c7b4 | 766 | ALOGE("ERR(%s):Fail on ion_client_create", __FUNCTION__); |
c15a6b00 | 767 | |
9dd63e1f SK |
768 | m_cameraId = cameraId; |
769 | ||
770 | m_BayerManager = new BayerBufManager(); | |
c15a6b00 JS |
771 | m_mainThread = new MainThread(this); |
772 | m_sensorThread = new SensorThread(this); | |
13d8c7b4 SK |
773 | m_ispThread = new IspThread(this); |
774 | m_mainThread->Start("MainThread", PRIORITY_DEFAULT, 0); | |
775 | ALOGV("DEBUG(%s): created sensorthread ################", __FUNCTION__); | |
776 | usleep(1600000); | |
777 | ||
c15a6b00 | 778 | m_requestManager = new RequestManager((SignalDrivenThread*)(m_mainThread.get())); |
13d8c7b4 SK |
779 | CSC_METHOD cscMethod = CSC_METHOD_HW; |
780 | m_exynosPictureCSC = csc_init(cscMethod); | |
781 | if (m_exynosPictureCSC == NULL) | |
782 | ALOGE("ERR(%s): csc_init() fail", __FUNCTION__); | |
783 | csc_set_hw_property(m_exynosPictureCSC, CSC_HW_PROPERTY_FIXED_NODE, PICTURE_GSC_NODE_NUM); | |
c15a6b00 | 784 | |
9dd63e1f SK |
785 | m_exynosVideoCSC = csc_init(cscMethod); |
786 | if (m_exynosVideoCSC == NULL) | |
787 | ALOGE("ERR(%s): csc_init() fail", __FUNCTION__); | |
788 | csc_set_hw_property(m_exynosVideoCSC, CSC_HW_PROPERTY_FIXED_NODE, PREVIEW_GSC_NODE_NUM); | |
789 | ||
13d8c7b4 | 790 | ALOGV("DEBUG(%s): END", __FUNCTION__); |
c15a6b00 JS |
791 | } |
792 | ||
793 | ExynosCameraHWInterface2::~ExynosCameraHWInterface2() | |
794 | { | |
9dd63e1f | 795 | ALOGD("%s: ENTER", __FUNCTION__); |
c15a6b00 | 796 | this->release(); |
9dd63e1f | 797 | ALOGD("%s: EXIT", __FUNCTION__); |
c15a6b00 JS |
798 | } |
799 | ||
800 | void ExynosCameraHWInterface2::release() | |
801 | { | |
13d8c7b4 | 802 | int i, res; |
9dd63e1f | 803 | ALOGD("%s: ENTER", __func__); |
13d8c7b4 | 804 | m_closing = true; |
9dd63e1f SK |
805 | |
806 | while (!m_scp_closed) | |
807 | usleep(1000); | |
13d8c7b4 SK |
808 | if (m_ispThread != NULL) { |
809 | m_ispThread->release(); | |
13d8c7b4 SK |
810 | } |
811 | ||
812 | if (m_sensorThread != NULL) { | |
813 | m_sensorThread->release(); | |
13d8c7b4 | 814 | } |
c15a6b00 JS |
815 | |
816 | if (m_mainThread != NULL) { | |
13d8c7b4 | 817 | m_mainThread->release(); |
13d8c7b4 SK |
818 | } |
819 | ||
820 | if (m_streamThreads[0] != NULL) { | |
821 | m_streamThreads[0]->release(); | |
9dd63e1f | 822 | m_streamThreads[0]->SetSignal(SIGNAL_THREAD_TERMINATE); |
c15a6b00 | 823 | } |
c15a6b00 | 824 | |
13d8c7b4 SK |
825 | if (m_streamThreads[1] != NULL) { |
826 | m_streamThreads[1]->release(); | |
9dd63e1f | 827 | m_streamThreads[1]->SetSignal(SIGNAL_THREAD_TERMINATE); |
c15a6b00 JS |
828 | } |
829 | ||
13d8c7b4 SK |
830 | |
831 | if (m_exynosPictureCSC) | |
832 | csc_deinit(m_exynosPictureCSC); | |
833 | m_exynosPictureCSC = NULL; | |
834 | ||
9dd63e1f SK |
835 | if (m_exynosVideoCSC) |
836 | csc_deinit(m_exynosVideoCSC); | |
837 | m_exynosVideoCSC = NULL; | |
838 | ||
839 | if (m_ispThread != NULL) { | |
840 | while (!m_ispThread->IsTerminated()) | |
841 | usleep(1000); | |
842 | m_ispThread = NULL; | |
843 | } | |
844 | ||
845 | if (m_sensorThread != NULL) { | |
846 | while (!m_sensorThread->IsTerminated()) | |
847 | usleep(1000); | |
848 | m_sensorThread = NULL; | |
849 | } | |
850 | ||
851 | if (m_mainThread != NULL) { | |
852 | while (!m_mainThread->IsTerminated()) | |
853 | usleep(1000); | |
854 | m_mainThread = NULL; | |
855 | } | |
856 | ||
857 | if (m_streamThreads[0] != NULL) { | |
858 | while (!m_streamThreads[0]->IsTerminated()) | |
859 | usleep(1000); | |
860 | m_streamThreads[0] = NULL; | |
861 | } | |
862 | ||
863 | if (m_streamThreads[1] != NULL) { | |
864 | while (!m_streamThreads[1]->IsTerminated()) | |
865 | usleep(1000); | |
866 | m_streamThreads[1] = NULL; | |
867 | } | |
868 | ||
c15a6b00 JS |
869 | for(i = 0; i < m_camera_info.sensor.buffers; i++) |
870 | freeCameraMemory(&m_camera_info.sensor.buffer[i], m_camera_info.sensor.planes); | |
871 | ||
c15a6b00 JS |
872 | for(i = 0; i < m_camera_info.capture.buffers; i++) |
873 | freeCameraMemory(&m_camera_info.capture.buffer[i], m_camera_info.capture.planes); | |
874 | ||
9dd63e1f | 875 | ALOGV("DEBUG(%s): calling exynos_v4l2_close - sensor", __FUNCTION__); |
13d8c7b4 SK |
876 | res = exynos_v4l2_close(m_camera_info.sensor.fd); |
877 | if (res != NO_ERROR ) { | |
9dd63e1f | 878 | ALOGE("ERR(%s): exynos_v4l2_close failed(%d)",__FUNCTION__ , res); |
13d8c7b4 SK |
879 | } |
880 | ||
9dd63e1f | 881 | ALOGV("DEBUG(%s): calling exynos_v4l2_close - isp", __FUNCTION__); |
13d8c7b4 SK |
882 | res = exynos_v4l2_close(m_camera_info.isp.fd); |
883 | if (res != NO_ERROR ) { | |
9dd63e1f | 884 | ALOGE("ERR(%s): exynos_v4l2_close failed(%d)",__FUNCTION__ , res); |
13d8c7b4 SK |
885 | } |
886 | ||
9dd63e1f | 887 | ALOGV("DEBUG(%s): calling exynos_v4l2_close - capture", __FUNCTION__); |
13d8c7b4 SK |
888 | res = exynos_v4l2_close(m_camera_info.capture.fd); |
889 | if (res != NO_ERROR ) { | |
9dd63e1f | 890 | ALOGE("ERR(%s): exynos_v4l2_close failed(%d)",__FUNCTION__ , res); |
13d8c7b4 SK |
891 | } |
892 | ||
9dd63e1f SK |
893 | ALOGV("DEBUG(%s): calling exynos_v4l2_close - scp", __FUNCTION__); |
894 | res = exynos_v4l2_close(m_fd_scp); | |
13d8c7b4 | 895 | if (res != NO_ERROR ) { |
9dd63e1f | 896 | ALOGE("ERR(%s): exynos_v4l2_close failed(%d)",__FUNCTION__ , res); |
13d8c7b4 | 897 | } |
9dd63e1f | 898 | ALOGV("DEBUG(%s): calling deleteIonClient", __FUNCTION__); |
c15a6b00 | 899 | deleteIonClient(m_ionCameraClient); |
9dd63e1f SK |
900 | |
901 | ALOGD("%s: EXIT", __func__); | |
13d8c7b4 SK |
902 | } |
903 | ||
c15a6b00 JS |
904 | int ExynosCameraHWInterface2::getCameraId() const |
905 | { | |
9dd63e1f | 906 | return m_cameraId; |
c15a6b00 | 907 | } |
c15a6b00 JS |
908 | |
909 | int ExynosCameraHWInterface2::setRequestQueueSrcOps(const camera2_request_queue_src_ops_t *request_src_ops) | |
910 | { | |
13d8c7b4 | 911 | ALOGV("DEBUG(%s):", __FUNCTION__); |
c15a6b00 JS |
912 | if ((NULL != request_src_ops) && (NULL != request_src_ops->dequeue_request) |
913 | && (NULL != request_src_ops->free_request) && (NULL != request_src_ops->request_count)) { | |
914 | m_requestQueueOps = (camera2_request_queue_src_ops_t*)request_src_ops; | |
915 | return 0; | |
916 | } | |
917 | else { | |
13d8c7b4 | 918 | ALOGE("DEBUG(%s):setRequestQueueSrcOps : NULL arguments", __FUNCTION__); |
c15a6b00 JS |
919 | return 1; |
920 | } | |
921 | } | |
922 | ||
923 | int ExynosCameraHWInterface2::notifyRequestQueueNotEmpty() | |
924 | { | |
b5237e6b | 925 | ALOGV("DEBUG(%s):setting [SIGNAL_MAIN_REQ_Q_NOT_EMPTY] current(%d)", __FUNCTION__, m_requestManager->GetNumEntries()); |
c15a6b00 | 926 | if ((NULL==m_frameQueueOps)|| (NULL==m_requestQueueOps)) { |
13d8c7b4 | 927 | ALOGE("DEBUG(%s):queue ops NULL. ignoring request", __FUNCTION__); |
c15a6b00 JS |
928 | return 0; |
929 | } | |
13d8c7b4 | 930 | m_isRequestQueueNull = false; |
b5237e6b SK |
931 | if (m_requestManager->GetNumEntries() == 0) |
932 | m_requestManager->SetInitialSkip(5); | |
c15a6b00 JS |
933 | m_mainThread->SetSignal(SIGNAL_MAIN_REQ_Q_NOT_EMPTY); |
934 | return 0; | |
935 | } | |
936 | ||
937 | int ExynosCameraHWInterface2::setFrameQueueDstOps(const camera2_frame_queue_dst_ops_t *frame_dst_ops) | |
938 | { | |
13d8c7b4 | 939 | ALOGV("DEBUG(%s):", __FUNCTION__); |
c15a6b00 JS |
940 | if ((NULL != frame_dst_ops) && (NULL != frame_dst_ops->dequeue_frame) |
941 | && (NULL != frame_dst_ops->cancel_frame) && (NULL !=frame_dst_ops->enqueue_frame)) { | |
942 | m_frameQueueOps = (camera2_frame_queue_dst_ops_t *)frame_dst_ops; | |
943 | return 0; | |
944 | } | |
945 | else { | |
13d8c7b4 | 946 | ALOGE("DEBUG(%s):setFrameQueueDstOps : NULL arguments", __FUNCTION__); |
c15a6b00 JS |
947 | return 1; |
948 | } | |
949 | } | |
950 | ||
951 | int ExynosCameraHWInterface2::getInProgressCount() | |
952 | { | |
953 | int inProgressCount = m_requestManager->GetNumEntries(); | |
13d8c7b4 | 954 | ALOGV("DEBUG(%s): # of dequeued req (%d)", __FUNCTION__, inProgressCount); |
c15a6b00 JS |
955 | return inProgressCount; |
956 | } | |
957 | ||
958 | int ExynosCameraHWInterface2::flushCapturesInProgress() | |
959 | { | |
960 | return 0; | |
961 | } | |
962 | ||
c15a6b00 JS |
963 | int ExynosCameraHWInterface2::constructDefaultRequest(int request_template, camera_metadata_t **request) |
964 | { | |
13d8c7b4 | 965 | ALOGV("DEBUG(%s): making template (%d) ", __FUNCTION__, request_template); |
c15a6b00 JS |
966 | |
967 | if (request == NULL) return BAD_VALUE; | |
968 | if (request_template < 0 || request_template >= CAMERA2_TEMPLATE_COUNT) { | |
969 | return BAD_VALUE; | |
970 | } | |
971 | status_t res; | |
972 | // Pass 1, calculate size and allocate | |
973 | res = constructDefaultRequestInternal(request_template, | |
974 | request, | |
975 | true); | |
976 | if (res != OK) { | |
977 | return res; | |
978 | } | |
979 | // Pass 2, build request | |
980 | res = constructDefaultRequestInternal(request_template, | |
981 | request, | |
982 | false); | |
983 | if (res != OK) { | |
984 | ALOGE("Unable to populate new request for template %d", | |
985 | request_template); | |
986 | } | |
987 | ||
988 | return res; | |
989 | } | |
990 | ||
991 | int ExynosCameraHWInterface2::allocateStream(uint32_t width, uint32_t height, int format, const camera2_stream_ops_t *stream_ops, | |
992 | uint32_t *stream_id, uint32_t *format_actual, uint32_t *usage, uint32_t *max_buffers) | |
993 | { | |
13d8c7b4 | 994 | ALOGD("DEBUG(%s): allocate stream width(%d) height(%d) format(%x)", __FUNCTION__, width, height, format); |
c15a6b00 | 995 | char node_name[30]; |
9dd63e1f | 996 | int fd = 0, allocCase = 0; |
13d8c7b4 SK |
997 | StreamThread *AllocatedStream; |
998 | stream_parameters_t newParameters; | |
c15a6b00 | 999 | |
9dd63e1f SK |
1000 | if ((format == CAMERA2_HAL_PIXEL_FORMAT_OPAQUE && |
1001 | isSupportedPreviewSize(m_cameraId, width, height))) { | |
1002 | if (!(m_streamThreads[0].get())) { | |
1003 | ALOGV("DEBUG(%s): stream 0 not exist", __FUNCTION__); | |
1004 | allocCase = 0; | |
13d8c7b4 SK |
1005 | } |
1006 | else { | |
9dd63e1f SK |
1007 | if ((m_streamThreads[0].get())->m_activated == TRUE) { |
1008 | ALOGV("DEBUG(%s): stream 0 exists and activated.", __FUNCTION__); | |
1009 | allocCase = 1; | |
1010 | } | |
1011 | else { | |
1012 | ALOGV("DEBUG(%s): stream 0 exists and deactivated.", __FUNCTION__); | |
1013 | allocCase = 2; | |
1014 | } | |
13d8c7b4 | 1015 | } |
9dd63e1f SK |
1016 | if (allocCase == 0 || allocCase == 2) { |
1017 | *stream_id = 0; | |
1018 | ||
1019 | if (allocCase == 0) { | |
1020 | m_streamThreads[0] = new StreamThread(this, *stream_id); | |
1021 | ||
1022 | ||
1023 | memset(&node_name, 0x00, sizeof(char[30])); | |
1024 | sprintf(node_name, "%s%d", NODE_PREFIX, 44); | |
1025 | fd = exynos_v4l2_open(node_name, O_RDWR, 0); | |
1026 | if (fd < 0) { | |
1027 | ALOGE("DEBUG(%s): failed to open preview video node (%s) fd (%d)", __FUNCTION__,node_name, fd); | |
1028 | } | |
1029 | else { | |
1030 | ALOGV("DEBUG(%s): preview video node opened(%s) fd (%d)", __FUNCTION__,node_name, fd); | |
1031 | } | |
1032 | m_fd_scp = fd; | |
1033 | } | |
1034 | AllocatedStream = (StreamThread*)(m_streamThreads[0].get()); | |
b5237e6b SK |
1035 | m_scp_flushing = false; |
1036 | m_scp_closing = false; | |
1037 | m_scp_closed = false; | |
9dd63e1f SK |
1038 | usleep(100000); // TODO : guarantee the codes below will be run after readyToRunInternal() |
1039 | ||
1040 | *format_actual = HAL_PIXEL_FORMAT_YV12; | |
1041 | *usage = GRALLOC_USAGE_SW_WRITE_OFTEN | GRALLOC_USAGE_YUV_ADDR; | |
1042 | *max_buffers = 8; | |
1043 | ||
1044 | newParameters.streamType = 0; | |
1045 | newParameters.outputWidth = width; | |
1046 | newParameters.outputHeight = height; | |
1047 | newParameters.nodeWidth = width; | |
1048 | newParameters.nodeHeight = height; | |
1049 | newParameters.outputFormat = *format_actual; | |
1050 | newParameters.nodeFormat = HAL_PIXEL_FORMAT_2_V4L2_PIX(*format_actual); | |
1051 | newParameters.streamOps = stream_ops; | |
1052 | newParameters.usage = *usage; | |
1053 | newParameters.numHwBuffers = *max_buffers; | |
1054 | newParameters.fd = m_fd_scp; | |
1055 | newParameters.nodePlanes = 3; | |
1056 | newParameters.svcPlanes = 3; | |
1057 | newParameters.halBuftype = V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE; | |
1058 | newParameters.memory = V4L2_MEMORY_DMABUF; | |
1059 | newParameters.ionClient = m_ionCameraClient; | |
1060 | AllocatedStream->m_index = *stream_id; | |
1061 | AllocatedStream->setParameter(&newParameters); | |
1062 | AllocatedStream->m_activated = true; | |
13d8c7b4 | 1063 | |
9dd63e1f SK |
1064 | m_scp_flushing = false; |
1065 | m_scp_closing = false; | |
1066 | m_scp_closed = false; | |
1067 | m_requestManager->SetDefaultParameters(width); | |
1068 | m_camera_info.dummy_shot.shot.ctl.scaler.cropRegion[2] = width; | |
1069 | return 0; | |
1070 | } | |
1071 | else if (allocCase == 1) { | |
1072 | record_parameters_t recordParameters; | |
1073 | StreamThread *parentStream; | |
1074 | parentStream = (StreamThread*)(m_streamThreads[0].get()); | |
1075 | if (!parentStream) { | |
1076 | return 1; | |
1077 | // TODO | |
1078 | } | |
1079 | *stream_id = 2; | |
1080 | usleep(100000); // TODO : guarantee the codes below will be run after readyToRunInternal() | |
1081 | ||
1082 | *format_actual = HAL_PIXEL_FORMAT_RGBA_8888; | |
1083 | *usage = GRALLOC_USAGE_SW_WRITE_OFTEN | GRALLOC_USAGE_YUV_ADDR; | |
1084 | *max_buffers = 10; | |
1085 | ||
1086 | recordParameters.outputWidth = width; | |
1087 | recordParameters.outputHeight = height; | |
1088 | recordParameters.outputFormat = *format_actual; | |
1089 | recordParameters.svcPlanes = 1; | |
1090 | recordParameters.streamOps = stream_ops; | |
1091 | recordParameters.usage = *usage; | |
1092 | recordParameters.numBufsInHal = 0; | |
1093 | ||
1094 | parentStream->setRecordingParameter(&recordParameters); | |
1095 | m_scp_flushing = false; | |
1096 | m_scp_closing = false; | |
1097 | m_scp_closed = false; | |
1098 | m_recordingEnabled = true; | |
1099 | return 0; | |
1100 | } | |
13d8c7b4 | 1101 | } |
9dd63e1f SK |
1102 | else if (format == HAL_PIXEL_FORMAT_BLOB |
1103 | && isSupportedJpegSize(m_cameraId, width, height)) { | |
13d8c7b4 SK |
1104 | |
1105 | *stream_id = 1; | |
1106 | ||
1107 | m_streamThreads[1] = new StreamThread(this, *stream_id); | |
1108 | AllocatedStream = (StreamThread*)(m_streamThreads[1].get()); | |
9dd63e1f | 1109 | |
13d8c7b4 SK |
1110 | fd = m_camera_info.capture.fd; |
1111 | usleep(100000); // TODO : guarantee the codes below will be run after readyToRunInternal() | |
1112 | ||
1113 | *format_actual = HAL_PIXEL_FORMAT_BLOB; | |
1114 | ||
1115 | *usage = GRALLOC_USAGE_SW_WRITE_OFTEN; | |
1116 | *max_buffers = 8; | |
1117 | ||
1118 | newParameters.streamType = 1; | |
1119 | newParameters.outputWidth = width; | |
1120 | newParameters.outputHeight = height; | |
9dd63e1f SK |
1121 | |
1122 | newParameters.nodeWidth = getSccOutputSizeX(m_cameraId); | |
1123 | newParameters.nodeHeight = getSccOutputSizeY(m_cameraId); | |
1124 | ||
13d8c7b4 SK |
1125 | newParameters.outputFormat = *format_actual; |
1126 | newParameters.nodeFormat = V4L2_PIX_FMT_YUYV; | |
1127 | newParameters.streamOps = stream_ops; | |
1128 | newParameters.usage = *usage; | |
1129 | newParameters.numHwBuffers = *max_buffers; | |
1130 | newParameters.fd = fd; | |
1131 | newParameters.nodePlanes = 1; | |
1132 | newParameters.svcPlanes = 1; | |
1133 | newParameters.halBuftype = V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE; | |
1134 | newParameters.memory = V4L2_MEMORY_DMABUF; | |
1135 | newParameters.ionClient = m_ionCameraClient; | |
9dd63e1f | 1136 | AllocatedStream->m_index = *stream_id; |
13d8c7b4 SK |
1137 | AllocatedStream->setParameter(&newParameters); |
1138 | return 0; | |
1139 | } | |
1140 | ALOGE("DEBUG(%s): Unsupported Pixel Format", __FUNCTION__); | |
1141 | return 1; // TODO : check proper error code | |
c15a6b00 JS |
1142 | } |
1143 | ||
13d8c7b4 SK |
1144 | int ExynosCameraHWInterface2::registerStreamBuffers(uint32_t stream_id, |
1145 | int num_buffers, buffer_handle_t *registeringBuffers) | |
c15a6b00 | 1146 | { |
13d8c7b4 SK |
1147 | int i,j; |
1148 | void *virtAddr[3]; | |
1149 | uint32_t plane_index = 0; | |
1150 | stream_parameters_t *targetStreamParms; | |
9dd63e1f | 1151 | record_parameters_t *targetRecordParms; |
13d8c7b4 SK |
1152 | node_info_t *currentNode; |
1153 | ||
c15a6b00 JS |
1154 | struct v4l2_buffer v4l2_buf; |
1155 | struct v4l2_plane planes[VIDEO_MAX_PLANES]; | |
13d8c7b4 SK |
1156 | |
1157 | ALOGV("DEBUG(%s): streamID (%d), num_buff(%d), handle(%x) ", __FUNCTION__, | |
1158 | stream_id, num_buffers, (uint32_t)registeringBuffers); | |
1159 | ||
c15a6b00 | 1160 | if (stream_id == 0) { |
13d8c7b4 SK |
1161 | targetStreamParms = &(m_streamThreads[0]->m_parameters); |
1162 | } | |
1163 | else if (stream_id == 1) { | |
1164 | targetStreamParms = &(m_streamThreads[1]->m_parameters); | |
1165 | } | |
9dd63e1f SK |
1166 | else if (stream_id == 2) { |
1167 | targetRecordParms = &(m_streamThreads[0]->m_recordParameters); | |
1168 | ||
1169 | targetRecordParms->numSvcBuffers = num_buffers; | |
1170 | ||
1171 | for (i = 0 ; i<targetRecordParms->numSvcBuffers ; i++) { | |
1172 | ALOGV("DEBUG(%s): registering Stream Buffers[%d] (%x) ", __FUNCTION__, | |
1173 | i, (uint32_t)(registeringBuffers[i])); | |
1174 | if (m_grallocHal) { | |
1175 | if (m_grallocHal->lock(m_grallocHal, registeringBuffers[i], | |
1176 | targetRecordParms->usage, 0, 0, | |
1177 | targetRecordParms->outputWidth, targetRecordParms->outputHeight, virtAddr) != 0) { | |
1178 | ALOGE("ERR(%s): could not obtain gralloc buffer", __FUNCTION__); | |
1179 | } | |
1180 | else { | |
1181 | ExynosBuffer currentBuf; | |
1182 | const private_handle_t *priv_handle = reinterpret_cast<const private_handle_t *>(registeringBuffers[i]); | |
b5237e6b SK |
1183 | //m_getAlignedYUVSize(HAL_PIXEL_FORMAT_2_V4L2_PIX(targetRecordParms->outputFormat), |
1184 | // targetRecordParms->outputWidth, targetRecordParms->outputHeight, ¤tBuf); | |
9dd63e1f SK |
1185 | currentBuf.fd.extFd[0] = priv_handle->fd; |
1186 | currentBuf.fd.extFd[1] = priv_handle->u_fd; | |
1187 | currentBuf.fd.extFd[2] = priv_handle->v_fd; | |
1188 | ALOGV("DEBUG(%s): yddr(%x), uoffset(%d), voffset(%d)", __FUNCTION__,priv_handle->yaddr, priv_handle->uoffset, priv_handle->voffset); | |
1189 | ALOGV("DEBUG(%s): ion_size(%d), stride(%d), ", __FUNCTION__,priv_handle->size, priv_handle->stride); | |
1190 | for (plane_index=0 ; plane_index < targetRecordParms->svcPlanes ; plane_index++) { | |
1191 | currentBuf.virt.extP[plane_index] = (char *)virtAddr[plane_index]; | |
1192 | ALOGV("DEBUG(%s): plane(%d): fd(%d) addr(%x)", | |
1193 | __FUNCTION__, plane_index, currentBuf.fd.extFd[i], | |
1194 | (unsigned int)currentBuf.virt.extP[plane_index]); | |
1195 | } | |
1196 | targetRecordParms->svcBufStatus[i] = ON_SERVICE; | |
b5237e6b SK |
1197 | targetRecordParms->svcBuffers[i] = currentBuf; |
1198 | targetRecordParms->svcBufHandle[i] = registeringBuffers[i]; | |
9dd63e1f SK |
1199 | } |
1200 | } | |
1201 | } | |
1202 | m_needsRecordBufferInit = true; | |
1203 | return 0; | |
1204 | } | |
13d8c7b4 SK |
1205 | else { |
1206 | ALOGE("ERR(%s) unregisterd stream id (%d)", __FUNCTION__, stream_id); | |
1207 | return 1; // TODO : proper error code? | |
1208 | } | |
c15a6b00 | 1209 | |
13d8c7b4 SK |
1210 | if (targetStreamParms->streamType ==0) { |
1211 | if (num_buffers < targetStreamParms->numHwBuffers) { | |
1212 | ALOGE("ERR(%s) registering insufficient num of buffers (%d) < (%d)", | |
1213 | __FUNCTION__, num_buffers, targetStreamParms->numHwBuffers); | |
1214 | return 1; // TODO : proper error code? | |
1215 | } | |
1216 | } | |
1217 | ALOGV("DEBUG(%s): format(%x) width(%d), height(%d) svcPlanes(%d)", | |
1218 | __FUNCTION__, targetStreamParms->outputFormat, targetStreamParms->outputWidth, | |
1219 | targetStreamParms->outputHeight, targetStreamParms->svcPlanes); | |
1220 | ||
1221 | targetStreamParms->numSvcBuffers = num_buffers; | |
1222 | currentNode = &(targetStreamParms->node); // TO Remove | |
1223 | ||
1224 | currentNode->fd = targetStreamParms->fd; | |
1225 | currentNode->width = targetStreamParms->nodeWidth; | |
1226 | currentNode->height = targetStreamParms->nodeHeight; | |
1227 | currentNode->format = targetStreamParms->nodeFormat; | |
1228 | currentNode->planes = targetStreamParms->nodePlanes; | |
1229 | currentNode->buffers = targetStreamParms->numHwBuffers; | |
1230 | currentNode->type = targetStreamParms->halBuftype; | |
1231 | currentNode->memory = targetStreamParms->memory; | |
1232 | currentNode->ionClient = targetStreamParms->ionClient; | |
1233 | ||
1234 | if (targetStreamParms->streamType == 0) { | |
1235 | cam_int_s_input(currentNode, m_camera_info.sensor_id); | |
1236 | cam_int_s_fmt(currentNode); | |
1237 | cam_int_reqbufs(currentNode); | |
1238 | } | |
1239 | else if (targetStreamParms->streamType == 1) { | |
1240 | for(i = 0; i < currentNode->buffers; i++){ | |
1241 | memcpy(&(currentNode->buffer[i]), &(m_camera_info.capture.buffer[i]), sizeof(ExynosBuffer)); | |
1242 | } | |
1243 | } | |
1244 | ||
1245 | for (i = 0 ; i<targetStreamParms->numSvcBuffers ; i++) { | |
1246 | ALOGV("DEBUG(%s): registering Stream Buffers[%d] (%x) ", __FUNCTION__, | |
1247 | i, (uint32_t)(registeringBuffers[i])); | |
1248 | if (m_grallocHal) { | |
1249 | if (m_grallocHal->lock(m_grallocHal, registeringBuffers[i], | |
1250 | targetStreamParms->usage, 0, 0, | |
1251 | currentNode->width, currentNode->height, virtAddr) != 0) { | |
1252 | ALOGE("ERR(%s): could not obtain gralloc buffer", __FUNCTION__); | |
1253 | } | |
1254 | else { | |
1255 | v4l2_buf.m.planes = planes; | |
1256 | v4l2_buf.type = currentNode->type; | |
1257 | v4l2_buf.memory = currentNode->memory; | |
1258 | v4l2_buf.index = i; | |
1259 | v4l2_buf.length = currentNode->planes; | |
c15a6b00 | 1260 | |
13d8c7b4 SK |
1261 | ExynosBuffer currentBuf; |
1262 | const private_handle_t *priv_handle = reinterpret_cast<const private_handle_t *>(registeringBuffers[i]); | |
1263 | ||
1264 | m_getAlignedYUVSize(currentNode->format, | |
1265 | currentNode->width, currentNode->height, ¤tBuf); | |
24231221 | 1266 | |
9dd63e1f SK |
1267 | v4l2_buf.m.planes[0].m.fd = priv_handle->fd; |
1268 | v4l2_buf.m.planes[2].m.fd = priv_handle->u_fd; | |
1269 | v4l2_buf.m.planes[1].m.fd = priv_handle->v_fd; | |
1270 | currentBuf.fd.extFd[0] = priv_handle->fd; | |
1271 | currentBuf.fd.extFd[2] = priv_handle->u_fd; | |
1272 | currentBuf.fd.extFd[1] = priv_handle->v_fd; | |
1273 | ALOGV("DEBUG(%s): yddr(%x), uoffset(%d), voffset(%d)", __FUNCTION__,priv_handle->yaddr, priv_handle->uoffset, priv_handle->voffset); | |
1274 | ALOGV("DEBUG(%s): ion_size(%d), stride(%d), ", __FUNCTION__,priv_handle->size, priv_handle->stride); | |
1275 | ||
1276 | ||
13d8c7b4 | 1277 | for (plane_index=0 ; plane_index < v4l2_buf.length ; plane_index++) { |
13d8c7b4 SK |
1278 | currentBuf.virt.extP[plane_index] = (char *)virtAddr[plane_index]; |
1279 | v4l2_buf.m.planes[plane_index].length = currentBuf.size.extS[plane_index]; | |
1280 | ALOGV("DEBUG(%s): plane(%d): fd(%d) addr(%x), length(%d)", | |
1281 | __FUNCTION__, plane_index, v4l2_buf.m.planes[plane_index].m.fd, | |
1282 | (unsigned int)currentBuf.virt.extP[plane_index], | |
1283 | v4l2_buf.m.planes[plane_index].length); | |
1284 | } | |
c15a6b00 | 1285 | |
13d8c7b4 SK |
1286 | if (targetStreamParms->streamType == 0) { |
1287 | if (i < currentNode->buffers) { | |
1288 | if (exynos_v4l2_qbuf(currentNode->fd, &v4l2_buf) < 0) { | |
9dd63e1f SK |
1289 | ALOGE("ERR(%s): stream id(%d) exynos_v4l2_qbuf() fail fd(%d)", |
1290 | __FUNCTION__, stream_id, currentNode->fd); | |
1291 | //return false; | |
13d8c7b4 | 1292 | } |
9dd63e1f SK |
1293 | ALOGV("DEBUG(%s): stream id(%d) exynos_v4l2_qbuf() success fd(%d)", |
1294 | __FUNCTION__, stream_id, currentNode->fd); | |
13d8c7b4 SK |
1295 | targetStreamParms->svcBufStatus[i] = REQUIRES_DQ_FROM_SVC; |
1296 | } | |
1297 | else { | |
1298 | targetStreamParms->svcBufStatus[i] = ON_SERVICE; | |
1299 | } | |
1300 | } | |
1301 | else if (targetStreamParms->streamType == 1) { | |
1302 | targetStreamParms->svcBufStatus[i] = ON_SERVICE; | |
c15a6b00 | 1303 | } |
13d8c7b4 SK |
1304 | targetStreamParms->svcBuffers[i] = currentBuf; |
1305 | targetStreamParms->svcBufHandle[i] = registeringBuffers[i]; | |
1306 | } | |
c15a6b00 | 1307 | } |
c15a6b00 | 1308 | } |
9dd63e1f SK |
1309 | ALOGV("DEBUG(%s): calling streamon", __FUNCTION__); |
1310 | cam_int_streamon(&(targetStreamParms->node)); | |
1311 | ALOGV("DEBUG(%s): calling streamon END", __FUNCTION__); | |
13d8c7b4 | 1312 | ALOGV("DEBUG(%s): END registerStreamBuffers", __FUNCTION__); |
c15a6b00 JS |
1313 | return 0; |
1314 | } | |
1315 | ||
1316 | int ExynosCameraHWInterface2::releaseStream(uint32_t stream_id) | |
1317 | { | |
13d8c7b4 SK |
1318 | StreamThread *targetStream; |
1319 | ALOGV("DEBUG(%s):", __FUNCTION__); | |
1320 | ||
b5237e6b | 1321 | if (stream_id == 0) { |
13d8c7b4 | 1322 | targetStream = (StreamThread*)(m_streamThreads[0].get()); |
9dd63e1f | 1323 | m_scp_flushing = true; |
13d8c7b4 | 1324 | } |
b5237e6b | 1325 | else if (stream_id == 1) { |
13d8c7b4 SK |
1326 | targetStream = (StreamThread*)(m_streamThreads[1].get()); |
1327 | } | |
b5237e6b SK |
1328 | else if (stream_id == 2 && m_recordingEnabled) { |
1329 | m_recordingEnabled = false; | |
1330 | return 0; | |
1331 | } | |
13d8c7b4 SK |
1332 | else { |
1333 | ALOGE("ERR:(%s): wrong stream id (%d)", __FUNCTION__, stream_id); | |
1334 | return 1; // TODO : proper error code? | |
1335 | } | |
1336 | ||
b5237e6b | 1337 | targetStream->m_releasing = true; |
13d8c7b4 | 1338 | targetStream->release(); |
b5237e6b SK |
1339 | while (targetStream->m_releasing) |
1340 | usleep(2000); | |
9dd63e1f | 1341 | targetStream->m_activated = false; |
13d8c7b4 | 1342 | ALOGV("DEBUG(%s): DONE", __FUNCTION__); |
c15a6b00 JS |
1343 | return 0; |
1344 | } | |
1345 | ||
1346 | int ExynosCameraHWInterface2::allocateReprocessStream( | |
13d8c7b4 SK |
1347 | uint32_t width, uint32_t height, uint32_t format, |
1348 | const camera2_stream_in_ops_t *reprocess_stream_ops, | |
c15a6b00 JS |
1349 | uint32_t *stream_id, uint32_t *consumer_usage, uint32_t *max_buffers) |
1350 | { | |
13d8c7b4 | 1351 | ALOGV("DEBUG(%s):", __FUNCTION__); |
c15a6b00 JS |
1352 | return 0; |
1353 | } | |
1354 | ||
1355 | int ExynosCameraHWInterface2::releaseReprocessStream(uint32_t stream_id) | |
1356 | { | |
13d8c7b4 | 1357 | ALOGV("DEBUG(%s):", __FUNCTION__); |
c15a6b00 JS |
1358 | return 0; |
1359 | } | |
1360 | ||
1361 | int ExynosCameraHWInterface2::triggerAction(uint32_t trigger_id, int ext1, int ext2) | |
1362 | { | |
13d8c7b4 | 1363 | ALOGV("DEBUG(%s):", __FUNCTION__); |
c15a6b00 JS |
1364 | return 0; |
1365 | } | |
1366 | ||
1367 | int ExynosCameraHWInterface2::setNotifyCallback(camera2_notify_callback notify_cb, void *user) | |
1368 | { | |
13d8c7b4 | 1369 | ALOGV("DEBUG(%s):", __FUNCTION__); |
c15a6b00 JS |
1370 | m_notifyCb = notify_cb; |
1371 | m_callbackCookie = user; | |
1372 | return 0; | |
1373 | } | |
1374 | ||
1375 | int ExynosCameraHWInterface2::getMetadataVendorTagOps(vendor_tag_query_ops_t **ops) | |
1376 | { | |
13d8c7b4 | 1377 | ALOGV("DEBUG(%s):", __FUNCTION__); |
c15a6b00 JS |
1378 | return 0; |
1379 | } | |
1380 | ||
1381 | int ExynosCameraHWInterface2::dump(int fd) | |
1382 | { | |
13d8c7b4 | 1383 | ALOGV("DEBUG(%s):", __FUNCTION__); |
c15a6b00 JS |
1384 | return 0; |
1385 | } | |
1386 | ||
13d8c7b4 SK |
1387 | void ExynosCameraHWInterface2::m_getAlignedYUVSize(int colorFormat, int w, int h, ExynosBuffer *buf) |
1388 | { | |
1389 | switch (colorFormat) { | |
1390 | // 1p | |
1391 | case V4L2_PIX_FMT_RGB565 : | |
1392 | case V4L2_PIX_FMT_YUYV : | |
1393 | case V4L2_PIX_FMT_UYVY : | |
1394 | case V4L2_PIX_FMT_VYUY : | |
1395 | case V4L2_PIX_FMT_YVYU : | |
1396 | buf->size.extS[0] = FRAME_SIZE(V4L2_PIX_2_HAL_PIXEL_FORMAT(colorFormat), w, h); | |
1397 | buf->size.extS[1] = 0; | |
1398 | buf->size.extS[2] = 0; | |
1399 | break; | |
1400 | // 2p | |
1401 | case V4L2_PIX_FMT_NV12 : | |
1402 | case V4L2_PIX_FMT_NV12T : | |
1403 | case V4L2_PIX_FMT_NV21 : | |
1404 | buf->size.extS[0] = ALIGN(w, 16) * ALIGN(h, 16); | |
1405 | buf->size.extS[1] = ALIGN(w/2, 16) * ALIGN(h/2, 16); | |
1406 | buf->size.extS[2] = 0; | |
1407 | break; | |
1408 | case V4L2_PIX_FMT_NV12M : | |
1409 | case V4L2_PIX_FMT_NV12MT_16X16 : | |
9dd63e1f | 1410 | case V4L2_PIX_FMT_NV21M: |
13d8c7b4 SK |
1411 | buf->size.extS[0] = ALIGN(w, 16) * ALIGN(h, 16); |
1412 | buf->size.extS[1] = ALIGN(buf->size.extS[0] / 2, 256); | |
1413 | buf->size.extS[2] = 0; | |
1414 | break; | |
1415 | case V4L2_PIX_FMT_NV16 : | |
1416 | case V4L2_PIX_FMT_NV61 : | |
1417 | buf->size.extS[0] = ALIGN(w, 16) * ALIGN(h, 16); | |
1418 | buf->size.extS[1] = ALIGN(w, 16) * ALIGN(h, 16); | |
1419 | buf->size.extS[2] = 0; | |
1420 | break; | |
1421 | // 3p | |
1422 | case V4L2_PIX_FMT_YUV420 : | |
1423 | case V4L2_PIX_FMT_YVU420 : | |
1424 | buf->size.extS[0] = (w * h); | |
1425 | buf->size.extS[1] = (w * h) >> 2; | |
1426 | buf->size.extS[2] = (w * h) >> 2; | |
1427 | break; | |
1428 | case V4L2_PIX_FMT_YUV420M: | |
1429 | case V4L2_PIX_FMT_YVU420M : | |
1430 | case V4L2_PIX_FMT_YUV422P : | |
1431 | buf->size.extS[0] = ALIGN(w, 32) * ALIGN(h, 16); | |
1432 | buf->size.extS[1] = ALIGN(w/2, 16) * ALIGN(h/2, 8); | |
1433 | buf->size.extS[2] = ALIGN(w/2, 16) * ALIGN(h/2, 8); | |
1434 | break; | |
1435 | default: | |
1436 | ALOGE("ERR(%s):unmatched colorFormat(%d)", __FUNCTION__, colorFormat); | |
1437 | return; | |
1438 | break; | |
1439 | } | |
1440 | } | |
c15a6b00 | 1441 | |
13d8c7b4 SK |
1442 | bool ExynosCameraHWInterface2::m_getRatioSize(int src_w, int src_h, |
1443 | int dst_w, int dst_h, | |
1444 | int *crop_x, int *crop_y, | |
1445 | int *crop_w, int *crop_h, | |
1446 | int zoom) | |
c15a6b00 | 1447 | { |
13d8c7b4 SK |
1448 | *crop_w = src_w; |
1449 | *crop_h = src_h; | |
1450 | ||
1451 | if ( src_w != dst_w | |
1452 | || src_h != dst_h) { | |
1453 | float src_ratio = 1.0f; | |
1454 | float dst_ratio = 1.0f; | |
1455 | ||
1456 | // ex : 1024 / 768 | |
1457 | src_ratio = (float)src_w / (float)src_h; | |
1458 | ||
1459 | // ex : 352 / 288 | |
1460 | dst_ratio = (float)dst_w / (float)dst_h; | |
1461 | ||
1462 | if (dst_w * dst_h < src_w * src_h) { | |
1463 | if (dst_ratio <= src_ratio) { | |
1464 | // shrink w | |
1465 | *crop_w = src_h * dst_ratio; | |
1466 | *crop_h = src_h; | |
1467 | } else { | |
1468 | // shrink h | |
1469 | *crop_w = src_w; | |
1470 | *crop_h = src_w / dst_ratio; | |
c15a6b00 | 1471 | } |
13d8c7b4 SK |
1472 | } else { |
1473 | if (dst_ratio <= src_ratio) { | |
1474 | // shrink w | |
1475 | *crop_w = src_h * dst_ratio; | |
1476 | *crop_h = src_h; | |
1477 | } else { | |
1478 | // shrink h | |
1479 | *crop_w = src_w; | |
1480 | *crop_h = src_w / dst_ratio; | |
c15a6b00 JS |
1481 | } |
1482 | } | |
c15a6b00 JS |
1483 | } |
1484 | ||
13d8c7b4 SK |
1485 | if (zoom != 0) { |
1486 | float zoomLevel = ((float)zoom + 10.0) / 10.0; | |
1487 | *crop_w = (int)((float)*crop_w / zoomLevel); | |
1488 | *crop_h = (int)((float)*crop_h / zoomLevel); | |
1489 | } | |
1490 | ||
1491 | #define CAMERA_CROP_WIDTH_RESTRAIN_NUM (0x2) | |
1492 | unsigned int w_align = (*crop_w & (CAMERA_CROP_WIDTH_RESTRAIN_NUM - 1)); | |
1493 | if (w_align != 0) { | |
1494 | if ( (CAMERA_CROP_WIDTH_RESTRAIN_NUM >> 1) <= w_align | |
1495 | && *crop_w + (CAMERA_CROP_WIDTH_RESTRAIN_NUM - w_align) <= dst_w) { | |
1496 | *crop_w += (CAMERA_CROP_WIDTH_RESTRAIN_NUM - w_align); | |
1497 | } | |
1498 | else | |
1499 | *crop_w -= w_align; | |
1500 | } | |
1501 | ||
1502 | #define CAMERA_CROP_HEIGHT_RESTRAIN_NUM (0x2) | |
1503 | unsigned int h_align = (*crop_h & (CAMERA_CROP_HEIGHT_RESTRAIN_NUM - 1)); | |
1504 | if (h_align != 0) { | |
1505 | if ( (CAMERA_CROP_HEIGHT_RESTRAIN_NUM >> 1) <= h_align | |
1506 | && *crop_h + (CAMERA_CROP_HEIGHT_RESTRAIN_NUM - h_align) <= dst_h) { | |
1507 | *crop_h += (CAMERA_CROP_HEIGHT_RESTRAIN_NUM - h_align); | |
1508 | } | |
1509 | else | |
1510 | *crop_h -= h_align; | |
1511 | } | |
1512 | ||
1513 | *crop_x = (src_w - *crop_w) >> 1; | |
1514 | *crop_y = (src_h - *crop_h) >> 1; | |
1515 | ||
1516 | if (*crop_x & (CAMERA_CROP_WIDTH_RESTRAIN_NUM >> 1)) | |
1517 | *crop_x -= 1; | |
1518 | ||
1519 | if (*crop_y & (CAMERA_CROP_HEIGHT_RESTRAIN_NUM >> 1)) | |
1520 | *crop_y -= 1; | |
1521 | ||
1522 | return true; | |
1523 | } | |
1524 | ||
9dd63e1f | 1525 | BayerBufManager::BayerBufManager() |
13d8c7b4 | 1526 | { |
9dd63e1f SK |
1527 | ALOGV("DEBUG(%s): ", __FUNCTION__); |
1528 | for (int i = 0; i < NUM_BAYER_BUFFERS ; i++) { | |
1529 | entries[i].status = BAYER_ON_HAL_EMPTY; | |
1530 | entries[i].reqFrameCnt = 0; | |
13d8c7b4 | 1531 | } |
9dd63e1f SK |
1532 | sensorEnqueueHead = 0; |
1533 | sensorDequeueHead = 0; | |
1534 | ispEnqueueHead = 0; | |
1535 | ispDequeueHead = 0; | |
1536 | numOnSensor = 0; | |
1537 | numOnIsp = 0; | |
1538 | numOnHalFilled = 0; | |
1539 | numOnHalEmpty = NUM_BAYER_BUFFERS; | |
13d8c7b4 SK |
1540 | } |
1541 | ||
9dd63e1f | 1542 | int BayerBufManager::GetIndexForSensorEnqueue() |
13d8c7b4 | 1543 | { |
9dd63e1f SK |
1544 | int ret = 0; |
1545 | if (numOnHalEmpty == 0) | |
1546 | ret = -1; | |
1547 | else | |
1548 | ret = sensorEnqueueHead; | |
1549 | ALOGV("DEBUG(%s): returning (%d)", __FUNCTION__, ret); | |
1550 | return ret; | |
13d8c7b4 SK |
1551 | } |
1552 | ||
9dd63e1f | 1553 | int BayerBufManager::MarkSensorEnqueue(int index) |
13d8c7b4 | 1554 | { |
9dd63e1f SK |
1555 | ALOGV("DEBUG(%s) : BayerIndex[%d] ", __FUNCTION__, index); |
1556 | ||
1557 | // sanity check | |
1558 | if (index != sensorEnqueueHead) { | |
1559 | ALOGV("DEBUG(%s) : Abnormal BayerIndex[%d] - expected[%d]", __FUNCTION__, index, sensorEnqueueHead); | |
1560 | return -1; | |
1561 | } | |
1562 | if (entries[index].status != BAYER_ON_HAL_EMPTY) { | |
1563 | ALOGV("DEBUG(%s) : Abnormal status in BayerIndex[%d] = (%d) expected (%d)", __FUNCTION__, | |
1564 | index, entries[index].status, BAYER_ON_HAL_EMPTY); | |
1565 | return -1; | |
13d8c7b4 | 1566 | } |
13d8c7b4 | 1567 | |
9dd63e1f SK |
1568 | entries[index].status = BAYER_ON_SENSOR; |
1569 | entries[index].reqFrameCnt = 0; | |
1570 | numOnHalEmpty--; | |
1571 | numOnSensor++; | |
1572 | sensorEnqueueHead = GetNextIndex(index); | |
1573 | ALOGV("DEBUG(%s) END: HAL-e(%d) HAL-f(%d) Sensor(%d) ISP(%d) ", | |
1574 | __FUNCTION__, numOnHalEmpty, numOnHalFilled, numOnSensor, numOnIsp); | |
1575 | return 0; | |
1576 | } | |
13d8c7b4 | 1577 | |
9dd63e1f | 1578 | int BayerBufManager::MarkSensorDequeue(int index, int reqFrameCnt, nsecs_t *timeStamp) |
13d8c7b4 | 1579 | { |
9dd63e1f SK |
1580 | ALOGV("DEBUG(%s) : BayerIndex[%d] reqFrameCnt(%d)", __FUNCTION__, index, reqFrameCnt); |
1581 | ||
1582 | // sanity check | |
1583 | if (index != sensorDequeueHead) { | |
1584 | ALOGV("DEBUG(%s) : Abnormal BayerIndex[%d] - expected[%d]", __FUNCTION__, index, sensorDequeueHead); | |
13d8c7b4 SK |
1585 | return -1; |
1586 | } | |
9dd63e1f SK |
1587 | if (entries[index].status != BAYER_ON_SENSOR) { |
1588 | ALOGV("DEBUG(%s) : Abnormal status in BayerIndex[%d] = (%d) expected (%d)", __FUNCTION__, | |
1589 | index, entries[index].status, BAYER_ON_SENSOR); | |
1590 | return -1; | |
13d8c7b4 | 1591 | } |
13d8c7b4 | 1592 | |
9dd63e1f SK |
1593 | entries[index].status = BAYER_ON_HAL_FILLED; |
1594 | entries[index].reqFrameCnt = reqFrameCnt; | |
1595 | entries[index].timeStamp = *timeStamp; | |
1596 | numOnHalFilled++; | |
1597 | numOnSensor--; | |
1598 | sensorDequeueHead = GetNextIndex(index); | |
1599 | ALOGV("DEBUG(%s) END: HAL-e(%d) HAL-f(%d) Sensor(%d) ISP(%d) ", | |
1600 | __FUNCTION__, numOnHalEmpty, numOnHalFilled, numOnSensor, numOnIsp); | |
1601 | return 0; | |
1602 | } | |
1603 | ||
1604 | int BayerBufManager::GetIndexForIspEnqueue(int *reqFrameCnt) | |
1605 | { | |
1606 | int ret = 0; | |
1607 | if (numOnHalFilled == 0) | |
1608 | ret = -1; | |
1609 | else { | |
1610 | *reqFrameCnt = entries[ispEnqueueHead].reqFrameCnt; | |
1611 | ret = ispEnqueueHead; | |
13d8c7b4 | 1612 | } |
9dd63e1f | 1613 | ALOGV("DEBUG(%s): returning BayerIndex[%d]", __FUNCTION__, ret); |
13d8c7b4 SK |
1614 | return ret; |
1615 | } | |
1616 | ||
9dd63e1f SK |
1617 | int BayerBufManager::GetIndexForIspDequeue(int *reqFrameCnt) |
1618 | { | |
1619 | int ret = 0; | |
1620 | if (numOnIsp == 0) | |
1621 | ret = -1; | |
1622 | else { | |
1623 | *reqFrameCnt = entries[ispDequeueHead].reqFrameCnt; | |
1624 | ret = ispDequeueHead; | |
1625 | } | |
1626 | ALOGV("DEBUG(%s): returning BayerIndex[%d]", __FUNCTION__, ret); | |
1627 | return ret; | |
1628 | } | |
13d8c7b4 | 1629 | |
9dd63e1f | 1630 | int BayerBufManager::MarkIspEnqueue(int index) |
13d8c7b4 | 1631 | { |
9dd63e1f SK |
1632 | ALOGV("DEBUG(%s) : BayerIndex[%d] ", __FUNCTION__, index); |
1633 | ||
1634 | // sanity check | |
1635 | if (index != ispEnqueueHead) { | |
1636 | ALOGV("DEBUG(%s) : Abnormal BayerIndex[%d] - expected[%d]", __FUNCTION__, index, ispEnqueueHead); | |
13d8c7b4 SK |
1637 | return -1; |
1638 | } | |
9dd63e1f SK |
1639 | if (entries[index].status != BAYER_ON_HAL_FILLED) { |
1640 | ALOGV("DEBUG(%s) : Abnormal status in BayerIndex[%d] = (%d) expected (%d)", __FUNCTION__, | |
1641 | index, entries[index].status, BAYER_ON_HAL_FILLED); | |
1642 | return -1; | |
13d8c7b4 SK |
1643 | } |
1644 | ||
9dd63e1f SK |
1645 | entries[index].status = BAYER_ON_ISP; |
1646 | numOnHalFilled--; | |
1647 | numOnIsp++; | |
1648 | ispEnqueueHead = GetNextIndex(index); | |
1649 | ALOGV("DEBUG(%s) END: HAL-e(%d) HAL-f(%d) Sensor(%d) ISP(%d) ", | |
1650 | __FUNCTION__, numOnHalEmpty, numOnHalFilled, numOnSensor, numOnIsp); | |
1651 | return 0; | |
1652 | } | |
1653 | ||
1654 | int BayerBufManager::MarkIspDequeue(int index) | |
1655 | { | |
1656 | ALOGV("DEBUG(%s) : BayerIndex[%d]", __FUNCTION__, index); | |
1657 | ||
1658 | // sanity check | |
1659 | if (index != ispDequeueHead) { | |
1660 | ALOGV("DEBUG(%s) : Abnormal BayerIndex[%d] - expected[%d]", __FUNCTION__, index, ispDequeueHead); | |
1661 | return -1; | |
13d8c7b4 | 1662 | } |
9dd63e1f SK |
1663 | if (entries[index].status != BAYER_ON_ISP) { |
1664 | ALOGV("DEBUG(%s) : Abnormal status in BayerIndex[%d] = (%d) expected (%d)", __FUNCTION__, | |
1665 | index, entries[index].status, BAYER_ON_ISP); | |
13d8c7b4 SK |
1666 | return -1; |
1667 | } | |
1668 | ||
9dd63e1f SK |
1669 | entries[index].status = BAYER_ON_HAL_EMPTY; |
1670 | entries[index].reqFrameCnt = 0; | |
1671 | numOnHalEmpty++; | |
1672 | numOnIsp--; | |
1673 | ispDequeueHead = GetNextIndex(index); | |
1674 | ALOGV("DEBUG(%s) END: HAL-e(%d) HAL-f(%d) Sensor(%d) ISP(%d) ", | |
1675 | __FUNCTION__, numOnHalEmpty, numOnHalFilled, numOnSensor, numOnIsp); | |
1676 | return 0; | |
1677 | } | |
13d8c7b4 | 1678 | |
9dd63e1f SK |
1679 | int BayerBufManager::GetNumOnSensor() |
1680 | { | |
1681 | return numOnSensor; | |
13d8c7b4 SK |
1682 | } |
1683 | ||
9dd63e1f | 1684 | int BayerBufManager::GetNumOnHalFilled() |
13d8c7b4 | 1685 | { |
9dd63e1f SK |
1686 | return numOnHalFilled; |
1687 | } | |
1688 | ||
1689 | int BayerBufManager::GetNumOnIsp() | |
1690 | { | |
1691 | return numOnIsp; | |
1692 | } | |
1693 | ||
1694 | int BayerBufManager::GetNextIndex(int index) | |
1695 | { | |
1696 | index++; | |
1697 | if (index >= NUM_BAYER_BUFFERS) | |
1698 | index = 0; | |
1699 | ||
1700 | return index; | |
1701 | } | |
1702 | ||
1703 | void ExynosCameraHWInterface2::m_mainThreadFunc(SignalDrivenThread * self) | |
1704 | { | |
1705 | camera_metadata_t *currentRequest = NULL; | |
1706 | camera_metadata_t *currentFrame = NULL; | |
1707 | size_t numEntries = 0; | |
1708 | size_t frameSize = 0; | |
1709 | camera_metadata_t * preparedFrame = NULL; | |
13d8c7b4 SK |
1710 | camera_metadata_t *deregisteredRequest = NULL; |
1711 | uint32_t currentSignal = self->GetProcessingSignal(); | |
1712 | MainThread * selfThread = ((MainThread*)self); | |
1713 | int res = 0; | |
1714 | ||
1715 | ALOGV("DEBUG(%s): m_mainThreadFunc (%x)", __FUNCTION__, currentSignal); | |
1716 | ||
1717 | if (currentSignal & SIGNAL_THREAD_RELEASE) { | |
1718 | ALOGV("DEBUG(%s): processing SIGNAL_THREAD_RELEASE", __FUNCTION__); | |
1719 | ||
1720 | ALOGV("DEBUG(%s): processing SIGNAL_THREAD_RELEASE DONE", __FUNCTION__); | |
1721 | selfThread->SetSignal(SIGNAL_THREAD_TERMINATE); | |
1722 | return; | |
1723 | } | |
1724 | ||
1725 | if (currentSignal & SIGNAL_MAIN_REQ_Q_NOT_EMPTY) { | |
1726 | ALOGV("DEBUG(%s): MainThread processing SIGNAL_MAIN_REQ_Q_NOT_EMPTY", __FUNCTION__); | |
1727 | if (m_requestManager->IsRequestQueueFull()==false | |
1728 | && m_requestManager->GetNumEntries()<NUM_MAX_DEQUEUED_REQUEST) { | |
1729 | m_requestQueueOps->dequeue_request(m_requestQueueOps, ¤tRequest); | |
1730 | if (NULL == currentRequest) { | |
1731 | ALOGV("DEBUG(%s): dequeue_request returned NULL ", __FUNCTION__); | |
1732 | m_isRequestQueueNull = true; | |
1733 | } | |
1734 | else { | |
1735 | m_requestManager->RegisterRequest(currentRequest); | |
1736 | ||
1737 | m_numOfRemainingReqInSvc = m_requestQueueOps->request_count(m_requestQueueOps); | |
1738 | ALOGV("DEBUG(%s): remaining req cnt (%d)", __FUNCTION__, m_numOfRemainingReqInSvc); | |
1739 | if (m_requestManager->IsRequestQueueFull()==false | |
1740 | && m_requestManager->GetNumEntries()<NUM_MAX_DEQUEUED_REQUEST) | |
1741 | selfThread->SetSignal(SIGNAL_MAIN_REQ_Q_NOT_EMPTY); // dequeue repeatedly | |
9dd63e1f | 1742 | |
13d8c7b4 SK |
1743 | m_sensorThread->SetSignal(SIGNAL_SENSOR_START_REQ_PROCESSING); |
1744 | } | |
c15a6b00 JS |
1745 | } |
1746 | else { | |
13d8c7b4 SK |
1747 | m_isRequestQueuePending = true; |
1748 | } | |
1749 | } | |
1750 | ||
1751 | if (currentSignal & SIGNAL_MAIN_STREAM_OUTPUT_DONE) { | |
1752 | ALOGV("DEBUG(%s): MainThread processing SIGNAL_MAIN_STREAM_OUTPUT_DONE", __FUNCTION__); | |
1753 | /*while (1)*/ { | |
13d8c7b4 SK |
1754 | m_requestManager->PrepareFrame(&numEntries, &frameSize, &preparedFrame); |
1755 | m_requestManager->DeregisterRequest(&deregisteredRequest); | |
1756 | m_requestQueueOps->free_request(m_requestQueueOps, deregisteredRequest); | |
1757 | m_frameQueueOps->dequeue_frame(m_frameQueueOps, numEntries, frameSize, ¤tFrame); | |
1758 | if (currentFrame==NULL) { | |
1759 | ALOGD("DBG(%s): frame dequeue returned NULL",__FUNCTION__ ); | |
1760 | } | |
1761 | else { | |
1762 | ALOGV("DEBUG(%s): frame dequeue done. numEntries(%d) frameSize(%d)",__FUNCTION__ , numEntries,frameSize); | |
1763 | } | |
1764 | res = append_camera_metadata(currentFrame, preparedFrame); | |
1765 | if (res==0) { | |
1766 | ALOGV("DEBUG(%s): frame metadata append success",__FUNCTION__); | |
1767 | m_frameQueueOps->enqueue_frame(m_frameQueueOps, currentFrame); | |
1768 | } | |
1769 | else { | |
1770 | ALOGE("ERR(%s): frame metadata append fail (%d)",__FUNCTION__, res); | |
1771 | } | |
1772 | } | |
1773 | if (!m_isRequestQueueNull) { | |
1774 | selfThread->SetSignal(SIGNAL_MAIN_REQ_Q_NOT_EMPTY); | |
1775 | } | |
9dd63e1f | 1776 | |
13d8c7b4 SK |
1777 | if (getInProgressCount()>0) { |
1778 | ALOGV("DEBUG(%s): STREAM_OUTPUT_DONE and signalling REQ_PROCESSING",__FUNCTION__); | |
1779 | m_sensorThread->SetSignal(SIGNAL_SENSOR_START_REQ_PROCESSING); | |
c15a6b00 | 1780 | } |
c15a6b00 | 1781 | } |
13d8c7b4 | 1782 | ALOGV("DEBUG(%s): MainThread Exit", __FUNCTION__); |
c15a6b00 JS |
1783 | return; |
1784 | } | |
13d8c7b4 | 1785 | |
c15a6b00 JS |
1786 | void ExynosCameraHWInterface2::m_sensorThreadInitialize(SignalDrivenThread * self) |
1787 | { | |
13d8c7b4 SK |
1788 | ALOGV("DEBUG(%s): ", __FUNCTION__ ); |
1789 | SensorThread * selfThread = ((SensorThread*)self); | |
c15a6b00 JS |
1790 | char node_name[30]; |
1791 | int fd = 0; | |
1792 | int i =0, j=0; | |
1793 | ||
9dd63e1f SK |
1794 | if(m_cameraId == 0) |
1795 | m_camera_info.sensor_id = SENSOR_NAME_S5K4E5; | |
1796 | else | |
1797 | m_camera_info.sensor_id = SENSOR_NAME_S5K6A3; | |
1798 | ||
13d8c7b4 SK |
1799 | memset(&m_camera_info.dummy_shot, 0x00, sizeof(struct camera2_shot_ext)); |
1800 | m_camera_info.dummy_shot.shot.ctl.request.metadataMode = METADATA_MODE_FULL; | |
1801 | m_camera_info.dummy_shot.shot.magicNumber = 0x23456789; | |
1802 | ||
9dd63e1f SK |
1803 | m_camera_info.dummy_shot.dis_bypass = 1; |
1804 | m_camera_info.dummy_shot.dnr_bypass = 1; | |
1805 | ||
13d8c7b4 SK |
1806 | /*sensor setting*/ |
1807 | m_camera_info.dummy_shot.shot.ctl.sensor.exposureTime = 0; | |
1808 | m_camera_info.dummy_shot.shot.ctl.sensor.frameDuration = 0; | |
1809 | m_camera_info.dummy_shot.shot.ctl.sensor.sensitivity = 0; | |
c15a6b00 | 1810 | |
13d8c7b4 SK |
1811 | m_camera_info.dummy_shot.shot.ctl.scaler.cropRegion[0] = 0; |
1812 | m_camera_info.dummy_shot.shot.ctl.scaler.cropRegion[1] = 0; | |
9dd63e1f | 1813 | //m_camera_info.dummy_shot.shot.ctl.scaler.cropRegion[2] = 1920; |
c15a6b00 | 1814 | |
13d8c7b4 SK |
1815 | /*request setting*/ |
1816 | m_camera_info.dummy_shot.request_sensor = 1; | |
1817 | m_camera_info.dummy_shot.request_scc = 0; | |
1818 | m_camera_info.dummy_shot.request_scp = 0; | |
9dd63e1f SK |
1819 | m_camera_info.dummy_shot.shot.ctl.request.outputStreams[0] = 0; |
1820 | m_camera_info.dummy_shot.shot.ctl.request.outputStreams[1] = 0; | |
1821 | m_camera_info.dummy_shot.shot.ctl.request.outputStreams[2] = 0; | |
13d8c7b4 SK |
1822 | |
1823 | /*sensor init*/ | |
c15a6b00 JS |
1824 | memset(&node_name, 0x00, sizeof(char[30])); |
1825 | sprintf(node_name, "%s%d", NODE_PREFIX, 40); | |
1826 | fd = exynos_v4l2_open(node_name, O_RDWR, 0); | |
13d8c7b4 | 1827 | |
c15a6b00 | 1828 | if (fd < 0) { |
13d8c7b4 | 1829 | ALOGE("ERR(%s): failed to open sensor video node (%s) fd (%d)", __FUNCTION__,node_name, fd); |
c15a6b00 JS |
1830 | } |
1831 | else { | |
13d8c7b4 | 1832 | ALOGV("DEBUG(%s): sensor video node opened(%s) fd (%d)", __FUNCTION__,node_name, fd); |
c15a6b00 JS |
1833 | } |
1834 | m_camera_info.sensor.fd = fd; | |
9dd63e1f SK |
1835 | |
1836 | m_camera_info.sensor.width = getSensorOutputSizeX(m_cameraId); | |
1837 | m_camera_info.sensor.height = getSensorOutputSizeY(m_cameraId); | |
1838 | ||
c15a6b00 JS |
1839 | m_camera_info.sensor.format = V4L2_PIX_FMT_SBGGR16; |
1840 | m_camera_info.sensor.planes = 2; | |
13d8c7b4 | 1841 | m_camera_info.sensor.buffers = NUM_BAYER_BUFFERS; |
c15a6b00 | 1842 | m_camera_info.sensor.type = V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE; |
24231221 | 1843 | m_camera_info.sensor.memory = V4L2_MEMORY_DMABUF; |
c15a6b00 JS |
1844 | m_camera_info.sensor.ionClient = m_ionCameraClient; |
1845 | ||
1846 | for(i = 0; i < m_camera_info.sensor.buffers; i++){ | |
1847 | initCameraMemory(&m_camera_info.sensor.buffer[i], m_camera_info.sensor.planes); | |
13d8c7b4 SK |
1848 | m_camera_info.sensor.buffer[i].size.extS[0] = m_camera_info.sensor.width*m_camera_info.sensor.height*2; |
1849 | m_camera_info.sensor.buffer[i].size.extS[1] = 8*1024; // HACK, driver use 8*1024, should be use predefined value | |
c15a6b00 JS |
1850 | allocCameraMemory(m_camera_info.sensor.ionClient, &m_camera_info.sensor.buffer[i], m_camera_info.sensor.planes); |
1851 | } | |
1852 | ||
13d8c7b4 SK |
1853 | m_initFlag1 = true; |
1854 | ||
13d8c7b4 SK |
1855 | |
1856 | while (!m_initFlag2) // temp | |
1857 | usleep(100000); | |
1858 | ALOGV("DEBUG(%s): END of SensorThreadInitialize ", __FUNCTION__); | |
1859 | return; | |
1860 | } | |
1861 | ||
1862 | ||
13d8c7b4 SK |
1863 | void ExynosCameraHWInterface2::DumpInfoWithShot(struct camera2_shot_ext * shot_ext) |
1864 | { | |
1865 | ALOGV("#### common Section"); | |
1866 | ALOGV("#### magic(%x) ", | |
1867 | shot_ext->shot.magicNumber); | |
1868 | ALOGV("#### ctl Section"); | |
1869 | ALOGV("#### metamode(%d) exposureTime(%lld) duration(%lld) ISO(%d) ", | |
1870 | shot_ext->shot.ctl.request.metadataMode, | |
1871 | shot_ext->shot.ctl.sensor.exposureTime, | |
1872 | shot_ext->shot.ctl.sensor.frameDuration, | |
1873 | shot_ext->shot.ctl.sensor.sensitivity); | |
1874 | ||
9dd63e1f SK |
1875 | ALOGV("#### OutputStream Sensor(%d) SCP(%d) SCC(%d) pv(%d) rec(%d)", |
1876 | shot_ext->request_sensor, shot_ext->request_scp, shot_ext->request_scc, | |
1877 | shot_ext->shot.ctl.request.outputStreams[0], | |
1878 | shot_ext->shot.ctl.request.outputStreams[2]); | |
13d8c7b4 SK |
1879 | |
1880 | ALOGV("#### DM Section"); | |
9dd63e1f | 1881 | ALOGV("#### metamode(%d) exposureTime(%lld) duration(%lld) ISO(%d) timestamp(%lld)", |
13d8c7b4 SK |
1882 | shot_ext->shot.dm.request.metadataMode, |
1883 | shot_ext->shot.dm.sensor.exposureTime, | |
1884 | shot_ext->shot.dm.sensor.frameDuration, | |
1885 | shot_ext->shot.dm.sensor.sensitivity, | |
9dd63e1f | 1886 | // shot_ext->shot.dm.sensor.frameCount, |
13d8c7b4 SK |
1887 | shot_ext->shot.dm.sensor.timeStamp); |
1888 | } | |
1889 | ||
1890 | void ExynosCameraHWInterface2::m_sensorThreadFunc(SignalDrivenThread * self) | |
1891 | { | |
1892 | uint32_t currentSignal = self->GetProcessingSignal(); | |
1893 | SensorThread * selfThread = ((SensorThread*)self); | |
1894 | int index; | |
1895 | status_t res; | |
1896 | nsecs_t frameTime; | |
1897 | int bayersOnSensor = 0, bayersOnIsp = 0; | |
1898 | ALOGV("DEBUG(%s): m_sensorThreadFunc (%x)", __FUNCTION__, currentSignal); | |
1899 | ||
1900 | if (currentSignal & SIGNAL_THREAD_RELEASE) { | |
9dd63e1f | 1901 | ALOGD("(%s): ENTER processing SIGNAL_THREAD_RELEASE", __FUNCTION__); |
13d8c7b4 | 1902 | |
9dd63e1f | 1903 | #if 0 // TODO |
13d8c7b4 | 1904 | for (int i = 0 ; i < NUM_BAYER_BUFFERS ; i++) { |
9dd63e1f | 1905 | ALOGV("DEBUG(%s):### BayerIndex[%d] Status (%d)", __FUNCTION__, i, m_bayerBufStatus[i]); |
13d8c7b4 SK |
1906 | if (m_bayerBufStatus[i]==BAYER_ON_SENSOR) { |
1907 | bayersOnSensor++; | |
1908 | } | |
1909 | else if (m_bayerBufStatus[i]==BAYER_ON_ISP) { | |
1910 | bayersOnIsp++; | |
1911 | } | |
1912 | } | |
1913 | for (int i = 0 ; i < bayersOnSensor ; i++) { | |
1914 | index = cam_int_dqbuf(&(m_camera_info.sensor)); | |
1915 | ALOGV("DEBUG(%s):### sensor dqbuf done index(%d)", __FUNCTION__, index); | |
1916 | m_bayerBufStatus[index] = BAYER_ON_HAL_EMPTY; | |
1917 | } | |
1918 | for (int i = 0 ; i < bayersOnIsp ; i++) { | |
1919 | index = cam_int_dqbuf(&(m_camera_info.isp)); | |
1920 | ALOGV("DEBUG(%s):### isp dqbuf done index(%d)", __FUNCTION__, index); | |
1921 | m_bayerBufStatus[index] = BAYER_ON_HAL_EMPTY; | |
1922 | } | |
1923 | ||
1924 | for (int i = 0 ; i < NUM_BAYER_BUFFERS ; i++) { | |
1925 | ALOGV("DEBUG(%s):### Bayer Buf[%d] Status (%d)", __FUNCTION__, i, m_bayerBufStatus[i]); | |
1926 | } | |
9dd63e1f SK |
1927 | #endif |
1928 | ALOGV("(%s): calling sensor streamoff", __FUNCTION__); | |
13d8c7b4 | 1929 | cam_int_streamoff(&(m_camera_info.sensor)); |
9dd63e1f | 1930 | ALOGV("(%s): calling sensor streamoff done", __FUNCTION__); |
b5237e6b SK |
1931 | |
1932 | m_camera_info.sensor.buffers = 0; | |
1933 | ALOGV("DEBUG(%s): sensor calling reqbuf 0 ", __FUNCTION__); | |
1934 | cam_int_reqbufs(&(m_camera_info.sensor)); | |
1935 | ALOGV("DEBUG(%s): sensor calling reqbuf 0 done", __FUNCTION__); | |
9dd63e1f SK |
1936 | |
1937 | ALOGV("(%s): calling ISP streamoff", __FUNCTION__); | |
1938 | isp_int_streamoff(&(m_camera_info.isp)); | |
1939 | ALOGV("(%s): calling ISP streamoff done", __FUNCTION__); | |
1940 | ||
b5237e6b SK |
1941 | m_camera_info.isp.buffers = 0; |
1942 | ALOGV("DEBUG(%s): isp calling reqbuf 0 ", __FUNCTION__); | |
1943 | cam_int_reqbufs(&(m_camera_info.isp)); | |
1944 | ALOGV("DEBUG(%s): isp calling reqbuf 0 done", __FUNCTION__); | |
1945 | ||
13d8c7b4 | 1946 | exynos_v4l2_s_ctrl(m_camera_info.sensor.fd, V4L2_CID_IS_S_STREAM, IS_DISABLE_STREAM); |
13d8c7b4 | 1947 | |
9dd63e1f | 1948 | ALOGD("(%s): EXIT processing SIGNAL_THREAD_RELEASE", __FUNCTION__); |
13d8c7b4 SK |
1949 | selfThread->SetSignal(SIGNAL_THREAD_TERMINATE); |
1950 | return; | |
1951 | } | |
1952 | ||
1953 | if (currentSignal & SIGNAL_SENSOR_START_REQ_PROCESSING) | |
1954 | { | |
1955 | ALOGV("DEBUG(%s): SensorThread processing SIGNAL_SENSOR_START_REQ_PROCESSING", __FUNCTION__); | |
9dd63e1f SK |
1956 | int targetStreamIndex = 0, i=0; |
1957 | int matchedFrameCnt, processingReqIndex; | |
13d8c7b4 SK |
1958 | struct camera2_shot_ext *shot_ext; |
1959 | if (!m_isSensorStarted) | |
1960 | { | |
1961 | m_isSensorStarted = true; | |
b5237e6b | 1962 | ALOGD("(%s): calling preview streamon", __FUNCTION__); |
13d8c7b4 | 1963 | cam_int_streamon(&(m_streamThreads[0]->m_parameters.node)); |
b5237e6b | 1964 | ALOGD("(%s): calling isp streamon done", __FUNCTION__); |
9dd63e1f SK |
1965 | for (i = 0; i < m_camera_info.isp.buffers; i++) { |
1966 | ALOGV("DEBUG(%s): isp initial QBUF [%d]", __FUNCTION__, i); | |
1967 | cam_int_qbuf(&(m_camera_info.isp), i); | |
1968 | } | |
1969 | ||
1970 | cam_int_streamon(&(m_camera_info.isp)); | |
1971 | ||
1972 | for (i = 0; i < m_camera_info.isp.buffers; i++) { | |
1973 | ALOGV("DEBUG(%s): isp initial DQBUF [%d]", __FUNCTION__, i); | |
1974 | cam_int_dqbuf(&(m_camera_info.isp)); | |
1975 | } | |
1976 | ||
13d8c7b4 SK |
1977 | ALOGV("DEBUG(%s): calling isp sctrl done", __FUNCTION__); |
1978 | exynos_v4l2_s_ctrl(m_camera_info.sensor.fd, V4L2_CID_IS_S_STREAM, IS_ENABLE_STREAM); | |
1979 | ALOGV("DEBUG(%s): calling sensor sctrl done", __FUNCTION__); | |
1980 | ||
1981 | } | |
13d8c7b4 | 1982 | |
9dd63e1f | 1983 | ALOGD("### Sensor DQBUF start"); |
13d8c7b4 SK |
1984 | index = cam_int_dqbuf(&(m_camera_info.sensor)); |
1985 | frameTime = systemTime(); | |
9dd63e1f SK |
1986 | ALOGD("### Sensor DQBUF done BayerIndex(%d)", index); |
1987 | bool wait = false; | |
1988 | shot_ext = (struct camera2_shot_ext *)(m_camera_info.sensor.buffer[index].virt.extP[1]); | |
1989 | matchedFrameCnt = m_requestManager->FindFrameCnt(shot_ext); | |
1990 | ALOGD("### Matched(%d) last(%d)", matchedFrameCnt, lastFrameCnt); | |
b5237e6b SK |
1991 | if (m_sensor_drop) { |
1992 | matchedFrameCnt = -1; | |
1993 | m_sensor_drop = false; | |
1994 | } | |
1995 | else if (matchedFrameCnt != -1) { | |
1996 | if (matchedFrameCnt == lastFrameCnt) { | |
1997 | m_sensor_drop = true; | |
1998 | matchedFrameCnt++; | |
1999 | } | |
2000 | lastFrameCnt = matchedFrameCnt; | |
9dd63e1f SK |
2001 | m_scp_closing = false; |
2002 | m_scp_closed = false; | |
2003 | } | |
2004 | ||
2005 | m_BayerManager->MarkSensorDequeue(index, matchedFrameCnt, &frameTime); | |
2006 | ||
2007 | m_requestManager->RegisterTimestamp(matchedFrameCnt, &frameTime); | |
2008 | ALOGD("### Sensor DQed BayerIndex[%d] passing to ISP. frameCnt(%d) timestamp(%lld)", | |
2009 | index, matchedFrameCnt, frameTime); | |
2010 | ||
2011 | if (!(m_ispThread.get())) | |
2012 | return; | |
13d8c7b4 | 2013 | |
9dd63e1f | 2014 | m_ispThread->SetSignal(SIGNAL_ISP_START_BAYER_INPUT); |
13d8c7b4 | 2015 | |
9dd63e1f | 2016 | while (m_BayerManager->GetNumOnSensor() <= NUM_SENSOR_QBUF) { |
13d8c7b4 | 2017 | |
9dd63e1f | 2018 | index = m_BayerManager->GetIndexForSensorEnqueue(); |
13d8c7b4 SK |
2019 | if (index == -1) { |
2020 | ALOGE("ERR(%s) No free Bayer buffer", __FUNCTION__); | |
2021 | break; | |
2022 | } | |
2023 | processingReqIndex = m_requestManager->MarkProcessingRequest(&(m_camera_info.sensor.buffer[index])); | |
2024 | ||
9dd63e1f | 2025 | shot_ext = (struct camera2_shot_ext *)(m_camera_info.sensor.buffer[index].virt.extP[1]); |
13d8c7b4 | 2026 | if (processingReqIndex == -1) { |
9dd63e1f | 2027 | ALOGV("DEBUG(%s) req underrun => inserting bubble to BayerIndex(%d)", __FUNCTION__, index); |
13d8c7b4 SK |
2028 | memcpy(shot_ext, &(m_camera_info.dummy_shot), sizeof(struct camera2_shot_ext)); |
2029 | } | |
2030 | ||
9dd63e1f SK |
2031 | m_BayerManager->MarkSensorEnqueue(index); |
2032 | if (m_scp_closing || m_scp_closed) { | |
2033 | ALOGV("(%s): SCP_CLOSING(%d) SCP_CLOSED(%d)", __FUNCTION__, m_scp_closing, m_scp_closed); | |
2034 | shot_ext->request_scc = 0; | |
2035 | shot_ext->request_scp = 0; | |
2036 | shot_ext->request_sensor = 0; | |
2037 | } | |
2038 | ALOGD("### Sensor QBUF start BayerIndex[%d]", index); | |
13d8c7b4 | 2039 | cam_int_qbuf(&(m_camera_info.sensor), index); |
9dd63e1f | 2040 | ALOGD("### Sensor QBUF done"); |
13d8c7b4 | 2041 | } |
9dd63e1f SK |
2042 | if (!m_closing){ |
2043 | ALOGE("!m_closing"); | |
13d8c7b4 | 2044 | selfThread->SetSignal(SIGNAL_SENSOR_START_REQ_PROCESSING); |
13d8c7b4 | 2045 | } |
b5237e6b | 2046 | /*if (wait) { |
9dd63e1f SK |
2047 | ALOGE("###waiting###"); |
2048 | usleep(20000); | |
b5237e6b | 2049 | }*/ |
9dd63e1f SK |
2050 | return; |
2051 | } | |
13d8c7b4 SK |
2052 | return; |
2053 | } | |
2054 | ||
13d8c7b4 SK |
2055 | void ExynosCameraHWInterface2::m_ispThreadInitialize(SignalDrivenThread * self) |
2056 | { | |
2057 | ALOGV("DEBUG(%s): ", __FUNCTION__ ); | |
2058 | IspThread * selfThread = ((IspThread*)self); | |
2059 | char node_name[30]; | |
2060 | int fd = 0; | |
2061 | int i =0, j=0; | |
2062 | ||
2063 | ||
2064 | while (!m_initFlag1) //temp | |
2065 | usleep(100000); | |
2066 | ||
2067 | /*isp init*/ | |
2068 | memset(&node_name, 0x00, sizeof(char[30])); | |
2069 | sprintf(node_name, "%s%d", NODE_PREFIX, 41); | |
2070 | fd = exynos_v4l2_open(node_name, O_RDWR, 0); | |
2071 | ||
2072 | if (fd < 0) { | |
2073 | ALOGE("ERR(%s): failed to open isp video node (%s) fd (%d)", __FUNCTION__,node_name, fd); | |
2074 | } | |
2075 | else { | |
2076 | ALOGV("DEBUG(%s): isp video node opened(%s) fd (%d)", __FUNCTION__,node_name, fd); | |
2077 | } | |
2078 | m_camera_info.isp.fd = fd; | |
2079 | ||
2080 | m_camera_info.isp.width = m_camera_info.sensor.width; | |
2081 | m_camera_info.isp.height = m_camera_info.sensor.height; | |
2082 | m_camera_info.isp.format = m_camera_info.sensor.format; | |
2083 | m_camera_info.isp.planes = m_camera_info.sensor.planes; | |
2084 | m_camera_info.isp.buffers = m_camera_info.sensor.buffers; | |
2085 | m_camera_info.isp.type = V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE; | |
2086 | m_camera_info.isp.memory = V4L2_MEMORY_DMABUF; | |
13d8c7b4 SK |
2087 | |
2088 | for(i = 0; i < m_camera_info.isp.buffers; i++){ | |
2089 | initCameraMemory(&m_camera_info.isp.buffer[i], m_camera_info.isp.planes); | |
2090 | m_camera_info.isp.buffer[i].size.extS[0] = m_camera_info.sensor.buffer[i].size.extS[0]; | |
2091 | m_camera_info.isp.buffer[i].size.extS[1] = m_camera_info.sensor.buffer[i].size.extS[1]; | |
2092 | m_camera_info.isp.buffer[i].fd.extFd[0] = m_camera_info.sensor.buffer[i].fd.extFd[0]; | |
2093 | m_camera_info.isp.buffer[i].fd.extFd[1] = m_camera_info.sensor.buffer[i].fd.extFd[1]; | |
2094 | m_camera_info.isp.buffer[i].virt.extP[0] = m_camera_info.sensor.buffer[i].virt.extP[0]; | |
2095 | m_camera_info.isp.buffer[i].virt.extP[1] = m_camera_info.sensor.buffer[i].virt.extP[1]; | |
2096 | }; | |
2097 | ||
9dd63e1f SK |
2098 | cam_int_s_input(&(m_camera_info.isp), m_camera_info.sensor_id); |
2099 | cam_int_s_fmt(&(m_camera_info.isp)); | |
2100 | ALOGV("DEBUG(%s): isp calling reqbuf", __FUNCTION__); | |
2101 | cam_int_reqbufs(&(m_camera_info.isp)); | |
2102 | ALOGV("DEBUG(%s): isp calling querybuf", __FUNCTION__); | |
13d8c7b4 | 2103 | ALOGV("DEBUG(%s): isp mem alloc done", __FUNCTION__); |
9dd63e1f | 2104 | |
13d8c7b4 SK |
2105 | cam_int_s_input(&(m_camera_info.sensor), m_camera_info.sensor_id); |
2106 | ALOGV("DEBUG(%s): sensor s_input done", __FUNCTION__); | |
13d8c7b4 SK |
2107 | if (cam_int_s_fmt(&(m_camera_info.sensor))< 0) { |
2108 | ALOGE("ERR(%s): sensor s_fmt fail", __FUNCTION__); | |
2109 | } | |
2110 | ALOGV("DEBUG(%s): sensor s_fmt done", __FUNCTION__); | |
2111 | cam_int_reqbufs(&(m_camera_info.sensor)); | |
2112 | ALOGV("DEBUG(%s): sensor reqbuf done", __FUNCTION__); | |
2113 | for (i = 0; i < m_camera_info.sensor.buffers; i++) { | |
2114 | ALOGV("DEBUG(%s): sensor initial QBUF [%d]", __FUNCTION__, i); | |
2115 | memcpy( m_camera_info.sensor.buffer[i].virt.extP[1], &(m_camera_info.dummy_shot), | |
2116 | sizeof(struct camera2_shot_ext)); | |
2117 | m_camera_info.dummy_shot.shot.ctl.sensor.frameDuration = 33*1000*1000; // apply from frame #1 | |
2118 | ||
2119 | cam_int_qbuf(&(m_camera_info.sensor), i); | |
9dd63e1f | 2120 | m_BayerManager->MarkSensorEnqueue(i); |
c15a6b00 | 2121 | } |
9dd63e1f | 2122 | ALOGE("== stream_on :: m_camera_info.sensor"); |
13d8c7b4 | 2123 | cam_int_streamon(&(m_camera_info.sensor)); |
c15a6b00 | 2124 | |
c15a6b00 JS |
2125 | |
2126 | ||
13d8c7b4 | 2127 | /*capture init*/ |
c15a6b00 JS |
2128 | memset(&node_name, 0x00, sizeof(char[30])); |
2129 | sprintf(node_name, "%s%d", NODE_PREFIX, 42); | |
2130 | fd = exynos_v4l2_open(node_name, O_RDWR, 0); | |
13d8c7b4 | 2131 | |
c15a6b00 | 2132 | if (fd < 0) { |
13d8c7b4 | 2133 | ALOGE("ERR(%s): failed to open capture video node (%s) fd (%d)", __FUNCTION__,node_name, fd); |
c15a6b00 JS |
2134 | } |
2135 | else { | |
13d8c7b4 | 2136 | ALOGV("DEBUG(%s): capture video node opened(%s) fd (%d)", __FUNCTION__,node_name, fd); |
c15a6b00 | 2137 | } |
c15a6b00 | 2138 | m_camera_info.capture.fd = fd; |
9dd63e1f SK |
2139 | |
2140 | m_camera_info.capture.width = getSccOutputSizeX(m_cameraId); | |
2141 | m_camera_info.capture.height = getSccOutputSizeY(m_cameraId); | |
c15a6b00 JS |
2142 | m_camera_info.capture.format = V4L2_PIX_FMT_YUYV; |
2143 | m_camera_info.capture.planes = 1; | |
2144 | m_camera_info.capture.buffers = 8; | |
2145 | m_camera_info.capture.type = V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE; | |
24231221 | 2146 | m_camera_info.capture.memory = V4L2_MEMORY_DMABUF; |
c15a6b00 JS |
2147 | m_camera_info.capture.ionClient = m_ionCameraClient; |
2148 | ||
2149 | for(i = 0; i < m_camera_info.capture.buffers; i++){ | |
2150 | initCameraMemory(&m_camera_info.capture.buffer[i], m_camera_info.capture.planes); | |
13d8c7b4 | 2151 | m_camera_info.capture.buffer[i].size.extS[0] = m_camera_info.capture.width*m_camera_info.capture.height*2; |
c15a6b00 JS |
2152 | allocCameraMemory(m_camera_info.capture.ionClient, &m_camera_info.capture.buffer[i], m_camera_info.capture.planes); |
2153 | } | |
2154 | ||
13d8c7b4 SK |
2155 | cam_int_s_input(&(m_camera_info.capture), m_camera_info.sensor_id); |
2156 | cam_int_s_fmt(&(m_camera_info.capture)); | |
2157 | ALOGV("DEBUG(%s): capture calling reqbuf", __FUNCTION__); | |
2158 | cam_int_reqbufs(&(m_camera_info.capture)); | |
2159 | ALOGV("DEBUG(%s): capture calling querybuf", __FUNCTION__); | |
c15a6b00 | 2160 | |
13d8c7b4 SK |
2161 | for (i = 0; i < m_camera_info.capture.buffers; i++) { |
2162 | ALOGV("DEBUG(%s): capture initial QBUF [%d]", __FUNCTION__, i); | |
2163 | cam_int_qbuf(&(m_camera_info.capture), i); | |
c15a6b00 | 2164 | } |
9dd63e1f SK |
2165 | |
2166 | ALOGE("== stream_on :: m_camera_info.capture"); | |
13d8c7b4 | 2167 | cam_int_streamon(&(m_camera_info.capture)); |
c15a6b00 | 2168 | |
13d8c7b4 SK |
2169 | m_initFlag2 = true; |
2170 | ALOGV("DEBUG(%s): END of IspThreadInitialize ", __FUNCTION__); | |
c15a6b00 JS |
2171 | return; |
2172 | } | |
2173 | ||
13d8c7b4 SK |
2174 | |
2175 | void ExynosCameraHWInterface2::m_ispThreadFunc(SignalDrivenThread * self) | |
c15a6b00 | 2176 | { |
13d8c7b4 SK |
2177 | uint32_t currentSignal = self->GetProcessingSignal(); |
2178 | IspThread * selfThread = ((IspThread*)self); | |
c15a6b00 | 2179 | int index; |
13d8c7b4 SK |
2180 | status_t res; |
2181 | ALOGV("DEBUG(%s): m_ispThreadFunc (%x)", __FUNCTION__, currentSignal); | |
2182 | ||
2183 | if (currentSignal & SIGNAL_THREAD_RELEASE) { | |
9dd63e1f | 2184 | ALOGD("(%s): ENTER processing SIGNAL_THREAD_RELEASE", __FUNCTION__); |
13d8c7b4 | 2185 | |
9dd63e1f | 2186 | ALOGV("(%s): calling capture streamoff", __FUNCTION__); |
13d8c7b4 | 2187 | cam_int_streamoff(&(m_camera_info.capture)); |
9dd63e1f SK |
2188 | ALOGV("(%s): calling capture streamoff done", __FUNCTION__); |
2189 | ||
b5237e6b SK |
2190 | m_camera_info.capture.buffers = 0; |
2191 | ALOGV("DEBUG(%s): capture calling reqbuf 0 ", __FUNCTION__); | |
2192 | cam_int_reqbufs(&(m_camera_info.capture)); | |
2193 | ALOGV("DEBUG(%s): capture calling reqbuf 0 done", __FUNCTION__); | |
2194 | ||
9dd63e1f | 2195 | ALOGD("(%s): EXIT processing SIGNAL_THREAD_RELEASE ", __FUNCTION__); |
13d8c7b4 SK |
2196 | selfThread->SetSignal(SIGNAL_THREAD_TERMINATE); |
2197 | return; | |
2198 | } | |
9dd63e1f | 2199 | |
13d8c7b4 | 2200 | if (currentSignal & SIGNAL_ISP_START_BAYER_INPUT) |
c15a6b00 | 2201 | { |
13d8c7b4 | 2202 | struct camera2_shot_ext *shot_ext; |
9dd63e1f SK |
2203 | int bayerIndexToEnqueue = 0; |
2204 | int processingFrameCnt = 0; | |
13d8c7b4 | 2205 | |
13d8c7b4 | 2206 | ALOGV("DEBUG(%s): IspThread processing SIGNAL_ISP_START_BAYER_INPUT", __FUNCTION__); |
9dd63e1f SK |
2207 | |
2208 | bayerIndexToEnqueue = m_BayerManager->GetIndexForIspEnqueue(&processingFrameCnt); | |
2209 | shot_ext = (struct camera2_shot_ext *)(m_camera_info.sensor.buffer[bayerIndexToEnqueue].virt.extP[1]); | |
2210 | ||
2211 | ALOGV("### isp QBUF start bayerIndex[%d] for frameCnt(%d)", bayerIndexToEnqueue, processingFrameCnt); | |
2212 | ||
2213 | if (processingFrameCnt != -1) { | |
2214 | ALOGV("### writing output stream info"); | |
2215 | m_requestManager->UpdateOutputStreamInfo(shot_ext, processingFrameCnt); | |
2216 | DumpInfoWithShot(shot_ext); | |
2217 | } | |
2218 | else { | |
2219 | memcpy(shot_ext, &(m_camera_info.dummy_shot), sizeof(struct camera2_shot_ext)); | |
c15a6b00 | 2220 | } |
13d8c7b4 SK |
2221 | if (m_scp_flushing) { |
2222 | shot_ext->request_scp = 1; | |
2223 | } | |
9dd63e1f SK |
2224 | if (m_scp_closing || m_scp_closed) { |
2225 | ALOGV("(%s): SCP_CLOSING(%d) SCP_CLOSED(%d)", __FUNCTION__, m_scp_closing, m_scp_closed); | |
2226 | shot_ext->request_scc = 0; | |
2227 | shot_ext->request_scp = 0; | |
2228 | shot_ext->request_sensor = 0; | |
c15a6b00 | 2229 | } |
9dd63e1f SK |
2230 | cam_int_qbuf(&(m_camera_info.isp), bayerIndexToEnqueue); |
2231 | ALOGV("### isp QBUF done bayerIndex[%d] scp(%d)", bayerIndexToEnqueue, shot_ext->request_scp); | |
2232 | m_BayerManager->MarkIspEnqueue(bayerIndexToEnqueue); | |
13d8c7b4 | 2233 | |
9dd63e1f SK |
2234 | if (m_BayerManager->GetNumOnHalFilled() != 0) { |
2235 | // input has priority | |
2236 | selfThread->SetSignal(SIGNAL_ISP_START_BAYER_INPUT); | |
2237 | return; | |
13d8c7b4 | 2238 | } |
9dd63e1f SK |
2239 | else { |
2240 | selfThread->SetSignal(SIGNAL_ISP_START_BAYER_DEQUEUE); | |
13d8c7b4 | 2241 | } |
9dd63e1f | 2242 | } |
13d8c7b4 | 2243 | |
9dd63e1f SK |
2244 | if (currentSignal & SIGNAL_ISP_START_BAYER_DEQUEUE) |
2245 | { | |
2246 | struct camera2_shot_ext *shot_ext; | |
2247 | int bayerIndexToDequeue = 0; | |
2248 | int processingFrameCnt = 0; | |
2249 | ALOGV("DEBUG(%s): IspThread processing SIGNAL_ISP_START_BAYER_DEQUEUE", __FUNCTION__); | |
2250 | ||
2251 | bayerIndexToDequeue = m_BayerManager->GetIndexForIspDequeue(&processingFrameCnt); | |
2252 | m_ispProcessingFrameCnt = processingFrameCnt; | |
2253 | m_previewOutput = 0; | |
2254 | m_recordOutput = 0; | |
2255 | shot_ext = (struct camera2_shot_ext *)(m_camera_info.sensor.buffer[bayerIndexToDequeue].virt.extP[1]); | |
2256 | if (processingFrameCnt != -1 || m_scp_flushing) // bubble | |
2257 | { | |
2258 | if (shot_ext->request_scc) { | |
2259 | m_streamThreads[1]->SetSignal(SIGNAL_STREAM_DATA_COMING); | |
13d8c7b4 | 2260 | } |
9dd63e1f SK |
2261 | m_previewOutput = shot_ext->shot.ctl.request.outputStreams[0]; |
2262 | m_recordOutput = shot_ext->shot.ctl.request.outputStreams[2]; | |
2263 | if (m_previewOutput || m_recordOutput) { | |
2264 | m_streamThreads[0]->SetSignal(SIGNAL_STREAM_DATA_COMING); | |
2265 | } | |
13d8c7b4 | 2266 | } |
9dd63e1f | 2267 | ALOGD("### isp DQBUF start"); |
13d8c7b4 | 2268 | index = cam_int_dqbuf(&(m_camera_info.isp)); |
9dd63e1f SK |
2269 | ALOGD("### isp DQBUF done bayerIndex(%d) for frameCnt(%d)", index, processingFrameCnt); |
2270 | shot_ext = (struct camera2_shot_ext *)(m_camera_info.sensor.buffer[index].virt.extP[1]); | |
2271 | ALOGV("(%s): SCP_CLOSING check sensor(%d) scc(%d) scp(%d) ", __FUNCTION__, | |
2272 | shot_ext->request_sensor, shot_ext->request_scc, shot_ext->request_scp); | |
2273 | if (shot_ext->request_scc + shot_ext->request_scp + shot_ext->request_sensor == 0) { | |
2274 | ALOGV("(%s): SCP_CLOSING check OK ", __FUNCTION__); | |
2275 | m_scp_closed = true; | |
2276 | } | |
2277 | else | |
2278 | m_scp_closed = false; | |
2279 | if (processingFrameCnt != -1) { | |
13d8c7b4 | 2280 | DumpInfoWithShot(shot_ext); |
9dd63e1f SK |
2281 | m_requestManager->ApplyDynamicMetadata(shot_ext, processingFrameCnt); |
2282 | } | |
2283 | m_BayerManager->MarkIspDequeue(index); | |
2284 | if (m_BayerManager->GetNumOnIsp() != 0) { | |
2285 | selfThread->SetSignal(SIGNAL_ISP_START_BAYER_DEQUEUE); | |
13d8c7b4 | 2286 | } |
c15a6b00 | 2287 | } |
9dd63e1f | 2288 | |
c15a6b00 JS |
2289 | return; |
2290 | } | |
2291 | ||
2292 | void ExynosCameraHWInterface2::m_streamThreadInitialize(SignalDrivenThread * self) | |
2293 | { | |
13d8c7b4 SK |
2294 | StreamThread * selfThread = ((StreamThread*)self); |
2295 | ALOGV("DEBUG(%s): ", __FUNCTION__ ); | |
2296 | memset(&(selfThread->m_parameters), 0, sizeof(stream_parameters_t)); | |
2297 | selfThread->m_isBufferInit = false; | |
2298 | ||
c15a6b00 JS |
2299 | return; |
2300 | } | |
2301 | ||
c15a6b00 JS |
2302 | void ExynosCameraHWInterface2::m_streamThreadFunc(SignalDrivenThread * self) |
2303 | { | |
13d8c7b4 SK |
2304 | uint32_t currentSignal = self->GetProcessingSignal(); |
2305 | StreamThread * selfThread = ((StreamThread*)self); | |
2306 | stream_parameters_t *selfStreamParms = &(selfThread->m_parameters); | |
9dd63e1f | 2307 | record_parameters_t *selfRecordParms = &(selfThread->m_recordParameters); |
13d8c7b4 | 2308 | node_info_t *currentNode = &(selfStreamParms->node); |
c15a6b00 | 2309 | |
13d8c7b4 | 2310 | ALOGV("DEBUG(%s): m_streamThreadFunc[%d] (%x)", __FUNCTION__, selfThread->m_index, currentSignal); |
c15a6b00 | 2311 | |
13d8c7b4 SK |
2312 | if (currentSignal & SIGNAL_STREAM_CHANGE_PARAMETER) { |
2313 | ALOGV("DEBUG(%s): processing SIGNAL_STREAM_CHANGE_PARAMETER", __FUNCTION__); | |
2314 | selfThread->applyChange(); | |
2315 | if (selfStreamParms->streamType==1) { | |
2316 | m_resizeBuf.size.extS[0] = ALIGN(selfStreamParms->outputWidth, 16) * ALIGN(selfStreamParms->outputHeight, 16) * 2; | |
2317 | m_resizeBuf.size.extS[1] = 0; | |
2318 | m_resizeBuf.size.extS[2] = 0; | |
c15a6b00 | 2319 | |
13d8c7b4 SK |
2320 | if (allocCameraMemory(selfStreamParms->ionClient, &m_resizeBuf, 1) == -1) { |
2321 | ALOGE("ERR(%s): Failed to allocate resize buf", __FUNCTION__); | |
2322 | } | |
2323 | } | |
2324 | ALOGV("DEBUG(%s): processing SIGNAL_STREAM_CHANGE_PARAMETER DONE", __FUNCTION__); | |
c15a6b00 | 2325 | } |
13d8c7b4 SK |
2326 | |
2327 | if (currentSignal & SIGNAL_THREAD_RELEASE) { | |
9dd63e1f | 2328 | int i, index = -1, cnt_to_dq = 0; |
13d8c7b4 SK |
2329 | status_t res; |
2330 | ALOGV("DEBUG(%s): processing SIGNAL_THREAD_RELEASE", __FUNCTION__); | |
2331 | ||
2332 | ||
2333 | ||
2334 | if (selfThread->m_isBufferInit) { | |
2335 | for ( i=0 ; i < selfStreamParms->numSvcBuffers; i++) { | |
2336 | ALOGV("DEBUG(%s): checking buffer index[%d] - status(%d)", | |
2337 | __FUNCTION__, i, selfStreamParms->svcBufStatus[i]); | |
2338 | if (selfStreamParms->svcBufStatus[i] ==ON_DRIVER) cnt_to_dq++; | |
2339 | } | |
b5237e6b | 2340 | |
9dd63e1f | 2341 | m_scp_closing = true; |
13d8c7b4 SK |
2342 | ALOGV("DEBUG(%s): calling stream(%d) streamoff (fd:%d)", __FUNCTION__, |
2343 | selfThread->m_index, selfStreamParms->fd); | |
2344 | cam_int_streamoff(&(selfStreamParms->node)); | |
2345 | ALOGV("DEBUG(%s): calling stream(%d) streamoff done", __FUNCTION__, selfThread->m_index); | |
b5237e6b SK |
2346 | if (selfStreamParms->streamType == 0) { |
2347 | ALOGV("DEBUG(%s): calling stream(%d) reqbuf 0 (fd:%d)", __FUNCTION__, | |
2348 | selfThread->m_index, selfStreamParms->fd); | |
2349 | currentNode->buffers = 0; | |
2350 | cam_int_reqbufs(currentNode); | |
2351 | ALOGV("DEBUG(%s): calling stream(%d) reqbuf 0 DONE(fd:%d)", __FUNCTION__, | |
2352 | selfThread->m_index, selfStreamParms->fd); | |
13d8c7b4 | 2353 | } |
b5237e6b | 2354 | selfThread->m_releasing = false; |
13d8c7b4 | 2355 | } |
b5237e6b | 2356 | if (selfThread->m_index == 1 && m_resizeBuf.size.s != 0) { |
9dd63e1f | 2357 | freeCameraMemory(&m_resizeBuf, 1); |
13d8c7b4 | 2358 | } |
b5237e6b | 2359 | if (selfThread->m_index == 2 && m_resizeBuf2.size.s != 0) { |
9dd63e1f SK |
2360 | freeCameraMemory(&m_resizeBuf2, 1); |
2361 | } | |
2362 | selfThread->m_isBufferInit = false; | |
13d8c7b4 | 2363 | selfThread->m_index = 255; |
9dd63e1f | 2364 | |
13d8c7b4 | 2365 | ALOGV("DEBUG(%s): processing SIGNAL_THREAD_RELEASE DONE", __FUNCTION__); |
9dd63e1f | 2366 | |
13d8c7b4 SK |
2367 | return; |
2368 | } | |
2369 | ||
2370 | if (currentSignal & SIGNAL_STREAM_DATA_COMING) { | |
c15a6b00 JS |
2371 | buffer_handle_t * buf = NULL; |
2372 | status_t res; | |
2373 | void *virtAddr[3]; | |
2374 | int i, j; | |
2375 | int index; | |
13d8c7b4 SK |
2376 | ALOGV("DEBUG(%s): stream(%d) processing SIGNAL_STREAM_DATA_COMING", |
2377 | __FUNCTION__,selfThread->m_index); | |
2378 | if (!(selfThread->m_isBufferInit)) { | |
2379 | for ( i=0 ; i < selfStreamParms->numSvcBuffers; i++) { | |
2380 | res = selfStreamParms->streamOps->dequeue_buffer(selfStreamParms->streamOps, &buf); | |
c15a6b00 | 2381 | if (res != NO_ERROR || buf == NULL) { |
13d8c7b4 | 2382 | ALOGE("ERR(%s): Init: unable to dequeue buffer : %d",__FUNCTION__ , res); |
c15a6b00 JS |
2383 | return; |
2384 | } | |
13d8c7b4 | 2385 | ALOGV("DEBUG(%s): got buf(%x) version(%d), numFds(%d), numInts(%d)", __FUNCTION__, (uint32_t)(*buf), |
c15a6b00 | 2386 | ((native_handle_t*)(*buf))->version, ((native_handle_t*)(*buf))->numFds, ((native_handle_t*)(*buf))->numInts); |
13d8c7b4 | 2387 | |
c15a6b00 | 2388 | if (m_grallocHal->lock(m_grallocHal, *buf, |
13d8c7b4 SK |
2389 | selfStreamParms->usage, |
2390 | 0, 0, selfStreamParms->outputWidth, selfStreamParms->outputHeight, virtAddr) != 0) { | |
2391 | ALOGE("ERR(%s): could not obtain gralloc buffer", __FUNCTION__); | |
2392 | return; | |
c15a6b00 | 2393 | } |
13d8c7b4 SK |
2394 | ALOGV("DEBUG(%s): locked img buf plane0(%x) plane1(%x) plane2(%x)", |
2395 | __FUNCTION__, (unsigned int)virtAddr[0], (unsigned int)virtAddr[1], (unsigned int)virtAddr[2]); | |
2396 | ||
2397 | index = selfThread->findBufferIndex(virtAddr[0]); | |
2398 | if (index == -1) { | |
2399 | ALOGE("ERR(%s): could not find buffer index", __FUNCTION__); | |
c15a6b00 JS |
2400 | } |
2401 | else { | |
13d8c7b4 SK |
2402 | ALOGV("DEBUG(%s): found buffer index[%d] - status(%d)", |
2403 | __FUNCTION__, index, selfStreamParms->svcBufStatus[index]); | |
2404 | if (selfStreamParms->svcBufStatus[index]== REQUIRES_DQ_FROM_SVC) | |
2405 | selfStreamParms->svcBufStatus[index] = ON_DRIVER; | |
2406 | else if (selfStreamParms->svcBufStatus[index]== ON_SERVICE) | |
2407 | selfStreamParms->svcBufStatus[index] = ON_HAL; | |
2408 | else { | |
9dd63e1f | 2409 | ALOGV("DBG(%s): buffer status abnormal (%d) " |
13d8c7b4 SK |
2410 | , __FUNCTION__, selfStreamParms->svcBufStatus[index]); |
2411 | } | |
2412 | if (*buf != selfStreamParms->svcBufHandle[index]) | |
9dd63e1f | 2413 | ALOGV("DBG(%s): different buf_handle index ", __FUNCTION__); |
13d8c7b4 SK |
2414 | else |
2415 | ALOGV("DEBUG(%s): same buf_handle index", __FUNCTION__); | |
c15a6b00 | 2416 | } |
13d8c7b4 | 2417 | m_svcBufIndex = 0; |
c15a6b00 | 2418 | } |
13d8c7b4 | 2419 | selfThread->m_isBufferInit = true; |
c15a6b00 | 2420 | } |
9dd63e1f SK |
2421 | |
2422 | if (m_recordingEnabled && m_needsRecordBufferInit) { | |
2423 | ALOGV("DEBUG(%s): Recording Buffer Initialization numsvcbuf(%d)", | |
2424 | __FUNCTION__, selfRecordParms->numSvcBuffers); | |
2425 | ||
2426 | m_resizeBuf2.size.extS[0] = ALIGN(selfRecordParms->outputWidth, 32) * ALIGN(selfRecordParms->outputHeight, 32) * 4; | |
2427 | m_resizeBuf2.size.extS[1] = 0; | |
2428 | m_resizeBuf2.size.extS[2] = 0; | |
2429 | ALOGV("DEBUG(%s): resizebuf2 size0(%d) size1(%d)", __FUNCTION__, m_resizeBuf2.size.extS[0], m_resizeBuf2.size.extS[1]); | |
2430 | if (allocCameraMemory(selfStreamParms->ionClient, &m_resizeBuf2, 1) == -1) { | |
2431 | ALOGE("ERR(%s): Failed to allocate resize buf2", __FUNCTION__); | |
2432 | } | |
2433 | ||
2434 | int checkingIndex = 0; | |
2435 | bool found = false; | |
2436 | for ( i=0 ; i < selfRecordParms->numSvcBuffers; i++) { | |
2437 | res = selfRecordParms->streamOps->dequeue_buffer(selfRecordParms->streamOps, &buf); | |
2438 | if (res != NO_ERROR || buf == NULL) { | |
2439 | ALOGE("ERR(%s): Init: unable to dequeue buffer : %d",__FUNCTION__ , res); | |
2440 | return; | |
2441 | } | |
2442 | selfRecordParms->numBufsInHal++; | |
2443 | ALOGV("DEBUG(%s): [record] got buf(%x) bufInHal(%d) version(%d), numFds(%d), numInts(%d)", __FUNCTION__, (uint32_t)(*buf), | |
2444 | selfRecordParms->numBufsInHal, ((native_handle_t*)(*buf))->version, ((native_handle_t*)(*buf))->numFds, ((native_handle_t*)(*buf))->numInts); | |
2445 | ||
2446 | if (m_grallocHal->lock(m_grallocHal, *buf, | |
2447 | selfRecordParms->usage, 0, 0, | |
2448 | selfRecordParms->outputWidth, selfRecordParms->outputHeight, virtAddr) != 0) { | |
2449 | ALOGE("ERR(%s): could not obtain gralloc buffer", __FUNCTION__); | |
2450 | } | |
2451 | else { | |
2452 | ALOGV("DEBUG(%s): [record] locked img buf plane0(%x) plane1(%x) plane2(%x)", | |
2453 | __FUNCTION__, (unsigned int)virtAddr[0], (unsigned int)virtAddr[1], (unsigned int)virtAddr[2]); | |
2454 | ||
2455 | } | |
2456 | found = false; | |
2457 | for (checkingIndex = 0; checkingIndex < selfRecordParms->numSvcBuffers ; checkingIndex++) { | |
2458 | //ALOGV("DEBUG(%s) : comparing %d %x %x", __FUNCTION__, checkingIndex, | |
2459 | //selfRecordParms->svcBufHandle[checkingIndex], *buf); | |
2460 | if (selfRecordParms->svcBufHandle[checkingIndex] == *buf ) { | |
2461 | found = true; | |
2462 | break; | |
2463 | } | |
2464 | } | |
2465 | ALOGV("DEBUG(%s): [record] found(%d) - index[%d]", __FUNCTION__, found, checkingIndex); | |
2466 | if (!found) break; | |
2467 | index = checkingIndex; | |
2468 | ||
2469 | ||
2470 | if (index == -1) { | |
b5237e6b | 2471 | ALOGD("ERR(%s): could not find buffer index", __FUNCTION__); |
9dd63e1f SK |
2472 | } |
2473 | else { | |
2474 | ALOGV("DEBUG(%s): found buffer index[%d] - status(%d)", | |
2475 | __FUNCTION__, index, selfRecordParms->svcBufStatus[index]); | |
2476 | if (selfRecordParms->svcBufStatus[index]== ON_SERVICE) | |
2477 | selfRecordParms->svcBufStatus[index] = ON_HAL; | |
2478 | else { | |
2479 | ALOGV("DBG(%s): buffer status abnormal (%d) " | |
2480 | , __FUNCTION__, selfRecordParms->svcBufStatus[index]); | |
2481 | } | |
2482 | if (*buf != selfRecordParms->svcBufHandle[index]) | |
2483 | ALOGV("DBG(%s): different buf_handle index ", __FUNCTION__); | |
2484 | else | |
2485 | ALOGV("DEBUG(%s): same buf_handle index", __FUNCTION__); | |
2486 | } | |
2487 | selfRecordParms->m_svcBufIndex = 0; | |
2488 | } | |
2489 | m_needsRecordBufferInit = false; | |
2490 | } | |
c15a6b00 | 2491 | |
b5237e6b SK |
2492 | do { |
2493 | if (selfStreamParms->streamType == 0) { | |
2494 | ALOGV("DEBUG(%s): stream(%d) type(%d) DQBUF START ",__FUNCTION__, | |
2495 | selfThread->m_index, selfStreamParms->streamType); | |
c15a6b00 | 2496 | |
b5237e6b SK |
2497 | index = cam_int_dqbuf(&(selfStreamParms->node)); |
2498 | ALOGV("DEBUG(%s): stream(%d) type(%d) DQBUF done index(%d)",__FUNCTION__, | |
2499 | selfThread->m_index, selfStreamParms->streamType, index); | |
9dd63e1f | 2500 | |
9dd63e1f | 2501 | |
b5237e6b SK |
2502 | if (selfStreamParms->svcBufStatus[index] != ON_DRIVER) |
2503 | ALOGD("DBG(%s): DQed buffer status abnormal (%d) ", | |
2504 | __FUNCTION__, selfStreamParms->svcBufStatus[index]); | |
2505 | selfStreamParms->svcBufStatus[index] = ON_HAL; | |
9dd63e1f | 2506 | |
b5237e6b SK |
2507 | if (m_recordOutput && m_recordingEnabled) { |
2508 | ALOGV("DEBUG(%s): Entering record frame creator, index(%d)",__FUNCTION__, selfRecordParms->m_svcBufIndex); | |
2509 | bool found = false; | |
2510 | for (int i = 0 ; selfRecordParms->numSvcBuffers ; i++) { | |
2511 | if (selfRecordParms->svcBufStatus[selfRecordParms->m_svcBufIndex] == ON_HAL) { | |
2512 | found = true; | |
2513 | break; | |
2514 | } | |
2515 | selfRecordParms->m_svcBufIndex++; | |
2516 | if (selfRecordParms->m_svcBufIndex >= selfRecordParms->numSvcBuffers) | |
2517 | selfRecordParms->m_svcBufIndex = 0; | |
2518 | } | |
2519 | if (!found) { | |
2520 | ALOGE("(%s): cannot find free recording buffer", __FUNCTION__); | |
2521 | selfRecordParms->m_svcBufIndex++; | |
2522 | break; | |
2523 | } | |
9dd63e1f | 2524 | |
b5237e6b SK |
2525 | if (m_exynosVideoCSC) { |
2526 | int videoW = selfRecordParms->outputWidth, videoH = selfRecordParms->outputHeight; | |
2527 | int cropX, cropY, cropW, cropH = 0; | |
2528 | int previewW = selfStreamParms->outputWidth, previewH = selfStreamParms->outputHeight; | |
9dd63e1f | 2529 | |
b5237e6b SK |
2530 | m_getRatioSize(previewW, previewH, |
2531 | videoW, videoH, | |
2532 | &cropX, &cropY, | |
2533 | &cropW, &cropH, | |
9dd63e1f SK |
2534 | 0); |
2535 | ||
b5237e6b SK |
2536 | ALOGV("DEBUG(%s):cropX = %d, cropY = %d, cropW = %d, cropH = %d", |
2537 | __FUNCTION__, cropX, cropY, cropW, cropH); | |
2538 | ||
2539 | ||
2540 | csc_set_src_format(m_exynosVideoCSC, | |
2541 | //ALIGN(previewW, 32), ALIGN(previewH, 32), | |
2542 | previewW, previewH, | |
2543 | cropX, cropY, cropW, cropH, | |
2544 | HAL_PIXEL_FORMAT_YV12, | |
2545 | 0); | |
2546 | ||
2547 | csc_set_dst_format(m_exynosVideoCSC, | |
2548 | ALIGN(videoW, 32), ALIGN(videoH, 32), | |
2549 | 0, 0, videoW, videoH, | |
2550 | HAL_PIXEL_FORMAT_RGBA_8888, | |
2551 | 1); | |
2552 | ||
2553 | ALOGV("DEBUG(%s) [1]-- bufindex(%d)", __FUNCTION__, selfRecordParms->m_svcBufIndex); | |
2554 | ||
2555 | csc_set_src_buffer(m_exynosVideoCSC, | |
2556 | (void **)(&(selfStreamParms->svcBuffers[index].fd.fd))); | |
2557 | for (int i=0 ; i <3 ; i++) | |
2558 | ALOGV("DEBUG(%s): src [%d] - %d, %x size(%d)", | |
2559 | __FUNCTION__, i, selfStreamParms->svcBuffers[index].fd.extFd[i], | |
2560 | selfStreamParms->svcBuffers[index].virt.extP[i], | |
2561 | selfStreamParms->svcBuffers[index].size.extS[i]); | |
2562 | //m_resizeBuf2.fd.extFd[2] = 0; | |
2563 | for (int i=0 ; i <selfRecordParms->svcPlanes; i++) | |
2564 | ALOGV("DEBUG(%s): m_resizeBuf2.fd.extFd[%d]=%d addr(%x) m_resizeBuf2.size.extS[%d]=%d", | |
2565 | __FUNCTION__, i, m_resizeBuf2.fd.extFd[i], (unsigned int)m_resizeBuf2.virt.extP[i], i, | |
2566 | m_resizeBuf2.size.extS[i]); | |
2567 | csc_set_dst_buffer(m_exynosVideoCSC, | |
2568 | (void **)(&(m_resizeBuf2.fd.fd))); | |
2569 | ||
2570 | if (csc_convert(m_exynosVideoCSC) != 0) { | |
2571 | ALOGE("ERR(%s):csc_convert() fail", __FUNCTION__); | |
2572 | } | |
2573 | else { | |
2574 | ALOGV("ERR(%s):csc_convert() SUCCESS", __FUNCTION__); | |
2575 | } | |
2576 | /*tempFd = selfStreamParms->svcBuffers[index].fd.extFd[2]; | |
2577 | selfStreamParms->svcBuffers[index].fd.extFd[2] = selfStreamParms->svcBuffers[index].fd.extFd[1]; | |
2578 | selfStreamParms->svcBuffers[index].fd.extFd[1] = tempFd; */ | |
9dd63e1f | 2579 | |
b5237e6b SK |
2580 | ALOGV("DEBUG(%s): svc addr[0] %x addr[1] %x", __FUNCTION__, |
2581 | (unsigned int)selfRecordParms->svcBuffers[selfRecordParms->m_svcBufIndex].virt.extP[0], | |
2582 | (unsigned int)selfRecordParms->svcBuffers[selfRecordParms->m_svcBufIndex].virt.extP[1]); | |
2583 | memcpy(selfRecordParms->svcBuffers[selfRecordParms->m_svcBufIndex].virt.extP[0], | |
2584 | m_resizeBuf2.virt.extP[0], videoW * videoH * 4); | |
9dd63e1f SK |
2585 | } |
2586 | else { | |
b5237e6b | 2587 | ALOGE("ERR(%s):m_exynosVideoCSC == NULL", __FUNCTION__); |
9dd63e1f | 2588 | } |
b5237e6b SK |
2589 | |
2590 | /* res = selfRecordParms->streamOps->enqueue_buffer(selfRecordParms->streamOps, | |
2591 | m_requestManager->GetTimestamp(m_ispProcessingFrameCnt), | |
2592 | &(selfRecordParms->svcBufHandle[selfRecordParms->m_svcBufIndex]));*/ | |
2593 | res = selfRecordParms->streamOps->enqueue_buffer(selfRecordParms->streamOps, | |
2594 | systemTime(), | |
2595 | &(selfRecordParms->svcBufHandle[selfRecordParms->m_svcBufIndex])); | |
2596 | ALOGV("DEBUG(%s): stream(%d) record enqueue_buffer to svc done res(%d)", __FUNCTION__, | |
2597 | selfThread->m_index, res); | |
2598 | if (res == 0) { | |
2599 | selfRecordParms->svcBufStatus[selfRecordParms->m_svcBufIndex] = ON_SERVICE; | |
2600 | selfRecordParms->numBufsInHal--; | |
2601 | } | |
2602 | /*selfRecordParms->m_svcBufIndex++; | |
2603 | if (selfRecordParms->m_svcBufIndex >= selfRecordParms->numSvcBuffers) | |
2604 | selfRecordParms->m_svcBufIndex = 0;*/ | |
2605 | m_requestManager->NotifyStreamOutput(m_ispProcessingFrameCnt, 2); | |
2606 | ||
2607 | } | |
2608 | if (m_previewOutput) { | |
2609 | res = selfStreamParms->streamOps->enqueue_buffer(selfStreamParms->streamOps, | |
2610 | m_requestManager->GetTimestamp(m_ispProcessingFrameCnt), &(selfStreamParms->svcBufHandle[index])); | |
2611 | ALOGV("DEBUG(%s): stream(%d) enqueue_buffer to svc done res(%d)", __FUNCTION__, selfThread->m_index, res); | |
2612 | } | |
9dd63e1f | 2613 | else { |
b5237e6b SK |
2614 | res = selfStreamParms->streamOps->cancel_buffer(selfStreamParms->streamOps, |
2615 | &(selfStreamParms->svcBufHandle[index])); | |
2616 | ALOGV("DEBUG(%s): stream(%d) cancel_buffer to svc done res(%d)", __FUNCTION__, selfThread->m_index, res); | |
9dd63e1f | 2617 | } |
9dd63e1f | 2618 | if (res == 0) { |
b5237e6b | 2619 | selfStreamParms->svcBufStatus[index] = ON_SERVICE; |
9dd63e1f | 2620 | } |
b5237e6b SK |
2621 | else { |
2622 | selfStreamParms->svcBufStatus[index] = ON_HAL; | |
2623 | } | |
2624 | m_requestManager->NotifyStreamOutput(m_ispProcessingFrameCnt, selfThread->m_index); | |
13d8c7b4 | 2625 | } |
b5237e6b SK |
2626 | else if (selfStreamParms->streamType == 1) { |
2627 | ALOGV("DEBUG(%s): stream(%d) type(%d) DQBUF START ",__FUNCTION__, | |
2628 | selfThread->m_index, selfStreamParms->streamType); | |
2629 | index = cam_int_dqbuf(&(selfStreamParms->node)); | |
2630 | ALOGV("DEBUG(%s): stream(%d) type(%d) DQBUF done index(%d)",__FUNCTION__, | |
2631 | selfThread->m_index, selfStreamParms->streamType, index); | |
13d8c7b4 | 2632 | |
b5237e6b | 2633 | m_jpegEncodingFrameCnt = m_ispProcessingFrameCnt; |
13d8c7b4 | 2634 | |
b5237e6b SK |
2635 | bool ret = false; |
2636 | int pictureW, pictureH, pictureFramesize = 0; | |
2637 | int pictureFormat; | |
2638 | int cropX, cropY, cropW, cropH = 0; | |
13d8c7b4 | 2639 | |
13d8c7b4 | 2640 | |
b5237e6b | 2641 | ExynosBuffer jpegBuf, resizeBufInfo; |
13d8c7b4 | 2642 | |
b5237e6b | 2643 | ExynosRect m_orgPictureRect; |
13d8c7b4 | 2644 | |
b5237e6b SK |
2645 | m_orgPictureRect.w = selfStreamParms->outputWidth; |
2646 | m_orgPictureRect.h = selfStreamParms->outputHeight; | |
13d8c7b4 | 2647 | |
b5237e6b | 2648 | ExynosBuffer* m_pictureBuf = &(m_camera_info.capture.buffer[index]); |
13d8c7b4 | 2649 | |
b5237e6b SK |
2650 | pictureW = getSccOutputSizeX(m_cameraId); |
2651 | pictureH = getSccOutputSizeY(m_cameraId); | |
2652 | pictureFormat = V4L2_PIX_FMT_YUYV; | |
2653 | pictureFramesize = FRAME_SIZE(V4L2_PIX_2_HAL_PIXEL_FORMAT(pictureFormat), pictureW, pictureH); | |
13d8c7b4 | 2654 | |
b5237e6b SK |
2655 | if (m_exynosPictureCSC) { |
2656 | m_getRatioSize(pictureW, pictureH, | |
2657 | m_orgPictureRect.w, m_orgPictureRect.h, | |
2658 | &cropX, &cropY, | |
2659 | &cropW, &cropH, | |
2660 | 0); | |
13d8c7b4 | 2661 | |
b5237e6b SK |
2662 | ALOGV("DEBUG(%s):cropX = %d, cropY = %d, cropW = %d, cropH = %d", |
2663 | __FUNCTION__, cropX, cropY, cropW, cropH); | |
13d8c7b4 | 2664 | |
b5237e6b SK |
2665 | csc_set_src_format(m_exynosPictureCSC, |
2666 | ALIGN(pictureW, 16), ALIGN(pictureH, 16), | |
2667 | cropX, cropY, cropW, cropH, | |
2668 | V4L2_PIX_2_HAL_PIXEL_FORMAT(pictureFormat), | |
2669 | 0); | |
13d8c7b4 | 2670 | |
b5237e6b SK |
2671 | csc_set_dst_format(m_exynosPictureCSC, |
2672 | m_orgPictureRect.w, m_orgPictureRect.h, | |
2673 | 0, 0, m_orgPictureRect.w, m_orgPictureRect.h, | |
2674 | V4L2_PIX_2_HAL_PIXEL_FORMAT(V4L2_PIX_FMT_NV16), | |
2675 | 0); | |
2676 | csc_set_src_buffer(m_exynosPictureCSC, | |
2677 | (void **)&m_pictureBuf->fd.fd); | |
13d8c7b4 | 2678 | |
b5237e6b SK |
2679 | csc_set_dst_buffer(m_exynosPictureCSC, |
2680 | (void **)&m_resizeBuf.fd.fd); | |
2681 | for (int i=0 ; i < 3 ; i++) | |
2682 | ALOGV("DEBUG(%s): m_resizeBuf.virt.extP[%d]=%d m_resizeBuf.size.extS[%d]=%d", | |
13d8c7b4 | 2683 | __FUNCTION__, i, m_resizeBuf.fd.extFd[i], i, m_resizeBuf.size.extS[i]); |
13d8c7b4 | 2684 | |
b5237e6b SK |
2685 | if (csc_convert(m_exynosPictureCSC) != 0) |
2686 | ALOGE("ERR(%s): csc_convert() fail", __FUNCTION__); | |
13d8c7b4 | 2687 | |
c15a6b00 | 2688 | |
b5237e6b SK |
2689 | } |
2690 | else { | |
2691 | ALOGE("ERR(%s): m_exynosPictureCSC == NULL", __FUNCTION__); | |
2692 | } | |
2693 | ||
2694 | resizeBufInfo = m_resizeBuf; | |
c15a6b00 | 2695 | |
b5237e6b | 2696 | m_getAlignedYUVSize(V4L2_PIX_FMT_NV16, m_orgPictureRect.w, m_orgPictureRect.h, &m_resizeBuf); |
a8b0b07d | 2697 | |
b5237e6b SK |
2698 | for (int i = 1; i < 3; i++) { |
2699 | if (m_resizeBuf.size.extS[i] != 0) | |
2700 | m_resizeBuf.fd.extFd[i] = m_resizeBuf.fd.extFd[i-1] + m_resizeBuf.size.extS[i-1]; | |
c15a6b00 | 2701 | |
b5237e6b SK |
2702 | ALOGV("(%s): m_resizeBuf.size.extS[%d] = %d", __FUNCTION__, i, m_resizeBuf.size.extS[i]); |
2703 | } | |
c15a6b00 | 2704 | |
c15a6b00 | 2705 | |
b5237e6b SK |
2706 | ExynosRect jpegRect; |
2707 | bool found = false; | |
2708 | jpegRect.w = m_orgPictureRect.w; | |
2709 | jpegRect.h = m_orgPictureRect.h; | |
2710 | jpegRect.colorFormat = V4L2_PIX_FMT_NV16; | |
a8b0b07d | 2711 | |
b5237e6b SK |
2712 | jpegBuf.size.extS[0] = 5*1024*1024; |
2713 | jpegBuf.size.extS[1] = 0; | |
2714 | jpegBuf.size.extS[2] = 0; | |
c15a6b00 | 2715 | |
b5237e6b | 2716 | allocCameraMemory(currentNode->ionClient, &jpegBuf, 1); |
13d8c7b4 | 2717 | |
b5237e6b SK |
2718 | ALOGV("DEBUG(%s): jpegBuf.size.s = %d , jpegBuf.virt.p = %x", __FUNCTION__, |
2719 | jpegBuf.size.s, (unsigned int)jpegBuf.virt.p); | |
13d8c7b4 | 2720 | |
b5237e6b SK |
2721 | |
2722 | if (yuv2Jpeg(&m_resizeBuf, &jpegBuf, &jpegRect) == false) | |
2723 | ALOGE("ERR(%s):yuv2Jpeg() fail", __FUNCTION__); | |
2724 | cam_int_qbuf(&(selfStreamParms->node), index); | |
2725 | ALOGV("DEBUG(%s): stream(%d) type(%d) QBUF DONE ",__FUNCTION__, | |
2726 | selfThread->m_index, selfStreamParms->streamType); | |
2727 | ||
2728 | m_resizeBuf = resizeBufInfo; | |
2729 | ||
2730 | for (int i = 0; i < selfStreamParms->numSvcBuffers ; i++) { | |
2731 | if (selfStreamParms->svcBufStatus[m_svcBufIndex] == ON_HAL) { | |
2732 | found = true; | |
2733 | break; | |
2734 | } | |
2735 | m_svcBufIndex++; | |
2736 | if (m_svcBufIndex >= selfStreamParms->numSvcBuffers) m_svcBufIndex = 0; | |
2737 | } | |
2738 | if (!found) { | |
2739 | ALOGE("ERR(%s): NO free SVC buffer for JPEG", __FUNCTION__); | |
13d8c7b4 SK |
2740 | } |
2741 | else { | |
b5237e6b SK |
2742 | memcpy(selfStreamParms->svcBuffers[m_svcBufIndex].virt.extP[0], jpegBuf.virt.extP[0], 5*1024*1024); |
2743 | ||
2744 | res = selfStreamParms->streamOps->enqueue_buffer(selfStreamParms->streamOps, | |
2745 | m_requestManager->GetTimestamp(m_jpegEncodingFrameCnt), &(selfStreamParms->svcBufHandle[m_svcBufIndex])); | |
2746 | ||
2747 | freeCameraMemory(&jpegBuf, 1); | |
2748 | ALOGV("DEBUG(%s): stream(%d) enqueue_buffer index(%d) to svc done res(%d)", | |
2749 | __FUNCTION__, selfThread->m_index, m_svcBufIndex, res); | |
2750 | if (res == 0) { | |
2751 | selfStreamParms->svcBufStatus[m_svcBufIndex] = ON_SERVICE; | |
2752 | } | |
2753 | else { | |
2754 | selfStreamParms->svcBufStatus[m_svcBufIndex] = ON_HAL; | |
2755 | } | |
2756 | m_requestManager->NotifyStreamOutput(m_jpegEncodingFrameCnt, selfThread->m_index); | |
13d8c7b4 | 2757 | } |
c15a6b00 | 2758 | |
b5237e6b | 2759 | } |
c15a6b00 | 2760 | } |
b5237e6b SK |
2761 | while (0); |
2762 | ||
9dd63e1f SK |
2763 | if (selfStreamParms->streamType==0 && m_recordOutput && m_recordingEnabled) { |
2764 | do { | |
2765 | ALOGV("DEBUG(%s): record currentBuf#(%d)", __FUNCTION__ , selfRecordParms->numBufsInHal); | |
2766 | if (selfRecordParms->numBufsInHal>=1) | |
2767 | { | |
2768 | ALOGV("DEBUG(%s): breaking", __FUNCTION__); | |
2769 | break; | |
2770 | } | |
2771 | res = selfRecordParms->streamOps->dequeue_buffer(selfRecordParms->streamOps, &buf); | |
2772 | if (res != NO_ERROR || buf == NULL) { | |
2773 | ALOGV("DEBUG(%s): record stream(%d) dequeue_buffer fail res(%d)",__FUNCTION__ , selfThread->m_index, res); | |
2774 | break; | |
2775 | } | |
2776 | selfRecordParms->numBufsInHal ++; | |
2777 | ALOGV("DEBUG(%s): record got buf(%x) numBufInHal(%d) version(%d), numFds(%d), numInts(%d)", __FUNCTION__, (uint32_t)(*buf), | |
2778 | selfRecordParms->numBufsInHal, ((native_handle_t*)(*buf))->version, ((native_handle_t*)(*buf))->numFds, ((native_handle_t*)(*buf))->numInts); | |
2779 | const private_handle_t *priv_handle = reinterpret_cast<const private_handle_t *>(*buf); | |
2780 | ||
2781 | bool found = false; | |
2782 | int checkingIndex = 0; | |
2783 | for (checkingIndex = 0; checkingIndex < selfRecordParms->numSvcBuffers ; checkingIndex++) { | |
2784 | if (priv_handle->fd == selfRecordParms->svcBuffers[checkingIndex].fd.extFd[0] ) { | |
2785 | found = true; | |
2786 | break; | |
2787 | } | |
2788 | } | |
2789 | ALOGV("DEBUG(%s): recording dequeueed_buffer found index(%d)", __FUNCTION__, found); | |
2790 | if (!found) break; | |
2791 | index = checkingIndex; | |
2792 | if (selfRecordParms->svcBufStatus[index] == ON_SERVICE) { | |
2793 | selfRecordParms->svcBufStatus[index] = ON_HAL; | |
2794 | } | |
2795 | else { | |
2796 | ALOGV("DEBUG(%s): record bufstatus abnormal [%d] status = %d", __FUNCTION__, | |
2797 | index, selfRecordParms->svcBufStatus[index]); | |
2798 | } | |
2799 | } while (0); | |
2800 | } | |
13d8c7b4 SK |
2801 | while(1) { |
2802 | res = selfStreamParms->streamOps->dequeue_buffer(selfStreamParms->streamOps, &buf); | |
2803 | if (res != NO_ERROR || buf == NULL) { | |
2804 | ALOGV("DEBUG(%s): stream(%d) dequeue_buffer fail res(%d)",__FUNCTION__ , selfThread->m_index, res); | |
2805 | break; | |
2806 | } | |
2807 | ||
2808 | ALOGV("DEBUG(%s): got buf(%x) version(%d), numFds(%d), numInts(%d)", __FUNCTION__, (uint32_t)(*buf), | |
2809 | ((native_handle_t*)(*buf))->version, ((native_handle_t*)(*buf))->numFds, ((native_handle_t*)(*buf))->numInts); | |
9dd63e1f | 2810 | const private_handle_t *priv_handle = reinterpret_cast<const private_handle_t *>(*buf); |
13d8c7b4 | 2811 | |
9dd63e1f SK |
2812 | bool found = false; |
2813 | int checkingIndex = 0; | |
2814 | for (checkingIndex = 0; checkingIndex < selfStreamParms->numSvcBuffers ; checkingIndex++) { | |
2815 | if (priv_handle->fd == selfStreamParms->svcBuffers[checkingIndex].fd.extFd[0] ) { | |
2816 | found = true; | |
2817 | break; | |
2818 | } | |
13d8c7b4 | 2819 | } |
9dd63e1f SK |
2820 | ALOGV("DEBUG(%s): post_dequeue_buffer found(%d)", __FUNCTION__, found); |
2821 | if (!found) break; | |
2822 | ALOGV("DEBUG(%s): preparing to qbuf [%d]", __FUNCTION__, checkingIndex); | |
2823 | index = checkingIndex; | |
2824 | if (index < selfStreamParms->numHwBuffers) { | |
2825 | uint32_t plane_index = 0; | |
2826 | ExynosBuffer* currentBuf = &(selfStreamParms->svcBuffers[index]); | |
2827 | struct v4l2_buffer v4l2_buf; | |
2828 | struct v4l2_plane planes[VIDEO_MAX_PLANES]; | |
13d8c7b4 | 2829 | |
9dd63e1f SK |
2830 | v4l2_buf.m.planes = planes; |
2831 | v4l2_buf.type = currentNode->type; | |
2832 | v4l2_buf.memory = currentNode->memory; | |
2833 | v4l2_buf.index = index; | |
2834 | v4l2_buf.length = currentNode->planes; | |
13d8c7b4 | 2835 | |
9dd63e1f SK |
2836 | v4l2_buf.m.planes[0].m.fd = priv_handle->fd; |
2837 | v4l2_buf.m.planes[2].m.fd = priv_handle->u_fd; | |
2838 | v4l2_buf.m.planes[1].m.fd = priv_handle->v_fd; | |
2839 | for (plane_index=0 ; plane_index < v4l2_buf.length ; plane_index++) { | |
2840 | v4l2_buf.m.planes[plane_index].length = currentBuf->size.extS[plane_index]; | |
2841 | ALOGV("DEBUG(%s): plane(%d): fd(%d) length(%d)", | |
2842 | __FUNCTION__, plane_index, v4l2_buf.m.planes[plane_index].m.fd, | |
2843 | v4l2_buf.m.planes[plane_index].length); | |
2844 | } | |
c15a6b00 | 2845 | |
9dd63e1f SK |
2846 | if (selfStreamParms->streamType == 0) { |
2847 | if (exynos_v4l2_qbuf(currentNode->fd, &v4l2_buf) < 0) { | |
2848 | ALOGE("ERR(%s): stream id(%d) exynos_v4l2_qbuf() fail", | |
2849 | __FUNCTION__, selfThread->m_index); | |
2850 | return; | |
13d8c7b4 | 2851 | } |
9dd63e1f SK |
2852 | selfStreamParms->svcBufStatus[index] = ON_DRIVER; |
2853 | ALOGV("DEBUG(%s): stream id(%d) type0 QBUF done index(%d)", | |
2854 | __FUNCTION__, selfThread->m_index, index); | |
2855 | } | |
2856 | else if (selfStreamParms->streamType == 1) { | |
2857 | selfStreamParms->svcBufStatus[index] = ON_HAL; | |
2858 | ALOGV("DEBUG(%s): stream id(%d) type1 DQBUF done index(%d)", | |
2859 | __FUNCTION__, selfThread->m_index, index); | |
13d8c7b4 SK |
2860 | } |
2861 | } | |
2862 | } | |
2863 | ALOGV("DEBUG(%s): stream(%d) processing SIGNAL_STREAM_DATA_COMING DONE", | |
2864 | __FUNCTION__,selfThread->m_index); | |
c15a6b00 | 2865 | } |
c15a6b00 JS |
2866 | return; |
2867 | } | |
2868 | ||
13d8c7b4 SK |
2869 | bool ExynosCameraHWInterface2::yuv2Jpeg(ExynosBuffer *yuvBuf, |
2870 | ExynosBuffer *jpegBuf, | |
2871 | ExynosRect *rect) | |
2872 | { | |
2873 | unsigned char *addr; | |
2874 | ||
2875 | ExynosJpegEncoderForCamera jpegEnc; | |
2876 | bool ret = false; | |
2877 | int res = 0; | |
2878 | ||
2879 | unsigned int *yuvSize = yuvBuf->size.extS; | |
2880 | ||
2881 | if (jpegEnc.create()) { | |
9dd63e1f | 2882 | ALOGE("ERR(%s):jpegEnc.create() fail", __FUNCTION__); |
13d8c7b4 SK |
2883 | goto jpeg_encode_done; |
2884 | } | |
2885 | ||
2886 | if (jpegEnc.setQuality(100)) { | |
9dd63e1f | 2887 | ALOGE("ERR(%s):jpegEnc.setQuality() fail", __FUNCTION__); |
13d8c7b4 SK |
2888 | goto jpeg_encode_done; |
2889 | } | |
2890 | ||
2891 | if (jpegEnc.setSize(rect->w, rect->h)) { | |
9dd63e1f | 2892 | ALOGE("ERR(%s):jpegEnc.setSize() fail", __FUNCTION__); |
13d8c7b4 SK |
2893 | goto jpeg_encode_done; |
2894 | } | |
2895 | ALOGV("%s : width = %d , height = %d\n", __FUNCTION__, rect->w, rect->h); | |
2896 | ||
2897 | if (jpegEnc.setColorFormat(rect->colorFormat)) { | |
9dd63e1f | 2898 | ALOGE("ERR(%s):jpegEnc.setColorFormat() fail", __FUNCTION__); |
13d8c7b4 SK |
2899 | goto jpeg_encode_done; |
2900 | } | |
9dd63e1f | 2901 | ALOGV("%s : color = %d\n", __FUNCTION__, &(rect->colorFormat)); |
13d8c7b4 SK |
2902 | |
2903 | if (jpegEnc.setJpegFormat(V4L2_PIX_FMT_JPEG_422)) { | |
9dd63e1f | 2904 | ALOGE("ERR(%s):jpegEnc.setJpegFormat() fail", __FUNCTION__); |
13d8c7b4 SK |
2905 | goto jpeg_encode_done; |
2906 | } | |
2907 | #if 0 | |
2908 | if (m_curCameraInfo->thumbnailW != 0 && m_curCameraInfo->thumbnailH != 0) { | |
2909 | int thumbW = 0, thumbH = 0; | |
2910 | mExifInfo.enableThumb = true; | |
2911 | if (rect->w < 320 || rect->h < 240) { | |
2912 | thumbW = 160; | |
2913 | thumbH = 120; | |
2914 | } else { | |
2915 | thumbW = m_curCameraInfo->thumbnailW; | |
2916 | thumbH = m_curCameraInfo->thumbnailH; | |
2917 | } | |
2918 | if (jpegEnc.setThumbnailSize(thumbW, thumbH)) { | |
9dd63e1f | 2919 | LOGE("ERR(%s):jpegEnc.setThumbnailSize(%d, %d) fail", __FUNCTION__, thumbW, thumbH); |
13d8c7b4 SK |
2920 | goto jpeg_encode_done; |
2921 | } | |
2922 | ||
2923 | if (0 < m_jpegThumbnailQuality && m_jpegThumbnailQuality <= 100) { | |
2924 | if (jpegEnc.setThumbnailQuality(m_jpegThumbnailQuality)) { | |
9dd63e1f | 2925 | LOGE("ERR(%s):jpegEnc.setThumbnailQuality(%d) fail", __FUNCTION__, m_jpegThumbnailQuality); |
13d8c7b4 SK |
2926 | goto jpeg_encode_done; |
2927 | } | |
2928 | } | |
2929 | ||
2930 | m_setExifChangedAttribute(&mExifInfo, rect); | |
2931 | } else | |
2932 | #endif | |
2933 | { | |
2934 | mExifInfo.enableThumb = false; | |
2935 | } | |
9dd63e1f SK |
2936 | ALOGV("DEBUG(%s):calling jpegEnc.setInBuf() yuvSize(%d)", __FUNCTION__, *yuvSize); |
2937 | /*for (int i=0 ; i < 3 ; i++) | |
13d8c7b4 | 2938 | ALOGV("DEBUG(%s):calling jpegEnc.setInBuf() virt.extP[%d]=%x extS[%d]=%d", |
9dd63e1f | 2939 | __FUNCTION__, i, yuvBuf->fd.extFd[i], i, yuvBuf->size.extS[i]);*/ |
13d8c7b4 | 2940 | if (jpegEnc.setInBuf((int *)&(yuvBuf->fd.fd), (int *)yuvSize)) { |
9dd63e1f | 2941 | ALOGE("ERR(%s):jpegEnc.setInBuf() fail", __FUNCTION__); |
13d8c7b4 SK |
2942 | goto jpeg_encode_done; |
2943 | } | |
2944 | ||
2945 | if (jpegEnc.setOutBuf(jpegBuf->fd.fd, jpegBuf->size.extS[0] + jpegBuf->size.extS[1] + jpegBuf->size.extS[2])) { | |
9dd63e1f | 2946 | ALOGE("ERR(%s):jpegEnc.setOutBuf() fail", __FUNCTION__); |
13d8c7b4 SK |
2947 | goto jpeg_encode_done; |
2948 | } | |
9dd63e1f | 2949 | /*for (int i=0 ; i < 3 ; i++) |
13d8c7b4 | 2950 | ALOGV("DEBUG(%s): jpegBuf->virt.extP[%d]=%x jpegBuf->size.extS[%d]=%d", |
9dd63e1f | 2951 | __FUNCTION__, i, jpegBuf->fd.extFd[i], i, jpegBuf->size.extS[i]);*/ |
13d8c7b4 SK |
2952 | memset(jpegBuf->virt.p,0,jpegBuf->size.extS[0] + jpegBuf->size.extS[1] + jpegBuf->size.extS[2]); |
2953 | ||
2954 | if (jpegEnc.updateConfig()) { | |
9dd63e1f | 2955 | ALOGE("ERR(%s):jpegEnc.updateConfig() fail", __FUNCTION__); |
13d8c7b4 SK |
2956 | goto jpeg_encode_done; |
2957 | } | |
2958 | ||
2959 | if (res = jpegEnc.encode((int *)&jpegBuf->size.s, NULL)) { | |
9dd63e1f | 2960 | ALOGE("ERR(%s):jpegEnc.encode() fail ret(%d)", __FUNCTION__, res); |
13d8c7b4 SK |
2961 | goto jpeg_encode_done; |
2962 | } | |
2963 | ||
2964 | ret = true; | |
2965 | ||
2966 | jpeg_encode_done: | |
2967 | ||
2968 | if (jpegEnc.flagCreate() == true) | |
2969 | jpegEnc.destroy(); | |
2970 | ||
2971 | return ret; | |
2972 | } | |
2973 | ||
2974 | ||
2975 | ExynosCameraHWInterface2::MainThread::~MainThread() | |
2976 | { | |
9dd63e1f | 2977 | ALOGD("(%s):", __FUNCTION__); |
13d8c7b4 SK |
2978 | } |
2979 | ||
2980 | void ExynosCameraHWInterface2::MainThread::release() | |
2981 | { | |
9dd63e1f | 2982 | ALOGD("(%s):", __func__); |
13d8c7b4 | 2983 | SetSignal(SIGNAL_THREAD_RELEASE); |
13d8c7b4 SK |
2984 | } |
2985 | ||
2986 | ExynosCameraHWInterface2::SensorThread::~SensorThread() | |
2987 | { | |
9dd63e1f | 2988 | ALOGD("(%s):", __FUNCTION__); |
13d8c7b4 SK |
2989 | } |
2990 | ||
2991 | void ExynosCameraHWInterface2::SensorThread::release() | |
2992 | { | |
9dd63e1f | 2993 | ALOGD("(%s):", __func__); |
13d8c7b4 | 2994 | SetSignal(SIGNAL_THREAD_RELEASE); |
13d8c7b4 SK |
2995 | } |
2996 | ||
2997 | ExynosCameraHWInterface2::IspThread::~IspThread() | |
2998 | { | |
9dd63e1f | 2999 | ALOGD("(%s):", __FUNCTION__); |
13d8c7b4 SK |
3000 | } |
3001 | ||
3002 | void ExynosCameraHWInterface2::IspThread::release() | |
3003 | { | |
9dd63e1f | 3004 | ALOGD("(%s):", __func__); |
13d8c7b4 | 3005 | SetSignal(SIGNAL_THREAD_RELEASE); |
13d8c7b4 SK |
3006 | } |
3007 | ||
3008 | ExynosCameraHWInterface2::StreamThread::~StreamThread() | |
3009 | { | |
9dd63e1f | 3010 | ALOGD("(%s):", __FUNCTION__); |
13d8c7b4 SK |
3011 | } |
3012 | ||
3013 | void ExynosCameraHWInterface2::StreamThread::setParameter(stream_parameters_t * new_parameters) | |
3014 | { | |
3015 | ALOGV("DEBUG(%s):", __FUNCTION__); | |
3016 | ||
3017 | m_tempParameters = new_parameters; | |
3018 | ||
c15a6b00 | 3019 | SetSignal(SIGNAL_STREAM_CHANGE_PARAMETER); |
13d8c7b4 SK |
3020 | |
3021 | // TODO : return synchronously (after setting parameters asynchronously) | |
9dd63e1f | 3022 | usleep(2000); |
13d8c7b4 SK |
3023 | } |
3024 | ||
3025 | void ExynosCameraHWInterface2::StreamThread::applyChange() | |
3026 | { | |
3027 | memcpy(&m_parameters, m_tempParameters, sizeof(stream_parameters_t)); | |
3028 | ||
9dd63e1f | 3029 | ALOGV("DEBUG(%s): Applying Stream paremeters width(%d), height(%d)", |
13d8c7b4 | 3030 | __FUNCTION__, m_parameters.outputWidth, m_parameters.outputHeight); |
c15a6b00 JS |
3031 | } |
3032 | ||
13d8c7b4 | 3033 | void ExynosCameraHWInterface2::StreamThread::release() |
c15a6b00 | 3034 | { |
9dd63e1f | 3035 | ALOGV("(%s):", __func__); |
13d8c7b4 | 3036 | SetSignal(SIGNAL_THREAD_RELEASE); |
13d8c7b4 SK |
3037 | } |
3038 | ||
3039 | int ExynosCameraHWInterface2::StreamThread::findBufferIndex(void * bufAddr) | |
3040 | { | |
3041 | int index; | |
3042 | for (index = 0 ; index < m_parameters.numSvcBuffers ; index++) { | |
3043 | if (m_parameters.svcBuffers[index].virt.extP[0] == bufAddr) | |
3044 | return index; | |
3045 | } | |
3046 | return -1; | |
c15a6b00 JS |
3047 | } |
3048 | ||
9dd63e1f SK |
3049 | void ExynosCameraHWInterface2::StreamThread::setRecordingParameter(record_parameters_t * recordParm) |
3050 | { | |
3051 | memcpy(&m_recordParameters, recordParm, sizeof(record_parameters_t)); | |
3052 | } | |
3053 | ||
c15a6b00 JS |
3054 | int ExynosCameraHWInterface2::createIonClient(ion_client ionClient) |
3055 | { | |
3056 | if (ionClient == 0) { | |
3057 | ionClient = ion_client_create(); | |
3058 | if (ionClient < 0) { | |
13d8c7b4 | 3059 | ALOGE("[%s]src ion client create failed, value = %d\n", __FUNCTION__, ionClient); |
c15a6b00 JS |
3060 | return 0; |
3061 | } | |
3062 | } | |
3063 | ||
3064 | return ionClient; | |
3065 | } | |
3066 | ||
3067 | int ExynosCameraHWInterface2::deleteIonClient(ion_client ionClient) | |
3068 | { | |
3069 | if (ionClient != 0) { | |
3070 | if (ionClient > 0) { | |
3071 | ion_client_destroy(ionClient); | |
3072 | } | |
3073 | ionClient = 0; | |
3074 | } | |
3075 | ||
3076 | return ionClient; | |
3077 | } | |
3078 | ||
13d8c7b4 | 3079 | int ExynosCameraHWInterface2::allocCameraMemory(ion_client ionClient, ExynosBuffer *buf, int iMemoryNum) |
c15a6b00 JS |
3080 | { |
3081 | int ret = 0; | |
3082 | int i = 0; | |
3083 | ||
3084 | if (ionClient == 0) { | |
13d8c7b4 | 3085 | ALOGE("[%s] ionClient is zero (%d)\n", __FUNCTION__, ionClient); |
c15a6b00 JS |
3086 | return -1; |
3087 | } | |
3088 | ||
3089 | for (i=0;i<iMemoryNum;i++) { | |
13d8c7b4 | 3090 | if (buf->size.extS[i] == 0) { |
c15a6b00 JS |
3091 | break; |
3092 | } | |
3093 | ||
13d8c7b4 SK |
3094 | buf->fd.extFd[i] = ion_alloc(ionClient, \ |
3095 | buf->size.extS[i], 0, ION_HEAP_EXYNOS_MASK,0); | |
3096 | if ((buf->fd.extFd[i] == -1) ||(buf->fd.extFd[i] == 0)) { | |
3097 | ALOGE("[%s]ion_alloc(%d) failed\n", __FUNCTION__, buf->size.extS[i]); | |
3098 | buf->fd.extFd[i] = -1; | |
c15a6b00 JS |
3099 | freeCameraMemory(buf, iMemoryNum); |
3100 | return -1; | |
3101 | } | |
3102 | ||
13d8c7b4 SK |
3103 | buf->virt.extP[i] = (char *)ion_map(buf->fd.extFd[i], \ |
3104 | buf->size.extS[i], 0); | |
3105 | if ((buf->virt.extP[i] == (char *)MAP_FAILED) || (buf->virt.extP[i] == NULL)) { | |
3106 | ALOGE("[%s]src ion map failed(%d)\n", __FUNCTION__, buf->size.extS[i]); | |
3107 | buf->virt.extP[i] = (char *)MAP_FAILED; | |
c15a6b00 JS |
3108 | freeCameraMemory(buf, iMemoryNum); |
3109 | return -1; | |
3110 | } | |
13d8c7b4 | 3111 | ALOGV("allocCameraMem : [%d][0x%08x] size(%d)", i, (unsigned int)(buf->virt.extP[i]), buf->size.extS[i]); |
c15a6b00 JS |
3112 | } |
3113 | ||
3114 | return ret; | |
3115 | } | |
3116 | ||
13d8c7b4 | 3117 | void ExynosCameraHWInterface2::freeCameraMemory(ExynosBuffer *buf, int iMemoryNum) |
c15a6b00 | 3118 | { |
13d8c7b4 | 3119 | |
c15a6b00 JS |
3120 | int i =0 ; |
3121 | ||
3122 | for (i=0;i<iMemoryNum;i++) { | |
13d8c7b4 SK |
3123 | if (buf->fd.extFd[i] != -1) { |
3124 | if (buf->virt.extP[i] != (char *)MAP_FAILED) { | |
3125 | ion_unmap(buf->virt.extP[i], buf->size.extS[i]); | |
c15a6b00 | 3126 | } |
13d8c7b4 | 3127 | ion_free(buf->fd.extFd[i]); |
c15a6b00 | 3128 | } |
13d8c7b4 SK |
3129 | buf->fd.extFd[i] = -1; |
3130 | buf->virt.extP[i] = (char *)MAP_FAILED; | |
3131 | buf->size.extS[i] = 0; | |
c15a6b00 JS |
3132 | } |
3133 | } | |
3134 | ||
13d8c7b4 | 3135 | void ExynosCameraHWInterface2::initCameraMemory(ExynosBuffer *buf, int iMemoryNum) |
c15a6b00 JS |
3136 | { |
3137 | int i =0 ; | |
3138 | for (i=0;i<iMemoryNum;i++) { | |
13d8c7b4 SK |
3139 | buf->virt.extP[i] = (char *)MAP_FAILED; |
3140 | buf->fd.extFd[i] = -1; | |
3141 | buf->size.extS[i] = 0; | |
c15a6b00 JS |
3142 | } |
3143 | } | |
3144 | ||
3145 | ||
13d8c7b4 SK |
3146 | |
3147 | ||
9dd63e1f | 3148 | static camera2_device_t *g_cam2_device = NULL; |
b5237e6b | 3149 | static bool g_camera_vaild = false; |
c15a6b00 JS |
3150 | |
3151 | static int HAL2_camera_device_close(struct hw_device_t* device) | |
3152 | { | |
9dd63e1f | 3153 | ALOGD("%s: ENTER", __FUNCTION__); |
c15a6b00 | 3154 | if (device) { |
9dd63e1f | 3155 | |
c15a6b00 | 3156 | camera2_device_t *cam_device = (camera2_device_t *)device; |
9dd63e1f SK |
3157 | ALOGD("cam_device(0x%08x):", (unsigned int)cam_device); |
3158 | ALOGD("g_cam2_device(0x%08x):", (unsigned int)g_cam2_device); | |
c15a6b00 | 3159 | delete static_cast<ExynosCameraHWInterface2 *>(cam_device->priv); |
9dd63e1f | 3160 | g_cam2_device = NULL; |
c15a6b00 | 3161 | free(cam_device); |
b5237e6b | 3162 | g_camera_vaild = false; |
c15a6b00 | 3163 | } |
9dd63e1f | 3164 | ALOGD("%s: EXIT", __FUNCTION__); |
c15a6b00 JS |
3165 | return 0; |
3166 | } | |
3167 | ||
3168 | static inline ExynosCameraHWInterface2 *obj(const struct camera2_device *dev) | |
3169 | { | |
3170 | return reinterpret_cast<ExynosCameraHWInterface2 *>(dev->priv); | |
3171 | } | |
3172 | ||
3173 | static int HAL2_device_set_request_queue_src_ops(const struct camera2_device *dev, | |
3174 | const camera2_request_queue_src_ops_t *request_src_ops) | |
3175 | { | |
13d8c7b4 | 3176 | ALOGV("DEBUG(%s):", __FUNCTION__); |
c15a6b00 JS |
3177 | return obj(dev)->setRequestQueueSrcOps(request_src_ops); |
3178 | } | |
3179 | ||
3180 | static int HAL2_device_notify_request_queue_not_empty(const struct camera2_device *dev) | |
3181 | { | |
13d8c7b4 | 3182 | ALOGV("DEBUG(%s):", __FUNCTION__); |
c15a6b00 JS |
3183 | return obj(dev)->notifyRequestQueueNotEmpty(); |
3184 | } | |
3185 | ||
3186 | static int HAL2_device_set_frame_queue_dst_ops(const struct camera2_device *dev, | |
3187 | const camera2_frame_queue_dst_ops_t *frame_dst_ops) | |
3188 | { | |
13d8c7b4 | 3189 | ALOGV("DEBUG(%s):", __FUNCTION__); |
c15a6b00 JS |
3190 | return obj(dev)->setFrameQueueDstOps(frame_dst_ops); |
3191 | } | |
3192 | ||
3193 | static int HAL2_device_get_in_progress_count(const struct camera2_device *dev) | |
3194 | { | |
13d8c7b4 | 3195 | ALOGV("DEBUG(%s):", __FUNCTION__); |
c15a6b00 JS |
3196 | return obj(dev)->getInProgressCount(); |
3197 | } | |
3198 | ||
3199 | static int HAL2_device_flush_captures_in_progress(const struct camera2_device *dev) | |
3200 | { | |
13d8c7b4 | 3201 | ALOGV("DEBUG(%s):", __FUNCTION__); |
c15a6b00 JS |
3202 | return obj(dev)->flushCapturesInProgress(); |
3203 | } | |
3204 | ||
3205 | static int HAL2_device_construct_default_request(const struct camera2_device *dev, | |
3206 | int request_template, camera_metadata_t **request) | |
3207 | { | |
13d8c7b4 | 3208 | ALOGV("DEBUG(%s):", __FUNCTION__); |
c15a6b00 JS |
3209 | return obj(dev)->constructDefaultRequest(request_template, request); |
3210 | } | |
3211 | ||
3212 | static int HAL2_device_allocate_stream( | |
3213 | const struct camera2_device *dev, | |
3214 | // inputs | |
3215 | uint32_t width, | |
3216 | uint32_t height, | |
3217 | int format, | |
3218 | const camera2_stream_ops_t *stream_ops, | |
3219 | // outputs | |
3220 | uint32_t *stream_id, | |
3221 | uint32_t *format_actual, | |
3222 | uint32_t *usage, | |
3223 | uint32_t *max_buffers) | |
3224 | { | |
9dd63e1f | 3225 | ALOGV("(%s): ", __FUNCTION__); |
c15a6b00 JS |
3226 | return obj(dev)->allocateStream(width, height, format, stream_ops, |
3227 | stream_id, format_actual, usage, max_buffers); | |
3228 | } | |
3229 | ||
3230 | ||
3231 | static int HAL2_device_register_stream_buffers(const struct camera2_device *dev, | |
3232 | uint32_t stream_id, | |
3233 | int num_buffers, | |
3234 | buffer_handle_t *buffers) | |
3235 | { | |
13d8c7b4 | 3236 | ALOGV("DEBUG(%s):", __FUNCTION__); |
c15a6b00 JS |
3237 | return obj(dev)->registerStreamBuffers(stream_id, num_buffers, buffers); |
3238 | } | |
3239 | ||
3240 | static int HAL2_device_release_stream( | |
3241 | const struct camera2_device *dev, | |
3242 | uint32_t stream_id) | |
3243 | { | |
9dd63e1f | 3244 | ALOGD("DEBUG(%s)(id: %d):", __FUNCTION__, stream_id); |
b5237e6b SK |
3245 | if (!g_camera_vaild) |
3246 | return 0; | |
c15a6b00 JS |
3247 | return obj(dev)->releaseStream(stream_id); |
3248 | } | |
3249 | ||
3250 | static int HAL2_device_allocate_reprocess_stream( | |
3251 | const struct camera2_device *dev, | |
3252 | uint32_t width, | |
3253 | uint32_t height, | |
3254 | uint32_t format, | |
3255 | const camera2_stream_in_ops_t *reprocess_stream_ops, | |
3256 | // outputs | |
3257 | uint32_t *stream_id, | |
3258 | uint32_t *consumer_usage, | |
3259 | uint32_t *max_buffers) | |
3260 | { | |
13d8c7b4 | 3261 | ALOGV("DEBUG(%s):", __FUNCTION__); |
c15a6b00 JS |
3262 | return obj(dev)->allocateReprocessStream(width, height, format, reprocess_stream_ops, |
3263 | stream_id, consumer_usage, max_buffers); | |
3264 | } | |
3265 | ||
3266 | static int HAL2_device_release_reprocess_stream( | |
3267 | const struct camera2_device *dev, | |
3268 | uint32_t stream_id) | |
3269 | { | |
13d8c7b4 | 3270 | ALOGV("DEBUG(%s):", __FUNCTION__); |
c15a6b00 JS |
3271 | return obj(dev)->releaseReprocessStream(stream_id); |
3272 | } | |
3273 | ||
3274 | static int HAL2_device_trigger_action(const struct camera2_device *dev, | |
3275 | uint32_t trigger_id, | |
3276 | int ext1, | |
3277 | int ext2) | |
3278 | { | |
13d8c7b4 | 3279 | ALOGV("DEBUG(%s):", __FUNCTION__); |
c15a6b00 JS |
3280 | return obj(dev)->triggerAction(trigger_id, ext1, ext2); |
3281 | } | |
3282 | ||
3283 | static int HAL2_device_set_notify_callback(const struct camera2_device *dev, | |
3284 | camera2_notify_callback notify_cb, | |
3285 | void *user) | |
3286 | { | |
13d8c7b4 | 3287 | ALOGV("DEBUG(%s):", __FUNCTION__); |
c15a6b00 JS |
3288 | return obj(dev)->setNotifyCallback(notify_cb, user); |
3289 | } | |
3290 | ||
3291 | static int HAL2_device_get_metadata_vendor_tag_ops(const struct camera2_device*dev, | |
3292 | vendor_tag_query_ops_t **ops) | |
3293 | { | |
13d8c7b4 | 3294 | ALOGV("DEBUG(%s):", __FUNCTION__); |
c15a6b00 JS |
3295 | return obj(dev)->getMetadataVendorTagOps(ops); |
3296 | } | |
3297 | ||
3298 | static int HAL2_device_dump(const struct camera2_device *dev, int fd) | |
3299 | { | |
13d8c7b4 | 3300 | ALOGV("DEBUG(%s):", __FUNCTION__); |
c15a6b00 JS |
3301 | return obj(dev)->dump(fd); |
3302 | } | |
3303 | ||
3304 | ||
3305 | ||
3306 | ||
3307 | ||
3308 | static int HAL2_getNumberOfCameras() | |
3309 | { | |
9dd63e1f SK |
3310 | ALOGV("(%s): returning 2", __FUNCTION__); |
3311 | return 2; | |
c15a6b00 JS |
3312 | } |
3313 | ||
3314 | ||
c15a6b00 JS |
3315 | static int HAL2_getCameraInfo(int cameraId, struct camera_info *info) |
3316 | { | |
9dd63e1f SK |
3317 | ALOGD("DEBUG(%s): cameraID: %d", __FUNCTION__, cameraId); |
3318 | static camera_metadata_t * mCameraInfo[2] = {NULL, NULL}; | |
3319 | ||
c15a6b00 | 3320 | status_t res; |
13d8c7b4 | 3321 | |
9dd63e1f SK |
3322 | if (cameraId == 0) |
3323 | info->facing = CAMERA_FACING_BACK; | |
3324 | else | |
3325 | info->facing = CAMERA_FACING_FRONT; | |
c15a6b00 JS |
3326 | info->orientation = 0; |
3327 | info->device_version = HARDWARE_DEVICE_API_VERSION(2, 0); | |
9dd63e1f SK |
3328 | if (mCameraInfo[cameraId] == NULL) { |
3329 | res = constructStaticInfo(&(mCameraInfo[cameraId]), cameraId, true); | |
c15a6b00 JS |
3330 | if (res != OK) { |
3331 | ALOGE("%s: Unable to allocate static info: %s (%d)", | |
13d8c7b4 | 3332 | __FUNCTION__, strerror(-res), res); |
c15a6b00 JS |
3333 | return res; |
3334 | } | |
9dd63e1f | 3335 | res = constructStaticInfo(&(mCameraInfo[cameraId]), cameraId, false); |
c15a6b00 JS |
3336 | if (res != OK) { |
3337 | ALOGE("%s: Unable to fill in static info: %s (%d)", | |
13d8c7b4 | 3338 | __FUNCTION__, strerror(-res), res); |
c15a6b00 JS |
3339 | return res; |
3340 | } | |
3341 | } | |
9dd63e1f | 3342 | info->static_camera_characteristics = mCameraInfo[cameraId]; |
13d8c7b4 | 3343 | return NO_ERROR; |
c15a6b00 JS |
3344 | } |
3345 | ||
3346 | #define SET_METHOD(m) m : HAL2_device_##m | |
3347 | ||
3348 | static camera2_device_ops_t camera2_device_ops = { | |
3349 | SET_METHOD(set_request_queue_src_ops), | |
3350 | SET_METHOD(notify_request_queue_not_empty), | |
3351 | SET_METHOD(set_frame_queue_dst_ops), | |
3352 | SET_METHOD(get_in_progress_count), | |
3353 | SET_METHOD(flush_captures_in_progress), | |
3354 | SET_METHOD(construct_default_request), | |
3355 | SET_METHOD(allocate_stream), | |
3356 | SET_METHOD(register_stream_buffers), | |
3357 | SET_METHOD(release_stream), | |
3358 | SET_METHOD(allocate_reprocess_stream), | |
3359 | SET_METHOD(release_reprocess_stream), | |
3360 | SET_METHOD(trigger_action), | |
3361 | SET_METHOD(set_notify_callback), | |
3362 | SET_METHOD(get_metadata_vendor_tag_ops), | |
3363 | SET_METHOD(dump), | |
3364 | }; | |
3365 | ||
3366 | #undef SET_METHOD | |
3367 | ||
3368 | ||
3369 | static int HAL2_camera_device_open(const struct hw_module_t* module, | |
3370 | const char *id, | |
3371 | struct hw_device_t** device) | |
3372 | { | |
9dd63e1f | 3373 | |
c15a6b00 JS |
3374 | |
3375 | int cameraId = atoi(id); | |
9dd63e1f | 3376 | |
b5237e6b | 3377 | g_camera_vaild = false; |
9dd63e1f | 3378 | ALOGD("\n\n>>> I'm Samsung's CameraHAL_2(ID:%d) <<<\n\n", cameraId); |
c15a6b00 | 3379 | if (cameraId < 0 || cameraId >= HAL2_getNumberOfCameras()) { |
13d8c7b4 | 3380 | ALOGE("ERR(%s):Invalid camera ID %s", __FUNCTION__, id); |
c15a6b00 JS |
3381 | return -EINVAL; |
3382 | } | |
3383 | ||
9dd63e1f | 3384 | ALOGD("g_cam2_device : 0x%08x", (unsigned int)g_cam2_device); |
c15a6b00 JS |
3385 | if (g_cam2_device) { |
3386 | if (obj(g_cam2_device)->getCameraId() == cameraId) { | |
13d8c7b4 | 3387 | ALOGV("DEBUG(%s):returning existing camera ID %s", __FUNCTION__, id); |
c15a6b00 JS |
3388 | goto done; |
3389 | } else { | |
9dd63e1f SK |
3390 | |
3391 | while (g_cam2_device) | |
3392 | usleep(10000); | |
3393 | /*ALOGE("ERR(%s):Cannot open camera %d. camera %d is already running!", | |
13d8c7b4 | 3394 | __FUNCTION__, cameraId, obj(g_cam2_device)->getCameraId()); |
9dd63e1f | 3395 | return -ENOSYS;*/ |
c15a6b00 JS |
3396 | } |
3397 | } | |
3398 | ||
3399 | g_cam2_device = (camera2_device_t *)malloc(sizeof(camera2_device_t)); | |
9dd63e1f SK |
3400 | ALOGD("g_cam2_device : 0x%08x", (unsigned int)g_cam2_device); |
3401 | ||
c15a6b00 JS |
3402 | if (!g_cam2_device) |
3403 | return -ENOMEM; | |
3404 | ||
3405 | g_cam2_device->common.tag = HARDWARE_DEVICE_TAG; | |
3406 | g_cam2_device->common.version = CAMERA_DEVICE_API_VERSION_2_0; | |
3407 | g_cam2_device->common.module = const_cast<hw_module_t *>(module); | |
3408 | g_cam2_device->common.close = HAL2_camera_device_close; | |
3409 | ||
3410 | g_cam2_device->ops = &camera2_device_ops; | |
3411 | ||
13d8c7b4 | 3412 | ALOGV("DEBUG(%s):open camera2 %s", __FUNCTION__, id); |
c15a6b00 JS |
3413 | |
3414 | g_cam2_device->priv = new ExynosCameraHWInterface2(cameraId, g_cam2_device); | |
3415 | ||
3416 | done: | |
3417 | *device = (hw_device_t *)g_cam2_device; | |
13d8c7b4 | 3418 | ALOGV("DEBUG(%s):opened camera2 %s (%p)", __FUNCTION__, id, *device); |
b5237e6b | 3419 | g_camera_vaild = true; |
c15a6b00 JS |
3420 | |
3421 | return 0; | |
3422 | } | |
3423 | ||
3424 | ||
3425 | static hw_module_methods_t camera_module_methods = { | |
3426 | open : HAL2_camera_device_open | |
3427 | }; | |
3428 | ||
3429 | extern "C" { | |
3430 | struct camera_module HAL_MODULE_INFO_SYM = { | |
3431 | common : { | |
3432 | tag : HARDWARE_MODULE_TAG, | |
3433 | module_api_version : CAMERA_MODULE_API_VERSION_2_0, | |
3434 | hal_api_version : HARDWARE_HAL_API_VERSION, | |
3435 | id : CAMERA_HARDWARE_MODULE_ID, | |
3436 | name : "Exynos Camera HAL2", | |
3437 | author : "Samsung Corporation", | |
3438 | methods : &camera_module_methods, | |
3439 | dso: NULL, | |
3440 | reserved: {0}, | |
3441 | }, | |
3442 | get_number_of_cameras : HAL2_getNumberOfCameras, | |
3443 | get_camera_info : HAL2_getCameraInfo | |
3444 | }; | |
3445 | } | |
3446 | ||
3447 | }; // namespace android |