blob: f12139144659d2335e2a76f29b81222aa583eb85 [file] [log] [blame]
Yin-Chia Yeh0dea57f2015-12-09 16:46:07 -08001/*
2 * Copyright (C) 2015 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//#define LOG_NDEBUG 0
18#define LOG_TAG "ACameraMetadata"
19
20#include "ACameraMetadata.h"
21#include <utils/Vector.h>
22
23using namespace android;
24
25/**
26 * ACameraMetadata Implementation
27 */
28ACameraMetadata::ACameraMetadata(camera_metadata_t* buffer, ACAMERA_METADATA_TYPE type) :
29 mData(buffer), mType(type) {
Yin-Chia Yehead91462016-01-06 16:45:08 -080030 if (mType == ACM_CHARACTERISTICS) {
31 filterUnsupportedFeatures();
32 }
33 // TODO: filter request/result keys
Yin-Chia Yeh0dea57f2015-12-09 16:46:07 -080034}
35
36bool
37ACameraMetadata::isNdkSupportedCapability(int32_t capability) {
38 switch (capability) {
39 case ANDROID_REQUEST_AVAILABLE_CAPABILITIES_BACKWARD_COMPATIBLE:
40 case ANDROID_REQUEST_AVAILABLE_CAPABILITIES_MANUAL_SENSOR:
41 case ANDROID_REQUEST_AVAILABLE_CAPABILITIES_MANUAL_POST_PROCESSING:
42 case ANDROID_REQUEST_AVAILABLE_CAPABILITIES_RAW:
43 case ANDROID_REQUEST_AVAILABLE_CAPABILITIES_READ_SENSOR_SETTINGS:
44 case ANDROID_REQUEST_AVAILABLE_CAPABILITIES_BURST_CAPTURE:
45 case ANDROID_REQUEST_AVAILABLE_CAPABILITIES_DEPTH_OUTPUT:
46 return true;
47 case ANDROID_REQUEST_AVAILABLE_CAPABILITIES_YUV_REPROCESSING:
48 case ANDROID_REQUEST_AVAILABLE_CAPABILITIES_PRIVATE_REPROCESSING:
49 case ANDROID_REQUEST_AVAILABLE_CAPABILITIES_CONSTRAINED_HIGH_SPEED_VIDEO:
50 return false;
51 default:
52 // Newly defined capabilities will be unsupported by default (blacklist)
53 // TODO: Should we do whitelist or blacklist here?
54 ALOGE("%s: Unknonwn capability %d", __FUNCTION__, capability);
55 return false;
56 }
57}
58
59void
60ACameraMetadata::filterUnsupportedFeatures() {
61 // Hide unsupported capabilities (reprocessing)
62 camera_metadata_entry entry = mData.find(ANDROID_REQUEST_AVAILABLE_CAPABILITIES);
63 if (entry.count == 0 || entry.type != ACAMERA_TYPE_BYTE) {
64 ALOGE("%s: malformed available capability key! count %zu, type %d",
65 __FUNCTION__, entry.count, entry.type);
66 return;
67 }
68
69 Vector<uint8_t> capabilities;
70 capabilities.setCapacity(entry.count);
71 for (size_t i = 0; i < entry.count; i++) {
72 uint8_t capability = entry.data.u8[i];
73 if (isNdkSupportedCapability(capability)) {
74 capabilities.push(capability);
75 }
76 }
77 mData.update(ANDROID_REQUEST_AVAILABLE_CAPABILITIES, capabilities);
78 // TODO: Hide unsupported streams (input/bidirectional streams)
79}
80
81bool
82ACameraMetadata::isVendorTag(const uint32_t tag) {
83 uint32_t tag_section = tag >> 16;
84 if (tag_section >= VENDOR_SECTION) {
85 return true;
86 }
87 return false;
88}
89
90camera_status_t
91ACameraMetadata::getConstEntry(uint32_t tag, ACameraMetadata_const_entry* entry) const {
92 if (entry == nullptr) {
93 return ACAMERA_ERROR_INVALID_PARAMETER;
94 }
95
96 camera_metadata_ro_entry rawEntry = mData.find(tag);
97 if (rawEntry.count == 0) {
98 ALOGE("%s: cannot find metadata tag %d", __FUNCTION__, tag);
99 return ACAMERA_ERROR_METADATA_NOT_FOUND;
100 }
101 entry->tag = tag;
102 entry->type = rawEntry.type;
103 entry->count = rawEntry.count;
104 entry->data.u8 = rawEntry.data.u8;
105 return ACAMERA_OK;
106}
107
108camera_status_t
109ACameraMetadata::update(uint32_t tag, uint32_t count, const uint8_t* data) {
110 return updateImpl<uint8_t>(tag, count, data);
111}
112
113camera_status_t
114ACameraMetadata::update(uint32_t tag, uint32_t count, const int32_t* data) {
115 return updateImpl<int32_t>(tag, count, data);
116}
117
118camera_status_t
119ACameraMetadata::update(uint32_t tag, uint32_t count, const float* data) {
120 return updateImpl<float>(tag, count, data);
121}
122
123camera_status_t
124ACameraMetadata::update(uint32_t tag, uint32_t count, const double* data) {
125 return updateImpl<double>(tag, count, data);
126}
127
128camera_status_t
129ACameraMetadata::update(uint32_t tag, uint32_t count, const int64_t* data) {
130 return updateImpl<int64_t>(tag, count, data);
131}
132
133camera_status_t
134ACameraMetadata::update(uint32_t tag, uint32_t count, const ACameraMetadata_rational* data) {
135 return updateImpl<camera_metadata_rational_t>(tag, count, data);
136}
137
138
139// TODO: some of key below should be hidden from user
140// ex: ACAMERA_REQUEST_ID and ACAMERA_REPROCESS_EFFECTIVE_EXPOSURE_FACTOR
141/*@O~@~@~@~@~@~@~@~@~@~@~@~@~@~@~@~@~@~@~@~@~@~@~@~@~@~@~@~@~@~@~@~@~@~
142 * The key entries below this point are generated from metadata
143 * definitions in /system/media/camera/docs. Do not modify by hand or
144 * modify the comment blocks at the start or end.
145 *~@~@~@~@~@~@~@~@~@~@~@~@~@~@~@~@~@~@~@~@~@~@~@~@~@~@~@~@~@~@~@~@~@~@~*/
146
147bool
148ACameraMetadata::isCaptureRequestTag(const uint32_t tag) {
149 // Skip check for vendor keys
150 if (isVendorTag(tag)) {
151 return true;
152 }
153
154 switch (tag) {
155 case ACAMERA_COLOR_CORRECTION_MODE:
156 case ACAMERA_COLOR_CORRECTION_TRANSFORM:
157 case ACAMERA_COLOR_CORRECTION_GAINS:
158 case ACAMERA_COLOR_CORRECTION_ABERRATION_MODE:
159 case ACAMERA_CONTROL_AE_ANTIBANDING_MODE:
160 case ACAMERA_CONTROL_AE_EXPOSURE_COMPENSATION:
161 case ACAMERA_CONTROL_AE_LOCK:
162 case ACAMERA_CONTROL_AE_MODE:
163 case ACAMERA_CONTROL_AE_REGIONS:
164 case ACAMERA_CONTROL_AE_TARGET_FPS_RANGE:
165 case ACAMERA_CONTROL_AE_PRECAPTURE_TRIGGER:
166 case ACAMERA_CONTROL_AF_MODE:
167 case ACAMERA_CONTROL_AF_REGIONS:
168 case ACAMERA_CONTROL_AF_TRIGGER:
169 case ACAMERA_CONTROL_AWB_LOCK:
170 case ACAMERA_CONTROL_AWB_MODE:
171 case ACAMERA_CONTROL_AWB_REGIONS:
172 case ACAMERA_CONTROL_CAPTURE_INTENT:
173 case ACAMERA_CONTROL_EFFECT_MODE:
174 case ACAMERA_CONTROL_MODE:
175 case ACAMERA_CONTROL_SCENE_MODE:
176 case ACAMERA_CONTROL_VIDEO_STABILIZATION_MODE:
177 case ACAMERA_CONTROL_POST_RAW_SENSITIVITY_BOOST:
178 case ACAMERA_EDGE_MODE:
179 case ACAMERA_FLASH_MODE:
180 case ACAMERA_HOT_PIXEL_MODE:
181 case ACAMERA_JPEG_GPS_COORDINATES:
182 case ACAMERA_JPEG_GPS_PROCESSING_METHOD:
183 case ACAMERA_JPEG_GPS_TIMESTAMP:
184 case ACAMERA_JPEG_ORIENTATION:
185 case ACAMERA_JPEG_QUALITY:
186 case ACAMERA_JPEG_THUMBNAIL_QUALITY:
187 case ACAMERA_JPEG_THUMBNAIL_SIZE:
188 case ACAMERA_LENS_APERTURE:
189 case ACAMERA_LENS_FILTER_DENSITY:
190 case ACAMERA_LENS_FOCAL_LENGTH:
191 case ACAMERA_LENS_FOCUS_DISTANCE:
192 case ACAMERA_LENS_OPTICAL_STABILIZATION_MODE:
193 case ACAMERA_NOISE_REDUCTION_MODE:
194 case ACAMERA_REQUEST_ID:
195 case ACAMERA_SCALER_CROP_REGION:
196 case ACAMERA_SENSOR_EXPOSURE_TIME:
197 case ACAMERA_SENSOR_FRAME_DURATION:
198 case ACAMERA_SENSOR_SENSITIVITY:
199 case ACAMERA_SENSOR_TEST_PATTERN_DATA:
200 case ACAMERA_SENSOR_TEST_PATTERN_MODE:
201 case ACAMERA_SHADING_MODE:
202 case ACAMERA_STATISTICS_FACE_DETECT_MODE:
203 case ACAMERA_STATISTICS_HOT_PIXEL_MAP_MODE:
204 case ACAMERA_STATISTICS_LENS_SHADING_MAP_MODE:
205 case ACAMERA_TONEMAP_CURVE_BLUE:
206 case ACAMERA_TONEMAP_CURVE_GREEN:
207 case ACAMERA_TONEMAP_CURVE_RED:
208 case ACAMERA_TONEMAP_MODE:
209 case ACAMERA_TONEMAP_GAMMA:
210 case ACAMERA_TONEMAP_PRESET_CURVE:
211 case ACAMERA_LED_TRANSMIT:
212 case ACAMERA_BLACK_LEVEL_LOCK:
213 case ACAMERA_REPROCESS_EFFECTIVE_EXPOSURE_FACTOR:
214 return true;
215 default:
216 return false;
217 }
218}
219
220/*~@~@~@~@~@~@~@~@~@~@~@~@~@~@~@~@~@~@~@~@~@~@~@~@~@~@~@~@~@~@~@~@~@~@~@~
221 * End generated code
222 *~@~@~@~@~@~@~@~@~@~@~@~@~@~@~@~@~@~@~@~@~@~@~@~@~@~@~@~@~@~@~@~@~@~O@*/