Skip to content

Commit

Permalink
Refactor subtitle profiles to be more readable
Browse files Browse the repository at this point in the history
  • Loading branch information
nielsvanvelzen committed Nov 14, 2024
1 parent 487104f commit ea33799
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 29 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -351,6 +351,7 @@ public void setMediaStreamInfo(ApiClient api, StreamInfo streamInfo) {
.setLabel(mediaStream.getDisplayTitle())
.setSelectionFlags(getSubtitleSelectionFlags(mediaStream))
.build();
Timber.i("Adding subtitle track %s of type %s", subtitleConfiguration.uri, subtitleConfiguration.mimeType);
subtitleConfigurations.add(subtitleConfiguration);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ import org.jellyfin.apiclient.model.dlna.EncodingContext
import org.jellyfin.apiclient.model.dlna.ProfileCondition
import org.jellyfin.apiclient.model.dlna.ProfileConditionType
import org.jellyfin.apiclient.model.dlna.ProfileConditionValue
import org.jellyfin.apiclient.model.dlna.SubtitleDeliveryMethod
import org.jellyfin.apiclient.model.dlna.TranscodingProfile

class ExoPlayerProfile(
Expand Down Expand Up @@ -206,36 +205,27 @@ class ExoPlayerProfile(
}.toTypedArray()

subtitleProfiles = buildList {
// Rendering supported
arrayOf(
Codec.Subtitle.SRT,
Codec.Subtitle.SUBRIP,
Codec.Subtitle.DVBSUB,
Codec.Subtitle.VTT,
Codec.Subtitle.IDX,
).forEach { codec ->
add(subtitleProfile(codec, SubtitleDeliveryMethod.Embed))
add(subtitleProfile(codec, SubtitleDeliveryMethod.Hls))
add(subtitleProfile(codec, SubtitleDeliveryMethod.External))
}
// Jellyfin server only supports WebVTT subtitles in HLS, other text subtitles will be converted to WebVTT
// which we do not want so only allow delivery over HLS for WebVTT subtitles
subtitleProfile(Codec.Subtitle.VTT, embedded = true, hls = true, external = true)
subtitleProfile(Codec.Subtitle.WEBVTT, embedded = true, hls = true, external = true)

// Rendering supported, but needs to be embedded
arrayOf(
Codec.Subtitle.PGS,
Codec.Subtitle.PGSSUB,
).forEach { codec ->
add(subtitleProfile(codec, SubtitleDeliveryMethod.Embed))
add(subtitleProfile(codec, SubtitleDeliveryMethod.Hls))
}
subtitleProfile(Codec.Subtitle.SRT, embedded = true, external = true)
subtitleProfile(Codec.Subtitle.SUBRIP, embedded = true, external = true)
subtitleProfile(Codec.Subtitle.TTML, embedded = true, external = true)

// Require baking
arrayOf(
Codec.Subtitle.ASS,
Codec.Subtitle.SSA,
Codec.Subtitle.DVDSUB,
).forEach { codec ->
add(subtitleProfile(codec, SubtitleDeliveryMethod.Encode))
}
// Not all subtitles can be loaded standalone by the player
subtitleProfile(Codec.Subtitle.DVBSUB, embedded = true, encode = true)
subtitleProfile(Codec.Subtitle.IDX, embedded = true, encode = true)
subtitleProfile(Codec.Subtitle.PGS, embedded = true, encode = true)
subtitleProfile(Codec.Subtitle.PGSSUB, embedded = true, encode = true)

// ASS/SSA renderer only supports a small subset of the specification so encoding is required for correct rendering
subtitleProfile(Codec.Subtitle.ASS, encode = true)
subtitleProfile(Codec.Subtitle.SSA, encode = true)

// Unsupported formats that need encoding
subtitleProfile(Codec.Subtitle.DVDSUB, encode = true)
}.toTypedArray()
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ object ProfileHelper {
)
)
}

!MediaTest.supportsAV1Main10() -> {
Timber.i("*** Does NOT support AV1 10 bit")
arrayOf(
Expand All @@ -43,6 +44,7 @@ object ProfileHelper {
)
)
}

else -> {
// supports all AV1
Timber.i("*** Supports AV1 10 bit")
Expand Down Expand Up @@ -83,6 +85,7 @@ object ProfileHelper {
)
)
}

else -> {
// If AVC is supported, include all relevant profiles
Timber.i("*** Supports AVC")
Expand Down Expand Up @@ -184,6 +187,7 @@ object ProfileHelper {
)
)
}

else -> {
// If HEVC is supported, include all relevant profiles
Timber.i("*** Supports HEVC 10 bit")
Expand Down Expand Up @@ -310,4 +314,17 @@ object ProfileHelper {
this.format = format
this.method = method
}

internal fun MutableList<SubtitleProfile>.subtitleProfile(
format: String,
embedded: Boolean = false,
external: Boolean = false,
hls: Boolean = false,
encode: Boolean = false,
) {
if (embedded) add(subtitleProfile(format, SubtitleDeliveryMethod.Embed))
if (external) add(subtitleProfile(format, SubtitleDeliveryMethod.External))
if (hls) add(subtitleProfile(format, SubtitleDeliveryMethod.Hls))
if (encode) add(subtitleProfile(format, SubtitleDeliveryMethod.Encode))
}
}

0 comments on commit ea33799

Please sign in to comment.