Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 8c75a649 authored by Shuzhen Wang's avatar Shuzhen Wang
Browse files

Camera: Fix coordinate mapping within partial result

Capture result coordinate mapping has the assumption that all relevant
tags are within the same capture result. With partial result, this
assumption is no longer true.

Address the issue by removing the remapped tags from partial result.

This approach shouldn't be causing performance degradation because we
are not touching 3A states, and 3A regions has dependency on crop
region, zoom ratio, and various modes used by the coordinate mappers.

Test: Camera CTS
Bug: 170575182
Change-Id: I022482ebf0f687d9b6138684aeda0f2bbf94046b
parent 22a0c240
Loading
Loading
Loading
Loading
+27 −1
Original line number Diff line number Diff line
@@ -182,8 +182,34 @@ void sendPartialCaptureResult(CaptureOutputStates& states,
        return;
    }

    // Update partial result by removing keys remapped by DistortionCorrection, ZoomRatio,
    // and RotationAndCrop mappers.
    std::set<uint32_t> keysToRemove;

    auto iter = states.distortionMappers.find(states.cameraId.c_str());
    if (iter != states.distortionMappers.end()) {
        const auto& remappedKeys = iter->second.getRemappedKeys();
        keysToRemove.insert(remappedKeys.begin(), remappedKeys.end());
    }

    const auto& remappedKeys = states.zoomRatioMappers[states.cameraId.c_str()].getRemappedKeys();
    keysToRemove.insert(remappedKeys.begin(), remappedKeys.end());

    auto mapper = states.rotateAndCropMappers.find(states.cameraId.c_str());
    if (mapper != states.rotateAndCropMappers.end()) {
        const auto& remappedKeys = iter->second.getRemappedKeys();
        keysToRemove.insert(remappedKeys.begin(), remappedKeys.end());
    }

    for (uint32_t key : keysToRemove) {
        captureResult.mMetadata.erase(key);
    }

    // Send partial result
    if (captureResult.mMetadata.entryCount() > 0) {
        insertResultLocked(states, &captureResult, frameNumber);
    }
}

void sendCaptureResult(
        CaptureOutputStates& states,
+14 −3
Original line number Diff line number Diff line
@@ -18,16 +18,23 @@
#define ANDROID_SERVERS_COORDINATEMAPPER_H

#include <array>
#include <set>

namespace android {

namespace camera3 {

class CoordinateMapper {
    // Right now only stores metadata tags containing 2D coordinates
    // to be corrected.
public:
    // The result metadata tags that are to be re-mapped
    const std::set<uint32_t>& getRemappedKeys() const {
        return mRemappedKeys;
    }

    virtual ~CoordinateMapper() = default;

protected:
    // Metadata key lists to correct
    // Metadata tags containing 2D coordinates to be corrected.

    // Both capture request and result
    static const std::array<uint32_t, 3> kMeteringRegionsToCorrect;
@@ -37,6 +44,10 @@ protected:

    // Only for capture results; don't clamp
    static const std::array<uint32_t, 2> kResultPointsToCorrectNoClamp;

    virtual void initRemappedKeys() = 0;
    std::set<uint32_t> mRemappedKeys;

}; // class CoordinateMapper

} // namespace camera3
+14 −0
Original line number Diff line number Diff line
@@ -29,6 +29,20 @@ namespace camera3 {


DistortionMapper::DistortionMapper() : mValidMapping(false), mValidGrids(false) {
    initRemappedKeys();
}

void DistortionMapper::initRemappedKeys() {
    mRemappedKeys.insert(
            kMeteringRegionsToCorrect.begin(),
            kMeteringRegionsToCorrect.end());
    mRemappedKeys.insert(
            kRectsToCorrect.begin(),
            kRectsToCorrect.end());
    mRemappedKeys.insert(
            kResultPointsToCorrectNoClamp.begin(),
            kResultPointsToCorrectNoClamp.end());
    mRemappedKeys.insert(ANDROID_DISTORTION_CORRECTION_MODE);
}

bool DistortionMapper::isDistortionSupported(const CameraMetadata &deviceInfo) {
+5 −2
Original line number Diff line number Diff line
@@ -32,7 +32,7 @@ namespace camera3 {
 * Utilities to transform between raw (distorted) and warped (corrected) coordinate systems
 * for cameras that support geometric distortion
 */
class DistortionMapper : private CoordinateMapper {
class DistortionMapper : public CoordinateMapper {
  public:
    DistortionMapper();

@@ -43,7 +43,10 @@ class DistortionMapper : private CoordinateMapper {
            mArrayWidth(other.mArrayWidth), mArrayHeight(other.mArrayHeight),
            mActiveWidth(other.mActiveWidth), mActiveHeight(other.mActiveHeight),
            mArrayDiffX(other.mArrayDiffX), mArrayDiffY(other.mArrayDiffY),
            mCorrectedGrid(other.mCorrectedGrid), mDistortedGrid(other.mDistortedGrid) {}
            mCorrectedGrid(other.mCorrectedGrid), mDistortedGrid(other.mDistortedGrid) {
            initRemappedKeys(); }

    void initRemappedKeys() override;

    /**
     * Check whether distortion correction is supported by the camera HAL
+14 −0
Original line number Diff line number Diff line
@@ -27,6 +27,18 @@ namespace android {

namespace camera3 {

void RotateAndCropMapper::initRemappedKeys() {
    mRemappedKeys.insert(
            kMeteringRegionsToCorrect.begin(),
            kMeteringRegionsToCorrect.end());
    mRemappedKeys.insert(
            kResultPointsToCorrectNoClamp.begin(),
            kResultPointsToCorrectNoClamp.end());

    mRemappedKeys.insert(ANDROID_SCALER_ROTATE_AND_CROP);
    mRemappedKeys.insert(ANDROID_SCALER_CROP_REGION);
}

bool RotateAndCropMapper::isNeeded(const CameraMetadata* deviceInfo) {
    auto entry = deviceInfo->find(ANDROID_SCALER_AVAILABLE_ROTATE_AND_CROP_MODES);
    for (size_t i = 0; i < entry.count; i++) {
@@ -36,6 +48,8 @@ bool RotateAndCropMapper::isNeeded(const CameraMetadata* deviceInfo) {
}

RotateAndCropMapper::RotateAndCropMapper(const CameraMetadata* deviceInfo) {
    initRemappedKeys();

    auto entry = deviceInfo->find(ANDROID_SENSOR_INFO_ACTIVE_ARRAY_SIZE);
    if (entry.count != 4) return;

Loading