use the resolution index instead of the qualities

- store and use the resolution index in Config class for video capture
This commit is contained in:
darthpaul 2022-07-13 01:38:54 +01:00
parent d8ea6d5175
commit 210f3e35c0
4 changed files with 15 additions and 28 deletions

View File

@ -42,7 +42,7 @@ class ChangeResolutionDialogX(
}
private fun setupPhotoResolutionPicker(view: View) {
val items = photoResolutions.mapIndexed { index, resolution->
val items = photoResolutions.mapIndexed { index, resolution ->
val megapixels = resolution.megaPixels
val aspectRatio = resolution.getAspectRatio(activity)
RadioItem(index, "${resolution.width} x ${resolution.height} ($megapixels MP, $aspectRatio)")
@ -74,24 +74,27 @@ class ChangeResolutionDialogX(
RadioItem(index, "${videoQuality.width} x ${videoQuality.height} ($megapixels MP, $aspectRatio)")
}
val videoQuality = if (isFrontCamera) config.frontVideoQuality else config.backVideoQuality
var selectionIndex = videoResolutions.indexOf(videoQuality)
var selectionIndex = if (isFrontCamera) config.frontVideoResIndex else config.backVideoResIndex
selectionIndex = selectionIndex.coerceAtLeast(0)
Log.i(TAG, "videoResolutions=$videoResolutions")
Log.i(TAG, "setupVideoResolutionPicker: selectionIndex=$selectionIndex")
view.change_resolution_video_holder.setOnClickListener {
RadioGroupDialog(activity, ArrayList(items), selectionIndex) {
selectionIndex = it as Int
val selectedItem = items[selectionIndex]
val selectedQuality = videoResolutions[selectionIndex]
view.change_resolution_video.text = selectedItem.title
if (isFrontCamera) {
config.frontVideoQuality = selectedQuality
config.frontVideoResIndex = selectionIndex
} else {
config.backVideoQuality = selectedQuality
config.backPhotoResIndex = selectionIndex
}
dialog.dismiss()
callback.invoke()
}
}
view.change_resolution_video.text = items.getOrNull(selectionIndex)?.title
val selectedItem = items.getOrNull(selectionIndex)
view.change_resolution_video.text = selectedItem?.title
Log.i(TAG, "setupVideoResolutionPicker: selectedItem=$selectedItem")
}
}

View File

@ -3,7 +3,6 @@ package com.simplemobiletools.camera.helpers
import android.content.Context
import android.os.Environment
import androidx.camera.core.CameraSelector
import com.simplemobiletools.camera.models.VideoQuality
import com.simplemobiletools.commons.helpers.BaseConfig
import java.io.File
@ -63,20 +62,6 @@ class Config(context: Context) : BaseConfig(context) {
get() = prefs.getInt(FRONT_PHOTO_RESOLUTION_INDEX, 0)
set(frontPhotoResIndex) = prefs.edit().putInt(FRONT_PHOTO_RESOLUTION_INDEX, frontPhotoResIndex).apply()
var backVideoQuality: VideoQuality
get() {
val backQuality = prefs.getString(BACK_VIDEO_QUALITY, VideoQuality.UHD.name)
return VideoQuality.values().first { it.name == backQuality }
}
set(backVideoQuality) = prefs.edit().putString(BACK_VIDEO_QUALITY, backVideoQuality.name).apply()
var frontVideoQuality: VideoQuality
get() {
val frontQuality = prefs.getString(FRONT_VIDEO_QUALITY, VideoQuality.UHD.name)
return VideoQuality.values().first { it.name == frontQuality }
}
set(frontVideoQuality) = prefs.edit().putString(FRONT_VIDEO_QUALITY, frontVideoQuality.name).apply()
var frontVideoResIndex: Int
get() = prefs.getInt(FRONT_VIDEO_RESOLUTION_INDEX, 0)
set(frontVideoResIndex) = prefs.edit().putInt(FRONT_VIDEO_RESOLUTION_INDEX, frontVideoResIndex).apply()

View File

@ -34,6 +34,7 @@ class VideoQualityManager(private val config: Config) {
.also { allQualities ->
val qualities = allQualities.map { it.toVideoQuality() }
videoQualities.add(CameraSelectorVideoQualities(camSelector, qualities))
}
Log.i(TAG, "bindCameraUseCases: videoQualities=$videoQualities")
}
@ -45,11 +46,9 @@ class VideoQualityManager(private val config: Config) {
}
fun getUserSelectedQuality(cameraSelector: CameraSelector): Quality {
return if (cameraSelector == CameraSelector.DEFAULT_FRONT_CAMERA) {
config.frontVideoQuality.toCameraXQuality()
} else {
config.backVideoQuality.toCameraXQuality()
}
var selectionIndex = if (cameraSelector == CameraSelector.DEFAULT_FRONT_CAMERA) config.frontVideoResIndex else config.backVideoResIndex
selectionIndex = selectionIndex.coerceAtLeast(0)
return getSupportedQualities(cameraSelector)[selectionIndex].toCameraXQuality()
}
fun getSupportedQualities(cameraSelector: CameraSelector): List<VideoQuality> {

View File

@ -223,7 +223,7 @@ class CameraXPreview(
private fun buildVideoCapture(): VideoCapture<Recorder> {
val qualitySelector = QualitySelector.from(
videoQualityManager.getUserSelectedQuality(cameraSelector),
FallbackStrategy.lowerQualityOrHigherThan(Quality.SD),
FallbackStrategy.higherQualityOrLowerThan(Quality.SD),
)
val recorder = Recorder.Builder()
.setQualitySelector(qualitySelector)