From f523e1760b7f5e221ac34c3c75919f24741cb31d Mon Sep 17 00:00:00 2001 From: Levon Date: Sun, 19 May 2024 16:36:48 -0500 Subject: [PATCH 1/3] only direct play hardware supported video codec --- .../deviceprofile/DeviceProfileBuilder.kt | 59 ++++++++++++++++++- 1 file changed, 57 insertions(+), 2 deletions(-) diff --git a/app/src/main/java/org/jellyfin/mobile/player/deviceprofile/DeviceProfileBuilder.kt b/app/src/main/java/org/jellyfin/mobile/player/deviceprofile/DeviceProfileBuilder.kt index a1152bfb7..781609db4 100644 --- a/app/src/main/java/org/jellyfin/mobile/player/deviceprofile/DeviceProfileBuilder.kt +++ b/app/src/main/java/org/jellyfin/mobile/player/deviceprofile/DeviceProfileBuilder.kt @@ -1,6 +1,8 @@ package org.jellyfin.mobile.player.deviceprofile +import android.media.MediaCodecInfo import android.media.MediaCodecList +import android.os.Build import org.jellyfin.mobile.app.AppPreferences import org.jellyfin.mobile.utils.Constants import org.jellyfin.sdk.model.api.CodecProfile @@ -11,6 +13,7 @@ import org.jellyfin.sdk.model.api.DlnaProfileType import org.jellyfin.sdk.model.api.SubtitleDeliveryMethod import org.jellyfin.sdk.model.api.SubtitleProfile import org.jellyfin.sdk.model.api.TranscodingProfile +import java.util.Locale class DeviceProfileBuilder( private val appPreferences: AppPreferences, @@ -37,11 +40,15 @@ class DeviceProfileBuilder( val name = codec.name when (codec) { is DeviceCodec.Video -> { - if (videoCodecs.containsKey(name)) { + if (videoCodecs.containsKey(name) && !isSoftwareOnly(codecInfo)) { videoCodecs[name] = videoCodecs[name]!!.mergeCodec(codec) - } else { + } + else if (!isSoftwareOnly(codecInfo)){ videoCodecs[name] = codec } + else { + // do nothing + } } is DeviceCodec.Audio -> { if (audioCodecs.containsKey(mimeType)) { @@ -158,6 +165,54 @@ class DeviceProfileBuilder( } } + // taken from https://github.com/Parseus/codecinfo + private fun isSoftwareOnly(codecInfo: MediaCodecInfo): Boolean { + if (Build.VERSION.SDK_INT >= 29) { + return codecInfo.isSoftwareOnly + } + + val codecName = codecInfo.name.lowercase(Locale.ENGLISH) + + // Broadcom codecs which specifically mention HW acceleration in their names + if (codecName.contains("omx.brcm.video", true) && codecName.contains("hw", true)) { + return false + } + + // Marvell codecs which specifically mention HW acceleration in their names + if (codecName.startsWith("omx.marvell.video.hw", true)) { + return false + } + + // Intel codecs which specifically mention HW acceleration in their names + if (codecName.startsWith("omx.intel.hw_vd", true)) { + return false + } + + // Qualcomm codecs which specifically mention HW acceleration in their names + if (codecName.startsWith("omx.qcom") && codecName.endsWith("hw")) { + return false + } + + // ARC/ARC++ (App Runtime for Chrome) codecs are always HW-only. + if (codecName.startsWith("c2.vda.arc") || codecName.startsWith("arc.")) { + return false + } + + return codecName.startsWith("omx.google.") + || codecName.contains("ffmpeg") // either OMX.ffmpeg or OMX.k3.ffmpeg + || (codecName.startsWith("omx.sec.") && codecName.contains(".sw.")) + || codecName == "omx.qcom.video.decoder.hevcswvdec" + || codecName.startsWith("c2.android.") + || codecName.startsWith("c2.google.") + || codecName.startsWith("omx.sprd.soft.") + || codecName.startsWith("omx.avcodec.") + || codecName.startsWith("omx.pv") + || codecName.endsWith("sw", true) + || codecName.endsWith("sw.dec", true) + || codecName.contains("sw_vd", true) + || (!codecName.startsWith("omx.") && !codecName.startsWith("c2.")) + } + fun getExternalPlayerProfile(): DeviceProfile = DeviceProfile( name = EXTERNAL_PLAYER_PROFILE_NAME, directPlayProfiles = listOf( From 190f8d58b622de0623c9202147ee4bc61e0a4221 Mon Sep 17 00:00:00 2001 From: Levon Date: Mon, 20 May 2024 07:12:06 -0500 Subject: [PATCH 2/3] better video builder logic --- .../player/deviceprofile/DeviceProfileBuilder.kt | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/app/src/main/java/org/jellyfin/mobile/player/deviceprofile/DeviceProfileBuilder.kt b/app/src/main/java/org/jellyfin/mobile/player/deviceprofile/DeviceProfileBuilder.kt index 781609db4..7e61570b1 100644 --- a/app/src/main/java/org/jellyfin/mobile/player/deviceprofile/DeviceProfileBuilder.kt +++ b/app/src/main/java/org/jellyfin/mobile/player/deviceprofile/DeviceProfileBuilder.kt @@ -40,14 +40,14 @@ class DeviceProfileBuilder( val name = codec.name when (codec) { is DeviceCodec.Video -> { - if (videoCodecs.containsKey(name) && !isSoftwareOnly(codecInfo)) { - videoCodecs[name] = videoCodecs[name]!!.mergeCodec(codec) + if (isSoftwareOnly(codecInfo)) { + continue } - else if (!isSoftwareOnly(codecInfo)){ - videoCodecs[name] = codec + if (videoCodecs.containsKey(name)) { + videoCodecs[name] = videoCodecs[name]!!.mergeCodec(codec) } else { - // do nothing + videoCodecs[name] = codec } } is DeviceCodec.Audio -> { From d05502e25d11fc90478f9b325c966be22b40c639 Mon Sep 17 00:00:00 2001 From: Levon Date: Tue, 21 May 2024 07:24:27 -0500 Subject: [PATCH 3/3] revert code formatting --- .../mobile/player/deviceprofile/DeviceProfileBuilder.kt | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/app/src/main/java/org/jellyfin/mobile/player/deviceprofile/DeviceProfileBuilder.kt b/app/src/main/java/org/jellyfin/mobile/player/deviceprofile/DeviceProfileBuilder.kt index 7e61570b1..85918436e 100644 --- a/app/src/main/java/org/jellyfin/mobile/player/deviceprofile/DeviceProfileBuilder.kt +++ b/app/src/main/java/org/jellyfin/mobile/player/deviceprofile/DeviceProfileBuilder.kt @@ -45,8 +45,7 @@ class DeviceProfileBuilder( } if (videoCodecs.containsKey(name)) { videoCodecs[name] = videoCodecs[name]!!.mergeCodec(codec) - } - else { + } else { videoCodecs[name] = codec } }