Eino-Ville Talvala | 7fa43f3 | 2013-02-06 17:20:07 -0800 | [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 |
Eino-Ville Talvala | 7fa43f3 | 2013-02-06 17:20:07 -0800 | [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_CAMERADEVICEBASE_H |
| 18 | #define ANDROID_SERVERS_CAMERA_CAMERADEVICEBASE_H |
| 19 | |
Shuzhen Wang | 0129d52 | 2016-10-30 22:43:41 -0700 | [diff] [blame] | 20 | #include <list> |
| 21 | |
Eino-Ville Talvala | 7fa43f3 | 2013-02-06 17:20:07 -0800 | [diff] [blame] | 22 | #include <utils/RefBase.h> |
Eino-Ville Talvala | 7fa43f3 | 2013-02-06 17:20:07 -0800 | [diff] [blame] | 23 | #include <utils/String16.h> |
| 24 | #include <utils/Vector.h> |
Emilian Peev | 40ead60 | 2017-09-26 15:46:36 +0100 | [diff] [blame] | 25 | #include <utils/KeyedVector.h> |
Eino-Ville Talvala | 7fa43f3 | 2013-02-06 17:20:07 -0800 | [diff] [blame] | 26 | #include <utils/Timers.h> |
Jianing Wei | 90e59c9 | 2014-03-12 18:29:36 -0700 | [diff] [blame] | 27 | #include <utils/List.h> |
Carlos Martinez Romero | 8e77610 | 2024-08-21 12:49:10 -0700 | [diff] [blame] | 28 | #include <gui/Flags.h> |
Eino-Ville Talvala | 7fa43f3 | 2013-02-06 17:20:07 -0800 | [diff] [blame] | 29 | |
| 30 | #include "hardware/camera2.h" |
| 31 | #include "camera/CameraMetadata.h" |
Jianing Wei | cb0652e | 2014-03-12 18:29:36 -0700 | [diff] [blame] | 32 | #include "camera/CaptureResult.h" |
Chien-Yu Chen | 618ff8a | 2015-03-13 11:27:17 -0700 | [diff] [blame] | 33 | #include "gui/IGraphicBufferProducer.h" |
Zhijun He | 125684a | 2015-12-26 15:07:30 -0800 | [diff] [blame] | 34 | #include "device3/Camera3StreamInterface.h" |
Shuzhen Wang | e867578 | 2019-12-05 09:12:14 -0800 | [diff] [blame] | 35 | #include "device3/StatusTracker.h" |
Eino-Ville Talvala | d56db1d | 2015-12-17 16:50:35 -0800 | [diff] [blame] | 36 | #include "binder/Status.h" |
Emilian Peev | faa4bde | 2020-01-23 12:19:37 -0800 | [diff] [blame] | 37 | #include "FrameProducer.h" |
Jayant Chowdhary | c67af1b | 2022-04-07 18:05:04 +0000 | [diff] [blame] | 38 | #include "utils/IPCTransport.h" |
Shuzhen Wang | 045be6c | 2023-10-12 10:01:10 -0700 | [diff] [blame] | 39 | #include "utils/SessionConfigurationUtils.h" |
Eino-Ville Talvala | 7fa43f3 | 2013-02-06 17:20:07 -0800 | [diff] [blame] | 40 | |
Yin-Chia Yeh | b978c38 | 2019-10-30 00:22:37 -0700 | [diff] [blame] | 41 | #include "CameraOfflineSessionBase.h" |
| 42 | |
Eino-Ville Talvala | 7fa43f3 | 2013-02-06 17:20:07 -0800 | [diff] [blame] | 43 | namespace android { |
| 44 | |
Emilian Peev | f481670 | 2020-04-03 15:44:51 -0700 | [diff] [blame] | 45 | namespace camera3 { |
| 46 | |
Emilian Peev | f481670 | 2020-04-03 15:44:51 -0700 | [diff] [blame] | 47 | typedef enum camera_stream_configuration_mode { |
| 48 | CAMERA_STREAM_CONFIGURATION_NORMAL_MODE = 0, |
| 49 | CAMERA_STREAM_CONFIGURATION_CONSTRAINED_HIGH_SPEED_MODE = 1, |
| 50 | CAMERA_VENDOR_STREAM_CONFIGURATION_MODE_START = 0x8000 |
| 51 | } camera_stream_configuration_mode_t; |
| 52 | |
Jayant Chowdhary | c67af1b | 2022-04-07 18:05:04 +0000 | [diff] [blame] | 53 | // Matches definition of camera3_jpeg_blob in camera3.h and HIDL definition |
| 54 | // device@3.2:types.hal, needs to stay around till HIDL support is removed (for |
| 55 | // HIDL -> AIDL cameraBlob translation) |
Emilian Peev | f481670 | 2020-04-03 15:44:51 -0700 | [diff] [blame] | 56 | typedef struct camera_jpeg_blob { |
| 57 | uint16_t jpeg_blob_id; |
| 58 | uint32_t jpeg_size; |
| 59 | } camera_jpeg_blob_t; |
| 60 | |
| 61 | enum { |
| 62 | CAMERA_JPEG_BLOB_ID = 0x00FF, |
| 63 | CAMERA_JPEG_APP_SEGMENTS_BLOB_ID = 0x0100, |
| 64 | }; |
| 65 | |
| 66 | } // namespace camera3 |
| 67 | |
| 68 | using camera3::camera_request_template_t;; |
| 69 | using camera3::camera_stream_configuration_mode_t; |
| 70 | using camera3::camera_stream_rotation_t; |
Shuzhen Wang | 38df0ca | 2024-10-09 11:33:44 -0700 | [diff] [blame^] | 71 | using camera3::SurfaceHolder; |
Emilian Peev | f481670 | 2020-04-03 15:44:51 -0700 | [diff] [blame] | 72 | |
Eino-Ville Talvala | 2f09bac | 2016-12-13 11:29:54 -0800 | [diff] [blame] | 73 | class CameraProviderManager; |
| 74 | |
Shuzhen Wang | 0129d52 | 2016-10-30 22:43:41 -0700 | [diff] [blame] | 75 | // Mapping of output stream index to surface ids |
| 76 | typedef std::unordered_map<int, std::vector<size_t> > SurfaceMap; |
| 77 | |
Eino-Ville Talvala | 7fa43f3 | 2013-02-06 17:20:07 -0800 | [diff] [blame] | 78 | /** |
| 79 | * Base interface for version >= 2 camera device classes, which interface to |
| 80 | * camera HAL device versions >= 2. |
| 81 | */ |
Emilian Peev | faa4bde | 2020-01-23 12:19:37 -0800 | [diff] [blame] | 82 | class CameraDeviceBase : public virtual FrameProducer { |
Eino-Ville Talvala | 7fa43f3 | 2013-02-06 17:20:07 -0800 | [diff] [blame] | 83 | public: |
| 84 | virtual ~CameraDeviceBase(); |
| 85 | |
Jayant Chowdhary | c67af1b | 2022-04-07 18:05:04 +0000 | [diff] [blame] | 86 | virtual IPCTransport getTransportType() const = 0; |
| 87 | |
Igor Murashkin | 7138105 | 2013-03-04 14:53:08 -0800 | [diff] [blame] | 88 | /** |
Emilian Peev | 00420d2 | 2018-02-05 21:33:13 +0000 | [diff] [blame] | 89 | * The device vendor tag ID |
| 90 | */ |
| 91 | virtual metadata_vendor_id_t getVendorTagId() const = 0; |
| 92 | |
Austin Borger | ed99f64 | 2023-06-01 16:51:35 -0700 | [diff] [blame] | 93 | virtual status_t initialize(sp<CameraProviderManager> manager, |
| 94 | const std::string& monitorTags) = 0; |
Eino-Ville Talvala | 7fa43f3 | 2013-02-06 17:20:07 -0800 | [diff] [blame] | 95 | virtual status_t disconnect() = 0; |
| 96 | |
Jianing Wei | cb0652e | 2014-03-12 18:29:36 -0700 | [diff] [blame] | 97 | virtual status_t dump(int fd, const Vector<String16> &args) = 0; |
Austin Borger | ed99f64 | 2023-06-01 16:51:35 -0700 | [diff] [blame] | 98 | virtual status_t startWatchingTags(const std::string &tags) = 0; |
Avichal Rakesh | 7e53cad | 2021-10-05 13:46:30 -0700 | [diff] [blame] | 99 | virtual status_t stopWatchingTags() = 0; |
| 100 | virtual status_t dumpWatchedEventsToVector(std::vector<std::string> &out) = 0; |
Eino-Ville Talvala | 7fa43f3 | 2013-02-06 17:20:07 -0800 | [diff] [blame] | 101 | |
| 102 | /** |
Jayant Chowdhary | 6a6d3a8 | 2021-11-17 16:54:34 -0800 | [diff] [blame] | 103 | * The physical camera device's static characteristics metadata buffer, or |
| 104 | * the logical camera's static characteristics if physical id is empty. |
Shuzhen Wang | 2e7f58f | 2018-07-11 14:00:29 -0700 | [diff] [blame] | 105 | */ |
Austin Borger | ed99f64 | 2023-06-01 16:51:35 -0700 | [diff] [blame] | 106 | virtual const CameraMetadata& infoPhysical(const std::string& physicalId) const = 0; |
Eino-Ville Talvala | 7fa43f3 | 2013-02-06 17:20:07 -0800 | [diff] [blame] | 107 | |
Emilian Peev | 1523014 | 2023-04-27 20:22:54 +0000 | [diff] [blame] | 108 | virtual bool isCompositeJpegRDisabled() const { return false; }; |
Emilian Peev | e579d8b | 2023-02-28 14:16:08 -0800 | [diff] [blame] | 109 | |
Emilian Peev | aebbe41 | 2018-01-15 13:53:24 +0000 | [diff] [blame] | 110 | struct PhysicalCameraSettings { |
| 111 | std::string cameraId; |
| 112 | CameraMetadata metadata; |
Shuzhen Wang | 911c6a3 | 2021-10-27 13:36:03 -0700 | [diff] [blame] | 113 | |
| 114 | // Whether the physical camera supports testPatternMode/testPatternData |
| 115 | bool mHasTestPatternModeTag = true; |
| 116 | bool mHasTestPatternDataTag = true; |
| 117 | |
| 118 | // Original value of TEST_PATTERN_MODE and DATA so that they can be |
| 119 | // restored when sensor muting is turned off |
| 120 | int32_t mOriginalTestPatternMode = 0; |
| 121 | int32_t mOriginalTestPatternData[4] = {}; |
| 122 | |
Shuzhen Wang | af22e91 | 2023-04-11 16:03:17 -0700 | [diff] [blame] | 123 | // Original value of SETTINGS_OVERRIDE so that they can be restored if |
| 124 | // camera service isn't overwriting the app value. |
| 125 | int32_t mOriginalSettingsOverride = ANDROID_CONTROL_SETTINGS_OVERRIDE_OFF; |
Emilian Peev | aebbe41 | 2018-01-15 13:53:24 +0000 | [diff] [blame] | 126 | }; |
| 127 | typedef List<PhysicalCameraSettings> PhysicalCameraSettingsList; |
| 128 | |
Eino-Ville Talvala | 7fa43f3 | 2013-02-06 17:20:07 -0800 | [diff] [blame] | 129 | /** |
| 130 | * Submit request for capture. The CameraDevice takes ownership of the |
| 131 | * passed-in buffer. |
Jianing Wei | cb0652e | 2014-03-12 18:29:36 -0700 | [diff] [blame] | 132 | * Output lastFrameNumber is the expected frame number of this request. |
Eino-Ville Talvala | 7fa43f3 | 2013-02-06 17:20:07 -0800 | [diff] [blame] | 133 | */ |
Jianing Wei | cb0652e | 2014-03-12 18:29:36 -0700 | [diff] [blame] | 134 | virtual status_t capture(CameraMetadata &request, int64_t *lastFrameNumber = NULL) = 0; |
Eino-Ville Talvala | 7fa43f3 | 2013-02-06 17:20:07 -0800 | [diff] [blame] | 135 | |
| 136 | /** |
Jianing Wei | 90e59c9 | 2014-03-12 18:29:36 -0700 | [diff] [blame] | 137 | * Submit a list of requests. |
Jianing Wei | cb0652e | 2014-03-12 18:29:36 -0700 | [diff] [blame] | 138 | * Output lastFrameNumber is the expected last frame number of the list of requests. |
Jianing Wei | 90e59c9 | 2014-03-12 18:29:36 -0700 | [diff] [blame] | 139 | */ |
Emilian Peev | aebbe41 | 2018-01-15 13:53:24 +0000 | [diff] [blame] | 140 | virtual status_t captureList(const List<const PhysicalCameraSettingsList> &requests, |
Ryan Prichard | 09a5c6e | 2024-06-27 23:42:58 -0700 | [diff] [blame] | 141 | const std::list<SurfaceMap> &surfaceMaps, |
Jianing Wei | cb0652e | 2014-03-12 18:29:36 -0700 | [diff] [blame] | 142 | int64_t *lastFrameNumber = NULL) = 0; |
Jianing Wei | 90e59c9 | 2014-03-12 18:29:36 -0700 | [diff] [blame] | 143 | |
| 144 | /** |
Eino-Ville Talvala | 7fa43f3 | 2013-02-06 17:20:07 -0800 | [diff] [blame] | 145 | * Submit request for streaming. The CameraDevice makes a copy of the |
| 146 | * passed-in buffer and the caller retains ownership. |
Jianing Wei | cb0652e | 2014-03-12 18:29:36 -0700 | [diff] [blame] | 147 | * Output lastFrameNumber is the last frame number of the previous streaming request. |
Eino-Ville Talvala | 7fa43f3 | 2013-02-06 17:20:07 -0800 | [diff] [blame] | 148 | */ |
Jianing Wei | cb0652e | 2014-03-12 18:29:36 -0700 | [diff] [blame] | 149 | virtual status_t setStreamingRequest(const CameraMetadata &request, |
| 150 | int64_t *lastFrameNumber = NULL) = 0; |
Eino-Ville Talvala | 7fa43f3 | 2013-02-06 17:20:07 -0800 | [diff] [blame] | 151 | |
| 152 | /** |
Jianing Wei | 90e59c9 | 2014-03-12 18:29:36 -0700 | [diff] [blame] | 153 | * Submit a list of requests for streaming. |
Jianing Wei | cb0652e | 2014-03-12 18:29:36 -0700 | [diff] [blame] | 154 | * Output lastFrameNumber is the last frame number of the previous streaming request. |
Jianing Wei | 90e59c9 | 2014-03-12 18:29:36 -0700 | [diff] [blame] | 155 | */ |
Emilian Peev | aebbe41 | 2018-01-15 13:53:24 +0000 | [diff] [blame] | 156 | virtual status_t setStreamingRequestList(const List<const PhysicalCameraSettingsList> &requests, |
Ryan Prichard | 09a5c6e | 2024-06-27 23:42:58 -0700 | [diff] [blame] | 157 | const std::list<SurfaceMap> &surfaceMaps, |
Jianing Wei | cb0652e | 2014-03-12 18:29:36 -0700 | [diff] [blame] | 158 | int64_t *lastFrameNumber = NULL) = 0; |
Jianing Wei | 90e59c9 | 2014-03-12 18:29:36 -0700 | [diff] [blame] | 159 | |
| 160 | /** |
Eino-Ville Talvala | 7fa43f3 | 2013-02-06 17:20:07 -0800 | [diff] [blame] | 161 | * Clear the streaming request slot. |
Jianing Wei | cb0652e | 2014-03-12 18:29:36 -0700 | [diff] [blame] | 162 | * Output lastFrameNumber is the last frame number of the previous streaming request. |
Eino-Ville Talvala | 7fa43f3 | 2013-02-06 17:20:07 -0800 | [diff] [blame] | 163 | */ |
Jianing Wei | cb0652e | 2014-03-12 18:29:36 -0700 | [diff] [blame] | 164 | virtual status_t clearStreamingRequest(int64_t *lastFrameNumber = NULL) = 0; |
Eino-Ville Talvala | 7fa43f3 | 2013-02-06 17:20:07 -0800 | [diff] [blame] | 165 | |
| 166 | /** |
| 167 | * Wait until a request with the given ID has been dequeued by the |
| 168 | * HAL. Returns TIMED_OUT if the timeout duration is reached. Returns |
| 169 | * immediately if the latest request received by the HAL has this id. |
| 170 | */ |
| 171 | virtual status_t waitUntilRequestReceived(int32_t requestId, |
| 172 | nsecs_t timeout) = 0; |
| 173 | |
| 174 | /** |
Yin-Chia Yeh | b97babb | 2015-03-12 13:42:44 -0700 | [diff] [blame] | 175 | * Create an output stream of the requested size, format, rotation and dataspace |
Eino-Ville Talvala | 7fa43f3 | 2013-02-06 17:20:07 -0800 | [diff] [blame] | 176 | * |
Eino-Ville Talvala | 3d82c0d | 2015-02-23 15:19:19 -0800 | [diff] [blame] | 177 | * For HAL_PIXEL_FORMAT_BLOB formats, the width and height should be the |
| 178 | * logical dimensions of the buffer, not the number of bytes. |
Eino-Ville Talvala | 7fa43f3 | 2013-02-06 17:20:07 -0800 | [diff] [blame] | 179 | */ |
Eino-Ville Talvala | 727d172 | 2015-06-09 13:44:19 -0700 | [diff] [blame] | 180 | virtual status_t createStream(sp<Surface> consumer, |
Eino-Ville Talvala | 3d82c0d | 2015-02-23 15:19:19 -0800 | [diff] [blame] | 181 | uint32_t width, uint32_t height, int format, |
Emilian Peev | f481670 | 2020-04-03 15:44:51 -0700 | [diff] [blame] | 182 | android_dataspace dataSpace, camera_stream_rotation_t rotation, int *id, |
Austin Borger | ed99f64 | 2023-06-01 16:51:35 -0700 | [diff] [blame] | 183 | const std::string& physicalCameraId, |
Jayant Chowdhary | 13f9b2f | 2020-12-02 22:46:15 -0800 | [diff] [blame] | 184 | const std::unordered_set<int32_t> &sensorPixelModesUsed, |
Emilian Peev | 40ead60 | 2017-09-26 15:46:36 +0100 | [diff] [blame] | 185 | std::vector<int> *surfaceIds = nullptr, |
Zhijun He | 5d677d1 | 2016-05-29 16:52:39 -0700 | [diff] [blame] | 186 | int streamSetId = camera3::CAMERA3_STREAM_SET_ID_INVALID, |
Shuzhen Wang | 83bff12 | 2020-11-20 15:51:39 -0800 | [diff] [blame] | 187 | bool isShared = false, bool isMultiResolution = false, |
Emilian Peev | 2295df7 | 2021-11-12 18:14:10 -0800 | [diff] [blame] | 188 | uint64_t consumerUsage = 0, |
Emilian Peev | c81a759 | 2022-02-14 17:38:18 -0800 | [diff] [blame] | 189 | int64_t dynamicProfile = ANDROID_REQUEST_AVAILABLE_DYNAMIC_RANGE_PROFILES_MAP_STANDARD, |
Shuzhen Wang | 8ed1e87 | 2022-03-08 16:34:33 -0800 | [diff] [blame] | 190 | int64_t streamUseCase = ANDROID_SCALER_AVAILABLE_STREAM_USE_CASES_DEFAULT, |
Shuzhen Wang | 610d7b8 | 2022-02-08 14:37:22 -0800 | [diff] [blame] | 191 | int timestampBase = OutputConfiguration::TIMESTAMP_BASE_DEFAULT, |
Austin Borger | 9e2b27c | 2022-07-15 11:27:24 -0700 | [diff] [blame] | 192 | int mirrorMode = OutputConfiguration::MIRROR_MODE_AUTO, |
Shuzhen Wang | bce53db | 2022-12-03 00:38:20 +0000 | [diff] [blame] | 193 | int32_t colorSpace = ANDROID_REQUEST_AVAILABLE_COLOR_SPACE_PROFILES_MAP_UNSPECIFIED, |
| 194 | bool useReadoutTimestamp = false) |
Austin Borger | 9e2b27c | 2022-07-15 11:27:24 -0700 | [diff] [blame] | 195 | = 0; |
Eino-Ville Talvala | 7fa43f3 | 2013-02-06 17:20:07 -0800 | [diff] [blame] | 196 | |
| 197 | /** |
Shuzhen Wang | 0129d52 | 2016-10-30 22:43:41 -0700 | [diff] [blame] | 198 | * Create an output stream of the requested size, format, rotation and |
| 199 | * dataspace with a number of consumers. |
| 200 | * |
| 201 | * For HAL_PIXEL_FORMAT_BLOB formats, the width and height should be the |
| 202 | * logical dimensions of the buffer, not the number of bytes. |
| 203 | */ |
Shuzhen Wang | 38df0ca | 2024-10-09 11:33:44 -0700 | [diff] [blame^] | 204 | virtual status_t createStream(const std::vector<SurfaceHolder>& consumers, |
Shuzhen Wang | 0129d52 | 2016-10-30 22:43:41 -0700 | [diff] [blame] | 205 | bool hasDeferredConsumer, uint32_t width, uint32_t height, int format, |
Emilian Peev | f481670 | 2020-04-03 15:44:51 -0700 | [diff] [blame] | 206 | android_dataspace dataSpace, camera_stream_rotation_t rotation, int *id, |
Austin Borger | ed99f64 | 2023-06-01 16:51:35 -0700 | [diff] [blame] | 207 | const std::string& physicalCameraId, |
Jayant Chowdhary | 13f9b2f | 2020-12-02 22:46:15 -0800 | [diff] [blame] | 208 | const std::unordered_set<int32_t> &sensorPixelModesUsed, |
Emilian Peev | 40ead60 | 2017-09-26 15:46:36 +0100 | [diff] [blame] | 209 | std::vector<int> *surfaceIds = nullptr, |
Shuzhen Wang | 0129d52 | 2016-10-30 22:43:41 -0700 | [diff] [blame] | 210 | int streamSetId = camera3::CAMERA3_STREAM_SET_ID_INVALID, |
Shuzhen Wang | 83bff12 | 2020-11-20 15:51:39 -0800 | [diff] [blame] | 211 | bool isShared = false, bool isMultiResolution = false, |
Emilian Peev | 2295df7 | 2021-11-12 18:14:10 -0800 | [diff] [blame] | 212 | uint64_t consumerUsage = 0, |
Emilian Peev | c81a759 | 2022-02-14 17:38:18 -0800 | [diff] [blame] | 213 | int64_t dynamicProfile = ANDROID_REQUEST_AVAILABLE_DYNAMIC_RANGE_PROFILES_MAP_STANDARD, |
Shuzhen Wang | 8ed1e87 | 2022-03-08 16:34:33 -0800 | [diff] [blame] | 214 | int64_t streamUseCase = ANDROID_SCALER_AVAILABLE_STREAM_USE_CASES_DEFAULT, |
Shuzhen Wang | 610d7b8 | 2022-02-08 14:37:22 -0800 | [diff] [blame] | 215 | int timestampBase = OutputConfiguration::TIMESTAMP_BASE_DEFAULT, |
Shuzhen Wang | bce53db | 2022-12-03 00:38:20 +0000 | [diff] [blame] | 216 | int32_t colorSpace = ANDROID_REQUEST_AVAILABLE_COLOR_SPACE_PROFILES_MAP_UNSPECIFIED, |
| 217 | bool useReadoutTimestamp = false) |
Austin Borger | 9e2b27c | 2022-07-15 11:27:24 -0700 | [diff] [blame] | 218 | = 0; |
Shuzhen Wang | 0129d52 | 2016-10-30 22:43:41 -0700 | [diff] [blame] | 219 | |
| 220 | /** |
Chien-Yu Chen | 618ff8a | 2015-03-13 11:27:17 -0700 | [diff] [blame] | 221 | * Create an input stream of width, height, and format. |
| 222 | * |
| 223 | * Return value is the stream ID if non-negative and an error if negative. |
| 224 | */ |
| 225 | virtual status_t createInputStream(uint32_t width, uint32_t height, |
Shuzhen Wang | 83bff12 | 2020-11-20 15:51:39 -0800 | [diff] [blame] | 226 | int32_t format, bool multiResolution, /*out*/ int32_t *id) = 0; |
Chien-Yu Chen | 618ff8a | 2015-03-13 11:27:17 -0700 | [diff] [blame] | 227 | |
Emilian Peev | 710c142 | 2017-08-30 11:19:38 +0100 | [diff] [blame] | 228 | struct StreamInfo { |
| 229 | uint32_t width; |
| 230 | uint32_t height; |
Eino-Ville Talvala | 91cd3f8 | 2017-08-21 16:12:50 -0700 | [diff] [blame] | 231 | |
Emilian Peev | 710c142 | 2017-08-30 11:19:38 +0100 | [diff] [blame] | 232 | uint32_t format; |
| 233 | bool formatOverridden; |
| 234 | uint32_t originalFormat; |
Eino-Ville Talvala | 91cd3f8 | 2017-08-21 16:12:50 -0700 | [diff] [blame] | 235 | |
Emilian Peev | 710c142 | 2017-08-30 11:19:38 +0100 | [diff] [blame] | 236 | android_dataspace dataSpace; |
Eino-Ville Talvala | 91cd3f8 | 2017-08-21 16:12:50 -0700 | [diff] [blame] | 237 | bool dataSpaceOverridden; |
| 238 | android_dataspace originalDataSpace; |
Emilian Peev | c81a759 | 2022-02-14 17:38:18 -0800 | [diff] [blame] | 239 | int64_t dynamicRangeProfile; |
Austin Borger | 9e2b27c | 2022-07-15 11:27:24 -0700 | [diff] [blame] | 240 | int32_t colorSpace; |
Eino-Ville Talvala | 91cd3f8 | 2017-08-21 16:12:50 -0700 | [diff] [blame] | 241 | |
Emilian Peev | 710c142 | 2017-08-30 11:19:38 +0100 | [diff] [blame] | 242 | StreamInfo() : width(0), height(0), format(0), formatOverridden(false), originalFormat(0), |
Eino-Ville Talvala | 91cd3f8 | 2017-08-21 16:12:50 -0700 | [diff] [blame] | 243 | dataSpace(HAL_DATASPACE_UNKNOWN), dataSpaceOverridden(false), |
Emilian Peev | 2295df7 | 2021-11-12 18:14:10 -0800 | [diff] [blame] | 244 | originalDataSpace(HAL_DATASPACE_UNKNOWN), |
Austin Borger | 9e2b27c | 2022-07-15 11:27:24 -0700 | [diff] [blame] | 245 | dynamicRangeProfile(ANDROID_REQUEST_AVAILABLE_DYNAMIC_RANGE_PROFILES_MAP_STANDARD), |
| 246 | colorSpace(ANDROID_REQUEST_AVAILABLE_COLOR_SPACE_PROFILES_MAP_UNSPECIFIED) {} |
Emilian Peev | 710c142 | 2017-08-30 11:19:38 +0100 | [diff] [blame] | 247 | /** |
| 248 | * Check whether the format matches the current or the original one in case |
| 249 | * it got overridden. |
| 250 | */ |
Eino-Ville Talvala | 91cd3f8 | 2017-08-21 16:12:50 -0700 | [diff] [blame] | 251 | bool matchFormat(uint32_t clientFormat) const { |
Emilian Peev | 710c142 | 2017-08-30 11:19:38 +0100 | [diff] [blame] | 252 | if ((formatOverridden && (originalFormat == clientFormat)) || |
| 253 | (format == clientFormat)) { |
| 254 | return true; |
| 255 | } |
| 256 | return false; |
| 257 | } |
Eino-Ville Talvala | 91cd3f8 | 2017-08-21 16:12:50 -0700 | [diff] [blame] | 258 | |
| 259 | /** |
| 260 | * Check whether the dataspace matches the current or the original one in case |
| 261 | * it got overridden. |
| 262 | */ |
| 263 | bool matchDataSpace(android_dataspace clientDataSpace) const { |
| 264 | if ((dataSpaceOverridden && (originalDataSpace == clientDataSpace)) || |
| 265 | (dataSpace == clientDataSpace)) { |
| 266 | return true; |
| 267 | } |
| 268 | return false; |
| 269 | } |
| 270 | |
Emilian Peev | 710c142 | 2017-08-30 11:19:38 +0100 | [diff] [blame] | 271 | }; |
| 272 | |
Chien-Yu Chen | 618ff8a | 2015-03-13 11:27:17 -0700 | [diff] [blame] | 273 | /** |
Eino-Ville Talvala | 7fa43f3 | 2013-02-06 17:20:07 -0800 | [diff] [blame] | 274 | * Get information about a given stream. |
| 275 | */ |
Emilian Peev | 710c142 | 2017-08-30 11:19:38 +0100 | [diff] [blame] | 276 | virtual status_t getStreamInfo(int id, StreamInfo *streamInfo) = 0; |
Eino-Ville Talvala | 7fa43f3 | 2013-02-06 17:20:07 -0800 | [diff] [blame] | 277 | |
| 278 | /** |
| 279 | * Set stream gralloc buffer transform |
| 280 | */ |
| 281 | virtual status_t setStreamTransform(int id, int transform) = 0; |
| 282 | |
| 283 | /** |
| 284 | * Delete stream. Must not be called if there are requests in flight which |
| 285 | * reference that stream. |
| 286 | */ |
| 287 | virtual status_t deleteStream(int id) = 0; |
| 288 | |
| 289 | /** |
Igor Murashkin | e2d167e | 2014-08-19 16:19:59 -0700 | [diff] [blame] | 290 | * Take the currently-defined set of streams and configure the HAL to use |
| 291 | * them. This is a long-running operation (may be several hundered ms). |
| 292 | * |
| 293 | * The device must be idle (see waitUntilDrained) before calling this. |
| 294 | * |
| 295 | * Returns OK on success; otherwise on error: |
| 296 | * - BAD_VALUE if the set of streams was invalid (e.g. fmts or sizes) |
| 297 | * - INVALID_OPERATION if the device was in the wrong state |
| 298 | */ |
Emilian Peev | 5fbe0ba | 2017-10-20 15:45:45 +0100 | [diff] [blame] | 299 | virtual status_t configureStreams(const CameraMetadata& sessionParams, |
Emilian Peev | f481670 | 2020-04-03 15:44:51 -0700 | [diff] [blame] | 300 | int operatingMode = |
| 301 | camera_stream_configuration_mode_t::CAMERA_STREAM_CONFIGURATION_NORMAL_MODE) = 0; |
Igor Murashkin | e2d167e | 2014-08-19 16:19:59 -0700 | [diff] [blame] | 302 | |
Emilian Peev | cc0b795 | 2020-01-07 13:54:47 -0800 | [diff] [blame] | 303 | /** |
| 304 | * Retrieve a list of all stream ids that were advertised as capable of |
| 305 | * supporting offline processing mode by Hal after the last stream configuration. |
| 306 | */ |
| 307 | virtual void getOfflineStreamIds(std::vector<int> *offlineStreamIds) = 0; |
| 308 | |
Carlos Martinez Romero | 8e77610 | 2024-08-21 12:49:10 -0700 | [diff] [blame] | 309 | #if WB_CAMERA3_AND_PROCESSORS_WITH_DEPENDENCIES |
| 310 | // get the surface of the input stream |
| 311 | virtual status_t getInputSurface(sp<Surface> *surface) = 0; |
| 312 | #else |
Chien-Yu Chen | 618ff8a | 2015-03-13 11:27:17 -0700 | [diff] [blame] | 313 | // get the buffer producer of the input stream |
| 314 | virtual status_t getInputBufferProducer( |
| 315 | sp<IGraphicBufferProducer> *producer) = 0; |
Carlos Martinez Romero | 8e77610 | 2024-08-21 12:49:10 -0700 | [diff] [blame] | 316 | #endif |
Chien-Yu Chen | 618ff8a | 2015-03-13 11:27:17 -0700 | [diff] [blame] | 317 | |
Igor Murashkin | e2d167e | 2014-08-19 16:19:59 -0700 | [diff] [blame] | 318 | /** |
Eino-Ville Talvala | 7fa43f3 | 2013-02-06 17:20:07 -0800 | [diff] [blame] | 319 | * Create a metadata buffer with fields that the HAL device believes are |
| 320 | * best for the given use case |
| 321 | */ |
Emilian Peev | f481670 | 2020-04-03 15:44:51 -0700 | [diff] [blame] | 322 | virtual status_t createDefaultRequest(camera_request_template_t templateId, |
Eino-Ville Talvala | 7fa43f3 | 2013-02-06 17:20:07 -0800 | [diff] [blame] | 323 | CameraMetadata *request) = 0; |
| 324 | |
| 325 | /** |
| 326 | * Wait until all requests have been processed. Returns INVALID_OPERATION if |
| 327 | * the streaming slot is not empty, or TIMED_OUT if the requests haven't |
| 328 | * finished processing in 10 seconds. |
| 329 | */ |
| 330 | virtual status_t waitUntilDrained() = 0; |
| 331 | |
| 332 | /** |
Zhijun He | 28c9b6f | 2014-08-08 12:00:47 -0700 | [diff] [blame] | 333 | * Get Jpeg buffer size for a given jpeg resolution. |
| 334 | * Negative values are error codes. |
| 335 | */ |
Jayant Chowdhary | 6a6d3a8 | 2021-11-17 16:54:34 -0800 | [diff] [blame] | 336 | virtual ssize_t getJpegBufferSize(const CameraMetadata &info, uint32_t width, |
| 337 | uint32_t height) const = 0; |
Zhijun He | 28c9b6f | 2014-08-08 12:00:47 -0700 | [diff] [blame] | 338 | |
| 339 | /** |
Eino-Ville Talvala | 7fa43f3 | 2013-02-06 17:20:07 -0800 | [diff] [blame] | 340 | * Connect HAL notifications to a listener. Overwrites previous |
| 341 | * listener. Set to NULL to stop receiving notifications. |
| 342 | */ |
Yin-Chia Yeh | e1c8063 | 2016-08-08 14:48:05 -0700 | [diff] [blame] | 343 | virtual status_t setNotifyCallback(wp<NotificationListener> listener) = 0; |
Eino-Ville Talvala | 7fa43f3 | 2013-02-06 17:20:07 -0800 | [diff] [blame] | 344 | |
| 345 | /** |
Eino-Ville Talvala | 46910bd | 2013-07-18 19:15:17 -0700 | [diff] [blame] | 346 | * Whether the device supports calling notifyAutofocus, notifyAutoExposure, |
| 347 | * and notifyAutoWhitebalance; if this returns false, the client must |
| 348 | * synthesize these notifications from received frame metadata. |
| 349 | */ |
| 350 | virtual bool willNotify3A() = 0; |
| 351 | |
| 352 | /** |
Eino-Ville Talvala | 7fa43f3 | 2013-02-06 17:20:07 -0800 | [diff] [blame] | 353 | * Trigger auto-focus. The latest ID used in a trigger autofocus or cancel |
| 354 | * autofocus call will be returned by the HAL in all subsequent AF |
| 355 | * notifications. |
| 356 | */ |
| 357 | virtual status_t triggerAutofocus(uint32_t id) = 0; |
| 358 | |
| 359 | /** |
| 360 | * Cancel auto-focus. The latest ID used in a trigger autofocus/cancel |
| 361 | * autofocus call will be returned by the HAL in all subsequent AF |
| 362 | * notifications. |
| 363 | */ |
| 364 | virtual status_t triggerCancelAutofocus(uint32_t id) = 0; |
| 365 | |
| 366 | /** |
| 367 | * Trigger pre-capture metering. The latest ID used in a trigger pre-capture |
| 368 | * call will be returned by the HAL in all subsequent AE and AWB |
| 369 | * notifications. |
| 370 | */ |
| 371 | virtual status_t triggerPrecaptureMetering(uint32_t id) = 0; |
| 372 | |
| 373 | /** |
Eino-Ville Talvala | abaa51d | 2013-08-14 11:37:00 -0700 | [diff] [blame] | 374 | * Flush all pending and in-flight requests. Blocks until flush is |
| 375 | * complete. |
Jianing Wei | cb0652e | 2014-03-12 18:29:36 -0700 | [diff] [blame] | 376 | * Output lastFrameNumber is the last frame number of the previous streaming request. |
Eino-Ville Talvala | abaa51d | 2013-08-14 11:37:00 -0700 | [diff] [blame] | 377 | */ |
Jianing Wei | cb0652e | 2014-03-12 18:29:36 -0700 | [diff] [blame] | 378 | virtual status_t flush(int64_t *lastFrameNumber = NULL) = 0; |
Eino-Ville Talvala | abaa51d | 2013-08-14 11:37:00 -0700 | [diff] [blame] | 379 | |
Zhijun He | 204e329 | 2014-07-14 17:09:23 -0700 | [diff] [blame] | 380 | /** |
Eino-Ville Talvala | 4d44cad | 2015-04-11 13:15:45 -0700 | [diff] [blame] | 381 | * Prepare stream by preallocating buffers for it asynchronously. |
| 382 | * Calls notifyPrepared() once allocation is complete. |
| 383 | */ |
| 384 | virtual status_t prepare(int streamId) = 0; |
| 385 | |
| 386 | /** |
Eino-Ville Talvala | b25e3c8 | 2015-07-15 16:04:27 -0700 | [diff] [blame] | 387 | * Free stream resources by dumping its unused gralloc buffers. |
| 388 | */ |
| 389 | virtual status_t tearDown(int streamId) = 0; |
| 390 | |
| 391 | /** |
Shuzhen Wang | b0fdc1e | 2016-03-20 23:21:39 -0700 | [diff] [blame] | 392 | * Add buffer listener for a particular stream in the device. |
| 393 | */ |
| 394 | virtual status_t addBufferListenerForStream(int streamId, |
| 395 | wp<camera3::Camera3StreamBufferListener> listener) = 0; |
| 396 | |
| 397 | /** |
Ruben Brunk | c78ac26 | 2015-08-13 17:58:46 -0700 | [diff] [blame] | 398 | * Prepare stream by preallocating up to maxCount buffers for it asynchronously. |
| 399 | * Calls notifyPrepared() once allocation is complete. |
| 400 | */ |
| 401 | virtual status_t prepare(int maxCount, int streamId) = 0; |
| 402 | |
| 403 | /** |
Zhijun He | 5d677d1 | 2016-05-29 16:52:39 -0700 | [diff] [blame] | 404 | * Set the deferred consumer surface and finish the rest of the stream configuration. |
| 405 | */ |
Shuzhen Wang | 758c215 | 2017-01-10 18:26:18 -0800 | [diff] [blame] | 406 | virtual status_t setConsumerSurfaces(int streamId, |
Shuzhen Wang | 38df0ca | 2024-10-09 11:33:44 -0700 | [diff] [blame^] | 407 | const std::vector<SurfaceHolder>& consumers, std::vector<int> *surfaceIds /*out*/) = 0; |
Zhijun He | 5d677d1 | 2016-05-29 16:52:39 -0700 | [diff] [blame] | 408 | |
Emilian Peev | 40ead60 | 2017-09-26 15:46:36 +0100 | [diff] [blame] | 409 | /** |
| 410 | * Update a given stream. |
| 411 | */ |
Shuzhen Wang | 38df0ca | 2024-10-09 11:33:44 -0700 | [diff] [blame^] | 412 | virtual status_t updateStream(int streamId, const std::vector<SurfaceHolder> &newSurfaces, |
Emilian Peev | 40ead60 | 2017-09-26 15:46:36 +0100 | [diff] [blame] | 413 | const std::vector<android::camera3::OutputStreamInfo> &outputInfo, |
| 414 | const std::vector<size_t> &removedSurfaceIds, |
| 415 | KeyedVector<sp<Surface>, size_t> *outputMap/*out*/) = 0; |
Chien-Yu Chen | a936ac2 | 2017-10-23 15:59:49 -0700 | [diff] [blame] | 416 | |
| 417 | /** |
| 418 | * Drop buffers for stream of streamId if dropping is true. If dropping is false, do not |
| 419 | * drop buffers for stream of streamId. |
| 420 | */ |
| 421 | virtual status_t dropStreamBuffers(bool /*dropping*/, int /*streamId*/) = 0; |
Emilian Peev | 2a8e283 | 2019-08-23 13:00:31 -0700 | [diff] [blame] | 422 | |
| 423 | /** |
| 424 | * Returns the maximum expected time it'll take for all currently in-flight |
| 425 | * requests to complete, based on their settings |
| 426 | */ |
| 427 | virtual nsecs_t getExpectedInFlightDuration() = 0; |
Yin-Chia Yeh | b978c38 | 2019-10-30 00:22:37 -0700 | [diff] [blame] | 428 | |
| 429 | /** |
| 430 | * switch to offline session |
| 431 | */ |
| 432 | virtual status_t switchToOffline( |
| 433 | const std::vector<int32_t>& streamsToKeep, |
| 434 | /*out*/ sp<CameraOfflineSessionBase>* session) = 0; |
Eino-Ville Talvala | f2e3709 | 2020-01-07 15:32:32 -0800 | [diff] [blame] | 435 | |
| 436 | /** |
| 437 | * Set the current behavior for the ROTATE_AND_CROP control when in AUTO. |
| 438 | * |
| 439 | * The value must be one of the ROTATE_AND_CROP_* values besides AUTO, |
| 440 | * and defaults to NONE. |
| 441 | */ |
| 442 | virtual status_t setRotateAndCropAutoBehavior( |
Jayant Chowdhary | 44d5f62 | 2023-09-20 03:11:41 +0000 | [diff] [blame] | 443 | camera_metadata_enum_android_scaler_rotate_and_crop_t rotateAndCropValue, |
| 444 | bool fromHal = false) = 0; |
Eino-Ville Talvala | f2e3709 | 2020-01-07 15:32:32 -0800 | [diff] [blame] | 445 | |
Shuzhen Wang | e867578 | 2019-12-05 09:12:14 -0800 | [diff] [blame] | 446 | /** |
Bharatt Kukreja | 7146ced | 2022-10-25 15:45:29 +0000 | [diff] [blame] | 447 | * Set the current behavior for the AUTOFRAMING control when in AUTO. |
| 448 | * |
| 449 | * The value must be one of the AUTOFRAMING_* values besides AUTO. |
| 450 | */ |
| 451 | virtual status_t setAutoframingAutoBehavior( |
| 452 | camera_metadata_enum_android_control_autoframing_t autoframingValue) = 0; |
| 453 | |
| 454 | /** |
Eino-Ville Talvala | 305cec6 | 2020-11-12 14:18:17 -0800 | [diff] [blame] | 455 | * Whether camera muting (producing black-only output) is supported. |
| 456 | * |
| 457 | * Calling setCameraMute(true) when this returns false will return an |
| 458 | * INVALID_OPERATION error. |
| 459 | */ |
| 460 | virtual bool supportsCameraMute() = 0; |
| 461 | |
| 462 | /** |
| 463 | * Mute the camera. |
| 464 | * |
| 465 | * When muted, black image data is output on all output streams. |
| 466 | */ |
| 467 | virtual status_t setCameraMute(bool enabled) = 0; |
| 468 | |
| 469 | /** |
Shuzhen Wang | af22e91 | 2023-04-11 16:03:17 -0700 | [diff] [blame] | 470 | * Whether the camera device supports zoom override. |
| 471 | */ |
| 472 | virtual bool supportsZoomOverride() = 0; |
| 473 | |
| 474 | // Set/reset zoom override |
| 475 | virtual status_t setZoomOverride(int32_t zoomOverride) = 0; |
| 476 | |
| 477 | /** |
Ravneet | aeb20dc | 2022-03-30 05:33:03 +0000 | [diff] [blame] | 478 | * Enable/disable camera service watchdog |
| 479 | */ |
| 480 | virtual status_t setCameraServiceWatchdog(bool enabled) = 0; |
| 481 | |
| 482 | /** |
Shuzhen Wang | e867578 | 2019-12-05 09:12:14 -0800 | [diff] [blame] | 483 | * Get the status tracker of the camera device |
| 484 | */ |
| 485 | virtual wp<camera3::StatusTracker> getStatusTracker() = 0; |
Shuzhen Wang | abbcb6b | 2020-12-09 22:32:44 -0800 | [diff] [blame] | 486 | |
| 487 | /** |
Shuzhen Wang | 03fe623 | 2023-02-05 12:41:15 -0800 | [diff] [blame] | 488 | * If the device is in eror state |
| 489 | */ |
| 490 | virtual bool hasDeviceError() = 0; |
| 491 | |
| 492 | /** |
Shuzhen Wang | abbcb6b | 2020-12-09 22:32:44 -0800 | [diff] [blame] | 493 | * Set bitmask for image dump flag |
| 494 | */ |
| 495 | void setImageDumpMask(int mask) { mImageDumpMask = mask; } |
| 496 | |
Cliff Wu | d3a0531 | 2021-04-26 23:07:31 +0800 | [diff] [blame] | 497 | /** |
Shuzhen Wang | 16610a6 | 2022-12-15 22:38:07 -0800 | [diff] [blame] | 498 | * Set stream use case overrides |
| 499 | */ |
| 500 | void setStreamUseCaseOverrides(const std::vector<int64_t>& useCaseOverrides) { |
| 501 | mStreamUseCaseOverrides = useCaseOverrides; |
| 502 | } |
| 503 | |
| 504 | void clearStreamUseCaseOverrides() {} |
| 505 | |
| 506 | /** |
Cliff Wu | d3a0531 | 2021-04-26 23:07:31 +0800 | [diff] [blame] | 507 | * The injection camera session to replace the internal camera |
| 508 | * session. |
| 509 | */ |
Austin Borger | ed99f64 | 2023-06-01 16:51:35 -0700 | [diff] [blame] | 510 | virtual status_t injectCamera(const std::string& injectedCamId, |
Cliff Wu | d3a0531 | 2021-04-26 23:07:31 +0800 | [diff] [blame] | 511 | sp<CameraProviderManager> manager) = 0; |
| 512 | |
| 513 | /** |
| 514 | * Stop the injection camera and restore to internal camera session. |
| 515 | */ |
| 516 | virtual status_t stopInjection() = 0; |
| 517 | |
malikakash | 22af94c | 2023-12-04 18:13:14 +0000 | [diff] [blame] | 518 | // Inject session parameters into an existing client. |
| 519 | virtual status_t injectSessionParams( |
| 520 | const CameraMetadata& sessionParams) = 0; |
| 521 | |
Shuzhen Wang | abbcb6b | 2020-12-09 22:32:44 -0800 | [diff] [blame] | 522 | protected: |
| 523 | bool mImageDumpMask = 0; |
Shuzhen Wang | 16610a6 | 2022-12-15 22:38:07 -0800 | [diff] [blame] | 524 | std::vector<int64_t> mStreamUseCaseOverrides; |
Eino-Ville Talvala | 7fa43f3 | 2013-02-06 17:20:07 -0800 | [diff] [blame] | 525 | }; |
| 526 | |
| 527 | }; // namespace android |
| 528 | |
| 529 | #endif |