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> |
Shuzhen Wang | 90708ea | 2021-11-04 11:40:49 -0700 | [diff] [blame] | 24 | #include <android/hardware/camera/device/3.8/types.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> |
Emilian Peev | 2295df7 | 2021-11-12 18:14:10 -0800 | [diff] [blame] | 27 | #include <android/hardware/camera/device/3.8/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> |
| 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 | d4abdf7 | 2021-05-28 11:22:50 -0700 | [diff] [blame] | 50 | typedef std::function<CameraMetadata (const String8 &, int targetSdkVersion)> 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( |
| 97 | camera3::OutputStreamInfo& streamInfo, bool isStreamInfoValid, |
| 98 | sp<Surface>& surface, const sp<IGraphicBufferProducer>& gbp, |
| 99 | const String8 &logicalCameraId, const CameraMetadata &physicalCameraMetadata, |
Emilian Peev | 2295df7 | 2021-11-12 18:14:10 -0800 | [diff] [blame] | 100 | const std::vector<int32_t> &sensorPixelModesUsed, int dynamicRangeProfile); |
Austin Borger | ea93124 | 2021-12-13 23:10:41 +0000 | [diff] [blame] | 101 | void mapStreamInfo(const camera3::OutputStreamInfo &streamInfo, |
| 102 | camera3::camera_stream_rotation_t rotation, String8 physicalId, int32_t groupId, |
| 103 | hardware::camera::device::V3_7::Stream *stream /*out*/); |
Colin Cross | b8a9dbb | 2020-08-27 04:12:26 +0000 | [diff] [blame] | 104 | |
Emilian Peev | 2295df7 | 2021-11-12 18:14:10 -0800 | [diff] [blame] | 105 | //check if format is 10-bit output compatible |
| 106 | bool is10bitCompatibleFormat(int32_t format); |
| 107 | |
| 108 | // check if the dynamic range requires 10-bit output |
| 109 | bool is10bitDynamicRangeProfile(int32_t dynamicRangeProfile); |
| 110 | |
| 111 | // Check if the device supports a given dynamicRangeProfile |
| 112 | bool isDynamicRangeProfileSupported(int dynamicRangeProfile, const CameraMetadata& staticMeta); |
| 113 | |
Austin Borger | ea93124 | 2021-12-13 23:10:41 +0000 | [diff] [blame] | 114 | // Check that the physicalCameraId passed in is spported by the camera |
| 115 | // device. |
| 116 | binder::Status checkPhysicalCameraId( |
| 117 | const std::vector<std::string> &physicalCameraIds, const String8 &physicalCameraId, |
| 118 | const String8 &logicalCameraId); |
Colin Cross | b8a9dbb | 2020-08-27 04:12:26 +0000 | [diff] [blame] | 119 | |
Austin Borger | ea93124 | 2021-12-13 23:10:41 +0000 | [diff] [blame] | 120 | binder::Status checkSurfaceType(size_t numBufferProducers, |
| 121 | bool deferredConsumer, int surfaceType); |
Colin Cross | b8a9dbb | 2020-08-27 04:12:26 +0000 | [diff] [blame] | 122 | |
Austin Borger | ea93124 | 2021-12-13 23:10:41 +0000 | [diff] [blame] | 123 | binder::Status checkOperatingMode(int operatingMode, |
| 124 | const CameraMetadata &staticInfo, const String8 &cameraId); |
Colin Cross | b8a9dbb | 2020-08-27 04:12:26 +0000 | [diff] [blame] | 125 | |
Austin Borger | ea93124 | 2021-12-13 23:10:41 +0000 | [diff] [blame] | 126 | // utility function to convert AIDL SessionConfiguration to HIDL |
| 127 | // streamConfiguration. Also checks for validity of SessionConfiguration and |
| 128 | // returns a non-ok binder::Status if the passed in session configuration |
| 129 | // isn't valid. |
| 130 | binder::Status |
| 131 | convertToHALStreamCombination(const SessionConfiguration& sessionConfiguration, |
| 132 | const String8 &cameraId, const CameraMetadata &deviceInfo, |
| 133 | metadataGetter getMetadata, const std::vector<std::string> &physicalCameraIds, |
Emilian Peev | 2295df7 | 2021-11-12 18:14:10 -0800 | [diff] [blame] | 134 | hardware::camera::device::V3_8::StreamConfiguration &streamConfiguration, |
Austin Borger | ea93124 | 2021-12-13 23:10:41 +0000 | [diff] [blame] | 135 | bool overrideForPerfClass, bool *earlyExit); |
Shuzhen Wang | 83bff12 | 2020-11-20 15:51:39 -0800 | [diff] [blame] | 136 | |
Emilian Peev | 2295df7 | 2021-11-12 18:14:10 -0800 | [diff] [blame] | 137 | // Utility function to convert a V3_8::StreamConfiguration to |
| 138 | // V3_7::StreamConfiguration. Return false if the original V3_8 configuration cannot |
| 139 | // be used by older version HAL. |
| 140 | bool convertHALStreamCombinationFromV38ToV37( |
Greg Kaiser | 5639fc9 | 2022-01-20 06:58:28 -0800 | [diff] [blame] | 141 | hardware::camera::device::V3_7::StreamConfiguration &streamConfigV37, |
| 142 | const hardware::camera::device::V3_8::StreamConfiguration &streamConfigV38); |
Emilian Peev | 2295df7 | 2021-11-12 18:14:10 -0800 | [diff] [blame] | 143 | |
Austin Borger | ea93124 | 2021-12-13 23:10:41 +0000 | [diff] [blame] | 144 | // Utility function to convert a V3_7::StreamConfiguration to |
| 145 | // V3_4::StreamConfiguration. Return false if the original V3_7 configuration cannot |
| 146 | // be used by older version HAL. |
| 147 | bool convertHALStreamCombinationFromV37ToV34( |
| 148 | hardware::camera::device::V3_4::StreamConfiguration &streamConfigV34, |
| 149 | const hardware::camera::device::V3_7::StreamConfiguration &streamConfigV37); |
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 | StreamConfigurationPair getStreamConfigurationPair(const CameraMetadata &metadata); |
Jayant Chowdhary | 13f9b2f | 2020-12-02 22:46:15 -0800 | [diff] [blame] | 152 | |
Austin Borger | ea93124 | 2021-12-13 23:10:41 +0000 | [diff] [blame] | 153 | status_t checkAndOverrideSensorPixelModesUsed( |
| 154 | const std::vector<int32_t> &sensorPixelModesUsed, int format, int width, int height, |
| 155 | const CameraMetadata &staticInfo, bool flexibleConsumer, |
| 156 | std::unordered_set<int32_t> *overriddenSensorPixelModesUsed); |
Jayant Chowdhary | 13f9b2f | 2020-12-02 22:46:15 -0800 | [diff] [blame] | 157 | |
Austin Borger | ea93124 | 2021-12-13 23:10:41 +0000 | [diff] [blame] | 158 | bool targetPerfClassPrimaryCamera( |
| 159 | const std::set<std::string>& perfClassPrimaryCameraIds, const std::string& cameraId, |
| 160 | int32_t targetSdkVersion); |
Jayant Chowdhary | 13f9b2f | 2020-12-02 22:46:15 -0800 | [diff] [blame] | 161 | |
Austin Borger | ea93124 | 2021-12-13 23:10:41 +0000 | [diff] [blame] | 162 | constexpr int32_t MAX_SURFACES_PER_STREAM = 4; |
Shuzhen Wang | d4abdf7 | 2021-05-28 11:22:50 -0700 | [diff] [blame] | 163 | |
Austin Borger | ea93124 | 2021-12-13 23:10:41 +0000 | [diff] [blame] | 164 | constexpr int32_t ROUNDING_WIDTH_CAP = 1920; |
Colin Cross | b8a9dbb | 2020-08-27 04:12:26 +0000 | [diff] [blame] | 165 | |
Austin Borger | ea93124 | 2021-12-13 23:10:41 +0000 | [diff] [blame] | 166 | constexpr int32_t SDK_VERSION_S = 31; |
| 167 | extern int32_t PERF_CLASS_LEVEL; |
| 168 | extern bool IS_PERF_CLASS; |
| 169 | constexpr int32_t PERF_CLASS_JPEG_THRESH_W = 1920; |
| 170 | constexpr int32_t PERF_CLASS_JPEG_THRESH_H = 1080; |
Jayant Chowdhary | 13f9b2f | 2020-12-02 22:46:15 -0800 | [diff] [blame] | 171 | |
Austin Borger | ea93124 | 2021-12-13 23:10:41 +0000 | [diff] [blame] | 172 | } // SessionConfigurationUtils |
Jayant Chowdhary | 13f9b2f | 2020-12-02 22:46:15 -0800 | [diff] [blame] | 173 | } // camera3 |
Jayant Chowdhary | 2bbdce4 | 2020-01-12 14:55:41 -0800 | [diff] [blame] | 174 | } // android |
Austin Borger | ea93124 | 2021-12-13 23:10:41 +0000 | [diff] [blame] | 175 | |
Jayant Chowdhary | 2bbdce4 | 2020-01-12 14:55:41 -0800 | [diff] [blame] | 176 | #endif |