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