blob: 96a715c7b8bea7375e10bc92691c2b83ae055db8 [file] [log] [blame]
Jayant Chowdharya04055f2022-01-03 02:07:49 +00001/*
2 * Copyright (C) 2022 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#ifndef ANDROID_SERVERS_CAMERA_HAL_CONVERSION_TEMPLATED_H
17#define ANDROID_SERVERS_CAMERA_HAL_CONVERSION_TEMPLATED_H
18
19#include "common/CameraProviderManager.h"
20
21#include <device3/Camera3StreamInterface.h>
22
23namespace android {
24
25template <class HalCameraDeviceStatus>
26HalCameraDeviceStatus mapFrameworkToHalCameraDeviceStatus(
27 const CameraDeviceStatus& s) {
28 switch(s) {
29 case CameraDeviceStatus::PRESENT:
30 return HalCameraDeviceStatus::PRESENT;
31 case CameraDeviceStatus::NOT_PRESENT:
32 return HalCameraDeviceStatus::NOT_PRESENT;
33 case CameraDeviceStatus::ENUMERATING:
34 return HalCameraDeviceStatus::ENUMERATING;
35 }
36 ALOGW("Unexpectedcamera device status code %d", s);
37 return HalCameraDeviceStatus::NOT_PRESENT;
38}
39
40template <class HalCameraDeviceStatus>
41CameraDeviceStatus HalToFrameworkCameraDeviceStatus(
42 const HalCameraDeviceStatus& s) {
43 switch(s) {
44 case HalCameraDeviceStatus::PRESENT:
45 return CameraDeviceStatus::PRESENT;
46 case HalCameraDeviceStatus::NOT_PRESENT:
47 return CameraDeviceStatus::NOT_PRESENT;
48 case HalCameraDeviceStatus::ENUMERATING:
49 return CameraDeviceStatus::ENUMERATING;
50 }
51 ALOGW("Unexpectedcamera device status code %d", s);
52 return CameraDeviceStatus::NOT_PRESENT;
53}
54
55template <class HalCameraResourceCost>
56CameraResourceCost HalToFrameworkResourceCost(
57 const HalCameraResourceCost& s) {
58 CameraResourceCost internalResourceCost;
59 internalResourceCost.resourceCost = (uint32_t)s.resourceCost;
60 for (const auto device : s.conflictingDevices) {
61 internalResourceCost.conflictingDevices.emplace_back(device.c_str());
62 }
63 return internalResourceCost;
64}
65
66template <class HalTorchModeStatus>
67TorchModeStatus HalToFrameworkTorchModeStatus(
68 const HalTorchModeStatus& s) {
69 switch(s) {
70 case HalTorchModeStatus::NOT_AVAILABLE:
71 return TorchModeStatus::NOT_AVAILABLE;
72 case HalTorchModeStatus::AVAILABLE_OFF:
73 return TorchModeStatus::AVAILABLE_OFF;
74 case HalTorchModeStatus::AVAILABLE_ON:
75 return TorchModeStatus::AVAILABLE_ON;
76 }
77 ALOGW("Unexpectedcamera torch mode status code %d", s);
78 return TorchModeStatus::NOT_AVAILABLE;
79}
80
81template <class HalCameraDeviceStatus>
82 const char* HalDeviceStatusToString(const HalCameraDeviceStatus& s) {
83 switch(s) {
84 case HalCameraDeviceStatus::NOT_PRESENT:
85 return "NOT_PRESENT";
86 case HalCameraDeviceStatus::PRESENT:
87 return "PRESENT";
88 case HalCameraDeviceStatus::ENUMERATING:
89 return "ENUMERATING";
90 }
91 ALOGW("Unexpected HAL device status code %d", s);
92 return "UNKNOWN_STATUS";
93}
94
95}
96
97#endif