Eino-Ville Talvala | 2e19c3c | 2012-08-26 09:29:28 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2012 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 | #ifndef ANDROID_SERVERS_CAMERA_CAMERA2PARAMETERS_H |
| 18 | #define ANDROID_SERVERS_CAMERA_CAMERA2PARAMETERS_H |
| 19 | |
| 20 | #include <system/graphics.h> |
| 21 | |
| 22 | #include <utils/Errors.h> |
| 23 | #include <utils/Mutex.h> |
| 24 | #include <utils/String8.h> |
| 25 | #include <utils/Vector.h> |
Eino-Ville Talvala | c85f826 | 2012-10-02 13:30:04 -0700 | [diff] [blame^] | 26 | #include <utils/KeyedVector.h> |
| 27 | #include <camera/CameraParameters.h> |
Eino-Ville Talvala | 2e19c3c | 2012-08-26 09:29:28 -0700 | [diff] [blame] | 28 | |
| 29 | #include "CameraMetadata.h" |
| 30 | |
| 31 | namespace android { |
| 32 | namespace camera2 { |
| 33 | |
Eino-Ville Talvala | 69230df | 2012-08-29 17:37:16 -0700 | [diff] [blame] | 34 | /** |
| 35 | * Current camera state; this is the full state of the Camera under the old |
| 36 | * camera API (contents of the CameraParameters object in a more-efficient |
| 37 | * format, plus other state). The enum values are mostly based off the |
| 38 | * corresponding camera2 enums, not the camera1 strings. A few are defined here |
| 39 | * if they don't cleanly map to camera2 values. |
| 40 | */ |
Eino-Ville Talvala | 2e19c3c | 2012-08-26 09:29:28 -0700 | [diff] [blame] | 41 | struct Parameters { |
Eino-Ville Talvala | 69230df | 2012-08-29 17:37:16 -0700 | [diff] [blame] | 42 | /** |
| 43 | * Parameters and other state |
| 44 | */ |
Eino-Ville Talvala | 2e19c3c | 2012-08-26 09:29:28 -0700 | [diff] [blame] | 45 | int cameraId; |
| 46 | int cameraFacing; |
| 47 | |
| 48 | int previewWidth, previewHeight; |
| 49 | int32_t previewFpsRange[2]; |
| 50 | int previewFps; // deprecated, here only for tracking changes |
| 51 | int previewFormat; |
| 52 | |
| 53 | int previewTransform; // set by CAMERA_CMD_SET_DISPLAY_ORIENTATION |
| 54 | |
| 55 | int pictureWidth, pictureHeight; |
| 56 | |
| 57 | int32_t jpegThumbSize[2]; |
| 58 | int32_t jpegQuality, jpegThumbQuality; |
| 59 | int32_t jpegRotation; |
| 60 | |
| 61 | bool gpsEnabled; |
| 62 | double gpsCoordinates[3]; |
| 63 | int64_t gpsTimestamp; |
| 64 | String8 gpsProcessingMethod; |
| 65 | |
| 66 | uint8_t wbMode; |
| 67 | uint8_t effectMode; |
| 68 | uint8_t antibandingMode; |
| 69 | uint8_t sceneMode; |
| 70 | |
| 71 | enum flashMode_t { |
| 72 | FLASH_MODE_OFF = 0, |
| 73 | FLASH_MODE_AUTO, |
| 74 | FLASH_MODE_ON, |
| 75 | FLASH_MODE_TORCH, |
| 76 | FLASH_MODE_RED_EYE = ANDROID_CONTROL_AE_ON_AUTO_FLASH_REDEYE, |
| 77 | FLASH_MODE_INVALID = -1 |
| 78 | } flashMode; |
| 79 | |
| 80 | enum focusMode_t { |
| 81 | FOCUS_MODE_AUTO = ANDROID_CONTROL_AF_AUTO, |
| 82 | FOCUS_MODE_MACRO = ANDROID_CONTROL_AF_MACRO, |
| 83 | FOCUS_MODE_CONTINUOUS_VIDEO = ANDROID_CONTROL_AF_CONTINUOUS_VIDEO, |
| 84 | FOCUS_MODE_CONTINUOUS_PICTURE = ANDROID_CONTROL_AF_CONTINUOUS_PICTURE, |
| 85 | FOCUS_MODE_EDOF = ANDROID_CONTROL_AF_EDOF, |
| 86 | FOCUS_MODE_INFINITY, |
| 87 | FOCUS_MODE_FIXED, |
| 88 | FOCUS_MODE_INVALID = -1 |
| 89 | } focusMode; |
| 90 | |
| 91 | struct Area { |
| 92 | int left, top, right, bottom; |
| 93 | int weight; |
| 94 | Area() {} |
| 95 | Area(int left, int top, int right, int bottom, int weight): |
| 96 | left(left), top(top), right(right), bottom(bottom), |
| 97 | weight(weight) {} |
| 98 | }; |
| 99 | Vector<Area> focusingAreas; |
| 100 | |
| 101 | int32_t exposureCompensation; |
| 102 | bool autoExposureLock; |
| 103 | bool autoWhiteBalanceLock; |
| 104 | |
| 105 | Vector<Area> meteringAreas; |
| 106 | |
| 107 | int zoom; |
| 108 | |
| 109 | int videoWidth, videoHeight; |
| 110 | |
| 111 | bool recordingHint; |
| 112 | bool videoStabilization; |
| 113 | |
James Painter | c3dbf1a | 2012-09-05 18:02:32 -0700 | [diff] [blame] | 114 | enum lightFxMode_t { |
| 115 | LIGHTFX_NONE = 0, |
| 116 | LIGHTFX_LOWLIGHT, |
| 117 | LIGHTFX_HDR |
| 118 | } lightFx; |
| 119 | |
Eino-Ville Talvala | c85f826 | 2012-10-02 13:30:04 -0700 | [diff] [blame^] | 120 | CameraParameters params; |
Eino-Ville Talvala | 2e19c3c | 2012-08-26 09:29:28 -0700 | [diff] [blame] | 121 | String8 paramsFlattened; |
| 122 | |
| 123 | // These parameters are also part of the camera API-visible state, but not |
| 124 | // directly listed in Camera.Parameters |
| 125 | bool storeMetadataInBuffers; |
| 126 | bool playShutterSound; |
| 127 | bool enableFaceDetect; |
| 128 | |
| 129 | bool enableFocusMoveMessages; |
| 130 | int afTriggerCounter; |
| 131 | int currentAfTriggerId; |
| 132 | bool afInMotion; |
| 133 | |
Eino-Ville Talvala | 69230df | 2012-08-29 17:37:16 -0700 | [diff] [blame] | 134 | int precaptureTriggerCounter; |
| 135 | |
Eino-Ville Talvala | 2e19c3c | 2012-08-26 09:29:28 -0700 | [diff] [blame] | 136 | uint32_t previewCallbackFlags; |
| 137 | bool previewCallbackOneShot; |
| 138 | |
Eino-Ville Talvala | 69230df | 2012-08-29 17:37:16 -0700 | [diff] [blame] | 139 | bool zslMode; |
| 140 | |
Eino-Ville Talvala | 2e19c3c | 2012-08-26 09:29:28 -0700 | [diff] [blame] | 141 | // Overall camera state |
| 142 | enum State { |
| 143 | DISCONNECTED, |
| 144 | STOPPED, |
| 145 | WAITING_FOR_PREVIEW_WINDOW, |
| 146 | PREVIEW, |
| 147 | RECORD, |
| 148 | STILL_CAPTURE, |
| 149 | VIDEO_SNAPSHOT |
| 150 | } state; |
| 151 | |
| 152 | // Number of zoom steps to simulate |
Eino-Ville Talvala | 1540532 | 2012-09-06 18:08:16 -0700 | [diff] [blame] | 153 | static const unsigned int NUM_ZOOM_STEPS = 30; |
Eino-Ville Talvala | 2e19c3c | 2012-08-26 09:29:28 -0700 | [diff] [blame] | 154 | |
| 155 | // Full static camera info, object owned by someone else, such as |
| 156 | // Camera2Device. |
| 157 | const CameraMetadata *info; |
| 158 | |
| 159 | // Fast-access static device information; this is a subset of the |
| 160 | // information available through the staticInfo() method, used for |
| 161 | // frequently-accessed values or values that have to be calculated from the |
| 162 | // static information. |
| 163 | struct DeviceInfo { |
| 164 | int32_t arrayWidth; |
| 165 | int32_t arrayHeight; |
| 166 | uint8_t bestFaceDetectMode; |
| 167 | int32_t maxFaces; |
Eino-Ville Talvala | c85f826 | 2012-10-02 13:30:04 -0700 | [diff] [blame^] | 168 | struct OverrideModes { |
| 169 | flashMode_t flashMode; |
| 170 | uint8_t wbMode; |
| 171 | focusMode_t focusMode; |
| 172 | OverrideModes(): |
| 173 | flashMode(FLASH_MODE_INVALID), |
| 174 | wbMode(ANDROID_CONTROL_AWB_OFF), |
| 175 | focusMode(FOCUS_MODE_INVALID) { |
| 176 | } |
| 177 | }; |
| 178 | DefaultKeyedVector<uint8_t, OverrideModes> sceneModeOverrides; |
Eino-Ville Talvala | 2e19c3c | 2012-08-26 09:29:28 -0700 | [diff] [blame] | 179 | } fastInfo; |
| 180 | |
Eino-Ville Talvala | c85f826 | 2012-10-02 13:30:04 -0700 | [diff] [blame^] | 181 | // Quirks information; these are short-lived flags to enable workarounds for |
| 182 | // incomplete HAL implementations |
| 183 | struct Quirks { |
| 184 | bool triggerAfWithAuto; |
| 185 | bool useZslFormat; |
| 186 | } quirks; |
| 187 | |
Eino-Ville Talvala | 69230df | 2012-08-29 17:37:16 -0700 | [diff] [blame] | 188 | /** |
| 189 | * Parameter manipulation and setup methods |
| 190 | */ |
Eino-Ville Talvala | 2e19c3c | 2012-08-26 09:29:28 -0700 | [diff] [blame] | 191 | |
| 192 | Parameters(int cameraId, int cameraFacing); |
| 193 | ~Parameters(); |
| 194 | |
| 195 | // Sets up default parameters |
| 196 | status_t initialize(const CameraMetadata *info); |
| 197 | |
| 198 | // Build fast device info |
| 199 | status_t buildFastInfo(); |
| 200 | |
| 201 | // Get entry from camera static characteristics information. min/maxCount |
| 202 | // are used for error checking the number of values in the entry. 0 for |
| 203 | // max/minCount means to do no bounds check in that direction. In case of |
| 204 | // error, the entry data pointer is null and the count is 0. |
| 205 | camera_metadata_ro_entry_t staticInfo(uint32_t tag, |
| 206 | size_t minCount=0, size_t maxCount=0) const; |
| 207 | |
| 208 | // Validate and update camera parameters based on new settings |
Eino-Ville Talvala | c85f826 | 2012-10-02 13:30:04 -0700 | [diff] [blame^] | 209 | status_t set(const String8 ¶mString); |
| 210 | |
| 211 | // Retrieve the current settings |
| 212 | String8 get() const; |
Eino-Ville Talvala | 2e19c3c | 2012-08-26 09:29:28 -0700 | [diff] [blame] | 213 | |
Eino-Ville Talvala | 69230df | 2012-08-29 17:37:16 -0700 | [diff] [blame] | 214 | // Update passed-in request for common parameters |
| 215 | status_t updateRequest(CameraMetadata *request) const; |
| 216 | |
Igor Murashkin | e500bc2 | 2012-09-18 18:23:49 -0700 | [diff] [blame] | 217 | // Calculate the crop region rectangle based on current stream sizes |
| 218 | struct CropRegion { |
| 219 | float left; |
| 220 | float top; |
| 221 | float width; |
| 222 | float height; |
| 223 | }; |
| 224 | CropRegion calculateCropRegion(void) const; |
| 225 | |
Eino-Ville Talvala | 2e19c3c | 2012-08-26 09:29:28 -0700 | [diff] [blame] | 226 | // Static methods for debugging and converting between camera1 and camera2 |
| 227 | // parameters |
| 228 | |
| 229 | static const char *getStateName(State state); |
| 230 | |
| 231 | static int formatStringToEnum(const char *format); |
| 232 | static const char *formatEnumToString(int format); |
| 233 | |
| 234 | static int wbModeStringToEnum(const char *wbMode); |
Eino-Ville Talvala | c85f826 | 2012-10-02 13:30:04 -0700 | [diff] [blame^] | 235 | static const char* wbModeEnumToString(uint8_t wbMode); |
Eino-Ville Talvala | 2e19c3c | 2012-08-26 09:29:28 -0700 | [diff] [blame] | 236 | static int effectModeStringToEnum(const char *effectMode); |
| 237 | static int abModeStringToEnum(const char *abMode); |
| 238 | static int sceneModeStringToEnum(const char *sceneMode); |
| 239 | static flashMode_t flashModeStringToEnum(const char *flashMode); |
Eino-Ville Talvala | c85f826 | 2012-10-02 13:30:04 -0700 | [diff] [blame^] | 240 | static const char* flashModeEnumToString(flashMode_t flashMode); |
Eino-Ville Talvala | 2e19c3c | 2012-08-26 09:29:28 -0700 | [diff] [blame] | 241 | static focusMode_t focusModeStringToEnum(const char *focusMode); |
Eino-Ville Talvala | c85f826 | 2012-10-02 13:30:04 -0700 | [diff] [blame^] | 242 | static const char* focusModeEnumToString(focusMode_t focusMode); |
Eino-Ville Talvala | 2e19c3c | 2012-08-26 09:29:28 -0700 | [diff] [blame] | 243 | static status_t parseAreas(const char *areasCStr, |
| 244 | Vector<Area> *areas); |
| 245 | static status_t validateAreas(const Vector<Area> &areas, |
| 246 | size_t maxRegions); |
| 247 | static bool boolFromString(const char *boolStr); |
| 248 | |
| 249 | // Map from camera orientation + facing to gralloc transform enum |
| 250 | static int degToTransform(int degrees, bool mirror); |
| 251 | |
Eino-Ville Talvala | 823b786 | 2012-09-27 18:08:20 -0700 | [diff] [blame] | 252 | // API specifies FPS ranges are done in fixed point integer, with LSB = 0.001. |
| 253 | // Note that this doesn't apply to the (deprecated) single FPS value. |
Eino-Ville Talvala | b5d9113 | 2012-09-27 14:18:13 -0700 | [diff] [blame] | 254 | static const int kFpsToApiScale = 1000; |
| 255 | |
Eino-Ville Talvala | 2e19c3c | 2012-08-26 09:29:28 -0700 | [diff] [blame] | 256 | // Transform between (-1000,-1000)-(1000,1000) normalized coords from camera |
| 257 | // API and HAL2 (0,0)-(activePixelArray.width/height) coordinates |
| 258 | int arrayXToNormalized(int width) const; |
| 259 | int arrayYToNormalized(int height) const; |
| 260 | int normalizedXToArray(int x) const; |
| 261 | int normalizedYToArray(int y) const; |
Eino-Ville Talvala | 2e19c3c | 2012-08-26 09:29:28 -0700 | [diff] [blame] | 262 | }; |
| 263 | |
| 264 | // This class encapsulates the Parameters class so that it can only be accessed |
| 265 | // by constructing a Lock object, which locks the SharedParameter's mutex. |
| 266 | class SharedParameters { |
| 267 | public: |
| 268 | SharedParameters(int cameraId, int cameraFacing): |
| 269 | mParameters(cameraId, cameraFacing) { |
| 270 | } |
| 271 | |
| 272 | template<typename S, typename P> |
| 273 | class BaseLock { |
| 274 | public: |
| 275 | BaseLock(S &p): |
| 276 | mParameters(p.mParameters), |
| 277 | mSharedParameters(p) { |
| 278 | mSharedParameters.mLock.lock(); |
| 279 | } |
| 280 | |
| 281 | ~BaseLock() { |
| 282 | mSharedParameters.mLock.unlock(); |
| 283 | } |
| 284 | P &mParameters; |
| 285 | private: |
| 286 | // Disallow copying, default construction |
| 287 | BaseLock(); |
| 288 | BaseLock(const BaseLock &); |
| 289 | BaseLock &operator=(const BaseLock &); |
| 290 | S &mSharedParameters; |
| 291 | }; |
| 292 | typedef BaseLock<SharedParameters, Parameters> Lock; |
| 293 | typedef BaseLock<const SharedParameters, const Parameters> ReadLock; |
| 294 | |
| 295 | // Access static info, read-only and immutable, so no lock needed |
| 296 | camera_metadata_ro_entry_t staticInfo(uint32_t tag, |
| 297 | size_t minCount=0, size_t maxCount=0) const { |
| 298 | return mParameters.staticInfo(tag, minCount, maxCount); |
| 299 | } |
| 300 | |
| 301 | // Only use for dumping or other debugging |
| 302 | const Parameters &unsafeAccess() { |
| 303 | return mParameters; |
| 304 | } |
| 305 | private: |
| 306 | Parameters mParameters; |
| 307 | mutable Mutex mLock; |
| 308 | }; |
| 309 | |
| 310 | |
| 311 | }; // namespace camera2 |
| 312 | }; // namespace android |
| 313 | |
| 314 | #endif |