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