mirror of
https://github.com/samsonjs/media.git
synced 2026-04-27 15:07:40 +00:00
Fix 2 CEA decoder bugs
1- Avoid dropped buffers by using a PriorityQueue instead of a set. 2- Process the end of stream after non-EOS buffers. Issue:#3250 ------------- Created by MOE: https://github.com/google/moe MOE_MIGRATED_REVID=169077365
This commit is contained in:
parent
30a04fd14b
commit
961f01a850
3 changed files with 12 additions and 11 deletions
|
|
@ -37,6 +37,9 @@ public final class SubtitleInputBuffer extends DecoderInputBuffer
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int compareTo(@NonNull SubtitleInputBuffer other) {
|
public int compareTo(@NonNull SubtitleInputBuffer other) {
|
||||||
|
if (isEndOfStream() != other.isEndOfStream()) {
|
||||||
|
return isEndOfStream() ? 1 : -1;
|
||||||
|
}
|
||||||
long delta = timeUs - other.timeUs;
|
long delta = timeUs - other.timeUs;
|
||||||
if (delta == 0) {
|
if (delta == 0) {
|
||||||
return 0;
|
return 0;
|
||||||
|
|
|
||||||
|
|
@ -294,9 +294,9 @@ public final class TextRenderer extends BaseRenderer implements Callback {
|
||||||
}
|
}
|
||||||
|
|
||||||
private long getNextEventTime() {
|
private long getNextEventTime() {
|
||||||
return ((nextSubtitleEventIndex == C.INDEX_UNSET)
|
return nextSubtitleEventIndex == C.INDEX_UNSET
|
||||||
|| (nextSubtitleEventIndex >= subtitle.getEventTimeCount())) ? Long.MAX_VALUE
|
|| nextSubtitleEventIndex >= subtitle.getEventTimeCount()
|
||||||
: (subtitle.getEventTime(nextSubtitleEventIndex));
|
? Long.MAX_VALUE : subtitle.getEventTime(nextSubtitleEventIndex);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void updateOutput(List<Cue> cues) {
|
private void updateOutput(List<Cue> cues) {
|
||||||
|
|
|
||||||
|
|
@ -24,7 +24,7 @@ import com.google.android.exoplayer2.text.SubtitleInputBuffer;
|
||||||
import com.google.android.exoplayer2.text.SubtitleOutputBuffer;
|
import com.google.android.exoplayer2.text.SubtitleOutputBuffer;
|
||||||
import com.google.android.exoplayer2.util.Assertions;
|
import com.google.android.exoplayer2.util.Assertions;
|
||||||
import java.util.LinkedList;
|
import java.util.LinkedList;
|
||||||
import java.util.TreeSet;
|
import java.util.PriorityQueue;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Base class for subtitle parsers for CEA captions.
|
* Base class for subtitle parsers for CEA captions.
|
||||||
|
|
@ -36,7 +36,7 @@ import java.util.TreeSet;
|
||||||
|
|
||||||
private final LinkedList<SubtitleInputBuffer> availableInputBuffers;
|
private final LinkedList<SubtitleInputBuffer> availableInputBuffers;
|
||||||
private final LinkedList<SubtitleOutputBuffer> availableOutputBuffers;
|
private final LinkedList<SubtitleOutputBuffer> availableOutputBuffers;
|
||||||
private final TreeSet<SubtitleInputBuffer> queuedInputBuffers;
|
private final PriorityQueue<SubtitleInputBuffer> queuedInputBuffers;
|
||||||
|
|
||||||
private SubtitleInputBuffer dequeuedInputBuffer;
|
private SubtitleInputBuffer dequeuedInputBuffer;
|
||||||
private long playbackPositionUs;
|
private long playbackPositionUs;
|
||||||
|
|
@ -50,7 +50,7 @@ import java.util.TreeSet;
|
||||||
for (int i = 0; i < NUM_OUTPUT_BUFFERS; i++) {
|
for (int i = 0; i < NUM_OUTPUT_BUFFERS; i++) {
|
||||||
availableOutputBuffers.add(new CeaOutputBuffer(this));
|
availableOutputBuffers.add(new CeaOutputBuffer(this));
|
||||||
}
|
}
|
||||||
queuedInputBuffers = new TreeSet<>();
|
queuedInputBuffers = new PriorityQueue<>();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
@ -73,7 +73,6 @@ import java.util.TreeSet;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void queueInputBuffer(SubtitleInputBuffer inputBuffer) throws SubtitleDecoderException {
|
public void queueInputBuffer(SubtitleInputBuffer inputBuffer) throws SubtitleDecoderException {
|
||||||
Assertions.checkArgument(inputBuffer != null);
|
|
||||||
Assertions.checkArgument(inputBuffer == dequeuedInputBuffer);
|
Assertions.checkArgument(inputBuffer == dequeuedInputBuffer);
|
||||||
if (inputBuffer.isDecodeOnly()) {
|
if (inputBuffer.isDecodeOnly()) {
|
||||||
// We can drop this buffer early (i.e. before it would be decoded) as the CEA formats allow
|
// We can drop this buffer early (i.e. before it would be decoded) as the CEA formats allow
|
||||||
|
|
@ -90,13 +89,12 @@ import java.util.TreeSet;
|
||||||
if (availableOutputBuffers.isEmpty()) {
|
if (availableOutputBuffers.isEmpty()) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
// iterate through all available input buffers whose timestamps are less than or equal
|
// iterate through all available input buffers whose timestamps are less than or equal
|
||||||
// to the current playback position; processing input buffers for future content should
|
// to the current playback position; processing input buffers for future content should
|
||||||
// be deferred until they would be applicable
|
// be deferred until they would be applicable
|
||||||
while (!queuedInputBuffers.isEmpty()
|
while (!queuedInputBuffers.isEmpty()
|
||||||
&& queuedInputBuffers.first().timeUs <= playbackPositionUs) {
|
&& queuedInputBuffers.peek().timeUs <= playbackPositionUs) {
|
||||||
SubtitleInputBuffer inputBuffer = queuedInputBuffers.pollFirst();
|
SubtitleInputBuffer inputBuffer = queuedInputBuffers.poll();
|
||||||
|
|
||||||
// If the input buffer indicates we've reached the end of the stream, we can
|
// If the input buffer indicates we've reached the end of the stream, we can
|
||||||
// return immediately with an output buffer propagating that
|
// return immediately with an output buffer propagating that
|
||||||
|
|
@ -142,7 +140,7 @@ import java.util.TreeSet;
|
||||||
public void flush() {
|
public void flush() {
|
||||||
playbackPositionUs = 0;
|
playbackPositionUs = 0;
|
||||||
while (!queuedInputBuffers.isEmpty()) {
|
while (!queuedInputBuffers.isEmpty()) {
|
||||||
releaseInputBuffer(queuedInputBuffers.pollFirst());
|
releaseInputBuffer(queuedInputBuffers.poll());
|
||||||
}
|
}
|
||||||
if (dequeuedInputBuffer != null) {
|
if (dequeuedInputBuffer != null) {
|
||||||
releaseInputBuffer(dequeuedInputBuffer);
|
releaseInputBuffer(dequeuedInputBuffer);
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue