universal7580: camera: add empty camera wrapper
[GitHub/LineageOS/android_device_samsung_universal7580-common.git] / camera / CameraWrapper.cpp
1 /*
2 * Copyright (C) 2017, The LineageOS 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 LOG_NDEBUG 0
18 #define LOG_PARAMETERS
19
20 #define LOG_TAG "CameraWrapper"
21 #include <cutils/log.h>
22
23 #include "CameraWrapper.h"
24 #include "Camera2Wrapper.h"
25
26 static camera_module_t *gVendorModule = 0;
27
28 static int check_vendor_module()
29 {
30 int rv = 0;
31 ALOGV("%s", __FUNCTION__);
32
33 if(gVendorModule)
34 return 0;
35
36 rv = hw_get_module_by_class("camera", "vendor", (const hw_module_t **)&gVendorModule);
37 if (rv)
38 ALOGE("failed to open vendor camera module");
39 return rv;
40 }
41
42 static struct hw_module_methods_t camera_module_methods = {
43 .open = camera_device_open
44 };
45
46 camera_module_t HAL_MODULE_INFO_SYM = {
47 .common = {
48 .tag = HARDWARE_MODULE_TAG,
49 .module_api_version = CAMERA_MODULE_API_VERSION_2_4,
50 .hal_api_version = HARDWARE_HAL_API_VERSION,
51 .id = CAMERA_HARDWARE_MODULE_ID,
52 .name = "universal7580 Camera Wrapper",
53 .author = "The LineageOS Project",
54 .methods = &camera_module_methods,
55 .dso = NULL,
56 .reserved = {0},
57 },
58 .get_number_of_cameras = camera_get_number_of_cameras,
59 .get_camera_info = camera_get_camera_info,
60 .set_callbacks = camera_set_callbacks,
61 .get_vendor_tag_ops = camera_get_vendor_tag_ops,
62 .open_legacy = camera_open_legacy,
63 .set_torch_mode = NULL,
64 .init = NULL,
65 .reserved = {0},
66 };
67
68 static int camera_device_open(const hw_module_t* module, const char* name,
69 hw_device_t** device)
70 {
71 int rv = -EINVAL;
72
73 if (name != NULL) {
74 if (check_vendor_module())
75 return -EINVAL;
76 rv = camera2_device_open(module, name, device);
77 }
78
79 return rv;
80 }
81
82 static int camera_get_number_of_cameras(void)
83 {
84 ALOGV("%s", __FUNCTION__);
85 if (check_vendor_module())
86 return 0;
87 return gVendorModule->get_number_of_cameras();
88 }
89
90 static int camera_get_camera_info(int camera_id, struct camera_info *info)
91 {
92 ALOGV("%s", __FUNCTION__);
93 if (check_vendor_module())
94 return 0;
95 return gVendorModule->get_camera_info(camera_id, info);
96 }
97
98 static int camera_set_callbacks(const camera_module_callbacks_t *callbacks)
99 {
100 ALOGV("%s", __FUNCTION__);
101 if (check_vendor_module())
102 return 0;
103 return gVendorModule->set_callbacks(callbacks);
104 }
105
106 static void camera_get_vendor_tag_ops(vendor_tag_ops_t* ops)
107 {
108 ALOGV("%s", __FUNCTION__);
109 if (check_vendor_module())
110 return;
111 return gVendorModule->get_vendor_tag_ops(ops);
112 }
113
114 static int camera_open_legacy(const struct hw_module_t* module, const char* id, uint32_t halVersion, struct hw_device_t** device)
115 {
116 ALOGV("%s", __FUNCTION__);
117 if (check_vendor_module())
118 return 0;
119 return camera2_device_open(module, id, device);
120 }