Eino-Ville Talvala | 7fa43f3 | 2013-02-06 17:20:07 -0800 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2013 The Android Open Source Project |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
| 16 | |
| 17 | #define LOG_TAG "Camera3-Device" |
| 18 | #define ATRACE_TAG ATRACE_TAG_CAMERA |
| 19 | //#define LOG_NDEBUG 0 |
| 20 | //#define LOG_NNDEBUG 0 // Per-frame verbose logging |
| 21 | |
| 22 | #ifdef LOG_NNDEBUG |
| 23 | #define ALOGVV(...) ALOGV(__VA_ARGS__) |
| 24 | #else |
| 25 | #define ALOGVV(...) ((void)0) |
| 26 | #endif |
| 27 | |
Eino-Ville Talvala | b2058d1 | 2013-04-09 13:49:56 -0700 | [diff] [blame] | 28 | // Convenience macro for transient errors |
| 29 | #define CLOGE(fmt, ...) ALOGE("Camera %d: %s: " fmt, mId, __FUNCTION__, \ |
| 30 | ##__VA_ARGS__) |
| 31 | |
| 32 | // Convenience macros for transitioning to the error state |
| 33 | #define SET_ERR(fmt, ...) setErrorState( \ |
| 34 | "%s: " fmt, __FUNCTION__, \ |
| 35 | ##__VA_ARGS__) |
| 36 | #define SET_ERR_L(fmt, ...) setErrorStateLocked( \ |
| 37 | "%s: " fmt, __FUNCTION__, \ |
| 38 | ##__VA_ARGS__) |
| 39 | |
Colin Cross | e5729fa | 2014-03-21 15:04:25 -0700 | [diff] [blame] | 40 | #include <inttypes.h> |
| 41 | |
Eino-Ville Talvala | 7fa43f3 | 2013-02-06 17:20:07 -0800 | [diff] [blame] | 42 | #include <utils/Log.h> |
| 43 | #include <utils/Trace.h> |
| 44 | #include <utils/Timers.h> |
Eino-Ville Talvala | 7b82efe | 2013-07-25 17:12:35 -0700 | [diff] [blame] | 45 | |
Igor Murashkin | ff3e31d | 2013-10-23 16:40:06 -0700 | [diff] [blame] | 46 | #include "utils/CameraTraces.h" |
Eino-Ville Talvala | 7b82efe | 2013-07-25 17:12:35 -0700 | [diff] [blame] | 47 | #include "device3/Camera3Device.h" |
| 48 | #include "device3/Camera3OutputStream.h" |
| 49 | #include "device3/Camera3InputStream.h" |
| 50 | #include "device3/Camera3ZslStream.h" |
Eino-Ville Talvala | f76e027 | 2013-02-27 18:02:26 -0800 | [diff] [blame] | 51 | |
| 52 | using namespace android::camera3; |
Eino-Ville Talvala | 7fa43f3 | 2013-02-06 17:20:07 -0800 | [diff] [blame] | 53 | |
| 54 | namespace android { |
| 55 | |
Eino-Ville Talvala | 7fa43f3 | 2013-02-06 17:20:07 -0800 | [diff] [blame] | 56 | Camera3Device::Camera3Device(int id): |
| 57 | mId(id), |
Eino-Ville Talvala | f76e027 | 2013-02-27 18:02:26 -0800 | [diff] [blame] | 58 | mHal3Device(NULL), |
Eino-Ville Talvala | 7d346fa | 2013-03-11 14:13:50 -0700 | [diff] [blame] | 59 | mStatus(STATUS_UNINITIALIZED), |
Zhijun He | 204e329 | 2014-07-14 17:09:23 -0700 | [diff] [blame] | 60 | mUsePartialResult(false), |
| 61 | mNumPartialResults(1), |
Eino-Ville Talvala | 42368d9 | 2013-04-09 14:13:50 -0700 | [diff] [blame] | 62 | mNextResultFrameNumber(0), |
| 63 | mNextShutterFrameNumber(0), |
Eino-Ville Talvala | 7d346fa | 2013-03-11 14:13:50 -0700 | [diff] [blame] | 64 | mListener(NULL) |
Eino-Ville Talvala | 7fa43f3 | 2013-02-06 17:20:07 -0800 | [diff] [blame] | 65 | { |
| 66 | ATRACE_CALL(); |
| 67 | camera3_callback_ops::notify = &sNotify; |
| 68 | camera3_callback_ops::process_capture_result = &sProcessCaptureResult; |
| 69 | ALOGV("%s: Created device for camera %d", __FUNCTION__, id); |
| 70 | } |
| 71 | |
| 72 | Camera3Device::~Camera3Device() |
| 73 | { |
| 74 | ATRACE_CALL(); |
| 75 | ALOGV("%s: Tearing down for camera id %d", __FUNCTION__, mId); |
| 76 | disconnect(); |
| 77 | } |
| 78 | |
Igor Murashkin | 7138105 | 2013-03-04 14:53:08 -0800 | [diff] [blame] | 79 | int Camera3Device::getId() const { |
| 80 | return mId; |
| 81 | } |
| 82 | |
Eino-Ville Talvala | f76e027 | 2013-02-27 18:02:26 -0800 | [diff] [blame] | 83 | /** |
| 84 | * CameraDeviceBase interface |
| 85 | */ |
| 86 | |
Eino-Ville Talvala | 7fa43f3 | 2013-02-06 17:20:07 -0800 | [diff] [blame] | 87 | status_t Camera3Device::initialize(camera_module_t *module) |
| 88 | { |
| 89 | ATRACE_CALL(); |
Eino-Ville Talvala | f1e98d8 | 2013-09-06 09:32:43 -0700 | [diff] [blame] | 90 | Mutex::Autolock il(mInterfaceLock); |
Eino-Ville Talvala | f76e027 | 2013-02-27 18:02:26 -0800 | [diff] [blame] | 91 | Mutex::Autolock l(mLock); |
| 92 | |
Eino-Ville Talvala | 7fa43f3 | 2013-02-06 17:20:07 -0800 | [diff] [blame] | 93 | ALOGV("%s: Initializing device for camera %d", __FUNCTION__, mId); |
Eino-Ville Talvala | f76e027 | 2013-02-27 18:02:26 -0800 | [diff] [blame] | 94 | if (mStatus != STATUS_UNINITIALIZED) { |
Eino-Ville Talvala | b2058d1 | 2013-04-09 13:49:56 -0700 | [diff] [blame] | 95 | CLOGE("Already initialized!"); |
Eino-Ville Talvala | 7fa43f3 | 2013-02-06 17:20:07 -0800 | [diff] [blame] | 96 | return INVALID_OPERATION; |
| 97 | } |
| 98 | |
| 99 | /** Open HAL device */ |
| 100 | |
| 101 | status_t res; |
| 102 | String8 deviceName = String8::format("%d", mId); |
| 103 | |
| 104 | camera3_device_t *device; |
| 105 | |
Zhijun He | 213ce79 | 2013-11-19 08:45:15 -0800 | [diff] [blame] | 106 | ATRACE_BEGIN("camera3->open"); |
Eino-Ville Talvala | 7fa43f3 | 2013-02-06 17:20:07 -0800 | [diff] [blame] | 107 | res = module->common.methods->open(&module->common, deviceName.string(), |
| 108 | reinterpret_cast<hw_device_t**>(&device)); |
Zhijun He | 213ce79 | 2013-11-19 08:45:15 -0800 | [diff] [blame] | 109 | ATRACE_END(); |
Eino-Ville Talvala | 7fa43f3 | 2013-02-06 17:20:07 -0800 | [diff] [blame] | 110 | |
| 111 | if (res != OK) { |
Eino-Ville Talvala | b2058d1 | 2013-04-09 13:49:56 -0700 | [diff] [blame] | 112 | SET_ERR_L("Could not open camera: %s (%d)", strerror(-res), res); |
Eino-Ville Talvala | 7fa43f3 | 2013-02-06 17:20:07 -0800 | [diff] [blame] | 113 | return res; |
| 114 | } |
| 115 | |
| 116 | /** Cross-check device version */ |
Zhijun He | 95dd5ba | 2014-03-26 18:18:00 -0700 | [diff] [blame] | 117 | if (device->common.version < CAMERA_DEVICE_API_VERSION_3_0) { |
Eino-Ville Talvala | b2058d1 | 2013-04-09 13:49:56 -0700 | [diff] [blame] | 118 | SET_ERR_L("Could not open camera: " |
Zhijun He | 95dd5ba | 2014-03-26 18:18:00 -0700 | [diff] [blame] | 119 | "Camera device should be at least %x, reports %x instead", |
Eino-Ville Talvala | b2058d1 | 2013-04-09 13:49:56 -0700 | [diff] [blame] | 120 | CAMERA_DEVICE_API_VERSION_3_0, |
Eino-Ville Talvala | 7fa43f3 | 2013-02-06 17:20:07 -0800 | [diff] [blame] | 121 | device->common.version); |
| 122 | device->common.close(&device->common); |
| 123 | return BAD_VALUE; |
| 124 | } |
| 125 | |
| 126 | camera_info info; |
| 127 | res = module->get_camera_info(mId, &info); |
| 128 | if (res != OK) return res; |
| 129 | |
| 130 | if (info.device_version != device->common.version) { |
Eino-Ville Talvala | b2058d1 | 2013-04-09 13:49:56 -0700 | [diff] [blame] | 131 | SET_ERR_L("HAL reporting mismatched camera_info version (%x)" |
| 132 | " and device version (%x).", |
Zhijun He | 95dd5ba | 2014-03-26 18:18:00 -0700 | [diff] [blame] | 133 | info.device_version, device->common.version); |
Eino-Ville Talvala | 7fa43f3 | 2013-02-06 17:20:07 -0800 | [diff] [blame] | 134 | device->common.close(&device->common); |
| 135 | return BAD_VALUE; |
| 136 | } |
| 137 | |
| 138 | /** Initialize device with callback functions */ |
| 139 | |
Eino-Ville Talvala | 17a61ad | 2013-06-03 16:53:32 -0700 | [diff] [blame] | 140 | ATRACE_BEGIN("camera3->initialize"); |
Eino-Ville Talvala | 7fa43f3 | 2013-02-06 17:20:07 -0800 | [diff] [blame] | 141 | res = device->ops->initialize(device, this); |
Eino-Ville Talvala | 17a61ad | 2013-06-03 16:53:32 -0700 | [diff] [blame] | 142 | ATRACE_END(); |
| 143 | |
Eino-Ville Talvala | 7fa43f3 | 2013-02-06 17:20:07 -0800 | [diff] [blame] | 144 | if (res != OK) { |
Eino-Ville Talvala | b2058d1 | 2013-04-09 13:49:56 -0700 | [diff] [blame] | 145 | SET_ERR_L("Unable to initialize HAL device: %s (%d)", |
| 146 | strerror(-res), res); |
Eino-Ville Talvala | 7fa43f3 | 2013-02-06 17:20:07 -0800 | [diff] [blame] | 147 | device->common.close(&device->common); |
| 148 | return BAD_VALUE; |
| 149 | } |
| 150 | |
Eino-Ville Talvala | f1e98d8 | 2013-09-06 09:32:43 -0700 | [diff] [blame] | 151 | /** Start up status tracker thread */ |
| 152 | mStatusTracker = new StatusTracker(this); |
| 153 | res = mStatusTracker->run(String8::format("C3Dev-%d-Status", mId).string()); |
| 154 | if (res != OK) { |
| 155 | SET_ERR_L("Unable to start status tracking thread: %s (%d)", |
| 156 | strerror(-res), res); |
| 157 | device->common.close(&device->common); |
| 158 | mStatusTracker.clear(); |
| 159 | return res; |
| 160 | } |
| 161 | |
Eino-Ville Talvala | 7fa43f3 | 2013-02-06 17:20:07 -0800 | [diff] [blame] | 162 | /** Start up request queue thread */ |
| 163 | |
Eino-Ville Talvala | f1e98d8 | 2013-09-06 09:32:43 -0700 | [diff] [blame] | 164 | mRequestThread = new RequestThread(this, mStatusTracker, device); |
Eino-Ville Talvala | f76e027 | 2013-02-27 18:02:26 -0800 | [diff] [blame] | 165 | res = mRequestThread->run(String8::format("C3Dev-%d-ReqQueue", mId).string()); |
Eino-Ville Talvala | 7fa43f3 | 2013-02-06 17:20:07 -0800 | [diff] [blame] | 166 | if (res != OK) { |
Eino-Ville Talvala | b2058d1 | 2013-04-09 13:49:56 -0700 | [diff] [blame] | 167 | SET_ERR_L("Unable to start request queue thread: %s (%d)", |
| 168 | strerror(-res), res); |
Eino-Ville Talvala | 7fa43f3 | 2013-02-06 17:20:07 -0800 | [diff] [blame] | 169 | device->common.close(&device->common); |
Eino-Ville Talvala | f76e027 | 2013-02-27 18:02:26 -0800 | [diff] [blame] | 170 | mRequestThread.clear(); |
Eino-Ville Talvala | 7fa43f3 | 2013-02-06 17:20:07 -0800 | [diff] [blame] | 171 | return res; |
| 172 | } |
| 173 | |
| 174 | /** Everything is good to go */ |
| 175 | |
Yin-Chia Yeh | cd8fce8 | 2014-06-18 10:51:34 -0700 | [diff] [blame] | 176 | mDeviceVersion = device->common.version; |
Eino-Ville Talvala | 7fa43f3 | 2013-02-06 17:20:07 -0800 | [diff] [blame] | 177 | mDeviceInfo = info.static_camera_characteristics; |
| 178 | mHal3Device = device; |
Eino-Ville Talvala | f1e98d8 | 2013-09-06 09:32:43 -0700 | [diff] [blame] | 179 | mStatus = STATUS_UNCONFIGURED; |
Eino-Ville Talvala | f76e027 | 2013-02-27 18:02:26 -0800 | [diff] [blame] | 180 | mNextStreamId = 0; |
Eino-Ville Talvala | ea26c77 | 2013-06-11 16:04:06 -0700 | [diff] [blame] | 181 | mNeedConfig = true; |
Eino-Ville Talvala | f1e98d8 | 2013-09-06 09:32:43 -0700 | [diff] [blame] | 182 | mPauseStateNotify = false; |
Eino-Ville Talvala | 7fa43f3 | 2013-02-06 17:20:07 -0800 | [diff] [blame] | 183 | |
Eino-Ville Talvala | fd6ecdd | 2013-10-11 09:51:09 -0700 | [diff] [blame] | 184 | // Will the HAL be sending in early partial result metadata? |
Zhijun He | 204e329 | 2014-07-14 17:09:23 -0700 | [diff] [blame] | 185 | if (mDeviceVersion >= CAMERA_DEVICE_API_VERSION_3_2) { |
| 186 | camera_metadata_entry partialResultsCount = |
| 187 | mDeviceInfo.find(ANDROID_REQUEST_PARTIAL_RESULT_COUNT); |
| 188 | if (partialResultsCount.count > 0) { |
| 189 | mNumPartialResults = partialResultsCount.data.i32[0]; |
| 190 | mUsePartialResult = (mNumPartialResults > 1); |
| 191 | } |
| 192 | } else { |
| 193 | camera_metadata_entry partialResultsQuirk = |
| 194 | mDeviceInfo.find(ANDROID_QUIRKS_USE_PARTIAL_RESULT); |
| 195 | if (partialResultsQuirk.count > 0 && partialResultsQuirk.data.u8[0] == 1) { |
| 196 | mUsePartialResult = true; |
| 197 | } |
Eino-Ville Talvala | fd6ecdd | 2013-10-11 09:51:09 -0700 | [diff] [blame] | 198 | } |
| 199 | |
Eino-Ville Talvala | 7fa43f3 | 2013-02-06 17:20:07 -0800 | [diff] [blame] | 200 | return OK; |
| 201 | } |
| 202 | |
| 203 | status_t Camera3Device::disconnect() { |
| 204 | ATRACE_CALL(); |
Eino-Ville Talvala | f1e98d8 | 2013-09-06 09:32:43 -0700 | [diff] [blame] | 205 | Mutex::Autolock il(mInterfaceLock); |
Eino-Ville Talvala | 7fa43f3 | 2013-02-06 17:20:07 -0800 | [diff] [blame] | 206 | |
Eino-Ville Talvala | f76e027 | 2013-02-27 18:02:26 -0800 | [diff] [blame] | 207 | ALOGV("%s: E", __FUNCTION__); |
| 208 | |
Eino-Ville Talvala | 214a17f | 2013-06-13 12:20:02 -0700 | [diff] [blame] | 209 | status_t res = OK; |
Eino-Ville Talvala | f76e027 | 2013-02-27 18:02:26 -0800 | [diff] [blame] | 210 | |
Eino-Ville Talvala | f1e98d8 | 2013-09-06 09:32:43 -0700 | [diff] [blame] | 211 | { |
| 212 | Mutex::Autolock l(mLock); |
| 213 | if (mStatus == STATUS_UNINITIALIZED) return res; |
| 214 | |
| 215 | if (mStatus == STATUS_ACTIVE || |
| 216 | (mStatus == STATUS_ERROR && mRequestThread != NULL)) { |
| 217 | res = mRequestThread->clearRepeatingRequests(); |
Eino-Ville Talvala | 214a17f | 2013-06-13 12:20:02 -0700 | [diff] [blame] | 218 | if (res != OK) { |
Eino-Ville Talvala | f1e98d8 | 2013-09-06 09:32:43 -0700 | [diff] [blame] | 219 | SET_ERR_L("Can't stop streaming"); |
Eino-Ville Talvala | 214a17f | 2013-06-13 12:20:02 -0700 | [diff] [blame] | 220 | // Continue to close device even in case of error |
Eino-Ville Talvala | f1e98d8 | 2013-09-06 09:32:43 -0700 | [diff] [blame] | 221 | } else { |
| 222 | res = waitUntilStateThenRelock(/*active*/ false, kShutdownTimeout); |
| 223 | if (res != OK) { |
| 224 | SET_ERR_L("Timeout waiting for HAL to drain"); |
| 225 | // Continue to close device even in case of error |
| 226 | } |
Eino-Ville Talvala | 214a17f | 2013-06-13 12:20:02 -0700 | [diff] [blame] | 227 | } |
Eino-Ville Talvala | f76e027 | 2013-02-27 18:02:26 -0800 | [diff] [blame] | 228 | } |
Eino-Ville Talvala | f76e027 | 2013-02-27 18:02:26 -0800 | [diff] [blame] | 229 | |
Eino-Ville Talvala | f1e98d8 | 2013-09-06 09:32:43 -0700 | [diff] [blame] | 230 | if (mStatus == STATUS_ERROR) { |
| 231 | CLOGE("Shutting down in an error state"); |
Eino-Ville Talvala | 214a17f | 2013-06-13 12:20:02 -0700 | [diff] [blame] | 232 | } |
Eino-Ville Talvala | f1e98d8 | 2013-09-06 09:32:43 -0700 | [diff] [blame] | 233 | |
| 234 | if (mStatusTracker != NULL) { |
| 235 | mStatusTracker->requestExit(); |
| 236 | } |
| 237 | |
| 238 | if (mRequestThread != NULL) { |
| 239 | mRequestThread->requestExit(); |
| 240 | } |
| 241 | |
| 242 | mOutputStreams.clear(); |
| 243 | mInputStream.clear(); |
| 244 | } |
| 245 | |
| 246 | // Joining done without holding mLock, otherwise deadlocks may ensue |
| 247 | // as the threads try to access parent state |
| 248 | if (mRequestThread != NULL && mStatus != STATUS_ERROR) { |
| 249 | // HAL may be in a bad state, so waiting for request thread |
| 250 | // (which may be stuck in the HAL processCaptureRequest call) |
| 251 | // could be dangerous. |
| 252 | mRequestThread->join(); |
| 253 | } |
| 254 | |
| 255 | if (mStatusTracker != NULL) { |
| 256 | mStatusTracker->join(); |
| 257 | } |
| 258 | |
| 259 | { |
| 260 | Mutex::Autolock l(mLock); |
| 261 | |
Eino-Ville Talvala | f76e027 | 2013-02-27 18:02:26 -0800 | [diff] [blame] | 262 | mRequestThread.clear(); |
Eino-Ville Talvala | f1e98d8 | 2013-09-06 09:32:43 -0700 | [diff] [blame] | 263 | mStatusTracker.clear(); |
Eino-Ville Talvala | f76e027 | 2013-02-27 18:02:26 -0800 | [diff] [blame] | 264 | |
Eino-Ville Talvala | f1e98d8 | 2013-09-06 09:32:43 -0700 | [diff] [blame] | 265 | if (mHal3Device != NULL) { |
Zhijun He | 213ce79 | 2013-11-19 08:45:15 -0800 | [diff] [blame] | 266 | ATRACE_BEGIN("camera3->close"); |
Eino-Ville Talvala | f1e98d8 | 2013-09-06 09:32:43 -0700 | [diff] [blame] | 267 | mHal3Device->common.close(&mHal3Device->common); |
Zhijun He | 213ce79 | 2013-11-19 08:45:15 -0800 | [diff] [blame] | 268 | ATRACE_END(); |
Eino-Ville Talvala | f1e98d8 | 2013-09-06 09:32:43 -0700 | [diff] [blame] | 269 | mHal3Device = NULL; |
| 270 | } |
Eino-Ville Talvala | f76e027 | 2013-02-27 18:02:26 -0800 | [diff] [blame] | 271 | |
Eino-Ville Talvala | f1e98d8 | 2013-09-06 09:32:43 -0700 | [diff] [blame] | 272 | mStatus = STATUS_UNINITIALIZED; |
| 273 | } |
Eino-Ville Talvala | f76e027 | 2013-02-27 18:02:26 -0800 | [diff] [blame] | 274 | |
| 275 | ALOGV("%s: X", __FUNCTION__); |
Eino-Ville Talvala | 214a17f | 2013-06-13 12:20:02 -0700 | [diff] [blame] | 276 | return res; |
Eino-Ville Talvala | 7fa43f3 | 2013-02-06 17:20:07 -0800 | [diff] [blame] | 277 | } |
| 278 | |
Eino-Ville Talvala | f1e98d8 | 2013-09-06 09:32:43 -0700 | [diff] [blame] | 279 | // For dumping/debugging only - |
| 280 | // try to acquire a lock a few times, eventually give up to proceed with |
| 281 | // debug/dump operations |
| 282 | bool Camera3Device::tryLockSpinRightRound(Mutex& lock) { |
| 283 | bool gotLock = false; |
| 284 | for (size_t i = 0; i < kDumpLockAttempts; ++i) { |
| 285 | if (lock.tryLock() == NO_ERROR) { |
| 286 | gotLock = true; |
| 287 | break; |
| 288 | } else { |
| 289 | usleep(kDumpSleepDuration); |
| 290 | } |
| 291 | } |
| 292 | return gotLock; |
| 293 | } |
| 294 | |
Yin-Chia Yeh | cd8fce8 | 2014-06-18 10:51:34 -0700 | [diff] [blame] | 295 | Camera3Device::Size Camera3Device::getMaxJpegResolution() const { |
| 296 | int32_t maxJpegWidth = 0, maxJpegHeight = 0; |
| 297 | if (mDeviceVersion >= CAMERA_DEVICE_API_VERSION_3_2) { |
| 298 | const int STREAM_CONFIGURATION_SIZE = 4; |
| 299 | const int STREAM_FORMAT_OFFSET = 0; |
| 300 | const int STREAM_WIDTH_OFFSET = 1; |
| 301 | const int STREAM_HEIGHT_OFFSET = 2; |
| 302 | const int STREAM_IS_INPUT_OFFSET = 3; |
| 303 | camera_metadata_ro_entry_t availableStreamConfigs = |
| 304 | mDeviceInfo.find(ANDROID_SCALER_AVAILABLE_STREAM_CONFIGURATIONS); |
| 305 | if (availableStreamConfigs.count == 0 || |
| 306 | availableStreamConfigs.count % STREAM_CONFIGURATION_SIZE != 0) { |
| 307 | return Size(0, 0); |
| 308 | } |
| 309 | |
| 310 | // Get max jpeg size (area-wise). |
| 311 | for (size_t i=0; i < availableStreamConfigs.count; i+= STREAM_CONFIGURATION_SIZE) { |
| 312 | int32_t format = availableStreamConfigs.data.i32[i + STREAM_FORMAT_OFFSET]; |
| 313 | int32_t width = availableStreamConfigs.data.i32[i + STREAM_WIDTH_OFFSET]; |
| 314 | int32_t height = availableStreamConfigs.data.i32[i + STREAM_HEIGHT_OFFSET]; |
| 315 | int32_t isInput = availableStreamConfigs.data.i32[i + STREAM_IS_INPUT_OFFSET]; |
| 316 | if (isInput == ANDROID_SCALER_AVAILABLE_STREAM_CONFIGURATIONS_OUTPUT |
| 317 | && format == HAL_PIXEL_FORMAT_BLOB && |
| 318 | (width * height > maxJpegWidth * maxJpegHeight)) { |
| 319 | maxJpegWidth = width; |
| 320 | maxJpegHeight = height; |
| 321 | } |
| 322 | } |
| 323 | } else { |
| 324 | camera_metadata_ro_entry availableJpegSizes = |
| 325 | mDeviceInfo.find(ANDROID_SCALER_AVAILABLE_JPEG_SIZES); |
| 326 | if (availableJpegSizes.count == 0 || availableJpegSizes.count % 2 != 0) { |
| 327 | return Size(0, 0); |
| 328 | } |
| 329 | |
| 330 | // Get max jpeg size (area-wise). |
| 331 | for (size_t i = 0; i < availableJpegSizes.count; i += 2) { |
| 332 | if ((availableJpegSizes.data.i32[i] * availableJpegSizes.data.i32[i + 1]) |
| 333 | > (maxJpegWidth * maxJpegHeight)) { |
| 334 | maxJpegWidth = availableJpegSizes.data.i32[i]; |
| 335 | maxJpegHeight = availableJpegSizes.data.i32[i + 1]; |
| 336 | } |
| 337 | } |
| 338 | } |
| 339 | return Size(maxJpegWidth, maxJpegHeight); |
| 340 | } |
| 341 | |
Zhijun He | f7da096 | 2014-04-24 13:27:56 -0700 | [diff] [blame] | 342 | ssize_t Camera3Device::getJpegBufferSize(uint32_t width, uint32_t height) const { |
Yin-Chia Yeh | cd8fce8 | 2014-06-18 10:51:34 -0700 | [diff] [blame] | 343 | // Get max jpeg size (area-wise). |
| 344 | Size maxJpegResolution = getMaxJpegResolution(); |
| 345 | if (maxJpegResolution.width == 0) { |
Zhijun He | f7da096 | 2014-04-24 13:27:56 -0700 | [diff] [blame] | 346 | ALOGE("%s: Camera %d: Can't find find valid available jpeg sizes in static metadata!", |
| 347 | __FUNCTION__, mId); |
| 348 | return BAD_VALUE; |
| 349 | } |
| 350 | |
Zhijun He | f7da096 | 2014-04-24 13:27:56 -0700 | [diff] [blame] | 351 | // Get max jpeg buffer size |
| 352 | ssize_t maxJpegBufferSize = 0; |
Yin-Chia Yeh | cd8fce8 | 2014-06-18 10:51:34 -0700 | [diff] [blame] | 353 | camera_metadata_ro_entry jpegBufMaxSize = mDeviceInfo.find(ANDROID_JPEG_MAX_SIZE); |
| 354 | if (jpegBufMaxSize.count == 0) { |
Zhijun He | f7da096 | 2014-04-24 13:27:56 -0700 | [diff] [blame] | 355 | ALOGE("%s: Camera %d: Can't find maximum JPEG size in static metadata!", __FUNCTION__, mId); |
| 356 | return BAD_VALUE; |
| 357 | } |
Yin-Chia Yeh | cd8fce8 | 2014-06-18 10:51:34 -0700 | [diff] [blame] | 358 | maxJpegBufferSize = jpegBufMaxSize.data.i32[0]; |
Zhijun He | f7da096 | 2014-04-24 13:27:56 -0700 | [diff] [blame] | 359 | |
| 360 | // Calculate final jpeg buffer size for the given resolution. |
Yin-Chia Yeh | cd8fce8 | 2014-06-18 10:51:34 -0700 | [diff] [blame] | 361 | float scaleFactor = ((float) (width * height)) / |
| 362 | (maxJpegResolution.width * maxJpegResolution.height); |
Zhijun He | f7da096 | 2014-04-24 13:27:56 -0700 | [diff] [blame] | 363 | ssize_t jpegBufferSize = scaleFactor * maxJpegBufferSize; |
| 364 | // Bound the buffer size to [MIN_JPEG_BUFFER_SIZE, maxJpegBufferSize]. |
| 365 | if (jpegBufferSize > maxJpegBufferSize) { |
| 366 | jpegBufferSize = maxJpegBufferSize; |
| 367 | } else if (jpegBufferSize < kMinJpegBufferSize) { |
| 368 | jpegBufferSize = kMinJpegBufferSize; |
| 369 | } |
| 370 | |
| 371 | return jpegBufferSize; |
| 372 | } |
| 373 | |
Eino-Ville Talvala | 7fa43f3 | 2013-02-06 17:20:07 -0800 | [diff] [blame] | 374 | status_t Camera3Device::dump(int fd, const Vector<String16> &args) { |
| 375 | ATRACE_CALL(); |
| 376 | (void)args; |
Eino-Ville Talvala | f1e98d8 | 2013-09-06 09:32:43 -0700 | [diff] [blame] | 377 | |
| 378 | // Try to lock, but continue in case of failure (to avoid blocking in |
| 379 | // deadlocks) |
| 380 | bool gotInterfaceLock = tryLockSpinRightRound(mInterfaceLock); |
| 381 | bool gotLock = tryLockSpinRightRound(mLock); |
| 382 | |
| 383 | ALOGW_IF(!gotInterfaceLock, |
| 384 | "Camera %d: %s: Unable to lock interface lock, proceeding anyway", |
| 385 | mId, __FUNCTION__); |
| 386 | ALOGW_IF(!gotLock, |
| 387 | "Camera %d: %s: Unable to lock main lock, proceeding anyway", |
| 388 | mId, __FUNCTION__); |
| 389 | |
Eino-Ville Talvala | f76e027 | 2013-02-27 18:02:26 -0800 | [diff] [blame] | 390 | String8 lines; |
Eino-Ville Talvala | 7fa43f3 | 2013-02-06 17:20:07 -0800 | [diff] [blame] | 391 | |
Eino-Ville Talvala | f76e027 | 2013-02-27 18:02:26 -0800 | [diff] [blame] | 392 | const char *status = |
| 393 | mStatus == STATUS_ERROR ? "ERROR" : |
| 394 | mStatus == STATUS_UNINITIALIZED ? "UNINITIALIZED" : |
Eino-Ville Talvala | f1e98d8 | 2013-09-06 09:32:43 -0700 | [diff] [blame] | 395 | mStatus == STATUS_UNCONFIGURED ? "UNCONFIGURED" : |
| 396 | mStatus == STATUS_CONFIGURED ? "CONFIGURED" : |
Eino-Ville Talvala | f76e027 | 2013-02-27 18:02:26 -0800 | [diff] [blame] | 397 | mStatus == STATUS_ACTIVE ? "ACTIVE" : |
| 398 | "Unknown"; |
Eino-Ville Talvala | f1e98d8 | 2013-09-06 09:32:43 -0700 | [diff] [blame] | 399 | |
Eino-Ville Talvala | f76e027 | 2013-02-27 18:02:26 -0800 | [diff] [blame] | 400 | lines.appendFormat(" Device status: %s\n", status); |
Eino-Ville Talvala | b2058d1 | 2013-04-09 13:49:56 -0700 | [diff] [blame] | 401 | if (mStatus == STATUS_ERROR) { |
| 402 | lines.appendFormat(" Error cause: %s\n", mErrorCause.string()); |
| 403 | } |
Eino-Ville Talvala | f76e027 | 2013-02-27 18:02:26 -0800 | [diff] [blame] | 404 | lines.appendFormat(" Stream configuration:\n"); |
| 405 | |
| 406 | if (mInputStream != NULL) { |
| 407 | write(fd, lines.string(), lines.size()); |
| 408 | mInputStream->dump(fd, args); |
| 409 | } else { |
| 410 | lines.appendFormat(" No input stream.\n"); |
| 411 | write(fd, lines.string(), lines.size()); |
| 412 | } |
| 413 | for (size_t i = 0; i < mOutputStreams.size(); i++) { |
| 414 | mOutputStreams[i]->dump(fd,args); |
| 415 | } |
| 416 | |
Eino-Ville Talvala | 42368d9 | 2013-04-09 14:13:50 -0700 | [diff] [blame] | 417 | lines = String8(" In-flight requests:\n"); |
| 418 | if (mInFlightMap.size() == 0) { |
| 419 | lines.append(" None\n"); |
| 420 | } else { |
| 421 | for (size_t i = 0; i < mInFlightMap.size(); i++) { |
| 422 | InFlightRequest r = mInFlightMap.valueAt(i); |
Colin Cross | e5729fa | 2014-03-21 15:04:25 -0700 | [diff] [blame] | 423 | lines.appendFormat(" Frame %d | Timestamp: %" PRId64 ", metadata" |
Eino-Ville Talvala | 42368d9 | 2013-04-09 14:13:50 -0700 | [diff] [blame] | 424 | " arrived: %s, buffers left: %d\n", mInFlightMap.keyAt(i), |
| 425 | r.captureTimestamp, r.haveResultMetadata ? "true" : "false", |
| 426 | r.numBuffersLeft); |
| 427 | } |
| 428 | } |
| 429 | write(fd, lines.string(), lines.size()); |
| 430 | |
Igor Murashkin | 1e479c0 | 2013-09-06 16:55:14 -0700 | [diff] [blame] | 431 | { |
| 432 | lines = String8(" Last request sent:\n"); |
| 433 | write(fd, lines.string(), lines.size()); |
| 434 | |
Eino-Ville Talvala | f1e98d8 | 2013-09-06 09:32:43 -0700 | [diff] [blame] | 435 | CameraMetadata lastRequest = getLatestRequestLocked(); |
Igor Murashkin | 1e479c0 | 2013-09-06 16:55:14 -0700 | [diff] [blame] | 436 | lastRequest.dump(fd, /*verbosity*/2, /*indentation*/6); |
| 437 | } |
| 438 | |
Eino-Ville Talvala | f76e027 | 2013-02-27 18:02:26 -0800 | [diff] [blame] | 439 | if (mHal3Device != NULL) { |
Eino-Ville Talvala | 42368d9 | 2013-04-09 14:13:50 -0700 | [diff] [blame] | 440 | lines = String8(" HAL device dump:\n"); |
Eino-Ville Talvala | f76e027 | 2013-02-27 18:02:26 -0800 | [diff] [blame] | 441 | write(fd, lines.string(), lines.size()); |
| 442 | mHal3Device->ops->dump(mHal3Device, fd); |
| 443 | } |
Eino-Ville Talvala | 7fa43f3 | 2013-02-06 17:20:07 -0800 | [diff] [blame] | 444 | |
Eino-Ville Talvala | f1e98d8 | 2013-09-06 09:32:43 -0700 | [diff] [blame] | 445 | if (gotLock) mLock.unlock(); |
| 446 | if (gotInterfaceLock) mInterfaceLock.unlock(); |
| 447 | |
Eino-Ville Talvala | 7fa43f3 | 2013-02-06 17:20:07 -0800 | [diff] [blame] | 448 | return OK; |
| 449 | } |
| 450 | |
| 451 | const CameraMetadata& Camera3Device::info() const { |
| 452 | ALOGVV("%s: E", __FUNCTION__); |
Eino-Ville Talvala | f76e027 | 2013-02-27 18:02:26 -0800 | [diff] [blame] | 453 | if (CC_UNLIKELY(mStatus == STATUS_UNINITIALIZED || |
| 454 | mStatus == STATUS_ERROR)) { |
Eino-Ville Talvala | b2058d1 | 2013-04-09 13:49:56 -0700 | [diff] [blame] | 455 | ALOGW("%s: Access to static info %s!", __FUNCTION__, |
Eino-Ville Talvala | f76e027 | 2013-02-27 18:02:26 -0800 | [diff] [blame] | 456 | mStatus == STATUS_ERROR ? |
| 457 | "when in error state" : "before init"); |
| 458 | } |
Eino-Ville Talvala | 7fa43f3 | 2013-02-06 17:20:07 -0800 | [diff] [blame] | 459 | return mDeviceInfo; |
| 460 | } |
| 461 | |
Jianing Wei | 90e59c9 | 2014-03-12 18:29:36 -0700 | [diff] [blame] | 462 | status_t Camera3Device::checkStatusOkToCaptureLocked() { |
| 463 | switch (mStatus) { |
| 464 | case STATUS_ERROR: |
| 465 | CLOGE("Device has encountered a serious error"); |
| 466 | return INVALID_OPERATION; |
| 467 | case STATUS_UNINITIALIZED: |
| 468 | CLOGE("Device not initialized"); |
| 469 | return INVALID_OPERATION; |
| 470 | case STATUS_UNCONFIGURED: |
| 471 | case STATUS_CONFIGURED: |
| 472 | case STATUS_ACTIVE: |
| 473 | // OK |
| 474 | break; |
| 475 | default: |
| 476 | SET_ERR_L("Unexpected status: %d", mStatus); |
| 477 | return INVALID_OPERATION; |
| 478 | } |
| 479 | return OK; |
| 480 | } |
| 481 | |
| 482 | status_t Camera3Device::convertMetadataListToRequestListLocked( |
| 483 | const List<const CameraMetadata> &metadataList, RequestList *requestList) { |
| 484 | if (requestList == NULL) { |
| 485 | CLOGE("requestList cannot be NULL."); |
| 486 | return BAD_VALUE; |
| 487 | } |
| 488 | |
Jianing Wei | cb0652e | 2014-03-12 18:29:36 -0700 | [diff] [blame] | 489 | int32_t burstId = 0; |
Jianing Wei | 90e59c9 | 2014-03-12 18:29:36 -0700 | [diff] [blame] | 490 | for (List<const CameraMetadata>::const_iterator it = metadataList.begin(); |
| 491 | it != metadataList.end(); ++it) { |
| 492 | sp<CaptureRequest> newRequest = setUpRequestLocked(*it); |
| 493 | if (newRequest == 0) { |
| 494 | CLOGE("Can't create capture request"); |
| 495 | return BAD_VALUE; |
| 496 | } |
Jianing Wei | cb0652e | 2014-03-12 18:29:36 -0700 | [diff] [blame] | 497 | |
| 498 | // Setup burst Id and request Id |
| 499 | newRequest->mResultExtras.burstId = burstId++; |
| 500 | if (it->exists(ANDROID_REQUEST_ID)) { |
| 501 | if (it->find(ANDROID_REQUEST_ID).count == 0) { |
| 502 | CLOGE("RequestID entry exists; but must not be empty in metadata"); |
| 503 | return BAD_VALUE; |
| 504 | } |
| 505 | newRequest->mResultExtras.requestId = it->find(ANDROID_REQUEST_ID).data.i32[0]; |
| 506 | } else { |
| 507 | CLOGE("RequestID does not exist in metadata"); |
| 508 | return BAD_VALUE; |
| 509 | } |
| 510 | |
Jianing Wei | 90e59c9 | 2014-03-12 18:29:36 -0700 | [diff] [blame] | 511 | requestList->push_back(newRequest); |
Jianing Wei | 2d6bb3f | 2014-04-11 10:00:31 -0700 | [diff] [blame] | 512 | |
| 513 | ALOGV("%s: requestId = %" PRId32, __FUNCTION__, newRequest->mResultExtras.requestId); |
Jianing Wei | 90e59c9 | 2014-03-12 18:29:36 -0700 | [diff] [blame] | 514 | } |
| 515 | return OK; |
| 516 | } |
| 517 | |
Jianing Wei | cb0652e | 2014-03-12 18:29:36 -0700 | [diff] [blame] | 518 | status_t Camera3Device::capture(CameraMetadata &request, int64_t* /*lastFrameNumber*/) { |
Eino-Ville Talvala | 7fa43f3 | 2013-02-06 17:20:07 -0800 | [diff] [blame] | 519 | ATRACE_CALL(); |
Eino-Ville Talvala | 7fa43f3 | 2013-02-06 17:20:07 -0800 | [diff] [blame] | 520 | |
Jianing Wei | 2d6bb3f | 2014-04-11 10:00:31 -0700 | [diff] [blame] | 521 | List<const CameraMetadata> requests; |
| 522 | requests.push_back(request); |
| 523 | return captureList(requests, /*lastFrameNumber*/NULL); |
Eino-Ville Talvala | 7fa43f3 | 2013-02-06 17:20:07 -0800 | [diff] [blame] | 524 | } |
| 525 | |
Jianing Wei | 90e59c9 | 2014-03-12 18:29:36 -0700 | [diff] [blame] | 526 | status_t Camera3Device::submitRequestsHelper( |
Jianing Wei | 2d6bb3f | 2014-04-11 10:00:31 -0700 | [diff] [blame] | 527 | const List<const CameraMetadata> &requests, bool repeating, |
| 528 | /*out*/ |
| 529 | int64_t *lastFrameNumber) { |
Jianing Wei | 90e59c9 | 2014-03-12 18:29:36 -0700 | [diff] [blame] | 530 | ATRACE_CALL(); |
| 531 | Mutex::Autolock il(mInterfaceLock); |
| 532 | Mutex::Autolock l(mLock); |
| 533 | |
| 534 | status_t res = checkStatusOkToCaptureLocked(); |
| 535 | if (res != OK) { |
| 536 | // error logged by previous call |
| 537 | return res; |
| 538 | } |
| 539 | |
| 540 | RequestList requestList; |
| 541 | |
| 542 | res = convertMetadataListToRequestListLocked(requests, /*out*/&requestList); |
| 543 | if (res != OK) { |
| 544 | // error logged by previous call |
| 545 | return res; |
| 546 | } |
| 547 | |
| 548 | if (repeating) { |
Jianing Wei | 2d6bb3f | 2014-04-11 10:00:31 -0700 | [diff] [blame] | 549 | res = mRequestThread->setRepeatingRequests(requestList, lastFrameNumber); |
Jianing Wei | 90e59c9 | 2014-03-12 18:29:36 -0700 | [diff] [blame] | 550 | } else { |
Jianing Wei | 2d6bb3f | 2014-04-11 10:00:31 -0700 | [diff] [blame] | 551 | res = mRequestThread->queueRequestList(requestList, lastFrameNumber); |
Jianing Wei | 90e59c9 | 2014-03-12 18:29:36 -0700 | [diff] [blame] | 552 | } |
| 553 | |
| 554 | if (res == OK) { |
| 555 | waitUntilStateThenRelock(/*active*/true, kActiveTimeout); |
| 556 | if (res != OK) { |
| 557 | SET_ERR_L("Can't transition to active in %f seconds!", |
| 558 | kActiveTimeout/1e9); |
| 559 | } |
Jianing Wei | 2d6bb3f | 2014-04-11 10:00:31 -0700 | [diff] [blame] | 560 | ALOGV("Camera %d: Capture request %" PRId32 " enqueued", mId, |
| 561 | (*(requestList.begin()))->mResultExtras.requestId); |
Jianing Wei | 90e59c9 | 2014-03-12 18:29:36 -0700 | [diff] [blame] | 562 | } else { |
| 563 | CLOGE("Cannot queue request. Impossible."); |
| 564 | return BAD_VALUE; |
| 565 | } |
| 566 | |
| 567 | return res; |
| 568 | } |
| 569 | |
Jianing Wei | cb0652e | 2014-03-12 18:29:36 -0700 | [diff] [blame] | 570 | status_t Camera3Device::captureList(const List<const CameraMetadata> &requests, |
| 571 | int64_t *lastFrameNumber) { |
Jianing Wei | 90e59c9 | 2014-03-12 18:29:36 -0700 | [diff] [blame] | 572 | ATRACE_CALL(); |
| 573 | |
Jianing Wei | cb0652e | 2014-03-12 18:29:36 -0700 | [diff] [blame] | 574 | return submitRequestsHelper(requests, /*repeating*/false, lastFrameNumber); |
Jianing Wei | 90e59c9 | 2014-03-12 18:29:36 -0700 | [diff] [blame] | 575 | } |
Eino-Ville Talvala | 7fa43f3 | 2013-02-06 17:20:07 -0800 | [diff] [blame] | 576 | |
Jianing Wei | cb0652e | 2014-03-12 18:29:36 -0700 | [diff] [blame] | 577 | status_t Camera3Device::setStreamingRequest(const CameraMetadata &request, |
| 578 | int64_t* /*lastFrameNumber*/) { |
Eino-Ville Talvala | 7fa43f3 | 2013-02-06 17:20:07 -0800 | [diff] [blame] | 579 | ATRACE_CALL(); |
Eino-Ville Talvala | 7fa43f3 | 2013-02-06 17:20:07 -0800 | [diff] [blame] | 580 | |
Jianing Wei | 2d6bb3f | 2014-04-11 10:00:31 -0700 | [diff] [blame] | 581 | List<const CameraMetadata> requests; |
| 582 | requests.push_back(request); |
| 583 | return setStreamingRequestList(requests, /*lastFrameNumber*/NULL); |
Eino-Ville Talvala | f76e027 | 2013-02-27 18:02:26 -0800 | [diff] [blame] | 584 | } |
| 585 | |
Jianing Wei | cb0652e | 2014-03-12 18:29:36 -0700 | [diff] [blame] | 586 | status_t Camera3Device::setStreamingRequestList(const List<const CameraMetadata> &requests, |
| 587 | int64_t *lastFrameNumber) { |
Jianing Wei | 90e59c9 | 2014-03-12 18:29:36 -0700 | [diff] [blame] | 588 | ATRACE_CALL(); |
| 589 | |
Jianing Wei | cb0652e | 2014-03-12 18:29:36 -0700 | [diff] [blame] | 590 | return submitRequestsHelper(requests, /*repeating*/true, lastFrameNumber); |
Jianing Wei | 90e59c9 | 2014-03-12 18:29:36 -0700 | [diff] [blame] | 591 | } |
Eino-Ville Talvala | f76e027 | 2013-02-27 18:02:26 -0800 | [diff] [blame] | 592 | |
| 593 | sp<Camera3Device::CaptureRequest> Camera3Device::setUpRequestLocked( |
| 594 | const CameraMetadata &request) { |
| 595 | status_t res; |
| 596 | |
Eino-Ville Talvala | f1e98d8 | 2013-09-06 09:32:43 -0700 | [diff] [blame] | 597 | if (mStatus == STATUS_UNCONFIGURED || mNeedConfig) { |
Eino-Ville Talvala | f76e027 | 2013-02-27 18:02:26 -0800 | [diff] [blame] | 598 | res = configureStreamsLocked(); |
| 599 | if (res != OK) { |
Eino-Ville Talvala | b2058d1 | 2013-04-09 13:49:56 -0700 | [diff] [blame] | 600 | SET_ERR_L("Can't set up streams: %s (%d)", strerror(-res), res); |
Eino-Ville Talvala | f76e027 | 2013-02-27 18:02:26 -0800 | [diff] [blame] | 601 | return NULL; |
| 602 | } |
Eino-Ville Talvala | f1e98d8 | 2013-09-06 09:32:43 -0700 | [diff] [blame] | 603 | if (mStatus == STATUS_UNCONFIGURED) { |
| 604 | CLOGE("No streams configured"); |
| 605 | return NULL; |
| 606 | } |
Eino-Ville Talvala | f76e027 | 2013-02-27 18:02:26 -0800 | [diff] [blame] | 607 | } |
| 608 | |
| 609 | sp<CaptureRequest> newRequest = createCaptureRequest(request); |
| 610 | return newRequest; |
Eino-Ville Talvala | 7fa43f3 | 2013-02-06 17:20:07 -0800 | [diff] [blame] | 611 | } |
| 612 | |
Jianing Wei | cb0652e | 2014-03-12 18:29:36 -0700 | [diff] [blame] | 613 | status_t Camera3Device::clearStreamingRequest(int64_t *lastFrameNumber) { |
Eino-Ville Talvala | 7fa43f3 | 2013-02-06 17:20:07 -0800 | [diff] [blame] | 614 | ATRACE_CALL(); |
Eino-Ville Talvala | f1e98d8 | 2013-09-06 09:32:43 -0700 | [diff] [blame] | 615 | Mutex::Autolock il(mInterfaceLock); |
Eino-Ville Talvala | f76e027 | 2013-02-27 18:02:26 -0800 | [diff] [blame] | 616 | Mutex::Autolock l(mLock); |
Eino-Ville Talvala | 7fa43f3 | 2013-02-06 17:20:07 -0800 | [diff] [blame] | 617 | |
Eino-Ville Talvala | f76e027 | 2013-02-27 18:02:26 -0800 | [diff] [blame] | 618 | switch (mStatus) { |
| 619 | case STATUS_ERROR: |
Eino-Ville Talvala | b2058d1 | 2013-04-09 13:49:56 -0700 | [diff] [blame] | 620 | CLOGE("Device has encountered a serious error"); |
Eino-Ville Talvala | f76e027 | 2013-02-27 18:02:26 -0800 | [diff] [blame] | 621 | return INVALID_OPERATION; |
| 622 | case STATUS_UNINITIALIZED: |
Eino-Ville Talvala | b2058d1 | 2013-04-09 13:49:56 -0700 | [diff] [blame] | 623 | CLOGE("Device not initialized"); |
Eino-Ville Talvala | f76e027 | 2013-02-27 18:02:26 -0800 | [diff] [blame] | 624 | return INVALID_OPERATION; |
Eino-Ville Talvala | f1e98d8 | 2013-09-06 09:32:43 -0700 | [diff] [blame] | 625 | case STATUS_UNCONFIGURED: |
| 626 | case STATUS_CONFIGURED: |
Eino-Ville Talvala | f76e027 | 2013-02-27 18:02:26 -0800 | [diff] [blame] | 627 | case STATUS_ACTIVE: |
| 628 | // OK |
| 629 | break; |
| 630 | default: |
Eino-Ville Talvala | b2058d1 | 2013-04-09 13:49:56 -0700 | [diff] [blame] | 631 | SET_ERR_L("Unexpected status: %d", mStatus); |
Eino-Ville Talvala | f76e027 | 2013-02-27 18:02:26 -0800 | [diff] [blame] | 632 | return INVALID_OPERATION; |
| 633 | } |
Eino-Ville Talvala | f1e98d8 | 2013-09-06 09:32:43 -0700 | [diff] [blame] | 634 | ALOGV("Camera %d: Clearing repeating request", mId); |
Jianing Wei | cb0652e | 2014-03-12 18:29:36 -0700 | [diff] [blame] | 635 | |
Jianing Wei | 2d6bb3f | 2014-04-11 10:00:31 -0700 | [diff] [blame] | 636 | return mRequestThread->clearRepeatingRequests(lastFrameNumber); |
Eino-Ville Talvala | 7fa43f3 | 2013-02-06 17:20:07 -0800 | [diff] [blame] | 637 | } |
| 638 | |
| 639 | status_t Camera3Device::waitUntilRequestReceived(int32_t requestId, nsecs_t timeout) { |
| 640 | ATRACE_CALL(); |
Eino-Ville Talvala | f1e98d8 | 2013-09-06 09:32:43 -0700 | [diff] [blame] | 641 | Mutex::Autolock il(mInterfaceLock); |
Eino-Ville Talvala | 7fa43f3 | 2013-02-06 17:20:07 -0800 | [diff] [blame] | 642 | |
Igor Murashkin | 4d2f2e8 | 2013-04-01 17:29:07 -0700 | [diff] [blame] | 643 | return mRequestThread->waitUntilRequestProcessed(requestId, timeout); |
Eino-Ville Talvala | 7fa43f3 | 2013-02-06 17:20:07 -0800 | [diff] [blame] | 644 | } |
| 645 | |
Igor Murashkin | 5a269fa | 2013-04-15 14:59:22 -0700 | [diff] [blame] | 646 | status_t Camera3Device::createInputStream( |
| 647 | uint32_t width, uint32_t height, int format, int *id) { |
| 648 | ATRACE_CALL(); |
Eino-Ville Talvala | f1e98d8 | 2013-09-06 09:32:43 -0700 | [diff] [blame] | 649 | Mutex::Autolock il(mInterfaceLock); |
Igor Murashkin | 5a269fa | 2013-04-15 14:59:22 -0700 | [diff] [blame] | 650 | Mutex::Autolock l(mLock); |
Eino-Ville Talvala | f1e98d8 | 2013-09-06 09:32:43 -0700 | [diff] [blame] | 651 | ALOGV("Camera %d: Creating new input stream %d: %d x %d, format %d", |
| 652 | mId, mNextStreamId, width, height, format); |
Igor Murashkin | 5a269fa | 2013-04-15 14:59:22 -0700 | [diff] [blame] | 653 | |
| 654 | status_t res; |
| 655 | bool wasActive = false; |
| 656 | |
| 657 | switch (mStatus) { |
| 658 | case STATUS_ERROR: |
| 659 | ALOGE("%s: Device has encountered a serious error", __FUNCTION__); |
| 660 | return INVALID_OPERATION; |
| 661 | case STATUS_UNINITIALIZED: |
| 662 | ALOGE("%s: Device not initialized", __FUNCTION__); |
| 663 | return INVALID_OPERATION; |
Eino-Ville Talvala | f1e98d8 | 2013-09-06 09:32:43 -0700 | [diff] [blame] | 664 | case STATUS_UNCONFIGURED: |
| 665 | case STATUS_CONFIGURED: |
Igor Murashkin | 5a269fa | 2013-04-15 14:59:22 -0700 | [diff] [blame] | 666 | // OK |
| 667 | break; |
| 668 | case STATUS_ACTIVE: |
| 669 | ALOGV("%s: Stopping activity to reconfigure streams", __FUNCTION__); |
Eino-Ville Talvala | f1e98d8 | 2013-09-06 09:32:43 -0700 | [diff] [blame] | 670 | res = internalPauseAndWaitLocked(); |
Igor Murashkin | 5a269fa | 2013-04-15 14:59:22 -0700 | [diff] [blame] | 671 | if (res != OK) { |
Eino-Ville Talvala | f1e98d8 | 2013-09-06 09:32:43 -0700 | [diff] [blame] | 672 | SET_ERR_L("Can't pause captures to reconfigure streams!"); |
Igor Murashkin | 5a269fa | 2013-04-15 14:59:22 -0700 | [diff] [blame] | 673 | return res; |
| 674 | } |
| 675 | wasActive = true; |
| 676 | break; |
| 677 | default: |
Eino-Ville Talvala | f1e98d8 | 2013-09-06 09:32:43 -0700 | [diff] [blame] | 678 | SET_ERR_L("%s: Unexpected status: %d", mStatus); |
Igor Murashkin | 5a269fa | 2013-04-15 14:59:22 -0700 | [diff] [blame] | 679 | return INVALID_OPERATION; |
| 680 | } |
Eino-Ville Talvala | f1e98d8 | 2013-09-06 09:32:43 -0700 | [diff] [blame] | 681 | assert(mStatus != STATUS_ACTIVE); |
Igor Murashkin | 5a269fa | 2013-04-15 14:59:22 -0700 | [diff] [blame] | 682 | |
| 683 | if (mInputStream != 0) { |
| 684 | ALOGE("%s: Cannot create more than 1 input stream", __FUNCTION__); |
| 685 | return INVALID_OPERATION; |
| 686 | } |
| 687 | |
| 688 | sp<Camera3InputStream> newStream = new Camera3InputStream(mNextStreamId, |
| 689 | width, height, format); |
Eino-Ville Talvala | f1e98d8 | 2013-09-06 09:32:43 -0700 | [diff] [blame] | 690 | newStream->setStatusTracker(mStatusTracker); |
Igor Murashkin | 5a269fa | 2013-04-15 14:59:22 -0700 | [diff] [blame] | 691 | |
| 692 | mInputStream = newStream; |
| 693 | |
| 694 | *id = mNextStreamId++; |
| 695 | |
| 696 | // Continue captures if active at start |
| 697 | if (wasActive) { |
| 698 | ALOGV("%s: Restarting activity to reconfigure streams", __FUNCTION__); |
| 699 | res = configureStreamsLocked(); |
| 700 | if (res != OK) { |
| 701 | ALOGE("%s: Can't reconfigure device for new stream %d: %s (%d)", |
| 702 | __FUNCTION__, mNextStreamId, strerror(-res), res); |
| 703 | return res; |
| 704 | } |
Eino-Ville Talvala | f1e98d8 | 2013-09-06 09:32:43 -0700 | [diff] [blame] | 705 | internalResumeLocked(); |
Igor Murashkin | 5a269fa | 2013-04-15 14:59:22 -0700 | [diff] [blame] | 706 | } |
| 707 | |
Eino-Ville Talvala | f1e98d8 | 2013-09-06 09:32:43 -0700 | [diff] [blame] | 708 | ALOGV("Camera %d: Created input stream", mId); |
Igor Murashkin | 5a269fa | 2013-04-15 14:59:22 -0700 | [diff] [blame] | 709 | return OK; |
| 710 | } |
| 711 | |
Igor Murashkin | 2fba584 | 2013-04-22 14:03:54 -0700 | [diff] [blame] | 712 | |
| 713 | status_t Camera3Device::createZslStream( |
| 714 | uint32_t width, uint32_t height, |
| 715 | int depth, |
| 716 | /*out*/ |
| 717 | int *id, |
| 718 | sp<Camera3ZslStream>* zslStream) { |
| 719 | ATRACE_CALL(); |
Eino-Ville Talvala | f1e98d8 | 2013-09-06 09:32:43 -0700 | [diff] [blame] | 720 | Mutex::Autolock il(mInterfaceLock); |
Igor Murashkin | 2fba584 | 2013-04-22 14:03:54 -0700 | [diff] [blame] | 721 | Mutex::Autolock l(mLock); |
Eino-Ville Talvala | f1e98d8 | 2013-09-06 09:32:43 -0700 | [diff] [blame] | 722 | ALOGV("Camera %d: Creating ZSL stream %d: %d x %d, depth %d", |
| 723 | mId, mNextStreamId, width, height, depth); |
Igor Murashkin | 2fba584 | 2013-04-22 14:03:54 -0700 | [diff] [blame] | 724 | |
| 725 | status_t res; |
| 726 | bool wasActive = false; |
| 727 | |
| 728 | switch (mStatus) { |
| 729 | case STATUS_ERROR: |
| 730 | ALOGE("%s: Device has encountered a serious error", __FUNCTION__); |
| 731 | return INVALID_OPERATION; |
| 732 | case STATUS_UNINITIALIZED: |
| 733 | ALOGE("%s: Device not initialized", __FUNCTION__); |
| 734 | return INVALID_OPERATION; |
Eino-Ville Talvala | f1e98d8 | 2013-09-06 09:32:43 -0700 | [diff] [blame] | 735 | case STATUS_UNCONFIGURED: |
| 736 | case STATUS_CONFIGURED: |
Igor Murashkin | 2fba584 | 2013-04-22 14:03:54 -0700 | [diff] [blame] | 737 | // OK |
| 738 | break; |
| 739 | case STATUS_ACTIVE: |
| 740 | ALOGV("%s: Stopping activity to reconfigure streams", __FUNCTION__); |
Eino-Ville Talvala | f1e98d8 | 2013-09-06 09:32:43 -0700 | [diff] [blame] | 741 | res = internalPauseAndWaitLocked(); |
Igor Murashkin | 2fba584 | 2013-04-22 14:03:54 -0700 | [diff] [blame] | 742 | if (res != OK) { |
Eino-Ville Talvala | f1e98d8 | 2013-09-06 09:32:43 -0700 | [diff] [blame] | 743 | SET_ERR_L("Can't pause captures to reconfigure streams!"); |
Igor Murashkin | 2fba584 | 2013-04-22 14:03:54 -0700 | [diff] [blame] | 744 | return res; |
| 745 | } |
| 746 | wasActive = true; |
| 747 | break; |
| 748 | default: |
Eino-Ville Talvala | f1e98d8 | 2013-09-06 09:32:43 -0700 | [diff] [blame] | 749 | SET_ERR_L("Unexpected status: %d", mStatus); |
Igor Murashkin | 2fba584 | 2013-04-22 14:03:54 -0700 | [diff] [blame] | 750 | return INVALID_OPERATION; |
| 751 | } |
Eino-Ville Talvala | f1e98d8 | 2013-09-06 09:32:43 -0700 | [diff] [blame] | 752 | assert(mStatus != STATUS_ACTIVE); |
Igor Murashkin | 2fba584 | 2013-04-22 14:03:54 -0700 | [diff] [blame] | 753 | |
| 754 | if (mInputStream != 0) { |
| 755 | ALOGE("%s: Cannot create more than 1 input stream", __FUNCTION__); |
| 756 | return INVALID_OPERATION; |
| 757 | } |
| 758 | |
| 759 | sp<Camera3ZslStream> newStream = new Camera3ZslStream(mNextStreamId, |
| 760 | width, height, depth); |
Eino-Ville Talvala | f1e98d8 | 2013-09-06 09:32:43 -0700 | [diff] [blame] | 761 | newStream->setStatusTracker(mStatusTracker); |
Igor Murashkin | 2fba584 | 2013-04-22 14:03:54 -0700 | [diff] [blame] | 762 | |
| 763 | res = mOutputStreams.add(mNextStreamId, newStream); |
| 764 | if (res < 0) { |
| 765 | ALOGE("%s: Can't add new stream to set: %s (%d)", |
| 766 | __FUNCTION__, strerror(-res), res); |
| 767 | return res; |
| 768 | } |
| 769 | mInputStream = newStream; |
| 770 | |
Yuvraj Pasi | e5e3d08 | 2014-04-15 18:37:45 +0530 | [diff] [blame] | 771 | mNeedConfig = true; |
| 772 | |
Igor Murashkin | 2fba584 | 2013-04-22 14:03:54 -0700 | [diff] [blame] | 773 | *id = mNextStreamId++; |
| 774 | *zslStream = newStream; |
| 775 | |
| 776 | // Continue captures if active at start |
| 777 | if (wasActive) { |
| 778 | ALOGV("%s: Restarting activity to reconfigure streams", __FUNCTION__); |
| 779 | res = configureStreamsLocked(); |
| 780 | if (res != OK) { |
| 781 | ALOGE("%s: Can't reconfigure device for new stream %d: %s (%d)", |
| 782 | __FUNCTION__, mNextStreamId, strerror(-res), res); |
| 783 | return res; |
| 784 | } |
Eino-Ville Talvala | f1e98d8 | 2013-09-06 09:32:43 -0700 | [diff] [blame] | 785 | internalResumeLocked(); |
Igor Murashkin | 2fba584 | 2013-04-22 14:03:54 -0700 | [diff] [blame] | 786 | } |
| 787 | |
Eino-Ville Talvala | f1e98d8 | 2013-09-06 09:32:43 -0700 | [diff] [blame] | 788 | ALOGV("Camera %d: Created ZSL stream", mId); |
Igor Murashkin | 2fba584 | 2013-04-22 14:03:54 -0700 | [diff] [blame] | 789 | return OK; |
| 790 | } |
| 791 | |
Eino-Ville Talvala | 7fa43f3 | 2013-02-06 17:20:07 -0800 | [diff] [blame] | 792 | status_t Camera3Device::createStream(sp<ANativeWindow> consumer, |
| 793 | uint32_t width, uint32_t height, int format, size_t size, int *id) { |
| 794 | ATRACE_CALL(); |
Eino-Ville Talvala | f1e98d8 | 2013-09-06 09:32:43 -0700 | [diff] [blame] | 795 | Mutex::Autolock il(mInterfaceLock); |
Eino-Ville Talvala | f76e027 | 2013-02-27 18:02:26 -0800 | [diff] [blame] | 796 | Mutex::Autolock l(mLock); |
Colin Cross | e5729fa | 2014-03-21 15:04:25 -0700 | [diff] [blame] | 797 | ALOGV("Camera %d: Creating new stream %d: %d x %d, format %d, size %zu", |
Eino-Ville Talvala | f1e98d8 | 2013-09-06 09:32:43 -0700 | [diff] [blame] | 798 | mId, mNextStreamId, width, height, format, size); |
Eino-Ville Talvala | 7fa43f3 | 2013-02-06 17:20:07 -0800 | [diff] [blame] | 799 | |
Eino-Ville Talvala | f76e027 | 2013-02-27 18:02:26 -0800 | [diff] [blame] | 800 | status_t res; |
| 801 | bool wasActive = false; |
| 802 | |
| 803 | switch (mStatus) { |
| 804 | case STATUS_ERROR: |
Eino-Ville Talvala | b2058d1 | 2013-04-09 13:49:56 -0700 | [diff] [blame] | 805 | CLOGE("Device has encountered a serious error"); |
Eino-Ville Talvala | f76e027 | 2013-02-27 18:02:26 -0800 | [diff] [blame] | 806 | return INVALID_OPERATION; |
| 807 | case STATUS_UNINITIALIZED: |
Eino-Ville Talvala | b2058d1 | 2013-04-09 13:49:56 -0700 | [diff] [blame] | 808 | CLOGE("Device not initialized"); |
Eino-Ville Talvala | f76e027 | 2013-02-27 18:02:26 -0800 | [diff] [blame] | 809 | return INVALID_OPERATION; |
Eino-Ville Talvala | f1e98d8 | 2013-09-06 09:32:43 -0700 | [diff] [blame] | 810 | case STATUS_UNCONFIGURED: |
| 811 | case STATUS_CONFIGURED: |
Eino-Ville Talvala | f76e027 | 2013-02-27 18:02:26 -0800 | [diff] [blame] | 812 | // OK |
| 813 | break; |
| 814 | case STATUS_ACTIVE: |
| 815 | ALOGV("%s: Stopping activity to reconfigure streams", __FUNCTION__); |
Eino-Ville Talvala | f1e98d8 | 2013-09-06 09:32:43 -0700 | [diff] [blame] | 816 | res = internalPauseAndWaitLocked(); |
Eino-Ville Talvala | f76e027 | 2013-02-27 18:02:26 -0800 | [diff] [blame] | 817 | if (res != OK) { |
Eino-Ville Talvala | f1e98d8 | 2013-09-06 09:32:43 -0700 | [diff] [blame] | 818 | SET_ERR_L("Can't pause captures to reconfigure streams!"); |
Eino-Ville Talvala | f76e027 | 2013-02-27 18:02:26 -0800 | [diff] [blame] | 819 | return res; |
| 820 | } |
| 821 | wasActive = true; |
| 822 | break; |
| 823 | default: |
Eino-Ville Talvala | b2058d1 | 2013-04-09 13:49:56 -0700 | [diff] [blame] | 824 | SET_ERR_L("Unexpected status: %d", mStatus); |
Eino-Ville Talvala | f76e027 | 2013-02-27 18:02:26 -0800 | [diff] [blame] | 825 | return INVALID_OPERATION; |
| 826 | } |
Eino-Ville Talvala | f1e98d8 | 2013-09-06 09:32:43 -0700 | [diff] [blame] | 827 | assert(mStatus != STATUS_ACTIVE); |
Eino-Ville Talvala | f76e027 | 2013-02-27 18:02:26 -0800 | [diff] [blame] | 828 | |
| 829 | sp<Camera3OutputStream> newStream; |
| 830 | if (format == HAL_PIXEL_FORMAT_BLOB) { |
Zhijun He | f7da096 | 2014-04-24 13:27:56 -0700 | [diff] [blame] | 831 | ssize_t jpegBufferSize = getJpegBufferSize(width, height); |
| 832 | if (jpegBufferSize > 0) { |
| 833 | ALOGV("%s: Overwrite Jpeg output buffer size from %zu to %zu", |
| 834 | __FUNCTION__, size, jpegBufferSize); |
| 835 | } else { |
| 836 | SET_ERR_L("Invalid jpeg buffer size %zd", jpegBufferSize); |
| 837 | return BAD_VALUE; |
| 838 | } |
| 839 | |
Eino-Ville Talvala | f76e027 | 2013-02-27 18:02:26 -0800 | [diff] [blame] | 840 | newStream = new Camera3OutputStream(mNextStreamId, consumer, |
Zhijun He | f7da096 | 2014-04-24 13:27:56 -0700 | [diff] [blame] | 841 | width, height, jpegBufferSize, format); |
Eino-Ville Talvala | f76e027 | 2013-02-27 18:02:26 -0800 | [diff] [blame] | 842 | } else { |
| 843 | newStream = new Camera3OutputStream(mNextStreamId, consumer, |
| 844 | width, height, format); |
| 845 | } |
Eino-Ville Talvala | f1e98d8 | 2013-09-06 09:32:43 -0700 | [diff] [blame] | 846 | newStream->setStatusTracker(mStatusTracker); |
Eino-Ville Talvala | f76e027 | 2013-02-27 18:02:26 -0800 | [diff] [blame] | 847 | |
| 848 | res = mOutputStreams.add(mNextStreamId, newStream); |
| 849 | if (res < 0) { |
Eino-Ville Talvala | b2058d1 | 2013-04-09 13:49:56 -0700 | [diff] [blame] | 850 | SET_ERR_L("Can't add new stream to set: %s (%d)", strerror(-res), res); |
Eino-Ville Talvala | f76e027 | 2013-02-27 18:02:26 -0800 | [diff] [blame] | 851 | return res; |
| 852 | } |
| 853 | |
| 854 | *id = mNextStreamId++; |
Eino-Ville Talvala | ea26c77 | 2013-06-11 16:04:06 -0700 | [diff] [blame] | 855 | mNeedConfig = true; |
Eino-Ville Talvala | f76e027 | 2013-02-27 18:02:26 -0800 | [diff] [blame] | 856 | |
| 857 | // Continue captures if active at start |
| 858 | if (wasActive) { |
| 859 | ALOGV("%s: Restarting activity to reconfigure streams", __FUNCTION__); |
| 860 | res = configureStreamsLocked(); |
| 861 | if (res != OK) { |
Eino-Ville Talvala | b2058d1 | 2013-04-09 13:49:56 -0700 | [diff] [blame] | 862 | CLOGE("Can't reconfigure device for new stream %d: %s (%d)", |
| 863 | mNextStreamId, strerror(-res), res); |
Eino-Ville Talvala | f76e027 | 2013-02-27 18:02:26 -0800 | [diff] [blame] | 864 | return res; |
| 865 | } |
Eino-Ville Talvala | f1e98d8 | 2013-09-06 09:32:43 -0700 | [diff] [blame] | 866 | internalResumeLocked(); |
Eino-Ville Talvala | f76e027 | 2013-02-27 18:02:26 -0800 | [diff] [blame] | 867 | } |
Eino-Ville Talvala | f1e98d8 | 2013-09-06 09:32:43 -0700 | [diff] [blame] | 868 | ALOGV("Camera %d: Created new stream", mId); |
Eino-Ville Talvala | f76e027 | 2013-02-27 18:02:26 -0800 | [diff] [blame] | 869 | return OK; |
Eino-Ville Talvala | 7fa43f3 | 2013-02-06 17:20:07 -0800 | [diff] [blame] | 870 | } |
| 871 | |
| 872 | status_t Camera3Device::createReprocessStreamFromStream(int outputId, int *id) { |
| 873 | ATRACE_CALL(); |
| 874 | (void)outputId; (void)id; |
| 875 | |
Eino-Ville Talvala | b2058d1 | 2013-04-09 13:49:56 -0700 | [diff] [blame] | 876 | CLOGE("Unimplemented"); |
Eino-Ville Talvala | 7fa43f3 | 2013-02-06 17:20:07 -0800 | [diff] [blame] | 877 | return INVALID_OPERATION; |
| 878 | } |
| 879 | |
| 880 | |
| 881 | status_t Camera3Device::getStreamInfo(int id, |
| 882 | uint32_t *width, uint32_t *height, uint32_t *format) { |
| 883 | ATRACE_CALL(); |
Eino-Ville Talvala | f1e98d8 | 2013-09-06 09:32:43 -0700 | [diff] [blame] | 884 | Mutex::Autolock il(mInterfaceLock); |
Eino-Ville Talvala | f76e027 | 2013-02-27 18:02:26 -0800 | [diff] [blame] | 885 | Mutex::Autolock l(mLock); |
Eino-Ville Talvala | 7fa43f3 | 2013-02-06 17:20:07 -0800 | [diff] [blame] | 886 | |
Eino-Ville Talvala | f76e027 | 2013-02-27 18:02:26 -0800 | [diff] [blame] | 887 | switch (mStatus) { |
| 888 | case STATUS_ERROR: |
Eino-Ville Talvala | b2058d1 | 2013-04-09 13:49:56 -0700 | [diff] [blame] | 889 | CLOGE("Device has encountered a serious error"); |
Eino-Ville Talvala | f76e027 | 2013-02-27 18:02:26 -0800 | [diff] [blame] | 890 | return INVALID_OPERATION; |
| 891 | case STATUS_UNINITIALIZED: |
Eino-Ville Talvala | b2058d1 | 2013-04-09 13:49:56 -0700 | [diff] [blame] | 892 | CLOGE("Device not initialized!"); |
Eino-Ville Talvala | f76e027 | 2013-02-27 18:02:26 -0800 | [diff] [blame] | 893 | return INVALID_OPERATION; |
Eino-Ville Talvala | f1e98d8 | 2013-09-06 09:32:43 -0700 | [diff] [blame] | 894 | case STATUS_UNCONFIGURED: |
| 895 | case STATUS_CONFIGURED: |
Eino-Ville Talvala | f76e027 | 2013-02-27 18:02:26 -0800 | [diff] [blame] | 896 | case STATUS_ACTIVE: |
| 897 | // OK |
| 898 | break; |
| 899 | default: |
Eino-Ville Talvala | b2058d1 | 2013-04-09 13:49:56 -0700 | [diff] [blame] | 900 | SET_ERR_L("Unexpected status: %d", mStatus); |
Eino-Ville Talvala | f76e027 | 2013-02-27 18:02:26 -0800 | [diff] [blame] | 901 | return INVALID_OPERATION; |
| 902 | } |
| 903 | |
| 904 | ssize_t idx = mOutputStreams.indexOfKey(id); |
| 905 | if (idx == NAME_NOT_FOUND) { |
Eino-Ville Talvala | b2058d1 | 2013-04-09 13:49:56 -0700 | [diff] [blame] | 906 | CLOGE("Stream %d is unknown", id); |
Eino-Ville Talvala | f76e027 | 2013-02-27 18:02:26 -0800 | [diff] [blame] | 907 | return idx; |
| 908 | } |
| 909 | |
| 910 | if (width) *width = mOutputStreams[idx]->getWidth(); |
| 911 | if (height) *height = mOutputStreams[idx]->getHeight(); |
| 912 | if (format) *format = mOutputStreams[idx]->getFormat(); |
| 913 | |
| 914 | return OK; |
Eino-Ville Talvala | 7fa43f3 | 2013-02-06 17:20:07 -0800 | [diff] [blame] | 915 | } |
| 916 | |
| 917 | status_t Camera3Device::setStreamTransform(int id, |
| 918 | int transform) { |
| 919 | ATRACE_CALL(); |
Eino-Ville Talvala | f1e98d8 | 2013-09-06 09:32:43 -0700 | [diff] [blame] | 920 | Mutex::Autolock il(mInterfaceLock); |
Eino-Ville Talvala | f76e027 | 2013-02-27 18:02:26 -0800 | [diff] [blame] | 921 | Mutex::Autolock l(mLock); |
Eino-Ville Talvala | 7fa43f3 | 2013-02-06 17:20:07 -0800 | [diff] [blame] | 922 | |
Eino-Ville Talvala | f76e027 | 2013-02-27 18:02:26 -0800 | [diff] [blame] | 923 | switch (mStatus) { |
| 924 | case STATUS_ERROR: |
Eino-Ville Talvala | b2058d1 | 2013-04-09 13:49:56 -0700 | [diff] [blame] | 925 | CLOGE("Device has encountered a serious error"); |
Eino-Ville Talvala | f76e027 | 2013-02-27 18:02:26 -0800 | [diff] [blame] | 926 | return INVALID_OPERATION; |
| 927 | case STATUS_UNINITIALIZED: |
Eino-Ville Talvala | b2058d1 | 2013-04-09 13:49:56 -0700 | [diff] [blame] | 928 | CLOGE("Device not initialized"); |
Eino-Ville Talvala | f76e027 | 2013-02-27 18:02:26 -0800 | [diff] [blame] | 929 | return INVALID_OPERATION; |
Eino-Ville Talvala | f1e98d8 | 2013-09-06 09:32:43 -0700 | [diff] [blame] | 930 | case STATUS_UNCONFIGURED: |
| 931 | case STATUS_CONFIGURED: |
Eino-Ville Talvala | f76e027 | 2013-02-27 18:02:26 -0800 | [diff] [blame] | 932 | case STATUS_ACTIVE: |
| 933 | // OK |
| 934 | break; |
| 935 | default: |
Eino-Ville Talvala | b2058d1 | 2013-04-09 13:49:56 -0700 | [diff] [blame] | 936 | SET_ERR_L("Unexpected status: %d", mStatus); |
Eino-Ville Talvala | f76e027 | 2013-02-27 18:02:26 -0800 | [diff] [blame] | 937 | return INVALID_OPERATION; |
| 938 | } |
| 939 | |
| 940 | ssize_t idx = mOutputStreams.indexOfKey(id); |
| 941 | if (idx == NAME_NOT_FOUND) { |
Eino-Ville Talvala | b2058d1 | 2013-04-09 13:49:56 -0700 | [diff] [blame] | 942 | CLOGE("Stream %d does not exist", |
| 943 | id); |
Eino-Ville Talvala | f76e027 | 2013-02-27 18:02:26 -0800 | [diff] [blame] | 944 | return BAD_VALUE; |
| 945 | } |
| 946 | |
| 947 | return mOutputStreams.editValueAt(idx)->setTransform(transform); |
Eino-Ville Talvala | 7fa43f3 | 2013-02-06 17:20:07 -0800 | [diff] [blame] | 948 | } |
| 949 | |
| 950 | status_t Camera3Device::deleteStream(int id) { |
| 951 | ATRACE_CALL(); |
Eino-Ville Talvala | f1e98d8 | 2013-09-06 09:32:43 -0700 | [diff] [blame] | 952 | Mutex::Autolock il(mInterfaceLock); |
Eino-Ville Talvala | f76e027 | 2013-02-27 18:02:26 -0800 | [diff] [blame] | 953 | Mutex::Autolock l(mLock); |
| 954 | status_t res; |
Eino-Ville Talvala | 7fa43f3 | 2013-02-06 17:20:07 -0800 | [diff] [blame] | 955 | |
Igor Murashkin | e2172be | 2013-05-28 15:31:39 -0700 | [diff] [blame] | 956 | ALOGV("%s: Camera %d: Deleting stream %d", __FUNCTION__, mId, id); |
| 957 | |
Eino-Ville Talvala | f76e027 | 2013-02-27 18:02:26 -0800 | [diff] [blame] | 958 | // CameraDevice semantics require device to already be idle before |
| 959 | // deleteStream is called, unlike for createStream. |
Eino-Ville Talvala | f1e98d8 | 2013-09-06 09:32:43 -0700 | [diff] [blame] | 960 | if (mStatus == STATUS_ACTIVE) { |
Igor Murashkin | 5282713 | 2013-05-13 14:53:44 -0700 | [diff] [blame] | 961 | ALOGV("%s: Camera %d: Device not idle", __FUNCTION__, mId); |
| 962 | return -EBUSY; |
Eino-Ville Talvala | f76e027 | 2013-02-27 18:02:26 -0800 | [diff] [blame] | 963 | } |
| 964 | |
Igor Murashkin | 2fba584 | 2013-04-22 14:03:54 -0700 | [diff] [blame] | 965 | sp<Camera3StreamInterface> deletedStream; |
Zhijun He | 5f44635 | 2014-01-22 09:49:33 -0800 | [diff] [blame] | 966 | ssize_t outputStreamIdx = mOutputStreams.indexOfKey(id); |
Eino-Ville Talvala | f76e027 | 2013-02-27 18:02:26 -0800 | [diff] [blame] | 967 | if (mInputStream != NULL && id == mInputStream->getId()) { |
| 968 | deletedStream = mInputStream; |
| 969 | mInputStream.clear(); |
| 970 | } else { |
Zhijun He | 5f44635 | 2014-01-22 09:49:33 -0800 | [diff] [blame] | 971 | if (outputStreamIdx == NAME_NOT_FOUND) { |
Eino-Ville Talvala | b2058d1 | 2013-04-09 13:49:56 -0700 | [diff] [blame] | 972 | CLOGE("Stream %d does not exist", id); |
Eino-Ville Talvala | f76e027 | 2013-02-27 18:02:26 -0800 | [diff] [blame] | 973 | return BAD_VALUE; |
| 974 | } |
Zhijun He | 5f44635 | 2014-01-22 09:49:33 -0800 | [diff] [blame] | 975 | } |
| 976 | |
| 977 | // Delete output stream or the output part of a bi-directional stream. |
| 978 | if (outputStreamIdx != NAME_NOT_FOUND) { |
| 979 | deletedStream = mOutputStreams.editValueAt(outputStreamIdx); |
Eino-Ville Talvala | f76e027 | 2013-02-27 18:02:26 -0800 | [diff] [blame] | 980 | mOutputStreams.removeItem(id); |
| 981 | } |
| 982 | |
| 983 | // Free up the stream endpoint so that it can be used by some other stream |
| 984 | res = deletedStream->disconnect(); |
| 985 | if (res != OK) { |
Eino-Ville Talvala | b2058d1 | 2013-04-09 13:49:56 -0700 | [diff] [blame] | 986 | SET_ERR_L("Can't disconnect deleted stream %d", id); |
Eino-Ville Talvala | f76e027 | 2013-02-27 18:02:26 -0800 | [diff] [blame] | 987 | // fall through since we want to still list the stream as deleted. |
| 988 | } |
| 989 | mDeletedStreams.add(deletedStream); |
Eino-Ville Talvala | ea26c77 | 2013-06-11 16:04:06 -0700 | [diff] [blame] | 990 | mNeedConfig = true; |
Eino-Ville Talvala | f76e027 | 2013-02-27 18:02:26 -0800 | [diff] [blame] | 991 | |
| 992 | return res; |
Eino-Ville Talvala | 7fa43f3 | 2013-02-06 17:20:07 -0800 | [diff] [blame] | 993 | } |
| 994 | |
| 995 | status_t Camera3Device::deleteReprocessStream(int id) { |
| 996 | ATRACE_CALL(); |
| 997 | (void)id; |
| 998 | |
Eino-Ville Talvala | b2058d1 | 2013-04-09 13:49:56 -0700 | [diff] [blame] | 999 | CLOGE("Unimplemented"); |
Eino-Ville Talvala | 7fa43f3 | 2013-02-06 17:20:07 -0800 | [diff] [blame] | 1000 | return INVALID_OPERATION; |
| 1001 | } |
| 1002 | |
| 1003 | |
| 1004 | status_t Camera3Device::createDefaultRequest(int templateId, |
| 1005 | CameraMetadata *request) { |
| 1006 | ATRACE_CALL(); |
Alex Ray | fe7e0c6 | 2013-05-30 00:12:13 -0700 | [diff] [blame] | 1007 | ALOGV("%s: for template %d", __FUNCTION__, templateId); |
Eino-Ville Talvala | f1e98d8 | 2013-09-06 09:32:43 -0700 | [diff] [blame] | 1008 | Mutex::Autolock il(mInterfaceLock); |
Eino-Ville Talvala | f76e027 | 2013-02-27 18:02:26 -0800 | [diff] [blame] | 1009 | Mutex::Autolock l(mLock); |
| 1010 | |
| 1011 | switch (mStatus) { |
| 1012 | case STATUS_ERROR: |
Eino-Ville Talvala | b2058d1 | 2013-04-09 13:49:56 -0700 | [diff] [blame] | 1013 | CLOGE("Device has encountered a serious error"); |
Eino-Ville Talvala | f76e027 | 2013-02-27 18:02:26 -0800 | [diff] [blame] | 1014 | return INVALID_OPERATION; |
| 1015 | case STATUS_UNINITIALIZED: |
Eino-Ville Talvala | b2058d1 | 2013-04-09 13:49:56 -0700 | [diff] [blame] | 1016 | CLOGE("Device is not initialized!"); |
Eino-Ville Talvala | f76e027 | 2013-02-27 18:02:26 -0800 | [diff] [blame] | 1017 | return INVALID_OPERATION; |
Eino-Ville Talvala | f1e98d8 | 2013-09-06 09:32:43 -0700 | [diff] [blame] | 1018 | case STATUS_UNCONFIGURED: |
| 1019 | case STATUS_CONFIGURED: |
Eino-Ville Talvala | f76e027 | 2013-02-27 18:02:26 -0800 | [diff] [blame] | 1020 | case STATUS_ACTIVE: |
| 1021 | // OK |
| 1022 | break; |
| 1023 | default: |
Eino-Ville Talvala | b2058d1 | 2013-04-09 13:49:56 -0700 | [diff] [blame] | 1024 | SET_ERR_L("Unexpected status: %d", mStatus); |
Eino-Ville Talvala | f76e027 | 2013-02-27 18:02:26 -0800 | [diff] [blame] | 1025 | return INVALID_OPERATION; |
| 1026 | } |
Eino-Ville Talvala | 7fa43f3 | 2013-02-06 17:20:07 -0800 | [diff] [blame] | 1027 | |
| 1028 | const camera_metadata_t *rawRequest; |
Eino-Ville Talvala | 17a61ad | 2013-06-03 16:53:32 -0700 | [diff] [blame] | 1029 | ATRACE_BEGIN("camera3->construct_default_request_settings"); |
Eino-Ville Talvala | 7fa43f3 | 2013-02-06 17:20:07 -0800 | [diff] [blame] | 1030 | rawRequest = mHal3Device->ops->construct_default_request_settings( |
| 1031 | mHal3Device, templateId); |
Eino-Ville Talvala | 17a61ad | 2013-06-03 16:53:32 -0700 | [diff] [blame] | 1032 | ATRACE_END(); |
Eino-Ville Talvala | b2058d1 | 2013-04-09 13:49:56 -0700 | [diff] [blame] | 1033 | if (rawRequest == NULL) { |
| 1034 | SET_ERR_L("HAL is unable to construct default settings for template %d", |
| 1035 | templateId); |
| 1036 | return DEAD_OBJECT; |
| 1037 | } |
Eino-Ville Talvala | 7fa43f3 | 2013-02-06 17:20:07 -0800 | [diff] [blame] | 1038 | *request = rawRequest; |
| 1039 | |
| 1040 | return OK; |
| 1041 | } |
| 1042 | |
| 1043 | status_t Camera3Device::waitUntilDrained() { |
| 1044 | ATRACE_CALL(); |
Eino-Ville Talvala | f1e98d8 | 2013-09-06 09:32:43 -0700 | [diff] [blame] | 1045 | Mutex::Autolock il(mInterfaceLock); |
Eino-Ville Talvala | f76e027 | 2013-02-27 18:02:26 -0800 | [diff] [blame] | 1046 | Mutex::Autolock l(mLock); |
Eino-Ville Talvala | 7fa43f3 | 2013-02-06 17:20:07 -0800 | [diff] [blame] | 1047 | |
Zhijun He | 69a3748 | 2014-03-23 18:44:49 -0700 | [diff] [blame] | 1048 | return waitUntilDrainedLocked(); |
| 1049 | } |
| 1050 | |
| 1051 | status_t Camera3Device::waitUntilDrainedLocked() { |
Eino-Ville Talvala | f76e027 | 2013-02-27 18:02:26 -0800 | [diff] [blame] | 1052 | switch (mStatus) { |
| 1053 | case STATUS_UNINITIALIZED: |
Eino-Ville Talvala | f1e98d8 | 2013-09-06 09:32:43 -0700 | [diff] [blame] | 1054 | case STATUS_UNCONFIGURED: |
Eino-Ville Talvala | f76e027 | 2013-02-27 18:02:26 -0800 | [diff] [blame] | 1055 | ALOGV("%s: Already idle", __FUNCTION__); |
| 1056 | return OK; |
Eino-Ville Talvala | f1e98d8 | 2013-09-06 09:32:43 -0700 | [diff] [blame] | 1057 | case STATUS_CONFIGURED: |
| 1058 | // To avoid race conditions, check with tracker to be sure |
Eino-Ville Talvala | f76e027 | 2013-02-27 18:02:26 -0800 | [diff] [blame] | 1059 | case STATUS_ERROR: |
| 1060 | case STATUS_ACTIVE: |
Eino-Ville Talvala | f1e98d8 | 2013-09-06 09:32:43 -0700 | [diff] [blame] | 1061 | // Need to verify shut down |
Eino-Ville Talvala | f76e027 | 2013-02-27 18:02:26 -0800 | [diff] [blame] | 1062 | break; |
| 1063 | default: |
Eino-Ville Talvala | b2058d1 | 2013-04-09 13:49:56 -0700 | [diff] [blame] | 1064 | SET_ERR_L("Unexpected status: %d",mStatus); |
Eino-Ville Talvala | f76e027 | 2013-02-27 18:02:26 -0800 | [diff] [blame] | 1065 | return INVALID_OPERATION; |
| 1066 | } |
| 1067 | |
Eino-Ville Talvala | f1e98d8 | 2013-09-06 09:32:43 -0700 | [diff] [blame] | 1068 | ALOGV("%s: Camera %d: Waiting until idle", __FUNCTION__, mId); |
| 1069 | status_t res = waitUntilStateThenRelock(/*active*/ false, kShutdownTimeout); |
| 1070 | return res; |
| 1071 | } |
| 1072 | |
| 1073 | // Pause to reconfigure |
| 1074 | status_t Camera3Device::internalPauseAndWaitLocked() { |
| 1075 | mRequestThread->setPaused(true); |
| 1076 | mPauseStateNotify = true; |
| 1077 | |
| 1078 | ALOGV("%s: Camera %d: Internal wait until idle", __FUNCTION__, mId); |
| 1079 | status_t res = waitUntilStateThenRelock(/*active*/ false, kShutdownTimeout); |
| 1080 | if (res != OK) { |
| 1081 | SET_ERR_L("Can't idle device in %f seconds!", |
| 1082 | kShutdownTimeout/1e9); |
Eino-Ville Talvala | f76e027 | 2013-02-27 18:02:26 -0800 | [diff] [blame] | 1083 | } |
| 1084 | |
Eino-Ville Talvala | f1e98d8 | 2013-09-06 09:32:43 -0700 | [diff] [blame] | 1085 | return res; |
| 1086 | } |
Eino-Ville Talvala | f76e027 | 2013-02-27 18:02:26 -0800 | [diff] [blame] | 1087 | |
Eino-Ville Talvala | f1e98d8 | 2013-09-06 09:32:43 -0700 | [diff] [blame] | 1088 | // Resume after internalPauseAndWaitLocked |
| 1089 | status_t Camera3Device::internalResumeLocked() { |
| 1090 | status_t res; |
| 1091 | |
| 1092 | mRequestThread->setPaused(false); |
| 1093 | |
| 1094 | res = waitUntilStateThenRelock(/*active*/ true, kActiveTimeout); |
| 1095 | if (res != OK) { |
| 1096 | SET_ERR_L("Can't transition to active in %f seconds!", |
| 1097 | kActiveTimeout/1e9); |
| 1098 | } |
| 1099 | mPauseStateNotify = false; |
Eino-Ville Talvala | f76e027 | 2013-02-27 18:02:26 -0800 | [diff] [blame] | 1100 | return OK; |
Eino-Ville Talvala | 7fa43f3 | 2013-02-06 17:20:07 -0800 | [diff] [blame] | 1101 | } |
| 1102 | |
Eino-Ville Talvala | f1e98d8 | 2013-09-06 09:32:43 -0700 | [diff] [blame] | 1103 | status_t Camera3Device::waitUntilStateThenRelock(bool active, |
| 1104 | nsecs_t timeout) { |
| 1105 | status_t res = OK; |
| 1106 | if (active == (mStatus == STATUS_ACTIVE)) { |
| 1107 | // Desired state already reached |
| 1108 | return res; |
| 1109 | } |
| 1110 | |
| 1111 | bool stateSeen = false; |
| 1112 | do { |
| 1113 | mRecentStatusUpdates.clear(); |
| 1114 | |
| 1115 | res = mStatusChanged.waitRelative(mLock, timeout); |
| 1116 | if (res != OK) break; |
| 1117 | |
| 1118 | // Check state change history during wait |
| 1119 | for (size_t i = 0; i < mRecentStatusUpdates.size(); i++) { |
| 1120 | if (active == (mRecentStatusUpdates[i] == STATUS_ACTIVE) ) { |
| 1121 | stateSeen = true; |
| 1122 | break; |
| 1123 | } |
| 1124 | } |
| 1125 | } while (!stateSeen); |
| 1126 | |
| 1127 | return res; |
| 1128 | } |
| 1129 | |
| 1130 | |
Eino-Ville Talvala | 7fa43f3 | 2013-02-06 17:20:07 -0800 | [diff] [blame] | 1131 | status_t Camera3Device::setNotifyCallback(NotificationListener *listener) { |
| 1132 | ATRACE_CALL(); |
Eino-Ville Talvala | 7d346fa | 2013-03-11 14:13:50 -0700 | [diff] [blame] | 1133 | Mutex::Autolock l(mOutputLock); |
Eino-Ville Talvala | 7fa43f3 | 2013-02-06 17:20:07 -0800 | [diff] [blame] | 1134 | |
Eino-Ville Talvala | 7d346fa | 2013-03-11 14:13:50 -0700 | [diff] [blame] | 1135 | if (listener != NULL && mListener != NULL) { |
| 1136 | ALOGW("%s: Replacing old callback listener", __FUNCTION__); |
| 1137 | } |
| 1138 | mListener = listener; |
| 1139 | |
| 1140 | return OK; |
Eino-Ville Talvala | 7fa43f3 | 2013-02-06 17:20:07 -0800 | [diff] [blame] | 1141 | } |
| 1142 | |
Eino-Ville Talvala | 46910bd | 2013-07-18 19:15:17 -0700 | [diff] [blame] | 1143 | bool Camera3Device::willNotify3A() { |
| 1144 | return false; |
| 1145 | } |
| 1146 | |
Eino-Ville Talvala | 7fa43f3 | 2013-02-06 17:20:07 -0800 | [diff] [blame] | 1147 | status_t Camera3Device::waitForNextFrame(nsecs_t timeout) { |
Eino-Ville Talvala | 7d346fa | 2013-03-11 14:13:50 -0700 | [diff] [blame] | 1148 | status_t res; |
| 1149 | Mutex::Autolock l(mOutputLock); |
Eino-Ville Talvala | 7fa43f3 | 2013-02-06 17:20:07 -0800 | [diff] [blame] | 1150 | |
Eino-Ville Talvala | 7d346fa | 2013-03-11 14:13:50 -0700 | [diff] [blame] | 1151 | while (mResultQueue.empty()) { |
| 1152 | res = mResultSignal.waitRelative(mOutputLock, timeout); |
| 1153 | if (res == TIMED_OUT) { |
| 1154 | return res; |
| 1155 | } else if (res != OK) { |
Colin Cross | e5729fa | 2014-03-21 15:04:25 -0700 | [diff] [blame] | 1156 | ALOGW("%s: Camera %d: No frame in %" PRId64 " ns: %s (%d)", |
Eino-Ville Talvala | b2058d1 | 2013-04-09 13:49:56 -0700 | [diff] [blame] | 1157 | __FUNCTION__, mId, timeout, strerror(-res), res); |
Eino-Ville Talvala | 7d346fa | 2013-03-11 14:13:50 -0700 | [diff] [blame] | 1158 | return res; |
| 1159 | } |
| 1160 | } |
| 1161 | return OK; |
Eino-Ville Talvala | 7fa43f3 | 2013-02-06 17:20:07 -0800 | [diff] [blame] | 1162 | } |
| 1163 | |
Jianing Wei | cb0652e | 2014-03-12 18:29:36 -0700 | [diff] [blame] | 1164 | status_t Camera3Device::getNextResult(CaptureResult *frame) { |
Eino-Ville Talvala | 7fa43f3 | 2013-02-06 17:20:07 -0800 | [diff] [blame] | 1165 | ATRACE_CALL(); |
Eino-Ville Talvala | 7d346fa | 2013-03-11 14:13:50 -0700 | [diff] [blame] | 1166 | Mutex::Autolock l(mOutputLock); |
Eino-Ville Talvala | 7fa43f3 | 2013-02-06 17:20:07 -0800 | [diff] [blame] | 1167 | |
Eino-Ville Talvala | 7d346fa | 2013-03-11 14:13:50 -0700 | [diff] [blame] | 1168 | if (mResultQueue.empty()) { |
| 1169 | return NOT_ENOUGH_DATA; |
| 1170 | } |
| 1171 | |
Jianing Wei | cb0652e | 2014-03-12 18:29:36 -0700 | [diff] [blame] | 1172 | if (frame == NULL) { |
| 1173 | ALOGE("%s: argument cannot be NULL", __FUNCTION__); |
| 1174 | return BAD_VALUE; |
| 1175 | } |
| 1176 | |
| 1177 | CaptureResult &result = *(mResultQueue.begin()); |
| 1178 | frame->mResultExtras = result.mResultExtras; |
| 1179 | frame->mMetadata.acquire(result.mMetadata); |
Eino-Ville Talvala | 7d346fa | 2013-03-11 14:13:50 -0700 | [diff] [blame] | 1180 | mResultQueue.erase(mResultQueue.begin()); |
| 1181 | |
| 1182 | return OK; |
Eino-Ville Talvala | 7fa43f3 | 2013-02-06 17:20:07 -0800 | [diff] [blame] | 1183 | } |
| 1184 | |
| 1185 | status_t Camera3Device::triggerAutofocus(uint32_t id) { |
| 1186 | ATRACE_CALL(); |
Eino-Ville Talvala | f1e98d8 | 2013-09-06 09:32:43 -0700 | [diff] [blame] | 1187 | Mutex::Autolock il(mInterfaceLock); |
Eino-Ville Talvala | 7fa43f3 | 2013-02-06 17:20:07 -0800 | [diff] [blame] | 1188 | |
Igor Murashkin | 4d2f2e8 | 2013-04-01 17:29:07 -0700 | [diff] [blame] | 1189 | ALOGV("%s: Triggering autofocus, id %d", __FUNCTION__, id); |
| 1190 | // Mix-in this trigger into the next request and only the next request. |
| 1191 | RequestTrigger trigger[] = { |
| 1192 | { |
| 1193 | ANDROID_CONTROL_AF_TRIGGER, |
| 1194 | ANDROID_CONTROL_AF_TRIGGER_START |
| 1195 | }, |
| 1196 | { |
| 1197 | ANDROID_CONTROL_AF_TRIGGER_ID, |
| 1198 | static_cast<int32_t>(id) |
Yin-Chia Yeh | 741ace8 | 2014-06-23 14:07:56 -0700 | [diff] [blame] | 1199 | } |
Igor Murashkin | 4d2f2e8 | 2013-04-01 17:29:07 -0700 | [diff] [blame] | 1200 | }; |
| 1201 | |
| 1202 | return mRequestThread->queueTrigger(trigger, |
| 1203 | sizeof(trigger)/sizeof(trigger[0])); |
Eino-Ville Talvala | 7fa43f3 | 2013-02-06 17:20:07 -0800 | [diff] [blame] | 1204 | } |
| 1205 | |
| 1206 | status_t Camera3Device::triggerCancelAutofocus(uint32_t id) { |
| 1207 | ATRACE_CALL(); |
Eino-Ville Talvala | f1e98d8 | 2013-09-06 09:32:43 -0700 | [diff] [blame] | 1208 | Mutex::Autolock il(mInterfaceLock); |
Eino-Ville Talvala | 7fa43f3 | 2013-02-06 17:20:07 -0800 | [diff] [blame] | 1209 | |
Igor Murashkin | 4d2f2e8 | 2013-04-01 17:29:07 -0700 | [diff] [blame] | 1210 | ALOGV("%s: Triggering cancel autofocus, id %d", __FUNCTION__, id); |
| 1211 | // Mix-in this trigger into the next request and only the next request. |
| 1212 | RequestTrigger trigger[] = { |
| 1213 | { |
| 1214 | ANDROID_CONTROL_AF_TRIGGER, |
| 1215 | ANDROID_CONTROL_AF_TRIGGER_CANCEL |
| 1216 | }, |
| 1217 | { |
| 1218 | ANDROID_CONTROL_AF_TRIGGER_ID, |
| 1219 | static_cast<int32_t>(id) |
Yin-Chia Yeh | 741ace8 | 2014-06-23 14:07:56 -0700 | [diff] [blame] | 1220 | } |
Igor Murashkin | 4d2f2e8 | 2013-04-01 17:29:07 -0700 | [diff] [blame] | 1221 | }; |
Eino-Ville Talvala | 7fa43f3 | 2013-02-06 17:20:07 -0800 | [diff] [blame] | 1222 | |
Igor Murashkin | 4d2f2e8 | 2013-04-01 17:29:07 -0700 | [diff] [blame] | 1223 | return mRequestThread->queueTrigger(trigger, |
| 1224 | sizeof(trigger)/sizeof(trigger[0])); |
Eino-Ville Talvala | 7fa43f3 | 2013-02-06 17:20:07 -0800 | [diff] [blame] | 1225 | } |
| 1226 | |
| 1227 | status_t Camera3Device::triggerPrecaptureMetering(uint32_t id) { |
| 1228 | ATRACE_CALL(); |
Eino-Ville Talvala | f1e98d8 | 2013-09-06 09:32:43 -0700 | [diff] [blame] | 1229 | Mutex::Autolock il(mInterfaceLock); |
Eino-Ville Talvala | 7fa43f3 | 2013-02-06 17:20:07 -0800 | [diff] [blame] | 1230 | |
Igor Murashkin | 4d2f2e8 | 2013-04-01 17:29:07 -0700 | [diff] [blame] | 1231 | ALOGV("%s: Triggering precapture metering, id %d", __FUNCTION__, id); |
| 1232 | // Mix-in this trigger into the next request and only the next request. |
| 1233 | RequestTrigger trigger[] = { |
| 1234 | { |
| 1235 | ANDROID_CONTROL_AE_PRECAPTURE_TRIGGER, |
| 1236 | ANDROID_CONTROL_AE_PRECAPTURE_TRIGGER_START |
| 1237 | }, |
| 1238 | { |
| 1239 | ANDROID_CONTROL_AE_PRECAPTURE_ID, |
| 1240 | static_cast<int32_t>(id) |
Yin-Chia Yeh | 741ace8 | 2014-06-23 14:07:56 -0700 | [diff] [blame] | 1241 | } |
Igor Murashkin | 4d2f2e8 | 2013-04-01 17:29:07 -0700 | [diff] [blame] | 1242 | }; |
Eino-Ville Talvala | 7fa43f3 | 2013-02-06 17:20:07 -0800 | [diff] [blame] | 1243 | |
Igor Murashkin | 4d2f2e8 | 2013-04-01 17:29:07 -0700 | [diff] [blame] | 1244 | return mRequestThread->queueTrigger(trigger, |
| 1245 | sizeof(trigger)/sizeof(trigger[0])); |
Eino-Ville Talvala | 7fa43f3 | 2013-02-06 17:20:07 -0800 | [diff] [blame] | 1246 | } |
| 1247 | |
| 1248 | status_t Camera3Device::pushReprocessBuffer(int reprocessStreamId, |
| 1249 | buffer_handle_t *buffer, wp<BufferReleasedListener> listener) { |
| 1250 | ATRACE_CALL(); |
| 1251 | (void)reprocessStreamId; (void)buffer; (void)listener; |
| 1252 | |
Eino-Ville Talvala | b2058d1 | 2013-04-09 13:49:56 -0700 | [diff] [blame] | 1253 | CLOGE("Unimplemented"); |
Eino-Ville Talvala | 7fa43f3 | 2013-02-06 17:20:07 -0800 | [diff] [blame] | 1254 | return INVALID_OPERATION; |
| 1255 | } |
| 1256 | |
Jianing Wei | cb0652e | 2014-03-12 18:29:36 -0700 | [diff] [blame] | 1257 | status_t Camera3Device::flush(int64_t *frameNumber) { |
Eino-Ville Talvala | abaa51d | 2013-08-14 11:37:00 -0700 | [diff] [blame] | 1258 | ATRACE_CALL(); |
| 1259 | ALOGV("%s: Camera %d: Flushing all requests", __FUNCTION__, mId); |
Eino-Ville Talvala | f1e98d8 | 2013-09-06 09:32:43 -0700 | [diff] [blame] | 1260 | Mutex::Autolock il(mInterfaceLock); |
Eino-Ville Talvala | abaa51d | 2013-08-14 11:37:00 -0700 | [diff] [blame] | 1261 | |
Zhijun He | 7ef2039 | 2014-04-21 16:04:17 -0700 | [diff] [blame] | 1262 | { |
| 1263 | Mutex::Autolock l(mLock); |
| 1264 | mRequestThread->clear(/*out*/frameNumber); |
| 1265 | } |
| 1266 | |
Zhijun He | 491e341 | 2013-12-27 10:57:44 -0800 | [diff] [blame] | 1267 | status_t res; |
| 1268 | if (mHal3Device->common.version >= CAMERA_DEVICE_API_VERSION_3_1) { |
| 1269 | res = mHal3Device->ops->flush(mHal3Device); |
| 1270 | } else { |
Zhijun He | 7ef2039 | 2014-04-21 16:04:17 -0700 | [diff] [blame] | 1271 | Mutex::Autolock l(mLock); |
Zhijun He | 69a3748 | 2014-03-23 18:44:49 -0700 | [diff] [blame] | 1272 | res = waitUntilDrainedLocked(); |
Zhijun He | 491e341 | 2013-12-27 10:57:44 -0800 | [diff] [blame] | 1273 | } |
| 1274 | |
| 1275 | return res; |
Eino-Ville Talvala | abaa51d | 2013-08-14 11:37:00 -0700 | [diff] [blame] | 1276 | } |
| 1277 | |
Zhijun He | 204e329 | 2014-07-14 17:09:23 -0700 | [diff] [blame] | 1278 | uint32_t Camera3Device::getDeviceVersion() { |
| 1279 | ATRACE_CALL(); |
| 1280 | Mutex::Autolock il(mInterfaceLock); |
| 1281 | return mDeviceVersion; |
| 1282 | } |
| 1283 | |
Eino-Ville Talvala | f76e027 | 2013-02-27 18:02:26 -0800 | [diff] [blame] | 1284 | /** |
Eino-Ville Talvala | f1e98d8 | 2013-09-06 09:32:43 -0700 | [diff] [blame] | 1285 | * Methods called by subclasses |
| 1286 | */ |
| 1287 | |
| 1288 | void Camera3Device::notifyStatus(bool idle) { |
| 1289 | { |
| 1290 | // Need mLock to safely update state and synchronize to current |
| 1291 | // state of methods in flight. |
| 1292 | Mutex::Autolock l(mLock); |
| 1293 | // We can get various system-idle notices from the status tracker |
| 1294 | // while starting up. Only care about them if we've actually sent |
| 1295 | // in some requests recently. |
| 1296 | if (mStatus != STATUS_ACTIVE && mStatus != STATUS_CONFIGURED) { |
| 1297 | return; |
| 1298 | } |
| 1299 | ALOGV("%s: Camera %d: Now %s", __FUNCTION__, mId, |
| 1300 | idle ? "idle" : "active"); |
| 1301 | mStatus = idle ? STATUS_CONFIGURED : STATUS_ACTIVE; |
| 1302 | mRecentStatusUpdates.add(mStatus); |
| 1303 | mStatusChanged.signal(); |
| 1304 | |
| 1305 | // Skip notifying listener if we're doing some user-transparent |
| 1306 | // state changes |
| 1307 | if (mPauseStateNotify) return; |
| 1308 | } |
| 1309 | NotificationListener *listener; |
| 1310 | { |
| 1311 | Mutex::Autolock l(mOutputLock); |
| 1312 | listener = mListener; |
| 1313 | } |
| 1314 | if (idle && listener != NULL) { |
| 1315 | listener->notifyIdle(); |
| 1316 | } |
| 1317 | } |
| 1318 | |
| 1319 | /** |
Eino-Ville Talvala | f76e027 | 2013-02-27 18:02:26 -0800 | [diff] [blame] | 1320 | * Camera3Device private methods |
| 1321 | */ |
| 1322 | |
| 1323 | sp<Camera3Device::CaptureRequest> Camera3Device::createCaptureRequest( |
| 1324 | const CameraMetadata &request) { |
| 1325 | ATRACE_CALL(); |
| 1326 | status_t res; |
| 1327 | |
| 1328 | sp<CaptureRequest> newRequest = new CaptureRequest; |
| 1329 | newRequest->mSettings = request; |
| 1330 | |
| 1331 | camera_metadata_entry_t inputStreams = |
| 1332 | newRequest->mSettings.find(ANDROID_REQUEST_INPUT_STREAMS); |
| 1333 | if (inputStreams.count > 0) { |
| 1334 | if (mInputStream == NULL || |
Zhijun He | d1d6467 | 2013-09-06 15:00:01 -0700 | [diff] [blame] | 1335 | mInputStream->getId() != inputStreams.data.i32[0]) { |
Eino-Ville Talvala | b2058d1 | 2013-04-09 13:49:56 -0700 | [diff] [blame] | 1336 | CLOGE("Request references unknown input stream %d", |
| 1337 | inputStreams.data.u8[0]); |
Eino-Ville Talvala | f76e027 | 2013-02-27 18:02:26 -0800 | [diff] [blame] | 1338 | return NULL; |
| 1339 | } |
| 1340 | // Lazy completion of stream configuration (allocation/registration) |
| 1341 | // on first use |
| 1342 | if (mInputStream->isConfiguring()) { |
| 1343 | res = mInputStream->finishConfiguration(mHal3Device); |
| 1344 | if (res != OK) { |
Eino-Ville Talvala | b2058d1 | 2013-04-09 13:49:56 -0700 | [diff] [blame] | 1345 | SET_ERR_L("Unable to finish configuring input stream %d:" |
Eino-Ville Talvala | f76e027 | 2013-02-27 18:02:26 -0800 | [diff] [blame] | 1346 | " %s (%d)", |
Eino-Ville Talvala | b2058d1 | 2013-04-09 13:49:56 -0700 | [diff] [blame] | 1347 | mInputStream->getId(), strerror(-res), res); |
Eino-Ville Talvala | f76e027 | 2013-02-27 18:02:26 -0800 | [diff] [blame] | 1348 | return NULL; |
| 1349 | } |
| 1350 | } |
| 1351 | |
| 1352 | newRequest->mInputStream = mInputStream; |
| 1353 | newRequest->mSettings.erase(ANDROID_REQUEST_INPUT_STREAMS); |
| 1354 | } |
| 1355 | |
| 1356 | camera_metadata_entry_t streams = |
| 1357 | newRequest->mSettings.find(ANDROID_REQUEST_OUTPUT_STREAMS); |
| 1358 | if (streams.count == 0) { |
Eino-Ville Talvala | b2058d1 | 2013-04-09 13:49:56 -0700 | [diff] [blame] | 1359 | CLOGE("Zero output streams specified!"); |
Eino-Ville Talvala | f76e027 | 2013-02-27 18:02:26 -0800 | [diff] [blame] | 1360 | return NULL; |
| 1361 | } |
| 1362 | |
| 1363 | for (size_t i = 0; i < streams.count; i++) { |
Zhijun He | d1d6467 | 2013-09-06 15:00:01 -0700 | [diff] [blame] | 1364 | int idx = mOutputStreams.indexOfKey(streams.data.i32[i]); |
Eino-Ville Talvala | f76e027 | 2013-02-27 18:02:26 -0800 | [diff] [blame] | 1365 | if (idx == NAME_NOT_FOUND) { |
Eino-Ville Talvala | b2058d1 | 2013-04-09 13:49:56 -0700 | [diff] [blame] | 1366 | CLOGE("Request references unknown stream %d", |
| 1367 | streams.data.u8[i]); |
Eino-Ville Talvala | f76e027 | 2013-02-27 18:02:26 -0800 | [diff] [blame] | 1368 | return NULL; |
| 1369 | } |
Igor Murashkin | 2fba584 | 2013-04-22 14:03:54 -0700 | [diff] [blame] | 1370 | sp<Camera3OutputStreamInterface> stream = |
| 1371 | mOutputStreams.editValueAt(idx); |
Eino-Ville Talvala | f76e027 | 2013-02-27 18:02:26 -0800 | [diff] [blame] | 1372 | |
| 1373 | // Lazy completion of stream configuration (allocation/registration) |
| 1374 | // on first use |
| 1375 | if (stream->isConfiguring()) { |
| 1376 | res = stream->finishConfiguration(mHal3Device); |
| 1377 | if (res != OK) { |
Eino-Ville Talvala | b2058d1 | 2013-04-09 13:49:56 -0700 | [diff] [blame] | 1378 | SET_ERR_L("Unable to finish configuring stream %d: %s (%d)", |
| 1379 | stream->getId(), strerror(-res), res); |
Eino-Ville Talvala | f76e027 | 2013-02-27 18:02:26 -0800 | [diff] [blame] | 1380 | return NULL; |
| 1381 | } |
| 1382 | } |
| 1383 | |
| 1384 | newRequest->mOutputStreams.push(stream); |
| 1385 | } |
| 1386 | newRequest->mSettings.erase(ANDROID_REQUEST_OUTPUT_STREAMS); |
| 1387 | |
| 1388 | return newRequest; |
Eino-Ville Talvala | 7fa43f3 | 2013-02-06 17:20:07 -0800 | [diff] [blame] | 1389 | } |
| 1390 | |
Eino-Ville Talvala | f76e027 | 2013-02-27 18:02:26 -0800 | [diff] [blame] | 1391 | status_t Camera3Device::configureStreamsLocked() { |
| 1392 | ATRACE_CALL(); |
| 1393 | status_t res; |
Eino-Ville Talvala | 7fa43f3 | 2013-02-06 17:20:07 -0800 | [diff] [blame] | 1394 | |
Eino-Ville Talvala | f1e98d8 | 2013-09-06 09:32:43 -0700 | [diff] [blame] | 1395 | if (mStatus != STATUS_UNCONFIGURED && mStatus != STATUS_CONFIGURED) { |
Eino-Ville Talvala | b2058d1 | 2013-04-09 13:49:56 -0700 | [diff] [blame] | 1396 | CLOGE("Not idle"); |
Eino-Ville Talvala | f76e027 | 2013-02-27 18:02:26 -0800 | [diff] [blame] | 1397 | return INVALID_OPERATION; |
| 1398 | } |
| 1399 | |
Eino-Ville Talvala | ea26c77 | 2013-06-11 16:04:06 -0700 | [diff] [blame] | 1400 | if (!mNeedConfig) { |
| 1401 | ALOGV("%s: Skipping config, no stream changes", __FUNCTION__); |
| 1402 | return OK; |
| 1403 | } |
| 1404 | |
Eino-Ville Talvala | f76e027 | 2013-02-27 18:02:26 -0800 | [diff] [blame] | 1405 | // Start configuring the streams |
Eino-Ville Talvala | f1e98d8 | 2013-09-06 09:32:43 -0700 | [diff] [blame] | 1406 | ALOGV("%s: Camera %d: Starting stream configuration", __FUNCTION__, mId); |
Eino-Ville Talvala | f76e027 | 2013-02-27 18:02:26 -0800 | [diff] [blame] | 1407 | |
| 1408 | camera3_stream_configuration config; |
| 1409 | |
| 1410 | config.num_streams = (mInputStream != NULL) + mOutputStreams.size(); |
| 1411 | |
| 1412 | Vector<camera3_stream_t*> streams; |
| 1413 | streams.setCapacity(config.num_streams); |
| 1414 | |
| 1415 | if (mInputStream != NULL) { |
| 1416 | camera3_stream_t *inputStream; |
| 1417 | inputStream = mInputStream->startConfiguration(); |
| 1418 | if (inputStream == NULL) { |
Eino-Ville Talvala | b2058d1 | 2013-04-09 13:49:56 -0700 | [diff] [blame] | 1419 | SET_ERR_L("Can't start input stream configuration"); |
Eino-Ville Talvala | f76e027 | 2013-02-27 18:02:26 -0800 | [diff] [blame] | 1420 | return INVALID_OPERATION; |
| 1421 | } |
| 1422 | streams.add(inputStream); |
| 1423 | } |
| 1424 | |
| 1425 | for (size_t i = 0; i < mOutputStreams.size(); i++) { |
Igor Murashkin | 2fba584 | 2013-04-22 14:03:54 -0700 | [diff] [blame] | 1426 | |
| 1427 | // Don't configure bidi streams twice, nor add them twice to the list |
| 1428 | if (mOutputStreams[i].get() == |
| 1429 | static_cast<Camera3StreamInterface*>(mInputStream.get())) { |
| 1430 | |
| 1431 | config.num_streams--; |
| 1432 | continue; |
| 1433 | } |
| 1434 | |
Eino-Ville Talvala | f76e027 | 2013-02-27 18:02:26 -0800 | [diff] [blame] | 1435 | camera3_stream_t *outputStream; |
| 1436 | outputStream = mOutputStreams.editValueAt(i)->startConfiguration(); |
| 1437 | if (outputStream == NULL) { |
Eino-Ville Talvala | b2058d1 | 2013-04-09 13:49:56 -0700 | [diff] [blame] | 1438 | SET_ERR_L("Can't start output stream configuration"); |
Eino-Ville Talvala | f76e027 | 2013-02-27 18:02:26 -0800 | [diff] [blame] | 1439 | return INVALID_OPERATION; |
| 1440 | } |
| 1441 | streams.add(outputStream); |
| 1442 | } |
| 1443 | |
| 1444 | config.streams = streams.editArray(); |
| 1445 | |
| 1446 | // Do the HAL configuration; will potentially touch stream |
| 1447 | // max_buffers, usage, priv fields. |
Eino-Ville Talvala | 17a61ad | 2013-06-03 16:53:32 -0700 | [diff] [blame] | 1448 | ATRACE_BEGIN("camera3->configure_streams"); |
Eino-Ville Talvala | f76e027 | 2013-02-27 18:02:26 -0800 | [diff] [blame] | 1449 | res = mHal3Device->ops->configure_streams(mHal3Device, &config); |
Eino-Ville Talvala | 17a61ad | 2013-06-03 16:53:32 -0700 | [diff] [blame] | 1450 | ATRACE_END(); |
Eino-Ville Talvala | f76e027 | 2013-02-27 18:02:26 -0800 | [diff] [blame] | 1451 | |
| 1452 | if (res != OK) { |
Eino-Ville Talvala | b2058d1 | 2013-04-09 13:49:56 -0700 | [diff] [blame] | 1453 | SET_ERR_L("Unable to configure streams with HAL: %s (%d)", |
| 1454 | strerror(-res), res); |
Eino-Ville Talvala | f76e027 | 2013-02-27 18:02:26 -0800 | [diff] [blame] | 1455 | return res; |
| 1456 | } |
| 1457 | |
Eino-Ville Talvala | 4c95676 | 2013-04-19 17:26:13 -0700 | [diff] [blame] | 1458 | // Finish all stream configuration immediately. |
| 1459 | // TODO: Try to relax this later back to lazy completion, which should be |
| 1460 | // faster |
| 1461 | |
Igor Murashkin | 073f857 | 2013-05-02 14:59:28 -0700 | [diff] [blame] | 1462 | if (mInputStream != NULL && mInputStream->isConfiguring()) { |
Eino-Ville Talvala | 4c95676 | 2013-04-19 17:26:13 -0700 | [diff] [blame] | 1463 | res = mInputStream->finishConfiguration(mHal3Device); |
| 1464 | if (res != OK) { |
| 1465 | SET_ERR_L("Can't finish configuring input stream %d: %s (%d)", |
| 1466 | mInputStream->getId(), strerror(-res), res); |
| 1467 | return res; |
| 1468 | } |
| 1469 | } |
| 1470 | |
| 1471 | for (size_t i = 0; i < mOutputStreams.size(); i++) { |
Igor Murashkin | 073f857 | 2013-05-02 14:59:28 -0700 | [diff] [blame] | 1472 | sp<Camera3OutputStreamInterface> outputStream = |
| 1473 | mOutputStreams.editValueAt(i); |
| 1474 | if (outputStream->isConfiguring()) { |
| 1475 | res = outputStream->finishConfiguration(mHal3Device); |
| 1476 | if (res != OK) { |
| 1477 | SET_ERR_L("Can't finish configuring output stream %d: %s (%d)", |
| 1478 | outputStream->getId(), strerror(-res), res); |
| 1479 | return res; |
| 1480 | } |
Eino-Ville Talvala | 4c95676 | 2013-04-19 17:26:13 -0700 | [diff] [blame] | 1481 | } |
| 1482 | } |
| 1483 | |
Eino-Ville Talvala | f76e027 | 2013-02-27 18:02:26 -0800 | [diff] [blame] | 1484 | // Request thread needs to know to avoid using repeat-last-settings protocol |
| 1485 | // across configure_streams() calls |
| 1486 | mRequestThread->configurationComplete(); |
| 1487 | |
Eino-Ville Talvala | f1e98d8 | 2013-09-06 09:32:43 -0700 | [diff] [blame] | 1488 | // Update device state |
Eino-Ville Talvala | f76e027 | 2013-02-27 18:02:26 -0800 | [diff] [blame] | 1489 | |
Eino-Ville Talvala | ea26c77 | 2013-06-11 16:04:06 -0700 | [diff] [blame] | 1490 | mNeedConfig = false; |
Eino-Ville Talvala | f76e027 | 2013-02-27 18:02:26 -0800 | [diff] [blame] | 1491 | |
Eino-Ville Talvala | f1e98d8 | 2013-09-06 09:32:43 -0700 | [diff] [blame] | 1492 | if (config.num_streams > 0) { |
| 1493 | mStatus = STATUS_CONFIGURED; |
| 1494 | } else { |
| 1495 | mStatus = STATUS_UNCONFIGURED; |
| 1496 | } |
| 1497 | |
| 1498 | ALOGV("%s: Camera %d: Stream configuration complete", __FUNCTION__, mId); |
| 1499 | |
Eino-Ville Talvala | f76e027 | 2013-02-27 18:02:26 -0800 | [diff] [blame] | 1500 | return OK; |
Eino-Ville Talvala | 7fa43f3 | 2013-02-06 17:20:07 -0800 | [diff] [blame] | 1501 | } |
| 1502 | |
Eino-Ville Talvala | b2058d1 | 2013-04-09 13:49:56 -0700 | [diff] [blame] | 1503 | void Camera3Device::setErrorState(const char *fmt, ...) { |
| 1504 | Mutex::Autolock l(mLock); |
| 1505 | va_list args; |
| 1506 | va_start(args, fmt); |
| 1507 | |
| 1508 | setErrorStateLockedV(fmt, args); |
| 1509 | |
| 1510 | va_end(args); |
| 1511 | } |
| 1512 | |
| 1513 | void Camera3Device::setErrorStateV(const char *fmt, va_list args) { |
| 1514 | Mutex::Autolock l(mLock); |
| 1515 | setErrorStateLockedV(fmt, args); |
| 1516 | } |
| 1517 | |
| 1518 | void Camera3Device::setErrorStateLocked(const char *fmt, ...) { |
| 1519 | va_list args; |
| 1520 | va_start(args, fmt); |
| 1521 | |
| 1522 | setErrorStateLockedV(fmt, args); |
| 1523 | |
| 1524 | va_end(args); |
| 1525 | } |
| 1526 | |
| 1527 | void Camera3Device::setErrorStateLockedV(const char *fmt, va_list args) { |
Eino-Ville Talvala | 42368d9 | 2013-04-09 14:13:50 -0700 | [diff] [blame] | 1528 | // Print out all error messages to log |
| 1529 | String8 errorCause = String8::formatV(fmt, args); |
| 1530 | ALOGE("Camera %d: %s", mId, errorCause.string()); |
| 1531 | |
| 1532 | // But only do error state transition steps for the first error |
Zhijun He | b05eeae | 2013-06-06 13:51:22 -0700 | [diff] [blame] | 1533 | if (mStatus == STATUS_ERROR || mStatus == STATUS_UNINITIALIZED) return; |
Eino-Ville Talvala | b2058d1 | 2013-04-09 13:49:56 -0700 | [diff] [blame] | 1534 | |
Igor Murashkin | ff3e31d | 2013-10-23 16:40:06 -0700 | [diff] [blame] | 1535 | // Save stack trace. View by dumping it later. |
| 1536 | CameraTraces::saveTrace(); |
| 1537 | // TODO: consider adding errorCause and client pid/procname |
| 1538 | |
Eino-Ville Talvala | 42368d9 | 2013-04-09 14:13:50 -0700 | [diff] [blame] | 1539 | mErrorCause = errorCause; |
| 1540 | |
| 1541 | mRequestThread->setPaused(true); |
Eino-Ville Talvala | b2058d1 | 2013-04-09 13:49:56 -0700 | [diff] [blame] | 1542 | mStatus = STATUS_ERROR; |
| 1543 | } |
Eino-Ville Talvala | f76e027 | 2013-02-27 18:02:26 -0800 | [diff] [blame] | 1544 | |
| 1545 | /** |
Eino-Ville Talvala | 42368d9 | 2013-04-09 14:13:50 -0700 | [diff] [blame] | 1546 | * In-flight request management |
| 1547 | */ |
| 1548 | |
Jianing Wei | cb0652e | 2014-03-12 18:29:36 -0700 | [diff] [blame] | 1549 | status_t Camera3Device::registerInFlight(uint32_t frameNumber, |
Zhijun He | c98bd8d | 2014-07-07 12:44:10 -0700 | [diff] [blame] | 1550 | int32_t numBuffers, CaptureResultExtras resultExtras, bool hasInput) { |
Eino-Ville Talvala | 42368d9 | 2013-04-09 14:13:50 -0700 | [diff] [blame] | 1551 | ATRACE_CALL(); |
| 1552 | Mutex::Autolock l(mInFlightLock); |
| 1553 | |
| 1554 | ssize_t res; |
Zhijun He | c98bd8d | 2014-07-07 12:44:10 -0700 | [diff] [blame] | 1555 | res = mInFlightMap.add(frameNumber, InFlightRequest(numBuffers, resultExtras, hasInput)); |
Eino-Ville Talvala | 42368d9 | 2013-04-09 14:13:50 -0700 | [diff] [blame] | 1556 | if (res < 0) return res; |
| 1557 | |
| 1558 | return OK; |
| 1559 | } |
| 1560 | |
| 1561 | /** |
Eino-Ville Talvala | fd6ecdd | 2013-10-11 09:51:09 -0700 | [diff] [blame] | 1562 | * Check if all 3A fields are ready, and send off a partial 3A-only result |
| 1563 | * to the output frame queue |
| 1564 | */ |
Zhijun He | 204e329 | 2014-07-14 17:09:23 -0700 | [diff] [blame] | 1565 | bool Camera3Device::processPartial3AResult( |
Jianing Wei | cb0652e | 2014-03-12 18:29:36 -0700 | [diff] [blame] | 1566 | uint32_t frameNumber, |
| 1567 | const CameraMetadata& partial, const CaptureResultExtras& resultExtras) { |
Eino-Ville Talvala | fd6ecdd | 2013-10-11 09:51:09 -0700 | [diff] [blame] | 1568 | |
| 1569 | // Check if all 3A states are present |
| 1570 | // The full list of fields is |
| 1571 | // android.control.afMode |
| 1572 | // android.control.awbMode |
| 1573 | // android.control.aeState |
| 1574 | // android.control.awbState |
| 1575 | // android.control.afState |
| 1576 | // android.control.afTriggerID |
| 1577 | // android.control.aePrecaptureID |
| 1578 | // TODO: Add android.control.aeMode |
| 1579 | |
| 1580 | bool gotAllStates = true; |
| 1581 | |
| 1582 | uint8_t afMode; |
| 1583 | uint8_t awbMode; |
| 1584 | uint8_t aeState; |
| 1585 | uint8_t afState; |
| 1586 | uint8_t awbState; |
Eino-Ville Talvala | fd6ecdd | 2013-10-11 09:51:09 -0700 | [diff] [blame] | 1587 | |
| 1588 | gotAllStates &= get3AResult(partial, ANDROID_CONTROL_AF_MODE, |
| 1589 | &afMode, frameNumber); |
| 1590 | |
| 1591 | gotAllStates &= get3AResult(partial, ANDROID_CONTROL_AWB_MODE, |
| 1592 | &awbMode, frameNumber); |
| 1593 | |
| 1594 | gotAllStates &= get3AResult(partial, ANDROID_CONTROL_AE_STATE, |
| 1595 | &aeState, frameNumber); |
| 1596 | |
| 1597 | gotAllStates &= get3AResult(partial, ANDROID_CONTROL_AF_STATE, |
| 1598 | &afState, frameNumber); |
| 1599 | |
| 1600 | gotAllStates &= get3AResult(partial, ANDROID_CONTROL_AWB_STATE, |
| 1601 | &awbState, frameNumber); |
| 1602 | |
Eino-Ville Talvala | fd6ecdd | 2013-10-11 09:51:09 -0700 | [diff] [blame] | 1603 | if (!gotAllStates) return false; |
| 1604 | |
Eino-Ville Talvala | 184dfe4 | 2013-11-07 15:13:16 -0800 | [diff] [blame] | 1605 | ALOGVV("%s: Camera %d: Frame %d, Request ID %d: AF mode %d, AWB mode %d, " |
Eino-Ville Talvala | fd6ecdd | 2013-10-11 09:51:09 -0700 | [diff] [blame] | 1606 | "AF state %d, AE state %d, AWB state %d, " |
| 1607 | "AF trigger %d, AE precapture trigger %d", |
Jianing Wei | 2d6bb3f | 2014-04-11 10:00:31 -0700 | [diff] [blame] | 1608 | __FUNCTION__, mId, frameNumber, resultExtras.requestId, |
Eino-Ville Talvala | fd6ecdd | 2013-10-11 09:51:09 -0700 | [diff] [blame] | 1609 | afMode, awbMode, |
| 1610 | afState, aeState, awbState, |
Yin-Chia Yeh | 741ace8 | 2014-06-23 14:07:56 -0700 | [diff] [blame] | 1611 | resultExtras.afTriggerId, resultExtras.precaptureTriggerId); |
Eino-Ville Talvala | fd6ecdd | 2013-10-11 09:51:09 -0700 | [diff] [blame] | 1612 | |
| 1613 | // Got all states, so construct a minimal result to send |
| 1614 | // In addition to the above fields, this means adding in |
| 1615 | // android.request.frameCount |
Eino-Ville Talvala | 184dfe4 | 2013-11-07 15:13:16 -0800 | [diff] [blame] | 1616 | // android.request.requestId |
Zhijun He | 204e329 | 2014-07-14 17:09:23 -0700 | [diff] [blame] | 1617 | // android.quirks.partialResult (for HAL version below HAL3.2) |
Eino-Ville Talvala | fd6ecdd | 2013-10-11 09:51:09 -0700 | [diff] [blame] | 1618 | |
Eino-Ville Talvala | 184dfe4 | 2013-11-07 15:13:16 -0800 | [diff] [blame] | 1619 | const size_t kMinimal3AResultEntries = 10; |
Eino-Ville Talvala | fd6ecdd | 2013-10-11 09:51:09 -0700 | [diff] [blame] | 1620 | |
| 1621 | Mutex::Autolock l(mOutputLock); |
| 1622 | |
Jianing Wei | cb0652e | 2014-03-12 18:29:36 -0700 | [diff] [blame] | 1623 | CaptureResult captureResult; |
| 1624 | captureResult.mResultExtras = resultExtras; |
| 1625 | captureResult.mMetadata = CameraMetadata(kMinimal3AResultEntries, /*dataCapacity*/ 0); |
| 1626 | // TODO: change this to sp<CaptureResult>. This will need other changes, including, |
| 1627 | // but not limited to CameraDeviceBase::getNextResult |
| 1628 | CaptureResult& min3AResult = |
| 1629 | *mResultQueue.insert(mResultQueue.end(), captureResult); |
Eino-Ville Talvala | fd6ecdd | 2013-10-11 09:51:09 -0700 | [diff] [blame] | 1630 | |
Jianing Wei | cb0652e | 2014-03-12 18:29:36 -0700 | [diff] [blame] | 1631 | if (!insert3AResult(min3AResult.mMetadata, ANDROID_REQUEST_FRAME_COUNT, |
| 1632 | // TODO: This is problematic casting. Need to fix CameraMetadata. |
| 1633 | reinterpret_cast<int32_t*>(&frameNumber), frameNumber)) { |
Eino-Ville Talvala | fd6ecdd | 2013-10-11 09:51:09 -0700 | [diff] [blame] | 1634 | return false; |
| 1635 | } |
| 1636 | |
Jianing Wei | cb0652e | 2014-03-12 18:29:36 -0700 | [diff] [blame] | 1637 | int32_t requestId = resultExtras.requestId; |
| 1638 | if (!insert3AResult(min3AResult.mMetadata, ANDROID_REQUEST_ID, |
Eino-Ville Talvala | 184dfe4 | 2013-11-07 15:13:16 -0800 | [diff] [blame] | 1639 | &requestId, frameNumber)) { |
| 1640 | return false; |
| 1641 | } |
| 1642 | |
Zhijun He | 204e329 | 2014-07-14 17:09:23 -0700 | [diff] [blame] | 1643 | if (mDeviceVersion < CAMERA_DEVICE_API_VERSION_3_2) { |
| 1644 | static const uint8_t partialResult = ANDROID_QUIRKS_PARTIAL_RESULT_PARTIAL; |
| 1645 | if (!insert3AResult(min3AResult.mMetadata, ANDROID_QUIRKS_PARTIAL_RESULT, |
| 1646 | &partialResult, frameNumber)) { |
| 1647 | return false; |
| 1648 | } |
Eino-Ville Talvala | fd6ecdd | 2013-10-11 09:51:09 -0700 | [diff] [blame] | 1649 | } |
| 1650 | |
Jianing Wei | cb0652e | 2014-03-12 18:29:36 -0700 | [diff] [blame] | 1651 | if (!insert3AResult(min3AResult.mMetadata, ANDROID_CONTROL_AF_MODE, |
Eino-Ville Talvala | fd6ecdd | 2013-10-11 09:51:09 -0700 | [diff] [blame] | 1652 | &afMode, frameNumber)) { |
| 1653 | return false; |
| 1654 | } |
| 1655 | |
Jianing Wei | cb0652e | 2014-03-12 18:29:36 -0700 | [diff] [blame] | 1656 | if (!insert3AResult(min3AResult.mMetadata, ANDROID_CONTROL_AWB_MODE, |
Eino-Ville Talvala | fd6ecdd | 2013-10-11 09:51:09 -0700 | [diff] [blame] | 1657 | &awbMode, frameNumber)) { |
| 1658 | return false; |
| 1659 | } |
| 1660 | |
Jianing Wei | cb0652e | 2014-03-12 18:29:36 -0700 | [diff] [blame] | 1661 | if (!insert3AResult(min3AResult.mMetadata, ANDROID_CONTROL_AE_STATE, |
Eino-Ville Talvala | fd6ecdd | 2013-10-11 09:51:09 -0700 | [diff] [blame] | 1662 | &aeState, frameNumber)) { |
| 1663 | return false; |
| 1664 | } |
| 1665 | |
Jianing Wei | cb0652e | 2014-03-12 18:29:36 -0700 | [diff] [blame] | 1666 | if (!insert3AResult(min3AResult.mMetadata, ANDROID_CONTROL_AF_STATE, |
Eino-Ville Talvala | fd6ecdd | 2013-10-11 09:51:09 -0700 | [diff] [blame] | 1667 | &afState, frameNumber)) { |
| 1668 | return false; |
| 1669 | } |
| 1670 | |
Jianing Wei | cb0652e | 2014-03-12 18:29:36 -0700 | [diff] [blame] | 1671 | if (!insert3AResult(min3AResult.mMetadata, ANDROID_CONTROL_AWB_STATE, |
Eino-Ville Talvala | fd6ecdd | 2013-10-11 09:51:09 -0700 | [diff] [blame] | 1672 | &awbState, frameNumber)) { |
| 1673 | return false; |
| 1674 | } |
| 1675 | |
Jianing Wei | cb0652e | 2014-03-12 18:29:36 -0700 | [diff] [blame] | 1676 | if (!insert3AResult(min3AResult.mMetadata, ANDROID_CONTROL_AF_TRIGGER_ID, |
Yin-Chia Yeh | 741ace8 | 2014-06-23 14:07:56 -0700 | [diff] [blame] | 1677 | &resultExtras.afTriggerId, frameNumber)) { |
Eino-Ville Talvala | fd6ecdd | 2013-10-11 09:51:09 -0700 | [diff] [blame] | 1678 | return false; |
| 1679 | } |
| 1680 | |
Jianing Wei | cb0652e | 2014-03-12 18:29:36 -0700 | [diff] [blame] | 1681 | if (!insert3AResult(min3AResult.mMetadata, ANDROID_CONTROL_AE_PRECAPTURE_ID, |
Yin-Chia Yeh | 741ace8 | 2014-06-23 14:07:56 -0700 | [diff] [blame] | 1682 | &resultExtras.precaptureTriggerId, frameNumber)) { |
Eino-Ville Talvala | fd6ecdd | 2013-10-11 09:51:09 -0700 | [diff] [blame] | 1683 | return false; |
| 1684 | } |
| 1685 | |
Zhijun He | 204e329 | 2014-07-14 17:09:23 -0700 | [diff] [blame] | 1686 | // We only send the aggregated partial when all 3A related metadata are available |
| 1687 | // For both API1 and API2. |
| 1688 | // TODO: we probably should pass through all partials to API2 unconditionally. |
Eino-Ville Talvala | fd6ecdd | 2013-10-11 09:51:09 -0700 | [diff] [blame] | 1689 | mResultSignal.signal(); |
| 1690 | |
| 1691 | return true; |
| 1692 | } |
| 1693 | |
| 1694 | template<typename T> |
| 1695 | bool Camera3Device::get3AResult(const CameraMetadata& result, int32_t tag, |
Jianing Wei | cb0652e | 2014-03-12 18:29:36 -0700 | [diff] [blame] | 1696 | T* value, uint32_t frameNumber) { |
Eino-Ville Talvala | fd6ecdd | 2013-10-11 09:51:09 -0700 | [diff] [blame] | 1697 | (void) frameNumber; |
| 1698 | |
| 1699 | camera_metadata_ro_entry_t entry; |
| 1700 | |
| 1701 | entry = result.find(tag); |
| 1702 | if (entry.count == 0) { |
| 1703 | ALOGVV("%s: Camera %d: Frame %d: No %s provided by HAL!", __FUNCTION__, |
| 1704 | mId, frameNumber, get_camera_metadata_tag_name(tag)); |
| 1705 | return false; |
| 1706 | } |
| 1707 | |
| 1708 | if (sizeof(T) == sizeof(uint8_t)) { |
| 1709 | *value = entry.data.u8[0]; |
| 1710 | } else if (sizeof(T) == sizeof(int32_t)) { |
| 1711 | *value = entry.data.i32[0]; |
| 1712 | } else { |
| 1713 | ALOGE("%s: Unexpected type", __FUNCTION__); |
| 1714 | return false; |
| 1715 | } |
| 1716 | return true; |
| 1717 | } |
| 1718 | |
| 1719 | template<typename T> |
| 1720 | bool Camera3Device::insert3AResult(CameraMetadata& result, int32_t tag, |
Jianing Wei | cb0652e | 2014-03-12 18:29:36 -0700 | [diff] [blame] | 1721 | const T* value, uint32_t frameNumber) { |
Eino-Ville Talvala | fd6ecdd | 2013-10-11 09:51:09 -0700 | [diff] [blame] | 1722 | if (result.update(tag, value, 1) != NO_ERROR) { |
| 1723 | mResultQueue.erase(--mResultQueue.end(), mResultQueue.end()); |
| 1724 | SET_ERR("Frame %d: Failed to set %s in partial metadata", |
| 1725 | frameNumber, get_camera_metadata_tag_name(tag)); |
| 1726 | return false; |
| 1727 | } |
| 1728 | return true; |
| 1729 | } |
| 1730 | |
| 1731 | /** |
Eino-Ville Talvala | f76e027 | 2013-02-27 18:02:26 -0800 | [diff] [blame] | 1732 | * Camera HAL device callback methods |
| 1733 | */ |
| 1734 | |
Eino-Ville Talvala | 7fa43f3 | 2013-02-06 17:20:07 -0800 | [diff] [blame] | 1735 | void Camera3Device::processCaptureResult(const camera3_capture_result *result) { |
Eino-Ville Talvala | 7d346fa | 2013-03-11 14:13:50 -0700 | [diff] [blame] | 1736 | ATRACE_CALL(); |
Eino-Ville Talvala | 7fa43f3 | 2013-02-06 17:20:07 -0800 | [diff] [blame] | 1737 | |
Eino-Ville Talvala | 7d346fa | 2013-03-11 14:13:50 -0700 | [diff] [blame] | 1738 | status_t res; |
| 1739 | |
Eino-Ville Talvala | 42368d9 | 2013-04-09 14:13:50 -0700 | [diff] [blame] | 1740 | uint32_t frameNumber = result->frame_number; |
Zhijun He | f0d962a | 2014-06-30 10:24:11 -0700 | [diff] [blame] | 1741 | if (result->result == NULL && result->num_output_buffers == 0 && |
| 1742 | result->input_buffer == NULL) { |
Eino-Ville Talvala | 42368d9 | 2013-04-09 14:13:50 -0700 | [diff] [blame] | 1743 | SET_ERR("No result data provided by HAL for frame %d", |
| 1744 | frameNumber); |
Eino-Ville Talvala | 7d346fa | 2013-03-11 14:13:50 -0700 | [diff] [blame] | 1745 | return; |
| 1746 | } |
Zhijun He | 204e329 | 2014-07-14 17:09:23 -0700 | [diff] [blame] | 1747 | |
| 1748 | // For HAL3.2 or above, If HAL doesn't support partial, it must always set |
| 1749 | // partial_result to 1 when metadata is included in this result. |
| 1750 | if (!mUsePartialResult && |
| 1751 | mDeviceVersion >= CAMERA_DEVICE_API_VERSION_3_2 && |
| 1752 | result->result != NULL && |
| 1753 | result->partial_result != 1) { |
| 1754 | SET_ERR("Result is malformed for frame %d: partial_result %u must be 1" |
| 1755 | " if partial result is not supported", |
| 1756 | frameNumber, result->partial_result); |
| 1757 | return; |
| 1758 | } |
| 1759 | |
| 1760 | bool isPartialResult = false; |
| 1761 | CameraMetadata collectedPartialResult; |
Jianing Wei | cb0652e | 2014-03-12 18:29:36 -0700 | [diff] [blame] | 1762 | CaptureResultExtras resultExtras; |
Zhijun He | c98bd8d | 2014-07-07 12:44:10 -0700 | [diff] [blame] | 1763 | bool hasInputBufferInRequest = false; |
Eino-Ville Talvala | 7d346fa | 2013-03-11 14:13:50 -0700 | [diff] [blame] | 1764 | |
Jianing Wei | cb0652e | 2014-03-12 18:29:36 -0700 | [diff] [blame] | 1765 | // Get capture timestamp and resultExtras from list of in-flight requests, |
| 1766 | // where it was added by the shutter notification for this frame. |
| 1767 | // Then update the in-flight status and remove the in-flight entry if |
| 1768 | // all result data has been received. |
Eino-Ville Talvala | 7d346fa | 2013-03-11 14:13:50 -0700 | [diff] [blame] | 1769 | nsecs_t timestamp = 0; |
Eino-Ville Talvala | 42368d9 | 2013-04-09 14:13:50 -0700 | [diff] [blame] | 1770 | { |
| 1771 | Mutex::Autolock l(mInFlightLock); |
| 1772 | ssize_t idx = mInFlightMap.indexOfKey(frameNumber); |
| 1773 | if (idx == NAME_NOT_FOUND) { |
| 1774 | SET_ERR("Unknown frame number for capture result: %d", |
| 1775 | frameNumber); |
| 1776 | return; |
| 1777 | } |
| 1778 | InFlightRequest &request = mInFlightMap.editValueAt(idx); |
Jianing Wei | cb0652e | 2014-03-12 18:29:36 -0700 | [diff] [blame] | 1779 | ALOGVV("%s: got InFlightRequest requestId = %" PRId32 ", frameNumber = %" PRId64 |
| 1780 | ", burstId = %" PRId32, |
| 1781 | __FUNCTION__, request.resultExtras.requestId, request.resultExtras.frameNumber, |
| 1782 | request.resultExtras.burstId); |
Zhijun He | 204e329 | 2014-07-14 17:09:23 -0700 | [diff] [blame] | 1783 | // Always update the partial count to the latest one. When framework aggregates adjacent |
| 1784 | // partial results into one, the latest partial count will be used. |
| 1785 | request.resultExtras.partialResultCount = result->partial_result; |
Eino-Ville Talvala | fd6ecdd | 2013-10-11 09:51:09 -0700 | [diff] [blame] | 1786 | |
| 1787 | // Check if this result carries only partial metadata |
Zhijun He | 204e329 | 2014-07-14 17:09:23 -0700 | [diff] [blame] | 1788 | if (mUsePartialResult && result->result != NULL) { |
| 1789 | if (mDeviceVersion >= CAMERA_DEVICE_API_VERSION_3_2) { |
| 1790 | if (result->partial_result > mNumPartialResults || result->partial_result < 1) { |
| 1791 | SET_ERR("Result is malformed for frame %d: partial_result %u must be in" |
| 1792 | " the range of [1, %d] when metadata is included in the result", |
| 1793 | frameNumber, result->partial_result, mNumPartialResults); |
| 1794 | return; |
| 1795 | } |
| 1796 | isPartialResult = (result->partial_result < mNumPartialResults); |
Zhijun He | 5d76e1a | 2014-07-22 16:08:13 -0700 | [diff] [blame^] | 1797 | if (isPartialResult) { |
| 1798 | request.partialResult.collectedResult.append(result->result); |
| 1799 | } |
Zhijun He | 204e329 | 2014-07-14 17:09:23 -0700 | [diff] [blame] | 1800 | } else { |
| 1801 | camera_metadata_ro_entry_t partialResultEntry; |
| 1802 | res = find_camera_metadata_ro_entry(result->result, |
| 1803 | ANDROID_QUIRKS_PARTIAL_RESULT, &partialResultEntry); |
| 1804 | if (res != NAME_NOT_FOUND && |
| 1805 | partialResultEntry.count > 0 && |
| 1806 | partialResultEntry.data.u8[0] == |
| 1807 | ANDROID_QUIRKS_PARTIAL_RESULT_PARTIAL) { |
| 1808 | // A partial result. Flag this as such, and collect this |
| 1809 | // set of metadata into the in-flight entry. |
| 1810 | isPartialResult = true; |
| 1811 | request.partialResult.collectedResult.append( |
| 1812 | result->result); |
| 1813 | request.partialResult.collectedResult.erase( |
| 1814 | ANDROID_QUIRKS_PARTIAL_RESULT); |
| 1815 | } |
| 1816 | } |
| 1817 | |
| 1818 | if (isPartialResult) { |
Eino-Ville Talvala | fd6ecdd | 2013-10-11 09:51:09 -0700 | [diff] [blame] | 1819 | // Fire off a 3A-only result if possible |
Zhijun He | 204e329 | 2014-07-14 17:09:23 -0700 | [diff] [blame] | 1820 | if (!request.partialResult.haveSent3A) { |
| 1821 | request.partialResult.haveSent3A = |
| 1822 | processPartial3AResult(frameNumber, |
| 1823 | request.partialResult.collectedResult, |
Jianing Wei | cb0652e | 2014-03-12 18:29:36 -0700 | [diff] [blame] | 1824 | request.resultExtras); |
Eino-Ville Talvala | fd6ecdd | 2013-10-11 09:51:09 -0700 | [diff] [blame] | 1825 | } |
| 1826 | } |
| 1827 | } |
| 1828 | |
Eino-Ville Talvala | 42368d9 | 2013-04-09 14:13:50 -0700 | [diff] [blame] | 1829 | timestamp = request.captureTimestamp; |
Jianing Wei | cb0652e | 2014-03-12 18:29:36 -0700 | [diff] [blame] | 1830 | resultExtras = request.resultExtras; |
Zhijun He | c98bd8d | 2014-07-07 12:44:10 -0700 | [diff] [blame] | 1831 | hasInputBufferInRequest = request.hasInputBuffer; |
Jianing Wei | cb0652e | 2014-03-12 18:29:36 -0700 | [diff] [blame] | 1832 | |
Zhijun He | 1d1f846 | 2013-10-02 16:29:51 -0700 | [diff] [blame] | 1833 | /** |
Eino-Ville Talvala | fd6ecdd | 2013-10-11 09:51:09 -0700 | [diff] [blame] | 1834 | * One of the following must happen before it's legal to call process_capture_result, |
| 1835 | * unless partial metadata is being provided: |
Zhijun He | 1d1f846 | 2013-10-02 16:29:51 -0700 | [diff] [blame] | 1836 | * - CAMERA3_MSG_SHUTTER (expected during normal operation) |
| 1837 | * - CAMERA3_MSG_ERROR (expected during flush) |
| 1838 | */ |
Zhijun He | 204e329 | 2014-07-14 17:09:23 -0700 | [diff] [blame] | 1839 | if (request.requestStatus == OK && timestamp == 0 && !isPartialResult) { |
Eino-Ville Talvala | 42368d9 | 2013-04-09 14:13:50 -0700 | [diff] [blame] | 1840 | SET_ERR("Called before shutter notify for frame %d", |
| 1841 | frameNumber); |
| 1842 | return; |
| 1843 | } |
| 1844 | |
Eino-Ville Talvala | fd6ecdd | 2013-10-11 09:51:09 -0700 | [diff] [blame] | 1845 | // Did we get the (final) result metadata for this capture? |
Zhijun He | 204e329 | 2014-07-14 17:09:23 -0700 | [diff] [blame] | 1846 | if (result->result != NULL && !isPartialResult) { |
Eino-Ville Talvala | 42368d9 | 2013-04-09 14:13:50 -0700 | [diff] [blame] | 1847 | if (request.haveResultMetadata) { |
| 1848 | SET_ERR("Called multiple times with metadata for frame %d", |
| 1849 | frameNumber); |
| 1850 | return; |
| 1851 | } |
Zhijun He | 204e329 | 2014-07-14 17:09:23 -0700 | [diff] [blame] | 1852 | if (mUsePartialResult && |
| 1853 | !request.partialResult.collectedResult.isEmpty()) { |
| 1854 | collectedPartialResult.acquire( |
| 1855 | request.partialResult.collectedResult); |
Eino-Ville Talvala | fd6ecdd | 2013-10-11 09:51:09 -0700 | [diff] [blame] | 1856 | } |
Eino-Ville Talvala | 42368d9 | 2013-04-09 14:13:50 -0700 | [diff] [blame] | 1857 | request.haveResultMetadata = true; |
| 1858 | } |
| 1859 | |
Zhijun He | c98bd8d | 2014-07-07 12:44:10 -0700 | [diff] [blame] | 1860 | uint32_t numBuffersReturned = result->num_output_buffers; |
| 1861 | if (result->input_buffer != NULL) { |
| 1862 | if (hasInputBufferInRequest) { |
| 1863 | numBuffersReturned += 1; |
| 1864 | } else { |
| 1865 | ALOGW("%s: Input buffer should be NULL if there is no input" |
| 1866 | " buffer sent in the request", |
| 1867 | __FUNCTION__); |
| 1868 | } |
| 1869 | } |
| 1870 | request.numBuffersLeft -= numBuffersReturned; |
Eino-Ville Talvala | 42368d9 | 2013-04-09 14:13:50 -0700 | [diff] [blame] | 1871 | if (request.numBuffersLeft < 0) { |
| 1872 | SET_ERR("Too many buffers returned for frame %d", |
| 1873 | frameNumber); |
| 1874 | return; |
| 1875 | } |
| 1876 | |
Zhijun He | 1b05dfc | 2013-11-21 12:57:51 -0800 | [diff] [blame] | 1877 | // Check if everything has arrived for this result (buffers and metadata), remove it from |
| 1878 | // InFlightMap if both arrived or HAL reports error for this request (i.e. during flush). |
| 1879 | if ((request.requestStatus != OK) || |
| 1880 | (request.haveResultMetadata && request.numBuffersLeft == 0)) { |
Eino-Ville Talvala | 17a61ad | 2013-06-03 16:53:32 -0700 | [diff] [blame] | 1881 | ATRACE_ASYNC_END("frame capture", frameNumber); |
Eino-Ville Talvala | 42368d9 | 2013-04-09 14:13:50 -0700 | [diff] [blame] | 1882 | mInFlightMap.removeItemsAt(idx, 1); |
| 1883 | } |
| 1884 | |
| 1885 | // Sanity check - if we have too many in-flight frames, something has |
| 1886 | // likely gone wrong |
| 1887 | if (mInFlightMap.size() > kInFlightWarnLimit) { |
Colin Cross | e5729fa | 2014-03-21 15:04:25 -0700 | [diff] [blame] | 1888 | CLOGE("In-flight list too large: %zu", mInFlightMap.size()); |
Eino-Ville Talvala | 42368d9 | 2013-04-09 14:13:50 -0700 | [diff] [blame] | 1889 | } |
| 1890 | |
| 1891 | } |
| 1892 | |
Eino-Ville Talvala | 42368d9 | 2013-04-09 14:13:50 -0700 | [diff] [blame] | 1893 | // Process the result metadata, if provided |
Eino-Ville Talvala | fd6ecdd | 2013-10-11 09:51:09 -0700 | [diff] [blame] | 1894 | bool gotResult = false; |
Zhijun He | 204e329 | 2014-07-14 17:09:23 -0700 | [diff] [blame] | 1895 | if (result->result != NULL && !isPartialResult) { |
Eino-Ville Talvala | 7d346fa | 2013-03-11 14:13:50 -0700 | [diff] [blame] | 1896 | Mutex::Autolock l(mOutputLock); |
| 1897 | |
Eino-Ville Talvala | fd6ecdd | 2013-10-11 09:51:09 -0700 | [diff] [blame] | 1898 | gotResult = true; |
| 1899 | |
Jianing Wei | 3c76fa3 | 2014-04-21 11:34:34 -0700 | [diff] [blame] | 1900 | // TODO: need to track errors for tighter bounds on expected frame number |
| 1901 | if (frameNumber < mNextResultFrameNumber) { |
Eino-Ville Talvala | 42368d9 | 2013-04-09 14:13:50 -0700 | [diff] [blame] | 1902 | SET_ERR("Out-of-order capture result metadata submitted! " |
| 1903 | "(got frame number %d, expecting %d)", |
| 1904 | frameNumber, mNextResultFrameNumber); |
| 1905 | return; |
| 1906 | } |
Jianing Wei | 3c76fa3 | 2014-04-21 11:34:34 -0700 | [diff] [blame] | 1907 | mNextResultFrameNumber = frameNumber + 1; |
Eino-Ville Talvala | 42368d9 | 2013-04-09 14:13:50 -0700 | [diff] [blame] | 1908 | |
Jianing Wei | cb0652e | 2014-03-12 18:29:36 -0700 | [diff] [blame] | 1909 | CaptureResult captureResult; |
| 1910 | captureResult.mResultExtras = resultExtras; |
| 1911 | captureResult.mMetadata = result->result; |
Eino-Ville Talvala | fd6ecdd | 2013-10-11 09:51:09 -0700 | [diff] [blame] | 1912 | |
Jianing Wei | cb0652e | 2014-03-12 18:29:36 -0700 | [diff] [blame] | 1913 | if (captureResult.mMetadata.update(ANDROID_REQUEST_FRAME_COUNT, |
| 1914 | (int32_t*)&frameNumber, 1) != OK) { |
Eino-Ville Talvala | b2058d1 | 2013-04-09 13:49:56 -0700 | [diff] [blame] | 1915 | SET_ERR("Failed to set frame# in metadata (%d)", |
Eino-Ville Talvala | 42368d9 | 2013-04-09 14:13:50 -0700 | [diff] [blame] | 1916 | frameNumber); |
Eino-Ville Talvala | fd6ecdd | 2013-10-11 09:51:09 -0700 | [diff] [blame] | 1917 | gotResult = false; |
Igor Murashkin | d2c9069 | 2013-04-02 12:32:32 -0700 | [diff] [blame] | 1918 | } else { |
| 1919 | ALOGVV("%s: Camera %d: Set frame# in metadata (%d)", |
Eino-Ville Talvala | 42368d9 | 2013-04-09 14:13:50 -0700 | [diff] [blame] | 1920 | __FUNCTION__, mId, frameNumber); |
Igor Murashkin | d2c9069 | 2013-04-02 12:32:32 -0700 | [diff] [blame] | 1921 | } |
Eino-Ville Talvala | 7d346fa | 2013-03-11 14:13:50 -0700 | [diff] [blame] | 1922 | |
Eino-Ville Talvala | fd6ecdd | 2013-10-11 09:51:09 -0700 | [diff] [blame] | 1923 | // Append any previous partials to form a complete result |
Zhijun He | 204e329 | 2014-07-14 17:09:23 -0700 | [diff] [blame] | 1924 | if (mUsePartialResult && !collectedPartialResult.isEmpty()) { |
| 1925 | captureResult.mMetadata.append(collectedPartialResult); |
Eino-Ville Talvala | fd6ecdd | 2013-10-11 09:51:09 -0700 | [diff] [blame] | 1926 | } |
| 1927 | |
Jianing Wei | cb0652e | 2014-03-12 18:29:36 -0700 | [diff] [blame] | 1928 | captureResult.mMetadata.sort(); |
Eino-Ville Talvala | fd6ecdd | 2013-10-11 09:51:09 -0700 | [diff] [blame] | 1929 | |
Eino-Ville Talvala | 42368d9 | 2013-04-09 14:13:50 -0700 | [diff] [blame] | 1930 | // Check that there's a timestamp in the result metadata |
Eino-Ville Talvala | 7d346fa | 2013-03-11 14:13:50 -0700 | [diff] [blame] | 1931 | |
| 1932 | camera_metadata_entry entry = |
Jianing Wei | cb0652e | 2014-03-12 18:29:36 -0700 | [diff] [blame] | 1933 | captureResult.mMetadata.find(ANDROID_SENSOR_TIMESTAMP); |
Eino-Ville Talvala | 7d346fa | 2013-03-11 14:13:50 -0700 | [diff] [blame] | 1934 | if (entry.count == 0) { |
Eino-Ville Talvala | b2058d1 | 2013-04-09 13:49:56 -0700 | [diff] [blame] | 1935 | SET_ERR("No timestamp provided by HAL for frame %d!", |
Eino-Ville Talvala | 42368d9 | 2013-04-09 14:13:50 -0700 | [diff] [blame] | 1936 | frameNumber); |
Eino-Ville Talvala | fd6ecdd | 2013-10-11 09:51:09 -0700 | [diff] [blame] | 1937 | gotResult = false; |
Alex Ray | fe7e0c6 | 2013-05-30 00:12:13 -0700 | [diff] [blame] | 1938 | } else if (timestamp != entry.data.i64[0]) { |
Eino-Ville Talvala | 42368d9 | 2013-04-09 14:13:50 -0700 | [diff] [blame] | 1939 | SET_ERR("Timestamp mismatch between shutter notify and result" |
Colin Cross | e5729fa | 2014-03-21 15:04:25 -0700 | [diff] [blame] | 1940 | " metadata for frame %d (%" PRId64 " vs %" PRId64 " respectively)", |
Eino-Ville Talvala | 42368d9 | 2013-04-09 14:13:50 -0700 | [diff] [blame] | 1941 | frameNumber, timestamp, entry.data.i64[0]); |
Eino-Ville Talvala | fd6ecdd | 2013-10-11 09:51:09 -0700 | [diff] [blame] | 1942 | gotResult = false; |
| 1943 | } |
| 1944 | |
| 1945 | if (gotResult) { |
| 1946 | // Valid result, insert into queue |
Jianing Wei | cb0652e | 2014-03-12 18:29:36 -0700 | [diff] [blame] | 1947 | List<CaptureResult>::iterator queuedResult = |
| 1948 | mResultQueue.insert(mResultQueue.end(), CaptureResult(captureResult)); |
| 1949 | ALOGVV("%s: result requestId = %" PRId32 ", frameNumber = %" PRId64 |
| 1950 | ", burstId = %" PRId32, __FUNCTION__, |
| 1951 | queuedResult->mResultExtras.requestId, |
| 1952 | queuedResult->mResultExtras.frameNumber, |
| 1953 | queuedResult->mResultExtras.burstId); |
Eino-Ville Talvala | 7d346fa | 2013-03-11 14:13:50 -0700 | [diff] [blame] | 1954 | } |
Eino-Ville Talvala | 7d346fa | 2013-03-11 14:13:50 -0700 | [diff] [blame] | 1955 | } // scope for mOutputLock |
| 1956 | |
Eino-Ville Talvala | 42368d9 | 2013-04-09 14:13:50 -0700 | [diff] [blame] | 1957 | // Return completed buffers to their streams with the timestamp |
| 1958 | |
Eino-Ville Talvala | 7d346fa | 2013-03-11 14:13:50 -0700 | [diff] [blame] | 1959 | for (size_t i = 0; i < result->num_output_buffers; i++) { |
| 1960 | Camera3Stream *stream = |
| 1961 | Camera3Stream::cast(result->output_buffers[i].stream); |
| 1962 | res = stream->returnBuffer(result->output_buffers[i], timestamp); |
| 1963 | // Note: stream may be deallocated at this point, if this buffer was the |
| 1964 | // last reference to it. |
| 1965 | if (res != OK) { |
Colin Cross | e5729fa | 2014-03-21 15:04:25 -0700 | [diff] [blame] | 1966 | ALOGE("Can't return buffer %zu for frame %d to its stream: " |
Eino-Ville Talvala | 42368d9 | 2013-04-09 14:13:50 -0700 | [diff] [blame] | 1967 | " %s (%d)", i, frameNumber, strerror(-res), res); |
Eino-Ville Talvala | 7d346fa | 2013-03-11 14:13:50 -0700 | [diff] [blame] | 1968 | } |
| 1969 | } |
| 1970 | |
Zhijun He | f0d962a | 2014-06-30 10:24:11 -0700 | [diff] [blame] | 1971 | if (result->input_buffer != NULL) { |
Zhijun He | c98bd8d | 2014-07-07 12:44:10 -0700 | [diff] [blame] | 1972 | if (hasInputBufferInRequest) { |
| 1973 | Camera3Stream *stream = |
| 1974 | Camera3Stream::cast(result->input_buffer->stream); |
| 1975 | res = stream->returnInputBuffer(*(result->input_buffer)); |
| 1976 | // Note: stream may be deallocated at this point, if this buffer was the |
| 1977 | // last reference to it. |
| 1978 | if (res != OK) { |
| 1979 | ALOGE("%s: RequestThread: Can't return input buffer for frame %d to" |
| 1980 | " its stream:%s (%d)", __FUNCTION__, |
| 1981 | frameNumber, strerror(-res), res); |
Zhijun He | 0ea8fa4 | 2014-07-07 17:05:38 -0700 | [diff] [blame] | 1982 | } |
| 1983 | } else { |
| 1984 | ALOGW("%s: Input buffer should be NULL if there is no input" |
| 1985 | " buffer sent in the request, skipping input buffer return.", |
| 1986 | __FUNCTION__); |
Zhijun He | f0d962a | 2014-06-30 10:24:11 -0700 | [diff] [blame] | 1987 | } |
| 1988 | } |
| 1989 | |
Eino-Ville Talvala | 46910bd | 2013-07-18 19:15:17 -0700 | [diff] [blame] | 1990 | // Finally, signal any waiters for new frames |
Eino-Ville Talvala | 42368d9 | 2013-04-09 14:13:50 -0700 | [diff] [blame] | 1991 | |
Eino-Ville Talvala | fd6ecdd | 2013-10-11 09:51:09 -0700 | [diff] [blame] | 1992 | if (gotResult) { |
Igor Murashkin | 4345d5b | 2013-05-17 14:39:53 -0700 | [diff] [blame] | 1993 | mResultSignal.signal(); |
| 1994 | } |
| 1995 | |
Eino-Ville Talvala | 7fa43f3 | 2013-02-06 17:20:07 -0800 | [diff] [blame] | 1996 | } |
| 1997 | |
| 1998 | void Camera3Device::notify(const camera3_notify_msg *msg) { |
Eino-Ville Talvala | 17a61ad | 2013-06-03 16:53:32 -0700 | [diff] [blame] | 1999 | ATRACE_CALL(); |
Eino-Ville Talvala | 7d346fa | 2013-03-11 14:13:50 -0700 | [diff] [blame] | 2000 | NotificationListener *listener; |
| 2001 | { |
| 2002 | Mutex::Autolock l(mOutputLock); |
Eino-Ville Talvala | 7d346fa | 2013-03-11 14:13:50 -0700 | [diff] [blame] | 2003 | listener = mListener; |
| 2004 | } |
Eino-Ville Talvala | 7fa43f3 | 2013-02-06 17:20:07 -0800 | [diff] [blame] | 2005 | |
Eino-Ville Talvala | 7d346fa | 2013-03-11 14:13:50 -0700 | [diff] [blame] | 2006 | if (msg == NULL) { |
Eino-Ville Talvala | 42368d9 | 2013-04-09 14:13:50 -0700 | [diff] [blame] | 2007 | SET_ERR("HAL sent NULL notify message!"); |
Eino-Ville Talvala | 7d346fa | 2013-03-11 14:13:50 -0700 | [diff] [blame] | 2008 | return; |
| 2009 | } |
| 2010 | |
| 2011 | switch (msg->type) { |
| 2012 | case CAMERA3_MSG_ERROR: { |
| 2013 | int streamId = 0; |
| 2014 | if (msg->message.error.error_stream != NULL) { |
| 2015 | Camera3Stream *stream = |
| 2016 | Camera3Stream::cast( |
| 2017 | msg->message.error.error_stream); |
| 2018 | streamId = stream->getId(); |
| 2019 | } |
Eino-Ville Talvala | 17a61ad | 2013-06-03 16:53:32 -0700 | [diff] [blame] | 2020 | ALOGV("Camera %d: %s: HAL error, frame %d, stream %d: %d", |
| 2021 | mId, __FUNCTION__, msg->message.error.frame_number, |
| 2022 | streamId, msg->message.error.error_code); |
Zhijun He | 1d1f846 | 2013-10-02 16:29:51 -0700 | [diff] [blame] | 2023 | |
Jianing Wei | cb0652e | 2014-03-12 18:29:36 -0700 | [diff] [blame] | 2024 | CaptureResultExtras resultExtras; |
Zhijun He | 1d1f846 | 2013-10-02 16:29:51 -0700 | [diff] [blame] | 2025 | // Set request error status for the request in the in-flight tracking |
| 2026 | { |
| 2027 | Mutex::Autolock l(mInFlightLock); |
| 2028 | ssize_t idx = mInFlightMap.indexOfKey(msg->message.error.frame_number); |
| 2029 | if (idx >= 0) { |
Jianing Wei | cb0652e | 2014-03-12 18:29:36 -0700 | [diff] [blame] | 2030 | InFlightRequest &r = mInFlightMap.editValueAt(idx); |
| 2031 | r.requestStatus = msg->message.error.error_code; |
| 2032 | resultExtras = r.resultExtras; |
| 2033 | } else { |
| 2034 | resultExtras.frameNumber = msg->message.error.frame_number; |
| 2035 | ALOGE("Camera %d: %s: cannot find in-flight request on frame %" PRId64 |
| 2036 | " error", mId, __FUNCTION__, resultExtras.frameNumber); |
Zhijun He | 1d1f846 | 2013-10-02 16:29:51 -0700 | [diff] [blame] | 2037 | } |
| 2038 | } |
| 2039 | |
Eino-Ville Talvala | 42368d9 | 2013-04-09 14:13:50 -0700 | [diff] [blame] | 2040 | if (listener != NULL) { |
Jianing Wei | cb0652e | 2014-03-12 18:29:36 -0700 | [diff] [blame] | 2041 | if (msg->message.error.error_code == CAMERA3_MSG_ERROR_DEVICE) { |
| 2042 | listener->notifyError(ICameraDeviceCallbacks::ERROR_CAMERA_DEVICE, |
| 2043 | resultExtras); |
Jianing Wei | cb0652e | 2014-03-12 18:29:36 -0700 | [diff] [blame] | 2044 | } |
| 2045 | } else { |
| 2046 | ALOGE("Camera %d: %s: no listener available", mId, __FUNCTION__); |
Eino-Ville Talvala | 42368d9 | 2013-04-09 14:13:50 -0700 | [diff] [blame] | 2047 | } |
Eino-Ville Talvala | 7d346fa | 2013-03-11 14:13:50 -0700 | [diff] [blame] | 2048 | break; |
| 2049 | } |
| 2050 | case CAMERA3_MSG_SHUTTER: { |
Eino-Ville Talvala | 42368d9 | 2013-04-09 14:13:50 -0700 | [diff] [blame] | 2051 | ssize_t idx; |
| 2052 | uint32_t frameNumber = msg->message.shutter.frame_number; |
| 2053 | nsecs_t timestamp = msg->message.shutter.timestamp; |
| 2054 | // Verify ordering of shutter notifications |
| 2055 | { |
| 2056 | Mutex::Autolock l(mOutputLock); |
Jianing Wei | 3c76fa3 | 2014-04-21 11:34:34 -0700 | [diff] [blame] | 2057 | // TODO: need to track errors for tighter bounds on expected frame number. |
| 2058 | if (frameNumber < mNextShutterFrameNumber) { |
Eino-Ville Talvala | 42368d9 | 2013-04-09 14:13:50 -0700 | [diff] [blame] | 2059 | SET_ERR("Shutter notification out-of-order. Expected " |
| 2060 | "notification for frame %d, got frame %d", |
| 2061 | mNextShutterFrameNumber, frameNumber); |
| 2062 | break; |
| 2063 | } |
Jianing Wei | 3c76fa3 | 2014-04-21 11:34:34 -0700 | [diff] [blame] | 2064 | mNextShutterFrameNumber = frameNumber + 1; |
Eino-Ville Talvala | 42368d9 | 2013-04-09 14:13:50 -0700 | [diff] [blame] | 2065 | } |
| 2066 | |
Jianing Wei | cb0652e | 2014-03-12 18:29:36 -0700 | [diff] [blame] | 2067 | CaptureResultExtras resultExtras; |
Eino-Ville Talvala | f1e98d8 | 2013-09-06 09:32:43 -0700 | [diff] [blame] | 2068 | |
Eino-Ville Talvala | 42368d9 | 2013-04-09 14:13:50 -0700 | [diff] [blame] | 2069 | // Set timestamp for the request in the in-flight tracking |
Eino-Ville Talvala | f1e98d8 | 2013-09-06 09:32:43 -0700 | [diff] [blame] | 2070 | // and get the request ID to send upstream |
Eino-Ville Talvala | 42368d9 | 2013-04-09 14:13:50 -0700 | [diff] [blame] | 2071 | { |
| 2072 | Mutex::Autolock l(mInFlightLock); |
| 2073 | idx = mInFlightMap.indexOfKey(frameNumber); |
| 2074 | if (idx >= 0) { |
Eino-Ville Talvala | f1e98d8 | 2013-09-06 09:32:43 -0700 | [diff] [blame] | 2075 | InFlightRequest &r = mInFlightMap.editValueAt(idx); |
| 2076 | r.captureTimestamp = timestamp; |
Jianing Wei | cb0652e | 2014-03-12 18:29:36 -0700 | [diff] [blame] | 2077 | resultExtras = r.resultExtras; |
Eino-Ville Talvala | 42368d9 | 2013-04-09 14:13:50 -0700 | [diff] [blame] | 2078 | } |
| 2079 | } |
| 2080 | if (idx < 0) { |
| 2081 | SET_ERR("Shutter notification for non-existent frame number %d", |
| 2082 | frameNumber); |
| 2083 | break; |
| 2084 | } |
Colin Cross | e5729fa | 2014-03-21 15:04:25 -0700 | [diff] [blame] | 2085 | ALOGVV("Camera %d: %s: Shutter fired for frame %d (id %d) at %" PRId64, |
Jianing Wei | cb0652e | 2014-03-12 18:29:36 -0700 | [diff] [blame] | 2086 | mId, __FUNCTION__, frameNumber, resultExtras.requestId, timestamp); |
Eino-Ville Talvala | 42368d9 | 2013-04-09 14:13:50 -0700 | [diff] [blame] | 2087 | // Call listener, if any |
| 2088 | if (listener != NULL) { |
Jianing Wei | cb0652e | 2014-03-12 18:29:36 -0700 | [diff] [blame] | 2089 | listener->notifyShutter(resultExtras, timestamp); |
Eino-Ville Talvala | 42368d9 | 2013-04-09 14:13:50 -0700 | [diff] [blame] | 2090 | } |
Eino-Ville Talvala | 7d346fa | 2013-03-11 14:13:50 -0700 | [diff] [blame] | 2091 | break; |
| 2092 | } |
| 2093 | default: |
Eino-Ville Talvala | 42368d9 | 2013-04-09 14:13:50 -0700 | [diff] [blame] | 2094 | SET_ERR("Unknown notify message from HAL: %d", |
Eino-Ville Talvala | b2058d1 | 2013-04-09 13:49:56 -0700 | [diff] [blame] | 2095 | msg->type); |
Eino-Ville Talvala | 7d346fa | 2013-03-11 14:13:50 -0700 | [diff] [blame] | 2096 | } |
Eino-Ville Talvala | 7fa43f3 | 2013-02-06 17:20:07 -0800 | [diff] [blame] | 2097 | } |
| 2098 | |
Eino-Ville Talvala | f1e98d8 | 2013-09-06 09:32:43 -0700 | [diff] [blame] | 2099 | CameraMetadata Camera3Device::getLatestRequestLocked() { |
Igor Murashkin | 1e479c0 | 2013-09-06 16:55:14 -0700 | [diff] [blame] | 2100 | ALOGV("%s", __FUNCTION__); |
| 2101 | |
Igor Murashkin | 1e479c0 | 2013-09-06 16:55:14 -0700 | [diff] [blame] | 2102 | CameraMetadata retVal; |
| 2103 | |
| 2104 | if (mRequestThread != NULL) { |
| 2105 | retVal = mRequestThread->getLatestRequest(); |
| 2106 | } |
| 2107 | |
Igor Murashkin | 1e479c0 | 2013-09-06 16:55:14 -0700 | [diff] [blame] | 2108 | return retVal; |
| 2109 | } |
| 2110 | |
Jianing Wei | cb0652e | 2014-03-12 18:29:36 -0700 | [diff] [blame] | 2111 | |
Eino-Ville Talvala | 7fa43f3 | 2013-02-06 17:20:07 -0800 | [diff] [blame] | 2112 | /** |
Eino-Ville Talvala | f76e027 | 2013-02-27 18:02:26 -0800 | [diff] [blame] | 2113 | * RequestThread inner class methods |
| 2114 | */ |
| 2115 | |
| 2116 | Camera3Device::RequestThread::RequestThread(wp<Camera3Device> parent, |
Eino-Ville Talvala | f1e98d8 | 2013-09-06 09:32:43 -0700 | [diff] [blame] | 2117 | sp<StatusTracker> statusTracker, |
Eino-Ville Talvala | f76e027 | 2013-02-27 18:02:26 -0800 | [diff] [blame] | 2118 | camera3_device_t *hal3Device) : |
| 2119 | Thread(false), |
| 2120 | mParent(parent), |
Eino-Ville Talvala | f1e98d8 | 2013-09-06 09:32:43 -0700 | [diff] [blame] | 2121 | mStatusTracker(statusTracker), |
Eino-Ville Talvala | f76e027 | 2013-02-27 18:02:26 -0800 | [diff] [blame] | 2122 | mHal3Device(hal3Device), |
Eino-Ville Talvala | 42368d9 | 2013-04-09 14:13:50 -0700 | [diff] [blame] | 2123 | mId(getId(parent)), |
Eino-Ville Talvala | f76e027 | 2013-02-27 18:02:26 -0800 | [diff] [blame] | 2124 | mReconfigured(false), |
| 2125 | mDoPause(false), |
| 2126 | mPaused(true), |
Igor Murashkin | 4d2f2e8 | 2013-04-01 17:29:07 -0700 | [diff] [blame] | 2127 | mFrameNumber(0), |
Jianing Wei | cb0652e | 2014-03-12 18:29:36 -0700 | [diff] [blame] | 2128 | mLatestRequestId(NAME_NOT_FOUND), |
Jianing Wei | 2d6bb3f | 2014-04-11 10:00:31 -0700 | [diff] [blame] | 2129 | mRepeatingLastFrameNumber(NO_IN_FLIGHT_REPEATING_FRAMES) { |
Eino-Ville Talvala | f1e98d8 | 2013-09-06 09:32:43 -0700 | [diff] [blame] | 2130 | mStatusId = statusTracker->addComponent(); |
Eino-Ville Talvala | f76e027 | 2013-02-27 18:02:26 -0800 | [diff] [blame] | 2131 | } |
| 2132 | |
| 2133 | void Camera3Device::RequestThread::configurationComplete() { |
| 2134 | Mutex::Autolock l(mRequestLock); |
| 2135 | mReconfigured = true; |
| 2136 | } |
| 2137 | |
Jianing Wei | 90e59c9 | 2014-03-12 18:29:36 -0700 | [diff] [blame] | 2138 | status_t Camera3Device::RequestThread::queueRequestList( |
Jianing Wei | 2d6bb3f | 2014-04-11 10:00:31 -0700 | [diff] [blame] | 2139 | List<sp<CaptureRequest> > &requests, |
| 2140 | /*out*/ |
| 2141 | int64_t *lastFrameNumber) { |
Jianing Wei | 90e59c9 | 2014-03-12 18:29:36 -0700 | [diff] [blame] | 2142 | Mutex::Autolock l(mRequestLock); |
| 2143 | for (List<sp<CaptureRequest> >::iterator it = requests.begin(); it != requests.end(); |
| 2144 | ++it) { |
| 2145 | mRequestQueue.push_back(*it); |
| 2146 | } |
| 2147 | |
Jianing Wei | 2d6bb3f | 2014-04-11 10:00:31 -0700 | [diff] [blame] | 2148 | if (lastFrameNumber != NULL) { |
| 2149 | *lastFrameNumber = mFrameNumber + mRequestQueue.size() - 1; |
| 2150 | ALOGV("%s: requestId %d, mFrameNumber %" PRId32 ", lastFrameNumber %" PRId64 ".", |
| 2151 | __FUNCTION__, (*(requests.begin()))->mResultExtras.requestId, mFrameNumber, |
| 2152 | *lastFrameNumber); |
| 2153 | } |
Jianing Wei | cb0652e | 2014-03-12 18:29:36 -0700 | [diff] [blame] | 2154 | |
Jianing Wei | 90e59c9 | 2014-03-12 18:29:36 -0700 | [diff] [blame] | 2155 | unpauseForNewRequests(); |
| 2156 | |
| 2157 | return OK; |
| 2158 | } |
| 2159 | |
Igor Murashkin | 4d2f2e8 | 2013-04-01 17:29:07 -0700 | [diff] [blame] | 2160 | |
| 2161 | status_t Camera3Device::RequestThread::queueTrigger( |
| 2162 | RequestTrigger trigger[], |
| 2163 | size_t count) { |
| 2164 | |
| 2165 | Mutex::Autolock l(mTriggerMutex); |
| 2166 | status_t ret; |
| 2167 | |
| 2168 | for (size_t i = 0; i < count; ++i) { |
| 2169 | ret = queueTriggerLocked(trigger[i]); |
| 2170 | |
| 2171 | if (ret != OK) { |
| 2172 | return ret; |
| 2173 | } |
| 2174 | } |
| 2175 | |
| 2176 | return OK; |
| 2177 | } |
| 2178 | |
Eino-Ville Talvala | 42368d9 | 2013-04-09 14:13:50 -0700 | [diff] [blame] | 2179 | int Camera3Device::RequestThread::getId(const wp<Camera3Device> &device) { |
| 2180 | sp<Camera3Device> d = device.promote(); |
| 2181 | if (d != NULL) return d->mId; |
| 2182 | return 0; |
| 2183 | } |
| 2184 | |
Igor Murashkin | 4d2f2e8 | 2013-04-01 17:29:07 -0700 | [diff] [blame] | 2185 | status_t Camera3Device::RequestThread::queueTriggerLocked( |
| 2186 | RequestTrigger trigger) { |
| 2187 | |
| 2188 | uint32_t tag = trigger.metadataTag; |
| 2189 | ssize_t index = mTriggerMap.indexOfKey(tag); |
| 2190 | |
| 2191 | switch (trigger.getTagType()) { |
| 2192 | case TYPE_BYTE: |
| 2193 | // fall-through |
| 2194 | case TYPE_INT32: |
| 2195 | break; |
| 2196 | default: |
Eino-Ville Talvala | 42368d9 | 2013-04-09 14:13:50 -0700 | [diff] [blame] | 2197 | ALOGE("%s: Type not supported: 0x%x", __FUNCTION__, |
| 2198 | trigger.getTagType()); |
Igor Murashkin | 4d2f2e8 | 2013-04-01 17:29:07 -0700 | [diff] [blame] | 2199 | return INVALID_OPERATION; |
| 2200 | } |
| 2201 | |
| 2202 | /** |
| 2203 | * Collect only the latest trigger, since we only have 1 field |
| 2204 | * in the request settings per trigger tag, and can't send more than 1 |
| 2205 | * trigger per request. |
| 2206 | */ |
| 2207 | if (index != NAME_NOT_FOUND) { |
| 2208 | mTriggerMap.editValueAt(index) = trigger; |
| 2209 | } else { |
| 2210 | mTriggerMap.add(tag, trigger); |
| 2211 | } |
| 2212 | |
| 2213 | return OK; |
| 2214 | } |
| 2215 | |
Eino-Ville Talvala | f76e027 | 2013-02-27 18:02:26 -0800 | [diff] [blame] | 2216 | status_t Camera3Device::RequestThread::setRepeatingRequests( |
Jianing Wei | 2d6bb3f | 2014-04-11 10:00:31 -0700 | [diff] [blame] | 2217 | const RequestList &requests, |
| 2218 | /*out*/ |
| 2219 | int64_t *lastFrameNumber) { |
Eino-Ville Talvala | f76e027 | 2013-02-27 18:02:26 -0800 | [diff] [blame] | 2220 | Mutex::Autolock l(mRequestLock); |
Jianing Wei | 2d6bb3f | 2014-04-11 10:00:31 -0700 | [diff] [blame] | 2221 | if (lastFrameNumber != NULL) { |
| 2222 | *lastFrameNumber = mRepeatingLastFrameNumber; |
| 2223 | } |
Eino-Ville Talvala | f76e027 | 2013-02-27 18:02:26 -0800 | [diff] [blame] | 2224 | mRepeatingRequests.clear(); |
| 2225 | mRepeatingRequests.insert(mRepeatingRequests.begin(), |
| 2226 | requests.begin(), requests.end()); |
Eino-Ville Talvala | 26fe6c7 | 2013-08-29 12:46:18 -0700 | [diff] [blame] | 2227 | |
| 2228 | unpauseForNewRequests(); |
| 2229 | |
Jianing Wei | 2d6bb3f | 2014-04-11 10:00:31 -0700 | [diff] [blame] | 2230 | mRepeatingLastFrameNumber = NO_IN_FLIGHT_REPEATING_FRAMES; |
Eino-Ville Talvala | f76e027 | 2013-02-27 18:02:26 -0800 | [diff] [blame] | 2231 | return OK; |
| 2232 | } |
| 2233 | |
Yin-Chia Yeh | 8684b7f | 2014-06-13 14:53:05 -0700 | [diff] [blame] | 2234 | bool Camera3Device::RequestThread::isRepeatingRequestLocked(const sp<CaptureRequest> requestIn) { |
| 2235 | if (mRepeatingRequests.empty()) { |
| 2236 | return false; |
| 2237 | } |
| 2238 | int32_t requestId = requestIn->mResultExtras.requestId; |
| 2239 | const RequestList &repeatRequests = mRepeatingRequests; |
| 2240 | // All repeating requests are guaranteed to have same id so only check first quest |
| 2241 | const sp<CaptureRequest> firstRequest = *repeatRequests.begin(); |
| 2242 | return (firstRequest->mResultExtras.requestId == requestId); |
| 2243 | } |
| 2244 | |
Jianing Wei | 2d6bb3f | 2014-04-11 10:00:31 -0700 | [diff] [blame] | 2245 | status_t Camera3Device::RequestThread::clearRepeatingRequests(/*out*/int64_t *lastFrameNumber) { |
Eino-Ville Talvala | f76e027 | 2013-02-27 18:02:26 -0800 | [diff] [blame] | 2246 | Mutex::Autolock l(mRequestLock); |
| 2247 | mRepeatingRequests.clear(); |
Jianing Wei | 2d6bb3f | 2014-04-11 10:00:31 -0700 | [diff] [blame] | 2248 | if (lastFrameNumber != NULL) { |
| 2249 | *lastFrameNumber = mRepeatingLastFrameNumber; |
| 2250 | } |
| 2251 | mRepeatingLastFrameNumber = NO_IN_FLIGHT_REPEATING_FRAMES; |
Eino-Ville Talvala | f76e027 | 2013-02-27 18:02:26 -0800 | [diff] [blame] | 2252 | return OK; |
| 2253 | } |
| 2254 | |
Jianing Wei | 2d6bb3f | 2014-04-11 10:00:31 -0700 | [diff] [blame] | 2255 | status_t Camera3Device::RequestThread::clear(/*out*/int64_t *lastFrameNumber) { |
Eino-Ville Talvala | abaa51d | 2013-08-14 11:37:00 -0700 | [diff] [blame] | 2256 | Mutex::Autolock l(mRequestLock); |
Jianing Wei | 2d6bb3f | 2014-04-11 10:00:31 -0700 | [diff] [blame] | 2257 | ALOGV("RequestThread::%s:", __FUNCTION__); |
Eino-Ville Talvala | abaa51d | 2013-08-14 11:37:00 -0700 | [diff] [blame] | 2258 | mRepeatingRequests.clear(); |
Yin-Chia Yeh | 8684b7f | 2014-06-13 14:53:05 -0700 | [diff] [blame] | 2259 | |
| 2260 | // Decrement repeating frame count for those requests never sent to device |
| 2261 | // TODO: Remove this after we have proper error handling so these requests |
| 2262 | // will generate an error callback. This might be the only place calling |
| 2263 | // isRepeatingRequestLocked. If so, isRepeatingRequestLocked should also be removed. |
| 2264 | const RequestList &requests = mRequestQueue; |
| 2265 | for (RequestList::const_iterator it = requests.begin(); |
| 2266 | it != requests.end(); ++it) { |
| 2267 | if (isRepeatingRequestLocked(*it)) { |
| 2268 | mRepeatingLastFrameNumber--; |
| 2269 | } |
| 2270 | } |
Eino-Ville Talvala | abaa51d | 2013-08-14 11:37:00 -0700 | [diff] [blame] | 2271 | mRequestQueue.clear(); |
| 2272 | mTriggerMap.clear(); |
Jianing Wei | 2d6bb3f | 2014-04-11 10:00:31 -0700 | [diff] [blame] | 2273 | if (lastFrameNumber != NULL) { |
| 2274 | *lastFrameNumber = mRepeatingLastFrameNumber; |
| 2275 | } |
| 2276 | mRepeatingLastFrameNumber = NO_IN_FLIGHT_REPEATING_FRAMES; |
Eino-Ville Talvala | abaa51d | 2013-08-14 11:37:00 -0700 | [diff] [blame] | 2277 | return OK; |
| 2278 | } |
| 2279 | |
Eino-Ville Talvala | f76e027 | 2013-02-27 18:02:26 -0800 | [diff] [blame] | 2280 | void Camera3Device::RequestThread::setPaused(bool paused) { |
| 2281 | Mutex::Autolock l(mPauseLock); |
| 2282 | mDoPause = paused; |
| 2283 | mDoPauseSignal.signal(); |
| 2284 | } |
| 2285 | |
Igor Murashkin | 4d2f2e8 | 2013-04-01 17:29:07 -0700 | [diff] [blame] | 2286 | status_t Camera3Device::RequestThread::waitUntilRequestProcessed( |
| 2287 | int32_t requestId, nsecs_t timeout) { |
| 2288 | Mutex::Autolock l(mLatestRequestMutex); |
| 2289 | status_t res; |
| 2290 | while (mLatestRequestId != requestId) { |
| 2291 | nsecs_t startTime = systemTime(); |
| 2292 | |
| 2293 | res = mLatestRequestSignal.waitRelative(mLatestRequestMutex, timeout); |
| 2294 | if (res != OK) return res; |
| 2295 | |
| 2296 | timeout -= (systemTime() - startTime); |
| 2297 | } |
| 2298 | |
| 2299 | return OK; |
| 2300 | } |
| 2301 | |
Eino-Ville Talvala | f1e98d8 | 2013-09-06 09:32:43 -0700 | [diff] [blame] | 2302 | void Camera3Device::RequestThread::requestExit() { |
| 2303 | // Call parent to set up shutdown |
| 2304 | Thread::requestExit(); |
| 2305 | // The exit from any possible waits |
| 2306 | mDoPauseSignal.signal(); |
| 2307 | mRequestSignal.signal(); |
| 2308 | } |
Igor Murashkin | 4d2f2e8 | 2013-04-01 17:29:07 -0700 | [diff] [blame] | 2309 | |
Eino-Ville Talvala | f76e027 | 2013-02-27 18:02:26 -0800 | [diff] [blame] | 2310 | bool Camera3Device::RequestThread::threadLoop() { |
| 2311 | |
| 2312 | status_t res; |
| 2313 | |
| 2314 | // Handle paused state. |
| 2315 | if (waitIfPaused()) { |
| 2316 | return true; |
| 2317 | } |
| 2318 | |
| 2319 | // Get work to do |
| 2320 | |
| 2321 | sp<CaptureRequest> nextRequest = waitForNextRequest(); |
| 2322 | if (nextRequest == NULL) { |
| 2323 | return true; |
| 2324 | } |
| 2325 | |
| 2326 | // Create request to HAL |
Eino-Ville Talvala | f76e027 | 2013-02-27 18:02:26 -0800 | [diff] [blame] | 2327 | camera3_capture_request_t request = camera3_capture_request_t(); |
Jianing Wei | 2d6bb3f | 2014-04-11 10:00:31 -0700 | [diff] [blame] | 2328 | request.frame_number = nextRequest->mResultExtras.frameNumber; |
Igor Murashkin | 4d2f2e8 | 2013-04-01 17:29:07 -0700 | [diff] [blame] | 2329 | Vector<camera3_stream_buffer_t> outputBuffers; |
Eino-Ville Talvala | f76e027 | 2013-02-27 18:02:26 -0800 | [diff] [blame] | 2330 | |
Eino-Ville Talvala | f1e98d8 | 2013-09-06 09:32:43 -0700 | [diff] [blame] | 2331 | // Get the request ID, if any |
| 2332 | int requestId; |
| 2333 | camera_metadata_entry_t requestIdEntry = |
| 2334 | nextRequest->mSettings.find(ANDROID_REQUEST_ID); |
| 2335 | if (requestIdEntry.count > 0) { |
| 2336 | requestId = requestIdEntry.data.i32[0]; |
| 2337 | } else { |
| 2338 | ALOGW("%s: Did not have android.request.id set in the request", |
| 2339 | __FUNCTION__); |
| 2340 | requestId = NAME_NOT_FOUND; |
| 2341 | } |
| 2342 | |
Igor Murashkin | 4d2f2e8 | 2013-04-01 17:29:07 -0700 | [diff] [blame] | 2343 | // Insert any queued triggers (before metadata is locked) |
| 2344 | int32_t triggerCount; |
| 2345 | res = insertTriggers(nextRequest); |
| 2346 | if (res < 0) { |
Eino-Ville Talvala | b2058d1 | 2013-04-09 13:49:56 -0700 | [diff] [blame] | 2347 | SET_ERR("RequestThread: Unable to insert triggers " |
| 2348 | "(capture request %d, HAL device: %s (%d)", |
Jianing Wei | 2d6bb3f | 2014-04-11 10:00:31 -0700 | [diff] [blame] | 2349 | request.frame_number, strerror(-res), res); |
Igor Murashkin | 4d2f2e8 | 2013-04-01 17:29:07 -0700 | [diff] [blame] | 2350 | cleanUpFailedRequest(request, nextRequest, outputBuffers); |
| 2351 | return false; |
| 2352 | } |
| 2353 | triggerCount = res; |
| 2354 | |
| 2355 | bool triggersMixedIn = (triggerCount > 0 || mPrevTriggers > 0); |
| 2356 | |
| 2357 | // If the request is the same as last, or we had triggers last time |
| 2358 | if (mPrevRequest != nextRequest || triggersMixedIn) { |
| 2359 | /** |
Eino-Ville Talvala | 2f876f9 | 2013-09-13 11:39:24 -0700 | [diff] [blame] | 2360 | * HAL workaround: |
| 2361 | * Insert a dummy trigger ID if a trigger is set but no trigger ID is |
| 2362 | */ |
| 2363 | res = addDummyTriggerIds(nextRequest); |
| 2364 | if (res != OK) { |
| 2365 | SET_ERR("RequestThread: Unable to insert dummy trigger IDs " |
| 2366 | "(capture request %d, HAL device: %s (%d)", |
Jianing Wei | 2d6bb3f | 2014-04-11 10:00:31 -0700 | [diff] [blame] | 2367 | request.frame_number, strerror(-res), res); |
Eino-Ville Talvala | 2f876f9 | 2013-09-13 11:39:24 -0700 | [diff] [blame] | 2368 | cleanUpFailedRequest(request, nextRequest, outputBuffers); |
| 2369 | return false; |
| 2370 | } |
| 2371 | |
| 2372 | /** |
Igor Murashkin | 4d2f2e8 | 2013-04-01 17:29:07 -0700 | [diff] [blame] | 2373 | * The request should be presorted so accesses in HAL |
| 2374 | * are O(logn). Sidenote, sorting a sorted metadata is nop. |
| 2375 | */ |
| 2376 | nextRequest->mSettings.sort(); |
Eino-Ville Talvala | f76e027 | 2013-02-27 18:02:26 -0800 | [diff] [blame] | 2377 | request.settings = nextRequest->mSettings.getAndLock(); |
| 2378 | mPrevRequest = nextRequest; |
Igor Murashkin | 4d2f2e8 | 2013-04-01 17:29:07 -0700 | [diff] [blame] | 2379 | ALOGVV("%s: Request settings are NEW", __FUNCTION__); |
| 2380 | |
| 2381 | IF_ALOGV() { |
| 2382 | camera_metadata_ro_entry_t e = camera_metadata_ro_entry_t(); |
| 2383 | find_camera_metadata_ro_entry( |
| 2384 | request.settings, |
| 2385 | ANDROID_CONTROL_AF_TRIGGER, |
| 2386 | &e |
| 2387 | ); |
| 2388 | if (e.count > 0) { |
| 2389 | ALOGV("%s: Request (frame num %d) had AF trigger 0x%x", |
| 2390 | __FUNCTION__, |
Jianing Wei | 2d6bb3f | 2014-04-11 10:00:31 -0700 | [diff] [blame] | 2391 | request.frame_number, |
Igor Murashkin | 4d2f2e8 | 2013-04-01 17:29:07 -0700 | [diff] [blame] | 2392 | e.data.u8[0]); |
| 2393 | } |
| 2394 | } |
| 2395 | } else { |
| 2396 | // leave request.settings NULL to indicate 'reuse latest given' |
| 2397 | ALOGVV("%s: Request settings are REUSED", |
| 2398 | __FUNCTION__); |
| 2399 | } |
Eino-Ville Talvala | f76e027 | 2013-02-27 18:02:26 -0800 | [diff] [blame] | 2400 | |
| 2401 | camera3_stream_buffer_t inputBuffer; |
Zhijun He | f0d962a | 2014-06-30 10:24:11 -0700 | [diff] [blame] | 2402 | uint32_t totalNumBuffers = 0; |
Eino-Ville Talvala | f76e027 | 2013-02-27 18:02:26 -0800 | [diff] [blame] | 2403 | |
| 2404 | // Fill in buffers |
| 2405 | |
| 2406 | if (nextRequest->mInputStream != NULL) { |
| 2407 | request.input_buffer = &inputBuffer; |
Igor Murashkin | 5a269fa | 2013-04-15 14:59:22 -0700 | [diff] [blame] | 2408 | res = nextRequest->mInputStream->getInputBuffer(&inputBuffer); |
Eino-Ville Talvala | f76e027 | 2013-02-27 18:02:26 -0800 | [diff] [blame] | 2409 | if (res != OK) { |
Eino-Ville Talvala | 07d2169 | 2013-09-24 18:04:19 -0700 | [diff] [blame] | 2410 | ALOGE("RequestThread: Can't get input buffer, skipping request:" |
Eino-Ville Talvala | f76e027 | 2013-02-27 18:02:26 -0800 | [diff] [blame] | 2411 | " %s (%d)", strerror(-res), res); |
| 2412 | cleanUpFailedRequest(request, nextRequest, outputBuffers); |
| 2413 | return true; |
| 2414 | } |
Zhijun He | f0d962a | 2014-06-30 10:24:11 -0700 | [diff] [blame] | 2415 | totalNumBuffers += 1; |
Eino-Ville Talvala | f76e027 | 2013-02-27 18:02:26 -0800 | [diff] [blame] | 2416 | } else { |
| 2417 | request.input_buffer = NULL; |
| 2418 | } |
| 2419 | |
| 2420 | outputBuffers.insertAt(camera3_stream_buffer_t(), 0, |
| 2421 | nextRequest->mOutputStreams.size()); |
| 2422 | request.output_buffers = outputBuffers.array(); |
| 2423 | for (size_t i = 0; i < nextRequest->mOutputStreams.size(); i++) { |
| 2424 | res = nextRequest->mOutputStreams.editItemAt(i)-> |
| 2425 | getBuffer(&outputBuffers.editItemAt(i)); |
| 2426 | if (res != OK) { |
Eino-Ville Talvala | 07d2169 | 2013-09-24 18:04:19 -0700 | [diff] [blame] | 2427 | ALOGE("RequestThread: Can't get output buffer, skipping request:" |
| 2428 | " %s (%d)", strerror(-res), res); |
Eino-Ville Talvala | f76e027 | 2013-02-27 18:02:26 -0800 | [diff] [blame] | 2429 | cleanUpFailedRequest(request, nextRequest, outputBuffers); |
| 2430 | return true; |
| 2431 | } |
| 2432 | request.num_output_buffers++; |
| 2433 | } |
Zhijun He | f0d962a | 2014-06-30 10:24:11 -0700 | [diff] [blame] | 2434 | totalNumBuffers += request.num_output_buffers; |
Eino-Ville Talvala | f76e027 | 2013-02-27 18:02:26 -0800 | [diff] [blame] | 2435 | |
Eino-Ville Talvala | 42368d9 | 2013-04-09 14:13:50 -0700 | [diff] [blame] | 2436 | // Log request in the in-flight queue |
| 2437 | sp<Camera3Device> parent = mParent.promote(); |
| 2438 | if (parent == NULL) { |
| 2439 | CLOGE("RequestThread: Parent is gone"); |
| 2440 | cleanUpFailedRequest(request, nextRequest, outputBuffers); |
| 2441 | return false; |
| 2442 | } |
| 2443 | |
Jianing Wei | cb0652e | 2014-03-12 18:29:36 -0700 | [diff] [blame] | 2444 | res = parent->registerInFlight(request.frame_number, |
Zhijun He | c98bd8d | 2014-07-07 12:44:10 -0700 | [diff] [blame] | 2445 | totalNumBuffers, nextRequest->mResultExtras, |
| 2446 | /*hasInput*/request.input_buffer != NULL); |
Jianing Wei | 2d6bb3f | 2014-04-11 10:00:31 -0700 | [diff] [blame] | 2447 | ALOGVV("%s: registered in flight requestId = %" PRId32 ", frameNumber = %" PRId64 |
| 2448 | ", burstId = %" PRId32 ".", |
Jianing Wei | cb0652e | 2014-03-12 18:29:36 -0700 | [diff] [blame] | 2449 | __FUNCTION__, |
| 2450 | nextRequest->mResultExtras.requestId, nextRequest->mResultExtras.frameNumber, |
| 2451 | nextRequest->mResultExtras.burstId); |
Eino-Ville Talvala | 42368d9 | 2013-04-09 14:13:50 -0700 | [diff] [blame] | 2452 | if (res != OK) { |
| 2453 | SET_ERR("RequestThread: Unable to register new in-flight request:" |
| 2454 | " %s (%d)", strerror(-res), res); |
| 2455 | cleanUpFailedRequest(request, nextRequest, outputBuffers); |
| 2456 | return false; |
| 2457 | } |
Igor Murashkin | 4d2f2e8 | 2013-04-01 17:29:07 -0700 | [diff] [blame] | 2458 | |
Zhijun He | cc27e11 | 2013-10-03 16:12:43 -0700 | [diff] [blame] | 2459 | // Inform waitUntilRequestProcessed thread of a new request ID |
| 2460 | { |
| 2461 | Mutex::Autolock al(mLatestRequestMutex); |
| 2462 | |
| 2463 | mLatestRequestId = requestId; |
| 2464 | mLatestRequestSignal.signal(); |
| 2465 | } |
| 2466 | |
Eino-Ville Talvala | f76e027 | 2013-02-27 18:02:26 -0800 | [diff] [blame] | 2467 | // Submit request and block until ready for next one |
Eino-Ville Talvala | 17a61ad | 2013-06-03 16:53:32 -0700 | [diff] [blame] | 2468 | ATRACE_ASYNC_BEGIN("frame capture", request.frame_number); |
| 2469 | ATRACE_BEGIN("camera3->process_capture_request"); |
Eino-Ville Talvala | f76e027 | 2013-02-27 18:02:26 -0800 | [diff] [blame] | 2470 | res = mHal3Device->ops->process_capture_request(mHal3Device, &request); |
Eino-Ville Talvala | 17a61ad | 2013-06-03 16:53:32 -0700 | [diff] [blame] | 2471 | ATRACE_END(); |
| 2472 | |
Eino-Ville Talvala | f76e027 | 2013-02-27 18:02:26 -0800 | [diff] [blame] | 2473 | if (res != OK) { |
Eino-Ville Talvala | b2058d1 | 2013-04-09 13:49:56 -0700 | [diff] [blame] | 2474 | SET_ERR("RequestThread: Unable to submit capture request %d to HAL" |
Eino-Ville Talvala | f76e027 | 2013-02-27 18:02:26 -0800 | [diff] [blame] | 2475 | " device: %s (%d)", request.frame_number, strerror(-res), res); |
| 2476 | cleanUpFailedRequest(request, nextRequest, outputBuffers); |
| 2477 | return false; |
| 2478 | } |
| 2479 | |
Igor Murashkin | 1e479c0 | 2013-09-06 16:55:14 -0700 | [diff] [blame] | 2480 | // Update the latest request sent to HAL |
| 2481 | if (request.settings != NULL) { // Don't update them if they were unchanged |
| 2482 | Mutex::Autolock al(mLatestRequestMutex); |
| 2483 | |
| 2484 | camera_metadata_t* cloned = clone_camera_metadata(request.settings); |
| 2485 | mLatestRequest.acquire(cloned); |
| 2486 | } |
| 2487 | |
Eino-Ville Talvala | f76e027 | 2013-02-27 18:02:26 -0800 | [diff] [blame] | 2488 | if (request.settings != NULL) { |
| 2489 | nextRequest->mSettings.unlock(request.settings); |
| 2490 | } |
Igor Murashkin | 4d2f2e8 | 2013-04-01 17:29:07 -0700 | [diff] [blame] | 2491 | |
| 2492 | // Remove any previously queued triggers (after unlock) |
| 2493 | res = removeTriggers(mPrevRequest); |
| 2494 | if (res != OK) { |
Eino-Ville Talvala | b2058d1 | 2013-04-09 13:49:56 -0700 | [diff] [blame] | 2495 | SET_ERR("RequestThread: Unable to remove triggers " |
Igor Murashkin | 4d2f2e8 | 2013-04-01 17:29:07 -0700 | [diff] [blame] | 2496 | "(capture request %d, HAL device: %s (%d)", |
| 2497 | request.frame_number, strerror(-res), res); |
| 2498 | return false; |
| 2499 | } |
| 2500 | mPrevTriggers = triggerCount; |
| 2501 | |
Eino-Ville Talvala | f76e027 | 2013-02-27 18:02:26 -0800 | [diff] [blame] | 2502 | return true; |
| 2503 | } |
| 2504 | |
Igor Murashkin | 1e479c0 | 2013-09-06 16:55:14 -0700 | [diff] [blame] | 2505 | CameraMetadata Camera3Device::RequestThread::getLatestRequest() const { |
| 2506 | Mutex::Autolock al(mLatestRequestMutex); |
| 2507 | |
| 2508 | ALOGV("RequestThread::%s", __FUNCTION__); |
| 2509 | |
| 2510 | return mLatestRequest; |
| 2511 | } |
| 2512 | |
Jianing Wei | cb0652e | 2014-03-12 18:29:36 -0700 | [diff] [blame] | 2513 | |
Eino-Ville Talvala | f76e027 | 2013-02-27 18:02:26 -0800 | [diff] [blame] | 2514 | void Camera3Device::RequestThread::cleanUpFailedRequest( |
| 2515 | camera3_capture_request_t &request, |
| 2516 | sp<CaptureRequest> &nextRequest, |
| 2517 | Vector<camera3_stream_buffer_t> &outputBuffers) { |
| 2518 | |
| 2519 | if (request.settings != NULL) { |
| 2520 | nextRequest->mSettings.unlock(request.settings); |
| 2521 | } |
| 2522 | if (request.input_buffer != NULL) { |
| 2523 | request.input_buffer->status = CAMERA3_BUFFER_STATUS_ERROR; |
Igor Murashkin | 5a269fa | 2013-04-15 14:59:22 -0700 | [diff] [blame] | 2524 | nextRequest->mInputStream->returnInputBuffer(*(request.input_buffer)); |
Eino-Ville Talvala | f76e027 | 2013-02-27 18:02:26 -0800 | [diff] [blame] | 2525 | } |
| 2526 | for (size_t i = 0; i < request.num_output_buffers; i++) { |
| 2527 | outputBuffers.editItemAt(i).status = CAMERA3_BUFFER_STATUS_ERROR; |
| 2528 | nextRequest->mOutputStreams.editItemAt(i)->returnBuffer( |
| 2529 | outputBuffers[i], 0); |
| 2530 | } |
Eino-Ville Talvala | f76e027 | 2013-02-27 18:02:26 -0800 | [diff] [blame] | 2531 | } |
| 2532 | |
| 2533 | sp<Camera3Device::CaptureRequest> |
| 2534 | Camera3Device::RequestThread::waitForNextRequest() { |
| 2535 | status_t res; |
| 2536 | sp<CaptureRequest> nextRequest; |
| 2537 | |
| 2538 | // Optimized a bit for the simple steady-state case (single repeating |
| 2539 | // request), to avoid putting that request in the queue temporarily. |
| 2540 | Mutex::Autolock l(mRequestLock); |
| 2541 | |
| 2542 | while (mRequestQueue.empty()) { |
| 2543 | if (!mRepeatingRequests.empty()) { |
| 2544 | // Always atomically enqueue all requests in a repeating request |
| 2545 | // list. Guarantees a complete in-sequence set of captures to |
| 2546 | // application. |
| 2547 | const RequestList &requests = mRepeatingRequests; |
| 2548 | RequestList::const_iterator firstRequest = |
| 2549 | requests.begin(); |
| 2550 | nextRequest = *firstRequest; |
| 2551 | mRequestQueue.insert(mRequestQueue.end(), |
| 2552 | ++firstRequest, |
| 2553 | requests.end()); |
| 2554 | // No need to wait any longer |
Jianing Wei | cb0652e | 2014-03-12 18:29:36 -0700 | [diff] [blame] | 2555 | |
Jianing Wei | 2d6bb3f | 2014-04-11 10:00:31 -0700 | [diff] [blame] | 2556 | mRepeatingLastFrameNumber = mFrameNumber + requests.size() - 1; |
Jianing Wei | cb0652e | 2014-03-12 18:29:36 -0700 | [diff] [blame] | 2557 | |
Eino-Ville Talvala | f76e027 | 2013-02-27 18:02:26 -0800 | [diff] [blame] | 2558 | break; |
| 2559 | } |
| 2560 | |
| 2561 | res = mRequestSignal.waitRelative(mRequestLock, kRequestTimeout); |
| 2562 | |
Eino-Ville Talvala | f1e98d8 | 2013-09-06 09:32:43 -0700 | [diff] [blame] | 2563 | if ((mRequestQueue.empty() && mRepeatingRequests.empty()) || |
| 2564 | exitPending()) { |
Eino-Ville Talvala | f76e027 | 2013-02-27 18:02:26 -0800 | [diff] [blame] | 2565 | Mutex::Autolock pl(mPauseLock); |
| 2566 | if (mPaused == false) { |
Eino-Ville Talvala | f1e98d8 | 2013-09-06 09:32:43 -0700 | [diff] [blame] | 2567 | ALOGV("%s: RequestThread: Going idle", __FUNCTION__); |
Eino-Ville Talvala | f76e027 | 2013-02-27 18:02:26 -0800 | [diff] [blame] | 2568 | mPaused = true; |
Eino-Ville Talvala | f1e98d8 | 2013-09-06 09:32:43 -0700 | [diff] [blame] | 2569 | // Let the tracker know |
| 2570 | sp<StatusTracker> statusTracker = mStatusTracker.promote(); |
| 2571 | if (statusTracker != 0) { |
| 2572 | statusTracker->markComponentIdle(mStatusId, Fence::NO_FENCE); |
| 2573 | } |
Eino-Ville Talvala | f76e027 | 2013-02-27 18:02:26 -0800 | [diff] [blame] | 2574 | } |
| 2575 | // Stop waiting for now and let thread management happen |
| 2576 | return NULL; |
| 2577 | } |
| 2578 | } |
| 2579 | |
| 2580 | if (nextRequest == NULL) { |
| 2581 | // Don't have a repeating request already in hand, so queue |
| 2582 | // must have an entry now. |
| 2583 | RequestList::iterator firstRequest = |
| 2584 | mRequestQueue.begin(); |
| 2585 | nextRequest = *firstRequest; |
| 2586 | mRequestQueue.erase(firstRequest); |
| 2587 | } |
| 2588 | |
Eino-Ville Talvala | 26fe6c7 | 2013-08-29 12:46:18 -0700 | [diff] [blame] | 2589 | // In case we've been unpaused by setPaused clearing mDoPause, need to |
| 2590 | // update internal pause state (capture/setRepeatingRequest unpause |
| 2591 | // directly). |
Eino-Ville Talvala | f76e027 | 2013-02-27 18:02:26 -0800 | [diff] [blame] | 2592 | Mutex::Autolock pl(mPauseLock); |
Eino-Ville Talvala | f1e98d8 | 2013-09-06 09:32:43 -0700 | [diff] [blame] | 2593 | if (mPaused) { |
| 2594 | ALOGV("%s: RequestThread: Unpaused", __FUNCTION__); |
| 2595 | sp<StatusTracker> statusTracker = mStatusTracker.promote(); |
| 2596 | if (statusTracker != 0) { |
| 2597 | statusTracker->markComponentActive(mStatusId); |
| 2598 | } |
| 2599 | } |
Eino-Ville Talvala | f76e027 | 2013-02-27 18:02:26 -0800 | [diff] [blame] | 2600 | mPaused = false; |
| 2601 | |
| 2602 | // Check if we've reconfigured since last time, and reset the preview |
| 2603 | // request if so. Can't use 'NULL request == repeat' across configure calls. |
| 2604 | if (mReconfigured) { |
| 2605 | mPrevRequest.clear(); |
| 2606 | mReconfigured = false; |
| 2607 | } |
| 2608 | |
Jianing Wei | 2d6bb3f | 2014-04-11 10:00:31 -0700 | [diff] [blame] | 2609 | if (nextRequest != NULL) { |
| 2610 | nextRequest->mResultExtras.frameNumber = mFrameNumber++; |
| 2611 | } |
Eino-Ville Talvala | f76e027 | 2013-02-27 18:02:26 -0800 | [diff] [blame] | 2612 | return nextRequest; |
| 2613 | } |
| 2614 | |
| 2615 | bool Camera3Device::RequestThread::waitIfPaused() { |
| 2616 | status_t res; |
| 2617 | Mutex::Autolock l(mPauseLock); |
| 2618 | while (mDoPause) { |
Eino-Ville Talvala | f76e027 | 2013-02-27 18:02:26 -0800 | [diff] [blame] | 2619 | if (mPaused == false) { |
| 2620 | mPaused = true; |
Eino-Ville Talvala | f1e98d8 | 2013-09-06 09:32:43 -0700 | [diff] [blame] | 2621 | ALOGV("%s: RequestThread: Paused", __FUNCTION__); |
| 2622 | // Let the tracker know |
| 2623 | sp<StatusTracker> statusTracker = mStatusTracker.promote(); |
| 2624 | if (statusTracker != 0) { |
| 2625 | statusTracker->markComponentIdle(mStatusId, Fence::NO_FENCE); |
| 2626 | } |
Eino-Ville Talvala | f76e027 | 2013-02-27 18:02:26 -0800 | [diff] [blame] | 2627 | } |
Eino-Ville Talvala | f1e98d8 | 2013-09-06 09:32:43 -0700 | [diff] [blame] | 2628 | |
Eino-Ville Talvala | f76e027 | 2013-02-27 18:02:26 -0800 | [diff] [blame] | 2629 | res = mDoPauseSignal.waitRelative(mPauseLock, kRequestTimeout); |
Eino-Ville Talvala | f1e98d8 | 2013-09-06 09:32:43 -0700 | [diff] [blame] | 2630 | if (res == TIMED_OUT || exitPending()) { |
Eino-Ville Talvala | f76e027 | 2013-02-27 18:02:26 -0800 | [diff] [blame] | 2631 | return true; |
| 2632 | } |
| 2633 | } |
| 2634 | // We don't set mPaused to false here, because waitForNextRequest needs |
| 2635 | // to further manage the paused state in case of starvation. |
| 2636 | return false; |
| 2637 | } |
| 2638 | |
Eino-Ville Talvala | 26fe6c7 | 2013-08-29 12:46:18 -0700 | [diff] [blame] | 2639 | void Camera3Device::RequestThread::unpauseForNewRequests() { |
| 2640 | // With work to do, mark thread as unpaused. |
| 2641 | // If paused by request (setPaused), don't resume, to avoid |
| 2642 | // extra signaling/waiting overhead to waitUntilPaused |
Eino-Ville Talvala | f1e98d8 | 2013-09-06 09:32:43 -0700 | [diff] [blame] | 2643 | mRequestSignal.signal(); |
Eino-Ville Talvala | 26fe6c7 | 2013-08-29 12:46:18 -0700 | [diff] [blame] | 2644 | Mutex::Autolock p(mPauseLock); |
| 2645 | if (!mDoPause) { |
Eino-Ville Talvala | f1e98d8 | 2013-09-06 09:32:43 -0700 | [diff] [blame] | 2646 | ALOGV("%s: RequestThread: Going active", __FUNCTION__); |
| 2647 | if (mPaused) { |
| 2648 | sp<StatusTracker> statusTracker = mStatusTracker.promote(); |
| 2649 | if (statusTracker != 0) { |
| 2650 | statusTracker->markComponentActive(mStatusId); |
| 2651 | } |
| 2652 | } |
Eino-Ville Talvala | 26fe6c7 | 2013-08-29 12:46:18 -0700 | [diff] [blame] | 2653 | mPaused = false; |
| 2654 | } |
| 2655 | } |
| 2656 | |
Eino-Ville Talvala | b2058d1 | 2013-04-09 13:49:56 -0700 | [diff] [blame] | 2657 | void Camera3Device::RequestThread::setErrorState(const char *fmt, ...) { |
| 2658 | sp<Camera3Device> parent = mParent.promote(); |
| 2659 | if (parent != NULL) { |
| 2660 | va_list args; |
| 2661 | va_start(args, fmt); |
| 2662 | |
| 2663 | parent->setErrorStateV(fmt, args); |
| 2664 | |
| 2665 | va_end(args); |
| 2666 | } |
| 2667 | } |
| 2668 | |
Igor Murashkin | 4d2f2e8 | 2013-04-01 17:29:07 -0700 | [diff] [blame] | 2669 | status_t Camera3Device::RequestThread::insertTriggers( |
| 2670 | const sp<CaptureRequest> &request) { |
| 2671 | |
| 2672 | Mutex::Autolock al(mTriggerMutex); |
| 2673 | |
Yin-Chia Yeh | 741ace8 | 2014-06-23 14:07:56 -0700 | [diff] [blame] | 2674 | sp<Camera3Device> parent = mParent.promote(); |
| 2675 | if (parent == NULL) { |
| 2676 | CLOGE("RequestThread: Parent is gone"); |
| 2677 | return DEAD_OBJECT; |
| 2678 | } |
| 2679 | |
Igor Murashkin | 4d2f2e8 | 2013-04-01 17:29:07 -0700 | [diff] [blame] | 2680 | CameraMetadata &metadata = request->mSettings; |
| 2681 | size_t count = mTriggerMap.size(); |
| 2682 | |
| 2683 | for (size_t i = 0; i < count; ++i) { |
| 2684 | RequestTrigger trigger = mTriggerMap.valueAt(i); |
Igor Murashkin | 4d2f2e8 | 2013-04-01 17:29:07 -0700 | [diff] [blame] | 2685 | uint32_t tag = trigger.metadataTag; |
Yin-Chia Yeh | 741ace8 | 2014-06-23 14:07:56 -0700 | [diff] [blame] | 2686 | |
| 2687 | if (tag == ANDROID_CONTROL_AF_TRIGGER_ID || tag == ANDROID_CONTROL_AE_PRECAPTURE_ID) { |
| 2688 | bool isAeTrigger = (trigger.metadataTag == ANDROID_CONTROL_AE_PRECAPTURE_ID); |
| 2689 | uint32_t triggerId = static_cast<uint32_t>(trigger.entryValue); |
| 2690 | isAeTrigger ? request->mResultExtras.precaptureTriggerId = triggerId : |
| 2691 | request->mResultExtras.afTriggerId = triggerId; |
| 2692 | if (parent->mDeviceVersion >= CAMERA_DEVICE_API_VERSION_3_2) { |
| 2693 | continue; // Trigger ID tag is deprecated since device HAL 3.2 |
| 2694 | } |
| 2695 | } |
| 2696 | |
Igor Murashkin | 4d2f2e8 | 2013-04-01 17:29:07 -0700 | [diff] [blame] | 2697 | camera_metadata_entry entry = metadata.find(tag); |
| 2698 | |
| 2699 | if (entry.count > 0) { |
| 2700 | /** |
| 2701 | * Already has an entry for this trigger in the request. |
| 2702 | * Rewrite it with our requested trigger value. |
| 2703 | */ |
| 2704 | RequestTrigger oldTrigger = trigger; |
| 2705 | |
| 2706 | oldTrigger.entryValue = entry.data.u8[0]; |
| 2707 | |
| 2708 | mTriggerReplacedMap.add(tag, oldTrigger); |
| 2709 | } else { |
| 2710 | /** |
| 2711 | * More typical, no trigger entry, so we just add it |
| 2712 | */ |
| 2713 | mTriggerRemovedMap.add(tag, trigger); |
| 2714 | } |
| 2715 | |
| 2716 | status_t res; |
| 2717 | |
| 2718 | switch (trigger.getTagType()) { |
| 2719 | case TYPE_BYTE: { |
| 2720 | uint8_t entryValue = static_cast<uint8_t>(trigger.entryValue); |
| 2721 | res = metadata.update(tag, |
| 2722 | &entryValue, |
| 2723 | /*count*/1); |
| 2724 | break; |
| 2725 | } |
| 2726 | case TYPE_INT32: |
| 2727 | res = metadata.update(tag, |
| 2728 | &trigger.entryValue, |
| 2729 | /*count*/1); |
| 2730 | break; |
| 2731 | default: |
| 2732 | ALOGE("%s: Type not supported: 0x%x", |
| 2733 | __FUNCTION__, |
| 2734 | trigger.getTagType()); |
| 2735 | return INVALID_OPERATION; |
| 2736 | } |
| 2737 | |
| 2738 | if (res != OK) { |
| 2739 | ALOGE("%s: Failed to update request metadata with trigger tag %s" |
| 2740 | ", value %d", __FUNCTION__, trigger.getTagName(), |
| 2741 | trigger.entryValue); |
| 2742 | return res; |
| 2743 | } |
| 2744 | |
| 2745 | ALOGV("%s: Mixed in trigger %s, value %d", __FUNCTION__, |
| 2746 | trigger.getTagName(), |
| 2747 | trigger.entryValue); |
| 2748 | } |
| 2749 | |
| 2750 | mTriggerMap.clear(); |
| 2751 | |
| 2752 | return count; |
| 2753 | } |
| 2754 | |
| 2755 | status_t Camera3Device::RequestThread::removeTriggers( |
| 2756 | const sp<CaptureRequest> &request) { |
| 2757 | Mutex::Autolock al(mTriggerMutex); |
| 2758 | |
| 2759 | CameraMetadata &metadata = request->mSettings; |
| 2760 | |
| 2761 | /** |
| 2762 | * Replace all old entries with their old values. |
| 2763 | */ |
| 2764 | for (size_t i = 0; i < mTriggerReplacedMap.size(); ++i) { |
| 2765 | RequestTrigger trigger = mTriggerReplacedMap.valueAt(i); |
| 2766 | |
| 2767 | status_t res; |
| 2768 | |
| 2769 | uint32_t tag = trigger.metadataTag; |
| 2770 | switch (trigger.getTagType()) { |
| 2771 | case TYPE_BYTE: { |
| 2772 | uint8_t entryValue = static_cast<uint8_t>(trigger.entryValue); |
| 2773 | res = metadata.update(tag, |
| 2774 | &entryValue, |
| 2775 | /*count*/1); |
| 2776 | break; |
| 2777 | } |
| 2778 | case TYPE_INT32: |
| 2779 | res = metadata.update(tag, |
| 2780 | &trigger.entryValue, |
| 2781 | /*count*/1); |
| 2782 | break; |
| 2783 | default: |
| 2784 | ALOGE("%s: Type not supported: 0x%x", |
| 2785 | __FUNCTION__, |
| 2786 | trigger.getTagType()); |
| 2787 | return INVALID_OPERATION; |
| 2788 | } |
| 2789 | |
| 2790 | if (res != OK) { |
| 2791 | ALOGE("%s: Failed to restore request metadata with trigger tag %s" |
| 2792 | ", trigger value %d", __FUNCTION__, |
| 2793 | trigger.getTagName(), trigger.entryValue); |
| 2794 | return res; |
| 2795 | } |
| 2796 | } |
| 2797 | mTriggerReplacedMap.clear(); |
| 2798 | |
| 2799 | /** |
| 2800 | * Remove all new entries. |
| 2801 | */ |
| 2802 | for (size_t i = 0; i < mTriggerRemovedMap.size(); ++i) { |
| 2803 | RequestTrigger trigger = mTriggerRemovedMap.valueAt(i); |
| 2804 | status_t res = metadata.erase(trigger.metadataTag); |
| 2805 | |
| 2806 | if (res != OK) { |
| 2807 | ALOGE("%s: Failed to erase metadata with trigger tag %s" |
| 2808 | ", trigger value %d", __FUNCTION__, |
| 2809 | trigger.getTagName(), trigger.entryValue); |
| 2810 | return res; |
| 2811 | } |
| 2812 | } |
| 2813 | mTriggerRemovedMap.clear(); |
| 2814 | |
| 2815 | return OK; |
| 2816 | } |
| 2817 | |
Eino-Ville Talvala | 2f876f9 | 2013-09-13 11:39:24 -0700 | [diff] [blame] | 2818 | status_t Camera3Device::RequestThread::addDummyTriggerIds( |
| 2819 | const sp<CaptureRequest> &request) { |
| 2820 | // Trigger ID 0 has special meaning in the HAL2 spec, so avoid it here |
| 2821 | static const int32_t dummyTriggerId = 1; |
| 2822 | status_t res; |
| 2823 | |
| 2824 | CameraMetadata &metadata = request->mSettings; |
| 2825 | |
| 2826 | // If AF trigger is active, insert a dummy AF trigger ID if none already |
| 2827 | // exists |
| 2828 | camera_metadata_entry afTrigger = metadata.find(ANDROID_CONTROL_AF_TRIGGER); |
| 2829 | camera_metadata_entry afId = metadata.find(ANDROID_CONTROL_AF_TRIGGER_ID); |
| 2830 | if (afTrigger.count > 0 && |
| 2831 | afTrigger.data.u8[0] != ANDROID_CONTROL_AF_TRIGGER_IDLE && |
| 2832 | afId.count == 0) { |
| 2833 | res = metadata.update(ANDROID_CONTROL_AF_TRIGGER_ID, &dummyTriggerId, 1); |
| 2834 | if (res != OK) return res; |
| 2835 | } |
| 2836 | |
| 2837 | // If AE precapture trigger is active, insert a dummy precapture trigger ID |
| 2838 | // if none already exists |
| 2839 | camera_metadata_entry pcTrigger = |
| 2840 | metadata.find(ANDROID_CONTROL_AE_PRECAPTURE_TRIGGER); |
| 2841 | camera_metadata_entry pcId = metadata.find(ANDROID_CONTROL_AE_PRECAPTURE_ID); |
| 2842 | if (pcTrigger.count > 0 && |
| 2843 | pcTrigger.data.u8[0] != ANDROID_CONTROL_AE_PRECAPTURE_TRIGGER_IDLE && |
| 2844 | pcId.count == 0) { |
| 2845 | res = metadata.update(ANDROID_CONTROL_AE_PRECAPTURE_ID, |
| 2846 | &dummyTriggerId, 1); |
| 2847 | if (res != OK) return res; |
| 2848 | } |
| 2849 | |
| 2850 | return OK; |
| 2851 | } |
Igor Murashkin | 4d2f2e8 | 2013-04-01 17:29:07 -0700 | [diff] [blame] | 2852 | |
| 2853 | |
Eino-Ville Talvala | f76e027 | 2013-02-27 18:02:26 -0800 | [diff] [blame] | 2854 | /** |
Eino-Ville Talvala | 7fa43f3 | 2013-02-06 17:20:07 -0800 | [diff] [blame] | 2855 | * Static callback forwarding methods from HAL to instance |
| 2856 | */ |
| 2857 | |
| 2858 | void Camera3Device::sProcessCaptureResult(const camera3_callback_ops *cb, |
| 2859 | const camera3_capture_result *result) { |
| 2860 | Camera3Device *d = |
| 2861 | const_cast<Camera3Device*>(static_cast<const Camera3Device*>(cb)); |
| 2862 | d->processCaptureResult(result); |
| 2863 | } |
| 2864 | |
| 2865 | void Camera3Device::sNotify(const camera3_callback_ops *cb, |
| 2866 | const camera3_notify_msg *msg) { |
| 2867 | Camera3Device *d = |
| 2868 | const_cast<Camera3Device*>(static_cast<const Camera3Device*>(cb)); |
| 2869 | d->notify(msg); |
| 2870 | } |
| 2871 | |
| 2872 | }; // namespace android |