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