Skip to content

Commit

Permalink
Merge pull request #496 from feelfreelinux/feat/camera-refactor
Browse files Browse the repository at this point in the history
Octo4a 2.1.0 - Camera service refactor
  • Loading branch information
feelfreelinux authored Jul 14, 2024
2 parents 3b2bcd2 + 87637d4 commit 3e9716a
Show file tree
Hide file tree
Showing 17 changed files with 953 additions and 391 deletions.
4 changes: 2 additions & 2 deletions app/app/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ android {
applicationId = "com.octo4a"
minSdk = 17
targetSdk = 28
versionName = "2.0.0"
versionCode = 2000000
versionName = "2.1.0"
versionCode = 2001000
multiDexEnabled = true

ndk {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import com.octo4a.utils.isServiceRunning

data class CameraSize(val width: Int, val height: Int)

data class CameraDescription(val id: String, val megapixels: Int, val lensFacing: Int, val sizes: List<CameraSize>)
data class CameraDescription(val id: String, val megapixels: Int, val lensFacing: Int, val sizes: List<CameraSize>, val frameRates: List<Int>)

fun CameraSize.readableString(): String {
return "${width}x${height}"
Expand Down Expand Up @@ -67,9 +67,11 @@ class CameraEnumerationRepository(val context: Context) {
val configs = characteristics.get(
CameraCharacteristics.SCALER_STREAM_CONFIGURATION_MAP
)
val fpsRanges = characteristics.get(CameraCharacteristics.CONTROL_AE_AVAILABLE_TARGET_FPS_RANGES)
val frameRates = fpsRanges?.map { it.upper }?.distinct()?.sorted() ?: emptyList()
val sizes = configs?.getOutputSizes(ImageFormat.YUV_420_888)
?.map { size -> CameraSize(size.width, size.height) }
CameraDescription(it, megapixels, facing, sizes ?: emptyList())
CameraDescription(it, megapixels, facing, sizes ?: emptyList(), frameRates)
}.toMutableList()
} else {
val needToRestartService = context.isServiceRunning(LegacyCameraService::class.java)
Expand All @@ -84,7 +86,7 @@ class CameraEnumerationRepository(val context: Context) {
Camera.getCameraInfo(i, cameraInfo)

val cam = Camera.open(i)

val supportedFrameRates = cam.parameters.supportedPreviewFrameRates.sorted()
val pictureSize = cam.parameters.pictureSize
val megaPixels = (pictureSize.width * pictureSize.height) / 1000000
cams.add(CameraDescription(
Expand All @@ -93,7 +95,8 @@ class CameraEnumerationRepository(val context: Context) {
cameraInfo.facing,
cam.parameters.supportedPreviewSizes.map {
CameraSize(it.width, it.height)
}
},
supportedFrameRates
))

cam.release()
Expand Down
Loading

0 comments on commit 3e9716a

Please sign in to comment.