Jayant Chowdhary | c67af1b | 2022-04-07 18:05:04 +0000 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2022 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 | |
| 17 | #include <cutils/properties.h> |
| 18 | |
| 19 | #include "SessionConfigurationUtils.h" |
| 20 | #include "SessionConfigurationUtilsHidl.h" |
| 21 | |
| 22 | #include "../CameraService.h" |
| 23 | #include "device3/aidl/AidlCamera3Device.h" |
| 24 | #include "device3/hidl/HidlCamera3Device.h" |
| 25 | #include "device3/Camera3OutputStream.h" |
| 26 | |
| 27 | using android::camera3::OutputStreamInfo; |
| 28 | using android::hardware::camera2::ICameraDeviceUser; |
| 29 | using android::hardware::camera::metadata::V3_6::CameraMetadataEnumAndroidSensorPixelMode; |
Jayant Chowdhary | c67af1b | 2022-04-07 18:05:04 +0000 | [diff] [blame] | 30 | |
| 31 | namespace android { |
| 32 | namespace camera3 { |
| 33 | |
| 34 | namespace SessionConfigurationUtils { |
| 35 | |
| 36 | status_t |
Jayant Chowdhary | ffc5d68 | 2022-05-12 18:34:34 +0000 | [diff] [blame] | 37 | convertAidlToHidl37StreamCombination( |
Jayant Chowdhary | c67af1b | 2022-04-07 18:05:04 +0000 | [diff] [blame] | 38 | const aidl::android::hardware::camera::device::StreamConfiguration &aidl, |
Jayant Chowdhary | ffc5d68 | 2022-05-12 18:34:34 +0000 | [diff] [blame] | 39 | hardware::camera::device::V3_7::StreamConfiguration &hidl) { |
Jayant Chowdhary | c67af1b | 2022-04-07 18:05:04 +0000 | [diff] [blame] | 40 | hidl.operationMode = |
| 41 | static_cast<hardware::camera::device::V3_2::StreamConfigurationMode>(aidl.operationMode); |
| 42 | if (aidl.streamConfigCounter < 0) { |
| 43 | return BAD_VALUE; |
| 44 | } |
| 45 | hidl.streamConfigCounter = static_cast<uint32_t>(aidl.streamConfigCounter); |
| 46 | hidl.multiResolutionInputImage = aidl.multiResolutionInputImage; |
| 47 | hidl.sessionParams = aidl.sessionParams.metadata; |
| 48 | hidl.streams.resize(aidl.streams.size()); |
| 49 | size_t i = 0; |
| 50 | for (const auto &stream : aidl.streams) { |
Jayant Chowdhary | ffc5d68 | 2022-05-12 18:34:34 +0000 | [diff] [blame] | 51 | if (static_cast<int>(stream.dynamicRangeProfile) != |
| 52 | ANDROID_REQUEST_AVAILABLE_DYNAMIC_RANGE_PROFILES_MAP_STANDARD) { |
| 53 | ALOGE("%s Dynamic range profile %" PRId64 " not supported by HIDL", __FUNCTION__, |
| 54 | stream.dynamicRangeProfile); |
| 55 | return BAD_VALUE; |
| 56 | } |
| 57 | |
| 58 | if (static_cast<int>(stream.useCase) != ANDROID_SCALER_AVAILABLE_STREAM_USE_CASES_DEFAULT) { |
| 59 | ALOGE("%s Stream use case %" PRId64 "not supported by HIDL", __FUNCTION__, |
| 60 | stream.useCase); |
| 61 | return BAD_VALUE; |
| 62 | } |
Jayant Chowdhary | c67af1b | 2022-04-07 18:05:04 +0000 | [diff] [blame] | 63 | |
| 64 | // hidl v3_7 |
Jayant Chowdhary | ffc5d68 | 2022-05-12 18:34:34 +0000 | [diff] [blame] | 65 | hidl.streams[i].groupId = stream.groupId; |
| 66 | hidl.streams[i].sensorPixelModesUsed.resize(stream.sensorPixelModesUsed.size()); |
Jayant Chowdhary | c67af1b | 2022-04-07 18:05:04 +0000 | [diff] [blame] | 67 | size_t j = 0; |
| 68 | for (const auto &mode : stream.sensorPixelModesUsed) { |
Jayant Chowdhary | ffc5d68 | 2022-05-12 18:34:34 +0000 | [diff] [blame] | 69 | hidl.streams[i].sensorPixelModesUsed[j] = |
Jayant Chowdhary | c67af1b | 2022-04-07 18:05:04 +0000 | [diff] [blame] | 70 | static_cast<CameraMetadataEnumAndroidSensorPixelMode>(mode); |
| 71 | j++; |
| 72 | } |
| 73 | |
| 74 | //hidl v3_4 |
Jayant Chowdhary | ffc5d68 | 2022-05-12 18:34:34 +0000 | [diff] [blame] | 75 | hidl.streams[i].v3_4.physicalCameraId = stream.physicalCameraId; |
Jayant Chowdhary | c67af1b | 2022-04-07 18:05:04 +0000 | [diff] [blame] | 76 | |
| 77 | if (stream.bufferSize < 0) { |
| 78 | return BAD_VALUE; |
| 79 | } |
Jayant Chowdhary | ffc5d68 | 2022-05-12 18:34:34 +0000 | [diff] [blame] | 80 | hidl.streams[i].v3_4.bufferSize = static_cast<uint32_t>(stream.bufferSize); |
Jayant Chowdhary | c67af1b | 2022-04-07 18:05:04 +0000 | [diff] [blame] | 81 | |
| 82 | // hild v3_2 |
Jayant Chowdhary | ffc5d68 | 2022-05-12 18:34:34 +0000 | [diff] [blame] | 83 | hidl.streams[i].v3_4.v3_2.id = stream.id; |
| 84 | hidl.streams[i].v3_4.v3_2.format = |
Jayant Chowdhary | c67af1b | 2022-04-07 18:05:04 +0000 | [diff] [blame] | 85 | static_cast<hardware::graphics::common::V1_0::PixelFormat>(stream.format); |
| 86 | |
| 87 | if (stream.width < 0 || stream.height < 0) { |
| 88 | return BAD_VALUE; |
| 89 | } |
Jayant Chowdhary | ffc5d68 | 2022-05-12 18:34:34 +0000 | [diff] [blame] | 90 | hidl.streams[i].v3_4.v3_2.width = static_cast<uint32_t>(stream.width); |
| 91 | hidl.streams[i].v3_4.v3_2.height = static_cast<uint32_t>(stream.height); |
| 92 | hidl.streams[i].v3_4.v3_2.usage = |
Jayant Chowdhary | c67af1b | 2022-04-07 18:05:04 +0000 | [diff] [blame] | 93 | static_cast<hardware::camera::device::V3_2::BufferUsageFlags>(stream.usage); |
Jayant Chowdhary | ffc5d68 | 2022-05-12 18:34:34 +0000 | [diff] [blame] | 94 | hidl.streams[i].v3_4.v3_2.streamType = |
Jayant Chowdhary | c67af1b | 2022-04-07 18:05:04 +0000 | [diff] [blame] | 95 | static_cast<hardware::camera::device::V3_2::StreamType>(stream.streamType); |
Jayant Chowdhary | ffc5d68 | 2022-05-12 18:34:34 +0000 | [diff] [blame] | 96 | hidl.streams[i].v3_4.v3_2.dataSpace = |
Jayant Chowdhary | c67af1b | 2022-04-07 18:05:04 +0000 | [diff] [blame] | 97 | static_cast<hardware::camera::device::V3_2::DataspaceFlags>(stream.dataSpace); |
Jayant Chowdhary | ffc5d68 | 2022-05-12 18:34:34 +0000 | [diff] [blame] | 98 | hidl.streams[i].v3_4.v3_2.rotation = |
Jayant Chowdhary | c67af1b | 2022-04-07 18:05:04 +0000 | [diff] [blame] | 99 | static_cast<hardware::camera::device::V3_2::StreamRotation>(stream.rotation); |
| 100 | i++; |
| 101 | } |
| 102 | return OK; |
| 103 | } |
| 104 | |
Jayant Chowdhary | c67af1b | 2022-04-07 18:05:04 +0000 | [diff] [blame] | 105 | binder::Status |
| 106 | convertToHALStreamCombination( |
| 107 | const SessionConfiguration& sessionConfiguration, |
Austin Borger | 0fb3ad9 | 2023-06-01 16:51:35 -0700 | [diff] [blame^] | 108 | const std::string &logicalCameraId, const CameraMetadata &deviceInfo, |
Jayant Chowdhary | c67af1b | 2022-04-07 18:05:04 +0000 | [diff] [blame] | 109 | metadataGetter getMetadata, const std::vector<std::string> &physicalCameraIds, |
Jayant Chowdhary | ffc5d68 | 2022-05-12 18:34:34 +0000 | [diff] [blame] | 110 | hardware::camera::device::V3_7::StreamConfiguration &streamConfiguration, |
Jayant Chowdhary | c67af1b | 2022-04-07 18:05:04 +0000 | [diff] [blame] | 111 | bool overrideForPerfClass, bool *earlyExit) { |
| 112 | aidl::android::hardware::camera::device::StreamConfiguration aidlStreamConfiguration; |
| 113 | auto ret = convertToHALStreamCombination(sessionConfiguration, logicalCameraId, deviceInfo, |
| 114 | getMetadata, physicalCameraIds, aidlStreamConfiguration, overrideForPerfClass, |
| 115 | earlyExit); |
| 116 | if (!ret.isOk()) { |
| 117 | return ret; |
| 118 | } |
| 119 | if (earlyExit != nullptr && *earlyExit) { |
| 120 | return binder::Status::ok(); |
| 121 | } |
| 122 | |
Jayant Chowdhary | ffc5d68 | 2022-05-12 18:34:34 +0000 | [diff] [blame] | 123 | if (convertAidlToHidl37StreamCombination(aidlStreamConfiguration, streamConfiguration) != OK) { |
Jayant Chowdhary | c67af1b | 2022-04-07 18:05:04 +0000 | [diff] [blame] | 124 | return STATUS_ERROR(CameraService::ERROR_ILLEGAL_ARGUMENT, |
Jayant Chowdhary | ffc5d68 | 2022-05-12 18:34:34 +0000 | [diff] [blame] | 125 | "Invalid AIDL->HIDL3.7 conversion"); |
Jayant Chowdhary | c67af1b | 2022-04-07 18:05:04 +0000 | [diff] [blame] | 126 | } |
| 127 | |
| 128 | return binder::Status::ok(); |
| 129 | } |
| 130 | |
Jayant Chowdhary | c67af1b | 2022-04-07 18:05:04 +0000 | [diff] [blame] | 131 | bool convertHALStreamCombinationFromV37ToV34( |
| 132 | hardware::camera::device::V3_4::StreamConfiguration &streamConfigV34, |
| 133 | const hardware::camera::device::V3_7::StreamConfiguration &streamConfigV37) { |
| 134 | if (streamConfigV37.multiResolutionInputImage) { |
| 135 | // ICameraDevice older than 3.7 doesn't support multi-resolution input image. |
| 136 | return false; |
| 137 | } |
| 138 | |
| 139 | streamConfigV34.streams.resize(streamConfigV37.streams.size()); |
| 140 | for (size_t i = 0; i < streamConfigV37.streams.size(); i++) { |
| 141 | if (streamConfigV37.streams[i].groupId != -1) { |
| 142 | // ICameraDevice older than 3.7 doesn't support multi-resolution output |
| 143 | // image |
| 144 | return false; |
| 145 | } |
| 146 | streamConfigV34.streams[i] = streamConfigV37.streams[i].v3_4; |
| 147 | } |
| 148 | streamConfigV34.operationMode = streamConfigV37.operationMode; |
| 149 | streamConfigV34.sessionParams = streamConfigV37.sessionParams; |
| 150 | |
| 151 | return true; |
| 152 | } |
| 153 | |
| 154 | } // namespace SessionConfigurationUtils |
| 155 | } // namespace camera3 |
| 156 | } // namespace android |