Skip to content
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

Add codec panel and support for user-defined AVC/HEVC levels #3985

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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 @@ -102,6 +102,16 @@ class UserPreferences(context: Context) : SharedPreferenceStore(
*/
var preferExoPlayerFfmpeg = booleanPreference("exoplayer_prefer_ffmpeg", defaultValue = false)

/**
* User defined AVC levels for main and high 10.
*/
var userAVCLevel = stringPreference("user_avc_level", "auto")

/**
* User defined HEVC levels for main and main 10.
*/
var userHEVCLevel = stringPreference("user_hevc_level", "auto")

/* Playback - Audio related */
/**
* Preferred behavior for audio streaming.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -514,7 +514,9 @@ private VideoOptions buildExoPlayerOptions(@Nullable Integer forcedSubtitleIndex
DeviceProfile internalProfile = new ExoPlayerProfile(
!internalOptions.getEnableDirectStream(),
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.getUserAVCLevel()),
userPreferences.getValue().get(UserPreferences.Companion.getUserHEVCLevel())
);
internalOptions.setProfile(internalProfile);
return internalOptions;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
package org.jellyfin.androidtv.ui.preference.screen

import org.jellyfin.androidtv.R
import org.jellyfin.androidtv.preference.UserPreferences
import org.jellyfin.androidtv.ui.preference.dsl.OptionsFragment
import org.jellyfin.androidtv.ui.preference.dsl.checkbox
import org.jellyfin.androidtv.ui.preference.dsl.list
import org.jellyfin.androidtv.ui.preference.dsl.optionsScreen
import org.koin.android.ext.android.inject

class PlaybackAdvancedCodecPreferencesScreen : OptionsFragment() {
private val userPreferences: UserPreferences by inject()

override val screen by optionsScreen {
setTitle(R.string.codec)

category {
setTitle(R.string.level_warning)

list {
setTitle(R.string.user_avc_level)
entries = mapOf(
// AVC levels as reported by ffprobe are multiplied by 10, e.g. level 4.1 is 41.
"auto" to "Auto",
"62" to "Level 6.2",
"61" to "Level 6.1",
"60" to "Level 6.0",
"52" to "Level 5.2",
"51" to "Level 5.1",
"50" to "Level 5.0",
"42" to "Level 4.2",
"41" to "Level 4.1",
"40" to "Level 4.0"
)
bind(userPreferences, UserPreferences.userAVCLevel)
}

list {
setTitle(R.string.user_hevc_level)
entries = mapOf(
// HEVC levels as reported by ffprobe are multiplied by 30, e.g. level 4.1 is 123.
"auto" to "Auto",
"186" to "Level 6.2",
"183" to "Level 6.1",
"180" to "Level 6.0",
"156" to "Level 5.2",
"153" to "Level 5.1",
"150" to "Level 5.0",
"123" to "Level 4.1",
"120" to "Level 4.0"
)
bind(userPreferences, UserPreferences.userHEVCLevel)
}
}

category {
setTitle(R.string.pref_audio)

checkbox {
setTitle(R.string.lbl_bitstream_ac3)
setContent(R.string.desc_bitstream_ac3)
bind(userPreferences, UserPreferences.ac3Enabled)
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -109,12 +109,6 @@ class PlaybackAdvancedPreferencesScreen : OptionsFragment() {
bind(userPreferences, UserPreferences.audioNightMode)
depends { Build.VERSION.SDK_INT >= Build.VERSION_CODES.P }
}

checkbox {
setTitle(R.string.lbl_bitstream_ac3)
setContent(R.string.desc_bitstream_ac3)
bind(userPreferences, UserPreferences.ac3Enabled)
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -194,6 +194,12 @@ class PlaybackPreferencesScreen : OptionsFragment() {
icon = R.drawable.ic_more
withFragment<PlaybackAdvancedPreferencesScreen>()
}

link {
setTitle(R.string.codec_advanced)
icon = R.drawable.ic_more
withFragment<PlaybackAdvancedCodecPreferencesScreen>()
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,9 @@ import org.jellyfin.apiclient.model.dlna.TranscodingProfile
class ExoPlayerProfile(
disableVideoDirectPlay: Boolean,
isAC3Enabled: Boolean,
downMixAudio: Boolean
downMixAudio: Boolean,
userAVCLevel: String? = "auto",
userHEVCLevel: String? = "auto"
) : DeviceProfile() {
private val downmixSupportedAudioCodecs = arrayOf(
Codec.Audio.AAC,
Expand Down Expand Up @@ -153,8 +155,22 @@ class ExoPlayerProfile(

codecProfiles = buildList {
// H264 profile
add(deviceAVCCodecProfile)
addAll(deviceAVCLevelCodecProfiles)
if (userAVCLevel == "auto") {
add(deviceAVCCodecProfile)
addAll(deviceAVCLevelCodecProfiles)
} else {
add(CodecProfile().apply {
type = CodecType.Video
codec = Codec.Video.H264
conditions = arrayOf(
ProfileCondition(
ProfileConditionType.LessThanEqual,
ProfileConditionValue.VideoLevel,
userAVCLevel
)
)
})
}
// H264 ref frames profile
add(CodecProfile().apply {
type = CodecType.Video
Expand Down Expand Up @@ -194,8 +210,23 @@ class ExoPlayerProfile(
)
})
// HEVC profiles
add(deviceHevcCodecProfile)
addAll(deviceHevcLevelCodecProfiles)
if (userHEVCLevel == "auto") {
add(deviceHevcCodecProfile)
addAll(deviceHevcLevelCodecProfiles)
} else {
add(CodecProfile().apply {
type = CodecType.Video
codec = Codec.Video.HEVC
conditions = arrayOf(
ProfileCondition(
ProfileConditionType.LessThanEqual,
ProfileConditionValue.VideoLevel,
userHEVCLevel
)
)
})
}

// AV1 profile
add(deviceAV1CodecProfile)
// Limit video resolution support for older devices
Expand Down
5 changes: 5 additions & 0 deletions app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -526,6 +526,11 @@
<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="codec_advanced">Advanced codec preferences</string>
<string name="codec">Codec</string>
<string name="user_avc_level">H.264 Level</string>
<string name="user_hevc_level">H.265 Level</string>
<string name="level_warning">Video\n\nSwitching from \'Auto\' could lead to playback issues</string>
<plurals name="seconds">
<item quantity="one">%1$s second</item>
<item quantity="other">%1$s seconds</item>
Expand Down