Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -288,6 +288,9 @@ class AndroidPlayerSettingsStore(
?: LetterboxExpansion.Default
}

override val trueBlackBarsFlow: Flow<Boolean> =
profileScopedFlow(false) { p, s -> p.boolFor(s, PlaybackSettingsKeys.TrueBlackBars, false) }

override val downloadsWifiOnlyFlow: Flow<Boolean> =
profileScopedFlow(true) { p, s -> p.boolFor(s, PlaybackSettingsKeys.DownloadsWifiOnly, true) }

Expand Down Expand Up @@ -462,6 +465,9 @@ class AndroidPlayerSettingsStore(
writeStringLocal(PlaybackSettingsKeys.LetterboxExpansion, safe)
}

override suspend fun setTrueBlackBars(value: Boolean) =
writeBoolLocal(PlaybackSettingsKeys.TrueBlackBars, value)

override suspend fun setDownloadsWifiOnly(value: Boolean) =
writeBoolLocal(PlaybackSettingsKeys.DownloadsWifiOnly, value)

Expand Down Expand Up @@ -722,6 +728,7 @@ class AndroidPlayerSettingsStore(
it.remove(booleanPreferencesKey(scope.keyPrefix + PlaybackSettingsKeys.PictureInPictureEnabled))
it.remove(booleanPreferencesKey(scope.keyPrefix + PlaybackSettingsKeys.ForceHdrPassthrough))
it.remove(stringPreferencesKey(scope.keyPrefix + PlaybackSettingsKeys.LetterboxExpansion))
it.remove(booleanPreferencesKey(scope.keyPrefix + PlaybackSettingsKeys.TrueBlackBars))
it.remove(intPreferencesKey(scope.keyPrefix + PlaybackSettingsKeys.ResumeRewindSeconds))
it.remove(intPreferencesKey(scope.keyPrefix + PlaybackSettingsKeys.PassOutThreshold))
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,13 @@ interface PlayerSettingsStore {
val letterboxExpansionFlow: Flow<String>
get() = flowOf(LetterboxExpansion.Default)

/**
* See [org.siloserver.silo.model.settings.PlaybackSettingsKeys.TrueBlackBars].
* Defaulted for the same reason as [letterboxExpansionFlow].
*/
val trueBlackBarsFlow: Flow<Boolean>
get() = flowOf(false)

/** Per-profile preference for restricting downloads to unmetered (Wi-Fi)
* networks. Default true. Consumed by [DownloadEnqueuer] at enqueue
* time to set the WorkManager NetworkType constraint. */
Expand Down Expand Up @@ -157,6 +164,7 @@ interface PlayerSettingsStore {
suspend fun setPictureInPictureEnabled(value: Boolean)
suspend fun setForceHdrPassthrough(value: Boolean)
suspend fun setLetterboxExpansion(value: String) = Unit
suspend fun setTrueBlackBars(value: Boolean) = Unit
suspend fun setDownloadsWifiOnly(value: Boolean)
suspend fun setKeepWatchedDownloads(value: Boolean)
suspend fun setDefaultDownloadQuality(value: String)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1335,6 +1335,7 @@ fun TvAppNavigation(
initialSubtitleAutoResolved = subtitleAutoResolved,
autoAdvanceCount = autoAdvanceCount,
episodeSelectionHandoff = episodeSelectionHandoff,
navigationSettled = !transition.isRunning,
onExit = { navController.popBackStack() },
// Host Stop: back to the room's lobby in place of the player.
// The membership is kept, so the lobby follows the next Start.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,9 +51,11 @@ import androidx.compose.runtime.withFrameNanos
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.draw.clip
import androidx.compose.ui.draw.drawBehind
import androidx.compose.ui.focus.FocusRequester
import androidx.compose.ui.focus.focusRequester
import androidx.compose.ui.focus.onFocusChanged
import androidx.compose.ui.graphics.BlendMode
import androidx.compose.ui.graphics.Brush
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.input.key.onPreviewKeyEvent
Expand Down Expand Up @@ -275,6 +277,9 @@ fun TvPlayerScreen(
// Consecutive auto-advance count (pass-out protection); 0 = manual start.
autoAdvanceCount: Int = 0,
episodeSelectionHandoff: org.siloserver.silo.common.player.video.EpisodeSelectionHandoff? = null,
// False while Navigation fades this screen in or out. True Black Bars
// keeps the black plate meanwhile (see `clearBars`).
navigationSettled: Boolean = true,
// Scope the ViewModel key by fileId too so switching 4K <-> 1080p on
// the detail screen and replaying actually spins up a fresh player
// session instead of reusing the cached one bound to the first fileId.
Expand Down Expand Up @@ -353,6 +358,7 @@ fun TvPlayerScreen(
val hdrEnabled by viewModel.hdrEnabled.collectAsState()
val dolbyVisionEnabled by viewModel.dolbyVisionEnabled.collectAsState()
val forceHdrPassthrough by viewModel.forceHdrPassthrough.collectAsState()
val trueBlackBars by viewModel.trueBlackBars.collectAsState()
val dolbyVisionSwitchInFlight by viewModel.dolbyVisionSwitchInFlight.collectAsState()
val subtitleSearch by viewModel.subtitleSearch.collectAsState()
val aiTranslate by viewModel.aiTranslate.collectAsState()
Expand Down Expand Up @@ -394,6 +400,9 @@ fun TvPlayerScreen(
// the inflated subtitleView after the AndroidView factory runs. Mirrors
// the phone PlayerScreen's `playerViewRef` pattern.
var playerViewRef by remember { mutableStateOf<PlayerView?>(null) }
// Latched on the first rendered frame and kept for this screen's life, so
// remounts (subtitle changes, recovery) don't repaint the bars.
var pictureShown by remember { mutableStateOf(false) }
var idleOverlayFocusRequest by remember { mutableStateOf(TvIdleOverlayFocusRequest()) }
val cleanPlaybackSeekScope = rememberCoroutineScope()
var pendingCleanSeekDirection by remember { mutableStateOf(0) }
Expand Down Expand Up @@ -1416,6 +1425,7 @@ fun TvPlayerScreen(
) {
val mountToken = eventTime.videoMountToken() ?: return
if (mountToken != viewModel.uiState.value.transportMountNonce) return
pictureShown = true
startupStallDetector.onFirstFrameRendered()
postResumeStallDetector.onFirstFrameRendered()
viewModel.onFirstVideoFrameRendered(mountToken)
Expand Down Expand Up @@ -1925,10 +1935,26 @@ fun TvPlayerScreen(
}
}

// True Black Bars (silo-android#475): once the picture is up, clear the
// player to transparent instead of painting it black, so anything not drawn
// over (the bars, Up Next, an error) shows the output's own black. Clearing,
// not just skipping the plate, also wipes the window's theme background and
// stale pixels nothing else repaints, such as the HUD after it hides. The
// plate stays until the first frame, and while Navigation fades the
// screen: the fade draws it into a layer, where clearing would let the
// other screen show through.
val clearBars = trueBlackBars && pictureShown && navigationSettled

Box(
modifier = Modifier
.fillMaxSize()
.background(Color.Black)
.then(
if (clearBars) {
Modifier.drawBehind { drawRect(Color.Transparent, blendMode = BlendMode.Clear) }

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Expose a transparent host surface before clearing the bars

When True Black Bars is enabled, this Clear draw still targets an opaque activity surface: Theme.SiloTv inherits the non-translucent Material theme and sets android:windowBackground to the fully opaque #FF141417. Android therefore discards the cleared alpha outside the SurfaceView's own transparent region, leaving black pixels in the app layer rather than exposing the output beneath it. On the affected HDR devices, the toggle consequently cannot change the compositing path that produces grey bars; the player must first provide a genuinely transparent window/surface region for the letterbox area.

Useful? React with 👍 / 👎.

} else {
Modifier.background(Color.Black)
},
)
.onGloballyPositioned { playerRootBounds = it.videoViewportBounds() }
.focusRequester(rootFocus)
.onFocusChanged { playerRootHasFocus = it.isFocused }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1512,6 +1512,8 @@ class TvPlayerViewModel(
.stateIn(viewModelScope, SharingStarted.Eagerly, true)
val forceHdrPassthrough: StateFlow<Boolean> = playerSettingsStore.forceHdrPassthroughFlow
.stateIn(viewModelScope, SharingStarted.Eagerly, false)
val trueBlackBars: StateFlow<Boolean> = playerSettingsStore.trueBlackBarsFlow
.stateIn(viewModelScope, SharingStarted.Eagerly, false)
private val dvProfile7Hdr10Fallback: StateFlow<Boolean> =
playerSettingsStore.dvProfile7HDR10FallbackFlow
.stateIn(viewModelScope, SharingStarted.Eagerly, false)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -283,6 +283,7 @@ fun TvSettingsScreen(
onDolbyVisionEnabledChanged = viewModel::onDolbyVisionEnabledChanged,
onDvProfile7HDR10FallbackChanged = viewModel::onDvProfile7HDR10FallbackChanged,
onForceHdrPassthroughChanged = viewModel::onForceHdrPassthroughChanged,
onTrueBlackBarsChanged = viewModel::onTrueBlackBarsChanged,
onResumeRewindSecondsChanged = viewModel::onResumeRewindSecondsChanged,
onPassOutThresholdChanged = viewModel::onPassOutThresholdChanged,
onNextUpPromptSecondsChanged = viewModel::onNextUpPromptSecondsChanged,
Expand Down Expand Up @@ -430,6 +431,7 @@ private fun SettingsSplitLayout(
onDolbyVisionEnabledChanged: (Boolean) -> Unit,
onDvProfile7HDR10FallbackChanged: (Boolean) -> Unit,
onForceHdrPassthroughChanged: (Boolean) -> Unit,
onTrueBlackBarsChanged: (Boolean) -> Unit,
onResumeRewindSecondsChanged: (Int) -> Unit,
onPassOutThresholdChanged: (Int) -> Unit,
onNextUpPromptSecondsChanged: (Int) -> Unit,
Expand Down Expand Up @@ -509,6 +511,7 @@ private fun SettingsSplitLayout(
onDolbyVisionEnabledChanged = onDolbyVisionEnabledChanged,
onDvProfile7HDR10FallbackChanged = onDvProfile7HDR10FallbackChanged,
onForceHdrPassthroughChanged = onForceHdrPassthroughChanged,
onTrueBlackBarsChanged = onTrueBlackBarsChanged,
onResumeRewindSecondsChanged = onResumeRewindSecondsChanged,
onPassOutThresholdChanged = onPassOutThresholdChanged,
onNextUpPromptSecondsChanged = onNextUpPromptSecondsChanged,
Expand Down Expand Up @@ -790,6 +793,7 @@ private fun SettingsDetailPane(
onDolbyVisionEnabledChanged: (Boolean) -> Unit,
onDvProfile7HDR10FallbackChanged: (Boolean) -> Unit,
onForceHdrPassthroughChanged: (Boolean) -> Unit,
onTrueBlackBarsChanged: (Boolean) -> Unit,
onResumeRewindSecondsChanged: (Int) -> Unit,
onPassOutThresholdChanged: (Int) -> Unit,
onNextUpPromptSecondsChanged: (Int) -> Unit,
Expand Down Expand Up @@ -844,6 +848,7 @@ private fun SettingsDetailPane(
onDolbyVisionEnabledChanged = onDolbyVisionEnabledChanged,
onDvProfile7HDR10FallbackChanged = onDvProfile7HDR10FallbackChanged,
onForceHdrPassthroughChanged = onForceHdrPassthroughChanged,
onTrueBlackBarsChanged = onTrueBlackBarsChanged,
onResumeRewindSecondsChanged = onResumeRewindSecondsChanged,
onPassOutThresholdChanged = onPassOutThresholdChanged,
onNextUpPromptSecondsChanged = onNextUpPromptSecondsChanged,
Expand Down Expand Up @@ -1131,6 +1136,7 @@ private fun TvPlaybackSettingsPane(
onDolbyVisionEnabledChanged: (Boolean) -> Unit,
onDvProfile7HDR10FallbackChanged: (Boolean) -> Unit,
onForceHdrPassthroughChanged: (Boolean) -> Unit,
onTrueBlackBarsChanged: (Boolean) -> Unit,
onResumeRewindSecondsChanged: (Int) -> Unit,
onPassOutThresholdChanged: (Int) -> Unit,
onNextUpPromptSecondsChanged: (Int) -> Unit,
Expand Down Expand Up @@ -1199,16 +1205,27 @@ private fun TvPlaybackSettingsPane(
checked = state.forceHdrPassthrough,
onCheckedChange = onForceHdrPassthroughChanged,
)
// Android TV only: tvOS composites its own letterbox, so the
// Apple pane has no counterpart (silo-android#475).
SettingsToggleRow(
label = "True Black Bars",
checked = state.trueBlackBars,
onCheckedChange = onTrueBlackBarsChanged,
)
// tvOS footer: the chosen preset's description, then the
// caveat for the one control here that can misbehave.
// caveat for Force HDR Passthrough. The True Black Bars
// sentence is Android TV's own.
SettingsFooterText(
text = (
QualityPresets.presetFor(state.qualityResolution, state.maxBitrateKbps)?.description
?: "${QualityPresets.describe(state.qualityResolution, state.maxBitrateKbps)}."
) + " Force HDR Passthrough allows HDR playback when this TV doesn't report " +
"support. It does not force the HDMI output into HDR; Android may still convert " +
"the picture to SDR. Enable it only if you've confirmed your TV supports the " +
"source format. Unsupported formats may produce a black screen or incorrect colors.",
"source format. Unsupported formats may produce a black screen or incorrect colors." +
" True Black Bars stops Silo from drawing the bars around the picture during " +
"playback. Try it if they look grey in HDR or Dolby Vision, and turn it off again " +
"if they get lighter or show a thin line.",
)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,7 @@ class TvSettingsViewModel(
val subtitleMatchesDevice: Boolean = false,
val dvProfile7HDR10Fallback: Boolean = true,
val forceHdrPassthrough: Boolean = false,
val trueBlackBars: Boolean = false,
val autoSkipCredits: Boolean = false,
// Seconds to skip back on resume (0 = off); consecutive auto-advances
// before the "Still watching?" prompt (0 = off).
Expand Down Expand Up @@ -395,6 +396,11 @@ class TvSettingsViewModel(
_uiState.update { it.copy(forceHdrPassthrough = value) }
}
}
viewModelScope.launch {
playerSettingsStore.trueBlackBarsFlow.collect { value ->
_uiState.update { it.copy(trueBlackBars = value) }
}
}
viewModelScope.launch {
playerSettingsStore.subtitleMatchesDeviceFlow.collect { value ->
_uiState.update { it.copy(subtitleMatchesDevice = value) }
Expand Down Expand Up @@ -660,6 +666,10 @@ class TvSettingsViewModel(
viewModelScope.launch { playerSettingsStore.setForceHdrPassthrough(value) }
}

fun onTrueBlackBarsChanged(value: Boolean) {
viewModelScope.launch { playerSettingsStore.setTrueBlackBars(value) }
}

fun onIntroSkipModeChanged(value: IntroSkipMode) {
viewModelScope.launch { playerSettingsStore.setIntroSkipMode(value) }
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,21 @@ object PlaybackSettingsKeys {
*/
const val ForceHdrPassthrough = "player.force_hdr_passthrough"

/**
* Local-only per-profile TV setting, off by default. Clears the bars
* around a picture that doesn't fill the screen to transparent instead of
* painting them opaque black.
*
* Some devices composite the app window's SDR black above reference black
* while HDR or Dolby Vision is on, so painted bars glow grey (Onn 4K Pro,
* Sony TVs). Others do the reverse and lift the transparent area (Fire TV,
* Google TV Streamer). Neither the chip vendor nor any platform signal
* tells them apart (silo-android#475), so the user picks what looks right
* on their device. It describes this device's compositor, not a playback
* preference, so this never enters [DeviceSettings].
*/
const val TrueBlackBars = "player.true_black_bars"

val DeviceSettings = listOf(
PreferredQuality,
MaxBitrateKbps,
Expand Down
Loading