| 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> | 
|  | 23 | #include <utils/String8.h> | 
|  | 24 | #include <utils/String16.h> | 
|  | 25 | #include <utils/Vector.h> | 
| Emilian Peev | 40ead60 | 2017-09-26 15:46:36 +0100 | [diff] [blame] | 26 | #include <utils/KeyedVector.h> | 
| Eino-Ville Talvala | 7fa43f3 | 2013-02-06 17:20:07 -0800 | [diff] [blame] | 27 | #include <utils/Timers.h> | 
| Jianing Wei | 90e59c9 | 2014-03-12 18:29:36 -0700 | [diff] [blame] | 28 | #include <utils/List.h> | 
| Eino-Ville Talvala | 7fa43f3 | 2013-02-06 17:20:07 -0800 | [diff] [blame] | 29 |  | 
|  | 30 | #include "hardware/camera2.h" | 
| Zhijun He | 0ea8fa4 | 2014-07-07 17:05:38 -0700 | [diff] [blame] | 31 | #include "hardware/camera3.h" | 
| Eino-Ville Talvala | 7fa43f3 | 2013-02-06 17:20:07 -0800 | [diff] [blame] | 32 | #include "camera/CameraMetadata.h" | 
| Jianing Wei | cb0652e | 2014-03-12 18:29:36 -0700 | [diff] [blame] | 33 | #include "camera/CaptureResult.h" | 
| Chien-Yu Chen | 618ff8a | 2015-03-13 11:27:17 -0700 | [diff] [blame] | 34 | #include "gui/IGraphicBufferProducer.h" | 
| Zhijun He | 125684a | 2015-12-26 15:07:30 -0800 | [diff] [blame] | 35 | #include "device3/Camera3StreamInterface.h" | 
| Eino-Ville Talvala | d56db1d | 2015-12-17 16:50:35 -0800 | [diff] [blame] | 36 | #include "binder/Status.h" | 
| Eino-Ville Talvala | 7fa43f3 | 2013-02-06 17:20:07 -0800 | [diff] [blame] | 37 |  | 
| Yin-Chia Yeh | b978c38 | 2019-10-30 00:22:37 -0700 | [diff] [blame] | 38 | #include "CameraOfflineSessionBase.h" | 
|  | 39 |  | 
| Eino-Ville Talvala | 7fa43f3 | 2013-02-06 17:20:07 -0800 | [diff] [blame] | 40 | namespace android { | 
|  | 41 |  | 
| Eino-Ville Talvala | 2f09bac | 2016-12-13 11:29:54 -0800 | [diff] [blame] | 42 | class CameraProviderManager; | 
|  | 43 |  | 
| Shuzhen Wang | 0129d52 | 2016-10-30 22:43:41 -0700 | [diff] [blame] | 44 | // Mapping of output stream index to surface ids | 
|  | 45 | typedef std::unordered_map<int, std::vector<size_t> > SurfaceMap; | 
|  | 46 |  | 
| Eino-Ville Talvala | 7fa43f3 | 2013-02-06 17:20:07 -0800 | [diff] [blame] | 47 | /** | 
|  | 48 | * Base interface for version >= 2 camera device classes, which interface to | 
|  | 49 | * camera HAL device versions >= 2. | 
|  | 50 | */ | 
|  | 51 | class CameraDeviceBase : public virtual RefBase { | 
|  | 52 | public: | 
|  | 53 | virtual ~CameraDeviceBase(); | 
|  | 54 |  | 
| Igor Murashkin | 7138105 | 2013-03-04 14:53:08 -0800 | [diff] [blame] | 55 | /** | 
|  | 56 | * The device's camera ID | 
|  | 57 | */ | 
| Eino-Ville Talvala | 0b1cb14 | 2016-12-19 16:29:17 -0800 | [diff] [blame] | 58 | virtual const String8& getId() const = 0; | 
| Igor Murashkin | 7138105 | 2013-03-04 14:53:08 -0800 | [diff] [blame] | 59 |  | 
| Emilian Peev | 00420d2 | 2018-02-05 21:33:13 +0000 | [diff] [blame] | 60 | /** | 
|  | 61 | * The device vendor tag ID | 
|  | 62 | */ | 
|  | 63 | virtual metadata_vendor_id_t getVendorTagId() const = 0; | 
|  | 64 |  | 
| Emilian Peev | bd8c503 | 2018-02-14 23:05:40 +0000 | [diff] [blame] | 65 | virtual status_t initialize(sp<CameraProviderManager> manager, const String8& monitorTags) = 0; | 
| Eino-Ville Talvala | 7fa43f3 | 2013-02-06 17:20:07 -0800 | [diff] [blame] | 66 | virtual status_t disconnect() = 0; | 
|  | 67 |  | 
| Jianing Wei | cb0652e | 2014-03-12 18:29:36 -0700 | [diff] [blame] | 68 | virtual status_t dump(int fd, const Vector<String16> &args) = 0; | 
| Eino-Ville Talvala | 7fa43f3 | 2013-02-06 17:20:07 -0800 | [diff] [blame] | 69 |  | 
|  | 70 | /** | 
|  | 71 | * The device's static characteristics metadata buffer | 
|  | 72 | */ | 
|  | 73 | virtual const CameraMetadata& info() const = 0; | 
| Shuzhen Wang | 2e7f58f | 2018-07-11 14:00:29 -0700 | [diff] [blame] | 74 | /** | 
|  | 75 | * The physical camera device's static characteristics metadata buffer | 
|  | 76 | */ | 
|  | 77 | virtual const CameraMetadata& info(const String8& physicalId) const = 0; | 
| Eino-Ville Talvala | 7fa43f3 | 2013-02-06 17:20:07 -0800 | [diff] [blame] | 78 |  | 
| Emilian Peev | aebbe41 | 2018-01-15 13:53:24 +0000 | [diff] [blame] | 79 | struct PhysicalCameraSettings { | 
|  | 80 | std::string cameraId; | 
|  | 81 | CameraMetadata metadata; | 
|  | 82 | }; | 
|  | 83 | typedef List<PhysicalCameraSettings> PhysicalCameraSettingsList; | 
|  | 84 |  | 
| Eino-Ville Talvala | 7fa43f3 | 2013-02-06 17:20:07 -0800 | [diff] [blame] | 85 | /** | 
|  | 86 | * Submit request for capture. The CameraDevice takes ownership of the | 
|  | 87 | * passed-in buffer. | 
| Jianing Wei | cb0652e | 2014-03-12 18:29:36 -0700 | [diff] [blame] | 88 | * Output lastFrameNumber is the expected frame number of this request. | 
| Eino-Ville Talvala | 7fa43f3 | 2013-02-06 17:20:07 -0800 | [diff] [blame] | 89 | */ | 
| Jianing Wei | cb0652e | 2014-03-12 18:29:36 -0700 | [diff] [blame] | 90 | virtual status_t capture(CameraMetadata &request, int64_t *lastFrameNumber = NULL) = 0; | 
| Eino-Ville Talvala | 7fa43f3 | 2013-02-06 17:20:07 -0800 | [diff] [blame] | 91 |  | 
|  | 92 | /** | 
| Jianing Wei | 90e59c9 | 2014-03-12 18:29:36 -0700 | [diff] [blame] | 93 | * Submit a list of requests. | 
| Jianing Wei | cb0652e | 2014-03-12 18:29:36 -0700 | [diff] [blame] | 94 | * 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] | 95 | */ | 
| Emilian Peev | aebbe41 | 2018-01-15 13:53:24 +0000 | [diff] [blame] | 96 | virtual status_t captureList(const List<const PhysicalCameraSettingsList> &requests, | 
| Shuzhen Wang | 0129d52 | 2016-10-30 22:43:41 -0700 | [diff] [blame] | 97 | const std::list<const SurfaceMap> &surfaceMaps, | 
| Jianing Wei | cb0652e | 2014-03-12 18:29:36 -0700 | [diff] [blame] | 98 | int64_t *lastFrameNumber = NULL) = 0; | 
| Jianing Wei | 90e59c9 | 2014-03-12 18:29:36 -0700 | [diff] [blame] | 99 |  | 
|  | 100 | /** | 
| Eino-Ville Talvala | 7fa43f3 | 2013-02-06 17:20:07 -0800 | [diff] [blame] | 101 | * Submit request for streaming. The CameraDevice makes a copy of the | 
|  | 102 | * passed-in buffer and the caller retains ownership. | 
| Jianing Wei | cb0652e | 2014-03-12 18:29:36 -0700 | [diff] [blame] | 103 | * 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] | 104 | */ | 
| Jianing Wei | cb0652e | 2014-03-12 18:29:36 -0700 | [diff] [blame] | 105 | virtual status_t setStreamingRequest(const CameraMetadata &request, | 
|  | 106 | int64_t *lastFrameNumber = NULL) = 0; | 
| Eino-Ville Talvala | 7fa43f3 | 2013-02-06 17:20:07 -0800 | [diff] [blame] | 107 |  | 
|  | 108 | /** | 
| Jianing Wei | 90e59c9 | 2014-03-12 18:29:36 -0700 | [diff] [blame] | 109 | * Submit a list of requests for streaming. | 
| Jianing Wei | cb0652e | 2014-03-12 18:29:36 -0700 | [diff] [blame] | 110 | * Output lastFrameNumber is the last frame number of the previous streaming request. | 
| Jianing Wei | 90e59c9 | 2014-03-12 18:29:36 -0700 | [diff] [blame] | 111 | */ | 
| Emilian Peev | aebbe41 | 2018-01-15 13:53:24 +0000 | [diff] [blame] | 112 | virtual status_t setStreamingRequestList(const List<const PhysicalCameraSettingsList> &requests, | 
| Shuzhen Wang | 0129d52 | 2016-10-30 22:43:41 -0700 | [diff] [blame] | 113 | const std::list<const SurfaceMap> &surfaceMaps, | 
| Jianing Wei | cb0652e | 2014-03-12 18:29:36 -0700 | [diff] [blame] | 114 | int64_t *lastFrameNumber = NULL) = 0; | 
| Jianing Wei | 90e59c9 | 2014-03-12 18:29:36 -0700 | [diff] [blame] | 115 |  | 
|  | 116 | /** | 
| Eino-Ville Talvala | 7fa43f3 | 2013-02-06 17:20:07 -0800 | [diff] [blame] | 117 | * Clear the streaming request slot. | 
| Jianing Wei | cb0652e | 2014-03-12 18:29:36 -0700 | [diff] [blame] | 118 | * 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] | 119 | */ | 
| Jianing Wei | cb0652e | 2014-03-12 18:29:36 -0700 | [diff] [blame] | 120 | virtual status_t clearStreamingRequest(int64_t *lastFrameNumber = NULL) = 0; | 
| Eino-Ville Talvala | 7fa43f3 | 2013-02-06 17:20:07 -0800 | [diff] [blame] | 121 |  | 
|  | 122 | /** | 
|  | 123 | * Wait until a request with the given ID has been dequeued by the | 
|  | 124 | * HAL. Returns TIMED_OUT if the timeout duration is reached. Returns | 
|  | 125 | * immediately if the latest request received by the HAL has this id. | 
|  | 126 | */ | 
|  | 127 | virtual status_t waitUntilRequestReceived(int32_t requestId, | 
|  | 128 | nsecs_t timeout) = 0; | 
|  | 129 |  | 
|  | 130 | /** | 
| Yin-Chia Yeh | b97babb | 2015-03-12 13:42:44 -0700 | [diff] [blame] | 131 | * 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] | 132 | * | 
| Eino-Ville Talvala | 3d82c0d | 2015-02-23 15:19:19 -0800 | [diff] [blame] | 133 | * For HAL_PIXEL_FORMAT_BLOB formats, the width and height should be the | 
|  | 134 | * logical dimensions of the buffer, not the number of bytes. | 
| Eino-Ville Talvala | 7fa43f3 | 2013-02-06 17:20:07 -0800 | [diff] [blame] | 135 | */ | 
| Eino-Ville Talvala | 727d172 | 2015-06-09 13:44:19 -0700 | [diff] [blame] | 136 | virtual status_t createStream(sp<Surface> consumer, | 
| Eino-Ville Talvala | 3d82c0d | 2015-02-23 15:19:19 -0800 | [diff] [blame] | 137 | uint32_t width, uint32_t height, int format, | 
| Zhijun He | 125684a | 2015-12-26 15:07:30 -0800 | [diff] [blame] | 138 | android_dataspace dataSpace, camera3_stream_rotation_t rotation, int *id, | 
| Shuzhen Wang | c28189a | 2017-11-27 23:05:10 -0800 | [diff] [blame] | 139 | const String8& physicalCameraId, | 
| Emilian Peev | 40ead60 | 2017-09-26 15:46:36 +0100 | [diff] [blame] | 140 | std::vector<int> *surfaceIds = nullptr, | 
| Zhijun He | 5d677d1 | 2016-05-29 16:52:39 -0700 | [diff] [blame] | 141 | int streamSetId = camera3::CAMERA3_STREAM_SET_ID_INVALID, | 
| Emilian Peev | 050f5dc | 2017-05-18 14:43:56 +0100 | [diff] [blame] | 142 | bool isShared = false, uint64_t consumerUsage = 0) = 0; | 
| Eino-Ville Talvala | 7fa43f3 | 2013-02-06 17:20:07 -0800 | [diff] [blame] | 143 |  | 
|  | 144 | /** | 
| Shuzhen Wang | 0129d52 | 2016-10-30 22:43:41 -0700 | [diff] [blame] | 145 | * Create an output stream of the requested size, format, rotation and | 
|  | 146 | * dataspace with a number of consumers. | 
|  | 147 | * | 
|  | 148 | * For HAL_PIXEL_FORMAT_BLOB formats, the width and height should be the | 
|  | 149 | * logical dimensions of the buffer, not the number of bytes. | 
|  | 150 | */ | 
|  | 151 | virtual status_t createStream(const std::vector<sp<Surface>>& consumers, | 
|  | 152 | bool hasDeferredConsumer, uint32_t width, uint32_t height, int format, | 
|  | 153 | android_dataspace dataSpace, camera3_stream_rotation_t rotation, int *id, | 
| Shuzhen Wang | c28189a | 2017-11-27 23:05:10 -0800 | [diff] [blame] | 154 | const String8& physicalCameraId, | 
| Emilian Peev | 40ead60 | 2017-09-26 15:46:36 +0100 | [diff] [blame] | 155 | std::vector<int> *surfaceIds = nullptr, | 
| Shuzhen Wang | 0129d52 | 2016-10-30 22:43:41 -0700 | [diff] [blame] | 156 | int streamSetId = camera3::CAMERA3_STREAM_SET_ID_INVALID, | 
| Emilian Peev | 050f5dc | 2017-05-18 14:43:56 +0100 | [diff] [blame] | 157 | bool isShared = false, uint64_t consumerUsage = 0) = 0; | 
| Shuzhen Wang | 0129d52 | 2016-10-30 22:43:41 -0700 | [diff] [blame] | 158 |  | 
|  | 159 | /** | 
| Chien-Yu Chen | 618ff8a | 2015-03-13 11:27:17 -0700 | [diff] [blame] | 160 | * Create an input stream of width, height, and format. | 
|  | 161 | * | 
|  | 162 | * Return value is the stream ID if non-negative and an error if negative. | 
|  | 163 | */ | 
|  | 164 | virtual status_t createInputStream(uint32_t width, uint32_t height, | 
|  | 165 | int32_t format, /*out*/ int32_t *id) = 0; | 
|  | 166 |  | 
| Emilian Peev | 710c142 | 2017-08-30 11:19:38 +0100 | [diff] [blame] | 167 | struct StreamInfo { | 
|  | 168 | uint32_t width; | 
|  | 169 | uint32_t height; | 
| Eino-Ville Talvala | 91cd3f8 | 2017-08-21 16:12:50 -0700 | [diff] [blame] | 170 |  | 
| Emilian Peev | 710c142 | 2017-08-30 11:19:38 +0100 | [diff] [blame] | 171 | uint32_t format; | 
|  | 172 | bool formatOverridden; | 
|  | 173 | uint32_t originalFormat; | 
| Eino-Ville Talvala | 91cd3f8 | 2017-08-21 16:12:50 -0700 | [diff] [blame] | 174 |  | 
| Emilian Peev | 710c142 | 2017-08-30 11:19:38 +0100 | [diff] [blame] | 175 | android_dataspace dataSpace; | 
| Eino-Ville Talvala | 91cd3f8 | 2017-08-21 16:12:50 -0700 | [diff] [blame] | 176 | bool dataSpaceOverridden; | 
|  | 177 | android_dataspace originalDataSpace; | 
|  | 178 |  | 
| Emilian Peev | 710c142 | 2017-08-30 11:19:38 +0100 | [diff] [blame] | 179 | StreamInfo() : width(0), height(0), format(0), formatOverridden(false), originalFormat(0), | 
| Eino-Ville Talvala | 91cd3f8 | 2017-08-21 16:12:50 -0700 | [diff] [blame] | 180 | dataSpace(HAL_DATASPACE_UNKNOWN), dataSpaceOverridden(false), | 
|  | 181 | originalDataSpace(HAL_DATASPACE_UNKNOWN) {} | 
| Emilian Peev | 710c142 | 2017-08-30 11:19:38 +0100 | [diff] [blame] | 182 | /** | 
|  | 183 | * Check whether the format matches the current or the original one in case | 
|  | 184 | * it got overridden. | 
|  | 185 | */ | 
| Eino-Ville Talvala | 91cd3f8 | 2017-08-21 16:12:50 -0700 | [diff] [blame] | 186 | bool matchFormat(uint32_t clientFormat) const { | 
| Emilian Peev | 710c142 | 2017-08-30 11:19:38 +0100 | [diff] [blame] | 187 | if ((formatOverridden && (originalFormat == clientFormat)) || | 
|  | 188 | (format == clientFormat)) { | 
|  | 189 | return true; | 
|  | 190 | } | 
|  | 191 | return false; | 
|  | 192 | } | 
| Eino-Ville Talvala | 91cd3f8 | 2017-08-21 16:12:50 -0700 | [diff] [blame] | 193 |  | 
|  | 194 | /** | 
|  | 195 | * Check whether the dataspace matches the current or the original one in case | 
|  | 196 | * it got overridden. | 
|  | 197 | */ | 
|  | 198 | bool matchDataSpace(android_dataspace clientDataSpace) const { | 
|  | 199 | if ((dataSpaceOverridden && (originalDataSpace == clientDataSpace)) || | 
|  | 200 | (dataSpace == clientDataSpace)) { | 
|  | 201 | return true; | 
|  | 202 | } | 
|  | 203 | return false; | 
|  | 204 | } | 
|  | 205 |  | 
| Emilian Peev | 710c142 | 2017-08-30 11:19:38 +0100 | [diff] [blame] | 206 | }; | 
|  | 207 |  | 
| Chien-Yu Chen | 618ff8a | 2015-03-13 11:27:17 -0700 | [diff] [blame] | 208 | /** | 
| Eino-Ville Talvala | 7fa43f3 | 2013-02-06 17:20:07 -0800 | [diff] [blame] | 209 | * Get information about a given stream. | 
|  | 210 | */ | 
| Emilian Peev | 710c142 | 2017-08-30 11:19:38 +0100 | [diff] [blame] | 211 | virtual status_t getStreamInfo(int id, StreamInfo *streamInfo) = 0; | 
| Eino-Ville Talvala | 7fa43f3 | 2013-02-06 17:20:07 -0800 | [diff] [blame] | 212 |  | 
|  | 213 | /** | 
|  | 214 | * Set stream gralloc buffer transform | 
|  | 215 | */ | 
|  | 216 | virtual status_t setStreamTransform(int id, int transform) = 0; | 
|  | 217 |  | 
|  | 218 | /** | 
|  | 219 | * Delete stream. Must not be called if there are requests in flight which | 
|  | 220 | * reference that stream. | 
|  | 221 | */ | 
|  | 222 | virtual status_t deleteStream(int id) = 0; | 
|  | 223 |  | 
|  | 224 | /** | 
| Igor Murashkin | e2d167e | 2014-08-19 16:19:59 -0700 | [diff] [blame] | 225 | * Take the currently-defined set of streams and configure the HAL to use | 
|  | 226 | * them. This is a long-running operation (may be several hundered ms). | 
|  | 227 | * | 
|  | 228 | * The device must be idle (see waitUntilDrained) before calling this. | 
|  | 229 | * | 
|  | 230 | * Returns OK on success; otherwise on error: | 
|  | 231 | * - BAD_VALUE if the set of streams was invalid (e.g. fmts or sizes) | 
|  | 232 | * - INVALID_OPERATION if the device was in the wrong state | 
|  | 233 | */ | 
| Emilian Peev | 5fbe0ba | 2017-10-20 15:45:45 +0100 | [diff] [blame] | 234 | virtual status_t configureStreams(const CameraMetadata& sessionParams, | 
|  | 235 | int operatingMode = 0) = 0; | 
| Igor Murashkin | e2d167e | 2014-08-19 16:19:59 -0700 | [diff] [blame] | 236 |  | 
| Chien-Yu Chen | 618ff8a | 2015-03-13 11:27:17 -0700 | [diff] [blame] | 237 | // get the buffer producer of the input stream | 
|  | 238 | virtual status_t getInputBufferProducer( | 
|  | 239 | sp<IGraphicBufferProducer> *producer) = 0; | 
|  | 240 |  | 
| Igor Murashkin | e2d167e | 2014-08-19 16:19:59 -0700 | [diff] [blame] | 241 | /** | 
| Eino-Ville Talvala | 7fa43f3 | 2013-02-06 17:20:07 -0800 | [diff] [blame] | 242 | * Create a metadata buffer with fields that the HAL device believes are | 
|  | 243 | * best for the given use case | 
|  | 244 | */ | 
|  | 245 | virtual status_t createDefaultRequest(int templateId, | 
|  | 246 | CameraMetadata *request) = 0; | 
|  | 247 |  | 
|  | 248 | /** | 
|  | 249 | * Wait until all requests have been processed. Returns INVALID_OPERATION if | 
|  | 250 | * the streaming slot is not empty, or TIMED_OUT if the requests haven't | 
|  | 251 | * finished processing in 10 seconds. | 
|  | 252 | */ | 
|  | 253 | virtual status_t waitUntilDrained() = 0; | 
|  | 254 |  | 
|  | 255 | /** | 
| Zhijun He | 28c9b6f | 2014-08-08 12:00:47 -0700 | [diff] [blame] | 256 | * Get Jpeg buffer size for a given jpeg resolution. | 
|  | 257 | * Negative values are error codes. | 
|  | 258 | */ | 
|  | 259 | virtual ssize_t getJpegBufferSize(uint32_t width, uint32_t height) const = 0; | 
|  | 260 |  | 
|  | 261 | /** | 
| Eino-Ville Talvala | 7fa43f3 | 2013-02-06 17:20:07 -0800 | [diff] [blame] | 262 | * Abstract class for HAL notification listeners | 
|  | 263 | */ | 
| Yin-Chia Yeh | e1c8063 | 2016-08-08 14:48:05 -0700 | [diff] [blame] | 264 | class NotificationListener : public virtual RefBase { | 
| Eino-Ville Talvala | 7fa43f3 | 2013-02-06 17:20:07 -0800 | [diff] [blame] | 265 | public: | 
| Eino-Ville Talvala | f1e98d8 | 2013-09-06 09:32:43 -0700 | [diff] [blame] | 266 | // The set of notifications is a merge of the notifications required for | 
|  | 267 | // API1 and API2. | 
|  | 268 |  | 
|  | 269 | // Required for API 1 and 2 | 
| Eino-Ville Talvala | d56db1d | 2015-12-17 16:50:35 -0800 | [diff] [blame] | 270 | virtual void notifyError(int32_t errorCode, | 
| Jianing Wei | cb0652e | 2014-03-12 18:29:36 -0700 | [diff] [blame] | 271 | const CaptureResultExtras &resultExtras) = 0; | 
| Eino-Ville Talvala | f1e98d8 | 2013-09-06 09:32:43 -0700 | [diff] [blame] | 272 |  | 
|  | 273 | // Required only for API2 | 
|  | 274 | virtual void notifyIdle() = 0; | 
| Jianing Wei | cb0652e | 2014-03-12 18:29:36 -0700 | [diff] [blame] | 275 | virtual void notifyShutter(const CaptureResultExtras &resultExtras, | 
| Eino-Ville Talvala | f1e98d8 | 2013-09-06 09:32:43 -0700 | [diff] [blame] | 276 | nsecs_t timestamp) = 0; | 
| Eino-Ville Talvala | 4d44cad | 2015-04-11 13:15:45 -0700 | [diff] [blame] | 277 | virtual void notifyPrepared(int streamId) = 0; | 
| Shuzhen Wang | 9d06601 | 2016-09-30 11:30:20 -0700 | [diff] [blame] | 278 | virtual void notifyRequestQueueEmpty() = 0; | 
| Eino-Ville Talvala | f1e98d8 | 2013-09-06 09:32:43 -0700 | [diff] [blame] | 279 |  | 
|  | 280 | // Required only for API1 | 
| Eino-Ville Talvala | 7fa43f3 | 2013-02-06 17:20:07 -0800 | [diff] [blame] | 281 | virtual void notifyAutoFocus(uint8_t newState, int triggerId) = 0; | 
|  | 282 | virtual void notifyAutoExposure(uint8_t newState, int triggerId) = 0; | 
|  | 283 | virtual void notifyAutoWhitebalance(uint8_t newState, | 
|  | 284 | int triggerId) = 0; | 
| Chien-Yu Chen | e8c535e | 2016-04-14 12:18:26 -0700 | [diff] [blame] | 285 | virtual void notifyRepeatingRequestError(long lastFrameNumber) = 0; | 
| Eino-Ville Talvala | 7fa43f3 | 2013-02-06 17:20:07 -0800 | [diff] [blame] | 286 | protected: | 
|  | 287 | virtual ~NotificationListener(); | 
|  | 288 | }; | 
|  | 289 |  | 
|  | 290 | /** | 
|  | 291 | * Connect HAL notifications to a listener. Overwrites previous | 
|  | 292 | * listener. Set to NULL to stop receiving notifications. | 
|  | 293 | */ | 
| Yin-Chia Yeh | e1c8063 | 2016-08-08 14:48:05 -0700 | [diff] [blame] | 294 | virtual status_t setNotifyCallback(wp<NotificationListener> listener) = 0; | 
| Eino-Ville Talvala | 7fa43f3 | 2013-02-06 17:20:07 -0800 | [diff] [blame] | 295 |  | 
|  | 296 | /** | 
| Eino-Ville Talvala | 46910bd | 2013-07-18 19:15:17 -0700 | [diff] [blame] | 297 | * Whether the device supports calling notifyAutofocus, notifyAutoExposure, | 
|  | 298 | * and notifyAutoWhitebalance; if this returns false, the client must | 
|  | 299 | * synthesize these notifications from received frame metadata. | 
|  | 300 | */ | 
|  | 301 | virtual bool     willNotify3A() = 0; | 
|  | 302 |  | 
|  | 303 | /** | 
| Eino-Ville Talvala | 7fa43f3 | 2013-02-06 17:20:07 -0800 | [diff] [blame] | 304 | * Wait for a new frame to be produced, with timeout in nanoseconds. | 
|  | 305 | * Returns TIMED_OUT when no frame produced within the specified duration | 
| Eino-Ville Talvala | f1e98d8 | 2013-09-06 09:32:43 -0700 | [diff] [blame] | 306 | * May be called concurrently to most methods, except for getNextFrame | 
| Eino-Ville Talvala | 7fa43f3 | 2013-02-06 17:20:07 -0800 | [diff] [blame] | 307 | */ | 
|  | 308 | virtual status_t waitForNextFrame(nsecs_t timeout) = 0; | 
|  | 309 |  | 
|  | 310 | /** | 
| Jianing Wei | cb0652e | 2014-03-12 18:29:36 -0700 | [diff] [blame] | 311 | * Get next capture result frame from the result queue. Returns NOT_ENOUGH_DATA | 
|  | 312 | * if the queue is empty; caller takes ownership of the metadata buffer inside | 
|  | 313 | * the capture result object's metadata field. | 
|  | 314 | * May be called concurrently to most methods, except for waitForNextFrame. | 
| Eino-Ville Talvala | 7fa43f3 | 2013-02-06 17:20:07 -0800 | [diff] [blame] | 315 | */ | 
| Jianing Wei | cb0652e | 2014-03-12 18:29:36 -0700 | [diff] [blame] | 316 | virtual status_t getNextResult(CaptureResult *frame) = 0; | 
| Eino-Ville Talvala | 7fa43f3 | 2013-02-06 17:20:07 -0800 | [diff] [blame] | 317 |  | 
|  | 318 | /** | 
|  | 319 | * Trigger auto-focus. The latest ID used in a trigger autofocus or cancel | 
|  | 320 | * autofocus call will be returned by the HAL in all subsequent AF | 
|  | 321 | * notifications. | 
|  | 322 | */ | 
|  | 323 | virtual status_t triggerAutofocus(uint32_t id) = 0; | 
|  | 324 |  | 
|  | 325 | /** | 
|  | 326 | * Cancel auto-focus. The latest ID used in a trigger autofocus/cancel | 
|  | 327 | * autofocus call will be returned by the HAL in all subsequent AF | 
|  | 328 | * notifications. | 
|  | 329 | */ | 
|  | 330 | virtual status_t triggerCancelAutofocus(uint32_t id) = 0; | 
|  | 331 |  | 
|  | 332 | /** | 
|  | 333 | * Trigger pre-capture metering. The latest ID used in a trigger pre-capture | 
|  | 334 | * call will be returned by the HAL in all subsequent AE and AWB | 
|  | 335 | * notifications. | 
|  | 336 | */ | 
|  | 337 | virtual status_t triggerPrecaptureMetering(uint32_t id) = 0; | 
|  | 338 |  | 
|  | 339 | /** | 
| Eino-Ville Talvala | abaa51d | 2013-08-14 11:37:00 -0700 | [diff] [blame] | 340 | * Flush all pending and in-flight requests. Blocks until flush is | 
|  | 341 | * complete. | 
| Jianing Wei | cb0652e | 2014-03-12 18:29:36 -0700 | [diff] [blame] | 342 | * 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] | 343 | */ | 
| Jianing Wei | cb0652e | 2014-03-12 18:29:36 -0700 | [diff] [blame] | 344 | virtual status_t flush(int64_t *lastFrameNumber = NULL) = 0; | 
| Eino-Ville Talvala | abaa51d | 2013-08-14 11:37:00 -0700 | [diff] [blame] | 345 |  | 
| Zhijun He | 204e329 | 2014-07-14 17:09:23 -0700 | [diff] [blame] | 346 | /** | 
| Eino-Ville Talvala | 4d44cad | 2015-04-11 13:15:45 -0700 | [diff] [blame] | 347 | * Prepare stream by preallocating buffers for it asynchronously. | 
|  | 348 | * Calls notifyPrepared() once allocation is complete. | 
|  | 349 | */ | 
|  | 350 | virtual status_t prepare(int streamId) = 0; | 
|  | 351 |  | 
|  | 352 | /** | 
| Eino-Ville Talvala | b25e3c8 | 2015-07-15 16:04:27 -0700 | [diff] [blame] | 353 | * Free stream resources by dumping its unused gralloc buffers. | 
|  | 354 | */ | 
|  | 355 | virtual status_t tearDown(int streamId) = 0; | 
|  | 356 |  | 
|  | 357 | /** | 
| Shuzhen Wang | b0fdc1e | 2016-03-20 23:21:39 -0700 | [diff] [blame] | 358 | * Add buffer listener for a particular stream in the device. | 
|  | 359 | */ | 
|  | 360 | virtual status_t addBufferListenerForStream(int streamId, | 
|  | 361 | wp<camera3::Camera3StreamBufferListener> listener) = 0; | 
|  | 362 |  | 
|  | 363 | /** | 
| Ruben Brunk | c78ac26 | 2015-08-13 17:58:46 -0700 | [diff] [blame] | 364 | * Prepare stream by preallocating up to maxCount buffers for it asynchronously. | 
|  | 365 | * Calls notifyPrepared() once allocation is complete. | 
|  | 366 | */ | 
|  | 367 | virtual status_t prepare(int maxCount, int streamId) = 0; | 
|  | 368 |  | 
|  | 369 | /** | 
| Zhijun He | 5d677d1 | 2016-05-29 16:52:39 -0700 | [diff] [blame] | 370 | * Set the deferred consumer surface and finish the rest of the stream configuration. | 
|  | 371 | */ | 
| Shuzhen Wang | 758c215 | 2017-01-10 18:26:18 -0800 | [diff] [blame] | 372 | virtual status_t setConsumerSurfaces(int streamId, | 
| Emilian Peev | 40ead60 | 2017-09-26 15:46:36 +0100 | [diff] [blame] | 373 | const std::vector<sp<Surface>>& consumers, std::vector<int> *surfaceIds /*out*/) = 0; | 
| Zhijun He | 5d677d1 | 2016-05-29 16:52:39 -0700 | [diff] [blame] | 374 |  | 
| Emilian Peev | 40ead60 | 2017-09-26 15:46:36 +0100 | [diff] [blame] | 375 | /** | 
|  | 376 | * Update a given stream. | 
|  | 377 | */ | 
|  | 378 | virtual status_t updateStream(int streamId, const std::vector<sp<Surface>> &newSurfaces, | 
|  | 379 | const std::vector<android::camera3::OutputStreamInfo> &outputInfo, | 
|  | 380 | const std::vector<size_t> &removedSurfaceIds, | 
|  | 381 | KeyedVector<sp<Surface>, size_t> *outputMap/*out*/) = 0; | 
| Chien-Yu Chen | a936ac2 | 2017-10-23 15:59:49 -0700 | [diff] [blame] | 382 |  | 
|  | 383 | /** | 
|  | 384 | * Drop buffers for stream of streamId if dropping is true. If dropping is false, do not | 
|  | 385 | * drop buffers for stream of streamId. | 
|  | 386 | */ | 
|  | 387 | virtual status_t dropStreamBuffers(bool /*dropping*/, int /*streamId*/) = 0; | 
| Emilian Peev | 2a8e283 | 2019-08-23 13:00:31 -0700 | [diff] [blame] | 388 |  | 
|  | 389 | /** | 
|  | 390 | * Returns the maximum expected time it'll take for all currently in-flight | 
|  | 391 | * requests to complete, based on their settings | 
|  | 392 | */ | 
|  | 393 | virtual nsecs_t getExpectedInFlightDuration() = 0; | 
| Yin-Chia Yeh | b978c38 | 2019-10-30 00:22:37 -0700 | [diff] [blame] | 394 |  | 
|  | 395 | /** | 
|  | 396 | * switch to offline session | 
|  | 397 | */ | 
|  | 398 | virtual status_t switchToOffline( | 
|  | 399 | const std::vector<int32_t>& streamsToKeep, | 
|  | 400 | /*out*/ sp<CameraOfflineSessionBase>* session) = 0; | 
| Eino-Ville Talvala | 7fa43f3 | 2013-02-06 17:20:07 -0800 | [diff] [blame] | 401 | }; | 
|  | 402 |  | 
|  | 403 | }; // namespace android | 
|  | 404 |  | 
|  | 405 | #endif |