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

Commit aad70e98 authored by Shuzhen Wang's avatar Shuzhen Wang
Browse files

Camera: Add mirror mode in OutputConfiguration

The mirror mode gives the camera framework the ability to override the
default AUTO mode, where front facing camera's outputs are mirrored.

CTS-Coverage-Bug: 218869676
Test: Camera CTS
Bug: 200309079
Change-Id: I90d5826311c7f9088d13240085506d5b040565eb
parent 5b7523bc
Loading
Loading
Loading
Loading
+6 −0
Original line number Diff line number Diff line
@@ -18195,6 +18195,7 @@ package android.hardware.camera2.params {
    method public void enableSurfaceSharing();
    method public int getDynamicRangeProfile();
    method public int getMaxSharedSurfaceCount();
    method public int getMirrorMode();
    method public int getStreamUseCase();
    method @Nullable public android.view.Surface getSurface();
    method public int getSurfaceGroupId();
@@ -18203,11 +18204,16 @@ package android.hardware.camera2.params {
    method public void removeSensorPixelModeUsed(int);
    method public void removeSurface(@NonNull android.view.Surface);
    method public void setDynamicRangeProfile(int);
    method public void setMirrorMode(int);
    method public void setPhysicalCameraId(@Nullable String);
    method public void setStreamUseCase(int);
    method public void setTimestampBase(int);
    method public void writeToParcel(android.os.Parcel, int);
    field @NonNull public static final android.os.Parcelable.Creator<android.hardware.camera2.params.OutputConfiguration> CREATOR;
    field public static final int MIRROR_MODE_AUTO = 0; // 0x0
    field public static final int MIRROR_MODE_H = 2; // 0x2
    field public static final int MIRROR_MODE_NONE = 1; // 0x1
    field public static final int MIRROR_MODE_V = 3; // 0x3
    field public static final int SURFACE_GROUP_ID_NONE = -1; // 0xffffffff
    field public static final int TIMESTAMP_BASE_CHOREOGRAPHER_SYNCED = 4; // 0x4
    field public static final int TIMESTAMP_BASE_DEFAULT = 0; // 0x0
+87 −3
Original line number Diff line number Diff line
@@ -263,6 +263,44 @@ public final class OutputConfiguration implements Parcelable {
         CameraMetadata.SCALER_AVAILABLE_STREAM_USE_CASES_VIDEO_CALL})
    public @interface StreamUseCase {};

    /**
     * Automatic mirroring based on camera facing
     *
     * <p>This is the default mirroring mode for the camera device. With this mode,
     * the camera output is mirrored horizontally for front-facing cameras. There is
     * no mirroring for rear-facing and external cameras.</p>
     */
    public static final int MIRROR_MODE_AUTO = 0;

    /**
     * No mirror transform is applied
     *
     * <p>No mirroring is applied to the camera output regardless of the camera facing.</p>
     */
    public static final int MIRROR_MODE_NONE = 1;

    /**
     * Camera output is mirrored horizontally
     *
     * <p>The camera output is mirrored horizontally, the same behavior as in AUTO mode for
     * front facing camera.</p>
     */
    public static final int MIRROR_MODE_H = 2;

    /**
     * Camera output is mirrored vertically
     */
    public static final int MIRROR_MODE_V = 3;

    /** @hide */
    @Retention(RetentionPolicy.SOURCE)
    @IntDef(prefix = {"MIRROR_MODE_"}, value =
        {MIRROR_MODE_AUTO,
          MIRROR_MODE_NONE,
          MIRROR_MODE_H,
          MIRROR_MODE_V})
    public @interface MirrorMode {};

    /**
     * Create a new {@link OutputConfiguration} instance with a {@link Surface}.
     *
@@ -461,6 +499,7 @@ public final class OutputConfiguration implements Parcelable {
        mDynamicRangeProfile = DynamicRangeProfiles.STANDARD;
        mStreamUseCase = CameraMetadata.SCALER_AVAILABLE_STREAM_USE_CASES_DEFAULT;
        mTimestampBase = TIMESTAMP_BASE_DEFAULT;
        mMirrorMode = MIRROR_MODE_AUTO;
    }

    /**
@@ -944,6 +983,42 @@ public final class OutputConfiguration implements Parcelable {
        return mTimestampBase;
    }

    /**
     * Set the mirroring mode for this output target
     *
     * <p>If this function is not called, the mirroring mode for this output is
     * {@link #MIRROR_MODE_AUTO}, with which the camera API will mirror the output images
     * horizontally for front facing camera.</p>
     *
     * <p>For efficiency, the mirror effect is applied as a transform flag, so it is only effective
     * in some outputs. It works automatically for SurfaceView and TextureView outputs. For manual
     * use of SurfaceTexture, it is reflected in the value of
     * {@link android.graphics.SurfaceTexture#getTransformMatrix}. For other end points, such as
     * ImageReader, MediaRecorder, or MediaCodec, the mirror mode has no effect. If mirroring is
     * needed for such outputs, the application needs to mirror the image buffers itself before
     * passing them onward.</p>
     */
    public void setMirrorMode(@MirrorMode int mirrorMode) {
        // Verify that the value is in range
        if (mirrorMode < MIRROR_MODE_AUTO ||
                mirrorMode > MIRROR_MODE_V) {
            throw new IllegalArgumentException("Not a valid mirror mode " + mirrorMode);
        }
        mMirrorMode = mirrorMode;
    }

    /**
     * Get the current mirroring mode
     *
     * <p>If no {@link #setMirrorMode} is called first, this function returns
     * {@link #MIRROR_MODE_AUTO}.</p>
     *
     * @return The currently set mirroring mode
     */
    public @MirrorMode int getMirrorMode() {
        return mMirrorMode;
    }

    /**
     * Create a new {@link OutputConfiguration} instance with another {@link OutputConfiguration}
     * instance.
@@ -973,6 +1048,7 @@ public final class OutputConfiguration implements Parcelable {
        this.mDynamicRangeProfile = other.mDynamicRangeProfile;
        this.mStreamUseCase = other.mStreamUseCase;
        this.mTimestampBase = other.mTimestampBase;
        this.mMirrorMode = other.mMirrorMode;
    }

    /**
@@ -998,6 +1074,8 @@ public final class OutputConfiguration implements Parcelable {
        DynamicRangeProfiles.checkProfileValue(dynamicRangeProfile);

        int timestampBase = source.readInt();
        int mirrorMode = source.readInt();

        mSurfaceGroupId = surfaceSetId;
        mRotation = rotation;
        mSurfaces = surfaces;
@@ -1023,6 +1101,7 @@ public final class OutputConfiguration implements Parcelable {
        mDynamicRangeProfile = dynamicRangeProfile;
        mStreamUseCase = streamUseCase;
        mTimestampBase = timestampBase;
        mMirrorMode = mirrorMode;
    }

    /**
@@ -1141,6 +1220,7 @@ public final class OutputConfiguration implements Parcelable {
        dest.writeInt(mDynamicRangeProfile);
        dest.writeInt(mStreamUseCase);
        dest.writeInt(mTimestampBase);
        dest.writeInt(mMirrorMode);
    }

    /**
@@ -1173,7 +1253,8 @@ public final class OutputConfiguration implements Parcelable {
                    !Objects.equals(mPhysicalCameraId, other.mPhysicalCameraId) ||
                    mIsMultiResolution != other.mIsMultiResolution ||
                    mStreamUseCase != other.mStreamUseCase ||
                    mTimestampBase != other.mTimestampBase)
                    mTimestampBase != other.mTimestampBase ||
                    mMirrorMode != other.mMirrorMode)
                return false;
            if (mSensorPixelModesUsed.size() != other.mSensorPixelModesUsed.size()) {
                return false;
@@ -1211,7 +1292,7 @@ public final class OutputConfiguration implements Parcelable {
                    mSurfaceGroupId, mSurfaceType, mIsShared ? 1 : 0,
                    mPhysicalCameraId == null ? 0 : mPhysicalCameraId.hashCode(),
                    mIsMultiResolution ? 1 : 0, mSensorPixelModesUsed.hashCode(),
                    mDynamicRangeProfile, mStreamUseCase, mTimestampBase);
                    mDynamicRangeProfile, mStreamUseCase, mTimestampBase, mMirrorMode);
        }

        return HashCodeHelpers.hashCode(
@@ -1220,7 +1301,8 @@ public final class OutputConfiguration implements Parcelable {
                mConfiguredDataspace, mSurfaceGroupId, mIsShared ? 1 : 0,
                mPhysicalCameraId == null ? 0 : mPhysicalCameraId.hashCode(),
                mIsMultiResolution ? 1 : 0, mSensorPixelModesUsed.hashCode(),
                mDynamicRangeProfile, mStreamUseCase, mTimestampBase);
                mDynamicRangeProfile, mStreamUseCase, mTimestampBase,
                mMirrorMode);
    }

    private static final String TAG = "OutputConfiguration";
@@ -1258,4 +1340,6 @@ public final class OutputConfiguration implements Parcelable {
    private int mStreamUseCase;
    // Timestamp base
    private int mTimestampBase;
    // Mirroring mode
    private int mMirrorMode;
}