blob: 53ddf994729e8da7038d1fee07369d6e5dc434eb [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>
Eino-Ville Talvalac85f8262012-10-02 13:30:04 -070026#include <utils/KeyedVector.h>
27#include <camera/CameraParameters.h>
Eino-Ville Talvala2e19c3c2012-08-26 09:29:28 -070028
29#include "CameraMetadata.h"
30
31namespace android {
32namespace camera2 {
33
Eino-Ville Talvala69230df2012-08-29 17:37:16 -070034/**
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 Talvala2e19c3c2012-08-26 09:29:28 -070041struct Parameters {
Eino-Ville Talvala69230df2012-08-29 17:37:16 -070042 /**
43 * Parameters and other state
44 */
Eino-Ville Talvala2e19c3c2012-08-26 09:29:28 -070045 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
Eino-Ville Talvala4c843702012-10-04 00:56:40 -070091 // For use with triggerAfWithAuto quirk
92 focusMode_t shadowFocusMode;
93
Eino-Ville Talvala2e19c3c2012-08-26 09:29:28 -070094 struct Area {
95 int left, top, right, bottom;
96 int weight;
97 Area() {}
98 Area(int left, int top, int right, int bottom, int weight):
99 left(left), top(top), right(right), bottom(bottom),
100 weight(weight) {}
101 };
102 Vector<Area> focusingAreas;
103
104 int32_t exposureCompensation;
105 bool autoExposureLock;
106 bool autoWhiteBalanceLock;
107
108 Vector<Area> meteringAreas;
109
110 int zoom;
111
112 int videoWidth, videoHeight;
113
114 bool recordingHint;
115 bool videoStabilization;
116
James Painterc3dbf1a2012-09-05 18:02:32 -0700117 enum lightFxMode_t {
118 LIGHTFX_NONE = 0,
119 LIGHTFX_LOWLIGHT,
120 LIGHTFX_HDR
121 } lightFx;
122
Eino-Ville Talvalac85f8262012-10-02 13:30:04 -0700123 CameraParameters params;
Eino-Ville Talvala2e19c3c2012-08-26 09:29:28 -0700124 String8 paramsFlattened;
125
126 // These parameters are also part of the camera API-visible state, but not
127 // directly listed in Camera.Parameters
128 bool storeMetadataInBuffers;
129 bool playShutterSound;
130 bool enableFaceDetect;
131
132 bool enableFocusMoveMessages;
133 int afTriggerCounter;
134 int currentAfTriggerId;
135 bool afInMotion;
136
Eino-Ville Talvala69230df2012-08-29 17:37:16 -0700137 int precaptureTriggerCounter;
138
Eino-Ville Talvala2e19c3c2012-08-26 09:29:28 -0700139 uint32_t previewCallbackFlags;
140 bool previewCallbackOneShot;
141
Eino-Ville Talvala69230df2012-08-29 17:37:16 -0700142 bool zslMode;
143
Eino-Ville Talvala2e19c3c2012-08-26 09:29:28 -0700144 // Overall camera state
145 enum State {
146 DISCONNECTED,
147 STOPPED,
148 WAITING_FOR_PREVIEW_WINDOW,
149 PREVIEW,
150 RECORD,
151 STILL_CAPTURE,
152 VIDEO_SNAPSHOT
153 } state;
154
155 // Number of zoom steps to simulate
Eino-Ville Talvala15405322012-09-06 18:08:16 -0700156 static const unsigned int NUM_ZOOM_STEPS = 30;
Eino-Ville Talvala2e19c3c2012-08-26 09:29:28 -0700157
158 // Full static camera info, object owned by someone else, such as
159 // Camera2Device.
160 const CameraMetadata *info;
161
162 // Fast-access static device information; this is a subset of the
163 // information available through the staticInfo() method, used for
164 // frequently-accessed values or values that have to be calculated from the
165 // static information.
166 struct DeviceInfo {
167 int32_t arrayWidth;
168 int32_t arrayHeight;
169 uint8_t bestFaceDetectMode;
170 int32_t maxFaces;
Eino-Ville Talvalac85f8262012-10-02 13:30:04 -0700171 struct OverrideModes {
172 flashMode_t flashMode;
173 uint8_t wbMode;
174 focusMode_t focusMode;
175 OverrideModes():
176 flashMode(FLASH_MODE_INVALID),
177 wbMode(ANDROID_CONTROL_AWB_OFF),
178 focusMode(FOCUS_MODE_INVALID) {
179 }
180 };
181 DefaultKeyedVector<uint8_t, OverrideModes> sceneModeOverrides;
Eino-Ville Talvala2e19c3c2012-08-26 09:29:28 -0700182 } fastInfo;
183
Eino-Ville Talvalac85f8262012-10-02 13:30:04 -0700184 // Quirks information; these are short-lived flags to enable workarounds for
185 // incomplete HAL implementations
186 struct Quirks {
187 bool triggerAfWithAuto;
188 bool useZslFormat;
189 } quirks;
190
Eino-Ville Talvala69230df2012-08-29 17:37:16 -0700191 /**
192 * Parameter manipulation and setup methods
193 */
Eino-Ville Talvala2e19c3c2012-08-26 09:29:28 -0700194
195 Parameters(int cameraId, int cameraFacing);
196 ~Parameters();
197
198 // Sets up default parameters
199 status_t initialize(const CameraMetadata *info);
200
Eino-Ville Talvala596cb972012-10-02 18:14:49 -0700201 // Build fast-access device static info from static info
Eino-Ville Talvala2e19c3c2012-08-26 09:29:28 -0700202 status_t buildFastInfo();
Eino-Ville Talvala596cb972012-10-02 18:14:49 -0700203 // Query for quirks from static info
204 status_t buildQuirks();
Eino-Ville Talvala2e19c3c2012-08-26 09:29:28 -0700205
206 // Get entry from camera static characteristics information. min/maxCount
207 // are used for error checking the number of values in the entry. 0 for
208 // max/minCount means to do no bounds check in that direction. In case of
209 // error, the entry data pointer is null and the count is 0.
210 camera_metadata_ro_entry_t staticInfo(uint32_t tag,
211 size_t minCount=0, size_t maxCount=0) const;
212
213 // Validate and update camera parameters based on new settings
Eino-Ville Talvalac85f8262012-10-02 13:30:04 -0700214 status_t set(const String8 &paramString);
215
216 // Retrieve the current settings
217 String8 get() const;
Eino-Ville Talvala2e19c3c2012-08-26 09:29:28 -0700218
Eino-Ville Talvala69230df2012-08-29 17:37:16 -0700219 // Update passed-in request for common parameters
220 status_t updateRequest(CameraMetadata *request) const;
221
Eino-Ville Talvaladb30e682012-10-04 13:21:08 -0700222 // Add/update JPEG entries in metadata
223 status_t updateRequestJpeg(CameraMetadata *request) const;
224
Igor Murashkine500bc22012-09-18 18:23:49 -0700225 // Calculate the crop region rectangle based on current stream sizes
226 struct CropRegion {
227 float left;
228 float top;
229 float width;
230 float height;
231 };
232 CropRegion calculateCropRegion(void) const;
233
Eino-Ville Talvala2e19c3c2012-08-26 09:29:28 -0700234 // Static methods for debugging and converting between camera1 and camera2
235 // parameters
236
237 static const char *getStateName(State state);
238
239 static int formatStringToEnum(const char *format);
240 static const char *formatEnumToString(int format);
241
242 static int wbModeStringToEnum(const char *wbMode);
Eino-Ville Talvalac85f8262012-10-02 13:30:04 -0700243 static const char* wbModeEnumToString(uint8_t wbMode);
Eino-Ville Talvala2e19c3c2012-08-26 09:29:28 -0700244 static int effectModeStringToEnum(const char *effectMode);
245 static int abModeStringToEnum(const char *abMode);
246 static int sceneModeStringToEnum(const char *sceneMode);
247 static flashMode_t flashModeStringToEnum(const char *flashMode);
Eino-Ville Talvalac85f8262012-10-02 13:30:04 -0700248 static const char* flashModeEnumToString(flashMode_t flashMode);
Eino-Ville Talvala2e19c3c2012-08-26 09:29:28 -0700249 static focusMode_t focusModeStringToEnum(const char *focusMode);
Eino-Ville Talvalac85f8262012-10-02 13:30:04 -0700250 static const char* focusModeEnumToString(focusMode_t focusMode);
Eino-Ville Talvala2e19c3c2012-08-26 09:29:28 -0700251 static status_t parseAreas(const char *areasCStr,
252 Vector<Area> *areas);
253 static status_t validateAreas(const Vector<Area> &areas,
254 size_t maxRegions);
255 static bool boolFromString(const char *boolStr);
256
257 // Map from camera orientation + facing to gralloc transform enum
258 static int degToTransform(int degrees, bool mirror);
259
Eino-Ville Talvala823b7862012-09-27 18:08:20 -0700260 // API specifies FPS ranges are done in fixed point integer, with LSB = 0.001.
261 // Note that this doesn't apply to the (deprecated) single FPS value.
Eino-Ville Talvalab5d91132012-09-27 14:18:13 -0700262 static const int kFpsToApiScale = 1000;
263
Eino-Ville Talvala2e19c3c2012-08-26 09:29:28 -0700264 // Transform between (-1000,-1000)-(1000,1000) normalized coords from camera
265 // API and HAL2 (0,0)-(activePixelArray.width/height) coordinates
266 int arrayXToNormalized(int width) const;
267 int arrayYToNormalized(int height) const;
268 int normalizedXToArray(int x) const;
269 int normalizedYToArray(int y) const;
Eino-Ville Talvala2e19c3c2012-08-26 09:29:28 -0700270};
271
272// This class encapsulates the Parameters class so that it can only be accessed
273// by constructing a Lock object, which locks the SharedParameter's mutex.
274class SharedParameters {
275 public:
276 SharedParameters(int cameraId, int cameraFacing):
277 mParameters(cameraId, cameraFacing) {
278 }
279
280 template<typename S, typename P>
281 class BaseLock {
282 public:
283 BaseLock(S &p):
284 mParameters(p.mParameters),
285 mSharedParameters(p) {
286 mSharedParameters.mLock.lock();
287 }
288
289 ~BaseLock() {
290 mSharedParameters.mLock.unlock();
291 }
292 P &mParameters;
293 private:
294 // Disallow copying, default construction
295 BaseLock();
296 BaseLock(const BaseLock &);
297 BaseLock &operator=(const BaseLock &);
298 S &mSharedParameters;
299 };
300 typedef BaseLock<SharedParameters, Parameters> Lock;
301 typedef BaseLock<const SharedParameters, const Parameters> ReadLock;
302
303 // Access static info, read-only and immutable, so no lock needed
304 camera_metadata_ro_entry_t staticInfo(uint32_t tag,
305 size_t minCount=0, size_t maxCount=0) const {
306 return mParameters.staticInfo(tag, minCount, maxCount);
307 }
308
309 // Only use for dumping or other debugging
310 const Parameters &unsafeAccess() {
311 return mParameters;
312 }
313 private:
314 Parameters mParameters;
315 mutable Mutex mLock;
316};
317
318
319}; // namespace camera2
320}; // namespace android
321
322#endif