blob: 16b2dd9c01d3ebb2cb2a963a099a990ce1c91834 [file] [log] [blame]
Igor Murashkine302ee32012-11-05 11:14:49 -08001/*
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 Salyzynd88dfe82017-04-11 08:56:09 -070019
20#include <stdint.h>
21
22#include <string>
23
Igor Murashkine302ee32012-11-05 11:14:49 -080024#include "cutils/properties.h"
Mark Salyzynd88dfe82017-04-11 08:56:09 -070025#include "log/log.h"
Igor Murashkine302ee32012-11-05 11:14:49 -080026#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 Talvala48bb03f2013-07-25 17:09:14 -070033#include "common/CameraDeviceBase.h"
Igor Murashkine302ee32012-11-05 11:14:49 -080034#include "utils/StrongPointer.h"
35
36#include <gui/CpuConsumer.h>
Mathias Agopiancc501112013-02-14 17:34:35 -080037#include <gui/Surface.h>
Igor Murashkine302ee32012-11-05 11:14:49 -080038
Igor Murashkine302ee32012-11-05 11:14:49 -080039#include "CameraStreamFixture.h"
Igor Murashkineab33fc2012-11-06 17:02:54 -080040#include "TestExtensions.h"
Igor Murashkine302ee32012-11-05 11:14:49 -080041
42namespace android {
43namespace camera2 {
44namespace tests {
45
46//FIXME: dont hardcode
47static CameraStreamParams METADATA_STREAM_PARAMETERS = {
Igor Murashkine302ee32012-11-05 11:14:49 -080048 /*mFormat*/ HAL_PIXEL_FORMAT_YCrCb_420_SP,
49 /*mHeapCount*/ 2
50};
51
Igor Murashkineab33fc2012-11-06 17:02:54 -080052class CameraMetadataTest
Igor Murashkine302ee32012-11-05 11:14:49 -080053 : public ::testing::Test,
54 public CameraStreamFixture {
55
56public:
Igor Murashkineab33fc2012-11-06 17:02:54 -080057 CameraMetadataTest()
Igor Murashkine302ee32012-11-05 11:14:49 -080058 : CameraStreamFixture(METADATA_STREAM_PARAMETERS) {
Igor Murashkineab33fc2012-11-06 17:02:54 -080059 TEST_EXTENSION_FORKING_CONSTRUCTOR;
Igor Murashkine302ee32012-11-05 11:14:49 -080060 }
61
Igor Murashkineab33fc2012-11-06 17:02:54 -080062 ~CameraMetadataTest() {
63 TEST_EXTENSION_FORKING_DESTRUCTOR;
Igor Murashkine302ee32012-11-05 11:14:49 -080064 }
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 Murashkin3d991c82013-04-18 10:09:16 -070076 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 Murashkine302ee32012-11-05 11:14:49 -080092protected:
93
94};
95
Igor Murashkineab33fc2012-11-06 17:02:54 -080096TEST_F(CameraMetadataTest, types) {
Igor Murashkine302ee32012-11-05 11:14:49 -080097
Igor Murashkineab33fc2012-11-06 17:02:54 -080098 TEST_EXTENSION_FORKING_INIT;
Igor Murashkine302ee32012-11-05 11:14:49 -080099
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 Murashkin3d991c82013-04-18 10:09:16 -0700137TEST_F(CameraMetadataTest, RequiredFormats) {
138 TEST_EXTENSION_FORKING_INIT;
139
140 EXPECT_TRUE(
141 HasElementInArrayFromStaticTag(ANDROID_SCALER_AVAILABLE_FORMATS,
Igor Murashkin3d991c82013-04-18 10:09:16 -0700142 HAL_PIXEL_FORMAT_BLOB)); // JPEG
143
Eino-Ville Talvala4c543a12013-06-25 18:12:19 -0700144 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 Murashkin3d991c82013-04-18 10:09:16 -0700148
Eino-Ville Talvala4c543a12013-06-25 18:12:19 -0700149 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 Murashkin3d991c82013-04-18 10:09:16 -0700163}
164
165TEST_F(CameraMetadataTest, SaneResolutions) {
166 TEST_EXTENSION_FORKING_INIT;
167
Yin-Chia Yeh8df990b2014-10-31 15:10:11 -0700168 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 Talvalae69efbb2015-03-06 13:19:36 -0800175 HAL_PIXEL_FORMAT_RAW16));
Yin-Chia Yeh8df990b2014-10-31 15:10:11 -0700176 }
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 Heb3ac07c2013-09-17 16:51:06 -0700194 }
Igor Murashkin3d991c82013-04-18 10:09:16 -0700195
Igor Murashkin3d991c82013-04-18 10:09:16 -0700196}
197
Igor Murashkine302ee32012-11-05 11:14:49 -0800198}
199}
200}