blob: f63eea1b07d2a9d47e6bdf9e441cd0ee1724e2f0 [file] [log] [blame]
Jayant Chowdharyc67af1b2022-04-07 18:05:04 +00001/*
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
27using android::camera3::OutputStreamInfo;
28using android::hardware::camera2::ICameraDeviceUser;
29using android::hardware::camera::metadata::V3_6::CameraMetadataEnumAndroidSensorPixelMode;
Jayant Chowdharyc67af1b2022-04-07 18:05:04 +000030
31namespace android {
32namespace camera3 {
33
34namespace SessionConfigurationUtils {
35
36status_t
Jayant Chowdharyffc5d682022-05-12 18:34:34 +000037convertAidlToHidl37StreamCombination(
Jayant Chowdharyc67af1b2022-04-07 18:05:04 +000038 const aidl::android::hardware::camera::device::StreamConfiguration &aidl,
Jayant Chowdharyffc5d682022-05-12 18:34:34 +000039 hardware::camera::device::V3_7::StreamConfiguration &hidl) {
Jayant Chowdharyc67af1b2022-04-07 18:05:04 +000040 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 Chowdharyffc5d682022-05-12 18:34:34 +000051 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 Chowdharyc67af1b2022-04-07 18:05:04 +000063
64 // hidl v3_7
Jayant Chowdharyffc5d682022-05-12 18:34:34 +000065 hidl.streams[i].groupId = stream.groupId;
66 hidl.streams[i].sensorPixelModesUsed.resize(stream.sensorPixelModesUsed.size());
Jayant Chowdharyc67af1b2022-04-07 18:05:04 +000067 size_t j = 0;
68 for (const auto &mode : stream.sensorPixelModesUsed) {
Jayant Chowdharyffc5d682022-05-12 18:34:34 +000069 hidl.streams[i].sensorPixelModesUsed[j] =
Jayant Chowdharyc67af1b2022-04-07 18:05:04 +000070 static_cast<CameraMetadataEnumAndroidSensorPixelMode>(mode);
71 j++;
72 }
73
74 //hidl v3_4
Jayant Chowdharyffc5d682022-05-12 18:34:34 +000075 hidl.streams[i].v3_4.physicalCameraId = stream.physicalCameraId;
Jayant Chowdharyc67af1b2022-04-07 18:05:04 +000076
77 if (stream.bufferSize < 0) {
78 return BAD_VALUE;
79 }
Jayant Chowdharyffc5d682022-05-12 18:34:34 +000080 hidl.streams[i].v3_4.bufferSize = static_cast<uint32_t>(stream.bufferSize);
Jayant Chowdharyc67af1b2022-04-07 18:05:04 +000081
82 // hild v3_2
Jayant Chowdharyffc5d682022-05-12 18:34:34 +000083 hidl.streams[i].v3_4.v3_2.id = stream.id;
84 hidl.streams[i].v3_4.v3_2.format =
Jayant Chowdharyc67af1b2022-04-07 18:05:04 +000085 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 Chowdharyffc5d682022-05-12 18:34:34 +000090 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 Chowdharyc67af1b2022-04-07 18:05:04 +000093 static_cast<hardware::camera::device::V3_2::BufferUsageFlags>(stream.usage);
Jayant Chowdharyffc5d682022-05-12 18:34:34 +000094 hidl.streams[i].v3_4.v3_2.streamType =
Jayant Chowdharyc67af1b2022-04-07 18:05:04 +000095 static_cast<hardware::camera::device::V3_2::StreamType>(stream.streamType);
Jayant Chowdharyffc5d682022-05-12 18:34:34 +000096 hidl.streams[i].v3_4.v3_2.dataSpace =
Jayant Chowdharyc67af1b2022-04-07 18:05:04 +000097 static_cast<hardware::camera::device::V3_2::DataspaceFlags>(stream.dataSpace);
Jayant Chowdharyffc5d682022-05-12 18:34:34 +000098 hidl.streams[i].v3_4.v3_2.rotation =
Jayant Chowdharyc67af1b2022-04-07 18:05:04 +000099 static_cast<hardware::camera::device::V3_2::StreamRotation>(stream.rotation);
100 i++;
101 }
102 return OK;
103}
104
Jayant Chowdharyc67af1b2022-04-07 18:05:04 +0000105binder::Status
106convertToHALStreamCombination(
107 const SessionConfiguration& sessionConfiguration,
Austin Borger0fb3ad92023-06-01 16:51:35 -0700108 const std::string &logicalCameraId, const CameraMetadata &deviceInfo,
Jayant Chowdharyc67af1b2022-04-07 18:05:04 +0000109 metadataGetter getMetadata, const std::vector<std::string> &physicalCameraIds,
Jayant Chowdharyffc5d682022-05-12 18:34:34 +0000110 hardware::camera::device::V3_7::StreamConfiguration &streamConfiguration,
Jayant Chowdharyc67af1b2022-04-07 18:05:04 +0000111 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 Chowdharyffc5d682022-05-12 18:34:34 +0000123 if (convertAidlToHidl37StreamCombination(aidlStreamConfiguration, streamConfiguration) != OK) {
Jayant Chowdharyc67af1b2022-04-07 18:05:04 +0000124 return STATUS_ERROR(CameraService::ERROR_ILLEGAL_ARGUMENT,
Jayant Chowdharyffc5d682022-05-12 18:34:34 +0000125 "Invalid AIDL->HIDL3.7 conversion");
Jayant Chowdharyc67af1b2022-04-07 18:05:04 +0000126 }
127
128 return binder::Status::ok();
129}
130
Jayant Chowdharyc67af1b2022-04-07 18:05:04 +0000131bool 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