blob: b5654acf452955696ae6c6ba03f280b2b276c57e [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>
Jayant Chowdharya04055f2022-01-03 02:07:49 +000024#include <aidl/android/hardware/camera/device/ICameraDevice.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>
Jayant Chowdhary2bbdce42020-01-12 14:55:41 -080027
Colin Crossb8a9dbb2020-08-27 04:12:26 +000028#include <device3/Camera3StreamInterface.h>
Jayant Chowdharyc67af1b2022-04-07 18:05:04 +000029#include <utils/IPCTransport.h>
Colin Crossb8a9dbb2020-08-27 04:12:26 +000030
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 Wanga79a64d2022-04-24 19:56:30 -070050typedef std::function<CameraMetadata (const String8 &, bool overrideForPerfClass)> 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,
Emilian Peevc81a7592022-02-14 17:38:18 -0800100 const std::vector<int32_t> &sensorPixelModesUsed, int64_t dynamicRangeProfile,
Austin Borger9e2b27c2022-07-15 11:27:24 -0700101 int64_t streamUseCase, int timestampBase, int mirrorMode,
102 int32_t colorSpace);
Shuzhen Wangc8ab4522021-12-14 20:12:42 -0800103
Emilian Peev2295df72021-11-12 18:14:10 -0800104//check if format is 10-bit output compatible
Emilian Peev434248e2022-10-06 14:58:54 -0700105bool is10bitCompatibleFormat(int32_t format, android_dataspace_t dataSpace);
Emilian Peev2295df72021-11-12 18:14:10 -0800106
107// check if the dynamic range requires 10-bit output
Emilian Peevc81a7592022-02-14 17:38:18 -0800108bool is10bitDynamicRangeProfile(int64_t dynamicRangeProfile);
Emilian Peev2295df72021-11-12 18:14:10 -0800109
110// Check if the device supports a given dynamicRangeProfile
Emilian Peevc81a7592022-02-14 17:38:18 -0800111bool isDynamicRangeProfileSupported(int64_t dynamicRangeProfile, const CameraMetadata& staticMeta);
Emilian Peev2295df72021-11-12 18:14:10 -0800112
Austin Borger9e2b27c2022-07-15 11:27:24 -0700113bool deviceReportsColorSpaces(const CameraMetadata& staticMeta);
114
115bool isColorSpaceSupported(int32_t colorSpace, int32_t format, android_dataspace dataSpace,
116 int64_t dynamicRangeProfile, const CameraMetadata& staticMeta);
117
Shuzhen Wang8ed1e872022-03-08 16:34:33 -0800118bool isStreamUseCaseSupported(int64_t streamUseCase, const CameraMetadata &deviceInfo);
Shuzhen Wangc8ab4522021-12-14 20:12:42 -0800119
Jayant Chowdharya04055f2022-01-03 02:07:49 +0000120void 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 Borgerea931242021-12-13 23:10:41 +0000124// Check that the physicalCameraId passed in is spported by the camera
125// device.
126binder::Status checkPhysicalCameraId(
127const std::vector<std::string> &physicalCameraIds, const String8 &physicalCameraId,
128const String8 &logicalCameraId);
Colin Crossb8a9dbb2020-08-27 04:12:26 +0000129
Austin Borgerea931242021-12-13 23:10:41 +0000130binder::Status checkSurfaceType(size_t numBufferProducers,
131bool deferredConsumer, int surfaceType);
Colin Crossb8a9dbb2020-08-27 04:12:26 +0000132
Austin Borgerea931242021-12-13 23:10:41 +0000133binder::Status checkOperatingMode(int operatingMode,
134const CameraMetadata &staticInfo, const String8 &cameraId);
Colin Crossb8a9dbb2020-08-27 04:12:26 +0000135
Jayant Chowdharya04055f2022-01-03 02:07:49 +0000136binder::Status
137convertToHALStreamCombination(
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 Borgerea931242021-12-13 23:10:41 +0000144StreamConfigurationPair getStreamConfigurationPair(const CameraMetadata &metadata);
Jayant Chowdhary13f9b2f2020-12-02 22:46:15 -0800145
Austin Borgerea931242021-12-13 23:10:41 +0000146status_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 Chowdhary13f9b2f2020-12-02 22:46:15 -0800150
Austin Borgerea931242021-12-13 23:10:41 +0000151bool targetPerfClassPrimaryCamera(
152 const std::set<std::string>& perfClassPrimaryCameraIds, const std::string& cameraId,
153 int32_t targetSdkVersion);
Jayant Chowdhary13f9b2f2020-12-02 22:46:15 -0800154
Austin Borgerea931242021-12-13 23:10:41 +0000155constexpr int32_t MAX_SURFACES_PER_STREAM = 4;
Shuzhen Wangd4abdf72021-05-28 11:22:50 -0700156
Austin Borgerea931242021-12-13 23:10:41 +0000157constexpr int32_t ROUNDING_WIDTH_CAP = 1920;
Colin Crossb8a9dbb2020-08-27 04:12:26 +0000158
Austin Borgerea931242021-12-13 23:10:41 +0000159constexpr int32_t SDK_VERSION_S = 31;
160extern int32_t PERF_CLASS_LEVEL;
161extern bool IS_PERF_CLASS;
162constexpr int32_t PERF_CLASS_JPEG_THRESH_W = 1920;
163constexpr int32_t PERF_CLASS_JPEG_THRESH_H = 1080;
Jayant Chowdhary13f9b2f2020-12-02 22:46:15 -0800164
Austin Borgerea931242021-12-13 23:10:41 +0000165} // SessionConfigurationUtils
Jayant Chowdhary13f9b2f2020-12-02 22:46:15 -0800166} // camera3
Jayant Chowdhary2bbdce42020-01-12 14:55:41 -0800167} // android
Austin Borgerea931242021-12-13 23:10:41 +0000168
Jayant Chowdhary2bbdce42020-01-12 14:55:41 -0800169#endif