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