From c6a4dd1d4a4162e7d229ec75b74c9df19fa252f1 Mon Sep 17 00:00:00 2001
From: MichaelRUSF <78215956+MichaelRUSF@users.noreply.github.com>
Date: Mon, 9 Oct 2023 00:32:09 -0400
Subject: [PATCH] Add option to transcode AAC to Dolby Digital
---
.../androidtv/preference/UserPreferences.kt | 5 +++++
.../androidtv/ui/playback/LegacyMediaManager.java | 2 +-
.../androidtv/ui/playback/PlaybackController.java | 3 ++-
.../preference/screen/PlaybackPreferencesScreen.kt | 7 +++++++
.../androidtv/util/profile/ExoPlayerProfile.kt | 13 +++++++------
app/src/main/res/values/strings.xml | 2 ++
6 files changed, 24 insertions(+), 8 deletions(-)
diff --git a/app/src/main/java/org/jellyfin/androidtv/preference/UserPreferences.kt b/app/src/main/java/org/jellyfin/androidtv/preference/UserPreferences.kt
index a7f4bebd07..a5aef681d4 100644
--- a/app/src/main/java/org/jellyfin/androidtv/preference/UserPreferences.kt
+++ b/app/src/main/java/org/jellyfin/androidtv/preference/UserPreferences.kt
@@ -121,6 +121,11 @@ class UserPreferences(context: Context) : SharedPreferenceStore(
*/
var ac3Enabled = booleanPreference("pref_bitstream_ac3", !DeviceUtils.isFireTvStickGen1)
+ /**
+ * Prefer AC3
+ */
+ var aacBypassEnabled = booleanPreference("pref_bypass_aac", false)
+
/**
* Default audio delay in milliseconds for libVLC
*/
diff --git a/app/src/main/java/org/jellyfin/androidtv/ui/playback/LegacyMediaManager.java b/app/src/main/java/org/jellyfin/androidtv/ui/playback/LegacyMediaManager.java
index 61df7f6810..a2ce922faa 100644
--- a/app/src/main/java/org/jellyfin/androidtv/ui/playback/LegacyMediaManager.java
+++ b/app/src/main/java/org/jellyfin/androidtv/ui/playback/LegacyMediaManager.java
@@ -606,7 +606,7 @@ private void playInternal(final org.jellyfin.sdk.model.api.BaseItemDto item, fin
options.setMediaSources(item.getMediaSources());
DeviceProfile profile;
if (DeviceUtils.is60()) {
- profile = new ExoPlayerProfile(context, false, false);
+ profile = new ExoPlayerProfile(context, false, false, false);
} else {
profile = new LibVlcProfile(context, false);
}
diff --git a/app/src/main/java/org/jellyfin/androidtv/ui/playback/PlaybackController.java b/app/src/main/java/org/jellyfin/androidtv/ui/playback/PlaybackController.java
index 402fca62f1..cbf7c76eaa 100644
--- a/app/src/main/java/org/jellyfin/androidtv/ui/playback/PlaybackController.java
+++ b/app/src/main/java/org/jellyfin/androidtv/ui/playback/PlaybackController.java
@@ -569,7 +569,8 @@ private VideoOptions buildExoPlayerOptions(@Nullable Integer forcedSubtitleIndex
DeviceProfile internalProfile = new ExoPlayerProfile(
mFragment.getContext(),
isLiveTv && !userPreferences.getValue().get(UserPreferences.Companion.getLiveTvDirectPlayEnabled()),
- userPreferences.getValue().get(UserPreferences.Companion.getAc3Enabled())
+ userPreferences.getValue().get(UserPreferences.Companion.getAc3Enabled()),
+ userPreferences.getValue().get(UserPreferences.Companion.getAacBypassEnabled())
);
internalOptions.setProfile(internalProfile);
return internalOptions;
diff --git a/app/src/main/java/org/jellyfin/androidtv/ui/preference/screen/PlaybackPreferencesScreen.kt b/app/src/main/java/org/jellyfin/androidtv/ui/preference/screen/PlaybackPreferencesScreen.kt
index a8f9b032c2..4cb437e74b 100644
--- a/app/src/main/java/org/jellyfin/androidtv/ui/preference/screen/PlaybackPreferencesScreen.kt
+++ b/app/src/main/java/org/jellyfin/androidtv/ui/preference/screen/PlaybackPreferencesScreen.kt
@@ -192,6 +192,13 @@ class PlaybackPreferencesScreen : OptionsFragment() {
depends { userPreferences[UserPreferences.videoPlayer] != PreferredVideoPlayer.EXTERNAL }
}
+ checkbox {
+ setTitle(R.string.lbl_bypass_aac)
+ setContent(R.string.desc_bypass_aac)
+ bind(userPreferences, UserPreferences.aacBypassEnabled)
+ depends { userPreferences[UserPreferences.videoPlayer] != PreferredVideoPlayer.EXTERNAL }
+ }
+
@Suppress("MagicNumber")
seekbar {
setTitle(R.string.pref_libvlc_audio_delay_title)
diff --git a/app/src/main/java/org/jellyfin/androidtv/util/profile/ExoPlayerProfile.kt b/app/src/main/java/org/jellyfin/androidtv/util/profile/ExoPlayerProfile.kt
index c834697a10..61a30dc466 100644
--- a/app/src/main/java/org/jellyfin/androidtv/util/profile/ExoPlayerProfile.kt
+++ b/app/src/main/java/org/jellyfin/androidtv/util/profile/ExoPlayerProfile.kt
@@ -29,12 +29,13 @@ class ExoPlayerProfile(
context: Context,
disableVideoDirectPlay: Boolean = false,
isAC3Enabled: Boolean = false,
+ isAACBYPASSEnabled: Boolean = false,
) : DeviceProfile() {
- private val downmixSupportedAudioCodecs = arrayOf(
- Codec.Audio.AAC,
- Codec.Audio.MP3,
- Codec.Audio.MP2
- )
+ private val downmixSupportedAudioCodecs = buildList {
+ if (isAC3Enabled && isAACBYPASSEnabled) add(Codec.Audio.AC3) else add(Codec.Audio.AAC)
+ add(Codec.Audio.MP3)
+ add(Codec.Audio.MP2)
+ }.toTypedArray()
/**
* Returns all audio codecs used commonly in video containers.
@@ -44,7 +45,7 @@ class ExoPlayerProfile(
addAll(downmixSupportedAudioCodecs)
add(Codec.Audio.AAC_LATM)
add(Codec.Audio.ALAC)
- if (isAC3Enabled) add(Codec.Audio.AC3)
+ if (isAC3Enabled && !isAACBYPASSEnabled) add(Codec.Audio.AC3)
if (isAC3Enabled) add(Codec.Audio.EAC3)
add(Codec.Audio.DCA)
add(Codec.Audio.DTS)
diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml
index af11f2c1d4..dd6575fcf9 100644
--- a/app/src/main/res/values/strings.xml
+++ b/app/src/main/res/values/strings.xml
@@ -494,6 +494,8 @@
Disable new music backend
Only disable this if you\'re experiencing issues with music playback
Disable device type warning
+ Transcode AAC to Dolby Digital audio
+ Must have Dolby Digital bitstreaming enabled
- %1$s second
- %1$s seconds