Skip to content

StreamVault is a TV-first free IPTV player for Android TV built with Kotlin, Jetpack Compose, Room, Hilt, and Media3.

better 4k handling and buffer timing

David Nashash3f3007f7c73b
diff --git a/app/src/main/java/com/streamvault/app/navigation/AppNavigation.kt b/app/src/main/java/com/streamvault/app/navigation/AppNavigation.kt
index f0a07f21..edd4121f 100644
--- a/app/src/main/java/com/streamvault/app/navigation/AppNavigation.kt
+++ b/app/src/main/java/com/streamvault/app/navigation/AppNavigation.kt
@@ -759,10 +759,15 @@ fun AppNavigation(mainActivity: MainActivity) {
if (!route.isNullOrBlank() && navController.popBackStack(route, false)) {
// Popped back to the exact route already in the backstack (same VM, handoff works)
Unit
- } else if (!navController.popBackStack()) {
+ } else if (!route.isNullOrBlank()) {
// Nothing left to pop — navigate to the return route or home as a last resort
- val fallback = route?.takeIf { it.isNotBlank() } ?: Routes.HOME
- navController.navigate(fallback) {
+ navController.navigate(route) {
+ popUpTo(Routes.PLAYER) { inclusive = true }
+ launchSingleTop = true
+ restoreState = true
+ }
+ } else if (!navController.popBackStack()) {
+ navController.navigate(Routes.HOME) {
popUpTo(Routes.PLAYER) { inclusive = true }
launchSingleTop = true
restoreState = true
diff --git a/app/src/main/java/com/streamvault/app/ui/screens/epg/EpgViewModel.kt b/app/src/main/java/com/streamvault/app/ui/screens/epg/EpgViewModel.kt
index 699af503..36df074f 100644
--- a/app/src/main/java/com/streamvault/app/ui/screens/epg/EpgViewModel.kt
+++ b/app/src/main/java/com/streamvault/app/ui/screens/epg/EpgViewModel.kt
@@ -414,6 +414,7 @@ class EpgViewModel @Inject constructor(
engine.stop()
engine.setDecoderMode(preferencesRepository.playerDecoderMode.first())
engine.setSurfaceMode(preferencesRepository.playerSurfaceMode.first())
+ engine.setPlaybackBufferMode(preferencesRepository.playerPlaybackBufferMode.first())
engine.prepare(preparedStreamInfo)
engine.setVolume(1f)
engine.play()
diff --git a/app/src/main/java/com/streamvault/app/ui/screens/home/HomeViewModel.kt b/app/src/main/java/com/streamvault/app/ui/screens/home/HomeViewModel.kt
index be8e2d56..2ffe086c 100644
--- a/app/src/main/java/com/streamvault/app/ui/screens/home/HomeViewModel.kt
+++ b/app/src/main/java/com/streamvault/app/ui/screens/home/HomeViewModel.kt
@@ -1061,6 +1061,7 @@ class HomeViewModel @Inject constructor(
engine.stop()
engine.setDecoderMode(preferencesRepository.playerDecoderMode.first())
engine.setSurfaceMode(preferencesRepository.playerSurfaceMode.first())
+ engine.setPlaybackBufferMode(preferencesRepository.playerPlaybackBufferMode.first())
engine.setFastRetryOnTransientFailures(
preferencesRepository.playerFastRetryOnTransientFailures.first()
)
diff --git a/app/src/main/java/com/streamvault/app/ui/screens/multiview/MultiViewViewModel.kt b/app/src/main/java/com/streamvault/app/ui/screens/multiview/MultiViewViewModel.kt
index 46686f54..8a357380 100644
--- a/app/src/main/java/com/streamvault/app/ui/screens/multiview/MultiViewViewModel.kt
+++ b/app/src/main/java/com/streamvault/app/ui/screens/multiview/MultiViewViewModel.kt
@@ -286,6 +286,7 @@ class MultiViewViewModel @Inject constructor(
localEngine.setFastRetryOnTransientFailures(
preferencesRepository.playerFastRetryOnTransientFailures.first()
)
+ localEngine.setPlaybackBufferMode(preferencesRepository.playerPlaybackBufferMode.first())
val streamInfo = when (val result = channelRepository.getStreamInfo(channel)) {
is Result.Success -> result.data
is Result.Error -> throw IllegalStateException(result.message)
diff --git a/app/src/main/java/com/streamvault/app/ui/screens/player/PlayerViewModel.kt b/app/src/main/java/com/streamvault/app/ui/screens/player/PlayerViewModel.kt
index b2e81f57..d30c6280 100644
--- a/app/src/main/java/com/streamvault/app/ui/screens/player/PlayerViewModel.kt
+++ b/app/src/main/java/com/streamvault/app/ui/screens/player/PlayerViewModel.kt
@@ -665,6 +665,13 @@ class PlayerViewModel @Inject constructor(
}
}
}
+ viewModelScope.launch {
+ preferencesRepository.playerPlaybackBufferMode
+ .combine(activePlayerEngineFlow) { mode, engine -> engine to mode }
+ .collect { (engine, mode) ->
+ engine.setPlaybackBufferMode(mode)
+ }
+ }
viewModelScope.launch {
preferencesRepository.playerAudioOutputPreference
.combine(activePlayerEngineFlow) { preference, engine -> engine to preference }
@@ -1145,6 +1152,7 @@ class PlayerViewModel @Inject constructor(
ethernetMaxHeight = preferencesRepository.playerEthernetMaxVideoHeight.first()
)
playerEngine.setSurfaceMode(preferencesRepository.playerSurfaceMode.first())
+ playerEngine.setPlaybackBufferMode(preferencesRepository.playerPlaybackBufferMode.first())
playerEngine.setVodHttpProtocolMode(preferencesRepository.playerVodHttpProtocolMode.first())
playerEngine.setFastRetryOnTransientFailures(preferencesRepository.playerFastRetryOnTransientFailures.first())
playerEngine.setAudioVideoOffsetMs(_audioVideoOffsetUiState.value.effectiveOffsetMs)
diff --git a/app/src/main/java/com/streamvault/app/ui/screens/settings/SettingsContentPane.kt b/app/src/main/java/com/streamvault/app/ui/screens/settings/SettingsContentPane.kt
index 0fe2ad11..176e4d56 100644
--- a/app/src/main/java/com/streamvault/app/ui/screens/settings/SettingsContentPane.kt
+++ b/app/src/main/java/com/streamvault/app/ui/screens/settings/SettingsContentPane.kt
@@ -59,6 +59,7 @@ internal fun SettingsContentPane(
viewModel = viewModel,
timeshiftDepthLabel = screenLabels.timeshiftDepthLabel,
decoderModeLabel = screenLabels.decoderModeLabel,
+ playbackBufferModeLabel = screenLabels.playbackBufferModeLabel,
audioOutputPreferenceLabel = screenLabels.audioOutputPreferenceLabel,
externalPlaybackModeLabel = screenLabels.externalPlaybackModeLabel,
surfaceModeLabel = screenLabels.surfaceModeLabel,
@@ -82,6 +83,7 @@ internal fun SettingsContentPane(
speedTestRecommendationLabel = screenLabels.speedTestRecommendationLabel,
onShowTimeshiftDepthDialogChange = { dialogState.showTimeshiftDepthDialog = it },
onShowDecoderModeDialogChange = { dialogState.showDecoderModeDialog = it },
+ onShowPlaybackBufferModeDialogChange = { dialogState.showPlaybackBufferModeDialog = it },
onShowAudioOutputPreferenceDialogChange = { dialogState.showAudioOutputPreferenceDialog = it },
onShowExternalPlaybackModeDialogChange = { dialogState.showExternalPlaybackModeDialog = it },
onShowSurfaceModeDialogChange = { dialogState.showSurfaceModeDialog = it },
diff --git a/app/src/main/java/com/streamvault/app/ui/screens/settings/SettingsPlaybackSection.kt b/app/src/main/java/com/streamvault/app/ui/screens/settings/SettingsPlaybackSection.kt
index d9454919..711fd504 100644
--- a/app/src/main/java/com/streamvault/app/ui/screens/settings/SettingsPlaybackSection.kt
+++ b/app/src/main/java/com/streamvault/app/ui/screens/settings/SettingsPlaybackSection.kt
@@ -36,6 +36,7 @@ internal fun LazyListScope.settingsPlaybackSection(
viewModel: SettingsViewModel,
timeshiftDepthLabel: String,
decoderModeLabel: String,
+ playbackBufferModeLabel: String,
audioOutputPreferenceLabel: String,
externalPlaybackModeLabel: String,
surfaceModeLabel: String,
@@ -59,6 +60,7 @@ internal fun LazyListScope.settingsPlaybackSection(
speedTestRecommendationLabel: String,
onShowTimeshiftDepthDialogChange: (Boolean) -> Unit,
onShowDecoderModeDialogChange: (Boolean) -> Unit,
+ onShowPlaybackBufferModeDialogChange: (Boolean) -> Unit,
onShowAudioOutputPreferenceDialogChange: (Boolean) -> Unit,
onShowExternalPlaybackModeDialogChange: (Boolean) -> Unit,
onShowSurfaceModeDialogChange: (Boolean) -> Unit,
@@ -274,6 +276,11 @@ internal fun LazyListScope.settingsPlaybackSection(
value = decoderModeLabel,
onClick = { onShowDecoderModeDialogChange(true) }
)
+ ClickableSettingsRow(
+ label = stringResource(R.string.settings_live_buffer_size),
+ value = playbackBufferModeLabel,
+ onClick = { onShowPlaybackBufferModeDialogChange(true) }
+ )
ClickableSettingsRow(
label = stringResource(R.string.settings_audio_output_mode),
value = audioOutputPreferenceLabel,
diff --git a/app/src/main/java/com/streamvault/app/ui/screens/settings/SettingsPlayerPreferenceDialogs.kt b/app/src/main/java/com/streamvault/app/ui/screens/settings/SettingsPlayerPreferenceDialogs.kt
index 1d9fd149..4452e0e4 100644
--- a/app/src/main/java/com/streamvault/app/ui/screens/settings/SettingsPlayerPreferenceDialogs.kt
+++ b/app/src/main/java/com/streamvault/app/ui/screens/settings/SettingsPlayerPreferenceDialogs.kt
@@ -8,6 +8,7 @@ import com.streamvault.app.R
import com.streamvault.domain.model.AppTimeFormat
import com.streamvault.domain.model.AudioOutputPreference
import com.streamvault.domain.model.DecoderMode
+import com.streamvault.domain.model.PlaybackBufferMode
import com.streamvault.domain.model.VodHttpProtocolMode
import com.streamvault.domain.model.PlayerSurfaceMode
@@ -24,6 +25,8 @@ internal fun SettingsPlayerPreferenceDialogs(
onShowAudioVideoOffsetDialogChange: (Boolean) -> Unit,
showDecoderModeDialog: Boolean,
onShowDecoderModeDialogChange: (Boolean) -> Unit,
+ showPlaybackBufferModeDialog: Boolean,
+ onShowPlaybackBufferModeDialogChange: (Boolean) -> Unit,
showAudioOutputPreferenceDialog: Boolean,
onShowAudioOutputPreferenceDialogChange: (Boolean) -> Unit,
showSurfaceModeDialog: Boolean,
@@ -124,6 +127,33 @@ internal fun SettingsPlayerPreferenceDialogs(
}
}
+ if (showPlaybackBufferModeDialog) {
+ val bufferOptions = remember(context) {
+ listOf(
+ PlaybackBufferMode.AUTO to context.getString(R.string.settings_live_buffer_auto),
+ PlaybackBufferMode.SMALL to context.getString(R.string.settings_live_buffer_small),
+ PlaybackBufferMode.MEDIUM to context.getString(R.string.settings_live_buffer_medium),
+ PlaybackBufferMode.LARGE to context.getString(R.string.settings_live_buffer_large)
+ )
+ }
+ PremiumSelectionDialog(
+ title = stringResource(R.string.settings_live_buffer_size),
+ onDismiss = { onShowPlaybackBufferModeDialogChange(false) }
+ ) {
+ bufferOptions.forEachIndexed { index, option ->
+ LevelOption(
+ level = index,
+ text = option.second,
+ currentLevel = if (uiState.playerPlaybackBufferMode == option.first) index else -1,
+ onSelect = {
+ viewModel.setPlayerPlaybackBufferMode(option.first)
+ onShowPlaybackBufferModeDialogChange(false)
+ }
+ )
+ }
+ }
+ }
+
if (showAudioOutputPreferenceDialog) {
val outputOptions = remember(context) {
listOf(
diff --git a/app/src/main/java/com/streamvault/app/ui/screens/settings/SettingsPreferenceDialogs.kt b/app/src/main/java/com/streamvault/app/ui/screens/settings/SettingsPreferenceDialogs.kt
index aefe0c0c..610cf053 100644
--- a/app/src/main/java/com/streamvault/app/ui/screens/settings/SettingsPreferenceDialogs.kt
+++ b/app/src/main/java/com/streamvault/app/ui/screens/settings/SettingsPreferenceDialogs.kt
@@ -36,6 +36,8 @@ internal fun SettingsPreferenceDialogs(
onShowAudioVideoOffsetDialogChange: (Boolean) -> Unit,
showDecoderModeDialog: Boolean,
onShowDecoderModeDialogChange: (Boolean) -> Unit,
+ showPlaybackBufferModeDialog: Boolean,
+ onShowPlaybackBufferModeDialogChange: (Boolean) -> Unit,
showAudioOutputPreferenceDialog: Boolean,
onShowAudioOutputPreferenceDialogChange: (Boolean) -> Unit,
showSurfaceModeDialog: Boolean,
@@ -89,6 +91,8 @@ internal fun SettingsPreferenceDialogs(
onShowAudioVideoOffsetDialogChange = onShowAudioVideoOffsetDialogChange,
showDecoderModeDialog = showDecoderModeDialog,
onShowDecoderModeDialogChange = onShowDecoderModeDialogChange,
+ showPlaybackBufferModeDialog = showPlaybackBufferModeDialog,
+ onShowPlaybackBufferModeDialogChange = onShowPlaybackBufferModeDialogChange,
showAudioOutputPreferenceDialog = showAudioOutputPreferenceDialog,
onShowAudioOutputPreferenceDialogChange = onShowAudioOutputPreferenceDialogChange,
showSurfaceModeDialog = showSurfaceModeDialog,
diff --git a/app/src/main/java/com/streamvault/app/ui/screens/settings/SettingsPreferenceModels.kt b/app/src/main/java/com/streamvault/app/ui/screens/settings/SettingsPreferenceModels.kt
index 24c4ebb0..549c8825 100644
--- a/app/src/main/java/com/streamvault/app/ui/screens/settings/SettingsPreferenceModels.kt
+++ b/app/src/main/java/com/streamvault/app/ui/screens/settings/SettingsPreferenceModels.kt
@@ -17,6 +17,7 @@ import com.streamvault.domain.model.DecoderMode
import com.streamvault.domain.model.GroupedChannelLabelMode
import com.streamvault.domain.model.LiveChannelGroupingMode
import com.streamvault.domain.model.LiveVariantPreferenceMode
+import com.streamvault.domain.model.PlaybackBufferMode
import com.streamvault.domain.model.VodDuplicateHandlingMode
import com.streamvault.domain.model.VodHttpProtocolMode
import com.streamvault.domain.model.VodVariantPreferenceMode
@@ -53,6 +54,7 @@ internal data class SettingsPreferenceSnapshot(
val playerMediaSessionEnabled: Boolean,
val playerFastRetryOnTransientFailures: Boolean,
val playerDecoderMode: DecoderMode,
+ val playerPlaybackBufferMode: PlaybackBufferMode,
val playerAudioOutputPreference: AudioOutputPreference,
val playerCompatibilityMemoryEnabled: Boolean,
val playerSurfaceMode: PlayerSurfaceMode,
diff --git a/app/src/main/java/com/streamvault/app/ui/screens/settings/SettingsPreferenceSnapshotMapper.kt b/app/src/main/java/com/streamvault/app/ui/screens/settings/SettingsPreferenceSnapshotMapper.kt
index 6ab1b1fb..6be4ed2e 100644
--- a/app/src/main/java/com/streamvault/app/ui/screens/settings/SettingsPreferenceSnapshotMapper.kt
+++ b/app/src/main/java/com/streamvault/app/ui/screens/settings/SettingsPreferenceSnapshotMapper.kt
@@ -16,6 +16,7 @@ internal fun SettingsUiState.applyPreferenceSnapshot(snapshot: SettingsPreferenc
playerMediaSessionEnabled = snapshot.playerMediaSessionEnabled,
playerFastRetryOnTransientFailures = snapshot.playerFastRetryOnTransientFailures,
playerDecoderMode = snapshot.playerDecoderMode,
+ playerPlaybackBufferMode = snapshot.playerPlaybackBufferMode,
playerAudioOutputPreference = snapshot.playerAudioOutputPreference,
playerCompatibilityMemoryEnabled = snapshot.playerCompatibilityMemoryEnabled,
playerSurfaceMode = snapshot.playerSurfaceMode,
diff --git a/app/src/main/java/com/streamvault/app/ui/screens/settings/SettingsScreenDialogState.kt b/app/src/main/java/com/streamvault/app/ui/screens/settings/SettingsScreenDialogState.kt
index b4c40b66..b89a0530 100644
--- a/app/src/main/java/com/streamvault/app/ui/screens/settings/SettingsScreenDialogState.kt
+++ b/app/src/main/java/com/streamvault/app/ui/screens/settings/SettingsScreenDialogState.kt
@@ -30,6 +30,7 @@ internal class SettingsScreenDialogState(
private val showExternalPlaybackModeDialogState: MutableState<Boolean>,
private val showAudioVideoOffsetDialogState: MutableState<Boolean>,
private val showDecoderModeDialogState: MutableState<Boolean>,
+ private val showPlaybackBufferModeDialogState: MutableState<Boolean>,
private val showAudioOutputPreferenceDialogState: MutableState<Boolean>,
private val showSurfaceModeDialogState: MutableState<Boolean>,
private val showVodHttpProtocolDialogState: MutableState<Boolean>,
@@ -91,6 +92,7 @@ internal class SettingsScreenDialogState(
var showExternalPlaybackModeDialog by showExternalPlaybackModeDialogState
var showAudioVideoOffsetDialog by showAudioVideoOffsetDialogState
var showDecoderModeDialog by showDecoderModeDialogState
+ var showPlaybackBufferModeDialog by showPlaybackBufferModeDialogState
var showAudioOutputPreferenceDialog by showAudioOutputPreferenceDialogState
var showSurfaceModeDialog by showSurfaceModeDialogState
var showVodHttpProtocolDialog by showVodHttpProtocolDialogState
@@ -220,6 +222,7 @@ internal fun rememberSettingsScreenDialogState(): SettingsScreenDialogState {
val showExternalPlaybackModeDialogState = rememberSaveable { mutableStateOf(false) }
val showAudioVideoOffsetDialogState = rememberSaveable { mutableStateOf(false) }
val showDecoderModeDialogState = rememberSaveable { mutableStateOf(false) }
+ val showPlaybackBufferModeDialogState = rememberSaveable { mutableStateOf(false) }
val showAudioOutputPreferenceDialogState = rememberSaveable { mutableStateOf(false) }
val showSurfaceModeDialogState = rememberSaveable { mutableStateOf(false) }
val showVodHttpProtocolDialogState = rememberSaveable { mutableStateOf(false) }
@@ -290,6 +293,7 @@ internal fun rememberSettingsScreenDialogState(): SettingsScreenDialogState {
showExternalPlaybackModeDialogState = showExternalPlaybackModeDialogState,
showAudioVideoOffsetDialogState = showAudioVideoOffsetDialogState,
showDecoderModeDialogState = showDecoderModeDialogState,
+ showPlaybackBufferModeDialogState = showPlaybackBufferModeDialogState,
showAudioOutputPreferenceDialogState = showAudioOutputPreferenceDialogState,
showSurfaceModeDialogState = showSurfaceModeDialogState,
showVodHttpProtocolDialogState = showVodHttpProtocolDialogState,
diff --git a/app/src/main/java/com/streamvault/app/ui/screens/settings/SettingsScreenDialogs.kt b/app/src/main/java/com/streamvault/app/ui/screens/settings/SettingsScreenDialogs.kt
index e50def94..20e4d834 100644
--- a/app/src/main/java/com/streamvault/app/ui/screens/settings/SettingsScreenDialogs.kt
+++ b/app/src/main/java/com/streamvault/app/ui/screens/settings/SettingsScreenDialogs.kt
@@ -188,6 +188,8 @@ internal fun SettingsScreenDialogs(
onShowAudioVideoOffsetDialogChange = { dialogState.showAudioVideoOffsetDialog = it },
showDecoderModeDialog = dialogState.showDecoderModeDialog,
onShowDecoderModeDialogChange = { dialogState.showDecoderModeDialog = it },
+ showPlaybackBufferModeDialog = dialogState.showPlaybackBufferModeDialog,
+ onShowPlaybackBufferModeDialogChange = { dialogState.showPlaybackBufferModeDialog = it },
showAudioOutputPreferenceDialog = dialogState.showAudioOutputPreferenceDialog,
onShowAudioOutputPreferenceDialogChange = { dialogState.showAudioOutputPreferenceDialog = it },
showSurfaceModeDialog = dialogState.showSurfaceModeDialog,
diff --git a/app/src/main/java/com/streamvault/app/ui/screens/settings/SettingsScreenState.kt b/app/src/main/java/com/streamvault/app/ui/screens/settings/SettingsScreenState.kt
index c02e663b..bcfd7c44 100644
--- a/app/src/main/java/com/streamvault/app/ui/screens/settings/SettingsScreenState.kt
+++ b/app/src/main/java/com/streamvault/app/ui/screens/settings/SettingsScreenState.kt
@@ -14,6 +14,7 @@ import com.streamvault.domain.model.AppTopLevelDestination
import com.streamvault.domain.model.AppTimeFormat
import com.streamvault.domain.model.AudioOutputPreference
import com.streamvault.domain.model.LiveStreamFormatMode
+import com.streamvault.domain.model.PlaybackBufferMode
import com.streamvault.domain.model.VodHttpProtocolMode
internal data class SettingsScreenLabels(
@@ -27,6 +28,7 @@ internal data class SettingsScreenLabels(
val playbackSpeedLabel: String,
val audioVideoOffsetLabel: String,
val decoderModeLabel: String,
+ val playbackBufferModeLabel: String,
val audioOutputPreferenceLabel: String,
val surfaceModeLabel: String,
val vodHttpProtocolLabel: String,
@@ -87,6 +89,9 @@ internal fun rememberSettingsScreenLabels(
val decoderModeLabel = remember(uiState.playerDecoderMode, context) {
formatDecoderModeLabel(uiState.playerDecoderMode, context)
}
+ val playbackBufferModeLabel = remember(uiState.playerPlaybackBufferMode, context) {
+ formatPlaybackBufferModeLabel(uiState.playerPlaybackBufferMode, context)
+ }
val audioOutputPreferenceLabel = remember(uiState.playerAudioOutputPreference, context) {
formatAudioOutputPreferenceLabel(uiState.playerAudioOutputPreference, context)
}
@@ -180,6 +185,7 @@ internal fun rememberSettingsScreenLabels(
playbackSpeedLabel = playbackSpeedLabel,
audioVideoOffsetLabel = audioVideoOffsetLabel,
decoderModeLabel = decoderModeLabel,
+ playbackBufferModeLabel = playbackBufferModeLabel,
audioOutputPreferenceLabel = audioOutputPreferenceLabel,
surfaceModeLabel = surfaceModeLabel,
vodHttpProtocolLabel = vodHttpProtocolLabel,
@@ -284,6 +290,16 @@ internal fun formatVodHttpProtocolModeLabel(
VodHttpProtocolMode.AUTO -> context.getString(R.string.settings_vod_http_protocol_auto)
}
+internal fun formatPlaybackBufferModeLabel(
+ mode: PlaybackBufferMode,
+ context: Context
+): String = when (mode) {
+ PlaybackBufferMode.AUTO -> context.getString(R.string.settings_live_buffer_auto)
+ PlaybackBufferMode.SMALL -> context.getString(R.string.settings_live_buffer_small)
+ PlaybackBufferMode.MEDIUM -> context.getString(R.string.settings_live_buffer_medium)
+ PlaybackBufferMode.LARGE -> context.getString(R.string.settings_live_buffer_large)
+}
+
internal fun formatLiveStreamFormatModeLabel(mode: LiveStreamFormatMode): String = when (mode) {
LiveStreamFormatMode.AUTO -> "Auto"
LiveStreamFormatMode.HLS -> "HLS (m3u8)"
diff --git a/app/src/main/java/com/streamvault/app/ui/screens/settings/SettingsStateBindings.kt b/app/src/main/java/com/streamvault/app/ui/screens/settings/SettingsStateBindings.kt
index e39c49cc..45bf70c6 100644
--- a/app/src/main/java/com/streamvault/app/ui/screens/settings/SettingsStateBindings.kt
+++ b/app/src/main/java/com/streamvault/app/ui/screens/settings/SettingsStateBindings.kt
@@ -17,6 +17,7 @@ import com.streamvault.domain.model.ExternalPlaybackMode
import com.streamvault.domain.model.GroupedChannelLabelMode
import com.streamvault.domain.model.LiveChannelGroupingMode
import com.streamvault.domain.model.LiveVariantPreferenceMode
+import com.streamvault.domain.model.PlaybackBufferMode
import com.streamvault.domain.model.VodDuplicateHandlingMode
import com.streamvault.domain.model.VodHttpProtocolMode
import com.streamvault.domain.model.VodVariantPreferenceMode
@@ -51,6 +52,7 @@ internal fun observeSettingsPreferenceSnapshot(
playerMediaSessionEnabled = true,
playerFastRetryOnTransientFailures = false,
playerDecoderMode = DecoderMode.AUTO,
+ playerPlaybackBufferMode = PlaybackBufferMode.AUTO,
playerAudioOutputPreference = AudioOutputPreference.AUTO,
playerCompatibilityMemoryEnabled = true,
playerSurfaceMode = com.streamvault.domain.model.PlayerSurfaceMode.AUTO,
@@ -130,6 +132,8 @@ internal fun observeSettingsPreferenceSnapshot(
snapshot.copy(playerFastRetryOnTransientFailures = enabled)
}.combine(preferencesRepository.playerDecoderMode) { snapshot, decoderMode ->
snapshot.copy(playerDecoderMode = decoderMode)
+ }.combine(preferencesRepository.playerPlaybackBufferMode) { snapshot, bufferMode ->
+ snapshot.copy(playerPlaybackBufferMode = bufferMode)
}.combine(preferencesRepository.playerAudioOutputPreference) { snapshot, audioOutputPreference ->
snapshot.copy(playerAudioOutputPreference = audioOutputPreference)
}.combine(preferencesRepository.playerCompatibilityMemoryEnabled) { snapshot, enabled ->
diff --git a/app/src/main/java/com/streamvault/app/ui/screens/settings/SettingsUiStateModel.kt b/app/src/main/java/com/streamvault/app/ui/screens/settings/SettingsUiStateModel.kt
index 70b339b3..b1f41dc1 100644
--- a/app/src/main/java/com/streamvault/app/ui/screens/settings/SettingsUiStateModel.kt
+++ b/app/src/main/java/com/streamvault/app/ui/screens/settings/SettingsUiStateModel.kt
@@ -25,6 +25,7 @@ import com.streamvault.domain.model.EpgResolutionSummary
import com.streamvault.domain.model.GroupedChannelLabelMode
import com.streamvault.domain.model.LiveChannelGroupingMode
import com.streamvault.domain.model.LiveVariantPreferenceMode
+import com.streamvault.domain.model.PlaybackBufferMode
import com.streamvault.domain.model.VodDuplicateHandlingMode
import com.streamvault.domain.model.VodHttpProtocolMode
import com.streamvault.domain.model.ExternalPlaybackMode
@@ -72,6 +73,7 @@ data class SettingsUiState(
val playerMediaSessionEnabled: Boolean = true,
val playerFastRetryOnTransientFailures: Boolean = false,
val playerDecoderMode: DecoderMode = DecoderMode.AUTO,
+ val playerPlaybackBufferMode: PlaybackBufferMode = PlaybackBufferMode.AUTO,
val playerAudioOutputPreference: AudioOutputPreference = AudioOutputPreference.AUTO,
val playerCompatibilityMemoryEnabled: Boolean = true,
val playerSurfaceMode: PlayerSurfaceMode = PlayerSurfaceMode.AUTO,
diff --git a/app/src/main/java/com/streamvault/app/ui/screens/settings/SettingsViewModel.kt b/app/src/main/java/com/streamvault/app/ui/screens/settings/SettingsViewModel.kt
index 5b5d3b66..a32cf797 100644
--- a/app/src/main/java/com/streamvault/app/ui/screens/settings/SettingsViewModel.kt
+++ b/app/src/main/java/com/streamvault/app/ui/screens/settings/SettingsViewModel.kt
@@ -50,6 +50,7 @@ import com.streamvault.domain.model.AudioOutputPreference
import com.streamvault.domain.model.LiveChannelGroupingMode
import com.streamvault.domain.model.LiveStreamFormatMode
import com.streamvault.domain.model.LiveVariantPreferenceMode
+import com.streamvault.domain.model.PlaybackBufferMode
import com.streamvault.domain.model.VodDuplicateHandlingMode
import com.streamvault.domain.model.VodHttpProtocolMode
import com.streamvault.domain.model.ProviderStatus
@@ -786,6 +787,12 @@ class SettingsViewModel @Inject constructor(
}
}
+ fun setPlayerPlaybackBufferMode(mode: PlaybackBufferMode) {
+ viewModelScope.launch {
+ preferencesRepository.setPlayerPlaybackBufferMode(mode)
+ }
+ }
+
fun setPlayerAudioOutputPreference(preference: AudioOutputPreference) {
viewModelScope.launch {
preferencesRepository.setPlayerAudioOutputPreference(preference)
diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml
index ff38d98c..888a4fd4 100644
--- a/app/src/main/res/values/strings.xml
+++ b/app/src/main/res/values/strings.xml
@@ -575,6 +575,11 @@
<string name="settings_decoder_hardware">Hardware Only</string>
<string name="settings_decoder_software">Prefer Software Decoder</string>
<string name="settings_decoder_compatibility">Compatibility Mode</string>
+ <string name="settings_live_buffer_size">Live buffer size</string>
+ <string name="settings_live_buffer_auto">Auto</string>
+ <string name="settings_live_buffer_small">Small</string>
+ <string name="settings_live_buffer_medium">Medium</string>
+ <string name="settings_live_buffer_large">Large</string>
<string name="settings_audio_output_mode">Audio Output</string>
<string name="settings_audio_output_auto">Auto</string>
<string name="settings_audio_output_prefer_passthrough">Prefer passthrough</string>
diff --git a/app/src/test/java/com/streamvault/app/ui/screens/settings/SettingsPlaybackBufferModeTest.kt b/app/src/test/java/com/streamvault/app/ui/screens/settings/SettingsPlaybackBufferModeTest.kt
new file mode 100644
index 00000000..7cae3496
--- /dev/null
+++ b/app/src/test/java/com/streamvault/app/ui/screens/settings/SettingsPlaybackBufferModeTest.kt
@@ -0,0 +1,31 @@
+package com.streamvault.app.ui.screens.settings
+
+import android.content.Context
+import com.google.common.truth.Truth.assertThat
+import com.streamvault.app.R
+import com.streamvault.domain.model.PlaybackBufferMode
+import org.junit.Test
+import org.mockito.kotlin.mock
+import org.mockito.kotlin.whenever
+
+class SettingsPlaybackBufferModeTest {
+
+ @Test
+ fun `settings ui state defaults live buffer size to auto`() {
+ assertThat(SettingsUiState().playerPlaybackBufferMode).isEqualTo(PlaybackBufferMode.AUTO)
+ }
+
+ @Test
+ fun `formatPlaybackBufferModeLabel maps modes to settings labels`() {
+ val context: Context = mock()
+ whenever(context.getString(R.string.settings_live_buffer_auto)).thenReturn("Auto")
+ whenever(context.getString(R.string.settings_live_buffer_small)).thenReturn("Small")
+ whenever(context.getString(R.string.settings_live_buffer_medium)).thenReturn("Medium")
+ whenever(context.getString(R.string.settings_live_buffer_large)).thenReturn("Large")
+
+ assertThat(formatPlaybackBufferModeLabel(PlaybackBufferMode.AUTO, context)).isEqualTo("Auto")
+ assertThat(formatPlaybackBufferModeLabel(PlaybackBufferMode.SMALL, context)).isEqualTo("Small")
+ assertThat(formatPlaybackBufferModeLabel(PlaybackBufferMode.MEDIUM, context)).isEqualTo("Medium")
+ assertThat(formatPlaybackBufferModeLabel(PlaybackBufferMode.LARGE, context)).isEqualTo("Large")
+ }
+}
diff --git a/data/src/main/java/com/streamvault/data/preferences/PreferencesRepository.kt b/data/src/main/java/com/streamvault/data/preferences/PreferencesRepository.kt
index 8cfba160..4a77fa9e 100644
--- a/data/src/main/java/com/streamvault/data/preferences/PreferencesRepository.kt
+++ b/data/src/main/java/com/streamvault/data/preferences/PreferencesRepository.kt
@@ -31,6 +31,7 @@ import com.streamvault.domain.model.LiveChannelObservedQuality
import com.streamvault.domain.model.LiveStreamFormatMode
import com.streamvault.domain.model.LiveVariantPreferenceMode
import com.streamvault.domain.model.AppTopLevelDestination
+import com.streamvault.domain.model.PlaybackBufferMode
import com.streamvault.domain.model.VodDuplicateHandlingMode
import com.streamvault.domain.model.VodHttpProtocolMode
import com.streamvault.domain.model.VodVariantObservation
@@ -71,6 +72,10 @@ private fun sanitizePlaybackTimerMinutes(minutes: Int): Int = when (minutes) {
else -> 120
}
+internal fun parsePlaybackBufferModePreference(saved: String?): PlaybackBufferMode =
+ saved?.let { value -> PlaybackBufferMode.entries.firstOrNull { it.name == value } }
+ ?: PlaybackBufferMode.AUTO
+
@Singleton
class PreferencesRepository @Inject constructor(
@ApplicationContext private val context: Context,
@@ -142,6 +147,7 @@ class PreferencesRepository @Inject constructor(
val PLAYER_FAST_RETRY_ON_TRANSIENT_FAILURES =
booleanPreferencesKey("player_fast_retry_on_transient_failures")
val PLAYER_DECODER_MODE = stringPreferencesKey("player_decoder_mode")
+ val PLAYER_PLAYBACK_BUFFER_MODE = stringPreferencesKey("player_playback_buffer_mode")
val PLAYER_LIVE_STREAM_FORMAT_MODE = stringPreferencesKey("player_live_stream_format_mode")
val PLAYER_VOD_HTTP_PROTOCOL_MODE = stringPreferencesKey("player_vod_http_protocol_mode")
val LEGACY_PLAYER_MOVIE_HTTP_PROTOCOL_MODE = stringPreferencesKey("player_movie_http_protocol_mode")
@@ -305,6 +311,10 @@ class PreferencesRepository @Inject constructor(
?: DecoderMode.AUTO
}
+ val playerPlaybackBufferMode: Flow<PlaybackBufferMode> = context.dataStore.data.map { preferences ->
+ parsePlaybackBufferModePreference(preferences[PreferencesKeys.PLAYER_PLAYBACK_BUFFER_MODE])
+ }
+
val playerSurfaceMode: Flow<PlayerSurfaceMode> = context.dataStore.data.map { preferences ->
preferences[PreferencesKeys.PLAYER_SURFACE_MODE]
?.let { saved -> PlayerSurfaceMode.entries.firstOrNull { it.name == saved } }
@@ -864,6 +874,12 @@ class PreferencesRepository @Inject constructor(
}
}
+ suspend fun setPlayerPlaybackBufferMode(mode: PlaybackBufferMode) {
+ context.dataStore.edit { preferences ->
+ preferences[PreferencesKeys.PLAYER_PLAYBACK_BUFFER_MODE] = mode.name
+ }
+ }
+
suspend fun setPlayerAudioOutputPreference(preference: AudioOutputPreference) {
context.dataStore.edit { preferences ->
preferences[PreferencesKeys.PLAYER_AUDIO_OUTPUT_PREFERENCE] = preference.name
diff --git a/data/src/test/java/com/streamvault/data/preferences/PreferencesRepositoryPlaybackBufferModeTest.kt b/data/src/test/java/com/streamvault/data/preferences/PreferencesRepositoryPlaybackBufferModeTest.kt
new file mode 100644
index 00000000..bcde9c00
--- /dev/null
+++ b/data/src/test/java/com/streamvault/data/preferences/PreferencesRepositoryPlaybackBufferModeTest.kt
@@ -0,0 +1,24 @@
+package com.streamvault.data.preferences
+
+import com.google.common.truth.Truth.assertThat
+import com.streamvault.domain.model.PlaybackBufferMode
+import org.junit.Test
+
+class PreferencesRepositoryPlaybackBufferModeTest {
+
+ @Test
+ fun `parsePlaybackBufferModePreference defaults to auto when missing`() {
+ assertThat(parsePlaybackBufferModePreference(null)).isEqualTo(PlaybackBufferMode.AUTO)
+ }
+
+ @Test
+ fun `parsePlaybackBufferModePreference defaults to auto when saved value is invalid`() {
+ assertThat(parsePlaybackBufferModePreference("TINY")).isEqualTo(PlaybackBufferMode.AUTO)
+ }
+
+ @Test
+ fun `parsePlaybackBufferModePreference restores saved mode`() {
+ assertThat(parsePlaybackBufferModePreference("MEDIUM")).isEqualTo(PlaybackBufferMode.MEDIUM)
+ assertThat(parsePlaybackBufferModePreference("LARGE")).isEqualTo(PlaybackBufferMode.LARGE)
+ }
+}
diff --git a/docs/CHANGELOG.md b/docs/CHANGELOG.md
index 19eb4048..b2ab46fe 100644
--- a/docs/CHANGELOG.md
+++ b/docs/CHANGELOG.md
@@ -7,6 +7,7 @@ All notable product changes are recorded in this document.
### Fixed
- Fixed Picture-in-Picture compatibility on Android 7.1 / API 25 devices.
+- Fixed 4K / UHD / HDR live HLS playback stability by allowing live streams to promote to deeper HLS buffer policies when metadata or observed video format indicates high-resolution or high-bitrate playback needs.
- Fixed series episode preview fallback so missing or failed preview images still show the episode label instead of an empty tile.
- Fixed live playback recovery so decoder failures can retry with an alternate stream format after a software-decoder attempt.
- Fixed movie decoder fallback so HEVC playback failures can retry against an AVC/H.264 variant when another version is available.
@@ -33,6 +34,7 @@ All notable product changes are recorded in this document.
- Added episode preview artwork in series details, preferring episode thumbnails and falling back to series poster/backdrop artwork when episode art is missing.
- Added customizable Home dashboard shelves so users can hide default rows, enable extra built-in rows, and reorder the Home layout.
- Added customizable top navigation so users can show, hide, and reorder primary tabs while keeping Settings always available and automatically constraining the default landing screen to visible tabs.
+- Added a `Live buffer size` playback setting with `Auto`, `Small`, `Medium`, and `Large` modes for tuning live-stream buffering behavior.
- Added a playback setting to prefer live stream format selection with `Auto`, `HLS`, or `MPEG-TS` modes for Xtream live playback.
- Added Movies duplicate handling with smart/grouped presentation, preferred version ranking, detail-page version selection, sticky manual choices, and playback observations for reliability-based movie variant selection.
- Added Series duplicate handling with smart/grouped browse and search presentation, preferred version ranking, detail-page version selection with sticky manual choice, and raw-safe favorites/custom-group actions across grouped variants.
@@ -46,6 +48,8 @@ All notable product changes are recorded in this document.
### Changed
- Changed the app minimum supported Android version to Android 7.1 / API 25.
+- Changed live HLS buffering to use content-aware auto scaling instead of one fixed live profile, keeping normal HD channels responsive while automatically using deeper buffers for detected or observed UHD / HDR / high-bitrate streams.
+- Changed low-memory playback devices to cap automatic UHD live-HLS buffer promotion at the medium profile instead of always jumping to the largest buffer target.
- Changed the Stalker `Device profile` field label in setup to `MAG Type` while keeping the same underlying saved value and behavior.
## [1.0.14] - 2026-06-06
diff --git a/domain/src/main/java/com/streamvault/domain/model/PlaybackBufferMode.kt b/domain/src/main/java/com/streamvault/domain/model/PlaybackBufferMode.kt
new file mode 100644
index 00000000..592cce8d
--- /dev/null
+++ b/domain/src/main/java/com/streamvault/domain/model/PlaybackBufferMode.kt
@@ -0,0 +1,8 @@
+package com.streamvault.domain.model
+
+enum class PlaybackBufferMode {
+ AUTO,
+ SMALL,
+ MEDIUM,
+ LARGE
+}
diff --git a/domain/src/main/java/com/streamvault/domain/model/VideoFormat.kt b/domain/src/main/java/com/streamvault/domain/model/VideoFormat.kt
index 34ac92e6..0225ff1e 100644
--- a/domain/src/main/java/com/streamvault/domain/model/VideoFormat.kt
+++ b/domain/src/main/java/com/streamvault/domain/model/VideoFormat.kt
@@ -7,7 +7,8 @@ data class VideoFormat(
val bitrate: Int = 0,
val codecV: String? = null,
val codecA: String? = null,
- val pixelWidthHeightRatio: Float = 1f
+ val pixelWidthHeightRatio: Float = 1f,
+ val isHdr: Boolean = false
) {
init {
require(width >= 0) { "width must be non-negative" }
diff --git a/player/src/main/java/com/streamvault/player/Media3PlayerEngine.kt b/player/src/main/java/com/streamvault/player/Media3PlayerEngine.kt
index 6e61f0af..a7d9e7be 100644
--- a/player/src/main/java/com/streamvault/player/Media3PlayerEngine.kt
+++ b/player/src/main/java/com/streamvault/player/Media3PlayerEngine.kt
@@ -30,6 +30,7 @@ import androidx.media3.exoplayer.video.VideoRendererEventListener
import androidx.media3.session.MediaSession
import com.streamvault.domain.model.AudioOutputPreference
import com.streamvault.domain.model.DecoderMode
+import com.streamvault.domain.model.PlaybackBufferMode
import com.streamvault.domain.model.VodHttpProtocolMode
import com.streamvault.domain.model.PlaybackCompatibilityKey
import com.streamvault.domain.model.PlaybackCompatibilityRecord
@@ -45,9 +46,11 @@ import com.streamvault.player.playback.AudioVideoOffsetAudioSink
import com.streamvault.player.playback.PlaybackCodecSelector
import com.streamvault.player.playback.PlaybackCompatibilityProfile
import com.streamvault.player.playback.PlaybackBufferPolicies
+import com.streamvault.player.playback.PlaybackBufferPolicy
import com.streamvault.player.playback.PlaybackErrorCategory
import com.streamvault.player.playback.FfmpegAudioFallbackRequest
import com.streamvault.player.playback.FfmpegExtensionSupport
+import com.streamvault.player.playback.LiveHlsBufferPromotionDecider
import com.streamvault.player.playback.PlaybackLogSanitizer
import com.streamvault.player.playback.PlaybackPreparationPlan
import com.streamvault.player.playback.PlaybackExtensionRendererMode
@@ -167,6 +170,7 @@ class Media3PlayerEngine @Inject constructor(
private var mediaSession: MediaSession? = null
private var requestedDecoderMode: DecoderMode = DecoderMode.AUTO
private var activeDecoderMode: DecoderMode = DecoderMode.HARDWARE
+ private var requestedPlaybackBufferMode: PlaybackBufferMode = PlaybackBufferMode.AUTO
private var requestedSurfaceMode: PlayerSurfaceMode = PlayerSurfaceMode.AUTO
private var requestedVodHttpProtocolMode: VodHttpProtocolMode = VodHttpProtocolMode.COMPATIBILITY_HTTP1
private var sessionSurfaceModeOverride: PlayerSurfaceMode? = null
@@ -205,6 +209,8 @@ class Media3PlayerEngine @Inject constructor(
private var retryGeneration = 0L
private var currentBufferIsLive: Boolean? = null
private var currentBufferPolicyLabel: String? = null
+ private var currentBufferPolicy: PlaybackBufferPolicy? = null
+ private val promotedLiveHlsBufferReasonsByMediaId = mutableMapOf<String, String>()
private var audioCodecUnsupportedReported = false
private var lastSupportErrorMessage: String? = null
private val isLowMemoryPlaybackDevice: Boolean = run {
@@ -364,6 +370,9 @@ class Media3PlayerEngine @Inject constructor(
if (shouldRefreshPlaybackSupportSnapshot()) {
playbackSupportSnapshotStore.write(buildPlaybackSupportSnapshot())
}
+ if (promoteLiveHlsBufferIfNeeded()) {
+ continue
+ }
if (shouldFallbackTextureViewBeforeFirstFrame(stats)) {
fallbackTextureViewSurface("NO_FIRST_FRAME")
continue
@@ -510,6 +519,16 @@ class Media3PlayerEngine @Inject constructor(
}
}
+ override fun setPlaybackBufferMode(mode: PlaybackBufferMode) {
+ if (requestedPlaybackBufferMode == mode) return
+ requestedPlaybackBufferMode = mode
+ lastStreamInfo?.let { streamInfo ->
+ val wasPlaying = exoPlayer?.playWhenReady == true
+ val position = exoPlayer?.currentPosition
+ prepareInternal(streamInfo, preserveRetryState = false, seekPositionMs = position, autoPlay = wasPlaying)
+ }
+ }
+
override fun setSurfaceMode(mode: PlayerSurfaceMode) {
if (requestedSurfaceMode == mode) return
requestedSurfaceMode = mode
@@ -825,6 +844,9 @@ class Media3PlayerEngine @Inject constructor(
lastMediaId = null
currentRetryPolicy = null
currentRetryContext = null
+ currentBufferIsLive = null
+ currentBufferPolicyLabel = null
+ currentBufferPolicy = null
playbackStarted = false
liveBufferingRecoveryArmed = false
playbackStartedRecoveryArmed = false
@@ -962,7 +984,12 @@ class Media3PlayerEngine @Inject constructor(
val previousDecoderPolicy = activeDecoderPolicy
val nextBufferPolicy = PlaybackBufferPolicies.forPlayback(
resolvedStreamType = currentResolvedStreamType,
- compatibilityMode = nextDecoderPolicy == ActiveDecoderPolicy.COMPATIBILITY
+ compatibilityMode = nextDecoderPolicy == ActiveDecoderPolicy.COMPATIBILITY,
+ lowMemoryDevice = isLowMemoryPlaybackDevice,
+ bufferMode = requestedPlaybackBufferMode,
+ streamInfo = streamInfo,
+ observedVideoFormat = _videoFormat.value,
+ qualityReasonOverride = promotedLiveHlsBufferReasonsByMediaId[mediaId]
)
val needsRecreate = activeDecoderMode != preferredDecoderMode ||
previousDecoderPolicy != nextDecoderPolicy ||
@@ -973,6 +1000,7 @@ class Media3PlayerEngine @Inject constructor(
activeDecoderPolicy = nextDecoderPolicy
currentBufferIsLive = isLiveBuffer
currentBufferPolicyLabel = nextBufferPolicy.label
+ currentBufferPolicy = nextBufferPolicy
updateRenderSurfaceForMode()
if (needsRecreate) {
recreatePlayer()
@@ -982,6 +1010,7 @@ class Media3PlayerEngine @Inject constructor(
TAG,
"prepare resolvedStreamType=$currentResolvedStreamType timeoutProfile=$currentTimeoutProfile decoderPreference=$activeDecoderMode activePolicy=$activeDecoderPolicy audioOutputPreference=$audioOutputPreference compatibilitySource=$compatibilityDecisionSource surface=${_renderSurfaceType.value} target=${PlaybackLogSanitizer.sanitizeUrl(streamInfo.url)}"
)
+ Log.i(TAG, nextBufferPolicy.describeForLog(currentResolvedStreamType, requestedPlaybackBufferMode))
try {
val player = getOrCreatePlayer()
@@ -1063,10 +1092,14 @@ class Media3PlayerEngine @Inject constructor(
private fun createPlayer(): ExoPlayer {
val renderersFactory = buildRenderersFactory()
- val bufferPolicy = PlaybackBufferPolicies.forPlayback(
+ val bufferPolicy = currentBufferPolicy ?: PlaybackBufferPolicies.forPlayback(
resolvedStreamType = currentResolvedStreamType,
compatibilityMode = activeDecoderPolicy == ActiveDecoderPolicy.COMPATIBILITY,
- lowMemoryDevice = isLowMemoryPlaybackDevice
+ lowMemoryDevice = isLowMemoryPlaybackDevice,
+ bufferMode = requestedPlaybackBufferMode,
+ streamInfo = lastStreamInfo,
+ observedVideoFormat = _videoFormat.value,
+ qualityReasonOverride = lastMediaId?.let(promotedLiveHlsBufferReasonsByMediaId::get)
)
val loadControl = DefaultLoadControl.Builder()
.setBufferDurationsMs(
@@ -1107,6 +1140,16 @@ class Media3PlayerEngine @Inject constructor(
}
}
+ private fun PlaybackBufferPolicy.describeForLog(
+ resolvedStreamType: ResolvedStreamType,
+ bufferMode: PlaybackBufferMode
+ ): String {
+ return "buffer-policy label=$label streamType=$resolvedStreamType mode=$bufferMode " +
+ "reason=$qualityReason minMs=$minBufferMs maxMs=$maxBufferMs " +
+ "playbackMs=$playbackBufferMs rebufferMs=$rebufferMs " +
+ "targetBytes=$targetBufferBytes lowMemoryCapped=$lowMemoryCapped"
+ }
+
private fun buildRenderersFactory(): DefaultRenderersFactory {
logFfmpegAvailability()
@@ -1617,6 +1660,41 @@ class Media3PlayerEngine @Inject constructor(
liveBufferingRecoveryArmed = liveBufferingRecoveryArmed || playbackStartedRecoveryArmed
)
+ private fun promoteLiveHlsBufferIfNeeded(): Boolean {
+ val streamInfo = lastStreamInfo ?: return false
+ val mediaId = lastMediaId ?: return false
+ val observedFormat = _videoFormat.value.takeUnless(VideoFormat::isEmpty) ?: return false
+ val decision = LiveHlsBufferPromotionDecider.decide(
+ bufferMode = requestedPlaybackBufferMode,
+ resolvedStreamType = currentResolvedStreamType,
+ isLive = isCurrentStreamLive(),
+ mediaAlreadyPromoted = mediaId in promotedLiveHlsBufferReasonsByMediaId,
+ currentPolicyLabel = currentBufferPolicyLabel,
+ streamInfo = streamInfo,
+ observedVideoFormat = observedFormat,
+ compatibilityMode = activeDecoderPolicy == ActiveDecoderPolicy.COMPATIBILITY,
+ lowMemoryDevice = isLowMemoryPlaybackDevice
+ ) ?: return false
+
+ promotedLiveHlsBufferReasonsByMediaId[mediaId] = decision.qualityReason
+ val wasPlaying = exoPlayer?.playWhenReady ?: true
+ Log.i(
+ TAG,
+ "buffer-policy promote mediaId=$mediaId from=${currentBufferPolicyLabel.orEmpty()} " +
+ "to=${decision.policy.label} reason=${decision.qualityReason} " +
+ "format=${observedFormat.width}x${observedFormat.height} " +
+ "bitrate=${observedFormat.bitrate} hdr=${observedFormat.isHdr} " +
+ "target=${PlaybackLogSanitizer.sanitizeUrl(streamInfo.url)}"
+ )
+ prepareInternal(
+ streamInfo = streamInfo,
+ preserveRetryState = true,
+ seekPositionMs = null,
+ autoPlay = wasPlaying
+ )
+ return true
+ }
+
private fun handleVideoStall() {
val streamInfo = lastStreamInfo ?: return
videoStallCount++
diff --git a/player/src/main/java/com/streamvault/player/PlayerEngine.kt b/player/src/main/java/com/streamvault/player/PlayerEngine.kt
index 42f359a0..6ebf2fe8 100644
--- a/player/src/main/java/com/streamvault/player/PlayerEngine.kt
+++ b/player/src/main/java/com/streamvault/player/PlayerEngine.kt
@@ -4,6 +4,7 @@ import android.content.Context
import android.view.View
import com.streamvault.domain.model.AudioOutputPreference
import com.streamvault.domain.model.DecoderMode
+import com.streamvault.domain.model.PlaybackBufferMode
import com.streamvault.domain.model.VodHttpProtocolMode
import com.streamvault.domain.model.PlayerSurfaceMode
import com.streamvault.domain.model.DrmScheme
@@ -71,6 +72,7 @@ interface PlayerEngine {
fun seekForward(ms: Long = 10_000)
fun seekBackward(ms: Long = 10_000)
fun setDecoderMode(mode: DecoderMode)
+ fun setPlaybackBufferMode(mode: PlaybackBufferMode)
fun setSurfaceMode(mode: PlayerSurfaceMode)
fun setVodHttpProtocolMode(mode: VodHttpProtocolMode)
fun setMediaSessionEnabled(enabled: Boolean)
diff --git a/player/src/main/java/com/streamvault/player/playback/LiveHlsBufferPromotionDecider.kt b/player/src/main/java/com/streamvault/player/playback/LiveHlsBufferPromotionDecider.kt
new file mode 100644
index 00000000..afd7761e
--- /dev/null
+++ b/player/src/main/java/com/streamvault/player/playback/LiveHlsBufferPromotionDecider.kt
@@ -0,0 +1,51 @@
+package com.streamvault.player.playback
+
+import com.streamvault.domain.model.PlaybackBufferMode
+import com.streamvault.domain.model.StreamInfo
+import com.streamvault.domain.model.VideoFormat
+
+internal data class LiveHlsBufferPromotionDecision(
+ val policy: PlaybackBufferPolicy,
+ val qualityReason: String
+)
+
+internal object LiveHlsBufferPromotionDecider {
+
+ fun decide(
+ bufferMode: PlaybackBufferMode,
+ resolvedStreamType: ResolvedStreamType,
+ isLive: Boolean,
+ mediaAlreadyPromoted: Boolean,
+ currentPolicyLabel: String?,
+ streamInfo: StreamInfo?,
+ observedVideoFormat: VideoFormat,
+ compatibilityMode: Boolean,
+ lowMemoryDevice: Boolean
+ ): LiveHlsBufferPromotionDecision? {
+ if (bufferMode != PlaybackBufferMode.AUTO) return null
+ if (resolvedStreamType != ResolvedStreamType.HLS || !isLive) return null
+ if (mediaAlreadyPromoted) return null
+ streamInfo ?: return null
+ if (observedVideoFormat.isEmpty) return null
+
+ val qualityReason = PlaybackBufferPolicies.highQualityLiveHlsReason(
+ streamInfo = null,
+ observedVideoFormat = observedVideoFormat
+ ) ?: return null
+ val promotedPolicy = PlaybackBufferPolicies.forPlayback(
+ resolvedStreamType = resolvedStreamType,
+ compatibilityMode = compatibilityMode,
+ lowMemoryDevice = lowMemoryDevice,
+ bufferMode = bufferMode,
+ streamInfo = streamInfo,
+ observedVideoFormat = observedVideoFormat,
+ qualityReasonOverride = qualityReason
+ )
+ if (promotedPolicy.label == currentPolicyLabel) return null
+
+ return LiveHlsBufferPromotionDecision(
+ policy = promotedPolicy,
+ qualityReason = qualityReason
+ )
+ }
+}
diff --git a/player/src/main/java/com/streamvault/player/playback/PlaybackBufferPolicies.kt b/player/src/main/java/com/streamvault/player/playback/PlaybackBufferPolicies.kt
index 9a8f9c10..61297b79 100644
--- a/player/src/main/java/com/streamvault/player/playback/PlaybackBufferPolicies.kt
+++ b/player/src/main/java/com/streamvault/player/playback/PlaybackBufferPolicies.kt
@@ -1,5 +1,10 @@
package com.streamvault.player.playback
+import com.streamvault.domain.model.PlaybackBufferMode
+import com.streamvault.domain.model.StreamInfo
+import com.streamvault.domain.model.VideoFormat
+import java.util.Locale
+
internal data class PlaybackBufferPolicy(
val label: String,
val minBufferMs: Int,
@@ -7,12 +12,16 @@ internal data class PlaybackBufferPolicy(
val playbackBufferMs: Int,
val rebufferMs: Int,
val targetBufferBytes: Int,
- val prioritizeTimeOverSizeThresholds: Boolean
+ val prioritizeTimeOverSizeThresholds: Boolean,
+ val qualityReason: String = "baseline",
+ val lowMemoryCapped: Boolean = false
)
internal object PlaybackBufferPolicies {
private const val DEFAULT_TARGET_BUFFER_BYTES = -1
private const val MPEG_TS_LIVE_TARGET_BUFFER_BYTES = 16 * 1024 * 1024
+ private const val MEDIUM_LIVE_TARGET_BUFFER_BYTES = 32 * 1024 * 1024
+ private const val LARGE_LIVE_TARGET_BUFFER_BYTES = 64 * 1024 * 1024
private const val MPEG_TS_LIVE_MIN_BUFFER_MS = 5_000
private const val MPEG_TS_LIVE_MAX_BUFFER_MS = 10_000
@@ -35,6 +44,17 @@ internal object PlaybackBufferPolicies {
private const val REBUFFER_MS = 5_000
private const val VOD_PLAYBACK_BUFFER_MS = 8_000
private const val VOD_REBUFFER_MS = 18_000
+ private const val MEDIUM_LIVE_MIN_BUFFER_MS = 15_000
+ private const val MEDIUM_LIVE_MAX_BUFFER_MS = 45_000
+ private const val MEDIUM_LIVE_PLAYBACK_BUFFER_MS = 3_000
+ private const val MEDIUM_LIVE_REBUFFER_MS = 10_000
+ private const val LARGE_LIVE_MIN_BUFFER_MS = 30_000
+ private const val LARGE_LIVE_MAX_BUFFER_MS = 90_000
+ private const val LARGE_LIVE_PLAYBACK_BUFFER_MS = 5_000
+ private const val LARGE_LIVE_REBUFFER_MS = 15_000
+ private const val UHD_MIN_WIDTH = 3_840
+ private const val UHD_MIN_HEIGHT = 2_160
+ private const val HIGH_BITRATE_THRESHOLD_BPS = 20_000_000
fun forPlayback(
isLive: Boolean,
@@ -68,6 +88,55 @@ internal object PlaybackBufferPolicies {
resolvedStreamType: ResolvedStreamType,
compatibilityMode: Boolean,
lowMemoryDevice: Boolean
+ ): PlaybackBufferPolicy = forPlayback(
+ resolvedStreamType = resolvedStreamType,
+ compatibilityMode = compatibilityMode,
+ lowMemoryDevice = lowMemoryDevice,
+ bufferMode = PlaybackBufferMode.AUTO,
+ streamInfo = null,
+ observedVideoFormat = null
+ )
+
+ fun forPlayback(
+ resolvedStreamType: ResolvedStreamType,
+ compatibilityMode: Boolean,
+ lowMemoryDevice: Boolean,
+ bufferMode: PlaybackBufferMode,
+ streamInfo: StreamInfo? = null,
+ observedVideoFormat: VideoFormat? = null,
+ qualityReasonOverride: String? = null
+ ): PlaybackBufferPolicy = when {
+ bufferMode == PlaybackBufferMode.MEDIUM && resolvedStreamType.isLive ->
+ mediumLivePolicy(label = "medium-live", qualityReason = "user-medium")
+ bufferMode == PlaybackBufferMode.LARGE && resolvedStreamType.isLive ->
+ largeLivePolicy(label = "large-live", qualityReason = "user-large")
+ bufferMode == PlaybackBufferMode.AUTO && resolvedStreamType == ResolvedStreamType.HLS -> {
+ val qualityReason = qualityReasonOverride ?: highQualityLiveHlsReason(streamInfo, observedVideoFormat)
+ when {
+ qualityReason == null -> baselineLivePolicy(
+ resolvedStreamType = resolvedStreamType,
+ compatibilityMode = compatibilityMode,
+ lowMemoryDevice = lowMemoryDevice
+ )
+ lowMemoryDevice -> mediumLivePolicy(
+ label = "auto-uhd-live-hls-capped",
+ qualityReason = qualityReason,
+ lowMemoryCapped = true
+ )
+ else -> largeLivePolicy(label = "auto-uhd-live-hls", qualityReason = qualityReason)
+ }
+ }
+ else -> baselineLivePolicy(
+ resolvedStreamType = resolvedStreamType,
+ compatibilityMode = compatibilityMode,
+ lowMemoryDevice = lowMemoryDevice
+ )
+ }
+
+ private fun baselineLivePolicy(
+ resolvedStreamType: ResolvedStreamType,
+ compatibilityMode: Boolean,
+ lowMemoryDevice: Boolean
): PlaybackBufferPolicy = when {
lowMemoryDevice && resolvedStreamType == ResolvedStreamType.MPEG_TS_LIVE ->
PlaybackBufferPolicy(
@@ -151,6 +220,58 @@ internal object PlaybackBufferPolicies {
)
}
+ private fun mediumLivePolicy(
+ label: String,
+ qualityReason: String,
+ lowMemoryCapped: Boolean = false
+ ): PlaybackBufferPolicy = PlaybackBufferPolicy(
+ label = label,
+ minBufferMs = MEDIUM_LIVE_MIN_BUFFER_MS,
+ maxBufferMs = MEDIUM_LIVE_MAX_BUFFER_MS,
+ playbackBufferMs = MEDIUM_LIVE_PLAYBACK_BUFFER_MS,
+ rebufferMs = MEDIUM_LIVE_REBUFFER_MS,
+ targetBufferBytes = MEDIUM_LIVE_TARGET_BUFFER_BYTES,
+ prioritizeTimeOverSizeThresholds = true,
+ qualityReason = qualityReason,
+ lowMemoryCapped = lowMemoryCapped
+ )
+
+ private fun largeLivePolicy(label: String, qualityReason: String): PlaybackBufferPolicy = PlaybackBufferPolicy(
+ label = label,
+ minBufferMs = LARGE_LIVE_MIN_BUFFER_MS,
+ maxBufferMs = LARGE_LIVE_MAX_BUFFER_MS,
+ playbackBufferMs = LARGE_LIVE_PLAYBACK_BUFFER_MS,
+ rebufferMs = LARGE_LIVE_REBUFFER_MS,
+ targetBufferBytes = LARGE_LIVE_TARGET_BUFFER_BYTES,
+ prioritizeTimeOverSizeThresholds = true,
+ qualityReason = qualityReason
+ )
+
+ fun highQualityLiveHlsReason(streamInfo: StreamInfo?, observedVideoFormat: VideoFormat?): String? {
+ observedVideoFormat?.let { format ->
+ when {
+ format.width >= UHD_MIN_WIDTH -> return "observed-width-${format.width}"
+ format.height >= UHD_MIN_HEIGHT -> return "observed-height-${format.height}"
+ format.bitrate >= HIGH_BITRATE_THRESHOLD_BPS -> return "observed-bitrate-${format.bitrate}"
+ format.isHdr -> return "observed-hdr"
+ }
+ }
+ val searchable = listOfNotNull(
+ streamInfo?.title,
+ streamInfo?.url,
+ streamInfo?.containerExtension
+ ).joinToString(" ").lowercase(Locale.ROOT)
+ if (searchable.isBlank()) return null
+ return when {
+ "2160p" in searchable -> "metadata-2160p"
+ "2160" in searchable -> "metadata-2160"
+ "uhd" in searchable -> "metadata-uhd"
+ "4k" in searchable -> "metadata-4k"
+ "hdr" in searchable -> "metadata-hdr"
+ else -> null
+ }
+ }
+
private val ResolvedStreamType.isLive: Boolean
get() = this == ResolvedStreamType.HLS ||
this == ResolvedStreamType.SMOOTH_STREAMING ||
diff --git a/player/src/main/java/com/streamvault/player/stats/PlayerStatsCollector.kt b/player/src/main/java/com/streamvault/player/stats/PlayerStatsCollector.kt
index 60644990..1a6bc3d9 100644
--- a/player/src/main/java/com/streamvault/player/stats/PlayerStatsCollector.kt
+++ b/player/src/main/java/com/streamvault/player/stats/PlayerStatsCollector.kt
@@ -1,6 +1,7 @@
package com.streamvault.player.stats
import androidx.media3.common.Format
+import androidx.media3.common.C
import androidx.media3.exoplayer.ExoPlayer
import com.streamvault.domain.model.VideoFormat
import com.streamvault.player.PlaybackState
@@ -148,7 +149,11 @@ class PlayerStatsCollector(
bitrate = video?.bitrate?.takeIf { it > 0 } ?: 0,
codecV = video?.sampleMimeType ?: video?.codecs,
codecA = audio?.sampleMimeType ?: audio?.codecs,
- pixelWidthHeightRatio = video?.pixelWidthHeightRatio?.takeIf { it > 0f } ?: 1f
+ pixelWidthHeightRatio = video?.pixelWidthHeightRatio?.takeIf { it > 0f } ?: 1f,
+ isHdr = video?.colorInfo?.colorTransfer in setOf(
+ C.COLOR_TRANSFER_ST2084,
+ C.COLOR_TRANSFER_HLG
+ )
)
playerStats.value = playerStats.value.copy(
videoCodec = video?.sampleMimeType ?: video?.codecs
diff --git a/player/src/test/java/com/streamvault/player/playback/LiveHlsBufferPromotionDeciderTest.kt b/player/src/test/java/com/streamvault/player/playback/LiveHlsBufferPromotionDeciderTest.kt
new file mode 100644
index 00000000..e51f0cd3
--- /dev/null
+++ b/player/src/test/java/com/streamvault/player/playback/LiveHlsBufferPromotionDeciderTest.kt
@@ -0,0 +1,80 @@
+package com.streamvault.player.playback
+
+import com.google.common.truth.Truth.assertThat
+import com.streamvault.domain.model.PlaybackBufferMode
+import com.streamvault.domain.model.StreamInfo
+import com.streamvault.domain.model.VideoFormat
+import org.junit.Test
+
+class LiveHlsBufferPromotionDeciderTest {
+
+ @Test
+ fun `unchanged policy does not request promotion`() {
+ val decision = LiveHlsBufferPromotionDecider.decide(
+ bufferMode = PlaybackBufferMode.AUTO,
+ resolvedStreamType = ResolvedStreamType.HLS,
+ isLive = true,
+ mediaAlreadyPromoted = false,
+ currentPolicyLabel = "stable-live",
+ streamInfo = StreamInfo(url = "https://example.com/live/channel.m3u8"),
+ observedVideoFormat = VideoFormat(width = 1_920, height = 1_080),
+ compatibilityMode = false,
+ lowMemoryDevice = false
+ )
+
+ assertThat(decision).isNull()
+ }
+
+ @Test
+ fun `observed uhd promotion requests stronger policy`() {
+ val decision = LiveHlsBufferPromotionDecider.decide(
+ bufferMode = PlaybackBufferMode.AUTO,
+ resolvedStreamType = ResolvedStreamType.HLS,
+ isLive = true,
+ mediaAlreadyPromoted = false,
+ currentPolicyLabel = "stable-live",
+ streamInfo = StreamInfo(url = "https://example.com/live/channel.m3u8"),
+ observedVideoFormat = VideoFormat(width = 3_840, height = 2_160),
+ compatibilityMode = false,
+ lowMemoryDevice = false
+ )
+
+ assertThat(decision).isNotNull()
+ assertThat(decision?.policy?.label).isEqualTo("auto-uhd-live-hls")
+ assertThat(decision?.qualityReason).isEqualTo("observed-width-3840")
+ }
+
+ @Test
+ fun `repeated observation after promotion does not request another promotion`() {
+ val decision = LiveHlsBufferPromotionDecider.decide(
+ bufferMode = PlaybackBufferMode.AUTO,
+ resolvedStreamType = ResolvedStreamType.HLS,
+ isLive = true,
+ mediaAlreadyPromoted = true,
+ currentPolicyLabel = "auto-uhd-live-hls",
+ streamInfo = StreamInfo(url = "https://example.com/live/channel.m3u8"),
+ observedVideoFormat = VideoFormat(width = 3_840, height = 2_160),
+ compatibilityMode = false,
+ lowMemoryDevice = false
+ )
+
+ assertThat(decision).isNull()
+ }
+
+ @Test
+ fun `manual large mode does not request observed auto promotion`() {
+ val decision = LiveHlsBufferPromotionDecider.decide(
+ bufferMode = PlaybackBufferMode.LARGE,
+ resolvedStreamType = ResolvedStreamType.HLS,
+ isLive = true,
+ mediaAlreadyPromoted = false,
+ currentPolicyLabel = "large-live",
+ streamInfo = StreamInfo(url = "https://example.com/live/channel.m3u8"),
+ observedVideoFormat = VideoFormat(width = 3_840, height = 2_160),
+ compatibilityMode = false,
+ lowMemoryDevice = false
+ )
+
+ assertThat(decision).isNull()
+ }
+}
diff --git a/player/src/test/java/com/streamvault/player/playback/PlaybackBufferPoliciesTest.kt b/player/src/test/java/com/streamvault/player/playback/PlaybackBufferPoliciesTest.kt
index c7c59efa..17b4e77c 100644
--- a/player/src/test/java/com/streamvault/player/playback/PlaybackBufferPoliciesTest.kt
+++ b/player/src/test/java/com/streamvault/player/playback/PlaybackBufferPoliciesTest.kt
@@ -1,6 +1,9 @@
package com.streamvault.player.playback
import com.google.common.truth.Truth.assertThat
+import com.streamvault.domain.model.PlaybackBufferMode
+import com.streamvault.domain.model.StreamInfo
+import com.streamvault.domain.model.VideoFormat
import org.junit.Test
class PlaybackBufferPoliciesTest {
@@ -18,6 +21,150 @@ class PlaybackBufferPoliciesTest {
assertThat(policy.prioritizeTimeOverSizeThresholds).isTrue()
}
+ @Test
+ fun `small live hls uses production live buffer baseline`() {
+ val policy = PlaybackBufferPolicies.forPlayback(
+ resolvedStreamType = ResolvedStreamType.HLS,
+ compatibilityMode = false,
+ lowMemoryDevice = false,
+ bufferMode = PlaybackBufferMode.SMALL
+ )
+
+ assertThat(policy.label).isEqualTo("stable-live")
+ assertThat(policy.minBufferMs).isEqualTo(8_000)
+ assertThat(policy.maxBufferMs).isEqualTo(30_000)
+ assertThat(policy.playbackBufferMs).isEqualTo(1_500)
+ assertThat(policy.rebufferMs).isEqualTo(5_000)
+ assertThat(policy.targetBufferBytes).isEqualTo(-1)
+ }
+
+ @Test
+ fun `medium live hls uses deeper buffer and byte target`() {
+ val policy = PlaybackBufferPolicies.forPlayback(
+ resolvedStreamType = ResolvedStreamType.HLS,
+ compatibilityMode = false,
+ lowMemoryDevice = false,
+ bufferMode = PlaybackBufferMode.MEDIUM
+ )
+
+ assertThat(policy.label).isEqualTo("medium-live")
+ assertThat(policy.minBufferMs).isEqualTo(15_000)
+ assertThat(policy.maxBufferMs).isEqualTo(45_000)
+ assertThat(policy.playbackBufferMs).isEqualTo(3_000)
+ assertThat(policy.rebufferMs).isEqualTo(10_000)
+ assertThat(policy.targetBufferBytes).isEqualTo(32 * 1024 * 1024)
+ assertThat(policy.qualityReason).isEqualTo("user-medium")
+ }
+
+ @Test
+ fun `large live hls uses deepest buffer and byte target`() {
+ val policy = PlaybackBufferPolicies.forPlayback(
+ resolvedStreamType = ResolvedStreamType.HLS,
+ compatibilityMode = false,
+ lowMemoryDevice = false,
+ bufferMode = PlaybackBufferMode.LARGE
+ )
+
+ assertThat(policy.label).isEqualTo("large-live")
+ assertThat(policy.minBufferMs).isEqualTo(30_000)
+ assertThat(policy.maxBufferMs).isEqualTo(90_000)
+ assertThat(policy.playbackBufferMs).isEqualTo(5_000)
+ assertThat(policy.rebufferMs).isEqualTo(15_000)
+ assertThat(policy.targetBufferBytes).isEqualTo(64 * 1024 * 1024)
+ assertThat(policy.qualityReason).isEqualTo("user-large")
+ }
+
+ @Test
+ fun `auto live hls promotes to large when metadata hints uhd`() {
+ val policy = PlaybackBufferPolicies.forPlayback(
+ resolvedStreamType = ResolvedStreamType.HLS,
+ compatibilityMode = false,
+ lowMemoryDevice = false,
+ bufferMode = PlaybackBufferMode.AUTO,
+ streamInfo = StreamInfo(
+ url = "https://example.com/live/sports_2160p/index.m3u8",
+ title = "Sports 4K HDR",
+ containerExtension = "m3u8"
+ )
+ )
+
+ assertThat(policy.label).isEqualTo("auto-uhd-live-hls")
+ assertThat(policy.minBufferMs).isEqualTo(30_000)
+ assertThat(policy.maxBufferMs).isEqualTo(90_000)
+ assertThat(policy.playbackBufferMs).isEqualTo(5_000)
+ assertThat(policy.rebufferMs).isEqualTo(15_000)
+ assertThat(policy.targetBufferBytes).isEqualTo(64 * 1024 * 1024)
+ assertThat(policy.qualityReason).isEqualTo("metadata-2160p")
+ }
+
+ @Test
+ fun `auto live hls promotes to large when observed format is uhd`() {
+ val policy = PlaybackBufferPolicies.forPlayback(
+ resolvedStreamType = ResolvedStreamType.HLS,
+ compatibilityMode = false,
+ lowMemoryDevice = false,
+ bufferMode = PlaybackBufferMode.AUTO,
+ observedVideoFormat = VideoFormat(width = 3_840, height = 2_160)
+ )
+
+ assertThat(policy.label).isEqualTo("auto-uhd-live-hls")
+ assertThat(policy.targetBufferBytes).isEqualTo(64 * 1024 * 1024)
+ assertThat(policy.qualityReason).isEqualTo("observed-width-3840")
+ }
+
+ @Test
+ fun `auto live hls promotes to large when observed format is high bitrate`() {
+ val policy = PlaybackBufferPolicies.forPlayback(
+ resolvedStreamType = ResolvedStreamType.HLS,
+ compatibilityMode = false,
+ lowMemoryDevice = false,
+ bufferMode = PlaybackBufferMode.AUTO,
+ observedVideoFormat = VideoFormat(width = 1_920, height = 1_080, bitrate = 20_000_000)
+ )
+
+ assertThat(policy.label).isEqualTo("auto-uhd-live-hls")
+ assertThat(policy.targetBufferBytes).isEqualTo(64 * 1024 * 1024)
+ assertThat(policy.qualityReason).isEqualTo("observed-bitrate-20000000")
+ }
+
+ @Test
+ fun `auto live hls promotes to large when observed format is hdr`() {
+ val policy = PlaybackBufferPolicies.forPlayback(
+ resolvedStreamType = ResolvedStreamType.HLS,
+ compatibilityMode = false,
+ lowMemoryDevice = false,
+ bufferMode = PlaybackBufferMode.AUTO,
+ observedVideoFormat = VideoFormat(width = 1_920, height = 1_080, isHdr = true)
+ )
+
+ assertThat(policy.label).isEqualTo("auto-uhd-live-hls")
+ assertThat(policy.targetBufferBytes).isEqualTo(64 * 1024 * 1024)
+ assertThat(policy.qualityReason).isEqualTo("observed-hdr")
+ }
+
+ @Test
+ fun `auto live hls caps uhd promotion to medium on low memory devices`() {
+ val policy = PlaybackBufferPolicies.forPlayback(
+ resolvedStreamType = ResolvedStreamType.HLS,
+ compatibilityMode = false,
+ lowMemoryDevice = true,
+ bufferMode = PlaybackBufferMode.AUTO,
+ streamInfo = StreamInfo(
+ url = "https://example.com/live/uhd/index.m3u8",
+ title = "Nature UHD"
+ )
+ )
+
+ assertThat(policy.label).isEqualTo("auto-uhd-live-hls-capped")
+ assertThat(policy.minBufferMs).isEqualTo(15_000)
+ assertThat(policy.maxBufferMs).isEqualTo(45_000)
+ assertThat(policy.playbackBufferMs).isEqualTo(3_000)
+ assertThat(policy.rebufferMs).isEqualTo(10_000)
+ assertThat(policy.targetBufferBytes).isEqualTo(32 * 1024 * 1024)
+ assertThat(policy.lowMemoryCapped).isTrue()
+ assertThat(policy.qualityReason).isEqualTo("metadata-uhd")
+ }
+
@Test
fun `compatibility live uses larger live buffer`() {
val policy = PlaybackBufferPolicies.forPlayback(isLive = true, compatibilityMode = true)
@@ -31,6 +178,21 @@ class PlaybackBufferPoliciesTest {
assertThat(policy.prioritizeTimeOverSizeThresholds).isTrue()
}
+ @Test
+ fun `compatibility live hls in auto can still promote from metadata`() {
+ val policy = PlaybackBufferPolicies.forPlayback(
+ resolvedStreamType = ResolvedStreamType.HLS,
+ compatibilityMode = true,
+ lowMemoryDevice = false,
+ bufferMode = PlaybackBufferMode.AUTO,
+ streamInfo = StreamInfo(url = "https://example.com/live/4k/index.m3u8")
+ )
+
+ assertThat(policy.label).isEqualTo("auto-uhd-live-hls")
+ assertThat(policy.minBufferMs).isEqualTo(30_000)
+ assertThat(policy.targetBufferBytes).isEqualTo(64 * 1024 * 1024)
+ }
+
@Test
fun `mpeg ts live prioritizes playable time over byte target`() {
val policy = PlaybackBufferPolicies.forPlayback(
@@ -47,6 +209,37 @@ class PlaybackBufferPoliciesTest {
assertThat(policy.prioritizeTimeOverSizeThresholds).isTrue()
}
+ @Test
+ fun `mpeg ts live remains unchanged in auto even with uhd metadata`() {
+ val policy = PlaybackBufferPolicies.forPlayback(
+ resolvedStreamType = ResolvedStreamType.MPEG_TS_LIVE,
+ compatibilityMode = false,
+ lowMemoryDevice = false,
+ bufferMode = PlaybackBufferMode.AUTO,
+ streamInfo = StreamInfo(url = "https://example.com/live/4k/channel.ts")
+ )
+
+ assertThat(policy.label).isEqualTo("mpeg-ts-live")
+ assertThat(policy.minBufferMs).isEqualTo(5_000)
+ assertThat(policy.maxBufferMs).isEqualTo(10_000)
+ assertThat(policy.targetBufferBytes).isEqualTo(16 * 1024 * 1024)
+ }
+
+ @Test
+ fun `mpeg ts live uses medium only when user selects medium`() {
+ val policy = PlaybackBufferPolicies.forPlayback(
+ resolvedStreamType = ResolvedStreamType.MPEG_TS_LIVE,
+ compatibilityMode = false,
+ lowMemoryDevice = false,
+ bufferMode = PlaybackBufferMode.MEDIUM
+ )
+
+ assertThat(policy.label).isEqualTo("medium-live")
+ assertThat(policy.minBufferMs).isEqualTo(15_000)
+ assertThat(policy.maxBufferMs).isEqualTo(45_000)
+ assertThat(policy.targetBufferBytes).isEqualTo(32 * 1024 * 1024)
+ }
+
@Test
fun `vod uses deeper movie buffer`() {
val policy = PlaybackBufferPolicies.forPlayback(isLive = false, compatibilityMode = false)