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> |
| 24 | #include <android/hardware/camera/device/3.4/ICameraDeviceSession.h> |
| 25 | |
Colin Cross | b8a9dbb | 2020-08-27 04:12:26 +0000 | [diff] [blame] | 26 | #include <hardware/camera3.h> |
| 27 | #include <device3/Camera3StreamInterface.h> |
| 28 | |
Jayant Chowdhary | 2bbdce4 | 2020-01-12 14:55:41 -0800 | [diff] [blame] | 29 | #include <stdint.h> |
| 30 | |
| 31 | namespace android { |
| 32 | |
| 33 | typedef std::function<CameraMetadata (const String8 &)> metadataGetter; |
| 34 | |
| 35 | class SessionConfigurationUtils { |
| 36 | public: |
Colin Cross | b8a9dbb | 2020-08-27 04:12:26 +0000 | [diff] [blame] | 37 | |
| 38 | static int64_t euclidDistSquare(int32_t x0, int32_t y0, int32_t x1, int32_t y1); |
| 39 | |
| 40 | // Find the closest dimensions for a given format in available stream configurations with |
| 41 | // a width <= ROUNDING_WIDTH_CAP |
| 42 | static bool roundBufferDimensionNearest(int32_t width, int32_t height, int32_t format, |
| 43 | android_dataspace dataSpace, const CameraMetadata& info, |
| 44 | /*out*/int32_t* outWidth, /*out*/int32_t* outHeight); |
| 45 | |
| 46 | //check if format is not custom format |
| 47 | static bool isPublicFormat(int32_t format); |
| 48 | |
| 49 | // Create a Surface from an IGraphicBufferProducer. Returns error if |
| 50 | // IGraphicBufferProducer's property doesn't match with streamInfo |
| 51 | static binder::Status createSurfaceFromGbp( |
| 52 | camera3::OutputStreamInfo& streamInfo, bool isStreamInfoValid, |
| 53 | sp<Surface>& surface, const sp<IGraphicBufferProducer>& gbp, |
| 54 | const String8 &cameraId, const CameraMetadata &physicalCameraMetadata); |
| 55 | |
| 56 | static void mapStreamInfo(const camera3::OutputStreamInfo &streamInfo, |
| 57 | camera3_stream_rotation_t rotation, String8 physicalId, |
| 58 | hardware::camera::device::V3_4::Stream *stream /*out*/); |
| 59 | |
| 60 | // Check that the physicalCameraId passed in is spported by the camera |
| 61 | // device. |
| 62 | static binder::Status checkPhysicalCameraId( |
| 63 | const std::vector<std::string> &physicalCameraIds, const String8 &physicalCameraId, |
| 64 | const String8 &logicalCameraId); |
| 65 | |
| 66 | static binder::Status checkSurfaceType(size_t numBufferProducers, |
| 67 | bool deferredConsumer, int surfaceType); |
| 68 | |
| 69 | static binder::Status checkOperatingMode(int operatingMode, |
| 70 | const CameraMetadata &staticInfo, const String8 &cameraId); |
| 71 | |
Jayant Chowdhary | 2bbdce4 | 2020-01-12 14:55:41 -0800 | [diff] [blame] | 72 | // utility function to convert AIDL SessionConfiguration to HIDL |
Eino-Ville Talvala | 0bdfa28 | 2020-06-19 13:54:35 -0700 | [diff] [blame] | 73 | // streamConfiguration. Also checks for validity of SessionConfiguration and |
Jayant Chowdhary | 2bbdce4 | 2020-01-12 14:55:41 -0800 | [diff] [blame] | 74 | // returns a non-ok binder::Status if the passed in session configuration |
| 75 | // isn't valid. |
| 76 | static binder::Status |
| 77 | convertToHALStreamCombination(const SessionConfiguration& sessionConfiguration, |
| 78 | const String8 &cameraId, const CameraMetadata &deviceInfo, |
| 79 | metadataGetter getMetadata, const std::vector<std::string> &physicalCameraIds, |
| 80 | hardware::camera::device::V3_4::StreamConfiguration &streamConfiguration, |
| 81 | bool *earlyExit); |
Colin Cross | b8a9dbb | 2020-08-27 04:12:26 +0000 | [diff] [blame] | 82 | |
| 83 | static const int32_t MAX_SURFACES_PER_STREAM = 4; |
| 84 | |
| 85 | static const int32_t ROUNDING_WIDTH_CAP = 1920; |
Jayant Chowdhary | 2bbdce4 | 2020-01-12 14:55:41 -0800 | [diff] [blame] | 86 | }; |
| 87 | |
| 88 | } // android |
| 89 | #endif |