1 /*
2  * Copyright (C) 2023 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 
17 #define FAILURE_DEBUG_PREFIX "CameraDevice"
18 
19 #include <string_view>
20 
21 #include <system/camera_metadata.h>
22 #include <system/graphics.h>
23 
24 #include "CameraDevice.h"
25 #include "CameraDeviceSession.h"
26 #include "debug.h"
27 
28 namespace android {
29 namespace hardware {
30 namespace camera {
31 namespace provider {
32 namespace implementation {
33 namespace {
34 const uint32_t kExtraResultKeys[] = {
35     ANDROID_COLOR_CORRECTION_GAINS,
36     ANDROID_COLOR_CORRECTION_TRANSFORM,
37     ANDROID_CONTROL_AE_STATE,
38     ANDROID_CONTROL_AF_STATE,
39     ANDROID_CONTROL_AWB_STATE,
40     ANDROID_FLASH_STATE,
41     ANDROID_LENS_FOCUS_DISTANCE,
42     ANDROID_LENS_STATE,
43     ANDROID_REQUEST_PIPELINE_DEPTH,
44     ANDROID_SENSOR_TIMESTAMP, // populate with zero, CameraDeviceSession will put an actual value
45     ANDROID_SENSOR_ROLLING_SHUTTER_SKEW,
46     ANDROID_SENSOR_NEUTRAL_COLOR_POINT,
47     ANDROID_SENSOR_NOISE_PROFILE,
48     ANDROID_STATISTICS_SCENE_FLICKER,
49     ANDROID_STATISTICS_LENS_SHADING_MAP,
50 };
51 
getSortedKeys(const CameraMetadataMap & m)52 std::vector<uint32_t> getSortedKeys(const CameraMetadataMap& m) {
53     std::vector<uint32_t> keys;
54     keys.reserve(m.size());
55     for (const auto& [tag, unused] : m) {
56         keys.push_back(tag);
57     }
58     std::sort(keys.begin(), keys.end());
59     return keys;
60 }
61 
62 camera_metadata_enum_android_control_capture_intent_t
MapRequestTemplateToIntent(const RequestTemplate tpl)63 MapRequestTemplateToIntent(const RequestTemplate tpl) {
64     switch (tpl) {
65     case RequestTemplate::PREVIEW:
66         return ANDROID_CONTROL_CAPTURE_INTENT_PREVIEW;
67     case RequestTemplate::STILL_CAPTURE:
68         return ANDROID_CONTROL_CAPTURE_INTENT_STILL_CAPTURE;
69     case RequestTemplate::VIDEO_RECORD:
70         return ANDROID_CONTROL_CAPTURE_INTENT_VIDEO_RECORD;
71     case RequestTemplate::VIDEO_SNAPSHOT:
72         return ANDROID_CONTROL_CAPTURE_INTENT_VIDEO_SNAPSHOT;
73     case RequestTemplate::ZERO_SHUTTER_LAG:
74         return ANDROID_CONTROL_CAPTURE_INTENT_ZERO_SHUTTER_LAG;
75     case RequestTemplate::MANUAL:
76         return ANDROID_CONTROL_CAPTURE_INTENT_MANUAL;
77     default:
78         return ANDROID_CONTROL_CAPTURE_INTENT_CUSTOM;
79     }
80 }
81 
82 }  // namespace
83 
84 using aidl::android::hardware::camera::common::Status;
85 using hw::HwCameraFactoryProduct;
86 
CameraDevice(HwCameraFactoryProduct hwCamera)87 CameraDevice::CameraDevice(HwCameraFactoryProduct hwCamera)
88         : mHwCamera(std::move(hwCamera)) {}
89 
~CameraDevice()90 CameraDevice::~CameraDevice() {}
91 
getCameraCharacteristics(CameraMetadata * metadata)92 ScopedAStatus CameraDevice::getCameraCharacteristics(CameraMetadata* metadata) {
93     CameraMetadataMap m;
94 
95     {
96         m[ANDROID_COLOR_CORRECTION_AVAILABLE_ABERRATION_MODES]
97             .add<uint8_t>(ANDROID_COLOR_CORRECTION_ABERRATION_MODE_OFF);
98     }
99     {   // ANDROID_CONTROL_...
100         m[ANDROID_CONTROL_AE_AVAILABLE_ANTIBANDING_MODES]
101             .add<uint8_t>(ANDROID_CONTROL_AE_ANTIBANDING_MODE_OFF)
102             .add<uint8_t>(ANDROID_CONTROL_AE_ANTIBANDING_MODE_AUTO);
103         m[ANDROID_CONTROL_AE_AVAILABLE_MODES]
104             .add<uint8_t>(ANDROID_CONTROL_AE_MODE_OFF)
105             .add<uint8_t>(ANDROID_CONTROL_AE_MODE_ON);
106         {
107             auto& ranges = m[ANDROID_CONTROL_AE_AVAILABLE_TARGET_FPS_RANGES];
108             for (const auto& r : mHwCamera->getTargetFpsRanges()) {
109                 ranges.add<int32_t>(r.first).add<int32_t>(r.second);
110             }
111         }
112         {
113             const auto aeCompensationRange = mHwCamera->getAeCompensationRange();
114             m[ANDROID_CONTROL_AE_COMPENSATION_RANGE]
115                 .add<int32_t>(std::get<0>(aeCompensationRange))
116                 .add<int32_t>(std::get<1>(aeCompensationRange));
117 
118             const camera_metadata_rational_t aeCompensationStep = {
119                 .numerator = std::get<2>(aeCompensationRange),
120                 .denominator = std::get<3>(aeCompensationRange),
121             };
122             m[ANDROID_CONTROL_AE_COMPENSATION_STEP] = aeCompensationStep;
123         }
124         m[ANDROID_CONTROL_AF_AVAILABLE_MODES]
125             .add<uint8_t>(ANDROID_CONTROL_AF_MODE_OFF)
126             .add<uint8_t>(ANDROID_CONTROL_AF_MODE_AUTO);
127         m[ANDROID_CONTROL_AVAILABLE_EFFECTS]
128             .add<uint8_t>(ANDROID_CONTROL_EFFECT_MODE_OFF);
129         m[ANDROID_CONTROL_AVAILABLE_SCENE_MODES]
130             .add<uint8_t>(ANDROID_CONTROL_SCENE_MODE_DISABLED);
131         m[ANDROID_CONTROL_AVAILABLE_VIDEO_STABILIZATION_MODES]
132             .add<uint8_t>(ANDROID_CONTROL_VIDEO_STABILIZATION_MODE_OFF);
133         m[ANDROID_CONTROL_AWB_AVAILABLE_MODES]
134             .add<uint8_t>(ANDROID_CONTROL_AWB_MODE_OFF)
135             .add<uint8_t>(ANDROID_CONTROL_AWB_MODE_AUTO);
136         m[ANDROID_CONTROL_MAX_REGIONS]
137             .add<int32_t>(0)    // AE
138             .add<int32_t>(0)    // AWB
139             .add<int32_t>(1);   // AF
140         m[ANDROID_CONTROL_AE_LOCK_AVAILABLE] =
141             uint8_t(ANDROID_CONTROL_AE_LOCK_AVAILABLE_FALSE);
142         m[ANDROID_CONTROL_AWB_LOCK_AVAILABLE] =
143             uint8_t(ANDROID_CONTROL_AWB_LOCK_AVAILABLE_FALSE);
144         m[ANDROID_CONTROL_AVAILABLE_MODES]
145             .add<uint8_t>(ANDROID_CONTROL_MODE_OFF)
146             .add<uint8_t>(ANDROID_CONTROL_MODE_AUTO);
147         {
148             const auto zoomRatioRange = mHwCamera->getZoomRatioRange();
149             m[ANDROID_CONTROL_ZOOM_RATIO_RANGE]
150                 .add<float>(zoomRatioRange.first)
151                 .add<float>(zoomRatioRange.second);
152         }
153     }
154     {   // ANDROID_EDGE_...
155         m[ANDROID_EDGE_AVAILABLE_EDGE_MODES]
156             .add<uint8_t>(ANDROID_EDGE_MODE_OFF);
157     }
158     {   // ANDROID_FLASH_INFO_...
159         const auto supportedFlashStrength = mHwCamera->getSupportedFlashStrength();
160         if (supportedFlashStrength.first > 0) {
161             m[ANDROID_FLASH_INFO_AVAILABLE] = uint8_t(ANDROID_FLASH_INFO_AVAILABLE_TRUE);
162             m[ANDROID_FLASH_INFO_STRENGTH_MAXIMUM_LEVEL] =
163                 int32_t(supportedFlashStrength.first);
164             m[ANDROID_FLASH_INFO_STRENGTH_DEFAULT_LEVEL] =
165                 int32_t(supportedFlashStrength.second);
166         } else {
167             m[ANDROID_FLASH_INFO_AVAILABLE] = uint8_t(ANDROID_FLASH_INFO_AVAILABLE_FALSE);
168         }
169     }
170     {   // ANDROID_HOT_PIXEL_...
171         m[ANDROID_HOT_PIXEL_AVAILABLE_HOT_PIXEL_MODES]
172             .add<uint8_t>(ANDROID_HOT_PIXEL_MODE_OFF);
173     }
174     {   // ANDROID_JPEG_...
175         {
176             auto& v = m[ANDROID_JPEG_AVAILABLE_THUMBNAIL_SIZES];
177             for (const auto sz : mHwCamera->getAvailableThumbnailSizes()) {
178                 v.add<int32_t>(sz.width).add<int32_t>(sz.height);
179             }
180         }
181         m[ANDROID_JPEG_MAX_SIZE] = int32_t(mHwCamera->getJpegMaxSize());
182     }
183     {   // ANDROID_LENS_...
184         m[ANDROID_LENS_FACING] = uint8_t(mHwCamera->isBackFacing() ?
185             ANDROID_LENS_FACING_BACK : ANDROID_LENS_FACING_FRONT);
186 
187         {
188             auto& v = m[ANDROID_LENS_INFO_AVAILABLE_APERTURES];
189             for (const float ap : mHwCamera->getAvailableApertures()) {
190                 v.add<float>(ap);
191             }
192         }
193         {
194             auto& v = m[ANDROID_LENS_INFO_AVAILABLE_FOCAL_LENGTHS];
195             for (const float ap : mHwCamera->getAvailableFocalLength()) {
196                 v.add<float>(ap);
197             }
198         }
199 
200         m[ANDROID_LENS_INFO_AVAILABLE_OPTICAL_STABILIZATION]
201             .add<uint8_t>(ANDROID_LENS_OPTICAL_STABILIZATION_MODE_OFF);
202         m[ANDROID_LENS_INFO_HYPERFOCAL_DISTANCE] =
203             float(mHwCamera->getHyperfocalDistance());
204         m[ANDROID_LENS_INFO_MINIMUM_FOCUS_DISTANCE] =
205             float(mHwCamera->getMinimumFocusDistance());
206         m[ANDROID_LENS_INFO_FOCUS_DISTANCE_CALIBRATION] =
207             uint8_t(ANDROID_LENS_INFO_FOCUS_DISTANCE_CALIBRATION_APPROXIMATE);
208         // system/media/camera/docs/docs.html#dynamic_android.statistics.lensShadingMap
209         m[ANDROID_LENS_INFO_SHADING_MAP_SIZE].add<int32_t>(4).add<int32_t>(3);
210     }
211     {   // ANDROID_NOISE_REDUCTION_...
212         m[ANDROID_NOISE_REDUCTION_AVAILABLE_NOISE_REDUCTION_MODES]
213             .add<uint8_t>(ANDROID_NOISE_REDUCTION_MODE_OFF);
214     }
215     {   // ANDROID_REQUEST_...
216         {
217             const auto maxNumOutputStreams = mHwCamera->getMaxNumOutputStreams();
218             m[ANDROID_REQUEST_MAX_NUM_OUTPUT_STREAMS]
219                 .add<int32_t>(std::get<0>(maxNumOutputStreams))
220                 .add<int32_t>(std::get<1>(maxNumOutputStreams))
221                 .add<int32_t>(std::get<2>(maxNumOutputStreams));
222         }
223 
224         m[ANDROID_REQUEST_MAX_NUM_INPUT_STREAMS] = int32_t(0);
225         m[ANDROID_REQUEST_PIPELINE_MAX_DEPTH] = uint8_t(mHwCamera->getPipelineMaxDepth());
226         m[ANDROID_REQUEST_PARTIAL_RESULT_COUNT] = int32_t(1);
227         {
228             auto& availableCaps = m[ANDROID_REQUEST_AVAILABLE_CAPABILITIES];
229             uint32_t availableCapsBitmap =
230                 mHwCamera->getAvailableCapabilitiesBitmap();
231 
232             for (int i = 0; availableCapsBitmap; ++i, availableCapsBitmap >>= 1) {
233                 if (availableCapsBitmap & 1) {
234                     availableCaps.add<uint8_t>(i);
235                 }
236             }
237         }
238     }
239     {   // ANDROID_SCALER_...
240         m[ANDROID_SCALER_AVAILABLE_MAX_DIGITAL_ZOOM] =
241             float(mHwCamera->getMaxDigitalZoom());
242 
243         {
244             auto& streamConfigurations = m[ANDROID_SCALER_AVAILABLE_STREAM_CONFIGURATIONS];
245             auto& minFrameDurations = m[ANDROID_SCALER_AVAILABLE_MIN_FRAME_DURATIONS];
246             auto& stallDurations = m[ANDROID_SCALER_AVAILABLE_STALL_DURATIONS];
247 
248             const int64_t minFrameDurationNs = mHwCamera->getMinFrameDurationNs();
249             const int64_t stallFrameDurationNs = mHwCamera->getStallFrameDurationNs();
250             const auto supportedFormats = mHwCamera->getSupportedPixelFormats();
251 
252             for (const auto& res : mHwCamera->getSupportedResolutions()) {
253                 for (const auto fmt : supportedFormats) {
254                     const int32_t fmti = static_cast<int32_t>(fmt);
255 
256                     streamConfigurations
257                         .add<int32_t>(fmti)
258                         .add<int32_t>(res.width).add<int32_t>(res.height)
259                         .add<int32_t>(ANDROID_SCALER_AVAILABLE_STREAM_CONFIGURATIONS_OUTPUT);
260                     minFrameDurations
261                         .add<int64_t>(fmti)
262                         .add<int64_t>(res.width).add<int64_t>(res.height)
263                         .add<int64_t>(minFrameDurationNs);
264                     stallDurations
265                         .add<int64_t>(fmti)
266                         .add<int64_t>(res.width).add<int64_t>(res.height)
267                         .add<int64_t>((fmt == PixelFormat::BLOB) ? stallFrameDurationNs : 0);
268                 }
269             }
270         }
271 
272         m[ANDROID_SCALER_CROPPING_TYPE] =
273             uint8_t(ANDROID_SCALER_CROPPING_TYPE_CENTER_ONLY);
274     }
275     {   // ANDROID_SENSOR_...
276         m[ANDROID_SENSOR_ORIENTATION] =
277             int32_t(mHwCamera->getSensorOrientation());
278         m[ANDROID_SENSOR_BLACK_LEVEL_PATTERN]
279             .add<int32_t>(64).add<int32_t>(64).add<int32_t>(64).add<int32_t>(64);
280         m[ANDROID_SENSOR_REFERENCE_ILLUMINANT1] =
281             uint8_t(ANDROID_SENSOR_REFERENCE_ILLUMINANT1_D50);
282         {
283             const camera_metadata_rational_t zero = {
284                 .numerator = 0, .denominator = 128
285             };
286             const camera_metadata_rational_t one = {
287                 .numerator = 128, .denominator = 128
288             };
289 
290             m[ANDROID_SENSOR_CALIBRATION_TRANSFORM1]
291                 .add(one).add(zero).add(zero)
292                 .add(zero).add(one).add(zero)
293                 .add(zero).add(zero).add(one);
294         }
295         {
296             const auto R1024 = [](int n){
297                 return camera_metadata_rational_t{
298                     .numerator = n, .denominator = 1024
299                 };
300             };
301 
302             // The values are borrowed from
303             // https://android.googlesource.com/platform/hardware/google/camera/+/refs/heads/main/devices/EmulatedCamera/hwl/configs/emu_camera_back.json
304             m[ANDROID_SENSOR_COLOR_TRANSFORM1]
305                 .add(R1024(3209)).add(R1024(-1655)).add(R1024(-502))
306                 .add(R1024(-1002)).add(R1024(1962)).add(R1024(34))
307                 .add(R1024(73)).add(R1024(-234)).add(R1024(1438));
308 
309             m[ANDROID_SENSOR_FORWARD_MATRIX1]
310                 .add(R1024(446)).add(R1024(394)).add(R1024(146))
311                 .add(R1024(227)).add(R1024(734)).add(R1024(62))
312                 .add(R1024(14)).add(R1024(99)).add(R1024(731));
313         }
314 
315         m[ANDROID_SENSOR_AVAILABLE_TEST_PATTERN_MODES]
316             .add<int32_t>(ANDROID_SENSOR_TEST_PATTERN_MODE_OFF);
317 
318         {
319             const auto sensorSize = mHwCamera->getSensorSize();
320             const auto sensorDPI = mHwCamera->getSensorDPI();
321 
322             m[ANDROID_SENSOR_INFO_ACTIVE_ARRAY_SIZE]
323                 .add<int32_t>(0).add<int32_t>(0)
324                 .add<int32_t>(sensorSize.width)
325                 .add<int32_t>(sensorSize.height);
326             m[ANDROID_SENSOR_INFO_PHYSICAL_SIZE]
327                 .add<float>(sensorSize.width / sensorDPI)
328                 .add<float>(sensorSize.height / sensorDPI);
329             m[ANDROID_SENSOR_INFO_PIXEL_ARRAY_SIZE]
330                 .add<int32_t>(sensorSize.width)
331                 .add<int32_t>(sensorSize.height);
332             m[ANDROID_SENSOR_INFO_PRE_CORRECTION_ACTIVE_ARRAY_SIZE]
333                 .add<int32_t>(0).add<int32_t>(0)
334                 .add<int32_t>(sensorSize.width)
335                 .add<int32_t>(sensorSize.height);
336         }
337         {
338             const auto senitivityRange = mHwCamera->getSensorSensitivityRange();
339 
340             m[ANDROID_SENSOR_INFO_SENSITIVITY_RANGE]
341                 .add<int32_t>(senitivityRange.first)
342                 .add<int32_t>(senitivityRange.second);
343 
344             m[ANDROID_SENSOR_MAX_ANALOG_SENSITIVITY] =
345                 int32_t(senitivityRange.second / 2);
346         }
347 
348         m[ANDROID_SENSOR_INFO_COLOR_FILTER_ARRANGEMENT] =
349             uint8_t(mHwCamera->getSensorColorFilterArrangement());
350 
351         {
352             const auto exposureTimeRange = mHwCamera->getSensorExposureTimeRange();
353 
354             m[ANDROID_SENSOR_INFO_EXPOSURE_TIME_RANGE]
355                 .add<int64_t>(exposureTimeRange.first)
356                 .add<int64_t>(exposureTimeRange.second);
357         }
358 
359         m[ANDROID_SENSOR_INFO_MAX_FRAME_DURATION] =
360             int64_t(mHwCamera->getSensorMaxFrameDuration());
361         m[ANDROID_SENSOR_INFO_WHITE_LEVEL] = int32_t(1023);
362         m[ANDROID_SENSOR_INFO_TIMESTAMP_SOURCE] =
363             uint8_t(ANDROID_SENSOR_INFO_TIMESTAMP_SOURCE_UNKNOWN);  // SYSTEM_TIME_MONOTONIC
364     }
365     {   // ANDROID_SHADING_...
366         m[ANDROID_SHADING_AVAILABLE_MODES]
367             .add<uint8_t>(ANDROID_SHADING_MODE_OFF)
368             .add<uint8_t>(ANDROID_SHADING_MODE_FAST);
369     }
370     {   // ANDROID_STATISTICS_...
371         m[ANDROID_STATISTICS_INFO_AVAILABLE_FACE_DETECT_MODES]
372             .add<uint8_t>(ANDROID_STATISTICS_FACE_DETECT_MODE_OFF);
373         m[ANDROID_STATISTICS_INFO_MAX_FACE_COUNT] = int32_t(0);
374         m[ANDROID_STATISTICS_INFO_AVAILABLE_HOT_PIXEL_MAP_MODES]
375             .add<uint8_t>(ANDROID_STATISTICS_HOT_PIXEL_MAP_MODE_OFF);
376         m[ANDROID_STATISTICS_INFO_AVAILABLE_LENS_SHADING_MAP_MODES]
377             .add<uint8_t>(ANDROID_STATISTICS_LENS_SHADING_MAP_MODE_OFF);
378     }
379     {   // ANDROID_INFO_...
380         m[ANDROID_INFO_SUPPORTED_HARDWARE_LEVEL] =
381             uint8_t(ANDROID_INFO_SUPPORTED_HARDWARE_LEVEL_LIMITED);
382     }
383     {   // ANDROID_SYNC_
384         m[ANDROID_SYNC_MAX_LATENCY] = ANDROID_SYNC_MAX_LATENCY_UNKNOWN;
385     }
386     {   // ANDROID_DISTORTION_CORRECTION_...
387         m[ANDROID_DISTORTION_CORRECTION_AVAILABLE_MODES]
388             .add<uint8_t>(ANDROID_DISTORTION_CORRECTION_MODE_OFF);
389     }
390 
391     ////////////////////////////////////////////////////////////////////////////
392     {
393         const std::vector<uint32_t> keys = getSortedKeys(m);
394         CameraMetadataValue& val = m[ANDROID_REQUEST_AVAILABLE_CHARACTERISTICS_KEYS];
395         for (const uint32_t key : keys) {
396             val.add<int32_t>(key);
397         }
398     }
399     {
400         CameraMetadataMap r = constructDefaultRequestSettings(RequestTemplate::PREVIEW);
401 
402         {
403             const std::vector<uint32_t> keys = getSortedKeys(r);
404             CameraMetadataValue& val = m[ANDROID_REQUEST_AVAILABLE_REQUEST_KEYS];
405             for (const uint32_t key : keys) {
406                 val.add<int32_t>(key);
407             }
408         }
409 
410         for (const uint32_t key : kExtraResultKeys) {
411             r[key];
412         }
413 
414         {
415             const std::vector<uint32_t> keys = getSortedKeys(r);
416             CameraMetadataValue& val = m[ANDROID_REQUEST_AVAILABLE_RESULT_KEYS];
417             for (const uint32_t key : keys) {
418                 val.add<int32_t>(key);
419             }
420         }
421     }
422 
423     auto maybeMetadata = serializeCameraMetadataMap(m);
424     if (maybeMetadata) {
425         *metadata = std::move(maybeMetadata.value());
426         return ScopedAStatus::ok();
427     } else {
428         return toScopedAStatus(Status::INTERNAL_ERROR);
429     }
430 }
431 
getPhysicalCameraCharacteristics(const std::string &,CameraMetadata *)432 ScopedAStatus CameraDevice::getPhysicalCameraCharacteristics(
433         const std::string& /*physicalCameraId*/, CameraMetadata* /*metadata*/) {
434     return toScopedAStatus(FAILURE(Status::OPERATION_NOT_SUPPORTED));
435 }
436 
getResourceCost(CameraResourceCost * cost)437 ScopedAStatus CameraDevice::getResourceCost(CameraResourceCost* cost) {
438     cost->resourceCost = 100;
439     return ScopedAStatus::ok();
440 }
441 
isStreamCombinationSupported(const StreamConfiguration & cfg,bool * support)442 ScopedAStatus CameraDevice::isStreamCombinationSupported(
443         const StreamConfiguration& cfg, bool* support) {
444     *support = CameraDeviceSession::isStreamCombinationSupported(cfg, *mHwCamera);
445     return ScopedAStatus::ok();
446 }
447 
open(const std::shared_ptr<ICameraDeviceCallback> & callback,std::shared_ptr<ICameraDeviceSession> * session)448 ScopedAStatus CameraDevice::open(const std::shared_ptr<ICameraDeviceCallback>& callback,
449         std::shared_ptr<ICameraDeviceSession>* session) {
450     *session = ndk::SharedRefBase::make<CameraDeviceSession>(
451         mSelf.lock(), callback, *mHwCamera);
452     return ScopedAStatus::ok();
453 }
454 
openInjectionSession(const std::shared_ptr<ICameraDeviceCallback> &,std::shared_ptr<ICameraInjectionSession> *)455 ScopedAStatus CameraDevice::openInjectionSession(
456         const std::shared_ptr<ICameraDeviceCallback>& /*callback*/,
457         std::shared_ptr<ICameraInjectionSession>* /*session*/) {
458     return toScopedAStatus(FAILURE(Status::OPERATION_NOT_SUPPORTED));
459 }
460 
setTorchMode(const bool)461 ScopedAStatus CameraDevice::setTorchMode(const bool /*on*/) {
462     return toScopedAStatus(FAILURE(Status::OPERATION_NOT_SUPPORTED));
463 }
464 
turnOnTorchWithStrengthLevel(const int32_t)465 ScopedAStatus CameraDevice::turnOnTorchWithStrengthLevel(const int32_t /*strength*/) {
466     return toScopedAStatus(FAILURE(Status::OPERATION_NOT_SUPPORTED));
467 }
468 
getTorchStrengthLevel(int32_t *)469 ScopedAStatus CameraDevice::getTorchStrengthLevel(int32_t* /*strength*/) {
470     return toScopedAStatus(FAILURE(Status::OPERATION_NOT_SUPPORTED));
471 }
472 
constructDefaultRequestSettings(const RequestTemplate tpl) const473 CameraMetadataMap CameraDevice::constructDefaultRequestSettings(const RequestTemplate tpl) const {
474     using namespace std::literals;
475     const auto sensorSize = mHwCamera->getSensorSize();
476     const std::pair<int32_t, int32_t> fpsRange = mHwCamera->getDefaultTargetFpsRange(tpl);
477 
478     CameraMetadataMap m;
479 
480     m[ANDROID_COLOR_CORRECTION_MODE] =
481         uint8_t(ANDROID_COLOR_CORRECTION_MODE_FAST);
482     m[ANDROID_COLOR_CORRECTION_ABERRATION_MODE] =
483         uint8_t(ANDROID_COLOR_CORRECTION_ABERRATION_MODE_OFF);
484     m[ANDROID_CONTROL_AE_ANTIBANDING_MODE] =
485         uint8_t(ANDROID_CONTROL_AE_ANTIBANDING_MODE_AUTO);
486     m[ANDROID_CONTROL_AE_EXPOSURE_COMPENSATION] = int32_t(0);
487     m[ANDROID_CONTROL_AE_LOCK] = uint8_t(ANDROID_CONTROL_AE_LOCK_OFF);
488     m[ANDROID_CONTROL_AE_MODE] = uint8_t((tpl == RequestTemplate::MANUAL) ?
489         ANDROID_CONTROL_AE_MODE_OFF : ANDROID_CONTROL_AE_MODE_ON);
490     m[ANDROID_CONTROL_AE_TARGET_FPS_RANGE]
491         .add<int32_t>(fpsRange.first).add<int32_t>(fpsRange.second);
492     m[ANDROID_CONTROL_AE_PRECAPTURE_TRIGGER] =
493         uint8_t(ANDROID_CONTROL_AE_PRECAPTURE_TRIGGER_IDLE);
494     m[ANDROID_CONTROL_AF_MODE] = uint8_t((tpl == RequestTemplate::MANUAL) ?
495         ANDROID_CONTROL_AF_MODE_OFF : ANDROID_CONTROL_AF_MODE_AUTO);
496     m[ANDROID_CONTROL_AF_TRIGGER] = uint8_t(ANDROID_CONTROL_AF_TRIGGER_IDLE);
497     m[ANDROID_CONTROL_AWB_LOCK] = uint8_t(ANDROID_CONTROL_AWB_LOCK_OFF);
498     m[ANDROID_CONTROL_AWB_MODE] = uint8_t((tpl == RequestTemplate::MANUAL) ?
499         ANDROID_CONTROL_AWB_MODE_OFF : ANDROID_CONTROL_AWB_MODE_AUTO);
500     m[ANDROID_CONTROL_CAPTURE_INTENT] = uint8_t(MapRequestTemplateToIntent(tpl));
501     m[ANDROID_CONTROL_EFFECT_MODE] = uint8_t(ANDROID_CONTROL_EFFECT_MODE_OFF);
502     m[ANDROID_CONTROL_MODE] = uint8_t((tpl == RequestTemplate::MANUAL) ?
503         ANDROID_CONTROL_MODE_OFF : ANDROID_CONTROL_MODE_AUTO);
504     m[ANDROID_CONTROL_SCENE_MODE] = uint8_t(ANDROID_CONTROL_SCENE_MODE_DISABLED);
505     m[ANDROID_CONTROL_VIDEO_STABILIZATION_MODE] =
506         uint8_t(ANDROID_CONTROL_VIDEO_STABILIZATION_MODE_OFF);
507     m[ANDROID_CONTROL_ZOOM_RATIO] = float(mHwCamera->getZoomRatioRange().first);
508 
509     m[ANDROID_EDGE_MODE] = uint8_t(ANDROID_EDGE_MODE_OFF);
510 
511     m[ANDROID_FLASH_MODE] = uint8_t(ANDROID_FLASH_MODE_OFF);
512 
513     m[ANDROID_HOT_PIXEL_MODE] = uint8_t(ANDROID_HOT_PIXEL_MODE_OFF);
514 
515     m[ANDROID_JPEG_ORIENTATION] = int32_t(0);
516     m[ANDROID_JPEG_QUALITY] = uint8_t(85);
517     m[ANDROID_JPEG_THUMBNAIL_QUALITY] = uint8_t(85);
518     m[ANDROID_JPEG_THUMBNAIL_SIZE].add<int32_t>(0).add<int32_t>(0);
519 
520     m[ANDROID_LENS_APERTURE] = float(mHwCamera->getDefaultAperture());
521     m[ANDROID_LENS_FOCAL_LENGTH] = float(mHwCamera->getDefaultFocalLength());
522     m[ANDROID_LENS_FOCUS_DISTANCE] = float(mHwCamera->getMinimumFocusDistance());
523     m[ANDROID_LENS_OPTICAL_STABILIZATION_MODE] =
524         uint8_t(ANDROID_LENS_OPTICAL_STABILIZATION_MODE_OFF);
525 
526     m[ANDROID_NOISE_REDUCTION_MODE] = uint8_t(ANDROID_NOISE_REDUCTION_MODE_OFF);
527 
528     m[ANDROID_SENSOR_TEST_PATTERN_MODE] = int32_t(ANDROID_SENSOR_TEST_PATTERN_MODE_OFF);
529 
530     m[ANDROID_REQUEST_ID] = int32_t(0);
531     m[ANDROID_REQUEST_METADATA_MODE] = uint8_t(ANDROID_REQUEST_METADATA_MODE_FULL);
532 
533     m[ANDROID_SCALER_CROP_REGION]
534         .add<int32_t>(0).add<int32_t>(0)
535         .add<int32_t>(sensorSize.width - 1)
536         .add<int32_t>(sensorSize.height - 1);
537 
538     m[ANDROID_SENSOR_EXPOSURE_TIME] = int64_t(mHwCamera->getDefaultSensorExpTime());
539     m[ANDROID_SENSOR_FRAME_DURATION] = int64_t(mHwCamera->getDefaultSensorFrameDuration());
540     m[ANDROID_SENSOR_SENSITIVITY] = int32_t(mHwCamera->getDefaultSensorSensitivity());
541 
542     m[ANDROID_SHADING_MODE] = uint8_t(ANDROID_SHADING_MODE_OFF);
543 
544     m[ANDROID_STATISTICS_FACE_DETECT_MODE] =
545         uint8_t(ANDROID_STATISTICS_FACE_DETECT_MODE_OFF);
546     m[ANDROID_STATISTICS_SHARPNESS_MAP_MODE] =
547         uint8_t(ANDROID_STATISTICS_SHARPNESS_MAP_MODE_OFF);
548     m[ANDROID_STATISTICS_HOT_PIXEL_MAP_MODE] =
549         uint8_t(ANDROID_STATISTICS_HOT_PIXEL_MAP_MODE_OFF);
550     m[ANDROID_STATISTICS_LENS_SHADING_MAP_MODE] =
551         uint8_t(ANDROID_STATISTICS_LENS_SHADING_MAP_MODE_OFF);
552 
553     m[ANDROID_BLACK_LEVEL_LOCK] = uint8_t(ANDROID_BLACK_LEVEL_LOCK_OFF);
554     m[ANDROID_DISTORTION_CORRECTION_MODE] =
555         uint8_t(ANDROID_DISTORTION_CORRECTION_MODE_OFF);
556 
557     return m;
558 }
559 
560 }  // namespace implementation
561 }  // namespace provider
562 }  // namespace camera
563 }  // namespace hardware
564 }  // namespace android
565