blob: e17d7000d4762f639745a521051f5c76a604c151 [file] [log] [blame]
Eino-Ville Talvala7fa43f32013-02-06 17:20:07 -08001/*
Shuzhen Wangc28189a2017-11-27 23:05:10 -08002 * Copyright (C) 2013-2018 The Android Open Source Project
Eino-Ville Talvala7fa43f32013-02-06 17:20:07 -08003 *
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 Wang0129d522016-10-30 22:43:41 -070020#include <list>
21
Eino-Ville Talvala7fa43f32013-02-06 17:20:07 -080022#include <utils/RefBase.h>
Eino-Ville Talvala7fa43f32013-02-06 17:20:07 -080023#include <utils/String16.h>
24#include <utils/Vector.h>
Emilian Peev40ead602017-09-26 15:46:36 +010025#include <utils/KeyedVector.h>
Eino-Ville Talvala7fa43f32013-02-06 17:20:07 -080026#include <utils/Timers.h>
Jianing Wei90e59c92014-03-12 18:29:36 -070027#include <utils/List.h>
Carlos Martinez Romero8e776102024-08-21 12:49:10 -070028#include <gui/Flags.h>
Eino-Ville Talvala7fa43f32013-02-06 17:20:07 -080029
30#include "hardware/camera2.h"
31#include "camera/CameraMetadata.h"
Jianing Weicb0652e2014-03-12 18:29:36 -070032#include "camera/CaptureResult.h"
Chien-Yu Chen618ff8a2015-03-13 11:27:17 -070033#include "gui/IGraphicBufferProducer.h"
Zhijun He125684a2015-12-26 15:07:30 -080034#include "device3/Camera3StreamInterface.h"
Shuzhen Wange8675782019-12-05 09:12:14 -080035#include "device3/StatusTracker.h"
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -080036#include "binder/Status.h"
Emilian Peevfaa4bde2020-01-23 12:19:37 -080037#include "FrameProducer.h"
Jayant Chowdharyc67af1b2022-04-07 18:05:04 +000038#include "utils/IPCTransport.h"
Shuzhen Wang045be6c2023-10-12 10:01:10 -070039#include "utils/SessionConfigurationUtils.h"
Eino-Ville Talvala7fa43f32013-02-06 17:20:07 -080040
Yin-Chia Yehb978c382019-10-30 00:22:37 -070041#include "CameraOfflineSessionBase.h"
42
Eino-Ville Talvala7fa43f32013-02-06 17:20:07 -080043namespace android {
44
Emilian Peevf4816702020-04-03 15:44:51 -070045namespace camera3 {
46
Emilian Peev0a2f9332024-09-20 22:13:54 +000047// TODO: Remove this once the GFX native dataspace
48// dependencies are available
49enum { HEIC_ULTRAHDR, ADATASPACE_HEIF_ULTRAHDR = 0x1006 };
50
Emilian Peevf4816702020-04-03 15:44:51 -070051typedef enum camera_stream_configuration_mode {
52 CAMERA_STREAM_CONFIGURATION_NORMAL_MODE = 0,
53 CAMERA_STREAM_CONFIGURATION_CONSTRAINED_HIGH_SPEED_MODE = 1,
54 CAMERA_VENDOR_STREAM_CONFIGURATION_MODE_START = 0x8000
55} camera_stream_configuration_mode_t;
56
Jayant Chowdharyc67af1b2022-04-07 18:05:04 +000057// Matches definition of camera3_jpeg_blob in camera3.h and HIDL definition
58// device@3.2:types.hal, needs to stay around till HIDL support is removed (for
59// HIDL -> AIDL cameraBlob translation)
Emilian Peevf4816702020-04-03 15:44:51 -070060typedef struct camera_jpeg_blob {
61 uint16_t jpeg_blob_id;
62 uint32_t jpeg_size;
63} camera_jpeg_blob_t;
64
65enum {
66 CAMERA_JPEG_BLOB_ID = 0x00FF,
67 CAMERA_JPEG_APP_SEGMENTS_BLOB_ID = 0x0100,
68};
69
70} // namespace camera3
71
72using camera3::camera_request_template_t;;
73using camera3::camera_stream_configuration_mode_t;
74using camera3::camera_stream_rotation_t;
Shuzhen Wang38df0ca2024-10-09 11:33:44 -070075using camera3::SurfaceHolder;
Emilian Peevf4816702020-04-03 15:44:51 -070076
Eino-Ville Talvala2f09bac2016-12-13 11:29:54 -080077class CameraProviderManager;
78
Shuzhen Wang0129d522016-10-30 22:43:41 -070079// Mapping of output stream index to surface ids
80typedef std::unordered_map<int, std::vector<size_t> > SurfaceMap;
81
Eino-Ville Talvala7fa43f32013-02-06 17:20:07 -080082/**
83 * Base interface for version >= 2 camera device classes, which interface to
84 * camera HAL device versions >= 2.
85 */
Emilian Peevfaa4bde2020-01-23 12:19:37 -080086class CameraDeviceBase : public virtual FrameProducer {
Eino-Ville Talvala7fa43f32013-02-06 17:20:07 -080087 public:
88 virtual ~CameraDeviceBase();
89
Jayant Chowdharyc67af1b2022-04-07 18:05:04 +000090 virtual IPCTransport getTransportType() const = 0;
91
Igor Murashkin71381052013-03-04 14:53:08 -080092 /**
Emilian Peev00420d22018-02-05 21:33:13 +000093 * The device vendor tag ID
94 */
95 virtual metadata_vendor_id_t getVendorTagId() const = 0;
96
Austin Borgered99f642023-06-01 16:51:35 -070097 virtual status_t initialize(sp<CameraProviderManager> manager,
98 const std::string& monitorTags) = 0;
Eino-Ville Talvala7fa43f32013-02-06 17:20:07 -080099 virtual status_t disconnect() = 0;
100
Jianing Weicb0652e2014-03-12 18:29:36 -0700101 virtual status_t dump(int fd, const Vector<String16> &args) = 0;
Austin Borgered99f642023-06-01 16:51:35 -0700102 virtual status_t startWatchingTags(const std::string &tags) = 0;
Avichal Rakesh7e53cad2021-10-05 13:46:30 -0700103 virtual status_t stopWatchingTags() = 0;
104 virtual status_t dumpWatchedEventsToVector(std::vector<std::string> &out) = 0;
Eino-Ville Talvala7fa43f32013-02-06 17:20:07 -0800105
106 /**
Jayant Chowdhary6a6d3a82021-11-17 16:54:34 -0800107 * The physical camera device's static characteristics metadata buffer, or
108 * the logical camera's static characteristics if physical id is empty.
Shuzhen Wang2e7f58f2018-07-11 14:00:29 -0700109 */
Austin Borgered99f642023-06-01 16:51:35 -0700110 virtual const CameraMetadata& infoPhysical(const std::string& physicalId) const = 0;
Eino-Ville Talvala7fa43f32013-02-06 17:20:07 -0800111
Emilian Peev15230142023-04-27 20:22:54 +0000112 virtual bool isCompositeJpegRDisabled() const { return false; };
Emilian Peeve579d8b2023-02-28 14:16:08 -0800113
Emilian Peevaebbe412018-01-15 13:53:24 +0000114 struct PhysicalCameraSettings {
115 std::string cameraId;
116 CameraMetadata metadata;
Shuzhen Wang911c6a32021-10-27 13:36:03 -0700117
118 // Whether the physical camera supports testPatternMode/testPatternData
119 bool mHasTestPatternModeTag = true;
120 bool mHasTestPatternDataTag = true;
121
122 // Original value of TEST_PATTERN_MODE and DATA so that they can be
123 // restored when sensor muting is turned off
124 int32_t mOriginalTestPatternMode = 0;
125 int32_t mOriginalTestPatternData[4] = {};
126
Shuzhen Wangaf22e912023-04-11 16:03:17 -0700127 // Original value of SETTINGS_OVERRIDE so that they can be restored if
128 // camera service isn't overwriting the app value.
129 int32_t mOriginalSettingsOverride = ANDROID_CONTROL_SETTINGS_OVERRIDE_OFF;
Emilian Peevaebbe412018-01-15 13:53:24 +0000130 };
131 typedef List<PhysicalCameraSettings> PhysicalCameraSettingsList;
132
Eino-Ville Talvala7fa43f32013-02-06 17:20:07 -0800133 /**
134 * Submit request for capture. The CameraDevice takes ownership of the
135 * passed-in buffer.
Jianing Weicb0652e2014-03-12 18:29:36 -0700136 * Output lastFrameNumber is the expected frame number of this request.
Eino-Ville Talvala7fa43f32013-02-06 17:20:07 -0800137 */
Jianing Weicb0652e2014-03-12 18:29:36 -0700138 virtual status_t capture(CameraMetadata &request, int64_t *lastFrameNumber = NULL) = 0;
Eino-Ville Talvala7fa43f32013-02-06 17:20:07 -0800139
140 /**
Jianing Wei90e59c92014-03-12 18:29:36 -0700141 * Submit a list of requests.
Jianing Weicb0652e2014-03-12 18:29:36 -0700142 * Output lastFrameNumber is the expected last frame number of the list of requests.
Jianing Wei90e59c92014-03-12 18:29:36 -0700143 */
Emilian Peevaebbe412018-01-15 13:53:24 +0000144 virtual status_t captureList(const List<const PhysicalCameraSettingsList> &requests,
Ryan Prichard09a5c6e2024-06-27 23:42:58 -0700145 const std::list<SurfaceMap> &surfaceMaps,
Jianing Weicb0652e2014-03-12 18:29:36 -0700146 int64_t *lastFrameNumber = NULL) = 0;
Jianing Wei90e59c92014-03-12 18:29:36 -0700147
148 /**
Eino-Ville Talvala7fa43f32013-02-06 17:20:07 -0800149 * Submit request for streaming. The CameraDevice makes a copy of the
150 * passed-in buffer and the caller retains ownership.
Jianing Weicb0652e2014-03-12 18:29:36 -0700151 * Output lastFrameNumber is the last frame number of the previous streaming request.
Eino-Ville Talvala7fa43f32013-02-06 17:20:07 -0800152 */
Jianing Weicb0652e2014-03-12 18:29:36 -0700153 virtual status_t setStreamingRequest(const CameraMetadata &request,
154 int64_t *lastFrameNumber = NULL) = 0;
Eino-Ville Talvala7fa43f32013-02-06 17:20:07 -0800155
156 /**
Jianing Wei90e59c92014-03-12 18:29:36 -0700157 * Submit a list of requests for streaming.
Jianing Weicb0652e2014-03-12 18:29:36 -0700158 * Output lastFrameNumber is the last frame number of the previous streaming request.
Jianing Wei90e59c92014-03-12 18:29:36 -0700159 */
Emilian Peevaebbe412018-01-15 13:53:24 +0000160 virtual status_t setStreamingRequestList(const List<const PhysicalCameraSettingsList> &requests,
Ryan Prichard09a5c6e2024-06-27 23:42:58 -0700161 const std::list<SurfaceMap> &surfaceMaps,
Jianing Weicb0652e2014-03-12 18:29:36 -0700162 int64_t *lastFrameNumber = NULL) = 0;
Jianing Wei90e59c92014-03-12 18:29:36 -0700163
164 /**
Eino-Ville Talvala7fa43f32013-02-06 17:20:07 -0800165 * Clear the streaming request slot.
Jianing Weicb0652e2014-03-12 18:29:36 -0700166 * Output lastFrameNumber is the last frame number of the previous streaming request.
Eino-Ville Talvala7fa43f32013-02-06 17:20:07 -0800167 */
Jianing Weicb0652e2014-03-12 18:29:36 -0700168 virtual status_t clearStreamingRequest(int64_t *lastFrameNumber = NULL) = 0;
Eino-Ville Talvala7fa43f32013-02-06 17:20:07 -0800169
170 /**
171 * Wait until a request with the given ID has been dequeued by the
172 * HAL. Returns TIMED_OUT if the timeout duration is reached. Returns
173 * immediately if the latest request received by the HAL has this id.
174 */
175 virtual status_t waitUntilRequestReceived(int32_t requestId,
176 nsecs_t timeout) = 0;
177
178 /**
Yin-Chia Yehb97babb2015-03-12 13:42:44 -0700179 * Create an output stream of the requested size, format, rotation and dataspace
Eino-Ville Talvala7fa43f32013-02-06 17:20:07 -0800180 *
Eino-Ville Talvala3d82c0d2015-02-23 15:19:19 -0800181 * For HAL_PIXEL_FORMAT_BLOB formats, the width and height should be the
182 * logical dimensions of the buffer, not the number of bytes.
Eino-Ville Talvala7fa43f32013-02-06 17:20:07 -0800183 */
Eino-Ville Talvala727d1722015-06-09 13:44:19 -0700184 virtual status_t createStream(sp<Surface> consumer,
Eino-Ville Talvala3d82c0d2015-02-23 15:19:19 -0800185 uint32_t width, uint32_t height, int format,
Emilian Peevf4816702020-04-03 15:44:51 -0700186 android_dataspace dataSpace, camera_stream_rotation_t rotation, int *id,
Austin Borgered99f642023-06-01 16:51:35 -0700187 const std::string& physicalCameraId,
Jayant Chowdhary13f9b2f2020-12-02 22:46:15 -0800188 const std::unordered_set<int32_t> &sensorPixelModesUsed,
Emilian Peev40ead602017-09-26 15:46:36 +0100189 std::vector<int> *surfaceIds = nullptr,
Zhijun He5d677d12016-05-29 16:52:39 -0700190 int streamSetId = camera3::CAMERA3_STREAM_SET_ID_INVALID,
Shuzhen Wang83bff122020-11-20 15:51:39 -0800191 bool isShared = false, bool isMultiResolution = false,
Emilian Peev2295df72021-11-12 18:14:10 -0800192 uint64_t consumerUsage = 0,
Emilian Peevc81a7592022-02-14 17:38:18 -0800193 int64_t dynamicProfile = ANDROID_REQUEST_AVAILABLE_DYNAMIC_RANGE_PROFILES_MAP_STANDARD,
Shuzhen Wang8ed1e872022-03-08 16:34:33 -0800194 int64_t streamUseCase = ANDROID_SCALER_AVAILABLE_STREAM_USE_CASES_DEFAULT,
Shuzhen Wang610d7b82022-02-08 14:37:22 -0800195 int timestampBase = OutputConfiguration::TIMESTAMP_BASE_DEFAULT,
Austin Borger9e2b27c2022-07-15 11:27:24 -0700196 int mirrorMode = OutputConfiguration::MIRROR_MODE_AUTO,
Shuzhen Wangbce53db2022-12-03 00:38:20 +0000197 int32_t colorSpace = ANDROID_REQUEST_AVAILABLE_COLOR_SPACE_PROFILES_MAP_UNSPECIFIED,
198 bool useReadoutTimestamp = false)
Austin Borger9e2b27c2022-07-15 11:27:24 -0700199 = 0;
Eino-Ville Talvala7fa43f32013-02-06 17:20:07 -0800200
201 /**
Shuzhen Wang0129d522016-10-30 22:43:41 -0700202 * Create an output stream of the requested size, format, rotation and
203 * dataspace with a number of consumers.
204 *
205 * For HAL_PIXEL_FORMAT_BLOB formats, the width and height should be the
206 * logical dimensions of the buffer, not the number of bytes.
207 */
Shuzhen Wang38df0ca2024-10-09 11:33:44 -0700208 virtual status_t createStream(const std::vector<SurfaceHolder>& consumers,
Shuzhen Wang0129d522016-10-30 22:43:41 -0700209 bool hasDeferredConsumer, uint32_t width, uint32_t height, int format,
Emilian Peevf4816702020-04-03 15:44:51 -0700210 android_dataspace dataSpace, camera_stream_rotation_t rotation, int *id,
Austin Borgered99f642023-06-01 16:51:35 -0700211 const std::string& physicalCameraId,
Jayant Chowdhary13f9b2f2020-12-02 22:46:15 -0800212 const std::unordered_set<int32_t> &sensorPixelModesUsed,
Emilian Peev40ead602017-09-26 15:46:36 +0100213 std::vector<int> *surfaceIds = nullptr,
Shuzhen Wang0129d522016-10-30 22:43:41 -0700214 int streamSetId = camera3::CAMERA3_STREAM_SET_ID_INVALID,
Shuzhen Wang83bff122020-11-20 15:51:39 -0800215 bool isShared = false, bool isMultiResolution = false,
Emilian Peev2295df72021-11-12 18:14:10 -0800216 uint64_t consumerUsage = 0,
Emilian Peevc81a7592022-02-14 17:38:18 -0800217 int64_t dynamicProfile = ANDROID_REQUEST_AVAILABLE_DYNAMIC_RANGE_PROFILES_MAP_STANDARD,
Shuzhen Wang8ed1e872022-03-08 16:34:33 -0800218 int64_t streamUseCase = ANDROID_SCALER_AVAILABLE_STREAM_USE_CASES_DEFAULT,
Shuzhen Wang610d7b82022-02-08 14:37:22 -0800219 int timestampBase = OutputConfiguration::TIMESTAMP_BASE_DEFAULT,
Shuzhen Wangbce53db2022-12-03 00:38:20 +0000220 int32_t colorSpace = ANDROID_REQUEST_AVAILABLE_COLOR_SPACE_PROFILES_MAP_UNSPECIFIED,
221 bool useReadoutTimestamp = false)
Austin Borger9e2b27c2022-07-15 11:27:24 -0700222 = 0;
Shuzhen Wang0129d522016-10-30 22:43:41 -0700223
224 /**
Chien-Yu Chen618ff8a2015-03-13 11:27:17 -0700225 * Create an input stream of width, height, and format.
226 *
227 * Return value is the stream ID if non-negative and an error if negative.
228 */
229 virtual status_t createInputStream(uint32_t width, uint32_t height,
Shuzhen Wang83bff122020-11-20 15:51:39 -0800230 int32_t format, bool multiResolution, /*out*/ int32_t *id) = 0;
Chien-Yu Chen618ff8a2015-03-13 11:27:17 -0700231
Emilian Peev710c1422017-08-30 11:19:38 +0100232 struct StreamInfo {
233 uint32_t width;
234 uint32_t height;
Eino-Ville Talvala91cd3f82017-08-21 16:12:50 -0700235
Emilian Peev710c1422017-08-30 11:19:38 +0100236 uint32_t format;
237 bool formatOverridden;
238 uint32_t originalFormat;
Eino-Ville Talvala91cd3f82017-08-21 16:12:50 -0700239
Emilian Peev710c1422017-08-30 11:19:38 +0100240 android_dataspace dataSpace;
Eino-Ville Talvala91cd3f82017-08-21 16:12:50 -0700241 bool dataSpaceOverridden;
242 android_dataspace originalDataSpace;
Emilian Peevc81a7592022-02-14 17:38:18 -0800243 int64_t dynamicRangeProfile;
Austin Borger9e2b27c2022-07-15 11:27:24 -0700244 int32_t colorSpace;
Eino-Ville Talvala91cd3f82017-08-21 16:12:50 -0700245
Emilian Peev710c1422017-08-30 11:19:38 +0100246 StreamInfo() : width(0), height(0), format(0), formatOverridden(false), originalFormat(0),
Eino-Ville Talvala91cd3f82017-08-21 16:12:50 -0700247 dataSpace(HAL_DATASPACE_UNKNOWN), dataSpaceOverridden(false),
Emilian Peev2295df72021-11-12 18:14:10 -0800248 originalDataSpace(HAL_DATASPACE_UNKNOWN),
Austin Borger9e2b27c2022-07-15 11:27:24 -0700249 dynamicRangeProfile(ANDROID_REQUEST_AVAILABLE_DYNAMIC_RANGE_PROFILES_MAP_STANDARD),
250 colorSpace(ANDROID_REQUEST_AVAILABLE_COLOR_SPACE_PROFILES_MAP_UNSPECIFIED) {}
Emilian Peev710c1422017-08-30 11:19:38 +0100251 /**
252 * Check whether the format matches the current or the original one in case
253 * it got overridden.
254 */
Eino-Ville Talvala91cd3f82017-08-21 16:12:50 -0700255 bool matchFormat(uint32_t clientFormat) const {
Emilian Peev710c1422017-08-30 11:19:38 +0100256 if ((formatOverridden && (originalFormat == clientFormat)) ||
257 (format == clientFormat)) {
258 return true;
259 }
260 return false;
261 }
Eino-Ville Talvala91cd3f82017-08-21 16:12:50 -0700262
263 /**
264 * Check whether the dataspace matches the current or the original one in case
265 * it got overridden.
266 */
267 bool matchDataSpace(android_dataspace clientDataSpace) const {
268 if ((dataSpaceOverridden && (originalDataSpace == clientDataSpace)) ||
269 (dataSpace == clientDataSpace)) {
270 return true;
271 }
272 return false;
273 }
274
Emilian Peev710c1422017-08-30 11:19:38 +0100275 };
276
Chien-Yu Chen618ff8a2015-03-13 11:27:17 -0700277 /**
Eino-Ville Talvala7fa43f32013-02-06 17:20:07 -0800278 * Get information about a given stream.
279 */
Emilian Peev710c1422017-08-30 11:19:38 +0100280 virtual status_t getStreamInfo(int id, StreamInfo *streamInfo) = 0;
Eino-Ville Talvala7fa43f32013-02-06 17:20:07 -0800281
282 /**
283 * Set stream gralloc buffer transform
284 */
285 virtual status_t setStreamTransform(int id, int transform) = 0;
286
287 /**
288 * Delete stream. Must not be called if there are requests in flight which
289 * reference that stream.
290 */
291 virtual status_t deleteStream(int id) = 0;
292
293 /**
Igor Murashkine2d167e2014-08-19 16:19:59 -0700294 * Take the currently-defined set of streams and configure the HAL to use
295 * them. This is a long-running operation (may be several hundered ms).
296 *
297 * The device must be idle (see waitUntilDrained) before calling this.
298 *
299 * Returns OK on success; otherwise on error:
300 * - BAD_VALUE if the set of streams was invalid (e.g. fmts or sizes)
301 * - INVALID_OPERATION if the device was in the wrong state
302 */
Emilian Peev5fbe0ba2017-10-20 15:45:45 +0100303 virtual status_t configureStreams(const CameraMetadata& sessionParams,
Emilian Peevf4816702020-04-03 15:44:51 -0700304 int operatingMode =
305 camera_stream_configuration_mode_t::CAMERA_STREAM_CONFIGURATION_NORMAL_MODE) = 0;
Igor Murashkine2d167e2014-08-19 16:19:59 -0700306
Emilian Peevcc0b7952020-01-07 13:54:47 -0800307 /**
308 * Retrieve a list of all stream ids that were advertised as capable of
309 * supporting offline processing mode by Hal after the last stream configuration.
310 */
311 virtual void getOfflineStreamIds(std::vector<int> *offlineStreamIds) = 0;
312
Carlos Martinez Romero8e776102024-08-21 12:49:10 -0700313#if WB_CAMERA3_AND_PROCESSORS_WITH_DEPENDENCIES
314 // get the surface of the input stream
315 virtual status_t getInputSurface(sp<Surface> *surface) = 0;
316#else
Chien-Yu Chen618ff8a2015-03-13 11:27:17 -0700317 // get the buffer producer of the input stream
318 virtual status_t getInputBufferProducer(
319 sp<IGraphicBufferProducer> *producer) = 0;
Carlos Martinez Romero8e776102024-08-21 12:49:10 -0700320#endif
Chien-Yu Chen618ff8a2015-03-13 11:27:17 -0700321
Igor Murashkine2d167e2014-08-19 16:19:59 -0700322 /**
Eino-Ville Talvala7fa43f32013-02-06 17:20:07 -0800323 * Create a metadata buffer with fields that the HAL device believes are
324 * best for the given use case
325 */
Emilian Peevf4816702020-04-03 15:44:51 -0700326 virtual status_t createDefaultRequest(camera_request_template_t templateId,
Eino-Ville Talvala7fa43f32013-02-06 17:20:07 -0800327 CameraMetadata *request) = 0;
328
329 /**
330 * Wait until all requests have been processed. Returns INVALID_OPERATION if
331 * the streaming slot is not empty, or TIMED_OUT if the requests haven't
332 * finished processing in 10 seconds.
333 */
334 virtual status_t waitUntilDrained() = 0;
335
336 /**
Zhijun He28c9b6f2014-08-08 12:00:47 -0700337 * Get Jpeg buffer size for a given jpeg resolution.
338 * Negative values are error codes.
339 */
Jayant Chowdhary6a6d3a82021-11-17 16:54:34 -0800340 virtual ssize_t getJpegBufferSize(const CameraMetadata &info, uint32_t width,
341 uint32_t height) const = 0;
Zhijun He28c9b6f2014-08-08 12:00:47 -0700342
343 /**
Eino-Ville Talvala7fa43f32013-02-06 17:20:07 -0800344 * Connect HAL notifications to a listener. Overwrites previous
345 * listener. Set to NULL to stop receiving notifications.
346 */
Yin-Chia Yehe1c80632016-08-08 14:48:05 -0700347 virtual status_t setNotifyCallback(wp<NotificationListener> listener) = 0;
Eino-Ville Talvala7fa43f32013-02-06 17:20:07 -0800348
349 /**
Eino-Ville Talvala46910bd2013-07-18 19:15:17 -0700350 * Whether the device supports calling notifyAutofocus, notifyAutoExposure,
351 * and notifyAutoWhitebalance; if this returns false, the client must
352 * synthesize these notifications from received frame metadata.
353 */
354 virtual bool willNotify3A() = 0;
355
356 /**
Eino-Ville Talvala7fa43f32013-02-06 17:20:07 -0800357 * Trigger auto-focus. The latest ID used in a trigger autofocus or cancel
358 * autofocus call will be returned by the HAL in all subsequent AF
359 * notifications.
360 */
361 virtual status_t triggerAutofocus(uint32_t id) = 0;
362
363 /**
364 * Cancel auto-focus. The latest ID used in a trigger autofocus/cancel
365 * autofocus call will be returned by the HAL in all subsequent AF
366 * notifications.
367 */
368 virtual status_t triggerCancelAutofocus(uint32_t id) = 0;
369
370 /**
371 * Trigger pre-capture metering. The latest ID used in a trigger pre-capture
372 * call will be returned by the HAL in all subsequent AE and AWB
373 * notifications.
374 */
375 virtual status_t triggerPrecaptureMetering(uint32_t id) = 0;
376
377 /**
Eino-Ville Talvalaabaa51d2013-08-14 11:37:00 -0700378 * Flush all pending and in-flight requests. Blocks until flush is
379 * complete.
Jianing Weicb0652e2014-03-12 18:29:36 -0700380 * Output lastFrameNumber is the last frame number of the previous streaming request.
Eino-Ville Talvalaabaa51d2013-08-14 11:37:00 -0700381 */
Jianing Weicb0652e2014-03-12 18:29:36 -0700382 virtual status_t flush(int64_t *lastFrameNumber = NULL) = 0;
Eino-Ville Talvalaabaa51d2013-08-14 11:37:00 -0700383
Zhijun He204e3292014-07-14 17:09:23 -0700384 /**
Eino-Ville Talvala4d44cad2015-04-11 13:15:45 -0700385 * Prepare stream by preallocating buffers for it asynchronously.
386 * Calls notifyPrepared() once allocation is complete.
387 */
388 virtual status_t prepare(int streamId) = 0;
389
390 /**
Eino-Ville Talvalab25e3c82015-07-15 16:04:27 -0700391 * Free stream resources by dumping its unused gralloc buffers.
392 */
393 virtual status_t tearDown(int streamId) = 0;
394
395 /**
Shuzhen Wangb0fdc1e2016-03-20 23:21:39 -0700396 * Add buffer listener for a particular stream in the device.
397 */
398 virtual status_t addBufferListenerForStream(int streamId,
399 wp<camera3::Camera3StreamBufferListener> listener) = 0;
400
401 /**
Ruben Brunkc78ac262015-08-13 17:58:46 -0700402 * Prepare stream by preallocating up to maxCount buffers for it asynchronously.
403 * Calls notifyPrepared() once allocation is complete.
404 */
405 virtual status_t prepare(int maxCount, int streamId) = 0;
406
407 /**
Zhijun He5d677d12016-05-29 16:52:39 -0700408 * Set the deferred consumer surface and finish the rest of the stream configuration.
409 */
Shuzhen Wang758c2152017-01-10 18:26:18 -0800410 virtual status_t setConsumerSurfaces(int streamId,
Shuzhen Wang38df0ca2024-10-09 11:33:44 -0700411 const std::vector<SurfaceHolder>& consumers, std::vector<int> *surfaceIds /*out*/) = 0;
Zhijun He5d677d12016-05-29 16:52:39 -0700412
Emilian Peev40ead602017-09-26 15:46:36 +0100413 /**
414 * Update a given stream.
415 */
Shuzhen Wang38df0ca2024-10-09 11:33:44 -0700416 virtual status_t updateStream(int streamId, const std::vector<SurfaceHolder> &newSurfaces,
Emilian Peev40ead602017-09-26 15:46:36 +0100417 const std::vector<android::camera3::OutputStreamInfo> &outputInfo,
418 const std::vector<size_t> &removedSurfaceIds,
419 KeyedVector<sp<Surface>, size_t> *outputMap/*out*/) = 0;
Chien-Yu Chena936ac22017-10-23 15:59:49 -0700420
421 /**
422 * Drop buffers for stream of streamId if dropping is true. If dropping is false, do not
423 * drop buffers for stream of streamId.
424 */
425 virtual status_t dropStreamBuffers(bool /*dropping*/, int /*streamId*/) = 0;
Emilian Peev2a8e2832019-08-23 13:00:31 -0700426
427 /**
428 * Returns the maximum expected time it'll take for all currently in-flight
429 * requests to complete, based on their settings
430 */
431 virtual nsecs_t getExpectedInFlightDuration() = 0;
Yin-Chia Yehb978c382019-10-30 00:22:37 -0700432
433 /**
434 * switch to offline session
435 */
436 virtual status_t switchToOffline(
437 const std::vector<int32_t>& streamsToKeep,
438 /*out*/ sp<CameraOfflineSessionBase>* session) = 0;
Eino-Ville Talvalaf2e37092020-01-07 15:32:32 -0800439
440 /**
441 * Set the current behavior for the ROTATE_AND_CROP control when in AUTO.
442 *
443 * The value must be one of the ROTATE_AND_CROP_* values besides AUTO,
444 * and defaults to NONE.
445 */
446 virtual status_t setRotateAndCropAutoBehavior(
Jayant Chowdhary44d5f622023-09-20 03:11:41 +0000447 camera_metadata_enum_android_scaler_rotate_and_crop_t rotateAndCropValue,
448 bool fromHal = false) = 0;
Eino-Ville Talvalaf2e37092020-01-07 15:32:32 -0800449
Shuzhen Wange8675782019-12-05 09:12:14 -0800450 /**
Bharatt Kukreja7146ced2022-10-25 15:45:29 +0000451 * Set the current behavior for the AUTOFRAMING control when in AUTO.
452 *
453 * The value must be one of the AUTOFRAMING_* values besides AUTO.
454 */
455 virtual status_t setAutoframingAutoBehavior(
456 camera_metadata_enum_android_control_autoframing_t autoframingValue) = 0;
457
458 /**
Eino-Ville Talvala305cec62020-11-12 14:18:17 -0800459 * Whether camera muting (producing black-only output) is supported.
460 *
461 * Calling setCameraMute(true) when this returns false will return an
462 * INVALID_OPERATION error.
463 */
464 virtual bool supportsCameraMute() = 0;
465
466 /**
467 * Mute the camera.
468 *
469 * When muted, black image data is output on all output streams.
470 */
471 virtual status_t setCameraMute(bool enabled) = 0;
472
473 /**
Shuzhen Wangaf22e912023-04-11 16:03:17 -0700474 * Whether the camera device supports zoom override.
475 */
476 virtual bool supportsZoomOverride() = 0;
477
478 // Set/reset zoom override
479 virtual status_t setZoomOverride(int32_t zoomOverride) = 0;
480
481 /**
Ravneetaeb20dc2022-03-30 05:33:03 +0000482 * Enable/disable camera service watchdog
483 */
484 virtual status_t setCameraServiceWatchdog(bool enabled) = 0;
485
486 /**
Shuzhen Wange8675782019-12-05 09:12:14 -0800487 * Get the status tracker of the camera device
488 */
489 virtual wp<camera3::StatusTracker> getStatusTracker() = 0;
Shuzhen Wangabbcb6b2020-12-09 22:32:44 -0800490
491 /**
Shuzhen Wang03fe6232023-02-05 12:41:15 -0800492 * If the device is in eror state
493 */
494 virtual bool hasDeviceError() = 0;
495
496 /**
Shuzhen Wangabbcb6b2020-12-09 22:32:44 -0800497 * Set bitmask for image dump flag
498 */
499 void setImageDumpMask(int mask) { mImageDumpMask = mask; }
500
Cliff Wud3a05312021-04-26 23:07:31 +0800501 /**
Shuzhen Wang16610a62022-12-15 22:38:07 -0800502 * Set stream use case overrides
503 */
504 void setStreamUseCaseOverrides(const std::vector<int64_t>& useCaseOverrides) {
505 mStreamUseCaseOverrides = useCaseOverrides;
506 }
507
508 void clearStreamUseCaseOverrides() {}
509
510 /**
Cliff Wud3a05312021-04-26 23:07:31 +0800511 * The injection camera session to replace the internal camera
512 * session.
513 */
Austin Borgered99f642023-06-01 16:51:35 -0700514 virtual status_t injectCamera(const std::string& injectedCamId,
Cliff Wud3a05312021-04-26 23:07:31 +0800515 sp<CameraProviderManager> manager) = 0;
516
517 /**
518 * Stop the injection camera and restore to internal camera session.
519 */
520 virtual status_t stopInjection() = 0;
521
malikakash22af94c2023-12-04 18:13:14 +0000522 // Inject session parameters into an existing client.
523 virtual status_t injectSessionParams(
524 const CameraMetadata& sessionParams) = 0;
525
Shuzhen Wangabbcb6b2020-12-09 22:32:44 -0800526protected:
527 bool mImageDumpMask = 0;
Shuzhen Wang16610a62022-12-15 22:38:07 -0800528 std::vector<int64_t> mStreamUseCaseOverrides;
Eino-Ville Talvala7fa43f32013-02-06 17:20:07 -0800529};
530
531}; // namespace android
532
533#endif