Experimental option to transcode surround sound audio to AC3 (#947)

## Description
Adds an experimental setting to prefer transcoding audio with more than
2 channels to AC3. Stereo audio does not transcode.

This is basically a workaround for HDMI ARC (not eARC) or optical audio
devices because instead of 2 uncompressed PCM channels, 6 AC3 channels
(ie 5.1) is possible.

An downside of enabling this is that embedded subtitles be burned in
causing a video transcode as well.

### Related issues
Fixes #255
Incorporates some code from #1410

### Testing
Just on the emulator so far to observe if the settings trigger the
transcode or not

## Screenshots
N/A

## AI or LLM usage
None

---------

Co-authored-by: darkflame91 <darkflame91@gmail.com>
This commit is contained in:
Damontecres 2026-07-09 13:15:42 -04:00 • committed by GitHub
parent f2287a85e8
commit d481aea85a
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
11 changed files with 205 additions and 54 deletions

View file

@ -53,7 +53,10 @@ sealed interface AppPreference<Pref, T> {
value: T?,
): String? = null
fun validate(value: T): PreferenceValidation = PreferenceValidation.Valid
fun validate(
prefs: Pref,
value: T,
): PreferenceValidation = PreferenceValidation.Valid
companion object {
val SkipForward =
@ -391,18 +394,25 @@ sealed interface AppPreference<Pref, T> {
defaultValue = true,
getter = { it.playbackPreferences.overrides.ac3Supported },
setter = { prefs, value ->
prefs.updatePlaybackOverrides { ac3Supported = value }
if (!value) prefs.updateExperimentalPreferences { preferAc3Surround = false }
prefs.updatePlaybackOverrides {
ac3Supported = value
}
},
summaryOn = R.string.enabled,
summaryOff = R.string.disabled,
)
val DownMixStereo =
AppSwitchPreference<AppPreferences>(
title = R.string.downmix_stereo,
defaultValue = false,
getter = { it.playbackPreferences.overrides.downmixStereo },
setter = { prefs, value ->
prefs.updatePlaybackOverrides { downmixStereo = value }
if (value) prefs.updateExperimentalPreferences { preferAc3Surround = false }
prefs.updatePlaybackOverrides {
downmixStereo = value
}
},
summaryOn = R.string.enabled,
summaryOff = R.string.disabled,
@ -1311,11 +1321,16 @@ data class AppSwitchPreference<Pref>(
override val defaultValue: Boolean,
override val getter: (prefs: Pref) -> Boolean,
override val setter: (prefs: Pref, value: Boolean) -> Pref,
val validator: (value: Boolean) -> PreferenceValidation = { PreferenceValidation.Valid },
val validator: (prefs: Pref, value: Boolean) -> PreferenceValidation = { _, _ -> PreferenceValidation.Valid },
@param:StringRes val summary: Int? = null,
@param:StringRes val summaryOn: Int? = null,
@param:StringRes val summaryOff: Int? = null,
) : AppPreference<Pref, Boolean> {
override fun validate(
prefs: Pref,
value: Boolean,
): PreferenceValidation = validator.invoke(prefs, value)
override fun summary(
context: Context,
value: Boolean?,

View file

@ -4,6 +4,7 @@ import com.github.damontecres.wholphin.R
import com.github.damontecres.wholphin.ui.nav.Destination
import com.github.damontecres.wholphin.ui.preferences.PreferenceGroup
import com.github.damontecres.wholphin.ui.preferences.PreferenceScreenOption
import com.github.damontecres.wholphin.ui.preferences.PreferenceValidation
object ExperimentalPreference {
val Enable =
@ -35,6 +36,30 @@ object ExperimentalPreference {
summaryOn = R.string.enabled,
summaryOff = R.string.disabled,
)
val PreferAc3ForSurround =
AppSwitchPreference<AppPreferences>(
title = R.string.prefer_ac3_for_surround,
defaultValue = true,
getter = { it.experimentalPreferences.preferAc3Surround },
setter = { prefs, value ->
prefs.updateExperimentalPreferences {
preferAc3Surround = value
}
},
summary = R.string.prefer_ac3_for_surround_summary,
validator = { prefs, value ->
prefs.playbackPreferences.overrides.let {
if (value && !it.ac3Supported) {
PreferenceValidation.Invalid("AC3 support is not enabled")
} else if (value && it.downmixStereo) {
PreferenceValidation.Invalid("Always downmixing to stereo")
} else {
PreferenceValidation.Valid
}
}
},
)
}
val experimentalPreferences =
@ -45,6 +70,7 @@ val experimentalPreferences =
preferences =
listOf(
ExperimentalPreference.VideoTunneling,
ExperimentalPreference.PreferAc3ForSurround,
),
),
)