Skip to content

Commit

Permalink
Add resolution codec check (#3953)
Browse files Browse the repository at this point in the history
* Add 4k resolution codec check

* 4k profile check

* Apply review changes

* Remove hard-coded resolutions
  • Loading branch information
MichaelRUSF authored Sep 8, 2024
1 parent cd8e619 commit 706b645
Show file tree
Hide file tree
Showing 4 changed files with 48 additions and 24 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@
import org.jellyfin.androidtv.preference.constant.NextUpBehavior;
import org.jellyfin.androidtv.preference.constant.RefreshRateSwitchingBehavior;
import org.jellyfin.androidtv.ui.livetv.TvManager;
import org.jellyfin.androidtv.util.DeviceUtils;
import org.jellyfin.androidtv.util.TimeUtils;
import org.jellyfin.androidtv.util.Utils;
import org.jellyfin.androidtv.util.apiclient.ReportingHelper;
Expand Down Expand Up @@ -523,8 +522,7 @@ 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,
!DeviceUtils.has4kVideoSupport()
userPreferences.getValue().get(UserPreferences.Companion.getAudioBehaviour()) == AudioBehavior.DOWNMIX_TO_STEREO
);
internalOptions.setProfile(internalProfile);
return internalOptions;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import org.jellyfin.androidtv.util.profile.ProfileHelper.deviceAVCCodecProfile
import org.jellyfin.androidtv.util.profile.ProfileHelper.deviceAVCLevelCodecProfiles
import org.jellyfin.androidtv.util.profile.ProfileHelper.deviceHevcCodecProfile
import org.jellyfin.androidtv.util.profile.ProfileHelper.deviceHevcLevelCodecProfiles
import org.jellyfin.androidtv.util.profile.ProfileHelper.max1080pProfileConditions
import org.jellyfin.androidtv.util.profile.ProfileHelper.maxResolutionCodecProfile
import org.jellyfin.androidtv.util.profile.ProfileHelper.maxAudioChannelsCodecProfile
import org.jellyfin.androidtv.util.profile.ProfileHelper.photoDirectPlayProfile
import org.jellyfin.androidtv.util.profile.ProfileHelper.subtitleProfile
Expand All @@ -27,8 +27,7 @@ import org.jellyfin.apiclient.model.dlna.TranscodingProfile
class ExoPlayerProfile(
disableVideoDirectPlay: Boolean,
isAC3Enabled: Boolean,
downMixAudio: Boolean,
disable4KVideo: Boolean
downMixAudio: Boolean
) : DeviceProfile() {
private val downmixSupportedAudioCodecs = arrayOf(
Codec.Audio.AAC,
Expand Down Expand Up @@ -200,12 +199,7 @@ class ExoPlayerProfile(
// AV1 profile
add(deviceAV1CodecProfile)
// Limit video resolution support for older devices
if (disable4KVideo) {
add(CodecProfile().apply {
type = CodecType.Video
conditions = max1080pProfileConditions
})
}
add(maxResolutionCodecProfile)
// Audio channel profile
add(maxAudioChannelsCodecProfile(channels = if (downMixAudio) 2 else 8))
}.toTypedArray()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import android.media.MediaCodecInfo.CodecProfileLevel
import android.media.MediaCodecList
import android.media.MediaFormat
import android.os.Build
import android.util.Size
import timber.log.Timber

class MediaCodecCapabilitiesTest {
Expand Down Expand Up @@ -165,4 +166,29 @@ class MediaCodecCapabilitiesTest {

return false
}

fun getMaxResolution(mime: String): Size {
var maxWidth = 0
var maxHeight = 0

for (info in mediaCodecList.codecInfos) {
if (info.isEncoder) continue

try {
val capabilities = info.getCapabilitiesForType(mime)
val videoCapabilities = capabilities.videoCapabilities ?: continue
val supportedWidth = videoCapabilities.supportedWidths?.upper ?: continue
val supportedHeight = videoCapabilities.supportedHeights?.upper ?: continue

maxWidth = maxOf(maxWidth, supportedWidth)
maxHeight = maxOf(maxHeight, supportedHeight)

} catch (e: IllegalArgumentException) {
Timber.d(e, "Codec %s does not support video capabilities", info.name)
}
}

return Size(maxWidth, maxHeight)
}

}
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package org.jellyfin.androidtv.util.profile

import android.media.MediaFormat
import org.jellyfin.androidtv.constant.Codec
import org.jellyfin.apiclient.model.dlna.CodecProfile
import org.jellyfin.apiclient.model.dlna.CodecType
Expand Down Expand Up @@ -251,19 +252,24 @@ object ProfileHelper {
}
}

val max1080pProfileConditions by lazy {
arrayOf(
ProfileCondition(
ProfileConditionType.LessThanEqual,
ProfileConditionValue.Width,
"1920"
),
ProfileCondition(
ProfileConditionType.LessThanEqual,
ProfileConditionValue.Height,
"1080"
val maxResolutionCodecProfile by lazy {
val maxResolution = MediaTest.getMaxResolution(MediaFormat.MIMETYPE_VIDEO_AVC)

CodecProfile().apply {
type = CodecType.Video
conditions = arrayOf(
ProfileCondition(
ProfileConditionType.LessThanEqual,
ProfileConditionValue.Width,
maxResolution.width.toString()
),
ProfileCondition(
ProfileConditionType.LessThanEqual,
ProfileConditionValue.Height,
maxResolution.height.toString()
)
)
)
}
}

val photoDirectPlayProfile by lazy {
Expand Down

0 comments on commit 706b645

Please sign in to comment.