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 | |
Eino-Ville Talvala | b99c5b8 | 2013-02-06 17:20:07 -0800 | [diff] [blame^] | 20 | #include "CameraDeviceBase.h" |
Eino-Ville Talvala | 61ab9f9 | 2012-05-17 10:30:54 -0700 | [diff] [blame] | 21 | #include "CameraService.h" |
Eino-Ville Talvala | 2e19c3c | 2012-08-26 09:29:28 -0700 | [diff] [blame] | 22 | #include "camera2/Parameters.h" |
Eino-Ville Talvala | a16733e | 2012-08-27 23:41:56 -0700 | [diff] [blame] | 23 | #include "camera2/FrameProcessor.h" |
Eino-Ville Talvala | 73bbd1f | 2012-09-26 10:45:47 -0700 | [diff] [blame] | 24 | #include "camera2/StreamingProcessor.h" |
Eino-Ville Talvala | da6665c | 2012-08-29 17:37:16 -0700 | [diff] [blame] | 25 | #include "camera2/JpegProcessor.h" |
| 26 | #include "camera2/ZslProcessor.h" |
| 27 | #include "camera2/CaptureSequencer.h" |
Eino-Ville Talvala | d86a688 | 2012-08-28 11:34:14 -0700 | [diff] [blame] | 28 | #include "camera2/CallbackProcessor.h" |
Eino-Ville Talvala | 61ab9f9 | 2012-05-17 10:30:54 -0700 | [diff] [blame] | 29 | |
| 30 | namespace android { |
| 31 | |
Eino-Ville Talvala | 73bbd1f | 2012-09-26 10:45:47 -0700 | [diff] [blame] | 32 | class IMemory; |
Eino-Ville Talvala | 61ab9f9 | 2012-05-17 10:30:54 -0700 | [diff] [blame] | 33 | /** |
Eino-Ville Talvala | b99c5b8 | 2013-02-06 17:20:07 -0800 | [diff] [blame^] | 34 | * Interface between android.hardware.Camera API and Camera HAL device for versions |
| 35 | * CAMERA_DEVICE_API_VERSION_2_0 and 3_0. |
Eino-Ville Talvala | 61ab9f9 | 2012-05-17 10:30:54 -0700 | [diff] [blame] | 36 | */ |
Eino-Ville Talvala | 8ce89d9 | 2012-08-10 08:40:26 -0700 | [diff] [blame] | 37 | class Camera2Client : |
| 38 | public CameraService::Client, |
Eino-Ville Talvala | b99c5b8 | 2013-02-06 17:20:07 -0800 | [diff] [blame^] | 39 | public CameraDeviceBase::NotificationListener |
Eino-Ville Talvala | 61ab9f9 | 2012-05-17 10:30:54 -0700 | [diff] [blame] | 40 | { |
| 41 | public: |
Eino-Ville Talvala | ea0d51b | 2012-08-28 01:25:43 -0700 | [diff] [blame] | 42 | /** |
| 43 | * ICamera interface (see ICamera for details) |
| 44 | */ |
Eino-Ville Talvala | 160d4af | 2012-08-03 09:40:16 -0700 | [diff] [blame] | 45 | |
Eino-Ville Talvala | 61ab9f9 | 2012-05-17 10:30:54 -0700 | [diff] [blame] | 46 | virtual void disconnect(); |
| 47 | virtual status_t connect(const sp<ICameraClient>& client); |
| 48 | virtual status_t lock(); |
| 49 | virtual status_t unlock(); |
| 50 | virtual status_t setPreviewDisplay(const sp<Surface>& surface); |
Eino-Ville Talvala | 6db981c | 2012-05-21 18:54:30 -0700 | [diff] [blame] | 51 | virtual status_t setPreviewTexture( |
Andy McFadden | 8ba0102 | 2012-12-18 09:46:54 -0800 | [diff] [blame] | 52 | const sp<IGraphicBufferProducer>& bufferProducer); |
Eino-Ville Talvala | 61ab9f9 | 2012-05-17 10:30:54 -0700 | [diff] [blame] | 53 | virtual void setPreviewCallbackFlag(int flag); |
| 54 | virtual status_t startPreview(); |
| 55 | virtual void stopPreview(); |
| 56 | virtual bool previewEnabled(); |
| 57 | virtual status_t storeMetaDataInBuffers(bool enabled); |
| 58 | virtual status_t startRecording(); |
| 59 | virtual void stopRecording(); |
| 60 | virtual bool recordingEnabled(); |
| 61 | virtual void releaseRecordingFrame(const sp<IMemory>& mem); |
| 62 | virtual status_t autoFocus(); |
| 63 | virtual status_t cancelAutoFocus(); |
| 64 | virtual status_t takePicture(int msgType); |
| 65 | virtual status_t setParameters(const String8& params); |
| 66 | virtual String8 getParameters() const; |
| 67 | virtual status_t sendCommand(int32_t cmd, int32_t arg1, int32_t arg2); |
| 68 | |
Eino-Ville Talvala | ea0d51b | 2012-08-28 01:25:43 -0700 | [diff] [blame] | 69 | /** |
| 70 | * Interface used by CameraService |
| 71 | */ |
Eino-Ville Talvala | 160d4af | 2012-08-03 09:40:16 -0700 | [diff] [blame] | 72 | |
Eino-Ville Talvala | 61ab9f9 | 2012-05-17 10:30:54 -0700 | [diff] [blame] | 73 | Camera2Client(const sp<CameraService>& cameraService, |
| 74 | const sp<ICameraClient>& cameraClient, |
Eino-Ville Talvala | ceb388d | 2013-02-19 10:40:14 -0800 | [diff] [blame] | 75 | const String16& clientPackageName, |
Eino-Ville Talvala | 61ab9f9 | 2012-05-17 10:30:54 -0700 | [diff] [blame] | 76 | int cameraId, |
| 77 | int cameraFacing, |
Igor Murashkin | ecf17e8 | 2012-10-02 16:05:11 -0700 | [diff] [blame] | 78 | int clientPid, |
Eino-Ville Talvala | ceb388d | 2013-02-19 10:40:14 -0800 | [diff] [blame] | 79 | uid_t clientUid, |
Eino-Ville Talvala | b99c5b8 | 2013-02-06 17:20:07 -0800 | [diff] [blame^] | 80 | int servicePid, |
| 81 | int deviceVersion); |
| 82 | |
Eino-Ville Talvala | 160d4af | 2012-08-03 09:40:16 -0700 | [diff] [blame] | 83 | virtual ~Camera2Client(); |
Eino-Ville Talvala | 61ab9f9 | 2012-05-17 10:30:54 -0700 | [diff] [blame] | 84 | |
Eino-Ville Talvala | f69c70d | 2012-05-20 15:59:14 -0700 | [diff] [blame] | 85 | status_t initialize(camera_module_t *module); |
| 86 | |
Eino-Ville Talvala | 61ab9f9 | 2012-05-17 10:30:54 -0700 | [diff] [blame] | 87 | virtual status_t dump(int fd, const Vector<String16>& args); |
| 88 | |
Eino-Ville Talvala | ea0d51b | 2012-08-28 01:25:43 -0700 | [diff] [blame] | 89 | /** |
Eino-Ville Talvala | b99c5b8 | 2013-02-06 17:20:07 -0800 | [diff] [blame^] | 90 | * Interface used by CameraDeviceBase |
Eino-Ville Talvala | ea0d51b | 2012-08-28 01:25:43 -0700 | [diff] [blame] | 91 | */ |
Eino-Ville Talvala | 160d4af | 2012-08-03 09:40:16 -0700 | [diff] [blame] | 92 | |
| 93 | virtual void notifyError(int errorCode, int arg1, int arg2); |
| 94 | virtual void notifyShutter(int frameNumber, nsecs_t timestamp); |
| 95 | virtual void notifyAutoFocus(uint8_t newState, int triggerId); |
| 96 | virtual void notifyAutoExposure(uint8_t newState, int triggerId); |
| 97 | virtual void notifyAutoWhitebalance(uint8_t newState, int triggerId); |
| 98 | |
Eino-Ville Talvala | ea0d51b | 2012-08-28 01:25:43 -0700 | [diff] [blame] | 99 | /** |
| 100 | * Interface used by independent components of Camera2Client. |
| 101 | */ |
Eino-Ville Talvala | a16733e | 2012-08-27 23:41:56 -0700 | [diff] [blame] | 102 | |
Eino-Ville Talvala | da6665c | 2012-08-29 17:37:16 -0700 | [diff] [blame] | 103 | int getCameraId() const; |
Eino-Ville Talvala | b99c5b8 | 2013-02-06 17:20:07 -0800 | [diff] [blame^] | 104 | const sp<CameraDeviceBase>& getCameraDevice(); |
Eino-Ville Talvala | 609acc0 | 2012-09-06 18:26:58 -0700 | [diff] [blame] | 105 | const sp<CameraService>& getCameraService(); |
Eino-Ville Talvala | a16733e | 2012-08-27 23:41:56 -0700 | [diff] [blame] | 106 | camera2::SharedParameters& getParameters(); |
| 107 | |
Eino-Ville Talvala | da6665c | 2012-08-29 17:37:16 -0700 | [diff] [blame] | 108 | int getPreviewStreamId() const; |
| 109 | int getCaptureStreamId() const; |
| 110 | int getCallbackStreamId() const; |
| 111 | int getRecordingStreamId() const; |
| 112 | int getZslStreamId() const; |
| 113 | |
Eino-Ville Talvala | 4865c52 | 2012-10-02 13:30:28 -0700 | [diff] [blame] | 114 | status_t registerFrameListener(int32_t minId, int32_t maxId, |
Eino-Ville Talvala | da6665c | 2012-08-29 17:37:16 -0700 | [diff] [blame] | 115 | wp<camera2::FrameProcessor::FilteredListener> listener); |
Eino-Ville Talvala | 4865c52 | 2012-10-02 13:30:28 -0700 | [diff] [blame] | 116 | status_t removeFrameListener(int32_t minId, int32_t maxId, |
| 117 | wp<camera2::FrameProcessor::FilteredListener> listener); |
| 118 | |
| 119 | status_t stopStream(); |
Eino-Ville Talvala | da6665c | 2012-08-29 17:37:16 -0700 | [diff] [blame] | 120 | |
Eino-Ville Talvala | a16733e | 2012-08-27 23:41:56 -0700 | [diff] [blame] | 121 | // Simple class to ensure that access to ICameraClient is serialized by |
| 122 | // requiring mCameraClientLock to be locked before access to mCameraClient |
| 123 | // is possible. |
| 124 | class SharedCameraClient { |
| 125 | public: |
| 126 | class Lock { |
| 127 | public: |
| 128 | Lock(SharedCameraClient &client); |
| 129 | ~Lock(); |
| 130 | sp<ICameraClient> &mCameraClient; |
| 131 | private: |
| 132 | SharedCameraClient &mSharedClient; |
| 133 | }; |
Eino-Ville Talvala | ea0d51b | 2012-08-28 01:25:43 -0700 | [diff] [blame] | 134 | SharedCameraClient(const sp<ICameraClient>& client); |
Eino-Ville Talvala | a16733e | 2012-08-27 23:41:56 -0700 | [diff] [blame] | 135 | SharedCameraClient& operator=(const sp<ICameraClient>& client); |
| 136 | void clear(); |
| 137 | private: |
| 138 | sp<ICameraClient> mCameraClient; |
| 139 | mutable Mutex mCameraClientLock; |
| 140 | } mSharedCameraClient; |
| 141 | |
Eino-Ville Talvala | ea0d51b | 2012-08-28 01:25:43 -0700 | [diff] [blame] | 142 | static size_t calculateBufferSize(int width, int height, |
| 143 | int format, int stride); |
| 144 | |
Eino-Ville Talvala | 4865c52 | 2012-10-02 13:30:28 -0700 | [diff] [blame] | 145 | static const int32_t kPreviewRequestIdStart = 10000000; |
| 146 | static const int32_t kPreviewRequestIdEnd = 20000000; |
| 147 | |
| 148 | static const int32_t kRecordingRequestIdStart = 20000000; |
| 149 | static const int32_t kRecordingRequestIdEnd = 30000000; |
| 150 | |
| 151 | static const int32_t kCaptureRequestIdStart = 30000000; |
| 152 | static const int32_t kCaptureRequestIdEnd = 40000000; |
Eino-Ville Talvala | da6665c | 2012-08-29 17:37:16 -0700 | [diff] [blame] | 153 | |
Eino-Ville Talvala | 61ab9f9 | 2012-05-17 10:30:54 -0700 | [diff] [blame] | 154 | private: |
Eino-Ville Talvala | 3cca136 | 2012-06-07 10:07:18 -0700 | [diff] [blame] | 155 | /** ICamera interface-related private members */ |
Eino-Ville Talvala | 61ab9f9 | 2012-05-17 10:30:54 -0700 | [diff] [blame] | 156 | |
Eino-Ville Talvala | ac45eb3 | 2012-06-07 10:24:51 -0700 | [diff] [blame] | 157 | // Mutex that must be locked by methods implementing the ICamera interface. |
Eino-Ville Talvala | 36cdfb1 | 2012-08-02 17:34:15 -0700 | [diff] [blame] | 158 | // Ensures serialization between incoming ICamera calls. All methods below |
| 159 | // that append 'L' to the name assume that mICameraLock is locked when |
| 160 | // they're called |
Eino-Ville Talvala | ac45eb3 | 2012-06-07 10:24:51 -0700 | [diff] [blame] | 161 | mutable Mutex mICameraLock; |
| 162 | |
Eino-Ville Talvala | 2e19c3c | 2012-08-26 09:29:28 -0700 | [diff] [blame] | 163 | typedef camera2::Parameters Parameters; |
Eino-Ville Talvala | 228a538 | 2012-08-13 12:16:06 -0700 | [diff] [blame] | 164 | |
Eino-Ville Talvala | 36cdfb1 | 2012-08-02 17:34:15 -0700 | [diff] [blame] | 165 | status_t setPreviewWindowL(const sp<IBinder>& binder, |
Eino-Ville Talvala | be0573b | 2012-06-15 12:42:30 -0700 | [diff] [blame] | 166 | sp<ANativeWindow> window); |
Eino-Ville Talvala | 228a538 | 2012-08-13 12:16:06 -0700 | [diff] [blame] | 167 | status_t startPreviewL(Parameters ¶ms, bool restart); |
| 168 | void stopPreviewL(); |
| 169 | status_t startRecordingL(Parameters ¶ms, bool restart); |
| 170 | bool recordingEnabledL(); |
James Dong | 8da4cd7 | 2012-08-04 19:58:07 -0700 | [diff] [blame] | 171 | |
Eino-Ville Talvala | 36cdfb1 | 2012-08-02 17:34:15 -0700 | [diff] [blame] | 172 | // Individual commands for sendCommand() |
| 173 | status_t commandStartSmoothZoomL(); |
| 174 | status_t commandStopSmoothZoomL(); |
| 175 | status_t commandSetDisplayOrientationL(int degrees); |
| 176 | status_t commandEnableShutterSoundL(bool enable); |
| 177 | status_t commandPlayRecordingSoundL(); |
| 178 | status_t commandStartFaceDetectionL(int type); |
Eino-Ville Talvala | 228a538 | 2012-08-13 12:16:06 -0700 | [diff] [blame] | 179 | status_t commandStopFaceDetectionL(Parameters ¶ms); |
Eino-Ville Talvala | 36cdfb1 | 2012-08-02 17:34:15 -0700 | [diff] [blame] | 180 | status_t commandEnableFocusMoveMsgL(bool enable); |
| 181 | status_t commandPingL(); |
| 182 | status_t commandSetVideoBufferCountL(size_t count); |
Eino-Ville Talvala | d4bcfde | 2012-06-07 17:12:38 -0700 | [diff] [blame] | 183 | |
Eino-Ville Talvala | 2e19c3c | 2012-08-26 09:29:28 -0700 | [diff] [blame] | 184 | // Current camera device configuration |
| 185 | camera2::SharedParameters mParameters; |
Eino-Ville Talvala | 8ce89d9 | 2012-08-10 08:40:26 -0700 | [diff] [blame] | 186 | |
Eino-Ville Talvala | 3cca136 | 2012-06-07 10:07:18 -0700 | [diff] [blame] | 187 | /** Camera device-related private members */ |
| 188 | |
Eino-Ville Talvala | 228a538 | 2012-08-13 12:16:06 -0700 | [diff] [blame] | 189 | void setPreviewCallbackFlagL(Parameters ¶ms, int flag); |
Eino-Ville Talvala | 5a4f93e | 2012-08-29 18:06:32 -0700 | [diff] [blame] | 190 | status_t updateRequests(Parameters ¶ms); |
Eino-Ville Talvala | 8ce89d9 | 2012-08-10 08:40:26 -0700 | [diff] [blame] | 191 | |
Eino-Ville Talvala | 9cca4c6 | 2012-06-15 15:41:44 -0700 | [diff] [blame] | 192 | // Used with stream IDs |
| 193 | static const int NO_STREAM = -1; |
| 194 | |
Eino-Ville Talvala | a16733e | 2012-08-27 23:41:56 -0700 | [diff] [blame] | 195 | sp<camera2::FrameProcessor> mFrameProcessor; |
Eino-Ville Talvala | 8ce89d9 | 2012-08-10 08:40:26 -0700 | [diff] [blame] | 196 | |
Eino-Ville Talvala | 73bbd1f | 2012-09-26 10:45:47 -0700 | [diff] [blame] | 197 | /* Preview/Recording related members */ |
Eino-Ville Talvala | 9cca4c6 | 2012-06-15 15:41:44 -0700 | [diff] [blame] | 198 | |
Eino-Ville Talvala | 9cca4c6 | 2012-06-15 15:41:44 -0700 | [diff] [blame] | 199 | sp<IBinder> mPreviewSurface; |
Eino-Ville Talvala | 73bbd1f | 2012-09-26 10:45:47 -0700 | [diff] [blame] | 200 | sp<camera2::StreamingProcessor> mStreamingProcessor; |
Eino-Ville Talvala | 9cca4c6 | 2012-06-15 15:41:44 -0700 | [diff] [blame] | 201 | |
Eino-Ville Talvala | 228a538 | 2012-08-13 12:16:06 -0700 | [diff] [blame] | 202 | /** Preview callback related members */ |
| 203 | |
Eino-Ville Talvala | d86a688 | 2012-08-28 11:34:14 -0700 | [diff] [blame] | 204 | sp<camera2::CallbackProcessor> mCallbackProcessor; |
Eino-Ville Talvala | 228a538 | 2012-08-13 12:16:06 -0700 | [diff] [blame] | 205 | |
Eino-Ville Talvala | 9cca4c6 | 2012-06-15 15:41:44 -0700 | [diff] [blame] | 206 | /* Still image capture related members */ |
| 207 | |
Eino-Ville Talvala | da6665c | 2012-08-29 17:37:16 -0700 | [diff] [blame] | 208 | sp<camera2::CaptureSequencer> mCaptureSequencer; |
| 209 | sp<camera2::JpegProcessor> mJpegProcessor; |
| 210 | sp<camera2::ZslProcessor> mZslProcessor; |
Eino-Ville Talvala | 9cca4c6 | 2012-06-15 15:41:44 -0700 | [diff] [blame] | 211 | |
Eino-Ville Talvala | 174181e | 2012-08-03 13:53:39 -0700 | [diff] [blame] | 212 | /** Notification-related members */ |
| 213 | |
| 214 | bool mAfInMotion; |
| 215 | |
Eino-Ville Talvala | b99c5b8 | 2013-02-06 17:20:07 -0800 | [diff] [blame^] | 216 | /** CameraDevice instance, wraps HAL camera device */ |
Eino-Ville Talvala | 3cca136 | 2012-06-07 10:07:18 -0700 | [diff] [blame] | 217 | |
Eino-Ville Talvala | b99c5b8 | 2013-02-06 17:20:07 -0800 | [diff] [blame^] | 218 | sp<CameraDeviceBase> mDevice; |
Eino-Ville Talvala | 3cca136 | 2012-06-07 10:07:18 -0700 | [diff] [blame] | 219 | |
Eino-Ville Talvala | 9cca4c6 | 2012-06-15 15:41:44 -0700 | [diff] [blame] | 220 | /** Utility members */ |
| 221 | |
Eino-Ville Talvala | 4865c52 | 2012-10-02 13:30:28 -0700 | [diff] [blame] | 222 | // Wait until the camera device has received the latest control settings |
| 223 | status_t syncWithDevice(); |
| 224 | |
Eino-Ville Talvala | 3a60914 | 2012-07-31 14:36:26 -0700 | [diff] [blame] | 225 | // Verify that caller is the owner of the camera |
| 226 | status_t checkPid(const char *checkLocation) const; |
Eino-Ville Talvala | 61ab9f9 | 2012-05-17 10:30:54 -0700 | [diff] [blame] | 227 | }; |
| 228 | |
| 229 | }; // namespace android |
| 230 | |
| 231 | #endif |