blob: fccbbc9c418d61c2747ea93cbc7e54e848b66129 [file] [log] [blame]
Jan Sebechlebsky5cb39962023-11-22 17:33:07 +01001/*
Biswarup Pal6152a302023-12-19 12:44:09 +00002 * Copyright 2023 The Android Open Source Project
Jan Sebechlebsky5cb39962023-11-22 17:33:07 +01003 *
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 Sebechlebsky3b478c42023-11-23 13:15:56 +010021#include <algorithm>
22#include <array>
Jan Sebechlebsky5cb39962023-11-22 17:33:07 +010023#include <chrono>
24#include <cstdint>
Jan Sebechlebsky3b478c42023-11-23 13:15:56 +010025#include <iterator>
Jan Sebechlebskyc3e1a632024-02-06 14:19:05 +010026#include <numeric>
Jan Sebechlebsky3b478c42023-11-23 13:15:56 +010027#include <optional>
Jan Sebechlebsky5cb39962023-11-22 17:33:07 +010028#include <string>
Jan Sebechlebskyc3e1a632024-02-06 14:19:05 +010029#include <vector>
Jan Sebechlebsky5cb39962023-11-22 17:33:07 +010030
31#include "VirtualCameraSession.h"
Jan Sebechlebsky3b478c42023-11-23 13:15:56 +010032#include "aidl/android/companion/virtualcamera/SupportedStreamConfiguration.h"
Biswarup Pal6152a302023-12-19 12:44:09 +000033#include "aidl/android/companion/virtualcamera/VirtualCameraConfiguration.h"
Jan Sebechlebsky5cb39962023-11-22 17:33:07 +010034#include "aidl/android/hardware/camera/common/Status.h"
35#include "aidl/android/hardware/camera/device/CameraMetadata.h"
Jan Sebechlebsky3b478c42023-11-23 13:15:56 +010036#include "aidl/android/hardware/camera/device/StreamConfiguration.h"
Jan Sebechlebsky5cb39962023-11-22 17:33:07 +010037#include "android/binder_auto_utils.h"
38#include "android/binder_status.h"
39#include "log/log.h"
40#include "system/camera_metadata.h"
41#include "util/MetadataBuilder.h"
42#include "util/Util.h"
43
44namespace android {
45namespace companion {
46namespace virtualcamera {
47
Jan Sebechlebsky3b478c42023-11-23 13:15:56 +010048using ::aidl::android::companion::virtualcamera::Format;
Jan Sebechlebsky5cb39962023-11-22 17:33:07 +010049using ::aidl::android::companion::virtualcamera::IVirtualCameraCallback;
Biswarup Pal112458f2023-12-28 19:50:17 +000050using ::aidl::android::companion::virtualcamera::LensFacing;
Biswarup Pal6152a302023-12-19 12:44:09 +000051using ::aidl::android::companion::virtualcamera::SensorOrientation;
Jan Sebechlebsky3b478c42023-11-23 13:15:56 +010052using ::aidl::android::companion::virtualcamera::SupportedStreamConfiguration;
Biswarup Pal6152a302023-12-19 12:44:09 +000053using ::aidl::android::companion::virtualcamera::VirtualCameraConfiguration;
Jan Sebechlebsky5cb39962023-11-22 17:33:07 +010054using ::aidl::android::hardware::camera::common::CameraResourceCost;
55using ::aidl::android::hardware::camera::common::Status;
56using ::aidl::android::hardware::camera::device::CameraMetadata;
57using ::aidl::android::hardware::camera::device::ICameraDeviceCallback;
58using ::aidl::android::hardware::camera::device::ICameraDeviceSession;
59using ::aidl::android::hardware::camera::device::ICameraInjectionSession;
Jan Sebechlebsky3b478c42023-11-23 13:15:56 +010060using ::aidl::android::hardware::camera::device::Stream;
Jan Sebechlebsky5cb39962023-11-22 17:33:07 +010061using ::aidl::android::hardware::camera::device::StreamConfiguration;
62using ::aidl::android::hardware::camera::device::StreamRotation;
63using ::aidl::android::hardware::camera::device::StreamType;
64using ::aidl::android::hardware::graphics::common::PixelFormat;
65
66namespace {
67
68using namespace std::chrono_literals;
69
70// Prefix of camera name - "device@1.1/virtual/{numerical_id}"
71const char* kDevicePathPrefix = "device@1.1/virtual/";
72
Jan Sebechlebsky5cb39962023-11-22 17:33:07 +010073constexpr int32_t kMaxJpegSize = 3 * 1024 * 1024 /*3MiB*/;
74
75constexpr MetadataBuilder::ControlRegion kDefaultEmptyControlRegion{};
76
Jan Sebechlebsky8ae23592024-02-02 16:08:18 +010077const std::array<PixelFormat, 3> kOutputFormats{
78 PixelFormat::IMPLEMENTATION_DEFINED, PixelFormat::YCBCR_420_888,
79 PixelFormat::BLOB};
Biswarup Pal6152a302023-12-19 12:44:09 +000080
Jan Sebechlebsky8ae23592024-02-02 16:08:18 +010081bool isSupportedOutputFormat(const PixelFormat pixelFormat) {
82 return std::find(kOutputFormats.begin(), kOutputFormats.end(), pixelFormat) !=
83 kOutputFormats.end();
84}
85
Jan Sebechlebskyc3e1a632024-02-06 14:19:05 +010086std::vector<MetadataBuilder::FpsRange> fpsRangesForInputConfig(
87 const std::vector<SupportedStreamConfiguration>& configs) {
88 std::set<MetadataBuilder::FpsRange> availableRanges;
89 for (const SupportedStreamConfiguration& config : configs) {
90 availableRanges.insert({.minFps = config.maxFps, .maxFps = config.maxFps});
91 }
92
93 return std::vector<MetadataBuilder::FpsRange>(availableRanges.begin(),
94 availableRanges.end());
95}
96
Jan Sebechlebsky3b478c42023-11-23 13:15:56 +010097std::optional<Resolution> getMaxResolution(
98 const std::vector<SupportedStreamConfiguration>& configs) {
99 auto itMax = std::max_element(configs.begin(), configs.end(),
100 [](const SupportedStreamConfiguration& a,
101 const SupportedStreamConfiguration& b) {
102 return a.width * b.height < a.width * b.height;
103 });
104 if (itMax == configs.end()) {
105 ALOGE(
106 "%s: empty vector of supported configurations, cannot find largest "
107 "resolution.",
108 __func__);
109 return std::nullopt;
110 }
111
112 return Resolution(itMax->width, itMax->height);
113}
114
Biswarup Pal6152a302023-12-19 12:44:09 +0000115// Returns a map of unique resolution to maximum maxFps for all streams with
116// that resolution.
117std::map<Resolution, int> getResolutionToMaxFpsMap(
Jan Sebechlebsky3b478c42023-11-23 13:15:56 +0100118 const std::vector<SupportedStreamConfiguration>& configs) {
Biswarup Pal6152a302023-12-19 12:44:09 +0000119 std::map<Resolution, int> resolutionToMaxFpsMap;
120
121 for (const SupportedStreamConfiguration& config : configs) {
122 Resolution resolution(config.width, config.height);
123 if (resolutionToMaxFpsMap.find(resolution) == resolutionToMaxFpsMap.end()) {
124 resolutionToMaxFpsMap[resolution] = config.maxFps;
125 } else {
126 int currentMaxFps = resolutionToMaxFpsMap[resolution];
127 resolutionToMaxFpsMap[resolution] = std::max(currentMaxFps, config.maxFps);
128 }
129 }
130
131 return resolutionToMaxFpsMap;
Jan Sebechlebsky3b478c42023-11-23 13:15:56 +0100132}
133
Jan Sebechlebsky5cb39962023-11-22 17:33:07 +0100134// TODO(b/301023410) - Populate camera characteristics according to camera configuration.
Jan Sebechlebsky3b478c42023-11-23 13:15:56 +0100135std::optional<CameraMetadata> initCameraCharacteristics(
Biswarup Pal6152a302023-12-19 12:44:09 +0000136 const std::vector<SupportedStreamConfiguration>& supportedInputConfig,
Biswarup Pal112458f2023-12-28 19:50:17 +0000137 const SensorOrientation sensorOrientation, const LensFacing lensFacing) {
Jan Sebechlebsky3b478c42023-11-23 13:15:56 +0100138 if (!std::all_of(supportedInputConfig.begin(), supportedInputConfig.end(),
139 [](const SupportedStreamConfiguration& config) {
Jan Sebechlebsky042d1fb2023-12-12 16:37:00 +0100140 return isFormatSupportedForInput(
Biswarup Pal6152a302023-12-19 12:44:09 +0000141 config.width, config.height, config.pixelFormat,
142 config.maxFps);
Jan Sebechlebsky3b478c42023-11-23 13:15:56 +0100143 })) {
Jan Sebechlebsky042d1fb2023-12-12 16:37:00 +0100144 ALOGE("%s: input configuration contains unsupported format", __func__);
Jan Sebechlebsky3b478c42023-11-23 13:15:56 +0100145 return std::nullopt;
146 }
147
148 MetadataBuilder builder =
Jan Sebechlebsky5cb39962023-11-22 17:33:07 +0100149 MetadataBuilder()
150 .setSupportedHardwareLevel(
151 ANDROID_INFO_SUPPORTED_HARDWARE_LEVEL_EXTERNAL)
152 .setFlashAvailable(false)
Biswarup Pal112458f2023-12-28 19:50:17 +0000153 .setLensFacing(
154 static_cast<camera_metadata_enum_android_lens_facing>(lensFacing))
Biswarup Pal8ad8bc52024-02-08 13:41:44 +0000155 .setAvailableFocalLengths({VirtualCameraDevice::kFocalLength})
Biswarup Pal6152a302023-12-19 12:44:09 +0000156 .setSensorOrientation(static_cast<int32_t>(sensorOrientation))
Jan Sebechlebskya984ffb2024-02-01 09:12:37 +0100157 .setSensorReadoutTimestamp(
158 ANDROID_SENSOR_READOUT_TIMESTAMP_NOT_SUPPORTED)
Jan Sebechlebskyad8d35f2024-02-05 11:58:59 +0100159 .setSensorTimestampSource(ANDROID_SENSOR_INFO_TIMESTAMP_SOURCE_UNKNOWN)
Biswarup Pald9be04d2024-01-31 14:35:15 +0000160 .setSensorPhysicalSize(36.0, 24.0)
Jan Sebechlebsky5cb39962023-11-22 17:33:07 +0100161 .setAvailableFaceDetectModes({ANDROID_STATISTICS_FACE_DETECT_MODE_OFF})
Jan Sebechlebskyb0119fa2023-12-04 10:29:06 +0100162 .setAvailableMaxDigitalZoom(1.0)
163 .setControlAvailableModes({ANDROID_CONTROL_MODE_AUTO})
Jan Sebechlebsky5cb39962023-11-22 17:33:07 +0100164 .setControlAfAvailableModes({ANDROID_CONTROL_AF_MODE_OFF})
Jan Sebechlebsky4425a732024-01-31 11:31:54 +0100165 .setControlAvailableSceneModes({ANDROID_CONTROL_SCENE_MODE_DISABLED})
166 .setControlAvailableEffects({ANDROID_CONTROL_EFFECT_MODE_OFF})
Jan Sebechlebskyc3e1a632024-02-06 14:19:05 +0100167 .setControlAeAvailableModes({ANDROID_CONTROL_AE_MODE_ON})
168 .setControlAeAvailableAntibandingModes(
169 {ANDROID_CONTROL_AE_ANTIBANDING_MODE_AUTO})
170 .setControlAeAvailableFpsRanges(
171 fpsRangesForInputConfig(supportedInputConfig))
Jan Sebechlebsky5cb39962023-11-22 17:33:07 +0100172 .setControlMaxRegions(0, 0, 0)
Jan Sebechlebsky5cb39962023-11-22 17:33:07 +0100173 .setControlAfRegions({kDefaultEmptyControlRegion})
174 .setControlAeRegions({kDefaultEmptyControlRegion})
175 .setControlAwbRegions({kDefaultEmptyControlRegion})
Jan Sebechlebskyc3e1a632024-02-06 14:19:05 +0100176 .setControlAeCompensationRange(0, 0)
Jan Sebechlebsky5cb39962023-11-22 17:33:07 +0100177 .setControlAeCompensationStep(camera_metadata_rational_t{0, 1})
Jan Sebechlebsky4425a732024-01-31 11:31:54 +0100178 .setControlAwbLockAvailable(false)
179 .setControlAeLockAvailable(false)
180 .setControlAvailableAwbModes({ANDROID_CONTROL_AWB_MODE_AUTO})
Jan Sebechlebsky6ab07fe2023-12-05 15:23:34 +0100181 .setControlZoomRatioRange(/*min=*/1.0, /*max=*/1.0)
Jan Sebechlebskyad8d35f2024-02-05 11:58:59 +0100182 // TODO(b/301023410) Add JPEG Exif + thumbnail support.
183 .setJpegAvailableThumbnailSizes({Resolution(0, 0)})
Jan Sebechlebsky5cb39962023-11-22 17:33:07 +0100184 .setMaxJpegSize(kMaxJpegSize)
Jan Sebechlebsky8ae23592024-02-02 16:08:18 +0100185 .setMaxNumberOutputStreams(
186 VirtualCameraDevice::kMaxNumberOfRawStreams,
187 VirtualCameraDevice::kMaxNumberOfProcessedStreams,
188 VirtualCameraDevice::kMaxNumberOfStallStreams)
Jan Sebechlebsky4425a732024-01-31 11:31:54 +0100189 .setSyncMaxLatency(ANDROID_SYNC_MAX_LATENCY_UNKNOWN)
Jan Sebechlebskyc3e1a632024-02-06 14:19:05 +0100190 .setAvailableRequestKeys(
191 {ANDROID_CONTROL_CAPTURE_INTENT, ANDROID_CONTROL_AE_MODE,
192 ANDROID_CONTROL_AE_EXPOSURE_COMPENSATION,
193 ANDROID_CONTROL_AE_TARGET_FPS_RANGE,
194 ANDROID_CONTROL_AE_ANTIBANDING_MODE,
195 ANDROID_CONTROL_AE_PRECAPTURE_TRIGGER, ANDROID_CONTROL_AF_TRIGGER,
196 ANDROID_CONTROL_AF_MODE, ANDROID_CONTROL_AWB_MODE,
197 ANDROID_STATISTICS_FACE_DETECT_MODE, ANDROID_FLASH_MODE})
198 .setAvailableResultKeys(
199 {ANDROID_CONTROL_AE_MODE, ANDROID_CONTROL_AE_PRECAPTURE_TRIGGER,
200 ANDROID_CONTROL_AF_MODE, ANDROID_CONTROL_AWB_MODE,
Biswarup Pal8ad8bc52024-02-08 13:41:44 +0000201 ANDROID_FLASH_STATE, ANDROID_SENSOR_TIMESTAMP,
202 ANDROID_LENS_FOCAL_LENGTH})
Jan Sebechlebsky5cb39962023-11-22 17:33:07 +0100203 .setAvailableCapabilities(
Jan Sebechlebskyad8d35f2024-02-05 11:58:59 +0100204 {ANDROID_REQUEST_AVAILABLE_CAPABILITIES_BACKWARD_COMPATIBLE});
Jan Sebechlebsky5cb39962023-11-22 17:33:07 +0100205
Jan Sebechlebsky3b478c42023-11-23 13:15:56 +0100206 // Active array size must correspond to largest supported input resolution.
207 std::optional<Resolution> maxResolution =
208 getMaxResolution(supportedInputConfig);
209 if (!maxResolution.has_value()) {
210 return std::nullopt;
211 }
212 builder.setSensorActiveArraySize(0, 0, maxResolution->width,
213 maxResolution->height);
Biswarup Pald9be04d2024-01-31 14:35:15 +0000214 builder.setSensorPixelArraySize(maxResolution->width, maxResolution->height);
Jan Sebechlebsky3b478c42023-11-23 13:15:56 +0100215
216 std::vector<MetadataBuilder::StreamConfiguration> outputConfigurations;
217
218 // TODO(b/301023410) Add also all "standard" resolutions we can rescale the
219 // streams to (all standard resolutions with same aspect ratio).
220
Biswarup Pal6152a302023-12-19 12:44:09 +0000221 std::map<Resolution, int> resolutionToMaxFpsMap =
222 getResolutionToMaxFpsMap(supportedInputConfig);
Jan Sebechlebsky3b478c42023-11-23 13:15:56 +0100223
Biswarup Pal6152a302023-12-19 12:44:09 +0000224 // Add configurations for all unique input resolutions and output formats.
Jan Sebechlebsky8ae23592024-02-02 16:08:18 +0100225 for (const PixelFormat format : kOutputFormats) {
Biswarup Pal6152a302023-12-19 12:44:09 +0000226 std::transform(
227 resolutionToMaxFpsMap.begin(), resolutionToMaxFpsMap.end(),
228 std::back_inserter(outputConfigurations), [format](const auto& entry) {
229 Resolution resolution = entry.first;
230 int maxFps = entry.second;
231 return MetadataBuilder::StreamConfiguration{
232 .width = resolution.width,
233 .height = resolution.height,
Jan Sebechlebsky8ae23592024-02-02 16:08:18 +0100234 .format = static_cast<int32_t>(format),
Biswarup Pal6152a302023-12-19 12:44:09 +0000235 .minFrameDuration = std::chrono::nanoseconds(1s) / maxFps,
236 .minStallDuration = 0s};
237 });
238 }
Jan Sebechlebsky3b478c42023-11-23 13:15:56 +0100239
240 ALOGV("Adding %zu output configurations", outputConfigurations.size());
241 builder.setAvailableOutputStreamConfigurations(outputConfigurations);
242
Jan Sebechlebskyad8d35f2024-02-05 11:58:59 +0100243 auto metadata = builder.setAvailableCharacteristicKeys().build();
Jan Sebechlebsky5cb39962023-11-22 17:33:07 +0100244 if (metadata == nullptr) {
245 ALOGE("Failed to build metadata!");
246 return CameraMetadata();
247 }
248
249 return std::move(*metadata);
250}
251
252} // namespace
253
254VirtualCameraDevice::VirtualCameraDevice(
Biswarup Pal6152a302023-12-19 12:44:09 +0000255 const uint32_t cameraId, const VirtualCameraConfiguration& configuration)
Jan Sebechlebsky5cb39962023-11-22 17:33:07 +0100256 : mCameraId(cameraId),
Biswarup Pal6152a302023-12-19 12:44:09 +0000257 mVirtualCameraClientCallback(configuration.virtualCameraCallback),
258 mSupportedInputConfigurations(configuration.supportedStreamConfigs) {
259 std::optional<CameraMetadata> metadata = initCameraCharacteristics(
Biswarup Pal112458f2023-12-28 19:50:17 +0000260 mSupportedInputConfigurations, configuration.sensorOrientation,
261 configuration.lensFacing);
Jan Sebechlebsky3b478c42023-11-23 13:15:56 +0100262 if (metadata.has_value()) {
263 mCameraCharacteristics = *metadata;
264 } else {
265 ALOGE(
266 "%s: Failed to initialize camera characteristic based on provided "
267 "configuration.",
268 __func__);
269 }
Jan Sebechlebsky5cb39962023-11-22 17:33:07 +0100270}
271
272ndk::ScopedAStatus VirtualCameraDevice::getCameraCharacteristics(
273 CameraMetadata* _aidl_return) {
274 ALOGV("%s", __func__);
275 if (_aidl_return == nullptr) {
276 return cameraStatus(Status::ILLEGAL_ARGUMENT);
277 }
278
279 *_aidl_return = mCameraCharacteristics;
280 return ndk::ScopedAStatus::ok();
281}
282
283ndk::ScopedAStatus VirtualCameraDevice::getPhysicalCameraCharacteristics(
284 const std::string& in_physicalCameraId, CameraMetadata* _aidl_return) {
285 ALOGV("%s: physicalCameraId %s", __func__, in_physicalCameraId.c_str());
286 (void)_aidl_return;
287
288 // VTS tests expect this call to fail with illegal argument status for
289 // all publicly advertised camera ids.
290 // Because we don't support physical camera ids, we just always
291 // fail with illegal argument (there's no valid argument to provide).
292 return cameraStatus(Status::ILLEGAL_ARGUMENT);
293}
294
295ndk::ScopedAStatus VirtualCameraDevice::getResourceCost(
296 CameraResourceCost* _aidl_return) {
297 ALOGV("%s", __func__);
298 if (_aidl_return == nullptr) {
299 return cameraStatus(Status::ILLEGAL_ARGUMENT);
300 }
301 _aidl_return->resourceCost = 100; // ¯\_(ツ)_/¯
302 return ndk::ScopedAStatus::ok();
303}
304
305ndk::ScopedAStatus VirtualCameraDevice::isStreamCombinationSupported(
306 const StreamConfiguration& in_streams, bool* _aidl_return) {
307 ALOGV("%s", __func__);
308
309 if (_aidl_return == nullptr) {
310 return cameraStatus(Status::ILLEGAL_ARGUMENT);
311 }
312
Jan Sebechlebsky3b478c42023-11-23 13:15:56 +0100313 *_aidl_return = isStreamCombinationSupported(in_streams);
314 return ndk::ScopedAStatus::ok();
315};
316
317bool VirtualCameraDevice::isStreamCombinationSupported(
318 const StreamConfiguration& streamConfiguration) const {
Jan Sebechlebsky39129f82024-01-19 16:42:11 +0100319 if (streamConfiguration.streams.empty()) {
320 ALOGE("%s: Querying empty configuration", __func__);
321 return false;
322 }
323
Jan Sebechlebsky8ae23592024-02-02 16:08:18 +0100324 int numberOfProcessedStreams = 0;
325 int numberOfStallStreams = 0;
Jan Sebechlebsky3b478c42023-11-23 13:15:56 +0100326 for (const Stream& stream : streamConfiguration.streams) {
Jan Sebechlebsky5cb39962023-11-22 17:33:07 +0100327 ALOGV("%s: Configuration queried: %s", __func__, stream.toString().c_str());
328
329 if (stream.streamType == StreamType::INPUT) {
330 ALOGW("%s: Input stream type is not supported", __func__);
Jan Sebechlebsky3b478c42023-11-23 13:15:56 +0100331 return false;
Jan Sebechlebsky5cb39962023-11-22 17:33:07 +0100332 }
333
Jan Sebechlebsky3b478c42023-11-23 13:15:56 +0100334 if (stream.rotation != StreamRotation::ROTATION_0 ||
Jan Sebechlebsky8ae23592024-02-02 16:08:18 +0100335 !isSupportedOutputFormat(stream.format)) {
Jan Sebechlebsky3b478c42023-11-23 13:15:56 +0100336 ALOGV("Unsupported output stream type");
337 return false;
338 }
339
Jan Sebechlebsky8ae23592024-02-02 16:08:18 +0100340 if (stream.format == PixelFormat::BLOB) {
341 numberOfStallStreams++;
342 } else {
343 numberOfProcessedStreams++;
344 }
345
Jan Sebechlebsky3b478c42023-11-23 13:15:56 +0100346 auto matchesSupportedInputConfig =
347 [&stream](const SupportedStreamConfiguration& config) {
348 return stream.width == config.width && stream.height == config.height;
349 };
350 if (std::none_of(mSupportedInputConfigurations.begin(),
351 mSupportedInputConfigurations.end(),
352 matchesSupportedInputConfig)) {
353 ALOGV("Requested config doesn't match any supported input config");
354 return false;
Jan Sebechlebsky5cb39962023-11-22 17:33:07 +0100355 }
356 }
Jan Sebechlebsky8ae23592024-02-02 16:08:18 +0100357
358 if (numberOfProcessedStreams > kMaxNumberOfProcessedStreams) {
359 ALOGE("%s: %d processed streams exceeds the supported maximum of %d",
360 __func__, numberOfProcessedStreams, kMaxNumberOfProcessedStreams);
361 return false;
362 }
363
364 if (numberOfStallStreams > kMaxNumberOfStallStreams) {
365 ALOGE("%s: %d stall streams exceeds the supported maximum of %d", __func__,
366 numberOfStallStreams, kMaxNumberOfStallStreams);
367 return false;
368 }
369
Jan Sebechlebsky3b478c42023-11-23 13:15:56 +0100370 return true;
371}
Jan Sebechlebsky5cb39962023-11-22 17:33:07 +0100372
373ndk::ScopedAStatus VirtualCameraDevice::open(
374 const std::shared_ptr<ICameraDeviceCallback>& in_callback,
375 std::shared_ptr<ICameraDeviceSession>* _aidl_return) {
376 ALOGV("%s", __func__);
377
378 *_aidl_return = ndk::SharedRefBase::make<VirtualCameraSession>(
Jan Sebechlebsky0bb5e092023-12-08 16:17:54 +0100379 sharedFromThis(), in_callback, mVirtualCameraClientCallback);
Jan Sebechlebsky5cb39962023-11-22 17:33:07 +0100380
381 return ndk::ScopedAStatus::ok();
382};
383
384ndk::ScopedAStatus VirtualCameraDevice::openInjectionSession(
385 const std::shared_ptr<ICameraDeviceCallback>& in_callback,
386 std::shared_ptr<ICameraInjectionSession>* _aidl_return) {
387 ALOGV("%s", __func__);
388
389 (void)in_callback;
390 (void)_aidl_return;
391 return cameraStatus(Status::OPERATION_NOT_SUPPORTED);
392}
393
394ndk::ScopedAStatus VirtualCameraDevice::setTorchMode(bool in_on) {
395 ALOGV("%s: on = %s", __func__, in_on ? "on" : "off");
396 return cameraStatus(Status::OPERATION_NOT_SUPPORTED);
397}
398
399ndk::ScopedAStatus VirtualCameraDevice::turnOnTorchWithStrengthLevel(
400 int32_t in_torchStrength) {
401 ALOGV("%s: torchStrength = %d", __func__, in_torchStrength);
402 return cameraStatus(Status::OPERATION_NOT_SUPPORTED);
403}
404
405ndk::ScopedAStatus VirtualCameraDevice::getTorchStrengthLevel(
406 int32_t* _aidl_return) {
407 (void)_aidl_return;
408 return cameraStatus(Status::OPERATION_NOT_SUPPORTED);
409}
410
411binder_status_t VirtualCameraDevice::dump(int fd, const char** args,
412 uint32_t numArgs) {
413 // TODO(b/301023410) Implement.
414 (void)fd;
415 (void)args;
416 (void)numArgs;
417 return STATUS_OK;
418}
419
420std::string VirtualCameraDevice::getCameraName() const {
421 return std::string(kDevicePathPrefix) + std::to_string(mCameraId);
422}
423
Jan Sebechlebskyc3e1a632024-02-06 14:19:05 +0100424const std::vector<SupportedStreamConfiguration>&
425VirtualCameraDevice::getInputConfigs() const {
426 return mSupportedInputConfigurations;
427}
428
Jan Sebechlebsky0bb5e092023-12-08 16:17:54 +0100429std::shared_ptr<VirtualCameraDevice> VirtualCameraDevice::sharedFromThis() {
430 // SharedRefBase which BnCameraDevice inherits from breaks
431 // std::enable_shared_from_this. This is recommended replacement for
432 // shared_from_this() per documentation in binder_interface_utils.h.
433 return ref<VirtualCameraDevice>();
434}
435
Jan Sebechlebsky5cb39962023-11-22 17:33:07 +0100436} // namespace virtualcamera
437} // namespace companion
438} // namespace android