Eino-Ville Talvala | 61ab9f9 | 2012-05-17 10:30:54 -0700 | [diff] [blame] | 1 | /* |
| 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 Talvala | f69c70d | 2012-05-20 15:59:14 -0700 | [diff] [blame] | 22 | #include "camera/CameraParameters.h" |
Eino-Ville Talvala | 61ab9f9 | 2012-05-17 10:30:54 -0700 | [diff] [blame] | 23 | |
| 24 | namespace android { |
| 25 | |
| 26 | /** |
| 27 | * Implements the android.hardware.camera API on top of |
| 28 | * camera device HAL version 2. |
| 29 | */ |
| 30 | class Camera2Client : public CameraService::Client |
| 31 | { |
| 32 | public: |
| 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 Talvala | 6db981c | 2012-05-21 18:54:30 -0700 | [diff] [blame] | 39 | virtual status_t setPreviewTexture( |
| 40 | const sp<ISurfaceTexture>& surfaceTexture); |
Eino-Ville Talvala | 61ab9f9 | 2012-05-17 10:30:54 -0700 | [diff] [blame] | 41 | 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 Talvala | 61ab9f9 | 2012-05-17 10:30:54 -0700 | [diff] [blame] | 60 | int cameraId, |
| 61 | int cameraFacing, |
| 62 | int clientPid); |
| 63 | ~Camera2Client(); |
| 64 | |
Eino-Ville Talvala | f69c70d | 2012-05-20 15:59:14 -0700 | [diff] [blame] | 65 | status_t initialize(camera_module_t *module); |
| 66 | |
Eino-Ville Talvala | 61ab9f9 | 2012-05-17 10:30:54 -0700 | [diff] [blame] | 67 | virtual status_t dump(int fd, const Vector<String16>& args); |
| 68 | |
| 69 | private: |
Eino-Ville Talvala | 6db981c | 2012-05-21 18:54:30 -0700 | [diff] [blame] | 70 | enum { |
| 71 | NOT_INITIALIZED, |
| 72 | STOPPED, |
| 73 | WAITING_FOR_PREVIEW_WINDOW, |
Eino-Ville Talvala | 7f61084 | 2012-06-07 10:20:51 -0700 | [diff] [blame] | 74 | PREVIEW, |
| 75 | RECORD, |
| 76 | STILL_CAPTURE |
Eino-Ville Talvala | 6db981c | 2012-05-21 18:54:30 -0700 | [diff] [blame] | 77 | } mState; |
| 78 | |
Eino-Ville Talvala | 3cca136 | 2012-06-07 10:07:18 -0700 | [diff] [blame] | 79 | /** ICamera interface-related private members */ |
Eino-Ville Talvala | 61ab9f9 | 2012-05-17 10:30:54 -0700 | [diff] [blame] | 80 | |
Eino-Ville Talvala | ac45eb3 | 2012-06-07 10:24:51 -0700 | [diff] [blame] | 81 | // 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 Talvala | 3cca136 | 2012-06-07 10:07:18 -0700 | [diff] [blame] | 85 | status_t setPreviewWindow(const sp<IBinder>& binder, |
| 86 | const sp<ANativeWindow>& window); |
Eino-Ville Talvala | ac45eb3 | 2012-06-07 10:24:51 -0700 | [diff] [blame] | 87 | void stopPreviewLocked(); |
| 88 | |
| 89 | // Mutex that must be locked before accessing mParams, mParamsFlattened |
| 90 | mutable Mutex mParamsLock; |
Eino-Ville Talvala | 3cca136 | 2012-06-07 10:07:18 -0700 | [diff] [blame] | 91 | 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 Talvala | 6db981c | 2012-05-21 18:54:30 -0700 | [diff] [blame] | 171 | |
| 172 | sp<IBinder> mPreviewSurface; |
| 173 | int mPreviewStreamId; |
| 174 | camera_metadata_t *mPreviewRequest; |
| 175 | |
Eino-Ville Talvala | 3cca136 | 2012-06-07 10:07:18 -0700 | [diff] [blame] | 176 | 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 Talvala | 6db981c | 2012-05-21 18:54:30 -0700 | [diff] [blame] | 189 | |
Eino-Ville Talvala | f69c70d | 2012-05-20 15:59:14 -0700 | [diff] [blame] | 190 | // Convert static camera info from a camera2 device to the |
| 191 | // old API parameter map. |
| 192 | status_t buildDefaultParameters(); |
Eino-Ville Talvala | 61ab9f9 | 2012-05-17 10:30:54 -0700 | [diff] [blame] | 193 | |
Eino-Ville Talvala | 6db981c | 2012-05-21 18:54:30 -0700 | [diff] [blame] | 194 | // Update preview request based on mParams |
| 195 | status_t updatePreviewRequest(); |
Eino-Ville Talvala | 6861a4e | 2012-06-07 10:32:12 -0700 | [diff] [blame^] | 196 | |
| 197 | // Convert camera1 preview format string to camera2 enum |
| 198 | static int formatStringToEnum(const char *format); |
Eino-Ville Talvala | 3cca136 | 2012-06-07 10:07:18 -0700 | [diff] [blame] | 199 | static const char *formatEnumToString(int format); |
Eino-Ville Talvala | 6861a4e | 2012-06-07 10:32:12 -0700 | [diff] [blame^] | 200 | |
| 201 | static int wbModeStringToEnum(const char *wbMode); |
| 202 | static int effectModeStringToEnum(const char *effectMode); |
| 203 | static int abModeStringToEnum(const char *abMode); |
| 204 | static int sceneModeStringToEnum(const char *sceneMode); |
| 205 | static Parameters::flashMode_t flashModeStringToEnum(const char *flashMode); |
| 206 | static Parameters::focusMode_t focusModeStringToEnum(const char *focusMode); |
| 207 | static status_t parseAreas(const char *areasCStr, |
| 208 | Vector<Parameters::Area> *areas); |
| 209 | static status_t validateAreas(const Vector<Parameters::Area> &areas, |
| 210 | size_t maxRegions); |
| 211 | static bool boolFromString(const char *boolStr); |
Eino-Ville Talvala | 61ab9f9 | 2012-05-17 10:30:54 -0700 | [diff] [blame] | 212 | }; |
| 213 | |
| 214 | }; // namespace android |
| 215 | |
| 216 | #endif |