blob: 8867e4d0e9573ee3a98cb1a2b95ee30d6fe2ea0f [file] [log] [blame]
Ari Hausman-Cohen10481a32016-08-02 10:41:27 -07001/*
2 * Copyright 2016 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 "metadata.h"
18
19#include <camera/CameraMetadata.h>
20
21#include "../common.h"
22
23namespace v4l2_camera_hal {
24
25Metadata::Metadata() { HAL_LOG_ENTER(); }
26
27Metadata::~Metadata() { HAL_LOG_ENTER(); }
28
29void Metadata::AddComponent(
30 std::unique_ptr<PartialMetadataInterface> component) {
31 HAL_LOG_ENTER();
32
33 components_.push_back(std::move(component));
34}
35
36int Metadata::FillStaticMetadata(camera_metadata_t** metadata) {
37 HAL_LOG_ENTER();
38
39 std::vector<int32_t> static_tags;
40 std::vector<int32_t> control_tags;
41 std::vector<int32_t> dynamic_tags;
42 int res = 0;
43
44 for (auto& component : components_) {
45 // Populate the fields.
46 res = component->PopulateStaticFields(metadata);
47 if (res) {
48 // Exit on error.
49 HAL_LOGE("Failed to get all static properties.");
50 return res;
51 }
52
53 // Note what tags the component adds.
54 const std::vector<int32_t>* tags = &component->StaticTags();
55 static_tags.insert(static_tags.end(), tags->begin(), tags->end());
56 tags = &component->ControlTags();
57 control_tags.insert(control_tags.end(), tags->begin(), tags->end());
58 tags = &component->DynamicTags();
59 dynamic_tags.insert(dynamic_tags.end(), tags->begin(), tags->end());
60 }
61
62 // Populate the meta fields.
63 android::CameraMetadata metadata_wrapper(*metadata);
64 static_tags.push_back(ANDROID_REQUEST_AVAILABLE_REQUEST_KEYS);
65 res = metadata_wrapper.update(ANDROID_REQUEST_AVAILABLE_REQUEST_KEYS,
66 control_tags.data(), control_tags.size());
67 if (res != android::OK) {
68 HAL_LOGE("Failed to add request keys meta key.");
69 return -ENODEV;
70 }
71 static_tags.push_back(ANDROID_REQUEST_AVAILABLE_RESULT_KEYS);
72 res = metadata_wrapper.update(ANDROID_REQUEST_AVAILABLE_RESULT_KEYS,
73 dynamic_tags.data(), dynamic_tags.size());
74 if (res != android::OK) {
75 HAL_LOGE("Failed to add result keys meta key.");
76 return -ENODEV;
77 }
78 static_tags.push_back(ANDROID_REQUEST_AVAILABLE_CHARACTERISTICS_KEYS);
79 res = metadata_wrapper.update(ANDROID_REQUEST_AVAILABLE_CHARACTERISTICS_KEYS,
80 static_tags.data(), static_tags.size());
81 if (res != android::OK) {
82 HAL_LOGE("Failed to add characteristics keys meta key.");
83 return -ENODEV;
84 }
85
86 *metadata = metadata_wrapper.release();
87 return 0;
88}
89
90bool Metadata::IsValidRequest(const camera_metadata_t* metadata) {
91 HAL_LOG_ENTER();
92
93 // Null means "use previous settings", which are inherently valid.
94 if (metadata == nullptr) return true;
95
96 for (auto& component : components_) {
97 // Check that all components support the values requested of them.
98 bool valid_request = component->SupportsRequestValues(metadata);
99 if (!valid_request) {
100 // Exit early if possible.
101 return false;
102 }
103 }
104
105 return true;
106}
107
108int Metadata::SetRequestSettings(const camera_metadata_t* metadata) {
109 HAL_LOG_ENTER();
110
111 // Null means "use previous settings".
112 if (metadata == nullptr) return 0;
113
114 for (auto& component : components_) {
115 int res = component->SetRequestValues(metadata);
116 if (res) {
117 // Exit early if possible.
118 HAL_LOGE("Failed to set all requested settings.");
119 return res;
120 }
121 }
122
123 return 0;
124}
125
126int Metadata::FillResultMetadata(camera_metadata_t** metadata) {
127 for (auto& component : components_) {
128 int res = component->PopulateDynamicFields(metadata);
129 if (res) {
130 // Exit early if possible.
131 HAL_LOGE("Failed to get all dynamic result fields.");
132 return res;
133 }
134 }
135
136 return 0;
137}
138
139} // namespace v4l2_camera_hal