diff --git a/android/app/build.gradle.kts b/android/app/build.gradle.kts index 957bb87c..0f1fac93 100644 --- a/android/app/build.gradle.kts +++ b/android/app/build.gradle.kts @@ -9,8 +9,8 @@ android { applicationId = "tv.orbit.classic" minSdk = 26 targetSdk = 36 - versionCode = 122 - versionName = "0.95.3-terra-logo" + versionCode = 123 + versionName = "0.95.4-plain-sound" } buildFeatures { compose = true } compileOptions { sourceCompatibility = JavaVersion.VERSION_17; targetCompatibility = JavaVersion.VERSION_17 } diff --git a/android/app/src/main/java/tv/orbit/classic/AudioOutput.kt b/android/app/src/main/java/tv/orbit/classic/AudioOutput.kt new file mode 100644 index 00000000..07f98312 --- /dev/null +++ b/android/app/src/main/java/tv/orbit/classic/AudioOutput.kt @@ -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() + } + } +} diff --git a/android/app/src/main/java/tv/orbit/classic/EmbyClient.kt b/android/app/src/main/java/tv/orbit/classic/EmbyClient.kt index 194544ec..2f46128d 100644 --- a/android/app/src/main/java/tv/orbit/classic/EmbyClient.kt +++ b/android/app/src/main/java/tv/orbit/classic/EmbyClient.kt @@ -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) diff --git a/android/app/src/main/java/tv/orbit/classic/EmbyPlaybackDialog.kt b/android/app/src/main/java/tv/orbit/classic/EmbyPlaybackDialog.kt index d772bffe..1bec4656 100644 --- a/android/app/src/main/java/tv/orbit/classic/EmbyPlaybackDialog.kt +++ b/android/app/src/main/java/tv/orbit/classic/EmbyPlaybackDialog.kt @@ -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())) diff --git a/android/app/src/main/java/tv/orbit/classic/GuidePicture.kt b/android/app/src/main/java/tv/orbit/classic/GuidePicture.kt index 19d28f0f..5cc7c928 100644 --- a/android/app/src/main/java/tv/orbit/classic/GuidePicture.kt +++ b/android/app/src/main/java/tv/orbit/classic/GuidePicture.kt @@ -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() diff --git a/android/app/src/main/java/tv/orbit/classic/Idents.kt b/android/app/src/main/java/tv/orbit/classic/Idents.kt index 7944e235..8126c247 100644 --- a/android/app/src/main/java/tv/orbit/classic/Idents.kt +++ b/android/app/src/main/java/tv/orbit/classic/Idents.kt @@ -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 diff --git a/android/app/src/main/java/tv/orbit/classic/SecureMediaDataSource.kt b/android/app/src/main/java/tv/orbit/classic/SecureMediaDataSource.kt index a18bceef..d3da8381 100644 --- a/android/app/src/main/java/tv/orbit/classic/SecureMediaDataSource.kt +++ b/android/app/src/main/java/tv/orbit/classic/SecureMediaDataSource.kt @@ -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()) { diff --git a/android/app/src/main/java/tv/orbit/classic/Settings.kt b/android/app/src/main/java/tv/orbit/classic/Settings.kt index 7873bdc6..a0a9d56a 100644 --- a/android/app/src/main/java/tv/orbit/classic/Settings.kt +++ b/android/app/src/main/java/tv/orbit/classic/Settings.kt @@ -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 }) } diff --git a/android/app/src/test/java/tv/orbit/classic/AudioOutputTest.kt b/android/app/src/test/java/tv/orbit/classic/AudioOutputTest.kt new file mode 100644 index 00000000..d71177ac --- /dev/null +++ b/android/app/src/test/java/tv/orbit/classic/AudioOutputTest.kt @@ -0,0 +1,18 @@ +package tv.orbit.classic + +import android.media.AudioFormat +import org.junit.Assert.assertArrayEquals +import org.junit.Test + +class AudioOutputTest { + private val tv = setOf(AudioFormat.ENCODING_PCM_16BIT, AudioFormat.ENCODING_AC3, AudioFormat.ENCODING_E_AC3, AudioFormat.ENCODING_DTS, AudioFormat.ENCODING_DOLBY_TRUEHD) + + @Test fun dolbyAndDtsAreDecodedOnTheBoxSoOnlyPlainSoundAndTrueHdGoOutUndecoded() { + // The TV accepts DTS and Dolby, but only PCM, and TrueHD (which the box can't decode), are sent as they are. + assertArrayEquals(intArrayOf(AudioFormat.ENCODING_PCM_16BIT, AudioFormat.ENCODING_DOLBY_TRUEHD), plainSoundEncodings(tv::contains)) + } + + @Test fun aConnectionWithoutTrueHdGetsPlainSoundOnly() { + assertArrayEquals(intArrayOf(AudioFormat.ENCODING_PCM_16BIT), plainSoundEncodings(setOf(AudioFormat.ENCODING_PCM_16BIT)::contains)) + } +} diff --git a/docs/VERIFICATION-0.95.4.md b/docs/VERIFICATION-0.95.4.md new file mode 100644 index 00000000..0f0cf5e0 --- /dev/null +++ b/docs/VERIFICATION-0.95.4.md @@ -0,0 +1,11 @@ +# Orbit TV 0.95.4: plain sound to the TV (no more DTS dropouts) + +A small playback fix of its own, approved by Paul on 3 November 2026 ("not sure anything else I can change this end"). No scheduler, artwork or plan changes. + +**What happened:** on Terra (201) at about 22:07 on 3 November, a programme with 6-channel DTS sound cut in and out every couple of seconds. Paul has no amplifier or soundbar: the sound goes to the TV's own speakers. The box's live audio log (22:10:58 to 22:11:40) showed Orbit sending a steady, gap-free DTS bitstream ("stream_type raw") to the TV, which then failed to keep decoding it. The box's own "Surround sound" setting was already off: ExoPlayer reads the HDMI connection's capabilities directly, and the TV claims DTS, so the setting was ignored. + +**The change:** every programme player (full screen, the next programme loaded ahead, and the guide's picture) now builds its sound output through `programmeRenderers` (AudioOutput.kt). Unless the new Watching setting "Surround sound to an amplifier" is on (off by default), the sound sink may only send PCM undecoded, so Dolby Digital, Dolby Digital Plus and DTS are decoded on the box by its own decoders (c2.amlogic.audio.decoder.ac3, eac3, dts, dtshd) and reach the TV as plain sound. TrueHD, which the box can't decode, still goes out undecoded when the connection accepts it, as before, rather than going silent. With the setting on, everything behaves exactly as in 0.95.3. + +Files: AudioOutput.kt (new), Settings.kt (the setting), EmbyPlaybackDialog.kt, Idents.kt, GuidePicture.kt (use the renderers). AudioOutputTest (2 tests). 365 unit tests pass; lint has no errors. + +**To check on the TV:** the same Terra programme (DTS) plays without dropouts; a Dolby programme sounds normal; the box's audio log shows stream_type pcm during a DTS programme. Not yet checked on the box.