blob: 220d1f8183418b3ff8e46ed5e03a04a53fe39814 [file] [log] [blame]
Jayant Chowdhary2bbdce42020-01-12 14:55:41 -08001/*
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 Borger0fb3ad92023-06-01 16:51:35 -070024#include <camera/StringUtils.h>
Jayant Chowdharya04055f2022-01-03 02:07:49 +000025#include <aidl/android/hardware/camera/device/ICameraDevice.h>
Jayant Chowdhary13f9b2f2020-12-02 22:46:15 -080026#include <android/hardware/camera/device/3.4/ICameraDeviceSession.h>
27#include <android/hardware/camera/device/3.7/ICameraDeviceSession.h>
Jayant Chowdhary2bbdce42020-01-12 14:55:41 -080028
Colin Crossb8a9dbb2020-08-27 04:12:26 +000029#include <device3/Camera3StreamInterface.h>
Jayant Chowdharyc67af1b2022-04-07 18:05:04 +000030#include <utils/IPCTransport.h>
Colin Crossb8a9dbb2020-08-27 04:12:26 +000031
Shuzhen Wangd4abdf72021-05-28 11:22:50 -070032#include <set>
Jayant Chowdhary2bbdce42020-01-12 14:55:41 -080033#include <stdint.h>
34
Austin Borgerea931242021-12-13 23:10:41 +000035#include "SessionConfigurationUtilsHost.h"
36
Jayant Chowdhary13f9b2f2020-12-02 22:46:15 -080037// Convenience methods for constructing binder::Status objects for error returns
38
39#define STATUS_ERROR(errorCode, errorString) \
40 binder::Status::fromServiceSpecificError(errorCode, \
Austin Borger0fb3ad92023-06-01 16:51:35 -070041 fmt::sprintf("%s:%d: %s", __FUNCTION__, __LINE__, errorString).c_str())
Jayant Chowdhary13f9b2f2020-12-02 22:46:15 -080042
43#define STATUS_ERROR_FMT(errorCode, errorString, ...) \
44 binder::Status::fromServiceSpecificError(errorCode, \
Austin Borger0fb3ad92023-06-01 16:51:35 -070045 fmt::sprintf("%s:%d: " errorString, __FUNCTION__, __LINE__, \
46 __VA_ARGS__).c_str())
Jayant Chowdhary13f9b2f2020-12-02 22:46:15 -080047
Jayant Chowdhary2bbdce42020-01-12 14:55:41 -080048namespace android {
Jayant Chowdhary13f9b2f2020-12-02 22:46:15 -080049namespace camera3 {
Jayant Chowdhary2bbdce42020-01-12 14:55:41 -080050
Austin Borger0fb3ad92023-06-01 16:51:35 -070051typedef std::function<CameraMetadata (const std::string &, bool overrideForPerfClass)>
52 metadataGetter;
Jayant Chowdhary2bbdce42020-01-12 14:55:41 -080053
Jayant Chowdhary13f9b2f2020-12-02 22:46:15 -080054class StreamConfiguration {
55public:
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.
70struct 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 Borgerea931242021-12-13 23:10:41 +000077namespace SessionConfigurationUtils {
Jayant Chowdharycd3d36b2021-07-10 10:53:53 -070078
Austin Borgerea931242021-12-13 23:10:41 +000079camera3::Size getMaxJpegResolution(const CameraMetadata &metadata,
80 bool ultraHighResolution);
Jayant Chowdharycd3d36b2021-07-10 10:53:53 -070081
Austin Borgerea931242021-12-13 23:10:41 +000082size_t getUHRMaxJpegBufferSize(camera3::Size uhrMaxJpegSize,
83 camera3::Size defaultMaxJpegSize, size_t defaultMaxJpegBufferSize);
Colin Crossb8a9dbb2020-08-27 04:12:26 +000084
Austin Borgerea931242021-12-13 23:10:41 +000085int64_t euclidDistSquare(int32_t x0, int32_t y0, int32_t x1, int32_t y1);
Colin Crossb8a9dbb2020-08-27 04:12:26 +000086
Austin Borgerea931242021-12-13 23:10:41 +000087// Find the closest dimensions for a given format in available stream configurations with
88// a width <= ROUNDING_WIDTH_CAP
89bool 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 Chowdhary9255ce02021-07-15 11:18:17 -070092
Austin Borgerea931242021-12-13 23:10:41 +000093// check if format is not custom format
94bool isPublicFormat(int32_t format);
Colin Crossb8a9dbb2020-08-27 04:12:26 +000095
Austin Borgerea931242021-12-13 23:10:41 +000096// Create a Surface from an IGraphicBufferProducer. Returns error if
97// IGraphicBufferProducer's property doesn't match with streamInfo
98binder::Status createSurfaceFromGbp(
Shuzhen Wangc8ab4522021-12-14 20:12:42 -080099 camera3::OutputStreamInfo& streamInfo, bool isStreamInfoValid,
100 sp<Surface>& surface, const sp<IGraphicBufferProducer>& gbp,
Austin Borger0fb3ad92023-06-01 16:51:35 -0700101 const std::string &logicalCameraId, const CameraMetadata &physicalCameraMetadata,
Emilian Peevc81a7592022-02-14 17:38:18 -0800102 const std::vector<int32_t> &sensorPixelModesUsed, int64_t dynamicRangeProfile,
Shuzhen Wang8ed1e872022-03-08 16:34:33 -0800103 int64_t streamUseCase, int timestampBase, int mirrorMode);
Shuzhen Wangc8ab4522021-12-14 20:12:42 -0800104
Emilian Peev2295df72021-11-12 18:14:10 -0800105//check if format is 10-bit output compatible
106bool is10bitCompatibleFormat(int32_t format);
107
108// check if the dynamic range requires 10-bit output
Emilian Peevc81a7592022-02-14 17:38:18 -0800109bool is10bitDynamicRangeProfile(int64_t dynamicRangeProfile);
Emilian Peev2295df72021-11-12 18:14:10 -0800110
111// Check if the device supports a given dynamicRangeProfile
Emilian Peevc81a7592022-02-14 17:38:18 -0800112bool isDynamicRangeProfileSupported(int64_t dynamicRangeProfile, const CameraMetadata& staticMeta);
Emilian Peev2295df72021-11-12 18:14:10 -0800113
Shuzhen Wang8ed1e872022-03-08 16:34:33 -0800114bool isStreamUseCaseSupported(int64_t streamUseCase, const CameraMetadata &deviceInfo);
Shuzhen Wangc8ab4522021-12-14 20:12:42 -0800115
Jayant Chowdharya04055f2022-01-03 02:07:49 +0000116void mapStreamInfo(const OutputStreamInfo &streamInfo,
Austin Borger0fb3ad92023-06-01 16:51:35 -0700117 camera3::camera_stream_rotation_t rotation, const std::string &physicalId,
Jayant Chowdharya04055f2022-01-03 02:07:49 +0000118 int32_t groupId, aidl::android::hardware::camera::device::Stream *stream /*out*/);
119
Austin Borgerea931242021-12-13 23:10:41 +0000120// Check that the physicalCameraId passed in is spported by the camera
121// device.
122binder::Status checkPhysicalCameraId(
Austin Borger0fb3ad92023-06-01 16:51:35 -0700123const std::vector<std::string> &physicalCameraIds, const std::string &physicalCameraId,
124const std::string &logicalCameraId);
Colin Crossb8a9dbb2020-08-27 04:12:26 +0000125
Austin Borgerea931242021-12-13 23:10:41 +0000126binder::Status checkSurfaceType(size_t numBufferProducers,
127bool deferredConsumer, int surfaceType);
Colin Crossb8a9dbb2020-08-27 04:12:26 +0000128
Austin Borgerea931242021-12-13 23:10:41 +0000129binder::Status checkOperatingMode(int operatingMode,
Austin Borger0fb3ad92023-06-01 16:51:35 -0700130const CameraMetadata &staticInfo, const std::string &cameraId);
Colin Crossb8a9dbb2020-08-27 04:12:26 +0000131
Jayant Chowdharya04055f2022-01-03 02:07:49 +0000132binder::Status
133convertToHALStreamCombination(
134 const SessionConfiguration& sessionConfiguration,
Austin Borger0fb3ad92023-06-01 16:51:35 -0700135 const std::string &logicalCameraId, const CameraMetadata &deviceInfo,
Jayant Chowdharya04055f2022-01-03 02:07:49 +0000136 metadataGetter getMetadata, const std::vector<std::string> &physicalCameraIds,
137 aidl::android::hardware::camera::device::StreamConfiguration &streamConfiguration,
138 bool overrideForPerfClass, bool *earlyExit);
139
Austin Borgerea931242021-12-13 23:10:41 +0000140StreamConfigurationPair getStreamConfigurationPair(const CameraMetadata &metadata);
Jayant Chowdhary13f9b2f2020-12-02 22:46:15 -0800141
Austin Borgerea931242021-12-13 23:10:41 +0000142status_t checkAndOverrideSensorPixelModesUsed(
143 const std::vector<int32_t> &sensorPixelModesUsed, int format, int width, int height,
144 const CameraMetadata &staticInfo, bool flexibleConsumer,
145 std::unordered_set<int32_t> *overriddenSensorPixelModesUsed);
Jayant Chowdhary13f9b2f2020-12-02 22:46:15 -0800146
Austin Borgerea931242021-12-13 23:10:41 +0000147bool targetPerfClassPrimaryCamera(
148 const std::set<std::string>& perfClassPrimaryCameraIds, const std::string& cameraId,
149 int32_t targetSdkVersion);
Jayant Chowdhary13f9b2f2020-12-02 22:46:15 -0800150
Austin Borgerea931242021-12-13 23:10:41 +0000151constexpr int32_t MAX_SURFACES_PER_STREAM = 4;
Shuzhen Wangd4abdf72021-05-28 11:22:50 -0700152
Austin Borgerea931242021-12-13 23:10:41 +0000153constexpr int32_t ROUNDING_WIDTH_CAP = 1920;
Colin Crossb8a9dbb2020-08-27 04:12:26 +0000154
Austin Borgerea931242021-12-13 23:10:41 +0000155constexpr int32_t SDK_VERSION_S = 31;
156extern int32_t PERF_CLASS_LEVEL;
157extern bool IS_PERF_CLASS;
158constexpr int32_t PERF_CLASS_JPEG_THRESH_W = 1920;
159constexpr int32_t PERF_CLASS_JPEG_THRESH_H = 1080;
Jayant Chowdhary13f9b2f2020-12-02 22:46:15 -0800160
Austin Borgerea931242021-12-13 23:10:41 +0000161} // SessionConfigurationUtils
Jayant Chowdhary13f9b2f2020-12-02 22:46:15 -0800162} // camera3
Jayant Chowdhary2bbdce42020-01-12 14:55:41 -0800163} // android
Austin Borgerea931242021-12-13 23:10:41 +0000164
Jayant Chowdhary2bbdce42020-01-12 14:55:41 -0800165#endif