1 /*
2 * Copyright (C) 2024 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16 #include "VirtualCameraCaptureResult.h"
17
18 #include <cstdint>
19 #include <memory>
20
21 #include "VirtualCameraCaptureRequest.h"
22 #include "aidl/android/hardware/camera/device/CameraMetadata.h"
23 #include "util/MetadataUtil.h"
24
25 namespace android {
26 namespace companion {
27 namespace virtualcamera {
28
29 using ::aidl::android::hardware::camera::device::CameraMetadata;
30 namespace {
31 // See REQUEST_PIPELINE_DEPTH in CaptureResult.java.
32 // This roughly corresponds to frame latency, we set to
33 // documented minimum of 2.
34 static constexpr uint8_t kPipelineDepth = 2;
35
36 } // namespace
37
createCaptureResultMetadata(const std::chrono::nanoseconds timestamp,const RequestSettings & requestSettings,const Resolution reportedSensorSize)38 std::unique_ptr<CameraMetadata> createCaptureResultMetadata(
39 const std::chrono::nanoseconds timestamp,
40 const RequestSettings& requestSettings,
41 const Resolution reportedSensorSize) {
42 // All of the keys used in the response needs to be referenced in
43 // availableResultKeys in CameraCharacteristics (see initCameraCharacteristics
44 // in VirtualCameraDevice.cc).
45 MetadataBuilder builder =
46 MetadataBuilder()
47 .setAberrationCorrectionMode(
48 ANDROID_COLOR_CORRECTION_ABERRATION_MODE_OFF)
49 .setControlAeAvailableAntibandingModes(
50 {ANDROID_CONTROL_AE_ANTIBANDING_MODE_OFF})
51 .setControlAeAntibandingMode(ANDROID_CONTROL_AE_ANTIBANDING_MODE_OFF)
52 .setControlAeExposureCompensation(0)
53 .setControlAeLockAvailable(false)
54 .setControlAeLock(ANDROID_CONTROL_AE_LOCK_OFF)
55 .setControlAeMode(ANDROID_CONTROL_AE_MODE_ON)
56 .setControlAePrecaptureTrigger(
57 // Limited devices are expected to have precapture ae enabled and
58 // respond to cancellation request. Since we don't actuall support
59 // AE at all, let's just respect the cancellation expectation in
60 // case it's requested
61 requestSettings.aePrecaptureTrigger ==
62 ANDROID_CONTROL_AE_PRECAPTURE_TRIGGER_CANCEL
63 ? ANDROID_CONTROL_AE_PRECAPTURE_TRIGGER_CANCEL
64 : ANDROID_CONTROL_AE_PRECAPTURE_TRIGGER_IDLE)
65 .setControlAeState(ANDROID_CONTROL_AE_STATE_INACTIVE)
66 .setControlAfMode(ANDROID_CONTROL_AF_MODE_OFF)
67 .setControlAfTrigger(ANDROID_CONTROL_AF_TRIGGER_IDLE)
68 .setControlAfState(ANDROID_CONTROL_AF_STATE_INACTIVE)
69 .setControlAwbMode(ANDROID_CONTROL_AWB_MODE_AUTO)
70 .setControlAwbLock(ANDROID_CONTROL_AWB_LOCK_OFF)
71 .setControlAwbState(ANDROID_CONTROL_AWB_STATE_INACTIVE)
72 .setControlCaptureIntent(requestSettings.captureIntent)
73 .setControlEffectMode(ANDROID_CONTROL_EFFECT_MODE_OFF)
74 .setControlMode(ANDROID_CONTROL_MODE_AUTO)
75 .setControlSceneMode(ANDROID_CONTROL_SCENE_MODE_DISABLED)
76 .setControlVideoStabilizationMode(
77 ANDROID_CONTROL_VIDEO_STABILIZATION_MODE_OFF)
78 .setCropRegion(0, 0, reportedSensorSize.width,
79 reportedSensorSize.height)
80 .setFaceDetectMode(ANDROID_STATISTICS_FACE_DETECT_MODE_OFF)
81 .setFlashState(ANDROID_FLASH_STATE_UNAVAILABLE)
82 .setFlashMode(ANDROID_FLASH_MODE_OFF)
83 .setFocalLength(VirtualCameraDevice::kFocalLength)
84 .setJpegQuality(requestSettings.jpegQuality)
85 .setJpegOrientation(requestSettings.jpegOrientation)
86 .setJpegThumbnailSize(requestSettings.thumbnailResolution.width,
87 requestSettings.thumbnailResolution.height)
88 .setJpegThumbnailQuality(requestSettings.thumbnailJpegQuality)
89 .setLensOpticalStabilizationMode(
90 ANDROID_LENS_OPTICAL_STABILIZATION_MODE_OFF)
91 .setNoiseReductionMode(ANDROID_NOISE_REDUCTION_MODE_OFF)
92 .setPipelineDepth(kPipelineDepth)
93 .setSensorTimestamp(timestamp)
94 .setStatisticsHotPixelMapMode(
95 ANDROID_STATISTICS_HOT_PIXEL_MAP_MODE_OFF)
96 .setStatisticsLensShadingMapMode(
97 ANDROID_STATISTICS_LENS_SHADING_MAP_MODE_OFF)
98 .setStatisticsSceneFlicker(ANDROID_STATISTICS_SCENE_FLICKER_NONE);
99
100 if (requestSettings.fpsRange.has_value()) {
101 builder.setControlAeTargetFpsRange(requestSettings.fpsRange.value());
102 }
103
104 if (requestSettings.gpsCoordinates.has_value()) {
105 const GpsCoordinates& coordinates = requestSettings.gpsCoordinates.value();
106 builder.setJpegGpsCoordinates(coordinates);
107 }
108
109 std::unique_ptr<CameraMetadata> metadata = builder.build();
110
111 if (metadata == nullptr) {
112 ALOGE("%s: Failed to build capture result metadata", __func__);
113 return std::make_unique<CameraMetadata>();
114 }
115 return metadata;
116 }
117
118 } // namespace virtualcamera
119 } // namespace companion
120 } // namespace android