Merge "Camera3: Remove mutex from ZoomRatioMapper"

gugelfrei
TreeHugger Robot 5 years ago committed by Android (Google) Code Review
commit 7609334508

@ -2112,6 +2112,13 @@ CameraProviderManager::ProviderInfo::DeviceInfo3::DeviceInfo3(const std::string&
CameraProviderManager::statusToString(status), status); CameraProviderManager::statusToString(status), status);
return; return;
} }
res = camera3::ZoomRatioMapper::overrideZoomRatioTags(
&mPhysicalCameraCharacteristics[id], &mSupportNativeZoomRatio);
if (OK != res) {
ALOGE("%s: Unable to override zoomRatio related tags: %s (%d)",
__FUNCTION__, strerror(-res), res);
}
} }
} }

@ -161,14 +161,9 @@ status_t Camera3Device::initialize(sp<CameraProviderManager> manager, const Stri
} }
} }
res = mZoomRatioMappers[physicalId].initZoomRatioTags( mZoomRatioMappers[physicalId] = ZoomRatioMapper(
&mPhysicalDeviceInfoMap[physicalId], &mPhysicalDeviceInfoMap[physicalId],
mSupportNativeZoomRatio, usePrecorrectArray); mSupportNativeZoomRatio, usePrecorrectArray);
if (res != OK) {
SET_ERR_L("Failed to initialize camera %s's zoomRatio tags: %s (%d)",
physicalId.c_str(), strerror(-res), res);
return res;
}
} }
} }
@ -353,13 +348,8 @@ status_t Camera3Device::initializeCommonLocked() {
} }
} }
res = mZoomRatioMappers[mId.c_str()].initZoomRatioTags(&mDeviceInfo, mZoomRatioMappers[mId.c_str()] = ZoomRatioMapper(&mDeviceInfo,
mSupportNativeZoomRatio, usePrecorrectArray); mSupportNativeZoomRatio, usePrecorrectArray);
if (res != OK) {
SET_ERR_L("Failed to initialize zoomRatio tags: %s (%d)",
strerror(-res), res);
return res;
}
return OK; return OK;
} }

