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

ExoPlayer: Only allow hardware-accelerated video codecs in DirectPlay #1135

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
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
@@ -1,6 +1,8 @@
package org.jellyfin.mobile.player.deviceprofile

import android.media.MediaCodecList
import android.os.Build
import com.google.android.exoplayer2.util.MimeTypes
import org.jellyfin.mobile.app.AppPreferences
import org.jellyfin.mobile.utils.Constants
import org.jellyfin.sdk.model.api.CodecProfile
Expand Down Expand Up @@ -57,7 +59,7 @@ class DeviceProfileBuilder(
// Build map of supported codecs from device support and hardcoded data
supportedVideoCodecs = Array(AVAILABLE_VIDEO_CODECS.size) { i ->
AVAILABLE_VIDEO_CODECS[i].filter { codec ->
videoCodecs.containsKey(codec)
videoCodecs.containsKey(codec) && canHardwareDecode(codec)
}.toTypedArray()
}
supportedAudioCodecs = Array(AVAILABLE_AUDIO_CODECS.size) { i ->
Expand Down Expand Up @@ -94,6 +96,22 @@ class DeviceProfileBuilder(
)
}

private fun canHardwareDecode(codec: String): Boolean {
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.Q) return true
val parsedCodec = when(codec) {
"mpeg4" -> "avc1"
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

mpeg4 might not be the same as h264, so this line might need to go

Suggested change
"mpeg4" -> "avc1"

i weren't really sure about this, there's a lot of conflicting information out there about how mpeg4 and h264 relate 🤔

"h264" -> "avc1"
"hevc" -> "hvc1"
"av1" -> "av01"
else -> codec
}
val mimeType = MimeTypes.getMediaMimeType(parsedCodec) ?: return false
val hardwareCodec = MediaCodecList(MediaCodecList.REGULAR_CODECS).codecInfos
.filter { it.isHardwareAccelerated }
.find { it.supportedTypes.contains(mimeType) }
return hardwareCodec != null
}

fun getDeviceProfile(): DeviceProfile {
val containerProfiles = ArrayList<ContainerProfile>()
val directPlayProfiles = ArrayList<DirectPlayProfile>()
Expand Down