Merge "Camera: Use default focal length in template to derive FOV" into pi-dev am: e8924ce00f

am: e7c5039154

Change-Id: I2da5801f3b6846410fc592ddaa03b9be0fb9df2c
gugelfrei
Shuzhen Wang 6 years ago committed by android-build-merger
commit 12281feb06

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

@ -48,17 +48,22 @@ Parameters::Parameters(int cameraId,
Parameters::~Parameters() {
}
status_t Parameters::initialize(const CameraMetadata *info, int deviceVersion) {
status_t Parameters::initialize(CameraDeviceBase *device, int deviceVersion) {
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__);
return BAD_VALUE;
}
Parameters::info = info;
Parameters::info = &info;
mDeviceVersion = deviceVersion;
res = buildFastInfo();
res = buildFastInfo(device);
if (res != OK) return res;
res = buildQuirks();
@ -766,17 +771,7 @@ status_t Parameters::initialize(const CameraMetadata *info, int deviceVersion) {
focusingAreas.clear();
focusingAreas.add(Parameters::Area(0,0,0,0,0));
if (fastInfo.isExternalCamera) {
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);
}
params.setFloat(CameraParameters::KEY_FOCAL_LENGTH, fastInfo.defaultFocalLength);
float horizFov, vertFov;
res = calculatePictureFovs(&horizFov, &vertFov);
@ -998,7 +993,7 @@ String8 Parameters::get() const {
return paramsFlattened;
}
status_t Parameters::buildFastInfo() {
status_t Parameters::buildFastInfo(CameraDeviceBase *device) {
camera_metadata_ro_entry_t activeArraySize =
staticInfo(ANDROID_SENSOR_INFO_ACTIVE_ARRAY_SIZE, 2, 4);
@ -1114,20 +1109,12 @@ status_t Parameters::buildFastInfo() {
focusDistanceCalibration.data.u8[0] !=
ANDROID_LENS_INFO_FOCUS_DISTANCE_CALIBRATION_UNCALIBRATED);
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;
res = getDefaultFocalLength(device);
if (res != OK) return res;
SortedVector<int32_t> availableFormats = getAvailableOutputFormats();
if (!availableFormats.size()) return NO_INIT;
if (sceneModeOverrides.count > 0) {
// 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
@ -1205,19 +1192,6 @@ status_t Parameters::buildFastInfo() {
fastInfo.bestFaceDetectMode = bestFaceDetectMode;
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
fastInfo.useFlexibleYuv = false;
for (size_t i = 0; i < availableFormats.size(); i++) {
@ -2451,6 +2425,50 @@ bool Parameters::useZeroShutterLag() const {
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) {
#define CASE_ENUM_TO_CHAR(x) case x: return(#x); break;
switch(state) {
@ -3246,12 +3264,12 @@ status_t Parameters::calculatePictureFovs(float *horizFov, float *vertFov)
if (horizFov != NULL) {
*horizFov = 180 / M_PI * 2 *
atanf(horizCropFactor * sensorSize.data.f[0] /
(2 * fastInfo.minFocalLength));
(2 * fastInfo.defaultFocalLength));
}
if (vertFov != NULL) {
*vertFov = 180 / M_PI * 2 *
atanf(vertCropFactor * sensorSize.data.f[1] /
(2 * fastInfo.minFocalLength));
(2 * fastInfo.defaultFocalLength));
}
return OK;
}

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

Loading…
Cancel
Save