Igor Murashkin | e302ee3 | 2012-11-05 11:14:49 -0800 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2012 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 "CameraMetadataTestFunctional" |
Mark Salyzyn | d88dfe8 | 2017-04-11 08:56:09 -0700 | [diff] [blame] | 19 | |
| 20 | #include <stdint.h> |
| 21 | |
| 22 | #include <string> |
| 23 | |
Igor Murashkin | e302ee3 | 2012-11-05 11:14:49 -0800 | [diff] [blame] | 24 | #include "cutils/properties.h" |
Mark Salyzyn | d88dfe8 | 2017-04-11 08:56:09 -0700 | [diff] [blame] | 25 | #include "log/log.h" |
Igor Murashkin | e302ee3 | 2012-11-05 11:14:49 -0800 | [diff] [blame] | 26 | #include "utils/Errors.h" |
| 27 | |
| 28 | #include "gtest/gtest.h" |
| 29 | #include "system/camera_metadata.h" |
| 30 | #include "hardware/hardware.h" |
| 31 | #include "hardware/camera2.h" |
| 32 | |
Eino-Ville Talvala | 48bb03f | 2013-07-25 17:09:14 -0700 | [diff] [blame] | 33 | #include "common/CameraDeviceBase.h" |
Igor Murashkin | e302ee3 | 2012-11-05 11:14:49 -0800 | [diff] [blame] | 34 | #include "utils/StrongPointer.h" |
| 35 | |
| 36 | #include <gui/CpuConsumer.h> |
Mathias Agopian | cc50111 | 2013-02-14 17:34:35 -0800 | [diff] [blame] | 37 | #include <gui/Surface.h> |
Igor Murashkin | e302ee3 | 2012-11-05 11:14:49 -0800 | [diff] [blame] | 38 | |
Igor Murashkin | e302ee3 | 2012-11-05 11:14:49 -0800 | [diff] [blame] | 39 | #include "CameraStreamFixture.h" |
Igor Murashkin | eab33fc | 2012-11-06 17:02:54 -0800 | [diff] [blame] | 40 | #include "TestExtensions.h" |
Igor Murashkin | e302ee3 | 2012-11-05 11:14:49 -0800 | [diff] [blame] | 41 | |
| 42 | namespace android { |
| 43 | namespace camera2 { |
| 44 | namespace tests { |
| 45 | |
| 46 | //FIXME: dont hardcode |
| 47 | static CameraStreamParams METADATA_STREAM_PARAMETERS = { |
Igor Murashkin | e302ee3 | 2012-11-05 11:14:49 -0800 | [diff] [blame] | 48 | /*mFormat*/ HAL_PIXEL_FORMAT_YCrCb_420_SP, |
| 49 | /*mHeapCount*/ 2 |
| 50 | }; |
| 51 | |
Igor Murashkin | eab33fc | 2012-11-06 17:02:54 -0800 | [diff] [blame] | 52 | class CameraMetadataTest |
Igor Murashkin | e302ee3 | 2012-11-05 11:14:49 -0800 | [diff] [blame] | 53 | : public ::testing::Test, |
| 54 | public CameraStreamFixture { |
| 55 | |
| 56 | public: |
Igor Murashkin | eab33fc | 2012-11-06 17:02:54 -0800 | [diff] [blame] | 57 | CameraMetadataTest() |
Igor Murashkin | e302ee3 | 2012-11-05 11:14:49 -0800 | [diff] [blame] | 58 | : CameraStreamFixture(METADATA_STREAM_PARAMETERS) { |
Igor Murashkin | eab33fc | 2012-11-06 17:02:54 -0800 | [diff] [blame] | 59 | TEST_EXTENSION_FORKING_CONSTRUCTOR; |
Igor Murashkin | e302ee3 | 2012-11-05 11:14:49 -0800 | [diff] [blame] | 60 | } |
| 61 | |
Igor Murashkin | eab33fc | 2012-11-06 17:02:54 -0800 | [diff] [blame] | 62 | ~CameraMetadataTest() { |
| 63 | TEST_EXTENSION_FORKING_DESTRUCTOR; |
Igor Murashkin | e302ee3 | 2012-11-05 11:14:49 -0800 | [diff] [blame] | 64 | } |
| 65 | |
| 66 | int GetTypeFromTag(uint32_t tag) const { |
| 67 | return get_camera_metadata_tag_type(tag); |
| 68 | } |
| 69 | |
| 70 | int GetTypeFromStaticTag(uint32_t tag) const { |
| 71 | const CameraMetadata& staticInfo = mDevice->info(); |
| 72 | camera_metadata_ro_entry entry = staticInfo.find(tag); |
| 73 | return entry.type; |
| 74 | } |
| 75 | |
Igor Murashkin | 3d991c8 | 2013-04-18 10:09:16 -0700 | [diff] [blame] | 76 | int GetEntryCountFromStaticTag(uint32_t tag) const { |
| 77 | const CameraMetadata& staticInfo = mDevice->info(); |
| 78 | camera_metadata_ro_entry entry = staticInfo.find(tag); |
| 79 | return entry.count; |
| 80 | } |
| 81 | |
| 82 | bool HasElementInArrayFromStaticTag(uint32_t tag, int32_t element) const { |
| 83 | const CameraMetadata& staticInfo = mDevice->info(); |
| 84 | camera_metadata_ro_entry entry = staticInfo.find(tag); |
| 85 | for (size_t i = 0; i < entry.count; ++i) { |
| 86 | if (entry.data.i32[i] == element) |
| 87 | return true; |
| 88 | } |
| 89 | return false; |
| 90 | } |
| 91 | |
Igor Murashkin | e302ee3 | 2012-11-05 11:14:49 -0800 | [diff] [blame] | 92 | protected: |
| 93 | |
| 94 | }; |
| 95 | |
Igor Murashkin | eab33fc | 2012-11-06 17:02:54 -0800 | [diff] [blame] | 96 | TEST_F(CameraMetadataTest, types) { |
Igor Murashkin | e302ee3 | 2012-11-05 11:14:49 -0800 | [diff] [blame] | 97 | |
Igor Murashkin | eab33fc | 2012-11-06 17:02:54 -0800 | [diff] [blame] | 98 | TEST_EXTENSION_FORKING_INIT; |
Igor Murashkin | e302ee3 | 2012-11-05 11:14:49 -0800 | [diff] [blame] | 99 | |
| 100 | //FIXME: set this up in an external file of some sort (xml?) |
| 101 | { |
| 102 | char value[PROPERTY_VALUE_MAX]; |
| 103 | property_get("ro.build.id", value, ""); |
| 104 | std::string str_value(value); |
| 105 | |
| 106 | if (str_value == "manta") |
| 107 | { |
| 108 | EXPECT_EQ(TYPE_BYTE, |
| 109 | GetTypeFromStaticTag(ANDROID_QUIRKS_TRIGGER_AF_WITH_AUTO)); |
| 110 | EXPECT_EQ(TYPE_BYTE, |
| 111 | GetTypeFromStaticTag(ANDROID_QUIRKS_USE_ZSL_FORMAT)); |
| 112 | EXPECT_EQ(TYPE_BYTE, |
| 113 | GetTypeFromStaticTag(ANDROID_QUIRKS_METERING_CROP_REGION)); |
| 114 | } |
| 115 | } |
| 116 | |
| 117 | /* |
| 118 | TODO: |
| 119 | go through all static metadata and make sure all fields we expect |
| 120 | that are there, ARE there. |
| 121 | |
| 122 | dont worry about the type as its enforced by the metadata api |
| 123 | we can probably check the range validity though |
| 124 | */ |
| 125 | |
| 126 | if (0) { |
| 127 | camera_metadata_ro_entry entry; |
| 128 | EXPECT_EQ(TYPE_BYTE, entry.type); |
| 129 | EXPECT_EQ(TYPE_INT32, entry.type); |
| 130 | EXPECT_EQ(TYPE_FLOAT, entry.type); |
| 131 | EXPECT_EQ(TYPE_INT64, entry.type); |
| 132 | EXPECT_EQ(TYPE_DOUBLE, entry.type); |
| 133 | EXPECT_EQ(TYPE_RATIONAL, entry.type); |
| 134 | } |
| 135 | } |
| 136 | |
Igor Murashkin | 3d991c8 | 2013-04-18 10:09:16 -0700 | [diff] [blame] | 137 | TEST_F(CameraMetadataTest, RequiredFormats) { |
| 138 | TEST_EXTENSION_FORKING_INIT; |
| 139 | |
| 140 | EXPECT_TRUE( |
| 141 | HasElementInArrayFromStaticTag(ANDROID_SCALER_AVAILABLE_FORMATS, |
Igor Murashkin | 3d991c8 | 2013-04-18 10:09:16 -0700 | [diff] [blame] | 142 | HAL_PIXEL_FORMAT_BLOB)); // JPEG |
| 143 | |
Eino-Ville Talvala | 4c543a1 | 2013-06-25 18:12:19 -0700 | [diff] [blame] | 144 | if (getDeviceVersion() < CAMERA_DEVICE_API_VERSION_3_0) { |
| 145 | // HAL2 can support either flexible YUV or YV12 + NV21 |
| 146 | if (!HasElementInArrayFromStaticTag(ANDROID_SCALER_AVAILABLE_FORMATS, |
| 147 | HAL_PIXEL_FORMAT_YCbCr_420_888)) { |
Igor Murashkin | 3d991c8 | 2013-04-18 10:09:16 -0700 | [diff] [blame] | 148 | |
Eino-Ville Talvala | 4c543a1 | 2013-06-25 18:12:19 -0700 | [diff] [blame] | 149 | EXPECT_TRUE( |
| 150 | HasElementInArrayFromStaticTag(ANDROID_SCALER_AVAILABLE_FORMATS, |
| 151 | HAL_PIXEL_FORMAT_YCrCb_420_SP)); // NV21 |
| 152 | |
| 153 | EXPECT_TRUE( |
| 154 | HasElementInArrayFromStaticTag(ANDROID_SCALER_AVAILABLE_FORMATS, |
| 155 | HAL_PIXEL_FORMAT_YV12)); |
| 156 | } |
| 157 | } else { |
| 158 | // HAL3 must support flexible YUV |
| 159 | EXPECT_TRUE(HasElementInArrayFromStaticTag(ANDROID_SCALER_AVAILABLE_FORMATS, |
| 160 | HAL_PIXEL_FORMAT_YCbCr_420_888)); |
| 161 | } |
| 162 | |
Igor Murashkin | 3d991c8 | 2013-04-18 10:09:16 -0700 | [diff] [blame] | 163 | } |
| 164 | |
| 165 | TEST_F(CameraMetadataTest, SaneResolutions) { |
| 166 | TEST_EXTENSION_FORKING_INIT; |
| 167 | |
Yin-Chia Yeh | 8df990b | 2014-10-31 15:10:11 -0700 | [diff] [blame] | 168 | if (getDeviceVersion() < CAMERA_DEVICE_API_VERSION_3_2) { |
| 169 | // Iff there are listed raw resolutions, the format should be available |
| 170 | int rawResolutionsCount = |
| 171 | GetEntryCountFromStaticTag(ANDROID_SCALER_AVAILABLE_RAW_SIZES); |
| 172 | if (rawResolutionsCount > 0) { |
| 173 | EXPECT_TRUE( |
| 174 | HasElementInArrayFromStaticTag(ANDROID_SCALER_AVAILABLE_FORMATS, |
Eino-Ville Talvala | e69efbb | 2015-03-06 13:19:36 -0800 | [diff] [blame] | 175 | HAL_PIXEL_FORMAT_RAW16)); |
Yin-Chia Yeh | 8df990b | 2014-10-31 15:10:11 -0700 | [diff] [blame] | 176 | } |
| 177 | |
| 178 | // Required processed sizes. |
| 179 | int processedSizeCount = |
| 180 | GetEntryCountFromStaticTag(ANDROID_SCALER_AVAILABLE_PROCESSED_SIZES); |
| 181 | EXPECT_NE(0, processedSizeCount); |
| 182 | EXPECT_EQ(0, processedSizeCount % 2); // multiple of 2 (w,h) |
| 183 | |
| 184 | // Required JPEG sizes |
| 185 | int jpegSizeCount = |
| 186 | GetEntryCountFromStaticTag(ANDROID_SCALER_AVAILABLE_JPEG_SIZES); |
| 187 | EXPECT_NE(0, jpegSizeCount); |
| 188 | EXPECT_EQ(0, jpegSizeCount % 2); // multiple of 2 (w,h) |
| 189 | } else { |
| 190 | int strmConfigCount = |
| 191 | GetEntryCountFromStaticTag(ANDROID_SCALER_AVAILABLE_STREAM_CONFIGURATIONS); |
| 192 | EXPECT_NE(0, strmConfigCount); |
| 193 | EXPECT_EQ(0, strmConfigCount % 4); // multiple of 4 (format,w,h,output?) |
Zhijun He | b3ac07c | 2013-09-17 16:51:06 -0700 | [diff] [blame] | 194 | } |
Igor Murashkin | 3d991c8 | 2013-04-18 10:09:16 -0700 | [diff] [blame] | 195 | |
Igor Murashkin | 3d991c8 | 2013-04-18 10:09:16 -0700 | [diff] [blame] | 196 | } |
| 197 | |
Igor Murashkin | e302ee3 | 2012-11-05 11:14:49 -0800 | [diff] [blame] | 198 | } |
| 199 | } |
| 200 | } |