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