1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
|
/*
* Copyright (C) 2017, The LineageOS Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#define LOG_NDEBUG 0
#define LOG_TAG "CameraWrapper"
#include <cutils/log.h>
#include "CameraWrapper.h"
#include "Camera3Wrapper.h"
static camera_module_t *gVendorModule = 0;
static char prop[PROPERTY_VALUE_MAX];
static int check_vendor_module()
{
int rv = 0;
ALOGV("%s", __FUNCTION__);
if(gVendorModule)
return 0;
rv = hw_get_module_by_class("camera", "vendor", (const hw_module_t **)&gVendorModule);
if (rv)
ALOGE("failed to open vendor camera module");
return rv;
}
static struct hw_module_methods_t camera_module_methods = {
.open = camera_device_open
};
camera_module_t HAL_MODULE_INFO_SYM = {
.common = {
.tag = HARDWARE_MODULE_TAG,
.module_api_version = CAMERA_MODULE_API_VERSION_2_4,
.hal_api_version = HARDWARE_HAL_API_VERSION,
.id = CAMERA_HARDWARE_MODULE_ID,
.name = "LineageOS Camera Wrapper",
.author = "The LineageOS Project",
.methods = &camera_module_methods,
.dso = NULL,
.reserved = {0},
},
.get_number_of_cameras = camera_get_number_of_cameras,
.get_camera_info = camera_get_camera_info,
.set_callbacks = camera_set_callbacks,
.get_vendor_tag_ops = camera_get_vendor_tag_ops,
.open_legacy = NULL,
.set_torch_mode = camera_set_torch_mode,
.init = NULL,
.reserved = {0},
};
static int camera_device_open(const hw_module_t* module, const char* name,
hw_device_t** device)
{
int rv = -EINVAL;
property_get("persist.camera.HAL3.enabled", prop, "1");
int isHAL3Enabled = atoi(prop);
ALOGV("%s: property persist.camera.HAL3.enabled is set to %d", __FUNCTION__, isHAL3Enabled);
if (name != NULL) {
if (check_vendor_module())
return -EINVAL;
if (isHAL3Enabled) {
ALOGV("%s: using HAL3", __FUNCTION__);
rv = camera3_device_open(module, name, device);
} else {
ALOGV("%s: Only HAL3 is supported", __FUNCTION__);
return -EINVAL;
}
}
return rv;
}
static int camera_get_number_of_cameras(void)
{
ALOGV("%s", __FUNCTION__);
if (check_vendor_module())
return 0;
return gVendorModule->get_number_of_cameras();
}
static int camera_get_camera_info(int camera_id, struct camera_info *info)
{
ALOGV("%s", __FUNCTION__);
if (check_vendor_module())
return 0;
return gVendorModule->get_camera_info(camera_id, info);
}
static int camera_set_callbacks(const camera_module_callbacks_t *callbacks)
{
ALOGV("%s", __FUNCTION__);
if (check_vendor_module())
return 0;
return gVendorModule->set_callbacks(callbacks);
}
static void camera_get_vendor_tag_ops(vendor_tag_ops_t* ops)
{
ALOGV("%s", __FUNCTION__);
if (check_vendor_module())
return;
return gVendorModule->get_vendor_tag_ops(ops);
}
static int camera_set_torch_mode(const char* camera_id, bool on)
{
ALOGV("%s", __FUNCTION__);
if (check_vendor_module())
return -EINVAL;
return gVendorModule->set_torch_mode(camera_id, on);
}
|