Modern Apps git

← Modern-Apps.git

youpipe: dedupe video feeds to one per resolution

Commit
c008e32d63856491a8de1b74224ff63ef25b8972
Author
vayun-mathur <[email protected]>
When
2026-08-21 15:49 UTC (3 months ago)
Parents
4d64a79

Diff

youpipe/src/main/java/com/vayunmathur/youpipe/util/YouPipeViewModel.kt
diff --git a/youpipe/src/main/java/com/vayunmathur/youpipe/util/YouPipeViewModel.kt b/youpipe/src/main/java/com/vayunmathur/youpipe/util/YouPipeViewModel.ktindex e67b60e033..cb1c976958 100644--- a/youpipe/src/main/java/com/vayunmathur/youpipe/util/YouPipeViewModel.kt+++ b/youpipe/src/main/java/com/vayunmathur/youpipe/util/YouPipeViewModel.kt@@ -786,32 +786,16 @@ class YouPipeViewModel(                         }                          if (progVideoOnly.isNotEmpty() || sabrVideoOnly.isNotEmpty()) {-                            // Combine progressive + SABR video-only. For same resolution+fps,-                            // if vp9 and avc both exist, keep only vp9 (user request). This preserves-                            // 60fps streams even when only avc has 60fps and vp9 has 30fps.-                            // AV1 is kept as distinct codec. Do NOT filter >1080p.-                            val combinedVideo = (+                            // Combine progressive + SABR video-only, then keep exactly one stream+                            // per resolution: highest fps wins, then best codec (av1 > vp9 > avc).+                            // Do NOT filter >1080p.+                            videoStreams = (                                 progVideoOnly.map { it.toDomain() } +                                     sabrVideoOnly.map { it.toSabrDomain(videoId) }                                 )-                                .groupBy { it.height to it.fps }-                                .flatMap { (_, streamsAtResFps) ->-                                    val hasVp9 = streamsAtResFps.any { it.codec == "vp9" }-                                    val hasAvc = streamsAtResFps.any { it.codec == "avc" }-                                    if (hasVp9 && hasAvc) {-                                        streamsAtResFps.filter { it.codec != "avc" }-                                    } else {-                                        streamsAtResFps-                                    }-                                }-                                // Keep different codec at same height/fps as distinct (e.g. av1 vs vp9 at 1080p60)-                                .distinctBy { Triple(it.codec, it.height, it.fps) }-                                .sortedWith(-                                    compareByDescending<VideoStream> { it.height }-                                        .thenByDescending { it.fps }-                                        .thenByDescending { codecPriority(it.codec) }-                                )-                            videoStreams = combinedVideo+                                .groupBy { it.height }+                                .map { (_, streamsAtRes) -> streamsAtRes.maxWith(videoStreamPreference) }+                                .sortedByDescending { it.height }                              // Audio: opus only (F-Droid friendly, higher quality). Filter before sort.                             val rawAudioCandidates = if (progAudio.isNotEmpty()) {@@ -830,7 +814,9 @@ class YouPipeViewModel(                                 )                         } else {                             videoStreams = ex.getVideoStreams().map { it.toDomain() }-                                .sortedWith(compareByDescending { it.height })+                                .groupBy { it.height }+                                .map { (_, streamsAtRes) -> streamsAtRes.maxWith(videoStreamPreference) }+                                .sortedByDescending { it.height }                             audioStreams = emptyList()                         }                     } else {@@ -1405,6 +1391,9 @@ private fun codecPriority(codec: String): Int = when (codec) {     "av1" -> 3; "vp9" -> 2; "avc" -> 1; else -> 0 } +private val videoStreamPreference: Comparator<VideoStream> =+    compareBy<VideoStream> { it.fps }.thenBy { codecPriority(it.codec) }+ /** Factory for constructing [YouPipeViewModel] with the repository. */ class YouPipeViewModelFactory(     private val application: Application,