blob: 2bdf7d44bca9df4dccc6cecbfe79d2d0559a454b [file] [log] [blame]
Eino-Ville Talvala61ab9f92012-05-17 10:30:54 -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_CAMERA2CLIENT_H
18#define ANDROID_SERVERS_CAMERA_CAMERA2CLIENT_H
19
20#include "Camera2Device.h"
21#include "CameraService.h"
Eino-Ville Talvalaf69c70d2012-05-20 15:59:14 -070022#include "camera/CameraParameters.h"
Eino-Ville Talvala61ab9f92012-05-17 10:30:54 -070023
24namespace android {
25
26/**
27 * Implements the android.hardware.camera API on top of
28 * camera device HAL version 2.
29 */
30class Camera2Client : public CameraService::Client
31{
32public:
33 // ICamera interface (see ICamera for details)
34 virtual void disconnect();
35 virtual status_t connect(const sp<ICameraClient>& client);
36 virtual status_t lock();
37 virtual status_t unlock();
38 virtual status_t setPreviewDisplay(const sp<Surface>& surface);
Eino-Ville Talvala6db981c2012-05-21 18:54:30 -070039 virtual status_t setPreviewTexture(
40 const sp<ISurfaceTexture>& surfaceTexture);
Eino-Ville Talvala61ab9f92012-05-17 10:30:54 -070041 virtual void setPreviewCallbackFlag(int flag);
42 virtual status_t startPreview();
43 virtual void stopPreview();
44 virtual bool previewEnabled();
45 virtual status_t storeMetaDataInBuffers(bool enabled);
46 virtual status_t startRecording();
47 virtual void stopRecording();
48 virtual bool recordingEnabled();
49 virtual void releaseRecordingFrame(const sp<IMemory>& mem);
50 virtual status_t autoFocus();
51 virtual status_t cancelAutoFocus();
52 virtual status_t takePicture(int msgType);
53 virtual status_t setParameters(const String8& params);
54 virtual String8 getParameters() const;
55 virtual status_t sendCommand(int32_t cmd, int32_t arg1, int32_t arg2);
56
57 // Interface used by CameraService
58 Camera2Client(const sp<CameraService>& cameraService,
59 const sp<ICameraClient>& cameraClient,
Eino-Ville Talvala61ab9f92012-05-17 10:30:54 -070060 int cameraId,
61 int cameraFacing,
62 int clientPid);
63 ~Camera2Client();
64
Eino-Ville Talvalaf69c70d2012-05-20 15:59:14 -070065 status_t initialize(camera_module_t *module);
66
Eino-Ville Talvala61ab9f92012-05-17 10:30:54 -070067 virtual status_t dump(int fd, const Vector<String16>& args);
68
69private:
Eino-Ville Talvala6db981c2012-05-21 18:54:30 -070070 enum {
71 NOT_INITIALIZED,
72 STOPPED,
73 WAITING_FOR_PREVIEW_WINDOW,
Eino-Ville Talvala7f610842012-06-07 10:20:51 -070074 PREVIEW,
75 RECORD,
76 STILL_CAPTURE
Eino-Ville Talvala6db981c2012-05-21 18:54:30 -070077 } mState;
78
Eino-Ville Talvala3cca1362012-06-07 10:07:18 -070079 /** ICamera interface-related private members */
Eino-Ville Talvala61ab9f92012-05-17 10:30:54 -070080
Eino-Ville Talvalaac45eb32012-06-07 10:24:51 -070081 // Mutex that must be locked by methods implementing the ICamera interface.
82 // Ensures serialization between incoming ICamera calls
83 mutable Mutex mICameraLock;
84
Eino-Ville Talvala3cca1362012-06-07 10:07:18 -070085 status_t setPreviewWindow(const sp<IBinder>& binder,
86 const sp<ANativeWindow>& window);
Eino-Ville Talvalaac45eb32012-06-07 10:24:51 -070087 void stopPreviewLocked();
88
89 // Mutex that must be locked before accessing mParams, mParamsFlattened
90 mutable Mutex mParamsLock;
Eino-Ville Talvala3cca1362012-06-07 10:07:18 -070091 String8 mParamsFlattened;
92 // Current camera state; this is the contents of the CameraParameters object
93 // in a more-efficient format. The enum values are mostly based off the
94 // corresponding camera2 enums, not the camera1 strings. A few are defined
95 // here if they don't cleanly map to camera2 values.
96 struct Parameters {
97 int previewWidth, previewHeight;
98 int previewFpsRangeMin, previewFpsRangeMax;
99 int previewFps; // deprecated, here only for tracking changes
100 int previewFormat;
101
102 int pictureWidth, pictureHeight;
103
104 int jpegThumbWidth, jpegThumbHeight;
105 int jpegQuality, jpegThumbQuality;
106 int jpegRotation;
107
108 bool gpsEnabled;
109 double gpsLatitude;
110 double gpsLongitude;
111 double gpsAltitude;
112 int64_t gpsTimestamp;
113 String8 gpsProcessingMethod;
114
115 int wbMode;
116 int effectMode;
117 int antibandingMode;
118 int sceneMode;
119
120 enum flashMode_t {
121 FLASH_MODE_OFF = 0,
122 FLASH_MODE_AUTO,
123 FLASH_MODE_ON,
124 FLASH_MODE_TORCH,
125 FLASH_MODE_RED_EYE = ANDROID_CONTROL_AE_ON_AUTO_FLASH_REDEYE,
126 FLASH_MODE_INVALID = -1
127 } flashMode;
128
129 enum focusMode_t {
130 FOCUS_MODE_AUTO = ANDROID_CONTROL_AF_AUTO,
131 FOCUS_MODE_MACRO = ANDROID_CONTROL_AF_MACRO,
132 FOCUS_MODE_CONTINUOUS_VIDEO = ANDROID_CONTROL_AF_CONTINUOUS_VIDEO,
133 FOCUS_MODE_CONTINUOUS_PICTURE =
134 ANDROID_CONTROL_AF_CONTINUOUS_PICTURE,
135 FOCUS_MODE_EDOF = ANDROID_CONTROL_AF_EDOF,
136 FOCUS_MODE_INFINITY,
137 FOCUS_MODE_FIXED,
138 FOCUS_MODE_INVALID = -1
139 } focusMode;
140
141 struct Area {
142 int left, top, right, bottom;
143 int weight;
144 Area() {}
145 Area(int left, int top, int right, int bottom, int weight):
146 left(left), top(top), right(right), bottom(bottom),
147 weight(weight) {}
148 };
149 Vector<Area> focusingAreas;
150
151 int exposureCompensation;
152 bool autoExposureLock;
153 bool autoWhiteBalanceLock;
154
155 Vector<Area> meteringAreas;
156
157 int zoom;
158
159 int videoWidth, videoHeight;
160
161 bool recordingHint;
162 bool videoStabilization;
163 } mParameters;
164
165 /** Camera device-related private members */
166
167 // Number of zoom steps to simulate
168 static const unsigned int NUM_ZOOM_STEPS = 10;
169 // Used with mPreviewStreamId
170 static const int NO_PREVIEW_STREAM = -1;
Eino-Ville Talvala6db981c2012-05-21 18:54:30 -0700171
172 sp<IBinder> mPreviewSurface;
173 int mPreviewStreamId;
174 camera_metadata_t *mPreviewRequest;
175
Eino-Ville Talvala3cca1362012-06-07 10:07:18 -0700176 camera_metadata_t *mCaptureRequest;
177
178 sp<Camera2Device> mDevice;
179
180
181 // Get values for static camera info entry. min/maxCount are used for error
182 // checking the number of values in the entry. 0 for max/minCount means to
183 // do no bounds check in that direction. In case of error, the entry data
184 // pointer is null and the count is 0.
185 camera_metadata_entry_t staticInfo(uint32_t tag,
186 size_t minCount=0, size_t maxCount=0);
187
188 /** Utility methods */
Eino-Ville Talvala6db981c2012-05-21 18:54:30 -0700189
Eino-Ville Talvalaf69c70d2012-05-20 15:59:14 -0700190 // Convert static camera info from a camera2 device to the
191 // old API parameter map.
192 status_t buildDefaultParameters();
Eino-Ville Talvala61ab9f92012-05-17 10:30:54 -0700193
Eino-Ville Talvala6db981c2012-05-21 18:54:30 -0700194 // Update preview request based on mParams
195 status_t updatePreviewRequest();
Eino-Ville Talvala3cca1362012-06-07 10:07:18 -0700196 static const char *formatEnumToString(int format);
Eino-Ville Talvala61ab9f92012-05-17 10:30:54 -0700197};
198
199}; // namespace android
200
201#endif