Skip to content

Commit

Permalink
Fix code style issues
Browse files Browse the repository at this point in the history
  • Loading branch information
thornbill committed May 21, 2021
1 parent 2b79c32 commit db6303b
Show file tree
Hide file tree
Showing 3 changed files with 61 additions and 53 deletions.
Expand Up @@ -9,11 +9,12 @@ import org.jellyfin.apiclient.model.dlna.EncodingContext
import org.jellyfin.apiclient.model.dlna.SubtitleDeliveryMethod
import org.jellyfin.apiclient.model.dlna.TranscodingProfile

@Suppress("MagicNumber")
open class BaseProfile : DeviceProfile() {
init {
name = "AndroidTV"
maxStreamingBitrate = 20000000
maxStaticBitrate = 100000000
maxStreamingBitrate = 20_000_000 // 20 mbps
maxStaticBitrate = 10_000_0000 // 10 mbps

transcodingProfiles = arrayOf(
// MKV video profile
Expand Down
Expand Up @@ -10,10 +10,11 @@ import org.jellyfin.apiclient.model.dlna.EncodingContext
import org.jellyfin.apiclient.model.dlna.SubtitleDeliveryMethod
import org.jellyfin.apiclient.model.dlna.TranscodingProfile

@Suppress("MagicNumber")
class ExternalPlayerProfile : DeviceProfile() {
init {
name = "AndroidTV-External"
maxStaticBitrate = 100000000
maxStaticBitrate = 100_000_000 // 100 mbps

directPlayProfiles = arrayOf(
DirectPlayProfile().apply {
Expand Down
106 changes: 56 additions & 50 deletions app/src/main/java/org/jellyfin/androidtv/util/profile/ProfileHelper.kt
Expand Up @@ -15,67 +15,73 @@ import org.jellyfin.apiclient.model.dlna.TranscodingProfile
import timber.log.Timber

object ProfileHelper {
private val MediaTest = MediaCodecCapabilitiesTest()
private val MediaTest by lazy { MediaCodecCapabilitiesTest() }

val deviceHevcCodecProfile = CodecProfile().apply {
type = CodecType.Video
codec = CodecTypes.HEVC
val deviceHevcCodecProfile by lazy {
CodecProfile().apply {
type = CodecType.Video
codec = CodecTypes.HEVC

conditions = if (!MediaTest.supportsHevc()) {
// The following condition is a method to exclude all HEVC
Timber.i("*** Does NOT support HEVC")
arrayOf(
ProfileCondition(
ProfileConditionType.Equals,
ProfileConditionValue.VideoProfile,
"none"
)
)
} else if (!MediaTest.supportsHevcMain10()) {
Timber.i("*** Does NOT support HEVC 10 bit")
arrayOf(
ProfileCondition(
ProfileConditionType.NotEquals,
ProfileConditionValue.VideoProfile,
"Main 10"
)
)
} else {
// supports all HEVC
Timber.i("*** Supports HEVC 10 bit")
arrayOf(
ProfileCondition(
ProfileConditionType.NotEquals,
ProfileConditionValue.VideoProfile,
"none"
)
)
conditions = when {
!MediaTest.supportsHevc() -> {
// The following condition is a method to exclude all HEVC
Timber.i("*** Does NOT support HEVC")
arrayOf(
ProfileCondition(
ProfileConditionType.Equals,
ProfileConditionValue.VideoProfile,
"none"
)
)
}
!MediaTest.supportsHevcMain10() -> {
Timber.i("*** Does NOT support HEVC 10 bit")
arrayOf(
ProfileCondition(
ProfileConditionType.NotEquals,
ProfileConditionValue.VideoProfile,
"Main 10"
)
)
}
else -> {
// supports all HEVC
Timber.i("*** Supports HEVC 10 bit")
arrayOf(
ProfileCondition(
ProfileConditionType.NotEquals,
ProfileConditionValue.VideoProfile,
"none"
)
)
}
}
}
}

@JvmStatic
fun addAc3Streaming(profile: DeviceProfile, primary: Boolean) {
if (Utils.downMixAudio()) return

val mkvProfile = findTranscodingProfile(profile, ContainerTypes.MKV)
if (mkvProfile != null) {
Timber.i("*** Adding AC3 as supported transcoded audio")
mkvProfile.audioCodec = if (primary) {
"${CodecTypes.AC3},${mkvProfile.audioCodec}"
} else {
"${mkvProfile.audioCodec},${CodecTypes.AC3}"
}
val mkvProfile = findTranscodingProfile(profile, ContainerTypes.MKV) ?: return

Timber.i("*** Adding AC3 as supported transcoded audio")
mkvProfile.audioCodec = when (primary) {
true -> "${CodecTypes.AC3},${mkvProfile.audioCodec}"
false -> "${mkvProfile.audioCodec},${CodecTypes.AC3}"
}
}

private fun findTranscodingProfile(deviceProfile: DeviceProfile, container: String) = (
deviceProfile.transcodingProfiles.find { it.container == container }
)
private fun findTranscodingProfile(
deviceProfile: DeviceProfile,
container: String
) = deviceProfile.transcodingProfiles.find { it.container == container }

internal fun subtitleProfile(format: String, method: SubtitleDeliveryMethod) = (
SubtitleProfile().apply {
this.format = format
this.method = method
}
)
internal fun subtitleProfile(
format: String,
method: SubtitleDeliveryMethod
) = SubtitleProfile().apply {
this.format = format
this.method = method
}
}

0 comments on commit db6303b

Please sign in to comment.