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