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