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 | d4bcfde | 2012-06-07 17:12:38 -0700 | [diff] [blame] | 23 | #include <binder/MemoryBase.h> |
| 24 | #include <binder/MemoryHeapBase.h> |
| 25 | #include <gui/CpuConsumer.h> |
Eino-Ville Talvala | 30e65e7 | 2012-08-21 13:30:45 -0700 | [diff] [blame] | 26 | #include <gui/BufferItemConsumer.h> |
Eino-Ville Talvala | 61ab9f9 | 2012-05-17 10:30:54 -0700 | [diff] [blame] | 27 | |
| 28 | namespace android { |
| 29 | |
| 30 | /** |
| 31 | * Implements the android.hardware.camera API on top of |
| 32 | * camera device HAL version 2. |
| 33 | */ |
Eino-Ville Talvala | 8ce89d9 | 2012-08-10 08:40:26 -0700 | [diff] [blame] | 34 | class Camera2Client : |
| 35 | public CameraService::Client, |
Eino-Ville Talvala | c8474b6 | 2012-08-24 16:30:44 -0700 | [diff] [blame^] | 36 | public Camera2Device::NotificationListener |
Eino-Ville Talvala | 61ab9f9 | 2012-05-17 10:30:54 -0700 | [diff] [blame] | 37 | { |
| 38 | public: |
| 39 | // ICamera interface (see ICamera for details) |
Eino-Ville Talvala | 160d4af | 2012-08-03 09:40:16 -0700 | [diff] [blame] | 40 | |
Eino-Ville Talvala | 61ab9f9 | 2012-05-17 10:30:54 -0700 | [diff] [blame] | 41 | virtual void disconnect(); |
| 42 | virtual status_t connect(const sp<ICameraClient>& client); |
| 43 | virtual status_t lock(); |
| 44 | virtual status_t unlock(); |
| 45 | virtual status_t setPreviewDisplay(const sp<Surface>& surface); |
Eino-Ville Talvala | 6db981c | 2012-05-21 18:54:30 -0700 | [diff] [blame] | 46 | virtual status_t setPreviewTexture( |
| 47 | const sp<ISurfaceTexture>& surfaceTexture); |
Eino-Ville Talvala | 61ab9f9 | 2012-05-17 10:30:54 -0700 | [diff] [blame] | 48 | virtual void setPreviewCallbackFlag(int flag); |
| 49 | virtual status_t startPreview(); |
| 50 | virtual void stopPreview(); |
| 51 | virtual bool previewEnabled(); |
| 52 | virtual status_t storeMetaDataInBuffers(bool enabled); |
| 53 | virtual status_t startRecording(); |
| 54 | virtual void stopRecording(); |
| 55 | virtual bool recordingEnabled(); |
| 56 | virtual void releaseRecordingFrame(const sp<IMemory>& mem); |
| 57 | virtual status_t autoFocus(); |
| 58 | virtual status_t cancelAutoFocus(); |
| 59 | virtual status_t takePicture(int msgType); |
| 60 | virtual status_t setParameters(const String8& params); |
| 61 | virtual String8 getParameters() const; |
| 62 | virtual status_t sendCommand(int32_t cmd, int32_t arg1, int32_t arg2); |
| 63 | |
| 64 | // Interface used by CameraService |
Eino-Ville Talvala | 160d4af | 2012-08-03 09:40:16 -0700 | [diff] [blame] | 65 | |
Eino-Ville Talvala | 61ab9f9 | 2012-05-17 10:30:54 -0700 | [diff] [blame] | 66 | Camera2Client(const sp<CameraService>& cameraService, |
| 67 | const sp<ICameraClient>& cameraClient, |
Eino-Ville Talvala | 61ab9f9 | 2012-05-17 10:30:54 -0700 | [diff] [blame] | 68 | int cameraId, |
| 69 | int cameraFacing, |
| 70 | int clientPid); |
Eino-Ville Talvala | 160d4af | 2012-08-03 09:40:16 -0700 | [diff] [blame] | 71 | virtual ~Camera2Client(); |
Eino-Ville Talvala | 61ab9f9 | 2012-05-17 10:30:54 -0700 | [diff] [blame] | 72 | |
Eino-Ville Talvala | f69c70d | 2012-05-20 15:59:14 -0700 | [diff] [blame] | 73 | status_t initialize(camera_module_t *module); |
| 74 | |
Eino-Ville Talvala | 61ab9f9 | 2012-05-17 10:30:54 -0700 | [diff] [blame] | 75 | virtual status_t dump(int fd, const Vector<String16>& args); |
| 76 | |
Eino-Ville Talvala | 160d4af | 2012-08-03 09:40:16 -0700 | [diff] [blame] | 77 | // Interface used by CameraDevice |
| 78 | |
| 79 | virtual void notifyError(int errorCode, int arg1, int arg2); |
| 80 | virtual void notifyShutter(int frameNumber, nsecs_t timestamp); |
| 81 | virtual void notifyAutoFocus(uint8_t newState, int triggerId); |
| 82 | virtual void notifyAutoExposure(uint8_t newState, int triggerId); |
| 83 | virtual void notifyAutoWhitebalance(uint8_t newState, int triggerId); |
| 84 | |
Eino-Ville Talvala | 61ab9f9 | 2012-05-17 10:30:54 -0700 | [diff] [blame] | 85 | private: |
Eino-Ville Talvala | 4ecfec3 | 2012-06-12 17:13:48 -0700 | [diff] [blame] | 86 | enum State { |
Eino-Ville Talvala | 3a60914 | 2012-07-31 14:36:26 -0700 | [diff] [blame] | 87 | DISCONNECTED, |
Eino-Ville Talvala | 6db981c | 2012-05-21 18:54:30 -0700 | [diff] [blame] | 88 | STOPPED, |
| 89 | WAITING_FOR_PREVIEW_WINDOW, |
Eino-Ville Talvala | 7f61084 | 2012-06-07 10:20:51 -0700 | [diff] [blame] | 90 | PREVIEW, |
| 91 | RECORD, |
Eino-Ville Talvala | d4bcfde | 2012-06-07 17:12:38 -0700 | [diff] [blame] | 92 | STILL_CAPTURE, |
| 93 | VIDEO_SNAPSHOT |
Eino-Ville Talvala | 228a538 | 2012-08-13 12:16:06 -0700 | [diff] [blame] | 94 | }; |
Eino-Ville Talvala | 4ecfec3 | 2012-06-12 17:13:48 -0700 | [diff] [blame] | 95 | static const char *getStateName(State state); |
| 96 | |
Eino-Ville Talvala | 3cca136 | 2012-06-07 10:07:18 -0700 | [diff] [blame] | 97 | /** ICamera interface-related private members */ |
Eino-Ville Talvala | 61ab9f9 | 2012-05-17 10:30:54 -0700 | [diff] [blame] | 98 | |
Eino-Ville Talvala | ac45eb3 | 2012-06-07 10:24:51 -0700 | [diff] [blame] | 99 | // Mutex that must be locked by methods implementing the ICamera interface. |
Eino-Ville Talvala | 36cdfb1 | 2012-08-02 17:34:15 -0700 | [diff] [blame] | 100 | // Ensures serialization between incoming ICamera calls. All methods below |
| 101 | // that append 'L' to the name assume that mICameraLock is locked when |
| 102 | // they're called |
Eino-Ville Talvala | ac45eb3 | 2012-06-07 10:24:51 -0700 | [diff] [blame] | 103 | mutable Mutex mICameraLock; |
| 104 | |
Eino-Ville Talvala | 8ce89d9 | 2012-08-10 08:40:26 -0700 | [diff] [blame] | 105 | // Mutex that must be locked by methods accessing the base Client's |
| 106 | // mCameraClient ICameraClient interface member, for sending notifications |
| 107 | // up to the camera user |
| 108 | mutable Mutex mICameraClientLock; |
| 109 | |
Eino-Ville Talvala | 228a538 | 2012-08-13 12:16:06 -0700 | [diff] [blame] | 110 | class Parameters; |
| 111 | |
Eino-Ville Talvala | 36cdfb1 | 2012-08-02 17:34:15 -0700 | [diff] [blame] | 112 | status_t setPreviewWindowL(const sp<IBinder>& binder, |
Eino-Ville Talvala | be0573b | 2012-06-15 12:42:30 -0700 | [diff] [blame] | 113 | sp<ANativeWindow> window); |
Eino-Ville Talvala | 228a538 | 2012-08-13 12:16:06 -0700 | [diff] [blame] | 114 | status_t startPreviewL(Parameters ¶ms, bool restart); |
| 115 | void stopPreviewL(); |
| 116 | status_t startRecordingL(Parameters ¶ms, bool restart); |
| 117 | bool recordingEnabledL(); |
James Dong | 8da4cd7 | 2012-08-04 19:58:07 -0700 | [diff] [blame] | 118 | |
Eino-Ville Talvala | 36cdfb1 | 2012-08-02 17:34:15 -0700 | [diff] [blame] | 119 | // Individual commands for sendCommand() |
| 120 | status_t commandStartSmoothZoomL(); |
| 121 | status_t commandStopSmoothZoomL(); |
| 122 | status_t commandSetDisplayOrientationL(int degrees); |
| 123 | status_t commandEnableShutterSoundL(bool enable); |
| 124 | status_t commandPlayRecordingSoundL(); |
| 125 | status_t commandStartFaceDetectionL(int type); |
Eino-Ville Talvala | 228a538 | 2012-08-13 12:16:06 -0700 | [diff] [blame] | 126 | status_t commandStopFaceDetectionL(Parameters ¶ms); |
Eino-Ville Talvala | 36cdfb1 | 2012-08-02 17:34:15 -0700 | [diff] [blame] | 127 | status_t commandEnableFocusMoveMsgL(bool enable); |
| 128 | status_t commandPingL(); |
| 129 | status_t commandSetVideoBufferCountL(size_t count); |
Eino-Ville Talvala | d4bcfde | 2012-06-07 17:12:38 -0700 | [diff] [blame] | 130 | |
Eino-Ville Talvala | 3cca136 | 2012-06-07 10:07:18 -0700 | [diff] [blame] | 131 | // Current camera state; this is the contents of the CameraParameters object |
| 132 | // in a more-efficient format. The enum values are mostly based off the |
| 133 | // corresponding camera2 enums, not the camera1 strings. A few are defined |
| 134 | // here if they don't cleanly map to camera2 values. |
| 135 | struct Parameters { |
| 136 | int previewWidth, previewHeight; |
Eino-Ville Talvala | 11b7cde | 2012-06-15 12:37:35 -0700 | [diff] [blame] | 137 | int32_t previewFpsRange[2]; |
Eino-Ville Talvala | 3cca136 | 2012-06-07 10:07:18 -0700 | [diff] [blame] | 138 | int previewFps; // deprecated, here only for tracking changes |
| 139 | int previewFormat; |
| 140 | |
Eino-Ville Talvala | 11b7cde | 2012-06-15 12:37:35 -0700 | [diff] [blame] | 141 | int previewTransform; // set by CAMERA_CMD_SET_DISPLAY_ORIENTATION |
| 142 | |
Eino-Ville Talvala | 3cca136 | 2012-06-07 10:07:18 -0700 | [diff] [blame] | 143 | int pictureWidth, pictureHeight; |
| 144 | |
Eino-Ville Talvala | 11b7cde | 2012-06-15 12:37:35 -0700 | [diff] [blame] | 145 | int32_t jpegThumbSize[2]; |
| 146 | int32_t jpegQuality, jpegThumbQuality; |
| 147 | int32_t jpegRotation; |
Eino-Ville Talvala | 3cca136 | 2012-06-07 10:07:18 -0700 | [diff] [blame] | 148 | |
| 149 | bool gpsEnabled; |
Eino-Ville Talvala | 11b7cde | 2012-06-15 12:37:35 -0700 | [diff] [blame] | 150 | double gpsCoordinates[3]; |
Eino-Ville Talvala | 3cca136 | 2012-06-07 10:07:18 -0700 | [diff] [blame] | 151 | int64_t gpsTimestamp; |
| 152 | String8 gpsProcessingMethod; |
| 153 | |
Eino-Ville Talvala | cab96a4 | 2012-08-24 11:29:22 -0700 | [diff] [blame] | 154 | uint8_t wbMode; |
| 155 | uint8_t effectMode; |
| 156 | uint8_t antibandingMode; |
| 157 | uint8_t sceneMode; |
Eino-Ville Talvala | 3cca136 | 2012-06-07 10:07:18 -0700 | [diff] [blame] | 158 | |
| 159 | enum flashMode_t { |
| 160 | FLASH_MODE_OFF = 0, |
| 161 | FLASH_MODE_AUTO, |
| 162 | FLASH_MODE_ON, |
| 163 | FLASH_MODE_TORCH, |
| 164 | FLASH_MODE_RED_EYE = ANDROID_CONTROL_AE_ON_AUTO_FLASH_REDEYE, |
| 165 | FLASH_MODE_INVALID = -1 |
| 166 | } flashMode; |
| 167 | |
| 168 | enum focusMode_t { |
| 169 | FOCUS_MODE_AUTO = ANDROID_CONTROL_AF_AUTO, |
| 170 | FOCUS_MODE_MACRO = ANDROID_CONTROL_AF_MACRO, |
| 171 | FOCUS_MODE_CONTINUOUS_VIDEO = ANDROID_CONTROL_AF_CONTINUOUS_VIDEO, |
| 172 | FOCUS_MODE_CONTINUOUS_PICTURE = |
| 173 | ANDROID_CONTROL_AF_CONTINUOUS_PICTURE, |
| 174 | FOCUS_MODE_EDOF = ANDROID_CONTROL_AF_EDOF, |
| 175 | FOCUS_MODE_INFINITY, |
| 176 | FOCUS_MODE_FIXED, |
| 177 | FOCUS_MODE_INVALID = -1 |
| 178 | } focusMode; |
| 179 | |
| 180 | struct Area { |
| 181 | int left, top, right, bottom; |
| 182 | int weight; |
| 183 | Area() {} |
| 184 | Area(int left, int top, int right, int bottom, int weight): |
| 185 | left(left), top(top), right(right), bottom(bottom), |
| 186 | weight(weight) {} |
| 187 | }; |
| 188 | Vector<Area> focusingAreas; |
| 189 | |
Eino-Ville Talvala | 11b7cde | 2012-06-15 12:37:35 -0700 | [diff] [blame] | 190 | int32_t exposureCompensation; |
Eino-Ville Talvala | 3cca136 | 2012-06-07 10:07:18 -0700 | [diff] [blame] | 191 | bool autoExposureLock; |
| 192 | bool autoWhiteBalanceLock; |
| 193 | |
| 194 | Vector<Area> meteringAreas; |
| 195 | |
| 196 | int zoom; |
| 197 | |
| 198 | int videoWidth, videoHeight; |
| 199 | |
| 200 | bool recordingHint; |
| 201 | bool videoStabilization; |
Eino-Ville Talvala | 78822d7 | 2012-07-18 17:52:18 -0700 | [diff] [blame] | 202 | |
Eino-Ville Talvala | 836b81f | 2012-07-27 11:35:21 -0700 | [diff] [blame] | 203 | String8 paramsFlattened; |
Eino-Ville Talvala | 36cdfb1 | 2012-08-02 17:34:15 -0700 | [diff] [blame] | 204 | |
| 205 | // These parameters are also part of the camera API-visible state, but not directly |
| 206 | // listed in Camera.Parameters |
| 207 | bool storeMetadataInBuffers; |
| 208 | bool playShutterSound; |
Eino-Ville Talvala | 8ce89d9 | 2012-08-10 08:40:26 -0700 | [diff] [blame] | 209 | bool enableFaceDetect; |
Eino-Ville Talvala | 174181e | 2012-08-03 13:53:39 -0700 | [diff] [blame] | 210 | |
Eino-Ville Talvala | 8ce89d9 | 2012-08-10 08:40:26 -0700 | [diff] [blame] | 211 | bool enableFocusMoveMessages; |
Eino-Ville Talvala | 174181e | 2012-08-03 13:53:39 -0700 | [diff] [blame] | 212 | int afTriggerCounter; |
| 213 | int currentAfTriggerId; |
| 214 | bool afInMotion; |
Eino-Ville Talvala | 228a538 | 2012-08-13 12:16:06 -0700 | [diff] [blame] | 215 | |
| 216 | uint32_t previewCallbackFlags; |
| 217 | bool previewCallbackOneShot; |
| 218 | |
| 219 | // Overall camera state |
| 220 | State state; |
Eino-Ville Talvala | 836b81f | 2012-07-27 11:35:21 -0700 | [diff] [blame] | 221 | }; |
| 222 | |
Eino-Ville Talvala | 8ce89d9 | 2012-08-10 08:40:26 -0700 | [diff] [blame] | 223 | // This class encapsulates the Parameters class so that it can only be accessed |
| 224 | // by constructing a Key object, which locks the LockedParameter's mutex. |
Eino-Ville Talvala | 836b81f | 2012-07-27 11:35:21 -0700 | [diff] [blame] | 225 | class LockedParameters { |
| 226 | public: |
| 227 | class Key { |
| 228 | public: |
| 229 | Key(LockedParameters &p): |
| 230 | mParameters(p.mParameters), |
| 231 | mLockedParameters(p) { |
| 232 | mLockedParameters.mLock.lock(); |
| 233 | } |
| 234 | |
| 235 | ~Key() { |
| 236 | mLockedParameters.mLock.unlock(); |
| 237 | } |
| 238 | Parameters &mParameters; |
| 239 | private: |
| 240 | // Disallow copying, default construction |
| 241 | Key(); |
| 242 | Key(const Key &); |
| 243 | Key &operator=(const Key &); |
| 244 | LockedParameters &mLockedParameters; |
| 245 | }; |
| 246 | class ReadKey { |
| 247 | public: |
| 248 | ReadKey(const LockedParameters &p): |
| 249 | mParameters(p.mParameters), |
| 250 | mLockedParameters(p) { |
| 251 | mLockedParameters.mLock.lock(); |
| 252 | } |
| 253 | |
| 254 | ~ReadKey() { |
| 255 | mLockedParameters.mLock.unlock(); |
| 256 | } |
| 257 | const Parameters &mParameters; |
| 258 | private: |
| 259 | // Disallow copying, default construction |
| 260 | ReadKey(); |
| 261 | ReadKey(const ReadKey &); |
| 262 | ReadKey &operator=(const ReadKey &); |
| 263 | const LockedParameters &mLockedParameters; |
| 264 | }; |
| 265 | |
| 266 | // Only use for dumping or other debugging |
| 267 | const Parameters &unsafeUnlock() { |
| 268 | return mParameters; |
| 269 | } |
| 270 | private: |
| 271 | Parameters mParameters; |
| 272 | mutable Mutex mLock; |
| 273 | |
Eino-Ville Talvala | 3cca136 | 2012-06-07 10:07:18 -0700 | [diff] [blame] | 274 | } mParameters; |
| 275 | |
Eino-Ville Talvala | 8ce89d9 | 2012-08-10 08:40:26 -0700 | [diff] [blame] | 276 | // Static device information; this is a subset of the information |
| 277 | // available through the staticInfo() method, used for frequently-accessed |
| 278 | // values or values that have to be calculated from the static information. |
| 279 | struct DeviceInfo { |
| 280 | int32_t arrayWidth; |
| 281 | int32_t arrayHeight; |
| 282 | uint8_t bestFaceDetectMode; |
| 283 | int32_t maxFaces; |
| 284 | }; |
| 285 | const DeviceInfo *mDeviceInfo; |
| 286 | |
Eino-Ville Talvala | 3cca136 | 2012-06-07 10:07:18 -0700 | [diff] [blame] | 287 | /** Camera device-related private members */ |
| 288 | |
Eino-Ville Talvala | 9cca4c6 | 2012-06-15 15:41:44 -0700 | [diff] [blame] | 289 | class Camera2Heap; |
| 290 | |
Eino-Ville Talvala | 228a538 | 2012-08-13 12:16:06 -0700 | [diff] [blame] | 291 | void setPreviewCallbackFlagL(Parameters ¶ms, int flag); |
Eino-Ville Talvala | 8ce89d9 | 2012-08-10 08:40:26 -0700 | [diff] [blame] | 292 | status_t updateRequests(const Parameters ¶ms); |
| 293 | |
Eino-Ville Talvala | 9cca4c6 | 2012-06-15 15:41:44 -0700 | [diff] [blame] | 294 | // Number of zoom steps to simulate |
| 295 | static const unsigned int NUM_ZOOM_STEPS = 10; |
| 296 | // Used with stream IDs |
| 297 | static const int NO_STREAM = -1; |
| 298 | |
Eino-Ville Talvala | c8474b6 | 2012-08-24 16:30:44 -0700 | [diff] [blame^] | 299 | /* Output frame metadata processing thread. This thread waits for new |
| 300 | * frames from the device, and analyzes them as necessary. |
| 301 | */ |
| 302 | class FrameProcessor: public Thread { |
| 303 | public: |
| 304 | FrameProcessor(wp<Camera2Client> client); |
| 305 | ~FrameProcessor(); |
Eino-Ville Talvala | 8ce89d9 | 2012-08-10 08:40:26 -0700 | [diff] [blame] | 306 | |
Eino-Ville Talvala | c8474b6 | 2012-08-24 16:30:44 -0700 | [diff] [blame^] | 307 | void dump(int fd, const Vector<String16>& args); |
| 308 | private: |
| 309 | static const nsecs_t kWaitDuration = 10000000; // 10 ms |
| 310 | wp<Camera2Client> mClient; |
| 311 | |
| 312 | virtual bool threadLoop(); |
| 313 | |
| 314 | void processNewFrames(sp<Camera2Client> &client); |
| 315 | status_t processFaceDetect(const CameraMetadata &frame, |
| 316 | sp<Camera2Client> &client); |
| 317 | |
| 318 | CameraMetadata mLastFrame; |
| 319 | }; |
| 320 | |
| 321 | sp<FrameProcessor> mFrameProcessor; |
Eino-Ville Talvala | 8ce89d9 | 2012-08-10 08:40:26 -0700 | [diff] [blame] | 322 | |
Eino-Ville Talvala | 9cca4c6 | 2012-06-15 15:41:44 -0700 | [diff] [blame] | 323 | /* Preview related members */ |
| 324 | |
| 325 | int mPreviewStreamId; |
Eino-Ville Talvala | cab96a4 | 2012-08-24 11:29:22 -0700 | [diff] [blame] | 326 | CameraMetadata mPreviewRequest; |
Eino-Ville Talvala | 9cca4c6 | 2012-06-15 15:41:44 -0700 | [diff] [blame] | 327 | sp<IBinder> mPreviewSurface; |
| 328 | sp<ANativeWindow> mPreviewWindow; |
Eino-Ville Talvala | 836b81f | 2012-07-27 11:35:21 -0700 | [diff] [blame] | 329 | |
| 330 | status_t updatePreviewRequest(const Parameters ¶ms); |
| 331 | status_t updatePreviewStream(const Parameters ¶ms); |
Eino-Ville Talvala | 9cca4c6 | 2012-06-15 15:41:44 -0700 | [diff] [blame] | 332 | |
Eino-Ville Talvala | 228a538 | 2012-08-13 12:16:06 -0700 | [diff] [blame] | 333 | /** Preview callback related members */ |
| 334 | |
| 335 | int mCallbackStreamId; |
| 336 | static const size_t kCallbackHeapCount = 6; |
| 337 | sp<CpuConsumer> mCallbackConsumer; |
| 338 | sp<ANativeWindow> mCallbackWindow; |
| 339 | // Simple listener that forwards frame available notifications from |
| 340 | // a CPU consumer to the callback notification |
| 341 | class CallbackWaiter: public CpuConsumer::FrameAvailableListener { |
| 342 | public: |
| 343 | CallbackWaiter(Camera2Client *parent) : mParent(parent) {} |
| 344 | void onFrameAvailable() { mParent->onCallbackAvailable(); } |
| 345 | private: |
| 346 | Camera2Client *mParent; |
| 347 | }; |
| 348 | sp<CallbackWaiter> mCallbackWaiter; |
| 349 | sp<Camera2Heap> mCallbackHeap; |
| 350 | int mCallbackHeapId; |
| 351 | size_t mCallbackHeapHead, mCallbackHeapFree; |
| 352 | // Handle callback image buffers |
| 353 | void onCallbackAvailable(); |
| 354 | |
| 355 | status_t updateCallbackStream(const Parameters ¶ms); |
| 356 | |
Eino-Ville Talvala | 9cca4c6 | 2012-06-15 15:41:44 -0700 | [diff] [blame] | 357 | /* Still image capture related members */ |
| 358 | |
| 359 | int mCaptureStreamId; |
| 360 | sp<CpuConsumer> mCaptureConsumer; |
| 361 | sp<ANativeWindow> mCaptureWindow; |
Eino-Ville Talvala | d4bcfde | 2012-06-07 17:12:38 -0700 | [diff] [blame] | 362 | // Simple listener that forwards frame available notifications from |
| 363 | // a CPU consumer to the capture notification |
| 364 | class CaptureWaiter: public CpuConsumer::FrameAvailableListener { |
| 365 | public: |
| 366 | CaptureWaiter(Camera2Client *parent) : mParent(parent) {} |
| 367 | void onFrameAvailable() { mParent->onCaptureAvailable(); } |
| 368 | private: |
| 369 | Camera2Client *mParent; |
| 370 | }; |
Eino-Ville Talvala | d4bcfde | 2012-06-07 17:12:38 -0700 | [diff] [blame] | 371 | sp<CaptureWaiter> mCaptureWaiter; |
Eino-Ville Talvala | cab96a4 | 2012-08-24 11:29:22 -0700 | [diff] [blame] | 372 | CameraMetadata mCaptureRequest; |
Eino-Ville Talvala | 9cca4c6 | 2012-06-15 15:41:44 -0700 | [diff] [blame] | 373 | sp<Camera2Heap> mCaptureHeap; |
| 374 | // Handle captured image buffers |
| 375 | void onCaptureAvailable(); |
Eino-Ville Talvala | 836b81f | 2012-07-27 11:35:21 -0700 | [diff] [blame] | 376 | |
| 377 | status_t updateCaptureRequest(const Parameters ¶ms); |
| 378 | status_t updateCaptureStream(const Parameters ¶ms); |
Eino-Ville Talvala | 9cca4c6 | 2012-06-15 15:41:44 -0700 | [diff] [blame] | 379 | |
| 380 | /* Recording related members */ |
| 381 | |
| 382 | int mRecordingStreamId; |
Eino-Ville Talvala | 228a538 | 2012-08-13 12:16:06 -0700 | [diff] [blame] | 383 | int mRecordingFrameCount; |
Eino-Ville Talvala | 30e65e7 | 2012-08-21 13:30:45 -0700 | [diff] [blame] | 384 | sp<BufferItemConsumer> mRecordingConsumer; |
Eino-Ville Talvala | 9cca4c6 | 2012-06-15 15:41:44 -0700 | [diff] [blame] | 385 | sp<ANativeWindow> mRecordingWindow; |
| 386 | // Simple listener that forwards frame available notifications from |
| 387 | // a CPU consumer to the recording notification |
Eino-Ville Talvala | 30e65e7 | 2012-08-21 13:30:45 -0700 | [diff] [blame] | 388 | class RecordingWaiter: public BufferItemConsumer::FrameAvailableListener { |
Eino-Ville Talvala | 9cca4c6 | 2012-06-15 15:41:44 -0700 | [diff] [blame] | 389 | public: |
| 390 | RecordingWaiter(Camera2Client *parent) : mParent(parent) {} |
| 391 | void onFrameAvailable() { mParent->onRecordingFrameAvailable(); } |
| 392 | private: |
| 393 | Camera2Client *mParent; |
| 394 | }; |
| 395 | sp<RecordingWaiter> mRecordingWaiter; |
Eino-Ville Talvala | cab96a4 | 2012-08-24 11:29:22 -0700 | [diff] [blame] | 396 | CameraMetadata mRecordingRequest; |
Eino-Ville Talvala | 9cca4c6 | 2012-06-15 15:41:44 -0700 | [diff] [blame] | 397 | sp<Camera2Heap> mRecordingHeap; |
| 398 | |
James Dong | 983cf23 | 2012-08-01 16:39:55 -0700 | [diff] [blame] | 399 | static const size_t kDefaultRecordingHeapCount = 8; |
| 400 | size_t mRecordingHeapCount; |
Eino-Ville Talvala | 30e65e7 | 2012-08-21 13:30:45 -0700 | [diff] [blame] | 401 | Vector<BufferItemConsumer::BufferItem> mRecordingBuffers; |
Eino-Ville Talvala | 9cca4c6 | 2012-06-15 15:41:44 -0700 | [diff] [blame] | 402 | size_t mRecordingHeapHead, mRecordingHeapFree; |
| 403 | // Handle new recording image buffers |
| 404 | void onRecordingFrameAvailable(); |
Eino-Ville Talvala | 836b81f | 2012-07-27 11:35:21 -0700 | [diff] [blame] | 405 | |
| 406 | status_t updateRecordingRequest(const Parameters ¶ms); |
| 407 | status_t updateRecordingStream(const Parameters ¶ms); |
Eino-Ville Talvala | 9cca4c6 | 2012-06-15 15:41:44 -0700 | [diff] [blame] | 408 | |
Eino-Ville Talvala | 174181e | 2012-08-03 13:53:39 -0700 | [diff] [blame] | 409 | /** Notification-related members */ |
| 410 | |
| 411 | bool mAfInMotion; |
| 412 | |
Eino-Ville Talvala | 9cca4c6 | 2012-06-15 15:41:44 -0700 | [diff] [blame] | 413 | /** Camera2Device instance wrapping HAL2 entry */ |
Eino-Ville Talvala | 3cca136 | 2012-06-07 10:07:18 -0700 | [diff] [blame] | 414 | |
| 415 | sp<Camera2Device> mDevice; |
| 416 | |
Eino-Ville Talvala | 9cca4c6 | 2012-06-15 15:41:44 -0700 | [diff] [blame] | 417 | /** Utility members */ |
| 418 | |
Eino-Ville Talvala | 3a60914 | 2012-07-31 14:36:26 -0700 | [diff] [blame] | 419 | // Verify that caller is the owner of the camera |
| 420 | status_t checkPid(const char *checkLocation) const; |
| 421 | |
Eino-Ville Talvala | 9cca4c6 | 2012-06-15 15:41:44 -0700 | [diff] [blame] | 422 | // Utility class for managing a set of IMemory blocks |
| 423 | class Camera2Heap : public RefBase { |
| 424 | public: |
| 425 | Camera2Heap(size_t buf_size, uint_t num_buffers = 1, |
| 426 | const char *name = NULL) : |
| 427 | mBufSize(buf_size), |
| 428 | mNumBufs(num_buffers) { |
| 429 | mHeap = new MemoryHeapBase(buf_size * num_buffers, 0, name); |
| 430 | mBuffers = new sp<MemoryBase>[mNumBufs]; |
| 431 | for (uint_t i = 0; i < mNumBufs; i++) |
| 432 | mBuffers[i] = new MemoryBase(mHeap, |
| 433 | i * mBufSize, |
| 434 | mBufSize); |
| 435 | } |
| 436 | |
| 437 | virtual ~Camera2Heap() |
| 438 | { |
| 439 | delete [] mBuffers; |
| 440 | } |
| 441 | |
| 442 | size_t mBufSize; |
| 443 | uint_t mNumBufs; |
| 444 | sp<MemoryHeapBase> mHeap; |
| 445 | sp<MemoryBase> *mBuffers; |
| 446 | }; |
Eino-Ville Talvala | 3cca136 | 2012-06-07 10:07:18 -0700 | [diff] [blame] | 447 | |
| 448 | // Get values for static camera info entry. min/maxCount are used for error |
| 449 | // checking the number of values in the entry. 0 for max/minCount means to |
| 450 | // do no bounds check in that direction. In case of error, the entry data |
| 451 | // pointer is null and the count is 0. |
Eino-Ville Talvala | cab96a4 | 2012-08-24 11:29:22 -0700 | [diff] [blame] | 452 | camera_metadata_ro_entry_t staticInfo(uint32_t tag, |
| 453 | size_t minCount=0, size_t maxCount=0) const; |
Eino-Ville Talvala | 3cca136 | 2012-06-07 10:07:18 -0700 | [diff] [blame] | 454 | |
Eino-Ville Talvala | 8ce89d9 | 2012-08-10 08:40:26 -0700 | [diff] [blame] | 455 | // Extract frequently-used camera static information into mDeviceInfo |
| 456 | status_t buildDeviceInfo(); |
Eino-Ville Talvala | f69c70d | 2012-05-20 15:59:14 -0700 | [diff] [blame] | 457 | // Convert static camera info from a camera2 device to the |
| 458 | // old API parameter map. |
| 459 | status_t buildDefaultParameters(); |
Eino-Ville Talvala | 61ab9f9 | 2012-05-17 10:30:54 -0700 | [diff] [blame] | 460 | |
Eino-Ville Talvala | be0573b | 2012-06-15 12:42:30 -0700 | [diff] [blame] | 461 | // Update parameters all requests use, based on mParameters |
Eino-Ville Talvala | cab96a4 | 2012-08-24 11:29:22 -0700 | [diff] [blame] | 462 | status_t updateRequestCommon(CameraMetadata *request, const Parameters ¶ms); |
Eino-Ville Talvala | be0573b | 2012-06-15 12:42:30 -0700 | [diff] [blame] | 463 | |
Eino-Ville Talvala | 30e65e7 | 2012-08-21 13:30:45 -0700 | [diff] [blame] | 464 | // Map from sensor active array pixel coordinates to normalized camera |
| 465 | // parameter coordinates. The former are (0,0)-(array width - 1, array height |
| 466 | // - 1), the latter from (-1000,-1000)-(1000,1000) |
Eino-Ville Talvala | 8ce89d9 | 2012-08-10 08:40:26 -0700 | [diff] [blame] | 467 | int arrayXToNormalized(int width) const; |
| 468 | int arrayYToNormalized(int height) const; |
| 469 | |
Eino-Ville Talvala | 6861a4e | 2012-06-07 10:32:12 -0700 | [diff] [blame] | 470 | // Convert camera1 preview format string to camera2 enum |
| 471 | static int formatStringToEnum(const char *format); |
Eino-Ville Talvala | 3cca136 | 2012-06-07 10:07:18 -0700 | [diff] [blame] | 472 | static const char *formatEnumToString(int format); |
Eino-Ville Talvala | 6861a4e | 2012-06-07 10:32:12 -0700 | [diff] [blame] | 473 | |
| 474 | static int wbModeStringToEnum(const char *wbMode); |
| 475 | static int effectModeStringToEnum(const char *effectMode); |
| 476 | static int abModeStringToEnum(const char *abMode); |
| 477 | static int sceneModeStringToEnum(const char *sceneMode); |
| 478 | static Parameters::flashMode_t flashModeStringToEnum(const char *flashMode); |
| 479 | static Parameters::focusMode_t focusModeStringToEnum(const char *focusMode); |
| 480 | static status_t parseAreas(const char *areasCStr, |
| 481 | Vector<Parameters::Area> *areas); |
| 482 | static status_t validateAreas(const Vector<Parameters::Area> &areas, |
| 483 | size_t maxRegions); |
| 484 | static bool boolFromString(const char *boolStr); |
Eino-Ville Talvala | c94cd19 | 2012-06-15 12:47:42 -0700 | [diff] [blame] | 485 | |
| 486 | // Map from camera orientation + facing to gralloc transform enum |
| 487 | static int degToTransform(int degrees, bool mirror); |
Eino-Ville Talvala | 160d4af | 2012-08-03 09:40:16 -0700 | [diff] [blame] | 488 | |
Eino-Ville Talvala | 228a538 | 2012-08-13 12:16:06 -0700 | [diff] [blame] | 489 | static size_t calculateBufferSize(int width, int height, |
| 490 | int format, int stride); |
Eino-Ville Talvala | 61ab9f9 | 2012-05-17 10:30:54 -0700 | [diff] [blame] | 491 | }; |
| 492 | |
| 493 | }; // namespace android |
| 494 | |
| 495 | #endif |