forked from recloudstream/cloudstream
Fixed subtitle elevation again
This commit is contained in:
parent
e215747749
commit
b79e2d768f
1 changed files with 366 additions and 333 deletions
|
@ -15,6 +15,8 @@
|
||||||
*/
|
*/
|
||||||
package com.lagradost.cloudstream3.ui.player;
|
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.checkNotNull;
|
||||||
import static com.google.android.exoplayer2.util.Assertions.checkState;
|
import static com.google.android.exoplayer2.util.Assertions.checkState;
|
||||||
import static java.lang.annotation.ElementType.TYPE_USE;
|
import static java.lang.annotation.ElementType.TYPE_USE;
|
||||||
|
@ -23,8 +25,10 @@ import android.os.Handler;
|
||||||
import android.os.Handler.Callback;
|
import android.os.Handler.Callback;
|
||||||
import android.os.Looper;
|
import android.os.Looper;
|
||||||
import android.os.Message;
|
import android.os.Message;
|
||||||
|
|
||||||
import androidx.annotation.IntDef;
|
import androidx.annotation.IntDef;
|
||||||
import androidx.annotation.Nullable;
|
import androidx.annotation.Nullable;
|
||||||
|
|
||||||
import com.google.android.exoplayer2.BaseRenderer;
|
import com.google.android.exoplayer2.BaseRenderer;
|
||||||
import com.google.android.exoplayer2.C;
|
import com.google.android.exoplayer2.C;
|
||||||
import com.google.android.exoplayer2.Format;
|
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.Log;
|
||||||
import com.google.android.exoplayer2.util.MimeTypes;
|
import com.google.android.exoplayer2.util.MimeTypes;
|
||||||
import com.google.android.exoplayer2.util.Util;
|
import com.google.android.exoplayer2.util.Util;
|
||||||
|
|
||||||
import java.lang.annotation.Documented;
|
import java.lang.annotation.Documented;
|
||||||
import java.lang.annotation.Retention;
|
import java.lang.annotation.Retention;
|
||||||
import java.lang.annotation.RetentionPolicy;
|
import java.lang.annotation.RetentionPolicy;
|
||||||
import java.lang.annotation.Target;
|
import java.lang.annotation.Target;
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
import java.util.List;
|
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
|
// 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.
|
* A renderer for text.
|
||||||
*
|
*
|
||||||
|
@ -79,8 +87,12 @@ public class NonFinalTextRenderer extends BaseRenderer implements Callback {
|
||||||
REPLACEMENT_STATE_SIGNAL_END_OF_STREAM,
|
REPLACEMENT_STATE_SIGNAL_END_OF_STREAM,
|
||||||
REPLACEMENT_STATE_WAIT_END_OF_STREAM
|
REPLACEMENT_STATE_WAIT_END_OF_STREAM
|
||||||
})
|
})
|
||||||
private @interface ReplacementState {}
|
private @interface ReplacementState {
|
||||||
/** The decoder does not need to be replaced. */
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The decoder does not need to be replaced.
|
||||||
|
*/
|
||||||
private static final int REPLACEMENT_STATE_NONE = 0;
|
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
|
* 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;
|
private static final int MSG_UPDATE_OUTPUT = 0;
|
||||||
|
|
||||||
@Nullable private final Handler outputHandler;
|
@Nullable
|
||||||
|
private final Handler outputHandler;
|
||||||
private TextOutput output = null;
|
private TextOutput output = null;
|
||||||
private SubtitleDecoderFactory decoderFactory = null;
|
private SubtitleDecoderFactory decoderFactory = null;
|
||||||
private FormatHolder formatHolder = null;
|
private FormatHolder formatHolder = null;
|
||||||
|
@ -106,11 +119,16 @@ public class NonFinalTextRenderer extends BaseRenderer implements Callback {
|
||||||
private boolean outputStreamEnded;
|
private boolean outputStreamEnded;
|
||||||
private boolean waitingForKeyFrame;
|
private boolean waitingForKeyFrame;
|
||||||
private @ReplacementState int decoderReplacementState;
|
private @ReplacementState int decoderReplacementState;
|
||||||
@Nullable private Format streamFormat;
|
@Nullable
|
||||||
@Nullable private SubtitleDecoder decoder;
|
private Format streamFormat;
|
||||||
@Nullable private SubtitleInputBuffer nextInputBuffer;
|
@Nullable
|
||||||
@Nullable private SubtitleOutputBuffer subtitle;
|
private SubtitleDecoder decoder;
|
||||||
@Nullable private SubtitleOutputBuffer nextSubtitle;
|
@Nullable
|
||||||
|
private SubtitleInputBuffer nextInputBuffer;
|
||||||
|
@Nullable
|
||||||
|
private SubtitleOutputBuffer subtitle;
|
||||||
|
@Nullable
|
||||||
|
private SubtitleOutputBuffer nextSubtitle;
|
||||||
private int nextSubtitleEventIndex;
|
private int nextSubtitleEventIndex;
|
||||||
private long finalStreamEndPositionUs;
|
private long finalStreamEndPositionUs;
|
||||||
|
|
||||||
|
@ -405,8 +423,23 @@ public class NonFinalTextRenderer extends BaseRenderer implements Callback {
|
||||||
}
|
}
|
||||||
|
|
||||||
private void invokeUpdateOutputInternal(List<Cue> cues) {
|
private void invokeUpdateOutputInternal(List<Cue> cues) {
|
||||||
output.onCues(cues);
|
// See https://github.com/google/ExoPlayer/issues/7934
|
||||||
output.onCues(new CueGroup(cues));
|
// 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));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
Loading…
Reference in a new issue