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> |
| 26 | #include <optional> |
Jan Sebechlebsky | 5cb3996 | 2023-11-22 17:33:07 +0100 | [diff] [blame] | 27 | #include <string> |
| 28 | |
| 29 | #include "VirtualCameraSession.h" |
Jan Sebechlebsky | 3b478c4 | 2023-11-23 13:15:56 +0100 | [diff] [blame] | 30 | #include "aidl/android/companion/virtualcamera/SupportedStreamConfiguration.h" |
Biswarup Pal | 6152a30 | 2023-12-19 12:44:09 +0000 | [diff] [blame] | 31 | #include "aidl/android/companion/virtualcamera/VirtualCameraConfiguration.h" |
Jan Sebechlebsky | 5cb3996 | 2023-11-22 17:33:07 +0100 | [diff] [blame] | 32 | #include "aidl/android/hardware/camera/common/Status.h" |
| 33 | #include "aidl/android/hardware/camera/device/CameraMetadata.h" |
Jan Sebechlebsky | 3b478c4 | 2023-11-23 13:15:56 +0100 | [diff] [blame] | 34 | #include "aidl/android/hardware/camera/device/StreamConfiguration.h" |
Jan Sebechlebsky | 5cb3996 | 2023-11-22 17:33:07 +0100 | [diff] [blame] | 35 | #include "android/binder_auto_utils.h" |
| 36 | #include "android/binder_status.h" |
| 37 | #include "log/log.h" |
| 38 | #include "system/camera_metadata.h" |
| 39 | #include "util/MetadataBuilder.h" |
| 40 | #include "util/Util.h" |
| 41 | |
| 42 | namespace android { |
| 43 | namespace companion { |
| 44 | namespace virtualcamera { |
| 45 | |
Jan Sebechlebsky | 3b478c4 | 2023-11-23 13:15:56 +0100 | [diff] [blame] | 46 | using ::aidl::android::companion::virtualcamera::Format; |
Jan Sebechlebsky | 5cb3996 | 2023-11-22 17:33:07 +0100 | [diff] [blame] | 47 | using ::aidl::android::companion::virtualcamera::IVirtualCameraCallback; |
Biswarup Pal | 112458f | 2023-12-28 19:50:17 +0000 | [diff] [blame^] | 48 | using ::aidl::android::companion::virtualcamera::LensFacing; |
Biswarup Pal | 6152a30 | 2023-12-19 12:44:09 +0000 | [diff] [blame] | 49 | using ::aidl::android::companion::virtualcamera::SensorOrientation; |
Jan Sebechlebsky | 3b478c4 | 2023-11-23 13:15:56 +0100 | [diff] [blame] | 50 | using ::aidl::android::companion::virtualcamera::SupportedStreamConfiguration; |
Biswarup Pal | 6152a30 | 2023-12-19 12:44:09 +0000 | [diff] [blame] | 51 | using ::aidl::android::companion::virtualcamera::VirtualCameraConfiguration; |
Jan Sebechlebsky | 5cb3996 | 2023-11-22 17:33:07 +0100 | [diff] [blame] | 52 | using ::aidl::android::hardware::camera::common::CameraResourceCost; |
| 53 | using ::aidl::android::hardware::camera::common::Status; |
| 54 | using ::aidl::android::hardware::camera::device::CameraMetadata; |
| 55 | using ::aidl::android::hardware::camera::device::ICameraDeviceCallback; |
| 56 | using ::aidl::android::hardware::camera::device::ICameraDeviceSession; |
| 57 | using ::aidl::android::hardware::camera::device::ICameraInjectionSession; |
Jan Sebechlebsky | 3b478c4 | 2023-11-23 13:15:56 +0100 | [diff] [blame] | 58 | using ::aidl::android::hardware::camera::device::Stream; |
Jan Sebechlebsky | 5cb3996 | 2023-11-22 17:33:07 +0100 | [diff] [blame] | 59 | using ::aidl::android::hardware::camera::device::StreamConfiguration; |
| 60 | using ::aidl::android::hardware::camera::device::StreamRotation; |
| 61 | using ::aidl::android::hardware::camera::device::StreamType; |
| 62 | using ::aidl::android::hardware::graphics::common::PixelFormat; |
| 63 | |
| 64 | namespace { |
| 65 | |
| 66 | using namespace std::chrono_literals; |
| 67 | |
| 68 | // Prefix of camera name - "device@1.1/virtual/{numerical_id}" |
| 69 | const char* kDevicePathPrefix = "device@1.1/virtual/"; |
| 70 | |
Jan Sebechlebsky | 5cb3996 | 2023-11-22 17:33:07 +0100 | [diff] [blame] | 71 | constexpr int32_t kMaxJpegSize = 3 * 1024 * 1024 /*3MiB*/; |
| 72 | |
| 73 | constexpr MetadataBuilder::ControlRegion kDefaultEmptyControlRegion{}; |
| 74 | |
Biswarup Pal | 6152a30 | 2023-12-19 12:44:09 +0000 | [diff] [blame] | 75 | const std::array<int32_t, 3> kOutputFormats{ |
| 76 | ANDROID_SCALER_AVAILABLE_FORMATS_IMPLEMENTATION_DEFINED, |
| 77 | ANDROID_SCALER_AVAILABLE_FORMATS_YCbCr_420_888, |
| 78 | ANDROID_SCALER_AVAILABLE_FORMATS_BLOB}; |
| 79 | |
Jan Sebechlebsky | 3b478c4 | 2023-11-23 13:15:56 +0100 | [diff] [blame] | 80 | struct Resolution { |
| 81 | Resolution(const int w, const int h) : width(w), height(h) { |
| 82 | } |
| 83 | |
| 84 | bool operator<(const Resolution& other) const { |
| 85 | return width * height < other.width * other.height; |
| 86 | } |
| 87 | |
| 88 | bool operator==(const Resolution& other) const { |
| 89 | return width == other.width && height == other.height; |
| 90 | } |
| 91 | |
| 92 | const int width; |
| 93 | const int height; |
| 94 | }; |
| 95 | |
| 96 | std::optional<Resolution> getMaxResolution( |
| 97 | const std::vector<SupportedStreamConfiguration>& configs) { |
| 98 | auto itMax = std::max_element(configs.begin(), configs.end(), |
| 99 | [](const SupportedStreamConfiguration& a, |
| 100 | const SupportedStreamConfiguration& b) { |
| 101 | return a.width * b.height < a.width * b.height; |
| 102 | }); |
| 103 | if (itMax == configs.end()) { |
| 104 | ALOGE( |
| 105 | "%s: empty vector of supported configurations, cannot find largest " |
| 106 | "resolution.", |
| 107 | __func__); |
| 108 | return std::nullopt; |
| 109 | } |
| 110 | |
| 111 | return Resolution(itMax->width, itMax->height); |
| 112 | } |
| 113 | |
Biswarup Pal | 6152a30 | 2023-12-19 12:44:09 +0000 | [diff] [blame] | 114 | // Returns a map of unique resolution to maximum maxFps for all streams with |
| 115 | // that resolution. |
| 116 | std::map<Resolution, int> getResolutionToMaxFpsMap( |
Jan Sebechlebsky | 3b478c4 | 2023-11-23 13:15:56 +0100 | [diff] [blame] | 117 | const std::vector<SupportedStreamConfiguration>& configs) { |
Biswarup Pal | 6152a30 | 2023-12-19 12:44:09 +0000 | [diff] [blame] | 118 | std::map<Resolution, int> resolutionToMaxFpsMap; |
| 119 | |
| 120 | for (const SupportedStreamConfiguration& config : configs) { |
| 121 | Resolution resolution(config.width, config.height); |
| 122 | if (resolutionToMaxFpsMap.find(resolution) == resolutionToMaxFpsMap.end()) { |
| 123 | resolutionToMaxFpsMap[resolution] = config.maxFps; |
| 124 | } else { |
| 125 | int currentMaxFps = resolutionToMaxFpsMap[resolution]; |
| 126 | resolutionToMaxFpsMap[resolution] = std::max(currentMaxFps, config.maxFps); |
| 127 | } |
| 128 | } |
| 129 | |
| 130 | return resolutionToMaxFpsMap; |
Jan Sebechlebsky | 3b478c4 | 2023-11-23 13:15:56 +0100 | [diff] [blame] | 131 | } |
| 132 | |
Jan Sebechlebsky | 5cb3996 | 2023-11-22 17:33:07 +0100 | [diff] [blame] | 133 | // TODO(b/301023410) - Populate camera characteristics according to camera configuration. |
Jan Sebechlebsky | 3b478c4 | 2023-11-23 13:15:56 +0100 | [diff] [blame] | 134 | std::optional<CameraMetadata> initCameraCharacteristics( |
Biswarup Pal | 6152a30 | 2023-12-19 12:44:09 +0000 | [diff] [blame] | 135 | const std::vector<SupportedStreamConfiguration>& supportedInputConfig, |
Biswarup Pal | 112458f | 2023-12-28 19:50:17 +0000 | [diff] [blame^] | 136 | const SensorOrientation sensorOrientation, const LensFacing lensFacing) { |
Jan Sebechlebsky | 3b478c4 | 2023-11-23 13:15:56 +0100 | [diff] [blame] | 137 | if (!std::all_of(supportedInputConfig.begin(), supportedInputConfig.end(), |
| 138 | [](const SupportedStreamConfiguration& config) { |
Jan Sebechlebsky | 042d1fb | 2023-12-12 16:37:00 +0100 | [diff] [blame] | 139 | return isFormatSupportedForInput( |
Biswarup Pal | 6152a30 | 2023-12-19 12:44:09 +0000 | [diff] [blame] | 140 | config.width, config.height, config.pixelFormat, |
| 141 | config.maxFps); |
Jan Sebechlebsky | 3b478c4 | 2023-11-23 13:15:56 +0100 | [diff] [blame] | 142 | })) { |
Jan Sebechlebsky | 042d1fb | 2023-12-12 16:37:00 +0100 | [diff] [blame] | 143 | ALOGE("%s: input configuration contains unsupported format", __func__); |
Jan Sebechlebsky | 3b478c4 | 2023-11-23 13:15:56 +0100 | [diff] [blame] | 144 | return std::nullopt; |
| 145 | } |
| 146 | |
| 147 | MetadataBuilder builder = |
Jan Sebechlebsky | 5cb3996 | 2023-11-22 17:33:07 +0100 | [diff] [blame] | 148 | MetadataBuilder() |
| 149 | .setSupportedHardwareLevel( |
| 150 | ANDROID_INFO_SUPPORTED_HARDWARE_LEVEL_EXTERNAL) |
| 151 | .setFlashAvailable(false) |
Biswarup Pal | 112458f | 2023-12-28 19:50:17 +0000 | [diff] [blame^] | 152 | .setLensFacing( |
| 153 | static_cast<camera_metadata_enum_android_lens_facing>(lensFacing)) |
Biswarup Pal | 6152a30 | 2023-12-19 12:44:09 +0000 | [diff] [blame] | 154 | .setSensorOrientation(static_cast<int32_t>(sensorOrientation)) |
Jan Sebechlebsky | 5cb3996 | 2023-11-22 17:33:07 +0100 | [diff] [blame] | 155 | .setAvailableFaceDetectModes({ANDROID_STATISTICS_FACE_DETECT_MODE_OFF}) |
Jan Sebechlebsky | b0119fa | 2023-12-04 10:29:06 +0100 | [diff] [blame] | 156 | .setAvailableMaxDigitalZoom(1.0) |
| 157 | .setControlAvailableModes({ANDROID_CONTROL_MODE_AUTO}) |
Jan Sebechlebsky | 5cb3996 | 2023-11-22 17:33:07 +0100 | [diff] [blame] | 158 | .setControlAfAvailableModes({ANDROID_CONTROL_AF_MODE_OFF}) |
Jan Sebechlebsky | 5cb3996 | 2023-11-22 17:33:07 +0100 | [diff] [blame] | 159 | .setControlAeAvailableFpsRange(10, 30) |
| 160 | .setControlMaxRegions(0, 0, 0) |
Jan Sebechlebsky | 5cb3996 | 2023-11-22 17:33:07 +0100 | [diff] [blame] | 161 | .setControlAfRegions({kDefaultEmptyControlRegion}) |
| 162 | .setControlAeRegions({kDefaultEmptyControlRegion}) |
| 163 | .setControlAwbRegions({kDefaultEmptyControlRegion}) |
| 164 | .setControlAeCompensationRange(0, 1) |
| 165 | .setControlAeCompensationStep(camera_metadata_rational_t{0, 1}) |
Jan Sebechlebsky | 6ab07fe | 2023-12-05 15:23:34 +0100 | [diff] [blame] | 166 | .setControlZoomRatioRange(/*min=*/1.0, /*max=*/1.0) |
Jan Sebechlebsky | 5cb3996 | 2023-11-22 17:33:07 +0100 | [diff] [blame] | 167 | .setMaxJpegSize(kMaxJpegSize) |
| 168 | .setAvailableRequestKeys({ANDROID_CONTROL_AF_MODE}) |
| 169 | .setAvailableResultKeys({ANDROID_CONTROL_AF_MODE}) |
| 170 | .setAvailableCapabilities( |
| 171 | {ANDROID_REQUEST_AVAILABLE_CAPABILITIES_BACKWARD_COMPATIBLE}) |
Jan Sebechlebsky | 3b478c4 | 2023-11-23 13:15:56 +0100 | [diff] [blame] | 172 | .setAvailableCharacteristicKeys(); |
Jan Sebechlebsky | 5cb3996 | 2023-11-22 17:33:07 +0100 | [diff] [blame] | 173 | |
Jan Sebechlebsky | 3b478c4 | 2023-11-23 13:15:56 +0100 | [diff] [blame] | 174 | // Active array size must correspond to largest supported input resolution. |
| 175 | std::optional<Resolution> maxResolution = |
| 176 | getMaxResolution(supportedInputConfig); |
| 177 | if (!maxResolution.has_value()) { |
| 178 | return std::nullopt; |
| 179 | } |
| 180 | builder.setSensorActiveArraySize(0, 0, maxResolution->width, |
| 181 | maxResolution->height); |
| 182 | |
| 183 | std::vector<MetadataBuilder::StreamConfiguration> outputConfigurations; |
| 184 | |
| 185 | // TODO(b/301023410) Add also all "standard" resolutions we can rescale the |
| 186 | // streams to (all standard resolutions with same aspect ratio). |
| 187 | |
Biswarup Pal | 6152a30 | 2023-12-19 12:44:09 +0000 | [diff] [blame] | 188 | std::map<Resolution, int> resolutionToMaxFpsMap = |
| 189 | getResolutionToMaxFpsMap(supportedInputConfig); |
Jan Sebechlebsky | 3b478c4 | 2023-11-23 13:15:56 +0100 | [diff] [blame] | 190 | |
Biswarup Pal | 6152a30 | 2023-12-19 12:44:09 +0000 | [diff] [blame] | 191 | // Add configurations for all unique input resolutions and output formats. |
| 192 | for (int32_t format : kOutputFormats) { |
| 193 | std::transform( |
| 194 | resolutionToMaxFpsMap.begin(), resolutionToMaxFpsMap.end(), |
| 195 | std::back_inserter(outputConfigurations), [format](const auto& entry) { |
| 196 | Resolution resolution = entry.first; |
| 197 | int maxFps = entry.second; |
| 198 | return MetadataBuilder::StreamConfiguration{ |
| 199 | .width = resolution.width, |
| 200 | .height = resolution.height, |
| 201 | .format = format, |
| 202 | .minFrameDuration = std::chrono::nanoseconds(1s) / maxFps, |
| 203 | .minStallDuration = 0s}; |
| 204 | }); |
| 205 | } |
Jan Sebechlebsky | 3b478c4 | 2023-11-23 13:15:56 +0100 | [diff] [blame] | 206 | |
| 207 | ALOGV("Adding %zu output configurations", outputConfigurations.size()); |
| 208 | builder.setAvailableOutputStreamConfigurations(outputConfigurations); |
| 209 | |
| 210 | auto metadata = builder.build(); |
Jan Sebechlebsky | 5cb3996 | 2023-11-22 17:33:07 +0100 | [diff] [blame] | 211 | if (metadata == nullptr) { |
| 212 | ALOGE("Failed to build metadata!"); |
| 213 | return CameraMetadata(); |
| 214 | } |
| 215 | |
| 216 | return std::move(*metadata); |
| 217 | } |
| 218 | |
| 219 | } // namespace |
| 220 | |
| 221 | VirtualCameraDevice::VirtualCameraDevice( |
Biswarup Pal | 6152a30 | 2023-12-19 12:44:09 +0000 | [diff] [blame] | 222 | const uint32_t cameraId, const VirtualCameraConfiguration& configuration) |
Jan Sebechlebsky | 5cb3996 | 2023-11-22 17:33:07 +0100 | [diff] [blame] | 223 | : mCameraId(cameraId), |
Biswarup Pal | 6152a30 | 2023-12-19 12:44:09 +0000 | [diff] [blame] | 224 | mVirtualCameraClientCallback(configuration.virtualCameraCallback), |
| 225 | mSupportedInputConfigurations(configuration.supportedStreamConfigs) { |
| 226 | std::optional<CameraMetadata> metadata = initCameraCharacteristics( |
Biswarup Pal | 112458f | 2023-12-28 19:50:17 +0000 | [diff] [blame^] | 227 | mSupportedInputConfigurations, configuration.sensorOrientation, |
| 228 | configuration.lensFacing); |
Jan Sebechlebsky | 3b478c4 | 2023-11-23 13:15:56 +0100 | [diff] [blame] | 229 | if (metadata.has_value()) { |
| 230 | mCameraCharacteristics = *metadata; |
| 231 | } else { |
| 232 | ALOGE( |
| 233 | "%s: Failed to initialize camera characteristic based on provided " |
| 234 | "configuration.", |
| 235 | __func__); |
| 236 | } |
Jan Sebechlebsky | 5cb3996 | 2023-11-22 17:33:07 +0100 | [diff] [blame] | 237 | } |
| 238 | |
| 239 | ndk::ScopedAStatus VirtualCameraDevice::getCameraCharacteristics( |
| 240 | CameraMetadata* _aidl_return) { |
| 241 | ALOGV("%s", __func__); |
| 242 | if (_aidl_return == nullptr) { |
| 243 | return cameraStatus(Status::ILLEGAL_ARGUMENT); |
| 244 | } |
| 245 | |
| 246 | *_aidl_return = mCameraCharacteristics; |
| 247 | return ndk::ScopedAStatus::ok(); |
| 248 | } |
| 249 | |
| 250 | ndk::ScopedAStatus VirtualCameraDevice::getPhysicalCameraCharacteristics( |
| 251 | const std::string& in_physicalCameraId, CameraMetadata* _aidl_return) { |
| 252 | ALOGV("%s: physicalCameraId %s", __func__, in_physicalCameraId.c_str()); |
| 253 | (void)_aidl_return; |
| 254 | |
| 255 | // VTS tests expect this call to fail with illegal argument status for |
| 256 | // all publicly advertised camera ids. |
| 257 | // Because we don't support physical camera ids, we just always |
| 258 | // fail with illegal argument (there's no valid argument to provide). |
| 259 | return cameraStatus(Status::ILLEGAL_ARGUMENT); |
| 260 | } |
| 261 | |
| 262 | ndk::ScopedAStatus VirtualCameraDevice::getResourceCost( |
| 263 | CameraResourceCost* _aidl_return) { |
| 264 | ALOGV("%s", __func__); |
| 265 | if (_aidl_return == nullptr) { |
| 266 | return cameraStatus(Status::ILLEGAL_ARGUMENT); |
| 267 | } |
| 268 | _aidl_return->resourceCost = 100; // ¯\_(ツ)_/¯ |
| 269 | return ndk::ScopedAStatus::ok(); |
| 270 | } |
| 271 | |
| 272 | ndk::ScopedAStatus VirtualCameraDevice::isStreamCombinationSupported( |
| 273 | const StreamConfiguration& in_streams, bool* _aidl_return) { |
| 274 | ALOGV("%s", __func__); |
| 275 | |
| 276 | if (_aidl_return == nullptr) { |
| 277 | return cameraStatus(Status::ILLEGAL_ARGUMENT); |
| 278 | } |
| 279 | |
Jan Sebechlebsky | 3b478c4 | 2023-11-23 13:15:56 +0100 | [diff] [blame] | 280 | *_aidl_return = isStreamCombinationSupported(in_streams); |
| 281 | return ndk::ScopedAStatus::ok(); |
| 282 | }; |
| 283 | |
| 284 | bool VirtualCameraDevice::isStreamCombinationSupported( |
| 285 | const StreamConfiguration& streamConfiguration) const { |
| 286 | for (const Stream& stream : streamConfiguration.streams) { |
Jan Sebechlebsky | 5cb3996 | 2023-11-22 17:33:07 +0100 | [diff] [blame] | 287 | ALOGV("%s: Configuration queried: %s", __func__, stream.toString().c_str()); |
| 288 | |
| 289 | if (stream.streamType == StreamType::INPUT) { |
| 290 | ALOGW("%s: Input stream type is not supported", __func__); |
Jan Sebechlebsky | 3b478c4 | 2023-11-23 13:15:56 +0100 | [diff] [blame] | 291 | return false; |
Jan Sebechlebsky | 5cb3996 | 2023-11-22 17:33:07 +0100 | [diff] [blame] | 292 | } |
| 293 | |
| 294 | // TODO(b/301023410) remove hardcoded format checks, verify against configuration. |
Jan Sebechlebsky | 3b478c4 | 2023-11-23 13:15:56 +0100 | [diff] [blame] | 295 | if (stream.rotation != StreamRotation::ROTATION_0 || |
Jan Sebechlebsky | 5cb3996 | 2023-11-22 17:33:07 +0100 | [diff] [blame] | 296 | (stream.format != PixelFormat::IMPLEMENTATION_DEFINED && |
| 297 | stream.format != PixelFormat::YCBCR_420_888 && |
| 298 | stream.format != PixelFormat::BLOB)) { |
Jan Sebechlebsky | 3b478c4 | 2023-11-23 13:15:56 +0100 | [diff] [blame] | 299 | ALOGV("Unsupported output stream type"); |
| 300 | return false; |
| 301 | } |
| 302 | |
| 303 | auto matchesSupportedInputConfig = |
| 304 | [&stream](const SupportedStreamConfiguration& config) { |
| 305 | return stream.width == config.width && stream.height == config.height; |
| 306 | }; |
| 307 | if (std::none_of(mSupportedInputConfigurations.begin(), |
| 308 | mSupportedInputConfigurations.end(), |
| 309 | matchesSupportedInputConfig)) { |
| 310 | ALOGV("Requested config doesn't match any supported input config"); |
| 311 | return false; |
Jan Sebechlebsky | 5cb3996 | 2023-11-22 17:33:07 +0100 | [diff] [blame] | 312 | } |
| 313 | } |
Jan Sebechlebsky | 3b478c4 | 2023-11-23 13:15:56 +0100 | [diff] [blame] | 314 | return true; |
| 315 | } |
Jan Sebechlebsky | 5cb3996 | 2023-11-22 17:33:07 +0100 | [diff] [blame] | 316 | |
| 317 | ndk::ScopedAStatus VirtualCameraDevice::open( |
| 318 | const std::shared_ptr<ICameraDeviceCallback>& in_callback, |
| 319 | std::shared_ptr<ICameraDeviceSession>* _aidl_return) { |
| 320 | ALOGV("%s", __func__); |
| 321 | |
| 322 | *_aidl_return = ndk::SharedRefBase::make<VirtualCameraSession>( |
Jan Sebechlebsky | 0bb5e09 | 2023-12-08 16:17:54 +0100 | [diff] [blame] | 323 | sharedFromThis(), in_callback, mVirtualCameraClientCallback); |
Jan Sebechlebsky | 5cb3996 | 2023-11-22 17:33:07 +0100 | [diff] [blame] | 324 | |
| 325 | return ndk::ScopedAStatus::ok(); |
| 326 | }; |
| 327 | |
| 328 | ndk::ScopedAStatus VirtualCameraDevice::openInjectionSession( |
| 329 | const std::shared_ptr<ICameraDeviceCallback>& in_callback, |
| 330 | std::shared_ptr<ICameraInjectionSession>* _aidl_return) { |
| 331 | ALOGV("%s", __func__); |
| 332 | |
| 333 | (void)in_callback; |
| 334 | (void)_aidl_return; |
| 335 | return cameraStatus(Status::OPERATION_NOT_SUPPORTED); |
| 336 | } |
| 337 | |
| 338 | ndk::ScopedAStatus VirtualCameraDevice::setTorchMode(bool in_on) { |
| 339 | ALOGV("%s: on = %s", __func__, in_on ? "on" : "off"); |
| 340 | return cameraStatus(Status::OPERATION_NOT_SUPPORTED); |
| 341 | } |
| 342 | |
| 343 | ndk::ScopedAStatus VirtualCameraDevice::turnOnTorchWithStrengthLevel( |
| 344 | int32_t in_torchStrength) { |
| 345 | ALOGV("%s: torchStrength = %d", __func__, in_torchStrength); |
| 346 | return cameraStatus(Status::OPERATION_NOT_SUPPORTED); |
| 347 | } |
| 348 | |
| 349 | ndk::ScopedAStatus VirtualCameraDevice::getTorchStrengthLevel( |
| 350 | int32_t* _aidl_return) { |
| 351 | (void)_aidl_return; |
| 352 | return cameraStatus(Status::OPERATION_NOT_SUPPORTED); |
| 353 | } |
| 354 | |
| 355 | binder_status_t VirtualCameraDevice::dump(int fd, const char** args, |
| 356 | uint32_t numArgs) { |
| 357 | // TODO(b/301023410) Implement. |
| 358 | (void)fd; |
| 359 | (void)args; |
| 360 | (void)numArgs; |
| 361 | return STATUS_OK; |
| 362 | } |
| 363 | |
| 364 | std::string VirtualCameraDevice::getCameraName() const { |
| 365 | return std::string(kDevicePathPrefix) + std::to_string(mCameraId); |
| 366 | } |
| 367 | |
Jan Sebechlebsky | 0bb5e09 | 2023-12-08 16:17:54 +0100 | [diff] [blame] | 368 | std::shared_ptr<VirtualCameraDevice> VirtualCameraDevice::sharedFromThis() { |
| 369 | // SharedRefBase which BnCameraDevice inherits from breaks |
| 370 | // std::enable_shared_from_this. This is recommended replacement for |
| 371 | // shared_from_this() per documentation in binder_interface_utils.h. |
| 372 | return ref<VirtualCameraDevice>(); |
| 373 | } |
| 374 | |
Jan Sebechlebsky | 5cb3996 | 2023-11-22 17:33:07 +0100 | [diff] [blame] | 375 | } // namespace virtualcamera |
| 376 | } // namespace companion |
| 377 | } // namespace android |