Jan Sebechlebsky | 5cb3996 | 2023-11-22 17:33:07 +0100 | [diff] [blame] | 1 | /* |
Biswarup Pal | 6152a30 | 2023-12-19 12:44:09 +0000 | [diff] [blame] | 2 | * Copyright 2023 The Android Open Source Project |
Jan Sebechlebsky | 5cb3996 | 2023-11-22 17:33:07 +0100 | [diff] [blame] | 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 | // #define LOG_NDEBUG 0 |
| 18 | #define LOG_TAG "VirtualCameraDevice" |
| 19 | #include "VirtualCameraDevice.h" |
| 20 | |
Jan Sebechlebsky | 3b478c4 | 2023-11-23 13:15:56 +0100 | [diff] [blame] | 21 | #include <algorithm> |
| 22 | #include <array> |
Jan Sebechlebsky | 5cb3996 | 2023-11-22 17:33:07 +0100 | [diff] [blame] | 23 | #include <chrono> |
| 24 | #include <cstdint> |
Jan Sebechlebsky | 3b478c4 | 2023-11-23 13:15:56 +0100 | [diff] [blame] | 25 | #include <iterator> |
Jan Sebechlebsky | c3e1a63 | 2024-02-06 14:19:05 +0100 | [diff] [blame] | 26 | #include <numeric> |
Jan Sebechlebsky | 3b478c4 | 2023-11-23 13:15:56 +0100 | [diff] [blame] | 27 | #include <optional> |
Jan Sebechlebsky | 5cb3996 | 2023-11-22 17:33:07 +0100 | [diff] [blame] | 28 | #include <string> |
Jan Sebechlebsky | c3e1a63 | 2024-02-06 14:19:05 +0100 | [diff] [blame] | 29 | #include <vector> |
Jan Sebechlebsky | 5cb3996 | 2023-11-22 17:33:07 +0100 | [diff] [blame] | 30 | |
Vadim Caen | 918e6dc | 2024-04-08 11:14:50 +0200 | [diff] [blame^] | 31 | #include "VirtualCameraService.h" |
Jan Sebechlebsky | 5cb3996 | 2023-11-22 17:33:07 +0100 | [diff] [blame] | 32 | #include "VirtualCameraSession.h" |
Jan Sebechlebsky | 3b478c4 | 2023-11-23 13:15:56 +0100 | [diff] [blame] | 33 | #include "aidl/android/companion/virtualcamera/SupportedStreamConfiguration.h" |
Biswarup Pal | 6152a30 | 2023-12-19 12:44:09 +0000 | [diff] [blame] | 34 | #include "aidl/android/companion/virtualcamera/VirtualCameraConfiguration.h" |
Jan Sebechlebsky | 5cb3996 | 2023-11-22 17:33:07 +0100 | [diff] [blame] | 35 | #include "aidl/android/hardware/camera/common/Status.h" |
| 36 | #include "aidl/android/hardware/camera/device/CameraMetadata.h" |
Jan Sebechlebsky | 3b478c4 | 2023-11-23 13:15:56 +0100 | [diff] [blame] | 37 | #include "aidl/android/hardware/camera/device/StreamConfiguration.h" |
Jan Sebechlebsky | 5cb3996 | 2023-11-22 17:33:07 +0100 | [diff] [blame] | 38 | #include "android/binder_auto_utils.h" |
| 39 | #include "android/binder_status.h" |
| 40 | #include "log/log.h" |
| 41 | #include "system/camera_metadata.h" |
Jan Sebechlebsky | 4ce3208 | 2024-02-14 16:02:11 +0100 | [diff] [blame] | 42 | #include "util/MetadataUtil.h" |
Jan Sebechlebsky | 5cb3996 | 2023-11-22 17:33:07 +0100 | [diff] [blame] | 43 | #include "util/Util.h" |
| 44 | |
| 45 | namespace android { |
| 46 | namespace companion { |
| 47 | namespace virtualcamera { |
| 48 | |
Jan Sebechlebsky | 3b478c4 | 2023-11-23 13:15:56 +0100 | [diff] [blame] | 49 | using ::aidl::android::companion::virtualcamera::Format; |
Jan Sebechlebsky | 5cb3996 | 2023-11-22 17:33:07 +0100 | [diff] [blame] | 50 | using ::aidl::android::companion::virtualcamera::IVirtualCameraCallback; |
Biswarup Pal | 112458f | 2023-12-28 19:50:17 +0000 | [diff] [blame] | 51 | using ::aidl::android::companion::virtualcamera::LensFacing; |
Biswarup Pal | 6152a30 | 2023-12-19 12:44:09 +0000 | [diff] [blame] | 52 | using ::aidl::android::companion::virtualcamera::SensorOrientation; |
Jan Sebechlebsky | 3b478c4 | 2023-11-23 13:15:56 +0100 | [diff] [blame] | 53 | using ::aidl::android::companion::virtualcamera::SupportedStreamConfiguration; |
Biswarup Pal | 6152a30 | 2023-12-19 12:44:09 +0000 | [diff] [blame] | 54 | using ::aidl::android::companion::virtualcamera::VirtualCameraConfiguration; |
Jan Sebechlebsky | 5cb3996 | 2023-11-22 17:33:07 +0100 | [diff] [blame] | 55 | using ::aidl::android::hardware::camera::common::CameraResourceCost; |
| 56 | using ::aidl::android::hardware::camera::common::Status; |
| 57 | using ::aidl::android::hardware::camera::device::CameraMetadata; |
| 58 | using ::aidl::android::hardware::camera::device::ICameraDeviceCallback; |
| 59 | using ::aidl::android::hardware::camera::device::ICameraDeviceSession; |
| 60 | using ::aidl::android::hardware::camera::device::ICameraInjectionSession; |
Jan Sebechlebsky | 3b478c4 | 2023-11-23 13:15:56 +0100 | [diff] [blame] | 61 | using ::aidl::android::hardware::camera::device::Stream; |
Jan Sebechlebsky | 5cb3996 | 2023-11-22 17:33:07 +0100 | [diff] [blame] | 62 | using ::aidl::android::hardware::camera::device::StreamConfiguration; |
| 63 | using ::aidl::android::hardware::camera::device::StreamRotation; |
| 64 | using ::aidl::android::hardware::camera::device::StreamType; |
| 65 | using ::aidl::android::hardware::graphics::common::PixelFormat; |
| 66 | |
| 67 | namespace { |
| 68 | |
| 69 | using namespace std::chrono_literals; |
| 70 | |
| 71 | // Prefix of camera name - "device@1.1/virtual/{numerical_id}" |
| 72 | const char* kDevicePathPrefix = "device@1.1/virtual/"; |
| 73 | |
Jan Sebechlebsky | 5cb3996 | 2023-11-22 17:33:07 +0100 | [diff] [blame] | 74 | constexpr int32_t kMaxJpegSize = 3 * 1024 * 1024 /*3MiB*/; |
| 75 | |
Jan Sebechlebsky | bb01c1d | 2024-02-12 11:41:37 +0100 | [diff] [blame] | 76 | constexpr int32_t kMinFps = 15; |
| 77 | |
| 78 | constexpr std::chrono::nanoseconds kMaxFrameDuration = |
| 79 | std::chrono::duration_cast<std::chrono::nanoseconds>(1e9ns / kMinFps); |
| 80 | |
| 81 | constexpr uint8_t kPipelineMaxDepth = 2; |
| 82 | |
Jan Sebechlebsky | 5cb3996 | 2023-11-22 17:33:07 +0100 | [diff] [blame] | 83 | constexpr MetadataBuilder::ControlRegion kDefaultEmptyControlRegion{}; |
| 84 | |
Jan Sebechlebsky | 4ce3208 | 2024-02-14 16:02:11 +0100 | [diff] [blame] | 85 | const std::array<Resolution, 5> kStandardJpegThumbnailSizes{ |
| 86 | Resolution(176, 144), Resolution(240, 144), Resolution(256, 144), |
| 87 | Resolution(240, 160), Resolution(240, 180)}; |
| 88 | |
Jan Sebechlebsky | 8ae2359 | 2024-02-02 16:08:18 +0100 | [diff] [blame] | 89 | const std::array<PixelFormat, 3> kOutputFormats{ |
| 90 | PixelFormat::IMPLEMENTATION_DEFINED, PixelFormat::YCBCR_420_888, |
| 91 | PixelFormat::BLOB}; |
Biswarup Pal | 6152a30 | 2023-12-19 12:44:09 +0000 | [diff] [blame] | 92 | |
Jan Sebechlebsky | 4c9bb1e | 2024-02-28 16:32:39 +0100 | [diff] [blame] | 93 | // The resolutions below will used to extend the set of supported output formats. |
| 94 | // All resolutions with lower pixel count and same aspect ratio as some supported |
| 95 | // input resolution will be added to the set of supported output resolutions. |
| 96 | const std::array<Resolution, 10> kOutputResolutions{ |
| 97 | Resolution(320, 240), Resolution(640, 360), Resolution(640, 480), |
| 98 | Resolution(720, 480), Resolution(720, 576), Resolution(800, 600), |
| 99 | Resolution(1024, 576), Resolution(1280, 720), Resolution(1280, 960), |
| 100 | Resolution(1280, 1080), |
| 101 | }; |
Jan Sebechlebsky | 4ce3208 | 2024-02-14 16:02:11 +0100 | [diff] [blame] | 102 | |
| 103 | std::vector<Resolution> getSupportedJpegThumbnailSizes( |
| 104 | const std::vector<SupportedStreamConfiguration>& configs) { |
| 105 | auto isSupportedByAnyInputConfig = |
| 106 | [&configs](const Resolution thumbnailResolution) { |
| 107 | return std::any_of( |
| 108 | configs.begin(), configs.end(), |
| 109 | [thumbnailResolution](const SupportedStreamConfiguration& config) { |
| 110 | return isApproximatellySameAspectRatio( |
| 111 | thumbnailResolution, Resolution(config.width, config.height)); |
| 112 | }); |
| 113 | }; |
| 114 | |
| 115 | std::vector<Resolution> supportedThumbnailSizes({Resolution(0, 0)}); |
| 116 | std::copy_if(kStandardJpegThumbnailSizes.begin(), |
| 117 | kStandardJpegThumbnailSizes.end(), |
| 118 | std::back_insert_iterator(supportedThumbnailSizes), |
| 119 | isSupportedByAnyInputConfig); |
| 120 | return supportedThumbnailSizes; |
| 121 | } |
| 122 | |
Jan Sebechlebsky | 8ae2359 | 2024-02-02 16:08:18 +0100 | [diff] [blame] | 123 | bool isSupportedOutputFormat(const PixelFormat pixelFormat) { |
| 124 | return std::find(kOutputFormats.begin(), kOutputFormats.end(), pixelFormat) != |
| 125 | kOutputFormats.end(); |
| 126 | } |
| 127 | |
Vadim Caen | 11dfd93 | 2024-03-05 09:57:20 +0100 | [diff] [blame] | 128 | std::vector<FpsRange> fpsRangesForInputConfig( |
Jan Sebechlebsky | c3e1a63 | 2024-02-06 14:19:05 +0100 | [diff] [blame] | 129 | const std::vector<SupportedStreamConfiguration>& configs) { |
Vadim Caen | 11dfd93 | 2024-03-05 09:57:20 +0100 | [diff] [blame] | 130 | std::set<FpsRange> availableRanges; |
Jan Sebechlebsky | bb01c1d | 2024-02-12 11:41:37 +0100 | [diff] [blame] | 131 | |
Jan Sebechlebsky | c3e1a63 | 2024-02-06 14:19:05 +0100 | [diff] [blame] | 132 | for (const SupportedStreamConfiguration& config : configs) { |
Jan Sebechlebsky | bb01c1d | 2024-02-12 11:41:37 +0100 | [diff] [blame] | 133 | availableRanges.insert({.minFps = kMinFps, .maxFps = config.maxFps}); |
Jan Sebechlebsky | c3e1a63 | 2024-02-06 14:19:05 +0100 | [diff] [blame] | 134 | availableRanges.insert({.minFps = config.maxFps, .maxFps = config.maxFps}); |
| 135 | } |
| 136 | |
Jan Sebechlebsky | bb01c1d | 2024-02-12 11:41:37 +0100 | [diff] [blame] | 137 | if (std::any_of(configs.begin(), configs.end(), |
| 138 | [](const SupportedStreamConfiguration& config) { |
| 139 | return config.maxFps >= 30; |
| 140 | })) { |
| 141 | availableRanges.insert({.minFps = kMinFps, .maxFps = 30}); |
| 142 | availableRanges.insert({.minFps = 30, .maxFps = 30}); |
| 143 | } |
| 144 | |
Vadim Caen | 11dfd93 | 2024-03-05 09:57:20 +0100 | [diff] [blame] | 145 | return std::vector<FpsRange>(availableRanges.begin(), availableRanges.end()); |
Jan Sebechlebsky | c3e1a63 | 2024-02-06 14:19:05 +0100 | [diff] [blame] | 146 | } |
| 147 | |
Jan Sebechlebsky | 3b478c4 | 2023-11-23 13:15:56 +0100 | [diff] [blame] | 148 | std::optional<Resolution> getMaxResolution( |
| 149 | const std::vector<SupportedStreamConfiguration>& configs) { |
| 150 | auto itMax = std::max_element(configs.begin(), configs.end(), |
| 151 | [](const SupportedStreamConfiguration& a, |
| 152 | const SupportedStreamConfiguration& b) { |
| 153 | return a.width * b.height < a.width * b.height; |
| 154 | }); |
| 155 | if (itMax == configs.end()) { |
| 156 | ALOGE( |
| 157 | "%s: empty vector of supported configurations, cannot find largest " |
| 158 | "resolution.", |
| 159 | __func__); |
| 160 | return std::nullopt; |
| 161 | } |
| 162 | |
| 163 | return Resolution(itMax->width, itMax->height); |
| 164 | } |
| 165 | |
Biswarup Pal | 6152a30 | 2023-12-19 12:44:09 +0000 | [diff] [blame] | 166 | // Returns a map of unique resolution to maximum maxFps for all streams with |
| 167 | // that resolution. |
| 168 | std::map<Resolution, int> getResolutionToMaxFpsMap( |
Jan Sebechlebsky | 3b478c4 | 2023-11-23 13:15:56 +0100 | [diff] [blame] | 169 | const std::vector<SupportedStreamConfiguration>& configs) { |
Biswarup Pal | 6152a30 | 2023-12-19 12:44:09 +0000 | [diff] [blame] | 170 | std::map<Resolution, int> resolutionToMaxFpsMap; |
| 171 | |
| 172 | for (const SupportedStreamConfiguration& config : configs) { |
| 173 | Resolution resolution(config.width, config.height); |
| 174 | if (resolutionToMaxFpsMap.find(resolution) == resolutionToMaxFpsMap.end()) { |
| 175 | resolutionToMaxFpsMap[resolution] = config.maxFps; |
| 176 | } else { |
| 177 | int currentMaxFps = resolutionToMaxFpsMap[resolution]; |
| 178 | resolutionToMaxFpsMap[resolution] = std::max(currentMaxFps, config.maxFps); |
| 179 | } |
| 180 | } |
| 181 | |
Jan Sebechlebsky | 4c9bb1e | 2024-02-28 16:32:39 +0100 | [diff] [blame] | 182 | std::map<Resolution, int> additionalResolutionToMaxFpsMap; |
| 183 | // Add additional resolutions we can support by downscaling input streams with |
| 184 | // same aspect ratio. |
| 185 | for (const Resolution& outputResolution : kOutputResolutions) { |
| 186 | for (const auto& [resolution, maxFps] : resolutionToMaxFpsMap) { |
| 187 | if (resolutionToMaxFpsMap.find(outputResolution) != |
| 188 | resolutionToMaxFpsMap.end()) { |
| 189 | // Resolution is already in the map, skip it. |
| 190 | continue; |
| 191 | } |
| 192 | |
| 193 | if (outputResolution < resolution && |
| 194 | isApproximatellySameAspectRatio(outputResolution, resolution)) { |
| 195 | // Lower resolution with same aspect ratio, we can achieve this by |
| 196 | // downscaling, let's add it to the map. |
| 197 | ALOGD( |
| 198 | "Extending set of output resolutions with %dx%d which has same " |
| 199 | "aspect ratio as supported input %dx%d.", |
| 200 | outputResolution.width, outputResolution.height, resolution.width, |
| 201 | resolution.height); |
| 202 | additionalResolutionToMaxFpsMap[outputResolution] = maxFps; |
| 203 | break; |
| 204 | } |
| 205 | } |
| 206 | } |
| 207 | |
| 208 | // Add all resolution we can achieve by downscaling to the map. |
| 209 | resolutionToMaxFpsMap.insert(additionalResolutionToMaxFpsMap.begin(), |
| 210 | additionalResolutionToMaxFpsMap.end()); |
| 211 | |
Biswarup Pal | 6152a30 | 2023-12-19 12:44:09 +0000 | [diff] [blame] | 212 | return resolutionToMaxFpsMap; |
Jan Sebechlebsky | 3b478c4 | 2023-11-23 13:15:56 +0100 | [diff] [blame] | 213 | } |
| 214 | |
Jan Sebechlebsky | 5cb3996 | 2023-11-22 17:33:07 +0100 | [diff] [blame] | 215 | // TODO(b/301023410) - Populate camera characteristics according to camera configuration. |
Jan Sebechlebsky | 3b478c4 | 2023-11-23 13:15:56 +0100 | [diff] [blame] | 216 | std::optional<CameraMetadata> initCameraCharacteristics( |
Biswarup Pal | 6152a30 | 2023-12-19 12:44:09 +0000 | [diff] [blame] | 217 | const std::vector<SupportedStreamConfiguration>& supportedInputConfig, |
Biswarup Pal | 37a7518 | 2024-01-16 15:53:35 +0000 | [diff] [blame] | 218 | const SensorOrientation sensorOrientation, const LensFacing lensFacing, |
| 219 | const int32_t deviceId) { |
Jan Sebechlebsky | 3b478c4 | 2023-11-23 13:15:56 +0100 | [diff] [blame] | 220 | if (!std::all_of(supportedInputConfig.begin(), supportedInputConfig.end(), |
| 221 | [](const SupportedStreamConfiguration& config) { |
Jan Sebechlebsky | 042d1fb | 2023-12-12 16:37:00 +0100 | [diff] [blame] | 222 | return isFormatSupportedForInput( |
Biswarup Pal | 6152a30 | 2023-12-19 12:44:09 +0000 | [diff] [blame] | 223 | config.width, config.height, config.pixelFormat, |
| 224 | config.maxFps); |
Jan Sebechlebsky | 3b478c4 | 2023-11-23 13:15:56 +0100 | [diff] [blame] | 225 | })) { |
Jan Sebechlebsky | 042d1fb | 2023-12-12 16:37:00 +0100 | [diff] [blame] | 226 | ALOGE("%s: input configuration contains unsupported format", __func__); |
Jan Sebechlebsky | 3b478c4 | 2023-11-23 13:15:56 +0100 | [diff] [blame] | 227 | return std::nullopt; |
| 228 | } |
| 229 | |
| 230 | MetadataBuilder builder = |
Jan Sebechlebsky | 5cb3996 | 2023-11-22 17:33:07 +0100 | [diff] [blame] | 231 | MetadataBuilder() |
| 232 | .setSupportedHardwareLevel( |
| 233 | ANDROID_INFO_SUPPORTED_HARDWARE_LEVEL_EXTERNAL) |
Biswarup Pal | 37a7518 | 2024-01-16 15:53:35 +0000 | [diff] [blame] | 234 | .setDeviceId(deviceId) |
Jan Sebechlebsky | 5cb3996 | 2023-11-22 17:33:07 +0100 | [diff] [blame] | 235 | .setFlashAvailable(false) |
Biswarup Pal | 112458f | 2023-12-28 19:50:17 +0000 | [diff] [blame] | 236 | .setLensFacing( |
| 237 | static_cast<camera_metadata_enum_android_lens_facing>(lensFacing)) |
Biswarup Pal | 8ad8bc5 | 2024-02-08 13:41:44 +0000 | [diff] [blame] | 238 | .setAvailableFocalLengths({VirtualCameraDevice::kFocalLength}) |
Biswarup Pal | 6152a30 | 2023-12-19 12:44:09 +0000 | [diff] [blame] | 239 | .setSensorOrientation(static_cast<int32_t>(sensorOrientation)) |
Jan Sebechlebsky | a984ffb | 2024-02-01 09:12:37 +0100 | [diff] [blame] | 240 | .setSensorReadoutTimestamp( |
| 241 | ANDROID_SENSOR_READOUT_TIMESTAMP_NOT_SUPPORTED) |
Jan Sebechlebsky | ad8d35f | 2024-02-05 11:58:59 +0100 | [diff] [blame] | 242 | .setSensorTimestampSource(ANDROID_SENSOR_INFO_TIMESTAMP_SOURCE_UNKNOWN) |
Biswarup Pal | d9be04d | 2024-01-31 14:35:15 +0000 | [diff] [blame] | 243 | .setSensorPhysicalSize(36.0, 24.0) |
Jan Sebechlebsky | ab37820 | 2024-02-26 10:50:42 +0100 | [diff] [blame] | 244 | .setAvailableAberrationCorrectionModes( |
| 245 | {ANDROID_COLOR_CORRECTION_ABERRATION_MODE_OFF}) |
| 246 | .setAvailableNoiseReductionModes({ANDROID_NOISE_REDUCTION_MODE_OFF}) |
Jan Sebechlebsky | 5cb3996 | 2023-11-22 17:33:07 +0100 | [diff] [blame] | 247 | .setAvailableFaceDetectModes({ANDROID_STATISTICS_FACE_DETECT_MODE_OFF}) |
Vadim Caen | 51d1f5c | 2024-04-09 16:19:08 +0200 | [diff] [blame] | 248 | .setAvailableStreamUseCases( |
| 249 | {ANDROID_SCALER_AVAILABLE_STREAM_USE_CASES_DEFAULT, |
| 250 | ANDROID_SCALER_AVAILABLE_STREAM_USE_CASES_PREVIEW, |
| 251 | ANDROID_SCALER_AVAILABLE_STREAM_USE_CASES_STILL_CAPTURE, |
| 252 | ANDROID_SCALER_AVAILABLE_STREAM_USE_CASES_VIDEO_RECORD, |
| 253 | ANDROID_SCALER_AVAILABLE_STREAM_USE_CASES_PREVIEW_VIDEO_STILL, |
| 254 | ANDROID_SCALER_AVAILABLE_STREAM_USE_CASES_VIDEO_CALL}) |
Jan Sebechlebsky | bb01c1d | 2024-02-12 11:41:37 +0100 | [diff] [blame] | 255 | .setAvailableTestPatternModes({ANDROID_SENSOR_TEST_PATTERN_MODE_OFF}) |
Jan Sebechlebsky | b0119fa | 2023-12-04 10:29:06 +0100 | [diff] [blame] | 256 | .setAvailableMaxDigitalZoom(1.0) |
| 257 | .setControlAvailableModes({ANDROID_CONTROL_MODE_AUTO}) |
Jan Sebechlebsky | 5cb3996 | 2023-11-22 17:33:07 +0100 | [diff] [blame] | 258 | .setControlAfAvailableModes({ANDROID_CONTROL_AF_MODE_OFF}) |
Jan Sebechlebsky | 4425a73 | 2024-01-31 11:31:54 +0100 | [diff] [blame] | 259 | .setControlAvailableSceneModes({ANDROID_CONTROL_SCENE_MODE_DISABLED}) |
| 260 | .setControlAvailableEffects({ANDROID_CONTROL_EFFECT_MODE_OFF}) |
Jan Sebechlebsky | bb01c1d | 2024-02-12 11:41:37 +0100 | [diff] [blame] | 261 | .setControlAvailableVideoStabilizationModes( |
| 262 | {ANDROID_CONTROL_VIDEO_STABILIZATION_MODE_OFF}) |
Jan Sebechlebsky | c3e1a63 | 2024-02-06 14:19:05 +0100 | [diff] [blame] | 263 | .setControlAeAvailableModes({ANDROID_CONTROL_AE_MODE_ON}) |
| 264 | .setControlAeAvailableAntibandingModes( |
| 265 | {ANDROID_CONTROL_AE_ANTIBANDING_MODE_AUTO}) |
| 266 | .setControlAeAvailableFpsRanges( |
| 267 | fpsRangesForInputConfig(supportedInputConfig)) |
Jan Sebechlebsky | 5cb3996 | 2023-11-22 17:33:07 +0100 | [diff] [blame] | 268 | .setControlMaxRegions(0, 0, 0) |
Jan Sebechlebsky | 5cb3996 | 2023-11-22 17:33:07 +0100 | [diff] [blame] | 269 | .setControlAfRegions({kDefaultEmptyControlRegion}) |
| 270 | .setControlAeRegions({kDefaultEmptyControlRegion}) |
| 271 | .setControlAwbRegions({kDefaultEmptyControlRegion}) |
Jan Sebechlebsky | c3e1a63 | 2024-02-06 14:19:05 +0100 | [diff] [blame] | 272 | .setControlAeCompensationRange(0, 0) |
Jan Sebechlebsky | 5cb3996 | 2023-11-22 17:33:07 +0100 | [diff] [blame] | 273 | .setControlAeCompensationStep(camera_metadata_rational_t{0, 1}) |
Jan Sebechlebsky | 4425a73 | 2024-01-31 11:31:54 +0100 | [diff] [blame] | 274 | .setControlAwbLockAvailable(false) |
| 275 | .setControlAeLockAvailable(false) |
| 276 | .setControlAvailableAwbModes({ANDROID_CONTROL_AWB_MODE_AUTO}) |
Jan Sebechlebsky | 6ab07fe | 2023-12-05 15:23:34 +0100 | [diff] [blame] | 277 | .setControlZoomRatioRange(/*min=*/1.0, /*max=*/1.0) |
Jan Sebechlebsky | ab37820 | 2024-02-26 10:50:42 +0100 | [diff] [blame] | 278 | .setCroppingType(ANDROID_SCALER_CROPPING_TYPE_CENTER_ONLY) |
Jan Sebechlebsky | 4ce3208 | 2024-02-14 16:02:11 +0100 | [diff] [blame] | 279 | .setJpegAvailableThumbnailSizes( |
| 280 | getSupportedJpegThumbnailSizes(supportedInputConfig)) |
Jan Sebechlebsky | 5cb3996 | 2023-11-22 17:33:07 +0100 | [diff] [blame] | 281 | .setMaxJpegSize(kMaxJpegSize) |
Jan Sebechlebsky | ab37820 | 2024-02-26 10:50:42 +0100 | [diff] [blame] | 282 | .setMaxFaceCount(0) |
Jan Sebechlebsky | bb01c1d | 2024-02-12 11:41:37 +0100 | [diff] [blame] | 283 | .setMaxFrameDuration(kMaxFrameDuration) |
Jan Sebechlebsky | 8ae2359 | 2024-02-02 16:08:18 +0100 | [diff] [blame] | 284 | .setMaxNumberOutputStreams( |
| 285 | VirtualCameraDevice::kMaxNumberOfRawStreams, |
| 286 | VirtualCameraDevice::kMaxNumberOfProcessedStreams, |
| 287 | VirtualCameraDevice::kMaxNumberOfStallStreams) |
Jan Sebechlebsky | ab37820 | 2024-02-26 10:50:42 +0100 | [diff] [blame] | 288 | .setRequestPartialResultCount(1) |
Jan Sebechlebsky | bb01c1d | 2024-02-12 11:41:37 +0100 | [diff] [blame] | 289 | .setPipelineMaxDepth(kPipelineMaxDepth) |
Jan Sebechlebsky | 4425a73 | 2024-01-31 11:31:54 +0100 | [diff] [blame] | 290 | .setSyncMaxLatency(ANDROID_SYNC_MAX_LATENCY_UNKNOWN) |
Jan Sebechlebsky | 4be2bd0 | 2024-02-26 18:35:18 +0100 | [diff] [blame] | 291 | .setAvailableRequestKeys({ANDROID_COLOR_CORRECTION_ABERRATION_MODE, |
| 292 | ANDROID_CONTROL_CAPTURE_INTENT, |
Jan Sebechlebsky | 4ce3208 | 2024-02-14 16:02:11 +0100 | [diff] [blame] | 293 | ANDROID_CONTROL_AE_MODE, |
| 294 | ANDROID_CONTROL_AE_EXPOSURE_COMPENSATION, |
| 295 | ANDROID_CONTROL_AE_TARGET_FPS_RANGE, |
| 296 | ANDROID_CONTROL_AE_ANTIBANDING_MODE, |
| 297 | ANDROID_CONTROL_AE_PRECAPTURE_TRIGGER, |
| 298 | ANDROID_CONTROL_AF_TRIGGER, |
| 299 | ANDROID_CONTROL_AF_MODE, |
| 300 | ANDROID_CONTROL_AWB_MODE, |
| 301 | ANDROID_SCALER_CROP_REGION, |
| 302 | ANDROID_CONTROL_EFFECT_MODE, |
| 303 | ANDROID_CONTROL_MODE, |
| 304 | ANDROID_CONTROL_SCENE_MODE, |
| 305 | ANDROID_CONTROL_VIDEO_STABILIZATION_MODE, |
| 306 | ANDROID_CONTROL_ZOOM_RATIO, |
Jan Sebechlebsky | 4ce3208 | 2024-02-14 16:02:11 +0100 | [diff] [blame] | 307 | ANDROID_FLASH_MODE, |
| 308 | ANDROID_JPEG_AVAILABLE_THUMBNAIL_SIZES, |
Vadim Caen | d86a3a4 | 2024-03-14 16:38:11 +0100 | [diff] [blame] | 309 | ANDROID_JPEG_ORIENTATION, |
Jan Sebechlebsky | 4ce3208 | 2024-02-14 16:02:11 +0100 | [diff] [blame] | 310 | ANDROID_JPEG_QUALITY, |
Jan Sebechlebsky | 4be2bd0 | 2024-02-26 18:35:18 +0100 | [diff] [blame] | 311 | ANDROID_JPEG_THUMBNAIL_QUALITY, |
Vadim Caen | d86a3a4 | 2024-03-14 16:38:11 +0100 | [diff] [blame] | 312 | ANDROID_JPEG_THUMBNAIL_SIZE, |
Jan Sebechlebsky | 4be2bd0 | 2024-02-26 18:35:18 +0100 | [diff] [blame] | 313 | ANDROID_NOISE_REDUCTION_MODE, |
| 314 | ANDROID_STATISTICS_FACE_DETECT_MODE}) |
Vadim Caen | 11dfd93 | 2024-03-05 09:57:20 +0100 | [diff] [blame] | 315 | .setAvailableResultKeys({ |
| 316 | ANDROID_COLOR_CORRECTION_ABERRATION_MODE, |
| 317 | ANDROID_CONTROL_AE_ANTIBANDING_MODE, |
| 318 | ANDROID_CONTROL_AE_EXPOSURE_COMPENSATION, |
| 319 | ANDROID_CONTROL_AE_LOCK, |
| 320 | ANDROID_CONTROL_AE_MODE, |
| 321 | ANDROID_CONTROL_AE_PRECAPTURE_TRIGGER, |
| 322 | ANDROID_CONTROL_AE_STATE, |
| 323 | ANDROID_CONTROL_AE_TARGET_FPS_RANGE, |
| 324 | ANDROID_CONTROL_AF_MODE, |
| 325 | ANDROID_CONTROL_AF_STATE, |
| 326 | ANDROID_CONTROL_AF_TRIGGER, |
| 327 | ANDROID_CONTROL_AWB_LOCK, |
| 328 | ANDROID_CONTROL_AWB_MODE, |
| 329 | ANDROID_CONTROL_AWB_STATE, |
| 330 | ANDROID_CONTROL_CAPTURE_INTENT, |
| 331 | ANDROID_CONTROL_EFFECT_MODE, |
| 332 | ANDROID_CONTROL_MODE, |
| 333 | ANDROID_CONTROL_SCENE_MODE, |
| 334 | ANDROID_CONTROL_VIDEO_STABILIZATION_MODE, |
| 335 | ANDROID_STATISTICS_FACE_DETECT_MODE, |
| 336 | ANDROID_FLASH_MODE, |
| 337 | ANDROID_FLASH_STATE, |
| 338 | ANDROID_JPEG_AVAILABLE_THUMBNAIL_SIZES, |
| 339 | ANDROID_JPEG_QUALITY, |
| 340 | ANDROID_JPEG_THUMBNAIL_QUALITY, |
| 341 | ANDROID_LENS_FOCAL_LENGTH, |
| 342 | ANDROID_LENS_OPTICAL_STABILIZATION_MODE, |
| 343 | ANDROID_NOISE_REDUCTION_MODE, |
| 344 | ANDROID_REQUEST_PIPELINE_DEPTH, |
| 345 | ANDROID_SENSOR_TIMESTAMP, |
| 346 | ANDROID_STATISTICS_HOT_PIXEL_MAP_MODE, |
| 347 | ANDROID_STATISTICS_LENS_SHADING_MAP_MODE, |
| 348 | ANDROID_STATISTICS_SCENE_FLICKER, |
| 349 | }) |
Jan Sebechlebsky | 5cb3996 | 2023-11-22 17:33:07 +0100 | [diff] [blame] | 350 | .setAvailableCapabilities( |
Jan Sebechlebsky | ad8d35f | 2024-02-05 11:58:59 +0100 | [diff] [blame] | 351 | {ANDROID_REQUEST_AVAILABLE_CAPABILITIES_BACKWARD_COMPATIBLE}); |
Jan Sebechlebsky | 5cb3996 | 2023-11-22 17:33:07 +0100 | [diff] [blame] | 352 | |
Jan Sebechlebsky | 3b478c4 | 2023-11-23 13:15:56 +0100 | [diff] [blame] | 353 | // Active array size must correspond to largest supported input resolution. |
| 354 | std::optional<Resolution> maxResolution = |
| 355 | getMaxResolution(supportedInputConfig); |
| 356 | if (!maxResolution.has_value()) { |
| 357 | return std::nullopt; |
| 358 | } |
| 359 | builder.setSensorActiveArraySize(0, 0, maxResolution->width, |
| 360 | maxResolution->height); |
Biswarup Pal | d9be04d | 2024-01-31 14:35:15 +0000 | [diff] [blame] | 361 | builder.setSensorPixelArraySize(maxResolution->width, maxResolution->height); |
Jan Sebechlebsky | 3b478c4 | 2023-11-23 13:15:56 +0100 | [diff] [blame] | 362 | |
| 363 | std::vector<MetadataBuilder::StreamConfiguration> outputConfigurations; |
| 364 | |
| 365 | // TODO(b/301023410) Add also all "standard" resolutions we can rescale the |
| 366 | // streams to (all standard resolutions with same aspect ratio). |
| 367 | |
Biswarup Pal | 6152a30 | 2023-12-19 12:44:09 +0000 | [diff] [blame] | 368 | std::map<Resolution, int> resolutionToMaxFpsMap = |
| 369 | getResolutionToMaxFpsMap(supportedInputConfig); |
Jan Sebechlebsky | 3b478c4 | 2023-11-23 13:15:56 +0100 | [diff] [blame] | 370 | |
Biswarup Pal | 6152a30 | 2023-12-19 12:44:09 +0000 | [diff] [blame] | 371 | // Add configurations for all unique input resolutions and output formats. |
Jan Sebechlebsky | 8ae2359 | 2024-02-02 16:08:18 +0100 | [diff] [blame] | 372 | for (const PixelFormat format : kOutputFormats) { |
Biswarup Pal | 6152a30 | 2023-12-19 12:44:09 +0000 | [diff] [blame] | 373 | std::transform( |
| 374 | resolutionToMaxFpsMap.begin(), resolutionToMaxFpsMap.end(), |
| 375 | std::back_inserter(outputConfigurations), [format](const auto& entry) { |
| 376 | Resolution resolution = entry.first; |
| 377 | int maxFps = entry.second; |
| 378 | return MetadataBuilder::StreamConfiguration{ |
| 379 | .width = resolution.width, |
| 380 | .height = resolution.height, |
Jan Sebechlebsky | 8ae2359 | 2024-02-02 16:08:18 +0100 | [diff] [blame] | 381 | .format = static_cast<int32_t>(format), |
Biswarup Pal | 6152a30 | 2023-12-19 12:44:09 +0000 | [diff] [blame] | 382 | .minFrameDuration = std::chrono::nanoseconds(1s) / maxFps, |
| 383 | .minStallDuration = 0s}; |
| 384 | }); |
| 385 | } |
Jan Sebechlebsky | 3b478c4 | 2023-11-23 13:15:56 +0100 | [diff] [blame] | 386 | |
| 387 | ALOGV("Adding %zu output configurations", outputConfigurations.size()); |
| 388 | builder.setAvailableOutputStreamConfigurations(outputConfigurations); |
| 389 | |
Jan Sebechlebsky | ad8d35f | 2024-02-05 11:58:59 +0100 | [diff] [blame] | 390 | auto metadata = builder.setAvailableCharacteristicKeys().build(); |
Jan Sebechlebsky | 5cb3996 | 2023-11-22 17:33:07 +0100 | [diff] [blame] | 391 | if (metadata == nullptr) { |
| 392 | ALOGE("Failed to build metadata!"); |
| 393 | return CameraMetadata(); |
| 394 | } |
| 395 | |
| 396 | return std::move(*metadata); |
| 397 | } |
| 398 | |
| 399 | } // namespace |
| 400 | |
| 401 | VirtualCameraDevice::VirtualCameraDevice( |
Biswarup Pal | 37a7518 | 2024-01-16 15:53:35 +0000 | [diff] [blame] | 402 | const uint32_t cameraId, const VirtualCameraConfiguration& configuration, |
| 403 | int32_t deviceId) |
Jan Sebechlebsky | 5cb3996 | 2023-11-22 17:33:07 +0100 | [diff] [blame] | 404 | : mCameraId(cameraId), |
Biswarup Pal | 6152a30 | 2023-12-19 12:44:09 +0000 | [diff] [blame] | 405 | mVirtualCameraClientCallback(configuration.virtualCameraCallback), |
| 406 | mSupportedInputConfigurations(configuration.supportedStreamConfigs) { |
| 407 | std::optional<CameraMetadata> metadata = initCameraCharacteristics( |
Biswarup Pal | 112458f | 2023-12-28 19:50:17 +0000 | [diff] [blame] | 408 | mSupportedInputConfigurations, configuration.sensorOrientation, |
Biswarup Pal | 37a7518 | 2024-01-16 15:53:35 +0000 | [diff] [blame] | 409 | configuration.lensFacing, deviceId); |
Jan Sebechlebsky | 3b478c4 | 2023-11-23 13:15:56 +0100 | [diff] [blame] | 410 | if (metadata.has_value()) { |
| 411 | mCameraCharacteristics = *metadata; |
| 412 | } else { |
| 413 | ALOGE( |
| 414 | "%s: Failed to initialize camera characteristic based on provided " |
| 415 | "configuration.", |
| 416 | __func__); |
| 417 | } |
Jan Sebechlebsky | 5cb3996 | 2023-11-22 17:33:07 +0100 | [diff] [blame] | 418 | } |
| 419 | |
| 420 | ndk::ScopedAStatus VirtualCameraDevice::getCameraCharacteristics( |
| 421 | CameraMetadata* _aidl_return) { |
| 422 | ALOGV("%s", __func__); |
| 423 | if (_aidl_return == nullptr) { |
| 424 | return cameraStatus(Status::ILLEGAL_ARGUMENT); |
| 425 | } |
| 426 | |
| 427 | *_aidl_return = mCameraCharacteristics; |
| 428 | return ndk::ScopedAStatus::ok(); |
| 429 | } |
| 430 | |
| 431 | ndk::ScopedAStatus VirtualCameraDevice::getPhysicalCameraCharacteristics( |
| 432 | const std::string& in_physicalCameraId, CameraMetadata* _aidl_return) { |
| 433 | ALOGV("%s: physicalCameraId %s", __func__, in_physicalCameraId.c_str()); |
| 434 | (void)_aidl_return; |
| 435 | |
| 436 | // VTS tests expect this call to fail with illegal argument status for |
| 437 | // all publicly advertised camera ids. |
| 438 | // Because we don't support physical camera ids, we just always |
| 439 | // fail with illegal argument (there's no valid argument to provide). |
| 440 | return cameraStatus(Status::ILLEGAL_ARGUMENT); |
| 441 | } |
| 442 | |
| 443 | ndk::ScopedAStatus VirtualCameraDevice::getResourceCost( |
| 444 | CameraResourceCost* _aidl_return) { |
| 445 | ALOGV("%s", __func__); |
| 446 | if (_aidl_return == nullptr) { |
| 447 | return cameraStatus(Status::ILLEGAL_ARGUMENT); |
| 448 | } |
| 449 | _aidl_return->resourceCost = 100; // ¯\_(ツ)_/¯ |
| 450 | return ndk::ScopedAStatus::ok(); |
| 451 | } |
| 452 | |
| 453 | ndk::ScopedAStatus VirtualCameraDevice::isStreamCombinationSupported( |
| 454 | const StreamConfiguration& in_streams, bool* _aidl_return) { |
| 455 | ALOGV("%s", __func__); |
| 456 | |
| 457 | if (_aidl_return == nullptr) { |
| 458 | return cameraStatus(Status::ILLEGAL_ARGUMENT); |
| 459 | } |
| 460 | |
Jan Sebechlebsky | 3b478c4 | 2023-11-23 13:15:56 +0100 | [diff] [blame] | 461 | *_aidl_return = isStreamCombinationSupported(in_streams); |
| 462 | return ndk::ScopedAStatus::ok(); |
| 463 | }; |
| 464 | |
| 465 | bool VirtualCameraDevice::isStreamCombinationSupported( |
| 466 | const StreamConfiguration& streamConfiguration) const { |
Jan Sebechlebsky | 39129f8 | 2024-01-19 16:42:11 +0100 | [diff] [blame] | 467 | if (streamConfiguration.streams.empty()) { |
| 468 | ALOGE("%s: Querying empty configuration", __func__); |
| 469 | return false; |
| 470 | } |
| 471 | |
Jan Sebechlebsky | 4c9bb1e | 2024-02-28 16:32:39 +0100 | [diff] [blame] | 472 | const std::vector<Stream>& streams = streamConfiguration.streams; |
| 473 | |
| 474 | Resolution firstStreamResolution(streams[0].width, streams[0].height); |
| 475 | auto isSameAspectRatioAsFirst = [firstStreamResolution](const Stream& stream) { |
| 476 | return isApproximatellySameAspectRatio( |
| 477 | firstStreamResolution, Resolution(stream.width, stream.height)); |
| 478 | }; |
| 479 | if (!std::all_of(streams.begin(), streams.end(), isSameAspectRatioAsFirst)) { |
| 480 | ALOGW( |
| 481 | "%s: Requested streams do not have same aspect ratio. Different aspect " |
| 482 | "ratios are currently " |
| 483 | "not supported by virtual camera. Stream configuration: %s", |
| 484 | __func__, streamConfiguration.toString().c_str()); |
| 485 | return false; |
| 486 | } |
| 487 | |
Jan Sebechlebsky | 8ae2359 | 2024-02-02 16:08:18 +0100 | [diff] [blame] | 488 | int numberOfProcessedStreams = 0; |
| 489 | int numberOfStallStreams = 0; |
Jan Sebechlebsky | 3b478c4 | 2023-11-23 13:15:56 +0100 | [diff] [blame] | 490 | for (const Stream& stream : streamConfiguration.streams) { |
Jan Sebechlebsky | 5cb3996 | 2023-11-22 17:33:07 +0100 | [diff] [blame] | 491 | ALOGV("%s: Configuration queried: %s", __func__, stream.toString().c_str()); |
| 492 | |
| 493 | if (stream.streamType == StreamType::INPUT) { |
| 494 | ALOGW("%s: Input stream type is not supported", __func__); |
Jan Sebechlebsky | 3b478c4 | 2023-11-23 13:15:56 +0100 | [diff] [blame] | 495 | return false; |
Jan Sebechlebsky | 5cb3996 | 2023-11-22 17:33:07 +0100 | [diff] [blame] | 496 | } |
| 497 | |
Jan Sebechlebsky | 3b478c4 | 2023-11-23 13:15:56 +0100 | [diff] [blame] | 498 | if (stream.rotation != StreamRotation::ROTATION_0 || |
Jan Sebechlebsky | 8ae2359 | 2024-02-02 16:08:18 +0100 | [diff] [blame] | 499 | !isSupportedOutputFormat(stream.format)) { |
Jan Sebechlebsky | 3b478c4 | 2023-11-23 13:15:56 +0100 | [diff] [blame] | 500 | ALOGV("Unsupported output stream type"); |
| 501 | return false; |
| 502 | } |
| 503 | |
Jan Sebechlebsky | 8ae2359 | 2024-02-02 16:08:18 +0100 | [diff] [blame] | 504 | if (stream.format == PixelFormat::BLOB) { |
| 505 | numberOfStallStreams++; |
| 506 | } else { |
| 507 | numberOfProcessedStreams++; |
| 508 | } |
| 509 | |
Jan Sebechlebsky | 4c9bb1e | 2024-02-28 16:32:39 +0100 | [diff] [blame] | 510 | Resolution requestedResolution(stream.width, stream.height); |
Jan Sebechlebsky | 3b478c4 | 2023-11-23 13:15:56 +0100 | [diff] [blame] | 511 | auto matchesSupportedInputConfig = |
Jan Sebechlebsky | 4c9bb1e | 2024-02-28 16:32:39 +0100 | [diff] [blame] | 512 | [requestedResolution](const SupportedStreamConfiguration& config) { |
| 513 | Resolution supportedInputResolution(config.width, config.height); |
| 514 | return requestedResolution <= supportedInputResolution && |
| 515 | isApproximatellySameAspectRatio(requestedResolution, |
| 516 | supportedInputResolution); |
Jan Sebechlebsky | 3b478c4 | 2023-11-23 13:15:56 +0100 | [diff] [blame] | 517 | }; |
| 518 | if (std::none_of(mSupportedInputConfigurations.begin(), |
| 519 | mSupportedInputConfigurations.end(), |
| 520 | matchesSupportedInputConfig)) { |
| 521 | ALOGV("Requested config doesn't match any supported input config"); |
| 522 | return false; |
Jan Sebechlebsky | 5cb3996 | 2023-11-22 17:33:07 +0100 | [diff] [blame] | 523 | } |
| 524 | } |
Jan Sebechlebsky | 8ae2359 | 2024-02-02 16:08:18 +0100 | [diff] [blame] | 525 | |
| 526 | if (numberOfProcessedStreams > kMaxNumberOfProcessedStreams) { |
| 527 | ALOGE("%s: %d processed streams exceeds the supported maximum of %d", |
| 528 | __func__, numberOfProcessedStreams, kMaxNumberOfProcessedStreams); |
| 529 | return false; |
| 530 | } |
| 531 | |
| 532 | if (numberOfStallStreams > kMaxNumberOfStallStreams) { |
| 533 | ALOGE("%s: %d stall streams exceeds the supported maximum of %d", __func__, |
| 534 | numberOfStallStreams, kMaxNumberOfStallStreams); |
| 535 | return false; |
| 536 | } |
| 537 | |
Jan Sebechlebsky | 3b478c4 | 2023-11-23 13:15:56 +0100 | [diff] [blame] | 538 | return true; |
| 539 | } |
Jan Sebechlebsky | 5cb3996 | 2023-11-22 17:33:07 +0100 | [diff] [blame] | 540 | |
| 541 | ndk::ScopedAStatus VirtualCameraDevice::open( |
| 542 | const std::shared_ptr<ICameraDeviceCallback>& in_callback, |
| 543 | std::shared_ptr<ICameraDeviceSession>* _aidl_return) { |
| 544 | ALOGV("%s", __func__); |
| 545 | |
| 546 | *_aidl_return = ndk::SharedRefBase::make<VirtualCameraSession>( |
Jan Sebechlebsky | 0bb5e09 | 2023-12-08 16:17:54 +0100 | [diff] [blame] | 547 | sharedFromThis(), in_callback, mVirtualCameraClientCallback); |
Jan Sebechlebsky | 5cb3996 | 2023-11-22 17:33:07 +0100 | [diff] [blame] | 548 | |
| 549 | return ndk::ScopedAStatus::ok(); |
| 550 | }; |
| 551 | |
| 552 | ndk::ScopedAStatus VirtualCameraDevice::openInjectionSession( |
| 553 | const std::shared_ptr<ICameraDeviceCallback>& in_callback, |
| 554 | std::shared_ptr<ICameraInjectionSession>* _aidl_return) { |
| 555 | ALOGV("%s", __func__); |
| 556 | |
| 557 | (void)in_callback; |
| 558 | (void)_aidl_return; |
| 559 | return cameraStatus(Status::OPERATION_NOT_SUPPORTED); |
| 560 | } |
| 561 | |
| 562 | ndk::ScopedAStatus VirtualCameraDevice::setTorchMode(bool in_on) { |
| 563 | ALOGV("%s: on = %s", __func__, in_on ? "on" : "off"); |
| 564 | return cameraStatus(Status::OPERATION_NOT_SUPPORTED); |
| 565 | } |
| 566 | |
| 567 | ndk::ScopedAStatus VirtualCameraDevice::turnOnTorchWithStrengthLevel( |
| 568 | int32_t in_torchStrength) { |
| 569 | ALOGV("%s: torchStrength = %d", __func__, in_torchStrength); |
| 570 | return cameraStatus(Status::OPERATION_NOT_SUPPORTED); |
| 571 | } |
| 572 | |
| 573 | ndk::ScopedAStatus VirtualCameraDevice::getTorchStrengthLevel( |
| 574 | int32_t* _aidl_return) { |
| 575 | (void)_aidl_return; |
| 576 | return cameraStatus(Status::OPERATION_NOT_SUPPORTED); |
| 577 | } |
| 578 | |
Vadim Caen | 918e6dc | 2024-04-08 11:14:50 +0200 | [diff] [blame^] | 579 | binder_status_t VirtualCameraDevice::dump(int fd, const char**, uint32_t) { |
| 580 | ALOGD("Dumping virtual camera %d", mCameraId); |
| 581 | const char* indent = " "; |
| 582 | const char* doubleIndent = " "; |
| 583 | dprintf(fd, "%svirtual_camera %d belongs to virtual device %d\n", indent, |
| 584 | mCameraId, |
| 585 | getDeviceId(mCameraCharacteristics) |
| 586 | .value_or(VirtualCameraService::kDefaultDeviceId)); |
| 587 | dprintf(fd, "%sSupportedStreamConfiguration:\n", indent); |
| 588 | for (auto& config : mSupportedInputConfigurations) { |
| 589 | dprintf(fd, "%s%s", doubleIndent, config.toString().c_str()); |
| 590 | } |
Jan Sebechlebsky | 5cb3996 | 2023-11-22 17:33:07 +0100 | [diff] [blame] | 591 | return STATUS_OK; |
| 592 | } |
| 593 | |
| 594 | std::string VirtualCameraDevice::getCameraName() const { |
| 595 | return std::string(kDevicePathPrefix) + std::to_string(mCameraId); |
| 596 | } |
| 597 | |
Jan Sebechlebsky | c3e1a63 | 2024-02-06 14:19:05 +0100 | [diff] [blame] | 598 | const std::vector<SupportedStreamConfiguration>& |
| 599 | VirtualCameraDevice::getInputConfigs() const { |
| 600 | return mSupportedInputConfigurations; |
| 601 | } |
| 602 | |
Jan Sebechlebsky | bb01c1d | 2024-02-12 11:41:37 +0100 | [diff] [blame] | 603 | Resolution VirtualCameraDevice::getMaxInputResolution() const { |
| 604 | std::optional<Resolution> maxResolution = |
| 605 | getMaxResolution(mSupportedInputConfigurations); |
| 606 | if (!maxResolution.has_value()) { |
| 607 | ALOGE( |
| 608 | "%s: Cannot determine sensor size for virtual camera - input " |
| 609 | "configurations empty?", |
| 610 | __func__); |
| 611 | return Resolution(0, 0); |
| 612 | } |
| 613 | return maxResolution.value(); |
| 614 | } |
| 615 | |
Jan Sebechlebsky | 0bb5e09 | 2023-12-08 16:17:54 +0100 | [diff] [blame] | 616 | std::shared_ptr<VirtualCameraDevice> VirtualCameraDevice::sharedFromThis() { |
| 617 | // SharedRefBase which BnCameraDevice inherits from breaks |
| 618 | // std::enable_shared_from_this. This is recommended replacement for |
| 619 | // shared_from_this() per documentation in binder_interface_utils.h. |
| 620 | return ref<VirtualCameraDevice>(); |
| 621 | } |
| 622 | |
Jan Sebechlebsky | 5cb3996 | 2023-11-22 17:33:07 +0100 | [diff] [blame] | 623 | } // namespace virtualcamera |
| 624 | } // namespace companion |
| 625 | } // namespace android |