Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Turn on face priority scene mode by default for front camera #296

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ import android.content.ContentValues
import android.content.Context
import android.content.pm.PackageManager
import android.hardware.camera2.CameraCaptureSession
import android.hardware.camera2.CameraCharacteristics
import android.hardware.camera2.CameraMetadata
import android.hardware.camera2.CaptureRequest
import android.hardware.camera2.CaptureResult
import android.hardware.camera2.TotalCaptureResult
Expand Down Expand Up @@ -429,6 +431,8 @@ private fun createPreviewUseCase(
)
}

setSceneModeIfNeeded(cameraInfo)

setResolutionSelector(
getResolutionSelector(cameraInfo.sensorLandscapeRatio, aspectRatio)
)
Expand All @@ -453,6 +457,24 @@ private fun Preview.Builder.setOpticalStabilizationModeEnabled(enabled: Boolean)
return this
}

@OptIn(ExperimentalCamera2Interop::class)
private fun Preview.Builder.setSceneModeIfNeeded(cameraInfo: CameraInfo): Preview.Builder {
with(Camera2CameraInfo.from(cameraInfo)) {
if (cameraInfo.appLensFacing == LensFacing.FRONT &&
getCameraCharacteristic(CameraCharacteristics.CONTROL_AVAILABLE_SCENE_MODES)?.contains(
CameraMetadata.CONTROL_SCENE_MODE_FACE_PRIORITY
) == true
) {
Camera2Interop.Extender(this@setSceneModeIfNeeded)
.setCaptureRequestOption(
CaptureRequest.CONTROL_SCENE_MODE,
CaptureRequest.CONTROL_SCENE_MODE_FACE_PRIORITY
)
}
}
return this
}

private fun getResolutionSelector(
sensorLandscapeRatio: Float,
aspectRatio: AspectRatio
Expand Down
Loading