Camera: Use default focal length in template to derive FOV

This is consistent with the default focal length set by the API1-HAL3
shim.

Test: Camera CTS, FOV test for CtsVerifier
Bug: 110445633
Change-Id: I4ecfb32c7cecdd9c56e04b25cf4d92a86122b2cb
gugelfrei
Shuzhen Wang 6 years ago
parent 53eea85dcb
commit b131f4a7c8

@ -102,7 +102,7 @@ status_t Camera2Client::initializeImpl(TProviderPtr providerPtr, const String8&
{ {
SharedParameters::Lock l(mParameters); SharedParameters::Lock l(mParameters);
res = l.mParameters.initialize(&(mDevice->info()), mDeviceVersion); res = l.mParameters.initialize(mDevice.get(), mDeviceVersion);
if (res != OK) { if (res != OK) {
ALOGE("%s: Camera %d: unable to build defaults: %s (%d)", ALOGE("%s: Camera %d: unable to build defaults: %s (%d)",
__FUNCTION__, mCameraId, strerror(-res), res); __FUNCTION__, mCameraId, strerror(-res), res);

@ -48,17 +48,22 @@ Parameters::Parameters(int cameraId,
Parameters::~Parameters() { Parameters::~Parameters() {
} }
status_t Parameters::initialize(const CameraMetadata *info, int deviceVersion) { status_t Parameters::initialize(CameraDeviceBase *device, int deviceVersion) {
status_t res; status_t res;
if (device == nullptr) {
ALOGE("%s: device is null!", __FUNCTION__);
return BAD_VALUE;
}
if (info->entryCount() == 0) { const CameraMetadata& info = device->info();
if (info.entryCount() == 0) {
ALOGE("%s: No static information provided!", __FUNCTION__); ALOGE("%s: No static information provided!", __FUNCTION__);
return BAD_VALUE; return BAD_VALUE;
} }
Parameters::info = info; Parameters::info = &info;
mDeviceVersion = deviceVersion; mDeviceVersion = deviceVersion;
res = buildFastInfo(); res = buildFastInfo(device);
if (res != OK) return res; if (res != OK) return res;
res = buildQuirks(); res = buildQuirks();
@ -766,17 +771,7 @@ status_t Parameters::initialize(const CameraMetadata *info, int deviceVersion) {
focusingAreas.clear(); focusingAreas.clear();
focusingAreas.add(Parameters::Area(0,0,0,0,0)); focusingAreas.add(Parameters::Area(0,0,0,0,0));
if (fastInfo.isExternalCamera) { params.setFloat(CameraParameters::KEY_FOCAL_LENGTH, fastInfo.defaultFocalLength);
params.setFloat(CameraParameters::KEY_FOCAL_LENGTH, -1.0);
} else {
camera_metadata_ro_entry_t availableFocalLengths =
staticInfo(ANDROID_LENS_INFO_AVAILABLE_FOCAL_LENGTHS, 0, 0, false);
if (!availableFocalLengths.count) return NO_INIT;
float minFocalLength = availableFocalLengths.data.f[0];
params.setFloat(CameraParameters::KEY_FOCAL_LENGTH, minFocalLength);
}
float horizFov, vertFov; float horizFov, vertFov;
res = calculatePictureFovs(&horizFov, &vertFov); res = calculatePictureFovs(&horizFov, &vertFov);
@ -998,7 +993,7 @@ String8 Parameters::get() const {
return paramsFlattened; return paramsFlattened;
} }
status_t Parameters::buildFastInfo() { status_t Parameters::buildFastInfo(CameraDeviceBase *device) {
camera_metadata_ro_entry_t activeArraySize = camera_metadata_ro_entry_t activeArraySize =
staticInfo(ANDROID_SENSOR_INFO_ACTIVE_ARRAY_SIZE, 2, 4); staticInfo(ANDROID_SENSOR_INFO_ACTIVE_ARRAY_SIZE, 2, 4);
@ -1114,20 +1109,12 @@ status_t Parameters::buildFastInfo() {
focusDistanceCalibration.data.u8[0] != focusDistanceCalibration.data.u8[0] !=
ANDROID_LENS_INFO_FOCUS_DISTANCE_CALIBRATION_UNCALIBRATED); ANDROID_LENS_INFO_FOCUS_DISTANCE_CALIBRATION_UNCALIBRATED);
res = getDefaultFocalLength(device);
camera_metadata_ro_entry_t hwLevel = staticInfo(ANDROID_INFO_SUPPORTED_HARDWARE_LEVEL); if (res != OK) return res;
if (!hwLevel.count) return NO_INIT;
fastInfo.isExternalCamera =
hwLevel.data.u8[0] == ANDROID_INFO_SUPPORTED_HARDWARE_LEVEL_EXTERNAL;
camera_metadata_ro_entry_t availableFocalLengths =
staticInfo(ANDROID_LENS_INFO_AVAILABLE_FOCAL_LENGTHS, 0, 0, /*required*/false);
if (!availableFocalLengths.count && !fastInfo.isExternalCamera) return NO_INIT;
SortedVector<int32_t> availableFormats = getAvailableOutputFormats(); SortedVector<int32_t> availableFormats = getAvailableOutputFormats();
if (!availableFormats.size()) return NO_INIT; if (!availableFormats.size()) return NO_INIT;
if (sceneModeOverrides.count > 0) { if (sceneModeOverrides.count > 0) {
// sceneModeOverrides is defined to have 3 entries for each scene mode, // sceneModeOverrides is defined to have 3 entries for each scene mode,
// which are AE, AWB, and AF override modes the HAL wants for that scene // which are AE, AWB, and AF override modes the HAL wants for that scene
@ -1205,19 +1192,6 @@ status_t Parameters::buildFastInfo() {
fastInfo.bestFaceDetectMode = bestFaceDetectMode; fastInfo.bestFaceDetectMode = bestFaceDetectMode;
fastInfo.maxFaces = maxFaces; fastInfo.maxFaces = maxFaces;
// Find smallest (widest-angle) focal length to use as basis of still
// picture FOV reporting.
if (fastInfo.isExternalCamera) {
fastInfo.minFocalLength = -1.0;
} else {
fastInfo.minFocalLength = availableFocalLengths.data.f[0];
for (size_t i = 1; i < availableFocalLengths.count; i++) {
if (fastInfo.minFocalLength > availableFocalLengths.data.f[i]) {
fastInfo.minFocalLength = availableFocalLengths.data.f[i];
}
}
}
// Check if the HAL supports HAL_PIXEL_FORMAT_YCbCr_420_888 // Check if the HAL supports HAL_PIXEL_FORMAT_YCbCr_420_888
fastInfo.useFlexibleYuv = false; fastInfo.useFlexibleYuv = false;
for (size_t i = 0; i < availableFormats.size(); i++) { for (size_t i = 0; i < availableFormats.size(); i++) {
@ -2451,6 +2425,50 @@ bool Parameters::useZeroShutterLag() const {
return true; return true;
} }
status_t Parameters::getDefaultFocalLength(CameraDeviceBase *device) {
if (device == nullptr) {
ALOGE("%s: Camera device is nullptr", __FUNCTION__);
return BAD_VALUE;
}
camera_metadata_ro_entry_t hwLevel = staticInfo(ANDROID_INFO_SUPPORTED_HARDWARE_LEVEL);
if (!hwLevel.count) return NO_INIT;
fastInfo.isExternalCamera =
hwLevel.data.u8[0] == ANDROID_INFO_SUPPORTED_HARDWARE_LEVEL_EXTERNAL;
camera_metadata_ro_entry_t availableFocalLengths =
staticInfo(ANDROID_LENS_INFO_AVAILABLE_FOCAL_LENGTHS, 0, 0, /*required*/false);
if (!availableFocalLengths.count && !fastInfo.isExternalCamera) return NO_INIT;
// Find focal length in PREVIEW template to use as default focal length.
if (fastInfo.isExternalCamera) {
fastInfo.defaultFocalLength = -1.0;
} else {
// Find smallest (widest-angle) focal length to use as basis of still
// picture FOV reporting.
fastInfo.defaultFocalLength = availableFocalLengths.data.f[0];
for (size_t i = 1; i < availableFocalLengths.count; i++) {
if (fastInfo.defaultFocalLength > availableFocalLengths.data.f[i]) {
fastInfo.defaultFocalLength = availableFocalLengths.data.f[i];
}
}
// Use focal length in preview template if it exists
CameraMetadata previewTemplate;
status_t res = device->createDefaultRequest(CAMERA3_TEMPLATE_PREVIEW, &previewTemplate);
if (res != OK) {
ALOGE("%s: Failed to create default PREVIEW request: %s (%d)",
__FUNCTION__, strerror(-res), res);
return res;
}
camera_metadata_entry entry = previewTemplate.find(ANDROID_LENS_FOCAL_LENGTH);
if (entry.count != 0) {
fastInfo.defaultFocalLength = entry.data.f[0];
}
}
return OK;
}
const char* Parameters::getStateName(State state) { const char* Parameters::getStateName(State state) {
#define CASE_ENUM_TO_CHAR(x) case x: return(#x); break; #define CASE_ENUM_TO_CHAR(x) case x: return(#x); break;
switch(state) { switch(state) {
@ -3246,12 +3264,12 @@ status_t Parameters::calculatePictureFovs(float *horizFov, float *vertFov)
if (horizFov != NULL) { if (horizFov != NULL) {
*horizFov = 180 / M_PI * 2 * *horizFov = 180 / M_PI * 2 *
atanf(horizCropFactor * sensorSize.data.f[0] / atanf(horizCropFactor * sensorSize.data.f[0] /
(2 * fastInfo.minFocalLength)); (2 * fastInfo.defaultFocalLength));
} }
if (vertFov != NULL) { if (vertFov != NULL) {
*vertFov = 180 / M_PI * 2 * *vertFov = 180 / M_PI * 2 *
atanf(vertCropFactor * sensorSize.data.f[1] / atanf(vertCropFactor * sensorSize.data.f[1] /
(2 * fastInfo.minFocalLength)); (2 * fastInfo.defaultFocalLength));
} }
return OK; return OK;
} }

@ -30,6 +30,8 @@
#include <camera/CameraParameters2.h> #include <camera/CameraParameters2.h>
#include <camera/CameraMetadata.h> #include <camera/CameraMetadata.h>
#include "common/CameraDeviceBase.h"
namespace android { namespace android {
namespace camera2 { namespace camera2 {
@ -241,7 +243,7 @@ struct Parameters {
}; };
DefaultKeyedVector<uint8_t, OverrideModes> sceneModeOverrides; DefaultKeyedVector<uint8_t, OverrideModes> sceneModeOverrides;
bool isExternalCamera; bool isExternalCamera;
float minFocalLength; float defaultFocalLength;
bool useFlexibleYuv; bool useFlexibleYuv;
Size maxJpegSize; Size maxJpegSize;
Size maxZslSize; Size maxZslSize;
@ -264,10 +266,10 @@ struct Parameters {
~Parameters(); ~Parameters();
// Sets up default parameters // Sets up default parameters
status_t initialize(const CameraMetadata *info, int deviceVersion); status_t initialize(CameraDeviceBase *device, int deviceVersion);
// Build fast-access device static info from static info // Build fast-access device static info from static info
status_t buildFastInfo(); status_t buildFastInfo(CameraDeviceBase *device);
// Query for quirks from static info // Query for quirks from static info
status_t buildQuirks(); status_t buildQuirks();
@ -300,6 +302,9 @@ struct Parameters {
// whether zero shutter lag should be used for non-recording operation // whether zero shutter lag should be used for non-recording operation
bool useZeroShutterLag() const; bool useZeroShutterLag() const;
// Get default focal length
status_t getDefaultFocalLength(CameraDeviceBase *camera);
// Calculate the crop region rectangle, either tightly about the preview // Calculate the crop region rectangle, either tightly about the preview
// resolution, or a region just based on the active array; both take // resolution, or a region just based on the active array; both take
// into account the current zoom level. // into account the current zoom level.

Loading…
Cancel
Save