blob: 817d0019c9341146f6187006c59fd119d977405d [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
32// Current camera state; this is the full state of the Camera under the old
33// camera API (contents of the CameraParameters object in a more-efficient
34// format, plus other state). The enum values are mostly based off the
35// corresponding camera2 enums, not the camera1 strings. A few are defined here
36// if they don't cleanly map to camera2 values.
37struct Parameters {
38 int cameraId;
39 int cameraFacing;
40
41 int previewWidth, previewHeight;
42 int32_t previewFpsRange[2];
43 int previewFps; // deprecated, here only for tracking changes
44 int previewFormat;
45
46 int previewTransform; // set by CAMERA_CMD_SET_DISPLAY_ORIENTATION
47
48 int pictureWidth, pictureHeight;
49
50 int32_t jpegThumbSize[2];
51 int32_t jpegQuality, jpegThumbQuality;
52 int32_t jpegRotation;
53
54 bool gpsEnabled;
55 double gpsCoordinates[3];
56 int64_t gpsTimestamp;
57 String8 gpsProcessingMethod;
58
59 uint8_t wbMode;
60 uint8_t effectMode;
61 uint8_t antibandingMode;
62 uint8_t sceneMode;
63
64 enum flashMode_t {
65 FLASH_MODE_OFF = 0,
66 FLASH_MODE_AUTO,
67 FLASH_MODE_ON,
68 FLASH_MODE_TORCH,
69 FLASH_MODE_RED_EYE = ANDROID_CONTROL_AE_ON_AUTO_FLASH_REDEYE,
70 FLASH_MODE_INVALID = -1
71 } flashMode;
72
73 enum focusMode_t {
74 FOCUS_MODE_AUTO = ANDROID_CONTROL_AF_AUTO,
75 FOCUS_MODE_MACRO = ANDROID_CONTROL_AF_MACRO,
76 FOCUS_MODE_CONTINUOUS_VIDEO = ANDROID_CONTROL_AF_CONTINUOUS_VIDEO,
77 FOCUS_MODE_CONTINUOUS_PICTURE = ANDROID_CONTROL_AF_CONTINUOUS_PICTURE,
78 FOCUS_MODE_EDOF = ANDROID_CONTROL_AF_EDOF,
79 FOCUS_MODE_INFINITY,
80 FOCUS_MODE_FIXED,
81 FOCUS_MODE_INVALID = -1
82 } focusMode;
83
84 struct Area {
85 int left, top, right, bottom;
86 int weight;
87 Area() {}
88 Area(int left, int top, int right, int bottom, int weight):
89 left(left), top(top), right(right), bottom(bottom),
90 weight(weight) {}
91 };
92 Vector<Area> focusingAreas;
93
94 int32_t exposureCompensation;
95 bool autoExposureLock;
96 bool autoWhiteBalanceLock;
97
98 Vector<Area> meteringAreas;
99
100 int zoom;
101
102 int videoWidth, videoHeight;
103
104 bool recordingHint;
105 bool videoStabilization;
106
107 String8 paramsFlattened;
108
109 // These parameters are also part of the camera API-visible state, but not
110 // directly listed in Camera.Parameters
111 bool storeMetadataInBuffers;
112 bool playShutterSound;
113 bool enableFaceDetect;
114
115 bool enableFocusMoveMessages;
116 int afTriggerCounter;
117 int currentAfTriggerId;
118 bool afInMotion;
119
120 uint32_t previewCallbackFlags;
121 bool previewCallbackOneShot;
122
123 // Overall camera state
124 enum State {
125 DISCONNECTED,
126 STOPPED,
127 WAITING_FOR_PREVIEW_WINDOW,
128 PREVIEW,
129 RECORD,
130 STILL_CAPTURE,
131 VIDEO_SNAPSHOT
132 } state;
133
134 // Number of zoom steps to simulate
135 static const unsigned int NUM_ZOOM_STEPS = 10;
136
137 // Full static camera info, object owned by someone else, such as
138 // Camera2Device.
139 const CameraMetadata *info;
140
141 // Fast-access static device information; this is a subset of the
142 // information available through the staticInfo() method, used for
143 // frequently-accessed values or values that have to be calculated from the
144 // static information.
145 struct DeviceInfo {
146 int32_t arrayWidth;
147 int32_t arrayHeight;
148 uint8_t bestFaceDetectMode;
149 int32_t maxFaces;
150 } fastInfo;
151
152 // Parameter manipulation and setup methods
153
154 Parameters(int cameraId, int cameraFacing);
155 ~Parameters();
156
157 // Sets up default parameters
158 status_t initialize(const CameraMetadata *info);
159
160 // Build fast device info
161 status_t buildFastInfo();
162
163 // Get entry from camera static characteristics information. min/maxCount
164 // are used for error checking the number of values in the entry. 0 for
165 // max/minCount means to do no bounds check in that direction. In case of
166 // error, the entry data pointer is null and the count is 0.
167 camera_metadata_ro_entry_t staticInfo(uint32_t tag,
168 size_t minCount=0, size_t maxCount=0) const;
169
170 // Validate and update camera parameters based on new settings
171 status_t set(const String8 &params);
172
173 // Static methods for debugging and converting between camera1 and camera2
174 // parameters
175
176 static const char *getStateName(State state);
177
178 static int formatStringToEnum(const char *format);
179 static const char *formatEnumToString(int format);
180
181 static int wbModeStringToEnum(const char *wbMode);
182 static int effectModeStringToEnum(const char *effectMode);
183 static int abModeStringToEnum(const char *abMode);
184 static int sceneModeStringToEnum(const char *sceneMode);
185 static flashMode_t flashModeStringToEnum(const char *flashMode);
186 static focusMode_t focusModeStringToEnum(const char *focusMode);
187 static status_t parseAreas(const char *areasCStr,
188 Vector<Area> *areas);
189 static status_t validateAreas(const Vector<Area> &areas,
190 size_t maxRegions);
191 static bool boolFromString(const char *boolStr);
192
193 // Map from camera orientation + facing to gralloc transform enum
194 static int degToTransform(int degrees, bool mirror);
195
196 // Transform between (-1000,-1000)-(1000,1000) normalized coords from camera
197 // API and HAL2 (0,0)-(activePixelArray.width/height) coordinates
198 int arrayXToNormalized(int width) const;
199 int arrayYToNormalized(int height) const;
200 int normalizedXToArray(int x) const;
201 int normalizedYToArray(int y) const;
202
203};
204
205// This class encapsulates the Parameters class so that it can only be accessed
206// by constructing a Lock object, which locks the SharedParameter's mutex.
207class SharedParameters {
208 public:
209 SharedParameters(int cameraId, int cameraFacing):
210 mParameters(cameraId, cameraFacing) {
211 }
212
213 template<typename S, typename P>
214 class BaseLock {
215 public:
216 BaseLock(S &p):
217 mParameters(p.mParameters),
218 mSharedParameters(p) {
219 mSharedParameters.mLock.lock();
220 }
221
222 ~BaseLock() {
223 mSharedParameters.mLock.unlock();
224 }
225 P &mParameters;
226 private:
227 // Disallow copying, default construction
228 BaseLock();
229 BaseLock(const BaseLock &);
230 BaseLock &operator=(const BaseLock &);
231 S &mSharedParameters;
232 };
233 typedef BaseLock<SharedParameters, Parameters> Lock;
234 typedef BaseLock<const SharedParameters, const Parameters> ReadLock;
235
236 // Access static info, read-only and immutable, so no lock needed
237 camera_metadata_ro_entry_t staticInfo(uint32_t tag,
238 size_t minCount=0, size_t maxCount=0) const {
239 return mParameters.staticInfo(tag, minCount, maxCount);
240 }
241
242 // Only use for dumping or other debugging
243 const Parameters &unsafeAccess() {
244 return mParameters;
245 }
246 private:
247 Parameters mParameters;
248 mutable Mutex mLock;
249};
250
251
252}; // namespace camera2
253}; // namespace android
254
255#endif