Skip to content

Commit e8268d7

Browse files
author
MichaelRUSF
committed
Add codec panel
1 parent 14d67e4 commit e8268d7

File tree

7 files changed

+126
-12
lines changed

7 files changed

+126
-12
lines changed

app/src/main/java/org/jellyfin/androidtv/preference/UserPreferences.kt

+10
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,16 @@ class UserPreferences(context: Context) : SharedPreferenceStore(
9898
*/
9999
var preferExoPlayerFfmpeg = booleanPreference("exoplayer_prefer_ffmpeg", defaultValue = false)
100100

101+
/**
102+
* User defined AVC levels for main and high 10.
103+
*/
104+
var userAVCLevel = stringPreference("user_avc_level", "auto")
105+
106+
/**
107+
* User defined HEVC levels for main and main 10.
108+
*/
109+
var userHEVCLevel = stringPreference("user_hevc_level", "auto")
110+
101111
/* Playback - Audio related */
102112
/**
103113
* Preferred behavior for audio streaming.

app/src/main/java/org/jellyfin/androidtv/ui/playback/PlaybackController.java

+3-1
Original file line numberDiff line numberDiff line change
@@ -522,7 +522,9 @@ private VideoOptions buildExoPlayerOptions(@Nullable Integer forcedSubtitleIndex
522522
DeviceProfile internalProfile = new ExoPlayerProfile(
523523
isLiveTv && !userPreferences.getValue().get(UserPreferences.Companion.getLiveTvDirectPlayEnabled()),
524524
userPreferences.getValue().get(UserPreferences.Companion.getAc3Enabled()),
525-
userPreferences.getValue().get(UserPreferences.Companion.getAudioBehaviour()) == AudioBehavior.DOWNMIX_TO_STEREO
525+
userPreferences.getValue().get(UserPreferences.Companion.getAudioBehaviour()) == AudioBehavior.DOWNMIX_TO_STEREO,
526+
userPreferences.getValue().get(UserPreferences.Companion.getUserAVCLevel()),
527+
userPreferences.getValue().get(UserPreferences.Companion.getUserHEVCLevel())
526528
);
527529
internalOptions.setProfile(internalProfile);
528530
return internalOptions;
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
package org.jellyfin.androidtv.ui.preference.screen
2+
3+
import org.jellyfin.androidtv.R
4+
import org.jellyfin.androidtv.preference.UserPreferences
5+
import org.jellyfin.androidtv.ui.preference.dsl.OptionsFragment
6+
import org.jellyfin.androidtv.ui.preference.dsl.checkbox
7+
import org.jellyfin.androidtv.ui.preference.dsl.list
8+
import org.jellyfin.androidtv.ui.preference.dsl.optionsScreen
9+
import org.koin.android.ext.android.inject
10+
11+
class PlaybackAdvancedCodecPreferencesScreen : OptionsFragment() {
12+
private val userPreferences: UserPreferences by inject()
13+
14+
override val screen by optionsScreen {
15+
setTitle(R.string.codec)
16+
17+
category {
18+
setTitle(R.string.level_warning)
19+
20+
list {
21+
setTitle(R.string.user_avc_level)
22+
entries = mapOf(
23+
// AVC levels as reported by ffprobe are multiplied by 10, e.g. level 4.1 is 41.
24+
"auto" to "Auto",
25+
"62" to "Level 6.2",
26+
"61" to "Level 6.1",
27+
"60" to "Level 6.0",
28+
"52" to "Level 5.2",
29+
"51" to "Level 5.1",
30+
"50" to "Level 5.0",
31+
"42" to "Level 4.2",
32+
"41" to "Level 4.1",
33+
"40" to "Level 4.0"
34+
)
35+
bind(userPreferences, UserPreferences.userAVCLevel)
36+
}
37+
38+
list {
39+
setTitle(R.string.user_hevc_level)
40+
entries = mapOf(
41+
// HEVC levels as reported by ffprobe are multiplied by 30, e.g. level 4.1 is 123.
42+
"auto" to "Auto",
43+
"186" to "Level 6.2",
44+
"183" to "Level 6.1",
45+
"180" to "Level 6.0",
46+
"156" to "Level 5.2",
47+
"153" to "Level 5.1",
48+
"150" to "Level 5.0",
49+
"123" to "Level 4.1",
50+
"120" to "Level 4.0"
51+
)
52+
bind(userPreferences, UserPreferences.userHEVCLevel)
53+
}
54+
}
55+
56+
category {
57+
setTitle(R.string.pref_audio)
58+
59+
checkbox {
60+
setTitle(R.string.lbl_bitstream_ac3)
61+
setContent(R.string.desc_bitstream_ac3)
62+
bind(userPreferences, UserPreferences.ac3Enabled)
63+
}
64+
}
65+
}
66+
}

app/src/main/java/org/jellyfin/androidtv/ui/preference/screen/PlaybackAdvancedPreferencesScreen.kt

-6
Original file line numberDiff line numberDiff line change
@@ -85,12 +85,6 @@ class PlaybackAdvancedPreferencesScreen : OptionsFragment() {
8585
bind(userPreferences, UserPreferences.audioNightMode)
8686
depends { Build.VERSION.SDK_INT >= Build.VERSION_CODES.P }
8787
}
88-
89-
checkbox {
90-
setTitle(R.string.lbl_bitstream_ac3)
91-
setContent(R.string.desc_bitstream_ac3)
92-
bind(userPreferences, UserPreferences.ac3Enabled)
93-
}
9488
}
9589
}
9690
}

app/src/main/java/org/jellyfin/androidtv/ui/preference/screen/PlaybackPreferencesScreen.kt

+6
Original file line numberDiff line numberDiff line change
@@ -148,6 +148,12 @@ class PlaybackPreferencesScreen : OptionsFragment() {
148148
icon = R.drawable.ic_more
149149
withFragment<PlaybackAdvancedPreferencesScreen>()
150150
}
151+
152+
link {
153+
setTitle(R.string.codec_advanced)
154+
icon = R.drawable.ic_more
155+
withFragment<PlaybackAdvancedCodecPreferencesScreen>()
156+
}
151157
}
152158
}
153159
}

app/src/main/java/org/jellyfin/androidtv/util/profile/ExoPlayerProfile.kt

+36-5
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,9 @@ import org.jellyfin.apiclient.model.dlna.TranscodingProfile
2727
class ExoPlayerProfile(
2828
disableVideoDirectPlay: Boolean,
2929
isAC3Enabled: Boolean,
30-
downMixAudio: Boolean
30+
downMixAudio: Boolean,
31+
userAVCLevel: String? = "auto",
32+
userHEVCLevel: String? = "auto"
3133
) : DeviceProfile() {
3234
private val downmixSupportedAudioCodecs = arrayOf(
3335
Codec.Audio.AAC,
@@ -154,8 +156,22 @@ class ExoPlayerProfile(
154156

155157
codecProfiles = buildList {
156158
// H264 profile
157-
add(deviceAVCCodecProfile)
158-
addAll(deviceAVCLevelCodecProfiles)
159+
if (userAVCLevel == "auto") {
160+
add(deviceAVCCodecProfile)
161+
addAll(deviceAVCLevelCodecProfiles)
162+
} else {
163+
add(CodecProfile().apply {
164+
type = CodecType.Video
165+
codec = Codec.Video.H264
166+
conditions = arrayOf(
167+
ProfileCondition(
168+
ProfileConditionType.LessThanEqual,
169+
ProfileConditionValue.VideoLevel,
170+
userAVCLevel
171+
)
172+
)
173+
})
174+
}
159175
// H264 ref frames profile
160176
add(CodecProfile().apply {
161177
type = CodecType.Video
@@ -195,8 +211,23 @@ class ExoPlayerProfile(
195211
)
196212
})
197213
// HEVC profiles
198-
add(deviceHevcCodecProfile)
199-
addAll(deviceHevcLevelCodecProfiles)
214+
if (userHEVCLevel == "auto") {
215+
add(deviceHevcCodecProfile)
216+
addAll(deviceHevcLevelCodecProfiles)
217+
} else {
218+
add(CodecProfile().apply {
219+
type = CodecType.Video
220+
codec = Codec.Video.HEVC
221+
conditions = arrayOf(
222+
ProfileCondition(
223+
ProfileConditionType.LessThanEqual,
224+
ProfileConditionValue.VideoLevel,
225+
userHEVCLevel
226+
)
227+
)
228+
})
229+
}
230+
200231
// AV1 profile
201232
add(deviceAV1CodecProfile)
202233
// Limit video resolution support for older devices

app/src/main/res/values/strings.xml

+5
Original file line numberDiff line numberDiff line change
@@ -516,6 +516,11 @@
516516
<string name="past_24_hours">Past 24 hours</string>
517517
<string name="prefer_exoplayer_ffmpeg">Prefer FFmpeg for audio playback</string>
518518
<string name="prefer_exoplayer_ffmpeg_content">Use FFmpeg to decode audio, even if platform codecs are available.</string>
519+
<string name="codec_advanced">Advanced codec preferences</string>
520+
<string name="codec">Codec</string>
521+
<string name="user_avc_level">H.264 Level</string>
522+
<string name="user_hevc_level">H.265 Level</string>
523+
<string name="level_warning">Video\n\nSwitching from \'Auto\' could lead to playback issues</string>
519524
<plurals name="seconds">
520525
<item quantity="one">%1$s second</item>
521526
<item quantity="other">%1$s seconds</item>

0 commit comments

Comments
 (0)