Skip to content

Commit

Permalink
refactor: group multiple constructor arguments into one
Browse files Browse the repository at this point in the history
  • Loading branch information
rickysixx committed Sep 21, 2024
1 parent f53c728 commit cb6f05a
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
import org.jellyfin.androidtv.data.model.DataRefreshService;
import org.jellyfin.androidtv.preference.UserPreferences;
import org.jellyfin.androidtv.preference.UserSettingPreferences;
import org.jellyfin.androidtv.preference.constant.AudioBehavior;
import org.jellyfin.androidtv.preference.constant.NextUpBehavior;
import org.jellyfin.androidtv.preference.constant.RefreshRateSwitchingBehavior;
import org.jellyfin.androidtv.ui.livetv.TvManager;
Expand Down Expand Up @@ -521,10 +520,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,
mFragment.getContext(),
userPreferences.getValue().get(UserPreferences.Companion.getPreferExoPlayerFfmpeg())
userPreferences.getValue()
);
internalOptions.setProfile(internalProfile);
return internalOptions;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ package org.jellyfin.androidtv.util.profile

import android.content.Context
import org.jellyfin.androidtv.constant.Codec
import org.jellyfin.androidtv.preference.UserPreferences
import org.jellyfin.androidtv.preference.constant.AudioBehavior
import org.jellyfin.androidtv.util.profile.ProfileHelper.audioDirectPlayProfile
import org.jellyfin.androidtv.util.profile.ProfileHelper.deviceAV1CodecProfile
import org.jellyfin.androidtv.util.profile.ProfileHelper.deviceAVCCodecProfile
Expand All @@ -28,10 +30,8 @@ import org.jellyfin.apiclient.model.dlna.TranscodingProfile

class ExoPlayerProfile(
disableVideoDirectPlay: Boolean,
isAC3Enabled: Boolean,
downMixAudio: Boolean,
context: Context,
preferFfmpeg: Boolean,
userPreferences: UserPreferences,
) : DeviceProfile() {
private val downmixSupportedAudioCodecs = arrayOf(
Codec.Audio.AAC,
Expand All @@ -47,10 +47,10 @@ class ExoPlayerProfile(
addAll(downmixSupportedAudioCodecs)
add(Codec.Audio.AAC_LATM)
add(Codec.Audio.ALAC)
if (isAC3Enabled) add(Codec.Audio.AC3)
if (isAC3Enabled) add(Codec.Audio.EAC3)
if (userPreferences[UserPreferences.ac3Enabled]) add(Codec.Audio.AC3)
if (userPreferences[UserPreferences.ac3Enabled]) add(Codec.Audio.EAC3)
add(Codec.Audio.DCA)
if (supportsDts(context, preferFfmpeg)) add(Codec.Audio.DTS)
if (supportsDts(context, userPreferences[UserPreferences.preferExoPlayerFfmpeg])) add(Codec.Audio.DTS)
add(Codec.Audio.MLP)
add(Codec.Audio.TRUEHD)
add(Codec.Audio.PCM_ALAW)
Expand Down Expand Up @@ -83,9 +83,9 @@ class ExoPlayerProfile(
if (supportsHevc) add(Codec.Video.HEVC)
add(Codec.Video.H264)
}.joinToString(",")
audioCodec = when (downMixAudio) {
true -> downmixSupportedAudioCodecs
false -> allSupportedAudioCodecsWithoutFFmpegExperimental
audioCodec = when (userPreferences[UserPreferences.audioBehaviour]) {
AudioBehavior.DOWNMIX_TO_STEREO -> downmixSupportedAudioCodecs
AudioBehavior.DIRECT_STREAM -> allSupportedAudioCodecsWithoutFFmpegExperimental
}.joinToString(",")
protocol = "hls"
copyTimestamps = false
Expand Down Expand Up @@ -132,9 +132,9 @@ class ExoPlayerProfile(
Codec.Video.AV1
).joinToString(",")

audioCodec = when (downMixAudio) {
true -> downmixSupportedAudioCodecs
false -> allSupportedAudioCodecs
audioCodec = when (userPreferences[UserPreferences.audioBehaviour]) {
AudioBehavior.DOWNMIX_TO_STEREO -> downmixSupportedAudioCodecs
AudioBehavior.DIRECT_STREAM -> allSupportedAudioCodecs
}.joinToString(",")
})
}
Expand Down Expand Up @@ -206,7 +206,10 @@ class ExoPlayerProfile(
// Limit video resolution support for older devices
add(maxResolutionCodecProfile)
// Audio channel profile
add(maxAudioChannelsCodecProfile(channels = if (downMixAudio) 2 else 8))
add(maxAudioChannelsCodecProfile(when (userPreferences[UserPreferences.audioBehaviour]) {
AudioBehavior.DIRECT_STREAM -> 8

Check warning

Code scanning / detekt

Report magic numbers. Magic number is a numeric literal that is not defined as a constant and hence it's unclear what the purpose of this number is. It's better to declare such numbers as constants and give them a proper name. By default, -1, 0, 1, and 2 are not considered to be magic numbers. Warning

This expression contains a magic number. Consider defining it to a well named constant.
AudioBehavior.DOWNMIX_TO_STEREO -> 2
}))
}.toTypedArray()

subtitleProfiles = buildList {
Expand Down

0 comments on commit cb6f05a

Please sign in to comment.