0.123.0 (versionCode 315): frame-rate matching and AVI, each off until switched on

Frame-rate matching sets the TV's display mode to a whole multiple of the
programme's frame rate (23.976 film at 23.976 Hz, 25 fps at 50 Hz), keeping the
resolution, and hands back to the TV's own choice when the programme closes.
AVI joins the direct-play containers only when its switch is on. Both are set
from adb (orbit_frame_rate, orbit_avi) and default off, so 0.123.0 behaves as
0.122.1 until then. Tests use the downstairs TV's real mode list.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-11-09 14:08:10 +00:00
co-authored by Claude Opus 5.5
parent b92fe53237
commit 58d11458fe
6 changed files with 131 additions and 3 deletions
@@ -1,6 +1,9 @@
package tv.orbit.classic
internal const val DirectVideoContainers = "mp4,mkv,mov,m4v,webm,ts,mpegts,3gp"
internal const val DirectVideoContainersBase = "mp4,mkv,mov,m4v,webm,ts,mpegts,3gp"
/** The containers Orbit plays directly; AVI only when its switch is on (PlayerSwitches, 9 November 2026). */
internal val DirectVideoContainers: String get() = if (PlayerSwitches.avi) "$DirectVideoContainersBase,avi" else DirectVideoContainersBase
internal fun supportedDirectContainer(value: String): String? = value.trim().lowercase(java.util.Locale.ROOT)
.takeIf { it in DirectVideoContainers.split(",") }
@@ -300,6 +300,20 @@ internal fun EmbyPlaybackDialog(session: EmbySampleSession, plan: EmbyPlaybackPl
}
}
DisposableEffect(player) { onDispose { watchAudioClock(false) } }
// Frame-rate matching (9 November 2026; off unless switched on): the TV's refresh follows the programme's, and goes
// back to the TV's own choice when the programme closes.
DisposableEffect(player) {
val window = generateSequence(context) { (it as? android.content.ContextWrapper)?.baseContext }.filterIsInstance<android.app.Activity>().firstOrNull()?.window
val matcher = object : Player.Listener {
override fun onTracksChanged(tracks: Tracks) {
if (!PlayerSwitches.frameRate || window == null) return
val fps = tracks.groups.firstOrNull { it.type == C.TRACK_TYPE_VIDEO && it.isSelected }?.getTrackFormat(0)?.frameRate ?: return
FrameRateMatch.apply(window, fps)
}
}
player.addListener(matcher)
onDispose { player.removeListener(matcher); window?.let(FrameRateMatch::reset) }
}
val covered = ident != null
// Luna's goodnight: the programme fades out beneath her, and back up if a button keeps Orbit on.
LaunchedEffect(player, SleepTimer.goodnight) {
@@ -70,6 +70,9 @@ class MainActivity : ComponentActivity() {
if (intent?.getBooleanExtra("orbit_read_evidence", false) == true) EvidenceRequest.pending = true
// Provider contract, step 3: the catalogue switch and the read-only shadow comparison.
when (intent?.getStringExtra("orbit_provider_catalogue")) { "on" -> ProviderSwitches.setCatalogue(this, true); "off" -> ProviderSwitches.setCatalogue(this, false) }
// Player improvements (9 November 2026): frame-rate matching and AVI, each off until switched on.
when (intent?.getStringExtra("orbit_frame_rate")) { "on" -> PlayerSwitches.setFrameRate(this, true); "off" -> PlayerSwitches.setFrameRate(this, false) }
when (intent?.getStringExtra("orbit_avi")) { "on" -> PlayerSwitches.setAvi(this, true); "off" -> PlayerSwitches.setAvi(this, false) }
if (intent?.hasExtra("orbit_shadow_catalogue") == true) CatalogueShadow.pending = intent.getIntExtra("orbit_shadow_catalogue", 5)
}
override fun onNewIntent(intent: android.content.Intent) { super.onNewIntent(intent); setIntent(intent); readAdbRequests(intent) }
@@ -83,6 +86,7 @@ class MainActivity : ComponentActivity() {
// The guide's logos, decoded ahead on a background thread so the guide opens with them ready.
Thread({ Pictures.warmLogos(resources) }, "orbit-logos").apply { priority = Thread.MIN_PRIORITY }.start()
ProviderSwitches.load(this)
PlayerSwitches.load(this)
readAdbRequests(intent)
// The hand-run playback test opens over Orbit, which stops in the background as it would for any other app, and comes back when it ends.
intent?.getStringExtra("orbit_play_test")?.takeIf(EmbyClient::validId)?.let { item ->
@@ -0,0 +1,58 @@
package tv.orbit.classic
import android.content.Context
import android.view.Window
import kotlin.math.abs
import kotlin.math.roundToInt
/**
* Player improvements (9 November 2026), each off until Paul turns it on, from adb only for now:
* am start -n tv.orbit.classic/.MainActivity --es orbit_frame_rate on|off --es orbit_avi on|off
* - Frame-rate matching: the TV's refresh rate follows the programme's (a 23.976 film at 23.976 Hz, a 25 fps UK show at
* 50 Hz), so motion is smooth instead of judder. The TV may blank for a second or two when it switches.
* - AVI: AVI files play directly (Media3 reads AVI; this TV decodes MPEG-4/XviD and MP3). Off, they stay unplayable
* and out of channel plans, as today; on, new plans may include them. Schedules already planned are not changed.
*/
internal object PlayerSwitches {
@Volatile var frameRate = false
@Volatile var avi = false
private const val FRAME_RATE = "player_frame_rate"
private const val AVI = "player_avi"
private fun prefs(context: Context) = context.getSharedPreferences("orbit_settings", Context.MODE_PRIVATE)
fun load(context: Context) { prefs(context).let { frameRate = it.getBoolean(FRAME_RATE, false); avi = it.getBoolean(AVI, false) } }
fun setFrameRate(context: Context, on: Boolean) { frameRate = on; prefs(context).edit().putBoolean(FRAME_RATE, on).apply(); log("frameRate", on) }
fun setAvi(context: Context, on: Boolean) { avi = on; prefs(context).edit().putBoolean(AVI, on).apply(); log("avi", on) }
private fun log(name: String, on: Boolean) = android.util.Log.i("OrbitPlayer", "$name switch=${if (on) "on" else "off"}")
}
internal data class DisplayModeInfo(val id: Int, val width: Int, val height: Int, val refreshHz: Float)
internal object FrameRateMatch {
/**
* The display mode for a programme at [fps]: same resolution as now, refresh a whole multiple of the frame rate, the
* highest such (25 fps prefers 50 Hz to 25 Hz). Null when the current mode already fits, the rate is unknown, or no
* mode fits. 23.976 and 24 are told apart (a 0.01 fps tolerance), since showing one at the other judders once a minute.
*/
fun pick(modes: List<DisplayModeInfo>, current: DisplayModeInfo, fps: Float): Int? {
if (fps.isNaN() || fps !in 10f..121f) return null
fun fits(refresh: Float): Boolean { val k = (refresh / fps).roundToInt(); return k >= 1 && abs(refresh / k - fps) < 0.01f }
if (fits(current.refreshHz)) return null
return modes.filter { it.width == current.width && it.height == current.height && fits(it.refreshHz) }.maxByOrNull { it.refreshHz }?.id
}
fun apply(window: Window, fps: Float) {
val display = window.decorView.display ?: return
val modes = display.supportedModes.map { DisplayModeInfo(it.modeId, it.physicalWidth, it.physicalHeight, it.refreshRate) }
val now = display.mode.let { DisplayModeInfo(it.modeId, it.physicalWidth, it.physicalHeight, it.refreshRate) }
val id = pick(modes, now, fps) ?: return
if (window.attributes.preferredDisplayModeId == id) return
window.attributes = window.attributes.also { it.preferredDisplayModeId = id }
android.util.Log.i("OrbitPlayer", "frameRate fps=$fps from=${now.refreshHz} mode=$id")
}
/** Back to the TV's own choice, when the programme closes. */
fun reset(window: Window) {
if (window.attributes.preferredDisplayModeId == 0) return
window.attributes = window.attributes.also { it.preferredDisplayModeId = 0 }
}
}