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