fix: Fix VideoProfile possibly being null (#2231)

* fix: Fix `VideoProfile` possibly being null

* Format
This commit is contained in:
Marc Rousavy 2023-12-04 13:46:21 +03:00 committed by GitHub
parent 9df46670a8
commit c23f49e6bd
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -31,14 +31,18 @@ fun RecordingSession.getRecommendedBitRate(fps: Int, codec: VideoCodec, hdr: Boo
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.S) {
val profiles = CamcorderProfile.getAll(cameraId, quality)
if (profiles != null) {
val best = profiles.videoProfiles.minBy { abs(it.width * it.height - targetResolution.width * targetResolution.height) }
val best = profiles.videoProfiles.filterNotNull().minBy {
abs(it.width * it.height - targetResolution.width * targetResolution.height)
}
recommendedProfile = RecommendedProfile(
best.bitrate,
best.codec,
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU) best.bitDepth else 8,
best.frameRate
)
if (best != null) {
recommendedProfile = RecommendedProfile(
best.bitrate,
best.codec,
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU) best.bitDepth else 8,
best.frameRate
)
}
}
}