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

Refactor subtitle profiles to be more readable #4210

Merged
Merged
Show file tree
Hide file tree
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
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))
}
}
Loading