Camera3: Remove mutex from ZoomRatioMapper
ZoomRatioMapper's member variables are const after construction. As a
result, we don't need mutex to protect updateCaptureRequest and
updateCaptureResult calls.
Also fixed missing zoom ratio mapping initialization for physical
sub-camera.
Test: testZoomRatio CTS
Bug: 130025314
Change-Id: Ibe2ff7cffb13178dcf70fc9e2eb044184e58bcf2
diff --git a/services/camera/libcameraservice/device3/Camera3Device.cpp b/services/camera/libcameraservice/device3/Camera3Device.cpp
index 1c5281d..09b1f02 100644
--- a/services/camera/libcameraservice/device3/Camera3Device.cpp
+++ b/services/camera/libcameraservice/device3/Camera3Device.cpp
@@ -161,14 +161,9 @@
}
}
- res = mZoomRatioMappers[physicalId].initZoomRatioTags(
+ mZoomRatioMappers[physicalId] = ZoomRatioMapper(
&mPhysicalDeviceInfoMap[physicalId],
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 @@
}
}
- res = mZoomRatioMappers[mId.c_str()].initZoomRatioTags(&mDeviceInfo,
+ mZoomRatioMappers[mId.c_str()] = ZoomRatioMapper(&mDeviceInfo,
mSupportNativeZoomRatio, usePrecorrectArray);
- if (res != OK) {
- SET_ERR_L("Failed to initialize zoomRatio tags: %s (%d)",
- strerror(-res), res);
- return res;
- }
return OK;
}
diff --git a/services/camera/libcameraservice/device3/ZoomRatioMapper.cpp b/services/camera/libcameraservice/device3/ZoomRatioMapper.cpp
index 7718819..84da45a 100644
--- a/services/camera/libcameraservice/device3/ZoomRatioMapper.cpp
+++ b/services/camera/libcameraservice/device3/ZoomRatioMapper.cpp
@@ -25,8 +25,6 @@
namespace camera3 {
-ZoomRatioMapper::ZoomRatioMapper() : mHalSupportsZoomRatio(false) {
-}
status_t ZoomRatioMapper::initZoomRatioInTemplate(CameraMetadata *request) {
camera_metadata_entry_t entry;
@@ -117,19 +115,17 @@
return OK;
}
-status_t ZoomRatioMapper::initZoomRatioTags(const CameraMetadata* deviceInfo,
+ZoomRatioMapper::ZoomRatioMapper(const CameraMetadata* deviceInfo,
bool supportNativeZoomRatio, bool usePrecorrectArray) {
- std::lock_guard<std::mutex> lock(mMutex);
-
camera_metadata_ro_entry_t entry;
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 arrayH = entry.data.i32[3];
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 activeH = entry.data.i32[3];
@@ -144,11 +140,12 @@
ALOGV("%s: array size: %d x %d, mHalSupportsZoomRatio %d",
__FUNCTION__, mArrayWidth, mArrayHeight, mHalSupportsZoomRatio);
- return OK;
+ mIsValid = true;
}
status_t ZoomRatioMapper::updateCaptureRequest(CameraMetadata* request) {
- std::lock_guard<std::mutex> lock(mMutex);
+ if (!mIsValid) return INVALID_OPERATION;
+
status_t res = OK;
bool zoomRatioIs1 = true;
camera_metadata_entry_t entry;
@@ -174,7 +171,8 @@
}
status_t ZoomRatioMapper::updateCaptureResult(CameraMetadata* result, bool requestedZoomRatioIs1) {
- std::lock_guard<std::mutex> lock(mMutex);
+ if (!mIsValid) return INVALID_OPERATION;
+
status_t res = OK;
if (mHalSupportsZoomRatio && requestedZoomRatioIs1) {
diff --git a/services/camera/libcameraservice/device3/ZoomRatioMapper.h b/services/camera/libcameraservice/device3/ZoomRatioMapper.h
index 38efbfd..16b223b 100644
--- a/services/camera/libcameraservice/device3/ZoomRatioMapper.h
+++ b/services/camera/libcameraservice/device3/ZoomRatioMapper.h
@@ -19,7 +19,6 @@
#include <utils/Errors.h>
#include <array>
-#include <mutex>
#include "camera/CameraMetadata.h"
#include "device3/CoordinateMapper.h"
@@ -36,7 +35,9 @@
*/
class ZoomRatioMapper : private CoordinateMapper {
public:
- ZoomRatioMapper();
+ ZoomRatioMapper() = default;
+ ZoomRatioMapper(const CameraMetadata *deviceInfo,
+ bool supportNativeZoomRatio, bool usePrecorrectArray);
ZoomRatioMapper(const ZoomRatioMapper& other) :
mHalSupportsZoomRatio(other.mHalSupportsZoomRatio),
mArrayWidth(other.mArrayWidth), mArrayHeight(other.mArrayHeight) {}
@@ -53,16 +54,6 @@
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.
*/
status_t updateCaptureRequest(CameraMetadata *request);
@@ -82,16 +73,16 @@
void scaleCoordinates(int32_t* coordPairs, int coordCount,
float scaleRatio, ClampMode clamp);
+ bool isValid() { return mIsValid; }
private:
+ // const after construction
bool mHalSupportsZoomRatio;
-
// active array / pre-correction array dimension
int32_t mArrayWidth, mArrayHeight;
- mutable std::mutex mMutex;
+ bool mIsValid = false;
float deriveZoomRatio(const CameraMetadata* metadata);
-
void scaleRects(int32_t* rects, int rectCount, float scaleRatio);
status_t separateZoomFromCropLocked(CameraMetadata* metadata, bool isResult);