Skip to content
This repository has been archived by the owner on Nov 8, 2023. It is now read-only.

Commit

Permalink
Camera2/3 HAL test: cleanup deprecated keys
Browse files Browse the repository at this point in the history
Bug:16877860
Change-Id: I1eddec02cefa39692f63cc54cc40b75f449516a7
  • Loading branch information
Yin-Chia Yeh committed Nov 6, 2014
1 parent 357ce00 commit 8df990b
Show file tree
Hide file tree
Showing 6 changed files with 273 additions and 103 deletions.
57 changes: 30 additions & 27 deletions tests/camera2/CameraBurstTests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -311,8 +311,7 @@ TEST_F(CameraBurstTest, ManualExposureControl) {
* $ setenv CAMERA2_TEST_VARIABLE_BURST_DUMP_FRAMES 1
* $ /data/nativetest/camera2_test/camera2_test --gtest_filter="*VariableBurst"
*/
// Disable this test for now, as we need cleanup the usage of the deprecated tag quite a bit.
TEST_F(CameraBurstTest, DISABLED_VariableBurst) {
TEST_F(CameraBurstTest, VariableBurst) {

TEST_EXTENSION_FORKING_INIT;

Expand Down Expand Up @@ -413,34 +412,38 @@ TEST_F(CameraBurstTest, DISABLED_VariableBurst) {
dout << std::endl;

{
camera_metadata_ro_entry availableProcessedSizes =
GetStaticEntry(ANDROID_SCALER_AVAILABLE_PROCESSED_SIZES);

camera_metadata_ro_entry availableProcessedMinFrameDurations =
GetStaticEntry(ANDROID_SCALER_AVAILABLE_PROCESSED_MIN_DURATIONS);

EXPECT_EQ(availableProcessedSizes.count,
availableProcessedMinFrameDurations.count * 2) <<
"The number of minimum frame durations doesn't match the number of "
"available sizes. Using fallback values";

if (availableProcessedSizes.count ==
availableProcessedMinFrameDurations.count * 2) {
bool gotSize = false;
for (size_t i = 0; i < availableProcessedSizes.count; i += 2) {
if (availableProcessedSizes.data.i32[i] == mWidth &&
availableProcessedSizes.data.i32[i+1] == mHeight) {
gotSize = true;
minDuration = availableProcessedMinFrameDurations.data.i64[i/2];
if (getDeviceVersion() < CAMERA_DEVICE_API_VERSION_3_2) {
camera_metadata_ro_entry availableProcessedSizes =
GetStaticEntry(ANDROID_SCALER_AVAILABLE_PROCESSED_SIZES);

camera_metadata_ro_entry availableProcessedMinFrameDurations =
GetStaticEntry(ANDROID_SCALER_AVAILABLE_PROCESSED_MIN_DURATIONS);

EXPECT_EQ(availableProcessedSizes.count,
availableProcessedMinFrameDurations.count * 2) <<
"The number of minimum frame durations doesn't match the number of "
"available sizes. Using fallback values";

if (availableProcessedSizes.count ==
availableProcessedMinFrameDurations.count * 2) {
bool gotSize = false;
for (size_t i = 0; i < availableProcessedSizes.count; i += 2) {
if (availableProcessedSizes.data.i32[i] == mWidth &&
availableProcessedSizes.data.i32[i+1] == mHeight) {
gotSize = true;
minDuration = availableProcessedMinFrameDurations.data.i64[i/2];
}
}
EXPECT_TRUE(gotSize) << "Can't find stream size in list of "
"available sizes: " << mWidth << ", " << mHeight;
}
EXPECT_TRUE(gotSize) << "Can't find stream size in list of "
"available sizes: " << mWidth << ", " << mHeight;
}
if (minDuration == 0) {
minDuration = 1 * SEC / 30; // Fall back to 30 fps as minimum duration
if (minDuration == 0) {
minDuration = 1 * SEC / 30; // Fall back to 30 fps as minimum duration
}
} else {
minDuration = getMinFrameDurationFor(
HAL_PIXEL_FORMAT_IMPLEMENTATION_DEFINED, mWidth, mHeight);
}

ASSERT_LT(0, minDuration);

camera_metadata_ro_entry maxFrameDuration =
Expand Down
45 changes: 26 additions & 19 deletions tests/camera2/CameraMetadataTests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -162,26 +162,33 @@ TEST_F(CameraMetadataTest, RequiredFormats) {
TEST_F(CameraMetadataTest, SaneResolutions) {
TEST_EXTENSION_FORKING_INIT;

// Iff there are listed raw resolutions, the format should be available
int rawResolutionsCount =
GetEntryCountFromStaticTag(ANDROID_SCALER_AVAILABLE_RAW_SIZES);
if (rawResolutionsCount > 0) {
EXPECT_TRUE(
HasElementInArrayFromStaticTag(ANDROID_SCALER_AVAILABLE_FORMATS,
HAL_PIXEL_FORMAT_RAW_SENSOR));
}
if (getDeviceVersion() < CAMERA_DEVICE_API_VERSION_3_2) {
// Iff there are listed raw resolutions, the format should be available
int rawResolutionsCount =
GetEntryCountFromStaticTag(ANDROID_SCALER_AVAILABLE_RAW_SIZES);
if (rawResolutionsCount > 0) {
EXPECT_TRUE(
HasElementInArrayFromStaticTag(ANDROID_SCALER_AVAILABLE_FORMATS,
HAL_PIXEL_FORMAT_RAW_SENSOR));
}

// Required processed sizes.
int processedSizeCount =
GetEntryCountFromStaticTag(ANDROID_SCALER_AVAILABLE_PROCESSED_SIZES);
EXPECT_NE(0, processedSizeCount);
EXPECT_EQ(0, processedSizeCount % 2); // multiple of 2 (w,h)

// Required JPEG sizes
int jpegSizeCount =
GetEntryCountFromStaticTag(ANDROID_SCALER_AVAILABLE_JPEG_SIZES);
EXPECT_NE(0, jpegSizeCount);
EXPECT_EQ(0, jpegSizeCount % 2); // multiple of 2 (w,h)
// Required processed sizes.
int processedSizeCount =
GetEntryCountFromStaticTag(ANDROID_SCALER_AVAILABLE_PROCESSED_SIZES);
EXPECT_NE(0, processedSizeCount);
EXPECT_EQ(0, processedSizeCount % 2); // multiple of 2 (w,h)

// Required JPEG sizes
int jpegSizeCount =
GetEntryCountFromStaticTag(ANDROID_SCALER_AVAILABLE_JPEG_SIZES);
EXPECT_NE(0, jpegSizeCount);
EXPECT_EQ(0, jpegSizeCount % 2); // multiple of 2 (w,h)
} else {
int strmConfigCount =
GetEntryCountFromStaticTag(ANDROID_SCALER_AVAILABLE_STREAM_CONFIGURATIONS);
EXPECT_NE(0, strmConfigCount);
EXPECT_EQ(0, strmConfigCount % 4); // multiple of 4 (format,w,h,output?)
}

}

Expand Down
71 changes: 47 additions & 24 deletions tests/camera2/CameraMultiStreamTests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -472,19 +472,42 @@ TEST_F(CameraMultiStreamTest, DISABLED_MultiBurst) {

TEST_EXTENSION_FORKING_INIT;

camera_metadata_ro_entry availableProcessedSizes =
GetStaticEntry(ANDROID_SCALER_AVAILABLE_PROCESSED_SIZES);
ASSERT_EQ(0u, availableProcessedSizes.count % 2);
ASSERT_GE(availableProcessedSizes.count, 2u);
camera_metadata_ro_entry availableProcessedMinFrameDurations =
GetStaticEntry(ANDROID_SCALER_AVAILABLE_PROCESSED_MIN_DURATIONS);
EXPECT_EQ(availableProcessedSizes.count,
availableProcessedMinFrameDurations.count * 2);

camera_metadata_ro_entry availableJpegSizes =
GetStaticEntry(ANDROID_SCALER_AVAILABLE_JPEG_SIZES);
ASSERT_EQ(0u, availableJpegSizes.count % 2);
ASSERT_GE(availableJpegSizes.count, 2u);
const int32_t* implDefData;
size_t implDefCount;
const int32_t* jpegData;
size_t jpegCount;
if (getDeviceVersion() < CAMERA_DEVICE_API_VERSION_3_2) {
camera_metadata_ro_entry availableProcessedSizes =
GetStaticEntry(ANDROID_SCALER_AVAILABLE_PROCESSED_SIZES);
ASSERT_EQ(0u, availableProcessedSizes.count % 2);
ASSERT_GE(availableProcessedSizes.count, 2u);
camera_metadata_ro_entry availableProcessedMinFrameDurations =
GetStaticEntry(ANDROID_SCALER_AVAILABLE_PROCESSED_MIN_DURATIONS);
EXPECT_EQ(availableProcessedSizes.count,
availableProcessedMinFrameDurations.count * 2);

camera_metadata_ro_entry availableJpegSizes =
GetStaticEntry(ANDROID_SCALER_AVAILABLE_JPEG_SIZES);
ASSERT_EQ(0u, availableJpegSizes.count % 2);
ASSERT_GE(availableJpegSizes.count, 2u);
implDefData = availableProcessedSizes.data.i32;
implDefCount = availableProcessedSizes.count;
jpegData = availableJpegSizes.data.i32;
jpegCount = availableJpegSizes.count;
} else {
const int32_t *implDefResolutions;
size_t implDefResolutionsCount;

getResolutionList(HAL_PIXEL_FORMAT_IMPLEMENTATION_DEFINED, &implDefData, &implDefCount);
ASSERT_NE(0u, implDefCount)
<< "Missing implementation defined sizes";
ASSERT_EQ(0u, implDefCount % 2);
ASSERT_GE(implDefCount, 2u);

getResolutionList(HAL_PIXEL_FORMAT_BLOB, &jpegData, &jpegCount);
ASSERT_EQ(0u, jpegCount % 2);
ASSERT_GE(jpegCount, 2u);
}

camera_metadata_ro_entry hardwareLevel =
GetStaticEntry(ANDROID_INFO_SUPPORTED_HARDWARE_LEVEL);
Expand All @@ -504,23 +527,25 @@ TEST_F(CameraMultiStreamTest, DISABLED_MultiBurst) {
}

// Find the right sizes for preview, metering, and capture streams
// assumes at least 2 entries in availableProcessedSizes.
int64_t minFrameDuration = DEFAULT_FRAME_DURATION;
Size processedMinSize, processedMaxSize, jpegMaxSize;
const int32_t* data = availableProcessedSizes.data.i32;
size_t count = availableProcessedSizes.count;

int32_t minIdx, maxIdx;
GetMinSize(data, count, &processedMinSize, &minIdx);
GetMaxSize(data, count, &processedMaxSize, &maxIdx);
GetMinSize(implDefData, implDefCount, &processedMinSize, &minIdx);
GetMaxSize(implDefData, implDefCount, &processedMaxSize, &maxIdx);
ALOGV("Found processed max size: %dx%d, min size = %dx%d",
processedMaxSize.width, processedMaxSize.height,
processedMinSize.width, processedMinSize.height);

if (availableProcessedSizes.count ==
availableProcessedMinFrameDurations.count * 2) {
if (getDeviceVersion() < CAMERA_DEVICE_API_VERSION_3_2) {
camera_metadata_ro_entry availableProcessedMinFrameDurations =
GetStaticEntry(ANDROID_SCALER_AVAILABLE_PROCESSED_MIN_DURATIONS);
minFrameDuration =
availableProcessedMinFrameDurations.data.i64[maxIdx / 2];
} else {
minFrameDuration = getMinFrameDurationFor(
HAL_PIXEL_FORMAT_IMPLEMENTATION_DEFINED,
processedMaxSize.width, processedMaxSize.height);
}

EXPECT_GT(minFrameDuration, 0);
Expand All @@ -531,9 +556,7 @@ TEST_F(CameraMultiStreamTest, DISABLED_MultiBurst) {

ALOGV("targeted minimal frame duration is: %"PRId64"ns", minFrameDuration);

data = &(availableJpegSizes.data.i32[0]);
count = availableJpegSizes.count;
GetMaxSize(data, count, &jpegMaxSize, &maxIdx);
GetMaxSize(jpegData, jpegCount, &jpegMaxSize, &maxIdx);
ALOGV("Found Jpeg size max idx = %d", maxIdx);

// Max Jpeg size should be available in processed sizes. Use it for
Expand Down Expand Up @@ -627,7 +650,7 @@ TEST_F(CameraMultiStreamTest, DISABLED_MultiBurst) {
// purely by analog gain if possible.
Vector<int32_t> sensitivities;
Vector<int64_t> exposures;
count = (maxAnalogSensitivity - minSensitivity + 99) / 100;
size_t count = (maxAnalogSensitivity - minSensitivity + 99) / 100;
sensitivities.push_back(minSensitivity);
for (size_t i = 1; i < count; i++) {
sensitivities.push_back(minSensitivity + i * 100);
Expand Down
89 changes: 86 additions & 3 deletions tests/camera2/CameraStreamFixture.h
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ class CameraStreamFixture
sp<CameraDeviceBase> device = mDevice;

/* use an arbitrary w,h */
{
if (getDeviceVersion() < CAMERA_DEVICE_API_VERSION_3_2) {
const int tag = ANDROID_SCALER_AVAILABLE_PROCESSED_SIZES;

const CameraMetadata& staticInfo = device->info();
Expand All @@ -106,9 +106,22 @@ class CameraStreamFixture

ASSERT_LE(2u, entry.count);
/* this seems like it would always be the smallest w,h
but we actually make no contract that it's sorted asc */;
but we actually make no contract that it's sorted asc */
mWidth = entry.data.i32[0];
mHeight = entry.data.i32[1];
} else {
buildOutputResolutions();
const int32_t *implDefResolutions;
size_t implDefResolutionsCount;

int format = HAL_PIXEL_FORMAT_IMPLEMENTATION_DEFINED;

getResolutionList(format,
&implDefResolutions, &implDefResolutionsCount);
ASSERT_NE(0u, implDefResolutionsCount)
<< "Missing implementation defined sizes";
mWidth = implDefResolutions[0];
mHeight = implDefResolutions[1];
}
}
void TearDown() {
Expand All @@ -117,12 +130,82 @@ class CameraStreamFixture
// important: shut down HAL before releasing streams
CameraModuleFixture::TearDown();

deleteOutputResolutions();
mNativeWindow.clear();
mCpuConsumer.clear();
mFrameListener.clear();
}

protected:

int64_t getMinFrameDurationFor(int32_t format, int32_t width, int32_t height) {
int64_t minFrameDuration = -1L;
const int tag = ANDROID_SCALER_AVAILABLE_MIN_FRAME_DURATIONS;
sp<CameraDeviceBase> device = mDevice;
const CameraMetadata& staticInfo = device->info();
camera_metadata_ro_entry_t availableMinDurations = staticInfo.find(tag);
for (uint32_t i = 0; i < availableMinDurations.count; i += 4) {
if (format == availableMinDurations.data.i64[i] &&
width == availableMinDurations.data.i64[i + 1] &&
height == availableMinDurations.data.i64[i + 2]) {
minFrameDuration = availableMinDurations.data.i64[i + 3];
break;
}
}
return minFrameDuration;
}

void buildOutputResolutions() {
if (getDeviceVersion() < CAMERA_DEVICE_API_VERSION_3_2) {
return;
}
if (mOutputResolutions.isEmpty()) {
const int tag = ANDROID_SCALER_AVAILABLE_STREAM_CONFIGURATIONS;
const CameraMetadata& staticInfo = mDevice->info();
camera_metadata_ro_entry_t availableStrmConfigs = staticInfo.find(tag);
ASSERT_EQ(0u, availableStrmConfigs.count % 4);
for (uint32_t i = 0; i < availableStrmConfigs.count; i += 4) {
int32_t format = availableStrmConfigs.data.i32[i];
int32_t width = availableStrmConfigs.data.i32[i + 1];
int32_t height = availableStrmConfigs.data.i32[i + 2];
int32_t inOrOut = availableStrmConfigs.data.i32[i + 3];
if (inOrOut == ANDROID_SCALER_AVAILABLE_STREAM_CONFIGURATIONS_OUTPUT) {
int index = mOutputResolutions.indexOfKey(format);
if (index < 0) {
index = mOutputResolutions.add(format, new Vector<int32_t>());
ASSERT_TRUE(index >= 0);
}
Vector<int32_t> *resolutions = mOutputResolutions.editValueAt(index);
resolutions->add(width);
resolutions->add(height);
}
}
}
}

void getResolutionList(int32_t format,
const int32_t **list,
size_t *count) {
status_t res;
ALOGV("Getting resolutions for format %x", format);
if (getDeviceVersion() < CAMERA_DEVICE_API_VERSION_3_2) {
return;
}
int index = mOutputResolutions.indexOfKey(format);
ASSERT_TRUE(index >= 0);
Vector<int32_t>* resolutions = mOutputResolutions.valueAt(index);
*list = resolutions->array();
*count = resolutions->size();
}

void deleteOutputResolutions() {
for (uint32_t i = 0; i < mOutputResolutions.size(); i++) {
Vector<int32_t>* resolutions = mOutputResolutions.editValueAt(i);
delete resolutions;
}
mOutputResolutions.clear();
}

struct FrameListener : public ConsumerBase::FrameAvailableListener {

FrameListener() {
Expand Down Expand Up @@ -280,7 +363,7 @@ class CameraStreamFixture
android::sp<FrameListener> mFrameListener;
android::sp<CpuConsumer> mCpuConsumer;
android::sp<ANativeWindow> mNativeWindow;

KeyedVector<int32_t, Vector<int32_t>* > mOutputResolutions;

private:
CameraStreamParams mParam;
Expand Down
Loading

0 comments on commit 8df990b

Please sign in to comment.