Fix NPE occurring when video dimens are smaller than existing presets
正在显示
1 个修改的文件
包含
7 行增加
和
3 行删除
| @@ -345,9 +345,11 @@ internal constructor( | @@ -345,9 +345,11 @@ internal constructor( | ||
| 345 | private fun determineAppropriateEncoding(width: Int, height: Int): VideoEncoding { | 345 | private fun determineAppropriateEncoding(width: Int, height: Int): VideoEncoding { |
| 346 | val presets = presetsForResolution(width, height) | 346 | val presets = presetsForResolution(width, height) |
| 347 | 347 | ||
| 348 | - return presets | ||
| 349 | - .last { width >= it.capture.width && height >= it.capture.height } | ||
| 350 | - .encoding | 348 | + val preset = presets |
| 349 | + .lastOrNull { width >= it.capture.width && height >= it.capture.height } | ||
| 350 | + ?: presets.first() | ||
| 351 | + | ||
| 352 | + return preset.encoding | ||
| 351 | } | 353 | } |
| 352 | 354 | ||
| 353 | private fun presetsForResolution(width: Int, height: Int): List<VideoPreset> { | 355 | private fun presetsForResolution(width: Int, height: Int): List<VideoPreset> { |
| @@ -444,6 +446,7 @@ internal constructor( | @@ -444,6 +446,7 @@ internal constructor( | ||
| 444 | } | 446 | } |
| 445 | 447 | ||
| 446 | companion object { | 448 | companion object { |
| 449 | + // Note: maintain order from smallest to biggest. | ||
| 447 | private val PRESETS_16_9 = listOf( | 450 | private val PRESETS_16_9 = listOf( |
| 448 | VideoPreset169.QVGA, | 451 | VideoPreset169.QVGA, |
| 449 | VideoPreset169.VGA, | 452 | VideoPreset169.VGA, |
| @@ -452,6 +455,7 @@ internal constructor( | @@ -452,6 +455,7 @@ internal constructor( | ||
| 452 | VideoPreset169.FHD | 455 | VideoPreset169.FHD |
| 453 | ) | 456 | ) |
| 454 | 457 | ||
| 458 | + // Note: maintain order from smallest to biggest. | ||
| 455 | private val PRESETS_4_3 = listOf( | 459 | private val PRESETS_4_3 = listOf( |
| 456 | VideoPreset43.QVGA, | 460 | VideoPreset43.QVGA, |
| 457 | VideoPreset43.VGA, | 461 | VideoPreset43.VGA, |
-
请 注册 或 登录 后发表评论