blob: e457bec390348bef0e92bad4c857cef501f9305e [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,
74 PREVIEW
75 } mState;
76
Eino-Ville Talvala3cca1362012-06-07 10:07:18 -070077 /** ICamera interface-related private members */
Eino-Ville Talvala61ab9f92012-05-17 10:30:54 -070078
Eino-Ville Talvala3cca1362012-06-07 10:07:18 -070079 status_t setPreviewWindow(const sp<IBinder>& binder,
80 const sp<ANativeWindow>& window);
81 String8 mParamsFlattened;
82 // Current camera state; this is the contents of the CameraParameters object
83 // in a more-efficient format. The enum values are mostly based off the
84 // corresponding camera2 enums, not the camera1 strings. A few are defined
85 // here if they don't cleanly map to camera2 values.
86 struct Parameters {
87 int previewWidth, previewHeight;
88 int previewFpsRangeMin, previewFpsRangeMax;
89 int previewFps; // deprecated, here only for tracking changes
90 int previewFormat;
91
92 int pictureWidth, pictureHeight;
93
94 int jpegThumbWidth, jpegThumbHeight;
95 int jpegQuality, jpegThumbQuality;
96 int jpegRotation;
97
98 bool gpsEnabled;
99 double gpsLatitude;
100 double gpsLongitude;
101 double gpsAltitude;
102 int64_t gpsTimestamp;
103 String8 gpsProcessingMethod;
104
105 int wbMode;
106 int effectMode;
107 int antibandingMode;
108 int sceneMode;
109
110 enum flashMode_t {
111 FLASH_MODE_OFF = 0,
112 FLASH_MODE_AUTO,
113 FLASH_MODE_ON,
114 FLASH_MODE_TORCH,
115 FLASH_MODE_RED_EYE = ANDROID_CONTROL_AE_ON_AUTO_FLASH_REDEYE,
116 FLASH_MODE_INVALID = -1
117 } flashMode;
118
119 enum focusMode_t {
120 FOCUS_MODE_AUTO = ANDROID_CONTROL_AF_AUTO,
121 FOCUS_MODE_MACRO = ANDROID_CONTROL_AF_MACRO,
122 FOCUS_MODE_CONTINUOUS_VIDEO = ANDROID_CONTROL_AF_CONTINUOUS_VIDEO,
123 FOCUS_MODE_CONTINUOUS_PICTURE =
124 ANDROID_CONTROL_AF_CONTINUOUS_PICTURE,
125 FOCUS_MODE_EDOF = ANDROID_CONTROL_AF_EDOF,
126 FOCUS_MODE_INFINITY,
127 FOCUS_MODE_FIXED,
128 FOCUS_MODE_INVALID = -1
129 } focusMode;
130
131 struct Area {
132 int left, top, right, bottom;
133 int weight;
134 Area() {}
135 Area(int left, int top, int right, int bottom, int weight):
136 left(left), top(top), right(right), bottom(bottom),
137 weight(weight) {}
138 };
139 Vector<Area> focusingAreas;
140
141 int exposureCompensation;
142 bool autoExposureLock;
143 bool autoWhiteBalanceLock;
144
145 Vector<Area> meteringAreas;
146
147 int zoom;
148
149 int videoWidth, videoHeight;
150
151 bool recordingHint;
152 bool videoStabilization;
153 } mParameters;
154
155 /** Camera device-related private members */
156
157 // Number of zoom steps to simulate
158 static const unsigned int NUM_ZOOM_STEPS = 10;
159 // Used with mPreviewStreamId
160 static const int NO_PREVIEW_STREAM = -1;
Eino-Ville Talvala6db981c2012-05-21 18:54:30 -0700161
162 sp<IBinder> mPreviewSurface;
163 int mPreviewStreamId;
164 camera_metadata_t *mPreviewRequest;
165
Eino-Ville Talvala3cca1362012-06-07 10:07:18 -0700166 camera_metadata_t *mCaptureRequest;
167
168 sp<Camera2Device> mDevice;
169
170
171 // Get values for static camera info entry. min/maxCount are used for error
172 // checking the number of values in the entry. 0 for max/minCount means to
173 // do no bounds check in that direction. In case of error, the entry data
174 // pointer is null and the count is 0.
175 camera_metadata_entry_t staticInfo(uint32_t tag,
176 size_t minCount=0, size_t maxCount=0);
177
178 /** Utility methods */
Eino-Ville Talvala6db981c2012-05-21 18:54:30 -0700179
Eino-Ville Talvalaf69c70d2012-05-20 15:59:14 -0700180 // Convert static camera info from a camera2 device to the
181 // old API parameter map.
182 status_t buildDefaultParameters();
Eino-Ville Talvala61ab9f92012-05-17 10:30:54 -0700183
Eino-Ville Talvala6db981c2012-05-21 18:54:30 -0700184 // Update preview request based on mParams
185 status_t updatePreviewRequest();
Eino-Ville Talvala3cca1362012-06-07 10:07:18 -0700186 static const char *formatEnumToString(int format);
Eino-Ville Talvala61ab9f92012-05-17 10:30:54 -0700187};
188
189}; // namespace android
190
191#endif