Skip to content
Closed
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