@ -25,8 +25,6 @@ namespace android {
namespace camera3 { namespace camera3 {
ZoomRatioMapper::ZoomRatioMapper() : mHalSupportsZoomRatio(false) {
}
status_t ZoomRatioMapper::initZoomRatioInTemplate(CameraMetadata *request) { status_t ZoomRatioMapper::initZoomRatioInTemplate(CameraMetadata *request) {
camera_metadata_entry_t entry; camera_metadata_entry_t entry;
@ -117,19 +115,17 @@ status_t ZoomRatioMapper::overrideZoomRatioTags(
return OK; return OK;
} }
status_t ZoomRatioMapper::initZoomRatioTags(const CameraMetadata* deviceInfo, ZoomRatioMapper::ZoomRatioMapper(const CameraMetadata* deviceInfo,
bool supportNativeZoomRatio, bool usePrecorrectArray) { bool supportNativeZoomRatio, bool usePrecorrectArray) {
std::lock_guard<std::mutex> lock(mMutex);
camera_metadata_ro_entry_t entry; camera_metadata_ro_entry_t entry;
entry = deviceInfo->find(ANDROID_SENSOR_INFO_PRE_CORRECTION_ACTIVE_ARRAY_SIZE); entry = deviceInfo->find(ANDROID_SENSOR_INFO_PRE_CORRECTION_ACTIVE_ARRAY_SIZE);
if (entry.count != 4) return BAD_VALUE; if (entry.count != 4) return;
int32_t arrayW = entry.data.i32[2]; int32_t arrayW = entry.data.i32[2];
int32_t arrayH = entry.data.i32[3]; int32_t arrayH = entry.data.i32[3];
entry = deviceInfo->find(ANDROID_SENSOR_INFO_ACTIVE_ARRAY_SIZE); entry = deviceInfo->find(ANDROID_SENSOR_INFO_ACTIVE_ARRAY_SIZE);
if (entry.count != 4) return BAD_VALUE; if (entry.count != 4) return;
int32_t activeW = entry.data.i32[2]; int32_t activeW = entry.data.i32[2];
int32_t activeH = entry.data.i32[3]; int32_t activeH = entry.data.i32[3];
@ -144,11 +140,12 @@ status_t ZoomRatioMapper::initZoomRatioTags(const CameraMetadata* deviceInfo,
ALOGV("%s: array size: %d x %d, mHalSupportsZoomRatio %d", ALOGV("%s: array size: %d x %d, mHalSupportsZoomRatio %d",
__FUNCTION__, mArrayWidth, mArrayHeight, mHalSupportsZoomRatio); __FUNCTION__, mArrayWidth, mArrayHeight, mHalSupportsZoomRatio);
return OK; mIsValid = true;
} }
status_t ZoomRatioMapper::updateCaptureRequest(CameraMetadata* request) { status_t ZoomRatioMapper::updateCaptureRequest(CameraMetadata* request) {
std::lock_guard<std::mutex> lock(mMutex); if (!mIsValid) return INVALID_OPERATION;
status_t res = OK; status_t res = OK;
bool zoomRatioIs1 = true; bool zoomRatioIs1 = true;
camera_metadata_entry_t entry; camera_metadata_entry_t entry;
@ -174,7 +171,8 @@ status_t ZoomRatioMapper::updateCaptureRequest(CameraMetadata* request) {
} }
status_t ZoomRatioMapper::updateCaptureResult(CameraMetadata* result, bool requestedZoomRatioIs1) { status_t ZoomRatioMapper::updateCaptureResult(CameraMetadata* result, bool requestedZoomRatioIs1) {
std::lock_guard<std::mutex> lock(mMutex); if (!mIsValid) return INVALID_OPERATION;
status_t res = OK; status_t res = OK;
if (mHalSupportsZoomRatio && requestedZoomRatioIs1) { if (mHalSupportsZoomRatio && requestedZoomRatioIs1) {

@ -19,7 +19,6 @@
#include <utils/Errors.h> #include <utils/Errors.h>
#include <array> #include <array>
#include <mutex>
#include "camera/CameraMetadata.h" #include "camera/CameraMetadata.h"
#include "device3/CoordinateMapper.h" #include "device3/CoordinateMapper.h"
@ -36,7 +35,9 @@ namespace camera3 {
*/ */
class ZoomRatioMapper : private CoordinateMapper { class ZoomRatioMapper : private CoordinateMapper {
public: public:
ZoomRatioMapper(); ZoomRatioMapper() = default;
ZoomRatioMapper(const CameraMetadata *deviceInfo,
bool supportNativeZoomRatio, bool usePrecorrectArray);
ZoomRatioMapper(const ZoomRatioMapper& other) : ZoomRatioMapper(const ZoomRatioMapper& other) :
mHalSupportsZoomRatio(other.mHalSupportsZoomRatio), mHalSupportsZoomRatio(other.mHalSupportsZoomRatio),
mArrayWidth(other.mArrayWidth), mArrayHeight(other.mArrayHeight) {} mArrayWidth(other.mArrayWidth), mArrayHeight(other.mArrayHeight) {}
@ -52,16 +53,6 @@ class ZoomRatioMapper : private CoordinateMapper {
static status_t overrideZoomRatioTags( static status_t overrideZoomRatioTags(
CameraMetadata* deviceInfo, bool* supportNativeZoomRatio); CameraMetadata* deviceInfo, bool* supportNativeZoomRatio);
/**
* Initialize zoom ratio mapper with static metadata.
*
* Note:
* This function may modify the static metadata with zoomRatio related
* tags.
*/
status_t initZoomRatioTags(const CameraMetadata *deviceInfo,
bool supportNativeZoomRatio, bool usePrecorrectArray);
/** /**
* Update capture request to handle both cropRegion and zoomRatio. * Update capture request to handle both cropRegion and zoomRatio.
*/ */
@ -82,16 +73,16 @@ class ZoomRatioMapper : private CoordinateMapper {
void scaleCoordinates(int32_t* coordPairs, int coordCount, void scaleCoordinates(int32_t* coordPairs, int coordCount,
float scaleRatio, ClampMode clamp); float scaleRatio, ClampMode clamp);
bool isValid() { return mIsValid; }
private: private:
// const after construction
bool mHalSupportsZoomRatio; bool mHalSupportsZoomRatio;
// active array / pre-correction array dimension // active array / pre-correction array dimension
int32_t mArrayWidth, mArrayHeight; int32_t mArrayWidth, mArrayHeight;
mutable std::mutex mMutex; bool mIsValid = false;
float deriveZoomRatio(const CameraMetadata* metadata); float deriveZoomRatio(const CameraMetadata* metadata);
void scaleRects(int32_t* rects, int rectCount, float scaleRatio); void scaleRects(int32_t* rects, int rectCount, float scaleRatio);
status_t separateZoomFromCropLocked(CameraMetadata* metadata, bool isResult); status_t separateZoomFromCropLocked(CameraMetadata* metadata, bool isResult);

@ -66,7 +66,8 @@ status_t setupTestMapper(ZoomRatioMapper *m, float maxDigitalZoom,
return res; return res;
} }
return m->initZoomRatioTags(&deviceInfo, hasZoomRatioRange, usePreCorrectArray); *m = ZoomRatioMapper(&deviceInfo, hasZoomRatioRange, usePreCorrectArray);
return OK;
} }
TEST(ZoomRatioTest, Initialization) { TEST(ZoomRatioTest, Initialization) {
@ -86,12 +87,12 @@ TEST(ZoomRatioTest, Initialization) {
res = ZoomRatioMapper::overrideZoomRatioTags(&deviceInfo, &supportNativeZoomRatio); res = ZoomRatioMapper::overrideZoomRatioTags(&deviceInfo, &supportNativeZoomRatio);
ASSERT_EQ(res, OK); ASSERT_EQ(res, OK);
ASSERT_EQ(supportNativeZoomRatio, false); ASSERT_EQ(supportNativeZoomRatio, false);
res = mapperNoZoomRange.initZoomRatioTags(&deviceInfo, mapperNoZoomRange = ZoomRatioMapper(&deviceInfo,
supportNativeZoomRatio, true/*usePreCorrectArray*/); supportNativeZoomRatio, true/*usePreCorrectArray*/);
ASSERT_EQ(res, OK); ASSERT_TRUE(mapperNoZoomRange.isValid());
res = mapperNoZoomRange.initZoomRatioTags(&deviceInfo, mapperNoZoomRange = ZoomRatioMapper(&deviceInfo,
supportNativeZoomRatio, false/*usePreCorrectArray*/); supportNativeZoomRatio, false/*usePreCorrectArray*/);
ASSERT_EQ(res, OK); ASSERT_TRUE(mapperNoZoomRange.isValid());
entry = deviceInfo.find(ANDROID_CONTROL_ZOOM_RATIO_RANGE); entry = deviceInfo.find(ANDROID_CONTROL_ZOOM_RATIO_RANGE);
ASSERT_EQ(entry.count, 2U); ASSERT_EQ(entry.count, 2U);
@ -120,12 +121,12 @@ TEST(ZoomRatioTest, Initialization) {
ASSERT_EQ(res, OK); ASSERT_EQ(res, OK);
ASSERT_EQ(supportNativeZoomRatio, true); ASSERT_EQ(supportNativeZoomRatio, true);
ZoomRatioMapper mapperWithZoomRange; ZoomRatioMapper mapperWithZoomRange;
res = mapperWithZoomRange.initZoomRatioTags(&deviceInfo, mapperWithZoomRange = ZoomRatioMapper(&deviceInfo,
supportNativeZoomRatio, true/*usePreCorrectArray*/); supportNativeZoomRatio, true/*usePreCorrectArray*/);
ASSERT_EQ(res, OK); ASSERT_TRUE(mapperWithZoomRange.isValid());
res = mapperWithZoomRange.initZoomRatioTags(&deviceInfo, mapperWithZoomRange = ZoomRatioMapper(&deviceInfo,
supportNativeZoomRatio, false/*usePreCorrectArray*/); supportNativeZoomRatio, false/*usePreCorrectArray*/);
ASSERT_EQ(res, OK); ASSERT_TRUE(mapperWithZoomRange.isValid());
entry = deviceInfo.find(ANDROID_CONTROL_ZOOM_RATIO_RANGE); entry = deviceInfo.find(ANDROID_CONTROL_ZOOM_RATIO_RANGE);
ASSERT_EQ(entry.count, 2U); ASSERT_EQ(entry.count, 2U);

Loading…
Cancel
Save