blob: bfa535e9d71969a6abef6d67b816a861913de28b [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 Pald9be04d2024-01-31 14:35:15 +0000155 .setFocalLength(43.0)
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,
201 ANDROID_FLASH_STATE, ANDROID_SENSOR_TIMESTAMP})
Jan Sebechlebsky5cb39962023-11-22 17:33:07 +0100202 .setAvailableCapabilities(
Jan Sebechlebskyad8d35f2024-02-05 11:58:59 +0100203 {ANDROID_REQUEST_AVAILABLE_CAPABILITIES_BACKWARD_COMPATIBLE});
Jan Sebechlebsky5cb39962023-11-22 17:33:07 +0100204
Jan Sebechlebsky3b478c42023-11-23 13:15:56 +0100205 // Active array size must correspond to largest supported input resolution.
206 std::optional<Resolution> maxResolution =
207 getMaxResolution(supportedInputConfig);
208 if (!maxResolution.has_value()) {
209 return std::nullopt;
210 }
211 builder.setSensorActiveArraySize(0, 0, maxResolution->width,
212 maxResolution->height);
Biswarup Pald9be04d2024-01-31 14:35:15 +0000213 builder.setSensorPixelArraySize(maxResolution->width, maxResolution->height);
Jan Sebechlebsky3b478c42023-11-23 13:15:56 +0100214
215 std::vector<MetadataBuilder::StreamConfiguration> outputConfigurations;
216
217 // TODO(b/301023410) Add also all "standard" resolutions we can rescale the
218 // streams to (all standard resolutions with same aspect ratio).
219
Biswarup Pal6152a302023-12-19 12:44:09 +0000220 std::map<Resolution, int> resolutionToMaxFpsMap =
221 getResolutionToMaxFpsMap(supportedInputConfig);
Jan Sebechlebsky3b478c42023-11-23 13:15:56 +0100222
Biswarup Pal6152a302023-12-19 12:44:09 +0000223 // Add configurations for all unique input resolutions and output formats.
Jan Sebechlebsky8ae23592024-02-02 16:08:18 +0100224 for (const PixelFormat format : kOutputFormats) {
Biswarup Pal6152a302023-12-19 12:44:09 +0000225 std::transform(
226 resolutionToMaxFpsMap.begin(), resolutionToMaxFpsMap.end(),
227 std::back_inserter(outputConfigurations), [format](const auto& entry) {
228 Resolution resolution = entry.first;
229 int maxFps = entry.second;
230 return MetadataBuilder::StreamConfiguration{
231 .width = resolution.width,
232 .height = resolution.height,
Jan Sebechlebsky8ae23592024-02-02 16:08:18 +0100233 .format = static_cast<int32_t>(format),
Biswarup Pal6152a302023-12-19 12:44:09 +0000234 .minFrameDuration = std::chrono::nanoseconds(1s) / maxFps,
235 .minStallDuration = 0s};
236 });
237 }
Jan Sebechlebsky3b478c42023-11-23 13:15:56 +0100238
239 ALOGV("Adding %zu output configurations", outputConfigurations.size());
240 builder.setAvailableOutputStreamConfigurations(outputConfigurations);
241
Jan Sebechlebskyad8d35f2024-02-05 11:58:59 +0100242 auto metadata = builder.setAvailableCharacteristicKeys().build();
Jan Sebechlebsky5cb39962023-11-22 17:33:07 +0100243 if (metadata == nullptr) {
244 ALOGE("Failed to build metadata!");
245 return CameraMetadata();
246 }
247
248 return std::move(*metadata);
249}
250
251} // namespace
252
253VirtualCameraDevice::VirtualCameraDevice(
Biswarup Pal6152a302023-12-19 12:44:09 +0000254 const uint32_t cameraId, const VirtualCameraConfiguration& configuration)
Jan Sebechlebsky5cb39962023-11-22 17:33:07 +0100255 : mCameraId(cameraId),
Biswarup Pal6152a302023-12-19 12:44:09 +0000256 mVirtualCameraClientCallback(configuration.virtualCameraCallback),
257 mSupportedInputConfigurations(configuration.supportedStreamConfigs) {
258 std::optional<CameraMetadata> metadata = initCameraCharacteristics(
Biswarup Pal112458f2023-12-28 19:50:17 +0000259 mSupportedInputConfigurations, configuration.sensorOrientation,
260 configuration.lensFacing);
Jan Sebechlebsky3b478c42023-11-23 13:15:56 +0100261 if (metadata.has_value()) {
262 mCameraCharacteristics = *metadata;
263 } else {
264 ALOGE(
265 "%s: Failed to initialize camera characteristic based on provided "
266 "configuration.",
267 __func__);
268 }
Jan Sebechlebsky5cb39962023-11-22 17:33:07 +0100269}
270
271ndk::ScopedAStatus VirtualCameraDevice::getCameraCharacteristics(
272 CameraMetadata* _aidl_return) {
273 ALOGV("%s", __func__);
274 if (_aidl_return == nullptr) {
275 return cameraStatus(Status::ILLEGAL_ARGUMENT);
276 }
277
278 *_aidl_return = mCameraCharacteristics;
279 return ndk::ScopedAStatus::ok();
280}
281
282ndk::ScopedAStatus VirtualCameraDevice::getPhysicalCameraCharacteristics(
283 const std::string& in_physicalCameraId, CameraMetadata* _aidl_return) {
284 ALOGV("%s: physicalCameraId %s", __func__, in_physicalCameraId.c_str());
285 (void)_aidl_return;
286
287 // VTS tests expect this call to fail with illegal argument status for
288 // all publicly advertised camera ids.
289 // Because we don't support physical camera ids, we just always
290 // fail with illegal argument (there's no valid argument to provide).
291 return cameraStatus(Status::ILLEGAL_ARGUMENT);
292}
293
294ndk::ScopedAStatus VirtualCameraDevice::getResourceCost(
295 CameraResourceCost* _aidl_return) {
296 ALOGV("%s", __func__);
297 if (_aidl_return == nullptr) {
298 return cameraStatus(Status::ILLEGAL_ARGUMENT);
299 }
300 _aidl_return->resourceCost = 100; // ¯\_(ツ)_/¯
301 return ndk::ScopedAStatus::ok();
302}
303
304ndk::ScopedAStatus VirtualCameraDevice::isStreamCombinationSupported(
305 const StreamConfiguration& in_streams, bool* _aidl_return) {
306 ALOGV("%s", __func__);
307
308 if (_aidl_return == nullptr) {
309 return cameraStatus(Status::ILLEGAL_ARGUMENT);
310 }
311
Jan Sebechlebsky3b478c42023-11-23 13:15:56 +0100312 *_aidl_return = isStreamCombinationSupported(in_streams);
313 return ndk::ScopedAStatus::ok();
314};
315
316bool VirtualCameraDevice::isStreamCombinationSupported(
317 const StreamConfiguration& streamConfiguration) const {
Jan Sebechlebsky39129f82024-01-19 16:42:11 +0100318 if (streamConfiguration.streams.empty()) {
319 ALOGE("%s: Querying empty configuration", __func__);
320 return false;
321 }
322
Jan Sebechlebsky8ae23592024-02-02 16:08:18 +0100323 int numberOfProcessedStreams = 0;
324 int numberOfStallStreams = 0;
Jan Sebechlebsky3b478c42023-11-23 13:15:56 +0100325 for (const Stream& stream : streamConfiguration.streams) {
Jan Sebechlebsky5cb39962023-11-22 17:33:07 +0100326 ALOGV("%s: Configuration queried: %s", __func__, stream.toString().c_str());
327
328 if (stream.streamType == StreamType::INPUT) {
329 ALOGW("%s: Input stream type is not supported", __func__);
Jan Sebechlebsky3b478c42023-11-23 13:15:56 +0100330 return false;
Jan Sebechlebsky5cb39962023-11-22 17:33:07 +0100331 }
332
Jan Sebechlebsky3b478c42023-11-23 13:15:56 +0100333 if (stream.rotation != StreamRotation::ROTATION_0 ||
Jan Sebechlebsky8ae23592024-02-02 16:08:18 +0100334 !isSupportedOutputFormat(stream.format)) {
Jan Sebechlebsky3b478c42023-11-23 13:15:56 +0100335 ALOGV("Unsupported output stream type");
336 return false;
337 }
338
Jan Sebechlebsky8ae23592024-02-02 16:08:18 +0100339 if (stream.format == PixelFormat::BLOB) {
340 numberOfStallStreams++;
341 } else {
342 numberOfProcessedStreams++;
343 }
344
Jan Sebechlebsky3b478c42023-11-23 13:15:56 +0100345 auto matchesSupportedInputConfig =
346 [&stream](const SupportedStreamConfiguration& config) {
347 return stream.width == config.width && stream.height == config.height;
348 };
349 if (std::none_of(mSupportedInputConfigurations.begin(),
350 mSupportedInputConfigurations.end(),
351 matchesSupportedInputConfig)) {
352 ALOGV("Requested config doesn't match any supported input config");
353 return false;
Jan Sebechlebsky5cb39962023-11-22 17:33:07 +0100354 }
355 }
Jan Sebechlebsky8ae23592024-02-02 16:08:18 +0100356
357 if (numberOfProcessedStreams > kMaxNumberOfProcessedStreams) {
358 ALOGE("%s: %d processed streams exceeds the supported maximum of %d",
359 __func__, numberOfProcessedStreams, kMaxNumberOfProcessedStreams);
360 return false;
361 }
362
363 if (numberOfStallStreams > kMaxNumberOfStallStreams) {
364 ALOGE("%s: %d stall streams exceeds the supported maximum of %d", __func__,
365 numberOfStallStreams, kMaxNumberOfStallStreams);
366 return false;
367 }
368
Jan Sebechlebsky3b478c42023-11-23 13:15:56 +0100369 return true;
370}
Jan Sebechlebsky5cb39962023-11-22 17:33:07 +0100371
372ndk::ScopedAStatus VirtualCameraDevice::open(
373 const std::shared_ptr<ICameraDeviceCallback>& in_callback,
374 std::shared_ptr<ICameraDeviceSession>* _aidl_return) {
375 ALOGV("%s", __func__);
376
377 *_aidl_return = ndk::SharedRefBase::make<VirtualCameraSession>(
Jan Sebechlebsky0bb5e092023-12-08 16:17:54 +0100378 sharedFromThis(), in_callback, mVirtualCameraClientCallback);
Jan Sebechlebsky5cb39962023-11-22 17:33:07 +0100379
380 return ndk::ScopedAStatus::ok();
381};
382
383ndk::ScopedAStatus VirtualCameraDevice::openInjectionSession(
384 const std::shared_ptr<ICameraDeviceCallback>& in_callback,
385 std::shared_ptr<ICameraInjectionSession>* _aidl_return) {
386 ALOGV("%s", __func__);
387
388 (void)in_callback;
389 (void)_aidl_return;
390 return cameraStatus(Status::OPERATION_NOT_SUPPORTED);
391}
392
393ndk::ScopedAStatus VirtualCameraDevice::setTorchMode(bool in_on) {
394 ALOGV("%s: on = %s", __func__, in_on ? "on" : "off");
395 return cameraStatus(Status::OPERATION_NOT_SUPPORTED);
396}
397
398ndk::ScopedAStatus VirtualCameraDevice::turnOnTorchWithStrengthLevel(
399 int32_t in_torchStrength) {
400 ALOGV("%s: torchStrength = %d", __func__, in_torchStrength);
401 return cameraStatus(Status::OPERATION_NOT_SUPPORTED);
402}
403
404ndk::ScopedAStatus VirtualCameraDevice::getTorchStrengthLevel(
405 int32_t* _aidl_return) {
406 (void)_aidl_return;
407 return cameraStatus(Status::OPERATION_NOT_SUPPORTED);
408}
409
410binder_status_t VirtualCameraDevice::dump(int fd, const char** args,
411 uint32_t numArgs) {
412 // TODO(b/301023410) Implement.
413 (void)fd;
414 (void)args;
415 (void)numArgs;
416 return STATUS_OK;
417}
418
419std::string VirtualCameraDevice::getCameraName() const {
420 return std::string(kDevicePathPrefix) + std::to_string(mCameraId);
421}
422
Jan Sebechlebskyc3e1a632024-02-06 14:19:05 +0100423const std::vector<SupportedStreamConfiguration>&
424VirtualCameraDevice::getInputConfigs() const {
425 return mSupportedInputConfigurations;
426}
427
Jan Sebechlebsky0bb5e092023-12-08 16:17:54 +0100428std::shared_ptr<VirtualCameraDevice> VirtualCameraDevice::sharedFromThis() {
429 // SharedRefBase which BnCameraDevice inherits from breaks
430 // std::enable_shared_from_this. This is recommended replacement for
431 // shared_from_this() per documentation in binder_interface_utils.h.
432 return ref<VirtualCameraDevice>();
433}
434
Jan Sebechlebsky5cb39962023-11-22 17:33:07 +0100435} // namespace virtualcamera
436} // namespace companion
437} // namespace android