blob: 8dfc11dca368850646512100a83ec61712d972c8 [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>
Shuzhen Wang90708ea2021-11-04 11:40:49 -070024#include <android/hardware/camera/device/3.8/types.h>
Jayant Chowdhary13f9b2f2020-12-02 22:46:15 -080025#include <android/hardware/camera/device/3.4/ICameraDeviceSession.h>
26#include <android/hardware/camera/device/3.7/ICameraDeviceSession.h>
Emilian Peev2295df72021-11-12 18:14:10 -080027#include <android/hardware/camera/device/3.8/ICameraDeviceSession.h>
Jayant Chowdhary2bbdce42020-01-12 14:55:41 -080028
Colin Crossb8a9dbb2020-08-27 04:12:26 +000029#include <device3/Camera3StreamInterface.h>
30
Shuzhen Wangd4abdf72021-05-28 11:22:50 -070031#include <set>
Jayant Chowdhary2bbdce42020-01-12 14:55:41 -080032#include <stdint.h>
33
Austin Borgerea931242021-12-13 23:10:41 +000034#include "SessionConfigurationUtilsHost.h"
35
Jayant Chowdhary13f9b2f2020-12-02 22:46:15 -080036// 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 Chowdhary2bbdce42020-01-12 14:55:41 -080047namespace android {
Jayant Chowdhary13f9b2f2020-12-02 22:46:15 -080048namespace camera3 {
Jayant Chowdhary2bbdce42020-01-12 14:55:41 -080049
Shuzhen Wangd4abdf72021-05-28 11:22:50 -070050typedef std::function<CameraMetadata (const String8 &, int targetSdkVersion)> metadataGetter;
Jayant Chowdhary2bbdce42020-01-12 14:55:41 -080051
Jayant Chowdhary13f9b2f2020-12-02 22:46:15 -080052class StreamConfiguration {
53public:
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.
68struct 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 Borgerea931242021-12-13 23:10:41 +000075namespace SessionConfigurationUtils {
Jayant Chowdharycd3d36b2021-07-10 10:53:53 -070076
Austin Borgerea931242021-12-13 23:10:41 +000077camera3::Size getMaxJpegResolution(const CameraMetadata &metadata,
78 bool ultraHighResolution);
Jayant Chowdharycd3d36b2021-07-10 10:53:53 -070079
Austin Borgerea931242021-12-13 23:10:41 +000080size_t getUHRMaxJpegBufferSize(camera3::Size uhrMaxJpegSize,
81 camera3::Size defaultMaxJpegSize, size_t defaultMaxJpegBufferSize);
Colin Crossb8a9dbb2020-08-27 04:12:26 +000082
Austin Borgerea931242021-12-13 23:10:41 +000083int64_t euclidDistSquare(int32_t x0, int32_t y0, int32_t x1, int32_t y1);
Colin Crossb8a9dbb2020-08-27 04:12:26 +000084
Austin Borgerea931242021-12-13 23:10:41 +000085// Find the closest dimensions for a given format in available stream configurations with
86// a width <= ROUNDING_WIDTH_CAP
87bool 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 Chowdhary9255ce02021-07-15 11:18:17 -070090
Austin Borgerea931242021-12-13 23:10:41 +000091// check if format is not custom format
92bool isPublicFormat(int32_t format);
Colin Crossb8a9dbb2020-08-27 04:12:26 +000093
Austin Borgerea931242021-12-13 23:10:41 +000094// Create a Surface from an IGraphicBufferProducer. Returns error if
95// IGraphicBufferProducer's property doesn't match with streamInfo
96binder::Status createSurfaceFromGbp(
Shuzhen Wangc8ab4522021-12-14 20:12:42 -080097 camera3::OutputStreamInfo& streamInfo, bool isStreamInfoValid,
98 sp<Surface>& surface, const sp<IGraphicBufferProducer>& gbp,
99 const String8 &logicalCameraId, const CameraMetadata &physicalCameraMetadata,
100 const std::vector<int32_t> &sensorPixelModesUsed, int dynamicRangeProfile,
101 int streamUseCase);
102
Austin Borgerea931242021-12-13 23:10:41 +0000103void mapStreamInfo(const camera3::OutputStreamInfo &streamInfo,
104 camera3::camera_stream_rotation_t rotation, String8 physicalId, int32_t groupId,
Shuzhen Wangc8ab4522021-12-14 20:12:42 -0800105 hardware::camera::device::V3_8::Stream *stream /*out*/);
Colin Crossb8a9dbb2020-08-27 04:12:26 +0000106
Emilian Peev2295df72021-11-12 18:14:10 -0800107//check if format is 10-bit output compatible
108bool is10bitCompatibleFormat(int32_t format);
109
110// check if the dynamic range requires 10-bit output
111bool is10bitDynamicRangeProfile(int32_t dynamicRangeProfile);
112
113// Check if the device supports a given dynamicRangeProfile
114bool isDynamicRangeProfileSupported(int dynamicRangeProfile, const CameraMetadata& staticMeta);
115
Shuzhen Wangc8ab4522021-12-14 20:12:42 -0800116bool isStreamUseCaseSupported(int streamUseCase, const CameraMetadata &deviceInfo);
117
Austin Borgerea931242021-12-13 23:10:41 +0000118// Check that the physicalCameraId passed in is spported by the camera
119// device.
120binder::Status checkPhysicalCameraId(
121const std::vector<std::string> &physicalCameraIds, const String8 &physicalCameraId,
122const String8 &logicalCameraId);
Colin Crossb8a9dbb2020-08-27 04:12:26 +0000123
Austin Borgerea931242021-12-13 23:10:41 +0000124binder::Status checkSurfaceType(size_t numBufferProducers,
125bool deferredConsumer, int surfaceType);
Colin Crossb8a9dbb2020-08-27 04:12:26 +0000126
Austin Borgerea931242021-12-13 23:10:41 +0000127binder::Status checkOperatingMode(int operatingMode,
128const CameraMetadata &staticInfo, const String8 &cameraId);
Colin Crossb8a9dbb2020-08-27 04:12:26 +0000129
Austin Borgerea931242021-12-13 23:10:41 +0000130// utility function to convert AIDL SessionConfiguration to HIDL
131// streamConfiguration. Also checks for validity of SessionConfiguration and
132// returns a non-ok binder::Status if the passed in session configuration
133// isn't valid.
134binder::Status
135convertToHALStreamCombination(const SessionConfiguration& sessionConfiguration,
136 const String8 &cameraId, const CameraMetadata &deviceInfo,
137 metadataGetter getMetadata, const std::vector<std::string> &physicalCameraIds,
Emilian Peev2295df72021-11-12 18:14:10 -0800138 hardware::camera::device::V3_8::StreamConfiguration &streamConfiguration,
Austin Borgerea931242021-12-13 23:10:41 +0000139 bool overrideForPerfClass, bool *earlyExit);
Shuzhen Wang83bff122020-11-20 15:51:39 -0800140
Emilian Peev2295df72021-11-12 18:14:10 -0800141// Utility function to convert a V3_8::StreamConfiguration to
142// V3_7::StreamConfiguration. Return false if the original V3_8 configuration cannot
143// be used by older version HAL.
144bool convertHALStreamCombinationFromV38ToV37(
Greg Kaiser5639fc92022-01-20 06:58:28 -0800145 hardware::camera::device::V3_7::StreamConfiguration &streamConfigV37,
146 const hardware::camera::device::V3_8::StreamConfiguration &streamConfigV38);
Emilian Peev2295df72021-11-12 18:14:10 -0800147
Austin Borgerea931242021-12-13 23:10:41 +0000148// Utility function to convert a V3_7::StreamConfiguration to
149// V3_4::StreamConfiguration. Return false if the original V3_7 configuration cannot
150// be used by older version HAL.
151bool convertHALStreamCombinationFromV37ToV34(
152 hardware::camera::device::V3_4::StreamConfiguration &streamConfigV34,
153 const hardware::camera::device::V3_7::StreamConfiguration &streamConfigV37);
Jayant Chowdhary13f9b2f2020-12-02 22:46:15 -0800154
Austin Borgerea931242021-12-13 23:10:41 +0000155StreamConfigurationPair getStreamConfigurationPair(const CameraMetadata &metadata);
Jayant Chowdhary13f9b2f2020-12-02 22:46:15 -0800156
Austin Borgerea931242021-12-13 23:10:41 +0000157status_t checkAndOverrideSensorPixelModesUsed(
158 const std::vector<int32_t> &sensorPixelModesUsed, int format, int width, int height,
159 const CameraMetadata &staticInfo, bool flexibleConsumer,
160 std::unordered_set<int32_t> *overriddenSensorPixelModesUsed);
Jayant Chowdhary13f9b2f2020-12-02 22:46:15 -0800161
Austin Borgerea931242021-12-13 23:10:41 +0000162bool targetPerfClassPrimaryCamera(
163 const std::set<std::string>& perfClassPrimaryCameraIds, const std::string& cameraId,
164 int32_t targetSdkVersion);
Jayant Chowdhary13f9b2f2020-12-02 22:46:15 -0800165
Austin Borgerea931242021-12-13 23:10:41 +0000166constexpr int32_t MAX_SURFACES_PER_STREAM = 4;
Shuzhen Wangd4abdf72021-05-28 11:22:50 -0700167
Austin Borgerea931242021-12-13 23:10:41 +0000168constexpr int32_t ROUNDING_WIDTH_CAP = 1920;
Colin Crossb8a9dbb2020-08-27 04:12:26 +0000169
Austin Borgerea931242021-12-13 23:10:41 +0000170constexpr int32_t SDK_VERSION_S = 31;
171extern int32_t PERF_CLASS_LEVEL;
172extern bool IS_PERF_CLASS;
173constexpr int32_t PERF_CLASS_JPEG_THRESH_W = 1920;
174constexpr int32_t PERF_CLASS_JPEG_THRESH_H = 1080;
Jayant Chowdhary13f9b2f2020-12-02 22:46:15 -0800175
Austin Borgerea931242021-12-13 23:10:41 +0000176} // SessionConfigurationUtils
Jayant Chowdhary13f9b2f2020-12-02 22:46:15 -0800177} // camera3
Jayant Chowdhary2bbdce42020-01-12 14:55:41 -0800178} // android
Austin Borgerea931242021-12-13 23:10:41 +0000179
Jayant Chowdhary2bbdce42020-01-12 14:55:41 -0800180#endif