jellyfin / jellyfin-androidtv

Android TV Client for Jellyfin
https://jellyfin.org
GNU General Public License v2.0
2.72k stars 466 forks source link

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

Open MichaelRUSF opened 1 month ago

MichaelRUSF commented 1 month ago

This PR adds an HDMI ARC audio output mode to address playback issues with high-resolution and uncompressed audio formats over an ARC connection in Jellyfin. Updates to the ExoPlayerProfile class and incorporates a new audio output preference. The PR ensures compatibility with PCM and TrueHD formats by transcoding unsupported surround sound formats to AC3, maintaining surround sound capabilities.

Changes

  1. Preference Option:

    • Added HDMI_ARC_OUTPUT option in AudioBehavior to allow users to enable HDMI ARC audio output.
  2. New Parameter:

    • Added enableARCAudio parameter to ExoPlayerProfile.
    • Added AudioBehavior.HDMI_ARC_OUTPUT condition to PlaybackController.
  3. Updated Audio Codecs:

    • Added downmixARCSupportedAudioCodecs for ARC audio.
    • Adjusted allSupportedAudioCodecs to include/exclude codecs based on enableARCAudio.
    • Updated audio codec selection for transcoding and direct play profiles based on new settings.
    • Added maximum audio channel profiles specifically for ARC audio.

Issues

Fixes: #3900 #3903 #2991
svemonix commented 3 weeks ago

Thanks for the contribution and this is a very good step in the right direction. However I believe the multichannel audio issue will only be partially fixed just like on the Plex client.

Basically the use case not covered is the following. Many Android TV devices can't output multichannel PCM which means that multichannel AAC will be output as 2.0 PCM on a receiver plugged in via ARC. Now, you could activate the S/PDIF mode which would solve the multichannel AAC playback by transcoding to AC3. The issue here is that it won't allow DD+ playback including DD+ Atmos even though the device and receiver supports it via ARC. It would also limit to 5.1.

So far the only client that can handle this properly is Kodi since it has more advanced settings. Maybe there should be a DD+ toggle together with the S/PDIF & ARC one.

MichaelRUSF commented 3 weeks ago

The issue here is that it won't allow DD+ playback including DD+ Atmos even though the device and receiver supports it via ARC. It would also limit to 5.1.

That statement is incorrect. Did you test a debug build, or are you making assumptions based on what you believe? AC3 (Dolby Digital) and EAC3 (Dolby Digital Plus) audio are not limited and behave the same as they would in direct play.

svemonix commented 3 weeks ago

The issue here is that it won't allow DD+ playback including DD+ Atmos even though the device and receiver supports it via ARC. It would also limit to 5.1.

That statement is incorrect. Did you test a debug build, or are you making assumptions based on what you believe? AC3 (Dolby Digital) and EAC3 (Dolby Digital Plus) audio are not limited and behave the same as they would in direct play.

As stated it was an assumption but looking at the details maybe there is an issue the other way around.

if ((isAC3Enabled) || (enableSPDIF)) { add(Codec.Audio.AC3) add(Codec.Audio.EAC3)

Isn't it gonna try to direct play and passthrough EAC3 even if using SPDIF (e.g. optical)? SPDIF doesn't support EAC3 only ARC.

salty-sweet commented 3 weeks ago

SPDIF doesn't support EAC3 only ARC.

I'd like to say that EAC3 can run through SPDIF up to 5.1 channels only. To temporarily work around the inconvenience caused by #3900, I am currently using a SPDIF connection for audio. Dolby Digital Plus 5.1 channel (and also limited to 1024kbps because more than that specific bitrate, FFMPEG-transcoded DDP/EAC3 audio doesn't work on my AVR) does work.

There could be some channel check in there as well to allow 5.1 EAC3, and filter out 7.1 over SPDIF.

MichaelRUSF commented 3 weeks ago

This PR is aimed at ARC rather than Optical audio, despite the name of the option. The name "SPDIF" was chosen because it is more commonly used across other platforms compared to eARC vs. ARC. However, if this naming is causing confusion, it can be changed.

Targeting Optical audio would result in the loss of EAC3/JOC (DD+ with Dolby Atmos) and limit DD to 5.1, which is not the goal of this PR. If issues arise for optical users after merging this PR, they can be addressed. My objective is to keep this process straightforward and get the PR merged.