0.95.4: decode Dolby and DTS on the box and send plain sound to the TV unless an amplifier is set, ending DTS dropouts
Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -0,0 +1,44 @@
|
||||
package tv.orbit.classic
|
||||
|
||||
import android.content.Context
|
||||
import android.media.AudioFormat
|
||||
import androidx.media3.exoplayer.DefaultRenderersFactory
|
||||
import androidx.media3.exoplayer.audio.AudioCapabilities
|
||||
import androidx.media3.exoplayer.audio.AudioSink
|
||||
import androidx.media3.exoplayer.audio.DefaultAudioSink
|
||||
|
||||
/**
|
||||
* How programme sound leaves the box. Paul's set-up (3 November 2026) is the TV's own speakers, no amplifier: the TV
|
||||
* claims DTS over HDMI, so ExoPlayer sent DTS undecoded, ignoring the box's "surround sound: never" setting, and the TV
|
||||
* cut it in and out every few seconds. Unless the viewer turns on "Send surround sound to an amplifier", Orbit decodes
|
||||
* Dolby and DTS on the box (it has its own decoders) and sends plain sound. TrueHD, which this box can't decode,
|
||||
* still goes out undecoded if the TV accepts it, rather than going silent.
|
||||
*/
|
||||
internal const val PASSTHROUGH_KEPT = AudioFormat.ENCODING_DOLBY_TRUEHD
|
||||
|
||||
/** What the sound sink may send undecoded. PCM always; TrueHD only where the connection takes it. */
|
||||
@androidx.annotation.OptIn(androidx.media3.common.util.UnstableApi::class)
|
||||
@Suppress("DEPRECATION")
|
||||
internal fun plainSoundCapabilities(device: AudioCapabilities): AudioCapabilities =
|
||||
AudioCapabilities(plainSoundEncodings(device::supportsEncoding), device.maxChannelCount)
|
||||
|
||||
/** The encodings sent undecoded, given which the connection accepts. */
|
||||
internal fun plainSoundEncodings(accepts: (Int) -> Boolean): IntArray =
|
||||
(listOf(AudioFormat.ENCODING_PCM_16BIT) + listOf(PASSTHROUGH_KEPT).filter(accepts)).toIntArray()
|
||||
|
||||
/** The renderers every programme player uses, so the choice of sound output is the same everywhere. */
|
||||
@androidx.annotation.OptIn(androidx.media3.common.util.UnstableApi::class)
|
||||
internal fun programmeRenderers(context: Context): DefaultRenderersFactory {
|
||||
val toAmplifier = OrbitSettings(context).surroundToAmplifier
|
||||
return object : DefaultRenderersFactory(context) {
|
||||
@Suppress("DEPRECATION")
|
||||
override fun buildAudioSink(context: Context, enableFloatOutput: Boolean, enableAudioOutputPlaybackParams: Boolean): AudioSink? {
|
||||
if (toAmplifier) return super.buildAudioSink(context, enableFloatOutput, enableAudioOutputPlaybackParams)
|
||||
return DefaultAudioSink.Builder(context)
|
||||
.setAudioCapabilities(plainSoundCapabilities(AudioCapabilities.getCapabilities(context)))
|
||||
.setEnableFloatOutput(enableFloatOutput)
|
||||
.setEnableAudioTrackPlaybackParams(enableAudioOutputPlaybackParams)
|
||||
.build()
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -66,7 +66,7 @@ internal class HttpsEmbyTransport(internal val deviceId: String = UUID.randomUUI
|
||||
connection.connectTimeout = 10_000
|
||||
connection.readTimeout = request.readTimeoutMs ?: if (request.path == "/Sessions/Logout") 5_000 else 15_000
|
||||
connection.setRequestProperty("Accept", "application/json")
|
||||
connection.setRequestProperty("X-Emby-Authorization", "Emby Client=\"Orbit TV\", Device=\"Orbit TV\", DeviceId=\"$deviceId\", Version=\"0.95.3\"")
|
||||
connection.setRequestProperty("X-Emby-Authorization", "Emby Client=\"Orbit TV\", Device=\"Orbit TV\", DeviceId=\"$deviceId\", Version=\"0.95.4\"")
|
||||
request.token?.let { connection.setRequestProperty("X-Emby-Token", it) }
|
||||
if (request.method == "POST") {
|
||||
val bytes = request.body.orEmpty().toByteArray(Charsets.UTF_8)
|
||||
|
||||
@@ -97,7 +97,7 @@ internal fun EmbyPlaybackDialog(session: EmbySampleSession, plan: EmbyPlaybackPl
|
||||
val player = remember(session, plan) {
|
||||
if (runningPlayer != null) return@remember runningPlayer
|
||||
val factory = DataSource.Factory { SecureMediaDataSource(session) }
|
||||
ExoPlayer.Builder(context).setMediaSourceFactory(DefaultMediaSourceFactory(factory))
|
||||
ExoPlayer.Builder(context, programmeRenderers(context)).setMediaSourceFactory(DefaultMediaSourceFactory(factory))
|
||||
.setSeekBackIncrementMs(10_000).setSeekForwardIncrementMs(10_000).build().apply {
|
||||
setMediaItem(channelMediaItem(plan))
|
||||
if (scheduled != null) seekTo(scheduled.programme.offsetAt(scheduled.nowMs()))
|
||||
|
||||
@@ -118,7 +118,7 @@ private fun GuideLivePlayer(session: EmbySampleSession, plan: EmbyPlaybackPlan,
|
||||
val player = remember(session, plan) {
|
||||
if (runningPlayer != null) return@remember runningPlayer
|
||||
val factory = DataSource.Factory { SecureMediaDataSource(session) }
|
||||
ExoPlayer.Builder(context).setMediaSourceFactory(DefaultMediaSourceFactory(factory)).build().apply {
|
||||
ExoPlayer.Builder(context, programmeRenderers(context)).setMediaSourceFactory(DefaultMediaSourceFactory(factory)).build().apply {
|
||||
setMediaItem(channelMediaItem(plan))
|
||||
seekTo(programme.offsetAt(System.currentTimeMillis()))
|
||||
trackSelectionParameters = trackSelectionParameters.buildUpon().setPreferredAudioLanguage("en").build()
|
||||
|
||||
@@ -78,7 +78,7 @@ internal class LoadedNext(val startMs: Long, val plan: EmbyPlaybackPlan, private
|
||||
@androidx.annotation.OptIn(androidx.media3.common.util.UnstableApi::class)
|
||||
internal fun loadNextPlayer(context: Context, session: EmbySampleSession, plan: EmbyPlaybackPlan, audio: String?): ExoPlayer {
|
||||
val factory = DataSource.Factory { SecureMediaDataSource(session) }
|
||||
return ExoPlayer.Builder(context).setMediaSourceFactory(DefaultMediaSourceFactory(factory)).setSeekBackIncrementMs(10_000).setSeekForwardIncrementMs(10_000).build().apply {
|
||||
return ExoPlayer.Builder(context, programmeRenderers(context)).setMediaSourceFactory(DefaultMediaSourceFactory(factory)).setSeekBackIncrementMs(10_000).setSeekForwardIncrementMs(10_000).build().apply {
|
||||
setMediaItem(channelMediaItem(plan))
|
||||
trackSelectionParameters = trackSelectionParameters.buildUpon().setPreferredAudioLanguage(audio ?: "en").build()
|
||||
prepare(); playWhenReady = false
|
||||
|
||||
@@ -33,7 +33,7 @@ internal class SecureMediaDataSource(private val session: EmbySampleSession) : B
|
||||
next.instanceFollowRedirects = false
|
||||
next.connectTimeout = 10_000
|
||||
next.readTimeout = 20_000
|
||||
next.setRequestProperty("User-Agent", "OrbitTV/0.95.3")
|
||||
next.setRequestProperty("User-Agent", "OrbitTV/0.95.4")
|
||||
next.setRequestProperty("Accept-Encoding", "identity")
|
||||
session.mediaHeaders(address).forEach { (key, value) -> next.setRequestProperty(key, value) }
|
||||
if (dataSpec.position != 0L || dataSpec.length != C.LENGTH_UNSET.toLong()) {
|
||||
|
||||
@@ -59,6 +59,10 @@ internal class OrbitSettings(context: Context) {
|
||||
var driveInIntro: Boolean
|
||||
get() = saved.getBoolean("drive_in_intro", true)
|
||||
set(value) { saved.edit().putBoolean("drive_in_intro", value).apply() }
|
||||
/** Off: Orbit decodes Dolby and DTS on the box and sends plain sound, which any TV plays. On: sends them undecoded, for an amplifier. */
|
||||
var surroundToAmplifier: Boolean
|
||||
get() = saved.getBoolean("surround_to_amplifier", false)
|
||||
set(value) { saved.edit().putBoolean("surround_to_amplifier", value).apply() }
|
||||
/** Turns off moving presentation such as the Drive-In's curtains. More screens will follow it as they gain motion. */
|
||||
var reduceMotion: Boolean
|
||||
get() = saved.getBoolean("reduce_motion", false)
|
||||
@@ -148,6 +152,7 @@ private fun ViewingDetail(totsOn: Boolean, windingDown: Boolean, onWindDown: (Bo
|
||||
var identSound by remember { mutableStateOf(settings.identSound) }
|
||||
var driveInIntro by remember { mutableStateOf(settings.driveInIntro) }
|
||||
var reduceMotion by remember { mutableStateOf(settings.reduceMotion) }
|
||||
var surroundToAmplifier by remember { mutableStateOf(settings.surroundToAmplifier) }
|
||||
var confirming by remember { mutableStateOf(false) }
|
||||
Column(modifier.verticalScroll(rememberScrollState()), verticalArrangement = Arrangement.spacedBy(8.dp)) {
|
||||
SettingLine("Subtitles", "Turn on English subtitles whenever you tune in, if the programme has them. You can still change them while watching, by pressing right.") {
|
||||
@@ -165,6 +170,9 @@ private fun ViewingDetail(totsOn: Boolean, windingDown: Boolean, onWindDown: (Bo
|
||||
SettingLine("Drive-In curtains", "Play the curtain intro, with its fanfare, as you go into a screening. Back skips it.") {
|
||||
OrbitButton(if (driveInIntro) "On" else "Off", Modifier.width(64.dp), selected = driveInIntro, onClick = { driveInIntro = !driveInIntro; settings.driveInIntro = driveInIntro })
|
||||
}
|
||||
SettingLine("Surround sound to an amplifier", "Send Dolby and DTS sound undecoded, for an amplifier or soundbar that decodes it. Leave off when the TV's own speakers play the sound. Takes effect from the next programme.") {
|
||||
OrbitButton(if (surroundToAmplifier) "On" else "Off", Modifier.width(64.dp), selected = surroundToAmplifier, onClick = { surroundToAmplifier = !surroundToAmplifier; settings.surroundToAmplifier = surroundToAmplifier })
|
||||
}
|
||||
SettingLine("Reduce motion", "Leave out moving presentation, such as the Drive-In's curtains.") {
|
||||
OrbitButton(if (reduceMotion) "On" else "Off", Modifier.width(64.dp), selected = reduceMotion, onClick = { reduceMotion = !reduceMotion; settings.reduceMotion = reduceMotion })
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user