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