Fixed subtitle elevation again

This commit is contained in:
Blatzar 2022-12-03 02:42:16 +01:00
parent e215747749
commit b79e2d768f

View file

@ -15,6 +15,8 @@
*/
package com.lagradost.cloudstream3.ui.player;
import static com.google.android.exoplayer2.text.Cue.DIMEN_UNSET;
import static com.google.android.exoplayer2.text.Cue.LINE_TYPE_NUMBER;
import static com.google.android.exoplayer2.util.Assertions.checkNotNull;
import static com.google.android.exoplayer2.util.Assertions.checkState;
import static java.lang.annotation.ElementType.TYPE_USE;
@ -23,8 +25,10 @@ import android.os.Handler;
import android.os.Handler.Callback;
import android.os.Looper;
import android.os.Message;
import androidx.annotation.IntDef;
import androidx.annotation.Nullable;
import com.google.android.exoplayer2.BaseRenderer;
import com.google.android.exoplayer2.C;
import com.google.android.exoplayer2.Format;
@ -43,13 +47,17 @@ import com.google.android.exoplayer2.text.TextOutput;
import com.google.android.exoplayer2.util.Log;
import com.google.android.exoplayer2.util.MimeTypes;
import com.google.android.exoplayer2.util.Util;
import java.lang.annotation.Documented;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
import java.util.Collections;
import java.util.List;
import java.util.stream.Collectors;
// DO NOT CONVERT TO KOTLIN AUTOMATICALLY, IT FUCKS UP AND DOES NOT DISPLAY SUBS FOR SOME REASON
// IF YOU CHANGE THE CODE MAKE SURE YOU GET THE CUES CORRECT!
/**
* A renderer for text.
*
@ -79,8 +87,12 @@ public class NonFinalTextRenderer extends BaseRenderer implements Callback {
REPLACEMENT_STATE_SIGNAL_END_OF_STREAM,
REPLACEMENT_STATE_WAIT_END_OF_STREAM
})
private @interface ReplacementState {}
/** The decoder does not need to be replaced. */
private @interface ReplacementState {
}
/**
* The decoder does not need to be replaced.
*/
private static final int REPLACEMENT_STATE_NONE = 0;
/**
* The decoder needs to be replaced, but we haven't yet signaled an end of stream to the existing
@ -97,7 +109,8 @@ public class NonFinalTextRenderer extends BaseRenderer implements Callback {
private static final int MSG_UPDATE_OUTPUT = 0;
@Nullable private final Handler outputHandler;
@Nullable
private final Handler outputHandler;
private TextOutput output = null;
private SubtitleDecoderFactory decoderFactory = null;
private FormatHolder formatHolder = null;
@ -106,11 +119,16 @@ public class NonFinalTextRenderer extends BaseRenderer implements Callback {
private boolean outputStreamEnded;
private boolean waitingForKeyFrame;
private @ReplacementState int decoderReplacementState;
@Nullable private Format streamFormat;
@Nullable private SubtitleDecoder decoder;
@Nullable private SubtitleInputBuffer nextInputBuffer;
@Nullable private SubtitleOutputBuffer subtitle;
@Nullable private SubtitleOutputBuffer nextSubtitle;
@Nullable
private Format streamFormat;
@Nullable
private SubtitleDecoder decoder;
@Nullable
private SubtitleInputBuffer nextInputBuffer;
@Nullable
private SubtitleOutputBuffer subtitle;
@Nullable
private SubtitleOutputBuffer nextSubtitle;
private int nextSubtitleEventIndex;
private long finalStreamEndPositionUs;
@ -405,8 +423,23 @@ public class NonFinalTextRenderer extends BaseRenderer implements Callback {
}
private void invokeUpdateOutputInternal(List<Cue> cues) {
output.onCues(cues);
output.onCues(new CueGroup(cues));
// 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
List<Cue> fixedCues = cues.stream().map(
cue -> {
Cue.Builder builder = cue.buildUpon();
if (cue.line == DIMEN_UNSET)
builder.setLine(-1f, LINE_TYPE_NUMBER);
return builder.setSize(DIMEN_UNSET).build();
}
).collect(Collectors.toList());
output.onCues(fixedCues);
output.onCues(new CueGroup(fixedCues));
}
/**