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