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

Commit c809976b authored by Austin Borger's avatar Austin Borger
Browse files

CameraService: Update rotate and crop dynamically on fold/unfold.

Currently, rotate and crop is set in response to overrideToPortrait
only when a camera connection is first established. Since on fold/unfold
we may switch to a camera with a different sensor orientation, rotate and
crop needs to be updated dynamically. This sets rotate and crop when
we detect a change in the physical id of a logical multi-camera.

Bug: 265024179
Test: Skype / WhatsApp video meeting checking fold/unfold behavior.
Change-Id: I3c0b86f2a3468b8ba09496b33eafbd746b9d4f65
parent 925abedb
Loading
Loading
Loading
Loading
+23 −0
Original line number Diff line number Diff line
@@ -342,6 +342,29 @@ void Camera2ClientBase<TClientBase>::notifyError(
          resultExtras.requestId);
}

template <typename TClientBase>
void Camera2ClientBase<TClientBase>::notifyPhysicalCameraChange(const std::string &physicalId) {
    // We're only interested in this notification if overrideToPortrait is turned on.
    if (!TClientBase::mOverrideToPortrait) {
        return;
    }

    String8 physicalId8(physicalId.c_str());
    auto physicalCameraMetadata = mDevice->infoPhysical(physicalId8);
    auto orientationEntry = physicalCameraMetadata.find(ANDROID_SENSOR_ORIENTATION);

    if (orientationEntry.count == 1) {
        int orientation = orientationEntry.data.i32[0];
        int rotateAndCropMode = ANDROID_SCALER_ROTATE_AND_CROP_NONE;

        if (orientation == 0 || orientation == 180) {
            rotateAndCropMode = ANDROID_SCALER_ROTATE_AND_CROP_90;
        }

        static_cast<TClientBase *>(this)->setRotateAndCropOverride(rotateAndCropMode);
    }
}

template <typename TClientBase>
status_t Camera2ClientBase<TClientBase>::notifyActive(float maxPreviewFps) {
    if (!mDeviceActive) {
+1 −0
Original line number Diff line number Diff line
@@ -75,6 +75,7 @@ public:

    virtual void          notifyError(int32_t errorCode,
                                      const CaptureResultExtras& resultExtras);
    virtual void          notifyPhysicalCameraChange(const std::string &physicalId) override;
    // Returns errors on app ops permission failures
    virtual status_t      notifyActive(float maxPreviewFps);
    virtual void          notifyIdle(int64_t /*requestCount*/, int64_t /*resultErrorCount*/,
+4 −0
Original line number Diff line number Diff line
@@ -40,6 +40,10 @@ class NotificationListener : public virtual RefBase {
    // Required for API 1 and 2
    virtual void notifyError(int32_t errorCode,
                             const CaptureResultExtras &resultExtras) = 0;

    // Optional for API 1 and 2
    virtual void notifyPhysicalCameraChange(const std::string &/*physicalId*/) {}

    // May return an error since it checks appops
    virtual status_t notifyActive(float maxPreviewFps) = 0;
    virtual void notifyIdle(int64_t requestCount, int64_t resultError, bool deviceError,
+2 −1
Original line number Diff line number Diff line
@@ -96,7 +96,8 @@ Camera3Device::Camera3Device(const String8 &id, bool overrideForPerfClass, bool
        mLastTemplateId(-1),
        mNeedFixupMonochromeTags(false),
        mOverrideForPerfClass(overrideForPerfClass),
        mOverrideToPortrait(overrideToPortrait)
        mOverrideToPortrait(overrideToPortrait),
        mActivePhysicalId("")
{
    ATRACE_CALL();
    ALOGV("%s: Created device for camera %s", __FUNCTION__, mId.string());
+3 −0
Original line number Diff line number Diff line
@@ -1357,6 +1357,9 @@ class Camera3Device :
    // app compatibility reasons.
    bool mOverrideToPortrait;

    // Current active physical id of the logical multi-camera, if any
    std::string mActivePhysicalId;

    // The current minimum expected frame duration based on AE_TARGET_FPS_RANGE
    nsecs_t mMinExpectedDuration = 0;
    // Whether the camera device runs at fixed frame rate based on AE_MODE and
Loading