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" |
Igor Murashkin | ae500e5 | 2013-04-22 14:03:54 -0700 | [diff] [blame] | 26 | #include "camera2/ZslProcessorInterface.h" |
Eino-Ville Talvala | da6665c | 2012-08-29 17:37:16 -0700 | [diff] [blame] | 27 | #include "camera2/CaptureSequencer.h" |
Eino-Ville Talvala | d86a688 | 2012-08-28 11:34:14 -0700 | [diff] [blame] | 28 | #include "camera2/CallbackProcessor.h" |
Igor Murashkin | 44cfcf0 | 2013-03-01 16:22:28 -0800 | [diff] [blame] | 29 | #include "Camera2ClientBase.h" |
Eino-Ville Talvala | 61ab9f9 | 2012-05-17 10:30:54 -0700 | [diff] [blame] | 30 | |
| 31 | namespace android { |
| 32 | |
Eino-Ville Talvala | 73bbd1f | 2012-09-26 10:45:47 -0700 | [diff] [blame] | 33 | class IMemory; |
Eino-Ville Talvala | 61ab9f9 | 2012-05-17 10:30:54 -0700 | [diff] [blame] | 34 | /** |
Eino-Ville Talvala | b99c5b8 | 2013-02-06 17:20:07 -0800 | [diff] [blame] | 35 | * Interface between android.hardware.Camera API and Camera HAL device for versions |
| 36 | * CAMERA_DEVICE_API_VERSION_2_0 and 3_0. |
Eino-Ville Talvala | 61ab9f9 | 2012-05-17 10:30:54 -0700 | [diff] [blame] | 37 | */ |
Eino-Ville Talvala | 8ce89d9 | 2012-08-10 08:40:26 -0700 | [diff] [blame] | 38 | class Camera2Client : |
Igor Murashkin | 44cfcf0 | 2013-03-01 16:22:28 -0800 | [diff] [blame] | 39 | public Camera2ClientBase<CameraService::Client> |
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 | |
Eino-Ville Talvala | 160d4af | 2012-08-03 09:40:16 -0700 | [diff] [blame] | 93 | virtual void notifyAutoFocus(uint8_t newState, int triggerId); |
| 94 | virtual void notifyAutoExposure(uint8_t newState, int triggerId); |
Eino-Ville Talvala | 160d4af | 2012-08-03 09:40:16 -0700 | [diff] [blame] | 95 | |
Eino-Ville Talvala | ea0d51b | 2012-08-28 01:25:43 -0700 | [diff] [blame] | 96 | /** |
| 97 | * Interface used by independent components of Camera2Client. |
| 98 | */ |
Eino-Ville Talvala | a16733e | 2012-08-27 23:41:56 -0700 | [diff] [blame] | 99 | |
Eino-Ville Talvala | a16733e | 2012-08-27 23:41:56 -0700 | [diff] [blame] | 100 | camera2::SharedParameters& getParameters(); |
| 101 | |
Eino-Ville Talvala | da6665c | 2012-08-29 17:37:16 -0700 | [diff] [blame] | 102 | int getPreviewStreamId() const; |
| 103 | int getCaptureStreamId() const; |
| 104 | int getCallbackStreamId() const; |
| 105 | int getRecordingStreamId() const; |
| 106 | int getZslStreamId() const; |
| 107 | |
Eino-Ville Talvala | 4865c52 | 2012-10-02 13:30:28 -0700 | [diff] [blame] | 108 | status_t registerFrameListener(int32_t minId, int32_t maxId, |
Eino-Ville Talvala | da6665c | 2012-08-29 17:37:16 -0700 | [diff] [blame] | 109 | wp<camera2::FrameProcessor::FilteredListener> listener); |
Eino-Ville Talvala | 4865c52 | 2012-10-02 13:30:28 -0700 | [diff] [blame] | 110 | status_t removeFrameListener(int32_t minId, int32_t maxId, |
| 111 | wp<camera2::FrameProcessor::FilteredListener> listener); |
| 112 | |
| 113 | status_t stopStream(); |
Eino-Ville Talvala | da6665c | 2012-08-29 17:37:16 -0700 | [diff] [blame] | 114 | |
Eino-Ville Talvala | ea0d51b | 2012-08-28 01:25:43 -0700 | [diff] [blame] | 115 | static size_t calculateBufferSize(int width, int height, |
| 116 | int format, int stride); |
| 117 | |
Eino-Ville Talvala | 4865c52 | 2012-10-02 13:30:28 -0700 | [diff] [blame] | 118 | static const int32_t kPreviewRequestIdStart = 10000000; |
| 119 | static const int32_t kPreviewRequestIdEnd = 20000000; |
| 120 | |
| 121 | static const int32_t kRecordingRequestIdStart = 20000000; |
| 122 | static const int32_t kRecordingRequestIdEnd = 30000000; |
| 123 | |
| 124 | static const int32_t kCaptureRequestIdStart = 30000000; |
| 125 | static const int32_t kCaptureRequestIdEnd = 40000000; |
Eino-Ville Talvala | da6665c | 2012-08-29 17:37:16 -0700 | [diff] [blame] | 126 | |
Eino-Ville Talvala | 61ab9f9 | 2012-05-17 10:30:54 -0700 | [diff] [blame] | 127 | private: |
Eino-Ville Talvala | 3cca136 | 2012-06-07 10:07:18 -0700 | [diff] [blame] | 128 | /** ICamera interface-related private members */ |
Eino-Ville Talvala | 2e19c3c | 2012-08-26 09:29:28 -0700 | [diff] [blame] | 129 | typedef camera2::Parameters Parameters; |
Eino-Ville Talvala | 228a538 | 2012-08-13 12:16:06 -0700 | [diff] [blame] | 130 | |
Eino-Ville Talvala | 36cdfb1 | 2012-08-02 17:34:15 -0700 | [diff] [blame] | 131 | status_t setPreviewWindowL(const sp<IBinder>& binder, |
Eino-Ville Talvala | be0573b | 2012-06-15 12:42:30 -0700 | [diff] [blame] | 132 | sp<ANativeWindow> window); |
Eino-Ville Talvala | 228a538 | 2012-08-13 12:16:06 -0700 | [diff] [blame] | 133 | status_t startPreviewL(Parameters ¶ms, bool restart); |
| 134 | void stopPreviewL(); |
| 135 | status_t startRecordingL(Parameters ¶ms, bool restart); |
| 136 | bool recordingEnabledL(); |
James Dong | 8da4cd7 | 2012-08-04 19:58:07 -0700 | [diff] [blame] | 137 | |
Eino-Ville Talvala | 36cdfb1 | 2012-08-02 17:34:15 -0700 | [diff] [blame] | 138 | // Individual commands for sendCommand() |
| 139 | status_t commandStartSmoothZoomL(); |
| 140 | status_t commandStopSmoothZoomL(); |
| 141 | status_t commandSetDisplayOrientationL(int degrees); |
| 142 | status_t commandEnableShutterSoundL(bool enable); |
| 143 | status_t commandPlayRecordingSoundL(); |
| 144 | status_t commandStartFaceDetectionL(int type); |
Eino-Ville Talvala | 228a538 | 2012-08-13 12:16:06 -0700 | [diff] [blame] | 145 | status_t commandStopFaceDetectionL(Parameters ¶ms); |
Eino-Ville Talvala | 36cdfb1 | 2012-08-02 17:34:15 -0700 | [diff] [blame] | 146 | status_t commandEnableFocusMoveMsgL(bool enable); |
| 147 | status_t commandPingL(); |
| 148 | status_t commandSetVideoBufferCountL(size_t count); |
Eino-Ville Talvala | d4bcfde | 2012-06-07 17:12:38 -0700 | [diff] [blame] | 149 | |
Eino-Ville Talvala | 2e19c3c | 2012-08-26 09:29:28 -0700 | [diff] [blame] | 150 | // Current camera device configuration |
| 151 | camera2::SharedParameters mParameters; |
Eino-Ville Talvala | 8ce89d9 | 2012-08-10 08:40:26 -0700 | [diff] [blame] | 152 | |
Eino-Ville Talvala | 3cca136 | 2012-06-07 10:07:18 -0700 | [diff] [blame] | 153 | /** Camera device-related private members */ |
| 154 | |
Eino-Ville Talvala | 228a538 | 2012-08-13 12:16:06 -0700 | [diff] [blame] | 155 | void setPreviewCallbackFlagL(Parameters ¶ms, int flag); |
Eino-Ville Talvala | 5a4f93e | 2012-08-29 18:06:32 -0700 | [diff] [blame] | 156 | status_t updateRequests(Parameters ¶ms); |
Igor Murashkin | ae500e5 | 2013-04-22 14:03:54 -0700 | [diff] [blame] | 157 | int mDeviceVersion; |
Eino-Ville Talvala | 8ce89d9 | 2012-08-10 08:40:26 -0700 | [diff] [blame] | 158 | |
Eino-Ville Talvala | 9cca4c6 | 2012-06-15 15:41:44 -0700 | [diff] [blame] | 159 | // Used with stream IDs |
| 160 | static const int NO_STREAM = -1; |
| 161 | |
Igor Murashkin | dca254a | 2013-05-13 14:53:44 -0700 | [diff] [blame^] | 162 | template <typename ProcessorT> |
| 163 | status_t updateProcessorStream(sp<ProcessorT> processor, Parameters params); |
| 164 | |
Eino-Ville Talvala | a16733e | 2012-08-27 23:41:56 -0700 | [diff] [blame] | 165 | sp<camera2::FrameProcessor> mFrameProcessor; |
Eino-Ville Talvala | 8ce89d9 | 2012-08-10 08:40:26 -0700 | [diff] [blame] | 166 | |
Eino-Ville Talvala | 73bbd1f | 2012-09-26 10:45:47 -0700 | [diff] [blame] | 167 | /* Preview/Recording related members */ |
Eino-Ville Talvala | 9cca4c6 | 2012-06-15 15:41:44 -0700 | [diff] [blame] | 168 | |
Eino-Ville Talvala | 9cca4c6 | 2012-06-15 15:41:44 -0700 | [diff] [blame] | 169 | sp<IBinder> mPreviewSurface; |
Eino-Ville Talvala | 73bbd1f | 2012-09-26 10:45:47 -0700 | [diff] [blame] | 170 | sp<camera2::StreamingProcessor> mStreamingProcessor; |
Eino-Ville Talvala | 9cca4c6 | 2012-06-15 15:41:44 -0700 | [diff] [blame] | 171 | |
Eino-Ville Talvala | 228a538 | 2012-08-13 12:16:06 -0700 | [diff] [blame] | 172 | /** Preview callback related members */ |
| 173 | |
Eino-Ville Talvala | d86a688 | 2012-08-28 11:34:14 -0700 | [diff] [blame] | 174 | sp<camera2::CallbackProcessor> mCallbackProcessor; |
Eino-Ville Talvala | 228a538 | 2012-08-13 12:16:06 -0700 | [diff] [blame] | 175 | |
Eino-Ville Talvala | 9cca4c6 | 2012-06-15 15:41:44 -0700 | [diff] [blame] | 176 | /* Still image capture related members */ |
| 177 | |
Eino-Ville Talvala | da6665c | 2012-08-29 17:37:16 -0700 | [diff] [blame] | 178 | sp<camera2::CaptureSequencer> mCaptureSequencer; |
| 179 | sp<camera2::JpegProcessor> mJpegProcessor; |
Igor Murashkin | ae500e5 | 2013-04-22 14:03:54 -0700 | [diff] [blame] | 180 | sp<camera2::ZslProcessorInterface> mZslProcessor; |
| 181 | sp<Thread> mZslProcessorThread; |
Eino-Ville Talvala | 9cca4c6 | 2012-06-15 15:41:44 -0700 | [diff] [blame] | 182 | |
Eino-Ville Talvala | 174181e | 2012-08-03 13:53:39 -0700 | [diff] [blame] | 183 | /** Notification-related members */ |
| 184 | |
| 185 | bool mAfInMotion; |
| 186 | |
Eino-Ville Talvala | 9cca4c6 | 2012-06-15 15:41:44 -0700 | [diff] [blame] | 187 | /** Utility members */ |
| 188 | |
Eino-Ville Talvala | 4865c52 | 2012-10-02 13:30:28 -0700 | [diff] [blame] | 189 | // Wait until the camera device has received the latest control settings |
| 190 | status_t syncWithDevice(); |
Eino-Ville Talvala | 61ab9f9 | 2012-05-17 10:30:54 -0700 | [diff] [blame] | 191 | }; |
| 192 | |
| 193 | }; // namespace android |
| 194 | |
| 195 | #endif |