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