Ari Hausman-Cohen | 7344215 | 2016-06-08 15:50:49 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2016 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 | #include "V4L2Camera.h" |
| 18 | |
Ari Hausman-Cohen | 345bd3a | 2016-06-13 15:33:53 -0700 | [diff] [blame] | 19 | #include <fcntl.h> |
Ari Hausman-Cohen | 4992584 | 2016-06-21 14:07:58 -0700 | [diff] [blame] | 20 | #include <linux/videodev2.h> |
Ari Hausman-Cohen | 345bd3a | 2016-06-13 15:33:53 -0700 | [diff] [blame] | 21 | #include <sys/types.h> |
| 22 | #include <sys/stat.h> |
| 23 | |
Ari Hausman-Cohen | 4992584 | 2016-06-21 14:07:58 -0700 | [diff] [blame] | 24 | #include <cstdlib> |
| 25 | |
Ari Hausman-Cohen | 7344215 | 2016-06-08 15:50:49 -0700 | [diff] [blame] | 26 | #include <camera/CameraMetadata.h> |
| 27 | #include <hardware/camera3.h> |
Ari Hausman-Cohen | 345bd3a | 2016-06-13 15:33:53 -0700 | [diff] [blame] | 28 | #include <nativehelper/ScopedFd.h> |
Ari Hausman-Cohen | 7344215 | 2016-06-08 15:50:49 -0700 | [diff] [blame] | 29 | |
| 30 | #include "Common.h" |
Ari Hausman-Cohen | 3eece6f | 2016-07-21 11:08:24 -0700 | [diff] [blame] | 31 | #include "V4L2Gralloc.h" |
Ari Hausman-Cohen | 7344215 | 2016-06-08 15:50:49 -0700 | [diff] [blame] | 32 | |
Ari Hausman-Cohen | 900c1e3 | 2016-06-20 16:52:41 -0700 | [diff] [blame] | 33 | #define ARRAY_SIZE(a) (sizeof(a) / sizeof(*(a))) |
| 34 | |
Ari Hausman-Cohen | 7344215 | 2016-06-08 15:50:49 -0700 | [diff] [blame] | 35 | namespace v4l2_camera_hal { |
| 36 | |
Ari Hausman-Cohen | dde8017 | 2016-07-01 16:20:36 -0700 | [diff] [blame] | 37 | // Helper function for managing metadata. |
| 38 | static std::vector<int32_t> getMetadataKeys( |
| 39 | const camera_metadata_t* metadata) { |
| 40 | std::vector<int32_t> keys; |
| 41 | size_t num_entries = get_camera_metadata_entry_count(metadata); |
| 42 | for (size_t i = 0; i < num_entries; ++i) { |
| 43 | camera_metadata_ro_entry_t entry; |
| 44 | get_camera_metadata_ro_entry(metadata, i, &entry); |
| 45 | keys.push_back(entry.tag); |
| 46 | } |
| 47 | return keys; |
| 48 | } |
| 49 | |
Ari Hausman-Cohen | 681eaa2 | 2016-07-21 16:28:17 -0700 | [diff] [blame^] | 50 | V4L2Camera* V4L2Camera::NewV4L2Camera(int id, const std::string path) { |
| 51 | HAL_LOG_ENTER(); |
| 52 | |
| 53 | std::unique_ptr<V4L2Gralloc> gralloc(V4L2Gralloc::NewV4L2Gralloc()); |
| 54 | if (!gralloc) { |
| 55 | HAL_LOGE("Failed to initialize gralloc helper."); |
| 56 | return nullptr; |
| 57 | } |
| 58 | |
| 59 | return new V4L2Camera(id, path, std::move(gralloc)); |
| 60 | } |
| 61 | |
| 62 | V4L2Camera::V4L2Camera(int id, std::string path, |
| 63 | std::unique_ptr<V4L2Gralloc> gralloc) |
Ari Hausman-Cohen | 4992584 | 2016-06-21 14:07:58 -0700 | [diff] [blame] | 64 | : default_camera_hal::Camera(id), |
| 65 | mDevicePath(std::move(path)), |
Ari Hausman-Cohen | 681eaa2 | 2016-07-21 16:28:17 -0700 | [diff] [blame^] | 66 | mGralloc(std::move(gralloc)), |
Ari Hausman-Cohen | 44d8432 | 2016-07-11 11:08:26 -0700 | [diff] [blame] | 67 | mOutStreamType(0), |
Ari Hausman-Cohen | 72fddb3 | 2016-06-30 16:53:31 -0700 | [diff] [blame] | 68 | mOutStreamFormat(0), |
| 69 | mOutStreamWidth(0), |
| 70 | mOutStreamHeight(0), |
Ari Hausman-Cohen | 3eece6f | 2016-07-21 11:08:24 -0700 | [diff] [blame] | 71 | mOutStreamBytesPerLine(0), |
Ari Hausman-Cohen | 72fddb3 | 2016-06-30 16:53:31 -0700 | [diff] [blame] | 72 | mOutStreamMaxBuffers(0), |
Ari Hausman-Cohen | 4992584 | 2016-06-21 14:07:58 -0700 | [diff] [blame] | 73 | mTemplatesInitialized(false), |
| 74 | mCharacteristicsInitialized(false) { |
Ari Hausman-Cohen | 7344215 | 2016-06-08 15:50:49 -0700 | [diff] [blame] | 75 | HAL_LOG_ENTER(); |
| 76 | } |
| 77 | |
| 78 | V4L2Camera::~V4L2Camera() { |
| 79 | HAL_LOG_ENTER(); |
| 80 | } |
| 81 | |
Ari Hausman-Cohen | 72fddb3 | 2016-06-30 16:53:31 -0700 | [diff] [blame] | 82 | // Helper function. Should be used instead of ioctl throughout this class. |
| 83 | template<typename T> |
| 84 | int V4L2Camera::ioctlLocked(int request, T data) { |
Ari Hausman-Cohen | 24e541c | 2016-07-21 11:20:30 -0700 | [diff] [blame] | 85 | HAL_LOG_ENTER(); |
| 86 | |
Ari Hausman-Cohen | 72fddb3 | 2016-06-30 16:53:31 -0700 | [diff] [blame] | 87 | android::Mutex::Autolock al(mDeviceLock); |
| 88 | if (mDeviceFd.get() < 0) { |
| 89 | return -ENODEV; |
| 90 | } |
| 91 | return TEMP_FAILURE_RETRY(ioctl(mDeviceFd.get(), request, data)); |
| 92 | } |
| 93 | |
Ari Hausman-Cohen | 345bd3a | 2016-06-13 15:33:53 -0700 | [diff] [blame] | 94 | int V4L2Camera::connect() { |
| 95 | HAL_LOG_ENTER(); |
| 96 | |
| 97 | if (mDeviceFd.get() >= 0) { |
| 98 | HAL_LOGE("Camera device %s is opened. Close it first", mDevicePath.c_str()); |
| 99 | return -EIO; |
| 100 | } |
| 101 | |
| 102 | int fd = TEMP_FAILURE_RETRY(open(mDevicePath.c_str(), O_RDWR)); |
| 103 | if (fd < 0) { |
| 104 | HAL_LOGE("failed to open %s (%s)", mDevicePath.c_str(), strerror(errno)); |
| 105 | return -errno; |
| 106 | } |
| 107 | mDeviceFd.reset(fd); |
| 108 | |
| 109 | // TODO(b/29185945): confirm this is a supported device. |
Ari Hausman-Cohen | 4992584 | 2016-06-21 14:07:58 -0700 | [diff] [blame] | 110 | // This is checked by the HAL, but the device at mDevicePath may |
| 111 | // not be the same one that was there when the HAL was loaded. |
| 112 | // (Alternatively, better hotplugging support may make this unecessary |
| 113 | // by disabling cameras that get disconnected and checking newly connected |
| 114 | // cameras, so connect() is never called on an unsupported camera) |
Ari Hausman-Cohen | 900c1e3 | 2016-06-20 16:52:41 -0700 | [diff] [blame] | 115 | |
| 116 | // TODO(b/29158098): Inform service of any flashes that are no longer available |
Ari Hausman-Cohen | 4992584 | 2016-06-21 14:07:58 -0700 | [diff] [blame] | 117 | // because this camera is in use. |
Ari Hausman-Cohen | 345bd3a | 2016-06-13 15:33:53 -0700 | [diff] [blame] | 118 | return 0; |
| 119 | } |
| 120 | |
| 121 | void V4L2Camera::disconnect() { |
| 122 | HAL_LOG_ENTER(); |
Ari Hausman-Cohen | 900c1e3 | 2016-06-20 16:52:41 -0700 | [diff] [blame] | 123 | // TODO(b/29158098): Inform service of any flashes that are available again |
Ari Hausman-Cohen | 4992584 | 2016-06-21 14:07:58 -0700 | [diff] [blame] | 124 | // because this camera is no longer in use. |
Ari Hausman-Cohen | 900c1e3 | 2016-06-20 16:52:41 -0700 | [diff] [blame] | 125 | |
Ari Hausman-Cohen | 345bd3a | 2016-06-13 15:33:53 -0700 | [diff] [blame] | 126 | mDeviceFd.reset(); |
Ari Hausman-Cohen | 44d8432 | 2016-07-11 11:08:26 -0700 | [diff] [blame] | 127 | |
| 128 | // Clear out our variables tracking device settings. |
| 129 | mOutStreamType = 0; |
| 130 | mOutStreamFormat = 0; |
| 131 | mOutStreamWidth = 0; |
| 132 | mOutStreamHeight = 0; |
Ari Hausman-Cohen | 3eece6f | 2016-07-21 11:08:24 -0700 | [diff] [blame] | 133 | mOutStreamBytesPerLine = 0; |
Ari Hausman-Cohen | 44d8432 | 2016-07-11 11:08:26 -0700 | [diff] [blame] | 134 | mOutStreamMaxBuffers = 0; |
Ari Hausman-Cohen | 345bd3a | 2016-06-13 15:33:53 -0700 | [diff] [blame] | 135 | } |
| 136 | |
Ari Hausman-Cohen | 24e541c | 2016-07-21 11:20:30 -0700 | [diff] [blame] | 137 | int V4L2Camera::streamOn() { |
| 138 | HAL_LOG_ENTER(); |
| 139 | |
| 140 | if (!mOutStreamType) { |
| 141 | HAL_LOGE("Stream format must be set before turning on stream."); |
| 142 | return -EINVAL; |
| 143 | } |
| 144 | |
| 145 | if (ioctlLocked(VIDIOC_STREAMON, &mOutStreamType) < 0) { |
| 146 | HAL_LOGE("STREAMON fails: %s", strerror(errno)); |
| 147 | return -ENODEV; |
| 148 | } |
| 149 | |
| 150 | return 0; |
| 151 | } |
| 152 | |
| 153 | int V4L2Camera::streamOff() { |
| 154 | HAL_LOG_ENTER(); |
| 155 | |
| 156 | // TODO(b/30000211): support mplane as well. |
| 157 | if (ioctlLocked(VIDIOC_STREAMOFF, &mOutStreamType) < 0) { |
| 158 | HAL_LOGE("STREAMOFF fails: %s", strerror(errno)); |
| 159 | return -ENODEV; |
| 160 | } |
| 161 | |
| 162 | return 0; |
| 163 | } |
| 164 | |
| 165 | |
Ari Hausman-Cohen | 900c1e3 | 2016-06-20 16:52:41 -0700 | [diff] [blame] | 166 | int V4L2Camera::initStaticInfo(camera_metadata_t** out) { |
Ari Hausman-Cohen | 7344215 | 2016-06-08 15:50:49 -0700 | [diff] [blame] | 167 | HAL_LOG_ENTER(); |
| 168 | |
Ari Hausman-Cohen | 4992584 | 2016-06-21 14:07:58 -0700 | [diff] [blame] | 169 | android::status_t res; |
| 170 | // Device characteristics need to be queried prior |
| 171 | // to static info setup. |
| 172 | if (!mCharacteristicsInitialized) { |
| 173 | res = initCharacteristics(); |
| 174 | if (res) { |
| 175 | return res; |
| 176 | } |
| 177 | } |
| 178 | |
Ari Hausman-Cohen | 900c1e3 | 2016-06-20 16:52:41 -0700 | [diff] [blame] | 179 | android::CameraMetadata info; |
Ari Hausman-Cohen | 63f6982 | 2016-06-10 11:40:35 -0700 | [diff] [blame] | 180 | |
Ari Hausman-Cohen | 900c1e3 | 2016-06-20 16:52:41 -0700 | [diff] [blame] | 181 | // Static metadata characteristics from /system/media/camera/docs/docs.html. |
| 182 | |
Ari Hausman-Cohen | 4992584 | 2016-06-21 14:07:58 -0700 | [diff] [blame] | 183 | /* android.colorCorrection. */ |
Ari Hausman-Cohen | 900c1e3 | 2016-06-20 16:52:41 -0700 | [diff] [blame] | 184 | |
| 185 | // No easy way to turn chromatic aberration correction OFF in v4l2, |
| 186 | // though this may be supportable via a collection of other user controls. |
| 187 | uint8_t avail_aberration_modes[] = { |
| 188 | ANDROID_COLOR_CORRECTION_ABERRATION_MODE_FAST, |
| 189 | ANDROID_COLOR_CORRECTION_ABERRATION_MODE_HIGH_QUALITY}; |
Ari Hausman-Cohen | dde8017 | 2016-07-01 16:20:36 -0700 | [diff] [blame] | 190 | res = info.update(ANDROID_COLOR_CORRECTION_AVAILABLE_ABERRATION_MODES, |
| 191 | avail_aberration_modes, ARRAY_SIZE(avail_aberration_modes)); |
| 192 | if (res != android::OK) { |
| 193 | return res; |
| 194 | } |
Ari Hausman-Cohen | 900c1e3 | 2016-06-20 16:52:41 -0700 | [diff] [blame] | 195 | |
| 196 | /* android.control. */ |
| 197 | |
| 198 | /* 3As */ |
| 199 | |
Ari Hausman-Cohen | dde8017 | 2016-07-01 16:20:36 -0700 | [diff] [blame] | 200 | res = info.update(ANDROID_CONTROL_AE_AVAILABLE_ANTIBANDING_MODES, |
| 201 | mAeAntibandingModes.data(), mAeAntibandingModes.size()); |
| 202 | if (res != android::OK) { |
| 203 | return res; |
| 204 | } |
Ari Hausman-Cohen | 900c1e3 | 2016-06-20 16:52:41 -0700 | [diff] [blame] | 205 | |
Ari Hausman-Cohen | dde8017 | 2016-07-01 16:20:36 -0700 | [diff] [blame] | 206 | res = info.update(ANDROID_CONTROL_AE_AVAILABLE_MODES, |
| 207 | mAeModes.data(), mAeModes.size()); |
| 208 | if (res != android::OK) { |
| 209 | return res; |
| 210 | } |
Ari Hausman-Cohen | 900c1e3 | 2016-06-20 16:52:41 -0700 | [diff] [blame] | 211 | |
Ari Hausman-Cohen | 4992584 | 2016-06-21 14:07:58 -0700 | [diff] [blame] | 212 | // Flatten mFpsRanges. |
Ari Hausman-Cohen | dde8017 | 2016-07-01 16:20:36 -0700 | [diff] [blame] | 213 | res = info.update(ANDROID_CONTROL_AE_AVAILABLE_TARGET_FPS_RANGES, |
| 214 | mFpsRanges.data(), mFpsRanges.total_num_elements()); |
| 215 | if (res != android::OK) { |
| 216 | return res; |
| 217 | } |
Ari Hausman-Cohen | 900c1e3 | 2016-06-20 16:52:41 -0700 | [diff] [blame] | 218 | |
Ari Hausman-Cohen | dde8017 | 2016-07-01 16:20:36 -0700 | [diff] [blame] | 219 | res = info.update(ANDROID_CONTROL_AE_COMPENSATION_RANGE, |
| 220 | mAeCompensationRange.data(), mAeCompensationRange.size()); |
| 221 | if (res != android::OK) { |
| 222 | return res; |
| 223 | } |
Ari Hausman-Cohen | 900c1e3 | 2016-06-20 16:52:41 -0700 | [diff] [blame] | 224 | |
Ari Hausman-Cohen | dde8017 | 2016-07-01 16:20:36 -0700 | [diff] [blame] | 225 | res = info.update(ANDROID_CONTROL_AE_COMPENSATION_STEP, |
| 226 | &mAeCompensationStep, 1); |
| 227 | if (res != android::OK) { |
| 228 | return res; |
| 229 | } |
Ari Hausman-Cohen | 900c1e3 | 2016-06-20 16:52:41 -0700 | [diff] [blame] | 230 | |
Ari Hausman-Cohen | dde8017 | 2016-07-01 16:20:36 -0700 | [diff] [blame] | 231 | res = info.update(ANDROID_CONTROL_AF_AVAILABLE_MODES, |
| 232 | mAfModes.data(), mAfModes.size()); |
| 233 | if (res != android::OK) { |
| 234 | return res; |
| 235 | } |
Ari Hausman-Cohen | 900c1e3 | 2016-06-20 16:52:41 -0700 | [diff] [blame] | 236 | |
Ari Hausman-Cohen | dde8017 | 2016-07-01 16:20:36 -0700 | [diff] [blame] | 237 | res = info.update(ANDROID_CONTROL_AWB_AVAILABLE_MODES, |
| 238 | mAwbModes.data(), mAwbModes.size()); |
| 239 | if (res != android::OK) { |
| 240 | return res; |
| 241 | } |
Ari Hausman-Cohen | 900c1e3 | 2016-06-20 16:52:41 -0700 | [diff] [blame] | 242 | |
| 243 | // Couldn't find any V4L2 support for regions, though maybe it's out there. |
| 244 | int32_t max_regions[] = {/*AE*/ 0,/*AWB*/ 0,/*AF*/ 0}; |
Ari Hausman-Cohen | dde8017 | 2016-07-01 16:20:36 -0700 | [diff] [blame] | 245 | res = info.update(ANDROID_CONTROL_MAX_REGIONS, |
| 246 | max_regions, ARRAY_SIZE(max_regions)); |
| 247 | if (res != android::OK) { |
| 248 | return res; |
| 249 | } |
Ari Hausman-Cohen | 900c1e3 | 2016-06-20 16:52:41 -0700 | [diff] [blame] | 250 | |
Ari Hausman-Cohen | dde8017 | 2016-07-01 16:20:36 -0700 | [diff] [blame] | 251 | res = info.update(ANDROID_CONTROL_AE_LOCK_AVAILABLE, |
| 252 | &mAeLockAvailable, 1); |
| 253 | if (res != android::OK) { |
| 254 | return res; |
| 255 | } |
| 256 | res = info.update(ANDROID_CONTROL_AWB_LOCK_AVAILABLE, |
| 257 | &mAwbLockAvailable, 1); |
| 258 | if (res != android::OK) { |
| 259 | return res; |
| 260 | } |
Ari Hausman-Cohen | 900c1e3 | 2016-06-20 16:52:41 -0700 | [diff] [blame] | 261 | |
| 262 | /* Scene modes. */ |
| 263 | |
Ari Hausman-Cohen | dde8017 | 2016-07-01 16:20:36 -0700 | [diff] [blame] | 264 | res = info.update(ANDROID_CONTROL_AVAILABLE_SCENE_MODES, |
| 265 | mSceneModes.data(), mSceneModes.size()); |
| 266 | if (res != android::OK) { |
| 267 | return res; |
| 268 | } |
Ari Hausman-Cohen | 900c1e3 | 2016-06-20 16:52:41 -0700 | [diff] [blame] | 269 | |
| 270 | // A 3-tuple of AE, AWB, AF overrides for each scene mode. |
| 271 | // Ignored for DISABLED, FACE_PRIORITY and FACE_PRIORITY_LOW_LIGHT. |
| 272 | uint8_t scene_mode_overrides[] = { |
| 273 | /*SCENE_MODE_DISABLED*/ /*AE*/0, /*AW*/0, /*AF*/0}; |
Ari Hausman-Cohen | dde8017 | 2016-07-01 16:20:36 -0700 | [diff] [blame] | 274 | res = info.update(ANDROID_CONTROL_SCENE_MODE_OVERRIDES, |
| 275 | scene_mode_overrides, ARRAY_SIZE(scene_mode_overrides)); |
| 276 | if (res != android::OK) { |
| 277 | return res; |
| 278 | } |
Ari Hausman-Cohen | 900c1e3 | 2016-06-20 16:52:41 -0700 | [diff] [blame] | 279 | |
| 280 | /* Top level 3A/Scenes switch. */ |
| 281 | |
Ari Hausman-Cohen | dde8017 | 2016-07-01 16:20:36 -0700 | [diff] [blame] | 282 | res = info.update(ANDROID_CONTROL_AVAILABLE_MODES, |
| 283 | mControlModes.data(), mControlModes.size()); |
| 284 | if (res != android::OK) { |
| 285 | return res; |
| 286 | } |
Ari Hausman-Cohen | 900c1e3 | 2016-06-20 16:52:41 -0700 | [diff] [blame] | 287 | |
| 288 | /* Other android.control configuration. */ |
| 289 | |
Ari Hausman-Cohen | dde8017 | 2016-07-01 16:20:36 -0700 | [diff] [blame] | 290 | res = info.update(ANDROID_CONTROL_AVAILABLE_VIDEO_STABILIZATION_MODES, |
| 291 | mVideoStabilizationModes.data(), |
| 292 | mVideoStabilizationModes.size()); |
| 293 | if (res != android::OK) { |
| 294 | return res; |
| 295 | } |
Ari Hausman-Cohen | 900c1e3 | 2016-06-20 16:52:41 -0700 | [diff] [blame] | 296 | |
Ari Hausman-Cohen | dde8017 | 2016-07-01 16:20:36 -0700 | [diff] [blame] | 297 | res = info.update(ANDROID_CONTROL_AVAILABLE_EFFECTS, |
| 298 | mEffects.data(), mEffects.size()); |
| 299 | if (res != android::OK) { |
| 300 | return res; |
| 301 | } |
Ari Hausman-Cohen | 900c1e3 | 2016-06-20 16:52:41 -0700 | [diff] [blame] | 302 | |
| 303 | // AVAILABLE_HIGH_SPEED_VIDEO_CONFIGURATIONS only necessary |
| 304 | // for devices supporting CONSTRAINED_HIGH_SPEED_VIDEO, |
| 305 | // which this HAL doesn't support. |
| 306 | |
| 307 | // POST_RAW_SENSITIVITY_BOOST_RANGE only necessary |
| 308 | // for devices supporting RAW format outputs. |
| 309 | |
| 310 | /* android.edge. */ |
| 311 | |
| 312 | // Not sure if V4L2 does or doesn't do this, but HAL documentation says |
| 313 | // all devices must support FAST, and FAST can be equivalent to OFF, so |
| 314 | // either way it's fine to list. |
| 315 | uint8_t avail_edge_modes[] = { |
| 316 | ANDROID_EDGE_MODE_FAST}; |
Ari Hausman-Cohen | dde8017 | 2016-07-01 16:20:36 -0700 | [diff] [blame] | 317 | res = info.update(ANDROID_EDGE_AVAILABLE_EDGE_MODES, |
| 318 | avail_edge_modes, ARRAY_SIZE(avail_edge_modes)); |
| 319 | if (res != android::OK) { |
| 320 | return res; |
| 321 | } |
Ari Hausman-Cohen | 900c1e3 | 2016-06-20 16:52:41 -0700 | [diff] [blame] | 322 | |
| 323 | /* android.flash. */ |
| 324 | |
Ari Hausman-Cohen | dde8017 | 2016-07-01 16:20:36 -0700 | [diff] [blame] | 325 | res = info.update(ANDROID_FLASH_INFO_AVAILABLE, |
| 326 | &mFlashAvailable, 1); |
| 327 | if (res != android::OK) { |
| 328 | return res; |
| 329 | } |
Ari Hausman-Cohen | 900c1e3 | 2016-06-20 16:52:41 -0700 | [diff] [blame] | 330 | |
| 331 | // info.chargeDuration, color.Temperature, maxEnergy marked FUTURE. |
| 332 | |
| 333 | /* android.hotPixel. */ |
| 334 | |
| 335 | // No known V4L2 hot pixel correction. But it might be happening, |
| 336 | // so we report FAST/HIGH_QUALITY. |
| 337 | uint8_t avail_hot_pixel_modes[] = { |
| 338 | ANDROID_HOT_PIXEL_MODE_FAST, |
| 339 | ANDROID_HOT_PIXEL_MODE_HIGH_QUALITY}; |
Ari Hausman-Cohen | dde8017 | 2016-07-01 16:20:36 -0700 | [diff] [blame] | 340 | res = info.update(ANDROID_HOT_PIXEL_AVAILABLE_HOT_PIXEL_MODES, |
| 341 | avail_hot_pixel_modes, ARRAY_SIZE(avail_hot_pixel_modes)); |
| 342 | if (res != android::OK) { |
| 343 | return res; |
| 344 | } |
Ari Hausman-Cohen | 900c1e3 | 2016-06-20 16:52:41 -0700 | [diff] [blame] | 345 | |
| 346 | /* android.jpeg. */ |
| 347 | |
| 348 | // For now, no thumbnails available (only [0,0], the "no thumbnail" size). |
| 349 | // TODO(b/29580107): Could end up with a mismatch between request & result, |
Ari Hausman-Cohen | 4992584 | 2016-06-21 14:07:58 -0700 | [diff] [blame] | 350 | // since V4L2 doesn't actually allow for thumbnail size control. |
Ari Hausman-Cohen | 900c1e3 | 2016-06-20 16:52:41 -0700 | [diff] [blame] | 351 | int32_t thumbnail_sizes[] = { |
| 352 | 0, 0}; |
Ari Hausman-Cohen | dde8017 | 2016-07-01 16:20:36 -0700 | [diff] [blame] | 353 | res = info.update(ANDROID_JPEG_AVAILABLE_THUMBNAIL_SIZES, |
| 354 | thumbnail_sizes, ARRAY_SIZE(thumbnail_sizes)); |
| 355 | if (res != android::OK) { |
| 356 | return res; |
| 357 | } |
Ari Hausman-Cohen | 900c1e3 | 2016-06-20 16:52:41 -0700 | [diff] [blame] | 358 | |
Ari Hausman-Cohen | 3eece6f | 2016-07-21 11:08:24 -0700 | [diff] [blame] | 359 | // V4L2 doesn't support querying this, |
| 360 | // so instead use a constant (defined in V4L2Gralloc.h). |
| 361 | int32_t max_jpeg_size = V4L2_MAX_JPEG_SIZE; |
Ari Hausman-Cohen | dde8017 | 2016-07-01 16:20:36 -0700 | [diff] [blame] | 362 | res = info.update(ANDROID_JPEG_MAX_SIZE, |
| 363 | &max_jpeg_size, 1); |
| 364 | if (res != android::OK) { |
| 365 | return res; |
| 366 | } |
Ari Hausman-Cohen | 900c1e3 | 2016-06-20 16:52:41 -0700 | [diff] [blame] | 367 | |
| 368 | /* android.lens. */ |
| 369 | |
| 370 | /* Misc. lens control. */ |
| 371 | |
Ari Hausman-Cohen | dde8017 | 2016-07-01 16:20:36 -0700 | [diff] [blame] | 372 | res = info.update(ANDROID_LENS_INFO_AVAILABLE_APERTURES, |
| 373 | &mAperture, 1); |
| 374 | if (res != android::OK) { |
| 375 | return res; |
| 376 | } |
Ari Hausman-Cohen | 900c1e3 | 2016-06-20 16:52:41 -0700 | [diff] [blame] | 377 | |
Ari Hausman-Cohen | dde8017 | 2016-07-01 16:20:36 -0700 | [diff] [blame] | 378 | res = info.update(ANDROID_LENS_INFO_AVAILABLE_FILTER_DENSITIES, |
| 379 | &mFilterDensity, 1); |
| 380 | if (res != android::OK) { |
| 381 | return res; |
| 382 | } |
Ari Hausman-Cohen | 900c1e3 | 2016-06-20 16:52:41 -0700 | [diff] [blame] | 383 | |
Ari Hausman-Cohen | dde8017 | 2016-07-01 16:20:36 -0700 | [diff] [blame] | 384 | res = info.update(ANDROID_LENS_INFO_AVAILABLE_OPTICAL_STABILIZATION, |
| 385 | mOpticalStabilizationModes.data(), |
| 386 | mOpticalStabilizationModes.size()); |
| 387 | if (res != android::OK) { |
| 388 | return res; |
| 389 | } |
Ari Hausman-Cohen | 900c1e3 | 2016-06-20 16:52:41 -0700 | [diff] [blame] | 390 | |
| 391 | // No known V4L2 shading map info. |
| 392 | int32_t shading_map_size[] = {1, 1}; |
Ari Hausman-Cohen | dde8017 | 2016-07-01 16:20:36 -0700 | [diff] [blame] | 393 | res = info.update(ANDROID_LENS_INFO_SHADING_MAP_SIZE, |
| 394 | shading_map_size, ARRAY_SIZE(shading_map_size)); |
| 395 | if (res != android::OK) { |
| 396 | return res; |
| 397 | } |
Ari Hausman-Cohen | 900c1e3 | 2016-06-20 16:52:41 -0700 | [diff] [blame] | 398 | |
| 399 | // All V4L2 devices are considered to be external facing. |
| 400 | uint8_t facing = ANDROID_LENS_FACING_EXTERNAL; |
Ari Hausman-Cohen | dde8017 | 2016-07-01 16:20:36 -0700 | [diff] [blame] | 401 | res = info.update(ANDROID_LENS_FACING, &facing, 1); |
| 402 | if (res != android::OK) { |
| 403 | return res; |
| 404 | } |
Ari Hausman-Cohen | 900c1e3 | 2016-06-20 16:52:41 -0700 | [diff] [blame] | 405 | |
| 406 | /* Zoom/Focus. */ |
| 407 | |
| 408 | // No way to actually get the focal length in V4L2, but it's a required key, |
Ari Hausman-Cohen | 4992584 | 2016-06-21 14:07:58 -0700 | [diff] [blame] | 409 | // so we just fake it. |
Ari Hausman-Cohen | dde8017 | 2016-07-01 16:20:36 -0700 | [diff] [blame] | 410 | res = info.update(ANDROID_LENS_INFO_AVAILABLE_FOCAL_LENGTHS, |
| 411 | &mFocalLength, 1); |
| 412 | if (res != android::OK) { |
| 413 | return res; |
| 414 | } |
Ari Hausman-Cohen | 900c1e3 | 2016-06-20 16:52:41 -0700 | [diff] [blame] | 415 | |
| 416 | // V4L2 focal units do not correspond to a particular physical unit. |
| 417 | uint8_t focus_calibration = |
| 418 | ANDROID_LENS_INFO_FOCUS_DISTANCE_CALIBRATION_UNCALIBRATED; |
Ari Hausman-Cohen | dde8017 | 2016-07-01 16:20:36 -0700 | [diff] [blame] | 419 | res = info.update(ANDROID_LENS_INFO_FOCUS_DISTANCE_CALIBRATION, |
| 420 | &focus_calibration, 1); |
| 421 | if (res != android::OK) { |
| 422 | return res; |
| 423 | } |
Ari Hausman-Cohen | 900c1e3 | 2016-06-20 16:52:41 -0700 | [diff] [blame] | 424 | |
| 425 | // info.hyperfocalDistance not required for UNCALIBRATED. |
| 426 | |
Ari Hausman-Cohen | dde8017 | 2016-07-01 16:20:36 -0700 | [diff] [blame] | 427 | res = info.update(ANDROID_LENS_INFO_MINIMUM_FOCUS_DISTANCE, |
| 428 | &mFocusDistance, 1); |
| 429 | if (res != android::OK) { |
| 430 | return res; |
| 431 | } |
Ari Hausman-Cohen | 900c1e3 | 2016-06-20 16:52:41 -0700 | [diff] [blame] | 432 | |
| 433 | /* Depth. */ |
| 434 | |
| 435 | // DEPTH capability not supported by this HAL. Not implemented: |
Ari Hausman-Cohen | 4992584 | 2016-06-21 14:07:58 -0700 | [diff] [blame] | 436 | // poseRotation |
| 437 | // poseTranslation |
| 438 | // intrinsicCalibration |
| 439 | // radialDistortion |
Ari Hausman-Cohen | 900c1e3 | 2016-06-20 16:52:41 -0700 | [diff] [blame] | 440 | |
| 441 | /* anroid.noise. */ |
| 442 | |
| 443 | // Unable to control noise reduction in V4L2 devices, |
| 444 | // but FAST is allowed to be the same as OFF. |
Ari Hausman-Cohen | 4992584 | 2016-06-21 14:07:58 -0700 | [diff] [blame] | 445 | uint8_t avail_noise_reduction_modes[] = {ANDROID_NOISE_REDUCTION_MODE_FAST}; |
Ari Hausman-Cohen | dde8017 | 2016-07-01 16:20:36 -0700 | [diff] [blame] | 446 | res = info.update(ANDROID_NOISE_REDUCTION_AVAILABLE_NOISE_REDUCTION_MODES, |
| 447 | avail_noise_reduction_modes, |
| 448 | ARRAY_SIZE(avail_noise_reduction_modes)); |
| 449 | if (res != android::OK) { |
| 450 | return res; |
| 451 | } |
Ari Hausman-Cohen | 900c1e3 | 2016-06-20 16:52:41 -0700 | [diff] [blame] | 452 | |
| 453 | /* android.request. */ |
| 454 | |
Ari Hausman-Cohen | 900c1e3 | 2016-06-20 16:52:41 -0700 | [diff] [blame] | 455 | int32_t max_num_output_streams[] = { |
Ari Hausman-Cohen | 72fddb3 | 2016-06-30 16:53:31 -0700 | [diff] [blame] | 456 | mMaxRawOutputStreams, mMaxYuvOutputStreams, mMaxJpegOutputStreams}; |
Ari Hausman-Cohen | dde8017 | 2016-07-01 16:20:36 -0700 | [diff] [blame] | 457 | res = info.update(ANDROID_REQUEST_MAX_NUM_OUTPUT_STREAMS, |
| 458 | max_num_output_streams, ARRAY_SIZE(max_num_output_streams)); |
| 459 | if (res != android::OK) { |
| 460 | return res; |
| 461 | } |
Ari Hausman-Cohen | 900c1e3 | 2016-06-20 16:52:41 -0700 | [diff] [blame] | 462 | |
Ari Hausman-Cohen | 72fddb3 | 2016-06-30 16:53:31 -0700 | [diff] [blame] | 463 | res = info.update(ANDROID_REQUEST_MAX_NUM_INPUT_STREAMS, |
| 464 | &mMaxInputStreams, 1); |
| 465 | if (res != android::OK) { |
| 466 | return res; |
| 467 | } |
Ari Hausman-Cohen | 900c1e3 | 2016-06-20 16:52:41 -0700 | [diff] [blame] | 468 | |
| 469 | // No way to know for V4L2, so fake with max allowable latency. |
| 470 | // Doesn't mean much without per-frame controls. |
| 471 | uint8_t pipeline_max_depth = 4; |
Ari Hausman-Cohen | dde8017 | 2016-07-01 16:20:36 -0700 | [diff] [blame] | 472 | res = info.update(ANDROID_REQUEST_PIPELINE_MAX_DEPTH, |
| 473 | &pipeline_max_depth, 1); |
| 474 | if (res != android::OK) { |
| 475 | return res; |
| 476 | } |
Ari Hausman-Cohen | 900c1e3 | 2016-06-20 16:52:41 -0700 | [diff] [blame] | 477 | |
| 478 | // Partial results not supported; partialResultCount defaults to 1. |
| 479 | |
| 480 | // Available capabilities & keys queried at very end of this method. |
| 481 | |
| 482 | /* android.scaler. */ |
| 483 | |
| 484 | /* Cropping. */ |
| 485 | |
Ari Hausman-Cohen | dde8017 | 2016-07-01 16:20:36 -0700 | [diff] [blame] | 486 | res = info.update(ANDROID_SCALER_AVAILABLE_MAX_DIGITAL_ZOOM, |
| 487 | &mMaxZoom, 1); |
| 488 | if (res != android::OK) { |
| 489 | return res; |
| 490 | } |
Ari Hausman-Cohen | 900c1e3 | 2016-06-20 16:52:41 -0700 | [diff] [blame] | 491 | |
Ari Hausman-Cohen | dde8017 | 2016-07-01 16:20:36 -0700 | [diff] [blame] | 492 | res = info.update(ANDROID_SCALER_CROPPING_TYPE, &mCropType, 1); |
| 493 | if (res != android::OK) { |
| 494 | return res; |
| 495 | } |
Ari Hausman-Cohen | 900c1e3 | 2016-06-20 16:52:41 -0700 | [diff] [blame] | 496 | |
| 497 | /* Streams. */ |
| 498 | |
| 499 | // availableInputOutputFormatsMap only required for reprocessing capability. |
| 500 | |
Ari Hausman-Cohen | 4992584 | 2016-06-21 14:07:58 -0700 | [diff] [blame] | 501 | // Flatten mStreamConfigs. |
Ari Hausman-Cohen | dde8017 | 2016-07-01 16:20:36 -0700 | [diff] [blame] | 502 | res = info.update(ANDROID_SCALER_AVAILABLE_STREAM_CONFIGURATIONS, |
| 503 | mStreamConfigs.data(), |
| 504 | mStreamConfigs.total_num_elements()); |
| 505 | if (res != android::OK) { |
| 506 | return res; |
| 507 | } |
Ari Hausman-Cohen | 900c1e3 | 2016-06-20 16:52:41 -0700 | [diff] [blame] | 508 | |
Ari Hausman-Cohen | 4992584 | 2016-06-21 14:07:58 -0700 | [diff] [blame] | 509 | // Flatten mMinFrameDurations. |
Ari Hausman-Cohen | dde8017 | 2016-07-01 16:20:36 -0700 | [diff] [blame] | 510 | res = info.update(ANDROID_SCALER_AVAILABLE_MIN_FRAME_DURATIONS, |
| 511 | mMinFrameDurations.data(), |
| 512 | mMinFrameDurations.total_num_elements()); |
| 513 | if (res != android::OK) { |
| 514 | return res; |
| 515 | } |
Ari Hausman-Cohen | 900c1e3 | 2016-06-20 16:52:41 -0700 | [diff] [blame] | 516 | |
Ari Hausman-Cohen | 4992584 | 2016-06-21 14:07:58 -0700 | [diff] [blame] | 517 | // Flatten mStallDurations. |
Ari Hausman-Cohen | dde8017 | 2016-07-01 16:20:36 -0700 | [diff] [blame] | 518 | res = info.update(ANDROID_SCALER_AVAILABLE_STALL_DURATIONS, |
| 519 | mStallDurations.data(), |
| 520 | mStallDurations.total_num_elements()); |
| 521 | if (res != android::OK) { |
| 522 | return res; |
| 523 | } |
Ari Hausman-Cohen | 900c1e3 | 2016-06-20 16:52:41 -0700 | [diff] [blame] | 524 | |
| 525 | /* android.sensor. */ |
| 526 | |
| 527 | /* Sizes. */ |
| 528 | |
Ari Hausman-Cohen | dde8017 | 2016-07-01 16:20:36 -0700 | [diff] [blame] | 529 | res = info.update(ANDROID_SENSOR_INFO_PIXEL_ARRAY_SIZE, |
| 530 | mPixelArraySize.data(), mPixelArraySize.size()); |
| 531 | if (res != android::OK) { |
| 532 | return res; |
| 533 | } |
Ari Hausman-Cohen | 900c1e3 | 2016-06-20 16:52:41 -0700 | [diff] [blame] | 534 | // No V4L2 way to differentiate active vs. inactive parts of the rectangle. |
Ari Hausman-Cohen | dde8017 | 2016-07-01 16:20:36 -0700 | [diff] [blame] | 535 | res = info.update(ANDROID_SENSOR_INFO_ACTIVE_ARRAY_SIZE, |
| 536 | mPixelArraySize.data(), mPixelArraySize.size()); |
| 537 | if (res != android::OK) { |
| 538 | return res; |
| 539 | } |
Ari Hausman-Cohen | 900c1e3 | 2016-06-20 16:52:41 -0700 | [diff] [blame] | 540 | |
Ari Hausman-Cohen | dde8017 | 2016-07-01 16:20:36 -0700 | [diff] [blame] | 541 | res = info.update(ANDROID_SENSOR_INFO_PHYSICAL_SIZE, |
| 542 | mPhysicalSize.data(), mPhysicalSize.size()); |
| 543 | if (res != android::OK) { |
| 544 | return res; |
| 545 | } |
Ari Hausman-Cohen | 900c1e3 | 2016-06-20 16:52:41 -0700 | [diff] [blame] | 546 | |
| 547 | /* Misc sensor information. */ |
| 548 | |
Ari Hausman-Cohen | dde8017 | 2016-07-01 16:20:36 -0700 | [diff] [blame] | 549 | res = info.update(ANDROID_SENSOR_INFO_MAX_FRAME_DURATION, |
| 550 | &mMaxFrameDuration, 1); |
| 551 | if (res != android::OK) { |
| 552 | return res; |
| 553 | } |
Ari Hausman-Cohen | 900c1e3 | 2016-06-20 16:52:41 -0700 | [diff] [blame] | 554 | |
| 555 | // HAL uses BOOTTIME timestamps. |
| 556 | // TODO(b/29457051): make sure timestamps are consistent throughout the HAL. |
| 557 | uint8_t timestamp_source = ANDROID_SENSOR_INFO_TIMESTAMP_SOURCE_UNKNOWN; |
Ari Hausman-Cohen | dde8017 | 2016-07-01 16:20:36 -0700 | [diff] [blame] | 558 | res = info.update(ANDROID_SENSOR_INFO_TIMESTAMP_SOURCE, |
| 559 | ×tamp_source, 1); |
| 560 | if (res != android::OK) { |
| 561 | return res; |
| 562 | } |
Ari Hausman-Cohen | 900c1e3 | 2016-06-20 16:52:41 -0700 | [diff] [blame] | 563 | |
| 564 | // As in initDeviceInfo, no way to actually get orientation. |
Ari Hausman-Cohen | dde8017 | 2016-07-01 16:20:36 -0700 | [diff] [blame] | 565 | res = info.update(ANDROID_SENSOR_ORIENTATION, &mOrientation, 1); |
| 566 | if (res != android::OK) { |
| 567 | return res; |
| 568 | } |
Ari Hausman-Cohen | 900c1e3 | 2016-06-20 16:52:41 -0700 | [diff] [blame] | 569 | |
| 570 | // availableTestPatternModes just defaults to OFF, which is fine. |
| 571 | |
| 572 | // info.exposureTimeRange, info.sensitivityRange: |
Ari Hausman-Cohen | 4992584 | 2016-06-21 14:07:58 -0700 | [diff] [blame] | 573 | // exposure/sensitivity manual control not supported. |
| 574 | // Could query V4L2_CID_ISO_SENSITIVITY to support sensitivity if desired. |
Ari Hausman-Cohen | 900c1e3 | 2016-06-20 16:52:41 -0700 | [diff] [blame] | 575 | |
| 576 | // info.whiteLevel, info.lensShadingApplied, |
Ari Hausman-Cohen | 4992584 | 2016-06-21 14:07:58 -0700 | [diff] [blame] | 577 | // info.preCorrectionPixelArraySize, referenceIlluminant1/2, |
| 578 | // calibrationTransform1/2, colorTransform1/2, forwardMatrix1/2, |
| 579 | // blackLevelPattern, profileHueSatMapDimensions |
| 580 | // all only necessary for RAW. |
Ari Hausman-Cohen | 900c1e3 | 2016-06-20 16:52:41 -0700 | [diff] [blame] | 581 | |
| 582 | // baseGainFactor marked FUTURE. |
| 583 | |
| 584 | // maxAnalogSensitivity optional for LIMITED device. |
| 585 | |
| 586 | // opticalBlackRegions: No known way to get in V4L2, but not necessary. |
| 587 | |
| 588 | // opaqueRawSize not necessary since RAW_OPAQUE format not supported. |
| 589 | |
Ari Hausman-Cohen | 4992584 | 2016-06-21 14:07:58 -0700 | [diff] [blame] | 590 | /* android.shading */ |
| 591 | |
| 592 | // No known V4L2 lens shading. But it might be happening, |
| 593 | // so we report FAST/HIGH_QUALITY. |
| 594 | uint8_t avail_shading_modes[] = { |
| 595 | ANDROID_SHADING_MODE_FAST, |
| 596 | ANDROID_SHADING_MODE_HIGH_QUALITY}; |
Ari Hausman-Cohen | dde8017 | 2016-07-01 16:20:36 -0700 | [diff] [blame] | 597 | res = info.update(ANDROID_SHADING_AVAILABLE_MODES, |
| 598 | avail_shading_modes, ARRAY_SIZE(avail_shading_modes)); |
| 599 | if (res != android::OK) { |
| 600 | return res; |
| 601 | } |
Ari Hausman-Cohen | 4992584 | 2016-06-21 14:07:58 -0700 | [diff] [blame] | 602 | |
Ari Hausman-Cohen | 900c1e3 | 2016-06-20 16:52:41 -0700 | [diff] [blame] | 603 | /* android.statistics */ |
| 604 | |
| 605 | // Face detection not supported. |
| 606 | uint8_t avail_face_detect_modes[] = { |
| 607 | ANDROID_STATISTICS_FACE_DETECT_MODE_OFF}; |
Ari Hausman-Cohen | dde8017 | 2016-07-01 16:20:36 -0700 | [diff] [blame] | 608 | res = info.update(ANDROID_STATISTICS_INFO_AVAILABLE_FACE_DETECT_MODES, |
| 609 | avail_face_detect_modes, |
| 610 | ARRAY_SIZE(avail_face_detect_modes)); |
| 611 | if (res != android::OK) { |
| 612 | return res; |
| 613 | } |
Ari Hausman-Cohen | 900c1e3 | 2016-06-20 16:52:41 -0700 | [diff] [blame] | 614 | |
| 615 | int32_t max_face_count = 0; |
Ari Hausman-Cohen | dde8017 | 2016-07-01 16:20:36 -0700 | [diff] [blame] | 616 | res = info.update(ANDROID_STATISTICS_INFO_MAX_FACE_COUNT, |
| 617 | &max_face_count, 1); |
| 618 | if (res != android::OK) { |
| 619 | return res; |
| 620 | } |
Ari Hausman-Cohen | 900c1e3 | 2016-06-20 16:52:41 -0700 | [diff] [blame] | 621 | |
| 622 | // info.histogramBucketCount, info.maxHistogramCount, |
Ari Hausman-Cohen | 4992584 | 2016-06-21 14:07:58 -0700 | [diff] [blame] | 623 | // info.maxSharpnessMapValue, info.sharpnessMapSizemarked FUTURE. |
Ari Hausman-Cohen | 900c1e3 | 2016-06-20 16:52:41 -0700 | [diff] [blame] | 624 | |
| 625 | // ON only needs to be supported for RAW capable devices. |
| 626 | uint8_t avail_hot_pixel_map_modes[] = { |
| 627 | ANDROID_STATISTICS_HOT_PIXEL_MAP_MODE_OFF}; |
Ari Hausman-Cohen | dde8017 | 2016-07-01 16:20:36 -0700 | [diff] [blame] | 628 | res = info.update(ANDROID_STATISTICS_INFO_AVAILABLE_HOT_PIXEL_MAP_MODES, |
| 629 | avail_hot_pixel_map_modes, |
| 630 | ARRAY_SIZE(avail_hot_pixel_map_modes)); |
| 631 | if (res != android::OK) { |
| 632 | return res; |
| 633 | } |
Ari Hausman-Cohen | 900c1e3 | 2016-06-20 16:52:41 -0700 | [diff] [blame] | 634 | |
| 635 | // ON only needs to be supported for RAW capable devices. |
| 636 | uint8_t avail_lens_shading_map_modes[] = { |
| 637 | ANDROID_STATISTICS_LENS_SHADING_MAP_MODE_OFF}; |
Ari Hausman-Cohen | dde8017 | 2016-07-01 16:20:36 -0700 | [diff] [blame] | 638 | res = info.update(ANDROID_STATISTICS_INFO_AVAILABLE_LENS_SHADING_MAP_MODES, |
| 639 | avail_lens_shading_map_modes, |
| 640 | ARRAY_SIZE(avail_lens_shading_map_modes)); |
| 641 | if (res != android::OK) { |
| 642 | return res; |
| 643 | } |
Ari Hausman-Cohen | 900c1e3 | 2016-06-20 16:52:41 -0700 | [diff] [blame] | 644 | |
| 645 | /* android.tonemap. */ |
| 646 | |
| 647 | // tonemapping only required for MANUAL_POST_PROCESSING capability. |
| 648 | |
| 649 | /* android.led. */ |
| 650 | |
Ari Hausman-Cohen | 4992584 | 2016-06-21 14:07:58 -0700 | [diff] [blame] | 651 | // May or may not have LEDs available. |
| 652 | if (!mLeds.empty()) { |
Ari Hausman-Cohen | dde8017 | 2016-07-01 16:20:36 -0700 | [diff] [blame] | 653 | res = info.update(ANDROID_LED_AVAILABLE_LEDS, mLeds.data(), mLeds.size()); |
| 654 | if (res != android::OK) { |
| 655 | return res; |
| 656 | } |
Ari Hausman-Cohen | 4992584 | 2016-06-21 14:07:58 -0700 | [diff] [blame] | 657 | } |
Ari Hausman-Cohen | 900c1e3 | 2016-06-20 16:52:41 -0700 | [diff] [blame] | 658 | |
| 659 | /* android.sync. */ |
| 660 | |
| 661 | // "LIMITED devices are strongly encouraged to use a non-negative value. |
Ari Hausman-Cohen | 4992584 | 2016-06-21 14:07:58 -0700 | [diff] [blame] | 662 | // If UNKNOWN is used here then app developers do not have a way to know |
| 663 | // when sensor settings have been applied." - Unfortunately, V4L2 doesn't |
| 664 | // really help here either. Could even be that adjusting settings mid-stream |
| 665 | // blocks in V4L2, and should be avoided. |
Ari Hausman-Cohen | 900c1e3 | 2016-06-20 16:52:41 -0700 | [diff] [blame] | 666 | int32_t max_latency = ANDROID_SYNC_MAX_LATENCY_UNKNOWN; |
Ari Hausman-Cohen | dde8017 | 2016-07-01 16:20:36 -0700 | [diff] [blame] | 667 | res = info.update(ANDROID_SYNC_MAX_LATENCY, |
| 668 | &max_latency, 1); |
| 669 | if (res != android::OK) { |
| 670 | return res; |
| 671 | } |
Ari Hausman-Cohen | 900c1e3 | 2016-06-20 16:52:41 -0700 | [diff] [blame] | 672 | |
| 673 | /* android.reprocess. */ |
| 674 | |
| 675 | // REPROCESSING not supported by this HAL. |
| 676 | |
| 677 | /* android.depth. */ |
| 678 | |
| 679 | // DEPTH not supported by this HAL. |
| 680 | |
| 681 | /* Capabilities and android.info. */ |
| 682 | |
| 683 | uint8_t hw_level = ANDROID_INFO_SUPPORTED_HARDWARE_LEVEL_LIMITED; |
Ari Hausman-Cohen | dde8017 | 2016-07-01 16:20:36 -0700 | [diff] [blame] | 684 | res = info.update(ANDROID_INFO_SUPPORTED_HARDWARE_LEVEL, |
| 685 | &hw_level, 1); |
| 686 | if (res != android::OK) { |
| 687 | return res; |
| 688 | } |
Ari Hausman-Cohen | 900c1e3 | 2016-06-20 16:52:41 -0700 | [diff] [blame] | 689 | |
| 690 | uint8_t capabilities[] = { |
| 691 | ANDROID_REQUEST_AVAILABLE_CAPABILITIES_BACKWARD_COMPATIBLE}; |
Ari Hausman-Cohen | dde8017 | 2016-07-01 16:20:36 -0700 | [diff] [blame] | 692 | res = info.update(ANDROID_REQUEST_AVAILABLE_CAPABILITIES, |
| 693 | capabilities, ARRAY_SIZE(capabilities)); |
| 694 | if (res != android::OK) { |
| 695 | return res; |
| 696 | } |
Ari Hausman-Cohen | 900c1e3 | 2016-06-20 16:52:41 -0700 | [diff] [blame] | 697 | |
Ari Hausman-Cohen | 4992584 | 2016-06-21 14:07:58 -0700 | [diff] [blame] | 698 | // Scan a default request template for included request keys. |
| 699 | if (!mTemplatesInitialized) { |
| 700 | res = initTemplates(); |
| 701 | if (res) { |
| 702 | return res; |
| 703 | } |
| 704 | } |
Ari Hausman-Cohen | dde8017 | 2016-07-01 16:20:36 -0700 | [diff] [blame] | 705 | const camera_metadata_t* preview_request = nullptr; |
Ari Hausman-Cohen | 4992584 | 2016-06-21 14:07:58 -0700 | [diff] [blame] | 706 | // Search templates from the beginning for a supported one. |
| 707 | for (uint8_t template_id = 1; template_id < CAMERA3_TEMPLATE_COUNT; |
| 708 | ++template_id) { |
| 709 | preview_request = constructDefaultRequestSettings(template_id); |
| 710 | if (preview_request != nullptr) { |
| 711 | break; |
| 712 | } |
| 713 | } |
| 714 | if (preview_request == nullptr) { |
| 715 | HAL_LOGE("No valid templates, can't get request keys."); |
| 716 | return -ENODEV; |
| 717 | } |
Ari Hausman-Cohen | dde8017 | 2016-07-01 16:20:36 -0700 | [diff] [blame] | 718 | std::vector<int32_t> avail_request_keys = getMetadataKeys(preview_request); |
| 719 | res = info.update(ANDROID_REQUEST_AVAILABLE_REQUEST_KEYS, |
| 720 | avail_request_keys.data(), avail_request_keys.size()); |
| 721 | if (res != android::OK) { |
| 722 | return res; |
Ari Hausman-Cohen | 4992584 | 2016-06-21 14:07:58 -0700 | [diff] [blame] | 723 | } |
Ari Hausman-Cohen | 900c1e3 | 2016-06-20 16:52:41 -0700 | [diff] [blame] | 724 | |
Ari Hausman-Cohen | 4992584 | 2016-06-21 14:07:58 -0700 | [diff] [blame] | 725 | // Result keys will be duplicated from the request, plus a few extras. |
Ari Hausman-Cohen | 24e541c | 2016-07-21 11:20:30 -0700 | [diff] [blame] | 726 | // TODO(b/30035628): additonal available result keys. |
Ari Hausman-Cohen | 4992584 | 2016-06-21 14:07:58 -0700 | [diff] [blame] | 727 | std::vector<int32_t> avail_result_keys(avail_request_keys); |
Ari Hausman-Cohen | dde8017 | 2016-07-01 16:20:36 -0700 | [diff] [blame] | 728 | res = info.update(ANDROID_REQUEST_AVAILABLE_RESULT_KEYS, |
| 729 | avail_result_keys.data(), avail_result_keys.size()); |
| 730 | if (res != android::OK) { |
| 731 | return res; |
| 732 | } |
Ari Hausman-Cohen | 900c1e3 | 2016-06-20 16:52:41 -0700 | [diff] [blame] | 733 | |
| 734 | // Last thing, once all the available characteristics have been added. |
Ari Hausman-Cohen | dde8017 | 2016-07-01 16:20:36 -0700 | [diff] [blame] | 735 | const camera_metadata_t* static_characteristics = info.getAndLock(); |
| 736 | std::vector<int32_t> avail_characteristics_keys = |
| 737 | getMetadataKeys(static_characteristics); |
| 738 | res = info.unlock(static_characteristics); |
| 739 | if (res != android::OK) { |
| 740 | return res; |
| 741 | } |
| 742 | avail_characteristics_keys.push_back( |
| 743 | ANDROID_REQUEST_AVAILABLE_CHARACTERISTICS_KEYS); |
| 744 | res = info.update(ANDROID_REQUEST_AVAILABLE_CHARACTERISTICS_KEYS, |
| 745 | avail_characteristics_keys.data(), |
| 746 | avail_characteristics_keys.size()); |
| 747 | if (res != android::OK) { |
| 748 | return res; |
| 749 | } |
Ari Hausman-Cohen | 900c1e3 | 2016-06-20 16:52:41 -0700 | [diff] [blame] | 750 | |
| 751 | *out = info.release(); |
| 752 | return 0; |
Ari Hausman-Cohen | 7344215 | 2016-06-08 15:50:49 -0700 | [diff] [blame] | 753 | } |
| 754 | |
| 755 | void V4L2Camera::initDeviceInfo(camera_info_t* info) { |
| 756 | HAL_LOG_ENTER(); |
| 757 | |
| 758 | // For now, just constants. |
| 759 | info->facing = CAMERA_FACING_EXTERNAL; |
Ari Hausman-Cohen | 4992584 | 2016-06-21 14:07:58 -0700 | [diff] [blame] | 760 | info->orientation = mOrientation; |
Ari Hausman-Cohen | 7344215 | 2016-06-08 15:50:49 -0700 | [diff] [blame] | 761 | info->resource_cost = 100; |
| 762 | info->conflicting_devices = nullptr; |
| 763 | info->conflicting_devices_length = 0; |
| 764 | } |
| 765 | |
| 766 | int V4L2Camera::initDevice() { |
| 767 | HAL_LOG_ENTER(); |
Ari Hausman-Cohen | 4992584 | 2016-06-21 14:07:58 -0700 | [diff] [blame] | 768 | int res; |
Ari Hausman-Cohen | 7344215 | 2016-06-08 15:50:49 -0700 | [diff] [blame] | 769 | |
Ari Hausman-Cohen | 4992584 | 2016-06-21 14:07:58 -0700 | [diff] [blame] | 770 | // Templates should be set up if they haven't already been. |
| 771 | if (!mTemplatesInitialized) { |
| 772 | res = initTemplates(); |
| 773 | if (res) { |
| 774 | return res; |
| 775 | } |
| 776 | } |
| 777 | |
| 778 | return 0; |
| 779 | } |
| 780 | |
Ari Hausman-Cohen | 24e541c | 2016-07-21 11:20:30 -0700 | [diff] [blame] | 781 | int V4L2Camera::enqueueBuffer(const camera3_stream_buffer_t* camera_buffer) { |
| 782 | HAL_LOG_ENTER(); |
| 783 | |
| 784 | // Set up a v4l2 buffer struct. |
| 785 | v4l2_buffer device_buffer; |
| 786 | memset(&device_buffer, 0, sizeof(device_buffer)); |
| 787 | device_buffer.type = mOutStreamType; |
| 788 | |
| 789 | // Use QUERYBUF to ensure our buffer/device is in good shape. |
| 790 | if (ioctlLocked(VIDIOC_QUERYBUF, &device_buffer) < 0) { |
| 791 | HAL_LOGE("QUERYBUF (%d) fails: %s", 0, strerror(errno)); |
| 792 | return -ENODEV; |
| 793 | } |
| 794 | |
| 795 | // Configure the device buffer based on the stream buffer. |
| 796 | device_buffer.memory = V4L2_MEMORY_USERPTR; |
| 797 | // TODO(b/29334616): when this is async, actually limit the number |
| 798 | // of buffers used to the known max, and set this according to the |
| 799 | // queue length. |
| 800 | device_buffer.index = 0; |
| 801 | // Lock the buffer for writing. |
Ari Hausman-Cohen | 681eaa2 | 2016-07-21 16:28:17 -0700 | [diff] [blame^] | 802 | int res = mGralloc->lock(camera_buffer, mOutStreamBytesPerLine, |
Ari Hausman-Cohen | 24e541c | 2016-07-21 11:20:30 -0700 | [diff] [blame] | 803 | &device_buffer); |
| 804 | if (res) { |
| 805 | return res; |
| 806 | } |
| 807 | if (ioctlLocked(VIDIOC_QBUF, &device_buffer) < 0) { |
| 808 | HAL_LOGE("QBUF (%d) fails: %s", 0, strerror(errno)); |
Ari Hausman-Cohen | 681eaa2 | 2016-07-21 16:28:17 -0700 | [diff] [blame^] | 809 | mGralloc->unlock(&device_buffer); |
Ari Hausman-Cohen | 24e541c | 2016-07-21 11:20:30 -0700 | [diff] [blame] | 810 | return -ENODEV; |
| 811 | } |
| 812 | |
| 813 | // Turn on the stream. |
| 814 | // TODO(b/29334616): Lock around stream on/off access, only start stream |
| 815 | // if not already on. (For now, since it's synchronous, it will always be |
| 816 | // turned off before another call to this function). |
| 817 | res = streamOn(); |
| 818 | if (res) { |
Ari Hausman-Cohen | 681eaa2 | 2016-07-21 16:28:17 -0700 | [diff] [blame^] | 819 | mGralloc->unlock(&device_buffer); |
Ari Hausman-Cohen | 24e541c | 2016-07-21 11:20:30 -0700 | [diff] [blame] | 820 | return res; |
| 821 | } |
| 822 | |
| 823 | // TODO(b/29334616): Enqueueing and dequeueing should be separate worker |
| 824 | // threads, not in the same function. |
| 825 | |
| 826 | // Dequeue the buffer. |
| 827 | v4l2_buffer result_buffer; |
| 828 | res = dequeueBuffer(&result_buffer); |
| 829 | if (res) { |
Ari Hausman-Cohen | 681eaa2 | 2016-07-21 16:28:17 -0700 | [diff] [blame^] | 830 | mGralloc->unlock(&result_buffer); |
Ari Hausman-Cohen | 24e541c | 2016-07-21 11:20:30 -0700 | [diff] [blame] | 831 | return res; |
| 832 | } |
| 833 | // Now that we're done painting the buffer, we can unlock it. |
Ari Hausman-Cohen | 681eaa2 | 2016-07-21 16:28:17 -0700 | [diff] [blame^] | 834 | res = mGralloc->unlock(&result_buffer); |
Ari Hausman-Cohen | 24e541c | 2016-07-21 11:20:30 -0700 | [diff] [blame] | 835 | if (res) { |
| 836 | return res; |
| 837 | } |
| 838 | |
| 839 | // All done, cleanup. |
| 840 | // TODO(b/29334616): Lock around stream on/off access, only stop stream if |
| 841 | // buffer queue is empty (synchronously, there's only ever 1 buffer in the |
| 842 | // queue at a time, so this is safe). |
| 843 | res = streamOff(); |
| 844 | if (res) { |
| 845 | return res; |
| 846 | } |
| 847 | |
| 848 | // Sanity check. |
| 849 | if (result_buffer.m.userptr != device_buffer.m.userptr) { |
| 850 | HAL_LOGE("Got the wrong buffer 0x%x back (expected 0x%x)", |
| 851 | result_buffer.m.userptr, device_buffer.m.userptr); |
| 852 | return -ENODEV; |
| 853 | } |
| 854 | |
| 855 | return 0; |
| 856 | } |
| 857 | |
| 858 | int V4L2Camera::dequeueBuffer(v4l2_buffer* buffer) { |
| 859 | HAL_LOG_ENTER(); |
| 860 | |
| 861 | memset(buffer, 0, sizeof(*buffer)); |
| 862 | buffer->type = mOutStreamType; |
| 863 | buffer->memory = V4L2_MEMORY_USERPTR; |
| 864 | if (ioctlLocked(VIDIOC_DQBUF, buffer) < 0) { |
| 865 | HAL_LOGE("DQBUF fails: %s", strerror(errno)); |
| 866 | return -ENODEV; |
| 867 | } |
| 868 | return 0; |
| 869 | } |
| 870 | |
| 871 | int V4L2Camera::getResultSettings(camera_metadata** metadata, |
| 872 | uint64_t* timestamp) { |
| 873 | HAL_LOG_ENTER(); |
| 874 | |
| 875 | int res; |
| 876 | android::CameraMetadata frame_metadata(*metadata); |
| 877 | |
| 878 | // TODO(b/30035628): fill in. |
| 879 | // For now just spoof the timestamp to a non-0 value and send it back. |
| 880 | int64_t frame_time = 1; |
| 881 | res = frame_metadata.update(ANDROID_SENSOR_TIMESTAMP, &frame_time, 1); |
| 882 | if (res != android::OK) { |
| 883 | return res; |
| 884 | } |
| 885 | |
| 886 | *metadata = frame_metadata.release(); |
| 887 | *timestamp = frame_time; |
| 888 | |
| 889 | return 0; |
| 890 | } |
| 891 | |
Ari Hausman-Cohen | 4992584 | 2016-06-21 14:07:58 -0700 | [diff] [blame] | 892 | int V4L2Camera::initTemplates() { |
| 893 | HAL_LOG_ENTER(); |
| 894 | int res; |
| 895 | |
| 896 | // Device characteristics need to be queried prior |
| 897 | // to template setup. |
| 898 | if (!mCharacteristicsInitialized) { |
| 899 | res = initCharacteristics(); |
| 900 | if (res) { |
| 901 | return res; |
| 902 | } |
| 903 | } |
| 904 | |
| 905 | // Note: static metadata expects all templates/requests |
| 906 | // to provide values for all supported keys. |
| 907 | |
Ari Hausman-Cohen | dde8017 | 2016-07-01 16:20:36 -0700 | [diff] [blame] | 908 | android::CameraMetadata base_metadata; |
Ari Hausman-Cohen | 4992584 | 2016-06-21 14:07:58 -0700 | [diff] [blame] | 909 | |
| 910 | // Start with defaults for all templates. |
| 911 | |
| 912 | /* android.colorCorrection. */ |
| 913 | |
| 914 | uint8_t aberration_mode = ANDROID_COLOR_CORRECTION_ABERRATION_MODE_FAST; |
Ari Hausman-Cohen | dde8017 | 2016-07-01 16:20:36 -0700 | [diff] [blame] | 915 | res = base_metadata.update(ANDROID_COLOR_CORRECTION_ABERRATION_MODE, |
| 916 | &aberration_mode, 1); |
| 917 | if (res != android::OK) { |
| 918 | return res; |
| 919 | } |
Ari Hausman-Cohen | 4992584 | 2016-06-21 14:07:58 -0700 | [diff] [blame] | 920 | |
| 921 | uint8_t color_correction_mode = ANDROID_COLOR_CORRECTION_MODE_FAST; |
Ari Hausman-Cohen | dde8017 | 2016-07-01 16:20:36 -0700 | [diff] [blame] | 922 | res = base_metadata.update(ANDROID_COLOR_CORRECTION_MODE, |
| 923 | &color_correction_mode, 1); |
| 924 | if (res != android::OK) { |
| 925 | return res; |
| 926 | } |
Ari Hausman-Cohen | 4992584 | 2016-06-21 14:07:58 -0700 | [diff] [blame] | 927 | |
| 928 | // transform and gains are for the unsupported MANUAL_POST_PROCESSING only. |
| 929 | |
| 930 | /* android.control. */ |
| 931 | |
| 932 | /* AE. */ |
| 933 | uint8_t ae_antibanding_mode = ANDROID_CONTROL_AE_ANTIBANDING_MODE_AUTO; |
Ari Hausman-Cohen | dde8017 | 2016-07-01 16:20:36 -0700 | [diff] [blame] | 934 | res = base_metadata.update(ANDROID_CONTROL_AE_ANTIBANDING_MODE, |
| 935 | &ae_antibanding_mode, 1); |
| 936 | if (res != android::OK) { |
| 937 | return res; |
| 938 | } |
Ari Hausman-Cohen | 4992584 | 2016-06-21 14:07:58 -0700 | [diff] [blame] | 939 | |
| 940 | // Only matters if AE_MODE = OFF |
| 941 | int32_t ae_exposure_compensation = 0; |
Ari Hausman-Cohen | dde8017 | 2016-07-01 16:20:36 -0700 | [diff] [blame] | 942 | res = base_metadata.update(ANDROID_CONTROL_AE_EXPOSURE_COMPENSATION, |
| 943 | &ae_exposure_compensation, 1); |
| 944 | if (res != android::OK) { |
| 945 | return res; |
| 946 | } |
Ari Hausman-Cohen | 4992584 | 2016-06-21 14:07:58 -0700 | [diff] [blame] | 947 | |
| 948 | uint8_t ae_lock = ANDROID_CONTROL_AE_LOCK_OFF; |
Ari Hausman-Cohen | dde8017 | 2016-07-01 16:20:36 -0700 | [diff] [blame] | 949 | res = base_metadata.update(ANDROID_CONTROL_AE_LOCK, &ae_lock, 1); |
| 950 | if (res != android::OK) { |
| 951 | return res; |
| 952 | } |
Ari Hausman-Cohen | 4992584 | 2016-06-21 14:07:58 -0700 | [diff] [blame] | 953 | |
| 954 | uint8_t ae_mode = ANDROID_CONTROL_AE_MODE_ON; |
Ari Hausman-Cohen | dde8017 | 2016-07-01 16:20:36 -0700 | [diff] [blame] | 955 | res = base_metadata.update(ANDROID_CONTROL_AE_MODE, &ae_mode, 1); |
| 956 | if (res != android::OK) { |
| 957 | return res; |
| 958 | } |
Ari Hausman-Cohen | 4992584 | 2016-06-21 14:07:58 -0700 | [diff] [blame] | 959 | |
| 960 | // AE regions not supported. |
| 961 | |
| 962 | // FPS set per-template. |
| 963 | |
| 964 | uint8_t ae_precapture_trigger = ANDROID_CONTROL_AE_PRECAPTURE_TRIGGER_IDLE; |
Ari Hausman-Cohen | dde8017 | 2016-07-01 16:20:36 -0700 | [diff] [blame] | 965 | res = base_metadata.update(ANDROID_CONTROL_AE_PRECAPTURE_TRIGGER, |
| 966 | &ae_precapture_trigger, 1); |
| 967 | if (res != android::OK) { |
| 968 | return res; |
| 969 | } |
Ari Hausman-Cohen | 4992584 | 2016-06-21 14:07:58 -0700 | [diff] [blame] | 970 | |
| 971 | /* AF. */ |
| 972 | |
| 973 | // AF mode set per-template. |
| 974 | |
| 975 | // AF regions not supported. |
| 976 | |
| 977 | uint8_t af_trigger = ANDROID_CONTROL_AF_TRIGGER_IDLE; |
Ari Hausman-Cohen | dde8017 | 2016-07-01 16:20:36 -0700 | [diff] [blame] | 978 | res = base_metadata.update(ANDROID_CONTROL_AF_TRIGGER, &af_trigger, 1); |
| 979 | if (res != android::OK) { |
| 980 | return res; |
| 981 | } |
Ari Hausman-Cohen | 4992584 | 2016-06-21 14:07:58 -0700 | [diff] [blame] | 982 | |
| 983 | /* AWB. */ |
| 984 | |
| 985 | // Priority: auto > off > Whatever is available. |
| 986 | uint8_t default_awb_mode = mAwbModes[0]; |
| 987 | if (std::count(mAwbModes.begin(), mAwbModes.end(), |
| 988 | ANDROID_CONTROL_AWB_MODE_AUTO)) { |
| 989 | default_awb_mode = ANDROID_CONTROL_AWB_MODE_AUTO; |
| 990 | } else if (std::count(mAwbModes.begin(), mAwbModes.end(), |
| 991 | ANDROID_CONTROL_AWB_MODE_OFF)) { |
| 992 | default_awb_mode = ANDROID_CONTROL_AWB_MODE_OFF; |
| 993 | } |
Ari Hausman-Cohen | dde8017 | 2016-07-01 16:20:36 -0700 | [diff] [blame] | 994 | res = base_metadata.update(ANDROID_CONTROL_AWB_MODE, &default_awb_mode, 1); |
| 995 | if (res != android::OK) { |
| 996 | return res; |
| 997 | } |
Ari Hausman-Cohen | 4992584 | 2016-06-21 14:07:58 -0700 | [diff] [blame] | 998 | |
| 999 | // AWB regions not supported. |
| 1000 | |
| 1001 | /* Other controls. */ |
| 1002 | |
| 1003 | uint8_t effect_mode = ANDROID_CONTROL_EFFECT_MODE_OFF; |
Ari Hausman-Cohen | dde8017 | 2016-07-01 16:20:36 -0700 | [diff] [blame] | 1004 | res = base_metadata.update(ANDROID_CONTROL_EFFECT_MODE, &effect_mode, 1); |
| 1005 | if (res != android::OK) { |
| 1006 | return res; |
| 1007 | } |
Ari Hausman-Cohen | 4992584 | 2016-06-21 14:07:58 -0700 | [diff] [blame] | 1008 | |
| 1009 | uint8_t control_mode = ANDROID_CONTROL_MODE_AUTO; |
Ari Hausman-Cohen | dde8017 | 2016-07-01 16:20:36 -0700 | [diff] [blame] | 1010 | res = base_metadata.update(ANDROID_CONTROL_MODE, &control_mode, 1); |
| 1011 | if (res != android::OK) { |
| 1012 | return res; |
| 1013 | } |
Ari Hausman-Cohen | 4992584 | 2016-06-21 14:07:58 -0700 | [diff] [blame] | 1014 | |
| 1015 | uint8_t scene_mode = ANDROID_CONTROL_SCENE_MODE_DISABLED; |
Ari Hausman-Cohen | dde8017 | 2016-07-01 16:20:36 -0700 | [diff] [blame] | 1016 | res = base_metadata.update(ANDROID_CONTROL_SCENE_MODE, |
| 1017 | &scene_mode, 1); |
| 1018 | if (res != android::OK) { |
| 1019 | return res; |
| 1020 | } |
Ari Hausman-Cohen | 4992584 | 2016-06-21 14:07:58 -0700 | [diff] [blame] | 1021 | |
| 1022 | uint8_t video_stabilization = ANDROID_CONTROL_VIDEO_STABILIZATION_MODE_OFF; |
Ari Hausman-Cohen | dde8017 | 2016-07-01 16:20:36 -0700 | [diff] [blame] | 1023 | res = base_metadata.update(ANDROID_CONTROL_VIDEO_STABILIZATION_MODE, |
| 1024 | &video_stabilization, 1); |
| 1025 | if (res != android::OK) { |
| 1026 | return res; |
| 1027 | } |
Ari Hausman-Cohen | 4992584 | 2016-06-21 14:07:58 -0700 | [diff] [blame] | 1028 | |
| 1029 | // postRawSensitivityBoost: RAW not supported, leave null. |
| 1030 | |
| 1031 | /* android.demosaic. */ |
| 1032 | |
| 1033 | // mode marked FUTURE. |
| 1034 | |
| 1035 | /* android.edge. */ |
| 1036 | |
| 1037 | uint8_t edge_mode = ANDROID_EDGE_MODE_FAST; |
Ari Hausman-Cohen | dde8017 | 2016-07-01 16:20:36 -0700 | [diff] [blame] | 1038 | res = base_metadata.update(ANDROID_EDGE_MODE, &edge_mode, 1); |
| 1039 | if (res != android::OK) { |
| 1040 | return res; |
| 1041 | } |
Ari Hausman-Cohen | 4992584 | 2016-06-21 14:07:58 -0700 | [diff] [blame] | 1042 | |
| 1043 | // strength marked FUTURE. |
| 1044 | |
| 1045 | /* android.flash. */ |
| 1046 | |
| 1047 | // firingPower, firingTime marked FUTURE. |
| 1048 | |
| 1049 | uint8_t flash_mode = ANDROID_FLASH_MODE_OFF; |
Ari Hausman-Cohen | dde8017 | 2016-07-01 16:20:36 -0700 | [diff] [blame] | 1050 | res = base_metadata.update(ANDROID_FLASH_MODE, &flash_mode, 1); |
| 1051 | if (res != android::OK) { |
| 1052 | return res; |
| 1053 | } |
Ari Hausman-Cohen | 4992584 | 2016-06-21 14:07:58 -0700 | [diff] [blame] | 1054 | |
| 1055 | /* android.hotPixel. */ |
| 1056 | |
| 1057 | uint8_t hp_mode = ANDROID_HOT_PIXEL_MODE_FAST; |
Ari Hausman-Cohen | dde8017 | 2016-07-01 16:20:36 -0700 | [diff] [blame] | 1058 | res = base_metadata.update(ANDROID_HOT_PIXEL_MODE, &hp_mode, 1); |
| 1059 | if (res != android::OK) { |
| 1060 | return res; |
| 1061 | } |
Ari Hausman-Cohen | 4992584 | 2016-06-21 14:07:58 -0700 | [diff] [blame] | 1062 | |
| 1063 | /* android.jpeg. */ |
| 1064 | |
| 1065 | double gps_coords[] = {/*latitude*/0, /*longitude*/0, /*altitude*/0}; |
Ari Hausman-Cohen | dde8017 | 2016-07-01 16:20:36 -0700 | [diff] [blame] | 1066 | res = base_metadata.update(ANDROID_JPEG_GPS_COORDINATES, gps_coords, 3); |
| 1067 | if (res != android::OK) { |
| 1068 | return res; |
| 1069 | } |
Ari Hausman-Cohen | 4992584 | 2016-06-21 14:07:58 -0700 | [diff] [blame] | 1070 | |
| 1071 | uint8_t gps_processing_method[] = "none"; |
Ari Hausman-Cohen | dde8017 | 2016-07-01 16:20:36 -0700 | [diff] [blame] | 1072 | res = base_metadata.update(ANDROID_JPEG_GPS_PROCESSING_METHOD, |
| 1073 | gps_processing_method, |
| 1074 | ARRAY_SIZE(gps_processing_method)); |
| 1075 | if (res != android::OK) { |
| 1076 | return res; |
| 1077 | } |
Ari Hausman-Cohen | 4992584 | 2016-06-21 14:07:58 -0700 | [diff] [blame] | 1078 | |
| 1079 | int64_t gps_timestamp = 0; |
Ari Hausman-Cohen | dde8017 | 2016-07-01 16:20:36 -0700 | [diff] [blame] | 1080 | res = base_metadata.update(ANDROID_JPEG_GPS_TIMESTAMP, &gps_timestamp, 1); |
| 1081 | if (res != android::OK) { |
| 1082 | return res; |
| 1083 | } |
Ari Hausman-Cohen | 4992584 | 2016-06-21 14:07:58 -0700 | [diff] [blame] | 1084 | |
| 1085 | // JPEG orientation is relative to sensor orientation (mOrientation). |
| 1086 | int32_t jpeg_orientation = 0; |
Ari Hausman-Cohen | dde8017 | 2016-07-01 16:20:36 -0700 | [diff] [blame] | 1087 | res = base_metadata.update(ANDROID_JPEG_ORIENTATION, &jpeg_orientation, 1); |
| 1088 | if (res != android::OK) { |
| 1089 | return res; |
| 1090 | } |
Ari Hausman-Cohen | 4992584 | 2016-06-21 14:07:58 -0700 | [diff] [blame] | 1091 | |
| 1092 | // 1-100, larger is higher quality. |
| 1093 | uint8_t jpeg_quality = 80; |
Ari Hausman-Cohen | dde8017 | 2016-07-01 16:20:36 -0700 | [diff] [blame] | 1094 | res = base_metadata.update(ANDROID_JPEG_QUALITY, &jpeg_quality, 1); |
| 1095 | if (res != android::OK) { |
| 1096 | return res; |
| 1097 | } |
Ari Hausman-Cohen | 4992584 | 2016-06-21 14:07:58 -0700 | [diff] [blame] | 1098 | |
| 1099 | // TODO(b/29580107): If thumbnail quality actually matters/can be adjusted, |
| 1100 | // adjust this. |
| 1101 | uint8_t thumbnail_quality = 80; |
Ari Hausman-Cohen | dde8017 | 2016-07-01 16:20:36 -0700 | [diff] [blame] | 1102 | res = base_metadata.update(ANDROID_JPEG_THUMBNAIL_QUALITY, |
| 1103 | &thumbnail_quality, 1); |
| 1104 | if (res != android::OK) { |
| 1105 | return res; |
| 1106 | } |
Ari Hausman-Cohen | 4992584 | 2016-06-21 14:07:58 -0700 | [diff] [blame] | 1107 | |
| 1108 | // TODO(b/29580107): Choose a size matching the resolution. |
| 1109 | int32_t thumbnail_size[] = {0, 0}; |
Ari Hausman-Cohen | dde8017 | 2016-07-01 16:20:36 -0700 | [diff] [blame] | 1110 | res = base_metadata.update(ANDROID_JPEG_THUMBNAIL_SIZE, thumbnail_size, 2); |
| 1111 | if (res != android::OK) { |
| 1112 | return res; |
| 1113 | } |
Ari Hausman-Cohen | 4992584 | 2016-06-21 14:07:58 -0700 | [diff] [blame] | 1114 | |
| 1115 | /* android.lens. */ |
| 1116 | |
| 1117 | // Fixed values. |
Ari Hausman-Cohen | dde8017 | 2016-07-01 16:20:36 -0700 | [diff] [blame] | 1118 | res = base_metadata.update(ANDROID_LENS_APERTURE, &mAperture, 1); |
| 1119 | if (res != android::OK) { |
| 1120 | return res; |
| 1121 | } |
| 1122 | res = base_metadata.update(ANDROID_LENS_FILTER_DENSITY, &mFilterDensity, 1); |
| 1123 | if (res != android::OK) { |
| 1124 | return res; |
| 1125 | } |
| 1126 | res = base_metadata.update(ANDROID_LENS_FOCAL_LENGTH, &mFocalLength, 1); |
| 1127 | if (res != android::OK) { |
| 1128 | return res; |
| 1129 | } |
| 1130 | res = base_metadata.update(ANDROID_LENS_FOCUS_DISTANCE, &mFocusDistance, 1); |
| 1131 | if (res != android::OK) { |
| 1132 | return res; |
| 1133 | } |
Ari Hausman-Cohen | 4992584 | 2016-06-21 14:07:58 -0700 | [diff] [blame] | 1134 | |
| 1135 | uint8_t optical_stabilization = ANDROID_LENS_OPTICAL_STABILIZATION_MODE_OFF; |
Ari Hausman-Cohen | dde8017 | 2016-07-01 16:20:36 -0700 | [diff] [blame] | 1136 | res = base_metadata.update(ANDROID_LENS_OPTICAL_STABILIZATION_MODE, |
Ari Hausman-Cohen | 4992584 | 2016-06-21 14:07:58 -0700 | [diff] [blame] | 1137 | &optical_stabilization, 1); |
Ari Hausman-Cohen | dde8017 | 2016-07-01 16:20:36 -0700 | [diff] [blame] | 1138 | if (res != android::OK) { |
| 1139 | return res; |
| 1140 | } |
Ari Hausman-Cohen | 4992584 | 2016-06-21 14:07:58 -0700 | [diff] [blame] | 1141 | |
| 1142 | /* android.noiseReduction. */ |
| 1143 | |
| 1144 | uint8_t noise_reduction_mode = ANDROID_NOISE_REDUCTION_MODE_FAST; |
Ari Hausman-Cohen | dde8017 | 2016-07-01 16:20:36 -0700 | [diff] [blame] | 1145 | res = base_metadata.update(ANDROID_NOISE_REDUCTION_MODE, |
| 1146 | &noise_reduction_mode, 1); |
| 1147 | if (res != android::OK) { |
| 1148 | return res; |
| 1149 | } |
Ari Hausman-Cohen | 4992584 | 2016-06-21 14:07:58 -0700 | [diff] [blame] | 1150 | |
| 1151 | // strength marked FUTURE. |
| 1152 | |
| 1153 | /* android.request. */ |
| 1154 | |
| 1155 | // Request Id unused by the HAL for now, and these are just |
| 1156 | // templates, so just fill it in with a dummy. |
| 1157 | int32_t id = 0; |
Ari Hausman-Cohen | dde8017 | 2016-07-01 16:20:36 -0700 | [diff] [blame] | 1158 | res = base_metadata.update(ANDROID_REQUEST_ID, &id, 1); |
| 1159 | if (res != android::OK) { |
| 1160 | return res; |
| 1161 | } |
Ari Hausman-Cohen | 4992584 | 2016-06-21 14:07:58 -0700 | [diff] [blame] | 1162 | |
| 1163 | // metadataMode marked FUTURE. |
| 1164 | |
| 1165 | /* android.scaler. */ |
| 1166 | |
| 1167 | // No cropping by default; use the full active array. |
Ari Hausman-Cohen | dde8017 | 2016-07-01 16:20:36 -0700 | [diff] [blame] | 1168 | res = base_metadata.update(ANDROID_SCALER_CROP_REGION, mPixelArraySize.data(), |
| 1169 | mPixelArraySize.size()); |
| 1170 | if (res != android::OK) { |
| 1171 | return res; |
| 1172 | } |
Ari Hausman-Cohen | 4992584 | 2016-06-21 14:07:58 -0700 | [diff] [blame] | 1173 | |
| 1174 | /* android.sensor. */ |
| 1175 | |
| 1176 | // exposureTime, sensitivity, testPattern[Data,Mode] not supported. |
| 1177 | |
| 1178 | // Ignored when AE is OFF. |
| 1179 | int64_t frame_duration = 33333333L; // 1/30 s. |
Ari Hausman-Cohen | dde8017 | 2016-07-01 16:20:36 -0700 | [diff] [blame] | 1180 | res = base_metadata.update(ANDROID_SENSOR_FRAME_DURATION, &frame_duration, 1); |
| 1181 | if (res != android::OK) { |
| 1182 | return res; |
| 1183 | } |
Ari Hausman-Cohen | 4992584 | 2016-06-21 14:07:58 -0700 | [diff] [blame] | 1184 | |
| 1185 | /* android.shading. */ |
| 1186 | |
| 1187 | uint8_t shading_mode = ANDROID_SHADING_MODE_FAST; |
Ari Hausman-Cohen | dde8017 | 2016-07-01 16:20:36 -0700 | [diff] [blame] | 1188 | res = base_metadata.update(ANDROID_SHADING_MODE, &shading_mode, 1); |
| 1189 | if (res != android::OK) { |
| 1190 | return res; |
| 1191 | } |
Ari Hausman-Cohen | 4992584 | 2016-06-21 14:07:58 -0700 | [diff] [blame] | 1192 | |
| 1193 | /* android.statistics. */ |
| 1194 | |
| 1195 | uint8_t face_detect_mode = ANDROID_STATISTICS_FACE_DETECT_MODE_OFF; |
Ari Hausman-Cohen | dde8017 | 2016-07-01 16:20:36 -0700 | [diff] [blame] | 1196 | res = base_metadata.update(ANDROID_STATISTICS_FACE_DETECT_MODE, |
| 1197 | &face_detect_mode, 1); |
| 1198 | if (res != android::OK) { |
| 1199 | return res; |
| 1200 | } |
Ari Hausman-Cohen | 4992584 | 2016-06-21 14:07:58 -0700 | [diff] [blame] | 1201 | |
| 1202 | // histogramMode, sharpnessMapMode marked FUTURE. |
| 1203 | |
| 1204 | uint8_t hp_map_mode = ANDROID_STATISTICS_HOT_PIXEL_MAP_MODE_OFF; |
Ari Hausman-Cohen | dde8017 | 2016-07-01 16:20:36 -0700 | [diff] [blame] | 1205 | res = base_metadata.update(ANDROID_STATISTICS_HOT_PIXEL_MAP_MODE, |
| 1206 | &hp_map_mode, 1); |
| 1207 | if (res != android::OK) { |
| 1208 | return res; |
| 1209 | } |
Ari Hausman-Cohen | 4992584 | 2016-06-21 14:07:58 -0700 | [diff] [blame] | 1210 | |
| 1211 | uint8_t lens_shading_map_mode = ANDROID_STATISTICS_LENS_SHADING_MAP_MODE_OFF; |
Ari Hausman-Cohen | dde8017 | 2016-07-01 16:20:36 -0700 | [diff] [blame] | 1212 | res = base_metadata.update(ANDROID_STATISTICS_LENS_SHADING_MAP_MODE, |
| 1213 | &lens_shading_map_mode, 1); |
| 1214 | if (res != android::OK) { |
| 1215 | return res; |
| 1216 | } |
Ari Hausman-Cohen | 4992584 | 2016-06-21 14:07:58 -0700 | [diff] [blame] | 1217 | |
| 1218 | /* android.tonemap. */ |
| 1219 | |
| 1220 | // Tonemap only required for MANUAL_POST_PROCESSING capability. |
| 1221 | |
| 1222 | /* android.led. */ |
| 1223 | |
| 1224 | uint8_t transmit = ANDROID_LED_TRANSMIT_ON; |
Ari Hausman-Cohen | dde8017 | 2016-07-01 16:20:36 -0700 | [diff] [blame] | 1225 | res = base_metadata.update(ANDROID_LED_TRANSMIT, &transmit, 1); |
| 1226 | if (res != android::OK) { |
| 1227 | return res; |
| 1228 | } |
Ari Hausman-Cohen | 4992584 | 2016-06-21 14:07:58 -0700 | [diff] [blame] | 1229 | |
| 1230 | /* android.reprocess */ |
| 1231 | |
| 1232 | // Only needed for REPROCESS capability. |
| 1233 | |
| 1234 | |
| 1235 | /* Template variable values. */ |
| 1236 | |
| 1237 | // Find the FPS ranges "closest" to a desired range |
| 1238 | // (minimum abs distance from min to min and max to max). |
| 1239 | // Find both a fixed rate and a variable rate, for different purposes. |
| 1240 | std::array<int32_t, 2> desired_flat_fps_range = {{30, 30}}; |
| 1241 | std::array<int32_t, 2> desired_variable_fps_range = {{5, 30}}; |
| 1242 | std::array<int32_t, 2> flat_fps_range; |
| 1243 | std::array<int32_t, 2> variable_fps_range; |
| 1244 | int32_t best_flat_distance = std::numeric_limits<int32_t>::max(); |
| 1245 | int32_t best_variable_distance = std::numeric_limits<int32_t>::max(); |
| 1246 | size_t num_fps_ranges = mFpsRanges.num_arrays(); |
| 1247 | for (size_t i = 0; i < num_fps_ranges; ++i) { |
| 1248 | const int32_t* range = mFpsRanges[i]; |
| 1249 | // Variable fps. |
| 1250 | int32_t distance = std::abs(range[0] - desired_variable_fps_range[0]) + |
| 1251 | std::abs(range[1] - desired_variable_fps_range[1]); |
| 1252 | if (distance < best_variable_distance) { |
| 1253 | variable_fps_range[0] = range[0]; |
| 1254 | variable_fps_range[1] = range[1]; |
| 1255 | best_variable_distance = distance; |
| 1256 | } |
| 1257 | // Flat fps. Only do if range is actually flat. |
| 1258 | // Note at least one flat range is required, |
| 1259 | // so something will always be filled in. |
| 1260 | if (range[0] == range[1]) { |
| 1261 | distance = std::abs(range[0] - desired_flat_fps_range[0]) + |
| 1262 | std::abs(range[1] - desired_flat_fps_range[1]); |
| 1263 | if (distance < best_flat_distance) { |
| 1264 | flat_fps_range[0] = range[0]; |
| 1265 | flat_fps_range[1] = range[1]; |
| 1266 | best_flat_distance = distance; |
| 1267 | } |
| 1268 | } |
| 1269 | } |
| 1270 | |
| 1271 | // Priority: continuous > auto > off > whatever is available. |
| 1272 | bool continuous_still_avail = std::count( |
| 1273 | mAfModes.begin(), mAfModes.end(), |
| 1274 | ANDROID_CONTROL_AF_MODE_CONTINUOUS_PICTURE); |
| 1275 | bool continuous_video_avail = std::count( |
| 1276 | mAfModes.begin(), mAfModes.end(), |
| 1277 | ANDROID_CONTROL_AF_MODE_CONTINUOUS_VIDEO); |
| 1278 | uint8_t non_continuous_af_mode = mAfModes[0]; |
| 1279 | if (std::count(mAfModes.begin(), mAfModes.end(), |
| 1280 | ANDROID_CONTROL_AF_MODE_AUTO)) { |
| 1281 | non_continuous_af_mode = ANDROID_CONTROL_AF_MODE_AUTO; |
| 1282 | } else if (std::count(mAfModes.begin(), mAfModes.end(), |
| 1283 | ANDROID_CONTROL_AF_MODE_OFF)) { |
| 1284 | non_continuous_af_mode = ANDROID_CONTROL_AF_MODE_OFF; |
| 1285 | } |
| 1286 | uint8_t still_af_mode = continuous_still_avail ? |
| 1287 | ANDROID_CONTROL_AF_MODE_CONTINUOUS_PICTURE : non_continuous_af_mode; |
| 1288 | uint8_t video_af_mode = continuous_video_avail ? |
| 1289 | ANDROID_CONTROL_AF_MODE_CONTINUOUS_VIDEO : non_continuous_af_mode; |
| 1290 | |
Ari Hausman-Cohen | dde8017 | 2016-07-01 16:20:36 -0700 | [diff] [blame] | 1291 | for (uint8_t template_id = 1; template_id < CAMERA3_TEMPLATE_COUNT; |
| 1292 | ++template_id) { |
Ari Hausman-Cohen | 4992584 | 2016-06-21 14:07:58 -0700 | [diff] [blame] | 1293 | // General differences/support. |
| 1294 | uint8_t intent; |
| 1295 | uint8_t af_mode; |
| 1296 | std::array<int32_t, 2> fps_range; |
| 1297 | switch(template_id) { |
| 1298 | case CAMERA3_TEMPLATE_PREVIEW: |
| 1299 | intent = ANDROID_CONTROL_CAPTURE_INTENT_PREVIEW; |
| 1300 | af_mode = still_af_mode; |
| 1301 | fps_range = flat_fps_range; |
| 1302 | break; |
| 1303 | case CAMERA3_TEMPLATE_STILL_CAPTURE: |
| 1304 | intent = ANDROID_CONTROL_CAPTURE_INTENT_STILL_CAPTURE; |
| 1305 | af_mode = still_af_mode; |
| 1306 | fps_range = variable_fps_range; |
| 1307 | break; |
| 1308 | case CAMERA3_TEMPLATE_VIDEO_RECORD: |
| 1309 | intent = ANDROID_CONTROL_CAPTURE_INTENT_VIDEO_RECORD; |
| 1310 | af_mode = video_af_mode; |
| 1311 | fps_range = flat_fps_range; |
| 1312 | break; |
| 1313 | case CAMERA3_TEMPLATE_VIDEO_SNAPSHOT: |
| 1314 | intent = ANDROID_CONTROL_CAPTURE_INTENT_VIDEO_SNAPSHOT; |
| 1315 | af_mode = video_af_mode; |
| 1316 | fps_range = flat_fps_range; |
| 1317 | break; |
| 1318 | case CAMERA3_TEMPLATE_ZERO_SHUTTER_LAG: // Fall through. |
| 1319 | case CAMERA3_TEMPLATE_MANUAL: // Fall though. |
| 1320 | default: |
| 1321 | // Unsupported/unrecognized. Don't add this template; skip it. |
| 1322 | continue; |
| 1323 | } |
| 1324 | |
Ari Hausman-Cohen | dde8017 | 2016-07-01 16:20:36 -0700 | [diff] [blame] | 1325 | // Copy our base metadata and add the new items. |
| 1326 | android::CameraMetadata template_metadata(base_metadata); |
| 1327 | res = template_metadata.update(ANDROID_CONTROL_CAPTURE_INTENT, &intent, 1); |
| 1328 | if (res != android::OK) { |
| 1329 | return res; |
| 1330 | } |
| 1331 | res = template_metadata.update(ANDROID_CONTROL_AE_TARGET_FPS_RANGE, |
| 1332 | fps_range.data(), fps_range.size()); |
| 1333 | if (res != android::OK) { |
| 1334 | return res; |
| 1335 | } |
| 1336 | res = template_metadata.update(ANDROID_CONTROL_AF_MODE, &af_mode, 1); |
| 1337 | if (res != android::OK) { |
| 1338 | return res; |
| 1339 | } |
Ari Hausman-Cohen | 4992584 | 2016-06-21 14:07:58 -0700 | [diff] [blame] | 1340 | |
| 1341 | const camera_metadata_t* template_raw_metadata = |
| 1342 | template_metadata.getAndLock(); |
| 1343 | res = setTemplate(template_id, template_raw_metadata); |
| 1344 | if (res != android::OK) { |
| 1345 | return res; |
| 1346 | } |
| 1347 | res = template_metadata.unlock(template_raw_metadata); |
| 1348 | if (res != android::OK) { |
| 1349 | return res; |
| 1350 | } |
Ari Hausman-Cohen | 4992584 | 2016-06-21 14:07:58 -0700 | [diff] [blame] | 1351 | } |
| 1352 | |
| 1353 | mTemplatesInitialized = true; |
Ari Hausman-Cohen | 7344215 | 2016-06-08 15:50:49 -0700 | [diff] [blame] | 1354 | return 0; |
| 1355 | } |
| 1356 | |
Ari Hausman-Cohen | 72fddb3 | 2016-06-30 16:53:31 -0700 | [diff] [blame] | 1357 | bool V4L2Camera::isSupportedStreamSet(default_camera_hal::Stream** streams, |
| 1358 | int count, uint32_t mode) { |
| 1359 | HAL_LOG_ENTER(); |
| 1360 | |
| 1361 | if (mode != CAMERA3_STREAM_CONFIGURATION_NORMAL_MODE) { |
| 1362 | HAL_LOGE("Unsupported stream configuration mode: %d", mode); |
| 1363 | return false; |
| 1364 | } |
| 1365 | |
| 1366 | // This should be checked by the caller, but put here as a sanity check. |
| 1367 | if (count < 1) { |
| 1368 | HAL_LOGE("Must request at least 1 stream"); |
| 1369 | return false; |
| 1370 | } |
| 1371 | |
| 1372 | // Count the number of streams of each type. |
| 1373 | int32_t num_input = 0; |
| 1374 | int32_t num_raw = 0; |
| 1375 | int32_t num_yuv = 0; |
| 1376 | int32_t num_jpeg = 0; |
| 1377 | for (int i = 0; i < count; ++i) { |
| 1378 | default_camera_hal::Stream* stream = streams[i]; |
| 1379 | |
| 1380 | if (stream->isInputType()) { |
| 1381 | ++num_input; |
| 1382 | } |
| 1383 | |
| 1384 | if (stream->isOutputType()) { |
| 1385 | switch (halToV4L2PixelFormat(stream->getFormat())) { |
| 1386 | case V4L2_PIX_FMT_YUV420: |
| 1387 | ++num_yuv; |
| 1388 | break; |
| 1389 | case V4L2_PIX_FMT_JPEG: |
| 1390 | ++num_jpeg; |
| 1391 | break; |
| 1392 | default: |
| 1393 | // Note: no supported raw formats at this time. |
| 1394 | HAL_LOGE("Unsupported format for stream %d: %d", i, stream->getFormat()); |
| 1395 | return false; |
| 1396 | } |
| 1397 | } |
| 1398 | } |
| 1399 | |
| 1400 | if (num_input > mMaxInputStreams || num_raw > mMaxRawOutputStreams || |
| 1401 | num_yuv > mMaxYuvOutputStreams || num_jpeg > mMaxJpegOutputStreams) { |
| 1402 | HAL_LOGE("Invalid stream configuration: %d input, %d RAW, %d YUV, %d JPEG " |
| 1403 | "(max supported: %d input, %d RAW, %d YUV, %d JPEG)", |
| 1404 | mMaxInputStreams, mMaxRawOutputStreams, mMaxYuvOutputStreams, |
| 1405 | mMaxJpegOutputStreams, num_input, num_raw, num_yuv, num_jpeg); |
| 1406 | return false; |
| 1407 | } |
| 1408 | |
| 1409 | // TODO(b/29939583): The above logic should be all that's necessary, |
| 1410 | // but V4L2 doesn't actually support more than 1 stream at a time. So for now, |
| 1411 | // if not all streams are the same format and size, error. Note that this |
| 1412 | // means the HAL is not spec-compliant; the requested streams are technically |
| 1413 | // valid and it is not technically allowed to error once it has reached this |
| 1414 | // point. |
| 1415 | int format = streams[0]->getFormat(); |
| 1416 | uint32_t width = streams[0]->getWidth(); |
| 1417 | uint32_t height = streams[0]->getHeight(); |
| 1418 | for (int i = 1; i < count; ++i) { |
| 1419 | const default_camera_hal::Stream* stream = streams[i]; |
| 1420 | if (stream->getFormat() != format || stream->getWidth() != width || |
| 1421 | stream->getHeight() != height) { |
| 1422 | HAL_LOGE("V4L2 only supports 1 stream configuration at a time " |
| 1423 | "(stream 0 is format %d, width %u, height %u, " |
| 1424 | "stream %d is format %d, width %u, height %u).", |
| 1425 | format, width, height, i, stream->getFormat(), |
| 1426 | stream->getWidth(), stream->getHeight()); |
| 1427 | return false; |
| 1428 | } |
| 1429 | } |
| 1430 | |
| 1431 | return true; |
| 1432 | } |
| 1433 | |
| 1434 | int V4L2Camera::setupStream(default_camera_hal::Stream* stream, |
| 1435 | uint32_t* max_buffers) { |
| 1436 | HAL_LOG_ENTER(); |
| 1437 | |
| 1438 | if (stream->getRotation() != CAMERA3_STREAM_ROTATION_0) { |
| 1439 | HAL_LOGE("Rotation %d not supported", stream->getRotation()); |
| 1440 | return -EINVAL; |
| 1441 | } |
| 1442 | |
| 1443 | // Doesn't matter what was requested, we always use dataspace V0_JFIF. |
| 1444 | // Note: according to camera3.h, this isn't allowed, but etalvala@google.com |
| 1445 | // claims it's underdocumented; the implementation lets the HAL overwrite it. |
| 1446 | stream->setDataSpace(HAL_DATASPACE_V0_JFIF); |
| 1447 | |
| 1448 | int ret = setFormat(stream); |
| 1449 | if (ret) { |
| 1450 | return ret; |
| 1451 | } |
| 1452 | |
| 1453 | // Only do buffer setup if we don't know our maxBuffers. |
| 1454 | if (mOutStreamMaxBuffers < 1) { |
| 1455 | ret = setupBuffers(); |
| 1456 | if (ret) { |
| 1457 | return ret; |
| 1458 | } |
| 1459 | } |
| 1460 | |
| 1461 | // Sanity check. |
| 1462 | if (mOutStreamMaxBuffers < 1) { |
| 1463 | HAL_LOGE("HAL failed to determine max number of buffers."); |
| 1464 | return -ENODEV; |
| 1465 | } |
| 1466 | *max_buffers = mOutStreamMaxBuffers; |
| 1467 | |
| 1468 | return 0; |
| 1469 | } |
| 1470 | |
| 1471 | int V4L2Camera::setFormat(const default_camera_hal::Stream* stream) { |
| 1472 | HAL_LOG_ENTER(); |
| 1473 | |
| 1474 | // Should be checked earlier; sanity check. |
| 1475 | if (stream->isInputType()) { |
| 1476 | HAL_LOGE("Input streams not supported."); |
| 1477 | return -EINVAL; |
| 1478 | } |
| 1479 | |
Ari Hausman-Cohen | 44d8432 | 2016-07-11 11:08:26 -0700 | [diff] [blame] | 1480 | // TODO(b/30000211): Check if appropriate to do multi-planar capture instead. |
| 1481 | uint32_t desired_type = V4L2_BUF_TYPE_VIDEO_CAPTURE; |
| 1482 | uint32_t desired_format = halToV4L2PixelFormat(stream->getFormat()); |
| 1483 | uint32_t desired_width = stream->getWidth(); |
| 1484 | uint32_t desired_height = stream->getHeight(); |
| 1485 | |
Ari Hausman-Cohen | 72fddb3 | 2016-06-30 16:53:31 -0700 | [diff] [blame] | 1486 | // Check to make sure we're not already in the correct format. |
Ari Hausman-Cohen | 44d8432 | 2016-07-11 11:08:26 -0700 | [diff] [blame] | 1487 | if (desired_type == mOutStreamType && |
| 1488 | desired_format == mOutStreamFormat && |
| 1489 | desired_width == mOutStreamWidth && |
| 1490 | desired_height == mOutStreamHeight) { |
Ari Hausman-Cohen | 72fddb3 | 2016-06-30 16:53:31 -0700 | [diff] [blame] | 1491 | return 0; |
| 1492 | } |
Ari Hausman-Cohen | 44d8432 | 2016-07-11 11:08:26 -0700 | [diff] [blame] | 1493 | |
Ari Hausman-Cohen | 72fddb3 | 2016-06-30 16:53:31 -0700 | [diff] [blame] | 1494 | // Not in the correct format, set our format. |
Ari Hausman-Cohen | 44d8432 | 2016-07-11 11:08:26 -0700 | [diff] [blame] | 1495 | v4l2_format format; |
| 1496 | memset(&format, 0, sizeof(format)); |
| 1497 | format.type = desired_type; |
| 1498 | format.fmt.pix.width = desired_width; |
| 1499 | format.fmt.pix.height = desired_height; |
| 1500 | format.fmt.pix.pixelformat = desired_format; |
| 1501 | // TODO(b/29334616): When async, this will need to check if the stream |
| 1502 | // is on, and if so, lock it off while setting format. |
| 1503 | if (ioctlLocked(VIDIOC_S_FMT, &format) < 0) { |
Ari Hausman-Cohen | 72fddb3 | 2016-06-30 16:53:31 -0700 | [diff] [blame] | 1504 | HAL_LOGE("S_FMT failed: %s", strerror(errno)); |
| 1505 | return -ENODEV; |
| 1506 | } |
| 1507 | // Check that the driver actually set to the requested values. |
Ari Hausman-Cohen | 44d8432 | 2016-07-11 11:08:26 -0700 | [diff] [blame] | 1508 | if (format.type != desired_type || |
| 1509 | format.fmt.pix.pixelformat != desired_format || |
| 1510 | format.fmt.pix.width != desired_width || |
| 1511 | format.fmt.pix.height != desired_height) { |
Ari Hausman-Cohen | 72fddb3 | 2016-06-30 16:53:31 -0700 | [diff] [blame] | 1512 | HAL_LOGE("Device doesn't support desired stream configuration."); |
| 1513 | return -EINVAL; |
| 1514 | } |
Ari Hausman-Cohen | 44d8432 | 2016-07-11 11:08:26 -0700 | [diff] [blame] | 1515 | |
| 1516 | // Keep track of the new format. |
| 1517 | mOutStreamType = format.type; |
| 1518 | mOutStreamFormat = format.fmt.pix.pixelformat; |
| 1519 | mOutStreamWidth = format.fmt.pix.width; |
| 1520 | mOutStreamHeight = format.fmt.pix.height; |
Ari Hausman-Cohen | 3eece6f | 2016-07-21 11:08:24 -0700 | [diff] [blame] | 1521 | mOutStreamBytesPerLine = format.fmt.pix.bytesperline; |
Ari Hausman-Cohen | 24e541c | 2016-07-21 11:20:30 -0700 | [diff] [blame] | 1522 | HAL_LOGV("New format: type %u, pixel format %u, width %u, height %u, " |
| 1523 | "bytes/line %u", mOutStreamType, mOutStreamFormat, mOutStreamWidth, |
| 1524 | mOutStreamHeight, mOutStreamBytesPerLine); |
| 1525 | |
Ari Hausman-Cohen | 72fddb3 | 2016-06-30 16:53:31 -0700 | [diff] [blame] | 1526 | // Since our format changed, our maxBuffers may be incorrect. |
| 1527 | mOutStreamMaxBuffers = 0; |
| 1528 | |
Ari Hausman-Cohen | 24e541c | 2016-07-21 11:20:30 -0700 | [diff] [blame] | 1529 | |
Ari Hausman-Cohen | 72fddb3 | 2016-06-30 16:53:31 -0700 | [diff] [blame] | 1530 | return 0; |
| 1531 | } |
| 1532 | |
| 1533 | int V4L2Camera::setupBuffers() { |
| 1534 | HAL_LOG_ENTER(); |
| 1535 | |
| 1536 | // "Request" a buffer (since we're using a userspace buffer, this just |
| 1537 | // tells V4L2 to switch into userspace buffer mode). |
| 1538 | v4l2_requestbuffers req_buffers; |
| 1539 | memset(&req_buffers, 0, sizeof(req_buffers)); |
Ari Hausman-Cohen | 24e541c | 2016-07-21 11:20:30 -0700 | [diff] [blame] | 1540 | req_buffers.type = mOutStreamType; |
Ari Hausman-Cohen | 72fddb3 | 2016-06-30 16:53:31 -0700 | [diff] [blame] | 1541 | req_buffers.memory = V4L2_MEMORY_USERPTR; |
| 1542 | req_buffers.count = 1; |
| 1543 | if (ioctlLocked(VIDIOC_REQBUFS, &req_buffers) < 0) { |
| 1544 | HAL_LOGE("REQBUFS failed: %s", strerror(errno)); |
| 1545 | return -ENODEV; |
| 1546 | } |
| 1547 | |
| 1548 | // V4L2 will set req_buffers.count to a number of buffers it can handle. |
| 1549 | mOutStreamMaxBuffers = req_buffers.count; |
| 1550 | return 0; |
| 1551 | } |
| 1552 | |
Ari Hausman-Cohen | 7344215 | 2016-06-08 15:50:49 -0700 | [diff] [blame] | 1553 | bool V4L2Camera::isValidCaptureSettings(const camera_metadata_t* settings) { |
| 1554 | HAL_LOG_ENTER(); |
| 1555 | |
Ari Hausman-Cohen | 4992584 | 2016-06-21 14:07:58 -0700 | [diff] [blame] | 1556 | // TODO(b/29335262): reject capture settings this camera isn't capable of. |
Ari Hausman-Cohen | 7344215 | 2016-06-08 15:50:49 -0700 | [diff] [blame] | 1557 | return true; |
| 1558 | } |
| 1559 | |
Ari Hausman-Cohen | 4992584 | 2016-06-21 14:07:58 -0700 | [diff] [blame] | 1560 | int V4L2Camera::initCharacteristics() { |
| 1561 | HAL_LOG_ENTER(); |
| 1562 | |
| 1563 | /* Physical characteristics. */ |
| 1564 | // No way to get these in V4L2, so faked. |
| 1565 | // Note: While many of these are primarily informative for post-processing |
| 1566 | // calculations by the app and will potentially cause bad results there, |
| 1567 | // focal length and physical size are actually used in framework |
| 1568 | // calculations (field of view, pixel pitch, etc), so faking them may |
| 1569 | // have unexpected results. |
| 1570 | mAperture = 2.0; // RPi camera v2 is f/2.0. |
| 1571 | mFilterDensity = 0.0; |
| 1572 | mFocalLength = 3.04; // RPi camera v2 is 3.04mm. |
| 1573 | mOrientation = 0; |
| 1574 | mPhysicalSize = {{3.674, 2.760}}; // RPi camera v2 is 3.674 x 2.760 mm. |
| 1575 | |
| 1576 | /* Fixed features. */ |
| 1577 | |
| 1578 | // TODO(b/29394024): query VIDIOC_CROPCAP to get pixel rectangle. |
| 1579 | // Spoofing as 640 x 480 for now. |
| 1580 | mPixelArraySize = {{/*xmin*/0, /*ymin*/0, /*width*/640, /*height*/480}}; |
| 1581 | |
| 1582 | // V4L2 VIDIOC_CROPCAP doesn't give a way to query this; |
| 1583 | // it's driver dependent. For now, assume freeform, and |
| 1584 | // some cameras may just behave badly. |
| 1585 | // TODO(b/29579652): Figure out a way to determine this. |
| 1586 | mCropType = ANDROID_SCALER_CROPPING_TYPE_FREEFORM; |
| 1587 | |
| 1588 | // TODO(b/29394024): query VIDIOC_CROPCAP to get cropping ranges, |
| 1589 | // and VIDIOC_G_CROP to determine if cropping is supported. |
| 1590 | // If the ioctl isn't available (or cropping has non-square pixelaspect), |
| 1591 | // assume no cropping/scaling. |
| 1592 | // May need to try setting some crops to determine what the driver actually |
| 1593 | // supports (including testing center vs freeform). |
| 1594 | mMaxZoom = 1; |
| 1595 | |
| 1596 | // TODO(b/29394024): query V4L2_CID_EXPOSURE_BIAS. |
| 1597 | mAeCompensationRange = {{0, 0}}; |
| 1598 | mAeCompensationStep = {1, 1}; |
| 1599 | |
| 1600 | // TODO(b/29394024): query V4L2_CID_3A_LOCK. |
| 1601 | mAeLockAvailable = ANDROID_CONTROL_AE_LOCK_AVAILABLE_FALSE; |
| 1602 | mAwbLockAvailable = ANDROID_CONTROL_AWB_LOCK_AVAILABLE_FALSE; |
| 1603 | |
| 1604 | // TODO(b/29394024): query V4L2_CID_FLASH_LED_MODE. |
| 1605 | mFlashAvailable = 0; |
| 1606 | |
| 1607 | // TODO(b/29394024): query V4L2_CID_FOCUS_ABSOLUTE for focus range. |
| 1608 | mFocusDistance = 0; // Fixed focus. |
| 1609 | |
Ari Hausman-Cohen | 72fddb3 | 2016-06-30 16:53:31 -0700 | [diff] [blame] | 1610 | // TODO(b/29939583): V4L2 can only support 1 stream at a time. |
| 1611 | // For now, just reporting minimum allowable for LIMITED devices. |
| 1612 | mMaxRawOutputStreams = 0; |
| 1613 | mMaxYuvOutputStreams = 2; |
| 1614 | mMaxJpegOutputStreams = 1; |
| 1615 | // Reprocessing not supported. |
| 1616 | mMaxInputStreams = 0; |
| 1617 | |
Ari Hausman-Cohen | 4992584 | 2016-06-21 14:07:58 -0700 | [diff] [blame] | 1618 | /* Features with (potentially) multiple options. */ |
| 1619 | |
| 1620 | // TODO(b/29394024): query V4L2_CID_EXPOSURE_AUTO for ae modes. |
| 1621 | mAeModes.push_back(ANDROID_CONTROL_AE_MODE_ON); |
| 1622 | |
| 1623 | // TODO(b/29394024): query V4L2_CID_POWER_LINE_FREQUENCY. |
| 1624 | // Auto as the default, since it could mean anything, while OFF would |
| 1625 | // require guaranteeing no antibanding happens. |
| 1626 | mAeAntibandingModes.push_back(ANDROID_CONTROL_AE_ANTIBANDING_MODE_AUTO); |
| 1627 | |
| 1628 | // TODO(b/29394024): query V4L2_CID_FOCUS_AUTO for |
| 1629 | // CONTINUOUS_VIDEO/CONTINUOUS_PICTURE. V4L2_CID_AUTO_FOCUS_START |
| 1630 | // supports what Android thinks of as auto focus (single auto focus). |
| 1631 | // V4L2_CID_AUTO_FOCUS_RANGE allows MACRO. |
| 1632 | mAfModes.push_back(ANDROID_CONTROL_AF_MODE_OFF); |
| 1633 | |
| 1634 | // TODO(b/29394024): query V4L2_CID_AUTO_WHITE_BALANCE, or |
| 1635 | // V4L2_CID_AUTO_N_PRESET_WHITE_BALANCE if available. |
| 1636 | mAwbModes.push_back(ANDROID_CONTROL_AWB_MODE_AUTO); |
| 1637 | |
| 1638 | // TODO(b/29394024): query V4L2_CID_SCENE_MODE. |
| 1639 | mSceneModes.push_back(ANDROID_CONTROL_SCENE_MODE_DISABLED); |
| 1640 | |
| 1641 | mControlModes.push_back(ANDROID_CONTROL_MODE_AUTO); |
| 1642 | if (mSceneModes.size() > 1) { |
| 1643 | // We have some mode other than just DISABLED available. |
| 1644 | mControlModes.push_back(ANDROID_CONTROL_MODE_USE_SCENE_MODE); |
| 1645 | } |
| 1646 | |
| 1647 | // TODO(b/29394024): query V4L2_CID_COLORFX. |
| 1648 | mEffects.push_back(ANDROID_CONTROL_EFFECT_MODE_OFF); |
| 1649 | |
| 1650 | // TODO(b/29394024): query V4L2_CID_FLASH_INDICATOR_INTENSITY. |
| 1651 | // For now, no indicator LED available; nothing to push back. |
| 1652 | // When there is, push back ANDROID_LED_AVAILABLE_LEDS_TRANSMIT. |
| 1653 | |
| 1654 | // TODO(b/29394024): query V4L2_CID_IMAGE_STABILIZATION. |
| 1655 | mOpticalStabilizationModes.push_back( |
| 1656 | ANDROID_LENS_OPTICAL_STABILIZATION_MODE_OFF); |
| 1657 | mVideoStabilizationModes.push_back( |
| 1658 | ANDROID_CONTROL_VIDEO_STABILIZATION_MODE_OFF); |
| 1659 | |
| 1660 | // Need to support YUV_420_888 and JPEG. |
| 1661 | // TODO(b/29394024): query VIDIOC_ENUM_FMT. |
| 1662 | std::vector<uint32_t> formats = {{V4L2_PIX_FMT_JPEG, V4L2_PIX_FMT_YUV420}}; |
Ari Hausman-Cohen | 4992584 | 2016-06-21 14:07:58 -0700 | [diff] [blame] | 1663 | // We want to find the smallest maximum frame duration amongst formats. |
| 1664 | mMaxFrameDuration = std::numeric_limits<int64_t>::max(); |
| 1665 | int64_t min_yuv_frame_duration = std::numeric_limits<int64_t>::max(); |
| 1666 | for (auto format : formats) { |
Ari Hausman-Cohen | 72fddb3 | 2016-06-30 16:53:31 -0700 | [diff] [blame] | 1667 | int32_t hal_format = V4L2ToHalPixelFormat(format); |
| 1668 | if (hal_format < 0) { |
| 1669 | // Unrecognized/unused format. Skip it. |
| 1670 | continue; |
Ari Hausman-Cohen | 4992584 | 2016-06-21 14:07:58 -0700 | [diff] [blame] | 1671 | } |
Ari Hausman-Cohen | 4992584 | 2016-06-21 14:07:58 -0700 | [diff] [blame] | 1672 | // TODO(b/29394024): query VIDIOC_ENUM_FRAMESIZES. |
| 1673 | // For now, just 640x480. |
| 1674 | ArrayVector<int32_t, 2> frame_sizes; |
| 1675 | frame_sizes.push_back({{640, 480}}); |
| 1676 | size_t num_frame_sizes = frame_sizes.num_arrays(); |
| 1677 | for (size_t i = 0; i < num_frame_sizes; ++i) { |
| 1678 | const int32_t* frame_size = frame_sizes[i]; |
| 1679 | mStreamConfigs.push_back({{hal_format, frame_size[0], frame_size[1], |
| 1680 | ANDROID_SCALER_AVAILABLE_STREAM_CONFIGURATIONS_OUTPUT}}); |
| 1681 | |
| 1682 | // TODO(b/29394024): query VIDIOC_ENUM_FRAMEINTERVALS. |
| 1683 | // For now, using the emulator max value of .3 sec. |
| 1684 | int64_t max_frame_duration = 300000000; |
| 1685 | // For now, min value of 30 fps = 1/30 spf ~= 33333333 ns. |
| 1686 | // For whatever reason the goldfish/qcom cameras report this as |
| 1687 | // 33331760, so copying that. |
| 1688 | int64_t min_frame_duration = 33331760; |
| 1689 | |
| 1690 | mMinFrameDurations.push_back( |
| 1691 | {{hal_format, frame_size[0], frame_size[1], min_frame_duration}}); |
| 1692 | |
| 1693 | // In theory max frame duration (min frame rate) should be consistent |
| 1694 | // between all formats, but we check and only advertise the smallest |
| 1695 | // available max duration just in case. |
| 1696 | if (max_frame_duration < mMaxFrameDuration) { |
| 1697 | mMaxFrameDuration = max_frame_duration; |
| 1698 | } |
| 1699 | |
| 1700 | // We only care about min frame duration (max frame rate) for YUV. |
| 1701 | if (hal_format == HAL_PIXEL_FORMAT_YCbCr_420_888 && |
| 1702 | min_frame_duration < min_yuv_frame_duration) { |
| 1703 | min_yuv_frame_duration = min_frame_duration; |
| 1704 | } |
| 1705 | |
| 1706 | // Usually 0 for non-jpeg, non-zero for JPEG. |
| 1707 | // Randomly choosing absurd 1 sec for JPEG. Unsure what this breaks. |
| 1708 | int64_t stall_duration = 0; |
| 1709 | if (hal_format == HAL_PIXEL_FORMAT_BLOB) { |
| 1710 | stall_duration = 1000000000; |
| 1711 | } |
| 1712 | mStallDurations.push_back( |
| 1713 | {{hal_format, frame_size[0], frame_size[1], stall_duration}}); |
| 1714 | } |
| 1715 | } |
| 1716 | |
| 1717 | // This should be at minimum {mi, ma}, {ma, ma} where mi and ma |
| 1718 | // are min and max frame rates for YUV_420_888. Min should be at most 15. |
| 1719 | // Convert from frame durations measured in ns. |
| 1720 | int32_t min_yuv_fps = 1000000000 / mMaxFrameDuration; |
| 1721 | if (min_yuv_fps > 15) { |
| 1722 | return -ENODEV; |
| 1723 | } |
| 1724 | int32_t max_yuv_fps = 1000000000 / min_yuv_frame_duration; |
| 1725 | mFpsRanges.push_back({{min_yuv_fps, max_yuv_fps}}); |
| 1726 | mFpsRanges.push_back({{max_yuv_fps, max_yuv_fps}}); |
| 1727 | // Always advertise {30, 30} if max is even higher, |
| 1728 | // since this is what the default video requests use. |
| 1729 | if (max_yuv_fps > 30) { |
| 1730 | mFpsRanges.push_back({{30, 30}}); |
| 1731 | } |
| 1732 | |
| 1733 | mCharacteristicsInitialized = true; |
| 1734 | return 0; |
| 1735 | } |
| 1736 | |
Ari Hausman-Cohen | 72fddb3 | 2016-06-30 16:53:31 -0700 | [diff] [blame] | 1737 | int V4L2Camera::V4L2ToHalPixelFormat(uint32_t v4l2_format) { |
| 1738 | // Translate V4L2 format to HAL format. |
| 1739 | int hal_format = -1; |
| 1740 | switch (v4l2_format) { |
| 1741 | case V4L2_PIX_FMT_JPEG: |
| 1742 | hal_format = HAL_PIXEL_FORMAT_BLOB; |
| 1743 | break; |
| 1744 | case V4L2_PIX_FMT_YUV420: |
| 1745 | hal_format = HAL_PIXEL_FORMAT_YCbCr_420_888; |
| 1746 | break; |
| 1747 | default: |
| 1748 | // Unrecognized format. |
| 1749 | break; |
| 1750 | } |
| 1751 | return hal_format; |
| 1752 | } |
| 1753 | |
| 1754 | uint32_t V4L2Camera::halToV4L2PixelFormat(int hal_format) { |
| 1755 | // Translate HAL format to V4L2 format. |
| 1756 | uint32_t v4l2_format = 0; |
| 1757 | switch (hal_format) { |
| 1758 | case HAL_PIXEL_FORMAT_IMPLEMENTATION_DEFINED: // fall-through. |
| 1759 | case HAL_PIXEL_FORMAT_YCbCr_420_888: |
| 1760 | v4l2_format = V4L2_PIX_FMT_YUV420; |
| 1761 | break; |
| 1762 | case HAL_PIXEL_FORMAT_BLOB: |
| 1763 | v4l2_format = V4L2_PIX_FMT_JPEG; |
| 1764 | break; |
| 1765 | default: |
| 1766 | // Unrecognized format. |
| 1767 | break; |
| 1768 | } |
| 1769 | return v4l2_format; |
| 1770 | } |
| 1771 | |
Ari Hausman-Cohen | 7344215 | 2016-06-08 15:50:49 -0700 | [diff] [blame] | 1772 | } // namespace v4l2_camera_hal |