Skip to content

Add ARC audio output mode with updated codec profiles and transcoding #3936

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,9 @@ enum class AudioBehavior(
* Downnmix audio to stereo. Disables the AC3, EAC3 and AAC_LATM audio codecs.
*/
DOWNMIX_TO_STEREO(R.string.pref_audio_compat),

/**
* Stream AC3, EAC3, and DTS directly. Disables TrueHD and caps other codecs to stereo.
*/
HDMI_ARC_OUTPUT(R.string.audio_hdmi_arc)
}
Original file line number Diff line number Diff line change
Expand Up @@ -514,7 +514,8 @@ private VideoOptions buildExoPlayerOptions(@Nullable Integer forcedSubtitleIndex
DeviceProfile internalProfile = new ExoPlayerProfile(
isLiveTv && !userPreferences.getValue().get(UserPreferences.Companion.getLiveTvDirectPlayEnabled()),
userPreferences.getValue().get(UserPreferences.Companion.getAc3Enabled()),
userPreferences.getValue().get(UserPreferences.Companion.getAudioBehaviour()) == AudioBehavior.DOWNMIX_TO_STEREO
userPreferences.getValue().get(UserPreferences.Companion.getAudioBehaviour()) == AudioBehavior.DOWNMIX_TO_STEREO,
userPreferences.getValue().get(UserPreferences.Companion.getAudioBehaviour()) == AudioBehavior.HDMI_ARC_OUTPUT
);
internalOptions.setProfile(internalProfile);
return internalOptions;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,28 +27,40 @@ import org.jellyfin.apiclient.model.dlna.TranscodingProfile
class ExoPlayerProfile(
disableVideoDirectPlay: Boolean,
isAC3Enabled: Boolean,
downMixAudio: Boolean
downMixAudio: Boolean,
enableARCAudio: Boolean
) : DeviceProfile() {
private val downmixSupportedAudioCodecs = arrayOf(
Codec.Audio.AAC,
Codec.Audio.MP3,
Codec.Audio.MP2
)

private val downmixARCSupportedAudioCodecs = arrayOf(
// Bypass isAC3Enabled check for HDMI ARC mode
Codec.Audio.AC3,
Codec.Audio.MP3,
Codec.Audio.MP2
)

/**
* Returns all audio codecs used commonly in video containers.
* This does not include containers / codecs found in audio files
*/
private val allSupportedAudioCodecs = buildList {
addAll(downmixSupportedAudioCodecs)
if ((isAC3Enabled) || (enableARCAudio)) {
add(Codec.Audio.AC3)
add(Codec.Audio.EAC3)
}
if (!enableARCAudio) {
add(Codec.Audio.MLP)
add(Codec.Audio.TRUEHD)
}
add(Codec.Audio.AAC_LATM)
add(Codec.Audio.ALAC)
if (isAC3Enabled) add(Codec.Audio.AC3)
if (isAC3Enabled) add(Codec.Audio.EAC3)
add(Codec.Audio.DCA)
add(Codec.Audio.DTS)
add(Codec.Audio.MLP)
add(Codec.Audio.TRUEHD)
add(Codec.Audio.PCM_ALAW)
add(Codec.Audio.PCM_MULAW)
add(Codec.Audio.PCM_S16LE)
Expand All @@ -69,6 +81,18 @@ class ExoPlayerProfile(
maxStreamingBitrate = 20_000_000 // 20 mbps
maxStaticBitrate = 10_000_0000 // 10 mbps

// Determine audio codecs for profiles
val audioCodecForTranscodingProfile = when {
downMixAudio -> downmixSupportedAudioCodecs
enableARCAudio -> downmixARCSupportedAudioCodecs
else -> allSupportedAudioCodecsWithoutFFmpegExperimental
}.joinToString(",")

val audioCodecForDirectPlayProfile = when {
downMixAudio -> downmixSupportedAudioCodecs
else -> allSupportedAudioCodecsWithoutFFmpegExperimental
}.joinToString(",")

transcodingProfiles = arrayOf(
// TS video profile
TranscodingProfile().apply {
Expand All @@ -79,10 +103,7 @@ class ExoPlayerProfile(
if (supportsHevc) add(Codec.Video.HEVC)
add(Codec.Video.H264)
}.joinToString(",")
audioCodec = when (downMixAudio) {
true -> downmixSupportedAudioCodecs
false -> allSupportedAudioCodecsWithoutFFmpegExperimental
}.joinToString(",")
audioCodec = audioCodecForTranscodingProfile
protocol = "hls"
copyTimestamps = false
enableSubtitlesInManifest = true
Expand Down Expand Up @@ -128,10 +149,7 @@ class ExoPlayerProfile(
Codec.Video.AV1
).joinToString(",")

audioCodec = when (downMixAudio) {
true -> downmixSupportedAudioCodecs
false -> allSupportedAudioCodecs
}.joinToString(",")
audioCodec = audioCodecForDirectPlayProfile
})
}
// Audio direct play
Expand Down Expand Up @@ -203,6 +221,32 @@ class ExoPlayerProfile(
add(maxResolutionCodecProfile)
// Audio channel profile
add(maxAudioChannelsCodecProfile(channels = if (downMixAudio) 2 else 8))
// Add maximum audio channel profiles for ARC if enableARCAudio is true
if (enableARCAudio) {
add(CodecProfile().apply {
type = CodecType.VideoAudio
codec = arrayOf(
Codec.Audio.AAC,
Codec.Audio.AAC_LATM,
Codec.Audio.ALAC,
Codec.Audio.PCM_ALAW,
Codec.Audio.PCM_MULAW,
Codec.Audio.PCM_S16LE,
Codec.Audio.PCM_S20LE,
Codec.Audio.PCM_S24LE,
Codec.Audio.OPUS,
Codec.Audio.FLAC,
Codec.Audio.VORBIS
).joinToString(",")
conditions = arrayOf(
ProfileCondition(
ProfileConditionType.LessThanEqual,
ProfileConditionValue.AudioChannels,
"2"
)
)
})
}
}.toTypedArray()

subtitleProfiles = buildList {
Expand Down
1 change: 1 addition & 0 deletions app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -525,6 +525,7 @@
<string name="segment_type_unknown">Unknown segments</string>
<string name="skip_forward_length">Skip forward length</string>
<string name="preference_enable_trickplay">Enable trickplay in video player</string>
<string name="audio_hdmi_arc">HDMI ARC</string>
<plurals name="seconds">
<item quantity="one">%1$s second</item>
<item quantity="other">%1$s seconds</item>
Expand Down