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 resolution codec check #3953

Merged
merged 4 commits into from
Sep 8, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
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 @@ -24,12 +24,12 @@
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;
import org.jellyfin.androidtv.util.apiclient.StreamHelper;
import org.jellyfin.androidtv.util.profile.ExoPlayerProfile;
import org.jellyfin.androidtv.util.profile.MediaCodecCapabilitiesTest;
import org.jellyfin.androidtv.util.sdk.compat.JavaCompat;
import org.jellyfin.apiclient.interaction.ApiClient;
import org.jellyfin.apiclient.interaction.Response;
Expand Down Expand Up @@ -509,6 +509,7 @@ public void onClick(DialogInterface dialog, int which) {

@NonNull
private VideoOptions buildExoPlayerOptions(@Nullable Integer forcedSubtitleIndex, BaseItemDto item, int maxBitrate) {
MediaCodecCapabilitiesTest mediaCodecCapabilitiesTest = new MediaCodecCapabilitiesTest();
VideoOptions internalOptions = new VideoOptions();
internalOptions.setItemId(item.getId());
internalOptions.setMediaSources(item.getMediaSources());
Expand All @@ -524,7 +525,7 @@ private VideoOptions buildExoPlayerOptions(@Nullable Integer forcedSubtitleIndex
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()
!mediaCodecCapabilitiesTest.supports4KResolution()
);
internalOptions.setProfile(internalProfile);
return internalOptions;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -165,4 +165,31 @@

return false
}

fun supports4KResolution(): Boolean {
Fixed Show fixed Hide fixed
for (info in mediaCodecList.codecInfos) {

Check warning

Code scanning / detekt

The loop contains more than one break or continue statement. The code should be refactored to increase readability. Warning

The loop contains more than one break or continue statement. The code should be refactored to increase readability.
if (info.isEncoder) continue

try {
val capabilities = info.getCapabilitiesForType(MediaFormat.MIMETYPE_VIDEO_AVC)
MichaelRUSF marked this conversation as resolved.
Show resolved Hide resolved
val videoCapabilities = capabilities.videoCapabilities

if (videoCapabilities != null) {
// Get the supported width and height ranges
val maxWidth = videoCapabilities.supportedWidths?.upper ?: 0
val maxHeight = videoCapabilities.supportedHeights?.upper ?: 0

// Check for 4K resolution support
if (maxWidth >= 3840 && maxHeight >= 2160) {
Fixed Show fixed Hide fixed
Fixed Show fixed Hide fixed
Timber.i("4K resolution is supported by codec %s", info.name)
return true
}
}
} catch (e: IllegalArgumentException) {
Timber.d(e, "Codec %s does not support video capabilities", info.name)
}
}

return false
}
}
Loading