Jiyoung Shin | c15a6b0 | 2012-06-05 01:08:14 -0700 | [diff] [blame] | 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) |
Sungjoong Kang | 13d8c7b | 2012-07-14 10:20:39 +0900 | [diff] [blame] | 23 | * \date 2012/07/10 |
Jiyoung Shin | c15a6b0 | 2012-06-05 01:08:14 -0700 | [diff] [blame] | 24 | * |
| 25 | * <b>Revision History: </b> |
| 26 | * - 2012/05/31 : Sungjoong Kang(sj3.kang@samsung.com) \n |
| 27 | * Initial Release |
Sungjoong Kang | 13d8c7b | 2012-07-14 10:20:39 +0900 | [diff] [blame] | 28 | * |
| 29 | * - 2012/07/10 : Sungjoong Kang(sj3.kang@samsung.com) \n |
| 30 | * 2nd Release |
| 31 | * |
Jiyoung Shin | c15a6b0 | 2012-06-05 01:08:14 -0700 | [diff] [blame] | 32 | */ |
| 33 | |
| 34 | //#define LOG_NDEBUG 0 |
Sungjoong Kang | 9dd63e1 | 2012-07-24 00:25:51 +0900 | [diff] [blame] | 35 | #define LOG_TAG "ExynosCameraHAL2" |
Jiyoung Shin | c15a6b0 | 2012-06-05 01:08:14 -0700 | [diff] [blame] | 36 | #include <utils/Log.h> |
| 37 | |
| 38 | #include "ExynosCameraHWInterface2.h" |
| 39 | #include "exynos_format.h" |
| 40 | |
| 41 | |
| 42 | |
| 43 | namespace android { |
| 44 | |
| 45 | |
Sungjoong Kang | 9dd63e1 | 2012-07-24 00:25:51 +0900 | [diff] [blame] | 46 | void m_savePostView(const char *fname, uint8_t *buf, uint32_t size) |
| 47 | { |
| 48 | int nw; |
| 49 | int cnt = 0; |
| 50 | uint32_t written = 0; |
| 51 | |
Sungjoong Kang | ad37861 | 2012-08-17 12:34:33 -0700 | [diff] [blame] | 52 | ALOGV("opening file [%s], address[%x], size(%d)", fname, (unsigned int)buf, size); |
Sungjoong Kang | 9dd63e1 | 2012-07-24 00:25:51 +0900 | [diff] [blame] | 53 | int fd = open(fname, O_RDWR | O_CREAT, 0644); |
| 54 | if (fd < 0) { |
| 55 | ALOGE("failed to create file [%s]: %s", fname, strerror(errno)); |
| 56 | return; |
| 57 | } |
| 58 | |
Sungjoong Kang | ad37861 | 2012-08-17 12:34:33 -0700 | [diff] [blame] | 59 | ALOGV("writing %d bytes to file [%s]", size, fname); |
Sungjoong Kang | 9dd63e1 | 2012-07-24 00:25:51 +0900 | [diff] [blame] | 60 | while (written < size) { |
| 61 | nw = ::write(fd, buf + written, size - written); |
| 62 | if (nw < 0) { |
| 63 | ALOGE("failed to write to file %d [%s]: %s",written,fname, strerror(errno)); |
| 64 | break; |
| 65 | } |
| 66 | written += nw; |
| 67 | cnt++; |
| 68 | } |
Sungjoong Kang | ad37861 | 2012-08-17 12:34:33 -0700 | [diff] [blame] | 69 | ALOGV("done writing %d bytes to file [%s] in %d passes",size, fname, cnt); |
Sungjoong Kang | 9dd63e1 | 2012-07-24 00:25:51 +0900 | [diff] [blame] | 70 | ::close(fd); |
| 71 | } |
| 72 | |
Jiyoung Shin | c15a6b0 | 2012-06-05 01:08:14 -0700 | [diff] [blame] | 73 | int get_pixel_depth(uint32_t fmt) |
| 74 | { |
| 75 | int depth = 0; |
| 76 | |
| 77 | switch (fmt) { |
| 78 | case V4L2_PIX_FMT_JPEG: |
| 79 | depth = 8; |
| 80 | break; |
| 81 | |
| 82 | case V4L2_PIX_FMT_NV12: |
| 83 | case V4L2_PIX_FMT_NV21: |
| 84 | case V4L2_PIX_FMT_YUV420: |
| 85 | case V4L2_PIX_FMT_YVU420M: |
| 86 | case V4L2_PIX_FMT_NV12M: |
| 87 | case V4L2_PIX_FMT_NV12MT: |
| 88 | depth = 12; |
| 89 | break; |
| 90 | |
| 91 | case V4L2_PIX_FMT_RGB565: |
| 92 | case V4L2_PIX_FMT_YUYV: |
| 93 | case V4L2_PIX_FMT_YVYU: |
| 94 | case V4L2_PIX_FMT_UYVY: |
| 95 | case V4L2_PIX_FMT_VYUY: |
| 96 | case V4L2_PIX_FMT_NV16: |
| 97 | case V4L2_PIX_FMT_NV61: |
| 98 | case V4L2_PIX_FMT_YUV422P: |
| 99 | case V4L2_PIX_FMT_SBGGR10: |
| 100 | case V4L2_PIX_FMT_SBGGR12: |
| 101 | case V4L2_PIX_FMT_SBGGR16: |
| 102 | depth = 16; |
| 103 | break; |
| 104 | |
| 105 | case V4L2_PIX_FMT_RGB32: |
| 106 | depth = 32; |
| 107 | break; |
| 108 | default: |
| 109 | ALOGE("Get depth failed(format : %d)", fmt); |
| 110 | break; |
| 111 | } |
| 112 | |
| 113 | return depth; |
Sungjoong Kang | 13d8c7b | 2012-07-14 10:20:39 +0900 | [diff] [blame] | 114 | } |
Jiyoung Shin | c15a6b0 | 2012-06-05 01:08:14 -0700 | [diff] [blame] | 115 | |
| 116 | int cam_int_s_fmt(node_info_t *node) |
| 117 | { |
| 118 | struct v4l2_format v4l2_fmt; |
| 119 | unsigned int framesize; |
| 120 | int ret; |
| 121 | |
| 122 | memset(&v4l2_fmt, 0, sizeof(struct v4l2_format)); |
| 123 | |
| 124 | v4l2_fmt.type = node->type; |
| 125 | framesize = (node->width * node->height * get_pixel_depth(node->format)) / 8; |
| 126 | |
| 127 | if (node->planes >= 1) { |
| 128 | v4l2_fmt.fmt.pix_mp.width = node->width; |
| 129 | v4l2_fmt.fmt.pix_mp.height = node->height; |
| 130 | v4l2_fmt.fmt.pix_mp.pixelformat = node->format; |
| 131 | v4l2_fmt.fmt.pix_mp.field = V4L2_FIELD_ANY; |
| 132 | } else { |
Sungjoong Kang | 13d8c7b | 2012-07-14 10:20:39 +0900 | [diff] [blame] | 133 | ALOGE("%s:S_FMT, Out of bound : Number of element plane",__FUNCTION__); |
Jiyoung Shin | c15a6b0 | 2012-06-05 01:08:14 -0700 | [diff] [blame] | 134 | } |
| 135 | |
| 136 | /* Set up for capture */ |
| 137 | ret = exynos_v4l2_s_fmt(node->fd, &v4l2_fmt); |
| 138 | |
| 139 | if (ret < 0) |
Sungjoong Kang | 13d8c7b | 2012-07-14 10:20:39 +0900 | [diff] [blame] | 140 | ALOGE("%s: exynos_v4l2_s_fmt fail (%d)",__FUNCTION__, ret); |
Jiyoung Shin | c15a6b0 | 2012-06-05 01:08:14 -0700 | [diff] [blame] | 141 | |
Sungjoong Kang | be494d1 | 2012-08-04 15:36:56 -0700 | [diff] [blame] | 142 | |
Jiyoung Shin | c15a6b0 | 2012-06-05 01:08:14 -0700 | [diff] [blame] | 143 | return ret; |
| 144 | } |
| 145 | |
| 146 | int cam_int_reqbufs(node_info_t *node) |
| 147 | { |
| 148 | struct v4l2_requestbuffers req; |
| 149 | int ret; |
| 150 | |
| 151 | req.count = node->buffers; |
| 152 | req.type = node->type; |
| 153 | req.memory = node->memory; |
| 154 | |
| 155 | ret = exynos_v4l2_reqbufs(node->fd, &req); |
| 156 | |
| 157 | if (ret < 0) |
Sungjoong Kang | 13d8c7b | 2012-07-14 10:20:39 +0900 | [diff] [blame] | 158 | ALOGE("%s: VIDIOC_REQBUFS (fd:%d) failed (%d)",__FUNCTION__,node->fd, ret); |
Jiyoung Shin | c15a6b0 | 2012-06-05 01:08:14 -0700 | [diff] [blame] | 159 | |
| 160 | return req.count; |
| 161 | } |
| 162 | |
| 163 | int cam_int_qbuf(node_info_t *node, int index) |
| 164 | { |
| 165 | struct v4l2_buffer v4l2_buf; |
| 166 | struct v4l2_plane planes[VIDEO_MAX_PLANES]; |
| 167 | int i; |
| 168 | int ret = 0; |
| 169 | |
| 170 | v4l2_buf.m.planes = planes; |
| 171 | v4l2_buf.type = node->type; |
| 172 | v4l2_buf.memory = node->memory; |
| 173 | v4l2_buf.index = index; |
| 174 | v4l2_buf.length = node->planes; |
| 175 | |
| 176 | for(i = 0; i < node->planes; i++){ |
Sungjoong Kang | 13d8c7b | 2012-07-14 10:20:39 +0900 | [diff] [blame] | 177 | v4l2_buf.m.planes[i].m.fd = (int)(node->buffer[index].fd.extFd[i]); |
| 178 | v4l2_buf.m.planes[i].length = (unsigned long)(node->buffer[index].size.extS[i]); |
Jiyoung Shin | c15a6b0 | 2012-06-05 01:08:14 -0700 | [diff] [blame] | 179 | } |
| 180 | |
| 181 | ret = exynos_v4l2_qbuf(node->fd, &v4l2_buf); |
| 182 | |
| 183 | if (ret < 0) |
Sungjoong Kang | 13d8c7b | 2012-07-14 10:20:39 +0900 | [diff] [blame] | 184 | ALOGE("%s: cam_int_qbuf failed (index:%d)(ret:%d)",__FUNCTION__, index, ret); |
Jiyoung Shin | c15a6b0 | 2012-06-05 01:08:14 -0700 | [diff] [blame] | 185 | |
| 186 | return ret; |
| 187 | } |
| 188 | |
| 189 | int cam_int_streamon(node_info_t *node) |
| 190 | { |
| 191 | enum v4l2_buf_type type = node->type; |
| 192 | int ret; |
| 193 | |
Sungjoong Kang | be494d1 | 2012-08-04 15:36:56 -0700 | [diff] [blame] | 194 | |
Jiyoung Shin | c15a6b0 | 2012-06-05 01:08:14 -0700 | [diff] [blame] | 195 | ret = exynos_v4l2_streamon(node->fd, type); |
| 196 | |
| 197 | if (ret < 0) |
Sungjoong Kang | ad37861 | 2012-08-17 12:34:33 -0700 | [diff] [blame] | 198 | ALOGE("%s: VIDIOC_STREAMON failed [%d] (%d)",__FUNCTION__, node->fd,ret); |
Jiyoung Shin | c15a6b0 | 2012-06-05 01:08:14 -0700 | [diff] [blame] | 199 | |
| 200 | ALOGV("On streaming I/O... ... fd(%d)", node->fd); |
| 201 | |
| 202 | return ret; |
| 203 | } |
| 204 | |
Sungjoong Kang | 13d8c7b | 2012-07-14 10:20:39 +0900 | [diff] [blame] | 205 | int cam_int_streamoff(node_info_t *node) |
| 206 | { |
Sungjoong Kang | ad37861 | 2012-08-17 12:34:33 -0700 | [diff] [blame] | 207 | enum v4l2_buf_type type = V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE; |
| 208 | int ret; |
Sungjoong Kang | 13d8c7b | 2012-07-14 10:20:39 +0900 | [diff] [blame] | 209 | |
Sungjoong Kang | be494d1 | 2012-08-04 15:36:56 -0700 | [diff] [blame] | 210 | |
Sungjoong Kang | ad37861 | 2012-08-17 12:34:33 -0700 | [diff] [blame] | 211 | ALOGV("Off streaming I/O... fd(%d)", node->fd); |
| 212 | ret = exynos_v4l2_streamoff(node->fd, type); |
Sungjoong Kang | 13d8c7b | 2012-07-14 10:20:39 +0900 | [diff] [blame] | 213 | |
| 214 | if (ret < 0) |
| 215 | ALOGE("%s: VIDIOC_STREAMOFF failed (%d)",__FUNCTION__, ret); |
| 216 | |
Sungjoong Kang | ad37861 | 2012-08-17 12:34:33 -0700 | [diff] [blame] | 217 | return ret; |
Sungjoong Kang | 13d8c7b | 2012-07-14 10:20:39 +0900 | [diff] [blame] | 218 | } |
| 219 | |
Sungjoong Kang | 9dd63e1 | 2012-07-24 00:25:51 +0900 | [diff] [blame] | 220 | int isp_int_streamoff(node_info_t *node) |
| 221 | { |
Sungjoong Kang | ad37861 | 2012-08-17 12:34:33 -0700 | [diff] [blame] | 222 | enum v4l2_buf_type type = V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE; |
| 223 | int ret; |
Sungjoong Kang | 9dd63e1 | 2012-07-24 00:25:51 +0900 | [diff] [blame] | 224 | |
Sungjoong Kang | ad37861 | 2012-08-17 12:34:33 -0700 | [diff] [blame] | 225 | ALOGV("Off streaming I/O... fd(%d)", node->fd); |
| 226 | ret = exynos_v4l2_streamoff(node->fd, type); |
Sungjoong Kang | 9dd63e1 | 2012-07-24 00:25:51 +0900 | [diff] [blame] | 227 | |
| 228 | if (ret < 0) |
| 229 | ALOGE("%s: VIDIOC_STREAMOFF failed (%d)",__FUNCTION__, ret); |
| 230 | |
Sungjoong Kang | ad37861 | 2012-08-17 12:34:33 -0700 | [diff] [blame] | 231 | return ret; |
Sungjoong Kang | 9dd63e1 | 2012-07-24 00:25:51 +0900 | [diff] [blame] | 232 | } |
| 233 | |
Jiyoung Shin | c15a6b0 | 2012-06-05 01:08:14 -0700 | [diff] [blame] | 234 | int cam_int_dqbuf(node_info_t *node) |
| 235 | { |
| 236 | struct v4l2_buffer v4l2_buf; |
| 237 | struct v4l2_plane planes[VIDEO_MAX_PLANES]; |
| 238 | int ret; |
| 239 | |
| 240 | v4l2_buf.type = node->type; |
| 241 | v4l2_buf.memory = node->memory; |
| 242 | v4l2_buf.m.planes = planes; |
| 243 | v4l2_buf.length = node->planes; |
| 244 | |
| 245 | ret = exynos_v4l2_dqbuf(node->fd, &v4l2_buf); |
| 246 | if (ret < 0) |
Sungjoong Kang | 13d8c7b | 2012-07-14 10:20:39 +0900 | [diff] [blame] | 247 | ALOGE("%s: VIDIOC_DQBUF failed (%d)",__FUNCTION__, ret); |
Jiyoung Shin | c15a6b0 | 2012-06-05 01:08:14 -0700 | [diff] [blame] | 248 | |
| 249 | return v4l2_buf.index; |
| 250 | } |
| 251 | |
Sungjoong Kang | feb7df4 | 2012-08-28 23:35:43 +0900 | [diff] [blame] | 252 | int cam_int_dqbuf(node_info_t *node, int num_plane) |
| 253 | { |
| 254 | struct v4l2_buffer v4l2_buf; |
| 255 | struct v4l2_plane planes[VIDEO_MAX_PLANES]; |
| 256 | int ret; |
| 257 | |
| 258 | v4l2_buf.type = node->type; |
| 259 | v4l2_buf.memory = node->memory; |
| 260 | v4l2_buf.m.planes = planes; |
| 261 | v4l2_buf.length = num_plane; |
| 262 | |
| 263 | ret = exynos_v4l2_dqbuf(node->fd, &v4l2_buf); |
| 264 | if (ret < 0) |
| 265 | ALOGE("%s: VIDIOC_DQBUF failed (%d)",__FUNCTION__, ret); |
| 266 | |
| 267 | return v4l2_buf.index; |
| 268 | } |
| 269 | |
Jiyoung Shin | c15a6b0 | 2012-06-05 01:08:14 -0700 | [diff] [blame] | 270 | int cam_int_s_input(node_info_t *node, int index) |
| 271 | { |
| 272 | int ret; |
Sungjoong Kang | 13d8c7b | 2012-07-14 10:20:39 +0900 | [diff] [blame] | 273 | |
Jiyoung Shin | c15a6b0 | 2012-06-05 01:08:14 -0700 | [diff] [blame] | 274 | ret = exynos_v4l2_s_input(node->fd, index); |
| 275 | if (ret < 0) |
Sungjoong Kang | 13d8c7b | 2012-07-14 10:20:39 +0900 | [diff] [blame] | 276 | ALOGE("%s: VIDIOC_S_INPUT failed (%d)",__FUNCTION__, ret); |
Jiyoung Shin | c15a6b0 | 2012-06-05 01:08:14 -0700 | [diff] [blame] | 277 | |
| 278 | return ret; |
| 279 | } |
| 280 | |
| 281 | |
| 282 | gralloc_module_t const* ExynosCameraHWInterface2::m_grallocHal; |
| 283 | |
| 284 | RequestManager::RequestManager(SignalDrivenThread* main_thread): |
| 285 | m_numOfEntries(0), |
Sungjoong Kang | ad37861 | 2012-08-17 12:34:33 -0700 | [diff] [blame] | 286 | m_entryInsertionIndex(-1), |
| 287 | m_entryProcessingIndex(-1), |
| 288 | m_entryFrameOutputIndex(-1), |
Sungjoong Kang | 2bdec06 | 2012-08-17 15:47:56 -0700 | [diff] [blame] | 289 | m_lastAeMode(0), |
| 290 | m_lastAaMode(0), |
| 291 | m_lastAwbMode(0), |
| 292 | m_lastAeComp(0), |
Sungjoong Kang | ad37861 | 2012-08-17 12:34:33 -0700 | [diff] [blame] | 293 | m_frameIndex(-1) |
Jiyoung Shin | c15a6b0 | 2012-06-05 01:08:14 -0700 | [diff] [blame] | 294 | { |
| 295 | m_metadataConverter = new MetadataConverter; |
| 296 | m_mainThread = main_thread; |
Sungjoong Kang | 13d8c7b | 2012-07-14 10:20:39 +0900 | [diff] [blame] | 297 | for (int i=0 ; i<NUM_MAX_REQUEST_MGR_ENTRY; i++) { |
Sungjoong Kang | 13d8c7b | 2012-07-14 10:20:39 +0900 | [diff] [blame] | 298 | memset(&(entries[i]), 0x00, sizeof(request_manager_entry_t)); |
Sungjoong Kang | be494d1 | 2012-08-04 15:36:56 -0700 | [diff] [blame] | 299 | entries[i].internal_shot.shot.ctl.request.frameCount = -1; |
Sungjoong Kang | 13d8c7b | 2012-07-14 10:20:39 +0900 | [diff] [blame] | 300 | } |
Sungjoong Kang | ad37861 | 2012-08-17 12:34:33 -0700 | [diff] [blame] | 301 | m_sensorPipelineSkipCnt = 0; |
Jiyoung Shin | c15a6b0 | 2012-06-05 01:08:14 -0700 | [diff] [blame] | 302 | return; |
| 303 | } |
| 304 | |
| 305 | RequestManager::~RequestManager() |
| 306 | { |
Sungjoong Kang | 15fd823 | 2012-08-23 16:16:44 -0700 | [diff] [blame] | 307 | ALOGV("%s", __FUNCTION__); |
| 308 | if (m_metadataConverter != NULL) { |
| 309 | delete m_metadataConverter; |
| 310 | m_metadataConverter = NULL; |
| 311 | } |
| 312 | |
Jiyoung Shin | c15a6b0 | 2012-06-05 01:08:14 -0700 | [diff] [blame] | 313 | return; |
| 314 | } |
| 315 | |
| 316 | int RequestManager::GetNumEntries() |
| 317 | { |
| 318 | return m_numOfEntries; |
| 319 | } |
| 320 | |
Sungjoong Kang | 9dd63e1 | 2012-07-24 00:25:51 +0900 | [diff] [blame] | 321 | void RequestManager::SetDefaultParameters(int cropX) |
| 322 | { |
| 323 | m_cropX = cropX; |
| 324 | } |
| 325 | |
Jiyoung Shin | c15a6b0 | 2012-06-05 01:08:14 -0700 | [diff] [blame] | 326 | bool RequestManager::IsRequestQueueFull() |
| 327 | { |
| 328 | Mutex::Autolock lock(m_requestMutex); |
| 329 | if (m_numOfEntries>=NUM_MAX_REQUEST_MGR_ENTRY) |
| 330 | return true; |
| 331 | else |
| 332 | return false; |
| 333 | } |
| 334 | |
| 335 | void RequestManager::RegisterRequest(camera_metadata_t * new_request) |
| 336 | { |
Sungjoong Kang | 13d8c7b | 2012-07-14 10:20:39 +0900 | [diff] [blame] | 337 | ALOGV("DEBUG(%s):", __FUNCTION__); |
| 338 | |
Jiyoung Shin | c15a6b0 | 2012-06-05 01:08:14 -0700 | [diff] [blame] | 339 | Mutex::Autolock lock(m_requestMutex); |
Sungjoong Kang | 13d8c7b | 2012-07-14 10:20:39 +0900 | [diff] [blame] | 340 | |
Jiyoung Shin | c15a6b0 | 2012-06-05 01:08:14 -0700 | [diff] [blame] | 341 | request_manager_entry * newEntry = NULL; |
Sungjoong Kang | 9dd63e1 | 2012-07-24 00:25:51 +0900 | [diff] [blame] | 342 | int newInsertionIndex = GetNextIndex(m_entryInsertionIndex); |
Sungjoong Kang | 13d8c7b | 2012-07-14 10:20:39 +0900 | [diff] [blame] | 343 | ALOGV("DEBUG(%s): got lock, new insertIndex(%d), cnt before reg(%d)", __FUNCTION__,newInsertionIndex,m_numOfEntries ); |
Jiyoung Shin | c15a6b0 | 2012-06-05 01:08:14 -0700 | [diff] [blame] | 344 | |
Sungjoong Kang | 13d8c7b | 2012-07-14 10:20:39 +0900 | [diff] [blame] | 345 | |
Jiyoung Shin | c15a6b0 | 2012-06-05 01:08:14 -0700 | [diff] [blame] | 346 | newEntry = &(entries[newInsertionIndex]); |
| 347 | |
| 348 | if (newEntry->status!=EMPTY) { |
Sungjoong Kang | 13d8c7b | 2012-07-14 10:20:39 +0900 | [diff] [blame] | 349 | ALOGV("DEBUG(%s): Circular buffer abnormal ", __FUNCTION__); |
| 350 | return; |
Jiyoung Shin | c15a6b0 | 2012-06-05 01:08:14 -0700 | [diff] [blame] | 351 | } |
| 352 | newEntry->status = REGISTERED; |
| 353 | newEntry->original_request = new_request; |
Sungjoong Kang | ad37861 | 2012-08-17 12:34:33 -0700 | [diff] [blame] | 354 | memset(&(newEntry->internal_shot), 0, sizeof(struct camera2_shot_ext)); |
Sungjoong Kang | 13d8c7b | 2012-07-14 10:20:39 +0900 | [diff] [blame] | 355 | m_metadataConverter->ToInternalShot(new_request, &(newEntry->internal_shot)); |
Sungjoong Kang | b56dcc0 | 2012-08-08 13:38:09 -0700 | [diff] [blame] | 356 | newEntry->output_stream_count = newEntry->internal_shot.shot.ctl.request.outputStreams[15]; |
Jiyoung Shin | c15a6b0 | 2012-06-05 01:08:14 -0700 | [diff] [blame] | 357 | |
| 358 | m_numOfEntries++; |
| 359 | m_entryInsertionIndex = newInsertionIndex; |
| 360 | |
Sungjoong Kang | 13d8c7b | 2012-07-14 10:20:39 +0900 | [diff] [blame] | 361 | |
Jiyoung Shin | c15a6b0 | 2012-06-05 01:08:14 -0700 | [diff] [blame] | 362 | ALOGV("## RegisterReq DONE num(%d), insert(%d), processing(%d), frame(%d), (frameCnt(%d))", |
Sungjoong Kang | be494d1 | 2012-08-04 15:36:56 -0700 | [diff] [blame] | 363 | m_numOfEntries,m_entryInsertionIndex,m_entryProcessingIndex, m_entryFrameOutputIndex, newEntry->internal_shot.shot.ctl.request.frameCount); |
Jiyoung Shin | c15a6b0 | 2012-06-05 01:08:14 -0700 | [diff] [blame] | 364 | } |
| 365 | |
| 366 | void RequestManager::DeregisterRequest(camera_metadata_t ** deregistered_request) |
| 367 | { |
Sungjoong Kang | 13d8c7b | 2012-07-14 10:20:39 +0900 | [diff] [blame] | 368 | ALOGV("DEBUG(%s):", __FUNCTION__); |
Sungjoong Kang | ad37861 | 2012-08-17 12:34:33 -0700 | [diff] [blame] | 369 | int frame_index; |
| 370 | request_manager_entry * currentEntry; |
| 371 | |
Jiyoung Shin | c15a6b0 | 2012-06-05 01:08:14 -0700 | [diff] [blame] | 372 | Mutex::Autolock lock(m_requestMutex); |
| 373 | |
Sungjoong Kang | ad37861 | 2012-08-17 12:34:33 -0700 | [diff] [blame] | 374 | frame_index = GetFrameIndex(); |
| 375 | currentEntry = &(entries[frame_index]); |
Sungjoong Kang | be494d1 | 2012-08-04 15:36:56 -0700 | [diff] [blame] | 376 | if (currentEntry->status != CAPTURED) { |
Sungjoong Kang | ad37861 | 2012-08-17 12:34:33 -0700 | [diff] [blame] | 377 | ALOGV("DBG(%s): Circular buffer abnormal. processing(%d), frame(%d), status(%d) ", __FUNCTION__ |
Jiyoung Shin | c15a6b0 | 2012-06-05 01:08:14 -0700 | [diff] [blame] | 378 | , m_entryProcessingIndex, m_entryFrameOutputIndex,(int)(currentEntry->status)); |
Sungjoong Kang | 13d8c7b | 2012-07-14 10:20:39 +0900 | [diff] [blame] | 379 | return; |
Jiyoung Shin | c15a6b0 | 2012-06-05 01:08:14 -0700 | [diff] [blame] | 380 | } |
Sungjoong Kang | 13d8c7b | 2012-07-14 10:20:39 +0900 | [diff] [blame] | 381 | if (deregistered_request) *deregistered_request = currentEntry->original_request; |
| 382 | |
Jiyoung Shin | c15a6b0 | 2012-06-05 01:08:14 -0700 | [diff] [blame] | 383 | currentEntry->status = EMPTY; |
| 384 | currentEntry->original_request = NULL; |
Sungjoong Kang | be494d1 | 2012-08-04 15:36:56 -0700 | [diff] [blame] | 385 | memset(&(currentEntry->internal_shot), 0, sizeof(struct camera2_shot_ext)); |
| 386 | currentEntry->internal_shot.shot.ctl.request.frameCount = -1; |
Jiyoung Shin | c15a6b0 | 2012-06-05 01:08:14 -0700 | [diff] [blame] | 387 | currentEntry->output_stream_count = 0; |
Sungjoong Kang | 13d8c7b | 2012-07-14 10:20:39 +0900 | [diff] [blame] | 388 | currentEntry->dynamic_meta_vaild = false; |
Jiyoung Shin | c15a6b0 | 2012-06-05 01:08:14 -0700 | [diff] [blame] | 389 | m_numOfEntries--; |
| 390 | ALOGV("## DeRegistReq DONE num(%d), insert(%d), processing(%d), frame(%d)", |
| 391 | m_numOfEntries,m_entryInsertionIndex,m_entryProcessingIndex, m_entryFrameOutputIndex); |
Sungjoong Kang | 13d8c7b | 2012-07-14 10:20:39 +0900 | [diff] [blame] | 392 | |
Jiyoung Shin | c15a6b0 | 2012-06-05 01:08:14 -0700 | [diff] [blame] | 393 | return; |
Jiyoung Shin | c15a6b0 | 2012-06-05 01:08:14 -0700 | [diff] [blame] | 394 | } |
| 395 | |
Sungjoong Kang | 13d8c7b | 2012-07-14 10:20:39 +0900 | [diff] [blame] | 396 | bool RequestManager::PrepareFrame(size_t* num_entries, size_t* frame_size, |
Sungjoong Kang | 0f26b20 | 2012-08-17 15:43:12 -0700 | [diff] [blame] | 397 | camera_metadata_t ** prepared_frame, int afState) |
Jiyoung Shin | c15a6b0 | 2012-06-05 01:08:14 -0700 | [diff] [blame] | 398 | { |
Sungjoong Kang | 13d8c7b | 2012-07-14 10:20:39 +0900 | [diff] [blame] | 399 | ALOGV("DEBUG(%s):", __FUNCTION__); |
Jiyoung Shin | c15a6b0 | 2012-06-05 01:08:14 -0700 | [diff] [blame] | 400 | Mutex::Autolock lock(m_requestMutex); |
| 401 | status_t res = NO_ERROR; |
Sungjoong Kang | ad37861 | 2012-08-17 12:34:33 -0700 | [diff] [blame] | 402 | int tempFrameOutputIndex = GetFrameIndex(); |
Sungjoong Kang | 13d8c7b | 2012-07-14 10:20:39 +0900 | [diff] [blame] | 403 | request_manager_entry * currentEntry = &(entries[tempFrameOutputIndex]); |
| 404 | ALOGV("DEBUG(%s): processing(%d), frameOut(%d), insert(%d) recentlycompleted(%d)", __FUNCTION__, |
| 405 | m_entryProcessingIndex, m_entryFrameOutputIndex, m_entryInsertionIndex, m_completedIndex); |
| 406 | |
Sungjoong Kang | be494d1 | 2012-08-04 15:36:56 -0700 | [diff] [blame] | 407 | if (currentEntry->status != CAPTURED) { |
Sungjoong Kang | ad37861 | 2012-08-17 12:34:33 -0700 | [diff] [blame] | 408 | ALOGV("DBG(%s): Circular buffer abnormal status(%d)", __FUNCTION__, (int)(currentEntry->status)); |
Sungjoong Kang | 13d8c7b | 2012-07-14 10:20:39 +0900 | [diff] [blame] | 409 | |
| 410 | return false; |
| 411 | } |
| 412 | m_entryFrameOutputIndex = tempFrameOutputIndex; |
Sungjoong Kang | fd2d78a | 2012-08-26 17:44:25 -0700 | [diff] [blame] | 413 | m_tempFrameMetadata = place_camera_metadata(m_tempFrameMetadataBuf, 2000, 20, 500); //estimated |
Sungjoong Kang | 0f26b20 | 2012-08-17 15:43:12 -0700 | [diff] [blame] | 414 | add_camera_metadata_entry(m_tempFrameMetadata, ANDROID_CONTROL_AF_STATE, &afState, 1); |
Sungjoong Kang | 13d8c7b | 2012-07-14 10:20:39 +0900 | [diff] [blame] | 415 | res = m_metadataConverter->ToDynamicMetadata(&(currentEntry->internal_shot), |
Jiyoung Shin | c15a6b0 | 2012-06-05 01:08:14 -0700 | [diff] [blame] | 416 | m_tempFrameMetadata); |
| 417 | if (res!=NO_ERROR) { |
Sungjoong Kang | 13d8c7b | 2012-07-14 10:20:39 +0900 | [diff] [blame] | 418 | ALOGE("ERROR(%s): ToDynamicMetadata (%d) ", __FUNCTION__, res); |
| 419 | return false; |
Jiyoung Shin | c15a6b0 | 2012-06-05 01:08:14 -0700 | [diff] [blame] | 420 | } |
| 421 | *num_entries = get_camera_metadata_entry_count(m_tempFrameMetadata); |
| 422 | *frame_size = get_camera_metadata_size(m_tempFrameMetadata); |
| 423 | *prepared_frame = m_tempFrameMetadata; |
Sungjoong Kang | 13d8c7b | 2012-07-14 10:20:39 +0900 | [diff] [blame] | 424 | ALOGV("## PrepareFrame DONE: frameOut(%d) frameCnt-req(%d)", m_entryFrameOutputIndex, |
Sungjoong Kang | be494d1 | 2012-08-04 15:36:56 -0700 | [diff] [blame] | 425 | currentEntry->internal_shot.shot.ctl.request.frameCount); |
Sungjoong Kang | 9dd63e1 | 2012-07-24 00:25:51 +0900 | [diff] [blame] | 426 | // Dump(); |
Sungjoong Kang | 13d8c7b | 2012-07-14 10:20:39 +0900 | [diff] [blame] | 427 | return true; |
Jiyoung Shin | c15a6b0 | 2012-06-05 01:08:14 -0700 | [diff] [blame] | 428 | } |
| 429 | |
Sungjoong Kang | 0f26b20 | 2012-08-17 15:43:12 -0700 | [diff] [blame] | 430 | int RequestManager::MarkProcessingRequest(ExynosBuffer* buf, int *afMode) |
Jiyoung Shin | c15a6b0 | 2012-06-05 01:08:14 -0700 | [diff] [blame] | 431 | { |
Sungjoong Kang | ad37861 | 2012-08-17 12:34:33 -0700 | [diff] [blame] | 432 | |
Jiyoung Shin | c15a6b0 | 2012-06-05 01:08:14 -0700 | [diff] [blame] | 433 | Mutex::Autolock lock(m_requestMutex); |
Sungjoong Kang | 13d8c7b | 2012-07-14 10:20:39 +0900 | [diff] [blame] | 434 | struct camera2_shot_ext * shot_ext; |
Sungjoong Kang | b56dcc0 | 2012-08-08 13:38:09 -0700 | [diff] [blame] | 435 | struct camera2_shot_ext * request_shot; |
Sungjoong Kang | 13d8c7b | 2012-07-14 10:20:39 +0900 | [diff] [blame] | 436 | int targetStreamIndex = 0; |
Sungjoong Kang | ad37861 | 2012-08-17 12:34:33 -0700 | [diff] [blame] | 437 | request_manager_entry * newEntry = NULL; |
Sungjoong Kang | 0f26b20 | 2012-08-17 15:43:12 -0700 | [diff] [blame] | 438 | static int count = 0; |
Sungjoong Kang | 13d8c7b | 2012-07-14 10:20:39 +0900 | [diff] [blame] | 439 | |
Sungjoong Kang | 13d8c7b | 2012-07-14 10:20:39 +0900 | [diff] [blame] | 440 | if (m_numOfEntries == 0) { |
Sungjoong Kang | ad37861 | 2012-08-17 12:34:33 -0700 | [diff] [blame] | 441 | ALOGD("DEBUG(%s): Request Manager Empty ", __FUNCTION__); |
Sungjoong Kang | 13d8c7b | 2012-07-14 10:20:39 +0900 | [diff] [blame] | 442 | return -1; |
| 443 | } |
| 444 | |
| 445 | if ((m_entryProcessingIndex == m_entryInsertionIndex) |
Sungjoong Kang | be494d1 | 2012-08-04 15:36:56 -0700 | [diff] [blame] | 446 | && (entries[m_entryProcessingIndex].status == REQUESTED || entries[m_entryProcessingIndex].status == CAPTURED)) { |
Sungjoong Kang | ad37861 | 2012-08-17 12:34:33 -0700 | [diff] [blame] | 447 | ALOGD("## MarkProcReq skipping(request underrun) - num(%d), insert(%d), processing(%d), frame(%d)", |
Sungjoong Kang | 13d8c7b | 2012-07-14 10:20:39 +0900 | [diff] [blame] | 448 | m_numOfEntries,m_entryInsertionIndex,m_entryProcessingIndex, m_entryFrameOutputIndex); |
| 449 | return -1; |
| 450 | } |
Jiyoung Shin | c15a6b0 | 2012-06-05 01:08:14 -0700 | [diff] [blame] | 451 | |
Sungjoong Kang | 9dd63e1 | 2012-07-24 00:25:51 +0900 | [diff] [blame] | 452 | int newProcessingIndex = GetNextIndex(m_entryProcessingIndex); |
Sungjoong Kang | ad37861 | 2012-08-17 12:34:33 -0700 | [diff] [blame] | 453 | ALOGV("DEBUG(%s): index(%d)", __FUNCTION__, newProcessingIndex); |
Jiyoung Shin | c15a6b0 | 2012-06-05 01:08:14 -0700 | [diff] [blame] | 454 | |
Jiyoung Shin | c15a6b0 | 2012-06-05 01:08:14 -0700 | [diff] [blame] | 455 | newEntry = &(entries[newProcessingIndex]); |
Sungjoong Kang | ad37861 | 2012-08-17 12:34:33 -0700 | [diff] [blame] | 456 | request_shot = &(newEntry->internal_shot); |
Sungjoong Kang | 0f26b20 | 2012-08-17 15:43:12 -0700 | [diff] [blame] | 457 | *afMode = (int)(newEntry->internal_shot.shot.ctl.aa.afMode); |
Sungjoong Kang | be494d1 | 2012-08-04 15:36:56 -0700 | [diff] [blame] | 458 | if (newEntry->status != REGISTERED) { |
Sungjoong Kang | ad37861 | 2012-08-17 12:34:33 -0700 | [diff] [blame] | 459 | ALOGD("DEBUG(%s)(%d): Circular buffer abnormal ", __FUNCTION__, newProcessingIndex); |
Sungjoong Kang | 13d8c7b | 2012-07-14 10:20:39 +0900 | [diff] [blame] | 460 | return -1; |
Jiyoung Shin | c15a6b0 | 2012-06-05 01:08:14 -0700 | [diff] [blame] | 461 | } |
Sungjoong Kang | ad37861 | 2012-08-17 12:34:33 -0700 | [diff] [blame] | 462 | |
Sungjoong Kang | be494d1 | 2012-08-04 15:36:56 -0700 | [diff] [blame] | 463 | newEntry->status = REQUESTED; |
Jiyoung Shin | c15a6b0 | 2012-06-05 01:08:14 -0700 | [diff] [blame] | 464 | |
Sungjoong Kang | ad37861 | 2012-08-17 12:34:33 -0700 | [diff] [blame] | 465 | shot_ext = (struct camera2_shot_ext *)buf->virt.extP[1]; |
Sungjoong Kang | 13d8c7b | 2012-07-14 10:20:39 +0900 | [diff] [blame] | 466 | |
Sungjoong Kang | ad37861 | 2012-08-17 12:34:33 -0700 | [diff] [blame] | 467 | memset(shot_ext, 0x00, sizeof(struct camera2_shot_ext)); |
| 468 | shot_ext->shot.ctl.request.frameCount = request_shot->shot.ctl.request.frameCount; |
Sungjoong Kang | 13d8c7b | 2012-07-14 10:20:39 +0900 | [diff] [blame] | 469 | shot_ext->request_sensor = 1; |
Sungjoong Kang | 9dd63e1 | 2012-07-24 00:25:51 +0900 | [diff] [blame] | 470 | shot_ext->dis_bypass = 1; |
| 471 | shot_ext->dnr_bypass = 1; |
Sungjoong Kang | ad37861 | 2012-08-17 12:34:33 -0700 | [diff] [blame] | 472 | shot_ext->fd_bypass = 1; |
| 473 | shot_ext->setfile = 0; |
| 474 | |
Sungjoong Kang | 13d8c7b | 2012-07-14 10:20:39 +0900 | [diff] [blame] | 475 | for (int i = 0; i < newEntry->output_stream_count; i++) { |
Sungjoong Kang | be494d1 | 2012-08-04 15:36:56 -0700 | [diff] [blame] | 476 | targetStreamIndex = newEntry->internal_shot.shot.ctl.request.outputStreams[i]; |
Sungjoong Kang | 13d8c7b | 2012-07-14 10:20:39 +0900 | [diff] [blame] | 477 | |
| 478 | if (targetStreamIndex==0) { |
| 479 | ALOGV("DEBUG(%s): outputstreams(%d) is for scalerP", __FUNCTION__, i); |
| 480 | shot_ext->request_scp = 1; |
Sungjoong Kang | fd2d78a | 2012-08-26 17:44:25 -0700 | [diff] [blame] | 481 | if (shot_ext->shot.ctl.stats.faceDetectMode != FACEDETECT_MODE_OFF) |
| 482 | shot_ext->fd_bypass = 0; |
Sungjoong Kang | 13d8c7b | 2012-07-14 10:20:39 +0900 | [diff] [blame] | 483 | } |
Sungjoong Kang | 9dd63e1 | 2012-07-24 00:25:51 +0900 | [diff] [blame] | 484 | else if (targetStreamIndex == 1) { |
Sungjoong Kang | 13d8c7b | 2012-07-14 10:20:39 +0900 | [diff] [blame] | 485 | ALOGV("DEBUG(%s): outputstreams(%d) is for scalerC", __FUNCTION__, i); |
| 486 | shot_ext->request_scc = 1; |
Sungjoong Kang | 9dd63e1 | 2012-07-24 00:25:51 +0900 | [diff] [blame] | 487 | } |
| 488 | else if (targetStreamIndex == 2) { |
| 489 | ALOGV("DEBUG(%s): outputstreams(%d) is for scalerP (record)", __FUNCTION__, i); |
| 490 | shot_ext->request_scp = 1; |
| 491 | shot_ext->shot.ctl.request.outputStreams[2] = 1; |
Sungjoong Kang | fd2d78a | 2012-08-26 17:44:25 -0700 | [diff] [blame] | 492 | if (shot_ext->shot.ctl.stats.faceDetectMode != FACEDETECT_MODE_OFF) |
| 493 | shot_ext->fd_bypass = 0; |
Sungjoong Kang | 13d8c7b | 2012-07-14 10:20:39 +0900 | [diff] [blame] | 494 | } |
Sungjoong Kang | 74d78eb | 2012-08-29 13:25:46 -0700 | [diff] [blame] | 495 | else if (targetStreamIndex == 3) { |
| 496 | ALOGV("DEBUG(%s): outputstreams(%d) is for scalerP (previewCb)", __FUNCTION__, i); |
| 497 | shot_ext->request_scp = 1; |
| 498 | shot_ext->shot.ctl.request.outputStreams[3] = 1; |
| 499 | } |
Sungjoong Kang | 13d8c7b | 2012-07-14 10:20:39 +0900 | [diff] [blame] | 500 | else { |
| 501 | ALOGV("DEBUG(%s): outputstreams(%d) has abnormal value(%d)", __FUNCTION__, i, targetStreamIndex); |
| 502 | } |
| 503 | } |
Sungjoong Kang | ad37861 | 2012-08-17 12:34:33 -0700 | [diff] [blame] | 504 | |
Sungjoong Kang | 0f26b20 | 2012-08-17 15:43:12 -0700 | [diff] [blame] | 505 | if (count == 0){ |
| 506 | shot_ext->shot.ctl.aa.mode = AA_CONTROL_AUTO; |
| 507 | } else |
| 508 | shot_ext->shot.ctl.aa.mode = AA_CONTROL_NONE; |
| 509 | |
| 510 | count++; |
Sungjoong Kang | ad37861 | 2012-08-17 12:34:33 -0700 | [diff] [blame] | 511 | shot_ext->shot.ctl.request.metadataMode = METADATA_MODE_FULL; |
| 512 | shot_ext->shot.ctl.stats.faceDetectMode = FACEDETECT_MODE_FULL; |
| 513 | shot_ext->shot.magicNumber = 0x23456789; |
| 514 | shot_ext->shot.ctl.sensor.exposureTime = 0; |
| 515 | shot_ext->shot.ctl.sensor.frameDuration = 33*1000*1000; |
| 516 | shot_ext->shot.ctl.sensor.sensitivity = 0; |
| 517 | |
Sungjoong Kang | e4657e3 | 2012-08-28 15:02:19 -0700 | [diff] [blame] | 518 | |
| 519 | shot_ext->shot.ctl.scaler.cropRegion[0] = newEntry->internal_shot.shot.ctl.scaler.cropRegion[0]; |
| 520 | shot_ext->shot.ctl.scaler.cropRegion[1] = newEntry->internal_shot.shot.ctl.scaler.cropRegion[1]; |
| 521 | shot_ext->shot.ctl.scaler.cropRegion[2] = newEntry->internal_shot.shot.ctl.scaler.cropRegion[2]; |
Sungjoong Kang | ad37861 | 2012-08-17 12:34:33 -0700 | [diff] [blame] | 522 | |
Sungjoong Kang | 13d8c7b | 2012-07-14 10:20:39 +0900 | [diff] [blame] | 523 | m_entryProcessingIndex = newProcessingIndex; |
Sungjoong Kang | ad37861 | 2012-08-17 12:34:33 -0700 | [diff] [blame] | 524 | return newProcessingIndex; |
Jiyoung Shin | c15a6b0 | 2012-06-05 01:08:14 -0700 | [diff] [blame] | 525 | } |
| 526 | |
Sungjoong Kang | 9dd63e1 | 2012-07-24 00:25:51 +0900 | [diff] [blame] | 527 | void RequestManager::NotifyStreamOutput(int frameCnt, int stream_id) |
Jiyoung Shin | c15a6b0 | 2012-06-05 01:08:14 -0700 | [diff] [blame] | 528 | { |
Sungjoong Kang | 9dd63e1 | 2012-07-24 00:25:51 +0900 | [diff] [blame] | 529 | int index; |
| 530 | |
| 531 | ALOGV("DEBUG(%s): frameCnt(%d), stream_id(%d)", __FUNCTION__, frameCnt, stream_id); |
| 532 | |
| 533 | index = FindEntryIndexByFrameCnt(frameCnt); |
| 534 | if (index == -1) { |
| 535 | ALOGE("ERR(%s): Cannot find entry for frameCnt(%d)", __FUNCTION__, frameCnt); |
| 536 | return; |
| 537 | } |
| 538 | ALOGV("DEBUG(%s): frameCnt(%d), stream_id(%d) last cnt (%d)", __FUNCTION__, frameCnt, stream_id, entries[index].output_stream_count); |
| 539 | |
Sungjoong Kang | be494d1 | 2012-08-04 15:36:56 -0700 | [diff] [blame] | 540 | entries[index].output_stream_count--; //TODO : match stream id also |
| 541 | CheckCompleted(index); |
Jiyoung Shin | c15a6b0 | 2012-06-05 01:08:14 -0700 | [diff] [blame] | 542 | return; |
| 543 | } |
| 544 | |
Sungjoong Kang | 13d8c7b | 2012-07-14 10:20:39 +0900 | [diff] [blame] | 545 | void RequestManager::CheckCompleted(int index) |
| 546 | { |
Sungjoong Kang | 9dd63e1 | 2012-07-24 00:25:51 +0900 | [diff] [blame] | 547 | ALOGV("DEBUG(%s): reqIndex(%d) current Count(%d)", __FUNCTION__, index, entries[index].output_stream_count); |
Sungjoong Kang | ad37861 | 2012-08-17 12:34:33 -0700 | [diff] [blame] | 548 | SetFrameIndex(index); |
| 549 | m_mainThread->SetSignal(SIGNAL_MAIN_STREAM_OUTPUT_DONE); |
Sungjoong Kang | 13d8c7b | 2012-07-14 10:20:39 +0900 | [diff] [blame] | 550 | return; |
| 551 | } |
Sungjoong Kang | 13d8c7b | 2012-07-14 10:20:39 +0900 | [diff] [blame] | 552 | |
Sungjoong Kang | ad37861 | 2012-08-17 12:34:33 -0700 | [diff] [blame] | 553 | void RequestManager::SetFrameIndex(int index) |
| 554 | { |
| 555 | Mutex::Autolock lock(m_requestMutex); |
| 556 | m_frameIndex = index; |
| 557 | } |
| 558 | |
| 559 | int RequestManager::GetFrameIndex() |
| 560 | { |
| 561 | return m_frameIndex; |
| 562 | } |
| 563 | |
| 564 | void RequestManager::ApplyDynamicMetadata(struct camera2_shot_ext *shot_ext) |
Sungjoong Kang | 13d8c7b | 2012-07-14 10:20:39 +0900 | [diff] [blame] | 565 | { |
Sungjoong Kang | 9dd63e1 | 2012-07-24 00:25:51 +0900 | [diff] [blame] | 566 | int index; |
Sungjoong Kang | b56dcc0 | 2012-08-08 13:38:09 -0700 | [diff] [blame] | 567 | struct camera2_shot_ext * request_shot; |
| 568 | nsecs_t timeStamp; |
Sungjoong Kang | ad37861 | 2012-08-17 12:34:33 -0700 | [diff] [blame] | 569 | int i; |
Sungjoong Kang | 9dd63e1 | 2012-07-24 00:25:51 +0900 | [diff] [blame] | 570 | |
Sungjoong Kang | ad37861 | 2012-08-17 12:34:33 -0700 | [diff] [blame] | 571 | ALOGV("DEBUG(%s): frameCnt(%d)", __FUNCTION__, shot_ext->shot.ctl.request.frameCount); |
Sungjoong Kang | 9dd63e1 | 2012-07-24 00:25:51 +0900 | [diff] [blame] | 572 | |
Sungjoong Kang | ad37861 | 2012-08-17 12:34:33 -0700 | [diff] [blame] | 573 | for (i = 0 ; i < NUM_MAX_REQUEST_MGR_ENTRY ; i++) { |
| 574 | if((entries[i].internal_shot.shot.ctl.request.frameCount == shot_ext->shot.ctl.request.frameCount) |
| 575 | && (entries[i].status == CAPTURED)) |
| 576 | break; |
| 577 | } |
| 578 | |
| 579 | if (i == NUM_MAX_REQUEST_MGR_ENTRY){ |
| 580 | ALOGE("[%s] no entry found(framecount:%d)", __FUNCTION__, shot_ext->shot.ctl.request.frameCount); |
Sungjoong Kang | 9dd63e1 | 2012-07-24 00:25:51 +0900 | [diff] [blame] | 581 | return; |
| 582 | } |
| 583 | |
Sungjoong Kang | ad37861 | 2012-08-17 12:34:33 -0700 | [diff] [blame] | 584 | request_manager_entry * newEntry = &(entries[i]); |
Sungjoong Kang | b56dcc0 | 2012-08-08 13:38:09 -0700 | [diff] [blame] | 585 | request_shot = &(newEntry->internal_shot); |
Sungjoong Kang | 9dd63e1 | 2012-07-24 00:25:51 +0900 | [diff] [blame] | 586 | |
Sungjoong Kang | be494d1 | 2012-08-04 15:36:56 -0700 | [diff] [blame] | 587 | newEntry->dynamic_meta_vaild = true; |
Sungjoong Kang | b56dcc0 | 2012-08-08 13:38:09 -0700 | [diff] [blame] | 588 | timeStamp = request_shot->shot.dm.sensor.timeStamp; |
Sungjoong Kang | ad37861 | 2012-08-17 12:34:33 -0700 | [diff] [blame] | 589 | memcpy(&(request_shot->shot.dm), &(shot_ext->shot.dm), sizeof(struct camera2_dm)); |
Sungjoong Kang | b56dcc0 | 2012-08-08 13:38:09 -0700 | [diff] [blame] | 590 | request_shot->shot.dm.sensor.timeStamp = timeStamp; |
Sungjoong Kang | ad37861 | 2012-08-17 12:34:33 -0700 | [diff] [blame] | 591 | CheckCompleted(i); |
Sungjoong Kang | 13d8c7b | 2012-07-14 10:20:39 +0900 | [diff] [blame] | 592 | } |
| 593 | |
| 594 | void RequestManager::DumpInfoWithIndex(int index) |
| 595 | { |
Sungjoong Kang | be494d1 | 2012-08-04 15:36:56 -0700 | [diff] [blame] | 596 | struct camera2_shot_ext * currMetadata = &(entries[index].internal_shot); |
Sungjoong Kang | 13d8c7b | 2012-07-14 10:20:39 +0900 | [diff] [blame] | 597 | |
| 598 | ALOGV("#### frameCount(%d) exposureTime(%lld) ISO(%d)", |
Sungjoong Kang | be494d1 | 2012-08-04 15:36:56 -0700 | [diff] [blame] | 599 | currMetadata->shot.ctl.request.frameCount, |
| 600 | currMetadata->shot.ctl.sensor.exposureTime, |
| 601 | currMetadata->shot.ctl.sensor.sensitivity); |
Sungjoong Kang | b56dcc0 | 2012-08-08 13:38:09 -0700 | [diff] [blame] | 602 | if (currMetadata->shot.ctl.request.outputStreams[15] == 0) |
Sungjoong Kang | 13d8c7b | 2012-07-14 10:20:39 +0900 | [diff] [blame] | 603 | ALOGV("#### No output stream selected"); |
Sungjoong Kang | b56dcc0 | 2012-08-08 13:38:09 -0700 | [diff] [blame] | 604 | else if (currMetadata->shot.ctl.request.outputStreams[15] == 1) |
Sungjoong Kang | be494d1 | 2012-08-04 15:36:56 -0700 | [diff] [blame] | 605 | ALOGV("#### OutputStreamId : %d", currMetadata->shot.ctl.request.outputStreams[0]); |
Sungjoong Kang | b56dcc0 | 2012-08-08 13:38:09 -0700 | [diff] [blame] | 606 | else if (currMetadata->shot.ctl.request.outputStreams[15] == 2) |
Sungjoong Kang | be494d1 | 2012-08-04 15:36:56 -0700 | [diff] [blame] | 607 | ALOGV("#### OutputStreamId : %d, %d", currMetadata->shot.ctl.request.outputStreams[0], |
| 608 | currMetadata->shot.ctl.request.outputStreams[1]); |
Sungjoong Kang | 13d8c7b | 2012-07-14 10:20:39 +0900 | [diff] [blame] | 609 | else |
Sungjoong Kang | b56dcc0 | 2012-08-08 13:38:09 -0700 | [diff] [blame] | 610 | ALOGV("#### OutputStream num (%d) abnormal ", currMetadata->shot.ctl.request.outputStreams[15]); |
Sungjoong Kang | 13d8c7b | 2012-07-14 10:20:39 +0900 | [diff] [blame] | 611 | } |
| 612 | |
Sungjoong Kang | ef6f83c | 2012-08-28 22:59:48 +0900 | [diff] [blame] | 613 | void RequestManager::UpdateIspParameters(struct camera2_shot_ext *shot_ext, int frameCnt) |
Sungjoong Kang | 13d8c7b | 2012-07-14 10:20:39 +0900 | [diff] [blame] | 614 | { |
Sungjoong Kang | 9dd63e1 | 2012-07-24 00:25:51 +0900 | [diff] [blame] | 615 | int index, targetStreamIndex; |
Sungjoong Kang | b56dcc0 | 2012-08-08 13:38:09 -0700 | [diff] [blame] | 616 | struct camera2_shot_ext * request_shot; |
Sungjoong Kang | 9dd63e1 | 2012-07-24 00:25:51 +0900 | [diff] [blame] | 617 | |
| 618 | ALOGV("DEBUG(%s): updating info with frameCnt(%d)", __FUNCTION__, frameCnt); |
| 619 | if (frameCnt < 0) |
Sungjoong Kang | 13d8c7b | 2012-07-14 10:20:39 +0900 | [diff] [blame] | 620 | return; |
Sungjoong Kang | 9dd63e1 | 2012-07-24 00:25:51 +0900 | [diff] [blame] | 621 | |
| 622 | index = FindEntryIndexByFrameCnt(frameCnt); |
| 623 | if (index == -1) { |
| 624 | ALOGE("ERR(%s): Cannot find entry for frameCnt(%d)", __FUNCTION__, frameCnt); |
| 625 | return; |
| 626 | } |
| 627 | |
Sungjoong Kang | 13d8c7b | 2012-07-14 10:20:39 +0900 | [diff] [blame] | 628 | request_manager_entry * newEntry = &(entries[index]); |
Sungjoong Kang | ad37861 | 2012-08-17 12:34:33 -0700 | [diff] [blame] | 629 | request_shot = &(newEntry->internal_shot); |
Sungjoong Kang | 2bdec06 | 2012-08-17 15:47:56 -0700 | [diff] [blame] | 630 | memcpy(&(shot_ext->shot.ctl), &(request_shot->shot.ctl), sizeof(struct camera2_ctl)); |
Sungjoong Kang | 13d8c7b | 2012-07-14 10:20:39 +0900 | [diff] [blame] | 631 | shot_ext->request_sensor = 1; |
Sungjoong Kang | ad37861 | 2012-08-17 12:34:33 -0700 | [diff] [blame] | 632 | shot_ext->dis_bypass = 1; |
| 633 | shot_ext->dnr_bypass = 1; |
| 634 | shot_ext->fd_bypass = 1; |
| 635 | shot_ext->setfile = 0; |
| 636 | |
Sungjoong Kang | 13d8c7b | 2012-07-14 10:20:39 +0900 | [diff] [blame] | 637 | shot_ext->request_scc = 0; |
| 638 | shot_ext->request_scp = 0; |
Sungjoong Kang | ad37861 | 2012-08-17 12:34:33 -0700 | [diff] [blame] | 639 | |
Sungjoong Kang | 9dd63e1 | 2012-07-24 00:25:51 +0900 | [diff] [blame] | 640 | shot_ext->shot.ctl.request.outputStreams[0] = 0; |
| 641 | shot_ext->shot.ctl.request.outputStreams[1] = 0; |
| 642 | shot_ext->shot.ctl.request.outputStreams[2] = 0; |
Sungjoong Kang | 74d78eb | 2012-08-29 13:25:46 -0700 | [diff] [blame] | 643 | shot_ext->shot.ctl.request.outputStreams[3] = 0; |
Sungjoong Kang | 9dd63e1 | 2012-07-24 00:25:51 +0900 | [diff] [blame] | 644 | |
Sungjoong Kang | e4657e3 | 2012-08-28 15:02:19 -0700 | [diff] [blame] | 645 | shot_ext->shot.ctl.scaler.cropRegion[0] = request_shot->shot.ctl.scaler.cropRegion[0]; |
| 646 | shot_ext->shot.ctl.scaler.cropRegion[1] = request_shot->shot.ctl.scaler.cropRegion[1]; |
| 647 | shot_ext->shot.ctl.scaler.cropRegion[2] = request_shot->shot.ctl.scaler.cropRegion[2]; |
| 648 | |
Sungjoong Kang | 2bdec06 | 2012-08-17 15:47:56 -0700 | [diff] [blame] | 649 | if (m_lastAaMode == request_shot->shot.ctl.aa.mode) { |
| 650 | shot_ext->shot.ctl.aa.mode = (enum aa_mode)(0); |
| 651 | } |
| 652 | else { |
| 653 | shot_ext->shot.ctl.aa.mode = request_shot->shot.ctl.aa.mode; |
| 654 | m_lastAaMode = (int)(shot_ext->shot.ctl.aa.mode); |
| 655 | } |
| 656 | if (m_lastAeMode == request_shot->shot.ctl.aa.aeMode) { |
| 657 | shot_ext->shot.ctl.aa.aeMode = (enum aa_aemode)(0); |
| 658 | } |
| 659 | else { |
| 660 | shot_ext->shot.ctl.aa.aeMode = request_shot->shot.ctl.aa.aeMode; |
| 661 | m_lastAeMode = (int)(shot_ext->shot.ctl.aa.aeMode); |
| 662 | } |
| 663 | if (m_lastAwbMode == request_shot->shot.ctl.aa.awbMode) { |
| 664 | shot_ext->shot.ctl.aa.awbMode = (enum aa_awbmode)(0); |
| 665 | } |
| 666 | else { |
| 667 | shot_ext->shot.ctl.aa.awbMode = request_shot->shot.ctl.aa.awbMode; |
| 668 | m_lastAwbMode = (int)(shot_ext->shot.ctl.aa.awbMode); |
| 669 | } |
| 670 | if (m_lastAeComp == request_shot->shot.ctl.aa.aeExpCompensation) { |
| 671 | shot_ext->shot.ctl.aa.aeExpCompensation = 0; |
| 672 | } |
| 673 | else { |
| 674 | shot_ext->shot.ctl.aa.aeExpCompensation = request_shot->shot.ctl.aa.aeExpCompensation; |
| 675 | m_lastAeComp = (int)(shot_ext->shot.ctl.aa.aeExpCompensation); |
| 676 | } |
Sungjoong Kang | ef6f83c | 2012-08-28 22:59:48 +0900 | [diff] [blame] | 677 | |
| 678 | shot_ext->shot.ctl.aa.afTrigger = 0; |
| 679 | |
Sungjoong Kang | 13d8c7b | 2012-07-14 10:20:39 +0900 | [diff] [blame] | 680 | for (int i = 0; i < newEntry->output_stream_count; i++) { |
Sungjoong Kang | ad37861 | 2012-08-17 12:34:33 -0700 | [diff] [blame] | 681 | targetStreamIndex = newEntry->internal_shot.shot.ctl.request.outputStreams[i]; |
Sungjoong Kang | 13d8c7b | 2012-07-14 10:20:39 +0900 | [diff] [blame] | 682 | |
| 683 | if (targetStreamIndex==0) { |
Sungjoong Kang | ad37861 | 2012-08-17 12:34:33 -0700 | [diff] [blame] | 684 | ALOGV("DEBUG(%s): outputstreams(%d) is for scalerP", __FUNCTION__, i); |
Sungjoong Kang | 13d8c7b | 2012-07-14 10:20:39 +0900 | [diff] [blame] | 685 | shot_ext->request_scp = 1; |
Sungjoong Kang | fd2d78a | 2012-08-26 17:44:25 -0700 | [diff] [blame] | 686 | if (shot_ext->shot.ctl.stats.faceDetectMode != FACEDETECT_MODE_OFF) |
| 687 | shot_ext->fd_bypass = 0; |
Sungjoong Kang | 13d8c7b | 2012-07-14 10:20:39 +0900 | [diff] [blame] | 688 | } |
Sungjoong Kang | 9dd63e1 | 2012-07-24 00:25:51 +0900 | [diff] [blame] | 689 | else if (targetStreamIndex == 1) { |
Sungjoong Kang | ad37861 | 2012-08-17 12:34:33 -0700 | [diff] [blame] | 690 | ALOGV("DEBUG(%s): outputstreams(%d) is for scalerC", __FUNCTION__, i); |
Sungjoong Kang | 13d8c7b | 2012-07-14 10:20:39 +0900 | [diff] [blame] | 691 | shot_ext->request_scc = 1; |
Sungjoong Kang | fd2d78a | 2012-08-26 17:44:25 -0700 | [diff] [blame] | 692 | if (shot_ext->shot.ctl.stats.faceDetectMode != FACEDETECT_MODE_OFF) |
| 693 | shot_ext->fd_bypass = 0; |
Sungjoong Kang | 9dd63e1 | 2012-07-24 00:25:51 +0900 | [diff] [blame] | 694 | } |
| 695 | else if (targetStreamIndex == 2) { |
Sungjoong Kang | ad37861 | 2012-08-17 12:34:33 -0700 | [diff] [blame] | 696 | ALOGV("DEBUG(%s): outputstreams(%d) is for scalerP (record)", __FUNCTION__, i); |
Sungjoong Kang | 9dd63e1 | 2012-07-24 00:25:51 +0900 | [diff] [blame] | 697 | shot_ext->request_scp = 1; |
| 698 | shot_ext->shot.ctl.request.outputStreams[2] = 1; |
Sungjoong Kang | 2bdec06 | 2012-08-17 15:47:56 -0700 | [diff] [blame] | 699 | shot_ext->shot.ctl.aa.aeTargetFpsRange[0] = 30; |
| 700 | shot_ext->shot.ctl.aa.aeTargetFpsRange[1] = 30; |
Sungjoong Kang | fd2d78a | 2012-08-26 17:44:25 -0700 | [diff] [blame] | 701 | if (shot_ext->shot.ctl.stats.faceDetectMode != FACEDETECT_MODE_OFF) |
| 702 | shot_ext->fd_bypass = 0; |
Sungjoong Kang | 13d8c7b | 2012-07-14 10:20:39 +0900 | [diff] [blame] | 703 | } |
Sungjoong Kang | 74d78eb | 2012-08-29 13:25:46 -0700 | [diff] [blame] | 704 | else if (targetStreamIndex == 3) { |
| 705 | ALOGV("DEBUG(%s): outputstreams(%d) is for scalerP (previewCb)", __FUNCTION__, i); |
| 706 | shot_ext->request_scp = 1; |
| 707 | shot_ext->shot.ctl.request.outputStreams[3] = 1; |
| 708 | } |
Sungjoong Kang | 13d8c7b | 2012-07-14 10:20:39 +0900 | [diff] [blame] | 709 | else { |
Sungjoong Kang | ad37861 | 2012-08-17 12:34:33 -0700 | [diff] [blame] | 710 | ALOGV("DEBUG(%s): outputstreams(%d) has abnormal value(%d)", __FUNCTION__, i, targetStreamIndex); |
Sungjoong Kang | 13d8c7b | 2012-07-14 10:20:39 +0900 | [diff] [blame] | 711 | } |
| 712 | } |
Sungjoong Kang | 2bdec06 | 2012-08-17 15:47:56 -0700 | [diff] [blame] | 713 | ALOGV("(%s): applied aa(%d) aemode(%d) expComp(%d), awb(%d) afmode(%d), ", __FUNCTION__, |
| 714 | (int)(shot_ext->shot.ctl.aa.mode), (int)(shot_ext->shot.ctl.aa.aeMode), |
| 715 | (int)(shot_ext->shot.ctl.aa.aeExpCompensation), (int)(shot_ext->shot.ctl.aa.awbMode), |
| 716 | (int)(shot_ext->shot.ctl.aa.afMode)); |
Sungjoong Kang | 13d8c7b | 2012-07-14 10:20:39 +0900 | [diff] [blame] | 717 | } |
| 718 | |
Sungjoong Kang | 9dd63e1 | 2012-07-24 00:25:51 +0900 | [diff] [blame] | 719 | int RequestManager::FindEntryIndexByFrameCnt(int frameCnt) |
Sungjoong Kang | 13d8c7b | 2012-07-14 10:20:39 +0900 | [diff] [blame] | 720 | { |
Sungjoong Kang | 9dd63e1 | 2012-07-24 00:25:51 +0900 | [diff] [blame] | 721 | for (int i = 0 ; i < NUM_MAX_REQUEST_MGR_ENTRY ; i++) { |
Sungjoong Kang | be494d1 | 2012-08-04 15:36:56 -0700 | [diff] [blame] | 722 | if (entries[i].internal_shot.shot.ctl.request.frameCount == frameCnt) |
Sungjoong Kang | 9dd63e1 | 2012-07-24 00:25:51 +0900 | [diff] [blame] | 723 | return i; |
| 724 | } |
| 725 | return -1; |
Sungjoong Kang | 13d8c7b | 2012-07-14 10:20:39 +0900 | [diff] [blame] | 726 | } |
| 727 | |
Sungjoong Kang | 9dd63e1 | 2012-07-24 00:25:51 +0900 | [diff] [blame] | 728 | void RequestManager::RegisterTimestamp(int frameCnt, nsecs_t * frameTime) |
Sungjoong Kang | 13d8c7b | 2012-07-14 10:20:39 +0900 | [diff] [blame] | 729 | { |
Sungjoong Kang | 9dd63e1 | 2012-07-24 00:25:51 +0900 | [diff] [blame] | 730 | int index = FindEntryIndexByFrameCnt(frameCnt); |
| 731 | if (index == -1) { |
| 732 | ALOGE("ERR(%s): Cannot find entry for frameCnt(%d)", __FUNCTION__, frameCnt); |
| 733 | return; |
| 734 | } |
| 735 | |
| 736 | request_manager_entry * currentEntry = &(entries[index]); |
Sungjoong Kang | be494d1 | 2012-08-04 15:36:56 -0700 | [diff] [blame] | 737 | currentEntry->internal_shot.shot.dm.sensor.timeStamp = *((uint64_t*)frameTime); |
Sungjoong Kang | 9dd63e1 | 2012-07-24 00:25:51 +0900 | [diff] [blame] | 738 | ALOGV("DEBUG(%s): applied timestamp for reqIndex(%d) frameCnt(%d) (%lld)", __FUNCTION__, |
Sungjoong Kang | be494d1 | 2012-08-04 15:36:56 -0700 | [diff] [blame] | 739 | index, frameCnt, currentEntry->internal_shot.shot.dm.sensor.timeStamp); |
Sungjoong Kang | 9dd63e1 | 2012-07-24 00:25:51 +0900 | [diff] [blame] | 740 | } |
| 741 | |
Sungjoong Kang | ad37861 | 2012-08-17 12:34:33 -0700 | [diff] [blame] | 742 | uint64_t RequestManager::GetTimestamp(int index) |
Sungjoong Kang | 9dd63e1 | 2012-07-24 00:25:51 +0900 | [diff] [blame] | 743 | { |
Sungjoong Kang | eed7ed1 | 2012-08-23 16:35:08 -0700 | [diff] [blame] | 744 | if (index < 0 || index >= NUM_MAX_REQUEST_MGR_ENTRY) { |
| 745 | ALOGE("ERR(%s): Request entry outside of bounds (%d)", __FUNCTION__, index); |
Sungjoong Kang | 9dd63e1 | 2012-07-24 00:25:51 +0900 | [diff] [blame] | 746 | return 0; |
| 747 | } |
| 748 | |
Sungjoong Kang | 13d8c7b | 2012-07-14 10:20:39 +0900 | [diff] [blame] | 749 | request_manager_entry * currentEntry = &(entries[index]); |
Sungjoong Kang | be494d1 | 2012-08-04 15:36:56 -0700 | [diff] [blame] | 750 | uint64_t frameTime = currentEntry->internal_shot.shot.dm.sensor.timeStamp; |
Sungjoong Kang | 9dd63e1 | 2012-07-24 00:25:51 +0900 | [diff] [blame] | 751 | ALOGV("DEBUG(%s): Returning timestamp for reqIndex(%d) (%lld)", __FUNCTION__, index, frameTime); |
Sungjoong Kang | 13d8c7b | 2012-07-14 10:20:39 +0900 | [diff] [blame] | 752 | return frameTime; |
| 753 | } |
| 754 | |
Sungjoong Kang | 9dd63e1 | 2012-07-24 00:25:51 +0900 | [diff] [blame] | 755 | int RequestManager::FindFrameCnt(struct camera2_shot_ext * shot_ext) |
| 756 | { |
Sungjoong Kang | ad37861 | 2012-08-17 12:34:33 -0700 | [diff] [blame] | 757 | int i; |
| 758 | |
Sungjoong Kang | be494d1 | 2012-08-04 15:36:56 -0700 | [diff] [blame] | 759 | if (m_numOfEntries == 0) { |
Sungjoong Kang | ad37861 | 2012-08-17 12:34:33 -0700 | [diff] [blame] | 760 | ALOGV("(%s): No Entry found", __FUNCTION__); |
Sungjoong Kang | be494d1 | 2012-08-04 15:36:56 -0700 | [diff] [blame] | 761 | return -1; |
| 762 | } |
Sungjoong Kang | ad37861 | 2012-08-17 12:34:33 -0700 | [diff] [blame] | 763 | |
Sungjoong Kang | be494d1 | 2012-08-04 15:36:56 -0700 | [diff] [blame] | 764 | for (i = 0 ; i < NUM_MAX_REQUEST_MGR_ENTRY ; i++) { |
Sungjoong Kang | ad37861 | 2012-08-17 12:34:33 -0700 | [diff] [blame] | 765 | if(entries[i].internal_shot.shot.ctl.request.frameCount != shot_ext->shot.ctl.request.frameCount) |
Sungjoong Kang | be494d1 | 2012-08-04 15:36:56 -0700 | [diff] [blame] | 766 | continue; |
Sungjoong Kang | ad37861 | 2012-08-17 12:34:33 -0700 | [diff] [blame] | 767 | |
| 768 | if (entries[i].status == REQUESTED) { |
| 769 | entries[i].status = CAPTURED; |
| 770 | return entries[i].internal_shot.shot.ctl.request.frameCount; |
Sungjoong Kang | be494d1 | 2012-08-04 15:36:56 -0700 | [diff] [blame] | 771 | } |
Sungjoong Kang | ad37861 | 2012-08-17 12:34:33 -0700 | [diff] [blame] | 772 | |
Sungjoong Kang | be494d1 | 2012-08-04 15:36:56 -0700 | [diff] [blame] | 773 | } |
Sungjoong Kang | ad37861 | 2012-08-17 12:34:33 -0700 | [diff] [blame] | 774 | |
| 775 | ALOGD("(%s): No Entry found", __FUNCTION__); |
| 776 | |
Sungjoong Kang | be494d1 | 2012-08-04 15:36:56 -0700 | [diff] [blame] | 777 | return -1; |
Sungjoong Kang | 9dd63e1 | 2012-07-24 00:25:51 +0900 | [diff] [blame] | 778 | } |
Sungjoong Kang | 13d8c7b | 2012-07-14 10:20:39 +0900 | [diff] [blame] | 779 | |
Sungjoong Kang | b5237e6 | 2012-07-27 07:39:05 -0700 | [diff] [blame] | 780 | void RequestManager::SetInitialSkip(int count) |
| 781 | { |
| 782 | ALOGV("(%s): Pipeline Restarting. setting cnt(%d) - current(%d)", __FUNCTION__, count, m_sensorPipelineSkipCnt); |
| 783 | if (count > m_sensorPipelineSkipCnt) |
| 784 | m_sensorPipelineSkipCnt = count; |
| 785 | } |
| 786 | |
Sungjoong Kang | ad37861 | 2012-08-17 12:34:33 -0700 | [diff] [blame] | 787 | int RequestManager::GetSkipCnt() |
| 788 | { |
| 789 | ALOGV("(%s): skip cnt(%d)", __FUNCTION__, m_sensorPipelineSkipCnt); |
| 790 | if (m_sensorPipelineSkipCnt == 0) |
| 791 | return m_sensorPipelineSkipCnt; |
| 792 | else |
| 793 | return --m_sensorPipelineSkipCnt; |
| 794 | } |
| 795 | |
Sungjoong Kang | 13d8c7b | 2012-07-14 10:20:39 +0900 | [diff] [blame] | 796 | void RequestManager::Dump(void) |
| 797 | { |
Sungjoong Kang | 13d8c7b | 2012-07-14 10:20:39 +0900 | [diff] [blame] | 798 | int i = 0; |
| 799 | request_manager_entry * currentEntry; |
Sungjoong Kang | ad37861 | 2012-08-17 12:34:33 -0700 | [diff] [blame] | 800 | ALOGD("## Dump totalentry(%d), insert(%d), processing(%d), frame(%d)", |
Sungjoong Kang | 13d8c7b | 2012-07-14 10:20:39 +0900 | [diff] [blame] | 801 | m_numOfEntries,m_entryInsertionIndex,m_entryProcessingIndex, m_entryFrameOutputIndex); |
| 802 | |
| 803 | for (i = 0 ; i < NUM_MAX_REQUEST_MGR_ENTRY ; i++) { |
| 804 | currentEntry = &(entries[i]); |
Sungjoong Kang | ad37861 | 2012-08-17 12:34:33 -0700 | [diff] [blame] | 805 | ALOGD("[%2d] status[%d] frameCnt[%3d] numOutput[%d] outstream[0]-%d outstream[1]-%d", i, |
Sungjoong Kang | be494d1 | 2012-08-04 15:36:56 -0700 | [diff] [blame] | 806 | currentEntry->status, currentEntry->internal_shot.shot.ctl.request.frameCount, |
Sungjoong Kang | ad37861 | 2012-08-17 12:34:33 -0700 | [diff] [blame] | 807 | currentEntry->output_stream_count, |
| 808 | currentEntry->internal_shot.shot.ctl.request.outputStreams[0], |
| 809 | currentEntry->internal_shot.shot.ctl.request.outputStreams[1]); |
Sungjoong Kang | 13d8c7b | 2012-07-14 10:20:39 +0900 | [diff] [blame] | 810 | } |
| 811 | } |
| 812 | |
Sungjoong Kang | 9dd63e1 | 2012-07-24 00:25:51 +0900 | [diff] [blame] | 813 | int RequestManager::GetNextIndex(int index) |
| 814 | { |
| 815 | index++; |
| 816 | if (index >= NUM_MAX_REQUEST_MGR_ENTRY) |
| 817 | index = 0; |
| 818 | |
| 819 | return index; |
| 820 | } |
| 821 | |
Sungjoong Kang | 6044e50 | 2012-08-27 00:29:28 -0700 | [diff] [blame] | 822 | ExynosCameraHWInterface2::ExynosCameraHWInterface2(int cameraId, camera2_device_t *dev, ExynosCamera2 * camera, int *openInvalid): |
Jiyoung Shin | c15a6b0 | 2012-06-05 01:08:14 -0700 | [diff] [blame] | 823 | m_requestQueueOps(NULL), |
| 824 | m_frameQueueOps(NULL), |
| 825 | m_callbackCookie(NULL), |
| 826 | m_numOfRemainingReqInSvc(0), |
| 827 | m_isRequestQueuePending(false), |
Sungjoong Kang | 13d8c7b | 2012-07-14 10:20:39 +0900 | [diff] [blame] | 828 | m_isRequestQueueNull(true), |
Jiyoung Shin | c15a6b0 | 2012-06-05 01:08:14 -0700 | [diff] [blame] | 829 | m_isSensorThreadOn(false), |
Sungjoong Kang | 13d8c7b | 2012-07-14 10:20:39 +0900 | [diff] [blame] | 830 | m_isSensorStarted(false), |
Sungjoong Kang | ad37861 | 2012-08-17 12:34:33 -0700 | [diff] [blame] | 831 | m_isIspStarted(false), |
Sungjoong Kang | 13d8c7b | 2012-07-14 10:20:39 +0900 | [diff] [blame] | 832 | m_ionCameraClient(0), |
| 833 | m_initFlag1(false), |
| 834 | m_initFlag2(false), |
Sungjoong Kang | 13d8c7b | 2012-07-14 10:20:39 +0900 | [diff] [blame] | 835 | m_scp_flushing(false), |
| 836 | m_closing(false), |
Sungjoong Kang | 9dd63e1 | 2012-07-24 00:25:51 +0900 | [diff] [blame] | 837 | m_recordingEnabled(false), |
| 838 | m_needsRecordBufferInit(false), |
Sungjoong Kang | 74d78eb | 2012-08-29 13:25:46 -0700 | [diff] [blame] | 839 | m_needsPreviewCbBufferInit(false), |
Sungjoong Kang | 9dd63e1 | 2012-07-24 00:25:51 +0900 | [diff] [blame] | 840 | lastFrameCnt(-1), |
hyeonmyeong Choi | 308291d | 2012-08-29 13:55:01 -0700 | [diff] [blame^] | 841 | m_zoomRatio(1), |
Sungjoong Kang | 9dd63e1 | 2012-07-24 00:25:51 +0900 | [diff] [blame] | 842 | m_scp_closing(false), |
| 843 | m_scp_closed(false), |
Sungjoong Kang | 0f26b20 | 2012-08-17 15:43:12 -0700 | [diff] [blame] | 844 | m_afState(HAL_AFSTATE_INACTIVE), |
| 845 | m_afMode(NO_CHANGE), |
| 846 | m_afMode2(NO_CHANGE), |
| 847 | m_IsAfModeUpdateRequired(false), |
| 848 | m_IsAfTriggerRequired(false), |
| 849 | m_IsAfLockRequired(false), |
Sungjoong Kang | 15fd823 | 2012-08-23 16:16:44 -0700 | [diff] [blame] | 850 | m_wideAspect(false), |
Sungjoong Kang | b55ed66 | 2012-08-31 21:31:34 -0700 | [diff] [blame] | 851 | m_aspectChanged(false), |
| 852 | m_scpOutputSignalCnt(0), |
| 853 | m_scpOutputImageCnt(0), |
Sungjoong Kang | 0f26b20 | 2012-08-17 15:43:12 -0700 | [diff] [blame] | 854 | m_afTriggerId(0), |
Sungjoong Kang | 8e2c2fd | 2012-08-27 00:02:22 -0700 | [diff] [blame] | 855 | m_afPendingTriggerId(0), |
| 856 | m_afModeWaitingCnt(0), |
Sungjoong Kang | 9dd63e1 | 2012-07-24 00:25:51 +0900 | [diff] [blame] | 857 | m_halDevice(dev), |
Sungjoong Kang | ad37861 | 2012-08-17 12:34:33 -0700 | [diff] [blame] | 858 | m_need_streamoff(0), |
Sungjoong Kang | a15b4e3 | 2012-08-28 12:55:39 -0700 | [diff] [blame] | 859 | m_nightCaptureCnt(0), |
Younghwan Joo | 6f19b6c | 2012-08-30 13:56:53 -0700 | [diff] [blame] | 860 | m_afFlashEnableFlg(false), |
Sungjoong Kang | 2d5e6ec | 2012-08-30 15:14:17 +0900 | [diff] [blame] | 861 | m_cameraId(cameraId), |
| 862 | m_thumbNailW(160), |
| 863 | m_thumbNailH(120) |
Jiyoung Shin | c15a6b0 | 2012-06-05 01:08:14 -0700 | [diff] [blame] | 864 | { |
Sungjoong Kang | 13d8c7b | 2012-07-14 10:20:39 +0900 | [diff] [blame] | 865 | ALOGV("DEBUG(%s):", __FUNCTION__); |
Jiyoung Shin | c15a6b0 | 2012-06-05 01:08:14 -0700 | [diff] [blame] | 866 | int ret = 0; |
Sungjoong Kang | 6044e50 | 2012-08-27 00:29:28 -0700 | [diff] [blame] | 867 | int res = 0; |
Jiyoung Shin | c15a6b0 | 2012-06-05 01:08:14 -0700 | [diff] [blame] | 868 | |
Sungjoong Kang | 13d8c7b | 2012-07-14 10:20:39 +0900 | [diff] [blame] | 869 | m_exynosPictureCSC = NULL; |
Sungjoong Kang | 9dd63e1 | 2012-07-24 00:25:51 +0900 | [diff] [blame] | 870 | m_exynosVideoCSC = NULL; |
Sungjoong Kang | 13d8c7b | 2012-07-14 10:20:39 +0900 | [diff] [blame] | 871 | |
Jiyoung Shin | c15a6b0 | 2012-06-05 01:08:14 -0700 | [diff] [blame] | 872 | if (!m_grallocHal) { |
| 873 | ret = hw_get_module(GRALLOC_HARDWARE_MODULE_ID, (const hw_module_t **)&m_grallocHal); |
| 874 | if (ret) |
Sungjoong Kang | 13d8c7b | 2012-07-14 10:20:39 +0900 | [diff] [blame] | 875 | ALOGE("ERR(%s):Fail on loading gralloc HAL", __FUNCTION__); |
| 876 | } |
Jiyoung Shin | c15a6b0 | 2012-06-05 01:08:14 -0700 | [diff] [blame] | 877 | |
Sungjoong Kang | daa1fcd | 2012-08-08 11:49:43 -0700 | [diff] [blame] | 878 | m_camera2 = camera; |
Jiyoung Shin | c15a6b0 | 2012-06-05 01:08:14 -0700 | [diff] [blame] | 879 | m_ionCameraClient = createIonClient(m_ionCameraClient); |
| 880 | if(m_ionCameraClient == 0) |
Sungjoong Kang | 13d8c7b | 2012-07-14 10:20:39 +0900 | [diff] [blame] | 881 | ALOGE("ERR(%s):Fail on ion_client_create", __FUNCTION__); |
Jiyoung Shin | c15a6b0 | 2012-06-05 01:08:14 -0700 | [diff] [blame] | 882 | |
Sungjoong Kang | 9dd63e1 | 2012-07-24 00:25:51 +0900 | [diff] [blame] | 883 | |
| 884 | m_BayerManager = new BayerBufManager(); |
Jiyoung Shin | c15a6b0 | 2012-06-05 01:08:14 -0700 | [diff] [blame] | 885 | m_mainThread = new MainThread(this); |
Sungjoong Kang | 6044e50 | 2012-08-27 00:29:28 -0700 | [diff] [blame] | 886 | *openInvalid = InitializeISPChain(); |
| 887 | if (*openInvalid < 0) { |
| 888 | // clean process |
| 889 | // 1. close video nodes |
| 890 | // SCP |
| 891 | res = exynos_v4l2_close(m_fd_scp); |
| 892 | if (res != NO_ERROR ) { |
| 893 | ALOGE("ERR(%s): exynos_v4l2_close failed(%d)",__FUNCTION__ , res); |
| 894 | } |
| 895 | // SCC |
| 896 | res = exynos_v4l2_close(m_camera_info.capture.fd); |
| 897 | if (res != NO_ERROR ) { |
| 898 | ALOGE("ERR(%s): exynos_v4l2_close failed(%d)",__FUNCTION__ , res); |
| 899 | } |
| 900 | // Sensor |
| 901 | res = exynos_v4l2_close(m_camera_info.sensor.fd); |
| 902 | if (res != NO_ERROR ) { |
| 903 | ALOGE("ERR(%s): exynos_v4l2_close failed(%d)",__FUNCTION__ , res); |
| 904 | } |
| 905 | // ISP |
| 906 | res = exynos_v4l2_close(m_camera_info.isp.fd); |
| 907 | if (res != NO_ERROR ) { |
| 908 | ALOGE("ERR(%s): exynos_v4l2_close failed(%d)",__FUNCTION__ , res); |
| 909 | } |
| 910 | } else { |
| 911 | m_sensorThread = new SensorThread(this); |
| 912 | m_mainThread->Start("MainThread", PRIORITY_DEFAULT, 0); |
| 913 | ALOGV("DEBUG(%s): created sensorthread ################", __FUNCTION__); |
| 914 | m_requestManager = new RequestManager((SignalDrivenThread*)(m_mainThread.get())); |
| 915 | CSC_METHOD cscMethod = CSC_METHOD_HW; |
| 916 | m_exynosPictureCSC = csc_init(cscMethod); |
| 917 | if (m_exynosPictureCSC == NULL) |
| 918 | ALOGE("ERR(%s): csc_init() fail", __FUNCTION__); |
| 919 | csc_set_hw_property(m_exynosPictureCSC, CSC_HW_PROPERTY_FIXED_NODE, PICTURE_GSC_NODE_NUM); |
Jiyoung Shin | c15a6b0 | 2012-06-05 01:08:14 -0700 | [diff] [blame] | 920 | |
Sungjoong Kang | 6044e50 | 2012-08-27 00:29:28 -0700 | [diff] [blame] | 921 | m_exynosVideoCSC = csc_init(cscMethod); |
| 922 | if (m_exynosVideoCSC == NULL) |
| 923 | ALOGE("ERR(%s): csc_init() fail", __FUNCTION__); |
| 924 | csc_set_hw_property(m_exynosVideoCSC, CSC_HW_PROPERTY_FIXED_NODE, VIDEO_GSC_NODE_NUM); |
Sungjoong Kang | 13d8c7b | 2012-07-14 10:20:39 +0900 | [diff] [blame] | 925 | |
Sungjoong Kang | 6044e50 | 2012-08-27 00:29:28 -0700 | [diff] [blame] | 926 | m_setExifFixedAttribute(); |
| 927 | } |
Jiyoung Shin | c15a6b0 | 2012-06-05 01:08:14 -0700 | [diff] [blame] | 928 | } |
| 929 | |
| 930 | ExynosCameraHWInterface2::~ExynosCameraHWInterface2() |
| 931 | { |
Sungjoong Kang | ad37861 | 2012-08-17 12:34:33 -0700 | [diff] [blame] | 932 | ALOGV("%s: ENTER", __FUNCTION__); |
Jiyoung Shin | c15a6b0 | 2012-06-05 01:08:14 -0700 | [diff] [blame] | 933 | this->release(); |
Sungjoong Kang | ad37861 | 2012-08-17 12:34:33 -0700 | [diff] [blame] | 934 | ALOGV("%s: EXIT", __FUNCTION__); |
Jiyoung Shin | c15a6b0 | 2012-06-05 01:08:14 -0700 | [diff] [blame] | 935 | } |
| 936 | |
| 937 | void ExynosCameraHWInterface2::release() |
| 938 | { |
Sungjoong Kang | 13d8c7b | 2012-07-14 10:20:39 +0900 | [diff] [blame] | 939 | int i, res; |
Sungjoong Kang | 9dd63e1 | 2012-07-24 00:25:51 +0900 | [diff] [blame] | 940 | ALOGD("%s: ENTER", __func__); |
Sungjoong Kang | 13d8c7b | 2012-07-14 10:20:39 +0900 | [diff] [blame] | 941 | m_closing = true; |
Sungjoong Kang | 9dd63e1 | 2012-07-24 00:25:51 +0900 | [diff] [blame] | 942 | |
Sungjoong Kang | ad37861 | 2012-08-17 12:34:33 -0700 | [diff] [blame] | 943 | if (m_streamThreads[1] != NULL) { |
| 944 | m_streamThreads[1]->release(); |
| 945 | m_streamThreads[1]->SetSignal(SIGNAL_THREAD_TERMINATE); |
| 946 | } |
| 947 | |
| 948 | if (m_streamThreads[0] != NULL) { |
| 949 | m_streamThreads[0]->release(); |
| 950 | m_streamThreads[0]->SetSignal(SIGNAL_THREAD_TERMINATE); |
| 951 | } |
| 952 | |
Sungjoong Kang | 13d8c7b | 2012-07-14 10:20:39 +0900 | [diff] [blame] | 953 | if (m_ispThread != NULL) { |
| 954 | m_ispThread->release(); |
Sungjoong Kang | 13d8c7b | 2012-07-14 10:20:39 +0900 | [diff] [blame] | 955 | } |
| 956 | |
| 957 | if (m_sensorThread != NULL) { |
| 958 | m_sensorThread->release(); |
Sungjoong Kang | 13d8c7b | 2012-07-14 10:20:39 +0900 | [diff] [blame] | 959 | } |
Jiyoung Shin | c15a6b0 | 2012-06-05 01:08:14 -0700 | [diff] [blame] | 960 | |
| 961 | if (m_mainThread != NULL) { |
Sungjoong Kang | 13d8c7b | 2012-07-14 10:20:39 +0900 | [diff] [blame] | 962 | m_mainThread->release(); |
Jiyoung Shin | c15a6b0 | 2012-06-05 01:08:14 -0700 | [diff] [blame] | 963 | } |
Jiyoung Shin | c15a6b0 | 2012-06-05 01:08:14 -0700 | [diff] [blame] | 964 | |
Sungjoong Kang | 13d8c7b | 2012-07-14 10:20:39 +0900 | [diff] [blame] | 965 | if (m_exynosPictureCSC) |
| 966 | csc_deinit(m_exynosPictureCSC); |
| 967 | m_exynosPictureCSC = NULL; |
| 968 | |
Sungjoong Kang | 9dd63e1 | 2012-07-24 00:25:51 +0900 | [diff] [blame] | 969 | if (m_exynosVideoCSC) |
| 970 | csc_deinit(m_exynosVideoCSC); |
| 971 | m_exynosVideoCSC = NULL; |
| 972 | |
Sungjoong Kang | ad37861 | 2012-08-17 12:34:33 -0700 | [diff] [blame] | 973 | if (m_streamThreads[1] != NULL) { |
| 974 | while (!m_streamThreads[1]->IsTerminated()) |
| 975 | { |
| 976 | ALOGD("Waiting for ISP thread is tetminated"); |
| 977 | usleep(100000); |
| 978 | } |
| 979 | m_streamThreads[1] = NULL; |
| 980 | } |
| 981 | |
| 982 | if (m_streamThreads[0] != NULL) { |
| 983 | while (!m_streamThreads[0]->IsTerminated()) |
| 984 | { |
| 985 | ALOGD("Waiting for sensor thread is tetminated"); |
| 986 | usleep(100000); |
| 987 | } |
| 988 | m_streamThreads[0] = NULL; |
| 989 | } |
| 990 | |
Sungjoong Kang | 9dd63e1 | 2012-07-24 00:25:51 +0900 | [diff] [blame] | 991 | if (m_ispThread != NULL) { |
| 992 | while (!m_ispThread->IsTerminated()) |
Sungjoong Kang | ad37861 | 2012-08-17 12:34:33 -0700 | [diff] [blame] | 993 | { |
| 994 | ALOGD("Waiting for isp thread is tetminated"); |
| 995 | usleep(100000); |
| 996 | } |
Sungjoong Kang | 9dd63e1 | 2012-07-24 00:25:51 +0900 | [diff] [blame] | 997 | m_ispThread = NULL; |
| 998 | } |
| 999 | |
| 1000 | if (m_sensorThread != NULL) { |
| 1001 | while (!m_sensorThread->IsTerminated()) |
Sungjoong Kang | ad37861 | 2012-08-17 12:34:33 -0700 | [diff] [blame] | 1002 | { |
| 1003 | ALOGD("Waiting for sensor thread is tetminated"); |
| 1004 | usleep(100000); |
| 1005 | } |
Sungjoong Kang | 9dd63e1 | 2012-07-24 00:25:51 +0900 | [diff] [blame] | 1006 | m_sensorThread = NULL; |
| 1007 | } |
| 1008 | |
Sungjoong Kang | ad37861 | 2012-08-17 12:34:33 -0700 | [diff] [blame] | 1009 | if (m_mainThread != NULL) { |
Sungjoong Kang | 9dd63e1 | 2012-07-24 00:25:51 +0900 | [diff] [blame] | 1010 | while (!m_mainThread->IsTerminated()) |
Sungjoong Kang | ad37861 | 2012-08-17 12:34:33 -0700 | [diff] [blame] | 1011 | { |
| 1012 | ALOGD("Waiting for main thread is tetminated"); |
| 1013 | usleep(100000); |
| 1014 | } |
Sungjoong Kang | 9dd63e1 | 2012-07-24 00:25:51 +0900 | [diff] [blame] | 1015 | m_mainThread = NULL; |
| 1016 | } |
| 1017 | |
Sungjoong Kang | 15fd823 | 2012-08-23 16:16:44 -0700 | [diff] [blame] | 1018 | if (m_requestManager != NULL) { |
| 1019 | delete m_requestManager; |
| 1020 | m_requestManager = NULL; |
| 1021 | } |
| 1022 | |
| 1023 | if (m_BayerManager != NULL) { |
| 1024 | delete m_BayerManager; |
| 1025 | m_BayerManager = NULL; |
| 1026 | } |
| 1027 | // for(i = 0; i < m_camera_info.sensor.buffers; i++) |
| 1028 | for (i = 0; i < NUM_BAYER_BUFFERS; i++) |
Jiyoung Shin | c15a6b0 | 2012-06-05 01:08:14 -0700 | [diff] [blame] | 1029 | freeCameraMemory(&m_camera_info.sensor.buffer[i], m_camera_info.sensor.planes); |
| 1030 | |
Jiyoung Shin | c15a6b0 | 2012-06-05 01:08:14 -0700 | [diff] [blame] | 1031 | for(i = 0; i < m_camera_info.capture.buffers; i++) |
| 1032 | freeCameraMemory(&m_camera_info.capture.buffer[i], m_camera_info.capture.planes); |
| 1033 | |
Sungjoong Kang | 9dd63e1 | 2012-07-24 00:25:51 +0900 | [diff] [blame] | 1034 | ALOGV("DEBUG(%s): calling exynos_v4l2_close - sensor", __FUNCTION__); |
Sungjoong Kang | 13d8c7b | 2012-07-14 10:20:39 +0900 | [diff] [blame] | 1035 | res = exynos_v4l2_close(m_camera_info.sensor.fd); |
| 1036 | if (res != NO_ERROR ) { |
Sungjoong Kang | 9dd63e1 | 2012-07-24 00:25:51 +0900 | [diff] [blame] | 1037 | ALOGE("ERR(%s): exynos_v4l2_close failed(%d)",__FUNCTION__ , res); |
Sungjoong Kang | 13d8c7b | 2012-07-14 10:20:39 +0900 | [diff] [blame] | 1038 | } |
| 1039 | |
Sungjoong Kang | 9dd63e1 | 2012-07-24 00:25:51 +0900 | [diff] [blame] | 1040 | ALOGV("DEBUG(%s): calling exynos_v4l2_close - isp", __FUNCTION__); |
Sungjoong Kang | 13d8c7b | 2012-07-14 10:20:39 +0900 | [diff] [blame] | 1041 | res = exynos_v4l2_close(m_camera_info.isp.fd); |
| 1042 | if (res != NO_ERROR ) { |
Sungjoong Kang | 9dd63e1 | 2012-07-24 00:25:51 +0900 | [diff] [blame] | 1043 | ALOGE("ERR(%s): exynos_v4l2_close failed(%d)",__FUNCTION__ , res); |
Sungjoong Kang | 13d8c7b | 2012-07-14 10:20:39 +0900 | [diff] [blame] | 1044 | } |
| 1045 | |
Sungjoong Kang | 9dd63e1 | 2012-07-24 00:25:51 +0900 | [diff] [blame] | 1046 | ALOGV("DEBUG(%s): calling exynos_v4l2_close - capture", __FUNCTION__); |
Sungjoong Kang | 13d8c7b | 2012-07-14 10:20:39 +0900 | [diff] [blame] | 1047 | res = exynos_v4l2_close(m_camera_info.capture.fd); |
| 1048 | if (res != NO_ERROR ) { |
Sungjoong Kang | 9dd63e1 | 2012-07-24 00:25:51 +0900 | [diff] [blame] | 1049 | ALOGE("ERR(%s): exynos_v4l2_close failed(%d)",__FUNCTION__ , res); |
Sungjoong Kang | 13d8c7b | 2012-07-14 10:20:39 +0900 | [diff] [blame] | 1050 | } |
| 1051 | |
Sungjoong Kang | 9dd63e1 | 2012-07-24 00:25:51 +0900 | [diff] [blame] | 1052 | ALOGV("DEBUG(%s): calling exynos_v4l2_close - scp", __FUNCTION__); |
Sungjoong Kang | ad37861 | 2012-08-17 12:34:33 -0700 | [diff] [blame] | 1053 | res = exynos_v4l2_close(m_fd_scp); |
Sungjoong Kang | 13d8c7b | 2012-07-14 10:20:39 +0900 | [diff] [blame] | 1054 | if (res != NO_ERROR ) { |
Sungjoong Kang | 9dd63e1 | 2012-07-24 00:25:51 +0900 | [diff] [blame] | 1055 | ALOGE("ERR(%s): exynos_v4l2_close failed(%d)",__FUNCTION__ , res); |
Sungjoong Kang | 13d8c7b | 2012-07-14 10:20:39 +0900 | [diff] [blame] | 1056 | } |
Sungjoong Kang | 9dd63e1 | 2012-07-24 00:25:51 +0900 | [diff] [blame] | 1057 | ALOGV("DEBUG(%s): calling deleteIonClient", __FUNCTION__); |
Jiyoung Shin | c15a6b0 | 2012-06-05 01:08:14 -0700 | [diff] [blame] | 1058 | deleteIonClient(m_ionCameraClient); |
Sungjoong Kang | ad37861 | 2012-08-17 12:34:33 -0700 | [diff] [blame] | 1059 | |
| 1060 | ALOGV("%s: EXIT", __func__); |
| 1061 | } |
| 1062 | |
Sungjoong Kang | 6044e50 | 2012-08-27 00:29:28 -0700 | [diff] [blame] | 1063 | int ExynosCameraHWInterface2::InitializeISPChain() |
Sungjoong Kang | ad37861 | 2012-08-17 12:34:33 -0700 | [diff] [blame] | 1064 | { |
| 1065 | char node_name[30]; |
| 1066 | int fd = 0; |
| 1067 | int i; |
Sungjoong Kang | 6044e50 | 2012-08-27 00:29:28 -0700 | [diff] [blame] | 1068 | int ret = 0; |
Sungjoong Kang | ad37861 | 2012-08-17 12:34:33 -0700 | [diff] [blame] | 1069 | |
| 1070 | /* Open Sensor */ |
| 1071 | memset(&node_name, 0x00, sizeof(char[30])); |
| 1072 | sprintf(node_name, "%s%d", NODE_PREFIX, 40); |
| 1073 | fd = exynos_v4l2_open(node_name, O_RDWR, 0); |
| 1074 | |
| 1075 | if (fd < 0) { |
| 1076 | ALOGE("ERR(%s): failed to open sensor video node (%s) fd (%d)", __FUNCTION__,node_name, fd); |
| 1077 | } |
| 1078 | else { |
| 1079 | ALOGV("DEBUG(%s): sensor video node opened(%s) fd (%d)", __FUNCTION__,node_name, fd); |
| 1080 | } |
| 1081 | m_camera_info.sensor.fd = fd; |
| 1082 | |
| 1083 | /* Open ISP */ |
| 1084 | memset(&node_name, 0x00, sizeof(char[30])); |
| 1085 | sprintf(node_name, "%s%d", NODE_PREFIX, 41); |
| 1086 | fd = exynos_v4l2_open(node_name, O_RDWR, 0); |
| 1087 | |
| 1088 | if (fd < 0) { |
| 1089 | ALOGE("ERR(%s): failed to open isp video node (%s) fd (%d)", __FUNCTION__,node_name, fd); |
| 1090 | } |
| 1091 | else { |
| 1092 | ALOGV("DEBUG(%s): isp video node opened(%s) fd (%d)", __FUNCTION__,node_name, fd); |
| 1093 | } |
| 1094 | m_camera_info.isp.fd = fd; |
| 1095 | |
| 1096 | /* Open ScalerC */ |
| 1097 | memset(&node_name, 0x00, sizeof(char[30])); |
| 1098 | sprintf(node_name, "%s%d", NODE_PREFIX, 42); |
| 1099 | fd = exynos_v4l2_open(node_name, O_RDWR, 0); |
| 1100 | |
| 1101 | if (fd < 0) { |
| 1102 | ALOGE("ERR(%s): failed to open capture video node (%s) fd (%d)", __FUNCTION__,node_name, fd); |
| 1103 | } |
| 1104 | else { |
| 1105 | ALOGV("DEBUG(%s): capture video node opened(%s) fd (%d)", __FUNCTION__,node_name, fd); |
| 1106 | } |
| 1107 | m_camera_info.capture.fd = fd; |
| 1108 | |
| 1109 | /* Open ScalerP */ |
| 1110 | memset(&node_name, 0x00, sizeof(char[30])); |
| 1111 | sprintf(node_name, "%s%d", NODE_PREFIX, 44); |
| 1112 | fd = exynos_v4l2_open(node_name, O_RDWR, 0); |
| 1113 | if (fd < 0) { |
| 1114 | ALOGE("DEBUG(%s): failed to open preview video node (%s) fd (%d)", __FUNCTION__,node_name, fd); |
| 1115 | } |
| 1116 | else { |
| 1117 | ALOGV("DEBUG(%s): preview video node opened(%s) fd (%d)", __FUNCTION__,node_name, fd); |
| 1118 | } |
| 1119 | m_fd_scp = fd; |
| 1120 | |
| 1121 | if(m_cameraId == 0) |
| 1122 | m_camera_info.sensor_id = SENSOR_NAME_S5K4E5; |
| 1123 | else |
| 1124 | m_camera_info.sensor_id = SENSOR_NAME_S5K6A3; |
| 1125 | |
| 1126 | memset(&m_camera_info.dummy_shot, 0x00, sizeof(struct camera2_shot_ext)); |
| 1127 | m_camera_info.dummy_shot.shot.ctl.request.metadataMode = METADATA_MODE_FULL; |
| 1128 | m_camera_info.dummy_shot.shot.magicNumber = 0x23456789; |
| 1129 | |
| 1130 | m_camera_info.dummy_shot.dis_bypass = 1; |
| 1131 | m_camera_info.dummy_shot.dnr_bypass = 1; |
| 1132 | m_camera_info.dummy_shot.fd_bypass = 1; |
| 1133 | |
| 1134 | /*sensor setting*/ |
| 1135 | m_camera_info.dummy_shot.shot.ctl.sensor.exposureTime = 0; |
| 1136 | m_camera_info.dummy_shot.shot.ctl.sensor.frameDuration = 0; |
| 1137 | m_camera_info.dummy_shot.shot.ctl.sensor.sensitivity = 0; |
| 1138 | |
| 1139 | m_camera_info.dummy_shot.shot.ctl.scaler.cropRegion[0] = 0; |
| 1140 | m_camera_info.dummy_shot.shot.ctl.scaler.cropRegion[1] = 0; |
| 1141 | |
| 1142 | /*request setting*/ |
| 1143 | m_camera_info.dummy_shot.request_sensor = 1; |
| 1144 | m_camera_info.dummy_shot.request_scc = 0; |
| 1145 | m_camera_info.dummy_shot.request_scp = 0; |
| 1146 | m_camera_info.dummy_shot.shot.ctl.request.outputStreams[0] = 0; |
| 1147 | m_camera_info.dummy_shot.shot.ctl.request.outputStreams[1] = 0; |
| 1148 | m_camera_info.dummy_shot.shot.ctl.request.outputStreams[2] = 0; |
Sungjoong Kang | 74d78eb | 2012-08-29 13:25:46 -0700 | [diff] [blame] | 1149 | m_camera_info.dummy_shot.shot.ctl.request.outputStreams[3] = 0; |
Sungjoong Kang | ad37861 | 2012-08-17 12:34:33 -0700 | [diff] [blame] | 1150 | |
| 1151 | m_camera_info.sensor.width = m_camera2->getSensorRawW(); |
| 1152 | m_camera_info.sensor.height = m_camera2->getSensorRawH(); |
| 1153 | |
| 1154 | m_camera_info.sensor.format = V4L2_PIX_FMT_SBGGR16; |
| 1155 | m_camera_info.sensor.planes = 2; |
| 1156 | m_camera_info.sensor.buffers = NUM_BAYER_BUFFERS; |
| 1157 | m_camera_info.sensor.type = V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE; |
| 1158 | m_camera_info.sensor.memory = V4L2_MEMORY_DMABUF; |
| 1159 | m_camera_info.sensor.ionClient = m_ionCameraClient; |
| 1160 | |
| 1161 | for(i = 0; i < m_camera_info.sensor.buffers; i++){ |
| 1162 | initCameraMemory(&m_camera_info.sensor.buffer[i], m_camera_info.sensor.planes); |
| 1163 | m_camera_info.sensor.buffer[i].size.extS[0] = m_camera_info.sensor.width*m_camera_info.sensor.height*2; |
| 1164 | m_camera_info.sensor.buffer[i].size.extS[1] = 8*1024; // HACK, driver use 8*1024, should be use predefined value |
| 1165 | allocCameraMemory(m_camera_info.sensor.ionClient, &m_camera_info.sensor.buffer[i], m_camera_info.sensor.planes); |
| 1166 | } |
| 1167 | |
| 1168 | m_camera_info.isp.width = m_camera_info.sensor.width; |
| 1169 | m_camera_info.isp.height = m_camera_info.sensor.height; |
| 1170 | m_camera_info.isp.format = m_camera_info.sensor.format; |
| 1171 | m_camera_info.isp.planes = m_camera_info.sensor.planes; |
| 1172 | m_camera_info.isp.buffers = m_camera_info.sensor.buffers; |
| 1173 | m_camera_info.isp.type = V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE; |
| 1174 | m_camera_info.isp.memory = V4L2_MEMORY_DMABUF; |
| 1175 | m_camera_info.isp.ionClient = m_ionCameraClient; |
| 1176 | |
| 1177 | for(i = 0; i < m_camera_info.isp.buffers; i++){ |
| 1178 | initCameraMemory(&m_camera_info.isp.buffer[i], m_camera_info.isp.planes); |
| 1179 | m_camera_info.isp.buffer[i].size.extS[0] = m_camera_info.sensor.buffer[i].size.extS[0]; |
| 1180 | m_camera_info.isp.buffer[i].size.extS[1] = m_camera_info.sensor.buffer[i].size.extS[1]; |
| 1181 | m_camera_info.isp.buffer[i].fd.extFd[0] = m_camera_info.sensor.buffer[i].fd.extFd[0]; |
| 1182 | m_camera_info.isp.buffer[i].fd.extFd[1] = m_camera_info.sensor.buffer[i].fd.extFd[1]; |
| 1183 | m_camera_info.isp.buffer[i].virt.extP[0] = m_camera_info.sensor.buffer[i].virt.extP[0]; |
| 1184 | m_camera_info.isp.buffer[i].virt.extP[1] = m_camera_info.sensor.buffer[i].virt.extP[1]; |
| 1185 | }; |
| 1186 | |
| 1187 | /* init ISP */ |
Sungjoong Kang | 6044e50 | 2012-08-27 00:29:28 -0700 | [diff] [blame] | 1188 | ret = cam_int_s_input(&(m_camera_info.isp), m_camera_info.sensor_id); |
| 1189 | if (ret < 0) { |
| 1190 | ALOGE("ERR(%s): cam_int_s_input(%d) failed!!!! ", __FUNCTION__, m_camera_info.sensor_id); |
| 1191 | return false; |
| 1192 | } |
Sungjoong Kang | ad37861 | 2012-08-17 12:34:33 -0700 | [diff] [blame] | 1193 | cam_int_s_fmt(&(m_camera_info.isp)); |
| 1194 | ALOGV("DEBUG(%s): isp calling reqbuf", __FUNCTION__); |
| 1195 | cam_int_reqbufs(&(m_camera_info.isp)); |
| 1196 | ALOGV("DEBUG(%s): isp calling querybuf", __FUNCTION__); |
| 1197 | ALOGV("DEBUG(%s): isp mem alloc done", __FUNCTION__); |
| 1198 | |
| 1199 | /* init Sensor */ |
| 1200 | cam_int_s_input(&(m_camera_info.sensor), m_camera_info.sensor_id); |
| 1201 | ALOGV("DEBUG(%s): sensor s_input done", __FUNCTION__); |
| 1202 | if (cam_int_s_fmt(&(m_camera_info.sensor))< 0) { |
| 1203 | ALOGE("ERR(%s): sensor s_fmt fail", __FUNCTION__); |
| 1204 | } |
| 1205 | ALOGV("DEBUG(%s): sensor s_fmt done", __FUNCTION__); |
| 1206 | cam_int_reqbufs(&(m_camera_info.sensor)); |
| 1207 | ALOGV("DEBUG(%s): sensor reqbuf done", __FUNCTION__); |
| 1208 | for (i = 0; i < m_camera_info.sensor.buffers; i++) { |
| 1209 | ALOGV("DEBUG(%s): sensor initial QBUF [%d]", __FUNCTION__, i); |
| 1210 | memcpy( m_camera_info.sensor.buffer[i].virt.extP[1], &(m_camera_info.dummy_shot), |
| 1211 | sizeof(struct camera2_shot_ext)); |
| 1212 | m_camera_info.dummy_shot.shot.ctl.sensor.frameDuration = 33*1000*1000; // apply from frame #1 |
| 1213 | m_camera_info.dummy_shot.shot.ctl.request.frameCount = -1; |
| 1214 | cam_int_qbuf(&(m_camera_info.sensor), i); |
| 1215 | } |
| 1216 | ALOGV("== stream_on :: .sensor"); |
| 1217 | cam_int_streamon(&(m_camera_info.sensor)); |
| 1218 | |
| 1219 | /* init Capture */ |
| 1220 | m_camera_info.capture.width = m_camera2->getSensorW(); |
| 1221 | m_camera_info.capture.height = m_camera2->getSensorH(); |
| 1222 | m_camera_info.capture.format = V4L2_PIX_FMT_YUYV; |
Sungjoong Kang | feb7df4 | 2012-08-28 23:35:43 +0900 | [diff] [blame] | 1223 | #ifdef ENABLE_FRAME_SYNC |
| 1224 | m_camera_info.capture.planes = 2; |
| 1225 | #else |
Sungjoong Kang | ad37861 | 2012-08-17 12:34:33 -0700 | [diff] [blame] | 1226 | m_camera_info.capture.planes = 1; |
Sungjoong Kang | feb7df4 | 2012-08-28 23:35:43 +0900 | [diff] [blame] | 1227 | #endif |
Sungjoong Kang | ad37861 | 2012-08-17 12:34:33 -0700 | [diff] [blame] | 1228 | m_camera_info.capture.buffers = 8; |
| 1229 | m_camera_info.capture.type = V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE; |
| 1230 | m_camera_info.capture.memory = V4L2_MEMORY_DMABUF; |
| 1231 | m_camera_info.capture.ionClient = m_ionCameraClient; |
| 1232 | |
| 1233 | for(i = 0; i < m_camera_info.capture.buffers; i++){ |
| 1234 | initCameraMemory(&m_camera_info.capture.buffer[i], m_camera_info.capture.planes); |
| 1235 | m_camera_info.capture.buffer[i].size.extS[0] = m_camera_info.capture.width*m_camera_info.capture.height*2; |
Sungjoong Kang | feb7df4 | 2012-08-28 23:35:43 +0900 | [diff] [blame] | 1236 | #ifdef ENABLE_FRAME_SYNC |
| 1237 | m_camera_info.capture.buffer[i].size.extS[1] = 4*1024; // HACK, driver use 4*1024, should be use predefined value |
| 1238 | #endif |
Sungjoong Kang | ad37861 | 2012-08-17 12:34:33 -0700 | [diff] [blame] | 1239 | allocCameraMemory(m_camera_info.capture.ionClient, &m_camera_info.capture.buffer[i], m_camera_info.capture.planes); |
| 1240 | } |
| 1241 | |
| 1242 | cam_int_s_input(&(m_camera_info.capture), m_camera_info.sensor_id); |
| 1243 | cam_int_s_fmt(&(m_camera_info.capture)); |
| 1244 | ALOGV("DEBUG(%s): capture calling reqbuf", __FUNCTION__); |
| 1245 | cam_int_reqbufs(&(m_camera_info.capture)); |
| 1246 | ALOGV("DEBUG(%s): capture calling querybuf", __FUNCTION__); |
| 1247 | |
| 1248 | for (i = 0; i < m_camera_info.capture.buffers; i++) { |
| 1249 | ALOGV("DEBUG(%s): capture initial QBUF [%d]", __FUNCTION__, i); |
| 1250 | cam_int_qbuf(&(m_camera_info.capture), i); |
| 1251 | } |
| 1252 | |
| 1253 | ALOGV("== stream_on :: capture"); |
Sungjoong Kang | 15fd823 | 2012-08-23 16:16:44 -0700 | [diff] [blame] | 1254 | if (cam_int_streamon(&(m_camera_info.capture)) < 0) { |
| 1255 | ALOGE("ERR(%s): capture stream on fail", __FUNCTION__); |
| 1256 | } else { |
| 1257 | m_camera_info.capture.status = true; |
| 1258 | } |
Sungjoong Kang | 6044e50 | 2012-08-27 00:29:28 -0700 | [diff] [blame] | 1259 | |
| 1260 | return true; |
Sungjoong Kang | ad37861 | 2012-08-17 12:34:33 -0700 | [diff] [blame] | 1261 | } |
| 1262 | |
| 1263 | void ExynosCameraHWInterface2::StartISP() |
| 1264 | { |
Sungjoong Kang | ad37861 | 2012-08-17 12:34:33 -0700 | [diff] [blame] | 1265 | ALOGV("== stream_on :: isp"); |
| 1266 | cam_int_streamon(&(m_camera_info.isp)); |
Sungjoong Kang | ad37861 | 2012-08-17 12:34:33 -0700 | [diff] [blame] | 1267 | exynos_v4l2_s_ctrl(m_camera_info.sensor.fd, V4L2_CID_IS_S_STREAM, IS_ENABLE_STREAM); |
Sungjoong Kang | 13d8c7b | 2012-07-14 10:20:39 +0900 | [diff] [blame] | 1268 | } |
| 1269 | |
Jiyoung Shin | c15a6b0 | 2012-06-05 01:08:14 -0700 | [diff] [blame] | 1270 | int ExynosCameraHWInterface2::getCameraId() const |
| 1271 | { |
Sungjoong Kang | 9dd63e1 | 2012-07-24 00:25:51 +0900 | [diff] [blame] | 1272 | return m_cameraId; |
Jiyoung Shin | c15a6b0 | 2012-06-05 01:08:14 -0700 | [diff] [blame] | 1273 | } |
Jiyoung Shin | c15a6b0 | 2012-06-05 01:08:14 -0700 | [diff] [blame] | 1274 | |
| 1275 | int ExynosCameraHWInterface2::setRequestQueueSrcOps(const camera2_request_queue_src_ops_t *request_src_ops) |
| 1276 | { |
Sungjoong Kang | 13d8c7b | 2012-07-14 10:20:39 +0900 | [diff] [blame] | 1277 | ALOGV("DEBUG(%s):", __FUNCTION__); |
Jiyoung Shin | c15a6b0 | 2012-06-05 01:08:14 -0700 | [diff] [blame] | 1278 | if ((NULL != request_src_ops) && (NULL != request_src_ops->dequeue_request) |
| 1279 | && (NULL != request_src_ops->free_request) && (NULL != request_src_ops->request_count)) { |
| 1280 | m_requestQueueOps = (camera2_request_queue_src_ops_t*)request_src_ops; |
| 1281 | return 0; |
| 1282 | } |
| 1283 | else { |
Sungjoong Kang | 13d8c7b | 2012-07-14 10:20:39 +0900 | [diff] [blame] | 1284 | ALOGE("DEBUG(%s):setRequestQueueSrcOps : NULL arguments", __FUNCTION__); |
Jiyoung Shin | c15a6b0 | 2012-06-05 01:08:14 -0700 | [diff] [blame] | 1285 | return 1; |
| 1286 | } |
| 1287 | } |
| 1288 | |
| 1289 | int ExynosCameraHWInterface2::notifyRequestQueueNotEmpty() |
| 1290 | { |
Sungjoong Kang | b5237e6 | 2012-07-27 07:39:05 -0700 | [diff] [blame] | 1291 | ALOGV("DEBUG(%s):setting [SIGNAL_MAIN_REQ_Q_NOT_EMPTY] current(%d)", __FUNCTION__, m_requestManager->GetNumEntries()); |
Jiyoung Shin | c15a6b0 | 2012-06-05 01:08:14 -0700 | [diff] [blame] | 1292 | if ((NULL==m_frameQueueOps)|| (NULL==m_requestQueueOps)) { |
Sungjoong Kang | 13d8c7b | 2012-07-14 10:20:39 +0900 | [diff] [blame] | 1293 | ALOGE("DEBUG(%s):queue ops NULL. ignoring request", __FUNCTION__); |
Jiyoung Shin | c15a6b0 | 2012-06-05 01:08:14 -0700 | [diff] [blame] | 1294 | return 0; |
| 1295 | } |
Sungjoong Kang | 13d8c7b | 2012-07-14 10:20:39 +0900 | [diff] [blame] | 1296 | m_isRequestQueueNull = false; |
Sungjoong Kang | 0f26b20 | 2012-08-17 15:43:12 -0700 | [diff] [blame] | 1297 | if (m_requestManager->GetNumEntries() == 0) |
| 1298 | m_requestManager->SetInitialSkip(5); |
Jiyoung Shin | c15a6b0 | 2012-06-05 01:08:14 -0700 | [diff] [blame] | 1299 | m_mainThread->SetSignal(SIGNAL_MAIN_REQ_Q_NOT_EMPTY); |
| 1300 | return 0; |
| 1301 | } |
| 1302 | |
| 1303 | int ExynosCameraHWInterface2::setFrameQueueDstOps(const camera2_frame_queue_dst_ops_t *frame_dst_ops) |
| 1304 | { |
Sungjoong Kang | 13d8c7b | 2012-07-14 10:20:39 +0900 | [diff] [blame] | 1305 | ALOGV("DEBUG(%s):", __FUNCTION__); |
Jiyoung Shin | c15a6b0 | 2012-06-05 01:08:14 -0700 | [diff] [blame] | 1306 | if ((NULL != frame_dst_ops) && (NULL != frame_dst_ops->dequeue_frame) |
| 1307 | && (NULL != frame_dst_ops->cancel_frame) && (NULL !=frame_dst_ops->enqueue_frame)) { |
| 1308 | m_frameQueueOps = (camera2_frame_queue_dst_ops_t *)frame_dst_ops; |
| 1309 | return 0; |
| 1310 | } |
| 1311 | else { |
Sungjoong Kang | 13d8c7b | 2012-07-14 10:20:39 +0900 | [diff] [blame] | 1312 | ALOGE("DEBUG(%s):setFrameQueueDstOps : NULL arguments", __FUNCTION__); |
Jiyoung Shin | c15a6b0 | 2012-06-05 01:08:14 -0700 | [diff] [blame] | 1313 | return 1; |
| 1314 | } |
| 1315 | } |
| 1316 | |
| 1317 | int ExynosCameraHWInterface2::getInProgressCount() |
| 1318 | { |
| 1319 | int inProgressCount = m_requestManager->GetNumEntries(); |
Sungjoong Kang | 13d8c7b | 2012-07-14 10:20:39 +0900 | [diff] [blame] | 1320 | ALOGV("DEBUG(%s): # of dequeued req (%d)", __FUNCTION__, inProgressCount); |
Jiyoung Shin | c15a6b0 | 2012-06-05 01:08:14 -0700 | [diff] [blame] | 1321 | return inProgressCount; |
| 1322 | } |
| 1323 | |
| 1324 | int ExynosCameraHWInterface2::flushCapturesInProgress() |
| 1325 | { |
| 1326 | return 0; |
| 1327 | } |
| 1328 | |
Jiyoung Shin | c15a6b0 | 2012-06-05 01:08:14 -0700 | [diff] [blame] | 1329 | int ExynosCameraHWInterface2::constructDefaultRequest(int request_template, camera_metadata_t **request) |
| 1330 | { |
Sungjoong Kang | 13d8c7b | 2012-07-14 10:20:39 +0900 | [diff] [blame] | 1331 | ALOGV("DEBUG(%s): making template (%d) ", __FUNCTION__, request_template); |
Jiyoung Shin | c15a6b0 | 2012-06-05 01:08:14 -0700 | [diff] [blame] | 1332 | |
| 1333 | if (request == NULL) return BAD_VALUE; |
| 1334 | if (request_template < 0 || request_template >= CAMERA2_TEMPLATE_COUNT) { |
| 1335 | return BAD_VALUE; |
| 1336 | } |
| 1337 | status_t res; |
| 1338 | // Pass 1, calculate size and allocate |
Sungjoong Kang | daa1fcd | 2012-08-08 11:49:43 -0700 | [diff] [blame] | 1339 | res = m_camera2->constructDefaultRequest(request_template, |
Jiyoung Shin | c15a6b0 | 2012-06-05 01:08:14 -0700 | [diff] [blame] | 1340 | request, |
| 1341 | true); |
| 1342 | if (res != OK) { |
| 1343 | return res; |
| 1344 | } |
| 1345 | // Pass 2, build request |
Sungjoong Kang | daa1fcd | 2012-08-08 11:49:43 -0700 | [diff] [blame] | 1346 | res = m_camera2->constructDefaultRequest(request_template, |
Jiyoung Shin | c15a6b0 | 2012-06-05 01:08:14 -0700 | [diff] [blame] | 1347 | request, |
| 1348 | false); |
| 1349 | if (res != OK) { |
| 1350 | ALOGE("Unable to populate new request for template %d", |
| 1351 | request_template); |
| 1352 | } |
| 1353 | |
| 1354 | return res; |
| 1355 | } |
| 1356 | |
| 1357 | int ExynosCameraHWInterface2::allocateStream(uint32_t width, uint32_t height, int format, const camera2_stream_ops_t *stream_ops, |
| 1358 | uint32_t *stream_id, uint32_t *format_actual, uint32_t *usage, uint32_t *max_buffers) |
| 1359 | { |
Sungjoong Kang | ad37861 | 2012-08-17 12:34:33 -0700 | [diff] [blame] | 1360 | ALOGV("DEBUG(%s): allocate stream width(%d) height(%d) format(%x)", __FUNCTION__, width, height, format); |
Jiyoung Shin | c15a6b0 | 2012-06-05 01:08:14 -0700 | [diff] [blame] | 1361 | char node_name[30]; |
Sungjoong Kang | 9dd63e1 | 2012-07-24 00:25:51 +0900 | [diff] [blame] | 1362 | int fd = 0, allocCase = 0; |
Sungjoong Kang | 13d8c7b | 2012-07-14 10:20:39 +0900 | [diff] [blame] | 1363 | StreamThread *AllocatedStream; |
| 1364 | stream_parameters_t newParameters; |
Jiyoung Shin | c15a6b0 | 2012-06-05 01:08:14 -0700 | [diff] [blame] | 1365 | |
Sungjoong Kang | daa1fcd | 2012-08-08 11:49:43 -0700 | [diff] [blame] | 1366 | if (format == CAMERA2_HAL_PIXEL_FORMAT_OPAQUE && |
| 1367 | m_camera2->isSupportedResolution(width, height)) { |
Sungjoong Kang | 9dd63e1 | 2012-07-24 00:25:51 +0900 | [diff] [blame] | 1368 | if (!(m_streamThreads[0].get())) { |
| 1369 | ALOGV("DEBUG(%s): stream 0 not exist", __FUNCTION__); |
| 1370 | allocCase = 0; |
Jiyoung Shin | c15a6b0 | 2012-06-05 01:08:14 -0700 | [diff] [blame] | 1371 | } |
Sungjoong Kang | 13d8c7b | 2012-07-14 10:20:39 +0900 | [diff] [blame] | 1372 | else { |
Alex Ray | 6bbb593 | 2012-07-27 17:19:48 -0700 | [diff] [blame] | 1373 | if ((m_streamThreads[0].get())->m_activated == true) { |
Sungjoong Kang | 9dd63e1 | 2012-07-24 00:25:51 +0900 | [diff] [blame] | 1374 | ALOGV("DEBUG(%s): stream 0 exists and activated.", __FUNCTION__); |
| 1375 | allocCase = 1; |
| 1376 | } |
| 1377 | else { |
| 1378 | ALOGV("DEBUG(%s): stream 0 exists and deactivated.", __FUNCTION__); |
| 1379 | allocCase = 2; |
| 1380 | } |
Sungjoong Kang | 13d8c7b | 2012-07-14 10:20:39 +0900 | [diff] [blame] | 1381 | } |
Sungjoong Kang | 15fd823 | 2012-08-23 16:16:44 -0700 | [diff] [blame] | 1382 | if ((width == 1920 && height == 1080) || (width == 1280 && height == 720)) { |
| 1383 | m_wideAspect = true; |
| 1384 | } |
| 1385 | else { |
| 1386 | m_wideAspect = false; |
| 1387 | } |
Sungjoong Kang | b55ed66 | 2012-08-31 21:31:34 -0700 | [diff] [blame] | 1388 | m_aspectChanged = true; |
Sungjoong Kang | 15fd823 | 2012-08-23 16:16:44 -0700 | [diff] [blame] | 1389 | ALOGV("DEBUG(%s): m_wideAspect (%d)", __FUNCTION__, m_wideAspect); |
| 1390 | |
Sungjoong Kang | 9dd63e1 | 2012-07-24 00:25:51 +0900 | [diff] [blame] | 1391 | if (allocCase == 0 || allocCase == 2) { |
| 1392 | *stream_id = 0; |
Jiyoung Shin | c15a6b0 | 2012-06-05 01:08:14 -0700 | [diff] [blame] | 1393 | |
Sungjoong Kang | 9dd63e1 | 2012-07-24 00:25:51 +0900 | [diff] [blame] | 1394 | if (allocCase == 0) { |
| 1395 | m_streamThreads[0] = new StreamThread(this, *stream_id); |
Sungjoong Kang | 9dd63e1 | 2012-07-24 00:25:51 +0900 | [diff] [blame] | 1396 | } |
| 1397 | AllocatedStream = (StreamThread*)(m_streamThreads[0].get()); |
Sungjoong Kang | b5237e6 | 2012-07-27 07:39:05 -0700 | [diff] [blame] | 1398 | m_scp_flushing = false; |
| 1399 | m_scp_closing = false; |
| 1400 | m_scp_closed = false; |
Sungjoong Kang | 9dd63e1 | 2012-07-24 00:25:51 +0900 | [diff] [blame] | 1401 | usleep(100000); // TODO : guarantee the codes below will be run after readyToRunInternal() |
Jiyoung Shin | c15a6b0 | 2012-06-05 01:08:14 -0700 | [diff] [blame] | 1402 | |
Rebecca Schultz Zavin | c853be7 | 2012-08-23 00:03:05 -0700 | [diff] [blame] | 1403 | *format_actual = HAL_PIXEL_FORMAT_EXYNOS_YV12; |
Alex Ray | 6bbb593 | 2012-07-27 17:19:48 -0700 | [diff] [blame] | 1404 | *usage = GRALLOC_USAGE_SW_WRITE_OFTEN; |
Sungjoong Kang | b55ed66 | 2012-08-31 21:31:34 -0700 | [diff] [blame] | 1405 | *max_buffers = 6; |
Jiyoung Shin | c15a6b0 | 2012-06-05 01:08:14 -0700 | [diff] [blame] | 1406 | |
Sungjoong Kang | 37e122d | 2012-08-08 11:13:48 -0700 | [diff] [blame] | 1407 | newParameters.streamType = STREAM_TYPE_DIRECT; |
Sungjoong Kang | 9dd63e1 | 2012-07-24 00:25:51 +0900 | [diff] [blame] | 1408 | newParameters.outputWidth = width; |
| 1409 | newParameters.outputHeight = height; |
| 1410 | newParameters.nodeWidth = width; |
| 1411 | newParameters.nodeHeight = height; |
| 1412 | newParameters.outputFormat = *format_actual; |
| 1413 | newParameters.nodeFormat = HAL_PIXEL_FORMAT_2_V4L2_PIX(*format_actual); |
| 1414 | newParameters.streamOps = stream_ops; |
| 1415 | newParameters.usage = *usage; |
Sungjoong Kang | be494d1 | 2012-08-04 15:36:56 -0700 | [diff] [blame] | 1416 | newParameters.numHwBuffers = 8; |
| 1417 | newParameters.numOwnSvcBuffers = *max_buffers; |
Sungjoong Kang | 9dd63e1 | 2012-07-24 00:25:51 +0900 | [diff] [blame] | 1418 | newParameters.fd = m_fd_scp; |
Sungjoong Kang | 74d78eb | 2012-08-29 13:25:46 -0700 | [diff] [blame] | 1419 | newParameters.nodePlanes = NUM_PLANES(*format_actual); |
| 1420 | newParameters.svcPlanes = NUM_PLANES(*format_actual); |
Sungjoong Kang | feb7df4 | 2012-08-28 23:35:43 +0900 | [diff] [blame] | 1421 | newParameters.metaPlanes = 1; |
Sungjoong Kang | 9dd63e1 | 2012-07-24 00:25:51 +0900 | [diff] [blame] | 1422 | newParameters.halBuftype = V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE; |
| 1423 | newParameters.memory = V4L2_MEMORY_DMABUF; |
| 1424 | newParameters.ionClient = m_ionCameraClient; |
Sungjoong Kang | be494d1 | 2012-08-04 15:36:56 -0700 | [diff] [blame] | 1425 | newParameters.numSvcBufsInHal = 0; |
Sungjoong Kang | 9dd63e1 | 2012-07-24 00:25:51 +0900 | [diff] [blame] | 1426 | AllocatedStream->m_index = *stream_id; |
| 1427 | AllocatedStream->setParameter(&newParameters); |
| 1428 | AllocatedStream->m_activated = true; |
Sungjoong Kang | 13d8c7b | 2012-07-14 10:20:39 +0900 | [diff] [blame] | 1429 | |
Sungjoong Kang | 9dd63e1 | 2012-07-24 00:25:51 +0900 | [diff] [blame] | 1430 | m_scp_flushing = false; |
| 1431 | m_scp_closing = false; |
| 1432 | m_scp_closed = false; |
Sungjoong Kang | ad37861 | 2012-08-17 12:34:33 -0700 | [diff] [blame] | 1433 | m_requestManager->SetDefaultParameters(m_camera2->getSensorW()); |
| 1434 | m_camera_info.dummy_shot.shot.ctl.scaler.cropRegion[2] = m_camera2->getSensorW(); |
Sungjoong Kang | 9dd63e1 | 2012-07-24 00:25:51 +0900 | [diff] [blame] | 1435 | return 0; |
| 1436 | } |
| 1437 | else if (allocCase == 1) { |
| 1438 | record_parameters_t recordParameters; |
| 1439 | StreamThread *parentStream; |
| 1440 | parentStream = (StreamThread*)(m_streamThreads[0].get()); |
| 1441 | if (!parentStream) { |
| 1442 | return 1; |
| 1443 | // TODO |
| 1444 | } |
| 1445 | *stream_id = 2; |
| 1446 | usleep(100000); // TODO : guarantee the codes below will be run after readyToRunInternal() |
| 1447 | |
Sungjoong Kang | 804236a | 2012-08-05 10:36:19 -0700 | [diff] [blame] | 1448 | *format_actual = HAL_PIXEL_FORMAT_YCbCr_420_SP; // NV12M |
Alex Ray | 6bbb593 | 2012-07-27 17:19:48 -0700 | [diff] [blame] | 1449 | *usage = GRALLOC_USAGE_SW_WRITE_OFTEN; |
James Dong | 2630679 | 2012-08-24 14:42:26 -0700 | [diff] [blame] | 1450 | *max_buffers = 6; |
Sungjoong Kang | 9dd63e1 | 2012-07-24 00:25:51 +0900 | [diff] [blame] | 1451 | |
| 1452 | recordParameters.outputWidth = width; |
| 1453 | recordParameters.outputHeight = height; |
| 1454 | recordParameters.outputFormat = *format_actual; |
Sungjoong Kang | 804236a | 2012-08-05 10:36:19 -0700 | [diff] [blame] | 1455 | recordParameters.svcPlanes = NUM_PLANES(*format_actual); |
Sungjoong Kang | 9dd63e1 | 2012-07-24 00:25:51 +0900 | [diff] [blame] | 1456 | recordParameters.streamOps = stream_ops; |
| 1457 | recordParameters.usage = *usage; |
Sungjoong Kang | be494d1 | 2012-08-04 15:36:56 -0700 | [diff] [blame] | 1458 | recordParameters.numOwnSvcBuffers = *max_buffers; |
| 1459 | recordParameters.numSvcBufsInHal = 0; |
Sungjoong Kang | 9dd63e1 | 2012-07-24 00:25:51 +0900 | [diff] [blame] | 1460 | |
| 1461 | parentStream->setRecordingParameter(&recordParameters); |
| 1462 | m_scp_flushing = false; |
| 1463 | m_scp_closing = false; |
| 1464 | m_scp_closed = false; |
| 1465 | m_recordingEnabled = true; |
| 1466 | return 0; |
| 1467 | } |
Sungjoong Kang | 13d8c7b | 2012-07-14 10:20:39 +0900 | [diff] [blame] | 1468 | } |
Sungjoong Kang | ad37861 | 2012-08-17 12:34:33 -0700 | [diff] [blame] | 1469 | else if (format == HAL_PIXEL_FORMAT_BLOB |
Sungjoong Kang | daa1fcd | 2012-08-08 11:49:43 -0700 | [diff] [blame] | 1470 | && m_camera2->isSupportedJpegResolution(width, height)) { |
Sungjoong Kang | 13d8c7b | 2012-07-14 10:20:39 +0900 | [diff] [blame] | 1471 | |
| 1472 | *stream_id = 1; |
| 1473 | |
Sungjoong Kang | 15fd823 | 2012-08-23 16:16:44 -0700 | [diff] [blame] | 1474 | if (!(m_streamThreads[*stream_id].get())) { |
Sungjoong Kang | 8e2c2fd | 2012-08-27 00:02:22 -0700 | [diff] [blame] | 1475 | ALOGV("DEBUG(%s): stream 1 not exist", __FUNCTION__); |
Sungjoong Kang | 15fd823 | 2012-08-23 16:16:44 -0700 | [diff] [blame] | 1476 | m_streamThreads[1] = new StreamThread(this, *stream_id); |
| 1477 | allocCase = 0; |
| 1478 | } |
| 1479 | else { |
| 1480 | if ((m_streamThreads[*stream_id].get())->m_activated == true) { |
Sungjoong Kang | 8e2c2fd | 2012-08-27 00:02:22 -0700 | [diff] [blame] | 1481 | ALOGV("DEBUG(%s): stream 1 exists and activated.", __FUNCTION__); |
Sungjoong Kang | 15fd823 | 2012-08-23 16:16:44 -0700 | [diff] [blame] | 1482 | allocCase = 1; |
| 1483 | } |
| 1484 | else { |
Sungjoong Kang | 8e2c2fd | 2012-08-27 00:02:22 -0700 | [diff] [blame] | 1485 | ALOGV("DEBUG(%s): stream 1 exists and deactivated.", __FUNCTION__); |
Sungjoong Kang | 15fd823 | 2012-08-23 16:16:44 -0700 | [diff] [blame] | 1486 | allocCase = 2; |
| 1487 | } |
| 1488 | } |
| 1489 | |
| 1490 | AllocatedStream = (StreamThread*)(m_streamThreads[*stream_id].get()); |
Sungjoong Kang | 9dd63e1 | 2012-07-24 00:25:51 +0900 | [diff] [blame] | 1491 | |
Sungjoong Kang | 13d8c7b | 2012-07-14 10:20:39 +0900 | [diff] [blame] | 1492 | fd = m_camera_info.capture.fd; |
| 1493 | usleep(100000); // TODO : guarantee the codes below will be run after readyToRunInternal() |
| 1494 | |
| 1495 | *format_actual = HAL_PIXEL_FORMAT_BLOB; |
| 1496 | |
| 1497 | *usage = GRALLOC_USAGE_SW_WRITE_OFTEN; |
Sungjoong Kang | 37e122d | 2012-08-08 11:13:48 -0700 | [diff] [blame] | 1498 | *max_buffers = 4; |
Sungjoong Kang | 13d8c7b | 2012-07-14 10:20:39 +0900 | [diff] [blame] | 1499 | |
Sungjoong Kang | 37e122d | 2012-08-08 11:13:48 -0700 | [diff] [blame] | 1500 | newParameters.streamType = STREAM_TYPE_INDIRECT; |
Sungjoong Kang | 13d8c7b | 2012-07-14 10:20:39 +0900 | [diff] [blame] | 1501 | newParameters.outputWidth = width; |
| 1502 | newParameters.outputHeight = height; |
Sungjoong Kang | 9dd63e1 | 2012-07-24 00:25:51 +0900 | [diff] [blame] | 1503 | |
Sungjoong Kang | daa1fcd | 2012-08-08 11:49:43 -0700 | [diff] [blame] | 1504 | newParameters.nodeWidth = m_camera2->getSensorW(); |
| 1505 | newParameters.nodeHeight = m_camera2->getSensorH(); |
Sungjoong Kang | 9dd63e1 | 2012-07-24 00:25:51 +0900 | [diff] [blame] | 1506 | |
Sungjoong Kang | 13d8c7b | 2012-07-14 10:20:39 +0900 | [diff] [blame] | 1507 | newParameters.outputFormat = *format_actual; |
| 1508 | newParameters.nodeFormat = V4L2_PIX_FMT_YUYV; |
| 1509 | newParameters.streamOps = stream_ops; |
| 1510 | newParameters.usage = *usage; |
Sungjoong Kang | be494d1 | 2012-08-04 15:36:56 -0700 | [diff] [blame] | 1511 | newParameters.numHwBuffers = 8; |
| 1512 | newParameters.numOwnSvcBuffers = *max_buffers; |
Sungjoong Kang | 13d8c7b | 2012-07-14 10:20:39 +0900 | [diff] [blame] | 1513 | newParameters.fd = fd; |
| 1514 | newParameters.nodePlanes = 1; |
| 1515 | newParameters.svcPlanes = 1; |
| 1516 | newParameters.halBuftype = V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE; |
| 1517 | newParameters.memory = V4L2_MEMORY_DMABUF; |
| 1518 | newParameters.ionClient = m_ionCameraClient; |
Sungjoong Kang | be494d1 | 2012-08-04 15:36:56 -0700 | [diff] [blame] | 1519 | newParameters.numSvcBufsInHal = 0; |
Sungjoong Kang | 9dd63e1 | 2012-07-24 00:25:51 +0900 | [diff] [blame] | 1520 | AllocatedStream->m_index = *stream_id; |
Sungjoong Kang | 13d8c7b | 2012-07-14 10:20:39 +0900 | [diff] [blame] | 1521 | AllocatedStream->setParameter(&newParameters); |
| 1522 | return 0; |
| 1523 | } |
Sungjoong Kang | 74d78eb | 2012-08-29 13:25:46 -0700 | [diff] [blame] | 1524 | else if (format == HAL_PIXEL_FORMAT_YCrCb_420_SP || format == HAL_PIXEL_FORMAT_YV12) { |
| 1525 | StreamThread *parentStream; |
| 1526 | callback_parameters_t callbackParameters; |
| 1527 | parentStream = (StreamThread*)(m_streamThreads[0].get()); |
| 1528 | if (!parentStream) { |
| 1529 | ALOGE("(%s): preview stream not exist", __FUNCTION__); |
| 1530 | return 1; |
| 1531 | } |
| 1532 | *stream_id = 3; |
| 1533 | |
| 1534 | *format_actual = format; |
| 1535 | *usage = GRALLOC_USAGE_SW_WRITE_OFTEN; |
| 1536 | *max_buffers = 4; |
| 1537 | if (width == parentStream->m_parameters.outputWidth |
| 1538 | && height == parentStream->m_parameters.outputHeight) { |
| 1539 | |
| 1540 | callbackParameters.outputWidth = width; |
| 1541 | callbackParameters.outputHeight = height; |
| 1542 | callbackParameters.outputFormat = *format_actual; |
| 1543 | callbackParameters.svcPlanes = NUM_PLANES(*format_actual); |
| 1544 | callbackParameters.streamOps = stream_ops; |
| 1545 | callbackParameters.usage = *usage; |
| 1546 | callbackParameters.numOwnSvcBuffers = *max_buffers; |
| 1547 | callbackParameters.numSvcBufsInHal = 0; |
| 1548 | if (format == HAL_PIXEL_FORMAT_YCrCb_420_SP) { |
| 1549 | callbackParameters.internalFormat = HAL_PIXEL_FORMAT_EXYNOS_YCrCb_420_SP; |
| 1550 | callbackParameters.internalPlanes = NUM_PLANES(HAL_PIXEL_FORMAT_EXYNOS_YCrCb_420_SP); |
| 1551 | } |
| 1552 | else { |
| 1553 | callbackParameters.internalFormat = HAL_PIXEL_FORMAT_EXYNOS_YV12; |
| 1554 | callbackParameters.internalPlanes = NUM_PLANES(HAL_PIXEL_FORMAT_EXYNOS_YV12); |
| 1555 | } |
| 1556 | |
| 1557 | parentStream->setCallbackParameter(&callbackParameters); |
| 1558 | m_previewCbEnabled = true; |
| 1559 | ALOGV("(%s): Enabling Previewcb - planes(%d)", __FUNCTION__, callbackParameters.svcPlanes); |
| 1560 | } |
| 1561 | return 0; |
| 1562 | } |
Sungjoong Kang | 13d8c7b | 2012-07-14 10:20:39 +0900 | [diff] [blame] | 1563 | ALOGE("DEBUG(%s): Unsupported Pixel Format", __FUNCTION__); |
| 1564 | return 1; // TODO : check proper error code |
| 1565 | } |
| 1566 | |
| 1567 | int ExynosCameraHWInterface2::registerStreamBuffers(uint32_t stream_id, |
| 1568 | int num_buffers, buffer_handle_t *registeringBuffers) |
| 1569 | { |
| 1570 | int i,j; |
| 1571 | void *virtAddr[3]; |
| 1572 | uint32_t plane_index = 0; |
| 1573 | stream_parameters_t *targetStreamParms; |
Sungjoong Kang | 9dd63e1 | 2012-07-24 00:25:51 +0900 | [diff] [blame] | 1574 | record_parameters_t *targetRecordParms; |
Sungjoong Kang | 74d78eb | 2012-08-29 13:25:46 -0700 | [diff] [blame] | 1575 | callback_parameters_t *targetCallbackParms; |
Sungjoong Kang | 13d8c7b | 2012-07-14 10:20:39 +0900 | [diff] [blame] | 1576 | node_info_t *currentNode; |
| 1577 | |
| 1578 | struct v4l2_buffer v4l2_buf; |
| 1579 | struct v4l2_plane planes[VIDEO_MAX_PLANES]; |
| 1580 | |
| 1581 | ALOGV("DEBUG(%s): streamID (%d), num_buff(%d), handle(%x) ", __FUNCTION__, |
| 1582 | stream_id, num_buffers, (uint32_t)registeringBuffers); |
| 1583 | |
| 1584 | if (stream_id == 0) { |
| 1585 | targetStreamParms = &(m_streamThreads[0]->m_parameters); |
| 1586 | } |
| 1587 | else if (stream_id == 1) { |
| 1588 | targetStreamParms = &(m_streamThreads[1]->m_parameters); |
Sungjoong Kang | 15fd823 | 2012-08-23 16:16:44 -0700 | [diff] [blame] | 1589 | // TODO : make clear stream off case |
| 1590 | m_need_streamoff = 0; |
| 1591 | |
| 1592 | if (m_camera_info.capture.status == false) { |
| 1593 | /* capture */ |
| 1594 | m_camera_info.capture.buffers = 8; |
| 1595 | cam_int_s_fmt(&(m_camera_info.capture)); |
| 1596 | cam_int_reqbufs(&(m_camera_info.capture)); |
| 1597 | for (i = 0; i < m_camera_info.capture.buffers; i++) { |
| 1598 | ALOGV("DEBUG(%s): capture initial QBUF [%d]", __FUNCTION__, i); |
| 1599 | cam_int_qbuf(&(m_camera_info.capture), i); |
| 1600 | } |
| 1601 | |
| 1602 | if (cam_int_streamon(&(m_camera_info.capture)) < 0) { |
| 1603 | ALOGE("ERR(%s): capture stream on fail", __FUNCTION__); |
| 1604 | } else { |
| 1605 | m_camera_info.capture.status = true; |
| 1606 | } |
| 1607 | } |
Sungjoong Kang | 13d8c7b | 2012-07-14 10:20:39 +0900 | [diff] [blame] | 1608 | } |
Sungjoong Kang | 9dd63e1 | 2012-07-24 00:25:51 +0900 | [diff] [blame] | 1609 | else if (stream_id == 2) { |
| 1610 | targetRecordParms = &(m_streamThreads[0]->m_recordParameters); |
| 1611 | |
| 1612 | targetRecordParms->numSvcBuffers = num_buffers; |
| 1613 | |
| 1614 | for (i = 0 ; i<targetRecordParms->numSvcBuffers ; i++) { |
| 1615 | ALOGV("DEBUG(%s): registering Stream Buffers[%d] (%x) ", __FUNCTION__, |
| 1616 | i, (uint32_t)(registeringBuffers[i])); |
| 1617 | if (m_grallocHal) { |
| 1618 | if (m_grallocHal->lock(m_grallocHal, registeringBuffers[i], |
| 1619 | targetRecordParms->usage, 0, 0, |
| 1620 | targetRecordParms->outputWidth, targetRecordParms->outputHeight, virtAddr) != 0) { |
| 1621 | ALOGE("ERR(%s): could not obtain gralloc buffer", __FUNCTION__); |
| 1622 | } |
| 1623 | else { |
| 1624 | ExynosBuffer currentBuf; |
| 1625 | const private_handle_t *priv_handle = reinterpret_cast<const private_handle_t *>(registeringBuffers[i]); |
Sungjoong Kang | 9dd63e1 | 2012-07-24 00:25:51 +0900 | [diff] [blame] | 1626 | currentBuf.fd.extFd[0] = priv_handle->fd; |
Alex Ray | 6bbb593 | 2012-07-27 17:19:48 -0700 | [diff] [blame] | 1627 | currentBuf.fd.extFd[1] = priv_handle->fd1; |
| 1628 | currentBuf.fd.extFd[2] = priv_handle->fd2; |
Sungjoong Kang | 9dd63e1 | 2012-07-24 00:25:51 +0900 | [diff] [blame] | 1629 | for (plane_index=0 ; plane_index < targetRecordParms->svcPlanes ; plane_index++) { |
| 1630 | currentBuf.virt.extP[plane_index] = (char *)virtAddr[plane_index]; |
| 1631 | ALOGV("DEBUG(%s): plane(%d): fd(%d) addr(%x)", |
Sungjoong Kang | 804236a | 2012-08-05 10:36:19 -0700 | [diff] [blame] | 1632 | __FUNCTION__, plane_index, currentBuf.fd.extFd[plane_index], |
Sungjoong Kang | 9dd63e1 | 2012-07-24 00:25:51 +0900 | [diff] [blame] | 1633 | (unsigned int)currentBuf.virt.extP[plane_index]); |
| 1634 | } |
| 1635 | targetRecordParms->svcBufStatus[i] = ON_SERVICE; |
Sungjoong Kang | b5237e6 | 2012-07-27 07:39:05 -0700 | [diff] [blame] | 1636 | targetRecordParms->svcBuffers[i] = currentBuf; |
| 1637 | targetRecordParms->svcBufHandle[i] = registeringBuffers[i]; |
Sungjoong Kang | 9dd63e1 | 2012-07-24 00:25:51 +0900 | [diff] [blame] | 1638 | } |
| 1639 | } |
| 1640 | } |
| 1641 | m_needsRecordBufferInit = true; |
| 1642 | return 0; |
| 1643 | } |
Sungjoong Kang | 74d78eb | 2012-08-29 13:25:46 -0700 | [diff] [blame] | 1644 | else if (stream_id == 3) { |
| 1645 | targetCallbackParms = &(m_streamThreads[0]->m_previewCbParameters); |
| 1646 | |
| 1647 | targetCallbackParms->numSvcBuffers = num_buffers; |
| 1648 | |
| 1649 | for (i = 0 ; i < targetCallbackParms->numSvcBuffers ; i++) { |
| 1650 | ALOGE("%s: registering Stream Buffers[%d] (%x) ", __FUNCTION__, |
| 1651 | i, (uint32_t)(registeringBuffers[i])); |
| 1652 | if (m_grallocHal) { |
| 1653 | if (m_grallocHal->lock(m_grallocHal, registeringBuffers[i], |
| 1654 | targetCallbackParms->usage, 0, 0, |
| 1655 | targetCallbackParms->outputWidth, targetCallbackParms->outputHeight, virtAddr) != 0) { |
| 1656 | ALOGE("ERR(%s): could not obtain gralloc buffer", __FUNCTION__); |
| 1657 | } |
| 1658 | else { |
| 1659 | ExynosBuffer currentBuf; |
| 1660 | const private_handle_t *priv_handle = reinterpret_cast<const private_handle_t *>(registeringBuffers[i]); |
| 1661 | currentBuf.fd.extFd[0] = priv_handle->fd; |
| 1662 | currentBuf.fd.extFd[1] = priv_handle->fd1; |
| 1663 | currentBuf.fd.extFd[2] = priv_handle->fd2; |
| 1664 | for (plane_index = 0 ; plane_index < targetCallbackParms->svcPlanes ; plane_index++) { |
| 1665 | currentBuf.virt.extP[plane_index] = (char *)virtAddr[plane_index]; |
| 1666 | } |
| 1667 | ALOGV("fd(%d) addr(%x) fd1(%d) fd2(%d)", priv_handle->fd, (unsigned int)currentBuf.virt.extP[plane_index], |
| 1668 | priv_handle->fd1, priv_handle->fd2); |
| 1669 | ALOGV("flags(%d) size(%d) offset(%d) stride(%d) vstride(%d)", |
| 1670 | priv_handle->flags, priv_handle->size, priv_handle->offset, |
| 1671 | priv_handle->stride, priv_handle->vstride); |
| 1672 | targetCallbackParms->svcBufStatus[i] = ON_SERVICE; |
| 1673 | targetCallbackParms->svcBuffers[i] = currentBuf; |
| 1674 | targetCallbackParms->svcBufHandle[i] = registeringBuffers[i]; |
| 1675 | } |
| 1676 | } |
| 1677 | } |
| 1678 | m_needsPreviewCbBufferInit = true; |
| 1679 | return 0; |
| 1680 | } |
Sungjoong Kang | 13d8c7b | 2012-07-14 10:20:39 +0900 | [diff] [blame] | 1681 | else { |
| 1682 | ALOGE("ERR(%s) unregisterd stream id (%d)", __FUNCTION__, stream_id); |
Sungjoong Kang | be494d1 | 2012-08-04 15:36:56 -0700 | [diff] [blame] | 1683 | return 1; |
Sungjoong Kang | 13d8c7b | 2012-07-14 10:20:39 +0900 | [diff] [blame] | 1684 | } |
| 1685 | |
Sungjoong Kang | 37e122d | 2012-08-08 11:13:48 -0700 | [diff] [blame] | 1686 | if (targetStreamParms->streamType == STREAM_TYPE_DIRECT) { |
Sungjoong Kang | 13d8c7b | 2012-07-14 10:20:39 +0900 | [diff] [blame] | 1687 | if (num_buffers < targetStreamParms->numHwBuffers) { |
| 1688 | ALOGE("ERR(%s) registering insufficient num of buffers (%d) < (%d)", |
| 1689 | __FUNCTION__, num_buffers, targetStreamParms->numHwBuffers); |
Sungjoong Kang | be494d1 | 2012-08-04 15:36:56 -0700 | [diff] [blame] | 1690 | return 1; |
Sungjoong Kang | 13d8c7b | 2012-07-14 10:20:39 +0900 | [diff] [blame] | 1691 | } |
| 1692 | } |
| 1693 | ALOGV("DEBUG(%s): format(%x) width(%d), height(%d) svcPlanes(%d)", |
| 1694 | __FUNCTION__, targetStreamParms->outputFormat, targetStreamParms->outputWidth, |
| 1695 | targetStreamParms->outputHeight, targetStreamParms->svcPlanes); |
| 1696 | |
| 1697 | targetStreamParms->numSvcBuffers = num_buffers; |
| 1698 | currentNode = &(targetStreamParms->node); // TO Remove |
| 1699 | |
| 1700 | currentNode->fd = targetStreamParms->fd; |
| 1701 | currentNode->width = targetStreamParms->nodeWidth; |
| 1702 | currentNode->height = targetStreamParms->nodeHeight; |
| 1703 | currentNode->format = targetStreamParms->nodeFormat; |
| 1704 | currentNode->planes = targetStreamParms->nodePlanes; |
| 1705 | currentNode->buffers = targetStreamParms->numHwBuffers; |
| 1706 | currentNode->type = targetStreamParms->halBuftype; |
| 1707 | currentNode->memory = targetStreamParms->memory; |
| 1708 | currentNode->ionClient = targetStreamParms->ionClient; |
| 1709 | |
Sungjoong Kang | 37e122d | 2012-08-08 11:13:48 -0700 | [diff] [blame] | 1710 | if (targetStreamParms->streamType == STREAM_TYPE_DIRECT) { |
Sungjoong Kang | ad37861 | 2012-08-17 12:34:33 -0700 | [diff] [blame] | 1711 | if(m_need_streamoff == 1) { |
Sungjoong Kang | 15fd823 | 2012-08-23 16:16:44 -0700 | [diff] [blame] | 1712 | if (m_sensorThread != NULL) { |
| 1713 | m_sensorThread->release(); |
| 1714 | /* TODO */ |
| 1715 | usleep(500000); |
| 1716 | } else { |
| 1717 | ALOGE("+++++++ sensor thread is NULL %d", __LINE__); |
| 1718 | } |
| 1719 | |
Sungjoong Kang | ad37861 | 2012-08-17 12:34:33 -0700 | [diff] [blame] | 1720 | ALOGV("(%s): calling capture streamoff", __FUNCTION__); |
Sungjoong Kang | 15fd823 | 2012-08-23 16:16:44 -0700 | [diff] [blame] | 1721 | if (cam_int_streamoff(&(m_camera_info.capture)) < 0) { |
| 1722 | ALOGE("ERR(%s): capture stream off fail", __FUNCTION__); |
| 1723 | } else { |
| 1724 | m_camera_info.capture.status = false; |
| 1725 | } |
| 1726 | |
Sungjoong Kang | ad37861 | 2012-08-17 12:34:33 -0700 | [diff] [blame] | 1727 | ALOGV("(%s): calling capture streamoff done", __FUNCTION__); |
| 1728 | |
| 1729 | m_camera_info.capture.buffers = 0; |
| 1730 | ALOGV("DEBUG(%s): capture calling reqbuf 0 ", __FUNCTION__); |
| 1731 | cam_int_reqbufs(&(m_camera_info.capture)); |
| 1732 | ALOGV("DEBUG(%s): capture calling reqbuf 0 done", __FUNCTION__); |
| 1733 | |
Sungjoong Kang | ad37861 | 2012-08-17 12:34:33 -0700 | [diff] [blame] | 1734 | m_isIspStarted = false; |
| 1735 | } |
| 1736 | |
Sungjoong Kang | ad37861 | 2012-08-17 12:34:33 -0700 | [diff] [blame] | 1737 | if (m_need_streamoff == 1) { |
| 1738 | m_camera_info.sensor.buffers = NUM_BAYER_BUFFERS; |
| 1739 | m_camera_info.isp.buffers = m_camera_info.sensor.buffers; |
| 1740 | m_camera_info.capture.buffers = 8; |
Sungjoong Kang | 15fd823 | 2012-08-23 16:16:44 -0700 | [diff] [blame] | 1741 | /* isp */ |
| 1742 | cam_int_s_fmt(&(m_camera_info.isp)); |
Sungjoong Kang | ad37861 | 2012-08-17 12:34:33 -0700 | [diff] [blame] | 1743 | cam_int_reqbufs(&(m_camera_info.isp)); |
Sungjoong Kang | 15fd823 | 2012-08-23 16:16:44 -0700 | [diff] [blame] | 1744 | /* sensor */ |
| 1745 | cam_int_s_fmt(&(m_camera_info.sensor)); |
Sungjoong Kang | ad37861 | 2012-08-17 12:34:33 -0700 | [diff] [blame] | 1746 | cam_int_reqbufs(&(m_camera_info.sensor)); |
| 1747 | |
| 1748 | for (i = 0; i < 8; i++) { |
| 1749 | ALOGV("DEBUG(%s): sensor initial QBUF [%d]", __FUNCTION__, i); |
| 1750 | memcpy( m_camera_info.sensor.buffer[i].virt.extP[1], &(m_camera_info.dummy_shot), |
| 1751 | sizeof(struct camera2_shot_ext)); |
| 1752 | m_camera_info.dummy_shot.shot.ctl.sensor.frameDuration = 33*1000*1000; // apply from frame #1 |
| 1753 | m_camera_info.dummy_shot.shot.ctl.request.frameCount = -1; |
| 1754 | cam_int_qbuf(&(m_camera_info.sensor), i); |
| 1755 | } |
| 1756 | |
Sungjoong Kang | 15fd823 | 2012-08-23 16:16:44 -0700 | [diff] [blame] | 1757 | /* capture */ |
| 1758 | cam_int_s_fmt(&(m_camera_info.capture)); |
Sungjoong Kang | ad37861 | 2012-08-17 12:34:33 -0700 | [diff] [blame] | 1759 | cam_int_reqbufs(&(m_camera_info.capture)); |
Sungjoong Kang | 15fd823 | 2012-08-23 16:16:44 -0700 | [diff] [blame] | 1760 | for (i = 0; i < m_camera_info.capture.buffers; i++) { |
| 1761 | ALOGV("DEBUG(%s): capture initial QBUF [%d]", __FUNCTION__, i); |
| 1762 | cam_int_qbuf(&(m_camera_info.capture), i); |
| 1763 | } |
Sungjoong Kang | ad37861 | 2012-08-17 12:34:33 -0700 | [diff] [blame] | 1764 | |
Sungjoong Kang | 15fd823 | 2012-08-23 16:16:44 -0700 | [diff] [blame] | 1765 | } |
| 1766 | |
| 1767 | cam_int_s_input(currentNode, m_camera_info.sensor_id); |
| 1768 | cam_int_s_fmt(currentNode); |
| 1769 | cam_int_reqbufs(currentNode); |
| 1770 | |
Sungjoong Kang | 13d8c7b | 2012-07-14 10:20:39 +0900 | [diff] [blame] | 1771 | } |
Sungjoong Kang | 37e122d | 2012-08-08 11:13:48 -0700 | [diff] [blame] | 1772 | else if (targetStreamParms->streamType == STREAM_TYPE_INDIRECT) { |
Sungjoong Kang | 13d8c7b | 2012-07-14 10:20:39 +0900 | [diff] [blame] | 1773 | for(i = 0; i < currentNode->buffers; i++){ |
| 1774 | memcpy(&(currentNode->buffer[i]), &(m_camera_info.capture.buffer[i]), sizeof(ExynosBuffer)); |
| 1775 | } |
| 1776 | } |
| 1777 | |
| 1778 | for (i = 0 ; i<targetStreamParms->numSvcBuffers ; i++) { |
| 1779 | ALOGV("DEBUG(%s): registering Stream Buffers[%d] (%x) ", __FUNCTION__, |
| 1780 | i, (uint32_t)(registeringBuffers[i])); |
| 1781 | if (m_grallocHal) { |
| 1782 | if (m_grallocHal->lock(m_grallocHal, registeringBuffers[i], |
| 1783 | targetStreamParms->usage, 0, 0, |
| 1784 | currentNode->width, currentNode->height, virtAddr) != 0) { |
| 1785 | ALOGE("ERR(%s): could not obtain gralloc buffer", __FUNCTION__); |
| 1786 | } |
| 1787 | else { |
| 1788 | v4l2_buf.m.planes = planes; |
| 1789 | v4l2_buf.type = currentNode->type; |
| 1790 | v4l2_buf.memory = currentNode->memory; |
| 1791 | v4l2_buf.index = i; |
| 1792 | v4l2_buf.length = currentNode->planes; |
| 1793 | |
| 1794 | ExynosBuffer currentBuf; |
Sungjoong Kang | feb7df4 | 2012-08-28 23:35:43 +0900 | [diff] [blame] | 1795 | ExynosBuffer metaBuf; |
Sungjoong Kang | 13d8c7b | 2012-07-14 10:20:39 +0900 | [diff] [blame] | 1796 | const private_handle_t *priv_handle = reinterpret_cast<const private_handle_t *>(registeringBuffers[i]); |
| 1797 | |
| 1798 | m_getAlignedYUVSize(currentNode->format, |
| 1799 | currentNode->width, currentNode->height, ¤tBuf); |
Alex Ray | 2423122 | 2012-06-27 15:18:15 -0700 | [diff] [blame] | 1800 | |
Sungjoong Kang | 37e122d | 2012-08-08 11:13:48 -0700 | [diff] [blame] | 1801 | ALOGV("DEBUG(%s): ion_size(%d), stride(%d), ", __FUNCTION__, priv_handle->size, priv_handle->stride); |
| 1802 | if (currentNode->planes == 1) { |
Sungjoong Kang | 74d78eb | 2012-08-29 13:25:46 -0700 | [diff] [blame] | 1803 | v4l2_buf.m.planes[0].m.fd = priv_handle->fd; |
| 1804 | currentBuf.fd.extFd[0] = priv_handle->fd; |
Sungjoong Kang | 37e122d | 2012-08-08 11:13:48 -0700 | [diff] [blame] | 1805 | currentBuf.size.extS[0] = priv_handle->size; |
| 1806 | currentBuf.size.extS[1] = 0; |
| 1807 | currentBuf.size.extS[2] = 0; |
Sungjoong Kang | 74d78eb | 2012-08-29 13:25:46 -0700 | [diff] [blame] | 1808 | } else if (currentNode->planes == 2) { |
| 1809 | v4l2_buf.m.planes[0].m.fd = priv_handle->fd; |
| 1810 | v4l2_buf.m.planes[1].m.fd = priv_handle->fd1; |
| 1811 | currentBuf.fd.extFd[0] = priv_handle->fd; |
| 1812 | currentBuf.fd.extFd[1] = priv_handle->fd1; |
| 1813 | |
| 1814 | } else if (currentNode->planes == 3) { |
| 1815 | v4l2_buf.m.planes[0].m.fd = priv_handle->fd; |
| 1816 | v4l2_buf.m.planes[2].m.fd = priv_handle->fd1; |
| 1817 | v4l2_buf.m.planes[1].m.fd = priv_handle->fd2; |
| 1818 | currentBuf.fd.extFd[0] = priv_handle->fd; |
| 1819 | currentBuf.fd.extFd[2] = priv_handle->fd1; |
| 1820 | currentBuf.fd.extFd[1] = priv_handle->fd2; |
Sungjoong Kang | 37e122d | 2012-08-08 11:13:48 -0700 | [diff] [blame] | 1821 | } |
Sungjoong Kang | be494d1 | 2012-08-04 15:36:56 -0700 | [diff] [blame] | 1822 | for (plane_index = 0 ; plane_index < v4l2_buf.length ; plane_index++) { |
Sungjoong Kang | 13d8c7b | 2012-07-14 10:20:39 +0900 | [diff] [blame] | 1823 | currentBuf.virt.extP[plane_index] = (char *)virtAddr[plane_index]; |
| 1824 | v4l2_buf.m.planes[plane_index].length = currentBuf.size.extS[plane_index]; |
| 1825 | ALOGV("DEBUG(%s): plane(%d): fd(%d) addr(%x), length(%d)", |
| 1826 | __FUNCTION__, plane_index, v4l2_buf.m.planes[plane_index].m.fd, |
| 1827 | (unsigned int)currentBuf.virt.extP[plane_index], |
| 1828 | v4l2_buf.m.planes[plane_index].length); |
Jiyoung Shin | c15a6b0 | 2012-06-05 01:08:14 -0700 | [diff] [blame] | 1829 | } |
Sungjoong Kang | 13d8c7b | 2012-07-14 10:20:39 +0900 | [diff] [blame] | 1830 | |
Sungjoong Kang | 37e122d | 2012-08-08 11:13:48 -0700 | [diff] [blame] | 1831 | if (targetStreamParms->streamType == STREAM_TYPE_DIRECT) { |
Sungjoong Kang | 13d8c7b | 2012-07-14 10:20:39 +0900 | [diff] [blame] | 1832 | if (i < currentNode->buffers) { |
Sungjoong Kang | feb7df4 | 2012-08-28 23:35:43 +0900 | [diff] [blame] | 1833 | |
| 1834 | |
| 1835 | #ifdef ENABLE_FRAME_SYNC |
| 1836 | /* add plane for metadata*/ |
| 1837 | metaBuf.size.extS[0] = 4*1024; |
| 1838 | allocCameraMemory(targetStreamParms->ionClient , &metaBuf, 1); |
| 1839 | |
| 1840 | v4l2_buf.length += targetStreamParms->metaPlanes; |
| 1841 | v4l2_buf.m.planes[3].m.fd = metaBuf.fd.extFd[0]; |
| 1842 | v4l2_buf.m.planes[3].length = metaBuf.size.extS[0]; |
| 1843 | |
| 1844 | ALOGV("Qbuf metaBuf: fd(%d), length(%d) plane(%d)", metaBuf.fd.extFd[0], metaBuf.size.extS[0], v4l2_buf.length); |
| 1845 | #endif |
Sungjoong Kang | 13d8c7b | 2012-07-14 10:20:39 +0900 | [diff] [blame] | 1846 | if (exynos_v4l2_qbuf(currentNode->fd, &v4l2_buf) < 0) { |
Sungjoong Kang | 9dd63e1 | 2012-07-24 00:25:51 +0900 | [diff] [blame] | 1847 | ALOGE("ERR(%s): stream id(%d) exynos_v4l2_qbuf() fail fd(%d)", |
| 1848 | __FUNCTION__, stream_id, currentNode->fd); |
| 1849 | //return false; |
Sungjoong Kang | 13d8c7b | 2012-07-14 10:20:39 +0900 | [diff] [blame] | 1850 | } |
Sungjoong Kang | 9dd63e1 | 2012-07-24 00:25:51 +0900 | [diff] [blame] | 1851 | ALOGV("DEBUG(%s): stream id(%d) exynos_v4l2_qbuf() success fd(%d)", |
| 1852 | __FUNCTION__, stream_id, currentNode->fd); |
Sungjoong Kang | 13d8c7b | 2012-07-14 10:20:39 +0900 | [diff] [blame] | 1853 | targetStreamParms->svcBufStatus[i] = REQUIRES_DQ_FROM_SVC; |
| 1854 | } |
| 1855 | else { |
| 1856 | targetStreamParms->svcBufStatus[i] = ON_SERVICE; |
| 1857 | } |
| 1858 | } |
Sungjoong Kang | 37e122d | 2012-08-08 11:13:48 -0700 | [diff] [blame] | 1859 | else if (targetStreamParms->streamType == STREAM_TYPE_INDIRECT) { |
Sungjoong Kang | 13d8c7b | 2012-07-14 10:20:39 +0900 | [diff] [blame] | 1860 | targetStreamParms->svcBufStatus[i] = ON_SERVICE; |
| 1861 | } |
| 1862 | targetStreamParms->svcBuffers[i] = currentBuf; |
Sungjoong Kang | feb7df4 | 2012-08-28 23:35:43 +0900 | [diff] [blame] | 1863 | targetStreamParms->metaBuffers[i] = metaBuf; |
Sungjoong Kang | 13d8c7b | 2012-07-14 10:20:39 +0900 | [diff] [blame] | 1864 | targetStreamParms->svcBufHandle[i] = registeringBuffers[i]; |
| 1865 | } |
Jiyoung Shin | c15a6b0 | 2012-06-05 01:08:14 -0700 | [diff] [blame] | 1866 | } |
Jiyoung Shin | c15a6b0 | 2012-06-05 01:08:14 -0700 | [diff] [blame] | 1867 | } |
Sungjoong Kang | ad37861 | 2012-08-17 12:34:33 -0700 | [diff] [blame] | 1868 | |
Sungjoong Kang | 9dd63e1 | 2012-07-24 00:25:51 +0900 | [diff] [blame] | 1869 | ALOGV("DEBUG(%s): calling streamon", __FUNCTION__); |
Sungjoong Kang | 15fd823 | 2012-08-23 16:16:44 -0700 | [diff] [blame] | 1870 | if (targetStreamParms->streamType == STREAM_TYPE_DIRECT) { |
Sungjoong Kang | ad37861 | 2012-08-17 12:34:33 -0700 | [diff] [blame] | 1871 | ALOGD("%s(%d), stream id = %d", __FUNCTION__, __LINE__, stream_id); |
| 1872 | cam_int_streamon(&(targetStreamParms->node)); |
| 1873 | } |
| 1874 | |
Sungjoong Kang | 15fd823 | 2012-08-23 16:16:44 -0700 | [diff] [blame] | 1875 | if (m_need_streamoff == 1) { |
| 1876 | if (cam_int_streamon(&(m_camera_info.capture)) < 0) { |
| 1877 | ALOGE("ERR(%s): capture stream on fail", __FUNCTION__); |
| 1878 | } else { |
| 1879 | m_camera_info.capture.status = true; |
| 1880 | } |
| 1881 | |
| 1882 | cam_int_streamon(&(m_camera_info.sensor)); |
| 1883 | } |
| 1884 | |
Sungjoong Kang | ad37861 | 2012-08-17 12:34:33 -0700 | [diff] [blame] | 1885 | ALOGV("DEBUG(%s): calling streamon END", __FUNCTION__); |
Sungjoong Kang | 13d8c7b | 2012-07-14 10:20:39 +0900 | [diff] [blame] | 1886 | ALOGV("DEBUG(%s): END registerStreamBuffers", __FUNCTION__); |
Sungjoong Kang | ad37861 | 2012-08-17 12:34:33 -0700 | [diff] [blame] | 1887 | |
| 1888 | if(!m_isIspStarted) { |
| 1889 | m_isIspStarted = true; |
| 1890 | StartISP(); |
Sungjoong Kang | ad37861 | 2012-08-17 12:34:33 -0700 | [diff] [blame] | 1891 | } |
| 1892 | |
Sungjoong Kang | 15fd823 | 2012-08-23 16:16:44 -0700 | [diff] [blame] | 1893 | if (m_need_streamoff == 1) { |
| 1894 | m_requestManager->SetInitialSkip(8); |
| 1895 | m_sensorThread->Start("SensorThread", PRIORITY_DEFAULT, 0); |
| 1896 | m_mainThread->SetSignal(SIGNAL_MAIN_REQ_Q_NOT_EMPTY); |
| 1897 | } |
| 1898 | m_need_streamoff = 1; |
| 1899 | |
Jiyoung Shin | c15a6b0 | 2012-06-05 01:08:14 -0700 | [diff] [blame] | 1900 | return 0; |
| 1901 | } |
| 1902 | |
| 1903 | int ExynosCameraHWInterface2::releaseStream(uint32_t stream_id) |
| 1904 | { |
Sungjoong Kang | 13d8c7b | 2012-07-14 10:20:39 +0900 | [diff] [blame] | 1905 | StreamThread *targetStream; |
| 1906 | ALOGV("DEBUG(%s):", __FUNCTION__); |
| 1907 | |
Sungjoong Kang | b5237e6 | 2012-07-27 07:39:05 -0700 | [diff] [blame] | 1908 | if (stream_id == 0) { |
Sungjoong Kang | 13d8c7b | 2012-07-14 10:20:39 +0900 | [diff] [blame] | 1909 | targetStream = (StreamThread*)(m_streamThreads[0].get()); |
Sungjoong Kang | 9dd63e1 | 2012-07-24 00:25:51 +0900 | [diff] [blame] | 1910 | m_scp_flushing = true; |
Sungjoong Kang | 13d8c7b | 2012-07-14 10:20:39 +0900 | [diff] [blame] | 1911 | } |
Sungjoong Kang | b5237e6 | 2012-07-27 07:39:05 -0700 | [diff] [blame] | 1912 | else if (stream_id == 1) { |
Sungjoong Kang | 13d8c7b | 2012-07-14 10:20:39 +0900 | [diff] [blame] | 1913 | targetStream = (StreamThread*)(m_streamThreads[1].get()); |
| 1914 | } |
Sungjoong Kang | b5237e6 | 2012-07-27 07:39:05 -0700 | [diff] [blame] | 1915 | else if (stream_id == 2 && m_recordingEnabled) { |
| 1916 | m_recordingEnabled = false; |
Sungjoong Kang | ad37861 | 2012-08-17 12:34:33 -0700 | [diff] [blame] | 1917 | m_needsRecordBufferInit = true; |
Sungjoong Kang | b5237e6 | 2012-07-27 07:39:05 -0700 | [diff] [blame] | 1918 | return 0; |
| 1919 | } |
Sungjoong Kang | 74d78eb | 2012-08-29 13:25:46 -0700 | [diff] [blame] | 1920 | else if (stream_id == 3 && m_previewCbEnabled) { |
| 1921 | m_previewCbEnabled = false; |
| 1922 | m_needsPreviewCbBufferInit = true; |
| 1923 | return 0; |
| 1924 | } |
Sungjoong Kang | 13d8c7b | 2012-07-14 10:20:39 +0900 | [diff] [blame] | 1925 | else { |
| 1926 | ALOGE("ERR:(%s): wrong stream id (%d)", __FUNCTION__, stream_id); |
Sungjoong Kang | be494d1 | 2012-08-04 15:36:56 -0700 | [diff] [blame] | 1927 | return 1; |
Sungjoong Kang | 13d8c7b | 2012-07-14 10:20:39 +0900 | [diff] [blame] | 1928 | } |
| 1929 | |
Sungjoong Kang | b5237e6 | 2012-07-27 07:39:05 -0700 | [diff] [blame] | 1930 | targetStream->m_releasing = true; |
Sungjoong Kang | 15fd823 | 2012-08-23 16:16:44 -0700 | [diff] [blame] | 1931 | do { |
| 1932 | ALOGD("stream thread release %d", __LINE__); |
| 1933 | targetStream->release(); |
| 1934 | usleep(33000); |
| 1935 | } while (targetStream->m_releasing); |
Sungjoong Kang | 9dd63e1 | 2012-07-24 00:25:51 +0900 | [diff] [blame] | 1936 | targetStream->m_activated = false; |
Sungjoong Kang | 13d8c7b | 2012-07-14 10:20:39 +0900 | [diff] [blame] | 1937 | ALOGV("DEBUG(%s): DONE", __FUNCTION__); |
Jiyoung Shin | c15a6b0 | 2012-06-05 01:08:14 -0700 | [diff] [blame] | 1938 | return 0; |
| 1939 | } |
| 1940 | |
| 1941 | int ExynosCameraHWInterface2::allocateReprocessStream( |
Sungjoong Kang | 13d8c7b | 2012-07-14 10:20:39 +0900 | [diff] [blame] | 1942 | uint32_t width, uint32_t height, uint32_t format, |
| 1943 | const camera2_stream_in_ops_t *reprocess_stream_ops, |
Jiyoung Shin | c15a6b0 | 2012-06-05 01:08:14 -0700 | [diff] [blame] | 1944 | uint32_t *stream_id, uint32_t *consumer_usage, uint32_t *max_buffers) |
| 1945 | { |
Sungjoong Kang | 13d8c7b | 2012-07-14 10:20:39 +0900 | [diff] [blame] | 1946 | ALOGV("DEBUG(%s):", __FUNCTION__); |
Jiyoung Shin | c15a6b0 | 2012-06-05 01:08:14 -0700 | [diff] [blame] | 1947 | return 0; |
| 1948 | } |
| 1949 | |
| 1950 | int ExynosCameraHWInterface2::releaseReprocessStream(uint32_t stream_id) |
| 1951 | { |
Sungjoong Kang | 13d8c7b | 2012-07-14 10:20:39 +0900 | [diff] [blame] | 1952 | ALOGV("DEBUG(%s):", __FUNCTION__); |
Jiyoung Shin | c15a6b0 | 2012-06-05 01:08:14 -0700 | [diff] [blame] | 1953 | return 0; |
| 1954 | } |
| 1955 | |
| 1956 | int ExynosCameraHWInterface2::triggerAction(uint32_t trigger_id, int ext1, int ext2) |
| 1957 | { |
Sungjoong Kang | 0f26b20 | 2012-08-17 15:43:12 -0700 | [diff] [blame] | 1958 | ALOGV("DEBUG(%s): id(%x), %d, %d", __FUNCTION__, trigger_id, ext1, ext2); |
| 1959 | |
| 1960 | switch (trigger_id) { |
| 1961 | case CAMERA2_TRIGGER_AUTOFOCUS: |
| 1962 | ALOGV("DEBUG(%s):TRIGGER_AUTOFOCUS id(%d)", __FUNCTION__, ext1); |
Sungjoong Kang | 8e2c2fd | 2012-08-27 00:02:22 -0700 | [diff] [blame] | 1963 | OnAfTriggerStart(ext1); |
Sungjoong Kang | 0f26b20 | 2012-08-17 15:43:12 -0700 | [diff] [blame] | 1964 | break; |
| 1965 | |
| 1966 | case CAMERA2_TRIGGER_CANCEL_AUTOFOCUS: |
| 1967 | ALOGV("DEBUG(%s):CANCEL_AUTOFOCUS id(%d)", __FUNCTION__, ext1); |
| 1968 | OnAfCancel(ext1); |
| 1969 | break; |
| 1970 | default: |
| 1971 | break; |
| 1972 | } |
Jiyoung Shin | c15a6b0 | 2012-06-05 01:08:14 -0700 | [diff] [blame] | 1973 | return 0; |
| 1974 | } |
| 1975 | |
| 1976 | int ExynosCameraHWInterface2::setNotifyCallback(camera2_notify_callback notify_cb, void *user) |
| 1977 | { |
Sungjoong Kang | 0f26b20 | 2012-08-17 15:43:12 -0700 | [diff] [blame] | 1978 | ALOGV("DEBUG(%s): cb_addr(%x)", __FUNCTION__, (unsigned int)notify_cb); |
Jiyoung Shin | c15a6b0 | 2012-06-05 01:08:14 -0700 | [diff] [blame] | 1979 | m_notifyCb = notify_cb; |
| 1980 | m_callbackCookie = user; |
| 1981 | return 0; |
| 1982 | } |
| 1983 | |
| 1984 | int ExynosCameraHWInterface2::getMetadataVendorTagOps(vendor_tag_query_ops_t **ops) |
| 1985 | { |
Sungjoong Kang | 13d8c7b | 2012-07-14 10:20:39 +0900 | [diff] [blame] | 1986 | ALOGV("DEBUG(%s):", __FUNCTION__); |
Jiyoung Shin | c15a6b0 | 2012-06-05 01:08:14 -0700 | [diff] [blame] | 1987 | return 0; |
| 1988 | } |
| 1989 | |
| 1990 | int ExynosCameraHWInterface2::dump(int fd) |
| 1991 | { |
Sungjoong Kang | 13d8c7b | 2012-07-14 10:20:39 +0900 | [diff] [blame] | 1992 | ALOGV("DEBUG(%s):", __FUNCTION__); |
Jiyoung Shin | c15a6b0 | 2012-06-05 01:08:14 -0700 | [diff] [blame] | 1993 | return 0; |
| 1994 | } |
| 1995 | |
Sungjoong Kang | 13d8c7b | 2012-07-14 10:20:39 +0900 | [diff] [blame] | 1996 | void ExynosCameraHWInterface2::m_getAlignedYUVSize(int colorFormat, int w, int h, ExynosBuffer *buf) |
| 1997 | { |
| 1998 | switch (colorFormat) { |
| 1999 | // 1p |
| 2000 | case V4L2_PIX_FMT_RGB565 : |
| 2001 | case V4L2_PIX_FMT_YUYV : |
| 2002 | case V4L2_PIX_FMT_UYVY : |
| 2003 | case V4L2_PIX_FMT_VYUY : |
| 2004 | case V4L2_PIX_FMT_YVYU : |
| 2005 | buf->size.extS[0] = FRAME_SIZE(V4L2_PIX_2_HAL_PIXEL_FORMAT(colorFormat), w, h); |
| 2006 | buf->size.extS[1] = 0; |
| 2007 | buf->size.extS[2] = 0; |
| 2008 | break; |
| 2009 | // 2p |
| 2010 | case V4L2_PIX_FMT_NV12 : |
| 2011 | case V4L2_PIX_FMT_NV12T : |
| 2012 | case V4L2_PIX_FMT_NV21 : |
| 2013 | buf->size.extS[0] = ALIGN(w, 16) * ALIGN(h, 16); |
| 2014 | buf->size.extS[1] = ALIGN(w/2, 16) * ALIGN(h/2, 16); |
| 2015 | buf->size.extS[2] = 0; |
| 2016 | break; |
| 2017 | case V4L2_PIX_FMT_NV12M : |
| 2018 | case V4L2_PIX_FMT_NV12MT_16X16 : |
Sungjoong Kang | 9dd63e1 | 2012-07-24 00:25:51 +0900 | [diff] [blame] | 2019 | case V4L2_PIX_FMT_NV21M: |
Sungjoong Kang | 13d8c7b | 2012-07-14 10:20:39 +0900 | [diff] [blame] | 2020 | buf->size.extS[0] = ALIGN(w, 16) * ALIGN(h, 16); |
| 2021 | buf->size.extS[1] = ALIGN(buf->size.extS[0] / 2, 256); |
| 2022 | buf->size.extS[2] = 0; |
| 2023 | break; |
| 2024 | case V4L2_PIX_FMT_NV16 : |
| 2025 | case V4L2_PIX_FMT_NV61 : |
| 2026 | buf->size.extS[0] = ALIGN(w, 16) * ALIGN(h, 16); |
| 2027 | buf->size.extS[1] = ALIGN(w, 16) * ALIGN(h, 16); |
| 2028 | buf->size.extS[2] = 0; |
| 2029 | break; |
| 2030 | // 3p |
| 2031 | case V4L2_PIX_FMT_YUV420 : |
| 2032 | case V4L2_PIX_FMT_YVU420 : |
| 2033 | buf->size.extS[0] = (w * h); |
| 2034 | buf->size.extS[1] = (w * h) >> 2; |
| 2035 | buf->size.extS[2] = (w * h) >> 2; |
| 2036 | break; |
| 2037 | case V4L2_PIX_FMT_YUV420M: |
| 2038 | case V4L2_PIX_FMT_YVU420M : |
| 2039 | case V4L2_PIX_FMT_YUV422P : |
| 2040 | buf->size.extS[0] = ALIGN(w, 32) * ALIGN(h, 16); |
| 2041 | buf->size.extS[1] = ALIGN(w/2, 16) * ALIGN(h/2, 8); |
| 2042 | buf->size.extS[2] = ALIGN(w/2, 16) * ALIGN(h/2, 8); |
| 2043 | break; |
| 2044 | default: |
| 2045 | ALOGE("ERR(%s):unmatched colorFormat(%d)", __FUNCTION__, colorFormat); |
| 2046 | return; |
| 2047 | break; |
| 2048 | } |
| 2049 | } |
| 2050 | |
| 2051 | bool ExynosCameraHWInterface2::m_getRatioSize(int src_w, int src_h, |
| 2052 | int dst_w, int dst_h, |
| 2053 | int *crop_x, int *crop_y, |
| 2054 | int *crop_w, int *crop_h, |
| 2055 | int zoom) |
| 2056 | { |
| 2057 | *crop_w = src_w; |
| 2058 | *crop_h = src_h; |
| 2059 | |
| 2060 | if ( src_w != dst_w |
| 2061 | || src_h != dst_h) { |
| 2062 | float src_ratio = 1.0f; |
| 2063 | float dst_ratio = 1.0f; |
| 2064 | |
| 2065 | // ex : 1024 / 768 |
| 2066 | src_ratio = (float)src_w / (float)src_h; |
| 2067 | |
| 2068 | // ex : 352 / 288 |
| 2069 | dst_ratio = (float)dst_w / (float)dst_h; |
| 2070 | |
| 2071 | if (dst_w * dst_h < src_w * src_h) { |
| 2072 | if (dst_ratio <= src_ratio) { |
| 2073 | // shrink w |
| 2074 | *crop_w = src_h * dst_ratio; |
| 2075 | *crop_h = src_h; |
| 2076 | } else { |
| 2077 | // shrink h |
| 2078 | *crop_w = src_w; |
| 2079 | *crop_h = src_w / dst_ratio; |
| 2080 | } |
| 2081 | } else { |
| 2082 | if (dst_ratio <= src_ratio) { |
| 2083 | // shrink w |
| 2084 | *crop_w = src_h * dst_ratio; |
| 2085 | *crop_h = src_h; |
| 2086 | } else { |
| 2087 | // shrink h |
| 2088 | *crop_w = src_w; |
| 2089 | *crop_h = src_w / dst_ratio; |
| 2090 | } |
| 2091 | } |
| 2092 | } |
| 2093 | |
| 2094 | if (zoom != 0) { |
| 2095 | float zoomLevel = ((float)zoom + 10.0) / 10.0; |
| 2096 | *crop_w = (int)((float)*crop_w / zoomLevel); |
| 2097 | *crop_h = (int)((float)*crop_h / zoomLevel); |
| 2098 | } |
| 2099 | |
| 2100 | #define CAMERA_CROP_WIDTH_RESTRAIN_NUM (0x2) |
| 2101 | unsigned int w_align = (*crop_w & (CAMERA_CROP_WIDTH_RESTRAIN_NUM - 1)); |
| 2102 | if (w_align != 0) { |
| 2103 | if ( (CAMERA_CROP_WIDTH_RESTRAIN_NUM >> 1) <= w_align |
| 2104 | && *crop_w + (CAMERA_CROP_WIDTH_RESTRAIN_NUM - w_align) <= dst_w) { |
| 2105 | *crop_w += (CAMERA_CROP_WIDTH_RESTRAIN_NUM - w_align); |
| 2106 | } |
| 2107 | else |
| 2108 | *crop_w -= w_align; |
| 2109 | } |
| 2110 | |
| 2111 | #define CAMERA_CROP_HEIGHT_RESTRAIN_NUM (0x2) |
| 2112 | unsigned int h_align = (*crop_h & (CAMERA_CROP_HEIGHT_RESTRAIN_NUM - 1)); |
| 2113 | if (h_align != 0) { |
| 2114 | if ( (CAMERA_CROP_HEIGHT_RESTRAIN_NUM >> 1) <= h_align |
| 2115 | && *crop_h + (CAMERA_CROP_HEIGHT_RESTRAIN_NUM - h_align) <= dst_h) { |
| 2116 | *crop_h += (CAMERA_CROP_HEIGHT_RESTRAIN_NUM - h_align); |
| 2117 | } |
| 2118 | else |
| 2119 | *crop_h -= h_align; |
| 2120 | } |
| 2121 | |
| 2122 | *crop_x = (src_w - *crop_w) >> 1; |
| 2123 | *crop_y = (src_h - *crop_h) >> 1; |
| 2124 | |
| 2125 | if (*crop_x & (CAMERA_CROP_WIDTH_RESTRAIN_NUM >> 1)) |
| 2126 | *crop_x -= 1; |
| 2127 | |
| 2128 | if (*crop_y & (CAMERA_CROP_HEIGHT_RESTRAIN_NUM >> 1)) |
| 2129 | *crop_y -= 1; |
| 2130 | |
| 2131 | return true; |
| 2132 | } |
| 2133 | |
Sungjoong Kang | 9dd63e1 | 2012-07-24 00:25:51 +0900 | [diff] [blame] | 2134 | BayerBufManager::BayerBufManager() |
Sungjoong Kang | 13d8c7b | 2012-07-14 10:20:39 +0900 | [diff] [blame] | 2135 | { |
Sungjoong Kang | 9dd63e1 | 2012-07-24 00:25:51 +0900 | [diff] [blame] | 2136 | ALOGV("DEBUG(%s): ", __FUNCTION__); |
| 2137 | for (int i = 0; i < NUM_BAYER_BUFFERS ; i++) { |
| 2138 | entries[i].status = BAYER_ON_HAL_EMPTY; |
| 2139 | entries[i].reqFrameCnt = 0; |
Sungjoong Kang | 13d8c7b | 2012-07-14 10:20:39 +0900 | [diff] [blame] | 2140 | } |
Sungjoong Kang | 9dd63e1 | 2012-07-24 00:25:51 +0900 | [diff] [blame] | 2141 | sensorEnqueueHead = 0; |
| 2142 | sensorDequeueHead = 0; |
| 2143 | ispEnqueueHead = 0; |
| 2144 | ispDequeueHead = 0; |
| 2145 | numOnSensor = 0; |
| 2146 | numOnIsp = 0; |
| 2147 | numOnHalFilled = 0; |
| 2148 | numOnHalEmpty = NUM_BAYER_BUFFERS; |
Sungjoong Kang | 13d8c7b | 2012-07-14 10:20:39 +0900 | [diff] [blame] | 2149 | } |
| 2150 | |
Sungjoong Kang | 15fd823 | 2012-08-23 16:16:44 -0700 | [diff] [blame] | 2151 | BayerBufManager::~BayerBufManager() |
| 2152 | { |
| 2153 | ALOGV("%s", __FUNCTION__); |
| 2154 | } |
| 2155 | |
Sungjoong Kang | 9dd63e1 | 2012-07-24 00:25:51 +0900 | [diff] [blame] | 2156 | int BayerBufManager::GetIndexForSensorEnqueue() |
Sungjoong Kang | 13d8c7b | 2012-07-14 10:20:39 +0900 | [diff] [blame] | 2157 | { |
Sungjoong Kang | 9dd63e1 | 2012-07-24 00:25:51 +0900 | [diff] [blame] | 2158 | int ret = 0; |
| 2159 | if (numOnHalEmpty == 0) |
| 2160 | ret = -1; |
| 2161 | else |
| 2162 | ret = sensorEnqueueHead; |
| 2163 | ALOGV("DEBUG(%s): returning (%d)", __FUNCTION__, ret); |
Sungjoong Kang | 13d8c7b | 2012-07-14 10:20:39 +0900 | [diff] [blame] | 2164 | return ret; |
| 2165 | } |
| 2166 | |
Sungjoong Kang | 9dd63e1 | 2012-07-24 00:25:51 +0900 | [diff] [blame] | 2167 | int BayerBufManager::MarkSensorEnqueue(int index) |
Sungjoong Kang | 13d8c7b | 2012-07-14 10:20:39 +0900 | [diff] [blame] | 2168 | { |
Sungjoong Kang | 9dd63e1 | 2012-07-24 00:25:51 +0900 | [diff] [blame] | 2169 | ALOGV("DEBUG(%s) : BayerIndex[%d] ", __FUNCTION__, index); |
| 2170 | |
| 2171 | // sanity check |
| 2172 | if (index != sensorEnqueueHead) { |
| 2173 | ALOGV("DEBUG(%s) : Abnormal BayerIndex[%d] - expected[%d]", __FUNCTION__, index, sensorEnqueueHead); |
| 2174 | return -1; |
| 2175 | } |
| 2176 | if (entries[index].status != BAYER_ON_HAL_EMPTY) { |
| 2177 | ALOGV("DEBUG(%s) : Abnormal status in BayerIndex[%d] = (%d) expected (%d)", __FUNCTION__, |
| 2178 | index, entries[index].status, BAYER_ON_HAL_EMPTY); |
Sungjoong Kang | 13d8c7b | 2012-07-14 10:20:39 +0900 | [diff] [blame] | 2179 | return -1; |
| 2180 | } |
| 2181 | |
Sungjoong Kang | 9dd63e1 | 2012-07-24 00:25:51 +0900 | [diff] [blame] | 2182 | entries[index].status = BAYER_ON_SENSOR; |
| 2183 | entries[index].reqFrameCnt = 0; |
| 2184 | numOnHalEmpty--; |
| 2185 | numOnSensor++; |
| 2186 | sensorEnqueueHead = GetNextIndex(index); |
| 2187 | ALOGV("DEBUG(%s) END: HAL-e(%d) HAL-f(%d) Sensor(%d) ISP(%d) ", |
| 2188 | __FUNCTION__, numOnHalEmpty, numOnHalFilled, numOnSensor, numOnIsp); |
| 2189 | return 0; |
| 2190 | } |
Sungjoong Kang | 13d8c7b | 2012-07-14 10:20:39 +0900 | [diff] [blame] | 2191 | |
Sungjoong Kang | 9dd63e1 | 2012-07-24 00:25:51 +0900 | [diff] [blame] | 2192 | int BayerBufManager::MarkSensorDequeue(int index, int reqFrameCnt, nsecs_t *timeStamp) |
| 2193 | { |
| 2194 | ALOGV("DEBUG(%s) : BayerIndex[%d] reqFrameCnt(%d)", __FUNCTION__, index, reqFrameCnt); |
| 2195 | |
Sungjoong Kang | 9dd63e1 | 2012-07-24 00:25:51 +0900 | [diff] [blame] | 2196 | if (entries[index].status != BAYER_ON_SENSOR) { |
Sungjoong Kang | ad37861 | 2012-08-17 12:34:33 -0700 | [diff] [blame] | 2197 | ALOGE("DEBUG(%s) : Abnormal status in BayerIndex[%d] = (%d) expected (%d)", __FUNCTION__, |
Sungjoong Kang | 9dd63e1 | 2012-07-24 00:25:51 +0900 | [diff] [blame] | 2198 | index, entries[index].status, BAYER_ON_SENSOR); |
Sungjoong Kang | 13d8c7b | 2012-07-14 10:20:39 +0900 | [diff] [blame] | 2199 | return -1; |
| 2200 | } |
| 2201 | |
Sungjoong Kang | 9dd63e1 | 2012-07-24 00:25:51 +0900 | [diff] [blame] | 2202 | entries[index].status = BAYER_ON_HAL_FILLED; |
Sungjoong Kang | 9dd63e1 | 2012-07-24 00:25:51 +0900 | [diff] [blame] | 2203 | numOnHalFilled++; |
| 2204 | numOnSensor--; |
Sungjoong Kang | ad37861 | 2012-08-17 12:34:33 -0700 | [diff] [blame] | 2205 | |
Sungjoong Kang | 9dd63e1 | 2012-07-24 00:25:51 +0900 | [diff] [blame] | 2206 | return 0; |
| 2207 | } |
Sungjoong Kang | 13d8c7b | 2012-07-14 10:20:39 +0900 | [diff] [blame] | 2208 | |
Sungjoong Kang | 9dd63e1 | 2012-07-24 00:25:51 +0900 | [diff] [blame] | 2209 | int BayerBufManager::GetIndexForIspEnqueue(int *reqFrameCnt) |
| 2210 | { |
| 2211 | int ret = 0; |
| 2212 | if (numOnHalFilled == 0) |
| 2213 | ret = -1; |
| 2214 | else { |
| 2215 | *reqFrameCnt = entries[ispEnqueueHead].reqFrameCnt; |
| 2216 | ret = ispEnqueueHead; |
| 2217 | } |
| 2218 | ALOGV("DEBUG(%s): returning BayerIndex[%d]", __FUNCTION__, ret); |
| 2219 | return ret; |
| 2220 | } |
| 2221 | |
| 2222 | int BayerBufManager::GetIndexForIspDequeue(int *reqFrameCnt) |
| 2223 | { |
| 2224 | int ret = 0; |
| 2225 | if (numOnIsp == 0) |
| 2226 | ret = -1; |
| 2227 | else { |
| 2228 | *reqFrameCnt = entries[ispDequeueHead].reqFrameCnt; |
| 2229 | ret = ispDequeueHead; |
| 2230 | } |
| 2231 | ALOGV("DEBUG(%s): returning BayerIndex[%d]", __FUNCTION__, ret); |
| 2232 | return ret; |
| 2233 | } |
| 2234 | |
| 2235 | int BayerBufManager::MarkIspEnqueue(int index) |
| 2236 | { |
| 2237 | ALOGV("DEBUG(%s) : BayerIndex[%d] ", __FUNCTION__, index); |
| 2238 | |
| 2239 | // sanity check |
| 2240 | if (index != ispEnqueueHead) { |
| 2241 | ALOGV("DEBUG(%s) : Abnormal BayerIndex[%d] - expected[%d]", __FUNCTION__, index, ispEnqueueHead); |
| 2242 | return -1; |
| 2243 | } |
| 2244 | if (entries[index].status != BAYER_ON_HAL_FILLED) { |
| 2245 | ALOGV("DEBUG(%s) : Abnormal status in BayerIndex[%d] = (%d) expected (%d)", __FUNCTION__, |
| 2246 | index, entries[index].status, BAYER_ON_HAL_FILLED); |
| 2247 | return -1; |
| 2248 | } |
| 2249 | |
| 2250 | entries[index].status = BAYER_ON_ISP; |
| 2251 | numOnHalFilled--; |
| 2252 | numOnIsp++; |
| 2253 | ispEnqueueHead = GetNextIndex(index); |
| 2254 | ALOGV("DEBUG(%s) END: HAL-e(%d) HAL-f(%d) Sensor(%d) ISP(%d) ", |
| 2255 | __FUNCTION__, numOnHalEmpty, numOnHalFilled, numOnSensor, numOnIsp); |
| 2256 | return 0; |
| 2257 | } |
| 2258 | |
| 2259 | int BayerBufManager::MarkIspDequeue(int index) |
| 2260 | { |
| 2261 | ALOGV("DEBUG(%s) : BayerIndex[%d]", __FUNCTION__, index); |
| 2262 | |
| 2263 | // sanity check |
| 2264 | if (index != ispDequeueHead) { |
| 2265 | ALOGV("DEBUG(%s) : Abnormal BayerIndex[%d] - expected[%d]", __FUNCTION__, index, ispDequeueHead); |
| 2266 | return -1; |
| 2267 | } |
| 2268 | if (entries[index].status != BAYER_ON_ISP) { |
| 2269 | ALOGV("DEBUG(%s) : Abnormal status in BayerIndex[%d] = (%d) expected (%d)", __FUNCTION__, |
| 2270 | index, entries[index].status, BAYER_ON_ISP); |
| 2271 | return -1; |
| 2272 | } |
| 2273 | |
| 2274 | entries[index].status = BAYER_ON_HAL_EMPTY; |
| 2275 | entries[index].reqFrameCnt = 0; |
| 2276 | numOnHalEmpty++; |
| 2277 | numOnIsp--; |
| 2278 | ispDequeueHead = GetNextIndex(index); |
| 2279 | ALOGV("DEBUG(%s) END: HAL-e(%d) HAL-f(%d) Sensor(%d) ISP(%d) ", |
| 2280 | __FUNCTION__, numOnHalEmpty, numOnHalFilled, numOnSensor, numOnIsp); |
| 2281 | return 0; |
| 2282 | } |
| 2283 | |
| 2284 | int BayerBufManager::GetNumOnSensor() |
| 2285 | { |
| 2286 | return numOnSensor; |
| 2287 | } |
| 2288 | |
| 2289 | int BayerBufManager::GetNumOnHalFilled() |
| 2290 | { |
| 2291 | return numOnHalFilled; |
| 2292 | } |
| 2293 | |
| 2294 | int BayerBufManager::GetNumOnIsp() |
| 2295 | { |
| 2296 | return numOnIsp; |
| 2297 | } |
| 2298 | |
| 2299 | int BayerBufManager::GetNextIndex(int index) |
| 2300 | { |
| 2301 | index++; |
| 2302 | if (index >= NUM_BAYER_BUFFERS) |
| 2303 | index = 0; |
| 2304 | |
| 2305 | return index; |
Sungjoong Kang | 13d8c7b | 2012-07-14 10:20:39 +0900 | [diff] [blame] | 2306 | } |
Jiyoung Shin | c15a6b0 | 2012-06-05 01:08:14 -0700 | [diff] [blame] | 2307 | |
| 2308 | void ExynosCameraHWInterface2::m_mainThreadFunc(SignalDrivenThread * self) |
| 2309 | { |
| 2310 | camera_metadata_t *currentRequest = NULL; |
| 2311 | camera_metadata_t *currentFrame = NULL; |
| 2312 | size_t numEntries = 0; |
Sungjoong Kang | 13d8c7b | 2012-07-14 10:20:39 +0900 | [diff] [blame] | 2313 | size_t frameSize = 0; |
Jiyoung Shin | c15a6b0 | 2012-06-05 01:08:14 -0700 | [diff] [blame] | 2314 | camera_metadata_t * preparedFrame = NULL; |
| 2315 | camera_metadata_t *deregisteredRequest = NULL; |
| 2316 | uint32_t currentSignal = self->GetProcessingSignal(); |
Sungjoong Kang | 13d8c7b | 2012-07-14 10:20:39 +0900 | [diff] [blame] | 2317 | MainThread * selfThread = ((MainThread*)self); |
Jiyoung Shin | c15a6b0 | 2012-06-05 01:08:14 -0700 | [diff] [blame] | 2318 | int res = 0; |
Sungjoong Kang | 13d8c7b | 2012-07-14 10:20:39 +0900 | [diff] [blame] | 2319 | |
Sungjoong Kang | ad37861 | 2012-08-17 12:34:33 -0700 | [diff] [blame] | 2320 | int ret; |
| 2321 | |
Sungjoong Kang | 13d8c7b | 2012-07-14 10:20:39 +0900 | [diff] [blame] | 2322 | ALOGV("DEBUG(%s): m_mainThreadFunc (%x)", __FUNCTION__, currentSignal); |
| 2323 | |
| 2324 | if (currentSignal & SIGNAL_THREAD_RELEASE) { |
| 2325 | ALOGV("DEBUG(%s): processing SIGNAL_THREAD_RELEASE", __FUNCTION__); |
| 2326 | |
| 2327 | ALOGV("DEBUG(%s): processing SIGNAL_THREAD_RELEASE DONE", __FUNCTION__); |
| 2328 | selfThread->SetSignal(SIGNAL_THREAD_TERMINATE); |
| 2329 | return; |
| 2330 | } |
| 2331 | |
Jiyoung Shin | c15a6b0 | 2012-06-05 01:08:14 -0700 | [diff] [blame] | 2332 | if (currentSignal & SIGNAL_MAIN_REQ_Q_NOT_EMPTY) { |
Sungjoong Kang | 13d8c7b | 2012-07-14 10:20:39 +0900 | [diff] [blame] | 2333 | ALOGV("DEBUG(%s): MainThread processing SIGNAL_MAIN_REQ_Q_NOT_EMPTY", __FUNCTION__); |
Sungjoong Kang | ad37861 | 2012-08-17 12:34:33 -0700 | [diff] [blame] | 2334 | if (m_requestManager->IsRequestQueueFull()==false) { |
Jiyoung Shin | c15a6b0 | 2012-06-05 01:08:14 -0700 | [diff] [blame] | 2335 | m_requestQueueOps->dequeue_request(m_requestQueueOps, ¤tRequest); |
| 2336 | if (NULL == currentRequest) { |
Sungjoong Kang | ad37861 | 2012-08-17 12:34:33 -0700 | [diff] [blame] | 2337 | ALOGE("DEBUG(%s)(0x%x): dequeue_request returned NULL ", __FUNCTION__, currentSignal); |
Sungjoong Kang | 13d8c7b | 2012-07-14 10:20:39 +0900 | [diff] [blame] | 2338 | m_isRequestQueueNull = true; |
Jiyoung Shin | c15a6b0 | 2012-06-05 01:08:14 -0700 | [diff] [blame] | 2339 | } |
| 2340 | else { |
| 2341 | m_requestManager->RegisterRequest(currentRequest); |
Sungjoong Kang | 13d8c7b | 2012-07-14 10:20:39 +0900 | [diff] [blame] | 2342 | |
Jiyoung Shin | c15a6b0 | 2012-06-05 01:08:14 -0700 | [diff] [blame] | 2343 | m_numOfRemainingReqInSvc = m_requestQueueOps->request_count(m_requestQueueOps); |
Sungjoong Kang | 13d8c7b | 2012-07-14 10:20:39 +0900 | [diff] [blame] | 2344 | ALOGV("DEBUG(%s): remaining req cnt (%d)", __FUNCTION__, m_numOfRemainingReqInSvc); |
Sungjoong Kang | ad37861 | 2012-08-17 12:34:33 -0700 | [diff] [blame] | 2345 | if (m_requestManager->IsRequestQueueFull()==false) |
Sungjoong Kang | 13d8c7b | 2012-07-14 10:20:39 +0900 | [diff] [blame] | 2346 | selfThread->SetSignal(SIGNAL_MAIN_REQ_Q_NOT_EMPTY); // dequeue repeatedly |
Sungjoong Kang | 9dd63e1 | 2012-07-24 00:25:51 +0900 | [diff] [blame] | 2347 | |
Jiyoung Shin | c15a6b0 | 2012-06-05 01:08:14 -0700 | [diff] [blame] | 2348 | m_sensorThread->SetSignal(SIGNAL_SENSOR_START_REQ_PROCESSING); |
| 2349 | } |
| 2350 | } |
| 2351 | else { |
| 2352 | m_isRequestQueuePending = true; |
| 2353 | } |
| 2354 | } |
| 2355 | |
| 2356 | if (currentSignal & SIGNAL_MAIN_STREAM_OUTPUT_DONE) { |
Sungjoong Kang | 13d8c7b | 2012-07-14 10:20:39 +0900 | [diff] [blame] | 2357 | ALOGV("DEBUG(%s): MainThread processing SIGNAL_MAIN_STREAM_OUTPUT_DONE", __FUNCTION__); |
| 2358 | /*while (1)*/ { |
Sungjoong Kang | 0f26b20 | 2012-08-17 15:43:12 -0700 | [diff] [blame] | 2359 | ret = m_requestManager->PrepareFrame(&numEntries, &frameSize, &preparedFrame, GetAfStateForService()); |
Sungjoong Kang | ad37861 | 2012-08-17 12:34:33 -0700 | [diff] [blame] | 2360 | if (ret == false) |
| 2361 | ALOGD("++++++ PrepareFrame ret = %d", ret); |
| 2362 | |
Sungjoong Kang | 13d8c7b | 2012-07-14 10:20:39 +0900 | [diff] [blame] | 2363 | m_requestManager->DeregisterRequest(&deregisteredRequest); |
Sungjoong Kang | ad37861 | 2012-08-17 12:34:33 -0700 | [diff] [blame] | 2364 | |
| 2365 | ret = m_requestQueueOps->free_request(m_requestQueueOps, deregisteredRequest); |
| 2366 | if (ret < 0) |
| 2367 | ALOGD("++++++ free_request ret = %d", ret); |
| 2368 | |
| 2369 | ret = m_frameQueueOps->dequeue_frame(m_frameQueueOps, numEntries, frameSize, ¤tFrame); |
| 2370 | if (ret < 0) |
| 2371 | ALOGD("++++++ dequeue_frame ret = %d", ret); |
| 2372 | |
Sungjoong Kang | 13d8c7b | 2012-07-14 10:20:39 +0900 | [diff] [blame] | 2373 | if (currentFrame==NULL) { |
Sungjoong Kang | ad37861 | 2012-08-17 12:34:33 -0700 | [diff] [blame] | 2374 | ALOGV("DBG(%s): frame dequeue returned NULL",__FUNCTION__ ); |
Sungjoong Kang | 13d8c7b | 2012-07-14 10:20:39 +0900 | [diff] [blame] | 2375 | } |
| 2376 | else { |
Sungjoong Kang | daa1fcd | 2012-08-08 11:49:43 -0700 | [diff] [blame] | 2377 | ALOGV("DEBUG(%s): frame dequeue done. numEntries(%d) frameSize(%d)",__FUNCTION__ , numEntries, frameSize); |
Sungjoong Kang | 13d8c7b | 2012-07-14 10:20:39 +0900 | [diff] [blame] | 2378 | } |
| 2379 | res = append_camera_metadata(currentFrame, preparedFrame); |
| 2380 | if (res==0) { |
| 2381 | ALOGV("DEBUG(%s): frame metadata append success",__FUNCTION__); |
| 2382 | m_frameQueueOps->enqueue_frame(m_frameQueueOps, currentFrame); |
| 2383 | } |
| 2384 | else { |
| 2385 | ALOGE("ERR(%s): frame metadata append fail (%d)",__FUNCTION__, res); |
| 2386 | } |
Jiyoung Shin | c15a6b0 | 2012-06-05 01:08:14 -0700 | [diff] [blame] | 2387 | } |
Sungjoong Kang | 13d8c7b | 2012-07-14 10:20:39 +0900 | [diff] [blame] | 2388 | if (!m_isRequestQueueNull) { |
| 2389 | selfThread->SetSignal(SIGNAL_MAIN_REQ_Q_NOT_EMPTY); |
Jiyoung Shin | c15a6b0 | 2012-06-05 01:08:14 -0700 | [diff] [blame] | 2390 | } |
Sungjoong Kang | 9dd63e1 | 2012-07-24 00:25:51 +0900 | [diff] [blame] | 2391 | |
Sungjoong Kang | 13d8c7b | 2012-07-14 10:20:39 +0900 | [diff] [blame] | 2392 | if (getInProgressCount()>0) { |
| 2393 | ALOGV("DEBUG(%s): STREAM_OUTPUT_DONE and signalling REQ_PROCESSING",__FUNCTION__); |
| 2394 | m_sensorThread->SetSignal(SIGNAL_SENSOR_START_REQ_PROCESSING); |
Jiyoung Shin | c15a6b0 | 2012-06-05 01:08:14 -0700 | [diff] [blame] | 2395 | } |
Jiyoung Shin | c15a6b0 | 2012-06-05 01:08:14 -0700 | [diff] [blame] | 2396 | } |
Sungjoong Kang | 13d8c7b | 2012-07-14 10:20:39 +0900 | [diff] [blame] | 2397 | ALOGV("DEBUG(%s): MainThread Exit", __FUNCTION__); |
Jiyoung Shin | c15a6b0 | 2012-06-05 01:08:14 -0700 | [diff] [blame] | 2398 | return; |
| 2399 | } |
Sungjoong Kang | 13d8c7b | 2012-07-14 10:20:39 +0900 | [diff] [blame] | 2400 | |
Jiyoung Shin | c15a6b0 | 2012-06-05 01:08:14 -0700 | [diff] [blame] | 2401 | void ExynosCameraHWInterface2::m_sensorThreadInitialize(SignalDrivenThread * self) |
| 2402 | { |
Sungjoong Kang | 13d8c7b | 2012-07-14 10:20:39 +0900 | [diff] [blame] | 2403 | ALOGV("DEBUG(%s): ", __FUNCTION__ ); |
Sungjoong Kang | ad37861 | 2012-08-17 12:34:33 -0700 | [diff] [blame] | 2404 | /* will add */ |
Sungjoong Kang | 13d8c7b | 2012-07-14 10:20:39 +0900 | [diff] [blame] | 2405 | return; |
| 2406 | } |
| 2407 | |
| 2408 | |
Sungjoong Kang | 13d8c7b | 2012-07-14 10:20:39 +0900 | [diff] [blame] | 2409 | void ExynosCameraHWInterface2::DumpInfoWithShot(struct camera2_shot_ext * shot_ext) |
| 2410 | { |
Sungjoong Kang | ad37861 | 2012-08-17 12:34:33 -0700 | [diff] [blame] | 2411 | ALOGD("#### common Section"); |
| 2412 | ALOGD("#### magic(%x) ", |
Sungjoong Kang | 13d8c7b | 2012-07-14 10:20:39 +0900 | [diff] [blame] | 2413 | shot_ext->shot.magicNumber); |
Sungjoong Kang | ad37861 | 2012-08-17 12:34:33 -0700 | [diff] [blame] | 2414 | ALOGD("#### ctl Section"); |
| 2415 | ALOGD("#### meta(%d) aper(%f) exp(%lld) duration(%lld) ISO(%d) AWB(%d)", |
Sungjoong Kang | 13d8c7b | 2012-07-14 10:20:39 +0900 | [diff] [blame] | 2416 | shot_ext->shot.ctl.request.metadataMode, |
Sungjoong Kang | b56dcc0 | 2012-08-08 13:38:09 -0700 | [diff] [blame] | 2417 | shot_ext->shot.ctl.lens.aperture, |
Sungjoong Kang | 13d8c7b | 2012-07-14 10:20:39 +0900 | [diff] [blame] | 2418 | shot_ext->shot.ctl.sensor.exposureTime, |
| 2419 | shot_ext->shot.ctl.sensor.frameDuration, |
Sungjoong Kang | b56dcc0 | 2012-08-08 13:38:09 -0700 | [diff] [blame] | 2420 | shot_ext->shot.ctl.sensor.sensitivity, |
| 2421 | shot_ext->shot.ctl.aa.awbMode); |
Sungjoong Kang | 13d8c7b | 2012-07-14 10:20:39 +0900 | [diff] [blame] | 2422 | |
Sungjoong Kang | 74d78eb | 2012-08-29 13:25:46 -0700 | [diff] [blame] | 2423 | ALOGD("#### OutputStream Sensor(%d) SCP(%d) SCC(%d) pv(%d) rec(%d) previewCb(%d)", |
Sungjoong Kang | 9dd63e1 | 2012-07-24 00:25:51 +0900 | [diff] [blame] | 2424 | shot_ext->request_sensor, shot_ext->request_scp, shot_ext->request_scc, |
Sungjoong Kang | 74d78eb | 2012-08-29 13:25:46 -0700 | [diff] [blame] | 2425 | shot_ext->shot.ctl.request.outputStreams[0], shot_ext->shot.ctl.request.outputStreams[2], |
| 2426 | shot_ext->shot.ctl.request.outputStreams[3]); |
Sungjoong Kang | 13d8c7b | 2012-07-14 10:20:39 +0900 | [diff] [blame] | 2427 | |
Sungjoong Kang | ad37861 | 2012-08-17 12:34:33 -0700 | [diff] [blame] | 2428 | ALOGD("#### DM Section"); |
| 2429 | ALOGD("#### meta(%d) aper(%f) exp(%lld) duration(%lld) ISO(%d) timestamp(%lld) AWB(%d) cnt(%d)", |
Sungjoong Kang | 13d8c7b | 2012-07-14 10:20:39 +0900 | [diff] [blame] | 2430 | shot_ext->shot.dm.request.metadataMode, |
Sungjoong Kang | b56dcc0 | 2012-08-08 13:38:09 -0700 | [diff] [blame] | 2431 | shot_ext->shot.dm.lens.aperture, |
Sungjoong Kang | 13d8c7b | 2012-07-14 10:20:39 +0900 | [diff] [blame] | 2432 | shot_ext->shot.dm.sensor.exposureTime, |
| 2433 | shot_ext->shot.dm.sensor.frameDuration, |
| 2434 | shot_ext->shot.dm.sensor.sensitivity, |
Sungjoong Kang | b56dcc0 | 2012-08-08 13:38:09 -0700 | [diff] [blame] | 2435 | shot_ext->shot.dm.sensor.timeStamp, |
| 2436 | shot_ext->shot.dm.aa.awbMode, |
| 2437 | shot_ext->shot.dm.request.frameCount ); |
Sungjoong Kang | 13d8c7b | 2012-07-14 10:20:39 +0900 | [diff] [blame] | 2438 | } |
| 2439 | |
Younghwan Joo | 6f19b6c | 2012-08-30 13:56:53 -0700 | [diff] [blame] | 2440 | void ExynosCameraHWInterface2::flashSetter(struct camera2_shot_ext * shot_ext) |
| 2441 | { |
| 2442 | // 1. AF Flash |
| 2443 | if (m_afFlashEnableFlg) { |
| 2444 | switch (m_afFlashCnt) { |
| 2445 | case IS_FLASH_AF_ON: |
| 2446 | ALOGE("(%s): [AF Flash] IS_FLASH_ON", __FUNCTION__); |
| 2447 | shot_ext->shot.ctl.aa.aeflashMode = AA_FLASHMODE_ON; |
| 2448 | m_afFlashCnt = IS_FLASH_AF_ON_START; |
| 2449 | break; |
| 2450 | case IF_FLASH_AF_OFF: |
| 2451 | ALOGE("(%s): [AF Flash] IS_FLASH_OFF and status clear", __FUNCTION__); |
| 2452 | shot_ext->shot.ctl.aa.aeflashMode = AA_FLASHMODE_OFF; |
| 2453 | m_afFlashEnableFlg = false; |
| 2454 | m_afFlashCnt = 0; |
| 2455 | break; |
| 2456 | } |
| 2457 | } |
| 2458 | |
| 2459 | // 2. Flash |
| 2460 | if (m_flashEnableFlg) { |
| 2461 | switch (m_flashCnt) { |
| 2462 | case IS_FLASH_ON: |
| 2463 | ALOGE("(%s): [Flash] Flash ON for Capture", __FUNCTION__); |
| 2464 | shot_ext->shot.ctl.aa.aeflashMode = AA_FLASHMODE_ON; |
| 2465 | shot_ext->shot.ctl.aa.awbMode = AA_AWBMODE_WB_AUTO; |
| 2466 | break; |
| 2467 | case IS_FLASH_ON_DONE: |
| 2468 | shot_ext->shot.ctl.aa.awbMode = AA_AWBMODE_LOCKED; |
| 2469 | shot_ext->shot.ctl.aa.aeflashMode = AA_FLASHMODE_AUTO; |
| 2470 | m_flashCnt = IS_FLASH_AUTO_AE_AWB_LOCK; // auto transition |
| 2471 | shot_ext->request_scc = 0; |
| 2472 | break; |
| 2473 | case IS_FLASH_AUTO_AE_AWB_LOCK: |
| 2474 | shot_ext->request_scc = 0; |
| 2475 | break; |
| 2476 | case IS_FLASH_AUTO_END: |
| 2477 | shot_ext->request_scc = 0; |
| 2478 | break; |
| 2479 | case IS_FLASH_AUTO_AE_AWB_LOCKED_AUTO_END: |
| 2480 | m_flashCnt = IS_FLASH_CAPTURE; |
| 2481 | shot_ext->shot.ctl.aa.aeflashMode = AA_FLASHMODE_CAPTURE; |
| 2482 | shot_ext->request_scc = 1; |
| 2483 | break; |
| 2484 | case IS_FLASH_CAPTURE: |
| 2485 | shot_ext->request_scc = 0; |
| 2486 | break; |
| 2487 | case IS_FLASH_CAPTURE_JPEG: |
| 2488 | shot_ext->request_scc = 0; |
| 2489 | m_flashCaptured = true; |
| 2490 | m_flashEnableFlg = false; |
| 2491 | m_flashCnt = 0; |
| 2492 | break; |
| 2493 | } |
| 2494 | } |
| 2495 | } |
| 2496 | |
| 2497 | void ExynosCameraHWInterface2::flashListener(struct camera2_shot_ext * shot_ext) |
| 2498 | { |
| 2499 | if (m_flashCaptured) { |
| 2500 | shot_ext->shot.ctl.aa.aeflashMode = AA_FLASHMODE_OFF; |
| 2501 | shot_ext->shot.ctl.aa.awbMode = AA_AWBMODE_WB_AUTO; |
| 2502 | ALOGE("(%s): [Flash] Flash off after Capture", __FUNCTION__); |
| 2503 | m_flashCaptured = false; |
| 2504 | } |
| 2505 | |
| 2506 | // 1. AF Flash |
| 2507 | if (m_afFlashEnableFlg) { |
| 2508 | ALOGV("(%s), [AF Flash] aa.aeflashMode : (ctl,dm) - (%d , %d)", __FUNCTION__, shot_ext->shot.ctl.aa.aeflashMode, shot_ext->shot.dm.aa.aeflashMode); |
| 2509 | ALOGV("(%s), [AF Flash] flash.flashMode : (ctl,dm) - (%d , %d)", __FUNCTION__, shot_ext->shot.ctl.flash.flashMode, shot_ext->shot.dm.flash.flashMode); |
| 2510 | |
| 2511 | switch (m_afFlashCnt) { |
| 2512 | case IS_FLASH_AF_ON_START: |
| 2513 | if (shot_ext->shot.dm.flash.flashMode == CAM2_FLASH_MODE_TORCH) { |
| 2514 | m_afFlashCnt = IS_FLASH_AF_ON_DONE; |
| 2515 | ALOGV("(%s): [AF Flash] Lis : dm.aa.aeflashMode == AA_FLASHMODE_ON", __FUNCTION__); |
| 2516 | m_IsAfTriggerRequired = true; |
| 2517 | } else { |
| 2518 | if (m_flashTimeOut == 0) |
| 2519 | m_afFlashCnt = IS_FLASH_AF_ON_DONE; |
| 2520 | else |
| 2521 | m_flashTimeOut--; |
| 2522 | } |
| 2523 | break; |
| 2524 | case IF_FLASH_AF_OFF: |
| 2525 | ALOGD("(%s): [AF Flash] Lis : IS_FLASH_OFF : status clear", __FUNCTION__); |
| 2526 | break; |
| 2527 | } |
| 2528 | } |
| 2529 | |
| 2530 | // 2. Flash |
| 2531 | if (m_flashEnableFlg) { |
| 2532 | switch (m_flashCnt) { |
| 2533 | case IS_FLASH_ON: |
| 2534 | if (shot_ext->shot.dm.flash.flashMode == CAM2_FLASH_MODE_TORCH) { |
| 2535 | m_flashCnt = IS_FLASH_ON_DONE; |
| 2536 | } else { |
| 2537 | ALOGV("(%s): [Flash] Waiting : dm.flash.flashMode == ANDROID_FLASH_TORCH", __FUNCTION__); |
| 2538 | m_flashTimeOut--; |
| 2539 | if (m_flashTimeOut == 0) |
| 2540 | m_flashCnt = IS_FLASH_CAPTURE_JPEG; |
| 2541 | } |
| 2542 | break; |
| 2543 | case IS_FLASH_AUTO_AE_AWB_LOCK: |
| 2544 | if (shot_ext->shot.dm.flash.flashMode == CAM2_FLASH_MODE_TORCH) { |
| 2545 | m_flashCnt = IS_FLASH_AUTO_END; |
| 2546 | } else { |
| 2547 | ALOGV("(%s): [Flash] Waiting : dm.flash.flashMode== AA_FLASHMODE_AUTO", __FUNCTION__); |
| 2548 | } |
| 2549 | break; |
| 2550 | case IS_FLASH_AUTO_END: |
| 2551 | if (shot_ext->shot.dm.flash.flashMode == CAM2_FLASH_MODE_OFF) { |
| 2552 | m_flashCnt = IS_FLASH_AUTO_AE_AWB_LOCKED_AUTO_END; |
| 2553 | } else { |
| 2554 | ALOGV("(%s): [Flash] Waiting : dm.aa.awbMode == AA_AWBMODE_LOCKED and dm.flash.flashMode== CAM2_FLASH_MODE_OFF", __FUNCTION__); |
| 2555 | } |
| 2556 | break; |
| 2557 | case IS_FLASH_CAPTURE: |
| 2558 | if (shot_ext->shot.dm.flash.flashMode == CAM2_FLASH_MODE_SINGLE) { |
| 2559 | m_flashCnt = IS_FLASH_CAPTURE_JPEG; |
| 2560 | } else { |
| 2561 | ALOGV("(%s): [Flash] Waiting : ctl.aa.aeflashMode == AA_FLASHMODE_CAPTURE", __FUNCTION__); |
| 2562 | } |
| 2563 | break; |
| 2564 | } |
| 2565 | } |
| 2566 | |
| 2567 | } |
| 2568 | |
Sungjoong Kang | 13d8c7b | 2012-07-14 10:20:39 +0900 | [diff] [blame] | 2569 | void ExynosCameraHWInterface2::m_sensorThreadFunc(SignalDrivenThread * self) |
| 2570 | { |
| 2571 | uint32_t currentSignal = self->GetProcessingSignal(); |
| 2572 | SensorThread * selfThread = ((SensorThread*)self); |
| 2573 | int index; |
Sungjoong Kang | ad37861 | 2012-08-17 12:34:33 -0700 | [diff] [blame] | 2574 | int index_isp; |
Sungjoong Kang | 13d8c7b | 2012-07-14 10:20:39 +0900 | [diff] [blame] | 2575 | status_t res; |
| 2576 | nsecs_t frameTime; |
| 2577 | int bayersOnSensor = 0, bayersOnIsp = 0; |
Sungjoong Kang | ad37861 | 2012-08-17 12:34:33 -0700 | [diff] [blame] | 2578 | int j = 0; |
| 2579 | bool isCapture = false; |
Sungjoong Kang | 13d8c7b | 2012-07-14 10:20:39 +0900 | [diff] [blame] | 2580 | ALOGV("DEBUG(%s): m_sensorThreadFunc (%x)", __FUNCTION__, currentSignal); |
| 2581 | |
| 2582 | if (currentSignal & SIGNAL_THREAD_RELEASE) { |
Sungjoong Kang | ad37861 | 2012-08-17 12:34:33 -0700 | [diff] [blame] | 2583 | ALOGV("(%s): ENTER processing SIGNAL_THREAD_RELEASE", __FUNCTION__); |
Sungjoong Kang | 13d8c7b | 2012-07-14 10:20:39 +0900 | [diff] [blame] | 2584 | |
Sungjoong Kang | 9dd63e1 | 2012-07-24 00:25:51 +0900 | [diff] [blame] | 2585 | ALOGV("(%s): calling sensor streamoff", __FUNCTION__); |
Sungjoong Kang | 13d8c7b | 2012-07-14 10:20:39 +0900 | [diff] [blame] | 2586 | cam_int_streamoff(&(m_camera_info.sensor)); |
Sungjoong Kang | 9dd63e1 | 2012-07-24 00:25:51 +0900 | [diff] [blame] | 2587 | ALOGV("(%s): calling sensor streamoff done", __FUNCTION__); |
Sungjoong Kang | b5237e6 | 2012-07-27 07:39:05 -0700 | [diff] [blame] | 2588 | |
| 2589 | m_camera_info.sensor.buffers = 0; |
| 2590 | ALOGV("DEBUG(%s): sensor calling reqbuf 0 ", __FUNCTION__); |
| 2591 | cam_int_reqbufs(&(m_camera_info.sensor)); |
| 2592 | ALOGV("DEBUG(%s): sensor calling reqbuf 0 done", __FUNCTION__); |
Sungjoong Kang | ad37861 | 2012-08-17 12:34:33 -0700 | [diff] [blame] | 2593 | |
Sungjoong Kang | 9dd63e1 | 2012-07-24 00:25:51 +0900 | [diff] [blame] | 2594 | ALOGV("(%s): calling ISP streamoff", __FUNCTION__); |
| 2595 | isp_int_streamoff(&(m_camera_info.isp)); |
| 2596 | ALOGV("(%s): calling ISP streamoff done", __FUNCTION__); |
Sungjoong Kang | ad37861 | 2012-08-17 12:34:33 -0700 | [diff] [blame] | 2597 | |
Sungjoong Kang | b5237e6 | 2012-07-27 07:39:05 -0700 | [diff] [blame] | 2598 | m_camera_info.isp.buffers = 0; |
| 2599 | ALOGV("DEBUG(%s): isp calling reqbuf 0 ", __FUNCTION__); |
| 2600 | cam_int_reqbufs(&(m_camera_info.isp)); |
| 2601 | ALOGV("DEBUG(%s): isp calling reqbuf 0 done", __FUNCTION__); |
| 2602 | |
Sungjoong Kang | 13d8c7b | 2012-07-14 10:20:39 +0900 | [diff] [blame] | 2603 | exynos_v4l2_s_ctrl(m_camera_info.sensor.fd, V4L2_CID_IS_S_STREAM, IS_DISABLE_STREAM); |
Sungjoong Kang | 13d8c7b | 2012-07-14 10:20:39 +0900 | [diff] [blame] | 2604 | |
Sungjoong Kang | ad37861 | 2012-08-17 12:34:33 -0700 | [diff] [blame] | 2605 | ALOGV("(%s): EXIT processing SIGNAL_THREAD_RELEASE", __FUNCTION__); |
Sungjoong Kang | 13d8c7b | 2012-07-14 10:20:39 +0900 | [diff] [blame] | 2606 | selfThread->SetSignal(SIGNAL_THREAD_TERMINATE); |
| 2607 | return; |
| 2608 | } |
| 2609 | |
| 2610 | if (currentSignal & SIGNAL_SENSOR_START_REQ_PROCESSING) |
| 2611 | { |
| 2612 | ALOGV("DEBUG(%s): SensorThread processing SIGNAL_SENSOR_START_REQ_PROCESSING", __FUNCTION__); |
Sungjoong Kang | 9dd63e1 | 2012-07-24 00:25:51 +0900 | [diff] [blame] | 2613 | int targetStreamIndex = 0, i=0; |
Sungjoong Kang | ad37861 | 2012-08-17 12:34:33 -0700 | [diff] [blame] | 2614 | int matchedFrameCnt = -1, processingReqIndex; |
Sungjoong Kang | 13d8c7b | 2012-07-14 10:20:39 +0900 | [diff] [blame] | 2615 | struct camera2_shot_ext *shot_ext; |
Sungjoong Kang | ad37861 | 2012-08-17 12:34:33 -0700 | [diff] [blame] | 2616 | struct camera2_shot_ext *shot_ext_capture; |
Sungjoong Kang | 0f26b20 | 2012-08-17 15:43:12 -0700 | [diff] [blame] | 2617 | bool triggered = false; |
| 2618 | int afMode; |
Sungjoong Kang | 9dd63e1 | 2012-07-24 00:25:51 +0900 | [diff] [blame] | 2619 | |
Sungjoong Kang | ad37861 | 2012-08-17 12:34:33 -0700 | [diff] [blame] | 2620 | /* dqbuf from sensor */ |
| 2621 | ALOGV("Sensor DQbuf start"); |
Sungjoong Kang | 13d8c7b | 2012-07-14 10:20:39 +0900 | [diff] [blame] | 2622 | index = cam_int_dqbuf(&(m_camera_info.sensor)); |
Sungjoong Kang | 9dd63e1 | 2012-07-24 00:25:51 +0900 | [diff] [blame] | 2623 | shot_ext = (struct camera2_shot_ext *)(m_camera_info.sensor.buffer[index].virt.extP[1]); |
Sungjoong Kang | ad37861 | 2012-08-17 12:34:33 -0700 | [diff] [blame] | 2624 | |
| 2625 | m_recordOutput = shot_ext->shot.ctl.request.outputStreams[2]; |
Sungjoong Kang | 74d78eb | 2012-08-29 13:25:46 -0700 | [diff] [blame] | 2626 | m_previewCbOutput = shot_ext->shot.ctl.request.outputStreams[3]; |
Sungjoong Kang | ad37861 | 2012-08-17 12:34:33 -0700 | [diff] [blame] | 2627 | |
Sungjoong Kang | a15b4e3 | 2012-08-28 12:55:39 -0700 | [diff] [blame] | 2628 | if (m_nightCaptureCnt != 0) { |
| 2629 | matchedFrameCnt = m_nightCaptureFrameCnt; |
Younghwan Joo | 6f19b6c | 2012-08-30 13:56:53 -0700 | [diff] [blame] | 2630 | } else if (m_flashCnt != 0) { |
| 2631 | matchedFrameCnt = m_flashFrameCount; |
| 2632 | ALOGD("Skip frame, request is fixed at %d", matchedFrameCnt); |
| 2633 | } else { |
Sungjoong Kang | a15b4e3 | 2012-08-28 12:55:39 -0700 | [diff] [blame] | 2634 | matchedFrameCnt = m_requestManager->FindFrameCnt(shot_ext); |
| 2635 | } |
Sungjoong Kang | ad37861 | 2012-08-17 12:34:33 -0700 | [diff] [blame] | 2636 | |
Sungjoong Kang | a07cbd9 | 2012-07-27 12:03:29 -0700 | [diff] [blame] | 2637 | if (matchedFrameCnt != -1) { |
Sungjoong Kang | ef6f83c | 2012-08-28 22:59:48 +0900 | [diff] [blame] | 2638 | frameTime = systemTime(); |
| 2639 | m_requestManager->RegisterTimestamp(matchedFrameCnt, &frameTime); |
| 2640 | m_requestManager->UpdateIspParameters(shot_ext, matchedFrameCnt); |
Sungjoong Kang | 8e2c2fd | 2012-08-27 00:02:22 -0700 | [diff] [blame] | 2641 | if (m_afModeWaitingCnt != 0) { |
| 2642 | ALOGV("### Af Trigger pulled, waiting for mode change cnt(%d) ", m_afModeWaitingCnt); |
| 2643 | m_afModeWaitingCnt --; |
| 2644 | if (m_afModeWaitingCnt == 1) { |
Sungjoong Kang | cd13bb7 | 2012-08-28 13:05:01 -0700 | [diff] [blame] | 2645 | m_afModeWaitingCnt = 0; |
Sungjoong Kang | 8e2c2fd | 2012-08-27 00:02:22 -0700 | [diff] [blame] | 2646 | OnAfTrigger(m_afPendingTriggerId); |
| 2647 | } |
| 2648 | } |
hyeonmyeong Choi | 308291d | 2012-08-29 13:55:01 -0700 | [diff] [blame^] | 2649 | m_zoomRatio = (float)m_camera2->getSensorW() / (float)shot_ext->shot.ctl.scaler.cropRegion[2]; |
Sungjoong Kang | e4657e3 | 2012-08-28 15:02:19 -0700 | [diff] [blame] | 2650 | float zoomLeft, zoomTop, zoomWidth, zoomHeight; |
| 2651 | int crop_x = 0, crop_y = 0, crop_w = 0, crop_h = 0; |
| 2652 | |
| 2653 | m_getRatioSize(m_camera2->getSensorW(), m_camera2->getSensorH(), |
| 2654 | m_streamThreads[0]->m_parameters.outputWidth, m_streamThreads[0]->m_parameters.outputHeight, |
| 2655 | &crop_x, &crop_y, |
| 2656 | &crop_w, &crop_h, |
| 2657 | 0); |
| 2658 | |
| 2659 | if (m_streamThreads[0]->m_parameters.outputWidth >= m_streamThreads[0]->m_parameters.outputHeight) { |
hyeonmyeong Choi | 308291d | 2012-08-29 13:55:01 -0700 | [diff] [blame^] | 2660 | zoomWidth = m_camera2->getSensorW() / m_zoomRatio; |
Sungjoong Kang | e4657e3 | 2012-08-28 15:02:19 -0700 | [diff] [blame] | 2661 | zoomHeight = zoomWidth * |
| 2662 | m_streamThreads[0]->m_parameters.outputHeight / m_streamThreads[0]->m_parameters.outputWidth; |
| 2663 | } else { |
hyeonmyeong Choi | 308291d | 2012-08-29 13:55:01 -0700 | [diff] [blame^] | 2664 | zoomHeight = m_camera2->getSensorH() / m_zoomRatio; |
Sungjoong Kang | e4657e3 | 2012-08-28 15:02:19 -0700 | [diff] [blame] | 2665 | zoomWidth = zoomHeight * |
| 2666 | m_streamThreads[0]->m_parameters.outputWidth / m_streamThreads[0]->m_parameters.outputHeight; |
| 2667 | } |
| 2668 | zoomLeft = (crop_w - zoomWidth) / 2; |
| 2669 | zoomTop = (crop_h - zoomHeight) / 2; |
| 2670 | |
| 2671 | int32_t new_cropRegion[3] = { zoomLeft, zoomTop, zoomWidth }; |
| 2672 | |
hyeonmyeong Choi | 308291d | 2012-08-29 13:55:01 -0700 | [diff] [blame^] | 2673 | if (new_cropRegion[0] * 2 + new_cropRegion[2] > m_camera2->getSensorW()) |
| 2674 | new_cropRegion[2]--; |
| 2675 | else if (new_cropRegion[0] * 2 + new_cropRegion[2] < m_camera2->getSensorW()) |
| 2676 | new_cropRegion[2]++; |
| 2677 | |
Sungjoong Kang | e4657e3 | 2012-08-28 15:02:19 -0700 | [diff] [blame] | 2678 | shot_ext->shot.ctl.scaler.cropRegion[0] = new_cropRegion[0]; |
| 2679 | shot_ext->shot.ctl.scaler.cropRegion[1] = new_cropRegion[1]; |
| 2680 | shot_ext->shot.ctl.scaler.cropRegion[2] = new_cropRegion[2]; |
Sungjoong Kang | 0f26b20 | 2012-08-17 15:43:12 -0700 | [diff] [blame] | 2681 | if (m_IsAfModeUpdateRequired) { |
| 2682 | ALOGE("### AF Mode change(Mode %d) ", m_afMode); |
| 2683 | shot_ext->shot.ctl.aa.afMode = m_afMode; |
| 2684 | if (m_afMode == AA_AFMODE_CONTINUOUS_VIDEO || m_afMode == AA_AFMODE_CONTINUOUS_PICTURE) { |
| 2685 | ALOGE("### With Automatic triger for continuous modes"); |
| 2686 | m_afState = HAL_AFSTATE_STARTED; |
| 2687 | shot_ext->shot.ctl.aa.afTrigger = 1; |
| 2688 | triggered = true; |
| 2689 | } |
| 2690 | m_IsAfModeUpdateRequired = false; |
| 2691 | if (m_afMode2 != NO_CHANGE) { |
| 2692 | enum aa_afmode tempAfMode = m_afMode2; |
| 2693 | m_afMode2 = NO_CHANGE; |
| 2694 | SetAfMode(tempAfMode); |
| 2695 | } |
| 2696 | } |
| 2697 | else { |
| 2698 | shot_ext->shot.ctl.aa.afMode = NO_CHANGE; |
| 2699 | } |
| 2700 | if (m_IsAfTriggerRequired) { |
| 2701 | ALOGE("### AF Triggering with mode (%d)", m_afMode); |
Younghwan Joo | 6f19b6c | 2012-08-30 13:56:53 -0700 | [diff] [blame] | 2702 | // Flash triggering with AF |
| 2703 | if ((shot_ext->shot.ctl.aa.aeMode >= AA_AEMODE_ON_AUTO_FLASH) && (m_afFlashEnableFlg == false) |
| 2704 | && (m_cameraId == 0)) { |
| 2705 | m_afFlashEnableFlg = true; |
| 2706 | m_flashTimeOut = 3; |
| 2707 | m_afFlashCnt = IS_FLASH_AF_ON; |
Sungjoong Kang | 36c106c | 2012-08-23 17:38:20 -0700 | [diff] [blame] | 2708 | } |
Younghwan Joo | 6f19b6c | 2012-08-30 13:56:53 -0700 | [diff] [blame] | 2709 | if (m_afFlashEnableFlg) { |
| 2710 | if (m_afFlashCnt == IS_FLASH_AF_ON_DONE) { |
| 2711 | // Flash is enabled and start AF |
| 2712 | if (m_afState == HAL_AFSTATE_SCANNING) { |
| 2713 | ALOGE("(%s): restarting trigger ", __FUNCTION__); |
| 2714 | } else { |
| 2715 | if (m_afState != HAL_AFSTATE_NEEDS_COMMAND) |
| 2716 | ALOGE("(%s): wrong trigger state %d", __FUNCTION__, m_afState); |
| 2717 | else |
| 2718 | m_afState = HAL_AFSTATE_STARTED; |
| 2719 | } |
| 2720 | shot_ext->shot.ctl.aa.afTrigger = 1; |
| 2721 | shot_ext->shot.ctl.aa.afMode = m_afMode; |
| 2722 | m_IsAfTriggerRequired = false; |
| 2723 | } |
| 2724 | } else { |
| 2725 | if (m_afState == HAL_AFSTATE_SCANNING) { |
| 2726 | ALOGE("(%s): restarting trigger ", __FUNCTION__); |
| 2727 | } else { |
| 2728 | if (m_afState != HAL_AFSTATE_NEEDS_COMMAND) |
| 2729 | ALOGE("(%s): wrong trigger state %d", __FUNCTION__, m_afState); |
| 2730 | else |
| 2731 | m_afState = HAL_AFSTATE_STARTED; |
| 2732 | } |
| 2733 | shot_ext->shot.ctl.aa.afTrigger = 1; |
| 2734 | shot_ext->shot.ctl.aa.afMode = m_afMode; |
| 2735 | m_IsAfTriggerRequired = false; |
Sungjoong Kang | 36c106c | 2012-08-23 17:38:20 -0700 | [diff] [blame] | 2736 | } |
Sungjoong Kang | 0f26b20 | 2012-08-17 15:43:12 -0700 | [diff] [blame] | 2737 | } |
| 2738 | else { |
Sungjoong Kang | 8e2c2fd | 2012-08-27 00:02:22 -0700 | [diff] [blame] | 2739 | shot_ext->shot.ctl.aa.afTrigger = 0; |
Sungjoong Kang | 0f26b20 | 2012-08-17 15:43:12 -0700 | [diff] [blame] | 2740 | } |
Sungjoong Kang | b55ed66 | 2012-08-31 21:31:34 -0700 | [diff] [blame] | 2741 | if (m_aspectChanged) { |
| 2742 | shot_ext->shot.ctl.aa.aeTargetFpsRange[0] = 15; |
Sungjoong Kang | 15fd823 | 2012-08-23 16:16:44 -0700 | [diff] [blame] | 2743 | shot_ext->shot.ctl.aa.aeTargetFpsRange[1] = 30; |
Sungjoong Kang | b55ed66 | 2012-08-31 21:31:34 -0700 | [diff] [blame] | 2744 | m_aspectChanged = false; |
Sungjoong Kang | 15fd823 | 2012-08-23 16:16:44 -0700 | [diff] [blame] | 2745 | } |
| 2746 | else { |
Sungjoong Kang | b55ed66 | 2012-08-31 21:31:34 -0700 | [diff] [blame] | 2747 | if (m_wideAspect) { |
| 2748 | shot_ext->setfile = ISS_SUB_SCENARIO_VIDEO; |
| 2749 | shot_ext->shot.ctl.aa.aeTargetFpsRange[0] = 30; |
| 2750 | shot_ext->shot.ctl.aa.aeTargetFpsRange[1] = 30; |
| 2751 | } |
| 2752 | else { |
| 2753 | shot_ext->setfile = ISS_SUB_SCENARIO_STILL; |
| 2754 | } |
Sungjoong Kang | 15fd823 | 2012-08-23 16:16:44 -0700 | [diff] [blame] | 2755 | } |
Sungjoong Kang | 0f26b20 | 2012-08-17 15:43:12 -0700 | [diff] [blame] | 2756 | if (triggered) |
| 2757 | shot_ext->shot.ctl.aa.afTrigger = 1; |
| 2758 | |
| 2759 | // TODO : check collision with AFMode Update |
| 2760 | if (m_IsAfLockRequired) { |
| 2761 | shot_ext->shot.ctl.aa.afMode = AA_AFMODE_OFF; |
| 2762 | m_IsAfLockRequired = false; |
| 2763 | } |
Rebecca Schultz Zavin | 4ed2f10 | 2012-08-22 00:55:29 -0700 | [diff] [blame] | 2764 | ALOGV("### Isp Qbuf start(%d) count (%d), SCP(%d) SCC(%d) DIS(%d) shot_size(%d)", |
Sungjoong Kang | ad37861 | 2012-08-17 12:34:33 -0700 | [diff] [blame] | 2765 | index, |
| 2766 | shot_ext->shot.ctl.request.frameCount, |
| 2767 | shot_ext->request_scp, |
| 2768 | shot_ext->request_scc, |
| 2769 | shot_ext->dis_bypass, sizeof(camera2_shot)); |
Sungjoong Kang | a15b4e3 | 2012-08-28 12:55:39 -0700 | [diff] [blame] | 2770 | ALOGV("### m_nightCaptureCnt (%d)", m_nightCaptureCnt); |
Sungjoong Kang | 8e2c2fd | 2012-08-27 00:02:22 -0700 | [diff] [blame] | 2771 | if (0 == shot_ext->shot.ctl.aa.afRegions[0] && 0 == shot_ext->shot.ctl.aa.afRegions[1] |
| 2772 | && 0 == shot_ext->shot.ctl.aa.afRegions[2] && 0 == shot_ext->shot.ctl.aa.afRegions[3]) { |
| 2773 | ALOGV("(%s): AF region resetting", __FUNCTION__); |
| 2774 | lastAfRegion[0] = 0; |
| 2775 | lastAfRegion[1] = 0; |
| 2776 | lastAfRegion[2] = 0; |
| 2777 | lastAfRegion[3] = 0; |
| 2778 | } |
| 2779 | else { |
| 2780 | if (!(lastAfRegion[0] == shot_ext->shot.ctl.aa.afRegions[0] && lastAfRegion[1] == shot_ext->shot.ctl.aa.afRegions[1] |
| 2781 | && lastAfRegion[2] == shot_ext->shot.ctl.aa.afRegions[2] && lastAfRegion[3] == shot_ext->shot.ctl.aa.afRegions[3])) { |
| 2782 | ALOGV("(%s): AF region changed : triggering", __FUNCTION__); |
| 2783 | shot_ext->shot.ctl.aa.afTrigger = 1; |
| 2784 | shot_ext->shot.ctl.aa.afMode = m_afMode; |
| 2785 | m_afState = HAL_AFSTATE_STARTED; |
| 2786 | lastAfRegion[0] = shot_ext->shot.ctl.aa.afRegions[0]; |
| 2787 | lastAfRegion[1] = shot_ext->shot.ctl.aa.afRegions[1]; |
| 2788 | lastAfRegion[2] = shot_ext->shot.ctl.aa.afRegions[2]; |
| 2789 | lastAfRegion[3] = shot_ext->shot.ctl.aa.afRegions[3]; |
| 2790 | } |
| 2791 | } |
Sungjoong Kang | a15b4e3 | 2012-08-28 12:55:39 -0700 | [diff] [blame] | 2792 | if (m_nightCaptureCnt == 0) { |
| 2793 | if (shot_ext->shot.ctl.aa.captureIntent == ANDROID_CONTROL_INTENT_STILL_CAPTURE |
| 2794 | && shot_ext->shot.ctl.aa.sceneMode == AA_SCENE_MODE_NIGHT) { |
| 2795 | shot_ext->shot.ctl.aa.sceneMode = AA_SCENE_MODE_NIGHT_CAPTURE; |
| 2796 | shot_ext->shot.ctl.aa.aeTargetFpsRange[0] = 2; |
| 2797 | shot_ext->shot.ctl.aa.aeTargetFpsRange[1] = 30; |
| 2798 | m_nightCaptureCnt = 4; |
| 2799 | m_nightCaptureFrameCnt = matchedFrameCnt; |
| 2800 | shot_ext->request_scc = 0; |
| 2801 | } |
| 2802 | } |
| 2803 | else if (m_nightCaptureCnt == 1) { |
| 2804 | shot_ext->shot.ctl.aa.sceneMode = AA_SCENE_MODE_NIGHT_CAPTURE; |
| 2805 | shot_ext->shot.ctl.aa.aeTargetFpsRange[0] = 2; |
| 2806 | shot_ext->shot.ctl.aa.aeTargetFpsRange[1] = 30; |
| 2807 | m_nightCaptureCnt--; |
| 2808 | shot_ext->request_scc = 1; |
| 2809 | } |
| 2810 | else if (m_nightCaptureCnt == 2 || m_nightCaptureCnt == 3 || m_nightCaptureCnt == 4) { |
| 2811 | shot_ext->shot.ctl.aa.sceneMode = AA_SCENE_MODE_NIGHT_CAPTURE; |
| 2812 | shot_ext->shot.ctl.aa.aeTargetFpsRange[0] = 2; |
| 2813 | shot_ext->shot.ctl.aa.aeTargetFpsRange[1] = 30; |
| 2814 | m_nightCaptureCnt--; |
| 2815 | shot_ext->request_scc = 0; |
| 2816 | } |
Younghwan Joo | 6f19b6c | 2012-08-30 13:56:53 -0700 | [diff] [blame] | 2817 | |
| 2818 | // Flash mode |
| 2819 | // Keep and Skip request_scc = 1 at flash enable mode to operate flash sequence |
| 2820 | if ((shot_ext->shot.ctl.aa.aeMode >= AA_AEMODE_ON_AUTO_FLASH) && (m_flashEnableFlg == false) |
| 2821 | && (m_cameraId == 0)) { |
| 2822 | if (shot_ext->shot.ctl.aa.captureIntent == ANDROID_CONTROL_INTENT_STILL_CAPTURE) { |
| 2823 | ALOGE("(%s): [Flash] Flash capture start : skip request scc 1#####", __FUNCTION__); |
| 2824 | shot_ext->request_scc = 0; |
| 2825 | m_flashFrameCount = matchedFrameCnt; |
| 2826 | m_flashEnableFlg = true; |
| 2827 | m_flashCaptured = false; |
| 2828 | m_flashCnt = IS_FLASH_ON; |
| 2829 | m_flashTimeOut = 3; |
| 2830 | } |
| 2831 | } |
| 2832 | |
| 2833 | flashListener(shot_ext); |
| 2834 | flashSetter(shot_ext); |
Sungjoong Kang | 8e2c2fd | 2012-08-27 00:02:22 -0700 | [diff] [blame] | 2835 | ALOGV("(%s): queued aa(%d) aemode(%d) awb(%d) afmode(%d) trigger(%d)", __FUNCTION__, |
| 2836 | (int)(shot_ext->shot.ctl.aa.mode), (int)(shot_ext->shot.ctl.aa.aeMode), |
| 2837 | (int)(shot_ext->shot.ctl.aa.awbMode), (int)(shot_ext->shot.ctl.aa.afMode), |
| 2838 | (int)(shot_ext->shot.ctl.aa.afTrigger)); |
Sungjoong Kang | ad37861 | 2012-08-17 12:34:33 -0700 | [diff] [blame] | 2839 | cam_int_qbuf(&(m_camera_info.isp), index); |
Sungjoong Kang | ad37861 | 2012-08-17 12:34:33 -0700 | [diff] [blame] | 2840 | |
| 2841 | usleep(10000); |
Sungjoong Kang | ad37861 | 2012-08-17 12:34:33 -0700 | [diff] [blame] | 2842 | |
| 2843 | ALOGV("### isp DQBUF start"); |
| 2844 | index_isp = cam_int_dqbuf(&(m_camera_info.isp)); |
Sungjoong Kang | ef6f83c | 2012-08-28 22:59:48 +0900 | [diff] [blame] | 2845 | |
Sungjoong Kang | ad37861 | 2012-08-17 12:34:33 -0700 | [diff] [blame] | 2846 | |
Sungjoong Kang | ad37861 | 2012-08-17 12:34:33 -0700 | [diff] [blame] | 2847 | shot_ext = (struct camera2_shot_ext *)(m_camera_info.isp.buffer[index_isp].virt.extP[1]); |
| 2848 | |
| 2849 | ALOGV("### Isp DQbuf done(%d) count (%d), SCP(%d) SCC(%d) shot_size(%d)", |
| 2850 | index, |
| 2851 | shot_ext->shot.ctl.request.frameCount, |
| 2852 | shot_ext->request_scp, |
| 2853 | shot_ext->request_scc, |
| 2854 | shot_ext->dis_bypass, sizeof(camera2_shot)); |
Sungjoong Kang | ef6f83c | 2012-08-28 22:59:48 +0900 | [diff] [blame] | 2855 | ALOGV("(%s): DM aa(%d) aemode(%d) awb(%d) afmode(%d)", __FUNCTION__, |
Sungjoong Kang | 8e2c2fd | 2012-08-27 00:02:22 -0700 | [diff] [blame] | 2856 | (int)(shot_ext->shot.dm.aa.mode), (int)(shot_ext->shot.dm.aa.aeMode), |
| 2857 | (int)(shot_ext->shot.dm.aa.awbMode), |
| 2858 | (int)(shot_ext->shot.dm.aa.afMode)); |
Sungjoong Kang | ad37861 | 2012-08-17 12:34:33 -0700 | [diff] [blame] | 2859 | |
Sungjoong Kang | ef6f83c | 2012-08-28 22:59:48 +0900 | [diff] [blame] | 2860 | m_previewOutput = 0; |
Sungjoong Kang | ad37861 | 2012-08-17 12:34:33 -0700 | [diff] [blame] | 2861 | if (shot_ext->request_scp) { |
| 2862 | m_previewOutput = 1; |
Sungjoong Kang | b55ed66 | 2012-08-31 21:31:34 -0700 | [diff] [blame] | 2863 | m_scpOutputSignalCnt++; |
Sungjoong Kang | ad37861 | 2012-08-17 12:34:33 -0700 | [diff] [blame] | 2864 | m_streamThreads[0]->SetSignal(SIGNAL_STREAM_DATA_COMING); |
| 2865 | } |
Sungjoong Kang | 15fd823 | 2012-08-23 16:16:44 -0700 | [diff] [blame] | 2866 | if (shot_ext->request_scc) { |
Sungjoong Kang | a15b4e3 | 2012-08-28 12:55:39 -0700 | [diff] [blame] | 2867 | ALOGV("### m_nightCaptureCnt (%d) request_scc true", m_nightCaptureCnt); |
| 2868 | memcpy(&m_jpegMetadata, &shot_ext->shot, sizeof(struct camera2_shot)); |
| 2869 | int shutterSpeed = (m_jpegMetadata.dm.sensor.exposureTime/1000); |
| 2870 | |
| 2871 | if (shutterSpeed < 0) { |
| 2872 | shutterSpeed = 100; |
| 2873 | } |
Sungjoong Kang | 15fd823 | 2012-08-23 16:16:44 -0700 | [diff] [blame] | 2874 | m_streamThreads[1]->SetSignal(SIGNAL_STREAM_DATA_COMING); |
| 2875 | } |
Sungjoong Kang | ad37861 | 2012-08-17 12:34:33 -0700 | [diff] [blame] | 2876 | |
| 2877 | ALOGV("(%s): SCP_CLOSING check sensor(%d) scc(%d) scp(%d) ", __FUNCTION__, |
| 2878 | shot_ext->request_sensor, shot_ext->request_scc, shot_ext->request_scp); |
| 2879 | if (shot_ext->request_scc + shot_ext->request_scp + shot_ext->request_sensor == 0) { |
| 2880 | ALOGV("(%s): SCP_CLOSING check OK ", __FUNCTION__); |
| 2881 | m_scp_closed = true; |
| 2882 | } |
| 2883 | else |
| 2884 | m_scp_closed = false; |
| 2885 | |
Sungjoong Kang | fd2d78a | 2012-08-26 17:44:25 -0700 | [diff] [blame] | 2886 | if (!shot_ext->fd_bypass) { |
| 2887 | /* FD orientation axis transformation */ |
| 2888 | for (int i=0; i < CAMERA2_MAX_FACES; i++) { |
| 2889 | if (shot_ext->shot.dm.stats.faceRectangles[i][0] > 0) |
| 2890 | shot_ext->shot.dm.stats.faceRectangles[i][0] = (m_camera2->m_curCameraInfo->sensorW |
Sungjoong Kang | ef6f83c | 2012-08-28 22:59:48 +0900 | [diff] [blame] | 2891 | * shot_ext->shot.dm.stats.faceRectangles[i][0]) |
| 2892 | / m_streamThreads[0].get()->m_parameters.outputWidth; |
Sungjoong Kang | fd2d78a | 2012-08-26 17:44:25 -0700 | [diff] [blame] | 2893 | if (shot_ext->shot.dm.stats.faceRectangles[i][1] > 0) |
| 2894 | shot_ext->shot.dm.stats.faceRectangles[i][1] = (m_camera2->m_curCameraInfo->sensorH |
Sungjoong Kang | ef6f83c | 2012-08-28 22:59:48 +0900 | [diff] [blame] | 2895 | * shot_ext->shot.dm.stats.faceRectangles[i][1]) |
| 2896 | / m_streamThreads[0].get()->m_parameters.outputHeight; |
Sungjoong Kang | fd2d78a | 2012-08-26 17:44:25 -0700 | [diff] [blame] | 2897 | if (shot_ext->shot.dm.stats.faceRectangles[i][2] > 0) |
| 2898 | shot_ext->shot.dm.stats.faceRectangles[i][2] = (m_camera2->m_curCameraInfo->sensorW |
Sungjoong Kang | ef6f83c | 2012-08-28 22:59:48 +0900 | [diff] [blame] | 2899 | * shot_ext->shot.dm.stats.faceRectangles[i][2]) |
| 2900 | / m_streamThreads[0].get()->m_parameters.outputWidth; |
Sungjoong Kang | fd2d78a | 2012-08-26 17:44:25 -0700 | [diff] [blame] | 2901 | if (shot_ext->shot.dm.stats.faceRectangles[i][3] > 0) |
| 2902 | shot_ext->shot.dm.stats.faceRectangles[i][3] = (m_camera2->m_curCameraInfo->sensorH |
Sungjoong Kang | ef6f83c | 2012-08-28 22:59:48 +0900 | [diff] [blame] | 2903 | * shot_ext->shot.dm.stats.faceRectangles[i][3]) |
| 2904 | / m_streamThreads[0].get()->m_parameters.outputHeight; |
Sungjoong Kang | fd2d78a | 2012-08-26 17:44:25 -0700 | [diff] [blame] | 2905 | } |
| 2906 | } |
Younghwan Joo | 6f19b6c | 2012-08-30 13:56:53 -0700 | [diff] [blame] | 2907 | if (m_nightCaptureCnt == 0 && m_flashCnt == 0) { |
Sungjoong Kang | a15b4e3 | 2012-08-28 12:55:39 -0700 | [diff] [blame] | 2908 | m_requestManager->ApplyDynamicMetadata(shot_ext); |
| 2909 | } |
Sungjoong Kang | 0f26b20 | 2012-08-17 15:43:12 -0700 | [diff] [blame] | 2910 | OnAfNotification(shot_ext->shot.dm.aa.afState); |
Sungjoong Kang | 13d8c7b | 2012-07-14 10:20:39 +0900 | [diff] [blame] | 2911 | } |
Sungjoong Kang | ad37861 | 2012-08-17 12:34:33 -0700 | [diff] [blame] | 2912 | |
Sungjoong Kang | 0f26b20 | 2012-08-17 15:43:12 -0700 | [diff] [blame] | 2913 | processingReqIndex = m_requestManager->MarkProcessingRequest(&(m_camera_info.sensor.buffer[index]), &afMode); |
Sungjoong Kang | ef6f83c | 2012-08-28 22:59:48 +0900 | [diff] [blame] | 2914 | if (processingReqIndex != -1) |
Sungjoong Kang | 0f26b20 | 2012-08-17 15:43:12 -0700 | [diff] [blame] | 2915 | SetAfMode((enum aa_afmode)afMode); |
Sungjoong Kang | ef6f83c | 2012-08-28 22:59:48 +0900 | [diff] [blame] | 2916 | |
Sungjoong Kang | ad37861 | 2012-08-17 12:34:33 -0700 | [diff] [blame] | 2917 | |
| 2918 | shot_ext = (struct camera2_shot_ext *)(m_camera_info.sensor.buffer[index].virt.extP[1]); |
| 2919 | if (m_scp_closing || m_scp_closed) { |
| 2920 | ALOGD("(%s): SCP_CLOSING(%d) SCP_CLOSED(%d)", __FUNCTION__, m_scp_closing, m_scp_closed); |
| 2921 | shot_ext->request_scc = 0; |
| 2922 | shot_ext->request_scp = 0; |
| 2923 | shot_ext->request_sensor = 0; |
| 2924 | } |
| 2925 | |
Sungjoong Kang | ad37861 | 2012-08-17 12:34:33 -0700 | [diff] [blame] | 2926 | cam_int_qbuf(&(m_camera_info.sensor), index); |
| 2927 | ALOGV("### Sensor QBUF done"); |
| 2928 | |
Sungjoong Kang | ef6f83c | 2012-08-28 22:59:48 +0900 | [diff] [blame] | 2929 | if (!m_scp_closing |
| 2930 | && ((matchedFrameCnt == -1) || (processingReqIndex == -1))){ |
| 2931 | ALOGD("make bubble shot: matchedFramcnt(%d) processingReqIndex(%d)", |
| 2932 | matchedFrameCnt, processingReqIndex); |
Sungjoong Kang | 13d8c7b | 2012-07-14 10:20:39 +0900 | [diff] [blame] | 2933 | selfThread->SetSignal(SIGNAL_SENSOR_START_REQ_PROCESSING); |
Sungjoong Kang | 13d8c7b | 2012-07-14 10:20:39 +0900 | [diff] [blame] | 2934 | } |
Sungjoong Kang | 9dd63e1 | 2012-07-24 00:25:51 +0900 | [diff] [blame] | 2935 | } |
Sungjoong Kang | 13d8c7b | 2012-07-14 10:20:39 +0900 | [diff] [blame] | 2936 | return; |
| 2937 | } |
| 2938 | |
Sungjoong Kang | 13d8c7b | 2012-07-14 10:20:39 +0900 | [diff] [blame] | 2939 | void ExynosCameraHWInterface2::m_ispThreadInitialize(SignalDrivenThread * self) |
| 2940 | { |
| 2941 | ALOGV("DEBUG(%s): ", __FUNCTION__ ); |
Sungjoong Kang | ad37861 | 2012-08-17 12:34:33 -0700 | [diff] [blame] | 2942 | /* will add */ |
Jiyoung Shin | c15a6b0 | 2012-06-05 01:08:14 -0700 | [diff] [blame] | 2943 | return; |
| 2944 | } |
| 2945 | |
Jiyoung Shin | c15a6b0 | 2012-06-05 01:08:14 -0700 | [diff] [blame] | 2946 | |
Sungjoong Kang | 13d8c7b | 2012-07-14 10:20:39 +0900 | [diff] [blame] | 2947 | void ExynosCameraHWInterface2::m_ispThreadFunc(SignalDrivenThread * self) |
| 2948 | { |
Sungjoong Kang | ad37861 | 2012-08-17 12:34:33 -0700 | [diff] [blame] | 2949 | ALOGV("DEBUG(%s): ", __FUNCTION__ ); |
| 2950 | /* will add */ |
Jiyoung Shin | c15a6b0 | 2012-06-05 01:08:14 -0700 | [diff] [blame] | 2951 | return; |
| 2952 | } |
| 2953 | |
Sungjoong Kang | 86646da | 2012-08-28 17:29:11 +0900 | [diff] [blame] | 2954 | void ExynosCameraHWInterface2::m_streamBufferInit(SignalDrivenThread *self) |
| 2955 | { |
| 2956 | uint32_t currentSignal = self->GetProcessingSignal(); |
| 2957 | StreamThread * selfThread = ((StreamThread*)self); |
| 2958 | stream_parameters_t *selfStreamParms = &(selfThread->m_parameters); |
| 2959 | record_parameters_t *selfRecordParms = &(selfThread->m_recordParameters); |
Sungjoong Kang | 74d78eb | 2012-08-29 13:25:46 -0700 | [diff] [blame] | 2960 | callback_parameters_t *selfPreviewCbParms = &(selfThread->m_previewCbParameters); |
Sungjoong Kang | 86646da | 2012-08-28 17:29:11 +0900 | [diff] [blame] | 2961 | node_info_t *currentNode = &(selfStreamParms->node); |
| 2962 | |
| 2963 | buffer_handle_t * buf = NULL; |
| 2964 | status_t res; |
| 2965 | void *virtAddr[3]; |
| 2966 | int i, j; |
| 2967 | int index; |
| 2968 | nsecs_t timestamp; |
| 2969 | |
| 2970 | if (!(selfThread->m_isBufferInit)) |
| 2971 | { |
| 2972 | for ( i=0 ; i < selfStreamParms->numSvcBuffers; i++) { |
| 2973 | res = selfStreamParms->streamOps->dequeue_buffer(selfStreamParms->streamOps, &buf); |
| 2974 | if (res != NO_ERROR || buf == NULL) { |
| 2975 | ALOGE("ERR(%s): Init: unable to dequeue buffer : %d",__FUNCTION__ , res); |
| 2976 | return; |
| 2977 | } |
| 2978 | ALOGV("DEBUG(%s): got buf(%x) version(%d), numFds(%d), numInts(%d)", __FUNCTION__, (uint32_t)(*buf), |
| 2979 | ((native_handle_t*)(*buf))->version, ((native_handle_t*)(*buf))->numFds, ((native_handle_t*)(*buf))->numInts); |
| 2980 | |
| 2981 | if (m_grallocHal->lock(m_grallocHal, *buf, |
| 2982 | selfStreamParms->usage, |
| 2983 | 0, 0, selfStreamParms->outputWidth, selfStreamParms->outputHeight, virtAddr) != 0) { |
| 2984 | ALOGE("ERR(%s): could not obtain gralloc buffer", __FUNCTION__); |
| 2985 | return; |
| 2986 | } |
| 2987 | ALOGV("DEBUG(%s): locked img buf plane0(%x) plane1(%x) plane2(%x)", |
| 2988 | __FUNCTION__, (unsigned int)virtAddr[0], (unsigned int)virtAddr[1], (unsigned int)virtAddr[2]); |
| 2989 | |
| 2990 | index = selfThread->findBufferIndex(virtAddr[0]); |
| 2991 | if (index == -1) { |
| 2992 | ALOGE("ERR(%s): could not find buffer index", __FUNCTION__); |
| 2993 | } |
| 2994 | else { |
| 2995 | ALOGV("DEBUG(%s): found buffer index[%d] - status(%d)", |
| 2996 | __FUNCTION__, index, selfStreamParms->svcBufStatus[index]); |
| 2997 | if (selfStreamParms->svcBufStatus[index]== REQUIRES_DQ_FROM_SVC) |
| 2998 | selfStreamParms->svcBufStatus[index] = ON_DRIVER; |
| 2999 | else if (selfStreamParms->svcBufStatus[index]== ON_SERVICE) |
| 3000 | selfStreamParms->svcBufStatus[index] = ON_HAL; |
| 3001 | else { |
| 3002 | ALOGV("DBG(%s): buffer status abnormal (%d) " |
| 3003 | , __FUNCTION__, selfStreamParms->svcBufStatus[index]); |
| 3004 | } |
| 3005 | selfStreamParms->numSvcBufsInHal++; |
| 3006 | if (*buf != selfStreamParms->svcBufHandle[index]) |
| 3007 | ALOGV("DBG(%s): different buf_handle index ", __FUNCTION__); |
| 3008 | else |
| 3009 | ALOGV("DEBUG(%s): same buf_handle index", __FUNCTION__); |
| 3010 | } |
| 3011 | selfStreamParms->svcBufIndex = 0; |
| 3012 | } |
| 3013 | selfThread->m_isBufferInit = true; |
| 3014 | } |
| 3015 | |
| 3016 | if (m_recordingEnabled && m_needsRecordBufferInit) { |
| 3017 | ALOGV("DEBUG(%s): Recording Buffer Initialization numsvcbuf(%d)", |
| 3018 | __FUNCTION__, selfRecordParms->numSvcBuffers); |
| 3019 | int checkingIndex = 0; |
| 3020 | bool found = false; |
| 3021 | for ( i=0 ; i < selfRecordParms->numSvcBuffers; i++) { |
| 3022 | res = selfRecordParms->streamOps->dequeue_buffer(selfRecordParms->streamOps, &buf); |
| 3023 | if (res != NO_ERROR || buf == NULL) { |
| 3024 | ALOGE("ERR(%s): Init: unable to dequeue buffer : %d",__FUNCTION__ , res); |
| 3025 | return; |
| 3026 | } |
| 3027 | selfRecordParms->numSvcBufsInHal++; |
| 3028 | ALOGV("DEBUG(%s): [record] got buf(%x) bufInHal(%d) version(%d), numFds(%d), numInts(%d)", __FUNCTION__, (uint32_t)(*buf), |
| 3029 | selfRecordParms->numSvcBufsInHal, ((native_handle_t*)(*buf))->version, ((native_handle_t*)(*buf))->numFds, ((native_handle_t*)(*buf))->numInts); |
| 3030 | |
| 3031 | if (m_grallocHal->lock(m_grallocHal, *buf, |
| 3032 | selfRecordParms->usage, 0, 0, |
| 3033 | selfRecordParms->outputWidth, selfRecordParms->outputHeight, virtAddr) != 0) { |
| 3034 | ALOGE("ERR(%s): could not obtain gralloc buffer", __FUNCTION__); |
| 3035 | } |
| 3036 | else { |
| 3037 | ALOGV("DEBUG(%s): [record] locked img buf plane0(%x) plane1(%x) plane2(%x)", |
| 3038 | __FUNCTION__, (unsigned int)virtAddr[0], (unsigned int)virtAddr[1], (unsigned int)virtAddr[2]); |
| 3039 | } |
| 3040 | found = false; |
| 3041 | for (checkingIndex = 0; checkingIndex < selfRecordParms->numSvcBuffers ; checkingIndex++) { |
| 3042 | if (selfRecordParms->svcBufHandle[checkingIndex] == *buf ) { |
| 3043 | found = true; |
| 3044 | break; |
| 3045 | } |
| 3046 | } |
| 3047 | ALOGV("DEBUG(%s): [record] found(%d) - index[%d]", __FUNCTION__, found, checkingIndex); |
| 3048 | if (!found) break; |
| 3049 | |
| 3050 | index = checkingIndex; |
| 3051 | |
| 3052 | if (index == -1) { |
| 3053 | ALOGV("ERR(%s): could not find buffer index", __FUNCTION__); |
| 3054 | } |
| 3055 | else { |
| 3056 | ALOGV("DEBUG(%s): found buffer index[%d] - status(%d)", |
| 3057 | __FUNCTION__, index, selfRecordParms->svcBufStatus[index]); |
| 3058 | if (selfRecordParms->svcBufStatus[index]== ON_SERVICE) |
| 3059 | selfRecordParms->svcBufStatus[index] = ON_HAL; |
| 3060 | else { |
| 3061 | ALOGV("DBG(%s): buffer status abnormal (%d) " |
| 3062 | , __FUNCTION__, selfRecordParms->svcBufStatus[index]); |
| 3063 | } |
| 3064 | if (*buf != selfRecordParms->svcBufHandle[index]) |
| 3065 | ALOGV("DBG(%s): different buf_handle index ", __FUNCTION__); |
| 3066 | else |
| 3067 | ALOGV("DEBUG(%s): same buf_handle index", __FUNCTION__); |
| 3068 | } |
| 3069 | selfRecordParms->svcBufIndex = 0; |
| 3070 | } |
| 3071 | m_needsRecordBufferInit = false; |
| 3072 | } |
Sungjoong Kang | 74d78eb | 2012-08-29 13:25:46 -0700 | [diff] [blame] | 3073 | if (m_previewCbEnabled && m_needsPreviewCbBufferInit) { |
| 3074 | ALOGV("DEBUG(%s): previewCb Buffer Initialization numsvcbuf(%d)", |
| 3075 | __FUNCTION__, selfPreviewCbParms->numSvcBuffers); |
| 3076 | int checkingIndex = 0; |
| 3077 | bool found = false; |
| 3078 | |
| 3079 | m_getAlignedYUVSize(HAL_PIXEL_FORMAT_2_V4L2_PIX(selfPreviewCbParms->internalFormat), selfPreviewCbParms->outputWidth, |
| 3080 | selfPreviewCbParms->outputHeight, &m_previewCbBuf); |
| 3081 | ALOGV("(%s): PreviewCb tempbuf size : %d %d %d", __FUNCTION__, m_previewCbBuf.size.extS[0], |
| 3082 | m_previewCbBuf.size.extS[1], m_previewCbBuf.size.extS[2]); |
| 3083 | |
| 3084 | if (allocCameraMemory(selfStreamParms->ionClient, &m_previewCbBuf, selfPreviewCbParms->internalPlanes) == -1) { |
| 3085 | ALOGE("ERR(%s): Failed to allocate previewcb buf", __FUNCTION__); |
| 3086 | } |
| 3087 | |
| 3088 | for ( i=0 ; i < selfPreviewCbParms->numSvcBuffers; i++) { |
| 3089 | res = selfPreviewCbParms->streamOps->dequeue_buffer(selfPreviewCbParms->streamOps, &buf); |
| 3090 | if (res != NO_ERROR || buf == NULL) { |
| 3091 | ALOGE("ERR(%s): Init: unable to dequeue buffer : %d",__FUNCTION__ , res); |
| 3092 | return; |
| 3093 | } |
| 3094 | selfPreviewCbParms->numSvcBufsInHal++; |
| 3095 | ALOGV("DEBUG(%s): [previewCb] got buf(%x) bufInHal(%d) version(%d), numFds(%d), numInts(%d)", __FUNCTION__, (uint32_t)(*buf), |
| 3096 | selfPreviewCbParms->numSvcBufsInHal, ((native_handle_t*)(*buf))->version, ((native_handle_t*)(*buf))->numFds, ((native_handle_t*)(*buf))->numInts); |
| 3097 | |
| 3098 | if (m_grallocHal->lock(m_grallocHal, *buf, |
| 3099 | selfPreviewCbParms->usage, 0, 0, |
| 3100 | selfPreviewCbParms->outputWidth, selfPreviewCbParms->outputHeight, virtAddr) != 0) { |
| 3101 | ALOGE("ERR(%s): could not obtain gralloc buffer", __FUNCTION__); |
| 3102 | } |
| 3103 | else { |
| 3104 | ALOGV("DEBUG(%s): [previewCb] locked img buf plane0(%x) plane1(%x) plane2(%x)", |
| 3105 | __FUNCTION__, (unsigned int)virtAddr[0], (unsigned int)virtAddr[1], (unsigned int)virtAddr[2]); |
| 3106 | } |
| 3107 | found = false; |
| 3108 | for (checkingIndex = 0; checkingIndex < selfPreviewCbParms->numSvcBuffers ; checkingIndex++) { |
| 3109 | if (selfPreviewCbParms->svcBufHandle[checkingIndex] == *buf ) { |
| 3110 | found = true; |
| 3111 | break; |
| 3112 | } |
| 3113 | } |
| 3114 | ALOGV("DEBUG(%s): [previewCb] found(%d) - index[%d]", __FUNCTION__, found, checkingIndex); |
| 3115 | if (!found) break; |
| 3116 | |
| 3117 | index = checkingIndex; |
| 3118 | |
| 3119 | if (index == -1) { |
| 3120 | ALOGV("ERR(%s): could not find buffer index", __FUNCTION__); |
| 3121 | } |
| 3122 | else { |
| 3123 | ALOGV("DEBUG(%s): found buffer index[%d] - status(%d)", |
| 3124 | __FUNCTION__, index, selfPreviewCbParms->svcBufStatus[index]); |
| 3125 | if (selfPreviewCbParms->svcBufStatus[index]== ON_SERVICE) |
| 3126 | selfPreviewCbParms->svcBufStatus[index] = ON_HAL; |
| 3127 | else { |
| 3128 | ALOGV("DBG(%s): buffer status abnormal (%d) " |
| 3129 | , __FUNCTION__, selfPreviewCbParms->svcBufStatus[index]); |
| 3130 | } |
| 3131 | if (*buf != selfPreviewCbParms->svcBufHandle[index]) |
| 3132 | ALOGV("DBG(%s): different buf_handle index ", __FUNCTION__); |
| 3133 | else |
| 3134 | ALOGV("DEBUG(%s): same buf_handle index", __FUNCTION__); |
| 3135 | } |
| 3136 | selfPreviewCbParms->svcBufIndex = 0; |
| 3137 | } |
| 3138 | m_needsPreviewCbBufferInit = false; |
| 3139 | } |
Sungjoong Kang | 86646da | 2012-08-28 17:29:11 +0900 | [diff] [blame] | 3140 | |
| 3141 | } |
| 3142 | |
Jiyoung Shin | c15a6b0 | 2012-06-05 01:08:14 -0700 | [diff] [blame] | 3143 | void ExynosCameraHWInterface2::m_streamThreadInitialize(SignalDrivenThread * self) |
| 3144 | { |
Sungjoong Kang | 13d8c7b | 2012-07-14 10:20:39 +0900 | [diff] [blame] | 3145 | StreamThread * selfThread = ((StreamThread*)self); |
| 3146 | ALOGV("DEBUG(%s): ", __FUNCTION__ ); |
| 3147 | memset(&(selfThread->m_parameters), 0, sizeof(stream_parameters_t)); |
| 3148 | selfThread->m_isBufferInit = false; |
| 3149 | |
Jiyoung Shin | c15a6b0 | 2012-06-05 01:08:14 -0700 | [diff] [blame] | 3150 | return; |
| 3151 | } |
| 3152 | |
Sungjoong Kang | 86646da | 2012-08-28 17:29:11 +0900 | [diff] [blame] | 3153 | void ExynosCameraHWInterface2::m_streamFunc0(SignalDrivenThread *self) |
Jiyoung Shin | c15a6b0 | 2012-06-05 01:08:14 -0700 | [diff] [blame] | 3154 | { |
Sungjoong Kang | 13d8c7b | 2012-07-14 10:20:39 +0900 | [diff] [blame] | 3155 | uint32_t currentSignal = self->GetProcessingSignal(); |
| 3156 | StreamThread * selfThread = ((StreamThread*)self); |
| 3157 | stream_parameters_t *selfStreamParms = &(selfThread->m_parameters); |
Sungjoong Kang | 9dd63e1 | 2012-07-24 00:25:51 +0900 | [diff] [blame] | 3158 | record_parameters_t *selfRecordParms = &(selfThread->m_recordParameters); |
Sungjoong Kang | 74d78eb | 2012-08-29 13:25:46 -0700 | [diff] [blame] | 3159 | callback_parameters_t *selfPreviewCbParms = &(selfThread->m_previewCbParameters); |
Sungjoong Kang | 13d8c7b | 2012-07-14 10:20:39 +0900 | [diff] [blame] | 3160 | node_info_t *currentNode = &(selfStreamParms->node); |
Jiyoung Shin | c15a6b0 | 2012-06-05 01:08:14 -0700 | [diff] [blame] | 3161 | |
Sungjoong Kang | 13d8c7b | 2012-07-14 10:20:39 +0900 | [diff] [blame] | 3162 | if (currentSignal & SIGNAL_STREAM_CHANGE_PARAMETER) { |
| 3163 | ALOGV("DEBUG(%s): processing SIGNAL_STREAM_CHANGE_PARAMETER", __FUNCTION__); |
Jiyoung Shin | c15a6b0 | 2012-06-05 01:08:14 -0700 | [diff] [blame] | 3164 | |
Sungjoong Kang | 13d8c7b | 2012-07-14 10:20:39 +0900 | [diff] [blame] | 3165 | ALOGV("DEBUG(%s): processing SIGNAL_STREAM_CHANGE_PARAMETER DONE", __FUNCTION__); |
Jiyoung Shin | c15a6b0 | 2012-06-05 01:08:14 -0700 | [diff] [blame] | 3166 | } |
Sungjoong Kang | 13d8c7b | 2012-07-14 10:20:39 +0900 | [diff] [blame] | 3167 | |
Sungjoong Kang | b55ed66 | 2012-08-31 21:31:34 -0700 | [diff] [blame] | 3168 | if (currentSignal & SIGNAL_THREAD_RELEASE) { |
| 3169 | int i, index = -1, cnt_to_dq = 0; |
| 3170 | status_t res; |
| 3171 | ALOGV("DEBUG(%s): processing SIGNAL_THREAD_RELEASE", __FUNCTION__); |
| 3172 | ALOGD("(%s):(%d) SIGNAL_THREAD_RELEASE", __FUNCTION__, selfStreamParms->streamType); |
| 3173 | |
| 3174 | if (selfThread->m_isBufferInit) { |
| 3175 | for ( i=0 ; i < selfStreamParms->numSvcBuffers; i++) { |
| 3176 | ALOGV("DEBUG(%s): checking buffer index[%d] - status(%d)", |
| 3177 | __FUNCTION__, i, selfStreamParms->svcBufStatus[i]); |
| 3178 | if (selfStreamParms->svcBufStatus[i] ==ON_DRIVER) cnt_to_dq++; |
| 3179 | } |
| 3180 | |
| 3181 | ALOGV("DEBUG(%s): calling stream(%d) streamoff (fd:%d)", __FUNCTION__, |
| 3182 | selfThread->m_index, selfStreamParms->fd); |
| 3183 | if (cam_int_streamoff(&(selfStreamParms->node)) < 0 ){ |
| 3184 | ALOGE("ERR(%s): stream off fail", __FUNCTION__); |
| 3185 | } else { |
| 3186 | m_scp_closing = true; |
| 3187 | } |
| 3188 | ALOGV("DEBUG(%s): calling stream(%d) streamoff done", __FUNCTION__, selfThread->m_index); |
| 3189 | ALOGV("DEBUG(%s): calling stream(%d) reqbuf 0 (fd:%d)", __FUNCTION__, |
| 3190 | selfThread->m_index, selfStreamParms->fd); |
| 3191 | currentNode->buffers = 0; |
| 3192 | cam_int_reqbufs(currentNode); |
| 3193 | ALOGV("DEBUG(%s): calling stream(%d) reqbuf 0 DONE(fd:%d)", __FUNCTION__, |
| 3194 | selfThread->m_index, selfStreamParms->fd); |
| 3195 | } |
| 3196 | #ifdef ENABLE_FRAME_SYNC |
| 3197 | // free metabuffers |
| 3198 | for(i = 0; i < NUM_MAX_CAMERA_BUFFERS; i++) |
| 3199 | if(selfStreamParms->metaBuffers[i].fd.extFd[0] != 0){ |
| 3200 | freeCameraMemory(&(selfStreamParms->metaBuffers[i]), 1); |
| 3201 | selfStreamParms->metaBuffers[i].fd.extFd[0] = 0; |
| 3202 | selfStreamParms->metaBuffers[i].size.extS[0] = 0; |
| 3203 | } |
| 3204 | #endif |
| 3205 | selfThread->m_isBufferInit = false; |
| 3206 | selfThread->m_index = 255; |
| 3207 | |
| 3208 | selfThread->m_releasing = false; |
| 3209 | |
| 3210 | ALOGV("DEBUG(%s): processing SIGNAL_THREAD_RELEASE DONE", __FUNCTION__); |
| 3211 | |
| 3212 | return; |
| 3213 | } |
| 3214 | |
Sungjoong Kang | 13d8c7b | 2012-07-14 10:20:39 +0900 | [diff] [blame] | 3215 | if (currentSignal & SIGNAL_STREAM_DATA_COMING) { |
Jiyoung Shin | c15a6b0 | 2012-06-05 01:08:14 -0700 | [diff] [blame] | 3216 | buffer_handle_t * buf = NULL; |
| 3217 | status_t res; |
| 3218 | void *virtAddr[3]; |
| 3219 | int i, j; |
| 3220 | int index; |
Sungjoong Kang | ad37861 | 2012-08-17 12:34:33 -0700 | [diff] [blame] | 3221 | nsecs_t timestamp; |
Sungjoong Kang | feb7df4 | 2012-08-28 23:35:43 +0900 | [diff] [blame] | 3222 | camera2_stream *frame; |
Sungjoong Kang | ad37861 | 2012-08-17 12:34:33 -0700 | [diff] [blame] | 3223 | |
Sungjoong Kang | 13d8c7b | 2012-07-14 10:20:39 +0900 | [diff] [blame] | 3224 | ALOGV("DEBUG(%s): stream(%d) processing SIGNAL_STREAM_DATA_COMING", |
| 3225 | __FUNCTION__,selfThread->m_index); |
Sungjoong Kang | ad37861 | 2012-08-17 12:34:33 -0700 | [diff] [blame] | 3226 | |
Sungjoong Kang | 86646da | 2012-08-28 17:29:11 +0900 | [diff] [blame] | 3227 | m_streamBufferInit(self); |
Jiyoung Shin | c15a6b0 | 2012-06-05 01:08:14 -0700 | [diff] [blame] | 3228 | |
Sungjoong Kang | b5237e6 | 2012-07-27 07:39:05 -0700 | [diff] [blame] | 3229 | do { |
Sungjoong Kang | 86646da | 2012-08-28 17:29:11 +0900 | [diff] [blame] | 3230 | ALOGV("DEBUG(%s): stream(%d) type(%d) DQBUF START ",__FUNCTION__, |
| 3231 | selfThread->m_index, selfStreamParms->streamType); |
Jiyoung Shin | c15a6b0 | 2012-06-05 01:08:14 -0700 | [diff] [blame] | 3232 | |
Sungjoong Kang | feb7df4 | 2012-08-28 23:35:43 +0900 | [diff] [blame] | 3233 | #ifdef ENABLE_FRAME_SYNC |
| 3234 | index = cam_int_dqbuf(&(selfStreamParms->node), selfStreamParms->nodePlanes + selfStreamParms->metaPlanes); |
| 3235 | frame = (struct camera2_stream *)(selfStreamParms->metaBuffers[index].virt.extP[0]); |
| 3236 | ALOGD("frame count(SCP) : %d", frame->fcount); |
| 3237 | #else |
Sungjoong Kang | 86646da | 2012-08-28 17:29:11 +0900 | [diff] [blame] | 3238 | index = cam_int_dqbuf(&(selfStreamParms->node)); |
Sungjoong Kang | feb7df4 | 2012-08-28 23:35:43 +0900 | [diff] [blame] | 3239 | #endif |
Sungjoong Kang | b55ed66 | 2012-08-31 21:31:34 -0700 | [diff] [blame] | 3240 | m_scpOutputImageCnt++; |
| 3241 | ALOGV("DEBUG(%s): stream(%d) DQBUF done index(%d) sigcnt(%d) imgcnt(%d)",__FUNCTION__, |
| 3242 | selfThread->m_index, index, m_scpOutputSignalCnt, m_scpOutputImageCnt); |
Sungjoong Kang | 13d8c7b | 2012-07-14 10:20:39 +0900 | [diff] [blame] | 3243 | |
Sungjoong Kang | 86646da | 2012-08-28 17:29:11 +0900 | [diff] [blame] | 3244 | if (selfStreamParms->svcBufStatus[index] != ON_DRIVER) |
| 3245 | ALOGV("DBG(%s): DQed buffer status abnormal (%d) ", |
| 3246 | __FUNCTION__, selfStreamParms->svcBufStatus[index]); |
| 3247 | selfStreamParms->svcBufStatus[index] = ON_HAL; |
Sungjoong Kang | 13d8c7b | 2012-07-14 10:20:39 +0900 | [diff] [blame] | 3248 | |
Sungjoong Kang | 86646da | 2012-08-28 17:29:11 +0900 | [diff] [blame] | 3249 | if (m_recordOutput && m_recordingEnabled) { |
| 3250 | ALOGV("DEBUG(%s): Entering record frame creator, index(%d)",__FUNCTION__, selfRecordParms->svcBufIndex); |
Sungjoong Kang | 37e122d | 2012-08-08 11:13:48 -0700 | [diff] [blame] | 3251 | bool found = false; |
Sungjoong Kang | 86646da | 2012-08-28 17:29:11 +0900 | [diff] [blame] | 3252 | for (int i = 0 ; selfRecordParms->numSvcBuffers ; i++) { |
| 3253 | if (selfRecordParms->svcBufStatus[selfRecordParms->svcBufIndex] == ON_HAL) { |
Sungjoong Kang | 37e122d | 2012-08-08 11:13:48 -0700 | [diff] [blame] | 3254 | found = true; |
| 3255 | break; |
| 3256 | } |
Sungjoong Kang | 86646da | 2012-08-28 17:29:11 +0900 | [diff] [blame] | 3257 | selfRecordParms->svcBufIndex++; |
| 3258 | if (selfRecordParms->svcBufIndex >= selfRecordParms->numSvcBuffers) |
| 3259 | selfRecordParms->svcBufIndex = 0; |
Sungjoong Kang | 37e122d | 2012-08-08 11:13:48 -0700 | [diff] [blame] | 3260 | } |
| 3261 | if (!found) { |
Sungjoong Kang | 86646da | 2012-08-28 17:29:11 +0900 | [diff] [blame] | 3262 | ALOGE("(%s): cannot find free recording buffer", __FUNCTION__); |
| 3263 | selfRecordParms->svcBufIndex++; |
Sungjoong Kang | 37e122d | 2012-08-08 11:13:48 -0700 | [diff] [blame] | 3264 | break; |
| 3265 | } |
Jiyoung Shin | c15a6b0 | 2012-06-05 01:08:14 -0700 | [diff] [blame] | 3266 | |
Sungjoong Kang | 86646da | 2012-08-28 17:29:11 +0900 | [diff] [blame] | 3267 | if (m_exynosVideoCSC) { |
| 3268 | int videoW = selfRecordParms->outputWidth, videoH = selfRecordParms->outputHeight; |
| 3269 | int cropX, cropY, cropW, cropH = 0; |
| 3270 | int previewW = selfStreamParms->outputWidth, previewH = selfStreamParms->outputHeight; |
| 3271 | m_getRatioSize(previewW, previewH, |
| 3272 | videoW, videoH, |
Sungjoong Kang | b5237e6 | 2012-07-27 07:39:05 -0700 | [diff] [blame] | 3273 | &cropX, &cropY, |
| 3274 | &cropW, &cropH, |
Sungjoong Kang | ad37861 | 2012-08-17 12:34:33 -0700 | [diff] [blame] | 3275 | 0); |
Sungjoong Kang | 13d8c7b | 2012-07-14 10:20:39 +0900 | [diff] [blame] | 3276 | |
Sungjoong Kang | b5237e6 | 2012-07-27 07:39:05 -0700 | [diff] [blame] | 3277 | ALOGV("DEBUG(%s):cropX = %d, cropY = %d, cropW = %d, cropH = %d", |
Sungjoong Kang | 86646da | 2012-08-28 17:29:11 +0900 | [diff] [blame] | 3278 | __FUNCTION__, cropX, cropY, cropW, cropH); |
Sungjoong Kang | 13d8c7b | 2012-07-14 10:20:39 +0900 | [diff] [blame] | 3279 | |
Sungjoong Kang | 86646da | 2012-08-28 17:29:11 +0900 | [diff] [blame] | 3280 | csc_set_src_format(m_exynosVideoCSC, |
| 3281 | previewW, previewH, |
Sungjoong Kang | b5237e6 | 2012-07-27 07:39:05 -0700 | [diff] [blame] | 3282 | cropX, cropY, cropW, cropH, |
Sungjoong Kang | 74d78eb | 2012-08-29 13:25:46 -0700 | [diff] [blame] | 3283 | selfStreamParms->outputFormat, |
Sungjoong Kang | b5237e6 | 2012-07-27 07:39:05 -0700 | [diff] [blame] | 3284 | 0); |
Sungjoong Kang | 13d8c7b | 2012-07-14 10:20:39 +0900 | [diff] [blame] | 3285 | |
Sungjoong Kang | 86646da | 2012-08-28 17:29:11 +0900 | [diff] [blame] | 3286 | csc_set_dst_format(m_exynosVideoCSC, |
| 3287 | videoW, videoH, |
| 3288 | 0, 0, videoW, videoH, |
| 3289 | selfRecordParms->outputFormat, |
| 3290 | 1); |
Jiyoung Shin | c15a6b0 | 2012-06-05 01:08:14 -0700 | [diff] [blame] | 3291 | |
Sungjoong Kang | 86646da | 2012-08-28 17:29:11 +0900 | [diff] [blame] | 3292 | csc_set_src_buffer(m_exynosVideoCSC, |
| 3293 | (void **)(&(selfStreamParms->svcBuffers[index].fd.fd))); |
Sungjoong Kang | 13d8c7b | 2012-07-14 10:20:39 +0900 | [diff] [blame] | 3294 | |
Sungjoong Kang | 86646da | 2012-08-28 17:29:11 +0900 | [diff] [blame] | 3295 | csc_set_dst_buffer(m_exynosVideoCSC, |
| 3296 | (void **)(&(selfRecordParms->svcBuffers[selfRecordParms->svcBufIndex].fd.fd))); |
Sungjoong Kang | 13d8c7b | 2012-07-14 10:20:39 +0900 | [diff] [blame] | 3297 | |
Sungjoong Kang | 86646da | 2012-08-28 17:29:11 +0900 | [diff] [blame] | 3298 | if (csc_convert(m_exynosVideoCSC) != 0) { |
| 3299 | ALOGE("ERR(%s):csc_convert() fail", __FUNCTION__); |
| 3300 | } |
| 3301 | else { |
| 3302 | ALOGV("(%s):csc_convert() SUCCESS", __FUNCTION__); |
| 3303 | } |
Sungjoong Kang | 13d8c7b | 2012-07-14 10:20:39 +0900 | [diff] [blame] | 3304 | } |
| 3305 | else { |
Sungjoong Kang | 86646da | 2012-08-28 17:29:11 +0900 | [diff] [blame] | 3306 | ALOGE("ERR(%s):m_exynosVideoCSC == NULL", __FUNCTION__); |
Sungjoong Kang | 13d8c7b | 2012-07-14 10:20:39 +0900 | [diff] [blame] | 3307 | } |
Sungjoong Kang | 13d8c7b | 2012-07-14 10:20:39 +0900 | [diff] [blame] | 3308 | |
Sungjoong Kang | 86646da | 2012-08-28 17:29:11 +0900 | [diff] [blame] | 3309 | res = selfRecordParms->streamOps->enqueue_buffer(selfRecordParms->streamOps, |
| 3310 | systemTime(), |
| 3311 | &(selfRecordParms->svcBufHandle[selfRecordParms->svcBufIndex])); |
| 3312 | ALOGV("DEBUG(%s): stream(%d) record enqueue_buffer to svc done res(%d)", __FUNCTION__, |
| 3313 | selfThread->m_index, res); |
Sungjoong Kang | 37e122d | 2012-08-08 11:13:48 -0700 | [diff] [blame] | 3314 | if (res == 0) { |
Sungjoong Kang | 86646da | 2012-08-28 17:29:11 +0900 | [diff] [blame] | 3315 | selfRecordParms->svcBufStatus[selfRecordParms->svcBufIndex] = ON_SERVICE; |
| 3316 | selfRecordParms->numSvcBufsInHal--; |
Sungjoong Kang | b5237e6 | 2012-07-27 07:39:05 -0700 | [diff] [blame] | 3317 | } |
Sungjoong Kang | b5237e6 | 2012-07-27 07:39:05 -0700 | [diff] [blame] | 3318 | } |
Sungjoong Kang | 74d78eb | 2012-08-29 13:25:46 -0700 | [diff] [blame] | 3319 | if (m_previewCbOutput && m_previewCbEnabled) { |
| 3320 | ALOGV("DEBUG(%s): Entering previewcb creator, index(%d)",__FUNCTION__, selfPreviewCbParms->svcBufIndex); |
| 3321 | |
| 3322 | bool found = false; |
| 3323 | for (int i = 0 ; selfPreviewCbParms->numSvcBuffers ; i++) { |
| 3324 | if (selfPreviewCbParms->svcBufStatus[selfPreviewCbParms->svcBufIndex] == ON_HAL) { |
| 3325 | found = true; |
| 3326 | break; |
| 3327 | } |
| 3328 | selfPreviewCbParms->svcBufIndex++; |
| 3329 | if (selfPreviewCbParms->svcBufIndex >= selfPreviewCbParms->numSvcBuffers) |
| 3330 | selfPreviewCbParms->svcBufIndex = 0; |
| 3331 | } |
| 3332 | if (!found) { |
| 3333 | ALOGE("(%s): cannot find free previewcb buffer", __FUNCTION__); |
| 3334 | selfPreviewCbParms->svcBufIndex++; |
| 3335 | break; |
| 3336 | } |
| 3337 | if (selfPreviewCbParms->outputFormat == HAL_PIXEL_FORMAT_YCrCb_420_SP) { |
| 3338 | if (m_exynosVideoCSC) { |
| 3339 | int previewCbW = selfPreviewCbParms->outputWidth, previewCbH = selfPreviewCbParms->outputHeight; |
| 3340 | int cropX, cropY, cropW, cropH = 0; |
| 3341 | int previewW = selfStreamParms->outputWidth, previewH = selfStreamParms->outputHeight; |
| 3342 | m_getRatioSize(previewW, previewH, |
| 3343 | previewCbW, previewCbH, |
| 3344 | &cropX, &cropY, |
| 3345 | &cropW, &cropH, |
| 3346 | 0); |
| 3347 | |
| 3348 | ALOGV("DEBUG(%s):cropX = %d, cropY = %d, cropW = %d, cropH = %d", |
| 3349 | __FUNCTION__, cropX, cropY, cropW, cropH); |
| 3350 | csc_set_src_format(m_exynosVideoCSC, |
| 3351 | previewW, previewH, |
| 3352 | cropX, cropY, cropW, cropH, |
| 3353 | selfStreamParms->outputFormat, |
| 3354 | 0); |
| 3355 | |
| 3356 | csc_set_dst_format(m_exynosVideoCSC, |
| 3357 | previewCbW, previewCbH, |
| 3358 | 0, 0, previewCbW, previewCbH, |
| 3359 | selfPreviewCbParms->internalFormat, |
| 3360 | 1); |
| 3361 | |
| 3362 | csc_set_src_buffer(m_exynosVideoCSC, |
| 3363 | (void **)(&(selfStreamParms->svcBuffers[index].fd.fd))); |
| 3364 | |
| 3365 | csc_set_dst_buffer(m_exynosVideoCSC, |
| 3366 | (void **)(&(m_previewCbBuf.fd.fd))); |
| 3367 | |
| 3368 | if (csc_convert(m_exynosVideoCSC) != 0) { |
| 3369 | ALOGE("ERR(%s):previewcb csc_convert() fail", __FUNCTION__); |
| 3370 | } |
| 3371 | else { |
| 3372 | ALOGV("(%s):previewcb csc_convert() SUCCESS", __FUNCTION__); |
| 3373 | } |
| 3374 | if (previewCbW == ALIGN(previewCbW, 16)) { |
| 3375 | ALOGV("(%s):previewcb %d = %d", __FUNCTION__, previewCbW, ALIGN(previewCbW, 16)); |
| 3376 | memcpy(selfPreviewCbParms->svcBuffers[selfPreviewCbParms->svcBufIndex].virt.extP[0], |
| 3377 | m_previewCbBuf.virt.extP[0], previewCbW * previewCbH); |
| 3378 | memcpy(selfPreviewCbParms->svcBuffers[selfPreviewCbParms->svcBufIndex].virt.extP[0] + previewCbW * previewCbH, |
| 3379 | m_previewCbBuf.virt.extP[1], previewCbW * previewCbH / 2 ); |
| 3380 | } |
| 3381 | else { |
| 3382 | // TODO : copy line by line ? |
| 3383 | } |
| 3384 | } |
| 3385 | else { |
| 3386 | ALOGE("ERR(%s):m_exynosVideoCSC == NULL", __FUNCTION__); |
| 3387 | } |
| 3388 | } |
| 3389 | else if (selfPreviewCbParms->outputFormat == HAL_PIXEL_FORMAT_YV12) { |
| 3390 | int previewCbW = selfPreviewCbParms->outputWidth, previewCbH = selfPreviewCbParms->outputHeight; |
| 3391 | int stride = ALIGN(previewCbW, 16); |
| 3392 | int c_stride = ALIGN(stride, 16); |
| 3393 | memcpy(selfPreviewCbParms->svcBuffers[selfPreviewCbParms->svcBufIndex].virt.extP[0], |
| 3394 | selfStreamParms->svcBuffers[index].virt.extP[0], stride * previewCbH); |
| 3395 | memcpy(selfPreviewCbParms->svcBuffers[selfPreviewCbParms->svcBufIndex].virt.extP[0] + stride * previewCbH, |
| 3396 | selfStreamParms->svcBuffers[index].virt.extP[1], c_stride * previewCbH / 2 ); |
| 3397 | memcpy(selfPreviewCbParms->svcBuffers[selfPreviewCbParms->svcBufIndex].virt.extP[0] + (stride * previewCbH) + (c_stride * previewCbH / 2), |
| 3398 | selfStreamParms->svcBuffers[index].virt.extP[2], c_stride * previewCbH / 2 ); |
| 3399 | |
| 3400 | } |
| 3401 | res = selfPreviewCbParms->streamOps->enqueue_buffer(selfPreviewCbParms->streamOps, |
| 3402 | systemTime(), |
| 3403 | &(selfPreviewCbParms->svcBufHandle[selfPreviewCbParms->svcBufIndex])); |
| 3404 | ALOGV("DEBUG(%s): stream(%d) previewcb enqueue_buffer[%d] to svc done res(%d)", __FUNCTION__, |
| 3405 | selfThread->m_index, index, res); |
| 3406 | if (res == 0) { |
| 3407 | selfPreviewCbParms->svcBufStatus[selfPreviewCbParms->svcBufIndex] = ON_SERVICE; |
| 3408 | selfPreviewCbParms->numSvcBufsInHal--; |
| 3409 | } |
| 3410 | } |
Sungjoong Kang | 86646da | 2012-08-28 17:29:11 +0900 | [diff] [blame] | 3411 | if (m_previewOutput && m_requestManager->GetSkipCnt() <= 0) { |
| 3412 | |
| 3413 | ALOGV("** Display Preview(frameCnt:%d)", m_requestManager->GetFrameIndex()); |
| 3414 | res = selfStreamParms->streamOps->enqueue_buffer(selfStreamParms->streamOps, |
| 3415 | m_requestManager->GetTimestamp(m_requestManager->GetFrameIndex()), |
| 3416 | &(selfStreamParms->svcBufHandle[index])); |
| 3417 | |
| 3418 | ALOGV("DEBUG(%s): stream(%d) enqueue_buffer to svc done res(%d)", __FUNCTION__, selfThread->m_index, res); |
| 3419 | } |
| 3420 | else { |
| 3421 | res = selfStreamParms->streamOps->cancel_buffer(selfStreamParms->streamOps, |
| 3422 | &(selfStreamParms->svcBufHandle[index])); |
| 3423 | ALOGV("DEBUG(%s): stream(%d) cancel_buffer to svc done res(%d)", __FUNCTION__, selfThread->m_index, res); |
| 3424 | } |
| 3425 | if (res == 0) { |
| 3426 | selfStreamParms->svcBufStatus[index] = ON_SERVICE; |
| 3427 | selfStreamParms->numSvcBufsInHal--; |
| 3428 | } |
| 3429 | else { |
| 3430 | selfStreamParms->svcBufStatus[index] = ON_HAL; |
| 3431 | } |
| 3432 | |
Sungjoong Kang | 13d8c7b | 2012-07-14 10:20:39 +0900 | [diff] [blame] | 3433 | } |
Sungjoong Kang | b5237e6 | 2012-07-27 07:39:05 -0700 | [diff] [blame] | 3434 | while (0); |
| 3435 | |
Sungjoong Kang | 86646da | 2012-08-28 17:29:11 +0900 | [diff] [blame] | 3436 | if (m_recordOutput && m_recordingEnabled) { |
Sungjoong Kang | 9dd63e1 | 2012-07-24 00:25:51 +0900 | [diff] [blame] | 3437 | do { |
Sungjoong Kang | be494d1 | 2012-08-04 15:36:56 -0700 | [diff] [blame] | 3438 | ALOGV("DEBUG(%s): record currentBuf#(%d)", __FUNCTION__ , selfRecordParms->numSvcBufsInHal); |
| 3439 | if (selfRecordParms->numSvcBufsInHal >= 1) |
Sungjoong Kang | 9dd63e1 | 2012-07-24 00:25:51 +0900 | [diff] [blame] | 3440 | { |
| 3441 | ALOGV("DEBUG(%s): breaking", __FUNCTION__); |
| 3442 | break; |
| 3443 | } |
| 3444 | res = selfRecordParms->streamOps->dequeue_buffer(selfRecordParms->streamOps, &buf); |
| 3445 | if (res != NO_ERROR || buf == NULL) { |
| 3446 | ALOGV("DEBUG(%s): record stream(%d) dequeue_buffer fail res(%d)",__FUNCTION__ , selfThread->m_index, res); |
| 3447 | break; |
| 3448 | } |
Sungjoong Kang | be494d1 | 2012-08-04 15:36:56 -0700 | [diff] [blame] | 3449 | selfRecordParms->numSvcBufsInHal ++; |
Sungjoong Kang | 9dd63e1 | 2012-07-24 00:25:51 +0900 | [diff] [blame] | 3450 | ALOGV("DEBUG(%s): record got buf(%x) numBufInHal(%d) version(%d), numFds(%d), numInts(%d)", __FUNCTION__, (uint32_t)(*buf), |
Sungjoong Kang | be494d1 | 2012-08-04 15:36:56 -0700 | [diff] [blame] | 3451 | selfRecordParms->numSvcBufsInHal, ((native_handle_t*)(*buf))->version, ((native_handle_t*)(*buf))->numFds, ((native_handle_t*)(*buf))->numInts); |
Sungjoong Kang | ad37861 | 2012-08-17 12:34:33 -0700 | [diff] [blame] | 3452 | |
Sungjoong Kang | 9dd63e1 | 2012-07-24 00:25:51 +0900 | [diff] [blame] | 3453 | const private_handle_t *priv_handle = reinterpret_cast<const private_handle_t *>(*buf); |
Sungjoong Kang | 9dd63e1 | 2012-07-24 00:25:51 +0900 | [diff] [blame] | 3454 | bool found = false; |
| 3455 | int checkingIndex = 0; |
| 3456 | for (checkingIndex = 0; checkingIndex < selfRecordParms->numSvcBuffers ; checkingIndex++) { |
| 3457 | if (priv_handle->fd == selfRecordParms->svcBuffers[checkingIndex].fd.extFd[0] ) { |
| 3458 | found = true; |
| 3459 | break; |
| 3460 | } |
| 3461 | } |
| 3462 | ALOGV("DEBUG(%s): recording dequeueed_buffer found index(%d)", __FUNCTION__, found); |
Sungjoong Kang | ad37861 | 2012-08-17 12:34:33 -0700 | [diff] [blame] | 3463 | |
| 3464 | if (!found) { |
| 3465 | break; |
| 3466 | } |
| 3467 | |
Sungjoong Kang | 9dd63e1 | 2012-07-24 00:25:51 +0900 | [diff] [blame] | 3468 | index = checkingIndex; |
| 3469 | if (selfRecordParms->svcBufStatus[index] == ON_SERVICE) { |
| 3470 | selfRecordParms->svcBufStatus[index] = ON_HAL; |
| 3471 | } |
| 3472 | else { |
| 3473 | ALOGV("DEBUG(%s): record bufstatus abnormal [%d] status = %d", __FUNCTION__, |
Sungjoong Kang | ad37861 | 2012-08-17 12:34:33 -0700 | [diff] [blame] | 3474 | index, selfRecordParms->svcBufStatus[index]); |
Sungjoong Kang | 9dd63e1 | 2012-07-24 00:25:51 +0900 | [diff] [blame] | 3475 | } |
| 3476 | } while (0); |
| 3477 | } |
Sungjoong Kang | 74d78eb | 2012-08-29 13:25:46 -0700 | [diff] [blame] | 3478 | if (m_previewCbOutput && m_previewCbEnabled) { |
| 3479 | do { |
| 3480 | ALOGV("DEBUG(%s): previewCb currentBuf#(%d)", __FUNCTION__ , selfPreviewCbParms->numSvcBufsInHal); |
| 3481 | if (selfPreviewCbParms->numSvcBufsInHal >= 1) |
| 3482 | { |
| 3483 | ALOGV("DEBUG(%s): breaking", __FUNCTION__); |
| 3484 | break; |
| 3485 | } |
| 3486 | res = selfPreviewCbParms->streamOps->dequeue_buffer(selfPreviewCbParms->streamOps, &buf); |
| 3487 | if (res != NO_ERROR || buf == NULL) { |
| 3488 | ALOGV("DEBUG(%s): previewcb stream(%d) dequeue_buffer fail res(%d)",__FUNCTION__ , selfThread->m_index, res); |
| 3489 | break; |
| 3490 | } |
| 3491 | selfPreviewCbParms->numSvcBufsInHal ++; |
| 3492 | ALOGV("DEBUG(%s): previewcb got buf(%x) numBufInHal(%d) version(%d), numFds(%d), numInts(%d)", __FUNCTION__, (uint32_t)(*buf), |
| 3493 | selfPreviewCbParms->numSvcBufsInHal, ((native_handle_t*)(*buf))->version, ((native_handle_t*)(*buf))->numFds, ((native_handle_t*)(*buf))->numInts); |
| 3494 | |
| 3495 | const private_handle_t *priv_handle = reinterpret_cast<const private_handle_t *>(*buf); |
| 3496 | bool found = false; |
| 3497 | int checkingIndex = 0; |
| 3498 | for (checkingIndex = 0; checkingIndex < selfPreviewCbParms->numSvcBuffers ; checkingIndex++) { |
| 3499 | if (priv_handle->fd == selfPreviewCbParms->svcBuffers[checkingIndex].fd.extFd[0] ) { |
| 3500 | found = true; |
| 3501 | break; |
| 3502 | } |
| 3503 | } |
| 3504 | ALOGV("DEBUG(%s): previewcb dequeueed_buffer found index(%d)", __FUNCTION__, found); |
| 3505 | |
| 3506 | if (!found) { |
| 3507 | break; |
| 3508 | } |
| 3509 | |
| 3510 | index = checkingIndex; |
| 3511 | if (selfPreviewCbParms->svcBufStatus[index] == ON_SERVICE) { |
| 3512 | selfPreviewCbParms->svcBufStatus[index] = ON_HAL; |
| 3513 | } |
| 3514 | else { |
| 3515 | ALOGV("DEBUG(%s): previewcb bufstatus abnormal [%d] status = %d", __FUNCTION__, |
| 3516 | index, selfPreviewCbParms->svcBufStatus[index]); |
| 3517 | } |
| 3518 | } while (0); |
| 3519 | } |
Sungjoong Kang | 86646da | 2012-08-28 17:29:11 +0900 | [diff] [blame] | 3520 | |
Sungjoong Kang | b55ed66 | 2012-08-31 21:31:34 -0700 | [diff] [blame] | 3521 | while (selfStreamParms->numSvcBufsInHal < selfStreamParms->numOwnSvcBuffers - 1) { |
Sungjoong Kang | 86646da | 2012-08-28 17:29:11 +0900 | [diff] [blame] | 3522 | res = selfStreamParms->streamOps->dequeue_buffer(selfStreamParms->streamOps, &buf); |
| 3523 | if (res != NO_ERROR || buf == NULL) { |
| 3524 | ALOGV("DEBUG(%s): stream(%d) dequeue_buffer fail res(%d)",__FUNCTION__ , selfThread->m_index, res); |
| 3525 | break; |
| 3526 | } |
| 3527 | selfStreamParms->numSvcBufsInHal++; |
| 3528 | ALOGV("DEBUG(%s): stream(%d) got buf(%x) numInHal(%d) version(%d), numFds(%d), numInts(%d)", __FUNCTION__, |
| 3529 | selfThread->m_index, (uint32_t)(*buf), selfStreamParms->numSvcBufsInHal, |
| 3530 | ((native_handle_t*)(*buf))->version, ((native_handle_t*)(*buf))->numFds, ((native_handle_t*)(*buf))->numInts); |
| 3531 | const private_handle_t *priv_handle = reinterpret_cast<const private_handle_t *>(*buf); |
| 3532 | |
| 3533 | bool found = false; |
| 3534 | int checkingIndex = 0; |
| 3535 | for (checkingIndex = 0; checkingIndex < selfStreamParms->numSvcBuffers ; checkingIndex++) { |
| 3536 | if (priv_handle->fd == selfStreamParms->svcBuffers[checkingIndex].fd.extFd[0] ) { |
| 3537 | found = true; |
Sungjoong Kang | 9dd63e1 | 2012-07-24 00:25:51 +0900 | [diff] [blame] | 3538 | break; |
| 3539 | } |
Sungjoong Kang | 86646da | 2012-08-28 17:29:11 +0900 | [diff] [blame] | 3540 | } |
| 3541 | ALOGV("DEBUG(%s): post_dequeue_buffer found(%d)", __FUNCTION__, found); |
| 3542 | if (!found) break; |
| 3543 | ALOGV("DEBUG(%s): preparing to qbuf [%d]", __FUNCTION__, checkingIndex); |
| 3544 | index = checkingIndex; |
| 3545 | if (index < selfStreamParms->numHwBuffers) { |
| 3546 | uint32_t plane_index = 0; |
| 3547 | ExynosBuffer* currentBuf = &(selfStreamParms->svcBuffers[index]); |
| 3548 | struct v4l2_buffer v4l2_buf; |
| 3549 | struct v4l2_plane planes[VIDEO_MAX_PLANES]; |
Sungjoong Kang | 13d8c7b | 2012-07-14 10:20:39 +0900 | [diff] [blame] | 3550 | |
Sungjoong Kang | 86646da | 2012-08-28 17:29:11 +0900 | [diff] [blame] | 3551 | v4l2_buf.m.planes = planes; |
| 3552 | v4l2_buf.type = currentNode->type; |
| 3553 | v4l2_buf.memory = currentNode->memory; |
| 3554 | v4l2_buf.index = index; |
| 3555 | v4l2_buf.length = currentNode->planes; |
| 3556 | |
| 3557 | v4l2_buf.m.planes[0].m.fd = priv_handle->fd; |
| 3558 | v4l2_buf.m.planes[2].m.fd = priv_handle->fd1; |
| 3559 | v4l2_buf.m.planes[1].m.fd = priv_handle->fd2; |
| 3560 | for (plane_index=0 ; plane_index < v4l2_buf.length ; plane_index++) { |
| 3561 | v4l2_buf.m.planes[plane_index].length = currentBuf->size.extS[plane_index]; |
| 3562 | ALOGV("DEBUG(%s): plane(%d): fd(%d) length(%d)", |
| 3563 | __FUNCTION__, plane_index, v4l2_buf.m.planes[plane_index].m.fd, |
| 3564 | v4l2_buf.m.planes[plane_index].length); |
Sungjoong Kang | 9dd63e1 | 2012-07-24 00:25:51 +0900 | [diff] [blame] | 3565 | } |
Sungjoong Kang | feb7df4 | 2012-08-28 23:35:43 +0900 | [diff] [blame] | 3566 | #ifdef ENABLE_FRAME_SYNC |
| 3567 | /* add plane for metadata*/ |
| 3568 | v4l2_buf.length += selfStreamParms->metaPlanes; |
| 3569 | v4l2_buf.m.planes[3].m.fd = selfStreamParms->metaBuffers[index].fd.extFd[0]; |
| 3570 | v4l2_buf.m.planes[3].length = selfStreamParms->metaBuffers[index].size.extS[0]; |
| 3571 | #endif |
Sungjoong Kang | 86646da | 2012-08-28 17:29:11 +0900 | [diff] [blame] | 3572 | if (exynos_v4l2_qbuf(currentNode->fd, &v4l2_buf) < 0) { |
| 3573 | ALOGE("ERR(%s): stream id(%d) exynos_v4l2_qbuf() fail", |
| 3574 | __FUNCTION__, selfThread->m_index); |
| 3575 | return; |
Sungjoong Kang | 9dd63e1 | 2012-07-24 00:25:51 +0900 | [diff] [blame] | 3576 | } |
Sungjoong Kang | 86646da | 2012-08-28 17:29:11 +0900 | [diff] [blame] | 3577 | selfStreamParms->svcBufStatus[index] = ON_DRIVER; |
| 3578 | ALOGV("DEBUG(%s): stream id(%d) type0 QBUF done index(%d)", |
| 3579 | __FUNCTION__, selfThread->m_index, index); |
Sungjoong Kang | 13d8c7b | 2012-07-14 10:20:39 +0900 | [diff] [blame] | 3580 | } |
| 3581 | } |
Sungjoong Kang | be494d1 | 2012-08-04 15:36:56 -0700 | [diff] [blame] | 3582 | |
Sungjoong Kang | 13d8c7b | 2012-07-14 10:20:39 +0900 | [diff] [blame] | 3583 | ALOGV("DEBUG(%s): stream(%d) processing SIGNAL_STREAM_DATA_COMING DONE", |
| 3584 | __FUNCTION__,selfThread->m_index); |
Jiyoung Shin | c15a6b0 | 2012-06-05 01:08:14 -0700 | [diff] [blame] | 3585 | } |
Sungjoong Kang | 86646da | 2012-08-28 17:29:11 +0900 | [diff] [blame] | 3586 | return; |
| 3587 | } |
| 3588 | |
| 3589 | void ExynosCameraHWInterface2::m_streamFunc1(SignalDrivenThread *self) |
| 3590 | { |
| 3591 | uint32_t currentSignal = self->GetProcessingSignal(); |
| 3592 | StreamThread * selfThread = ((StreamThread*)self); |
| 3593 | stream_parameters_t *selfStreamParms = &(selfThread->m_parameters); |
| 3594 | record_parameters_t *selfRecordParms = &(selfThread->m_recordParameters); |
| 3595 | node_info_t *currentNode = &(selfStreamParms->node); |
| 3596 | |
| 3597 | if (currentSignal & SIGNAL_STREAM_CHANGE_PARAMETER) { |
| 3598 | ALOGV("DEBUG(%s): processing SIGNAL_STREAM_CHANGE_PARAMETER", __FUNCTION__); |
| 3599 | |
| 3600 | m_resizeBuf.size.extS[0] = ALIGN(selfStreamParms->outputWidth, 16) * ALIGN(selfStreamParms->outputHeight, 16) * 2; |
| 3601 | m_resizeBuf.size.extS[1] = 0; |
| 3602 | m_resizeBuf.size.extS[2] = 0; |
| 3603 | |
| 3604 | if (allocCameraMemory(selfStreamParms->ionClient, &m_resizeBuf, 1) == -1) { |
| 3605 | ALOGE("ERR(%s): Failed to allocate resize buf", __FUNCTION__); |
| 3606 | } |
| 3607 | |
| 3608 | ALOGV("DEBUG(%s): processing SIGNAL_STREAM_CHANGE_PARAMETER DONE", __FUNCTION__); |
| 3609 | } |
| 3610 | |
| 3611 | if (currentSignal & SIGNAL_STREAM_DATA_COMING) { |
| 3612 | buffer_handle_t * buf = NULL; |
| 3613 | status_t res; |
| 3614 | void *virtAddr[3]; |
| 3615 | int i, j; |
| 3616 | int index; |
| 3617 | nsecs_t timestamp; |
| 3618 | |
| 3619 | ALOGV("DEBUG(%s): stream(%d) processing SIGNAL_STREAM_DATA_COMING", |
| 3620 | __FUNCTION__,selfThread->m_index); |
| 3621 | |
| 3622 | m_streamBufferInit(self); |
| 3623 | |
| 3624 | do { |
| 3625 | ExynosRect jpegRect; |
| 3626 | bool found = false; |
| 3627 | bool ret = false; |
| 3628 | int pictureW, pictureH, pictureFramesize = 0; |
| 3629 | int pictureFormat; |
| 3630 | int cropX, cropY, cropW, cropH = 0; |
| 3631 | ExynosBuffer resizeBufInfo; |
| 3632 | ExynosRect m_orgPictureRect; |
Sungjoong Kang | feb7df4 | 2012-08-28 23:35:43 +0900 | [diff] [blame] | 3633 | camera2_stream *frame; |
Sungjoong Kang | 86646da | 2012-08-28 17:29:11 +0900 | [diff] [blame] | 3634 | |
| 3635 | ALOGD("DEBUG(%s): stream(%d) type(%d) DQBUF START ",__FUNCTION__, |
| 3636 | selfThread->m_index, selfStreamParms->streamType); |
| 3637 | index = cam_int_dqbuf(&(selfStreamParms->node)); |
| 3638 | ALOGD("DEBUG(%s): stream(%d) type(%d) DQBUF done index(%d)",__FUNCTION__, |
| 3639 | selfThread->m_index, selfStreamParms->streamType, index); |
| 3640 | |
Sungjoong Kang | feb7df4 | 2012-08-28 23:35:43 +0900 | [diff] [blame] | 3641 | #ifdef ENABLE_FRAME_SYNC |
| 3642 | frame = (struct camera2_stream *)(selfStreamParms->svcBuffers[index].virt.extP[selfStreamParms->nodePlanes -1]); |
| 3643 | ALOGD("frame count(SCC) : %d", frame->fcount); |
| 3644 | #endif |
Sungjoong Kang | 86646da | 2012-08-28 17:29:11 +0900 | [diff] [blame] | 3645 | for (int i = 0; i < selfStreamParms->numSvcBuffers ; i++) { |
| 3646 | if (selfStreamParms->svcBufStatus[selfStreamParms->svcBufIndex] == ON_HAL) { |
| 3647 | found = true; |
| 3648 | break; |
| 3649 | } |
| 3650 | selfStreamParms->svcBufIndex++; |
| 3651 | if (selfStreamParms->svcBufIndex >= selfStreamParms->numSvcBuffers) |
| 3652 | selfStreamParms->svcBufIndex = 0; |
| 3653 | } |
| 3654 | if (!found) { |
| 3655 | ALOGE("ERR(%s): NO free SVC buffer for JPEG", __FUNCTION__); |
| 3656 | break; |
| 3657 | } |
| 3658 | |
| 3659 | m_orgPictureRect.w = selfStreamParms->outputWidth; |
| 3660 | m_orgPictureRect.h = selfStreamParms->outputHeight; |
| 3661 | |
| 3662 | ExynosBuffer* m_pictureBuf = &(m_camera_info.capture.buffer[index]); |
| 3663 | |
Sungjoong Kang | e4657e3 | 2012-08-28 15:02:19 -0700 | [diff] [blame] | 3664 | m_getRatioSize(selfStreamParms->nodeWidth, selfStreamParms->nodeHeight, |
| 3665 | m_orgPictureRect.w, m_orgPictureRect.h, |
| 3666 | &cropX, &cropY, |
| 3667 | &pictureW, &pictureH, |
| 3668 | 0); |
Sungjoong Kang | 86646da | 2012-08-28 17:29:11 +0900 | [diff] [blame] | 3669 | pictureFormat = V4L2_PIX_FMT_YUYV; |
| 3670 | pictureFramesize = FRAME_SIZE(V4L2_PIX_2_HAL_PIXEL_FORMAT(pictureFormat), pictureW, pictureH); |
| 3671 | |
| 3672 | if (m_exynosPictureCSC) { |
hyeonmyeong Choi | 308291d | 2012-08-29 13:55:01 -0700 | [diff] [blame^] | 3673 | float zoom_w = 0, zoom_h = 0; |
| 3674 | if (m_orgPictureRect.w >= m_orgPictureRect.h) { |
| 3675 | zoom_w = pictureW / m_zoomRatio; |
| 3676 | zoom_h = zoom_w * m_orgPictureRect.h / m_orgPictureRect.w; |
| 3677 | } else { |
| 3678 | zoom_h = pictureH / m_zoomRatio; |
| 3679 | zoom_w = zoom_h * m_orgPictureRect.w / m_orgPictureRect.h; |
| 3680 | } |
| 3681 | cropX = (pictureW - zoom_w) / 2; |
| 3682 | cropY = (pictureH - zoom_h) / 2; |
| 3683 | cropW = zoom_w; |
| 3684 | cropH = zoom_h; |
Sungjoong Kang | 86646da | 2012-08-28 17:29:11 +0900 | [diff] [blame] | 3685 | |
| 3686 | ALOGV("DEBUG(%s):cropX = %d, cropY = %d, cropW = %d, cropH = %d", |
| 3687 | __FUNCTION__, cropX, cropY, cropW, cropH); |
| 3688 | |
| 3689 | csc_set_src_format(m_exynosPictureCSC, |
| 3690 | ALIGN(pictureW, 16), ALIGN(pictureH, 16), |
| 3691 | cropX, cropY, cropW, cropH, |
| 3692 | V4L2_PIX_2_HAL_PIXEL_FORMAT(pictureFormat), |
| 3693 | 0); |
| 3694 | |
| 3695 | csc_set_dst_format(m_exynosPictureCSC, |
| 3696 | m_orgPictureRect.w, m_orgPictureRect.h, |
| 3697 | 0, 0, m_orgPictureRect.w, m_orgPictureRect.h, |
| 3698 | V4L2_PIX_2_HAL_PIXEL_FORMAT(V4L2_PIX_FMT_NV16), |
| 3699 | 0); |
| 3700 | csc_set_src_buffer(m_exynosPictureCSC, |
| 3701 | (void **)&m_pictureBuf->fd.fd); |
| 3702 | |
| 3703 | csc_set_dst_buffer(m_exynosPictureCSC, |
| 3704 | (void **)&m_resizeBuf.fd.fd); |
| 3705 | for (int i = 0 ; i < 3 ; i++) |
| 3706 | ALOGV("DEBUG(%s): m_resizeBuf.virt.extP[%d]=%d m_resizeBuf.size.extS[%d]=%d", |
| 3707 | __FUNCTION__, i, m_resizeBuf.fd.extFd[i], i, m_resizeBuf.size.extS[i]); |
| 3708 | |
| 3709 | if (csc_convert(m_exynosPictureCSC) != 0) |
| 3710 | ALOGE("ERR(%s): csc_convert() fail", __FUNCTION__); |
| 3711 | |
| 3712 | |
| 3713 | } |
| 3714 | else { |
| 3715 | ALOGE("ERR(%s): m_exynosPictureCSC == NULL", __FUNCTION__); |
| 3716 | } |
| 3717 | |
| 3718 | resizeBufInfo = m_resizeBuf; |
| 3719 | |
| 3720 | m_getAlignedYUVSize(V4L2_PIX_FMT_NV16, m_orgPictureRect.w, m_orgPictureRect.h, &m_resizeBuf); |
| 3721 | |
| 3722 | for (int i = 1; i < 3; i++) { |
| 3723 | if (m_resizeBuf.size.extS[i] != 0) |
| 3724 | m_resizeBuf.fd.extFd[i] = m_resizeBuf.fd.extFd[i-1] + m_resizeBuf.size.extS[i-1]; |
| 3725 | |
| 3726 | ALOGV("(%s): m_resizeBuf.size.extS[%d] = %d", __FUNCTION__, i, m_resizeBuf.size.extS[i]); |
| 3727 | } |
| 3728 | |
| 3729 | jpegRect.w = m_orgPictureRect.w; |
| 3730 | jpegRect.h = m_orgPictureRect.h; |
| 3731 | jpegRect.colorFormat = V4L2_PIX_FMT_NV16; |
| 3732 | |
| 3733 | if (yuv2Jpeg(&m_resizeBuf, &selfStreamParms->svcBuffers[selfStreamParms->svcBufIndex], &jpegRect) == false) |
| 3734 | ALOGE("ERR(%s):yuv2Jpeg() fail", __FUNCTION__); |
| 3735 | cam_int_qbuf(&(selfStreamParms->node), index); |
| 3736 | ALOGV("DEBUG(%s): stream(%d) type(%d) QBUF DONE ",__FUNCTION__, |
| 3737 | selfThread->m_index, selfStreamParms->streamType); |
| 3738 | |
| 3739 | m_resizeBuf = resizeBufInfo; |
| 3740 | |
| 3741 | res = selfStreamParms->streamOps->enqueue_buffer(selfStreamParms->streamOps, systemTime(), &(selfStreamParms->svcBufHandle[selfStreamParms->svcBufIndex])); |
| 3742 | |
| 3743 | ALOGV("DEBUG(%s): stream(%d) enqueue_buffer index(%d) to svc done res(%d)", |
| 3744 | __FUNCTION__, selfThread->m_index, selfStreamParms->svcBufIndex, res); |
| 3745 | if (res == 0) { |
| 3746 | selfStreamParms->svcBufStatus[selfStreamParms->svcBufIndex] = ON_SERVICE; |
| 3747 | selfStreamParms->numSvcBufsInHal--; |
| 3748 | } |
| 3749 | else { |
| 3750 | selfStreamParms->svcBufStatus[selfStreamParms->svcBufIndex] = ON_HAL; |
| 3751 | } |
| 3752 | } |
| 3753 | while (0); |
| 3754 | |
| 3755 | while (selfStreamParms->numSvcBufsInHal < selfStreamParms->numOwnSvcBuffers) { |
| 3756 | res = selfStreamParms->streamOps->dequeue_buffer(selfStreamParms->streamOps, &buf); |
| 3757 | if (res != NO_ERROR || buf == NULL) { |
| 3758 | ALOGV("DEBUG(%s): stream(%d) dequeue_buffer fail res(%d)",__FUNCTION__ , selfThread->m_index, res); |
| 3759 | break; |
| 3760 | } |
| 3761 | |
| 3762 | ALOGV("DEBUG(%s): stream(%d) got buf(%x) numInHal(%d) version(%d), numFds(%d), numInts(%d)", __FUNCTION__, |
| 3763 | selfThread->m_index, (uint32_t)(*buf), selfStreamParms->numSvcBufsInHal, |
| 3764 | ((native_handle_t*)(*buf))->version, ((native_handle_t*)(*buf))->numFds, ((native_handle_t*)(*buf))->numInts); |
| 3765 | |
| 3766 | const private_handle_t *priv_handle = reinterpret_cast<const private_handle_t *>(*buf); |
| 3767 | |
| 3768 | bool found = false; |
| 3769 | int checkingIndex = 0; |
| 3770 | for (checkingIndex = 0; checkingIndex < selfStreamParms->numSvcBuffers ; checkingIndex++) { |
| 3771 | if (priv_handle->fd == selfStreamParms->svcBuffers[checkingIndex].fd.extFd[0] ) { |
| 3772 | found = true; |
| 3773 | break; |
| 3774 | } |
| 3775 | } |
| 3776 | if (!found) break; |
| 3777 | selfStreamParms->svcBufStatus[checkingIndex] = ON_HAL; |
| 3778 | selfStreamParms->numSvcBufsInHal++; |
| 3779 | } |
| 3780 | |
| 3781 | ALOGV("DEBUG(%s): stream(%d) processing SIGNAL_STREAM_DATA_COMING DONE", |
| 3782 | __FUNCTION__,selfThread->m_index); |
| 3783 | } |
| 3784 | |
| 3785 | if (currentSignal & SIGNAL_THREAD_RELEASE) { |
| 3786 | int i, index = -1, cnt_to_dq = 0; |
| 3787 | status_t res; |
| 3788 | ALOGV("DEBUG(%s): processing SIGNAL_THREAD_RELEASE", __FUNCTION__); |
| 3789 | ALOGD("(%s):(%d) SIGNAL_THREAD_RELEASE", __FUNCTION__, selfStreamParms->streamType); |
| 3790 | |
| 3791 | if (selfThread->m_isBufferInit) { |
| 3792 | for ( i=0 ; i < selfStreamParms->numSvcBuffers; i++) { |
| 3793 | ALOGV("DEBUG(%s): checking buffer index[%d] - status(%d)", |
| 3794 | __FUNCTION__, i, selfStreamParms->svcBufStatus[i]); |
| 3795 | if (selfStreamParms->svcBufStatus[i] ==ON_DRIVER) cnt_to_dq++; |
| 3796 | } |
| 3797 | |
| 3798 | ALOGV("DEBUG(%s): calling stream(%d) streamoff (fd:%d)", __FUNCTION__, |
| 3799 | selfThread->m_index, selfStreamParms->fd); |
| 3800 | if (cam_int_streamoff(&(selfStreamParms->node)) < 0 ){ |
| 3801 | ALOGE("ERR(%s): stream off fail", __FUNCTION__); |
| 3802 | } else { |
| 3803 | m_camera_info.capture.status = false; |
| 3804 | } |
| 3805 | ALOGV("DEBUG(%s): calling stream(%d) streamoff done", __FUNCTION__, selfThread->m_index); |
| 3806 | ALOGV("DEBUG(%s): calling stream(%d) reqbuf 0 (fd:%d)", __FUNCTION__, |
| 3807 | selfThread->m_index, selfStreamParms->fd); |
| 3808 | currentNode->buffers = 0; |
| 3809 | cam_int_reqbufs(currentNode); |
| 3810 | ALOGV("DEBUG(%s): calling stream(%d) reqbuf 0 DONE(fd:%d)", __FUNCTION__, |
| 3811 | selfThread->m_index, selfStreamParms->fd); |
| 3812 | } |
| 3813 | if (selfThread->m_index == 1 && m_resizeBuf.size.s != 0) { |
| 3814 | freeCameraMemory(&m_resizeBuf, 1); |
| 3815 | } |
| 3816 | selfThread->m_isBufferInit = false; |
| 3817 | selfThread->m_index = 255; |
| 3818 | |
| 3819 | selfThread->m_releasing = false; |
| 3820 | |
| 3821 | ALOGV("DEBUG(%s): processing SIGNAL_THREAD_RELEASE DONE", __FUNCTION__); |
| 3822 | |
| 3823 | return; |
| 3824 | } |
| 3825 | |
| 3826 | return; |
| 3827 | } |
| 3828 | |
| 3829 | |
| 3830 | void ExynosCameraHWInterface2::m_streamThreadFunc(SignalDrivenThread * self) |
| 3831 | { |
| 3832 | uint32_t currentSignal = self->GetProcessingSignal(); |
| 3833 | StreamThread * selfThread = ((StreamThread*)self); |
| 3834 | stream_parameters_t *selfStreamParms = &(selfThread->m_parameters); |
| 3835 | record_parameters_t *selfRecordParms = &(selfThread->m_recordParameters); |
| 3836 | node_info_t *currentNode = &(selfStreamParms->node); |
| 3837 | |
| 3838 | ALOGV("DEBUG(%s): m_streamThreadFunc[%d] (%x)", __FUNCTION__, selfThread->m_index, currentSignal); |
| 3839 | |
| 3840 | if (currentSignal & SIGNAL_STREAM_CHANGE_PARAMETER) { |
| 3841 | ALOGV("DEBUG(%s): processing SIGNAL_STREAM_CHANGE_PARAMETER", __FUNCTION__); |
| 3842 | |
| 3843 | //Do something in Parent thread handler |
| 3844 | selfThread->applyChange(); |
| 3845 | |
| 3846 | ALOGV("DEBUG(%s): processing SIGNAL_STREAM_CHANGE_PARAMETER DONE", __FUNCTION__); |
| 3847 | } |
| 3848 | |
| 3849 | // Do something in Child thread handler |
| 3850 | // Should change function to class that inherited StreamThread class to support dynamic stream allocation |
| 3851 | if (selfStreamParms->streamType == STREAM_TYPE_DIRECT) |
| 3852 | { |
| 3853 | m_streamFunc0(self); |
| 3854 | } |
| 3855 | else if (selfStreamParms->streamType == STREAM_TYPE_INDIRECT) |
| 3856 | { |
| 3857 | m_streamFunc1(self); |
| 3858 | } |
| 3859 | |
| 3860 | if (currentSignal & SIGNAL_THREAD_RELEASE) { |
| 3861 | ALOGV("DEBUG(%s): processing SIGNAL_THREAD_RELEASE", __FUNCTION__); |
| 3862 | ALOGD("(%s):(%d) SIGNAL_THREAD_RELEASE", __FUNCTION__, selfStreamParms->streamType); |
| 3863 | |
| 3864 | //Do something in Parent thread handler |
| 3865 | |
| 3866 | ALOGV("DEBUG(%s): processing SIGNAL_THREAD_RELEASE DONE", __FUNCTION__); |
| 3867 | |
| 3868 | return; |
| 3869 | } |
| 3870 | |
Jiyoung Shin | c15a6b0 | 2012-06-05 01:08:14 -0700 | [diff] [blame] | 3871 | return; |
| 3872 | } |
| 3873 | |
Sungjoong Kang | 2d5e6ec | 2012-08-30 15:14:17 +0900 | [diff] [blame] | 3874 | bool ExynosCameraHWInterface2::m_checkThumbnailSize(int w, int h) |
| 3875 | { |
| 3876 | int sizeOfSupportList; |
| 3877 | |
| 3878 | //REAR Camera |
| 3879 | if(this->getCameraId() == 0) { |
| 3880 | sizeOfSupportList = sizeof(SUPPORT_THUMBNAIL_REAR_SIZE) / (sizeof(int)*2); |
| 3881 | |
| 3882 | for(int i = 0; i < sizeOfSupportList; i++) { |
| 3883 | if((SUPPORT_THUMBNAIL_REAR_SIZE[i][0] == w) &&(SUPPORT_THUMBNAIL_REAR_SIZE[i][1] == h)) |
| 3884 | return true; |
| 3885 | } |
| 3886 | |
| 3887 | } |
| 3888 | else { |
| 3889 | sizeOfSupportList = sizeof(SUPPORT_THUMBNAIL_FRONT_SIZE) / (sizeof(int)*2); |
| 3890 | |
| 3891 | for(int i = 0; i < sizeOfSupportList; i++) { |
| 3892 | if((SUPPORT_THUMBNAIL_FRONT_SIZE[i][0] == w) &&(SUPPORT_THUMBNAIL_FRONT_SIZE[i][1] == h)) |
| 3893 | return true; |
| 3894 | } |
| 3895 | } |
| 3896 | |
| 3897 | return false; |
| 3898 | } |
Sungjoong Kang | 13d8c7b | 2012-07-14 10:20:39 +0900 | [diff] [blame] | 3899 | bool ExynosCameraHWInterface2::yuv2Jpeg(ExynosBuffer *yuvBuf, |
| 3900 | ExynosBuffer *jpegBuf, |
| 3901 | ExynosRect *rect) |
Jiyoung Shin | c15a6b0 | 2012-06-05 01:08:14 -0700 | [diff] [blame] | 3902 | { |
Sungjoong Kang | 13d8c7b | 2012-07-14 10:20:39 +0900 | [diff] [blame] | 3903 | unsigned char *addr; |
| 3904 | |
| 3905 | ExynosJpegEncoderForCamera jpegEnc; |
| 3906 | bool ret = false; |
| 3907 | int res = 0; |
| 3908 | |
| 3909 | unsigned int *yuvSize = yuvBuf->size.extS; |
| 3910 | |
| 3911 | if (jpegEnc.create()) { |
Sungjoong Kang | 9dd63e1 | 2012-07-24 00:25:51 +0900 | [diff] [blame] | 3912 | ALOGE("ERR(%s):jpegEnc.create() fail", __FUNCTION__); |
Sungjoong Kang | 13d8c7b | 2012-07-14 10:20:39 +0900 | [diff] [blame] | 3913 | goto jpeg_encode_done; |
| 3914 | } |
| 3915 | |
| 3916 | if (jpegEnc.setQuality(100)) { |
Sungjoong Kang | 9dd63e1 | 2012-07-24 00:25:51 +0900 | [diff] [blame] | 3917 | ALOGE("ERR(%s):jpegEnc.setQuality() fail", __FUNCTION__); |
Sungjoong Kang | 13d8c7b | 2012-07-14 10:20:39 +0900 | [diff] [blame] | 3918 | goto jpeg_encode_done; |
| 3919 | } |
| 3920 | |
| 3921 | if (jpegEnc.setSize(rect->w, rect->h)) { |
Sungjoong Kang | 9dd63e1 | 2012-07-24 00:25:51 +0900 | [diff] [blame] | 3922 | ALOGE("ERR(%s):jpegEnc.setSize() fail", __FUNCTION__); |
Sungjoong Kang | 13d8c7b | 2012-07-14 10:20:39 +0900 | [diff] [blame] | 3923 | goto jpeg_encode_done; |
| 3924 | } |
| 3925 | ALOGV("%s : width = %d , height = %d\n", __FUNCTION__, rect->w, rect->h); |
| 3926 | |
| 3927 | if (jpegEnc.setColorFormat(rect->colorFormat)) { |
Sungjoong Kang | 9dd63e1 | 2012-07-24 00:25:51 +0900 | [diff] [blame] | 3928 | ALOGE("ERR(%s):jpegEnc.setColorFormat() fail", __FUNCTION__); |
Sungjoong Kang | 13d8c7b | 2012-07-14 10:20:39 +0900 | [diff] [blame] | 3929 | goto jpeg_encode_done; |
| 3930 | } |
Sungjoong Kang | 13d8c7b | 2012-07-14 10:20:39 +0900 | [diff] [blame] | 3931 | |
| 3932 | if (jpegEnc.setJpegFormat(V4L2_PIX_FMT_JPEG_422)) { |
Sungjoong Kang | 9dd63e1 | 2012-07-24 00:25:51 +0900 | [diff] [blame] | 3933 | ALOGE("ERR(%s):jpegEnc.setJpegFormat() fail", __FUNCTION__); |
Sungjoong Kang | 13d8c7b | 2012-07-14 10:20:39 +0900 | [diff] [blame] | 3934 | goto jpeg_encode_done; |
| 3935 | } |
Sungjoong Kang | 13d8c7b | 2012-07-14 10:20:39 +0900 | [diff] [blame] | 3936 | |
Sungjoong Kang | 2d5e6ec | 2012-08-30 15:14:17 +0900 | [diff] [blame] | 3937 | if((m_jpegMetadata.ctl.jpeg.thumbnailSize[0] != 0) && (m_jpegMetadata.ctl.jpeg.thumbnailSize[1] != 0)) { |
| 3938 | mExifInfo.enableThumb = true; |
| 3939 | if(!m_checkThumbnailSize(m_jpegMetadata.ctl.jpeg.thumbnailSize[0], m_jpegMetadata.ctl.jpeg.thumbnailSize[1])) { |
| 3940 | //default value |
| 3941 | m_thumbNailW = SUPPORT_THUMBNAIL_REAR_SIZE[0][0]; |
| 3942 | m_thumbNailH = SUPPORT_THUMBNAIL_REAR_SIZE[0][1]; |
| 3943 | } else { |
| 3944 | m_thumbNailW = m_jpegMetadata.ctl.jpeg.thumbnailSize[0]; |
| 3945 | m_thumbNailH = m_jpegMetadata.ctl.jpeg.thumbnailSize[1]; |
| 3946 | } |
Sungjoong Kang | 13d8c7b | 2012-07-14 10:20:39 +0900 | [diff] [blame] | 3947 | |
Sungjoong Kang | 2d5e6ec | 2012-08-30 15:14:17 +0900 | [diff] [blame] | 3948 | ALOGV("(%s) m_thumbNailW = %d, m_thumbNailH = %d", __FUNCTION__, m_thumbNailW, m_thumbNailH); |
| 3949 | |
| 3950 | } else { |
| 3951 | mExifInfo.enableThumb = false; |
| 3952 | } |
| 3953 | |
| 3954 | if (jpegEnc.setThumbnailSize(m_thumbNailW, m_thumbNailH)) { |
| 3955 | ALOGE("ERR(%s):jpegEnc.setThumbnailSize(%d, %d) fail", __FUNCTION__, m_thumbNailH, m_thumbNailH); |
Sungjoong Kang | eed7ed1 | 2012-08-23 16:35:08 -0700 | [diff] [blame] | 3956 | goto jpeg_encode_done; |
| 3957 | } |
| 3958 | |
Sungjoong Kang | 2d5e6ec | 2012-08-30 15:14:17 +0900 | [diff] [blame] | 3959 | ALOGV("(%s):jpegEnc.setThumbnailSize(%d, %d) ", __FUNCTION__, m_thumbNailW, m_thumbNailW); |
Sungjoong Kang | eed7ed1 | 2012-08-23 16:35:08 -0700 | [diff] [blame] | 3960 | if (jpegEnc.setThumbnailQuality(50)) { |
| 3961 | ALOGE("ERR(%s):jpegEnc.setThumbnailQuality fail", __FUNCTION__); |
| 3962 | goto jpeg_encode_done; |
| 3963 | } |
| 3964 | |
| 3965 | m_setExifChangedAttribute(&mExifInfo, rect, &m_jpegMetadata); |
Sungjoong Kang | 9dd63e1 | 2012-07-24 00:25:51 +0900 | [diff] [blame] | 3966 | ALOGV("DEBUG(%s):calling jpegEnc.setInBuf() yuvSize(%d)", __FUNCTION__, *yuvSize); |
Sungjoong Kang | eed7ed1 | 2012-08-23 16:35:08 -0700 | [diff] [blame] | 3967 | if (jpegEnc.setInBuf((int *)&(yuvBuf->fd.fd), &(yuvBuf->virt.p), (int *)yuvSize)) { |
Sungjoong Kang | 9dd63e1 | 2012-07-24 00:25:51 +0900 | [diff] [blame] | 3968 | ALOGE("ERR(%s):jpegEnc.setInBuf() fail", __FUNCTION__); |
Sungjoong Kang | 13d8c7b | 2012-07-14 10:20:39 +0900 | [diff] [blame] | 3969 | goto jpeg_encode_done; |
| 3970 | } |
Sungjoong Kang | eed7ed1 | 2012-08-23 16:35:08 -0700 | [diff] [blame] | 3971 | if (jpegEnc.setOutBuf(jpegBuf->fd.fd, jpegBuf->virt.p, jpegBuf->size.extS[0] + jpegBuf->size.extS[1] + jpegBuf->size.extS[2])) { |
Sungjoong Kang | 9dd63e1 | 2012-07-24 00:25:51 +0900 | [diff] [blame] | 3972 | ALOGE("ERR(%s):jpegEnc.setOutBuf() fail", __FUNCTION__); |
Sungjoong Kang | 13d8c7b | 2012-07-14 10:20:39 +0900 | [diff] [blame] | 3973 | goto jpeg_encode_done; |
| 3974 | } |
Sungjoong Kang | 13d8c7b | 2012-07-14 10:20:39 +0900 | [diff] [blame] | 3975 | |
| 3976 | if (jpegEnc.updateConfig()) { |
Sungjoong Kang | 9dd63e1 | 2012-07-24 00:25:51 +0900 | [diff] [blame] | 3977 | ALOGE("ERR(%s):jpegEnc.updateConfig() fail", __FUNCTION__); |
Sungjoong Kang | 13d8c7b | 2012-07-14 10:20:39 +0900 | [diff] [blame] | 3978 | goto jpeg_encode_done; |
| 3979 | } |
| 3980 | |
Sungjoong Kang | eed7ed1 | 2012-08-23 16:35:08 -0700 | [diff] [blame] | 3981 | if (res = jpegEnc.encode((int *)&jpegBuf->size.s, &mExifInfo)) { |
Sungjoong Kang | 9dd63e1 | 2012-07-24 00:25:51 +0900 | [diff] [blame] | 3982 | ALOGE("ERR(%s):jpegEnc.encode() fail ret(%d)", __FUNCTION__, res); |
Sungjoong Kang | 13d8c7b | 2012-07-14 10:20:39 +0900 | [diff] [blame] | 3983 | goto jpeg_encode_done; |
| 3984 | } |
| 3985 | |
| 3986 | ret = true; |
| 3987 | |
| 3988 | jpeg_encode_done: |
| 3989 | |
| 3990 | if (jpegEnc.flagCreate() == true) |
| 3991 | jpegEnc.destroy(); |
| 3992 | |
| 3993 | return ret; |
Jiyoung Shin | c15a6b0 | 2012-06-05 01:08:14 -0700 | [diff] [blame] | 3994 | } |
| 3995 | |
Sungjoong Kang | 8e2c2fd | 2012-08-27 00:02:22 -0700 | [diff] [blame] | 3996 | void ExynosCameraHWInterface2::OnAfTriggerStart(int id) |
| 3997 | { |
| 3998 | m_afPendingTriggerId = id; |
Sungjoong Kang | cd13bb7 | 2012-08-28 13:05:01 -0700 | [diff] [blame] | 3999 | m_afModeWaitingCnt = 3; |
Sungjoong Kang | 8e2c2fd | 2012-08-27 00:02:22 -0700 | [diff] [blame] | 4000 | } |
Sungjoong Kang | 13d8c7b | 2012-07-14 10:20:39 +0900 | [diff] [blame] | 4001 | |
Sungjoong Kang | 0f26b20 | 2012-08-17 15:43:12 -0700 | [diff] [blame] | 4002 | void ExynosCameraHWInterface2::OnAfTrigger(int id) |
| 4003 | { |
Sungjoong Kang | 8e2c2fd | 2012-08-27 00:02:22 -0700 | [diff] [blame] | 4004 | m_afTriggerId = id; |
Younghwan Joo | 6f19b6c | 2012-08-30 13:56:53 -0700 | [diff] [blame] | 4005 | |
Sungjoong Kang | 0f26b20 | 2012-08-17 15:43:12 -0700 | [diff] [blame] | 4006 | switch (m_afMode) { |
| 4007 | case AA_AFMODE_AUTO: |
| 4008 | case AA_AFMODE_MACRO: |
Sungjoong Kang | 8e2c2fd | 2012-08-27 00:02:22 -0700 | [diff] [blame] | 4009 | case AA_AFMODE_OFF: |
Sungjoong Kang | 0f26b20 | 2012-08-17 15:43:12 -0700 | [diff] [blame] | 4010 | OnAfTriggerAutoMacro(id); |
| 4011 | break; |
| 4012 | case AA_AFMODE_CONTINUOUS_VIDEO: |
| 4013 | OnAfTriggerCAFVideo(id); |
| 4014 | break; |
| 4015 | case AA_AFMODE_CONTINUOUS_PICTURE: |
| 4016 | OnAfTriggerCAFPicture(id); |
| 4017 | break; |
Sungjoong Kang | 8e2c2fd | 2012-08-27 00:02:22 -0700 | [diff] [blame] | 4018 | |
Sungjoong Kang | 0f26b20 | 2012-08-17 15:43:12 -0700 | [diff] [blame] | 4019 | default: |
| 4020 | break; |
| 4021 | } |
| 4022 | } |
| 4023 | |
| 4024 | void ExynosCameraHWInterface2::OnAfTriggerAutoMacro(int id) |
| 4025 | { |
| 4026 | int nextState = NO_TRANSITION; |
Sungjoong Kang | 0f26b20 | 2012-08-17 15:43:12 -0700 | [diff] [blame] | 4027 | |
| 4028 | switch (m_afState) { |
| 4029 | case HAL_AFSTATE_INACTIVE: |
| 4030 | nextState = HAL_AFSTATE_NEEDS_COMMAND; |
| 4031 | m_IsAfTriggerRequired = true; |
| 4032 | break; |
| 4033 | case HAL_AFSTATE_NEEDS_COMMAND: |
| 4034 | nextState = NO_TRANSITION; |
| 4035 | break; |
| 4036 | case HAL_AFSTATE_STARTED: |
| 4037 | nextState = NO_TRANSITION; |
| 4038 | break; |
| 4039 | case HAL_AFSTATE_SCANNING: |
| 4040 | nextState = NO_TRANSITION; |
| 4041 | break; |
| 4042 | case HAL_AFSTATE_LOCKED: |
| 4043 | nextState = HAL_AFSTATE_NEEDS_COMMAND; |
| 4044 | m_IsAfTriggerRequired = true; |
| 4045 | break; |
| 4046 | case HAL_AFSTATE_FAILED: |
| 4047 | nextState = HAL_AFSTATE_NEEDS_COMMAND; |
| 4048 | m_IsAfTriggerRequired = true; |
| 4049 | break; |
| 4050 | default: |
| 4051 | break; |
| 4052 | } |
| 4053 | ALOGV("(%s): State (%d) -> (%d)", __FUNCTION__, m_afState, nextState); |
| 4054 | if (nextState != NO_TRANSITION) |
| 4055 | m_afState = nextState; |
| 4056 | } |
| 4057 | |
| 4058 | void ExynosCameraHWInterface2::OnAfTriggerCAFPicture(int id) |
| 4059 | { |
| 4060 | int nextState = NO_TRANSITION; |
Sungjoong Kang | 0f26b20 | 2012-08-17 15:43:12 -0700 | [diff] [blame] | 4061 | |
| 4062 | switch (m_afState) { |
| 4063 | case HAL_AFSTATE_INACTIVE: |
| 4064 | nextState = HAL_AFSTATE_FAILED; |
| 4065 | SetAfStateForService(ANDROID_CONTROL_AF_STATE_NOT_FOCUSED_LOCKED); |
| 4066 | break; |
| 4067 | case HAL_AFSTATE_NEEDS_COMMAND: |
| 4068 | // not used |
| 4069 | break; |
| 4070 | case HAL_AFSTATE_STARTED: |
| 4071 | nextState = HAL_AFSTATE_NEEDS_DETERMINATION; |
Sungjoong Kang | 36c106c | 2012-08-23 17:38:20 -0700 | [diff] [blame] | 4072 | m_AfHwStateFailed = false; |
Sungjoong Kang | 0f26b20 | 2012-08-17 15:43:12 -0700 | [diff] [blame] | 4073 | break; |
| 4074 | case HAL_AFSTATE_SCANNING: |
| 4075 | nextState = HAL_AFSTATE_NEEDS_DETERMINATION; |
Sungjoong Kang | 36c106c | 2012-08-23 17:38:20 -0700 | [diff] [blame] | 4076 | m_AfHwStateFailed = false; |
Sungjoong Kang | 0f26b20 | 2012-08-17 15:43:12 -0700 | [diff] [blame] | 4077 | break; |
| 4078 | case HAL_AFSTATE_NEEDS_DETERMINATION: |
| 4079 | nextState = NO_TRANSITION; |
| 4080 | break; |
| 4081 | case HAL_AFSTATE_PASSIVE_FOCUSED: |
| 4082 | m_IsAfLockRequired = true; |
Sungjoong Kang | 36c106c | 2012-08-23 17:38:20 -0700 | [diff] [blame] | 4083 | if (m_AfHwStateFailed) { |
| 4084 | ALOGV("(%s): LAST : fail", __FUNCTION__); |
| 4085 | SetAfStateForService(ANDROID_CONTROL_AF_STATE_NOT_FOCUSED_LOCKED); |
| 4086 | nextState = HAL_AFSTATE_FAILED; |
| 4087 | } |
| 4088 | else { |
| 4089 | ALOGV("(%s): LAST : success", __FUNCTION__); |
| 4090 | SetAfStateForService(ANDROID_CONTROL_AF_STATE_FOCUSED_LOCKED); |
| 4091 | nextState = HAL_AFSTATE_LOCKED; |
| 4092 | } |
| 4093 | m_AfHwStateFailed = false; |
Sungjoong Kang | 0f26b20 | 2012-08-17 15:43:12 -0700 | [diff] [blame] | 4094 | break; |
| 4095 | case HAL_AFSTATE_LOCKED: |
| 4096 | nextState = NO_TRANSITION; |
| 4097 | break; |
| 4098 | case HAL_AFSTATE_FAILED: |
| 4099 | nextState = NO_TRANSITION; |
| 4100 | break; |
| 4101 | default: |
| 4102 | break; |
| 4103 | } |
| 4104 | ALOGV("(%s): State (%d) -> (%d)", __FUNCTION__, m_afState, nextState); |
| 4105 | if (nextState != NO_TRANSITION) |
| 4106 | m_afState = nextState; |
| 4107 | } |
| 4108 | |
| 4109 | |
| 4110 | void ExynosCameraHWInterface2::OnAfTriggerCAFVideo(int id) |
| 4111 | { |
| 4112 | int nextState = NO_TRANSITION; |
Sungjoong Kang | 0f26b20 | 2012-08-17 15:43:12 -0700 | [diff] [blame] | 4113 | |
| 4114 | switch (m_afState) { |
| 4115 | case HAL_AFSTATE_INACTIVE: |
| 4116 | nextState = HAL_AFSTATE_FAILED; |
| 4117 | SetAfStateForService(ANDROID_CONTROL_AF_STATE_NOT_FOCUSED_LOCKED); |
| 4118 | break; |
| 4119 | case HAL_AFSTATE_NEEDS_COMMAND: |
| 4120 | // not used |
| 4121 | break; |
| 4122 | case HAL_AFSTATE_STARTED: |
| 4123 | m_IsAfLockRequired = true; |
| 4124 | nextState = HAL_AFSTATE_FAILED; |
| 4125 | SetAfStateForService(ANDROID_CONTROL_AF_STATE_NOT_FOCUSED_LOCKED); |
| 4126 | break; |
| 4127 | case HAL_AFSTATE_SCANNING: |
| 4128 | m_IsAfLockRequired = true; |
| 4129 | nextState = HAL_AFSTATE_FAILED; |
| 4130 | SetAfStateForService(ANDROID_CONTROL_AF_STATE_NOT_FOCUSED_LOCKED); |
| 4131 | break; |
| 4132 | case HAL_AFSTATE_NEEDS_DETERMINATION: |
| 4133 | // not used |
| 4134 | break; |
| 4135 | case HAL_AFSTATE_PASSIVE_FOCUSED: |
| 4136 | m_IsAfLockRequired = true; |
| 4137 | SetAfStateForService(ANDROID_CONTROL_AF_STATE_FOCUSED_LOCKED); |
| 4138 | nextState = HAL_AFSTATE_LOCKED; |
| 4139 | break; |
| 4140 | case HAL_AFSTATE_LOCKED: |
| 4141 | nextState = NO_TRANSITION; |
| 4142 | break; |
| 4143 | case HAL_AFSTATE_FAILED: |
| 4144 | nextState = NO_TRANSITION; |
| 4145 | break; |
| 4146 | default: |
| 4147 | break; |
| 4148 | } |
| 4149 | ALOGV("(%s): State (%d) -> (%d)", __FUNCTION__, m_afState, nextState); |
| 4150 | if (nextState != NO_TRANSITION) |
| 4151 | m_afState = nextState; |
| 4152 | } |
| 4153 | |
| 4154 | void ExynosCameraHWInterface2::OnAfNotification(enum aa_afstate noti) |
| 4155 | { |
| 4156 | switch (m_afMode) { |
| 4157 | case AA_AFMODE_AUTO: |
| 4158 | case AA_AFMODE_MACRO: |
| 4159 | OnAfNotificationAutoMacro(noti); |
| 4160 | break; |
| 4161 | case AA_AFMODE_CONTINUOUS_VIDEO: |
| 4162 | OnAfNotificationCAFVideo(noti); |
| 4163 | break; |
| 4164 | case AA_AFMODE_CONTINUOUS_PICTURE: |
| 4165 | OnAfNotificationCAFPicture(noti); |
| 4166 | break; |
| 4167 | case AA_AFMODE_OFF: |
| 4168 | default: |
| 4169 | break; |
| 4170 | } |
| 4171 | } |
| 4172 | |
| 4173 | void ExynosCameraHWInterface2::OnAfNotificationAutoMacro(enum aa_afstate noti) |
| 4174 | { |
| 4175 | int nextState = NO_TRANSITION; |
| 4176 | bool bWrongTransition = false; |
| 4177 | |
| 4178 | if (m_afState == HAL_AFSTATE_INACTIVE || m_afState == HAL_AFSTATE_NEEDS_COMMAND) { |
| 4179 | switch (noti) { |
| 4180 | case AA_AFSTATE_INACTIVE: |
| 4181 | case AA_AFSTATE_ACTIVE_SCAN: |
| 4182 | case AA_AFSTATE_AF_ACQUIRED_FOCUS: |
| 4183 | case AA_AFSTATE_AF_FAILED_FOCUS: |
| 4184 | default: |
| 4185 | nextState = NO_TRANSITION; |
| 4186 | break; |
| 4187 | } |
| 4188 | } |
| 4189 | else if (m_afState == HAL_AFSTATE_STARTED) { |
| 4190 | switch (noti) { |
| 4191 | case AA_AFSTATE_INACTIVE: |
| 4192 | nextState = NO_TRANSITION; |
| 4193 | break; |
| 4194 | case AA_AFSTATE_ACTIVE_SCAN: |
| 4195 | nextState = HAL_AFSTATE_SCANNING; |
| 4196 | SetAfStateForService(ANDROID_CONTROL_AF_STATE_ACTIVE_SCAN); |
| 4197 | break; |
| 4198 | case AA_AFSTATE_AF_ACQUIRED_FOCUS: |
| 4199 | nextState = NO_TRANSITION; |
| 4200 | break; |
| 4201 | case AA_AFSTATE_AF_FAILED_FOCUS: |
| 4202 | nextState = NO_TRANSITION; |
| 4203 | break; |
| 4204 | default: |
| 4205 | bWrongTransition = true; |
| 4206 | break; |
| 4207 | } |
| 4208 | } |
| 4209 | else if (m_afState == HAL_AFSTATE_SCANNING) { |
| 4210 | switch (noti) { |
| 4211 | case AA_AFSTATE_INACTIVE: |
| 4212 | bWrongTransition = true; |
| 4213 | break; |
| 4214 | case AA_AFSTATE_ACTIVE_SCAN: |
| 4215 | nextState = NO_TRANSITION; |
| 4216 | break; |
| 4217 | case AA_AFSTATE_AF_ACQUIRED_FOCUS: |
| 4218 | nextState = HAL_AFSTATE_LOCKED; |
| 4219 | SetAfStateForService(ANDROID_CONTROL_AF_STATE_FOCUSED_LOCKED); |
| 4220 | break; |
| 4221 | case AA_AFSTATE_AF_FAILED_FOCUS: |
| 4222 | nextState = HAL_AFSTATE_FAILED; |
| 4223 | SetAfStateForService(ANDROID_CONTROL_AF_STATE_NOT_FOCUSED_LOCKED); |
| 4224 | break; |
| 4225 | default: |
| 4226 | bWrongTransition = true; |
| 4227 | break; |
| 4228 | } |
| 4229 | } |
| 4230 | else if (m_afState == HAL_AFSTATE_LOCKED) { |
| 4231 | switch (noti) { |
| 4232 | case AA_AFSTATE_INACTIVE: |
| 4233 | case AA_AFSTATE_ACTIVE_SCAN: |
| 4234 | bWrongTransition = true; |
| 4235 | break; |
| 4236 | case AA_AFSTATE_AF_ACQUIRED_FOCUS: |
Younghwan Joo | 6f19b6c | 2012-08-30 13:56:53 -0700 | [diff] [blame] | 4237 | // Flash off if flash mode is available. |
| 4238 | if (m_afFlashEnableFlg) |
| 4239 | m_afFlashCnt = IF_FLASH_AF_OFF; |
Sungjoong Kang | 0f26b20 | 2012-08-17 15:43:12 -0700 | [diff] [blame] | 4240 | nextState = NO_TRANSITION; |
| 4241 | break; |
| 4242 | case AA_AFSTATE_AF_FAILED_FOCUS: |
| 4243 | default: |
| 4244 | bWrongTransition = true; |
| 4245 | break; |
| 4246 | } |
| 4247 | } |
| 4248 | else if (m_afState == HAL_AFSTATE_FAILED) { |
| 4249 | switch (noti) { |
| 4250 | case AA_AFSTATE_INACTIVE: |
| 4251 | case AA_AFSTATE_ACTIVE_SCAN: |
| 4252 | case AA_AFSTATE_AF_ACQUIRED_FOCUS: |
| 4253 | bWrongTransition = true; |
| 4254 | break; |
| 4255 | case AA_AFSTATE_AF_FAILED_FOCUS: |
Younghwan Joo | 6f19b6c | 2012-08-30 13:56:53 -0700 | [diff] [blame] | 4256 | // Flash off if flash mode is available. |
| 4257 | if (m_afFlashEnableFlg) |
| 4258 | m_afFlashCnt = IF_FLASH_AF_OFF; |
Sungjoong Kang | 0f26b20 | 2012-08-17 15:43:12 -0700 | [diff] [blame] | 4259 | nextState = NO_TRANSITION; |
| 4260 | break; |
| 4261 | default: |
| 4262 | bWrongTransition = true; |
| 4263 | break; |
| 4264 | } |
| 4265 | } |
| 4266 | if (bWrongTransition) { |
| 4267 | ALOGV("(%s): Wrong Transition state(%d) noti(%d)", __FUNCTION__, m_afState, noti); |
| 4268 | return; |
| 4269 | } |
| 4270 | ALOGV("(%s): State (%d) -> (%d) by (%d)", __FUNCTION__, m_afState, nextState, noti); |
| 4271 | if (nextState != NO_TRANSITION) |
| 4272 | m_afState = nextState; |
| 4273 | } |
| 4274 | |
| 4275 | void ExynosCameraHWInterface2::OnAfNotificationCAFPicture(enum aa_afstate noti) |
| 4276 | { |
| 4277 | int nextState = NO_TRANSITION; |
| 4278 | bool bWrongTransition = false; |
| 4279 | |
| 4280 | if (m_afState == HAL_AFSTATE_INACTIVE) { |
| 4281 | switch (noti) { |
| 4282 | case AA_AFSTATE_INACTIVE: |
| 4283 | case AA_AFSTATE_ACTIVE_SCAN: |
| 4284 | case AA_AFSTATE_AF_ACQUIRED_FOCUS: |
| 4285 | case AA_AFSTATE_AF_FAILED_FOCUS: |
| 4286 | default: |
| 4287 | nextState = NO_TRANSITION; |
| 4288 | break; |
| 4289 | } |
| 4290 | } |
| 4291 | else if (m_afState == HAL_AFSTATE_STARTED) { |
| 4292 | switch (noti) { |
| 4293 | case AA_AFSTATE_INACTIVE: |
| 4294 | nextState = NO_TRANSITION; |
| 4295 | break; |
| 4296 | case AA_AFSTATE_ACTIVE_SCAN: |
| 4297 | nextState = HAL_AFSTATE_SCANNING; |
| 4298 | SetAfStateForService(ANDROID_CONTROL_AF_STATE_PASSIVE_SCAN); |
| 4299 | break; |
| 4300 | case AA_AFSTATE_AF_ACQUIRED_FOCUS: |
| 4301 | nextState = HAL_AFSTATE_PASSIVE_FOCUSED; |
| 4302 | SetAfStateForService(ANDROID_CONTROL_AF_STATE_PASSIVE_FOCUSED); |
| 4303 | break; |
| 4304 | case AA_AFSTATE_AF_FAILED_FOCUS: |
Sungjoong Kang | cd13bb7 | 2012-08-28 13:05:01 -0700 | [diff] [blame] | 4305 | //nextState = HAL_AFSTATE_FAILED; |
| 4306 | //SetAfStateForService(ANDROID_CONTROL_AF_STATE_NOT_FOCUSED_LOCKED); |
| 4307 | nextState = NO_TRANSITION; |
Sungjoong Kang | 0f26b20 | 2012-08-17 15:43:12 -0700 | [diff] [blame] | 4308 | break; |
| 4309 | default: |
| 4310 | bWrongTransition = true; |
| 4311 | break; |
| 4312 | } |
| 4313 | } |
| 4314 | else if (m_afState == HAL_AFSTATE_SCANNING) { |
| 4315 | switch (noti) { |
| 4316 | case AA_AFSTATE_INACTIVE: |
Sungjoong Kang | 36c106c | 2012-08-23 17:38:20 -0700 | [diff] [blame] | 4317 | nextState = NO_TRANSITION; |
Sungjoong Kang | 0f26b20 | 2012-08-17 15:43:12 -0700 | [diff] [blame] | 4318 | break; |
| 4319 | case AA_AFSTATE_ACTIVE_SCAN: |
| 4320 | nextState = NO_TRANSITION; |
Sungjoong Kang | 36c106c | 2012-08-23 17:38:20 -0700 | [diff] [blame] | 4321 | m_AfHwStateFailed = false; |
Sungjoong Kang | 0f26b20 | 2012-08-17 15:43:12 -0700 | [diff] [blame] | 4322 | break; |
| 4323 | case AA_AFSTATE_AF_ACQUIRED_FOCUS: |
| 4324 | nextState = HAL_AFSTATE_PASSIVE_FOCUSED; |
Sungjoong Kang | 36c106c | 2012-08-23 17:38:20 -0700 | [diff] [blame] | 4325 | m_AfHwStateFailed = false; |
Sungjoong Kang | 0f26b20 | 2012-08-17 15:43:12 -0700 | [diff] [blame] | 4326 | SetAfStateForService(ANDROID_CONTROL_AF_STATE_PASSIVE_FOCUSED); |
| 4327 | break; |
| 4328 | case AA_AFSTATE_AF_FAILED_FOCUS: |
Sungjoong Kang | 36c106c | 2012-08-23 17:38:20 -0700 | [diff] [blame] | 4329 | nextState = HAL_AFSTATE_PASSIVE_FOCUSED; |
| 4330 | m_AfHwStateFailed = true; |
| 4331 | SetAfStateForService(ANDROID_CONTROL_AF_STATE_PASSIVE_FOCUSED); |
Sungjoong Kang | 0f26b20 | 2012-08-17 15:43:12 -0700 | [diff] [blame] | 4332 | break; |
| 4333 | default: |
| 4334 | bWrongTransition = true; |
| 4335 | break; |
| 4336 | } |
| 4337 | } |
| 4338 | else if (m_afState == HAL_AFSTATE_PASSIVE_FOCUSED) { |
| 4339 | switch (noti) { |
| 4340 | case AA_AFSTATE_INACTIVE: |
Sungjoong Kang | 36c106c | 2012-08-23 17:38:20 -0700 | [diff] [blame] | 4341 | nextState = NO_TRANSITION; |
Sungjoong Kang | 0f26b20 | 2012-08-17 15:43:12 -0700 | [diff] [blame] | 4342 | break; |
| 4343 | case AA_AFSTATE_ACTIVE_SCAN: |
| 4344 | nextState = HAL_AFSTATE_SCANNING; |
Sungjoong Kang | 36c106c | 2012-08-23 17:38:20 -0700 | [diff] [blame] | 4345 | m_AfHwStateFailed = false; |
Sungjoong Kang | 0f26b20 | 2012-08-17 15:43:12 -0700 | [diff] [blame] | 4346 | SetAfStateForService(ANDROID_CONTROL_AF_STATE_PASSIVE_SCAN); |
| 4347 | break; |
| 4348 | case AA_AFSTATE_AF_ACQUIRED_FOCUS: |
| 4349 | nextState = NO_TRANSITION; |
Sungjoong Kang | 36c106c | 2012-08-23 17:38:20 -0700 | [diff] [blame] | 4350 | m_AfHwStateFailed = false; |
Sungjoong Kang | 0f26b20 | 2012-08-17 15:43:12 -0700 | [diff] [blame] | 4351 | break; |
| 4352 | case AA_AFSTATE_AF_FAILED_FOCUS: |
Sungjoong Kang | 36c106c | 2012-08-23 17:38:20 -0700 | [diff] [blame] | 4353 | nextState = NO_TRANSITION; |
| 4354 | m_AfHwStateFailed = true; |
Sungjoong Kang | 0f26b20 | 2012-08-17 15:43:12 -0700 | [diff] [blame] | 4355 | break; |
| 4356 | default: |
| 4357 | bWrongTransition = true; |
| 4358 | break; |
| 4359 | } |
| 4360 | } |
| 4361 | else if (m_afState == HAL_AFSTATE_NEEDS_DETERMINATION) { |
| 4362 | switch (noti) { |
| 4363 | case AA_AFSTATE_INACTIVE: |
Sungjoong Kang | 36c106c | 2012-08-23 17:38:20 -0700 | [diff] [blame] | 4364 | nextState = NO_TRANSITION; |
Sungjoong Kang | 0f26b20 | 2012-08-17 15:43:12 -0700 | [diff] [blame] | 4365 | break; |
| 4366 | case AA_AFSTATE_ACTIVE_SCAN: |
| 4367 | nextState = NO_TRANSITION; |
| 4368 | break; |
| 4369 | case AA_AFSTATE_AF_ACQUIRED_FOCUS: |
| 4370 | m_IsAfLockRequired = true; |
| 4371 | nextState = HAL_AFSTATE_LOCKED; |
| 4372 | SetAfStateForService(ANDROID_CONTROL_AF_STATE_FOCUSED_LOCKED); |
| 4373 | break; |
| 4374 | case AA_AFSTATE_AF_FAILED_FOCUS: |
| 4375 | m_IsAfLockRequired = true; |
| 4376 | nextState = HAL_AFSTATE_FAILED; |
| 4377 | SetAfStateForService(ANDROID_CONTROL_AF_STATE_NOT_FOCUSED_LOCKED); |
| 4378 | break; |
| 4379 | default: |
| 4380 | bWrongTransition = true; |
| 4381 | break; |
| 4382 | } |
| 4383 | } |
| 4384 | else if (m_afState == HAL_AFSTATE_LOCKED) { |
| 4385 | switch (noti) { |
| 4386 | case AA_AFSTATE_INACTIVE: |
| 4387 | nextState = NO_TRANSITION; |
| 4388 | break; |
| 4389 | case AA_AFSTATE_ACTIVE_SCAN: |
| 4390 | bWrongTransition = true; |
| 4391 | break; |
| 4392 | case AA_AFSTATE_AF_ACQUIRED_FOCUS: |
| 4393 | nextState = NO_TRANSITION; |
| 4394 | break; |
| 4395 | case AA_AFSTATE_AF_FAILED_FOCUS: |
| 4396 | default: |
| 4397 | bWrongTransition = true; |
| 4398 | break; |
| 4399 | } |
| 4400 | } |
| 4401 | else if (m_afState == HAL_AFSTATE_FAILED) { |
| 4402 | switch (noti) { |
| 4403 | case AA_AFSTATE_INACTIVE: |
Sungjoong Kang | 36c106c | 2012-08-23 17:38:20 -0700 | [diff] [blame] | 4404 | bWrongTransition = true; |
| 4405 | break; |
Sungjoong Kang | 0f26b20 | 2012-08-17 15:43:12 -0700 | [diff] [blame] | 4406 | case AA_AFSTATE_ACTIVE_SCAN: |
Sungjoong Kang | 36c106c | 2012-08-23 17:38:20 -0700 | [diff] [blame] | 4407 | nextState = HAL_AFSTATE_SCANNING; |
| 4408 | break; |
Sungjoong Kang | 0f26b20 | 2012-08-17 15:43:12 -0700 | [diff] [blame] | 4409 | case AA_AFSTATE_AF_ACQUIRED_FOCUS: |
| 4410 | bWrongTransition = true; |
| 4411 | break; |
| 4412 | case AA_AFSTATE_AF_FAILED_FOCUS: |
| 4413 | nextState = NO_TRANSITION; |
| 4414 | break; |
| 4415 | default: |
| 4416 | bWrongTransition = true; |
| 4417 | break; |
| 4418 | } |
| 4419 | } |
| 4420 | if (bWrongTransition) { |
| 4421 | ALOGV("(%s): Wrong Transition state(%d) noti(%d)", __FUNCTION__, m_afState, noti); |
| 4422 | return; |
| 4423 | } |
| 4424 | ALOGV("(%s): State (%d) -> (%d) by (%d)", __FUNCTION__, m_afState, nextState, noti); |
| 4425 | if (nextState != NO_TRANSITION) |
| 4426 | m_afState = nextState; |
| 4427 | } |
| 4428 | |
| 4429 | void ExynosCameraHWInterface2::OnAfNotificationCAFVideo(enum aa_afstate noti) |
| 4430 | { |
| 4431 | int nextState = NO_TRANSITION; |
| 4432 | bool bWrongTransition = false; |
| 4433 | |
| 4434 | if (m_afState == HAL_AFSTATE_INACTIVE) { |
| 4435 | switch (noti) { |
| 4436 | case AA_AFSTATE_INACTIVE: |
| 4437 | case AA_AFSTATE_ACTIVE_SCAN: |
| 4438 | case AA_AFSTATE_AF_ACQUIRED_FOCUS: |
| 4439 | case AA_AFSTATE_AF_FAILED_FOCUS: |
| 4440 | default: |
| 4441 | nextState = NO_TRANSITION; |
| 4442 | break; |
| 4443 | } |
| 4444 | } |
| 4445 | else if (m_afState == HAL_AFSTATE_STARTED) { |
| 4446 | switch (noti) { |
| 4447 | case AA_AFSTATE_INACTIVE: |
| 4448 | nextState = NO_TRANSITION; |
| 4449 | break; |
| 4450 | case AA_AFSTATE_ACTIVE_SCAN: |
| 4451 | nextState = HAL_AFSTATE_SCANNING; |
| 4452 | SetAfStateForService(ANDROID_CONTROL_AF_STATE_PASSIVE_SCAN); |
| 4453 | break; |
| 4454 | case AA_AFSTATE_AF_ACQUIRED_FOCUS: |
| 4455 | nextState = HAL_AFSTATE_PASSIVE_FOCUSED; |
| 4456 | SetAfStateForService(ANDROID_CONTROL_AF_STATE_PASSIVE_FOCUSED); |
| 4457 | break; |
| 4458 | case AA_AFSTATE_AF_FAILED_FOCUS: |
| 4459 | nextState = HAL_AFSTATE_FAILED; |
| 4460 | SetAfStateForService(ANDROID_CONTROL_AF_STATE_NOT_FOCUSED_LOCKED); |
| 4461 | break; |
| 4462 | default: |
| 4463 | bWrongTransition = true; |
| 4464 | break; |
| 4465 | } |
| 4466 | } |
| 4467 | else if (m_afState == HAL_AFSTATE_SCANNING) { |
| 4468 | switch (noti) { |
| 4469 | case AA_AFSTATE_INACTIVE: |
| 4470 | bWrongTransition = true; |
| 4471 | break; |
| 4472 | case AA_AFSTATE_ACTIVE_SCAN: |
| 4473 | nextState = NO_TRANSITION; |
| 4474 | break; |
| 4475 | case AA_AFSTATE_AF_ACQUIRED_FOCUS: |
| 4476 | nextState = HAL_AFSTATE_PASSIVE_FOCUSED; |
| 4477 | SetAfStateForService(ANDROID_CONTROL_AF_STATE_PASSIVE_FOCUSED); |
| 4478 | break; |
| 4479 | case AA_AFSTATE_AF_FAILED_FOCUS: |
| 4480 | nextState = NO_TRANSITION; |
Sungjoong Kang | 36c106c | 2012-08-23 17:38:20 -0700 | [diff] [blame] | 4481 | m_IsAfTriggerRequired = true; |
Sungjoong Kang | 0f26b20 | 2012-08-17 15:43:12 -0700 | [diff] [blame] | 4482 | break; |
| 4483 | default: |
| 4484 | bWrongTransition = true; |
| 4485 | break; |
| 4486 | } |
| 4487 | } |
| 4488 | else if (m_afState == HAL_AFSTATE_PASSIVE_FOCUSED) { |
| 4489 | switch (noti) { |
| 4490 | case AA_AFSTATE_INACTIVE: |
| 4491 | bWrongTransition = true; |
| 4492 | break; |
| 4493 | case AA_AFSTATE_ACTIVE_SCAN: |
| 4494 | nextState = HAL_AFSTATE_SCANNING; |
| 4495 | SetAfStateForService(ANDROID_CONTROL_AF_STATE_PASSIVE_SCAN); |
| 4496 | break; |
| 4497 | case AA_AFSTATE_AF_ACQUIRED_FOCUS: |
| 4498 | nextState = NO_TRANSITION; |
| 4499 | break; |
| 4500 | case AA_AFSTATE_AF_FAILED_FOCUS: |
| 4501 | nextState = HAL_AFSTATE_FAILED; |
| 4502 | SetAfStateForService(ANDROID_CONTROL_AF_STATE_NOT_FOCUSED_LOCKED); |
Sungjoong Kang | 8e2c2fd | 2012-08-27 00:02:22 -0700 | [diff] [blame] | 4503 | // TODO : needs NO_TRANSITION ? |
Sungjoong Kang | 0f26b20 | 2012-08-17 15:43:12 -0700 | [diff] [blame] | 4504 | break; |
| 4505 | default: |
| 4506 | bWrongTransition = true; |
| 4507 | break; |
| 4508 | } |
| 4509 | } |
| 4510 | else if (m_afState == HAL_AFSTATE_NEEDS_DETERMINATION) { |
| 4511 | switch (noti) { |
| 4512 | case AA_AFSTATE_INACTIVE: |
| 4513 | bWrongTransition = true; |
| 4514 | break; |
| 4515 | case AA_AFSTATE_ACTIVE_SCAN: |
| 4516 | nextState = NO_TRANSITION; |
| 4517 | break; |
| 4518 | case AA_AFSTATE_AF_ACQUIRED_FOCUS: |
| 4519 | m_IsAfLockRequired = true; |
| 4520 | nextState = HAL_AFSTATE_LOCKED; |
| 4521 | SetAfStateForService(ANDROID_CONTROL_AF_STATE_FOCUSED_LOCKED); |
| 4522 | break; |
| 4523 | case AA_AFSTATE_AF_FAILED_FOCUS: |
| 4524 | nextState = HAL_AFSTATE_FAILED; |
| 4525 | SetAfStateForService(ANDROID_CONTROL_AF_STATE_NOT_FOCUSED_LOCKED); |
| 4526 | break; |
| 4527 | default: |
| 4528 | bWrongTransition = true; |
| 4529 | break; |
| 4530 | } |
| 4531 | } |
| 4532 | else if (m_afState == HAL_AFSTATE_LOCKED) { |
| 4533 | switch (noti) { |
| 4534 | case AA_AFSTATE_INACTIVE: |
| 4535 | nextState = NO_TRANSITION; |
| 4536 | break; |
| 4537 | case AA_AFSTATE_ACTIVE_SCAN: |
| 4538 | bWrongTransition = true; |
| 4539 | break; |
| 4540 | case AA_AFSTATE_AF_ACQUIRED_FOCUS: |
| 4541 | nextState = NO_TRANSITION; |
| 4542 | break; |
| 4543 | case AA_AFSTATE_AF_FAILED_FOCUS: |
| 4544 | default: |
| 4545 | bWrongTransition = true; |
| 4546 | break; |
| 4547 | } |
| 4548 | } |
| 4549 | else if (m_afState == HAL_AFSTATE_FAILED) { |
| 4550 | switch (noti) { |
| 4551 | case AA_AFSTATE_INACTIVE: |
| 4552 | case AA_AFSTATE_ACTIVE_SCAN: |
| 4553 | case AA_AFSTATE_AF_ACQUIRED_FOCUS: |
| 4554 | bWrongTransition = true; |
| 4555 | break; |
| 4556 | case AA_AFSTATE_AF_FAILED_FOCUS: |
| 4557 | nextState = NO_TRANSITION; |
| 4558 | break; |
| 4559 | default: |
| 4560 | bWrongTransition = true; |
| 4561 | break; |
| 4562 | } |
| 4563 | } |
| 4564 | if (bWrongTransition) { |
| 4565 | ALOGV("(%s): Wrong Transition state(%d) noti(%d)", __FUNCTION__, m_afState, noti); |
| 4566 | return; |
| 4567 | } |
| 4568 | ALOGV("(%s): State (%d) -> (%d) by (%d)", __FUNCTION__, m_afState, nextState, noti); |
| 4569 | if (nextState != NO_TRANSITION) |
| 4570 | m_afState = nextState; |
| 4571 | } |
| 4572 | |
| 4573 | void ExynosCameraHWInterface2::OnAfCancel(int id) |
| 4574 | { |
Sungjoong Kang | 8e2c2fd | 2012-08-27 00:02:22 -0700 | [diff] [blame] | 4575 | m_afTriggerId = id; |
| 4576 | |
Sungjoong Kang | 0f26b20 | 2012-08-17 15:43:12 -0700 | [diff] [blame] | 4577 | switch (m_afMode) { |
| 4578 | case AA_AFMODE_AUTO: |
| 4579 | case AA_AFMODE_MACRO: |
Sungjoong Kang | 8e2c2fd | 2012-08-27 00:02:22 -0700 | [diff] [blame] | 4580 | case AA_AFMODE_OFF: |
Sungjoong Kang | 0f26b20 | 2012-08-17 15:43:12 -0700 | [diff] [blame] | 4581 | OnAfCancelAutoMacro(id); |
| 4582 | break; |
| 4583 | case AA_AFMODE_CONTINUOUS_VIDEO: |
| 4584 | OnAfCancelCAFVideo(id); |
| 4585 | break; |
| 4586 | case AA_AFMODE_CONTINUOUS_PICTURE: |
| 4587 | OnAfCancelCAFPicture(id); |
| 4588 | break; |
Sungjoong Kang | 0f26b20 | 2012-08-17 15:43:12 -0700 | [diff] [blame] | 4589 | default: |
| 4590 | break; |
| 4591 | } |
| 4592 | } |
| 4593 | |
| 4594 | void ExynosCameraHWInterface2::OnAfCancelAutoMacro(int id) |
| 4595 | { |
| 4596 | int nextState = NO_TRANSITION; |
| 4597 | m_afTriggerId = id; |
| 4598 | |
Younghwan Joo | 6f19b6c | 2012-08-30 13:56:53 -0700 | [diff] [blame] | 4599 | if (m_afFlashEnableFlg) { |
| 4600 | m_afFlashCnt = IF_FLASH_AF_OFF; |
| 4601 | } |
Sungjoong Kang | 0f26b20 | 2012-08-17 15:43:12 -0700 | [diff] [blame] | 4602 | switch (m_afState) { |
| 4603 | case HAL_AFSTATE_INACTIVE: |
| 4604 | nextState = NO_TRANSITION; |
Sungjoong Kang | cd13bb7 | 2012-08-28 13:05:01 -0700 | [diff] [blame] | 4605 | SetAfStateForService(ANDROID_CONTROL_AF_STATE_INACTIVE); |
Sungjoong Kang | 0f26b20 | 2012-08-17 15:43:12 -0700 | [diff] [blame] | 4606 | break; |
| 4607 | case HAL_AFSTATE_NEEDS_COMMAND: |
| 4608 | case HAL_AFSTATE_STARTED: |
| 4609 | case HAL_AFSTATE_SCANNING: |
| 4610 | case HAL_AFSTATE_LOCKED: |
| 4611 | case HAL_AFSTATE_FAILED: |
| 4612 | SetAfMode(AA_AFMODE_OFF); |
| 4613 | SetAfStateForService(ANDROID_CONTROL_AF_STATE_INACTIVE); |
| 4614 | nextState = HAL_AFSTATE_INACTIVE; |
| 4615 | break; |
| 4616 | default: |
| 4617 | break; |
| 4618 | } |
| 4619 | ALOGV("(%s): State (%d) -> (%d)", __FUNCTION__, m_afState, nextState); |
| 4620 | if (nextState != NO_TRANSITION) |
| 4621 | m_afState = nextState; |
| 4622 | } |
| 4623 | |
| 4624 | void ExynosCameraHWInterface2::OnAfCancelCAFPicture(int id) |
| 4625 | { |
| 4626 | int nextState = NO_TRANSITION; |
| 4627 | m_afTriggerId = id; |
| 4628 | |
| 4629 | switch (m_afState) { |
| 4630 | case HAL_AFSTATE_INACTIVE: |
| 4631 | nextState = NO_TRANSITION; |
| 4632 | break; |
| 4633 | case HAL_AFSTATE_NEEDS_COMMAND: |
| 4634 | case HAL_AFSTATE_STARTED: |
| 4635 | case HAL_AFSTATE_SCANNING: |
| 4636 | case HAL_AFSTATE_LOCKED: |
| 4637 | case HAL_AFSTATE_FAILED: |
| 4638 | case HAL_AFSTATE_NEEDS_DETERMINATION: |
| 4639 | case HAL_AFSTATE_PASSIVE_FOCUSED: |
| 4640 | SetAfMode(AA_AFMODE_OFF); |
| 4641 | SetAfStateForService(ANDROID_CONTROL_AF_STATE_INACTIVE); |
| 4642 | SetAfMode(AA_AFMODE_CONTINUOUS_PICTURE); |
| 4643 | nextState = HAL_AFSTATE_INACTIVE; |
| 4644 | break; |
| 4645 | default: |
| 4646 | break; |
| 4647 | } |
| 4648 | ALOGV("(%s): State (%d) -> (%d)", __FUNCTION__, m_afState, nextState); |
| 4649 | if (nextState != NO_TRANSITION) |
| 4650 | m_afState = nextState; |
| 4651 | } |
| 4652 | |
| 4653 | void ExynosCameraHWInterface2::OnAfCancelCAFVideo(int id) |
| 4654 | { |
| 4655 | int nextState = NO_TRANSITION; |
| 4656 | m_afTriggerId = id; |
| 4657 | |
| 4658 | switch (m_afState) { |
| 4659 | case HAL_AFSTATE_INACTIVE: |
| 4660 | nextState = NO_TRANSITION; |
| 4661 | break; |
| 4662 | case HAL_AFSTATE_NEEDS_COMMAND: |
| 4663 | case HAL_AFSTATE_STARTED: |
| 4664 | case HAL_AFSTATE_SCANNING: |
| 4665 | case HAL_AFSTATE_LOCKED: |
| 4666 | case HAL_AFSTATE_FAILED: |
| 4667 | case HAL_AFSTATE_NEEDS_DETERMINATION: |
| 4668 | case HAL_AFSTATE_PASSIVE_FOCUSED: |
| 4669 | SetAfMode(AA_AFMODE_OFF); |
| 4670 | SetAfStateForService(ANDROID_CONTROL_AF_STATE_INACTIVE); |
| 4671 | SetAfMode(AA_AFMODE_CONTINUOUS_VIDEO); |
| 4672 | nextState = HAL_AFSTATE_INACTIVE; |
| 4673 | break; |
| 4674 | default: |
| 4675 | break; |
| 4676 | } |
| 4677 | ALOGV("(%s): State (%d) -> (%d)", __FUNCTION__, m_afState, nextState); |
| 4678 | if (nextState != NO_TRANSITION) |
| 4679 | m_afState = nextState; |
| 4680 | } |
| 4681 | |
| 4682 | void ExynosCameraHWInterface2::SetAfStateForService(int newState) |
| 4683 | { |
Sungjoong Kang | 8e2c2fd | 2012-08-27 00:02:22 -0700 | [diff] [blame] | 4684 | if (m_serviceAfState != newState || newState == 0) |
| 4685 | m_notifyCb(CAMERA2_MSG_AUTOFOCUS, newState, m_afTriggerId, 0, m_callbackCookie); |
Sungjoong Kang | 0f26b20 | 2012-08-17 15:43:12 -0700 | [diff] [blame] | 4686 | m_serviceAfState = newState; |
Sungjoong Kang | 0f26b20 | 2012-08-17 15:43:12 -0700 | [diff] [blame] | 4687 | } |
| 4688 | |
| 4689 | int ExynosCameraHWInterface2::GetAfStateForService() |
| 4690 | { |
| 4691 | return m_serviceAfState; |
| 4692 | } |
| 4693 | |
| 4694 | void ExynosCameraHWInterface2::SetAfMode(enum aa_afmode afMode) |
| 4695 | { |
| 4696 | if (m_afMode != afMode) { |
| 4697 | if (m_IsAfModeUpdateRequired) { |
| 4698 | m_afMode2 = afMode; |
| 4699 | ALOGV("(%s): pending(%d) and new(%d)", __FUNCTION__, m_afMode, afMode); |
| 4700 | } |
| 4701 | else { |
| 4702 | ALOGV("(%s): current(%d) new(%d)", __FUNCTION__, m_afMode, afMode); |
| 4703 | m_IsAfModeUpdateRequired = true; |
| 4704 | m_afMode = afMode; |
Sungjoong Kang | cd13bb7 | 2012-08-28 13:05:01 -0700 | [diff] [blame] | 4705 | if (m_afModeWaitingCnt != 0) { |
| 4706 | m_afModeWaitingCnt = 0; |
| 4707 | OnAfTrigger(m_afPendingTriggerId); |
| 4708 | } |
Sungjoong Kang | 8e2c2fd | 2012-08-27 00:02:22 -0700 | [diff] [blame] | 4709 | } |
Sungjoong Kang | 0f26b20 | 2012-08-17 15:43:12 -0700 | [diff] [blame] | 4710 | } |
| 4711 | } |
| 4712 | |
Sungjoong Kang | eed7ed1 | 2012-08-23 16:35:08 -0700 | [diff] [blame] | 4713 | void ExynosCameraHWInterface2::m_setExifFixedAttribute(void) |
| 4714 | { |
| 4715 | char property[PROPERTY_VALUE_MAX]; |
| 4716 | |
| 4717 | //2 0th IFD TIFF Tags |
Rebecca Schultz Zavin | 1b8ef18 | 2012-09-04 09:44:10 -0700 | [diff] [blame] | 4718 | #if 0 // STOPSHIP TODO(aray): remove before launch, but for now don't leak product data |
Sungjoong Kang | eed7ed1 | 2012-08-23 16:35:08 -0700 | [diff] [blame] | 4719 | //3 Maker |
| 4720 | property_get("ro.product.brand", property, EXIF_DEF_MAKER); |
| 4721 | strncpy((char *)mExifInfo.maker, property, |
| 4722 | sizeof(mExifInfo.maker) - 1); |
| 4723 | mExifInfo.maker[sizeof(mExifInfo.maker) - 1] = '\0'; |
| 4724 | //3 Model |
| 4725 | property_get("ro.product.model", property, EXIF_DEF_MODEL); |
| 4726 | strncpy((char *)mExifInfo.model, property, |
| 4727 | sizeof(mExifInfo.model) - 1); |
| 4728 | mExifInfo.model[sizeof(mExifInfo.model) - 1] = '\0'; |
| 4729 | //3 Software |
| 4730 | property_get("ro.build.id", property, EXIF_DEF_SOFTWARE); |
| 4731 | strncpy((char *)mExifInfo.software, property, |
| 4732 | sizeof(mExifInfo.software) - 1); |
| 4733 | mExifInfo.software[sizeof(mExifInfo.software) - 1] = '\0'; |
Alex Ray | 5a92f77 | 2012-08-27 17:23:41 -0700 | [diff] [blame] | 4734 | #endif |
Sungjoong Kang | eed7ed1 | 2012-08-23 16:35:08 -0700 | [diff] [blame] | 4735 | |
| 4736 | //3 YCbCr Positioning |
| 4737 | mExifInfo.ycbcr_positioning = EXIF_DEF_YCBCR_POSITIONING; |
| 4738 | |
| 4739 | //2 0th IFD Exif Private Tags |
| 4740 | //3 F Number |
| 4741 | mExifInfo.fnumber.num = EXIF_DEF_FNUMBER_NUM; |
| 4742 | mExifInfo.fnumber.den = EXIF_DEF_FNUMBER_DEN; |
| 4743 | //3 Exposure Program |
| 4744 | mExifInfo.exposure_program = EXIF_DEF_EXPOSURE_PROGRAM; |
| 4745 | //3 Exif Version |
| 4746 | memcpy(mExifInfo.exif_version, EXIF_DEF_EXIF_VERSION, sizeof(mExifInfo.exif_version)); |
| 4747 | //3 Aperture |
| 4748 | uint32_t av = APEX_FNUM_TO_APERTURE((double)mExifInfo.fnumber.num/mExifInfo.fnumber.den); |
| 4749 | mExifInfo.aperture.num = av*EXIF_DEF_APEX_DEN; |
| 4750 | mExifInfo.aperture.den = EXIF_DEF_APEX_DEN; |
| 4751 | //3 Maximum lens aperture |
| 4752 | mExifInfo.max_aperture.num = mExifInfo.aperture.num; |
| 4753 | mExifInfo.max_aperture.den = mExifInfo.aperture.den; |
| 4754 | //3 Lens Focal Length |
| 4755 | mExifInfo.focal_length.num = EXIF_DEF_FOCAL_LEN_NUM; |
| 4756 | mExifInfo.focal_length.den = EXIF_DEF_FOCAL_LEN_DEN; |
| 4757 | //3 User Comments |
| 4758 | strcpy((char *)mExifInfo.user_comment, EXIF_DEF_USERCOMMENTS); |
| 4759 | //3 Color Space information |
| 4760 | mExifInfo.color_space = EXIF_DEF_COLOR_SPACE; |
| 4761 | //3 Exposure Mode |
| 4762 | mExifInfo.exposure_mode = EXIF_DEF_EXPOSURE_MODE; |
| 4763 | |
| 4764 | //2 0th IFD GPS Info Tags |
| 4765 | unsigned char gps_version[4] = { 0x02, 0x02, 0x00, 0x00 }; |
| 4766 | memcpy(mExifInfo.gps_version_id, gps_version, sizeof(gps_version)); |
| 4767 | |
| 4768 | //2 1th IFD TIFF Tags |
| 4769 | mExifInfo.compression_scheme = EXIF_DEF_COMPRESSION; |
| 4770 | mExifInfo.x_resolution.num = EXIF_DEF_RESOLUTION_NUM; |
| 4771 | mExifInfo.x_resolution.den = EXIF_DEF_RESOLUTION_DEN; |
| 4772 | mExifInfo.y_resolution.num = EXIF_DEF_RESOLUTION_NUM; |
| 4773 | mExifInfo.y_resolution.den = EXIF_DEF_RESOLUTION_DEN; |
| 4774 | mExifInfo.resolution_unit = EXIF_DEF_RESOLUTION_UNIT; |
| 4775 | } |
| 4776 | |
| 4777 | void ExynosCameraHWInterface2::m_setExifChangedAttribute(exif_attribute_t *exifInfo, ExynosRect *rect, |
| 4778 | camera2_shot *currentEntry) |
| 4779 | { |
| 4780 | camera2_dm *dm = &(currentEntry->dm); |
| 4781 | camera2_ctl *ctl = &(currentEntry->ctl); |
| 4782 | |
| 4783 | ALOGV("(%s): framecnt(%d) exp(%lld) iso(%d)", __FUNCTION__, ctl->request.frameCount, dm->sensor.exposureTime,dm->aa.isoValue ); |
| 4784 | if (!ctl->request.frameCount) |
| 4785 | return; |
| 4786 | //2 0th IFD TIFF Tags |
| 4787 | //3 Width |
| 4788 | exifInfo->width = rect->w; |
| 4789 | //3 Height |
| 4790 | exifInfo->height = rect->h; |
| 4791 | //3 Orientation |
| 4792 | switch (ctl->jpeg.orientation) { |
| 4793 | case 90: |
| 4794 | exifInfo->orientation = EXIF_ORIENTATION_90; |
| 4795 | break; |
| 4796 | case 180: |
| 4797 | exifInfo->orientation = EXIF_ORIENTATION_180; |
| 4798 | break; |
| 4799 | case 270: |
| 4800 | exifInfo->orientation = EXIF_ORIENTATION_270; |
| 4801 | break; |
| 4802 | case 0: |
| 4803 | default: |
| 4804 | exifInfo->orientation = EXIF_ORIENTATION_UP; |
| 4805 | break; |
| 4806 | } |
| 4807 | |
| 4808 | //3 Date time |
| 4809 | time_t rawtime; |
| 4810 | struct tm *timeinfo; |
| 4811 | time(&rawtime); |
| 4812 | timeinfo = localtime(&rawtime); |
| 4813 | strftime((char *)exifInfo->date_time, 20, "%Y:%m:%d %H:%M:%S", timeinfo); |
| 4814 | |
| 4815 | //2 0th IFD Exif Private Tags |
| 4816 | //3 Exposure Time |
| 4817 | int shutterSpeed = (dm->sensor.exposureTime/1000); |
| 4818 | |
| 4819 | if (shutterSpeed < 0) { |
| 4820 | shutterSpeed = 100; |
| 4821 | } |
| 4822 | |
| 4823 | exifInfo->exposure_time.num = 1; |
| 4824 | // x us -> 1/x s */ |
| 4825 | //exifInfo->exposure_time.den = (uint32_t)(1000000 / shutterSpeed); |
| 4826 | exifInfo->exposure_time.den = (uint32_t)((double)1000000 / shutterSpeed); |
| 4827 | |
| 4828 | //3 ISO Speed Rating |
| 4829 | exifInfo->iso_speed_rating = dm->aa.isoValue; |
| 4830 | |
| 4831 | uint32_t av, tv, bv, sv, ev; |
| 4832 | av = APEX_FNUM_TO_APERTURE((double)exifInfo->fnumber.num / exifInfo->fnumber.den); |
| 4833 | tv = APEX_EXPOSURE_TO_SHUTTER((double)exifInfo->exposure_time.num / exifInfo->exposure_time.den); |
| 4834 | sv = APEX_ISO_TO_FILMSENSITIVITY(exifInfo->iso_speed_rating); |
| 4835 | bv = av + tv - sv; |
| 4836 | ev = av + tv; |
| 4837 | //ALOGD("Shutter speed=%d us, iso=%d", shutterSpeed, exifInfo->iso_speed_rating); |
| 4838 | ALOGD("AV=%d, TV=%d, SV=%d", av, tv, sv); |
| 4839 | |
| 4840 | //3 Shutter Speed |
| 4841 | exifInfo->shutter_speed.num = tv * EXIF_DEF_APEX_DEN; |
| 4842 | exifInfo->shutter_speed.den = EXIF_DEF_APEX_DEN; |
| 4843 | //3 Brightness |
| 4844 | exifInfo->brightness.num = bv*EXIF_DEF_APEX_DEN; |
| 4845 | exifInfo->brightness.den = EXIF_DEF_APEX_DEN; |
| 4846 | //3 Exposure Bias |
| 4847 | if (ctl->aa.sceneMode== AA_SCENE_MODE_BEACH|| |
| 4848 | ctl->aa.sceneMode== AA_SCENE_MODE_SNOW) { |
| 4849 | exifInfo->exposure_bias.num = EXIF_DEF_APEX_DEN; |
| 4850 | exifInfo->exposure_bias.den = EXIF_DEF_APEX_DEN; |
| 4851 | } else { |
| 4852 | exifInfo->exposure_bias.num = 0; |
| 4853 | exifInfo->exposure_bias.den = 0; |
| 4854 | } |
| 4855 | //3 Metering Mode |
| 4856 | /*switch (m_curCameraInfo->metering) { |
| 4857 | case METERING_MODE_CENTER: |
| 4858 | exifInfo->metering_mode = EXIF_METERING_CENTER; |
| 4859 | break; |
| 4860 | case METERING_MODE_MATRIX: |
| 4861 | exifInfo->metering_mode = EXIF_METERING_MULTISPOT; |
| 4862 | break; |
| 4863 | case METERING_MODE_SPOT: |
| 4864 | exifInfo->metering_mode = EXIF_METERING_SPOT; |
| 4865 | break; |
| 4866 | case METERING_MODE_AVERAGE: |
| 4867 | default: |
| 4868 | exifInfo->metering_mode = EXIF_METERING_AVERAGE; |
| 4869 | break; |
| 4870 | }*/ |
| 4871 | exifInfo->metering_mode = EXIF_METERING_CENTER; |
| 4872 | |
| 4873 | //3 Flash |
| 4874 | int flash = dm->flash.flashMode; |
| 4875 | if (dm->flash.flashMode == FLASH_MODE_OFF || flash < 0) |
| 4876 | exifInfo->flash = EXIF_DEF_FLASH; |
| 4877 | else |
| 4878 | exifInfo->flash = flash; |
| 4879 | |
| 4880 | //3 White Balance |
| 4881 | if (dm->aa.awbMode == AA_AWBMODE_WB_AUTO) |
| 4882 | exifInfo->white_balance = EXIF_WB_AUTO; |
| 4883 | else |
| 4884 | exifInfo->white_balance = EXIF_WB_MANUAL; |
| 4885 | |
| 4886 | //3 Scene Capture Type |
| 4887 | switch (ctl->aa.sceneMode) { |
| 4888 | case AA_SCENE_MODE_PORTRAIT: |
| 4889 | exifInfo->scene_capture_type = EXIF_SCENE_PORTRAIT; |
| 4890 | break; |
| 4891 | case AA_SCENE_MODE_LANDSCAPE: |
| 4892 | exifInfo->scene_capture_type = EXIF_SCENE_LANDSCAPE; |
| 4893 | break; |
| 4894 | case AA_SCENE_MODE_NIGHT_PORTRAIT: |
| 4895 | exifInfo->scene_capture_type = EXIF_SCENE_NIGHT; |
| 4896 | break; |
| 4897 | default: |
| 4898 | exifInfo->scene_capture_type = EXIF_SCENE_STANDARD; |
| 4899 | break; |
| 4900 | } |
| 4901 | |
| 4902 | //2 0th IFD GPS Info Tags |
| 4903 | if (ctl->jpeg.gpsCoordinates[0] != 0 && ctl->jpeg.gpsCoordinates[1] != 0) { |
| 4904 | |
| 4905 | if (ctl->jpeg.gpsCoordinates[0] > 0) |
| 4906 | strcpy((char *)exifInfo->gps_latitude_ref, "N"); |
| 4907 | else |
| 4908 | strcpy((char *)exifInfo->gps_latitude_ref, "S"); |
| 4909 | |
| 4910 | if (ctl->jpeg.gpsCoordinates[1] > 0) |
| 4911 | strcpy((char *)exifInfo->gps_longitude_ref, "E"); |
| 4912 | else |
| 4913 | strcpy((char *)exifInfo->gps_longitude_ref, "W"); |
| 4914 | |
| 4915 | if (ctl->jpeg.gpsCoordinates[2] > 0) |
| 4916 | exifInfo->gps_altitude_ref = 0; |
| 4917 | else |
| 4918 | exifInfo->gps_altitude_ref = 1; |
| 4919 | |
| 4920 | double latitude = fabs(ctl->jpeg.gpsCoordinates[0] / 10000.0); |
| 4921 | double longitude = fabs(ctl->jpeg.gpsCoordinates[1] / 10000.0); |
| 4922 | double altitude = fabs(ctl->jpeg.gpsCoordinates[2] / 100.0); |
| 4923 | |
| 4924 | exifInfo->gps_latitude[0].num = (uint32_t)latitude; |
| 4925 | exifInfo->gps_latitude[0].den = 1; |
| 4926 | exifInfo->gps_latitude[1].num = (uint32_t)((latitude - exifInfo->gps_latitude[0].num) * 60); |
| 4927 | exifInfo->gps_latitude[1].den = 1; |
| 4928 | exifInfo->gps_latitude[2].num = (uint32_t)((((latitude - exifInfo->gps_latitude[0].num) * 60) |
| 4929 | - exifInfo->gps_latitude[1].num) * 60); |
| 4930 | exifInfo->gps_latitude[2].den = 1; |
| 4931 | |
| 4932 | exifInfo->gps_longitude[0].num = (uint32_t)longitude; |
| 4933 | exifInfo->gps_longitude[0].den = 1; |
| 4934 | exifInfo->gps_longitude[1].num = (uint32_t)((longitude - exifInfo->gps_longitude[0].num) * 60); |
| 4935 | exifInfo->gps_longitude[1].den = 1; |
| 4936 | exifInfo->gps_longitude[2].num = (uint32_t)((((longitude - exifInfo->gps_longitude[0].num) * 60) |
| 4937 | - exifInfo->gps_longitude[1].num) * 60); |
| 4938 | exifInfo->gps_longitude[2].den = 1; |
| 4939 | |
| 4940 | exifInfo->gps_altitude.num = (uint32_t)altitude; |
| 4941 | exifInfo->gps_altitude.den = 1; |
| 4942 | |
| 4943 | struct tm tm_data; |
| 4944 | long timestamp; |
| 4945 | timestamp = (long)ctl->jpeg.gpsTimestamp; |
| 4946 | gmtime_r(×tamp, &tm_data); |
| 4947 | exifInfo->gps_timestamp[0].num = tm_data.tm_hour; |
| 4948 | exifInfo->gps_timestamp[0].den = 1; |
| 4949 | exifInfo->gps_timestamp[1].num = tm_data.tm_min; |
| 4950 | exifInfo->gps_timestamp[1].den = 1; |
| 4951 | exifInfo->gps_timestamp[2].num = tm_data.tm_sec; |
| 4952 | exifInfo->gps_timestamp[2].den = 1; |
| 4953 | snprintf((char*)exifInfo->gps_datestamp, sizeof(exifInfo->gps_datestamp), |
| 4954 | "%04d:%02d:%02d", tm_data.tm_year + 1900, tm_data.tm_mon + 1, tm_data.tm_mday); |
| 4955 | |
| 4956 | exifInfo->enableGps = true; |
| 4957 | } else { |
| 4958 | exifInfo->enableGps = false; |
| 4959 | } |
| 4960 | |
| 4961 | //2 1th IFD TIFF Tags |
| 4962 | exifInfo->widthThumb = ctl->jpeg.thumbnailSize[0]; |
| 4963 | exifInfo->heightThumb = ctl->jpeg.thumbnailSize[1]; |
| 4964 | } |
| 4965 | |
Sungjoong Kang | 13d8c7b | 2012-07-14 10:20:39 +0900 | [diff] [blame] | 4966 | ExynosCameraHWInterface2::MainThread::~MainThread() |
Jiyoung Shin | c15a6b0 | 2012-06-05 01:08:14 -0700 | [diff] [blame] | 4967 | { |
Sungjoong Kang | ad37861 | 2012-08-17 12:34:33 -0700 | [diff] [blame] | 4968 | ALOGV("(%s):", __FUNCTION__); |
Sungjoong Kang | 13d8c7b | 2012-07-14 10:20:39 +0900 | [diff] [blame] | 4969 | } |
| 4970 | |
| 4971 | void ExynosCameraHWInterface2::MainThread::release() |
| 4972 | { |
Sungjoong Kang | ad37861 | 2012-08-17 12:34:33 -0700 | [diff] [blame] | 4973 | ALOGV("(%s):", __func__); |
Sungjoong Kang | 13d8c7b | 2012-07-14 10:20:39 +0900 | [diff] [blame] | 4974 | SetSignal(SIGNAL_THREAD_RELEASE); |
Sungjoong Kang | 13d8c7b | 2012-07-14 10:20:39 +0900 | [diff] [blame] | 4975 | } |
| 4976 | |
| 4977 | ExynosCameraHWInterface2::SensorThread::~SensorThread() |
| 4978 | { |
Sungjoong Kang | ad37861 | 2012-08-17 12:34:33 -0700 | [diff] [blame] | 4979 | ALOGV("(%s):", __FUNCTION__); |
Sungjoong Kang | 13d8c7b | 2012-07-14 10:20:39 +0900 | [diff] [blame] | 4980 | } |
| 4981 | |
| 4982 | void ExynosCameraHWInterface2::SensorThread::release() |
| 4983 | { |
Sungjoong Kang | ad37861 | 2012-08-17 12:34:33 -0700 | [diff] [blame] | 4984 | ALOGV("(%s):", __func__); |
Sungjoong Kang | 13d8c7b | 2012-07-14 10:20:39 +0900 | [diff] [blame] | 4985 | SetSignal(SIGNAL_THREAD_RELEASE); |
Sungjoong Kang | 13d8c7b | 2012-07-14 10:20:39 +0900 | [diff] [blame] | 4986 | } |
| 4987 | |
| 4988 | ExynosCameraHWInterface2::IspThread::~IspThread() |
| 4989 | { |
Sungjoong Kang | ad37861 | 2012-08-17 12:34:33 -0700 | [diff] [blame] | 4990 | ALOGV("(%s):", __FUNCTION__); |
Sungjoong Kang | 13d8c7b | 2012-07-14 10:20:39 +0900 | [diff] [blame] | 4991 | } |
| 4992 | |
| 4993 | void ExynosCameraHWInterface2::IspThread::release() |
| 4994 | { |
Sungjoong Kang | ad37861 | 2012-08-17 12:34:33 -0700 | [diff] [blame] | 4995 | ALOGV("(%s):", __func__); |
Sungjoong Kang | 13d8c7b | 2012-07-14 10:20:39 +0900 | [diff] [blame] | 4996 | SetSignal(SIGNAL_THREAD_RELEASE); |
Sungjoong Kang | 13d8c7b | 2012-07-14 10:20:39 +0900 | [diff] [blame] | 4997 | } |
| 4998 | |
| 4999 | ExynosCameraHWInterface2::StreamThread::~StreamThread() |
| 5000 | { |
Sungjoong Kang | ad37861 | 2012-08-17 12:34:33 -0700 | [diff] [blame] | 5001 | ALOGV("(%s):", __FUNCTION__); |
Sungjoong Kang | 13d8c7b | 2012-07-14 10:20:39 +0900 | [diff] [blame] | 5002 | } |
| 5003 | |
| 5004 | void ExynosCameraHWInterface2::StreamThread::setParameter(stream_parameters_t * new_parameters) |
| 5005 | { |
| 5006 | ALOGV("DEBUG(%s):", __FUNCTION__); |
| 5007 | |
| 5008 | m_tempParameters = new_parameters; |
| 5009 | |
| 5010 | SetSignal(SIGNAL_STREAM_CHANGE_PARAMETER); |
| 5011 | |
| 5012 | // TODO : return synchronously (after setting parameters asynchronously) |
Sungjoong Kang | 9dd63e1 | 2012-07-24 00:25:51 +0900 | [diff] [blame] | 5013 | usleep(2000); |
Sungjoong Kang | 13d8c7b | 2012-07-14 10:20:39 +0900 | [diff] [blame] | 5014 | } |
| 5015 | |
| 5016 | void ExynosCameraHWInterface2::StreamThread::applyChange() |
| 5017 | { |
| 5018 | memcpy(&m_parameters, m_tempParameters, sizeof(stream_parameters_t)); |
| 5019 | |
Sungjoong Kang | 9dd63e1 | 2012-07-24 00:25:51 +0900 | [diff] [blame] | 5020 | ALOGV("DEBUG(%s): Applying Stream paremeters width(%d), height(%d)", |
Sungjoong Kang | 13d8c7b | 2012-07-14 10:20:39 +0900 | [diff] [blame] | 5021 | __FUNCTION__, m_parameters.outputWidth, m_parameters.outputHeight); |
| 5022 | } |
| 5023 | |
| 5024 | void ExynosCameraHWInterface2::StreamThread::release() |
| 5025 | { |
Sungjoong Kang | 9dd63e1 | 2012-07-24 00:25:51 +0900 | [diff] [blame] | 5026 | ALOGV("(%s):", __func__); |
Sungjoong Kang | 13d8c7b | 2012-07-14 10:20:39 +0900 | [diff] [blame] | 5027 | SetSignal(SIGNAL_THREAD_RELEASE); |
Sungjoong Kang | 13d8c7b | 2012-07-14 10:20:39 +0900 | [diff] [blame] | 5028 | } |
| 5029 | |
| 5030 | int ExynosCameraHWInterface2::StreamThread::findBufferIndex(void * bufAddr) |
| 5031 | { |
| 5032 | int index; |
| 5033 | for (index = 0 ; index < m_parameters.numSvcBuffers ; index++) { |
| 5034 | if (m_parameters.svcBuffers[index].virt.extP[0] == bufAddr) |
| 5035 | return index; |
| 5036 | } |
| 5037 | return -1; |
Jiyoung Shin | c15a6b0 | 2012-06-05 01:08:14 -0700 | [diff] [blame] | 5038 | } |
| 5039 | |
Sungjoong Kang | 9dd63e1 | 2012-07-24 00:25:51 +0900 | [diff] [blame] | 5040 | void ExynosCameraHWInterface2::StreamThread::setRecordingParameter(record_parameters_t * recordParm) |
| 5041 | { |
| 5042 | memcpy(&m_recordParameters, recordParm, sizeof(record_parameters_t)); |
| 5043 | } |
| 5044 | |
Sungjoong Kang | 74d78eb | 2012-08-29 13:25:46 -0700 | [diff] [blame] | 5045 | void ExynosCameraHWInterface2::StreamThread::setCallbackParameter(callback_parameters_t * callbackParm) |
| 5046 | { |
| 5047 | memcpy(&m_previewCbParameters, callbackParm, sizeof(callback_parameters_t)); |
| 5048 | } |
| 5049 | |
Jiyoung Shin | c15a6b0 | 2012-06-05 01:08:14 -0700 | [diff] [blame] | 5050 | int ExynosCameraHWInterface2::createIonClient(ion_client ionClient) |
| 5051 | { |
| 5052 | if (ionClient == 0) { |
| 5053 | ionClient = ion_client_create(); |
| 5054 | if (ionClient < 0) { |
Sungjoong Kang | 13d8c7b | 2012-07-14 10:20:39 +0900 | [diff] [blame] | 5055 | ALOGE("[%s]src ion client create failed, value = %d\n", __FUNCTION__, ionClient); |
Jiyoung Shin | c15a6b0 | 2012-06-05 01:08:14 -0700 | [diff] [blame] | 5056 | return 0; |
| 5057 | } |
| 5058 | } |
| 5059 | |
| 5060 | return ionClient; |
| 5061 | } |
| 5062 | |
| 5063 | int ExynosCameraHWInterface2::deleteIonClient(ion_client ionClient) |
| 5064 | { |
| 5065 | if (ionClient != 0) { |
| 5066 | if (ionClient > 0) { |
| 5067 | ion_client_destroy(ionClient); |
| 5068 | } |
| 5069 | ionClient = 0; |
| 5070 | } |
| 5071 | |
| 5072 | return ionClient; |
| 5073 | } |
| 5074 | |
Sungjoong Kang | 13d8c7b | 2012-07-14 10:20:39 +0900 | [diff] [blame] | 5075 | int ExynosCameraHWInterface2::allocCameraMemory(ion_client ionClient, ExynosBuffer *buf, int iMemoryNum) |
Jiyoung Shin | c15a6b0 | 2012-06-05 01:08:14 -0700 | [diff] [blame] | 5076 | { |
| 5077 | int ret = 0; |
| 5078 | int i = 0; |
| 5079 | |
| 5080 | if (ionClient == 0) { |
Sungjoong Kang | 13d8c7b | 2012-07-14 10:20:39 +0900 | [diff] [blame] | 5081 | ALOGE("[%s] ionClient is zero (%d)\n", __FUNCTION__, ionClient); |
Jiyoung Shin | c15a6b0 | 2012-06-05 01:08:14 -0700 | [diff] [blame] | 5082 | return -1; |
| 5083 | } |
| 5084 | |
| 5085 | for (i=0;i<iMemoryNum;i++) { |
Sungjoong Kang | 13d8c7b | 2012-07-14 10:20:39 +0900 | [diff] [blame] | 5086 | if (buf->size.extS[i] == 0) { |
Jiyoung Shin | c15a6b0 | 2012-06-05 01:08:14 -0700 | [diff] [blame] | 5087 | break; |
| 5088 | } |
| 5089 | |
Sungjoong Kang | 13d8c7b | 2012-07-14 10:20:39 +0900 | [diff] [blame] | 5090 | buf->fd.extFd[i] = ion_alloc(ionClient, \ |
| 5091 | buf->size.extS[i], 0, ION_HEAP_EXYNOS_MASK,0); |
| 5092 | if ((buf->fd.extFd[i] == -1) ||(buf->fd.extFd[i] == 0)) { |
| 5093 | ALOGE("[%s]ion_alloc(%d) failed\n", __FUNCTION__, buf->size.extS[i]); |
| 5094 | buf->fd.extFd[i] = -1; |
Jiyoung Shin | c15a6b0 | 2012-06-05 01:08:14 -0700 | [diff] [blame] | 5095 | freeCameraMemory(buf, iMemoryNum); |
| 5096 | return -1; |
| 5097 | } |
| 5098 | |
Sungjoong Kang | 13d8c7b | 2012-07-14 10:20:39 +0900 | [diff] [blame] | 5099 | buf->virt.extP[i] = (char *)ion_map(buf->fd.extFd[i], \ |
| 5100 | buf->size.extS[i], 0); |
| 5101 | if ((buf->virt.extP[i] == (char *)MAP_FAILED) || (buf->virt.extP[i] == NULL)) { |
| 5102 | ALOGE("[%s]src ion map failed(%d)\n", __FUNCTION__, buf->size.extS[i]); |
| 5103 | buf->virt.extP[i] = (char *)MAP_FAILED; |
Jiyoung Shin | c15a6b0 | 2012-06-05 01:08:14 -0700 | [diff] [blame] | 5104 | freeCameraMemory(buf, iMemoryNum); |
| 5105 | return -1; |
| 5106 | } |
Sungjoong Kang | 13d8c7b | 2012-07-14 10:20:39 +0900 | [diff] [blame] | 5107 | ALOGV("allocCameraMem : [%d][0x%08x] size(%d)", i, (unsigned int)(buf->virt.extP[i]), buf->size.extS[i]); |
Jiyoung Shin | c15a6b0 | 2012-06-05 01:08:14 -0700 | [diff] [blame] | 5108 | } |
| 5109 | |
| 5110 | return ret; |
| 5111 | } |
| 5112 | |
Sungjoong Kang | 13d8c7b | 2012-07-14 10:20:39 +0900 | [diff] [blame] | 5113 | void ExynosCameraHWInterface2::freeCameraMemory(ExynosBuffer *buf, int iMemoryNum) |
Jiyoung Shin | c15a6b0 | 2012-06-05 01:08:14 -0700 | [diff] [blame] | 5114 | { |
Sungjoong Kang | 13d8c7b | 2012-07-14 10:20:39 +0900 | [diff] [blame] | 5115 | |
Jiyoung Shin | c15a6b0 | 2012-06-05 01:08:14 -0700 | [diff] [blame] | 5116 | int i =0 ; |
Sungjoong Kang | 15fd823 | 2012-08-23 16:16:44 -0700 | [diff] [blame] | 5117 | int ret = 0; |
Jiyoung Shin | c15a6b0 | 2012-06-05 01:08:14 -0700 | [diff] [blame] | 5118 | |
| 5119 | for (i=0;i<iMemoryNum;i++) { |
Sungjoong Kang | 13d8c7b | 2012-07-14 10:20:39 +0900 | [diff] [blame] | 5120 | if (buf->fd.extFd[i] != -1) { |
| 5121 | if (buf->virt.extP[i] != (char *)MAP_FAILED) { |
Sungjoong Kang | 15fd823 | 2012-08-23 16:16:44 -0700 | [diff] [blame] | 5122 | ret = ion_unmap(buf->virt.extP[i], buf->size.extS[i]); |
| 5123 | if (ret < 0) |
| 5124 | ALOGE("ERR(%s)", __FUNCTION__); |
Jiyoung Shin | c15a6b0 | 2012-06-05 01:08:14 -0700 | [diff] [blame] | 5125 | } |
Sungjoong Kang | 13d8c7b | 2012-07-14 10:20:39 +0900 | [diff] [blame] | 5126 | ion_free(buf->fd.extFd[i]); |
Jiyoung Shin | c15a6b0 | 2012-06-05 01:08:14 -0700 | [diff] [blame] | 5127 | } |
Sungjoong Kang | 13d8c7b | 2012-07-14 10:20:39 +0900 | [diff] [blame] | 5128 | buf->fd.extFd[i] = -1; |
| 5129 | buf->virt.extP[i] = (char *)MAP_FAILED; |
| 5130 | buf->size.extS[i] = 0; |
Jiyoung Shin | c15a6b0 | 2012-06-05 01:08:14 -0700 | [diff] [blame] | 5131 | } |
| 5132 | } |
| 5133 | |
Sungjoong Kang | 13d8c7b | 2012-07-14 10:20:39 +0900 | [diff] [blame] | 5134 | void ExynosCameraHWInterface2::initCameraMemory(ExynosBuffer *buf, int iMemoryNum) |
Jiyoung Shin | c15a6b0 | 2012-06-05 01:08:14 -0700 | [diff] [blame] | 5135 | { |
| 5136 | int i =0 ; |
| 5137 | for (i=0;i<iMemoryNum;i++) { |
Sungjoong Kang | 13d8c7b | 2012-07-14 10:20:39 +0900 | [diff] [blame] | 5138 | buf->virt.extP[i] = (char *)MAP_FAILED; |
| 5139 | buf->fd.extFd[i] = -1; |
| 5140 | buf->size.extS[i] = 0; |
Jiyoung Shin | c15a6b0 | 2012-06-05 01:08:14 -0700 | [diff] [blame] | 5141 | } |
| 5142 | } |
| 5143 | |
| 5144 | |
Sungjoong Kang | 13d8c7b | 2012-07-14 10:20:39 +0900 | [diff] [blame] | 5145 | |
| 5146 | |
Sungjoong Kang | 9dd63e1 | 2012-07-24 00:25:51 +0900 | [diff] [blame] | 5147 | static camera2_device_t *g_cam2_device = NULL; |
Sungjoong Kang | b5237e6 | 2012-07-27 07:39:05 -0700 | [diff] [blame] | 5148 | static bool g_camera_vaild = false; |
Sungjoong Kang | daa1fcd | 2012-08-08 11:49:43 -0700 | [diff] [blame] | 5149 | ExynosCamera2 * g_camera2[2] = { NULL, NULL }; |
Jiyoung Shin | c15a6b0 | 2012-06-05 01:08:14 -0700 | [diff] [blame] | 5150 | |
| 5151 | static int HAL2_camera_device_close(struct hw_device_t* device) |
| 5152 | { |
Sungjoong Kang | ad37861 | 2012-08-17 12:34:33 -0700 | [diff] [blame] | 5153 | ALOGV("%s: ENTER", __FUNCTION__); |
Jiyoung Shin | c15a6b0 | 2012-06-05 01:08:14 -0700 | [diff] [blame] | 5154 | if (device) { |
Sungjoong Kang | 9dd63e1 | 2012-07-24 00:25:51 +0900 | [diff] [blame] | 5155 | |
Jiyoung Shin | c15a6b0 | 2012-06-05 01:08:14 -0700 | [diff] [blame] | 5156 | camera2_device_t *cam_device = (camera2_device_t *)device; |
Sungjoong Kang | ad37861 | 2012-08-17 12:34:33 -0700 | [diff] [blame] | 5157 | ALOGV("cam_device(0x%08x):", (unsigned int)cam_device); |
| 5158 | ALOGV("g_cam2_device(0x%08x):", (unsigned int)g_cam2_device); |
Jiyoung Shin | c15a6b0 | 2012-06-05 01:08:14 -0700 | [diff] [blame] | 5159 | delete static_cast<ExynosCameraHWInterface2 *>(cam_device->priv); |
Sungjoong Kang | ad37861 | 2012-08-17 12:34:33 -0700 | [diff] [blame] | 5160 | g_cam2_device = NULL; |
Jiyoung Shin | c15a6b0 | 2012-06-05 01:08:14 -0700 | [diff] [blame] | 5161 | free(cam_device); |
Sungjoong Kang | b5237e6 | 2012-07-27 07:39:05 -0700 | [diff] [blame] | 5162 | g_camera_vaild = false; |
Jiyoung Shin | c15a6b0 | 2012-06-05 01:08:14 -0700 | [diff] [blame] | 5163 | } |
Sungjoong Kang | 15fd823 | 2012-08-23 16:16:44 -0700 | [diff] [blame] | 5164 | |
Sungjoong Kang | ad37861 | 2012-08-17 12:34:33 -0700 | [diff] [blame] | 5165 | ALOGV("%s: EXIT", __FUNCTION__); |
Jiyoung Shin | c15a6b0 | 2012-06-05 01:08:14 -0700 | [diff] [blame] | 5166 | return 0; |
| 5167 | } |
| 5168 | |
| 5169 | static inline ExynosCameraHWInterface2 *obj(const struct camera2_device *dev) |
| 5170 | { |
| 5171 | return reinterpret_cast<ExynosCameraHWInterface2 *>(dev->priv); |
| 5172 | } |
| 5173 | |
| 5174 | static int HAL2_device_set_request_queue_src_ops(const struct camera2_device *dev, |
| 5175 | const camera2_request_queue_src_ops_t *request_src_ops) |
| 5176 | { |
Sungjoong Kang | 13d8c7b | 2012-07-14 10:20:39 +0900 | [diff] [blame] | 5177 | ALOGV("DEBUG(%s):", __FUNCTION__); |
Jiyoung Shin | c15a6b0 | 2012-06-05 01:08:14 -0700 | [diff] [blame] | 5178 | return obj(dev)->setRequestQueueSrcOps(request_src_ops); |
| 5179 | } |
| 5180 | |
| 5181 | static int HAL2_device_notify_request_queue_not_empty(const struct camera2_device *dev) |
| 5182 | { |
Sungjoong Kang | 13d8c7b | 2012-07-14 10:20:39 +0900 | [diff] [blame] | 5183 | ALOGV("DEBUG(%s):", __FUNCTION__); |
Jiyoung Shin | c15a6b0 | 2012-06-05 01:08:14 -0700 | [diff] [blame] | 5184 | return obj(dev)->notifyRequestQueueNotEmpty(); |
| 5185 | } |
| 5186 | |
| 5187 | static int HAL2_device_set_frame_queue_dst_ops(const struct camera2_device *dev, |
| 5188 | const camera2_frame_queue_dst_ops_t *frame_dst_ops) |
| 5189 | { |
Sungjoong Kang | 13d8c7b | 2012-07-14 10:20:39 +0900 | [diff] [blame] | 5190 | ALOGV("DEBUG(%s):", __FUNCTION__); |
Jiyoung Shin | c15a6b0 | 2012-06-05 01:08:14 -0700 | [diff] [blame] | 5191 | return obj(dev)->setFrameQueueDstOps(frame_dst_ops); |
| 5192 | } |
| 5193 | |
| 5194 | static int HAL2_device_get_in_progress_count(const struct camera2_device *dev) |
| 5195 | { |
Sungjoong Kang | 13d8c7b | 2012-07-14 10:20:39 +0900 | [diff] [blame] | 5196 | ALOGV("DEBUG(%s):", __FUNCTION__); |
Jiyoung Shin | c15a6b0 | 2012-06-05 01:08:14 -0700 | [diff] [blame] | 5197 | return obj(dev)->getInProgressCount(); |
| 5198 | } |
| 5199 | |
| 5200 | static int HAL2_device_flush_captures_in_progress(const struct camera2_device *dev) |
| 5201 | { |
Sungjoong Kang | 13d8c7b | 2012-07-14 10:20:39 +0900 | [diff] [blame] | 5202 | ALOGV("DEBUG(%s):", __FUNCTION__); |
Jiyoung Shin | c15a6b0 | 2012-06-05 01:08:14 -0700 | [diff] [blame] | 5203 | return obj(dev)->flushCapturesInProgress(); |
| 5204 | } |
| 5205 | |
| 5206 | static int HAL2_device_construct_default_request(const struct camera2_device *dev, |
| 5207 | int request_template, camera_metadata_t **request) |
| 5208 | { |
Sungjoong Kang | 13d8c7b | 2012-07-14 10:20:39 +0900 | [diff] [blame] | 5209 | ALOGV("DEBUG(%s):", __FUNCTION__); |
Jiyoung Shin | c15a6b0 | 2012-06-05 01:08:14 -0700 | [diff] [blame] | 5210 | return obj(dev)->constructDefaultRequest(request_template, request); |
| 5211 | } |
| 5212 | |
| 5213 | static int HAL2_device_allocate_stream( |
| 5214 | const struct camera2_device *dev, |
| 5215 | // inputs |
| 5216 | uint32_t width, |
| 5217 | uint32_t height, |
| 5218 | int format, |
| 5219 | const camera2_stream_ops_t *stream_ops, |
| 5220 | // outputs |
| 5221 | uint32_t *stream_id, |
| 5222 | uint32_t *format_actual, |
| 5223 | uint32_t *usage, |
| 5224 | uint32_t *max_buffers) |
| 5225 | { |
Sungjoong Kang | 9dd63e1 | 2012-07-24 00:25:51 +0900 | [diff] [blame] | 5226 | ALOGV("(%s): ", __FUNCTION__); |
Jiyoung Shin | c15a6b0 | 2012-06-05 01:08:14 -0700 | [diff] [blame] | 5227 | return obj(dev)->allocateStream(width, height, format, stream_ops, |
| 5228 | stream_id, format_actual, usage, max_buffers); |
| 5229 | } |
| 5230 | |
| 5231 | |
| 5232 | static int HAL2_device_register_stream_buffers(const struct camera2_device *dev, |
| 5233 | uint32_t stream_id, |
| 5234 | int num_buffers, |
| 5235 | buffer_handle_t *buffers) |
| 5236 | { |
Sungjoong Kang | 13d8c7b | 2012-07-14 10:20:39 +0900 | [diff] [blame] | 5237 | ALOGV("DEBUG(%s):", __FUNCTION__); |
Jiyoung Shin | c15a6b0 | 2012-06-05 01:08:14 -0700 | [diff] [blame] | 5238 | return obj(dev)->registerStreamBuffers(stream_id, num_buffers, buffers); |
| 5239 | } |
| 5240 | |
| 5241 | static int HAL2_device_release_stream( |
| 5242 | const struct camera2_device *dev, |
| 5243 | uint32_t stream_id) |
| 5244 | { |
Sungjoong Kang | ad37861 | 2012-08-17 12:34:33 -0700 | [diff] [blame] | 5245 | ALOGV("DEBUG(%s)(id: %d):", __FUNCTION__, stream_id); |
Sungjoong Kang | b5237e6 | 2012-07-27 07:39:05 -0700 | [diff] [blame] | 5246 | if (!g_camera_vaild) |
| 5247 | return 0; |
Jiyoung Shin | c15a6b0 | 2012-06-05 01:08:14 -0700 | [diff] [blame] | 5248 | return obj(dev)->releaseStream(stream_id); |
| 5249 | } |
| 5250 | |
| 5251 | static int HAL2_device_allocate_reprocess_stream( |
| 5252 | const struct camera2_device *dev, |
| 5253 | uint32_t width, |
| 5254 | uint32_t height, |
| 5255 | uint32_t format, |
| 5256 | const camera2_stream_in_ops_t *reprocess_stream_ops, |
| 5257 | // outputs |
| 5258 | uint32_t *stream_id, |
| 5259 | uint32_t *consumer_usage, |
| 5260 | uint32_t *max_buffers) |
| 5261 | { |
Sungjoong Kang | 13d8c7b | 2012-07-14 10:20:39 +0900 | [diff] [blame] | 5262 | ALOGV("DEBUG(%s):", __FUNCTION__); |
Jiyoung Shin | c15a6b0 | 2012-06-05 01:08:14 -0700 | [diff] [blame] | 5263 | return obj(dev)->allocateReprocessStream(width, height, format, reprocess_stream_ops, |
| 5264 | stream_id, consumer_usage, max_buffers); |
| 5265 | } |
| 5266 | |
Eino-Ville Talvala | 2b0421d | 2012-09-04 13:41:55 -0700 | [diff] [blame] | 5267 | static int HAL2_device_allocate_reprocess_stream_from_stream( |
| 5268 | const struct camera2_device *dev, |
| 5269 | uint32_t output_stream_id, |
| 5270 | const camera2_stream_in_ops_t *reprocess_stream_ops, |
| 5271 | // outputs |
| 5272 | uint32_t *stream_id) |
| 5273 | { |
| 5274 | ALOGV("DEBUG(%s):", __FUNCTION__); |
| 5275 | // Temporary stub |
| 5276 | return 0; |
| 5277 | } |
| 5278 | |
Jiyoung Shin | c15a6b0 | 2012-06-05 01:08:14 -0700 | [diff] [blame] | 5279 | static int HAL2_device_release_reprocess_stream( |
| 5280 | const struct camera2_device *dev, |
| 5281 | uint32_t stream_id) |
| 5282 | { |
Sungjoong Kang | 13d8c7b | 2012-07-14 10:20:39 +0900 | [diff] [blame] | 5283 | ALOGV("DEBUG(%s):", __FUNCTION__); |
Jiyoung Shin | c15a6b0 | 2012-06-05 01:08:14 -0700 | [diff] [blame] | 5284 | return obj(dev)->releaseReprocessStream(stream_id); |
| 5285 | } |
| 5286 | |
| 5287 | static int HAL2_device_trigger_action(const struct camera2_device *dev, |
| 5288 | uint32_t trigger_id, |
| 5289 | int ext1, |
| 5290 | int ext2) |
| 5291 | { |
Sungjoong Kang | 13d8c7b | 2012-07-14 10:20:39 +0900 | [diff] [blame] | 5292 | ALOGV("DEBUG(%s):", __FUNCTION__); |
Jiyoung Shin | c15a6b0 | 2012-06-05 01:08:14 -0700 | [diff] [blame] | 5293 | return obj(dev)->triggerAction(trigger_id, ext1, ext2); |
| 5294 | } |
| 5295 | |
| 5296 | static int HAL2_device_set_notify_callback(const struct camera2_device *dev, |
| 5297 | camera2_notify_callback notify_cb, |
| 5298 | void *user) |
| 5299 | { |
Sungjoong Kang | 13d8c7b | 2012-07-14 10:20:39 +0900 | [diff] [blame] | 5300 | ALOGV("DEBUG(%s):", __FUNCTION__); |
Jiyoung Shin | c15a6b0 | 2012-06-05 01:08:14 -0700 | [diff] [blame] | 5301 | return obj(dev)->setNotifyCallback(notify_cb, user); |
| 5302 | } |
| 5303 | |
| 5304 | static int HAL2_device_get_metadata_vendor_tag_ops(const struct camera2_device*dev, |
| 5305 | vendor_tag_query_ops_t **ops) |
| 5306 | { |
Sungjoong Kang | 13d8c7b | 2012-07-14 10:20:39 +0900 | [diff] [blame] | 5307 | ALOGV("DEBUG(%s):", __FUNCTION__); |
Jiyoung Shin | c15a6b0 | 2012-06-05 01:08:14 -0700 | [diff] [blame] | 5308 | return obj(dev)->getMetadataVendorTagOps(ops); |
| 5309 | } |
| 5310 | |
| 5311 | static int HAL2_device_dump(const struct camera2_device *dev, int fd) |
| 5312 | { |
Sungjoong Kang | 13d8c7b | 2012-07-14 10:20:39 +0900 | [diff] [blame] | 5313 | ALOGV("DEBUG(%s):", __FUNCTION__); |
Jiyoung Shin | c15a6b0 | 2012-06-05 01:08:14 -0700 | [diff] [blame] | 5314 | return obj(dev)->dump(fd); |
| 5315 | } |
| 5316 | |
| 5317 | |
| 5318 | |
| 5319 | |
| 5320 | |
| 5321 | static int HAL2_getNumberOfCameras() |
| 5322 | { |
Sungjoong Kang | 9dd63e1 | 2012-07-24 00:25:51 +0900 | [diff] [blame] | 5323 | ALOGV("(%s): returning 2", __FUNCTION__); |
| 5324 | return 2; |
Jiyoung Shin | c15a6b0 | 2012-06-05 01:08:14 -0700 | [diff] [blame] | 5325 | } |
| 5326 | |
| 5327 | |
Jiyoung Shin | c15a6b0 | 2012-06-05 01:08:14 -0700 | [diff] [blame] | 5328 | static int HAL2_getCameraInfo(int cameraId, struct camera_info *info) |
| 5329 | { |
Sungjoong Kang | ad37861 | 2012-08-17 12:34:33 -0700 | [diff] [blame] | 5330 | ALOGV("DEBUG(%s): cameraID: %d", __FUNCTION__, cameraId); |
Sungjoong Kang | 9dd63e1 | 2012-07-24 00:25:51 +0900 | [diff] [blame] | 5331 | static camera_metadata_t * mCameraInfo[2] = {NULL, NULL}; |
Sungjoong Kang | ad37861 | 2012-08-17 12:34:33 -0700 | [diff] [blame] | 5332 | |
Jiyoung Shin | c15a6b0 | 2012-06-05 01:08:14 -0700 | [diff] [blame] | 5333 | status_t res; |
Sungjoong Kang | 13d8c7b | 2012-07-14 10:20:39 +0900 | [diff] [blame] | 5334 | |
Sungjoong Kang | daa1fcd | 2012-08-08 11:49:43 -0700 | [diff] [blame] | 5335 | if (cameraId == 0) { |
Sungjoong Kang | 9dd63e1 | 2012-07-24 00:25:51 +0900 | [diff] [blame] | 5336 | info->facing = CAMERA_FACING_BACK; |
Sungjoong Kang | daa1fcd | 2012-08-08 11:49:43 -0700 | [diff] [blame] | 5337 | if (!g_camera2[0]) |
| 5338 | g_camera2[0] = new ExynosCamera2(0); |
| 5339 | } |
| 5340 | else if (cameraId == 1) { |
Sungjoong Kang | 9dd63e1 | 2012-07-24 00:25:51 +0900 | [diff] [blame] | 5341 | info->facing = CAMERA_FACING_FRONT; |
Sungjoong Kang | daa1fcd | 2012-08-08 11:49:43 -0700 | [diff] [blame] | 5342 | if (!g_camera2[1]) |
| 5343 | g_camera2[1] = new ExynosCamera2(1); |
| 5344 | } |
| 5345 | else |
| 5346 | return BAD_VALUE; |
| 5347 | |
Jiyoung Shin | c15a6b0 | 2012-06-05 01:08:14 -0700 | [diff] [blame] | 5348 | info->orientation = 0; |
| 5349 | info->device_version = HARDWARE_DEVICE_API_VERSION(2, 0); |
Sungjoong Kang | 9dd63e1 | 2012-07-24 00:25:51 +0900 | [diff] [blame] | 5350 | if (mCameraInfo[cameraId] == NULL) { |
Sungjoong Kang | daa1fcd | 2012-08-08 11:49:43 -0700 | [diff] [blame] | 5351 | res = g_camera2[cameraId]->constructStaticInfo(&(mCameraInfo[cameraId]), cameraId, true); |
Jiyoung Shin | c15a6b0 | 2012-06-05 01:08:14 -0700 | [diff] [blame] | 5352 | if (res != OK) { |
| 5353 | ALOGE("%s: Unable to allocate static info: %s (%d)", |
Sungjoong Kang | 13d8c7b | 2012-07-14 10:20:39 +0900 | [diff] [blame] | 5354 | __FUNCTION__, strerror(-res), res); |
Jiyoung Shin | c15a6b0 | 2012-06-05 01:08:14 -0700 | [diff] [blame] | 5355 | return res; |
| 5356 | } |
Sungjoong Kang | daa1fcd | 2012-08-08 11:49:43 -0700 | [diff] [blame] | 5357 | res = g_camera2[cameraId]->constructStaticInfo(&(mCameraInfo[cameraId]), cameraId, false); |
Jiyoung Shin | c15a6b0 | 2012-06-05 01:08:14 -0700 | [diff] [blame] | 5358 | if (res != OK) { |
| 5359 | ALOGE("%s: Unable to fill in static info: %s (%d)", |
Sungjoong Kang | 13d8c7b | 2012-07-14 10:20:39 +0900 | [diff] [blame] | 5360 | __FUNCTION__, strerror(-res), res); |
Jiyoung Shin | c15a6b0 | 2012-06-05 01:08:14 -0700 | [diff] [blame] | 5361 | return res; |
| 5362 | } |
| 5363 | } |
Sungjoong Kang | 9dd63e1 | 2012-07-24 00:25:51 +0900 | [diff] [blame] | 5364 | info->static_camera_characteristics = mCameraInfo[cameraId]; |
Sungjoong Kang | 13d8c7b | 2012-07-14 10:20:39 +0900 | [diff] [blame] | 5365 | return NO_ERROR; |
Jiyoung Shin | c15a6b0 | 2012-06-05 01:08:14 -0700 | [diff] [blame] | 5366 | } |
| 5367 | |
| 5368 | #define SET_METHOD(m) m : HAL2_device_##m |
| 5369 | |
| 5370 | static camera2_device_ops_t camera2_device_ops = { |
| 5371 | SET_METHOD(set_request_queue_src_ops), |
| 5372 | SET_METHOD(notify_request_queue_not_empty), |
| 5373 | SET_METHOD(set_frame_queue_dst_ops), |
| 5374 | SET_METHOD(get_in_progress_count), |
| 5375 | SET_METHOD(flush_captures_in_progress), |
| 5376 | SET_METHOD(construct_default_request), |
| 5377 | SET_METHOD(allocate_stream), |
| 5378 | SET_METHOD(register_stream_buffers), |
| 5379 | SET_METHOD(release_stream), |
| 5380 | SET_METHOD(allocate_reprocess_stream), |
Eino-Ville Talvala | 2b0421d | 2012-09-04 13:41:55 -0700 | [diff] [blame] | 5381 | SET_METHOD(allocate_reprocess_stream_from_stream), |
Jiyoung Shin | c15a6b0 | 2012-06-05 01:08:14 -0700 | [diff] [blame] | 5382 | SET_METHOD(release_reprocess_stream), |
| 5383 | SET_METHOD(trigger_action), |
| 5384 | SET_METHOD(set_notify_callback), |
| 5385 | SET_METHOD(get_metadata_vendor_tag_ops), |
| 5386 | SET_METHOD(dump), |
| 5387 | }; |
| 5388 | |
| 5389 | #undef SET_METHOD |
| 5390 | |
| 5391 | |
| 5392 | static int HAL2_camera_device_open(const struct hw_module_t* module, |
| 5393 | const char *id, |
| 5394 | struct hw_device_t** device) |
| 5395 | { |
Sungjoong Kang | 9dd63e1 | 2012-07-24 00:25:51 +0900 | [diff] [blame] | 5396 | |
Jiyoung Shin | c15a6b0 | 2012-06-05 01:08:14 -0700 | [diff] [blame] | 5397 | |
| 5398 | int cameraId = atoi(id); |
Sungjoong Kang | 6044e50 | 2012-08-27 00:29:28 -0700 | [diff] [blame] | 5399 | int openInvalid = 0; |
Sungjoong Kang | 9dd63e1 | 2012-07-24 00:25:51 +0900 | [diff] [blame] | 5400 | |
Sungjoong Kang | b5237e6 | 2012-07-27 07:39:05 -0700 | [diff] [blame] | 5401 | g_camera_vaild = false; |
Sungjoong Kang | ad37861 | 2012-08-17 12:34:33 -0700 | [diff] [blame] | 5402 | ALOGV("\n\n>>> I'm Samsung's CameraHAL_2(ID:%d) <<<\n\n", cameraId); |
Jiyoung Shin | c15a6b0 | 2012-06-05 01:08:14 -0700 | [diff] [blame] | 5403 | if (cameraId < 0 || cameraId >= HAL2_getNumberOfCameras()) { |
Sungjoong Kang | 13d8c7b | 2012-07-14 10:20:39 +0900 | [diff] [blame] | 5404 | ALOGE("ERR(%s):Invalid camera ID %s", __FUNCTION__, id); |
Jiyoung Shin | c15a6b0 | 2012-06-05 01:08:14 -0700 | [diff] [blame] | 5405 | return -EINVAL; |
| 5406 | } |
| 5407 | |
Sungjoong Kang | ad37861 | 2012-08-17 12:34:33 -0700 | [diff] [blame] | 5408 | ALOGV("g_cam2_device : 0x%08x", (unsigned int)g_cam2_device); |
Jiyoung Shin | c15a6b0 | 2012-06-05 01:08:14 -0700 | [diff] [blame] | 5409 | if (g_cam2_device) { |
| 5410 | if (obj(g_cam2_device)->getCameraId() == cameraId) { |
Sungjoong Kang | 13d8c7b | 2012-07-14 10:20:39 +0900 | [diff] [blame] | 5411 | ALOGV("DEBUG(%s):returning existing camera ID %s", __FUNCTION__, id); |
Jiyoung Shin | c15a6b0 | 2012-06-05 01:08:14 -0700 | [diff] [blame] | 5412 | goto done; |
| 5413 | } else { |
Sungjoong Kang | 9dd63e1 | 2012-07-24 00:25:51 +0900 | [diff] [blame] | 5414 | |
| 5415 | while (g_cam2_device) |
| 5416 | usleep(10000); |
Jiyoung Shin | c15a6b0 | 2012-06-05 01:08:14 -0700 | [diff] [blame] | 5417 | } |
| 5418 | } |
| 5419 | |
| 5420 | g_cam2_device = (camera2_device_t *)malloc(sizeof(camera2_device_t)); |
Sungjoong Kang | ad37861 | 2012-08-17 12:34:33 -0700 | [diff] [blame] | 5421 | ALOGV("g_cam2_device : 0x%08x", (unsigned int)g_cam2_device); |
Sungjoong Kang | 9dd63e1 | 2012-07-24 00:25:51 +0900 | [diff] [blame] | 5422 | |
Jiyoung Shin | c15a6b0 | 2012-06-05 01:08:14 -0700 | [diff] [blame] | 5423 | if (!g_cam2_device) |
| 5424 | return -ENOMEM; |
| 5425 | |
| 5426 | g_cam2_device->common.tag = HARDWARE_DEVICE_TAG; |
| 5427 | g_cam2_device->common.version = CAMERA_DEVICE_API_VERSION_2_0; |
| 5428 | g_cam2_device->common.module = const_cast<hw_module_t *>(module); |
| 5429 | g_cam2_device->common.close = HAL2_camera_device_close; |
| 5430 | |
| 5431 | g_cam2_device->ops = &camera2_device_ops; |
| 5432 | |
Sungjoong Kang | 13d8c7b | 2012-07-14 10:20:39 +0900 | [diff] [blame] | 5433 | ALOGV("DEBUG(%s):open camera2 %s", __FUNCTION__, id); |
Jiyoung Shin | c15a6b0 | 2012-06-05 01:08:14 -0700 | [diff] [blame] | 5434 | |
Sungjoong Kang | 6044e50 | 2012-08-27 00:29:28 -0700 | [diff] [blame] | 5435 | g_cam2_device->priv = new ExynosCameraHWInterface2(cameraId, g_cam2_device, g_camera2[cameraId], &openInvalid); |
| 5436 | if (!openInvalid) { |
| 5437 | ALOGE("DEBUG(%s): ExynosCameraHWInterface2 creation failed(%d)", __FUNCTION__); |
Younghwan Joo | 6f19b6c | 2012-08-30 13:56:53 -0700 | [diff] [blame] | 5438 | return -ENODEV; |
Sungjoong Kang | 6044e50 | 2012-08-27 00:29:28 -0700 | [diff] [blame] | 5439 | } |
Jiyoung Shin | c15a6b0 | 2012-06-05 01:08:14 -0700 | [diff] [blame] | 5440 | done: |
| 5441 | *device = (hw_device_t *)g_cam2_device; |
Sungjoong Kang | 13d8c7b | 2012-07-14 10:20:39 +0900 | [diff] [blame] | 5442 | ALOGV("DEBUG(%s):opened camera2 %s (%p)", __FUNCTION__, id, *device); |
Sungjoong Kang | b5237e6 | 2012-07-27 07:39:05 -0700 | [diff] [blame] | 5443 | g_camera_vaild = true; |
Jiyoung Shin | c15a6b0 | 2012-06-05 01:08:14 -0700 | [diff] [blame] | 5444 | |
| 5445 | return 0; |
| 5446 | } |
| 5447 | |
| 5448 | |
| 5449 | static hw_module_methods_t camera_module_methods = { |
| 5450 | open : HAL2_camera_device_open |
| 5451 | }; |
| 5452 | |
| 5453 | extern "C" { |
| 5454 | struct camera_module HAL_MODULE_INFO_SYM = { |
| 5455 | common : { |
| 5456 | tag : HARDWARE_MODULE_TAG, |
| 5457 | module_api_version : CAMERA_MODULE_API_VERSION_2_0, |
| 5458 | hal_api_version : HARDWARE_HAL_API_VERSION, |
| 5459 | id : CAMERA_HARDWARE_MODULE_ID, |
| 5460 | name : "Exynos Camera HAL2", |
| 5461 | author : "Samsung Corporation", |
| 5462 | methods : &camera_module_methods, |
| 5463 | dso: NULL, |
| 5464 | reserved: {0}, |
| 5465 | }, |
| 5466 | get_number_of_cameras : HAL2_getNumberOfCameras, |
| 5467 | get_camera_info : HAL2_getCameraInfo |
| 5468 | }; |
| 5469 | } |
| 5470 | |
| 5471 | }; // namespace android |