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