feat(exoplayer): let the read-ahead buffer depth be chosen instead of fixed at 50s

ExoPlayer's DefaultLoadControl was built with hard-coded durations picked from
one memory tier, so read-ahead stopped at 50s on any device reporting 2GB or
less free, with no way to raise it. On hardware where mpv cannot render at all
that ceiling is the whole buffer budget.

Playback Buffer offers Auto, Large and Extra Large. The durations are taken
from jellyfin-androidtv and jellyfin-android so the same words mean the same
thing across Jellyfin clients; Auto keeps the memory-tiered values that
shipped. Named tiers rather than a duration because a duration would be a
promise the load control cannot keep: prioritizeTimeOverSizeThresholds is
disabled, so targetBufferBytes stops the loader even below minBufferMs and the
byte cap binds first above roughly 23 Mbit/s.

The tier crosses the method channel as a string and resolves in the core,
where an unrecognised name falls back to Auto. LoadControlPolicy clamps the
resulting pair: media3 validates the ordering with Guava Preconditions, an
unconditional throw R8 does not elide, so a bad pair would be an
IllegalArgumentException out of player construction rather than a bad buffer.

The two play-start thresholds stay fixed even though the Jellyfin tiers move
them. BufferingStallPolicy.MIN_BUFFER_AHEAD_MS is a const derived from
BUFFER_FOR_PLAYBACK_AFTER_REBUFFER_MS, so a runtime value there would make the
stall watchdog indict a player that is obeying its own load control.

That leaves the byte target as a second, often smaller ceiling, and nothing
surfaced either. The resolved values now reach getStats, and the overlay's
Buffer section gains a Cache Limit row reading "120s / 128MB" next to the
buffered-ahead duration, so a tier that appears to do nothing on a
high-bitrate file explains itself.

close #1816
This commit is contained in:
edde746
2026-08-07 08:43:47 +02:00
parent f5ccaab3ab
commit 660e375248
37 changed files with 539 additions and 25 deletions
+16
View File
@@ -83,6 +83,16 @@ extension DvConversionModePreferenceNativeValue on DvConversionModePreference {
};
}
enum PlaybackBufferTier { auto, large, extraLarge }
extension PlaybackBufferTierNativeValue on PlaybackBufferTier {
String get nativeValue => switch (this) {
PlaybackBufferTier.auto => 'auto',
PlaybackBufferTier.large => 'large',
PlaybackBufferTier.extraLarge => 'extra_large',
};
}
const String _bufferSizeMigratedKey = 'buffer_size_migrated_to_auto';
const String _legacyUseSeasonPosterKey = 'use_season_poster';
const String _legacyMpvConfigEntriesKey = 'mpv_config_entries';
@@ -504,6 +514,11 @@ class SettingsService extends BaseSharedPreferencesService {
static const exitFullscreenOnPlayerClose = BoolPref('exit_fullscreen_on_player_close');
static const bufferSize = _BufferSizePref();
static const playbackBufferTier = EnumPref<PlaybackBufferTier>(
'playback_buffer_tier',
values: PlaybackBufferTier.values,
defaultValue: PlaybackBufferTier.auto,
);
static const libraryDensity = _LibraryDensityPref();
static const automotiveUiScale = _AutomotiveUiScalePref();
static const tvCornerSpotlightBackdrop = BoolPref('tv_corner_spotlight_backdrop');
@@ -932,6 +947,7 @@ class SettingsService extends BaseSharedPreferencesService {
themeMode,
videoPlayerNavigationEnabled,
bufferSize,
playbackBufferTier,
libraryDensity,
automotiveUiScale,
tvCornerSpotlightBackdrop,