Jayant Chowdhary | 2bbdce4 | 2020-01-12 14:55:41 -0800 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2020 The Android Open Source Project |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
| 16 | #ifndef ANDROID_SERVERS_CAMERA_SESSION_CONFIGURATION_UTILS_H |
| 17 | #define ANDROID_SERVERS_CAMERA_SESSION_CONFIGURATION_UTILS_H |
| 18 | |
| 19 | #include <android/hardware/camera2/BnCameraDeviceUser.h> |
| 20 | #include <android/hardware/camera2/ICameraDeviceCallbacks.h> |
| 21 | #include <camera/camera2/OutputConfiguration.h> |
| 22 | #include <camera/camera2/SessionConfiguration.h> |
| 23 | #include <camera/camera2/SubmitInfo.h> |
Austin Borger | 0fb3ad9 | 2023-06-01 16:51:35 -0700 | [diff] [blame] | 24 | #include <camera/StringUtils.h> |
Jayant Chowdhary | a04055f | 2022-01-03 02:07:49 +0000 | [diff] [blame] | 25 | #include <aidl/android/hardware/camera/device/ICameraDevice.h> |
Jayant Chowdhary | 13f9b2f | 2020-12-02 22:46:15 -0800 | [diff] [blame] | 26 | #include <android/hardware/camera/device/3.4/ICameraDeviceSession.h> |
| 27 | #include <android/hardware/camera/device/3.7/ICameraDeviceSession.h> |
Jayant Chowdhary | 2bbdce4 | 2020-01-12 14:55:41 -0800 | [diff] [blame] | 28 | |
Colin Cross | b8a9dbb | 2020-08-27 04:12:26 +0000 | [diff] [blame] | 29 | #include <device3/Camera3StreamInterface.h> |
Jayant Chowdhary | c67af1b | 2022-04-07 18:05:04 +0000 | [diff] [blame] | 30 | #include <utils/IPCTransport.h> |
Colin Cross | b8a9dbb | 2020-08-27 04:12:26 +0000 | [diff] [blame] | 31 | |
Shuzhen Wang | d4abdf7 | 2021-05-28 11:22:50 -0700 | [diff] [blame] | 32 | #include <set> |
Jayant Chowdhary | 2bbdce4 | 2020-01-12 14:55:41 -0800 | [diff] [blame] | 33 | #include <stdint.h> |
| 34 | |
Austin Borger | ea93124 | 2021-12-13 23:10:41 +0000 | [diff] [blame] | 35 | #include "SessionConfigurationUtilsHost.h" |
| 36 | |
Jayant Chowdhary | 13f9b2f | 2020-12-02 22:46:15 -0800 | [diff] [blame] | 37 | // Convenience methods for constructing binder::Status objects for error returns |
| 38 | |
| 39 | #define STATUS_ERROR(errorCode, errorString) \ |
| 40 | binder::Status::fromServiceSpecificError(errorCode, \ |
Austin Borger | 0fb3ad9 | 2023-06-01 16:51:35 -0700 | [diff] [blame] | 41 | fmt::sprintf("%s:%d: %s", __FUNCTION__, __LINE__, errorString).c_str()) |
Jayant Chowdhary | 13f9b2f | 2020-12-02 22:46:15 -0800 | [diff] [blame] | 42 | |
| 43 | #define STATUS_ERROR_FMT(errorCode, errorString, ...) \ |
| 44 | binder::Status::fromServiceSpecificError(errorCode, \ |
Austin Borger | 0fb3ad9 | 2023-06-01 16:51:35 -0700 | [diff] [blame] | 45 | fmt::sprintf("%s:%d: " errorString, __FUNCTION__, __LINE__, \ |
| 46 | __VA_ARGS__).c_str()) |
Jayant Chowdhary | 13f9b2f | 2020-12-02 22:46:15 -0800 | [diff] [blame] | 47 | |
Jayant Chowdhary | 2bbdce4 | 2020-01-12 14:55:41 -0800 | [diff] [blame] | 48 | namespace android { |
Jayant Chowdhary | 13f9b2f | 2020-12-02 22:46:15 -0800 | [diff] [blame] | 49 | namespace camera3 { |
Jayant Chowdhary | 2bbdce4 | 2020-01-12 14:55:41 -0800 | [diff] [blame] | 50 | |
Austin Borger | 0fb3ad9 | 2023-06-01 16:51:35 -0700 | [diff] [blame] | 51 | typedef std::function<CameraMetadata (const std::string &, bool overrideForPerfClass)> |
| 52 | metadataGetter; |
Jayant Chowdhary | 2bbdce4 | 2020-01-12 14:55:41 -0800 | [diff] [blame] | 53 | |
Jayant Chowdhary | 13f9b2f | 2020-12-02 22:46:15 -0800 | [diff] [blame] | 54 | class StreamConfiguration { |
| 55 | public: |
| 56 | int32_t format; |
| 57 | int32_t width; |
| 58 | int32_t height; |
| 59 | int32_t isInput; |
| 60 | static void getStreamConfigurations( |
| 61 | const CameraMetadata &static_info, bool maxRes, |
| 62 | std::unordered_map<int, std::vector<StreamConfiguration>> *scm); |
| 63 | static void getStreamConfigurations( |
| 64 | const CameraMetadata &static_info, int configuration, |
| 65 | std::unordered_map<int, std::vector<StreamConfiguration>> *scm); |
| 66 | }; |
| 67 | |
| 68 | // Holds the default StreamConfigurationMap and Maximum resolution |
| 69 | // StreamConfigurationMap for a camera device. |
| 70 | struct StreamConfigurationPair { |
| 71 | std::unordered_map<int, std::vector<camera3::StreamConfiguration>> |
| 72 | mDefaultStreamConfigurationMap; |
| 73 | std::unordered_map<int, std::vector<camera3::StreamConfiguration>> |
| 74 | mMaximumResolutionStreamConfigurationMap; |
| 75 | }; |
| 76 | |
Austin Borger | ea93124 | 2021-12-13 23:10:41 +0000 | [diff] [blame] | 77 | namespace SessionConfigurationUtils { |
Jayant Chowdhary | cd3d36b | 2021-07-10 10:53:53 -0700 | [diff] [blame] | 78 | |
Austin Borger | ea93124 | 2021-12-13 23:10:41 +0000 | [diff] [blame] | 79 | camera3::Size getMaxJpegResolution(const CameraMetadata &metadata, |
| 80 | bool ultraHighResolution); |
Jayant Chowdhary | cd3d36b | 2021-07-10 10:53:53 -0700 | [diff] [blame] | 81 | |
Austin Borger | ea93124 | 2021-12-13 23:10:41 +0000 | [diff] [blame] | 82 | size_t getUHRMaxJpegBufferSize(camera3::Size uhrMaxJpegSize, |
| 83 | camera3::Size defaultMaxJpegSize, size_t defaultMaxJpegBufferSize); |
Colin Cross | b8a9dbb | 2020-08-27 04:12:26 +0000 | [diff] [blame] | 84 | |
Austin Borger | ea93124 | 2021-12-13 23:10:41 +0000 | [diff] [blame] | 85 | int64_t euclidDistSquare(int32_t x0, int32_t y0, int32_t x1, int32_t y1); |
Colin Cross | b8a9dbb | 2020-08-27 04:12:26 +0000 | [diff] [blame] | 86 | |
Austin Borger | ea93124 | 2021-12-13 23:10:41 +0000 | [diff] [blame] | 87 | // Find the closest dimensions for a given format in available stream configurations with |
| 88 | // a width <= ROUNDING_WIDTH_CAP |
| 89 | bool roundBufferDimensionNearest(int32_t width, int32_t height, int32_t format, |
| 90 | android_dataspace dataSpace, const CameraMetadata& info, bool maxResolution, |
| 91 | /*out*/int32_t* outWidth, /*out*/int32_t* outHeight); |
Jayant Chowdhary | 9255ce0 | 2021-07-15 11:18:17 -0700 | [diff] [blame] | 92 | |
Austin Borger | ea93124 | 2021-12-13 23:10:41 +0000 | [diff] [blame] | 93 | // check if format is not custom format |
| 94 | bool isPublicFormat(int32_t format); |
Colin Cross | b8a9dbb | 2020-08-27 04:12:26 +0000 | [diff] [blame] | 95 | |
Austin Borger | ea93124 | 2021-12-13 23:10:41 +0000 | [diff] [blame] | 96 | // Create a Surface from an IGraphicBufferProducer. Returns error if |
| 97 | // IGraphicBufferProducer's property doesn't match with streamInfo |
| 98 | binder::Status createSurfaceFromGbp( |
Shuzhen Wang | c8ab452 | 2021-12-14 20:12:42 -0800 | [diff] [blame] | 99 | camera3::OutputStreamInfo& streamInfo, bool isStreamInfoValid, |
| 100 | sp<Surface>& surface, const sp<IGraphicBufferProducer>& gbp, |
Austin Borger | 0fb3ad9 | 2023-06-01 16:51:35 -0700 | [diff] [blame] | 101 | const std::string &logicalCameraId, const CameraMetadata &physicalCameraMetadata, |
Emilian Peev | c81a759 | 2022-02-14 17:38:18 -0800 | [diff] [blame] | 102 | const std::vector<int32_t> &sensorPixelModesUsed, int64_t dynamicRangeProfile, |
Austin Borger | 9e2b27c | 2022-07-15 11:27:24 -0700 | [diff] [blame] | 103 | int64_t streamUseCase, int timestampBase, int mirrorMode, |
| 104 | int32_t colorSpace); |
Shuzhen Wang | c8ab452 | 2021-12-14 20:12:42 -0800 | [diff] [blame] | 105 | |
Emilian Peev | 2295df7 | 2021-11-12 18:14:10 -0800 | [diff] [blame] | 106 | //check if format is 10-bit output compatible |
Emilian Peev | 434248e | 2022-10-06 14:58:54 -0700 | [diff] [blame] | 107 | bool is10bitCompatibleFormat(int32_t format, android_dataspace_t dataSpace); |
Emilian Peev | 2295df7 | 2021-11-12 18:14:10 -0800 | [diff] [blame] | 108 | |
| 109 | // check if the dynamic range requires 10-bit output |
Emilian Peev | c81a759 | 2022-02-14 17:38:18 -0800 | [diff] [blame] | 110 | bool is10bitDynamicRangeProfile(int64_t dynamicRangeProfile); |
Emilian Peev | 2295df7 | 2021-11-12 18:14:10 -0800 | [diff] [blame] | 111 | |
| 112 | // Check if the device supports a given dynamicRangeProfile |
Emilian Peev | c81a759 | 2022-02-14 17:38:18 -0800 | [diff] [blame] | 113 | bool isDynamicRangeProfileSupported(int64_t dynamicRangeProfile, const CameraMetadata& staticMeta); |
Emilian Peev | 2295df7 | 2021-11-12 18:14:10 -0800 | [diff] [blame] | 114 | |
Austin Borger | 9e2b27c | 2022-07-15 11:27:24 -0700 | [diff] [blame] | 115 | bool deviceReportsColorSpaces(const CameraMetadata& staticMeta); |
| 116 | |
| 117 | bool isColorSpaceSupported(int32_t colorSpace, int32_t format, android_dataspace dataSpace, |
| 118 | int64_t dynamicRangeProfile, const CameraMetadata& staticMeta); |
| 119 | |
Austin Borger | 9b263b1 | 2023-03-27 17:01:33 -0700 | [diff] [blame] | 120 | bool dataSpaceFromColorSpace(android_dataspace *dataSpace, int32_t colorSpace); |
| 121 | |
Shuzhen Wang | 8ed1e87 | 2022-03-08 16:34:33 -0800 | [diff] [blame] | 122 | bool isStreamUseCaseSupported(int64_t streamUseCase, const CameraMetadata &deviceInfo); |
Shuzhen Wang | c8ab452 | 2021-12-14 20:12:42 -0800 | [diff] [blame] | 123 | |
Jayant Chowdhary | a04055f | 2022-01-03 02:07:49 +0000 | [diff] [blame] | 124 | void mapStreamInfo(const OutputStreamInfo &streamInfo, |
Austin Borger | 0fb3ad9 | 2023-06-01 16:51:35 -0700 | [diff] [blame] | 125 | camera3::camera_stream_rotation_t rotation, const std::string &physicalId, |
Jayant Chowdhary | a04055f | 2022-01-03 02:07:49 +0000 | [diff] [blame] | 126 | int32_t groupId, aidl::android::hardware::camera::device::Stream *stream /*out*/); |
| 127 | |
Austin Borger | ea93124 | 2021-12-13 23:10:41 +0000 | [diff] [blame] | 128 | // Check that the physicalCameraId passed in is spported by the camera |
| 129 | // device. |
| 130 | binder::Status checkPhysicalCameraId( |
Austin Borger | 0fb3ad9 | 2023-06-01 16:51:35 -0700 | [diff] [blame] | 131 | const std::vector<std::string> &physicalCameraIds, const std::string &physicalCameraId, |
| 132 | const std::string &logicalCameraId); |
Colin Cross | b8a9dbb | 2020-08-27 04:12:26 +0000 | [diff] [blame] | 133 | |
Austin Borger | ea93124 | 2021-12-13 23:10:41 +0000 | [diff] [blame] | 134 | binder::Status checkSurfaceType(size_t numBufferProducers, |
| 135 | bool deferredConsumer, int surfaceType); |
Colin Cross | b8a9dbb | 2020-08-27 04:12:26 +0000 | [diff] [blame] | 136 | |
Austin Borger | ea93124 | 2021-12-13 23:10:41 +0000 | [diff] [blame] | 137 | binder::Status checkOperatingMode(int operatingMode, |
Austin Borger | 0fb3ad9 | 2023-06-01 16:51:35 -0700 | [diff] [blame] | 138 | const CameraMetadata &staticInfo, const std::string &cameraId); |
Colin Cross | b8a9dbb | 2020-08-27 04:12:26 +0000 | [diff] [blame] | 139 | |
Jayant Chowdhary | a04055f | 2022-01-03 02:07:49 +0000 | [diff] [blame] | 140 | binder::Status |
| 141 | convertToHALStreamCombination( |
| 142 | const SessionConfiguration& sessionConfiguration, |
Austin Borger | 0fb3ad9 | 2023-06-01 16:51:35 -0700 | [diff] [blame] | 143 | const std::string &logicalCameraId, const CameraMetadata &deviceInfo, |
Xin Li | 65d5308 | 2023-08-25 14:16:11 -0700 | [diff] [blame^] | 144 | bool isCompositeJpegRDisabled, metadataGetter getMetadata, |
| 145 | const std::vector<std::string> &physicalCameraIds, |
Jayant Chowdhary | a04055f | 2022-01-03 02:07:49 +0000 | [diff] [blame] | 146 | aidl::android::hardware::camera::device::StreamConfiguration &streamConfiguration, |
| 147 | bool overrideForPerfClass, bool *earlyExit); |
| 148 | |
Austin Borger | ea93124 | 2021-12-13 23:10:41 +0000 | [diff] [blame] | 149 | StreamConfigurationPair getStreamConfigurationPair(const CameraMetadata &metadata); |
Jayant Chowdhary | 13f9b2f | 2020-12-02 22:46:15 -0800 | [diff] [blame] | 150 | |
Austin Borger | ea93124 | 2021-12-13 23:10:41 +0000 | [diff] [blame] | 151 | status_t checkAndOverrideSensorPixelModesUsed( |
| 152 | const std::vector<int32_t> &sensorPixelModesUsed, int format, int width, int height, |
Jayant Chowdhary | a80ad24 | 2023-03-17 00:49:47 +0000 | [diff] [blame] | 153 | const CameraMetadata &staticInfo, |
Austin Borger | ea93124 | 2021-12-13 23:10:41 +0000 | [diff] [blame] | 154 | std::unordered_set<int32_t> *overriddenSensorPixelModesUsed); |
Jayant Chowdhary | 13f9b2f | 2020-12-02 22:46:15 -0800 | [diff] [blame] | 155 | |
Austin Borger | ea93124 | 2021-12-13 23:10:41 +0000 | [diff] [blame] | 156 | bool targetPerfClassPrimaryCamera( |
| 157 | const std::set<std::string>& perfClassPrimaryCameraIds, const std::string& cameraId, |
| 158 | int32_t targetSdkVersion); |
Jayant Chowdhary | 13f9b2f | 2020-12-02 22:46:15 -0800 | [diff] [blame] | 159 | |
Austin Borger | ea93124 | 2021-12-13 23:10:41 +0000 | [diff] [blame] | 160 | constexpr int32_t MAX_SURFACES_PER_STREAM = 4; |
Shuzhen Wang | d4abdf7 | 2021-05-28 11:22:50 -0700 | [diff] [blame] | 161 | |
Austin Borger | ea93124 | 2021-12-13 23:10:41 +0000 | [diff] [blame] | 162 | constexpr int32_t ROUNDING_WIDTH_CAP = 1920; |
Colin Cross | b8a9dbb | 2020-08-27 04:12:26 +0000 | [diff] [blame] | 163 | |
Austin Borger | ea93124 | 2021-12-13 23:10:41 +0000 | [diff] [blame] | 164 | constexpr int32_t SDK_VERSION_S = 31; |
| 165 | extern int32_t PERF_CLASS_LEVEL; |
| 166 | extern bool IS_PERF_CLASS; |
| 167 | constexpr int32_t PERF_CLASS_JPEG_THRESH_W = 1920; |
| 168 | constexpr int32_t PERF_CLASS_JPEG_THRESH_H = 1080; |
Jayant Chowdhary | 13f9b2f | 2020-12-02 22:46:15 -0800 | [diff] [blame] | 169 | |
Austin Borger | ea93124 | 2021-12-13 23:10:41 +0000 | [diff] [blame] | 170 | } // SessionConfigurationUtils |
Jayant Chowdhary | 13f9b2f | 2020-12-02 22:46:15 -0800 | [diff] [blame] | 171 | } // camera3 |
Jayant Chowdhary | 2bbdce4 | 2020-01-12 14:55:41 -0800 | [diff] [blame] | 172 | } // android |
Austin Borger | ea93124 | 2021-12-13 23:10:41 +0000 | [diff] [blame] | 173 | |
Jayant Chowdhary | 2bbdce4 | 2020-01-12 14:55:41 -0800 | [diff] [blame] | 174 | #endif |