blob: 6afe550d944245de57aaa52fd69129cdcd032031
1 | /* |
2 | * Copyright (C) 2013 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 | #include <system/camera_metadata.h> |
18 | //#include "Metadata.h" |
19 | |
20 | //#define LOG_NDEBUG 0 |
21 | #define LOG_TAG "VendorTags" |
22 | #include <cutils/log.h> |
23 | |
24 | #define ATRACE_TAG (ATRACE_TAG_CAMERA | ATRACE_TAG_HAL) |
25 | #include <utils/Log.h> |
26 | |
27 | #include "VendorTags.h" |
28 | |
29 | namespace default_camera_hal { |
30 | |
31 | // Internal representations of vendor tags for convenience. |
32 | // Other classes must access this data via public interfaces. |
33 | // Structured to be easy to extend and contain complexity. |
34 | namespace { |
35 | // Describes a single vendor tag entry |
36 | struct Entry { |
37 | const char* name; |
38 | uint8_t type; |
39 | }; |
40 | // Describes a vendor tag section |
41 | struct Section { |
42 | const char* name; |
43 | uint32_t start; |
44 | uint32_t end; |
45 | const Entry* tags; |
46 | }; |
47 | |
48 | enum vendor_section { |
49 | ANDROID_LENS = VENDOR_SECTION, |
50 | ANDROID_LENS_INFO, |
51 | ANDROID_SECTION_END |
52 | }; |
53 | |
54 | const int FAKEVENDOR_SECTION_COUNT = ANDROID_SECTION_END - VENDOR_SECTION; |
55 | |
56 | enum vendor_section_ranges { |
57 | ANDROID_LENS_START = ANDROID_LENS << 16, |
58 | ANDROID_LENS_INFO_START = ANDROID_LENS_INFO << 16 |
59 | }; |
60 | |
61 | |
62 | enum vendor_tags { |
63 | ANDROID_LENS_APERTURE = // float | public |
64 | ANDROID_LENS_START, |
65 | ANDROID_LENS_FILTER_DENSITY, // float | public |
66 | ANDROID_LENS_FOCAL_LENGTH, // float | public |
67 | ANDROID_LENS_FOCUS_DISTANCE, // float | public |
68 | ANDROID_LENS_OPTICAL_STABILIZATION_MODE, // enum | public |
69 | ANDROID_LENS_FACING, // enum | public |
70 | #if PLATFORM_SDK_VERSION <= 22 |
71 | ANDROID_LENS_POSITION, // float[] | system |
72 | #endif |
73 | ANDROID_LENS_FOCUS_RANGE, // float[] | public |
74 | ANDROID_LENS_STATE, // enum | public |
75 | ANDROID_LENS_END, |
76 | }; |
77 | |
78 | |
79 | enum vendor_info_tags { |
80 | ANDROID_LENS_INFO_AVAILABLE_APERTURES = // float[] | public |
81 | ANDROID_LENS_INFO_START, |
82 | ANDROID_LENS_INFO_AVAILABLE_FILTER_DENSITIES, // float[] | public |
83 | ANDROID_LENS_INFO_AVAILABLE_FOCAL_LENGTHS, // float[] | public |
84 | ANDROID_LENS_INFO_AVAILABLE_OPTICAL_STABILIZATION,// byte[] | public |
85 | ANDROID_LENS_INFO_HYPERFOCAL_DISTANCE, // float | public |
86 | ANDROID_LENS_INFO_MINIMUM_FOCUS_DISTANCE, // float | public |
87 | ANDROID_LENS_INFO_SHADING_MAP_SIZE, // int32[] | hidden |
88 | ANDROID_LENS_INFO_FOCUS_DISTANCE_CALIBRATION, // enum | public |
89 | ANDROID_LENS_INFO_END, |
90 | }; |
91 | |
92 | |
93 | const static char *fakevendor_section_names[FAKEVENDOR_SECTION_COUNT] = { |
94 | "android.lens", |
95 | "android.lens.info" |
96 | }; |
97 | |
98 | static uint32_t fakevendor_section_bounds[FAKEVENDOR_SECTION_COUNT][2] = { |
99 | |
100 | { (uint32_t) ANDROID_LENS_START, (uint32_t) ANDROID_LENS_END }, |
101 | { (uint32_t) ANDROID_LENS_INFO_START, (uint32_t) ANDROID_LENS_INFO_END }, |
102 | |
103 | }; |
104 | |
105 | |
106 | vendor_tag_info_t fakevendor_lens[ANDROID_LENS_END - |
107 | ANDROID_LENS_START] = { |
108 | [ ANDROID_LENS_APERTURE - ANDROID_LENS_START ] = |
109 | { "aperture", TYPE_FLOAT }, |
110 | [ ANDROID_LENS_FILTER_DENSITY - ANDROID_LENS_START ] = |
111 | { "filterDensity", TYPE_FLOAT }, |
112 | [ ANDROID_LENS_FOCAL_LENGTH - ANDROID_LENS_START ] = |
113 | { "focalLength", TYPE_FLOAT }, |
114 | [ ANDROID_LENS_FOCUS_DISTANCE - ANDROID_LENS_START ] = |
115 | { "focusDistance", TYPE_FLOAT }, |
116 | [ ANDROID_LENS_OPTICAL_STABILIZATION_MODE - ANDROID_LENS_START ] = |
117 | { "opticalStabilizationMode", TYPE_BYTE }, |
118 | [ ANDROID_LENS_FACING - ANDROID_LENS_START ] = |
119 | { "facing", TYPE_BYTE }, |
120 | #if PLATFORM_SDK_VERSION <= 22 |
121 | [ ANDROID_LENS_POSITION - ANDROID_LENS_START ] = |
122 | { "position", TYPE_FLOAT }, |
123 | #endif |
124 | [ ANDROID_LENS_FOCUS_RANGE - ANDROID_LENS_START ] = |
125 | { "focusRange", TYPE_FLOAT }, |
126 | [ ANDROID_LENS_STATE - ANDROID_LENS_START ] = |
127 | { "state", TYPE_BYTE }, |
128 | |
129 | }; |
130 | |
131 | |
132 | vendor_tag_info_t fakevendor_lens_info[ANDROID_LENS_INFO_END - |
133 | ANDROID_LENS_INFO_START] = { |
134 | [ ANDROID_LENS_INFO_AVAILABLE_APERTURES - ANDROID_LENS_INFO_START ] = |
135 | { "availableApertures", TYPE_FLOAT }, |
136 | [ ANDROID_LENS_INFO_AVAILABLE_FILTER_DENSITIES - ANDROID_LENS_INFO_START ] = |
137 | { "availableFilterDensities", TYPE_FLOAT }, |
138 | [ ANDROID_LENS_INFO_AVAILABLE_FOCAL_LENGTHS - ANDROID_LENS_INFO_START ] = |
139 | { "availableFocalLengths", TYPE_FLOAT }, |
140 | [ ANDROID_LENS_INFO_AVAILABLE_OPTICAL_STABILIZATION - ANDROID_LENS_INFO_START ] = |
141 | { "availableOpticalStabilization", TYPE_BYTE }, |
142 | [ ANDROID_LENS_INFO_HYPERFOCAL_DISTANCE - ANDROID_LENS_INFO_START ] = |
143 | { "hyperfocalDistance", TYPE_FLOAT }, |
144 | [ ANDROID_LENS_INFO_MINIMUM_FOCUS_DISTANCE - ANDROID_LENS_INFO_START ] = |
145 | { "minimumFocusDistance", TYPE_FLOAT }, |
146 | [ ANDROID_LENS_INFO_SHADING_MAP_SIZE - ANDROID_LENS_INFO_START ] = |
147 | { "shadingMapSize", TYPE_INT32 }, |
148 | [ ANDROID_LENS_INFO_FOCUS_DISTANCE_CALIBRATION - ANDROID_LENS_INFO_START ] = |
149 | { "focusDistanceCalibration", TYPE_BYTE }, |
150 | |
151 | }; |
152 | |
153 | vendor_tag_info_t *fakevendor_tag_info[FAKEVENDOR_SECTION_COUNT] = { |
154 | fakevendor_lens, |
155 | fakevendor_lens_info |
156 | }; |
157 | |
158 | } // namespace |
159 | |
160 | VendorTags::VendorTags() |
161 | : mTagCount(0) |
162 | { |
163 | int section; |
164 | unsigned int start, end; |
165 | for (section = 0; section < FAKEVENDOR_SECTION_COUNT; section++) { |
166 | start = fakevendor_section_bounds[section][0]; |
167 | end = fakevendor_section_bounds[section][1]; |
168 | mTagCount += end - start; |
169 | } |
170 | } |
171 | |
172 | VendorTags::~VendorTags() |
173 | { |
174 | } |
175 | |
176 | int VendorTags::getTagCount(const vendor_tag_ops_t* ops) |
177 | { |
178 | ALOGV("%s ,mTagCount =%d",__func__,mTagCount); |
179 | return mTagCount; |
180 | } |
181 | |
182 | void VendorTags::getAllTags(const vendor_tag_ops_t* ops, uint32_t* tag_array) |
183 | { |
184 | ALOGV("%s",__func__); |
185 | if (tag_array == NULL) { |
186 | ALOGE("%s: NULL tag_array", __func__); |
187 | return; |
188 | } |
189 | int section; |
190 | unsigned int start, end, tag; |
191 | for (section = 0; section < FAKEVENDOR_SECTION_COUNT; section++) { |
192 | start = fakevendor_section_bounds[section][0]; |
193 | end = fakevendor_section_bounds[section][1]; |
194 | for (tag = start; tag < end; tag++) { |
195 | *tag_array++ = tag; |
196 | } |
197 | } |
198 | } |
199 | |
200 | const char* VendorTags::getSectionName(const vendor_tag_ops_t* ops, uint32_t tag) |
201 | { |
202 | ALOGV("%s",__func__); |
203 | |
204 | int tag_section = (tag >> 16) - VENDOR_SECTION; |
205 | if (tag_section < 0 || |
206 | tag_section >= FAKEVENDOR_SECTION_COUNT) return NULL; |
207 | |
208 | return fakevendor_section_names[tag_section]; |
209 | } |
210 | |
211 | const char* VendorTags::getTagName(const vendor_tag_ops_t* ops, uint32_t tag) |
212 | { |
213 | ALOGV("%s",__func__); |
214 | |
215 | int tag_section = (tag >> 16) - VENDOR_SECTION; |
216 | if (tag_section < 0 |
217 | || tag_section >= FAKEVENDOR_SECTION_COUNT |
218 | || tag >= fakevendor_section_bounds[tag_section][1]) return NULL; |
219 | int tag_index = tag & 0xFFFF; |
220 | return fakevendor_tag_info[tag_section][tag_index].tag_name; |
221 | } |
222 | |
223 | int VendorTags::getTagType(const vendor_tag_ops_t* ops, uint32_t tag) |
224 | { |
225 | ALOGV("%s",__func__); |
226 | |
227 | int tag_section = (tag >> 16) - VENDOR_SECTION; |
228 | if (tag_section < 0 |
229 | || tag_section >= FAKEVENDOR_SECTION_COUNT |
230 | || tag >= fakevendor_section_bounds[tag_section][1]) return -1; |
231 | int tag_index = tag & 0xFFFF; |
232 | return fakevendor_tag_info[tag_section][tag_index].tag_type; |
233 | } |
234 | } // namespace default_camera_hal |
235 |