blob: a127c7bdcb7e5a3fd22e470935241b49fb4f671f [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,
Shuzhen Wang8ed1e872022-03-08 16:34:33 -0800101 int64_t streamUseCase, int timestampBase, int mirrorMode);
Shuzhen Wangc8ab4522021-12-14 20:12:42 -0800102
Emilian Peev2295df72021-11-12 18:14:10 -0800103//check if format is 10-bit output compatible
104bool is10bitCompatibleFormat(int32_t format);
105
106// check if the dynamic range requires 10-bit output
Emilian Peevc81a7592022-02-14 17:38:18 -0800107bool is10bitDynamicRangeProfile(int64_t dynamicRangeProfile);
Emilian Peev2295df72021-11-12 18:14:10 -0800108
109// Check if the device supports a given dynamicRangeProfile
Emilian Peevc81a7592022-02-14 17:38:18 -0800110bool isDynamicRangeProfileSupported(int64_t dynamicRangeProfile, const CameraMetadata& staticMeta);
Emilian Peev2295df72021-11-12 18:14:10 -0800111
Shuzhen Wang8ed1e872022-03-08 16:34:33 -0800112bool isStreamUseCaseSupported(int64_t streamUseCase, const CameraMetadata &deviceInfo);
Shuzhen Wangc8ab4522021-12-14 20:12:42 -0800113
Jayant Chowdharya04055f2022-01-03 02:07:49 +0000114void mapStreamInfo(const OutputStreamInfo &streamInfo,
115 camera3::camera_stream_rotation_t rotation, String8 physicalId,
116 int32_t groupId, aidl::android::hardware::camera::device::Stream *stream /*out*/);
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
Jayant Chowdharya04055f2022-01-03 02:07:49 +0000130binder::Status
131convertToHALStreamCombination(
132 const SessionConfiguration& sessionConfiguration,
133 const String8 &logicalCameraId, const CameraMetadata &deviceInfo,
134 metadataGetter getMetadata, const std::vector<std::string> &physicalCameraIds,
135 aidl::android::hardware::camera::device::StreamConfiguration &streamConfiguration,
136 bool overrideForPerfClass, bool *earlyExit);
137
Austin Borgerea931242021-12-13 23:10:41 +0000138StreamConfigurationPair getStreamConfigurationPair(const CameraMetadata &metadata);
Jayant Chowdhary13f9b2f2020-12-02 22:46:15 -0800139
Austin Borgerea931242021-12-13 23:10:41 +0000140status_t checkAndOverrideSensorPixelModesUsed(
141 const std::vector<int32_t> &sensorPixelModesUsed, int format, int width, int height,
142 const CameraMetadata &staticInfo, bool flexibleConsumer,
143 std::unordered_set<int32_t> *overriddenSensorPixelModesUsed);
Jayant Chowdhary13f9b2f2020-12-02 22:46:15 -0800144
Austin Borgerea931242021-12-13 23:10:41 +0000145bool targetPerfClassPrimaryCamera(
146 const std::set<std::string>& perfClassPrimaryCameraIds, const std::string& cameraId,
147 int32_t targetSdkVersion);
Jayant Chowdhary13f9b2f2020-12-02 22:46:15 -0800148
Austin Borgerea931242021-12-13 23:10:41 +0000149constexpr int32_t MAX_SURFACES_PER_STREAM = 4;
Shuzhen Wangd4abdf72021-05-28 11:22:50 -0700150
Austin Borgerea931242021-12-13 23:10:41 +0000151constexpr int32_t ROUNDING_WIDTH_CAP = 1920;
Colin Crossb8a9dbb2020-08-27 04:12:26 +0000152
Austin Borgerea931242021-12-13 23:10:41 +0000153constexpr int32_t SDK_VERSION_S = 31;
154extern int32_t PERF_CLASS_LEVEL;
155extern bool IS_PERF_CLASS;
156constexpr int32_t PERF_CLASS_JPEG_THRESH_W = 1920;
157constexpr int32_t PERF_CLASS_JPEG_THRESH_H = 1080;
Jayant Chowdhary13f9b2f2020-12-02 22:46:15 -0800158
Austin Borgerea931242021-12-13 23:10:41 +0000159} // SessionConfigurationUtils
Jayant Chowdhary13f9b2f2020-12-02 22:46:15 -0800160} // camera3
Jayant Chowdhary2bbdce42020-01-12 14:55:41 -0800161} // android
Austin Borgerea931242021-12-13 23:10:41 +0000162
Jayant Chowdhary2bbdce42020-01-12 14:55:41 -0800163#endif