blob: 7272b61dd97d9ec5d75ed27049e3aff267bc797a [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"
Ari Hausman-Cohenab3a0a42016-08-02 11:10:56 -070022#include "metadata/fixed_property.h"
Ari Hausman-Cohencd9fef62016-07-15 15:54:13 -070023
24namespace v4l2_camera_hal {
25
26V4L2Metadata::V4L2Metadata(V4L2Wrapper* device) : device_(device) {
27 HAL_LOG_ENTER();
28
Ari Hausman-Cohen10481a32016-08-02 10:41:27 -070029 // TODO(b/30140438): Add all metadata components used by V4L2Camera here.
30 // Currently these are all the fixed properties. Will add the other properties
31 // as more PartialMetadata subclasses get implemented.
Ari Hausman-Cohenab3a0a42016-08-02 11:10:56 -070032
33 // TODO(b/30510395): subcomponents of 3A.
34 AddComponent(std::unique_ptr<PartialMetadataInterface>(
35 new FixedProperty<std::array<int32_t, 3>>(
36 ANDROID_CONTROL_MAX_REGIONS, {{/*AE*/ 0, /*AWB*/ 0, /*AF*/ 0}})));
37
38 // TODO(30510395): subcomponents focus/lens.
39 AddComponent(
40 std::unique_ptr<PartialMetadataInterface>(new FixedProperty<uint8_t>(
41 ANDROID_LENS_INFO_FOCUS_DISTANCE_CALIBRATION,
42 ANDROID_LENS_INFO_FOCUS_DISTANCE_CALIBRATION_UNCALIBRATED)));
43
44 // TODO(30510395): subcomponents of formats/streams.
45 // TODO(b/29939583): V4L2 can only support 1 stream at a time.
46 // For now, just reporting minimum allowable for LIMITED devices.
47 AddComponent(std::unique_ptr<PartialMetadataInterface>(
48 new FixedProperty<std::array<int32_t, 3>>(
49 ANDROID_REQUEST_MAX_NUM_OUTPUT_STREAMS,
50 {{/* Raw */ 0, /* Non-stalling */ 2, /* Stalling */ 1}})));
51 // Reprocessing not supported.
52 AddComponent(std::unique_ptr<PartialMetadataInterface>(
53 new FixedProperty<int32_t>(ANDROID_REQUEST_MAX_NUM_INPUT_STREAMS, 0)));
54 // No way to know pipeline depth for V4L2, so fake with max allowable latency.
55 // Doesn't mean much without per-frame controls anyways.
56 AddComponent(std::unique_ptr<PartialMetadataInterface>(
57 new FixedProperty<uint8_t>(ANDROID_REQUEST_PIPELINE_MAX_DEPTH, 4)));
58 // "LIMITED devices are strongly encouraged to use a non-negative value.
59 // If UNKNOWN is used here then app developers do not have a way to know
60 // when sensor settings have been applied." - Unfortunately, V4L2 doesn't
61 // really help here either. Could even be that adjusting settings mid-stream
62 // blocks in V4L2, and should be avoided.
63 AddComponent(
64 std::unique_ptr<PartialMetadataInterface>(new FixedProperty<int32_t>(
65 ANDROID_SYNC_MAX_LATENCY, ANDROID_SYNC_MAX_LATENCY_UNKNOWN)));
66
67 // TODO(30510395): subcomponents of cropping/sensors.
68 // V4L2 VIDIOC_CROPCAP doesn't give a way to query this;
69 // it's driver dependent. For now, assume freeform, and
70 // some cameras may just behave badly.
71 // TODO(b/29579652): Figure out a way to determine this.
72 AddComponent(std::unique_ptr<PartialMetadataInterface>(
73 new FixedProperty<uint8_t>(ANDROID_SCALER_CROPPING_TYPE,
74 ANDROID_SCALER_CROPPING_TYPE_FREEFORM)));
75 // No way to get in V4L2, so faked. RPi camera v2 is 3.674 x 2.760 mm.
76 // Physical size is used in framework calculations (field of view,
77 // pixel pitch, etc.), so faking it may have unexpected results.
78 AddComponent(std::unique_ptr<PartialMetadataInterface>(
79 new FixedProperty<std::array<float, 2>>(ANDROID_SENSOR_INFO_PHYSICAL_SIZE,
80 {{3.674, 2.760}})));
81 // HAL uses BOOTTIME timestamps.
82 // TODO(b/29457051): make sure timestamps are consistent throughout the HAL.
83 AddComponent(
84 std::unique_ptr<PartialMetadataInterface>(new FixedProperty<uint8_t>(
85 ANDROID_SENSOR_INFO_TIMESTAMP_SOURCE,
86 ANDROID_SENSOR_INFO_TIMESTAMP_SOURCE_UNKNOWN)));
87 // Noo way to actually get orientation from V4L2.
88 AddComponent(std::unique_ptr<PartialMetadataInterface>(
89 new FixedProperty<int32_t>(ANDROID_SENSOR_ORIENTATION, 0)));
90
91 // TODO(30510395): subcomponents of face detection.
92 // Face detection not supported.
93 AddComponent(std::unique_ptr<PartialMetadataInterface>(
94 new FixedProperty<int32_t>(ANDROID_STATISTICS_INFO_MAX_FACE_COUNT, 0)));
95
96 /* Capabilities. */
97 // The V4L2Metadata pretends to at least meet the
98 // "LIMITED" and "BACKWARD_COMPATIBLE" functionality requirements.
99 AddComponent(
100 std::unique_ptr<PartialMetadataInterface>(new FixedProperty<uint8_t>(
101 ANDROID_INFO_SUPPORTED_HARDWARE_LEVEL,
102 ANDROID_INFO_SUPPORTED_HARDWARE_LEVEL_LIMITED)));
103 AddComponent(std::unique_ptr<PartialMetadataInterface>(
104 new FixedProperty<std::vector<uint8_t>>(
105 ANDROID_REQUEST_AVAILABLE_CAPABILITIES,
106 {ANDROID_REQUEST_AVAILABLE_CAPABILITIES_BACKWARD_COMPATIBLE})));
Ari Hausman-Cohencd9fef62016-07-15 15:54:13 -0700107}
108
109V4L2Metadata::~V4L2Metadata() { HAL_LOG_ENTER(); }
110
Ari Hausman-Cohencd9fef62016-07-15 15:54:13 -0700111} // namespace v4l2_camera_hal