Ari Hausman-Cohen | cd9fef6 | 2016-07-15 15:54:13 -0700 | [diff] [blame] | 1 | /* |
| 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-Cohen | ab3a0a4 | 2016-08-02 11:10:56 -0700 | [diff] [blame] | 22 | #include "metadata/fixed_property.h" |
Ari Hausman-Cohen | 183ffc3 | 2016-08-02 12:35:36 -0700 | [diff] [blame] | 23 | #include "metadata/ignored_control.h" |
Ari Hausman-Cohen | cd9fef6 | 2016-07-15 15:54:13 -0700 | [diff] [blame] | 24 | |
| 25 | namespace v4l2_camera_hal { |
| 26 | |
| 27 | V4L2Metadata::V4L2Metadata(V4L2Wrapper* device) : device_(device) { |
| 28 | HAL_LOG_ENTER(); |
| 29 | |
Ari Hausman-Cohen | 10481a3 | 2016-08-02 10:41:27 -0700 | [diff] [blame] | 30 | // TODO(b/30140438): Add all metadata components used by V4L2Camera here. |
| 31 | // Currently these are all the fixed properties. Will add the other properties |
| 32 | // as more PartialMetadata subclasses get implemented. |
Ari Hausman-Cohen | ab3a0a4 | 2016-08-02 11:10:56 -0700 | [diff] [blame] | 33 | |
Ari Hausman-Cohen | 183ffc3 | 2016-08-02 12:35:36 -0700 | [diff] [blame] | 34 | AddComponent( |
| 35 | std::unique_ptr<PartialMetadataInterface>(new IgnoredControl<uint8_t>( |
| 36 | ANDROID_COLOR_CORRECTION_ABERRATION_MODE, |
| 37 | ANDROID_COLOR_CORRECTION_AVAILABLE_ABERRATION_MODES, |
| 38 | {ANDROID_COLOR_CORRECTION_ABERRATION_MODE_FAST, |
| 39 | ANDROID_COLOR_CORRECTION_ABERRATION_MODE_HIGH_QUALITY}, |
| 40 | ANDROID_COLOR_CORRECTION_ABERRATION_MODE_FAST))); |
| 41 | |
Ari Hausman-Cohen | ab3a0a4 | 2016-08-02 11:10:56 -0700 | [diff] [blame] | 42 | // TODO(b/30510395): subcomponents of 3A. |
| 43 | AddComponent(std::unique_ptr<PartialMetadataInterface>( |
| 44 | new FixedProperty<std::array<int32_t, 3>>( |
| 45 | ANDROID_CONTROL_MAX_REGIONS, {{/*AE*/ 0, /*AWB*/ 0, /*AF*/ 0}}))); |
| 46 | |
Ari Hausman-Cohen | 183ffc3 | 2016-08-02 12:35:36 -0700 | [diff] [blame] | 47 | // Not sure if V4L2 does or doesn't do this, but HAL documentation says |
| 48 | // all devices must support FAST, and FAST can be equivalent to OFF, so |
| 49 | // either way it's fine to list. |
| 50 | AddComponent( |
| 51 | std::unique_ptr<PartialMetadataInterface>(new IgnoredControl<uint8_t>( |
| 52 | ANDROID_EDGE_MODE, ANDROID_EDGE_AVAILABLE_EDGE_MODES, |
| 53 | {ANDROID_EDGE_MODE_FAST}, ANDROID_EDGE_MODE_FAST))); |
| 54 | |
| 55 | // TODO(30510395): subcomponents of hotpixel. |
| 56 | // No known V4L2 hot pixel correction. But it might be happening, |
| 57 | // so we report FAST/HIGH_QUALITY. |
| 58 | AddComponent( |
| 59 | std::unique_ptr<PartialMetadataInterface>(new IgnoredControl<uint8_t>( |
| 60 | ANDROID_HOT_PIXEL_MODE, ANDROID_HOT_PIXEL_AVAILABLE_HOT_PIXEL_MODES, |
| 61 | {ANDROID_HOT_PIXEL_MODE_FAST, ANDROID_HOT_PIXEL_MODE_HIGH_QUALITY}, |
| 62 | ANDROID_HOT_PIXEL_MODE_FAST))); |
| 63 | // ON only needs to be supported for RAW capable devices. |
| 64 | AddComponent( |
| 65 | std::unique_ptr<PartialMetadataInterface>(new IgnoredControl<uint8_t>( |
| 66 | ANDROID_STATISTICS_HOT_PIXEL_MAP_MODE, |
| 67 | ANDROID_STATISTICS_INFO_AVAILABLE_HOT_PIXEL_MAP_MODES, |
| 68 | {ANDROID_STATISTICS_HOT_PIXEL_MAP_MODE_OFF}, |
| 69 | ANDROID_STATISTICS_HOT_PIXEL_MAP_MODE_OFF))); |
| 70 | |
Ari Hausman-Cohen | ab3a0a4 | 2016-08-02 11:10:56 -0700 | [diff] [blame] | 71 | // TODO(30510395): subcomponents focus/lens. |
Ari Hausman-Cohen | 183ffc3 | 2016-08-02 12:35:36 -0700 | [diff] [blame] | 72 | // No way to actually get the aperture and focal length |
| 73 | // in V4L2, but they're required keys, so fake them. |
| 74 | AddComponent( |
| 75 | std::unique_ptr<PartialMetadataInterface>(new IgnoredControl<float>( |
| 76 | ANDROID_LENS_APERTURE, ANDROID_LENS_INFO_AVAILABLE_APERTURES, {2.0}, |
| 77 | 2.0))); // RPi camera v2 is f/2.0. |
| 78 | AddComponent( |
| 79 | std::unique_ptr<PartialMetadataInterface>(new IgnoredControl<float>( |
| 80 | ANDROID_LENS_FOCAL_LENGTH, ANDROID_LENS_INFO_AVAILABLE_FOCAL_LENGTHS, |
| 81 | {3.04}, 3.04))); // RPi camera v2 is 3.04mm. |
| 82 | // No known way to get filter densities from V4L2, |
| 83 | // report 0 to indicate this control is not supported. |
| 84 | AddComponent( |
| 85 | std::unique_ptr<PartialMetadataInterface>(new IgnoredControl<float>( |
| 86 | ANDROID_LENS_FILTER_DENSITY, |
| 87 | ANDROID_LENS_INFO_AVAILABLE_FILTER_DENSITIES, {0.0}, 0.0))); |
| 88 | // V4L2 focal units do not correspond to a particular physical unit. |
Ari Hausman-Cohen | ab3a0a4 | 2016-08-02 11:10:56 -0700 | [diff] [blame] | 89 | AddComponent( |
| 90 | std::unique_ptr<PartialMetadataInterface>(new FixedProperty<uint8_t>( |
| 91 | ANDROID_LENS_INFO_FOCUS_DISTANCE_CALIBRATION, |
| 92 | ANDROID_LENS_INFO_FOCUS_DISTANCE_CALIBRATION_UNCALIBRATED))); |
Ari Hausman-Cohen | 183ffc3 | 2016-08-02 12:35:36 -0700 | [diff] [blame] | 93 | // info.hyperfocalDistance not required for UNCALIBRATED. |
| 94 | // No known V4L2 lens shading. But it might be happening, |
| 95 | // so report FAST/HIGH_QUALITY. |
| 96 | AddComponent( |
| 97 | std::unique_ptr<PartialMetadataInterface>(new IgnoredControl<uint8_t>( |
| 98 | ANDROID_SHADING_MODE, ANDROID_SHADING_AVAILABLE_MODES, |
| 99 | {ANDROID_SHADING_MODE_FAST, ANDROID_SHADING_MODE_HIGH_QUALITY}, |
| 100 | ANDROID_SHADING_MODE_FAST))); |
| 101 | // ON only needs to be supported for RAW capable devices. |
| 102 | AddComponent( |
| 103 | std::unique_ptr<PartialMetadataInterface>(new IgnoredControl<uint8_t>( |
| 104 | ANDROID_STATISTICS_LENS_SHADING_MAP_MODE, |
| 105 | ANDROID_STATISTICS_INFO_AVAILABLE_LENS_SHADING_MAP_MODES, |
| 106 | {ANDROID_STATISTICS_LENS_SHADING_MAP_MODE_OFF}, |
| 107 | ANDROID_STATISTICS_LENS_SHADING_MAP_MODE_OFF))); |
| 108 | |
| 109 | // Unable to control noise reduction in V4L2 devices, |
| 110 | // but FAST is allowed to be the same as OFF. |
| 111 | AddComponent( |
| 112 | std::unique_ptr<PartialMetadataInterface>(new IgnoredControl<uint8_t>( |
| 113 | ANDROID_NOISE_REDUCTION_MODE, |
| 114 | ANDROID_NOISE_REDUCTION_AVAILABLE_NOISE_REDUCTION_MODES, |
| 115 | {ANDROID_NOISE_REDUCTION_MODE_FAST}, |
| 116 | ANDROID_NOISE_REDUCTION_MODE_FAST))); |
Ari Hausman-Cohen | ab3a0a4 | 2016-08-02 11:10:56 -0700 | [diff] [blame] | 117 | |
| 118 | // TODO(30510395): subcomponents of formats/streams. |
Ari Hausman-Cohen | 183ffc3 | 2016-08-02 12:35:36 -0700 | [diff] [blame] | 119 | // For now, no thumbnails available (only [0,0], the "no thumbnail" size). |
| 120 | // TODO(b/29580107): Could end up with a mismatch between request & result, |
| 121 | // since V4L2 doesn't actually allow for thumbnail size control. |
| 122 | AddComponent(std::unique_ptr<PartialMetadataInterface>( |
| 123 | new IgnoredControl<std::array<int32_t, 2>>( |
| 124 | ANDROID_JPEG_THUMBNAIL_SIZE, ANDROID_JPEG_AVAILABLE_THUMBNAIL_SIZES, |
| 125 | {{{0, 0}}}, {{0, 0}}))); |
Ari Hausman-Cohen | ab3a0a4 | 2016-08-02 11:10:56 -0700 | [diff] [blame] | 126 | // TODO(b/29939583): V4L2 can only support 1 stream at a time. |
| 127 | // For now, just reporting minimum allowable for LIMITED devices. |
| 128 | AddComponent(std::unique_ptr<PartialMetadataInterface>( |
| 129 | new FixedProperty<std::array<int32_t, 3>>( |
| 130 | ANDROID_REQUEST_MAX_NUM_OUTPUT_STREAMS, |
| 131 | {{/* Raw */ 0, /* Non-stalling */ 2, /* Stalling */ 1}}))); |
| 132 | // Reprocessing not supported. |
| 133 | AddComponent(std::unique_ptr<PartialMetadataInterface>( |
| 134 | new FixedProperty<int32_t>(ANDROID_REQUEST_MAX_NUM_INPUT_STREAMS, 0))); |
| 135 | // No way to know pipeline depth for V4L2, so fake with max allowable latency. |
| 136 | // Doesn't mean much without per-frame controls anyways. |
| 137 | AddComponent(std::unique_ptr<PartialMetadataInterface>( |
| 138 | new FixedProperty<uint8_t>(ANDROID_REQUEST_PIPELINE_MAX_DEPTH, 4))); |
| 139 | // "LIMITED devices are strongly encouraged to use a non-negative value. |
| 140 | // If UNKNOWN is used here then app developers do not have a way to know |
| 141 | // when sensor settings have been applied." - Unfortunately, V4L2 doesn't |
| 142 | // really help here either. Could even be that adjusting settings mid-stream |
| 143 | // blocks in V4L2, and should be avoided. |
| 144 | AddComponent( |
| 145 | std::unique_ptr<PartialMetadataInterface>(new FixedProperty<int32_t>( |
| 146 | ANDROID_SYNC_MAX_LATENCY, ANDROID_SYNC_MAX_LATENCY_UNKNOWN))); |
| 147 | |
| 148 | // TODO(30510395): subcomponents of cropping/sensors. |
| 149 | // V4L2 VIDIOC_CROPCAP doesn't give a way to query this; |
| 150 | // it's driver dependent. For now, assume freeform, and |
| 151 | // some cameras may just behave badly. |
| 152 | // TODO(b/29579652): Figure out a way to determine this. |
| 153 | AddComponent(std::unique_ptr<PartialMetadataInterface>( |
| 154 | new FixedProperty<uint8_t>(ANDROID_SCALER_CROPPING_TYPE, |
| 155 | ANDROID_SCALER_CROPPING_TYPE_FREEFORM))); |
| 156 | // No way to get in V4L2, so faked. RPi camera v2 is 3.674 x 2.760 mm. |
| 157 | // Physical size is used in framework calculations (field of view, |
| 158 | // pixel pitch, etc.), so faking it may have unexpected results. |
| 159 | AddComponent(std::unique_ptr<PartialMetadataInterface>( |
| 160 | new FixedProperty<std::array<float, 2>>(ANDROID_SENSOR_INFO_PHYSICAL_SIZE, |
| 161 | {{3.674, 2.760}}))); |
| 162 | // HAL uses BOOTTIME timestamps. |
| 163 | // TODO(b/29457051): make sure timestamps are consistent throughout the HAL. |
| 164 | AddComponent( |
| 165 | std::unique_ptr<PartialMetadataInterface>(new FixedProperty<uint8_t>( |
| 166 | ANDROID_SENSOR_INFO_TIMESTAMP_SOURCE, |
| 167 | ANDROID_SENSOR_INFO_TIMESTAMP_SOURCE_UNKNOWN))); |
| 168 | // Noo way to actually get orientation from V4L2. |
| 169 | AddComponent(std::unique_ptr<PartialMetadataInterface>( |
| 170 | new FixedProperty<int32_t>(ANDROID_SENSOR_ORIENTATION, 0))); |
| 171 | |
| 172 | // TODO(30510395): subcomponents of face detection. |
| 173 | // Face detection not supported. |
Ari Hausman-Cohen | 183ffc3 | 2016-08-02 12:35:36 -0700 | [diff] [blame] | 174 | AddComponent( |
| 175 | std::unique_ptr<PartialMetadataInterface>(new IgnoredControl<uint8_t>( |
| 176 | ANDROID_STATISTICS_FACE_DETECT_MODE, |
| 177 | ANDROID_STATISTICS_INFO_AVAILABLE_FACE_DETECT_MODES, |
| 178 | {ANDROID_STATISTICS_FACE_DETECT_MODE_OFF}, |
| 179 | ANDROID_STATISTICS_FACE_DETECT_MODE_OFF))); |
Ari Hausman-Cohen | ab3a0a4 | 2016-08-02 11:10:56 -0700 | [diff] [blame] | 180 | AddComponent(std::unique_ptr<PartialMetadataInterface>( |
| 181 | new FixedProperty<int32_t>(ANDROID_STATISTICS_INFO_MAX_FACE_COUNT, 0))); |
| 182 | |
| 183 | /* Capabilities. */ |
| 184 | // The V4L2Metadata pretends to at least meet the |
| 185 | // "LIMITED" and "BACKWARD_COMPATIBLE" functionality requirements. |
| 186 | AddComponent( |
| 187 | std::unique_ptr<PartialMetadataInterface>(new FixedProperty<uint8_t>( |
| 188 | ANDROID_INFO_SUPPORTED_HARDWARE_LEVEL, |
| 189 | ANDROID_INFO_SUPPORTED_HARDWARE_LEVEL_LIMITED))); |
| 190 | AddComponent(std::unique_ptr<PartialMetadataInterface>( |
| 191 | new FixedProperty<std::vector<uint8_t>>( |
| 192 | ANDROID_REQUEST_AVAILABLE_CAPABILITIES, |
| 193 | {ANDROID_REQUEST_AVAILABLE_CAPABILITIES_BACKWARD_COMPATIBLE}))); |
Ari Hausman-Cohen | cd9fef6 | 2016-07-15 15:54:13 -0700 | [diff] [blame] | 194 | } |
| 195 | |
| 196 | V4L2Metadata::~V4L2Metadata() { HAL_LOG_ENTER(); } |
| 197 | |
Ari Hausman-Cohen | cd9fef6 | 2016-07-15 15:54:13 -0700 | [diff] [blame] | 198 | } // namespace v4l2_camera_hal |