Fixed inconsistent subtitle padding (exoplayer was wack)

Fixes #1074
This commit is contained in:
Blatzar 2022-06-19 01:55:29 +02:00
parent cc7d7ec478
commit f5545a10f5
2 changed files with 24 additions and 7 deletions

View file

@ -73,7 +73,7 @@ class CustomDecoder : SubtitleDecoder {
private var realDecoder: SubtitleDecoder? = null
override fun getName(): String {
return realDecoder?.name ?: this::class.java.name
return realDecoder?.name ?: this::javaClass.name
}
override fun dequeueInputBuffer(): SubtitleInputBuffer {
@ -127,6 +127,11 @@ class CustomDecoder : SubtitleDecoder {
}
}
private fun SubtitleInputBuffer.setSubtitleText(text: String) {
// println("Set subtitle text -----\n$text\n-----")
this.data = ByteBuffer.wrap(text.toByteArray(charset(UTF_8)))
}
override fun queueInputBuffer(inputBuffer: SubtitleInputBuffer) {
Log.i(TAG, "queueInputBuffer")
try {
@ -152,7 +157,7 @@ class CustomDecoder : SubtitleDecoder {
)
realDecoder?.let { decoder ->
decoder.dequeueInputBuffer()?.let { buff ->
if (decoder::class.java != SsaDecoder::class.java) {
if (decoder !is SsaDecoder) {
if (regexSubtitlesToRemoveCaptions)
captionRegex.forEach { rgx ->
str = str.replace(rgx, "\n")
@ -162,8 +167,7 @@ class CustomDecoder : SubtitleDecoder {
str = str.replace(rgx, "\n")
}
}
buff.data = ByteBuffer.wrap(str.toByteArray(charset(UTF_8)))
buff.setSubtitleText(str)
decoder.queueInputBuffer(buff)
Log.i(
TAG,
@ -180,7 +184,7 @@ class CustomDecoder : SubtitleDecoder {
if (!inputString.isNullOrBlank()) {
var str: String = inputString
if (realDecoder!!::class.java != SsaDecoder::class.java) {
if (realDecoder !is SsaDecoder) {
if (regexSubtitlesToRemoveCaptions)
captionRegex.forEach { rgx ->
str = str.replace(rgx, "\n")
@ -190,7 +194,7 @@ class CustomDecoder : SubtitleDecoder {
str = str.replace(rgx, "\n")
}
}
inputBuffer.data = ByteBuffer.wrap(str.toByteArray(charset(UTF_8)))
inputBuffer.setSubtitleText(str)
}
realDecoder?.queueInputBuffer(inputBuffer)

View file

@ -22,6 +22,8 @@ import androidx.annotation.IntDef
import com.google.android.exoplayer2.*
import com.google.android.exoplayer2.source.SampleStream.ReadDataResult
import com.google.android.exoplayer2.text.*
import com.google.android.exoplayer2.text.Cue.DIMEN_UNSET
import com.google.android.exoplayer2.text.Cue.LINE_TYPE_NUMBER
import com.google.android.exoplayer2.util.Assertions
import com.google.android.exoplayer2.util.Log
import com.google.android.exoplayer2.util.MimeTypes
@ -308,7 +310,18 @@ open class NonFinalTextRenderer @JvmOverloads constructor(
}
private fun invokeUpdateOutputInternal(cues: List<Cue>) {
output.onCues(cues.map { cue -> cue.buildUpon().setSize(Cue.DIMEN_UNSET).build() }) // this fixes https://github.com/LagradOst/CloudStream-3/issues/717
output.onCues(cues.map { cue ->
val builder = cue.buildUpon()
// See https://github.com/google/ExoPlayer/issues/7934
// SubripDecoder texts tend to be DIMEN_UNSET which pushes up the
// subs unlike WEBVTT which creates an inconsistency
if (cue.line == DIMEN_UNSET)
builder.setLine(-1f, LINE_TYPE_NUMBER)
// this fixes https://github.com/LagradOst/CloudStream-3/issues/717
builder.setSize(DIMEN_UNSET).build()
})
}
/**