blob: 36e1dd7393a3386ee7f5118cc4b529b30cd1d7c5 [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 Wang83bff122020-11-20 15:51:39 -080024#include <android/hardware/camera/device/3.7/types.h>
Jayant Chowdhary2bbdce42020-01-12 14:55:41 -080025
Colin Crossb8a9dbb2020-08-27 04:12:26 +000026#include <device3/Camera3StreamInterface.h>
27
Jayant Chowdhary2bbdce42020-01-12 14:55:41 -080028#include <stdint.h>
29
30namespace android {
31
32typedef std::function<CameraMetadata (const String8 &)> metadataGetter;
33
34class SessionConfigurationUtils {
35public:
Colin Crossb8a9dbb2020-08-27 04:12:26 +000036
37 static int64_t euclidDistSquare(int32_t x0, int32_t y0, int32_t x1, int32_t y1);
38
39 // Find the closest dimensions for a given format in available stream configurations with
40 // a width <= ROUNDING_WIDTH_CAP
41 static bool roundBufferDimensionNearest(int32_t width, int32_t height, int32_t format,
42 android_dataspace dataSpace, const CameraMetadata& info,
43 /*out*/int32_t* outWidth, /*out*/int32_t* outHeight);
44
45 //check if format is not custom format
46 static bool isPublicFormat(int32_t format);
47
48 // Create a Surface from an IGraphicBufferProducer. Returns error if
49 // IGraphicBufferProducer's property doesn't match with streamInfo
50 static binder::Status createSurfaceFromGbp(
51 camera3::OutputStreamInfo& streamInfo, bool isStreamInfoValid,
52 sp<Surface>& surface, const sp<IGraphicBufferProducer>& gbp,
53 const String8 &cameraId, const CameraMetadata &physicalCameraMetadata);
54
55 static void mapStreamInfo(const camera3::OutputStreamInfo &streamInfo,
Shuzhen Wang83bff122020-11-20 15:51:39 -080056 camera3::camera_stream_rotation_t rotation, String8 physicalId, int32_t groupId,
57 hardware::camera::device::V3_7::Stream *stream /*out*/);
Colin Crossb8a9dbb2020-08-27 04:12:26 +000058
59 // Check that the physicalCameraId passed in is spported by the camera
60 // device.
61 static binder::Status checkPhysicalCameraId(
62 const std::vector<std::string> &physicalCameraIds, const String8 &physicalCameraId,
63 const String8 &logicalCameraId);
64
65 static binder::Status checkSurfaceType(size_t numBufferProducers,
66 bool deferredConsumer, int surfaceType);
67
68 static binder::Status checkOperatingMode(int operatingMode,
69 const CameraMetadata &staticInfo, const String8 &cameraId);
70
Jayant Chowdhary2bbdce42020-01-12 14:55:41 -080071 // utility function to convert AIDL SessionConfiguration to HIDL
Eino-Ville Talvala0bdfa282020-06-19 13:54:35 -070072 // streamConfiguration. Also checks for validity of SessionConfiguration and
Jayant Chowdhary2bbdce42020-01-12 14:55:41 -080073 // returns a non-ok binder::Status if the passed in session configuration
74 // isn't valid.
75 static binder::Status
76 convertToHALStreamCombination(const SessionConfiguration& sessionConfiguration,
77 const String8 &cameraId, const CameraMetadata &deviceInfo,
78 metadataGetter getMetadata, const std::vector<std::string> &physicalCameraIds,
Shuzhen Wang83bff122020-11-20 15:51:39 -080079 hardware::camera::device::V3_7::StreamConfiguration &streamConfiguration,
Jayant Chowdhary2bbdce42020-01-12 14:55:41 -080080 bool *earlyExit);
Colin Crossb8a9dbb2020-08-27 04:12:26 +000081
Shuzhen Wang83bff122020-11-20 15:51:39 -080082 // Utility function to convert a V3_7::StreamConfiguration to
83 // V3_4::StreamConfiguration. Return false if the original V3_7 configuration cannot
84 // be used by older version HAL.
85 static bool convertHALStreamCombinationFromV37ToV34(
86 hardware::camera::device::V3_4::StreamConfiguration &streamConfigV34,
87 const hardware::camera::device::V3_7::StreamConfiguration &streamConfigV37);
88
Colin Crossb8a9dbb2020-08-27 04:12:26 +000089 static const int32_t MAX_SURFACES_PER_STREAM = 4;
90
91 static const int32_t ROUNDING_WIDTH_CAP = 1920;
Jayant Chowdhary2bbdce42020-01-12 14:55:41 -080092};
93
94} // android
95#endif