Igor Murashkin | e7ee763 | 2013-06-11 18:10:18 -0700 | [diff] [blame] | 1 | /* |
Shuzhen Wang | c28189a | 2017-11-27 23:05:10 -0800 | [diff] [blame] | 2 | * Copyright (C) 2013-2018 The Android Open Source Project |
Igor Murashkin | e7ee763 | 2013-06-11 18:10:18 -0700 | [diff] [blame] | 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_PHOTOGRAPHY_CAMERADEVICECLIENT_H |
| 18 | #define ANDROID_SERVERS_CAMERA_PHOTOGRAPHY_CAMERADEVICECLIENT_H |
| 19 | |
Eino-Ville Talvala | d56db1d | 2015-12-17 16:50:35 -0800 | [diff] [blame] | 20 | #include <android/hardware/camera2/BnCameraDeviceUser.h> |
| 21 | #include <android/hardware/camera2/ICameraDeviceCallbacks.h> |
Yin-Chia Yeh | b97babb | 2015-03-12 13:42:44 -0700 | [diff] [blame] | 22 | #include <camera/camera2/OutputConfiguration.h> |
Emilian Peev | 35ae826 | 2018-11-08 13:11:32 +0000 | [diff] [blame] | 23 | #include <camera/camera2/SessionConfiguration.h> |
Eino-Ville Talvala | d56db1d | 2015-12-17 16:50:35 -0800 | [diff] [blame] | 24 | #include <camera/camera2/SubmitInfo.h> |
Eino-Ville Talvala | 7b82efe | 2013-07-25 17:12:35 -0700 | [diff] [blame] | 25 | |
Igor Murashkin | e7ee763 | 2013-06-11 18:10:18 -0700 | [diff] [blame] | 26 | #include "CameraService.h" |
Eino-Ville Talvala | 7b82efe | 2013-07-25 17:12:35 -0700 | [diff] [blame] | 27 | #include "common/FrameProcessorBase.h" |
| 28 | #include "common/Camera2ClientBase.h" |
Emilian Peev | 538c90e | 2018-12-17 18:03:19 +0000 | [diff] [blame] | 29 | #include "CompositeStream.h" |
Igor Murashkin | e7ee763 | 2013-06-11 18:10:18 -0700 | [diff] [blame] | 30 | |
Emilian Peev | 40ead60 | 2017-09-26 15:46:36 +0100 | [diff] [blame] | 31 | using android::camera3::OutputStreamInfo; |
Emilian Peev | 538c90e | 2018-12-17 18:03:19 +0000 | [diff] [blame] | 32 | using android::camera3::CompositeStream; |
Emilian Peev | 40ead60 | 2017-09-26 15:46:36 +0100 | [diff] [blame] | 33 | |
Igor Murashkin | e7ee763 | 2013-06-11 18:10:18 -0700 | [diff] [blame] | 34 | namespace android { |
| 35 | |
Eino-Ville Talvala | d56db1d | 2015-12-17 16:50:35 -0800 | [diff] [blame] | 36 | struct CameraDeviceClientBase : |
| 37 | public CameraService::BasicClient, |
| 38 | public hardware::camera2::BnCameraDeviceUser |
Igor Murashkin | e7ee763 | 2013-06-11 18:10:18 -0700 | [diff] [blame] | 39 | { |
Eino-Ville Talvala | d56db1d | 2015-12-17 16:50:35 -0800 | [diff] [blame] | 40 | typedef hardware::camera2::ICameraDeviceCallbacks TCamCallbacks; |
Igor Murashkin | e7ee763 | 2013-06-11 18:10:18 -0700 | [diff] [blame] | 41 | |
Eino-Ville Talvala | d56db1d | 2015-12-17 16:50:35 -0800 | [diff] [blame] | 42 | const sp<hardware::camera2::ICameraDeviceCallbacks>& getRemoteCallback() { |
Igor Murashkin | e7ee763 | 2013-06-11 18:10:18 -0700 | [diff] [blame] | 43 | return mRemoteCallback; |
| 44 | } |
| 45 | |
| 46 | protected: |
| 47 | CameraDeviceClientBase(const sp<CameraService>& cameraService, |
Eino-Ville Talvala | d56db1d | 2015-12-17 16:50:35 -0800 | [diff] [blame] | 48 | const sp<hardware::camera2::ICameraDeviceCallbacks>& remoteCallback, |
Igor Murashkin | e7ee763 | 2013-06-11 18:10:18 -0700 | [diff] [blame] | 49 | const String16& clientPackageName, |
Eino-Ville Talvala | 2f09bac | 2016-12-13 11:29:54 -0800 | [diff] [blame] | 50 | const String8& cameraId, |
Yin-Chia Yeh | c3e9d6f | 2018-02-06 10:56:32 -0800 | [diff] [blame] | 51 | int api1CameraId, |
Igor Murashkin | e7ee763 | 2013-06-11 18:10:18 -0700 | [diff] [blame] | 52 | int cameraFacing, |
| 53 | int clientPid, |
| 54 | uid_t clientUid, |
| 55 | int servicePid); |
| 56 | |
Eino-Ville Talvala | d56db1d | 2015-12-17 16:50:35 -0800 | [diff] [blame] | 57 | sp<hardware::camera2::ICameraDeviceCallbacks> mRemoteCallback; |
Igor Murashkin | e7ee763 | 2013-06-11 18:10:18 -0700 | [diff] [blame] | 58 | }; |
| 59 | |
| 60 | /** |
| 61 | * Implements the binder ICameraDeviceUser API, |
| 62 | * meant for HAL3-public implementation of |
| 63 | * android.hardware.photography.CameraDevice |
| 64 | */ |
| 65 | class CameraDeviceClient : |
| 66 | public Camera2ClientBase<CameraDeviceClientBase>, |
Eino-Ville Talvala | 7b82efe | 2013-07-25 17:12:35 -0700 | [diff] [blame] | 67 | public camera2::FrameProcessorBase::FilteredListener |
Igor Murashkin | e7ee763 | 2013-06-11 18:10:18 -0700 | [diff] [blame] | 68 | { |
| 69 | public: |
| 70 | /** |
| 71 | * ICameraDeviceUser interface (see ICameraDeviceUser for details) |
| 72 | */ |
| 73 | |
| 74 | // Note that the callee gets a copy of the metadata. |
Eino-Ville Talvala | d56db1d | 2015-12-17 16:50:35 -0800 | [diff] [blame] | 75 | virtual binder::Status submitRequest( |
| 76 | const hardware::camera2::CaptureRequest& request, |
| 77 | bool streaming = false, |
| 78 | /*out*/ |
Eino-Ville Talvala | bbbbe84 | 2017-02-28 17:50:56 -0800 | [diff] [blame] | 79 | hardware::camera2::utils::SubmitInfo *submitInfo = nullptr) override; |
Jianing Wei | 90e59c9 | 2014-03-12 18:29:36 -0700 | [diff] [blame] | 80 | // List of requests are copied. |
Eino-Ville Talvala | d56db1d | 2015-12-17 16:50:35 -0800 | [diff] [blame] | 81 | virtual binder::Status submitRequestList( |
| 82 | const std::vector<hardware::camera2::CaptureRequest>& requests, |
| 83 | bool streaming = false, |
| 84 | /*out*/ |
Eino-Ville Talvala | bbbbe84 | 2017-02-28 17:50:56 -0800 | [diff] [blame] | 85 | hardware::camera2::utils::SubmitInfo *submitInfo = nullptr) override; |
Eino-Ville Talvala | d56db1d | 2015-12-17 16:50:35 -0800 | [diff] [blame] | 86 | virtual binder::Status cancelRequest(int requestId, |
| 87 | /*out*/ |
Eino-Ville Talvala | bbbbe84 | 2017-02-28 17:50:56 -0800 | [diff] [blame] | 88 | int64_t* lastFrameNumber = NULL) override; |
Igor Murashkin | e7ee763 | 2013-06-11 18:10:18 -0700 | [diff] [blame] | 89 | |
Eino-Ville Talvala | bbbbe84 | 2017-02-28 17:50:56 -0800 | [diff] [blame] | 90 | virtual binder::Status beginConfigure() override; |
Ruben Brunk | b2119af | 2014-05-09 19:57:56 -0700 | [diff] [blame] | 91 | |
Emilian Peev | 5fbe0ba | 2017-10-20 15:45:45 +0100 | [diff] [blame] | 92 | virtual binder::Status endConfigure(int operatingMode, |
| 93 | const hardware::camera2::impl::CameraMetadataNative& sessionParams) override; |
Ruben Brunk | b2119af | 2014-05-09 19:57:56 -0700 | [diff] [blame] | 94 | |
Emilian Peev | 35ae826 | 2018-11-08 13:11:32 +0000 | [diff] [blame] | 95 | // Verify specific session configuration. |
| 96 | virtual binder::Status isSessionConfigurationSupported( |
| 97 | const SessionConfiguration& sessionConfiguration, |
| 98 | /*out*/ |
| 99 | bool* streamStatus) override; |
| 100 | |
Yin-Chia Yeh | 5090c73 | 2017-07-20 16:05:29 -0700 | [diff] [blame] | 101 | // Returns -EBUSY if device is not idle or in error state |
Eino-Ville Talvala | bbbbe84 | 2017-02-28 17:50:56 -0800 | [diff] [blame] | 102 | virtual binder::Status deleteStream(int streamId) override; |
Igor Murashkin | e7ee763 | 2013-06-11 18:10:18 -0700 | [diff] [blame] | 103 | |
Eino-Ville Talvala | d56db1d | 2015-12-17 16:50:35 -0800 | [diff] [blame] | 104 | virtual binder::Status createStream( |
| 105 | const hardware::camera2::params::OutputConfiguration &outputConfiguration, |
| 106 | /*out*/ |
Eino-Ville Talvala | bbbbe84 | 2017-02-28 17:50:56 -0800 | [diff] [blame] | 107 | int32_t* newStreamId = NULL) override; |
Igor Murashkin | e7ee763 | 2013-06-11 18:10:18 -0700 | [diff] [blame] | 108 | |
Chien-Yu Chen | 618ff8a | 2015-03-13 11:27:17 -0700 | [diff] [blame] | 109 | // Create an input stream of width, height, and format. |
Eino-Ville Talvala | d56db1d | 2015-12-17 16:50:35 -0800 | [diff] [blame] | 110 | virtual binder::Status createInputStream(int width, int height, int format, |
| 111 | /*out*/ |
Eino-Ville Talvala | bbbbe84 | 2017-02-28 17:50:56 -0800 | [diff] [blame] | 112 | int32_t* newStreamId = NULL) override; |
Chien-Yu Chen | 618ff8a | 2015-03-13 11:27:17 -0700 | [diff] [blame] | 113 | |
| 114 | // Get the buffer producer of the input stream |
Eino-Ville Talvala | d56db1d | 2015-12-17 16:50:35 -0800 | [diff] [blame] | 115 | virtual binder::Status getInputSurface( |
| 116 | /*out*/ |
Eino-Ville Talvala | bbbbe84 | 2017-02-28 17:50:56 -0800 | [diff] [blame] | 117 | view::Surface *inputSurface) override; |
Chien-Yu Chen | 618ff8a | 2015-03-13 11:27:17 -0700 | [diff] [blame] | 118 | |
Igor Murashkin | e7ee763 | 2013-06-11 18:10:18 -0700 | [diff] [blame] | 119 | // Create a request object from a template. |
Eino-Ville Talvala | d56db1d | 2015-12-17 16:50:35 -0800 | [diff] [blame] | 120 | virtual binder::Status createDefaultRequest(int templateId, |
| 121 | /*out*/ |
Eino-Ville Talvala | bbbbe84 | 2017-02-28 17:50:56 -0800 | [diff] [blame] | 122 | hardware::camera2::impl::CameraMetadataNative* request) override; |
Igor Murashkin | e7ee763 | 2013-06-11 18:10:18 -0700 | [diff] [blame] | 123 | |
| 124 | // Get the static metadata for the camera |
| 125 | // -- Caller owns the newly allocated metadata |
Eino-Ville Talvala | d56db1d | 2015-12-17 16:50:35 -0800 | [diff] [blame] | 126 | virtual binder::Status getCameraInfo( |
| 127 | /*out*/ |
Eino-Ville Talvala | bbbbe84 | 2017-02-28 17:50:56 -0800 | [diff] [blame] | 128 | hardware::camera2::impl::CameraMetadataNative* cameraCharacteristics) override; |
Igor Murashkin | e7ee763 | 2013-06-11 18:10:18 -0700 | [diff] [blame] | 129 | |
Zhijun He | 2ab500c | 2013-07-23 08:02:53 -0700 | [diff] [blame] | 130 | // Wait until all the submitted requests have finished processing |
Eino-Ville Talvala | bbbbe84 | 2017-02-28 17:50:56 -0800 | [diff] [blame] | 131 | virtual binder::Status waitUntilIdle() override; |
Eino-Ville Talvala | abaa51d | 2013-08-14 11:37:00 -0700 | [diff] [blame] | 132 | |
| 133 | // Flush all active and pending requests as fast as possible |
Eino-Ville Talvala | d56db1d | 2015-12-17 16:50:35 -0800 | [diff] [blame] | 134 | virtual binder::Status flush( |
| 135 | /*out*/ |
Eino-Ville Talvala | bbbbe84 | 2017-02-28 17:50:56 -0800 | [diff] [blame] | 136 | int64_t* lastFrameNumber = NULL) override; |
Eino-Ville Talvala | abaa51d | 2013-08-14 11:37:00 -0700 | [diff] [blame] | 137 | |
Eino-Ville Talvala | 4d44cad | 2015-04-11 13:15:45 -0700 | [diff] [blame] | 138 | // Prepare stream by preallocating its buffers |
Eino-Ville Talvala | bbbbe84 | 2017-02-28 17:50:56 -0800 | [diff] [blame] | 139 | virtual binder::Status prepare(int32_t streamId) override; |
Eino-Ville Talvala | 4d44cad | 2015-04-11 13:15:45 -0700 | [diff] [blame] | 140 | |
Eino-Ville Talvala | b25e3c8 | 2015-07-15 16:04:27 -0700 | [diff] [blame] | 141 | // Tear down stream resources by freeing its unused buffers |
Eino-Ville Talvala | bbbbe84 | 2017-02-28 17:50:56 -0800 | [diff] [blame] | 142 | virtual binder::Status tearDown(int32_t streamId) override; |
Eino-Ville Talvala | b25e3c8 | 2015-07-15 16:04:27 -0700 | [diff] [blame] | 143 | |
Ruben Brunk | c78ac26 | 2015-08-13 17:58:46 -0700 | [diff] [blame] | 144 | // Prepare stream by preallocating up to maxCount of its buffers |
Eino-Ville Talvala | bbbbe84 | 2017-02-28 17:50:56 -0800 | [diff] [blame] | 145 | virtual binder::Status prepare2(int32_t maxCount, int32_t streamId) override; |
Ruben Brunk | c78ac26 | 2015-08-13 17:58:46 -0700 | [diff] [blame] | 146 | |
Emilian Peev | 40ead60 | 2017-09-26 15:46:36 +0100 | [diff] [blame] | 147 | // Update an output configuration |
| 148 | virtual binder::Status updateOutputConfiguration(int streamId, |
| 149 | const hardware::camera2::params::OutputConfiguration &outputConfiguration) override; |
| 150 | |
Shuzhen Wang | 758c215 | 2017-01-10 18:26:18 -0800 | [diff] [blame] | 151 | // Finalize the output configurations with surfaces not added before. |
| 152 | virtual binder::Status finalizeOutputConfigurations(int32_t streamId, |
Eino-Ville Talvala | bbbbe84 | 2017-02-28 17:50:56 -0800 | [diff] [blame] | 153 | const hardware::camera2::params::OutputConfiguration &outputConfiguration) override; |
Zhijun He | 5d677d1 | 2016-05-29 16:52:39 -0700 | [diff] [blame] | 154 | |
Yin-Chia Yeh | cfab4e1 | 2019-09-09 13:08:28 -0700 | [diff] [blame] | 155 | virtual binder::Status setCameraAudioRestriction(int32_t mode) override; |
| 156 | |
| 157 | virtual binder::Status getGlobalAudioRestriction(/*out*/int32_t* outMode) override; |
Yin-Chia Yeh | dba0323 | 2019-08-19 15:54:28 -0700 | [diff] [blame] | 158 | |
Igor Murashkin | e7ee763 | 2013-06-11 18:10:18 -0700 | [diff] [blame] | 159 | /** |
| 160 | * Interface used by CameraService |
| 161 | */ |
| 162 | |
| 163 | CameraDeviceClient(const sp<CameraService>& cameraService, |
Eino-Ville Talvala | d56db1d | 2015-12-17 16:50:35 -0800 | [diff] [blame] | 164 | const sp<hardware::camera2::ICameraDeviceCallbacks>& remoteCallback, |
Igor Murashkin | e7ee763 | 2013-06-11 18:10:18 -0700 | [diff] [blame] | 165 | const String16& clientPackageName, |
Eino-Ville Talvala | 2f09bac | 2016-12-13 11:29:54 -0800 | [diff] [blame] | 166 | const String8& cameraId, |
Igor Murashkin | e7ee763 | 2013-06-11 18:10:18 -0700 | [diff] [blame] | 167 | int cameraFacing, |
| 168 | int clientPid, |
| 169 | uid_t clientUid, |
| 170 | int servicePid); |
| 171 | virtual ~CameraDeviceClient(); |
| 172 | |
Emilian Peev | bd8c503 | 2018-02-14 23:05:40 +0000 | [diff] [blame] | 173 | virtual status_t initialize(sp<CameraProviderManager> manager, |
| 174 | const String8& monitorTags) override; |
Igor Murashkin | e7ee763 | 2013-06-11 18:10:18 -0700 | [diff] [blame] | 175 | |
| 176 | virtual status_t dump(int fd, const Vector<String16>& args); |
| 177 | |
Eino-Ville Talvala | c400396 | 2016-01-13 10:07:04 -0800 | [diff] [blame] | 178 | virtual status_t dumpClient(int fd, const Vector<String16>& args); |
| 179 | |
Igor Murashkin | e7ee763 | 2013-06-11 18:10:18 -0700 | [diff] [blame] | 180 | /** |
Eino-Ville Talvala | f1e98d8 | 2013-09-06 09:32:43 -0700 | [diff] [blame] | 181 | * Device listener interface |
| 182 | */ |
| 183 | |
| 184 | virtual void notifyIdle(); |
Eino-Ville Talvala | d56db1d | 2015-12-17 16:50:35 -0800 | [diff] [blame] | 185 | virtual void notifyError(int32_t errorCode, |
Jianing Wei | cb0652e | 2014-03-12 18:29:36 -0700 | [diff] [blame] | 186 | const CaptureResultExtras& resultExtras); |
| 187 | virtual void notifyShutter(const CaptureResultExtras& resultExtras, nsecs_t timestamp); |
Eino-Ville Talvala | 4d44cad | 2015-04-11 13:15:45 -0700 | [diff] [blame] | 188 | virtual void notifyPrepared(int streamId); |
Shuzhen Wang | 9d06601 | 2016-09-30 11:30:20 -0700 | [diff] [blame] | 189 | virtual void notifyRequestQueueEmpty(); |
Chien-Yu Chen | e8c535e | 2016-04-14 12:18:26 -0700 | [diff] [blame] | 190 | virtual void notifyRepeatingRequestError(long lastFrameNumber); |
Eino-Ville Talvala | f1e98d8 | 2013-09-06 09:32:43 -0700 | [diff] [blame] | 191 | |
| 192 | /** |
Igor Murashkin | e7ee763 | 2013-06-11 18:10:18 -0700 | [diff] [blame] | 193 | * Interface used by independent components of CameraDeviceClient. |
| 194 | */ |
| 195 | protected: |
| 196 | /** FilteredListener implementation **/ |
Jianing Wei | cb0652e | 2014-03-12 18:29:36 -0700 | [diff] [blame] | 197 | virtual void onResultAvailable(const CaptureResult& result); |
Igor Murashkin | e7ee763 | 2013-06-11 18:10:18 -0700 | [diff] [blame] | 198 | virtual void detachDevice(); |
| 199 | |
Igor Murashkin | f8b2a6f | 2013-09-17 17:03:28 -0700 | [diff] [blame] | 200 | // Calculate the ANativeWindow transform from android.sensor.orientation |
| 201 | status_t getRotationTransformLocked(/*out*/int32_t* transform); |
| 202 | |
Igor Murashkin | e7ee763 | 2013-06-11 18:10:18 -0700 | [diff] [blame] | 203 | private: |
Shuzhen Wang | 0129d52 | 2016-10-30 22:43:41 -0700 | [diff] [blame] | 204 | // StreamSurfaceId encapsulates streamId + surfaceId for a particular surface. |
| 205 | // streamId specifies the index of the stream the surface belongs to, and the |
| 206 | // surfaceId specifies the index of the surface within the stream. (one stream |
| 207 | // could contain multiple surfaces.) |
| 208 | class StreamSurfaceId final { |
| 209 | public: |
| 210 | StreamSurfaceId() { |
| 211 | mStreamId = -1; |
| 212 | mSurfaceId = -1; |
| 213 | } |
| 214 | StreamSurfaceId(int32_t streamId, int32_t surfaceId) { |
| 215 | mStreamId = streamId; |
| 216 | mSurfaceId = surfaceId; |
| 217 | } |
| 218 | int32_t streamId() const { |
| 219 | return mStreamId; |
| 220 | } |
| 221 | int32_t surfaceId() const { |
| 222 | return mSurfaceId; |
| 223 | } |
| 224 | |
| 225 | private: |
| 226 | int32_t mStreamId; |
| 227 | int32_t mSurfaceId; |
| 228 | |
| 229 | }; // class StreamSurfaceId |
| 230 | |
| 231 | private: |
Igor Murashkin | e7ee763 | 2013-06-11 18:10:18 -0700 | [diff] [blame] | 232 | /** ICameraDeviceUser interface-related private members */ |
| 233 | |
| 234 | /** Preview callback related members */ |
Eino-Ville Talvala | 7b82efe | 2013-07-25 17:12:35 -0700 | [diff] [blame] | 235 | sp<camera2::FrameProcessorBase> mFrameProcessor; |
Igor Murashkin | e7ee763 | 2013-06-11 18:10:18 -0700 | [diff] [blame] | 236 | static const int32_t FRAME_PROCESSOR_LISTENER_MIN_ID = 0; |
| 237 | static const int32_t FRAME_PROCESSOR_LISTENER_MAX_ID = 0x7fffffffL; |
| 238 | |
Emilian Peev | 00420d2 | 2018-02-05 21:33:13 +0000 | [diff] [blame] | 239 | std::vector<int32_t> mSupportedPhysicalRequestKeys; |
| 240 | |
Eino-Ville Talvala | 2f09bac | 2016-12-13 11:29:54 -0800 | [diff] [blame] | 241 | template<typename TProviderPtr> |
Emilian Peev | bd8c503 | 2018-02-14 23:05:40 +0000 | [diff] [blame] | 242 | status_t initializeImpl(TProviderPtr providerPtr, const String8& monitorTags); |
Eino-Ville Talvala | 2f09bac | 2016-12-13 11:29:54 -0800 | [diff] [blame] | 243 | |
Igor Murashkin | e7ee763 | 2013-06-11 18:10:18 -0700 | [diff] [blame] | 244 | /** Utility members */ |
Eino-Ville Talvala | d56db1d | 2015-12-17 16:50:35 -0800 | [diff] [blame] | 245 | binder::Status checkPidStatus(const char* checkLocation); |
Emilian Peev | 35ae826 | 2018-11-08 13:11:32 +0000 | [diff] [blame] | 246 | binder::Status checkOperatingModeLocked(int operatingMode) const; |
| 247 | binder::Status checkPhysicalCameraIdLocked(String8 physicalCameraId); |
| 248 | binder::Status checkSurfaceTypeLocked(size_t numBufferProducers, bool deferredConsumer, |
| 249 | int surfaceType) const; |
| 250 | static void mapStreamInfo(const OutputStreamInfo &streamInfo, |
| 251 | camera3_stream_rotation_t rotation, String8 physicalId, |
| 252 | hardware::camera::device::V3_4::Stream *stream /*out*/); |
Igor Murashkin | e7ee763 | 2013-06-11 18:10:18 -0700 | [diff] [blame] | 253 | bool enforceRequestPermissions(CameraMetadata& metadata); |
| 254 | |
Ruben Brunk | bba7557 | 2014-11-20 17:29:50 -0800 | [diff] [blame] | 255 | // Find the square of the euclidean distance between two points |
| 256 | static int64_t euclidDistSquare(int32_t x0, int32_t y0, int32_t x1, int32_t y1); |
| 257 | |
Zhijun He | 5d677d1 | 2016-05-29 16:52:39 -0700 | [diff] [blame] | 258 | // Create an output stream with surface deferred for future. |
| 259 | binder::Status createDeferredSurfaceStreamLocked( |
| 260 | const hardware::camera2::params::OutputConfiguration &outputConfiguration, |
Shuzhen Wang | 758c215 | 2017-01-10 18:26:18 -0800 | [diff] [blame] | 261 | bool isShared, |
Zhijun He | 5d677d1 | 2016-05-29 16:52:39 -0700 | [diff] [blame] | 262 | int* newStreamId = NULL); |
| 263 | |
| 264 | // Set the stream transform flags to automatically rotate the camera stream for preview use |
| 265 | // cases. |
| 266 | binder::Status setStreamTransformLocked(int streamId); |
| 267 | |
Ruben Brunk | bba7557 | 2014-11-20 17:29:50 -0800 | [diff] [blame] | 268 | // Find the closest dimensions for a given format in available stream configurations with |
| 269 | // a width <= ROUNDING_WIDTH_CAP |
Ruben Brunk | 77a77f6 | 2015-06-12 16:15:35 -0700 | [diff] [blame] | 270 | static const int32_t ROUNDING_WIDTH_CAP = 1920; |
Ruben Brunk | bba7557 | 2014-11-20 17:29:50 -0800 | [diff] [blame] | 271 | static bool roundBufferDimensionNearest(int32_t width, int32_t height, int32_t format, |
Eino-Ville Talvala | 3d82c0d | 2015-02-23 15:19:19 -0800 | [diff] [blame] | 272 | android_dataspace dataSpace, const CameraMetadata& info, |
| 273 | /*out*/int32_t* outWidth, /*out*/int32_t* outHeight); |
Ruben Brunk | bba7557 | 2014-11-20 17:29:50 -0800 | [diff] [blame] | 274 | |
Eman Copty | 6d7af0e | 2016-06-17 20:46:40 -0700 | [diff] [blame] | 275 | //check if format is not custom format |
| 276 | static bool isPublicFormat(int32_t format); |
| 277 | |
Shuzhen Wang | 758c215 | 2017-01-10 18:26:18 -0800 | [diff] [blame] | 278 | // Create a Surface from an IGraphicBufferProducer. Returns error if |
| 279 | // IGraphicBufferProducer's property doesn't match with streamInfo |
| 280 | binder::Status createSurfaceFromGbp(OutputStreamInfo& streamInfo, bool isStreamInfoValid, |
Shuzhen Wang | 2e7f58f | 2018-07-11 14:00:29 -0700 | [diff] [blame] | 281 | sp<Surface>& surface, const sp<IGraphicBufferProducer>& gbp, |
| 282 | const String8& physicalCameraId); |
Shuzhen Wang | 758c215 | 2017-01-10 18:26:18 -0800 | [diff] [blame] | 283 | |
Yin-Chia Yeh | 4dfa4cc | 2017-11-10 20:00:09 -0800 | [diff] [blame] | 284 | |
| 285 | // Utility method to insert the surface into SurfaceMap |
| 286 | binder::Status insertGbpLocked(const sp<IGraphicBufferProducer>& gbp, |
Emilian Peev | f873aa5 | 2018-01-26 14:58:28 +0000 | [diff] [blame] | 287 | /*out*/SurfaceMap* surfaceMap, /*out*/Vector<int32_t>* streamIds, |
| 288 | /*out*/int32_t* currentStreamId); |
Yin-Chia Yeh | 4dfa4cc | 2017-11-10 20:00:09 -0800 | [diff] [blame] | 289 | |
Shuzhen Wang | c28189a | 2017-11-27 23:05:10 -0800 | [diff] [blame] | 290 | // Check that the physicalCameraId passed in is spported by the camera |
| 291 | // device. |
| 292 | bool checkPhysicalCameraId(const String8& physicalCameraId); |
| 293 | |
Shuzhen Wang | 0129d52 | 2016-10-30 22:43:41 -0700 | [diff] [blame] | 294 | // IGraphicsBufferProducer binder -> Stream ID + Surface ID for output streams |
| 295 | KeyedVector<sp<IBinder>, StreamSurfaceId> mStreamMap; |
Igor Murashkin | e7ee763 | 2013-06-11 18:10:18 -0700 | [diff] [blame] | 296 | |
Yin-Chia Yeh | 4dfa4cc | 2017-11-10 20:00:09 -0800 | [diff] [blame] | 297 | // Stream ID -> OutputConfiguration. Used for looking up Surface by stream/surface index |
| 298 | KeyedVector<int32_t, hardware::camera2::params::OutputConfiguration> mConfiguredOutputs; |
| 299 | |
Chien-Yu Chen | 618ff8a | 2015-03-13 11:27:17 -0700 | [diff] [blame] | 300 | struct InputStreamConfiguration { |
| 301 | bool configured; |
| 302 | int32_t width; |
| 303 | int32_t height; |
| 304 | int32_t format; |
| 305 | int32_t id; |
| 306 | } mInputStream; |
| 307 | |
Chien-Yu Chen | e8c535e | 2016-04-14 12:18:26 -0700 | [diff] [blame] | 308 | // Streaming request ID |
| 309 | int32_t mStreamingRequestId; |
Shuzhen Wang | c9ca678 | 2016-04-26 13:40:31 -0700 | [diff] [blame] | 310 | Mutex mStreamingRequestIdLock; |
Chien-Yu Chen | e8c535e | 2016-04-14 12:18:26 -0700 | [diff] [blame] | 311 | static const int32_t REQUEST_ID_NONE = -1; |
Igor Murashkin | e7ee763 | 2013-06-11 18:10:18 -0700 | [diff] [blame] | 312 | |
| 313 | int32_t mRequestIdCounter; |
Eino-Ville Talvala | 412fe56 | 2015-08-20 17:08:32 -0700 | [diff] [blame] | 314 | |
Zhijun He | 5d677d1 | 2016-05-29 16:52:39 -0700 | [diff] [blame] | 315 | // The list of output streams whose surfaces are deferred. We have to track them separately |
| 316 | // as there are no surfaces available and can not be put into mStreamMap. Once the deferred |
| 317 | // Surface is configured, the stream id will be moved to mStreamMap. |
| 318 | Vector<int32_t> mDeferredStreams; |
Shuzhen Wang | 0129d52 | 2016-10-30 22:43:41 -0700 | [diff] [blame] | 319 | |
Shuzhen Wang | 758c215 | 2017-01-10 18:26:18 -0800 | [diff] [blame] | 320 | // stream ID -> outputStreamInfo mapping |
| 321 | std::unordered_map<int32_t, OutputStreamInfo> mStreamInfoMap; |
| 322 | |
Emilian Peev | 538c90e | 2018-12-17 18:03:19 +0000 | [diff] [blame] | 323 | KeyedVector<sp<IBinder>, sp<CompositeStream>> mCompositeStreamMap; |
| 324 | |
Emilian Peev | 35ae826 | 2018-11-08 13:11:32 +0000 | [diff] [blame] | 325 | static const int32_t MAX_SURFACES_PER_STREAM = 4; |
Shuzhen Wang | 03d8cc1 | 2018-09-12 14:17:09 -0700 | [diff] [blame] | 326 | sp<CameraProviderManager> mProviderManager; |
Igor Murashkin | e7ee763 | 2013-06-11 18:10:18 -0700 | [diff] [blame] | 327 | }; |
| 328 | |
| 329 | }; // namespace android |
| 330 | |
| 331 | #endif |